Skip to content

Commit

Permalink
plugins/ocp: Use structure for ocp smart log
Browse files Browse the repository at this point in the history
printed log tested (same), except below
Remove wrong duplicated prints from stdout
  NVMe base errata version
  NVMe command set errata version

Signed-off-by: Steven Seungcheol Lee <[email protected]>
  • Loading branch information
sc108-lee committed Dec 7, 2024
1 parent 4f82fd2 commit e1426d6
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 130 deletions.
83 changes: 41 additions & 42 deletions plugins/ocp/ocp-print-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,85 +136,84 @@ static void json_fw_activation_history(const struct fw_activation_history *fw_hi
printf("\n");
}

static void json_smart_extended_log(void *data)
static void json_smart_extended_log(struct ocp_smart_extended_log *log)
{
struct json_object *root;
struct json_object *pmuw;
struct json_object *pmur;
uint16_t smart_log_ver = 0;
__u8 *log_data = data;
char guid[40];

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

json_object_add_value_uint64(pmuw, "hi",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW + 8] & 0xFFFFFFFFFFFFFFFF));
le64_to_cpu(*(uint64_t *)&log->physical_media_units_written[8]));
json_object_add_value_uint64(pmuw, "lo",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW] & 0xFFFFFFFFFFFFFFFF));
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",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR + 8] & 0xFFFFFFFFFFFFFFFF));
le64_to_cpu(*(uint64_t *)&log->physical_media_units_read[8]));
json_object_add_value_uint64(pmur, "lo",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR] & 0xFFFFFFFFFFFFFFFF));
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",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BUNBR] & 0x0000FFFFFFFFFFFF));
int48_to_long(log->bad_user_nand_blocks_raw));
json_object_add_value_uint(root, "Bad user nand blocks - Normalized",
(uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BUNBN]));
le16_to_cpu(log->bad_user_nand_blocks_normalized));
json_object_add_value_uint64(root, "Bad system nand blocks - Raw",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BSNBR] & 0x0000FFFFFFFFFFFF));
int48_to_long(log->bad_system_nand_blocks_raw));
json_object_add_value_uint(root, "Bad system nand blocks - Normalized",
(uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BSNBN]));
le16_to_cpu(log->bad_system_nand_blocks_normalized));
json_object_add_value_uint64(root, "XOR recovery count",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_XRC]));
le64_to_cpu(log->xor_recovery_count));
json_object_add_value_uint64(root, "Uncorrectable read error count",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_UREC]));
le64_to_cpu(log->uncorrectable_read_err_count));
json_object_add_value_uint64(root, "Soft ecc error count",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_SEEC]));
le64_to_cpu(log->soft_ecc_err_count));
json_object_add_value_uint(root, "End to end detected errors",
(uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_EEDC]));
le32_to_cpu(log->end_to_end_detected_err));
json_object_add_value_uint(root, "End to end corrected errors",
(uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_EECE]));
le32_to_cpu(log->end_to_end_corrected_err));
json_object_add_value_uint(root, "System data percent used",
(__u8)log_data[SCAO_SDPU]);
log->system_data_used_percent);
json_object_add_value_uint64(root, "Refresh counts",
(uint64_t)(le64_to_cpu(*(uint64_t *)&log_data[SCAO_RFSC]) & 0x00FFFFFFFFFFFFFF));
le64_to_cpu(*(uint64_t *)&log->refresh_counts) & 0x00FFFFFFFFFFFFFF);
json_object_add_value_uint(root, "Max User data erase counts",
(uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_MXUDEC]));
le32_to_cpu(log->user_data_erase_count_max));
json_object_add_value_uint(root, "Min User data erase counts",
(uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_MNUDEC]));
le32_to_cpu(log->user_data_erase_count_min));
json_object_add_value_uint(root, "Number of Thermal throttling events",
(__u8)log_data[SCAO_NTTE]);
log->thermal_throttling_event_count);
json_object_add_value_uint(root, "Current throttling status",
(__u8)log_data[SCAO_CTS]);
log->thermal_throttling_current_status);
json_object_add_value_uint64(root, "PCIe correctable error count",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PCEC]));
le64_to_cpu(log->pcie_correctable_err_count));
json_object_add_value_uint(root, "Incomplete shutdowns",
(uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_ICS]));
le32_to_cpu(log->incomplete_shoutdowns));
json_object_add_value_uint(root, "Percent free blocks",
(__u8)log_data[SCAO_PFB]);
log->percent_free_blocks);
json_object_add_value_uint(root, "Capacitor health",
(uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_CPH]));
le16_to_cpu(log->capacitor_health));
json_object_add_value_uint64(root, "Unaligned I/O",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_UIO]));
le64_to_cpu(log->unaligned_io));
json_object_add_value_uint64(root, "Security Version Number",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_SVN]));
le64_to_cpu(log->security_version));
json_object_add_value_uint64(root, "NUSE - Namespace utilization",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_NUSE]));
le64_to_cpu(log->total_nuse));
json_object_add_value_uint128(root, "PLP start count",
le128_to_cpu(&log_data[SCAO_PSC]));
le128_to_cpu(log->plp_start_count));
json_object_add_value_uint128(root, "Endurance estimate",
le128_to_cpu(&log_data[SCAO_EEST]));
smart_log_ver = (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_LPV]);
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"",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_LPG + 8]),
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_LPG]));
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) {
Expand All @@ -223,25 +222,25 @@ static void json_smart_extended_log(void *data)
default:
case 4:
json_object_add_value_uint(root, "NVMe Command Set Errata Version",
(__u8)log_data[SCAO_NCSEV]);
log->nvme_cmdset_errata_version);
json_object_add_value_uint(root, "Lowest Permitted Firmware Revision",
le64_to_cpu(*(uint64_t *)&log_data[SCAO_PSCC]));
le64_to_cpu(log->lowest_permitted_fw_rev));
fallthrough;
case 2 ... 3:
json_object_add_value_uint(root, "Errata Version Field",
(__u8)log_data[SCAO_EVF]);
log->dssd_errata_version);
json_object_add_value_uint(root, "Point Version Field",
le16_to_cpu(*(uint16_t *)&log_data[SCAO_PVF]));
le16_to_cpu(log->dssd_point_version));
json_object_add_value_uint(root, "Minor Version Field",
le16_to_cpu(*(uint16_t *)&log_data[SCAO_MIVF]));
le16_to_cpu(log->dssd_minor_version));
json_object_add_value_uint(root, "Major Version Field",
(__u8)log_data[SCAO_MAVF]);
log->dssd_major_version);
json_object_add_value_uint(root, "NVMe Base Errata Version",
(__u8)log_data[SCAO_NBEV]);
log->nvme_base_errata_version);
json_object_add_value_uint(root, "PCIe Link Retraining Count",
le64_to_cpu(*(uint64_t *)&log_data[SCAO_PLRC]));
le64_to_cpu(log->pcie_link_retaining_count));
json_object_add_value_uint(root, "Power State Change Count",
le64_to_cpu(*(uint64_t *)&log_data[SCAO_PSCC]));
le64_to_cpu(log->power_state_change_count));
}
json_print_object(root, NULL);
printf("\n");
Expand Down
87 changes: 41 additions & 46 deletions plugins/ocp/ocp-print-stdout.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,101 +98,96 @@ static void stdout_fw_activation_history(const struct fw_activation_history *fw_
printf("\n");
}

