Add io_uring IO interface
[linux-2.6-block.git] / include / uapi / 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;          /* as of now unused */
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           __resv;
28         };
29         __u64   user_data;      /* data to be passed back at completion time */
30         __u64   __pad2[3];
31 };
32
33 #define IORING_OP_NOP           0
34 #define IORING_OP_READV         1
35 #define IORING_OP_WRITEV        2
36
37 /*
38  * IO completion data structure (Completion Queue Entry)
39  */
40 struct io_uring_cqe {
41         __u64   user_data;      /* sqe->data submission passed back */
42         __s32   res;            /* result code for this event */
43         __u32   flags;
44 };
45
46 /*
47  * Magic offsets for the application to mmap the data it needs
48  */
49 #define IORING_OFF_SQ_RING              0ULL
50 #define IORING_OFF_CQ_RING              0x8000000ULL
51 #define IORING_OFF_SQES                 0x10000000ULL
52
53 /*
54  * Filled with the offset for mmap(2)
55  */
56 struct io_sqring_offsets {
57         __u32 head;
58         __u32 tail;
59         __u32 ring_mask;
60         __u32 ring_entries;
61         __u32 flags;
62         __u32 dropped;
63         __u32 array;
64         __u32 resv1;
65         __u64 resv2;
66 };
67
68 struct io_cqring_offsets {
69         __u32 head;
70         __u32 tail;
71         __u32 ring_mask;
72         __u32 ring_entries;
73         __u32 overflow;
74         __u32 cqes;
75         __u64 resv[2];
76 };
77
78 /*
79  * io_uring_enter(2) flags
80  */
81 #define IORING_ENTER_GETEVENTS  (1U << 0)
82
83 /*
84  * Passed in for io_uring_setup(2). Copied back with updated info on success
85  */
86 struct io_uring_params {
87         __u32 sq_entries;
88         __u32 cq_entries;
89         __u32 flags;
90         __u32 resv[7];
91         struct io_sqring_offsets sq_off;
92         struct io_cqring_offsets cq_off;
93 };
94
95 #endif