]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
320ae51f JA |
2 | #ifndef INT_BLK_MQ_H |
3 | #define INT_BLK_MQ_H | |
4 | ||
cf43e6be | 5 | #include "blk-stat.h" |
244c65a3 | 6 | #include "blk-mq-tag.h" |
cf43e6be | 7 | |
24d2f903 CH |
8 | struct blk_mq_tag_set; |
9 | ||
320ae51f JA |
10 | struct blk_mq_ctx { |
11 | struct { | |
12 | spinlock_t lock; | |
13 | struct list_head rq_list; | |
14 | } ____cacheline_aligned_in_smp; | |
15 | ||
16 | unsigned int cpu; | |
17 | unsigned int index_hw; | |
320ae51f JA |
18 | |
19 | /* incremented at dispatch time */ | |
20 | unsigned long rq_dispatched[2]; | |
21 | unsigned long rq_merged; | |
22 | ||
23 | /* incremented at completion time */ | |
24 | unsigned long ____cacheline_aligned_in_smp rq_completed[2]; | |
25 | ||
26 | struct request_queue *queue; | |
27 | struct kobject kobj; | |
4bb659b1 | 28 | } ____cacheline_aligned_in_smp; |
320ae51f | 29 | |
780db207 | 30 | void blk_mq_freeze_queue(struct request_queue *q); |
84c8ff7f | 31 | void blk_mq_exit_queue(struct request_queue *q); |
e3a2b3f9 | 32 | int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr); |
aed3ea94 | 33 | void blk_mq_wake_waiters(struct request_queue *q); |
de148297 | 34 | bool blk_mq_dispatch_rq_list(struct request_queue *, struct list_head *, bool); |
2c3ad667 | 35 | void blk_mq_flush_busy_ctxs(struct blk_mq_hw_ctx *hctx, struct list_head *list); |
bd6737f1 JA |
36 | bool blk_mq_get_driver_tag(struct request *rq, struct blk_mq_hw_ctx **hctx, |
37 | bool wait); | |
b347689f ML |
38 | struct request *blk_mq_dequeue_from_ctx(struct blk_mq_hw_ctx *hctx, |
39 | struct blk_mq_ctx *start); | |
2c3ad667 JA |
40 | |
41 | /* | |
42 | * Internal helpers for allocating/freeing the request map | |
43 | */ | |
cc71a6f4 JA |
44 | void blk_mq_free_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags, |
45 | unsigned int hctx_idx); | |
46 | void blk_mq_free_rq_map(struct blk_mq_tags *tags); | |
47 | struct blk_mq_tags *blk_mq_alloc_rq_map(struct blk_mq_tag_set *set, | |
48 | unsigned int hctx_idx, | |
49 | unsigned int nr_tags, | |
50 | unsigned int reserved_tags); | |
51 | int blk_mq_alloc_rqs(struct blk_mq_tag_set *set, struct blk_mq_tags *tags, | |
52 | unsigned int hctx_idx, unsigned int depth); | |
2c3ad667 JA |
53 | |
54 | /* | |
55 | * Internal helpers for request insertion into sw queues | |
56 | */ | |
57 | void __blk_mq_insert_request(struct blk_mq_hw_ctx *hctx, struct request *rq, | |
58 | bool at_head); | |
b0850297 | 59 | void blk_mq_request_bypass_insert(struct request *rq, bool run_queue); |
bd166ef1 JA |
60 | void blk_mq_insert_requests(struct blk_mq_hw_ctx *hctx, struct blk_mq_ctx *ctx, |
61 | struct list_head *list); | |
320ae51f | 62 | |
5e22a908 | 63 | /* Used by blk_insert_cloned_request() to issue request directly */ |
ffef502f | 64 | blk_status_t blk_mq_request_issue_directly(struct request *rq); |
5e22a908 | 65 | |
320ae51f JA |
66 | /* |
67 | * CPU -> queue mappings | |
68 | */ | |
f14bbe77 | 69 | extern int blk_mq_hw_queue_to_node(unsigned int *map, unsigned int); |
320ae51f | 70 | |
7d7e0f90 CH |
71 | static inline struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *q, |
72 | int cpu) | |
73 | { | |
74 | return q->queue_hw_ctx[q->mq_map[cpu]]; | |
75 | } | |
76 | ||
67aec14c JA |
77 | /* |
78 | * sysfs helpers | |
79 | */ | |
737f98cf | 80 | extern void blk_mq_sysfs_init(struct request_queue *q); |
7ea5fe31 | 81 | extern void blk_mq_sysfs_deinit(struct request_queue *q); |
2d0364c8 | 82 | extern int __blk_mq_register_dev(struct device *dev, struct request_queue *q); |
67aec14c JA |
83 | extern int blk_mq_sysfs_register(struct request_queue *q); |
84 | extern void blk_mq_sysfs_unregister(struct request_queue *q); | |
868f2f0b | 85 | extern void blk_mq_hctx_kobj_init(struct blk_mq_hw_ctx *hctx); |
67aec14c | 86 | |
90415837 CH |
87 | extern void blk_mq_rq_timed_out(struct request *req, bool reserved); |
88 | ||
e09aae7e ML |
89 | void blk_mq_release(struct request_queue *q); |
90 | ||
1aecfe48 ML |
91 | static inline struct blk_mq_ctx *__blk_mq_get_ctx(struct request_queue *q, |
92 | unsigned int cpu) | |
93 | { | |
94 | return per_cpu_ptr(q->queue_ctx, cpu); | |
95 | } | |
96 | ||
97 | /* | |
98 | * This assumes per-cpu software queueing queues. They could be per-node | |
99 | * as well, for instance. For now this is hardcoded as-is. Note that we don't | |
100 | * care about preemption, since we know the ctx's are persistent. This does | |
101 | * mean that we can't rely on ctx always matching the currently running CPU. | |
102 | */ | |
103 | static inline struct blk_mq_ctx *blk_mq_get_ctx(struct request_queue *q) | |
104 | { | |
105 | return __blk_mq_get_ctx(q, get_cpu()); | |
106 | } | |
107 | ||
108 | static inline void blk_mq_put_ctx(struct blk_mq_ctx *ctx) | |
109 | { | |
110 | put_cpu(); | |
111 | } | |
112 | ||
cb96a42c ML |
113 | struct blk_mq_alloc_data { |
114 | /* input parameter */ | |
115 | struct request_queue *q; | |
9a95e4ef | 116 | blk_mq_req_flags_t flags; |
229a9287 | 117 | unsigned int shallow_depth; |
cb96a42c ML |
118 | |
119 | /* input & output parameter */ | |
120 | struct blk_mq_ctx *ctx; | |
121 | struct blk_mq_hw_ctx *hctx; | |
122 | }; | |
123 | ||
4941115b JA |
124 | static inline struct blk_mq_tags *blk_mq_tags_from_data(struct blk_mq_alloc_data *data) |
125 | { | |
bd166ef1 JA |
126 | if (data->flags & BLK_MQ_REQ_INTERNAL) |
127 | return data->hctx->sched_tags; | |
128 | ||
4941115b JA |
129 | return data->hctx->tags; |
130 | } | |
131 | ||
5d1b25c1 BVA |
132 | static inline bool blk_mq_hctx_stopped(struct blk_mq_hw_ctx *hctx) |
133 | { | |
134 | return test_bit(BLK_MQ_S_STOPPED, &hctx->state); | |
135 | } | |
136 | ||
19c66e59 ML |
137 | static inline bool blk_mq_hw_queue_mapped(struct blk_mq_hw_ctx *hctx) |
138 | { | |
139 | return hctx->nr_ctx && hctx->tags; | |
140 | } | |
141 | ||
f299b7c7 | 142 | void blk_mq_in_flight(struct request_queue *q, struct hd_struct *part, |
416d3aa7 OS |
143 | unsigned int inflight[2]); |
144 | void blk_mq_in_flight_rw(struct request_queue *q, struct hd_struct *part, | |
145 | unsigned int inflight[2]); | |
f299b7c7 | 146 | |
de148297 ML |
147 | static inline void blk_mq_put_dispatch_budget(struct blk_mq_hw_ctx *hctx) |
148 | { | |
149 | struct request_queue *q = hctx->queue; | |
150 | ||
151 | if (q->mq_ops->put_budget) | |
152 | q->mq_ops->put_budget(hctx); | |
153 | } | |
154 | ||
88022d72 | 155 | static inline bool blk_mq_get_dispatch_budget(struct blk_mq_hw_ctx *hctx) |
de148297 ML |
156 | { |
157 | struct request_queue *q = hctx->queue; | |
158 | ||
159 | if (q->mq_ops->get_budget) | |
160 | return q->mq_ops->get_budget(hctx); | |
88022d72 | 161 | return true; |
de148297 ML |
162 | } |
163 | ||
244c65a3 ML |
164 | static inline void __blk_mq_put_driver_tag(struct blk_mq_hw_ctx *hctx, |
165 | struct request *rq) | |
166 | { | |
167 | blk_mq_put_tag(hctx, hctx->tags, rq->mq_ctx, rq->tag); | |
168 | rq->tag = -1; | |
169 | ||
170 | if (rq->rq_flags & RQF_MQ_INFLIGHT) { | |
171 | rq->rq_flags &= ~RQF_MQ_INFLIGHT; | |
172 | atomic_dec(&hctx->nr_active); | |
173 | } | |
174 | } | |
175 | ||
176 | static inline void blk_mq_put_driver_tag_hctx(struct blk_mq_hw_ctx *hctx, | |
177 | struct request *rq) | |
178 | { | |
179 | if (rq->tag == -1 || rq->internal_tag == -1) | |
180 | return; | |
181 | ||
182 | __blk_mq_put_driver_tag(hctx, rq); | |
183 | } | |
184 | ||
185 | static inline void blk_mq_put_driver_tag(struct request *rq) | |
186 | { | |
187 | struct blk_mq_hw_ctx *hctx; | |
188 | ||
189 | if (rq->tag == -1 || rq->internal_tag == -1) | |
190 | return; | |
191 | ||
192 | hctx = blk_mq_map_queue(rq->q, rq->mq_ctx->cpu); | |
193 | __blk_mq_put_driver_tag(hctx, rq); | |
194 | } | |
195 | ||
320ae51f | 196 | #endif |