From: Keith Busch Date: Mon, 8 Jun 2015 17:15:01 +0000 (-0600) Subject: Add nvme identify list controller sub command X-Git-Tag: v0.1~35 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=488e1f45ca57797c597ebfe23dfb961a3f55f846;p=users%2Fsagi%2Fnvme-cli.git Add nvme identify list controller sub command Signed-off-by: Keith Busch --- diff --git a/Documentation/cmds-main.txt b/Documentation/cmds-main.txt index d313e6a1..edfb3e3f 100644 --- a/Documentation/cmds-main.txt +++ b/Documentation/cmds-main.txt @@ -52,6 +52,9 @@ linknvme:nvme-list-ns[1]:: linknvme:nvme-list[1]:: List all nvme controllers +linknvme:nvme-list-ctrl[1]:: + List controller in NVMe subsystem + linknvme:nvme-read[1]:: Issue IO Read Command diff --git a/Documentation/nvme-list-ctrl.1 b/Documentation/nvme-list-ctrl.1 new file mode 100644 index 00000000..820d72b6 --- /dev/null +++ b/Documentation/nvme-list-ctrl.1 @@ -0,0 +1,55 @@ +'\" t +.\" Title: nvme-id-ns +.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] +.\" Generator: DocBook XSL Stylesheets v1.76.1 +.\" Date: 06/08/2015 +.\" Manual: Git Manual +.\" Source: Git +.\" Language: English +.\" +.TH "NVME\-ID\-NS" "1" "06/08/2015" "Git" "Git 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-list-ctrl \- Send NVMe Identify List Controllers, return result and structure +.SH "SYNOPSIS" +.sp +.nf +\fInvme list\-ctrl\fR [\-\-cntid= | \-c ] +.fi +.SH "DESCRIPTION" +.sp +For the NVMe device given, sends an identify command for controller list and provides the result and returned structure\&. +.sp +The parameter is mandatory and may be either the NVMe character device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1)\&. The starting controller in the list always begins with 0 unless the \*(Aq\-\-cntid\*(Aq option is given to override\&. +.sp +On success, the controller array is printed for each index and controller identifier\&. +.SH "OPTIONS" +.PP +\-c , \-\-cntid= +.RS 4 +Retrieve the identify list structure starting with the given controller id\&. +.RE +.SH "EXAMPLES" +.sp +No examples yet\&. +.SH "NVME" +.sp +Part of the nvme\-user suite diff --git a/Documentation/nvme-list-ctrl.html b/Documentation/nvme-list-ctrl.html new file mode 100644 index 00000000..f39d7528 --- /dev/null +++ b/Documentation/nvme-list-ctrl.html @@ -0,0 +1,811 @@ + + + + + +nvme-id-ns(1) + + + + + +
+
+

SYNOPSIS

+
+
+
nvme list-ctrl <device> [--cntid=<cntid> | -c <cntid>]
+
+
+
+
+
+

DESCRIPTION

+
+

For the NVMe device given, sends an identify command for controller list +and provides the result and returned structure.

+

The <device> parameter is mandatory and may be either the NVMe character +device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1). +The starting controller in the list always begins with 0 unless the +'--cntid' option is given to override.

+

On success, the controller array is printed for each index and controller +identifier.

+
+
+
+

OPTIONS

+
+
+
+-c <cntid> +
+
+--cntid=<cntid> +
+
+

+ Retrieve the identify list structure starting with the given controller id. +

+
+
+
+
+
+

EXAMPLES

+
+

No examples yet.

+
+
+
+

NVME

+
+

Part of the nvme-user suite

+
+
+
+

