]> www.infradead.org Git - users/hch/misc.git/commitdiff
nvme-pci: add a symolic name for the small pool size
authorLeon Romanovsky <leon@kernel.org>
Sat, 10 May 2025 05:22:06 +0000 (07:22 +0200)
committerChristoph Hellwig <hch@lst.de>
Sun, 11 May 2025 03:32:35 +0000 (05:32 +0200)
Open coding magic numbers in multiple places is never a good idea.

Signed-off-by: Leon Romanovsky <leon@kernel.org>
[hch: split from a larger patch]
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/host/pci.c

index 413b9fc8e1719e059abd447fb251dafdc1d8f26d..cf5c105d5b8fa13279a9344dcd6bcc19877fb8c4 100644 (file)
@@ -36,6 +36,8 @@
 
 #define SGES_PER_PAGE  (NVME_CTRL_PAGE_SIZE / sizeof(struct nvme_sgl_desc))
 
+#define NVME_SMALL_POOL_SIZE   256
+
 /*
  * These can be higher, but we need to ensure that any command doesn't
  * require an sg allocation that needs more than a page of data.
@@ -632,7 +634,7 @@ static blk_status_t nvme_pci_setup_prps(struct nvme_dev *dev,
        }
 
        if (DIV_ROUND_UP(length, NVME_CTRL_PAGE_SIZE) <=
-           256 / sizeof(__le64))
+           NVME_SMALL_POOL_SIZE / sizeof(__le64))
                iod->flags |= IOD_SMALL_POOL;
 
        prp_list = dma_pool_alloc(nvme_dma_pool(dev, iod), GFP_ATOMIC,
@@ -717,7 +719,7 @@ static blk_status_t nvme_pci_setup_sgls(struct nvme_dev *dev,
                return BLK_STS_OK;
        }
 
-       if (entries <= 256 / sizeof(*sg_list))
+       if (entries <= NVME_SMALL_POOL_SIZE / sizeof(*sg_list))
                iod->flags |= IOD_SMALL_POOL;
 
        sg_list = dma_pool_alloc(nvme_dma_pool(dev, iod), GFP_ATOMIC, &sgl_dma);
@@ -2833,7 +2835,7 @@ static int nvme_disable_prepare_reset(struct nvme_dev *dev, bool shutdown)
 
 static int nvme_setup_prp_pools(struct nvme_dev *dev)
 {
-       size_t small_align = 256;
+       size_t small_align = NVME_SMALL_POOL_SIZE;
 
        dev->prp_page_pool = dma_pool_create("prp list page", dev->dev,
                                                NVME_CTRL_PAGE_SIZE,
@@ -2841,12 +2843,13 @@ static int nvme_setup_prp_pools(struct nvme_dev *dev)
        if (!dev->prp_page_pool)
                return -ENOMEM;
 
+       static_assert(NVME_SMALL_POOL_SIZE < 512);
        if (dev->ctrl.quirks & NVME_QUIRK_DMAPOOL_ALIGN_512)
                small_align = 512;
 
        /* Optimisation for I/Os between 4k and 128k */
-       dev->prp_small_pool = dma_pool_create("prp list 256", dev->dev,
-                                               256, small_align, 0);
+       dev->prp_small_pool = dma_pool_create("prp list small", dev->dev,
+                       NVME_SMALL_POOL_SIZE, small_align, 0);
        if (!dev->prp_small_pool) {
                dma_pool_destroy(dev->prp_page_pool);
                return -ENOMEM;