Skip to content

Commit 32ce3f1

Browse files
committed
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: Jonathan Cameron <[email protected]> Reviewed-by: Vishal Verma <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Link: https://lore.kernel.org/r/167601999378.1924368.15071142145866277623.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent 45d235c commit 32ce3f1

File tree

2 files changed

+47
-33
lines changed

2 files changed

+47
-33
lines changed

drivers/cxl/core/hdm.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,8 @@ int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm)
826826
cxled = cxl_endpoint_decoder_alloc(port);
827827
if (IS_ERR(cxled)) {
828828
dev_warn(&port->dev,
829-
"Failed to allocate the decoder\n");
829+
"Failed to allocate decoder%d.%d\n",
830+
port->id, i);
830831
return PTR_ERR(cxled);
831832
}
832833
cxld = &cxled->cxld;
@@ -836,21 +837,25 @@ int devm_cxl_enumerate_decoders(struct cxl_hdm *cxlhdm)
836837
cxlsd = cxl_switch_decoder_alloc(port, target_count);
837838
if (IS_ERR(cxlsd)) {
838839
dev_warn(&port->dev,
839-
"Failed to allocate the decoder\n");
840+
"Failed to allocate decoder%d.%d\n",
841+
port->id, i);
840842
return PTR_ERR(cxlsd);
841843
}
842844
cxld = &cxlsd->cxld;
843845
}
844846

845847
rc = init_hdm_decoder(port, cxld, target_map, hdm, i, &dpa_base);
846848
if (rc) {
849+
dev_warn(&port->dev,
850+
"Failed to initialize decoder%d.%d\n",
851+
port->id, i);
847852
put_device(&cxld->dev);
848853
return rc;
849854
}
850855
rc = add_hdm_decoder(port, cxld, target_map);
851856
if (rc) {
852857
dev_warn(&port->dev,
853-
"Failed to add decoder to port\n");
858+
"Failed to add decoder%d.%d\n", port->id, i);
854859
return rc;
855860
}
856861
}

drivers/cxl/port.c

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,55 +30,64 @@ static void schedule_detach(void *cxlmd)
3030
schedule_cxl_memdev_detach(cxlmd);
3131
}
3232

33-
static int cxl_port_probe(struct device *dev)
33+
static int cxl_switch_port_probe(struct cxl_port *port)
3434
{
35-
struct cxl_port *port = to_cxl_port(dev);
3635
struct cxl_hdm *cxlhdm;
3736
int rc;
3837

38+
rc = devm_cxl_port_enumerate_dports(port);
39+
if (rc < 0)
40+
return rc;
3941

40-
if (!is_cxl_endpoint(port)) {
41-
rc = devm_cxl_port_enumerate_dports(port);
42-
if (rc < 0)
43-
return rc;
44-
if (rc == 1)
45-
return devm_cxl_add_passthrough_decoder(port);
46-
}
42+
if (rc == 1)
43+
return devm_cxl_add_passthrough_decoder(port);
4744

4845
cxlhdm = devm_cxl_setup_hdm(port);
4946
if (IS_ERR(cxlhdm))
5047
return PTR_ERR(cxlhdm);
5148

52-
if (is_cxl_endpoint(port)) {
53-
struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport);
54-
struct cxl_dev_state *cxlds = cxlmd->cxlds;
49+
return devm_cxl_enumerate_decoders(cxlhdm);
50+
}
5551

56-
/* Cache the data early to ensure is_visible() works */
57-
read_cdat_data(port);
52+
static int cxl_endpoint_port_probe(struct cxl_port *port)
53+
{
54+
struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport);
55+
struct cxl_dev_state *cxlds = cxlmd->cxlds;
56+
struct cxl_hdm *cxlhdm;
57+
int rc;
58+
59+
cxlhdm = devm_cxl_setup_hdm(port);
60+
if (IS_ERR(cxlhdm))
61+
return PTR_ERR(cxlhdm);
5862

59-
get_device(&cxlmd->dev);
60-
rc = devm_add_action_or_reset(dev, schedule_detach, cxlmd);
61-
if (rc)
62-
return rc;
63+
/* Cache the data early to ensure is_visible() works */
64+
read_cdat_data(port);
6365

64-
rc = cxl_hdm_decode_init(cxlds, cxlhdm);
65-
if (rc)
66-
return rc;
66+
get_device(&cxlmd->dev);
67+
rc = devm_add_action_or_reset(&port->dev, schedule_detach, cxlmd);
68+
if (rc)
69+
return rc;
6770

68-
rc = cxl_await_media_ready(cxlds);
69-
if (rc) {
70-
dev_err(dev, "Media not active (%d)\n", rc);
71-
return rc;
72-
}
73-
}
71+
rc = cxl_hdm_decode_init(cxlds, cxlhdm);
72+
if (rc)
73+
return rc;
7474

75-
rc = devm_cxl_enumerate_decoders(cxlhdm);
75+
rc = cxl_await_media_ready(cxlds);
7676
if (rc) {
77-
dev_err(dev, "Couldn't enumerate decoders (%d)\n", rc);
77+
dev_err(&port->dev, "Media not active (%d)\n", rc);
7878
return rc;
7979
}
8080

81-
return 0;
81+
return devm_cxl_enumerate_decoders(cxlhdm);
82+
}
83+
84+
static int cxl_port_probe(struct device *dev)
85+
{
86+
struct cxl_port *port = to_cxl_port(dev);
87+
88+
if (is_cxl_endpoint(port))
89+
return cxl_endpoint_port_probe(port);
90+
return cxl_switch_port_probe(port);
8291
}
8392

8493
static ssize_t CDAT_read(struct file *filp, struct kobject *kobj,

0 commit comments

Comments
 (0)