Skip to content

Commit e764f12

Browse files
davejiangdjbw
authored andcommitted
cxl: Move cxl_await_media_ready() to before capacity info retrieval
Move cxl_await_media_ready() to cxl_pci probe before driver starts issuing IDENTIFY and retrieving memory device information to ensure that the device is ready to provide the information. Allow cxl_pci_probe() to succeed even if media is not ready. Cache the media failure in cxlds and don't ask the device for any media information. The rationale for proceeding in the !media_ready case is to allow for mailbox operations to interrogate and/or remediate the device. After media is repaired then rebinding the cxl_pci driver is expected to restart the capacity scan. Suggested-by: Dan Williams <dan.j.williams@intel.com> Fixes: b39cb10 ("cxl/mem: Register CXL memX devices") Reviewed-by: Ira Weiny <ira.weiny@intel.com> Signed-off-by: Dave Jiang <dave.jiang@intel.com> Link: https://lore.kernel.org/r/168445310026.3251520.8124296540679268206.stgit@djiang5-mobl3 [djbw: fixup cxl_test] Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent ce17ad0 commit e764f12

File tree

6 files changed

+22
-11
lines changed

6 files changed

+22
-11
lines changed

drivers/cxl/core/mbox.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ static int cxl_mem_get_partition_info(struct cxl_dev_state *cxlds)
10281028
* cxl_dev_state_identify() - Send the IDENTIFY command to the device.
10291029
* @cxlds: The device data for the operation
10301030
*
1031-
* Return: 0 if identify was executed successfully.
1031+
* Return: 0 if identify was executed successfully or media not ready.
10321032
*
10331033
* This will dispatch the identify command to the device and on success populate
10341034
* structures to be exported to sysfs.
@@ -1041,6 +1041,9 @@ int cxl_dev_state_identify(struct cxl_dev_state *cxlds)
10411041
u32 val;
10421042
int rc;
10431043

1044+
if (!cxlds->media_ready)
1045+
return 0;
1046+
10441047
mbox_cmd = (struct cxl_mbox_cmd) {
10451048
.opcode = CXL_MBOX_OP_IDENTIFY,
10461049
.size_out = sizeof(id),
@@ -1115,10 +1118,12 @@ int cxl_mem_create_range_info(struct cxl_dev_state *cxlds)
11151118
cxlds->persistent_only_bytes, "pmem");
11161119
}
11171120

1118-
rc = cxl_mem_get_partition_info(cxlds);
1119-
if (rc) {
1120-
dev_err(dev, "Failed to query partition information\n");
1121-
return rc;
1121+
if (cxlds->media_ready) {
1122+
rc = cxl_mem_get_partition_info(cxlds);
1123+
if (rc) {
1124+
dev_err(dev, "Failed to query partition information\n");
1125+
return rc;
1126+
}
11221127
}
11231128

11241129
rc = add_dpa_res(dev, &cxlds->dpa_res, &cxlds->ram_res, 0,

drivers/cxl/cxlmem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ struct cxl_poison_state {
266266
* @regs: Parsed register blocks
267267
* @cxl_dvsec: Offset to the PCIe device DVSEC
268268
* @rcd: operating in RCD mode (CXL 3.0 9.11.8 CXL Devices Attached to an RCH)
269+
* @media_ready: Indicate whether the device media is usable
269270
* @payload_size: Size of space for payload
270271
* (CXL 2.0 8.2.8.4.3 Mailbox Capabilities Register)
271272
* @lsa_size: Size of Label Storage Area
@@ -303,6 +304,7 @@ struct cxl_dev_state {
303304
int cxl_dvsec;
304305

305306
bool rcd;
307+
bool media_ready;
306308
size_t payload_size;
307309
size_t lsa_size;
308310
struct mutex mbox_mutex; /* Protects device mailbox and firmware */

drivers/cxl/mem.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ static int cxl_mem_probe(struct device *dev)
124124
struct dentry *dentry;
125125
int rc;
126126

127+
if (!cxlds->media_ready)
128+
return -EBUSY;
129+
127130
/*
128131
* Someone is trying to reattach this device after it lost its port
129132
* connection (an endpoint port previously registered by this memdev was

drivers/cxl/pci.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,12 @@ static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
708708
if (rc)
709709
dev_dbg(&pdev->dev, "Failed to map RAS capability.\n");
710710

711+
rc = cxl_await_media_ready(cxlds);
712+
if (rc == 0)
713+
cxlds->media_ready = true;
714+
else
715+
dev_warn(&pdev->dev, "Media not active (%d)\n", rc);
716+
711717
rc = cxl_pci_setup_mailbox(cxlds);
712718
if (rc)
713719
return rc;

drivers/cxl/port.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,6 @@ static int cxl_endpoint_port_probe(struct cxl_port *port)
117117
if (rc)
118118
return rc;
119119

120-
rc = cxl_await_media_ready(cxlds);
121-
if (rc) {
122-
dev_err(&port->dev, "Media not active (%d)\n", rc);
123-
return rc;
124-
}
125-
126120
rc = devm_cxl_enumerate_decoders(cxlhdm, &info);
127121
if (rc)
128122
return rc;

tools/testing/cxl/test/mem.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,7 @@ static int cxl_mock_mem_probe(struct platform_device *pdev)
12561256
if (rc)
12571257
return rc;
12581258

1259+
cxlds->media_ready = true;
12591260
rc = cxl_dev_state_identify(cxlds);
12601261
if (rc)
12611262
return rc;

0 commit comments

Comments
 (0)