Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

cxl/port: Introduce port_to_host() helper

In CXL subsystem, a port has its own host device for the port creation
and removal. The host of CXL root and all the first level ports is the
platform firmware device, the host of other ports is their parent port's
device. Create this new helper to much easier to get the host of a cxl
port.

Introduce port_to_host() and use it to replace all places where using
open coded to get the host of a port.

Remove endpoint_host() as its functionality can be replaced by
port_to_host().

[dj: Squashed commit 1 and 3 in the series to commit 1. ]

Signed-off-by: Li Ming <ming.li@zohomail.com>
Tested-by: Alison Schofield <alison.schofield@intel.com>
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
Link: https://patch.msgid.link/20260210-fix-port-enumeration-failure-v3-1-06acce0b9ead@zohomail.com
Signed-off-by: Dave Jiang <dave.jiang@intel.com>

authored by

Li Ming and committed by
Dave Jiang
822655e6 318c5885

+21 -26
+18
drivers/cxl/core/core.h
··· 152 152 int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port, 153 153 struct access_coordinate *c); 154 154 155 + static inline struct device *port_to_host(struct cxl_port *port) 156 + { 157 + struct cxl_port *parent = is_cxl_root(port) ? NULL : 158 + to_cxl_port(port->dev.parent); 159 + 160 + /* 161 + * The host of CXL root port and the first level of ports is 162 + * the platform firmware device, the host of all other ports 163 + * is their parent port. 164 + */ 165 + if (!parent) 166 + return port->uport_dev; 167 + else if (is_cxl_root(parent)) 168 + return parent->uport_dev; 169 + else 170 + return &parent->dev; 171 + } 172 + 155 173 static inline struct device *dport_to_host(struct cxl_dport *dport) 156 174 { 157 175 struct cxl_port *port = dport->port;
+3 -26
drivers/cxl/core/port.c
··· 615 615 static void unregister_port(void *_port) 616 616 { 617 617 struct cxl_port *port = _port; 618 - struct cxl_port *parent = parent_port_of(port); 619 - struct device *lock_dev; 620 618 621 - /* 622 - * CXL root port's and the first level of ports are unregistered 623 - * under the platform firmware device lock, all other ports are 624 - * unregistered while holding their parent port lock. 625 - */ 626 - if (!parent) 627 - lock_dev = port->uport_dev; 628 - else if (is_cxl_root(parent)) 629 - lock_dev = parent->uport_dev; 630 - else 631 - lock_dev = &parent->dev; 632 - 633 - device_lock_assert(lock_dev); 619 + device_lock_assert(port_to_host(port)); 634 620 port->dead = true; 635 621 device_unregister(&port->dev); 636 622 } ··· 1413 1427 return NULL; 1414 1428 } 1415 1429 1416 - static struct device *endpoint_host(struct cxl_port *endpoint) 1417 - { 1418 - struct cxl_port *port = to_cxl_port(endpoint->dev.parent); 1419 - 1420 - if (is_cxl_root(port)) 1421 - return port->uport_dev; 1422 - return &port->dev; 1423 - } 1424 - 1425 1430 static void delete_endpoint(void *data) 1426 1431 { 1427 1432 struct cxl_memdev *cxlmd = data; 1428 1433 struct cxl_port *endpoint = cxlmd->endpoint; 1429 - struct device *host = endpoint_host(endpoint); 1434 + struct device *host = port_to_host(endpoint); 1430 1435 1431 1436 scoped_guard(device, host) { 1432 1437 if (host->driver && !endpoint->dead) { ··· 1433 1456 1434 1457 int cxl_endpoint_autoremove(struct cxl_memdev *cxlmd, struct cxl_port *endpoint) 1435 1458 { 1436 - struct device *host = endpoint_host(endpoint); 1459 + struct device *host = port_to_host(endpoint); 1437 1460 struct device *dev = &cxlmd->dev; 1438 1461 1439 1462 get_device(host);