[PATCH 1/1] nvme: initialize CMB only if supported
Max Gurtovoy
maxg at mellanox.com
Mon Jun 29 05:38:53 EDT 2020
According to the NVMe specification revision 1.4 (CMBS):
"If set to ‘1’, this bit indicates that the controller supports the
Controller Memory Buffer, and that addresses supplied by the host are
permitted to reference the Controller Memory Buffer only if the host has
enabled the Controller Memory Buffer’s controller memory space. If the
controller supports the Controller Memory Buffer, this bit shall be set
to ‘1’."
Also, while we're here, add more macro definitions related to CMB
registers added to revision 1.4 of the spec.
Signed-off-by: Max Gurtovoy <maxg at mellanox.com>
---
drivers/nvme/host/pci.c | 5 ++++-
include/linux/nvme.h | 11 +++++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index b1d18f0..1698b5f 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1762,6 +1762,10 @@ static void nvme_map_cmb(struct nvme_dev *dev)
struct pci_dev *pdev = to_pci_dev(dev->dev);
int bar;
+ if (readl(dev->bar + NVME_REG_VS) >= NVME_VS(1, 4, 0) &&
+ !NVME_CAP_CMBS(dev->ctrl.cap))
+ return;
+
if (dev->cmb_size)
return;
@@ -2364,7 +2368,6 @@ static int nvme_pci_enable(struct nvme_dev *dev)
dev->q_depth);
}
-
nvme_map_cmb(dev);
pci_enable_pcie_error_reporting(pdev);
diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index 5ce51ab..3afd490 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -116,6 +116,10 @@ enum {
NVME_REG_BPMBL = 0x0048, /* Boot Partition Memory Buffer
* Location
*/
+ NVME_REG_CMBMSC = 0x0050, /* Controller Memory Buffer Memory
+ * Space Control
+ */
+ NVME_REG_CMBSTS = 0x0058, /* Controller Memory Buffer Status */
NVME_REG_PMRCAP = 0x0e00, /* Persistent Memory Capabilities */
NVME_REG_PMRCTL = 0x0e04, /* Persistent Memory Region Control */
NVME_REG_PMRSTS = 0x0e08, /* Persistent Memory Region Status */
@@ -134,8 +138,15 @@ enum {
#define NVME_CAP_NSSRC(cap) (((cap) >> 36) & 0x1)
#define NVME_CAP_MPSMIN(cap) (((cap) >> 48) & 0xf)
#define NVME_CAP_MPSMAX(cap) (((cap) >> 52) & 0xf)
+#define NVME_CAP_CMBS(cap) (((cap) >> 57) & 0x1)
#define NVME_CMB_BIR(cmbloc) ((cmbloc) & 0x7)
+#define NVME_CMB_QMMS(cmbloc) (((cmbloc) >> 3) & 0x1)
+#define NVME_CMB_QPDS(cmbloc) (((cmbloc) >> 4) & 0x1)
+#define NVME_CMB_DPMLS(cmbloc) (((cmbloc) >> 5) & 0x1)
+#define NVME_CMB_DPCILS(cmbloc) (((cmbloc) >> 6) & 0x1)
+#define NVME_CMB_DMMMS(cmbloc) (((cmbloc) >> 7) & 0x1)
+#define NVME_CMB_QDA(cmbloc) (((cmbloc) >> 8) & 0x1)
#define NVME_CMB_OFST(cmbloc) (((cmbloc) >> 12) & 0xfffff)
enum {
--
1.8.3.1
More information about the Linux-nvme
mailing list