1320ae51fSJens Axboe #ifndef INT_BLK_MQ_H 2320ae51fSJens Axboe #define INT_BLK_MQ_H 3320ae51fSJens Axboe 424d2f903SChristoph Hellwig struct blk_mq_tag_set; 524d2f903SChristoph Hellwig 6320ae51fSJens Axboe struct blk_mq_ctx { 7320ae51fSJens Axboe struct { 8320ae51fSJens Axboe spinlock_t lock; 9320ae51fSJens Axboe struct list_head rq_list; 10320ae51fSJens Axboe } ____cacheline_aligned_in_smp; 11320ae51fSJens Axboe 12320ae51fSJens Axboe unsigned int cpu; 13320ae51fSJens Axboe unsigned int index_hw; 14320ae51fSJens Axboe 15320ae51fSJens Axboe /* incremented at dispatch time */ 16320ae51fSJens Axboe unsigned long rq_dispatched[2]; 17320ae51fSJens Axboe unsigned long rq_merged; 18320ae51fSJens Axboe 19320ae51fSJens Axboe /* incremented at completion time */ 20320ae51fSJens Axboe unsigned long ____cacheline_aligned_in_smp rq_completed[2]; 21320ae51fSJens Axboe 22320ae51fSJens Axboe struct request_queue *queue; 23320ae51fSJens Axboe struct kobject kobj; 244bb659b1SJens Axboe } ____cacheline_aligned_in_smp; 25320ae51fSJens Axboe 26320ae51fSJens Axboe void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async); 27780db207STejun Heo void blk_mq_freeze_queue(struct request_queue *q); 283edcc0ceSMing Lei void blk_mq_free_queue(struct request_queue *q); 29e3a2b3f9SJens Axboe int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr); 30aed3ea94SJens Axboe void blk_mq_wake_waiters(struct request_queue *q); 31320ae51fSJens Axboe 32320ae51fSJens Axboe /* 33320ae51fSJens Axboe * CPU hotplug helpers 34320ae51fSJens Axboe */ 35676141e4SJens Axboe void blk_mq_enable_hotplug(void); 36676141e4SJens Axboe void blk_mq_disable_hotplug(void); 37320ae51fSJens Axboe 38320ae51fSJens Axboe /* 39320ae51fSJens Axboe * CPU -> queue mappings 40320ae51fSJens Axboe */ 41da695ba2SChristoph Hellwig int blk_mq_map_queues(struct blk_mq_tag_set *set); 42f14bbe77SJens Axboe extern int blk_mq_hw_queue_to_node(unsigned int *map, unsigned int); 43320ae51fSJens Axboe 447d7e0f90SChristoph Hellwig static inline struct blk_mq_hw_ctx *blk_mq_map_queue(struct request_queue *q, 457d7e0f90SChristoph Hellwig int cpu) 467d7e0f90SChristoph Hellwig { 477d7e0f90SChristoph Hellwig return q->queue_hw_ctx[q->mq_map[cpu]]; 487d7e0f90SChristoph Hellwig } 497d7e0f90SChristoph Hellwig 50e93ecf60SJens Axboe /* 5167aec14cSJens Axboe * sysfs helpers 5267aec14cSJens Axboe */ 5367aec14cSJens Axboe extern int blk_mq_sysfs_register(struct request_queue *q); 5467aec14cSJens Axboe extern void blk_mq_sysfs_unregister(struct request_queue *q); 55868f2f0bSKeith Busch extern void blk_mq_hctx_kobj_init(struct blk_mq_hw_ctx *hctx); 5667aec14cSJens Axboe 5790415837SChristoph Hellwig extern void blk_mq_rq_timed_out(struct request *req, bool reserved); 5890415837SChristoph Hellwig 59e09aae7eSMing Lei void blk_mq_release(struct request_queue *q); 60e09aae7eSMing Lei 611aecfe48SMing Lei static inline struct blk_mq_ctx *__blk_mq_get_ctx(struct request_queue *q, 621aecfe48SMing Lei unsigned int cpu) 631aecfe48SMing Lei { 641aecfe48SMing Lei return per_cpu_ptr(q->queue_ctx, cpu); 651aecfe48SMing Lei } 661aecfe48SMing Lei 671aecfe48SMing Lei /* 681aecfe48SMing Lei * This assumes per-cpu software queueing queues. They could be per-node 691aecfe48SMing Lei * as well, for instance. For now this is hardcoded as-is. Note that we don't 701aecfe48SMing Lei * care about preemption, since we know the ctx's are persistent. This does 711aecfe48SMing Lei * mean that we can't rely on ctx always matching the currently running CPU. 721aecfe48SMing Lei */ 731aecfe48SMing Lei static inline struct blk_mq_ctx *blk_mq_get_ctx(struct request_queue *q) 741aecfe48SMing Lei { 751aecfe48SMing Lei return __blk_mq_get_ctx(q, get_cpu()); 761aecfe48SMing Lei } 771aecfe48SMing Lei 781aecfe48SMing Lei static inline void blk_mq_put_ctx(struct blk_mq_ctx *ctx) 791aecfe48SMing Lei { 801aecfe48SMing Lei put_cpu(); 811aecfe48SMing Lei } 821aecfe48SMing Lei 83cb96a42cSMing Lei struct blk_mq_alloc_data { 84cb96a42cSMing Lei /* input parameter */ 85cb96a42cSMing Lei struct request_queue *q; 866f3b0e8bSChristoph Hellwig unsigned int flags; 87cb96a42cSMing Lei 88cb96a42cSMing Lei /* input & output parameter */ 89cb96a42cSMing Lei struct blk_mq_ctx *ctx; 90cb96a42cSMing Lei struct blk_mq_hw_ctx *hctx; 91cb96a42cSMing Lei }; 92cb96a42cSMing Lei 93cb96a42cSMing Lei static inline void blk_mq_set_alloc_data(struct blk_mq_alloc_data *data, 946f3b0e8bSChristoph Hellwig struct request_queue *q, unsigned int flags, 956f3b0e8bSChristoph Hellwig struct blk_mq_ctx *ctx, struct blk_mq_hw_ctx *hctx) 96cb96a42cSMing Lei { 97cb96a42cSMing Lei data->q = q; 986f3b0e8bSChristoph Hellwig data->flags = flags; 99cb96a42cSMing Lei data->ctx = ctx; 100cb96a42cSMing Lei data->hctx = hctx; 101cb96a42cSMing Lei } 102cb96a42cSMing Lei 103*5d1b25c1SBart Van Assche static inline bool blk_mq_hctx_stopped(struct blk_mq_hw_ctx *hctx) 104*5d1b25c1SBart Van Assche { 105*5d1b25c1SBart Van Assche return test_bit(BLK_MQ_S_STOPPED, &hctx->state); 106*5d1b25c1SBart Van Assche } 107*5d1b25c1SBart Van Assche 10819c66e59SMing Lei static inline bool blk_mq_hw_queue_mapped(struct blk_mq_hw_ctx *hctx) 10919c66e59SMing Lei { 11019c66e59SMing Lei return hctx->nr_ctx && hctx->tags; 11119c66e59SMing Lei } 11219c66e59SMing Lei 113320ae51fSJens Axboe #endif 114