linux-nvme.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] nvme: initialize CMB only if supported
@ 2020-06-29  9:38 Max Gurtovoy
  2020-06-29 11:31 ` Christoph Hellwig
  0 siblings, 1 reply; 2+ messages in thread
From: Max Gurtovoy @ 2020-06-29  9:38 UTC (permalink / raw)
  To: sagi, linux-nvme, kbusch, hch; +Cc: israelr, logang, Max Gurtovoy

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@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


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 1/1] nvme: initialize CMB only if supported
  2020-06-29  9:38 [PATCH 1/1] nvme: initialize CMB only if supported Max Gurtovoy
@ 2020-06-29 11:31 ` Christoph Hellwig
  0 siblings, 0 replies; 2+ messages in thread
From: Christoph Hellwig @ 2020-06-29 11:31 UTC (permalink / raw)
  To: Max Gurtovoy; +Cc: sagi, israelr, linux-nvme, kbusch, logang, hch

On Mon, Jun 29, 2020 at 12:38:53PM +0300, Max Gurtovoy wrote:
> 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.

Please read my comment on the previous patch that tried this about a
week or two ago.

_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-29 11:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-29  9:38 [PATCH 1/1] nvme: initialize CMB only if supported Max Gurtovoy
2020-06-29 11:31 ` Christoph Hellwig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).