From: Gollu Appalanaidu Date: Sun, 22 Aug 2021 17:55:03 +0000 (+0530) Subject: nvme: add support for fid supported and effects log(lid = 0x12) X-Git-Tag: v1.16~27^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=4bed6fae997abbe5de7c74f4e8a313c1287c1d5c;p=users%2Fsagi%2Fnvme-cli.git nvme: add support for fid supported and effects log(lid = 0x12) Signed-off-by: Gollu Appalanaidu --- diff --git a/Documentation/nvme-fid-support-effects-log.1 b/Documentation/nvme-fid-support-effects-log.1 new file mode 100644 index 00000000..d5b64ad6 --- /dev/null +++ b/Documentation/nvme-fid-support-effects-log.1 @@ -0,0 +1,63 @@ +'\" t +.\" Title: nvme-fid-support-effects-log +.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] +.\" Generator: DocBook XSL Stylesheets v1.79.1 +.\" Date: 08/26/2021 +.\" Manual: NVMe Manual +.\" Source: NVMe +.\" Language: English +.\" +.TH "NVME\-FID\-SUPPORT\-" "1" "08/26/2021" "NVMe" "NVMe Manual" +.\" ----------------------------------------------------------------- +.\" * Define some portability stuff +.\" ----------------------------------------------------------------- +.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.\" http://bugs.debian.org/507673 +.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html +.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.ie \n(.g .ds Aq \(aq +.el .ds Aq ' +.\" ----------------------------------------------------------------- +.\" * set default formatting +.\" ----------------------------------------------------------------- +.\" disable hyphenation +.nh +.\" disable justification (adjust text to left margin only) +.ad l +.\" ----------------------------------------------------------------- +.\" * MAIN CONTENT STARTS HERE * +.\" ----------------------------------------------------------------- +.SH "NAME" +nvme-fid-support-effects-log \- Send NVMe FID Support and Effects log, return result and structure +.SH "SYNOPSIS" +.sp +.nf +\fInvme fid\-support\-effects\-log\fR [\-o | \-\-output\-format=] +.fi +.SH "DESCRIPTION" +.sp +For the NVMe device given, sends an FID Support and Effects log and provides the result and returned logstructure\&. +.sp +The parameter is mandatory and may be either the NVMe character device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1)\&. +.sp +On success, the structure may be returned in one of several ways depending on the option flags; the structure may be parsed by the program or the raw buffer may be printed to stdout\&. +.SH "OPTIONS" +.PP +\-o , \-\-output\-format= +.RS 4 +Set the reporting format to +\fInormal\fR, +\fIjson\fR, or +\fIbinary\fR\&. Only one output format can be used at a time\&. +.RE +.PP +\-H, \-\-human\-readable +.RS 4 +This option will parse and format many of the bit fields into human\-readable formats\&. +.RE +.SH "EXAMPLES" +.sp +No examples yet\&. +.SH "NVME" +.sp +Part of the nvme\-user suite diff --git a/Documentation/nvme-fid-support-effects-log.html b/Documentation/nvme-fid-support-effects-log.html new file mode 100644 index 00000000..b6171000 --- /dev/null +++ b/Documentation/nvme-fid-support-effects-log.html @@ -0,0 +1,821 @@ + + + + + + +nvme-fid-support-effects-log(1) + + + + + +
+
+

SYNOPSIS

+
+
+
nvme fid-support-effects-log <device> [-o <fmt> | --output-format=<fmt>]
+
+
+
+
+
+

DESCRIPTION

+
+

For the NVMe device given, sends an FID Support and Effects log and +provides the result and returned logstructure.

+

The <device> parameter is mandatory and may be either the NVMe character +device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1).

+

On success, the structure may be returned in one of several ways depending +on the option flags; the structure may be parsed by the program or the +raw buffer may be printed to stdout.

+
+
+
+

OPTIONS

+
+
+
+-o <format> +
+
+--output-format=<format> +
+
+

+ Set the reporting format to normal, json, or + binary. Only one output format can be used at a time. +

+
+
+-H +
+
+--human-readable +
+
+

+ This option will parse and format many of the bit fields + into human-readable formats. +

+
+
+
+
+
+

EXAMPLES

+
+

No examples yet.

+
+
+
+

NVME

+
+

Part of the nvme-user suite

+
+
+
+

