blk-mq.h 18.0 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
2 3 4 5
#ifndef BLK_MQ_H
#define BLK_MQ_H

#include <linux/blkdev.h>
6
#include <linux/sbitmap.h>
7
#include <linux/srcu.h>
8 9

struct blk_mq_tags;
10
struct blk_flush_queue;
11

12
/**
13 14
 * struct blk_mq_hw_ctx - State for a hardware queue facing the hardware
 * block device
15
 */
16 17
struct blk_mq_hw_ctx {
	struct {
18
		/** @lock: Protects the dispatch list. */
19
		spinlock_t		lock;
20 21 22 23 24 25 26
		/**
		 * @dispatch: Used for requests that are ready to be
		 * dispatched to the hardware but for some reason (e.g. lack of
		 * resources) could not be sent to the hardware. As soon as the
		 * driver can send new requests, requests at this list will
		 * be sent first for a fairer dispatch.
		 */
27
		struct list_head	dispatch;
28 29 30 31 32
		 /**
		  * @state: BLK_MQ_S_* flags. Defines the state of the hw
		  * queue (active, scheduled to restart, stopped).
		  */
		unsigned long		state;
33 34
	} ____cacheline_aligned_in_smp;

35 36 37
	/**
	 * @run_work: Used for scheduling a hardware queue run at a later time.
	 */
38
	struct delayed_work	run_work;
39
	/** @cpumask: Map of available CPUs where this hctx can run. */
40
	cpumask_var_t		cpumask;
41 42 43 44
	/**
	 * @next_cpu: Used by blk_mq_hctx_next_cpu() for round-robin CPU
	 * selection from @cpumask.
	 */
45
	int			next_cpu;
46 47 48 49
	/**
	 * @next_cpu_batch: Counter of how many works left in the batch before
	 * changing to the next CPU.
	 */
50
	int			next_cpu_batch;
51

52 53
	/** @flags: BLK_MQ_F_* flags. Defines the behaviour of the queue. */
	unsigned long		flags;
54

55 56 57 58
	/**
	 * @sched_data: Pointer owned by the IO scheduler attached to a request
	 * queue. It's up to the IO scheduler how to use this pointer.
	 */
59
	void			*sched_data;
60 61 62
	/**
	 * @queue: Pointer to the request queue that owns this hardware context.
	 */
63
	struct request_queue	*queue;
64
	/** @fq: Queue of requests that need to perform a flush operation. */
65
	struct blk_flush_queue	*fq;
66

67 68 69 70
	/**
	 * @driver_data: Pointer to data owned by the block driver that created
	 * this hctx
	 */
71 72
	void			*driver_data;

73 74 75 76
	/**
	 * @ctx_map: Bitmap for each software queue. If bit is on, there is a
	 * pending request in that software queue.
	 */
77
	struct sbitmap		ctx_map;
78

79 80 81 82
	/**
	 * @dispatch_from: Software queue to be used when no scheduler was
	 * selected.
	 */
83
	struct blk_mq_ctx	*dispatch_from;
84 85 86 87 88
	/**
	 * @dispatch_busy: Number used by blk_mq_update_dispatch_busy() to
	 * decide if the hw_queue is busy using Exponential Weighted Moving
	 * Average algorithm.
	 */
89
	unsigned int		dispatch_busy;
90

91
	/** @type: HCTX_TYPE_* flags. Type of hardware queue. */
92
	unsigned short		type;
93
	/** @nr_ctx: Number of software queues. */
94
	unsigned short		nr_ctx;
95
	/** @ctxs: Array of software queues. */
96
	struct blk_mq_ctx	**ctxs;
97

98
	/** @dispatch_wait_lock: Lock for dispatch_wait queue. */
99
	spinlock_t		dispatch_wait_lock;
100 101 102 103
	/**
	 * @dispatch_wait: Waitqueue to put requests when there is no tag
	 * available at the moment, to wait for another try in the future.
	 */
104
	wait_queue_entry_t	dispatch_wait;
105 106 107 108 109

