Blame SOURCES/0010-nvme-cli-Decode-Supported-Events-Bitmap-in-PEL-heade.patch

61fcf4
From a0db61992c14b34fcf6787b957d5d5d0e77c6f33 Mon Sep 17 00:00:00 2001
61fcf4
From: Maurizio Lombardi <mlombard@redhat.com>
61fcf4
Date: Wed, 29 Jun 2022 18:00:44 +0200
61fcf4
Subject: [PATCH 3/7] nvme-cli: Decode "Supported Events Bitmap" in PEL header
61fcf4
61fcf4
"Supported Events Bitmap" in PEL header shows what events
61fcf4
are supported in current nvme devices.
61fcf4
61fcf4
Persistent Event Log for device: nvme0n1
61fcf4
Action for Persistent Event Log: 0
61fcf4
..
61fcf4
..
61fcf4
..
61fcf4
Supported Events Bitmap:
61fcf4
        Support SMART/Health Log Snapshot Event(0x1)
61fcf4
        Support Firmware Commit Event(0x2)
61fcf4
        Support Timestamp Change Event(0x3)
61fcf4
        Support Power-on or Reset Event(0x4)
61fcf4
        Support NVM Subsystem Hardware Error Event(0x5)
61fcf4
        Support Change Namespace Event(0x6)
61fcf4
        Support Format NVM Start Event(0x7)
61fcf4
        Support Format NVM Completion Event(0x8)
61fcf4
        Support Sanitize Start Event(0x9)
61fcf4
        Support Sanitize Completion Event(0xa)
61fcf4
        Support Set Feature Event(0xb)
61fcf4
        Support Set Telemetry CRT  Event(0xc)
61fcf4
        Support Thermal Excursion Event(0xd)
61fcf4
61fcf4
Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
61fcf4
---
61fcf4
 nvme-print.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++------
61fcf4
 nvme.c       |  4 ++--
61fcf4
 2 files changed, 48 insertions(+), 8 deletions(-)
61fcf4
61fcf4
diff --git a/nvme-print.c b/nvme-print.c
61fcf4
index f631b347..21524a50 100755
61fcf4
--- a/nvme-print.c
61fcf4
+++ b/nvme-print.c
61fcf4
@@ -1015,6 +1015,26 @@ void nvme_show_predictable_latency_event_agg_log(
61fcf4
 	}
61fcf4
 }
61fcf4
 
61fcf4
+const char *nvme_pel_event_to_string(int type)
61fcf4
+{
61fcf4
+	switch (type) {
61fcf4
+	case NVME_SMART_HEALTH_EVENT:	return "SMART/Health Log Snapshot Event(0x1)";
61fcf4
+	case NVME_FW_COMMIT_EVENT:	return "Firmware Commit Event(0x2)";
61fcf4
+	case NVME_TIMESTAMP_EVENT:	return "Timestamp Change Event(0x3)";
61fcf4
+	case NVME_POWER_ON_RESET_EVENT:	return "Power-on or Reset Event(0x4)";
61fcf4
+	case NVME_NSS_HW_ERROR_EVENT:	return "NVM Subsystem Hardware Error Event(0x5)";
61fcf4
+	case NVME_CHANGE_NS_EVENT:	return "Change Namespace Event(0x6)";
61fcf4
+	case NVME_FORMAT_START_EVENT:	return "Format NVM Start Event(0x7)";
61fcf4
+	case NVME_FORMAT_COMPLETION_EVENT:	return "Format NVM Completion Event(0x8)";
61fcf4
+	case NVME_SANITIZE_START_EVENT:	return "Sanitize Start Event(0x9)";
61fcf4
+	case NVME_SANITIZE_COMPLETION_EVENT:	return "Sanitize Completion Event(0xa)";
61fcf4
+	case NVME_SET_FEATURE_EVENT:	return "Set Feature Event(0xb)";
61fcf4
+	case NVME_TELEMETRY_CRT:		return "Set Telemetry CRT  Event(0xc)";
61fcf4
+	case NVME_THERMAL_EXCURSION_EVENT:	return "Thermal Excursion Event(0xd)";
61fcf4
+	default:			return NULL;
61fcf4
+	}
61fcf4
+}
61fcf4
+
61fcf4
 static const char *nvme_show_nss_hw_error(__u16 error_code)
61fcf4
 {
61fcf4
 	switch (error_code) {
61fcf4
@@ -1043,6 +1063,29 @@ static const char *nvme_show_nss_hw_error(__u16 error_code)
61fcf4
 	}
61fcf4
 }
61fcf4
 
