From: Ben Widawsky <ben.widawsky@intel.com>
To: linux-cxl@vger.kernel.org
Cc: Ben Widawsky <ben.widawsky@intel.com>,
Alison Schofield <alison.schofield@intel.com>,
Dan Williams <dan.j.williams@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
Jonathan Cameron <Jonathan.Cameron@Huawei.com>,
Vishal Verma <vishal.l.verma@intel.com>
Subject: [PATCH v2 08/14] cxl/pci: Implement wait for media active
Date: Wed, 1 Dec 2021 20:37:44 -0800 [thread overview]
Message-ID: <20211202043750.3501494-9-ben.widawsky@intel.com> (raw)
In-Reply-To: <20211202043750.3501494-1-ben.widawsky@intel.com>
The CXL Type 3 Memory Device Software Guide (Revision 1.0) describes the
need to check media active before using HDM. CXL 2.0 8.1.3.8.2 states:
Memory_Active: When set, indicates that the CXL Range 1 memory is
fully initialized and available for software use. Must be set within
Range 1. Memory_Active_Timeout of deassertion of reset to CXL device
if CXL.mem HwInit Mode=1
Unfortunately, Memory_Active can take quite a long time depending on
media size (up to 256s per 2.0 spec). Since the cxl_pci driver doesn't
care about this, a callback is exported as part of driver state for use
by drivers that do care. The implementation waits for 60s as that is
considered more than enough and falls within typical Linux timeout
lengths.
Signed-off-by: Ben Widawsky <ben.widawsky@intel.com>
---
drivers/cxl/cxlmem.h | 1 +
drivers/cxl/pci.c | 59 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 60 insertions(+)
diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
index 8d0a14c53518..47651432e2ae 100644
--- a/drivers/cxl/cxlmem.h
+++ b/drivers/cxl/cxlmem.h
@@ -163,6 +163,7 @@ struct cxl_dev_state {
struct cxl_endpoint_dvsec_info *info;
int (*mbox_send)(struct cxl_dev_state *cxlds, struct cxl_mbox_cmd *cmd);
+ int (*wait_media_ready)(struct cxl_dev_state *cxlds);
};
enum cxl_opcode {
diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c
index 4e00abde5dbb..e7523a7614a4 100644
--- a/drivers/cxl/pci.c
+++ b/drivers/cxl/pci.c
@@ -466,6 +466,63 @@ static int wait_for_valid(struct cxl_dev_state *cxlds)
return valid ? 0 : -ETIMEDOUT;
}
+/*
+ * Implements Figure 43 of the CXL Type 3 Memory Device Software Guide. Waits a
+ * full 60s no matter what the device reports.
+ */
+static int wait_for_media_ready(struct cxl_dev_state *cxlds)
+{
+ const unsigned long timeout = jiffies + (60 * HZ);
+ struct pci_dev *pdev = to_pci_dev(cxlds->dev);
+ int d = cxlds->device_dvsec;
+ u64 md_status;
+ bool active;
+ int rc;
+
+ rc = wait_for_valid(cxlds);
+ if (rc)
+ return rc;
+
+ do {
+ u64 size;
+ u32 temp;
+ int rc;
+
+ rc = pci_read_config_dword(pdev,
+ d + CXL_DVSEC_PCIE_DEVICE_RANGE_SIZE_HIGH_OFFSET(0),
+ &temp);
+ if (rc)
+ return -ENXIO;
+ size = (u64)temp << 32;
+
+ rc = pci_read_config_dword(pdev,
+ d + CXL_DVSEC_PCIE_DEVICE_RANGE_SIZE_LOW_OFFSET(0),
+ &temp);
+ if (rc)
+ return -ENXIO;
+ size |= temp & CXL_DVSEC_PCIE_DEVICE_MEM_SIZE_LOW_MASK;
+
+ active = FIELD_GET(CXL_DVSEC_PCIE_DEVICE_MEM_ACTIVE, temp);
+ if (active)
+ break;
+ cpu_relax();
+ mdelay(100);
+ } while (!time_after(jiffies, timeout));
+
+ if (!active)
+ return -ETIMEDOUT;
+
+ rc = check_device_status(cxlds);
+ if (rc)
+ return rc;
+
+ md_status = readq(cxlds->regs.memdev + CXLMDEV_STATUS_OFFSET);
+ if (!CXLMDEV_READY(md_status))
+ return -EIO;
+
+ return 0;
+}
+
static struct cxl_endpoint_dvsec_info *dvsec_ranges(struct cxl_dev_state *cxlds)
{
struct pci_dev *pdev = to_pci_dev(cxlds->dev);
@@ -579,6 +636,8 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
return -ENXIO;
}
+ cxlds->wait_media_ready = wait_for_media_ready;
+
rc = cxl_setup_regs(pdev, CXL_REGLOC_RBI_MEMDEV, &map);
if (rc)
return rc;
--
2.34.1
next prev parent reply other threads:[~2021-12-02 4:40 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-02 4:37 [PATCH v2 00/14] Add drivers for CXL ports and mem devices Ben Widawsky
2021-12-02 4:37 ` [PATCH v2 01/14] cxl/core: Add, document, and tighten up decoder APIs Ben Widawsky
2021-12-06 10:51 ` Jonathan Cameron
2021-12-02 4:37 ` [PATCH v2 02/14] cxl: Introduce endpoint decoders Ben Widawsky
2021-12-02 4:37 ` [PATCH v2 03/14] cxl/core: Move target population locking to caller Ben Widawsky
2021-12-02 4:37 ` [PATCH v2 04/14] cxl: Introduce topology host registration Ben Widawsky
2021-12-02 5:58 ` Dan Williams
2021-12-03 21:06 ` Dan Williams
2021-12-04 3:21 ` Ben Widawsky
2021-12-02 4:37 ` [PATCH v2 05/14] cxl/core: Store global list of root ports Ben Widawsky
2021-12-02 4:37 ` [PATCH v2 06/14] cxl/pci: Cache device DVSEC offset Ben Widawsky
2021-12-02 4:37 ` [PATCH v2 07/14] cxl: Cache and pass DVSEC ranges Ben Widawsky
2021-12-02 4:37 ` Ben Widawsky [this message]
2021-12-02 4:37 ` [PATCH v2 09/14] cxl/pci: Store component register base in cxlds Ben Widawsky
2021-12-02 4:37 ` [PATCH v2 10/14] cxl: Make passthrough decoder init implicit Ben Widawsky
2021-12-02 4:37 ` [PATCH v2 11/14] cxl/port: Introduce a port driver Ben Widawsky
2021-12-02 6:36 ` Dan Williams
2021-12-02 4:37 ` [PATCH v2 12/14] cxl: Unify port enumeration for decoders Ben Widawsky
2021-12-02 4:37 ` [PATCH v2 13/14] cxl/port: Cleanup adding passthrough decoders Ben Widawsky
2021-12-02 4:37 ` [PATCH v2 14/14] cxl/mem: Introduce cxl_mem driver Ben Widawsky
2021-12-04 4:07 ` Dan Williams
2021-12-15 17:25 ` [PATCH v2 00/14] Add drivers for CXL ports and mem devices Jonathan Cameron
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=20211202043750.3501494-9-ben.widawsky@intel.com \
--to=ben.widawsky@intel.com \
--cc=Jonathan.Cameron@Huawei.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=ira.weiny@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=vishal.l.verma@intel.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.