aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWarner Losh <imp@FreeBSD.org>2022-03-29 19:21:55 +0000
committerWarner Losh <imp@FreeBSD.org>2022-04-01 03:12:38 +0000
commita70b5660f379d6400d8238cbdec6309d2990a0f9 (patch)
treef50403833a17fb593d97215708d52a608d8d1fbf
parentab71bbb75a92412f6327ff152ebe638568e9021c (diff)
downloadsrc-a70b5660f379d6400d8238cbdec6309d2990a0f9.tar.gz
src-a70b5660f379d6400d8238cbdec6309d2990a0f9.zip
nvme: MPS is a power of two, not a size / 8k
Setting MPS in the CC should be a power of 2 number (it specifies the page size of the host is 2^(12+MPS)), so adjust the calcuation. There is no functional change because we do not support any architecutres != 4k pages (yet). Other changes are needed for architectures with 16k or 64k pages, especially when the underlying NVMe drive doesn't support that page size (Most drives support a range that's small, and many only support 4k), but let's at least do this calculation correctly. 12 - 12 is just as much 0 as 4096 >> 13 is :) Sponsored by: Netflix Reviewed by: mav Differential Revision: https://reviews.freebsd.org/D34707
-rw-r--r--sys/dev/nvme/nvme_ctrlr.c2
-rw-r--r--sys/dev/nvme/nvme_private.h5
2 files changed, 6 insertions, 1 deletions
diff --git a/sys/dev/nvme/nvme_ctrlr.c b/sys/dev/nvme/nvme_ctrlr.c
index aa41c8fe5540..a632d7fb68e9 100644
--- a/sys/dev/nvme/nvme_ctrlr.c
+++ b/sys/dev/nvme/nvme_ctrlr.c
@@ -389,7 +389,7 @@ nvme_ctrlr_enable(struct nvme_controller *ctrlr)
cc |= 4 << NVME_CC_REG_IOCQES_SHIFT; /* CQ entry size == 16 == 2^4 */
/* This evaluates to 0, which is according to spec. */
- cc |= (PAGE_SIZE >> 13) << NVME_CC_REG_MPS_SHIFT;
+ cc |= (PAGE_SHIFT - NVME_BASE_SHIFT) << NVME_CC_REG_MPS_SHIFT;
nvme_ctrlr_barrier(ctrlr, BUS_SPACE_BARRIER_WRITE);
nvme_mmio_write_4(ctrlr, cc, cc);
diff --git a/sys/dev/nvme/nvme_private.h b/sys/dev/nvme/nvme_private.h
index c889246f9350..977cc2c8d30d 100644
--- a/sys/dev/nvme/nvme_private.h
+++ b/sys/dev/nvme/nvme_private.h
@@ -97,6 +97,11 @@ MALLOC_DECLARE(M_NVME);
#define NVME_MAX_AER_LOG_SIZE (4096)
/*
+ * Page size parameters
+ */
+#define NVME_BASE_SHIFT 12 /* Several parameters (MSP) are 2^(12+x) */
+
+/*
* Define CACHE_LINE_SIZE here for older FreeBSD versions that do not define
* it.
*/