1 /* SPDX-License-Identifier: GPL-2.0 */
7 #include "blk-mq-tag.h"
9 #define MAX_SCHED_RQ (16 * BLKDEV_DEFAULT_RQ)
11 struct io_cq *blk_mq_sched_get_icq(struct request_queue *q);
12 void blk_mq_sched_assign_ioc(struct request *rq);
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);
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);
29 void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx);
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);
35 static inline void blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx)
37 if (test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
38 __blk_mq_sched_restart(hctx);
41 static inline bool bio_mergeable(struct bio *bio)
43 return !(bio->bi_opf & REQ_NOMERGE_FLAGS);
47 blk_mq_sched_allow_merge(struct request_queue *q, struct request *rq,
50 if (rq->rq_flags & RQF_ELV) {
51 struct elevator_queue *e = q->elevator;
53 if (e->type->ops.allow_merge)
54 return e->type->ops.allow_merge(q, rq, bio);
59 static inline void blk_mq_sched_completed_request(struct request *rq, u64 now)
61 if (rq->rq_flags & RQF_ELV) {
62 struct elevator_queue *e = rq->q->elevator;
64 if (e->type->ops.completed_request)
65 e->type->ops.completed_request(rq, now);
69 static inline void blk_mq_sched_requeue_request(struct request *rq)
71 if (rq->rq_flags & RQF_ELV) {
72 struct request_queue *q = rq->q;
73 struct elevator_queue *e = q->elevator;
75 if ((rq->rq_flags & RQF_ELVPRIV) && e->type->ops.requeue_request)
76 e->type->ops.requeue_request(rq);
80 static inline bool blk_mq_sched_has_work(struct blk_mq_hw_ctx *hctx)
82 struct elevator_queue *e = hctx->queue->elevator;
84 if (e && e->type->ops.has_work)
85 return e->type->ops.has_work(hctx);
90 static inline bool blk_mq_sched_needs_restart(struct blk_mq_hw_ctx *hctx)
92 return test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);