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