anitazha / rpms / ndctl

Forked from rpms/ndctl a year ago
Clone

Blame SOURCES/0127-libndctl-papr-Add-limited-support-for-inject-smart.patch

e0018b
From 9ef460eb7fd1b1f286955b18db8c18cd1a640e77 Mon Sep 17 00:00:00 2001
e0018b
From: Vaibhav Jain <vaibhav@linux.ibm.com>
e0018b
Date: Tue, 25 Jan 2022 02:08:04 +0530
e0018b
Subject: [PATCH 127/217] libndctl/papr: Add limited support for inject-smart
e0018b
e0018b
Implements support for ndctl inject-smart command by providing an
e0018b
implementation of 'smart_inject*' dimm-ops callbacks. Presently only
e0018b
support for injecting unsafe-shutdown and fatal-health states is
e0018b
available.
e0018b
e0018b
The patch also introduce various PAPR PDSM structures that are used to
e0018b
communicate the inject-smart errors to the papr_scm kernel
e0018b
module. This is done via SMART_INJECT PDSM which sends a payload of
e0018b
type 'struct nd_papr_pdsm_smart_inject'.
e0018b
e0018b
With the patch following output from ndctl inject-smart command is
e0018b
expected for PAPR NVDIMMs:
e0018b
e0018b
$ sudo ndctl inject-smart -fU nmem0
e0018b
[
e0018b
  {
e0018b
    "dev":"nmem0",
e0018b
    "flag_failed_flush":true,
e0018b
    "flag_smart_event":true,
e0018b
    "health":{
e0018b
      "health_state":"fatal",
e0018b
      "shutdown_state":"dirty",
e0018b
      "shutdown_count":0
e0018b
    }
e0018b
  }
e0018b
]
e0018b
e0018b
$ sudo ndctl inject-smart -N nmem0
e0018b
[
e0018b
  {
e0018b
    "dev":"nmem0",
e0018b
    "health":{
e0018b
      "health_state":"ok",
e0018b
      "shutdown_state":"clean",
e0018b
      "shutdown_count":0
e0018b
    }
e0018b
  }
e0018b
]
e0018b
e0018b
The patch depends on the kernel PAPR PDSM implementation for
e0018b
PDSM_SMART_INJECT posted at [1].
e0018b
e0018b
[1] : https://lore.kernel.org/nvdimm/20220124202204.1488346-1-vaibhav@linux.ibm.com/
e0018b
e0018b
Link: https://lore.kernel.org/r/20220124203804.1490254-1-vaibhav@linux.ibm.com
e0018b
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
e0018b
Signed-off-by: Shivaprasad G Bhat <sbhat@linux.ibm.com>
e0018b
Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>
e0018b
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
e0018b
---
e0018b
 ndctl/lib/papr.c      | 61 +++++++++++++++++++++++++++++++++++++++++++
e0018b
 ndctl/lib/papr_pdsm.h | 17 ++++++++++++
e0018b
 2 files changed, 78 insertions(+)
e0018b
e0018b
diff --git a/ndctl/lib/papr.c b/ndctl/lib/papr.c
e0018b
index 46cf9c1..7a1d559 100644
e0018b
--- a/ndctl/lib/papr.c
e0018b
+++ b/ndctl/lib/papr.c
e0018b
@@ -221,6 +221,41 @@ static unsigned int papr_smart_get_shutdown_state(struct ndctl_cmd *cmd)
e0018b
 	return health.dimm_bad_shutdown;
e0018b
 }
e0018b
 
e0018b
+static int papr_smart_inject_supported(struct ndctl_dimm *dimm)
e0018b
+{
e0018b
+	if (!ndctl_dimm_is_cmd_supported(dimm, ND_CMD_CALL))
e0018b
+		return -EOPNOTSUPP;
e0018b
+
e0018b
+	if (!test_dimm_dsm(dimm, PAPR_PDSM_SMART_INJECT))
e0018b
+		return -EIO;
e0018b
+
e0018b
+	return ND_SMART_INJECT_HEALTH_STATE | ND_SMART_INJECT_UNCLEAN_SHUTDOWN;
e0018b
+}
e0018b
+
e0018b
+static int papr_smart_inject_valid(struct ndctl_cmd *cmd)
e0018b
+{
e0018b
+	if (cmd->type != ND_CMD_CALL ||
e0018b
+	    to_pdsm(cmd)->cmd_status != 0 ||
e0018b
+	    to_pdsm_cmd(cmd) != PAPR_PDSM_SMART_INJECT)
e0018b
+		return -EINVAL;
e0018b
+
e0018b
+	return 0;
e0018b
+}
e0018b
+
e0018b
+static struct ndctl_cmd *papr_new_smart_inject(struct ndctl_dimm *dimm)
e0018b
+{
e0018b
+	struct ndctl_cmd *cmd;
e0018b
+
e0018b
+	cmd = allocate_cmd(dimm, PAPR_PDSM_SMART_INJECT,
e0018b
+			sizeof(struct nd_papr_pdsm_smart_inject));
e0018b
+	if (!cmd)
e0018b
+		return NULL;
e0018b
+	/* Set the input payload size */
e0018b
+	to_ndcmd(cmd)->nd_size_in = ND_PDSM_HDR_SIZE +
e0018b
+		sizeof(struct nd_papr_pdsm_smart_inject);
e0018b
+	return cmd;
e0018b
+}
e0018b
+
e0018b
 static unsigned int papr_smart_get_life_used(struct ndctl_cmd *cmd)
