4 #include <linux/kernel.h>
5 #include <linux/module.h>
8 #include <linux/slab.h>
25 return blk_map_queue_find_tag(q->queue_tags, tag);
36 static int __blk_free_tags(
struct blk_queue_tag *bqt)
45 kfree(bqt->tag_index);
46 bqt->tag_index =
NULL;
67 struct blk_queue_tag *bqt = q->queue_tags;
75 queue_flag_clear_unlocked(QUEUE_FLAG_QUEUED, q);
103 queue_flag_clear_unlocked(QUEUE_FLAG_QUEUED, q);
111 unsigned long *tag_map;
114 if (q && depth > q->nr_requests * 2) {
115 depth = q->nr_requests * 2;
125 tag_map = kzalloc(nr_ulongs *
sizeof(
unsigned long),
GFP_ATOMIC);
129 tags->real_max_depth =
depth;
130 tags->max_depth =
depth;
131 tags->tag_index = tag_index;
132 tags->tag_map = tag_map;
140 static struct blk_queue_tag *__blk_queue_init_tags(
struct request_queue *q,
143 struct blk_queue_tag *
tags;
149 if (init_tag_map(q, tags, depth))
165 return __blk_queue_init_tags(
NULL, depth);
179 struct blk_queue_tag *tags)
183 BUG_ON(tags && q->queue_tags && tags != q->queue_tags);
185 if (!tags && !q->queue_tags) {
186 tags = __blk_queue_init_tags(q, depth);
191 }
else if (q->queue_tags) {
195 queue_flag_set(QUEUE_FLAG_QUEUED, q);
203 q->queue_tags =
tags;
204 queue_flag_set_unlocked(QUEUE_FLAG_QUEUED, q);
205 INIT_LIST_HEAD(&q->tag_busy_list);
220 struct blk_queue_tag *bqt = q->queue_tags;
222 unsigned long *tag_map;
223 int max_depth, nr_ulongs;
234 if (new_depth <= bqt->real_max_depth) {
249 tag_index = bqt->tag_index;
250 tag_map = bqt->tag_map;
251 max_depth = bqt->real_max_depth;
253 if (init_tag_map(q, bqt, new_depth))
256 memcpy(bqt->tag_index, tag_index, max_depth *
sizeof(
struct request *));
258 memcpy(bqt->tag_map, tag_map, nr_ulongs *
sizeof(
unsigned long));
282 struct blk_queue_tag *bqt = q->queue_tags;
283 unsigned tag = rq->tag;
285 BUG_ON(tag >= bqt->real_max_depth);
287 list_del_init(&rq->queuelist);
330 struct blk_queue_tag *bqt = q->queue_tags;
336 "%s: request %p for device [%s] already tagged %d",
338 rq->rq_disk ? rq->rq_disk->disk_name :
"?", rq->tag);
349 max_depth = bqt->max_depth;
350 if (!rq_is_sync(rq) && max_depth > 1) {
360 if (tag >= max_depth)
371 bqt->tag_index[
tag] =
rq;
373 list_add(&rq->queuelist, &q->tag_busy_list);