1
2
3
4
5#ifndef __LINUX_BLK_TYPES_H
6#define __LINUX_BLK_TYPES_H
7
8#include <linux/types.h>
9#include <linux/bvec.h>
10
11struct bio_set;
12struct bio;
13struct bio_integrity_payload;
14struct page;
15struct block_device;
16struct io_context;
17struct cgroup_subsys_state;
18typedef void (bio_end_io_t) (struct bio *);
19
20struct blk_issue_stat {
21 u64 stat;
22};
23
24
25
26
27
28struct bio {
29 struct bio *bi_next;
30 struct block_device *bi_bdev;
31 int bi_error;
32 unsigned int bi_opf;
33
34
35
36 unsigned short bi_flags;
37 unsigned short bi_ioprio;
38
39 struct bvec_iter bi_iter;
40
41
42
43
44 unsigned int bi_phys_segments;
45
46
47
48
49
50 unsigned int bi_seg_front_size;
51 unsigned int bi_seg_back_size;
52
53 atomic_t __bi_remaining;
54
55 bio_end_io_t *bi_end_io;
56
57 void *bi_private;
58#ifdef CONFIG_BLK_CGROUP
59
60
61
62
63 struct io_context *bi_ioc;
64 struct cgroup_subsys_state *bi_css;
65#ifdef CONFIG_BLK_DEV_THROTTLING_LOW
66 void *bi_cg_private;
67 struct blk_issue_stat bi_issue_stat;
68#endif
69#endif
70 union {
71#if defined(CONFIG_BLK_DEV_INTEGRITY)
72 struct bio_integrity_payload *bi_integrity;
73#endif
74 };
75
76 unsigned short bi_vcnt;
77
78
79
80
81
82 unsigned short bi_max_vecs;
83
84 atomic_t __bi_cnt;
85
86 struct bio_vec *bi_io_vec;
87
88 struct bio_set *bi_pool;
89
90
91
92
93
94
95 struct bio_vec bi_inline_vecs[0];
96};
97
98#define BIO_RESET_BYTES offsetof(struct bio, bi_max_vecs)
99
100
101
102
103#define BIO_SEG_VALID 1
104#define BIO_CLONED 2
105#define BIO_BOUNCED 3
106#define BIO_USER_MAPPED 4
107#define BIO_NULL_MAPPED 5
108#define BIO_QUIET 6
109#define BIO_CHAIN 7
110#define BIO_REFFED 8
111#define BIO_THROTTLED 9
112
113#define BIO_TRACE_COMPLETION 10
114
115
116
117
118
119
120
121#define BVEC_POOL_NR 6
122#define BVEC_POOL_MAX (BVEC_POOL_NR - 1)
123
124
125
126
127
128
129#define BVEC_POOL_BITS (3)
130#define BVEC_POOL_OFFSET (16 - BVEC_POOL_BITS)
131#define BVEC_POOL_IDX(bio) ((bio)->bi_flags >> BVEC_POOL_OFFSET)
132#if (1<< BVEC_POOL_BITS) < (BVEC_POOL_NR+1)
133# error "BVEC_POOL_BITS is too small"
134#endif
135
136
137
138
139
140#define BIO_RESET_BITS BVEC_POOL_OFFSET
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155#define REQ_OP_BITS 8
156#define REQ_OP_MASK ((1 << REQ_OP_BITS) - 1)
157#define REQ_FLAG_BITS 24
158
159enum req_opf {
160
161 REQ_OP_READ = 0,
162
163 REQ_OP_WRITE = 1,
164
165 REQ_OP_FLUSH = 2,
166
167 REQ_OP_DISCARD = 3,
168
169 REQ_OP_ZONE_REPORT = 4,
170
171 REQ_OP_SECURE_ERASE = 5,
172
173 REQ_OP_ZONE_RESET = 6,
174
175 REQ_OP_WRITE_SAME = 7,
176
177 REQ_OP_WRITE_ZEROES = 9,
178
179
180 REQ_OP_SCSI_IN = 32,
181 REQ_OP_SCSI_OUT = 33,
182
183 REQ_OP_DRV_IN = 34,
184 REQ_OP_DRV_OUT = 35,
185
186 REQ_OP_LAST,
187};
188
189enum req_flag_bits {
190 __REQ_FAILFAST_DEV =
191 REQ_OP_BITS,
192 __REQ_FAILFAST_TRANSPORT,
193 __REQ_FAILFAST_DRIVER,
194 __REQ_SYNC,
195 __REQ_META,
196 __REQ_PRIO,
197 __REQ_NOMERGE,
198 __REQ_IDLE,
199 __REQ_INTEGRITY,
200 __REQ_FUA,
201 __REQ_PREFLUSH,
202 __REQ_RAHEAD,
203 __REQ_BACKGROUND,
204
205
206 __REQ_NOUNMAP,
207
208 __REQ_NR_BITS,
209};
210
211#define REQ_FAILFAST_DEV (1ULL << __REQ_FAILFAST_DEV)
212#define REQ_FAILFAST_TRANSPORT (1ULL << __REQ_FAILFAST_TRANSPORT)
213#define REQ_FAILFAST_DRIVER (1ULL << __REQ_FAILFAST_DRIVER)
214#define REQ_SYNC (1ULL << __REQ_SYNC)
215#define REQ_META (1ULL << __REQ_META)
216#define REQ_PRIO (1ULL << __REQ_PRIO)
217#define REQ_NOMERGE (1ULL << __REQ_NOMERGE)
218#define REQ_IDLE (1ULL << __REQ_IDLE)
219#define REQ_INTEGRITY (1ULL << __REQ_INTEGRITY)
220#define REQ_FUA (1ULL << __REQ_FUA)
221#define REQ_PREFLUSH (1ULL << __REQ_PREFLUSH)
222#define REQ_RAHEAD (1ULL << __REQ_RAHEAD)
223#define REQ_BACKGROUND (1ULL << __REQ_BACKGROUND)
224
225#define REQ_NOUNMAP (1ULL << __REQ_NOUNMAP)
226
227#define REQ_FAILFAST_MASK \
228 (REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER)
229
230#define REQ_NOMERGE_FLAGS \
231 (REQ_NOMERGE | REQ_PREFLUSH | REQ_FUA)
232
233#define bio_op(bio) \
234 ((bio)->bi_opf & REQ_OP_MASK)
235#define req_op(req) \
236 ((req)->cmd_flags & REQ_OP_MASK)
237
238
239static inline void bio_set_op_attrs(struct bio *bio, unsigned op,
240 unsigned op_flags)
241{
242 bio->bi_opf = op | op_flags;
243}
244
245static inline bool op_is_write(unsigned int op)
246{
247 return (op & 1);
248}
249
250
251
252
253
254static inline bool op_is_flush(unsigned int op)
255{
256 return op & (REQ_FUA | REQ_PREFLUSH);
257}
258
259
260
261
262
263
264static inline bool op_is_sync(unsigned int op)
265{
266 return (op & REQ_OP_MASK) == REQ_OP_READ ||
267 (op & (REQ_SYNC | REQ_FUA | REQ_PREFLUSH));
268}
269
270typedef unsigned int blk_qc_t;
271#define BLK_QC_T_NONE -1U
272#define BLK_QC_T_SHIFT 16
273#define BLK_QC_T_INTERNAL (1U << 31)
274
275static inline bool blk_qc_t_valid(blk_qc_t cookie)
276{
277 return cookie != BLK_QC_T_NONE;
278}
279
280static inline blk_qc_t blk_tag_to_qc_t(unsigned int tag, unsigned int queue_num,
281 bool internal)
282{
283 blk_qc_t ret = tag | (queue_num << BLK_QC_T_SHIFT);
284
285 if (internal)
286 ret |= BLK_QC_T_INTERNAL;
287
288 return ret;
289}
290
291static inline unsigned int blk_qc_t_to_queue_num(blk_qc_t cookie)
292{
293 return (cookie & ~BLK_QC_T_INTERNAL) >> BLK_QC_T_SHIFT;
294}
295
296static inline unsigned int blk_qc_t_to_tag(blk_qc_t cookie)
297{
298 return cookie & ((1u << BLK_QC_T_SHIFT) - 1);
299}
300
301static inline bool blk_qc_t_is_internal(blk_qc_t cookie)
302{
303 return (cookie & BLK_QC_T_INTERNAL) != 0;
304}
305
306struct blk_rq_stat {
307 s64 mean;
308 u64 min;
309 u64 max;
310 s32 nr_samples;
311 s32 nr_batch;
312 u64 batch;
313};
314
315#endif
316