On 4/24/23 12:59 PM, Dan Williams wrote:
Attempts to filter by memdev fail when the memdev is an RCD (RCH topology):

     # cxl list -BEM -m 11
       Warning: no matching devices found

     [
     ]

This is caused by VH topology assumption where an intervening host-bridge
port is expected between the root CXL port and the endpoint. In an RCH
topology an endpoint is integrated in the host-bridge.

Search for endpoints directly attached to the root:

     # cxl list -BEMu -m 11
     {
       "bus":"root3",
       "provider":"cxl_test",
       "endpoints:root3":[
         {
           "endpoint":"endpoint22",
           "host":"mem11",
           "depth":1,
           "memdev":{
             "memdev":"mem11",
             "ram_size":"2.00 GiB (2.15 GB)",
             "serial":"0xa",
             "numa_node":0,
             "host":"cxl_rcd.10"
           }
         }
       ]
     }


Signed-off-by: Dan Williams <dan.j.willi...@intel.com>

Reviewed-by: Dave Jiang <dave.ji...@intel.com>

---
  cxl/lib/libcxl.c |   19 ++++++++++++++++---
  1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
index 59e5bdbcc750..e6c94d623303 100644
--- a/cxl/lib/libcxl.c
+++ b/cxl/lib/libcxl.c
@@ -1457,8 +1457,9 @@ CXL_EXPORT int cxl_memdev_enable(struct cxl_memdev 
*memdev)
        return 0;
  }
-static struct cxl_endpoint *cxl_port_find_endpoint(struct cxl_port *parent_port,
-                                                  struct cxl_memdev *memdev)
+static struct cxl_endpoint *
+cxl_port_recurse_endpoint(struct cxl_port *parent_port,
+                         struct cxl_memdev *memdev)
  {
        struct cxl_endpoint *endpoint;
        struct cxl_port *port;
@@ -1468,7 +1469,7 @@ static struct cxl_endpoint *cxl_port_find_endpoint(struct 
cxl_port *parent_port,
                        if (strcmp(cxl_endpoint_get_host(endpoint),
                                   cxl_memdev_get_devname(memdev)) == 0)
                                return endpoint;
-               endpoint = cxl_port_find_endpoint(port, memdev);
+               endpoint = cxl_port_recurse_endpoint(port, memdev);
                if (endpoint)
                        return endpoint;
        }
@@ -1476,6 +1477,18 @@ static struct cxl_endpoint 
*cxl_port_find_endpoint(struct cxl_port *parent_port,
        return NULL;
  }
+static struct cxl_endpoint *cxl_port_find_endpoint(struct cxl_port *parent_port,
+                                                  struct cxl_memdev *memdev)
+{
+       struct cxl_endpoint *endpoint;
+
+       cxl_endpoint_foreach(parent_port, endpoint)
+               if (strcmp(cxl_endpoint_get_host(endpoint),
+                          cxl_memdev_get_devname(memdev)) == 0)
+                       return endpoint;
+       return cxl_port_recurse_endpoint(parent_port, memdev);
+}
+
  CXL_EXPORT struct cxl_endpoint *
  cxl_memdev_get_endpoint(struct cxl_memdev *memdev)
  {



Reply via email to