blk-mq.h 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef BLK_MQ_H
  3. #define BLK_MQ_H
  4. #include <linux/blkdev.h>
  5. #include <linux/sbitmap.h>
  6. #include <linux/lockdep.h>
  7. #include <linux/scatterlist.h>
  8. #include <linux/prefetch.h>
  9. #include <linux/android_kabi.h>
  10. struct blk_mq_tags;
  11. struct blk_flush_queue;
  12. #define BLKDEV_MIN_RQ 4
  13. #define BLKDEV_DEFAULT_RQ 128
  14. enum rq_end_io_ret {
  15. RQ_END_IO_NONE,
  16. RQ_END_IO_FREE,
  17. };
  18. typedef enum rq_end_io_ret (rq_end_io_fn)(struct request *, blk_status_t);
  19. /*
  20. * request flags */
  21. typedef __u32 __bitwise req_flags_t;
  22. /* drive already may have started this one */
  23. #define RQF_STARTED ((__force req_flags_t)(1 << 1))
  24. /* may not be passed by ioscheduler */
  25. #define RQF_SOFTBARRIER ((__force req_flags_t)(1 << 3))
  26. /* request for flush sequence */
  27. #define RQF_FLUSH_SEQ ((__force req_flags_t)(1 << 4))
  28. /* merge of different types, fail separately */
  29. #define RQF_MIXED_MERGE ((__force req_flags_t)(1 << 5))
  30. /* track inflight for MQ */
  31. #define RQF_MQ_INFLIGHT ((__force req_flags_t)(1 << 6))
  32. /* don't call prep for this one */
  33. #define RQF_DONTPREP ((__force req_flags_t)(1 << 7))
  34. /* vaguely specified driver internal error. Ignored by the block layer */
  35. #define RQF_FAILED ((__force req_flags_t)(1 << 10))
  36. /* don't warn about errors */
  37. #define RQF_QUIET ((__force req_flags_t)(1 << 11))
  38. /* elevator private data attached */
  39. #define RQF_ELVPRIV ((__force req_flags_t)(1 << 12))
  40. /* account into disk and partition IO statistics */
  41. #define RQF_IO_STAT ((__force req_flags_t)(1 << 13))
  42. /* runtime pm request */
  43. #define RQF_PM ((__force req_flags_t)(1 << 15))
  44. /* on IO scheduler merge hash */
  45. #define RQF_HASHED ((__force req_flags_t)(1 << 16))
  46. /* track IO completion time */
  47. #define RQF_STATS ((__force req_flags_t)(1 << 17))
  48. /* Look at ->special_vec for the actual data payload instead of the
  49. bio chain. */
  50. #define RQF_SPECIAL_PAYLOAD ((__force req_flags_t)(1 << 18))
  51. /* The per-zone write lock is held for this request */
  52. #define RQF_ZONE_WRITE_LOCKED ((__force req_flags_t)(1 << 19))
  53. /* already slept for hybrid poll */
  54. #define RQF_MQ_POLL_SLEPT ((__force req_flags_t)(1 << 20))
  55. /* ->timeout has been called, don't expire again */
  56. #define RQF_TIMED_OUT ((__force req_flags_t)(1 << 21))
  57. /* queue has elevator attached */
  58. #define RQF_ELV ((__force req_flags_t)(1 << 22))
  59. #define RQF_RESV ((__force req_flags_t)(1 << 23))
  60. /* flags that prevent us from merging requests: */
  61. #define RQF_NOMERGE_FLAGS \
  62. (RQF_STARTED | RQF_SOFTBARRIER | RQF_FLUSH_SEQ | RQF_SPECIAL_PAYLOAD)
  63. enum mq_rq_state {
  64. MQ_RQ_IDLE = 0,
  65. MQ_RQ_IN_FLIGHT = 1,
  66. MQ_RQ_COMPLETE = 2,
  67. };
  68. /*
  69. * Try to put the fields that are referenced together in the same cacheline.
  70. *
  71. * If you modify this structure, make sure to update blk_rq_init() and
  72. * especially blk_mq_rq_ctx_init() to take care of the added fields.
  73. */
  74. struct request {
  75. struct request_queue *q;
  76. struct blk_mq_ctx *mq_ctx;
  77. struct blk_mq_hw_ctx *mq_hctx;
  78. blk_opf_t cmd_flags; /* op and common flags */
  79. req_flags_t rq_flags;
  80. int tag;
  81. int internal_tag;
  82. unsigned int timeout;
  83. /* the following two fields are internal, NEVER access directly */
  84. unsigned int __data_len; /* total data len */
  85. sector_t __sector; /* sector cursor */
  86. struct bio *bio;
  87. struct bio *biotail;
  88. union {
  89. struct list_head queuelist;
  90. struct request *rq_next;
  91. };
  92. struct block_device *part;
  93. #ifdef CONFIG_BLK_RQ_ALLOC_TIME
  94. /* Time that the first bio started allocating this request. */
  95. u64 alloc_time_ns;
  96. #endif
  97. /* Time that this request was allocated for this IO. */
  98. u64 start_time_ns;
  99. /* Time that I/O was submitted to the device. */
  100. u64 io_start_time_ns;
  101. #ifdef CONFIG_BLK_WBT
  102. unsigned short wbt_flags;
  103. #endif
  104. /*
  105. * rq sectors used for blk stats. It has the same value
  106. * with blk_rq_sectors(rq), except that it never be zeroed
  107. * by completion.
  108. */
  109. unsigned short stats_sectors;
  110. /*
  111. * Number of scatter-gather DMA addr+len pairs after
  112. * physical address coalescing is performed.
  113. */
  114. unsigned short nr_phys_segments;
  115. #ifdef CONFIG_BLK_DEV_INTEGRITY
  116. unsigned short nr_integrity_segments;
  117. #endif
  118. #ifdef CONFIG_BLK_INLINE_ENCRYPTION
  119. struct bio_crypt_ctx *crypt_ctx;
  120. struct blk_crypto_keyslot *crypt_keyslot;
  121. #endif
  122. unsigned short write_hint;
  123. unsigned short ioprio;
  124. enum mq_rq_state state;
  125. atomic_t ref;
  126. unsigned long deadline;
  127. /*
  128. * The hash is used inside the scheduler, and killed once the
  129. * request reaches the dispatch list. The ipi_list is only used
  130. * to queue the request for softirq completion, which is long
  131. * after the request has been unhashed (and even removed from
  132. * the dispatch list).
  133. */
  134. union {
  135. struct hlist_node hash; /* merge hash */
  136. struct llist_node ipi_list;
  137. };
  138. /*
  139. * The rb_node is only used inside the io scheduler, requests
  140. * are pruned when moved to the dispatch queue. So let the
  141. * completion_data share space with the rb_node.
  142. */
  143. union {
  144. struct rb_node rb_node; /* sort/lookup */
  145. struct bio_vec special_vec;
  146. void *completion_data;
  147. };
  148. /*
  149. * Three pointers are available for IO schedulers. If they need
  150. * more private data they have to allocate it dynamically.
  151. */
  152. struct {
  153. struct io_cq *icq;
  154. void *priv[2];
  155. } elv;
  156. struct {
  157. unsigned int seq;
  158. struct list_head list;
  159. rq_end_io_fn *saved_end_io;
  160. } flush;
  161. union {
  162. struct __call_single_data csd;
  163. u64 fifo_time;
  164. };
  165. /*
  166. * completion callback.
  167. */
  168. rq_end_io_fn *end_io;
  169. void *end_io_data;
  170. ANDROID_KABI_RESERVE(1);
  171. };
  172. static inline enum req_op req_op(const struct request *req)
  173. {
  174. return req->cmd_flags & REQ_OP_MASK;
  175. }
  176. static inline bool blk_rq_is_passthrough(struct request *rq)
  177. {
  178. return blk_op_is_passthrough(req_op(rq));
  179. }
  180. static inline unsigned short req_get_ioprio(struct request *req)
  181. {
  182. return req->ioprio;
  183. }
  184. #define rq_data_dir(rq) (op_is_write(req_op(rq)) ? WRITE : READ)
  185. #define rq_dma_dir(rq) \
  186. (op_is_write(req_op(rq)) ? DMA_TO_DEVICE : DMA_FROM_DEVICE)
  187. #define rq_list_add(listptr, rq) do { \
  188. (rq)->rq_next = *(listptr); \
  189. *(listptr) = rq; \
  190. } while (0)
  191. #define rq_list_add_tail(lastpptr, rq) do { \
  192. (rq)->rq_next = NULL; \
  193. **(lastpptr) = rq; \
  194. *(lastpptr) = &rq->rq_next; \
  195. } while (0)
  196. #define rq_list_pop(listptr) \
  197. ({ \
  198. struct request *__req = NULL; \
  199. if ((listptr) && *(listptr)) { \
  200. __req = *(listptr); \
  201. *(listptr) = __req->rq_next; \
  202. } \
  203. __req; \
  204. })
  205. #define rq_list_peek(listptr) \
  206. ({ \
  207. struct request *__req = NULL; \
  208. if ((listptr) && *(listptr)) \
  209. __req = *(listptr); \
  210. __req; \
  211. })
  212. #define rq_list_for_each(listptr, pos) \
  213. for (pos = rq_list_peek((listptr)); pos; pos = rq_list_next(pos))
  214. #define rq_list_for_each_safe(listptr, pos, nxt) \
  215. for (pos = rq_list_peek((listptr)), nxt = rq_list_next(pos); \
  216. pos; pos = nxt, nxt = pos ? rq_list_next(pos) : NULL)
  217. #define rq_list_next(rq) (rq)->rq_next
  218. #define rq_list_empty(list) ((list) == (struct request *) NULL)
  219. /**
  220. * rq_list_move() - move a struct request from one list to another
  221. * @src: The source list @rq is currently in
  222. * @dst: The destination list that @rq will be appended to
  223. * @rq: The request to move
  224. * @prev: The request preceding @rq in @src (NULL if @rq is the head)
  225. */
  226. static inline void rq_list_move(struct request **src, struct request **dst,
  227. struct request *rq, struct request *prev)
  228. {
  229. if (prev)
  230. prev->rq_next = rq->rq_next;
  231. else
  232. *src = rq->rq_next;
  233. rq_list_add(dst, rq);
  234. }
  235. /**
  236. * enum blk_eh_timer_return - How the timeout handler should proceed
  237. * @BLK_EH_DONE: The block driver completed the command or will complete it at
  238. * a later time.
  239. * @BLK_EH_RESET_TIMER: Reset the request timer and continue waiting for the
  240. * request to complete.
  241. */
  242. enum blk_eh_timer_return {
  243. BLK_EH_DONE,
  244. BLK_EH_RESET_TIMER,
  245. };
  246. #define BLK_TAG_ALLOC_FIFO 0 /* allocate starting from 0 */
  247. #define BLK_TAG_ALLOC_RR 1 /* allocate starting from last allocated tag */
  248. /**
  249. * struct blk_mq_hw_ctx - State for a hardware queue facing the hardware
  250. * block device
  251. */
  252. struct blk_mq_hw_ctx {
  253. struct {
  254. /** @lock: Protects the dispatch list. */
  255. spinlock_t lock;
  256. /**
  257. * @dispatch: Used for requests that are ready to be
  258. * dispatched to the hardware but for some reason (e.g. lack of
  259. * resources) could not be sent to the hardware. As soon as the
  260. * driver can send new requests, requests at this list will
  261. * be sent first for a fairer dispatch.
  262. */
  263. struct list_head dispatch;
  264. /**
  265. * @state: BLK_MQ_S_* flags. Defines the state of the hw
  266. * queue (active, scheduled to restart, stopped).
  267. */
  268. unsigned long state;
  269. } ____cacheline_aligned_in_smp;
  270. /**
  271. * @run_work: Used for scheduling a hardware queue run at a later time.
  272. */
  273. struct delayed_work run_work;
  274. /** @cpumask: Map of available CPUs where this hctx can run. */
  275. cpumask_var_t cpumask;
  276. /**
  277. * @next_cpu: Used by blk_mq_hctx_next_cpu() for round-robin CPU
  278. * selection from @cpumask.
  279. */
  280. int next_cpu;
  281. /**
  282. * @next_cpu_batch: Counter of how many works left in the batch before
  283. * changing to the next CPU.
  284. */
  285. int next_cpu_batch;
  286. /** @flags: BLK_MQ_F_* flags. Defines the behaviour of the queue. */
  287. unsigned long flags;
  288. /**
  289. * @sched_data: Pointer owned by the IO scheduler attached to a request
  290. * queue. It's up to the IO scheduler how to use this pointer.
  291. */
  292. void *sched_data;
  293. /**
  294. * @queue: Pointer to the request queue that owns this hardware context.
  295. */
  296. struct request_queue *queue;
  297. /** @fq: Queue of requests that need to perform a flush operation. */
  298. struct blk_flush_queue *fq;
  299. /**
  300. * @driver_data: Pointer to data owned by the block driver that created
  301. * this hctx
  302. */
  303. void *driver_data;
  304. /**
  305. * @ctx_map: Bitmap for each software queue. If bit is on, there is a
  306. * pending request in that software queue.
  307. */
  308. struct sbitmap ctx_map;
  309. /**
  310. * @dispatch_from: Software queue to be used when no scheduler was
  311. * selected.
  312. */
  313. struct blk_mq_ctx *dispatch_from;
  314. /**
  315. * @dispatch_busy: Number used by blk_mq_update_dispatch_busy() to
  316. * decide if the hw_queue is busy using Exponential Weighted Moving
  317. * Average algorithm.
  318. */
  319. unsigned int dispatch_busy;
  320. /** @type: HCTX_TYPE_* flags. Type of hardware queue. */
  321. unsigned short type;
  322. /** @nr_ctx: Number of software queues. */
  323. unsigned short nr_ctx;
  324. /** @ctxs: Array of software queues. */
  325. struct blk_mq_ctx **ctxs;
  326. /** @dispatch_wait_lock: Lock for dispatch_wait queue. */
  327. spinlock_t dispatch_wait_lock;
  328. /**
  329. * @dispatch_wait: Waitqueue to put requests when there is no tag
  330. * available at the moment, to wait for another try in the future.
  331. */
  332. wait_queue_entry_t dispatch_wait;
  333. /**
  334. * @wait_index: Index of next available dispatch_wait queue to insert
  335. * requests.
  336. */
  337. atomic_t wait_index;
  338. /**
  339. * @tags: Tags owned by the block driver. A tag at this set is only
  340. * assigned when a request is dispatched from a hardware queue.
  341. */
  342. struct blk_mq_tags *tags;
  343. /**
  344. * @sched_tags: Tags owned by I/O scheduler. If there is an I/O
  345. * scheduler associated with a request queue, a tag is assigned when
  346. * that request is allocated. Else, this member is not used.
  347. */
  348. struct blk_mq_tags *sched_tags;
  349. /** @queued: Number of queued requests. */
  350. unsigned long queued;
  351. /** @run: Number of dispatched requests. */
  352. unsigned long run;
  353. /** @numa_node: NUMA node the storage adapter has been connected to. */
  354. unsigned int numa_node;
  355. /** @queue_num: Index of this hardware queue. */
  356. unsigned int queue_num;
  357. /**
  358. * @nr_active: Number of active requests. Only used when a tag set is
  359. * shared across request queues.
  360. */
  361. atomic_t nr_active;
  362. /** @cpuhp_online: List to store request if CPU is going to die */
  363. struct hlist_node cpuhp_online;
  364. /** @cpuhp_dead: List to store request if some CPU die. */
  365. struct hlist_node cpuhp_dead;
  366. /** @kobj: Kernel object for sysfs. */
  367. struct kobject kobj;
  368. #ifdef CONFIG_BLK_DEBUG_FS
  369. /**
  370. * @debugfs_dir: debugfs directory for this hardware queue. Named
  371. * as cpu<cpu_number>.
  372. */
  373. struct dentry *debugfs_dir;
  374. /** @sched_debugfs_dir: debugfs directory for the scheduler. */
  375. struct dentry *sched_debugfs_dir;
  376. #endif
  377. /**
  378. * @hctx_list: if this hctx is not in use, this is an entry in
  379. * q->unused_hctx_list.
  380. */
  381. struct list_head hctx_list;
  382. ANDROID_KABI_RESERVE(1);
  383. };
  384. /**
  385. * struct blk_mq_queue_map - Map software queues to hardware queues
  386. * @mq_map: CPU ID to hardware queue index map. This is an array
  387. * with nr_cpu_ids elements. Each element has a value in the range
  388. * [@queue_offset, @queue_offset + @nr_queues).
  389. * @nr_queues: Number of hardware queues to map CPU IDs onto.
  390. * @queue_offset: First hardware queue to map onto. Used by the PCIe NVMe
  391. * driver to map each hardware queue type (enum hctx_type) onto a distinct
  392. * set of hardware queues.
  393. */
  394. struct blk_mq_queue_map {
  395. unsigned int *mq_map;
  396. unsigned int nr_queues;
  397. unsigned int queue_offset;
  398. };
  399. /**
  400. * enum hctx_type - Type of hardware queue
  401. * @HCTX_TYPE_DEFAULT: All I/O not otherwise accounted for.
  402. * @HCTX_TYPE_READ: Just for READ I/O.
  403. * @HCTX_TYPE_POLL: Polled I/O of any kind.
  404. * @HCTX_MAX_TYPES: Number of types of hctx.
  405. */
  406. enum hctx_type {
  407. HCTX_TYPE_DEFAULT,
  408. HCTX_TYPE_READ,
  409. HCTX_TYPE_POLL,
  410. HCTX_MAX_TYPES,
  411. };
  412. /**
  413. * struct blk_mq_tag_set - tag set that can be shared between request queues
  414. * @map: One or more ctx -> hctx mappings. One map exists for each
  415. * hardware queue type (enum hctx_type) that the driver wishes
  416. * to support. There are no restrictions on maps being of the
  417. * same size, and it's perfectly legal to share maps between
  418. * types.
  419. * @nr_maps: Number of elements in the @map array. A number in the range
  420. * [1, HCTX_MAX_TYPES].
  421. * @ops: Pointers to functions that implement block driver behavior.
  422. * @nr_hw_queues: Number of hardware queues supported by the block driver that
  423. * owns this data structure.
  424. * @queue_depth: Number of tags per hardware queue, reserved tags included.
  425. * @reserved_tags: Number of tags to set aside for BLK_MQ_REQ_RESERVED tag
  426. * allocations.
  427. * @cmd_size: Number of additional bytes to allocate per request. The block
  428. * driver owns these additional bytes.
  429. * @numa_node: NUMA node the storage adapter has been connected to.
  430. * @timeout: Request processing timeout in jiffies.
  431. * @flags: Zero or more BLK_MQ_F_* flags.
  432. * @driver_data: Pointer to data owned by the block driver that created this
  433. * tag set.
  434. * @tags: Tag sets. One tag set per hardware queue. Has @nr_hw_queues
  435. * elements.
  436. * @shared_tags:
  437. * Shared set of tags. Has @nr_hw_queues elements. If set,
  438. * shared by all @tags.
  439. * @tag_list_lock: Serializes tag_list accesses.
  440. * @tag_list: List of the request queues that use this tag set. See also
  441. * request_queue.tag_set_list.
  442. */
  443. struct blk_mq_tag_set {
  444. struct blk_mq_queue_map map[HCTX_MAX_TYPES];
  445. unsigned int nr_maps;
  446. const struct blk_mq_ops *ops;
  447. unsigned int nr_hw_queues;
  448. unsigned int queue_depth;
  449. unsigned int reserved_tags;
  450. unsigned int cmd_size;
  451. int numa_node;
  452. unsigned int timeout;
  453. unsigned int flags;
  454. void *driver_data;
  455. struct blk_mq_tags **tags;
  456. struct blk_mq_tags *shared_tags;
  457. struct mutex tag_list_lock;
  458. struct list_head tag_list;
  459. ANDROID_KABI_RESERVE(1);
  460. };
  461. /**
  462. * struct blk_mq_queue_data - Data about a request inserted in a queue
  463. *
  464. * @rq: Request pointer.
  465. * @last: If it is the last request in the queue.
  466. */
  467. struct blk_mq_queue_data {
  468. struct request *rq;
  469. bool last;
  470. };
  471. typedef bool (busy_tag_iter_fn)(struct request *, void *);
  472. /**
  473. * struct blk_mq_ops - Callback functions that implements block driver
  474. * behaviour.
  475. */
  476. struct blk_mq_ops {
  477. /**
  478. * @queue_rq: Queue a new request from block IO.
  479. */
  480. blk_status_t (*queue_rq)(struct blk_mq_hw_ctx *,
  481. const struct blk_mq_queue_data *);
  482. /**
  483. * @commit_rqs: If a driver uses bd->last to judge when to submit
  484. * requests to hardware, it must define this function. In case of errors
  485. * that make us stop issuing further requests, this hook serves the
  486. * purpose of kicking the hardware (which the last request otherwise
  487. * would have done).
  488. */
  489. void (*commit_rqs)(struct blk_mq_hw_ctx *);
  490. /**
  491. * @queue_rqs: Queue a list of new requests. Driver is guaranteed
  492. * that each request belongs to the same queue. If the driver doesn't
  493. * empty the @rqlist completely, then the rest will be queued
  494. * individually by the block layer upon return.
  495. */
  496. void (*queue_rqs)(struct request **rqlist);
  497. /**
  498. * @get_budget: Reserve budget before queue request, once .queue_rq is
  499. * run, it is driver's responsibility to release the
  500. * reserved budget. Also we have to handle failure case
  501. * of .get_budget for avoiding I/O deadlock.
  502. */
  503. int (*get_budget)(struct request_queue *);
  504. /**
  505. * @put_budget: Release the reserved budget.
  506. */
  507. void (*put_budget)(struct request_queue *, int);
  508. /**
  509. * @set_rq_budget_token: store rq's budget token
  510. */
  511. void (*set_rq_budget_token)(struct request *, int);
  512. /**
  513. * @get_rq_budget_token: retrieve rq's budget token
  514. */
  515. int (*get_rq_budget_token)(struct request *);
  516. /**
  517. * @timeout: Called on request timeout.
  518. */
  519. enum blk_eh_timer_return (*timeout)(struct request *);
  520. /**
  521. * @poll: Called to poll for completion of a specific tag.
  522. */
  523. int (*poll)(struct blk_mq_hw_ctx *, struct io_comp_batch *);
  524. /**
  525. * @complete: Mark the request as complete.
  526. */
  527. void (*complete)(struct request *);
  528. /**
  529. * @init_hctx: Called when the block layer side of a hardware queue has
  530. * been set up, allowing the driver to allocate/init matching
  531. * structures.
  532. */
  533. int (*init_hctx)(struct blk_mq_hw_ctx *, void *, unsigned int);
  534. /**
  535. * @exit_hctx: Ditto for exit/teardown.
  536. */
  537. void (*exit_hctx)(struct blk_mq_hw_ctx *, unsigned int);
  538. /**
  539. * @init_request: Called for every command allocated by the block layer
  540. * to allow the driver to set up driver specific data.
  541. *
  542. * Tag greater than or equal to queue_depth is for setting up
  543. * flush request.
  544. */
  545. int (*init_request)(struct blk_mq_tag_set *set, struct request *,
  546. unsigned int, unsigned int);
  547. /**
  548. * @exit_request: Ditto for exit/teardown.
  549. */
  550. void (*exit_request)(struct blk_mq_tag_set *set, struct request *,
  551. unsigned int);
  552. /**
  553. * @cleanup_rq: Called before freeing one request which isn't completed
  554. * yet, and usually for freeing the driver private data.
  555. */
  556. void (*cleanup_rq)(struct request *);
  557. /**
  558. * @busy: If set, returns whether or not this queue currently is busy.
  559. */
  560. bool (*busy)(struct request_queue *);
  561. /**
  562. * @map_queues: This allows drivers specify their own queue mapping by
  563. * overriding the setup-time function that builds the mq_map.
  564. */
  565. void (*map_queues)(struct blk_mq_tag_set *set);
  566. #ifdef CONFIG_BLK_DEBUG_FS
  567. /**
  568. * @show_rq: Used by the debugfs implementation to show driver-specific
  569. * information about a request.
  570. */
  571. void (*show_rq)(struct seq_file *m, struct request *rq);
  572. #endif
  573. ANDROID_KABI_RESERVE(1);
  574. };
  575. enum {
  576. BLK_MQ_F_SHOULD_MERGE = 1 << 0,
  577. BLK_MQ_F_TAG_QUEUE_SHARED = 1 << 1,
  578. /*
  579. * Set when this device requires underlying blk-mq device for
  580. * completing IO:
  581. */
  582. BLK_MQ_F_STACKING = 1 << 2,
  583. BLK_MQ_F_TAG_HCTX_SHARED = 1 << 3,
  584. BLK_MQ_F_BLOCKING = 1 << 5,
  585. /* Do not allow an I/O scheduler to be configured. */
  586. BLK_MQ_F_NO_SCHED = 1 << 6,
  587. /*
  588. * Select 'none' during queue registration in case of a single hwq
  589. * or shared hwqs instead of 'mq-deadline'.
  590. */
  591. BLK_MQ_F_NO_SCHED_BY_DEFAULT = 1 << 7,
  592. BLK_MQ_F_ALLOC_POLICY_START_BIT = 8,
  593. BLK_MQ_F_ALLOC_POLICY_BITS = 1,
  594. BLK_MQ_S_STOPPED = 0,
  595. BLK_MQ_S_TAG_ACTIVE = 1,
  596. BLK_MQ_S_SCHED_RESTART = 2,
  597. /* hw queue is inactive after all its CPUs become offline */
  598. BLK_MQ_S_INACTIVE = 3,
  599. BLK_MQ_MAX_DEPTH = 10240,
  600. BLK_MQ_CPU_WORK_BATCH = 8,
  601. };
  602. #define BLK_MQ_FLAG_TO_ALLOC_POLICY(flags) \
  603. ((flags >> BLK_MQ_F_ALLOC_POLICY_START_BIT) & \
  604. ((1 << BLK_MQ_F_ALLOC_POLICY_BITS) - 1))
  605. #define BLK_ALLOC_POLICY_TO_MQ_FLAG(policy) \
  606. ((policy & ((1 << BLK_MQ_F_ALLOC_POLICY_BITS) - 1)) \
  607. << BLK_MQ_F_ALLOC_POLICY_START_BIT)
  608. #define BLK_MQ_NO_HCTX_IDX (-1U)
  609. struct gendisk *__blk_mq_alloc_disk(struct blk_mq_tag_set *set, void *queuedata,
  610. struct lock_class_key *lkclass);
  611. #define blk_mq_alloc_disk(set, queuedata) \
  612. ({ \
  613. static struct lock_class_key __key; \
  614. \
  615. __blk_mq_alloc_disk(set, queuedata, &__key); \
  616. })
  617. struct gendisk *blk_mq_alloc_disk_for_queue(struct request_queue *q,
  618. struct lock_class_key *lkclass);
  619. struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *);
  620. int blk_mq_init_allocated_queue(struct blk_mq_tag_set *set,
  621. struct request_queue *q);
  622. void blk_mq_destroy_queue(struct request_queue *);
  623. int blk_mq_alloc_tag_set(struct blk_mq_tag_set *set);
  624. int blk_mq_alloc_sq_tag_set(struct blk_mq_tag_set *set,
  625. const struct blk_mq_ops *ops, unsigned int queue_depth,
  626. unsigned int set_flags);
  627. void blk_mq_free_tag_set(struct blk_mq_tag_set *set);
  628. void blk_mq_free_request(struct request *rq);
  629. bool blk_mq_queue_inflight(struct request_queue *q);
  630. enum {
  631. /* return when out of requests */
  632. BLK_MQ_REQ_NOWAIT = (__force blk_mq_req_flags_t)(1 << 0),
  633. /* allocate from reserved pool */
  634. BLK_MQ_REQ_RESERVED = (__force blk_mq_req_flags_t)(1 << 1),
  635. /* set RQF_PM */
  636. BLK_MQ_REQ_PM = (__force blk_mq_req_flags_t)(1 << 2),
  637. };
  638. struct request *blk_mq_alloc_request(struct request_queue *q, blk_opf_t opf,
  639. blk_mq_req_flags_t flags);
  640. struct request *blk_mq_alloc_request_hctx(struct request_queue *q,
  641. blk_opf_t opf, blk_mq_req_flags_t flags,
  642. unsigned int hctx_idx);
  643. /*
  644. * Tag address space map.
  645. */
  646. struct blk_mq_tags {
  647. unsigned int nr_tags;
  648. unsigned int nr_reserved_tags;
  649. atomic_t active_queues;
  650. struct sbitmap_queue bitmap_tags;
  651. struct sbitmap_queue breserved_tags;
  652. struct request **rqs;
  653. struct request **static_rqs;
  654. struct list_head page_list;
  655. /*
  656. * used to clear request reference in rqs[] before freeing one
  657. * request pool
  658. */
  659. spinlock_t lock;
  660. };
  661. static inline struct request *blk_mq_tag_to_rq(struct blk_mq_tags *tags,
  662. unsigned int tag)
  663. {
  664. if (tag < tags->nr_tags) {
  665. prefetch(tags->rqs[tag]);
  666. return tags->rqs[tag];
  667. }
  668. return NULL;
  669. }
  670. enum {
  671. BLK_MQ_UNIQUE_TAG_BITS = 16,
  672. BLK_MQ_UNIQUE_TAG_MASK = (1 << BLK_MQ_UNIQUE_TAG_BITS) - 1,
  673. };
  674. u32 blk_mq_unique_tag(struct request *rq);
  675. static inline u16 blk_mq_unique_tag_to_hwq(u32 unique_tag)
  676. {
  677. return unique_tag >> BLK_MQ_UNIQUE_TAG_BITS;
  678. }
  679. static inline u16 blk_mq_unique_tag_to_tag(u32 unique_tag)
  680. {
  681. return unique_tag & BLK_MQ_UNIQUE_TAG_MASK;
  682. }
  683. /**
  684. * blk_mq_rq_state() - read the current MQ_RQ_* state of a request
  685. * @rq: target request.
  686. */
  687. static inline enum mq_rq_state blk_mq_rq_state(struct request *rq)
  688. {
  689. return READ_ONCE(rq->state);
  690. }
  691. static inline int blk_mq_request_started(struct request *rq)
  692. {
  693. return blk_mq_rq_state(rq) != MQ_RQ_IDLE;
  694. }
  695. static inline int blk_mq_request_completed(struct request *rq)
  696. {
  697. return blk_mq_rq_state(rq) == MQ_RQ_COMPLETE;
  698. }
  699. /*
  700. *
  701. * Set the state to complete when completing a request from inside ->queue_rq.
  702. * This is used by drivers that want to ensure special complete actions that
  703. * need access to the request are called on failure, e.g. by nvme for
  704. * multipathing.
  705. */
  706. static inline void blk_mq_set_request_complete(struct request *rq)
  707. {
  708. WRITE_ONCE(rq->state, MQ_RQ_COMPLETE);
  709. }
  710. /*
  711. * Complete the request directly instead of deferring it to softirq or
  712. * completing it another CPU. Useful in preemptible instead of an interrupt.
  713. */
  714. static inline void blk_mq_complete_request_direct(struct request *rq,
  715. void (*complete)(struct request *rq))
  716. {
  717. WRITE_ONCE(rq->state, MQ_RQ_COMPLETE);
  718. complete(rq);
  719. }
  720. void blk_mq_start_request(struct request *rq);
  721. void blk_mq_end_request(struct request *rq, blk_status_t error);
  722. void __blk_mq_end_request(struct request *rq, blk_status_t error);
  723. void blk_mq_end_request_batch(struct io_comp_batch *ib);
  724. /*
  725. * Only need start/end time stamping if we have iostat or
  726. * blk stats enabled, or using an IO scheduler.
  727. */
  728. static inline bool blk_mq_need_time_stamp(struct request *rq)
  729. {
  730. return (rq->rq_flags & (RQF_IO_STAT | RQF_STATS | RQF_ELV));
  731. }
  732. static inline bool blk_mq_is_reserved_rq(struct request *rq)
  733. {
  734. return rq->rq_flags & RQF_RESV;
  735. }
  736. /*
  737. * Batched completions only work when there is no I/O error and no special
  738. * ->end_io handler.
  739. */
  740. static inline bool blk_mq_add_to_batch(struct request *req,
  741. struct io_comp_batch *iob, int ioerror,
  742. void (*complete)(struct io_comp_batch *))
  743. {
  744. if (!iob || (req->rq_flags & RQF_ELV) || ioerror ||
  745. (req->end_io && !blk_rq_is_passthrough(req)))
  746. return false;
  747. if (!iob->complete)
  748. iob->complete = complete;
  749. else if (iob->complete != complete)
  750. return false;
  751. iob->need_ts |= blk_mq_need_time_stamp(req);
  752. rq_list_add(&iob->req_list, req);
  753. return true;
  754. }
  755. void blk_mq_requeue_request(struct request *rq, bool kick_requeue_list);
  756. void blk_mq_kick_requeue_list(struct request_queue *q);
  757. void blk_mq_delay_kick_requeue_list(struct request_queue *q, unsigned long msecs);
  758. void blk_mq_complete_request(struct request *rq);
  759. bool blk_mq_complete_request_remote(struct request *rq);
  760. void blk_mq_stop_hw_queue(struct blk_mq_hw_ctx *hctx);
  761. void blk_mq_start_hw_queue(struct blk_mq_hw_ctx *hctx);
  762. void blk_mq_stop_hw_queues(struct request_queue *q);
  763. void blk_mq_start_hw_queues(struct request_queue *q);
  764. void blk_mq_start_stopped_hw_queue(struct blk_mq_hw_ctx *hctx, bool async);
  765. void blk_mq_start_stopped_hw_queues(struct request_queue *q, bool async);
  766. void blk_mq_quiesce_queue(struct request_queue *q);
  767. void blk_mq_wait_quiesce_done(struct request_queue *q);
  768. void blk_mq_unquiesce_queue(struct request_queue *q);
  769. void blk_mq_delay_run_hw_queue(struct blk_mq_hw_ctx *hctx, unsigned long msecs);
  770. void blk_mq_run_hw_queue(struct blk_mq_hw_ctx *hctx, bool async);
  771. void blk_mq_run_hw_queues(struct request_queue *q, bool async);
  772. void blk_mq_delay_run_hw_queues(struct request_queue *q, unsigned long msecs);
  773. void blk_mq_tagset_busy_iter(struct blk_mq_tag_set *tagset,
  774. busy_tag_iter_fn *fn, void *priv);
  775. void blk_mq_tagset_wait_completed_request(struct blk_mq_tag_set *tagset);
  776. void blk_mq_freeze_queue(struct request_queue *q);
  777. void blk_mq_unfreeze_queue(struct request_queue *q);
  778. void blk_freeze_queue_start(struct request_queue *q);
  779. void blk_mq_freeze_queue_wait(struct request_queue *q);
  780. int blk_mq_freeze_queue_wait_timeout(struct request_queue *q,
  781. unsigned long timeout);
  782. void blk_mq_map_queues(struct blk_mq_queue_map *qmap);
  783. void blk_mq_update_nr_hw_queues(struct blk_mq_tag_set *set, int nr_hw_queues);
  784. void blk_mq_quiesce_queue_nowait(struct request_queue *q);
  785. unsigned int blk_mq_rq_cpu(struct request *rq);
  786. bool __blk_should_fake_timeout(struct request_queue *q);
  787. static inline bool blk_should_fake_timeout(struct request_queue *q)
  788. {
  789. if (IS_ENABLED(CONFIG_FAIL_IO_TIMEOUT) &&
  790. test_bit(QUEUE_FLAG_FAIL_IO, &q->queue_flags))
  791. return __blk_should_fake_timeout(q);
  792. return false;
  793. }
  794. /**
  795. * blk_mq_rq_from_pdu - cast a PDU to a request
  796. * @pdu: the PDU (Protocol Data Unit) to be casted
  797. *
  798. * Return: request
  799. *
  800. * Driver command data is immediately after the request. So subtract request
  801. * size to get back to the original request.
  802. */
  803. static inline struct request *blk_mq_rq_from_pdu(void *pdu)
  804. {
  805. return pdu - sizeof(struct request);
  806. }
  807. /**
  808. * blk_mq_rq_to_pdu - cast a request to a PDU
  809. * @rq: the request to be casted
  810. *
  811. * Return: pointer to the PDU
  812. *
  813. * Driver command data is immediately after the request. So add request to get
  814. * the PDU.
  815. */
  816. static inline void *blk_mq_rq_to_pdu(struct request *rq)
  817. {
  818. return rq + 1;
  819. }
  820. #define queue_for_each_hw_ctx(q, hctx, i) \
  821. xa_for_each(&(q)->hctx_table, (i), (hctx))
  822. #define hctx_for_each_ctx(hctx, ctx, i) \
  823. for ((i) = 0; (i) < (hctx)->nr_ctx && \
  824. ({ ctx = (hctx)->ctxs[(i)]; 1; }); (i)++)
  825. static inline void blk_mq_cleanup_rq(struct request *rq)
  826. {
  827. if (rq->q->mq_ops->cleanup_rq)
  828. rq->q->mq_ops->cleanup_rq(rq);
  829. }
  830. static inline void blk_rq_bio_prep(struct request *rq, struct bio *bio,
  831. unsigned int nr_segs)
  832. {
  833. rq->nr_phys_segments = nr_segs;
  834. rq->__data_len = bio->bi_iter.bi_size;
  835. rq->bio = rq->biotail = bio;
  836. rq->ioprio = bio_prio(bio);
  837. }
  838. void blk_mq_hctx_set_fq_lock_class(struct blk_mq_hw_ctx *hctx,
  839. struct lock_class_key *key);
  840. static inline bool rq_is_sync(struct request *rq)
  841. {
  842. return op_is_sync(rq->cmd_flags);
  843. }
  844. void blk_rq_init(struct request_queue *q, struct request *rq);
  845. int blk_rq_prep_clone(struct request *rq, struct request *rq_src,
  846. struct bio_set *bs, gfp_t gfp_mask,
  847. int (*bio_ctr)(struct bio *, struct bio *, void *), void *data);
  848. void blk_rq_unprep_clone(struct request *rq);
  849. blk_status_t blk_insert_cloned_request(struct request *rq);
  850. struct rq_map_data {
  851. struct page **pages;
  852. unsigned long offset;
  853. unsigned short page_order;
  854. unsigned short nr_entries;
  855. bool null_mapped;
  856. bool from_user;
  857. };
  858. int blk_rq_map_user(struct request_queue *, struct request *,
  859. struct rq_map_data *, void __user *, unsigned long, gfp_t);
  860. int blk_rq_map_user_io(struct request *, struct rq_map_data *,
  861. void __user *, unsigned long, gfp_t, bool, int, bool, int);
  862. int blk_rq_map_user_iov(struct request_queue *, struct request *,
  863. struct rq_map_data *, const struct iov_iter *, gfp_t);
  864. int blk_rq_unmap_user(struct bio *);
  865. int blk_rq_map_kern(struct request_queue *, struct request *, void *,
  866. unsigned int, gfp_t);
  867. int blk_rq_append_bio(struct request *rq, struct bio *bio);
  868. void blk_execute_rq_nowait(struct request *rq, bool at_head);
  869. blk_status_t blk_execute_rq(struct request *rq, bool at_head);
  870. bool blk_rq_is_poll(struct request *rq);
  871. struct req_iterator {
  872. struct bvec_iter iter;
  873. struct bio *bio;
  874. };
  875. #define __rq_for_each_bio(_bio, rq) \
  876. if ((rq->bio)) \
  877. for (_bio = (rq)->bio; _bio; _bio = _bio->bi_next)
  878. #define rq_for_each_segment(bvl, _rq, _iter) \
  879. __rq_for_each_bio(_iter.bio, _rq) \
  880. bio_for_each_segment(bvl, _iter.bio, _iter.iter)
  881. #define rq_for_each_bvec(bvl, _rq, _iter) \
  882. __rq_for_each_bio(_iter.bio, _rq) \
  883. bio_for_each_bvec(bvl, _iter.bio, _iter.iter)
  884. #define rq_iter_last(bvec, _iter) \
  885. (_iter.bio->bi_next == NULL && \
  886. bio_iter_last(bvec, _iter.iter))
  887. /*
  888. * blk_rq_pos() : the current sector
  889. * blk_rq_bytes() : bytes left in the entire request
  890. * blk_rq_cur_bytes() : bytes left in the current segment
  891. * blk_rq_sectors() : sectors left in the entire request
  892. * blk_rq_cur_sectors() : sectors left in the current segment
  893. * blk_rq_stats_sectors() : sectors of the entire request used for stats
  894. */
  895. static inline sector_t blk_rq_pos(const struct request *rq)
  896. {
  897. return rq->__sector;
  898. }
  899. static inline unsigned int blk_rq_bytes(const struct request *rq)
  900. {
  901. return rq->__data_len;
  902. }
  903. static inline int blk_rq_cur_bytes(const struct request *rq)
  904. {
  905. if (!rq->bio)
  906. return 0;
  907. if (!bio_has_data(rq->bio)) /* dataless requests such as discard */
  908. return rq->bio->bi_iter.bi_size;
  909. return bio_iovec(rq->bio).bv_len;
  910. }
  911. static inline unsigned int blk_rq_sectors(const struct request *rq)
  912. {
  913. return blk_rq_bytes(rq) >> SECTOR_SHIFT;
  914. }
  915. static inline unsigned int blk_rq_cur_sectors(const struct request *rq)
  916. {
  917. return blk_rq_cur_bytes(rq) >> SECTOR_SHIFT;
  918. }
  919. static inline unsigned int blk_rq_stats_sectors(const struct request *rq)
  920. {
  921. return rq->stats_sectors;
  922. }
  923. /*
  924. * Some commands like WRITE SAME have a payload or data transfer size which
  925. * is different from the size of the request. Any driver that supports such
  926. * commands using the RQF_SPECIAL_PAYLOAD flag needs to use this helper to
  927. * calculate the data transfer size.
  928. */
  929. static inline unsigned int blk_rq_payload_bytes(struct request *rq)
  930. {
  931. if (rq->rq_flags & RQF_SPECIAL_PAYLOAD)
  932. return rq->special_vec.bv_len;
  933. return blk_rq_bytes(rq);
  934. }
  935. /*
  936. * Return the first full biovec in the request. The caller needs to check that
  937. * there are any bvecs before calling this helper.
  938. */
  939. static inline struct bio_vec req_bvec(struct request *rq)
  940. {
  941. if (rq->rq_flags & RQF_SPECIAL_PAYLOAD)
  942. return rq->special_vec;
  943. return mp_bvec_iter_bvec(rq->bio->bi_io_vec, rq->bio->bi_iter);
  944. }
  945. static inline unsigned int blk_rq_count_bios(struct request *rq)
  946. {
  947. unsigned int nr_bios = 0;
  948. struct bio *bio;
  949. __rq_for_each_bio(bio, rq)
  950. nr_bios++;
  951. return nr_bios;
  952. }
  953. void blk_steal_bios(struct bio_list *list, struct request *rq);
  954. /*
  955. * Request completion related functions.
  956. *
  957. * blk_update_request() completes given number of bytes and updates
  958. * the request without completing it.
  959. */
  960. bool blk_update_request(struct request *rq, blk_status_t error,
  961. unsigned int nr_bytes);
  962. void blk_abort_request(struct request *);
  963. /*
  964. * Number of physical segments as sent to the device.
  965. *
  966. * Normally this is the number of discontiguous data segments sent by the
  967. * submitter. But for data-less command like discard we might have no
  968. * actual data segments submitted, but the driver might have to add it's
  969. * own special payload. In that case we still return 1 here so that this
  970. * special payload will be mapped.
  971. */
  972. static inline unsigned short blk_rq_nr_phys_segments(struct request *rq)
  973. {
  974. if (rq->rq_flags & RQF_SPECIAL_PAYLOAD)
  975. return 1;
  976. return rq->nr_phys_segments;
  977. }
  978. /*
  979. * Number of discard segments (or ranges) the driver needs to fill in.
  980. * Each discard bio merged into a request is counted as one segment.
  981. */
  982. static inline unsigned short blk_rq_nr_discard_segments(struct request *rq)
  983. {
  984. return max_t(unsigned short, rq->nr_phys_segments, 1);
  985. }
  986. int __blk_rq_map_sg(struct request_queue *q, struct request *rq,
  987. struct scatterlist *sglist, struct scatterlist **last_sg);
  988. static inline int blk_rq_map_sg(struct request_queue *q, struct request *rq,
  989. struct scatterlist *sglist)
  990. {
  991. struct scatterlist *last_sg = NULL;
  992. return __blk_rq_map_sg(q, rq, sglist, &last_sg);
  993. }
  994. void blk_dump_rq_flags(struct request *, char *);
  995. #ifdef CONFIG_BLK_DEV_ZONED
  996. static inline unsigned int blk_rq_zone_no(struct request *rq)
  997. {
  998. return disk_zone_no(rq->q->disk, blk_rq_pos(rq));
  999. }
  1000. static inline unsigned int blk_rq_zone_is_seq(struct request *rq)
  1001. {
  1002. return disk_zone_is_seq(rq->q->disk, blk_rq_pos(rq));
  1003. }
  1004. bool blk_req_needs_zone_write_lock(struct request *rq);
  1005. bool blk_req_zone_write_trylock(struct request *rq);
  1006. void __blk_req_zone_write_lock(struct request *rq);
  1007. void __blk_req_zone_write_unlock(struct request *rq);
  1008. static inline void blk_req_zone_write_lock(struct request *rq)
  1009. {
  1010. if (blk_req_needs_zone_write_lock(rq))
  1011. __blk_req_zone_write_lock(rq);
  1012. }
  1013. static inline void blk_req_zone_write_unlock(struct request *rq)
  1014. {
  1015. if (rq->rq_flags & RQF_ZONE_WRITE_LOCKED)
  1016. __blk_req_zone_write_unlock(rq);
  1017. }
  1018. static inline bool blk_req_zone_is_write_locked(struct request *rq)
  1019. {
  1020. return rq->q->disk->seq_zones_wlock &&
  1021. test_bit(blk_rq_zone_no(rq), rq->q->disk->seq_zones_wlock);
  1022. }
  1023. static inline bool blk_req_can_dispatch_to_zone(struct request *rq)
  1024. {
  1025. if (!blk_req_needs_zone_write_lock(rq))
  1026. return true;
  1027. return !blk_req_zone_is_write_locked(rq);
  1028. }
  1029. #else /* CONFIG_BLK_DEV_ZONED */
  1030. static inline bool blk_req_needs_zone_write_lock(struct request *rq)
  1031. {
  1032. return false;
  1033. }
  1034. static inline void blk_req_zone_write_lock(struct request *rq)
  1035. {
  1036. }
  1037. static inline void blk_req_zone_write_unlock(struct request *rq)
  1038. {
  1039. }
  1040. static inline bool blk_req_zone_is_write_locked(struct request *rq)
  1041. {
  1042. return false;
  1043. }
  1044. static inline bool blk_req_can_dispatch_to_zone(struct request *rq)
  1045. {
  1046. return true;
  1047. }
  1048. #endif /* CONFIG_BLK_DEV_ZONED */
  1049. #endif /* BLK_MQ_H */