static void stdout_smart_extended_log(void *data)
static void stdout_smart_extended_log(struct ocp_smart_extended_log *log)
{
uint16_t smart_log_ver = 0;
__u8 *log_data = data;

printf("SMART Cloud Attributes :-\n");

printf(" Physical media units written - %"PRIu64" %"PRIu64"\n",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW + 8] & 0xFFFFFFFFFFFFFFFF),
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW] & 0xFFFFFFFFFFFFFFFF));
le64_to_cpu(*(uint64_t *)&log->physical_media_units_written[8]),
le64_to_cpu(*(uint64_t *)&log->physical_media_units_written));
printf(" Physical media units read - %"PRIu64" %"PRIu64"\n",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR + 8] & 0xFFFFFFFFFFFFFFFF),
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR] & 0xFFFFFFFFFFFFFFFF));
le64_to_cpu(*(uint64_t *)&log->physical_media_units_read[8]),
le64_to_cpu(*(uint64_t *)&log->physical_media_units_read));
printf(" Bad user nand blocks - Raw %"PRIu64"\n",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BUNBR] & 0x0000FFFFFFFFFFFF));
int48_to_long(log->bad_user_nand_blocks_raw));
printf(" Bad user nand blocks - Normalized %d\n",
(uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BUNBN]));
le16_to_cpu(log->bad_user_nand_blocks_normalized));
printf(" Bad system nand blocks - Raw %"PRIu64"\n",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BSNBR] & 0x0000FFFFFFFFFFFF));
int48_to_long(log->bad_system_nand_blocks_raw));
printf(" Bad system nand blocks - Normalized %d\n",
(uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BSNBN]));
le16_to_cpu(log->bad_system_nand_blocks_normalized));
printf(" XOR recovery count %"PRIu64"\n",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_XRC]));
le64_to_cpu(log->xor_recovery_count));
printf(" Uncorrectable read error count %"PRIu64"\n",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_UREC]));
le64_to_cpu(log->uncorrectable_read_err_count));
printf(" Soft ecc error count %"PRIu64"\n",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_SEEC]));
le64_to_cpu(log->soft_ecc_err_count));
printf(" End to end detected errors %"PRIu32"\n",
(uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_EEDC]));
le32_to_cpu(log->end_to_end_detected_err));
printf(" End to end corrected errors %"PRIu32"\n",
(uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_EECE]));
le32_to_cpu(log->end_to_end_corrected_err));
printf(" System data percent used %d\n",
(__u8)log_data[SCAO_SDPU]);
log->system_data_used_percent);
printf(" Refresh counts %"PRIu64"\n",
(uint64_t)(le64_to_cpu(*(uint64_t *)&log_data[SCAO_RFSC]) & 0x00FFFFFFFFFFFFFF));
le64_to_cpu(*(uint64_t *)&log->refresh_counts) & 0x00FFFFFFFFFFFFFF);
printf(" Max User data erase counts %"PRIu32"\n",
(uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_MXUDEC]));
le32_to_cpu(log->user_data_erase_count_max));
printf(" Min User data erase counts %"PRIu32"\n",
(uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_MNUDEC]));
le32_to_cpu(log->user_data_erase_count_min));
printf(" Number of Thermal throttling events %d\n",
(__u8)log_data[SCAO_NTTE]);
log->thermal_throttling_event_count);
printf(" Current throttling status 0x%x\n",
(__u8)log_data[SCAO_CTS]);
log->thermal_throttling_current_status);
printf(" PCIe correctable error count %"PRIu64"\n",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PCEC]));
le64_to_cpu(log->pcie_correctable_err_count));
printf(" Incomplete shutdowns %"PRIu32"\n",
(uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_ICS]));
le32_to_cpu(log->incomplete_shoutdowns));
printf(" Percent free blocks %d\n",
(__u8)log_data[SCAO_PFB]);
log->percent_free_blocks);
printf(" Capacitor health %"PRIu16"\n",
(uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_CPH]));
printf(" NVMe base errata version %c\n",
(uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_CPH]));
printf(" NVMe command set errata version %c\n",
(uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_CPH]));
le16_to_cpu(log->capacitor_health));
printf(" Unaligned I/O %"PRIu64"\n",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_UIO]));
le64_to_cpu(log->unaligned_io));
printf(" Security Version Number %"PRIu64"\n",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_SVN]));
le64_to_cpu(log->security_version));
printf(" NUSE - Namespace utilization %"PRIu64"\n",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_NUSE]));
le64_to_cpu(log->total_nuse));
printf(" PLP start count %s\n",
uint128_t_to_string(le128_to_cpu(&log_data[SCAO_PSC])));
uint128_t_to_string(le128_to_cpu(log->plp_start_count)));
printf(" Endurance estimate %s\n",
uint128_t_to_string(le128_to_cpu(&log_data[SCAO_EEST])));
smart_log_ver = (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_LPV]);
uint128_t_to_string(le128_to_cpu(log->endurance_estimate)));
smart_log_ver = le16_to_cpu(log->log_page_version);
printf(" Log page version %"PRIu16"\n", smart_log_ver);
printf(" Log page GUID 0x");
printf("%"PRIx64"%"PRIx64"\n", (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_LPG + 8]),
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_LPG]));
printf("%"PRIx64"%"PRIx64"\n", le64_to_cpu(*(uint64_t *)&log->log_page_guid[8]),
le64_to_cpu(*(uint64_t *)&log->log_page_guid));
switch (smart_log_ver) {
case 0 ... 1:
break;
default:
case 4:
printf(" NVMe Command Set Errata Version %d\n",
(__u8)log_data[SCAO_NCSEV]);
log->nvme_cmdset_errata_version);
printf(" Lowest Permitted Firmware Revision %"PRIu64"\n",
le64_to_cpu(*(uint64_t *)&log_data[SCAO_PSCC]));
le64_to_cpu(log->lowest_permitted_fw_rev));
fallthrough;
case 2 ... 3:
printf(" Errata Version Field %d\n",
(__u8)log_data[SCAO_EVF]);
log->dssd_errata_version);
printf(" Point Version Field %"PRIu16"\n",
le16_to_cpu(*(uint16_t *)&log_data[SCAO_PVF]));
le16_to_cpu(log->dssd_point_version));
printf(" Minor Version Field %"PRIu16"\n",
le16_to_cpu(*(uint16_t *)&log_data[SCAO_MIVF]));
le16_to_cpu(log->dssd_minor_version));
printf(" Major Version Field %d\n",
(__u8)log_data[SCAO_MAVF]);
log->dssd_major_version);
printf(" NVMe Base Errata Version %d\n",
(__u8)log_data[SCAO_NBEV]);
log->nvme_base_errata_version);
printf(" PCIe Link Retraining Count %"PRIu64"\n",
(uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PLRC]));
le64_to_cpu(log->pcie_link_retaining_count));
printf(" Power State Change Count %"PRIu64"\n",
le64_to_cpu(*(uint64_t *)&log_data[SCAO_PSCC]));
le64_to_cpu(log->power_state_change_count));
}
printf("\n");
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/ocp/ocp-print.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