	/**
	 * @wait_index: Index of next available dispatch_wait queue to insert
	 * requests.
	 */
110
	atomic_t		wait_index;
111

112 113 114 115
	/**
	 * @tags: Tags owned by the block driver. A tag at this set is only
	 * assigned when a request is dispatched from a hardware queue.
	 */
116
	struct blk_mq_tags	*tags;
117 118 119 120 121
	/**
	 * @sched_tags: Tags owned by I/O scheduler. If there is an I/O
	 * scheduler associated with a request queue, a tag is assigned when
	 * that request is allocated. Else, this member is not used.
	 */
122
	struct blk_mq_tags	*sched_tags;
123

124
	/** @queued: Number of queued requests. */
125
	unsigned long		queued;
126
	/** @run: Number of dispatched requests. */
127
	unsigned long		run;
128
#define BLK_MQ_MAX_DISPATCH_ORDER	7
129
	/** @dispatched: Number of dispatch requests by queue. */
130 131
	unsigned long		dispatched[BLK_MQ_MAX_DISPATCH_ORDER];

132
	/** @numa_node: NUMA node the storage adapter has been connected to. */
133
	unsigned int		numa_node;
134
	/** @queue_num: Index of this hardware queue. */
135
	unsigned int		queue_num;
136

137 138 139 140
	/**
	 * @nr_active: Number of active requests. Only used when a tag set is
	 * shared across request queues.
	 */
141 142
	atomic_t		nr_active;

143 144
	/** @cpuhp_online: List to store request if CPU is going to die */
	struct hlist_node	cpuhp_online;
145
	/** @cpuhp_dead: List to store request if some CPU die. */
146
	struct hlist_node	cpuhp_dead;
147
	/** @kobj: Kernel object for sysfs. */
148
	struct kobject		kobj;
J
Jens Axboe 已提交
149

150
	/** @poll_considered: Count times blk_poll() was called. */
151
	unsigned long		poll_considered;
152
	/** @poll_invoked: Count how many requests blk_poll() polled. */
J
Jens Axboe 已提交
153
	unsigned long		poll_invoked;
154
	/** @poll_success: Count how many polled requests were completed. */
J
Jens Axboe 已提交
155
	unsigned long		poll_success;
156 157

#ifdef CONFIG_BLK_DEBUG_FS
158 159 160 161
	/**
	 * @debugfs_dir: debugfs directory for this hardware queue. Named
	 * as cpu<cpu_number>.
	 */
162
	struct dentry		*debugfs_dir;
163
	/** @sched_debugfs_dir:	debugfs directory for the scheduler. */
164
	struct dentry		*sched_debugfs_dir;
165
#endif
166

167 168 169 170
	/**
	 * @hctx_list: if this hctx is not in use, this is an entry in
	 * q->unused_hctx_list.
	 */
171 172
	struct list_head	hctx_list;

173 174 175 176 177
	/**
	 * @srcu: Sleepable RCU. Use as lock when type of the hardware queue is
	 * blocking (BLK_MQ_F_BLOCKING). Must be the last member - see also
	 * blk_mq_hw_ctx_size().
	 */
178
	struct srcu_struct	srcu[];
179 180
};

181
/**
182
 * struct blk_mq_queue_map - Map software queues to hardware queues
183 184 185 186 187 188 189 190
 * @mq_map:       CPU ID to hardware queue index map. This is an array
 *	with nr_cpu_ids elements. Each element has a value in the range
 *	[@queue_offset, @queue_offset + @nr_queues).
 * @nr_queues:    Number of hardware queues to map CPU IDs onto.
 * @queue_offset: First hardware queue to map onto. Used by the PCIe NVMe
 *	driver to map each hardware queue type (enum hctx_type) onto a distinct
 *	set of hardware queues.
 */
J
Jens Axboe 已提交
191 192 193
struct blk_mq_queue_map {
	unsigned int *mq_map;
	unsigned int nr_queues;
194
	unsigned int queue_offset;
J
Jens Axboe 已提交
195 196
};

197 198 199 200 201 202 203
/**
 * enum hctx_type - Type of hardware queue
 * @HCTX_TYPE_DEFAULT:	All I/O not otherwise accounted for.
 * @HCTX_TYPE_READ:	Just for READ I/O.
 * @HCTX_TYPE_POLL:	Polled I/O of any kind.
 * @HCTX_MAX_TYPES:	Number of types of hctx.
 */
204
enum hctx_type {
205 206 207
	HCTX_TYPE_DEFAULT,
	HCTX_TYPE_READ,
	HCTX_TYPE_POLL,
208 209

	HCTX_MAX_TYPES,
J
Jens Axboe 已提交
210 211
};

