Blame SOURCES/0036-libcxl-add-support-for-the-Identify-Device-command.patch

2eb93d
From 244862cbbfecda9b6b638eccaca526f4daba2795 Mon Sep 17 00:00:00 2001
2eb93d
From: Vishal Verma <vishal.l.verma@intel.com>
2eb93d
Date: Thu, 7 Oct 2021 02:21:28 -0600
2eb93d
Subject: [PATCH 036/217] libcxl: add support for the 'Identify Device' command
2eb93d
2eb93d
Add APIs to allocate and send an 'Identify Device' command, and
2eb93d
accessors to retrieve some of the fields from the resulting data.
2eb93d
2eb93d
Only add a handful accessor functions; more can be added as the need
2eb93d
arises. The fields added are fw_revision, partition_align, and
2eb93d
lsa_size.
2eb93d
2eb93d
Cc: Ben Widawsky <ben.widawsky@intel.com>
2eb93d
Cc: Dan Williams <dan.j.williams@intel.com>
2eb93d
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
2eb93d
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
2eb93d
---
2eb93d
 cxl/lib/libcxl.c   | 52 ++++++++++++++++++++++++++++++++++++++++++++++
2eb93d
 cxl/lib/libcxl.sym |  4 ++++
2eb93d
 cxl/lib/private.h  | 19 +++++++++++++++++
2eb93d
 cxl/libcxl.h       |  4 ++++
2eb93d
 4 files changed, 79 insertions(+)
2eb93d
2eb93d
diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
2eb93d
index 727d599..ed21670 100644
2eb93d
--- a/cxl/lib/libcxl.c
2eb93d
+++ b/cxl/lib/libcxl.c
2eb93d
@@ -13,7 +13,10 @@
2eb93d
 #include <sys/sysmacros.h>
2eb93d
 #include <uuid/uuid.h>
2eb93d
 #include <ccan/list/list.h>
2eb93d
+#include <ccan/endian/endian.h>
2eb93d
+#include <ccan/minmax/minmax.h>
2eb93d
 #include <ccan/array_size/array_size.h>
2eb93d
+#include <ccan/short_types/short_types.h>
2eb93d
 
2eb93d
 #include <util/log.h>
2eb93d
 #include <util/size.h>
2eb93d
@@ -674,6 +677,55 @@ CXL_EXPORT const char *cxl_cmd_get_devname(struct cxl_cmd *cmd)
2eb93d
 	return cxl_memdev_get_devname(cmd->memdev);
2eb93d
 }
2eb93d
 
2eb93d
+CXL_EXPORT struct cxl_cmd *cxl_cmd_new_identify(struct cxl_memdev *memdev)
2eb93d
+{
2eb93d
+	return cxl_cmd_new_generic(memdev, CXL_MEM_COMMAND_ID_IDENTIFY);
2eb93d
+}
2eb93d
+
2eb93d
+CXL_EXPORT int cxl_cmd_identify_get_fw_rev(struct cxl_cmd *cmd, char *fw_rev,
2eb93d
+		int fw_len)
2eb93d
+{
2eb93d
+	struct cxl_cmd_identify *id =
2eb93d
+			(struct cxl_cmd_identify *)cmd->send_cmd->out.payload;
2eb93d
+
2eb93d
+	if (cmd->send_cmd->id != CXL_MEM_COMMAND_ID_IDENTIFY)
2eb93d
+		return -EINVAL;
2eb93d
+	if (cmd->status < 0)
2eb93d
+		return cmd->status;
2eb93d
+
2eb93d
+	if (fw_len > 0)
2eb93d
+		memcpy(fw_rev, id->fw_revision,
2eb93d
+			min(fw_len, CXL_CMD_IDENTIFY_FW_REV_LENGTH));
2eb93d
+	return 0;
2eb93d
+}
2eb93d
+
2eb93d
+CXL_EXPORT unsigned long long cxl_cmd_identify_get_partition_align(
2eb93d
+		struct cxl_cmd *cmd)
2eb93d
+{
2eb93d
+	struct cxl_cmd_identify *id =
2eb93d
+			(struct cxl_cmd_identify *)cmd->send_cmd->out.payload;
2eb93d
+
2eb93d
+	if (cmd->send_cmd->id != CXL_MEM_COMMAND_ID_IDENTIFY)
2eb93d
+		return -EINVAL;
2eb93d
+	if (cmd->status < 0)
2eb93d
+		return cmd->status;
2eb93d
+
2eb93d
+	return le64_to_cpu(id->partition_align);
2eb93d
+}
2eb93d
+
2eb93d
+CXL_EXPORT unsigned int cxl_cmd_identify_get_label_size(struct cxl_cmd *cmd)
2eb93d
+{
2eb93d
+	struct cxl_cmd_identify *id =
2eb93d
+			(struct cxl_cmd_identify *)cmd->send_cmd->out.payload;
2eb93d
+
2eb93d
+	if (cmd->send_cmd->id != CXL_MEM_COMMAND_ID_IDENTIFY)
2eb93d
+		return -EINVAL;
2eb93d
+	if (cmd->status < 0)
2eb93d
+		return cmd->status;
2eb93d
+
2eb93d
+	return le32_to_cpu(id->lsa_size);
2eb93d
+}
2eb93d
+
2eb93d
 CXL_EXPORT struct cxl_cmd *cxl_cmd_new_raw(struct cxl_memdev *memdev,
2eb93d
 		int opcode)
