Skip to content

Commit 3b946fe

Browse files
Christoph Hellwigkeithbusch
authored andcommitted
nvme: simplify the max_discard_segments calculation
Just stash away the DMRL value in the nvme_ctrl struture, and leave all interpretation to nvme_config_discard, where we know DSM is supported by the time we're configuring the number of segments. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent f29886c commit 3b946fe

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

drivers/nvme/host/core.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,7 +1752,10 @@ static void nvme_config_discard(struct nvme_ctrl *ctrl, struct gendisk *disk,
17521752
return;
17531753

17541754
blk_queue_max_discard_sectors(queue, max_discard_sectors);
1755-
blk_queue_max_discard_segments(queue, ctrl->max_discard_segments);
1755+
if (ctrl->dmrl)
1756+
blk_queue_max_discard_segments(queue, ctrl->dmrl);
1757+
else
1758+
blk_queue_max_discard_segments(queue, NVME_DSM_MAX_RANGES);
17561759
queue->limits.discard_granularity = queue_logical_block_size(queue);
17571760

17581761
if (ctrl->quirks & NVME_QUIRK_DEALLOCATE_ZEROES)
@@ -2912,11 +2915,6 @@ static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl)
29122915
struct nvme_id_ctrl_nvm *id;
29132916
int ret;
29142917

2915-
if (ctrl->oncs & NVME_CTRL_ONCS_DSM)
2916-
ctrl->max_discard_segments = NVME_DSM_MAX_RANGES;
2917-
else
2918-
ctrl->max_discard_segments = 0;
2919-
29202918
/*
29212919
* Even though NVMe spec explicitly states that MDTS is not applicable
29222920
* to the write-zeroes, we are cautious and limit the size to the
@@ -2946,8 +2944,7 @@ static int nvme_init_non_mdts_limits(struct nvme_ctrl *ctrl)
29462944
if (ret)
29472945
goto free_data;
29482946

2949-
if (id->dmrl)
2950-
ctrl->max_discard_segments = id->dmrl;
2947+
ctrl->dmrl = id->dmrl;
29512948
ctrl->dmrsl = le32_to_cpu(id->dmrsl);
29522949
if (id->wzsl)
29532950
ctrl->max_zeroes_sectors = nvme_mps_to_sectors(ctrl, id->wzsl);

drivers/nvme/host/nvme.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,13 @@ struct nvme_ctrl {
297297
u32 max_hw_sectors;
298298
u32 max_segments;
299299
u32 max_integrity_segments;
300-
u32 max_discard_segments;
301300
u32 max_zeroes_sectors;
302301
#ifdef CONFIG_BLK_DEV_ZONED
303302
u32 max_zone_append;
304303
#endif
305304
u16 crdt[3];
306305
u16 oncs;
306+
u8 dmrl;
307307
u32 dmrsl;
308308
u16 oacs;
309309
u16 sqsize;

0 commit comments

Comments
 (0)