Blame SOURCES/0126-libndctl-intel-Indicate-supported-smart-inject-types.patch

2eb93d
From edcd9b7e10b3b33a9660e412a2db1beab30936d3 Mon Sep 17 00:00:00 2001
2eb93d
From: Vaibhav Jain <vaibhav@linux.ibm.com>
2eb93d
Date: Tue, 25 Jan 2022 02:07:35 +0530
2eb93d
Subject: [PATCH 126/217] libndctl, intel: Indicate supported smart-inject
2eb93d
 types
8afcf0
2eb93d
Presently the inject-smart code assumes support for injecting all
2eb93d
smart-errors namely media-temperature, controller-temperature,
2eb93d
spares-remaining, fatal-health and unsafe-shutdown. This assumption
2eb93d
may break in case of other non-Intel NVDIMM types namely PAPR NVDIMMs
2eb93d
which presently only have support for injecting unsafe-shutdown and
2eb93d
fatal health events.
8afcf0
2eb93d
Trying to inject-smart errors on PAPR NVDIMMs causes problems as
2eb93d
smart_inject() prematurely exits when trying to inject
2eb93d
media-temperature smart-error errors out.
8afcf0
2eb93d
To fix this issue the patch proposes extending the definition of
2eb93d
dimm_op 'smart_inject_supported' to return bitmap of flags indicating
2eb93d
the type of smart-error injections supported by an NVDIMM. These types
2eb93d
are indicated by the newly introduced defines ND_SMART_INJECT_* . A
2eb93d
dimm-ops provide can return an bitmap composed of these flags back
2eb93d
from its implementation of 'smart_inject_supported' to indicate to
2eb93d
dimm_inject_smart() which type of smart-error injection it
2eb93d
supports. In case of an error the dimm-op is still expected to return
2eb93d
a negative error code back to the caller.
2eb93d
2eb93d
The patch updates intel_dimm_smart_inject_supported() to return a
2eb93d
bitmap composed of all ND_SMART_INJECT_* flags to indicate support for
2eb93d
all smart-error types.
2eb93d
2eb93d
Finally the patch also updates smart_inject() to test for specific
2eb93d
ND_START_INJECT_* flags before sending a smart-inject command via
2eb93d
dimm-provider.
2eb93d
2eb93d
Link: https://lore.kernel.org/r/20220124203735.1490186-1-vaibhav@linux.ibm.com
2eb93d
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
2eb93d
Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>
2eb93d
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
2eb93d
---
2eb93d
 ndctl/inject-smart.c | 31 ++++++++++++++++++++++++-------
2eb93d
 ndctl/lib/intel.c    |  7 ++++++-
2eb93d
 ndctl/libndctl.h     |  8 ++++++++
2eb93d
 3 files changed, 38 insertions(+), 8 deletions(-)
8afcf0
8afcf0
diff --git a/ndctl/inject-smart.c b/ndctl/inject-smart.c
8afcf0
index 2b9d7e8..bd8c01e 100644
8afcf0
--- a/ndctl/inject-smart.c
8afcf0
+++ b/ndctl/inject-smart.c
8afcf0
@@ -395,18 +395,26 @@ out:
8afcf0
 	} \
8afcf0
 }
8afcf0
 
8afcf0
-static int smart_inject(struct ndctl_dimm *dimm)
8afcf0
+static int smart_inject(struct ndctl_dimm *dimm, unsigned int inject_types)
8afcf0
 {
8afcf0
 	const char *name = ndctl_dimm_get_devname(dimm);
8afcf0
 	struct ndctl_cmd *si_cmd = NULL;
8afcf0
 	int rc = -EOPNOTSUPP;
8afcf0
 
8afcf0
-	send_inject_val(media_temperature)
8afcf0
-	send_inject_val(ctrl_temperature)
8afcf0
-	send_inject_val(spares)
8afcf0
-	send_inject_bool(fatal)
8afcf0
-	send_inject_bool(unsafe_shutdown)
8afcf0
+	if (inject_types & ND_SMART_INJECT_MEDIA_TEMPERATURE)
8afcf0
+		send_inject_val(media_temperature);
8afcf0
 
8afcf0
+	if (inject_types & ND_SMART_INJECT_CTRL_TEMPERATURE)
8afcf0
+		send_inject_val(ctrl_temperature);
8afcf0
+
8afcf0
+	if (inject_types & ND_SMART_INJECT_SPARES_REMAINING)
8afcf0
+		send_inject_val(spares);
8afcf0
+
8afcf0
+	if (inject_types & ND_SMART_INJECT_HEALTH_STATE)
8afcf0
+		send_inject_bool(fatal);
8afcf0
+
8afcf0
+	if (inject_types & ND_SMART_INJECT_UNCLEAN_SHUTDOWN)
8afcf0
+		send_inject_bool(unsafe_shutdown);
8afcf0
 out:
8afcf0
 	ndctl_cmd_unref(si_cmd);
8afcf0
 	return rc;
8afcf0
@@ -417,6 +425,7 @@ static int dimm_inject_smart(struct ndctl_dimm *dimm)
8afcf0
 	struct json_object *jhealth;
8afcf0
 	struct json_object *jdimms;
8afcf0
 	struct json_object *jdimm;
8afcf0
+	unsigned int supported_types;
8afcf0
 	int rc;
8afcf0
 
8afcf0
 	rc = ndctl_dimm_smart_inject_supported(dimm);
8afcf0
@@ -433,6 +442,14 @@ static int dimm_inject_smart(struct ndctl_dimm *dimm)
8afcf0
 		error("%s: smart injection not supported by either platform firmware or the kernel.",
8afcf0
 			ndctl_dimm_get_devname(dimm));
8afcf0
 		return rc;
8afcf0
+	default:
8afcf0
+		if (rc < 0) {
8afcf0
+			error("%s: Unknown error %d while checking for smart injection support",
8afcf0
+			      ndctl_dimm_get_devname(dimm), rc);
8afcf0
+			return rc;
8afcf0
+		}
8afcf0
+		supported_types = rc;
8afcf0
+		break;
8afcf0
 	}
