diff mbox series

[ndctl,v2,RESEND,1/2] cxl/list: Add parent_dport attribute to memdev and root port listing

Message ID 20230726180955.88834-2-fan.ni@gmx.us
State New, archived
Headers show
Series cxl-graph: add a new command to construct CXL topology graph images | expand

Commit Message

Fan Ni July 26, 2023, 6:09 p.m. UTC
From: Fan Ni <nifan@outlook.com>

Add `parent_dport` attribute to memdev and root port when listing by
leveraging cxl_port_get_parent_dport function. The attribute will be
used to describe the cxl topology when plotting cxl topology graph.

Signed-off-by: Fan Ni <fan.ni@samsung.com>
---
 cxl/json.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

--
2.39.2
diff mbox series

Patch

diff --git a/cxl/json.c b/cxl/json.c
index 9a4b5c7..f7600dc 100644
--- a/cxl/json.c
+++ b/cxl/json.c
@@ -540,6 +540,23 @@  struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
 	if (jobj)
 		json_object_object_add(jdev, "host", jobj);

+	/* add parent_dport attribute to memdev */
+	if (cxl_memdev_get_endpoint(memdev)) {
+		struct cxl_endpoint *ep = cxl_memdev_get_endpoint(memdev);
+
+		if (ep) {
+			struct cxl_port *port = cxl_endpoint_get_port(ep);
+
+			if (cxl_port_get_parent_dport(port)) {
+				struct cxl_dport *dport = cxl_port_get_parent_dport(port);
+
+				jobj = json_object_new_string(cxl_dport_get_devname(dport));
+				if (jobj)
+					json_object_object_add(jdev, "parent_dport", jobj);
+			}
+		}
+	}
+
 	if (!cxl_memdev_is_enabled(memdev)) {
 		jobj = json_object_new_string("disabled");
 		if (jobj)
@@ -1009,9 +1026,9 @@  static struct json_object *__util_cxl_port_to_json(struct cxl_port *port,
 		struct cxl_dport *dport = cxl_port_get_parent_dport(port);

 		jobj = json_object_new_string(cxl_dport_get_devname(dport));
-		if (jobj)
-			json_object_object_add(jport, "parent_dport", jobj);
-	}
+	} else
+		jobj = json_object_new_string("ACPI0017:00");
+	json_object_object_add(jport, "parent_dport", jobj);

 	jobj = json_object_new_int(cxl_port_get_depth(port));
 	if (jobj)