+ + + diff --git a/Documentation/nvme-fid-support-effects-log.txt b/Documentation/nvme-fid-support-effects-log.txt new file mode 100644 index 00000000..d2702eb2 --- /dev/null +++ b/Documentation/nvme-fid-support-effects-log.txt @@ -0,0 +1,43 @@ +nvme-fid-support-effects-log(1) +=============================== + +NAME +---- +nvme-fid-support-effects-log - Send NVMe FID Support and Effects log, return result and structure + +SYNOPSIS +-------- +[verse] +'nvme fid-support-effects-log' [-o | --output-format=] + +DESCRIPTION +----------- +For the NVMe device given, sends an FID Support and Effects log and +provides the result and returned logstructure. + +The parameter is mandatory and may be either the NVMe character +device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1). + +On success, the structure may be returned in one of several ways depending +on the option flags; the structure may be parsed by the program or the +raw buffer may be printed to stdout. + +OPTIONS +------- +-o :: +--output-format=:: + Set the reporting format to 'normal', 'json', or + 'binary'. Only one output format can be used at a time. + +-H:: +--human-readable:: + This option will parse and format many of the bit fields + into human-readable formats. + +EXAMPLES +-------- +No examples yet. + +NVME +---- +Part of the nvme-user suite \ No newline at end of file diff --git a/completions/_nvme b/completions/_nvme index 92147eb3..8ab92aef 100644 --- a/completions/_nvme +++ b/completions/_nvme @@ -52,6 +52,7 @@ _nvme () { 'capacity-mgmt: submit capacity management command' 'show-regs:shows the controller registers; requires admin character device' 'boot-part-log: retrieve boot partition log' + 'fid-support-effects-log:retrieve fid support and effects log' 'help:print brief descriptions of all nvme commands' ) @@ -840,6 +841,14 @@ _nvme () { _arguments '*:: :->subcmds' _describe -t commands "nvme show-regs options" _shor ;; + (fid-support-effects-log) + local _fidsupporteffectslog + _fidsupporteffectslog=( + /dev/nvme':supply a device to use (required)' + ) + _arguments '*:: :->subcmds' + _describe -t commands "nvme fid-support-effects-log options" _fidsupporteffectslog + ;; (help) local _h _h=( id-ctrl id-ns list-ns id-iocs create-ns delete-ns attach-ns detach-ns @@ -848,7 +857,11 @@ _nvme () { security-send security-recv resv-acquire resv-register resv-release resv-report flush compare read write copy show-regs persistent-event-log pred-lat-event-agg-log nvm-id-ctrl endurance-event-agg-log lba-status-log +<<<<<<< HEAD resv-notif-log capacity-mgmt id-domain boot-part-log +======= + resv-notif-log capacity-mgmt id-domain fid-support-effects-log +>>>>>>> nvme: add support for fid supported and effects log(lid = 0x12) ) _arguments '*:: :->subcmds' _describe -t commands "help: infos on a specific nvme command, or provide no option to see a synopsis of all nvme commands" _h diff --git a/completions/bash-nvme-completion.sh b/completions/bash-nvme-completion.sh index b7f9f6da..8381f43e 100644 --- a/completions/bash-nvme-completion.sh +++ b/completions/bash-nvme-completion.sh @@ -100,7 +100,7 @@ _cmds="list list-subsys id-ctrl id-ns \ ns-rescan show-regs discover connect-all \ connect disconnect disconnect-all gen-hostnqn \ show-hostnqn dir-receive dir-send virt-mgmt \ - rpmb boot-part-log" + rpmb boot-part-log fid-support-effects-log" # Add plugins: for plugin in "${!_plugin_subcmds[@]}"; do @@ -221,6 +221,9 @@ nvme_list_opts () { --output-format= -o" ;; "ana-log") + opts+=" --output-format -o" + ;; + "fid-support-effects-log") opts+=" --output-format -o" ;; "error-log") diff --git a/linux/nvme.h b/linux/nvme.h index eeb46399..413c15ad 100644 --- a/linux/nvme.h +++ b/linux/nvme.h @@ -1313,6 +1313,7 @@ enum { NVME_LOG_LBA_STATUS = 0x0e, NVME_LOG_ENDURANCE_GROUP_EVENT_AGG = 0x0f, NVME_LOG_BOOT_PARTITION = 0x15, + NVME_LOG_FID_SUPPORT_EFFECTS = 0x12, NVME_LOG_DISC = 0x70, NVME_LOG_RESERVATION = 0x80, NVME_LOG_SANITIZE = 0x81, @@ -1967,4 +1968,25 @@ struct nvme_id_domain_list { struct nvme_id_domain_attr_entry domain_attr[]; }; +enum { + NVME_FID_EFFECTS_FSUPP = 1 << 0, + NVME_FID_EFFECTS_UDCC = 1 << 1, + NVME_FID_EFFECTS_NCC = 1 << 2, + NVME_FID_EFFECTS_NIC = 1 << 3, + NVME_FID_EFFECTS_CCC = 1 << 4, + NVME_FID_EFFECTS_UUID_SEL = 1 << 19, + NVME_FID_SCOPE_SHIFT = 20, + NVME_FID_SCOPE_MASK = 0xfff, + NVME_FID_SCOPE_NS = 1 << 0, + NVME_FID_SCOPE_CTRL = 1 << 1, + NVME_FID_SCOPE_NVM_SET = 1 << 2, + NVME_FID_SCOPE_ENDGRP = 1 << 3, + NVME_FID_SCOPE_DOMAIN = 1 << 4, + NVME_FID_SCOPE_NSS = 1 << 5, +}; + +struct nvme_fid_support_effects { + __le32 fid_support[256]; +}; + #endif /* _LINUX_NVME_H */ diff --git a/nvme-builtin.h b/nvme-builtin.h index a45b632f..85870715 100644 --- a/nvme-builtin.h +++ b/nvme-builtin.h @@ -89,6 +89,7 @@ COMMAND_LIST( ENTRY("dir-send", "Submit a Directive Send command, return results", dir_send) ENTRY("virt-mgmt", "Manage Flexible Resources between Primary and Secondary Controller ", virtual_mgmt) ENTRY("rpmb", "Replay Protection Memory Block commands", rpmb_cmd) + ENTRY("fid-support-effects-log", "Submit Feature ID Support and Effects Log, Return result", get_fid_support_effects_log) ); #endif diff --git a/nvme-ioctl.c b/nvme-ioctl.c index 9fd6c60f..f1c0fce9 100644 --- a/nvme-ioctl.c +++ b/nvme-ioctl.c @@ -665,6 +665,12 @@ int nvme_boot_part_log(int fd, __u8 lsp, void *data, __u32 size) false, lsp, size, data); } +int nvme_fid_support_effects_log(int fd, struct nvme_fid_support_effects *fid_log) +{ + return nvme_get_log(fd, 0, NVME_LOG_FID_SUPPORT_EFFECTS, false, + NVME_NO_LOG_LSP, sizeof(*fid_log), fid_log); +} + int nvme_feature(int fd, __u8 opcode, __u32 nsid, __u32 cdw10, __u32 cdw11, __u32 cdw12, __u32 cdw14, __u32 data_len, void *data, __u32 *result) { diff --git a/nvme-ioctl.h b/nvme-ioctl.h index a0368e9e..43c8a065 100644 --- a/nvme-ioctl.h +++ b/nvme-ioctl.h @@ -122,6 +122,7 @@ int nvme_lba_status_log(int fd, void *lba_status, bool rae, __u32 size); int nvme_resv_notif_log(int fd, struct nvme_resv_notif_log *resv); int nvme_boot_part_log(int fd, __u8 lsp, void *data, __u32 size); +int nvme_fid_support_effects_log(int fd, struct nvme_fid_support_effects *fid_log); int nvme_feature(int fd, __u8 opcode, __u32 nsid, __u32 cdw10, __u32 cdw11, __u32 cdw12, __u32 cdw14, __u32 data_len, void *data, __u32 *result); diff --git a/nvme-print.c b/nvme-print.c index 045d8649..f1014dd1 100755 --- a/nvme-print.c +++ b/nvme-print.c @@ -1844,6 +1844,33 @@ static void json_boot_part_log(void *bp_log) json_free_object(root); } +static void json_fid_support_effects_log(struct nvme_fid_support_effects *fid_log) +{ + struct json_object *root; + struct json_object *fids; + struct json_object *fids_list; + unsigned int fid; + char key[128]; + __u32 fid_support; + + root = json_create_object(); + fids_list = json_create_array(); + for (fid = 0; fid < 256; fid++) { + fid_support = le32_to_cpu(fid_log->fid_support[fid]); + if (fid_support & NVME_FID_EFFECTS_FSUPP) { + fids = json_create_object(); + sprintf(key, "fid_%u", fid); + json_object_add_value_uint(fids, key, fid_support); + json_array_add_value_object(fids_list, fids); + } + } + + json_object_add_value_object(root, "fid_support", fids_list); + json_print_object(root, NULL); + printf("\n"); + json_free_object(root); +} + void nvme_show_boot_part_log(void *bp_log, const char *devname, __u32 size, enum nvme_print_flags flags) { @@ -1860,6 +1887,55 @@ void nvme_show_boot_part_log(void *bp_log, const char *devname, printf("Active BPID: %u\n", (le32_to_cpu(hdr->bpinfo) >> 31) & 0x1); } +static void nvme_show_fid_support_effects_log_human(__u32 fid_support) +{ + const char *set = "+"; + const char *clr = "-"; + __u16 fsp; + + printf(" FSUPP+"); + printf(" UDCC%s", (fid_support & NVME_FID_EFFECTS_UDCC) ? set : clr); + printf(" NCC%s", (fid_support & NVME_FID_EFFECTS_NCC) ? set : clr); + printf(" NIC%s", (fid_support & NVME_FID_EFFECTS_NIC) ? set : clr); + printf(" CCC%s", (fid_support & NVME_FID_EFFECTS_CCC) ? set : clr); + printf(" USS%s", (fid_support & NVME_FID_EFFECTS_UUID_SEL) ? set : clr); + + fsp = (fid_support >> NVME_FID_SCOPE_SHIFT) & NVME_FID_SCOPE_MASK; + + printf(" NAMESPACE SCOPE%s", (fsp & NVME_FID_SCOPE_NS) ? set : clr); + printf(" CONTROLLER SCOPE%s", (fsp & NVME_FID_SCOPE_CTRL) ? set : clr); + printf(" NVM SET SCOPE%s", (fsp & NVME_FID_SCOPE_NVM_SET) ? set : clr); + printf(" ENDURANCE GROUP SCOPE%s", (fsp & NVME_FID_SCOPE_ENDGRP) ? set : clr); + printf(" DOMAIN SCOPE%s", (fsp & NVME_FID_SCOPE_DOMAIN) ? set : clr); + printf(" NVM Subsystem SCOPE%s", (fsp & NVME_FID_SCOPE_NSS) ? set : clr); +} + +void nvme_show_fid_support_effects_log(struct nvme_fid_support_effects *fid_log, + const char *devname, enum nvme_print_flags flags) +{ + __u32 fid_effect; + int i, human = flags & VERBOSE; + + if (flags & BINARY) + return d_raw((unsigned char *)fid_log, sizeof(*fid_log)); + if (flags & JSON) + return json_fid_support_effects_log(fid_log); + + printf("FID Supports Effects Log for device: %s\n", devname); + printf("Admin Command Set\n"); + for (i = 0; i < 256; i++) { + fid_effect = le32_to_cpu(fid_log->fid_support[i]); + if (fid_effect & NVME_FID_EFFECTS_FSUPP) { + printf("FID %02x -> Support Effects Log: %08x", i, + fid_effect); + if (human) + nvme_show_fid_support_effects_log_human(fid_effect); + else + printf("\n"); + } + } +} + static void nvme_show_subsystem(struct nvme_subsystem *s) { int i; diff --git a/nvme-print.h b/nvme-print.h index 5321b8cc..14b4e74e 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -70,6 +70,8 @@ void nvme_show_resv_notif_log(struct nvme_resv_notif_log *resv, const char *devname, enum nvme_print_flags flags); void nvme_show_boot_part_log(void *bp_log, const char *devname, __u32 size, enum nvme_print_flags flags); +void nvme_show_fid_support_effects_log(struct nvme_fid_support_effects *fid_log, + 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); diff --git a/nvme.c b/nvme.c index dab40aee..7bace35b 100644 --- a/nvme.c +++ b/nvme.c @@ -1552,6 +1552,53 @@ ret: return nvme_status_to_errno(err, false); } +static int get_fid_support_effects_log(int argc, char **argv, struct command *cmd, + struct plugin *plugin) +{ + const char *desc = "Retrieve FID Support and Effects log and show it."; + const char *human_readable = "show log in readable format"; + struct nvme_fid_support_effects fid_support_log; + enum nvme_print_flags flags; + int fd, err = -1; + + struct config { + int human_readable; + char *output_format; + }; + + struct config cfg = { + .output_format = "normal", + }; + + OPT_ARGS(opts) = { + OPT_FMT("output-format", 'o', &cfg.output_format, output_format), + OPT_FLAG("human-readable",'H', &cfg.human_readable, human_readable), + OPT_END() + }; + + err = fd = parse_and_open(argc, argv, desc, opts); + if (fd < 0) + goto ret; + + err = flags = validate_output_format(cfg.output_format); + if (flags < 0) + goto close_fd; + if (cfg.human_readable) + flags |= VERBOSE; + + err = nvme_fid_support_effects_log(fd, &fid_support_log); + if (!err) + nvme_show_fid_support_effects_log(&fid_support_log, devicename, flags); + else if (err > 0) + nvme_show_status(err); + else + perror("fid support effects log"); +close_fd: + close(fd); +ret: + return nvme_status_to_errno(err, false); +} + static int list_ctrl(int argc, char **argv, struct command *cmd, struct plugin *plugin) { const char *desc = "Show controller list information for the subsystem the "\