2 * Block data types and constants. Directly include this file only to
3 * break include dependency loop.
5 #ifndef __LINUX_BLK_TYPES_H
6 #define __LINUX_BLK_TYPES_H
8 #include <linux/atomic.h>
9 #include <linux/types.h>
10 #include <linux/bvec.h>
15 typedef void (bio_end_io_t) (struct bio *);
18 * Block error status values. See block/blk-core:blk_errors for the details.
20 typedef u8 __bitwise blk_status_t;
22 #define BLK_STS_NOTSUPP ((__force blk_status_t)1)
23 #define BLK_STS_TIMEOUT ((__force blk_status_t)2)
24 #define BLK_STS_NOSPC ((__force blk_status_t)3)
25 #define BLK_STS_TRANSPORT ((__force blk_status_t)4)
26 #define BLK_STS_TARGET ((__force blk_status_t)5)
27 #define BLK_STS_NEXUS ((__force blk_status_t)6)
28 #define BLK_STS_MEDIUM ((__force blk_status_t)7)
29 #define BLK_STS_PROTECTION ((__force blk_status_t)8)
30 #define BLK_STS_RESOURCE ((__force blk_status_t)9)
31 #define BLK_STS_IOERR ((__force blk_status_t)10)
33 /* hack for device mapper, don't use elsewhere: */
34 #define BLK_STS_DM_REQUEUE ((__force blk_status_t)11)
36 #define BLK_STS_AGAIN ((__force blk_status_t)12)
39 * main unit of I/O for the block layer and lower layers (ie drivers and
43 struct bio *bi_next; /* request queue link */
44 struct block_device *bi_bdev;
45 blk_status_t bi_status;
46 unsigned int bi_opf; /* bottom bits req flags,
47 * top bits REQ_OP. Use
50 unsigned short bi_flags; /* status, command, etc */
51 unsigned short bi_ioprio;
53 struct bvec_iter bi_iter;
55 atomic_t __bi_remaining;
57 bio_end_io_t *bi_end_io;
60 unsigned short bi_vcnt; /* how many bio_vec's */
63 * Everything starting with bi_max_vecs will be preserved by bio_reset()
66 unsigned short bi_max_vecs; /* max bvl_vecs we can hold */
68 atomic_t __bi_cnt; /* pin count */
70 struct bio_vec *bi_io_vec; /* the actual vec list */
72 struct bio_set *bi_pool;
75 * We can inline a number of vecs at the end of the bio, to avoid
76 * double allocations for a small number of bio_vecs. This member
77 * MUST obviously be kept at the very end of the bio.
79 struct bio_vec bi_inline_vecs[0];
82 #define BIO_RESET_BYTES offsetof(struct bio, bi_max_vecs)
87 #define BIO_SEG_VALID 1 /* bi_phys_segments valid */
88 #define BIO_CLONED 2 /* doesn't own data */
89 #define BIO_BOUNCED 3 /* bio is a bounce bio */
90 #define BIO_USER_MAPPED 4 /* contains user pages */
91 #define BIO_NULL_MAPPED 5 /* contains invalid user pages */
92 #define BIO_QUIET 6 /* Make BIO Quiet */
93 #define BIO_CHAIN 7 /* chained bio, ->bi_remaining in effect */
94 #define BIO_REFFED 8 /* bio has elevated ->bi_cnt */
97 * Flags starting here get preserved by bio_reset() - this includes
100 #define BIO_RESET_BITS 10
103 * We support 6 different bvec pools, the last one is magic in that it
104 * is backed by a mempool.
106 #define BVEC_POOL_NR 6
107 #define BVEC_POOL_MAX (BVEC_POOL_NR - 1)
110 * Top 4 bits of bio flags indicate the pool the bvecs came from. We add
111 * 1 to the actual index so that 0 indicates that there are no bvecs to be
114 #define BVEC_POOL_BITS (4)
115 #define BVEC_POOL_OFFSET (16 - BVEC_POOL_BITS)
116 #define BVEC_POOL_IDX(bio) ((bio)->bi_flags >> BVEC_POOL_OFFSET)
119 * Operations and flags common to the bio and request structures.
120 * We use 8 bits for encoding the operation, and the remaining 24 for flags.
122 * The least significant bit of the operation number indicates the data
123 * transfer direction:
125 * - if the least significant bit is set transfers are TO the device
126 * - if the least significant bit is not set transfers are FROM the device
128 * If a operation does not transfer data the least significant bit has no
131 #define REQ_OP_BITS 8
132 #define REQ_OP_MASK ((1 << REQ_OP_BITS) - 1)
133 #define REQ_FLAG_BITS 24
136 /* read sectors from the device */
138 /* write sectors to the device */
140 /* flush the volatile write cache */
142 /* discard sectors */
144 /* get zone information */
145 REQ_OP_ZONE_REPORT = 4,
146 /* securely erase sectors */
147 REQ_OP_SECURE_ERASE = 5,
148 /* seset a zone write pointer */
149 REQ_OP_ZONE_RESET = 6,
150 /* write the same sector many times */
151 REQ_OP_WRITE_SAME = 7,
152 /* write the zero filled sector many times */
153 REQ_OP_WRITE_ZEROES = 8,
155 /* SCSI passthrough using struct scsi_request */
157 REQ_OP_SCSI_OUT = 33,
158 /* Driver private requests */
166 __REQ_FAILFAST_DEV = /* no driver retries of device errors */
168 __REQ_FAILFAST_TRANSPORT, /* no driver retries of transport errors */
169 __REQ_FAILFAST_DRIVER, /* no driver retries of driver errors */
170 __REQ_SYNC, /* request is sync (sync write or read) */
171 __REQ_META, /* metadata io request */
172 __REQ_PRIO, /* boost priority in cfq */
173 __REQ_NOMERGE, /* don't touch this for merging */
174 __REQ_IDLE, /* anticipate more IO after this one */
175 __REQ_INTEGRITY, /* I/O includes block integrity payload */
176 __REQ_FUA, /* forced unit access */
177 __REQ_PREFLUSH, /* request for cache flush */
178 __REQ_RAHEAD, /* read ahead, can fail anytime */
179 __REQ_BACKGROUND, /* background IO */
180 __REQ_NR_BITS, /* stops here */
183 #define REQ_SYNC (1ULL << __REQ_SYNC)
184 #define REQ_META (1ULL << __REQ_META)
185 #define REQ_PRIO (1ULL << __REQ_PRIO)
187 #define REQ_NOMERGE_FLAGS (REQ_PREFLUSH | REQ_FUA)
189 #define bio_op(bio) \
190 ((bio)->bi_opf & REQ_OP_MASK)
192 static inline void bio_set_op_attrs(struct bio *bio, unsigned op,
195 bio->bi_opf = op | op_flags;
198 #define REQ_RAHEAD (1ULL << __REQ_RAHEAD)
199 #define REQ_THROTTLED (1ULL << __REQ_THROTTLED)
201 #define REQ_FUA (1ULL << __REQ_FUA)
202 #define REQ_PREFLUSH (1ULL << __REQ_PREFLUSH)
204 #define RW_MASK REQ_OP_WRITE
206 #define READ REQ_OP_READ
207 #define WRITE REQ_OP_WRITE
209 #define READ_SYNC REQ_SYNC
210 #define WRITE_SYNC (REQ_SYNC)
211 #define WRITE_ODIRECT REQ_SYNC
212 #define WRITE_FLUSH (REQ_SYNC | REQ_PREFLUSH)
213 #define WRITE_FUA (REQ_SYNC | REQ_FUA)
214 #define WRITE_FLUSH_FUA (REQ_SYNC | REQ_PREFLUSH | REQ_FUA)
216 #endif /* __LINUX_BLK_TYPES_H */