From: Guan Junxiong Date: Wed, 13 Dec 2017 02:11:31 +0000 (+0800) Subject: nvme-cli: support to set the property for NVMe over Fabric X-Git-Tag: v1.5~9 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=33977713162e633ac4b3838b4aefa487a9898b44;p=users%2Fsagi%2Fnvme-cli.git nvme-cli: support to set the property for NVMe over Fabric Signed-off-by: Guan Junxiong --- diff --git a/Documentation/nvme-set-property.1 b/Documentation/nvme-set-property.1 new file mode 100644 index 00000000..0ade1089 --- /dev/null +++ b/Documentation/nvme-set-property.1 @@ -0,0 +1,51 @@ +'\" t +.\" Title: nvme-set-property +.\" Author: [FIXME: author] [see http://docbook.sf.net/el/author] +.\" Generator: DocBook XSL Stylesheets v1.78.1 +.\" Date: 06/28/2017 +.\" Manual: NVMe Manual +.\" Source: NVMe +.\" Language: English +.\" +.TH "NVME\-SET\-PROPERTY" "1" "11/24/2017" "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-set-propery \- Writes and shows the defined NVMe controller property for NVMe ove Fabric +.SH "SYNOPSIS" +.sp +.nf +\fInvme set\-property\fR [\-\-offset= | \-n ] + [\-\-value= | \-v ] +.fi +.SH "DESCRIPTION" +.sp +Writes and shows the defined NVMe controller property for NVMe ove Fabric\&. Please use it carefully\&. +.SH "OPTIONS" +.PP +\-o , \-\-offset= +.RS 4 +The offset of the property\&. +.RE +.SH "EXAMPLES" +.RE +.SH "NVME" +.sp +Part of the nvme\-user suite diff --git a/Documentation/nvme-set-property.html b/Documentation/nvme-set-property.html new file mode 100644 index 00000000..f1299379 --- /dev/null +++ b/Documentation/nvme-set-property.html @@ -0,0 +1,814 @@ + + + + + +nvme-set-property(1) + + + + + +
+
+

SYNOPSIS

+
+
+
nvme set-property <device> [--offset=<offset> | -o <offset> ]
+	 					[--value=<val> | -v <val> ]
+
+
+
+
+
+

DESCRIPTION

+
+

Writes and shows the defined NVMe controller property for NVMe ove Fabric.

+
+
+
+

OPTIONS

+
+
+
+-o +
+
+--offset +
+
+

+ The offset of the property +

+
+
+
+-v +
+
+--value +
+
+

+ The value of the property to be set +

+
+
+
+
+
+

EXAMPLES

+
+
    +
  • +
    +
    +
    +
    +
    +

    NVME

    +
    +

    Part of the nvme-user suite

    +
    +
    +
+

