Blame SOURCES/0012-nvme-cli-Adds-readable-firmware-level-in-persistent.patch

35de48
From 7e858ab53eb23083205d75f590ca2c2b256c2a7b Mon Sep 17 00:00:00 2001
35de48
From: Maurizio Lombardi <mlombard@redhat.com>
35de48
Date: Thu, 30 Jun 2022 16:37:40 +0200
35de48
Subject: [PATCH 5/7] nvme-cli: Adds readable firmware level in persistent
35de48
35de48
For example, In Firmware Commit Event:
35de48
35de48
Old Firmware Revision: 3617604718875264338
35de48
New Firmware Revision: 3833777500989048146
35de48
35de48
changes to
35de48
Old Firmware Revision: 3617604718875264338 (REV.SP42)
35de48
New Firmware Revision: 3833777500989048146 (REV.SP45)
35de48
35de48
Signed-off-by: Maurizio Lombardi <mlombard@redhat.com>
35de48
---
35de48
 nvme-print.c | 43 ++++++++++++++++++++++++++++---------------
35de48
 1 file changed, 28 insertions(+), 15 deletions(-)
35de48
35de48
diff --git a/nvme-print.c b/nvme-print.c
35de48
index 3b82b174..74ecd95a 100755
35de48
--- a/nvme-print.c
35de48
+++ b/nvme-print.c
35de48
@@ -104,12 +104,15 @@ const char *nvme_cmd_to_string(int admin, __u8 opcode)
35de48
 	return "Unknown";
35de48
 }
35de48
 
35de48
-static char *fw_to_string(__u8 fw[])
35de48
+static const char *fw_to_string(char *c)
35de48
 {
35de48
-	static char frs[9];
35de48
+	static char ret[9];
35de48
+	int i;
35de48
 
35de48
-	snprintf(frs, sizeof(frs), "%-.*s", 8, fw);
35de48
-	return frs;
35de48
+	for (i = 0; i < 8; i++)
35de48
+		ret[i] = c[i] >= '!' && c[i] <= '~' ? c[i] : '.';
35de48
+	ret[i] = '\0';
35de48
+	return ret;
35de48
 }
35de48
 
35de48
 static const char *get_sanitize_log_sstat_status_str(__u16 status)
35de48
@@ -1094,6 +1097,7 @@ void json_persistent_event_log(void *pevent_log_info, __u32 size)
35de48
 	__u32 offset, por_info_len, por_info_list;
35de48
 	__u64 *fw_rev;
35de48
 	char key[128];
35de48
+	char fw_str[50];
35de48
 	struct nvme_smart_log *smart_event;
35de48
 	struct nvme_fw_commit_event *fw_commit_event;
35de48
 	struct nvme_time_stamp_change_event *ts_change_event;
35de48
@@ -1266,10 +1270,14 @@ void json_persistent_event_log(void *pevent_log_info, __u32 size)
35de48
 			break;
35de48
 		case NVME_FW_COMMIT_EVENT:
35de48
 			fw_commit_event = pevent_log_info + offset;
35de48
-			json_object_add_value_uint(valid_attrs, "old_fw_rev",
35de48
-				le64_to_cpu(fw_commit_event->old_fw_rev));
35de48
-			json_object_add_value_uint(valid_attrs, "new_fw_rev",
35de48
-				le64_to_cpu(fw_commit_event->new_fw_rev));
35de48
+			snprintf(fw_str, sizeof(fw_str), "%"PRIu64" (%s)",
35de48
+					le64_to_cpu(fw_commit_event->old_fw_rev),
35de48
+					fw_to_string((char *)&fw_commit_event->old_fw_rev));
35de48
+			json_object_add_value_string(valid_attrs, "old_fw_rev", fw_str);
35de48
+			snprintf(fw_str, sizeof(fw_str), "%"PRIu64" (%s)",
35de48
+					le64_to_cpu(fw_commit_event->new_fw_rev),
35de48
+					fw_to_string((char *)&fw_commit_event->new_fw_rev));
35de48
+			json_object_add_value_string(valid_attrs, "new_fw_rev", fw_str);
35de48
 			json_object_add_value_uint(valid_attrs, "fw_commit_action",
35de48
 				fw_commit_event->fw_commit_action);
35de48
 			json_object_add_value_uint(valid_attrs, "fw_slot",
35de48
@@ -1297,8 +1305,10 @@ void json_persistent_event_log(void *pevent_log_info, __u32 size)
35de48
 			por_info_list = por_info_len / sizeof(*por_event);
35de48
 
35de48
 			fw_rev = pevent_log_info + offset;
35de48
-			json_object_add_value_uint(valid_attrs, "fw_rev",
35de48
-				le64_to_cpu(*fw_rev));
35de48
+			snprintf(fw_str, sizeof(fw_str), "%"PRIu64" (%s)",
35de48
+					le64_to_cpu(*fw_rev),
35de48
+					fw_to_string((char *)fw_rev));
35de48
+			json_object_add_value_string(valid_attrs, "fw_rev", fw_str);
35de48
 			for (int i = 0; i < por_info_list; i++) {
35de48
 				por_event = pevent_log_info + offset +
35de48
 					sizeof(*fw_rev) + i * sizeof(*por_event);
35de48
@@ -1529,10 +1539,12 @@ void nvme_show_persistent_event_log(void *pevent_log_info,
35de48
 		case NVME_FW_COMMIT_EVENT:
35de48
 			fw_commit_event = pevent_log_info + offset;
35de48
 			printf("FW Commit Event Entry: \n");
35de48
-			printf("Old Firmware Revision: %"PRIu64"\n",
35de48
-				le64_to_cpu(fw_commit_event->old_fw_rev));
35de48
-			printf("New Firmware Revision: %"PRIu64"\n",
35de48
-				le64_to_cpu(fw_commit_event->new_fw_rev));
35de48
+			printf("Old Firmware Revision: %"PRIu64" (%s)\n",
35de48
+					le64_to_cpu(fw_commit_event->old_fw_rev),
35de48
+					fw_to_string((char *)&fw_commit_event->old_fw_rev));
35de48
+			printf("New Firmware Revision: %"PRIu64" (%s)\n",
35de48
+					le64_to_cpu(fw_commit_event->new_fw_rev),
35de48
+					fw_to_string((char *)&fw_commit_event->new_fw_rev));
35de48
 			printf("FW Commit Action: %u\n",
35de48
 				fw_commit_event->fw_commit_action);
35de48
 			printf("FW Slot: %u\n", fw_commit_event->fw_slot);
35de48
@@ -1559,7 +1571,8 @@ void nvme_show_persistent_event_log(void *pevent_log_info,
35de48
 
35de48
 			printf("Power On Reset Event Entry: \n");
35de48
 			fw_rev = pevent_log_info + offset;
35de48
-			printf("Firmware Revision: %"PRIu64"\n", le64_to_cpu(*fw_rev));
35de48
+			printf("Firmware Revision: %"PRIu64" (%s)\n", le64_to_cpu(*fw_rev),
35de48
+					fw_to_string((char *)fw_rev));
35de48
 			printf("Reset Information List: \n");
35de48
 
35de48
 			for (int i = 0; i < por_info_list; i++) {
35de48
-- 
35de48
2.31.1
35de48