anitazha / rpms / ndctl

Forked from rpms/ndctl a year ago
Clone

Blame SOURCES/aa99000-libndctl-papr-Add-support-for-reporting-shutdown-count.patch

4a01d4
libndctl/papr: Add support for reporting shutdown-count
4a01d4
4a01d4
BZ: 
4a01d4
Brew: 
4a01d4
4a01d4
commit aa990008f48f21121474a411d829f24e832c89a2
4a01d4
Author: Vaibhav Jain <vaibhav@linux.ibm.com>
4a01d4
Date:   Tue Jan 25 00:26:05 2022 +0530
4a01d4
4a01d4
    libndctl/papr: Add support for reporting shutdown-count
4a01d4
    
4a01d4
    Add support for reporting dirty-shutdown-count (DSC) for PAPR based
4a01d4
    NVDIMMs. The sysfs attribute exposing this value is located at
4a01d4
    nmemX/papr/dirty_shutdown.
4a01d4
    
4a01d4
    This counter is also returned in payload for PAPR_PDSM_HEALTH as newly
4a01d4
    introduced member 'dimm_dsc' in 'struct nd_papr_pdsm_health'. Presence
4a01d4
    of 'DSC' is indicated by the PDSM_DIMM_DSC_VALID extension flag.
4a01d4
    
4a01d4
    The patch implements 'ndctl_dimm_ops.smart_get_shutdown_count'
4a01d4
    callback in implemented as papr_smart_get_shutdown_count().
4a01d4
    
4a01d4
    Kernel side changes to support reporting DSC have been merged to linux kernel
4a01d4
    via patch proposed at [1]. With updated kernel 'ndctl list -DH' reports
4a01d4
    following output on PPC64:
4a01d4
    
4a01d4
    $ sudo ndctl list -DH
4a01d4
    [
4a01d4
      {
4a01d4
        "dev":"nmem0",
4a01d4
        "health":{
4a01d4
          "health_state":"ok",
4a01d4
          "life_used_percentage":50,
4a01d4
          "shutdown_state":"clean",
4a01d4
          "shutdown_count":10
4a01d4
        }
4a01d4
      }
4a01d4
    ]
4a01d4
    
4a01d4
    [1] http://patchwork.ozlabs.org/project/linuxppc-dev/patch/20210624080621.252038-1-vaibhav@linux.ibm.com
4a01d4
    
4a01d4
    Link: https://lore.kernel.org/r/20220124185605.1465681-1-vaibhav@linux.ibm.com
4a01d4
    Signed-off-by: Vaibhav Jain <vaibhav@linux.ibm.com>
4a01d4
    Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
4a01d4
4a01d4
diff --git a/ndctl/lib/libndctl.c b/ndctl/lib/libndctl.c
4a01d4
index 47a234c..5979a92 100644
4a01d4
--- a/ndctl/lib/libndctl.c
4a01d4
+++ b/ndctl/lib/libndctl.c
4a01d4
@@ -1819,8 +1819,12 @@ static int add_papr_dimm(struct ndctl_dimm *dimm, const char *dimm_base)
4a01d4
 
4a01d4
 		/* Allocate monitor mode fd */
4a01d4
 		dimm->health_eventfd = open(path, O_RDONLY|O_CLOEXEC);
4a01d4
-		rc = 0;
4a01d4
+		/* Get the dirty shutdown counter value */
4a01d4
+		sprintf(path, "%s/papr/dirty_shutdown", dimm_base);
4a01d4
+		if (sysfs_read_attr(ctx, path, buf) == 0)
4a01d4
+			dimm->dirty_shutdown = strtoll(buf, NULL, 0);
4a01d4
 
4a01d4
+		rc = 0;
4a01d4
 	} else if (strcmp(buf, "nvdimm_test") == 0) {
4a01d4
 		/* probe via common populate_dimm_attributes() */
4a01d4
 		rc = populate_dimm_attributes(dimm, dimm_base, "papr");
4a01d4
diff --git a/ndctl/lib/papr.c b/ndctl/lib/papr.c
4a01d4
index 43b8412..46cf9c1 100644
4a01d4
--- a/ndctl/lib/papr.c
4a01d4
+++ b/ndctl/lib/papr.c
4a01d4
@@ -165,6 +165,9 @@ static unsigned int papr_smart_get_flags(struct ndctl_cmd *cmd)
4a01d4
 		if (health.extension_flags & PDSM_DIMM_HEALTH_RUN_GAUGE_VALID)
4a01d4
 			flags |= ND_SMART_USED_VALID;
4a01d4
 
4a01d4
+		if (health.extension_flags &  PDSM_DIMM_DSC_VALID)
4a01d4
+			flags |= ND_SMART_SHUTDOWN_COUNT_VALID;
4a01d4
+
4a01d4
 		return flags;
4a01d4
 	}
4a01d4
 
4a01d4
@@ -236,6 +239,25 @@ static unsigned int papr_smart_get_life_used(struct ndctl_cmd *cmd)
4a01d4
 		(100 - health.dimm_fuel_gauge) : 0;
4a01d4
 }
4a01d4
 
4a01d4
+static unsigned int papr_smart_get_shutdown_count(struct ndctl_cmd *cmd)
4a01d4
+{
4a01d4
+
4a01d4
+	struct nd_papr_pdsm_health health;
4a01d4
+
4a01d4
+	/* Ignore in case of error or invalid pdsm */
4a01d4
+	if (!cmd_is_valid(cmd) ||
4a01d4
+	    to_pdsm(cmd)->cmd_status != 0 ||
4a01d4
+	    to_pdsm_cmd(cmd) != PAPR_PDSM_HEALTH)
4a01d4
+		return 0;
4a01d4
+
4a01d4
+	/* get the payload from command */
4a01d4
+	health = to_payload(cmd)->health;
4a01d4
+
4a01d4
+	return (health.extension_flags & PDSM_DIMM_DSC_VALID) ?
4a01d4
+		(health.dimm_dsc) : 0;
4a01d4
+
4a01d4
+}
4a01d4
+
4a01d4
 struct ndctl_dimm_ops * const papr_dimm_ops = &(struct ndctl_dimm_ops) {
4a01d4
 	.cmd_is_supported = papr_cmd_is_supported,
4a01d4
 	.smart_get_flags = papr_smart_get_flags,
4a01d4
@@ -245,4 +267,5 @@ struct ndctl_dimm_ops * const papr_dimm_ops = &(struct ndctl_dimm_ops) {
4a01d4
 	.smart_get_health = papr_smart_get_health,
4a01d4
 	.smart_get_shutdown_state = papr_smart_get_shutdown_state,
4a01d4
 	.smart_get_life_used = papr_smart_get_life_used,
4a01d4
+	.smart_get_shutdown_count = papr_smart_get_shutdown_count,
4a01d4
 };
4a01d4
diff --git a/ndctl/lib/papr_pdsm.h b/ndctl/lib/papr_pdsm.h
4a01d4
index 1bac8a7..f45b1e4 100644
4a01d4
--- a/ndctl/lib/papr_pdsm.h
4a01d4
+++ b/ndctl/lib/papr_pdsm.h
4a01d4
@@ -75,6 +75,9 @@
4a01d4
 /* Indicate that the 'dimm_fuel_gauge' field is valid */
4a01d4
 #define PDSM_DIMM_HEALTH_RUN_GAUGE_VALID 1
4a01d4
 
4a01d4
+/* Indicate that the 'dimm_dsc' field is valid */
4a01d4
+#define PDSM_DIMM_DSC_VALID 2
4a01d4
+
4a01d4
 /*
4a01d4
  * Struct exchanged between kernel & ndctl in for PAPR_PDSM_HEALTH
4a01d4
  * Various flags indicate the health status of the dimm.
4a01d4
@@ -103,6 +106,9 @@ struct nd_papr_pdsm_health {
4a01d4
 
4a01d4
 			/* Extension flag PDSM_DIMM_HEALTH_RUN_GAUGE_VALID */
4a01d4
 			__u16 dimm_fuel_gauge;
4a01d4
+
4a01d4
+			/* Extension flag PDSM_DIMM_DSC_VALID */
4a01d4
+			__u64 dimm_dsc;
4a01d4
 		};
4a01d4
 		__u8 buf[ND_PDSM_PAYLOAD_MAX_SIZE];
4a01d4
 	};