Commit 32ce3f18 authored by Dan Williams's avatar Dan Williams

cxl/port: Split endpoint and switch port probe

Jonathan points out that the shared code between the switch and endpoint
case is small. Before adding another is_cxl_endpoint() conditional,
just split the two cases.

Rather than duplicate the "Couldn't enumerate decoders" error message
take the opportunity to improve the error messages in
devm_cxl_enumerate_decoders().
Reported-by: default avatarJonathan Cameron <Jonathan.Cameron@Huawei.com>
Reviewed-by: default avatarVishal Verma <vishal.l.verma@intel.com>
Reviewed-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/167601999378.1924368.15071142145866277623.stgit@dwillia2-xfh.jf.intel.comSigned-off-by: default avatarDan Williams <dan.j.williams@intel.com>
parent 45d235c5
...@@ -826,7 +826,8 @@ int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm) ...@@ -826,7 +826,8 @@ int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm)
cxled = cxl_endpoint_decoder_alloc(port); cxled = cxl_endpoint_decoder_alloc(port);
if (IS_ERR(cxled)) { if (IS_ERR(cxled)) {
dev_warn(&port->dev, dev_warn(&port->dev,
"Failed to allocate the decoder\n"); "Failed to allocate decoder%d.%d\n",
port->id, i);
return PTR_ERR(cxled); return PTR_ERR(cxled);
} }
cxld = &cxled->cxld; cxld = &cxled->cxld;
...@@ -836,7 +837,8 @@ int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm) ...@@ -836,7 +837,8 @@ int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm)
cxlsd = cxl_switch_decoder_alloc(port, target_count); cxlsd = cxl_switch_decoder_alloc(port, target_count);
if (IS_ERR(cxlsd)) { if (IS_ERR(cxlsd)) {
dev_warn(&port->dev, dev_warn(&port->dev,
"Failed to allocate the decoder\n"); "Failed to allocate decoder%d.%d\n",
port->id, i);
return PTR_ERR(cxlsd); return PTR_ERR(cxlsd);
} }
cxld = &cxlsd->cxld; cxld = &cxlsd->cxld;
...@@ -844,13 +846,16 @@ int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm) ...@@ -844,13 +846,16 @@ int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm)
rc = init_hdm_decoder(port, cxld, target_map, hdm, i, &dpa_base); rc = init_hdm_decoder(port, cxld, target_map, hdm, i, &dpa_base);
if (rc) { if (rc) {
dev_warn(&port->dev,
"Failed to initialize decoder%d.%d\n",
port->id, i);
put_device(&cxld->dev); put_device(&cxld->dev);
return rc; return rc;
} }
rc = add_hdm_decoder(port, cxld, target_map); rc = add_hdm_decoder(port, cxld, target_map);
if (rc) { if (rc) {
dev_warn(&port->dev, dev_warn(&port->dev,
"Failed to add decoder to port\n"); "Failed to add decoder%d.%d\n", port->id, i);
return rc; return rc;
} }
} }
......
...@@ -30,55 +30,64 @@ static void schedule_detach(void *cxlmd) ...@@ -30,55 +30,64 @@ static void schedule_detach(void *cxlmd)
schedule_cxl_memdev_detach(cxlmd); schedule_cxl_memdev_detach(cxlmd);
} }
static int cxl_port_probe(struct device *dev) static int cxl_switch_port_probe(struct cxl_port *port)
{ {
struct cxl_port *port = to_cxl_port(dev);
struct cxl_hdm *cxlhdm; struct cxl_hdm *cxlhdm;
int rc; int rc;
rc = devm_cxl_port_enumerate_dports(port);
if (rc < 0)
return rc;
if (!is_cxl_endpoint(port)) { if (rc == 1)
rc = devm_cxl_port_enumerate_dports(port); return devm_cxl_add_passthrough_decoder(port);
if (rc < 0)
return rc;
if (rc == 1)
return devm_cxl_add_passthrough_decoder(port);
}
cxlhdm = devm_cxl_setup_hdm(port); cxlhdm = devm_cxl_setup_hdm(port);
if (IS_ERR(cxlhdm)) if (IS_ERR(cxlhdm))
return PTR_ERR(cxlhdm); return PTR_ERR(cxlhdm);
if (is_cxl_endpoint(port)) { return devm_cxl_enumerate_decoders(cxlhdm);
struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport); }
struct cxl_dev_state *cxlds = cxlmd->cxlds;
/* Cache the data early to ensure is_visible() works */ static int cxl_endpoint_port_probe(struct cxl_port *port)
read_cdat_data(port); {
struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport);
struct cxl_dev_state *cxlds = cxlmd->cxlds;
struct cxl_hdm *cxlhdm;
int rc;
cxlhdm = devm_cxl_setup_hdm(port);
if (IS_ERR(cxlhdm))
return PTR_ERR(cxlhdm);
get_device(&cxlmd->dev); /* Cache the data early to ensure is_visible() works */
rc = devm_add_action_or_reset(dev, schedule_detach, cxlmd); read_cdat_data(port);
if (rc)
return rc;
rc = cxl_hdm_decode_init(cxlds, cxlhdm); get_device(&cxlmd->dev);
if (rc) rc = devm_add_action_or_reset(&port->dev, schedule_detach, cxlmd);
return rc; if (rc)
return rc;
rc = cxl_await_media_ready(cxlds); rc = cxl_hdm_decode_init(cxlds, cxlhdm);
if (rc) { if (rc)
dev_err(dev, "Media not active (%d)\n", rc); return rc;
return rc;
}
}
rc = devm_cxl_enumerate_decoders(cxlhdm); rc = cxl_await_media_ready(cxlds);
if (rc) { if (rc) {
dev_err(dev, "Couldn't enumerate decoders (%d)\n", rc); dev_err(&port->dev, "Media not active (%d)\n", rc);
return rc; return rc;
} }
return 0; return devm_cxl_enumerate_decoders(cxlhdm);
}
static int cxl_port_probe(struct device *dev)
{
struct cxl_port *port = to_cxl_port(dev);
if (is_cxl_endpoint(port))
return cxl_endpoint_port_probe(port);
return cxl_switch_port_probe(port);
} }
static ssize_t CDAT_read(struct file *filp, struct kobject *kobj, static ssize_t CDAT_read(struct file *filp, struct kobject *kobj,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment