From: Klaus Jensen <its@irrelevant.dk>
To: linux-nvme@lists.infradead.org
Cc: Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@fb.com>,
Klaus Jensen <k.jensen@samsung.com>,
Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>
Subject: [PATCH] nvme: allow use of cmb on v1.4 controllers
Date: Thu, 14 Jan 2021 14:24:41 +0100 [thread overview]
Message-ID: <20210114132441.193782-1-its@irrelevant.dk> (raw)
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 | 25 ++++++++++++++++++++++++-
include/linux/nvme.h | 6 ++++++
2 files changed, 30 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 50d9a20568a2..9c2bbb242994 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -1787,7 +1787,8 @@ static u32 nvme_cmb_size(struct nvme_dev *dev)
static void nvme_map_cmb(struct nvme_dev *dev)
{
- u64 size, offset;
+ u32 vs;
+ u64 size, offset, cmbmsc;
resource_size_t bar_size;
struct pci_dev *pdev = to_pci_dev(dev->dev);
int bar;
@@ -1795,6 +1796,15 @@ static void nvme_map_cmb(struct nvme_dev *dev)
if (dev->cmb_size)
return;
+ vs = readl(dev->bar + NVME_REG_VS);
+
+ if (vs >= NVME_VS(1, 4, 0)) {
+ if (!NVME_CAP_CMBS(dev->ctrl.cap))
+ return;
+
+ writel(NVME_CMBMSC_CRE, dev->bar + NVME_REG_CMBMSC);
+ }
+
dev->cmbsz = readl(dev->bar + NVME_REG_CMBSZ);
if (!dev->cmbsz)
return;
@@ -1805,6 +1815,19 @@ static void nvme_map_cmb(struct nvme_dev *dev)
bar = NVME_CMB_BIR(dev->cmbloc);
bar_size = pci_resource_len(pdev, bar);
+ if (vs >= NVME_VS(1, 4, 0)) {
+ cmbmsc = pci_resource_start(pdev, bar);
+ cmbmsc |= (NVME_CMBMSC_CRE | NVME_CMBMSC_CMSE);
+
+ /*
+ * Writing the low bits may cause the controller to check the
+ * validity of the 52 bit controller base address in the CMBMSC
+ * register, so write the high bits first.
+ */
+ writel(cmbmsc >> 32, dev->bar + NVME_REG_CMBMSC + 4);
+ writel(cmbmsc, dev->bar + NVME_REG_CMBMSC);
+ }
+
if (offset > bar_size)
return;
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
_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme
next reply other threads:[~2021-01-14 13:25 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-14 13:24 Klaus Jensen [this message]
2021-01-14 17:33 ` [PATCH] nvme: allow use of cmb on v1.4 controllers Christoph Hellwig
2021-01-15 6:12 ` Klaus Jensen
2021-01-14 18:06 ` Keith Busch
2021-01-14 18:15 ` Keith Busch
2021-01-15 6:13 ` Klaus Jensen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210114132441.193782-1-its@irrelevant.dk \
--to=its@irrelevant.dk \
--cc=axboe@fb.com \
--cc=hch@lst.de \
--cc=k.jensen@samsung.com \
--cc=kbusch@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox