Blame SOURCES/0121-cxl-list-Support-filtering-memdevs-by-ports.patch

26ccd9
From 15cae420681c5e8efad2b4cbaf0470960e2eba52 Mon Sep 17 00:00:00 2001
26ccd9
From: Dan Williams <dan.j.williams@intel.com>
26ccd9
Date: Sun, 23 Jan 2022 16:54:55 -0800
26ccd9
Subject: [PATCH 121/217] cxl/list: Support filtering memdevs by ports
26ccd9
26ccd9
The ability to filter memdevs by decoders falls short when the decoder does
26ccd9
not have its target list programmed. So, introduce a by port filter to show
26ccd9
the potential memdevs that can be targeted by the decoder.
26ccd9
26ccd9
Link: https://lore.kernel.org/r/164298569568.3021641.888802471376117408.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   |  3 +-
26ccd9
 Documentation/cxl/lib/libcxl.txt |  7 ++++-
26ccd9
 cxl/filter.c                     | 50 ++++++++++++++++++++++++++++++++
26ccd9
 cxl/lib/libcxl.c                 | 23 +++++++++++++++
26ccd9
 cxl/lib/libcxl.sym               |  2 ++
26ccd9
 cxl/libcxl.h                     |  3 ++
26ccd9
 6 files changed, 86 insertions(+), 2 deletions(-)
26ccd9
26ccd9
diff --git a/Documentation/cxl/cxl-list.txt b/Documentation/cxl/cxl-list.txt
26ccd9
index 04e831e..90e6d9f 100644
26ccd9
--- a/Documentation/cxl/cxl-list.txt
26ccd9
+++ b/Documentation/cxl/cxl-list.txt
26ccd9
@@ -63,7 +63,8 @@ one or more memdevs. For example:
26ccd9
 ----
26ccd9
 Additionally, when provisioning new interleave configurations it is
26ccd9
 useful to know which memdevs can be referenced by a given decoder like a
26ccd9
-root decoder:
26ccd9
+root decoder, or mapped by a given port if the decoders are not
26ccd9
+configured.
26ccd9
 ----
26ccd9
 # cxl list -Mu -d decoder0.0
26ccd9
 {
26ccd9
diff --git a/Documentation/cxl/lib/libcxl.txt b/Documentation/cxl/lib/libcxl.txt
26ccd9
index 5ad3027..a0fcee9 100644
26ccd9
--- a/Documentation/cxl/lib/libcxl.txt
26ccd9
+++ b/Documentation/cxl/lib/libcxl.txt
26ccd9
@@ -276,11 +276,12 @@ CXL / PCIe host bridge.
26ccd9
 ----
26ccd9
 struct cxl_dport *cxl_dport_get_first(struct cxl_port *port);
26ccd9
 struct cxl_dport *cxl_dport_get_next(struct cxl_dport *dport);
26ccd9
+struct cxl_dport *cxl_port_get_dport_by_memdev(struct cxl_port *port,
26ccd9
+                                               struct cxl_memdev *memdev);
26ccd9
 
26ccd9
 #define cxl_dport_foreach(port, dport)                                     \
26ccd9
        for (dport = cxl_dport_get_first(port); dport != NULL;              \
26ccd9
             dport = cxl_dport_get_next(dport))
26ccd9
-
26ccd9
 ----
26ccd9
 
26ccd9
 ===== DPORT: Attributes
26ccd9
@@ -288,12 +289,16 @@ struct cxl_dport *cxl_dport_get_next(struct cxl_dport *dport);
26ccd9
 const char *cxl_dport_get_devname(struct cxl_dport *dport);
26ccd9
 const char *cxl_dport_get_physical_node(struct cxl_dport *dport);
26ccd9
 int cxl_dport_get_id(struct cxl_dport *dport);
26ccd9
+bool cxl_dport_maps_memdev(struct cxl_dport *dport, struct cxl_memdev *memdev);
26ccd9
 ----
26ccd9
 The id of a dport is the hardware idenfifier used by an upstream port to
26ccd9
 reference a downstream port. The physical node of a dport is only
26ccd9
 available for platform firmware defined downstream ports and alias the
26ccd9
 companion object, like a PCI host bridge, in the PCI device hierarchy.
26ccd9
 
26ccd9
+The cxl_dport_maps_memdev() helper checks if a dport is an ancestor of a
26ccd9
+given memdev.
26ccd9
+
26ccd9
 ENDPOINTS
26ccd9
 ---------
26ccd9
 CXL endpoint objects encapsulate the set of host-managed device-memory
26ccd9
diff --git a/cxl/filter.c b/cxl/filter.c
26ccd9
index c972545..c691edf 100644
26ccd9
--- a/cxl/filter.c
26ccd9
+++ b/cxl/filter.c
26ccd9
@@ -486,6 +486,53 @@ util_cxl_memdev_filter_by_decoder(struct cxl_memdev *memdev, const char *ident)
26ccd9
 	return NULL;
26ccd9
 }
26ccd9
 
26ccd9
+static bool __memdev_filter_by_port(struct cxl_memdev *memdev,
26ccd9
+				    struct cxl_port *port,
26ccd9
+				    const char *port_ident)
26ccd9
+{
26ccd9
+	struct cxl_endpoint *endpoint;
26ccd9
+
26ccd9
+	if (util_cxl_port_filter(port, port_ident, CXL_PF_SINGLE) &&
26ccd9
+	    cxl_port_get_dport_by_memdev(port, memdev))
26ccd9
+		return true;
26ccd9
+
26ccd9
+	cxl_endpoint_foreach(port, endpoint)
26ccd9
+		if (__memdev_filter_by_port(memdev,
26ccd9
+					    cxl_endpoint_get_port(endpoint),
26ccd9
+					    port_ident))
26ccd9
+			return true;
26ccd9
+	return false;
26ccd9
+}
26ccd9
+
26ccd9
+static struct cxl_memdev *
26ccd9
+util_cxl_memdev_filter_by_port(struct cxl_memdev *memdev, const char *bus_ident,
26ccd9
+			       const char *port_ident)
26ccd9
+{
26ccd9
+	struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev);
26ccd9
+	struct cxl_bus *bus;
26ccd9
+
26ccd9
+	if (!bus_ident && !port_ident)
26ccd9
+		return memdev;
26ccd9
+
26ccd9
+	cxl_bus_foreach(ctx, bus) {
26ccd9
+		struct cxl_port *port, *top;
26ccd9
+
26ccd9
+		port = cxl_bus_get_port(bus);
26ccd9
+		if (util_cxl_bus_filter(bus, bus_ident))
26ccd9
+			if (__memdev_filter_by_port(memdev, port,
26ccd9
+						    cxl_bus_get_devname(bus)))
26ccd9
+				return memdev;
26ccd9
+		if (__memdev_filter_by_port(memdev, port, port_ident))
26ccd9
+				return memdev;
26ccd9
+		top = port;
26ccd9
+		cxl_port_foreach_all(top, port)
26ccd9
+			if (__memdev_filter_by_port(memdev, port, port_ident))
26ccd9
+				return memdev;
26ccd9
+	}
26ccd9
+
26ccd9
+	return NULL;
26ccd9
+}
26ccd9
+
26ccd9
 static unsigned long params_to_flags(struct cxl_filter_params *param)
