]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
ocp: split error recovery log print codes
authorTokunori Ikegami <ikegami.t@gmail.com>
Sun, 20 Oct 2024 16:35:02 +0000 (01:35 +0900)
committerDaniel Wagner <wagi@monom.org>
Wed, 23 Oct 2024 12:24:49 +0000 (14:24 +0200)
Move into ocp-print-stdout.c and ocp-print-json.c.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
plugins/ocp/ocp-nvme.c
plugins/ocp/ocp-nvme.h
plugins/ocp/ocp-print-binary.c
plugins/ocp/ocp-print-json.c
plugins/ocp/ocp-print-stdout.c
plugins/ocp/ocp-print.c
plugins/ocp/ocp-print.h

index a2acb2ed23914e0cd6d62dd53822661c8ab4119e..666d1a8403f2f3da2b5979c3d5b6f3822a8f3603 100644 (file)
@@ -1706,8 +1706,6 @@ static int ocp_unsupported_requirements_log(int argc, char **argv, struct comman
 
 #define C1_ERROR_RECOVERY_LOG_BUF_LEN       0x200
 #define C1_ERROR_RECOVERY_OPCODE            0xC1
-#define C1_GUID_LENGTH                      16
-#define C1_PREV_PANIC_IDS_LENGTH            4
 
 static __u8 error_recovery_guid[C1_GUID_LENGTH] = {
        0x44, 0xd9, 0x31, 0x21,
@@ -1716,115 +1714,9 @@ static __u8 error_recovery_guid[C1_GUID_LENGTH] = {
        0xba, 0x83, 0x19, 0x5a
 };
 
-/**
- * struct ocp_error_recovery_log_page -        Error Recovery Log Page
- * @panic_reset_wait_time:             Panic Reset Wait Time
- * @panic_reset_action:                        Panic Reset Action
- * @device_recover_action_1:           Device Recovery Action 1
- * @panic_id:                          Panic ID
- * @device_capabilities:               Device Capabilities
- * @vendor_specific_recovery_opcode:   Vendor Specific Recovery Opcode
- * @reserved:                          Reserved
- * @vendor_specific_command_cdw12:     Vendor Specific Command CDW12
- * @vendor_specific_command_cdw13:     Vendor Specific Command CDW13
- * @vendor_specific_command_timeout:   Vendor Specific Command Timeout
- * @device_recover_action_2:           Device Recovery Action 2
- * @device_recover_action_2_timeout:   Device Recovery Action 2 Timeout
- * @panic_count:                       Panic Count
- * @prev_panic_id:                     Previous Panic IDs
- * @reserved2:                         Reserved
- * @log_page_version:                  Log Page Version
- * @log_page_guid:                     Log Page GUID
- */
-struct __packed ocp_error_recovery_log_page {
-       __le16  panic_reset_wait_time;                   /* 2 bytes      - 0x00 - 0x01 */
-       __u8    panic_reset_action;                      /* 1 byte       - 0x02 */
-       __u8    device_recover_action_1;                 /* 1 byte       - 0x03 */
-       __le64  panic_id;                                /* 8 bytes      - 0x04 - 0x0B */
-       __le32  device_capabilities;                     /* 4 bytes      - 0x0C - 0x0F */
-       __u8    vendor_specific_recovery_opcode;         /* 1 byte       - 0x10 */
-       __u8    reserved[0x3];                           /* 3 bytes      - 0x11 - 0x13 */
-       __le32  vendor_specific_command_cdw12;           /* 4 bytes      - 0x14 - 0x17 */
-       __le32  vendor_specific_command_cdw13;           /* 4 bytes      - 0x18 - 0x1B */
-       __u8    vendor_specific_command_timeout;         /* 1 byte       - 0x1C */
-       __u8    device_recover_action_2;                 /* 1 byte       - 0x1D */
-       __u8    device_recover_action_2_timeout;         /* 1 byte       - 0x1E */
-       __u8    panic_count;                             /* 1 byte       - 0x1F */
-       __le64  prev_panic_id[C1_PREV_PANIC_IDS_LENGTH]; /* 32 bytes     - 0x20 - 0x3F */
-       __u8    reserved2[0x1ae];                        /* 430 bytes    - 0x40 - 0x1ED */
-       __le16  log_page_version;                        /* 2 bytes      - 0x1EE - 0x1EF */
-       __u8    log_page_guid[0x10];                     /* 16 bytes     - 0x1F0 - 0x1FF */
-};
-
-static void ocp_print_c1_log_normal(struct ocp_error_recovery_log_page *log_data);
-static void ocp_print_c1_log_json(struct ocp_error_recovery_log_page *log_data);
-static void ocp_print_c1_log_binary(struct ocp_error_recovery_log_page *log_data);
 static int get_c1_log_page(struct nvme_dev *dev, char *format);
 static int ocp_error_recovery_log(int argc, char **argv, struct command *cmd, struct plugin *plugin);
 
-static void ocp_print_c1_log_normal(struct ocp_error_recovery_log_page *log_data)
-{
-       int i;
-
-       printf("  Error Recovery/C1 Log Page Data\n");
-       printf("  Panic Reset Wait Time             : 0x%x\n", le16_to_cpu(log_data->panic_reset_wait_time));
-       printf("  Panic Reset Action                : 0x%x\n", log_data->panic_reset_action);
-       printf("  Device Recovery Action 1          : 0x%x\n", log_data->device_recover_action_1);
-       printf("  Panic ID                          : 0x%x\n", le32_to_cpu(log_data->panic_id));
-       printf("  Device Capabilities               : 0x%x\n", le32_to_cpu(log_data->device_capabilities));
-       printf("  Vendor Specific Recovery Opcode   : 0x%x\n", log_data->vendor_specific_recovery_opcode);
-       printf("  Vendor Specific Command CDW12     : 0x%x\n", le32_to_cpu(log_data->vendor_specific_command_cdw12));
-       printf("  Vendor Specific Command CDW13     : 0x%x\n", le32_to_cpu(log_data->vendor_specific_command_cdw13));
-       printf("  Vendor Specific Command Timeout   : 0x%x\n", log_data->vendor_specific_command_timeout);
-       printf("  Device Recovery Action 2          : 0x%x\n", log_data->device_recover_action_2);
-       printf("  Device Recovery Action 2 Timeout  : 0x%x\n", log_data->device_recover_action_2_timeout);
-       printf("  Panic Count                       : 0x%x\n", log_data->panic_count);
-       printf("  Previous Panic IDs:");
-       for (i = 0; i < C1_PREV_PANIC_IDS_LENGTH; i++)
-               printf("%s Panic ID N-%d : 0x%lx\n", i ? "                     " : "", i + 1,
-                      le64_to_cpu(log_data->prev_panic_id[i]));
-       printf("  Log Page Version                  : 0x%x\n", le16_to_cpu(log_data->log_page_version));
-       printf("  Log page GUID                     : 0x");
-       for (i = C1_GUID_LENGTH - 1; i >= 0; i--)
-               printf("%02x", log_data->log_page_guid[i]);
-       printf("\n");
-}
-
-static void ocp_print_c1_log_json(struct ocp_error_recovery_log_page *log_data)
-{
-       struct json_object *root;
-
-       root = json_create_object();
-       char guid[64];
-
-       json_object_add_value_int(root, "Panic Reset Wait Time", le16_to_cpu(log_data->panic_reset_wait_time));
-       json_object_add_value_int(root, "Panic Reset Action", log_data->panic_reset_action);
-       json_object_add_value_int(root, "Device Recovery Action 1", log_data->device_recover_action_1);
-       json_object_add_value_int(root, "Panic ID", le32_to_cpu(log_data->panic_id));
-       json_object_add_value_int(root, "Device Capabilities", le32_to_cpu(log_data->device_capabilities));
-       json_object_add_value_int(root, "Vendor Specific Recovery Opcode", log_data->vendor_specific_recovery_opcode);
-       json_object_add_value_int(root, "Vendor Specific Command CDW12", le32_to_cpu(log_data->vendor_specific_command_cdw12));
-       json_object_add_value_int(root, "Vendor Specific Command CDW13", le32_to_cpu(log_data->vendor_specific_command_cdw13));
-       json_object_add_value_int(root, "Vendor Specific Command Timeout", log_data->vendor_specific_command_timeout);
-       json_object_add_value_int(root, "Device Recovery Action 2", log_data->device_recover_action_2);
-       json_object_add_value_int(root, "Device Recovery Action 2 Timeout", log_data->device_recover_action_2_timeout);
-       json_object_add_value_int(root, "Log Page Version", le16_to_cpu(log_data->log_page_version));
-
-       memset((void *)guid, 0, 64);
-       sprintf((char *)guid, "0x%"PRIx64"%"PRIx64"", (uint64_t)le64_to_cpu(*(uint64_t *)&log_data->log_page_guid[8]),
-               (uint64_t)le64_to_cpu(*(uint64_t *)&log_data->log_page_guid[0]));
-       json_object_add_value_string(root, "Log page GUID", guid);
-
-       json_print_object(root, NULL);
-       printf("\n");
-       json_free_object(root);
-}
-
-static void ocp_print_c1_log_binary(struct ocp_error_recovery_log_page *log_data)
-{
-       return d_raw((unsigned char *)log_data, sizeof(*log_data));
-}
-
 static int get_c1_log_page(struct nvme_dev *dev, char *format)
 {
        struct ocp_error_recovery_log_page *log_data;
@@ -1870,20 +1762,7 @@ static int get_c1_log_page(struct nvme_dev *dev, char *format)
                                goto out;
                        }
                }
-
-               switch (fmt) {
-               case NORMAL:
-                       ocp_print_c1_log_normal(log_data);
-                       break;
-               case JSON:
-                       ocp_print_c1_log_json(log_data);
-                       break;
-               case BINARY:
-                       ocp_print_c1_log_binary(log_data);
-                       break;
-               default:
-                       break;
-               }
+               ocp_c1_log(log_data, fmt);
        } else {
                fprintf(stderr, "ERROR : OCP : Unable to read C1 data from buffer\n");
        }
