Commit | Line | Data |
---|---|---|
e2239016 JA |
1 | /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ |
2 | /* | |
3 | * Header file for the io_uring interface. | |
4 | * | |
5 | * Copyright (C) 2019 Jens Axboe | |
6 | * Copyright (C) 2019 Christoph Hellwig | |
7 | */ | |
8 | #ifndef LINUX_IO_URING_H | |
9 | #define LINUX_IO_URING_H | |
e31b8288 | 10 | |
6e70fd30 | 11 | #include <linux/fs.h> |
e2239016 | 12 | #include <linux/types.h> |
6e70fd30 | 13 | |
e31b8288 | 14 | /* |
f0403f94 | 15 | * IO submission data structure (Submission Queue Entry) |
e31b8288 | 16 | */ |
f0403f94 | 17 | struct io_uring_sqe { |
a7086591 | 18 | __u8 opcode; /* type of operation for this sqe */ |
48e698fa | 19 | __u8 flags; /* IOSQE_ flags */ |
a7086591 JA |
20 | __u16 ioprio; /* ioprio for the request */ |
21 | __s32 fd; /* file descriptor to do IO on */ | |
22 | __u64 off; /* offset into file */ | |
919850d2 | 23 | __u64 addr; /* pointer to buffer or iovecs */ |
a7086591 | 24 | __u32 len; /* buffer size or number of iovecs */ |
e31b8288 JA |
25 | union { |
26 | __kernel_rwf_t rw_flags; | |
48e698fa | 27 | __u32 fsync_flags; |
b532dd6d | 28 | __u16 poll_events; |
a819dfb6 | 29 | __u32 sync_range_flags; |
e31b8288 | 30 | }; |
48e698fa | 31 | __u64 user_data; /* data to be passed back at completion time */ |
f3e769a4 JA |
32 | union { |
33 | __u16 buf_index; /* index into fixed buffers, if used */ | |
34 | __u64 __pad2[3]; | |
35 | }; | |
e31b8288 JA |
36 | }; |
37 | ||
2ea53ca3 JA |
38 | /* |
39 | * sqe->flags | |
40 | */ | |
e9d4aa07 | 41 | #define IOSQE_FIXED_FILE (1U << 0) /* use fixed fileset */ |
a819dfb6 JA |
42 | #define IOSQE_IO_DRAIN (1U << 1) /* issue after inflight IO */ |
43 | #define IOSQE_IO_LINK (1U << 2) /* next IO depends on this one */ | |
2ea53ca3 | 44 | |
e31b8288 JA |
45 | /* |
46 | * io_uring_setup() flags | |
47 | */ | |
e9d4aa07 JA |
48 | #define IORING_SETUP_IOPOLL (1U << 0) /* io_context is polled */ |
49 | #define IORING_SETUP_SQPOLL (1U << 1) /* SQ poll thread */ | |
50 | #define IORING_SETUP_SQ_AFF (1U << 2) /* sq_thread_cpu is valid */ | |
e31b8288 | 51 | |
8025517d | 52 | #define IORING_OP_NOP 0 |
f0403f94 JA |
53 | #define IORING_OP_READV 1 |
54 | #define IORING_OP_WRITEV 2 | |
e31b8288 | 55 | #define IORING_OP_FSYNC 3 |
48e698fa JA |
56 | #define IORING_OP_READ_FIXED 4 |
57 | #define IORING_OP_WRITE_FIXED 5 | |
b532dd6d JA |
58 | #define IORING_OP_POLL_ADD 6 |
59 | #define IORING_OP_POLL_REMOVE 7 | |
a819dfb6 | 60 | #define IORING_OP_SYNC_FILE_RANGE 8 |
48e698fa JA |
61 | |
62 | /* | |
63 | * sqe->fsync_flags | |
64 | */ | |
e9d4aa07 | 65 | #define IORING_FSYNC_DATASYNC (1U << 0) |
e31b8288 JA |
66 | |
67 | /* | |
f0403f94 | 68 | * IO completion data structure (Completion Queue Entry) |
e31b8288 | 69 | */ |
f0403f94 | 70 | struct io_uring_cqe { |
48e698fa | 71 | __u64 user_data; /* sqe->data submission passed back */ |
e2239016 JA |
72 | __s32 res; /* result code for this event */ |
73 | __u32 flags; | |
e31b8288 JA |
74 | }; |
75 | ||
e31b8288 JA |
76 | /* |
77 | * Magic offsets for the application to mmap the data it needs | |
78 | */ | |
79 | #define IORING_OFF_SQ_RING 0ULL | |
80 | #define IORING_OFF_CQ_RING 0x8000000ULL | |
f0403f94 | 81 | #define IORING_OFF_SQES 0x10000000ULL |
e31b8288 JA |
82 | |
83 | /* | |
84 | * Filled with the offset for mmap(2) | |
85 | */ | |
86 | struct io_sqring_offsets { | |
e2239016 JA |
87 | __u32 head; |
88 | __u32 tail; | |
89 | __u32 ring_mask; | |
90 | __u32 ring_entries; | |
91 | __u32 flags; | |
92 | __u32 dropped; | |
93 | __u32 array; | |
66169493 JA |
94 | __u32 resv1; |
95 | __u64 resv2; | |
e31b8288 JA |
96 | }; |
97 | ||
48e698fa JA |
98 | /* |
99 | * sq_ring->flags | |
100 | */ | |
e9d4aa07 | 101 | #define IORING_SQ_NEED_WAKEUP (1U << 0) /* needs io_uring_enter wakeup */ |
e31b8288 JA |
102 | |
103 | struct io_cqring_offsets { | |
e2239016 JA |
104 | __u32 head; |
105 | __u32 tail; | |
106 | __u32 ring_mask; | |
107 | __u32 ring_entries; | |
108 | __u32 overflow; | |
f0403f94 | 109 | __u32 cqes; |
66169493 | 110 | __u64 resv[2]; |
e31b8288 JA |
111 | }; |
112 | ||
e2239016 JA |
113 | /* |
114 | * io_uring_enter(2) flags | |
115 | */ | |
e9d4aa07 JA |
116 | #define IORING_ENTER_GETEVENTS (1U << 0) |
117 | #define IORING_ENTER_SQ_WAKEUP (1U << 1) | |
e31b8288 JA |
118 | |
119 | /* | |
120 | * Passed in for io_uring_setup(2). Copied back with updated info on success | |
121 | */ | |
122 | struct io_uring_params { | |
e2239016 JA |
123 | __u32 sq_entries; |
124 | __u32 cq_entries; | |
125 | __u32 flags; | |
e9d4aa07 JA |
126 | __u32 sq_thread_cpu; |
127 | __u32 sq_thread_idle; | |
128 | __u32 resv[5]; | |
e31b8288 JA |
129 | struct io_sqring_offsets sq_off; |
130 | struct io_cqring_offsets cq_off; | |
131 | }; | |
132 | ||
2ea53ca3 JA |
133 | /* |
134 | * io_uring_register(2) opcodes and arguments | |
135 | */ | |
136 | #define IORING_REGISTER_BUFFERS 0 | |
137 | #define IORING_UNREGISTER_BUFFERS 1 | |
a7abc9fb JA |
138 | #define IORING_REGISTER_FILES 2 |
139 | #define IORING_UNREGISTER_FILES 3 | |
a819dfb6 JA |
140 | #define IORING_REGISTER_EVENTFD 4 |
141 | #define IORING_UNREGISTER_EVENTFD 5 | |
2ea53ca3 | 142 | |
e31b8288 | 143 | #endif |