26ccd9
 {
26ccd9
 	unsigned long flags = 0;
26ccd9
@@ -647,6 +694,9 @@ static void walk_endpoints(struct cxl_port *port, struct cxl_filter_params *p,
26ccd9
 			if (!util_cxl_memdev_filter_by_decoder(
26ccd9
 				    memdev, p->decoder_filter))
26ccd9
 				continue;
26ccd9
+			if (!util_cxl_memdev_filter_by_port(
26ccd9
+				    memdev, p->bus_filter, p->port_filter))
26ccd9
+				continue;
26ccd9
 			if (!p->idle && !cxl_memdev_is_enabled(memdev))
26ccd9
 				continue;
26ccd9
 			jobj = util_cxl_memdev_to_json(memdev, flags);
26ccd9
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
26ccd9
index 4ebb8b9..dcfc826 100644
26ccd9
--- a/cxl/lib/libcxl.c
26ccd9
+++ b/cxl/lib/libcxl.c
26ccd9
@@ -1452,6 +1452,29 @@ CXL_EXPORT int cxl_dport_get_id(struct cxl_dport *dport)
26ccd9
 	return dport->id;
26ccd9
 }
26ccd9
 
26ccd9
+CXL_EXPORT bool cxl_dport_maps_memdev(struct cxl_dport *dport,
26ccd9
+				      struct cxl_memdev *memdev)
26ccd9
+{
26ccd9
+	struct cxl_ctx *ctx = cxl_memdev_get_ctx(memdev);
26ccd9
+
26ccd9
+	dbg(ctx, "memdev: %s dport: %s\n", memdev->host_path, dport->dev_path);
26ccd9
+
26ccd9
+	if (dport->phys_path)
26ccd9
+		return !!strstr(memdev->host_path, dport->phys_path);
26ccd9
+	return !!strstr(memdev->host_path, dport->dev_path);
26ccd9
+}
26ccd9
+
26ccd9
+CXL_EXPORT struct cxl_dport *
26ccd9
+cxl_port_get_dport_by_memdev(struct cxl_port *port, struct cxl_memdev *memdev)
26ccd9
+{
26ccd9
+	struct cxl_dport *dport;
26ccd9
+
26ccd9
+	cxl_dport_foreach(port, dport)
26ccd9
+		if (cxl_dport_maps_memdev(dport, memdev))
26ccd9
+			return dport;
26ccd9
+	return NULL;
26ccd9
+}
26ccd9
+
26ccd9
 static void *add_cxl_bus(void *parent, int id, const char *cxlbus_base)
26ccd9
 {
26ccd9
 	const char *devname = devpath_to_devname(cxlbus_base);
26ccd9
diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
26ccd9
index 0190b13..2c8358e 100644
26ccd9
--- a/cxl/lib/libcxl.sym
26ccd9
+++ b/cxl/lib/libcxl.sym
26ccd9
@@ -149,4 +149,6 @@ global:
26ccd9
 	cxl_dport_get_devname;
26ccd9
 	cxl_dport_get_physical_node;
26ccd9
 	cxl_dport_get_id;
26ccd9
+	cxl_port_get_dport_by_memdev;
26ccd9
+	cxl_dport_maps_memdev;
26ccd9
 } LIBCXL_1;
26ccd9
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
26ccd9
index 874c381..c8d07bb 100644
26ccd9
--- a/cxl/libcxl.h
26ccd9
+++ b/cxl/libcxl.h
26ccd9
@@ -111,6 +111,9 @@ struct cxl_dport *cxl_dport_get_next(struct cxl_dport *dport);
26ccd9
 const char *cxl_dport_get_devname(struct cxl_dport *dport);
26ccd9
 const char *cxl_dport_get_physical_node(struct cxl_dport *dport);
26ccd9
 int cxl_dport_get_id(struct cxl_dport *dport);
26ccd9
+bool cxl_dport_maps_memdev(struct cxl_dport *dport, struct cxl_memdev *memdev);
26ccd9
+struct cxl_dport *cxl_port_get_dport_by_memdev(struct cxl_port *port,
26ccd9
+					       struct cxl_memdev *memdev);
26ccd9
 
26ccd9
 #define cxl_dport_foreach(port, dport)                                         \
26ccd9
 	for (dport = cxl_dport_get_first(port); dport != NULL;                 \
26ccd9
-- 
26ccd9
2.27.0
26ccd9