sbitmap_clear_bit(&hctx->ctx_map, ctx->index_hw);
 }
 
+struct mq_inflight {
+       struct hd_struct *part;
+       unsigned int *inflight;
+};
+
+static void blk_mq_check_inflight(struct blk_mq_hw_ctx *hctx,
+                                 struct request *rq, void *priv,
+                                 bool reserved)
+{
+       struct mq_inflight *mi = priv;
+
+       if (test_bit(REQ_ATOM_STARTED, &rq->atomic_flags) &&
+           !test_bit(REQ_ATOM_COMPLETE, &rq->atomic_flags)) {
+               /*
+                * Count as inflight if it either matches the partition we
+                * asked for, or if it's the root
+                */
+               if (rq->part == mi->part || mi->part->partno)
+                       mi->inflight[0]++;
+       }
+}
+
+void blk_mq_in_flight(struct request_queue *q, struct hd_struct *part,
+                     unsigned int inflight[2])
+{
+       struct mq_inflight mi = { .part = part, .inflight = inflight, };
+
+       inflight[0] = 0;
+       blk_mq_queue_tag_busy_iter(q, blk_mq_check_inflight, &mi);
+}
+
 void blk_freeze_queue_start(struct request_queue *q)
 {
        int freeze_depth;
 
        return hctx->nr_ctx && hctx->tags;
 }
 
+void blk_mq_in_flight(struct request_queue *q, struct hd_struct *part,
+                       unsigned int inflight[2]);
+
 #endif
 
 static void disk_del_events(struct gendisk *disk);
 static void disk_release_events(struct gendisk *disk);
 
+void part_inc_in_flight(struct request_queue *q, struct hd_struct *part, int rw)
+{
+       if (q->mq_ops)
+               return;
+
+       atomic_inc(&part->in_flight[rw]);
+       if (part->partno)
+               atomic_inc(&part_to_disk(part)->part0.in_flight[rw]);
+}
+
+void part_dec_in_flight(struct request_queue *q, struct hd_struct *part, int rw)
+{
+       if (q->mq_ops)
+               return;
+
+       atomic_dec(&part->in_flight[rw]);
+       if (part->partno)
+               atomic_dec(&part_to_disk(part)->part0.in_flight[rw]);
+}
+
+void part_in_flight(struct request_queue *q, struct hd_struct *part,
+                   unsigned int inflight[2])
+{
+       if (q->mq_ops) {
+               blk_mq_in_flight(q, part, inflight);
+               return;
+       }
+
+       inflight[0] = atomic_read(&part->in_flight[0]) +
+                       atomic_read(&part->in_flight[1]);
+       if (part->partno) {
+               part = &part_to_disk(part)->part0;
+               inflight[1] = atomic_read(&part->in_flight[0]) +
+                               atomic_read(&part->in_flight[1]);
+       }
+}
+
 /**
  * disk_get_part - get partition
  * @disk: disk to look partition from
 
 #define part_stat_sub(cpu, gendiskp, field, subnd)                     \
        part_stat_add(cpu, gendiskp, field, -subnd)
 
-static inline void part_inc_in_flight(struct request_queue *q,
-                                     struct hd_struct *part, int rw)
-{
-       atomic_inc(&part->in_flight[rw]);
-       if (part->partno)
-               atomic_inc(&part_to_disk(part)->part0.in_flight[rw]);
-}
-
-static inline void part_dec_in_flight(struct request_queue *q,
-                                     struct hd_struct *part, int rw)
-{
-       atomic_dec(&part->in_flight[rw]);
-       if (part->partno)
-               atomic_dec(&part_to_disk(part)->part0.in_flight[rw]);
-}
-
-static inline void part_in_flight(struct request_queue *q,
-                                 struct hd_struct *part,
-                                 unsigned int inflight[2])
-{
-       inflight[0] = atomic_read(&part->in_flight[0]) +
-                       atomic_read(&part->in_flight[1]);
-       if (part->partno) {
-               part = &part_to_disk(part)->part0;
-               inflight[1] = atomic_read(&part->in_flight[0]) +
-                               atomic_read(&part->in_flight[1]);
-       } else
-               inflight[1] = 0;
-}
+void part_in_flight(struct request_queue *q, struct hd_struct *part,
+                       unsigned int inflight[2]);
+void part_dec_in_flight(struct request_queue *q, struct hd_struct *part,
+                       int rw);
+void part_inc_in_flight(struct request_queue *q, struct hd_struct *part,
+                       int rw);
 
 static inline struct partition_meta_info *alloc_part_info(struct gendisk *disk)
 {