1
2
3
4
5
6#ifndef __LINUX_BLK_TYPES_H
7#define __LINUX_BLK_TYPES_H
8
9#include <linux/types.h>
10#include <linux/bvec.h>
11#include <linux/device.h>
12#include <linux/ktime.h>
13
14struct bio_set;
15struct bio;
16struct bio_integrity_payload;
17struct page;
18struct io_context;
19struct cgroup_subsys_state;
20typedef void (bio_end_io_t) (struct bio *);
21struct bio_crypt_ctx;
22
23struct block_device {
24 sector_t bd_start_sect;
25 struct disk_stats __percpu *bd_stats;
26 unsigned long bd_stamp;
27 bool bd_read_only;
28 dev_t bd_dev;
29 int bd_openers;
30 struct inode * bd_inode;
31 struct super_block * bd_super;
32 void * bd_claiming;
33 struct device bd_device;
34 void * bd_holder;
35 int bd_holders;
36 bool bd_write_holder;
37 struct kobject *bd_holder_dir;
38 u8 bd_partno;
39 spinlock_t bd_size_lock;
40 struct gendisk * bd_disk;
41
42
43 int bd_fsfreeze_count;
44
45 struct mutex bd_fsfreeze_mutex;
46 struct super_block *bd_fsfreeze_sb;
47
48 struct partition_meta_info *bd_meta_info;
49#ifdef CONFIG_FAIL_MAKE_REQUEST
50 bool bd_make_it_fail;
51#endif
52} __randomize_layout;
53
54#define bdev_whole(_bdev) \
55 ((_bdev)->bd_disk->part0)
56
57#define dev_to_bdev(device) \
58 container_of((device), struct block_device, bd_device)
59
60#define bdev_kobj(_bdev) \
61 (&((_bdev)->bd_device.kobj))
62
63
64
65
66
67#if defined(CONFIG_ALPHA) && !defined(__alpha_bwx__)
68typedef u32 __bitwise blk_status_t;
69#else
70typedef u8 __bitwise blk_status_t;
71#endif
72#define BLK_STS_OK 0
73#define BLK_STS_NOTSUPP ((__force blk_status_t)1)
74#define BLK_STS_TIMEOUT ((__force blk_status_t)2)
75#define BLK_STS_NOSPC ((__force blk_status_t)3)
76#define BLK_STS_TRANSPORT ((__force blk_status_t)4)
77#define BLK_STS_TARGET ((__force blk_status_t)5)
78#define BLK_STS_NEXUS ((__force blk_status_t)6)
79#define BLK_STS_MEDIUM ((__force blk_status_t)7)
80#define BLK_STS_PROTECTION ((__force blk_status_t)8)
81#define BLK_STS_RESOURCE ((__force blk_status_t)9)
82#define BLK_STS_IOERR ((__force blk_status_t)10)
83
84
85#define BLK_STS_DM_REQUEUE ((__force blk_status_t)11)
86
87#define BLK_STS_AGAIN ((__force blk_status_t)12)
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105#define BLK_STS_DEV_RESOURCE ((__force blk_status_t)13)
106
107
108
109
110
111
112
113
114
115
116
117#define BLK_STS_ZONE_RESOURCE ((__force blk_status_t)14)
118
119
120
121
122
123
124
125
126#define BLK_STS_ZONE_OPEN_RESOURCE ((__force blk_status_t)15)
127
128
129
130
131
132
133
134
135#define BLK_STS_ZONE_ACTIVE_RESOURCE ((__force blk_status_t)16)
136
137
138
139
140
141
142
143
144
145
146
147
148
149static inline bool blk_path_error(blk_status_t error)
150{
151 switch (error) {
152 case BLK_STS_NOTSUPP:
153 case BLK_STS_NOSPC:
154 case BLK_STS_TARGET:
155 case BLK_STS_NEXUS:
156 case BLK_STS_MEDIUM:
157 case BLK_STS_PROTECTION:
158 return false;
159 }
160
161
162 return true;
163}
164
165
166
167
168
169
170
171#define BIO_ISSUE_RES_BITS 1
172#define BIO_ISSUE_SIZE_BITS 12
173#define BIO_ISSUE_RES_SHIFT (64 - BIO_ISSUE_RES_BITS)
174#define BIO_ISSUE_SIZE_SHIFT (BIO_ISSUE_RES_SHIFT - BIO_ISSUE_SIZE_BITS)
175#define BIO_ISSUE_TIME_MASK ((1ULL << BIO_ISSUE_SIZE_SHIFT) - 1)
176#define BIO_ISSUE_SIZE_MASK \
177 (((1ULL << BIO_ISSUE_SIZE_BITS) - 1) << BIO_ISSUE_SIZE_SHIFT)
178#define BIO_ISSUE_RES_MASK (~((1ULL << BIO_ISSUE_RES_SHIFT) - 1))
179
180
181#define BIO_ISSUE_THROTL_SKIP_LATENCY (1ULL << 63)
182
183struct bio_issue {
184 u64 value;
185};
186
187static inline u64 __bio_issue_time(u64 time)
188{
189 return time & BIO_ISSUE_TIME_MASK;
190}
191
192static inline u64 bio_issue_time(struct bio_issue *issue)
193{
194 return __bio_issue_time(issue->value);
195}
196
197static inline sector_t bio_issue_size(struct bio_issue *issue)
198{
199 return ((issue->value & BIO_ISSUE_SIZE_MASK) >> BIO_ISSUE_SIZE_SHIFT);
200}
201
202static inline void bio_issue_init(struct bio_issue *issue,
203 sector_t size)
204{
205 size &= (1ULL << BIO_ISSUE_SIZE_BITS) - 1;
206 issue->value = ((issue->value & BIO_ISSUE_RES_MASK) |
207 (ktime_get_ns() & BIO_ISSUE_TIME_MASK) |
208 ((u64)size << BIO_ISSUE_SIZE_SHIFT));
209}
210
211
212
213
214
215struct bio {
216 struct bio *bi_next;
217 struct block_device *bi_bdev;
218 unsigned int bi_opf;
219
220
221
222 unsigned short bi_flags;
223 unsigned short bi_ioprio;
224 unsigned short bi_write_hint;
225 blk_status_t bi_status;
226 atomic_t __bi_remaining;
227
228 struct bvec_iter bi_iter;
229
230 bio_end_io_t *bi_end_io;
231
232 void *bi_private;
233#ifdef CONFIG_BLK_CGROUP
234
235
236
237
238
239
240 struct blkcg_gq *bi_blkg;
241 struct bio_issue bi_issue;
242#ifdef CONFIG_BLK_CGROUP_IOCOST
243 u64 bi_iocost_cost;
244#endif
245#endif
246
247#ifdef CONFIG_BLK_INLINE_ENCRYPTION
248 struct bio_crypt_ctx *bi_crypt_context;
249#endif
250
251 union {
252#if defined(CONFIG_BLK_DEV_INTEGRITY)
253 struct bio_integrity_payload *bi_integrity;
254#endif
255 };
256
257 unsigned short bi_vcnt;
258
259
260
261
262
263 unsigned short bi_max_vecs;
264
265 atomic_t __bi_cnt;
266
267 struct bio_vec *bi_io_vec;
268
269 struct bio_set *bi_pool;
270
271
272
273
274
275
276 struct bio_vec bi_inline_vecs[];
277};
278
279#define BIO_RESET_BYTES offsetof(struct bio, bi_max_vecs)
280#define BIO_MAX_SECTORS (UINT_MAX >> SECTOR_SHIFT)
281
282
283
284
285enum {
286 BIO_NO_PAGE_REF,
287 BIO_CLONED,
288 BIO_BOUNCED,
289 BIO_WORKINGSET,
290 BIO_QUIET,
291 BIO_CHAIN,
292 BIO_REFFED,
293 BIO_THROTTLED,
294
295 BIO_TRACE_COMPLETION,
296
297 BIO_CGROUP_ACCT,
298 BIO_TRACKED,
299 BIO_REMAPPED,
300 BIO_ZONE_WRITE_LOCKED,
301 BIO_PERCPU_CACHE,
302 BIO_FLAG_LAST
303};
304
305typedef __u32 __bitwise blk_mq_req_flags_t;
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320#define REQ_OP_BITS 8
321#define REQ_OP_MASK ((1 << REQ_OP_BITS) - 1)
322#define REQ_FLAG_BITS 24
323
324enum req_opf {
325
326 REQ_OP_READ = 0,
327
328 REQ_OP_WRITE = 1,
329
330 REQ_OP_FLUSH = 2,
331
332 REQ_OP_DISCARD = 3,
333
334 REQ_OP_SECURE_ERASE = 5,
335
336 REQ_OP_WRITE_SAME = 7,
337
338 REQ_OP_WRITE_ZEROES = 9,
339
340 REQ_OP_ZONE_OPEN = 10,
341
342 REQ_OP_ZONE_CLOSE = 11,
343
344 REQ_OP_ZONE_FINISH = 12,
345
346 REQ_OP_ZONE_APPEND = 13,
347
348 REQ_OP_ZONE_RESET = 15,
349
350 REQ_OP_ZONE_RESET_ALL = 17,
351
352
353 REQ_OP_DRV_IN = 34,
354 REQ_OP_DRV_OUT = 35,
355
356 REQ_OP_LAST,
357};
358
359enum req_flag_bits {
360 __REQ_FAILFAST_DEV =
361 REQ_OP_BITS,
362 __REQ_FAILFAST_TRANSPORT,
363 __REQ_FAILFAST_DRIVER,
364 __REQ_SYNC,
365 __REQ_META,
366 __REQ_PRIO,
367 __REQ_NOMERGE,
368 __REQ_IDLE,
369 __REQ_INTEGRITY,
370 __REQ_FUA,
371 __REQ_PREFLUSH,
372 __REQ_RAHEAD,
373 __REQ_BACKGROUND,
374 __REQ_NOWAIT,
375
376
377
378
379
380
381
382 __REQ_CGROUP_PUNT,
383
384
385 __REQ_NOUNMAP,
386
387 __REQ_HIPRI,
388
389
390 __REQ_DRV,
391 __REQ_SWAP,
392 __REQ_NR_BITS,
393};
394
395#define REQ_FAILFAST_DEV (1ULL << __REQ_FAILFAST_DEV)
396#define REQ_FAILFAST_TRANSPORT (1ULL << __REQ_FAILFAST_TRANSPORT)
397#define REQ_FAILFAST_DRIVER (1ULL << __REQ_FAILFAST_DRIVER)
398#define REQ_SYNC (1ULL << __REQ_SYNC)
399#define REQ_META (1ULL << __REQ_META)
400#define REQ_PRIO (1ULL << __REQ_PRIO)
401#define REQ_NOMERGE (1ULL << __REQ_NOMERGE)
402#define REQ_IDLE (1ULL << __REQ_IDLE)
403#define REQ_INTEGRITY (1ULL << __REQ_INTEGRITY)
404#define REQ_FUA (1ULL << __REQ_FUA)
405#define REQ_PREFLUSH (1ULL << __REQ_PREFLUSH)
406#define REQ_RAHEAD (1ULL << __REQ_RAHEAD)
407#define REQ_BACKGROUND (1ULL << __REQ_BACKGROUND)
408#define REQ_NOWAIT (1ULL << __REQ_NOWAIT)
409#define REQ_CGROUP_PUNT (1ULL << __REQ_CGROUP_PUNT)
410
411#define REQ_NOUNMAP (1ULL << __REQ_NOUNMAP)
412#define REQ_HIPRI (1ULL << __REQ_HIPRI)
413
414#define REQ_DRV (1ULL << __REQ_DRV)
415#define REQ_SWAP (1ULL << __REQ_SWAP)
416
417#define REQ_FAILFAST_MASK \
418 (REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | REQ_FAILFAST_DRIVER)
419
420#define REQ_NOMERGE_FLAGS \
421 (REQ_NOMERGE | REQ_PREFLUSH | REQ_FUA)
422
423enum stat_group {
424 STAT_READ,
425 STAT_WRITE,
426 STAT_DISCARD,
427 STAT_FLUSH,
428
429 NR_STAT_GROUPS
430};
431
432#define bio_op(bio) \
433 ((bio)->bi_opf & REQ_OP_MASK)
434#define req_op(req) \
435 ((req)->cmd_flags & REQ_OP_MASK)
436
437
438static inline void bio_set_op_attrs(struct bio *bio, unsigned op,
439 unsigned op_flags)
440{
441 bio->bi_opf = op | op_flags;
442}
443
444static inline bool op_is_write(unsigned int op)
445{
446 return (op & 1);
447}
448
449
450
451
452
453static inline bool op_is_flush(unsigned int op)
454{
455 return op & (REQ_FUA | REQ_PREFLUSH);
456}
457
458
459
460
461
462
463static inline bool op_is_sync(unsigned int op)
464{
465 return (op & REQ_OP_MASK) == REQ_OP_READ ||
466 (op & (REQ_SYNC | REQ_FUA | REQ_PREFLUSH));
467}
468
469static inline bool op_is_discard(unsigned int op)
470{
471 return (op & REQ_OP_MASK) == REQ_OP_DISCARD;
472}
473
474
475
476
477
478
479
480static inline bool op_is_zone_mgmt(enum req_opf op)
481{
482 switch (op & REQ_OP_MASK) {
483 case REQ_OP_ZONE_RESET:
484 case REQ_OP_ZONE_OPEN:
485 case REQ_OP_ZONE_CLOSE:
486 case REQ_OP_ZONE_FINISH:
487 return true;
488 default:
489 return false;
490 }
491}
492
493static inline int op_stat_group(unsigned int op)
494{
495 if (op_is_discard(op))
496 return STAT_DISCARD;
497 return op_is_write(op);
498}
499
500typedef unsigned int blk_qc_t;
501#define BLK_QC_T_NONE -1U
502#define BLK_QC_T_SHIFT 16
503#define BLK_QC_T_INTERNAL (1U << 31)
504
505static inline bool blk_qc_t_valid(blk_qc_t cookie)
506{
507 return cookie != BLK_QC_T_NONE;
508}
509
510static inline unsigned int blk_qc_t_to_queue_num(blk_qc_t cookie)
511{
512 return (cookie & ~BLK_QC_T_INTERNAL) >> BLK_QC_T_SHIFT;
513}
514
515static inline unsigned int blk_qc_t_to_tag(blk_qc_t cookie)
516{
517 return cookie & ((1u << BLK_QC_T_SHIFT) - 1);
518}
519
520static inline bool blk_qc_t_is_internal(blk_qc_t cookie)
521{
522 return (cookie & BLK_QC_T_INTERNAL) != 0;
523}
524
525struct blk_rq_stat {
526 u64 mean;
527 u64 min;
528 u64 max;
529 u32 nr_samples;
530 u64 batch;
531};
532
533#endif
534