Skip to content

Commit

Permalink
nvme-print: add human readable output for IOCS Data Structure
Browse files Browse the repository at this point in the history
Add human readable output for Identify I/O Command Set Data
Structure (CNS 1Ch).

Signed-off-by: Francis Pravin <[email protected]>
  • Loading branch information
francispravin5 authored and igaw committed Feb 27, 2025
1 parent 75d7055 commit 91c4bb0
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
23 changes: 23 additions & 0 deletions nvme-print-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,39 @@ 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;

for (i = 0; i < ARRAY_SIZE(iocs->iocsc); i++) {
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);
}
}

Expand Down
28 changes: 26 additions & 2 deletions nvme-print-stdout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 5 additions & 2 deletions nvme.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -4144,14 +4144,17 @@ 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;

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 {
Expand Down

0 comments on commit 91c4bb0

Please sign in to comment.