* [PATCH 0/2 v2] Small cleanups @ 2019-10-21 3:40 Damien Le Moal 2019-10-21 3:40 ` [PATCH 1/2 v2] nvme: Cleanup and rename nvme_block_nr() Damien Le Moal ` (2 more replies) 0 siblings, 3 replies; 9+ messages in thread From: Damien Le Moal @ 2019-10-21 3:40 UTC (permalink / raw) To: linux-nvme, Christoph Hellwig, Keith Busch, Sagi Grimberg, linux-block, Jens Axboe This is series is a couple of cleanup patches. The first one cleans up the helper function nvme_block_nr() using SECTOR_SHIFT instead of the hard coded value 9 and clarifies the helper role by renaming it to nvme_sect_to_lba(). The second patch introduces the nvme_lba_to_sect() helper to convert a device logical block number into a 512B sector value. Please consider this series for kernel 5.5. Damien Le Moal (2): nvme: Cleanup and rename nvme_block_nr() nvme: Introduce nvme_lba_to_sect() drivers/nvme/host/core.c | 20 ++++++++++---------- drivers/nvme/host/nvme.h | 15 +++++++++++++-- 2 files changed, 23 insertions(+), 12 deletions(-) Changes from v1: * Renamed the helpers to a clearer function name. -- 2.21.0 _______________________________________________ Linux-nvme mailing list Linux-nvme@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-nvme ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/2 v2] nvme: Cleanup and rename nvme_block_nr() 2019-10-21 3:40 [PATCH 0/2 v2] Small cleanups Damien Le Moal @ 2019-10-21 3:40 ` Damien Le Moal 2019-10-21 3:44 ` Christoph Hellwig 2019-10-21 7:14 ` Johannes Thumshirn 2019-10-21 3:40 ` [PATCH 2/2 v2] nvme: Introduce nvme_lba_to_sect() Damien Le Moal 2019-10-21 13:55 ` [PATCH 0/2 v2] Small cleanups Keith Busch 2 siblings, 2 replies; 9+ messages in thread From: Damien Le Moal @ 2019-10-21 3:40 UTC (permalink / raw) To: linux-nvme, Christoph Hellwig, Keith Busch, Sagi Grimberg, linux-block, Jens Axboe Rename nvme_block_nr() to nvme_sect_to_lba() and use SECTOR_SHIFT instead of its hard coded value 9. Also add a comment to decribe this helper. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com> --- drivers/nvme/host/core.c | 6 +++--- drivers/nvme/host/nvme.h | 7 +++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index fa7ba09dca77..6b37103b31d9 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -626,7 +626,7 @@ static blk_status_t nvme_setup_discard(struct nvme_ns *ns, struct request *req, } __rq_for_each_bio(bio, req) { - u64 slba = nvme_block_nr(ns, bio->bi_iter.bi_sector); + u64 slba = nvme_sect_to_lba(ns, bio->bi_iter.bi_sector); u32 nlb = bio->bi_iter.bi_size >> ns->lba_shift; if (n < segments) { @@ -667,7 +667,7 @@ static inline blk_status_t nvme_setup_write_zeroes(struct nvme_ns *ns, cmnd->write_zeroes.opcode = nvme_cmd_write_zeroes; cmnd->write_zeroes.nsid = cpu_to_le32(ns->head->ns_id); cmnd->write_zeroes.slba = - cpu_to_le64(nvme_block_nr(ns, blk_rq_pos(req))); + cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req))); cmnd->write_zeroes.length = cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1); cmnd->write_zeroes.control = 0; @@ -691,7 +691,7 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns, cmnd->rw.opcode = (rq_data_dir(req) ? nvme_cmd_write : nvme_cmd_read); cmnd->rw.nsid = cpu_to_le32(ns->head->ns_id); - cmnd->rw.slba = cpu_to_le64(nvme_block_nr(ns, blk_rq_pos(req))); + cmnd->rw.slba = cpu_to_le64(nvme_sect_to_lba(ns, blk_rq_pos(req))); cmnd->rw.length = cpu_to_le16((blk_rq_bytes(req) >> ns->lba_shift) - 1); if (req_op(req) == REQ_OP_WRITE && ctrl->nr_streams) diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 22e8401352c2..617ee8512f91 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -419,9 +419,12 @@ static inline int nvme_reset_subsystem(struct nvme_ctrl *ctrl) return ctrl->ops->reg_write32(ctrl, NVME_REG_NSSR, 0x4E564D65); } -static inline u64 nvme_block_nr(struct nvme_ns *ns, sector_t sector) +/* + * Convert a 512B sector number to a device logical block number. + */ +static inline u64 nvme_sect_to_lba(struct nvme_ns *ns, sector_t sector) { - return (sector >> (ns->lba_shift - 9)); + return sector >> (ns->lba_shift - SECTOR_SHIFT); } static inline void nvme_end_request(struct request *req, __le16 status, -- 2.21.0 _______________________________________________ Linux-nvme mailing list Linux-nvme@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-nvme ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2 v2] nvme: Cleanup and rename nvme_block_nr() 2019-10-21 3:40 ` [PATCH 1/2 v2] nvme: Cleanup and rename nvme_block_nr() Damien Le Moal @ 2019-10-21 3:44 ` Christoph Hellwig 2019-10-21 3:44 ` Christoph Hellwig 2019-10-21 7:14 ` Johannes Thumshirn 1 sibling, 1 reply; 9+ messages in thread From: Christoph Hellwig @ 2019-10-21 3:44 UTC (permalink / raw) To: Damien Le Moal Cc: Jens Axboe, Sagi Grimberg, linux-nvme, linux-block, Keith Busch, Christoph Hellwig On Mon, Oct 21, 2019 at 12:40:03PM +0900, Damien Le Moal wrote: > Rename nvme_block_nr() to nvme_sect_to_lba() and use SECTOR_SHIFT > instead of its hard coded value 9. Also add a comment to decribe this > helper. > > Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com> Looks fine, Reviewed-by: Christoph Hellwig <hch@lst.de> _______________________________________________ Linux-nvme mailing list Linux-nvme@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-nvme ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2 v2] nvme: Cleanup and rename nvme_block_nr() 2019-10-21 3:44 ` Christoph Hellwig @ 2019-10-21 3:44 ` Christoph Hellwig 0 siblings, 0 replies; 9+ messages in thread From: Christoph Hellwig @ 2019-10-21 3:44 UTC (permalink / raw) To: Damien Le Moal Cc: Jens Axboe, Sagi Grimberg, linux-nvme, linux-block, Keith Busch, Christoph Hellwig On Mon, Oct 21, 2019 at 05:44:14AM +0200, Christoph Hellwig wrote: > On Mon, Oct 21, 2019 at 12:40:03PM +0900, Damien Le Moal wrote: > > Rename nvme_block_nr() to nvme_sect_to_lba() and use SECTOR_SHIFT > > instead of its hard coded value 9. Also add a comment to decribe this > > helper. > > > > Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com> > > Looks fine, > > Reviewed-by: Christoph Hellwig <hch@lst.de> Looks fine, Reviewed-by: Christoph Hellwig <hch@lst.de> _______________________________________________ Linux-nvme mailing list Linux-nvme@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-nvme ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2 v2] nvme: Cleanup and rename nvme_block_nr() 2019-10-21 3:40 ` [PATCH 1/2 v2] nvme: Cleanup and rename nvme_block_nr() Damien Le Moal 2019-10-21 3:44 ` Christoph Hellwig @ 2019-10-21 7:14 ` Johannes Thumshirn 1 sibling, 0 replies; 9+ messages in thread From: Johannes Thumshirn @ 2019-10-21 7:14 UTC (permalink / raw) To: Damien Le Moal, linux-nvme, Christoph Hellwig, Keith Busch, Sagi Grimberg, linux-block, Jens Axboe Looks good, Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> -- Johannes Thumshirn SUSE Labs Filesystems jthumshirn@suse.de +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850 _______________________________________________ Linux-nvme mailing list Linux-nvme@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-nvme ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 2/2 v2] nvme: Introduce nvme_lba_to_sect() 2019-10-21 3:40 [PATCH 0/2 v2] Small cleanups Damien Le Moal 2019-10-21 3:40 ` [PATCH 1/2 v2] nvme: Cleanup and rename nvme_block_nr() Damien Le Moal @ 2019-10-21 3:40 ` Damien Le Moal 2019-10-21 3:44 ` Christoph Hellwig 2019-10-21 7:14 ` Johannes Thumshirn 2019-10-21 13:55 ` [PATCH 0/2 v2] Small cleanups Keith Busch 2 siblings, 2 replies; 9+ messages in thread From: Damien Le Moal @ 2019-10-21 3:40 UTC (permalink / raw) To: linux-nvme, Christoph Hellwig, Keith Busch, Sagi Grimberg, linux-block, Jens Axboe Introduce the new helper function nvme_lba_to_sect() to convert a device logical block number to a 512B sector number. Use this new helper in obvious places, cleaning up the code. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com> --- drivers/nvme/host/core.c | 14 +++++++------- drivers/nvme/host/nvme.h | 8 ++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 6b37103b31d9..5a5d83dd9689 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1647,7 +1647,7 @@ static void nvme_init_integrity(struct gendisk *disk, u16 ms, u8 pi_type) static void nvme_set_chunk_size(struct nvme_ns *ns) { - u32 chunk_size = (((u32)ns->noiob) << (ns->lba_shift - 9)); + u32 chunk_size = nvme_lba_to_sect(ns, ns->noiob); blk_queue_chunk_sectors(ns->queue, rounddown_pow_of_two(chunk_size)); } @@ -1684,8 +1684,7 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns) static void nvme_config_write_zeroes(struct gendisk *disk, struct nvme_ns *ns) { - u32 max_sectors; - unsigned short bs = 1 << ns->lba_shift; + u64 max_blocks; if (!(ns->ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) || (ns->ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES)) @@ -1701,11 +1700,12 @@ static void nvme_config_write_zeroes(struct gendisk *disk, struct nvme_ns *ns) * nvme_init_identify() if available. */ if (ns->ctrl->max_hw_sectors == UINT_MAX) - max_sectors = ((u32)(USHRT_MAX + 1) * bs) >> 9; + max_blocks = (u64)USHRT_MAX + 1; else - max_sectors = ((u32)(ns->ctrl->max_hw_sectors + 1) * bs) >> 9; + max_blocks = ns->ctrl->max_hw_sectors + 1; - blk_queue_max_write_zeroes_sectors(disk->queue, max_sectors); + blk_queue_max_write_zeroes_sectors(disk->queue, + nvme_lba_to_sect(ns, max_blocks)); } static int nvme_report_ns_ids(struct nvme_ctrl *ctrl, unsigned int nsid, @@ -1748,7 +1748,7 @@ static bool nvme_ns_ids_equal(struct nvme_ns_ids *a, struct nvme_ns_ids *b) static void nvme_update_disk_info(struct gendisk *disk, struct nvme_ns *ns, struct nvme_id_ns *id) { - sector_t capacity = le64_to_cpu(id->nsze) << (ns->lba_shift - 9); + sector_t capacity = nvme_lba_to_sect(ns, le64_to_cpu(id->nsze)); unsigned short bs = 1 << ns->lba_shift; u32 atomic_bs, phys_bs, io_opt; diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h index 617ee8512f91..837ca66a7e33 100644 --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -427,6 +427,14 @@ static inline u64 nvme_sect_to_lba(struct nvme_ns *ns, sector_t sector) return sector >> (ns->lba_shift - SECTOR_SHIFT); } +/* + * Convert a device logical block number to a 512B sector number. + */ +static inline sector_t nvme_lba_to_sect(struct nvme_ns *ns, u64 lba) +{ + return lba << (ns->lba_shift - SECTOR_SHIFT); +} + static inline void nvme_end_request(struct request *req, __le16 status, union nvme_result result) { -- 2.21.0 _______________________________________________ Linux-nvme mailing list Linux-nvme@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-nvme ^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2 v2] nvme: Introduce nvme_lba_to_sect() 2019-10-21 3:40 ` [PATCH 2/2 v2] nvme: Introduce nvme_lba_to_sect() Damien Le Moal @ 2019-10-21 3:44 ` Christoph Hellwig 2019-10-21 7:14 ` Johannes Thumshirn 1 sibling, 0 replies; 9+ messages in thread From: Christoph Hellwig @ 2019-10-21 3:44 UTC (permalink / raw) To: Damien Le Moal Cc: Jens Axboe, Sagi Grimberg, linux-nvme, linux-block, Keith Busch, Christoph Hellwig On Mon, Oct 21, 2019 at 12:40:04PM +0900, Damien Le Moal wrote: > Introduce the new helper function nvme_lba_to_sect() to convert a device > logical block number to a 512B sector number. Use this new helper in > obvious places, cleaning up the code. > > Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com> Looks fine, Reviewed-by: Christoph Hellwig <hch@lst.de> _______________________________________________ Linux-nvme mailing list Linux-nvme@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-nvme ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2 v2] nvme: Introduce nvme_lba_to_sect() 2019-10-21 3:40 ` [PATCH 2/2 v2] nvme: Introduce nvme_lba_to_sect() Damien Le Moal 2019-10-21 3:44 ` Christoph Hellwig @ 2019-10-21 7:14 ` Johannes Thumshirn 1 sibling, 0 replies; 9+ messages in thread From: Johannes Thumshirn @ 2019-10-21 7:14 UTC (permalink / raw) To: Damien Le Moal, linux-nvme, Christoph Hellwig, Keith Busch, Sagi Grimberg, linux-block, Jens Axboe Looks good, Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> -- Johannes Thumshirn SUSE Labs Filesystems jthumshirn@suse.de +49 911 74053 689 SUSE Software Solutions Germany GmbH Maxfeldstr. 5 90409 Nürnberg Germany (HRB 36809, AG Nürnberg) Geschäftsführer: Felix Imendörffer Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850 _______________________________________________ Linux-nvme mailing list Linux-nvme@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-nvme ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 0/2 v2] Small cleanups 2019-10-21 3:40 [PATCH 0/2 v2] Small cleanups Damien Le Moal 2019-10-21 3:40 ` [PATCH 1/2 v2] nvme: Cleanup and rename nvme_block_nr() Damien Le Moal 2019-10-21 3:40 ` [PATCH 2/2 v2] nvme: Introduce nvme_lba_to_sect() Damien Le Moal @ 2019-10-21 13:55 ` Keith Busch 2 siblings, 0 replies; 9+ messages in thread From: Keith Busch @ 2019-10-21 13:55 UTC (permalink / raw) To: Damien Le Moal Cc: linux-block, Jens Axboe, Christoph Hellwig, linux-nvme, Sagi Grimberg On Mon, Oct 21, 2019 at 12:40:02PM +0900, Damien Le Moal wrote: > This is series is a couple of cleanup patches. The first one cleans up > the helper function nvme_block_nr() using SECTOR_SHIFT instead of the > hard coded value 9 and clarifies the helper role by renaming it to > nvme_sect_to_lba(). The second patch introduces the nvme_lba_to_sect() > helper to convert a device logical block number into a 512B sector > value. Thank you, patches applied to nvme-5.5 with the reviews. _______________________________________________ Linux-nvme mailing list Linux-nvme@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-nvme ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2019-10-21 13:55 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-10-21 3:40 [PATCH 0/2 v2] Small cleanups Damien Le Moal 2019-10-21 3:40 ` [PATCH 1/2 v2] nvme: Cleanup and rename nvme_block_nr() Damien Le Moal 2019-10-21 3:44 ` Christoph Hellwig 2019-10-21 3:44 ` Christoph Hellwig 2019-10-21 7:14 ` Johannes Thumshirn 2019-10-21 3:40 ` [PATCH 2/2 v2] nvme: Introduce nvme_lba_to_sect() Damien Le Moal 2019-10-21 3:44 ` Christoph Hellwig 2019-10-21 7:14 ` Johannes Thumshirn 2019-10-21 13:55 ` [PATCH 0/2 v2] Small cleanups Keith Busch
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).