From: Leon Romanovsky Date: Sat, 10 May 2025 05:22:06 +0000 (+0200) Subject: nvme-pci: add a symolic name for the small pool size X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=eafa9130cc65cdd9b94a859471bacaf5c4eab838;p=users%2Fhch%2Fmisc.git nvme-pci: add a symolic name for the small pool size Open coding magic numbers in multiple places is never a good idea. Signed-off-by: Leon Romanovsky [hch: split from a larger patch] Signed-off-by: Christoph Hellwig --- diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c index 413b9fc8e171..cf5c105d5b8f 100644 --- a/drivers/nvme/host/pci.c +++ b/drivers/nvme/host/pci.c @@ -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;