2eb93d
 {
2eb93d
diff --git a/cxl/lib/libcxl.sym b/cxl/lib/libcxl.sym
2eb93d
index 3900f90..1dc45f4 100644
2eb93d
--- a/cxl/lib/libcxl.sym
2eb93d
+++ b/cxl/lib/libcxl.sym
2eb93d
@@ -29,6 +29,10 @@ global:
2eb93d
 	cxl_cmd_submit;
2eb93d
 	cxl_cmd_get_mbox_status;
2eb93d
 	cxl_cmd_get_out_size;
2eb93d
+	cxl_cmd_new_identify;
2eb93d
+	cxl_cmd_identify_get_fw_rev;
2eb93d
+	cxl_cmd_identify_get_partition_align;
2eb93d
+	cxl_cmd_identify_get_label_size;
2eb93d
 local:
2eb93d
         *;
2eb93d
 };
2eb93d
diff --git a/cxl/lib/private.h b/cxl/lib/private.h
2eb93d
index 87ca17e..3273f21 100644
2eb93d
--- a/cxl/lib/private.h
2eb93d
+++ b/cxl/lib/private.h
2eb93d
@@ -54,6 +54,25 @@ struct cxl_cmd {
2eb93d
 	int status;
2eb93d
 };
2eb93d
 
2eb93d
+#define CXL_CMD_IDENTIFY_FW_REV_LENGTH 0x10
2eb93d
+
2eb93d
+struct cxl_cmd_identify {
2eb93d
+	char fw_revision[CXL_CMD_IDENTIFY_FW_REV_LENGTH];
2eb93d
+	le64 total_capacity;
2eb93d
+	le64 volatile_capacity;
2eb93d
+	le64 persistent_capacity;
2eb93d
+	le64 partition_align;
2eb93d
+	le16 info_event_log_size;
2eb93d
+	le16 warning_event_log_size;
2eb93d
+	le16 failure_event_log_size;
2eb93d
+	le16 fatal_event_log_size;
2eb93d
+	le32 lsa_size;
2eb93d
+	u8 poison_list_max_mer[3];
2eb93d
+	le16 inject_poison_limit;
2eb93d
+	u8 poison_caps;
2eb93d
+	u8 qos_telemetry_caps;
2eb93d
+} __attribute__((packed));
2eb93d
+
2eb93d
 static inline int check_kmod(struct kmod_ctx *kmod_ctx)
2eb93d
 {
2eb93d
 	return kmod_ctx ? 0 : -ENXIO;
2eb93d
diff --git a/cxl/libcxl.h b/cxl/libcxl.h
2eb93d
index 6e87b80..0f2d5e9 100644
2eb93d
--- a/cxl/libcxl.h
2eb93d
+++ b/cxl/libcxl.h
2eb93d
@@ -58,6 +58,10 @@ void cxl_cmd_unref(struct cxl_cmd *cmd);
2eb93d
 int cxl_cmd_submit(struct cxl_cmd *cmd);
2eb93d
 int cxl_cmd_get_mbox_status(struct cxl_cmd *cmd);
2eb93d
 int cxl_cmd_get_out_size(struct cxl_cmd *cmd);
2eb93d
+struct cxl_cmd *cxl_cmd_new_identify(struct cxl_memdev *memdev);
2eb93d
+int cxl_cmd_identify_get_fw_rev(struct cxl_cmd *cmd, char *fw_rev, int fw_len);
2eb93d
+unsigned long long cxl_cmd_identify_get_partition_align(struct cxl_cmd *cmd);
2eb93d
+unsigned int cxl_cmd_identify_get_label_size(struct cxl_cmd *cmd);
2eb93d
 
2eb93d
 #ifdef __cplusplus
2eb93d
 } /* extern "C" */
2eb93d
-- 
2eb93d
2.27.0
2eb93d