Blame SOURCES/0039-libcxl-add-label_size-to-cxl_memdev-and-an-API-to-re.patch

e0018b
From 101966ed3e4a73a6e0e1c269306e976040e068a9 Mon Sep 17 00:00:00 2001
e0018b
From: Vishal Verma <vishal.l.verma@intel.com>
e0018b
Date: Thu, 7 Oct 2021 02:21:32 -0600
e0018b
Subject: [PATCH 039/217] libcxl: add label_size to cxl_memdev, and an API to
e0018b
 retrieve it
e0018b
e0018b
Size of the Label Storage Area (LSA) is available as a sysfs attribute
e0018b
called 'label_storage_size'. Add that to libcxl's memdev so that it is available
e0018b
for label related commands.
e0018b
e0018b
Cc: Dan Williams <dan.j.williams@intel.com>
e0018b
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
e0018b
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
e0018b
---
e0018b
 cxl/lib/libcxl.c   | 12 ++++++++++++
e0018b
 cxl/lib/libcxl.sym |  1 +
e0018b
 cxl/lib/private.h  |  1 +
e0018b
 cxl/libcxl.h       |  1 +
e0018b
 4 files changed, 15 insertions(+)
e0018b
e0018b
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
e0018b
index 76913a2..def3a97 100644
e0018b
--- a/cxl/lib/libcxl.c
e0018b
+++ b/cxl/lib/libcxl.c
e0018b
@@ -247,6 +247,13 @@ static void *add_cxl_memdev(void *parent, int id, const char *cxlmem_base)
e0018b
 	if (memdev->payload_max < 0)
e0018b
 		goto err_read;
e0018b
 
e0018b
+	sprintf(path, "%s/label_storage_size", cxlmem_base);
e0018b
+	if (sysfs_read_attr(ctx, path, buf) < 0)
e0018b
+		goto err_read;
e0018b
+	memdev->lsa_size = strtoull(buf, NULL, 0);
e0018b
+	if (memdev->lsa_size == ULLONG_MAX)
e0018b
+		goto err_read;
e0018b
+
e0018b
 	memdev->dev_path = strdup(cxlmem_base);
e0018b
 	if (!memdev->dev_path)
e0018b
 		goto err_read;
e0018b
@@ -350,6 +357,11 @@ CXL_EXPORT const char *cxl_memdev_get_firmware_verison(struct cxl_memdev *memdev
e0018b
 	return memdev->firmware_version;
e0018b
 }
e0018b
 
e0018b
+CXL_EXPORT size_t cxl_memdev_get_label_size(struct cxl_memdev *memdev)
e0018b
+{
e0018b
+	return memdev->lsa_size;
e0018b
+}
e0018b
+
e0018b
 CXL_EXPORT void cxl_cmd_unref(struct cxl_cmd *cmd)
e0018b
 {
e0018b
 	if (!cmd)
e0018b
diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
e0018b
index 629322c..858e953 100644
e0018b
--- a/cxl/lib/libcxl.sym
e0018b
+++ b/cxl/lib/libcxl.sym
e0018b
@@ -64,6 +64,7 @@ global:
e0018b
 	cxl_cmd_health_info_get_pmem_errors;
e0018b
 	cxl_cmd_new_read_label;
e0018b
 	cxl_cmd_read_label_get_payload;
e0018b
+	cxl_memdev_get_label_size;
e0018b
 local:
e0018b
         *;
e0018b
 };
e0018b
diff --git a/cxl/lib/private.h b/cxl/lib/private.h
e0018b
index bf3a897..c4ed741 100644
e0018b
--- a/cxl/lib/private.h
e0018b
+++ b/cxl/lib/private.h
e0018b
@@ -21,6 +21,7 @@ struct cxl_memdev {
e0018b
 	unsigned long long pmem_size;
e0018b
 	unsigned long long ram_size;
e0018b
 	int payload_max;
e0018b
+	size_t lsa_size;
e0018b
 	struct kmod_module *module;
e0018b
 };
e0018b
 
e0018b
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
e0018b
index 7408745..d3b97a1 100644
e0018b
--- a/cxl/libcxl.h
e0018b
+++ b/cxl/libcxl.h
e0018b
@@ -42,6 +42,7 @@ struct cxl_ctx *cxl_memdev_get_ctx(struct cxl_memdev *memdev);
e0018b
 unsigned long long cxl_memdev_get_pmem_size(struct cxl_memdev *memdev);
e0018b
 unsigned long long cxl_memdev_get_ram_size(struct cxl_memdev *memdev);
e0018b
 const char *cxl_memdev_get_firmware_verison(struct cxl_memdev *memdev);
e0018b
+size_t cxl_memdev_get_label_size(struct cxl_memdev *memdev);
e0018b
 
e0018b
 #define cxl_memdev_foreach(ctx, memdev) \
e0018b
         for (memdev = cxl_memdev_get_first(ctx); \
e0018b
-- 
e0018b
2.27.0
e0018b