anitazha / rpms / ndctl

Forked from rpms/ndctl a year ago
Clone

Blame SOURCES/0007-msft-Add-xlat_firmware_status-for-JEDEC-Byte-Address.patch

e0018b
From 11357d68b77392e4360ae2824e75bf8397a84885 Mon Sep 17 00:00:00 2001
e0018b
From: Redhairer Li <redhairer.li@intel.com>
e0018b
Date: Sat, 9 Jan 2021 23:36:33 +0800
e0018b
Subject: [PATCH 007/217] msft: Add xlat_firmware_status for JEDEC Byte
e0018b
 Addressable Energy Backed DSM
e0018b
e0018b
Translate the status codes of the result of JEDEC Byte Addressable Energy Backed
e0018b
DSM to generic errno style error codes.
e0018b
e0018b
Signed-off-by: Li Redhairer <redhairer.li@intel.com>
e0018b
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
e0018b
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
e0018b
Link: https://lore.kernel.org/r/20210109153633.8493-1-redhairer.li@intel.com
e0018b
---
e0018b
 ndctl/lib/msft.c | 22 ++++++++++++++++++++++
e0018b
 ndctl/lib/msft.h |  6 ++++++
e0018b
 2 files changed, 28 insertions(+)
e0018b
e0018b
diff --git a/ndctl/lib/msft.c b/ndctl/lib/msft.c
e0018b
index 145872c..3112799 100644
e0018b
--- a/ndctl/lib/msft.c
e0018b
+++ b/ndctl/lib/msft.c
e0018b
@@ -149,10 +149,32 @@ static unsigned int msft_cmd_smart_get_life_used(struct ndctl_cmd *cmd)
e0018b
 	return 100 - CMD_MSFT_SMART(cmd)->nvm_lifetime;
e0018b
 }
e0018b
 
e0018b
+static int msft_cmd_xlat_firmware_status(struct ndctl_cmd *cmd)
e0018b
+{
e0018b
+	unsigned int status;
e0018b
+
e0018b
+	status = cmd->get_firmware_status(cmd) & NDN_MSFT_STATUS_MASK;
e0018b
+
e0018b
+	/* Common statuses */
e0018b
+	switch (status) {
e0018b
+	case NDN_MSFT_STATUS_SUCCESS:
e0018b
+		return 0;
e0018b
+	case NDN_MSFT_STATUS_NOTSUPP:
e0018b
+		return -EOPNOTSUPP;
e0018b
+	case NDN_MSFT_STATUS_INVALPARM:
e0018b
+		return -EINVAL;
e0018b
+	case NDN_MSFT_STATUS_I2CERR:
e0018b
+		return -EIO;
e0018b
+	}
e0018b
+
e0018b
+	return -ENOMSG;
e0018b
+}
e0018b
+
e0018b
 struct ndctl_dimm_ops * const msft_dimm_ops = &(struct ndctl_dimm_ops) {
e0018b
 	.new_smart = msft_dimm_cmd_new_smart,
e0018b
 	.smart_get_flags = msft_cmd_smart_get_flags,
e0018b
 	.smart_get_health = msft_cmd_smart_get_health,
e0018b
 	.smart_get_media_temperature = msft_cmd_smart_get_media_temperature,
e0018b
 	.smart_get_life_used = msft_cmd_smart_get_life_used,
e0018b
+	.xlat_firmware_status = msft_cmd_xlat_firmware_status,
e0018b
 };
e0018b
diff --git a/ndctl/lib/msft.h b/ndctl/lib/msft.h
e0018b
index 7cfd26f..978cc11 100644
e0018b
--- a/ndctl/lib/msft.h
e0018b
+++ b/ndctl/lib/msft.h
e0018b
@@ -50,4 +50,10 @@ struct ndn_pkg_msft {
e0018b
 	union ndn_msft_cmd	u;
e0018b
 } __attribute__((packed));
e0018b
 
e0018b
+#define NDN_MSFT_STATUS_MASK		0xffff
e0018b
+#define NDN_MSFT_STATUS_SUCCESS	0
e0018b
+#define NDN_MSFT_STATUS_NOTSUPP	1
e0018b
+#define NDN_MSFT_STATUS_INVALPARM	2
e0018b
+#define NDN_MSFT_STATUS_I2CERR		3
e0018b
+
e0018b
 #endif /* __NDCTL_MSFT_H__ */
e0018b
-- 
e0018b
2.27.0
e0018b