212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
/**
 * struct blk_mq_tag_set - tag set that can be shared between request queues
 * @map:	   One or more ctx -> hctx mappings. One map exists for each
 *		   hardware queue type (enum hctx_type) that the driver wishes
 *		   to support. There are no restrictions on maps being of the
 *		   same size, and it's perfectly legal to share maps between
 *		   types.
 * @nr_maps:	   Number of elements in the @map array. A number in the range
 *		   [1, HCTX_MAX_TYPES].
 * @ops:	   Pointers to functions that implement block driver behavior.
 * @nr_hw_queues:  Number of hardware queues supported by the block driver that
 *		   owns this data structure.
 * @queue_depth:   Number of tags per hardware queue, reserved tags included.
 * @reserved_tags: Number of tags to set aside for BLK_MQ_REQ_RESERVED tag
 *		   allocations.
 * @cmd_size:	   Number of additional bytes to allocate per request. The block
 *		   driver owns these additional bytes.
 * @numa_node:	   NUMA node the storage adapter has been connected to.
 * @timeout:	   Request processing timeout in jiffies.
 * @flags:	   Zero or more BLK_MQ_F_* flags.
 * @driver_data:   Pointer to data owned by the block driver that created this
 *		   tag set.
234 235 236
 * @__bitmap_tags: A shared tags sbitmap, used over all hctx's
 * @__breserved_tags:
 *		   A shared reserved tags sbitmap, used over all hctx's
237 238 239 240 241 242
 * @tags:	   Tag sets. One tag set per hardware queue. Has @nr_hw_queues
 *		   elements.
 * @tag_list_lock: Serializes tag_list accesses.
 * @tag_list:	   List of the request queues that use this tag set. See also
 *		   request_queue.tag_set_list.
 */
243
struct blk_mq_tag_set {
J
Jens Axboe 已提交
244
	struct blk_mq_queue_map	map[HCTX_MAX_TYPES];
245
	unsigned int		nr_maps;
J
Jens Axboe 已提交
246
	const struct blk_mq_ops	*ops;
247 248
	unsigned int		nr_hw_queues;
	unsigned int		queue_depth;
249
	unsigned int		reserved_tags;
250
	unsigned int		cmd_size;
251 252
	int			numa_node;
	unsigned int		timeout;
253
	unsigned int		flags;
254 255
	void			*driver_data;

256 257
	struct sbitmap_queue	__bitmap_tags;
	struct sbitmap_queue	__breserved_tags;
258
	struct blk_mq_tags	**tags;
259 260 261

	struct mutex		tag_list_lock;
	struct list_head	tag_list;
262 263
};

264 265 266 267 268 269
/**
 * struct blk_mq_queue_data - Data about a request inserted in a queue
 *
 * @rq:   Request pointer.
 * @last: If it is the last request in the queue.
 */
270 271 272 273 274
struct blk_mq_queue_data {
	struct request *rq;
	bool last;
};

275
typedef bool (busy_iter_fn)(struct blk_mq_hw_ctx *, struct request *, void *,
276
		bool);
277
typedef bool (busy_tag_iter_fn)(struct request *, void *, bool);
J
Jens Axboe 已提交
278

279 280 281 282
/**
 * struct blk_mq_ops - Callback functions that implements block driver
 * behaviour.
 */
