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

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