|
|
2eb93d |
From eec8c953a840a1cbdca63352c64cec3e48e86afe Mon Sep 17 00:00:00 2001
|
|
|
2eb93d |
From: Dan Williams <dan.j.williams@intel.com>
|
|
|
2eb93d |
Date: Sun, 23 Jan 2022 16:53:39 -0800
|
|
|
2eb93d |
Subject: [PATCH 107/217] cxl/list: Add 'host' entries for memdevs
|
|
|
2eb93d |
|
|
|
2eb93d |
For debugging CXL port connectivity issues it will be useful to have the
|
|
|
2eb93d |
PCI device name for the memory expander in the 'memdev' listing.
|
|
|
2eb93d |
|
|
|
2eb93d |
Link: https://lore.kernel.org/r/164298561980.3021641.9636572507721689266.stgit@dwillia2-desk3.amr.corp.intel.com
|
|
|
2eb93d |
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
|
|
|
2eb93d |
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
|
|
|
2eb93d |
---
|
|
|
2eb93d |
Documentation/cxl/cxl-list.txt | 3 ++-
|
|
|
2eb93d |
Documentation/cxl/lib/libcxl.txt | 4 ++++
|
|
|
2eb93d |
cxl/json.c | 5 +++++
|
|
|
2eb93d |
cxl/lib/libcxl.c | 24 ++++++++++++++++++++++++
|
|
|
2eb93d |
cxl/lib/libcxl.sym | 1 +
|
|
|
2eb93d |
cxl/lib/private.h | 1 +
|
|
|
2eb93d |
cxl/libcxl.h | 1 +
|
|
|
2eb93d |
7 files changed, 38 insertions(+), 1 deletion(-)
|
|
|
2eb93d |
|
|
|
2eb93d |
diff --git a/Documentation/cxl/cxl-list.txt b/Documentation/cxl/cxl-list.txt
|
|
|
2eb93d |
index 30b6161..9c21ab7 100644
|
|
|
2eb93d |
--- a/Documentation/cxl/cxl-list.txt
|
|
|
2eb93d |
+++ b/Documentation/cxl/cxl-list.txt
|
|
|
2eb93d |
@@ -43,7 +43,8 @@ EXAMPLE
|
|
|
2eb93d |
"memdev":"mem0",
|
|
|
2eb93d |
"pmem_size":268435456,
|
|
|
2eb93d |
"ram_size":0,
|
|
|
2eb93d |
- "serial":0
|
|
|
2eb93d |
+ "serial":0,
|
|
|
2eb93d |
+ "host":"0000:35:00.0"
|
|
|
2eb93d |
}
|
|
|
2eb93d |
]
|
|
|
2eb93d |
|
|
|
2eb93d |
diff --git a/Documentation/cxl/lib/libcxl.txt b/Documentation/cxl/lib/libcxl.txt
|
|
|
2eb93d |
index e4b372d..91fd33e 100644
|
|
|
2eb93d |
--- a/Documentation/cxl/lib/libcxl.txt
|
|
|
2eb93d |
+++ b/Documentation/cxl/lib/libcxl.txt
|
|
|
2eb93d |
@@ -40,6 +40,7 @@ kernel, or to send data or trigger kernel operations for a given device.
|
|
|
2eb93d |
struct cxl_memdev *cxl_memdev_get_first(struct cxl_ctx *ctx);
|
|
|
2eb93d |
struct cxl_memdev *cxl_memdev_get_next(struct cxl_memdev *memdev);
|
|
|
2eb93d |
struct cxl_ctx *cxl_memdev_get_ctx(struct cxl_memdev *memdev);
|
|
|
2eb93d |
+const char *cxl_memdev_get_host(struct cxl_memdev *memdev)
|
|
|
2eb93d |
|
|
|
2eb93d |
#define cxl_memdev_foreach(ctx, memdev) \
|
|
|
2eb93d |
for (memdev = cxl_memdev_get_first(ctx); \
|
|
|
2eb93d |
@@ -54,6 +55,9 @@ memory device commands, see the port, decoder, and endpoint APIs to
|
|
|
2eb93d |
determine what if any CXL Memory Resources are reachable given a
|
|
|
2eb93d |
specific memdev.
|
|
|
2eb93d |
|
|
|
2eb93d |
+The host of a memdev is the PCIe Endpoint device that registered its CXL
|
|
|
2eb93d |
+capabilities with the Linux CXL core.
|
|
|
2eb93d |
+
|
|
|
2eb93d |
=== MEMDEV: Attributes
|
|
|
2eb93d |
----
|
|
|
2eb93d |
int cxl_memdev_get_id(struct cxl_memdev *memdev);
|
|
|
2eb93d |
diff --git a/cxl/json.c b/cxl/json.c
|
|
|
2eb93d |
index af3b4fe..1868686 100644
|
|
|
2eb93d |
--- a/cxl/json.c
|
|
|
2eb93d |
+++ b/cxl/json.c
|
|
|
2eb93d |
@@ -219,6 +219,11 @@ struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
|
|
|
2eb93d |
if (jobj)
|
|
|
2eb93d |
json_object_object_add(jdev, "serial", jobj);
|
|
|
2eb93d |
}
|
|
|
2eb93d |
+
|
|
|
2eb93d |
+ jobj = json_object_new_string(cxl_memdev_get_host(memdev));
|
|
|
2eb93d |
+ if (jobj)
|
|
|
2eb93d |
+ json_object_object_add(jdev, "host", jobj);
|
|
|
2eb93d |
+
|
|
|
2eb93d |
return jdev;
|
|
|
2eb93d |
}
|
|
|
2eb93d |
|
|
|
2eb93d |
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
|
|
|
2eb93d |
index 5f48202..c4ddc7d 100644
|
|
|
2eb93d |
--- a/cxl/lib/libcxl.c
|
|
|
2eb93d |
+++ b/cxl/lib/libcxl.c
|
|
|
2eb93d |
@@ -63,6 +63,7 @@ static void free_memdev(struct cxl_memdev *memdev, struct list_head *head)
|
|
|
2eb93d |
free(memdev->firmware_version);
|
|
|
2eb93d |
free(memdev->dev_buf);
|
|
|
2eb93d |
free(memdev->dev_path);
|
|
|
2eb93d |
+ free(memdev->host);
|
|
|
2eb93d |
free(memdev);
|
|
|
2eb93d |
}
|
|
|
2eb93d |
|
|
|
2eb93d |
@@ -297,6 +298,7 @@ static void *add_cxl_memdev(void *parent, int id, const char *cxlmem_base)
|
|
|
2eb93d |
char *path = calloc(1, strlen(cxlmem_base) + 100);
|
|
|
2eb93d |
struct cxl_ctx *ctx = parent;
|
|
|
2eb93d |
struct cxl_memdev *memdev, *memdev_dup;
|
|
|
2eb93d |
+ char *host, *rpath = NULL;
|
|
|
2eb93d |
char buf[SYSFS_ATTR_SIZE];
|
|
|
2eb93d |
struct stat st;
|
|
|
2eb93d |
|
|
|
2eb93d |
@@ -350,6 +352,22 @@ static void *add_cxl_memdev(void *parent, int id, const char *cxlmem_base)
|
|
|
2eb93d |
if (!memdev->dev_path)
|
|
|
2eb93d |
goto err_read;
|
|
|
2eb93d |
|
|
|
2eb93d |
+ rpath = realpath(cxlmem_base, NULL);
|
|
|
2eb93d |
+ if (!rpath)
|
|
|
2eb93d |
+ goto err_read;
|
|
|
2eb93d |
+ host = strrchr(rpath, '/');
|
|
|
2eb93d |
+ if (host) {
|
|
|
2eb93d |
+ host[0] = '\0';
|
|
|
2eb93d |
+ host = strrchr(rpath, '/');
|
|
|
2eb93d |
+ }
|
|
|
2eb93d |
+ if (!host)
|
|
|
2eb93d |
+ goto err_read;
|
|
|
2eb93d |
+ memdev->host = strdup(host + 1);
|
|
|
2eb93d |
+ if (!memdev->host)
|
|
|
2eb93d |
+ goto err_read;
|
|
|
2eb93d |
+ free(rpath);
|
|
|
2eb93d |
+ rpath = NULL;
|
|
|
2eb93d |
+
|
|
|
2eb93d |
sprintf(path, "%s/firmware_version", cxlmem_base);
|
|
|
2eb93d |
if (sysfs_read_attr(ctx, path, buf) < 0)
|
|
|
2eb93d |
goto err_read;
|
|
|
2eb93d |
@@ -381,6 +399,7 @@ static void *add_cxl_memdev(void *parent, int id, const char *cxlmem_base)
|
|
|
2eb93d |
free(memdev->dev_buf);
|
|
|
2eb93d |
free(memdev->dev_path);
|
|
|
2eb93d |
free(memdev);
|
|
|
2eb93d |
+ free(rpath);
|
|
|
2eb93d |
err_dev:
|
|
|
2eb93d |
free(path);
|
|
|
2eb93d |
return NULL;
|
|
|
2eb93d |
@@ -431,6 +450,11 @@ CXL_EXPORT const char *cxl_memdev_get_devname(struct cxl_memdev *memdev)
|
|
|
2eb93d |
return devpath_to_devname(memdev->dev_path);
|
|
|
2eb93d |
}
|
|
|
2eb93d |
|
|
|
2eb93d |
+CXL_EXPORT const char *cxl_memdev_get_host(struct cxl_memdev *memdev)
|
|
|
2eb93d |
+{
|
|
|
2eb93d |
+ return memdev->host;
|
|
|
2eb93d |
+}
|
|
|
2eb93d |
+
|
|
|
2eb93d |
CXL_EXPORT int cxl_memdev_get_major(struct cxl_memdev *memdev)
|
|
|
2eb93d |
{
|
|
|
2eb93d |
return memdev->major;
|
|
|
2eb93d |
diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
|
|
|
2eb93d |
index dc2863e..8f0688a 100644
|
|
|
2eb93d |
--- a/cxl/lib/libcxl.sym
|
|
|
2eb93d |
+++ b/cxl/lib/libcxl.sym
|
|
|
2eb93d |
@@ -77,6 +77,7 @@ local:
|
|
|
2eb93d |
LIBCXL_2 {
|
|
|
2eb93d |
global:
|
|
|
2eb93d |
cxl_memdev_get_serial;
|
|
|
2eb93d |
+ cxl_memdev_get_host;
|
|
|
2eb93d |
cxl_bus_get_first;
|
|
|
2eb93d |
cxl_bus_get_next;
|
|
|
2eb93d |
cxl_bus_get_provider;
|
|
|
2eb93d |
diff --git a/cxl/lib/private.h b/cxl/lib/private.h
|
|
|
2eb93d |
index cedd2f2..b097bdf 100644
|
|
|
2eb93d |
--- a/cxl/lib/private.h
|
|
|
2eb93d |
+++ b/cxl/lib/private.h
|
|
|
2eb93d |
@@ -22,6 +22,7 @@ struct cxl_memdev {
|
|
|
2eb93d |
int id, major, minor;
|
|
|
2eb93d |
void *dev_buf;
|
|
|
2eb93d |
size_t buf_len;
|
|
|
2eb93d |
+ char *host;
|
|
|
2eb93d |
char *dev_path;
|
|
|
2eb93d |
char *firmware_version;
|
|
|
2eb93d |
struct cxl_ctx *ctx;
|
|
|
2eb93d |
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
|
|
|
2eb93d |
index a60777e..5487b55 100644
|
|
|
2eb93d |
--- a/cxl/libcxl.h
|
|
|
2eb93d |
+++ b/cxl/libcxl.h
|
|
|
2eb93d |
@@ -38,6 +38,7 @@ struct cxl_memdev *cxl_memdev_get_next(struct cxl_memdev *memdev);
|
|
|
2eb93d |
int cxl_memdev_get_id(struct cxl_memdev *memdev);
|
|
|
2eb93d |
unsigned long long cxl_memdev_get_serial(struct cxl_memdev *memdev);
|
|
|
2eb93d |
const char *cxl_memdev_get_devname(struct cxl_memdev *memdev);
|
|
|
2eb93d |
+const char *cxl_memdev_get_host(struct cxl_memdev *memdev);
|
|
|
2eb93d |
int cxl_memdev_get_major(struct cxl_memdev *memdev);
|
|
|
2eb93d |
int cxl_memdev_get_minor(struct cxl_memdev *memdev);
|
|
|
2eb93d |
struct cxl_ctx *cxl_memdev_get_ctx(struct cxl_memdev *memdev);
|
|
|
2eb93d |
--
|
|
|
2eb93d |
2.27.0
|
|
|
2eb93d |
|