283
struct blk_mq_ops {
284 285
	/**
	 * @queue_rq: Queue a new request from block IO.
286
	 */
287 288
	blk_status_t (*queue_rq)(struct blk_mq_hw_ctx *,
				 const struct blk_mq_queue_data *);
289

290 291 292 293
	/**
	 * @commit_rqs: If a driver uses bd->last to judge when to submit
	 * requests to hardware, it must define this function. In case of errors
	 * that make us stop issuing further requests, this hook serves the
J
Jens Axboe 已提交
294 295 296
	 * purpose of kicking the hardware (which the last request otherwise
	 * would have done).
	 */
297
	void (*commit_rqs)(struct blk_mq_hw_ctx *);
J
Jens Axboe 已提交
298

299 300
	/**
	 * @get_budget: Reserve budget before queue request, once .queue_rq is
301 302 303 304
	 * run, it is driver's responsibility to release the
	 * reserved budget. Also we have to handle failure case
	 * of .get_budget for avoiding I/O deadlock.
	 */
305 306
	bool (*get_budget)(struct request_queue *);

307 308 309
	/**
	 * @put_budget: Release the reserved budget.
	 */
310
	void (*put_budget)(struct request_queue *);
311

312 313
	/**
	 * @timeout: Called on request timeout.
314
	 */
315
	enum blk_eh_timer_return (*timeout)(struct request *, bool);
316

317 318
	/**
	 * @poll: Called to poll for completion of a specific tag.
J
Jens Axboe 已提交
319
	 */
320
	int (*poll)(struct blk_mq_hw_ctx *);
J
Jens Axboe 已提交
321

322 323 324
	/**
	 * @complete: Mark the request as complete.
	 */
325
	void (*complete)(struct request *);
326

327 328 329 330
	/**
	 * @init_hctx: Called when the block layer side of a hardware queue has
	 * been set up, allowing the driver to allocate/init matching
	 * structures.
331
	 */
332
	int (*init_hctx)(struct blk_mq_hw_ctx *, void *, unsigned int);
333 334 335
	/**
	 * @exit_hctx: Ditto for exit/teardown.
	 */
336
	void (*exit_hctx)(struct blk_mq_hw_ctx *, unsigned int);
337

338 339 340
	/**
	 * @init_request: Called for every command allocated by the block layer
	 * to allow the driver to set up driver specific data.
341 342 343
	 *
	 * Tag greater than or equal to queue_depth is for setting up
	 * flush request.
344
	 */
345 346
	int (*init_request)(struct blk_mq_tag_set *set, struct request *,
			    unsigned int, unsigned int);
347 348 349
	/**
	 * @exit_request: Ditto for exit/teardown.
	 */
350 351
	void (*exit_request)(struct blk_mq_tag_set *set, struct request *,
			     unsigned int);
352 353 354 355

	/**
	 * @initialize_rq_fn: Called from inside blk_get_request().
	 */
356
	void (*initialize_rq_fn)(struct request *rq);
357

358 359 360
	/**
	 * @cleanup_rq: Called before freeing one request which isn't completed
	 * yet, and usually for freeing the driver private data.
M
Ming Lei 已提交
361
	 */
362
	void (*cleanup_rq)(struct request *);
M
Ming Lei 已提交
363

364 365
	/**
	 * @busy: If set, returns whether or not this queue currently is busy.
J
Jens Axboe 已提交
366
	 */
367
	bool (*busy)(struct request_queue *);
J
Jens Axboe 已提交
368

369 370 371 372
	/**
	 * @map_queues: This allows drivers specify their own queue mapping by
	 * overriding the setup-time function that builds the mq_map.
	 */
373
	int (*map_queues)(struct blk_mq_tag_set *set);
374 375

#ifdef CONFIG_BLK_DEBUG_FS
376 377
	/**
	 * @show_rq: Used by the debugfs implementation to show driver-specific
378 379 380 381
	 * information about a request.
	 */
	void (*show_rq)(struct seq_file *m, struct request *rq);
#endif
382 383 384 385
};

enum {
	BLK_MQ_F_SHOULD_MERGE	= 1 << 0,
386
	BLK_MQ_F_TAG_QUEUE_SHARED = 1 << 1,
387 388 389 390 391
	/*
	 * Set when this device requires underlying blk-mq device for
	 * completing IO:
	 */
	BLK_MQ_F_STACKING	= 1 << 2,
392
	BLK_MQ_F_TAG_HCTX_SHARED = 1 << 3,
393
	BLK_MQ_F_BLOCKING	= 1 << 5,
394
	BLK_MQ_F_NO_SCHED	= 1 << 6,
S
Shaohua Li 已提交
395 396
	BLK_MQ_F_ALLOC_POLICY_START_BIT = 8,
	BLK_MQ_F_ALLOC_POLICY_BITS = 1,
397

398
	BLK_MQ_S_STOPPED	= 0,
399
	BLK_MQ_S_TAG_ACTIVE	= 1,
400
	BLK_MQ_S_SCHED_RESTART	= 2,
401

402 403 404
	/* hw queue is inactive after all its CPUs become offline */
	BLK_MQ_S_INACTIVE	= 3,

405
	BLK_MQ_MAX_DEPTH	= 10240,
406 407