+ + + diff --git a/Documentation/nvme-list-ctrl.txt b/Documentation/nvme-list-ctrl.txt new file mode 100644 index 00000000..44e645ac --- /dev/null +++ b/Documentation/nvme-list-ctrl.txt @@ -0,0 +1,38 @@ +nvme-id-ns(1) +============= + +NAME +---- +nvme-list-ctrl - Send NVMe Identify List Controllers, return result and structure + +SYNOPSIS +-------- +[verse] +'nvme list-ctrl' [--cntid= | -c ] + +DESCRIPTION +----------- +For the NVMe device given, sends an identify command for controller list +and provides the result and returned structure. + +The parameter is mandatory and may be either the NVMe character +device (ex: /dev/nvme0), or a namespace block device (ex: /dev/nvme0n1). +The starting controller in the list always begins with 0 unless the +`'--cntid'` option is given to override. + +On success, the controller array is printed for each index and controller +identifier. + +OPTIONS +------- +-c :: +--cntid=:: + Retrieve the identify list structure starting with the given controller id. + +EXAMPLES +-------- +No examples yet. + +NVME +---- +Part of the nvme-user suite diff --git a/linux/nvme.h b/linux/nvme.h index 7aeccf41..60c6c516 100644 --- a/linux/nvme.h +++ b/linux/nvme.h @@ -322,6 +322,11 @@ struct nvme_dsm_range { __le64 slba; }; +struct nvme_controller_list { + __le16 num; + __le16 identifier[]; +}; + /* Admin commands */ enum nvme_admin_opcode { @@ -335,8 +340,10 @@ enum nvme_admin_opcode { nvme_admin_set_features = 0x09, nvme_admin_get_features = 0x0a, nvme_admin_async_event = 0x0c, + nvme_admin_ns_mgmt = 0x0d, nvme_admin_activate_fw = 0x10, nvme_admin_download_fw = 0x11, + nvme_admin_ns_attach = 0x15, nvme_admin_format_nvm = 0x80, nvme_admin_security_send = 0x81, nvme_admin_security_recv = 0x82, diff --git a/nvme.c b/nvme.c index 4904c77e..2c6e62bc 100644 --- a/nvme.c +++ b/nvme.c @@ -49,6 +49,8 @@ #include "src/argconfig.h" #include "src/suffix.h" +#define min(x, y) (x) > (y) ? (y) : (x) + static int fd; static struct stat nvme_stat; static const char *devicename; @@ -58,6 +60,7 @@ static const char *devicename; ENTRY(ID_CTRL, "id-ctrl", "Send NVMe Identify Controller", id_ctrl) \ ENTRY(ID_NS, "id-ns", "Send NVMe Identify Namespace, display structure", id_ns) \ ENTRY(LIST_NS, "list-ns", "Send NVMe Identify List, display structure", list_ns) \ + ENTRY(LIST_CTRL, "list-ctrl", "Send NVMe Identify Controller List, display structure", list_ctrl) \ ENTRY(GET_NS_ID, "get-ns-id", "Retrieve the namespace ID of opened block device", get_ns_id) \ ENTRY(GET_LOG, "get-log", "Generic NVMe get log, returns log in raw format", get_log) \ ENTRY(GET_FW_LOG, "fw-log", "Retrieve FW Log, show it", get_fw_log) \ @@ -331,7 +334,7 @@ static const char *nvme_status_to_string(__u32 status) } } -static int identify(int namespace, void *ptr, int cns) +static int identify(int namespace, void *ptr, __u32 cns) { struct nvme_admin_cmd cmd; @@ -1153,6 +1156,43 @@ static int get_log(int argc, char **argv) } } +static int list_ctrl(int argc, char **argv) +{ + int err, i; + struct nvme_controller_list *cntlist; + + struct config { + __u16 cntid; + }; + struct config cfg; + + const struct config defaults = { + .cntid = 0, + }; + + const struct argconfig_commandline_options command_line_options[] = { + {"cntid", "NUM", CFG_POSITIVE, &defaults.cntid, required_argument, NULL}, + {"c", "NUM", CFG_POSITIVE, &defaults.cntid, required_argument, NULL}, + {0} + }; + argconfig_parse(argc, argv, "list_ctrl", command_line_options, + &defaults, &cfg, sizeof(cfg)); + get_dev(1, argc, argv); + + if (posix_memalign((void *)&cntlist, getpagesize(), 0x1000)) + return ENOMEM; + + err = identify(0, cntlist, defaults.cntid << 16 | 0x13); + if (!err) { + for (i = 0; i < (min(cntlist->num, 2048)); i++) + printf("[%4u]:%#x\n", i, cntlist->identifier[i]); + } + else if (err > 0) + fprintf(stderr, "NVMe Status:%s(%x) cntid:%d\n", + nvme_status_to_string(err), err, defaults.cntid); + return err; +} + static int list_ns(int argc, char **argv) { int err, i; @@ -1188,7 +1228,7 @@ static int list_ns(int argc, char **argv) return err; } -static char * nvme_char_from_block(char *block) +static char *nvme_char_from_block(char *block) { char slen[16]; unsigned len; @@ -1581,7 +1621,6 @@ static int get_feature(int argc, char **argv) return err; } -#define min(x, y) x > y ? y : x; static int fw_download(int argc, char **argv) { int err, fw_fd = -1; @@ -2756,7 +2795,7 @@ static int nvme_passthru(int argc, char **argv, int ioctl_cmd) printf("cdw15 : %08x\n", cmd.cdw15); printf("timeout_ms : %08x\n", cmd.timeout_ms); if (cfg.dry_run) - return 0; + return 0; } err = ioctl(fd, ioctl_cmd, &cmd); if (err >= 0) {