Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
416 changes: 85 additions & 331 deletions nvme-print-json.c

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ static const char *pmrmscu = "PMRMSCU=0xe18 register offset";

struct nvme_config nvme_cfg = {
.output_format = "normal",
.output_format_ver = 1,
.timeout = NVME_DEFAULT_IOCTL_TIMEOUT,
};

Expand Down
3 changes: 0 additions & 3 deletions nvme.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ struct nvme_config {
__u32 timeout;
bool dry_run;
bool no_retries;
unsigned int output_format_ver;
};

/*
Expand All @@ -74,8 +73,6 @@ struct nvme_config {
OPT_FLAG("dry-run", 0, &nvme_cfg.dry_run, dry_run), \
OPT_FLAG("no-retries", 0, &nvme_cfg.no_retries, \
"disable retry logic on errors\n"), \
OPT_UINT("output-format-version", 0, &nvme_cfg.output_format_ver, \
"output format version: 1|2"), \
OPT_END() \
}

Expand Down
177 changes: 1 addition & 176 deletions plugins/ocp/ocp-print-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,171 +138,7 @@ static void json_fw_activation_history(const struct fw_activation_history *fw_hi
printf("\n");
}

static void json_smart_extended_log_v1(struct ocp_smart_extended_log *log)
{
struct json_object *root;
struct json_object *pmuw;
struct json_object *pmur;
uint16_t smart_log_ver = 0;
uint16_t dssd_version = 0;
int i = 0;
char guid[40];
char ascii_arr[65];
char *ascii = ascii_arr;

root = json_create_object();
pmuw = json_create_object();
pmur = json_create_object();

json_object_add_value_uint64(pmuw, "hi",
le64_to_cpu(*(uint64_t *)&log->physical_media_units_written[8]));
json_object_add_value_uint64(pmuw, "lo",
le64_to_cpu(*(uint64_t *)&log->physical_media_units_written));
json_object_add_value_object(root, "Physical media units written", pmuw);
json_object_add_value_uint64(pmur, "hi",
le64_to_cpu(*(uint64_t *)&log->physical_media_units_read[8]));
json_object_add_value_uint64(pmur, "lo",
le64_to_cpu(*(uint64_t *)&log->physical_media_units_read));
json_object_add_value_object(root, "Physical media units read", pmur);
json_object_add_value_uint64(root, "Bad user nand blocks - Raw",
int48_to_long(log->bad_user_nand_blocks_raw));
json_object_add_value_uint(root, "Bad user nand blocks - Normalized",
le16_to_cpu(log->bad_user_nand_blocks_normalized));
json_object_add_value_uint64(root, "Bad system nand blocks - Raw",
int48_to_long(log->bad_system_nand_blocks_raw));
json_object_add_value_uint(root, "Bad system nand blocks - Normalized",
le16_to_cpu(log->bad_system_nand_blocks_normalized));
json_object_add_value_uint64(root, "XOR recovery count",
le64_to_cpu(log->xor_recovery_count));
json_object_add_value_uint64(root, "Uncorrectable read error count",
le64_to_cpu(log->uncorrectable_read_err_count));
json_object_add_value_uint64(root, "Soft ecc error count",
le64_to_cpu(log->soft_ecc_err_count));
json_object_add_value_uint(root, "End to end detected errors",
le32_to_cpu(log->end_to_end_detected_err));
json_object_add_value_uint(root, "End to end corrected errors",
le32_to_cpu(log->end_to_end_corrected_err));
json_object_add_value_uint(root, "System data percent used",
log->system_data_used_percent);
json_object_add_value_uint64(root, "Refresh counts",
int56_to_long(log->refresh_counts));
json_object_add_value_uint(root, "Max User data erase counts",
le32_to_cpu(log->user_data_erase_count_max));
json_object_add_value_uint(root, "Min User data erase counts",
le32_to_cpu(log->user_data_erase_count_min));
json_object_add_value_uint(root, "Number of Thermal throttling events",
log->thermal_throttling_event_count);
json_object_add_value_uint(root, "Current throttling status",
log->thermal_throttling_current_status);
json_object_add_value_uint64(root, "PCIe correctable error count",
le64_to_cpu(log->pcie_correctable_err_count));
json_object_add_value_uint(root, "Incomplete shutdowns",
le32_to_cpu(log->incomplete_shoutdowns));
json_object_add_value_uint(root, "Percent free blocks",
log->percent_free_blocks);
json_object_add_value_uint(root, "Capacitor health",
le16_to_cpu(log->capacitor_health));
json_object_add_value_uint64(root, "Unaligned I/O",
le64_to_cpu(log->unaligned_io));
json_object_add_value_uint64(root, "Security Version Number",
le64_to_cpu(log->security_version));
json_object_add_value_uint64(root, "NUSE - Namespace utilization",
le64_to_cpu(log->total_nuse));
json_object_add_value_uint128(root, "PLP start count",
le128_to_cpu(log->plp_start_count));
json_object_add_value_uint128(root, "Endurance estimate",
le128_to_cpu(log->endurance_estimate));
smart_log_ver = le16_to_cpu(log->log_page_version);

json_object_add_value_uint(root, "Log page version", smart_log_ver);

memset((void *)guid, 0, 40);
sprintf((char *)guid, "0x%"PRIx64"%"PRIx64"",
le64_to_cpu(*(uint64_t *)&log->log_page_guid[8]),
le64_to_cpu(*(uint64_t *)&log->log_page_guid));
json_object_add_value_string(root, "Log page GUID", guid);

switch (smart_log_ver) {
case 0 ... 1:
break;
default:
case 5:
json_object_add_value_uint(root, "NVMe Over Pcie Errata Version",
log->nvme_over_pcie_errate_version);
json_object_add_value_uint(root, "NVMe Mi Errata Version",
log->nvme_mi_errata_version);
json_object_add_value_uint(root, "Total media dies",
le16_to_cpu(log->total_media_dies));
json_object_add_value_uint(root, "Total die failure tolerance",
le16_to_cpu(log->total_die_failure_tolerance));
json_object_add_value_uint(root, "Media dies offline",
le16_to_cpu(log->media_dies_offline));
json_object_add_value_uint(root, "Max temperature recorded",
log->max_temperature_recorded);
json_object_add_value_uint64(root, "Nand avg erase count",
le64_to_cpu(log->nand_avg_erase_count));
json_object_add_value_uint(root, "Command timeouts",
le32_to_cpu(log->command_timeouts));
json_object_add_value_uint(root, "Sys area program fail count raw",
le32_to_cpu(log->sys_area_program_fail_count_raw));
json_object_add_value_uint(root, "Sys area program fail count noralized",
log->sys_area_program_fail_count_normalized);
json_object_add_value_uint(root, "Sys area uncorrectable read count raw",
le32_to_cpu(log->sys_area_uncorr_read_count_raw));
json_object_add_value_uint(root, "Sys area uncorrectable read count noralized",
log->sys_area_uncorr_read_count_normalized);
json_object_add_value_uint(root, "Sys area erase fail count raw",
le32_to_cpu(log->sys_area_erase_fail_count_raw));
json_object_add_value_uint(root, "Sys area erase fail count noralized",
log->sys_area_erase_fail_count_normalized);
json_object_add_value_uint(root, "Max peak power capability",
le16_to_cpu(log->max_peak_power_capability));
json_object_add_value_uint(root, "Current max avg power",
le16_to_cpu(log->current_max_avg_power));
json_object_add_value_uint64(root, "Lifetime power consumed",
int48_to_long(log->lifetime_power_consumed));
memset((void *)ascii, 0, 65);
for (i = 0; i < 8; i++)
ascii += sprintf(ascii, "%c", log->dssd_firmware_revision[i]);
json_object_add_value_string(root, "Dssd firmware revision", ascii_arr);
json_object_add_value_string(root, "Dssd firmware build UUID",
util_uuid_to_string(log->dssd_firmware_build_uuid));
ascii = ascii_arr;
memset((void *)ascii, 0, 65);
for (i = 0; i < 64; i++)
ascii += sprintf(ascii, "%c", log->dssd_firmware_build_label[i]);
json_object_add_value_string(root, "Dssd firmware build label", ascii_arr);
fallthrough;
case 4:
json_object_add_value_uint(root, "NVMe Command Set Errata Version",
log->nvme_cmdset_errata_version);
json_object_add_value_uint(root, "Lowest Permitted Firmware Revision",
le64_to_cpu(log->lowest_permitted_fw_rev));
fallthrough;
case 2 ... 3:
json_object_add_value_uint(root, "Errata Version Field",
log->dssd_errata_version);
memcpy(&dssd_version, log->dssd_point_version, sizeof(dssd_version));
json_object_add_value_uint(root, "Point Version Field",
le16_to_cpu(dssd_version));
memcpy(&dssd_version, log->dssd_minor_version, sizeof(dssd_version));
json_object_add_value_uint(root, "Minor Version Field",
le16_to_cpu(dssd_version));
json_object_add_value_uint(root, "Major Version Field",
log->dssd_major_version);
json_object_add_value_uint(root, "NVMe Base Errata Version",
log->nvme_base_errata_version);
json_object_add_value_uint(root, "PCIe Link Retraining Count",
le64_to_cpu(log->pcie_link_retaining_count));
json_object_add_value_uint(root, "Power State Change Count",
le64_to_cpu(log->power_state_change_count));
}
json_print_object(root, NULL);
printf("\n");
json_free_object(root);
}

static void json_smart_extended_log_v2(struct ocp_smart_extended_log *log)
static void json_smart_extended_log(struct ocp_smart_extended_log *log)
{
struct json_object *root;
struct json_object *pmuw;
Expand Down Expand Up @@ -466,17 +302,6 @@ static void json_smart_extended_log_v2(struct ocp_smart_extended_log *log)
json_free_object(root);
}

static void json_smart_extended_log(struct ocp_smart_extended_log *log, unsigned int version)
{
switch (version) {
default:
case 1:
json_smart_extended_log_v1(log);
break;
case 2:
json_smart_extended_log_v2(log);
}
}
static void json_telemetry_log(struct ocp_telemetry_parse_options *options)
{
print_ocp_telemetry_json(options);
Expand Down
2 changes: 1 addition & 1 deletion plugins/ocp/ocp-print-stdout.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ static void stdout_fw_activation_history(const struct fw_activation_history *fw_
printf("\n");
}

static void stdout_smart_extended_log(struct ocp_smart_extended_log *log, unsigned int version)
static void stdout_smart_extended_log(struct ocp_smart_extended_log *log)
{
uint16_t smart_log_ver = 0;
uint16_t dssd_version = 0;
Expand Down
4 changes: 2 additions & 2 deletions plugins/ocp/ocp-print.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ void ocp_fw_act_history(const struct fw_activation_history *fw_history, nvme_pri
ocp_print(fw_act_history, flags, fw_history);
}

void ocp_smart_extended_log(struct ocp_smart_extended_log *log, unsigned int version,
void ocp_smart_extended_log(struct ocp_smart_extended_log *log,
nvme_print_flags_t flags)
{
ocp_print(smart_extended_log, flags, log, version);
ocp_print(smart_extended_log, flags, log);
}

void ocp_show_telemetry_log(struct ocp_telemetry_parse_options *options, nvme_print_flags_t flags)
Expand Down
6 changes: 3 additions & 3 deletions plugins/ocp/ocp-print.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
struct ocp_print_ops {
void (*hwcomp_log)(struct hwcomp_log *log, __u32 id, bool list);
void (*fw_act_history)(const struct fw_activation_history *fw_history);
void (*smart_extended_log)(struct ocp_smart_extended_log *log, unsigned int version);
void (*smart_extended_log)(struct ocp_smart_extended_log *log);
void (*telemetry_log)(struct ocp_telemetry_parse_options *options);
void (*c3_log)(struct nvme_transport_handle *hdl, struct ssd_latency_monitor_log *log_data);
void (*c5_log)(struct nvme_transport_handle *hdl, struct unsupported_requirement_log *log_data);
Expand All @@ -37,8 +37,8 @@ static inline struct ocp_print_ops *ocp_get_json_print_ops(nvme_print_flags_t fl

void ocp_show_hwcomp_log(struct hwcomp_log *log, __u32 id, bool list, nvme_print_flags_t flags);
void ocp_fw_act_history(const struct fw_activation_history *fw_history, nvme_print_flags_t flags);
void ocp_smart_extended_log(struct ocp_smart_extended_log *log, unsigned int version,
nvme_print_flags_t flags);
void ocp_smart_extended_log(struct ocp_smart_extended_log *log,
nvme_print_flags_t flags);
void ocp_show_telemetry_log(struct ocp_telemetry_parse_options *options, nvme_print_flags_t flags);
void ocp_c3_log(struct nvme_transport_handle *hdl, struct ssd_latency_monitor_log *log_data,
nvme_print_flags_t flags);
Expand Down
11 changes: 3 additions & 8 deletions plugins/ocp/ocp-smart-extended-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ static __u8 scao_guid[GUID_LEN] = {
0xC9, 0x14, 0xD5, 0xAF
};

static int get_c0_log_page(struct nvme_transport_handle *hdl, char *format,
unsigned int format_version)
static int get_c0_log_page(struct nvme_transport_handle *hdl, char *format)
{
struct ocp_smart_extended_log *data;
struct nvme_passthru_cmd cmd;
Expand Down Expand Up @@ -86,7 +85,7 @@ static int get_c0_log_page(struct nvme_transport_handle *hdl, char *format,
}

/* print the data */
ocp_smart_extended_log(data, format_version, fmt);
ocp_smart_extended_log(data, fmt);
} else {
fprintf(stderr, "ERROR : OCP : Unable to read C0 data from buffer\n");
}
Expand All @@ -106,26 +105,22 @@ int ocp_smart_add_log(int argc, char **argv, struct command *acmd,

struct config {
char *output_format;
unsigned int output_format_version;
};

struct config cfg = {
.output_format = "normal",
.output_format_version = 1,
};

OPT_ARGS(opts) = {
OPT_FMT("output-format", 'o', &cfg.output_format, "output Format: normal|json"),
OPT_UINT("output-format-version", 0, &cfg.output_format_version, "output Format version: 1|2"),
OPT_END()
};

ret = parse_and_open(&ctx, &hdl, argc, argv, desc, opts);
if (ret)
return ret;

ret = get_c0_log_page(hdl, cfg.output_format,
cfg.output_format_version);
ret = get_c0_log_page(hdl, cfg.output_format);
if (ret)
fprintf(stderr, "ERROR : OCP : Failure reading the C0 Log Page, ret = %d\n",
ret);
Expand Down