]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | #ifndef _LINUX_BLKDEV_H |
3 | #define _LINUX_BLKDEV_H | |
4 | ||
85fd0bc9 | 5 | #include <linux/sched.h> |
e6017571 | 6 | #include <linux/sched/clock.h> |
85fd0bc9 | 7 | |
f5ff8422 JA |
8 | #ifdef CONFIG_BLOCK |
9 | ||
1da177e4 LT |
10 | #include <linux/major.h> |
11 | #include <linux/genhd.h> | |
12 | #include <linux/list.h> | |
320ae51f | 13 | #include <linux/llist.h> |
1da177e4 LT |
14 | #include <linux/timer.h> |
15 | #include <linux/workqueue.h> | |
16 | #include <linux/pagemap.h> | |
66114cad | 17 | #include <linux/backing-dev-defs.h> |
1da177e4 LT |
18 | #include <linux/wait.h> |
19 | #include <linux/mempool.h> | |
34c0fd54 | 20 | #include <linux/pfn.h> |
1da177e4 | 21 | #include <linux/bio.h> |
1da177e4 | 22 | #include <linux/stringify.h> |
3e6053d7 | 23 | #include <linux/gfp.h> |
d351af01 | 24 | #include <linux/bsg.h> |
c7c22e4d | 25 | #include <linux/smp.h> |
548bc8e1 | 26 | #include <linux/rcupdate.h> |
add703fd | 27 | #include <linux/percpu-refcount.h> |
84be456f | 28 | #include <linux/scatterlist.h> |
6a0cb1bc | 29 | #include <linux/blkzoned.h> |
1d9bd516 TH |
30 | #include <linux/seqlock.h> |
31 | #include <linux/u64_stats_sync.h> | |
1da177e4 | 32 | |
de477254 | 33 | struct module; |
21b2f0c8 CH |
34 | struct scsi_ioctl_command; |
35 | ||
1da177e4 | 36 | struct request_queue; |
1da177e4 | 37 | struct elevator_queue; |
2056a782 | 38 | struct blk_trace; |
3d6392cf JA |
39 | struct request; |
40 | struct sg_io_hdr; | |
aa387cc8 | 41 | struct bsg_job; |
3c798398 | 42 | struct blkcg_gq; |
7c94e1c1 | 43 | struct blk_flush_queue; |
bbd3e064 | 44 | struct pr_ops; |
87760e5e | 45 | struct rq_wb; |
34dbad5d OS |
46 | struct blk_queue_stats; |
47 | struct blk_stat_callback; | |
1da177e4 LT |
48 | |
49 | #define BLKDEV_MIN_RQ 4 | |
50 | #define BLKDEV_MAX_RQ 128 /* Default maximum */ | |
51 | ||
0206319f SB |
52 | /* Must be consisitent with blk_mq_poll_stats_bkt() */ |
53 | #define BLK_MQ_POLL_STATS_BKTS 16 | |
54 | ||
8bd435b3 TH |
55 | /* |
56 | * Maximum number of blkcg policies allowed to be registered concurrently. | |
57 | * Defined here to simplify include dependency. | |
58 | */ | |
e21b7a0b | 59 | #define BLKCG_MAX_POLS 3 |
8bd435b3 | 60 | |
2a842aca | 61 | typedef void (rq_end_io_fn)(struct request *, blk_status_t); |
1da177e4 | 62 | |
5b788ce3 TH |
63 | #define BLK_RL_SYNCFULL (1U << 0) |
64 | #define BLK_RL_ASYNCFULL (1U << 1) | |
65 | ||
1da177e4 | 66 | struct request_list { |
5b788ce3 | 67 | struct request_queue *q; /* the queue this rl belongs to */ |
a051661c TH |
68 | #ifdef CONFIG_BLK_CGROUP |
69 | struct blkcg_gq *blkg; /* blkg this request pool belongs to */ | |
70 | #endif | |
1faa16d2 JA |
71 | /* |
72 | * count[], starved[], and wait[] are indexed by | |
73 | * BLK_RW_SYNC/BLK_RW_ASYNC | |
74 | */ | |
8a5ecdd4 TH |
75 | int count[2]; |
76 | int starved[2]; | |
77 | mempool_t *rq_pool; | |
78 | wait_queue_head_t wait[2]; | |
5b788ce3 | 79 | unsigned int flags; |
1da177e4 LT |
80 | }; |
81 | ||
e8064021 CH |
82 | /* |
83 | * request flags */ | |
84 | typedef __u32 __bitwise req_flags_t; | |
85 | ||
86 | /* elevator knows about this request */ | |
87 | #define RQF_SORTED ((__force req_flags_t)(1 << 0)) | |
88 | /* drive already may have started this one */ | |
89 | #define RQF_STARTED ((__force req_flags_t)(1 << 1)) | |
90 | /* uses tagged queueing */ | |
91 | #define RQF_QUEUED ((__force req_flags_t)(1 << 2)) | |
92 | /* may not be passed by ioscheduler */ | |
93 | #define RQF_SOFTBARRIER ((__force req_flags_t)(1 << 3)) | |
94 | /* request for flush sequence */ | |
95 | #define RQF_FLUSH_SEQ ((__force req_flags_t)(1 << 4)) | |
96 | /* merge of different types, fail separately */ | |
97 | #define RQF_MIXED_MERGE ((__force req_flags_t)(1 << 5)) | |
98 | /* track inflight for MQ */ | |
99 | #define RQF_MQ_INFLIGHT ((__force req_flags_t)(1 << 6)) | |
100 | /* don't call prep for this one */ | |
101 | #define RQF_DONTPREP ((__force req_flags_t)(1 << 7)) | |
102 | /* set for "ide_preempt" requests and also for requests for which the SCSI | |
103 | "quiesce" state must be ignored. */ | |
104 | #define RQF_PREEMPT ((__force req_flags_t)(1 << 8)) | |
105 | /* contains copies of user pages */ | |
106 | #define RQF_COPY_USER ((__force req_flags_t)(1 << 9)) | |
107 | /* vaguely specified driver internal error. Ignored by the block layer */ | |
108 | #define RQF_FAILED ((__force req_flags_t)(1 << 10)) | |
109 | /* don't warn about errors */ | |
110 | #define RQF_QUIET ((__force req_flags_t)(1 << 11)) | |
111 | /* elevator private data attached */ | |
112 | #define RQF_ELVPRIV ((__force req_flags_t)(1 << 12)) | |
113 | /* account I/O stat */ | |
114 | #define RQF_IO_STAT ((__force req_flags_t)(1 << 13)) | |
115 | /* request came from our alloc pool */ | |
116 | #define RQF_ALLOCED ((__force req_flags_t)(1 << 14)) | |
117 | /* runtime pm request */ | |
118 | #define RQF_PM ((__force req_flags_t)(1 << 15)) | |
119 | /* on IO scheduler merge hash */ | |
120 | #define RQF_HASHED ((__force req_flags_t)(1 << 16)) | |
cf43e6be JA |
121 | /* IO stats tracking on */ |
122 | #define RQF_STATS ((__force req_flags_t)(1 << 17)) | |
f9d03f96 CH |
123 | /* Look at ->special_vec for the actual data payload instead of the |
124 | bio chain. */ | |
125 | #define RQF_SPECIAL_PAYLOAD ((__force req_flags_t)(1 << 18)) | |
6cc77e9c CH |
126 | /* The per-zone write lock is held for this request */ |
127 | #define RQF_ZONE_WRITE_LOCKED ((__force req_flags_t)(1 << 19)) | |
e8064021 CH |
128 | |
129 | /* flags that prevent us from merging requests: */ | |
130 | #define RQF_NOMERGE_FLAGS \ | |
f9d03f96 | 131 | (RQF_STARTED | RQF_SOFTBARRIER | RQF_FLUSH_SEQ | RQF_SPECIAL_PAYLOAD) |
e8064021 | 132 | |
1da177e4 | 133 | /* |
af76e555 CH |
134 | * Try to put the fields that are referenced together in the same cacheline. |
135 | * | |
136 | * If you modify this structure, make sure to update blk_rq_init() and | |
137 | * especially blk_mq_rq_ctx_init() to take care of the added fields. | |
1da177e4 LT |
138 | */ |
139 | struct request { | |
6897fc22 | 140 | struct list_head queuelist; |
320ae51f | 141 | union { |
966a9671 | 142 | call_single_data_t csd; |
9828c2c6 | 143 | u64 fifo_time; |
320ae51f | 144 | }; |
ff856bad | 145 | |
165125e1 | 146 | struct request_queue *q; |
320ae51f | 147 | struct blk_mq_ctx *mq_ctx; |
e6a1c874 | 148 | |
ca93e453 | 149 | int cpu; |
ef295ecf | 150 | unsigned int cmd_flags; /* op and common flags */ |
e8064021 | 151 | req_flags_t rq_flags; |
d486f1f2 JA |
152 | |
153 | int internal_tag; | |
154 | ||
242f9dcb | 155 | unsigned long atomic_flags; |
1da177e4 | 156 | |
a2dec7b3 | 157 | /* the following two fields are internal, NEVER access directly */ |
a2dec7b3 | 158 | unsigned int __data_len; /* total data len */ |
bd166ef1 | 159 | int tag; |
181fdde3 | 160 | sector_t __sector; /* sector cursor */ |
1da177e4 LT |
161 | |
162 | struct bio *bio; | |
163 | struct bio *biotail; | |
164 | ||
360f92c2 JA |
165 | /* |
166 | * The hash is used inside the scheduler, and killed once the | |
167 | * request reaches the dispatch list. The ipi_list is only used | |
168 | * to queue the request for softirq completion, which is long | |
169 | * after the request has been unhashed (and even removed from | |
170 | * the dispatch list). | |
171 | */ | |
172 | union { | |
173 | struct hlist_node hash; /* merge hash */ | |
174 | struct list_head ipi_list; | |
175 | }; | |
176 | ||
e6a1c874 JA |
177 | /* |
178 | * The rb_node is only used inside the io scheduler, requests | |
179 | * are pruned when moved to the dispatch queue. So let the | |
c186794d | 180 | * completion_data share space with the rb_node. |
e6a1c874 JA |
181 | */ |
182 | union { | |
183 | struct rb_node rb_node; /* sort/lookup */ | |
f9d03f96 | 184 | struct bio_vec special_vec; |
c186794d | 185 | void *completion_data; |
e26738e0 | 186 | int error_count; /* for legacy drivers, don't use */ |
e6a1c874 | 187 | }; |
9817064b | 188 | |
ff7d145f | 189 | /* |
7f1dc8a2 | 190 | * Three pointers are available for the IO schedulers, if they need |
c186794d MS |
191 | * more they have to dynamically allocate it. Flush requests are |
192 | * never put on the IO scheduler. So let the flush fields share | |
a612fddf | 193 | * space with the elevator data. |
ff7d145f | 194 | */ |
c186794d | 195 | union { |
a612fddf TH |
196 | struct { |
197 | struct io_cq *icq; | |
198 | void *priv[2]; | |
199 | } elv; | |
200 | ||
c186794d MS |
201 | struct { |
202 | unsigned int seq; | |
203 | struct list_head list; | |
4853abaa | 204 | rq_end_io_fn *saved_end_io; |
c186794d MS |
205 | } flush; |
206 | }; | |
ff7d145f | 207 | |
8f34ee75 | 208 | struct gendisk *rq_disk; |
09e099d4 | 209 | struct hd_struct *part; |
1da177e4 | 210 | unsigned long start_time; |
cf43e6be | 211 | struct blk_issue_stat issue_stat; |
9195291e | 212 | #ifdef CONFIG_BLK_CGROUP |
a051661c | 213 | struct request_list *rl; /* rl this rq is alloced from */ |
9195291e DS |
214 | unsigned long long start_time_ns; |
215 | unsigned long long io_start_time_ns; /* when passed to hardware */ | |
216 | #endif | |
1da177e4 LT |
217 | /* Number of scatter-gather DMA addr+len pairs after |
218 | * physical address coalescing is performed. | |
219 | */ | |
220 | unsigned short nr_phys_segments; | |
13f05c8d MP |
221 | #if defined(CONFIG_BLK_DEV_INTEGRITY) |
222 | unsigned short nr_integrity_segments; | |
223 | #endif | |
1da177e4 | 224 | |
8f34ee75 JA |
225 | unsigned short ioprio; |
226 | ||
1dd5198b | 227 | unsigned int timeout; |
1da177e4 | 228 | |
731ec497 | 229 | void *special; /* opaque pointer available for LLD use */ |
cdd60262 | 230 | |
7a85f889 | 231 | unsigned int extra_len; /* length of alignment and padding */ |
1da177e4 | 232 | |
cb6934f8 JA |
233 | unsigned short write_hint; |
234 | ||
1d9bd516 TH |
235 | /* |
236 | * On blk-mq, the lower bits of ->gstate (generation number and | |
237 | * state) carry the MQ_RQ_* state value and the upper bits the | |
238 | * generation number which is monotonically incremented and used to | |
239 | * distinguish the reuse instances. | |
240 | * | |
241 | * ->gstate_seq allows updates to ->gstate and other fields | |
242 | * (currently ->deadline) during request start to be read | |
243 | * atomically from the timeout path, so that it can operate on a | |
244 | * coherent set of information. | |
245 | */ | |
246 | seqcount_t gstate_seq; | |
247 | u64 gstate; | |
248 | ||
249 | /* | |
250 | * ->aborted_gstate is used by the timeout to claim a specific | |
251 | * recycle instance of this request. See blk_mq_timeout_work(). | |
252 | */ | |
253 | struct u64_stats_sync aborted_gstate_sync; | |
254 | u64 aborted_gstate; | |
255 | ||
242f9dcb JA |
256 | unsigned long deadline; |
257 | struct list_head timeout_list; | |
1da177e4 | 258 | |
1da177e4 | 259 | /* |
c00895ab | 260 | * completion callback. |
1da177e4 LT |
261 | */ |
262 | rq_end_io_fn *end_io; | |
263 | void *end_io_data; | |
abae1fde FT |
264 | |
265 | /* for bidi */ | |
266 | struct request *next_rq; | |
1da177e4 LT |
267 | }; |
268 | ||
aebf526b CH |
269 | static inline bool blk_rq_is_scsi(struct request *rq) |
270 | { | |
271 | return req_op(rq) == REQ_OP_SCSI_IN || req_op(rq) == REQ_OP_SCSI_OUT; | |
272 | } | |
273 | ||
274 | static inline bool blk_rq_is_private(struct request *rq) | |
275 | { | |
276 | return req_op(rq) == REQ_OP_DRV_IN || req_op(rq) == REQ_OP_DRV_OUT; | |
277 | } | |
278 | ||
57292b58 CH |
279 | static inline bool blk_rq_is_passthrough(struct request *rq) |
280 | { | |
aebf526b | 281 | return blk_rq_is_scsi(rq) || blk_rq_is_private(rq); |
57292b58 CH |
282 | } |
283 | ||
766ca442 FLVC |
284 | static inline unsigned short req_get_ioprio(struct request *req) |
285 | { | |
286 | return req->ioprio; | |
287 | } | |
288 | ||
1da177e4 LT |
289 | #include <linux/elevator.h> |
290 | ||
320ae51f JA |
291 | struct blk_queue_ctx; |
292 | ||
165125e1 | 293 | typedef void (request_fn_proc) (struct request_queue *q); |
dece1635 | 294 | typedef blk_qc_t (make_request_fn) (struct request_queue *q, struct bio *bio); |
ea435e1b | 295 | typedef bool (poll_q_fn) (struct request_queue *q, blk_qc_t); |
165125e1 | 296 | typedef int (prep_rq_fn) (struct request_queue *, struct request *); |
28018c24 | 297 | typedef void (unprep_rq_fn) (struct request_queue *, struct request *); |
1da177e4 LT |
298 | |
299 | struct bio_vec; | |
ff856bad | 300 | typedef void (softirq_done_fn)(struct request *); |
2fb98e84 | 301 | typedef int (dma_drain_needed_fn)(struct request *); |
ef9e3fac | 302 | typedef int (lld_busy_fn) (struct request_queue *q); |
aa387cc8 | 303 | typedef int (bsg_job_fn) (struct bsg_job *); |
6d247d7f CH |
304 | typedef int (init_rq_fn)(struct request_queue *, struct request *, gfp_t); |
305 | typedef void (exit_rq_fn)(struct request_queue *, struct request *); | |
1da177e4 | 306 | |
242f9dcb JA |
307 | enum blk_eh_timer_return { |
308 | BLK_EH_NOT_HANDLED, | |
309 | BLK_EH_HANDLED, | |
310 | BLK_EH_RESET_TIMER, | |
311 | }; | |
312 | ||
313 | typedef enum blk_eh_timer_return (rq_timed_out_fn)(struct request *); | |
314 | ||
1da177e4 LT |
315 | enum blk_queue_state { |
316 | Queue_down, | |
317 | Queue_up, | |
318 | }; | |
319 | ||
1da177e4 LT |
320 | struct blk_queue_tag { |
321 | struct request **tag_index; /* map of busy tags */ | |
322 | unsigned long *tag_map; /* bit map of free/busy tags */ | |
1da177e4 | 323 | int max_depth; /* what we will send to device */ |
ba025082 | 324 | int real_max_depth; /* what the array can hold */ |
1da177e4 | 325 | atomic_t refcnt; /* map can be shared */ |
ee1b6f7a SL |
326 | int alloc_policy; /* tag allocation policy */ |
327 | int next_tag; /* next tag */ | |
1da177e4 | 328 | }; |
ee1b6f7a SL |
329 | #define BLK_TAG_ALLOC_FIFO 0 /* allocate starting from 0 */ |
330 | #define BLK_TAG_ALLOC_RR 1 /* allocate starting from last allocated tag */ | |
1da177e4 | 331 | |
abf54393 FT |
332 | #define BLK_SCSI_MAX_CMDS (256) |
333 | #define BLK_SCSI_CMD_PER_LONG (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8)) | |
334 | ||
797476b8 DLM |
335 | /* |
336 | * Zoned block device models (zoned limit). | |
337 | */ | |
338 | enum blk_zoned_model { | |
339 | BLK_ZONED_NONE, /* Regular block device */ | |
340 | BLK_ZONED_HA, /* Host-aware zoned block device */ | |
341 | BLK_ZONED_HM, /* Host-managed zoned block device */ | |
342 | }; | |
343 | ||
025146e1 MP |
344 | struct queue_limits { |
345 | unsigned long bounce_pfn; | |
346 | unsigned long seg_boundary_mask; | |
03100aad | 347 | unsigned long virt_boundary_mask; |
025146e1 MP |
348 | |
349 | unsigned int max_hw_sectors; | |
ca369d51 | 350 | unsigned int max_dev_sectors; |
762380ad | 351 | unsigned int chunk_sectors; |
025146e1 MP |
352 | unsigned int max_sectors; |
353 | unsigned int max_segment_size; | |
c72758f3 MP |
354 | unsigned int physical_block_size; |
355 | unsigned int alignment_offset; | |
356 | unsigned int io_min; | |
357 | unsigned int io_opt; | |
67efc925 | 358 | unsigned int max_discard_sectors; |
0034af03 | 359 | unsigned int max_hw_discard_sectors; |
4363ac7c | 360 | unsigned int max_write_same_sectors; |
a6f0788e | 361 | unsigned int max_write_zeroes_sectors; |
86b37281 MP |
362 | unsigned int discard_granularity; |
363 | unsigned int discard_alignment; | |
025146e1 MP |
364 | |
365 | unsigned short logical_block_size; | |
8a78362c | 366 | unsigned short max_segments; |
13f05c8d | 367 | unsigned short max_integrity_segments; |
1e739730 | 368 | unsigned short max_discard_segments; |
025146e1 | 369 | |
c72758f3 | 370 | unsigned char misaligned; |
86b37281 | 371 | unsigned char discard_misaligned; |
e692cb66 | 372 | unsigned char cluster; |
c78afc62 | 373 | unsigned char raid_partial_stripes_expensive; |
797476b8 | 374 | enum blk_zoned_model zoned; |
025146e1 MP |
375 | }; |
376 | ||
6a0cb1bc HR |
377 | #ifdef CONFIG_BLK_DEV_ZONED |
378 | ||
379 | struct blk_zone_report_hdr { | |
380 | unsigned int nr_zones; | |
381 | u8 padding[60]; | |
382 | }; | |
383 | ||
384 | extern int blkdev_report_zones(struct block_device *bdev, | |
385 | sector_t sector, struct blk_zone *zones, | |
386 | unsigned int *nr_zones, gfp_t gfp_mask); | |
387 | extern int blkdev_reset_zones(struct block_device *bdev, sector_t sectors, | |
388 | sector_t nr_sectors, gfp_t gfp_mask); | |
389 | ||
3ed05a98 ST |
390 | extern int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, |
391 | unsigned int cmd, unsigned long arg); | |
392 | extern int blkdev_reset_zones_ioctl(struct block_device *bdev, fmode_t mode, | |
393 | unsigned int cmd, unsigned long arg); | |
394 | ||
395 | #else /* CONFIG_BLK_DEV_ZONED */ | |
396 | ||
397 | static inline int blkdev_report_zones_ioctl(struct block_device *bdev, | |
398 | fmode_t mode, unsigned int cmd, | |
399 | unsigned long arg) | |
400 | { | |
401 | return -ENOTTY; | |
402 | } | |
403 | ||
404 | static inline int blkdev_reset_zones_ioctl(struct block_device *bdev, | |
405 | fmode_t mode, unsigned int cmd, | |
406 | unsigned long arg) | |
407 | { | |
408 | return -ENOTTY; | |
409 | } | |
410 | ||
6a0cb1bc HR |
411 | #endif /* CONFIG_BLK_DEV_ZONED */ |
412 | ||
d7b76301 | 413 | struct request_queue { |
1da177e4 LT |
414 | /* |
415 | * Together with queue_head for cacheline sharing | |
416 | */ | |
417 | struct list_head queue_head; | |
418 | struct request *last_merge; | |
b374d18a | 419 | struct elevator_queue *elevator; |
8a5ecdd4 TH |
420 | int nr_rqs[2]; /* # allocated [a]sync rqs */ |
421 | int nr_rqs_elvpriv; /* # allocated rqs w/ elvpriv */ | |
1da177e4 | 422 | |
8e8320c9 JA |
423 | atomic_t shared_hctx_restart; |
424 | ||
34dbad5d | 425 | struct blk_queue_stats *stats; |
87760e5e JA |
426 | struct rq_wb *rq_wb; |
427 | ||
1da177e4 | 428 | /* |
a051661c TH |
429 | * If blkcg is not used, @q->root_rl serves all requests. If blkcg |
430 | * is used, root blkg allocates from @q->root_rl and all other | |
431 | * blkgs from their own blkg->rl. Which one to use should be | |
432 | * determined using bio_request_list(). | |
1da177e4 | 433 | */ |
a051661c | 434 | struct request_list root_rl; |
1da177e4 LT |
435 | |
436 | request_fn_proc *request_fn; | |
1da177e4 | 437 | make_request_fn *make_request_fn; |
ea435e1b | 438 | poll_q_fn *poll_fn; |
1da177e4 | 439 | prep_rq_fn *prep_rq_fn; |
28018c24 | 440 | unprep_rq_fn *unprep_rq_fn; |
ff856bad | 441 | softirq_done_fn *softirq_done_fn; |
242f9dcb | 442 | rq_timed_out_fn *rq_timed_out_fn; |
2fb98e84 | 443 | dma_drain_needed_fn *dma_drain_needed; |
ef9e3fac | 444 | lld_busy_fn *lld_busy_fn; |
d280bab3 | 445 | /* Called just after a request is allocated */ |
6d247d7f | 446 | init_rq_fn *init_rq_fn; |
d280bab3 | 447 | /* Called just before a request is freed */ |
6d247d7f | 448 | exit_rq_fn *exit_rq_fn; |
d280bab3 BVA |
449 | /* Called from inside blk_get_request() */ |
450 | void (*initialize_rq_fn)(struct request *rq); | |
1da177e4 | 451 | |
f8a5b122 | 452 | const struct blk_mq_ops *mq_ops; |
320ae51f JA |
453 | |
454 | unsigned int *mq_map; | |
455 | ||
456 | /* sw queues */ | |
e6cdb092 | 457 | struct blk_mq_ctx __percpu *queue_ctx; |
320ae51f JA |
458 | unsigned int nr_queues; |
459 | ||
d278d4a8 JA |
460 | unsigned int queue_depth; |
461 | ||
320ae51f JA |
462 | /* hw dispatch queues */ |
463 | struct blk_mq_hw_ctx **queue_hw_ctx; | |
464 | unsigned int nr_hw_queues; | |
465 | ||
8922e16c TH |
466 | /* |
467 | * Dispatch queue sorting | |
468 | */ | |
1b47f531 | 469 | sector_t end_sector; |
8922e16c | 470 | struct request *boundary_rq; |
8922e16c | 471 | |
1da177e4 | 472 | /* |
3cca6dc1 | 473 | * Delayed queue handling |
1da177e4 | 474 | */ |
3cca6dc1 | 475 | struct delayed_work delay_work; |
1da177e4 | 476 | |
dc3b17cc | 477 | struct backing_dev_info *backing_dev_info; |
1da177e4 LT |
478 | |
479 | /* | |
480 | * The queue owner gets to use this for whatever they like. | |
481 | * ll_rw_blk doesn't touch it. | |
482 | */ | |
483 | void *queuedata; | |
484 | ||
1da177e4 | 485 | /* |
d7b76301 | 486 | * various queue flags, see QUEUE_* below |
1da177e4 | 487 | */ |
d7b76301 | 488 | unsigned long queue_flags; |
1da177e4 | 489 | |
a73f730d TH |
490 | /* |
491 | * ida allocated id for this queue. Used to index queues from | |
492 | * ioctx. | |
493 | */ | |
494 | int id; | |
495 | ||
1da177e4 | 496 | /* |
d7b76301 | 497 | * queue needs bounce pages for pages above this limit |
1da177e4 | 498 | */ |
d7b76301 | 499 | gfp_t bounce_gfp; |
1da177e4 LT |
500 | |
501 | /* | |
152587de JA |
502 | * protects queue structures from reentrancy. ->__queue_lock should |
503 | * _never_ be used directly, it is queue private. always use | |
504 | * ->queue_lock. | |
1da177e4 | 505 | */ |
152587de | 506 | spinlock_t __queue_lock; |
1da177e4 LT |
507 | spinlock_t *queue_lock; |
508 | ||
509 | /* | |
510 | * queue kobject | |
511 | */ | |
512 | struct kobject kobj; | |
513 | ||
320ae51f JA |
514 | /* |
515 | * mq queue kobject | |
516 | */ | |
517 | struct kobject mq_kobj; | |
518 | ||
ac6fc48c DW |
519 | #ifdef CONFIG_BLK_DEV_INTEGRITY |
520 | struct blk_integrity integrity; | |
521 | #endif /* CONFIG_BLK_DEV_INTEGRITY */ | |
522 | ||
47fafbc7 | 523 | #ifdef CONFIG_PM |
6c954667 LM |
524 | struct device *dev; |
525 | int rpm_status; | |
526 | unsigned int nr_pending; | |
527 | #endif | |
528 | ||
1da177e4 LT |
529 | /* |
530 | * queue settings | |
531 | */ | |
532 | unsigned long nr_requests; /* Max # of requests */ | |
533 | unsigned int nr_congestion_on; | |
534 | unsigned int nr_congestion_off; | |
535 | unsigned int nr_batching; | |
536 | ||
fa0ccd83 | 537 | unsigned int dma_drain_size; |
d7b76301 | 538 | void *dma_drain_buffer; |
e3790c7d | 539 | unsigned int dma_pad_mask; |
1da177e4 LT |
540 | unsigned int dma_alignment; |
541 | ||
542 | struct blk_queue_tag *queue_tags; | |
6eca9004 | 543 | struct list_head tag_busy_list; |
1da177e4 | 544 | |
15853af9 | 545 | unsigned int nr_sorted; |
0a7ae2ff | 546 | unsigned int in_flight[2]; |
cf43e6be | 547 | |
24faf6f6 BVA |
548 | /* |
549 | * Number of active block driver functions for which blk_drain_queue() | |
550 | * must wait. Must be incremented around functions that unlock the | |
551 | * queue_lock internally, e.g. scsi_request_fn(). | |
552 | */ | |
553 | unsigned int request_fn_active; | |
1da177e4 | 554 | |
242f9dcb | 555 | unsigned int rq_timeout; |
64f1c21e | 556 | int poll_nsec; |
34dbad5d OS |
557 | |
558 | struct blk_stat_callback *poll_cb; | |
0206319f | 559 | struct blk_rq_stat poll_stat[BLK_MQ_POLL_STATS_BKTS]; |
34dbad5d | 560 | |
242f9dcb | 561 | struct timer_list timeout; |
287922eb | 562 | struct work_struct timeout_work; |
242f9dcb JA |
563 | struct list_head timeout_list; |
564 | ||
a612fddf | 565 | struct list_head icq_list; |
4eef3049 | 566 | #ifdef CONFIG_BLK_CGROUP |
a2b1693b | 567 | DECLARE_BITMAP (blkcg_pols, BLKCG_MAX_POLS); |
3c798398 | 568 | struct blkcg_gq *root_blkg; |
03aa264a | 569 | struct list_head blkg_list; |
4eef3049 | 570 | #endif |
a612fddf | 571 | |
025146e1 MP |
572 | struct queue_limits limits; |
573 | ||
6cc77e9c CH |
574 | /* |
575 | * Zoned block device information for request dispatch control. | |
576 | * nr_zones is the total number of zones of the device. This is always | |
577 | * 0 for regular block devices. seq_zones_bitmap is a bitmap of nr_zones | |
578 | * bits which indicates if a zone is conventional (bit clear) or | |
579 | * sequential (bit set). seq_zones_wlock is a bitmap of nr_zones | |
580 | * bits which indicates if a zone is write locked, that is, if a write | |
581 | * request targeting the zone was dispatched. All three fields are | |
582 | * initialized by the low level device driver (e.g. scsi/sd.c). | |
583 | * Stacking drivers (device mappers) may or may not initialize | |
584 | * these fields. | |
585 | */ | |
586 | unsigned int nr_zones; | |
587 | unsigned long *seq_zones_bitmap; | |
588 | unsigned long *seq_zones_wlock; | |
589 | ||
1da177e4 LT |
590 | /* |
591 | * sg stuff | |
592 | */ | |
593 | unsigned int sg_timeout; | |
594 | unsigned int sg_reserved_size; | |
1946089a | 595 | int node; |
6c5c9341 | 596 | #ifdef CONFIG_BLK_DEV_IO_TRACE |
2056a782 | 597 | struct blk_trace *blk_trace; |
5acb3cc2 | 598 | struct mutex blk_trace_mutex; |
6c5c9341 | 599 | #endif |
1da177e4 | 600 | /* |
4913efe4 | 601 | * for flush operations |
1da177e4 | 602 | */ |
7c94e1c1 | 603 | struct blk_flush_queue *fq; |
483f4afc | 604 | |
6fca6a61 CH |
605 | struct list_head requeue_list; |
606 | spinlock_t requeue_lock; | |
2849450a | 607 | struct delayed_work requeue_work; |
6fca6a61 | 608 | |
483f4afc | 609 | struct mutex sysfs_lock; |
d351af01 | 610 | |
d732580b | 611 | int bypass_depth; |
4ecd4fef | 612 | atomic_t mq_freeze_depth; |
d732580b | 613 | |
d351af01 | 614 | #if defined(CONFIG_BLK_DEV_BSG) |
aa387cc8 | 615 | bsg_job_fn *bsg_job_fn; |
d351af01 FT |
616 | struct bsg_class_device bsg_dev; |
617 | #endif | |
e43473b7 VG |
618 | |
619 | #ifdef CONFIG_BLK_DEV_THROTTLING | |
620 | /* Throttle data */ | |
621 | struct throtl_data *td; | |
622 | #endif | |
548bc8e1 | 623 | struct rcu_head rcu_head; |
320ae51f | 624 | wait_queue_head_t mq_freeze_wq; |
3ef28e83 | 625 | struct percpu_ref q_usage_counter; |
320ae51f | 626 | struct list_head all_q_node; |
0d2602ca JA |
627 | |
628 | struct blk_mq_tag_set *tag_set; | |
629 | struct list_head tag_set_list; | |
54efd50b | 630 | struct bio_set *bio_split; |
4593fdbe | 631 | |
03796c14 | 632 | #ifdef CONFIG_BLK_DEBUG_FS |
07e4fead | 633 | struct dentry *debugfs_dir; |
d332ce09 | 634 | struct dentry *sched_debugfs_dir; |
07e4fead OS |
635 | #endif |
636 | ||
4593fdbe | 637 | bool mq_sysfs_init_done; |
6d247d7f CH |
638 | |
639 | size_t cmd_size; | |
640 | void *rq_alloc_data; | |
dc9edc44 BVA |
641 | |
642 | struct work_struct release_work; | |
f793dfd3 JA |
643 | |
644 | #define BLK_MAX_WRITE_HINTS 5 | |
645 | u64 write_hints[BLK_MAX_WRITE_HINTS]; | |
1da177e4 LT |
646 | }; |
647 | ||
e743eb1e JA |
648 | #define QUEUE_FLAG_QUEUED 0 /* uses generic tag queueing */ |
649 | #define QUEUE_FLAG_STOPPED 1 /* queue is stopped */ | |
650 | #define QUEUE_FLAG_DYING 2 /* queue being torn down */ | |
651 | #define QUEUE_FLAG_BYPASS 3 /* act as dumb FIFO queue */ | |
652 | #define QUEUE_FLAG_BIDI 4 /* queue supports bidi requests */ | |
653 | #define QUEUE_FLAG_NOMERGES 5 /* disable merge attempts */ | |
654 | #define QUEUE_FLAG_SAME_COMP 6 /* complete on same CPU-group */ | |
655 | #define QUEUE_FLAG_FAIL_IO 7 /* fake timeout */ | |
e743eb1e | 656 | #define QUEUE_FLAG_NONROT 9 /* non-rotational device (SSD) */ |
88e740f1 | 657 | #define QUEUE_FLAG_VIRT QUEUE_FLAG_NONROT /* paravirt device */ |
e743eb1e JA |
658 | #define QUEUE_FLAG_IO_STAT 10 /* do IO stats */ |
659 | #define QUEUE_FLAG_DISCARD 11 /* supports DISCARD */ | |
660 | #define QUEUE_FLAG_NOXMERGES 12 /* No extended merges */ | |
661 | #define QUEUE_FLAG_ADD_RANDOM 13 /* Contributes to random pool */ | |
662 | #define QUEUE_FLAG_SECERASE 14 /* supports secure erase */ | |
663 | #define QUEUE_FLAG_SAME_FORCE 15 /* force complete on same CPU */ | |
664 | #define QUEUE_FLAG_DEAD 16 /* queue tear-down finished */ | |
665 | #define QUEUE_FLAG_INIT_DONE 17 /* queue is initialized */ | |
666 | #define QUEUE_FLAG_NO_SG_MERGE 18 /* don't attempt to merge SG segments*/ | |
667 | #define QUEUE_FLAG_POLL 19 /* IO polling enabled if set */ | |
668 | #define QUEUE_FLAG_WC 20 /* Write back caching */ | |
669 | #define QUEUE_FLAG_FUA 21 /* device supports FUA writes */ | |
670 | #define QUEUE_FLAG_FLUSH_NQ 22 /* flush not queueuable */ | |
671 | #define QUEUE_FLAG_DAX 23 /* device supports DAX */ | |
672 | #define QUEUE_FLAG_STATS 24 /* track rq completion times */ | |
673 | #define QUEUE_FLAG_POLL_STATS 25 /* collecting stats for hybrid polling */ | |
674 | #define QUEUE_FLAG_REGISTERED 26 /* queue has been registered to a disk */ | |
675 | #define QUEUE_FLAG_SCSI_PASSTHROUGH 27 /* queue supports SCSI commands */ | |
676 | #define QUEUE_FLAG_QUIESCED 28 /* queue has been quiesced */ | |
c9254f2d | 677 | #define QUEUE_FLAG_PREEMPT_ONLY 29 /* only process REQ_PREEMPT requests */ |
bc58ba94 JA |
678 | |
679 | #define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ | |
e2e1a148 JA |
680 | (1 << QUEUE_FLAG_SAME_COMP) | \ |
681 | (1 << QUEUE_FLAG_ADD_RANDOM)) | |
797e7dbb | 682 | |
94eddfbe | 683 | #define QUEUE_FLAG_MQ_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ |
8e0b60b9 CH |
684 | (1 << QUEUE_FLAG_SAME_COMP) | \ |
685 | (1 << QUEUE_FLAG_POLL)) | |
94eddfbe | 686 | |
9e0c8299 BVA |
687 | /* |
688 | * @q->queue_lock is set while a queue is being initialized. Since we know | |
689 | * that no other threads access the queue object before @q->queue_lock has | |
690 | * been set, it is safe to manipulate queue flags without holding the | |
691 | * queue_lock if @q->queue_lock == NULL. See also blk_alloc_queue_node() and | |
692 | * blk_init_allocated_queue(). | |
693 | */ | |
8bcb6c7d | 694 | static inline void queue_lockdep_assert_held(struct request_queue *q) |
8f45c1a5 | 695 | { |
8bcb6c7d AK |
696 | if (q->queue_lock) |
697 | lockdep_assert_held(q->queue_lock); | |
8f45c1a5 LT |
698 | } |
699 | ||
75ad23bc NP |
700 | static inline void queue_flag_set_unlocked(unsigned int flag, |
701 | struct request_queue *q) | |
702 | { | |
703 | __set_bit(flag, &q->queue_flags); | |
704 | } | |
705 | ||
e48ec690 JA |
706 | static inline int queue_flag_test_and_clear(unsigned int flag, |
707 | struct request_queue *q) | |
708 | { | |
8bcb6c7d | 709 | queue_lockdep_assert_held(q); |
e48ec690 JA |
710 | |
711 | if (test_bit(flag, &q->queue_flags)) { | |
712 | __clear_bit(flag, &q->queue_flags); | |
713 | return 1; | |
714 | } | |
715 | ||
716 | return 0; | |
717 | } | |
718 | ||
719 | static inline int queue_flag_test_and_set(unsigned int flag, | |
720 | struct request_queue *q) | |
721 | { | |
8bcb6c7d | 722 | queue_lockdep_assert_held(q); |
e48ec690 JA |
723 | |
724 | if (!test_bit(flag, &q->queue_flags)) { | |
725 | __set_bit(flag, &q->queue_flags); | |
726 | return 0; | |
727 | } | |
728 | ||
729 | return 1; | |
730 | } | |
731 | ||
75ad23bc NP |
732 | static inline void queue_flag_set(unsigned int flag, struct request_queue *q) |
733 | { | |
8bcb6c7d | 734 | queue_lockdep_assert_held(q); |
75ad23bc NP |
735 | __set_bit(flag, &q->queue_flags); |
736 | } | |
737 | ||
738 | static inline void queue_flag_clear_unlocked(unsigned int flag, | |
739 | struct request_queue *q) | |
740 | { | |
741 | __clear_bit(flag, &q->queue_flags); | |
742 | } | |
743 | ||
0a7ae2ff JA |
744 | static inline int queue_in_flight(struct request_queue *q) |
745 | { | |
746 | return q->in_flight[0] + q->in_flight[1]; | |
747 | } | |
748 | ||
75ad23bc NP |
749 | static inline void queue_flag_clear(unsigned int flag, struct request_queue *q) |
750 | { | |
8bcb6c7d | 751 | queue_lockdep_assert_held(q); |
75ad23bc NP |
752 | __clear_bit(flag, &q->queue_flags); |
753 | } | |
754 | ||
1da177e4 LT |
755 | #define blk_queue_tagged(q) test_bit(QUEUE_FLAG_QUEUED, &(q)->queue_flags) |
756 | #define blk_queue_stopped(q) test_bit(QUEUE_FLAG_STOPPED, &(q)->queue_flags) | |
3f3299d5 | 757 | #define blk_queue_dying(q) test_bit(QUEUE_FLAG_DYING, &(q)->queue_flags) |
c246e80d | 758 | #define blk_queue_dead(q) test_bit(QUEUE_FLAG_DEAD, &(q)->queue_flags) |
d732580b | 759 | #define blk_queue_bypass(q) test_bit(QUEUE_FLAG_BYPASS, &(q)->queue_flags) |
320ae51f | 760 | #define blk_queue_init_done(q) test_bit(QUEUE_FLAG_INIT_DONE, &(q)->queue_flags) |
ac9fafa1 | 761 | #define blk_queue_nomerges(q) test_bit(QUEUE_FLAG_NOMERGES, &(q)->queue_flags) |
488991e2 AB |
762 | #define blk_queue_noxmerges(q) \ |
763 | test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags) | |
a68bbddb | 764 | #define blk_queue_nonrot(q) test_bit(QUEUE_FLAG_NONROT, &(q)->queue_flags) |
bc58ba94 | 765 | #define blk_queue_io_stat(q) test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags) |
e2e1a148 | 766 | #define blk_queue_add_random(q) test_bit(QUEUE_FLAG_ADD_RANDOM, &(q)->queue_flags) |
c15227de | 767 | #define blk_queue_discard(q) test_bit(QUEUE_FLAG_DISCARD, &(q)->queue_flags) |
288dab8a CH |
768 | #define blk_queue_secure_erase(q) \ |
769 | (test_bit(QUEUE_FLAG_SECERASE, &(q)->queue_flags)) | |
163d4baa | 770 | #define blk_queue_dax(q) test_bit(QUEUE_FLAG_DAX, &(q)->queue_flags) |
9efc160f BVA |
771 | #define blk_queue_scsi_passthrough(q) \ |
772 | test_bit(QUEUE_FLAG_SCSI_PASSTHROUGH, &(q)->queue_flags) | |
1da177e4 | 773 | |
33659ebb CH |
774 | #define blk_noretry_request(rq) \ |
775 | ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \ | |
776 | REQ_FAILFAST_DRIVER)) | |
f4560ffe | 777 | #define blk_queue_quiesced(q) test_bit(QUEUE_FLAG_QUIESCED, &(q)->queue_flags) |
c9254f2d BVA |
778 | #define blk_queue_preempt_only(q) \ |
779 | test_bit(QUEUE_FLAG_PREEMPT_ONLY, &(q)->queue_flags) | |
780 | ||
781 | extern int blk_set_preempt_only(struct request_queue *q); | |
782 | extern void blk_clear_preempt_only(struct request_queue *q); | |
33659ebb | 783 | |
57292b58 CH |
784 | static inline bool blk_account_rq(struct request *rq) |
785 | { | |
786 | return (rq->rq_flags & RQF_STARTED) && !blk_rq_is_passthrough(rq); | |
787 | } | |
33659ebb | 788 | |
ab780f1e | 789 | #define blk_rq_cpu_valid(rq) ((rq)->cpu != -1) |
abae1fde | 790 | #define blk_bidi_rq(rq) ((rq)->next_rq != NULL) |
336cdb40 KU |
791 | /* rq->queuelist of dequeued request must be list_empty() */ |
792 | #define blk_queued_rq(rq) (!list_empty(&(rq)->queuelist)) | |
1da177e4 LT |
793 | |
794 | #define list_entry_rq(ptr) list_entry((ptr), struct request, queuelist) | |
795 | ||
4e1b2d52 | 796 | #define rq_data_dir(rq) (op_is_write(req_op(rq)) ? WRITE : READ) |
1da177e4 | 797 | |
49fd524f JA |
798 | /* |
799 | * Driver can handle struct request, if it either has an old style | |
800 | * request_fn defined, or is blk-mq based. | |
801 | */ | |
802 | static inline bool queue_is_rq_based(struct request_queue *q) | |
803 | { | |
804 | return q->request_fn || q->mq_ops; | |
805 | } | |
806 | ||
e692cb66 MP |
807 | static inline unsigned int blk_queue_cluster(struct request_queue *q) |
808 | { | |
809 | return q->limits.cluster; | |
810 | } | |
811 | ||
797476b8 DLM |
812 | static inline enum blk_zoned_model |
813 | blk_queue_zoned_model(struct request_queue *q) | |
814 | { | |
815 | return q->limits.zoned; | |
816 | } | |
817 | ||
818 | static inline bool blk_queue_is_zoned(struct request_queue *q) | |
819 | { | |
820 | switch (blk_queue_zoned_model(q)) { | |
821 | case BLK_ZONED_HA: | |
822 | case BLK_ZONED_HM: | |
823 | return true; | |
824 | default: | |
825 | return false; | |
826 | } | |
827 | } | |
828 | ||
f99e8648 | 829 | static inline unsigned int blk_queue_zone_sectors(struct request_queue *q) |
6a0cb1bc HR |
830 | { |
831 | return blk_queue_is_zoned(q) ? q->limits.chunk_sectors : 0; | |
832 | } | |
833 | ||
6cc77e9c CH |
834 | static inline unsigned int blk_queue_nr_zones(struct request_queue *q) |
835 | { | |
836 | return q->nr_zones; | |
837 | } | |
838 | ||
839 | static inline unsigned int blk_queue_zone_no(struct request_queue *q, | |
840 | sector_t sector) | |
841 | { | |
842 | if (!blk_queue_is_zoned(q)) | |
843 | return 0; | |
844 | return sector >> ilog2(q->limits.chunk_sectors); | |
845 | } | |
846 | ||
847 | static inline bool blk_queue_zone_is_seq(struct request_queue *q, | |
848 | sector_t sector) | |
849 | { | |
850 | if (!blk_queue_is_zoned(q) || !q->seq_zones_bitmap) | |
851 | return false; | |
852 | return test_bit(blk_queue_zone_no(q, sector), q->seq_zones_bitmap); | |
853 | } | |
854 | ||
1faa16d2 JA |
855 | static inline bool rq_is_sync(struct request *rq) |
856 | { | |
ef295ecf | 857 | return op_is_sync(rq->cmd_flags); |
1faa16d2 JA |
858 | } |
859 | ||
5b788ce3 | 860 | static inline bool blk_rl_full(struct request_list *rl, bool sync) |
1da177e4 | 861 | { |
5b788ce3 TH |
862 | unsigned int flag = sync ? BLK_RL_SYNCFULL : BLK_RL_ASYNCFULL; |
863 | ||
864 | return rl->flags & flag; | |
1da177e4 LT |
865 | } |
866 | ||
5b788ce3 | 867 | static inline void blk_set_rl_full(struct request_list *rl, bool sync) |
1da177e4 | 868 | { |
5b788ce3 TH |
869 | unsigned int flag = sync ? BLK_RL_SYNCFULL : BLK_RL_ASYNCFULL; |
870 | ||
871 | rl->flags |= flag; | |
1da177e4 LT |
872 | } |
873 | ||
5b788ce3 | 874 | static inline void blk_clear_rl_full(struct request_list *rl, bool sync) |
1da177e4 | 875 | { |
5b788ce3 TH |
876 | unsigned int flag = sync ? BLK_RL_SYNCFULL : BLK_RL_ASYNCFULL; |
877 | ||
878 | rl->flags &= ~flag; | |
1da177e4 LT |
879 | } |
880 | ||
e2a60da7 MP |
881 | static inline bool rq_mergeable(struct request *rq) |
882 | { | |
57292b58 | 883 | if (blk_rq_is_passthrough(rq)) |
e2a60da7 | 884 | return false; |
1da177e4 | 885 | |
3a5e02ce MC |
886 | if (req_op(rq) == REQ_OP_FLUSH) |
887 | return false; | |
888 | ||
a6f0788e CK |
889 | if (req_op(rq) == REQ_OP_WRITE_ZEROES) |
890 | return false; | |
891 | ||
e2a60da7 | 892 | if (rq->cmd_flags & REQ_NOMERGE_FLAGS) |
e8064021 CH |
893 | return false; |
894 | if (rq->rq_flags & RQF_NOMERGE_FLAGS) | |
e2a60da7 MP |
895 | return false; |
896 | ||
897 | return true; | |
898 | } | |
1da177e4 | 899 | |
4363ac7c MP |
900 | static inline bool blk_write_same_mergeable(struct bio *a, struct bio *b) |
901 | { | |
efbeccdb CH |
902 | if (bio_page(a) == bio_page(b) && |
903 | bio_offset(a) == bio_offset(b)) | |
4363ac7c MP |
904 | return true; |
905 | ||
906 | return false; | |
907 | } | |
908 | ||
d278d4a8 JA |
909 | static inline unsigned int blk_queue_depth(struct request_queue *q) |
910 | { | |
911 | if (q->queue_depth) | |
912 | return q->queue_depth; | |
913 | ||
914 | return q->nr_requests; | |
915 | } | |
916 | ||
1da177e4 LT |
917 | /* |
918 | * q->prep_rq_fn return values | |
919 | */ | |
0fb5b1fb MP |
920 | enum { |
921 | BLKPREP_OK, /* serve it */ | |
922 | BLKPREP_KILL, /* fatal error, kill, return -EIO */ | |
923 | BLKPREP_DEFER, /* leave on queue */ | |
924 | BLKPREP_INVALID, /* invalid command, kill, return -EREMOTEIO */ | |
925 | }; | |
1da177e4 LT |
926 | |
927 | extern unsigned long blk_max_low_pfn, blk_max_pfn; | |
928 | ||
929 | /* | |
930 | * standard bounce addresses: | |
931 | * | |
932 | * BLK_BOUNCE_HIGH : bounce all highmem pages | |
933 | * BLK_BOUNCE_ANY : don't bounce anything | |
934 | * BLK_BOUNCE_ISA : bounce pages above ISA DMA boundary | |
935 | */ | |
2472892a AK |
936 | |
937 | #if BITS_PER_LONG == 32 | |
1da177e4 | 938 | #define BLK_BOUNCE_HIGH ((u64)blk_max_low_pfn << PAGE_SHIFT) |
2472892a AK |
939 | #else |
940 | #define BLK_BOUNCE_HIGH -1ULL | |
941 | #endif | |
942 | #define BLK_BOUNCE_ANY (-1ULL) | |
bfe17231 | 943 | #define BLK_BOUNCE_ISA (DMA_BIT_MASK(24)) |
1da177e4 | 944 | |
3d6392cf JA |
945 | /* |
946 | * default timeout for SG_IO if none specified | |
947 | */ | |
948 | #define BLK_DEFAULT_SG_TIMEOUT (60 * HZ) | |
f2f1fa78 | 949 | #define BLK_MIN_SG_TIMEOUT (7 * HZ) |
3d6392cf | 950 | |
152e283f FT |
951 | struct rq_map_data { |
952 | struct page **pages; | |
953 | int page_order; | |
954 | int nr_entries; | |
56c451f4 | 955 | unsigned long offset; |
97ae77a1 | 956 | int null_mapped; |
ecb554a8 | 957 | int from_user; |
152e283f FT |
958 | }; |
959 | ||
5705f702 | 960 | struct req_iterator { |
7988613b | 961 | struct bvec_iter iter; |
5705f702 N |
962 | struct bio *bio; |
963 | }; | |
964 | ||
965 | /* This should not be used directly - use rq_for_each_segment */ | |
1e428079 JA |
966 | #define for_each_bio(_bio) \ |
967 | for (; _bio; _bio = _bio->bi_next) | |
5705f702 | 968 | #define __rq_for_each_bio(_bio, rq) \ |
1da177e4 LT |
969 | if ((rq->bio)) \ |
970 | for (_bio = (rq)->bio; _bio; _bio = _bio->bi_next) | |
971 | ||
5705f702 N |
972 | #define rq_for_each_segment(bvl, _rq, _iter) \ |
973 | __rq_for_each_bio(_iter.bio, _rq) \ | |
7988613b | 974 | bio_for_each_segment(bvl, _iter.bio, _iter.iter) |
5705f702 | 975 | |
4550dd6c | 976 | #define rq_iter_last(bvec, _iter) \ |
7988613b | 977 | (_iter.bio->bi_next == NULL && \ |
4550dd6c | 978 | bio_iter_last(bvec, _iter.iter)) |
5705f702 | 979 | |
2d4dc890 IL |
980 | #ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE |
981 | # error "You should define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform" | |
982 | #endif | |
983 | #if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE | |
984 | extern void rq_flush_dcache_pages(struct request *rq); | |
985 | #else | |
986 | static inline void rq_flush_dcache_pages(struct request *rq) | |
987 | { | |
988 | } | |
989 | #endif | |
990 | ||
1da177e4 LT |
991 | extern int blk_register_queue(struct gendisk *disk); |
992 | extern void blk_unregister_queue(struct gendisk *disk); | |
dece1635 | 993 | extern blk_qc_t generic_make_request(struct bio *bio); |
f421e1d9 | 994 | extern blk_qc_t direct_make_request(struct bio *bio); |
2a4aa30c | 995 | extern void blk_rq_init(struct request_queue *q, struct request *rq); |
da8d7f07 | 996 | extern void blk_init_request_from_bio(struct request *req, struct bio *bio); |
1da177e4 | 997 | extern void blk_put_request(struct request *); |
165125e1 | 998 | extern void __blk_put_request(struct request_queue *, struct request *); |
6a15674d BVA |
999 | extern struct request *blk_get_request_flags(struct request_queue *, |
1000 | unsigned int op, | |
9a95e4ef | 1001 | blk_mq_req_flags_t flags); |
cd6ce148 BVA |
1002 | extern struct request *blk_get_request(struct request_queue *, unsigned int op, |
1003 | gfp_t gfp_mask); | |
165125e1 | 1004 | extern void blk_requeue_request(struct request_queue *, struct request *); |
ef9e3fac | 1005 | extern int blk_lld_busy(struct request_queue *q); |
78d8e58a MS |
1006 | extern int blk_rq_prep_clone(struct request *rq, struct request *rq_src, |
1007 | struct bio_set *bs, gfp_t gfp_mask, | |
1008 | int (*bio_ctr)(struct bio *, struct bio *, void *), | |
1009 | void *data); | |
1010 | extern void blk_rq_unprep_clone(struct request *rq); | |
2a842aca | 1011 | extern blk_status_t blk_insert_cloned_request(struct request_queue *q, |
82124d60 | 1012 | struct request *rq); |
98d61d5b | 1013 | extern int blk_rq_append_bio(struct request *rq, struct bio *bio); |
3cca6dc1 | 1014 | extern void blk_delay_queue(struct request_queue *, unsigned long); |
af67c31f | 1015 | extern void blk_queue_split(struct request_queue *, struct bio **); |
165125e1 | 1016 | extern void blk_recount_segments(struct request_queue *, struct bio *); |
0bfc96cb | 1017 | extern int scsi_verify_blk_ioctl(struct block_device *, unsigned int); |
577ebb37 PB |
1018 | extern int scsi_cmd_blk_ioctl(struct block_device *, fmode_t, |
1019 | unsigned int, void __user *); | |
74f3c8af AV |
1020 | extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t, |
1021 | unsigned int, void __user *); | |
e915e872 AV |
1022 | extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t, |
1023 | struct scsi_ioctl_command __user *); | |
3fcfab16 | 1024 | |
9a95e4ef | 1025 | extern int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags); |
2e6edc95 | 1026 | extern void blk_queue_exit(struct request_queue *q); |
165125e1 | 1027 | extern void blk_start_queue(struct request_queue *q); |
21491412 | 1028 | extern void blk_start_queue_async(struct request_queue *q); |
165125e1 | 1029 | extern void blk_stop_queue(struct request_queue *q); |
1da177e4 | 1030 | extern void blk_sync_queue(struct request_queue *q); |
165125e1 | 1031 | extern void __blk_stop_queue(struct request_queue *q); |
24ecfbe2 | 1032 | extern void __blk_run_queue(struct request_queue *q); |
a7928c15 | 1033 | extern void __blk_run_queue_uncond(struct request_queue *q); |
165125e1 | 1034 | extern void blk_run_queue(struct request_queue *); |
c21e6beb | 1035 | extern void blk_run_queue_async(struct request_queue *q); |
a3bce90e | 1036 | extern int blk_rq_map_user(struct request_queue *, struct request *, |
152e283f FT |
1037 | struct rq_map_data *, void __user *, unsigned long, |
1038 | gfp_t); | |
8e5cfc45 | 1039 | extern int blk_rq_unmap_user(struct bio *); |
165125e1 JA |
1040 | extern int blk_rq_map_kern(struct request_queue *, struct request *, void *, unsigned int, gfp_t); |
1041 | extern int blk_rq_map_user_iov(struct request_queue *, struct request *, | |
26e49cfc KO |
1042 | struct rq_map_data *, const struct iov_iter *, |
1043 | gfp_t); | |
b7819b92 | 1044 | extern void blk_execute_rq(struct request_queue *, struct gendisk *, |
994ca9a1 | 1045 | struct request *, int); |
165125e1 | 1046 | extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *, |
15fc858a | 1047 | struct request *, int, rq_end_io_fn *); |
6e39b69e | 1048 | |
2a842aca CH |
1049 | int blk_status_to_errno(blk_status_t status); |
1050 | blk_status_t errno_to_blk_status(int errno); | |
1051 | ||
ea435e1b | 1052 | bool blk_poll(struct request_queue *q, blk_qc_t cookie); |
05229bee | 1053 | |
165125e1 | 1054 | static inline struct request_queue *bdev_get_queue(struct block_device *bdev) |
1da177e4 | 1055 | { |
ff9ea323 | 1056 | return bdev->bd_disk->queue; /* this is never NULL */ |
1da177e4 LT |
1057 | } |
1058 | ||
5efccd17 | 1059 | /* |
80a761fd TH |
1060 | * blk_rq_pos() : the current sector |
1061 | * blk_rq_bytes() : bytes left in the entire request | |
1062 | * blk_rq_cur_bytes() : bytes left in the current segment | |
1063 | * blk_rq_err_bytes() : bytes left till the next error boundary | |
1064 | * blk_rq_sectors() : sectors left in the entire request | |
1065 | * blk_rq_cur_sectors() : sectors left in the current segment | |
5efccd17 | 1066 | */ |
5b93629b TH |
1067 | static inline sector_t blk_rq_pos(const struct request *rq) |
1068 | { | |
a2dec7b3 | 1069 | return rq->__sector; |
2e46e8b2 TH |
1070 | } |
1071 | ||
1072 | static inline unsigned int blk_rq_bytes(const struct request *rq) | |
1073 | { | |
a2dec7b3 | 1074 | return rq->__data_len; |
5b93629b TH |
1075 | } |
1076 | ||
2e46e8b2 TH |
1077 | static inline int blk_rq_cur_bytes(const struct request *rq) |
1078 | { | |
1079 | return rq->bio ? bio_cur_bytes(rq->bio) : 0; | |
1080 | } | |
5efccd17 | 1081 | |
80a761fd TH |
1082 | extern unsigned int blk_rq_err_bytes(const struct request *rq); |
1083 | ||
5b93629b TH |
1084 | static inline unsigned int blk_rq_sectors(const struct request *rq) |
1085 | { | |
2e46e8b2 | 1086 | return blk_rq_bytes(rq) >> 9; |
5b93629b TH |
1087 | } |
1088 | ||
1089 | static inline unsigned int blk_rq_cur_sectors(const struct request *rq) | |
1090 | { | |
2e46e8b2 | 1091 | return blk_rq_cur_bytes(rq) >> 9; |
5b93629b TH |
1092 | } |
1093 | ||
6cc77e9c CH |
1094 | static inline unsigned int blk_rq_zone_no(struct request *rq) |
1095 | { | |
1096 | return blk_queue_zone_no(rq->q, blk_rq_pos(rq)); | |
1097 | } | |
1098 | ||
1099 | static inline unsigned int blk_rq_zone_is_seq(struct request *rq) | |
1100 | { | |
1101 | return blk_queue_zone_is_seq(rq->q, blk_rq_pos(rq)); | |
1102 | } | |
1103 | ||
2e3258ec CH |
1104 | /* |
1105 | * Some commands like WRITE SAME have a payload or data transfer size which | |
1106 | * is different from the size of the request. Any driver that supports such | |
1107 | * commands using the RQF_SPECIAL_PAYLOAD flag needs to use this helper to | |
1108 | * calculate the data transfer size. | |
1109 | */ | |
1110 | static inline unsigned int blk_rq_payload_bytes(struct request *rq) | |
1111 | { | |
1112 | if (rq->rq_flags & RQF_SPECIAL_PAYLOAD) | |
1113 | return rq->special_vec.bv_len; | |
1114 | return blk_rq_bytes(rq); | |
1115 | } | |
1116 | ||
f31dc1cd | 1117 | static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q, |
8fe0d473 | 1118 | int op) |
f31dc1cd | 1119 | { |
7afafc8a | 1120 | if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE)) |
871dd928 | 1121 | return min(q->limits.max_discard_sectors, UINT_MAX >> 9); |
f31dc1cd | 1122 | |
8fe0d473 | 1123 | if (unlikely(op == REQ_OP_WRITE_SAME)) |
4363ac7c MP |
1124 | return q->limits.max_write_same_sectors; |
1125 | ||
a6f0788e CK |
1126 | if (unlikely(op == REQ_OP_WRITE_ZEROES)) |
1127 | return q->limits.max_write_zeroes_sectors; | |
1128 | ||
f31dc1cd MP |
1129 | return q->limits.max_sectors; |
1130 | } | |
1131 | ||
762380ad JA |
1132 | /* |
1133 | * Return maximum size of a request at given offset. Only valid for | |
1134 | * file system requests. | |
1135 | */ | |
1136 | static inline unsigned int blk_max_size_offset(struct request_queue *q, | |
1137 | sector_t offset) | |
1138 | { | |
1139 | if (!q->limits.chunk_sectors) | |
736ed4de | 1140 | return q->limits.max_sectors; |
762380ad JA |
1141 | |
1142 | return q->limits.chunk_sectors - | |
1143 | (offset & (q->limits.chunk_sectors - 1)); | |
1144 | } | |
1145 | ||
17007f39 DLM |
1146 | static inline unsigned int blk_rq_get_max_sectors(struct request *rq, |
1147 | sector_t offset) | |
f31dc1cd MP |
1148 | { |
1149 | struct request_queue *q = rq->q; | |
1150 | ||
57292b58 | 1151 | if (blk_rq_is_passthrough(rq)) |
f31dc1cd MP |
1152 | return q->limits.max_hw_sectors; |
1153 | ||
7afafc8a AH |
1154 | if (!q->limits.chunk_sectors || |
1155 | req_op(rq) == REQ_OP_DISCARD || | |
1156 | req_op(rq) == REQ_OP_SECURE_ERASE) | |
8fe0d473 | 1157 | return blk_queue_get_max_sectors(q, req_op(rq)); |
762380ad | 1158 | |
17007f39 | 1159 | return min(blk_max_size_offset(q, offset), |
8fe0d473 | 1160 | blk_queue_get_max_sectors(q, req_op(rq))); |
f31dc1cd MP |
1161 | } |
1162 | ||
75afb352 JN |
1163 | static inline unsigned int blk_rq_count_bios(struct request *rq) |
1164 | { | |
1165 | unsigned int nr_bios = 0; | |
1166 | struct bio *bio; | |
1167 | ||
1168 | __rq_for_each_bio(bio, rq) | |
1169 | nr_bios++; | |
1170 | ||
1171 | return nr_bios; | |
1172 | } | |
1173 | ||
9934c8c0 TH |
1174 | /* |
1175 | * Request issue related functions. | |
1176 | */ | |
1177 | extern struct request *blk_peek_request(struct request_queue *q); | |
1178 | extern void blk_start_request(struct request *rq); | |
1179 | extern struct request *blk_fetch_request(struct request_queue *q); | |
1180 | ||
ef71de8b CH |
1181 | void blk_steal_bios(struct bio_list *list, struct request *rq); |
1182 | ||
1da177e4 | 1183 | /* |
2e60e022 TH |
1184 | * Request completion related functions. |
1185 | * | |
1186 | * blk_update_request() completes given number of bytes and updates | |
1187 | * the request without completing it. | |
1188 | * | |
f06d9a2b TH |
1189 | * blk_end_request() and friends. __blk_end_request() must be called |
1190 | * with the request queue spinlock acquired. | |
1da177e4 LT |
1191 | * |
1192 | * Several drivers define their own end_request and call | |
3bcddeac KU |
1193 | * blk_end_request() for parts of the original function. |
1194 | * This prevents code duplication in drivers. | |
1da177e4 | 1195 | */ |
2a842aca | 1196 | extern bool blk_update_request(struct request *rq, blk_status_t error, |
2e60e022 | 1197 | unsigned int nr_bytes); |
2a842aca CH |
1198 | extern void blk_finish_request(struct request *rq, blk_status_t error); |
1199 | extern bool blk_end_request(struct request *rq, blk_status_t error, | |
b1f74493 | 1200 | unsigned int nr_bytes); |
2a842aca CH |
1201 | extern void blk_end_request_all(struct request *rq, blk_status_t error); |
1202 | extern bool __blk_end_request(struct request *rq, blk_status_t error, | |
b1f74493 | 1203 | unsigned int nr_bytes); |
2a842aca CH |
1204 | extern void __blk_end_request_all(struct request *rq, blk_status_t error); |
1205 | extern bool __blk_end_request_cur(struct request *rq, blk_status_t error); | |
2e60e022 | 1206 | |
ff856bad | 1207 | extern void blk_complete_request(struct request *); |
242f9dcb JA |
1208 | extern void __blk_complete_request(struct request *); |
1209 | extern void blk_abort_request(struct request *); | |
28018c24 | 1210 | extern void blk_unprep_request(struct request *); |
ff856bad | 1211 | |
1da177e4 LT |
1212 | /* |
1213 | * Access functions for manipulating queue properties | |
1214 | */ | |
165125e1 | 1215 | extern struct request_queue *blk_init_queue_node(request_fn_proc *rfn, |
1946089a | 1216 | spinlock_t *lock, int node_id); |
165125e1 | 1217 | extern struct request_queue *blk_init_queue(request_fn_proc *, spinlock_t *); |
5ea708d1 | 1218 | extern int blk_init_allocated_queue(struct request_queue *); |
165125e1 JA |
1219 | extern void blk_cleanup_queue(struct request_queue *); |
1220 | extern void blk_queue_make_request(struct request_queue *, make_request_fn *); | |
1221 | extern void blk_queue_bounce_limit(struct request_queue *, u64); | |
086fa5ff | 1222 | extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int); |
762380ad | 1223 | extern void blk_queue_chunk_sectors(struct request_queue *, unsigned int); |
8a78362c | 1224 | extern void blk_queue_max_segments(struct request_queue *, unsigned short); |
1e739730 CH |
1225 | extern void blk_queue_max_discard_segments(struct request_queue *, |
1226 | unsigned short); | |
165125e1 | 1227 | extern void blk_queue_max_segment_size(struct request_queue *, unsigned int); |
67efc925 CH |
1228 | extern void blk_queue_max_discard_sectors(struct request_queue *q, |
1229 | unsigned int max_discard_sectors); | |
4363ac7c MP |
1230 | extern void blk_queue_max_write_same_sectors(struct request_queue *q, |
1231 | unsigned int max_write_same_sectors); | |
a6f0788e CK |
1232 | extern void blk_queue_max_write_zeroes_sectors(struct request_queue *q, |
1233 | unsigned int max_write_same_sectors); | |
e1defc4f | 1234 | extern void blk_queue_logical_block_size(struct request_queue *, unsigned short); |
892b6f90 | 1235 | extern void blk_queue_physical_block_size(struct request_queue *, unsigned int); |
c72758f3 MP |
1236 | extern void blk_queue_alignment_offset(struct request_queue *q, |
1237 | unsigned int alignment); | |
7c958e32 | 1238 | extern void blk_limits_io_min(struct queue_limits *limits, unsigned int min); |
c72758f3 | 1239 | extern void blk_queue_io_min(struct request_queue *q, unsigned int min); |
3c5820c7 | 1240 | extern void blk_limits_io_opt(struct queue_limits *limits, unsigned int opt); |
c72758f3 | 1241 | extern void blk_queue_io_opt(struct request_queue *q, unsigned int opt); |
d278d4a8 | 1242 | extern void blk_set_queue_depth(struct request_queue *q, unsigned int depth); |
e475bba2 | 1243 | extern void blk_set_default_limits(struct queue_limits *lim); |
b1bd055d | 1244 | extern void blk_set_stacking_limits(struct queue_limits *lim); |
c72758f3 MP |
1245 | extern int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, |
1246 | sector_t offset); | |
17be8c24 MP |
1247 | extern int bdev_stack_limits(struct queue_limits *t, struct block_device *bdev, |
1248 | sector_t offset); | |
c72758f3 MP |
1249 | extern void disk_stack_limits(struct gendisk *disk, struct block_device *bdev, |
1250 | sector_t offset); | |
165125e1 | 1251 | extern void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b); |
e3790c7d | 1252 | extern void blk_queue_dma_pad(struct request_queue *, unsigned int); |
27f8221a | 1253 | extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int); |
2fb98e84 TH |
1254 | extern int blk_queue_dma_drain(struct request_queue *q, |
1255 | dma_drain_needed_fn *dma_drain_needed, | |
1256 | void *buf, unsigned int size); | |
ef9e3fac | 1257 | extern void blk_queue_lld_busy(struct request_queue *q, lld_busy_fn *fn); |
165125e1 | 1258 | extern void blk_queue_segment_boundary(struct request_queue *, unsigned long); |
03100aad | 1259 | extern void blk_queue_virt_boundary(struct request_queue *, unsigned long); |
165125e1 | 1260 | extern void blk_queue_prep_rq(struct request_queue *, prep_rq_fn *pfn); |
28018c24 | 1261 | extern void blk_queue_unprep_rq(struct request_queue *, unprep_rq_fn *ufn); |
165125e1 | 1262 | extern void blk_queue_dma_alignment(struct request_queue *, int); |
11c3e689 | 1263 | extern void blk_queue_update_dma_alignment(struct request_queue *, int); |
165125e1 | 1264 | extern void blk_queue_softirq_done(struct request_queue *, softirq_done_fn *); |
242f9dcb JA |
1265 | extern void blk_queue_rq_timed_out(struct request_queue *, rq_timed_out_fn *); |
1266 | extern void blk_queue_rq_timeout(struct request_queue *, unsigned int); | |
f3876930 | 1267 | extern void blk_queue_flush_queueable(struct request_queue *q, bool queueable); |
93e9d8e8 | 1268 | extern void blk_queue_write_cache(struct request_queue *q, bool enabled, bool fua); |
1da177e4 | 1269 | |
1e739730 CH |
1270 | /* |
1271 | * Number of physical segments as sent to the device. | |
1272 | * | |
1273 | * Normally this is the number of discontiguous data segments sent by the | |
1274 | * submitter. But for data-less command like discard we might have no | |
1275 | * actual data segments submitted, but the driver might have to add it's | |
1276 | * own special payload. In that case we still return 1 here so that this | |
1277 | * special payload will be mapped. | |
1278 | */ | |
f9d03f96 CH |
1279 | static inline unsigned short blk_rq_nr_phys_segments(struct request *rq) |
1280 | { | |
1281 | if (rq->rq_flags & RQF_SPECIAL_PAYLOAD) | |
1282 | return 1; | |
1283 | return rq->nr_phys_segments; | |
1284 | } | |
1285 | ||
1e739730 CH |
1286 | /* |
1287 | * Number of discard segments (or ranges) the driver needs to fill in. | |
1288 | * Each discard bio merged into a request is counted as one segment. | |
1289 | */ | |
1290 | static inline unsigned short blk_rq_nr_discard_segments(struct request *rq) | |
1291 | { | |
1292 | return max_t(unsigned short, rq->nr_phys_segments, 1); | |
1293 | } | |
1294 | ||
165125e1 | 1295 | extern int blk_rq_map_sg(struct request_queue *, struct request *, struct scatterlist *); |
1da177e4 | 1296 | extern void blk_dump_rq_flags(struct request *, char *); |
1da177e4 | 1297 | extern long nr_blockdev_pages(void); |
1da177e4 | 1298 | |
09ac46c4 | 1299 | bool __must_check blk_get_queue(struct request_queue *); |
165125e1 JA |
1300 | struct request_queue *blk_alloc_queue(gfp_t); |
1301 | struct request_queue *blk_alloc_queue_node(gfp_t, int); | |
1302 | extern void blk_put_queue(struct request_queue *); | |
3f21c265 | 1303 | extern void blk_set_queue_dying(struct request_queue *); |
1da177e4 | 1304 | |
6c954667 LM |
1305 | /* |
1306 | * block layer runtime pm functions | |
1307 | */ | |
47fafbc7 | 1308 | #ifdef CONFIG_PM |
6c954667 LM |
1309 | extern void blk_pm_runtime_init(struct request_queue *q, struct device *dev); |
1310 | extern int blk_pre_runtime_suspend(struct request_queue *q); | |
1311 | extern void blk_post_runtime_suspend(struct request_queue *q, int err); | |
1312 | extern void blk_pre_runtime_resume(struct request_queue *q); | |
1313 | extern void blk_post_runtime_resume(struct request_queue *q, int err); | |
d07ab6d1 | 1314 | extern void blk_set_runtime_active(struct request_queue *q); |
6c954667 LM |
1315 | #else |
1316 | static inline void blk_pm_runtime_init(struct request_queue *q, | |
1317 | struct device *dev) {} | |
1318 | static inline int blk_pre_runtime_suspend(struct request_queue *q) | |
1319 | { | |
1320 | return -ENOSYS; | |
1321 | } | |
1322 | static inline void blk_post_runtime_suspend(struct request_queue *q, int err) {} | |
1323 | static inline void blk_pre_runtime_resume(struct request_queue *q) {} | |
1324 | static inline void blk_post_runtime_resume(struct request_queue *q, int err) {} | |
9a05e754 | 1325 | static inline void blk_set_runtime_active(struct request_queue *q) {} |
6c954667 LM |
1326 | #endif |
1327 | ||
316cc67d | 1328 | /* |
75df7136 SJ |
1329 | * blk_plug permits building a queue of related requests by holding the I/O |
1330 | * fragments for a short period. This allows merging of sequential requests | |
1331 | * into single larger request. As the requests are moved from a per-task list to | |
1332 | * the device's request_queue in a batch, this results in improved scalability | |
1333 | * as the lock contention for request_queue lock is reduced. | |
1334 | * | |
1335 | * It is ok not to disable preemption when adding the request to the plug list | |
1336 | * or when attempting a merge, because blk_schedule_flush_list() will only flush | |
1337 | * the plug list when the task sleeps by itself. For details, please see | |
1338 | * schedule() where blk_schedule_flush_plug() is called. | |
316cc67d | 1339 | */ |
73c10101 | 1340 | struct blk_plug { |
75df7136 | 1341 | struct list_head list; /* requests */ |
320ae51f | 1342 | struct list_head mq_list; /* blk-mq requests */ |
75df7136 | 1343 | struct list_head cb_list; /* md requires an unplug callback */ |
73c10101 | 1344 | }; |
55c022bb | 1345 | #define BLK_MAX_REQUEST_COUNT 16 |
50d24c34 | 1346 | #define BLK_PLUG_FLUSH_SIZE (128 * 1024) |
55c022bb | 1347 | |
9cbb1750 | 1348 | struct blk_plug_cb; |
74018dc3 | 1349 | typedef void (*blk_plug_cb_fn)(struct blk_plug_cb *, bool); |
048c9374 N |
1350 | struct blk_plug_cb { |
1351 | struct list_head list; | |
9cbb1750 N |
1352 | blk_plug_cb_fn callback; |
1353 | void *data; | |
048c9374 | 1354 | }; |
9cbb1750 N |
1355 | extern struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug, |
1356 | void *data, int size); | |
73c10101 JA |
1357 | extern void blk_start_plug(struct blk_plug *); |
1358 | extern void blk_finish_plug(struct blk_plug *); | |
f6603783 | 1359 | extern void blk_flush_plug_list(struct blk_plug *, bool); |
73c10101 JA |
1360 | |
1361 | static inline void blk_flush_plug(struct task_struct *tsk) | |
1362 | { | |
1363 | struct blk_plug *plug = tsk->plug; | |
1364 | ||
a237c1c5 JA |
1365 | if (plug) |
1366 | blk_flush_plug_list(plug, false); | |
1367 | } | |
1368 | ||
1369 | static inline void blk_schedule_flush_plug(struct task_struct *tsk) | |
1370 | { | |
1371 | struct blk_plug *plug = tsk->plug; | |
1372 | ||
88b996cd | 1373 | if (plug) |
f6603783 | 1374 | blk_flush_plug_list(plug, true); |
73c10101 JA |
1375 | } |
1376 | ||
1377 | static inline bool blk_needs_flush_plug(struct task_struct *tsk) | |
1378 | { | |
1379 | struct blk_plug *plug = tsk->plug; | |
1380 | ||
320ae51f JA |
1381 | return plug && |
1382 | (!list_empty(&plug->list) || | |
1383 | !list_empty(&plug->mq_list) || | |
1384 | !list_empty(&plug->cb_list)); | |
73c10101 JA |
1385 | } |
1386 | ||
1da177e4 LT |
1387 | /* |
1388 | * tag stuff | |
1389 | */ | |
165125e1 JA |
1390 | extern int blk_queue_start_tag(struct request_queue *, struct request *); |
1391 | extern struct request *blk_queue_find_tag(struct request_queue *, int); | |
1392 | extern void blk_queue_end_tag(struct request_queue *, struct request *); | |
ee1b6f7a | 1393 | extern int blk_queue_init_tags(struct request_queue *, int, struct blk_queue_tag *, int); |
165125e1 JA |
1394 | extern void blk_queue_free_tags(struct request_queue *); |
1395 | extern int blk_queue_resize_tags(struct request_queue *, int); | |
1396 | extern void blk_queue_invalidate_tags(struct request_queue *); | |
ee1b6f7a | 1397 | extern struct blk_queue_tag *blk_init_tags(int, int); |
492dfb48 | 1398 | extern void blk_free_tags(struct blk_queue_tag *); |
1da177e4 | 1399 | |
f583f492 DS |
1400 | static inline struct request *blk_map_queue_find_tag(struct blk_queue_tag *bqt, |
1401 | int tag) | |
1402 | { | |
1403 | if (unlikely(bqt == NULL || tag >= bqt->real_max_depth)) | |
1404 | return NULL; | |
1405 | return bqt->tag_index[tag]; | |
1406 | } | |
dd3932ed | 1407 | |
ee472d83 CH |
1408 | extern int blkdev_issue_flush(struct block_device *, gfp_t, sector_t *); |
1409 | extern int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, | |
1410 | sector_t nr_sects, gfp_t gfp_mask, struct page *page); | |
e950fdf7 CH |
1411 | |
1412 | #define BLKDEV_DISCARD_SECURE (1 << 0) /* issue a secure erase */ | |
dd3932ed | 1413 | |
fbd9b09a DM |
1414 | extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector, |
1415 | sector_t nr_sects, gfp_t gfp_mask, unsigned long flags); | |
38f25255 | 1416 | extern int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, |
288dab8a | 1417 | sector_t nr_sects, gfp_t gfp_mask, int flags, |
469e3216 | 1418 | struct bio **biop); |
ee472d83 CH |
1419 | |
1420 | #define BLKDEV_ZERO_NOUNMAP (1 << 0) /* do not free blocks */ | |
cb365b96 | 1421 | #define BLKDEV_ZERO_NOFALLBACK (1 << 1) /* don't write explicit zeroes */ |
ee472d83 | 1422 | |
e73c23ff CK |
1423 | extern int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, |
1424 | sector_t nr_sects, gfp_t gfp_mask, struct bio **biop, | |
ee472d83 | 1425 | unsigned flags); |
3f14d792 | 1426 | extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, |
ee472d83 CH |
1427 | sector_t nr_sects, gfp_t gfp_mask, unsigned flags); |
1428 | ||
2cf6d26a CH |
1429 | static inline int sb_issue_discard(struct super_block *sb, sector_t block, |
1430 | sector_t nr_blocks, gfp_t gfp_mask, unsigned long flags) | |
fb2dce86 | 1431 | { |
2cf6d26a CH |
1432 | return blkdev_issue_discard(sb->s_bdev, block << (sb->s_blocksize_bits - 9), |
1433 | nr_blocks << (sb->s_blocksize_bits - 9), | |
1434 | gfp_mask, flags); | |
fb2dce86 | 1435 | } |
e6fa0be6 | 1436 | static inline int sb_issue_zeroout(struct super_block *sb, sector_t block, |
a107e5a3 | 1437 | sector_t nr_blocks, gfp_t gfp_mask) |
e6fa0be6 LC |
1438 | { |
1439 | return blkdev_issue_zeroout(sb->s_bdev, | |
1440 | block << (sb->s_blocksize_bits - 9), | |
1441 | nr_blocks << (sb->s_blocksize_bits - 9), | |
ee472d83 | 1442 | gfp_mask, 0); |
e6fa0be6 | 1443 | } |
1da177e4 | 1444 | |
f00c4d80 | 1445 | extern int blk_verify_command(unsigned char *cmd, fmode_t mode); |
0b07de85 | 1446 | |
eb28d31b MP |
1447 | enum blk_default_limits { |
1448 | BLK_MAX_SEGMENTS = 128, | |
1449 | BLK_SAFE_MAX_SECTORS = 255, | |
d2be537c | 1450 | BLK_DEF_MAX_SECTORS = 2560, |
eb28d31b MP |
1451 | BLK_MAX_SEGMENT_SIZE = 65536, |
1452 | BLK_SEG_BOUNDARY_MASK = 0xFFFFFFFFUL, | |
1453 | }; | |
0e435ac2 | 1454 | |
1da177e4 LT |
1455 | #define blkdev_entry_to_request(entry) list_entry((entry), struct request, queuelist) |
1456 | ||
ae03bf63 MP |
1457 | static inline unsigned long queue_segment_boundary(struct request_queue *q) |
1458 | { | |
025146e1 | 1459 | return q->limits.seg_boundary_mask; |
ae03bf63 MP |
1460 | } |
1461 | ||
03100aad KB |
1462 | static inline unsigned long queue_virt_boundary(struct request_queue *q) |
1463 | { | |
1464 | return q->limits.virt_boundary_mask; | |
1465 | } | |
1466 | ||
ae03bf63 MP |
1467 | static inline unsigned int queue_max_sectors(struct request_queue *q) |
1468 | { | |
025146e1 | 1469 | return q->limits.max_sectors; |
ae03bf63 MP |
1470 | } |
1471 | ||
1472 | static inline unsigned int queue_max_hw_sectors(struct request_queue *q) | |
1473 | { | |
025146e1 | 1474 | return q->limits.max_hw_sectors; |
ae03bf63 MP |
1475 | } |
1476 | ||
8a78362c | 1477 | static inline unsigned short queue_max_segments(struct request_queue *q) |
ae03bf63 | 1478 | { |
8a78362c | 1479 | return q->limits.max_segments; |
ae03bf63 MP |
1480 | } |
1481 | ||
1e739730 CH |
1482 | static inline unsigned short queue_max_discard_segments(struct request_queue *q) |
1483 | { | |
1484 | return q->limits.max_discard_segments; | |
1485 | } | |
1486 | ||
ae03bf63 MP |
1487 | static inline unsigned int queue_max_segment_size(struct request_queue *q) |
1488 | { | |
025146e1 | 1489 | return q->limits.max_segment_size; |
ae03bf63 MP |
1490 | } |
1491 | ||
e1defc4f | 1492 | static inline unsigned short queue_logical_block_size(struct request_queue *q) |
1da177e4 LT |
1493 | { |
1494 | int retval = 512; | |
1495 | ||
025146e1 MP |
1496 | if (q && q->limits.logical_block_size) |
1497 | retval = q->limits.logical_block_size; | |
1da177e4 LT |
1498 | |
1499 | return retval; | |
1500 | } | |
1501 | ||
e1defc4f | 1502 | static inline unsigned short bdev_logical_block_size(struct block_device *bdev) |
1da177e4 | 1503 | { |
e1defc4f | 1504 | return queue_logical_block_size(bdev_get_queue(bdev)); |
1da177e4 LT |
1505 | } |
1506 | ||
c72758f3 MP |
1507 | static inline unsigned int queue_physical_block_size(struct request_queue *q) |
1508 | { | |
1509 | return q->limits.physical_block_size; | |
1510 | } | |
1511 | ||
892b6f90 | 1512 | static inline unsigned int bdev_physical_block_size(struct block_device *bdev) |
ac481c20 MP |
1513 | { |
1514 | return queue_physical_block_size(bdev_get_queue(bdev)); | |
1515 | } | |
1516 | ||
c72758f3 MP |
1517 | static inline unsigned int queue_io_min(struct request_queue *q) |
1518 | { | |
1519 | return q->limits.io_min; | |
1520 | } | |
1521 | ||
ac481c20 MP |
1522 | static inline int bdev_io_min(struct block_device *bdev) |
1523 | { | |
1524 | return queue_io_min(bdev_get_queue(bdev)); | |
1525 | } | |
1526 | ||
c72758f3 MP |
1527 | static inline unsigned int queue_io_opt(struct request_queue *q) |
1528 | { | |
1529 | return q->limits.io_opt; | |
1530 | } | |
1531 | ||
ac481c20 MP |
1532 | static inline int bdev_io_opt(struct block_device *bdev) |
1533 | { | |
1534 | return queue_io_opt(bdev_get_queue(bdev)); | |
1535 | } | |
1536 | ||
c72758f3 MP |
1537 | static inline int queue_alignment_offset(struct request_queue *q) |
1538 | { | |
ac481c20 | 1539 | if (q->limits.misaligned) |
c72758f3 MP |
1540 | return -1; |
1541 | ||
ac481c20 | 1542 | return q->limits.alignment_offset; |
c72758f3 MP |
1543 | } |
1544 | ||
e03a72e1 | 1545 | static inline int queue_limit_alignment_offset(struct queue_limits *lim, sector_t sector) |
81744ee4 MP |
1546 | { |
1547 | unsigned int granularity = max(lim->physical_block_size, lim->io_min); | |
b8839b8c | 1548 | unsigned int alignment = sector_div(sector, granularity >> 9) << 9; |
81744ee4 | 1549 | |
b8839b8c | 1550 | return (granularity + lim->alignment_offset - alignment) % granularity; |
c72758f3 MP |
1551 | } |
1552 | ||
ac481c20 MP |
1553 | static inline int bdev_alignment_offset(struct block_device *bdev) |
1554 | { | |
1555 | struct request_queue *q = bdev_get_queue(bdev); | |
1556 | ||
1557 | if (q->limits.misaligned) | |
1558 | return -1; | |
1559 | ||
1560 | if (bdev != bdev->bd_contains) | |
1561 | return bdev->bd_part->alignment_offset; | |
1562 | ||
1563 | return q->limits.alignment_offset; | |
1564 | } | |
1565 | ||
86b37281 MP |
1566 | static inline int queue_discard_alignment(struct request_queue *q) |
1567 | { | |
1568 | if (q->limits.discard_misaligned) | |
1569 | return -1; | |
1570 | ||
1571 | return q->limits.discard_alignment; | |
1572 | } | |
1573 | ||
e03a72e1 | 1574 | static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector_t sector) |
86b37281 | 1575 | { |
59771079 | 1576 | unsigned int alignment, granularity, offset; |
dd3d145d | 1577 | |
a934a00a MP |
1578 | if (!lim->max_discard_sectors) |
1579 | return 0; | |
1580 | ||
59771079 LT |
1581 | /* Why are these in bytes, not sectors? */ |
1582 | alignment = lim->discard_alignment >> 9; | |
1583 | granularity = lim->discard_granularity >> 9; | |
1584 | if (!granularity) | |
1585 | return 0; | |
1586 | ||
1587 | /* Offset of the partition start in 'granularity' sectors */ | |
1588 | offset = sector_div(sector, granularity); | |
1589 | ||
1590 | /* And why do we do this modulus *again* in blkdev_issue_discard()? */ | |
1591 | offset = (granularity + alignment - offset) % granularity; | |
1592 | ||
1593 | /* Turn it back into bytes, gaah */ | |
1594 | return offset << 9; | |
86b37281 MP |
1595 | } |
1596 | ||
c6e66634 PB |
1597 | static inline int bdev_discard_alignment(struct block_device *bdev) |
1598 | { | |
1599 | struct request_queue *q = bdev_get_queue(bdev); | |
1600 | ||
1601 | if (bdev != bdev->bd_contains) | |
1602 | return bdev->bd_part->discard_alignment; | |
1603 | ||
1604 | return q->limits.discard_alignment; | |
1605 | } | |
1606 | ||
4363ac7c MP |
1607 | static inline unsigned int bdev_write_same(struct block_device *bdev) |
1608 | { | |
1609 | struct request_queue *q = bdev_get_queue(bdev); | |
1610 | ||
1611 | if (q) | |
1612 | return q->limits.max_write_same_sectors; | |
1613 | ||
1614 | return 0; | |
1615 | } | |
1616 | ||
a6f0788e CK |
1617 | static inline unsigned int bdev_write_zeroes_sectors(struct block_device *bdev) |
1618 | { | |
1619 | struct request_queue *q = bdev_get_queue(bdev); | |
1620 | ||
1621 | if (q) | |
1622 | return q->limits.max_write_zeroes_sectors; | |
1623 | ||
1624 | return 0; | |
1625 | } | |
1626 | ||
797476b8 DLM |
1627 | static inline enum blk_zoned_model bdev_zoned_model(struct block_device *bdev) |
1628 | { | |
1629 | struct request_queue *q = bdev_get_queue(bdev); | |
1630 | ||
1631 | if (q) | |
1632 | return blk_queue_zoned_model(q); | |
1633 | ||
1634 | return BLK_ZONED_NONE; | |
1635 | } | |
1636 | ||
1637 | static inline bool bdev_is_zoned(struct block_device *bdev) | |
1638 | { | |
1639 | struct request_queue *q = bdev_get_queue(bdev); | |
1640 | ||
1641 | if (q) | |
1642 | return blk_queue_is_zoned(q); | |
1643 | ||
1644 | return false; | |
1645 | } | |
1646 | ||
f99e8648 | 1647 | static inline unsigned int bdev_zone_sectors(struct block_device *bdev) |
6a0cb1bc HR |
1648 | { |
1649 | struct request_queue *q = bdev_get_queue(bdev); | |
1650 | ||
1651 | if (q) | |
f99e8648 | 1652 | return blk_queue_zone_sectors(q); |
6cc77e9c CH |
1653 | return 0; |
1654 | } | |
6a0cb1bc | 1655 | |
6cc77e9c CH |
1656 | static inline unsigned int bdev_nr_zones(struct block_device *bdev) |
1657 | { | |
1658 | struct request_queue *q = bdev_get_queue(bdev); | |
1659 | ||
1660 | if (q) | |
1661 | return blk_queue_nr_zones(q); | |
6a0cb1bc HR |
1662 | return 0; |
1663 | } | |
1664 | ||
165125e1 | 1665 | static inline int queue_dma_alignment(struct request_queue *q) |
1da177e4 | 1666 | { |
482eb689 | 1667 | return q ? q->dma_alignment : 511; |
1da177e4 LT |
1668 | } |
1669 | ||
14417799 | 1670 | static inline int blk_rq_aligned(struct request_queue *q, unsigned long addr, |
87904074 FT |
1671 | unsigned int len) |
1672 | { | |
1673 | unsigned int alignment = queue_dma_alignment(q) | q->dma_pad_mask; | |
14417799 | 1674 | return !(addr & alignment) && !(len & alignment); |
87904074 FT |
1675 | } |
1676 | ||
1da177e4 LT |
1677 | /* assumes size > 256 */ |
1678 | static inline unsigned int blksize_bits(unsigned int size) | |
1679 | { | |
1680 | unsigned int bits = 8; | |
1681 | do { | |
1682 | bits++; | |
1683 | size >>= 1; | |
1684 | } while (size > 256); | |
1685 | return bits; | |
1686 | } | |
1687 | ||
2befb9e3 | 1688 | static inline unsigned int block_size(struct block_device *bdev) |
1da177e4 LT |
1689 | { |
1690 | return bdev->bd_block_size; | |
1691 | } | |
1692 | ||
f3876930 | 1693 | static inline bool queue_flush_queueable(struct request_queue *q) |
1694 | { | |
c888a8f9 | 1695 | return !test_bit(QUEUE_FLAG_FLUSH_NQ, &q->queue_flags); |
f3876930 | 1696 | } |
1697 | ||
1da177e4 LT |
1698 | typedef struct {struct page *v;} Sector; |
1699 | ||
1700 | unsigned char *read_dev_sector(struct block_device *, sector_t, Sector *); | |
1701 | ||
1702 | static inline void put_dev_sector(Sector p) | |
1703 | { | |
09cbfeaf | 1704 | put_page(p.v); |
1da177e4 LT |
1705 | } |
1706 | ||
e0af2917 ML |
1707 | static inline bool __bvec_gap_to_prev(struct request_queue *q, |
1708 | struct bio_vec *bprv, unsigned int offset) | |
1709 | { | |
1710 | return offset || | |
1711 | ((bprv->bv_offset + bprv->bv_len) & queue_virt_boundary(q)); | |
1712 | } | |
1713 | ||
03100aad KB |
1714 | /* |
1715 | * Check if adding a bio_vec after bprv with offset would create a gap in | |
1716 | * the SG list. Most drivers don't care about this, but some do. | |
1717 | */ | |
1718 | static inline bool bvec_gap_to_prev(struct request_queue *q, | |
1719 | struct bio_vec *bprv, unsigned int offset) | |
1720 | { | |
1721 | if (!queue_virt_boundary(q)) | |
1722 | return false; | |
e0af2917 | 1723 | return __bvec_gap_to_prev(q, bprv, offset); |
03100aad KB |
1724 | } |
1725 | ||
729204ef ML |
1726 | /* |
1727 | * Check if the two bvecs from two bios can be merged to one segment. | |
1728 | * If yes, no need to check gap between the two bios since the 1st bio | |
1729 | * and the 1st bvec in the 2nd bio can be handled in one segment. | |
1730 | */ | |
1731 | static inline bool bios_segs_mergeable(struct request_queue *q, | |
1732 | struct bio *prev, struct bio_vec *prev_last_bv, | |
1733 | struct bio_vec *next_first_bv) | |
1734 | { | |
1735 | if (!BIOVEC_PHYS_MERGEABLE(prev_last_bv, next_first_bv)) | |
1736 | return false; | |
1737 | if (!BIOVEC_SEG_BOUNDARY(q, prev_last_bv, next_first_bv)) | |
1738 | return false; | |
1739 | if (prev->bi_seg_back_size + next_first_bv->bv_len > | |
1740 | queue_max_segment_size(q)) | |
1741 | return false; | |
1742 | return true; | |
1743 | } | |
1744 | ||
5a8d75a1 ML |
1745 | static inline bool bio_will_gap(struct request_queue *q, |
1746 | struct request *prev_rq, | |
1747 | struct bio *prev, | |
1748 | struct bio *next) | |
5e7c4274 | 1749 | { |
25e71a99 ML |
1750 | if (bio_has_data(prev) && queue_virt_boundary(q)) { |
1751 | struct bio_vec pb, nb; | |
1752 | ||
5a8d75a1 ML |
1753 | /* |
1754 | * don't merge if the 1st bio starts with non-zero | |
1755 | * offset, otherwise it is quite difficult to respect | |
1756 | * sg gap limit. We work hard to merge a huge number of small | |
1757 | * single bios in case of mkfs. | |
1758 | */ | |
1759 | if (prev_rq) | |
1760 | bio_get_first_bvec(prev_rq->bio, &pb); | |
1761 | else | |
1762 | bio_get_first_bvec(prev, &pb); | |
1763 | if (pb.bv_offset) | |
1764 | return true; | |
1765 | ||
1766 | /* | |
1767 | * We don't need to worry about the situation that the | |
1768 | * merged segment ends in unaligned virt boundary: | |
1769 | * | |
1770 | * - if 'pb' ends aligned, the merged segment ends aligned | |
1771 | * - if 'pb' ends unaligned, the next bio must include | |
1772 | * one single bvec of 'nb', otherwise the 'nb' can't | |
1773 | * merge with 'pb' | |
1774 | */ | |
25e71a99 ML |
1775 | bio_get_last_bvec(prev, &pb); |
1776 | bio_get_first_bvec(next, &nb); | |
5e7c4274 | 1777 | |
729204ef ML |
1778 | if (!bios_segs_mergeable(q, prev, &pb, &nb)) |
1779 | return __bvec_gap_to_prev(q, &pb, nb.bv_offset); | |
25e71a99 ML |
1780 | } |
1781 | ||
1782 | return false; | |
5e7c4274 JA |
1783 | } |
1784 | ||
1785 | static inline bool req_gap_back_merge(struct request *req, struct bio *bio) | |
1786 | { | |
5a8d75a1 | 1787 | return bio_will_gap(req->q, req, req->biotail, bio); |
5e7c4274 JA |
1788 | } |
1789 | ||
1790 | static inline bool req_gap_front_merge(struct request *req, struct bio *bio) | |
1791 | { | |
5a8d75a1 | 1792 | return bio_will_gap(req->q, NULL, bio, req->bio); |
5e7c4274 JA |
1793 | } |
1794 | ||
59c3d45e | 1795 | int kblockd_schedule_work(struct work_struct *work); |
ee63cfa7 | 1796 | int kblockd_schedule_work_on(int cpu, struct work_struct *work); |
59c3d45e | 1797 | int kblockd_schedule_delayed_work(struct delayed_work *dwork, unsigned long delay); |
8ab14595 | 1798 | int kblockd_schedule_delayed_work_on(int cpu, struct delayed_work *dwork, unsigned long delay); |
818cd1cb | 1799 | int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork, unsigned long delay); |
1da177e4 | 1800 | |
9195291e | 1801 | #ifdef CONFIG_BLK_CGROUP |
28f4197e JA |
1802 | /* |
1803 | * This should not be using sched_clock(). A real patch is in progress | |
1804 | * to fix this up, until that is in place we need to disable preemption | |
1805 | * around sched_clock() in this function and set_io_start_time_ns(). | |
1806 | */ | |
9195291e DS |
1807 | static inline void set_start_time_ns(struct request *req) |
1808 | { | |
28f4197e | 1809 | preempt_disable(); |
9195291e | 1810 | req->start_time_ns = sched_clock(); |
28f4197e | 1811 | preempt_enable(); |
9195291e DS |
1812 | } |
1813 | ||
1814 | static inline void set_io_start_time_ns(struct request *req) | |
1815 | { | |
28f4197e | 1816 | preempt_disable(); |
9195291e | 1817 | req->io_start_time_ns = sched_clock(); |
28f4197e | 1818 | preempt_enable(); |
9195291e | 1819 | } |
84c124da DS |
1820 | |
1821 | static inline uint64_t rq_start_time_ns(struct request *req) | |
1822 | { | |
1823 | return req->start_time_ns; | |
1824 | } | |
1825 | ||
1826 | static inline uint64_t rq_io_start_time_ns(struct request *req) | |
1827 | { | |
1828 | return req->io_start_time_ns; | |
1829 | } | |
9195291e DS |
1830 | #else |
1831 | static inline void set_start_time_ns(struct request *req) {} | |
1832 | static inline void set_io_start_time_ns(struct request *req) {} | |
84c124da DS |
1833 | static inline uint64_t rq_start_time_ns(struct request *req) |
1834 | { | |
1835 | return 0; | |
1836 | } | |
1837 | static inline uint64_t rq_io_start_time_ns(struct request *req) | |
1838 | { | |
1839 | return 0; | |
1840 | } | |
9195291e DS |
1841 | #endif |
1842 | ||
1da177e4 LT |
1843 | #define MODULE_ALIAS_BLOCKDEV(major,minor) \ |
1844 | MODULE_ALIAS("block-major-" __stringify(major) "-" __stringify(minor)) | |
1845 | #define MODULE_ALIAS_BLOCKDEV_MAJOR(major) \ | |
1846 | MODULE_ALIAS("block-major-" __stringify(major) "-*") | |
1847 | ||
7ba1ba12 MP |
1848 | #if defined(CONFIG_BLK_DEV_INTEGRITY) |
1849 | ||
8288f496 MP |
1850 | enum blk_integrity_flags { |
1851 | BLK_INTEGRITY_VERIFY = 1 << 0, | |
1852 | BLK_INTEGRITY_GENERATE = 1 << 1, | |
3aec2f41 | 1853 | BLK_INTEGRITY_DEVICE_CAPABLE = 1 << 2, |
aae7df50 | 1854 | BLK_INTEGRITY_IP_CHECKSUM = 1 << 3, |
8288f496 | 1855 | }; |
7ba1ba12 | 1856 | |
18593088 | 1857 | struct blk_integrity_iter { |
7ba1ba12 MP |
1858 | void *prot_buf; |
1859 | void *data_buf; | |
3be91c4a | 1860 | sector_t seed; |
7ba1ba12 | 1861 | unsigned int data_size; |
3be91c4a | 1862 | unsigned short interval; |
7ba1ba12 MP |
1863 | const char *disk_name; |
1864 | }; | |
1865 | ||
4e4cbee9 | 1866 | typedef blk_status_t (integrity_processing_fn) (struct blk_integrity_iter *); |
7ba1ba12 | 1867 | |
0f8087ec MP |
1868 | struct blk_integrity_profile { |
1869 | integrity_processing_fn *generate_fn; | |
1870 | integrity_processing_fn *verify_fn; | |
1871 | const char *name; | |
1872 | }; | |
7ba1ba12 | 1873 | |
25520d55 | 1874 | extern void blk_integrity_register(struct gendisk *, struct blk_integrity *); |
7ba1ba12 | 1875 | extern void blk_integrity_unregister(struct gendisk *); |
ad7fce93 | 1876 | extern int blk_integrity_compare(struct gendisk *, struct gendisk *); |
13f05c8d MP |
1877 | extern int blk_rq_map_integrity_sg(struct request_queue *, struct bio *, |
1878 | struct scatterlist *); | |
1879 | extern int blk_rq_count_integrity_sg(struct request_queue *, struct bio *); | |
4eaf99be MP |
1880 | extern bool blk_integrity_merge_rq(struct request_queue *, struct request *, |
1881 | struct request *); | |
1882 | extern bool blk_integrity_merge_bio(struct request_queue *, struct request *, | |
1883 | struct bio *); | |
7ba1ba12 | 1884 | |
25520d55 | 1885 | static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk) |
b04accc4 | 1886 | { |
ac6fc48c | 1887 | struct blk_integrity *bi = &disk->queue->integrity; |
25520d55 MP |
1888 | |
1889 | if (!bi->profile) | |
1890 | return NULL; | |
1891 | ||
1892 | return bi; | |
b04accc4 JA |
1893 | } |
1894 | ||
25520d55 MP |
1895 | static inline |
1896 | struct blk_integrity *bdev_get_integrity(struct block_device *bdev) | |
b02739b0 | 1897 | { |
25520d55 | 1898 | return blk_get_integrity(bdev->bd_disk); |
b02739b0 MP |
1899 | } |
1900 | ||
180b2f95 | 1901 | static inline bool blk_integrity_rq(struct request *rq) |
7ba1ba12 | 1902 | { |
180b2f95 | 1903 | return rq->cmd_flags & REQ_INTEGRITY; |
7ba1ba12 MP |
1904 | } |
1905 | ||
13f05c8d MP |
1906 | static inline void blk_queue_max_integrity_segments(struct request_queue *q, |
1907 | unsigned int segs) | |
1908 | { | |
1909 | q->limits.max_integrity_segments = segs; | |
1910 | } | |
1911 | ||
1912 | static inline unsigned short | |
1913 | queue_max_integrity_segments(struct request_queue *q) | |
1914 | { | |
1915 | return q->limits.max_integrity_segments; | |
1916 | } | |
1917 | ||
7f39add3 SG |
1918 | static inline bool integrity_req_gap_back_merge(struct request *req, |
1919 | struct bio *next) | |
1920 | { | |
1921 | struct bio_integrity_payload *bip = bio_integrity(req->bio); | |
1922 | struct bio_integrity_payload *bip_next = bio_integrity(next); | |
1923 | ||
1924 | return bvec_gap_to_prev(req->q, &bip->bip_vec[bip->bip_vcnt - 1], | |
1925 | bip_next->bip_vec[0].bv_offset); | |
1926 | } | |
1927 | ||
1928 | static inline bool integrity_req_gap_front_merge(struct request *req, | |
1929 | struct bio *bio) | |
1930 | { | |
1931 | struct bio_integrity_payload *bip = bio_integrity(bio); | |
1932 | struct bio_integrity_payload *bip_next = bio_integrity(req->bio); | |
1933 | ||
1934 | return bvec_gap_to_prev(req->q, &bip->bip_vec[bip->bip_vcnt - 1], | |
1935 | bip_next->bip_vec[0].bv_offset); | |
1936 | } | |
1937 | ||
7ba1ba12 MP |
1938 | #else /* CONFIG_BLK_DEV_INTEGRITY */ |
1939 | ||
fd83240a SR |
1940 | struct bio; |
1941 | struct block_device; | |
1942 | struct gendisk; | |
1943 | struct blk_integrity; | |
1944 | ||
1945 | static inline int blk_integrity_rq(struct request *rq) | |
1946 | { | |
1947 | return 0; | |
1948 | } | |
1949 | static inline int blk_rq_count_integrity_sg(struct request_queue *q, | |
1950 | struct bio *b) | |
1951 | { | |
1952 | return 0; | |
1953 | } | |
1954 | static inline int blk_rq_map_integrity_sg(struct request_queue *q, | |
1955 | struct bio *b, | |
1956 | struct scatterlist *s) | |
1957 | { | |
1958 | return 0; | |
1959 | } | |
1960 | static inline struct blk_integrity *bdev_get_integrity(struct block_device *b) | |
1961 | { | |
61a04e5b | 1962 | return NULL; |
fd83240a SR |
1963 | } |
1964 | static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk) | |
1965 | { | |
1966 | return NULL; | |
1967 | } | |
1968 | static inline int blk_integrity_compare(struct gendisk *a, struct gendisk *b) | |
1969 | { | |
1970 | return 0; | |
1971 | } | |
25520d55 | 1972 | static inline void blk_integrity_register(struct gendisk *d, |
fd83240a SR |
1973 | struct blk_integrity *b) |
1974 | { | |
fd83240a SR |
1975 | } |
1976 | static inline void blk_integrity_unregister(struct gendisk *d) | |
1977 | { | |
1978 | } | |
1979 | static inline void blk_queue_max_integrity_segments(struct request_queue *q, | |
1980 | unsigned int segs) | |
1981 | { | |
1982 | } | |
1983 | static inline unsigned short queue_max_integrity_segments(struct request_queue *q) | |
1984 | { | |
1985 | return 0; | |
1986 | } | |
4eaf99be MP |
1987 | static inline bool blk_integrity_merge_rq(struct request_queue *rq, |
1988 | struct request *r1, | |
1989 | struct request *r2) | |
fd83240a | 1990 | { |
cb1a5ab6 | 1991 | return true; |
fd83240a | 1992 | } |
4eaf99be MP |
1993 | static inline bool blk_integrity_merge_bio(struct request_queue *rq, |
1994 | struct request *r, | |
1995 | struct bio *b) | |
fd83240a | 1996 | { |
cb1a5ab6 | 1997 | return true; |
fd83240a | 1998 | } |
25520d55 | 1999 | |
7f39add3 SG |
2000 | static inline bool integrity_req_gap_back_merge(struct request *req, |
2001 | struct bio *next) | |
2002 | { | |
2003 | return false; | |
2004 | } | |
2005 | static inline bool integrity_req_gap_front_merge(struct request *req, | |
2006 | struct bio *bio) | |
2007 | { | |
2008 | return false; | |
2009 | } | |
7ba1ba12 MP |
2010 | |
2011 | #endif /* CONFIG_BLK_DEV_INTEGRITY */ | |
2012 | ||
08f85851 | 2013 | struct block_device_operations { |
d4430d62 | 2014 | int (*open) (struct block_device *, fmode_t); |
db2a144b | 2015 | void (*release) (struct gendisk *, fmode_t); |
c11f0c0b | 2016 | int (*rw_page)(struct block_device *, sector_t, struct page *, bool); |
d4430d62 AV |
2017 | int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long); |
2018 | int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long); | |
77ea887e TH |
2019 | unsigned int (*check_events) (struct gendisk *disk, |
2020 | unsigned int clearing); | |
2021 | /* ->media_changed() is DEPRECATED, use ->check_events() instead */ | |
08f85851 | 2022 | int (*media_changed) (struct gendisk *); |
c3e33e04 | 2023 | void (*unlock_native_capacity) (struct gendisk *); |
08f85851 AV |
2024 | int (*revalidate_disk) (struct gendisk *); |
2025 | int (*getgeo)(struct block_device *, struct hd_geometry *); | |
b3a27d05 NG |
2026 | /* this callback is with swap_lock and sometimes page table lock held */ |
2027 | void (*swap_slot_free_notify) (struct block_device *, unsigned long); | |
08f85851 | 2028 | struct module *owner; |
bbd3e064 | 2029 | const struct pr_ops *pr_ops; |
08f85851 AV |
2030 | }; |
2031 | ||
633a08b8 AV |
2032 | extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int, |
2033 | unsigned long); | |
47a191fd MW |
2034 | extern int bdev_read_page(struct block_device *, sector_t, struct page *); |
2035 | extern int bdev_write_page(struct block_device *, sector_t, struct page *, | |
2036 | struct writeback_control *); | |
6cc77e9c CH |
2037 | |
2038 | #ifdef CONFIG_BLK_DEV_ZONED | |
2039 | bool blk_req_needs_zone_write_lock(struct request *rq); | |
2040 | void __blk_req_zone_write_lock(struct request *rq); | |
2041 | void __blk_req_zone_write_unlock(struct request *rq); | |
2042 | ||
2043 | static inline void blk_req_zone_write_lock(struct request *rq) | |
2044 | { | |
2045 | if (blk_req_needs_zone_write_lock(rq)) | |
2046 | __blk_req_zone_write_lock(rq); | |
2047 | } | |
2048 | ||
2049 | static inline void blk_req_zone_write_unlock(struct request *rq) | |
2050 | { | |
2051 | if (rq->rq_flags & RQF_ZONE_WRITE_LOCKED) | |
2052 | __blk_req_zone_write_unlock(rq); | |
2053 | } | |
2054 | ||
2055 | static inline bool blk_req_zone_is_write_locked(struct request *rq) | |
2056 | { | |
2057 | return rq->q->seq_zones_wlock && | |
2058 | test_bit(blk_rq_zone_no(rq), rq->q->seq_zones_wlock); | |
2059 | } | |
2060 | ||
2061 | static inline bool blk_req_can_dispatch_to_zone(struct request *rq) | |
2062 | { | |
2063 | if (!blk_req_needs_zone_write_lock(rq)) | |
2064 | return true; | |
2065 | return !blk_req_zone_is_write_locked(rq); | |
2066 | } | |
2067 | #else | |
2068 | static inline bool blk_req_needs_zone_write_lock(struct request *rq) | |
2069 | { | |
2070 | return false; | |
2071 | } | |
2072 | ||
2073 | static inline void blk_req_zone_write_lock(struct request *rq) | |
2074 | { | |
2075 | } | |
2076 | ||
2077 | static inline void blk_req_zone_write_unlock(struct request *rq) | |
2078 | { | |
2079 | } | |
2080 | static inline bool blk_req_zone_is_write_locked(struct request *rq) | |
2081 | { | |
2082 | return false; | |
2083 | } | |
2084 | ||
2085 | static inline bool blk_req_can_dispatch_to_zone(struct request *rq) | |
2086 | { | |
2087 | return true; | |
2088 | } | |
2089 | #endif /* CONFIG_BLK_DEV_ZONED */ | |
2090 | ||
9361401e | 2091 | #else /* CONFIG_BLOCK */ |
ac13a829 FF |
2092 | |
2093 | struct block_device; | |
2094 | ||
9361401e DH |
2095 | /* |
2096 | * stubs for when the block layer is configured out | |
2097 | */ | |
2098 | #define buffer_heads_over_limit 0 | |
2099 | ||
9361401e DH |
2100 | static inline long nr_blockdev_pages(void) |
2101 | { | |
2102 | return 0; | |
2103 | } | |
2104 | ||
1f940bdf JA |
2105 | struct blk_plug { |
2106 | }; | |
2107 | ||
2108 | static inline void blk_start_plug(struct blk_plug *plug) | |
73c10101 JA |
2109 | { |
2110 | } | |
2111 | ||
1f940bdf | 2112 | static inline void blk_finish_plug(struct blk_plug *plug) |
73c10101 JA |
2113 | { |
2114 | } | |
2115 | ||
1f940bdf | 2116 | static inline void blk_flush_plug(struct task_struct *task) |
73c10101 JA |
2117 | { |
2118 | } | |
2119 | ||
a237c1c5 JA |
2120 | static inline void blk_schedule_flush_plug(struct task_struct *task) |
2121 | { | |
2122 | } | |
2123 | ||
2124 | ||
73c10101 JA |
2125 | static inline bool blk_needs_flush_plug(struct task_struct *tsk) |
2126 | { | |
2127 | return false; | |
2128 | } | |
2129 | ||
ac13a829 FF |
2130 | static inline int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask, |
2131 | sector_t *error_sector) | |
2132 | { | |
2133 | return 0; | |
2134 | } | |
2135 | ||
9361401e DH |
2136 | #endif /* CONFIG_BLOCK */ |
2137 | ||
1da177e4 | 2138 | #endif |