1#ifndef INT_BLK_MQ_TAG_H
2#define INT_BLK_MQ_TAG_H
3
4#include "blk-mq.h"
5
6
7
8
9#ifdef __GENKSYMS__
10struct blk_mq_tags;
11#else
12struct blk_mq_tags {
13 unsigned int nr_tags;
14 unsigned int nr_reserved_tags;
15
16 atomic_t active_queues;
17
18 struct sbitmap_queue bitmap_tags;
19 struct sbitmap_queue breserved_tags;
20
21 struct request **rqs;
22 struct request **static_rqs;
23 struct list_head page_list;
24};
25#endif
26
27
28extern struct blk_mq_tags *blk_mq_init_tags(unsigned int nr_tags, unsigned int reserved_tags, int node, int alloc_policy);
29extern void blk_mq_free_tags(struct blk_mq_tags *tags);
30
31extern unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data);
32extern void blk_mq_put_tag(struct blk_mq_hw_ctx *hctx, struct blk_mq_tags *tags,
33 struct blk_mq_ctx *ctx, unsigned int tag);
34extern bool blk_mq_has_free_tags(struct blk_mq_tags *tags);
35extern int blk_mq_tag_update_depth(struct blk_mq_hw_ctx *hctx,
36 struct blk_mq_tags **tags,
37 unsigned int depth, bool can_grow);
38extern void blk_mq_tag_wakeup_all(struct blk_mq_tags *tags, bool);
39void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_iter_fn *fn,
40 void *priv);
41
42static inline struct sbq_wait_state *bt_wait_ptr(struct sbitmap_queue *bt,
43 struct blk_mq_hw_ctx *hctx)
44{
45 if (!hctx)
46 return &bt->ws[0];
47 return sbq_wait_ptr(bt, &hctx->wait_index);
48}
49
50enum {
51 BLK_MQ_TAG_CACHE_MIN = 1,
52 BLK_MQ_TAG_CACHE_MAX = 64,
53};
54
55enum {
56 BLK_MQ_TAG_FAIL = -1U,
57 BLK_MQ_TAG_MIN = BLK_MQ_TAG_CACHE_MIN,
58 BLK_MQ_TAG_MAX = BLK_MQ_TAG_FAIL - 1,
59};
60
61extern bool __blk_mq_tag_busy(struct blk_mq_hw_ctx *);
62extern void __blk_mq_tag_idle(struct blk_mq_hw_ctx *);
63
64static inline bool blk_mq_tag_busy(struct blk_mq_hw_ctx *hctx)
65{
66 if (!(hctx->flags & BLK_MQ_F_TAG_SHARED))
67 return false;
68
69 return __blk_mq_tag_busy(hctx);
70}
71
72static inline void blk_mq_tag_idle(struct blk_mq_hw_ctx *hctx)
73{
74 if (!(hctx->flags & BLK_MQ_F_TAG_SHARED))
75 return;
76
77 __blk_mq_tag_idle(hctx);
78}
79
80
81
82
83
84
85
86static inline void blk_mq_tag_set_rq(struct blk_mq_hw_ctx *hctx,
87 unsigned int tag, struct request *rq)
88{
89 hctx->tags->rqs[tag] = rq;
90}
91
92static inline bool blk_mq_tag_is_reserved(struct blk_mq_tags *tags,
93 unsigned int tag)
94{
95 return tag < tags->nr_reserved_tags;
96}
97
98#endif
99