linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] nvme: allow use of cmb on v1.4 controllers
@ 2021-01-15  6:30 Klaus Jensen
  2021-01-15  6:32 ` Klaus Jensen
  2021-01-18 17:59 ` Christoph Hellwig
  0 siblings, 2 replies; 4+ messages in thread
From: Klaus Jensen @ 2021-01-15  6:30 UTC (permalink / raw)
  To: linux-nvme
  Cc: Jens Axboe, Klaus Jensen, linux-kernel, Keith Busch,
	Christoph Hellwig, Sagi Grimberg, Klaus Jensen

From: Klaus Jensen <k.jensen@samsung.com>

Since NVMe v1.4 the Controller Memory Buffer must be explicitly enabled
by the host.

Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 drivers/nvme/host/pci.c | 13 ++++++++++++-
 include/linux/nvme.h    |  6 ++++++
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 50d9a20568a2..62eb83030a5a 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -23,6 +23,7 @@
 #include <linux/t10-pi.h>
 #include <linux/types.h>
 #include <linux/io-64-nonatomic-lo-hi.h>
+#include <linux/io-64-nonatomic-hi-lo.h>
 #include <linux/sed-opal.h>
 #include <linux/pci-p2pdma.h>
 
@@ -1787,7 +1788,7 @@ static u32 nvme_cmb_size(struct nvme_dev *dev)
 
 static void nvme_map_cmb(struct nvme_dev *dev)
 {
-	u64 size, offset;
+	u64 size, offset, cmbmsc;
 	resource_size_t bar_size;
 	struct pci_dev *pdev = to_pci_dev(dev->dev);
 	int bar;
@@ -1795,6 +1796,9 @@ static void nvme_map_cmb(struct nvme_dev *dev)
 	if (dev->cmb_size)
 		return;
 
+	if (NVME_CAP_CMBS(dev->ctrl.cap))
+		writel(NVME_CMBMSC_CRE, dev->bar + NVME_REG_CMBMSC);
+
 	dev->cmbsz = readl(dev->bar + NVME_REG_CMBSZ);
 	if (!dev->cmbsz)
 		return;
@@ -1808,6 +1812,13 @@ static void nvme_map_cmb(struct nvme_dev *dev)
 	if (offset > bar_size)
 		return;
 
+	if (NVME_CAP_CMBS(dev->ctrl.cap)) {
+		cmbmsc = pci_bus_address(pdev, bar) + offset;
+		cmbmsc |= (NVME_CMBMSC_CRE | NVME_CMBMSC_CMSE);
+
+		hi_lo_writeq(cmbmsc, dev->bar + NVME_REG_CMBMSC);
+	}
+
 	/*
 	 * Controllers may support a CMB size larger than their BAR,
 	 * for example, due to being behind a bridge. Reduce the CMB to
diff --git a/include/linux/nvme.h b/include/linux/nvme.h
index d92535997687..bfed36e342cc 100644
--- a/include/linux/nvme.h
+++ b/include/linux/nvme.h
@@ -116,6 +116,9 @@ enum {
 	NVME_REG_BPMBL	= 0x0048,	/* Boot Partition Memory Buffer
 					 * Location
 					 */
+	NVME_REG_CMBMSC = 0x0050,	/* Controller Memory Buffer Memory
+					 * Space Control
+					 */
 	NVME_REG_PMRCAP	= 0x0e00,	/* Persistent Memory Capabilities */
 	NVME_REG_PMRCTL	= 0x0e04,	/* Persistent Memory Region Control */
 	NVME_REG_PMRSTS	= 0x0e08,	/* Persistent Memory Region Status */
@@ -135,6 +138,7 @@ enum {
 #define NVME_CAP_CSS(cap)	(((cap) >> 37) & 0xff)
 #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_OFST(cmbloc)	(((cmbloc) >> 12) & 0xfffff)
@@ -192,6 +196,8 @@ enum {
 	NVME_CSTS_SHST_OCCUR	= 1 << 2,
 	NVME_CSTS_SHST_CMPLT	= 2 << 2,
 	NVME_CSTS_SHST_MASK	= 3 << 2,
+	NVME_CMBMSC_CRE		= 1 << 0,
+	NVME_CMBMSC_CMSE	= 1 << 1,
 };
 
 struct nvme_id_power_state {
-- 
2.30.0


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

* Re: [PATCH v2] nvme: allow use of cmb on v1.4 controllers
  2021-01-15  6:30 [PATCH v2] nvme: allow use of cmb on v1.4 controllers Klaus Jensen
@ 2021-01-15  6:32 ` Klaus Jensen
  2021-01-18 17:59 ` Christoph Hellwig
  1 sibling, 0 replies; 4+ messages in thread
From: Klaus Jensen @ 2021-01-15  6:32 UTC (permalink / raw)
  To: linux-nvme
  Cc: Sagi Grimberg, Klaus Jensen, linux-kernel, Jens Axboe,
	Keith Busch, Christoph Hellwig

[-- Attachment #1: Type: text/plain, Size: 462 bytes --]

On Jan 15 07:30, Klaus Jensen wrote:
> From: Klaus Jensen <k.jensen@samsung.com>
> 
> Since NVMe v1.4 the Controller Memory Buffer must be explicitly enabled
> by the host.
> 

Sorry, messed up and missed adding the changes for v2.

v2:
  - Do not explicitly check the NVMe version, rely on the presence of
    the new register instead. (Christoph)
  - Use hi_lo_writeq. (Christoph, Keith)
  - Fix missing offset and use pci_bus_address(). (Keith)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2] nvme: allow use of cmb on v1.4 controllers
  2021-01-15  6:30 [PATCH v2] nvme: allow use of cmb on v1.4 controllers Klaus Jensen
  2021-01-15  6:32 ` Klaus Jensen
@ 2021-01-18 17:59 ` Christoph Hellwig
  2021-01-18 18:29   ` Klaus Jensen
  1 sibling, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2021-01-18 17:59 UTC (permalink / raw)
  To: Klaus Jensen
  Cc: linux-nvme, Jens Axboe, linux-kernel, Keith Busch,
	Christoph Hellwig, Sagi Grimberg, Klaus Jensen

Thanks,

applied to nvme-5.11 with a little tweak to remove the cmbmsc local
variable and a comment explaining what is going on.

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

* Re: [PATCH v2] nvme: allow use of cmb on v1.4 controllers
  2021-01-18 17:59 ` Christoph Hellwig
@ 2021-01-18 18:29   ` Klaus Jensen
  0 siblings, 0 replies; 4+ messages in thread
From: Klaus Jensen @ 2021-01-18 18:29 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Sagi Grimberg, Klaus Jensen, linux-kernel, linux-nvme,
	Jens Axboe, Keith Busch

[-- Attachment #1: Type: text/plain, Size: 206 bytes --]

On Jan 18 18:59, Christoph Hellwig wrote:
> Thanks,
> 
> applied to nvme-5.11 with a little tweak to remove the cmbmsc local
> variable and a comment explaining what is going on.
> 

Sweet. Thanks!

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2021-01-18 18:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-15  6:30 [PATCH v2] nvme: allow use of cmb on v1.4 controllers Klaus Jensen
2021-01-15  6:32 ` Klaus Jensen
2021-01-18 17:59 ` Christoph Hellwig
2021-01-18 18:29   ` Klaus Jensen

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).