8afcf0
 
8afcf0
 	if (sctx.op_mask & (1 << OP_SET)) {
8afcf0
@@ -441,7 +458,7 @@ static int dimm_inject_smart(struct ndctl_dimm *dimm)
8afcf0
 			goto out;
8afcf0
 	}
8afcf0
 	if (sctx.op_mask & (1 << OP_INJECT)) {
8afcf0
-		rc = smart_inject(dimm);
8afcf0
+		rc = smart_inject(dimm, supported_types);
8afcf0
 		if (rc)
8afcf0
 			goto out;
8afcf0
 	}
8afcf0
diff --git a/ndctl/lib/intel.c b/ndctl/lib/intel.c
8afcf0
index a3df26e..1314854 100644
8afcf0
--- a/ndctl/lib/intel.c
8afcf0
+++ b/ndctl/lib/intel.c
8afcf0
@@ -455,7 +455,12 @@ static int intel_dimm_smart_inject_supported(struct ndctl_dimm *dimm)
8afcf0
 		return -EIO;
8afcf0
 	}
8afcf0
 
8afcf0
-	return 0;
8afcf0
+	/* Indicate all smart injection types are supported */
8afcf0
+	return ND_SMART_INJECT_SPARES_REMAINING |
8afcf0
+		ND_SMART_INJECT_MEDIA_TEMPERATURE |
8afcf0
+		ND_SMART_INJECT_CTRL_TEMPERATURE |
8afcf0
+		ND_SMART_INJECT_HEALTH_STATE |
8afcf0
+		ND_SMART_INJECT_UNCLEAN_SHUTDOWN;
8afcf0
 }
8afcf0
 
8afcf0
 static const char *intel_cmd_desc(int fn)
8afcf0
diff --git a/ndctl/libndctl.h b/ndctl/libndctl.h
8afcf0
index b59026c..4d5cdbf 100644
8afcf0
--- a/ndctl/libndctl.h
8afcf0
+++ b/ndctl/libndctl.h
8afcf0
@@ -69,6 +69,13 @@ extern "C" {
8afcf0
 #define ND_EVENT_HEALTH_STATE		(1 << 3)
8afcf0
 #define ND_EVENT_UNCLEAN_SHUTDOWN	(1 << 4)
8afcf0
 
8afcf0
+/* Flags indicating support for various smart injection types */
8afcf0
+#define ND_SMART_INJECT_SPARES_REMAINING	(1 << 0)
8afcf0
+#define ND_SMART_INJECT_MEDIA_TEMPERATURE	(1 << 1)
8afcf0
+#define ND_SMART_INJECT_CTRL_TEMPERATURE	(1 << 2)
8afcf0
+#define ND_SMART_INJECT_HEALTH_STATE		(1 << 3)
8afcf0
+#define ND_SMART_INJECT_UNCLEAN_SHUTDOWN	(1 << 4)
8afcf0
+
8afcf0
 size_t ndctl_min_namespace_size(void);
8afcf0
 size_t ndctl_sizeof_namespace_index(void);
8afcf0
 size_t ndctl_sizeof_namespace_label(void);
8afcf0
@@ -311,6 +318,7 @@ int ndctl_cmd_smart_inject_spares(struct ndctl_cmd *cmd, bool enable,
8afcf0
 		unsigned int spares);
8afcf0
 int ndctl_cmd_smart_inject_fatal(struct ndctl_cmd *cmd, bool enable);
8afcf0
 int ndctl_cmd_smart_inject_unsafe_shutdown(struct ndctl_cmd *cmd, bool enable);
8afcf0
+/* Returns a bitmap of ND_SMART_INJECT_* supported */
8afcf0
 int ndctl_dimm_smart_inject_supported(struct ndctl_dimm *dimm);
8afcf0
 
8afcf0
 struct ndctl_cmd *ndctl_dimm_cmd_new_vendor_specific(struct ndctl_dimm *dimm,
2eb93d
-- 
2eb93d
2.27.0
2eb93d