Skip to content

Commit 822655e

Browse files
liming011davejiang
authored andcommitted
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>
1 parent 318c588 commit 822655e

2 files changed

Lines changed: 21 additions & 26 deletions

File tree

drivers/cxl/core/core.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,24 @@ int cxl_pci_get_bandwidth(struct pci_dev *pdev, struct access_coordinate *c);
152152
int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,
153153
struct access_coordinate *c);
154154

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+
155173
static inline struct device *dport_to_host(struct cxl_dport *dport)
156174
{
157175
struct cxl_port *port = dport->port;

drivers/cxl/core/port.c

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -615,22 +615,8 @@ struct cxl_port *parent_port_of(struct cxl_port *port)
615615
static void unregister_port(void *_port)
616616
{
617617
struct cxl_port *port = _port;
618-
struct cxl_port *parent = parent_port_of(port);
619-
struct device *lock_dev;
620618

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));
634620
port->dead = true;
635621
device_unregister(&port->dev);
636622
}
@@ -1427,20 +1413,11 @@ static struct device *grandparent(struct device *dev)
14271413
return NULL;
14281414
}
14291415

1430-
static struct device *endpoint_host(struct cxl_port *endpoint)
1431-
{
1432-
struct cxl_port *port = to_cxl_port(endpoint->dev.parent);
1433-
1434-
if (is_cxl_root(port))
1435-
return port->uport_dev;
1436-
return &port->dev;
1437-
}
1438-
14391416
static void delete_endpoint(void *data)
14401417
{
14411418
struct cxl_memdev *cxlmd = data;
14421419
struct cxl_port *endpoint = cxlmd->endpoint;
1443-
struct device *host = endpoint_host(endpoint);
1420+
struct device *host = port_to_host(endpoint);
14441421

14451422
scoped_guard(device, host) {
14461423
if (host->driver && !endpoint->dead) {
@@ -1456,7 +1433,7 @@ static void delete_endpoint(void *data)
14561433

14571434
int cxl_endpoint_autoremove(struct cxl_memdev *cxlmd, struct cxl_port *endpoint)
14581435
{
1459-
struct device *host = endpoint_host(endpoint);
1436+
struct device *host = port_to_host(endpoint);
14601437
struct device *dev = &cxlmd->dev;
14611438

14621439
get_device(host);

0 commit comments

Comments
 (0)