]> www.infradead.org Git - users/sagi/nvme-cli.git/commitdiff
ocp: add hwcomp log command list option
authorTokunori Ikegami <ikegami.t@gmail.com>
Sat, 31 Aug 2024 10:49:59 +0000 (19:49 +0900)
committerDaniel Wagner <wagi@monom.org>
Mon, 16 Sep 2024 15:19:25 +0000 (17:19 +0200)
This is to list component descriptions.

Signed-off-by: Tokunori Ikegami <ikegami.t@gmail.com>
plugins/ocp/ocp-nvme.c

index d566f81b5c5e9328242d169d329a0978ec8e9591..cea49395b2fc05f2baf6e1a64b8c268d7907b874 100644 (file)
@@ -4414,7 +4414,25 @@ static const char *hwcomp_id_to_string(__u32 id)
        return "Reserved";
 }
 
-static void print_hwcomp_log_normal(struct hwcomp_log *log, __u32 id)
+static void print_hwcomp_desc(struct hwcomp_desc *desc, __u64 date_lot_size, __u8 *date_lot_code,
+                             __u64 add_info_size, __u8 *add_info, bool list)
+{
+       printf("  Component: %s\n", hwcomp_id_to_string(le32_to_cpu(desc->id)));
+
+       if (list)
+               return;
+
+       printf("    Date/Lot Size: 0x%llx\n", date_lot_size);
+       printf("    Additional Information Size: 0x%llx\n", add_info_size);
+       printf("    Identifier: 0x%08x\n", le32_to_cpu(desc->id));
+       printf("    Manufacture: 0x%016lx\n", le64_to_cpu(desc->mfg));
+       printf("    Revision: 0x%016lx\n", le64_to_cpu(desc->rev));
+       printf("    Manufacture Code: 0x%016lx\n", le64_to_cpu(desc->mfg_code));
+       print_array("    Date/Lot Code", date_lot_code, date_lot_size);
+       print_array("    Additional Information", add_info, add_info_size);
+}
+
+static void print_hwcomp_log_normal(struct hwcomp_log *log, __u32 id, bool list)
 {
        size_t date_lot_code_offset = sizeof(struct hwcomp_desc);
        struct hwcomp_desc *desc;
@@ -4440,19 +4458,9 @@ static void print_hwcomp_log_normal(struct hwcomp_log *log, __u32 id)
                add_info_size = le64_to_cpu(desc->add_info_size) * sizeof(__le32);
                add_info = add_info_size ? date_lot_code ? date_lot_code + date_lot_size :
                    (__u8 *)desc + date_lot_code_offset : NULL;
-
-               if (!id || id == le32_to_cpu(desc->id)) {
-                       printf("  Component: %s\n", hwcomp_id_to_string(le32_to_cpu(desc->id)));
-                       printf("    Date/Lot Size: 0x%llx\n", date_lot_size);
-                       printf("    Additional Information Size: 0x%llx\n", add_info_size);
-                       printf("    Identifier: 0x%08x\n", le32_to_cpu(desc->id));
-                       printf("    Manufacture: 0x%016lx\n", le64_to_cpu(desc->mfg));
-                       printf("    Revision: 0x%016lx\n", le64_to_cpu(desc->rev));
-                       printf("    Manufacture Code: 0x%016lx\n", le64_to_cpu(desc->mfg_code));
-                       print_array("    Date/Lot Code", date_lot_code, date_lot_size);
-                       print_array("    Additional Information", add_info, add_info_size);
-               }
-
+               if (!id || id == le32_to_cpu(desc->id))
+                       print_hwcomp_desc(desc, date_lot_size, date_lot_code, add_info_size,
+                                         add_info, list);
                desc_size = date_lot_code_offset + date_lot_size + add_info_size;
                desc = (struct hwcomp_desc *)((__u8 *)desc + desc_size);
                log_size -= desc_size;
@@ -4517,7 +4525,7 @@ static int get_hwcomp_log_data(struct nvme_dev *dev, struct hwcomp_log *log)
        return ret;
 }
 
-static int get_hwcomp_log(struct nvme_dev *dev, __u32 id)
+static int get_hwcomp_log(struct nvme_dev *dev, __u32 id, bool list)
 {
        _cleanup_free_ __u8 *desc = NULL;
 
@@ -4542,7 +4550,7 @@ static int get_hwcomp_log(struct nvme_dev *dev, __u32 id)
 
        switch (fmt) {
        case NORMAL:
-               print_hwcomp_log_normal(&log, id);
+               print_hwcomp_log_normal(&log, id, list);
                break;
        case BINARY:
                print_hwcomp_log_binary(&log);
@@ -4562,8 +4570,10 @@ static int ocp_hwcomp_log(int argc, char **argv, struct command *cmd, struct plu
        const char *desc = "retrieve hardware component log";
        struct config {
                __u32 id;
+               bool list;
        } cfg = { 0 };
        const char *id_desc = "component identifier";
+       const char *list_desc = "list component descriptions";
 
        OPT_VALS(id) = {
                VAL_LONG("asic", HWCOMP_ID_ASIC),
@@ -4581,13 +4591,14 @@ static int ocp_hwcomp_log(int argc, char **argv, struct command *cmd, struct plu
                VAL_END()
        };
 
-       NVME_ARGS(opts, OPT_LONG("comp-id", 'i', &cfg.id, id_desc, id));
+       NVME_ARGS(opts, OPT_LONG("comp-id", 'i', &cfg.id, id_desc, id),
+                 OPT_FLAG("list", 'l', &cfg.list, list_desc));
 
        ret = parse_and_open(&dev, argc, argv, desc, opts);
        if (ret)
                return ret;
 
-       ret = get_hwcomp_log(dev, cfg.id);
+       ret = get_hwcomp_log(dev, cfg.id, cfg.list);
        if (ret)
                fprintf(stderr, "error: ocp: failed to get hwcomp log: %02X, ret: %d\n", LID_HWCOMP,
                        ret);