Move into ocp-print-stdout.c and ocp-print-json.c.
Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
#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,
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;
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");
}
__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 */
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)
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,
.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)
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,
.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)
{
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);
+}
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;
};
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 */