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