e0018b
 {
e0018b
 	struct nd_papr_pdsm_health health;
e0018b
@@ -255,11 +290,37 @@ static unsigned int papr_smart_get_shutdown_count(struct ndctl_cmd *cmd)
e0018b
 
e0018b
 	return (health.extension_flags & PDSM_DIMM_DSC_VALID) ?
e0018b
 		(health.dimm_dsc) : 0;
e0018b
+}
e0018b
+
e0018b
+static int papr_cmd_smart_inject_fatal(struct ndctl_cmd *cmd, bool enable)
e0018b
+{
e0018b
+	if (papr_smart_inject_valid(cmd) < 0)
e0018b
+		return -EINVAL;
e0018b
+
e0018b
+	to_payload(cmd)->inject.flags |= PDSM_SMART_INJECT_HEALTH_FATAL;
e0018b
+	to_payload(cmd)->inject.fatal_enable = enable;
e0018b
 
e0018b
+	return 0;
e0018b
+}
e0018b
+
e0018b
+static int papr_cmd_smart_inject_unsafe_shutdown(struct ndctl_cmd *cmd,
e0018b
+						 bool enable)
e0018b
+{
e0018b
+	if (papr_smart_inject_valid(cmd) < 0)
e0018b
+		return -EINVAL;
e0018b
+
e0018b
+	to_payload(cmd)->inject.flags |= PDSM_SMART_INJECT_BAD_SHUTDOWN;
e0018b
+	to_payload(cmd)->inject.unsafe_shutdown_enable = enable;
e0018b
+
e0018b
+	return 0;
e0018b
 }
e0018b
 
e0018b
 struct ndctl_dimm_ops * const papr_dimm_ops = &(struct ndctl_dimm_ops) {
e0018b
 	.cmd_is_supported = papr_cmd_is_supported,
e0018b
+	.new_smart_inject = papr_new_smart_inject,
e0018b
+	.smart_inject_supported = papr_smart_inject_supported,
e0018b
+	.smart_inject_fatal = papr_cmd_smart_inject_fatal,
e0018b
+	.smart_inject_unsafe_shutdown = papr_cmd_smart_inject_unsafe_shutdown,
e0018b
 	.smart_get_flags = papr_smart_get_flags,
e0018b
 	.get_firmware_status =  papr_get_firmware_status,
e0018b
 	.xlat_firmware_status = papr_xlat_firmware_status,
e0018b
diff --git a/ndctl/lib/papr_pdsm.h b/ndctl/lib/papr_pdsm.h
e0018b
index f45b1e4..20ac20f 100644
e0018b
--- a/ndctl/lib/papr_pdsm.h
e0018b
+++ b/ndctl/lib/papr_pdsm.h
e0018b
@@ -121,12 +121,29 @@ struct nd_papr_pdsm_health {
e0018b
 enum papr_pdsm {
e0018b
 	PAPR_PDSM_MIN = 0x0,
e0018b
 	PAPR_PDSM_HEALTH,
e0018b
+	PAPR_PDSM_SMART_INJECT,
e0018b
 	PAPR_PDSM_MAX,
e0018b
 };
e0018b
+/* Flags for injecting specific smart errors */
e0018b
+#define PDSM_SMART_INJECT_HEALTH_FATAL		(1 << 0)
e0018b
+#define PDSM_SMART_INJECT_BAD_SHUTDOWN		(1 << 1)
e0018b
+
e0018b
+struct nd_papr_pdsm_smart_inject {
e0018b
+	union {
e0018b
+		struct {
e0018b
+			/* One or more of PDSM_SMART_INJECT_ */
e0018b
+			__u32 flags;
e0018b
+			__u8 fatal_enable;
e0018b
+			__u8 unsafe_shutdown_enable;
e0018b
+		};
e0018b
+		__u8 buf[ND_PDSM_PAYLOAD_MAX_SIZE];
e0018b
+	};
e0018b
+};
e0018b
 
e0018b
 /* Maximal union that can hold all possible payload types */
e0018b
 union nd_pdsm_payload {
e0018b
 	struct nd_papr_pdsm_health health;
e0018b
+	struct nd_papr_pdsm_smart_inject inject;
e0018b
 	__u8 buf[ND_PDSM_PAYLOAD_MAX_SIZE];
e0018b
 } __attribute__((packed));
e0018b
 
e0018b
-- 
e0018b
2.27.0
e0018b