index 6f7c149a00d88cbd8c007c6b8f87b5dd50f40e85..b9705c03f389b0789f5de158419d62fcae28262e 100644 (file)
@@ -119,4 +119,47 @@ struct __packed unsupported_requirement_log {
        __le16  log_page_version;
        __u8    log_page_guid[C5_GUID_LENGTH];
 };
+
+#define C1_GUID_LENGTH                      16
+#define C1_PREV_PANIC_IDS_LENGTH            4
+
+/**
+ * struct ocp_error_recovery_log_page -        Error Recovery Log Page
+ * @panic_reset_wait_time:             Panic Reset Wait Time
+ * @panic_reset_action:                        Panic Reset Action
+ * @device_recover_action_1:           Device Recovery Action 1
+ * @panic_id:                          Panic ID
+ * @device_capabilities:               Device Capabilities
+ * @vendor_specific_recovery_opcode:   Vendor Specific Recovery Opcode
+ * @reserved:                          Reserved
+ * @vendor_specific_command_cdw12:     Vendor Specific Command CDW12
+ * @vendor_specific_command_cdw13:     Vendor Specific Command CDW13
+ * @vendor_specific_command_timeout:   Vendor Specific Command Timeout
+ * @device_recover_action_2:           Device Recovery Action 2
+ * @device_recover_action_2_timeout:   Device Recovery Action 2 Timeout
+ * @panic_count:                       Panic Count
+ * @prev_panic_id:                     Previous Panic IDs
+ * @reserved2:                         Reserved
+ * @log_page_version:                  Log Page Version
+ * @log_page_guid:                     Log Page GUID
+ */
+struct __packed ocp_error_recovery_log_page {
+       __le16  panic_reset_wait_time;                   /* 2 bytes      - 0x00 - 0x01 */
+       __u8    panic_reset_action;                      /* 1 byte       - 0x02 */
+       __u8    device_recover_action_1;                 /* 1 byte       - 0x03 */
+       __le64  panic_id;                                /* 8 bytes      - 0x04 - 0x0B */
+       __le32  device_capabilities;                     /* 4 bytes      - 0x0C - 0x0F */
+       __u8    vendor_specific_recovery_opcode;         /* 1 byte       - 0x10 */
+       __u8    reserved[0x3];                           /* 3 bytes      - 0x11 - 0x13 */
+       __le32  vendor_specific_command_cdw12;           /* 4 bytes      - 0x14 - 0x17 */
+       __le32  vendor_specific_command_cdw13;           /* 4 bytes      - 0x18 - 0x1B */
+       __u8    vendor_specific_command_timeout;         /* 1 byte       - 0x1C */
+       __u8    device_recover_action_2;                 /* 1 byte       - 0x1D */
+       __u8    device_recover_action_2_timeout;         /* 1 byte       - 0x1E */
+       __u8    panic_count;                             /* 1 byte       - 0x1F */
+       __le64  prev_panic_id[C1_PREV_PANIC_IDS_LENGTH]; /* 32 bytes     - 0x20 - 0x3F */
+       __u8    reserved2[0x1ae];                        /* 430 bytes    - 0x40 - 0x1ED */
+       __le16  log_page_version;                        /* 2 bytes      - 0x1EE - 0x1EF */
+       __u8    log_page_guid[0x10];                     /* 16 bytes     - 0x1F0 - 0x1FF */
+};
 #endif /* OCP_NVME_H */
