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 */ | |
e31b8288 | 23 | union { |
a7086591 | 24 | void *addr; /* buffer or iovecs */ |
e2239016 | 25 | __u64 __pad; |
e31b8288 | 26 | }; |
a7086591 | 27 | __u32 len; /* buffer size or number of iovecs */ |
e31b8288 JA |
28 | union { |
29 | __kernel_rwf_t rw_flags; | |
48e698fa | 30 | __u32 fsync_flags; |
e31b8288 | 31 | }; |
48e698fa | 32 | __u64 user_data; /* data to be passed back at completion time */ |
f3e769a4 JA |
33 | union { |
34 | __u16 buf_index; /* index into fixed buffers, if used */ | |
35 | __u64 __pad2[3]; | |
36 | }; | |
e31b8288 JA |
37 | }; |
38 | ||
2ea53ca3 JA |
39 | /* |
40 | * sqe->flags | |
41 | */ | |
48e698fa | 42 | #define IOSQE_FIXED_FILE (1 << 0) /* use fixed fileset */ |
2ea53ca3 | 43 | |
e31b8288 JA |
44 | /* |
45 | * io_uring_setup() flags | |
46 | */ | |
47 | #define IORING_SETUP_IOPOLL (1 << 0) /* io_context is polled */ | |
2ea53ca3 JA |
48 | #define IORING_SETUP_SQPOLL (1 << 1) /* SQ poll thread */ |
49 | #define IORING_SETUP_SQ_AFF (1 << 2) /* sq_thread_cpu is valid */ | |
e31b8288 | 50 | |
8025517d | 51 | #define IORING_OP_NOP 0 |
f0403f94 JA |
52 | #define IORING_OP_READV 1 |
53 | #define IORING_OP_WRITEV 2 | |
e31b8288 | 54 | #define IORING_OP_FSYNC 3 |
48e698fa JA |
55 | #define IORING_OP_READ_FIXED 4 |
56 | #define IORING_OP_WRITE_FIXED 5 | |
57 | ||
58 | /* | |
59 | * sqe->fsync_flags | |
60 | */ | |
61 | #define IORING_FSYNC_DATASYNC (1 << 0) | |
e31b8288 JA |
62 | |
63 | /* | |
f0403f94 | 64 | * IO completion data structure (Completion Queue Entry) |
e31b8288 | 65 | */ |
f0403f94 | 66 | struct io_uring_cqe { |
48e698fa | 67 | __u64 user_data; /* sqe->data submission passed back */ |
e2239016 JA |
68 | __s32 res; /* result code for this event */ |
69 | __u32 flags; | |
e31b8288 JA |
70 | }; |
71 | ||
e2239016 JA |
72 | /* |
73 | * io_uring_event->flags | |
74 | */ | |
f0403f94 | 75 | #define IOCQE_FLAG_CACHEHIT (1 << 0) /* IO did not hit media */ |
e31b8288 JA |
76 | |
77 | /* | |
78 | * Magic offsets for the application to mmap the data it needs | |
79 | */ | |
80 | #define IORING_OFF_SQ_RING 0ULL | |
81 | #define IORING_OFF_CQ_RING 0x8000000ULL | |
f0403f94 | 82 | #define IORING_OFF_SQES 0x10000000ULL |
e31b8288 JA |
83 | |
84 | /* | |
85 | * Filled with the offset for mmap(2) | |
86 | */ | |
87 | struct io_sqring_offsets { | |
e2239016 JA |
88 | __u32 head; |
89 | __u32 tail; | |
90 | __u32 ring_mask; | |
91 | __u32 ring_entries; | |
92 | __u32 flags; | |
93 | __u32 dropped; | |
94 | __u32 array; | |
95 | __u32 resv[3]; | |
e31b8288 JA |
96 | }; |
97 | ||
48e698fa JA |
98 | /* |
99 | * sq_ring->flags | |
100 | */ | |
e31b8288 JA |
101 | #define IORING_SQ_NEED_WAKEUP (1 << 0) /* needs io_uring_enter wakeup */ |
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; |
e2239016 | 110 | __u32 resv[4]; |
e31b8288 JA |
111 | }; |
112 | ||
e2239016 JA |
113 | /* |
114 | * io_uring_enter(2) flags | |
115 | */ | |
e31b8288 JA |
116 | #define IORING_ENTER_GETEVENTS (1 << 0) |
117 | ||
118 | /* | |
119 | * Passed in for io_uring_setup(2). Copied back with updated info on success | |
120 | */ | |
121 | struct io_uring_params { | |
e2239016 JA |
122 | __u32 sq_entries; |
123 | __u32 cq_entries; | |
124 | __u32 flags; | |
125 | __u16 sq_thread_cpu; | |
126 | __u16 resv[9]; | |
e31b8288 JA |
127 | struct io_sqring_offsets sq_off; |
128 | struct io_cqring_offsets cq_off; | |
129 | }; | |
130 | ||
2ea53ca3 JA |
131 | /* |
132 | * io_uring_register(2) opcodes and arguments | |
133 | */ | |
134 | #define IORING_REGISTER_BUFFERS 0 | |
135 | #define IORING_UNREGISTER_BUFFERS 1 | |
a7abc9fb JA |
136 | #define IORING_REGISTER_FILES 2 |
137 | #define IORING_UNREGISTER_FILES 3 | |
2ea53ca3 JA |
138 | |
139 | struct io_uring_register_buffers { | |
140 | struct iovec *iovecs; | |
48e698fa | 141 | __u32 nr_iovecs; |
2ea53ca3 JA |
142 | }; |
143 | ||
a7abc9fb | 144 | struct io_uring_register_files { |
48e698fa JA |
145 | __s32 *fds; |
146 | __u32 nr_fds; | |
a7abc9fb JA |
147 | }; |
148 | ||
e31b8288 | 149 | #endif |