	BLK_MQ_CPU_WORK_BATCH	= 8,
408
};
S
Shaohua Li 已提交
409 410 411 412 413 414
#define BLK_MQ_FLAG_TO_ALLOC_POLICY(flags) \
	((flags >> BLK_MQ_F_ALLOC_POLICY_START_BIT) & \
		((1 << BLK_MQ_F_ALLOC_POLICY_BITS) - 1))
#define BLK_ALLOC_POLICY_TO_MQ_FLAG(policy) \
	((policy & ((1 << BLK_MQ_F_ALLOC_POLICY_BITS) - 1)) \
		<< BLK_MQ_F_ALLOC_POLICY_START_BIT)
415

416
struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *);
417 418
struct request_queue *blk_mq_init_queue_data(struct blk_mq_tag_set *set,
		void *queuedata);
419
struct request_queue *blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
420 421
						  struct request_queue *q,
						  bool elevator_init);
422 423 424 425
struct request_queue *blk_mq_init_sq_queue(struct blk_mq_tag_set *set,
						const struct blk_mq_ops *ops,
						unsigned int queue_depth,
						unsigned int set_flags);
426
void blk_mq_unregister_dev(struct device *, struct request_queue *);
427

428 429 430
int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set);
void blk_mq_free_tag_set(struct blk_mq_tag_set *set);

431 432 433
void blk_mq_flush_plug_list(struct blk_plug *plug, bool from_schedule);

void blk_mq_free_request(struct request *rq);
434

435
bool blk_mq_queue_inflight(struct request_queue *q);
436

437
enum {
438 439 440 441 442 443
	/* return when out of requests */
	BLK_MQ_REQ_NOWAIT	= (__force blk_mq_req_flags_t)(1 << 0),
	/* allocate from reserved pool */
	BLK_MQ_REQ_RESERVED	= (__force blk_mq_req_flags_t)(1 << 1),
	/* set RQF_PREEMPT */
	BLK_MQ_REQ_PREEMPT	= (__force blk_mq_req_flags_t)(1 << 3),
444 445
};

446
struct request *blk_mq_alloc_request(struct request_queue *q, unsigned int op,
447
		blk_mq_req_flags_t flags);
448
struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
449 450
		unsigned int op, blk_mq_req_flags_t flags,
		unsigned int hctx_idx);
451
struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags, unsigned int tag);
452

B
Bart Van Assche 已提交
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
enum {
	BLK_MQ_UNIQUE_TAG_BITS = 16,
	BLK_MQ_UNIQUE_TAG_MASK = (1 << BLK_MQ_UNIQUE_TAG_BITS) - 1,
};

u32 blk_mq_unique_tag(struct request *rq);

static inline u16 blk_mq_unique_tag_to_hwq(u32 unique_tag)
{
	return unique_tag >> BLK_MQ_UNIQUE_TAG_BITS;
}

static inline u16 blk_mq_unique_tag_to_tag(u32 unique_tag)
{
	return unique_tag & BLK_MQ_UNIQUE_TAG_MASK;
}

P
Pavel Begunkov 已提交
470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
/**
 * blk_mq_rq_state() - read the current MQ_RQ_* state of a request
 * @rq: target request.
 */
static inline enum mq_rq_state blk_mq_rq_state(struct request *rq)
{
	return READ_ONCE(rq->state);
}

static inline int blk_mq_request_started(struct request *rq)
{
	return blk_mq_rq_state(rq) != MQ_RQ_IDLE;
}

static inline int blk_mq_request_completed(struct request *rq)
{
	return blk_mq_rq_state(rq) == MQ_RQ_COMPLETE;
}
488

489
void blk_mq_start_request(struct request *rq);
490 491
void blk_mq_end_request(struct request *rq, blk_status_t error);
void __blk_mq_end_request(struct request *rq, blk_status_t error);
492

