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

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