blob: 0ec74bab8dbe1e413777d03015de3b8aefd54f20 [file] [log] [blame]
Jens Axboe2b188cc2019-01-07 10:46:33 -07001/* 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 */
17struct io_uring_sqe {
18 __u8 opcode; /* type of operation for this sqe */
Jens Axboe6b063142019-01-10 22:13:58 -070019 __u8 flags; /* IOSQE_ flags */
Jens Axboe2b188cc2019-01-07 10:46:33 -070020 __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;
Christoph Hellwigc992fe22019-01-11 09:43:02 -070027 __u32 fsync_flags;
Jens Axboe2b188cc2019-01-07 10:46:33 -070028 };
29 __u64 user_data; /* data to be passed back at completion time */
Jens Axboeedafcce2019-01-09 09:16:05 -070030 union {
31 __u16 buf_index; /* index into fixed buffers, if used */
32 __u64 __pad2[3];
33 };
Jens Axboe2b188cc2019-01-07 10:46:33 -070034};
35
Jens Axboedef596e2019-01-09 08:59:42 -070036/*
Jens Axboe6b063142019-01-10 22:13:58 -070037 * sqe->flags
38 */
39#define IOSQE_FIXED_FILE (1U << 0) /* use fixed fileset */
40
41/*
Jens Axboedef596e2019-01-09 08:59:42 -070042 * io_uring_setup() flags
43 */
44#define IORING_SETUP_IOPOLL (1U << 0) /* io_context is polled */
Jens Axboe6c271ce2019-01-10 11:22:30 -070045#define IORING_SETUP_SQPOLL (1U << 1) /* SQ poll thread */
46#define IORING_SETUP_SQ_AFF (1U << 2) /* sq_thread_cpu is valid */
Jens Axboedef596e2019-01-09 08:59:42 -070047
Jens Axboe2b188cc2019-01-07 10:46:33 -070048#define IORING_OP_NOP 0
49#define IORING_OP_READV 1
50#define IORING_OP_WRITEV 2
Christoph Hellwigc992fe22019-01-11 09:43:02 -070051#define IORING_OP_FSYNC 3
Jens Axboeedafcce2019-01-09 09:16:05 -070052#define IORING_OP_READ_FIXED 4
53#define IORING_OP_WRITE_FIXED 5
Christoph Hellwigc992fe22019-01-11 09:43:02 -070054
55/*
56 * sqe->fsync_flags
57 */
58#define IORING_FSYNC_DATASYNC (1U << 0)
Jens Axboe2b188cc2019-01-07 10:46:33 -070059
60/*
61 * IO completion data structure (Completion Queue Entry)
62 */
63struct 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 * Magic offsets for the application to mmap the data it needs
71 */
72#define IORING_OFF_SQ_RING 0ULL
73#define IORING_OFF_CQ_RING 0x8000000ULL
74#define IORING_OFF_SQES 0x10000000ULL
75
76/*
77 * Filled with the offset for mmap(2)
78 */
79struct io_sqring_offsets {
80 __u32 head;
81 __u32 tail;
82 __u32 ring_mask;
83 __u32 ring_entries;
84 __u32 flags;
85 __u32 dropped;
86 __u32 array;
87 __u32 resv1;
88 __u64 resv2;
89};
90
Jens Axboe6c271ce2019-01-10 11:22:30 -070091/*
92 * sq_ring->flags
93 */
94#define IORING_SQ_NEED_WAKEUP (1U << 0) /* needs io_uring_enter wakeup */
95
Jens Axboe2b188cc2019-01-07 10:46:33 -070096struct io_cqring_offsets {
97 __u32 head;
98 __u32 tail;
99 __u32 ring_mask;
100 __u32 ring_entries;
101 __u32 overflow;
102 __u32 cqes;
103 __u64 resv[2];
104};
105
106/*
107 * io_uring_enter(2) flags
108 */
109#define IORING_ENTER_GETEVENTS (1U << 0)
Jens Axboe6c271ce2019-01-10 11:22:30 -0700110#define IORING_ENTER_SQ_WAKEUP (1U << 1)
Jens Axboe2b188cc2019-01-07 10:46:33 -0700111
112/*
113 * Passed in for io_uring_setup(2). Copied back with updated info on success
114 */
115struct io_uring_params {
116 __u32 sq_entries;
117 __u32 cq_entries;
118 __u32 flags;
Jens Axboe6c271ce2019-01-10 11:22:30 -0700119 __u32 sq_thread_cpu;
120 __u32 sq_thread_idle;
121 __u32 resv[5];
Jens Axboe2b188cc2019-01-07 10:46:33 -0700122 struct io_sqring_offsets sq_off;
123 struct io_cqring_offsets cq_off;
124};
125
Jens Axboeedafcce2019-01-09 09:16:05 -0700126/*
127 * io_uring_register(2) opcodes and arguments
128 */
129#define IORING_REGISTER_BUFFERS 0
130#define IORING_UNREGISTER_BUFFERS 1
Jens Axboe6b063142019-01-10 22:13:58 -0700131#define IORING_REGISTER_FILES 2
132#define IORING_UNREGISTER_FILES 3
Jens Axboeedafcce2019-01-09 09:16:05 -0700133
Jens Axboe2b188cc2019-01-07 10:46:33 -0700134#endif