Some cleanups for NVMe-pci driver
cover Some cleanups for NVMe-pci driver
Hi,
These are some cleanups for NVMe-pci driver, and no functional changes, please help to review. Thanks.
Baolin Wang (5):
nvme-pci: Fix some comments issues
nvme-pci: Add a blank line after declarations
nvme-pci: Remove redundant segment validation
nvme-pci: Use the consistent return type of nvme_pci_iod_alloc_size()
nvme-pci: Use standard block status macro
drivers/nvme/host/pci.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/5 nvme-pci: Fix some comments issues
Fix comments' typo and remove whitespaces before tabs to cleanup checkpatch errors.
--- drivers/nvme/host/pci.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/nvme/host/pci.c +4 -4
@@ -1260,9 +1260,9 @@ static enum blk_eh_timer_return nvme_timeout(struct request *req, bool reserved) }/* -* Shutdown the controller immediately and schedule a reset if the -* command was already aborted once before and still hasn't been -* returned to the driver, or if this is the admin queue. +* Shutdown the controller immediately and schedule a reset if the +* command was already aborted once before and still hasn't been +* returned to the driver, or if this is the admin queue. */ if (!nvmeq->qid || iod->aborted) { dev_warn(dev->ctrl.device,
@@ -2002,7 +2002,7 @@ static void nvme_calc_irq_sets(struct irq_affinity *affd, unsigned int nrirqs)unsigned int nr_read_queues, nr_write_queues = dev->nr_write_queues;/* -* If there is no interupt available for queues, ensure that +* If there is no interrupt available for queues, ensure that * the default queue is set to 1. The affinity set size is * also set to one, but the irq core ignores it for this case. *
Signature · 1 line
1.8.3.1
PATCH 3/5 nvme-pci: Remove redundant segment validation
In reply to Baolin WangWe've validated the segment counts before calling nvme_map_data(), so there is no need to validate again in nvme_pci_use_sgls() only called from nvme_map_data().
--- drivers/nvme/host/pci.c | 3 --- 1 file changed, 3 deletions(-)
drivers/nvme/host/pci.c +0 -3
@@ -501,9 +501,6 @@ static inline bool nvme_pci_use_sgls(struct nvme_dev *dev, struct request *req)int nseg =blk_rq_nr_phys_segments (req);unsigned int avg_seg_size; -if (nseg ==0 ) -return false; - avg_seg_size =DIV_ROUND_UP (blk_rq_payload_bytes (req), nseg);if (!(dev->ctrl.sgls & ((1 <<0 ) | (1 <<1 ))))
Signature · 1 line
1.8.3.1
PATCH 2/5 nvme-pci: Add a blank line after declarations
In reply to Baolin WangAdd a blank line after declarations to make code more readable.
--- drivers/nvme/host/pci.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/nvme/host/pci.c +4 -0
@@ -1019,6 +1019,7 @@ static irqreturn_t nvme_irq(int irq, void *data)static irqreturn_t nvme_irq_check (int irq,void *data) {struct nvme_queue *nvmeq = data; +if (nvme_cqe_pending (nvmeq))return IRQ_WAKE_THREAD ;return IRQ_NONE ;
@@ -1401,6 +1402,7 @@ static int nvme_cmb_qdepth(struct nvme_dev *dev, int nr_io_queues,if (q_size_aligned * nr_io_queues > dev->cmb_size) {u64 mem_per_q =div_u64 (dev->cmb_size, nr_io_queues); + mem_per_q =round_down (mem_per_q, dev->ctrl.page_size); q_depth =div_u64 (mem_per_q, entry_size);
@@ -2875,6 +2877,7 @@ static void nvme_reset_done(struct pci_dev *pdev)static void nvme_shutdown (struct pci_dev *pdev) {struct nvme_dev *dev =pci_get_drvdata (pdev); +nvme_disable_prepare_reset (dev, true); }
@@ -3005,6 +3008,7 @@ static int nvme_suspend(struct device *dev)static int nvme_simple_suspend (struct device *dev) {struct nvme_dev *ndev =pci_get_drvdata (to_pci_dev (dev)); +return nvme_disable_prepare_reset (ndev, true); }
Signature · 7 lines
1.8.3.1 _______________________________________________ Linux-nvme mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-nvme
PATCH 4/5 nvme-pci: Use the consistent return type of nvme_pci_iod_alloc_size()
In reply to Baolin WangThe nvme_pci_iod_alloc_size() should return 'size_t' type to keep consistent.
--- drivers/nvme/host/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/nvme/host/pci.c +1 -1
@@ -362,7 +362,7 @@ static int nvme_pci_npages_sgl(unsigned int num_seg)return DIV_ROUND_UP (num_seg *sizeof (struct nvme_sgl_desc ),PAGE_SIZE ); } -static unsigned int nvme_pci_iod_alloc_size (struct nvme_dev *dev, +static size_t nvme_pci_iod_alloc_size (struct nvme_dev *dev,unsigned int size,unsigned int nseg,bool use_sgl) {size_t alloc_size;
Signature · 1 line
1.8.3.1
PATCH 5/5 nvme-pci: Use standard block status macro
In reply to Baolin WangUse standard block status macro.
--- drivers/nvme/host/pci.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/nvme/host/pci.c +3 -3
@@ -762,7 +762,7 @@ static blk_status_t nvme_setup_prp_simple(struct nvme_dev *dev, cmnd->dptr.prp1 =cpu_to_le64 (iod->first_dma);if (bv->bv_len > first_prp_len) cmnd->dptr.prp2 =cpu_to_le64 (iod->first_dma + first_prp_len); -return 0 ; +return BLK_STS_OK ; } static blk_status_t nvme_setup_sgl_simple(struct nvme_dev *dev,
@@ -780,7 +780,7 @@ static blk_status_t nvme_setup_sgl_simple(struct nvme_dev *dev, cmnd->dptr.sgl.addr =cpu_to_le64 (iod->first_dma); cmnd->dptr.sgl.length =cpu_to_le32 (iod->dma_len); cmnd->dptr.sgl.type =NVME_SGL_FMT_DATA_DESC <<4 ; -return 0 ; +return BLK_STS_OK ; } static blk_status_t nvme_map_data(struct nvme_dev *dev, struct request *req,
@@ -844,7 +844,7 @@ static blk_status_t nvme_map_metadata(struct nvme_dev *dev, struct request *req,if (dma_mapping_error (dev->dev, iod->meta_dma))return BLK_STS_IOERR ; cmnd->rw.metadata =cpu_to_le64 (iod->meta_dma); -return 0 ; +return BLK_STS_OK ; }/*
Signature · 1 line
1.8.3.1
Re: [PATCH 1/5] nvme-pci: Fix some comments issues
In reply to Baolin WangRe: [PATCH 2/5] nvme-pci: Add a blank line after declarations
In reply to Baolin WangRe: [PATCH 4/5] nvme-pci: Use the consistent return type of nvme_pci_iod_alloc_size()
In reply to Baolin WangRe: [PATCH 5/5] nvme-pci: Use standard block status macro
In reply to Baolin Wang_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 2/5] nvme-pci: Add a blank line after declarations
In reply to Baolin WangQuoted 4 lines · Baolin Wang
Add a blank line after declarations to make code more readable.
Signed-off-by Baolin Wang<[email protected]>---
Looks good to me.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Re: [PATCH 1/5] nvme-pci: Fix some comments issues
In reply to Baolin WangQuoted 4 lines · Baolin Wang
Fix comments' typo and remove whitespaces before tabs to cleanup checkpatch errors.
Signed-off-by Baolin Wang<[email protected]>
Looks good to me.
Re: [PATCH 3/5] nvme-pci: Remove redundant segment validation
In reply to Baolin WangQuoted 5 lines · Baolin Wang
We've validated the segment counts before calling
nvme_map_data(), so there is no need to validate again innvme_pci_use_sgls()only called fromnvme_map_data().Signed-off-by Baolin Wang<[email protected]>
Indeed we do call blk_rq_nr_phys_segments() in nvme_queue_rq().
Looks good to me.
Re: [PATCH 4/5] nvme-pci: Use the consistent return type of nvme_pci_iod_alloc_size()
In reply to Baolin WangQuoted 4 lines · Baolin Wang
The
nvme_pci_iod_alloc_size()should return 'size_t' type to keep consistent.Signed-off-by Baolin Wang<[email protected]>
Looks good.
Re: [PATCH 5/5] nvme-pci: Use standard block status macro
In reply to Baolin WangQuoted 3 lines · Baolin Wang
Use standard block status macro.
Signed-off-by Baolin Wang<[email protected]>
Looks good.
Thanks,
applied to nvme-5.9.
Keith Busch
maintainerRe: [PATCH 5/5] nvme-pci: Use standard block status macro
In reply to Baolin Wangdrivers/nvme/host/pci.c static blk_status_t nvme_map_metadata(struct nvme_dev *dev, struct request *req, · line 848
Quoted 8 lines · Baolin Wang
static
blk_status_tnvme_map_data(structnvme_dev*dev, struct request *req,drivers/nvme/host/pci.c +1
-1@@ -844,7 +844,7 @@ static blk_status_t nvme_map_metadata(struct nvme_dev *dev, struct request *req,if (dma_mapping_error (dev->dev, iod->meta_dma))return BLK_STS_IOERR ; cmnd->rw.metadata =cpu_to_le64 (iod->meta_dma); -return 0 ; +return BLK_STS_OK ; }
This is fine, though it takes knowing that this value is 0 for the subsequent 'if (!ret)' check to make sense. Maybe those should change to 'if (ret != BLK_STS_OK)' so the check uses the same symbol as the return, and will always work in the unlikely event that the defines are reordered.
Re: [PATCH 5/5] nvme-pci: Use standard block status macro
Quoted 15 lines · Keith Busch
drivers/nvme/host/pci.c static blk_status_t nvme_map_metadata(struct nvme_dev *dev, struct request *req, · line 848
Quoted 8 lines · Baolin Wang
static
blk_status_tnvme_map_data(structnvme_dev*dev, struct request *req,drivers/nvme/host/pci.c +1
-1@@ -844,7 +844,7 @@ static blk_status_t nvme_map_metadata(struct nvme_dev *dev, struct request *req,if (dma_mapping_error (dev->dev, iod->meta_dma))return BLK_STS_IOERR ; cmnd->rw.metadata =cpu_to_le64 (iod->meta_dma); -return 0 ; +return BLK_STS_OK ; }This is fine, though it takes knowing that this value is 0 for the subsequent 'if (!ret)' check to make sense. Maybe those should change to 'if (ret !=
BLK_STS_OK)' so the check uses the same symbol as the return, and will always work in the unlikely event that the defines are reordered.
Okay, I will send another patch to convert to 'if (ret != BLK_STS_OK)' validation. Thanks.
Christoph Hellwig
maintainerRe: [PATCH 5/5] nvme-pci: Use standard block status macro
In reply to Keith BuschQuoted 15 lines · Keith Busch
drivers/nvme/host/pci.c static blk_status_t nvme_map_metadata(struct nvme_dev *dev, struct request *req, · line 848
Quoted 8 lines · Baolin Wang
static
blk_status_tnvme_map_data(structnvme_dev*dev, struct request *req,drivers/nvme/host/pci.c +1
-1@@ -844,7 +844,7 @@ static blk_status_t nvme_map_metadata(struct nvme_dev *dev, struct request *req,if (dma_mapping_error (dev->dev, iod->meta_dma))return BLK_STS_IOERR ; cmnd->rw.metadata =cpu_to_le64 (iod->meta_dma); -return 0 ; +return BLK_STS_OK ; }This is fine, though it takes knowing that this value is 0 for the subsequent 'if (!ret)' check to make sense. Maybe those should change to 'if (ret !=
BLK_STS_OK)' so the check uses the same symbol as the return, and will always work in the unlikely event that the defines are reordered.
If you think this version is inconsistent I'd rather drop this patch. The assumption that 0 == BLK_STS_OK is inherent all over the code.