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

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