io_uring: use kernel header directly
[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
16  */
17 struct io_uring_iocb {
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_FIXEDBUFS  (1 << 1)        /* IO buffers are fixed */
39 #define IORING_SETUP_SQTHREAD   (1 << 2)        /* Use SQ thread */
40 #define IORING_SETUP_SQWQ       (1 << 3)        /* Use SQ workqueue */
41 #define IORING_SETUP_SQPOLL     (1 << 4)        /* SQ thread polls */
42
43 #define IORING_OP_READ          1
44 #define IORING_OP_WRITE         2
45 #define IORING_OP_FSYNC         3
46 #define IORING_OP_FDSYNC        4
47 #define IORING_OP_READ_FIXED    5
48 #define IORING_OP_WRITE_FIXED   6
49
50 /*
51  * IO completion data structure
52  */
53 struct io_uring_event {
54         __u64   index;          /* what iocb this event came from */
55         __s32   res;            /* result code for this event */
56         __u32   flags;
57 };
58
59 /*
60  * io_uring_event->flags
61  */
62 #define IOEV_FLAG_CACHEHIT      (1 << 0)        /* IO did not hit media */
63
64 /*
65  * Magic offsets for the application to mmap the data it needs
66  */
67 #define IORING_OFF_SQ_RING              0ULL
68 #define IORING_OFF_CQ_RING              0x8000000ULL
69 #define IORING_OFF_IOCB                 0x10000000ULL
70
71 /*
72  * Filled with the offset for mmap(2)
73  */
74 struct io_sqring_offsets {
75         __u32 head;
76         __u32 tail;
77         __u32 ring_mask;
78         __u32 ring_entries;
79         __u32 flags;
80         __u32 dropped;
81         __u32 array;
82         __u32 resv[3];
83 };
84
85 #define IORING_SQ_NEED_WAKEUP   (1 << 0) /* needs io_uring_enter wakeup */
86
87 struct io_cqring_offsets {
88         __u32 head;
89         __u32 tail;
90         __u32 ring_mask;
91         __u32 ring_entries;
92         __u32 overflow;
93         __u32 events;
94         __u32 resv[4];
95 };
96
97 /*
98  * io_uring_enter(2) flags
99  */
100 #define IORING_ENTER_GETEVENTS  (1 << 0)
101
102 /*
103  * Passed in for io_uring_setup(2). Copied back with updated info on success
104  */
105 struct io_uring_params {
106         __u32 sq_entries;
107         __u32 cq_entries;
108         __u32 flags;
109         __u16 sq_thread_cpu;
110         __u16 resv[9];
111         struct io_sqring_offsets sq_off;
112         struct io_cqring_offsets cq_off;
113 };
114
115 #endif