Skip to content

Commit 172738b

Browse files
committed
cxl/port: Link the 'parent_dport' in portX/ and endpointX/ sysfs
Similar to the justification in: 1b58b4c ("cxl/port: Record parent dport when adding ports") ...userspace wants to know the routing information for ports for calculating the memdev order for region creation among other things. Cache the information the kernel discovers at enumeration time in a 'parent_dport' attribute to save userspace the time of trawling sysfs to recover the same information. Reviewed-by: Jonathan Cameron <[email protected]> Link: https://lore.kernel.org/r/167124082375.1626103.6047000000121298560.stgit@dwillia2-xfh.jf.intel.com Signed-off-by: Dan Williams <[email protected]>
1 parent af3ea9a commit 172738b

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

Documentation/ABI/testing/sysfs-bus-cxl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,21 @@ Description:
9090
capability.
9191

9292

93+
What: /sys/bus/cxl/devices/{port,endpoint}X/parent_dport
94+
Date: January, 2023
95+
KernelVersion: v6.3
96+
97+
Description:
98+
(RO) CXL port objects are instantiated for each upstream port in
99+
a CXL/PCIe switch, and for each endpoint to map the
100+
corresponding memory device into the CXL port hierarchy. When a
101+
descendant CXL port (switch or endpoint) is enumerated it is
102+
useful to know which 'dport' object in the parent CXL port
103+
routes to this descendant. The 'parent_dport' symlink points to
104+
the device representing the downstream port of a CXL switch that
105+
routes to {port,endpoint}X.
106+
107+
93108
What: /sys/bus/cxl/devices/portX/dportY
94109
Date: June, 2021
95110
KernelVersion: v5.14

drivers/cxl/core/port.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,29 @@ static int devm_cxl_link_uport(struct device *host, struct cxl_port *port)
583583
return devm_add_action_or_reset(host, cxl_unlink_uport, port);
584584
}
585585

586+
static void cxl_unlink_parent_dport(void *_port)
587+
{
588+
struct cxl_port *port = _port;
589+
590+
sysfs_remove_link(&port->dev.kobj, "parent_dport");
591+
}
592+
593+
static int devm_cxl_link_parent_dport(struct device *host,
594+
struct cxl_port *port,
595+
struct cxl_dport *parent_dport)
596+
{
597+
int rc;
598+
599+
if (!parent_dport)
600+
return 0;
601+
602+
rc = sysfs_create_link(&port->dev.kobj, &parent_dport->dport->kobj,
603+
"parent_dport");
604+
if (rc)
605+
return rc;
606+
return devm_add_action_or_reset(host, cxl_unlink_parent_dport, port);
607+
}
608+
586609
static struct lock_class_key cxl_port_key;
587610

588611
static struct cxl_port *cxl_port_alloc(struct device *uport,
@@ -692,6 +715,10 @@ static struct cxl_port *__devm_cxl_add_port(struct device *host,
692715
if (rc)
693716
return ERR_PTR(rc);
694717

718+
rc = devm_cxl_link_parent_dport(host, port, parent_dport);
719+
if (rc)
720+
return ERR_PTR(rc);
721+
695722
return port;
696723

697724
err:
@@ -1164,6 +1191,7 @@ static void delete_endpoint(void *data)
11641191

11651192
device_lock(parent);
11661193
if (parent->driver && !endpoint->dead) {
1194+
devm_release_action(parent, cxl_unlink_parent_dport, endpoint);
11671195
devm_release_action(parent, cxl_unlink_uport, endpoint);
11681196
devm_release_action(parent, unregister_port, endpoint);
11691197
}
@@ -1194,6 +1222,7 @@ EXPORT_SYMBOL_NS_GPL(cxl_endpoint_autoremove, CXL);
11941222
*/
11951223
static void delete_switch_port(struct cxl_port *port)
11961224
{
1225+
devm_release_action(port->dev.parent, cxl_unlink_parent_dport, port);
11971226
devm_release_action(port->dev.parent, cxl_unlink_uport, port);
11981227
devm_release_action(port->dev.parent, unregister_port, port);
11991228
}

0 commit comments

Comments
 (0)