+ + + diff --git a/Documentation/nvme-set-property.txt b/Documentation/nvme-set-property.txt new file mode 100644 index 00000000..7c490588 --- /dev/null +++ b/Documentation/nvme-set-property.txt @@ -0,0 +1,34 @@ +nvme-set-property(1) +============= + +NAME +---- +nvme-set-property - Writes and shows the defined NVMe controller property +for NVMe ove Fabric + +SYNOPSIS +-------- +[verse] +'nvme set-property' [--offset= | -o ] [--value= | -v ] + + +DESCRIPTION +----------- +Writes and shows the defined NVMe controller property for NVMe ove Fabric + +OPTIONS +------- +-o:: +--offset:: + The offset of the property + +-v:: +--value: + The value of the property to be set + +EXAMPLES +-------- + +NVME +---- +Part of the nvme-user suite diff --git a/nvme-builtin.h b/nvme-builtin.h index 14c449b9..b0eb5339 100644 --- a/nvme-builtin.h +++ b/nvme-builtin.h @@ -25,6 +25,7 @@ COMMAND_LIST( ENTRY("effects-log", "Retrieve Command Effects Log, show it", get_effects_log) ENTRY("get-feature", "Get feature and show the resulting value", get_feature) ENTRY("set-feature", "Set a feature and show the resulting value", set_feature) + ENTRY("set-property", "Set a property and show the resulting value", set_property) ENTRY("format", "Format namespace with new block format", format) ENTRY("fw-activate", "Activate new firmware slot", fw_activate) ENTRY("fw-download", "Download new firmware", fw_download) diff --git a/nvme-ioctl.c b/nvme-ioctl.c index ae6d724c..f735eccf 100644 --- a/nvme-ioctl.c +++ b/nvme-ioctl.c @@ -526,6 +526,26 @@ int nvme_get_properties(int fd, void **pbar) return ret; } +int nvme_set_property(int fd, int offset, int value) +{ + __le64 val = cpu_to_le64(value); + __le32 off = cpu_to_le32(offset); + bool is64bit; + + switch (off) { + case NVME_REG_CAP: + case NVME_REG_ASQ: + case NVME_REG_ACQ: + is64bit = true; + break; + default: + is64bit = false; + } + + return nvme_property(fd, nvme_fabrics_type_property_set, + off, &val, is64bit ? 1: 0); +} + int nvme_get_feature(int fd, __u32 nsid, __u8 fid, __u8 sel, __u32 cdw11, __u32 data_len, void *data, __u32 *result) { diff --git a/nvme-ioctl.h b/nvme-ioctl.h index 90e2e181..7cc80c88 100644 --- a/nvme-ioctl.h +++ b/nvme-ioctl.h @@ -122,5 +122,6 @@ int nvme_dir_send(int fd, __u32 nsid, __u16 dspec, __u8 dtype, __u8 doper, int nvme_dir_recv(int fd, __u32 nsid, __u16 dspec, __u8 dtype, __u8 doper, __u32 data_len, __u32 dw12, void *data, __u32 *result); int nvme_get_properties(int fd, void **pbar); +int nvme_set_property(int fd, int offset, int value); #endif /* _NVME_LIB_H */ diff --git a/nvme-print.c b/nvme-print.c index 382c832c..87f0766d 100644 --- a/nvme-print.c +++ b/nvme-print.c @@ -1125,6 +1125,25 @@ char *nvme_feature_to_string(int feature) } } +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"; + } +} + char* nvme_select_to_string(int sel) { switch (sel) { diff --git a/nvme-print.h b/nvme-print.h index 525d551f..926c196f 100644 --- a/nvme-print.h +++ b/nvme-print.h @@ -34,6 +34,7 @@ void nvme_directive_show_fields(__u8 dtype, __u8 doper, unsigned int result, uns char *nvme_status_to_string(__u32 status); char *nvme_select_to_string(int sel); char *nvme_feature_to_string(int feature); +char *nvme_register_to_string(int reg); 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); diff --git a/nvme.c b/nvme.c index d792c299..4b0b8616 100644 --- a/nvme.c +++ b/nvme.c @@ -2037,6 +2037,58 @@ static int show_registers(int argc, char **argv, struct command *cmd, struct plu return 0; } +static int set_property(int argc, char **argv, struct command *cmd, struct plugin *plugin) +{ + const char *desc = "Writes and shows the defined NVMe controller property "\ + "for NVMe ove Fabric"; + const char *offset = "the offset of the property"; + const char *value = "the value of the property to be set"; + int fd, err; + + struct config { + int offset; + int value; + }; + + struct config cfg = { + .offset = -1, + .value = -1, + }; + + const struct argconfig_commandline_options command_line_options[] = { + {"offset", 'o', "NUM", CFG_POSITIVE, &cfg.offset, required_argument, offset}, + {"value", 'v', "NUM", CFG_POSITIVE, &cfg.value, required_argument, value}, + {NULL} + }; + + fd = parse_and_open(argc, argv, desc, command_line_options, &cfg, sizeof(cfg)); + if (fd < 0) + return fd; + + if (cfg.offset == -1) { + fprintf(stderr, "offset required param"); + return EINVAL; + } + if (cfg.value == -1) { + fprintf(stderr, "value required param"); + return EINVAL; + } + + err = nvme_set_property(fd, cfg.offset, cfg.value); + if (err < 0) { + perror("set-property"); + return errno; + } else if (!err) { + printf("set-property: %02x (%s), value: %#08x\n", cfg.offset, + nvme_register_to_string(cfg.offset), cfg.value); + } else if (err > 0) { + fprintf(stderr, "NVMe Status: %s(%x)\n", + nvme_status_to_string(err), err); + } + + return err; +} + static int format(int argc, char **argv, struct command *cmd, struct plugin *plugin) { const char *desc = "Re-format a specified namespace on the "\