block: Provide blk_mq_sched_get_icq()
[linux-2.6-microblaze.git] / block / blk-mq-sched.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef BLK_MQ_SCHED_H
3 #define BLK_MQ_SCHED_H
4
5 #include "elevator.h"
6 #include "blk-mq.h"
7 #include "blk-mq-tag.h"
8
9 #define MAX_SCHED_RQ (16 * BLKDEV_DEFAULT_RQ)
10
11 struct io_cq *blk_mq_sched_get_icq(struct request_queue *q);
12 void blk_mq_sched_assign_ioc(struct request *rq);
13
14 bool blk_mq_sched_try_merge(struct request_queue *q, struct bio *bio,
15                 unsigned int nr_segs, struct request **merged_request);
16 bool blk_mq_sched_bio_merge(struct request_queue *q, struct bio *bio,
17                 unsigned int nr_segs);
18 bool blk_mq_sched_try_insert_merge(struct request_queue *q, struct request *rq,
19                                    struct list_head *free);
20 void blk_mq_sched_mark_restart_hctx(struct blk_mq_hw_ctx *hctx);
21 void __blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx);
22
23 void blk_mq_sched_insert_request(struct request *rq, bool at_head,
24                                  bool run_queue, bool async);
25 void blk_mq_sched_insert_requests(struct blk_mq_hw_ctx *hctx,
26                                   struct blk_mq_ctx *ctx,
27                                   struct list_head *list, bool run_queue_async);
28
29 void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx);
30
31 int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e);
32 void blk_mq_exit_sched(struct request_queue *q, struct elevator_queue *e);
33 void blk_mq_sched_free_rqs(struct request_queue *q);
34
35 static inline void blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx)
36 {
37         if (test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
38                 __blk_mq_sched_restart(hctx);
39 }
40
41 static inline bool bio_mergeable(struct bio *bio)
42 {
43         return !(bio->bi_opf & REQ_NOMERGE_FLAGS);
44 }
45
46 static inline bool
47 blk_mq_sched_allow_merge(struct request_queue *q, struct request *rq,
48                          struct bio *bio)
49 {
50         if (rq->rq_flags & RQF_ELV) {
51                 struct elevator_queue *e = q->elevator;
52
53                 if (e->type->ops.allow_merge)
54                         return e->type->ops.allow_merge(q, rq, bio);
55         }
56         return true;
57 }
58
59 static inline void blk_mq_sched_completed_request(struct request *rq, u64 now)
60 {
61         if (rq->rq_flags & RQF_ELV) {
62                 struct elevator_queue *e = rq->q->elevator;
63
64                 if (e->type->ops.completed_request)
65                         e->type->ops.completed_request(rq, now);
66         }
67 }
68
69 static inline void blk_mq_sched_requeue_request(struct request *rq)
70 {
71         if (rq->rq_flags & RQF_ELV) {
72                 struct request_queue *q = rq->q;
73                 struct elevator_queue *e = q->elevator;
74
75                 if ((rq->rq_flags & RQF_ELVPRIV) && e->type->ops.requeue_request)
76                         e->type->ops.requeue_request(rq);
77         }
78 }
79
80 static inline bool blk_mq_sched_has_work(struct blk_mq_hw_ctx *hctx)
81 {
82         struct elevator_queue *e = hctx->queue->elevator;
83
84         if (e && e->type->ops.has_work)
85                 return e->type->ops.has_work(hctx);
86
87         return false;
88 }
89
90 static inline bool blk_mq_sched_needs_restart(struct blk_mq_hw_ctx *hctx)
91 {
92         return test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);
93 }
94
95 #endif