Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/libnvme-mi.map
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
LIBNVME_MI_UNRELEASED {
global:
nvme_mi_admin_abort;
};

LIBNVME_MI_1_14 {
Expand Down
2 changes: 2 additions & 0 deletions src/libnvme.map
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
LIBNVME_UNRELEASED {
global:
nvme_abort;
};

LIBNVME_1_14 {
Expand Down
18 changes: 18 additions & 0 deletions src/nvme/api-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1104,4 +1104,22 @@ struct nvme_lm_migration_recv_args {
__u8 csuidxp;
};

/**
* struct nvme_abort_args - Arguments for the NVMe Abort command
* @result: The command completion result from CQE dword0
* @args_size: Size of &struct nvme_abort_args
* @fd: File descriptor of nvme device
* @timeout: Timeout in ms
* @sqid: Submission queue identifier
* @cid: Command indentifier
*/
struct nvme_abort_args {
__u32 *result;
int args_size;
int fd;
__u32 timeout;
__u16 sqid;
__u16 cid;
};

#endif /* _LIBNVME_API_TYPES_H */
16 changes: 16 additions & 0 deletions src/nvme/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2532,3 +2532,19 @@ int nvme_lm_get_features_ctrl_data_queue(int fd, __u16 cdqid,

return nvme_get_features(&args);
}

int nvme_abort(struct nvme_abort_args *args)
{
struct nvme_passthru_cmd cmd = {
.opcode = nvme_admin_abort_cmd,
.cdw10 = NVME_SET(args->sqid, ABORT_CDW10_SQID) |
NVME_SET(args->cid, ABORT_CDW10_CID),
};

if (args->args_size < sizeof(*args)) {
errno = EINVAL;
return -1;
}

return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
}
18 changes: 18 additions & 0 deletions src/nvme/ioctl.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,15 @@ enum nvme_cmd_dword_fields {
NVME_ZNS_MGMT_RECV_ZRAS_FEAT_MASK = 0x1,
NVME_DIM_TAS_SHIFT = 0,
NVME_DIM_TAS_MASK = 0xF,
NVME_ABORT_CDW10_SQID_SHIFT = 0,
NVME_ABORT_CDW10_CID_SHIFT = 16,
NVME_ABORT_CDW10_SQID_MASK = 0xff,
NVME_ABORT_CDW10_CID_MASK = 0xff,
};

enum nvme_cqe_dword_fields {
NVME_ABORT_CQEDW0_IANP_SHIFT = 0,
NVME_ABORT_CQEDW0_IANP_MASK = 0x1,
};

/**
Expand Down Expand Up @@ -4588,4 +4597,13 @@ int nvme_lm_set_features_ctrl_data_queue(int fd, __u16 cdqid, __u32 hp, __u32 tp
int nvme_lm_get_features_ctrl_data_queue(int fd, __u16 cdqid,
struct nvme_lm_ctrl_data_queue_fid_data *data,
__u32 *result);

/**
* nvme_abort() - Submit an abort command
* @args: &struct nvme_abort_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_abort(struct nvme_abort_args *args);
#endif /* _LIBNVME_IOCTL_H */
25 changes: 25 additions & 0 deletions src/nvme/mi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2668,4 +2668,29 @@ int nvme_mi_aem_process(nvme_mi_ep_t ep, void *userdata)
return rc;
}

int nvme_mi_admin_abort(nvme_mi_ctrl_t ctrl, struct nvme_abort_args *args)
{
struct nvme_mi_admin_resp_hdr resp_hdr;
struct nvme_mi_admin_req_hdr req_hdr;
struct nvme_mi_resp resp;
struct nvme_mi_req req;
int rc;

if (args->args_size < sizeof(*args)) {
errno = EINVAL;
return -1;
}

nvme_mi_admin_init_req(ctrl->ep, &req, &req_hdr, ctrl->id, nvme_admin_abort_cmd);

req_hdr.cdw10 = NVME_SET(args->sqid, ABORT_CDW10_SQID) |
NVME_SET(args->cid, ABORT_CDW10_CID),

nvme_mi_admin_init_resp(&resp, &resp_hdr);

rc = nvme_mi_submit(ctrl->ep, &req, &resp);
if (rc)
return rc;

return nvme_mi_admin_parse_status(&resp, NULL);
}
8 changes: 8 additions & 0 deletions src/nvme/mi.h
Original file line number Diff line number Diff line change
Expand Up @@ -3559,4 +3559,12 @@ int nvme_mi_aem_disable(nvme_mi_ep_t ep);
*/
int nvme_mi_aem_process(nvme_mi_ep_t ep, void *userdata);

/**
* nvme_mi_admin_abort() - Submit an abort command
* @ctrl: Controller to send abort command to
* @args: &struct nvme_abort_args argument structure
*
* Return: 0 on success, non-zero on failure
*/
int nvme_mi_admin_abort(nvme_mi_ctrl_t ctrl, struct nvme_abort_args *args);
#endif /* _LIBNVME_MI_MI_H */