From: Martin Belanger Date: Fri, 18 Feb 2022 09:07:11 +0000 (+0100) Subject: ioctl: Add nvme_dim_send() X-Git-Tag: v1.0-rc4~5^2~1 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=b9d6b333a4dc5d6b510120b41ff6d844ec053c58;p=users%2Fsagi%2Flibnvme.git ioctl: Add nvme_dim_send() Add nvme_dim_send() to send Discovery Information Managements commands. Signed-off-by: Martin Belanger [dwagner: reorder args arguments, rename function] Signed-off-by: Daniel Wagner --- diff --git a/src/libnvme.map b/src/libnvme.map index 7d1e5470..5828c3b9 100644 --- a/src/libnvme.map +++ b/src/libnvme.map @@ -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; diff --git a/src/nvme/ioctl.c b/src/nvme/ioctl.c index 8ece9e1d..fc266da3 100644 --- a/src/nvme/ioctl.c +++ b/src/nvme/ioctl.c @@ -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); +} diff --git a/src/nvme/ioctl.h b/src/nvme/ioctl.h index 6b92690c..c4db5e8a 100644 --- a/src/nvme/ioctl.h +++ b/src/nvme/ioctl.h @@ -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 */