From 7fdaa7210afc47b3f1386d9c0d2a8120ddbd3733 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 22 Dec 2024 15:03:19 +0900 Subject: [PATCH 1/5] ocp: replace to use json_object_* macros to obj_* macros Since currently mixed to use them in ocp-print-json.c then unify. Signed-off-by: Tokunori Ikegami --- nvme-print-json.c | 7 - nvme-print.h | 7 + plugins/ocp/ocp-print-json.c | 754 ++++++++++++++++------------------- 3 files changed, 353 insertions(+), 415 deletions(-) diff --git a/nvme-print-json.c b/nvme-print-json.c index 09d37dce19..15ea9f7155 100644 --- a/nvme-print-json.c +++ b/nvme-print-json.c @@ -22,13 +22,6 @@ #define array_add_obj json_array_add_value_object #define array_add_str json_array_add_value_string -#define obj_add_array json_object_add_value_array -#define obj_add_int json_object_add_value_int -#define obj_add_obj json_object_add_value_object -#define obj_add_uint json_object_add_value_uint -#define obj_add_uint128 json_object_add_value_uint128 -#define obj_add_uint64 json_object_add_value_uint64 - static const uint8_t zero_uuid[16] = { 0 }; static struct print_ops json_print_ops; static struct json_object *json_r; diff --git a/nvme-print.h b/nvme-print.h index 304d712a5a..43cfd4a9cf 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -21,6 +21,13 @@ typedef struct nvme_effects_log_node { #define STR_LEN 100 #define obj_add_str json_object_add_value_string +#define obj_add_int json_object_add_value_int +#define obj_add_uint json_object_add_value_uint +#define obj_add_uint64 json_object_add_value_uint64 +#define obj_add_uint128 json_object_add_value_uint128 +#define obj_add_obj json_object_add_value_object +#define obj_add_array json_object_add_value_array +#define obj_new_str_len json_object_new_string_len void d(unsigned char *buf, int len, int width, int group); void d_raw(unsigned char *buf, unsigned len); diff --git a/plugins/ocp/ocp-print-json.c b/plugins/ocp/ocp-print-json.c index 17789cbd44..10d85e0101 100644 --- a/plugins/ocp/ocp-print-json.c +++ b/plugins/ocp/ocp-print-json.c @@ -84,9 +84,10 @@ static void json_hwcomp_log(struct hwcomp_log *log, __u32 id, bool list) static void json_fw_activation_history(const struct fw_activation_history *fw_history) { struct json_object *root = json_create_object(); + struct json_object *fw; - json_object_add_value_uint(root, "log identifier", fw_history->log_id); - json_object_add_value_uint(root, "valid entries", le32_to_cpu(fw_history->valid_entries)); + obj_add_uint(root, "log identifier", fw_history->log_id); + obj_add_uint(root, "valid entries", le32_to_cpu(fw_history->valid_entries)); struct json_object *entries = json_create_array(); @@ -94,41 +95,37 @@ static void json_fw_activation_history(const struct fw_activation_history *fw_hi const struct fw_activation_history_entry *entry = &fw_history->entries[index]; struct json_object *entry_obj = json_create_object(); - json_object_add_value_uint(entry_obj, "version number", entry->ver_num); - json_object_add_value_uint(entry_obj, "entry length", entry->entry_length); - json_object_add_value_uint(entry_obj, "activation count", - le16_to_cpu(entry->activation_count)); - json_object_add_value_uint64(entry_obj, "timestamp", - (0x0000FFFFFFFFFFFF & le64_to_cpu(entry->timestamp))); - json_object_add_value_uint(entry_obj, "power cycle count", - le64_to_cpu(entry->power_cycle_count)); + obj_add_uint(entry_obj, "version number", entry->ver_num); + obj_add_uint(entry_obj, "entry length", entry->entry_length); + obj_add_uint(entry_obj, "activation count", le16_to_cpu(entry->activation_count)); + obj_add_uint64(entry_obj, "timestamp", + (0x0000FFFFFFFFFFFF & le64_to_cpu(entry->timestamp))); + obj_add_uint(entry_obj, "power cycle count", le64_to_cpu(entry->power_cycle_count)); - struct json_object *fw = json_object_new_string_len(entry->previous_fw, - sizeof(entry->previous_fw)); + fw = obj_new_str_len(entry->previous_fw, sizeof(entry->previous_fw)); - json_object_add_value_object(entry_obj, "previous firmware", fw); + obj_add_obj(entry_obj, "previous firmware", fw); - fw = json_object_new_string_len(entry->new_fw, sizeof(entry->new_fw)); + fw = obj_new_str_len(entry->new_fw, sizeof(entry->new_fw)); - json_object_add_value_object(entry_obj, "new firmware", fw); - json_object_add_value_uint(entry_obj, "slot number", entry->slot_number); - json_object_add_value_uint(entry_obj, "commit action type", entry->commit_action); - json_object_add_value_uint(entry_obj, "result", le16_to_cpu(entry->result)); + obj_add_obj(entry_obj, "new firmware", fw); + obj_add_uint(entry_obj, "slot number", entry->slot_number); + obj_add_uint(entry_obj, "commit action type", entry->commit_action); + obj_add_uint(entry_obj, "result", le16_to_cpu(entry->result)); json_array_add_value_object(entries, entry_obj); } - json_object_add_value_array(root, "entries", entries); + obj_add_array(root, "entries", entries); - json_object_add_value_uint(root, "log page version", - le16_to_cpu(fw_history->log_page_version)); + obj_add_uint(root, "log page version", le16_to_cpu(fw_history->log_page_version)); char guid[2 * sizeof(fw_history->log_page_guid) + 3] = { 0 }; sprintf(guid, "0x%"PRIx64"%"PRIx64"", le64_to_cpu(fw_history->log_page_guid[1]), le64_to_cpu(fw_history->log_page_guid[0])); - json_object_add_value_string(root, "log page guid", guid); + obj_add_str(root, "log page guid", guid); json_print_object(root, NULL); json_free_object(root); @@ -149,99 +146,89 @@ static void json_smart_extended_log_v1(void *data) 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)); - json_object_add_value_uint64(pmuw, "lo", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW] & 0xFFFFFFFFFFFFFFFF)); - 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)); - json_object_add_value_uint64(pmur, "lo", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR] & 0xFFFFFFFFFFFFFFFF)); - 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)); - json_object_add_value_uint(root, "Bad user nand blocks - Normalized", - (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BUNBN])); - json_object_add_value_uint64(root, "Bad system nand blocks - Raw", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BSNBR] & 0x0000FFFFFFFFFFFF)); - json_object_add_value_uint(root, "Bad system nand blocks - Normalized", - (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BSNBN])); - json_object_add_value_uint64(root, "XOR recovery count", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_XRC])); - json_object_add_value_uint64(root, "Uncorrectable read error count", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_UREC])); - json_object_add_value_uint64(root, "Soft ecc error count", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_SEEC])); - json_object_add_value_uint(root, "End to end detected errors", - (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_EEDC])); - json_object_add_value_uint(root, "End to end corrected errors", - (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_EECE])); - json_object_add_value_uint(root, "System data percent used", - (__u8)log_data[SCAO_SDPU]); - json_object_add_value_uint64(root, "Refresh counts", - (uint64_t)(le64_to_cpu(*(uint64_t *)&log_data[SCAO_RFSC]) & 0x00FFFFFFFFFFFFFF)); - json_object_add_value_uint(root, "Max User data erase counts", - (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_MXUDEC])); - json_object_add_value_uint(root, "Min User data erase counts", - (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_MNUDEC])); - json_object_add_value_uint(root, "Number of Thermal throttling events", - (__u8)log_data[SCAO_NTTE]); - json_object_add_value_uint(root, "Current throttling status", - (__u8)log_data[SCAO_CTS]); - json_object_add_value_uint64(root, "PCIe correctable error count", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PCEC])); - json_object_add_value_uint(root, "Incomplete shutdowns", - (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_ICS])); - json_object_add_value_uint(root, "Percent free blocks", - (__u8)log_data[SCAO_PFB]); - json_object_add_value_uint(root, "Capacitor health", - (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_CPH])); - json_object_add_value_uint64(root, "Unaligned I/O", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_UIO])); - json_object_add_value_uint64(root, "Security Version Number", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_SVN])); - json_object_add_value_uint64(root, "NUSE - Namespace utilization", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_NUSE])); - json_object_add_value_uint128(root, "PLP start count", - le128_to_cpu(&log_data[SCAO_PSC])); - json_object_add_value_uint128(root, "Endurance estimate", - le128_to_cpu(&log_data[SCAO_EEST])); + obj_add_uint64(pmuw, "hi", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW + 8] & 0xFFFFFFFFFFFFFFFF)); + obj_add_uint64(pmuw, "lo", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW] & 0xFFFFFFFFFFFFFFFF)); + obj_add_obj(root, "Physical media units written", pmuw); + obj_add_uint64(pmur, "hi", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR + 8] & 0xFFFFFFFFFFFFFFFF)); + obj_add_uint64(pmur, "lo", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR] & 0xFFFFFFFFFFFFFFFF)); + obj_add_obj(root, "Physical media units read", pmur); + obj_add_uint64(root, "Bad user nand blocks - Raw", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BUNBR] & 0x0000FFFFFFFFFFFF)); + obj_add_uint(root, "Bad user nand blocks - Normalized", + (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BUNBN])); + obj_add_uint64(root, "Bad system nand blocks - Raw", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BSNBR] & 0x0000FFFFFFFFFFFF)); + obj_add_uint(root, "Bad system nand blocks - Normalized", + (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BSNBN])); + obj_add_uint64(root, "XOR recovery count", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_XRC])); + obj_add_uint64(root, "Uncorrectable read error count", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_UREC])); + obj_add_uint64(root, "Soft ecc error count", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_SEEC])); + obj_add_uint(root, "End to end detected errors", + (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_EEDC])); + obj_add_uint(root, "End to end corrected errors", + (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_EECE])); + obj_add_uint(root, "System data percent used", (__u8)log_data[SCAO_SDPU]); + obj_add_uint64(root, "Refresh counts", + (uint64_t)(le64_to_cpu(*(uint64_t *)&log_data[SCAO_RFSC]) & 0x00FFFFFFFFFFFFFF)); + obj_add_uint(root, "Max User data erase counts", + (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_MXUDEC])); + obj_add_uint(root, "Min User data erase counts", + (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_MNUDEC])); + obj_add_uint(root, "Number of Thermal throttling events", (__u8)log_data[SCAO_NTTE]); + obj_add_uint(root, "Current throttling status", (__u8)log_data[SCAO_CTS]); + obj_add_uint64(root, "PCIe correctable error count", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PCEC])); + obj_add_uint(root, "Incomplete shutdowns", + (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_ICS])); + obj_add_uint(root, "Percent free blocks", (__u8)log_data[SCAO_PFB]); + obj_add_uint(root, "Capacitor health", + (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_CPH])); + obj_add_uint64(root, "Unaligned I/O", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_UIO])); + obj_add_uint64(root, "Security Version Number", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_SVN])); + obj_add_uint64(root, "NUSE - Namespace utilization", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_NUSE])); + obj_add_uint128(root, "PLP start count", le128_to_cpu(&log_data[SCAO_PSC])); + obj_add_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]); - json_object_add_value_uint(root, "Log page version", smart_log_ver); + obj_add_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])); - json_object_add_value_string(root, "Log page GUID", guid); + obj_add_str(root, "Log page GUID", guid); switch (smart_log_ver) { case 0 ... 1: break; default: case 4: - json_object_add_value_uint(root, "NVMe Command Set Errata Version", - (__u8)log_data[SCAO_NCSEV]); - json_object_add_value_uint(root, "Lowest Permitted Firmware Revision", - le64_to_cpu(*(uint64_t *)&log_data[SCAO_PSCC])); + obj_add_uint(root, "NVMe Command Set Errata Version", (__u8)log_data[SCAO_NCSEV]); + obj_add_uint(root, "Lowest Permitted Firmware Revision", + le64_to_cpu(*(uint64_t *)&log_data[SCAO_PSCC])); fallthrough; case 2 ... 3: - json_object_add_value_uint(root, "Errata Version Field", - (__u8)log_data[SCAO_EVF]); - json_object_add_value_uint(root, "Point Version Field", - le16_to_cpu(*(uint16_t *)&log_data[SCAO_PVF])); - json_object_add_value_uint(root, "Minor Version Field", - le16_to_cpu(*(uint16_t *)&log_data[SCAO_MIVF])); - json_object_add_value_uint(root, "Major Version Field", - (__u8)log_data[SCAO_MAVF]); - json_object_add_value_uint(root, "NVMe Base Errata Version", - (__u8)log_data[SCAO_NBEV]); - json_object_add_value_uint(root, "PCIe Link Retraining Count", - le64_to_cpu(*(uint64_t *)&log_data[SCAO_PLRC])); - json_object_add_value_uint(root, "Power State Change Count", - le64_to_cpu(*(uint64_t *)&log_data[SCAO_PSCC])); + obj_add_uint(root, "Errata Version Field", (__u8)log_data[SCAO_EVF]); + obj_add_uint(root, "Point Version Field", + le16_to_cpu(*(uint16_t *)&log_data[SCAO_PVF])); + obj_add_uint(root, "Minor Version Field", + le16_to_cpu(*(uint16_t *)&log_data[SCAO_MIVF])); + obj_add_uint(root, "Major Version Field", (__u8)log_data[SCAO_MAVF]); + obj_add_uint(root, "NVMe Base Errata Version", (__u8)log_data[SCAO_NBEV]); + obj_add_uint(root, "PCIe Link Retraining Count", + le64_to_cpu(*(uint64_t *)&log_data[SCAO_PLRC])); + obj_add_uint(root, "Power State Change Count", + le64_to_cpu(*(uint64_t *)&log_data[SCAO_PSCC])); } json_print_object(root, NULL); printf("\n"); @@ -261,99 +248,89 @@ static void json_smart_extended_log_v2(void *data) 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)); - json_object_add_value_uint64(pmuw, "lo", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW] & 0xFFFFFFFFFFFFFFFF)); - 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)); - json_object_add_value_uint64(pmur, "lo", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR] & 0xFFFFFFFFFFFFFFFF)); - 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)); - json_object_add_value_uint(root, "bad_user_nand_blocks_normalized", - (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BUNBN])); - json_object_add_value_uint64(root, "bad_system_nand_blocks_raw", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BSNBR] & 0x0000FFFFFFFFFFFF)); - json_object_add_value_uint(root, "bad_system_nand_blocks_normalized", - (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BSNBN])); - json_object_add_value_uint64(root, "xor_recovery_count", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_XRC])); - json_object_add_value_uint64(root, "uncorrectable_read_errors", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_UREC])); - json_object_add_value_uint64(root, "soft_ecc_error_count", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_SEEC])); - json_object_add_value_uint(root, "end_to_end_detected_errors", - (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_EEDC])); - json_object_add_value_uint(root, "end_to_end_corrected_errors", - (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_EECE])); - json_object_add_value_uint(root, "system_data_percent_used", - (__u8)log_data[SCAO_SDPU]); - json_object_add_value_uint64(root, "refresh_count", - (uint64_t)(le64_to_cpu(*(uint64_t *)&log_data[SCAO_RFSC]) & 0x00FFFFFFFFFFFFFF)); - json_object_add_value_uint(root, "max_user_data_erase_count", - (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_MXUDEC])); - json_object_add_value_uint(root, "min_user_data_erase_count", - (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_MNUDEC])); - json_object_add_value_uint(root, "thermal_throttling_events", - (__u8)log_data[SCAO_NTTE]); - json_object_add_value_uint(root, "current_throttling_status", - (__u8)log_data[SCAO_CTS]); - json_object_add_value_uint64(root, "pcie_correctable_errors", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PCEC])); - json_object_add_value_uint(root, "incomplete_shutdowns", - (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_ICS])); - json_object_add_value_uint(root, "percent_free_blocks", - (__u8)log_data[SCAO_PFB]); - json_object_add_value_uint(root, "capacitor_health", - (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_CPH])); - json_object_add_value_uint64(root, "unaligned_io", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_UIO])); - json_object_add_value_uint64(root, "security_version_number", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_SVN])); - json_object_add_value_uint64(root, "nuse_namespace_utilization", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_NUSE])); - json_object_add_value_uint128(root, "plp_start_count", - le128_to_cpu(&log_data[SCAO_PSC])); - json_object_add_value_uint128(root, "endurance_estimate", - le128_to_cpu(&log_data[SCAO_EEST])); + obj_add_uint64(pmuw, "hi", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW + 8] & 0xFFFFFFFFFFFFFFFF)); + obj_add_uint64(pmuw, "lo", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW] & 0xFFFFFFFFFFFFFFFF)); + obj_add_obj(root, "physical_media_units_written", pmuw); + obj_add_uint64(pmur, "hi", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR + 8] & 0xFFFFFFFFFFFFFFFF)); + obj_add_uint64(pmur, "lo", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR] & 0xFFFFFFFFFFFFFFFF)); + obj_add_obj(root, "physical_media_units_read", pmur); + obj_add_uint64(root, "bad_user_nand_blocks_raw", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BUNBR] & 0x0000FFFFFFFFFFFF)); + obj_add_uint(root, "bad_user_nand_blocks_normalized", + (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BUNBN])); + obj_add_uint64(root, "bad_system_nand_blocks_raw", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BSNBR] & 0x0000FFFFFFFFFFFF)); + obj_add_uint(root, "bad_system_nand_blocks_normalized", + (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BSNBN])); + obj_add_uint64(root, "xor_recovery_count", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_XRC])); + obj_add_uint64(root, "uncorrectable_read_errors", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_UREC])); + obj_add_uint64(root, "soft_ecc_error_count", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_SEEC])); + obj_add_uint(root, "end_to_end_detected_errors", + (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_EEDC])); + obj_add_uint(root, "end_to_end_corrected_errors", + (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_EECE])); + obj_add_uint(root, "system_data_percent_used", (__u8)log_data[SCAO_SDPU]); + obj_add_uint64(root, "refresh_count", + (uint64_t)(le64_to_cpu(*(uint64_t *)&log_data[SCAO_RFSC]) & 0x00FFFFFFFFFFFFFF)); + obj_add_uint(root, "max_user_data_erase_count", + (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_MXUDEC])); + obj_add_uint(root, "min_user_data_erase_count", + (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_MNUDEC])); + obj_add_uint(root, "thermal_throttling_events", (__u8)log_data[SCAO_NTTE]); + obj_add_uint(root, "current_throttling_status", (__u8)log_data[SCAO_CTS]); + obj_add_uint64(root, "pcie_correctable_errors", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PCEC])); + obj_add_uint(root, "incomplete_shutdowns", + (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_ICS])); + obj_add_uint(root, "percent_free_blocks", (__u8)log_data[SCAO_PFB]); + obj_add_uint(root, "capacitor_health", + (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_CPH])); + obj_add_uint64(root, "unaligned_io", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_UIO])); + obj_add_uint64(root, "security_version_number", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_SVN])); + obj_add_uint64(root, "nuse_namespace_utilization", + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_NUSE])); + obj_add_uint128(root, "plp_start_count", le128_to_cpu(&log_data[SCAO_PSC])); + obj_add_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]); - json_object_add_value_uint(root, "log_page_version", smart_log_ver); + obj_add_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])); - json_object_add_value_string(root, "log_page_guid", guid); + obj_add_str(root, "log_page_guid", guid); switch (smart_log_ver) { case 0 ... 1: break; default: case 4: - json_object_add_value_uint(root, "nvme_command_set_errata_version", - (__u8)log_data[SCAO_NCSEV]); - json_object_add_value_uint(root, "lowest_permitted_firmware_revision", - le64_to_cpu(*(uint64_t *)&log_data[SCAO_PSCC])); + obj_add_uint(root, "nvme_command_set_errata_version", (__u8)log_data[SCAO_NCSEV]); + obj_add_uint(root, "lowest_permitted_firmware_revision", + le64_to_cpu(*(uint64_t *)&log_data[SCAO_PSCC])); fallthrough; case 2 ... 3: - json_object_add_value_uint(root, "errata_version_field", - (__u8)log_data[SCAO_EVF]); - json_object_add_value_uint(root, "point_version_field", - le16_to_cpu(*(uint16_t *)&log_data[SCAO_PVF])); - json_object_add_value_uint(root, "minor_version_field", - le16_to_cpu(*(uint16_t *)&log_data[SCAO_MIVF])); - json_object_add_value_uint(root, "major_version_field", - (__u8)log_data[SCAO_MAVF]); - json_object_add_value_uint(root, "nvme_base_errata_version", - (__u8)log_data[SCAO_NBEV]); - json_object_add_value_uint(root, "pcie_link_retraining_count", - le64_to_cpu(*(uint64_t *)&log_data[SCAO_PLRC])); - json_object_add_value_uint(root, "power_state_change_count", - le64_to_cpu(*(uint64_t *)&log_data[SCAO_PSCC])); + obj_add_uint(root, "errata_version_field", (__u8)log_data[SCAO_EVF]); + obj_add_uint(root, "point_version_field", + le16_to_cpu(*(uint16_t *)&log_data[SCAO_PVF])); + obj_add_uint(root, "minor_version_field", + le16_to_cpu(*(uint16_t *)&log_data[SCAO_MIVF])); + obj_add_uint(root, "major_version_field", (__u8)log_data[SCAO_MAVF]); + obj_add_uint(root, "nvme_base_errata_version", (__u8)log_data[SCAO_NBEV]); + obj_add_uint(root, "pcie_link_retraining_count", + le64_to_cpu(*(uint64_t *)&log_data[SCAO_PLRC])); + obj_add_uint(root, "power_state_change_count", + le64_to_cpu(*(uint64_t *)&log_data[SCAO_PSCC])); } json_print_object(root, NULL); printf("\n"); @@ -387,31 +364,23 @@ static void json_c3_log(struct nvme_dev *dev, struct ssd_latency_monitor_log *lo root = json_create_object(); - json_object_add_value_uint(root, "Feature Status", - log_data->feature_status); - json_object_add_value_uint(root, "Active Bucket Timer", - C3_ACTIVE_BUCKET_TIMER_INCREMENT * - le16_to_cpu(log_data->active_bucket_timer)); - json_object_add_value_uint(root, "Active Bucket Timer Threshold", - C3_ACTIVE_BUCKET_TIMER_INCREMENT * - le16_to_cpu(log_data->active_bucket_timer_threshold)); - json_object_add_value_uint(root, "Active Threshold A", - C3_ACTIVE_THRESHOLD_INCREMENT * - le16_to_cpu(log_data->active_threshold_a + 1)); - json_object_add_value_uint(root, "Active Threshold B", - C3_ACTIVE_THRESHOLD_INCREMENT * - le16_to_cpu(log_data->active_threshold_b + 1)); - json_object_add_value_uint(root, "Active Threshold C", - C3_ACTIVE_THRESHOLD_INCREMENT * - le16_to_cpu(log_data->active_threshold_c + 1)); - json_object_add_value_uint(root, "Active Threshold D", - C3_ACTIVE_THRESHOLD_INCREMENT * - le16_to_cpu(log_data->active_threshold_d + 1)); - json_object_add_value_uint(root, "Active Latency Configuration", - le16_to_cpu(log_data->active_latency_config)); - json_object_add_value_uint(root, "Active Latency Minimum Window", - C3_MINIMUM_WINDOW_INCREMENT * - le16_to_cpu(log_data->active_latency_min_window)); + obj_add_uint(root, "Feature Status", log_data->feature_status); + obj_add_uint(root, "Active Bucket Timer", + C3_ACTIVE_BUCKET_TIMER_INCREMENT * le16_to_cpu(log_data->active_bucket_timer)); + obj_add_uint(root, "Active Bucket Timer Threshold", C3_ACTIVE_BUCKET_TIMER_INCREMENT * + le16_to_cpu(log_data->active_bucket_timer_threshold)); + obj_add_uint(root, "Active Threshold A", + C3_ACTIVE_THRESHOLD_INCREMENT * le16_to_cpu(log_data->active_threshold_a + 1)); + obj_add_uint(root, "Active Threshold B", + C3_ACTIVE_THRESHOLD_INCREMENT * le16_to_cpu(log_data->active_threshold_b + 1)); + obj_add_uint(root, "Active Threshold C", + C3_ACTIVE_THRESHOLD_INCREMENT * le16_to_cpu(log_data->active_threshold_c + 1)); + obj_add_uint(root, "Active Threshold D", + C3_ACTIVE_THRESHOLD_INCREMENT * le16_to_cpu(log_data->active_threshold_d + 1)); + obj_add_uint(root, "Active Latency Configuration", + le16_to_cpu(log_data->active_latency_config)); + obj_add_uint(root, "Active Latency Minimum Window", + C3_MINIMUM_WINDOW_INCREMENT * le16_to_cpu(log_data->active_latency_min_window)); for (i = 0; i < C3_BUCKET_NUM; i++) { struct json_object *bucket; @@ -419,10 +388,10 @@ static void json_c3_log(struct nvme_dev *dev, struct ssd_latency_monitor_log *lo bucket = json_create_object(); sprintf(buf, "Active Bucket Counter: Bucket %d", i); for (j = 2; j >= 0; j--) { - json_object_add_value_uint(bucket, operation[j], - le32_to_cpu(log_data->active_bucket_counter[i][j+1])); + obj_add_uint(bucket, operation[j], + le32_to_cpu(log_data->active_bucket_counter[i][j+1])); } - json_object_add_value_object(root, buf, bucket); + obj_add_obj(root, buf, bucket); } for (i = 0; i < C3_BUCKET_NUM; i++) { @@ -432,14 +401,14 @@ static void json_c3_log(struct nvme_dev *dev, struct ssd_latency_monitor_log *lo sprintf(buf, "Active Latency Time Stamp: Bucket %d", i); for (j = 2; j >= 0; j--) { if (le64_to_cpu(log_data->active_latency_timestamp[3-i][j]) == -1) { - json_object_add_value_string(bucket, operation[j], "NA"); + obj_add_str(bucket, operation[j], "NA"); } else { convert_ts(le64_to_cpu(log_data->active_latency_timestamp[3-i][j]), ts_buf); - json_object_add_value_string(bucket, operation[j], ts_buf); + obj_add_str(bucket, operation[j], ts_buf); } } - json_object_add_value_object(root, buf, bucket); + obj_add_obj(root, buf, bucket); } for (i = 0; i < C3_BUCKET_NUM; i++) { @@ -448,14 +417,14 @@ static void json_c3_log(struct nvme_dev *dev, struct ssd_latency_monitor_log *lo bucket = json_create_object(); sprintf(buf, "Active Measured Latency: Bucket %d", i); for (j = 2; j >= 0; j--) { - json_object_add_value_uint(bucket, operation[j], - le16_to_cpu(log_data->active_measured_latency[3-i][j])); + obj_add_uint(bucket, operation[j], + le16_to_cpu(log_data->active_measured_latency[3-i][j])); } - json_object_add_value_object(root, buf, bucket); + obj_add_obj(root, buf, bucket); } - json_object_add_value_uint(root, "Active Latency Stamp Units", - le16_to_cpu(log_data->active_latency_stamp_units)); + obj_add_uint(root, "Active Latency Stamp Units", + le16_to_cpu(log_data->active_latency_stamp_units)); for (i = 0; i < C3_BUCKET_NUM; i++) { struct json_object *bucket; @@ -463,10 +432,10 @@ static void json_c3_log(struct nvme_dev *dev, struct ssd_latency_monitor_log *lo bucket = json_create_object(); sprintf(buf, "Static Bucket Counter: Bucket %d", i); for (j = 2; j >= 0; j--) { - json_object_add_value_uint(bucket, operation[j], - le32_to_cpu(log_data->static_bucket_counter[i][j+1])); + obj_add_uint(bucket, operation[j], + le32_to_cpu(log_data->static_bucket_counter[i][j+1])); } - json_object_add_value_object(root, buf, bucket); + obj_add_obj(root, buf, bucket); } for (i = 0; i < C3_BUCKET_NUM; i++) { @@ -476,14 +445,14 @@ static void json_c3_log(struct nvme_dev *dev, struct ssd_latency_monitor_log *lo sprintf(buf, "Static Latency Time Stamp: Bucket %d", i); for (j = 2; j >= 0; j--) { if (le64_to_cpu(log_data->static_latency_timestamp[3-i][j]) == -1) { - json_object_add_value_string(bucket, operation[j], "NA"); + obj_add_str(bucket, operation[j], "NA"); } else { convert_ts(le64_to_cpu(log_data->static_latency_timestamp[3-i][j]), ts_buf); - json_object_add_value_string(bucket, operation[j], ts_buf); + obj_add_str(bucket, operation[j], ts_buf); } } - json_object_add_value_object(root, buf, bucket); + obj_add_obj(root, buf, bucket); } for (i = 0; i < C3_BUCKET_NUM; i++) { @@ -492,14 +461,14 @@ static void json_c3_log(struct nvme_dev *dev, struct ssd_latency_monitor_log *lo bucket = json_create_object(); sprintf(buf, "Static Measured Latency: Bucket %d", i); for (j = 2; j >= 0; j--) { - json_object_add_value_uint(bucket, operation[j], - le16_to_cpu(log_data->static_measured_latency[3-i][j])); + obj_add_uint(bucket, operation[j], + le16_to_cpu(log_data->static_measured_latency[3-i][j])); } - json_object_add_value_object(root, buf, bucket); + obj_add_obj(root, buf, bucket); } - json_object_add_value_uint(root, "Static Latency Stamp Units", - le16_to_cpu(log_data->static_latency_stamp_units)); + obj_add_uint(root, "Static Latency Stamp Units", + le16_to_cpu(log_data->static_latency_stamp_units)); if (log_page_version >= 0x4) { strcpy(buf, "0x"); @@ -512,26 +481,24 @@ static void json_c3_log(struct nvme_dev *dev, struct ssd_latency_monitor_log *lo sprintf(hex_string, "%02x", log_data->latency_monitor_debug_log_size[i--]); strcat(buf, hex_string); } - json_object_add_value_string(root, "Debug Telemetry Log Size", buf); + obj_add_str(root, "Debug Telemetry Log Size", buf); } - json_object_add_value_uint(root, "Debug Log Trigger Enable", - le16_to_cpu(log_data->debug_log_trigger_enable)); - json_object_add_value_uint(root, "Debug Log Measured Latency", - le16_to_cpu(log_data->debug_log_measured_latency)); + obj_add_uint(root, "Debug Log Trigger Enable", + le16_to_cpu(log_data->debug_log_trigger_enable)); + obj_add_uint(root, "Debug Log Measured Latency", + le16_to_cpu(log_data->debug_log_measured_latency)); if (le64_to_cpu(log_data->debug_log_latency_stamp) == -1) { - json_object_add_value_string(root, "Debug Log Latency Time Stamp", "NA"); + obj_add_str(root, "Debug Log Latency Time Stamp", "NA"); } else { convert_ts(le64_to_cpu(log_data->debug_log_latency_stamp), ts_buf); - json_object_add_value_string(root, "Debug Log Latency Time Stamp", ts_buf); + obj_add_str(root, "Debug Log Latency Time Stamp", ts_buf); } - json_object_add_value_uint(root, "Debug Log Pointer", - le16_to_cpu(log_data->debug_log_ptr)); - json_object_add_value_uint(root, "Debug Counter Trigger Source", - le16_to_cpu(log_data->debug_log_counter_trigger)); - json_object_add_value_uint(root, "Debug Log Stamp Units", - le16_to_cpu(log_data->debug_log_stamp_units)); - json_object_add_value_uint(root, "Log Page Version", log_page_version); + obj_add_uint(root, "Debug Log Pointer", le16_to_cpu(log_data->debug_log_ptr)); + obj_add_uint(root, "Debug Counter Trigger Source", + le16_to_cpu(log_data->debug_log_counter_trigger)); + obj_add_uint(root, "Debug Log Stamp Units", le16_to_cpu(log_data->debug_log_stamp_units)); + obj_add_uint(root, "Log Page Version", log_page_version); char guid[(GUID_LEN * 2) + 1]; char *ptr = &guid[0]; @@ -539,7 +506,7 @@ static void json_c3_log(struct nvme_dev *dev, struct ssd_latency_monitor_log *lo for (i = GUID_LEN - 1; i >= 0; i--) ptr += sprintf(ptr, "%02X", log_data->log_page_guid[i]); - json_object_add_value_string(root, "Log Page GUID", guid); + obj_add_str(root, "Log Page GUID", guid); json_print_object(root, NULL); printf("\n"); @@ -557,23 +524,20 @@ static void json_c5_log(struct nvme_dev *dev, struct unsupported_requirement_log root = json_create_object(); - json_object_add_value_int(root, "Number Unsupported Req IDs", - le16_to_cpu(log_data->unsupported_count)); + obj_add_int(root, "Number Unsupported Req IDs", le16_to_cpu(log_data->unsupported_count)); memset((void *)unsup_req_list_str, 0, 40); for (j = 0; j < le16_to_cpu(log_data->unsupported_count); j++) { sprintf((char *)unsup_req_list_str, "Unsupported Requirement List %d", j); - json_object_add_value_string(root, unsup_req_list_str, - (char *)log_data->unsupported_req_list[j]); + obj_add_str(root, unsup_req_list_str, (char *)log_data->unsupported_req_list[j]); } - json_object_add_value_int(root, "Log Page Version", - le16_to_cpu(log_data->log_page_version)); + obj_add_int(root, "Log Page Version", le16_to_cpu(log_data->log_page_version)); memset((void *)guid, 0, GUID_LEN); for (j = GUID_LEN - 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); + obj_add_str(root, "Log page GUID", guid_buf); json_print_object(root, NULL); printf("\n"); @@ -588,34 +552,29 @@ static void json_c1_log(struct ocp_error_recovery_log_page *log_data) root = json_create_object(); char guid[64]; - json_object_add_value_int(root, "Panic Reset Wait Time", - le16_to_cpu(log_data->panic_reset_wait_time)); - json_object_add_value_int(root, "Panic Reset Action", log_data->panic_reset_action); - json_object_add_value_int(root, "Device Recovery Action 1", - log_data->device_recover_action_1); - json_object_add_value_int(root, "Panic ID", le32_to_cpu(log_data->panic_id)); - json_object_add_value_int(root, "Device Capabilities", - le32_to_cpu(log_data->device_capabilities)); - json_object_add_value_int(root, "Vendor Specific Recovery Opcode", - log_data->vendor_specific_recovery_opcode); - json_object_add_value_int(root, "Vendor Specific Command CDW12", - le32_to_cpu(log_data->vendor_specific_command_cdw12)); - json_object_add_value_int(root, "Vendor Specific Command CDW13", - le32_to_cpu(log_data->vendor_specific_command_cdw13)); - json_object_add_value_int(root, "Vendor Specific Command Timeout", - log_data->vendor_specific_command_timeout); - json_object_add_value_int(root, "Device Recovery Action 2", - log_data->device_recover_action_2); - json_object_add_value_int(root, "Device Recovery Action 2 Timeout", - log_data->device_recover_action_2_timeout); - json_object_add_value_int(root, "Log Page Version", - le16_to_cpu(log_data->log_page_version)); + obj_add_int(root, "Panic Reset Wait Time", le16_to_cpu(log_data->panic_reset_wait_time)); + obj_add_int(root, "Panic Reset Action", log_data->panic_reset_action); + obj_add_int(root, "Device Recovery Action 1", log_data->device_recover_action_1); + obj_add_int(root, "Panic ID", le32_to_cpu(log_data->panic_id)); + obj_add_int(root, "Device Capabilities", le32_to_cpu(log_data->device_capabilities)); + obj_add_int(root, "Vendor Specific Recovery Opcode", + log_data->vendor_specific_recovery_opcode); + obj_add_int(root, "Vendor Specific Command CDW12", + le32_to_cpu(log_data->vendor_specific_command_cdw12)); + obj_add_int(root, "Vendor Specific Command CDW13", + le32_to_cpu(log_data->vendor_specific_command_cdw13)); + obj_add_int(root, "Vendor Specific Command Timeout", + log_data->vendor_specific_command_timeout); + obj_add_int(root, "Device Recovery Action 2", log_data->device_recover_action_2); + obj_add_int(root, "Device Recovery Action 2 Timeout", + log_data->device_recover_action_2_timeout); + obj_add_int(root, "Log Page Version", le16_to_cpu(log_data->log_page_version)); memset((void *)guid, 0, 64); sprintf((char *)guid, "0x%"PRIx64"%"PRIx64"", (uint64_t)le64_to_cpu(*(uint64_t *)&log_data->log_page_guid[8]), (uint64_t)le64_to_cpu(*(uint64_t *)&log_data->log_page_guid[0])); - json_object_add_value_string(root, "Log page GUID", guid); + obj_add_str(root, "Log page GUID", guid); json_print_object(root, NULL); printf("\n"); @@ -628,32 +587,27 @@ static void json_c4_log(struct ocp_device_capabilities_log_page *log_data) char guid[64]; int i; - json_object_add_value_int(root, "PCI Express Ports", le16_to_cpu(log_data->pcie_exp_port)); - json_object_add_value_int(root, "OOB Management Support", - le16_to_cpu(log_data->oob_management_support)); - json_object_add_value_int(root, "Write Zeroes Command Support", - le16_to_cpu(log_data->wz_cmd_support)); - json_object_add_value_int(root, "Sanitize Command Support", - le16_to_cpu(log_data->sanitize_cmd_support)); - json_object_add_value_int(root, "Dataset Management Command Support", - le16_to_cpu(log_data->dsm_cmd_support)); - json_object_add_value_int(root, "Write Uncorrectable Command Support", - le16_to_cpu(log_data->wu_cmd_support)); - json_object_add_value_int(root, "Fused Operation Support", - le16_to_cpu(log_data->fused_operation_support)); - json_object_add_value_int(root, "Minimum Valid DSSD Power State", - le16_to_cpu(log_data->min_valid_dssd_pwr_state)); + obj_add_int(root, "PCI Express Ports", le16_to_cpu(log_data->pcie_exp_port)); + obj_add_int(root, "OOB Management Support", le16_to_cpu(log_data->oob_management_support)); + obj_add_int(root, "Write Zeroes Command Support", le16_to_cpu(log_data->wz_cmd_support)); + obj_add_int(root, "Sanitize Command Support", le16_to_cpu(log_data->sanitize_cmd_support)); + obj_add_int(root, "Dataset Management Command Support", + le16_to_cpu(log_data->dsm_cmd_support)); + obj_add_int(root, "Write Uncorrectable Command Support", + le16_to_cpu(log_data->wu_cmd_support)); + obj_add_int(root, "Fused Operation Support", + le16_to_cpu(log_data->fused_operation_support)); + obj_add_int(root, "Minimum Valid DSSD Power State", + le16_to_cpu(log_data->min_valid_dssd_pwr_state)); for (i = 0; i <= 127; i++) - json_object_add_value_int(root, "DSSD Power State Descriptors", - log_data->dssd_pwr_state_desc[i]); - json_object_add_value_int(root, "Log Page Version", - le16_to_cpu(log_data->log_page_version)); + obj_add_int(root, "DSSD Power State Descriptors", log_data->dssd_pwr_state_desc[i]); + obj_add_int(root, "Log Page Version", le16_to_cpu(log_data->log_page_version)); memset((void *)guid, 0, 64); sprintf((char *)guid, "0x%"PRIx64"%"PRIx64"", (uint64_t)le64_to_cpu(*(uint64_t *)&log_data->log_page_guid[8]), (uint64_t)le64_to_cpu(*(uint64_t *)&log_data->log_page_guid[0])); - json_object_add_value_string(root, "Log page GUID", guid); + obj_add_str(root, "Log page GUID", guid); json_print_object(root, NULL); printf("\n"); @@ -689,140 +643,134 @@ static void json_c9_log(struct telemetry_str_log_format *log_data, __u8 *log_dat char *ascii = ascii_buf; int j; - json_object_add_value_int(root, "Log Page Version", - le16_to_cpu(log_data->log_page_version)); + obj_add_int(root, "Log Page Version", le16_to_cpu(log_data->log_page_version)); memset((__u8 *)res, 0, 48); for (j = 0; j < 15; j++) res += sprintf(res, "%d", log_data->reserved1[j]); - json_object_add_value_string(root, "Reserved", res_arr); + obj_add_str(root, "Reserved", res_arr); memset((void *)guid, 0, GUID_LEN); for (j = GUID_LEN - 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); + obj_add_str(root, "Log page GUID", guid_buf); - json_object_add_value_int(root, "Telemetry String Log Size", le64_to_cpu(log_data->sls)); + obj_add_int(root, "Telemetry String Log Size", le64_to_cpu(log_data->sls)); res = res_arr; memset((__u8 *)res, 0, 48); for (j = 0; j < 24; j++) res += sprintf(res, "%d", log_data->reserved2[j]); - json_object_add_value_string(root, "Reserved", res_arr); - - json_object_add_value_int(root, "Statistics Identifier String Table Start", - le64_to_cpu(log_data->sits)); - json_object_add_value_int(root, "Event String Table Start", le64_to_cpu(log_data->ests)); - json_object_add_value_int(root, "Event String Table Size", le64_to_cpu(log_data->estsz)); - json_object_add_value_int(root, "VU Event String Table Start", - le64_to_cpu(log_data->vu_eve_sts)); - json_object_add_value_int(root, "VU Event String Table Size", - le64_to_cpu(log_data->vu_eve_st_sz)); - json_object_add_value_int(root, "ASCII Table Start", - le64_to_cpu(log_data->ascts)); - json_object_add_value_int(root, "ASCII Table Size", - le64_to_cpu(log_data->asctsz)); + obj_add_str(root, "Reserved", res_arr); + + obj_add_int(root, "Statistics Identifier String Table Start", le64_to_cpu(log_data->sits)); + obj_add_int(root, "Event String Table Start", le64_to_cpu(log_data->ests)); + obj_add_int(root, "Event String Table Size", le64_to_cpu(log_data->estsz)); + obj_add_int(root, "VU Event String Table Start", le64_to_cpu(log_data->vu_eve_sts)); + obj_add_int(root, "VU Event String Table Size", le64_to_cpu(log_data->vu_eve_st_sz)); + obj_add_int(root, "ASCII Table Start", le64_to_cpu(log_data->ascts)); + obj_add_int(root, "ASCII Table Size", le64_to_cpu(log_data->asctsz)); memset((void *)fifo, 0, 16); for (j = 0; j < 16; j++) fifo += sprintf(fifo, "%c", log_data->fifo1[j]); - json_object_add_value_string(root, "FIFO 1 ASCII String", fifo_arr); + obj_add_str(root, "FIFO 1 ASCII String", fifo_arr); fifo = fifo_arr; memset((void *)fifo, 0, 16); for (j = 0; j < 16; j++) fifo += sprintf(fifo, "%c", log_data->fifo2[j]); - json_object_add_value_string(root, "FIFO 2 ASCII String", fifo_arr); + obj_add_str(root, "FIFO 2 ASCII String", fifo_arr); fifo = fifo_arr; memset((void *)fifo, 0, 16); for (j = 0; j < 16; j++) fifo += sprintf(fifo, "%c", log_data->fifo3[j]); - json_object_add_value_string(root, "FIFO 3 ASCII String", fifo_arr); + obj_add_str(root, "FIFO 3 ASCII String", fifo_arr); fifo = fifo_arr; memset((void *)fifo, 0, 16); for (j = 0; j < 16; j++) fifo += sprintf(fifo, "%c", log_data->fifo4[j]); - json_object_add_value_string(root, "FIFO 4 ASCII String", fifo_arr); + obj_add_str(root, "FIFO 4 ASCII String", fifo_arr); fifo = fifo_arr; memset((void *)fifo, 0, 16); for (j = 0; j < 16; j++) fifo += sprintf(fifo, "%c", log_data->fifo5[j]); - json_object_add_value_string(root, "FIFO 5 ASCII String", fifo_arr); + obj_add_str(root, "FIFO 5 ASCII String", fifo_arr); fifo = fifo_arr; memset((void *)fifo, 0, 16); for (j = 0; j < 16; j++) fifo += sprintf(fifo, "%c", log_data->fifo6[j]); - json_object_add_value_string(root, "FIFO 6 ASCII String", fifo_arr); + obj_add_str(root, "FIFO 6 ASCII String", fifo_arr); fifo = fifo_arr; memset((void *)fifo, 0, 16); for (j = 0; j < 16; j++) fifo += sprintf(fifo, "%c", log_data->fifo7[j]); - json_object_add_value_string(root, "FIFO 7 ASCII String", fifo_arr); + obj_add_str(root, "FIFO 7 ASCII String", fifo_arr); fifo = fifo_arr; memset((void *)fifo, 0, 16); for (j = 0; j < 16; j++) fifo += sprintf(fifo, "%c", log_data->fifo8[j]); - json_object_add_value_string(root, "FIFO 8 ASCII String", fifo_arr); + obj_add_str(root, "FIFO 8 ASCII String", fifo_arr); fifo = fifo_arr; memset((void *)fifo, 0, 16); for (j = 0; j < 16; j++) fifo += sprintf(fifo, "%c", log_data->fifo9[j]); - json_object_add_value_string(root, "FIFO 9 ASCII String", fifo_arr); + obj_add_str(root, "FIFO 9 ASCII String", fifo_arr); fifo = fifo_arr; memset((void *)fifo, 0, 16); for (j = 0; j < 16; j++) fifo += sprintf(fifo, "%c", log_data->fifo10[j]); - json_object_add_value_string(root, "FIFO 10 ASCII String", fifo_arr); + obj_add_str(root, "FIFO 10 ASCII String", fifo_arr); fifo = fifo_arr; memset((void *)fifo, 0, 16); for (j = 0; j < 16; j++) fifo += sprintf(fifo, "%c", log_data->fifo11[j]); - json_object_add_value_string(root, "FIFO 11 ASCII String", fifo_arr); + obj_add_str(root, "FIFO 11 ASCII String", fifo_arr); fifo = fifo_arr; memset((void *)fifo, 0, 16); for (j = 0; j < 16; j++) fifo += sprintf(fifo, "%c", log_data->fifo12[j]); - json_object_add_value_string(root, "FIFO 12 ASCII String", fifo_arr); + obj_add_str(root, "FIFO 12 ASCII String", fifo_arr); fifo = fifo_arr; memset((void *)fifo, 0, 16); for (j = 0; j < 16; j++) fifo += sprintf(fifo, "%c", log_data->fifo13[j]); - json_object_add_value_string(root, "FIFO 13 ASCII String", fifo_arr); + obj_add_str(root, "FIFO 13 ASCII String", fifo_arr); fifo = fifo_arr; memset((void *)fifo, 0, 16); for (j = 0; j < 16; j++) fifo += sprintf(fifo, "%c", log_data->fifo14[j]); - json_object_add_value_string(root, "FIFO 14 ASCII String", fifo_arr); + obj_add_str(root, "FIFO 14 ASCII String", fifo_arr); fifo = fifo_arr; memset((void *)fifo, 0, 16); for (j = 0; j < 16; j++) fifo += sprintf(fifo, "%c", log_data->fifo15[j]); - json_object_add_value_string(root, "FIFO 15 ASCII String", fifo_arr); + obj_add_str(root, "FIFO 15 ASCII String", fifo_arr); fifo = fifo_arr; memset((void *)fifo, 0, 16); for (j = 0; j < 16; j++) fifo += sprintf(fifo, "%c", log_data->fifo16[j]); - json_object_add_value_string(root, "FIFO 16 ASCII String", fifo_arr); + obj_add_str(root, "FIFO 16 ASCII String", fifo_arr); res = res_arr; memset((__u8 *)res, 0, 48); for (j = 0; j < 48; j++) res += sprintf(res, "%d", log_data->reserved3[j]); - json_object_add_value_string(root, "Reserved", res_arr); + obj_add_str(root, "Reserved", res_arr); if (log_data->sitsz != 0) { @@ -834,22 +782,21 @@ static void json_c9_log(struct telemetry_str_log_format *log_data, __u8 *log_dat 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)); + obj_add_uint(entry, "Vendor Specific Statistic Identifier", + le16_to_cpu(stat_id_str_table_arr[j].vs_si)); + obj_add_uint(entry, "Reserved", + le64_to_cpu(stat_id_str_table_arr[j].reserved1)); + obj_add_uint(entry, "ASCII ID Length", + le64_to_cpu(stat_id_str_table_arr[j].ascii_id_len)); + obj_add_uint(entry, "ASCII ID offset", + le64_to_cpu(stat_id_str_table_arr[j].ascii_id_ofst)); + obj_add_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); + obj_add_obj(stat_table, buf, entry); } - json_object_add_value_object(root, - "Statistics Identifier String Table", stat_table); + obj_add_obj(root, "Statistics Identifier String Table", stat_table); } if (log_data->estsz != 0) { @@ -861,21 +808,20 @@ static void json_c9_log(struct telemetry_str_log_format *log_data, __u8 *log_dat 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)); + obj_add_int(entry, "Debug Event Class", + le16_to_cpu(event_id_str_table_arr[j].deb_eve_class)); + obj_add_int(entry, "Event Identifier", + le16_to_cpu(event_id_str_table_arr[j].ei)); + obj_add_int(entry, "ASCII ID Length", + le64_to_cpu(event_id_str_table_arr[j].ascii_id_len)); + obj_add_int(entry, "ASCII ID offset", + le64_to_cpu(event_id_str_table_arr[j].ascii_id_ofst)); + obj_add_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); + obj_add_obj(eve_table, buf, entry); } - json_object_add_value_object(root, - "Event Identifier String Table Entry", + obj_add_obj(root, "Event Identifier String Table Entry", eve_table); } @@ -888,21 +834,20 @@ static void json_c9_log(struct telemetry_str_log_format *log_data, __u8 *log_dat 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)); + obj_add_int(entry, "Debug Event Class", + le16_to_cpu(vu_event_id_str_table_arr[j].deb_eve_class)); + obj_add_int(entry, "VU Event Identifier", + le16_to_cpu(vu_event_id_str_table_arr[j].vu_ei)); + obj_add_int(entry, "ASCII ID Length", + le64_to_cpu(vu_event_id_str_table_arr[j].ascii_id_len)); + obj_add_int(entry, "ASCII ID offset", + le64_to_cpu(vu_event_id_str_table_arr[j].ascii_id_ofst)); + obj_add_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); + obj_add_obj(vu_eve_table, buf, entry); } - json_object_add_value_object(root, - "VU Event Identifier String Table Entry", + obj_add_obj(root, "VU Event Identifier String Table Entry", vu_eve_table); } @@ -913,7 +858,7 @@ static void json_c9_log(struct telemetry_str_log_format *log_data, __u8 *log_dat 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); + obj_add_str(root, "ASCII Table", ascii_buf); } json_print_object(root, NULL); @@ -933,63 +878,56 @@ static void json_c7_log(struct nvme_dev *dev, struct tcg_configuration_log *log_ root = json_create_object(); - json_object_add_value_int(root, "State", log_data->state); + obj_add_int(root, "State", 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", - log_data->locking_sp_act_count); - json_object_add_value_int(root, "Tper Revert Count", - log_data->locking_sp_rev_count); - json_object_add_value_int(root, "Number of Locking Objects", - log_data->no_of_locking_obj); - json_object_add_value_int(root, "Number of Single User Mode Locking Objects", - log_data->no_of_single_um_locking_obj); - json_object_add_value_int(root, "Number of Range Provisioned Locking Objects", - log_data->no_of_range_prov_locking_obj); - json_object_add_value_int(root, "Number of Namespace Provisioned Locking Objects", - log_data->no_of_ns_prov_locking_obj); - json_object_add_value_int(root, "Number of Read Locked Locking Objects", - log_data->no_of_read_lock_locking_obj); - json_object_add_value_int(root, "Number of Write Locked Locking Objects", - log_data->no_of_write_lock_locking_obj); - json_object_add_value_int(root, "Number of Read Unlocked Locking Objects", - log_data->no_of_read_unlock_locking_obj); - json_object_add_value_int(root, "Number of Write Unlocked Locking Objects", - log_data->no_of_write_unlock_locking_obj); - json_object_add_value_int(root, "Reserved2", log_data->rsvd15); - - json_object_add_value_int(root, "SID Authentication Try Count", - le32_to_cpu(log_data->sid_auth_try_count)); - json_object_add_value_int(root, "SID Authentication Try Limit", - le32_to_cpu(log_data->sid_auth_try_limit)); - json_object_add_value_int(root, "Programmatic TCG Reset Count", - le32_to_cpu(log_data->pro_tcg_rc)); - json_object_add_value_int(root, "Programmatic Reset Lock Count", - le32_to_cpu(log_data->pro_rlc)); - json_object_add_value_int(root, "TCG Error Count", le32_to_cpu(log_data->tcg_ec)); + obj_add_str(root, "Reserved1", res_arr); + obj_add_int(root, "Locking SP Activation Count", log_data->locking_sp_act_count); + obj_add_int(root, "Tper Revert Count", log_data->locking_sp_rev_count); + obj_add_int(root, "Number of Locking Objects", log_data->no_of_locking_obj); + obj_add_int(root, "Number of Single User Mode Locking Objects", + log_data->no_of_single_um_locking_obj); + obj_add_int(root, "Number of Range Provisioned Locking Objects", + log_data->no_of_range_prov_locking_obj); + obj_add_int(root, "Number of Namespace Provisioned Locking Objects", + log_data->no_of_ns_prov_locking_obj); + obj_add_int(root, "Number of Read Locked Locking Objects", + log_data->no_of_read_lock_locking_obj); + obj_add_int(root, "Number of Write Locked Locking Objects", + log_data->no_of_write_lock_locking_obj); + obj_add_int(root, "Number of Read Unlocked Locking Objects", + log_data->no_of_read_unlock_locking_obj); + obj_add_int(root, "Number of Write Unlocked Locking Objects", + log_data->no_of_write_unlock_locking_obj); + obj_add_int(root, "Reserved2", log_data->rsvd15); + + obj_add_int(root, "SID Authentication Try Count", + le32_to_cpu(log_data->sid_auth_try_count)); + obj_add_int(root, "SID Authentication Try Limit", + le32_to_cpu(log_data->sid_auth_try_limit)); + obj_add_int(root, "Programmatic TCG Reset Count", le32_to_cpu(log_data->pro_tcg_rc)); + obj_add_int(root, "Programmatic Reset Lock Count", le32_to_cpu(log_data->pro_rlc)); + obj_add_int(root, "TCG Error Count", le32_to_cpu(log_data->tcg_ec)); memset((__u8 *)res, 0, 458); - if (log_page_version == 1) { + if (log_page_version == 1) res += sprintf(res, "%d%d", *(__u8 *)&log_data->no_of_ns_prov_locking_obj_ext, *((__u8 *)&log_data->no_of_ns_prov_locking_obj_ext + 1)); - } else { - json_object_add_value_int(root, - "Number of Namespace Provisioned Locking Objects Extended", - log_data->no_of_ns_prov_locking_obj_ext); - } + else + obj_add_int(root, "Number of Namespace Provisioned Locking Objects Extended", + log_data->no_of_ns_prov_locking_obj_ext); for (j = 0; j < 456; j++) res += sprintf(res, "%d", log_data->rsvd38[j]); - json_object_add_value_string(root, "Reserved3", res_arr); + obj_add_str(root, "Reserved3", res_arr); - json_object_add_value_int(root, "Log Page Version", log_page_version); + obj_add_int(root, "Log Page Version", log_page_version); memset((void *)guid, 0, GUID_LEN); for (j = GUID_LEN - 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); + obj_add_str(root, "Log page GUID", guid_buf); json_print_object(root, NULL); printf("\n"); From f48312b72bc08cb777e9e1da78f04de2059a99a7 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 22 Dec 2024 16:29:17 +0900 Subject: [PATCH 2/5] ocp: use struct nvme_timestamp type for FAHE-5 timestamp field Since the field defined by the NVMe timestamp feature. Signed-off-by: Tokunori Ikegami --- nvme.h | 2 +- plugins/ocp/ocp-fw-activation-history.h | 3 ++- plugins/ocp/ocp-print-json.c | 3 +-- plugins/ocp/ocp-print-stdout.c | 3 +-- util/types.c | 2 +- util/types.h | 2 +- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/nvme.h b/nvme.h index cae4345214..363a82d99d 100644 --- a/nvme.h +++ b/nvme.h @@ -31,6 +31,7 @@ #include "util/mem.h" #include "util/argconfig.h" #include "util/cleanup.h" +#include "util/types.h" enum nvme_print_flags { NORMAL = 0, @@ -147,7 +148,6 @@ const char *nvme_select_to_string(int sel); void d(unsigned char *buf, int len, int width, int group); void d_raw(unsigned char *buf, unsigned len); -uint64_t int48_to_long(uint8_t *data); int get_reg_size(int offset); bool nvme_is_ctrl_reg(int offset); diff --git a/plugins/ocp/ocp-fw-activation-history.h b/plugins/ocp/ocp-fw-activation-history.h index 15733a3fd5..fa37e4bd60 100644 --- a/plugins/ocp/ocp-fw-activation-history.h +++ b/plugins/ocp/ocp-fw-activation-history.h @@ -4,6 +4,7 @@ * * Authors: karl.dedow@solidigm.com */ +#include #include "common.h" #include "linux/types.h" @@ -18,7 +19,7 @@ struct __packed fw_activation_history_entry { __u8 entry_length; __le16 reserved1; __le16 activation_count; - __le64 timestamp; + struct nvme_timestamp ts; __le64 reserved2; __le64 power_cycle_count; char previous_fw[8]; diff --git a/plugins/ocp/ocp-print-json.c b/plugins/ocp/ocp-print-json.c index 10d85e0101..fadb70ea39 100644 --- a/plugins/ocp/ocp-print-json.c +++ b/plugins/ocp/ocp-print-json.c @@ -98,8 +98,7 @@ static void json_fw_activation_history(const struct fw_activation_history *fw_hi obj_add_uint(entry_obj, "version number", entry->ver_num); obj_add_uint(entry_obj, "entry length", entry->entry_length); obj_add_uint(entry_obj, "activation count", le16_to_cpu(entry->activation_count)); - obj_add_uint64(entry_obj, "timestamp", - (0x0000FFFFFFFFFFFF & le64_to_cpu(entry->timestamp))); + obj_add_uint64(entry_obj, "timestamp", int48_to_long(entry->ts.timestamp)); obj_add_uint(entry_obj, "power cycle count", le64_to_cpu(entry->power_cycle_count)); fw = obj_new_str_len(entry->previous_fw, sizeof(entry->previous_fw)); diff --git a/plugins/ocp/ocp-print-stdout.c b/plugins/ocp/ocp-print-stdout.c index f86c1b8428..61309a937e 100644 --- a/plugins/ocp/ocp-print-stdout.c +++ b/plugins/ocp/ocp-print-stdout.c @@ -75,8 +75,7 @@ static void stdout_fw_activation_history(const struct fw_activation_history *fw_ printf(" %-22s%d\n", "entry length:", entry->entry_length); printf(" %-22s%d\n", "activation count:", le16_to_cpu(entry->activation_count)); - printf(" %-22s%"PRIu64"\n", "timestamp:", - (0x0000FFFFFFFFFFFF & le64_to_cpu(entry->timestamp))); + printf(" %-22s%"PRIu64"\n", "timestamp:", int48_to_long(entry->ts.timestamp)); printf(" %-22s%"PRIu64"\n", "power cycle count:", le64_to_cpu(entry->power_cycle_count)); printf(" %-22s%.*s\n", "previous firmware:", (int)sizeof(entry->previous_fw), diff --git a/util/types.c b/util/types.c index 20c121b1a6..cc2e7550b1 100644 --- a/util/types.c +++ b/util/types.c @@ -36,7 +36,7 @@ long double int128_to_double(__u8 *data) return result; } -uint64_t int48_to_long(__u8 *data) +uint64_t int48_to_long(const __u8 *data) { int i; uint64_t result = 0; diff --git a/util/types.h b/util/types.h index b2e8fc8df5..bb4125f2a1 100644 --- a/util/types.h +++ b/util/types.h @@ -36,7 +36,7 @@ typedef union nvme_uint128 nvme_uint128_t; nvme_uint128_t le128_to_cpu(__u8 *data); long double int128_to_double(__u8 *data); -uint64_t int48_to_long(__u8 *data); +uint64_t int48_to_long(const __u8 *data); char *uint128_t_to_string(nvme_uint128_t val); char *uint128_t_to_l10n_string(nvme_uint128_t val); From a75c9650a5563beb8a54c4bee348de79b39f7ad1 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 22 Dec 2024 18:21:01 +0900 Subject: [PATCH 3/5] ocp: remove unnecessary 64 bits mask Since the 64 bits variables not necessary to mask by 64 bits. Signed-off-by: Tokunori Ikegami --- plugins/ocp/ocp-print-json.c | 12 ++++-------- plugins/ocp/ocp-print-stdout.c | 8 ++++---- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/plugins/ocp/ocp-print-json.c b/plugins/ocp/ocp-print-json.c index fadb70ea39..c611cfd2d3 100644 --- a/plugins/ocp/ocp-print-json.c +++ b/plugins/ocp/ocp-print-json.c @@ -145,15 +145,11 @@ static void json_smart_extended_log_v1(void *data) pmuw = json_create_object(); pmur = json_create_object(); - obj_add_uint64(pmuw, "hi", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW + 8] & 0xFFFFFFFFFFFFFFFF)); - obj_add_uint64(pmuw, "lo", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW] & 0xFFFFFFFFFFFFFFFF)); + obj_add_uint64(pmuw, "hi", (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW + 8])); + obj_add_uint64(pmuw, "lo", (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW])); obj_add_obj(root, "Physical media units written", pmuw); - obj_add_uint64(pmur, "hi", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR + 8] & 0xFFFFFFFFFFFFFFFF)); - obj_add_uint64(pmur, "lo", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR] & 0xFFFFFFFFFFFFFFFF)); + obj_add_uint64(pmur, "hi", (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR + 8])); + obj_add_uint64(pmur, "lo", (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR])); obj_add_obj(root, "Physical media units read", pmur); obj_add_uint64(root, "Bad user nand blocks - Raw", (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BUNBR] & 0x0000FFFFFFFFFFFF)); diff --git a/plugins/ocp/ocp-print-stdout.c b/plugins/ocp/ocp-print-stdout.c index 61309a937e..3ddf229392 100644 --- a/plugins/ocp/ocp-print-stdout.c +++ b/plugins/ocp/ocp-print-stdout.c @@ -105,11 +105,11 @@ static void stdout_smart_extended_log(void *data, unsigned int version) 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)); + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW + 8]), + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUW])); 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)); + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR + 8]), + (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR])); printf(" Bad user nand blocks - Raw %"PRIu64"\n", (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BUNBR] & 0x0000FFFFFFFFFFFF)); printf(" Bad user nand blocks - Normalized %d\n", From 5887743a0fb3bdcda3d2a53c4f911128b3d384d0 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Sun, 22 Dec 2024 18:50:21 +0900 Subject: [PATCH 4/5] ocp-print: use int48_to_long() to print 48 bits values This is to reduce unnecessary mask with 0x0000FFFFFFFFFFFF. Signed-off-by: Tokunori Ikegami --- plugins/ocp/ocp-print-json.c | 6 ++---- plugins/ocp/ocp-print-stdout.c | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/plugins/ocp/ocp-print-json.c b/plugins/ocp/ocp-print-json.c index c611cfd2d3..6360b67172 100644 --- a/plugins/ocp/ocp-print-json.c +++ b/plugins/ocp/ocp-print-json.c @@ -151,12 +151,10 @@ static void json_smart_extended_log_v1(void *data) obj_add_uint64(pmur, "hi", (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR + 8])); obj_add_uint64(pmur, "lo", (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR])); obj_add_obj(root, "Physical media units read", pmur); - obj_add_uint64(root, "Bad user nand blocks - Raw", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BUNBR] & 0x0000FFFFFFFFFFFF)); + obj_add_uint64(root, "Bad user nand blocks - Raw", int48_to_long(&log_data[SCAO_BUNBR])); obj_add_uint(root, "Bad user nand blocks - Normalized", (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BUNBN])); - obj_add_uint64(root, "Bad system nand blocks - Raw", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BSNBR] & 0x0000FFFFFFFFFFFF)); + obj_add_uint64(root, "Bad system nand blocks - Raw", int48_to_long(&log_data[SCAO_BSNBR])); obj_add_uint(root, "Bad system nand blocks - Normalized", (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BSNBN])); obj_add_uint64(root, "XOR recovery count", diff --git a/plugins/ocp/ocp-print-stdout.c b/plugins/ocp/ocp-print-stdout.c index 3ddf229392..7f767bbfb4 100644 --- a/plugins/ocp/ocp-print-stdout.c +++ b/plugins/ocp/ocp-print-stdout.c @@ -111,11 +111,11 @@ static void stdout_smart_extended_log(void *data, unsigned int version) (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR + 8]), (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_PMUR])); printf(" Bad user nand blocks - Raw %"PRIu64"\n", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BUNBR] & 0x0000FFFFFFFFFFFF)); + int48_to_long(&log_data[SCAO_BUNBR])); printf(" Bad user nand blocks - Normalized %d\n", (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BUNBN])); printf(" Bad system nand blocks - Raw %"PRIu64"\n", - (uint64_t)le64_to_cpu(*(uint64_t *)&log_data[SCAO_BSNBR] & 0x0000FFFFFFFFFFFF)); + int48_to_long(&log_data[SCAO_BSNBR])); printf(" Bad system nand blocks - Normalized %d\n", (uint16_t)le16_to_cpu(*(uint16_t *)&log_data[SCAO_BSNBN])); printf(" XOR recovery count %"PRIu64"\n", From 0e98910e7bb7dc839ed7f0c90d3c68aa2769c553 Mon Sep 17 00:00:00 2001 From: Tokunori Ikegami Date: Mon, 23 Dec 2024 00:29:13 +0900 Subject: [PATCH 5/5] util: introduce int56_to_long() type conversion helper This is to remove unnecessary mask with 0x00FFFFFFFFFFFFFF. Signed-off-by: Tokunori Ikegami --- plugins/ocp/ocp-print-json.c | 3 +-- plugins/ocp/ocp-print-stdout.c | 2 +- util/types.c | 21 +++++++++++++++++---- util/types.h | 1 + 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/plugins/ocp/ocp-print-json.c b/plugins/ocp/ocp-print-json.c index 6360b67172..1a74c89697 100644 --- a/plugins/ocp/ocp-print-json.c +++ b/plugins/ocp/ocp-print-json.c @@ -168,8 +168,7 @@ static void json_smart_extended_log_v1(void *data) obj_add_uint(root, "End to end corrected errors", (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_EECE])); obj_add_uint(root, "System data percent used", (__u8)log_data[SCAO_SDPU]); - obj_add_uint64(root, "Refresh counts", - (uint64_t)(le64_to_cpu(*(uint64_t *)&log_data[SCAO_RFSC]) & 0x00FFFFFFFFFFFFFF)); + obj_add_uint64(root, "Refresh counts", int56_to_long(&log_data[SCAO_RFSC])); obj_add_uint(root, "Max User data erase counts", (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_MXUDEC])); obj_add_uint(root, "Min User data erase counts", diff --git a/plugins/ocp/ocp-print-stdout.c b/plugins/ocp/ocp-print-stdout.c index 7f767bbfb4..5880104af6 100644 --- a/plugins/ocp/ocp-print-stdout.c +++ b/plugins/ocp/ocp-print-stdout.c @@ -131,7 +131,7 @@ static void stdout_smart_extended_log(void *data, unsigned int version) printf(" System data percent used %d\n", (__u8)log_data[SCAO_SDPU]); printf(" Refresh counts %"PRIu64"\n", - (uint64_t)(le64_to_cpu(*(uint64_t *)&log_data[SCAO_RFSC]) & 0x00FFFFFFFFFFFFFF)); + int56_to_long(&log_data[SCAO_RFSC])); printf(" Max User data erase counts %"PRIu32"\n", (uint32_t)le32_to_cpu(*(uint32_t *)&log_data[SCAO_MXUDEC])); printf(" Min User data erase counts %"PRIu32"\n", diff --git a/util/types.c b/util/types.c index cc2e7550b1..a34479a551 100644 --- a/util/types.c +++ b/util/types.c @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -36,18 +37,30 @@ long double int128_to_double(__u8 *data) return result; } -uint64_t int48_to_long(const __u8 *data) +static uint64_t int_to_long(int bits, const __u8 *data) { int i; uint64_t result = 0; + int bytes = (bits + CHAR_BIT - 1) / CHAR_BIT; - for (i = 0; i < 6; i++) { - result *= 256; - result += data[5 - i]; + for (i = 0; i < bytes; i++) { + result <<= CHAR_BIT; + result += data[bytes - 1 - i]; } + return result; } +uint64_t int48_to_long(const __u8 *data) +{ + return int_to_long(48, data); +} + +uint64_t int56_to_long(const __u8 *data) +{ + return int_to_long(56, data); +} + long double uint128_t_to_double(nvme_uint128_t data) { long double result = 0; diff --git a/util/types.h b/util/types.h index bb4125f2a1..70a7760707 100644 --- a/util/types.h +++ b/util/types.h @@ -37,6 +37,7 @@ typedef union nvme_uint128 nvme_uint128_t; nvme_uint128_t le128_to_cpu(__u8 *data); long double int128_to_double(__u8 *data); uint64_t int48_to_long(const __u8 *data); +uint64_t int56_to_long(const __u8 *data); char *uint128_t_to_string(nvme_uint128_t val); char *uint128_t_to_l10n_string(nvme_uint128_t val);