]> www.infradead.org Git - users/hch/misc.git/commitdiff
nvme-pci: rework the build time assert for NVME_MAX_NR_DESCRIPTORS nvme-new-dma-api
authorChristoph Hellwig <hch@lst.de>
Thu, 5 Jun 2025 11:18:44 +0000 (13:18 +0200)
committerChristoph Hellwig <hch@lst.de>
Tue, 10 Jun 2025 05:06:34 +0000 (07:06 +0200)
The current use of an always_inline helper is a bit convoluted.
Instead use macros that represent the arithmerics used for building
up the PRP chain.

Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/host/pci.c

index 735f448d8db2ef6dbf69f3c2f5d990eb4469a50a..0f07599e0980abf1a8a59ad663696616becf2f3d 100644 (file)
 #define NVME_MAX_META_SEGS \
        ((NVME_SMALL_POOL_SIZE / sizeof(struct nvme_sgl_desc)) - 1)
 
+/*
+ * The last entry is used to link to the next descriptor.
+ */
+#define PRPS_PER_PAGE \
+       (((NVME_CTRL_PAGE_SIZE / sizeof(__le64))) - 1)
+
+/*
+ * I/O could be non-aligned both at the beginning and end.
+ */
+#define MAX_PRP_RANGE \
+       (NVME_MAX_BYTES + 2 * (NVME_CTRL_PAGE_SIZE - 1))
+
+static_assert(MAX_PRP_RANGE / NVME_CTRL_PAGE_SIZE <=
+       (1 /* prp1 */ + NVME_MAX_NR_DESCRIPTORS * PRPS_PER_PAGE));
+
 static int use_threaded_interrupts;
 module_param(use_threaded_interrupts, int, 0444);
 
@@ -405,18 +420,6 @@ static bool nvme_dbbuf_update_and_check_event(u16 value, __le32 *dbbuf_db,
        return true;
 }
 
-/*
- * Will slightly overestimate the number of pages needed.  This is OK
- * as it only leads to a small amount of wasted memory for the lifetime of
- * the I/O.
- */
-static __always_inline int nvme_pci_npages_prp(void)
-{
-       unsigned max_bytes = NVME_MAX_BYTES + NVME_CTRL_PAGE_SIZE;
-       unsigned nprps = DIV_ROUND_UP(max_bytes, NVME_CTRL_PAGE_SIZE);
-       return DIV_ROUND_UP(8 * nprps, NVME_CTRL_PAGE_SIZE - 8);
-}
-
 static struct nvme_descriptor_pools *
 nvme_setup_descriptor_pools(struct nvme_dev *dev, unsigned numa_node)
 {
@@ -3934,7 +3937,6 @@ static int __init nvme_init(void)
        BUILD_BUG_ON(sizeof(struct nvme_create_sq) != 64);
        BUILD_BUG_ON(sizeof(struct nvme_delete_queue) != 64);
        BUILD_BUG_ON(IRQ_AFFINITY_MAX_SETS < 2);
-       BUILD_BUG_ON(nvme_pci_npages_prp() > NVME_MAX_NR_DESCRIPTORS);
 
        return pci_register_driver(&nvme_driver);
 }