]> www.infradead.org Git - users/hch/nvme-cli.git/commitdiff
Unify print routines
authorKeith Busch <kbusch@kernel.org>
Tue, 29 Oct 2019 11:01:57 +0000 (20:01 +0900)
committerKeith Busch <kbusch@kernel.org>
Thu, 7 Nov 2019 23:00:59 +0000 (08:00 +0900)
Move all the binary/json/normal output handling into a single function
call for each structure that we print. This will reduce the API surface
that we have to maintain.

Signed-off-by: Keith Busch <kbusch@kernel.org>
nvme-ioctl.c
nvme-lightnvm.c
nvme-print.c
nvme-print.h
nvme-topology.c
nvme.c
nvme.h
plugins/lnvm/lnvm-nvme.c

index ab4153b712552b413c0b83a19cae08fbf6d2e664..61e79910d12ea9cf891957b2939d6a6808e7baba 100644 (file)
@@ -363,6 +363,7 @@ int nvme_identify(int fd, __u32 nsid, __u32 cdw10, void *data)
 
 int nvme_identify_ctrl(int fd, void *data)
 {
+       memset(data, 0, sizeof(struct nvme_id_ctrl));
        return nvme_identify(fd, 0, 1, data);
 }
 
index 22ad9a0f061d9f379b55ac0a9f5053cc9744dcfd..b83310170256af6ee123e6438361ca97d5fe5b2c 100644 (file)
@@ -333,7 +333,7 @@ static void show_lnvm_ppaf(struct nvme_nvm_addr_format *ppaf)
 static void show_lnvm_id12_ns(void *t, unsigned int flags)
 {
        int i;
-       int human = flags & HUMAN;
+       int human = flags & VERBOSE;
        struct nvme_nvm_id12 *id = t;
 
        uint32_t cap = (uint32_t) le32_to_cpu(id->cap);
@@ -379,7 +379,7 @@ static void show_lnvm_id12_ns(void *t, unsigned int flags)
 
 static void show_lnvm_id20_ns(struct nvme_nvm_id20 *id, unsigned int flags)
 {
-       int human = flags & HUMAN;
+       int human = flags & VERBOSE;
        uint32_t mccap = (uint32_t) le32_to_cpu(id->mccap);
 
        printf("ver_major     : %#x\n", id->mjr);
@@ -454,7 +454,7 @@ int lnvm_do_id_ns(int fd, int nsid, unsigned int flags)
 
        err = lnvm_get_identity(fd, nsid, &nvm_id);
        if (!err) {
-               if (flags & RAW)
+               if (flags & BINARY)
                        d_raw((unsigned char *)&nvm_id, sizeof(nvm_id));
                else
                        show_lnvm_id_ns(&nvm_id, flags);
@@ -532,7 +532,7 @@ int lnvm_do_chunk_log(int fd, __u32 nsid, __u32 data_len, void *data,
                goto out;
        }
 
-       if (flags & RAW)
+       if (flags & BINARY)
                d_raw(data, data_len);
        else
                show_lnvm_chunk_log(data, data_len);
@@ -584,7 +584,7 @@ static int __lnvm_do_get_bbtbl(int fd, struct nvme_nvm_id12 *id,
                return err;
        }
 
-       if (flags & RAW)
+       if (flags & BINARY)
                d_raw((unsigned char *)&bbtbl->blk, bbtblsz);
        else {
                printf("LightNVM Bad Block Stats:\n");
index ae91eb843eb1129c4139333de29ca4fa225356fb..3a4be3a4e46a1b05e3e6f63dc8deb25eba90b613 100644 (file)
 #include "util/suffix.h"
 #include "common.h"
 
-static const uint8_t zero_uuid[16] = {
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
-};
+static const uint8_t zero_uuid[16] = { 0 };
+static const uint8_t invalid_uuid[16] = {[0 ... 15] = 0xff };
+static const char dash[100] = {[0 ... 99] = '-'};
 
-static const uint8_t invalid_uuid[16] = {
-       0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
-};
+static long double int128_to_double(__u8 *data)
+{
+       int i;
+       long double result = 0;
+
+       for (i = 0; i < 16; i++) {
+               result *= 256;
+               result += data[15 - i];
+       }
+       return result;
+}
 
 static const char *nvme_ana_state_to_string(enum nvme_ana_state state)
 {
@@ -35,4161 +43,4357 @@ static const char *nvme_ana_state_to_string(enum nvme_ana_state state)
        return "invalid state";
 }
 
-static long double int128_to_double(__u8 *data)
-{
-       int i;
-       long double result = 0;
-
-       for (i = 0; i < 16; i++) {
-               result *= 256;
-               result += data[15 - i];
-       }
-       return result;
-}
-
-void d(unsigned char *buf, int len, int width, int group)
+static const char *nvme_cmd_to_string(int admin, __u8 opcode)
 {
-       int i, offset = 0, line_done = 0;
-       char ascii[32 + 1];
-
-       assert(width < sizeof(ascii));
-       printf("     ");
-       for (i = 0; i <= 15; i++)
-               printf("%3x", i);
-       for (i = 0; i < len; i++) {
-               line_done = 0;
-               if (i % width == 0)
-                       printf( "\n%04x:", offset);
-               if (i % group == 0)
-                       printf( " %02x", buf[i]);
-               else
-                       printf( "%02x", buf[i]);
-               ascii[i % width] = (buf[i] >= '!' && buf[i] <= '~') ? buf[i] : '.';
-               if (((i + 1) % width) == 0) {
-                       ascii[i % width + 1] = '\0';
-                       printf( " \"%.*s\"", width, ascii);
-                       offset += width;
-                       line_done = 1;
+       if (admin) {
+               switch (opcode) {
+               case nvme_admin_delete_sq:      return "Delete I/O Submission Queue";
+               case nvme_admin_create_sq:      return "Create I/O Submission Queue";
+               case nvme_admin_get_log_page:   return "Get Log Page";
+               case nvme_admin_delete_cq:      return "Delete I/O Completion Queue";
+               case nvme_admin_create_cq:      return "Create I/O Completion Queue";
+               case nvme_admin_identify:       return "Identify";
+               case nvme_admin_abort_cmd:      return "Abort";
+               case nvme_admin_set_features:   return "Set Features";
+               case nvme_admin_get_features:   return "Get Features";
+               case nvme_admin_async_event:    return "Asynchronous Event Request";
+               case nvme_admin_ns_mgmt:        return "Namespace Management";
+               case nvme_admin_activate_fw:    return "Firmware Commit";
+               case nvme_admin_download_fw:    return "Firmware Image Download";
+               case nvme_admin_dev_self_test:  return "Device Self-test";
+               case nvme_admin_ns_attach:      return "Namespace Attachment";
+               case nvme_admin_keep_alive:     return "Keep Alive";
+               case nvme_admin_directive_send: return "Directive Send";
+               case nvme_admin_directive_recv: return "Directive Receive";
+               case nvme_admin_virtual_mgmt:   return "Virtualization Management";
+               case nvme_admin_nvme_mi_send:   return "NVMEe-MI Send";
+               case nvme_admin_nvme_mi_recv:   return "NVMEe-MI Receive";
+               case nvme_admin_dbbuf:          return "Doorbell Buffer Config";
+               case nvme_admin_format_nvm:     return "Format NVM";
+               case nvme_admin_security_send:  return "Security Send";
+               case nvme_admin_security_recv:  return "Security Receive";
+               case nvme_admin_sanitize_nvm:   return "Sanitize";
+               }
+       } else {
+               switch (opcode) {
+               case nvme_cmd_flush:            return "Flush";
+               case nvme_cmd_write:            return "Write";
+               case nvme_cmd_read:             return "Read";
+               case nvme_cmd_write_uncor:      return "Write Uncorrectable";
+               case nvme_cmd_compare:          return "Compare";
+               case nvme_cmd_write_zeroes:     return "Write Zeroes";
+               case nvme_cmd_dsm:              return "Dataset Management";
+               case nvme_cmd_resv_register:    return "Reservation Register";
+               case nvme_cmd_resv_report:      return "Reservation Report";
+               case nvme_cmd_resv_acquire:     return "Reservation Acquire";
+               case nvme_cmd_resv_release:     return "Reservation Release";
                }
        }
-       if (!line_done) {
-               unsigned b = width - (i % width);
-               ascii[i % width + 1] = '\0';
-               printf( " %*s \"%.*s\"",
-                               2 * b + b / group + (b % group ? 1 : 0), "",
-                               width, ascii);
-       }
-       printf( "\n");
-}
 
-void d_raw(unsigned char *buf, unsigned len)
-{
-       unsigned i;
-       for (i = 0; i < len; i++)
-               putchar(*(buf+i));
+       return "Unknown";
 }
 
-void show_nvme_status(__u16 status)
+static const char *fw_to_string(__u64 fw)
 {
-       fprintf(stderr, "NVMe status: %s(%#x)\n",
-                       nvme_status_to_string(status), status);
+       static char ret[9];
+       char *c = (char *)&fw;
+       int i;
+
+       for (i = 0; i < 8; i++)
+               ret[i] = c[i] >= '!' && c[i] <= '~' ? c[i] : '.';
+       ret[i] = '\0';
+       return ret;
 }
 
-static void format(char *formatter, size_t fmt_sz, char *tofmt, size_t tofmtsz)
+static const char *get_sanitize_log_sstat_status_str(__u16 status)
 {
+       const char *str;
 
-       fmt_sz = snprintf(formatter,fmt_sz, "%-*.*s",
-                (int)tofmtsz, (int)tofmtsz, tofmt);
-       /* trim() the obnoxious trailing white lines */
-       while (fmt_sz) {
-               if (formatter[fmt_sz - 1] != ' ' && formatter[fmt_sz - 1] != '\0') {
-                       formatter[fmt_sz] = '\0';
-                       break;
-               }
-               fmt_sz--;
+       switch (status & NVME_SANITIZE_LOG_STATUS_MASK) {
+       case NVME_SANITIZE_LOG_NEVER_SANITIZED:
+               str = "NVM Subsystem has never been sanitized.";
+               break;
+       case NVME_SANITIZE_LOG_COMPLETED_SUCCESS:
+               str = "Most Recent Sanitize Command Completed Successfully.";
+               break;
+       case NVME_SANITIZE_LOG_IN_PROGESS:
+               str = "Sanitize in Progress.";
+               break;
+       case NVME_SANITIZE_LOG_COMPLETED_FAILED:
+               str = "Most Recent Sanitize Command Failed.";
+               break;
+       case NVME_SANITIZE_LOG_ND_COMPLETED_SUCCESS:
+               str = "Most Recent Sanitize Command (No-Deallocate After Sanitize) Completed Successfully.";
+               break;
+       default:
+               str = "Unknown.";
        }
+
+       return str;
 }
 
-static const char *nvme_uuid_to_string(uuid_t uuid)
+static void json_nvme_id_ns(struct nvme_id_ns *ns, unsigned int mode)
 {
-       /* large enough to hold uuid str (37) + null-termination byte */
-       static char uuid_str[40];
-#ifdef LIBUUID
-       uuid_unparse_lower(uuid, uuid_str);
-#else
-       static const char *hex_digits = "0123456789abcdef";
-       char *p = &uuid_str[0];
+       char nguid_buf[2 * sizeof(ns->nguid) + 1], eui64_buf[2 * sizeof(ns->eui64) + 1];
+       char *nguid = nguid_buf, *eui64 = eui64_buf;
+       struct json_object *root;
+       struct json_array *lbafs;
        int i;
-       for (i = 0; i < 16; i++) {
-               *p++ = hex_digits[(uuid.b[i] & 0xf0) >> 4];
-               *p++ = hex_digits[uuid.b[i] & 0x0f];
-               if (i == 3 || i == 5 || i == 7 || i == 9)
-                       *p++ = '-';
+
+       long double nvmcap = int128_to_double(ns->nvmcap);
+
+       root = json_create_object();
+
+       json_object_add_value_uint(root, "nsze", le64_to_cpu(ns->nsze));
+       json_object_add_value_uint(root, "ncap", le64_to_cpu(ns->ncap));
+       json_object_add_value_uint(root, "nuse", le64_to_cpu(ns->nuse));
+       json_object_add_value_int(root, "nsfeat", ns->nsfeat);
+       json_object_add_value_int(root, "nlbaf", ns->nlbaf);
+       json_object_add_value_int(root, "flbas", ns->flbas);
+       json_object_add_value_int(root, "mc", ns->mc);
+       json_object_add_value_int(root, "dpc", ns->dpc);
+       json_object_add_value_int(root, "dps", ns->dps);
+       json_object_add_value_int(root, "nmic", ns->nmic);
+       json_object_add_value_int(root, "rescap", ns->rescap);
+       json_object_add_value_int(root, "fpi", ns->fpi);
+       json_object_add_value_int(root, "nawun", le16_to_cpu(ns->nawun));
+       json_object_add_value_int(root, "nawupf", le16_to_cpu(ns->nawupf));
+       json_object_add_value_int(root, "nacwu", le16_to_cpu(ns->nacwu));
+       json_object_add_value_int(root, "nabsn", le16_to_cpu(ns->nabsn));
+       json_object_add_value_int(root, "nabo", le16_to_cpu(ns->nabo));
+       json_object_add_value_int(root, "nabspf", le16_to_cpu(ns->nabspf));
+       json_object_add_value_int(root, "noiob", le16_to_cpu(ns->noiob));
+       json_object_add_value_float(root, "nvmcap", nvmcap);
+       json_object_add_value_int(root, "nsattr", ns->nsattr);
+       json_object_add_value_int(root, "nvmsetid", le16_to_cpu(ns->nvmsetid));
+
+       if (ns->nsfeat & 0x10) {
+               json_object_add_value_int(root, "npwg", le16_to_cpu(ns->npwg));
+               json_object_add_value_int(root, "npwa", le16_to_cpu(ns->npwa));
+               json_object_add_value_int(root, "npdg", le16_to_cpu(ns->npdg));
+               json_object_add_value_int(root, "npda", le16_to_cpu(ns->npda));
+               json_object_add_value_int(root, "nows", le16_to_cpu(ns->nows));
        }
-       *p = '\0';
-#endif
-       return uuid_str;
-}
 
-static void show_nvme_id_ctrl_cmic(__u8 cmic)
-{
-       __u8 rsvd = (cmic & 0xF0) >> 4;
-       __u8 ana = (cmic & 0x8) >> 3;
-       __u8 sriov = (cmic & 0x4) >> 2;
-       __u8 mctl = (cmic & 0x2) >> 1;
-       __u8 mp = cmic & 0x1;
-       if (rsvd)
-               printf("  [7:4] : %#x\tReserved\n", rsvd);
-       printf("  [3:3] : %#x\tANA %ssupported\n", ana, ana ? "" : "not ");
-       printf("  [2:2] : %#x\t%s\n", sriov, sriov ? "SR-IOV" : "PCI");
-       printf("  [1:1] : %#x\t%s Controller\n",
-               mctl, mctl ? "Multi" : "Single");
-       printf("  [0:0] : %#x\t%s Port\n", mp, mp ? "Multi" : "Single");
+       json_object_add_value_int(root, "anagrpid", le32_to_cpu(ns->anagrpid));
+       json_object_add_value_int(root, "endgid", le16_to_cpu(ns->endgid));
+
+       memset(eui64, 0, sizeof(eui64_buf));
+       for (i = 0; i < sizeof(ns->eui64); i++)
+               eui64 += sprintf(eui64, "%02x", ns->eui64[i]);
+
+       memset(nguid, 0, sizeof(nguid_buf));
+       for (i = 0; i < sizeof(ns->nguid); i++)
+               nguid += sprintf(nguid, "%02x", ns->nguid[i]);
+
+       json_object_add_value_string(root, "eui64", eui64_buf);
+       json_object_add_value_string(root, "nguid", nguid_buf);
+
+       lbafs = json_create_array();
+       json_object_add_value_array(root, "lbafs", lbafs);
+
+       for (i = 0; i <= ns->nlbaf; i++) {
+               struct json_object *lbaf = json_create_object();
+
+               json_object_add_value_int(lbaf, "ms", le16_to_cpu(ns->lbaf[i].ms));
+               json_object_add_value_int(lbaf, "ds", ns->lbaf[i].ds);
+               json_object_add_value_int(lbaf, "rp", ns->lbaf[i].rp);
+
+               json_array_add_value_object(lbafs, lbaf);
+       }
+
+       json_print_object(root, NULL);
        printf("\n");
+       json_free_object(root);
 }
 
-static void show_nvme_id_ctrl_oaes(__le32 ctrl_oaes)
+static void json_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode,
+                       void (*vs)(__u8 *vs, struct json_object *root))
 {
-       __u32 oaes = le32_to_cpu(ctrl_oaes);
-       __u32 rsvd0 = (oaes & 0xFFFF8000) >> 15;
-       __u32 nace = (oaes & 0x100) >> 8;
-       __u32 fan = (oaes & 0x200) >> 9;
-       __u32 anacn = (oaes & 800) >> 11;
-       __u32 plealcn = (oaes & 0x1000) >> 12;
-       __u32 lbasin = (oaes & 0x2000) >> 13;
-       __u32 egealpcn = (oaes & 0x4000) >> 14;
-       __u32 rsvd1 = oaes & 0xFF;
+       struct json_object *root;
+       struct json_array *psds;
 
-       if (rsvd0)
-               printf(" [31:10] : %#x\tReserved\n", rsvd0);
-       printf("[14:14] : %#x\tEndurance Group Event Aggregate Log Page"\
-                       " Change Notice %sSupported\n",
-                       egealpcn, egealpcn ? "" : "Not ");
-       printf("[13:13] : %#x\tLBA Status Information Notices %sSupported\n",
-                       lbasin, lbasin ? "" : "Not ");
-       printf("[12:12] : %#x\tPredictable Latency Event Aggregate Log Change"\
-                       " Notices %sSupported\n",
-                       plealcn, plealcn ? "" : "Not ");
-       printf("[11:11] : %#x\tAsymmetric Namespace Access Change Notices"\
-                       " %sSupported\n", anacn, anacn ? "" : "Not ");
-       printf("  [9:9] : %#x\tFirmware Activation Notices %sSupported\n",
-               fan, fan ? "" : "Not ");
-       printf("  [8:8] : %#x\tNamespace Attribute Changed Event %sSupported\n",
-               nace, nace ? "" : "Not ");
-       if (rsvd1)
-               printf("  [7:0] : %#x\tReserved\n", rsvd1);
-       printf("\n");
-}
-
-static void show_nvme_id_ctrl_ctratt(__le32 ctrl_ctratt)
-{
-       __u32 ctratt = le32_to_cpu(ctrl_ctratt);
-       __u32 rsvd = ctratt >> 10;
-       __u32 hostid128 = (ctratt & NVME_CTRL_CTRATT_128_ID) >> 0;
-       __u32 psp = (ctratt & NVME_CTRL_CTRATT_NON_OP_PSP) >> 1;
-       __u32 sets = (ctratt & NVME_CTRL_CTRATT_NVM_SETS) >> 2;
-       __u32 rrl = (ctratt & NVME_CTRL_CTRATT_READ_RECV_LVLS) >> 3;
-       __u32 eg = (ctratt & NVME_CTRL_CTRATT_ENDURANCE_GROUPS) >> 4;
-       __u32 iod = (ctratt & NVME_CTRL_CTRATT_PREDICTABLE_LAT) >> 5;
-       __u32 ng = (ctratt & NVME_CTRL_CTRATT_NAMESPACE_GRANULARITY) >> 7;
-       __u32 uuidlist = (ctratt & NVME_CTRL_CTRATT_UUID_LIST) >> 9;
-       __u32 rsvd6 = (ctratt & 0x00000040) >> 6;
-       __u32 rsvd8 = (ctratt & 0x00000100) >> 8;
-
-       if (rsvd)
-               printf(" [31:10] : %#x\tReserved\n", rsvd);
-
-       printf("  [9:9] : %#x\tUUID List %sSupported\n",
-               uuidlist, uuidlist ? "" : "Not ");
-       if (rsvd8)
-               printf(" [8:8] : %#x\tReserved\n", rsvd8);
-       printf("  [7:7] : %#x\tNamespace Granularity %sSupported\n",
-               ng, ng ? "" : "Not ");
-       if (rsvd6)
-               printf(" [6:6] : %#x\tReserved\n", rsvd6);
-       printf("  [5:5] : %#x\tPredictable Latency Mode %sSupported\n",
-               iod, iod ? "" : "Not ");
-       printf("  [4:4] : %#x\tEndurance Groups %sSupported\n",
-               eg, eg ? "" : "Not ");
-       printf("  [3:3] : %#x\tRead Recovery Levels %sSupported\n",
-               rrl, rrl ? "" : "Not ");
-       printf("  [2:2] : %#x\tNVM Sets %sSupported\n",
-               sets, sets ? "" : "Not ");
-       printf("  [1:1] : %#x\tNon-Operational Power State Permissive %sSupported\n",
-               psp, psp ? "" : "Not ");
-       printf("  [0:0] : %#x\t128-bit Host Identifier %sSupported\n",
-               hostid128, hostid128 ? "" : "Not ");
-       printf("\n");
-}
-
-static void show_nvme_id_ctrl_cntrltype(__u8 cntrltype)
-{
-       __u8 rsvd = (cntrltype & 0xFC) >> 2;
-       __u8 cntrl = cntrltype & 0x3;
-
-       static const char *type[] = {
-               "Controller type not reported",
-               "I/O Controller",
-               "Discovery Controller",
-               "Administrative Controller"
-       };
-
-       printf("  [7:2] : %#x\tReserved\n", rsvd);
-       printf("  [1:0] : %#x\t%s\n", cntrltype, type[cntrl]);
-}
-
-static void show_nvme_id_ctrl_oacs(__le16 ctrl_oacs)
-{
-       __u16 oacs = le16_to_cpu(ctrl_oacs);
-       __u16 rsvd = (oacs & 0xFC00) >> 10;
-       __u16 glbas = (oacs & 0x200) >> 9;
-       __u16 dbc = (oacs & 0x100) >> 8;
-       __u16 vir = (oacs & 0x80) >> 7;
-       __u16 nmi = (oacs & 0x40) >> 6;
-       __u16 dir = (oacs & 0x20) >> 5;
-       __u16 sft = (oacs & 0x10) >> 4;
-       __u16 nsm = (oacs & 0x8) >> 3;
-       __u16 fwc = (oacs & 0x4) >> 2;
-       __u16 fmt = (oacs & 0x2) >> 1;
-       __u16 sec = oacs & 0x1;
-
-       if (rsvd)
-               printf(" [15:9] : %#x\tReserved\n", rsvd);
-       printf("  [9:9] : %#x\tGet LBA Status Capability %sSupported\n",
-               glbas, glbas ? "" : "Not ");
-       printf("  [8:8] : %#x\tDoorbell Buffer Config %sSupported\n",
-               dbc, dbc ? "" : "Not ");
-       printf("  [7:7] : %#x\tVirtualization Management %sSupported\n",
-               vir, vir ? "" : "Not ");
-       printf("  [6:6] : %#x\tNVMe-MI Send and Receive %sSupported\n",
-               nmi, nmi ? "" : "Not ");
-       printf("  [5:5] : %#x\tDirectives %sSupported\n",
-               dir, dir ? "" : "Not ");
-       printf("  [4:4] : %#x\tDevice Self-test %sSupported\n",
-               sft, sft ? "" : "Not ");
-       printf("  [3:3] : %#x\tNS Management and Attachment %sSupported\n",
-               nsm, nsm ? "" : "Not ");
-       printf("  [2:2] : %#x\tFW Commit and Download %sSupported\n",
-               fwc, fwc ? "" : "Not ");
-       printf("  [1:1] : %#x\tFormat NVM %sSupported\n",
-               fmt, fmt ? "" : "Not ");
-       printf("  [0:0] : %#x\tSecurity Send and Receive %sSupported\n",
-               sec, sec ? "" : "Not ");
-       printf("\n");
-}
+       long double tnvmcap = int128_to_double(ctrl->tnvmcap);
+       long double unvmcap = int128_to_double(ctrl->unvmcap);
 
-static void show_nvme_id_ctrl_frmw(__u8 frmw)
-{
-       __u8 rsvd = (frmw & 0xE0) >> 5;
-       __u8 fawr = (frmw & 0x10) >> 4;
-       __u8 nfws = (frmw & 0xE) >> 1;
-       __u8 s1ro = frmw & 0x1;
-       if (rsvd)
-               printf("  [7:5] : %#x\tReserved\n", rsvd);
-       printf("  [4:4] : %#x\tFirmware Activate Without Reset %sSupported\n",
-               fawr, fawr ? "" : "Not ");
-       printf("  [3:1] : %#x\tNumber of Firmware Slots\n", nfws);
-       printf("  [0:0] : %#x\tFirmware Slot 1 Read%s\n",
-               s1ro, s1ro ? "-Only" : "/Write");
-       printf("\n");
-}
+       char sn[sizeof(ctrl->sn) + 1], mn[sizeof(ctrl->mn) + 1],
+               fr[sizeof(ctrl->fr) + 1], subnqn[sizeof(ctrl->subnqn) + 1];
+       __u32 ieee = ctrl->ieee[2] << 16 | ctrl->ieee[1] << 8 | ctrl->ieee[0];
 
-static void show_nvme_id_ctrl_lpa(__u8 lpa)
-{
-       __u8 rsvd = (lpa & 0xE0) >> 5;
-       __u8 persevnt = (lpa & 0x10) >> 4;
-       __u8 telem = (lpa & 0x8) >> 3;
-       __u8 ed = (lpa & 0x4) >> 2;
-       __u8 celp = (lpa & 0x2) >> 1;
-       __u8 smlp = lpa & 0x1;
-       if (rsvd)
-               printf("  [7:4] : %#x\tReserved\n", rsvd);
-       printf("  [4:4] : %#x\tPersistent Event log %sSupported\n",
-                       persevnt, persevnt ? "" : "Not ");
-       printf("  [3:3] : %#x\tTelemetry host/controller initiated log page %sSupported\n",
-              telem, telem ? "" : "Not ");
-       printf("  [2:2] : %#x\tExtended data for Get Log Page %sSupported\n",
-               ed, ed ? "" : "Not ");
-       printf("  [1:1] : %#x\tCommand Effects Log Page %sSupported\n",
-               celp, celp ? "" : "Not ");
-       printf("  [0:0] : %#x\tSMART/Health Log Page per NS %sSupported\n",
-               smlp, smlp ? "" : "Not ");
-       printf("\n");
-}
+       int i;
 
-static void show_nvme_id_ctrl_avscc(__u8 avscc)
-{
-       __u8 rsvd = (avscc & 0xFE) >> 1;
-       __u8 fmt = avscc & 0x1;
-       if (rsvd)
-               printf("  [7:1] : %#x\tReserved\n", rsvd);
-       printf("  [0:0] : %#x\tAdmin Vendor Specific Commands uses %s Format\n",
-               fmt, fmt ? "NVMe" : "Vendor Specific");
-       printf("\n");
-}
+       snprintf(sn, sizeof(sn), "%-.*s", (int)sizeof(ctrl->sn), ctrl->sn);
+       snprintf(mn, sizeof(mn), "%-.*s", (int)sizeof(ctrl->mn), ctrl->mn);
+       snprintf(fr, sizeof(fr), "%-.*s", (int)sizeof(ctrl->fr), ctrl->fr);
+       snprintf(subnqn, sizeof(subnqn), "%-.*s", (int)sizeof(ctrl->subnqn), ctrl->subnqn);
 
-static void show_nvme_id_ctrl_apsta(__u8 apsta)
-{
-       __u8 rsvd = (apsta & 0xFE) >> 1;
-       __u8 apst = apsta & 0x1;
-       if (rsvd)
-               printf("  [7:1] : %#x\tReserved\n", rsvd);
-       printf("  [0:0] : %#x\tAutonomous Power State Transitions %sSupported\n",
-               apst, apst ? "" : "Not ");
-       printf("\n");
-}
+       root = json_create_object();
 
-static void show_nvme_id_ctrl_rpmbs(__le32 ctrl_rpmbs)
-{
-       __u32 rpmbs = le32_to_cpu(ctrl_rpmbs);
-       __u32 asz = (rpmbs & 0xFF000000) >> 24;
-       __u32 tsz = (rpmbs & 0xFF0000) >> 16;
-       __u32 rsvd = (rpmbs & 0xFFC0) >> 6;
-       __u32 auth = (rpmbs & 0x38) >> 3;
-       __u32 rpmb = rpmbs & 0x7;
+       json_object_add_value_int(root, "vid", le16_to_cpu(ctrl->vid));
+       json_object_add_value_int(root, "ssvid", le16_to_cpu(ctrl->ssvid));
+       json_object_add_value_string(root, "sn", sn);
+       json_object_add_value_string(root, "mn", mn);
+       json_object_add_value_string(root, "fr", fr);
+       json_object_add_value_int(root, "rab", ctrl->rab);
+       json_object_add_value_int(root, "ieee", ieee);
+       json_object_add_value_int(root, "cmic", ctrl->cmic);
+       json_object_add_value_int(root, "mdts", ctrl->mdts);
+       json_object_add_value_int(root, "cntlid", le16_to_cpu(ctrl->cntlid));
+       json_object_add_value_uint(root, "ver", le32_to_cpu(ctrl->ver));
+       json_object_add_value_uint(root, "rtd3r", le32_to_cpu(ctrl->rtd3r));
+       json_object_add_value_uint(root, "rtd3e", le32_to_cpu(ctrl->rtd3e));
+       json_object_add_value_uint(root, "oaes", le32_to_cpu(ctrl->oaes));
+       json_object_add_value_int(root, "ctratt", le32_to_cpu(ctrl->ctratt));
+       json_object_add_value_int(root, "rrls", le16_to_cpu(ctrl->rrls));
+       json_object_add_value_int(root, "crdt1", le16_to_cpu(ctrl->crdt1));
+       json_object_add_value_int(root, "crdt2", le16_to_cpu(ctrl->crdt2));
+       json_object_add_value_int(root, "crdt3", le16_to_cpu(ctrl->crdt3));
+       json_object_add_value_int(root, "oacs", le16_to_cpu(ctrl->oacs));
+       json_object_add_value_int(root, "acl", ctrl->acl);
+       json_object_add_value_int(root, "aerl", ctrl->aerl);
+       json_object_add_value_int(root, "frmw", ctrl->frmw);
+       json_object_add_value_int(root, "lpa", ctrl->lpa);
+       json_object_add_value_int(root, "elpe", ctrl->elpe);
+       json_object_add_value_int(root, "npss", ctrl->npss);
+       json_object_add_value_int(root, "avscc", ctrl->avscc);
+       json_object_add_value_int(root, "apsta", ctrl->apsta);
+       json_object_add_value_int(root, "wctemp", le16_to_cpu(ctrl->wctemp));
+       json_object_add_value_int(root, "cctemp", le16_to_cpu(ctrl->cctemp));
+       json_object_add_value_int(root, "mtfa", le16_to_cpu(ctrl->mtfa));
+       json_object_add_value_uint(root, "hmpre", le32_to_cpu(ctrl->hmpre));
+       json_object_add_value_uint(root, "hmmin", le32_to_cpu(ctrl->hmmin));
+       json_object_add_value_float(root, "tnvmcap", tnvmcap);
+       json_object_add_value_float(root, "unvmcap", unvmcap);
+       json_object_add_value_uint(root, "rpmbs", le32_to_cpu(ctrl->rpmbs));
+       json_object_add_value_int(root, "edstt", le16_to_cpu(ctrl->edstt));
+       json_object_add_value_int(root, "dsto", ctrl->dsto);
+       json_object_add_value_int(root, "fwug", ctrl->fwug);
+       json_object_add_value_int(root, "kas", le16_to_cpu(ctrl->kas));
+       json_object_add_value_int(root, "hctma", le16_to_cpu(ctrl->hctma));
+       json_object_add_value_int(root, "mntmt", le16_to_cpu(ctrl->mntmt));
+       json_object_add_value_int(root, "mxtmt", le16_to_cpu(ctrl->mxtmt));
+       json_object_add_value_int(root, "sanicap", le32_to_cpu(ctrl->sanicap));
+       json_object_add_value_int(root, "hmminds", le32_to_cpu(ctrl->hmminds));
+       json_object_add_value_int(root, "hmmaxd", le16_to_cpu(ctrl->hmmaxd));
+       json_object_add_value_int(root, "nsetidmax", le16_to_cpu(ctrl->nsetidmax));
 
-       printf(" [31:24]: %#x\tAccess Size\n", asz);
-       printf(" [23:16]: %#x\tTotal Size\n", tsz);
-       if (rsvd)
-               printf(" [15:6] : %#x\tReserved\n", rsvd);
-       printf("  [5:3] : %#x\tAuthentication Method\n", auth);
-       printf("  [2:0] : %#x\tNumber of RPMB Units\n", rpmb);
-       printf("\n");
-}
+       json_object_add_value_int(root, "anatt",ctrl->anatt);
+       json_object_add_value_int(root, "anacap", ctrl->anacap);
+       json_object_add_value_int(root, "anagrpmax", le32_to_cpu(ctrl->anagrpmax));
+       json_object_add_value_int(root, "nanagrpid", le32_to_cpu(ctrl->nanagrpid));
+       json_object_add_value_int(root, "sqes", ctrl->sqes);
+       json_object_add_value_int(root, "cqes", ctrl->cqes);
+       json_object_add_value_int(root, "maxcmd", le16_to_cpu(ctrl->maxcmd));
+       json_object_add_value_uint(root, "nn", le32_to_cpu(ctrl->nn));
+       json_object_add_value_int(root, "oncs", le16_to_cpu(ctrl->oncs));
+       json_object_add_value_int(root, "fuses", le16_to_cpu(ctrl->fuses));
+       json_object_add_value_int(root, "fna", ctrl->fna);
+       json_object_add_value_int(root, "vwc", ctrl->vwc);
+       json_object_add_value_int(root, "awun", le16_to_cpu(ctrl->awun));
+       json_object_add_value_int(root, "awupf", le16_to_cpu(ctrl->awupf));
+       json_object_add_value_int(root, "nvscc", ctrl->nvscc);
+       json_object_add_value_int(root, "nwpc", ctrl->nwpc);
+       json_object_add_value_int(root, "acwu", le16_to_cpu(ctrl->acwu));
+       json_object_add_value_int(root, "sgls", le32_to_cpu(ctrl->sgls));
 
-static void show_nvme_id_ctrl_hctma(__le16 ctrl_hctma)
-{
-       __u16 hctma = le16_to_cpu(ctrl_hctma);
-       __u16 rsvd = (hctma & 0xFFFE) >> 1;
-       __u16 hctm = hctma & 0x1;
+       if (strlen(subnqn))
+               json_object_add_value_string(root, "subnqn", subnqn);
 
-       if (rsvd)
-               printf(" [15:1] : %#x\tReserved\n", rsvd);
-       printf("  [0:0] : %#x\tHost Controlled Thermal Management %sSupported\n",
-               hctm, hctm ? "" : "Not ");
-       printf("\n");
-}
+       json_object_add_value_int(root, "ioccsz", le32_to_cpu(ctrl->ioccsz));
+       json_object_add_value_int(root, "iorcsz", le32_to_cpu(ctrl->iorcsz));
+       json_object_add_value_int(root, "icdoff", le16_to_cpu(ctrl->icdoff));
+       json_object_add_value_int(root, "ctrattr", ctrl->ctrattr);
+       json_object_add_value_int(root, "msdbd", ctrl->msdbd);
 
-static void show_nvme_id_ctrl_sanicap(__le32 ctrl_sanicap)
-{
-       __u32 sanicap = le32_to_cpu(ctrl_sanicap);
-       __u32 rsvd = (sanicap & 0x1FFFFFF8) >> 3;
-       __u32 owr = (sanicap & 0x4) >> 2;
-       __u32 ber = (sanicap & 0x2) >> 1;
-       __u32 cer = sanicap & 0x1;
-       __u32 ndi = (sanicap & 0x20000000) >> 29;
-       __u32 nodmmas = (sanicap & 0xC0000000) >> 30;
+       psds = json_create_array();
+       json_object_add_value_array(root, "psds", psds);
 
-       static const char *modifies_media[] = {
-               "Additional media modification after sanitize operation completes successfully is not defined",
-               "Media is not additionally modified after sanitize operation completes successfully",
-               "Media is additionally modified after sanitize operation completes successfully",
-               "Reserved"
-       };
+       for (i = 0; i <= ctrl->npss; i++) {
+               struct json_object *psd = json_create_object();
 
-       printf("  [31:30] : %#x\t%s\n", nodmmas, modifies_media[nodmmas]);
-       printf("  [29:29] : %#x\tNo-Deallocate After Sanitize bit in Sanitize command %sSupported\n",
-               ndi, ndi ? "Not " : "");
-       if (rsvd)
-               printf("  [28:3] : %#x\tReserved\n", rsvd);
-       printf("    [2:2] : %#x\tOverwrite Sanitize Operation %sSupported\n",
-               owr, owr ? "" : "Not ");
-       printf("    [1:1] : %#x\tBlock Erase Sanitize Operation %sSupported\n",
-               ber, ber ? "" : "Not ");
-       printf("    [0:0] : %#x\tCrypto Erase Sanitize Operation %sSupported\n",
-               cer, cer ? "" : "Not ");
-       printf("\n");
-}
+               json_object_add_value_int(psd, "max_power",
+                       le16_to_cpu(ctrl->psd[i].max_power));
+               json_object_add_value_int(psd, "flags", ctrl->psd[i].flags);
+               json_object_add_value_uint(psd, "entry_lat",
+                       le32_to_cpu(ctrl->psd[i].entry_lat));
+               json_object_add_value_uint(psd, "exit_lat",
+                       le32_to_cpu(ctrl->psd[i].exit_lat));
+               json_object_add_value_int(psd, "read_tput", ctrl->psd[i].read_tput);
+               json_object_add_value_int(psd, "read_lat", ctrl->psd[i].read_lat);
+               json_object_add_value_int(psd, "write_tput", ctrl->psd[i].write_tput);
+               json_object_add_value_int(psd, "write_lat", ctrl->psd[i].write_lat);
+               json_object_add_value_int(psd, "idle_power",
+                       le16_to_cpu(ctrl->psd[i].idle_power));
+               json_object_add_value_int(psd, "idle_scale", ctrl->psd[i].idle_scale);
+               json_object_add_value_int(psd, "active_power",
+                       le16_to_cpu(ctrl->psd[i].active_power));
+               json_object_add_value_int(psd, "active_work_scale", ctrl->psd[i].active_work_scale);
 
-static void show_nvme_id_ctrl_anacap(__u8 anacap)
-{
-       __u8 nz = (anacap & 0x80) >> 7;
-       __u8 grpid_change = (anacap & 0x40) >> 6;
-       __u8 rsvd = (anacap & 0x20) >> 5;
-       __u8 ana_change = (anacap & 0x10) >> 4;
-       __u8 ana_persist_loss = (anacap & 0x08) >> 3;
-       __u8 ana_inaccessible = (anacap & 0x04) >> 2;
-       __u8 ana_nonopt = (anacap & 0x02) >> 1;
-       __u8 ana_opt = (anacap & 0x01);
+               json_array_add_value_object(psds, psd);
+       }
 
-       printf("  [7:7] : %#x\tNon-zero group ID %sSupported\n",
-                       nz, nz ? "" : "Not ");
-       printf("  [6:6] : %#x\tGroup ID does %schange\n",
-                       grpid_change, grpid_change ? "" : "not ");
-       if (rsvd)
-               printf(" [5:5] : %#x\tReserved\n", rsvd);
-       printf("  [4:4] : %#x\tANA Change state %sSupported\n",
-                       ana_change, ana_change ? "" : "Not ");
-       printf("  [3:3] : %#x\tANA Persistent Loss state %sSupported\n",
-                       ana_persist_loss, ana_persist_loss ? "" : "Not ");
-       printf("  [2:2] : %#x\tANA Inaccessible state %sSupported\n",
-                       ana_inaccessible, ana_inaccessible ? "" : "Not ");
-       printf("  [1:1] : %#x\tANA Non-optimized state %sSupported\n",
-                       ana_nonopt, ana_nonopt ? "" : "Not ");
-       printf("  [0:0] : %#x\tANA Optimized state %sSupported\n",
-                       ana_opt, ana_opt ? "" : "Not ");
+       if(vs)
+               vs(ctrl->vs, root);
+       json_print_object(root, NULL);
        printf("\n");
+       json_free_object(root);
 }
 
-static void show_nvme_id_ctrl_sqes(__u8 sqes)
+static void json_error_log(struct nvme_error_log_page *err_log, int entries)
 {
-       __u8 msqes = (sqes & 0xF0) >> 4;
-       __u8 rsqes = sqes & 0xF;
-       printf("  [7:4] : %#x\tMax SQ Entry Size (%d)\n", msqes, 1 << msqes);
-       printf("  [3:0] : %#x\tMin SQ Entry Size (%d)\n", rsqes, 1 << rsqes);
-       printf("\n");
-}
+       struct json_object *root;
+       struct json_array *errors;
 
-static void show_nvme_id_ctrl_cqes(__u8 cqes)
-{
-       __u8 mcqes = (cqes & 0xF0) >> 4;
-       __u8 rcqes = cqes & 0xF;
-       printf("  [7:4] : %#x\tMax CQ Entry Size (%d)\n", mcqes, 1 << mcqes);
-       printf("  [3:0] : %#x\tMin CQ Entry Size (%d)\n", rcqes, 1 << rcqes);
-       printf("\n");
-}
+       int i;
 
-static void show_nvme_id_ctrl_oncs(__le16 ctrl_oncs)
-{
-       __u16 oncs = le16_to_cpu(ctrl_oncs);
-       __u16 rsvd = (oncs & 0xFF00) >> 8;
-       __u16 vrfy = (oncs & 0x80) >> 7;
-       __u16 tmst = (oncs & 0x40) >> 6;
-       __u16 resv = (oncs & 0x20) >> 5;
-       __u16 save = (oncs & 0x10) >> 4;
-       __u16 wzro = (oncs & 0x8) >> 3;
-       __u16 dsms = (oncs & 0x4) >> 2;
-       __u16 wunc = (oncs & 0x2) >> 1;
-       __u16 cmp = oncs & 0x1;
+       root = json_create_object();
 
-       if (rsvd)
-               printf(" [15:8] : %#x\tReserved\n", rsvd);
-       printf("  [7:7] : %#x\tVerify %sSupported\n",
-               vrfy, vrfy ? "" : "Not ");
-       printf("  [6:6] : %#x\tTimestamp %sSupported\n",
-               tmst, tmst ? "" : "Not ");
-       printf("  [5:5] : %#x\tReservations %sSupported\n",
-               resv, resv ? "" : "Not ");
-       printf("  [4:4] : %#x\tSave and Select %sSupported\n",
-               save, save ? "" : "Not ");
-       printf("  [3:3] : %#x\tWrite Zeroes %sSupported\n",
-               wzro, wzro ? "" : "Not ");
-       printf("  [2:2] : %#x\tData Set Management %sSupported\n",
-               dsms, dsms ? "" : "Not ");
-       printf("  [1:1] : %#x\tWrite Uncorrectable %sSupported\n",
-               wunc, wunc ? "" : "Not ");
-       printf("  [0:0] : %#x\tCompare %sSupported\n",
-               cmp, cmp ? "" : "Not ");
-       printf("\n");
-}
+       errors = json_create_array();
+       json_object_add_value_array(root, "errors", errors);
 
-static void show_nvme_id_ctrl_fuses(__le16 ctrl_fuses)
-{
-       __u16 fuses = le16_to_cpu(ctrl_fuses);
-       __u16 rsvd = (fuses & 0xFE) >> 1;
-       __u16 cmpw = fuses & 0x1;
+       for (i = 0; i < entries; i++) {
+               struct json_object *error = json_create_object();
 
-       if (rsvd)
-               printf(" [15:1] : %#x\tReserved\n", rsvd);
-       printf("  [0:0] : %#x\tFused Compare and Write %sSupported\n",
-               cmpw, cmpw ? "" : "Not ");
-       printf("\n");
-}
+               json_object_add_value_uint(error, "error_count",
+                                          le64_to_cpu(err_log[i].error_count));
+               json_object_add_value_int(error, "sqid",
+                                         le16_to_cpu(err_log[i].sqid));
+               json_object_add_value_int(error, "cmdid",
+                                         le16_to_cpu(err_log[i].cmdid));
+               json_object_add_value_int(error, "status_field",
+                                         le16_to_cpu(err_log[i].status_field));
+               json_object_add_value_int(error, "parm_error_location",
+                                         le16_to_cpu(err_log[i].parm_error_location));
+               json_object_add_value_uint(error, "lba",
+                                          le64_to_cpu(err_log[i].lba));
+               json_object_add_value_uint(error, "nsid",
+                                          le32_to_cpu(err_log[i].nsid));
+               json_object_add_value_int(error, "vs", err_log[i].vs);
+               json_object_add_value_int(error, "trtype", err_log[i].trtype);
+               json_object_add_value_uint(error, "cs",
+                                          le64_to_cpu(err_log[i].cs));
+               json_object_add_value_int(error, "trtype_spec_info",
+                                         le16_to_cpu(err_log[i].trtype_spec_info));
 
-static void show_nvme_id_ctrl_fna(__u8 fna)
-{
-       __u8 rsvd = (fna & 0xF8) >> 3;
-       __u8 cese = (fna & 0x4) >> 2;
-       __u8 cens = (fna & 0x2) >> 1;
-       __u8 fmns = fna & 0x1;
-       if (rsvd)
-               printf("  [7:3] : %#x\tReserved\n", rsvd);
-       printf("  [2:2] : %#x\tCrypto Erase %sSupported as part of Secure Erase\n",
-               cese, cese ? "" : "Not ");
-       printf("  [1:1] : %#x\tCrypto Erase Applies to %s Namespace(s)\n",
-               cens, cens ? "All" : "Single");
-       printf("  [0:0] : %#x\tFormat Applies to %s Namespace(s)\n",
-               fmns, fmns ? "All" : "Single");
+               json_array_add_value_object(errors, error);
+       }
+
+       json_print_object(root, NULL);
        printf("\n");
+       json_free_object(root);
 }
 
-static void show_nvme_id_ctrl_vwc(__u8 vwc)
+static void json_nvme_resv_report(struct nvme_reservation_status *status, int bytes, __u32 cdw11)
 {
-       __u8 rsvd = (vwc & 0xF8) >> 3;
-       __u8 flush = (vwc & 0x6) >> 1;
-       __u8 vwcp = vwc & 0x1;
+       struct json_object *root;
+       struct json_array *rcs;
+       int i, j, regctl, entries;
 
-       static const char *flush_behavior[] = {
-               "Support for the NSID field set to FFFFFFFFh is not indicated",
-               "Reserved",
-               "The Flush command does not support NSID set to FFFFFFFFh",
-               "The Flush command supports NSID set to FFFFFFFFh"
-       };
+       regctl = status->regctl[0] | (status->regctl[1] << 8);
 
-       if (rsvd)
-               printf("  [7:3] : %#x\tReserved\n", rsvd);
-       printf("  [2:1] : %#x\t%s\n", flush, flush_behavior[flush]);
-       printf("  [0:0] : %#x\tVolatile Write Cache %sPresent\n",
-               vwcp, vwcp ? "" : "Not ");
-       printf("\n");
-}
+       root = json_create_object();
 
-static void show_nvme_id_ctrl_nvscc(__u8 nvscc)
-{
-       __u8 rsvd = (nvscc & 0xFE) >> 1;
-       __u8 fmt = nvscc & 0x1;
-       if (rsvd)
-               printf("  [7:1] : %#x\tReserved\n", rsvd);
-       printf("  [0:0] : %#x\tNVM Vendor Specific Commands uses %s Format\n",
-               fmt, fmt ? "NVMe" : "Vendor Specific");
-       printf("\n");
-}
+       json_object_add_value_int(root, "gen", le32_to_cpu(status->gen));
+       json_object_add_value_int(root, "rtype", status->rtype);
+       json_object_add_value_int(root, "regctl", regctl);
+       json_object_add_value_int(root, "ptpls", status->ptpls);
 
-static void show_nvme_id_ctrl_nwpc(__u8 nwpc)
-{
-       __u8 no_wp_wp = (nwpc & 0x01);
-       __u8 wp_power_cycle = (nwpc & 0x02) >> 1;
-       __u8 wp_permanent = (nwpc & 0x04) >> 2;
-       __u8 rsvd = (nwpc & 0xF8) >> 3;
+       rcs = json_create_array();
+        /* check Extended Data Structure bit */
+        if ((cdw11 & 0x1) == 0) {
+                /* if status buffer was too small, don't loop past the end of the buffer */
+                entries = (bytes - 24) / 24;
+                if (entries < regctl)
+                        regctl = entries;
 
-       if (rsvd)
-               printf("  [7:3] : %#x\tReserved\n", rsvd);
+               json_object_add_value_array(root, "regctls", rcs);
+               for (i = 0; i < regctl; i++) {
+                       struct json_object *rc = json_create_object();
 
-       printf("  [2:2] : %#x\tPermanent Write Protect %sSupported\n",
-               wp_permanent, wp_permanent ? "" : "Not ");
-       printf("  [1:1] : %#x\tWrite Protect Until Power Supply %sSupported\n",
-               wp_power_cycle, wp_power_cycle ? "" : "Not ");
-       printf("  [0:0] : %#x\tNo Write Protect and Write Protect Namespace %sSupported\n",
-               no_wp_wp, no_wp_wp ? "" : "Not ");
-       printf("\n");
-}
+                       json_object_add_value_int(rc, "cntlid", le16_to_cpu(status->regctl_ds[i].cntlid));
+                       json_object_add_value_int(rc, "rcsts", status->regctl_ds[i].rcsts);
+                       json_object_add_value_uint(rc, "hostid", le64_to_cpu(status->regctl_ds[i].hostid));
+                       json_object_add_value_uint(rc, "rkey", le64_to_cpu(status->regctl_ds[i].rkey));
 
-static void show_nvme_id_ctrl_sgls(__le32 ctrl_sgls)
-{
-       __u32 sgls = le32_to_cpu(ctrl_sgls);
-       __u32 rsvd0 = (sgls & 0xFFC00000) >> 22;
-       __u32 trsdbd = (sgls & 0x200000) >> 21;
-       __u32 aofdsl = (sgls & 0x100000) >> 20;
-       __u32 mpcsd = (sgls & 0x80000) >> 19;
-       __u32 sglltb = (sgls & 0x40000) >> 18;
-       __u32 bacmdb = (sgls & 0x20000) >> 17;
-       __u32 bbs = (sgls & 0x10000) >> 16;
-       __u32 rsvd1 = (sgls & 0xFFF8) >> 3;
-       __u32 key = (sgls & 0x4) >> 2;
-       __u32 sglsp = sgls & 0x3;
+                       json_array_add_value_object(rcs, rc);
+               }
+       } else {
+               struct nvme_reservation_status_ext *ext_status = (struct nvme_reservation_status_ext *)status;
+               char    hostid[33];
 
-       if (rsvd0)
-               printf(" [31:22]: %#x\tReserved\n", rsvd0);
-       if (sglsp || (!sglsp && trsdbd))
-               printf(" [21:21]: %#x\tTransport SGL Data Block Descriptor %sSupported\n",
-                       trsdbd, trsdbd ? "" : "Not ");
-       if (sglsp || (!sglsp && aofdsl))
-               printf(" [20:20]: %#x\tAddress Offsets %sSupported\n",
-                       aofdsl, aofdsl ? "" : "Not ");
-       if (sglsp || (!sglsp && mpcsd))
-               printf(" [19:19]: %#x\tMetadata Pointer Containing "
-                       "SGL Descriptor is %sSupported\n",
-                       mpcsd, mpcsd ? "" : "Not ");
-       if (sglsp || (!sglsp && sglltb))
-               printf(" [18:18]: %#x\tSGL Length Larger than Buffer %sSupported\n",
-                       sglltb, sglltb ? "" : "Not ");
-       if (sglsp || (!sglsp && bacmdb))
-               printf(" [17:17]: %#x\tByte-Aligned Contig. MD Buffer %sSupported\n",
-                       bacmdb, bacmdb ? "" : "Not ");
-       if (sglsp || (!sglsp && bbs))
-               printf(" [16:16]: %#x\tSGL Bit-Bucket %sSupported\n",
-                       bbs, bbs ? "" : "Not ");
-       if (rsvd1)
-               printf(" [15:3] : %#x\tReserved\n", rsvd1);
-       if (sglsp || (!sglsp && key))
-               printf("  [2:2] : %#x\tKeyed SGL Data Block descriptor %sSupported\n",
-                       key, key ? "" : "Not ");
-       if (sglsp == 0x3)
-               printf("  [1:0] : %#x\tReserved\n", sglsp);
-       else if (sglsp == 0x2)
-               printf("  [1:0] : %#x\tScatter-Gather Lists Supported."
-                       " Dword alignment required.\n", sglsp);
-       else if (sglsp == 0x1)
-               printf("  [1:0] : %#x\tScatter-Gather Lists Supported."
-                       " No Dword alignment required.\n", sglsp);
-       else
-               printf(" [1:0]  : %#x\tScatter-Gather Lists Not Supported\n", sglsp);
-       printf("\n");
-}
+                /* if status buffer was too small, don't loop past the end of the buffer */
+                entries = (bytes - 64) / 64;
+                if (entries < regctl)
+                        regctl = entries;
 
-static void show_nvme_id_ctrl_ctrattr(__u8 ctrattr)
-{
-       __u8 rsvd = (ctrattr & 0xFE) >> 1;
-       __u8 scm = ctrattr & 0x1;
-       if (rsvd)
-               printf("  [7:1] : %#x\tReserved\n", rsvd);
-       printf("  [0:0] : %#x\t%s Controller Model\n",
-               scm, scm ? "Static" : "Dynamic");
-       printf("\n");
-}
+               json_object_add_value_array(root, "regctlext", rcs);
+               for (i = 0; i < regctl; i++) {
+                       struct json_object *rc = json_create_object();
 
-static void show_nvme_id_ns_nsfeat(__u8 nsfeat)
-{
-       __u8 rsvd = (nsfeat & 0xE0) >> 5;
-       __u8 ioopt = (nsfeat & 0x10) >> 4;
-       __u8 dulbe = (nsfeat & 0x4) >> 2;
-       __u8 na = (nsfeat & 0x2) >> 1;
-       __u8 thin = nsfeat & 0x1;
-       if (rsvd)
-               printf("  [7:5] : %#x\tReserved\n", rsvd);
-       printf("  [4:4] : %#x\tNPWG, NPWA, NPDG, NPDA, and NOWS are %sSupported\n",
-               ioopt, ioopt ? "" : "Not ");
-       printf("  [2:2] : %#x\tDeallocated or Unwritten Logical Block error %sSupported\n",
-               dulbe, dulbe ? "" : "Not ");
-       printf("  [1:1] : %#x\tNamespace uses %s\n",
-               na, na ? "NAWUN, NAWUPF, and NACWU" : "AWUN, AWUPF, and ACWU");
-       printf("  [0:0] : %#x\tThin Provisioning %sSupported\n",
-               thin, thin ? "" : "Not ");
-       printf("\n");
-}
+                       json_object_add_value_int(rc, "cntlid", le16_to_cpu(ext_status->regctl_eds[i].cntlid));
+                       json_object_add_value_int(rc, "rcsts", ext_status->regctl_eds[i].rcsts);
+                       json_object_add_value_uint(rc, "rkey", le64_to_cpu(ext_status->regctl_eds[i].rkey));
+                       for (j = 0; j < 16; j++)
+                               sprintf(hostid + j * 2, "%02x", ext_status->regctl_eds[i].hostid[j]);
 
-static void show_nvme_id_ns_flbas(__u8 flbas)
-{
-       __u8 rsvd = (flbas & 0xE0) >> 5;
-       __u8 mdedata = (flbas & 0x10) >> 4;
-       __u8 lbaf = flbas & 0xF;
-       if (rsvd)
-               printf("  [7:5] : %#x\tReserved\n", rsvd);
-       printf("  [4:4] : %#x\tMetadata Transferred %s\n",
-               mdedata, mdedata ? "at End of Data LBA" : "in Separate Contiguous Buffer");
-       printf("  [3:0] : %#x\tCurrent LBA Format Selected\n", lbaf);
-       printf("\n");
-}
+                       json_object_add_value_string(rc, "hostid", hostid);
 
-static void show_nvme_id_ns_mc(__u8 mc)
-{
-       __u8 rsvd = (mc & 0xFC) >> 2;
-       __u8 mdp = (mc & 0x2) >> 1;
-       __u8 extdlba = mc & 0x1;
-       if (rsvd)
-               printf("  [7:2] : %#x\tReserved\n", rsvd);
-       printf("  [1:1] : %#x\tMetadata Pointer %sSupported\n",
-               mdp, mdp ? "" : "Not ");
-       printf("  [0:0] : %#x\tMetadata as Part of Extended Data LBA %sSupported\n",
-               extdlba, extdlba ? "" : "Not ");
-       printf("\n");
-}
+                       json_array_add_value_object(rcs, rc);
+               }
+       }
 
-static void show_nvme_id_ns_dpc(__u8 dpc)
-{
-       __u8 rsvd = (dpc & 0xE0) >> 5;
-       __u8 pil8 = (dpc & 0x10) >> 4;
-       __u8 pif8 = (dpc & 0x8) >> 3;
-       __u8 pit3 = (dpc & 0x4) >> 2;
-       __u8 pit2 = (dpc & 0x2) >> 1;
-       __u8 pit1 = dpc & 0x1;
-       if (rsvd)
-               printf("  [7:5] : %#x\tReserved\n", rsvd);
-       printf("  [4:4] : %#x\tProtection Information Transferred as Last 8 Bytes of Metadata %sSupported\n",
-               pil8, pil8 ? "" : "Not ");
-       printf("  [3:3] : %#x\tProtection Information Transferred as First 8 Bytes of Metadata %sSupported\n",
-               pif8, pif8 ? "" : "Not ");
-       printf("  [2:2] : %#x\tProtection Information Type 3 %sSupported\n",
-               pit3, pit3 ? "" : "Not ");
-       printf("  [1:1] : %#x\tProtection Information Type 2 %sSupported\n",
-               pit2, pit2 ? "" : "Not ");
-       printf("  [0:0] : %#x\tProtection Information Type 1 %sSupported\n",
-               pit1, pit1 ? "" : "Not ");
+       json_print_object(root, NULL);
        printf("\n");
+       json_free_object(root);
 }
 
-static void show_nvme_id_ns_dps(__u8 dps)
+static void json_fw_log(struct nvme_firmware_log_page *fw_log, const char *devname)
 {
-       __u8 rsvd = (dps & 0xF0) >> 4;
-       __u8 pif8 = (dps & 0x8) >> 3;
-       __u8 pit = dps & 0x7;
-       if (rsvd)
-               printf("  [7:4] : %#x\tReserved\n", rsvd);
-       printf("  [3:3] : %#x\tProtection Information is Transferred as %s 8 Bytes of Metadata\n",
-               pif8, pif8 ? "First" : "Last");
-       printf("  [2:0] : %#x\tProtection Information %s\n", pit,
-               pit == 3 ? "Type 3 Enabled" :
-               pit == 2 ? "Type 2 Enabled" :
-               pit == 1 ? "Type 1 Enabled" :
-               pit == 0 ? "Disabled" : "Reserved Enabled");
-       printf("\n");
-}
+       struct json_object *root;
+       struct json_object *fwsi;
+       char fmt[21];
+       char str[32];
+       int i;
+
+       root = json_create_object();
+       fwsi = json_create_object();
+
+       json_object_add_value_int(fwsi, "Active Firmware Slot (afi)", fw_log->afi);
+
+       for (i = 0; i < 7; i++) {
+               if (fw_log->frs[i]) {
+                       snprintf(fmt, sizeof(fmt), "Firmware Rev Slot %d", i+1);
+                       snprintf(str, sizeof(str), "%"PRIu64" (%s)", (uint64_t)fw_log->frs[i],
+                       fw_to_string(fw_log->frs[i]));
+                       json_object_add_value_string(fwsi, fmt, str);
+               }
+       }
+       json_object_add_value_object(root, devname, fwsi);
 
-static void show_nvme_id_ns_nmic(__u8 nmic)
-{
-       __u8 rsvd = (nmic & 0xFE) >> 1;
-       __u8 mp = nmic & 0x1;
-       if (rsvd)
-               printf("  [7:1] : %#x\tReserved\n", rsvd);
-       printf("  [0:0] : %#x\tNamespace Multipath %sCapable\n",
-               mp, mp ? "" : "Not ");
+       json_print_object(root, NULL);
        printf("\n");
+       json_free_object(root);
 }
 
-static void show_nvme_id_ns_rescap(__u8 rescap)
+static void json_changed_ns_list_log(struct nvme_changed_ns_list_log *log,
+                                    const char *devname)
 {
-       __u8 rsvd = (rescap & 0x80) >> 7;
-       __u8 eaar = (rescap & 0x40) >> 6;
-       __u8 wear = (rescap & 0x20) >> 5;
-       __u8 earo = (rescap & 0x10) >> 4;
-       __u8 wero = (rescap & 0x8) >> 3;
-       __u8 ea = (rescap & 0x4) >> 2;
-       __u8 we = (rescap & 0x2) >> 1;
-       __u8 ptpl = rescap & 0x1;
-       if (rsvd)
-               printf("  [7:7] : %#x\tReserved\n", rsvd);
-       printf("  [6:6] : %#x\tExclusive Access - All Registrants %sSupported\n",
-               eaar, eaar ? "" : "Not ");
-       printf("  [5:5] : %#x\tWrite Exclusive - All Registrants %sSupported\n",
-               wear, wear ? "" : "Not ");
-       printf("  [4:4] : %#x\tExclusive Access - Registrants Only %sSupported\n",
-               earo, earo ? "" : "Not ");
-       printf("  [3:3] : %#x\tWrite Exclusive - Registrants Only %sSupported\n",
-               wero, wero ? "" : "Not ");
-       printf("  [2:2] : %#x\tExclusive Access %sSupported\n",
-               ea, ea ? "" : "Not ");
-       printf("  [1:1] : %#x\tWrite Exclusive %sSupported\n",
-               we, we ? "" : "Not ");
-       printf("  [0:0] : %#x\tPersist Through Power Loss %sSupported\n",
-               ptpl, ptpl ? "" : "Not ");
+       struct json_object *root;
+       struct json_object *nsi;
+       char fmt[32];
+       char str[32];
+       __u32 nsid;
+       int i;
+
+       if (log->log[0] == cpu_to_le32(0xffffffff))
+               return;
+
+       root = json_create_object();
+       nsi = json_create_object();
+
+       json_object_add_value_string(root, "Changed Namespace List Log", devname);
+
+       for (i = 0; i < NVME_MAX_CHANGED_NAMESPACES; i++) {
+               nsid = le32_to_cpu(log->log[i]);
+
+               if (nsid == 0)
+                       break;
+
+               snprintf(fmt, sizeof(fmt), "[%4u]", i + 1);
+               snprintf(str, sizeof(str), "%#x", nsid);
+               json_object_add_value_string(nsi, fmt, str);
+       }
+
+       json_object_add_value_object(root, devname, nsi);
+       json_print_object(root, NULL);
        printf("\n");
+
+       json_free_object(root);
 }
 
-static void show_nvme_id_ns_fpi(__u8 fpi)
+static void json_endurance_log(struct nvme_endurance_group_log *endurance_group,
+                       __u16 group_id)
 {
-       __u8 fpis = (fpi & 0x80) >> 7;
-       __u8 fpii = fpi & 0x7F;
-       printf("  [7:7] : %#x\tFormat Progress Indicator %sSupported\n",
-               fpis, fpis ? "" : "Not ");
-       if (fpis || (!fpis && fpii))
-               printf("  [6:0] : %#x\tFormat Progress Indicator (Remaining %d%%)\n",
-               fpii, fpii);
+       struct json_object *root;
+
+       long double endurance_estimate= int128_to_double(endurance_group->endurance_estimate);
+       long double data_units_read= int128_to_double(endurance_group->data_units_read);
+       long double data_units_written= int128_to_double(endurance_group->data_units_written);
+       long double media_units_written= int128_to_double(endurance_group->media_units_written);
+       long double host_read_cmds = int128_to_double(endurance_group->host_read_cmds);
+       long double host_write_cmds = int128_to_double(endurance_group->host_write_cmds);
+       long double media_data_integrity_err = int128_to_double(endurance_group->media_data_integrity_err);
+       long double num_err_info_log_entries = int128_to_double(endurance_group->num_err_info_log_entries);
+
+       root = json_create_object();
+
+       json_object_add_value_int(root, "critical_warning", endurance_group->critical_warning);
+       json_object_add_value_int(root, "avl_spare", endurance_group->avl_spare);
+       json_object_add_value_int(root, "avl_spare_threshold", endurance_group->avl_spare_threshold);
+       json_object_add_value_int(root, "percent_used", endurance_group->percent_used);
+       json_object_add_value_float(root, "endurance_estimate", endurance_estimate);
+       json_object_add_value_float(root, "data_units_read", data_units_read);
+       json_object_add_value_float(root, "data_units_written", data_units_written);
+       json_object_add_value_float(root, "mediate_write_commands", media_units_written);
+       json_object_add_value_float(root, "host_read_cmds", host_read_cmds);
+       json_object_add_value_float(root, "host_write_cmds", host_write_cmds);
+       json_object_add_value_float(root, "media_data_integrity_err", media_data_integrity_err);
+       json_object_add_value_float(root, "num_err_info_log_entries", num_err_info_log_entries);
+
+       json_print_object(root, NULL);
        printf("\n");
+       json_free_object(root);
 }
 
-static void show_nvme_id_ns_dlfeat(__u8 dlfeat)
+static void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid)
 {
-       __u8 rsvd = (dlfeat & 0xE0) >> 5;
-       __u8 guard = (dlfeat & 0x10) >> 4;
-       __u8 dwz = (dlfeat & 0x8) >> 3;
-       __u8 val = dlfeat & 0x7;
-       if (rsvd)
-               printf("  [7:5] : %#x\tReserved\n", rsvd);
-       printf("  [4:4] : %#x\tGuard Field of Deallocated Logical Blocks is set to %s\n",
-               guard, guard ? "CRC of The Value Read" : "0xFFFF");
-       printf("  [3:3] : %#x\tDeallocate Bit in the Write Zeroes Command is %sSupported\n",
-               dwz, dwz ? "" : "Not ");
-       printf("  [2:0] : %#x\tBytes Read From a Deallocated Logical Block and its Metadata are %s\n", val,
-               val == 2 ? "0xFF" :
-               val == 1 ? "0x00" :
-               val == 0 ? "Not Reported" : "Reserved Value");
+       struct json_object *root;
+       int c;
+       char key[21];
+
+       unsigned int temperature = ((smart->temperature[1] << 8) |
+               smart->temperature[0]);
+
+       long double data_units_read = int128_to_double(smart->data_units_read);
+       long double data_units_written = int128_to_double(smart->data_units_written);
+       long double host_read_commands = int128_to_double(smart->host_reads);
+       long double host_write_commands = int128_to_double(smart->host_writes);
+       long double controller_busy_time = int128_to_double(smart->ctrl_busy_time);
+       long double power_cycles = int128_to_double(smart->power_cycles);
+       long double power_on_hours = int128_to_double(smart->power_on_hours);
+       long double unsafe_shutdowns = int128_to_double(smart->unsafe_shutdowns);
+       long double media_errors = int128_to_double(smart->media_errors);
+       long double num_err_log_entries = int128_to_double(smart->num_err_log_entries);
+
+       root = json_create_object();
+
+       json_object_add_value_int(root, "critical_warning", smart->critical_warning);
+       json_object_add_value_int(root, "temperature", temperature);
+       json_object_add_value_int(root, "avail_spare", smart->avail_spare);
+       json_object_add_value_int(root, "spare_thresh", smart->spare_thresh);
+       json_object_add_value_int(root, "percent_used", smart->percent_used);
+       json_object_add_value_int(root, "endurance_grp_critical_warning_summary",
+                       smart->endu_grp_crit_warn_sumry);
+       json_object_add_value_float(root, "data_units_read", data_units_read);
+       json_object_add_value_float(root, "data_units_written", data_units_written);
+       json_object_add_value_float(root, "host_read_commands", host_read_commands);
+       json_object_add_value_float(root, "host_write_commands", host_write_commands);
+       json_object_add_value_float(root, "controller_busy_time", controller_busy_time);
+       json_object_add_value_float(root, "power_cycles", power_cycles);
+       json_object_add_value_float(root, "power_on_hours", power_on_hours);
+       json_object_add_value_float(root, "unsafe_shutdowns", unsafe_shutdowns);
+       json_object_add_value_float(root, "media_errors", media_errors);
+       json_object_add_value_float(root, "num_err_log_entries", num_err_log_entries);
+       json_object_add_value_uint(root, "warning_temp_time",
+                       le32_to_cpu(smart->warning_temp_time));
+       json_object_add_value_uint(root, "critical_comp_time",
+                       le32_to_cpu(smart->critical_comp_time));
+
+       for (c=0; c < 8; c++) {
+               __s32 temp = le16_to_cpu(smart->temp_sensor[c]);
+
+               if (temp == 0)
+                       continue;
+               sprintf(key, "temperature_sensor_%d",c+1);
+               json_object_add_value_int(root, key, temp);
+       }
+
+       json_object_add_value_uint(root, "thm_temp1_trans_count",
+                       le32_to_cpu(smart->thm_temp1_trans_count));
+       json_object_add_value_uint(root, "thm_temp2_trans_count",
+                       le32_to_cpu(smart->thm_temp2_trans_count));
+       json_object_add_value_uint(root, "thm_temp1_total_time",
+                       le32_to_cpu(smart->thm_temp1_total_time));
+       json_object_add_value_uint(root, "thm_temp2_total_time",
+                       le32_to_cpu(smart->thm_temp2_total_time));
+
+       json_print_object(root, NULL);
        printf("\n");
+       json_free_object(root);
 }
 
-void show_nvme_id_ns(struct nvme_id_ns *ns, unsigned int mode)
+static void json_ana_log(struct nvme_ana_rsp_hdr *ana_log, const char *devname)
 {
+       int offset = sizeof(struct nvme_ana_rsp_hdr);
+       struct nvme_ana_rsp_hdr *hdr = ana_log;
+       struct nvme_ana_group_desc *ana_desc;
+       struct json_array *desc_list;
+       struct json_array *ns_list;
+       struct json_object *desc;
+       struct json_object *nsid;
+       struct json_object *root;
+       size_t nsid_buf_size;
+       void *base = ana_log;
+       __u32 nr_nsids;
        int i;
-       int human = mode & HUMAN,
-               vs = mode & VS;
+       int j;
 
-       printf("nsze    : %#"PRIx64"\n", le64_to_cpu(ns->nsze));
-       printf("ncap    : %#"PRIx64"\n", le64_to_cpu(ns->ncap));
-       printf("nuse    : %#"PRIx64"\n", le64_to_cpu(ns->nuse));
-       printf("nsfeat  : %#x\n", ns->nsfeat);
-       if (human)
-               show_nvme_id_ns_nsfeat(ns->nsfeat);
-       printf("nlbaf   : %d\n", ns->nlbaf);
-       printf("flbas   : %#x\n", ns->flbas);
-       if (human)
-               show_nvme_id_ns_flbas(ns->flbas);
-       printf("mc      : %#x\n", ns->mc);
-       if (human)
-               show_nvme_id_ns_mc(ns->mc);
-       printf("dpc     : %#x\n", ns->dpc);
-       if (human)
-               show_nvme_id_ns_dpc(ns->dpc);
-       printf("dps     : %#x\n", ns->dps);
-       if (human)
-               show_nvme_id_ns_dps(ns->dps);
-       printf("nmic    : %#x\n", ns->nmic);
-       if (human)
-               show_nvme_id_ns_nmic(ns->nmic);
-       printf("rescap  : %#x\n", ns->rescap);
-       if (human)
-               show_nvme_id_ns_rescap(ns->rescap);
-       printf("fpi     : %#x\n", ns->fpi);
-       if (human)
-               show_nvme_id_ns_fpi(ns->fpi);
-       printf("dlfeat  : %d\n", ns->dlfeat);
-       if (human)
-               show_nvme_id_ns_dlfeat(ns->dlfeat);
-       printf("nawun   : %d\n", le16_to_cpu(ns->nawun));
-       printf("nawupf  : %d\n", le16_to_cpu(ns->nawupf));
-       printf("nacwu   : %d\n", le16_to_cpu(ns->nacwu));
-       printf("nabsn   : %d\n", le16_to_cpu(ns->nabsn));
-       printf("nabo    : %d\n", le16_to_cpu(ns->nabo));
-       printf("nabspf  : %d\n", le16_to_cpu(ns->nabspf));
-       printf("noiob   : %d\n", le16_to_cpu(ns->noiob));
-       printf("nvmcap  : %.0Lf\n", int128_to_double(ns->nvmcap));
-       if (ns->nsfeat & 0x10) {
-               printf("npwg    : %u\n", le16_to_cpu(ns->npwg));
-               printf("npwa    : %u\n", le16_to_cpu(ns->npwa));
-               printf("npdg    : %u\n", le16_to_cpu(ns->npdg));
-               printf("npda    : %u\n", le16_to_cpu(ns->npda));
-               printf("nows    : %u\n", le16_to_cpu(ns->nows));
+       root = json_create_object();
+       json_object_add_value_string(root,
+                       "Asynchronous Namespace Access Log for NVMe device",
+                       devname);
+       json_object_add_value_uint(root, "chgcnt",
+                       le64_to_cpu(hdr->chgcnt));
+       json_object_add_value_uint(root, "ngrps", le16_to_cpu(hdr->ngrps));
+
+       desc_list = json_create_array();
+       for (i = 0; i < le16_to_cpu(ana_log->ngrps); i++) {
+               desc = json_create_object();
+               ana_desc = base + offset;
+               nr_nsids = le32_to_cpu(ana_desc->nnsids);
+               nsid_buf_size = nr_nsids * sizeof(__le32);
+
+               offset += sizeof(*ana_desc);
+               json_object_add_value_uint(desc, "grpid",
+                               le32_to_cpu(ana_desc->grpid));
+               json_object_add_value_uint(desc, "nnsids",
+                               le32_to_cpu(ana_desc->nnsids));
+               json_object_add_value_uint(desc, "chgcnt",
+                               le64_to_cpu(ana_desc->chgcnt));
+               json_object_add_value_string(desc, "state",
+                               nvme_ana_state_to_string(ana_desc->state));
+
+               ns_list = json_create_array();
+               for (j = 0; j < le32_to_cpu(ana_desc->nnsids); j++) {
+                       nsid = json_create_object();
+                       json_object_add_value_uint(nsid, "nsid",
+                                       le32_to_cpu(ana_desc->nsids[j]));
+                       json_array_add_value_object(ns_list, nsid);
+               }
+               json_object_add_value_array(desc, "NSIDS", ns_list);
+               offset += nsid_buf_size;
+               json_array_add_value_object(desc_list, desc);
        }
-       printf("nsattr  : %u\n", ns->nsattr);
-       printf("nvmsetid: %d\n", le16_to_cpu(ns->nvmsetid));
-       printf("anagrpid: %u\n", le32_to_cpu(ns->anagrpid));
-       printf("endgid  : %d\n", le16_to_cpu(ns->endgid));
-
-       printf("nguid   : ");
-       for (i = 0; i < 16; i++)
-               printf("%02x", ns->nguid[i]);
-       printf("\n");
 
-       printf("eui64   : ");
-       for (i = 0; i < 8; i++)
-               printf("%02x", ns->eui64[i]);
+       json_object_add_value_array(root, "ANA DESC LIST ", desc_list);
+       json_print_object(root, NULL);
        printf("\n");
-
-       for (i = 0; i <= ns->nlbaf; i++) {
-               if (human)
-                       printf("LBA Format %2d : Metadata Size: %-3d bytes - "
-                               "Data Size: %-2d bytes - Relative Performance: %#x %s %s\n", i,
-                               le16_to_cpu(ns->lbaf[i].ms), 1 << ns->lbaf[i].ds, ns->lbaf[i].rp,
-                               ns->lbaf[i].rp == 3 ? "Degraded" :
-                               ns->lbaf[i].rp == 2 ? "Good" :
-                               ns->lbaf[i].rp == 1 ? "Better" : "Best",
-                               i == (ns->flbas & 0xf) ? "(in use)" : "");
-               else
-                       printf("lbaf %2d : ms:%-3d lbads:%-2d rp:%#x %s\n", i,
-                               le16_to_cpu(ns->lbaf[i].ms), ns->lbaf[i].ds, ns->lbaf[i].rp,
-                               i == (ns->flbas & 0xf) ? "(in use)" : "");
-       }
-       if (vs) {
-               printf("vs[]:\n");
-               d(ns->vs, sizeof(ns->vs), 16, 1);
-       }
+       json_free_object(root);
 }
 
-
-void json_nvme_id_ns_descs(void *data)
+static void json_self_test_log(struct nvme_self_test_log *self_test)
 {
-       /* large enough to hold uuid str (37) or nguid str (32) + zero byte */
-       char json_str[40];
-       char *json_str_p;
-
-       union {
-               __u8 eui64[NVME_NIDT_EUI64_LEN];
-               __u8 nguid[NVME_NIDT_NGUID_LEN];
-
-#ifdef LIBUUID
-               uuid_t uuid;
-#endif
-       } desc;
-
        struct json_object *root;
-       struct json_array *json_array = NULL;
-
-       off_t off;
-       int pos, len = 0;
+       struct json_array *valid;
+       struct json_object *valid_attrs;
        int i;
 
-       for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
-               struct nvme_ns_id_desc *cur = data + pos;
-               const char *nidt_name = NULL;
+       root = json_create_object();
+       json_object_add_value_int(root, "Current Device Self-Test Operation", self_test->crnt_dev_selftest_oprn);
+       json_object_add_value_int(root, "Current Device Self-Test Completion", self_test->crnt_dev_selftest_compln);
+       valid = json_create_array();
 
-               if (cur->nidl == 0)
-                       break;
+       for (i=0; i < NVME_SELF_TEST_REPORTS; i++) {
+               if ((self_test->result[i].device_self_test_status & 0xf) == 0xf)
+                       continue;
+               valid_attrs = json_create_object();
+               json_object_add_value_int(valid_attrs, "Self test result",
+                       self_test->result[i].device_self_test_status & 0xf);
+               json_object_add_value_int(valid_attrs, "Self test code",
+                       self_test->result[i].device_self_test_status >> 4);
+               json_object_add_value_int(valid_attrs, "Segment number",
+                       self_test->result[i].segment_num);
+               json_object_add_value_int(valid_attrs, "Valid Diagnostic Information",
+                       self_test->result[i].valid_diagnostic_info);
+               json_object_add_value_uint(valid_attrs, "Power on hours (POH)",
+                       le64_to_cpu(self_test->result[i].power_on_hours));
+               if (self_test->result[i].valid_diagnostic_info & NVME_SELF_TEST_VALID_NSID)
+                       json_object_add_value_int(valid_attrs, "Namespace Identifier (NSID)",
+                               le32_to_cpu(self_test->result[i].nsid));
+               if (self_test->result[i].valid_diagnostic_info & NVME_SELF_TEST_VALID_FLBA)
+                       json_object_add_value_uint(valid_attrs, "Failing LBA",
+                               le64_to_cpu(self_test->result[i].failing_lba));
+               if (self_test->result[i].valid_diagnostic_info & NVME_SELF_TEST_VALID_SCT)
+                       json_object_add_value_int(valid_attrs, "Status Code Type",
+                               self_test->result[i].status_code_type);
+               if(self_test->result[i].valid_diagnostic_info & NVME_SELF_TEST_VALID_SC)
+                       json_object_add_value_int(valid_attrs, "Status Code",
+                               self_test->result[i].status_code);
+               json_object_add_value_int(valid_attrs, "Vendor Specific",
+                       (self_test->result[i].vendor_specific[1] << 8) |
+                       (self_test->result[i].vendor_specific[0]));
+               json_array_add_value_object(valid, valid_attrs);
+       }
+       json_object_add_value_array(root, "List of Valid Reports", valid);
+       json_print_object(root, NULL);
+       printf("\n");
+       json_free_object(root);
+}
 
-               memset(json_str, 0, sizeof(json_str));
-               json_str_p = json_str;
-               off = pos + sizeof(*cur);
+static void json_effects_log(struct nvme_effects_log_page *effects_log)
+{
+       struct json_object *root;
+       unsigned int opcode;
+       char key[128];
+       __u32 effect;
 
-               switch (cur->nidt) {
-               case NVME_NIDT_EUI64:
-                       memcpy(desc.eui64, data + off, sizeof(desc.eui64));
-                       for (i = 0; i < sizeof(desc.eui64); i++)
-                               json_str_p += sprintf(json_str_p, "%02x", desc.eui64[i]);
-                       len += sizeof(desc.eui64);
-                       nidt_name = "eui64";
-                       break;
+       root = json_create_object();
 
-               case NVME_NIDT_NGUID:
-                       memcpy(desc.nguid, data + off, sizeof(desc.nguid));
-                       for (i = 0; i < sizeof(desc.nguid); i++)
-                               json_str_p += sprintf(json_str_p, "%02x", desc.nguid[i]);
-                       len += sizeof(desc.nguid);
-                       nidt_name = "nguid";
-                       break;
+       for (opcode = 0; opcode < 256; opcode++) {
+               sprintf(key, "ACS%d (%s)", opcode, nvme_cmd_to_string(1, opcode));
+               effect = le32_to_cpu(effects_log->acs[opcode]);
+               json_object_add_value_uint(root, key, effect);
+       }
 
-#ifdef LIBUUID
-               case NVME_NIDT_UUID:
-                       memcpy(desc.uuid, data + off, sizeof(desc.uuid));
-                       uuid_unparse_lower(desc.uuid, json_str);
-                       len += sizeof(desc.uuid);
-                       nidt_name = "uuid";
-                       break;
-#endif
-               default:
-                       /* Skip unnkown types */
-                       len = cur->nidl;
-                       break;
-               }
+       for (opcode = 0; opcode < 256; opcode++) {
+               sprintf(key, "IOCS%d (%s)", opcode, nvme_cmd_to_string(0, opcode));
+               effect = le32_to_cpu(effects_log->iocs[opcode]);
+               json_object_add_value_uint(root, key, effect);
+       }
 
-               if (nidt_name) {
-                       struct json_object *elem = json_create_object();
+       json_print_object(root, NULL);
+       printf("\n");
+       json_free_object(root);
+}
 
-                       json_object_add_value_int(elem, "loc", pos);
-                       json_object_add_value_int(elem, "nidt", (int)cur->nidt);
-                       json_object_add_value_int(elem, "nidl", (int)cur->nidl);
-                       json_object_add_value_string(elem, "type", nidt_name);
-                       json_object_add_value_string(elem, nidt_name, json_str);
+static void json_sanitize_log(struct nvme_sanitize_log_page *sanitize_log,
+                             const char *devname)
+{
+       struct json_object *root;
+       struct json_object *dev;
+       struct json_object *sstat;
+       const char *status_str;
+       char str[128];
+       __u16 status = le16_to_cpu(sanitize_log->status);
 
-                       if (!json_array) {
-                               json_array = json_create_array();
-                       }
-                       json_array_add_value_object(json_array, elem);
-               }
+       root = json_create_object();
+       dev = json_create_object();
+       sstat = json_create_object();
 
-               len += sizeof(*cur);
-       }
+       json_object_add_value_int(dev, "sprog", le16_to_cpu(sanitize_log->progress));
+       json_object_add_value_int(sstat, "global_erased",
+                       (status & NVME_SANITIZE_LOG_GLOBAL_DATA_ERASED) >> 8);
+       json_object_add_value_int(sstat, "no_cmplted_passes",
+                       (status & NVME_SANITIZE_LOG_NUM_CMPLTED_PASS_MASK) >> 3);
 
-       root = json_create_object();
+       status_str = get_sanitize_log_sstat_status_str(status);
+       sprintf(str, "(%d) %s", status & NVME_SANITIZE_LOG_STATUS_MASK, status_str);
+       json_object_add_value_string(sstat, "status", str);
 
-       if (json_array)
-               json_object_add_value_array(root, "ns-descs", json_array);
+       json_object_add_value_object(dev, "sstat", sstat);
+       json_object_add_value_uint(dev, "cdw10_info", le32_to_cpu(sanitize_log->cdw10_info));
+       json_object_add_value_uint(dev, "time_over_write", le32_to_cpu(sanitize_log->est_ovrwrt_time));
+       json_object_add_value_uint(dev, "time_block_erase", le32_to_cpu(sanitize_log->est_blk_erase_time));
+       json_object_add_value_uint(dev, "time_crypto_erase", le32_to_cpu(sanitize_log->est_crypto_erase_time));
 
+       json_object_add_value_uint(dev, "time_over_write_no_dealloc", le32_to_cpu(sanitize_log->est_ovrwrt_time_with_no_deallocate));
+       json_object_add_value_uint(dev, "time_block_erase_no_dealloc", le32_to_cpu(sanitize_log->est_blk_erase_time_with_no_deallocate));
+       json_object_add_value_uint(dev, "time_crypto_erase_no_dealloc", le32_to_cpu(sanitize_log->est_crypto_erase_time_with_no_deallocate));
+
+       json_object_add_value_object(root, devname, dev);
        json_print_object(root, NULL);
        printf("\n");
-
        json_free_object(root);
 }
 
-void show_nvme_id_ns_descs(void *data)
+static void nvme_show_subsystem(struct subsys_list_item *item)
 {
-       int pos, len = 0;
        int i;
-#ifdef LIBUUID
-       uuid_t uuid;
-       char uuid_str[37];
-#endif
-       __u8 eui64[8];
-       __u8 nguid[16];
-
-       for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
-               struct nvme_ns_id_desc *cur = data + pos;
 
-               if (cur->nidl == 0)
-                       break;
-
-               switch (cur->nidt) {
-               case NVME_NIDT_EUI64:
-                       memcpy(eui64, data + pos + sizeof(*cur), sizeof(eui64));
-                       printf("eui64   : ");
-                       for (i = 0; i < 8; i++)
-                               printf("%02x", eui64[i]);
-                       printf("\n");
-                       len += sizeof(eui64);
-                       break;
-               case NVME_NIDT_NGUID:
-                       memcpy(nguid, data + pos + sizeof(*cur), sizeof(nguid));
-                       printf("nguid   : ");
-                       for (i = 0; i < 16; i++)
-                               printf("%02x", nguid[i]);
-                       printf("\n");
-                       len += sizeof(nguid);
-                       break;
-#ifdef LIBUUID
-               case NVME_NIDT_UUID:
-                       memcpy(uuid, data + pos + sizeof(*cur), 16);
-                       uuid_unparse_lower(uuid, uuid_str);
-                       printf("uuid    : %s\n", uuid_str);
-                       len += sizeof(uuid);
-                       break;
-#endif
-               default:
-                       /* Skip unnkown types */
-                       len = cur->nidl;
-                       break;
-               }
+       printf("%s - NQN=%s\n", item->name, item->subsysnqn);
+       printf("\\\n");
 
-               len += sizeof(*cur);
+       for (i = 0; i < item->nctrls; i++) {
+               printf(" +- %s %s %s %s %s\n", item->ctrls[i].name,
+                               item->ctrls[i].transport,
+                               item->ctrls[i].address,
+                               item->ctrls[i].state,
+                               item->ctrls[i].ana_state ?
+                                       item->ctrls[i].ana_state : "");
        }
 }
 
-static void print_ps_power_and_scale(__le16 ctr_power, __u8 scale)
+static void json_print_nvme_subsystem_list(struct subsys_list_item *slist, int n)
 {
-       __u16 power = le16_to_cpu(ctr_power);
+       struct json_object *root;
+       struct json_array *subsystems;
+       struct json_object *subsystem_attrs;
+       struct json_array *paths;
+       struct json_object *path_attrs;
+       int i, j;
 
-       switch (scale & 0x3) {
-       case 0:
-               /* Not reported for this power state */
-               printf("-");
-               break;
+       root = json_create_object();
+       subsystems = json_create_array();
+
+       for (i = 0; i < n; i++) {
+               subsystem_attrs = json_create_object();
+
+               json_object_add_value_string(subsystem_attrs,
+                                            "Name", slist[i].name);
+               json_object_add_value_string(subsystem_attrs,
+                                            "NQN", slist[i].subsysnqn);
 
-       case 1:
-               /* Units of 0.0001W */
-               printf("%01u.%04uW", power / 10000, power % 10000);
-               break;
+               json_array_add_value_object(subsystems, subsystem_attrs);
 
-       case 2:
-               /* Units of 0.01W */
-               printf("%01u.%02uW", power / 100, scale % 100);
-               break;
+               paths = json_create_array();
+
+               for (j = 0; j < slist[i].nctrls; j++) {
+                       path_attrs = json_create_object();
+                       json_object_add_value_string(path_attrs, "Name",
+                                       slist[i].ctrls[j].name);
+                       json_object_add_value_string(path_attrs, "Transport",
+                                       slist[i].ctrls[j].transport);
+                       json_object_add_value_string(path_attrs, "Address",
+                                       slist[i].ctrls[j].address);
+                       json_object_add_value_string(path_attrs, "State",
+                                       slist[i].ctrls[j].state);
+                       if (slist[i].ctrls[j].ana_state)
+                               json_object_add_value_string(path_attrs,
+                                               "ANAState",
+                                               slist[i].ctrls[j].ana_state);
+                       json_array_add_value_object(paths, path_attrs);
+               }
+               if (j) {
+                       json_object_add_value_array(subsystem_attrs, "Paths", paths);
+               }
 
-       default:
-               printf("reserved");
        }
+
+       if (i)
+               json_object_add_value_array(root, "Subsystems", subsystems);
+       json_print_object(root, NULL);
+       printf("\n");
+       json_free_object(root);
 }
 
-static void show_nvme_id_ctrl_power(struct nvme_id_ctrl *ctrl)
+void nvme_show_subsystem_list(struct subsys_list_item *slist, int n,
+                            enum nvme_print_flags flags)
 {
        int i;
 
+       if (flags & JSON)
+               return json_print_nvme_subsystem_list(slist, n);
 
-       for (i = 0; i <= ctrl->npss; i++) {
-               __u16 max_power = le16_to_cpu(ctrl->psd[i].max_power);
-
-               printf("ps %4d : mp:", i);
-
-               if (ctrl->psd[i].flags & NVME_PS_FLAGS_MAX_POWER_SCALE)
-                       printf("%01u.%04uW ", max_power / 10000, max_power % 10000);
-               else
-                       printf("%01u.%02uW ", max_power / 100, max_power % 100);
+       for (i = 0; i < n; i++)
+               nvme_show_subsystem(&slist[i]);
+}
 
-               if (ctrl->psd[i].flags & NVME_PS_FLAGS_NON_OP_STATE)
-                       printf("non-");
+static void nvme_show_registers_cap(struct nvme_bar_cap *cap)
+{
+       printf("\tController Memory Buffer Supported (CMBS): The Controller Memory Buffer is %s\n",
+                       ((cap->rsvd_cmbs_pmrs & 0x02) >> 1) ? "Supported" : "Not Supported");
+       printf("\tPersistent Memory Region Supported (PMRS): The Persistent Memory Region is %s\n",
+                       (cap->rsvd_cmbs_pmrs & 0x01) ? "supported":"not supported");
+       printf("\tMemory Page Size Maximum         (MPSMAX): %u bytes\n", 1 <<  (12 + ((cap->mpsmax_mpsmin & 0xf0) >> 4)));
+       printf("\tMemory Page Size Minimum         (MPSMIN): %u bytes\n", 1 <<  (12 + (cap->mpsmax_mpsmin & 0x0f)));
+       printf("\tBoot Partition Support              (BPS): %s\n", (cap->bps_css_nssrs_dstrd & 0x2000) ? "Yes":"No");
+       printf("\tCommand Sets Supported              (CSS): NVM command set is %s\n",
+                       (cap->bps_css_nssrs_dstrd & 0x0020) ? "supported":"not supported");
+       printf("\tNVM Subsystem Reset Supported     (NSSRS): %s\n", (cap->bps_css_nssrs_dstrd & 0x0010) ? "Yes":"No");
+       printf("\tDoorbell Stride                   (DSTRD): %u bytes\n", 1 << (2 + (cap->bps_css_nssrs_dstrd & 0x000f)));
+       printf("\tTimeout                              (TO): %u ms\n", cap->to * 500);
+       printf("\tArbitration Mechanism Supported     (AMS): Weighted Round Robin with Urgent Priority Class is %s\n",
+                       (cap->ams_cqr & 0x02) ? "supported":"not supported");
+       printf("\tContiguous Queues Required          (CQR): %s\n", (cap->ams_cqr & 0x01) ? "Yes":"No");
+       printf("\tMaximum Queue Entries Supported    (MQES): %u\n\n", cap->mqes + 1);
+}
 
-               printf("operational enlat:%d exlat:%d rrt:%d rrl:%d\n"
-                       "          rwt:%d rwl:%d idle_power:",
-                       le32_to_cpu(ctrl->psd[i].entry_lat), le32_to_cpu(ctrl->psd[i].exit_lat),
-                       ctrl->psd[i].read_tput, ctrl->psd[i].read_lat,
-                       ctrl->psd[i].write_tput, ctrl->psd[i].write_lat);
-               print_ps_power_and_scale(ctrl->psd[i].idle_power,
-                                        POWER_SCALE(ctrl->psd[i].idle_scale));
-               printf(" active_power:");
-               print_ps_power_and_scale(ctrl->psd[i].active_power,
-                                        POWER_SCALE(ctrl->psd[i].active_work_scale));
-               printf("\n");
+static void nvme_show_registers_version(__u32 vs)
+{
+       printf("\tNVMe specification %d.%d\n\n", (vs & 0xffff0000) >> 16,  (vs & 0x0000ff00) >> 8);
+}
 
+static void nvme_show_registers_cc_ams (__u8 ams)
+{
+       printf("\tArbitration Mechanism Selected     (AMS): ");
+       switch (ams) {
+       case 0:
+               printf("Round Robin\n");
+               break;
+       case 1:
+               printf("Weighted Round Robin with Urgent Priority Class\n");
+               break;
+       case 7:
+               printf("Vendor Specific\n");
+               break;
+       default:
+               printf("Reserved\n");
        }
 }
 
-void __show_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*vendor_show)(__u8 *vs, struct json_object *root))
+static void nvme_show_registers_cc_shn (__u8 shn)
 {
-       int human = mode & HUMAN, vs = mode & VS;
-
-       printf("vid       : %#x\n", le16_to_cpu(ctrl->vid));
-       printf("ssvid     : %#x\n", le16_to_cpu(ctrl->ssvid));
-       printf("sn        : %-.*s\n", (int)sizeof(ctrl->sn), ctrl->sn);
-       printf("mn        : %-.*s\n", (int)sizeof(ctrl->mn), ctrl->mn);
-       printf("fr        : %-.*s\n", (int)sizeof(ctrl->fr), ctrl->fr);
-       printf("rab       : %d\n", ctrl->rab);
-       printf("ieee      : %02x%02x%02x\n",
-               ctrl->ieee[2], ctrl->ieee[1], ctrl->ieee[0]);
-       printf("cmic      : %#x\n", ctrl->cmic);
-       if (human)
-               show_nvme_id_ctrl_cmic(ctrl->cmic);
-       printf("mdts      : %d\n", ctrl->mdts);
-       printf("cntlid    : %#x\n", le16_to_cpu(ctrl->cntlid));
-       printf("ver       : %#x\n", le32_to_cpu(ctrl->ver));
-       printf("rtd3r     : %#x\n", le32_to_cpu(ctrl->rtd3r));
-       printf("rtd3e     : %#x\n", le32_to_cpu(ctrl->rtd3e));
-       printf("oaes      : %#x\n", le32_to_cpu(ctrl->oaes));
-       if (human)
-               show_nvme_id_ctrl_oaes(ctrl->oaes);
-       printf("ctratt    : %#x\n", le32_to_cpu(ctrl->ctratt));
-       if (human)
-               show_nvme_id_ctrl_ctratt(ctrl->ctratt);
-       printf("rrls      : %#x\n", le16_to_cpu(ctrl->rrls));
-       printf("cntrltype : %d\n", ctrl->cntrltype);
-       if (human)
-               show_nvme_id_ctrl_cntrltype(ctrl->cntrltype);
-       printf("fguid     : %-.*s\n", (int)sizeof(ctrl->fguid), ctrl->fguid);
-       printf("crdt1     : %u\n", le16_to_cpu(ctrl->crdt1));
-       printf("crdt2     : %u\n", le16_to_cpu(ctrl->crdt2));
-       printf("crdt3     : %u\n", le16_to_cpu(ctrl->crdt3));
-
-       printf("oacs      : %#x\n", le16_to_cpu(ctrl->oacs));
-       if (human)
-               show_nvme_id_ctrl_oacs(ctrl->oacs);
-       printf("acl       : %d\n", ctrl->acl);
-       printf("aerl      : %d\n", ctrl->aerl);
-       printf("frmw      : %#x\n", ctrl->frmw);
-       if (human)
-               show_nvme_id_ctrl_frmw(ctrl->frmw);
-       printf("lpa       : %#x\n", ctrl->lpa);
-       if (human)
-               show_nvme_id_ctrl_lpa(ctrl->lpa);
-       printf("elpe      : %d\n", ctrl->elpe);
-       printf("npss      : %d\n", ctrl->npss);
-       printf("avscc     : %#x\n", ctrl->avscc);
-       if (human)
-               show_nvme_id_ctrl_avscc(ctrl->avscc);
-       printf("apsta     : %#x\n", ctrl->apsta);
-       if (human)
-               show_nvme_id_ctrl_apsta(ctrl->apsta);
-       printf("wctemp    : %d\n", le16_to_cpu(ctrl->wctemp));
-       printf("cctemp    : %d\n", le16_to_cpu(ctrl->cctemp));
-       printf("mtfa      : %d\n", le16_to_cpu(ctrl->mtfa));
-       printf("hmpre     : %d\n", le32_to_cpu(ctrl->hmpre));
-       printf("hmmin     : %d\n", le32_to_cpu(ctrl->hmmin));
-       printf("tnvmcap   : %.0Lf\n", int128_to_double(ctrl->tnvmcap));
-       printf("unvmcap   : %.0Lf\n", int128_to_double(ctrl->unvmcap));
-       printf("rpmbs     : %#x\n", le32_to_cpu(ctrl->rpmbs));
-       if (human)
-               show_nvme_id_ctrl_rpmbs(ctrl->rpmbs);
-       printf("edstt     : %d\n", le16_to_cpu(ctrl->edstt));
-       printf("dsto      : %d\n", ctrl->dsto);
-       printf("fwug      : %d\n", ctrl->fwug);
-       printf("kas       : %d\n", le16_to_cpu(ctrl->kas));
-       printf("hctma     : %#x\n", le16_to_cpu(ctrl->hctma));
-       if (human)
-               show_nvme_id_ctrl_hctma(ctrl->hctma);
-       printf("mntmt     : %d\n", le16_to_cpu(ctrl->mntmt));
-       printf("mxtmt     : %d\n", le16_to_cpu(ctrl->mxtmt));
-       printf("sanicap   : %#x\n", le32_to_cpu(ctrl->sanicap));
-       if (human)
-               show_nvme_id_ctrl_sanicap(ctrl->sanicap);
-       printf("hmminds   : %d\n", le32_to_cpu(ctrl->hmminds));
-       printf("hmmaxd    : %d\n", le16_to_cpu(ctrl->hmmaxd));
-       printf("nsetidmax : %d\n", le16_to_cpu(ctrl->nsetidmax));
-       printf("endgidmax : %d\n", le16_to_cpu(ctrl->endgidmax));
-       printf("anatt     : %d\n", ctrl->anatt);
-       printf("anacap    : %d\n", ctrl->anacap);
-       if (human)
-               show_nvme_id_ctrl_anacap(ctrl->anacap);
-       printf("anagrpmax : %d\n", ctrl->anagrpmax);
-       printf("nanagrpid : %d\n", le32_to_cpu(ctrl->nanagrpid));
-       printf("pels      : %d\n", le32_to_cpu(ctrl->pels));
-       printf("sqes      : %#x\n", ctrl->sqes);
-       if (human)
-               show_nvme_id_ctrl_sqes(ctrl->sqes);
-       printf("cqes      : %#x\n", ctrl->cqes);
-       if (human)
-               show_nvme_id_ctrl_cqes(ctrl->cqes);
-       printf("maxcmd    : %d\n", le16_to_cpu(ctrl->maxcmd));
-       printf("nn        : %d\n", le32_to_cpu(ctrl->nn));
-       printf("oncs      : %#x\n", le16_to_cpu(ctrl->oncs));
-       if (human)
-               show_nvme_id_ctrl_oncs(ctrl->oncs);
-       printf("fuses     : %#x\n", le16_to_cpu(ctrl->fuses));
-       if (human)
-               show_nvme_id_ctrl_fuses(ctrl->fuses);
-       printf("fna       : %#x\n", ctrl->fna);
-       if (human)
-               show_nvme_id_ctrl_fna(ctrl->fna);
-       printf("vwc       : %#x\n", ctrl->vwc);
-       if (human)
-               show_nvme_id_ctrl_vwc(ctrl->vwc);
-       printf("awun      : %d\n", le16_to_cpu(ctrl->awun));
-       printf("awupf     : %d\n", le16_to_cpu(ctrl->awupf));
-       printf("nvscc     : %d\n", ctrl->nvscc);
-       if (human)
-               show_nvme_id_ctrl_nvscc(ctrl->nvscc);
-       printf("nwpc      : %d\n", ctrl->nwpc);
-       if (human)
-               show_nvme_id_ctrl_nwpc(ctrl->nwpc);
-       printf("acwu      : %d\n", le16_to_cpu(ctrl->acwu));
-       printf("sgls      : %#x\n", le32_to_cpu(ctrl->sgls));
-       if (human)
-               show_nvme_id_ctrl_sgls(ctrl->sgls);
-       printf("mnan      : %d\n", le32_to_cpu(ctrl->mnan));
-       printf("subnqn    : %-.*s\n", (int)sizeof(ctrl->subnqn), ctrl->subnqn);
-       printf("ioccsz    : %d\n", le32_to_cpu(ctrl->ioccsz));
-       printf("iorcsz    : %d\n", le32_to_cpu(ctrl->iorcsz));
-       printf("icdoff    : %d\n", le16_to_cpu(ctrl->icdoff));
-       printf("ctrattr   : %#x\n", ctrl->ctrattr);
-       if (human)
-               show_nvme_id_ctrl_ctrattr(ctrl->ctrattr);
-       printf("msdbd     : %d\n", ctrl->msdbd);
-
-       show_nvme_id_ctrl_power(ctrl);
-       if (vendor_show)
-               vendor_show(ctrl->vs, NULL);
-       else if (vs) {
-               printf("vs[]:\n");
-               d(ctrl->vs, sizeof(ctrl->vs), 16, 1);
+       printf("\tShutdown Notification              (SHN): ");
+       switch (shn) {
+       case 0:
+               printf("No notification; no effect\n");
+               break;
+       case 1:
+               printf("Normal shutdown notification\n");
+               break;
+       case 2:
+               printf("Abrupt shutdown notification\n");
+               break;
+       default:
+               printf("Reserved\n");
        }
 }
 
-void show_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode)
+static void nvme_show_registers_cc(__u32 cc)
 {
-       __show_nvme_id_ctrl(ctrl, mode, NULL);
+       printf("\tI/O Completion Queue Entry Size (IOCQES): %u bytes\n", 1 << ((cc & 0x00f00000) >> NVME_CC_IOCQES_SHIFT));
+       printf("\tI/O Submission Queue Entry Size (IOSQES): %u bytes\n", 1 << ((cc & 0x000f0000) >> NVME_CC_IOSQES_SHIFT));
+       nvme_show_registers_cc_shn((cc & 0x0000c000) >> NVME_CC_SHN_SHIFT);
+       nvme_show_registers_cc_ams((cc & 0x00003800) >> NVME_CC_AMS_SHIFT);
+       printf("\tMemory Page Size                   (MPS): %u bytes\n", 1 << (12 + ((cc & 0x00000780) >> NVME_CC_MPS_SHIFT)));
+       printf("\tI/O Command Sets Selected          (CSS): %s\n", (cc & 0x00000070) ? "Reserved":"NVM Command Set");
+       printf("\tEnable                              (EN): %s\n\n", (cc & 0x00000001) ? "Yes":"No");
 }
 
-void show_nvme_id_nvmset(struct nvme_id_nvmset *nvmset)
+static void nvme_show_registers_csts_shst(__u8 shst)
 {
-       int i;
-
-       printf("nid     : %d\n", nvmset->nid);
-       printf(".................\n");
-       for (i = 0; i < nvmset->nid; i++) {
-               printf(" NVM Set Attribute Entry[%2d]\n", i);
-               printf(".................\n");
-               printf("nvmset_id               : %d\n",
-                               le16_to_cpu(nvmset->ent[i].id));
-               printf("enduracne_group_id      : %d\n",
-                               le16_to_cpu(nvmset->ent[i].endurance_group_id));
-               printf("random_4k_read_typical  : %u\n",
-                               le32_to_cpu(nvmset->ent[i].random_4k_read_typical));
-               printf("optimal_write_size      : %u\n",
-                               le32_to_cpu(nvmset->ent[i].opt_write_size));
-               printf("total_nvmset_cap        : %.0Lf\n",
-                               int128_to_double(nvmset->ent[i].total_nvmset_cap));
-               printf("unalloc_nvmset_cap      : %.0Lf\n",
-                               int128_to_double(nvmset->ent[i].unalloc_nvmset_cap));
-               printf(".................\n");
+       printf("\tShutdown Status               (SHST): ");
+       switch (shst) {
+       case 0:
+               printf("Normal operation (no shutdown has been requested)\n");
+               break;
+       case 1:
+               printf("Shutdown processing occurring\n");
+               break;
+       case 2:
+               printf("Shutdown processing complete\n");
+               break;
+       default:
+               printf("Reserved\n");
        }
 }
 
-void json_nvme_id_nvmset(struct nvme_id_nvmset *nvmset, const char *devname)
+static void nvme_show_registers_csts(__u32 csts)
 {
-       struct json_object *root;
-       struct json_array *entries;
-       __u32 nent = nvmset->nid;
-       int i;
-
-       root = json_create_object();
+       printf("\tProcessing Paused               (PP): %s\n", (csts & 0x00000020) ? "Yes":"No");
+       printf("\tNVM Subsystem Reset Occurred (NSSRO): %s\n", (csts & 0x00000010) ? "Yes":"No");
+       nvme_show_registers_csts_shst((csts & 0x0000000c) >> 2);
+       printf("\tController Fatal Status        (CFS): %s\n", (csts & 0x00000002) ? "True":"False");
+       printf("\tReady                          (RDY): %s\n\n", (csts & 0x00000001) ? "Yes":"No");
 
-       json_object_add_value_int(root, "nid", nent);
+}
 
-       entries = json_create_array();
-       for (i = 0; i < nent; i++) {
-               struct json_object *entry = json_create_object();
+static void nvme_show_registers_aqa(__u32 aqa)
+{
+       printf("\tAdmin Completion Queue Size (ACQS): %u\n", ((aqa & 0x0fff0000) >> 16)+1);
+       printf("\tAdmin Submission Queue Size (ASQS): %u\n\n", (aqa & 0x00000fff)+1);
 
-               json_object_add_value_int(entry, "nvmset_id", le16_to_cpu(nvmset->ent[i].id));
-               json_object_add_value_int(entry, "endurance_group_id", le16_to_cpu(nvmset->ent[i].endurance_group_id));
-               json_object_add_value_int(entry, "random_4k_read_typical", le32_to_cpu(nvmset->ent[i].random_4k_read_typical));
-               json_object_add_value_int(entry, "optimal_write_size", le32_to_cpu(nvmset->ent[i].opt_write_size));
-               json_object_add_value_float(entry, "total_nvmset_cap", int128_to_double(nvmset->ent[i].total_nvmset_cap));
-               json_object_add_value_float(entry, "unalloc_nvmset_cap", int128_to_double(nvmset->ent[i].unalloc_nvmset_cap));
+}
 
-               json_array_add_value_object(entries, entry);
+static void nvme_show_registers_cmbloc(__u32 cmbloc, __u32 cmbsz)
+{
+       if (cmbsz == 0) {
+               printf("\tController Memory Buffer feature is not supported\n\n");
+               return;
        }
 
-       json_object_add_value_array(root, "NVMSet", entries);
+        static const char *enforced[] = { "Enforced", "Not Enforced" };
 
-       json_print_object(root, NULL);
-       printf("\n");
-       json_free_object(root);
+       printf("\tOffset                                                        (OFST): 0x%x (See cmbsz.szu for granularity)\n",
+                       (cmbloc & 0xfffff000) >> 12);
+
+       printf("\tCMB Queue Dword Alignment                                     (CQDA): %d\n",
+                       (cmbloc & 0x00000100) >> 8);
+
+       printf("\tCMB Data Metadata Mixed Memory Support                      (CDMMMS): %s\n",
+                       enforced[(cmbloc & 0x00000080) >> 7]);
+
+       printf("\tCMB Data Pointer and Command Independent Locations Support (CDPCILS): %s\n",
+                       enforced[(cmbloc & 0x00000040) >> 6]);
+
+       printf("\tCMB Data Pointer Mixed Locations Support                    (CDPMLS): %s\n",
+                       enforced[(cmbloc & 0x00000020) >> 5]);
+
+       printf("\tCMB Queue Physically Discontiguous Support                   (CQPDS): %s\n",
+                       enforced[(cmbloc & 0x00000010) >> 4]);
+
+       printf("\tCMB Queue Mixed Memory Support                               (CQMMS): %s\n",
+                       enforced[(cmbloc & 0x00000008) >> 3]);
+
+       printf("\tBase Indicator Register                                        (BIR): 0x%x\n\n",
+                       (cmbloc & 0x00000007));
 }
 
-void show_nvme_list_secondary_ctrl(const struct nvme_secondary_controllers_list *sc_list, __u32 count)
+static const char *nvme_register_szu_to_string(__u8 szu)
 {
-       int i;
-       __u16 num = sc_list->num;
-       __u32 entries = min(num, count);
-
-       static const char * const state_desc[] = { "Offline", "Online" };
-       const struct nvme_secondary_controller_entry *sc_entry = &sc_list->sc_entry[0];
+       switch (szu) {
+       case 0: return "4 KB";
+       case 1: return "64 KB";
+       case 2: return "1 MB";
+       case 3: return "16 MB";
+       case 4: return "256 MB";
+       case 5: return "4 GB";
+       case 6: return "64 GB";
+       default:        return "Reserved";
+       }
+}
 
-       printf("Identify Secondary Controller List:\n");
-       printf("   NUMID       : Number of Identifiers           : %d\n", num);
+static void nvme_show_registers_cmbsz(__u32 cmbsz)
+{
+       if (cmbsz == 0) {
+               printf("\tController Memory Buffer feature is not supported\n\n");
+               return;
+       }
+       printf("\tSize                      (SZ): %u\n", (cmbsz & 0xfffff000) >> 12);
+       printf("\tSize Units               (SZU): %s\n", nvme_register_szu_to_string((cmbsz & 0x00000f00) >> 8));
+       printf("\tWrite Data Support       (WDS): Write Data and metadata transfer in Controller Memory Buffer is %s\n",
+                       (cmbsz & 0x00000010) ? "Supported":"Not supported");
+       printf("\tRead Data Support        (RDS): Read Data and metadata transfer in Controller Memory Buffer is %s\n",
+                       (cmbsz & 0x00000008) ? "Supported":"Not supported");
+       printf("\tPRP SGL List Support   (LISTS): PRP/SG Lists in Controller Memory Buffer is %s\n",
+                       (cmbsz & 0x00000004) ? "Supported":"Not supported");
+       printf("\tCompletion Queue Support (CQS): Admin and I/O Completion Queues in Controller Memory Buffer is %s\n",
+                       (cmbsz & 0x00000002) ? "Supported":"Not supported");
+       printf("\tSubmission Queue Support (SQS): Admin and I/O Submission Queues in Controller Memory Buffer is %s\n\n",
+                       (cmbsz & 0x00000001) ? "Supported":"Not supported");
+}
 
-       for (i = 0; i < entries; i++) {
-               printf("   SCEntry[%-3d]:\n", i);
-               printf("................\n");
-               printf("     SCID      : Secondary Controller Identifier : 0x%.04x\n",
-                               le16_to_cpu(sc_entry[i].scid));
-               printf("     PCID      : Primary Controller Identifier   : 0x%.04x\n",
-                               le16_to_cpu(sc_entry[i].pcid));
-               printf("     SCS       : Secondary Controller State      : 0x%.04x (%s)\n",
-                               sc_entry[i].scs,
-                               state_desc[sc_entry[i].scs & 0x1]);
-               printf("     VFN       : Virtual Function Number         : 0x%.04x\n",
-                               le16_to_cpu(sc_entry[i].vfn));
-               printf("     NVQ       : Num VQ Flex Resources Assigned  : 0x%.04x\n",
-                               le16_to_cpu(sc_entry[i].nvq));
-               printf("     NVI       : Num VI Flex Resources Assigned  : 0x%.04x\n",
-                               le16_to_cpu(sc_entry[i].nvi));
+static void nvme_show_registers_bpinfo_brs(__u8 brs)
+{
+       printf("\tBoot Read Status                (BRS): ");
+       switch (brs) {
+       case 0:
+               printf("No Boot Partition read operation requested\n");
+               break;
+       case 1:
+               printf("Boot Partition read in progress\n");
+               break;
+       case 2:
+               printf("Boot Partition read completed successfully\n");
+               break;
+       case 3:
+               printf("Error completing Boot Partition read\n");
+               break;
+       default:
+               printf("Invalid\n");
        }
 }
 
-void json_nvme_list_secondary_ctrl(const struct nvme_secondary_controllers_list *sc_list, __u32 count)
+static void nvme_show_registers_bpinfo(__u32 bpinfo)
 {
-       int i;
-       struct json_object *root;
-       struct json_array *entries;
-       __u32 nent = min(sc_list->num, count);
-       const struct nvme_secondary_controller_entry *sc_entry = &sc_list->sc_entry[0];
+       if (bpinfo == 0) {
+               printf("\tBoot Partition feature is not supported\n\n");
+               return;
+       }
 
-       root = json_create_object();
+       printf("\tActive Boot Partition ID      (ABPID): %u\n", (bpinfo & 0x80000000) >> 31);
+       nvme_show_registers_bpinfo_brs((bpinfo & 0x03000000) >> 24);
+       printf("\tBoot Partition Size            (BPSZ): %u\n", bpinfo & 0x00007fff);
+}
 
-       json_object_add_value_int(root, "num", nent);
+static void nvme_show_registers_bprsel(__u32 bprsel)
+{
+       if (bprsel == 0) {
+               printf("\tBoot Partition feature is not supported\n\n");
+               return;
+       }
 
-       entries = json_create_array();
-       for (i = 0; i < nent; i++) {
-               struct json_object *entry = json_create_object();
+       printf("\tBoot Partition Identifier      (BPID): %u\n", (bprsel & 0x80000000) >> 31);
+       printf("\tBoot Partition Read Offset    (BPROF): %x\n", (bprsel & 0x3ffffc00) >> 10);
+       printf("\tBoot Partition Read Size      (BPRSZ): %x\n", bprsel & 0x000003ff);
+}
 
-               json_object_add_value_int(entry, "secondary-controller-identifier", le16_to_cpu(sc_entry[i].scid));
-               json_object_add_value_int(entry, "primary-controller-identifier", le16_to_cpu(sc_entry[i].pcid));
-               json_object_add_value_int(entry, "secondary-controller-state",
-                                         sc_entry[i].scs);
-               json_object_add_value_int(entry, "virtual-function-number",  le16_to_cpu(sc_entry[i].vfn));
-               json_object_add_value_int(entry, "num-virtual-queues",  le16_to_cpu(sc_entry[i].nvq));
-               json_object_add_value_int(entry, "num-virtual-interrupts",  le16_to_cpu(sc_entry[i].nvi));
-               json_array_add_value_object(entries, entry);
+static void nvme_show_registers_bpmbl(uint64_t bpmbl)
+{
+       if (bpmbl == 0) {
+               printf("\tBoot Partition feature is not supported\n\n");
+               return;
        }
 
-       json_object_add_value_array(root, "secondary-controllers", entries);
+       printf("\tBoot Partition Memory Buffer Base Address (BMBBA): %"PRIx64"\n", bpmbl);
+}
 
-       json_print_object(root, NULL);
-       printf("\n");
-       json_free_object(root);
+static void nvme_show_registers_cmbmsc(uint64_t cmbmsc)
+{
+       printf("\tController Base Address (CBA)      : %lx\n",
+                       (cmbmsc & 0xfffffffffffff000) >> 12);
+       printf("\tController Memory Space Enable (CMSE): %lx\n",
+                       (cmbmsc & 0x0000000000000002) >> 1);
+       printf("\tCapabilities Registers Enabled (CRE) : CMBLOC and "\
+              "CMBSZ registers are%senabled\n\n", (cmbmsc & 0x0000000000000001) ? " " : " NOT ");
 }
 
-void show_nvme_id_ns_granularity_list(const struct nvme_id_ns_granularity_list *glist, unsigned int flags)
+static void nvme_show_registers_cmbsts(__u32 cmbsts)
 {
-       int i;
+       printf("\tController Base Address Invalid (CBAI): %x\n\n", (cmbsts & 0x00000001));
+}
 
-       printf("Identify Namespace Granularity List:\n");
-       printf("   ATTR        : Namespace Granularity Attributes: 0x%x\n", glist->attributes);
-       printf("   NUMD        : Number of Descriptors           : %d\n", glist->num_descriptors);
+static void nvme_show_registers_pmrcap(__u32 pmrcap)
+{
+       printf("\tController Memory Space Supported (CMSS)                 : "\
+              "Referencing PMR with host supplied addresses is %s\n",
+              ((pmrcap & 0x01000000) >> 24) ? "Supported" : "Not Supported");
+       printf("\tPersistent Memory Region Timeout                  (PMRTO): %x\n", (pmrcap & 0x00ff0000) >> 16);
+       printf("\tPersistent Memory Region Write Barrier Mechanisms(PMRWBM): %x\n", (pmrcap & 0x00003c00) >> 10);
+       printf("\tPersistent Memory Region Time Units               (PMRTU): PMR time unit is %s\n",
+                       (pmrcap & 0x00000300) >> 8 ? "minutes":"500 milliseconds");
+       printf("\tBase Indicator Register                             (BIR): %x\n", (pmrcap & 0x000000e0) >> 5);
+       printf("\tWrite Data Support                                  (WDS): Write data to the PMR is %s\n",
+                       (pmrcap & 0x00000010) ? "supported":"not supported");
+       printf("\tRead Data Support                                   (RDS): Read data from the PMR is %s\n",
+                       (pmrcap & 0x00000008) ? "supported":"not supported");
+}
 
-       /* Number of Descriptors is a 0's based value */
-       for (i = 0; i <= glist->num_descriptors; i++) {
-               printf("\n     Entry[%2d] :\n", i);
-               printf("................\n");
-               printf("     NSG       : Namespace Size Granularity     : 0x%"PRIx64"\n",
-                               le64_to_cpu(glist->entry[i].namespace_size_granularity));
-               printf("     NCG       : Namespace Capacity Granularity : 0x%"PRIx64"\n",
-                               le64_to_cpu(glist->entry[i].namespace_capacity_granularity));
-       }
+static void nvme_show_registers_pmrctl(__u32 pmrctl)
+{
+       printf("\tEnable (EN): PMR is %s\n", (pmrctl & 0x00000001) ? "READY":"Disabled");
 }
 
-void json_nvme_id_ns_granularity_list(const struct nvme_id_ns_granularity_list *glist, unsigned int flags)
+static const char *nvme_register_pmr_hsts_to_string(__u8 hsts)
 {
-       int i;
-       struct json_object *root;
-       struct json_array *entries;
+        switch (hsts) {
+        case 0: return "Normal Operation";
+        case 1: return "Restore Error";
+        case 2: return "Read Only";
+        case 3: return "Unreliable";
+        default: return "Reserved";
+        }
+}
 
-       root = json_create_object();
+static void nvme_show_registers_pmrsts(__u32 pmrsts, __u32 pmrctl)
+{
+       printf("\tController Base Address Invalid (CBAI): %x\n", (pmrsts & 0x00001000) >> 12);
+       printf("\tHealth Status                   (HSTS): %s\n", nvme_register_pmr_hsts_to_string((pmrsts & 0x00000e00) >> 9));
+       printf("\tNot Ready                       (NRDY): The Persistent Memory Region is %s to process "\
+              "PCI Express memory read and write requests\n",
+              (pmrsts & 0x00000100) == 0 && (pmrctl & 0x00000001) ? "READY":"Not Ready");
+       printf("\tError                           (ERR) : %x\n", (pmrsts & 0x000000ff));
+}
 
-       json_object_add_value_int(root, "attributes", glist->attributes);
-       json_object_add_value_int(root, "num-descriptors", glist->num_descriptors);
+static const char *nvme_register_pmr_pmrszu_to_string(__u8 pmrszu)
+{
+       switch (pmrszu) {
+       case 0: return "Bytes";
+       case 1: return "One KB";
+       case 2: return "One MB";
+       case 3: return "One GB";
+       default: return "Reserved";
+       }
+}
 
-       entries = json_create_array();
-       for (i = 0; i <= glist->num_descriptors; i++) {
-               struct json_object *entry = json_create_object();
+static void nvme_show_registers_pmrebs(__u32 pmrebs)
+{
+       printf("\tPMR Elasticity Buffer Size Base  (PMRWBZ): %x\n", (pmrebs & 0xffffff00) >> 8);
+       printf("\tRead Bypass Behavior                     : memory reads not conflicting with memory writes "\
+              "in the PMR Elasticity Buffer %s bypass those memory writes\n",
+              (pmrebs & 0x00000010) ? "SHALL":"MAY");
+       printf("\tPMR Elasticity Buffer Size Units (PMRSZU): %s\n",
+               nvme_register_pmr_pmrszu_to_string(pmrebs & 0x0000000f));
+}
+
+static void nvme_show_registers_pmrswtp(__u32 pmrswtp)
+{
+       printf("\tPMR Sustained Write Throughput       (PMRSWTV): %x\n", (pmrswtp & 0xffffff00) >> 8);
+       printf("\tPMR Sustained Write Throughput Units (PMRSWTU): %s/second\n",
+               nvme_register_pmr_pmrszu_to_string(pmrswtp & 0x0000000f));
+}
 
-               json_object_add_value_uint(entry, "namespace-size-granularity",
-                       le64_to_cpu(glist->entry[i].namespace_size_granularity));
-               json_object_add_value_uint(entry, "namespace-capacity-granularity",
-                       le64_to_cpu(glist->entry[i].namespace_capacity_granularity));
-               json_array_add_value_object(entries, entry);
-       }
+static void nvme_show_registers_pmrmsc(uint64_t pmrmsc)
+{
+       printf("\tController Base Address (CBA)         : %lx\n", (pmrmsc & 0xfffffffffffff000) >> 12);
+       printf("\tController Memory Space Enable (CMSE  : %lx\n\n", (pmrmsc & 0x0000000000000001) >> 1);
+}
 
-       json_object_add_value_array(root, "namespace-granularity-list", entries);
+static inline uint32_t mmio_read32(void *addr)
+{
+       __le32 *p = addr;
 
-       json_print_object(root, NULL);
-       printf("\n");
-       json_free_object(root);
+       return le32_to_cpu(*p);
 }
 
-void show_nvme_id_uuid_list(const struct nvme_id_uuid_list *uuid_list, unsigned int flags)
+/* Access 64-bit registers as 2 32-bit; Some devices fail 64-bit MMIO. */
+static inline __u64 mmio_read64(void *addr)
 {
-       int i, human = flags & HUMAN;
-       /* The 0th entry is reserved */
-       for (i = 1; i < NVME_MAX_UUID_ENTRIES; i++) {
-               uuid_t uuid;
-               char *association = "";
-               uint8_t identifier_association = uuid_list->entry[i].header & 0x3;
-               /* The list is terminated by a zero UUID value */
-               if (memcmp(uuid_list->entry[i].uuid, zero_uuid, sizeof(zero_uuid)) == 0)
-                       break;
-               memcpy(&uuid, uuid_list->entry[i].uuid, sizeof(uuid));
-               if (human) {
-                       switch (identifier_association) {
-                       case 0x0:
-                               association = "No association reported";
-                               break;
-                       case 0x1:
-                               association = "associated with PCI Vendor ID";
-                               break;
-                       case 0x2:
-                               association = "associated with PCI Subsystem Vendor ID";
-                               break;
-                       default:
-                               association = "Reserved";
-                               break;
-                       }
-               }
-               printf(" Entry[%3d]\n", i);
-               printf(".................\n");
-               printf("association  : 0x%x %s\n", identifier_association, association);
-               printf("UUID         : %s", nvme_uuid_to_string(uuid));
-               if (memcmp(uuid_list->entry[i].uuid, invalid_uuid, sizeof(zero_uuid)) == 0)
-                       printf(" (Invalid UUID)");
-               printf("\n.................\n");
-       }
+       __le32 *p = addr;
+
+       return le32_to_cpu(*p) | ((uint64_t)le32_to_cpu(*(p + 1)) << 32);
 }
 
-void json_nvme_id_uuid_list(struct nvme_id_uuid_list *uuid_list)
+static void json_ctrl_registers(void *bar)
 {
+       uint64_t cap, asq, acq, bpmbl, cmbmsc, pmrmsc;
+       uint32_t vs, intms, intmc, cc, csts, nssr, aqa, cmbsz, cmbloc,
+                       bpinfo, bprsel, cmbsts, pmrcap, pmrctl, pmrsts, pmrebs, pmrswtp;
        struct json_object *root;
-       struct json_array *entries;
-       int i;
+
+       cap = mmio_read64(bar + NVME_REG_CAP);
+       vs = mmio_read32(bar + NVME_REG_VS);
+       intms = mmio_read32(bar + NVME_REG_INTMS);
+       intmc = mmio_read32(bar + NVME_REG_INTMC);
+       cc = mmio_read32(bar + NVME_REG_CC);
+       csts = mmio_read32(bar + NVME_REG_CSTS);
+       nssr = mmio_read32(bar + NVME_REG_NSSR);
+       aqa = mmio_read32(bar + NVME_REG_AQA);
+       asq = mmio_read64(bar + NVME_REG_ASQ);
+       acq = mmio_read64(bar + NVME_REG_ACQ);
+       cmbloc = mmio_read32(bar + NVME_REG_CMBLOC);
+       cmbsz = mmio_read32(bar + NVME_REG_CMBSZ);
+       bpinfo = mmio_read32(bar + NVME_REG_BPINFO);
+       bprsel = mmio_read32(bar + NVME_REG_BPRSEL);
+       bpmbl = mmio_read64(bar + NVME_REG_BPMBL);
+       cmbmsc = mmio_read64(bar + NVME_REG_CMBMSC);
+       cmbsts = mmio_read32(bar + NVME_REG_CMBSTS);
+       pmrcap = mmio_read32(bar + NVME_REG_PMRCAP);
+       pmrctl = mmio_read32(bar + NVME_REG_PMRCTL);
+       pmrsts = mmio_read32(bar + NVME_REG_PMRSTS);
+       pmrebs = mmio_read32(bar + NVME_REG_PMREBS);
+       pmrswtp = mmio_read32(bar + NVME_REG_PMRSWTP);
+       pmrmsc = mmio_read64(bar + NVME_REG_PMRMSC);
+
        root = json_create_object();
-       entries = json_create_array();
-       /* The 0th entry is reserved */
-       for (i = 1; i < NVME_MAX_UUID_ENTRIES; i++) {
-               uuid_t uuid;
-               struct json_object *entry = json_create_object();
-               /* The list is terminated by a zero UUID value */
-               if (memcmp(uuid_list->entry[i].uuid, zero_uuid, sizeof(zero_uuid)) == 0)
-                       break;
-               memcpy(&uuid, uuid_list->entry[i].uuid, sizeof(uuid));
-               json_object_add_value_int(entry, "association", uuid_list->entry[i].header & 0x3);
-               json_object_add_value_string(entry, "uuid", nvme_uuid_to_string(uuid));
-               json_array_add_value_object(entries, entry);
-       }
-       json_object_add_value_array(root, "UUID-list", entries);
+       json_object_add_value_uint(root, "cap", cap);
+       json_object_add_value_int(root, "vs", vs);
+       json_object_add_value_int(root, "intms", intms);
+       json_object_add_value_int(root, "intmc", intmc);
+       json_object_add_value_int(root, "cc", cc);
+       json_object_add_value_int(root, "csts", csts);
+       json_object_add_value_int(root, "nssr", nssr);
+       json_object_add_value_int(root, "aqa", aqa);
+       json_object_add_value_uint(root, "asq", asq);
+       json_object_add_value_uint(root, "acq", acq);
+       json_object_add_value_int(root, "cmbloc", cmbloc);
+       json_object_add_value_int(root, "cmbsz", cmbsz);
+       json_object_add_value_int(root, "bpinfo", bpinfo);
+       json_object_add_value_int(root, "bprsel", bprsel);
+       json_object_add_value_uint(root, "bpmbl", bpmbl);
+       json_object_add_value_uint(root, "cmbmsc", cmbmsc);
+       json_object_add_value_int(root, "cmbsts", cmbsts);
+       json_object_add_value_int(root, "pmrcap", pmrcap);
+       json_object_add_value_int(root, "pmrctl", pmrctl);
+       json_object_add_value_int(root, "pmrsts", pmrsts);
+       json_object_add_value_int(root, "pmrebs", pmrebs);
+       json_object_add_value_int(root, "pmrswtp", pmrswtp);
+       json_object_add_value_uint(root, "pmrmsc", pmrmsc);
        json_print_object(root, NULL);
        printf("\n");
        json_free_object(root);
 }
 
-static const char *nvme_trtype_to_string(__u8 trtype)
-{
-       switch(trtype) {
-       case 0: return "The transport type is not indicated or the error "\
-               "is not transport related.";
-       case 1: return "RDMA Transport error.";
-       case 2: return "Fibre Channel Transport error.";
-       case 3: return "TCP Transport error.";
-       case 254: return "Intra-host Transport error.";
-       default: return "Reserved";
-       };
-}
-
-void show_error_log(struct nvme_error_log_page *err_log, int entries, const char *devname)
+void nvme_show_ctrl_registers(void *bar, bool fabrics, enum nvme_print_flags flags)
 {
-       int i;
-
-       printf("Error Log Entries for device:%s entries:%d\n", devname,
-                                                               entries);
-       printf(".................\n");
-       for (i = 0; i < entries; i++) {
-               printf(" Entry[%2d]   \n", i);
-               printf(".................\n");
-               printf("error_count     : %"PRIu64"\n", le64_to_cpu(err_log[i].error_count));
-               printf("sqid            : %d\n", err_log[i].sqid);
-               printf("cmdid           : %#x\n", err_log[i].cmdid);
-               printf("status_field    : %#x(%s)\n", err_log[i].status_field,
-                       nvme_status_to_string(le16_to_cpu(err_log[i].status_field) >> 1));
-               printf("parm_err_loc    : %#x\n", err_log[i].parm_error_location);
-               printf("lba             : %#"PRIx64"\n",le64_to_cpu(err_log[i].lba));
-               printf("nsid            : %#x\n", err_log[i].nsid);
-               printf("vs              : %d\n", err_log[i].vs);
-               printf("trtype          : %s\n", nvme_trtype_to_string(err_log[i].trtype));
-               printf("cs              : %#"PRIx64"\n",
-                      le64_to_cpu(err_log[i].cs));
-               printf("trtype_spec_info: %#x\n", err_log[i].trtype_spec_info);
-               printf(".................\n");
-       }
-}
+       const unsigned int reg_size = 0x50;  /* 00h to 4Fh */
+       uint64_t cap, asq, acq, bpmbl, cmbmsc, pmrmsc;
+       uint32_t vs, intms, intmc, cc, csts, nssr, aqa, cmbsz, cmbloc, bpinfo,
+                bprsel, cmbsts, pmrcap, pmrctl, pmrsts, pmrebs, pmrswtp;
+       int human = flags & VERBOSE;
 
-void show_nvme_resv_report(struct nvme_reservation_status *status, int bytes, __u32 cdw11)
-{
-       int i, j, regctl, entries;
+       if (flags & BINARY)
+               return d_raw((unsigned char *)bar, reg_size);
+       if (flags & JSON)
+               return json_ctrl_registers(bar);
 
-       regctl = status->regctl[0] | (status->regctl[1] << 8);
+       cap = mmio_read64(bar + NVME_REG_CAP);
+       vs = mmio_read32(bar + NVME_REG_VS);
+       intms = mmio_read32(bar + NVME_REG_INTMS);
+       intmc = mmio_read32(bar + NVME_REG_INTMC);
+       cc = mmio_read32(bar + NVME_REG_CC);
+       csts = mmio_read32(bar + NVME_REG_CSTS);
+       nssr = mmio_read32(bar + NVME_REG_NSSR);
+       aqa = mmio_read32(bar + NVME_REG_AQA);
+       asq = mmio_read64(bar + NVME_REG_ASQ);
+       acq = mmio_read64(bar + NVME_REG_ACQ);
+       cmbloc = mmio_read32(bar + NVME_REG_CMBLOC);
+       cmbsz = mmio_read32(bar + NVME_REG_CMBSZ);
+       bpinfo = mmio_read32(bar + NVME_REG_BPINFO);
+       bprsel = mmio_read32(bar + NVME_REG_BPRSEL);
+       bpmbl = mmio_read64(bar + NVME_REG_BPMBL);
+       cmbmsc = mmio_read64(bar + NVME_REG_CMBMSC);
+       cmbsts = mmio_read32(bar + NVME_REG_CMBSTS);
+       pmrcap = mmio_read32(bar + NVME_REG_PMRCAP);
+       pmrctl = mmio_read32(bar + NVME_REG_PMRCTL);
+       pmrsts = mmio_read32(bar + NVME_REG_PMRSTS);
+       pmrebs = mmio_read32(bar + NVME_REG_PMREBS);
+       pmrswtp = mmio_read32(bar + NVME_REG_PMRSWTP);
+       pmrmsc = mmio_read64(bar + NVME_REG_PMRMSC);
 
-       printf("\nNVME Reservation status:\n\n");
-       printf("gen       : %d\n", le32_to_cpu(status->gen));
-       printf("rtype     : %d\n", status->rtype);
-       printf("regctl    : %d\n", regctl);
-       printf("ptpls     : %d\n", status->ptpls);
+       if (human) {
+               if (cap != 0xffffffff) {
+                       printf("cap     : %"PRIx64"\n", cap);
+                       nvme_show_registers_cap((struct nvme_bar_cap *)&cap);
+               }
+               if (vs != 0xffffffff) {
+                       printf("version : %x\n", vs);
+                       nvme_show_registers_version(vs);
+               }
+               if (cc != 0xffffffff) {
+                       printf("cc      : %x\n", cc);
+                       nvme_show_registers_cc(cc);
+               }
+               if (csts != 0xffffffff) {
+                       printf("csts    : %x\n", csts);
+                       nvme_show_registers_csts(csts);
+               }
+               if (nssr != 0xffffffff) {
+                       printf("nssr    : %x\n", nssr);
+                       printf("\tNVM Subsystem Reset Control (NSSRC): %u\n\n", nssr);
+               }
+               if (!fabrics) {
+                       printf("intms   : %x\n", intms);
+                       printf("\tInterrupt Vector Mask Set (IVMS): %x\n\n",
+                                       intms);
 
-       /* check Extended Data Structure bit */
-       if ((cdw11 & 0x1) == 0) {
-               /* if status buffer was too small, don't loop past the end of the buffer */
-               entries = (bytes - 24) / 24;
-               if (entries < regctl)
-                       regctl = entries;
+                       printf("intmc   : %x\n", intmc);
+                       printf("\tInterrupt Vector Mask Clear (IVMC): %x\n\n",
+                                       intmc);
+                       printf("aqa     : %x\n", aqa);
+                       nvme_show_registers_aqa(aqa);
 
-               for (i = 0; i < regctl; i++) {
-                       printf("regctl[%d] :\n", i);
-                       printf("  cntlid  : %x\n", le16_to_cpu(status->regctl_ds[i].cntlid));
-                       printf("  rcsts   : %x\n", status->regctl_ds[i].rcsts);
-                       printf("  hostid  : %"PRIx64"\n", le64_to_cpu(status->regctl_ds[i].hostid));
-                       printf("  rkey    : %"PRIx64"\n", le64_to_cpu(status->regctl_ds[i].rkey));
-               }
-       } else {
-               struct nvme_reservation_status_ext *ext_status = (struct nvme_reservation_status_ext *)status;
-               /* if status buffer was too small, don't loop past the end of the buffer */
-               entries = (bytes - 64) / 64;
-               if (entries < regctl)
-                       regctl = entries;
+                       printf("asq     : %"PRIx64"\n", asq);
+                       printf("\tAdmin Submission Queue Base (ASQB): %"PRIx64"\n\n",
+                                       asq);
 
-               for (i = 0; i < regctl; i++) {
-                       printf("regctlext[%d] :\n", i);
-                       printf("  cntlid     : %x\n", le16_to_cpu(ext_status->regctl_eds[i].cntlid));
-                       printf("  rcsts      : %x\n", ext_status->regctl_eds[i].rcsts);
-                       printf("  rkey       : %"PRIx64"\n", le64_to_cpu(ext_status->regctl_eds[i].rkey));
-                       printf("  hostid     : ");
-                       for (j = 0; j < 16; j++)
-                               printf("%x", ext_status->regctl_eds[i].hostid[j]);
-                       printf("\n");
-               }
-       }
-       printf("\n");
-}
+                       printf("acq     : %"PRIx64"\n", acq);
+                       printf("\tAdmin Completion Queue Base (ACQB): %"PRIx64"\n\n",
+                                       acq);
 
-static const char *fw_to_string(__u64 fw)
-{
-       static char ret[9];
-       char *c = (char *)&fw;
-       int i;
+                       printf("cmbloc  : %x\n", cmbloc);
+                       nvme_show_registers_cmbloc(cmbloc, cmbsz);
 
-       for (i = 0; i < 8; i++)
-               ret[i] = c[i] >= '!' && c[i] <= '~' ? c[i] : '.';
-       ret[i] = '\0';
-       return ret;
-}
+                       printf("cmbsz   : %x\n", cmbsz);
+                       nvme_show_registers_cmbsz(cmbsz);
 
-void show_fw_log(struct nvme_firmware_log_page *fw_log, const char *devname)
-{
-       int i;
+                       printf("bpinfo  : %x\n", bpinfo);
+                       nvme_show_registers_bpinfo(bpinfo);
 
-       printf("Firmware Log for device:%s\n", devname);
-       printf("afi  : %#x\n", fw_log->afi);
-       for (i = 0; i < 7; i++)
-               if (fw_log->frs[i])
-                       printf("frs%d : %#016"PRIx64" (%s)\n", i + 1, (uint64_t)fw_log->frs[i],
-                                               fw_to_string(fw_log->frs[i]));
-}
+                       printf("bprsel  : %x\n", bprsel);
+                       nvme_show_registers_bprsel(bprsel);
 
-void show_changed_ns_list_log(struct nvme_changed_ns_list_log *log, const char *devname)
-{
-       int i;
-       __u32 nsid;
+                       printf("bpmbl   : %"PRIx64"\n", bpmbl);
+                       nvme_show_registers_bpmbl(bpmbl);
 
-       if (log->log[0] != cpu_to_le32(0XFFFFFFFF)) {
-               for (i = 0; i < NVME_MAX_CHANGED_NAMESPACES; i++) {
-                       nsid = le32_to_cpu(log->log[i]);
-                       if (nsid == 0)
-                               break;
+                       printf("cmbmsc  : %"PRIx64"\n", cmbmsc);
+                       nvme_show_registers_cmbmsc(cmbmsc);
 
-                       printf("[%4u]:%#x\n", i, nsid);
-               }
-       } else
-               printf("more than %d ns changed\n", NVME_MAX_CHANGED_NAMESPACES);
-}
+                       printf("cmbsts  : %x\n", cmbsts);
+                       nvme_show_registers_cmbsts(cmbsts);
 
-static void show_effects_log_human(__u32 effect)
-{
-       const char *set = "+";
-       const char *clr = "-";
+                       printf("pmrcap  : %x\n", pmrcap);
+                       nvme_show_registers_pmrcap(pmrcap);
 
-       printf("  CSUPP+");
-       printf("  LBCC%s", (effect & NVME_CMD_EFFECTS_LBCC) ? set : clr);
-       printf("  NCC%s", (effect & NVME_CMD_EFFECTS_NCC) ? set : clr);
-       printf("  NIC%s", (effect & NVME_CMD_EFFECTS_NIC) ? set : clr);
-       printf("  CCC%s", (effect & NVME_CMD_EFFECTS_CCC) ? set : clr);
-       printf("  USS%s", (effect & NVME_CMD_EFFECTS_UUID_SEL) ? set : clr);
+                       printf("pmrctl  : %x\n", pmrctl);
+                       nvme_show_registers_pmrctl(pmrctl);
 
-       if ((effect & NVME_CMD_EFFECTS_CSE_MASK) >> 16 == 0)
-               printf("  No command restriction\n");
-       else if ((effect & NVME_CMD_EFFECTS_CSE_MASK) >> 16 == 1)
-               printf("  No other command for same namespace\n");
-       else if ((effect & NVME_CMD_EFFECTS_CSE_MASK) >> 16 == 2)
-               printf("  No other command for any namespace\n");
-       else
-               printf("  Reserved CSE\n");
-}
+                       printf("pmrsts  : %x\n", pmrsts);
+                       nvme_show_registers_pmrsts(pmrsts, pmrctl);
 
-static const char *nvme_cmd_to_string(int admin, __u8 opcode)
-{
-       if (admin) {
-               switch (opcode) {
-               case nvme_admin_delete_sq:      return "Delete I/O Submission Queue";
-               case nvme_admin_create_sq:      return "Create I/O Submission Queue";
-               case nvme_admin_get_log_page:   return "Get Log Page";
-               case nvme_admin_delete_cq:      return "Delete I/O Completion Queue";
-               case nvme_admin_create_cq:      return "Create I/O Completion Queue";
-               case nvme_admin_identify:       return "Identify";
-               case nvme_admin_abort_cmd:      return "Abort";
-               case nvme_admin_set_features:   return "Set Features";
-               case nvme_admin_get_features:   return "Get Features";
-               case nvme_admin_async_event:    return "Asynchronous Event Request";
-               case nvme_admin_ns_mgmt:        return "Namespace Management";
-               case nvme_admin_activate_fw:    return "Firmware Commit";
-               case nvme_admin_download_fw:    return "Firmware Image Download";
-               case nvme_admin_dev_self_test:  return "Device Self-test";
-               case nvme_admin_ns_attach:      return "Namespace Attachment";
-               case nvme_admin_keep_alive:     return "Keep Alive";
-               case nvme_admin_directive_send: return "Directive Send";
-               case nvme_admin_directive_recv: return "Directive Receive";
-               case nvme_admin_virtual_mgmt:   return "Virtualization Management";
-               case nvme_admin_nvme_mi_send:   return "NVMEe-MI Send";
-               case nvme_admin_nvme_mi_recv:   return "NVMEe-MI Receive";
-               case nvme_admin_dbbuf:          return "Doorbell Buffer Config";
-               case nvme_admin_format_nvm:     return "Format NVM";
-               case nvme_admin_security_send:  return "Security Send";
-               case nvme_admin_security_recv:  return "Security Receive";
-               case nvme_admin_sanitize_nvm:   return "Sanitize";
+                       printf("pmrebs  : %x\n", pmrebs);
+                       nvme_show_registers_pmrebs(pmrebs);
+
+                       printf("pmrswtp : %x\n", pmrswtp);
+                       nvme_show_registers_pmrswtp(pmrswtp);
+
+                       printf("pmrmsc  : %"PRIx64"\n", pmrmsc);
+                       nvme_show_registers_pmrmsc(pmrmsc);
                }
        } else {
-               switch (opcode) {
-               case nvme_cmd_flush:            return "Flush";
-               case nvme_cmd_write:            return "Write";
-               case nvme_cmd_read:             return "Read";
-               case nvme_cmd_write_uncor:      return "Write Uncorrectable";
-               case nvme_cmd_compare:          return "Compare";
-               case nvme_cmd_write_zeroes:     return "Write Zeroes";
-               case nvme_cmd_dsm:              return "Dataset Management";
-               case nvme_cmd_resv_register:    return "Reservation Register";
-               case nvme_cmd_resv_report:      return "Reservation Report";
-               case nvme_cmd_resv_acquire:     return "Reservation Acquire";
-               case nvme_cmd_resv_release:     return "Reservation Release";
+               if (cap != 0xffffffff)
+                       printf("cap     : %"PRIx64"\n", cap);
+               if (vs != 0xffffffff)
+                       printf("version : %x\n", vs);
+               if (cc != 0xffffffff)
+                       printf("cc      : %x\n", cc);
+               if (csts != 0xffffffff)
+                       printf("csts    : %x\n", csts);
+               if (nssr != 0xffffffff)
+                       printf("nssr    : %x\n", nssr);
+               if (!fabrics) {
+                       printf("intms   : %x\n", intms);
+                       printf("intmc   : %x\n", intmc);
+                       printf("aqa     : %x\n", aqa);
+                       printf("asq     : %"PRIx64"\n", asq);
+                       printf("acq     : %"PRIx64"\n", acq);
+                       printf("cmbloc  : %x\n", cmbloc);
+                       printf("cmbsz   : %x\n", cmbsz);
+                       printf("bpinfo  : %x\n", bpinfo);
+                       printf("bprsel  : %x\n", bprsel);
+                       printf("bpmbl   : %"PRIx64"\n", bpmbl);
+                       printf("cmbmsc  : %"PRIx64"\n", cmbmsc);
+                       printf("cmbsts  : %x\n", cmbsts);
+                       printf("pmrcap  : %x\n", pmrcap);
+                       printf("pmrctl  : %x\n", pmrctl);
+                       printf("pmrsts  : %x\n", pmrsts);
+                       printf("pmrebs  : %x\n", pmrebs);
+                       printf("pmrswtp : %x\n", pmrswtp);
+                       printf("pmrmsc  : %"PRIx64"\n", pmrmsc);
                }
        }
-
-       return "Unknown";
 }
 
-void show_effects_log(struct nvme_effects_log_page *effects, unsigned int flags)
+void nvme_show_single_property(int offset, uint64_t value64, int human)
 {
-       int i;
-       int human = flags & HUMAN;
-       __u32 effect;
+       uint32_t value32;
 
-       printf("Admin Command Set\n");
-       for (i = 0; i < 256; i++) {
-               effect = le32_to_cpu(effects->acs[i]);
-               if (effect & NVME_CMD_EFFECTS_CSUPP) {
-                       printf("ACS%-6d[%-32s] %08x", i,
-                                       nvme_cmd_to_string(1, i), effect);
-                       if (human)
-                               show_effects_log_human(effect);
-                       else
-                               printf("\n");
-               }
-       }
-       printf("\nNVM Command Set\n");
-       for (i = 0; i < 256; i++) {
-               effect = le32_to_cpu(effects->iocs[i]);
-               if (effect & NVME_CMD_EFFECTS_CSUPP) {
-                       printf("IOCS%-5d[%-32s] %08x", i,
-                                       nvme_cmd_to_string(0, i), effect);
-                       if (human)
-                               show_effects_log_human(effect);
-                       else
-                               printf("\n");
-               }
+       if (!human) {
+               if (is_64bit_reg(offset))
+                       printf("property: 0x%02x (%s), value: %"PRIx64"\n", offset,
+                                  nvme_register_to_string(offset), value64);
+               else
+                       printf("property: 0x%02x (%s), value: %x\n", offset,
+                                  nvme_register_to_string(offset),
+                                  (uint32_t) value64);
+
+               return;
        }
-}
 
-uint64_t int48_to_long(__u8 *data)
-{
-       int i;
-       uint64_t result = 0;
+       value32 = (uint32_t) value64;
 
-       for (i = 0; i < 6; i++) {
-               result *= 256;
-               result += data[5 - i];
-       }
-       return result;
-}
+       switch (offset) {
+       case NVME_REG_CAP:
+               printf("cap : %"PRIx64"\n", value64);
+               nvme_show_registers_cap((struct nvme_bar_cap *)&value64);
+               break;
 
-void show_endurance_log(struct nvme_endurance_group_log *endurance_group,
-                       __u16 group_id, const char *devname)
-{
-       printf("Endurance Group Log for NVME device:%s Group ID:%x\n", devname, group_id);
-       printf("critical warning        : %u\n", endurance_group->critical_warning);
-       printf("avl_spare               : %u\n", endurance_group->avl_spare);
-       printf("avl_spare_threshold     : %u\n", endurance_group->avl_spare_threshold);
-       printf("percent_used            : %u%%\n", endurance_group->percent_used);
-       printf("endurance_estimate      : %'.0Lf\n",
-               int128_to_double(endurance_group->endurance_estimate));
-       printf("data_units_read         : %'.0Lf\n",
-               int128_to_double(endurance_group->data_units_read));
-       printf("data_units_written      : %'.0Lf\n",
-               int128_to_double(endurance_group->data_units_written));
-       printf("media_units_written     : %'.0Lf\n",
-               int128_to_double(endurance_group->media_units_written));
-       printf("host_read_cmds          : %'.0Lf\n",
-               int128_to_double(endurance_group->host_read_cmds));
-       printf("host_write_cmds         : %'.0Lf\n",
-               int128_to_double(endurance_group->host_write_cmds));
-       printf("media_data_integrity_err: %'.0Lf\n",
-               int128_to_double(endurance_group->media_data_integrity_err));
-       printf("num_err_info_log_entries: %'.0Lf\n",
-               int128_to_double(endurance_group->num_err_info_log_entries));
-}
+       case NVME_REG_VS:
+               printf("version : %x\n", value32);
+               nvme_show_registers_version(value32);
+               break;
 
-void show_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname)
-{
-       /* convert temperature from Kelvin to Celsius */
-       int temperature = ((smart->temperature[1] << 8) |
-               smart->temperature[0]) - 273;
-       int i;
+       case NVME_REG_CC:
+               printf("cc : %x\n", value32);
+               nvme_show_registers_cc(value32);
+               break;
 
-       printf("Smart Log for NVME device:%s namespace-id:%x\n", devname, nsid);
-       printf("critical_warning                        : %#x\n", smart->critical_warning);
-       printf("temperature                             : %d C\n", temperature);
-       printf("available_spare                         : %u%%\n", smart->avail_spare);
-       printf("available_spare_threshold               : %u%%\n", smart->spare_thresh);
-       printf("percentage_used                         : %u%%\n", smart->percent_used);
-       printf("endurance group critical warning summary: %#x\n", smart->endu_grp_crit_warn_sumry);
-       printf("data_units_read                         : %'.0Lf\n",
-               int128_to_double(smart->data_units_read));
-       printf("data_units_written                      : %'.0Lf\n",
-               int128_to_double(smart->data_units_written));
-       printf("host_read_commands                      : %'.0Lf\n",
-               int128_to_double(smart->host_reads));
-       printf("host_write_commands                     : %'.0Lf\n",
-               int128_to_double(smart->host_writes));
-       printf("controller_busy_time                    : %'.0Lf\n",
-               int128_to_double(smart->ctrl_busy_time));
-       printf("power_cycles                            : %'.0Lf\n",
-               int128_to_double(smart->power_cycles));
-       printf("power_on_hours                          : %'.0Lf\n",
-               int128_to_double(smart->power_on_hours));
-       printf("unsafe_shutdowns                        : %'.0Lf\n",
-               int128_to_double(smart->unsafe_shutdowns));
-       printf("media_errors                            : %'.0Lf\n",
-               int128_to_double(smart->media_errors));
-       printf("num_err_log_entries                     : %'.0Lf\n",
-               int128_to_double(smart->num_err_log_entries));
-       printf("Warning Temperature Time                : %u\n", le32_to_cpu(smart->warning_temp_time));
-       printf("Critical Composite Temperature Time     : %u\n", le32_to_cpu(smart->critical_comp_time));
-       for (i = 0; i < 8; i++) {
-               __s32 temp = le16_to_cpu(smart->temp_sensor[i]);
+       case NVME_REG_CSTS:
+               printf("csts : %x\n", value32);
+               nvme_show_registers_csts(value32);
+               break;
 
-               if (temp == 0)
-                       continue;
-               printf("Temperature Sensor %d           : %d C\n", i + 1,
-                       temp - 273);
+       case NVME_REG_NSSR:
+               printf("nssr : %x\n", value32);
+               printf("\tNVM Subsystem Reset Control (NSSRC): %u\n\n", value32);
+               break;
+
+       default:
+               printf("unknown property: 0x%02x (%s), value: %"PRIx64"\n", offset,
+                          nvme_register_to_string(offset), value64);
+               break;
        }
-       printf("Thermal Management T1 Trans Count       : %u\n", le32_to_cpu(smart->thm_temp1_trans_count));
-       printf("Thermal Management T2 Trans Count       : %u\n", le32_to_cpu(smart->thm_temp2_trans_count));
-       printf("Thermal Management T1 Total Time        : %u\n", le32_to_cpu(smart->thm_temp1_total_time));
-       printf("Thermal Management T2 Total Time        : %u\n", le32_to_cpu(smart->thm_temp2_total_time));
 }
 
-void show_ana_log(struct nvme_ana_rsp_hdr *ana_log, const char *devname)
+void nvme_show_relatives(const char *name)
 {
-       int offset = sizeof(struct nvme_ana_rsp_hdr);
-       struct nvme_ana_rsp_hdr *hdr = ana_log;
-       struct nvme_ana_group_desc *desc;
-       size_t nsid_buf_size;
-       void *base = ana_log;
-       __u32 nr_nsids;
-       int i;
-       int j;
+       unsigned id, i, nsid = NVME_NSID_ALL;
+       char *path = NULL;
+       bool block = true;
+       int ret;
 
-       printf("Asynchronous Namespace Access Log for NVMe device: %s\n",
-                       devname);
-       printf("ANA LOG HEADER :-\n");
-       printf("chgcnt  :       %"PRIu64"\n",
-                       le64_to_cpu(hdr->chgcnt));
-       printf("ngrps   :       %u\n", le16_to_cpu(hdr->ngrps));
-       printf("ANA Log Desc :-\n");
+       ret = sscanf(name, "nvme%dn%d", &id, &nsid);
+       switch (ret) {
+       case 1:
+               if (asprintf(&path, "/sys/class/nvme/%s", name) < 0)
+                       path = NULL;
+               block = false;
+               break;
+       case 2:
+               if (asprintf(&path, "/sys/block/%s/device", name) < 0)
+                       path = NULL;
+               break;
+       default:
+               return;
+       }
 
-       for (i = 0; i < le16_to_cpu(ana_log->ngrps); i++) {
-               desc = base + offset;
-               nr_nsids = le32_to_cpu(desc->nnsids);
-               nsid_buf_size = nr_nsids * sizeof(__le32);
+       if (!path)
+               return;
 
-               offset += sizeof(*desc);
-               printf("grpid   :       %u\n", le32_to_cpu(desc->grpid));
-               printf("nnsids  :       %u\n", le32_to_cpu(desc->nnsids));
-               printf("chgcnt  :       %"PRIu64"\n",
-                      le64_to_cpu(desc->chgcnt));
-               printf("state   :       %s\n",
-                               nvme_ana_state_to_string(desc->state));
-               for (j = 0; j < le32_to_cpu(desc->nnsids); j++)
-                       printf("        nsid    :       %u\n",
-                                       le32_to_cpu(desc->nsids[j]));
-               printf("\n");
-               offset += nsid_buf_size;
-       }
-}
+       if (block) {
+               char *subsysnqn;
+               struct subsys_list_item *slist;
+               int subcnt = 0;
 
-void show_self_test_log(struct nvme_self_test_log *self_test, const char *devname)
-{
-       int i, temp;
-       const char *test_code_res;
-       static const char *const test_res[] = {
-               "Operation completed without error",
-               "Operation was aborted by a Device Self-test command",
-               "Operation was aborted by a Controller Level Reset",
-               "Operation was aborted due to a removal of a namespace from the namespace inventory",
-               "Operation was aborted due to the processing of a Format NVM command",
-               "A fatal error or unknown test error occurred while the controller was executing the"\
-               " device self-test operation and the operation did not complete",
-               "Operation completed with a segment that failed and the segment that failed is not known",
-               "Operation completed with one or more failed segments and the first segment that failed "\
-               "is indicated in the SegmentNumber field",
-               "Operation was aborted for unknown reason",
-               "Operation was aborted due to a sanitize operation",
-               "Reserved"
-       };
+               subsysnqn = get_nvme_subsnqn(path);
+               if (!subsysnqn)
+                       return;
+               slist = get_subsys_list(&subcnt, subsysnqn, nsid);
+               if (subcnt != 1) {
+                       free(subsysnqn);
+                       free(path);
+                       return;
+               }
 
-       printf("Device Self Test Log for NVME device:%s\n", devname);
-       printf("Current operation : %#x\n", self_test->crnt_dev_selftest_oprn);
-       printf("Current Completion : %u%%\n", self_test->crnt_dev_selftest_compln);
-       for (i = 0; i < NVME_SELF_TEST_REPORTS; i++) {
-               temp = self_test->result[i].device_self_test_status & 0xf;
-               if (temp == 0xf)
-                       continue;
+               fprintf(stderr, "Namespace %s has parent controller(s):", name);
+               for (i = 0; i < slist[0].nctrls; i++)
+                       fprintf(stderr, "%s%s", i ? ", " : "", slist[0].ctrls[i].name);
+               fprintf(stderr, "\n\n");
+               free(subsysnqn);
+       } else {
+               struct dirent **paths;
+               bool comma = false;
+               int n, ns, cntlid;
 
-               printf("Result[%d]:\n", i);
-               printf("  Test Result                  : %#x %s\n", temp,
-                       test_res[temp > 10 ? 10 : temp]);
+               n = scandir(path, &paths, scan_ctrl_paths_filter, alphasort);
+               if (n < 0) {
+                       free(path);
+                       return;
+               }
 
-               temp = self_test->result[i].device_self_test_status >> 4;
-               switch (temp) {
-               case 1:
-                       test_code_res = "Short device self-test operation";
-                       break;
-               case 2:
-                       test_code_res = "Extended device self-test operation";
-                       break;
-               case 0xe:
-                       test_code_res = "Vendor specific";
-                       break;
-               default :
-                       test_code_res = "Reserved";
-                       break;
+               fprintf(stderr, "Controller %s has child namespace(s):", name);
+               for (i = 0; i < n; i++) {
+                       if (sscanf(paths[i]->d_name, "nvme%dc%dn%d",
+                                  &id, &cntlid, &ns) != 3) {
+                               if (sscanf(paths[i]->d_name, "nvme%dn%d",
+                                          &id, &ns) != 2) {
+                                       continue;
+                               }
+                       }
+                       fprintf(stderr, "%snvme%dn%d", comma ? ", " : "", id, ns);
+                       comma = true;
                }
-               printf("  Test Code                    : %#x %s\n", temp,
-                       test_code_res);
-               if (temp == 7)
-                       printf("  Segment number               : %#x\n",
-                               self_test->result[i].segment_num);
+               fprintf(stderr, "\n\n");
+               free(paths);
+       }
+       free(path);
+}
 
-               temp = self_test->result[i].valid_diagnostic_info;
-               printf("  Valid Diagnostic Information : %#x\n", temp);
-               printf("  Power on hours (POH)         : %#"PRIx64"\n",
-                       le64_to_cpu(self_test->result[i].power_on_hours));
+void d(unsigned char *buf, int len, int width, int group)
+{
+       int i, offset = 0, line_done = 0;
+       char ascii[32 + 1];
 
-               if (temp & NVME_SELF_TEST_VALID_NSID)
-                       printf("  Namespace Identifier         : %#x\n",
-                               le32_to_cpu(self_test->result[i].nsid));
-               if (temp & NVME_SELF_TEST_VALID_FLBA)
-                       printf("  Failing LBA                  : %#"PRIx64"\n",
-                               le64_to_cpu(self_test->result[i].failing_lba));
-               if (temp & NVME_SELF_TEST_VALID_SCT)
-                       printf("  Status Code Type             : %#x\n",
-                               self_test->result[i].status_code_type);
-               if (temp & NVME_SELF_TEST_VALID_SC)
-                       printf("  Status Code                  : %#x\n",
-                               self_test->result[i].status_code);
-               printf("  Vendor Specific                      : %x %x\n",
-                       self_test->result[i].vendor_specific[0],
-                       self_test->result[i].vendor_specific[0]);
+       assert(width < sizeof(ascii));
+       printf("     ");
+       for (i = 0; i <= 15; i++)
+               printf("%3x", i);
+       for (i = 0; i < len; i++) {
+               line_done = 0;
+               if (i % width == 0)
+                       printf( "\n%04x:", offset);
+               if (i % group == 0)
+                       printf( " %02x", buf[i]);
+               else
+                       printf( "%02x", buf[i]);
+               ascii[i % width] = (buf[i] >= '!' && buf[i] <= '~') ? buf[i] : '.';
+               if (((i + 1) % width) == 0) {
+                       ascii[i % width + 1] = '\0';
+                       printf( " \"%.*s\"", width, ascii);
+                       offset += width;
+                       line_done = 1;
+               }
+       }
+       if (!line_done) {
+               unsigned b = width - (i % width);
+               ascii[i % width + 1] = '\0';
+               printf( " %*s \"%.*s\"",
+                               2 * b + b / group + (b % group ? 1 : 0), "",
+                               width, ascii);
        }
+       printf( "\n");
 }
 
-static void show_sanitize_log_sprog(__u32 sprog)
+void d_raw(unsigned char *buf, unsigned len)
 {
-       double percent;
+       unsigned i;
+       for (i = 0; i < len; i++)
+               putchar(*(buf+i));
+}
 
-       percent = (((double)sprog * 100) / 0x10000);
-       printf("\t(%f%%)\n", percent);
+void nvme_show_status(__u16 status)
+{
+       fprintf(stderr, "NVMe status: %s(%#x)\n",
+                       nvme_status_to_string(status), status);
 }
 
-static const char *get_sanitize_log_sstat_status_str(__u16 status)
+static void format(char *formatter, size_t fmt_sz, char *tofmt, size_t tofmtsz)
 {
-       const char *str;
 
-       switch (status & NVME_SANITIZE_LOG_STATUS_MASK) {
-       case NVME_SANITIZE_LOG_NEVER_SANITIZED:
-               str = "NVM Subsystem has never been sanitized.";
-               break;
-       case NVME_SANITIZE_LOG_COMPLETED_SUCCESS:
-               str = "Most Recent Sanitize Command Completed Successfully.";
-               break;
-       case NVME_SANITIZE_LOG_IN_PROGESS:
-               str = "Sanitize in Progress.";
-               break;
-       case NVME_SANITIZE_LOG_COMPLETED_FAILED:
-               str = "Most Recent Sanitize Command Failed.";
-               break;
-       case NVME_SANITIZE_LOG_ND_COMPLETED_SUCCESS:
-               str = "Most Recent Sanitize Command (No-Deallocate After Sanitize) Completed Successfully.";
-               break;
-       default:
-               str = "Unknown.";
+       fmt_sz = snprintf(formatter,fmt_sz, "%-*.*s",
+                (int)tofmtsz, (int)tofmtsz, tofmt);
+       /* trim() the obnoxious trailing white lines */
+       while (fmt_sz) {
+               if (formatter[fmt_sz - 1] != ' ' && formatter[fmt_sz - 1] != '\0') {
+                       formatter[fmt_sz] = '\0';
+                       break;
+               }
+               fmt_sz--;
+       }
+}
+
+static const char *nvme_uuid_to_string(uuid_t uuid)
+{
+       /* large enough to hold uuid str (37) + null-termination byte */
+       static char uuid_str[40];
+#ifdef LIBUUID
+       uuid_unparse_lower(uuid, uuid_str);
+#else
+       static const char *hex_digits = "0123456789abcdef";
+       char *p = &uuid_str[0];
+       int i;
+       for (i = 0; i < 16; i++) {
+               *p++ = hex_digits[(uuid.b[i] & 0xf0) >> 4];
+               *p++ = hex_digits[uuid.b[i] & 0x0f];
+               if (i == 3 || i == 5 || i == 7 || i == 9)
+                       *p++ = '-';
        }
-
-       return str;
+       *p = '\0';
+#endif
+       return uuid_str;
 }
 
-static void show_sanitize_log_sstat(__u16 status)
+static void nvme_show_id_ctrl_cmic(__u8 cmic)
 {
-       const char *str = get_sanitize_log_sstat_status_str(status);
-
-       printf("\t[2:0]\t%s\n", str);
-       str = "Number of completed passes if most recent operation was overwrite";
-       printf("\t[7:3]\t%s:\t%u\n", str, (status & NVME_SANITIZE_LOG_NUM_CMPLTED_PASS_MASK) >> 3);
-
-       printf("\t  [8]\t");
-       if (status & NVME_SANITIZE_LOG_GLOBAL_DATA_ERASED)
-               str = "Global Data Erased set: no NS LB in the NVM subsystem has been written to "\
-                     "and no PMR in the NVM subsystem has been enabled";
-       else
-               str = "Global Data Erased cleared: a NS LB in the NVM subsystem has been written to "\
-                     "or  a PMR in the NVM subsystem has been enabled";
-       printf("%s\n", str);
+       __u8 rsvd = (cmic & 0xF0) >> 4;
+       __u8 ana = (cmic & 0x8) >> 3;
+       __u8 sriov = (cmic & 0x4) >> 2;
+       __u8 mctl = (cmic & 0x2) >> 1;
+       __u8 mp = cmic & 0x1;
+       if (rsvd)
+               printf("  [7:4] : %#x\tReserved\n", rsvd);
+       printf("  [3:3] : %#x\tANA %ssupported\n", ana, ana ? "" : "not ");
+       printf("  [2:2] : %#x\t%s\n", sriov, sriov ? "SR-IOV" : "PCI");
+       printf("  [1:1] : %#x\t%s Controller\n",
+               mctl, mctl ? "Multi" : "Single");
+       printf("  [0:0] : %#x\t%s Port\n", mp, mp ? "Multi" : "Single");
+       printf("\n");
 }
 
-static void show_estimate_sanitize_time(const char *text, uint32_t value)
+static void nvme_show_id_ctrl_oaes(__le32 ctrl_oaes)
 {
-       if (value == 0xffffffff)
-               printf("%s:  0xffffffff (No time period reported)\n", text);
-       else
-               printf("%s:  %u\n", text, value);
+       __u32 oaes = le32_to_cpu(ctrl_oaes);
+       __u32 rsvd0 = (oaes & 0xFFFF8000) >> 15;
+       __u32 nace = (oaes & 0x100) >> 8;
+       __u32 fan = (oaes & 0x200) >> 9;
+       __u32 anacn = (oaes & 800) >> 11;
+       __u32 plealcn = (oaes & 0x1000) >> 12;
+       __u32 lbasin = (oaes & 0x2000) >> 13;
+       __u32 egealpcn = (oaes & 0x4000) >> 14;
+       __u32 rsvd1 = oaes & 0xFF;
+
+       if (rsvd0)
+               printf(" [31:10] : %#x\tReserved\n", rsvd0);
+       printf("[14:14] : %#x\tEndurance Group Event Aggregate Log Page"\
+                       " Change Notice %sSupported\n",
+                       egealpcn, egealpcn ? "" : "Not ");
+       printf("[13:13] : %#x\tLBA Status Information Notices %sSupported\n",
+                       lbasin, lbasin ? "" : "Not ");
+       printf("[12:12] : %#x\tPredictable Latency Event Aggregate Log Change"\
+                       " Notices %sSupported\n",
+                       plealcn, plealcn ? "" : "Not ");
+       printf("[11:11] : %#x\tAsymmetric Namespace Access Change Notices"\
+                       " %sSupported\n", anacn, anacn ? "" : "Not ");
+       printf("  [9:9] : %#x\tFirmware Activation Notices %sSupported\n",
+               fan, fan ? "" : "Not ");
+       printf("  [8:8] : %#x\tNamespace Attribute Changed Event %sSupported\n",
+               nace, nace ? "" : "Not ");
+       if (rsvd1)
+               printf("  [7:0] : %#x\tReserved\n", rsvd1);
+       printf("\n");
 }
 
-void show_sanitize_log(struct nvme_sanitize_log_page *sanitize, unsigned int mode, const char *devname)
+static void nvme_show_id_ctrl_ctratt(__le32 ctrl_ctratt)
 {
-       int human = mode & HUMAN;
-       __u16 status = le16_to_cpu(sanitize->status) & NVME_SANITIZE_LOG_STATUS_MASK;
-
-       printf("Sanitize Progress                      (SPROG) :  %u",
-              le16_to_cpu(sanitize->progress));
-       if (human && status == NVME_SANITIZE_LOG_IN_PROGESS)
-               show_sanitize_log_sprog(le16_to_cpu(sanitize->progress));
-       else
-               printf("\n");
+       __u32 ctratt = le32_to_cpu(ctrl_ctratt);
+       __u32 rsvd = ctratt >> 10;
+       __u32 hostid128 = (ctratt & NVME_CTRL_CTRATT_128_ID) >> 0;
+       __u32 psp = (ctratt & NVME_CTRL_CTRATT_NON_OP_PSP) >> 1;
+       __u32 sets = (ctratt & NVME_CTRL_CTRATT_NVM_SETS) >> 2;
+       __u32 rrl = (ctratt & NVME_CTRL_CTRATT_READ_RECV_LVLS) >> 3;
+       __u32 eg = (ctratt & NVME_CTRL_CTRATT_ENDURANCE_GROUPS) >> 4;
+       __u32 iod = (ctratt & NVME_CTRL_CTRATT_PREDICTABLE_LAT) >> 5;
+       __u32 ng = (ctratt & NVME_CTRL_CTRATT_NAMESPACE_GRANULARITY) >> 7;
+       __u32 uuidlist = (ctratt & NVME_CTRL_CTRATT_UUID_LIST) >> 9;
+       __u32 rsvd6 = (ctratt & 0x00000040) >> 6;
+       __u32 rsvd8 = (ctratt & 0x00000100) >> 8;
 
-       printf("Sanitize Status                        (SSTAT) :  %#x\n", le16_to_cpu(sanitize->status));
-       if (human)
-               show_sanitize_log_sstat(le16_to_cpu(sanitize->status));
+       if (rsvd)
+               printf(" [31:10] : %#x\tReserved\n", rsvd);
 
-       printf("Sanitize Command Dword 10 Information (SCDW10) :  %#x\n", le32_to_cpu(sanitize->cdw10_info));
-       show_estimate_sanitize_time("Estimated Time For Overwrite                   ", le32_to_cpu(sanitize->est_ovrwrt_time));
-       show_estimate_sanitize_time("Estimated Time For Block Erase                 ", le32_to_cpu(sanitize->est_blk_erase_time));
-       show_estimate_sanitize_time("Estimated Time For Crypto Erase                ", le32_to_cpu(sanitize->est_crypto_erase_time));
-       show_estimate_sanitize_time("Estimated Time For Overwrite (No-Deallocate)   ", le32_to_cpu(sanitize->est_ovrwrt_time_with_no_deallocate));
-       show_estimate_sanitize_time("Estimated Time For Block Erase (No-Deallocate) ", le32_to_cpu(sanitize->est_blk_erase_time_with_no_deallocate));
-       show_estimate_sanitize_time("Estimated Time For Crypto Erase (No-Deallocate)", le32_to_cpu(sanitize->est_crypto_erase_time_with_no_deallocate));
+       printf("  [9:9] : %#x\tUUID List %sSupported\n",
+               uuidlist, uuidlist ? "" : "Not ");
+       if (rsvd8)
+               printf(" [8:8] : %#x\tReserved\n", rsvd8);
+       printf("  [7:7] : %#x\tNamespace Granularity %sSupported\n",
+               ng, ng ? "" : "Not ");
+       if (rsvd6)
+               printf(" [6:6] : %#x\tReserved\n", rsvd6);
+       printf("  [5:5] : %#x\tPredictable Latency Mode %sSupported\n",
+               iod, iod ? "" : "Not ");
+       printf("  [4:4] : %#x\tEndurance Groups %sSupported\n",
+               eg, eg ? "" : "Not ");
+       printf("  [3:3] : %#x\tRead Recovery Levels %sSupported\n",
+               rrl, rrl ? "" : "Not ");
+       printf("  [2:2] : %#x\tNVM Sets %sSupported\n",
+               sets, sets ? "" : "Not ");
+       printf("  [1:1] : %#x\tNon-Operational Power State Permissive %sSupported\n",
+               psp, psp ? "" : "Not ");
+       printf("  [0:0] : %#x\t128-bit Host Identifier %sSupported\n",
+               hostid128, hostid128 ? "" : "Not ");
+       printf("\n");
 }
 
-const char *nvme_feature_to_string(int feature)
+static void nvme_show_id_ctrl_cntrltype(__u8 cntrltype)
 {
-       switch (feature) {
-       case NVME_FEAT_ARBITRATION:     return "Arbitration";
-       case NVME_FEAT_POWER_MGMT:      return "Power Management";
-       case NVME_FEAT_LBA_RANGE:       return "LBA Range Type";
-       case NVME_FEAT_TEMP_THRESH:     return "Temperature Threshold";
-       case NVME_FEAT_ERR_RECOVERY:    return "Error Recovery";
-       case NVME_FEAT_VOLATILE_WC:     return "Volatile Write Cache";
-       case NVME_FEAT_NUM_QUEUES:      return "Number of Queues";
-       case NVME_FEAT_IRQ_COALESCE:    return "Interrupt Coalescing";
-       case NVME_FEAT_IRQ_CONFIG:      return "Interrupt Vector Configuration";
-       case NVME_FEAT_WRITE_ATOMIC:    return "Write Atomicity Normal";
-       case NVME_FEAT_ASYNC_EVENT:     return "Async Event Configuration";
-       case NVME_FEAT_AUTO_PST:        return "Autonomous Power State Transition";
-       case NVME_FEAT_HOST_MEM_BUF:    return "Host Memory Buffer";
-       case NVME_FEAT_KATO:            return "Keep Alive Timer";
-       case NVME_FEAT_NOPSC:           return "Non-Operational Power State Config";
-       case NVME_FEAT_RRL:             return "Read Recovery Level";
-       case NVME_FEAT_PLM_CONFIG:      return "Predicatable Latency Mode Config";
-       case NVME_FEAT_PLM_WINDOW:      return "Predicatable Latency Mode Window";
-       case NVME_FEAT_SW_PROGRESS:     return "Software Progress";
-       case NVME_FEAT_HOST_ID:         return "Host Identifier";
-       case NVME_FEAT_RESV_MASK:       return "Reservation Notification Mask";
-       case NVME_FEAT_RESV_PERSIST:    return "Reservation Persistence";
-       case NVME_FEAT_TIMESTAMP:       return "Timestamp";
-       case NVME_FEAT_WRITE_PROTECT:   return "Namespce Write Protect";
-       case NVME_FEAT_HCTM:            return "Host Controlled Thermal Management";
-       case NVME_FEAT_HOST_BEHAVIOR:   return "Host Behavior";
-       case NVME_FEAT_SANITIZE:        return "Sanitize";
-       default:                        return "Unknown";
-       }
+       __u8 rsvd = (cntrltype & 0xFC) >> 2;
+       __u8 cntrl = cntrltype & 0x3;
+
+       static const char *type[] = {
+               "Controller type not reported",
+               "I/O Controller",
+               "Discovery Controller",
+               "Administrative Controller"
+       };
+
+       printf("  [7:2] : %#x\tReserved\n", rsvd);
+       printf("  [1:0] : %#x\t%s\n", cntrltype, type[cntrl]);
 }
 
-const char *nvme_register_to_string(int reg)
+static void nvme_show_id_ctrl_oacs(__le16 ctrl_oacs)
 {
-       switch (reg) {
-       case NVME_REG_CAP:      return "Controller Capabilities";
-       case NVME_REG_VS:       return "Version";
-       case NVME_REG_INTMS:    return "Interrupt Vector Mask Set";
-       case NVME_REG_INTMC:    return "Interrupt Vector Mask Clear";
-       case NVME_REG_CC:       return "Controller Configuration";
-       case NVME_REG_CSTS:     return "Controller Status";
-       case NVME_REG_NSSR:     return "NVM Subsystem Reset";
-       case NVME_REG_AQA:      return "Admin Queue Attributes";
-       case NVME_REG_ASQ:      return "Admin Submission Queue Base Address";
-       case NVME_REG_ACQ:      return "Admin Completion Queue Base Address";
-       case NVME_REG_CMBLOC:   return "Controller Memory Buffer Location";
-       case NVME_REG_CMBSZ:    return "Controller Memory Buffer Size";
-       default:                        return "Unknown";
-       }
+       __u16 oacs = le16_to_cpu(ctrl_oacs);
+       __u16 rsvd = (oacs & 0xFC00) >> 10;
+       __u16 glbas = (oacs & 0x200) >> 9;
+       __u16 dbc = (oacs & 0x100) >> 8;
+       __u16 vir = (oacs & 0x80) >> 7;
+       __u16 nmi = (oacs & 0x40) >> 6;
+       __u16 dir = (oacs & 0x20) >> 5;
+       __u16 sft = (oacs & 0x10) >> 4;
+       __u16 nsm = (oacs & 0x8) >> 3;
+       __u16 fwc = (oacs & 0x4) >> 2;
+       __u16 fmt = (oacs & 0x2) >> 1;
+       __u16 sec = oacs & 0x1;
+
+       if (rsvd)
+               printf(" [15:9] : %#x\tReserved\n", rsvd);
+       printf("  [9:9] : %#x\tGet LBA Status Capability %sSupported\n",
+               glbas, glbas ? "" : "Not ");
+       printf("  [8:8] : %#x\tDoorbell Buffer Config %sSupported\n",
+               dbc, dbc ? "" : "Not ");
+       printf("  [7:7] : %#x\tVirtualization Management %sSupported\n",
+               vir, vir ? "" : "Not ");
+       printf("  [6:6] : %#x\tNVMe-MI Send and Receive %sSupported\n",
+               nmi, nmi ? "" : "Not ");
+       printf("  [5:5] : %#x\tDirectives %sSupported\n",
+               dir, dir ? "" : "Not ");
+       printf("  [4:4] : %#x\tDevice Self-test %sSupported\n",
+               sft, sft ? "" : "Not ");
+       printf("  [3:3] : %#x\tNS Management and Attachment %sSupported\n",
+               nsm, nsm ? "" : "Not ");
+       printf("  [2:2] : %#x\tFW Commit and Download %sSupported\n",
+               fwc, fwc ? "" : "Not ");
+       printf("  [1:1] : %#x\tFormat NVM %sSupported\n",
+               fmt, fmt ? "" : "Not ");
+       printf("  [0:0] : %#x\tSecurity Send and Receive %sSupported\n",
+               sec, sec ? "" : "Not ");
+       printf("\n");
 }
 
-const char *nvme_select_to_string(int sel)
+static void nvme_show_id_ctrl_frmw(__u8 frmw)
 {
-       switch (sel) {
-       case 0:  return "Current";
-       case 1:  return "Default";
-       case 2:  return "Saved";
-       case 3:  return "Supported capabilities";
-       default: return "Reserved";
-       }
+       __u8 rsvd = (frmw & 0xE0) >> 5;
+       __u8 fawr = (frmw & 0x10) >> 4;
+       __u8 nfws = (frmw & 0xE) >> 1;
+       __u8 s1ro = frmw & 0x1;
+       if (rsvd)
+               printf("  [7:5] : %#x\tReserved\n", rsvd);
+       printf("  [4:4] : %#x\tFirmware Activate Without Reset %sSupported\n",
+               fawr, fawr ? "" : "Not ");
+       printf("  [3:1] : %#x\tNumber of Firmware Slots\n", nfws);
+       printf("  [0:0] : %#x\tFirmware Slot 1 Read%s\n",
+               s1ro, s1ro ? "-Only" : "/Write");
+       printf("\n");
 }
 
-void nvme_show_select_result(__u32 result)
+static void nvme_show_id_ctrl_lpa(__u8 lpa)
 {
-       if (result & 0x1)
-               printf("  Feature is saveable\n");
-       if (result & 0x2)
-               printf("  Feature is per-namespace\n");
-       if (result & 0x4)
-               printf("  Feature is changeable\n");
+       __u8 rsvd = (lpa & 0xE0) >> 5;
+       __u8 persevnt = (lpa & 0x10) >> 4;
+       __u8 telem = (lpa & 0x8) >> 3;
+       __u8 ed = (lpa & 0x4) >> 2;
+       __u8 celp = (lpa & 0x2) >> 1;
+       __u8 smlp = lpa & 0x1;
+       if (rsvd)
+               printf("  [7:4] : %#x\tReserved\n", rsvd);
+       printf("  [4:4] : %#x\tPersistent Event log %sSupported\n",
+                       persevnt, persevnt ? "" : "Not ");
+       printf("  [3:3] : %#x\tTelemetry host/controller initiated log page %sSupported\n",
+              telem, telem ? "" : "Not ");
+       printf("  [2:2] : %#x\tExtended data for Get Log Page %sSupported\n",
+               ed, ed ? "" : "Not ");
+       printf("  [1:1] : %#x\tCommand Effects Log Page %sSupported\n",
+               celp, celp ? "" : "Not ");
+       printf("  [0:0] : %#x\tSMART/Health Log Page per NS %sSupported\n",
+               smlp, smlp ? "" : "Not ");
+       printf("\n");
 }
 
-const char *nvme_status_to_string(__u32 status)
+static void nvme_show_id_ctrl_avscc(__u8 avscc)
 {
-       switch (status & 0x3ff) {
-       case NVME_SC_SUCCESS:                   return "SUCCESS: The command completed successfully";
-       case NVME_SC_INVALID_OPCODE:            return "INVALID_OPCODE: The associated command opcode field is not valid";
-       case NVME_SC_INVALID_FIELD:             return "INVALID_FIELD: A reserved coded value or an unsupported value in a defined field";
-       case NVME_SC_CMDID_CONFLICT:            return "CMDID_CONFLICT: The command identifier is already in use";
-       case NVME_SC_DATA_XFER_ERROR:           return "DATA_XFER_ERROR: Error while trying to transfer the data or metadata";
-       case NVME_SC_POWER_LOSS:                return "POWER_LOSS: Command aborted due to power loss notification";
-       case NVME_SC_INTERNAL:                  return "INTERNAL: The command was not completed successfully due to an internal error";
-       case NVME_SC_ABORT_REQ:                 return "ABORT_REQ: The command was aborted due to a Command Abort request";
-       case NVME_SC_ABORT_QUEUE:               return "ABORT_QUEUE: The command was aborted due to a Delete I/O Submission Queue request";
-       case NVME_SC_FUSED_FAIL:                return "FUSED_FAIL: The command was aborted due to the other command in a fused operation failing";
-       case NVME_SC_FUSED_MISSING:             return "FUSED_MISSING: The command was aborted due to a Missing Fused Command";
-       case NVME_SC_INVALID_NS:                return "INVALID_NS: The namespace or the format of that namespace is invalid";
-       case NVME_SC_CMD_SEQ_ERROR:             return "CMD_SEQ_ERROR: The command was aborted due to a protocol violation in a multicommand sequence";
-       case NVME_SC_SANITIZE_FAILED:           return "SANITIZE_FAILED: The most recent sanitize operation failed and no recovery actions has been successfully completed";
-       case NVME_SC_SANITIZE_IN_PROGRESS:      return "SANITIZE_IN_PROGRESS: The requested function is prohibited while a sanitize operation is in progress";
-       case NVME_SC_LBA_RANGE:                 return "LBA_RANGE: The command references a LBA that exceeds the size of the namespace";
-       case NVME_SC_NS_WRITE_PROTECTED:        return "NS_WRITE_PROTECTED: The command is prohibited while the namespace is write protected by the host.";
-       case NVME_SC_CAP_EXCEEDED:              return "CAP_EXCEEDED: The execution of the command has caused the capacity of the namespace to be exceeded";
-       case NVME_SC_NS_NOT_READY:              return "NS_NOT_READY: The namespace is not ready to be accessed as a result of a condition other than a condition that is reported as an Asymmetric Namespace Access condition";
-       case NVME_SC_RESERVATION_CONFLICT:      return "RESERVATION_CONFLICT: The command was aborted due to a conflict with a reservation held on the accessed namespace";
-       case NVME_SC_CQ_INVALID:                return "CQ_INVALID: The Completion Queue identifier specified in the command does not exist";
-       case NVME_SC_QID_INVALID:               return "QID_INVALID: The creation of the I/O Completion Queue failed due to an invalid queue identifier specified as part of the command. An invalid queue identifier is one that is currently in use or one that is outside the range supported by the controller";
-       case NVME_SC_QUEUE_SIZE:                return "QUEUE_SIZE: The host attempted to create an I/O Completion Queue with an invalid number of entries";
-       case NVME_SC_ABORT_LIMIT:               return "ABORT_LIMIT: The number of concurrently outstanding Abort commands has exceeded the limit indicated in the Identify Controller data structure";
-       case NVME_SC_ABORT_MISSING:             return "ABORT_MISSING: The abort command is missing";
-       case NVME_SC_ASYNC_LIMIT:               return "ASYNC_LIMIT: The number of concurrently outstanding Asynchronous Event Request commands has been exceeded";
-       case NVME_SC_FIRMWARE_SLOT:             return "FIRMWARE_SLOT: The firmware slot indicated is invalid or read only. This error is indicated if the firmware slot exceeds the number supported";
-       case NVME_SC_FIRMWARE_IMAGE:            return "FIRMWARE_IMAGE: The firmware image specified for activation is invalid and not loaded by the controller";
-       case NVME_SC_INVALID_VECTOR:            return "INVALID_VECTOR: The creation of the I/O Completion Queue failed due to an invalid interrupt vector specified as part of the command";
-       case NVME_SC_INVALID_LOG_PAGE:          return "INVALID_LOG_PAGE: The log page indicated is invalid. This error condition is also returned if a reserved log page is requested";
-       case NVME_SC_INVALID_FORMAT:            return "INVALID_FORMAT: The LBA Format specified is not supported. This may be due to various conditions";
-       case NVME_SC_FW_NEEDS_CONV_RESET:       return "FW_NEEDS_CONVENTIONAL_RESET: The firmware commit was successful, however, activation of the firmware image requires a conventional reset";
-       case NVME_SC_INVALID_QUEUE:             return "INVALID_QUEUE: This error indicates that it is invalid to delete the I/O Completion Queue specified. The typical reason for this error condition is that there is an associated I/O Submission Queue that has not been deleted.";
-       case NVME_SC_FEATURE_NOT_SAVEABLE:      return "FEATURE_NOT_SAVEABLE: The Feature Identifier specified does not support a saveable value";
-       case NVME_SC_FEATURE_NOT_CHANGEABLE:    return "FEATURE_NOT_CHANGEABLE: The Feature Identifier is not able to be changed";
-       case NVME_SC_FEATURE_NOT_PER_NS:        return "FEATURE_NOT_PER_NS: The Feature Identifier specified is not namespace specific. The Feature Identifier settings apply across all namespaces";
-       case NVME_SC_FW_NEEDS_SUBSYS_RESET:     return "FW_NEEDS_SUBSYSTEM_RESET: The firmware commit was successful, however, activation of the firmware image requires an NVM Subsystem";
-       case NVME_SC_FW_NEEDS_RESET:            return "FW_NEEDS_RESET: The firmware commit was successful; however, the image specified does not support being activated without a reset";
-       case NVME_SC_FW_NEEDS_MAX_TIME:         return "FW_NEEDS_MAX_TIME_VIOLATION: The image specified if activated immediately would exceed the Maximum Time for Firmware Activation (MTFA) value reported in Identify Controller. To activate the firmware, the Firmware Commit command needs to be re-issued and the image activated using a reset";
-       case NVME_SC_FW_ACTIVATE_PROHIBITED:    return "FW_ACTIVATION_PROHIBITED: The image specified is being prohibited from activation by the controller for vendor specific reasons";
-       case NVME_SC_OVERLAPPING_RANGE:         return "OVERLAPPING_RANGE: This error is indicated if the firmware image has overlapping ranges";
-       case NVME_SC_NS_INSUFFICIENT_CAP:       return "NS_INSUFFICIENT_CAPACITY: Creating the namespace requires more free space than is currently available. The Command Specific Information field of the Error Information Log specifies the total amount of NVM capacity required to create the namespace in bytes";
-       case NVME_SC_NS_ID_UNAVAILABLE:         return "NS_ID_UNAVAILABLE: The number of namespaces supported has been exceeded";
-       case NVME_SC_NS_ALREADY_ATTACHED:       return "NS_ALREADY_ATTACHED: The controller is already attached to the namespace specified";
-       case NVME_SC_NS_IS_PRIVATE:             return "NS_IS_PRIVATE: The namespace is private and is already attached to one controller";
-       case NVME_SC_NS_NOT_ATTACHED:           return "NS_NOT_ATTACHED: The request to detach the controller could not be completed because the controller is not attached to the namespace";
-       case NVME_SC_THIN_PROV_NOT_SUPP:        return "THIN_PROVISIONING_NOT_SUPPORTED: Thin provisioning is not supported by the controller";
-       case NVME_SC_CTRL_LIST_INVALID:         return "CONTROLLER_LIST_INVALID: The controller list provided is invalid";
-       case NVME_SC_BP_WRITE_PROHIBITED:       return "BOOT PARTITION WRITE PROHIBITED: The command is trying to modify a Boot Partition while it is locked";
-       case NVME_SC_BAD_ATTRIBUTES:            return "BAD_ATTRIBUTES: Bad attributes were given";
-       case NVME_SC_WRITE_FAULT:               return "WRITE_FAULT: The write data could not be committed to the media";
-       case NVME_SC_READ_ERROR:                return "READ_ERROR: The read data could not be recovered from the media";
-       case NVME_SC_GUARD_CHECK:               return "GUARD_CHECK: The command was aborted due to an end-to-end guard check failure";
-       case NVME_SC_APPTAG_CHECK:              return "APPTAG_CHECK: The command was aborted due to an end-to-end application tag check failure";
-       case NVME_SC_REFTAG_CHECK:              return "REFTAG_CHECK: The command was aborted due to an end-to-end reference tag check failure";
-       case NVME_SC_COMPARE_FAILED:            return "COMPARE_FAILED: The command failed due to a miscompare during a Compare command";
-       case NVME_SC_ACCESS_DENIED:             return "ACCESS_DENIED: Access to the namespace and/or LBA range is denied due to lack of access rights";
-       case NVME_SC_UNWRITTEN_BLOCK:           return "UNWRITTEN_BLOCK: The command failed due to an attempt to read from an LBA range containing a deallocated or unwritten logical block";
-       case NVME_SC_ANA_PERSISTENT_LOSS:       return "ASYMMETRIC_NAMESPACE_ACCESS_PERSISTENT_LOSS: The requested function (e.g., command) is not able to be performed as a result of the relationship between the controller and the namespace being in the ANA Persistent Loss state";
-       case NVME_SC_ANA_INACCESSIBLE:          return "ASYMMETRIC_NAMESPACE_ACCESS_INACCESSIBLE: The requested function (e.g., command) is not able to be performed as a result of the relationship between the controller and the namespace being in the ANA Inaccessible state";
-       case NVME_SC_ANA_TRANSITION:            return "ASYMMETRIC_NAMESPACE_ACCESS_TRANSITION: The requested function (e.g., command) is not able to be performed as a result of the relationship between the controller and the namespace transitioning between Asymmetric Namespace Access states";
-       case NVME_SC_CMD_INTERRUPTED:           return "CMD_INTERRUPTED: Command processing was interrupted and the controller is unable to successfully complete the command. The host should retry the command.";
-       case NVME_SC_PMR_SAN_PROHIBITED:        return "Sanitize Prohibited While Persistent Memory Region is Enabled: A sanitize operation is prohibited while the Persistent Memory Region is enabled.";
-       default:                                return "Unknown";
-       }
+       __u8 rsvd = (avscc & 0xFE) >> 1;
+       __u8 fmt = avscc & 0x1;
+       if (rsvd)
+               printf("  [7:1] : %#x\tReserved\n", rsvd);
+       printf("  [0:0] : %#x\tAdmin Vendor Specific Commands uses %s Format\n",
+               fmt, fmt ? "NVMe" : "Vendor Specific");
+       printf("\n");
 }
 
-static const char *nvme_feature_lba_type_to_string(__u8 type)
+static void nvme_show_id_ctrl_apsta(__u8 apsta)
 {
-       switch (type) {
-       case 0: return "Reserved";
-       case 1: return "Filesystem";
-       case 2: return "RAID";
-       case 3: return "Cache";
-       case 4: return "Page / Swap file";
-       default:
-               if (type>=0x05 && type<=0x7f)
-                       return "Reserved";
-               else
-                       return "Vendor Specific";
-       }
+       __u8 rsvd = (apsta & 0xFE) >> 1;
+       __u8 apst = apsta & 0x1;
+       if (rsvd)
+               printf("  [7:1] : %#x\tReserved\n", rsvd);
+       printf("  [0:0] : %#x\tAutonomous Power State Transitions %sSupported\n",
+               apst, apst ? "" : "Not ");
+       printf("\n");
 }
 
-void show_lba_range(struct nvme_lba_range_type *lbrt, int nr_ranges)
+static void nvme_show_id_ctrl_rpmbs(__le32 ctrl_rpmbs)
 {
-       int i, j;
+       __u32 rpmbs = le32_to_cpu(ctrl_rpmbs);
+       __u32 asz = (rpmbs & 0xFF000000) >> 24;
+       __u32 tsz = (rpmbs & 0xFF0000) >> 16;
+       __u32 rsvd = (rpmbs & 0xFFC0) >> 6;
+       __u32 auth = (rpmbs & 0x38) >> 3;
+       __u32 rpmb = rpmbs & 0x7;
 
-       for (i = 0; i <= nr_ranges; i++) {
-               printf("\ttype       : %#x - %s\n", lbrt[i].type, nvme_feature_lba_type_to_string(lbrt[i].type));
-               printf("\tattributes : %#x - %s, %s\n", lbrt[i].attributes, (lbrt[i].attributes & 0x0001) ? "LBA range may be overwritten":"LBA range should not be overwritten",
-                       ((lbrt[i].attributes & 0x0002) >> 1) ? "LBA range should be hidden from the OS/EFI/BIOS":"LBA range should be visible from the OS/EFI/BIOS");
-               printf("\tslba       : %#"PRIx64"\n", (uint64_t)(lbrt[i].slba));
-               printf("\tnlb        : %#"PRIx64"\n", (uint64_t)(lbrt[i].nlb));
-               printf("\tguid       : ");
-               for (j = 0; j < 16; j++)
-                       printf("%02x", lbrt[i].guid[j]);
-               printf("\n");
-       }
+       printf(" [31:24]: %#x\tAccess Size\n", asz);
+       printf(" [23:16]: %#x\tTotal Size\n", tsz);
+       if (rsvd)
+               printf(" [15:6] : %#x\tReserved\n", rsvd);
+       printf("  [5:3] : %#x\tAuthentication Method\n", auth);
+       printf("  [2:0] : %#x\tNumber of RPMB Units\n", rpmb);
+       printf("\n");
 }
 
-
-static const char *nvme_feature_wl_hints_to_string(__u8 wh)
+static void nvme_show_id_ctrl_hctma(__le16 ctrl_hctma)
 {
-       switch (wh) {
-       case 0: return "No Workload";
-       case 1: return "Extended Idle Period with a Burst of Random Writes";
-       case 2: return "Heavy Sequential Writes";
-       default:return "Reserved";
-       }
-}
+       __u16 hctma = le16_to_cpu(ctrl_hctma);
+       __u16 rsvd = (hctma & 0xFFFE) >> 1;
+       __u16 hctm = hctma & 0x1;
 
-static const char *nvme_feature_temp_type_to_string(__u8 type)
-{
-       switch (type) {
-       case 0: return "Over Temperature Threshold";
-       case 1: return "Under Temperature Threshold";
-       default:return "Reserved";
-       }
+       if (rsvd)
+               printf(" [15:1] : %#x\tReserved\n", rsvd);
+       printf("  [0:0] : %#x\tHost Controlled Thermal Management %sSupported\n",
+               hctm, hctm ? "" : "Not ");
+       printf("\n");
 }
 
-static const char *nvme_feature_temp_sel_to_string(__u8 sel)
+static void nvme_show_id_ctrl_sanicap(__le32 ctrl_sanicap)
 {
-       switch (sel)
-       {
-       case 0: return "Composite Temperature";
-       case 1: return "Temperature Sensor 1";
-       case 2: return "Temperature Sensor 2";
-       case 3: return "Temperature Sensor 3";
-       case 4: return "Temperature Sensor 4";
-       case 5: return "Temperature Sensor 5";
-       case 6: return "Temperature Sensor 6";
-       case 7: return "Temperature Sensor 7";
-       case 8: return "Temperature Sensor 8";
-       default:return "Reserved";
-       }
+       __u32 sanicap = le32_to_cpu(ctrl_sanicap);
+       __u32 rsvd = (sanicap & 0x1FFFFFF8) >> 3;
+       __u32 owr = (sanicap & 0x4) >> 2;
+       __u32 ber = (sanicap & 0x2) >> 1;
+       __u32 cer = sanicap & 0x1;
+       __u32 ndi = (sanicap & 0x20000000) >> 29;
+       __u32 nodmmas = (sanicap & 0xC0000000) >> 30;
+
+       static const char *modifies_media[] = {
+               "Additional media modification after sanitize operation completes successfully is not defined",
+               "Media is not additionally modified after sanitize operation completes successfully",
+               "Media is additionally modified after sanitize operation completes successfully",
+               "Reserved"
+       };
+
+       printf("  [31:30] : %#x\t%s\n", nodmmas, modifies_media[nodmmas]);
+       printf("  [29:29] : %#x\tNo-Deallocate After Sanitize bit in Sanitize command %sSupported\n",
+               ndi, ndi ? "Not " : "");
+       if (rsvd)
+               printf("  [28:3] : %#x\tReserved\n", rsvd);
+       printf("    [2:2] : %#x\tOverwrite Sanitize Operation %sSupported\n",
+               owr, owr ? "" : "Not ");
+       printf("    [1:1] : %#x\tBlock Erase Sanitize Operation %sSupported\n",
+               ber, ber ? "" : "Not ");
+       printf("    [0:0] : %#x\tCrypto Erase Sanitize Operation %sSupported\n",
+               cer, cer ? "" : "Not ");
+       printf("\n");
 }
 
-static void show_auto_pst(struct nvme_auto_pst *apst)
+static void nvme_show_id_ctrl_anacap(__u8 anacap)
 {
-       int i;
+       __u8 nz = (anacap & 0x80) >> 7;
+       __u8 grpid_change = (anacap & 0x40) >> 6;
+       __u8 rsvd = (anacap & 0x20) >> 5;
+       __u8 ana_change = (anacap & 0x10) >> 4;
+       __u8 ana_persist_loss = (anacap & 0x08) >> 3;
+       __u8 ana_inaccessible = (anacap & 0x04) >> 2;
+       __u8 ana_nonopt = (anacap & 0x02) >> 1;
+       __u8 ana_opt = (anacap & 0x01);
 
-       printf( "\tAuto PST Entries");
-       printf("\t.................\n");
-       for (i = 0; i < 32; i++) {
-               printf("\tEntry[%2d]   \n", i);
-               printf("\t.................\n");
-               printf("\tIdle Time Prior to Transition (ITPT): %u ms\n", (apst[i].data & 0xffffff00) >> 8);
-               printf("\tIdle Transition Power State   (ITPS): %u\n", (apst[i].data & 0x000000f8) >> 3);
-               printf("\t.................\n");
-       }
+       printf("  [7:7] : %#x\tNon-zero group ID %sSupported\n",
+                       nz, nz ? "" : "Not ");
+       printf("  [6:6] : %#x\tGroup ID does %schange\n",
+                       grpid_change, grpid_change ? "" : "not ");
+       if (rsvd)
+               printf(" [5:5] : %#x\tReserved\n", rsvd);
+       printf("  [4:4] : %#x\tANA Change state %sSupported\n",
+                       ana_change, ana_change ? "" : "Not ");
+       printf("  [3:3] : %#x\tANA Persistent Loss state %sSupported\n",
+                       ana_persist_loss, ana_persist_loss ? "" : "Not ");
+       printf("  [2:2] : %#x\tANA Inaccessible state %sSupported\n",
+                       ana_inaccessible, ana_inaccessible ? "" : "Not ");
+       printf("  [1:1] : %#x\tANA Non-optimized state %sSupported\n",
+                       ana_nonopt, ana_nonopt ? "" : "Not ");
+       printf("  [0:0] : %#x\tANA Optimized state %sSupported\n",
+                       ana_opt, ana_opt ? "" : "Not ");
+       printf("\n");
 }
 
-static void show_timestamp(struct nvme_timestamp *ts)
+static void nvme_show_id_ctrl_sqes(__u8 sqes)
 {
-       struct tm *tm;
-       char buffer[32];
-       time_t timestamp = int48_to_long(ts->timestamp) / 1000;
-
-       tm = localtime(&timestamp);
-       strftime(buffer, sizeof(buffer), "%c %Z", tm);
+       __u8 msqes = (sqes & 0xF0) >> 4;
+       __u8 rsqes = sqes & 0xF;
+       printf("  [7:4] : %#x\tMax SQ Entry Size (%d)\n", msqes, 1 << msqes);
+       printf("  [3:0] : %#x\tMin SQ Entry Size (%d)\n", rsqes, 1 << rsqes);
+       printf("\n");
+}
 
-       printf("\tThe timestamp is : %"PRIu64" (%s)\n", int48_to_long(ts->timestamp), buffer);
-       printf("\t%s\n", (ts->attr & 2) ? "The Timestamp field was initialized with a "\
-                       "Timestamp value using a Set Features command." : "The Timestamp field was initialized "\
-                       "to â€˜0’ by a Controller Level Reset.");
-       printf("\t%s\n", (ts->attr & 1) ? "The controller may have stopped counting during vendor specific "\
-                       "intervals after the Timestamp value was initialized" : "The controller counted time in milliseconds "\
-                       "continuously since the Timestamp value was initialized.");
+static void nvme_show_id_ctrl_cqes(__u8 cqes)
+{
+       __u8 mcqes = (cqes & 0xF0) >> 4;
+       __u8 rcqes = cqes & 0xF;
+       printf("  [7:4] : %#x\tMax CQ Entry Size (%d)\n", mcqes, 1 << mcqes);
+       printf("  [3:0] : %#x\tMin CQ Entry Size (%d)\n", rcqes, 1 << rcqes);
+       printf("\n");
 }
 
-static void show_host_mem_buffer(struct nvme_host_mem_buffer *hmb)
+static void nvme_show_id_ctrl_oncs(__le16 ctrl_oncs)
 {
-       printf("\tHost Memory Descriptor List Entry Count (HMDLEC): %u\n", hmb->hmdlec);
-       printf("\tHost Memory Descriptor List Address     (HMDLAU): 0x%x\n", hmb->hmdlau);
-       printf("\tHost Memory Descriptor List Address     (HMDLAL): 0x%x\n", hmb->hmdlal);
-       printf("\tHost Memory Buffer Size                  (HSIZE): %u\n", hmb->hsize);
+       __u16 oncs = le16_to_cpu(ctrl_oncs);
+       __u16 rsvd = (oncs & 0xFF00) >> 8;
+       __u16 vrfy = (oncs & 0x80) >> 7;
+       __u16 tmst = (oncs & 0x40) >> 6;
+       __u16 resv = (oncs & 0x20) >> 5;
+       __u16 save = (oncs & 0x10) >> 4;
+       __u16 wzro = (oncs & 0x8) >> 3;
+       __u16 dsms = (oncs & 0x4) >> 2;
+       __u16 wunc = (oncs & 0x2) >> 1;
+       __u16 cmp = oncs & 0x1;
+
+       if (rsvd)
+               printf(" [15:8] : %#x\tReserved\n", rsvd);
+       printf("  [7:7] : %#x\tVerify %sSupported\n",
+               vrfy, vrfy ? "" : "Not ");
+       printf("  [6:6] : %#x\tTimestamp %sSupported\n",
+               tmst, tmst ? "" : "Not ");
+       printf("  [5:5] : %#x\tReservations %sSupported\n",
+               resv, resv ? "" : "Not ");
+       printf("  [4:4] : %#x\tSave and Select %sSupported\n",
+               save, save ? "" : "Not ");
+       printf("  [3:3] : %#x\tWrite Zeroes %sSupported\n",
+               wzro, wzro ? "" : "Not ");
+       printf("  [2:2] : %#x\tData Set Management %sSupported\n",
+               dsms, dsms ? "" : "Not ");
+       printf("  [1:1] : %#x\tWrite Uncorrectable %sSupported\n",
+               wunc, wunc ? "" : "Not ");
+       printf("  [0:0] : %#x\tCompare %sSupported\n",
+               cmp, cmp ? "" : "Not ");
+       printf("\n");
 }
 
-void nvme_directive_show_fields(__u8 dtype, __u8 doper, unsigned int result, unsigned char *buf)
+static void nvme_show_id_ctrl_fuses(__le16 ctrl_fuses)
 {
-        __u8 *field = buf;
-        int count, i;
-        switch (dtype) {
-        case NVME_DIR_IDENTIFY:
-                switch (doper) {
-                case NVME_DIR_RCV_ID_OP_PARAM:
-                        printf("\tDirective support \n");
-                        printf("\t\tIdentify Directive  : %s\n", (*field & 0x1) ? "supported":"not supported");
-                        printf("\t\tStream Directive    : %s\n", (*field & 0x2) ? "supported":"not supported");
-                        printf("\tDirective status \n");
-                        printf("\t\tIdentify Directive  : %s\n", (*(field + 32) & 0x1) ? "enabled" : "disabled");
-                        printf("\t\tStream Directive    : %s\n", (*(field + 32) & 0x2) ? "enabled" : "disabled");
-                        break;
-                default:
-                        fprintf(stderr, "invalid directive operations for Identify Directives\n");
-                }
-                break;
-        case NVME_DIR_STREAMS:
-                switch (doper) {
-                case NVME_DIR_RCV_ST_OP_PARAM:
-                        printf("\tMax Streams Limit                          (MSL): %u\n", *(__u16 *) field);
-                        printf("\tNVM Subsystem Streams Available           (NSSA): %u\n", *(__u16 *) (field + 2));
-                        printf("\tNVM Subsystem Streams Open                (NSSO): %u\n", *(__u16 *) (field + 4));
-                        printf("\tStream Write Size (in unit of LB size)     (SWS): %u\n", *(__u32 *) (field + 16));
-                        printf("\tStream Granularity Size (in unit of SWS)   (SGS): %u\n", *(__u16 *) (field + 20));
-                        printf("\tNamespece Streams Allocated                (NSA): %u\n", *(__u16 *) (field + 22));
-                        printf("\tNamespace Streams Open                     (NSO): %u\n", *(__u16 *) (field + 24));
-                        break;
-                case NVME_DIR_RCV_ST_OP_STATUS:
-                        count = *(__u16 *) field;
-                        printf("\tOpen Stream Count  : %u\n", *(__u16 *) field);
-                        for ( i = 0; i < count; i++ ) {
-                                printf("\tStream Identifier %.6u : %u\n", i + 1, *(__u16 *) (field + ((i + 1) * 2)));
-                        }
-                        break;
-                case NVME_DIR_RCV_ST_OP_RESOURCE:
-                        printf("\tNamespace Streams Allocated (NSA): %u\n", result & 0xffff);
-                        break;
-                default:
-                        fprintf(stderr, "invalid directive operations for Streams Directives\n");
-                }
-                break;
-        default:
-                fprintf(stderr, "invalid directive type\n");
-                break;
-        }
-        return;
+       __u16 fuses = le16_to_cpu(ctrl_fuses);
+       __u16 rsvd = (fuses & 0xFE) >> 1;
+       __u16 cmpw = fuses & 0x1;
+
+       if (rsvd)
+               printf(" [15:1] : %#x\tReserved\n", rsvd);
+       printf("  [0:0] : %#x\tFused Compare and Write %sSupported\n",
+               cmpw, cmpw ? "" : "Not ");
+       printf("\n");
 }
 
-static const char *nvme_plm_window(__u32 plm)
+static void nvme_show_id_ctrl_fna(__u8 fna)
 {
-       switch (plm & 0x7) {
-       case 1:
-               return "Deterministic Window (DTWIN)";
-       case 2:
-               return "Non-deterministic Window (NDWIN)";
-       default:
-               return "Reserved";
-       }
+       __u8 rsvd = (fna & 0xF8) >> 3;
+       __u8 cese = (fna & 0x4) >> 2;
+       __u8 cens = (fna & 0x2) >> 1;
+       __u8 fmns = fna & 0x1;
+       if (rsvd)
+               printf("  [7:3] : %#x\tReserved\n", rsvd);
+       printf("  [2:2] : %#x\tCrypto Erase %sSupported as part of Secure Erase\n",
+               cese, cese ? "" : "Not ");
+       printf("  [1:1] : %#x\tCrypto Erase Applies to %s Namespace(s)\n",
+               cens, cens ? "All" : "Single");
+       printf("  [0:0] : %#x\tFormat Applies to %s Namespace(s)\n",
+               fmns, fmns ? "All" : "Single");
+       printf("\n");
 }
 
-static void show_plm_config(struct nvme_plm_config *plmcfg)
+static void nvme_show_id_ctrl_vwc(__u8 vwc)
 {
-       printf("\tEnable Event          :%04x\n", le16_to_cpu(plmcfg->enable_event));
-       printf("\tDTWIN Reads Threshold :%"PRIu64"\n", le64_to_cpu(plmcfg->dtwin_reads_thresh));
-       printf("\tDTWIN Writes Threshold:%"PRIu64"\n", le64_to_cpu(plmcfg->dtwin_writes_thresh));
-       printf("\tDTWIN Time Threshold  :%"PRIu64"\n", le64_to_cpu(plmcfg->dtwin_time_thresh));
+       __u8 rsvd = (vwc & 0xF8) >> 3;
+       __u8 flush = (vwc & 0x6) >> 1;
+       __u8 vwcp = vwc & 0x1;
+
+       static const char *flush_behavior[] = {
+               "Support for the NSID field set to FFFFFFFFh is not indicated",
+               "Reserved",
+               "The Flush command does not support NSID set to FFFFFFFFh",
+               "The Flush command supports NSID set to FFFFFFFFh"
+       };
+
+       if (rsvd)
+               printf("  [7:3] : %#x\tReserved\n", rsvd);
+       printf("  [2:1] : %#x\t%s\n", flush, flush_behavior[flush]);
+       printf("  [0:0] : %#x\tVolatile Write Cache %sPresent\n",
+               vwcp, vwcp ? "" : "Not ");
+       printf("\n");
 }
 
-void nvme_feature_show_fields(__u32 fid, unsigned int result, unsigned char *buf)
+static void nvme_show_id_ctrl_nvscc(__u8 nvscc)
 {
-       __u8 field;
-       uint64_t ull;
+       __u8 rsvd = (nvscc & 0xFE) >> 1;
+       __u8 fmt = nvscc & 0x1;
+       if (rsvd)
+               printf("  [7:1] : %#x\tReserved\n", rsvd);
+       printf("  [0:0] : %#x\tNVM Vendor Specific Commands uses %s Format\n",
+               fmt, fmt ? "NVMe" : "Vendor Specific");
+       printf("\n");
+}
 
-       switch (fid) {
-       case NVME_FEAT_ARBITRATION:
-               printf("\tHigh Priority Weight   (HPW): %u\n", ((result & 0xff000000) >> 24) + 1);
-               printf("\tMedium Priority Weight (MPW): %u\n", ((result & 0x00ff0000) >> 16) + 1);
-               printf("\tLow Priority Weight    (LPW): %u\n", ((result & 0x0000ff00) >> 8) + 1);
-               printf("\tArbitration Burst       (AB): ");
-               if ((result & 0x00000007) == 7)
-                       printf("No limit\n");
-               else
-                       printf("%u\n",  1 << (result & 0x00000007));
-               break;
-       case NVME_FEAT_POWER_MGMT:
-               field = (result & 0x000000E0) >> 5;
-               printf("\tWorkload Hint (WH): %u - %s\n",  field, nvme_feature_wl_hints_to_string(field));
-               printf("\tPower State   (PS): %u\n",  result & 0x0000001f);
-               break;
-       case NVME_FEAT_LBA_RANGE:
-               field = result & 0x0000003f;
-               printf("\tNumber of LBA Ranges (NUM): %u\n", field + 1);
-               show_lba_range((struct nvme_lba_range_type *)buf, field);
-               break;
-       case NVME_FEAT_TEMP_THRESH:
-               field = (result & 0x00300000) >> 20;
-               printf("\tThreshold Type Select         (THSEL): %u - %s\n", field, nvme_feature_temp_type_to_string(field));
-               field = (result & 0x000f0000) >> 16;
-               printf("\tThreshold Temperature Select (TMPSEL): %u - %s\n", field, nvme_feature_temp_sel_to_string(field));
-               printf("\tTemperature Threshold         (TMPTH): %d C\n", (result & 0x0000ffff) - 273);
-               break;
-       case NVME_FEAT_ERR_RECOVERY:
-               printf("\tDeallocated or Unwritten Logical Block Error Enable (DULBE): %s\n", ((result & 0x00010000) >> 16) ? "Enabled":"Disabled");
-               printf("\tTime Limited Error Recovery                          (TLER): %u ms\n", (result & 0x0000ffff) * 100);
-               break;
-       case NVME_FEAT_VOLATILE_WC:
-               printf("\tVolatile Write Cache Enable (WCE): %s\n", (result & 0x00000001) ? "Enabled":"Disabled");
-               break;
-       case NVME_FEAT_NUM_QUEUES:
-               printf("\tNumber of IO Completion Queues Allocated (NCQA): %u\n", ((result & 0xffff0000) >> 16) + 1);
-               printf("\tNumber of IO Submission Queues Allocated (NSQA): %u\n",  (result & 0x0000ffff) + 1);
-               break;
-       case NVME_FEAT_IRQ_COALESCE:
-               printf("\tAggregation Time     (TIME): %u usec\n", ((result & 0x0000ff00) >> 8) * 100);
-               printf("\tAggregation Threshold (THR): %u\n",  (result & 0x000000ff) + 1);
-               break;
-       case NVME_FEAT_IRQ_CONFIG:
-               printf("\tCoalescing Disable (CD): %s\n", ((result & 0x00010000) >> 16) ? "True":"False");
-               printf("\tInterrupt Vector   (IV): %u\n",  result & 0x0000ffff);
-               break;
-       case NVME_FEAT_WRITE_ATOMIC:
-               printf("\tDisable Normal (DN): %s\n", (result & 0x00000001) ? "True":"False");
-               break;
-       case NVME_FEAT_ASYNC_EVENT:
-               printf("\tTelemetry Log Notices           : %s\n", ((result & 0x00000400) >> 10) ? "Send async event":"Do not send async event");
-               printf("\tFirmware Activation Notices     : %s\n", ((result & 0x00000200) >> 9) ? "Send async event":"Do not send async event");
-               printf("\tNamespace Attribute Notices     : %s\n", ((result & 0x00000100) >> 8) ? "Send async event":"Do not send async event");
-               printf("\tSMART / Health Critical Warnings: %s\n", (result & 0x000000ff) ? "Send async event":"Do not send async event");
-               break;
-       case NVME_FEAT_AUTO_PST:
-               printf("\tAutonomous Power State Transition Enable (APSTE): %s\n", (result & 0x00000001) ? "Enabled":"Disabled");
-               show_auto_pst((struct nvme_auto_pst *)buf);
-               break;
-       case NVME_FEAT_HOST_MEM_BUF:
-               printf("\tMemory Return       (MR): %s\n", ((result & 0x00000002) >> 1) ? "True":"False");
-               printf("\tEnable Host Memory (EHM): %s\n", (result & 0x00000001) ? "Enabled":"Disabled");
-               show_host_mem_buffer((struct nvme_host_mem_buffer *)buf);
-               break;
-       case NVME_FEAT_SW_PROGRESS:
-               printf("\tPre-boot Software Load Count (PBSLC): %u\n", result & 0x000000ff);
-               break;
-       case NVME_FEAT_PLM_CONFIG:
-               printf("\tPredictable Latency Window Enabled: %s\n", result & 0x1 ? "True":"False");
-               show_plm_config((struct nvme_plm_config *)buf);
-               break;
-       case NVME_FEAT_PLM_WINDOW:
-               printf("\tWindow Select: %s", nvme_plm_window(result));
-               break;
-       case NVME_FEAT_HOST_ID:
-               ull =  buf[7]; ull <<= 8; ull |= buf[6]; ull <<= 8; ull |= buf[5]; ull <<= 8;
-               ull |= buf[4]; ull <<= 8; ull |= buf[3]; ull <<= 8; ull |= buf[2]; ull <<= 8;
-               ull |= buf[1]; ull <<= 8; ull |= buf[0];
-               printf("\tHost Identifier (HOSTID):  %" PRIu64 "\n", ull);
-               break;
-       case NVME_FEAT_RESV_MASK:
-               printf("\tMask Reservation Preempted Notification  (RESPRE): %s\n", ((result & 0x00000008) >> 3) ? "True":"False");
-               printf("\tMask Reservation Released Notification   (RESREL): %s\n", ((result & 0x00000004) >> 2) ? "True":"False");
-               printf("\tMask Registration Preempted Notification (REGPRE): %s\n", ((result & 0x00000002) >> 1) ? "True":"False");
-               break;
-       case NVME_FEAT_RESV_PERSIST:
-               printf("\tPersist Through Power Loss (PTPL): %s\n", (result & 0x00000001) ? "True":"False");
-               break;
-       case NVME_FEAT_WRITE_PROTECT:
-               printf("\tNamespace Write Protect: %s\n", result != NVME_NS_NO_WRITE_PROTECT ? "True" :  "False");
-               break;
-       case NVME_FEAT_TIMESTAMP:
-               show_timestamp((struct nvme_timestamp *)buf);
-               break;
-       case NVME_FEAT_HCTM:
-               printf("\tThermal Management Temperature 1 (TMT1) : %u Kelvin\n", (result >> 16));
-               printf("\tThermal Management Temperature 2 (TMT2) : %u Kelvin\n", (result & 0x0000ffff));
-               break;
-       case NVME_FEAT_KATO:
-               printf("\tKeep Alive Timeout (KATO) in milliseconds: %u\n", result);
-               break;
-       case NVME_FEAT_NOPSC:
-               printf("\tNon-Operational Power State Permissive Mode Enable (NOPPME): %s\n", (result & 1) ? "True" : "False");
-               break;
-       case NVME_FEAT_HOST_BEHAVIOR:
-               printf("\tHost Behavior Support: %s\n", (buf[0] & 0x1) ? "True" : "False");
-               break;
-       }
+static void nvme_show_id_ctrl_nwpc(__u8 nwpc)
+{
+       __u8 no_wp_wp = (nwpc & 0x01);
+       __u8 wp_power_cycle = (nwpc & 0x02) >> 1;
+       __u8 wp_permanent = (nwpc & 0x04) >> 2;
+       __u8 rsvd = (nwpc & 0xF8) >> 3;
+
+       if (rsvd)
+               printf("  [7:3] : %#x\tReserved\n", rsvd);
+
+       printf("  [2:2] : %#x\tPermanent Write Protect %sSupported\n",
+               wp_permanent, wp_permanent ? "" : "Not ");
+       printf("  [1:1] : %#x\tWrite Protect Until Power Supply %sSupported\n",
+               wp_power_cycle, wp_power_cycle ? "" : "Not ");
+       printf("  [0:0] : %#x\tNo Write Protect and Write Protect Namespace %sSupported\n",
+               no_wp_wp, no_wp_wp ? "" : "Not ");
+       printf("\n");
 }
 
-void show_lba_status(struct nvme_lba_status *list)
+static void nvme_show_id_ctrl_sgls(__le32 ctrl_sgls)
 {
-       int idx;
+       __u32 sgls = le32_to_cpu(ctrl_sgls);
+       __u32 rsvd0 = (sgls & 0xFFC00000) >> 22;
+       __u32 trsdbd = (sgls & 0x200000) >> 21;
+       __u32 aofdsl = (sgls & 0x100000) >> 20;
+       __u32 mpcsd = (sgls & 0x80000) >> 19;
+       __u32 sglltb = (sgls & 0x40000) >> 18;
+       __u32 bacmdb = (sgls & 0x20000) >> 17;
+       __u32 bbs = (sgls & 0x10000) >> 16;
+       __u32 rsvd1 = (sgls & 0xFFF8) >> 3;
+       __u32 key = (sgls & 0x4) >> 2;
+       __u32 sglsp = sgls & 0x3;
 
-       printf("Number of LBA Status Descriptors(NLSD): %" PRIu64 "\n",
-                       le64_to_cpu(list->nlsd));
-       printf("Completion Condition(CMPC): %u\n", list->cmpc);
-       switch (list->cmpc) {
-       case 1:
-               printf("\tCompleted due to transferring the amount of data"\
-                       " specified in the MNDW field\n");
-               break;
-       case 2:
-               printf("\tCompleted due to having performed the action\n"\
-                       "\tspecified in the Action Type field over the\n"\
-                       "\tnumber of logical blocks specified in the\n"\
-                       "\tRange Length field\n");
-               break;
-       }
+       if (rsvd0)
+               printf(" [31:22]: %#x\tReserved\n", rsvd0);
+       if (sglsp || (!sglsp && trsdbd))
+               printf(" [21:21]: %#x\tTransport SGL Data Block Descriptor %sSupported\n",
+                       trsdbd, trsdbd ? "" : "Not ");
+       if (sglsp || (!sglsp && aofdsl))
+               printf(" [20:20]: %#x\tAddress Offsets %sSupported\n",
+                       aofdsl, aofdsl ? "" : "Not ");
+       if (sglsp || (!sglsp && mpcsd))
+               printf(" [19:19]: %#x\tMetadata Pointer Containing "
+                       "SGL Descriptor is %sSupported\n",
+                       mpcsd, mpcsd ? "" : "Not ");
+       if (sglsp || (!sglsp && sglltb))
+               printf(" [18:18]: %#x\tSGL Length Larger than Buffer %sSupported\n",
+                       sglltb, sglltb ? "" : "Not ");
+       if (sglsp || (!sglsp && bacmdb))
+               printf(" [17:17]: %#x\tByte-Aligned Contig. MD Buffer %sSupported\n",
+                       bacmdb, bacmdb ? "" : "Not ");
+       if (sglsp || (!sglsp && bbs))
+               printf(" [16:16]: %#x\tSGL Bit-Bucket %sSupported\n",
+                       bbs, bbs ? "" : "Not ");
+       if (rsvd1)
+               printf(" [15:3] : %#x\tReserved\n", rsvd1);
+       if (sglsp || (!sglsp && key))
+               printf("  [2:2] : %#x\tKeyed SGL Data Block descriptor %sSupported\n",
+                       key, key ? "" : "Not ");
+       if (sglsp == 0x3)
+               printf("  [1:0] : %#x\tReserved\n", sglsp);
+       else if (sglsp == 0x2)
+               printf("  [1:0] : %#x\tScatter-Gather Lists Supported."
+                       " Dword alignment required.\n", sglsp);
+       else if (sglsp == 0x1)
+               printf("  [1:0] : %#x\tScatter-Gather Lists Supported."
+                       " No Dword alignment required.\n", sglsp);
+       else
+               printf(" [1:0]  : %#x\tScatter-Gather Lists Not Supported\n", sglsp);
+       printf("\n");
+}
 
-       for (idx = 0; idx < list->nlsd; idx++) {
-               struct nvme_lba_status_desc *e = &list->descs[idx];
-               printf("{ DSLBA: 0x%016"PRIu64", NLB: 0x%08x, Status: 0x%02x }\n",
-                               le64_to_cpu(e->dslba), le32_to_cpu(e->nlb),
-                               e->status);
-       }
+static void nvme_show_id_ctrl_ctrattr(__u8 ctrattr)
+{
+       __u8 rsvd = (ctrattr & 0xFE) >> 1;
+       __u8 scm = ctrattr & 0x1;
+       if (rsvd)
+               printf("  [7:1] : %#x\tReserved\n", rsvd);
+       printf("  [0:0] : %#x\t%s Controller Model\n",
+               scm, scm ? "Static" : "Dynamic");
+       printf("\n");
 }
 
-static void show_list_item(struct nvme_namespace *n)
+static void nvme_show_id_ns_nsfeat(__u8 nsfeat)
 {
-       long long lba   = 1 << n->ns.lbaf[(n->ns.flbas & 0x0f)].ds;
-       double nsze     = le64_to_cpu(n->ns.nsze) * lba;
-       double nuse     = le64_to_cpu(n->ns.nuse) * lba;
-
-       const char *s_suffix = suffix_si_get(&nsze);
-       const char *u_suffix = suffix_si_get(&nuse);
-       const char *l_suffix = suffix_binary_get(&lba);
-
-       char usage[128];
-       char format[128];
-
-       sprintf(usage,"%6.2f %2sB / %6.2f %2sB", nuse, u_suffix,
-               nsze, s_suffix);
-       sprintf(format,"%3.0f %2sB + %2d B", (double)lba, l_suffix,
-               le16_to_cpu(n->ns.lbaf[(n->ns.flbas & 0x0f)].ms));
-       printf("/dev/%-11s %-*.*s %-*.*s %-9d %-26s %-16s %-.*s\n", n->name,
-               (int)sizeof(n->ctrl->id.sn), (int)sizeof(n->ctrl->id.sn), n->ctrl->id.sn,
-               (int)sizeof(n->ctrl->id.mn), (int)sizeof(n->ctrl->id.mn), n->ctrl->id.mn,
-               n->nsid, usage, format, (int)sizeof(n->ctrl->id.fr), n->ctrl->id.fr);
+       __u8 rsvd = (nsfeat & 0xE0) >> 5;
+       __u8 ioopt = (nsfeat & 0x10) >> 4;
+       __u8 dulbe = (nsfeat & 0x4) >> 2;
+       __u8 na = (nsfeat & 0x2) >> 1;
+       __u8 thin = nsfeat & 0x1;
+       if (rsvd)
+               printf("  [7:5] : %#x\tReserved\n", rsvd);
+       printf("  [4:4] : %#x\tNPWG, NPWA, NPDG, NPDA, and NOWS are %sSupported\n",
+               ioopt, ioopt ? "" : "Not ");
+       printf("  [2:2] : %#x\tDeallocated or Unwritten Logical Block error %sSupported\n",
+               dulbe, dulbe ? "" : "Not ");
+       printf("  [1:1] : %#x\tNamespace uses %s\n",
+               na, na ? "NAWUN, NAWUPF, and NACWU" : "AWUN, AWUPF, and ACWU");
+       printf("  [0:0] : %#x\tThin Provisioning %sSupported\n",
+               thin, thin ? "" : "Not ");
+       printf("\n");
 }
 
-static const char dash[] = "---------------------------------------------------------------------------------------------------";
+static void nvme_show_id_ns_flbas(__u8 flbas)
+{
+       __u8 rsvd = (flbas & 0xE0) >> 5;
+       __u8 mdedata = (flbas & 0x10) >> 4;
+       __u8 lbaf = flbas & 0xF;
+       if (rsvd)
+               printf("  [7:5] : %#x\tReserved\n", rsvd);
+       printf("  [4:4] : %#x\tMetadata Transferred %s\n",
+               mdedata, mdedata ? "at End of Data LBA" : "in Separate Contiguous Buffer");
+       printf("  [3:0] : %#x\tCurrent LBA Format Selected\n", lbaf);
+       printf("\n");
+}
 
-static void show_simple_list(struct nvme_topology *t)
+static void nvme_show_id_ns_mc(__u8 mc)
 {
-       int i, j, k;
+       __u8 rsvd = (mc & 0xFC) >> 2;
+       __u8 mdp = (mc & 0x2) >> 1;
+       __u8 extdlba = mc & 0x1;
+       if (rsvd)
+               printf("  [7:2] : %#x\tReserved\n", rsvd);
+       printf("  [1:1] : %#x\tMetadata Pointer %sSupported\n",
+               mdp, mdp ? "" : "Not ");
+       printf("  [0:0] : %#x\tMetadata as Part of Extended Data LBA %sSupported\n",
+               extdlba, extdlba ? "" : "Not ");
+       printf("\n");
+}
 
-       printf("%-16s %-20s %-40s %-9s %-26s %-16s %-8s\n",
-           "Node", "SN", "Model", "Namespace", "Usage", "Format", "FW Rev");
-       printf("%-.16s %-.20s %-.40s %-.9s %-.26s %-.16s %-.8s\n", dash, dash,
-               dash, dash, dash, dash, dash);
+static void nvme_show_id_ns_dpc(__u8 dpc)
+{
+       __u8 rsvd = (dpc & 0xE0) >> 5;
+       __u8 pil8 = (dpc & 0x10) >> 4;
+       __u8 pif8 = (dpc & 0x8) >> 3;
+       __u8 pit3 = (dpc & 0x4) >> 2;
+       __u8 pit2 = (dpc & 0x2) >> 1;
+       __u8 pit1 = dpc & 0x1;
+       if (rsvd)
+               printf("  [7:5] : %#x\tReserved\n", rsvd);
+       printf("  [4:4] : %#x\tProtection Information Transferred as Last 8 Bytes of Metadata %sSupported\n",
+               pil8, pil8 ? "" : "Not ");
+       printf("  [3:3] : %#x\tProtection Information Transferred as First 8 Bytes of Metadata %sSupported\n",
+               pif8, pif8 ? "" : "Not ");
+       printf("  [2:2] : %#x\tProtection Information Type 3 %sSupported\n",
+               pit3, pit3 ? "" : "Not ");
+       printf("  [1:1] : %#x\tProtection Information Type 2 %sSupported\n",
+               pit2, pit2 ? "" : "Not ");
+       printf("  [0:0] : %#x\tProtection Information Type 1 %sSupported\n",
+               pit1, pit1 ? "" : "Not ");
+       printf("\n");
+}
 
-       for (i = 0; i < t->nr_subsystems; i++) {
-               struct nvme_subsystem *s = &t->subsystems[i];
+static void nvme_show_id_ns_dps(__u8 dps)
+{
+       __u8 rsvd = (dps & 0xF0) >> 4;
+       __u8 pif8 = (dps & 0x8) >> 3;
+       __u8 pit = dps & 0x7;
+       if (rsvd)
+               printf("  [7:4] : %#x\tReserved\n", rsvd);
+       printf("  [3:3] : %#x\tProtection Information is Transferred as %s 8 Bytes of Metadata\n",
+               pif8, pif8 ? "First" : "Last");
+       printf("  [2:0] : %#x\tProtection Information %s\n", pit,
+               pit == 3 ? "Type 3 Enabled" :
+               pit == 2 ? "Type 2 Enabled" :
+               pit == 1 ? "Type 1 Enabled" :
+               pit == 0 ? "Disabled" : "Reserved Enabled");
+       printf("\n");
+}
 
-               for (j = 0; j < s->nr_ctrls; j++) {
-                       struct nvme_ctrl *c = &s->ctrls[j];
+static void nvme_show_id_ns_nmic(__u8 nmic)
+{
+       __u8 rsvd = (nmic & 0xFE) >> 1;
+       __u8 mp = nmic & 0x1;
+       if (rsvd)
+               printf("  [7:1] : %#x\tReserved\n", rsvd);
+       printf("  [0:0] : %#x\tNamespace Multipath %sCapable\n",
+               mp, mp ? "" : "Not ");
+       printf("\n");
+}
 
-                       for (k = 0; k < c->nr_namespaces; k++) {
-                               struct nvme_namespace *n = &c->namespaces[k];
-                               show_list_item(n);
-                       }
-               }
+static void nvme_show_id_ns_rescap(__u8 rescap)
+{
+       __u8 rsvd = (rescap & 0x80) >> 7;
+       __u8 eaar = (rescap & 0x40) >> 6;
+       __u8 wear = (rescap & 0x20) >> 5;
+       __u8 earo = (rescap & 0x10) >> 4;
+       __u8 wero = (rescap & 0x8) >> 3;
+       __u8 ea = (rescap & 0x4) >> 2;
+       __u8 we = (rescap & 0x2) >> 1;
+       __u8 ptpl = rescap & 0x1;
+       if (rsvd)
+               printf("  [7:7] : %#x\tReserved\n", rsvd);
+       printf("  [6:6] : %#x\tExclusive Access - All Registrants %sSupported\n",
+               eaar, eaar ? "" : "Not ");
+       printf("  [5:5] : %#x\tWrite Exclusive - All Registrants %sSupported\n",
+               wear, wear ? "" : "Not ");
+       printf("  [4:4] : %#x\tExclusive Access - Registrants Only %sSupported\n",
+               earo, earo ? "" : "Not ");
+       printf("  [3:3] : %#x\tWrite Exclusive - Registrants Only %sSupported\n",
+               wero, wero ? "" : "Not ");
+       printf("  [2:2] : %#x\tExclusive Access %sSupported\n",
+               ea, ea ? "" : "Not ");
+       printf("  [1:1] : %#x\tWrite Exclusive %sSupported\n",
+               we, we ? "" : "Not ");
+       printf("  [0:0] : %#x\tPersist Through Power Loss %sSupported\n",
+               ptpl, ptpl ? "" : "Not ");
+       printf("\n");
+}
 
-               for (j = 0; j < s->nr_namespaces; j++) {
-                       struct nvme_namespace *n = &s->namespaces[j];
-                       show_list_item(n);
-               }
-       }
+static void nvme_show_id_ns_fpi(__u8 fpi)
+{
+       __u8 fpis = (fpi & 0x80) >> 7;
+       __u8 fpii = fpi & 0x7F;
+       printf("  [7:7] : %#x\tFormat Progress Indicator %sSupported\n",
+               fpis, fpis ? "" : "Not ");
+       if (fpis || (!fpis && fpii))
+               printf("  [6:0] : %#x\tFormat Progress Indicator (Remaining %d%%)\n",
+               fpii, fpii);
+       printf("\n");
 }
 
-static void show_details_ns(struct nvme_namespace *n, bool ctrl)
+static void nvme_show_id_ns_dlfeat(__u8 dlfeat)
 {
-       long long lba   = 1 << n->ns.lbaf[(n->ns.flbas & 0x0f)].ds;
-       double nsze     = le64_to_cpu(n->ns.nsze) * lba;
-       double nuse     = le64_to_cpu(n->ns.nuse) * lba;
+       __u8 rsvd = (dlfeat & 0xE0) >> 5;
+       __u8 guard = (dlfeat & 0x10) >> 4;
+       __u8 dwz = (dlfeat & 0x8) >> 3;
+       __u8 val = dlfeat & 0x7;
+       if (rsvd)
+               printf("  [7:5] : %#x\tReserved\n", rsvd);
+       printf("  [4:4] : %#x\tGuard Field of Deallocated Logical Blocks is set to %s\n",
+               guard, guard ? "CRC of The Value Read" : "0xFFFF");
+       printf("  [3:3] : %#x\tDeallocate Bit in the Write Zeroes Command is %sSupported\n",
+               dwz, dwz ? "" : "Not ");
+       printf("  [2:0] : %#x\tBytes Read From a Deallocated Logical Block and its Metadata are %s\n", val,
+               val == 2 ? "0xFF" :
+               val == 1 ? "0x00" :
+               val == 0 ? "Not Reported" : "Reserved Value");
+       printf("\n");
+}
 
-       const char *s_suffix = suffix_si_get(&nsze);
-       const char *u_suffix = suffix_si_get(&nuse);
-       const char *l_suffix = suffix_binary_get(&lba);
+void nvme_show_id_ns(struct nvme_id_ns *ns, unsigned int nsid,
+               enum nvme_print_flags flags)
+{
+       int human = flags & VERBOSE;
+       int vs = flags & VS;
+       int i;
 
-       char usage[128];
-       char format[128];
+       if (flags & BINARY)
+               return d_raw((unsigned char *)ns, sizeof(*ns));
+       if (flags & JSON)
+               return json_nvme_id_ns(ns, flags);
 
-       sprintf(usage,"%6.2f %2sB / %6.2f %2sB", nuse, u_suffix,
-               nsze, s_suffix);
-       sprintf(format,"%3.0f %2sB + %2d B", (double)lba, l_suffix,
-               le16_to_cpu(n->ns.lbaf[(n->ns.flbas & 0x0f)].ms));
+       printf("NVME Identify Namespace %d:\n", nsid);
+       printf("nsze    : %#"PRIx64"\n", le64_to_cpu(ns->nsze));
+       printf("ncap    : %#"PRIx64"\n", le64_to_cpu(ns->ncap));
+       printf("nuse    : %#"PRIx64"\n", le64_to_cpu(ns->nuse));
+       printf("nsfeat  : %#x\n", ns->nsfeat);
+       if (human)
+               nvme_show_id_ns_nsfeat(ns->nsfeat);
+       printf("nlbaf   : %d\n", ns->nlbaf);
+       printf("flbas   : %#x\n", ns->flbas);
+       if (human)
+               nvme_show_id_ns_flbas(ns->flbas);
+       printf("mc      : %#x\n", ns->mc);
+       if (human)
+               nvme_show_id_ns_mc(ns->mc);
+       printf("dpc     : %#x\n", ns->dpc);
+       if (human)
+               nvme_show_id_ns_dpc(ns->dpc);
+       printf("dps     : %#x\n", ns->dps);
+       if (human)
+               nvme_show_id_ns_dps(ns->dps);
+       printf("nmic    : %#x\n", ns->nmic);
+       if (human)
+               nvme_show_id_ns_nmic(ns->nmic);
+       printf("rescap  : %#x\n", ns->rescap);
+       if (human)
+               nvme_show_id_ns_rescap(ns->rescap);
+       printf("fpi     : %#x\n", ns->fpi);
+       if (human)
+               nvme_show_id_ns_fpi(ns->fpi);
+       printf("dlfeat  : %d\n", ns->dlfeat);
+       if (human)
+               nvme_show_id_ns_dlfeat(ns->dlfeat);
+       printf("nawun   : %d\n", le16_to_cpu(ns->nawun));
+       printf("nawupf  : %d\n", le16_to_cpu(ns->nawupf));
+       printf("nacwu   : %d\n", le16_to_cpu(ns->nacwu));
+       printf("nabsn   : %d\n", le16_to_cpu(ns->nabsn));
+       printf("nabo    : %d\n", le16_to_cpu(ns->nabo));
+       printf("nabspf  : %d\n", le16_to_cpu(ns->nabspf));
+       printf("noiob   : %d\n", le16_to_cpu(ns->noiob));
+       printf("nvmcap  : %.0Lf\n", int128_to_double(ns->nvmcap));
+       if (ns->nsfeat & 0x10) {
+               printf("npwg    : %u\n", le16_to_cpu(ns->npwg));
+               printf("npwa    : %u\n", le16_to_cpu(ns->npwa));
+               printf("npdg    : %u\n", le16_to_cpu(ns->npdg));
+               printf("npda    : %u\n", le16_to_cpu(ns->npda));
+               printf("nows    : %u\n", le16_to_cpu(ns->nows));
+       }
+       printf("nsattr  : %u\n", ns->nsattr);
+       printf("nvmsetid: %d\n", le16_to_cpu(ns->nvmsetid));
+       printf("anagrpid: %u\n", le32_to_cpu(ns->anagrpid));
+       printf("endgid  : %d\n", le16_to_cpu(ns->endgid));
 
-       printf("%-12s %-8x %-26s %-16s ", n->name, n->nsid, usage, format);
+       printf("nguid   : ");
+       for (i = 0; i < 16; i++)
+               printf("%02x", ns->nguid[i]);
+       printf("\n");
 
-       if (ctrl)
-               printf("%s", n->ctrl->name);
-       else {
-               struct nvme_subsystem *s = n->ctrl->subsys;
-               int i;
+       printf("eui64   : ");
+       for (i = 0; i < 8; i++)
+               printf("%02x", ns->eui64[i]);
+       printf("\n");
 
-               for (i = 0; i < s->nr_ctrls; i++)
-                       printf("%s%s", i ? ", " : "", s->ctrls[i].name);
+       for (i = 0; i <= ns->nlbaf; i++) {
+               if (human)
+                       printf("LBA Format %2d : Metadata Size: %-3d bytes - "
+                               "Data Size: %-2d bytes - Relative Performance: %#x %s %s\n", i,
+                               le16_to_cpu(ns->lbaf[i].ms), 1 << ns->lbaf[i].ds, ns->lbaf[i].rp,
+                               ns->lbaf[i].rp == 3 ? "Degraded" :
+                               ns->lbaf[i].rp == 2 ? "Good" :
+                               ns->lbaf[i].rp == 1 ? "Better" : "Best",
+                               i == (ns->flbas & 0xf) ? "(in use)" : "");
+               else
+                       printf("lbaf %2d : ms:%-3d lbads:%-2d rp:%#x %s\n", i,
+                               le16_to_cpu(ns->lbaf[i].ms), ns->lbaf[i].ds, ns->lbaf[i].rp,
+                               i == (ns->flbas & 0xf) ? "(in use)" : "");
+       }
+       if (vs) {
+               printf("vs[]:\n");
+               d(ns->vs, sizeof(ns->vs), 16, 1);
        }
-       printf("\n");
 }
 
-static void show_detailed_list(struct nvme_topology *t)
+
+static void json_nvme_id_ns_descs(void *data)
 {
-       int i, j, k;
+       /* large enough to hold uuid str (37) or nguid str (32) + zero byte */
+       char json_str[40];
+       char *json_str_p;
 
-       printf("NVM Express Subsystems\n\n");
-       printf("%-16s %-96s %-.16s\n", "Subsystem", "Subsystem-NQN", "Controllers");
-       printf("%-.16s %-.96s %-.16s\n", dash, dash, dash);
-       for (i = 0; i < t->nr_subsystems; i++) {
-               struct nvme_subsystem *s = &t->subsystems[i];
+       union {
+               __u8 eui64[NVME_NIDT_EUI64_LEN];
+               __u8 nguid[NVME_NIDT_NGUID_LEN];
 
-               printf("%-16s %-96s ", s->name, s->subsysnqn);
-               for (j = 0; j < s->nr_ctrls; j++) {
-                       struct nvme_ctrl *c = &s->ctrls[j];
+#ifdef LIBUUID
+               uuid_t uuid;
+#endif
+       } desc;
 
-                       printf("%s%s", j ? ", " : "", c->name);
-               }
-               printf("\n");
-       };
+       struct json_object *root;
+       struct json_array *json_array = NULL;
 
-       printf("\nNVM Express Controllers\n\n");
-       printf("%-8s %-20s %-40s %-8s %-6s %-14s %-12s %-16s\n", "Device",
-               "SN", "MN", "FR", "TxPort", "Address", "Subsystem", "Namespaces");
-       printf("%-.8s %-.20s %-.40s %-.8s %-.6s %-.14s %-.12s %-.16s\n", dash, dash,
-               dash, dash, dash, dash, dash, dash);
-       for (i = 0; i < t->nr_subsystems; i++) {
-               struct nvme_subsystem *s = &t->subsystems[i];
+       off_t off;
+       int pos, len = 0;
+       int i;
 
-               for (j = 0; j < s->nr_ctrls; j++) {
-                       bool comma = false;
-                       struct nvme_ctrl *c = &s->ctrls[j];
+       for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
+               struct nvme_ns_id_desc *cur = data + pos;
+               const char *nidt_name = NULL;
 
-                       printf("%-8s %-.20s %-.40s %-.8s %-6s %-14s %-12s ",
-                               c->name, c->id.sn, c->id.mn, c->id.fr,
-                               c->transport, c->address, s->name);
+               if (cur->nidl == 0)
+                       break;
 
-                       for (k = 0; k < c->nr_namespaces; k++) {
-                               struct nvme_namespace *n = &c->namespaces[k];
-                               printf("%s%s", comma ? ", " : "", n->name);
-                               comma = true;
-                       }
-                       for (k = 0; k < s->nr_namespaces; k++) {
-                               struct nvme_namespace *n = &s->namespaces[k];
-                               printf("%s%s", comma ? ", " : "", n->name);
-                               comma = true;
-                       }
-                       printf("\n");
-               }
-       }
+               memset(json_str, 0, sizeof(json_str));
+               json_str_p = json_str;
+               off = pos + sizeof(*cur);
 
-       printf("\nNVM Express Namespaces\n\n");
-       printf("%-12s %-8s %-26s %-16s %-16s\n", "Device", "NSID", "Usage", "Format", "Controllers");
-       printf("%-.12s %-.8s %-.26s %-.16s %-.16s\n", dash, dash, dash, dash, dash);
+               switch (cur->nidt) {
+               case NVME_NIDT_EUI64:
+                       memcpy(desc.eui64, data + off, sizeof(desc.eui64));
+                       for (i = 0; i < sizeof(desc.eui64); i++)
+                               json_str_p += sprintf(json_str_p, "%02x", desc.eui64[i]);
+                       len += sizeof(desc.eui64);
+                       nidt_name = "eui64";
+                       break;
 
-       for (i = 0; i < t->nr_subsystems; i++) {
-               struct nvme_subsystem *s = &t->subsystems[i];
+               case NVME_NIDT_NGUID:
+                       memcpy(desc.nguid, data + off, sizeof(desc.nguid));
+                       for (i = 0; i < sizeof(desc.nguid); i++)
+                               json_str_p += sprintf(json_str_p, "%02x", desc.nguid[i]);
+                       len += sizeof(desc.nguid);
+                       nidt_name = "nguid";
+                       break;
 
-               for (j = 0; j < s->nr_ctrls; j++) {
-                       struct nvme_ctrl *c = &s->ctrls[j];
+#ifdef LIBUUID
+               case NVME_NIDT_UUID:
+                       memcpy(desc.uuid, data + off, sizeof(desc.uuid));
+                       uuid_unparse_lower(desc.uuid, json_str);
+                       len += sizeof(desc.uuid);
+                       nidt_name = "uuid";
+                       break;
+#endif
+               default:
+                       /* Skip unnkown types */
+                       len = cur->nidl;
+                       break;
+               }
 
-                       for (k = 0; k < c->nr_namespaces; k++) {
-                               struct nvme_namespace *n = &c->namespaces[k];
-                               show_details_ns(n, true);
+               if (nidt_name) {
+                       struct json_object *elem = json_create_object();
+
+                       json_object_add_value_int(elem, "loc", pos);
+                       json_object_add_value_int(elem, "nidt", (int)cur->nidt);
+                       json_object_add_value_int(elem, "nidl", (int)cur->nidl);
+                       json_object_add_value_string(elem, "type", nidt_name);
+                       json_object_add_value_string(elem, nidt_name, json_str);
+
+                       if (!json_array) {
+                               json_array = json_create_array();
                        }
+                       json_array_add_value_object(json_array, elem);
                }
-               for (j = 0; j < s->nr_namespaces; j++) {
-                       struct nvme_namespace *n = &s->namespaces[j];
-                       show_details_ns(n, false);
-               }
-       }
-}
 
-void show_list_items(struct nvme_topology *t, unsigned verbose)
-{
-       switch (verbose) {
-       case 0:
-               show_simple_list(t);
-               break;
-       case 1:
-       default:
-               show_detailed_list(t);
-               break;
+               len += sizeof(*cur);
        }
-}
-
-static void json_simple_ns(struct nvme_namespace *n, struct json_array *devices)
-{
-       struct json_object *device_attrs;
-       char formatter[41] = { 0 };
-       double nsze, nuse;
-       int index = -1;
-       long long lba;
-       char *devnode;
 
-       if (asprintf(&devnode, "/dev/%s", n->name) < 0)
-               return;
+       root = json_create_object();
 
-       device_attrs = json_create_object();
-       json_object_add_value_int(device_attrs, "NameSpace", n->nsid);
+       if (json_array)
+               json_object_add_value_array(root, "ns-descs", json_array);
 
-       json_object_add_value_string(device_attrs, "DevicePath", devnode);
-       free(devnode);
+       json_print_object(root, NULL);
+       printf("\n");
 
-       format(formatter, sizeof(formatter),
-                          n->ctrl->id.fr,
-                          sizeof(n->ctrl->id.fr));
+       json_free_object(root);
+}
 
-       json_object_add_value_string(device_attrs, "Firmware", formatter);
+void nvme_show_id_ns_descs(void *data, unsigned nsid, enum nvme_print_flags flags)
+{
+       int pos, len = 0;
+       int i;
+#ifdef LIBUUID
+       uuid_t uuid;
+       char uuid_str[37];
+#endif
+       __u8 eui64[8];
+       __u8 nguid[16];
 
-       if (sscanf(n->ctrl->name, "nvme%d", &index) == 1)
-               json_object_add_value_int(device_attrs, "Index", index);
+       if (flags & BINARY)
+               return  d_raw((unsigned char *)data, 0x1000);
+       if (flags & JSON)
+               return json_nvme_id_ns_descs(data);
 
-       format(formatter, sizeof(formatter),
-                      n->ctrl->id.mn,
-                      sizeof(n->ctrl->id.mn));
+       printf("NVME Namespace Identification Descriptors NS %d:\n", nsid);
+       for (pos = 0; pos < NVME_IDENTIFY_DATA_SIZE; pos += len) {
+               struct nvme_ns_id_desc *cur = data + pos;
 
-       json_object_add_value_string(device_attrs, "ModelNumber", formatter);
+               if (cur->nidl == 0)
+                       break;
 
-       if (index >= 0) {
-               char *product = nvme_product_name(index);
+               switch (cur->nidt) {
+               case NVME_NIDT_EUI64:
+                       memcpy(eui64, data + pos + sizeof(*cur), sizeof(eui64));
+                       printf("eui64   : ");
+                       for (i = 0; i < 8; i++)
+                               printf("%02x", eui64[i]);
+                       printf("\n");
+                       len += sizeof(eui64);
+                       break;
+               case NVME_NIDT_NGUID:
+                       memcpy(nguid, data + pos + sizeof(*cur), sizeof(nguid));
+                       printf("nguid   : ");
+                       for (i = 0; i < 16; i++)
+                               printf("%02x", nguid[i]);
+                       printf("\n");
+                       len += sizeof(nguid);
+                       break;
+#ifdef LIBUUID
+               case NVME_NIDT_UUID:
+                       memcpy(uuid, data + pos + sizeof(*cur), 16);
+                       uuid_unparse_lower(uuid, uuid_str);
+                       printf("uuid    : %s\n", uuid_str);
+                       len += sizeof(uuid);
+                       break;
+#endif
+               default:
+                       /* Skip unnkown types */
+                       len = cur->nidl;
+                       break;
+               }
 
-               json_object_add_value_string(device_attrs, "ProductName", product);
-               free((void*)product);
+               len += sizeof(*cur);
        }
-
-       format(formatter, sizeof(formatter),
-              n->ctrl->id.sn,
-              sizeof(n->ctrl->id.sn));
-
-       json_object_add_value_string(device_attrs, "SerialNumber", formatter);
-
-       lba = 1 << n->ns.lbaf[(n->ns.flbas & 0x0f)].ds;
-       nsze = le64_to_cpu(n->ns.nsze) * lba;
-       nuse = le64_to_cpu(n->ns.nuse) * lba;
-
-       json_object_add_value_uint(device_attrs, "UsedBytes", nuse);
-       json_object_add_value_uint(device_attrs, "MaximumLBA",
-                                 le64_to_cpu(n->ns.nsze));
-       json_object_add_value_uint(device_attrs, "PhysicalSize", nsze);
-       json_object_add_value_uint(device_attrs, "SectorSize", lba);
-
-       json_array_add_value_object(devices, device_attrs);
 }
 
-static void json_simple_list(struct nvme_topology *t)
+static void print_ps_power_and_scale(__le16 ctr_power, __u8 scale)
 {
-       struct json_object *root;
-       struct json_array *devices;
-       int i, j, k;
-
-       root = json_create_object();
-       devices = json_create_array();
-       for (i = 0; i < t->nr_subsystems; i++) {
-               struct nvme_subsystem *s = &t->subsystems[i];
+       __u16 power = le16_to_cpu(ctr_power);
 
-               for (j = 0; j < s->nr_ctrls; j++) {
-                       struct nvme_ctrl *c = &s->ctrls[j];
+       switch (scale & 0x3) {
+       case 0:
+               /* Not reported for this power state */
+               printf("-");
+               break;
 
-                       for (k = 0; k < c->nr_namespaces; k++) {
-                               struct nvme_namespace *n = &c->namespaces[k];
-                               json_simple_ns(n, devices);
-                       }
-               }
+       case 1:
+               /* Units of 0.0001W */
+               printf("%01u.%04uW", power / 10000, power % 10000);
+               break;
 
-               for (j = 0; j < s->nr_namespaces; j++) {
-                       struct nvme_namespace *n = &s->namespaces[j];
-                       json_simple_ns(n, devices);
-               }
+       case 2:
+               /* Units of 0.01W */
+               printf("%01u.%02uW", power / 100, scale % 100);
+               break;
+
+       default:
+               printf("reserved");
        }
-       json_object_add_value_array(root, "Devices", devices);
-       json_print_object(root, NULL);
 }
 
-static void json_detail_ns(struct nvme_namespace *n, struct json_object *ns_attrs)
+static void nvme_show_id_ctrl_power(struct nvme_id_ctrl *ctrl)
 {
-       long long lba;
-       double nsze, nuse;
-
-       lba = 1 << n->ns.lbaf[(n->ns.flbas & 0x0f)].ds;
-       nsze = le64_to_cpu(n->ns.nsze) * lba;
-       nuse = le64_to_cpu(n->ns.nuse) * lba;
+       int i;
 
-       json_object_add_value_string(ns_attrs, "NameSpace", n->name);
-       json_object_add_value_uint(ns_attrs, "NSID", n->nsid);
 
-       json_object_add_value_uint(ns_attrs, "UsedBytes", nuse);
-       json_object_add_value_uint(ns_attrs, "MaximumLBA",
-               le64_to_cpu(n->ns.nsze));
-       json_object_add_value_uint(ns_attrs, "PhysicalSize", nsze);
-       json_object_add_value_uint(ns_attrs, "SectorSize", lba);
-}
+       for (i = 0; i <= ctrl->npss; i++) {
+               __u16 max_power = le16_to_cpu(ctrl->psd[i].max_power);
 
-static void json_detail_list(struct nvme_topology *t)
-{
-       int i, j, k;
-       struct json_object *root;
-       struct json_array *devices;
-       char formatter[41] = { 0 };
+               printf("ps %4d : mp:", i);
 
-       root = json_create_object();
-       devices = json_create_array();
+               if (ctrl->psd[i].flags & NVME_PS_FLAGS_MAX_POWER_SCALE)
+                       printf("%01u.%04uW ", max_power / 10000, max_power % 10000);
+               else
+                       printf("%01u.%02uW ", max_power / 100, max_power % 100);
 
-       for (i = 0; i < t->nr_subsystems; i++) {
-               struct nvme_subsystem *s = &t->subsystems[i];
-               struct json_object *subsys_attrs;
-               struct json_array *namespaces, *ctrls;
+               if (ctrl->psd[i].flags & NVME_PS_FLAGS_NON_OP_STATE)
+                       printf("non-");
 
-               subsys_attrs = json_create_object();
-               json_object_add_value_string(subsys_attrs, "Subsystem", s->name);
-               json_object_add_value_string(subsys_attrs, "SubsystemNQN", s->subsysnqn);
+               printf("operational enlat:%d exlat:%d rrt:%d rrl:%d\n"
+                       "          rwt:%d rwl:%d idle_power:",
+                       le32_to_cpu(ctrl->psd[i].entry_lat), le32_to_cpu(ctrl->psd[i].exit_lat),
+                       ctrl->psd[i].read_tput, ctrl->psd[i].read_lat,
+                       ctrl->psd[i].write_tput, ctrl->psd[i].write_lat);
+               print_ps_power_and_scale(ctrl->psd[i].idle_power,
+                                        POWER_SCALE(ctrl->psd[i].idle_scale));
+               printf(" active_power:");
+               print_ps_power_and_scale(ctrl->psd[i].active_power,
+                                        POWER_SCALE(ctrl->psd[i].active_work_scale));
+               printf("\n");
 
-               ctrls = json_create_array();
-               json_object_add_value_array(subsys_attrs, "Controllers", ctrls);
-               for (j = 0; j < s->nr_ctrls; j++) {
-                       struct json_object *ctrl_attrs = json_create_object();
-                       struct nvme_ctrl *c = &s->ctrls[j];
-                       struct json_array *namespaces;
+       }
+}
 
-                       json_object_add_value_string(ctrl_attrs, "Controller", c->name);
-                       json_object_add_value_string(ctrl_attrs, "Transport", c->transport);
-                       json_object_add_value_string(ctrl_attrs, "Address", c->address);
-                       json_object_add_value_string(ctrl_attrs, "State", c->state);
+void __nvme_show_id_ctrl(struct nvme_id_ctrl *ctrl, enum nvme_print_flags flags,
+                       void (*vendor_show)(__u8 *vs, struct json_object *root))
+{
+       int human = flags & VERBOSE, vs = flags & VS;
 
-                       format(formatter, sizeof(formatter), c->id.fr, sizeof(c->id.fr));
-                       json_object_add_value_string(ctrl_attrs, "Firmware", formatter);
+       if (flags & BINARY)
+               return d_raw((unsigned char *)ctrl, sizeof(*ctrl));
+       else if (flags & JSON)
+               return json_nvme_id_ctrl(ctrl, flags, vendor_show);
 
-                       format(formatter, sizeof(formatter), c->id.mn, sizeof(c->id.mn));
-                       json_object_add_value_string(ctrl_attrs, "ModelNumber", formatter);
+       printf("NVME Identify Controller:\n");
+       printf("vid       : %#x\n", le16_to_cpu(ctrl->vid));
+       printf("ssvid     : %#x\n", le16_to_cpu(ctrl->ssvid));
+       printf("sn        : %-.*s\n", (int)sizeof(ctrl->sn), ctrl->sn);
+       printf("mn        : %-.*s\n", (int)sizeof(ctrl->mn), ctrl->mn);
+       printf("fr        : %-.*s\n", (int)sizeof(ctrl->fr), ctrl->fr);
+       printf("rab       : %d\n", ctrl->rab);
+       printf("ieee      : %02x%02x%02x\n",
+               ctrl->ieee[2], ctrl->ieee[1], ctrl->ieee[0]);
+       printf("cmic      : %#x\n", ctrl->cmic);
+       if (human)
+               nvme_show_id_ctrl_cmic(ctrl->cmic);
+       printf("mdts      : %d\n", ctrl->mdts);
+       printf("cntlid    : %#x\n", le16_to_cpu(ctrl->cntlid));
+       printf("ver       : %#x\n", le32_to_cpu(ctrl->ver));
+       printf("rtd3r     : %#x\n", le32_to_cpu(ctrl->rtd3r));
+       printf("rtd3e     : %#x\n", le32_to_cpu(ctrl->rtd3e));
+       printf("oaes      : %#x\n", le32_to_cpu(ctrl->oaes));
+       if (human)
+               nvme_show_id_ctrl_oaes(ctrl->oaes);
+       printf("ctratt    : %#x\n", le32_to_cpu(ctrl->ctratt));
+       if (human)
+               nvme_show_id_ctrl_ctratt(ctrl->ctratt);
+       printf("rrls      : %#x\n", le16_to_cpu(ctrl->rrls));
+       printf("cntrltype : %d\n", ctrl->cntrltype);
+       if (human)
+               nvme_show_id_ctrl_cntrltype(ctrl->cntrltype);
+       printf("fguid     : %-.*s\n", (int)sizeof(ctrl->fguid), ctrl->fguid);
+       printf("crdt1     : %u\n", le16_to_cpu(ctrl->crdt1));
+       printf("crdt2     : %u\n", le16_to_cpu(ctrl->crdt2));
+       printf("crdt3     : %u\n", le16_to_cpu(ctrl->crdt3));
 
-                       format(formatter, sizeof(formatter), c->id.sn, sizeof(c->id.sn));
-                       json_object_add_value_string(ctrl_attrs, "SerialNumber", formatter);
+       printf("oacs      : %#x\n", le16_to_cpu(ctrl->oacs));
+       if (human)
+               nvme_show_id_ctrl_oacs(ctrl->oacs);
+       printf("acl       : %d\n", ctrl->acl);
+       printf("aerl      : %d\n", ctrl->aerl);
+       printf("frmw      : %#x\n", ctrl->frmw);
+       if (human)
+               nvme_show_id_ctrl_frmw(ctrl->frmw);
+       printf("lpa       : %#x\n", ctrl->lpa);
+       if (human)
+               nvme_show_id_ctrl_lpa(ctrl->lpa);
+       printf("elpe      : %d\n", ctrl->elpe);
+       printf("npss      : %d\n", ctrl->npss);
+       printf("avscc     : %#x\n", ctrl->avscc);
+       if (human)
+               nvme_show_id_ctrl_avscc(ctrl->avscc);
+       printf("apsta     : %#x\n", ctrl->apsta);
+       if (human)
+               nvme_show_id_ctrl_apsta(ctrl->apsta);
+       printf("wctemp    : %d\n", le16_to_cpu(ctrl->wctemp));
+       printf("cctemp    : %d\n", le16_to_cpu(ctrl->cctemp));
+       printf("mtfa      : %d\n", le16_to_cpu(ctrl->mtfa));
+       printf("hmpre     : %d\n", le32_to_cpu(ctrl->hmpre));
+       printf("hmmin     : %d\n", le32_to_cpu(ctrl->hmmin));
+       printf("tnvmcap   : %.0Lf\n", int128_to_double(ctrl->tnvmcap));
+       printf("unvmcap   : %.0Lf\n", int128_to_double(ctrl->unvmcap));
+       printf("rpmbs     : %#x\n", le32_to_cpu(ctrl->rpmbs));
+       if (human)
+               nvme_show_id_ctrl_rpmbs(ctrl->rpmbs);
+       printf("edstt     : %d\n", le16_to_cpu(ctrl->edstt));
+       printf("dsto      : %d\n", ctrl->dsto);
+       printf("fwug      : %d\n", ctrl->fwug);
+       printf("kas       : %d\n", le16_to_cpu(ctrl->kas));
+       printf("hctma     : %#x\n", le16_to_cpu(ctrl->hctma));
+       if (human)
+               nvme_show_id_ctrl_hctma(ctrl->hctma);
+       printf("mntmt     : %d\n", le16_to_cpu(ctrl->mntmt));
+       printf("mxtmt     : %d\n", le16_to_cpu(ctrl->mxtmt));
+       printf("sanicap   : %#x\n", le32_to_cpu(ctrl->sanicap));
+       if (human)
+               nvme_show_id_ctrl_sanicap(ctrl->sanicap);
+       printf("hmminds   : %d\n", le32_to_cpu(ctrl->hmminds));
+       printf("hmmaxd    : %d\n", le16_to_cpu(ctrl->hmmaxd));
+       printf("nsetidmax : %d\n", le16_to_cpu(ctrl->nsetidmax));
+       printf("endgidmax : %d\n", le16_to_cpu(ctrl->endgidmax));
+       printf("anatt     : %d\n", ctrl->anatt);
+       printf("anacap    : %d\n", ctrl->anacap);
+       if (human)
+               nvme_show_id_ctrl_anacap(ctrl->anacap);
+       printf("anagrpmax : %d\n", ctrl->anagrpmax);
+       printf("nanagrpid : %d\n", le32_to_cpu(ctrl->nanagrpid));
+       printf("pels      : %d\n", le32_to_cpu(ctrl->pels));
+       printf("sqes      : %#x\n", ctrl->sqes);
+       if (human)
+               nvme_show_id_ctrl_sqes(ctrl->sqes);
+       printf("cqes      : %#x\n", ctrl->cqes);
+       if (human)
+               nvme_show_id_ctrl_cqes(ctrl->cqes);
+       printf("maxcmd    : %d\n", le16_to_cpu(ctrl->maxcmd));
+       printf("nn        : %d\n", le32_to_cpu(ctrl->nn));
+       printf("oncs      : %#x\n", le16_to_cpu(ctrl->oncs));
+       if (human)
+               nvme_show_id_ctrl_oncs(ctrl->oncs);
+       printf("fuses     : %#x\n", le16_to_cpu(ctrl->fuses));
+       if (human)
+               nvme_show_id_ctrl_fuses(ctrl->fuses);
+       printf("fna       : %#x\n", ctrl->fna);
+       if (human)
+               nvme_show_id_ctrl_fna(ctrl->fna);
+       printf("vwc       : %#x\n", ctrl->vwc);
+       if (human)
+               nvme_show_id_ctrl_vwc(ctrl->vwc);
+       printf("awun      : %d\n", le16_to_cpu(ctrl->awun));
+       printf("awupf     : %d\n", le16_to_cpu(ctrl->awupf));
+       printf("nvscc     : %d\n", ctrl->nvscc);
+       if (human)
+               nvme_show_id_ctrl_nvscc(ctrl->nvscc);
+       printf("nwpc      : %d\n", ctrl->nwpc);
+       if (human)
+               nvme_show_id_ctrl_nwpc(ctrl->nwpc);
+       printf("acwu      : %d\n", le16_to_cpu(ctrl->acwu));
+       printf("sgls      : %#x\n", le32_to_cpu(ctrl->sgls));
+       if (human)
+               nvme_show_id_ctrl_sgls(ctrl->sgls);
+       printf("mnan      : %d\n", le32_to_cpu(ctrl->mnan));
+       printf("subnqn    : %-.*s\n", (int)sizeof(ctrl->subnqn), ctrl->subnqn);
+       printf("ioccsz    : %d\n", le32_to_cpu(ctrl->ioccsz));
+       printf("iorcsz    : %d\n", le32_to_cpu(ctrl->iorcsz));
+       printf("icdoff    : %d\n", le16_to_cpu(ctrl->icdoff));
+       printf("ctrattr   : %#x\n", ctrl->ctrattr);
+       if (human)
+               nvme_show_id_ctrl_ctrattr(ctrl->ctrattr);
+       printf("msdbd     : %d\n", ctrl->msdbd);
 
-                       namespaces = json_create_array();
+       nvme_show_id_ctrl_power(ctrl);
+       if (vendor_show)
+               vendor_show(ctrl->vs, NULL);
+       else if (vs) {
+               printf("vs[]:\n");
+               d(ctrl->vs, sizeof(ctrl->vs), 16, 1);
+       }
+}
 
-                       for (k = 0; k < c->nr_namespaces; k++) {
-                               struct json_object *ns_attrs = json_create_object();
-                               struct nvme_namespace *n = &c->namespaces[k];
+void nvme_show_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode)
+{
+       __nvme_show_id_ctrl(ctrl, mode, NULL);
+}
 
-                               json_detail_ns(n, ns_attrs);
-                               json_array_add_value_object(namespaces, ns_attrs);
-                       }
-                       if (k)
-                               json_object_add_value_array(ctrl_attrs, "Namespaces", namespaces);
-                       else
-                               json_free_array(namespaces);
+static void json_nvme_id_nvmset(struct nvme_id_nvmset *nvmset)
+{
+       struct json_object *root;
+       struct json_array *entries;
+       __u32 nent = nvmset->nid;
+       int i;
 
-                       json_array_add_value_object(ctrls, ctrl_attrs);
-               }
+       root = json_create_object();
 
-               namespaces = json_create_array();
-               for (k = 0; k < s->nr_namespaces; k++) {
-                       struct json_object *ns_attrs = json_create_object();
-                       struct nvme_namespace *n = &s->namespaces[k];
+       json_object_add_value_int(root, "nid", nent);
 
-                       json_detail_ns(n, ns_attrs);
-                       json_array_add_value_object(namespaces, ns_attrs);
-               }
-               if (k)
-                       json_object_add_value_array(subsys_attrs, "Namespaces", namespaces);
-               else
-                       json_free_array(namespaces);
+       entries = json_create_array();
+       for (i = 0; i < nent; i++) {
+               struct json_object *entry = json_create_object();
 
-               json_array_add_value_object(devices, subsys_attrs);
+               json_object_add_value_int(entry, "nvmset_id",
+                                         le16_to_cpu(nvmset->ent[i].id));
+               json_object_add_value_int(entry, "endurance_group_id",
+                                         le16_to_cpu(nvmset->ent[i].endurance_group_id));
+               json_object_add_value_int(entry, "random_4k_read_typical",
+                                         le32_to_cpu(nvmset->ent[i].random_4k_read_typical));
+               json_object_add_value_int(entry, "optimal_write_size",
+                                         le32_to_cpu(nvmset->ent[i].opt_write_size));
+               json_object_add_value_float(entry, "total_nvmset_cap",
+                                           int128_to_double(nvmset->ent[i].total_nvmset_cap));
+               json_object_add_value_float(entry, "unalloc_nvmset_cap",
+                                           int128_to_double(nvmset->ent[i].unalloc_nvmset_cap));
+               json_array_add_value_object(entries, entry);
        }
 
-       json_object_add_value_array(root, "Devices", devices);
+       json_object_add_value_array(root, "NVMSet", entries);
        json_print_object(root, NULL);
        printf("\n");
        json_free_object(root);
 }
 
-void json_print_list_items(struct nvme_topology *t, unsigned verbose)
+void nvme_show_id_nvmset(struct nvme_id_nvmset *nvmset, unsigned nvmset_id,
+       enum nvme_print_flags flags)
 {
-       switch (verbose) {
-       case 0:
-               json_simple_list(t);
-               break;
-       default:
-               json_detail_list(t);
-               break;
+       int i;
+
+       if (flags & BINARY)
+               return d_raw((unsigned char *)nvmset, sizeof(*nvmset));
+       if (flags & JSON)
+               return json_nvme_id_nvmset(nvmset);
+
+       printf("NVME Identify NVM Set List %d:\n", nvmset_id);
+       printf("nid     : %d\n", nvmset->nid);
+       printf(".................\n");
+       for (i = 0; i < nvmset->nid; i++) {
+               printf(" NVM Set Attribute Entry[%2d]\n", i);
+               printf(".................\n");
+               printf("nvmset_id               : %d\n",
+                               le16_to_cpu(nvmset->ent[i].id));
+               printf("enduracne_group_id      : %d\n",
+                               le16_to_cpu(nvmset->ent[i].endurance_group_id));
+               printf("random_4k_read_typical  : %u\n",
+                               le32_to_cpu(nvmset->ent[i].random_4k_read_typical));
+               printf("optimal_write_size      : %u\n",
+                               le32_to_cpu(nvmset->ent[i].opt_write_size));
+               printf("total_nvmset_cap        : %.0Lf\n",
+                               int128_to_double(nvmset->ent[i].total_nvmset_cap));
+               printf("unalloc_nvmset_cap      : %.0Lf\n",
+                               int128_to_double(nvmset->ent[i].unalloc_nvmset_cap));
+               printf(".................\n");
        }
 }
 
-void json_nvme_id_ns(struct nvme_id_ns *ns, unsigned int mode)
+static void json_nvme_list_secondary_ctrl(const struct nvme_secondary_controllers_list *sc_list,
+                                         __u32 count)
 {
-       char nguid_buf[2 * sizeof(ns->nguid) + 1], eui64_buf[2 * sizeof(ns->eui64) + 1];
-       char *nguid = nguid_buf, *eui64 = eui64_buf;
-       struct json_object *root;
-       struct json_array *lbafs;
        int i;
-
-       long double nvmcap = int128_to_double(ns->nvmcap);
+       struct json_object *root;
+       struct json_array *entries;
+       __u32 nent = min(sc_list->num, count);
+       const struct nvme_secondary_controller_entry *sc_entry = &sc_list->sc_entry[0];
 
        root = json_create_object();
 
-       json_object_add_value_uint(root, "nsze", le64_to_cpu(ns->nsze));
-       json_object_add_value_uint(root, "ncap", le64_to_cpu(ns->ncap));
-       json_object_add_value_uint(root, "nuse", le64_to_cpu(ns->nuse));
-       json_object_add_value_int(root, "nsfeat", ns->nsfeat);
-       json_object_add_value_int(root, "nlbaf", ns->nlbaf);
-       json_object_add_value_int(root, "flbas", ns->flbas);
-       json_object_add_value_int(root, "mc", ns->mc);
-       json_object_add_value_int(root, "dpc", ns->dpc);
-       json_object_add_value_int(root, "dps", ns->dps);
-       json_object_add_value_int(root, "nmic", ns->nmic);
-       json_object_add_value_int(root, "rescap", ns->rescap);
-       json_object_add_value_int(root, "fpi", ns->fpi);
-       json_object_add_value_int(root, "nawun", le16_to_cpu(ns->nawun));
-       json_object_add_value_int(root, "nawupf", le16_to_cpu(ns->nawupf));
-       json_object_add_value_int(root, "nacwu", le16_to_cpu(ns->nacwu));
-       json_object_add_value_int(root, "nabsn", le16_to_cpu(ns->nabsn));
-       json_object_add_value_int(root, "nabo", le16_to_cpu(ns->nabo));
-       json_object_add_value_int(root, "nabspf", le16_to_cpu(ns->nabspf));
-       json_object_add_value_int(root, "noiob", le16_to_cpu(ns->noiob));
-       json_object_add_value_float(root, "nvmcap", nvmcap);
-       json_object_add_value_int(root, "nsattr", ns->nsattr);
-       json_object_add_value_int(root, "nvmsetid", le16_to_cpu(ns->nvmsetid));
+       json_object_add_value_int(root, "num", nent);
 
-       if (ns->nsfeat & 0x10) {
-               json_object_add_value_int(root, "npwg", le16_to_cpu(ns->npwg));
-               json_object_add_value_int(root, "npwa", le16_to_cpu(ns->npwa));
-               json_object_add_value_int(root, "npdg", le16_to_cpu(ns->npdg));
-               json_object_add_value_int(root, "npda", le16_to_cpu(ns->npda));
-               json_object_add_value_int(root, "nows", le16_to_cpu(ns->nows));
-       }
+       entries = json_create_array();
+       for (i = 0; i < nent; i++) {
+               struct json_object *entry = json_create_object();
 
-       json_object_add_value_int(root, "anagrpid", le32_to_cpu(ns->anagrpid));
-       json_object_add_value_int(root, "endgid", le16_to_cpu(ns->endgid));
+               json_object_add_value_int(entry, "secondary-controller-identifier", le16_to_cpu(sc_entry[i].scid));
+               json_object_add_value_int(entry, "primary-controller-identifier", le16_to_cpu(sc_entry[i].pcid));
+               json_object_add_value_int(entry, "secondary-controller-state",
+                                         sc_entry[i].scs);
+               json_object_add_value_int(entry, "virtual-function-number",  le16_to_cpu(sc_entry[i].vfn));
+               json_object_add_value_int(entry, "num-virtual-queues",  le16_to_cpu(sc_entry[i].nvq));
+               json_object_add_value_int(entry, "num-virtual-interrupts",  le16_to_cpu(sc_entry[i].nvi));
+               json_array_add_value_object(entries, entry);
+       }
 
-       memset(eui64, 0, sizeof(eui64_buf));
-       for (i = 0; i < sizeof(ns->eui64); i++)
-               eui64 += sprintf(eui64, "%02x", ns->eui64[i]);
+       json_object_add_value_array(root, "secondary-controllers", entries);
 
-       memset(nguid, 0, sizeof(nguid_buf));
-       for (i = 0; i < sizeof(ns->nguid); i++)
-               nguid += sprintf(nguid, "%02x", ns->nguid[i]);
+       json_print_object(root, NULL);
+       printf("\n");
+       json_free_object(root);
+}
 
-       json_object_add_value_string(root, "eui64", eui64_buf);
-       json_object_add_value_string(root, "nguid", nguid_buf);
+void nvme_show_list_secondary_ctrl(const struct nvme_secondary_controllers_list *sc_list,
+       __u32 count, enum nvme_print_flags flags)
+{
+       const struct nvme_secondary_controller_entry *sc_entry = &sc_list->sc_entry[0];
+       static const char * const state_desc[] = { "Offline", "Online" };
 
-       lbafs = json_create_array();
-       json_object_add_value_array(root, "lbafs", lbafs);
+       __u16 num = sc_list->num;
+       __u32 entries = min(num, count);
+       int i;
 
-       for (i = 0; i <= ns->nlbaf; i++) {
-               struct json_object *lbaf = json_create_object();
+       if (flags & BINARY)
+               return d_raw((unsigned char *)sc_list, sizeof(*sc_list));
+       if (flags & JSON)
+               return json_nvme_list_secondary_ctrl(sc_list, entries);
 
-               json_object_add_value_int(lbaf, "ms", le16_to_cpu(ns->lbaf[i].ms));
-               json_object_add_value_int(lbaf, "ds", ns->lbaf[i].ds);
-               json_object_add_value_int(lbaf, "rp", ns->lbaf[i].rp);
+       printf("Identify Secondary Controller List:\n");
+       printf("   NUMID       : Number of Identifiers           : %d\n", num);
 
-               json_array_add_value_object(lbafs, lbaf);
+       for (i = 0; i < entries; i++) {
+               printf("   SCEntry[%-3d]:\n", i);
+               printf("................\n");
+               printf("     SCID      : Secondary Controller Identifier : 0x%.04x\n",
+                               le16_to_cpu(sc_entry[i].scid));
+               printf("     PCID      : Primary Controller Identifier   : 0x%.04x\n",
+                               le16_to_cpu(sc_entry[i].pcid));
+               printf("     SCS       : Secondary Controller State      : 0x%.04x (%s)\n",
+                               sc_entry[i].scs,
+                               state_desc[sc_entry[i].scs & 0x1]);
+               printf("     VFN       : Virtual Function Number         : 0x%.04x\n",
+                               le16_to_cpu(sc_entry[i].vfn));
+               printf("     NVQ       : Num VQ Flex Resources Assigned  : 0x%.04x\n",
+                               le16_to_cpu(sc_entry[i].nvq));
+               printf("     NVI       : Num VI Flex Resources Assigned  : 0x%.04x\n",
+                               le16_to_cpu(sc_entry[i].nvi));
        }
-
-       json_print_object(root, NULL);
-       printf("\n");
-       json_free_object(root);
 }
 
-void json_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*vs)(__u8 *vs, struct json_object *root))
+static void json_nvme_id_ns_granularity_list(const struct nvme_id_ns_granularity_list *glist)
 {
+       int i;
        struct json_object *root;
-       struct json_array *psds;
-
-       long double tnvmcap = int128_to_double(ctrl->tnvmcap);
-       long double unvmcap = int128_to_double(ctrl->unvmcap);
+       struct json_array *entries;
 
-       char sn[sizeof(ctrl->sn) + 1], mn[sizeof(ctrl->mn) + 1],
-               fr[sizeof(ctrl->fr) + 1], subnqn[sizeof(ctrl->subnqn) + 1];
-       __u32 ieee = ctrl->ieee[2] << 16 | ctrl->ieee[1] << 8 | ctrl->ieee[0];
+       root = json_create_object();
 
-       int i;
+       json_object_add_value_int(root, "attributes", glist->attributes);
+       json_object_add_value_int(root, "num-descriptors", glist->num_descriptors);
 
-       snprintf(sn, sizeof(sn), "%-.*s", (int)sizeof(ctrl->sn), ctrl->sn);
-       snprintf(mn, sizeof(mn), "%-.*s", (int)sizeof(ctrl->mn), ctrl->mn);
-       snprintf(fr, sizeof(fr), "%-.*s", (int)sizeof(ctrl->fr), ctrl->fr);
-       snprintf(subnqn, sizeof(subnqn), "%-.*s", (int)sizeof(ctrl->subnqn), ctrl->subnqn);
+       entries = json_create_array();
+       for (i = 0; i <= glist->num_descriptors; i++) {
+               struct json_object *entry = json_create_object();
 
-       root = json_create_object();
+               json_object_add_value_uint(entry, "namespace-size-granularity",
+                       le64_to_cpu(glist->entry[i].namespace_size_granularity));
+               json_object_add_value_uint(entry, "namespace-capacity-granularity",
+                       le64_to_cpu(glist->entry[i].namespace_capacity_granularity));
+               json_array_add_value_object(entries, entry);
+       }
 
-       json_object_add_value_int(root, "vid", le16_to_cpu(ctrl->vid));
-       json_object_add_value_int(root, "ssvid", le16_to_cpu(ctrl->ssvid));
-       json_object_add_value_string(root, "sn", sn);
-       json_object_add_value_string(root, "mn", mn);
-       json_object_add_value_string(root, "fr", fr);
-       json_object_add_value_int(root, "rab", ctrl->rab);
-       json_object_add_value_int(root, "ieee", ieee);
-       json_object_add_value_int(root, "cmic", ctrl->cmic);
-       json_object_add_value_int(root, "mdts", ctrl->mdts);
-       json_object_add_value_int(root, "cntlid", le16_to_cpu(ctrl->cntlid));
-       json_object_add_value_uint(root, "ver", le32_to_cpu(ctrl->ver));
-       json_object_add_value_uint(root, "rtd3r", le32_to_cpu(ctrl->rtd3r));
-       json_object_add_value_uint(root, "rtd3e", le32_to_cpu(ctrl->rtd3e));
-       json_object_add_value_uint(root, "oaes", le32_to_cpu(ctrl->oaes));
-       json_object_add_value_int(root, "ctratt", le32_to_cpu(ctrl->ctratt));
-       json_object_add_value_int(root, "rrls", le16_to_cpu(ctrl->rrls));
-       json_object_add_value_int(root, "crdt1", le16_to_cpu(ctrl->crdt1));
-       json_object_add_value_int(root, "crdt2", le16_to_cpu(ctrl->crdt2));
-       json_object_add_value_int(root, "crdt3", le16_to_cpu(ctrl->crdt3));
-       json_object_add_value_int(root, "oacs", le16_to_cpu(ctrl->oacs));
-       json_object_add_value_int(root, "acl", ctrl->acl);
-       json_object_add_value_int(root, "aerl", ctrl->aerl);
-       json_object_add_value_int(root, "frmw", ctrl->frmw);
-       json_object_add_value_int(root, "lpa", ctrl->lpa);
-       json_object_add_value_int(root, "elpe", ctrl->elpe);
-       json_object_add_value_int(root, "npss", ctrl->npss);
-       json_object_add_value_int(root, "avscc", ctrl->avscc);
-       json_object_add_value_int(root, "apsta", ctrl->apsta);
-       json_object_add_value_int(root, "wctemp", le16_to_cpu(ctrl->wctemp));
-       json_object_add_value_int(root, "cctemp", le16_to_cpu(ctrl->cctemp));
-       json_object_add_value_int(root, "mtfa", le16_to_cpu(ctrl->mtfa));
-       json_object_add_value_uint(root, "hmpre", le32_to_cpu(ctrl->hmpre));
-       json_object_add_value_uint(root, "hmmin", le32_to_cpu(ctrl->hmmin));
-       json_object_add_value_float(root, "tnvmcap", tnvmcap);
-       json_object_add_value_float(root, "unvmcap", unvmcap);
-       json_object_add_value_uint(root, "rpmbs", le32_to_cpu(ctrl->rpmbs));
-       json_object_add_value_int(root, "edstt", le16_to_cpu(ctrl->edstt));
-       json_object_add_value_int(root, "dsto", ctrl->dsto);
-       json_object_add_value_int(root, "fwug", ctrl->fwug);
-       json_object_add_value_int(root, "kas", le16_to_cpu(ctrl->kas));
-       json_object_add_value_int(root, "hctma", le16_to_cpu(ctrl->hctma));
-       json_object_add_value_int(root, "mntmt", le16_to_cpu(ctrl->mntmt));
-       json_object_add_value_int(root, "mxtmt", le16_to_cpu(ctrl->mxtmt));
-       json_object_add_value_int(root, "sanicap", le32_to_cpu(ctrl->sanicap));
-       json_object_add_value_int(root, "hmminds", le32_to_cpu(ctrl->hmminds));
-       json_object_add_value_int(root, "hmmaxd", le16_to_cpu(ctrl->hmmaxd));
-       json_object_add_value_int(root, "nsetidmax", le16_to_cpu(ctrl->nsetidmax));
+       json_object_add_value_array(root, "namespace-granularity-list", entries);
 
-       json_object_add_value_int(root, "anatt",ctrl->anatt);
-       json_object_add_value_int(root, "anacap", ctrl->anacap);
-       json_object_add_value_int(root, "anagrpmax", le32_to_cpu(ctrl->anagrpmax));
-       json_object_add_value_int(root, "nanagrpid", le32_to_cpu(ctrl->nanagrpid));
-       json_object_add_value_int(root, "sqes", ctrl->sqes);
-       json_object_add_value_int(root, "cqes", ctrl->cqes);
-       json_object_add_value_int(root, "maxcmd", le16_to_cpu(ctrl->maxcmd));
-       json_object_add_value_uint(root, "nn", le32_to_cpu(ctrl->nn));
-       json_object_add_value_int(root, "oncs", le16_to_cpu(ctrl->oncs));
-       json_object_add_value_int(root, "fuses", le16_to_cpu(ctrl->fuses));
-       json_object_add_value_int(root, "fna", ctrl->fna);
-       json_object_add_value_int(root, "vwc", ctrl->vwc);
-       json_object_add_value_int(root, "awun", le16_to_cpu(ctrl->awun));
-       json_object_add_value_int(root, "awupf", le16_to_cpu(ctrl->awupf));
-       json_object_add_value_int(root, "nvscc", ctrl->nvscc);
-       json_object_add_value_int(root, "nwpc", ctrl->nwpc);
-       json_object_add_value_int(root, "acwu", le16_to_cpu(ctrl->acwu));
-       json_object_add_value_int(root, "sgls", le32_to_cpu(ctrl->sgls));
+       json_print_object(root, NULL);
+       printf("\n");
+       json_free_object(root);
+}
 
-       if (strlen(subnqn))
-               json_object_add_value_string(root, "subnqn", subnqn);
+void nvme_show_id_ns_granularity_list(const struct nvme_id_ns_granularity_list *glist,
+       enum nvme_print_flags flags)
+{
+       int i;
 
-       json_object_add_value_int(root, "ioccsz", le32_to_cpu(ctrl->ioccsz));
-       json_object_add_value_int(root, "iorcsz", le32_to_cpu(ctrl->iorcsz));
-       json_object_add_value_int(root, "icdoff", le16_to_cpu(ctrl->icdoff));
-       json_object_add_value_int(root, "ctrattr", ctrl->ctrattr);
-       json_object_add_value_int(root, "msdbd", ctrl->msdbd);
+       if (flags & BINARY)
+               return d_raw((unsigned char *)glist, sizeof(*glist));
+       if (flags & JSON)
+               return json_nvme_id_ns_granularity_list(glist);
 
-       psds = json_create_array();
-       json_object_add_value_array(root, "psds", psds);
+       printf("Identify Namespace Granularity List:\n");
+       printf("   ATTR        : Namespace Granularity Attributes: 0x%x\n", glist->attributes);
+       printf("   NUMD        : Number of Descriptors           : %d\n", glist->num_descriptors);
 
-       for (i = 0; i <= ctrl->npss; i++) {
-               struct json_object *psd = json_create_object();
+       /* Number of Descriptors is a 0's based value */
+       for (i = 0; i <= glist->num_descriptors; i++) {
+               printf("\n     Entry[%2d] :\n", i);
+               printf("................\n");
+               printf("     NSG       : Namespace Size Granularity     : 0x%"PRIx64"\n",
+                               le64_to_cpu(glist->entry[i].namespace_size_granularity));
+               printf("     NCG       : Namespace Capacity Granularity : 0x%"PRIx64"\n",
+                               le64_to_cpu(glist->entry[i].namespace_capacity_granularity));
+       }
+}
 
-               json_object_add_value_int(psd, "max_power",
-                       le16_to_cpu(ctrl->psd[i].max_power));
-               json_object_add_value_int(psd, "flags", ctrl->psd[i].flags);
-               json_object_add_value_uint(psd, "entry_lat",
-                       le32_to_cpu(ctrl->psd[i].entry_lat));
-               json_object_add_value_uint(psd, "exit_lat",
-                       le32_to_cpu(ctrl->psd[i].exit_lat));
-               json_object_add_value_int(psd, "read_tput", ctrl->psd[i].read_tput);
-               json_object_add_value_int(psd, "read_lat", ctrl->psd[i].read_lat);
-               json_object_add_value_int(psd, "write_tput", ctrl->psd[i].write_tput);
-               json_object_add_value_int(psd, "write_lat", ctrl->psd[i].write_lat);
-               json_object_add_value_int(psd, "idle_power",
-                       le16_to_cpu(ctrl->psd[i].idle_power));
-               json_object_add_value_int(psd, "idle_scale", ctrl->psd[i].idle_scale);
-               json_object_add_value_int(psd, "active_power",
-                       le16_to_cpu(ctrl->psd[i].active_power));
-               json_object_add_value_int(psd, "active_work_scale", ctrl->psd[i].active_work_scale);
+static void json_nvme_id_uuid_list(const struct nvme_id_uuid_list *uuid_list)
+{
+       struct json_object *root;
+       struct json_array *entries;
+       int i;
 
-               json_array_add_value_object(psds, psd);
+       root = json_create_object();
+       entries = json_create_array();
+       /* The 0th entry is reserved */
+       for (i = 1; i < NVME_MAX_UUID_ENTRIES; i++) {
+               uuid_t uuid;
+               struct json_object *entry = json_create_object();
+               /* The list is terminated by a zero UUID value */
+               if (memcmp(uuid_list->entry[i].uuid, zero_uuid, sizeof(zero_uuid)) == 0)
+                       break;
+               memcpy(&uuid, uuid_list->entry[i].uuid, sizeof(uuid));
+               json_object_add_value_int(entry, "association", uuid_list->entry[i].header & 0x3);
+               json_object_add_value_string(entry, "uuid", nvme_uuid_to_string(uuid));
+               json_array_add_value_object(entries, entry);
        }
-
-       if(vs)
-               vs(ctrl->vs, root);
+       json_object_add_value_array(root, "UUID-list", entries);
        json_print_object(root, NULL);
        printf("\n");
        json_free_object(root);
 }
 
-void json_error_log(struct nvme_error_log_page *err_log, int entries, const char *devname)
+void nvme_show_id_uuid_list(const struct nvme_id_uuid_list *uuid_list,
+                               enum nvme_print_flags flags)
 {
-       struct json_object *root;
-       struct json_array *errors;
+       int i, human = flags & VERBOSE;
 
-       int i;
+       if (flags & BINARY)
+               return d_raw((unsigned char *)uuid_list, sizeof(*uuid_list));
+       if (flags & JSON)
+               return json_nvme_id_uuid_list(uuid_list);
 
-       root = json_create_object();
+       /* The 0th entry is reserved */
+       printf("NVME Identify UUID:\n");
+       for (i = 1; i < NVME_MAX_UUID_ENTRIES; i++) {
+               uuid_t uuid;
+               char *association = "";
+               uint8_t identifier_association = uuid_list->entry[i].header & 0x3;
+               /* The list is terminated by a zero UUID value */
+               if (memcmp(uuid_list->entry[i].uuid, zero_uuid, sizeof(zero_uuid)) == 0)
+                       break;
+               memcpy(&uuid, uuid_list->entry[i].uuid, sizeof(uuid));
+               if (human) {
+                       switch (identifier_association) {
+                       case 0x0:
+                               association = "No association reported";
+                               break;
+                       case 0x1:
+                               association = "associated with PCI Vendor ID";
+                               break;
+                       case 0x2:
+                               association = "associated with PCI Subsystem Vendor ID";
+                               break;
+                       default:
+                               association = "Reserved";
+                               break;
+                       }
+               }
+               printf(" Entry[%3d]\n", i);
+               printf(".................\n");
+               printf("association  : 0x%x %s\n", identifier_association, association);
+               printf("UUID         : %s", nvme_uuid_to_string(uuid));
+               if (memcmp(uuid_list->entry[i].uuid, invalid_uuid, sizeof(zero_uuid)) == 0)
+                       printf(" (Invalid UUID)");
+               printf("\n.................\n");
+       }
+}
 
-       errors = json_create_array();
-       json_object_add_value_array(root, "errors", errors);
+static const char *nvme_trtype_to_string(__u8 trtype)
+{
+       switch(trtype) {
+       case 0: return "The transport type is not indicated or the error "\
+               "is not transport related.";
+       case 1: return "RDMA Transport error.";
+       case 2: return "Fibre Channel Transport error.";
+       case 3: return "TCP Transport error.";
+       case 254: return "Intra-host Transport error.";
+       default: return "Reserved";
+       };
+}
 
-       for (i = 0; i < entries; i++) {
-               struct json_object *error = json_create_object();
+void nvme_show_error_log(struct nvme_error_log_page *err_log, int entries,
+                       const char *devname, enum nvme_print_flags flags)
+{
+       int i;
 
-               json_object_add_value_uint(error, "error_count",
-                                          le64_to_cpu(err_log[i].error_count));
-               json_object_add_value_int(error, "sqid",
-                                         le16_to_cpu(err_log[i].sqid));
-               json_object_add_value_int(error, "cmdid",
-                                         le16_to_cpu(err_log[i].cmdid));
-               json_object_add_value_int(error, "status_field",
-                                         le16_to_cpu(err_log[i].status_field));
-               json_object_add_value_int(error, "parm_error_location",
-                                         le16_to_cpu(err_log[i].parm_error_location));
-               json_object_add_value_uint(error, "lba",
-                                          le64_to_cpu(err_log[i].lba));
-               json_object_add_value_uint(error, "nsid",
-                                          le32_to_cpu(err_log[i].nsid));
-               json_object_add_value_int(error, "vs", err_log[i].vs);
-               json_object_add_value_int(error, "trtype", err_log[i].trtype);
-               json_object_add_value_uint(error, "cs",
-                                          le64_to_cpu(err_log[i].cs));
-               json_object_add_value_int(error, "trtype_spec_info",
-                                         le16_to_cpu(err_log[i].trtype_spec_info));
+       if (flags & BINARY)
+               return d_raw((unsigned char *)err_log, entries * sizeof(*err_log));
+       else if (flags & JSON)
+               return json_error_log(err_log, entries);
 
-               json_array_add_value_object(errors, error);
+       printf("Error Log Entries for device:%s entries:%d\n", devname,
+                                                               entries);
+       printf(".................\n");
+       for (i = 0; i < entries; i++) {
+               printf(" Entry[%2d]   \n", i);
+               printf(".................\n");
+               printf("error_count     : %"PRIu64"\n", le64_to_cpu(err_log[i].error_count));
+               printf("sqid            : %d\n", err_log[i].sqid);
+               printf("cmdid           : %#x\n", err_log[i].cmdid);
+               printf("status_field    : %#x(%s)\n", err_log[i].status_field,
+                       nvme_status_to_string(le16_to_cpu(err_log[i].status_field) >> 1));
+               printf("parm_err_loc    : %#x\n", err_log[i].parm_error_location);
+               printf("lba             : %#"PRIx64"\n",le64_to_cpu(err_log[i].lba));
+               printf("nsid            : %#x\n", err_log[i].nsid);
+               printf("vs              : %d\n", err_log[i].vs);
+               printf("trtype          : %s\n", nvme_trtype_to_string(err_log[i].trtype));
+               printf("cs              : %#"PRIx64"\n",
+                      le64_to_cpu(err_log[i].cs));
+               printf("trtype_spec_info: %#x\n", err_log[i].trtype_spec_info);
+               printf(".................\n");
        }
-
-       json_print_object(root, NULL);
-       printf("\n");
-       json_free_object(root);
 }
 
-void json_nvme_resv_report(struct nvme_reservation_status *status, int bytes, __u32 cdw11)
+void nvme_show_resv_report(struct nvme_reservation_status *status, int bytes, __u32 cdw11,
+                    enum nvme_print_flags flags)
 {
-       struct json_object *root;
-       struct json_array *rcs;
        int i, j, regctl, entries;
 
-       regctl = status->regctl[0] | (status->regctl[1] << 8);
+       if (flags & BINARY)
+               return d_raw((unsigned char *)status, bytes);
+       else if (flags & JSON)
+               return json_nvme_resv_report(status, bytes, cdw11);
 
-       root = json_create_object();
+       regctl = status->regctl[0] | (status->regctl[1] << 8);
 
-       json_object_add_value_int(root, "gen", le32_to_cpu(status->gen));
-       json_object_add_value_int(root, "rtype", status->rtype);
-       json_object_add_value_int(root, "regctl", regctl);
-       json_object_add_value_int(root, "ptpls", status->ptpls);
+       printf("\nNVME Reservation status:\n\n");
+       printf("gen       : %d\n", le32_to_cpu(status->gen));
+       printf("rtype     : %d\n", status->rtype);
+       printf("regctl    : %d\n", regctl);
+       printf("ptpls     : %d\n", status->ptpls);
 
-       rcs = json_create_array();
-        /* check Extended Data Structure bit */
-        if ((cdw11 & 0x1) == 0) {
-                /* if status buffer was too small, don't loop past the end of the buffer */
-                entries = (bytes - 24) / 24;
-                if (entries < regctl)
-                        regctl = entries;
+       /* check Extended Data Structure bit */
+       if ((cdw11 & 0x1) == 0) {
+               /* if status buffer was too small, don't loop past the end of the buffer */
+               entries = (bytes - 24) / 24;
+               if (entries < regctl)
+                       regctl = entries;
 
-               json_object_add_value_array(root, "regctls", rcs);
                for (i = 0; i < regctl; i++) {
-                       struct json_object *rc = json_create_object();
-
-                       json_object_add_value_int(rc, "cntlid", le16_to_cpu(status->regctl_ds[i].cntlid));
-                       json_object_add_value_int(rc, "rcsts", status->regctl_ds[i].rcsts);
-                       json_object_add_value_uint(rc, "hostid", le64_to_cpu(status->regctl_ds[i].hostid));
-                       json_object_add_value_uint(rc, "rkey", le64_to_cpu(status->regctl_ds[i].rkey));
-
-                       json_array_add_value_object(rcs, rc);
+                       printf("regctl[%d] :\n", i);
+                       printf("  cntlid  : %x\n", le16_to_cpu(status->regctl_ds[i].cntlid));
+                       printf("  rcsts   : %x\n", status->regctl_ds[i].rcsts);
+                       printf("  hostid  : %"PRIx64"\n", le64_to_cpu(status->regctl_ds[i].hostid));
+                       printf("  rkey    : %"PRIx64"\n", le64_to_cpu(status->regctl_ds[i].rkey));
                }
        } else {
                struct nvme_reservation_status_ext *ext_status = (struct nvme_reservation_status_ext *)status;
-               char    hostid[33];
-
-                /* if status buffer was too small, don't loop past the end of the buffer */
-                entries = (bytes - 64) / 64;
-                if (entries < regctl)
-                        regctl = entries;
+               /* if status buffer was too small, don't loop past the end of the buffer */
+               entries = (bytes - 64) / 64;
+               if (entries < regctl)
+                       regctl = entries;
 
-               json_object_add_value_array(root, "regctlext", rcs);
                for (i = 0; i < regctl; i++) {
-                       struct json_object *rc = json_create_object();
-
-                       json_object_add_value_int(rc, "cntlid", le16_to_cpu(ext_status->regctl_eds[i].cntlid));
-                       json_object_add_value_int(rc, "rcsts", ext_status->regctl_eds[i].rcsts);
-                       json_object_add_value_uint(rc, "rkey", le64_to_cpu(ext_status->regctl_eds[i].rkey));
+                       printf("regctlext[%d] :\n", i);
+                       printf("  cntlid     : %x\n", le16_to_cpu(ext_status->regctl_eds[i].cntlid));
+                       printf("  rcsts      : %x\n", ext_status->regctl_eds[i].rcsts);
+                       printf("  rkey       : %"PRIx64"\n", le64_to_cpu(ext_status->regctl_eds[i].rkey));
+                       printf("  hostid     : ");
                        for (j = 0; j < 16; j++)
-                               sprintf(hostid + j * 2, "%02x", ext_status->regctl_eds[i].hostid[j]);
-
-                       json_object_add_value_string(rc, "hostid", hostid);
-
-                       json_array_add_value_object(rcs, rc);
+                               printf("%x", ext_status->regctl_eds[i].hostid[j]);
+                       printf("\n");
                }
        }
-
-       json_print_object(root, NULL);
        printf("\n");
-       json_free_object(root);
 }
 
-void json_fw_log(struct nvme_firmware_log_page *fw_log, const char *devname)
+void nvme_show_fw_log(struct nvme_firmware_log_page *fw_log, const char *devname,
+                    enum nvme_print_flags flags)
 {
-       struct json_object *root;
-       struct json_object *fwsi;
-       char fmt[21];
-       char str[32];
        int i;
 
-       root = json_create_object();
-       fwsi = json_create_object();
-
-       json_object_add_value_int(fwsi, "Active Firmware Slot (afi)", fw_log->afi);
+       if (flags & BINARY)
+               return d_raw((unsigned char *)fw_log, sizeof(*fw_log));
+       if (flags & JSON)
+               return json_fw_log(fw_log, devname);
 
+       printf("Firmware Log for device:%s\n", devname);
+       printf("afi  : %#x\n", fw_log->afi);
        for (i = 0; i < 7; i++) {
-               if (fw_log->frs[i]) {
-                       snprintf(fmt, sizeof(fmt), "Firmware Rev Slot %d", i+1);
-                       snprintf(str, sizeof(str), "%"PRIu64" (%s)", (uint64_t)fw_log->frs[i],
-                       fw_to_string(fw_log->frs[i]));
-                       json_object_add_value_string(fwsi, fmt, str);
-               }
+               if (fw_log->frs[i])
+                       printf("frs%d : %#016"PRIx64" (%s)\n", i + 1, (uint64_t)fw_log->frs[i],
+                                               fw_to_string(fw_log->frs[i]));
        }
-       json_object_add_value_object(root, devname, fwsi);
-
-       json_print_object(root, NULL);
-       printf("\n");
-       json_free_object(root);
 }
 
-void json_changed_ns_list_log(struct nvme_changed_ns_list_log *log, const char *devname)
+void nvme_show_changed_ns_list_log(struct nvme_changed_ns_list_log *log,
+                                  const char *devname,
+                                  enum nvme_print_flags flags)
 {
-       struct json_object *root;
-       struct json_object *nsi;
-       char fmt[32];
-       char str[32];
-       __u32 nsid;
        int i;
+       __u32 nsid;
 
-       if (log->log[0] == cpu_to_le32(0XFFFFFFFF))
-               return;
-
-       root = json_create_object();
-       nsi = json_create_object();
-
-       json_object_add_value_string(root, "Changed Namespace List Log", devname);
+       if (flags & BINARY)
+               return d_raw((unsigned char *)log, sizeof(*log));
+       else if (flags & JSON)
+               return json_changed_ns_list_log(log, devname);
 
-       for (i = 0; i < NVME_MAX_CHANGED_NAMESPACES; i++) {
-               nsid = le32_to_cpu(log->log[i]);
+       if (log->log[0] != cpu_to_le32(0XFFFFFFFF)) {
+               for (i = 0; i < NVME_MAX_CHANGED_NAMESPACES; i++) {
+                       nsid = le32_to_cpu(log->log[i]);
+                       if (nsid == 0)
+                               break;
 
-               if (nsid == 0)
-                       break;
+                       printf("[%4u]:%#x\n", i, nsid);
+               }
+       } else
+               printf("more than %d ns changed\n", NVME_MAX_CHANGED_NAMESPACES);
+}
 
-               snprintf(fmt, sizeof(fmt), "[%4u]", i + 1);
-               snprintf(str, sizeof(str), "%#x", nsid);
-               json_object_add_value_string(nsi, fmt, str);
-       }
+static void nvme_show_effects_log_human(__u32 effect)
+{
+       const char *set = "+";
+       const char *clr = "-";
 
-       json_object_add_value_object(root, devname, nsi);
-       json_print_object(root, NULL);
-       printf("\n");
+       printf("  CSUPP+");
+       printf("  LBCC%s", (effect & NVME_CMD_EFFECTS_LBCC) ? set : clr);
+       printf("  NCC%s", (effect & NVME_CMD_EFFECTS_NCC) ? set : clr);
+       printf("  NIC%s", (effect & NVME_CMD_EFFECTS_NIC) ? set : clr);
+       printf("  CCC%s", (effect & NVME_CMD_EFFECTS_CCC) ? set : clr);
+       printf("  USS%s", (effect & NVME_CMD_EFFECTS_UUID_SEL) ? set : clr);
 
-       json_free_object(root);
+       if ((effect & NVME_CMD_EFFECTS_CSE_MASK) >> 16 == 0)
+               printf("  No command restriction\n");
+       else if ((effect & NVME_CMD_EFFECTS_CSE_MASK) >> 16 == 1)
+               printf("  No other command for same namespace\n");
+       else if ((effect & NVME_CMD_EFFECTS_CSE_MASK) >> 16 == 2)
+               printf("  No other command for any namespace\n");
+       else
+               printf("  Reserved CSE\n");
 }
 
-void json_endurance_log(struct nvme_endurance_group_log *endurance_group,
-                       __u16 group_id, const char *devname)
+void nvme_show_effects_log(struct nvme_effects_log_page *effects, unsigned int flags)
 {
-       struct json_object *root;
+       int i, human = flags & VERBOSE;
+       __u32 effect;
 
-       long double endurance_estimate= int128_to_double(endurance_group->endurance_estimate);
-       long double data_units_read= int128_to_double(endurance_group->data_units_read);
-       long double data_units_written= int128_to_double(endurance_group->data_units_written);
-       long double media_units_written= int128_to_double(endurance_group->media_units_written);
-       long double host_read_cmds = int128_to_double(endurance_group->host_read_cmds);
-       long double host_write_cmds = int128_to_double(endurance_group->host_write_cmds);
-       long double media_data_integrity_err = int128_to_double(endurance_group->media_data_integrity_err);
-       long double num_err_info_log_entries = int128_to_double(endurance_group->num_err_info_log_entries);
+       if (flags & BINARY)
+               return d_raw((unsigned char *)effects, sizeof(*effects));
+       else if (flags & JSON)
+               return json_effects_log(effects);
 
-       root = json_create_object();
+       printf("Admin Command Set\n");
+       for (i = 0; i < 256; i++) {
+               effect = le32_to_cpu(effects->acs[i]);
+               if (effect & NVME_CMD_EFFECTS_CSUPP) {
+                       printf("ACS%-6d[%-32s] %08x", i,
+                                       nvme_cmd_to_string(1, i), effect);
+                       if (human)
+                               nvme_show_effects_log_human(effect);
+                       else
+                               printf("\n");
+               }
+       }
+       printf("\nNVM Command Set\n");
+       for (i = 0; i < 256; i++) {
+               effect = le32_to_cpu(effects->iocs[i]);
+               if (effect & NVME_CMD_EFFECTS_CSUPP) {
+                       printf("IOCS%-5d[%-32s] %08x", i,
+                                       nvme_cmd_to_string(0, i), effect);
+                       if (human)
+                               nvme_show_effects_log_human(effect);
+                       else
+                               printf("\n");
+               }
+       }
+}
 
-       json_object_add_value_int(root, "critical_warning", endurance_group->critical_warning);
-       json_object_add_value_int(root, "avl_spare", endurance_group->avl_spare);
-       json_object_add_value_int(root, "avl_spare_threshold", endurance_group->avl_spare_threshold);
-       json_object_add_value_int(root, "percent_used", endurance_group->percent_used);
-       json_object_add_value_float(root, "endurance_estimate", endurance_estimate);
-       json_object_add_value_float(root, "data_units_read", data_units_read);
-       json_object_add_value_float(root, "data_units_written", data_units_written);
-       json_object_add_value_float(root, "mediate_write_commands", media_units_written);
-       json_object_add_value_float(root, "host_read_cmds", host_read_cmds);
-       json_object_add_value_float(root, "host_write_cmds", host_write_cmds);
-       json_object_add_value_float(root, "media_data_integrity_err", media_data_integrity_err);
-       json_object_add_value_float(root, "num_err_info_log_entries", num_err_info_log_entries);
+uint64_t int48_to_long(__u8 *data)
+{
+       int i;
+       uint64_t result = 0;
 
-       json_print_object(root, NULL);
-       printf("\n");
-       json_free_object(root);
+       for (i = 0; i < 6; i++) {
+               result *= 256;
+               result += data[5 - i];
+       }
+       return result;
 }
 
-void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname)
+void nvme_show_endurance_log(struct nvme_endurance_group_log *endurance_log,
+                            __u16 group_id, const char *devname,
+                            enum nvme_print_flags flags)
 {
-       struct json_object *root;
-       int c;
-       char key[21];
-
-       unsigned int temperature = ((smart->temperature[1] << 8) |
-               smart->temperature[0]);
+       if (flags & BINARY)
+               return d_raw((unsigned char *)endurance_log, sizeof(*endurance_log));
+       else if (flags & JSON)
+               return json_endurance_log(endurance_log, group_id);
 
-       long double data_units_read = int128_to_double(smart->data_units_read);
-       long double data_units_written = int128_to_double(smart->data_units_written);
-       long double host_read_commands = int128_to_double(smart->host_reads);
-       long double host_write_commands = int128_to_double(smart->host_writes);
-       long double controller_busy_time = int128_to_double(smart->ctrl_busy_time);
-       long double power_cycles = int128_to_double(smart->power_cycles);
-       long double power_on_hours = int128_to_double(smart->power_on_hours);
-       long double unsafe_shutdowns = int128_to_double(smart->unsafe_shutdowns);
-       long double media_errors = int128_to_double(smart->media_errors);
-       long double num_err_log_entries = int128_to_double(smart->num_err_log_entries);
+       printf("Endurance Group Log for NVME device:%s Group ID:%x\n", devname, group_id);
+       printf("critical warning        : %u\n", endurance_log->critical_warning);
+       printf("avl_spare               : %u\n", endurance_log->avl_spare);
+       printf("avl_spare_threshold     : %u\n", endurance_log->avl_spare_threshold);
+       printf("percent_used            : %u%%\n", endurance_log->percent_used);
+       printf("endurance_estimate      : %'.0Lf\n",
+               int128_to_double(endurance_log->endurance_estimate));
+       printf("data_units_read         : %'.0Lf\n",
+               int128_to_double(endurance_log->data_units_read));
+       printf("data_units_written      : %'.0Lf\n",
+               int128_to_double(endurance_log->data_units_written));
+       printf("media_units_written     : %'.0Lf\n",
+               int128_to_double(endurance_log->media_units_written));
+       printf("host_read_cmds          : %'.0Lf\n",
+               int128_to_double(endurance_log->host_read_cmds));
+       printf("host_write_cmds         : %'.0Lf\n",
+               int128_to_double(endurance_log->host_write_cmds));
+       printf("media_data_integrity_err: %'.0Lf\n",
+               int128_to_double(endurance_log->media_data_integrity_err));
+       printf("num_err_info_log_entries: %'.0Lf\n",
+               int128_to_double(endurance_log->num_err_info_log_entries));
+}
 
-       root = json_create_object();
+void nvme_show_smart_log(struct nvme_smart_log *smart, unsigned int nsid,
+                        const char *devname, enum nvme_print_flags flags)
+{
+       /* convert temperature from Kelvin to Celsius */
+       int temperature = ((smart->temperature[1] << 8) |
+                           smart->temperature[0]) - 273;
+       int i;
 
-       json_object_add_value_int(root, "critical_warning", smart->critical_warning);
-       json_object_add_value_int(root, "temperature", temperature);
-       json_object_add_value_int(root, "avail_spare", smart->avail_spare);
-       json_object_add_value_int(root, "spare_thresh", smart->spare_thresh);
-       json_object_add_value_int(root, "percent_used", smart->percent_used);
-       json_object_add_value_int(root, "endurance_grp_critical_warning_summary",
-                       smart->endu_grp_crit_warn_sumry);
-       json_object_add_value_float(root, "data_units_read", data_units_read);
-       json_object_add_value_float(root, "data_units_written", data_units_written);
-       json_object_add_value_float(root, "host_read_commands", host_read_commands);
-       json_object_add_value_float(root, "host_write_commands", host_write_commands);
-       json_object_add_value_float(root, "controller_busy_time", controller_busy_time);
-       json_object_add_value_float(root, "power_cycles", power_cycles);
-       json_object_add_value_float(root, "power_on_hours", power_on_hours);
-       json_object_add_value_float(root, "unsafe_shutdowns", unsafe_shutdowns);
-       json_object_add_value_float(root, "media_errors", media_errors);
-       json_object_add_value_float(root, "num_err_log_entries", num_err_log_entries);
-       json_object_add_value_uint(root, "warning_temp_time",
-                       le32_to_cpu(smart->warning_temp_time));
-       json_object_add_value_uint(root, "critical_comp_time",
-                       le32_to_cpu(smart->critical_comp_time));
+       if (flags & BINARY)
+               return d_raw((unsigned char *)smart, sizeof(*smart));
+       else if (flags & JSON)
+               return json_smart_log(smart, nsid);
 
-       for (c=0; c < 8; c++) {
-               __s32 temp = le16_to_cpu(smart->temp_sensor[c]);
+       printf("Smart Log for NVME device:%s namespace-id:%x\n", devname, nsid);
+       printf("critical_warning                        : %#x\n", smart->critical_warning);
+       printf("temperature                             : %d C\n", temperature);
+       printf("available_spare                         : %u%%\n", smart->avail_spare);
+       printf("available_spare_threshold               : %u%%\n", smart->spare_thresh);
+       printf("percentage_used                         : %u%%\n", smart->percent_used);
+       printf("endurance group critical warning summary: %#x\n", smart->endu_grp_crit_warn_sumry);
+       printf("data_units_read                         : %'.0Lf\n",
+               int128_to_double(smart->data_units_read));
+       printf("data_units_written                      : %'.0Lf\n",
+               int128_to_double(smart->data_units_written));
+       printf("host_read_commands                      : %'.0Lf\n",
+               int128_to_double(smart->host_reads));
+       printf("host_write_commands                     : %'.0Lf\n",
+               int128_to_double(smart->host_writes));
+       printf("controller_busy_time                    : %'.0Lf\n",
+               int128_to_double(smart->ctrl_busy_time));
+       printf("power_cycles                            : %'.0Lf\n",
+               int128_to_double(smart->power_cycles));
+       printf("power_on_hours                          : %'.0Lf\n",
+               int128_to_double(smart->power_on_hours));
+       printf("unsafe_shutdowns                        : %'.0Lf\n",
+               int128_to_double(smart->unsafe_shutdowns));
+       printf("media_errors                            : %'.0Lf\n",
+               int128_to_double(smart->media_errors));
+       printf("num_err_log_entries                     : %'.0Lf\n",
+               int128_to_double(smart->num_err_log_entries));
+       printf("Warning Temperature Time                : %u\n", le32_to_cpu(smart->warning_temp_time));
+       printf("Critical Composite Temperature Time     : %u\n", le32_to_cpu(smart->critical_comp_time));
+       for (i = 0; i < 8; i++) {
+               __s32 temp = le16_to_cpu(smart->temp_sensor[i]);
 
                if (temp == 0)
                        continue;
-               sprintf(key, "temperature_sensor_%d",c+1);
-               json_object_add_value_int(root, key, temp);
+               printf("Temperature Sensor %d           : %d C\n", i + 1,
+                       temp - 273);
        }
-
-       json_object_add_value_uint(root, "thm_temp1_trans_count",
-                       le32_to_cpu(smart->thm_temp1_trans_count));
-       json_object_add_value_uint(root, "thm_temp2_trans_count",
-                       le32_to_cpu(smart->thm_temp2_trans_count));
-       json_object_add_value_uint(root, "thm_temp1_total_time",
-                       le32_to_cpu(smart->thm_temp1_total_time));
-       json_object_add_value_uint(root, "thm_temp2_total_time",
-                       le32_to_cpu(smart->thm_temp2_total_time));
-
-       json_print_object(root, NULL);
-       printf("\n");
-       json_free_object(root);
+       printf("Thermal Management T1 Trans Count       : %u\n", le32_to_cpu(smart->thm_temp1_trans_count));
+       printf("Thermal Management T2 Trans Count       : %u\n", le32_to_cpu(smart->thm_temp2_trans_count));
+       printf("Thermal Management T1 Total Time        : %u\n", le32_to_cpu(smart->thm_temp1_total_time));
+       printf("Thermal Management T2 Total Time        : %u\n", le32_to_cpu(smart->thm_temp2_total_time));
 }
 
-void json_ana_log(struct nvme_ana_rsp_hdr *ana_log, const char *devname)
+void nvme_show_ana_log(struct nvme_ana_rsp_hdr *ana_log, const char *devname,
+                       enum nvme_print_flags flags, size_t len)
 {
        int offset = sizeof(struct nvme_ana_rsp_hdr);
        struct nvme_ana_rsp_hdr *hdr = ana_log;
-       struct nvme_ana_group_desc *ana_desc;
-       struct json_array *desc_list;
-       struct json_array *ns_list;
-       struct json_object *desc;
-       struct json_object *nsid;
-       struct json_object *root;
+       struct nvme_ana_group_desc *desc;
        size_t nsid_buf_size;
        void *base = ana_log;
        __u32 nr_nsids;
-       int i;
-       int j;
+       int i, j;
 
-       root = json_create_object();
-       json_object_add_value_string(root,
-                       "Asynchronous Namespace Access Log for NVMe device:",
+       if (flags & BINARY)
+               return d_raw((unsigned char *)ana_log, len);
+       else if (flags & JSON)
+               return json_ana_log(ana_log, devname);
+
+       printf("Asynchronous Namespace Access Log for NVMe device: %s\n",
                        devname);
-       json_object_add_value_uint(root, "chgcnt",
+       printf("ANA LOG HEADER :-\n");
+       printf("chgcnt  :       %"PRIu64"\n",
                        le64_to_cpu(hdr->chgcnt));
-       json_object_add_value_uint(root, "ngrps", le16_to_cpu(hdr->ngrps));
+       printf("ngrps   :       %u\n", le16_to_cpu(hdr->ngrps));
+       printf("ANA Log Desc :-\n");
 
-       desc_list = json_create_array();
        for (i = 0; i < le16_to_cpu(ana_log->ngrps); i++) {
-               desc = json_create_object();
-               ana_desc = base + offset;
-               nr_nsids = le32_to_cpu(ana_desc->nnsids);
+               desc = base + offset;
+               nr_nsids = le32_to_cpu(desc->nnsids);
                nsid_buf_size = nr_nsids * sizeof(__le32);
 
-               offset += sizeof(*ana_desc);
-               json_object_add_value_uint(desc, "grpid",
-                               le32_to_cpu(ana_desc->grpid));
-               json_object_add_value_uint(desc, "nnsids",
-                               le32_to_cpu(ana_desc->nnsids));
-               json_object_add_value_uint(desc, "chgcnt",
-                               le64_to_cpu(ana_desc->chgcnt));
-               json_object_add_value_string(desc, "state",
-                               nvme_ana_state_to_string(ana_desc->state));
-
-               ns_list = json_create_array();
-               for (j = 0; j < le32_to_cpu(ana_desc->nnsids); j++) {
-                       nsid = json_create_object();
-                       json_object_add_value_uint(nsid, "nsid",
-                                       le32_to_cpu(ana_desc->nsids[j]));
-                       json_array_add_value_object(ns_list, nsid);
-               }
-               json_object_add_value_array(desc, "NSIDS", ns_list);
+               offset += sizeof(*desc);
+               printf("grpid   :       %u\n", le32_to_cpu(desc->grpid));
+               printf("nnsids  :       %u\n", le32_to_cpu(desc->nnsids));
+               printf("chgcnt  :       %"PRIu64"\n",
+                      le64_to_cpu(desc->chgcnt));
+               printf("state   :       %s\n",
+                               nvme_ana_state_to_string(desc->state));
+               for (j = 0; j < le32_to_cpu(desc->nnsids); j++)
+                       printf("        nsid    :       %u\n",
+                                       le32_to_cpu(desc->nsids[j]));
+               printf("\n");
                offset += nsid_buf_size;
-               json_array_add_value_object(desc_list, desc);
-       }
-
-       json_object_add_value_array(root, "ANA DESC LIST ", desc_list);
-       json_print_object(root, NULL);
-       printf("\n");
-       json_free_object(root);
-}
-
-void json_self_test_log(struct nvme_self_test_log *self_test, const char *devname)
-{
-       struct json_object *root;
-       struct json_array *valid;
-       struct json_object *valid_attrs;
-       int i;
-
-       root = json_create_object();
-       json_object_add_value_int(root, "Current Device Self-Test Operation", self_test->crnt_dev_selftest_oprn);
-       json_object_add_value_int(root, "Current Device Self-Test Completion", self_test->crnt_dev_selftest_compln);
-       valid = json_create_array();
-
-       for (i=0; i < NVME_SELF_TEST_REPORTS; i++) {
-               if ((self_test->result[i].device_self_test_status & 0xf) == 0xf)
-                       continue;
-               valid_attrs = json_create_object();
-               json_object_add_value_int(valid_attrs, "Self test result", self_test->result[i].device_self_test_status & 0xf);
-               json_object_add_value_int(valid_attrs, "Self test code", self_test->result[i].device_self_test_status >> 4);
-               json_object_add_value_int(valid_attrs, "Segment number", self_test->result[i].segment_num);
-               json_object_add_value_int(valid_attrs, "Valid Diagnostic Information", self_test->result[i].valid_diagnostic_info);
-               json_object_add_value_uint(valid_attrs, "Power on hours (POH)",le64_to_cpu(self_test->result[i].power_on_hours));
-               if (self_test->result[i].valid_diagnostic_info & NVME_SELF_TEST_VALID_NSID)
-                       json_object_add_value_int(valid_attrs, "Namespace Identifier (NSID)", le32_to_cpu(self_test->result[i].nsid));
-               if (self_test->result[i].valid_diagnostic_info & NVME_SELF_TEST_VALID_FLBA)
-                       json_object_add_value_uint(valid_attrs, "Failing LBA",le64_to_cpu(self_test->result[i].failing_lba));
-               if (self_test->result[i].valid_diagnostic_info & NVME_SELF_TEST_VALID_SCT)
-                       json_object_add_value_int(valid_attrs, "Status Code Type",self_test->result[i].status_code_type);
-               if(self_test->result[i].valid_diagnostic_info & NVME_SELF_TEST_VALID_SC)
-                       json_object_add_value_int(valid_attrs, "Status Code",self_test->result[i].status_code);
-               json_object_add_value_int(valid_attrs, "Vendor Specific",(self_test->result[i].vendor_specific[1] << 8) |
-                       (self_test->result[i].vendor_specific[0]));
-               json_array_add_value_object(valid, valid_attrs);
-       }
-       json_object_add_value_array(root, "List of Valid Reports", valid);
-       json_print_object(root, NULL);
-       printf("\n");
-       json_free_object(root);
+       }
 }
 
-void json_effects_log(struct nvme_effects_log_page *effects_log, const char *devname)
+void nvme_show_self_test_log(struct nvme_self_test_log *self_test, const char *devname,
+                            enum nvme_print_flags flags)
 {
-       struct json_object *root;
-       unsigned int opcode;
-       char key[128];
-       __u32 effect;
-
-       root = json_create_object();
-
-       for (opcode = 0; opcode < 256; opcode++) {
-               sprintf(key, "ACS%d (%s)", opcode, nvme_cmd_to_string(1, opcode));
-               effect = le32_to_cpu(effects_log->acs[opcode]);
-               json_object_add_value_uint(root, key, effect);
-       }
+       int i, temp;
+       const char *test_code_res;
+       static const char *const test_res[] = {
+               "Operation completed without error",
+               "Operation was aborted by a Device Self-test command",
+               "Operation was aborted by a Controller Level Reset",
+               "Operation was aborted due to a removal of a namespace from the namespace inventory",
+               "Operation was aborted due to the processing of a Format NVM command",
+               "A fatal error or unknown test error occurred while the controller was executing the"\
+               " device self-test operation and the operation did not complete",
+               "Operation completed with a segment that failed and the segment that failed is not known",
+               "Operation completed with one or more failed segments and the first segment that failed "\
+               "is indicated in the SegmentNumber field",
+               "Operation was aborted for unknown reason",
+               "Operation was aborted due to a sanitize operation",
+               "Reserved"
+       };
 
-       for (opcode = 0; opcode < 256; opcode++) {
-               sprintf(key, "IOCS%d (%s)", opcode, nvme_cmd_to_string(0, opcode));
-               effect = le32_to_cpu(effects_log->iocs[opcode]);
-               json_object_add_value_uint(root, key, effect);
+       if (self_test->crnt_dev_selftest_oprn == 0) {
+               fprintf(stderr, "Test is %d%% complete and is still in progress.\n",
+                       self_test->crnt_dev_selftest_compln);
+               return;
        }
 
-       json_print_object(root, NULL);
-       printf("\n");
-       json_free_object(root);
-}
+       if (flags & BINARY)
+               return d_raw((unsigned char *)self_test, sizeof(*self_test));
+       if (flags & JSON)
+               return json_self_test_log(self_test);
 
-void json_sanitize_log(struct nvme_sanitize_log_page *sanitize_log, const char *devname)
-{
-       struct json_object *root;
-       struct json_object *dev;
-       struct json_object *sstat;
-       const char *status_str;
-       char str[128];
-       __u16 status = le16_to_cpu(sanitize_log->status);
+       printf("Device Self Test Log for NVME device:%s\n", devname);
+       printf("Current operation : %#x\n", self_test->crnt_dev_selftest_oprn);
+       printf("Current Completion : %u%%\n", self_test->crnt_dev_selftest_compln);
+       for (i = 0; i < NVME_SELF_TEST_REPORTS; i++) {
+               temp = self_test->result[i].device_self_test_status & 0xf;
+               if (temp == 0xf)
+                       continue;
 
-       root = json_create_object();
-       dev = json_create_object();
-       sstat = json_create_object();
+               printf("Result[%d]:\n", i);
+               printf("  Test Result                  : %#x %s\n", temp,
+                       test_res[temp > 10 ? 10 : temp]);
 
-       json_object_add_value_int(dev, "sprog", le16_to_cpu(sanitize_log->progress));
-       json_object_add_value_int(sstat, "global_erased",
-                       (status & NVME_SANITIZE_LOG_GLOBAL_DATA_ERASED) >> 8);
-       json_object_add_value_int(sstat, "no_cmplted_passes",
-                       (status & NVME_SANITIZE_LOG_NUM_CMPLTED_PASS_MASK) >> 3);
+               temp = self_test->result[i].device_self_test_status >> 4;
+               switch (temp) {
+               case 1:
+                       test_code_res = "Short device self-test operation";
+                       break;
+               case 2:
+                       test_code_res = "Extended device self-test operation";
+                       break;
+               case 0xe:
+                       test_code_res = "Vendor specific";
+                       break;
+               default :
+                       test_code_res = "Reserved";
+                       break;
+               }
+               printf("  Test Code                    : %#x %s\n", temp,
+                       test_code_res);
+               if (temp == 7)
+                       printf("  Segment number               : %#x\n",
+                               self_test->result[i].segment_num);
 
-       status_str = get_sanitize_log_sstat_status_str(status);
-       sprintf(str, "(%d) %s", status & NVME_SANITIZE_LOG_STATUS_MASK, status_str);
-       json_object_add_value_string(sstat, "status", str);
+               temp = self_test->result[i].valid_diagnostic_info;
+               printf("  Valid Diagnostic Information : %#x\n", temp);
+               printf("  Power on hours (POH)         : %#"PRIx64"\n",
+                       le64_to_cpu(self_test->result[i].power_on_hours));
 
-       json_object_add_value_object(dev, "sstat", sstat);
-       json_object_add_value_uint(dev, "cdw10_info", le32_to_cpu(sanitize_log->cdw10_info));
-       json_object_add_value_uint(dev, "time_over_write", le32_to_cpu(sanitize_log->est_ovrwrt_time));
-       json_object_add_value_uint(dev, "time_block_erase", le32_to_cpu(sanitize_log->est_blk_erase_time));
-       json_object_add_value_uint(dev, "time_crypto_erase", le32_to_cpu(sanitize_log->est_crypto_erase_time));
+               if (temp & NVME_SELF_TEST_VALID_NSID)
+                       printf("  Namespace Identifier         : %#x\n",
+                               le32_to_cpu(self_test->result[i].nsid));
+               if (temp & NVME_SELF_TEST_VALID_FLBA)
+                       printf("  Failing LBA                  : %#"PRIx64"\n",
+                               le64_to_cpu(self_test->result[i].failing_lba));
+               if (temp & NVME_SELF_TEST_VALID_SCT)
+                       printf("  Status Code Type             : %#x\n",
+                               self_test->result[i].status_code_type);
+               if (temp & NVME_SELF_TEST_VALID_SC)
+                       printf("  Status Code                  : %#x\n",
+                               self_test->result[i].status_code);
+               printf("  Vendor Specific                      : %x %x\n",
+                       self_test->result[i].vendor_specific[0],
+                       self_test->result[i].vendor_specific[0]);
+       }
+}
 
-       json_object_add_value_uint(dev, "time_over_write_no_dealloc", le32_to_cpu(sanitize_log->est_ovrwrt_time_with_no_deallocate));
-       json_object_add_value_uint(dev, "time_block_erase_no_dealloc", le32_to_cpu(sanitize_log->est_blk_erase_time_with_no_deallocate));
-       json_object_add_value_uint(dev, "time_crypto_erase_no_dealloc", le32_to_cpu(sanitize_log->est_crypto_erase_time_with_no_deallocate));
+static void nvme_show_sanitize_log_sprog(__u32 sprog)
+{
+       double percent;
 
-       json_object_add_value_object(root, devname, dev);
-       json_print_object(root, NULL);
-       printf("\n");
-       json_free_object(root);
+       percent = (((double)sprog * 100) / 0x10000);
+       printf("\t(%f%%)\n", percent);
 }
 
-static void show_nvme_subsystem(struct subsys_list_item *item)
+static void nvme_show_sanitize_log_sstat(__u16 status)
 {
-       int i;
-
-       printf("%s - NQN=%s\n", item->name, item->subsysnqn);
-       printf("\\\n");
+       const char *str = get_sanitize_log_sstat_status_str(status);
 
-       for (i = 0; i < item->nctrls; i++) {
-               printf(" +- %s %s %s %s %s\n", item->ctrls[i].name,
-                               item->ctrls[i].transport,
-                               item->ctrls[i].address,
-                               item->ctrls[i].state,
-                               item->ctrls[i].ana_state ?
-                                       item->ctrls[i].ana_state : "");
-       }
+       printf("\t[2:0]\t%s\n", str);
+       str = "Number of completed passes if most recent operation was overwrite";
+       printf("\t[7:3]\t%s:\t%u\n", str, (status & NVME_SANITIZE_LOG_NUM_CMPLTED_PASS_MASK) >> 3);
 
+       printf("\t  [8]\t");
+       if (status & NVME_SANITIZE_LOG_GLOBAL_DATA_ERASED)
+               str = "Global Data Erased set: no NS LB in the NVM subsystem has been written to "\
+                     "and no PMR in the NVM subsystem has been enabled";
+       else
+               str = "Global Data Erased cleared: a NS LB in the NVM subsystem has been written to "\
+                     "or  a PMR in the NVM subsystem has been enabled";
+       printf("%s\n", str);
 }
 
-void show_nvme_subsystem_list(struct subsys_list_item *slist, int n)
+static void nvme_show_estimate_sanitize_time(const char *text, uint32_t value)
 {
-       int i;
-
-       for (i = 0; i < n; i++)
-               show_nvme_subsystem(&slist[i]);
+       printf("%s:  %u%s\n", text, value,
+               value == 0xffffffff ? " (No time period reported)" : "");
 }
-void json_print_nvme_subsystem_list(struct subsys_list_item *slist, int n)
-{
-       struct json_object *root;
-       struct json_array *subsystems;
-       struct json_object *subsystem_attrs;
-       struct json_array *paths;
-       struct json_object *path_attrs;
-       int i, j;
 
-       root = json_create_object();
-       subsystems = json_create_array();
+void nvme_show_sanitize_log(struct nvme_sanitize_log_page *sanitize,
+                           const char *devname, enum nvme_print_flags flags)
+{
+       int human = flags & VERBOSE;
+       __u16 status = le16_to_cpu(sanitize->status) & NVME_SANITIZE_LOG_STATUS_MASK;
 
-       for (i = 0; i < n; i++) {
-               subsystem_attrs = json_create_object();
+       if (flags & BINARY)
+               d_raw((unsigned char *)sanitize, sizeof(*sanitize));
+       else if (flags & JSON)
+               json_sanitize_log(sanitize, devname);
 
-               json_object_add_value_string(subsystem_attrs,
-                                            "Name", slist[i].name);
-               json_object_add_value_string(subsystem_attrs,
-                                            "NQN", slist[i].subsysnqn);
+       printf("Sanitize Progress                      (SPROG) :  %u",
+              le16_to_cpu(sanitize->progress));
 
-               json_array_add_value_object(subsystems, subsystem_attrs);
+       if (human && status == NVME_SANITIZE_LOG_IN_PROGESS)
+               nvme_show_sanitize_log_sprog(le16_to_cpu(sanitize->progress));
+       else
+               printf("\n");
 
-               paths = json_create_array();
+       printf("Sanitize Status                        (SSTAT) :  %#x\n",
+               le16_to_cpu(sanitize->status));
+       if (human)
+               nvme_show_sanitize_log_sstat(le16_to_cpu(sanitize->status));
+
+       printf("Sanitize Command Dword 10 Information (SCDW10) :  %#x\n",
+               le32_to_cpu(sanitize->cdw10_info));
+       nvme_show_estimate_sanitize_time("Estimated Time For Overwrite                   ",
+               le32_to_cpu(sanitize->est_ovrwrt_time));
+       nvme_show_estimate_sanitize_time("Estimated Time For Block Erase                 ",
+               le32_to_cpu(sanitize->est_blk_erase_time));
+       nvme_show_estimate_sanitize_time("Estimated Time For Crypto Erase                ",
+               le32_to_cpu(sanitize->est_crypto_erase_time));
+       nvme_show_estimate_sanitize_time("Estimated Time For Overwrite (No-Deallocate)   ",
+               le32_to_cpu(sanitize->est_ovrwrt_time_with_no_deallocate));
+       nvme_show_estimate_sanitize_time("Estimated Time For Block Erase (No-Deallocate) ",
+               le32_to_cpu(sanitize->est_blk_erase_time_with_no_deallocate));
+       nvme_show_estimate_sanitize_time("Estimated Time For Crypto Erase (No-Deallocate)",
+               le32_to_cpu(sanitize->est_crypto_erase_time_with_no_deallocate));
+}
 
-               for (j = 0; j < slist[i].nctrls; j++) {
-                       path_attrs = json_create_object();
-                       json_object_add_value_string(path_attrs, "Name",
-                                       slist[i].ctrls[j].name);
-                       json_object_add_value_string(path_attrs, "Transport",
-                                       slist[i].ctrls[j].transport);
-                       json_object_add_value_string(path_attrs, "Address",
-                                       slist[i].ctrls[j].address);
-                       json_object_add_value_string(path_attrs, "State",
-                                       slist[i].ctrls[j].state);
-                       if (slist[i].ctrls[j].ana_state)
-                               json_object_add_value_string(path_attrs,
-                                               "ANAState",
-                                               slist[i].ctrls[j].ana_state);
-                       json_array_add_value_object(paths, path_attrs);
-               }
-               if (j) {
-                       json_object_add_value_array(subsystem_attrs, "Paths", paths);
-               }
+const char *nvme_feature_to_string(int feature)
+{
+       switch (feature) {
+       case NVME_FEAT_ARBITRATION:     return "Arbitration";
+       case NVME_FEAT_POWER_MGMT:      return "Power Management";
+       case NVME_FEAT_LBA_RANGE:       return "LBA Range Type";
+       case NVME_FEAT_TEMP_THRESH:     return "Temperature Threshold";
+       case NVME_FEAT_ERR_RECOVERY:    return "Error Recovery";
+       case NVME_FEAT_VOLATILE_WC:     return "Volatile Write Cache";
+       case NVME_FEAT_NUM_QUEUES:      return "Number of Queues";
+       case NVME_FEAT_IRQ_COALESCE:    return "Interrupt Coalescing";
+       case NVME_FEAT_IRQ_CONFIG:      return "Interrupt Vector Configuration";
+       case NVME_FEAT_WRITE_ATOMIC:    return "Write Atomicity Normal";
+       case NVME_FEAT_ASYNC_EVENT:     return "Async Event Configuration";
+       case NVME_FEAT_AUTO_PST:        return "Autonomous Power State Transition";
+       case NVME_FEAT_HOST_MEM_BUF:    return "Host Memory Buffer";
+       case NVME_FEAT_KATO:            return "Keep Alive Timer";
+       case NVME_FEAT_NOPSC:           return "Non-Operational Power State Config";
+       case NVME_FEAT_RRL:             return "Read Recovery Level";
+       case NVME_FEAT_PLM_CONFIG:      return "Predicatable Latency Mode Config";
+       case NVME_FEAT_PLM_WINDOW:      return "Predicatable Latency Mode Window";
+       case NVME_FEAT_SW_PROGRESS:     return "Software Progress";
+       case NVME_FEAT_HOST_ID:         return "Host Identifier";
+       case NVME_FEAT_RESV_MASK:       return "Reservation Notification Mask";
+       case NVME_FEAT_RESV_PERSIST:    return "Reservation Persistence";
+       case NVME_FEAT_TIMESTAMP:       return "Timestamp";
+       case NVME_FEAT_WRITE_PROTECT:   return "Namespce Write Protect";
+       case NVME_FEAT_HCTM:            return "Host Controlled Thermal Management";
+       case NVME_FEAT_HOST_BEHAVIOR:   return "Host Behavior";
+       case NVME_FEAT_SANITIZE:        return "Sanitize";
+       default:                        return "Unknown";
+       }
+}
 
+const char *nvme_register_to_string(int reg)
+{
+       switch (reg) {
+       case NVME_REG_CAP:      return "Controller Capabilities";
+       case NVME_REG_VS:       return "Version";
+       case NVME_REG_INTMS:    return "Interrupt Vector Mask Set";
+       case NVME_REG_INTMC:    return "Interrupt Vector Mask Clear";
+       case NVME_REG_CC:       return "Controller Configuration";
+       case NVME_REG_CSTS:     return "Controller Status";
+       case NVME_REG_NSSR:     return "NVM Subsystem Reset";
+       case NVME_REG_AQA:      return "Admin Queue Attributes";
+       case NVME_REG_ASQ:      return "Admin Submission Queue Base Address";
+       case NVME_REG_ACQ:      return "Admin Completion Queue Base Address";
+       case NVME_REG_CMBLOC:   return "Controller Memory Buffer Location";
+       case NVME_REG_CMBSZ:    return "Controller Memory Buffer Size";
+       default:                return "Unknown";
        }
+}
 
-       if (i)
-               json_object_add_value_array(root, "Subsystems", subsystems);
-       json_print_object(root, NULL);
-       printf("\n");
-       json_free_object(root);
+const char *nvme_select_to_string(int sel)
+{
+       switch (sel) {
+       case 0:  return "Current";
+       case 1:  return "Default";
+       case 2:  return "Saved";
+       case 3:  return "Supported capabilities";
+       default: return "Reserved";
+       }
 }
 
-static void show_registers_cap(struct nvme_bar_cap *cap)
+void nvme_show_select_result(__u32 result)
 {
-       printf("\tController Memory Buffer Supported (CMBS): The Controller Memory Buffer is %s\n",
-                       ((cap->rsvd_cmbs_pmrs & 0x02) >> 1) ? "Supported" : "Not Supported");
-       printf("\tPersistent Memory Region Supported (PMRS): The Persistent Memory Region is %s\n",
-                       (cap->rsvd_cmbs_pmrs & 0x01) ? "supported":"not supported");
-       printf("\tMemory Page Size Maximum         (MPSMAX): %u bytes\n", 1 <<  (12 + ((cap->mpsmax_mpsmin & 0xf0) >> 4)));
-       printf("\tMemory Page Size Minimum         (MPSMIN): %u bytes\n", 1 <<  (12 + (cap->mpsmax_mpsmin & 0x0f)));
-       printf("\tBoot Partition Support              (BPS): %s\n", (cap->bps_css_nssrs_dstrd & 0x2000) ? "Yes":"No");
-       printf("\tCommand Sets Supported              (CSS): NVM command set is %s\n",
-                       (cap->bps_css_nssrs_dstrd & 0x0020) ? "supported":"not supported");
-       printf("\tNVM Subsystem Reset Supported     (NSSRS): %s\n", (cap->bps_css_nssrs_dstrd & 0x0010) ? "Yes":"No");
-       printf("\tDoorbell Stride                   (DSTRD): %u bytes\n", 1 << (2 + (cap->bps_css_nssrs_dstrd & 0x000f)));
-       printf("\tTimeout                              (TO): %u ms\n", cap->to * 500);
-       printf("\tArbitration Mechanism Supported     (AMS): Weighted Round Robin with Urgent Priority Class is %s\n",
-                       (cap->ams_cqr & 0x02) ? "supported":"not supported");
-       printf("\tContiguous Queues Required          (CQR): %s\n", (cap->ams_cqr & 0x01) ? "Yes":"No");
-       printf("\tMaximum Queue Entries Supported    (MQES): %u\n\n", cap->mqes + 1);
+       if (result & 0x1)
+               printf("  Feature is saveable\n");
+       if (result & 0x2)
+               printf("  Feature is per-namespace\n");
+       if (result & 0x4)
+               printf("  Feature is changeable\n");
 }
 
-static void show_registers_version(__u32 vs)
+const char *nvme_status_to_string(__u32 status)
 {
-       printf("\tNVMe specification %d.%d\n\n", (vs & 0xffff0000) >> 16,  (vs & 0x0000ff00) >> 8);
+       switch (status & 0x3ff) {
+       case NVME_SC_SUCCESS:
+               return "SUCCESS: The command completed successfully";
+       case NVME_SC_INVALID_OPCODE:
+               return "INVALID_OPCODE: The associated command opcode field is not valid";
+       case NVME_SC_INVALID_FIELD:
+               return "INVALID_FIELD: A reserved coded value or an unsupported value in a defined field";
+       case NVME_SC_CMDID_CONFLICT:
+               return "CMDID_CONFLICT: The command identifier is already in use";
+       case NVME_SC_DATA_XFER_ERROR:
+               return "DATA_XFER_ERROR: Error while trying to transfer the data or metadata";
+       case NVME_SC_POWER_LOSS:
+               return "POWER_LOSS: Command aborted due to power loss notification";
+       case NVME_SC_INTERNAL:
+               return "INTERNAL: The command was not completed successfully due to an internal error";
+       case NVME_SC_ABORT_REQ:
+               return "ABORT_REQ: The command was aborted due to a Command Abort request";
+       case NVME_SC_ABORT_QUEUE:
+               return "ABORT_QUEUE: The command was aborted due to a Delete I/O Submission Queue request";
+       case NVME_SC_FUSED_FAIL:
+               return "FUSED_FAIL: The command was aborted due to the other command in a fused operation failing";
+       case NVME_SC_FUSED_MISSING:
+               return "FUSED_MISSING: The command was aborted due to a Missing Fused Command";
+       case NVME_SC_INVALID_NS:
+               return "INVALID_NS: The namespace or the format of that namespace is invalid";
+       case NVME_SC_CMD_SEQ_ERROR:
+               return "CMD_SEQ_ERROR: The command was aborted due to a protocol violation in a multicommand sequence";
+       case NVME_SC_SANITIZE_FAILED:
+               return "SANITIZE_FAILED: The most recent sanitize operation failed and no recovery actions has been successfully completed";
+       case NVME_SC_SANITIZE_IN_PROGRESS:
+               return "SANITIZE_IN_PROGRESS: The requested function is prohibited while a sanitize operation is in progress";
+       case NVME_SC_LBA_RANGE:
+               return "LBA_RANGE: The command references a LBA that exceeds the size of the namespace";
+       case NVME_SC_NS_WRITE_PROTECTED:
+               return "NS_WRITE_PROTECTED: The command is prohibited while the namespace is write protected by the host.";
+       case NVME_SC_CAP_EXCEEDED:
+               return "CAP_EXCEEDED: The execution of the command has caused the capacity of the namespace to be exceeded";
+       case NVME_SC_NS_NOT_READY:
+               return "NS_NOT_READY: The namespace is not ready to be accessed as a result of a condition other than a condition that is reported as an Asymmetric Namespace Access condition";
+       case NVME_SC_RESERVATION_CONFLICT:
+               return "RESERVATION_CONFLICT: The command was aborted due to a conflict with a reservation held on the accessed namespace";
+       case NVME_SC_CQ_INVALID:
+               return "CQ_INVALID: The Completion Queue identifier specified in the command does not exist";
+       case NVME_SC_QID_INVALID:
+               return "QID_INVALID: The creation of the I/O Completion Queue failed due to an invalid queue identifier specified as part of the command. An invalid queue identifier is one that is currently in use or one that is outside the range supported by the controller";
+       case NVME_SC_QUEUE_SIZE:
+               return "QUEUE_SIZE: The host attempted to create an I/O Completion Queue with an invalid number of entries";
+       case NVME_SC_ABORT_LIMIT:
+               return "ABORT_LIMIT: The number of concurrently outstanding Abort commands has exceeded the limit indicated in the Identify Controller data structure";
+       case NVME_SC_ABORT_MISSING:
+               return "ABORT_MISSING: The abort command is missing";
+       case NVME_SC_ASYNC_LIMIT:
+               return "ASYNC_LIMIT: The number of concurrently outstanding Asynchronous Event Request commands has been exceeded";
+       case NVME_SC_FIRMWARE_SLOT:
+               return "FIRMWARE_SLOT: The firmware slot indicated is invalid or read only. This error is indicated if the firmware slot exceeds the number supported";
+       case NVME_SC_FIRMWARE_IMAGE:
+               return "FIRMWARE_IMAGE: The firmware image specified for activation is invalid and not loaded by the controller";
+       case NVME_SC_INVALID_VECTOR:
+               return "INVALID_VECTOR: The creation of the I/O Completion Queue failed due to an invalid interrupt vector specified as part of the command";
+       case NVME_SC_INVALID_LOG_PAGE:
+               return "INVALID_LOG_PAGE: The log page indicated is invalid. This error condition is also returned if a reserved log page is requested";
+       case NVME_SC_INVALID_FORMAT:
+               return "INVALID_FORMAT: The LBA Format specified is not supported. This may be due to various conditions";
+       case NVME_SC_FW_NEEDS_CONV_RESET:
+               return "FW_NEEDS_CONVENTIONAL_RESET: The firmware commit was successful, however, activation of the firmware image requires a conventional reset";
+       case NVME_SC_INVALID_QUEUE:
+               return "INVALID_QUEUE: This error indicates that it is invalid to delete the I/O Completion Queue specified. The typical reason for this error condition is that there is an associated I/O Submission Queue that has not been deleted.";
+       case NVME_SC_FEATURE_NOT_SAVEABLE:
+               return "FEATURE_NOT_SAVEABLE: The Feature Identifier specified does not support a saveable value";
+       case NVME_SC_FEATURE_NOT_CHANGEABLE:
+               return "FEATURE_NOT_CHANGEABLE: The Feature Identifier is not able to be changed";
+       case NVME_SC_FEATURE_NOT_PER_NS:
+               return "FEATURE_NOT_PER_NS: The Feature Identifier specified is not namespace specific. The Feature Identifier settings apply across all namespaces";
+       case NVME_SC_FW_NEEDS_SUBSYS_RESET:
+               return "FW_NEEDS_SUBSYSTEM_RESET: The firmware commit was successful, however, activation of the firmware image requires an NVM Subsystem";
+       case NVME_SC_FW_NEEDS_RESET:
+               return "FW_NEEDS_RESET: The firmware commit was successful; however, the image specified does not support being activated without a reset";
+       case NVME_SC_FW_NEEDS_MAX_TIME:
+               return "FW_NEEDS_MAX_TIME_VIOLATION: The image specified if activated immediately would exceed the Maximum Time for Firmware Activation (MTFA) value reported in Identify Controller. To activate the firmware, the Firmware Commit command needs to be re-issued and the image activated using a reset";
+       case NVME_SC_FW_ACTIVATE_PROHIBITED:
+               return "FW_ACTIVATION_PROHIBITED: The image specified is being prohibited from activation by the controller for vendor specific reasons";
+       case NVME_SC_OVERLAPPING_RANGE:
+               return "OVERLAPPING_RANGE: This error is indicated if the firmware image has overlapping ranges";
+       case NVME_SC_NS_INSUFFICIENT_CAP:
+               return "NS_INSUFFICIENT_CAPACITY: Creating the namespace requires more free space than is currently available. The Command Specific Information field of the Error Information Log specifies the total amount of NVM capacity required to create the namespace in bytes";
+       case NVME_SC_NS_ID_UNAVAILABLE:
+               return "NS_ID_UNAVAILABLE: The number of namespaces supported has been exceeded";
+       case NVME_SC_NS_ALREADY_ATTACHED:
+               return "NS_ALREADY_ATTACHED: The controller is already attached to the namespace specified";
+       case NVME_SC_NS_IS_PRIVATE:
+               return "NS_IS_PRIVATE: The namespace is private and is already attached to one controller";
+       case NVME_SC_NS_NOT_ATTACHED:
+               return "NS_NOT_ATTACHED: The request to detach the controller could not be completed because the controller is not attached to the namespace";
+       case NVME_SC_THIN_PROV_NOT_SUPP:
+               return "THIN_PROVISIONING_NOT_SUPPORTED: Thin provisioning is not supported by the controller";
+       case NVME_SC_CTRL_LIST_INVALID:
+               return "CONTROLLER_LIST_INVALID: The controller list provided is invalid";
+       case NVME_SC_BP_WRITE_PROHIBITED:
+               return "BOOT PARTITION WRITE PROHIBITED: The command is trying to modify a Boot Partition while it is locked";
+       case NVME_SC_BAD_ATTRIBUTES:
+               return "BAD_ATTRIBUTES: Bad attributes were given";
+       case NVME_SC_WRITE_FAULT:
+               return "WRITE_FAULT: The write data could not be committed to the media";
+       case NVME_SC_READ_ERROR:
+               return "READ_ERROR: The read data could not be recovered from the media";
+       case NVME_SC_GUARD_CHECK:
+               return "GUARD_CHECK: The command was aborted due to an end-to-end guard check failure";
+       case NVME_SC_APPTAG_CHECK:
+               return "APPTAG_CHECK: The command was aborted due to an end-to-end application tag check failure";
+       case NVME_SC_REFTAG_CHECK:
+               return "REFTAG_CHECK: The command was aborted due to an end-to-end reference tag check failure";
+       case NVME_SC_COMPARE_FAILED:
+               return "COMPARE_FAILED: The command failed due to a miscompare during a Compare command";
+       case NVME_SC_ACCESS_DENIED:
+               return "ACCESS_DENIED: Access to the namespace and/or LBA range is denied due to lack of access rights";
+       case NVME_SC_UNWRITTEN_BLOCK:
+               return "UNWRITTEN_BLOCK: The command failed due to an attempt to read from an LBA range containing a deallocated or unwritten logical block";
+       case NVME_SC_ANA_PERSISTENT_LOSS:
+               return "ASYMMETRIC_NAMESPACE_ACCESS_PERSISTENT_LOSS: The requested function (e.g., command) is not able to be performed as a result of the relationship between the controller and the namespace being in the ANA Persistent Loss state";
+       case NVME_SC_ANA_INACCESSIBLE:
+               return "ASYMMETRIC_NAMESPACE_ACCESS_INACCESSIBLE: The requested function (e.g., command) is not able to be performed as a result of the relationship between the controller and the namespace being in the ANA Inaccessible state";
+       case NVME_SC_ANA_TRANSITION:
+               return "ASYMMETRIC_NAMESPACE_ACCESS_TRANSITION: The requested function (e.g., command) is not able to be performed as a result of the relationship between the controller and the namespace transitioning between Asymmetric Namespace Access states";
+       case NVME_SC_CMD_INTERRUPTED:
+               return "CMD_INTERRUPTED: Command processing was interrupted and the controller is unable to successfully complete the command. The host should retry the command.";
+       case NVME_SC_PMR_SAN_PROHIBITED:
+               return "Sanitize Prohibited While Persistent Memory Region is Enabled: A sanitize operation is prohibited while the Persistent Memory Region is enabled.";
+       default:
+               return "Unknown";
+       }
 }
 
-static void show_registers_cc_ams (__u8 ams)
+static const char *nvme_feature_lba_type_to_string(__u8 type)
 {
-       printf("\tArbitration Mechanism Selected     (AMS): ");
-       switch (ams) {
-       case 0:
-               printf("Round Robin\n");
-               break;
-       case 1:
-               printf("Weighted Round Robin with Urgent Priority Class\n");
-               break;
-       case 7:
-               printf("Vendor Specific\n");
-               break;
+       switch (type) {
+       case 0: return "Reserved";
+       case 1: return "Filesystem";
+       case 2: return "RAID";
+       case 3: return "Cache";
+       case 4: return "Page / Swap file";
        default:
-               printf("Reserved\n");
+               if (type>=0x05 && type<=0x7f)
+                       return "Reserved";
+               else
+                       return "Vendor Specific";
        }
 }
 
-static void show_registers_cc_shn (__u8 shn)
+void nvme_show_lba_range(struct nvme_lba_range_type *lbrt, int nr_ranges)
 {
-       printf("\tShutdown Notification              (SHN): ");
-       switch (shn) {
-       case 0:
-               printf("No notification; no effect\n");
-               break;
-       case 1:
-               printf("Normal shutdown notification\n");
-               break;
-       case 2:
-               printf("Abrupt shutdown notification\n");
-               break;
-       default:
-               printf("Reserved\n");
+       int i, j;
+
+       for (i = 0; i <= nr_ranges; i++) {
+               printf("\ttype       : %#x - %s\n", lbrt[i].type, nvme_feature_lba_type_to_string(lbrt[i].type));
+               printf("\tattributes : %#x - %s, %s\n", lbrt[i].attributes, (lbrt[i].attributes & 0x0001) ? "LBA range may be overwritten":"LBA range should not be overwritten",
+                       ((lbrt[i].attributes & 0x0002) >> 1) ? "LBA range should be hidden from the OS/EFI/BIOS":"LBA range should be visible from the OS/EFI/BIOS");
+               printf("\tslba       : %#"PRIx64"\n", (uint64_t)(lbrt[i].slba));
+               printf("\tnlb        : %#"PRIx64"\n", (uint64_t)(lbrt[i].nlb));
+               printf("\tguid       : ");
+               for (j = 0; j < 16; j++)
+                       printf("%02x", lbrt[i].guid[j]);
+               printf("\n");
        }
 }
 
-static void show_registers_cc(__u32 cc)
+
+static const char *nvme_feature_wl_hints_to_string(__u8 wh)
 {
-       printf("\tI/O Completion Queue Entry Size (IOCQES): %u bytes\n", 1 << ((cc & 0x00f00000) >> NVME_CC_IOCQES_SHIFT));
-       printf("\tI/O Submission Queue Entry Size (IOSQES): %u bytes\n", 1 << ((cc & 0x000f0000) >> NVME_CC_IOSQES_SHIFT));
-       show_registers_cc_shn((cc & 0x0000c000) >> NVME_CC_SHN_SHIFT);
-       show_registers_cc_ams((cc & 0x00003800) >> NVME_CC_AMS_SHIFT);
-       printf("\tMemory Page Size                   (MPS): %u bytes\n", 1 << (12 + ((cc & 0x00000780) >> NVME_CC_MPS_SHIFT)));
-       printf("\tI/O Command Sets Selected          (CSS): %s\n", (cc & 0x00000070) ? "Reserved":"NVM Command Set");
-       printf("\tEnable                              (EN): %s\n\n", (cc & 0x00000001) ? "Yes":"No");
+       switch (wh) {
+       case 0: return "No Workload";
+       case 1: return "Extended Idle Period with a Burst of Random Writes";
+       case 2: return "Heavy Sequential Writes";
+       default:return "Reserved";
+       }
 }
 
-static void show_registers_csts_shst(__u8 shst)
+static const char *nvme_feature_temp_type_to_string(__u8 type)
 {
-       printf("\tShutdown Status               (SHST): ");
-       switch (shst) {
-       case 0:
-               printf("Normal operation (no shutdown has been requested)\n");
-               break;
-       case 1:
-               printf("Shutdown processing occurring\n");
-               break;
-       case 2:
-               printf("Shutdown processing complete\n");
-               break;
-       default:
-               printf("Reserved\n");
+       switch (type) {
+       case 0: return "Over Temperature Threshold";
+       case 1: return "Under Temperature Threshold";
+       default:return "Reserved";
        }
 }
 
-static void show_registers_csts(__u32 csts)
+static const char *nvme_feature_temp_sel_to_string(__u8 sel)
 {
-       printf("\tProcessing Paused               (PP): %s\n", (csts & 0x00000020) ? "Yes":"No");
-       printf("\tNVM Subsystem Reset Occurred (NSSRO): %s\n", (csts & 0x00000010) ? "Yes":"No");
-       show_registers_csts_shst((csts & 0x0000000c) >> 2);
-       printf("\tController Fatal Status        (CFS): %s\n", (csts & 0x00000002) ? "True":"False");
-       printf("\tReady                          (RDY): %s\n\n", (csts & 0x00000001) ? "Yes":"No");
-
+       switch (sel)
+       {
+       case 0: return "Composite Temperature";
+       case 1: return "Temperature Sensor 1";
+       case 2: return "Temperature Sensor 2";
+       case 3: return "Temperature Sensor 3";
+       case 4: return "Temperature Sensor 4";
+       case 5: return "Temperature Sensor 5";
+       case 6: return "Temperature Sensor 6";
+       case 7: return "Temperature Sensor 7";
+       case 8: return "Temperature Sensor 8";
+       default:return "Reserved";
+       }
 }
 
-static void show_registers_aqa(__u32 aqa)
+static void nvme_show_auto_pst(struct nvme_auto_pst *apst)
 {
-       printf("\tAdmin Completion Queue Size (ACQS): %u\n", ((aqa & 0x0fff0000) >> 16)+1);
-       printf("\tAdmin Submission Queue Size (ASQS): %u\n\n", (aqa & 0x00000fff)+1);
+       int i;
 
+       printf( "\tAuto PST Entries");
+       printf("\t.................\n");
+       for (i = 0; i < 32; i++) {
+               printf("\tEntry[%2d]   \n", i);
+               printf("\t.................\n");
+               printf("\tIdle Time Prior to Transition (ITPT): %u ms\n", (apst[i].data & 0xffffff00) >> 8);
+               printf("\tIdle Transition Power State   (ITPS): %u\n", (apst[i].data & 0x000000f8) >> 3);
+               printf("\t.................\n");
+       }
 }
 
-static void show_registers_cmbloc(__u32 cmbloc, __u32 cmbsz)
+static void nvme_show_timestamp(struct nvme_timestamp *ts)
 {
-       if (cmbsz == 0) {
-               printf("\tController Memory Buffer feature is not supported\n\n");
-               return;
-       }
-
-        static const char *enforced[] = { "Enforced", "Not Enforced" };
-
-       printf("\tOffset                                                        (OFST): 0x%x (See cmbsz.szu for granularity)\n",
-                       (cmbloc & 0xfffff000) >> 12);
-
-       printf("\tCMB Queue Dword Alignment                                     (CQDA): %d\n",
-                       (cmbloc & 0x00000100) >> 8);
-
-       printf("\tCMB Data Metadata Mixed Memory Support                      (CDMMMS): %s\n",
-                       enforced[(cmbloc & 0x00000080) >> 7]);
-
-       printf("\tCMB Data Pointer and Command Independent Locations Support (CDPCILS): %s\n",
-                       enforced[(cmbloc & 0x00000040) >> 6]);
-
-       printf("\tCMB Data Pointer Mixed Locations Support                    (CDPMLS): %s\n",
-                       enforced[(cmbloc & 0x00000020) >> 5]);
-
-       printf("\tCMB Queue Physically Discontiguous Support                   (CQPDS): %s\n",
-                       enforced[(cmbloc & 0x00000010) >> 4]);
+       struct tm *tm;
+       char buffer[32];
+       time_t timestamp = int48_to_long(ts->timestamp) / 1000;
 
-       printf("\tCMB Queue Mixed Memory Support                               (CQMMS): %s\n",
-                       enforced[(cmbloc & 0x00000008) >> 3]);
+       tm = localtime(&timestamp);
+       strftime(buffer, sizeof(buffer), "%c %Z", tm);
 
-       printf("\tBase Indicator Register                                        (BIR): 0x%x\n\n",
-                       (cmbloc & 0x00000007));
+       printf("\tThe timestamp is : %"PRIu64" (%s)\n", int48_to_long(ts->timestamp), buffer);
+       printf("\t%s\n", (ts->attr & 2) ? "The Timestamp field was initialized with a "\
+                       "Timestamp value using a Set Features command." : "The Timestamp field was initialized "\
+                       "to â€˜0’ by a Controller Level Reset.");
+       printf("\t%s\n", (ts->attr & 1) ? "The controller may have stopped counting during vendor specific "\
+                       "intervals after the Timestamp value was initialized" : "The controller counted time in milliseconds "\
+                       "continuously since the Timestamp value was initialized.");
 }
 
-static const char *nvme_register_szu_to_string(__u8 szu)
+static void nvme_show_host_mem_buffer(struct nvme_host_mem_buffer *hmb)
 {
-       switch (szu) {
-       case 0: return "4 KB";
-       case 1: return "64 KB";
-       case 2: return "1 MB";
-       case 3: return "16 MB";
-       case 4: return "256 MB";
-       case 5: return "4 GB";
-       case 6: return "64 GB";
-       default:        return "Reserved";
-       }
+       printf("\tHost Memory Descriptor List Entry Count (HMDLEC): %u\n", hmb->hmdlec);
+       printf("\tHost Memory Descriptor List Address     (HMDLAU): 0x%x\n", hmb->hmdlau);
+       printf("\tHost Memory Descriptor List Address     (HMDLAL): 0x%x\n", hmb->hmdlal);
+       printf("\tHost Memory Buffer Size                  (HSIZE): %u\n", hmb->hsize);
 }
 
-static void show_registers_cmbsz(__u32 cmbsz)
+void nvme_directive_show_fields(__u8 dtype, __u8 doper, unsigned int result, unsigned char *buf)
 {
-       if (cmbsz == 0) {
-               printf("\tController Memory Buffer feature is not supported\n\n");
-               return;
-       }
-       printf("\tSize                      (SZ): %u\n", (cmbsz & 0xfffff000) >> 12);
-       printf("\tSize Units               (SZU): %s\n", nvme_register_szu_to_string((cmbsz & 0x00000f00) >> 8));
-       printf("\tWrite Data Support       (WDS): Write Data and metadata transfer in Controller Memory Buffer is %s\n",
-                       (cmbsz & 0x00000010) ? "Supported":"Not supported");
-       printf("\tRead Data Support        (RDS): Read Data and metadata transfer in Controller Memory Buffer is %s\n",
-                       (cmbsz & 0x00000008) ? "Supported":"Not supported");
-       printf("\tPRP SGL List Support   (LISTS): PRP/SG Lists in Controller Memory Buffer is %s\n",
-                       (cmbsz & 0x00000004) ? "Supported":"Not supported");
-       printf("\tCompletion Queue Support (CQS): Admin and I/O Completion Queues in Controller Memory Buffer is %s\n",
-                       (cmbsz & 0x00000002) ? "Supported":"Not supported");
-       printf("\tSubmission Queue Support (SQS): Admin and I/O Submission Queues in Controller Memory Buffer is %s\n\n",
-                       (cmbsz & 0x00000001) ? "Supported":"Not supported");
+        __u8 *field = buf;
+        int count, i;
+        switch (dtype) {
+        case NVME_DIR_IDENTIFY:
+                switch (doper) {
+                case NVME_DIR_RCV_ID_OP_PARAM:
+                        printf("\tDirective support \n");
+                        printf("\t\tIdentify Directive  : %s\n", (*field & 0x1) ? "supported":"not supported");
+                        printf("\t\tStream Directive    : %s\n", (*field & 0x2) ? "supported":"not supported");
+                        printf("\tDirective status \n");
+                        printf("\t\tIdentify Directive  : %s\n", (*(field + 32) & 0x1) ? "enabled" : "disabled");
+                        printf("\t\tStream Directive    : %s\n", (*(field + 32) & 0x2) ? "enabled" : "disabled");
+                        break;
+                default:
+                        fprintf(stderr, "invalid directive operations for Identify Directives\n");
+                }
+                break;
+        case NVME_DIR_STREAMS:
+                switch (doper) {
+                case NVME_DIR_RCV_ST_OP_PARAM:
+                        printf("\tMax Streams Limit                          (MSL): %u\n", *(__u16 *) field);
+                        printf("\tNVM Subsystem Streams Available           (NSSA): %u\n", *(__u16 *) (field + 2));
+                        printf("\tNVM Subsystem Streams Open                (NSSO): %u\n", *(__u16 *) (field + 4));
+                        printf("\tStream Write Size (in unit of LB size)     (SWS): %u\n", *(__u32 *) (field + 16));
+                        printf("\tStream Granularity Size (in unit of SWS)   (SGS): %u\n", *(__u16 *) (field + 20));
+                        printf("\tNamespece Streams Allocated                (NSA): %u\n", *(__u16 *) (field + 22));
+                        printf("\tNamespace Streams Open                     (NSO): %u\n", *(__u16 *) (field + 24));
+                        break;
+                case NVME_DIR_RCV_ST_OP_STATUS:
+                        count = *(__u16 *) field;
+                        printf("\tOpen Stream Count  : %u\n", *(__u16 *) field);
+                        for ( i = 0; i < count; i++ ) {
+                                printf("\tStream Identifier %.6u : %u\n", i + 1, *(__u16 *) (field + ((i + 1) * 2)));
+                        }
+                        break;
+                case NVME_DIR_RCV_ST_OP_RESOURCE:
+                        printf("\tNamespace Streams Allocated (NSA): %u\n", result & 0xffff);
+                        break;
+                default:
+                        fprintf(stderr, "invalid directive operations for Streams Directives\n");
+                }
+                break;
+        default:
+                fprintf(stderr, "invalid directive type\n");
+                break;
+        }
+        return;
 }
 
-static void show_registers_bpinfo_brs(__u8 brs)
+static const char *nvme_plm_window(__u32 plm)
 {
-       printf("\tBoot Read Status                (BRS): ");
-       switch (brs) {
-       case 0:
-               printf("No Boot Partition read operation requested\n");
-               break;
+       switch (plm & 0x7) {
        case 1:
-               printf("Boot Partition read in progress\n");
-               break;
+               return "Deterministic Window (DTWIN)";
        case 2:
-               printf("Boot Partition read completed successfully\n");
-               break;
-       case 3:
-               printf("Error completing Boot Partition read\n");
-               break;
+               return "Non-deterministic Window (NDWIN)";
        default:
-               printf("Invalid\n");
+               return "Reserved";
        }
 }
 
-static void show_registers_bpinfo(__u32 bpinfo)
+static void nvme_show_plm_config(struct nvme_plm_config *plmcfg)
 {
-       if (bpinfo == 0) {
-               printf("\tBoot Partition feature is not supported\n\n");
-               return;
-       }
-
-       printf("\tActive Boot Partition ID      (ABPID): %u\n", (bpinfo & 0x80000000) >> 31);
-       show_registers_bpinfo_brs((bpinfo & 0x03000000) >> 24);
-       printf("\tBoot Partition Size            (BPSZ): %u\n", bpinfo & 0x00007fff);
+       printf("\tEnable Event          :%04x\n", le16_to_cpu(plmcfg->enable_event));
+       printf("\tDTWIN Reads Threshold :%"PRIu64"\n", le64_to_cpu(plmcfg->dtwin_reads_thresh));
+       printf("\tDTWIN Writes Threshold:%"PRIu64"\n", le64_to_cpu(plmcfg->dtwin_writes_thresh));
+       printf("\tDTWIN Time Threshold  :%"PRIu64"\n", le64_to_cpu(plmcfg->dtwin_time_thresh));
 }
 
-static void show_registers_bprsel(__u32 bprsel)
+void nvme_feature_show_fields(__u32 fid, unsigned int result, unsigned char *buf)
 {
-       if (bprsel == 0) {
-               printf("\tBoot Partition feature is not supported\n\n");
-               return;
-       }
-
-       printf("\tBoot Partition Identifier      (BPID): %u\n", (bprsel & 0x80000000) >> 31);
-       printf("\tBoot Partition Read Offset    (BPROF): %x\n", (bprsel & 0x3ffffc00) >> 10);
-       printf("\tBoot Partition Read Size      (BPRSZ): %x\n", bprsel & 0x000003ff);
-}
+       __u8 field;
+       uint64_t ull;
 
-static void show_registers_bpmbl(uint64_t bpmbl)
-{
-       if (bpmbl == 0) {
-               printf("\tBoot Partition feature is not supported\n\n");
-               return;
+       switch (fid) {
+       case NVME_FEAT_ARBITRATION:
+               printf("\tHigh Priority Weight   (HPW): %u\n", ((result & 0xff000000) >> 24) + 1);
+               printf("\tMedium Priority Weight (MPW): %u\n", ((result & 0x00ff0000) >> 16) + 1);
+               printf("\tLow Priority Weight    (LPW): %u\n", ((result & 0x0000ff00) >> 8) + 1);
+               printf("\tArbitration Burst       (AB): ");
+               if ((result & 0x00000007) == 7)
+                       printf("No limit\n");
+               else
+                       printf("%u\n",  1 << (result & 0x00000007));
+               break;
+       case NVME_FEAT_POWER_MGMT:
+               field = (result & 0x000000E0) >> 5;
+               printf("\tWorkload Hint (WH): %u - %s\n",  field, nvme_feature_wl_hints_to_string(field));
+               printf("\tPower State   (PS): %u\n",  result & 0x0000001f);
+               break;
+       case NVME_FEAT_LBA_RANGE:
+               field = result & 0x0000003f;
+               printf("\tNumber of LBA Ranges (NUM): %u\n", field + 1);
+               nvme_show_lba_range((struct nvme_lba_range_type *)buf, field);
+               break;
+       case NVME_FEAT_TEMP_THRESH:
+               field = (result & 0x00300000) >> 20;
+               printf("\tThreshold Type Select         (THSEL): %u - %s\n", field, nvme_feature_temp_type_to_string(field));
+               field = (result & 0x000f0000) >> 16;
+               printf("\tThreshold Temperature Select (TMPSEL): %u - %s\n", field, nvme_feature_temp_sel_to_string(field));
+               printf("\tTemperature Threshold         (TMPTH): %d C\n", (result & 0x0000ffff) - 273);
+               break;
+       case NVME_FEAT_ERR_RECOVERY:
+               printf("\tDeallocated or Unwritten Logical Block Error Enable (DULBE): %s\n", ((result & 0x00010000) >> 16) ? "Enabled":"Disabled");
+               printf("\tTime Limited Error Recovery                          (TLER): %u ms\n", (result & 0x0000ffff) * 100);
+               break;
+       case NVME_FEAT_VOLATILE_WC:
+               printf("\tVolatile Write Cache Enable (WCE): %s\n", (result & 0x00000001) ? "Enabled":"Disabled");
+               break;
+       case NVME_FEAT_NUM_QUEUES:
+               printf("\tNumber of IO Completion Queues Allocated (NCQA): %u\n", ((result & 0xffff0000) >> 16) + 1);
+               printf("\tNumber of IO Submission Queues Allocated (NSQA): %u\n",  (result & 0x0000ffff) + 1);
+               break;
+       case NVME_FEAT_IRQ_COALESCE:
+               printf("\tAggregation Time     (TIME): %u usec\n", ((result & 0x0000ff00) >> 8) * 100);
+               printf("\tAggregation Threshold (THR): %u\n",  (result & 0x000000ff) + 1);
+               break;
+       case NVME_FEAT_IRQ_CONFIG:
+               printf("\tCoalescing Disable (CD): %s\n", ((result & 0x00010000) >> 16) ? "True":"False");
+               printf("\tInterrupt Vector   (IV): %u\n",  result & 0x0000ffff);
+               break;
+       case NVME_FEAT_WRITE_ATOMIC:
+               printf("\tDisable Normal (DN): %s\n", (result & 0x00000001) ? "True":"False");
+               break;
+       case NVME_FEAT_ASYNC_EVENT:
+               printf("\tTelemetry Log Notices           : %s\n", ((result & 0x00000400) >> 10) ? "Send async event":"Do not send async event");
+               printf("\tFirmware Activation Notices     : %s\n", ((result & 0x00000200) >> 9) ? "Send async event":"Do not send async event");
+               printf("\tNamespace Attribute Notices     : %s\n", ((result & 0x00000100) >> 8) ? "Send async event":"Do not send async event");
+               printf("\tSMART / Health Critical Warnings: %s\n", (result & 0x000000ff) ? "Send async event":"Do not send async event");
+               break;
+       case NVME_FEAT_AUTO_PST:
+               printf("\tAutonomous Power State Transition Enable (APSTE): %s\n", (result & 0x00000001) ? "Enabled":"Disabled");
+               nvme_show_auto_pst((struct nvme_auto_pst *)buf);
+               break;
+       case NVME_FEAT_HOST_MEM_BUF:
+               printf("\tMemory Return       (MR): %s\n", ((result & 0x00000002) >> 1) ? "True":"False");
+               printf("\tEnable Host Memory (EHM): %s\n", (result & 0x00000001) ? "Enabled":"Disabled");
+               nvme_show_host_mem_buffer((struct nvme_host_mem_buffer *)buf);
+               break;
+       case NVME_FEAT_SW_PROGRESS:
+               printf("\tPre-boot Software Load Count (PBSLC): %u\n", result & 0x000000ff);
+               break;
+       case NVME_FEAT_PLM_CONFIG:
+               printf("\tPredictable Latency Window Enabled: %s\n", result & 0x1 ? "True":"False");
+               nvme_show_plm_config((struct nvme_plm_config *)buf);
+               break;
+       case NVME_FEAT_PLM_WINDOW:
+               printf("\tWindow Select: %s", nvme_plm_window(result));
+               break;
+       case NVME_FEAT_HOST_ID:
+               ull =  buf[7]; ull <<= 8; ull |= buf[6]; ull <<= 8; ull |= buf[5]; ull <<= 8;
+               ull |= buf[4]; ull <<= 8; ull |= buf[3]; ull <<= 8; ull |= buf[2]; ull <<= 8;
+               ull |= buf[1]; ull <<= 8; ull |= buf[0];
+               printf("\tHost Identifier (HOSTID):  %" PRIu64 "\n", ull);
+               break;
+       case NVME_FEAT_RESV_MASK:
+               printf("\tMask Reservation Preempted Notification  (RESPRE): %s\n", ((result & 0x00000008) >> 3) ? "True":"False");
+               printf("\tMask Reservation Released Notification   (RESREL): %s\n", ((result & 0x00000004) >> 2) ? "True":"False");
+               printf("\tMask Registration Preempted Notification (REGPRE): %s\n", ((result & 0x00000002) >> 1) ? "True":"False");
+               break;
+       case NVME_FEAT_RESV_PERSIST:
+               printf("\tPersist Through Power Loss (PTPL): %s\n", (result & 0x00000001) ? "True":"False");
+               break;
+       case NVME_FEAT_WRITE_PROTECT:
+               printf("\tNamespace Write Protect: %s\n", result != NVME_NS_NO_WRITE_PROTECT ? "True" :  "False");
+               break;
+       case NVME_FEAT_TIMESTAMP:
+               nvme_show_timestamp((struct nvme_timestamp *)buf);
+               break;
+       case NVME_FEAT_HCTM:
+               printf("\tThermal Management Temperature 1 (TMT1) : %u Kelvin\n", (result >> 16));
+               printf("\tThermal Management Temperature 2 (TMT2) : %u Kelvin\n", (result & 0x0000ffff));
+               break;
+       case NVME_FEAT_KATO:
+               printf("\tKeep Alive Timeout (KATO) in milliseconds: %u\n", result);
+               break;
+       case NVME_FEAT_NOPSC:
+               printf("\tNon-Operational Power State Permissive Mode Enable (NOPPME): %s\n", (result & 1) ? "True" : "False");
+               break;
+       case NVME_FEAT_HOST_BEHAVIOR:
+               printf("\tHost Behavior Support: %s\n", (buf[0] & 0x1) ? "True" : "False");
+               break;
        }
-
-       printf("\tBoot Partition Memory Buffer Base Address (BMBBA): %"PRIx64"\n", bpmbl);
 }
 
-static void show_registers_cmbmsc(uint64_t cmbmsc)
+void nvme_show_lba_status(struct nvme_lba_status *list, unsigned long len,
+                       enum nvme_print_flags flags)
 {
-       printf("\tController Base Address (CBA)      : %lx\n",
-                       (cmbmsc & 0xfffffffffffff000) >> 12);
-       printf("\tController Memory Space Enable (CMSE): %lx\n",
-                       (cmbmsc & 0x0000000000000002) >> 1);
-       printf("\tCapabilities Registers Enabled (CRE) : CMBLOC and "\
-              "CMBSZ registers are%senabled\n\n", (cmbmsc & 0x0000000000000001) ? " " : " NOT ");
-}
+       int idx;
 
-static void show_registers_cmbsts(__u32 cmbsts)
-{
-       printf("\tController Base Address Invalid (CBAI): %x\n\n", (cmbsts & 0x00000001));
-}
+       if (flags & BINARY)
+               return  d_raw((unsigned char *)list, len);
 
-static void show_registers_pmrcap(__u32 pmrcap)
-{
-       printf("\tController Memory Space Supported (CMSS)                 : "\
-              "Referencing PMR with host supplied addresses is %s\n",
-              ((pmrcap & 0x01000000) >> 24) ? "Supported" : "Not Supported");
-       printf("\tPersistent Memory Region Timeout                  (PMRTO): %x\n", (pmrcap & 0x00ff0000) >> 16);
-       printf("\tPersistent Memory Region Write Barrier Mechanisms(PMRWBM): %x\n", (pmrcap & 0x00003c00) >> 10);
-       printf("\tPersistent Memory Region Time Units               (PMRTU): PMR time unit is %s\n",
-                       (pmrcap & 0x00000300) >> 8 ? "minutes":"500 milliseconds");
-       printf("\tBase Indicator Register                             (BIR): %x\n", (pmrcap & 0x000000e0) >> 5);
-       printf("\tWrite Data Support                                  (WDS): Write data to the PMR is %s\n",
-                       (pmrcap & 0x00000010) ? "supported":"not supported");
-       printf("\tRead Data Support                                   (RDS): Read data from the PMR is %s\n",
-                       (pmrcap & 0x00000008) ? "supported":"not supported");
-}
+       printf("Number of LBA Status Descriptors(NLSD): %" PRIu64 "\n",
+               le64_to_cpu(list->nlsd));
+       printf("Completion Condition(CMPC): %u\n", list->cmpc);
 
-static void show_registers_pmrctl(__u32 pmrctl)
-{
-       printf("\tEnable (EN): PMR is %s\n", (pmrctl & 0x00000001) ? "READY":"Disabled");
-}
+       switch (list->cmpc) {
+       case 1:
+               printf("\tCompleted due to transferring the amount of data"\
+                       " specified in the MNDW field\n");
+               break;
+       case 2:
+               printf("\tCompleted due to having performed the action\n"\
+                       "\tspecified in the Action Type field over the\n"\
+                       "\tnumber of logical blocks specified in the\n"\
+                       "\tRange Length field\n");
+               break;
+       }
 
-static const char *nvme_register_pmr_hsts_to_string(__u8 hsts)
-{
-        switch (hsts) {
-        case 0: return "Normal Operation";
-        case 1: return "Restore Error";
-        case 2: return "Read Only";
-        case 3: return "Unreliable";
-        default: return "Reserved";
-        }
+       for (idx = 0; idx < list->nlsd; idx++) {
+               struct nvme_lba_status_desc *e = &list->descs[idx];
+               printf("{ DSLBA: 0x%016"PRIu64", NLB: 0x%08x, Status: 0x%02x }\n",
+                               le64_to_cpu(e->dslba), le32_to_cpu(e->nlb),
+                               e->status);
+       }
 }
 
-static void show_registers_pmrsts(__u32 pmrsts, __u32 pmrctl)
+static void nvme_show_list_item(struct nvme_namespace *n)
 {
-       printf("\tController Base Address Invalid (CBAI): %x\n", (pmrsts & 0x00001000) >> 12);
-       printf("\tHealth Status                   (HSTS): %s\n", nvme_register_pmr_hsts_to_string((pmrsts & 0x00000e00) >> 9));
-       printf("\tNot Ready                       (NRDY): The Persistent Memory Region is %s to process "\
-              "PCI Express memory read and write requests\n",
-              (pmrsts & 0x00000100) == 0 && (pmrctl & 0x00000001) ? "READY":"Not Ready");
-       printf("\tError                           (ERR) : %x\n", (pmrsts & 0x000000ff));
-}
+       long long lba   = 1 << n->ns.lbaf[(n->ns.flbas & 0x0f)].ds;
+       double nsze     = le64_to_cpu(n->ns.nsze) * lba;
+       double nuse     = le64_to_cpu(n->ns.nuse) * lba;
 
-static const char *nvme_register_pmr_pmrszu_to_string(__u8 pmrszu)
-{
-       switch (pmrszu) {
-       case 0: return "Bytes";
-       case 1: return "One KB";
-       case 2: return "One MB";
-       case 3: return "One GB";
-       default: return "Reserved";
-       }
-}
+       const char *s_suffix = suffix_si_get(&nsze);
+       const char *u_suffix = suffix_si_get(&nuse);
+       const char *l_suffix = suffix_binary_get(&lba);
 
-static void show_registers_pmrebs(__u32 pmrebs)
-{
-       printf("\tPMR Elasticity Buffer Size Base  (PMRWBZ): %x\n", (pmrebs & 0xffffff00) >> 8);
-       printf("\tRead Bypass Behavior                     : memory reads not conflicting with memory writes "\
-              "in the PMR Elasticity Buffer %s bypass those memory writes\n",
-              (pmrebs & 0x00000010) ? "SHALL":"MAY");
-       printf("\tPMR Elasticity Buffer Size Units (PMRSZU): %s\n",
-               nvme_register_pmr_pmrszu_to_string(pmrebs & 0x0000000f));
-}
+       char usage[128];
+       char format[128];
 
-static void show_registers_pmrswtp(__u32 pmrswtp)
-{
-       printf("\tPMR Sustained Write Throughput       (PMRSWTV): %x\n", (pmrswtp & 0xffffff00) >> 8);
-       printf("\tPMR Sustained Write Throughput Units (PMRSWTU): %s/second\n",
-               nvme_register_pmr_pmrszu_to_string(pmrswtp & 0x0000000f));
+       sprintf(usage,"%6.2f %2sB / %6.2f %2sB", nuse, u_suffix,
+               nsze, s_suffix);
+       sprintf(format,"%3.0f %2sB + %2d B", (double)lba, l_suffix,
+               le16_to_cpu(n->ns.lbaf[(n->ns.flbas & 0x0f)].ms));
+       printf("/dev/%-11s %-*.*s %-*.*s %-9d %-26s %-16s %-.*s\n", n->name,
+               (int)sizeof(n->ctrl->id.sn), (int)sizeof(n->ctrl->id.sn), n->ctrl->id.sn,
+               (int)sizeof(n->ctrl->id.mn), (int)sizeof(n->ctrl->id.mn), n->ctrl->id.mn,
+               n->nsid, usage, format, (int)sizeof(n->ctrl->id.fr), n->ctrl->id.fr);
 }
 
-static void show_registers_pmrmsc(uint64_t pmrmsc)
+static void nvme_show_simple_list(struct nvme_topology *t)
 {
-       printf("\tController Base Address (CBA)         : %lx\n", (pmrmsc & 0xfffffffffffff000) >> 12);
-       printf("\tController Memory Space Enable (CMSE  : %lx\n\n", (pmrmsc & 0x0000000000000001) >> 1);
-}
+       int i, j, k;
 
-static inline uint32_t mmio_read32(void *addr)
-{
-       __le32 *p = addr;
+       printf("%-16s %-20s %-40s %-9s %-26s %-16s %-8s\n",
+           "Node", "SN", "Model", "Namespace", "Usage", "Format", "FW Rev");
+       printf("%-.16s %-.20s %-.40s %-.9s %-.26s %-.16s %-.8s\n", dash, dash,
+               dash, dash, dash, dash, dash);
 
-       return le32_to_cpu(*p);
-}
+       for (i = 0; i < t->nr_subsystems; i++) {
+               struct nvme_subsystem *s = &t->subsystems[i];
 
-/* Access 64-bit registers as 2 32-bit; Some devices fail 64-bit MMIO. */
-static inline __u64 mmio_read64(void *addr)
-{
-       __le32 *p = addr;
+               for (j = 0; j < s->nr_ctrls; j++) {
+                       struct nvme_ctrl *c = &s->ctrls[j];
 
-       return le32_to_cpu(*p) | ((uint64_t)le32_to_cpu(*(p + 1)) << 32);
+                       for (k = 0; k < c->nr_namespaces; k++) {
+                               struct nvme_namespace *n = &c->namespaces[k];
+                               nvme_show_list_item(n);
+                       }
+               }
+
+               for (j = 0; j < s->nr_namespaces; j++) {
+                       struct nvme_namespace *n = &s->namespaces[j];
+                       nvme_show_list_item(n);
+               }
+       }
 }
 
-void json_ctrl_registers(void *bar)
+static void nvme_show_details_ns(struct nvme_namespace *n, bool ctrl)
 {
-       uint64_t cap, asq, acq, bpmbl, cmbmsc, pmrmsc;
-       uint32_t vs, intms, intmc, cc, csts, nssr, aqa, cmbsz, cmbloc,
-                       bpinfo, bprsel, cmbsts, pmrcap, pmrctl, pmrsts, pmrebs, pmrswtp;
-       struct json_object *root;
+       long long lba   = 1 << n->ns.lbaf[(n->ns.flbas & 0x0f)].ds;
+       double nsze     = le64_to_cpu(n->ns.nsze) * lba;
+       double nuse     = le64_to_cpu(n->ns.nuse) * lba;
 
-       cap = mmio_read64(bar + NVME_REG_CAP);
-       vs = mmio_read32(bar + NVME_REG_VS);
-       intms = mmio_read32(bar + NVME_REG_INTMS);
-       intmc = mmio_read32(bar + NVME_REG_INTMC);
-       cc = mmio_read32(bar + NVME_REG_CC);
-       csts = mmio_read32(bar + NVME_REG_CSTS);
-       nssr = mmio_read32(bar + NVME_REG_NSSR);
-       aqa = mmio_read32(bar + NVME_REG_AQA);
-       asq = mmio_read64(bar + NVME_REG_ASQ);
-       acq = mmio_read64(bar + NVME_REG_ACQ);
-       cmbloc = mmio_read32(bar + NVME_REG_CMBLOC);
-       cmbsz = mmio_read32(bar + NVME_REG_CMBSZ);
-       bpinfo = mmio_read32(bar + NVME_REG_BPINFO);
-       bprsel = mmio_read32(bar + NVME_REG_BPRSEL);
-       bpmbl = mmio_read64(bar + NVME_REG_BPMBL);
-       cmbmsc = mmio_read64(bar + NVME_REG_CMBMSC);
-       cmbsts = mmio_read32(bar + NVME_REG_CMBSTS);
-       pmrcap = mmio_read32(bar + NVME_REG_PMRCAP);
-       pmrctl = mmio_read32(bar + NVME_REG_PMRCTL);
-       pmrsts = mmio_read32(bar + NVME_REG_PMRSTS);
-       pmrebs = mmio_read32(bar + NVME_REG_PMREBS);
-       pmrswtp = mmio_read32(bar + NVME_REG_PMRSWTP);
-       pmrmsc = mmio_read64(bar + NVME_REG_PMRMSC);
+       const char *s_suffix = suffix_si_get(&nsze);
+       const char *u_suffix = suffix_si_get(&nuse);
+       const char *l_suffix = suffix_binary_get(&lba);
 
-       root = json_create_object();
-       json_object_add_value_uint(root, "cap", cap);
-       json_object_add_value_int(root, "vs", vs);
-       json_object_add_value_int(root, "intms", intms);
-       json_object_add_value_int(root, "intmc", intmc);
-       json_object_add_value_int(root, "cc", cc);
-       json_object_add_value_int(root, "csts", csts);
-       json_object_add_value_int(root, "nssr", nssr);
-       json_object_add_value_int(root, "aqa", aqa);
-       json_object_add_value_uint(root, "asq", asq);
-       json_object_add_value_uint(root, "acq", acq);
-       json_object_add_value_int(root, "cmbloc", cmbloc);
-       json_object_add_value_int(root, "cmbsz", cmbsz);
-       json_object_add_value_int(root, "bpinfo", bpinfo);
-       json_object_add_value_int(root, "bprsel", bprsel);
-       json_object_add_value_uint(root, "bpmbl", bpmbl);
-       json_object_add_value_uint(root, "cmbmsc", cmbmsc);
-       json_object_add_value_int(root, "cmbsts", cmbsts);
-       json_object_add_value_int(root, "pmrcap", pmrcap);
-       json_object_add_value_int(root, "pmrctl", pmrctl);
-       json_object_add_value_int(root, "pmrsts", pmrsts);
-       json_object_add_value_int(root, "pmrebs", pmrebs);
-       json_object_add_value_int(root, "pmrswtp", pmrswtp);
-       json_object_add_value_uint(root, "pmrmsc", pmrmsc);
-       json_print_object(root, NULL);
+       char usage[128];
+       char format[128];
+
+       sprintf(usage,"%6.2f %2sB / %6.2f %2sB", nuse, u_suffix,
+               nsze, s_suffix);
+       sprintf(format,"%3.0f %2sB + %2d B", (double)lba, l_suffix,
+               le16_to_cpu(n->ns.lbaf[(n->ns.flbas & 0x0f)].ms));
+
+       printf("%-12s %-8x %-26s %-16s ", n->name, n->nsid, usage, format);
+
+       if (ctrl)
+               printf("%s", n->ctrl->name);
+       else {
+               struct nvme_subsystem *s = n->ctrl->subsys;
+               int i;
+
+               for (i = 0; i < s->nr_ctrls; i++)
+                       printf("%s%s", i ? ", " : "", s->ctrls[i].name);
+       }
        printf("\n");
-       json_free_object(root);
 }
 
-void show_ctrl_registers(void *bar, unsigned int mode, bool fabrics)
+static void nvme_show_detailed_list(struct nvme_topology *t)
 {
-       uint64_t cap, asq, acq, bpmbl, cmbmsc, pmrmsc;
-       uint32_t vs, intms, intmc, cc, csts, nssr, aqa, cmbsz, cmbloc, bpinfo,
-                bprsel, cmbsts, pmrcap, pmrctl, pmrsts, pmrebs, pmrswtp;
+       int i, j, k;
 
-       int human = mode & HUMAN;
+       printf("NVM Express Subsystems\n\n");
+       printf("%-16s %-96s %-.16s\n", "Subsystem", "Subsystem-NQN", "Controllers");
+       printf("%-.16s %-.96s %-.16s\n", dash, dash, dash);
+       for (i = 0; i < t->nr_subsystems; i++) {
+               struct nvme_subsystem *s = &t->subsystems[i];
 
-       cap = mmio_read64(bar + NVME_REG_CAP);
-       vs = mmio_read32(bar + NVME_REG_VS);
-       intms = mmio_read32(bar + NVME_REG_INTMS);
-       intmc = mmio_read32(bar + NVME_REG_INTMC);
-       cc = mmio_read32(bar + NVME_REG_CC);
-       csts = mmio_read32(bar + NVME_REG_CSTS);
-       nssr = mmio_read32(bar + NVME_REG_NSSR);
-       aqa = mmio_read32(bar + NVME_REG_AQA);
-       asq = mmio_read64(bar + NVME_REG_ASQ);
-       acq = mmio_read64(bar + NVME_REG_ACQ);
-       cmbloc = mmio_read32(bar + NVME_REG_CMBLOC);
-       cmbsz = mmio_read32(bar + NVME_REG_CMBSZ);
-       bpinfo = mmio_read32(bar + NVME_REG_BPINFO);
-       bprsel = mmio_read32(bar + NVME_REG_BPRSEL);
-       bpmbl = mmio_read64(bar + NVME_REG_BPMBL);
-       cmbmsc = mmio_read64(bar + NVME_REG_CMBMSC);
-       cmbsts = mmio_read32(bar + NVME_REG_CMBSTS);
-       pmrcap = mmio_read32(bar + NVME_REG_PMRCAP);
-       pmrctl = mmio_read32(bar + NVME_REG_PMRCTL);
-       pmrsts = mmio_read32(bar + NVME_REG_PMRSTS);
-       pmrebs = mmio_read32(bar + NVME_REG_PMREBS);
-       pmrswtp = mmio_read32(bar + NVME_REG_PMRSWTP);
-       pmrmsc = mmio_read64(bar + NVME_REG_PMRMSC);
+               printf("%-16s %-96s ", s->name, s->subsysnqn);
+               for (j = 0; j < s->nr_ctrls; j++) {
+                       struct nvme_ctrl *c = &s->ctrls[j];
 
-       if (human) {
-               if (cap != 0xffffffff) {
-                       printf("cap     : %"PRIx64"\n", cap);
-                       show_registers_cap((struct nvme_bar_cap *)&cap);
-               }
-               if (vs != 0xffffffff) {
-                       printf("version : %x\n", vs);
-                       show_registers_version(vs);
+                       printf("%s%s", j ? ", " : "", c->name);
                }
-               if (cc != 0xffffffff) {
-                       printf("cc      : %x\n", cc);
-                       show_registers_cc(cc);
+               printf("\n");
+       };
+
+       printf("\nNVM Express Controllers\n\n");
+       printf("%-8s %-20s %-40s %-8s %-6s %-14s %-12s %-16s\n", "Device",
+               "SN", "MN", "FR", "TxPort", "Address", "Subsystem", "Namespaces");
+       printf("%-.8s %-.20s %-.40s %-.8s %-.6s %-.14s %-.12s %-.16s\n", dash, dash,
+               dash, dash, dash, dash, dash, dash);
+       for (i = 0; i < t->nr_subsystems; i++) {
+               struct nvme_subsystem *s = &t->subsystems[i];
+
+               for (j = 0; j < s->nr_ctrls; j++) {
+                       bool comma = false;
+                       struct nvme_ctrl *c = &s->ctrls[j];
+
+                       printf("%-8s %-.20s %-.40s %-.8s %-6s %-14s %-12s ",
+                               c->name, c->id.sn, c->id.mn, c->id.fr,
+                               c->transport, c->address, s->name);
+
+                       for (k = 0; k < c->nr_namespaces; k++) {
+                               struct nvme_namespace *n = &c->namespaces[k];
+                               printf("%s%s", comma ? ", " : "", n->name);
+                               comma = true;
+                       }
+                       for (k = 0; k < s->nr_namespaces; k++) {
+                               struct nvme_namespace *n = &s->namespaces[k];
+                               printf("%s%s", comma ? ", " : "", n->name);
+                               comma = true;
+                       }
+                       printf("\n");
                }
-               if (csts != 0xffffffff) {
-                       printf("csts    : %x\n", csts);
-                       show_registers_csts(csts);
+       }
+
+       printf("\nNVM Express Namespaces\n\n");
+       printf("%-12s %-8s %-26s %-16s %-16s\n", "Device", "NSID", "Usage", "Format", "Controllers");
+       printf("%-.12s %-.8s %-.26s %-.16s %-.16s\n", dash, dash, dash, dash, dash);
+
+       for (i = 0; i < t->nr_subsystems; i++) {
+               struct nvme_subsystem *s = &t->subsystems[i];
+
+               for (j = 0; j < s->nr_ctrls; j++) {
+                       struct nvme_ctrl *c = &s->ctrls[j];
+
+                       for (k = 0; k < c->nr_namespaces; k++) {
+                               struct nvme_namespace *n = &c->namespaces[k];
+                               nvme_show_details_ns(n, true);
+                       }
                }
-               if (nssr != 0xffffffff) {
-                       printf("nssr    : %x\n", nssr);
-                       printf("\tNVM Subsystem Reset Control (NSSRC): %u\n\n", nssr);
+               for (j = 0; j < s->nr_namespaces; j++) {
+                       struct nvme_namespace *n = &s->namespaces[j];
+                       nvme_show_details_ns(n, false);
                }
-               if (!fabrics) {
-                       printf("intms   : %x\n", intms);
-                       printf("\tInterrupt Vector Mask Set (IVMS): %x\n\n",
-                                       intms);
+       }
+}
 
-                       printf("intmc   : %x\n", intmc);
-                       printf("\tInterrupt Vector Mask Clear (IVMC): %x\n\n",
-                                       intmc);
-                       printf("aqa     : %x\n", aqa);
-                       show_registers_aqa(aqa);
+static void json_detail_ns(struct nvme_namespace *n, struct json_object *ns_attrs)
+{
+       long long lba;
+       double nsze, nuse;
 
-                       printf("asq     : %"PRIx64"\n", asq);
-                       printf("\tAdmin Submission Queue Base (ASQB): %"PRIx64"\n\n",
-                                       asq);
+       lba = 1 << n->ns.lbaf[(n->ns.flbas & 0x0f)].ds;
+       nsze = le64_to_cpu(n->ns.nsze) * lba;
+       nuse = le64_to_cpu(n->ns.nuse) * lba;
 
-                       printf("acq     : %"PRIx64"\n", acq);
-                       printf("\tAdmin Completion Queue Base (ACQB): %"PRIx64"\n\n",
-                                       acq);
+       json_object_add_value_string(ns_attrs, "NameSpace", n->name);
+       json_object_add_value_uint(ns_attrs, "NSID", n->nsid);
 
-                       printf("cmbloc  : %x\n", cmbloc);
-                       show_registers_cmbloc(cmbloc, cmbsz);
+       json_object_add_value_uint(ns_attrs, "UsedBytes", nuse);
+       json_object_add_value_uint(ns_attrs, "MaximumLBA",
+               le64_to_cpu(n->ns.nsze));
+       json_object_add_value_uint(ns_attrs, "PhysicalSize", nsze);
+       json_object_add_value_uint(ns_attrs, "SectorSize", lba);
+}
 
-                       printf("cmbsz   : %x\n", cmbsz);
-                       show_registers_cmbsz(cmbsz);
+static void json_detail_list(struct nvme_topology *t)
+{
+       int i, j, k;
+       struct json_object *root;
+       struct json_array *devices;
+       char formatter[41] = { 0 };
 
-                       printf("bpinfo  : %x\n", bpinfo);
-                       show_registers_bpinfo(bpinfo);
+       root = json_create_object();
+       devices = json_create_array();
 
-                       printf("bprsel  : %x\n", bprsel);
-                       show_registers_bprsel(bprsel);
+       for (i = 0; i < t->nr_subsystems; i++) {
+               struct nvme_subsystem *s = &t->subsystems[i];
+               struct json_object *subsys_attrs;
+               struct json_array *namespaces, *ctrls;
+
+               subsys_attrs = json_create_object();
+               json_object_add_value_string(subsys_attrs, "Subsystem", s->name);
+               json_object_add_value_string(subsys_attrs, "SubsystemNQN", s->subsysnqn);
 
-                       printf("bpmbl   : %"PRIx64"\n", bpmbl);
-                       show_registers_bpmbl(bpmbl);
+               ctrls = json_create_array();
+               json_object_add_value_array(subsys_attrs, "Controllers", ctrls);
+               for (j = 0; j < s->nr_ctrls; j++) {
+                       struct json_object *ctrl_attrs = json_create_object();
+                       struct nvme_ctrl *c = &s->ctrls[j];
+                       struct json_array *namespaces;
 
-                       printf("cmbmsc  : %"PRIx64"\n", cmbmsc);
-                       show_registers_cmbmsc(cmbmsc);
+                       json_object_add_value_string(ctrl_attrs, "Controller", c->name);
+                       json_object_add_value_string(ctrl_attrs, "Transport", c->transport);
+                       json_object_add_value_string(ctrl_attrs, "Address", c->address);
+                       json_object_add_value_string(ctrl_attrs, "State", c->state);
 
-                       printf("cmbsts  : %x\n", cmbsts);
-                       show_registers_cmbsts(cmbsts);
+                       format(formatter, sizeof(formatter), c->id.fr, sizeof(c->id.fr));
+                       json_object_add_value_string(ctrl_attrs, "Firmware", formatter);
 
-                       printf("pmrcap  : %x\n", pmrcap);
-                       show_registers_pmrcap(pmrcap);
+                       format(formatter, sizeof(formatter), c->id.mn, sizeof(c->id.mn));
+                       json_object_add_value_string(ctrl_attrs, "ModelNumber", formatter);
 
-                       printf("pmrctl  : %x\n", pmrctl);
-                       show_registers_pmrctl(pmrctl);
+                       format(formatter, sizeof(formatter), c->id.sn, sizeof(c->id.sn));
+                       json_object_add_value_string(ctrl_attrs, "SerialNumber", formatter);
 
-                       printf("pmrsts  : %x\n", pmrsts);
-                       show_registers_pmrsts(pmrsts, pmrctl);
+                       namespaces = json_create_array();
 
-                       printf("pmrebs  : %x\n", pmrebs);
-                       show_registers_pmrebs(pmrebs);
+                       for (k = 0; k < c->nr_namespaces; k++) {
+                               struct json_object *ns_attrs = json_create_object();
+                               struct nvme_namespace *n = &c->namespaces[k];
 
-                       printf("pmrswtp : %x\n", pmrswtp);
-                       show_registers_pmrswtp(pmrswtp);
+                               json_detail_ns(n, ns_attrs);
+                               json_array_add_value_object(namespaces, ns_attrs);
+                       }
+                       if (k)
+                               json_object_add_value_array(ctrl_attrs, "Namespaces", namespaces);
+                       else
+                               json_free_array(namespaces);
 
-                       printf("pmrmsc  : %"PRIx64"\n", pmrmsc);
-                       show_registers_pmrmsc(pmrmsc);
+                       json_array_add_value_object(ctrls, ctrl_attrs);
                }
-       } else {
-               if (cap != 0xffffffff)
-                       printf("cap     : %"PRIx64"\n", cap);
-               if (vs != 0xffffffff)
-                       printf("version : %x\n", vs);
-               if (cc != 0xffffffff)
-                       printf("cc      : %x\n", cc);
-               if (csts != 0xffffffff)
-                       printf("csts    : %x\n", csts);
-               if (nssr != 0xffffffff)
-                       printf("nssr    : %x\n", nssr);
-               if (!fabrics) {
-                       printf("intms   : %x\n", intms);
-                       printf("intmc   : %x\n", intmc);
-                       printf("aqa     : %x\n", aqa);
-                       printf("asq     : %"PRIx64"\n", asq);
-                       printf("acq     : %"PRIx64"\n", acq);
-                       printf("cmbloc  : %x\n", cmbloc);
-                       printf("cmbsz   : %x\n", cmbsz);
-                       printf("bpinfo  : %x\n", bpinfo);
-                       printf("bprsel  : %x\n", bprsel);
-                       printf("bpmbl   : %"PRIx64"\n", bpmbl);
-                       printf("cmbmsc  : %"PRIx64"\n", cmbmsc);
-                       printf("cmbsts  : %x\n", cmbsts);
-                       printf("pmrcap  : %x\n", pmrcap);
-                       printf("pmrctl  : %x\n", pmrctl);
-                       printf("pmrsts  : %x\n", pmrsts);
-                       printf("pmrebs  : %x\n", pmrebs);
-                       printf("pmrswtp : %x\n", pmrswtp);
-                       printf("pmrmsc  : %"PRIx64"\n", pmrmsc);
+
+               namespaces = json_create_array();
+               for (k = 0; k < s->nr_namespaces; k++) {
+                       struct json_object *ns_attrs = json_create_object();
+                       struct nvme_namespace *n = &s->namespaces[k];
+
+                       json_detail_ns(n, ns_attrs);
+                       json_array_add_value_object(namespaces, ns_attrs);
                }
+               if (k)
+                       json_object_add_value_array(subsys_attrs, "Namespaces", namespaces);
+               else
+                       json_free_array(namespaces);
+
+               json_array_add_value_object(devices, subsys_attrs);
        }
+
+       json_object_add_value_array(root, "Devices", devices);
+       json_print_object(root, NULL);
+       printf("\n");
+       json_free_object(root);
 }
 
-void show_single_property(int offset, uint64_t value64, int human)
+static void json_simple_ns(struct nvme_namespace *n, struct json_array *devices)
 {
-       uint32_t value32;
-
-       if (!human) {
-               if (is_64bit_reg(offset))
-                       printf("property: 0x%02x (%s), value: %"PRIx64"\n", offset,
-                                  nvme_register_to_string(offset), value64);
-               else
-                       printf("property: 0x%02x (%s), value: %x\n", offset,
-                                  nvme_register_to_string(offset),
-                                  (uint32_t) value64);
+       struct json_object *device_attrs;
+       char formatter[41] = { 0 };
+       double nsze, nuse;
+       int index = -1;
+       long long lba;
+       char *devnode;
 
+       if (asprintf(&devnode, "/dev/%s", n->name) < 0)
                return;
-       }
 
-       value32 = (uint32_t) value64;
+       device_attrs = json_create_object();
+       json_object_add_value_int(device_attrs, "NameSpace", n->nsid);
 
-       switch (offset) {
-       case NVME_REG_CAP:
-               printf("cap : %"PRIx64"\n", value64);
-               show_registers_cap((struct nvme_bar_cap *)&value64);
-               break;
+       json_object_add_value_string(device_attrs, "DevicePath", devnode);
+       free(devnode);
 
-       case NVME_REG_VS:
-               printf("version : %x\n", value32);
-               show_registers_version(value32);
-               break;
+       format(formatter, sizeof(formatter),
+                          n->ctrl->id.fr,
+                          sizeof(n->ctrl->id.fr));
 
-       case NVME_REG_CC:
-               printf("cc : %x\n", value32);
-               show_registers_cc(value32);
-               break;
+       json_object_add_value_string(device_attrs, "Firmware", formatter);
 
-       case NVME_REG_CSTS:
-               printf("csts : %x\n", value32);
-               show_registers_csts(value32);
-               break;
+       if (sscanf(n->ctrl->name, "nvme%d", &index) == 1)
+               json_object_add_value_int(device_attrs, "Index", index);
 
-       case NVME_REG_NSSR:
-               printf("nssr : %x\n", value32);
-               printf("\tNVM Subsystem Reset Control (NSSRC): %u\n\n", value32);
-               break;
+       format(formatter, sizeof(formatter),
+                      n->ctrl->id.mn,
+                      sizeof(n->ctrl->id.mn));
 
-       default:
-               printf("unknown property: 0x%02x (%s), value: %"PRIx64"\n", offset,
-                          nvme_register_to_string(offset), value64);
-               break;
-       }
-}
+       json_object_add_value_string(device_attrs, "ModelNumber", formatter);
 
-void show_relatives(const char *name)
-{
-       unsigned id, i, nsid = NVME_NSID_ALL;
-       char *path = NULL;
-       bool block = true;
-       int ret;
+       if (index >= 0) {
+               char *product = nvme_product_name(index);
 
-       ret = sscanf(name, "nvme%dn%d", &id, &nsid);
-       switch (ret) {
-       case 1:
-               if (asprintf(&path, "/sys/class/nvme/%s", name) < 0)
-                       path = NULL;
-               block = false;
-               break;
-       case 2:
-               if (asprintf(&path, "/sys/block/%s/device", name) < 0)
-                       path = NULL;
-               break;
-       default:
-               return;
+               json_object_add_value_string(device_attrs, "ProductName", product);
+               free((void*)product);
        }
-       if (!path)
-               return;
 
-       if (block) {
-               char *subsysnqn;
-               struct subsys_list_item *slist;
-               int subcnt = 0;
+       format(formatter, sizeof(formatter),
+              n->ctrl->id.sn,
+              sizeof(n->ctrl->id.sn));
 
-               subsysnqn = get_nvme_subsnqn(path);
-               if (!subsysnqn)
-                       return;
-               slist = get_subsys_list(&subcnt, subsysnqn, nsid);
-               if (subcnt != 1) {
-                       free(subsysnqn);
-                       free(path);
-                       return;
-               }
+       json_object_add_value_string(device_attrs, "SerialNumber", formatter);
 
-               fprintf(stderr, "Namespace %s has parent controller(s):", name);
-               for (i = 0; i < slist[0].nctrls; i++)
-                       fprintf(stderr, "%s%s", i ? ", " : "", slist[0].ctrls[i].name);
-               fprintf(stderr, "\n\n");
-               free(subsysnqn);
-       } else {
-               struct dirent **paths;
-               bool comma = false;
-               int n, ns, cntlid;
+       lba = 1 << n->ns.lbaf[(n->ns.flbas & 0x0f)].ds;
+       nsze = le64_to_cpu(n->ns.nsze) * lba;
+       nuse = le64_to_cpu(n->ns.nuse) * lba;
 
-               n = scandir(path, &paths, scan_ctrl_paths_filter, alphasort);
-               if (n < 0) {
-                       free(path);
-                       return;
-               }
+       json_object_add_value_uint(device_attrs, "UsedBytes", nuse);
+       json_object_add_value_uint(device_attrs, "MaximumLBA",
+                                 le64_to_cpu(n->ns.nsze));
+       json_object_add_value_uint(device_attrs, "PhysicalSize", nsze);
+       json_object_add_value_uint(device_attrs, "SectorSize", lba);
 
-               fprintf(stderr, "Controller %s has child namespace(s):", name);
-               for (i = 0; i < n; i++) {
-                       if (sscanf(paths[i]->d_name, "nvme%dc%dn%d",
-                                  &id, &cntlid, &ns) != 3) {
-                               if (sscanf(paths[i]->d_name, "nvme%dn%d",
-                                          &id, &ns) != 2) {
-                                       continue;
-                               }
+       json_array_add_value_object(devices, device_attrs);
+}
+
+static void json_simple_list(struct nvme_topology *t)
+{
+       struct json_object *root;
+       struct json_array *devices;
+       int i, j, k;
+
+       root = json_create_object();
+       devices = json_create_array();
+       for (i = 0; i < t->nr_subsystems; i++) {
+               struct nvme_subsystem *s = &t->subsystems[i];
+
+               for (j = 0; j < s->nr_ctrls; j++) {
+                       struct nvme_ctrl *c = &s->ctrls[j];
+
+                       for (k = 0; k < c->nr_namespaces; k++) {
+                               struct nvme_namespace *n = &c->namespaces[k];
+                               json_simple_ns(n, devices);
                        }
-                       fprintf(stderr, "%snvme%dn%d", comma ? ", " : "", id, ns);
-                       comma = true;
                }
-               fprintf(stderr, "\n\n");
-               free(paths);
+
+               for (j = 0; j < s->nr_namespaces; j++) {
+                       struct nvme_namespace *n = &s->namespaces[j];
+                       json_simple_ns(n, devices);
+               }
        }
-       free(path);
+       json_object_add_value_array(root, "Devices", devices);
+       json_print_object(root, NULL);
+}
+
+static void json_print_list_items(struct nvme_topology *t, enum nvme_print_flags flags)
+{
+       if (flags & VERBOSE)
+               json_detail_list(t);
+       else
+               json_simple_list(t);
+}
+
+void nvme_show_list_items(struct nvme_topology *t, enum nvme_print_flags flags)
+{
+       if (flags & JSON)
+               json_print_list_items(t, flags);
+       else if (flags & VERBOSE)
+               nvme_show_detailed_list(t);
+       else
+               nvme_show_simple_list(t);
 }
index dea891563320ed990e2d5e46c5099627a55bf9be..6b78078bf2ed2898da84acdb7f1e1f13186e1ca8 100644 (file)
@@ -5,74 +5,62 @@
 #include "util/json.h"
 #include <inttypes.h>
 
-enum {
-       TERSE = 0x1u,   /* only show a few useful fields */
-       HUMAN = 0x2u,   /* interpret some values for humans */
-       VS    = 0x4u,   /* print vendor specific data area */
-       RAW   = 0x8u,   /* just dump raw bytes */
-};
-
 void d(unsigned char *buf, int len, int width, int group);
 void d_raw(unsigned char *buf, unsigned len);
-void show_nvme_status(__u16 status);
-
 uint64_t int48_to_long(__u8 *data);
 
-void __show_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*vendor_show)(__u8 *vs, struct json_object *root));
-void show_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode);
-void show_nvme_id_ns(struct nvme_id_ns *ns, unsigned int flags);
-void show_nvme_resv_report(struct nvme_reservation_status *status, int bytes, __u32 cdw11);
-void show_lba_range(struct nvme_lba_range_type *lbrt, int nr_ranges);
-void show_error_log(struct nvme_error_log_page *err_log, int entries, const char *devname);
-void show_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname);
-void show_ana_log(struct nvme_ana_rsp_hdr *ana_log, const char *devname);
-void show_self_test_log(struct nvme_self_test_log *self_test, const char *devname);
-void show_fw_log(struct nvme_firmware_log_page *fw_log, const char *devname);
-void show_effects_log(struct nvme_effects_log_page *effects, unsigned int flags);
-void show_changed_ns_list_log(struct nvme_changed_ns_list_log *log, const char *devname);
-void show_endurance_log(struct nvme_endurance_group_log *endurance_group,
-                       __u16 group_id, const char *devname);
-void show_sanitize_log(struct nvme_sanitize_log_page *sanitize, unsigned int mode, const char *devname);
-void show_ctrl_registers(void *bar, unsigned int mode, bool fabrics);
-void show_single_property(int offset, uint64_t prop, int human);
-void show_nvme_id_ns_descs(void *data);
-void show_lba_status(struct nvme_lba_status *list);
-void show_list_items(struct nvme_topology *t, unsigned verbose);
-void show_nvme_subsystem_list(struct subsys_list_item *slist, int n);
-void show_nvme_id_nvmset(struct nvme_id_nvmset *nvmset);
-void show_nvme_list_secondary_ctrl(const struct nvme_secondary_controllers_list *sc_list, __u32 count);
-void show_nvme_id_ns_granularity_list(const struct nvme_id_ns_granularity_list *granularity, unsigned int flags);
-void show_nvme_id_uuid_list(const struct nvme_id_uuid_list *uuid_list, unsigned int flags);
+void nvme_show_status(__u16 status);
+void nvme_show_relatives(const char *name);
+
+void __nvme_show_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode,
+       void (*vendor_show)(__u8 *vs, struct json_object *root));
+void nvme_show_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode);
+void nvme_show_id_ns(struct nvme_id_ns *ns, unsigned int nsid,
+       enum nvme_print_flags flags);
+void nvme_show_resv_report(struct nvme_reservation_status *status, int bytes, __u32 cdw11,
+       enum nvme_print_flags flags);
+void nvme_show_lba_range(struct nvme_lba_range_type *lbrt, int nr_ranges);
+void nvme_show_error_log(struct nvme_error_log_page *err_log, int entries,
+       const char *devname, enum nvme_print_flags flags);
+void nvme_show_smart_log(struct nvme_smart_log *smart, unsigned int nsid,
+       const char *devname, enum nvme_print_flags flags);
+void nvme_show_ana_log(struct nvme_ana_rsp_hdr *ana_log, const char *devname,
+       enum nvme_print_flags flags, size_t len);
+void nvme_show_self_test_log(struct nvme_self_test_log *self_test, const char *devname,
+       enum nvme_print_flags flags);
+void nvme_show_fw_log(struct nvme_firmware_log_page *fw_log, const char *devname,
+       enum nvme_print_flags flags);
+void nvme_show_effects_log(struct nvme_effects_log_page *effects, unsigned int flags);
+void nvme_show_changed_ns_list_log(struct nvme_changed_ns_list_log *log,
+       const char *devname, enum nvme_print_flags flags);
+void nvme_show_endurance_log(struct nvme_endurance_group_log *endurance_log,
+       __u16 group_id, const char *devname, enum nvme_print_flags flags);
+void nvme_show_sanitize_log(struct nvme_sanitize_log_page *sanitize,
+       const char *devname, enum nvme_print_flags flags);
+void nvme_show_ctrl_registers(void *bar, bool fabrics, enum nvme_print_flags flags);
+void nvme_show_single_property(int offset, uint64_t prop, int human);
+void nvme_show_id_ns_descs(void *data, unsigned nsid, enum nvme_print_flags flags);
+void nvme_show_lba_status(struct nvme_lba_status *list, unsigned long len,
+       enum nvme_print_flags flags);
+void nvme_show_list_items(struct nvme_topology *t, enum nvme_print_flags flags);
+void nvme_show_subsystem_list(struct subsys_list_item *slist, int n,
+       enum nvme_print_flags flags);
+void nvme_show_id_nvmset(struct nvme_id_nvmset *nvmset, unsigned nvmset_id,
+       enum nvme_print_flags flags);
+void nvme_show_list_secondary_ctrl(const struct nvme_secondary_controllers_list *sc_list,
+       __u32 count, enum nvme_print_flags flags);
+void nvme_show_id_ns_granularity_list(const struct nvme_id_ns_granularity_list *glist,
+       enum nvme_print_flags flags);
+void nvme_show_id_uuid_list(const struct nvme_id_uuid_list *uuid_list,
+       enum nvme_print_flags flags);
 
 void nvme_feature_show_fields(__u32 fid, unsigned int result, unsigned char *buf);
 void nvme_directive_show_fields(__u8 dtype, __u8 doper, unsigned int result, unsigned char *buf);
+void nvme_show_select_result(__u32 result);
+
 const char *nvme_status_to_string(__u32 status);
 const char *nvme_select_to_string(int sel);
 const char *nvme_feature_to_string(int feature);
 const char *nvme_register_to_string(int reg);
-void nvme_show_select_result(__u32 result);
-void show_relatives(const char *name);
-
-void json_nvme_id_ctrl(struct nvme_id_ctrl *ctrl, unsigned int mode, void (*vendor_show)(__u8 *vs, struct json_object *root));
-void json_nvme_id_ns(struct nvme_id_ns *ns, unsigned int flags);
-void json_nvme_resv_report(struct nvme_reservation_status *status, int bytes, __u32 cdw11);
-void json_error_log(struct nvme_error_log_page *err_log, int entries, const char *devname);
-void json_smart_log(struct nvme_smart_log *smart, unsigned int nsid, const char *devname);
-void json_ana_log(struct nvme_ana_rsp_hdr *ana_log, const char *devname);
-void json_effects_log(struct nvme_effects_log_page *effects_log, const char *devname);
-void json_sanitize_log(struct nvme_sanitize_log_page *sanitize_log, const char *devname);
-void json_fw_log(struct nvme_firmware_log_page *fw_log, const char *devname);
-void json_changed_ns_list_log(struct nvme_changed_ns_list_log *log, const char *devname);
-void json_endurance_log(struct nvme_endurance_group_log *endurance_group,
-                       __u16 group_id, const char *devname);
-void json_print_list_items(struct nvme_topology *t, unsigned verbose);
-void json_nvme_id_ns_descs(void *data);
-void json_print_nvme_subsystem_list(struct subsys_list_item *slist, int n);
-void json_self_test_log(struct nvme_self_test_log *self_test, const char *devname);
-void json_nvme_id_nvmset(struct nvme_id_nvmset *nvmset, const char *devname);
-void json_ctrl_registers(void *bar);
-void json_nvme_list_secondary_ctrl(const struct nvme_secondary_controllers_list *sc_list, __u32 count);
-void json_nvme_id_ns_granularity_list(const struct nvme_id_ns_granularity_list *granularity, unsigned int flags);
-void json_nvme_id_uuid_list(struct nvme_id_uuid_list *uuid_list);
 
 #endif
index 13ab52c43cfb9cb0ab98fef17470e34a9343cb44..058e1855c57be40b312d4c4b6ce1386f1d6194aa 100644 (file)
@@ -155,6 +155,7 @@ static int scan_ctrl(struct nvme_ctrl *c, char *p)
                fprintf(stderr, "Failed to open %s: %s\n", path, strerror(errno));
                return errno;
        }
+
        c->nr_namespaces = ret;
        c->namespaces = calloc(c->nr_namespaces, sizeof(*n));
        for (i = 0; i < c->nr_namespaces; i++) {
@@ -174,8 +175,10 @@ static int scan_ctrl(struct nvme_ctrl *c, char *p)
                return ret;
 
        fd = open(path, O_RDONLY);
-       if (fd < 0)
+       if (fd < 0) {
+               fprintf(stderr, "Failed to open %s\n", path);
                goto free;
+       }
 
        ret = nvme_identify_ctrl(fd, &c->id);
        if (ret < 0)
@@ -223,6 +226,7 @@ static int scan_subsystem(struct nvme_subsystem *s)
                fprintf(stderr, "Failed to open %s: %s\n", path, strerror(errno));
                return errno;
        }
+
        s->nr_namespaces = ret;
        s->namespaces = calloc(s->nr_namespaces, sizeof(*n));
        for (i = 0; i < s->nr_namespaces; i++) {
@@ -231,6 +235,7 @@ static int scan_subsystem(struct nvme_subsystem *s)
                n->ctrl = &s->ctrls[0];
                scan_namespace(n);
        }
+
        while (i--)
                free(ns[i]);
        free(ns);
diff --git a/nvme.c b/nvme.c
index 4aff6d352c14486f42656b9702230d822de4257b..997251bbc53b9c682ff02899216f74cdda637eb3 100644 (file)
--- a/nvme.c
+++ b/nvme.c
@@ -206,7 +206,7 @@ int parse_and_open(int argc, char **argv, const char *desc,
        return ret;
 }
 
-int validate_output_format(char *format)
+enum nvme_print_flags validate_output_format(char *format)
 {
        if (!format)
                return -EINVAL;
@@ -227,7 +227,8 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug
                        "(default) or binary.";
        const char *namespace = "(optional) desired namespace";
        const char *raw = "output in binary format";
-       int err, fmt, fd;
+       enum nvme_print_flags flags;
+       int err, fd;
 
        struct config {
                __u32 namespace_id;
@@ -252,27 +253,20 @@ static int get_smart_log(int argc, char **argv, struct command *cmd, struct plug
        if (fd < 0)
                goto ret;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               err = fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
        if (cfg.raw_binary)
-               fmt = BINARY;
+               flags = BINARY;
 
        err = nvme_smart_log(fd, cfg.namespace_id, &smart_log);
-       if (!err) {
-               if (fmt == BINARY)
-                       d_raw((unsigned char *)&smart_log, sizeof(smart_log));
-               else if (fmt == JSON)
-                       json_smart_log(&smart_log, cfg.namespace_id, devicename);
-               else
-                       show_smart_log(&smart_log, cfg.namespace_id, devicename);
-       } else if (err > 0)
-               show_nvme_status(err);
+       if (!err)
+               nvme_show_smart_log(&smart_log, cfg.namespace_id, devicename,
+                                   flags);
+       else if (err > 0)
+               nvme_show_status(err);
        else
                perror("smart log");
-
 close_fd:
        close(fd);
 ret:
@@ -282,14 +276,14 @@ ret:
 static int get_ana_log(int argc, char **argv, struct command *cmd,
                struct plugin *plugin)
 {
-       const char *desc = "Retrieve ANA log for the given device" \
-                           "in either decoded format "\
-                           "(default) or binary.";
+       const char *desc = "Retrieve ANA log for the given device in " \
+                           "decoded format (default), json or binary.";
        void *ana_log;
-       int err, fmt, fd;
+       int err, fd;
        int groups = 0; /* Right now get all the per ANA group NSIDS */
        size_t ana_log_len;
        struct nvme_id_ctrl ctrl;
+       enum nvme_print_flags flags;
 
        struct config {
                char *output_format;
@@ -308,19 +302,17 @@ static int get_ana_log(int argc, char **argv, struct command *cmd,
        if (fd < 0)
                goto ret;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               err = fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
 
-       memset(&ctrl, 0, sizeof (struct nvme_id_ctrl));
        err = nvme_identify_ctrl(fd, &ctrl);
        if (err) {
                fprintf(stderr, "ERROR : nvme_identify_ctrl() failed 0x%x\n",
                                err);
                goto close_fd;
        }
+
        ana_log_len = sizeof(struct nvme_ana_rsp_hdr) +
                le32_to_cpu(ctrl.nanagrpid) * sizeof(struct nvme_ana_group_desc);
        if (!(ctrl.anacap & (1 << 6)))
@@ -328,21 +320,16 @@ static int get_ana_log(int argc, char **argv, struct command *cmd,
 
        ana_log = malloc(ana_log_len);
        if (!ana_log) {
-               perror("malloc : ");
+               perror("malloc");
                err = -ENOMEM;
                goto close_fd;
        }
 
        err = nvme_ana_log(fd, ana_log, ana_log_len, groups ? NVME_ANA_LOG_RGO : 0);
        if (!err) {
-               if (fmt == BINARY)
-                       d_raw((unsigned char *)ana_log, ana_log_len);
-               else if (fmt == JSON)
-                       json_ana_log(ana_log, devicename);
-               else
-                       show_ana_log(ana_log, devicename);
+               nvme_show_ana_log(ana_log, devicename, flags, ana_log_len);
        } else if (err > 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                perror("ana-log");
        free(ana_log);
@@ -419,7 +406,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *cmd, struct
        if (err < 0)
                perror("get-telemetry-log");
        else if (err > 0) {
-               show_nvme_status(err);
+               nvme_show_status(err);
                fprintf(stderr, "Failed to acquire telemetry header %d!\n", err);
                goto close_output;
        }
@@ -457,7 +444,7 @@ static int get_telemetry_log(int argc, char **argv, struct command *cmd, struct
                        break;
                } else if (err > 0) {
                        fprintf(stderr, "Failed to acquire full telemetry log!\n");
-                       show_nvme_status(err);
+                       nvme_show_status(err);
                        break;
                }
 
@@ -483,12 +470,10 @@ ret:
 static int get_endurance_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
 {
        struct nvme_endurance_group_log endurance_log;
-
        const char *desc = "Retrieves endurance groups log page and prints the log.";
        const char *group_id = "The endurance group identifier";
-
+       enum nvme_print_flags flags;
        int err, fd;
-       int fmt;
 
        struct config {
                char *output_format;
@@ -510,25 +495,17 @@ static int get_endurance_log(int argc, char **argv, struct command *cmd, struct
        if (fd < 0)
                goto ret;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               err = fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
 
        err = nvme_endurance_log(fd, cfg.group_id, &endurance_log);
-       if (!err) {
-               if (fmt == BINARY)
-                       d_raw((unsigned char *)&endurance_log, sizeof(endurance_log));
-               else if (fmt == JSON)
-                       json_endurance_log(&endurance_log, cfg.group_id, devicename);
-               else
-                       show_endurance_log(&endurance_log, cfg.group_id, devicename);
-       } else if (err > 0)
-               show_nvme_status(err);
+       if (!err)
+               nvme_show_endurance_log(&endurance_log, cfg.group_id, devicename, flags);
+       else if (err > 0)
+               nvme_show_status(err);
        else
                perror("endurance log");
-
 close_fd:
        close(fd);
 ret:
@@ -543,8 +520,7 @@ static int get_effects_log(int argc, char **argv, struct command *cmd, struct pl
        struct nvme_effects_log_page effects;
 
        int err, fd;
-       int fmt;
-       unsigned int flags = 0;
+       enum nvme_print_flags flags;
 
        struct config {
                int   raw_binary;
@@ -567,31 +543,21 @@ static int get_effects_log(int argc, char **argv, struct command *cmd, struct pl
        if (fd < 0)
                goto ret;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               err = fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
        if (cfg.raw_binary)
-               fmt = BINARY;
-
+               flags = BINARY;
        if (cfg.human_readable)
-               flags |= HUMAN;
+               flags |= VERBOSE;
 
        err = nvme_effects_log(fd, &effects);
-       if (!err) {
-               if (fmt == BINARY)
-                       d_raw((unsigned char *)&effects, sizeof(effects));
-               else if (fmt == JSON)
-                       json_effects_log(&effects, devicename);
-               else
-                       show_effects_log(&effects, flags);
-       }
+       if (!err)
+               nvme_show_effects_log(&effects, flags);
        else if (err > 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                perror("effects log page");
-
 close_fd:
        close(fd);
 ret:
@@ -605,8 +571,10 @@ static int get_error_log(int argc, char **argv, struct command *cmd, struct plug
                "in either decoded format (default) or binary.";
        const char *log_entries = "number of entries to retrieve";
        const char *raw = "dump in binary format";
+       struct nvme_error_log_page *err_log;
        struct nvme_id_ctrl ctrl;
-       int err, fmt, fd;
+       enum nvme_print_flags flags;
+       int err, fd;
 
        struct config {
                __u32 log_entries;
@@ -630,13 +598,11 @@ static int get_error_log(int argc, char **argv, struct command *cmd, struct plug
        if (fd < 0)
                goto ret;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               err = fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
        if (cfg.raw_binary)
-               fmt = BINARY;
+               flags = BINARY;
 
        if (!cfg.log_entries) {
                fprintf(stderr, "non-zero log-entries is required param\n");
@@ -645,38 +611,31 @@ static int get_error_log(int argc, char **argv, struct command *cmd, struct plug
        }
 
        err = nvme_identify_ctrl(fd, &ctrl);
-       if (err < 0)
+       if (err < 0) {
                perror("identify controller");
-       else if (err) {
+               goto close_fd;
+       } else if (err) {
                fprintf(stderr, "could not identify controller\n");
                err = -ENODEV;
-       } else {
-               struct nvme_error_log_page *err_log;
-
-               cfg.log_entries = min(cfg.log_entries, ctrl.elpe + 1);
-               err_log = calloc(cfg.log_entries, sizeof(struct nvme_error_log_page));
-               if (!err_log) {
-                       fprintf(stderr, "could not alloc buffer for error log\n");
-                       err = -ENOMEM;
-                       goto close_fd;
-               }
+               goto close_fd;
+       }
 
-               err = nvme_error_log(fd, cfg.log_entries, err_log);
-               if (!err) {
-                       if (fmt == BINARY)
-                               d_raw((unsigned char *)err_log, cfg.log_entries * sizeof(*err_log));
-                       else if (fmt == JSON)
-                               json_error_log(err_log, cfg.log_entries, devicename);
-                       else
-                               show_error_log(err_log, cfg.log_entries, devicename);
-               }
-               else if (err > 0)
-                       show_nvme_status(err);
-               else
-                       perror("error log");
-               free(err_log);
+       cfg.log_entries = min(cfg.log_entries, ctrl.elpe + 1);
+       err_log = calloc(cfg.log_entries, sizeof(struct nvme_error_log_page));
+       if (!err_log) {
+               fprintf(stderr, "could not alloc buffer for error log\n");
+               err = -ENOMEM;
+               goto close_fd;
        }
 
+       err = nvme_error_log(fd, cfg.log_entries, err_log);
+       if (!err)
+               nvme_show_error_log(err_log, cfg.log_entries, devicename, flags);
+       else if (err > 0)
+               nvme_show_status(err);
+       else
+               perror("error log");
+       free(err_log);
 close_fd:
        close(fd);
 ret:
@@ -688,8 +647,9 @@ static int get_fw_log(int argc, char **argv, struct command *cmd, struct plugin
        const char *desc = "Retrieve the firmware log for the "\
                "specified device in either decoded format (default) or binary.";
        const char *raw = "use binary output";
-       int err, fmt, fd;
        struct nvme_firmware_log_page fw_log;
+       enum nvme_print_flags flags;
+       int err, fd;
 
        struct config {
                int raw_binary;
@@ -710,28 +670,19 @@ static int get_fw_log(int argc, char **argv, struct command *cmd, struct plugin
        if (fd < 0)
                goto ret;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               err = fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
        if (cfg.raw_binary)
-               fmt = BINARY;
+               flags = BINARY;
 
        err = nvme_fw_log(fd, &fw_log);
-       if (!err) {
-               if (fmt == BINARY)
-                       d_raw((unsigned char *)&fw_log, sizeof(fw_log));
-               else if (fmt == JSON)
-                       json_fw_log(&fw_log, devicename);
-               else
-                       show_fw_log(&fw_log, devicename);
-       }
+       if (!err)
+               nvme_show_fw_log(&fw_log, devicename, flags);
        else if (err > 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                perror("fw log");
-
 close_fd:
        close(fd);
 ret:
@@ -745,7 +696,8 @@ static int get_changed_ns_list_log(int argc, char **argv, struct command *cmd, s
                        "in either decoded format "\
                        "(default) or binary.";
        const char *raw = "output in binary format";
-       int err, fmt, fd;
+       enum nvme_print_flags flags;
+       int err, fd;
 
        struct config {
                int   raw_binary;
@@ -766,28 +718,20 @@ static int get_changed_ns_list_log(int argc, char **argv, struct command *cmd, s
        if (fd < 0)
                goto ret;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               err = fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
-
        if (cfg.raw_binary)
-               fmt = BINARY;
+               flags = BINARY;
 
        err = nvme_changed_ns_list_log(fd, &changed_ns_list_log);
-       if (!err) {
-               if (fmt == BINARY)
-                       d_raw((unsigned char *)changed_ns_list_log.log, sizeof(changed_ns_list_log.log));
-               else if (fmt == JSON)
-                       json_changed_ns_list_log(&changed_ns_list_log, devicename);
-               else
-                       show_changed_ns_list_log(&changed_ns_list_log, devicename);
-       } else if (err > 0)
-               show_nvme_status(err);
+       if (!err)
+               nvme_show_changed_ns_list_log(&changed_ns_list_log, devicename,
+                                             flags);
+       else if (err > 0)
+               nvme_show_status(err);
        else
                perror("changed ns list log");
-
 close_fd:
        close(fd);
 ret:
@@ -886,12 +830,11 @@ static int get_log(int argc, char **argv, struct command *cmd, struct plugin *pl
                        } else
                                d_raw((unsigned char *)log, cfg.log_len);
                } else if (err > 0)
-                       show_nvme_status(err);
+                       nvme_show_status(err);
                else
                        perror("log page");
                free(log);
        }
-
 close_fd:
        close(fd);
 ret:
@@ -903,9 +846,9 @@ static int sanitize_log(int argc, char **argv, struct command *command, struct p
        const char *desc = "Retrieve sanitize log and show it.";
        const char *raw = "show log in binary format";
        const char *human_readable = "show log in readable format";
-       int fd, ret, fmt;
-       unsigned int flags = 0;
        struct nvme_sanitize_log_page sanitize_log;
+       enum nvme_print_flags flags;
+       int fd, err;
 
        struct config {
                int   raw_binary;
@@ -924,39 +867,29 @@ static int sanitize_log(int argc, char **argv, struct command *command, struct p
                OPT_END()
        };
 
-       ret = fd = parse_and_open(argc, argv, desc, opts);
+       err = fd = parse_and_open(argc, argv, desc, opts);
        if (fd < 0)
                goto ret;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               ret = fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
        if (cfg.raw_binary)
-               fmt = BINARY;
-
+               flags = BINARY;
        if (cfg.human_readable)
-               flags |= HUMAN;
-
-       ret = nvme_sanitize_log(fd, &sanitize_log);
-       if (!ret) {
-               if (fmt == BINARY)
-                       d_raw((unsigned char *)&sanitize_log, sizeof(sanitize_log));
-               else if (fmt == JSON)
-                       json_sanitize_log(&sanitize_log, devicename);
-               else
-                       show_sanitize_log(&sanitize_log, flags, devicename);
-       }
-       else if (ret > 0)
-               show_nvme_status(ret);
+               flags |= VERBOSE;
+
+       err = nvme_sanitize_log(fd, &sanitize_log);
+       if (!err)
+               nvme_show_sanitize_log(&sanitize_log, devicename, flags);
+       else if (err > 0)
+               nvme_show_status(err);
        else
                perror("sanitize status log");
-
 close_fd:
        close(fd);
 ret:
-       return nvme_status_to_errno(ret, false);
+       return nvme_status_to_errno(err, false);
 }
 
 static int list_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin)
@@ -1001,12 +934,11 @@ static int list_ctrl(int argc, char **argv, struct command *cmd, struct plugin *
                        printf("[%4u]:%#x\n", i, le16_to_cpu(cntlist->identifier[i]));
        }
        else if (err > 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                perror("id controller list");
 
        free(cntlist);
-
 close_fd:
        close(fd);
 ret:
@@ -1053,12 +985,10 @@ static int list_ns(int argc, char **argv, struct command *cmd, struct plugin *pl
                for (i = 0; i < 1024; i++)
                        if (ns_list[i])
                                printf("[%4u]:%#x\n", i, le32_to_cpu(ns_list[i]));
-       } else if (err > 0) {
-               show_nvme_status(err);
-       } else {
+       } else if (err > 0)
+               nvme_show_status(err);
+       else
                perror("id namespace list");
-       }
-
 close_fd:
        close(fd);
 ret:
@@ -1115,7 +1045,7 @@ static int delete_ns(int argc, char **argv, struct command *cmd, struct plugin *
                printf("%s: Success, deleted nsid:%d\n", cmd->name,
                                                                cfg.namespace_id);
        else if (err > 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                perror("delete namespace");
 
@@ -1179,7 +1109,7 @@ static int nvme_attach_ns(int argc, char **argv, int attach, const char *desc, s
        if (!err)
                printf("%s: Success, nsid:%d\n", cmd->name, cfg.namespace_id);
        else if (err > 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                perror(attach ? "attach namespace" : "detach namespace");
 
@@ -1278,7 +1208,7 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
                                perror("identify-namespace");
                        else {
                                fprintf(stderr, "identify failed\n");
-                               show_nvme_status(err);
+                               nvme_show_status(err);
                        }
                        goto close_fd;
                }
@@ -1307,7 +1237,7 @@ static int create_ns(int argc, char **argv, struct command *cmd, struct plugin *
        if (!err)
                printf("%s: Success, created nsid:%d\n", cmd->name, nsid);
        else if (err > 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                perror("create namespace");
 
@@ -1321,10 +1251,12 @@ static int list_subsys(int argc, char **argv, struct command *cmd,
                struct plugin *plugin)
 {
        struct subsys_list_item *slist;
-       int fmt, ret, subcnt = 0;
+       enum nvme_print_flags flags;
+       int err, subcnt = 0;
        char *subsysnqn = NULL;
        const char *desc = "Retrieve information for subsystems";
        __u32 namespace_id;
+
        struct config {
                char *output_format;
        };
@@ -1338,8 +1270,8 @@ static int list_subsys(int argc, char **argv, struct command *cmd,
                OPT_END()
        };
 
-       ret = argconfig_parse(argc, argv, desc, opts);
-       if (ret < 0)
+       err = argconfig_parse(argc, argv, desc, opts);
+       if (err < 0)
                goto ret;
 
        devicename = NULL;
@@ -1348,11 +1280,10 @@ static int list_subsys(int argc, char **argv, struct command *cmd,
                int id;
 
                devicename = basename(argv[optind]);
-               if (sscanf(devicename, "nvme%dn%d", &id,
-                          &namespace_id) != 2) {
+               if (sscanf(devicename, "nvme%dn%d", &id, &namespace_id) != 2) {
                        fprintf(stderr, "%s is not a NVMe namespace device\n",
                                argv[optind]);
-                       ret = -EINVAL;
+                       err = -EINVAL;
                        goto ret;
                }
                sprintf(path, "/sys/block/%s/device", devicename);
@@ -1360,37 +1291,28 @@ static int list_subsys(int argc, char **argv, struct command *cmd,
                if (!subsysnqn) {
                        fprintf(stderr, "Cannot read subsys NQN from %s\n",
                                devicename);
-                       ret = -EINVAL;
+                       err = -EINVAL;
                        goto ret;
                }
                optind++;
        }
 
-       if (ret < 0) {
-               argconfig_print_help(desc, opts);
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto free;
-       }
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt != JSON && fmt != NORMAL) {
-               if (subsysnqn)
-                       free(subsysnqn);
-               ret = -EINVAL;
+       if (flags != JSON && flags != NORMAL) {
+               err = -EINVAL;
                goto free;
        }
 
        slist = get_subsys_list(&subcnt, subsysnqn, namespace_id);
-       if (fmt == JSON)
-               json_print_nvme_subsystem_list(slist, subcnt);
-       else
-               show_nvme_subsystem_list(slist, subcnt);
-
+       nvme_show_subsystem_list(slist, subcnt, flags);
        free_subsys_list(slist, subcnt);
 free:
        if (subsysnqn)
                free(subsysnqn);
-
 ret:
-       return nvme_status_to_errno(ret, false);
+       return nvme_status_to_errno(err, false);
 }
 
 static int list(int argc, char **argv, struct command *cmd, struct plugin *plugin)
@@ -1398,7 +1320,8 @@ static int list(int argc, char **argv, struct command *cmd, struct plugin *plugi
        const char *desc = "Retrieve basic information for all NVMe namespaces";
        const char *verbose = "Increase output verbosity";
        struct nvme_topology t;
-       int fmt, ret = 0;
+       enum nvme_print_flags flags;
+       int err = 0;
 
        struct config {
                char *output_format;
@@ -1416,27 +1339,27 @@ static int list(int argc, char **argv, struct command *cmd, struct plugin *plugi
                OPT_END()
        };
 
-       ret = argconfig_parse(argc, argv, desc, opts);
-       if (ret < 0)
-               return ret;
+       err = argconfig_parse(argc, argv, desc, opts);
+       if (err < 0)
+               return err;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt != JSON && fmt != NORMAL) {
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
+               return err;
+       if (flags != JSON && flags != NORMAL) {
                fprintf(stderr, "Invalid output format\n");
                return -EINVAL;
        }
+       if (cfg.verbose)
+               flags |= VERBOSE;
 
-       ret = scan_subsystems(&t);
-       if (ret) {
+       err = scan_subsystems(&t);
+       if (err) {
                fprintf(stderr, "Failed to scan namespaces\n");
-               return ret;
+               return err;
        }
 
-       if (fmt == JSON)
-               json_print_list_items(&t, cfg.verbose);
-       else
-               show_list_items(&t, cfg.verbose);
-
+       nvme_show_list_items(&t, flags);
        free_topology(&t);
        return 0;
 }
@@ -1516,7 +1439,8 @@ cleanup_devices:
        return devname;
 }
 
-int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin, void (*vs)(__u8 *vs, struct json_object *root))
+int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin,
+               void (*vs)(__u8 *vs, struct json_object *root))
 {
        const char *desc = "Send an Identify Controller command to "\
                "the given device and report information about the specified "\
@@ -1526,9 +1450,9 @@ int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin,
        const char *vendor_specific = "dump binary vendor field";
        const char *raw = "show identify in binary format";
        const char *human_readable = "show identify in readable format";
-       int err, fmt, fd;
-       unsigned int flags = 0;
+       enum nvme_print_flags flags;
        struct nvme_id_ctrl ctrl;
+       int err, fd;
 
        struct config {
                int vendor_specific;
@@ -1553,37 +1477,23 @@ int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin,
        if (fd < 0)
                goto ret;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               err = fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
-       if (cfg.raw_binary) {
-               fprintf(stderr, "binary output\n");
-               fmt = BINARY;
-       }
-
+       if (cfg.raw_binary)
+               flags = BINARY;
        if (cfg.vendor_specific)
                flags |= VS;
        if (cfg.human_readable)
-               flags |= HUMAN;
+               flags |= VERBOSE;
 
        err = nvme_identify_ctrl(fd, &ctrl);
-       if (!err) {
-               if (fmt == BINARY)
-                       d_raw((unsigned char *)&ctrl, sizeof(ctrl));
-               else if (fmt == JSON)
-                       json_nvme_id_ctrl(&ctrl, flags, vs);
-               else {
-                       printf("NVME Identify Controller:\n");
-                       __show_nvme_id_ctrl(&ctrl, flags, vs);
-               }
-       }
+       if (!err)
+               __nvme_show_id_ctrl(&ctrl, flags, vs);
        else if (err > 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                perror("identify controller");
-
 close_fd:
        close(fd);
 ret:
@@ -1602,8 +1512,10 @@ static int ns_descs(int argc, char **argv, struct command *cmd, struct plugin *p
                            "of the specific namespace in either human-readable or binary format.";
        const char *raw = "show descriptors in binary format";
        const char *namespace_id = "identifier of desired namespace";
-       int err, fmt, fd;
+       enum nvme_print_flags flags;
+       int err, fd;
        void *nsdescs;
+
        struct config {
                __u32 namespace_id;
                int raw_binary;
@@ -1626,13 +1538,12 @@ static int ns_descs(int argc, char **argv, struct command *cmd, struct plugin *p
        if (fd < 0)
                goto ret;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               err = fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
        if (cfg.raw_binary)
-               fmt = BINARY;
+               flags = BINARY;
+
        if (!cfg.namespace_id) {
                cfg.namespace_id = get_nsid(fd);
                if (cfg.namespace_id == 0) {
@@ -1648,23 +1559,13 @@ static int ns_descs(int argc, char **argv, struct command *cmd, struct plugin *p
        }
 
        err = nvme_identify_ns_descs(fd, cfg.namespace_id, nsdescs);
-       if (!err) {
-               if (fmt == BINARY)
-                       d_raw((unsigned char *)nsdescs, 0x1000);
-               else if (fmt == JSON)
-                       json_nvme_id_ns_descs(nsdescs);
-               else {
-                       printf("NVME Namespace Identification Descriptors NS %d:\n", cfg.namespace_id);
-                       show_nvme_id_ns_descs(nsdescs);
-               }
-       }
+       if (!err)
+               nvme_show_id_ns_descs(nsdescs, cfg.namespace_id, flags);
        else if (err > 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                perror("identify namespace");
-
        free(nsdescs);
-
 close_fd:
        close(fd);
 ret:
@@ -1682,9 +1583,10 @@ static int id_ns(int argc, char **argv, struct command *cmd, struct plugin *plug
        const char *raw = "show identify in binary format";
        const char *human_readable = "show identify in readable format";
        const char *namespace_id = "identifier of desired namespace";
+
+       enum nvme_print_flags flags;
        struct nvme_id_ns ns;
-       int err, fmt, fd;
-       unsigned int flags = 0;
+       int err, fd;
 
        struct config {
                __u32 namespace_id;
@@ -1714,44 +1616,36 @@ static int id_ns(int argc, char **argv, struct command *cmd, struct plugin *plug
        if (fd < 0)
                goto ret;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               err = fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
        if (cfg.raw_binary)
-               fmt = BINARY;
+               flags = BINARY;
        if (cfg.vendor_specific)
                flags |= VS;
        if (cfg.human_readable)
-               flags |= HUMAN;
+               flags |= VERBOSE;
+
        if (!cfg.namespace_id && S_ISBLK(nvme_stat.st_mode)) {
                cfg.namespace_id = get_nsid(fd);
                if (cfg.namespace_id == 0) {
                        err = -EINVAL;
                        goto close_fd;
                }
-       }
-       else if(!cfg.namespace_id)
+       } else if (!cfg.namespace_id) {
                fprintf(stderr,
                        "Error: requesting namespace-id from non-block device\n");
+               err = -ENOTBLK;
+               goto close_fd;
+       }
 
        err = nvme_identify_ns(fd, cfg.namespace_id, cfg.force, &ns);
-       if (!err) {
-               if (fmt == BINARY)
-                       d_raw((unsigned char *)&ns, sizeof(ns));
-               else if (fmt == JSON)
-                       json_nvme_id_ns(&ns, flags);
-               else {
-                       printf("NVME Identify Namespace %d:\n", cfg.namespace_id);
-                       show_nvme_id_ns(&ns, flags);
-               }
-       }
+       if (!err)
+               nvme_show_id_ns(&ns, cfg.namespace_id, flags);
        else if (err > 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                perror("identify namespace");
-
 close_fd:
        close(fd);
 ret:
@@ -1763,9 +1657,10 @@ static int id_ns_granularity(int argc, char **argv, struct command *cmd, struct
        const char *desc = "Send an Identify Namespace Granularity List command to the "\
                "given device, returns namespace granularity list "\
                "in either human-readable or binary format.";
-       int err, fmt, fd;
-       unsigned int flags = 0;
+
        struct nvme_id_ns_granularity_list *granularity_list;
+       enum nvme_print_flags flags;
+       int err, fd;
 
        struct config {
                char *output_format;
@@ -1784,11 +1679,9 @@ static int id_ns_granularity(int argc, char **argv, struct command *cmd, struct
        if (fd < 0)
                goto ret;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               err = fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
 
        if (posix_memalign((void *)&granularity_list, getpagesize(), NVME_IDENTIFY_DATA_SIZE)) {
                fprintf(stderr, "can not allocate granularity list payload\n");
@@ -1797,16 +1690,10 @@ static int id_ns_granularity(int argc, char **argv, struct command *cmd, struct
        }
 
        err = nvme_identify_ns_granularity(fd, granularity_list);
-       if (!err) {
-               if (fmt == BINARY)
-                       d_raw((unsigned char *)granularity_list, sizeof(*granularity_list));
-               else if (fmt == JSON)
-                       json_nvme_id_ns_granularity_list(granularity_list, flags);
-               else
-                       show_nvme_id_ns_granularity_list(granularity_list, flags);
-       }
+       if (!err)
+               nvme_show_id_ns_granularity_list(granularity_list, flags);
        else if (err > 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                perror("identify namespace granularity");
 
@@ -1823,8 +1710,10 @@ static int id_nvmset(int argc, char **argv, struct command *cmd, struct plugin *
                "than or equal to the value specified CDW11.NVMSETID "\
                "in either binary format or json format";
        const char *nvmset_id = "NVM Set Identify value";
-       int err, fmt, fd;
+
        struct nvme_id_nvmset nvmset;
+       enum nvme_print_flags flags;
+       int err, fd;
 
        struct config {
                __u16 nvmset_id;
@@ -1846,25 +1735,15 @@ static int id_nvmset(int argc, char **argv, struct command *cmd, struct plugin *
        if (fd < 0)
                goto ret;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               err = fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
 
        err = nvme_identify_nvmset(fd, cfg.nvmset_id, &nvmset);
-       if (!err) {
-               if (fmt == BINARY)
-                       d_raw((unsigned char *)&nvmset, sizeof(nvmset));
-               else if (fmt == JSON)
-                       json_nvme_id_nvmset(&nvmset, devicename);
-               else {
-                       printf("NVME Identify NVM Set List %d:\n", cfg.nvmset_id);
-                       show_nvme_id_nvmset(&nvmset);
-               }
-       }
+       if (!err)
+               nvme_show_id_nvmset(&nvmset, cfg.nvmset_id, flags);
        else if (err > 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                perror("identify nvm set list");
 
@@ -1881,14 +1760,17 @@ static int id_uuid(int argc, char **argv, struct command *cmd, struct plugin *pl
                "in either human-readable or binary format.";
        const char *raw = "show uuid in binary format";
        const char *human_readable = "show uuid in readable format";
+
        struct nvme_id_uuid_list uuid_list;
-       int err, fmt, fd;
-       unsigned int flags = 0;
+       enum nvme_print_flags flags;
+       int err, fd;
+
        struct config {
                int   raw_binary;
                int   human_readable;
                char *output_format;
        };
+
        struct config cfg = {
                .output_format = "normal",
        };
@@ -1904,29 +1786,19 @@ static int id_uuid(int argc, char **argv, struct command *cmd, struct plugin *pl
        if (fd < 0)
                return fd;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               err = fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
-
        if (cfg.raw_binary)
-               fmt = BINARY;
+               flags = BINARY;
        if (cfg.human_readable)
-               flags |= HUMAN;
+               flags |= VERBOSE;
 
        err = nvme_identify_uuid(fd, &uuid_list);
-       if (!err) {
-               if (fmt == BINARY)
-                       d_raw((unsigned char *)&uuid_list, sizeof(uuid_list));
-               else if (fmt == JSON)
-                       json_nvme_id_uuid_list(&uuid_list);
-               else {
-                       printf("NVME Identify UUID:\n");
-                       show_nvme_id_uuid_list(&uuid_list, flags);
-               }
-       } else if (err > 0)
-               show_nvme_status(err);
+       if (!err)
+               nvme_show_id_uuid_list(&uuid_list, flags);
+       else if (err > 0)
+               nvme_show_status(err);
        else
                perror("identify UUID list");
 close_fd:
@@ -2017,7 +1889,7 @@ static int virtual_mgmt(int argc, char **argv, struct command *cmd, struct plugi
        if (!err) {
                printf("success, Number of Resources allocated:%#x\n", result);
        } else if (err > 0) {
-               show_nvme_status(err);
+               nvme_show_status(err);
        } else
                perror("virt-mgmt");
 
@@ -2033,8 +1905,10 @@ static int list_secondary_ctrl(int argc, char **argv, struct command *cmd, struc
        const char *controller = "lowest controller identifier to display";
        const char *namespace_id = "optional namespace attached to controller";
        const char *num_entries = "number of entries to retrieve";
-       int err, fmt, fd;
+
        struct nvme_secondary_controllers_list *sc_list;
+       enum nvme_print_flags flags;
+       int err, fd;
 
        struct config {
                __u16 cntid;
@@ -2062,11 +1936,9 @@ static int list_secondary_ctrl(int argc, char **argv, struct command *cmd, struc
        if (fd < 0)
                goto ret;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               err = fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
 
        if (!cfg.num_entries) {
                fprintf(stderr, "non-zero num-entries is required param\n");
@@ -2081,15 +1953,10 @@ static int list_secondary_ctrl(int argc, char **argv, struct command *cmd, struc
        }
 
        err = nvme_identify_secondary_ctrl_list(fd, cfg.namespace_id, cfg.cntid, sc_list);
-       if (!err) {
-               if (fmt == BINARY)
-                       d_raw((unsigned char *)sc_list, sizeof(*sc_list));
-               else if (fmt == JSON)
-                       json_nvme_list_secondary_ctrl(sc_list, cfg.num_entries);
-               else
-                       show_nvme_list_secondary_ctrl(sc_list, cfg.num_entries);
-       } else if (err > 0)
-               show_nvme_status(err);
+       if (!err)
+               nvme_show_list_secondary_ctrl(sc_list, cfg.num_entries, flags);
+       else if (err > 0)
+               nvme_show_status(err);
        else
                perror("id secondary controller list");
 
@@ -2141,7 +2008,7 @@ static int device_self_test(int argc, char **argv, struct command *cmd, struct p
                else
                        printf("Device self-test started\n");
        } else if (err > 0) {
-               show_nvme_status(err);
+               nvme_show_status(err);
        } else
                perror("Device self-test");
 
@@ -2152,13 +2019,15 @@ ret:
 
 static int self_test_log(int argc, char **argv, struct command *cmd, struct plugin *plugin)
 {
-       struct nvme_self_test_log self_test_log;
        const char *desc = "Retrieve the self-test log for the given device and given test "\
                        "(or optionally a namespace) in either decoded format "\
                        "(default) or binary.";
        const char *namespace_id = "Indicate the namespace from which the self-test "\
                                    "log has to be obtained";
-       int err, fmt, fd;
+
+       struct nvme_self_test_log self_test_log;
+       enum nvme_print_flags flags;
+       int err, fd;
 
        struct config {
                __u32 namespace_id;
@@ -2180,31 +2049,17 @@ static int self_test_log(int argc, char **argv, struct command *cmd, struct plug
        if (fd < 0)
                goto ret;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               err = fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
 
        err = nvme_self_test_log(fd, cfg.namespace_id, &self_test_log);
-       if (!err) {
-               if (self_test_log.crnt_dev_selftest_oprn == 0) {
-                       if (fmt == BINARY)
-                               d_raw((unsigned char *)&self_test_log, sizeof(self_test_log));
-                       else if (fmt == JSON)
-                               json_self_test_log(&self_test_log, devicename);
-                       else
-                               show_self_test_log(&self_test_log, devicename);
-               } else {
-                       printf("Test is %d%% complete and is still in progress.\n",
-                               self_test_log.crnt_dev_selftest_compln);
-               }
-       } else if (err > 0) {
-               show_nvme_status(err);
-       } else {
-               perror("self_test_log");
-       }
-
+       if (!err)
+               nvme_show_self_test_log(&self_test_log, devicename, flags);
+       else if (err > 0)
+               nvme_show_status(err);
+       else
+               perror("self test log");
 close_fd:
        close(fd);
 ret:
@@ -2332,7 +2187,7 @@ static int get_feature(int argc, char **argv, struct command *cmd, struct plugin
                } else if (buf)
                        d_raw(buf, cfg.data_len);
        } else if (err > 0) {
-               show_nvme_status(err);
+               nvme_show_status(err);
        } else
                perror("get-feature");
 
@@ -2433,7 +2288,7 @@ static int fw_download(int argc, char **argv, struct command *cmd, struct plugin
                        perror("fw-download");
                        break;
                } else if (err != 0) {
-                       show_nvme_status(err);
+                       nvme_show_status(err);
                        break;
                }
                fw_buf     += cfg.xfer;
@@ -2529,7 +2384,7 @@ static int fw_commit(int argc, char **argv, struct command *cmd, struct plugin *
                        printf(", but firmware requires %s reset\n", nvme_fw_status_reset_type(err));
                        break;
                default:
-                       show_nvme_status(err);
+                       nvme_show_status(err);
                        break;
                }
        else {
@@ -2700,7 +2555,7 @@ static int sanitize(int argc, char **argv, struct command *cmd, struct plugin *p
        if (ret < 0)
                perror("sanitize");
        else if (ret > 0)
-               show_nvme_status(ret);
+               nvme_show_status(ret);
 
 close_fd:
        close(fd);
@@ -2714,10 +2569,11 @@ static int show_registers(int argc, char **argv, struct command *cmd, struct plu
                                        "in binary or human-readable format";
        const char *human_readable = "show info in readable format in case of "\
                                        "output_format == normal";
-       void *bar;
-       int fd, err, fmt;
+
+       enum nvme_print_flags flags;
        bool fabrics = true;
-       const int reg_size = 0x50;  /* 00h to 4Fh */
+       int fd, err;
+       void *bar;
 
        struct config {
                int human_readable;
@@ -2739,19 +2595,11 @@ static int show_registers(int argc, char **argv, struct command *cmd, struct plu
        if (fd < 0)
                goto ret;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               fprintf(stderr, "Invalid argument --output-format=%s\n",
-                               cfg.output_format);
-               err = -fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
-
-       if (cfg.human_readable && fmt != NORMAL) {
-               fprintf(stderr, "Only --output-format=normal supports -H\n");
-               err = -EINVAL;
-               goto close_fd;
-       }
+       if (cfg.human_readable)
+               flags |= VERBOSE;
 
        err = nvme_get_properties(fd, &bar);
        if (err) {
@@ -2760,21 +2608,14 @@ static int show_registers(int argc, char **argv, struct command *cmd, struct plu
                if (bar)
                        err = 0;
        }
-       if (!bar) {
-               err = -ENODEV;
+       if (!bar)
                goto close_fd;
-       }
-
-       if (fmt == BINARY)
-               d_raw((unsigned char *) bar, reg_size);
-       else if (fmt == JSON)
-               json_ctrl_registers(bar);
-       else
-               show_ctrl_registers(bar, cfg.human_readable ? HUMAN : 0, fabrics);
 
+       nvme_show_ctrl_registers(bar, fabrics, flags);
        if (fabrics)
                free(bar);
-
+       else
+               munmap(bar, getpagesize());
 close_fd:
        close(fd);
 ret:
@@ -2822,9 +2663,9 @@ static int get_property(int argc, char **argv, struct command *cmd, struct plugi
        if (err < 0) {
                perror("get-property");
        } else if (!err) {
-               show_single_property(cfg.offset, value, cfg.human_readable);
+               nvme_show_single_property(cfg.offset, value, cfg.human_readable);
        } else if (err > 0) {
-               show_nvme_status(err);
+               nvme_show_status(err);
        }
 
 close_fd:
@@ -2879,7 +2720,7 @@ static int set_property(int argc, char **argv, struct command *cmd, struct plugi
                printf("set-property: %02x (%s), value: %#08x\n", cfg.offset,
                                nvme_register_to_string(cfg.offset), cfg.value);
        } else if (err > 0) {
-               show_nvme_status(err);
+               nvme_show_status(err);
        }
 
 close_fd:
@@ -2968,7 +2809,6 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu
                }
        }
 
-       memset(&ctrl, 0, sizeof (struct nvme_id_ctrl));
        err = nvme_identify_ctrl(fd, &ctrl);
        if (err) {
                perror("identify-ctrl");
@@ -3006,7 +2846,7 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu
                                perror("identify-namespace");
                        else {
                                fprintf(stderr, "identify failed\n");
-                               show_nvme_status(err);
+                               nvme_show_status(err);
                        }
                        goto close_fd;
                }
@@ -3064,7 +2904,7 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu
                fprintf(stderr, "You are about to format %s, namespace %#x%s.\n",
                        devicename, cfg.namespace_id,
                        cfg.namespace_id == NVME_NSID_ALL ? "(ALL namespaces)" : "");
-               show_relatives(devicename);
+               nvme_show_relatives(devicename);
                fprintf(stderr, "WARNING: Format may irrevocably delete this device's data.\n"
                        "You have 10 seconds to press Ctrl-C to cancel this operation.\n\n"
                        "Use the force [--force|-f] option to suppress this warning.\n");
@@ -3077,7 +2917,7 @@ static int format(int argc, char **argv, struct command *cmd, struct plugin *plu
        if (err < 0)
                perror("format");
        else if (err != 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else {
                printf("Success formatting namespace:%x\n", cfg.namespace_id);
                if (S_ISBLK(nvme_stat.st_mode) && ioctl(fd, BLKRRPART) < 0) {
@@ -3197,13 +3037,13 @@ static int set_feature(int argc, char **argv, struct command *cmd, struct plugin
                        nvme_feature_to_string(cfg.feature_id), cfg.value);
                if (buf) {
                        if (cfg.feature_id == NVME_FEAT_LBA_RANGE)
-                               show_lba_range((struct nvme_lba_range_type *)buf,
+                               nvme_show_lba_range((struct nvme_lba_range_type *)buf,
                                                                result);
                        else
                                d(buf, cfg.data_len, 16, 1);
                }
        } else if (err > 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
 
 close_ffd:
        close(ffd);
@@ -3452,7 +3292,7 @@ static int dir_send(int argc, char **argv, struct command *cmd, struct plugin *p
                }
        }
        else if (err > 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
 
 close_ffd:
        close(ffd);
@@ -3510,7 +3350,7 @@ static int write_uncor(int argc, char **argv, struct command *cmd, struct plugin
        if (err < 0)
                perror("write uncorrectable");
        else if (err != 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                printf("NVME Write Uncorrectable Success\n");
 
@@ -3602,7 +3442,7 @@ static int write_zeroes(int argc, char **argv, struct command *cmd, struct plugi
        if (err < 0)
                perror("write-zeroes");
        else if (err != 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                printf("NVME Write Zeroes Success\n");
 
@@ -3703,7 +3543,7 @@ static int dsm(int argc, char **argv, struct command *cmd, struct plugin *plugin
        if (err < 0)
                perror("data-set management");
        else if (err != 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                printf("NVMe DSM: success\n");
 
@@ -3752,7 +3592,7 @@ static int flush(int argc, char **argv, struct command *cmd, struct plugin *plug
        if (err < 0)
                perror("flush");
        else if (err != 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                printf("NVMe Flush: success\n");
 close_fd:
@@ -3826,7 +3666,7 @@ static int resv_acquire(int argc, char **argv, struct command *cmd, struct plugi
        if (err < 0)
                perror("reservation acquire");
        else if (err != 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                printf("NVME Reservation Acquire success\n");
 
@@ -3904,7 +3744,7 @@ static int resv_register(int argc, char **argv, struct command *cmd, struct plug
        if (err < 0)
                perror("reservation register");
        else if (err != 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                printf("NVME Reservation  success\n");
 
@@ -3978,7 +3818,7 @@ static int resv_release(int argc, char **argv, struct command *cmd, struct plugi
        if (err < 0)
                perror("reservation release");
        else if (err != 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                printf("NVME Reservation Release success\n");
 
@@ -4000,8 +3840,9 @@ static int resv_report(int argc, char **argv, struct command *cmd, struct plugin
        const char *cdw11 = "command dword 11 value";
        const char *raw = "dump output in binary format";
 
-       int err, fmt, fd, size;
        struct nvme_reservation_status *status;
+       enum nvme_print_flags flags;
+       int err, fd, size;
 
        struct config {
                __u32 namespace_id;
@@ -4031,25 +3872,24 @@ static int resv_report(int argc, char **argv, struct command *cmd, struct plugin
        if (fd < 0)
                goto ret;
 
-       fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0) {
-               err = fmt;
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
-       }
        if (cfg.raw_binary)
-               fmt = BINARY;
+               flags = BINARY;
 
        if (!cfg.namespace_id) {
                cfg.namespace_id = get_nsid(fd);
                if (cfg.namespace_id == 0) {
-                       err = -EINVAL;
+                       err = -ENOTBLK;
                        goto close_fd;
                }
        }
+
        if (!cfg.numd || cfg.numd >= (0x1000 >> 2))
                cfg.numd = (0x1000 >> 2) - 1;
        if (cfg.numd < 3)
-               cfg.numd = 3; /* get the header fields at least */
+               cfg.numd = 3;
 
        size = (cfg.numd + 1) << 2;
 
@@ -4061,22 +3901,13 @@ static int resv_report(int argc, char **argv, struct command *cmd, struct plugin
        memset(status, 0, size);
 
        err = nvme_resv_report(fd, cfg.namespace_id, cfg.numd, cfg.cdw11, status);
-       if (err < 0)
-               perror("reservation report");
-       else if (err != 0)
+       if (!err)
+               nvme_show_resv_report(status, size, cfg.cdw11, flags);
+       else if (err > 0)
                fprintf(stderr, "NVME IO command error:%04x\n", err);
-       else {
-               if (fmt == BINARY)
-                       d_raw((unsigned char *)status, size);
-               else if (fmt == JSON)
-                       json_nvme_resv_report(status, size, cfg.cdw11);
-               else {
-                       printf("NVME Reservation Report success\n");
-                       show_nvme_resv_report(status, size, cfg.cdw11);
-               }
-       }
+       else
+               perror("reservation report");
        free(status);
-
 close_fd:
        close(fd);
 ret:
@@ -4086,9 +3917,9 @@ ret:
 static unsigned long long elapsed_utime(struct timeval start_time,
                                        struct timeval end_time)
 {
-       unsigned long long ret = (end_time.tv_sec - start_time.tv_sec) * 1000000 +
+       unsigned long long err = (end_time.tv_sec - start_time.tv_sec) * 1000000 +
                (end_time.tv_usec - start_time.tv_usec);
-       return ret;
+       return err;
 }
 
 static int submit_io(int opcode, char *command, const char *desc,
@@ -4308,7 +4139,7 @@ static int submit_io(int opcode, char *command, const char *desc,
        if (err < 0)
                perror("submit-io");
        else if (err)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else {
                if (!(opcode & 1) && write(dfd, (void *)buffer, cfg.data_size) < 0) {
                        fprintf(stderr, "write: %s: failed to write buffer to output file\n",
@@ -4416,7 +4247,7 @@ static int verify_cmd(int argc, char **argv, struct command *cmd, struct plugin
 
        err = fd = parse_and_open(argc, argv, desc, opts);
        if (fd < 0)
-               return fd;
+               goto err;
 
        if (cfg.prinfo > 0xf) {
                err = EINVAL;
@@ -4442,12 +4273,13 @@ static int verify_cmd(int argc, char **argv, struct command *cmd, struct plugin
        if (err < 0)
                perror("verify");
        else if (err != 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else
                printf("NVME Verify Success\n");
 
 close_fd:
        close(fd);
+err:
        return err;
 }
 
@@ -4548,9 +4380,11 @@ static int get_lba_status(int argc, char **argv, struct command *cmd,
                             " Status Descriptors to return.";
        const char *rl = "Range Length(RL) specifies the length of the range"\
                          " of contiguous LBAs beginning at SLBA";
-       int err, fd, fmt;
-       void *buf;
+
+       enum nvme_print_flags flags;
        unsigned long buf_len;
+       int err, fd;
+       void *buf;
 
        struct config {
                __u64 slba;
@@ -4579,10 +4413,10 @@ static int get_lba_status(int argc, char **argv, struct command *cmd,
 
        err = fd = parse_and_open(argc, argv, desc, opts);
        if (fd < 0)
-               goto ret;
+               goto err;
 
-       err = fmt = validate_output_format(cfg.output_format);
-       if (fmt < 0)
+       err = flags = validate_output_format(cfg.output_format);
+       if (flags < 0)
                goto close_fd;
 
        if (!cfg.atype) {
@@ -4600,19 +4434,16 @@ static int get_lba_status(int argc, char **argv, struct command *cmd,
 
        err = nvme_get_lba_status(fd, cfg.slba, cfg.mndw, cfg.atype, cfg.rl,
                        buf);
-       if (err)
-               goto free;
-
-       if (fmt == BINARY)
-               d_raw((unsigned char *)buf, buf_len);
+       if (!err)
+               nvme_show_lba_status(buf, buf_len, flags);
+       else if (err > 0)
+               fprintf(stderr, "NVME command error:%04x\n", err);
        else
-               show_lba_status(buf);
-
-free:
+               perror("get lba status");
        free(buf);
 close_fd:
        close(fd);
-ret:
+err:
        return nvme_status_to_errno(err, false);
 }
 
@@ -4737,7 +4568,7 @@ static int dir_receive(int argc, char **argv, struct command *cmd, struct plugin
                }
        }
        else if (err > 0)
-               show_nvme_status(err);
+               nvme_show_status(err);
 free:
        if (cfg.data_len)
                free(buf);
@@ -4925,7 +4756,7 @@ static int passthru(int argc, char **argv, int ioctl_cmd, const char *desc, stru
        if (err < 0)
                perror("passthru");
        else if (err)
-               show_nvme_status(err);
+               nvme_show_status(err);
        else  {
                if (!cfg.raw_binary) {
                        fprintf(stderr, "NVMe command result:%08x\n", result);
@@ -5040,7 +4871,7 @@ void register_extension(struct plugin *plugin)
 
 int main(int argc, char **argv)
 {
-       int ret;
+       int err;
 
        nvme.extensions->parent = &nvme;
        if (argc < 2) {
@@ -5049,9 +4880,9 @@ int main(int argc, char **argv)
        }
        setlocale(LC_ALL, "");
 
-       ret = handle_plugin(argc - 1, &argv[1], nvme.extensions);
-       if (ret == -ENOTTY)
+       err = handle_plugin(argc - 1, &argv[1], nvme.extensions);
+       if (err == -ENOTTY)
                general_help(&builtin);
 
-       return ret;
+       return err;
 }
diff --git a/nvme.h b/nvme.h
index e5ac92a44346bc94ea380fbd0125a7c8520929e7..42640185d94c69284c3b7f3c5d8a142ea7c37182 100644 (file)
--- a/nvme.h
+++ b/nvme.h
 #include <stdbool.h>
 #include <stdint.h>
 #include <endian.h>
+
 #include "plugin.h"
 #include "util/json.h"
-
-#define unlikely(x) x
-
+#include "util/argconfig.h"
 #include "linux/nvme.h"
 
+enum nvme_print_flags {
+       NORMAL  = 0,
+       VERBOSE = 1 << 0,       /* verbosely decode complex values for humans */
+       JSON    = 1 << 1,       /* display in json format */
+       VS      = 1 << 2,       /* hex dump vendor specific data areas */
+       BINARY  = 1 << 3,       /* binary dump raw bytes */
+};
+
 struct nvme_effects_log_page {
        __le32 acs[256];
        __le32 iocs[256];
@@ -207,12 +214,6 @@ struct subsys_list_item {
        struct ctrl_list_item *ctrls;
 };
 
-enum {
-       NORMAL,
-       JSON,
-       BINARY,
-};
-
 struct connect_args {
        char *subsysnqn;
        char *transport;
@@ -237,14 +238,13 @@ extern const char *subsys_dir;
 
 void register_extension(struct plugin *plugin);
 
-#include "util/argconfig.h"
 int parse_and_open(int argc, char **argv, const char *desc,
        const struct argconfig_commandline_options *clo);
 
 extern const char *devicename;
 
 int __id_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin, void (*vs)(__u8 *vs, struct json_object *root));
-int    validate_output_format(char *format);
+enum nvme_print_flags validate_output_format(char *format);
 
 int get_nvme_ctrl_info(char *name, char *path, struct ctrl_list_item *ctrl,
                        __u32 nsid);
index 23c1c4b7d8e2d8d7fa316fad6b478a4eba8c101e..36781766c741e0422e48814c25f765405de1cfcb 100644 (file)
@@ -121,9 +121,9 @@ static int lnvm_id_ns(int argc, char **argv, struct command *cmd, struct plugin
                return fd;
 
        if (cfg.human_readable)
-               flags |= HUMAN;
+               flags |= VERBOSE;
        else if (cfg.raw_binary)
-               flags |= RAW;
+               flags |= BINARY;
 
        return lnvm_do_id_ns(fd, cfg.namespace_id, flags);
 }
@@ -172,9 +172,9 @@ static int lnvm_chunk_log(int argc, char **argv, struct command *cmd, struct plu
        }
 
        if (fmt == BINARY)
-               flags |= RAW;
+               flags |= BINARY;
        else if (cfg.human_readable)
-               flags |= HUMAN;
+               flags |= VERBOSE;
 
        nsid = nvme_get_nsid(fd);
 
@@ -382,7 +382,7 @@ static int lnvm_get_bbtbl(int argc, char **argv, struct command *cmd, struct plu
        fd = parse_and_open(argc, argv, desc, opts);
 
        if (cfg.raw_binary)
-               flags |= RAW;
+               flags |= BINARY;
 
        return lnvm_do_get_bbtbl(fd, cfg.namespace_id, cfg.lunid, cfg.chid, flags);
 }