summaryrefslogtreecommitdiffstats
path: root/plugins/ocp
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-05 08:38:36 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-08-05 08:38:36 +0000
commit3c0f1ed2ea093dd0d3e8ba70f3c9963e66321f87 (patch)
tree2020852fabf5e530c687d41e36ddc5c453b0c9ed /plugins/ocp
parentAdding upstream version 2.9.1. (diff)
downloadnvme-cli-3c0f1ed2ea093dd0d3e8ba70f3c9963e66321f87.tar.xz
nvme-cli-3c0f1ed2ea093dd0d3e8ba70f3c9963e66321f87.zip
Adding upstream version 2.10.upstream/2.10
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'plugins/ocp')
-rw-r--r--plugins/ocp/meson.build1
-rw-r--r--plugins/ocp/ocp-fw-activation-history.c2
-rw-r--r--plugins/ocp/ocp-nvme.c2144
-rw-r--r--plugins/ocp/ocp-nvme.h9
-rw-r--r--plugins/ocp/ocp-smart-extended-log.c2
-rw-r--r--plugins/ocp/ocp-telemetry-decode.c1566
-rw-r--r--plugins/ocp/ocp-telemetry-decode.h1228
7 files changed, 4354 insertions, 598 deletions
diff --git a/plugins/ocp/meson.build b/plugins/ocp/meson.build
index 64447ff..7835444 100644
--- a/plugins/ocp/meson.build
+++ b/plugins/ocp/meson.build
@@ -4,5 +4,6 @@ sources += [
'plugins/ocp/ocp-clear-features.c',
'plugins/ocp/ocp-smart-extended-log.c',
'plugins/ocp/ocp-fw-activation-history.c',
+ 'plugins/ocp/ocp-telemetry-decode.c',
]
diff --git a/plugins/ocp/ocp-fw-activation-history.c b/plugins/ocp/ocp-fw-activation-history.c
index 16598a0..543042f 100644
--- a/plugins/ocp/ocp-fw-activation-history.c
+++ b/plugins/ocp/ocp-fw-activation-history.c
@@ -207,7 +207,7 @@ int ocp_fw_activation_history_log(int argc, char **argv, struct command *cmd,
}
if (!err) {
- enum nvme_print_flags print_flag;
+ nvme_print_flags_t print_flag;
err = validate_output_format(format, &print_flag);
if (err < 0) {
diff --git a/plugins/ocp/ocp-nvme.c b/plugins/ocp/ocp-nvme.c
index 6eaa773..91f4083 100644
--- a/plugins/ocp/ocp-nvme.c
+++ b/plugins/ocp/ocp-nvme.c
@@ -23,10 +23,12 @@
#include "linux/types.h"
#include "util/types.h"
#include "nvme-print.h"
+#include "nvme-wrap.h"
#include "ocp-smart-extended-log.h"
#include "ocp-clear-features.h"
#include "ocp-fw-activation-history.h"
+#include "ocp-telemetry-decode.h"
#define CREATE_CMD
#include "ocp-nvme.h"
@@ -112,6 +114,93 @@ struct __packed feature_latency_monitor {
__u8 reserved[4083];
};
+struct erri_entry {
+ union {
+ __u8 flags;
+ struct {
+ __u8 enable:1;
+ __u8 single:1;
+ __u8 rsvd2:6;
+ };
+ };
+ __u8 rsvd1;
+ __le16 type;
+ union {
+ __u8 specific[28];
+ struct {
+ __le16 nrtdp;
+ __u8 rsvd4[26];
+ };
+ };
+};
+
+#define ERRI_ENTRIES_MAX 127
+
+enum erri_type {
+ ERRI_TYPE_CPU_CTRL_HANG = 1,
+ ERRI_TYPE_NAND_HANG,
+ ERRI_TYPE_PLP_DEFECT,
+ ERRI_TYPE_LOGICAL_FIRMWARE_ERROR,
+ ERRI_TYPE_DRAM_CORRUPT_CRIT,
+ ERRI_TYPE_DRAM_CORRUPT_NON_CRIT,
+ ERRI_TYPE_NAND_CORRUPT,
+ ERRI_TYPE_SRAM_CORRUPT,
+ ERRI_TYPE_HW_MALFUNCTION,
+ ERRI_TYPE_NO_MORE_NAND_SPARES,
+ ERRI_TYPE_INCOMPLETE_SHUTDOWN,
+};
+
+const char *erri_type_to_string(__le16 type)
+{
+ switch (type) {
+ case ERRI_TYPE_CPU_CTRL_HANG:
+ return "CPU/controller hang";
+ case ERRI_TYPE_NAND_HANG:
+ return "NAND hang";
+ case ERRI_TYPE_PLP_DEFECT:
+ return "PLP defect";
+ case ERRI_TYPE_LOGICAL_FIRMWARE_ERROR:
+ return "logical firmware error";
+ case ERRI_TYPE_DRAM_CORRUPT_CRIT:
+ return "DRAM corruption critical path";
+ case ERRI_TYPE_DRAM_CORRUPT_NON_CRIT:
+ return "DRAM corruption non-critical path";
+ case ERRI_TYPE_NAND_CORRUPT:
+ return "NAND corruption";
+ case ERRI_TYPE_SRAM_CORRUPT:
+ return "SRAM corruption";
+ case ERRI_TYPE_HW_MALFUNCTION:
+ return "HW malfunction";
+ case ERRI_TYPE_NO_MORE_NAND_SPARES:
+ return "no more NAND spares available";
+ case ERRI_TYPE_INCOMPLETE_SHUTDOWN:
+ return "incomplete shutdown";
+ default:
+ break;
+ }
+
+ return "unknown";
+}
+
+struct erri_get_cq_entry {
+ __u32 nume:7;
+ __u32 rsvd7:25;
+};
+
+struct erri_config {
+ char *file;
+ __u8 number;
+ __u16 type;
+ __u16 nrtdp;
+};
+
+static const char *sel = "[0-3]: current/default/saved/supported";
+static const char *no_uuid = "Skip UUID index search (UUID index not required for OCP 1.0)";
+const char *data = "Error injection data structure entries";
+const char *number = "Number of valid error injection data entries";
+static const char *type = "Error injection type";
+static const char *nrtdp = "Number of reads to trigger device panic";
+
static int ocp_print_C3_log_normal(struct nvme_dev *dev,
struct ssd_latency_monitor_log *log_data)
{
@@ -140,7 +229,7 @@ static int ocp_print_C3_log_normal(struct nvme_dev *dev,
printf(" Active Threshold D %d ms\n",
C3_ACTIVE_THRESHOLD_INCREMENT *
le16_to_cpu(log_data->active_threshold_d+1));
- printf(" Active Latency Configuration 0x%x \n",
+ printf(" Active Latency Configuration 0x%x\n",
le16_to_cpu(log_data->active_latency_config));
printf(" Active Latency Minimum Window %d ms\n",
C3_MINIMUM_WINDOW_INCREMENT *
@@ -397,7 +486,7 @@ static void ocp_print_C3_log_json(struct ssd_latency_monitor_log *log_data)
static int get_c3_log_page(struct nvme_dev *dev, char *format)
{
struct ssd_latency_monitor_log *log_data;
- enum nvme_print_flags fmt;
+ nvme_print_flags_t fmt;
int ret;
__u8 *data;
int i;
@@ -664,8 +753,8 @@ static const char *eol_plp_failure_mode_to_string(__u8 mode)
return "Reserved";
}
-static int eol_plp_failure_mode_get(struct nvme_dev *dev, const __u32 nsid,
- const __u8 fid, __u8 sel)
+static int eol_plp_failure_mode_get(struct nvme_dev *dev, const __u32 nsid, const __u8 fid,
+ __u8 sel, bool uuid)
{
__u32 result;
int err;
@@ -684,6 +773,15 @@ static int eol_plp_failure_mode_get(struct nvme_dev *dev, const __u32 nsid,
.result = &result,
};
+ if (uuid) {
+ /* OCP 2.0 requires UUID index support */
+ err = ocp_get_uuid_index(dev, &args.uuidx);
+ if (err || !args.uuidx) {
+ nvme_show_error("ERROR: No OCP UUID index found");
+ return err;
+ }
+ }
+
err = nvme_get_features(&args);
if (!err) {
nvme_show_result("End of Life Behavior (feature: %#0*x): %#0*x (%s: %s)",
@@ -716,7 +814,6 @@ static int eol_plp_failure_mode_set(struct nvme_dev *dev, const __u32 nsid,
}
}
-
struct nvme_set_features_args args = {
.args_size = sizeof(args),
.fd = dev_fd(dev),
@@ -756,7 +853,7 @@ static int eol_plp_failure_mode(int argc, char **argv, struct command *cmd,
"No argument prints current mode.";
const char *mode = "[0-3]: default/rom/wtm/normal";
const char *save = "Specifies that the controller shall save the attribute";
- const char *sel = "[0-3,8]: current/default/saved/supported/changed";
+ const char *sel = "[0-3]: current/default/saved/supported";
const __u32 nsid = 0;
const __u8 fid = 0xc2;
struct nvme_dev *dev;
@@ -774,14 +871,12 @@ static int eol_plp_failure_mode(int argc, char **argv, struct command *cmd,
.sel = 0,
};
- OPT_ARGS(opts) = {
- OPT_BYTE("mode", 'm', &cfg.mode, mode),
- OPT_FLAG("save", 's', &cfg.save, save),
- OPT_BYTE("sel", 'S', &cfg.sel, sel),
- OPT_FLAG("no-uuid", 'n', NULL,
- "Skip UUID index search (UUID index not required for OCP 1.0)"),
- OPT_END()
- };
+ NVME_ARGS(opts,
+ OPT_BYTE("mode", 'm', &cfg.mode, mode),
+ OPT_FLAG("save", 's', &cfg.save, save),
+ OPT_BYTE("sel", 'S', &cfg.sel, sel),
+ OPT_FLAG("no-uuid", 'n', NULL,
+ "Skip UUID index search (UUID index not required for OCP 1.0)"));
err = parse_and_open(&dev, argc, argv, desc, opts);
if (err)
@@ -792,7 +887,8 @@ static int eol_plp_failure_mode(int argc, char **argv, struct command *cmd,
cfg.save,
!argconfig_parse_seen(opts, "no-uuid"));
else
- err = eol_plp_failure_mode_get(dev, nsid, fid, cfg.sel);
+ err = eol_plp_failure_mode_get(dev, nsid, fid, cfg.sel,
+ !argconfig_parse_seen(opts, "no-uuid"));
dev_close(dev);
@@ -804,58 +900,15 @@ static int eol_plp_failure_mode(int argc, char **argv, struct command *cmd,
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
/// Telemetry Log
+//global buffers
+static __le64 total_log_page_sz;
+static __u8 *header_data;
+static struct telemetry_str_log_format *log_data;
-#define TELEMETRY_HEADER_SIZE 512
-#define TELEMETRY_BYTE_PER_BLOCK 512
-#define TELEMETRY_TRANSFER_SIZE 1024
-#define FILE_NAME_SIZE 2048
-
-enum TELEMETRY_TYPE {
- TELEMETRY_TYPE_NONE = 0,
- TELEMETRY_TYPE_HOST = 7,
- TELEMETRY_TYPE_CONTROLLER = 8,
- TELEMETRY_TYPE_HOST_0 = 9,
- TELEMETRY_TYPE_HOST_1 = 10,
-};
+__u8 *ptelemetry_buffer;
+__u8 *pstring_buffer;
+__u8 *pC9_string_buffer;
-struct telemetry_initiated_log {
- __u8 LogIdentifier;
- __u8 Reserved1[4];
- __u8 IEEE[3];
- __le16 DataArea1LastBlock;
- __le16 DataArea2LastBlock;
- __le16 DataArea3LastBlock;
- __u8 Reserved2[368];
- __u8 DataAvailable;
- __u8 DataGenerationNumber;
- __u8 ReasonIdentifier[128];
-};
-
-struct telemetry_data_area_1 {
- __le16 major_version;
- __le16 minor_version;
- __u8 reserved1[4];
- __le64 timestamp;
- __u8 log_page_guid[16];
- __u8 no_of_tps_supp;
- __u8 tps;
- __u8 reserved2[6];
- __le16 sls;
- __u8 reserved3[8];
- __le16 fw_revision;
- __u8 reserved4[32];
- __le16 da1_stat_start;
- __le16 da1_stat_size;
- __le16 da2_stat_start;
- __le16 da2_stat_size;
- __u8 reserved5[32];
- __u8 event_fifo_da[16];
- __le64 event_fifo_start[16];
- __le64 event_fifo_size[16];
- __u8 reserved6[80];
- __u8 smart_health_info[512];
- __u8 smart_health_info_extended[512];
-};
static void get_serial_number(struct nvme_id_ctrl *ctrl, char *sn)
{
int i;
@@ -867,39 +920,20 @@ static void get_serial_number(struct nvme_id_ctrl *ctrl, char *sn)
}
}
-static int get_telemetry_header(struct nvme_dev *dev, __u32 ns, __u8 tele_type,
- __u32 data_len, void *data, __u8 nLSP, __u8 nRAE)
-{
- struct nvme_passthru_cmd cmd = {
- .opcode = nvme_admin_get_log_page,
- .nsid = ns,
- .addr = (__u64)(uintptr_t) data,
- .data_len = data_len,
- };
-
- __u32 numd = (data_len >> 2) - 1;
- __u16 numdu = numd >> 16;
- __u16 numdl = numd & 0xffff;
-
- cmd.cdw10 = tele_type | (nLSP & 0x0F) << 8 | (nRAE & 0x01) << 15 | (numdl & 0xFFFF) << 16;
- cmd.cdw11 = numdu;
- cmd.cdw12 = 0;
- cmd.cdw13 = 0;
- cmd.cdw14 = 0;
-
- return nvme_submit_admin_passthru(dev_fd(dev), &cmd, NULL);
-}
-
static void print_telemetry_header(struct telemetry_initiated_log *logheader,
int tele_type)
{
if (logheader) {
unsigned int i = 0, j = 0;
+ __u8 dataGenNum;
- if (tele_type == TELEMETRY_TYPE_HOST)
+ if (tele_type == TELEMETRY_TYPE_HOST) {
printf("============ Telemetry Host Header ============\n");
- else
+ dataGenNum = logheader->DataHostGenerationNumber;
+ } else {
printf("========= Telemetry Controller Header =========\n");
+ dataGenNum = logheader->DataCtlrGenerationNumber;
+ }
printf("Log Identifier : 0x%02X\n", logheader->LogIdentifier);
printf("IEEE : 0x%02X%02X%02X\n",
@@ -910,8 +944,10 @@ static void print_telemetry_header(struct telemetry_initiated_log *logheader,
le16_to_cpu(logheader->DataArea2LastBlock));
printf("Data Area 3 Last Block : 0x%04X\n",
le16_to_cpu(logheader->DataArea3LastBlock));
- printf("Data Available : 0x%02X\n", logheader->DataAvailable);
- printf("Data Generation Number : 0x%02X\n", logheader->DataGenerationNumber);
+ printf("Data Available : 0x%02X\n",
+ logheader->CtlrDataAvailable);
+ printf("Data Generation Number : 0x%02X\n",
+ dataGenNum);
printf("Reason Identifier :\n");
for (i = 0; i < 8; i++) {
@@ -922,6 +958,7 @@ static void print_telemetry_header(struct telemetry_initiated_log *logheader,
printf("===============================================\n\n");
}
}
+
static int get_telemetry_data(struct nvme_dev *dev, __u32 ns, __u8 tele_type,
__u32 data_len, void *data, __u8 nLSP, __u8 nRAE,
__u64 offset)
@@ -935,10 +972,14 @@ static int get_telemetry_data(struct nvme_dev *dev, __u32 ns, __u8 tele_type,
__u32 numd = (data_len >> 2) - 1;
__u16 numdu = numd >> 16;
__u16 numdl = numd & 0xffff;
- cmd.cdw10 = tele_type | (nLSP & 0x0F) << 8 | (nRAE & 0x01) << 15 | (numdl & 0xFFFF) << 16;
+
+ cmd.cdw10 = tele_type |
+ (nLSP & 0x0F) << 8 |
+ (nRAE & 0x01) << 15 |
+ (numdl & 0xFFFF) << 16;
cmd.cdw11 = numdu;
- cmd.cdw12 = offset;
- cmd.cdw13 = 0;
+ cmd.cdw12 = (__u32)(0x00000000FFFFFFFF & offset);
+ cmd.cdw13 = (__u32)((0xFFFFFFFF00000000 & offset) >> 8);
cmd.cdw14 = 0;
return nvme_submit_admin_passthru(dev_fd(dev), &cmd, NULL);
}
@@ -946,121 +987,117 @@ static void print_telemetry_data_area_1(struct telemetry_data_area_1 *da1,
int tele_type)
{
if (da1) {
- unsigned int i = 0;
+ int i = 0;
+
if (tele_type == TELEMETRY_TYPE_HOST)
printf("============ Telemetry Host Data area 1 ============\n");
else
printf("========= Telemetry Controller Data area 1 =========\n");
- printf("Major Version : 0x%x\n", le16_to_cpu(da1->major_version));
- printf("Minor Version : 0x%x\n", le16_to_cpu(da1->minor_version));
- for (i = 0; i < 4; i++)
- printf("reserved1 : 0x%x\n", da1->reserved1[i]);
+ printf("Major Version : 0x%x\n", le16_to_cpu(da1->major_version));
+ printf("Minor Version : 0x%x\n", le16_to_cpu(da1->minor_version));
printf("Timestamp : %"PRIu64"\n", le64_to_cpu(da1->timestamp));
- for (i = 15; i >= 0; i--)
- printf("%x", da1->log_page_guid[i]);
- printf("Number Telemetry Profiles Supported : 0x%x\n", da1->no_of_tps_supp);
- printf("Telemetry Profile Selected (TPS) : 0x%x\n", da1->tps);
- for (i = 0; i < 6; i++)
- printf("reserved2 : 0x%x\n", da1->reserved2[i]);
- printf("Telemetry String Log Size (SLS) : 0x%x\n", le16_to_cpu(da1->sls));
+ printf("Log Page GUID : 0x");
+ for (int j = 15; j >= 0; j--)
+ printf("%02x", da1->log_page_guid[j]);
+ printf("\n");
+ printf("Number Telemetry Profiles Supported : 0x%x\n",
+ da1->no_of_tps_supp);
+ printf("Telemetry Profile Selected (TPS) : 0x%x\n",
+ da1->tps);
+ printf("Telemetry String Log Size (SLS) : 0x%lx\n",
+ le64_to_cpu(da1->sls));
+ printf("Firmware Revision : ");
for (i = 0; i < 8; i++)
- printf("reserved3 : 0x%x\n", da1->reserved3[i]);
- printf("Firmware Revision : 0x%x\n", le16_to_cpu(da1->fw_revision));
- for (i = 0; i < 32; i++)
- printf("reserved4 : 0x%x\n", da1->reserved4[i]);
- printf("Data Area 1 Statistic Start : 0x%x\n", le16_to_cpu(da1->da1_stat_start));
- printf("Data Area 1 Statistic Size : 0x%x\n", le16_to_cpu(da1->da1_stat_size));
- printf("Data Area 2 Statistic Start : 0x%x\n", le16_to_cpu(da1->da2_stat_start));
- printf("Data Area 2 Statistic Size : 0x%x\n", le16_to_cpu(da1->da2_stat_size));
- for (i = 0; i < 32; i++)
- printf("reserved5 : 0x%x\n", da1->reserved5[i]);
- for (i = 0; i < 17; i++){
- printf("Event FIFO %d Data Area : 0x%x\n", i, da1->event_fifo_da[i]);
- printf("Event FIFO %d Start : %"PRIu64"\n", i, le64_to_cpu(da1->event_fifo_start[i]));
- printf("Event FIFO %d Size : %"PRIu64"\n", i, le64_to_cpu(da1->event_fifo_size[i]));
- }
- for (i = 0; i < 80; i++)
- printf("reserved6 : 0x%x\n", da1->reserved6[i]);
- for (i = 0; i < 512; i++){
- printf("SMART / Health Information : 0x%x\n", da1->smart_health_info[i]);
- printf("SMART / Health Information Extended : 0x%x\n", da1->smart_health_info_extended[i]);
- }
- printf("===============================================\n\n");
- }
-}
-static void print_telemetry_da1_stat(__u8 *da1_stat, int tele_type, __u16 buf_size)
-{
- if (da1_stat) {
- unsigned int i = 0;
- if (tele_type == TELEMETRY_TYPE_HOST)
- printf("============ Telemetry Host Data area 1 Statistics ============\n");
- else
- printf("========= Telemetry Controller Data area 1 Statistics =========\n");
- while((i + 8) < buf_size) {
- printf("Statistics Identifier : 0x%x\n", (da1_stat[i] | da1_stat[i+1] << 8));
- printf("Statistics info : 0x%x\n", da1_stat[i+2]);
- printf("NS info : 0x%x\n", da1_stat[i+3]);
- printf("Statistic Data Size : 0x%x\n", (da1_stat[i+4] | da1_stat[i+5] << 8));
- printf("Reserved : 0x%x\n", (da1_stat[i+6] | da1_stat[i+7] << 8));
- i = 8 + ((da1_stat[i+4] | da1_stat[i+5] << 8) * 4);
- }
- printf("===============================================\n\n");
- }
-}
-static void print_telemetry_da1_fifo(__u8 *da1_fifo, int tele_type, __u16 buf_size)
-{
- if (da1_fifo) {
- unsigned int i = 0;
- if (tele_type == TELEMETRY_TYPE_HOST)
- printf("============ Telemetry Host Data area 1 FIFO ============\n");
- else
- printf("========= Telemetry Controller Data area 1 FIFO =========\n");
- while((i + 4) < buf_size) {
- printf("Debug Event Class Type : 0x%x\n", da1_fifo[i]);
- printf("Event ID : 0x%x\n", (da1_fifo[i+1] | da1_fifo[i+2] << 8));
- printf("Event Data Size : 0x%x\n", da1_fifo[3]);
- i = 4 + ((da1_fifo[3]) * 4);
+ printf("%c", (char)da1->fw_revision[i]);
+ printf("\n");
+ printf("Data Area 1 Statistic Start : 0x%lx\n",
+ le64_to_cpu(da1->da1_stat_start));
+ printf("Data Area 1 Statistic Size : 0x%lx\n",
+ le64_to_cpu(da1->da1_stat_size));
+ printf("Data Area 2 Statistic Start : 0x%lx\n",
+ le64_to_cpu(da1->da2_stat_start));
+ printf("Data Area 2 Statistic Size : 0x%lx\n",
+ le64_to_cpu(da1->da2_stat_size));
+ for (i = 0; i < 16; i++) {
+ printf("Event FIFO %d Data Area : 0x%x\n",
+ i, da1->event_fifo_da[i]);
+ printf("Event FIFO %d Start : 0x%"PRIx64"\n",
+ i, le64_to_cpu(da1->event_fifos[i].start));
+ printf("Event FIFO %d Size : 0x%"PRIx64"\n",
+ i, le64_to_cpu(da1->event_fifos[i].size));
}
+ printf("SMART / Health Information :\n");
+ printf("0x");
+ for (i = 0; i < 512; i++)
+ printf("%02x", da1->smart_health_info[i]);
+ printf("\n");
+
+ printf("SMART / Health Information Extended :\n");
+ printf("0x");
+ for (i = 0; i < 512; i++)
+ printf("%02x", da1->smart_health_info_extended[i]);
+ printf("\n");
+
printf("===============================================\n\n");
}
}
-static void print_telemetry_da2_stat(__u8 *da1_stat, int tele_type, __u16 buf_size)
+static void print_telemetry_da_stat(struct telemetry_stats_desc *da_stat,
+ int tele_type,
+ __u16 buf_size,
+ __u8 data_area)
{
- if (da1_stat) {
+ if (da_stat) {
unsigned int i = 0;
+ struct telemetry_stats_desc *next_da_stat = da_stat;
+
if (tele_type == TELEMETRY_TYPE_HOST)
- printf("============ Telemetry Host Data area 1 Statistics ============\n");
+ printf("============ Telemetry Host Data Area %d Statistics ============\n",
+ data_area);
else
- printf("========= Telemetry Controller Data area 1 Statistics =========\n");
- while((i + 8) < buf_size) {
- printf("Statistics Identifier : 0x%x\n", (da1_stat[i] | da1_stat[i+1] << 8));
- printf("Statistics info : 0x%x\n", da1_stat[i+2]);
- printf("NS info : 0x%x\n", da1_stat[i+3]);
- printf("Statistic Data Size : 0x%x\n", (da1_stat[i+4] | da1_stat[i+5] << 8));
- printf("Reserved : 0x%x\n", (da1_stat[i+6] | da1_stat[i+7] << 8));
- i = 8 + ((da1_stat[i+4] | da1_stat[i+5] << 8) * 4);
+ printf("========= Telemetry Controller Data Area %d Statistics =========\n",
+ data_area);
+ while ((i + 8) < buf_size) {
+ print_stats_desc(next_da_stat);
+ i += 8 + ((next_da_stat->size) * 4);
+ next_da_stat = (struct telemetry_stats_desc *)((__u64)da_stat + i);
+
+ if ((next_da_stat->id == 0) && (next_da_stat->size == 0))
+ break;
}
printf("===============================================\n\n");
}
}
-static void print_telemetry_da2_fifo(__u8 *da1_fifo, int tele_type, __u16 buf_size)
+static void print_telemetry_da_fifo(struct telemetry_event_desc *da_fifo,
+ __le64 buf_size,
+ int tele_type,
+ int da,
+ int index)
{
- if (da1_fifo) {
+ if (da_fifo) {
unsigned int i = 0;
+ struct telemetry_event_desc *next_da_fifo = da_fifo;
+
if (tele_type == TELEMETRY_TYPE_HOST)
- printf("============ Telemetry Host Data area 1 Statistics ============\n");
+ printf("========= Telemetry Host Data area %d Event FIFO %d =========\n",
+ da, index);
else
- printf("========= Telemetry Controller Data area 1 Statistics =========\n");
- while((i + 4) < buf_size) {
- printf("Debug Event Class Type : 0x%x\n", da1_fifo[i]);
- printf("Event ID : 0x%x\n", (da1_fifo[i+1] | da1_fifo[i+2] << 8));
- printf("Event Data Size : 0x%x\n", da1_fifo[3]);
- i = 4 + ((da1_fifo[3]) * 4);
+ printf("====== Telemetry Controller Data area %d Event FIFO %d ======\n",
+ da, index);
+
+
+ while ((i + 4) < buf_size) {
+ /* Print Event Data */
+ print_telemetry_fifo_event(next_da_fifo->class, /* Event class type */
+ next_da_fifo->id, /* Event ID */
+ next_da_fifo->size, /* Event data size */
+ (__u8 *)&next_da_fifo->data); /* Event data */
+
+ i += (4 + (next_da_fifo->size * 4));
+ next_da_fifo = (struct telemetry_event_desc *)((__u64)da_fifo + i);
}
printf("===============================================\n\n");
}
}
-
static int extract_dump_get_log(struct nvme_dev *dev, char *featurename, char *filename, char *sn,
int dumpsize, int transfersize, __u32 nsid, __u8 log_id,
__u8 lsp, __u64 offset, bool rae)
@@ -1146,10 +1183,12 @@ static int get_telemetry_dump(struct nvme_dev *dev, char *filename, char *sn,
enum TELEMETRY_TYPE tele_type, int data_area, bool header_print)
{
__u32 err = 0, nsid = 0;
- __u8 lsp = 0, rae = 0;
+ __le64 da1_sz = 512, m_512_sz = 0, da1_off = 0, m_512_off = 0, diff = 0,
+ temp_sz = 0, temp_ofst = 0;
+ __u8 lsp = 0, rae = 0, flag = 0;
+ __u8 data[TELEMETRY_HEADER_SIZE] = { 0 };
unsigned int i = 0;
- char data[TELEMETRY_TRANSFER_SIZE] = { 0 };
- char data1[1536] = { 0 };
+ char data1[TELEMETRY_DATA_SIZE] = { 0 };
char *featurename = 0;
struct telemetry_initiated_log *logheader = (struct telemetry_initiated_log *)data;
struct telemetry_data_area_1 *da1 = (struct telemetry_data_area_1 *)data1;
@@ -1172,51 +1211,245 @@ static int get_telemetry_dump(struct nvme_dev *dev, char *filename, char *sn,
rae = 1;
}
- err = get_telemetry_header(dev, nsid, tele_type, TELEMETRY_HEADER_SIZE,
- (void *)data, lsp, rae);
- if (err)
+ /* Get the telemetry header */
+ err = get_telemetry_data(dev, nsid, tele_type, TELEMETRY_HEADER_SIZE,
+ (void *)data, lsp, rae, 0);
+ if (err) {
+ printf("get_telemetry_header failed, err: %d.\n", err);
return err;
+ }
if (header_print)
print_telemetry_header(logheader, tele_type);
- err = get_telemetry_data(dev, nsid, tele_type, 1536,
+
+ /* Get the telemetry data */
+ err = get_telemetry_data(dev, nsid, tele_type, TELEMETRY_DATA_SIZE,
(void *)data1, lsp, rae, 512);
- if (err)
+ if (err) {
+ printf("get_telemetry_data failed for type: 0x%x, err: %d.\n", tele_type, err);
return err;
+ }
+
print_telemetry_data_area_1(da1, tele_type);
- char *da1_stat = calloc((da1->da1_stat_size * 4), sizeof(char));
- err = get_telemetry_data(dev, nsid, tele_type, (da1->da1_stat_size) * 4,
- (void *)da1_stat, lsp, rae, (da1->da1_stat_start) * 4);
- if (err)
- return err;
- print_telemetry_da1_stat((void *)da1_stat, tele_type, (da1->da1_stat_size) * 4);
- for (i = 0; i < 17 ; i++){
- if (da1->event_fifo_da[i] == 1){
- char *da1_fifo = calloc((da1->event_fifo_size[i]) * 4, sizeof(char));
- err = get_telemetry_data(dev, nsid, tele_type, (da1->event_fifo_size[i]) * 4,
- (void *)da1_stat, lsp, rae, (da1->event_fifo_start[i]) * 4);
- if (err)
+
+ /* Print the Data Area 1 Stats */
+ if (da1->da1_stat_size != 0) {
+ diff = 0;
+ da1_sz = (da1->da1_stat_size) * 4;
+ m_512_sz = (da1->da1_stat_size) * 4;
+ da1_off = (da1->da1_stat_start) * 4;
+ m_512_off = (da1->da1_stat_start) * 4;
+ temp_sz = (da1->da1_stat_size) * 4;
+ temp_ofst = (da1->da1_stat_start) * 4;
+ flag = 0;
+
+ if ((da1_off % 512) > 0) {
+ m_512_off = (__le64) ((da1_off / 512));
+ da1_off = m_512_off * 512;
+ diff = temp_ofst - da1_off;
+ flag = 1;
+ }
+
+ if (da1_sz < 512)
+ da1_sz = 512;
+ else if ((da1_sz % 512) > 0) {
+ if (flag == 0) {
+ m_512_sz = (__le64) ((da1_sz / 512) + 1);
+ da1_sz = m_512_sz * 512;
+ } else {
+ if (diff < 512)
+ diff = 1;
+ else
+ diff = (diff / 512) * 512;
+
+ m_512_sz = (__le64) ((da1_sz / 512) + 1 + diff + 1);
+ da1_sz = m_512_sz * 512;
+ }
+ }
+
+ char *da1_stat = calloc(da1_sz, sizeof(char));
+
+ err = get_telemetry_data(dev, nsid, tele_type, da1_sz,
+ (void *)da1_stat, lsp, rae, da1_off);
+ if (err) {
+ printf("get_telemetry_data da1 stats failed, err: %d.\n", err);
+ return err;
+ }
+
+ print_telemetry_da_stat((void *)(da1_stat + (temp_ofst - da1_off)),
+ tele_type, (da1->da1_stat_size) * 4, 1);
+ }
+
+ /* Print the Data Area 1 Event FIFO's */
+ for (i = 0; i < 16 ; i++) {
+ if ((da1->event_fifo_da[i] == 1) && (da1->event_fifos[i].size != 0)) {
+ diff = 0;
+ da1_sz = da1->event_fifos[i].size * 4;
+ m_512_sz = da1->event_fifos[i].size * 4;
+ da1_off = da1->event_fifos[i].start * 4;
+ m_512_off = da1->event_fifos[i].start * 4;
+ temp_sz = da1->event_fifos[i].size * 4;
+ temp_ofst = da1->event_fifos[i].start * 4;
+ flag = 0;
+
+ if ((da1_off % 512) > 0) {
+ m_512_off = (__le64) ((da1_off / 512));
+ da1_off = m_512_off * 512;
+ diff = temp_ofst - da1_off;
+ flag = 1;
+ }
+
+ if (da1_sz < 512)
+ da1_sz = 512;
+ else if ((da1_sz % 512) > 0) {
+ if (flag == 0) {
+ m_512_sz = (__le64) ((da1_sz / 512) + 1);
+ da1_sz = m_512_sz * 512;
+ } else {
+ if (diff < 512)
+ diff = 1;
+ else
+ diff = (diff / 512) * 512;
+
+ m_512_sz = (__le64) ((da1_sz / 512) + 1 + diff + 1);
+ da1_sz = m_512_sz * 512;
+ }
+ }
+
+ char *da1_fifo = calloc(da1_sz, sizeof(char));
+
+ err = get_telemetry_data(dev, nsid, tele_type,
+ (da1->event_fifos[i].size) * 4,
+ (void *)da1_fifo, lsp, rae, da1_off);
+ if (err) {
+ printf("get_telemetry_data da1 event fifos failed, err: %d.\n",
+ err);
return err;
- print_telemetry_da1_fifo((void *)da1_fifo, tele_type, (da1->event_fifo_size[i]) * 4);
+ }
+ print_telemetry_da_fifo((void *)(da1_fifo + (temp_ofst - da1_off)),
+ temp_sz,
+ tele_type,
+ da1->event_fifo_da[i],
+ i);
}
}
- char *da2_stat = calloc((da1->da2_stat_size * 4), sizeof(char));
- err = get_telemetry_data(dev, nsid, tele_type, (da1->da2_stat_size) * 4,
- (void *)da2_stat, lsp, rae, (da1->da2_stat_start) * 4);
- if (err)
- return err;
- print_telemetry_da2_stat((void *)da2_stat, tele_type, (da1->da2_stat_size) * 4);
- for (i = 0; i < 17 ; i++){
- if (da1->event_fifo_da[i] == 2){
- char *da1_fifo = calloc((da1->event_fifo_size[i]) * 4, sizeof(char));
- err = get_telemetry_data(dev, nsid, tele_type, (da1->event_fifo_size[i]) * 4,
- (void *)da1_stat, lsp, rae, (da1->event_fifo_start[i]) * 4);
- if (err)
+
+ /* Print the Data Area 2 Stats */
+ if (da1->da2_stat_size != 0) {
+ da1_off = (da1->da2_stat_start) * 4;
+ temp_ofst = (da1->da2_stat_start) * 4;
+ da1_sz = (da1->da2_stat_size) * 4;
+ diff = 0;
+ flag = 0;
+
+ if (da1->da2_stat_start == 0) {
+ da1_off = 512 + (logheader->DataArea1LastBlock * 512);
+ temp_ofst = 512 + (le16_to_cpu(logheader->DataArea1LastBlock) * 512);
+ if ((da1_off % 512) == 0) {
+ m_512_off = (__le64) (((da1_off) / 512));
+ da1_off = m_512_off * 512;
+ diff = temp_ofst - da1_off;
+ flag = 1;
+ }
+ } else {
+
+ if (((da1_off * 4) % 512) > 0) {
+ m_512_off = (__le64) ((((da1->da2_stat_start) * 4) / 512));
+ da1_off = m_512_off * 512;
+ diff = ((da1->da2_stat_start) * 4) - da1_off;
+ flag = 1;
+ }
+ }
+
+ if (da1_sz < 512)
+ da1_sz = 512;
+ else if ((da1_sz % 512) > 0) {
+ if (flag == 0) {
+ m_512_sz = (__le64) ((da1->da2_stat_size / 512) + 1);
+ da1_sz = m_512_sz * 512;
+ } else {
+ if (diff < 512)
+ diff = 1;
+ else
+ diff = (diff / 512) * 512;
+ m_512_sz = (__le64) ((da1->da2_stat_size / 512) + 1 + diff + 1);
+ da1_sz = m_512_sz * 512;
+ }
+ }
+
+ char *da2_stat = calloc(da1_sz, sizeof(char));
+
+ err = get_telemetry_data(dev, nsid, tele_type, da1_sz,
+ (void *)da2_stat, lsp, rae, da1_off);
+ if (err) {
+ printf("get_telemetry_data da2 stats failed, err: %d.\n", err);
+ return err;
+ }
+
+ print_telemetry_da_stat((void *)(da2_stat + (temp_ofst - da1_off)),
+ tele_type,
+ (da1->da2_stat_size) * 4,
+ 2);
+ }
+
+ /* Print the Data Area 2 Event FIFO's */
+ for (i = 0; i < 16 ; i++) {
+ if ((da1->event_fifo_da[i] == 2) && (da1->event_fifos[i].size != 0)) {
+ diff = 0;
+ da1_sz = da1->event_fifos[i].size * 4;
+ m_512_sz = da1->event_fifos[i].size * 4;
+ da1_off = da1->event_fifos[i].start * 4;
+ m_512_off = da1->event_fifos[i].start * 4;
+ temp_sz = da1->event_fifos[i].size * 4;
+ temp_ofst = da1->event_fifos[i].start * 4;
+ flag = 0;
+
+ if ((da1_off % 512) > 0) {
+ m_512_off = (__le64) ((da1_off / 512));
+ da1_off = m_512_off * 512;
+ diff = temp_ofst - da1_off;
+ flag = 1;
+ }
+
+ if (da1_sz < 512)
+ da1_sz = 512;
+ else if ((da1_sz % 512) > 0) {
+ if (flag == 0) {
+ m_512_sz = (__le64) ((da1_sz / 512) + 1);
+ da1_sz = m_512_sz * 512;
+ }
+
+ else {
+ if (diff < 512)
+ diff = 1;
+ else
+ diff = (diff / 512) * 512;
+
+ m_512_sz = (__le64) ((da1_sz / 512) + 1 + diff + 1);
+ da1_sz = m_512_sz * 512;
+ }
+ }
+
+ char *da1_fifo = calloc(da1_sz, sizeof(char));
+
+ err = get_telemetry_data(dev, nsid, tele_type,
+ (da1->event_fifos[i].size) * 4,
+ (void *)da1_fifo, lsp, rae, da1_off);
+ if (err) {
+ printf("get_telemetry_data da2 event fifos failed, err: %d.\n",
+ err);
return err;
- print_telemetry_da2_fifo((void *)da1_fifo, tele_type, (da1->event_fifo_size[i]) * 4);
+ }
+ print_telemetry_da_fifo((void *)(da1_fifo + (temp_ofst - da1_off)),
+ temp_sz,
+ tele_type,
+ da1->event_fifo_da[i],
+ i);
}
}
+ printf("------------------------------FIFO End---------------------------\n");
+
switch (data_area) {
case 1:
offset = TELEMETRY_HEADER_SIZE;
@@ -1252,43 +1485,283 @@ static int get_telemetry_dump(struct nvme_dev *dev, char *filename, char *sn,
return err;
}
+static int get_telemetry_log_page_data(struct nvme_dev *dev, int tele_type)
+{
+ char file_path[PATH_MAX];
+ void *telemetry_log;
+ const size_t bs = 512;
+ struct nvme_telemetry_log *hdr;
+ size_t full_size, offset = bs;
+ int err, fd;
+
+ if ((tele_type == TELEMETRY_TYPE_HOST_0) || (tele_type == TELEMETRY_TYPE_HOST_1))
+ tele_type = TELEMETRY_TYPE_HOST;
+
+ int log_id = (tele_type == TELEMETRY_TYPE_HOST ? NVME_LOG_LID_TELEMETRY_HOST :
+ NVME_LOG_LID_TELEMETRY_CTRL);
+
+ hdr = malloc(bs);
+ telemetry_log = malloc(bs);
+ if (!hdr || !telemetry_log) {
+ fprintf(stderr, "Failed to allocate %zu bytes for log: %s\n",
+ bs, strerror(errno));
+ err = -ENOMEM;
+ goto exit_status;
+ }
+ memset(hdr, 0, bs);
+
+ sprintf(file_path, DEFAULT_TELEMETRY_BIN);
+ fd = open(file_path, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to open output file %s: %s!\n",
+ file_path, strerror(errno));
+ err = fd;
+ goto exit_status;
+ }
+
+ struct nvme_get_log_args args = {
+ .lpo = 0,
+ .result = NULL,
+ .log = hdr,
+ .args_size = sizeof(args),
+ .fd = dev_fd(dev),
+ .timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
+ .lid = log_id,
+ .len = bs,
+ .nsid = NVME_NSID_ALL,
+ .csi = NVME_CSI_NVM,
+ .lsi = NVME_LOG_LSI_NONE,
+ .lsp = NVME_LOG_TELEM_HOST_LSP_CREATE,
+ .uuidx = NVME_UUID_NONE,
+ .rae = true,
+ .ot = false,
+ };
+
+ err = nvme_get_log(&args);
+ if (err < 0)
+ nvme_show_error("Failed to fetch the log from drive.\n");
+ else if (err > 0) {
+ nvme_show_status(err);
+ nvme_show_error("Failed to fetch telemetry-header. Error:%d.\n", err);
+ goto close_fd;
+ }
+
+ err = write(fd, (void *)hdr, bs);
+ if (err != bs) {
+ nvme_show_error("Failed to write data to file.\n");
+ goto close_fd;
+ }
+
+ full_size = (le16_to_cpu(hdr->dalb3) * bs) + offset;
+
+ while (offset != full_size) {
+ args.log = telemetry_log;
+ args.lpo = offset;
+ args.lsp = NVME_LOG_LSP_NONE;
+ err = nvme_get_log(&args);
+ if (err < 0) {
+ nvme_show_error("Failed to fetch the log from drive.\n");
+ break;
+ } else if (err > 0) {
+ nvme_show_error("Failed to fetch telemetry-log.\n");
+ nvme_show_status(err);
+ break;
+ }
+
+ err = write(fd, (void *)telemetry_log, bs);
+ if (err != bs) {
+ nvme_show_error("Failed to write data to file.\n");
+ break;
+ }
+ err = 0;
+ offset += bs;
+ }
+
+close_fd:
+ close(fd);
+exit_status:
+ free(hdr);
+ free(telemetry_log);
+
+ return err;
+}
+
+static int get_c9_log_page_data(struct nvme_dev *dev, int print_data, int save_bin)
+{
+ int ret = 0, fd;
+ __le64 stat_id_str_table_ofst = 0;
+ __le64 event_str_table_ofst = 0;
+ __le64 vu_event_str_table_ofst = 0;
+ __le64 ascii_table_ofst = 0;
+ char file_path[PATH_MAX];
+
+ header_data = (__u8 *)malloc(sizeof(__u8) * C9_TELEMETRY_STR_LOG_LEN);
+ if (!header_data) {
+ fprintf(stderr, "ERROR : OCP : malloc : %s\n", strerror(errno));
+ return -1;
+ }
+ memset(header_data, 0, sizeof(__u8) * C9_TELEMETRY_STR_LOG_LEN);
+
+ ret = nvme_get_log_simple(dev_fd(dev), C9_TELEMETRY_STRING_LOG_ENABLE_OPCODE,
+ C9_TELEMETRY_STR_LOG_LEN, header_data);
+
+ if (!ret) {
+ log_data = (struct telemetry_str_log_format *)header_data;
+ if (print_data) {
+ printf("Statistics Identifier String Table Size = %lld\n",
+ log_data->sitsz);
+ printf("Event String Table Size = %lld\n", log_data->estsz);
+ printf("VU Event String Table Size = %lld\n", log_data->vu_eve_st_sz);
+ printf("ASCII Table Size = %lld\n", log_data->asctsz);
+ }
+
+ //Calculating the offset for dynamic fields.
+
+ stat_id_str_table_ofst = log_data->sits * 4;
+ event_str_table_ofst = log_data->ests * 4;
+ vu_event_str_table_ofst = log_data->vu_eve_sts * 4;
+ ascii_table_ofst = log_data->ascts * 4;
+ total_log_page_sz = C9_TELEMETRY_STR_LOG_LEN +
+ (log_data->sitsz * 4) + (log_data->estsz * 4) +
+ (log_data->vu_eve_st_sz * 4) + (log_data->asctsz * 4);
+
+ if (print_data) {
+ printf("stat_id_str_table_ofst = %lld\n", stat_id_str_table_ofst);
+ printf("event_str_table_ofst = %lld\n", event_str_table_ofst);
+ printf("vu_event_str_table_ofst = %lld\n", vu_event_str_table_ofst);
+ printf("ascii_table_ofst = %lld\n", ascii_table_ofst);
+ printf("total_log_page_sz = %lld\n", total_log_page_sz);
+ }
+
+ pC9_string_buffer = (__u8 *)malloc(sizeof(__u8) * total_log_page_sz);
+ if (!pC9_string_buffer) {
+ fprintf(stderr, "ERROR : OCP : malloc : %s\n", strerror(errno));
+ return -1;
+ }
+ memset(pC9_string_buffer, 0, sizeof(__u8) * total_log_page_sz);
+
+ ret = nvme_get_log_simple(dev_fd(dev), C9_TELEMETRY_STRING_LOG_ENABLE_OPCODE,
+ total_log_page_sz, pC9_string_buffer);
+ } else
+ fprintf(stderr, "ERROR : OCP : Unable to read C9 data.\n");
+
+ if (save_bin) {
+ sprintf(file_path, DEFAULT_STRING_BIN);
+ fd = open(file_path, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to open output file %s: %s!\n",
+ file_path, strerror(errno));
+ goto exit_status;
+ }
+
+ ret = write(fd, (void *)pC9_string_buffer, total_log_page_sz);
+ if (ret != total_log_page_sz)
+ fprintf(stderr, "Failed to flush all data to file!\n");
+
+ close(fd);
+ }
+
+exit_status:
+ return 0;
+}
+
+int parse_ocp_telemetry_log(struct ocp_telemetry_parse_options *options)
+{
+ int status = 0;
+ long telemetry_buffer_size = 0;
+ long string_buffer_size = 0;
+ enum nvme_print_flags fmt;
+ unsigned char log_id;
+
+ if (options->telemetry_log) {
+ if (strstr((const char *)options->telemetry_log, "bin")) {
+ // Read the data from the telemetry binary file
+ ptelemetry_buffer =
+ read_binary_file(NULL, (const char *)options->telemetry_log,
+ &telemetry_buffer_size, 1);
+ if (ptelemetry_buffer == NULL) {
+ nvme_show_error("Failed to read telemetry-log.\n");
+ return -1;
+ }
+ }
+ } else {
+ nvme_show_error("telemetry-log is empty.\n");
+ return -1;
+ }
+
+ log_id = ptelemetry_buffer[0];
+ if ((log_id != NVME_LOG_LID_TELEMETRY_HOST) && (log_id != NVME_LOG_LID_TELEMETRY_CTRL)) {
+ nvme_show_error("Invalid LogPageId [0x%02X]\n", log_id);
+ return -1;
+ }
+
+ if (options->string_log) {
+ // Read the data from the string binary file
+ if (strstr((const char *)options->string_log, "bin")) {
+ pstring_buffer = read_binary_file(NULL, (const char *)options->string_log,
+ &string_buffer_size, 1);
+ if (pstring_buffer == NULL) {
+ nvme_show_error("Failed to read string-log.\n");
+ return -1;
+ }
+ }
+ } else {
+ nvme_show_error("string-log is empty.\n");
+ return -1;
+ }
+
+ status = validate_output_format(options->output_format, &fmt);
+ if (status < 0) {
+ nvme_show_error("Invalid output format\n");
+ return status;
+ }
+
+ switch (fmt) {
+ case NORMAL:
+ print_ocp_telemetry_normal(options);
+ break;
+ case JSON:
+ print_ocp_telemetry_json(options);
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+
static int ocp_telemetry_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
- struct nvme_dev *dev;
- int err = 0;
- const char *desc = "Retrieve and save telemetry log.";
- const char *type = "Telemetry Type; 'host[Create bit]' or 'controller'";
- const char *area = "Telemetry Data Area; 1 or 3";
- const char *file = "Output file name with path;\n"
+ const char *desc = "Retrieve and parse OCP Telemetry log.";
+ const char *telemetry_log = "Telemetry log binary;\n 'host.bin' or 'controller.bin'";
+ const char *string_log = "String log binary; 'C9.bin'";
+ const char *output_file = "Output file name with path;\n"
"e.g. '-o ./path/name'\n'-o ./path1/path2/';\n"
"If requested path does not exist, the directory will be newly created.";
+ const char *output_format = "output format normal|json";
+ const char *data_area = "Telemetry Data Area; 1 or 2;\n"
+ "e.g. '-a 1 for Data Area 1.'\n'-a 2 for Data Areas 1 and 2.';\n";
+ const char *telemetry_type = "Telemetry Type; 'host' or 'controller'";
+ struct nvme_dev *dev;
+ int err = 0;
__u32 nsid = NVME_NSID_ALL;
struct stat nvme_stat;
char sn[21] = {0,};
struct nvme_id_ctrl ctrl;
bool is_support_telemetry_controller;
-
+ struct ocp_telemetry_parse_options opt;
int tele_type = 0;
int tele_area = 0;
- struct config {
- char *type;
- int area;
- char *file;
- };
-
- struct config cfg = {
- .type = NULL,
- .area = 0,
- .file = NULL,
- };
-
OPT_ARGS(opts) = {
- OPT_STR("telemetry_type", 't', &cfg.type, type),
- OPT_INT("telemetry_data_area", 'a', &cfg.area, area),
- OPT_FILE("output-file", 'o', &cfg.file, file),
+ OPT_STR("telemetry-log", 'l', &opt.telemetry_log, telemetry_log),
+ OPT_STR("string-log", 's', &opt.string_log, string_log),
+ OPT_FILE("output-file", 'o', &opt.output_file, output_file),
+ OPT_FMT("output-format", 'f', &opt.output_format, output_format),
+ OPT_INT("data-area", 'a', &opt.data_area, data_area),
+ OPT_STR("telemetry-type", 't', &opt.telemetry_type, telemetry_type),
OPT_END()
};
@@ -1314,36 +1787,84 @@ static int ocp_telemetry_log(int argc, char **argv, struct command *cmd,
is_support_telemetry_controller = ((ctrl.lpa & 0x8) >> 3);
- if (!cfg.type && !cfg.area) {
- tele_type = TELEMETRY_TYPE_NONE;
- tele_area = 0;
- } else if (cfg.type && cfg.area) {
- if (!strcmp(cfg.type, "host0"))
+ if (!opt.data_area) {
+ nvme_show_result("Missing data-area. Using default data area 1.\n");
+ opt.data_area = DATA_AREA_1;//Default data area 1
+ } else if (opt.data_area != 1 && opt.data_area != 2) {
+ nvme_show_result("Invalid data-area specified. Please specify 1 or 2.\n");
+ goto out;
+ }
+
+ tele_area = opt.data_area;
+
+ if (opt.telemetry_type) {
+ if (!strcmp(opt.telemetry_type, "host0"))
tele_type = TELEMETRY_TYPE_HOST_0;
- else if (!strcmp(cfg.type, "host1"))
+ else if (!strcmp(opt.telemetry_type, "host1"))
tele_type = TELEMETRY_TYPE_HOST_1;
- else if (!strcmp(cfg.type, "controller"))
+ else if (!strcmp(opt.telemetry_type, "host"))
+ tele_type = TELEMETRY_TYPE_HOST;
+ else if (!strcmp(opt.telemetry_type, "controller"))
tele_type = TELEMETRY_TYPE_CONTROLLER;
+ else {
+ nvme_show_error("telemetry-type should be host or controller.\n");
+ goto out;
+ }
+ } else {
+ tele_type = TELEMETRY_TYPE_HOST; //Default Type - Host
+ nvme_show_result("Missing telemetry-type. Using default - host.\n");
+ }
- tele_area = cfg.area;
+ if (!opt.telemetry_log) {
+ nvme_show_result("\nMissing telemetry-log. Fetching from drive...\n");
+ err = get_telemetry_log_page_data(dev, tele_type);//Pull Telemetry log
+ if (err) {
+ nvme_show_error("Failed to fetch telemetry-log from the drive.\n");
+ goto out;
+ }
+ nvme_show_result("telemetry.bin generated. Proceeding with next steps.\n");
+ opt.telemetry_log = DEFAULT_TELEMETRY_BIN;
+ }
- if ((tele_area != 1 && tele_area != 3) ||
- (tele_type == TELEMETRY_TYPE_CONTROLLER && tele_area != 3)) {
- printf("\nUnsupported parameters entered.\n");
- printf("Possible combinations; {'host0',1}, {'host0',3}, {'host1',1}, {'host1',3}, {'controller',3}\n");
- return err;
+ if (!opt.string_log) {
+ nvme_show_result("Missing string-log. Fetching from drive...\n");
+ err = get_c9_log_page_data(dev, 0, 1); //Pull String log
+ if (err) {
+ nvme_show_error("Failed to fetch string-log from the drive.\n");
+ goto out;
}
- } else {
- printf("\nShould provide these all; 'telemetry_type' and 'telemetry_data_area'\n");
- return err;
+ nvme_show_result("string.bin generated. Proceeding with next steps.\n");
+ opt.string_log = DEFAULT_STRING_BIN;
}
- if (tele_type == TELEMETRY_TYPE_NONE) {
+ if (!opt.output_format) {
+ nvme_show_result("Missing format. Using default format - JSON.\n");
+ opt.output_format = DEFAULT_OUTPUT_FORMAT_JSON;
+ }
+
+ switch (tele_type) {
+ case TELEMETRY_TYPE_HOST: {
+ printf("Extracting Telemetry Host Dump (Data Area %d)...\n", tele_area);
+ err = parse_ocp_telemetry_log(&opt);
+ if (err)
+ nvme_show_result("Status:(%x)\n", err);
+ }
+ break;
+ case TELEMETRY_TYPE_CONTROLLER: {
+ printf("Extracting Telemetry Controller Dump (Data Area %d)...\n", tele_area);
+ if (is_support_telemetry_controller == true) {
+ err = parse_ocp_telemetry_log(&opt);
+ if (err)
+ nvme_show_result("Status:(%x)\n", err);
+ }
+ }
+ break;
+ case TELEMETRY_TYPE_NONE: {
printf("\n-------------------------------------------------------------\n");
/* Host 0 (lsp == 0) must be executed before Host 1 (lsp == 1). */
printf("\nExtracting Telemetry Host 0 Dump (Data Area 1)...\n");
- err = get_telemetry_dump(dev, cfg.file, sn,
+ err = get_telemetry_dump(dev, opt.output_file, sn,
TELEMETRY_TYPE_HOST_0, 1, true);
if (err)
fprintf(stderr, "NVMe Status: %s(%x)\n", nvme_status_to_string(err, false), err);
@@ -1352,7 +1873,7 @@ static int ocp_telemetry_log(int argc, char **argv, struct command *cmd,
printf("\nExtracting Telemetry Host 0 Dump (Data Area 3)...\n");
- err = get_telemetry_dump(dev, cfg.file, sn,
+ err = get_telemetry_dump(dev, opt.output_file, sn,
TELEMETRY_TYPE_HOST_0, 3, false);
if (err)
fprintf(stderr, "NVMe Status: %s(%x)\n", nvme_status_to_string(err, false), err);
@@ -1361,7 +1882,7 @@ static int ocp_telemetry_log(int argc, char **argv, struct command *cmd,
printf("\nExtracting Telemetry Host 1 Dump (Data Area 1)...\n");
- err = get_telemetry_dump(dev, cfg.file, sn,
+ err = get_telemetry_dump(dev, opt.output_file, sn,
TELEMETRY_TYPE_HOST_1, 1, true);
if (err)
fprintf(stderr, "NVMe Status: %s(%x)\n", nvme_status_to_string(err, false), err);
@@ -1370,7 +1891,7 @@ static int ocp_telemetry_log(int argc, char **argv, struct command *cmd,
printf("\nExtracting Telemetry Host 1 Dump (Data Area 3)...\n");
- err = get_telemetry_dump(dev, cfg.file, sn,
+ err = get_telemetry_dump(dev, opt.output_file, sn,
TELEMETRY_TYPE_HOST_1, 3, false);
if (err)
fprintf(stderr, "NVMe Status: %s(%x)\n", nvme_status_to_string(err, false), err);
@@ -1380,35 +1901,35 @@ static int ocp_telemetry_log(int argc, char **argv, struct command *cmd,
printf("\nExtracting Telemetry Controller Dump (Data Area 3)...\n");
if (is_support_telemetry_controller == true) {
- err = get_telemetry_dump(dev, cfg.file, sn,
+ err = get_telemetry_dump(dev, opt.output_file, sn,
TELEMETRY_TYPE_CONTROLLER, 3, true);
if (err)
fprintf(stderr, "NVMe Status: %s(%x)\n", nvme_status_to_string(err, false), err);
}
printf("\n-------------------------------------------------------------\n");
- } else if (tele_type == TELEMETRY_TYPE_CONTROLLER) {
- printf("Extracting Telemetry Controller Dump (Data Area %d)...\n", tele_area);
-
- if (is_support_telemetry_controller == true) {
- err = get_telemetry_dump(dev, cfg.file, sn, tele_type, tele_area, true);
- if (err)
- fprintf(stderr, "NVMe Status: %s(%x)\n", nvme_status_to_string(err, false), err);
- }
- } else {
+ }
+ break;
+ case TELEMETRY_TYPE_HOST_0:
+ case TELEMETRY_TYPE_HOST_1:
+ default: {
printf("Extracting Telemetry Host(%d) Dump (Data Area %d)...\n",
(tele_type == TELEMETRY_TYPE_HOST_0) ? 0 : 1, tele_area);
- err = get_telemetry_dump(dev, cfg.file, sn, tele_type, tele_area, true);
+ err = get_telemetry_dump(dev, opt.output_file, sn, tele_type, tele_area, true);
if (err)
fprintf(stderr, "NVMe Status: %s(%x)\n", nvme_status_to_string(err, false), err);
}
+ break;
+ }
- printf("telemetry-log done.\n");
-
-return err;
+ printf("ocp internal-log command completed.\n");
+out:
+ dev_close(dev);
+ return err;
}
+
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
@@ -1511,7 +2032,7 @@ static void ocp_print_c5_log_binary(struct unsupported_requirement_log *log_data
static int get_c5_log_page(struct nvme_dev *dev, char *format)
{
- enum nvme_print_flags fmt;
+ nvme_print_flags_t fmt;
int ret;
__u8 *data;
int i;
@@ -1585,7 +2106,6 @@ out:
return ret;
}
-
static int ocp_unsupported_requirements_log(int argc, char **argv, struct command *cmd,
struct plugin *plugin)
{
@@ -1738,7 +2258,7 @@ 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)
{
struct ocp_error_recovery_log_page *log_data;
- enum nvme_print_flags fmt;
+ nvme_print_flags_t fmt;
int ret;
__u8 *data;
int i, j;
@@ -1954,7 +2474,7 @@ static void ocp_print_c4_log_binary(struct ocp_device_capabilities_log_page *log
static int get_c4_log_page(struct nvme_dev *dev, char *format)
{
struct ocp_device_capabilities_log_page *log_data;
- enum nvme_print_flags fmt;
+ nvme_print_flags_t fmt;
int ret;
__u8 *data;
int i, j;
@@ -2241,6 +2761,106 @@ static int set_dssd_power_state_feature(int argc, char **argv, struct command *c
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
+/// DSSD Power State (Feature Identifier C7h) Get Feature
+
+static int get_dssd_power_state(struct nvme_dev *dev, const __u32 nsid,
+ const __u8 fid, __u8 sel, bool uuid)
+{
+ __u32 result;
+ int err;
+ __u8 uuid_index = 0;
+
+ if (uuid) {
+ /* OCP 2.0 requires UUID index support */
+ err = ocp_get_uuid_index(dev, &uuid_index);
+ if (err || !uuid_index) {
+ nvme_show_error("ERROR: No OCP UUID index found");
+ return err;
+ }
+ }
+
+ struct nvme_get_features_args args = {
+ .args_size = sizeof(args),
+ .fd = dev_fd(dev),
+ .fid = fid,
+ .nsid = nsid,
+ .sel = sel,
+ .cdw11 = 0,
+ .uuidx = uuid_index,
+ .data_len = 0,
+ .data = NULL,
+ .timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
+ .result = &result,
+ };
+
+ err = nvme_get_features(&args);
+ if (!err) {
+ printf("get-feature:0xC7 %s value: %#08x\n", nvme_select_to_string(sel), result);
+
+ if (sel == NVME_GET_FEATURES_SEL_SUPPORTED)
+ nvme_show_select_result(fid, result);
+ } else {
+ nvme_show_error("Could not get feature: 0xC7 with sel: %d\n", sel);
+ }
+
+ return err;
+}
+
+static int get_dssd_power_state_feature(int argc, char **argv, struct command *cmd,
+ struct plugin *plugin)
+{
+ const char *desc = "Define DSSD Power State (Feature Identifier C7h) Get Feature.";
+ const char *all = "Print out all 3 values at once - Current, Default, and Saved";
+ const char *sel = "[0-3]: current/default/saved/supported/";
+ const __u32 nsid = 0;
+ const __u8 fid = 0xC7;
+ struct nvme_dev *dev;
+ int i, err;
+
+ struct config {
+ __u8 sel;
+ bool all;
+ };
+
+ struct config cfg = {
+ .sel = 0,
+ .all = false,
+ };
+
+ OPT_ARGS(opts) = {
+ OPT_BYTE("sel", 'S', &cfg.sel, sel),
+ OPT_FLAG("all", 'a', NULL, all),
+ OPT_FLAG("no-uuid", 'n', NULL,
+ "Skip UUID index search (UUID index not required for OCP 1.0)"),
+ OPT_END()
+ };
+
+ err = parse_and_open(&dev, argc, argv, desc, opts);
+ if (err)
+ return err;
+
+ if (argconfig_parse_seen(opts, "all")) {
+ for (i = 0; i < 3; i++) {
+ err = get_dssd_power_state(dev, nsid, fid, i,
+ !argconfig_parse_seen(opts, "no-uuid"));
+ if (err)
+ break;
+ }
+ } else if (argconfig_parse_seen(opts, "sel"))
+ err = get_dssd_power_state(dev, nsid, fid, cfg.sel,
+ !argconfig_parse_seen(opts, "no-uuid"));
+ else
+ nvme_show_error("Required to have --sel as an argument, or pass the --all flag.");
+
+ dev_close(dev);
+
+ return err;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
/// plp_health_check_interval
static int set_plp_health_check_interval(int argc, char **argv, struct command *cmd,
@@ -2517,139 +3137,12 @@ static int get_dssd_async_event_config(int argc, char **argv, struct command *cm
///////////////////////////////////////////////////////////////////////////////
/// Telemetry String Log Format Log Page (LID : C9h)
-/* C9 Telemetry String Log Format Log Page */
-#define C9_GUID_LENGTH 16
-#define C9_TELEMETRY_STRING_LOG_ENABLE_OPCODE 0xC9
-#define C9_TELEMETRY_STR_LOG_LEN 432
-#define C9_TELEMETRY_STR_LOG_SIST_OFST 431
-
-/**
- * struct telemetry_str_log_format - Telemetry String Log Format
- * @log_page_version: indicates the version of the mapping this log page uses
- * Shall be set to 01h.
- * @reserved1: Reserved.
- * @log_page_guid: Shall be set to B13A83691A8F408B9EA495940057AA44h.
- * @sls: Shall be set to the number of DWORDS in the String Log.
- * @reserved2: reserved.
- * @sits: shall be set to the number of DWORDS in the Statistics
- * Identifier String Table
- * @ests: Shall be set to the number of DWORDS from byte 0 of this
- * log page to the start of the Event String Table
- * @estsz: shall be set to the number of DWORDS in the Event String Table
- * @vu_eve_sts: Shall be set to the number of DWORDS from byte 0 of this
- * log page to the start of the VU Event String Table
- * @vu_eve_st_sz: shall be set to the number of DWORDS in the VU Event String Table
- * @ascts: the number of DWORDS from byte 0 of this log page until the ASCII Table Starts.
- * @asctsz: the number of DWORDS in the ASCII Table
- * @fifo1: FIFO 0 ASCII String
- * @fifo2: FIFO 1 ASCII String
- * @fifo3: FIFO 2 ASCII String
- * @fifo4: FIFO 3 ASCII String
- * @fif05: FIFO 4 ASCII String
- * @fifo6: FIFO 5 ASCII String
- * @fifo7: FIFO 6 ASCII String
- * @fifo8: FIFO 7 ASCII String
- * @fifo9: FIFO 8 ASCII String
- * @fifo10: FIFO 9 ASCII String
- * @fif011: FIFO 10 ASCII String
- * @fif012: FIFO 11 ASCII String
- * @fifo13: FIFO 12 ASCII String
- * @fif014: FIFO 13 ASCII String
- * @fif015: FIFO 14 ASCII String
- * @fif016: FIFO 15 ASCII String
- * @reserved3: reserved
- */
-struct __attribute__((__packed__)) telemetry_str_log_format {
- __u8 log_page_version;
- __u8 reserved1[15];
- __u8 log_page_guid[C9_GUID_LENGTH];
- __le64 sls;
- __u8 reserved2[24];
- __le64 sits;
- __le64 sitsz;
- __le64 ests;
- __le64 estsz;
- __le64 vu_eve_sts;
- __le64 vu_eve_st_sz;
- __le64 ascts;
- __le64 asctsz;
- __u8 fifo1[16];
- __u8 fifo2[16];
- __u8 fifo3[16];
- __u8 fifo4[16];
- __u8 fifo5[16];
- __u8 fifo6[16];
- __u8 fifo7[16];
- __u8 fifo8[16];
- __u8 fifo9[16];
- __u8 fifo10[16];
- __u8 fifo11[16];
- __u8 fifo12[16];
- __u8 fifo13[16];
- __u8 fifo14[16];
- __u8 fifo15[16];
- __u8 fifo16[16];
- __u8 reserved3[48];
-};
-
-/*
- * struct statistics_id_str_table_entry - Statistics Identifier String Table Entry
- * @vs_si: Shall be set the Vendor Unique Statistic Identifier number.
- * @reserved1: Reserved
- * @ascii_id_len: Shall be set the number of ASCII Characters that are valid.
- * @ascii_id_ofst: Shall be set to the offset from DWORD 0/Byte 0 of the Start
- * of the ASCII Table to the first character of the string for
- * this Statistic Identifier string..
- * @reserved2 reserved
- */
-struct __attribute__((__packed__)) statistics_id_str_table_entry {
- __le16 vs_si;
- __u8 reserved1;
- __u8 ascii_id_len;
- __le64 ascii_id_ofst;
- __le32 reserved2;
-};
-
-/*
- * struct event_id_str_table_entry - Event Identifier String Table Entry
- * @deb_eve_class: Shall be set the Debug Class.
- * @ei: Shall be set to the Event Identifier
- * @ascii_id_len: Shall be set the number of ASCII Characters that are valid.
- * @ascii_id_ofst: This is the offset from DWORD 0/ Byte 0 of the start of the
- * ASCII table to the ASCII data for this identifier
- * @reserved2 reserved
- */
-struct __attribute__((__packed__)) event_id_str_table_entry {
- __u8 deb_eve_class;
- __le16 ei;
- __u8 ascii_id_len;
- __le64 ascii_id_ofst;
- __le32 reserved2;
-};
-
-/*
- * struct vu_event_id_str_table_entry - VU Event Identifier String Table Entry
- * @deb_eve_class: Shall be set the Debug Class.
- * @vu_ei: Shall be set to the VU Event Identifier
- * @ascii_id_len: Shall be set the number of ASCII Characters that are valid.
- * @ascii_id_ofst: This is the offset from DWORD 0/ Byte 0 of the start of the
- * ASCII table to the ASCII data for this identifier
- * @reserved reserved
- */
-struct __attribute__((__packed__)) vu_event_id_str_table_entry {
- __u8 deb_eve_class;
- __le16 vu_ei;
- __u8 ascii_id_len;
- __le64 ascii_id_ofst;
- __le32 reserved;
-};
-
/* Function declaration for Telemetry String Log Format (LID:C9h) */
static int ocp_telemetry_str_log_format(int argc, char **argv, struct command *cmd,
struct plugin *plugin);
-static int ocp_print_C9_log_normal(struct telemetry_str_log_format *log_data,__u8 *log_data_buf)
+static int ocp_print_C9_log_normal(struct telemetry_str_log_format *log_data, __u8 *log_data_buf)
{
//calculating the index value for array
__le64 stat_id_index = (log_data->sitsz * 4) / 16;
@@ -2657,14 +3150,13 @@ static int ocp_print_C9_log_normal(struct telemetry_str_log_format *log_data,__u
__le64 vu_eve_index = (log_data->vu_eve_st_sz * 4) / 16;
__le64 ascii_table_index = (log_data->asctsz * 4);
//Calculating the offset for dynamic fields.
- __le64 stat_id_str_table_ofst = C9_TELEMETRY_STR_LOG_SIST_OFST + (log_data->sitsz * 4);
- __le64 event_str_table_ofst = stat_id_str_table_ofst + (log_data->estsz * 4);
- __le64 vu_event_str_table_ofst = event_str_table_ofst + (log_data->vu_eve_st_sz * 4);
- __le64 ascii_table_ofst = vu_event_str_table_ofst + (log_data->asctsz * 4);
+ __le64 stat_id_str_table_ofst = log_data->sits * 4;
+ __le64 event_str_table_ofst = log_data->ests * 4;
+ __le64 vu_event_str_table_ofst = log_data->vu_eve_sts * 4;
+ __le64 ascii_table_ofst = log_data->ascts * 4;
struct statistics_id_str_table_entry stat_id_str_table_arr[stat_id_index];
struct event_id_str_table_entry event_id_str_table_arr[eve_id_index];
struct vu_event_id_str_table_entry vu_event_id_str_table_arr[vu_eve_index];
- __u8 ascii_table_info_arr[ascii_table_index];
int j;
printf(" Log Page Version : 0x%x\n", log_data->log_page_version);
@@ -2697,172 +3189,180 @@ static int ocp_print_C9_log_normal(struct telemetry_str_log_format *log_data,__u
printf(" FIFO 1 ASCII String\n");
printf(" index value ascii_val\n");
- for (j = 0; j < 16; j++){
+ for (j = 0; j < 16; j++)
printf(" %d %d %c \n", j, log_data->fifo1[j], log_data->fifo1[j]);
- }
printf(" FIFO 2 ASCII String\n");
printf(" index value ascii_val\n");
- for (j = 0; j < 16; j++){
+ for (j = 0; j < 16; j++)
printf(" %d %d %c \n", j, log_data->fifo2[j], log_data->fifo2[j]);
- }
printf(" FIFO 3 ASCII String\n");
printf(" index value ascii_val\n");
- for (j = 0; j < 16; j++){
+ for (j = 0; j < 16; j++)
printf(" %d %d %c \n", j, log_data->fifo3[j], log_data->fifo3[j]);
- }
printf(" FIFO 4 ASCII String\n");
printf(" index value ascii_val\n");
- for (j = 0; j < 16; j++){
-
+ for (j = 0; j < 16; j++)
printf(" %d %d %c \n", j, log_data->fifo4[j], log_data->fifo4[j]);
- }
printf(" FIFO 5 ASCII String\n");
printf(" index value ascii_val\n");
- for (j = 0; j < 16; j++){
+ for (j = 0; j < 16; j++)
printf(" %d %d %c \n", j, log_data->fifo5[j], log_data->fifo5[j]);
- }
printf(" FIFO 6 ASCII String\n");
printf(" index value ascii_val\n");
- for (j = 0; j < 16; j++){
+ for (j = 0; j < 16; j++)
printf(" %d %d %c \n", j, log_data->fifo6[j], log_data->fifo6[j]);
- }
printf(" FIFO 7 ASCII String\n");
printf(" index value ascii_val\n");
- for (j = 0; j < 16; j++){
+ for (j = 0; j < 16; j++)
printf(" %d %d %c \n", j, log_data->fifo7[j], log_data->fifo7[j]);
- }
printf(" FIFO 8 ASCII String\n");
printf(" index value ascii_val\n");
- for (j = 0; j < 16; j++){
- printf("index value ascii_val");
+ for (j = 0; j < 16; j++)
printf(" %d %d %c \n", j, log_data->fifo8[j], log_data->fifo8[j]);
- }
printf(" FIFO 9 ASCII String\n");
printf(" index value ascii_val\n");
- for (j = 0; j < 16; j++){
+ for (j = 0; j < 16; j++)
printf(" %d %d %c \n", j, log_data->fifo9[j], log_data->fifo9[j]);
- }
printf(" FIFO 10 ASCII String\n");
printf(" index value ascii_val\n");
- for (j = 0; j < 16; j++){
+ for (j = 0; j < 16; j++)
printf(" %d %d %c \n", j, log_data->fifo10[j], log_data->fifo10[j]);
- }
printf(" FIFO 11 ASCII String\n");
printf(" index value ascii_val\n");
- for (j = 0; j < 16; j++){
+ for (j = 0; j < 16; j++)
printf(" %d %d %c \n", j, log_data->fifo11[j], log_data->fifo11[j]);
- }
printf(" FIFO 12 ASCII String\n");
printf(" index value ascii_val\n");
- for (j = 0; j < 16; j++){
+ for (j = 0; j < 16; j++)
printf(" %d %d %c \n", j, log_data->fifo12[j], log_data->fifo12[j]);
- }
printf(" FIFO 13 ASCII String\n");
printf(" index value ascii_val\n");
- for (j = 0; j < 16; j++){
+ for (j = 0; j < 16; j++)
printf(" %d %d %c \n", j, log_data->fifo13[j], log_data->fifo13[j]);
- }
printf(" FIFO 14 ASCII String\n");
printf(" index value ascii_val\n");
- for (j = 0; j < 16; j++){
+ for (j = 0; j < 16; j++)
printf(" %d %d %c \n", j, log_data->fifo14[j], log_data->fifo14[j]);
- }
printf(" FIFO 15 ASCII String\n");
printf(" index value ascii_val\n");
- for (j = 0; j < 16; j++){
+ for (j = 0; j < 16; j++)
printf(" %d %d %c \n", j, log_data->fifo15[j], log_data->fifo16[j]);
- }
printf(" FIFO 16 ASCII String\n");
printf(" index value ascii_val\n");
- for (j = 0; j < 16; j++){
+ for (j = 0; j < 16; j++)
printf(" %d %d %c \n", j, log_data->fifo16[j], log_data->fifo16[j]);
- }
printf(" Reserved : ");
for (j = 0; j < 48; j++)
printf("%d", log_data->reserved3[j]);
printf("\n");
- memcpy(stat_id_str_table_arr, (__u8*)log_data_buf + stat_id_str_table_ofst, (log_data->sitsz * 4));
- memcpy(event_id_str_table_arr, (__u8*)log_data_buf + event_str_table_ofst, (log_data->estsz * 4));
- memcpy(vu_event_id_str_table_arr, (__u8*)log_data_buf + vu_event_str_table_ofst, (log_data->vu_eve_st_sz * 4));
- memcpy(ascii_table_info_arr, (__u8*)log_data_buf + ascii_table_ofst, (log_data->asctsz * 4));
- printf(" Statistics Identifier String Table\n");
- for (j = 0; j < stat_id_index; j++){
- printf(" Vendor Specific Statistic Identifier : 0x%x\n",le16_to_cpu(stat_id_str_table_arr[j].vs_si));
- printf(" Reserved : 0x%d",stat_id_str_table_arr[j].reserved1);
- printf(" ASCII ID Length : 0x%x\n",stat_id_str_table_arr[j].ascii_id_len);
- printf(" ASCII ID offset : 0x%lx\n",le64_to_cpu(stat_id_str_table_arr[j].ascii_id_ofst));
- printf(" Reserved : 0x%d\n",stat_id_str_table_arr[j].reserved2);
+ if (log_data->sitsz != 0) {
+ memcpy(stat_id_str_table_arr,
+ (__u8 *)log_data_buf + stat_id_str_table_ofst,
+ (log_data->sitsz * 4));
+ printf(" Statistics Identifier String Table\n");
+ for (j = 0; j < stat_id_index; j++) {
+ printf(" Vendor Specific Statistic Identifier : 0x%x\n",
+ le16_to_cpu(stat_id_str_table_arr[j].vs_si));
+ printf(" Reserved : 0x%x\n",
+ stat_id_str_table_arr[j].reserved1);
+ printf(" ASCII ID Length : 0x%x\n",
+ stat_id_str_table_arr[j].ascii_id_len);
+ printf(" ASCII ID offset : 0x%lx\n",
+ le64_to_cpu(stat_id_str_table_arr[j].ascii_id_ofst));
+ printf(" Reserved : 0x%x\n",
+ stat_id_str_table_arr[j].reserved2);
+ }
}
- printf(" Event Identifier String Table Entry\n");
- for (j = 0; j < eve_id_index; j++){
- printf(" Debug Event Class : 0x%x\n",event_id_str_table_arr[j].deb_eve_class);
- printf(" Event Identifier : 0x%x\n",le16_to_cpu(event_id_str_table_arr[j].ei));
- printf(" ASCII ID Length : 0x%x\n",event_id_str_table_arr[j].ascii_id_len);
- printf(" ASCII ID offset : 0x%lx\n",le64_to_cpu(event_id_str_table_arr[j].ascii_id_ofst));
- printf(" Reserved : 0x%d\n",event_id_str_table_arr[j].reserved2);
+ if (log_data->estsz != 0) {
+ memcpy(event_id_str_table_arr, (__u8 *)log_data_buf +
+ event_str_table_ofst, (log_data->estsz * 4));
+ printf(" Event Identifier String Table Entry\n");
+ for (j = 0; j < eve_id_index; j++) {
+ printf(" Debug Event Class : 0x%x\n",
+ event_id_str_table_arr[j].deb_eve_class);
+ printf(" Event Identifier : 0x%x\n",
+ le16_to_cpu(event_id_str_table_arr[j].ei));
+ printf(" ASCII ID Length : 0x%x\n",
+ event_id_str_table_arr[j].ascii_id_len);
+ printf(" ASCII ID offset : 0x%lx\n",
+ le64_to_cpu(event_id_str_table_arr[j].ascii_id_ofst));
+ printf(" Reserved : 0x%x\n",
+ event_id_str_table_arr[j].reserved2);
+
+ }
}
- printf(" VU Event Identifier String Table Entry\n");
- for (j = 0; j < vu_eve_index; j++){
- printf(" Debug Event Class : 0x%x\n",vu_event_id_str_table_arr[j].deb_eve_class);
- printf(" VU Event Identifier : 0x%x\n",le16_to_cpu(vu_event_id_str_table_arr[j].vu_ei));
- printf(" ASCII ID Length : 0x%x\n",vu_event_id_str_table_arr[j].ascii_id_len);
- printf(" ASCII ID offset : 0x%lx\n",le64_to_cpu(vu_event_id_str_table_arr[j].ascii_id_ofst));
- printf(" Reserved : 0x%d\n",vu_event_id_str_table_arr[j].reserved);
+ if (log_data->vu_eve_st_sz != 0) {
+ memcpy(vu_event_id_str_table_arr, (__u8 *)log_data_buf +
+ vu_event_str_table_ofst, (log_data->vu_eve_st_sz * 4));
+ printf(" VU Event Identifier String Table Entry\n");
+ for (j = 0; j < vu_eve_index; j++) {
+ printf(" Debug Event Class : 0x%x\n",
+ vu_event_id_str_table_arr[j].deb_eve_class);
+ printf(" VU Event Identifier : 0x%x\n",
+ le16_to_cpu(vu_event_id_str_table_arr[j].vu_ei));
+ printf(" ASCII ID Length : 0x%x\n",
+ vu_event_id_str_table_arr[j].ascii_id_len);
+ printf(" ASCII ID offset : 0x%lx\n",
+ le64_to_cpu(vu_event_id_str_table_arr[j].ascii_id_ofst));
+ printf(" Reserved : 0x%x\n",
+ vu_event_id_str_table_arr[j].reserved);
+ }
}
- printf(" ASCII Table\n");
- printf(" Byte Data_Byte ASCII_Character\n");
- for (j = 0; j < ascii_table_index; j++){
- printf(" %lld 0x%x %c \n",ascii_table_ofst+j,ascii_table_info_arr[j],ascii_table_info_arr[j]);
+ if (log_data->asctsz != 0) {
+ printf(" ASCII Table\n");
+ printf(" Byte Data_Byte ASCII_Character\n");
+ for (j = 0; j < ascii_table_index; j++)
+ printf(" %lld %d %c\n",
+ ascii_table_ofst+j, log_data_buf[ascii_table_ofst + j],
+ (char)log_data_buf[ascii_table_ofst + j]);
}
+
return 0;
}
-static int ocp_print_C9_log_json(struct telemetry_str_log_format *log_data,__u8 *log_data_buf)
+static int ocp_print_C9_log_json(struct telemetry_str_log_format *log_data, __u8 *log_data_buf)
{
struct json_object *root = json_create_object();
- struct json_object *stat_table = json_create_object();
- struct json_object *eve_table = json_create_object();
- struct json_object *vu_eve_table = json_create_object();
- struct json_object *entry = json_create_object();
char res_arr[48];
char *res = res_arr;
char guid_buf[C9_GUID_LENGTH];
char *guid = guid_buf;
char fifo_arr[16];
char *fifo = fifo_arr;
+ char buf[128];
//calculating the index value for array
__le64 stat_id_index = (log_data->sitsz * 4) / 16;
__le64 eve_id_index = (log_data->estsz * 4) / 16;
__le64 vu_eve_index = (log_data->vu_eve_st_sz * 4) / 16;
__le64 ascii_table_index = (log_data->asctsz * 4);
//Calculating the offset for dynamic fields.
- __le64 stat_id_str_table_ofst = C9_TELEMETRY_STR_LOG_SIST_OFST + (log_data->sitsz * 4);
- __le64 event_str_table_ofst = stat_id_str_table_ofst + (log_data->estsz * 4);
- __le64 vu_event_str_table_ofst = event_str_table_ofst + (log_data->vu_eve_st_sz * 4);
- __le64 ascii_table_ofst = vu_event_str_table_ofst + (log_data->asctsz * 4);
+ __le64 stat_id_str_table_ofst = log_data->sits * 4;
+ __le64 event_str_table_ofst = log_data->ests * 4;
+ __le64 vu_event_str_table_ofst = log_data->vu_eve_sts * 4;
+ __le64 ascii_table_ofst = log_data->ascts * 4;
struct statistics_id_str_table_entry stat_id_str_table_arr[stat_id_index];
struct event_id_str_table_entry event_id_str_table_arr[eve_id_index];
struct vu_event_id_str_table_entry vu_event_id_str_table_arr[vu_eve_index];
@@ -2982,74 +3482,117 @@ static int ocp_print_C9_log_json(struct telemetry_str_log_format *log_data,__u8
for (j = 0; j < 48; j++)
res += sprintf(res, "%d", log_data->reserved3[j]);
json_object_add_value_string(root, "Reserved", res_arr);
-
- memcpy(stat_id_str_table_arr, (__u8*)log_data_buf + stat_id_str_table_ofst, (log_data->sitsz * 4));
- memcpy(event_id_str_table_arr, (__u8*)log_data_buf + event_str_table_ofst, (log_data->estsz * 4));
- memcpy(vu_event_id_str_table_arr, (__u8*)log_data_buf + vu_event_str_table_ofst, (log_data->vu_eve_st_sz * 4));
- memcpy(ascii_table_info_arr, (__u8*)log_data_buf + ascii_table_ofst, (log_data->asctsz * 4));
-
- for (j = 0; j < stat_id_index; j++){
- json_object_add_value_int(entry, "Vendor Specific Statistic Identifier", le16_to_cpu(stat_id_str_table_arr[j].vs_si));
- json_object_add_value_int(entry, "Reserved", le64_to_cpu(stat_id_str_table_arr[j].reserved1));
- json_object_add_value_int(entry, "ASCII ID Length", le64_to_cpu(stat_id_str_table_arr[j].ascii_id_len));
- json_object_add_value_int(entry, "ASCII ID offset", le64_to_cpu(stat_id_str_table_arr[j].ascii_id_ofst));
- json_object_add_value_int(entry, "Reserved", le64_to_cpu(stat_id_str_table_arr[j].reserved2));
- json_array_add_value_object(stat_table, entry);
- }
- json_object_add_value_array(root, "Statistics Identifier String Table", stat_table);
-
- for (j = 0; j < eve_id_index; j++){
- json_object_add_value_int(entry, "Debug Event Class", le16_to_cpu(event_id_str_table_arr[j].deb_eve_class));
- json_object_add_value_int(entry, "Event Identifier", le16_to_cpu(event_id_str_table_arr[j].ei));
- json_object_add_value_int(entry, "ASCII ID Length", le64_to_cpu(event_id_str_table_arr[j].ascii_id_len));
- json_object_add_value_int(entry, "ASCII ID offset", le64_to_cpu(event_id_str_table_arr[j].ascii_id_ofst));
- json_object_add_value_int(entry, "Reserved", le64_to_cpu(event_id_str_table_arr[j].reserved2));
- json_array_add_value_object(eve_table, entry);
- }
- json_object_add_value_array(root, "Event Identifier String Table Entry", eve_table);
-
- for (j = 0; j < vu_eve_index; j++){
- json_object_add_value_int(entry, "Debug Event Class", le16_to_cpu(vu_event_id_str_table_arr[j].deb_eve_class));
- json_object_add_value_int(entry, "VU Event Identifier", le16_to_cpu(vu_event_id_str_table_arr[j].vu_ei));
- json_object_add_value_int(entry, "ASCII ID Length", le64_to_cpu(vu_event_id_str_table_arr[j].ascii_id_len));
- json_object_add_value_int(entry, "ASCII ID offset", le64_to_cpu(vu_event_id_str_table_arr[j].ascii_id_ofst));
- json_object_add_value_int(entry, "Reserved", le64_to_cpu(vu_event_id_str_table_arr[j].reserved));
- json_array_add_value_object(vu_eve_table, entry);
- }
- json_object_add_value_array(root, "VU Event Identifier String Table Entry", vu_eve_table);
-
- memset((void *)ascii, 0, ascii_table_index);
- for (j = 0; j < ascii_table_index; j++)
- ascii += sprintf(ascii, "%c", ascii_table_info_arr[j]);
- json_object_add_value_string(root, "ASCII Table", ascii_buf);
+
+ if (log_data->sitsz != 0) {
+
+ memcpy(stat_id_str_table_arr,
+ (__u8 *)log_data_buf + stat_id_str_table_ofst,
+ (log_data->sitsz * 4));
+ struct json_object *stat_table = json_create_object();
+
+ for (j = 0; j < stat_id_index; j++) {
+ struct json_object *entry = json_create_object();
+
+ json_object_add_value_uint(entry, "Vendor Specific Statistic Identifier",
+ le16_to_cpu(stat_id_str_table_arr[j].vs_si));
+ json_object_add_value_uint(entry, "Reserved",
+ le64_to_cpu(stat_id_str_table_arr[j].reserved1));
+ json_object_add_value_uint(entry, "ASCII ID Length",
+ le64_to_cpu(stat_id_str_table_arr[j].ascii_id_len));
+ json_object_add_value_uint(entry, "ASCII ID offset",
+ le64_to_cpu(stat_id_str_table_arr[j].ascii_id_ofst));
+ json_object_add_value_uint(entry, "Reserved2",
+ le64_to_cpu(stat_id_str_table_arr[j].reserved2));
+ sprintf(buf, "Statistics Identifier String Table %d", j);
+ json_object_add_value_object(stat_table, buf, entry);
+ }
+
+ json_object_add_value_object(root,
+ "Statistics Identifier String Table", stat_table);
+ }
+
+ if (log_data->estsz != 0) {
+ struct json_object *eve_table = json_create_object();
+
+ memcpy(event_id_str_table_arr,
+ (__u8 *)log_data_buf + event_str_table_ofst,
+ (log_data->estsz * 4));
+ for (j = 0; j < eve_id_index; j++) {
+ struct json_object *entry = json_create_object();
+
+ json_object_add_value_int(entry, "Debug Event Class",
+ le16_to_cpu(event_id_str_table_arr[j].deb_eve_class));
+ json_object_add_value_int(entry, "Event Identifier",
+ le16_to_cpu(event_id_str_table_arr[j].ei));
+ json_object_add_value_int(entry, "ASCII ID Length",
+ le64_to_cpu(event_id_str_table_arr[j].ascii_id_len));
+ json_object_add_value_int(entry, "ASCII ID offset",
+ le64_to_cpu(event_id_str_table_arr[j].ascii_id_ofst));
+ json_object_add_value_int(entry, "Reserved",
+ le64_to_cpu(event_id_str_table_arr[j].reserved2));
+ sprintf(buf, "Event Identifier String Table Entry %d", j);
+ json_object_add_value_object(eve_table, buf, entry);
+ }
+ json_object_add_value_object(root,
+ "Event Identifier String Table Entry",
+ eve_table);
+ }
+
+ if (log_data->vu_eve_st_sz != 0) {
+ struct json_object *vu_eve_table = json_create_object();
+
+ memcpy(vu_event_id_str_table_arr,
+ (__u8 *)log_data_buf + vu_event_str_table_ofst,
+ (log_data->vu_eve_st_sz * 4));
+ for (j = 0; j < vu_eve_index; j++) {
+ struct json_object *entry = json_create_object();
+
+ json_object_add_value_int(entry, "Debug Event Class",
+ le16_to_cpu(vu_event_id_str_table_arr[j].deb_eve_class));
+ json_object_add_value_int(entry, "VU Event Identifier",
+ le16_to_cpu(vu_event_id_str_table_arr[j].vu_ei));
+ json_object_add_value_int(entry, "ASCII ID Length",
+ le64_to_cpu(vu_event_id_str_table_arr[j].ascii_id_len));
+ json_object_add_value_int(entry, "ASCII ID offset",
+ le64_to_cpu(vu_event_id_str_table_arr[j].ascii_id_ofst));
+ json_object_add_value_int(entry, "Reserved",
+ le64_to_cpu(vu_event_id_str_table_arr[j].reserved));
+ sprintf(buf, "VU Event Identifier String Table Entry %d", j);
+ json_object_add_value_object(vu_eve_table, buf, entry);
+ }
+ json_object_add_value_object(root,
+ "VU Event Identifier String Table Entry",
+ vu_eve_table);
+ }
+
+ if (log_data->asctsz != 0) {
+ memcpy(ascii_table_info_arr,
+ (__u8 *)log_data_buf + ascii_table_ofst,
+ (log_data->asctsz * 4));
+ memset((void *)ascii, 0, ascii_table_index);
+ for (j = 0; j < ascii_table_index; j++)
+ ascii += sprintf(ascii, "%c", ascii_table_info_arr[j]);
+ json_object_add_value_string(root, "ASCII Table", ascii_buf);
+ }
json_print_object(root, NULL);
printf("\n");
json_free_object(root);
- json_free_object(stat_table);
- json_free_object(eve_table);
- json_free_object(vu_eve_table);
return 0;
}
-static void ocp_print_c9_log_binary(__u8 *log_data_buf,int total_log_page_size)
+static void ocp_print_c9_log_binary(__u8 *log_data_buf, int total_log_page_size)
{
return d_raw((unsigned char *)log_data_buf, total_log_page_size);
}
static int get_c9_log_page(struct nvme_dev *dev, char *format)
{
+
int ret = 0;
- __u8 *header_data;
- struct telemetry_str_log_format *log_data;
- enum nvme_print_flags fmt;
- __u8 *full_log_buf_data = NULL;
- __le64 stat_id_str_table_ofst = 0;
- __le64 event_str_table_ofst = 0;
- __le64 vu_event_str_table_ofst = 0;
- __le64 ascii_table_ofst = 0;
- __le64 total_log_page_sz = 0;
+
+ nvme_print_flags_t fmt;
ret = validate_output_format(format, &fmt);
if (ret < 0) {
@@ -3057,80 +3600,320 @@ static int get_c9_log_page(struct nvme_dev *dev, char *format)
return ret;
}
- header_data = (__u8 *)malloc(sizeof(__u8) * C9_TELEMETRY_STR_LOG_LEN);
- if (!header_data) {
+ get_c9_log_page_data(dev, 1, 0);
+
+ if (!ret) {
+ switch (fmt) {
+ case NORMAL:
+ ocp_print_C9_log_normal(log_data, pC9_string_buffer);
+ break;
+ case JSON:
+ ocp_print_C9_log_json(log_data, pC9_string_buffer);
+ break;
+ case BINARY:
+ ocp_print_c9_log_binary(pC9_string_buffer, total_log_page_sz);
+ break;
+ default:
+ fprintf(stderr, "unhandled output format\n");
+ break;
+ }
+ } else
+ fprintf(stderr, "ERROR : OCP : Unable to read C9 data from buffer\n");
+ free(header_data);
+ return ret;
+}
+
+static int ocp_telemetry_str_log_format(int argc, char **argv, struct command *cmd,
+ struct plugin *plugin)
+{
+ struct nvme_dev *dev;
+ int ret = 0;
+ const char *desc = "Retrieve telemetry string log format";
+
+ struct config {
+ char *output_format;
+ };
+
+ struct config cfg = {
+ .output_format = "normal",
+ };
+
+ OPT_ARGS(opts) = {
+ OPT_FMT("output-format", 'o', &cfg.output_format, "output Format: normal|json"),
+ OPT_END()
+ };
+
+ ret = parse_and_open(&dev, argc, argv, desc, opts);
+ if (ret)
+ return ret;
+
+ ret = get_c9_log_page(dev, cfg.output_format);
+ if (ret)
+ fprintf(stderr, "ERROR : OCP : Failure reading the C9 Log Page, ret = %d\n", ret);
+
+ dev_close(dev);
+
+ return ret;
+}
+
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////////
+/// TCG Configuration Log Page (LID : C7h)
+
+/* C7 TCG Configuration Log Page */
+#define C7_GUID_LENGTH 16
+#define C7_TCG_CONFIGURATION_LEN 512
+#define C7_TCG_CONFIGURATION_OPCODE 0xC7
+#define C7_TCG_CONFIGURATION_LOG_VERSION 0x1
+
+static __u8 tcg_configuration_guid[C7_GUID_LENGTH] = {
+ 0x06, 0x40, 0x24, 0xBD,
+ 0x7E, 0xE0, 0xE6, 0x83,
+ 0xC0, 0x47, 0x54, 0xFA,
+ 0x9D, 0x2A, 0xE0, 0x54
+};
+
+/*
+ * struct tcg_configuration_log - TCG Configuration Log Page Structure
+ * @state: state
+ * @rsvd1: Reserved1
+ * @locking_sp_act_count: Locking SP Activation Count
+ * @type_rev_count: Tper Revert Count
+ * @locking_sp_rev_count: Locking SP Revert Count.
+ * @no_of_locking_obj: Number of Locking Objects
+ * @no_of_single_um_locking_obj: Number of Single User Mode Locking Objects
+ * @no_of_range_prov_locking_obj: Number of Range Provisioned Locking Objects
+ * @no_of_ns_prov_locking_obj: Number of Namespace Provisioned Locking Objects
+ * @no_of_read_lock_locking_obj: Number of Read Locked Locking Objects
+ * @no_of_write_lock_locking_obj: Number of Write Locked Locking Objects
+ * @no_of_read_unlock_locking_obj: Number of Read Unlocked Locking Objects
+ * @no_of_read_unlock_locking_obj: Number of Write Unlocked Locking Objects
+ * @rsvd2: Reserved2
+ * @sid_auth_try_count: SID Authentication Try Count
+ * @sid_auth_try_limit: SID Authentication Try Limit
+ * @pro_tcg_rc: Programmatic TCG Reset Count
+ * @pro_rlc: Programmatic Reset Lock Count
+ * @tcg_ec: TCG Error Count
+ * @rsvd3: Reserved3
+ * @log_page_version: Log Page Version
+ */
+struct __packed tcg_configuration_log {
+ __u8 state;
+ __u8 rsvd1[3];
+ __u8 locking_sp_act_count;
+ __u8 type_rev_count;
+ __u8 locking_sp_rev_count;
+ __u8 no_of_locking_obj;
+ __u8 no_of_single_um_locking_obj;
+ __u8 no_of_range_prov_locking_obj;
+ __u8 no_of_ns_prov_locking_obj;
+ __u8 no_of_read_lock_locking_obj;
+ __u8 no_of_write_lock_locking_obj;
+ __u8 no_of_read_unlock_locking_obj;
+ __u8 no_of_write_unlock_locking_obj;
+ __u8 rsvd2;
+ __u32 sid_auth_try_count;
+ __u32 sid_auth_try_limit;
+ __u32 pro_tcg_rc;
+ __u32 pro_rlc;
+ __u32 tcg_ec;
+ __u8 rsvd3[458];
+ __le16 log_page_version;
+ __u8 log_page_guid[C7_GUID_LENGTH];
+
+};
+
+/* Function declaration for TCG Configuration log page (LID:C7h) */
+static int ocp_tcg_configuration_log(int argc, char **argv, struct command *cmd,
+ struct plugin *plugin);
+
+static int ocp_print_C7_log_normal(struct nvme_dev *dev,
+ struct tcg_configuration_log *log_data)
+{
+ int j;
+
+ printf("TCG Configuration C7 Log Page Data-\n");
+
+ printf(" State : 0x%x\n", log_data->state);
+ printf(" Reserved1 : 0x");
+ for (j = 0; j < 3; j++)
+ printf("%d", log_data->rsvd1[j]);
+ printf("\n");
+ printf(" Locking SP Activation Count : 0x%x\n", log_data->locking_sp_act_count);
+ printf(" Tper Revert Count : 0x%x\n", log_data->type_rev_count);
+ printf(" Locking SP Revert Count : 0x%x\n", log_data->locking_sp_rev_count);
+ printf(" Number of Locking Objects : 0x%x\n", log_data->no_of_locking_obj);
+ printf(" Number of Single User Mode Locking Objects : 0x%x\n", log_data->no_of_single_um_locking_obj);
+ printf(" Number of Range Provisioned Locking Objects : 0x%x\n", log_data->no_of_range_prov_locking_obj);
+ printf(" Number of Namespace Provisioned Locking Objects : 0x%x\n", log_data->no_of_ns_prov_locking_obj);
+ printf(" Number of Read Locked Locking Objects : 0x%x\n", log_data->no_of_read_lock_locking_obj);
+ printf(" Number of Write Locked Locking Objects : 0x%x\n", log_data->no_of_write_lock_locking_obj);
+ printf(" Number of Read Unlocked Locking Objects : 0x%x\n", log_data->no_of_read_unlock_locking_obj);
+ printf(" Number of Write Unlocked Locking Objects : 0x%x\n", log_data->no_of_write_unlock_locking_obj);
+ printf(" Reserved2 : 0x%x\n", log_data->rsvd2);
+
+ printf(" SID Authentication Try Count : 0x%x\n", le32_to_cpu(log_data->sid_auth_try_count));
+ printf(" SID Authentication Try Limit : 0x%x\n", le32_to_cpu(log_data->sid_auth_try_limit));
+ printf(" Programmatic TCG Reset Count : 0x%x\n", le32_to_cpu(log_data->pro_tcg_rc));
+ printf(" Programmatic Reset Lock Count : 0x%x\n", le32_to_cpu(log_data->pro_rlc));
+ printf(" TCG Error Count : 0x%x\n", le32_to_cpu(log_data->tcg_ec));
+
+ printf(" Reserved3 : 0x");
+ for (j = 0; j < 458; j++)
+ printf("%d", log_data->rsvd3[j]);
+ printf("\n");
+
+ printf(" Log Page Version : 0x%x\n", le16_to_cpu(log_data->log_page_version));
+ printf(" Log page GUID : 0x");
+ for (j = C7_GUID_LENGTH - 1; j >= 0; j--)
+ printf("%x", log_data->log_page_guid[j]);
+ printf("\n");
+
+ return 0;
+}
+
+static void ocp_print_C7_log_json(struct tcg_configuration_log *log_data)
+{
+ int j;
+ struct json_object *root;
+ char guid_buf[C7_GUID_LENGTH];
+ char *guid = guid_buf;
+ char res_arr[458];
+ char *res = res_arr;
+
+ root = json_create_object();
+
+ json_object_add_value_int(root, "State", le16_to_cpu(log_data->state));
+ memset((__u8 *)res, 0, 3);
+ for (j = 0; j < 3; j++)
+ res += sprintf(res, "%d", log_data->rsvd1[j]);
+ json_object_add_value_string(root, "Reserved1", res_arr);
+ json_object_add_value_int(root, "Locking SP Activation Count", le16_to_cpu(log_data->locking_sp_act_count));
+ json_object_add_value_int(root, "Tper Revert Count", le16_to_cpu(log_data->locking_sp_rev_count));
+ json_object_add_value_int(root, "Number of Locking Objects", le16_to_cpu(log_data->no_of_locking_obj));
+ json_object_add_value_int(root, "Number of Single User Mode Locking Objects", le16_to_cpu(log_data->no_of_single_um_locking_obj));
+ json_object_add_value_int(root, "Number of Range Provisioned Locking Objects", le16_to_cpu(log_data->no_of_range_prov_locking_obj));
+ json_object_add_value_int(root, "Number of Namespace Provisioned Locking Objects", le16_to_cpu(log_data->no_of_ns_prov_locking_obj));
+ json_object_add_value_int(root, "Number of Read Locked Locking Objects", le16_to_cpu(log_data->no_of_read_lock_locking_obj));
+ json_object_add_value_int(root, "Number of Write Locked Locking Objects", le16_to_cpu(log_data->no_of_write_lock_locking_obj));
+ json_object_add_value_int(root, "Number of Read Unlocked Locking Objects", le16_to_cpu(log_data->no_of_read_unlock_locking_obj));
+ json_object_add_value_int(root, "Number of Write Unlocked Locking Objects", le16_to_cpu(log_data->no_of_write_unlock_locking_obj));
+ json_object_add_value_int(root, "Reserved2", le16_to_cpu(log_data->rsvd2));
+
+ json_object_add_value_int(root, "SID Authentication Try Count", le16_to_cpu(log_data->sid_auth_try_count));
+ json_object_add_value_int(root, "SID Authentication Try Limit", le16_to_cpu(log_data->sid_auth_try_limit));
+ json_object_add_value_int(root, "Programmatic TCG Reset Count", le16_to_cpu(log_data->pro_tcg_rc));
+ json_object_add_value_int(root, "Programmatic Reset Lock Count", le16_to_cpu(log_data->pro_rlc));
+ json_object_add_value_int(root, "TCG Error Count", le16_to_cpu(log_data->tcg_ec));
+
+ memset((__u8 *)res, 0, 458);
+ for (j = 0; j < 458; j++)
+ res += sprintf(res, "%d", log_data->rsvd3[j]);
+ json_object_add_value_string(root, "Reserved3", res_arr);
+
+ json_object_add_value_int(root, "Log Page Version", le16_to_cpu(log_data->log_page_version));
+
+ memset((void *)guid, 0, C7_GUID_LENGTH);
+ for (j = C7_GUID_LENGTH - 1; j >= 0; j--)
+ guid += sprintf(guid, "%02x", log_data->log_page_guid[j]);
+ json_object_add_value_string(root, "Log page GUID", guid_buf);
+
+ json_print_object(root, NULL);
+ printf("\n");
+
+ json_free_object(root);
+}
+
+static void ocp_print_c7_log_binary(struct tcg_configuration_log *log_data)
+{
+ return d_raw((unsigned char *)log_data, sizeof(*log_data));
+}
+
+static int get_c7_log_page(struct nvme_dev *dev, char *format)
+{
+ nvme_print_flags_t fmt;
+ int ret;
+ __u8 *data;
+ int i;
+ struct tcg_configuration_log *log_data;
+ int j;
+
+ ret = validate_output_format(format, &fmt);
+ if (ret < 0) {
+ fprintf(stderr, "ERROR : OCP : invalid output format\n");
+ return ret;
+ }
+
+ data = (__u8 *)malloc(sizeof(__u8) * C7_TCG_CONFIGURATION_LEN);
+ if (!data) {
fprintf(stderr, "ERROR : OCP : malloc : %s\n", strerror(errno));
return -1;
}
- memset(header_data, 0, sizeof(__u8) * C9_TELEMETRY_STR_LOG_LEN);
-
- ret = nvme_get_log_simple(dev_fd(dev), C9_TELEMETRY_STRING_LOG_ENABLE_OPCODE,
- C9_TELEMETRY_STR_LOG_LEN, header_data);
+ memset(data, 0, sizeof(__u8) * C7_TCG_CONFIGURATION_LEN);
+ ret = nvme_get_log_simple(dev_fd(dev), C7_TCG_CONFIGURATION_OPCODE,
+ C7_TCG_CONFIGURATION_LEN, data);
if (!ret) {
- log_data = (struct telemetry_str_log_format *)header_data;
- printf("Statistics Identifier String Table Size = %lld\n",log_data->sitsz);
- printf("Event String Table Size = %lld\n",log_data->estsz);
- printf("VU Event String Table Size = %lld\n",log_data->vu_eve_st_sz);
- printf("ASCII Table Size = %lld\n",log_data->asctsz);
+ log_data = (struct tcg_configuration_log *)data;
- //Calculating the offset for dynamic fields.
- stat_id_str_table_ofst = C9_TELEMETRY_STR_LOG_SIST_OFST + (log_data->sitsz * 4);
- event_str_table_ofst = stat_id_str_table_ofst + (log_data->estsz * 4);
- vu_event_str_table_ofst = event_str_table_ofst + (log_data->vu_eve_st_sz * 4);
- ascii_table_ofst = vu_event_str_table_ofst + (log_data->asctsz * 4);
- total_log_page_sz = stat_id_str_table_ofst + event_str_table_ofst + vu_event_str_table_ofst + ascii_table_ofst;
-
- printf("stat_id_str_table_ofst = %lld\n",stat_id_str_table_ofst);
- printf("event_str_table_ofst = %lld\n",event_str_table_ofst);
- printf("vu_event_str_table_ofst = %lld\n",vu_event_str_table_ofst);
- printf("ascii_table_ofst = %lld\n",ascii_table_ofst);
- printf("total_log_page_sz = %lld\n",total_log_page_sz);
-
- full_log_buf_data = (__u8 *)malloc(sizeof(__u8) * total_log_page_sz);
- if (!full_log_buf_data) {
- fprintf(stderr, "ERROR : OCP : malloc : %s\n", strerror(errno));
- return -1;
+ /* check log page version */
+ if (log_data->log_page_version != C7_TCG_CONFIGURATION_LOG_VERSION) {
+ fprintf(stderr, "ERROR : OCP : invalid TCG Configuration Log Page version\n");
+ ret = -1;
+ goto out;
}
- memset(full_log_buf_data, 0, sizeof(__u8) * total_log_page_sz);
- ret = nvme_get_log_simple(dev_fd(dev), C9_TELEMETRY_STRING_LOG_ENABLE_OPCODE,
- total_log_page_sz, full_log_buf_data);
+ /*
+ * check log page guid
+ * Verify GUID matches
+ */
+ for (i = 0; i < 16; i++) {
+ if (tcg_configuration_guid[i] != log_data->log_page_guid[i]) {
+ fprintf(stderr, "ERROR : OCP : Unknown GUID in C7 Log Page data\n");
+ fprintf(stderr, "ERROR : OCP : Expected GUID: 0x");
+ for (j = 0; j < 16; j++)
+ fprintf(stderr, "%x", tcg_configuration_guid[j]);
+ fprintf(stderr, "\nERROR : OCP : Actual GUID: 0x");
+ for (j = 0; j < 16; j++)
+ fprintf(stderr, "%x", log_data->log_page_guid[j]);
+ fprintf(stderr, "\n");
- if (!ret) {
- switch (fmt) {
- case NORMAL:
- ocp_print_C9_log_normal(log_data,full_log_buf_data);
- break;
- case JSON:
- ocp_print_C9_log_json(log_data,full_log_buf_data);
- break;
- case BINARY:
- ocp_print_c9_log_binary(full_log_buf_data,total_log_page_sz);
- break;
- default:
- fprintf(stderr, "unhandled output format\n");
- break;
+ ret = -1;
+ goto out;
}
- } else{
- fprintf(stderr, "ERROR : OCP : Unable to read C9 data from buffer\n");
+ }
+
+ switch (fmt) {
+ case NORMAL:
+ ocp_print_C7_log_normal(dev, log_data);
+ break;
+ case JSON:
+ ocp_print_C7_log_json(log_data);
+ break;
+ case BINARY:
+ ocp_print_c7_log_binary(log_data);
+ break;
+ default:
+ break;
}
} else {
- fprintf(stderr, "ERROR : OCP : Unable to read C9 data from buffer\n");
+ fprintf(stderr, "ERROR : OCP : Unable to read C7 data from buffer\n");
}
- free(header_data);
- free(full_log_buf_data);
-
+out:
+ free(data);
return ret;
}
-static int ocp_telemetry_str_log_format(int argc, char **argv, struct command *cmd,
- struct plugin *plugin)
+
+static int ocp_tcg_configuration_log(int argc, char **argv, struct command *cmd,
+ struct plugin *plugin)
{
+ const char *desc = "Retrieve TCG Configuration Log Page Data";
struct nvme_dev *dev;
int ret = 0;
- const char *desc = "Retrieve telemetry string log format";
struct config {
char *output_format;
@@ -3149,12 +3932,11 @@ static int ocp_telemetry_str_log_format(int argc, char **argv, struct command *c
if (ret)
return ret;
- ret = get_c9_log_page(dev, cfg.output_format);
+ ret = get_c7_log_page(dev, cfg.output_format);
if (ret)
- fprintf(stderr, "ERROR : OCP : Failure reading the C9 Log Page, ret = %d\n", ret);
+ fprintf(stderr, "ERROR : OCP : Failure reading the C7 Log Page, ret = %d\n", ret);
dev_close(dev);
-
return ret;
}
@@ -3187,3 +3969,177 @@ static int fw_activation_history_log(int argc, char **argv, struct command *cmd,
{
return ocp_fw_activation_history_log(argc, argv, cmd, plugin);
}
+
+static int error_injection_get(struct nvme_dev *dev, const __u8 sel, bool uuid)
+{
+ struct erri_get_cq_entry cq_entry;
+ int err;
+ int i;
+ const __u8 fid = 0xc0;
+
+ _cleanup_free_ struct erri_entry *entry = NULL;
+
+ struct nvme_get_features_args args = {
+ .result = (__u32 *)&cq_entry,
+ .data = entry,
+ .args_size = sizeof(args),
+ .fd = dev_fd(dev),
+ .timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
+ .sel = sel,
+ .data_len = sizeof(*entry) * ERRI_ENTRIES_MAX,
+ .fid = fid,
+ };
+
+ if (uuid) {
+ /* OCP 2.0 requires UUID index support */
+ err = ocp_get_uuid_index(dev, &args.uuidx);
+ if (err || !args.uuidx) {
+ nvme_show_error("ERROR: No OCP UUID index found");
+ return err;
+ }
+ }
+
+ entry = nvme_alloc(args.data_len);
+ if (!entry) {
+ nvme_show_error("malloc: %s", strerror(errno));
+ return -errno;
+ }
+
+ err = nvme_cli_get_features(dev, &args);
+ if (!err) {
+ nvme_show_result("Number of Error Injecttions (feature: %#0*x): %#0*x (%s: %d)",
+ fid ? 4 : 2, fid, cq_entry.nume ? 10 : 8, cq_entry.nume,
+ nvme_select_to_string(sel), cq_entry.nume);
+ if (sel == NVME_GET_FEATURES_SEL_SUPPORTED)
+ nvme_show_select_result(fid, *args.result);
+ for (i = 0; i < cq_entry.nume; i++) {
+ printf("Entry: %d, Flags: %x (%s%s), Type: %x (%s), NRTDP: %d\n", i,
+ entry->flags, entry->enable ? "Enabled" : "Disabled",
+ entry->single ? ", Single instance" : "", entry->type,
+ erri_type_to_string(entry->type), entry->nrtdp);
+ }
+ } else {
+ nvme_show_error("Could not get feature: %#0*x.", fid ? 4 : 2, fid);
+ }
+
+ return err;
+}
+
+static int get_error_injection(int argc, char **argv, struct command *cmd, struct plugin *plugin)
+{
+ const char *desc = "Return set of error injection";
+ int err;
+ struct config {
+ __u8 sel;
+ };
+ struct config cfg = { 0 };
+
+ _cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
+
+ OPT_ARGS(opts) = {
+ OPT_BYTE("sel", 's', &cfg.sel, sel),
+ OPT_FLAG("no-uuid", 'n', NULL, no_uuid),
+ OPT_END()
+ };
+
+ err = parse_and_open(&dev, argc, argv, desc, opts);
+ if (err)
+ return err;
+
+ return error_injection_get(dev, cfg.sel, !argconfig_parse_seen(opts, "no-uuid"));
+}
+
+static int error_injection_set(struct nvme_dev *dev, struct erri_config *cfg, bool uuid)
+{
+ int err;
+ __u32 result;
+ struct nvme_set_features_args args = {
+ .args_size = sizeof(args),
+ .fd = dev_fd(dev),
+ .fid = 0xc0,
+ .cdw11 = cfg->number,
+ .data_len = cfg->number * sizeof(struct erri_entry),
+ .timeout = nvme_cfg.timeout,
+ .result = &result,
+ };
+
+ _cleanup_fd_ int ffd = -1;
+
+ _cleanup_free_ struct erri_entry *entry = NULL;
+
+ if (uuid) {
+ /* OCP 2.0 requires UUID index support */
+ err = ocp_get_uuid_index(dev, &args.uuidx);
+ if (err || !args.uuidx) {
+ nvme_show_error("ERROR: No OCP UUID index found");
+ return err;
+ }
+ }
+
+ entry = nvme_alloc(args.data_len);
+ if (!entry) {
+ nvme_show_error("malloc: %s", strerror(errno));
+ return -errno;
+ }
+
+ if (cfg->file && strlen(cfg->file)) {
+ ffd = open(cfg->file, O_RDONLY);
+ if (ffd < 0) {
+ nvme_show_error("Failed to open file %s: %s", cfg->file, strerror(errno));
+ return -EINVAL;
+ }
+ err = read(ffd, entry, args.data_len);
+ if (err < 0) {
+ nvme_show_error("failed to read data buffer from input file: %s",
+ strerror(errno));
+ return -errno;
+ }
+ } else {
+ entry->enable = 1;
+ entry->single = 1;
+ entry->type = cfg->type;
+ entry->nrtdp = cfg->nrtdp;
+ }
+
+ args.data = entry;
+
+ err = nvme_set_features(&args);
+ if (err) {
+ if (err < 0)
+ nvme_show_error("set-error-injection: %s", nvme_strerror(errno));
+ else if (err > 0)
+ nvme_show_status(err);
+ return err;
+ }
+
+ printf("set-error-injection, data: %s, number: %d, uuid: %d, type: %d, nrtdp: %d\n",
+ cfg->file, cfg->number, args.uuidx, cfg->type, cfg->nrtdp);
+ if (args.data)
+ d(args.data, args.data_len, 16, 1);
+
+ return 0;
+}
+
+static int set_error_injection(int argc, char **argv, struct command *cmd, struct plugin *plugin)
+{
+ const char *desc = "Inject error conditions";
+ int err;
+ struct erri_config cfg = {
+ .number = 1,
+ };
+
+ _cleanup_nvme_dev_ struct nvme_dev *dev = NULL;
+
+ NVME_ARGS(opts,
+ OPT_FILE("data", 'd', &cfg.file, data),
+ OPT_BYTE("number", 'n', &cfg.number, number),
+ OPT_FLAG("no-uuid", 'N', NULL, no_uuid),
+ OPT_SHRT("type", 't', &cfg.type, type),
+ OPT_SHRT("nrtdp", 'r', &cfg.nrtdp, nrtdp));
+
+ err = parse_and_open(&dev, argc, argv, desc, opts);
+ if (err)
+ return err;
+
+ return error_injection_set(dev, &cfg, !argconfig_parse_seen(opts, "no-uuid"));
+}
diff --git a/plugins/ocp/ocp-nvme.h b/plugins/ocp/ocp-nvme.h
index 0317ea7..16d929d 100644
--- a/plugins/ocp/ocp-nvme.h
+++ b/plugins/ocp/ocp-nvme.h
@@ -11,9 +11,10 @@
#if !defined(OCP_NVME) || defined(CMD_HEADER_MULTI_READ)
#define OCP_NVME
+#define OCP_PLUGIN_VERSION "2.9.0"
#include "cmd.h"
-PLUGIN(NAME("ocp", "OCP cloud SSD extensions", NVME_VERSION),
+PLUGIN(NAME("ocp", "OCP cloud SSD extensions", OCP_PLUGIN_VERSION),
COMMAND_LIST(
ENTRY("smart-add-log", "Retrieve extended SMART Information", smart_add_log)
ENTRY("latency-monitor-log", "Get Latency Monitor Log Page", ocp_latency_monitor_log)
@@ -26,13 +27,17 @@ PLUGIN(NAME("ocp", "OCP cloud SSD extensions", NVME_VERSION),
ENTRY("unsupported-reqs-log", "Get Unsupported Requirements Log Page", ocp_unsupported_requirements_log)
ENTRY("error-recovery-log", "Retrieve Error Recovery Log Page", ocp_error_recovery_log)
ENTRY("device-capability-log", "Get Device capabilities Requirements Log Page", ocp_device_capabilities_log)
- ENTRY("set-dssd-power-state-feature", "Get Device capabilities Requirements Log Page", set_dssd_power_state_feature)
+ ENTRY("set-dssd-power-state-feature", "Set DSSD Power State feature", set_dssd_power_state_feature)
+ ENTRY("get-dssd-power-state-feature", "Get DSSD Power State feature", get_dssd_power_state_feature)
ENTRY("set-plp-health-check-interval", "Set PLP Health Check Interval", set_plp_health_check_interval)
ENTRY("get-plp-health-check-interval", "Get PLP Health Check Interval", get_plp_health_check_interval)
ENTRY("telemetry-string-log", "Retrieve Telemetry string Log Page", ocp_telemetry_str_log_format)
ENTRY("set-telemetry-profile", "Set Telemetry Profile Feature", ocp_set_telemetry_profile_feature)
ENTRY("set-dssd-async-event-config", "Set DSSD Async Event Config", set_dssd_async_event_config)
ENTRY("get-dssd-async-event-config", "Get DSSD Async Event Config", get_dssd_async_event_config)
+ ENTRY("tcg-configuration-log", "Retrieve TCG Configuration Log Page", ocp_tcg_configuration_log)
+ ENTRY("get-error-injection", "Return set of error injection", get_error_injection)
+ ENTRY("set-error-injection", "Inject error conditions", set_error_injection)
)
);
diff --git a/plugins/ocp/ocp-smart-extended-log.c b/plugins/ocp/ocp-smart-extended-log.c
index 0d8ba81..6a524d3 100644
--- a/plugins/ocp/ocp-smart-extended-log.c
+++ b/plugins/ocp/ocp-smart-extended-log.c
@@ -252,7 +252,7 @@ static void ocp_print_C0_log_json(void *data)
static int get_c0_log_page(int fd, char *format)
{
- enum nvme_print_flags fmt;
+ nvme_print_flags_t fmt;
__u8 *data;
int i;
int ret;
diff --git a/plugins/ocp/ocp-telemetry-decode.c b/plugins/ocp/ocp-telemetry-decode.c
new file mode 100644
index 0000000..11963be
--- /dev/null
+++ b/plugins/ocp/ocp-telemetry-decode.c
@@ -0,0 +1,1566 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) 2024 Western Digital Corporation or its affiliates.
+ *
+ * Authors: Jeff Lien <jeff.lien@wdc.com>,
+ */
+
+#include "common.h"
+#include "nvme.h"
+#include "libnvme.h"
+#include "plugin.h"
+#include "linux/types.h"
+#include "util/types.h"
+#include "nvme-print.h"
+
+#include "ocp-telemetry-decode.h"
+
+
+void print_vu_event_data(__u32 size, __u8 *data)
+{
+ int j;
+ __u16 vu_event_id = *(__u16 *)data;
+
+ printf(" VU Event ID : 0x%02x\n", le16_to_cpu(vu_event_id));
+ printf(" VU Data : 0x");
+ for (j = 2; j < size; j++)
+ printf("%x", data[j]);
+ printf("\n\n");
+}
+
+void print_stats_desc(struct telemetry_stats_desc *stat_desc)
+{
+ int j;
+ /* Get the statistics Identifier string name and data size */
+ __u16 stat_id = stat_desc->id;
+ __u32 stat_data_sz = ((stat_desc->size) * 4);
+
+ printf("Statistics Identifier : 0x%x, %s\n",
+ stat_id, telemetry_stat_id_to_string(stat_id));
+ printf("Statistics info : 0x%x\n", stat_desc->info);
+ printf("NS info : 0x%x\n", stat_desc->ns_info);
+ printf("Statistic Data Size : 0x%x\n", le16_to_cpu(stat_data_sz));
+
+ if (stat_data_sz > 0) {
+ printf("%s : 0x",
+ telemetry_stat_id_to_string(stat_id));
+ for (j = 0; j < stat_data_sz; j++)
+ printf("%02x", stat_desc->data[j]);
+ printf("\n");
+ }
+ printf("\n");
+}
+
+void print_telemetry_fifo_event(__u8 class_type,
+ __u16 id, __u8 size_dw, __u8 *data)
+{
+ int j;
+ const char *class_str = NULL;
+ __u32 size = size_dw * 4;
+ char time_str[40];
+ uint64_t timestamp = 0;
+
+ memset((void *)time_str, '\0', 40);
+
+ if (class_type) {
+ class_str = telemetry_event_class_to_string(class_type);
+ printf("Event Class : %s\n", class_str);
+ }
+
+ switch (class_type) {
+ case TELEMETRY_TIMESTAMP_CLASS:
+ timestamp = (0x0000FFFFFFFFFFFF & le64_to_cpu(*(uint64_t *)data));
+
+ memset((void *)time_str, 0, 9);
+ sprintf((char *)time_str, "%04d:%02d:%02d", (int)(le64_to_cpu(timestamp)/3600),
+ (int)((le64_to_cpu(timestamp%3600)/60)),
+ (int)(le64_to_cpu(timestamp%60)));
+
+ printf(" Event ID : 0x%02x %s\n", id, telemetry_ts_event_to_string(id));
+ printf(" Timestamp : %s\n", time_str);
+ printf(" Size : %d\n", size);
+ if (size > 8) {
+ printf(" VU Data : 0x");
+ for (j = 8; j < size; j++)
+ printf("%02x", data[j]);
+ printf("\n\n");
+ }
+ break;
+
+ case TELEMETRY_PCIE_CLASS:
+ printf(" Event ID : 0x%02x %s\n",
+ id, telemetry_pcie_event_id_to_string(id));
+ printf(" State : 0x%02x %s\n",
+ data[0], telemetry_pcie_state_data_to_string(data[0]));
+ printf(" Speed : 0x%02x %s\n",
+ data[1], telemetry_pcie_speed_data_to_string(data[1]));
+ printf(" Width : 0x%02x %s\n",
+ data[2], telemetry_pcie_width_data_to_string(data[2]));
+ if (size > 4) {
+ printf(" VU Data : ");
+ for (j = 4; j < size; j++)
+ printf("%x", data[j]);
+ printf("\n\n");
+ }
+ break;
+
+ case TELEMETRY_NVME_CLASS:
+ printf(" Event ID : 0x%02x %s\n",
+ id, telemetry_nvme_event_id_to_string(id));
+ if ((id == ADMIN_QUEUE_NONZERO_STATUS) ||
+ (id == IO_QUEUE_NONZERO_STATUS)) {
+ printf(" Cmd Op Code : 0x%02x\n", data[0]);
+ __u16 status = *(__u16 *)&data[1];
+ __u16 cmd_id = *(__u16 *)&data[3];
+ __u16 sq_id = *(__u16 *)&data[5];
+
+ printf(" Status Code : 0x%04x\n", le16_to_cpu(status));
+ printf(" Cmd ID : 0x%04x\n", le16_to_cpu(cmd_id));
+ printf(" SQ ID : 0x%04x\n", le16_to_cpu(sq_id));
+ } else if (id == CC_REGISTER_CHANGED) {
+ __u32 cc_reg_data = *(__u32 *)data;
+
+ printf(" CC Reg Data : 0x%08x\n",
+ le32_to_cpu(cc_reg_data));
+ } else if (id == CSTS_REGISTER_CHANGED) {
+ __u32 csts_reg_data = *(__u32 *)data;
+
+ printf(" CSTS Reg Data : 0x%08x\n",
+ le32_to_cpu(csts_reg_data));
+ }
+ if (size > 8)
+ print_vu_event_data(size, (__u8 *)&data[8]);
+ break;
+
+ case TELEMETRY_RESET_CLASS:
+ printf(" Event ID : 0x%02x %s\n",
+ id, telemetry_reset_event_id_to_string(id));
+ if (size)
+ print_vu_event_data(size, data);
+ break;
+
+ case TELEMETRY_BOOT_SEQ_CLASS:
+ printf(" Event ID : 0x%02x %s\n",
+ id, telemetry_boot_seq_event_id_to_string(id));
+ if (size)
+ print_vu_event_data(size, data);
+ break;
+
+ case TELEMETRY_FW_ASSERT_CLASS:
+ printf(" Event ID : 0x%02x %s\n",
+ id, telemetry_fw_assert_event_id_to_string(id));
+ if (size)
+ print_vu_event_data(size, data);
+ break;
+
+ case TELEMETRY_TEMPERATURE_CLASS:
+ printf(" Event ID : 0x%02x %s\n",
+ id, telemetry_temperature_event_id_to_string(id));
+ if (size)
+ print_vu_event_data(size, data);
+ break;
+
+ case TELEMETRY_MEDIA_DBG_CLASS:
+ printf(" Event ID : 0x%02x %s\n",
+ id, telemetry_media_debug_event_id_to_string(id));
+ if (size)
+ print_vu_event_data(size, data);
+ break;
+
+ case TELEMETRY_MEDIA_WEAR_CLASS:
+ printf(" Event ID : 0x%02x %s\n",
+ id, telemetry_media_debug_event_id_to_string(id));
+ __u32 host_tb_written = *(__u32 *)&data[0];
+ __u32 media_tb_written = *(__u32 *)&data[4];
+ __u32 media_tb_erased = *(__u32 *)&data[8];
+
+ printf(" Host TB Written : 0x%04x\n",
+ le16_to_cpu(host_tb_written));
+ printf(" Media TB Written : 0x%04x\n",
+ le16_to_cpu(media_tb_written));
+ printf(" Media TB Erased : 0x%04x\n",
+ le16_to_cpu(media_tb_erased));
+
+ if (size > 12)
+ print_vu_event_data(size, (__u8 *)&data[12]);
+ break;
+
+ case TELEMETRY_STAT_SNAPSHOT_CLASS:
+ printf(" Statistic ID : 0x%02x %s\n",
+ id, telemetry_stat_id_to_string(id));
+ print_stats_desc((struct telemetry_stats_desc *)data);
+ break;
+
+ default:
+ /*
+ * printf("Unknown Event Class Type\n");
+ * printf("Data : 0x");
+ * for (j = 0; j < size; j++)
+ * printf("%x", data[j]);
+ * printf("\n\n");
+ */
+ break;
+ }
+}
+
+struct statistic_entry statistic_identifiers_map[] = {
+ { 0x00, "Error, this entry does not exist." },
+ { 0x01, "Outstanding Admin Commands" },
+ { 0x02, "Host Write Bandwidth"},
+ { 0x03, "GC Write Bandwidth"},
+ { 0x04, "Active Namespaces"},
+ { 0x05, "Internal Write Workload"},
+ { 0x06, "Internal Read Workload"},
+ { 0x07, "Internal Write Queue Depth"},
+ { 0x08, "Internal Read Queue Depth"},
+ { 0x09, "Pending Trim LBA Count"},
+ { 0x0A, "Host Trim LBA Request Count"},
+ { 0x0B, "Current NVMe Power State"},
+ { 0x0C, "Current DSSD Power State"},
+ { 0x0D, "Program Fail Count"},
+ { 0x0E, "Erase Fail Count"},
+ { 0x0F, "Read Disturb Writes"},
+ { 0x10, "Retention Writes"},
+ { 0x11, "Wear Leveling Writes"},
+ { 0x12, "Read Recovery Writes"},
+ { 0x13, "GC Writes"},
+ { 0x14, "SRAM Correctable Count"},
+ { 0x15, "DRAM Correctable Count"},
+ { 0x16, "SRAM Uncorrectable Count"},
+ { 0x17, "DRAM Uncorrectable Count"},
+ { 0x18, "Data Integrity Error Count"},
+ { 0x19, "Read Retry Error Count"},
+ { 0x1A, "PERST Events Count"},
+ { 0x1B, "Max Die Bad Block"},
+ { 0x1C, "Max NAND Channel Bad Block"},
+ { 0x1D, "Minimum NAND Channel Bad Block"}
+};
+
+struct request_data host_log_page_header[] = {
+ { "LogIdentifier", 1 },
+ { "Reserved1", 4 },
+ { "IEEE OUI Identifier", 3 },
+ { "Telemetry Host-Initiated Data Area 1 Last Block", 2 },
+ { "Telemetry Host-Initiated Data Area 2 Last Block", 2 },
+ { "Telemetry Host-Initiated Data Area 3 Last Block", 2 },
+ { "Reserved2", 2 },
+ { "Telemetry Host-Initiated Data Area 4 Last Block", 4 },
+ { "Reserved3", 360 },
+ { "Telemetry Host-Initiated Scope", 1 },
+ { "Telemetry Host Initiated Generation Number", 1 },
+ { "Telemetry Host-Initiated Data Available", 1 },
+ { "Telemetry Controller-Initiated Data Generation Number", 1 }
+};
+
+struct request_data controller_log_page_header[] = {
+ { "LogIdentifier", 1 },
+ { "Reserved1", 4 },
+ { "IEEE OUI Identifier", 3 },
+ { "Telemetry Host-Initiated Data Area 1 Last Block", 2 },
+ { "Telemetry Host-Initiated Data Area 2 Last Block", 2 },
+ { "Telemetry Host-Initiated Data Area 3 Last Block", 2 },
+ { "Reserved2", 2 },
+ { "Telemetry Host-Initiated Data Area 4 Last Block", 4 },
+ { "Reserved3", 361 },
+ { "Telemetry Controller-Initiated Scope", 1 },
+ { "Telemetry Controller-Initiated Data Available", 1 },
+ { "Telemetry Controller-Initiated Data Generation Number", 1 }
+};
+
+struct request_data reason_identifier[] = {
+ { "Error ID", 64 },
+ { "File ID", 8 },
+ { "Line Number", 2 },
+ { "Valid Flags", 1 },
+ { "Reserved", 21 },
+ { "VU Reason Extension", 32 }
+};
+
+struct request_data ocp_header_in_da1[] = {
+ { "Major Version", 2 },
+ { "Minor Version", 2 },
+ { "Reserved1", 4 },
+ { "Timestamp", 8 },
+ { "Log page GUID", 16 },
+ { "Number Telemetry Profiles Supported", 1 },
+ { "Telemetry Profile Selected", 1 },
+ { "Reserved2", 6 },
+ { "Telemetry String Log Size", 8 },
+ { "Reserved3", 8 },
+ { "Firmware Revision", 8 },
+ { "Reserved4", 32 },
+ { "Data Area 1 Statistic Start", 8 },
+ { "Data Area 1 Statistic Size", 8 },
+ { "Data Area 2 Statistic Start", 8 },
+ { "Data Area 2 Statistic Size", 8 },
+ { "Reserved5", 32 },
+ { "Event FIFO 1 Data Area", 1 },
+ { "Event FIFO 2 Data Area", 1 },
+ { "Event FIFO 3 Data Area", 1 },
+ { "Event FIFO 4 Data Area", 1 },
+ { "Event FIFO 5 Data Area", 1 },
+ { "Event FIFO 6 Data Area", 1 },
+ { "Event FIFO 7 Data Area", 1 },
+ { "Event FIFO 8 Data Area", 1 },
+ { "Event FIFO 9 Data Area", 1 },
+ { "Event FIFO 10 Data Area", 1 },
+ { "Event FIFO 11 Data Area", 1 },
+ { "Event FIFO 12 Data Area", 1 },
+ { "Event FIFO 13 Data Area", 1 },
+ { "Event FIFO 14 Data Area", 1 },
+ { "Event FIFO 15 Data Area", 1 },
+ { "Event FIFO 16 Data Area", 1 },
+ { "Event FIFO 1 Start", 8 },
+ { "Event FIFO 1 Size", 8 },
+ { "Event FIFO 2 Start", 8 },
+ { "Event FIFO 2 Size", 8 },
+ { "Event FIFO 3 Start", 8 },
+ { "Event FIFO 3 Size", 8 },
+ { "Event FIFO 4 Start", 8 },
+ { "Event FIFO 4 Size", 8 },
+ { "Event FIFO 5 Start", 8 },
+ { "Event FIFO 5 Size", 8 },
+ { "Event FIFO 6 Start", 8 },
+ { "Event FIFO 6 Size", 8 },
+ { "Event FIFO 7 Start", 8 },
+ { "Event FIFO 7 Size", 8 },
+ { "Event FIFO 8 Start", 8 },
+ { "Event FIFO 8 Size", 8 },
+ { "Event FIFO 9 Start", 8 },
+ { "Event FIFO 9 Size", 8 },
+ { "Event FIFO 10 Start", 8 },
+ { "Event FIFO 10 Size", 8 },
+ { "Event FIFO 11 Start", 8 },
+ { "Event FIFO 11 Size", 8 },
+ { "Event FIFO 12 Start", 8 },
+ { "Event FIFO 12 Size", 8 },
+ { "Event FIFO 13 Start", 8 },
+ { "Event FIFO 13 Size", 8 },
+ { "Event FIFO 14 Start", 8 },
+ { "Event FIFO 14 Size", 8 },
+ { "Event FIFO 15 Start", 8 },
+ { "Event FIFO 15 Size", 8 },
+ { "Event FIFO 16 Start", 8 },
+ { "Event FIFO 16 Size", 8 },
+ { "Reserved6", 80 }
+};
+
+struct request_data smart[] = {
+ { "Critical Warning", 1 },
+ { "Composite Temperature", 2 },
+ { "Available Spare", 1 },
+ { "Available Spare Threshold", 1 },
+ { "Percentage Used", 1 },
+ { "Reserved1", 26 },
+ { "Data Units Read", 16 },
+ { "Data Units Written", 16 },
+ { "Host Read Commands", 16 },
+ { "Host Write Commands", 16 },
+ { "Controller Busy Time", 16 },
+ { "Power Cycles", 16 },
+ { "Power On Hours", 16 },
+ { "Unsafe Shutdowns", 16 },
+ { "Media and Data Integrity Errors", 16 },
+ { "Number of Error Information Log Entries", 16 },
+ { "Warning Composite Temperature Time", 4 },
+ { "Critical Composite Temperature Time", 4 },
+ { "Temperature Sensor 1", 2 },
+ { "Temperature Sensor 2", 2 },
+ { "Temperature Sensor 3", 2 },
+ { "Temperature Sensor 4", 2 },
+ { "Temperature Sensor 5", 2 },
+ { "Temperature Sensor 6", 2 },
+ { "Temperature Sensor 7", 2 },
+ { "Temperature Sensor 8", 2 },
+ { "Thermal Management Temperature 1 Transition Count", 4 },
+ { "Thermal Management Temperature 2 Transition Count", 4 },
+ { "Total Time for Thermal Management Temperature 1", 4 },
+ { "Total Time for Thermal Management Temperature 2", 4 },
+ { "Reserved2", 280 }
+};
+
+struct request_data smart_extended[] = {
+ { "Physical Media Units Written", 16 },
+ { "Physical Media Units Read", 16 },
+ { "Bad User NAND Blocks Raw Count", 6 },
+ { "Bad User NAND Blocks Normalized Value", 2 },
+ { "Bad System NAND Blocks Raw Count", 6 },
+ { "Bad System NAND Blocks Normalized Value", 2 },
+ { "XOR Recovery Count", 8 },
+ { "Uncorrectable Read Error Count", 8 },
+ { "Soft ECC Error Count", 8 },
+ { "End to End Correction Counts Detected Errors", 4 },
+ { "End to End Correction Counts Corrected Errors", 4 },
+ { "System Data Percent Used", 1 },
+ { "Refresh Counts", 7 },
+ { "Maximum User Data Erase Count", 4 },
+ { "Minimum User Data Erase Count", 4 },
+ { "Number of thermal throttling events", 1 },
+ { "Current Throttling Status", 1 },
+ { "Errata Version Field", 1 },
+ { "Point Version Field", 2 },
+ { "Minor Version Field", 2 },
+ { "Major Version Field", 1 },
+ { "PCIe Correctable Error Count", 8 },
+ { "Incomplete Shutdowns", 4 },
+ { "Reserved1", 4 },
+ { "Percent Free Blocks", 1 },
+ { "Reserved2", 7 },
+ { "Capacitor Health", 2 },
+ { "NVMe Base Errata Version", 1 },
+ { "NVMe Command Set Errata Version", 1 },
+ { "Reserved3", 4 },
+ { "Unaligned IO", 8 },
+ { "Security Version Number", 8 },
+ { "Total NUSE", 8 },
+ { "PLP Start Count", 16 },
+ { "Endurance Estimate", 16 },
+ { "PCIe Link Retraining Count", 8 },
+ { "Power State Change Count", 8 },
+ { "Lowest Permitted Firmware Revision", 8 },
+ { "Reserved4", 278 },
+ { "Log Page Version", 2 },
+ { "Log page GUID", 16 }
+};
+
+void json_add_formatted_u32_str(struct json_object *pobject, const char *msg, unsigned int pdata)
+{
+ char data_str[70] = { 0 };
+
+ sprintf(data_str, "0x%x", pdata);
+ json_object_add_value_string(pobject, msg, data_str);
+}
+
+void json_add_formatted_var_size_str(struct json_object *pobject, const char *msg, __u8 *pdata,
+ unsigned int data_size)
+{
+ char description_str[256] = "";
+ char temp_buffer[3] = { 0 };
+
+ for (size_t i = 0; i < data_size; ++i) {
+ sprintf(temp_buffer, "%02X", pdata[i]);
+ strcat(description_str, temp_buffer);
+ }
+
+ json_object_add_value_string(pobject, msg, description_str);
+}
+
+int get_telemetry_das_offset_and_size(
+ struct nvme_ocp_telemetry_common_header *ptelemetry_common_header,
+ struct nvme_ocp_telemetry_offsets *ptelemetry_das_offset)
+{
+ if (NULL == ptelemetry_common_header || NULL == ptelemetry_das_offset) {
+ nvme_show_error("Invalid input arguments.");
+ return -1;
+ }
+
+ if (ptelemetry_common_header->log_id == NVME_LOG_LID_TELEMETRY_HOST)
+ ptelemetry_das_offset->header_size =
+ sizeof(struct nvme_ocp_telemetry_host_initiated_header);
+ else if (ptelemetry_common_header->log_id == NVME_LOG_LID_TELEMETRY_CTRL)
+ ptelemetry_das_offset->header_size =
+ sizeof(struct nvme_ocp_telemetry_controller_initiated_header);
+ else
+ return -1;
+
+ ptelemetry_das_offset->da1_start_offset = ptelemetry_das_offset->header_size;
+ ptelemetry_das_offset->da1_size = ptelemetry_common_header->da1_last_block *
+ OCP_TELEMETRY_DATA_BLOCK_SIZE;
+
+ ptelemetry_das_offset->da2_start_offset = ptelemetry_das_offset->da1_start_offset +
+ ptelemetry_das_offset->da1_size;
+ ptelemetry_das_offset->da2_size =
+ (ptelemetry_common_header->da2_last_block -
+ ptelemetry_common_header->da1_last_block) * OCP_TELEMETRY_DATA_BLOCK_SIZE;
+
+ ptelemetry_das_offset->da3_start_offset = ptelemetry_das_offset->da2_start_offset +
+ ptelemetry_das_offset->da2_size;
+ ptelemetry_das_offset->da3_size =
+ (ptelemetry_common_header->da3_last_block -
+ ptelemetry_common_header->da2_last_block) * OCP_TELEMETRY_DATA_BLOCK_SIZE;
+
+ ptelemetry_das_offset->da4_start_offset = ptelemetry_das_offset->da3_start_offset +
+ ptelemetry_das_offset->da3_size;
+ ptelemetry_das_offset->da4_size =
+ (ptelemetry_common_header->da4_last_block -
+ ptelemetry_common_header->da3_last_block) * OCP_TELEMETRY_DATA_BLOCK_SIZE;
+
+ return 0;
+}
+
+int get_static_id_ascii_string(int identifier, char *description)
+{
+ if (pstring_buffer == NULL)
+ return -1;
+
+ struct nvme_ocp_telemetry_string_header *pocp_ts_header =
+ (struct nvme_ocp_telemetry_string_header *)pstring_buffer;
+
+ //Calculating the sizes of the tables. Note: Data is present in the form of DWORDS,
+ //So multiplying with sizeof(DWORD)
+ unsigned long long sits_table_size = (pocp_ts_header->sitsz) * SIZE_OF_DWORD;
+
+ //Calculating number of entries present in all 3 tables
+ int sits_entries = (int)sits_table_size /
+ sizeof(struct nvme_ocp_statistics_identifier_string_table);
+
+ for (int sits_entry = 0; sits_entry < sits_entries; sits_entry++) {
+ struct nvme_ocp_statistics_identifier_string_table
+ *peach_statistic_entry =
+ (struct nvme_ocp_statistics_identifier_string_table *)
+ (pstring_buffer + (pocp_ts_header->sits * SIZE_OF_DWORD) +
+ (sits_entry *
+ sizeof(struct nvme_ocp_statistics_identifier_string_table)));
+
+ if (identifier == (int)peach_statistic_entry->vs_statistic_identifier) {
+ char *pdescription = (char *)(pstring_buffer +
+ (pocp_ts_header->ascts * SIZE_OF_DWORD) +
+ (peach_statistic_entry->ascii_id_offset *
+ SIZE_OF_DWORD));
+
+ memcpy(description, pdescription,
+ peach_statistic_entry->ascii_id_length + 1);
+
+ // If ASCII string isn't found, see in our internal Map
+ // for 2.5 Spec defined strings (id < 0x1D).
+ if ((description == NULL) && (identifier < 0x1D))
+ memcpy(description,
+ statistic_identifiers_map[identifier].description,
+ peach_statistic_entry->ascii_id_length + 1);
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+int get_event_id_ascii_string(int identifier, int debug_event_class, char *description)
+{
+ if (pstring_buffer == NULL)
+ return -1;
+
+ struct nvme_ocp_telemetry_string_header *pocp_ts_header =
+ (struct nvme_ocp_telemetry_string_header *)pstring_buffer;
+
+ //Calculating the sizes of the tables. Note: Data is present in the form of DWORDS,
+ //So multiplying with sizeof(DWORD)
+ unsigned long long ests_table_size = (pocp_ts_header->estsz) * SIZE_OF_DWORD;
+
+ //Calculating number of entries present in all 3 tables
+ int ests_entries = (int)ests_table_size / sizeof(struct nvme_ocp_event_string_table);
+
+ for (int ests_entry = 0; ests_entry < ests_entries; ests_entry++) {
+ struct nvme_ocp_event_string_table *peach_event_entry =
+ (struct nvme_ocp_event_string_table *)
+ (pstring_buffer + (pocp_ts_header->ests * SIZE_OF_DWORD) +
+ (ests_entry * sizeof(struct nvme_ocp_event_string_table)));
+
+ if (identifier == (int)peach_event_entry->event_identifier &&
+ debug_event_class == (int)peach_event_entry->debug_event_class) {
+ char *pdescription = (char *)(pstring_buffer +
+ (pocp_ts_header->ascts * SIZE_OF_DWORD) +
+ (peach_event_entry->ascii_id_offset * SIZE_OF_DWORD));
+
+ memcpy(description, pdescription,
+ peach_event_entry->ascii_id_length + 1);
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+int get_vu_event_id_ascii_string(int identifier, int debug_event_class, char *description)
+{
+ if (pstring_buffer == NULL)
+ return -1;
+
+ struct nvme_ocp_telemetry_string_header *pocp_ts_header =
+ (struct nvme_ocp_telemetry_string_header *)pstring_buffer;
+
+ //Calculating the sizes of the tables. Note: Data is present in the form of DWORDS,
+ //So multiplying with sizeof(DWORD)
+ unsigned long long vuests_table_size = (pocp_ts_header->vu_estsz) * SIZE_OF_DWORD;
+
+ //Calculating number of entries present in all 3 tables
+ int vu_ests_entries = (int)vuests_table_size /
+ sizeof(struct nvme_ocp_vu_event_string_table);
+
+ for (int vu_ests_entry = 0; vu_ests_entry < vu_ests_entries; vu_ests_entry++) {
+ struct nvme_ocp_vu_event_string_table *peach_vu_event_entry =
+ (struct nvme_ocp_vu_event_string_table *)
+ (pstring_buffer + (pocp_ts_header->vu_ests * SIZE_OF_DWORD) +
+ (vu_ests_entry * sizeof(struct nvme_ocp_vu_event_string_table)));
+
+ if (identifier == (int)peach_vu_event_entry->vu_event_identifier &&
+ debug_event_class ==
+ (int)peach_vu_event_entry->debug_event_class) {
+ char *pdescription = (char *)(pstring_buffer +
+ (pocp_ts_header->ascts * SIZE_OF_DWORD) +
+ (peach_vu_event_entry->ascii_id_offset * SIZE_OF_DWORD));
+
+ memcpy(description, pdescription,
+ peach_vu_event_entry->ascii_id_length + 1);
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
+int parse_ocp_telemetry_string_log(int event_fifo_num, int identifier, int debug_event_class,
+ enum ocp_telemetry_string_tables string_table, char *description)
+{
+ if (pstring_buffer == NULL)
+ return -1;
+
+ if (event_fifo_num != 0) {
+ struct nvme_ocp_telemetry_string_header *pocp_ts_header =
+ (struct nvme_ocp_telemetry_string_header *)pstring_buffer;
+
+ if (*pocp_ts_header->fifo_ascii_string[event_fifo_num-1] != '\0')
+ memcpy(description, pocp_ts_header->fifo_ascii_string[event_fifo_num-1],
+ 16);
+ else
+ description = "";
+
+ return 0;
+ }
+
+ if (string_table == STATISTICS_IDENTIFIER_STRING)
+ get_static_id_ascii_string(identifier, description);
+ else if (string_table == EVENT_STRING)
+ get_event_id_ascii_string(identifier, debug_event_class, description);
+ else if (string_table == VU_EVENT_STRING)
+ get_vu_event_id_ascii_string(identifier, debug_event_class, description);
+
+ return 0;
+}
+
+void parse_time_stamp_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descriptor,
+ struct json_object *pevent_descriptor_obj, __u8 *pevent_specific_data,
+ struct json_object *pevent_fifos_object, FILE *fp)
+{
+ struct nvme_ocp_time_stamp_dbg_evt_class_format *ptime_stamp_event =
+ (struct nvme_ocp_time_stamp_dbg_evt_class_format *) pevent_specific_data;
+
+ int vu_event_id = (int)ptime_stamp_event->vu_event_identifier;
+
+ unsigned int data_size = ((pevent_descriptor->event_data_size * SIZE_OF_DWORD)-
+ sizeof(struct nvme_ocp_time_stamp_dbg_evt_class_format));
+
+ __u8 *pdata = (__u8 *)ptime_stamp_event +
+ sizeof(struct nvme_ocp_time_stamp_dbg_evt_class_format);
+
+ char description_str[256] = "";
+
+ parse_ocp_telemetry_string_log(0, ptime_stamp_event->vu_event_identifier,
+ pevent_descriptor->debug_event_class_type,
+ VU_EVENT_STRING, description_str);
+
+ if (pevent_fifos_object != NULL) {
+ json_add_formatted_var_size_str(pevent_descriptor_obj, STR_CLASS_SPECIFIC_DATA,
+ ptime_stamp_event->time_stamp, DATA_SIZE_8);
+ json_add_formatted_u32_str(pevent_descriptor_obj, STR_VU_EVENT_ID_STRING,
+ vu_event_id);
+ json_object_add_value_string(pevent_descriptor_obj, STR_VU_EVENT_STRING,
+ description_str);
+ json_add_formatted_var_size_str(pevent_descriptor_obj, STR_VU_DATA, pdata,
+ data_size);
+ } else {
+ if (fp) {
+ print_formatted_var_size_str(STR_CLASS_SPECIFIC_DATA,
+ ptime_stamp_event->time_stamp, DATA_SIZE_8, fp);
+ fprintf(fp, "%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
+ fprintf(fp, "%s: %s\n", STR_VU_EVENT_STRING, description_str);
+ print_formatted_var_size_str(STR_VU_DATA, pdata, data_size, fp);
+ } else {
+ print_formatted_var_size_str(STR_CLASS_SPECIFIC_DATA,
+ ptime_stamp_event->time_stamp, DATA_SIZE_8, fp);
+ printf("%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
+ printf("%s: %s\n", STR_VU_EVENT_STRING, description_str);
+ print_formatted_var_size_str(STR_VU_DATA, pdata, data_size, fp);
+ }
+ }
+}
+
+void parse_pcie_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descriptor,
+ struct json_object *pevent_descriptor_obj, __u8 *pevent_specific_data,
+ struct json_object *pevent_fifos_object, FILE *fp)
+{
+ struct nvme_ocp_pcie_dbg_evt_class_format *ppcie_event =
+ (struct nvme_ocp_pcie_dbg_evt_class_format *) pevent_specific_data;
+ int vu_event_id = (int) ppcie_event->vu_event_identifier;
+ unsigned int data_size = ((pevent_descriptor->event_data_size * SIZE_OF_DWORD) -
+ sizeof(struct nvme_ocp_pcie_dbg_evt_class_format));
+ __u8 *pdata = (__u8 *) ppcie_event + sizeof(struct nvme_ocp_pcie_dbg_evt_class_format);
+ char description_str[256] = "";
+
+ parse_ocp_telemetry_string_log(0, ppcie_event->vu_event_identifier,
+ pevent_descriptor->debug_event_class_type, VU_EVENT_STRING, description_str);
+
+ if (pevent_fifos_object != NULL) {
+ json_add_formatted_var_size_str(pevent_descriptor_obj, STR_CLASS_SPECIFIC_DATA,
+ ppcie_event->pCIeDebugEventData, DATA_SIZE_4);
+ json_add_formatted_u32_str(pevent_descriptor_obj, STR_VU_EVENT_ID_STRING,
+ vu_event_id);
+ json_object_add_value_string(pevent_descriptor_obj, STR_VU_EVENT_STRING,
+ description_str);
+ json_add_formatted_var_size_str(pevent_descriptor_obj, STR_VU_DATA, pdata,
+ data_size);
+ } else {
+ if (fp) {
+ print_formatted_var_size_str(STR_CLASS_SPECIFIC_DATA,
+ ppcie_event->pCIeDebugEventData, DATA_SIZE_4, fp);
+ fprintf(fp, "%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
+ fprintf(fp, "%s: %s\n", STR_VU_EVENT_STRING, description_str);
+ print_formatted_var_size_str(STR_VU_DATA, pdata, data_size, fp);
+ } else {
+ print_formatted_var_size_str(STR_CLASS_SPECIFIC_DATA,
+ ppcie_event->pCIeDebugEventData, DATA_SIZE_4, fp);
+ printf("%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
+ printf("%s: %s\n", STR_VU_EVENT_STRING, description_str);
+ print_formatted_var_size_str(STR_VU_DATA, pdata, data_size, fp);
+ }
+ }
+}
+
+void parse_nvme_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descriptor,
+ struct json_object *pevent_descriptor_obj, __u8 *pevent_specific_data,
+ struct json_object *pevent_fifos_object, FILE *fp)
+{
+ struct nvme_ocp_nvme_dbg_evt_class_format *pnvme_event =
+ (struct nvme_ocp_nvme_dbg_evt_class_format *) pevent_specific_data;
+ int vu_event_id = (int) pnvme_event->vu_event_identifier;
+ unsigned int data_size = ((pevent_descriptor->event_data_size *
+ SIZE_OF_DWORD) - sizeof(struct nvme_ocp_nvme_dbg_evt_class_format));
+ __u8 *pdata = (__u8 *) pnvme_event + sizeof(struct nvme_ocp_nvme_dbg_evt_class_format);
+ char description_str[256] = "";
+
+ parse_ocp_telemetry_string_log(0, pnvme_event->vu_event_identifier,
+ pevent_descriptor->debug_event_class_type, VU_EVENT_STRING,
+ description_str);
+
+ if (pevent_fifos_object != NULL) {
+ json_add_formatted_var_size_str(pevent_descriptor_obj, STR_CLASS_SPECIFIC_DATA,
+ pnvme_event->nvmeDebugEventData, DATA_SIZE_8);
+ json_add_formatted_u32_str(pevent_descriptor_obj, STR_VU_EVENT_ID_STRING,
+ vu_event_id);
+ json_object_add_value_string(pevent_descriptor_obj, STR_VU_EVENT_STRING,
+ description_str);
+ json_add_formatted_var_size_str(pevent_descriptor_obj, STR_VU_DATA, pdata,
+ data_size);
+ } else {
+ if (fp) {
+ print_formatted_var_size_str(STR_CLASS_SPECIFIC_DATA,
+ pnvme_event->nvmeDebugEventData, DATA_SIZE_8, fp);
+ fprintf(fp, "%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
+ fprintf(fp, "%s: %s\n", STR_VU_EVENT_STRING, description_str);
+ print_formatted_var_size_str(STR_VU_DATA, pdata, data_size, fp);
+ } else {
+ print_formatted_var_size_str(STR_CLASS_SPECIFIC_DATA,
+ pnvme_event->nvmeDebugEventData, DATA_SIZE_8, fp);
+ printf("%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
+ printf("%s: %s\n", STR_VU_EVENT_STRING, description_str);
+ print_formatted_var_size_str(STR_VU_DATA, pdata, data_size, fp);
+ }
+ }
+}
+
+void parse_common_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descriptor,
+ struct json_object *pevent_descriptor_obj, __u8 *pevent_specific_data,
+ struct json_object *pevent_fifos_object, FILE *fp)
+{
+ struct nvme_ocp_common_dbg_evt_class_format *pcommon_debug_event =
+ (struct nvme_ocp_common_dbg_evt_class_format *) pevent_specific_data;
+ int vu_event_id = (int) pcommon_debug_event->vu_event_identifier;
+ unsigned int data_size = ((pevent_descriptor->event_data_size *
+ SIZE_OF_DWORD) - sizeof(struct nvme_ocp_common_dbg_evt_class_format));
+ __u8 *pdata = (__u8 *) pcommon_debug_event +
+ sizeof(struct nvme_ocp_common_dbg_evt_class_format);
+ char description_str[256] = "";
+
+ parse_ocp_telemetry_string_log(0, pcommon_debug_event->vu_event_identifier,
+ pevent_descriptor->debug_event_class_type, VU_EVENT_STRING, description_str);
+
+ if (pevent_fifos_object != NULL) {
+ json_add_formatted_u32_str(pevent_descriptor_obj, STR_VU_EVENT_ID_STRING,
+ vu_event_id);
+ json_object_add_value_string(pevent_descriptor_obj, STR_VU_EVENT_STRING,
+ description_str);
+ json_add_formatted_var_size_str(pevent_descriptor_obj, STR_VU_DATA, pdata,
+ data_size);
+ } else {
+ if (fp) {
+ fprintf(fp, "%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
+ fprintf(fp, "%s: %s\n", STR_VU_EVENT_STRING, description_str);
+ print_formatted_var_size_str(STR_VU_DATA, pdata, data_size, fp);
+ } else {
+ printf("%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
+ printf("%s: %s\n", STR_VU_EVENT_STRING, description_str);
+ print_formatted_var_size_str(STR_VU_DATA, pdata, data_size, fp);
+ }
+ }
+}
+
+void parse_media_wear_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descriptor,
+ struct json_object *pevent_descriptor_obj, __u8 *pevent_specific_data,
+ struct json_object *pevent_fifos_object, FILE *fp)
+{
+ struct nvme_ocp_media_wear_dbg_evt_class_format *pmedia_wear_event =
+ (struct nvme_ocp_media_wear_dbg_evt_class_format *) pevent_specific_data;
+ int vu_event_id = (int) pmedia_wear_event->vu_event_identifier;
+ unsigned int data_size = ((pevent_descriptor->event_data_size * SIZE_OF_DWORD) -
+ sizeof(struct nvme_ocp_media_wear_dbg_evt_class_format));
+ __u8 *pdata = (__u8 *) pmedia_wear_event +
+ sizeof(struct nvme_ocp_media_wear_dbg_evt_class_format);
+ char description_str[256] = "";
+
+ parse_ocp_telemetry_string_log(0, pmedia_wear_event->vu_event_identifier,
+ pevent_descriptor->debug_event_class_type, VU_EVENT_STRING,
+ description_str);
+
+ if (pevent_fifos_object != NULL) {
+ json_add_formatted_var_size_str(pevent_descriptor_obj, STR_CLASS_SPECIFIC_DATA,
+ pmedia_wear_event->currentMediaWear, DATA_SIZE_12);
+ json_add_formatted_u32_str(pevent_descriptor_obj, STR_VU_EVENT_ID_STRING,
+ vu_event_id);
+ json_object_add_value_string(pevent_descriptor_obj, STR_VU_EVENT_STRING,
+ description_str);
+ json_add_formatted_var_size_str(pevent_descriptor_obj, STR_VU_DATA, pdata,
+ data_size);
+ } else {
+ if (fp) {
+ print_formatted_var_size_str(STR_CLASS_SPECIFIC_DATA,
+ pmedia_wear_event->currentMediaWear, DATA_SIZE_12, fp);
+ fprintf(fp, "%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
+ fprintf(fp, "%s: %s\n", STR_VU_EVENT_STRING, description_str);
+ print_formatted_var_size_str(STR_VU_DATA, pdata, data_size, fp);
+ } else {
+ print_formatted_var_size_str(STR_CLASS_SPECIFIC_DATA,
+ pmedia_wear_event->currentMediaWear, DATA_SIZE_12, NULL);
+ printf("%s: 0x%x\n", STR_VU_EVENT_ID_STRING, vu_event_id);
+ printf("%s: %s\n", STR_VU_EVENT_STRING, description_str);
+ print_formatted_var_size_str(STR_VU_DATA, pdata, data_size, fp);
+ }
+ }
+}
+
+int parse_event_fifo(unsigned int fifo_num, unsigned char *pfifo_start,
+ struct json_object *pevent_fifos_object, unsigned char *pstring_buffer,
+ struct nvme_ocp_telemetry_offsets *poffsets, __u64 fifo_size, FILE *fp)
+{
+ if (NULL == pfifo_start || NULL == poffsets) {
+ nvme_show_error("Input buffer was NULL");
+ return -1;
+ }
+
+ int status = 0;
+ unsigned int event_fifo_number = fifo_num + 1;
+ char *description = (char *)malloc((40 + 1) * sizeof(char));
+
+ memset(description, 0, sizeof(40));
+
+ status =
+ parse_ocp_telemetry_string_log(event_fifo_number, 0, 0, EVENT_STRING, description);
+
+ if (status != 0) {
+ nvme_show_error("Failed to get C9 String. status: %d\n", status);
+ return -1;
+ }
+
+ char event_fifo_name[100] = {0};
+
+ snprintf(event_fifo_name, sizeof(event_fifo_name), "%s%d%s%s", "EVENT FIFO ",
+ event_fifo_number, " - ", description);
+
+ struct json_object *pevent_fifo_array = NULL;
+
+ if (pevent_fifos_object != NULL)
+ pevent_fifo_array = json_create_array();
+ else {
+ char buffer[1024] = {0};
+
+ sprintf(buffer, "%s%s\n%s", STR_LINE, event_fifo_name, STR_LINE);
+ if (fp)
+ fprintf(fp, "%s", buffer);
+ else
+ printf("%s", buffer);
+ }
+
+ int offset_to_move = 0;
+ unsigned int event_des_size = sizeof(struct nvme_ocp_telemetry_event_descriptor);
+
+ while ((fifo_size > 0) && (offset_to_move < fifo_size)) {
+ struct nvme_ocp_telemetry_event_descriptor *pevent_descriptor =
+ (struct nvme_ocp_telemetry_event_descriptor *)
+ (pfifo_start + offset_to_move);
+
+ if (pevent_descriptor != NULL && pevent_descriptor->event_data_size >= 0) {
+ //Data is present in the form of DWORDS, So multiplying with sizeof(DWORD)
+ unsigned int data_size = pevent_descriptor->event_data_size *
+ SIZE_OF_DWORD;
+
+ __u8 *pevent_specific_data = (__u8 *)pevent_descriptor + event_des_size;
+
+ char description_str[256] = "";
+
+ parse_ocp_telemetry_string_log(0, pevent_descriptor->event_id,
+ pevent_descriptor->debug_event_class_type, EVENT_STRING,
+ description_str);
+
+ struct json_object *pevent_descriptor_obj =
+ ((pevent_fifos_object != NULL)?json_create_object():NULL);
+
+ if (pevent_descriptor_obj != NULL) {
+ json_add_formatted_u32_str(pevent_descriptor_obj,
+ STR_DBG_EVENT_CLASS_TYPE,
+ pevent_descriptor->debug_event_class_type);
+ json_add_formatted_u32_str(pevent_descriptor_obj,
+ STR_EVENT_IDENTIFIER, pevent_descriptor->event_id);
+ json_object_add_value_string(pevent_descriptor_obj,
+ STR_EVENT_STRING, description_str);
+ json_add_formatted_u32_str(pevent_descriptor_obj,
+ STR_EVENT_DATA_SIZE, pevent_descriptor->event_data_size);
+
+ if (pevent_descriptor->debug_event_class_type >= 0x80)
+ json_add_formatted_var_size_str(pevent_descriptor_obj,
+ STR_VU_DATA, pevent_specific_data, data_size);
+ } else {
+ if (fp) {
+ fprintf(fp, "%s: 0x%x\n", STR_DBG_EVENT_CLASS_TYPE,
+ pevent_descriptor->debug_event_class_type);
+ fprintf(fp, "%s: 0x%x\n", STR_EVENT_IDENTIFIER,
+ pevent_descriptor->event_id);
+ fprintf(fp, "%s: %s\n", STR_EVENT_STRING, description_str);
+ fprintf(fp, "%s: 0x%x\n", STR_EVENT_DATA_SIZE,
+ pevent_descriptor->event_data_size);
+ } else {
+ printf("%s: 0x%x\n", STR_DBG_EVENT_CLASS_TYPE,
+ pevent_descriptor->debug_event_class_type);
+ printf("%s: 0x%x\n", STR_EVENT_IDENTIFIER,
+ pevent_descriptor->event_id);
+ printf("%s: %s\n", STR_EVENT_STRING, description_str);
+ printf("%s: 0x%x\n", STR_EVENT_DATA_SIZE,
+ pevent_descriptor->event_data_size);
+ }
+
+ if (pevent_descriptor->debug_event_class_type >= 0x80)
+ print_formatted_var_size_str(STR_VU_DATA,
+ pevent_specific_data, data_size, fp);
+ }
+
+ switch (pevent_descriptor->debug_event_class_type) {
+ case TIME_STAMP_CLASS_TYPE:
+ parse_time_stamp_event(pevent_descriptor, pevent_descriptor_obj,
+ pevent_specific_data, pevent_fifos_object, fp);
+ break;
+ case PCIE_CLASS_TYPE:
+ parse_pcie_event(pevent_descriptor, pevent_descriptor_obj,
+ pevent_specific_data, pevent_fifos_object, fp);
+ break;
+ case NVME_CLASS_TYPE:
+ parse_nvme_event(pevent_descriptor, pevent_descriptor_obj,
+ pevent_specific_data, pevent_fifos_object, fp);
+ break;
+ case RESET_CLASS_TYPE:
+ case BOOT_SEQUENCE_CLASS_TYPE:
+ case FIRMWARE_ASSERT_CLASS_TYPE:
+ case TEMPERATURE_CLASS_TYPE:
+ case MEDIA_CLASS_TYPE:
+ parse_common_event(pevent_descriptor, pevent_descriptor_obj,
+ pevent_specific_data, pevent_fifos_object, fp);
+ break;
+ case MEDIA_WEAR_CLASS_TYPE:
+ parse_media_wear_event(pevent_descriptor, pevent_descriptor_obj,
+ pevent_specific_data, pevent_fifos_object, fp);
+ break;
+ case STATISTIC_SNAPSHOT_CLASS_TYPE: {
+ struct nvme_ocp_statistic_snapshot_evt_class_format
+ *pStaticSnapshotEvent =
+ (struct nvme_ocp_statistic_snapshot_evt_class_format *)
+ pevent_specific_data;
+ struct nvme_ocp_telemetry_statistic_descriptor *pstatistic_entry =
+ (struct nvme_ocp_telemetry_statistic_descriptor *)
+ (&pStaticSnapshotEvent->statisticDescriptorData);
+
+ parse_statistic(pstatistic_entry, pevent_descriptor_obj, fp);
+ break;
+ }
+ case RESERVED_CLASS_TYPE:
+ default:
+ break;
+ }
+
+ if (pevent_descriptor_obj != NULL && pevent_fifo_array != NULL)
+ json_array_add_value_object(pevent_fifo_array, pevent_descriptor_obj);
+ else {
+ if (fp)
+ fprintf(fp, STR_LINE2);
+ else
+ printf(STR_LINE2);
+ }
+ } else
+ break;
+
+ offset_to_move += (pevent_descriptor->event_data_size * SIZE_OF_DWORD + event_des_size);
+ }
+
+ if (pevent_fifos_object != NULL && pevent_fifo_array != NULL)
+ json_object_add_value_array(pevent_fifos_object, event_fifo_name,
+ pevent_fifo_array);
+
+ free(description);
+ return 0;
+}
+
+int parse_event_fifos(struct json_object *root, struct nvme_ocp_telemetry_offsets *poffsets,
+ FILE *fp)
+{
+ if (poffsets == NULL) {
+ nvme_show_error("Input buffer was NULL");
+ return -1;
+ }
+
+ struct json_object *pevent_fifos_object = NULL;
+
+ if (root != NULL)
+ pevent_fifos_object = json_create_object();
+
+ __u8 *pda1_header_offset = ptelemetry_buffer + poffsets->da1_start_offset;//512
+ __u8 *pda2_offset = ptelemetry_buffer + poffsets->da2_start_offset;
+ struct nvme_ocp_header_in_da1 *pda1_header = (struct nvme_ocp_header_in_da1 *)
+ pda1_header_offset;
+ struct nvme_ocp_event_fifo_data event_fifo[MAX_NUM_FIFOS];
+
+ for (int fifo_num = 0; fifo_num < MAX_NUM_FIFOS; fifo_num++) {
+ event_fifo[fifo_num].event_fifo_num = fifo_num;
+ event_fifo[fifo_num].event_fifo_da = pda1_header->event_fifo_da[fifo_num];
+ event_fifo[fifo_num].event_fifo_start =
+ pda1_header->fifo_offsets[fifo_num].event_fifo_start;
+ event_fifo[fifo_num].event_fifo_size =
+ pda1_header->fifo_offsets[fifo_num].event_fifo_size;
+ }
+
+ //Parse all the FIFOs DA wise
+ for (int fifo_no = 0; fifo_no < MAX_NUM_FIFOS; fifo_no++) {
+ if (event_fifo[fifo_no].event_fifo_da == poffsets->data_area) {
+ __u64 fifo_offset =
+ (event_fifo[fifo_no].event_fifo_start * SIZE_OF_DWORD);
+ __u64 fifo_size =
+ (event_fifo[fifo_no].event_fifo_size * SIZE_OF_DWORD);
+ __u8 *pfifo_start = NULL;
+
+ if (event_fifo[fifo_no].event_fifo_da == 1)
+ pfifo_start = pda1_header_offset + fifo_offset;
+ else if (event_fifo[fifo_no].event_fifo_da == 2)
+ pfifo_start = pda2_offset + fifo_offset;
+ else {
+ nvme_show_error("Unsupported Data Area:[%d]", poffsets->data_area);
+ return -1;
+ }
+
+ int status = parse_event_fifo(fifo_no, pfifo_start, pevent_fifos_object,
+ pstring_buffer, poffsets, fifo_size, fp);
+
+ if (status != 0) {
+ nvme_show_error("Failed to parse Event FIFO. status:%d\n", status);
+ return -1;
+ }
+ }
+ }
+
+ if (pevent_fifos_object != NULL && root != NULL) {
+ const char *data_area = (poffsets->data_area == 1 ? STR_DA_1_EVENT_FIFO_INFO :
+ STR_DA_2_EVENT_FIFO_INFO);
+
+ json_object_add_value_array(root, data_area, pevent_fifos_object);
+ }
+
+ return 0;
+}
+
+int parse_statistic(struct nvme_ocp_telemetry_statistic_descriptor *pstatistic_entry,
+ struct json_object *pstats_array, FILE *fp)
+{
+ if (pstatistic_entry == NULL) {
+ nvme_show_error("Input buffer was NULL");
+ return -1;
+ }
+
+ unsigned int data_size = pstatistic_entry->statistic_data_size * SIZE_OF_DWORD;
+ __u8 *pdata = (__u8 *)pstatistic_entry +
+ sizeof(struct nvme_ocp_telemetry_statistic_descriptor);
+ char description_str[256] = "";
+
+ parse_ocp_telemetry_string_log(0, pstatistic_entry->statistic_id, 0,
+ STATISTICS_IDENTIFIER_STRING, description_str);
+
+ if (pstats_array != NULL) {
+ struct json_object *pstatistics_object = json_create_object();
+
+ json_add_formatted_u32_str(pstatistics_object, STR_STATISTICS_IDENTIFIER,
+ pstatistic_entry->statistic_id);
+ json_object_add_value_string(pstatistics_object, STR_STATISTICS_IDENTIFIER_STR,
+ description_str);
+ json_add_formatted_u32_str(pstatistics_object,
+ STR_STATISTICS_INFO_BEHAVIOUR_TYPE,
+ pstatistic_entry->statistic_info_behaviour_type);
+ json_add_formatted_u32_str(pstatistics_object, STR_STATISTICS_INFO_RESERVED,
+ pstatistic_entry->statistic_info_reserved);
+ json_add_formatted_u32_str(pstatistics_object, STR_NAMESPACE_IDENTIFIER,
+ pstatistic_entry->ns_info_nsid);
+ json_add_formatted_u32_str(pstatistics_object, STR_NAMESPACE_INFO_VALID,
+ pstatistic_entry->ns_info_ns_info_valid);
+ json_add_formatted_u32_str(pstatistics_object, STR_STATISTICS_DATA_SIZE,
+ pstatistic_entry->statistic_data_size);
+ json_add_formatted_u32_str(pstatistics_object, STR_RESERVED,
+ pstatistic_entry->reserved);
+ json_add_formatted_var_size_str(pstatistics_object, STR_STATISTICS_SPECIFIC_DATA,
+ pdata, data_size);
+
+ if (pstatistics_object != NULL)
+ json_array_add_value_object(pstats_array, pstatistics_object);
+ } else {
+ if (fp) {
+ fprintf(fp, "%s: 0x%x\n", STR_STATISTICS_IDENTIFIER,
+ pstatistic_entry->statistic_id);
+ fprintf(fp, "%s: %s\n", STR_STATISTICS_IDENTIFIER_STR, description_str);
+ fprintf(fp, "%s: 0x%x\n", STR_STATISTICS_INFO_BEHAVIOUR_TYPE,
+ pstatistic_entry->statistic_info_behaviour_type);
+ fprintf(fp, "%s: 0x%x\n", STR_STATISTICS_INFO_RESERVED,
+ pstatistic_entry->statistic_info_reserved);
+ fprintf(fp, "%s: 0x%x\n", STR_NAMESPACE_IDENTIFIER,
+ pstatistic_entry->ns_info_nsid);
+ fprintf(fp, "%s: 0x%x\n", STR_NAMESPACE_INFO_VALID,
+ pstatistic_entry->ns_info_ns_info_valid);
+ fprintf(fp, "%s: 0x%x\n", STR_STATISTICS_DATA_SIZE,
+ pstatistic_entry->statistic_data_size);
+ fprintf(fp, "%s: 0x%x\n", STR_RESERVED, pstatistic_entry->reserved);
+ print_formatted_var_size_str(STR_STATISTICS_SPECIFIC_DATA, pdata,
+ data_size, fp);
+ fprintf(fp, STR_LINE2);
+ } else {
+ printf("%s: 0x%x\n", STR_STATISTICS_IDENTIFIER,
+ pstatistic_entry->statistic_id);
+ printf("%s: %s\n", STR_STATISTICS_IDENTIFIER_STR, description_str);
+ printf("%s: 0x%x\n", STR_STATISTICS_INFO_BEHAVIOUR_TYPE,
+ pstatistic_entry->statistic_info_behaviour_type);
+ printf("%s: 0x%x\n", STR_STATISTICS_INFO_RESERVED,
+ pstatistic_entry->statistic_info_reserved);
+ printf("%s: 0x%x\n", STR_NAMESPACE_IDENTIFIER,
+ pstatistic_entry->ns_info_nsid);
+ printf("%s: 0x%x\n", STR_NAMESPACE_INFO_VALID,
+ pstatistic_entry->ns_info_ns_info_valid);
+ printf("%s: 0x%x\n", STR_STATISTICS_DATA_SIZE,
+ pstatistic_entry->statistic_data_size);
+ printf("%s: 0x%x\n", STR_RESERVED, pstatistic_entry->reserved);
+ print_formatted_var_size_str(STR_STATISTICS_SPECIFIC_DATA, pdata,
+ data_size, fp);
+ printf(STR_LINE2);
+ }
+ }
+
+ return 0;
+}
+
+int parse_statistics(struct json_object *root, struct nvme_ocp_telemetry_offsets *poffsets,
+ FILE *fp)
+{
+ if (poffsets == NULL) {
+ nvme_show_error("Input buffer was NULL");
+ return -1;
+ }
+
+ __u8 *pda1_ocp_header_offset = ptelemetry_buffer + poffsets->header_size;//512
+ __u32 statistics_size = 0;
+ __u32 stats_da_1_start_dw = 0, stats_da_1_size_dw = 0;
+ __u32 stats_da_2_start_dw = 0, stats_da_2_size_dw = 0;
+ __u8 *pstats_offset = NULL;
+
+ if (poffsets->data_area == 1) {
+ __u32 stats_da_1_start = *(__u32 *)(pda1_ocp_header_offset +
+ offsetof(struct nvme_ocp_header_in_da1, da1_statistic_start));
+ __u32 stats_da_1_size = *(__u32 *)(pda1_ocp_header_offset +
+ offsetof(struct nvme_ocp_header_in_da1, da1_statistic_size));
+
+ //Data is present in the form of DWORDS, So multiplying with sizeof(DWORD)
+ stats_da_1_start_dw = (stats_da_1_start * SIZE_OF_DWORD);
+ stats_da_1_size_dw = (stats_da_1_size * SIZE_OF_DWORD);
+
+ pstats_offset = pda1_ocp_header_offset + stats_da_1_start_dw;
+ statistics_size = stats_da_1_size_dw;
+ } else if (poffsets->data_area == 2) {
+ __u32 stats_da_2_start = *(__u32 *)(pda1_ocp_header_offset +
+ offsetof(struct nvme_ocp_header_in_da1, da2_statistic_start));
+ __u32 stats_da_2_size = *(__u32 *)(pda1_ocp_header_offset +
+ offsetof(struct nvme_ocp_header_in_da1, da2_statistic_size));
+
+ stats_da_2_start_dw = (stats_da_2_start * SIZE_OF_DWORD);
+ stats_da_2_size_dw = (stats_da_2_size * SIZE_OF_DWORD);
+
+ pstats_offset = pda1_ocp_header_offset + poffsets->da1_size + stats_da_2_start_dw;
+ statistics_size = stats_da_2_size_dw;
+ } else {
+ nvme_show_error("Unsupported Data Area:[%d]", poffsets->data_area);
+ return -1;
+ }
+
+ struct json_object *pstats_array = ((root != NULL) ? json_create_array() : NULL);
+
+ __u32 stat_des_size = sizeof(struct nvme_ocp_telemetry_statistic_descriptor);//8
+ __u32 offset_to_move = 0;
+
+ while (((statistics_size > 0) && (offset_to_move < statistics_size))) {
+ struct nvme_ocp_telemetry_statistic_descriptor *pstatistic_entry =
+ (struct nvme_ocp_telemetry_statistic_descriptor *)
+ (pstats_offset + offset_to_move);
+
+ parse_statistic(pstatistic_entry, pstats_array, fp);
+ offset_to_move += (pstatistic_entry->statistic_data_size * SIZE_OF_DWORD +
+ stat_des_size);
+ }
+
+ if (root != NULL && pstats_array != NULL) {
+ const char *pdata_area =
+ (poffsets->data_area == 1 ? STR_DA_1_STATS : STR_DA_2_STATS);
+
+ json_object_add_value_array(root, pdata_area, pstats_array);
+ }
+
+ return 0;
+}
+
+int print_ocp_telemetry_normal(struct ocp_telemetry_parse_options *options)
+{
+ int status = 0;
+
+ if (options->output_file != NULL) {
+ FILE *fp = fopen(options->output_file, "w");
+
+ if (fp) {
+ fprintf(fp, STR_LINE);
+ fprintf(fp, "%s\n", STR_LOG_PAGE_HEADER);
+ fprintf(fp, STR_LINE);
+ if (!strcmp(options->telemetry_type, "host"))
+ generic_structure_parser(ptelemetry_buffer, host_log_page_header,
+ ARRAY_SIZE(host_log_page_header), NULL, 0, fp);
+ else if (!strcmp(options->telemetry_type, "controller"))
+ generic_structure_parser(ptelemetry_buffer,
+ controller_log_page_header,
+ ARRAY_SIZE(controller_log_page_header), NULL, 0, fp);
+ fprintf(fp, STR_LINE);
+ fprintf(fp, "%s\n", STR_REASON_IDENTIFIER);
+ fprintf(fp, STR_LINE);
+ __u8 *preason_identifier_offset = ptelemetry_buffer +
+ offsetof(struct nvme_ocp_telemetry_host_initiated_header,
+ reason_id);
+
+ generic_structure_parser(preason_identifier_offset, reason_identifier,
+ ARRAY_SIZE(reason_identifier), NULL, 0, fp);
+
+ fprintf(fp, STR_LINE);
+ fprintf(fp, "%s\n", STR_TELEMETRY_HOST_DATA_BLOCK_1);
+ fprintf(fp, STR_LINE);
+
+ //Set DA to 1 and get offsets
+ struct nvme_ocp_telemetry_offsets offsets = { 0 };
+
+ offsets.data_area = 1;// Default DA - DA1
+
+ struct nvme_ocp_telemetry_common_header *ptelemetry_common_header =
+ (struct nvme_ocp_telemetry_common_header *) ptelemetry_buffer;
+
+ get_telemetry_das_offset_and_size(ptelemetry_common_header, &offsets);
+
+ __u8 *pda1_header_offset = ptelemetry_buffer +
+ offsets.da1_start_offset;//512
+
+ generic_structure_parser(pda1_header_offset, ocp_header_in_da1,
+ ARRAY_SIZE(ocp_header_in_da1), NULL, 0, fp);
+
+ fprintf(fp, STR_LINE);
+ fprintf(fp, "%s\n", STR_SMART_HEALTH_INFO);
+ fprintf(fp, STR_LINE);
+ __u8 *pda1_smart_offset = pda1_header_offset +
+ offsetof(struct nvme_ocp_header_in_da1, smart_health_info);
+ //512+512 =1024
+
+ generic_structure_parser(pda1_smart_offset, smart, ARRAY_SIZE(smart),
+ NULL, 0, fp);
+
+ fprintf(fp, STR_LINE);
+ fprintf(fp, "%s\n", STR_SMART_HEALTH_INTO_EXTENDED);
+ fprintf(fp, STR_LINE);
+ __u8 *pda1_smart_ext_offset = pda1_header_offset +
+ offsetof(struct nvme_ocp_header_in_da1,
+ smart_health_info_extended);
+
+ generic_structure_parser(pda1_smart_ext_offset, smart_extended,
+ ARRAY_SIZE(smart_extended), NULL, 0, fp);
+
+ fprintf(fp, STR_LINE);
+ fprintf(fp, "%s\n", STR_DA_1_STATS);
+ fprintf(fp, STR_LINE);
+
+ status = parse_statistics(NULL, &offsets, fp);
+ if (status != 0) {
+ nvme_show_error("status: %d\n", status);
+ return -1;
+ }
+
+ fprintf(fp, STR_LINE);
+ fprintf(fp, "%s\n", STR_DA_1_EVENT_FIFO_INFO);
+ fprintf(fp, STR_LINE);
+ status = parse_event_fifos(NULL, &offsets, fp);
+ if (status != 0) {
+ nvme_show_error("status: %d\n", status);
+ return -1;
+ }
+
+ //Set the DA to 2
+ if (options->data_area == 2) {
+ offsets.data_area = 2;
+ fprintf(fp, STR_LINE);
+ fprintf(fp, "%s\n", STR_DA_2_STATS);
+ fprintf(fp, STR_LINE);
+ status = parse_statistics(NULL, &offsets, fp);
+
+ if (status != 0) {
+ nvme_show_error("status: %d\n", status);
+ return -1;
+ }
+
+ fprintf(fp, STR_LINE);
+ fprintf(fp, "%s\n", STR_DA_2_EVENT_FIFO_INFO);
+ fprintf(fp, STR_LINE);
+ status = parse_event_fifos(NULL, &offsets, fp);
+ if (status != 0) {
+ nvme_show_error("status: %d\n", status);
+ return -1;
+ }
+ }
+
+ fprintf(fp, STR_LINE);
+ fclose(fp);
+ } else {
+ nvme_show_error("Failed to open %s file.\n", options->output_file);
+ return -1;
+ }
+ } else {
+ printf(STR_LINE);
+ printf("%s\n", STR_LOG_PAGE_HEADER);
+ printf(STR_LINE);
+ if (!strcmp(options->telemetry_type, "host"))
+ generic_structure_parser(ptelemetry_buffer, host_log_page_header,
+ ARRAY_SIZE(host_log_page_header), NULL, 0, NULL);
+ else if (!strcmp(options->telemetry_type, "controller"))
+ generic_structure_parser(ptelemetry_buffer, controller_log_page_header,
+ ARRAY_SIZE(controller_log_page_header), NULL, 0, NULL);
+
+ printf(STR_LINE);
+ printf("%s\n", STR_REASON_IDENTIFIER);
+ printf(STR_LINE);
+ __u8 *preason_identifier_offset = ptelemetry_buffer +
+ offsetof(struct nvme_ocp_telemetry_host_initiated_header, reason_id);
+ generic_structure_parser(preason_identifier_offset, reason_identifier,
+ ARRAY_SIZE(reason_identifier), NULL, 0, NULL);
+
+ printf(STR_LINE);
+ printf("%s\n", STR_TELEMETRY_HOST_DATA_BLOCK_1);
+ printf(STR_LINE);
+
+ //Set DA to 1 and get offsets
+ struct nvme_ocp_telemetry_offsets offsets = { 0 };
+
+ offsets.data_area = 1;
+
+ struct nvme_ocp_telemetry_common_header *ptelemetry_common_header =
+ (struct nvme_ocp_telemetry_common_header *) ptelemetry_buffer;
+
+ get_telemetry_das_offset_and_size(ptelemetry_common_header, &offsets);
+
+ __u8 *pda1_header_offset = ptelemetry_buffer + offsets.da1_start_offset;//512
+
+ generic_structure_parser(pda1_header_offset, ocp_header_in_da1,
+ ARRAY_SIZE(ocp_header_in_da1), NULL, 0, NULL);
+
+ printf(STR_LINE);
+ printf("%s\n", STR_SMART_HEALTH_INFO);
+ printf(STR_LINE);
+ __u8 *pda1_smart_offset = pda1_header_offset +
+ offsetof(struct nvme_ocp_header_in_da1, smart_health_info);
+
+ generic_structure_parser(pda1_smart_offset, smart, ARRAY_SIZE(smart), NULL, 0,
+ NULL);
+
+ printf(STR_LINE);
+ printf("%s\n", STR_SMART_HEALTH_INTO_EXTENDED);
+ printf(STR_LINE);
+ __u8 *pda1_smart_ext_offset = pda1_header_offset +
+ offsetof(struct nvme_ocp_header_in_da1, smart_health_info_extended);
+
+ generic_structure_parser(pda1_smart_ext_offset, smart_extended,
+ ARRAY_SIZE(smart_extended), NULL, 0, NULL);
+
+ printf(STR_LINE);
+ printf("%s\n", STR_DA_1_STATS);
+ printf(STR_LINE);
+ status = parse_statistics(NULL, &offsets, NULL);
+ if (status != 0) {
+ nvme_show_error("status: %d\n", status);
+ return -1;
+ }
+
+ printf(STR_LINE);
+ printf("%s\n", STR_DA_1_EVENT_FIFO_INFO);
+ printf(STR_LINE);
+ status = parse_event_fifos(NULL, &offsets, NULL);
+ if (status != 0) {
+ nvme_show_error("status: %d\n", status);
+ return -1;
+ }
+
+ //Set the DA to 2
+ if (options->data_area == 2) {
+ offsets.data_area = 2;
+ printf(STR_LINE);
+ printf("%s\n", STR_DA_2_STATS);
+ printf(STR_LINE);
+ status = parse_statistics(NULL, &offsets, NULL);
+ if (status != 0) {
+ nvme_show_error("status: %d\n", status);
+ return -1;
+ }
+
+ printf(STR_LINE);
+ printf("%s\n", STR_DA_2_EVENT_FIFO_INFO);
+ printf(STR_LINE);
+ status = parse_event_fifos(NULL, &offsets, NULL);
+ if (status != 0) {
+ nvme_show_error("status: %d\n", status);
+ return -1;
+ }
+ }
+
+ printf(STR_LINE);
+ }
+
+ return status;
+}
+
+int print_ocp_telemetry_json(struct ocp_telemetry_parse_options *options)
+{
+ int status = 0;
+
+ //create json objects
+ struct json_object *root, *pheader, *preason_identifier, *da1_header, *smart_obj,
+ *ext_smart_obj;
+
+ root = json_create_object();
+
+ //Add data to root json object
+
+ //"Log Page Header"
+ pheader = json_create_object();
+
+ generic_structure_parser(ptelemetry_buffer, host_log_page_header,
+ ARRAY_SIZE(host_log_page_header), pheader, 0, NULL);
+ json_object_add_value_object(root, STR_LOG_PAGE_HEADER, pheader);
+
+ //"Reason Identifier"
+ preason_identifier = json_create_object();
+
+ __u8 *preason_identifier_offset = ptelemetry_buffer +
+ offsetof(struct nvme_ocp_telemetry_host_initiated_header, reason_id);
+
+ generic_structure_parser(preason_identifier_offset, reason_identifier,
+ ARRAY_SIZE(reason_identifier), preason_identifier, 0, NULL);
+ json_object_add_value_object(pheader, STR_REASON_IDENTIFIER, preason_identifier);
+
+ struct nvme_ocp_telemetry_offsets offsets = { 0 };
+
+ //Set DA to 1 and get offsets
+ offsets.data_area = 1;
+ struct nvme_ocp_telemetry_common_header *ptelemetry_common_header =
+ (struct nvme_ocp_telemetry_common_header *) ptelemetry_buffer;
+
+ get_telemetry_das_offset_and_size(ptelemetry_common_header, &offsets);
+
+ //"Telemetry Host-Initiated Data Block 1"
+ __u8 *pda1_header_offset = ptelemetry_buffer + offsets.da1_start_offset;//512
+
+ da1_header = json_create_object();
+
+ generic_structure_parser(pda1_header_offset, ocp_header_in_da1,
+ ARRAY_SIZE(ocp_header_in_da1), da1_header, 0, NULL);
+ json_object_add_value_object(root, STR_TELEMETRY_HOST_DATA_BLOCK_1, da1_header);
+
+ //"SMART / Health Information Log(LID-02h)"
+ __u8 *pda1_smart_offset = pda1_header_offset + offsetof(struct nvme_ocp_header_in_da1,
+ smart_health_info);
+ smart_obj = json_create_object();
+
+ generic_structure_parser(pda1_smart_offset, smart, ARRAY_SIZE(smart), smart_obj, 0, NULL);
+ json_object_add_value_object(da1_header, STR_SMART_HEALTH_INFO, smart_obj);
+
+ //"SMART / Health Information Extended(LID-C0h)"
+ __u8 *pda1_smart_ext_offset = pda1_header_offset + offsetof(struct nvme_ocp_header_in_da1,
+ smart_health_info_extended);
+ ext_smart_obj = json_create_object();
+
+ generic_structure_parser(pda1_smart_ext_offset, smart_extended, ARRAY_SIZE(smart_extended),
+ ext_smart_obj, 0, NULL);
+ json_object_add_value_object(da1_header, STR_SMART_HEALTH_INTO_EXTENDED, ext_smart_obj);
+
+ //Data Area 1 Statistics
+ status = parse_statistics(root, &offsets, NULL);
+ if (status != 0) {
+ nvme_show_error("status: %d\n", status);
+ return -1;
+ }
+
+ //Data Area 1 Event FIFOs
+ status = parse_event_fifos(root, &offsets, NULL);
+ if (status != 0) {
+ nvme_show_error("status: %d\n", status, NULL);
+ return -1;
+ }
+
+ if (options->data_area == 2) {
+ //Set the DA to 2
+ offsets.data_area = 2;
+ //Data Area 2 Statistics
+ status = parse_statistics(root, &offsets, NULL);
+ if (status != 0) {
+ nvme_show_error("status: %d\n", status);
+ return -1;
+ }
+
+ //Data Area 2 Event FIFOs
+ status = parse_event_fifos(root, &offsets, NULL);
+ if (status != 0) {
+ nvme_show_error("status: %d\n", status);
+ return -1;
+ }
+ }
+
+ if (options->output_file != NULL) {
+ const char *json_string = json_object_to_json_string(root);
+ FILE *fp = fopen(options->output_file, "w");
+
+ if (fp) {
+ fputs(json_string, fp);
+ fclose(fp);
+ } else {
+ nvme_show_error("Failed to open %s file.\n", options->output_file);
+ return -1;
+ }
+ } else {
+ //Print root json object
+ json_print_object(root, NULL);
+ nvme_show_result("\n");
+ json_free_object(root);
+ }
+
+ return status;
+}
diff --git a/plugins/ocp/ocp-telemetry-decode.h b/plugins/ocp/ocp-telemetry-decode.h
new file mode 100644
index 0000000..ed31a6c
--- /dev/null
+++ b/plugins/ocp/ocp-telemetry-decode.h
@@ -0,0 +1,1228 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright (c) 2024 Western Digital Corporation or its affiliates.
+ *
+ * Authors: Jeff Lien <jeff.lien@wdc.com>,
+ */
+
+#include "nvme.h"
+#include "nvme-print.h"
+#include "util/utils.h"
+#include "common.h"
+
+extern __u8 *ptelemetry_buffer;
+extern __u8 *pstring_buffer;
+
+/*****************************************************************************
+ * Telemetry Statistics ID's and Strings
+ *****************************************************************************/
+enum TELEMETRY_STATISTIC_ID {
+ TELEMETRY_STAT_ID_OAC = 0x1, /* Outstanding Admin Commands */
+ TELEMETRY_STAT_ID_HWB = 0x2, /* Host Write Bandwidth */
+ TELEMETRY_STAT_ID_GCWB = 0x3, /* Garbage Collection Write Bandwidth */
+ TELEMETRY_STAT_ID_AN = 0x4, /* Active Namespaces */
+ TELEMETRY_STAT_ID_IWW = 0x5, /* Internal Write Workload */
+ TELEMETRY_STAT_ID_IRW = 0x6, /* Internal Read Workload */
+ TELEMETRY_STAT_ID_IWQD = 0x7, /* Internal Write Queue Depth */
+ TELEMETRY_STAT_ID_IRQD = 0x8, /* Internal Read Queue Depth */
+ TELEMETRY_STAT_ID_PTC = 0x9, /* Pending Trim LBA Count */
+ TELEMETRY_STAT_ID_HTRC = 0xA, /* Host Trim LBA Request Count */
+ TELEMETRY_STAT_ID_CNPS = 0xB, /* Current NVMe Power State */
+ TELEMETRY_STAT_ID_CDPS = 0xC, /* Current DSSD Power State */
+ TELEMETRY_STAT_ID_PFC = 0xD, /* Program Fail Count */
+ TELEMETRY_STAT_ID_EFC = 0xE, /* Erase Fail Count */
+ TELEMETRY_STAT_ID_RDW = 0xF, /* Read Disturb Write */
+ TELEMETRY_STAT_ID_RW = 0x10, /* Retention Writes */
+ TELEMETRY_STAT_ID_WLW = 0x11, /* Wear Leveling Writes */
+ TELEMETRY_STAT_ID_RRW = 0x12, /* Read Recovery Writes */
+ TELEMETRY_STAT_ID_GCW = 0x13, /* Garbage Collection Writes */
+ TELEMETRY_STAT_ID_SCC = 0x14, /* SRAM Correctable Count */
+ TELEMETRY_STAT_ID_DCC = 0x15, /* DRAM Uncorrectable Count */
+ TELEMETRY_STAT_ID_SUC = 0x16, /* SRAM Correctable Count */
+ TELEMETRY_STAT_ID_DUC = 0x17, /* DRAM Uncorrectable Count */
+ TELEMETRY_STAT_ID_DIEC = 0x18, /* Data Integrity Error Count */
+ TELEMETRY_STAT_ID_RREC = 0x19, /* Read Retry Error Count */
+ TELEMETRY_STAT_ID_PEC = 0x1A, /* PERST Events Count */
+ TELEMETRY_STAT_ID_MAXDBB = 0x1B, /* Max Die Bad Block */
+ TELEMETRY_STAT_ID_MAXCBB = 0x1C, /* Max NAND Channel Bad Block */
+ TELEMETRY_STAT_ID_MINCBB = 0x1D, /* Min NAND Channel Bad Block */
+};
+
+static const char * const telemetry_stat_id_str[] = {
+ [TELEMETRY_STAT_ID_OAC] = "Outstanding Admin Commands",
+ [TELEMETRY_STAT_ID_HWB] = "Host Write Bandwidth",
+ [TELEMETRY_STAT_ID_GCWB] = "Garbage Collection Write Bandwidth",
+ [TELEMETRY_STAT_ID_AN] = "Active Namespaces",
+ [TELEMETRY_STAT_ID_IWW] = "Internal Write Workload",
+ [TELEMETRY_STAT_ID_IRW] = "Internal Read Workload",
+ [TELEMETRY_STAT_ID_IWQD] = "Internal Write Queue Depth",
+ [TELEMETRY_STAT_ID_IRQD] = "Internal Read Queue Depth",
+ [TELEMETRY_STAT_ID_PTC] = "Pending Trim LBA Count",
+ [TELEMETRY_STAT_ID_HTRC] = "Host Trim LBA Request Count",
+ [TELEMETRY_STAT_ID_CNPS] = "Current NVMe Power State",
+ [TELEMETRY_STAT_ID_CDPS] = "Current DSSD Power State",
+ [TELEMETRY_STAT_ID_PFC] = "Program Fail Count",
+ [TELEMETRY_STAT_ID_EFC] = "Erase Fail Count",
+ [TELEMETRY_STAT_ID_RDW] = "Read Disturb Write",
+ [TELEMETRY_STAT_ID_RW] = "Retention Writes",
+ [TELEMETRY_STAT_ID_WLW] = "Wear Leveling Writes",
+ [TELEMETRY_STAT_ID_RRW] = "Read Recovery Writes",
+ [TELEMETRY_STAT_ID_GCW] = "Garbage Collection Writes",
+ [TELEMETRY_STAT_ID_SCC] = "SRAM Correctable Count",
+ [TELEMETRY_STAT_ID_DCC] = "DRAM Correctable Count",
+ [TELEMETRY_STAT_ID_SUC] = "SRAM Uncorrectable Count",
+ [TELEMETRY_STAT_ID_DUC] = "DRAM Uncorrectable Count",
+ [TELEMETRY_STAT_ID_DIEC] = "Data Integrity Error Count",
+ [TELEMETRY_STAT_ID_RREC] = "Read Retry Error Count",
+ [TELEMETRY_STAT_ID_PEC] = "PERST Events Count",
+ [TELEMETRY_STAT_ID_MAXDBB] = "Max Die Bad Block",
+ [TELEMETRY_STAT_ID_MAXCBB] = "Max NAND Channel Bad Block",
+ [TELEMETRY_STAT_ID_MINCBB] = "Min NAND Channel Bad Block",
+};
+
+/*****************************************************************************
+ * Telemetry FIFO Event Class ID's and Strings
+ *****************************************************************************/
+enum TELEMETRY_EVENT_CLASS_TYPE {
+ TELEMETRY_TIMESTAMP_CLASS = 0x1,
+ TELEMETRY_PCIE_CLASS = 0x2,
+ TELEMETRY_NVME_CLASS = 0x3,
+ TELEMETRY_RESET_CLASS = 0x4,
+ TELEMETRY_BOOT_SEQ_CLASS = 0x5,
+ TELEMETRY_FW_ASSERT_CLASS = 0x6,
+ TELEMETRY_TEMPERATURE_CLASS = 0x7,
+ TELEMETRY_MEDIA_DBG_CLASS = 0x8,
+ TELEMETRY_MEDIA_WEAR_CLASS = 0x9,
+ TELEMETRY_STAT_SNAPSHOT_CLASS = 0xA,
+};
+
+static const char * const telemetry_event_class_str[] = {
+ [TELEMETRY_TIMESTAMP_CLASS] = "Timestamp Class",
+ [TELEMETRY_PCIE_CLASS] = "PCIe Class",
+ [TELEMETRY_NVME_CLASS] = "NVMe Class",
+ [TELEMETRY_RESET_CLASS] = "Reset Class",
+ [TELEMETRY_BOOT_SEQ_CLASS] = "Boot Sequence Class",
+ [TELEMETRY_FW_ASSERT_CLASS] = "FW Assert Class",
+ [TELEMETRY_TEMPERATURE_CLASS] = "Temperature Class",
+ [TELEMETRY_MEDIA_DBG_CLASS] = "Media Debug Class",
+ [TELEMETRY_MEDIA_WEAR_CLASS] = "Media Wear Class",
+ [TELEMETRY_STAT_SNAPSHOT_CLASS] = "Statistic Snapshot Class",
+};
+
+/*****************************************************************************
+ * Telemetry Timestamp Class (01h) Event ID's and Strings
+ *****************************************************************************/
+enum TELEMETRY_TIMESTAMP_EVENT_ID {
+ TIMESTAMP_HOST_CMD_ISSUED = 0x0000,
+ TIMESTAMP_SNAPSHOT = 0x0001,
+ TIMESTAMP_POWER_ON_HOURS = 0x0002,
+};
+
+static const char * const telemetry_timestamp_event_id_str[] = {
+ [TIMESTAMP_HOST_CMD_ISSUED] = "Timestamp Host Cmd Issued",
+ [TIMESTAMP_SNAPSHOT] = "Timestamp Snapshot",
+ [TIMESTAMP_POWER_ON_HOURS] = "Timestamp Power on Hours",
+};
+
+/*****************************************************************************
+ * Telemetry PCIE Class (02h) Event ID's and Strings
+ *****************************************************************************/
+enum TELEMETRY_PCIE_EVENT_ID {
+ PCIE_LINK_UP = 0x0000,
+ PCIE_LINK_DOWN = 0x0001,
+ PCIE_ERROR_DETECTED = 0x0002,
+ PCIE_PERST_ASSERTED = 0x0003,
+ PCIE_PERST_DEASSERTED = 0x0004,
+ PCIE_REFCLK_STABLE = 0x0005,
+ PCIE_VMAIN_STABLE = 0x0006,
+ PCIE_LINK_NEGOTIATED = 0x0007,
+};
+
+static const char * const telemetry_pcie_event_id_str[] = {
+ [PCIE_LINK_UP] = "PCIe Link Up",
+ [PCIE_LINK_DOWN] = "PCIe Link Down",
+ [PCIE_ERROR_DETECTED] = "PCIe Error Detected",
+ [PCIE_PERST_ASSERTED] = "PCIe PERST Asserted",
+ [PCIE_PERST_DEASSERTED] = "PCIe PERST Deasserted",
+ [PCIE_REFCLK_STABLE] = "PCIe Refclk Stable",
+ [PCIE_VMAIN_STABLE] = "PCIe Vmain Stable",
+ [PCIE_LINK_NEGOTIATED] = "PCIe Link Negotiated",
+};
+
+enum TELEMETRY_PCIE_STATE_DATA {
+ PCIE_STATE_UNCHANGED = 0x00,
+ PCIE_SPEED_CHANGED = 0x01,
+ PCIE_WIDTH_CHANGED = 0x02,
+};
+
+static const char * const telemetry_pcie_state_data_str[] = {
+ [PCIE_STATE_UNCHANGED] = "PCIe State Unchained",
+ [PCIE_SPEED_CHANGED] = "PCIe Speed Changed",
+ [PCIE_WIDTH_CHANGED] = "PCIe Width Changed",
+};
+
+enum TELEMETRY_PCIE_SPEED_DATA {
+ PCIE_LINK_GEN1 = 0x01,
+ PCIE_LINK_GEN2 = 0x02,
+ PCIE_LINK_GEN3 = 0x03,
+ PCIE_LINK_GEN4 = 0x04,
+ PCIE_LINK_GEN5 = 0x05,
+ PCIE_LINK_GEN6 = 0x06,
+ PCIE_LINK_GEN7 = 0x07,
+};
+
+static const char * const telemetry_pcie_speed_data_str[] = {
+ [PCIE_LINK_GEN1] = "PCIe Link Speed Gen1",
+ [PCIE_LINK_GEN2] = "PCIe Link Speed Gen2",
+ [PCIE_LINK_GEN3] = "PCIe Link Speed Gen3",
+ [PCIE_LINK_GEN4] = "PCIe Link Speed Gen4",
+ [PCIE_LINK_GEN5] = "PCIe Link Speed Gen5",
+ [PCIE_LINK_GEN6] = "PCIe Link Speed Gen6",
+ [PCIE_LINK_GEN7] = "PCIe Link Speed Gen7",
+};
+
+enum TELEMETRY_PCIE_WIDTH_DATA {
+ PCIE_LINK_X1 = 0x01,
+ PCIE_LINK_X2 = 0x02,
+ PCIE_LINK_X4 = 0x03,
+ PCIE_LINK_X8 = 0x04,
+ PCIE_LINK_X16 = 0x05,
+};
+
+static const char * const telemetry_pcie_width_data_str[] = {
+ [PCIE_LINK_X1] = "PCIe Link Width x1",
+ [PCIE_LINK_X2] = "PCIe Link Width x2",
+ [PCIE_LINK_X4] = "PCIe Link Width x4",
+ [PCIE_LINK_X8] = "PCIe Link Width x8",
+ [PCIE_LINK_X16] = "PCIe Link Width x16",
+};
+
+/*****************************************************************************
+ * Telemetry NVMe Class (03h) Event ID's and Strings
+ *****************************************************************************/
+enum TELEMETRY_NVME_EVENT_ID {
+ CC_EN_0_TO_1 = 0x0000,
+ CC_EN_1_TO_0 = 0x0001,
+ CSTS_RDY_0_TO_1 = 0x0002,
+ CSTS_RDY_1_TO_0 = 0x0003,
+ NVME_EVENT_ID_RESERVED = 0x0004,
+ CREATE_IO_QUEUE_PROCESSED = 0x0005,
+ ADMIN_QUEUE_CMD_PROCESSED = 0x0006,
+ ADMIN_QUEUE_NONZERO_STATUS = 0x0007,
+ IO_QUEUE_NONZERO_STATUS = 0x0008,
+ CSTS_CFS_0_TO_1 = 0x0009,
+ ADMIN_QUEUE_BASE_WRITTEN = 0x000A,
+ CC_REGISTER_CHANGED = 0x000B,
+ CSTS_REGISTER_CHANGED = 0x000C,
+ DELETE_IO_QUEUE_PROCESSED = 0x000D,
+};
+
+static const char * const telemetry_nvme_event_id_str[] = {
+ [CC_EN_0_TO_1] = "CC.EN Transitions from 0 to 1",
+ [CC_EN_1_TO_0] = "CC.EN Transitions from 1 to 0",
+ [CSTS_RDY_0_TO_1] = "CSTS.RDY Transitions from 0 to 1",
+ [CSTS_RDY_1_TO_0] = "CSTS.RDY Transitions from 1 to 0",
+ [NVME_EVENT_ID_RESERVED] = "Reserved NVMe Event ID",
+ [CREATE_IO_QUEUE_PROCESSED] = "Create IO SQ or CQ Command Processed",
+ [ADMIN_QUEUE_CMD_PROCESSED] = "Other Admin Queue Command Processed",
+ [ADMIN_QUEUE_NONZERO_STATUS] = "Admin Command Returned Non-zero Status",
+ [IO_QUEUE_NONZERO_STATUS] = "IO Command Returned Non-zero Status",
+ [CSTS_CFS_0_TO_1] = "CSTS.CFS Transitions from 0 to 1",
+ [ADMIN_QUEUE_BASE_WRITTEN] = "Admin SQ or CQ Base Address Written",
+ [CC_REGISTER_CHANGED] = "CC Register Changed",
+ [CSTS_REGISTER_CHANGED] = "CTS Register Changed",
+ [DELETE_IO_QUEUE_PROCESSED] = "Delete IO SQ or CQ Command Processed",
+};
+
+/*****************************************************************************
+ * Telemetry Reset Class (04h) Event ID's and Strings
+ *****************************************************************************/
+enum TELEMETRY_RESET_EVENT_ID {
+ PCIE_CONVENTIONAL_HOT_RESET = 0x0000,
+ MAIN_POWER_CYCLE = 0x0001,
+ PERST = 0x0002,
+ PCIE_FUNCTION_LEVEL_RESET = 0x0003,
+ NVME_SUBSYSTEM_RESET = 0x0004,
+};
+
+static const char * const telemetry_reset_event_id_str[] = {
+ [PCIE_CONVENTIONAL_HOT_RESET] = "PCIE Conventional Hot Reset",
+ [MAIN_POWER_CYCLE] = "Main Power_Cycle",
+ [PERST] = "PERST",
+ [PCIE_FUNCTION_LEVEL_RESET] = "PCIE Function Level Reset",
+ [NVME_SUBSYSTEM_RESET] = "NVMe Subsytem Reset",
+};
+
+/*****************************************************************************
+ * Telemetry Boot Sequence Class (05h) Event ID's and Strings
+ *****************************************************************************/
+enum TELEMETRY_BOOT_SEQ_EVENT_ID {
+ MAIN_FW_BOOT_COMPLETE = 0x0000,
+ FTL_LOAD_FROM_NVM_COMPLETE = 0x0001,
+ FTL_REBUILD_STARTED = 0x0002,
+ FTL_REBUILD_COMPLETE = 0x0003,
+};
+
+static const char * const telemetry_boot_seq_event_id_str[] = {
+ [MAIN_FW_BOOT_COMPLETE] = "Main Firmware Boot Complete",
+ [FTL_LOAD_FROM_NVM_COMPLETE] = "FTL Load from NVM Complete",
+ [FTL_REBUILD_STARTED] = "FTL Rebuild Started",
+ [FTL_REBUILD_COMPLETE] = "FTL Rebuild Complete",
+};
+
+/*****************************************************************************
+ * Telemetry Firmware Assert Class (06h) Event ID's and Strings
+ *****************************************************************************/
+enum TELEMETRY_FW_ASSERT_EVENT_ID {
+ ASSERT_NVME_CODE = 0x0000,
+ ASSERT_MEDIA_CODE = 0x0001,
+ ASSERT_SECURITY_CODE = 0x0002,
+ ASSERT_BACKGROUND_CODE = 0x0003,
+ FTL_REBUILD_FAILED = 0x0004,
+ FTL_DATA_MISMATCH = 0x0005,
+ ASSERT_OTHER_CODE = 0x0006,
+};
+
+static const char * const telemetry_fw_assert_event_id_str[] = {
+ [ASSERT_NVME_CODE] = "Assert in NVMe Processing Code",
+ [ASSERT_MEDIA_CODE] = "Assert in Media Code",
+ [ASSERT_SECURITY_CODE] = "Assert in Security Code",
+ [ASSERT_BACKGROUND_CODE] = "Assert in Background Services Code",
+ [FTL_REBUILD_FAILED] = "FTL Rebuild Failed",
+ [FTL_DATA_MISMATCH] = "FTL Data Mismatch",
+ [ASSERT_OTHER_CODE] = "FTL Other Code",
+};
+
+/*****************************************************************************
+ * Telemetry Temperature Class (07h) Event ID's and Strings
+ *****************************************************************************/
+enum TELEMETRY_TEMPERATURE_EVENT_ID {
+ COMPOSITE_TEMP_DECREASE = 0x0000,
+ COMPOSITE_TEMP_INCREASE_WCTEMP = 0x0001,
+ COMPOSITE_TEMP_INCREASE_CCTEMP = 0x0002,
+};
+
+static const char * const telemetry_temperature_event_id_str[] = {
+ [COMPOSITE_TEMP_DECREASE] = "Composite Temp Decreases to (WCTEMP-2)",
+ [COMPOSITE_TEMP_INCREASE_WCTEMP] = "Composite Temp Increases to WCTEMP",
+ [COMPOSITE_TEMP_INCREASE_CCTEMP] = "Composite Temp Increases to CCTEMP",
+};
+
+/*****************************************************************************
+ * Telemetry Media Debug Class (08h) Event ID's and Strings
+ *****************************************************************************/
+enum TELEMETRY_MEDIA_DEBUG_EVENT_ID {
+ XOR_RECOVERY_INVOKED = 0x0000,
+ UNCORRECTABLE_MEDIA_ERROR = 0x0001,
+ BAD_BLOCK_PROGRAM_ERROR = 0x0002,
+ BAD_BLOCK_ERASE_ERROR = 0x0003,
+ BAD_BLOCK_READ_ERROR = 0x0004,
+ PLANE_FAILURE_EVENT = 0x0005,
+};
+
+static const char * const telemetry_media_debug_event_id_str[] = {
+ [XOR_RECOVERY_INVOKED] = "XOR Recovery Invoked",
+ [UNCORRECTABLE_MEDIA_ERROR] = "Uncorrectable Media Error",
+ [BAD_BLOCK_PROGRAM_ERROR] = "Block Marked Bad Due to Program Error",
+ [BAD_BLOCK_ERASE_ERROR] = "Block Marked Bad Due to Erase Error",
+ [BAD_BLOCK_READ_ERROR] = "Block Marked Bad Due to Read Error",
+ [PLANE_FAILURE_EVENT] = "Plane Failure Event",
+};
+
+/*****************************************************************************
+ * Telemetry Media Wear Class (09h) Event ID's and Strings
+ *****************************************************************************/
+enum TELEMETRY_MEDIA_WEAR_EVENT_ID {
+ MEDIA_WEAR = 0x0000,
+};
+
+static const char * const telemetry_media_wear_event_id_str[] = {
+ [MEDIA_WEAR] = "Media Wear",
+};
+
+
+/*****************************************************************************
+ * Telemetry Data Structures
+ *****************************************************************************/
+#define TELEMETRY_HEADER_SIZE 512
+#define TELEMETRY_DATA_SIZE 1536
+#define TELEMETRY_BYTE_PER_BLOCK 512
+#define TELEMETRY_TRANSFER_SIZE 1024
+#define FILE_NAME_SIZE 2048
+
+enum TELEMETRY_TYPE {
+ TELEMETRY_TYPE_NONE = 0,
+ TELEMETRY_TYPE_HOST = 7,
+ TELEMETRY_TYPE_CONTROLLER = 8,
+ TELEMETRY_TYPE_HOST_0 = 9,
+ TELEMETRY_TYPE_HOST_1 = 10,
+};
+
+struct telemetry_initiated_log {
+ __u8 LogIdentifier;
+ __u8 Reserved1[4];
+ __u8 IEEE[3];
+ __le16 DataArea1LastBlock;
+ __le16 DataArea2LastBlock;
+ __le16 DataArea3LastBlock;
+ __u8 Reserved2[2];
+ __le32 DataArea4LastBlock;
+ __u8 Reserved3[361];
+ __u8 DataHostGenerationNumber;
+ __u8 CtlrDataAvailable;
+ __u8 DataCtlrGenerationNumber;
+ __u8 ReasonIdentifier[128];
+};
+
+struct telemetry_stats_desc {
+ __le16 id;
+ __u8 info;
+ __u8 ns_info;
+ __le16 size;
+ __le16 rsvd1;
+ __u8 data[];
+};
+
+struct telemetry_event_desc {
+ __u8 class;
+ __le16 id;
+ __u8 size;
+ __u8 data[];
+};
+
+struct event_fifo {
+ __le64 start;
+ __le64 size;
+};
+
+struct telemetry_data_area_1 {
+ __le16 major_version;
+ __le16 minor_version;
+ __u8 reserved1[4];
+ __le64 timestamp;
+ __u8 log_page_guid[16];
+ __u8 no_of_tps_supp;
+ __u8 tps;
+ __u8 reserved2[6];
+ __le64 sls;
+ __u8 reserved3[8];
+ __u8 fw_revision[8];
+ __u8 reserved4[32];
+ __le64 da1_stat_start;
+ __le64 da1_stat_size;
+ __le64 da2_stat_start;
+ __le64 da2_stat_size;
+ __u8 reserved5[32];
+ __u8 event_fifo_da[16];
+ struct event_fifo event_fifos[16];
+ __u8 reserved6[80];
+ __u8 smart_health_info[512];
+ __u8 smart_health_info_extended[512];
+};
+
+#define DATA_SIZE_12 12
+#define DATA_SIZE_8 8
+#define DATA_SIZE_4 4
+#define MAX_BUFFER_32_KB 0x8000
+#define OCP_TELEMETRY_DATA_BLOCK_SIZE 512
+#define SIZE_OF_DWORD 4
+#define MAX_NUM_FIFOS 16
+#define DA1_OFFSET 512
+#define DEFAULT_ASCII_STRING_SIZE 16
+
+#define DEFAULT_TELEMETRY_BIN "telemetry.bin"
+#define DEFAULT_STRING_BIN "string.bin"
+#define DEFAULT_OUTPUT_FORMAT_JSON "json"
+
+/* C9 Telemetry String Log Format Log Page */
+#define C9_GUID_LENGTH 16
+#define C9_TELEMETRY_STRING_LOG_ENABLE_OPCODE 0xC9
+#define C9_TELEMETRY_STR_LOG_LEN 432
+#define C9_TELEMETRY_STR_LOG_SIST_OFST 431
+
+#define STR_LOG_PAGE_HEADER "Log Page Header"
+#define STR_REASON_IDENTIFIER "Reason Identifier"
+#define STR_TELEMETRY_HOST_DATA_BLOCK_1 "Telemetry Host-Initiated Data Block 1"
+#define STR_SMART_HEALTH_INFO "SMART / Health Information Log(LID-02h)"
+#define STR_SMART_HEALTH_INTO_EXTENDED "SMART / Health Information Extended(LID-C0h)"
+#define STR_DA_1_STATS "Data Area 1 Statistics"
+#define STR_DA_2_STATS "Data Area 2 Statistics"
+#define STR_DA_1_EVENT_FIFO_INFO "Data Area 1 Event FIFO info"
+#define STR_DA_2_EVENT_FIFO_INFO "Data Area 2 Event FIFO info"
+#define STR_STATISTICS_IDENTIFIER "Statistics Identifier"
+#define STR_STATISTICS_IDENTIFIER_STR "Statistic Identifier String"
+#define STR_STATISTICS_INFO_BEHAVIOUR_TYPE "Statistics Info Behavior Type"
+#define STR_STATISTICS_INFO_RESERVED "Statistics Info Reserved"
+#define STR_NAMESPACE_IDENTIFIER "Namespace Identifier"
+#define STR_NAMESPACE_INFO_VALID "Namespace Information Valid"
+#define STR_STATISTICS_DATA_SIZE "Statistic Data Size"
+#define STR_RESERVED "Reserved"
+#define STR_STATISTICS_SPECIFIC_DATA "Statistic Specific Data"
+#define STR_CLASS_SPECIFIC_DATA "Class Specific Data"
+#define STR_DBG_EVENT_CLASS_TYPE "Debug Event Class type"
+#define STR_EVENT_IDENTIFIER "Event Identifier"
+#define STR_EVENT_STRING "Event String"
+#define STR_EVENT_DATA_SIZE "Event Data Size"
+#define STR_VU_EVENT_STRING "VU Event String"
+#define STR_VU_EVENT_ID_STRING "VU Event Identifier"
+#define STR_VU_DATA "VU Data"
+#define STR_LINE "==============================================================================\n"
+#define STR_LINE2 "-----------------------------------------------------------------------------\n"
+
+/**
+ * enum ocp_telemetry_data_area - Telemetry Data Areas
+ * @DATA_AREA_1: Data Area 1
+ * @DATA_AREA_2: Data Area 2
+ * @DATA_AREA_3: Data Area 3
+ * @DATA_AREA_4: Data Area 4
+ */
+enum ocp_telemetry_data_area {
+ DATA_AREA_1 = 0x01,
+ DATA_AREA_2 = 0x02,
+ DATA_AREA_3 = 0x03,
+ DATA_AREA_4 = 0x04,
+};
+
+/**
+ * enum ocp_telemetry_string_tables - OCP telemetry string tables
+ * @STATISTICS_IDENTIFIER_STRING: Statistic Identifier string
+ * @EVENT_STRING: Event String
+ * @VU_EVENT_STRING: VU Event String
+ */
+enum ocp_telemetry_string_tables {
+ STATISTICS_IDENTIFIER_STRING = 0,
+ EVENT_STRING,
+ VU_EVENT_STRING
+};
+
+/**
+ * enum ocp_telemetry_debug_event_class_types - OCP Debug Event Class types
+ * @RESERVED_CLASS_TYPE: Reserved class
+ * @TIME_STAMP_CLASS_TYPE: Time stamp class
+ * @PCIE_CLASS_TYPE: PCIe class
+ * @NVME_CLASS_TYPE: NVME class
+ * @RESET_CLASS_TYPE: Reset class
+ * @BOOT_SEQUENCE_CLASS_TYPE: Boot Sequence class
+ * @FIRMWARE_ASSERT_CLASS_TYPE: Firmware Assert class
+ * @TEMPERATURE_CLASS_TYPE: Temperature class
+ * @MEDIA_CLASS_TYPE: Media class
+ * @MEDIA_WEAR_CLASS_TYPE: Media wear class
+ * @STATISTIC_SNAPSHOT_CLASS_TYPE: Statistic snapshot class
+ * @RESERVED: Reserved class
+ * @VENDOR_UNIQUE_CLASS_TYPE: Vendor Unique class
+ */
+enum ocp_telemetry_debug_event_class_types {
+ RESERVED_CLASS_TYPE = 0x00,
+ TIME_STAMP_CLASS_TYPE = 0x01,
+ PCIE_CLASS_TYPE = 0x02,
+ NVME_CLASS_TYPE = 0x03,
+ RESET_CLASS_TYPE = 0x04,
+ BOOT_SEQUENCE_CLASS_TYPE = 0x05,
+ FIRMWARE_ASSERT_CLASS_TYPE = 0x06,
+ TEMPERATURE_CLASS_TYPE = 0x07,
+ MEDIA_CLASS_TYPE = 0x08,
+ MEDIA_WEAR_CLASS_TYPE = 0x09,
+ STATISTIC_SNAPSHOT_CLASS_TYPE = 0x0A,
+ //RESERVED = 7Fh-0Bh,
+ //VENDOR_UNIQUE_CLASS_TYPE = FFh-80h,
+};
+
+/**
+ * struct telemetry_str_log_format - Telemetry String Log Format
+ * @log_page_version: indicates the version of the mapping this log page uses
+ * Shall be set to 01h.
+ * @reserved1: Reserved.
+ * @log_page_guid: Shall be set to B13A83691A8F408B9EA495940057AA44h.
+ * @sls: Shall be set to the number of DWORDS in the String Log.
+ * @reserved2: reserved.
+ * @sits: shall be set to the number of DWORDS in the Statistics
+ * Identifier String Table
+ * @ests: Shall be set to the number of DWORDS from byte 0 of this
+ * log page to the start of the Event String Table
+ * @estsz: shall be set to the number of DWORDS in the Event String Table
+ * @vu_eve_sts: Shall be set to the number of DWORDS from byte 0 of this
+ * log page to the start of the VU Event String Table
+ * @vu_eve_st_sz: shall be set to the number of DWORDS in the VU Event String Table
+ * @ascts: the number of DWORDS from byte 0 of this log page until the
+ * ASCII Table Starts.
+ * @asctsz: the number of DWORDS in the ASCII Table
+ * @fifo1: FIFO 0 ASCII String
+ * @fifo2: FIFO 1 ASCII String
+ * @fifo3: FIFO 2 ASCII String
+ * @fifo4: FIFO 3 ASCII String
+ * @fif05: FIFO 4 ASCII String
+ * @fifo6: FIFO 5 ASCII String
+ * @fifo7: FIFO 6 ASCII String
+ * @fifo8: FIFO 7 ASCII String
+ * @fifo9: FIFO 8 ASCII String
+ * @fifo10: FIFO 9 ASCII String
+ * @fif011: FIFO 10 ASCII String
+ * @fif012: FIFO 11 ASCII String
+ * @fifo13: FIFO 12 ASCII String
+ * @fif014: FIFO 13 ASCII String
+ * @fif015: FIFO 14 ASCII String
+ * @fif016: FIFO 15 ASCII String
+ * @reserved3: reserved
+ */
+struct __packed telemetry_str_log_format {
+ __u8 log_page_version;
+ __u8 reserved1[15];
+ __u8 log_page_guid[C9_GUID_LENGTH];
+ __le64 sls;
+ __u8 reserved2[24];
+ __le64 sits;
+ __le64 sitsz;
+ __le64 ests;
+ __le64 estsz;
+ __le64 vu_eve_sts;
+ __le64 vu_eve_st_sz;
+ __le64 ascts;
+ __le64 asctsz;
+ __u8 fifo1[16];
+ __u8 fifo2[16];
+ __u8 fifo3[16];
+ __u8 fifo4[16];
+ __u8 fifo5[16];
+ __u8 fifo6[16];
+ __u8 fifo7[16];
+ __u8 fifo8[16];
+ __u8 fifo9[16];
+ __u8 fifo10[16];
+ __u8 fifo11[16];
+ __u8 fifo12[16];
+ __u8 fifo13[16];
+ __u8 fifo14[16];
+ __u8 fifo15[16];
+ __u8 fifo16[16];
+ __u8 reserved3[48];
+};
+
+/*
+ * struct statistics_id_str_table_entry - Statistics Identifier String Table Entry
+ * @vs_si: Shall be set the Vendor Unique Statistic Identifier number.
+ * @reserved1: Reserved
+ * @ascii_id_len: Shall be set the number of ASCII Characters that are valid.
+ * @ascii_id_ofst: Shall be set to the offset from DWORD 0/Byte 0 of the Start
+ * of the ASCII Table to the first character of the string for
+ * this Statistic Identifier string..
+ * @reserved2 reserved
+ */
+struct __packed statistics_id_str_table_entry {
+ __le16 vs_si;
+ __u8 reserved1;
+ __u8 ascii_id_len;
+ __le64 ascii_id_ofst;
+ __le32 reserved2;
+};
+
+/*
+ * struct event_id_str_table_entry - Event Identifier String Table Entry
+ * @deb_eve_class: Shall be set the Debug Class.
+ * @ei: Shall be set to the Event Identifier
+ * @ascii_id_len: Shall be set the number of ASCII Characters that are valid.
+ * @ascii_id_ofst: This is the offset from DWORD 0/ Byte 0 of the start of the
+ * ASCII table to the ASCII data for this identifier
+ * @reserved2 reserved
+ */
+struct __packed event_id_str_table_entry {
+ __u8 deb_eve_class;
+ __le16 ei;
+ __u8 ascii_id_len;
+ __le64 ascii_id_ofst;
+ __le32 reserved2;
+};
+
+/*
+ * struct vu_event_id_str_table_entry - VU Event Identifier String Table Entry
+ * @deb_eve_class: Shall be set the Debug Class.
+ * @vu_ei: Shall be set to the VU Event Identifier
+ * @ascii_id_len: Shall be set the number of ASCII Characters that are valid.
+ * @ascii_id_ofst: This is the offset from DWORD 0/ Byte 0 of the start of the
+ * ASCII table to the ASCII data for this identifier
+ * @reserved reserved
+ */
+struct __packed vu_event_id_str_table_entry {
+ __u8 deb_eve_class;
+ __le16 vu_ei;
+ __u8 ascii_id_len;
+ __le64 ascii_id_ofst;
+ __le32 reserved;
+};
+
+
+struct __packed ocp_telemetry_parse_options {
+ char *telemetry_log;
+ char *string_log;
+ char *output_file;
+ char *output_format;
+ int data_area;
+ char *telemetry_type;
+};
+
+struct __packed nvme_ocp_telemetry_reason_id
+{
+ __u8 error_id[64]; // Bytes 63:00
+ __u8 file_id[8]; // Bytes 71:64
+ __le16 line_number; // Bytes 73:72
+ __u8 valid_flags; // Bytes 74
+ __u8 reserved[21]; // Bytes 95:75
+ __u8 vu_reason_ext[32]; // Bytes 127:96
+};
+
+struct __packed nvme_ocp_telemetry_common_header
+{
+ __u8 log_id; // Byte 00
+ __le32 reserved1; // Bytes 04:01
+ __u8 ieee_oui_id[3]; // Bytes 07:05
+ __le16 da1_last_block; // Bytes 09:08
+ __le16 da2_last_block; // Bytes 11:10
+ __le16 da3_last_block; // Bytes 13:12
+ __le16 reserved2; // Bytes 15:14
+ __le32 da4_last_block; // Bytes 19:16
+};
+
+struct __packed nvme_ocp_telemetry_host_initiated_header
+{
+ struct nvme_ocp_telemetry_common_header commonHeader; // Bytes 19:00
+ __u8 reserved3[360]; // Bytes 379:20
+ __u8 host_initiated_scope; // Byte 380
+ __u8 host_initiated_gen_number; // Byte 381
+ __u8 host_initiated_data_available; // Byte 382
+ __u8 ctrl_initiated_gen_number; // Byte 383
+ struct nvme_ocp_telemetry_reason_id reason_id; // Bytes 511:384
+};
+
+struct __packed nvme_ocp_telemetry_controller_initiated_header
+{
+ struct nvme_ocp_telemetry_common_header commonHeader; // Bytes 19:00
+ __u8 reserved3[361]; // Bytes 380:20
+ __u8 ctrl_initiated_scope; // Byte 381
+ __u8 ctrl_initiated_data_available; // Byte 382
+ __u8 ctrl_initiated_gen_number; // Byte 383
+ struct nvme_ocp_telemetry_reason_id reason_id; // Bytes 511:384
+};
+
+struct __packed nvme_ocp_telemetry_smart
+{
+ __u8 critical_warning; // Byte 0
+ __le16 composite_temperature; // Bytes 2:1
+ __u8 available_spare; // Bytes 3
+ __u8 available_spare_threshold; // Bytes 4
+ __u8 percentage_used; // Bytes 5
+ __u8 reserved1[26]; // Bytes 31:6
+ __u8 data_units_read[16]; // Bytes 47:32
+ __u8 data_units_written[16]; // Bytes 63:48
+ __u8 host_read_commands[16]; // Byte 79:64
+ __u8 host_write_commands[16]; // Bytes 95:80
+ __u8 controller_busy_time[16]; // Bytes 111:96
+ __u8 power_cycles[16]; // Bytes 127:112
+ __u8 power_on_hours[16]; // Bytes 143:128
+ __u8 unsafe_shutdowns[16]; // Bytes 159:144
+ __u8 media_and_data_integrity_errors[16]; // Bytes 175:160
+ __u8 number_of_error_information_log_entries[16]; // Bytes 191:176
+ __le32 warning_composite_temperature_time; // Byte 195:192
+ __le32 critical_composite_temperature_time; // Bytes 199:196
+ __le16 temperature_sensor1; // Bytes 201:200
+ __le16 temperature_sensor2; // Byte 203:202
+ __le16 temperature_sensor3; // Byte 205:204
+ __le16 temperature_sensor4; // Bytes 207:206
+ __le16 temperature_sensor5; // Bytes 209:208
+ __le16 temperature_sensor6; // Bytes 211:210
+ __le16 temperature_sensor7; // Bytes 213:212
+ __le16 temperature_sensor8; // Bytes 215:214
+ __le32 thermal_management_temperature1_transition_count; // Bytes 219:216
+ __le32 thermal_management_temperature2_transition_count; // Bytes 223:220
+ __le32 total_time_for_thermal_management_temperature1; // Bytes 227:224
+ __le32 total_time_for_thermal_management_temperature2; // Bytes 231:228
+ __u8 reserved2[280]; // Bytes 511:232
+};
+
+struct __packed nvme_ocp_telemetry_smart_extended
+{
+ __u8 physical_media_units_written[16]; // Bytes 15:0
+ __u8 physical_media_units_read[16]; // Bytes 31:16
+ __u8 bad_user_nand_blocks_raw_count[6]; // Bytes 37:32
+ __le16 bad_user_nand_blocks_normalized_value; // Bytes 39:38
+ __u8 bad_system_nand_blocks_raw_count[6]; // Bytes 45:40
+ __le16 bad_system_nand_blocks_normalized_value; // Bytes 47:46
+ __le64 xor_recovery_count; // Bytes 55:48
+ __le64 uncorrectable_read_error_count; // Bytes 63:56
+ __le64 soft_ecc_error_count; // Bytes 71:64
+ __le32 end_to_end_correction_counts_detected_errors; // Bytes 75:72
+ __le32 end_to_end_correction_counts_corrected_errors; // Bytes 79:76
+ __u8 system_data_percent_used; // Byte 80
+ __u8 refresh_counts[7]; // Bytes 87:81
+ __le32 max_user_data_erase_count; // Bytes 91:88
+ __le32 min_user_data_erase_count; // Bytes 95:92
+ __u8 num_thermal_throttling_events; // Bytes 96
+ __u8 current_throttling_status; // Bytes 97
+ __u8 errata_version_field; // Byte 98
+ __le16 point_version_field; // Byte 100:99
+ __le16 minor_version_field; // Byte 102:101
+ __u8 major_version_field; // Byte 103
+ __le64 pcie_correctable_error_count; // Bytes 111:104
+ __le32 incomplete_shutdowns; // Bytes 115:112
+ __le32 reserved1; // Bytes 119:116
+ __u8 percent_free_blocks; // Byte 120
+ __u8 reserved2[7]; // Bytes 127:121
+ __le16 capacitor_health; // Bytes 129:128
+ __u8 nvme_base_errata_version; // Byte 130
+ __u8 nvme_command_set_errata_version; // Byte 131
+ __le32 reserved3; // Bytes 135:132
+ __le64 unaligned_io; // Bytes 143:136
+ __le64 security_version_number; // Bytes 151:144
+ __le64 total_nuse; // Bytes 159:152
+ __u8 plp_start_count[16]; // Bytes 175:160
+ __u8 endurance_estimate[16]; // Bytes 191:176
+ __le64 pcie_link_retraining_count; // Bytes 199:192
+ __le64 power_state_change_count; // Bytes 207:200
+ __le64 lowest_permitted_firmware_revision; // Bytes 215:208
+ __u8 reserved4[278]; // Bytes 493:216
+ __le16 log_page_version; // Bytes 495:494
+ __u8 log_page_guid[16]; // Bytes 511:496
+};
+
+struct __packed nvme_ocp_event_fifo_data
+{
+ __le32 event_fifo_num;
+ __u8 event_fifo_da;
+ __le64 event_fifo_start;
+ __le64 event_fifo_size;
+};
+
+struct __packed nvme_ocp_telemetry_offsets
+{
+ __le32 data_area;
+ __le32 header_size;
+ __le32 da1_start_offset;
+ __le32 da1_size;
+ __le32 da2_start_offset;
+ __le32 da2_size;
+ __le32 da3_start_offset;
+ __le32 da3_size;
+ __le32 da4_start_offset;
+ __le32 da4_size;
+};
+
+struct __packed nvme_ocp_event_fifo_offsets
+{
+ __le64 event_fifo_start;
+ __le64 event_fifo_size;
+};
+
+struct __packed nvme_ocp_header_in_da1
+{
+ __le16 major_version; // Bytes 1:0
+ __le16 minor_version; // Bytes 3:2
+ __le32 reserved1; // Bytes 7:4
+ __le64 time_stamp; // Bytes 15:8
+ __u8 log_page_guid[16]; // Bytes 31:16
+ __u8 num_telemetry_profiles_supported; // Byte 32
+ __u8 telemetry_profile_selected; // Byte 33
+ __u8 reserved2[6]; // Bytes 39:34
+ __le64 string_log_size; // Bytes 47:40
+ __le64 reserved3; // Bytes 55:48
+ __le64 firmware_revision; // Bytes 63:56
+ __u8 reserved4[32]; // Bytes 95:64
+ __le64 da1_statistic_start; // Bytes 103:96
+ __le64 da1_statistic_size; // Bytes 111:104
+ __le64 da2_statistic_start; // Bytes 119:112
+ __le64 da2_statistic_size; // Bytes 127:120
+ __u8 reserved5[32]; // Bytes 159:128
+ __u8 event_fifo_da[16]; // Bytes 175:160
+ struct nvme_ocp_event_fifo_offsets fifo_offsets[16]; // Bytes 431:176
+ __u8 reserved6[80]; // Bytes 511:432
+ struct nvme_ocp_telemetry_smart smart_health_info; // Bytes 1023:512
+ struct nvme_ocp_telemetry_smart_extended smart_health_info_extended; // Bytes 1535:1024
+};
+
+struct __packed nvme_ocp_telemetry_statistic_descriptor
+{
+ __le16 statistic_id; // Bytes 1:0
+ __u8 statistic_info_behaviour_type : 4; // Byte 2(3:0)
+ __u8 statistic_info_reserved : 4; // Byte 2(7:4)
+ __u8 ns_info_nsid : 7; // Bytes 3(6:0)
+ __u8 ns_info_ns_info_valid : 1; // Bytes 3(7)
+ __le16 statistic_data_size; // Bytes 5:4
+ __le16 reserved; // Bytes 7:6
+};
+
+struct __packed nvme_ocp_telemetry_event_descriptor
+{
+ __u8 debug_event_class_type; // Byte 0
+ __le16 event_id; // Bytes 2:1
+ __u8 event_data_size; // Byte 3
+};
+
+struct __packed nvme_ocp_time_stamp_dbg_evt_class_format
+{
+ __u8 time_stamp[DATA_SIZE_8]; // Bytes 11:4
+ __le16 vu_event_identifier; // Bytes 13:12
+};
+
+struct __packed nvme_ocp_pcie_dbg_evt_class_format
+{
+ __u8 pCIeDebugEventData[DATA_SIZE_4]; // Bytes 7:4
+ __le16 vu_event_identifier; // Bytes 9:8
+};
+
+struct __packed nvme_ocp_nvme_dbg_evt_class_format
+{
+ __u8 nvmeDebugEventData[DATA_SIZE_8]; // Bytes 11:4
+ __le16 vu_event_identifier; // Bytes 13:12
+};
+
+struct __packed nvme_ocp_common_dbg_evt_class_format
+{
+ __le16 vu_event_identifier; // Bytes 5:4
+};
+
+struct __packed nvme_ocp_media_wear_dbg_evt_class_format
+{
+ __u8 currentMediaWear[DATA_SIZE_12]; // Bytes 15:4
+ __le16 vu_event_identifier; // Bytes 17:16
+};
+
+struct __packed nvme_ocp_statistic_snapshot_evt_class_format
+{
+ struct nvme_ocp_telemetry_statistic_descriptor statisticDescriptorData; // Bytes 11:10
+};
+
+struct __packed nvme_ocp_statistics_identifier_string_table
+{
+ __le16 vs_statistic_identifier; //1:0
+ __u8 reserved1; //2
+ __u8 ascii_id_length; //3
+ __le64 ascii_id_offset; //11:4
+ __le32 reserved2; //15:12
+};
+
+struct __packed nvme_ocp_event_string_table
+{
+ __u8 debug_event_class; //0
+ __le16 event_identifier; //2:1
+ __u8 ascii_id_length; //3
+ __le64 ascii_id_offset; //11:4
+ __le32 reserved; //15:12
+};
+
+struct __packed nvme_ocp_vu_event_string_table
+{
+ __u8 debug_event_class; //0
+ __le16 vu_event_identifier; //2:1
+ __u8 ascii_id_length; //3
+ __le64 ascii_id_offset; //11:4
+ __le32 reserved; //15:12
+};
+
+struct __packed nvme_ocp_telemetry_string_header
+{
+ __u8 version; //0:0
+ __u8 reserved1[15]; //15:1
+ __u8 guid[16]; //32:16
+ __le64 string_log_size; //39:32
+ __u8 reserved2[24]; //63:40
+ __le64 sits; //71:64 Statistics Identifier String Table Start(SITS)
+ __le64 sitsz; //79:72 Statistics Identifier String Table Size (SITSZ)
+ __le64 ests; //87:80 Event String Table Start(ESTS)
+ __le64 estsz; //95:88 Event String Table Size(ESTSZ)
+ __le64 vu_ests; //103:96 VU Event String Table Start
+ __le64 vu_estsz; //111:104 VU Event String Table Size
+ __le64 ascts; //119:112 ASCII Table start
+ __le64 asctsz; //127:120 ASCII Table Size
+ __u8 fifo_ascii_string[16][16]; //383:128
+ __u8 reserved3[48]; //431:384
+};
+
+struct __packed statistic_entry {
+ int identifier;
+ char *description;
+};
+
+/************************************************************
+ * Telemetry Parsing Function Prototypes
+ ************************************************************/
+void print_vu_event_data(__u32 size, __u8 *data);
+void print_stats_desc(struct telemetry_stats_desc *stat_desc);
+void print_telemetry_fifo_event(__u8 class_type,
+ __u16 id, __u8 size, __u8 *data);
+
+
+/************************************************************
+ * Telemetry ID to String Conversion Functions
+ ************************************************************/
+static inline const char *arg_str(const char * const *strings,
+ size_t array_size, size_t idx)
+{
+ if (idx < array_size && strings[idx])
+ return strings[idx];
+ return "unrecognized";
+}
+
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+#define ARGSTR(s, i) arg_str(s, ARRAY_SIZE(s), i)
+
+static inline const char *telemetry_stat_id_to_string(int stat_id)
+{
+ return ARGSTR(telemetry_stat_id_str, stat_id);
+}
+static inline const char *telemetry_event_class_to_string(int class)
+{
+ return ARGSTR(telemetry_event_class_str, class);
+}
+static inline const char *telemetry_ts_event_to_string(int event_id)
+{
+ return ARGSTR(telemetry_timestamp_event_id_str, event_id);
+}
+static inline const char *telemetry_pcie_event_id_to_string(int event_id)
+{
+ return ARGSTR(telemetry_pcie_event_id_str, event_id);
+}
+static inline const char *telemetry_pcie_state_data_to_string(int pcie_state)
+{
+ return ARGSTR(telemetry_pcie_state_data_str, pcie_state);
+}
+static inline const char *telemetry_pcie_speed_data_to_string(int pcie_speed)
+{
+ return ARGSTR(telemetry_pcie_speed_data_str, pcie_speed);
+}
+static inline const char *telemetry_pcie_width_data_to_string(int pcie_width)
+{
+ return ARGSTR(telemetry_pcie_width_data_str, pcie_width);
+}
+static inline const char *telemetry_nvme_event_id_to_string(int event_id)
+{
+ return ARGSTR(telemetry_nvme_event_id_str, event_id);
+}
+static inline const char *telemetry_reset_event_id_to_string(int event_id)
+{
+ return ARGSTR(telemetry_reset_event_id_str, event_id);
+}
+static inline const char *telemetry_boot_seq_event_id_to_string(int event_id)
+{
+ return ARGSTR(telemetry_boot_seq_event_id_str, event_id);
+}
+static inline const char *telemetry_fw_assert_event_id_to_string(int event_id)
+{
+ return ARGSTR(telemetry_fw_assert_event_id_str, event_id);
+}
+static inline const char *telemetry_temperature_event_id_to_string(int event_id)
+{
+ return ARGSTR(telemetry_temperature_event_id_str, event_id);
+}
+static inline const char *telemetry_media_debug_event_id_to_string(int event_id)
+{
+ return ARGSTR(telemetry_media_debug_event_id_str, event_id);
+}
+static inline const char *telemetry_media_wear_event_id_to_string(int event_id)
+{
+ return ARGSTR(telemetry_media_wear_event_id_str, event_id);
+}
+
+/**
+ * @brief parse the ocp telemetry host or controller log binary file
+ * into json or text
+ *
+ * @param options, input pointer for inputs like telemetry log bin file,
+ * string log bin file and output file etc.
+ *
+ * @return 0 success
+ */
+int parse_ocp_telemetry_log(struct ocp_telemetry_parse_options *options);
+
+/**
+ * @brief parse the ocp telemetry string log binary file to json or text
+ *
+ * @param event_fifo_num, input event FIFO number
+ * @param debug_event_class, input debug event class id
+ * @param string_table, input string table
+ * @param description, input description string
+ *
+ * @return 0 success
+ */
+int parse_ocp_telemetry_string_log(int event_fifo_num, int identifier, int debug_event_class,
+ enum ocp_telemetry_string_tables string_table, char *description);
+
+/**
+ * @brief gets the telemetry datas areas, offsets and sizes information
+ *
+ * @param ptelemetry_common_header, input telemetry common header pointer
+ * @param ptelemetry_das_offset, input telemetry offsets pointer
+ *
+ * @return 0 success
+ */
+int get_telemetry_das_offset_and_size(
+ struct nvme_ocp_telemetry_common_header *ptelemetry_common_header,
+ struct nvme_ocp_telemetry_offsets *ptelemetry_das_offset);
+
+/**
+ * @brief parses statistics data to text or json formats
+ *
+ * @param root, input time json root object pointer
+ * @param ptelemetry_das_offset, input telemetry offsets pointer
+ * @param fp, input file pointer
+ *
+ * @return 0 success
+ */
+int parse_statistics(struct json_object *root, struct nvme_ocp_telemetry_offsets *pOffsets,
+ FILE *fp);
+
+/**
+ * @brief parses a single statistic data to text or json formats
+ *
+ * @param pstatistic_entry, statistic entry pointer
+ * @param pstats_array, stats array pointer
+ * @param fp, input file pointer
+ *
+ * @return 0 success
+ */
+int parse_statistic(struct nvme_ocp_telemetry_statistic_descriptor *pstatistic_entry,
+ struct json_object *pstats_array, FILE *fp);
+
+/**
+ * @brief parses event fifos data to text or json formats
+ *
+ * @param root, input time json root object pointer
+ * @param poffsets, input telemetry offsets pointer
+ * @param fp, input file pointer
+ *
+ * @return 0 success
+ */
+int parse_event_fifos(struct json_object *root, struct nvme_ocp_telemetry_offsets *poffsets,
+ FILE *fp);
+
+/**
+ * @brief parses a single event fifo data to text or json formats
+ *
+ * @param fifo_num, input event fifo number
+ * @param pfifo_start, event fifo start pointer
+ * @param pevent_fifos_object, event fifos json object pointer
+ * @param ptelemetry_das_offset, input telemetry offsets pointer
+ * @param fifo_size, input event fifo size
+ * @param fp, input file pointer
+ *
+ * @return 0 success
+ */
+int parse_event_fifo(unsigned int fifo_num, unsigned char *pfifo_start,
+ struct json_object *pevent_fifos_object, unsigned char *pstring_buffer,
+ struct nvme_ocp_telemetry_offsets *poffsets, __u64 fifo_size, FILE *fp);
+
+/**
+ * @brief parses event fifos data to text or json formats
+ *
+ * @return 0 success
+ */
+int print_ocp_telemetry_normal(struct ocp_telemetry_parse_options *options);
+
+/**
+ * @brief parses event fifos data to text or json formats
+ *
+ * @return 0 success
+ */
+int print_ocp_telemetry_json(struct ocp_telemetry_parse_options *options);
+
+/**
+ * @brief gets statistic id ascii string
+ *
+ * @param identifier, string id
+ * @param description, string description
+ *
+ * @return 0 success
+ */
+int get_static_id_ascii_string(int identifier, char *description);
+
+/**
+ * @brief gets event id ascii string
+ *
+ * @param identifier, string id
+ * @param debug_event_class, debug event class
+ * @param description, string description
+ *
+ * @return 0 success
+ */
+int get_event_id_ascii_string(int identifier, int debug_event_class, char *description);
+
+/**
+ * @brief gets vu event id ascii string
+ *
+ * @param identifier, string id
+ * @param debug_event_class, debug event class
+ * @param description, string description
+ *
+ * @return 0 success
+ */
+int get_vu_event_id_ascii_string(int identifier, int debug_event_class, char *description);
+
+/**
+ * @brief parses a time-stamp event fifo data to text or json formats
+ *
+ * @param pevent_descriptor, input event descriptor data
+ * @param pevent_descriptor_obj, event descriptor json object pointer
+ * @param pevent_specific_data, input event specific data
+ * @param pevent_fifos_object, event fifos json object pointer
+ * @param fp, input file pointer
+ *
+ * @return
+ */
+void parse_time_stamp_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descriptor,
+ struct json_object *pevent_descriptor_obj, __u8 *pevent_specific_data,
+ struct json_object *pevent_fifos_object, FILE *fp);
+
+/**
+ * @brief parses a pcie event fifo data to text or json formats
+ *
+ * @param pevent_descriptor, input event descriptor data
+ * @param pevent_descriptor_obj, event descriptor json object pointer
+ * @param pevent_specific_data, input event specific data
+ * @param pevent_fifos_object, event fifos json object pointer
+ * @param fp, input file pointer
+ *
+ * @return
+ */
+void parse_pcie_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descriptor,
+ struct json_object *pevent_descriptor_obj, __u8 *pevent_specific_data,
+ struct json_object *pevent_fifos_object, FILE *fp);
+
+/**
+ * @brief parses a nvme event fifo data to text or json formats
+ *
+ * @param pevent_descriptor, input event descriptor data
+ * @param pevent_descriptor_obj, event descriptor json object pointer
+ * @param pevent_specific_data, input event specific data
+ * @param pevent_fifos_object, event fifos json object pointer
+ * @param fp, input file pointer
+ *
+ * @return
+ */
+void parse_nvme_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descriptor,
+ struct json_object *pevent_descriptor_obj, __u8 *pevent_specific_data,
+ struct json_object *pevent_fifos_object, FILE *fp);
+
+/**
+ * @brief parses common event fifo data to text or json formats
+ *
+ * @param pevent_descriptor, input event descriptor data
+ * @param pevent_descriptor_obj, event descriptor json object pointer
+ * @param pevent_specific_data, input event specific data
+ * @param pevent_fifos_object, event fifos json object pointer
+ * @param fp, input file pointer
+ *
+ * @return
+ */
+void parse_common_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descriptor,
+ struct json_object *pevent_descriptor_obj, __u8 *pevent_specific_data,
+ struct json_object *pevent_fifos_object, FILE *fp);
+
+/**
+ * @brief parses a media-wear event fifo data to text or json formats
+ *
+ * @param pevent_descriptor, input event descriptor data
+ * @param pevent_descriptor_obj, event descriptor json object pointer
+ * @param pevent_specific_data, input event specific data
+ * @param pevent_fifos_object, event fifos json object pointer
+ * @param fp, input file pointer
+ *
+ * @return
+ */
+void parse_media_wear_event(struct nvme_ocp_telemetry_event_descriptor *pevent_descriptor,
+ struct json_object *pevent_descriptor_obj, __u8 *pevent_specific_data,
+ struct json_object *pevent_fifos_object, FILE *fp);