Blame SOURCES/0106-cxl-list-Add-host-entries-for-port-like-objects.patch

2eb93d
From f39735be3c1157fdfa7dd5c781048a411ebe4dc5 Mon Sep 17 00:00:00 2001
2eb93d
From: Dan Williams <dan.j.williams@intel.com>
2eb93d
Date: Sun, 23 Jan 2022 16:53:34 -0800
2eb93d
Subject: [PATCH 106/217] cxl/list: Add 'host' entries for port-like objects
2eb93d
2eb93d
Add the device name of the "host" device for a given CXL port object. The
2eb93d
kernel calls this the 'uport' attribute.
2eb93d
2eb93d
Link: https://lore.kernel.org/r/164298561473.3021641.16508989603599026269.stgit@dwillia2-desk3.amr.corp.intel.com
2eb93d
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2eb93d
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
2eb93d
---
2eb93d
 Documentation/cxl/cxl-list.txt   |  9 +++++++++
2eb93d
 Documentation/cxl/lib/libcxl.txt |  5 +++++
2eb93d
 cxl/json.c                       |  4 ++++
2eb93d
 cxl/lib/libcxl.c                 | 10 ++++++++++
2eb93d
 cxl/lib/libcxl.sym               |  2 ++
2eb93d
 cxl/libcxl.h                     |  2 ++
2eb93d
 6 files changed, 32 insertions(+)
2eb93d
2eb93d
diff --git a/Documentation/cxl/cxl-list.txt b/Documentation/cxl/cxl-list.txt
2eb93d
index d342da2..30b6161 100644
2eb93d
--- a/Documentation/cxl/cxl-list.txt
2eb93d
+++ b/Documentation/cxl/cxl-list.txt
2eb93d
@@ -210,6 +210,15 @@ OPTIONS
2eb93d
 --endpoints::
2eb93d
 	Include endpoint objects (CXL Memory Device decoders) in the
2eb93d
 	listing.
2eb93d
+----
2eb93d
+# cxl list -E
2eb93d
+[
2eb93d
+  {
2eb93d
+    "endpoint":"endpoint2",
2eb93d
+    "host":"mem0"
2eb93d
+  }
2eb93d
+]
2eb93d
+----
2eb93d
 
2eb93d
 -e::
2eb93d
 --endpoint::
2eb93d
diff --git a/Documentation/cxl/lib/libcxl.txt b/Documentation/cxl/lib/libcxl.txt
2eb93d
index eebab37..e4b372d 100644
2eb93d
--- a/Documentation/cxl/lib/libcxl.txt
2eb93d
+++ b/Documentation/cxl/lib/libcxl.txt
2eb93d
@@ -178,6 +178,7 @@ struct cxl_port *cxl_port_get_next(struct cxl_port *port);
2eb93d
 struct cxl_port *cxl_port_get_parent(struct cxl_port *port);
2eb93d
 struct cxl_bus *cxl_port_get_bus(struct cxl_port *port);
2eb93d
 struct cxl_ctx *cxl_port_get_ctx(struct cxl_port *port);
2eb93d
+const char *cxl_port_get_host(struct cxl_port *port);
2eb93d
 
2eb93d
 #define cxl_port_foreach(parent, port)                                      \
