xref: /openbmc/linux/block/blk-mq.h (revision 19c66e59ce57e7b181625cbb408d48eb10837763)
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 
2830a91cb4SChristoph Hellwig void __blk_mq_complete_request(struct request *rq);
29320ae51fSJens Axboe void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async);
30780db207STejun Heo void blk_mq_freeze_queue(struct request_queue *q);
313edcc0ceSMing Lei void blk_mq_free_queue(struct request_queue *q);
328727af4bSChristoph Hellwig void blk_mq_clone_flush_request(struct request *flush_rq,
338727af4bSChristoph Hellwig 		struct request *orig_rq);
34e3a2b3f9SJens Axboe int blk_mq_update_nr_requests(struct request_queue *q, unsigned int nr);
35320ae51fSJens Axboe 
36320ae51fSJens Axboe /*
37320ae51fSJens Axboe  * CPU hotplug helpers
38320ae51fSJens Axboe  */
39320ae51fSJens Axboe struct blk_mq_cpu_notifier;
40320ae51fSJens Axboe void blk_mq_init_cpu_notifier(struct blk_mq_cpu_notifier *notifier,
41e814e71bSJens Axboe 			      int (*fn)(void *, unsigned long, unsigned int),
42320ae51fSJens Axboe 			      void *data);
43320ae51fSJens Axboe void blk_mq_register_cpu_notifier(struct blk_mq_cpu_notifier *notifier);
44320ae51fSJens Axboe void blk_mq_unregister_cpu_notifier(struct blk_mq_cpu_notifier *notifier);
45320ae51fSJens Axboe void blk_mq_cpu_init(void);
46676141e4SJens Axboe void blk_mq_enable_hotplug(void);
47676141e4SJens Axboe void blk_mq_disable_hotplug(void);
48320ae51fSJens Axboe 
49320ae51fSJens Axboe /*
50320ae51fSJens Axboe  * CPU -> queue mappings
51320ae51fSJens Axboe  */
5224d2f903SChristoph Hellwig extern unsigned int *blk_mq_make_queue_map(struct blk_mq_tag_set *set);
53320ae51fSJens Axboe extern int blk_mq_update_queue_map(unsigned int *map, unsigned int nr_queues);
54f14bbe77SJens Axboe extern int blk_mq_hw_queue_to_node(unsigned int *map, unsigned int);
55320ae51fSJens Axboe 
56e93ecf60SJens Axboe /*
5767aec14cSJens Axboe  * sysfs helpers
5867aec14cSJens Axboe  */
5967aec14cSJens Axboe extern int blk_mq_sysfs_register(struct request_queue *q);
6067aec14cSJens Axboe extern void blk_mq_sysfs_unregister(struct request_queue *q);
6167aec14cSJens Axboe 
6290415837SChristoph Hellwig extern void blk_mq_rq_timed_out(struct request *req, bool reserved);
6390415837SChristoph Hellwig 
6467aec14cSJens Axboe /*
65e93ecf60SJens Axboe  * Basic implementation of sparser bitmap, allowing the user to spread
66e93ecf60SJens Axboe  * the bits over more cachelines.
67e93ecf60SJens Axboe  */
68e93ecf60SJens Axboe struct blk_align_bitmap {
69e93ecf60SJens Axboe 	unsigned long word;
70e93ecf60SJens Axboe 	unsigned long depth;
71e93ecf60SJens Axboe } ____cacheline_aligned_in_smp;
72e93ecf60SJens Axboe 
731aecfe48SMing Lei static inline struct blk_mq_ctx *__blk_mq_get_ctx(struct request_queue *q,
741aecfe48SMing Lei 					   unsigned int cpu)
751aecfe48SMing Lei {
761aecfe48SMing Lei 	return per_cpu_ptr(q->queue_ctx, cpu);
771aecfe48SMing Lei }
781aecfe48SMing Lei 
791aecfe48SMing Lei /*
801aecfe48SMing Lei  * This assumes per-cpu software queueing queues. They could be per-node
811aecfe48SMing Lei  * as well, for instance. For now this is hardcoded as-is. Note that we don't
821aecfe48SMing Lei  * care about preemption, since we know the ctx's are persistent. This does
831aecfe48SMing Lei  * mean that we can't rely on ctx always matching the currently running CPU.
841aecfe48SMing Lei  */
851aecfe48SMing Lei static inline struct blk_mq_ctx *blk_mq_get_ctx(struct request_queue *q)
861aecfe48SMing Lei {
871aecfe48SMing Lei 	return __blk_mq_get_ctx(q, get_cpu());
881aecfe48SMing Lei }
891aecfe48SMing Lei 
901aecfe48SMing Lei static inline void blk_mq_put_ctx(struct blk_mq_ctx *ctx)
911aecfe48SMing Lei {
921aecfe48SMing Lei 	put_cpu();
931aecfe48SMing Lei }
941aecfe48SMing Lei 
95cb96a42cSMing Lei struct blk_mq_alloc_data {
96cb96a42cSMing Lei 	/* input parameter */
97cb96a42cSMing Lei 	struct request_queue *q;
98cb96a42cSMing Lei 	gfp_t gfp;
99cb96a42cSMing Lei 	bool reserved;
100cb96a42cSMing Lei 
101cb96a42cSMing Lei 	/* input & output parameter */
102cb96a42cSMing Lei 	struct blk_mq_ctx *ctx;
103cb96a42cSMing Lei 	struct blk_mq_hw_ctx *hctx;
104cb96a42cSMing Lei };
105cb96a42cSMing Lei 
106cb96a42cSMing Lei static inline void blk_mq_set_alloc_data(struct blk_mq_alloc_data *data,
107cb96a42cSMing Lei 		struct request_queue *q, gfp_t gfp, bool reserved,
108cb96a42cSMing Lei 		struct blk_mq_ctx *ctx,
109cb96a42cSMing Lei 		struct blk_mq_hw_ctx *hctx)
110cb96a42cSMing Lei {
111cb96a42cSMing Lei 	data->q = q;
112cb96a42cSMing Lei 	data->gfp = gfp;
113cb96a42cSMing Lei 	data->reserved = reserved;
114cb96a42cSMing Lei 	data->ctx = ctx;
115cb96a42cSMing Lei 	data->hctx = hctx;
116cb96a42cSMing Lei }
117cb96a42cSMing Lei 
118*19c66e59SMing Lei static inline bool blk_mq_hw_queue_mapped(struct blk_mq_hw_ctx *hctx)
119*19c66e59SMing Lei {
120*19c66e59SMing Lei 	return hctx->nr_ctx && hctx->tags;
121*19c66e59SMing Lei }
122*19c66e59SMing Lei 
123320ae51fSJens Axboe #endif
124