anitazha / rpms / ndctl

Forked from rpms/ndctl a year ago
Clone

Blame SOURCES/0038-libcxl-add-support-for-the-GET_LSA-command.patch

e0018b
From c7ae078f1050ed54e254377404af2ae0879f2a39 Mon Sep 17 00:00:00 2001
e0018b
From: Vishal Verma <vishal.l.verma@intel.com>
e0018b
Date: Thu, 7 Oct 2021 02:21:30 -0600
e0018b
Subject: [PATCH 038/217] libcxl: add support for the 'GET_LSA' command
e0018b
e0018b
Add a command allocator and accessor APIs for the 'GET_LSA' mailbox
e0018b
command.
e0018b
e0018b
Cc: Ben Widawsky <ben.widawsky@intel.com>
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   | 36 ++++++++++++++++++++++++++++++++++++
e0018b
 cxl/lib/libcxl.sym |  2 ++
e0018b
 cxl/lib/private.h  |  5 +++++
e0018b
 cxl/libcxl.h       |  4 ++++
e0018b
 4 files changed, 47 insertions(+)
e0018b
e0018b
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
e0018b
index 065824d..76913a2 100644
e0018b
--- a/cxl/lib/libcxl.c
e0018b
+++ b/cxl/lib/libcxl.c
e0018b
@@ -1036,6 +1036,42 @@ CXL_EXPORT struct cxl_cmd *cxl_cmd_new_raw(struct cxl_memdev *memdev,
e0018b
 	return cmd;
e0018b
 }
e0018b
 
e0018b
+CXL_EXPORT struct cxl_cmd *cxl_cmd_new_read_label(struct cxl_memdev *memdev,
e0018b
+		unsigned int offset, unsigned int length)
e0018b
+{
e0018b
+	struct cxl_cmd_get_lsa_in *get_lsa;
e0018b
+	struct cxl_cmd *cmd;
e0018b
+
e0018b
+	cmd = cxl_cmd_new_generic(memdev, CXL_MEM_COMMAND_ID_GET_LSA);
e0018b
+	if (!cmd)
e0018b
+		return NULL;
e0018b
+
e0018b
+	get_lsa = (struct cxl_cmd_get_lsa_in *)cmd->send_cmd->in.payload;
e0018b
+	get_lsa->offset = cpu_to_le32(offset);
e0018b
+	get_lsa->length = cpu_to_le32(length);
e0018b
+	return cmd;
e0018b
+}
e0018b
+
e0018b
+CXL_EXPORT ssize_t cxl_cmd_read_label_get_payload(struct cxl_cmd *cmd,
e0018b
+		void *buf, unsigned int length)
e0018b
+{
e0018b
+	struct cxl_cmd_get_lsa_in *get_lsa;
e0018b
+	void *payload;
e0018b
+	int rc;
e0018b
+
e0018b
+	rc = cxl_cmd_validate_status(cmd, CXL_MEM_COMMAND_ID_GET_LSA);
e0018b
+	if (rc)
e0018b
+		return rc;
e0018b
+
e0018b
+	get_lsa = (struct cxl_cmd_get_lsa_in *)cmd->send_cmd->in.payload;
e0018b
+	if (length > le32_to_cpu(get_lsa->length))
e0018b
+		return -EINVAL;
e0018b
+
e0018b
+	payload = (void *)cmd->send_cmd->out.payload;
e0018b
+	memcpy(buf, payload, length);
e0018b
+	return length;
e0018b
+}
e0018b
+
e0018b
 CXL_EXPORT int cxl_cmd_submit(struct cxl_cmd *cmd)
e0018b
 {
e0018b
 	struct cxl_memdev *memdev = cmd->memdev;
e0018b
diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
e0018b
index c83bc28..629322c 100644
e0018b
--- a/cxl/lib/libcxl.sym
e0018b
+++ b/cxl/lib/libcxl.sym
e0018b
@@ -62,6 +62,8 @@ global:
e0018b
 	cxl_cmd_health_info_get_dirty_shutdowns;
e0018b
 	cxl_cmd_health_info_get_volatile_errors;
e0018b
 	cxl_cmd_health_info_get_pmem_errors;
e0018b
+	cxl_cmd_new_read_label;
e0018b
+	cxl_cmd_read_label_get_payload;
e0018b
 local:
e0018b
         *;
e0018b
 };
e0018b
diff --git a/cxl/lib/private.h b/cxl/lib/private.h
e0018b
index 885553a..bf3a897 100644
e0018b
--- a/cxl/lib/private.h
e0018b
+++ b/cxl/lib/private.h
e0018b
@@ -73,6 +73,11 @@ struct cxl_cmd_identify {
e0018b
 	u8 qos_telemetry_caps;
e0018b
 } __attribute__((packed));
e0018b
 
e0018b
+struct cxl_cmd_get_lsa_in {
e0018b
+	le32 offset;
e0018b
+	le32 length;
e0018b
+} __attribute__((packed));
e0018b
+
e0018b
 struct cxl_cmd_get_health_info {
e0018b
 	u8 health_status;
e0018b
 	u8 media_status;
e0018b
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
e0018b
index eae2db8..7408745 100644
e0018b
--- a/cxl/libcxl.h
e0018b
+++ b/cxl/libcxl.h
e0018b
@@ -95,6 +95,10 @@ int cxl_cmd_health_info_get_temperature(struct cxl_cmd *cmd);
e0018b
 int cxl_cmd_health_info_get_dirty_shutdowns(struct cxl_cmd *cmd);
e0018b
 int cxl_cmd_health_info_get_volatile_errors(struct cxl_cmd *cmd);
e0018b
 int cxl_cmd_health_info_get_pmem_errors(struct cxl_cmd *cmd);
e0018b
+struct cxl_cmd *cxl_cmd_new_read_label(struct cxl_memdev *memdev,
e0018b
+		unsigned int offset, unsigned int length);
e0018b
+ssize_t cxl_cmd_read_label_get_payload(struct cxl_cmd *cmd, void *buf,
e0018b
+		unsigned int length);
e0018b
 
e0018b
 #ifdef __cplusplus
e0018b
 } /* extern "C" */
e0018b
-- 
e0018b
2.27.0
e0018b