]> www.infradead.org Git - users/sagi/libnvme.git/commitdiff
ioctl: Add nvme_dim_send()
authorMartin Belanger <martin.belanger@dell.com>
Fri, 18 Feb 2022 09:07:11 +0000 (10:07 +0100)
committerDaniel Wagner <dwagner@suse.de>
Mon, 21 Feb 2022 16:03:12 +0000 (17:03 +0100)
Add nvme_dim_send() to send Discovery Information Managements commands.

Signed-off-by: Martin Belanger <martin.belanger@dell.com>
[dwagner: reorder args arguments, rename function]
Signed-off-by: Daniel Wagner <dwagner@suse.de>
src/libnvme.map
src/nvme/ioctl.c
src/nvme/ioctl.h

index 7d1e5470f6801a811b5b1596d070a17c920982e4..5828c3b929d9a8ac2a58ba95b06c049dbfc39ad7 100644 (file)
@@ -42,6 +42,7 @@ LIBNVME_1_0 {
                nvme_ctrls_filter;
                nvme_default_host;
                nvme_dev_self_test;
+               nvme_dim_send;
                nvme_directive_recv;
                nvme_directive_recv_identify_parameters;
                nvme_directive_recv_stream_allocate;
index 8ece9e1d78bb3b08a66f44a2faf487bc328e443a..fc266da3daddc361ded94416b5f11cdee91f82ae 100644 (file)
@@ -306,6 +306,8 @@ enum nvme_cmd_dword_fields {
        NVME_ZNS_MGMT_RECV_ZRASF_MASK                           = 0xff,
        NVME_ZNS_MGMT_RECV_ZRAS_FEAT_SHIFT                      = 16,
        NVME_ZNS_MGMT_RECV_ZRAS_FEAT_MASK                       = 0x1,
+       NVME_DIM_TAS_SHIFT                                      = 0,
+       NVME_DIM_TAS_MASK                                       = 0xF,
 };
 
 enum features {
@@ -1842,3 +1844,23 @@ int nvme_zns_append(struct nvme_zns_append_args *args)
        }
        return nvme_submit_io_passthru64(args->fd, &cmd, args->result);
 }
+
+int nvme_dim_send(struct nvme_dim_args *args)
+{
+       __u32 cdw10 = NVME_SET(args->tas, DIM_TAS);
+
+       struct nvme_passthru_cmd  cmd = {
+               .opcode     = nvme_admin_discovery_info_mgmt,
+               .cdw10      = cdw10,
+               .addr       = (__u64)(uintptr_t)args->data,
+               .data_len   = args->data_len,
+               .timeout_ms = args->timeout,
+       };
+
+       if (args->args_size < sizeof(*args)) {
+               errno = EINVAL;
+               return -1;
+       }
+
+       return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
+}
index 6b92690ccbf1299fbbb791fe8f5a40105151effa..c4db5e8a2a19cf61d99febfe7bcfa984e70fcca3 100644 (file)
@@ -4346,4 +4346,33 @@ struct nvme_zns_append_args {
  */
 int nvme_zns_append(struct nvme_zns_append_args *args);
 
+/**
+ * struct nvme_dim_args - Arguments for the Discovery Information Management (DIM) command
+ * @result:    Set on completion to the command's CQE DWORD 0 controller response.
+ * @data:      Pointer to the DIM data
+ * @args_size: Length of the structure
+ * @fd:                File descriptor of nvme device
+ * @timeout:   Timeout in ms
+ * @data_len:  Length of @data
+ * @tas:       Task field of the Command Dword 10 (cdw10)
+ */
+struct nvme_dim_args {
+       __u32   *result;
+       void    *data;
+       int     args_size;
+       int     fd;
+       __u32   timeout;
+       __u32   data_len;
+       __u8    tas;
+} __attribute__((packed, aligned(__alignof__(__u32*))));
+
+/**
+ * nvme_dim_send - Send a Discovery Information Management (DIM) command
+ * @args:      &struct nvme_dim_args argument structure
+ *
+ * Return: The nvme command status if a response was received (see
+ * &enum nvme_status_field) or -1 with errno set otherwise.
+ */
+int nvme_dim_send(struct nvme_dim_args *args);
+
 #endif /* _LIBNVME_IOCTL_H */