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

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