Commit e08f2ae8 authored by Damien Le Moal's avatar Damien Le Moal Committed by Jens Axboe

nvme: Introduce nvme_lba_to_sect()

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.
Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarDamien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: default avatarKeith Busch <kbusch@kernel.org>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 314d48dd
...@@ -1611,7 +1611,7 @@ static void nvme_init_integrity(struct gendisk *disk, u16 ms, u8 pi_type) ...@@ -1611,7 +1611,7 @@ static void nvme_init_integrity(struct gendisk *disk, u16 ms, u8 pi_type)
static void nvme_set_chunk_size(struct nvme_ns *ns) 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)); blk_queue_chunk_sectors(ns->queue, rounddown_pow_of_two(chunk_size));
} }
...@@ -1648,8 +1648,7 @@ static void nvme_config_discard(struct gendisk *disk, struct nvme_ns *ns) ...@@ -1648,8 +1648,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) static void nvme_config_write_zeroes(struct gendisk *disk, struct nvme_ns *ns)
{ {
u32 max_sectors; u64 max_blocks;
unsigned short bs = 1 << ns->lba_shift;
if (!(ns->ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) || if (!(ns->ctrl->oncs & NVME_CTRL_ONCS_WRITE_ZEROES) ||
(ns->ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES)) (ns->ctrl->quirks & NVME_QUIRK_DISABLE_WRITE_ZEROES))
...@@ -1665,11 +1664,12 @@ static void nvme_config_write_zeroes(struct gendisk *disk, struct nvme_ns *ns) ...@@ -1665,11 +1664,12 @@ static void nvme_config_write_zeroes(struct gendisk *disk, struct nvme_ns *ns)
* nvme_init_identify() if available. * nvme_init_identify() if available.
*/ */
if (ns->ctrl->max_hw_sectors == UINT_MAX) if (ns->ctrl->max_hw_sectors == UINT_MAX)
max_sectors = ((u32)(USHRT_MAX + 1) * bs) >> 9; max_blocks = (u64)USHRT_MAX + 1;
else 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, static int nvme_report_ns_ids(struct nvme_ctrl *ctrl, unsigned int nsid,
...@@ -1712,7 +1712,7 @@ static bool nvme_ns_ids_equal(struct nvme_ns_ids *a, struct nvme_ns_ids *b) ...@@ -1712,7 +1712,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, static void nvme_update_disk_info(struct gendisk *disk,
struct nvme_ns *ns, struct nvme_id_ns *id) 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; unsigned short bs = 1 << ns->lba_shift;
u32 atomic_bs, phys_bs, io_opt; u32 atomic_bs, phys_bs, io_opt;
......
...@@ -426,6 +426,14 @@ static inline u64 nvme_sect_to_lba(struct nvme_ns *ns, sector_t sector) ...@@ -426,6 +426,14 @@ static inline u64 nvme_sect_to_lba(struct nvme_ns *ns, sector_t sector)
return sector >> (ns->lba_shift - SECTOR_SHIFT); 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, static inline void nvme_end_request(struct request *req, __le16 status,
union nvme_result result) union nvme_result result)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment