Blame SOURCES/0046-cxl-add-health-information-to-cxl-list.patch

2eb93d
From f5d1e2133c54c1f420a0c3cf45fa633f097823be Mon Sep 17 00:00:00 2001
2eb93d
From: Vishal Verma <vishal.l.verma@intel.com>
2eb93d
Date: Thu, 7 Oct 2021 02:21:39 -0600
2eb93d
Subject: [PATCH 046/217] cxl: add health information to cxl-list
2eb93d
2eb93d
Add JSON output for fields from the 'GET_HEALTH_INFO' mailbox command
2eb93d
to memory device listings.
2eb93d
2eb93d
Cc: Dan Williams <dan.j.williams@intel.com>
2eb93d
Reviewed-by: Dan Williams <dan.j.williams@intel.com>
2eb93d
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
2eb93d
---
2eb93d
 Documentation/cxl/cxl-list.txt |  38 +++++++
2eb93d
 cxl/list.c                     |   5 +
2eb93d
 util/json.c                    | 179 +++++++++++++++++++++++++++++++++
2eb93d
 util/json.h                    |   1 +
2eb93d
 4 files changed, 223 insertions(+)
2eb93d
2eb93d
diff --git a/Documentation/cxl/cxl-list.txt b/Documentation/cxl/cxl-list.txt
2eb93d
index 370d5b8..c8d10fb 100644
2eb93d
--- a/Documentation/cxl/cxl-list.txt
2eb93d
+++ b/Documentation/cxl/cxl-list.txt
2eb93d
@@ -48,6 +48,44 @@ OPTIONS
2eb93d
 --idle::
2eb93d
 	Include idle (not enabled / zero-sized) devices in the listing
2eb93d
 
2eb93d
+-H::
2eb93d
+--health::
2eb93d
+	Include health information in the memdev listing. Example listing:
2eb93d
+----
2eb93d
+# cxl list -m mem0 -H
2eb93d
+[
2eb93d
+  {
2eb93d
+    "memdev":"mem0",
2eb93d
+    "pmem_size":268435456,
2eb93d
+    "ram_size":268435456,
2eb93d
+    "health":{
2eb93d
+      "maintenance_needed":true,
2eb93d
+      "performance_degraded":true,
2eb93d
+      "hw_replacement_needed":true,
2eb93d
+      "media_normal":false,
2eb93d
+      "media_not_ready":false,
2eb93d
+      "media_persistence_lost":false,
2eb93d
+      "media_data_lost":true,
2eb93d
+      "media_powerloss_persistence_loss":false,
2eb93d
+      "media_shutdown_persistence_loss":false,
2eb93d
+      "media_persistence_loss_imminent":false,
2eb93d
+      "media_powerloss_data_loss":false,
2eb93d
+      "media_shutdown_data_loss":false,
2eb93d
+      "media_data_loss_imminent":false,
2eb93d
+      "ext_life_used":"normal",
2eb93d
+      "ext_temperature":"critical",
2eb93d
+      "ext_corrected_volatile":"warning",
2eb93d
+      "ext_corrected_persistent":"normal",
2eb93d
+      "life_used_percent":15,
2eb93d
+      "temperature":25,
2eb93d
+      "dirty_shutdowns":10,
2eb93d
+      "volatile_errors":20,
2eb93d
+      "pmem_errors":30
2eb93d
+    }
2eb93d
+  }
2eb93d
+]
2eb93d
+----
2eb93d
+
2eb93d
 include::human-option.txt[]
2eb93d
 
2eb93d
 include::verbose-option.txt[]
2eb93d
diff --git a/cxl/list.c b/cxl/list.c
2eb93d
index 043d20c..b1468b7 100644
2eb93d
--- a/cxl/list.c
2eb93d
+++ b/cxl/list.c
2eb93d
@@ -16,6 +16,7 @@ static struct {
2eb93d
 	bool memdevs;
2eb93d
 	bool idle;
2eb93d
 	bool human;
2eb93d
+	bool health;
2eb93d
 } list;
2eb93d
 
2eb93d
 static unsigned long listopts_to_flags(void)
2eb93d
@@ -26,6 +27,8 @@ static unsigned long listopts_to_flags(void)
2eb93d
 		flags |= UTIL_JSON_IDLE;
2eb93d
 	if (list.human)
2eb93d
 		flags |= UTIL_JSON_HUMAN;
2eb93d
+	if (list.health)
2eb93d
+		flags |= UTIL_JSON_HEALTH;
2eb93d
 	return flags;
2eb93d
 }
2eb93d
 
2eb93d
@@ -57,6 +60,8 @@ int cmd_list(int argc, const char **argv, struct cxl_ctx *ctx)
2eb93d
 		OPT_BOOLEAN('i', "idle", &list.idle, "include idle devices"),
2eb93d
 		OPT_BOOLEAN('u', "human", &list.human,
2eb93d
 				"use human friendly number formats "),
2eb93d
+		OPT_BOOLEAN('H', "health", &list.health,
2eb93d
+				"include memory device health information "),
2eb93d
 		OPT_END(),
2eb93d
 	};
2eb93d
 	const char * const u[] = {
2eb93d
diff --git a/util/json.c b/util/json.c
2eb93d
index 3be3a92..f97cf07 100644
2eb93d
--- a/util/json.c
2eb93d
+++ b/util/json.c
2eb93d
@@ -1442,6 +1442,180 @@ struct json_object *util_badblock_rec_to_json(u64 block, u64 count,
2eb93d
 	return NULL;
2eb93d
 }
2eb93d
 
2eb93d
+static struct json_object *util_cxl_memdev_health_to_json(
2eb93d
+		struct cxl_memdev *memdev, unsigned long flags)
2eb93d
+{
2eb93d
+	struct json_object *jhealth;
2eb93d
+	struct json_object *jobj;
2eb93d
+	struct cxl_cmd *cmd;
2eb93d
+	u32 field;
2eb93d
+	int rc;
2eb93d
+
2eb93d
+	jhealth = json_object_new_object();
2eb93d
+	if (!jhealth)
2eb93d
+		return NULL;
2eb93d
+	if (!memdev)
2eb93d
+		goto err_jobj;
2eb93d
+
2eb93d
+	cmd = cxl_cmd_new_get_health_info(memdev);
2eb93d
+	if (!cmd)
2eb93d
+		goto err_jobj;
2eb93d
+
2eb93d
+	rc = cxl_cmd_submit(cmd);
2eb93d
+	if (rc < 0)
2eb93d
+		goto err_cmd;
2eb93d
+	rc = cxl_cmd_get_mbox_status(cmd);
2eb93d
+	if (rc != 0)
2eb93d
+		goto err_cmd;
2eb93d
+
2eb93d
+	/* health_status fields */
2eb93d
+	rc = cxl_cmd_health_info_get_maintenance_needed(cmd);
2eb93d
+	jobj = json_object_new_boolean(rc);
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "maintenance_needed", jobj);
2eb93d
+
2eb93d
+	rc = cxl_cmd_health_info_get_performance_degraded(cmd);
2eb93d
+	jobj = json_object_new_boolean(rc);
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "performance_degraded", jobj);
2eb93d
+
2eb93d
+	rc = cxl_cmd_health_info_get_hw_replacement_needed(cmd);
2eb93d
+	jobj = json_object_new_boolean(rc);
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "hw_replacement_needed", jobj);
2eb93d
+
2eb93d
+	/* media_status fields */
2eb93d
+	rc = cxl_cmd_health_info_get_media_normal(cmd);
2eb93d
+	jobj = json_object_new_boolean(rc);
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "media_normal", jobj);
2eb93d
+
2eb93d
+	rc = cxl_cmd_health_info_get_media_not_ready(cmd);
2eb93d
+	jobj = json_object_new_boolean(rc);
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "media_not_ready", jobj);
2eb93d
+
2eb93d
+	rc = cxl_cmd_health_info_get_media_persistence_lost(cmd);
2eb93d
+	jobj = json_object_new_boolean(rc);
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "media_persistence_lost", jobj);
2eb93d
+
2eb93d
+	rc = cxl_cmd_health_info_get_media_data_lost(cmd);
2eb93d
+	jobj = json_object_new_boolean(rc);
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "media_data_lost", jobj);
2eb93d
+
2eb93d
+	rc = cxl_cmd_health_info_get_media_powerloss_persistence_loss(cmd);
2eb93d
+	jobj = json_object_new_boolean(rc);
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "media_powerloss_persistence_loss", jobj);
2eb93d
+
2eb93d
+	rc = cxl_cmd_health_info_get_media_shutdown_persistence_loss(cmd);
2eb93d
+	jobj = json_object_new_boolean(rc);
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "media_shutdown_persistence_loss", jobj);
2eb93d
+
2eb93d
+	rc = cxl_cmd_health_info_get_media_persistence_loss_imminent(cmd);
2eb93d
+	jobj = json_object_new_boolean(rc);
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "media_persistence_loss_imminent", jobj);
2eb93d
+
2eb93d
+	rc = cxl_cmd_health_info_get_media_powerloss_data_loss(cmd);
2eb93d
+	jobj = json_object_new_boolean(rc);
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "media_powerloss_data_loss", jobj);
2eb93d
+
2eb93d
+	rc = cxl_cmd_health_info_get_media_shutdown_data_loss(cmd);
2eb93d
+	jobj = json_object_new_boolean(rc);
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "media_shutdown_data_loss", jobj);
2eb93d
+
2eb93d
+	rc = cxl_cmd_health_info_get_media_data_loss_imminent(cmd);
2eb93d
+	jobj = json_object_new_boolean(rc);
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "media_data_loss_imminent", jobj);
2eb93d
+
2eb93d
+	/* ext_status fields */
2eb93d
+	if (cxl_cmd_health_info_get_ext_life_used_normal(cmd))
2eb93d
+		jobj = json_object_new_string("normal");
2eb93d
+	else if (cxl_cmd_health_info_get_ext_life_used_warning(cmd))
2eb93d
+		jobj = json_object_new_string("warning");
2eb93d
+	else if (cxl_cmd_health_info_get_ext_life_used_critical(cmd))
2eb93d
+		jobj = json_object_new_string("critical");
2eb93d
+	else
2eb93d
+		jobj = json_object_new_string("unknown");
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "ext_life_used", jobj);
2eb93d
+
2eb93d
+	if (cxl_cmd_health_info_get_ext_temperature_normal(cmd))
2eb93d
+		jobj = json_object_new_string("normal");
2eb93d
+	else if (cxl_cmd_health_info_get_ext_temperature_warning(cmd))
2eb93d
+		jobj = json_object_new_string("warning");
2eb93d
+	else if (cxl_cmd_health_info_get_ext_temperature_critical(cmd))
2eb93d
+		jobj = json_object_new_string("critical");
2eb93d
+	else
2eb93d
+		jobj = json_object_new_string("unknown");
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "ext_temperature", jobj);
2eb93d
+
2eb93d
+	if (cxl_cmd_health_info_get_ext_corrected_volatile_normal(cmd))
2eb93d
+		jobj = json_object_new_string("normal");
2eb93d
+	else if (cxl_cmd_health_info_get_ext_corrected_volatile_warning(cmd))
2eb93d
+		jobj = json_object_new_string("warning");
2eb93d
+	else
2eb93d
+		jobj = json_object_new_string("unknown");
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "ext_corrected_volatile", jobj);
2eb93d
+
2eb93d
+	if (cxl_cmd_health_info_get_ext_corrected_persistent_normal(cmd))
2eb93d
+		jobj = json_object_new_string("normal");
2eb93d
+	else if (cxl_cmd_health_info_get_ext_corrected_persistent_warning(cmd))
2eb93d
+		jobj = json_object_new_string("warning");
2eb93d
+	else
2eb93d
+		jobj = json_object_new_string("unknown");
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "ext_corrected_persistent", jobj);
2eb93d
+
2eb93d
+	/* other fields */
2eb93d
+	field = cxl_cmd_health_info_get_life_used(cmd);
2eb93d
+	if (field != 0xff) {
2eb93d
+		jobj = json_object_new_int(field);
2eb93d
+		if (jobj)
2eb93d
+			json_object_object_add(jhealth, "life_used_percent", jobj);
2eb93d
+	}
2eb93d
+
2eb93d
+	field = cxl_cmd_health_info_get_temperature(cmd);
2eb93d
+	if (field != 0xffff) {
2eb93d
+		jobj = json_object_new_int(field);
2eb93d
+		if (jobj)
2eb93d
+			json_object_object_add(jhealth, "temperature", jobj);
2eb93d
+	}
2eb93d
+
2eb93d
+	field = cxl_cmd_health_info_get_dirty_shutdowns(cmd);
2eb93d
+	jobj = json_object_new_int64(field);
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "dirty_shutdowns", jobj);
2eb93d
+
2eb93d
+	field = cxl_cmd_health_info_get_volatile_errors(cmd);
2eb93d
+	jobj = json_object_new_int64(field);
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "volatile_errors", jobj);
2eb93d
+
2eb93d
+	field = cxl_cmd_health_info_get_pmem_errors(cmd);
2eb93d
+	jobj = json_object_new_int64(field);
2eb93d
+	if (jobj)
2eb93d
+		json_object_object_add(jhealth, "pmem_errors", jobj);
2eb93d
+
2eb93d
+	cxl_cmd_unref(cmd);
2eb93d
+	return jhealth;
2eb93d
+
2eb93d
+err_cmd:
2eb93d
+	cxl_cmd_unref(cmd);
2eb93d
+err_jobj:
2eb93d
+	json_object_put(jhealth);
2eb93d
+	return NULL;
2eb93d
+}
2eb93d
+
2eb93d
 struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
2eb93d
 		unsigned long flags)
2eb93d
 {
2eb93d
@@ -1464,5 +1638,10 @@ struct json_object *util_cxl_memdev_to_json(struct cxl_memdev *memdev,
2eb93d
 	if (jobj)
2eb93d
 		json_object_object_add(jdev, "ram_size", jobj);
2eb93d
 
2eb93d
+	if (flags & UTIL_JSON_HEALTH) {
2eb93d
+		jobj = util_cxl_memdev_health_to_json(memdev, flags);
2eb93d
+		if (jobj)
2eb93d
+			json_object_object_add(jdev, "health", jobj);
2eb93d
+	}
2eb93d
 	return jdev;
2eb93d
 }
2eb93d
diff --git a/util/json.h b/util/json.h
2eb93d
index 91918c8..ce575e6 100644
2eb93d
--- a/util/json.h
2eb93d
+++ b/util/json.h
2eb93d
@@ -19,6 +19,7 @@ enum util_json_flags {
2eb93d
 	UTIL_JSON_CONFIGURED	= (1 << 7),
2eb93d
 	UTIL_JSON_FIRMWARE	= (1 << 8),
2eb93d
 	UTIL_JSON_DAX_MAPPINGS	= (1 << 9),
2eb93d
+	UTIL_JSON_HEALTH	= (1 << 10),
2eb93d
 };
2eb93d
 
2eb93d
 struct json_object;
2eb93d
-- 
2eb93d
2.27.0
2eb93d