[PATCH 4/4] nvme-pci: remove the dev->q_depth field

Christoph Hellwig hch at lst.de
Sun Dec 25 02:32:34 PST 2022


This field duplicates the sqsize field in the common nvme_ctrl structure,
so remove it and use the common field instead.

Signed-off-by: Christoph Hellwig <hch at lst.de>
---
 drivers/nvme/host/pci.c | 30 +++++++++++++-----------------
 1 file changed, 13 insertions(+), 17 deletions(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index a621dd7a0a8efa..59ef702f910efa 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -126,7 +126,6 @@ struct nvme_dev {
 	unsigned max_qid;
 	unsigned io_queues[HCTX_MAX_TYPES];
 	unsigned int num_vecs;
-	u32 q_depth;
 	int io_sqes;
 	u32 db_stride;
 	void __iomem *bar;
@@ -1515,7 +1514,7 @@ static void nvme_reap_pending_cqes(struct nvme_dev *dev)
 static int nvme_cmb_qdepth(struct nvme_dev *dev, int nr_io_queues,
 				int entry_size)
 {
-	int q_depth = dev->q_depth;
+	u16 q_depth = dev->ctrl.sqsize;
 	unsigned q_size_aligned = roundup(q_depth * entry_size,
 					  NVME_CTRL_PAGE_SIZE);
 
@@ -1824,7 +1823,7 @@ static int nvme_create_io_queues(struct nvme_dev *dev)
 	int ret = 0;
 
 	for (i = dev->ctrl.queue_count; i <= dev->max_qid; i++) {
-		if (nvme_alloc_queue(dev, i, dev->q_depth)) {
+		if (nvme_alloc_queue(dev, i, dev->ctrl.sqsize)) {
 			ret = -ENOMEM;
 			break;
 		}
@@ -2333,12 +2332,10 @@ static int nvme_setup_io_queues(struct nvme_dev *dev)
 	if (dev->cmb_use_sqes) {
 		result = nvme_cmb_qdepth(dev, nr_io_queues,
 				sizeof(struct nvme_command));
-		if (result > 0) {
-			dev->q_depth = result;
+		if (result > 0)
 			dev->ctrl.sqsize = result;
-		} else {
+		else
 			dev->cmb_use_sqes = false;
-		}
 	}
 
 	do {
@@ -2537,8 +2534,8 @@ static int nvme_pci_enable(struct nvme_dev *dev)
 
 	dev->ctrl.cap = lo_hi_readq(dev->bar + NVME_REG_CAP);
 
-	dev->q_depth = min_t(u32, NVME_CAP_MQES(dev->ctrl.cap) + 1,
-				io_queue_depth);
+	dev->ctrl.sqsize = min_t(u32, NVME_CAP_MQES(dev->ctrl.cap) + 1,
+				 io_queue_depth);
 	dev->db_stride = 1 << NVME_CAP_STRIDE(dev->ctrl.cap);
 	dev->dbs = dev->bar + 4096;
 
@@ -2557,16 +2554,16 @@ static int nvme_pci_enable(struct nvme_dev *dev)
 	 * some MacBook7,1 to avoid controller resets and data loss.
 	 */
 	if (pdev->vendor == PCI_VENDOR_ID_APPLE && pdev->device == 0x2001) {
-		dev->q_depth = 2;
+		dev->ctrl.sqsize = 2;
 		dev_warn(dev->ctrl.device, "detected Apple NVMe controller, "
 			"set queue depth=%u to work around controller resets\n",
-			dev->q_depth);
+			dev->ctrl.sqsize);
 	} else if (pdev->vendor == PCI_VENDOR_ID_SAMSUNG &&
 		   (pdev->device == 0xa821 || pdev->device == 0xa822) &&
 		   NVME_CAP_MQES(dev->ctrl.cap) == 0) {
-		dev->q_depth = 64;
+		dev->ctrl.sqsize = 64;
 		dev_err(dev->ctrl.device, "detected PM1725 NVMe controller, "
-                        "set queue depth=%u\n", dev->q_depth);
+                        "set queue depth=%u\n", dev->ctrl.sqsize);
 	}
 
 	/*
@@ -2574,12 +2571,11 @@ static int nvme_pci_enable(struct nvme_dev *dev)
 	 * big enough so that we get 32 tags for the admin queue
 	 */
 	if ((dev->ctrl.quirks & NVME_QUIRK_SHARED_TAGS) &&
-	    (dev->q_depth < (NVME_AQ_DEPTH + 2))) {
-		dev->q_depth = NVME_AQ_DEPTH + 2;
+	    (dev->ctrl.sqsize < NVME_AQ_DEPTH + 2)) {
+		dev->ctrl.sqsize = NVME_AQ_DEPTH + 2;
 		dev_warn(dev->ctrl.device, "IO queue depth clamped to %d\n",
-			 dev->q_depth);
+			 dev->ctrl.sqsize);
 	}
-	dev->ctrl.sqsize = dev->q_depth;
 
 	nvme_map_cmb(dev);
 
-- 
2.35.1




More information about the Linux-nvme mailing list