1 /* SPDX-License-Identifier: GPL-2.0 */
8 #define MAX_SCHED_RQ (16 * BLKDEV_DEFAULT_RQ)
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);
19 void blk_mq_sched_dispatch_requests(struct blk_mq_hw_ctx *hctx);
21 int blk_mq_init_sched(struct request_queue *q, struct elevator_type *e);
22 void blk_mq_exit_sched(struct request_queue *q, struct elevator_queue *e);
23 void blk_mq_sched_free_rqs(struct request_queue *q);
25 static inline void blk_mq_sched_restart(struct blk_mq_hw_ctx *hctx)
27 if (test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state))
28 __blk_mq_sched_restart(hctx);
31 static inline bool bio_mergeable(struct bio *bio)
33 return !(bio->bi_opf & REQ_NOMERGE_FLAGS);
37 blk_mq_sched_allow_merge(struct request_queue *q, struct request *rq,
40 if (rq->rq_flags & RQF_USE_SCHED) {
41 struct elevator_queue *e = q->elevator;
43 if (e->type->ops.allow_merge)
44 return e->type->ops.allow_merge(q, rq, bio);
49 static inline void blk_mq_sched_completed_request(struct request *rq, u64 now)
51 if (rq->rq_flags & RQF_USE_SCHED) {
52 struct elevator_queue *e = rq->q->elevator;
54 if (e->type->ops.completed_request)
55 e->type->ops.completed_request(rq, now);
59 static inline void blk_mq_sched_requeue_request(struct request *rq)
61 if (rq->rq_flags & RQF_USE_SCHED) {
62 struct request_queue *q = rq->q;
63 struct elevator_queue *e = q->elevator;
65 if (e->type->ops.requeue_request)
66 e->type->ops.requeue_request(rq);
70 static inline bool blk_mq_sched_has_work(struct blk_mq_hw_ctx *hctx)
72 struct elevator_queue *e = hctx->queue->elevator;
74 if (e && e->type->ops.has_work)
75 return e->type->ops.has_work(hctx);
80 static inline bool blk_mq_sched_needs_restart(struct blk_mq_hw_ctx *hctx)
82 return test_bit(BLK_MQ_S_SCHED_RESTART, &hctx->state);