Update to newer io_uring API
[fio.git] / os / io_uring.h
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
10
11 #include <linux/fs.h>
12 #include <linux/types.h>
13
14 /*
15  * IO submission data structure (Submission Queue Entry)
16  */
17 struct io_uring_sqe {
18         __u8    opcode;
19         __u8    flags;
20         __u16   ioprio;
21         __s32   fd;
22         __u64   off;
23         union {
24                 void    *addr;
25                 __u64   __pad;
26         };
27         __u32   len;
28         union {
29                 __kernel_rwf_t  rw_flags;
30                 __u32           __resv;
31         };
32 };
33
34 /*
35  * io_uring_setup() flags
36  */
37 #define IORING_SETUP_IOPOLL     (1 << 0)        /* io_context is polled */
38 #define IORING_SETUP_SQTHREAD   (1 << 1)        /* Use SQ thread */
39 #define IORING_SETUP_SQWQ       (1 << 2)        /* Use SQ workqueue */
40 #define IORING_SETUP_SQPOLL     (1 << 3)        /* SQ thread polls */
41
42 #define IORING_OP_READV         1
43 #define IORING_OP_WRITEV        2
44 #define IORING_OP_FSYNC         3
45 #define IORING_OP_FDSYNC        4
46 #define IORING_OP_READ_FIXED    5
47 #define IORING_OP_WRITE_FIXED   6
48
49 /*
50  * IO completion data structure (Completion Queue Entry)
51  */
52 struct io_uring_cqe {
53         __u64   index;          /* what sqe this event came from */
54         __s32   res;            /* result code for this event */
55         __u32   flags;
56 };
57
58 /*
59  * io_uring_event->flags
60  */
61 #define IOCQE_FLAG_CACHEHIT     (1 << 0)        /* IO did not hit media */
62
63 /*
64  * Magic offsets for the application to mmap the data it needs
65  */
66 #define IORING_OFF_SQ_RING              0ULL
67 #define IORING_OFF_CQ_RING              0x8000000ULL
68 #define IORING_OFF_SQES                 0x10000000ULL
69
70 /*
71  * Filled with the offset for mmap(2)
72  */
73 struct io_sqring_offsets {
74         __u32 head;
75         __u32 tail;
76         __u32 ring_mask;
77         __u32 ring_entries;
78         __u32 flags;
79         __u32 dropped;
80         __u32 array;
81         __u32 resv[3];
82 };
83
84 #define IORING_SQ_NEED_WAKEUP   (1 << 0) /* needs io_uring_enter wakeup */
85
86 struct io_cqring_offsets {
87         __u32 head;
88         __u32 tail;
89         __u32 ring_mask;
90         __u32 ring_entries;
91         __u32 overflow;
92         __u32 cqes;
93         __u32 resv[4];
94 };
95
96 /*
97  * io_uring_enter(2) flags
98  */
99 #define IORING_ENTER_GETEVENTS  (1 << 0)
100
101 /*
102  * Passed in for io_uring_setup(2). Copied back with updated info on success
103  */
104 struct io_uring_params {
105         __u32 sq_entries;
106         __u32 cq_entries;
107         __u32 flags;
108         __u16 sq_thread_cpu;
109         __u16 resv[9];
110         struct io_sqring_offsets sq_off;
111         struct io_cqring_offsets cq_off;
112 };
113
114 #endif