#include "ocp-hardware-component-log.h"
#include "ocp-fw-activation-history.h"
#include "ocp-smart-extended-log.h"
#include "ocp-telemetry-decode.h"
#include "ocp-nvme.h"

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)(void *data);
void (*smart_extended_log)(struct ocp_smart_extended_log *log);
void (*telemetry_log)(struct ocp_telemetry_parse_options *options);
void (*c3_log)(struct nvme_dev *dev, struct ssd_latency_monitor_log *log_data);
void (*c5_log)(struct nvme_dev *dev, struct unsupported_requirement_log *log_data);
Expand Down
6 changes: 3 additions & 3 deletions plugins/ocp/ocp-smart-extended-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static __u8 scao_guid[GUID_LEN] = {
static int get_c0_log_page(struct nvme_dev *dev, char *format)
{
nvme_print_flags_t fmt;
__u8 *data;
struct ocp_smart_extended_log *data;
int i;
int ret;
int fd = dev_fd(dev);
Expand Down Expand Up @@ -67,7 +67,7 @@ static int get_c0_log_page(struct nvme_dev *dev, char *format)
/* check log page guid */
/* Verify GUID matches */
for (i = 0; i < 16; i++) {
if (scao_guid[i] != data[SCAO_LPG + i]) {
if (scao_guid[i] != data->log_page_guid[i]) {
int j;

fprintf(stderr, "ERROR : OCP : Unknown GUID in C0 Log Page data\n");
Expand All @@ -77,7 +77,7 @@ static int get_c0_log_page(struct nvme_dev *dev, char *format)

fprintf(stderr, "\nERROR : OCP : Actual GUID: 0x");
for (j = 0; j < 16; j++)
fprintf(stderr, "%x", data[SCAO_LPG + j]);
fprintf(stderr, "%x", data->log_page_guid[j]);
fprintf(stderr, "\n");

ret = -1;
Expand Down
Loading

0 comments on commit e1426d6

Please sign in to comment.