blk-mq-tag.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef INT_BLK_MQ_TAG_H
  3. #define INT_BLK_MQ_TAG_H
  4. #include "blk-mq.h"
  5. /*
  6. * Tag address space map.
  7. */
  8. struct blk_mq_tags {
  9. unsigned int nr_tags;
  10. unsigned int nr_reserved_tags;
  11. atomic_t active_queues;
  12. struct sbitmap_queue bitmap_tags;
  13. struct sbitmap_queue breserved_tags;
  14. struct request **rqs;
  15. struct request **static_rqs;
  16. struct list_head page_list;
  17. };
  18. extern struct blk_mq_tags *blk_mq_init_tags(unsigned int nr_tags, unsigned int reserved_tags, int node, int alloc_policy);
  19. extern void blk_mq_free_tags(struct blk_mq_tags *tags);
  20. extern unsigned int blk_mq_get_tag(struct blk_mq_alloc_data *data);
  21. extern void blk_mq_put_tag(struct blk_mq_hw_ctx *hctx, struct blk_mq_tags *tags,
  22. struct blk_mq_ctx *ctx, unsigned int tag);
  23. extern bool blk_mq_has_free_tags(struct blk_mq_tags *tags);
  24. extern int blk_mq_tag_update_depth(struct blk_mq_hw_ctx *hctx,
  25. struct blk_mq_tags **tags,
  26. unsigned int depth, bool can_grow);
  27. extern void blk_mq_tag_wakeup_all(struct blk_mq_tags *tags, bool);
  28. void blk_mq_queue_tag_busy_iter(struct request_queue *q, busy_iter_fn *fn,
  29. void *priv);
  30. static inline struct sbq_wait_state *bt_wait_ptr(struct sbitmap_queue *bt,
  31. struct blk_mq_hw_ctx *hctx)
  32. {
  33. if (!hctx)
  34. return &bt->ws[0];
  35. return sbq_wait_ptr(bt, &hctx->wait_index);
  36. }
  37. enum {
  38. BLK_MQ_TAG_FAIL = -1U,
  39. BLK_MQ_TAG_MIN = 1,
  40. BLK_MQ_TAG_MAX = BLK_MQ_TAG_FAIL - 1,
  41. };
  42. extern bool __blk_mq_tag_busy(struct blk_mq_hw_ctx *);
  43. extern void __blk_mq_tag_idle(struct blk_mq_hw_ctx *);
  44. static inline bool blk_mq_tag_busy(struct blk_mq_hw_ctx *hctx)
  45. {
  46. if (!(hctx->flags & BLK_MQ_F_TAG_SHARED))
  47. return false;
  48. return __blk_mq_tag_busy(hctx);
  49. }
  50. static inline void blk_mq_tag_idle(struct blk_mq_hw_ctx *hctx)
  51. {
  52. if (!(hctx->flags & BLK_MQ_F_TAG_SHARED))
  53. return;
  54. __blk_mq_tag_idle(hctx);
  55. }
  56. /*
  57. * This helper should only be used for flush request to share tag
  58. * with the request cloned from, and both the two requests can't be
  59. * in flight at the same time. The caller has to make sure the tag
  60. * can't be freed.
  61. */
  62. static inline void blk_mq_tag_set_rq(struct blk_mq_hw_ctx *hctx,
  63. unsigned int tag, struct request *rq)
  64. {
  65. hctx->tags->rqs[tag] = rq;
  66. }
  67. static inline bool blk_mq_tag_is_reserved(struct blk_mq_tags *tags,
  68. unsigned int tag)
  69. {
  70. return tag < tags->nr_reserved_tags;
  71. }
  72. #endif