@@ -40,7 +40,9 @@
/* Per dimm data. Holds per-dimm data parsed from the cmd_pkgs */
struct dimm_priv {
- /* Empty for now */
+
+ /* Cache the dimm health status */
+ struct nd_papr_scm_dimm_health_stat health;
};
static bool papr_cmd_is_supported(struct ndctl_dimm *dimm, int cmd)
@@ -88,6 +90,43 @@ static bool cmd_is_valid(struct ndctl_dimm *dimm, struct ndctl_cmd *cmd)
return true;
}
+/*
+ * Parse the nd_papr_scm_dimm_health_stat_v1 payload embedded in ndctl_cmd and
+ * update dimm health/flags
+ */
+static int update_dimm_health_v1(struct ndctl_dimm *dimm, struct ndctl_cmd *cmd)
+{
+ struct nd_papr_scm_cmd_pkg *pcmd = nd_to_papr_cmd_pkg(cmd->pkg);
+ struct dimm_priv *p = dimm->dimm_user_data;
+ const struct nd_papr_scm_dimm_health_stat_v1 *health =
+ papr_scm_pcmd_to_payload(pcmd);
+
+ /* Update the dimm flags */
+ dimm->flags.f_arm = health->dimm_unarmed;
+ dimm->flags.f_flush = health->dimm_bad_shutdown;
+ dimm->flags.f_restore = health->dimm_bad_restore;
+ dimm->flags.f_smart = (health->dimm_health != 0);
+
+ /* Cache the dimm health information */
+ memcpy(&p->health, health, sizeof(*health));
+ return 0;
+}
+
+/* Check payload version returned and pass the packet to appropriate handler */
+static int update_dimm_health(struct ndctl_dimm *dimm, struct ndctl_cmd *cmd)
+{
+ const struct nd_papr_scm_cmd_pkg *pcmd = nd_to_papr_cmd_pkg(cmd->pkg);
+
+ if (pcmd->payload_version == 1)
+ return update_dimm_health_v1(dimm, cmd);
+
+ /* unknown version */
+ PAPR_ERR(dimm, "Unknown payload version for dimm_health."
+ "Ver=%d, Supported=%d\n", pcmd->payload_version,
+ ND_PAPR_SCM_DIMM_HEALTH_VERSION);
+ return -EINVAL;
+}
+
/* Parse a command payload and update dimm flags/private data */
static int update_dimm_stats(struct ndctl_dimm *dimm, struct ndctl_cmd *cmd)
{
@@ -113,6 +152,8 @@ static int update_dimm_stats(struct ndctl_dimm *dimm, struct ndctl_cmd *cmd)
/* Get the command dsm and handle it */
pcmd = nd_to_papr_cmd_pkg(cmd->pkg);
switch (pcmd_to_dsm(pcmd)) {
+ case DSM_PAPR_SCM_HEALTH:
+ return update_dimm_health(dimm, cmd);
default:
PAPR_ERR(dimm, "Unhandled dsm-command 0x%016llx\n",
pcmd_to_dsm(pcmd));
@@ -158,14 +199,45 @@ static struct ndctl_cmd *allocate_cmd(struct ndctl_dimm *dimm,
return cmd;
}
+static struct ndctl_cmd *papr_new_smart_health(struct ndctl_dimm *dimm)
+{
+ struct ndctl_cmd *cmd_ret;
+
+ cmd_ret = allocate_cmd(dimm, DSM_PAPR_SCM_HEALTH,
+ sizeof(struct nd_papr_scm_dimm_health_stat),
+ ND_PAPR_SCM_DIMM_HEALTH_VERSION);
+ if (!cmd_ret) {
+ PAPR_ERR(dimm, "Unable to allocate smart_health command\n");
+ return NULL;
+ }
+
+ cmd_ret->pkg[0].nd_size_out = ND_PAPR_SCM_ENVELOPE_CONTENT_SIZE(
+ struct nd_papr_scm_dimm_health_stat);
+
+ return cmd_ret;
+}
+
+static unsigned int papr_smart_get_health(struct ndctl_cmd *cmd)
+{
+ struct dimm_priv *p = cmd->dimm->dimm_user_data;
+
+ /*
+ * Update the dimm stats and use some math to return one of
+ * defined ND_SMART_*_HEALTH values
+ */
+ if (update_dimm_stats(cmd->dimm, cmd) || !p->health.dimm_health)
+ return 0;
+ else
+ return 1 << (p->health.dimm_health - 1);
+}
+
static unsigned int papr_smart_get_flags(struct ndctl_cmd *cmd)
{
/* In case of error return empty flags * */
if (update_dimm_stats(cmd->dimm, cmd))
return 0;
- /* Return empty flags for now as no DSM support */
- return 0;
+ return ND_SMART_HEALTH_VALID;
}
static int papr_dimm_init(struct ndctl_dimm *dimm)
@@ -205,4 +277,6 @@ struct ndctl_dimm_ops * const papr_scm_dimm_ops = &(struct ndctl_dimm_ops) {
.dimm_init = papr_dimm_init,
.dimm_uninit = papr_dimm_uninit,
.smart_get_flags = papr_smart_get_flags,
+ .new_smart = papr_new_smart_health,
+ .smart_get_health = papr_smart_get_health,
};
Add support for reporting DIMM health by issuing DSM_PAPR_SCM_HEALTH DSM. It returns an instance of ' struct nd_papr_scm_dimm_health_stat' as defined in 'papr_scm_dsm.h'. The patch provides support for dimm-ops 'new_smart' & 'smart_get_health' as papr_new_smart_health() & papr_smart_get_health() respectively. This callbacks should enable ndctl to report DIMM health. Also a new member 'struct dimm_priv.health' is introduced which holds the current health status of the dimm. This member is set inside newly added function 'update_dimm_health_v1()' which parses the v1 payload returned by the kernel after servicing DSM_PAPR_SCM_HEALTH. The function will also update dimm-flags viz 'struct ndctl_dimm.flags.f_*' based on the flags set in the returned payload. Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com> --- ndctl/lib/papr_scm.c | 80 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 77 insertions(+), 3 deletions(-)