diff mbox series

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

Message ID 20250107035708.1134954-3-ming.li@zohomail.com
State New
Headers show
Series Delay to enumerate ports/dports component registers | expand

Commit Message

Li Ming Jan. 7, 2025, 3:57 a.m. UTC
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@zohomail.com>
---
 drivers/cxl/port.c | 28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)
diff mbox series

Patch

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;