493
void blk_mq_requeue_request(struct request *rq, bool kick_requeue_list);
494
void blk_mq_kick_requeue_list(struct request_queue *q);
495
void blk_mq_delay_kick_requeue_list(struct request_queue *q, unsigned long msecs);
496
void blk_mq_complete_request(struct request *rq);
497
bool blk_mq_complete_request_remote(struct request *rq);
498
bool blk_mq_queue_stopped(struct request_queue *q);
499 500
void blk_mq_stop_hw_queue(struct blk_mq_hw_ctx *hctx);
void blk_mq_start_hw_queue(struct blk_mq_hw_ctx *hctx);
501
void blk_mq_stop_hw_queues(struct request_queue *q);
502
void blk_mq_start_hw_queues(struct request_queue *q);
503
void blk_mq_start_stopped_hw_queue(struct blk_mq_hw_ctx *hctx, bool async);
504
void blk_mq_start_stopped_hw_queues(struct request_queue *q, bool async);
505
void blk_mq_quiesce_queue(struct request_queue *q);
506
void blk_mq_unquiesce_queue(struct request_queue *q);
507
void blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs);
508
void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async);
509
void blk_mq_run_hw_queues(struct request_queue *q, bool async);
510
void blk_mq_delay_run_hw_queues(struct request_queue *q, unsigned long msecs);
511 512
void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
		busy_tag_iter_fn *fn, void *priv);
513
void blk_mq_tagset_wait_completed_request(struct blk_mq_tag_set *tagset);
514
void blk_mq_freeze_queue(struct request_queue *q);
515
void blk_mq_unfreeze_queue(struct request_queue *q);
516
void blk_freeze_queue_start(struct request_queue *q);
517
void blk_mq_freeze_queue_wait(struct request_queue *q);
518 519
int blk_mq_freeze_queue_wait_timeout(struct request_queue *q,
				     unsigned long timeout);
520

J
Jens Axboe 已提交
521
int blk_mq_map_queues(struct blk_mq_queue_map *qmap);
K
Keith Busch 已提交
522 523
void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int nr_hw_queues);

524
void blk_mq_quiesce_queue_nowait(struct request_queue *q);
525

J
Jens Axboe 已提交
526 527
unsigned int blk_mq_rq_cpu(struct request *rq);

528 529 530 531 532 533 534 535 536
bool __blk_should_fake_timeout(struct request_queue *q);
static inline bool blk_should_fake_timeout(struct request_queue *q)
{
	if (IS_ENABLED(CONFIG_FAIL_IO_TIMEOUT) &&
	    test_bit(QUEUE_FLAG_FAIL_IO, &q->queue_flags))
		return __blk_should_fake_timeout(q);
	return false;
}

537 538 539 540 541 542
/**
 * blk_mq_rq_from_pdu - cast a PDU to a request
 * @pdu: the PDU (Protocol Data Unit) to be casted
 *
 * Return: request
 *
543
 * Driver command data is immediately after the request. So subtract request
544
 * size to get back to the original request.
545 546 547 548 549
 */
static inline struct request *blk_mq_rq_from_pdu(void *pdu)
{
	return pdu - sizeof(struct request);
}
550 551 552 553 554 555 556 557 558 559

/**
 * blk_mq_rq_to_pdu - cast a request to a PDU
 * @rq: the request to be casted
 *
 * Return: pointer to the PDU
 *
 * Driver command data is immediately after the request. So add request to get
 * the PDU.
 */
560 561
static inline void *blk_mq_rq_to_pdu(struct request *rq)
{
J
Jens Axboe 已提交
562
	return rq + 1;
563 564 565
}

#define queue_for_each_hw_ctx(q, hctx, i)				\
566 567
	for ((i) = 0; (i) < (q)->nr_hw_queues &&			\
	     ({ hctx = (q)->queue_hw_ctx[i]; 1; }); (i)++)
568 569

#define hctx_for_each_ctx(hctx, ctx, i)					\
570 571
	for ((i) = 0; (i) < (hctx)->nr_ctx &&				\
	     ({ ctx = (hctx)->ctxs[(i)]; 1; }); (i)++)
572

S
Sagi Grimberg 已提交
573 574 575 576 577 578 579 580 581 582
static inline blk_qc_t request_to_qc_t(struct blk_mq_hw_ctx *hctx,
		struct request *rq)
{
	if (rq->tag != -1)
		return rq->tag | (hctx->queue_num << BLK_QC_T_SHIFT);

	return rq->internal_tag | (hctx->queue_num << BLK_QC_T_SHIFT) |
			BLK_QC_T_INTERNAL;
}

M
Ming Lei 已提交
583 584 585 586 587 588
static inline void blk_mq_cleanup_rq(struct request *rq)
{
	if (rq->q->mq_ops->cleanup_rq)
		rq->q->mq_ops->cleanup_rq(rq);
}

589
blk_qc_t blk_mq_submit_bio(struct bio *bio);
590

591
#endif