Skip to content

Commit 34b8d86

Browse files
committed
ioctl: add nvme_abort() function
This is support for the abort command. Signed-off-by: Tokunori Ikegami <[email protected]>
1 parent 846d61c commit 34b8d86

4 files changed

Lines changed: 54 additions & 0 deletions

File tree

src/libnvme.map

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# SPDX-License-Identifier: LGPL-2.1-or-later
22
LIBNVME_UNRELEASED {
3+
global:
4+
nvme_abort;
35
};
46

57
LIBNVME_1_14 {

src/nvme/api-types.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,4 +1104,22 @@ struct nvme_lm_migration_recv_args {
11041104
__u8 csuidxp;
11051105
};
11061106

1107+
/**
1108+
* struct nvme_abort_args - Arguments for the NVMe Abort command
1109+
* @result: The command completion result from CQE dword0
1110+
* @args_size: Size of &struct nvme_abort_args
1111+
* @fd: File descriptor of nvme device
1112+
* @timeout: Timeout in ms
1113+
* @sqid: Submission queue identifier
1114+
* @cid: Command indentifier
1115+
*/
1116+
struct nvme_abort_args {
1117+
__u32 *result;
1118+
int args_size;
1119+
int fd;
1120+
__u32 timeout;
1121+
__u16 sqid;
1122+
__u16 cid;
1123+
};
1124+
11071125
#endif /* _LIBNVME_API_TYPES_H */

src/nvme/ioctl.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,3 +2532,19 @@ int nvme_lm_get_features_ctrl_data_queue(int fd, __u16 cdqid,
25322532

25332533
return nvme_get_features(&args);
25342534
}
2535+
2536+
int nvme_abort(struct nvme_abort_args *args)
2537+
{
2538+
struct nvme_passthru_cmd cmd = {
2539+
.opcode = nvme_admin_abort_cmd,
2540+
.cdw10 = NVME_SET(args->sqid, ABORT_CDW10_SQID) |
2541+
NVME_SET(args->cid, ABORT_CDW10_CID),
2542+
};
2543+
2544+
if (args->args_size < sizeof(*args)) {
2545+
errno = EINVAL;
2546+
return -1;
2547+
}
2548+
2549+
return nvme_submit_admin_passthru(args->fd, &cmd, args->result);
2550+
}

src/nvme/ioctl.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,15 @@ enum nvme_cmd_dword_fields {
326326
NVME_ZNS_MGMT_RECV_ZRAS_FEAT_MASK = 0x1,
327327
NVME_DIM_TAS_SHIFT = 0,
328328
NVME_DIM_TAS_MASK = 0xF,
329+
NVME_ABORT_CDW10_SQID_SHIFT = 0,
330+
NVME_ABORT_CDW10_CID_SHIFT = 16,
331+
NVME_ABORT_CDW10_SQID_MASK = 0xff,
332+
NVME_ABORT_CDW10_CID_MASK = 0xff,
333+
};
334+
335+
enum nvme_cqe_dword_fields {
336+
NVME_ABORT_CQEDW0_IANP_SHIFT = 0,
337+
NVME_ABORT_CQEDW0_IANP_MASK = 0x1,
329338
};
330339

331340
/**
@@ -4588,4 +4597,13 @@ int nvme_lm_set_features_ctrl_data_queue(int fd, __u16 cdqid, __u32 hp, __u32 tp
45884597
int nvme_lm_get_features_ctrl_data_queue(int fd, __u16 cdqid,
45894598
struct nvme_lm_ctrl_data_queue_fid_data *data,
45904599
__u32 *result);
4600+
4601+
/**
4602+
* nvme_abort() - Submit an abort command
4603+
* @args: &struct nvme_abort_args argument structure
4604+
*
4605+
* Return: The nvme command status if a response was received (see
4606+
* &enum nvme_status_field) or -1 with errno set otherwise.
4607+
*/
4608+
int nvme_abort(struct nvme_abort_args *args);
45914609
#endif /* _LIBNVME_IOCTL_H */

0 commit comments

Comments
 (0)