61fcf4
+static void add_bitmap(int i, __u8 seb, struct json_object *root, int json_flag)
61fcf4
+{
61fcf4
+	char evt_str[50];
61fcf4
+	char key[128];
61fcf4
+
61fcf4
+	for (int bit = 0; bit < 8; bit++) {
61fcf4
+		if (nvme_pel_event_to_string(bit + i * 8)) {
61fcf4
+			if (json_flag == 1) {
61fcf4
+				sprintf(key, "bitmap_%x", (bit + i * 8));
61fcf4
+				if ((seb >> bit) & 0x1)
61fcf4
+					snprintf(evt_str, sizeof(evt_str), "Support %s",
61fcf4
+						nvme_pel_event_to_string(bit + i * 8));
61fcf4
+				json_object_add_value_string(root, key, evt_str);
61fcf4
+			} else {
61fcf4
+				if (nvme_pel_event_to_string(bit + i * 8))
61fcf4
+					if ((seb >> bit) & 0x1)
61fcf4
+						printf("	Support %s\n",
61fcf4
+							nvme_pel_event_to_string(bit + i * 8));
61fcf4
+			}
61fcf4
+		}
61fcf4
+	}
61fcf4
+}
61fcf4
+
61fcf4
 void json_persistent_event_log(void *pevent_log_info, __u32 size)
61fcf4
 {
61fcf4
 	struct json_object *root;
61fcf4
@@ -1112,9 +1155,7 @@ void json_persistent_event_log(void *pevent_log_info, __u32 size)
61fcf4
 		for (int i = 0; i < 32; i++) {
61fcf4
 			if (pevent_log_head->supp_event_bm[i] == 0)
61fcf4
 				continue;
61fcf4
-			sprintf(key, "bitmap_%d", i);
61fcf4
-			json_object_add_value_uint(root, key,
61fcf4
-				pevent_log_head->supp_event_bm[i]);
61fcf4
+			add_bitmap(i, pevent_log_head->supp_event_bm[i], root, 1);
61fcf4
 		}
61fcf4
 	} else {
61fcf4
 		printf("No log data can be shown with this log len at least " \
61fcf4
@@ -1440,12 +1481,11 @@ void nvme_show_persistent_event_log(void *pevent_log_info,
61fcf4
 			le32_to_cpu(pevent_log_head->rci));
61fcf4
 		if(human)
61fcf4
 			nvme_show_persistent_event_log_rci(pevent_log_head->rci);
61fcf4
-		printf("Supported Events Bitmap: ");
61fcf4
+		printf("Supported Events Bitmap: \n");
61fcf4
 		for (int i = 0; i < 32; i++) {
61fcf4
 			if (pevent_log_head->supp_event_bm[i] == 0)
61fcf4
 				continue;
61fcf4
-			printf("BitMap[%d] is 0x%x\n", i,
61fcf4
-				pevent_log_head->supp_event_bm[i]);
61fcf4
+			add_bitmap(i, pevent_log_head->supp_event_bm[i], NULL, 0);
61fcf4
 		}
61fcf4
 	} else {
61fcf4
 		printf("No log data can be shown with this log len at least " \
61fcf4
diff --git a/nvme.c b/nvme.c
61fcf4
index 0535ed2b..44c53e6b 100644
61fcf4
--- a/nvme.c
61fcf4
+++ b/nvme.c
61fcf4
@@ -4808,7 +4808,7 @@ static int dsm(int argc, char **argv, struct command *cmd, struct plugin *plugin
61fcf4
 
61fcf4
 	nc = argconfig_parse_comma_sep_array(cfg.ctx_attrs, ctx_attrs, ARRAY_SIZE(ctx_attrs));
61fcf4
 	nb = argconfig_parse_comma_sep_array(cfg.blocks, nlbs, ARRAY_SIZE(nlbs));
61fcf4
-	ns = argconfig_parse_comma_sep_array_long(cfg.slbas, slbas, ARRAY_SIZE(slbas));
61fcf4
+	ns = argconfig_parse_comma_sep_array_long(cfg.slbas, (long long unsigned int *)slbas, ARRAY_SIZE(slbas));
61fcf4
 	nr = max(nc, max(nb, ns));
61fcf4
 	if (!nr || nr > 256) {
61fcf4
 		fprintf(stderr, "No range definition provided\n");
61fcf4
@@ -4963,7 +4963,7 @@ static int copy(int argc, char **argv, struct command *cmd, struct plugin *plugi
61fcf4
 		}
61fcf4
 	}
61fcf4
 
61fcf4
-	copy = nvme_setup_copy_range(nlbs, slbas, eilbrts, elbatms, elbats, nr);
61fcf4
+	copy = nvme_setup_copy_range(nlbs, (__u64 *)slbas, eilbrts, elbatms, elbats, nr);
61fcf4
 	if (!copy) {
61fcf4
 		fprintf(stderr, "failed to allocate payload\n");
61fcf4
 		errno = ENOMEM;
61fcf4
-- 
61fcf4
2.31.1
61fcf4