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