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

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