[RFC PATCH 2/8] cxl/port: Delay port HDM setup until port component regs setup done

From: Li Ming
Date: Mon Jan 06 2025 - 22:58:08 EST


Currently, devm_cxl_add_endpoint() is responsible for all CXL ports
component registers enumeration. so HDM setup for the port of host
bridge/switch also needs to be delayed until componeng registers setup
finished. So moving CXL host bridge/switch HDM setup implementation out
of cxl_switch_port_probe(), and let devm_cxl_add_endpoint() help to
setup HDM on such ports.

Signed-off-by: Li Ming <ming.li@xxxxxxxxxxxx>
---
drivers/cxl/port.c | 28 +++++++++++++++++++++++++---
1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c
index ae09bbbe0a17..c59f198f6cb0 100644
--- a/drivers/cxl/port.c
+++ b/drivers/cxl/port.c
@@ -59,7 +59,6 @@ static int discover_region(struct device *dev, void *root)

static int cxl_switch_port_probe(struct cxl_port *port)
{
- struct cxl_hdm *cxlhdm;
int rc;

/* Cache the data early to ensure is_visible() works */
@@ -71,6 +70,18 @@ static int cxl_switch_port_probe(struct cxl_port *port)

cxl_switch_parse_cdat(port);

+ return 0;
+}
+
+static int cxl_switch_port_setup_hdm(struct cxl_port *port)
+{
+ struct cxl_hdm *cxlhdm;
+ int rc;
+
+ /* Skip hdm setup if there is a cxlhdm on the port */
+ if (dev_get_drvdata(&port->dev))
+ return 0;
+
cxlhdm = devm_cxl_setup_hdm(port, NULL);
if (!IS_ERR(cxlhdm))
return devm_cxl_enumerate_decoders(cxlhdm, NULL);
@@ -89,6 +100,17 @@ static int cxl_switch_port_probe(struct cxl_port *port)
return -ENXIO;
}

+static int cxl_switch_port_setup(struct cxl_port *port)
+{
+ int rc;
+
+ rc = cxl_port_setup_regs(port);
+ if (rc)
+ return rc;
+
+ return cxl_switch_port_setup_hdm(port);
+}
+
static int cxl_endpoint_port_probe(struct cxl_port *port)
{
struct cxl_port *iter, *parent_port = to_cxl_port(port->dev.parent);
@@ -109,9 +131,9 @@ static int cxl_endpoint_port_probe(struct cxl_port *port)
*/
if (iter != parent_port) {
guard(device)(&iter->dev);
- rc = cxl_port_setup_regs(iter);
+ rc = cxl_switch_port_setup(iter);
} else {
- rc = cxl_port_setup_regs(iter);
+ rc = cxl_switch_port_setup(iter);
}
if (rc)
return rc;
--
2.34.1