2eb93d
        for (port = cxl_port_get_first(parent); port != NULL;                \
2eb93d
@@ -192,6 +193,9 @@ as a parent object retrievable via cxl_port_get_parent().
2eb93d
 The root port of a hiearchy can be retrieved via any port instance in
2eb93d
 that hierarchy via cxl_port_get_bus().
2eb93d
 
2eb93d
+The host of a port is the corresponding device name of the PCIe Root
2eb93d
+Port, or Switch Upstream Port with CXL capabilities.
2eb93d
+
2eb93d
 === PORT: Attributes
2eb93d
 ----
2eb93d
 const char *cxl_port_get_devname(struct cxl_port *port);
2eb93d
@@ -222,6 +226,7 @@ struct cxl_endpoint *cxl_endpoint_get_next(struct cxl_endpoint *endpoint);
2eb93d
 struct cxl_ctx *cxl_endpoint_get_ctx(struct cxl_endpoint *endpoint);
2eb93d
 struct cxl_port *cxl_endpoint_get_parent(struct cxl_endpoint *endpoint);
2eb93d
 struct cxl_port *cxl_endpoint_get_port(struct cxl_endpoint *endpoint);
2eb93d
+const char *cxl_endpoint_get_host(struct cxl_endpoint *endpoint);
2eb93d
 
2eb93d
 #define cxl_endpoint_foreach(port, endpoint)                                 \
2eb93d
        for (endpoint = cxl_endpoint_get_first(port); endpoint != NULL;       \
2eb93d
diff --git a/cxl/json.c b/cxl/json.c
2eb93d
index 08f6192..af3b4fe 100644
2eb93d
--- a/cxl/json.c
2eb93d
+++ b/cxl/json.c
2eb93d
@@ -258,6 +258,10 @@ static struct json_object *__util_cxl_port_to_json(struct cxl_port *port,
2eb93d
 	if (jobj)
2eb93d
 		json_object_object_add(jport, name_key, jobj);
2eb93d
 
2eb93d
+	jobj = json_object_new_string(cxl_port_get_host(port));
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jport, "host", jobj);
2eb93d
+
2eb93d
 	if (!cxl_port_is_enabled(port)) {
2eb93d
 		jobj = json_object_new_string("disabled");
2eb93d
 		if (jobj)
2eb93d
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
2eb93d
index a25e715..5f48202 100644
2eb93d
--- a/cxl/lib/libcxl.c
2eb93d
+++ b/cxl/lib/libcxl.c
2eb93d
@@ -626,6 +626,11 @@ CXL_EXPORT struct cxl_port *cxl_endpoint_get_port(struct cxl_endpoint *endpoint)
2eb93d
 	return &endpoint->port;
2eb93d
 }
2eb93d
 
2eb93d
+CXL_EXPORT const char *cxl_endpoint_get_host(struct cxl_endpoint *endpoint)
2eb93d
+{
2eb93d
+	return cxl_port_get_host(&endpoint->port);
2eb93d
+}
2eb93d
+
2eb93d
 CXL_EXPORT int cxl_endpoint_is_enabled(struct cxl_endpoint *endpoint)
2eb93d
 {
2eb93d
 	return cxl_port_is_enabled(&endpoint->port);
2eb93d
@@ -744,6 +749,11 @@ CXL_EXPORT struct cxl_bus *cxl_port_get_bus(struct cxl_port *port)
2eb93d
 	return bus;
2eb93d
 }
2eb93d
 
2eb93d
+CXL_EXPORT const char *cxl_port_get_host(struct cxl_port *port)
2eb93d
+{
2eb93d
+	return devpath_to_devname(port->uport);
2eb93d
+}
2eb93d
+
2eb93d
 CXL_EXPORT int cxl_port_is_enabled(struct cxl_port *port)
2eb93d
 {
2eb93d
 	struct cxl_ctx *ctx = cxl_port_get_ctx(port);
2eb93d
diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
2eb93d
index 7a51a0c..dc2863e 100644
2eb93d
--- a/cxl/lib/libcxl.sym
2eb93d
+++ b/cxl/lib/libcxl.sym
2eb93d
@@ -95,6 +95,7 @@ global:
2eb93d
 	cxl_port_to_bus;
2eb93d
 	cxl_port_is_endpoint;
2eb93d
 	cxl_port_get_bus;
2eb93d
+	cxl_port_get_host;
2eb93d
 	cxl_endpoint_get_first;
2eb93d
 	cxl_endpoint_get_next;
2eb93d
 	cxl_endpoint_get_devname;
2eb93d
@@ -103,4 +104,5 @@ global:
2eb93d
 	cxl_endpoint_is_enabled;
2eb93d
 	cxl_endpoint_get_parent;
2eb93d
 	cxl_endpoint_get_port;
2eb93d
+	cxl_endpoint_get_host;
2eb93d
 } LIBCXL_1;
2eb93d
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
2eb93d
index f6ba9a1..a60777e 100644
2eb93d
--- a/cxl/libcxl.h
2eb93d
+++ b/cxl/libcxl.h
2eb93d
@@ -83,6 +83,7 @@ bool cxl_port_is_switch(struct cxl_port *port);
2eb93d
 struct cxl_bus *cxl_port_to_bus(struct cxl_port *port);
2eb93d
 bool cxl_port_is_endpoint(struct cxl_port *port);
2eb93d
 struct cxl_bus *cxl_port_get_bus(struct cxl_port *port);
2eb93d
+const char *cxl_port_get_host(struct cxl_port *port);
2eb93d
 
2eb93d
 #define cxl_port_foreach(parent, port)                                         \
2eb93d
 	for (port = cxl_port_get_first(parent); port != NULL;                  \
2eb93d
@@ -97,6 +98,7 @@ struct cxl_ctx *cxl_endpoint_get_ctx(struct cxl_endpoint *endpoint);
2eb93d
 int cxl_endpoint_is_enabled(struct cxl_endpoint *endpoint);
2eb93d
 struct cxl_port *cxl_endpoint_get_parent(struct cxl_endpoint *endpoint);
2eb93d
 struct cxl_port *cxl_endpoint_get_port(struct cxl_endpoint *endpoint);
2eb93d
+const char *cxl_endpoint_get_host(struct cxl_endpoint *endpoint);
2eb93d
 
2eb93d
 #define cxl_endpoint_foreach(port, endpoint)                                   \
2eb93d
 	for (endpoint = cxl_endpoint_get_first(port); endpoint != NULL;        \
2eb93d
-- 
2eb93d
2.27.0
2eb93d