From 1e842b671b1cd825913e6e3e5ec7f9fd9123d0dc Mon Sep 17 00:00:00 2001 From: Steven Seungcheol Lee Date: Tue, 19 Nov 2024 12:58:46 +0900 Subject: [PATCH] ocp-nvme: Update ocp v2.6 Hardware Component Log Identifier C6h Hardware Component Log Size (bytes) Component Identifier added 0x000C Born on Date. The date on which the device was manufactured. ASCII string format is MMDDYYYY. Signed-off-by: Steven Seungcheol Lee --- plugins/ocp/ocp-hardware-component-log.c | 10 +++++++++- plugins/ocp/ocp-hardware-component-log.h | 1 + plugins/ocp/ocp-print-binary.c | 6 ++++-- plugins/ocp/ocp-print-json.c | 4 +++- plugins/ocp/ocp-print-stdout.c | 4 +++- 5 files changed, 20 insertions(+), 5 deletions(-) diff --git a/plugins/ocp/ocp-hardware-component-log.c b/plugins/ocp/ocp-hardware-component-log.c index cc36a180..5e039dd8 100644 --- a/plugins/ocp/ocp-hardware-component-log.c +++ b/plugins/ocp/ocp-hardware-component-log.c @@ -154,6 +154,8 @@ const char *hwcomp_id_to_string(__u32 id) return "Country of Origin"; case HWCOMP_ID_HW_REV: return "Global Device Hardware Revision"; + case HWCOMP_ID_BORN_ON_DATE: + return "Born on Date"; case HWCOMP_ID_VENDOR ... HWCOMP_ID_MAX: return "Vendor Unique Component"; case HWCOMP_ID_RSVD: @@ -193,7 +195,12 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log) print_info_array("guid", log->guid, ARRAY_SIZE(log->guid)); print_info("size: %s\n", uint128_t_to_string(le128_to_cpu(log->size))); - args.len = uint128_t_to_double(le128_to_cpu(log->size)) * sizeof(__le32) - desc_offset; + if (log->ver > 1) + args.len = uint128_t_to_double(le128_to_cpu(log->size)) - desc_offset; + else + args.len = uint128_t_to_double(le128_to_cpu(log->size)) * sizeof(__le32) + - desc_offset; + log->desc = calloc(1, args.len); if (!log->desc) { fprintf(stderr, "error: ocp: calloc: %s\n", strerror(errno)); @@ -268,6 +275,7 @@ int ocp_hwcomp_log(int argc, char **argv, struct command *cmd, struct plugin *pl VAL_LONG("sn", HWCOMP_ID_SN), VAL_LONG("country", HWCOMP_ID_COUNTRY), VAL_LONG("hw-rev", HWCOMP_ID_HW_REV), + VAL_LONG("born-on-date", HWCOMP_ID_BORN_ON_DATE), VAL_LONG("vendor", HWCOMP_ID_VENDOR), VAL_END() }; diff --git a/plugins/ocp/ocp-hardware-component-log.h b/plugins/ocp/ocp-hardware-component-log.h index f5e5162e..f0e5c1f9 100644 --- a/plugins/ocp/ocp-hardware-component-log.h +++ b/plugins/ocp/ocp-hardware-component-log.h @@ -54,6 +54,7 @@ enum hwcomp_id { HWCOMP_ID_SN, HWCOMP_ID_COUNTRY, HWCOMP_ID_HW_REV, + HWCOMP_ID_BORN_ON_DATE, HWCOMP_ID_VENDOR = 0x8000, HWCOMP_ID_MAX = 0xffff, }; diff --git a/plugins/ocp/ocp-print-binary.c b/plugins/ocp/ocp-print-binary.c index 64e1246b..b9cd3156 100644 --- a/plugins/ocp/ocp-print-binary.c +++ b/plugins/ocp/ocp-print-binary.c @@ -7,9 +7,11 @@ static void binary_hwcomp_log(struct hwcomp_log *log, __u32 id, bool list) { - long double desc_len = uint128_t_to_double(le128_to_cpu(log->size)) * sizeof(__le32); + long double desc_len = uint128_t_to_double(le128_to_cpu(log->size)); + if (log->ver == 1) + desc_len *= sizeof(__le32); - d_raw((unsigned char *)log, offsetof(struct hwcomp_log, desc) + desc_len); + d_raw((unsigned char *)log, desc_len); } static void binary_c5_log(struct nvme_dev *dev, struct unsupported_requirement_log *log_data) diff --git a/plugins/ocp/ocp-print-json.c b/plugins/ocp/ocp-print-json.c index d18957e5..d32ed991 100644 --- a/plugins/ocp/ocp-print-json.c +++ b/plugins/ocp/ocp-print-json.c @@ -65,7 +65,9 @@ static void json_hwcomp_log(struct hwcomp_log *log, __u32 id, bool list) { struct json_object *r = json_create_object(); - long double log_size = uint128_t_to_double(le128_to_cpu(log->size)) * sizeof(__le32); + long double log_size = uint128_t_to_double(le128_to_cpu(log->size)); + if (log->ver == 1) + log_size *= sizeof(__le32); obj_add_uint_02x(r, "Log Identifier", LID_HWCOMP); obj_add_uint_0x(r, "Log Page Version", le16_to_cpu(log->ver)); diff --git a/plugins/ocp/ocp-print-stdout.c b/plugins/ocp/ocp-print-stdout.c index cb66aa57..1de237d7 100644 --- a/plugins/ocp/ocp-print-stdout.c +++ b/plugins/ocp/ocp-print-stdout.c @@ -32,7 +32,9 @@ static void stdout_hwcomp_log(struct hwcomp_log *log, __u32 id, bool list) int num = 1; struct hwcomp_desc_entry e = { log->desc }; - long double log_size = uint128_t_to_double(le128_to_cpu(log->size)) * sizeof(__le32); + long double log_size = uint128_t_to_double(le128_to_cpu(log->size)); + if (log->ver == 1) + log_size *= sizeof(__le32); printf("Log Identifier: 0x%02xh\n", LID_HWCOMP); printf("Log Page Version: 0x%x\n", le16_to_cpu(log->ver)); -- 2.50.1