From: Christoph Hellwig <hch@lst.de>
To: Keith Busch <kbusch@kernel.org>
Cc: Sagi Grimberg <sagi@grimberg.me>,
Chaitanya Kulkarni <kch@nvidia.com>,
Gerd Bayer <gbayer@linux.ibm.com>,
asahi@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
linux-nvme@lists.infradead.org
Subject: [PATCH 06/12] nvme-pci: factor the iod mempool creation into a helper
Date: Tue, 8 Nov 2022 16:02:46 +0100 [thread overview]
Message-ID: <20221108150252.2123727-7-hch@lst.de> (raw)
In-Reply-To: <20221108150252.2123727-1-hch@lst.de>
Add a helper to create the iod mempool.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
drivers/nvme/host/pci.c | 41 ++++++++++++++++++-----------------------
1 file changed, 18 insertions(+), 23 deletions(-)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index b638f43f2df26..f7dab65bf5042 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -390,14 +390,6 @@ static int nvme_pci_npages_sgl(void)
PAGE_SIZE);
}
-static size_t nvme_pci_iod_alloc_size(void)
-{
- size_t npages = max(nvme_pci_npages_prp(), nvme_pci_npages_sgl());
-
- return sizeof(__le64 *) * npages +
- sizeof(struct scatterlist) * NVME_MAX_SEGS;
-}
-
static int nvme_admin_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
unsigned int hctx_idx)
{
@@ -2762,6 +2754,22 @@ static void nvme_release_prp_pools(struct nvme_dev *dev)
dma_pool_destroy(dev->prp_small_pool);
}
+static int nvme_pci_alloc_iod_mempool(struct nvme_dev *dev)
+{
+ size_t npages = max(nvme_pci_npages_prp(), nvme_pci_npages_sgl());
+ size_t alloc_size = sizeof(__le64 *) * npages +
+ sizeof(struct scatterlist) * NVME_MAX_SEGS;
+
+ WARN_ON_ONCE(alloc_size > PAGE_SIZE);
+ dev->iod_mempool = mempool_create_node(1,
+ mempool_kmalloc, mempool_kfree,
+ (void *)alloc_size, GFP_KERNEL,
+ dev_to_node(dev->dev));
+ if (!dev->iod_mempool)
+ return -ENOMEM;
+ return 0;
+}
+
static void nvme_free_tagset(struct nvme_dev *dev)
{
if (dev->tagset.tags)
@@ -3087,7 +3095,6 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
int node, result = -ENOMEM;
struct nvme_dev *dev;
unsigned long quirks = id->driver_data;
- size_t alloc_size;
node = dev_to_node(&pdev->dev);
if (node == NUMA_NO_NODE)
@@ -3132,21 +3139,9 @@ static int nvme_probe(struct pci_dev *pdev, const struct pci_device_id *id)
quirks |= NVME_QUIRK_SIMPLE_SUSPEND;
}
- /*
- * Double check that our mempool alloc size will cover the biggest
- * command we support.
- */
- alloc_size = nvme_pci_iod_alloc_size();
- WARN_ON_ONCE(alloc_size > PAGE_SIZE);
-
- dev->iod_mempool = mempool_create_node(1, mempool_kmalloc,
- mempool_kfree,
- (void *) alloc_size,
- GFP_KERNEL, node);
- if (!dev->iod_mempool) {
- result = -ENOMEM;
+ result = nvme_pci_alloc_iod_mempool(dev);
+ if (result)
goto release_pools;
- }
result = nvme_init_ctrl(&dev->ctrl, &pdev->dev, &nvme_pci_ctrl_ops,
quirks);
--
2.30.2
next prev parent reply other threads:[~2022-11-08 15:05 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-08 15:02 RFC: nvme-pci: split the probe and reset handlers Christoph Hellwig
2022-11-08 15:02 ` [PATCH 01/12] nvme-pci: don't call nvme_init_ctrl_finish from nvme_passthru_end Christoph Hellwig
2022-11-09 2:55 ` Sagi Grimberg
2022-11-09 6:26 ` Christoph Hellwig
2022-11-08 15:02 ` [PATCH 02/12] nvme: move OPAL setup from PCIe to core Christoph Hellwig
2022-11-09 2:55 ` Sagi Grimberg
2022-11-09 20:44 ` Keith Busch
2022-11-09 23:22 ` Chaitanya Kulkarni
2022-11-13 16:15 ` Christoph Hellwig
2022-11-08 15:02 ` [PATCH 03/12] nvme: simplify transport specific device attribute handling Christoph Hellwig
2022-11-09 2:57 ` Sagi Grimberg
2022-11-08 15:02 ` [PATCH 04/12] nvme-pci: put the admin queue in nvme_dev_remove_admin Christoph Hellwig
2022-11-09 2:58 ` Sagi Grimberg
2022-11-09 6:28 ` Christoph Hellwig
2022-11-08 15:02 ` [PATCH 05/12] nvme-pci: move more teardown work to nvme_remove Christoph Hellwig
2022-11-09 3:00 ` Sagi Grimberg
2022-11-08 15:02 ` Christoph Hellwig [this message]
2022-11-09 3:00 ` [PATCH 06/12] nvme-pci: factor the iod mempool creation into a helper Sagi Grimberg
2022-11-08 15:02 ` [PATCH 07/12] nvme-pci: factor out a nvme_pci_alloc_ctrl helper Christoph Hellwig
2022-11-09 3:03 ` Sagi Grimberg
2022-11-09 6:28 ` Christoph Hellwig
2022-11-08 15:02 ` [PATCH 08/12] nvme-pci: set constant paramters in nvme_pci_alloc_ctrl Christoph Hellwig
2022-11-09 3:03 ` Sagi Grimberg
2022-11-08 15:02 ` [PATCH 09/12] nvme-pci: call nvme_pci_configure_admin_queue from nvme_pci_enable Christoph Hellwig
2022-11-09 3:04 ` Sagi Grimberg
2022-11-08 15:02 ` [PATCH 10/12] nvme-pci: split nvme_dbbuf_dma_alloc Christoph Hellwig
2022-11-09 3:05 ` Sagi Grimberg
2022-11-08 15:02 ` [PATCH 11/12] nvme-pci: split the initial probe from the rest path Christoph Hellwig
2022-11-09 3:14 ` Sagi Grimberg
2022-11-09 6:31 ` Christoph Hellwig
2022-11-09 17:00 ` Keith Busch
2022-11-09 15:18 ` Gerd Bayer
2022-11-09 15:51 ` Keith Busch
2022-11-09 15:56 ` Keith Busch
2022-11-10 3:17 ` Chao Leng
2022-11-13 16:19 ` Christoph Hellwig
2022-11-08 15:02 ` [PATCH 12/12] nvme-pci: don't unbind the driver on reset failure Christoph Hellwig
2022-11-09 3:15 ` Sagi Grimberg
2022-11-09 17:10 ` Keith Busch
2022-11-09 17:12 ` RFC: nvme-pci: split the probe and reset handlers Keith Busch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221108150252.2123727-7-hch@lst.de \
--to=hch@lst.de \
--cc=asahi@lists.linux.dev \
--cc=gbayer@linux.ibm.com \
--cc=kbusch@kernel.org \
--cc=kch@nvidia.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox