From 91c4bb0817216241612d235717cee43c5b4528ec Mon Sep 17 00:00:00 2001 From: Francis Pravin Date: Thu, 27 Feb 2025 17:49:32 +0530 Subject: [PATCH] nvme-print: add human readable output for IOCS Data Structure Add human readable output for Identify I/O Command Set Data Structure (CNS 1Ch). Signed-off-by: Francis Pravin --- nvme-print-json.c | 23 +++++++++++++++++++++++ nvme-print-stdout.c | 28 ++++++++++++++++++++++++++-- nvme.c | 7 +++++-- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/nvme-print-json.c b/nvme-print-json.c index 5b3c362960..13b3c6cf0e 100644 --- a/nvme-print-json.c +++ b/nvme-print-json.c @@ -186,9 +186,27 @@ static void obj_print(struct json_object *o) json_print(o); } +static void json_id_iocs_iocsc(struct json_object *obj_iocsc, __u64 iocsc) +{ + __u8 cpncs = NVME_GET(iocsc, IOCS_IOCSC_CPNCS); + __u8 slmcs = NVME_GET(iocsc, IOCS_IOCSC_SLMCS); + __u8 znscs = NVME_GET(iocsc, IOCS_IOCSC_ZNSCS); + __u8 kvcs = NVME_GET(iocsc, IOCS_IOCSC_KVCS); + __u8 nvmcs = NVME_GET(iocsc, IOCS_IOCSC_NVMCS); + + obj_add_str(obj_iocsc, "Computational Programs Namespace Command Set", cpncs ? + "Selected" : "Not selected"); + obj_add_str(obj_iocsc, "Subsystem Local Memory Command Set", slmcs ? + "Selected" : "Not selected"); + obj_add_str(obj_iocsc, "Zoned Namespace Command Set", znscs ? "Selected" : "Not selected"); + obj_add_str(obj_iocsc, "Key Value Command Set", kvcs ? "Selected" : "Not selected"); + obj_add_str(obj_iocsc, "NVM Command Set", nvmcs ? "Selected" : "Not selected"); +} + static void json_id_iocs(struct nvme_id_iocs *iocs) { struct json_object *r = json_create_object(); + struct json_object *obj_iocsc; char json_str[STR_LEN]; __u16 i; @@ -196,6 +214,11 @@ static void json_id_iocs(struct nvme_id_iocs *iocs) if (iocs->iocsc[i]) { sprintf(json_str, "I/O Command Set Combination[%u]", i); obj_add_uint64(r, json_str, le64_to_cpu(iocs->iocsc[i])); + + obj_iocsc = json_create_object(); + sprintf(json_str, "IOCSC%u", i); + json_id_iocs_iocsc(obj_iocsc, le64_to_cpu(iocs->iocsc[i])); + obj_add_obj(r, json_str, obj_iocsc); } } diff --git a/nvme-print-stdout.c b/nvme-print-stdout.c index 2e4acf252d..e10bd11fbc 100644 --- a/nvme-print-stdout.c +++ b/nvme-print-stdout.c @@ -3954,14 +3954,38 @@ static void stdout_endurance_group_list(struct nvme_id_endurance_group_list *end printf("[%4u]:%#x\n", i, le16_to_cpu(endgrp_list->identifier[i])); } +static void stdout_id_iocs_iocsc(__u64 iocsc) +{ + __u8 cpncs = NVME_GET(iocsc, IOCS_IOCSC_CPNCS); + __u8 slmcs = NVME_GET(iocsc, IOCS_IOCSC_SLMCS); + __u8 znscs = NVME_GET(iocsc, IOCS_IOCSC_ZNSCS); + __u8 kvcs = NVME_GET(iocsc, IOCS_IOCSC_KVCS); + __u8 nvmcs = NVME_GET(iocsc, IOCS_IOCSC_NVMCS); + + printf(" [4:4] : %#x\tComputational Programs Namespace Command Set %sSelected\n", + cpncs, cpncs ? "" : "Not "); + printf(" [3:3] : %#x\tSubsystem Local Memory Command Set %sSelected\n", slmcs, + slmcs ? "" : "Not "); + printf(" [2:2] : %#x\tZoned Namespace Command Set %sSelected\n", znscs, + znscs ? "" : "Not "); + printf(" [1:1] : %#x\tKey Value Command Set %sSelected\n", kvcs, kvcs ? "" : "Not "); + printf(" [0:0] : %#x\tNVM Command Set %sSelected\n", nvmcs, nvmcs ? "" : "Not "); + printf("\n"); +} + static void stdout_id_iocs(struct nvme_id_iocs *iocs) { + bool human = stdout_print_ops.flags & VERBOSE; __u16 i; - for (i = 0; i < ARRAY_SIZE(iocs->iocsc); i++) - if (iocs->iocsc[i]) + for (i = 0; i < ARRAY_SIZE(iocs->iocsc); i++) { + if (iocs->iocsc[i]) { printf("I/O Command Set Combination[%u]:%"PRIx64"\n", i, (uint64_t)le64_to_cpu(iocs->iocsc[i])); + if (human) + stdout_id_iocs_iocsc(le64_to_cpu(iocs->iocsc[i])); + } + } } static void stdout_error_log(struct nvme_error_log_page *err_log, int entries, diff --git a/nvme.c b/nvme.c index 6d6e76fdf3..5b722e6ec1 100644 --- a/nvme.c +++ b/nvme.c @@ -4120,8 +4120,8 @@ static int id_iocs(int argc, char **argv, struct command *cmd, struct plugin *pl _cleanup_free_ struct nvme_id_iocs *iocs = NULL; _cleanup_nvme_dev_ struct nvme_dev *dev = NULL; - int err; nvme_print_flags_t flags; + int err; struct config { __u16 cntid; @@ -4144,6 +4144,9 @@ static int id_iocs(int argc, char **argv, struct command *cmd, struct plugin *pl return err; } + if (argconfig_parse_seen(opts, "verbose")) + flags |= VERBOSE; + iocs = nvme_alloc(sizeof(*iocs)); if (!iocs) return -ENOMEM; @@ -4151,7 +4154,7 @@ static int id_iocs(int argc, char **argv, struct command *cmd, struct plugin *pl err = nvme_identify_iocs(dev_fd(dev), cfg.cntid, iocs); if (!err) { printf("NVMe Identify I/O Command Set:\n"); - nvme_show_id_iocs(iocs, 0); + nvme_show_id_iocs(iocs, flags); } else if (err > 0) { nvme_show_status(err); } else {