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 154bb659b1SJens Axboe unsigned int last_tag ____cacheline_aligned_in_smp; 164bb659b1SJens Axboe 17320ae51fSJens Axboe /* incremented at dispatch time */ 18320ae51fSJens Axboe unsigned long rq_dispatched[2]; 19320ae51fSJens Axboe unsigned long rq_merged; 20320ae51fSJens Axboe 21320ae51fSJens Axboe /* incremented at completion time */ 22320ae51fSJens Axboe unsigned long ____cacheline_aligned_in_smp rq_completed[2]; 23320ae51fSJens Axboe 24320ae51fSJens Axboe struct request_queue *queue; 25320ae51fSJens Axboe struct kobject kobj; 264bb659b1SJens Axboe } ____cacheline_aligned_in_smp; 27320ae51fSJens Axboe 28320ae51fSJens Axboe void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async); 29780db207STejun Heo void blk_mq_freeze_queue(struct request_queue *q); 303edcc0ceSMing Lei void blk_mq_free_queue(struct request_queue *q); 31e3a2b3f9SJens Axboe int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr); 32aed3ea94SJens Axboe void blk_mq_wake_waiters(struct request_queue *q); 33320ae51fSJens Axboe 34320ae51fSJens Axboe /* 35320ae51fSJens Axboe * CPU hotplug helpers 36320ae51fSJens Axboe */ 37320ae51fSJens Axboe struct blk_mq_cpu_notifier; 38320ae51fSJens Axboe void blk_mq_init_cpu_notifier(struct blk_mq_cpu_notifier *notifier, 39e814e71bSJens Axboe int (*fn)(void *, unsigned long, unsigned int), 40320ae51fSJens Axboe void *data); 41320ae51fSJens Axboe void blk_mq_register_cpu_notifier(struct blk_mq_cpu_notifier *notifier); 42320ae51fSJens Axboe void blk_mq_unregister_cpu_notifier(struct blk_mq_cpu_notifier *notifier); 43320ae51fSJens Axboe void blk_mq_cpu_init(void); 44676141e4SJens Axboe void blk_mq_enable_hotplug(void); 45676141e4SJens Axboe void blk_mq_disable_hotplug(void); 46320ae51fSJens Axboe 47320ae51fSJens Axboe /* 48320ae51fSJens Axboe * CPU -> queue mappings 49320ae51fSJens Axboe */ 5024d2f903SChristoph Hellwig extern unsigned int *blk_mq_make_queue_map(struct blk_mq_tag_set *set); 515778322eSAkinobu Mita extern int blk_mq_update_queue_map(unsigned int *map, unsigned int nr_queues, 525778322eSAkinobu Mita const struct cpumask *online_mask); 53f14bbe77SJens Axboe extern int blk_mq_hw_queue_to_node(unsigned int *map, unsigned int); 54320ae51fSJens Axboe 55e93ecf60SJens Axboe /* 5667aec14cSJens Axboe * sysfs helpers 5767aec14cSJens Axboe */ 5867aec14cSJens Axboe extern int blk_mq_sysfs_register(struct request_queue *q); 5967aec14cSJens Axboe extern void blk_mq_sysfs_unregister(struct request_queue *q); 60*868f2f0bSKeith Busch extern void blk_mq_hctx_kobj_init(struct blk_mq_hw_ctx *hctx); 6167aec14cSJens Axboe 6290415837SChristoph Hellwig extern void blk_mq_rq_timed_out(struct request *req, bool reserved); 6390415837SChristoph Hellwig 64e09aae7eSMing Lei void blk_mq_release(struct request_queue *q); 65e09aae7eSMing Lei 6667aec14cSJens Axboe /* 67e93ecf60SJens Axboe * Basic implementation of sparser bitmap, allowing the user to spread 68e93ecf60SJens Axboe * the bits over more cachelines. 69e93ecf60SJens Axboe */ 70e93ecf60SJens Axboe struct blk_align_bitmap { 71e93ecf60SJens Axboe unsigned long word; 72e93ecf60SJens Axboe unsigned long depth; 73e93ecf60SJens Axboe } ____cacheline_aligned_in_smp; 74e93ecf60SJens Axboe 751aecfe48SMing Lei static inline struct blk_mq_ctx *__blk_mq_get_ctx(struct request_queue *q, 761aecfe48SMing Lei unsigned int cpu) 771aecfe48SMing Lei { 781aecfe48SMing Lei return per_cpu_ptr(q->queue_ctx, cpu); 791aecfe48SMing Lei } 801aecfe48SMing Lei 811aecfe48SMing Lei /* 821aecfe48SMing Lei * This assumes per-cpu software queueing queues. They could be per-node 831aecfe48SMing Lei * as well, for instance. For now this is hardcoded as-is. Note that we don't 841aecfe48SMing Lei * care about preemption, since we know the ctx's are persistent. This does 851aecfe48SMing Lei * mean that we can't rely on ctx always matching the currently running CPU. 861aecfe48SMing Lei */ 871aecfe48SMing Lei static inline struct blk_mq_ctx *blk_mq_get_ctx(struct request_queue *q) 881aecfe48SMing Lei { 891aecfe48SMing Lei return __blk_mq_get_ctx(q, get_cpu()); 901aecfe48SMing Lei } 911aecfe48SMing Lei 921aecfe48SMing Lei static inline void blk_mq_put_ctx(struct blk_mq_ctx *ctx) 931aecfe48SMing Lei { 941aecfe48SMing Lei put_cpu(); 951aecfe48SMing Lei } 961aecfe48SMing Lei 97cb96a42cSMing Lei struct blk_mq_alloc_data { 98cb96a42cSMing Lei /* input parameter */ 99cb96a42cSMing Lei struct request_queue *q; 1006f3b0e8bSChristoph Hellwig unsigned int flags; 101cb96a42cSMing Lei 102cb96a42cSMing Lei /* input & output parameter */ 103cb96a42cSMing Lei struct blk_mq_ctx *ctx; 104cb96a42cSMing Lei struct blk_mq_hw_ctx *hctx; 105cb96a42cSMing Lei }; 106cb96a42cSMing Lei 107cb96a42cSMing Lei static inline void blk_mq_set_alloc_data(struct blk_mq_alloc_data *data, 1086f3b0e8bSChristoph Hellwig struct request_queue *q, unsigned int flags, 1096f3b0e8bSChristoph Hellwig struct blk_mq_ctx *ctx, struct blk_mq_hw_ctx *hctx) 110cb96a42cSMing Lei { 111cb96a42cSMing Lei data->q = q; 1126f3b0e8bSChristoph Hellwig data->flags = flags; 113cb96a42cSMing Lei data->ctx = ctx; 114cb96a42cSMing Lei data->hctx = hctx; 115cb96a42cSMing Lei } 116cb96a42cSMing Lei 11719c66e59SMing Lei static inline bool blk_mq_hw_queue_mapped(struct blk_mq_hw_ctx *hctx) 11819c66e59SMing Lei { 11919c66e59SMing Lei return hctx->nr_ctx && hctx->tags; 12019c66e59SMing Lei } 12119c66e59SMing Lei 122320ae51fSJens Axboe #endif 123