index b3167fc620c76a18d2ea45fdfcb9ea441206f96e..2dd1cbfb5dae2d4a08a5cc091a24b3ca0839367f 100644 (file)
@@ -17,9 +17,15 @@ static void binary_c5_log(struct nvme_dev *dev, struct unsupported_requirement_l
        d_raw((unsigned char *)log_data, sizeof(*log_data));
 }
 
+static void binary_c1_log(struct ocp_error_recovery_log_page *log_data)
+{
+       d_raw((unsigned char *)log_data, sizeof(*log_data));
+}
+
 static struct ocp_print_ops binary_print_ops = {
        .hwcomp_log = binary_hwcomp_log,
        .c5_log = binary_c5_log,
+       .c1_log = binary_c1_log,
 };
 
 struct ocp_print_ops *ocp_get_binary_print_ops(nvme_print_flags_t flags)
index 3b00a150f6665b2ff35938e024d0db4faeea9433..019e098717ff3b0bd3bd3de535f9d5285f4b6f4e 100644 (file)
@@ -441,6 +441,47 @@ static void json_c5_log(struct nvme_dev *dev, struct unsupported_requirement_log
        json_free_object(root);
 }
 
+static void json_c1_log(struct ocp_error_recovery_log_page *log_data)
+{
+       struct json_object *root;
+
+       root = json_create_object();
+       char guid[64];
+
+       json_object_add_value_int(root, "Panic Reset Wait Time",
+                                 le16_to_cpu(log_data->panic_reset_wait_time));
+       json_object_add_value_int(root, "Panic Reset Action", log_data->panic_reset_action);
+       json_object_add_value_int(root, "Device Recovery Action 1",
+                                 log_data->device_recover_action_1);
+       json_object_add_value_int(root, "Panic ID", le32_to_cpu(log_data->panic_id));
+       json_object_add_value_int(root, "Device Capabilities",
+                                 le32_to_cpu(log_data->device_capabilities));
+       json_object_add_value_int(root, "Vendor Specific Recovery Opcode",
+                                 log_data->vendor_specific_recovery_opcode);
+       json_object_add_value_int(root, "Vendor Specific Command CDW12",
+                                 le32_to_cpu(log_data->vendor_specific_command_cdw12));
+       json_object_add_value_int(root, "Vendor Specific Command CDW13",
+                                 le32_to_cpu(log_data->vendor_specific_command_cdw13));
+       json_object_add_value_int(root, "Vendor Specific Command Timeout",
+                                 log_data->vendor_specific_command_timeout);
+       json_object_add_value_int(root, "Device Recovery Action 2",
+                                 log_data->device_recover_action_2);
+       json_object_add_value_int(root, "Device Recovery Action 2 Timeout",
+                                 log_data->device_recover_action_2_timeout);
+       json_object_add_value_int(root, "Log Page Version",
+                                 le16_to_cpu(log_data->log_page_version));
+
+       memset((void *)guid, 0, 64);
+       sprintf((char *)guid, "0x%"PRIx64"%"PRIx64"",
+               (uint64_t)le64_to_cpu(*(uint64_t *)&log_data->log_page_guid[8]),
+               (uint64_t)le64_to_cpu(*(uint64_t *)&log_data->log_page_guid[0]));
+       json_object_add_value_string(root, "Log page GUID", guid);
+
+       json_print_object(root, NULL);
+       printf("\n");
+       json_free_object(root);
+}
+
 static struct ocp_print_ops json_print_ops = {
        .hwcomp_log = json_hwcomp_log,
        .fw_act_history = json_fw_activation_history,
@@ -448,6 +489,7 @@ static struct ocp_print_ops json_print_ops = {
        .telemetry_log = json_telemetry_log,
        .c3_log = json_c3_log,
        .c5_log = json_c5_log,
+       .c1_log = json_c1_log,
 };
 
 struct ocp_print_ops *ocp_get_json_print_ops(nvme_print_flags_t flags)
index 9cc7f5a2c99f548409307daed2d8ce9daf1c30cf..478dd02e15f92f6a7ef092a7d644314d91752199 100644 (file)
@@ -353,6 +353,43 @@ static int stdout_c5_log(struct nvme_dev *dev, struct unsupported_requirement_lo
        return 0;
 }
 
+static void stdout_c1_log(struct ocp_error_recovery_log_page *log_data)
+{
+       int i;
+
+       printf("  Error Recovery/C1 Log Page Data\n");
+       printf("  Panic Reset Wait Time             : 0x%x\n",
+              le16_to_cpu(log_data->panic_reset_wait_time));
+       printf("  Panic Reset Action                : 0x%x\n", log_data->panic_reset_action);
+       printf("  Device Recovery Action 1          : 0x%x\n", log_data->device_recover_action_1);
+       printf("  Panic ID                          : 0x%x\n", le32_to_cpu(log_data->panic_id));
+       printf("  Device Capabilities               : 0x%x\n",
+              le32_to_cpu(log_data->device_capabilities));
+       printf("  Vendor Specific Recovery Opcode   : 0x%x\n",
+              log_data->vendor_specific_recovery_opcode);
+       printf("  Vendor Specific Command CDW12     : 0x%x\n",
+              le32_to_cpu(log_data->vendor_specific_command_cdw12));
+       printf("  Vendor Specific Command CDW13     : 0x%x\n",
+              le32_to_cpu(log_data->vendor_specific_command_cdw13));
+       printf("  Vendor Specific Command Timeout   : 0x%x\n",
+              log_data->vendor_specific_command_timeout);
+       printf("  Device Recovery Action 2          : 0x%x\n",
+              log_data->device_recover_action_2);
+       printf("  Device Recovery Action 2 Timeout  : 0x%x\n",
+              log_data->device_recover_action_2_timeout);
+       printf("  Panic Count                       : 0x%x\n", log_data->panic_count);
+       printf("  Previous Panic IDs:");
+       for (i = 0; i < C1_PREV_PANIC_IDS_LENGTH; i++)
+               printf("%s Panic ID N-%d : 0x%"PRIx64"\n", i ? "                     " : "", i + 1,
+                      le64_to_cpu(log_data->prev_panic_id[i]));
+       printf("  Log Page Version                  : 0x%x\n",
+              le16_to_cpu(log_data->log_page_version));
+       printf("  Log page GUID                     : 0x");
+       for (i = C1_GUID_LENGTH - 1; i >= 0; i--)
+               printf("%02x", log_data->log_page_guid[i]);
+       printf("\n");
+}
+
 static struct ocp_print_ops stdout_print_ops = {
        .hwcomp_log = stdout_hwcomp_log,
        .fw_act_history = stdout_fw_activation_history,
@@ -360,6 +397,7 @@ static struct ocp_print_ops stdout_print_ops = {
        .telemetry_log = stdout_telemetry_log,
        .c3_log = (void *)stdout_c3_log,
        .c5_log = (void *)stdout_c5_log,
+       .c1_log = stdout_c1_log,
 };
 
 struct ocp_print_ops *ocp_get_stdout_print_ops(nvme_print_flags_t flags)
index 68bb6d2822f27c22d131188c19316a02267d8b2e..e9b57f8af9d5927d32f38f2c957bbe31c1a053e4 100644 (file)
@@ -57,3 +57,8 @@ void ocp_c5_log(struct nvme_dev *dev, struct unsupported_requirement_log *log_da
 {
        ocp_print(c5_log, flags, dev, log_data);
 }
+
+void ocp_c1_log(struct ocp_error_recovery_log_page *log_data, nvme_print_flags_t flags)
+{
+       ocp_print(c1_log, flags, log_data);
+}
index 46f4d04c596f8371aeb513a355fd6847e0cd6876..d80c417ba409be331f0e73e1df5e91a5edee6d53 100644 (file)
@@ -14,6 +14,7 @@ struct ocp_print_ops {
        void (*telemetry_log)(struct ocp_telemetry_parse_options *options);
        void (*c3_log)(struct nvme_dev *dev, struct ssd_latency_monitor_log *log_data);
        void (*c5_log)(struct nvme_dev *dev, struct unsupported_requirement_log *log_data);
+       void (*c1_log)(struct ocp_error_recovery_log_page *log_data);
        nvme_print_flags_t flags;
 };
 
@@ -37,4 +38,5 @@ void ocp_c3_log(struct nvme_dev *dev, struct ssd_latency_monitor_log *log_data,
                nvme_print_flags_t flags);
 void ocp_c5_log(struct nvme_dev *dev, struct unsupported_requirement_log *log_data,
                nvme_print_flags_t flags);
+void ocp_c1_log(struct ocp_error_recovery_log_page *log_data, nvme_print_flags_t flags);
 #endif /* OCP_PRINT_H */