Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | #ifndef _LINUX_BLKDEV_H |
| 3 | #define _LINUX_BLKDEV_H |
| 4 | |
| 5 | #include <linux/sched.h> |
| 6 | #include <linux/sched/clock.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 7 | #include <linux/major.h> |
| 8 | #include <linux/genhd.h> |
| 9 | #include <linux/list.h> |
| 10 | #include <linux/llist.h> |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 11 | #include <linux/minmax.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 12 | #include <linux/timer.h> |
| 13 | #include <linux/workqueue.h> |
| 14 | #include <linux/pagemap.h> |
| 15 | #include <linux/backing-dev-defs.h> |
| 16 | #include <linux/wait.h> |
| 17 | #include <linux/mempool.h> |
| 18 | #include <linux/pfn.h> |
| 19 | #include <linux/bio.h> |
| 20 | #include <linux/stringify.h> |
| 21 | #include <linux/gfp.h> |
| 22 | #include <linux/bsg.h> |
| 23 | #include <linux/smp.h> |
| 24 | #include <linux/rcupdate.h> |
| 25 | #include <linux/percpu-refcount.h> |
| 26 | #include <linux/scatterlist.h> |
| 27 | #include <linux/blkzoned.h> |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 28 | #include <linux/pm.h> |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 29 | |
| 30 | struct module; |
| 31 | struct scsi_ioctl_command; |
| 32 | |
| 33 | struct request_queue; |
| 34 | struct elevator_queue; |
| 35 | struct blk_trace; |
| 36 | struct request; |
| 37 | struct sg_io_hdr; |
| 38 | struct bsg_job; |
| 39 | struct blkcg_gq; |
| 40 | struct blk_flush_queue; |
| 41 | struct pr_ops; |
| 42 | struct rq_qos; |
| 43 | struct blk_queue_stats; |
| 44 | struct blk_stat_callback; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 45 | struct blk_keyslot_manager; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 46 | |
| 47 | #define BLKDEV_MIN_RQ 4 |
| 48 | #define BLKDEV_MAX_RQ 128 /* Default maximum */ |
| 49 | |
| 50 | /* Must be consistent with blk_mq_poll_stats_bkt() */ |
| 51 | #define BLK_MQ_POLL_STATS_BKTS 16 |
| 52 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 53 | /* Doing classic polling */ |
| 54 | #define BLK_MQ_POLL_CLASSIC -1 |
| 55 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 56 | /* |
| 57 | * Maximum number of blkcg policies allowed to be registered concurrently. |
| 58 | * Defined here to simplify include dependency. |
| 59 | */ |
| 60 | #define BLKCG_MAX_POLS 5 |
| 61 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 62 | static inline int blk_validate_block_size(unsigned int bsize) |
| 63 | { |
| 64 | if (bsize < 512 || bsize > PAGE_SIZE || !is_power_of_2(bsize)) |
| 65 | return -EINVAL; |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 70 | typedef void (rq_end_io_fn)(struct request *, blk_status_t); |
| 71 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 72 | /* |
| 73 | * request flags */ |
| 74 | typedef __u32 __bitwise req_flags_t; |
| 75 | |
| 76 | /* elevator knows about this request */ |
| 77 | #define RQF_SORTED ((__force req_flags_t)(1 << 0)) |
| 78 | /* drive already may have started this one */ |
| 79 | #define RQF_STARTED ((__force req_flags_t)(1 << 1)) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 80 | /* may not be passed by ioscheduler */ |
| 81 | #define RQF_SOFTBARRIER ((__force req_flags_t)(1 << 3)) |
| 82 | /* request for flush sequence */ |
| 83 | #define RQF_FLUSH_SEQ ((__force req_flags_t)(1 << 4)) |
| 84 | /* merge of different types, fail separately */ |
| 85 | #define RQF_MIXED_MERGE ((__force req_flags_t)(1 << 5)) |
| 86 | /* track inflight for MQ */ |
| 87 | #define RQF_MQ_INFLIGHT ((__force req_flags_t)(1 << 6)) |
| 88 | /* don't call prep for this one */ |
| 89 | #define RQF_DONTPREP ((__force req_flags_t)(1 << 7)) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 90 | /* vaguely specified driver internal error. Ignored by the block layer */ |
| 91 | #define RQF_FAILED ((__force req_flags_t)(1 << 10)) |
| 92 | /* don't warn about errors */ |
| 93 | #define RQF_QUIET ((__force req_flags_t)(1 << 11)) |
| 94 | /* elevator private data attached */ |
| 95 | #define RQF_ELVPRIV ((__force req_flags_t)(1 << 12)) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 96 | /* account into disk and partition IO statistics */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 97 | #define RQF_IO_STAT ((__force req_flags_t)(1 << 13)) |
| 98 | /* request came from our alloc pool */ |
| 99 | #define RQF_ALLOCED ((__force req_flags_t)(1 << 14)) |
| 100 | /* runtime pm request */ |
| 101 | #define RQF_PM ((__force req_flags_t)(1 << 15)) |
| 102 | /* on IO scheduler merge hash */ |
| 103 | #define RQF_HASHED ((__force req_flags_t)(1 << 16)) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 104 | /* track IO completion time */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 105 | #define RQF_STATS ((__force req_flags_t)(1 << 17)) |
| 106 | /* Look at ->special_vec for the actual data payload instead of the |
| 107 | bio chain. */ |
| 108 | #define RQF_SPECIAL_PAYLOAD ((__force req_flags_t)(1 << 18)) |
| 109 | /* The per-zone write lock is held for this request */ |
| 110 | #define RQF_ZONE_WRITE_LOCKED ((__force req_flags_t)(1 << 19)) |
| 111 | /* already slept for hybrid poll */ |
| 112 | #define RQF_MQ_POLL_SLEPT ((__force req_flags_t)(1 << 20)) |
| 113 | /* ->timeout has been called, don't expire again */ |
| 114 | #define RQF_TIMED_OUT ((__force req_flags_t)(1 << 21)) |
| 115 | |
| 116 | /* flags that prevent us from merging requests: */ |
| 117 | #define RQF_NOMERGE_FLAGS \ |
| 118 | (RQF_STARTED | RQF_SOFTBARRIER | RQF_FLUSH_SEQ | RQF_SPECIAL_PAYLOAD) |
| 119 | |
| 120 | /* |
| 121 | * Request state for blk-mq. |
| 122 | */ |
| 123 | enum mq_rq_state { |
| 124 | MQ_RQ_IDLE = 0, |
| 125 | MQ_RQ_IN_FLIGHT = 1, |
| 126 | MQ_RQ_COMPLETE = 2, |
| 127 | }; |
| 128 | |
| 129 | /* |
| 130 | * Try to put the fields that are referenced together in the same cacheline. |
| 131 | * |
| 132 | * If you modify this structure, make sure to update blk_rq_init() and |
| 133 | * especially blk_mq_rq_ctx_init() to take care of the added fields. |
| 134 | */ |
| 135 | struct request { |
| 136 | struct request_queue *q; |
| 137 | struct blk_mq_ctx *mq_ctx; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 138 | struct blk_mq_hw_ctx *mq_hctx; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 139 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 140 | unsigned int cmd_flags; /* op and common flags */ |
| 141 | req_flags_t rq_flags; |
| 142 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 143 | int tag; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 144 | int internal_tag; |
| 145 | |
| 146 | /* the following two fields are internal, NEVER access directly */ |
| 147 | unsigned int __data_len; /* total data len */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 148 | sector_t __sector; /* sector cursor */ |
| 149 | |
| 150 | struct bio *bio; |
| 151 | struct bio *biotail; |
| 152 | |
| 153 | struct list_head queuelist; |
| 154 | |
| 155 | /* |
| 156 | * The hash is used inside the scheduler, and killed once the |
| 157 | * request reaches the dispatch list. The ipi_list is only used |
| 158 | * to queue the request for softirq completion, which is long |
| 159 | * after the request has been unhashed (and even removed from |
| 160 | * the dispatch list). |
| 161 | */ |
| 162 | union { |
| 163 | struct hlist_node hash; /* merge hash */ |
| 164 | struct list_head ipi_list; |
| 165 | }; |
| 166 | |
| 167 | /* |
| 168 | * The rb_node is only used inside the io scheduler, requests |
| 169 | * are pruned when moved to the dispatch queue. So let the |
| 170 | * completion_data share space with the rb_node. |
| 171 | */ |
| 172 | union { |
| 173 | struct rb_node rb_node; /* sort/lookup */ |
| 174 | struct bio_vec special_vec; |
| 175 | void *completion_data; |
| 176 | int error_count; /* for legacy drivers, don't use */ |
| 177 | }; |
| 178 | |
| 179 | /* |
| 180 | * Three pointers are available for the IO schedulers, if they need |
| 181 | * more they have to dynamically allocate it. Flush requests are |
| 182 | * never put on the IO scheduler. So let the flush fields share |
| 183 | * space with the elevator data. |
| 184 | */ |
| 185 | union { |
| 186 | struct { |
| 187 | struct io_cq *icq; |
| 188 | void *priv[2]; |
| 189 | } elv; |
| 190 | |
| 191 | struct { |
| 192 | unsigned int seq; |
| 193 | struct list_head list; |
| 194 | rq_end_io_fn *saved_end_io; |
| 195 | } flush; |
| 196 | }; |
| 197 | |
| 198 | struct gendisk *rq_disk; |
| 199 | struct hd_struct *part; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 200 | #ifdef CONFIG_BLK_RQ_ALLOC_TIME |
| 201 | /* Time that the first bio started allocating this request. */ |
| 202 | u64 alloc_time_ns; |
| 203 | #endif |
| 204 | /* Time that this request was allocated for this IO. */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 205 | u64 start_time_ns; |
| 206 | /* Time that I/O was submitted to the device. */ |
| 207 | u64 io_start_time_ns; |
| 208 | |
| 209 | #ifdef CONFIG_BLK_WBT |
| 210 | unsigned short wbt_flags; |
| 211 | #endif |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 212 | /* |
| 213 | * rq sectors used for blk stats. It has the same value |
| 214 | * with blk_rq_sectors(rq), except that it never be zeroed |
| 215 | * by completion. |
| 216 | */ |
| 217 | unsigned short stats_sectors; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 218 | |
| 219 | /* |
| 220 | * Number of scatter-gather DMA addr+len pairs after |
| 221 | * physical address coalescing is performed. |
| 222 | */ |
| 223 | unsigned short nr_phys_segments; |
| 224 | |
| 225 | #if defined(CONFIG_BLK_DEV_INTEGRITY) |
| 226 | unsigned short nr_integrity_segments; |
| 227 | #endif |
| 228 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 229 | #ifdef CONFIG_BLK_INLINE_ENCRYPTION |
| 230 | struct bio_crypt_ctx *crypt_ctx; |
| 231 | struct blk_ksm_keyslot *crypt_keyslot; |
| 232 | #endif |
| 233 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 234 | unsigned short write_hint; |
| 235 | unsigned short ioprio; |
| 236 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 237 | enum mq_rq_state state; |
| 238 | refcount_t ref; |
| 239 | |
| 240 | unsigned int timeout; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 241 | unsigned long deadline; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 242 | |
| 243 | union { |
| 244 | struct __call_single_data csd; |
| 245 | u64 fifo_time; |
| 246 | }; |
| 247 | |
| 248 | /* |
| 249 | * completion callback. |
| 250 | */ |
| 251 | rq_end_io_fn *end_io; |
| 252 | void *end_io_data; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 253 | }; |
| 254 | |
| 255 | static inline bool blk_op_is_scsi(unsigned int op) |
| 256 | { |
| 257 | return op == REQ_OP_SCSI_IN || op == REQ_OP_SCSI_OUT; |
| 258 | } |
| 259 | |
| 260 | static inline bool blk_op_is_private(unsigned int op) |
| 261 | { |
| 262 | return op == REQ_OP_DRV_IN || op == REQ_OP_DRV_OUT; |
| 263 | } |
| 264 | |
| 265 | static inline bool blk_rq_is_scsi(struct request *rq) |
| 266 | { |
| 267 | return blk_op_is_scsi(req_op(rq)); |
| 268 | } |
| 269 | |
| 270 | static inline bool blk_rq_is_private(struct request *rq) |
| 271 | { |
| 272 | return blk_op_is_private(req_op(rq)); |
| 273 | } |
| 274 | |
| 275 | static inline bool blk_rq_is_passthrough(struct request *rq) |
| 276 | { |
| 277 | return blk_rq_is_scsi(rq) || blk_rq_is_private(rq); |
| 278 | } |
| 279 | |
| 280 | static inline bool bio_is_passthrough(struct bio *bio) |
| 281 | { |
| 282 | unsigned op = bio_op(bio); |
| 283 | |
| 284 | return blk_op_is_scsi(op) || blk_op_is_private(op); |
| 285 | } |
| 286 | |
| 287 | static inline unsigned short req_get_ioprio(struct request *req) |
| 288 | { |
| 289 | return req->ioprio; |
| 290 | } |
| 291 | |
| 292 | #include <linux/elevator.h> |
| 293 | |
| 294 | struct blk_queue_ctx; |
| 295 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 296 | struct bio_vec; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 297 | |
| 298 | enum blk_eh_timer_return { |
| 299 | BLK_EH_DONE, /* drivers has completed the command */ |
| 300 | BLK_EH_RESET_TIMER, /* reset timer and try again */ |
| 301 | }; |
| 302 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 303 | enum blk_queue_state { |
| 304 | Queue_down, |
| 305 | Queue_up, |
| 306 | }; |
| 307 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 308 | #define BLK_TAG_ALLOC_FIFO 0 /* allocate starting from 0 */ |
| 309 | #define BLK_TAG_ALLOC_RR 1 /* allocate starting from last allocated tag */ |
| 310 | |
| 311 | #define BLK_SCSI_MAX_CMDS (256) |
| 312 | #define BLK_SCSI_CMD_PER_LONG (BLK_SCSI_MAX_CMDS / (sizeof(long) * 8)) |
| 313 | |
| 314 | /* |
| 315 | * Zoned block device models (zoned limit). |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 316 | * |
| 317 | * Note: This needs to be ordered from the least to the most severe |
| 318 | * restrictions for the inheritance in blk_stack_limits() to work. |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 319 | */ |
| 320 | enum blk_zoned_model { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 321 | BLK_ZONED_NONE = 0, /* Regular block device */ |
| 322 | BLK_ZONED_HA, /* Host-aware zoned block device */ |
| 323 | BLK_ZONED_HM, /* Host-managed zoned block device */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 324 | }; |
| 325 | |
| 326 | struct queue_limits { |
| 327 | unsigned long bounce_pfn; |
| 328 | unsigned long seg_boundary_mask; |
| 329 | unsigned long virt_boundary_mask; |
| 330 | |
| 331 | unsigned int max_hw_sectors; |
| 332 | unsigned int max_dev_sectors; |
| 333 | unsigned int chunk_sectors; |
| 334 | unsigned int max_sectors; |
| 335 | unsigned int max_segment_size; |
| 336 | unsigned int physical_block_size; |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 337 | unsigned int logical_block_size; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 338 | unsigned int alignment_offset; |
| 339 | unsigned int io_min; |
| 340 | unsigned int io_opt; |
| 341 | unsigned int max_discard_sectors; |
| 342 | unsigned int max_hw_discard_sectors; |
| 343 | unsigned int max_write_same_sectors; |
| 344 | unsigned int max_write_zeroes_sectors; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 345 | unsigned int max_zone_append_sectors; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 346 | unsigned int discard_granularity; |
| 347 | unsigned int discard_alignment; |
| 348 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 349 | unsigned short max_segments; |
| 350 | unsigned short max_integrity_segments; |
| 351 | unsigned short max_discard_segments; |
| 352 | |
| 353 | unsigned char misaligned; |
| 354 | unsigned char discard_misaligned; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 355 | unsigned char raid_partial_stripes_expensive; |
| 356 | enum blk_zoned_model zoned; |
| 357 | }; |
| 358 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 359 | typedef int (*report_zones_cb)(struct blk_zone *zone, unsigned int idx, |
| 360 | void *data); |
| 361 | |
| 362 | void blk_queue_set_zoned(struct gendisk *disk, enum blk_zoned_model model); |
| 363 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 364 | #ifdef CONFIG_BLK_DEV_ZONED |
| 365 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 366 | #define BLK_ALL_ZONES ((unsigned int)-1) |
| 367 | int blkdev_report_zones(struct block_device *bdev, sector_t sector, |
| 368 | unsigned int nr_zones, report_zones_cb cb, void *data); |
| 369 | unsigned int blkdev_nr_zones(struct gendisk *disk); |
| 370 | extern int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op, |
| 371 | sector_t sectors, sector_t nr_sectors, |
| 372 | gfp_t gfp_mask); |
| 373 | int blk_revalidate_disk_zones(struct gendisk *disk, |
| 374 | void (*update_driver_data)(struct gendisk *disk)); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 375 | |
| 376 | extern int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode, |
| 377 | unsigned int cmd, unsigned long arg); |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 378 | extern int blkdev_zone_mgmt_ioctl(struct block_device *bdev, fmode_t mode, |
| 379 | unsigned int cmd, unsigned long arg); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 380 | |
| 381 | #else /* CONFIG_BLK_DEV_ZONED */ |
| 382 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 383 | static inline unsigned int blkdev_nr_zones(struct gendisk *disk) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 384 | { |
| 385 | return 0; |
| 386 | } |
| 387 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 388 | static inline int blkdev_report_zones_ioctl(struct block_device *bdev, |
| 389 | fmode_t mode, unsigned int cmd, |
| 390 | unsigned long arg) |
| 391 | { |
| 392 | return -ENOTTY; |
| 393 | } |
| 394 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 395 | static inline int blkdev_zone_mgmt_ioctl(struct block_device *bdev, |
| 396 | fmode_t mode, unsigned int cmd, |
| 397 | unsigned long arg) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 398 | { |
| 399 | return -ENOTTY; |
| 400 | } |
| 401 | |
| 402 | #endif /* CONFIG_BLK_DEV_ZONED */ |
| 403 | |
| 404 | struct request_queue { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 405 | struct request *last_merge; |
| 406 | struct elevator_queue *elevator; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 407 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 408 | struct percpu_ref q_usage_counter; |
| 409 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 410 | struct blk_queue_stats *stats; |
| 411 | struct rq_qos *rq_qos; |
| 412 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 413 | const struct blk_mq_ops *mq_ops; |
| 414 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 415 | /* sw queues */ |
| 416 | struct blk_mq_ctx __percpu *queue_ctx; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 417 | |
| 418 | unsigned int queue_depth; |
| 419 | |
| 420 | /* hw dispatch queues */ |
| 421 | struct blk_mq_hw_ctx **queue_hw_ctx; |
| 422 | unsigned int nr_hw_queues; |
| 423 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 424 | struct backing_dev_info *backing_dev_info; |
| 425 | |
| 426 | /* |
| 427 | * The queue owner gets to use this for whatever they like. |
| 428 | * ll_rw_blk doesn't touch it. |
| 429 | */ |
| 430 | void *queuedata; |
| 431 | |
| 432 | /* |
| 433 | * various queue flags, see QUEUE_* below |
| 434 | */ |
| 435 | unsigned long queue_flags; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 436 | /* |
| 437 | * Number of contexts that have called blk_set_pm_only(). If this |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 438 | * counter is above zero then only RQF_PM requests are processed. |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 439 | */ |
| 440 | atomic_t pm_only; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 441 | |
| 442 | /* |
| 443 | * ida allocated id for this queue. Used to index queues from |
| 444 | * ioctx. |
| 445 | */ |
| 446 | int id; |
| 447 | |
| 448 | /* |
| 449 | * queue needs bounce pages for pages above this limit |
| 450 | */ |
| 451 | gfp_t bounce_gfp; |
| 452 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 453 | spinlock_t queue_lock; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 454 | |
| 455 | /* |
| 456 | * queue kobject |
| 457 | */ |
| 458 | struct kobject kobj; |
| 459 | |
| 460 | /* |
| 461 | * mq queue kobject |
| 462 | */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 463 | struct kobject *mq_kobj; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 464 | |
| 465 | #ifdef CONFIG_BLK_DEV_INTEGRITY |
| 466 | struct blk_integrity integrity; |
| 467 | #endif /* CONFIG_BLK_DEV_INTEGRITY */ |
| 468 | |
| 469 | #ifdef CONFIG_PM |
| 470 | struct device *dev; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 471 | enum rpm_status rpm_status; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 472 | unsigned int nr_pending; |
| 473 | #endif |
| 474 | |
| 475 | /* |
| 476 | * queue settings |
| 477 | */ |
| 478 | unsigned long nr_requests; /* Max # of requests */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 479 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 480 | unsigned int dma_pad_mask; |
| 481 | unsigned int dma_alignment; |
| 482 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 483 | #ifdef CONFIG_BLK_INLINE_ENCRYPTION |
| 484 | /* Inline crypto capabilities */ |
| 485 | struct blk_keyslot_manager *ksm; |
| 486 | #endif |
| 487 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 488 | unsigned int rq_timeout; |
| 489 | int poll_nsec; |
| 490 | |
| 491 | struct blk_stat_callback *poll_cb; |
| 492 | struct blk_rq_stat poll_stat[BLK_MQ_POLL_STATS_BKTS]; |
| 493 | |
| 494 | struct timer_list timeout; |
| 495 | struct work_struct timeout_work; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 496 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 497 | atomic_t nr_active_requests_shared_sbitmap; |
| 498 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 499 | struct list_head icq_list; |
| 500 | #ifdef CONFIG_BLK_CGROUP |
| 501 | DECLARE_BITMAP (blkcg_pols, BLKCG_MAX_POLS); |
| 502 | struct blkcg_gq *root_blkg; |
| 503 | struct list_head blkg_list; |
| 504 | #endif |
| 505 | |
| 506 | struct queue_limits limits; |
| 507 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 508 | unsigned int required_elevator_features; |
| 509 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 510 | #ifdef CONFIG_BLK_DEV_ZONED |
| 511 | /* |
| 512 | * Zoned block device information for request dispatch control. |
| 513 | * nr_zones is the total number of zones of the device. This is always |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 514 | * 0 for regular block devices. conv_zones_bitmap is a bitmap of nr_zones |
| 515 | * bits which indicates if a zone is conventional (bit set) or |
| 516 | * sequential (bit clear). seq_zones_wlock is a bitmap of nr_zones |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 517 | * bits which indicates if a zone is write locked, that is, if a write |
| 518 | * request targeting the zone was dispatched. All three fields are |
| 519 | * initialized by the low level device driver (e.g. scsi/sd.c). |
| 520 | * Stacking drivers (device mappers) may or may not initialize |
| 521 | * these fields. |
| 522 | * |
| 523 | * Reads of this information must be protected with blk_queue_enter() / |
| 524 | * blk_queue_exit(). Modifying this information is only allowed while |
| 525 | * no requests are being processed. See also blk_mq_freeze_queue() and |
| 526 | * blk_mq_unfreeze_queue(). |
| 527 | */ |
| 528 | unsigned int nr_zones; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 529 | unsigned long *conv_zones_bitmap; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 530 | unsigned long *seq_zones_wlock; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 531 | unsigned int max_open_zones; |
| 532 | unsigned int max_active_zones; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 533 | #endif /* CONFIG_BLK_DEV_ZONED */ |
| 534 | |
| 535 | /* |
| 536 | * sg stuff |
| 537 | */ |
| 538 | unsigned int sg_timeout; |
| 539 | unsigned int sg_reserved_size; |
| 540 | int node; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 541 | struct mutex debugfs_mutex; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 542 | #ifdef CONFIG_BLK_DEV_IO_TRACE |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 543 | struct blk_trace __rcu *blk_trace; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 544 | #endif |
| 545 | /* |
| 546 | * for flush operations |
| 547 | */ |
| 548 | struct blk_flush_queue *fq; |
| 549 | |
| 550 | struct list_head requeue_list; |
| 551 | spinlock_t requeue_lock; |
| 552 | struct delayed_work requeue_work; |
| 553 | |
| 554 | struct mutex sysfs_lock; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 555 | struct mutex sysfs_dir_lock; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 556 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 557 | /* |
| 558 | * for reusing dead hctx instance in case of updating |
| 559 | * nr_hw_queues |
| 560 | */ |
| 561 | struct list_head unused_hctx_list; |
| 562 | spinlock_t unused_hctx_lock; |
| 563 | |
| 564 | int mq_freeze_depth; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 565 | |
| 566 | #if defined(CONFIG_BLK_DEV_BSG) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 567 | struct bsg_class_device bsg_dev; |
| 568 | #endif |
| 569 | |
| 570 | #ifdef CONFIG_BLK_DEV_THROTTLING |
| 571 | /* Throttle data */ |
| 572 | struct throtl_data *td; |
| 573 | #endif |
| 574 | struct rcu_head rcu_head; |
| 575 | wait_queue_head_t mq_freeze_wq; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 576 | /* |
| 577 | * Protect concurrent access to q_usage_counter by |
| 578 | * percpu_ref_kill() and percpu_ref_reinit(). |
| 579 | */ |
| 580 | struct mutex mq_freeze_lock; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 581 | |
| 582 | struct blk_mq_tag_set *tag_set; |
| 583 | struct list_head tag_set_list; |
| 584 | struct bio_set bio_split; |
| 585 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 586 | struct dentry *debugfs_dir; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 587 | |
| 588 | #ifdef CONFIG_BLK_DEBUG_FS |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 589 | struct dentry *sched_debugfs_dir; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 590 | struct dentry *rqos_debugfs_dir; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 591 | #endif |
| 592 | |
| 593 | bool mq_sysfs_init_done; |
| 594 | |
| 595 | size_t cmd_size; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 596 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 597 | #define BLK_MAX_WRITE_HINTS 5 |
| 598 | u64 write_hints[BLK_MAX_WRITE_HINTS]; |
| 599 | }; |
| 600 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 601 | /* Keep blk_queue_flag_name[] in sync with the definitions below */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 602 | #define QUEUE_FLAG_STOPPED 0 /* queue is stopped */ |
| 603 | #define QUEUE_FLAG_DYING 1 /* queue being torn down */ |
| 604 | #define QUEUE_FLAG_NOMERGES 3 /* disable merge attempts */ |
| 605 | #define QUEUE_FLAG_SAME_COMP 4 /* complete on same CPU-group */ |
| 606 | #define QUEUE_FLAG_FAIL_IO 5 /* fake timeout */ |
| 607 | #define QUEUE_FLAG_NONROT 6 /* non-rotational device (SSD) */ |
| 608 | #define QUEUE_FLAG_VIRT QUEUE_FLAG_NONROT /* paravirt device */ |
| 609 | #define QUEUE_FLAG_IO_STAT 7 /* do disk/partitions IO accounting */ |
| 610 | #define QUEUE_FLAG_DISCARD 8 /* supports DISCARD */ |
| 611 | #define QUEUE_FLAG_NOXMERGES 9 /* No extended merges */ |
| 612 | #define QUEUE_FLAG_ADD_RANDOM 10 /* Contributes to random pool */ |
| 613 | #define QUEUE_FLAG_SECERASE 11 /* supports secure erase */ |
| 614 | #define QUEUE_FLAG_SAME_FORCE 12 /* force complete on same CPU */ |
| 615 | #define QUEUE_FLAG_DEAD 13 /* queue tear-down finished */ |
| 616 | #define QUEUE_FLAG_INIT_DONE 14 /* queue is initialized */ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 617 | #define QUEUE_FLAG_STABLE_WRITES 15 /* don't modify blks until WB is done */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 618 | #define QUEUE_FLAG_POLL 16 /* IO polling enabled if set */ |
| 619 | #define QUEUE_FLAG_WC 17 /* Write back caching */ |
| 620 | #define QUEUE_FLAG_FUA 18 /* device supports FUA writes */ |
| 621 | #define QUEUE_FLAG_DAX 19 /* device supports DAX */ |
| 622 | #define QUEUE_FLAG_STATS 20 /* track IO start and completion times */ |
| 623 | #define QUEUE_FLAG_POLL_STATS 21 /* collecting stats for hybrid polling */ |
| 624 | #define QUEUE_FLAG_REGISTERED 22 /* queue has been registered to a disk */ |
| 625 | #define QUEUE_FLAG_SCSI_PASSTHROUGH 23 /* queue supports SCSI commands */ |
| 626 | #define QUEUE_FLAG_QUIESCED 24 /* queue has been quiesced */ |
| 627 | #define QUEUE_FLAG_PCI_P2PDMA 25 /* device supports PCI p2p requests */ |
| 628 | #define QUEUE_FLAG_ZONE_RESETALL 26 /* supports Zone Reset All */ |
| 629 | #define QUEUE_FLAG_RQ_ALLOC_TIME 27 /* record rq->alloc_time_ns */ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 630 | #define QUEUE_FLAG_HCTX_ACTIVE 28 /* at least one blk-mq hctx is active */ |
| 631 | #define QUEUE_FLAG_NOWAIT 29 /* device supports NOWAIT */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 632 | |
| 633 | #define QUEUE_FLAG_MQ_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \ |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 634 | (1 << QUEUE_FLAG_SAME_COMP) | \ |
| 635 | (1 << QUEUE_FLAG_NOWAIT)) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 636 | |
| 637 | void blk_queue_flag_set(unsigned int flag, struct request_queue *q); |
| 638 | void blk_queue_flag_clear(unsigned int flag, struct request_queue *q); |
| 639 | bool blk_queue_flag_test_and_set(unsigned int flag, struct request_queue *q); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 640 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 641 | #define blk_queue_stopped(q) test_bit(QUEUE_FLAG_STOPPED, &(q)->queue_flags) |
| 642 | #define blk_queue_dying(q) test_bit(QUEUE_FLAG_DYING, &(q)->queue_flags) |
| 643 | #define blk_queue_dead(q) test_bit(QUEUE_FLAG_DEAD, &(q)->queue_flags) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 644 | #define blk_queue_init_done(q) test_bit(QUEUE_FLAG_INIT_DONE, &(q)->queue_flags) |
| 645 | #define blk_queue_nomerges(q) test_bit(QUEUE_FLAG_NOMERGES, &(q)->queue_flags) |
| 646 | #define blk_queue_noxmerges(q) \ |
| 647 | test_bit(QUEUE_FLAG_NOXMERGES, &(q)->queue_flags) |
| 648 | #define blk_queue_nonrot(q) test_bit(QUEUE_FLAG_NONROT, &(q)->queue_flags) |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 649 | #define blk_queue_stable_writes(q) \ |
| 650 | test_bit(QUEUE_FLAG_STABLE_WRITES, &(q)->queue_flags) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 651 | #define blk_queue_io_stat(q) test_bit(QUEUE_FLAG_IO_STAT, &(q)->queue_flags) |
| 652 | #define blk_queue_add_random(q) test_bit(QUEUE_FLAG_ADD_RANDOM, &(q)->queue_flags) |
| 653 | #define blk_queue_discard(q) test_bit(QUEUE_FLAG_DISCARD, &(q)->queue_flags) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 654 | #define blk_queue_zone_resetall(q) \ |
| 655 | test_bit(QUEUE_FLAG_ZONE_RESETALL, &(q)->queue_flags) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 656 | #define blk_queue_secure_erase(q) \ |
| 657 | (test_bit(QUEUE_FLAG_SECERASE, &(q)->queue_flags)) |
| 658 | #define blk_queue_dax(q) test_bit(QUEUE_FLAG_DAX, &(q)->queue_flags) |
| 659 | #define blk_queue_scsi_passthrough(q) \ |
| 660 | test_bit(QUEUE_FLAG_SCSI_PASSTHROUGH, &(q)->queue_flags) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 661 | #define blk_queue_pci_p2pdma(q) \ |
| 662 | test_bit(QUEUE_FLAG_PCI_P2PDMA, &(q)->queue_flags) |
| 663 | #ifdef CONFIG_BLK_RQ_ALLOC_TIME |
| 664 | #define blk_queue_rq_alloc_time(q) \ |
| 665 | test_bit(QUEUE_FLAG_RQ_ALLOC_TIME, &(q)->queue_flags) |
| 666 | #else |
| 667 | #define blk_queue_rq_alloc_time(q) false |
| 668 | #endif |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 669 | |
| 670 | #define blk_noretry_request(rq) \ |
| 671 | ((rq)->cmd_flags & (REQ_FAILFAST_DEV|REQ_FAILFAST_TRANSPORT| \ |
| 672 | REQ_FAILFAST_DRIVER)) |
| 673 | #define blk_queue_quiesced(q) test_bit(QUEUE_FLAG_QUIESCED, &(q)->queue_flags) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 674 | #define blk_queue_pm_only(q) atomic_read(&(q)->pm_only) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 675 | #define blk_queue_fua(q) test_bit(QUEUE_FLAG_FUA, &(q)->queue_flags) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 676 | #define blk_queue_registered(q) test_bit(QUEUE_FLAG_REGISTERED, &(q)->queue_flags) |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 677 | #define blk_queue_nowait(q) test_bit(QUEUE_FLAG_NOWAIT, &(q)->queue_flags) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 678 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 679 | extern void blk_set_pm_only(struct request_queue *q); |
| 680 | extern void blk_clear_pm_only(struct request_queue *q); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 681 | |
| 682 | static inline bool blk_account_rq(struct request *rq) |
| 683 | { |
| 684 | return (rq->rq_flags & RQF_STARTED) && !blk_rq_is_passthrough(rq); |
| 685 | } |
| 686 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 687 | #define list_entry_rq(ptr) list_entry((ptr), struct request, queuelist) |
| 688 | |
| 689 | #define rq_data_dir(rq) (op_is_write(req_op(rq)) ? WRITE : READ) |
| 690 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 691 | #define rq_dma_dir(rq) \ |
| 692 | (op_is_write(req_op(rq)) ? DMA_TO_DEVICE : DMA_FROM_DEVICE) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 693 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 694 | #define dma_map_bvec(dev, bv, dir, attrs) \ |
| 695 | dma_map_page_attrs(dev, (bv)->bv_page, (bv)->bv_offset, (bv)->bv_len, \ |
| 696 | (dir), (attrs)) |
| 697 | |
| 698 | static inline bool queue_is_mq(struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 699 | { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 700 | return q->mq_ops; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 701 | } |
| 702 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 703 | #ifdef CONFIG_PM |
| 704 | static inline enum rpm_status queue_rpm_status(struct request_queue *q) |
| 705 | { |
| 706 | return q->rpm_status; |
| 707 | } |
| 708 | #else |
| 709 | static inline enum rpm_status queue_rpm_status(struct request_queue *q) |
| 710 | { |
| 711 | return RPM_ACTIVE; |
| 712 | } |
| 713 | #endif |
| 714 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 715 | static inline enum blk_zoned_model |
| 716 | blk_queue_zoned_model(struct request_queue *q) |
| 717 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 718 | if (IS_ENABLED(CONFIG_BLK_DEV_ZONED)) |
| 719 | return q->limits.zoned; |
| 720 | return BLK_ZONED_NONE; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | static inline bool blk_queue_is_zoned(struct request_queue *q) |
| 724 | { |
| 725 | switch (blk_queue_zoned_model(q)) { |
| 726 | case BLK_ZONED_HA: |
| 727 | case BLK_ZONED_HM: |
| 728 | return true; |
| 729 | default: |
| 730 | return false; |
| 731 | } |
| 732 | } |
| 733 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 734 | static inline sector_t blk_queue_zone_sectors(struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 735 | { |
| 736 | return blk_queue_is_zoned(q) ? q->limits.chunk_sectors : 0; |
| 737 | } |
| 738 | |
| 739 | #ifdef CONFIG_BLK_DEV_ZONED |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 740 | static inline unsigned int blk_queue_nr_zones(struct request_queue *q) |
| 741 | { |
| 742 | return blk_queue_is_zoned(q) ? q->nr_zones : 0; |
| 743 | } |
| 744 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 745 | static inline unsigned int blk_queue_zone_no(struct request_queue *q, |
| 746 | sector_t sector) |
| 747 | { |
| 748 | if (!blk_queue_is_zoned(q)) |
| 749 | return 0; |
| 750 | return sector >> ilog2(q->limits.chunk_sectors); |
| 751 | } |
| 752 | |
| 753 | static inline bool blk_queue_zone_is_seq(struct request_queue *q, |
| 754 | sector_t sector) |
| 755 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 756 | if (!blk_queue_is_zoned(q)) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 757 | return false; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 758 | if (!q->conv_zones_bitmap) |
| 759 | return true; |
| 760 | return !test_bit(blk_queue_zone_no(q, sector), q->conv_zones_bitmap); |
| 761 | } |
| 762 | |
| 763 | static inline void blk_queue_max_open_zones(struct request_queue *q, |
| 764 | unsigned int max_open_zones) |
| 765 | { |
| 766 | q->max_open_zones = max_open_zones; |
| 767 | } |
| 768 | |
| 769 | static inline unsigned int queue_max_open_zones(const struct request_queue *q) |
| 770 | { |
| 771 | return q->max_open_zones; |
| 772 | } |
| 773 | |
| 774 | static inline void blk_queue_max_active_zones(struct request_queue *q, |
| 775 | unsigned int max_active_zones) |
| 776 | { |
| 777 | q->max_active_zones = max_active_zones; |
| 778 | } |
| 779 | |
| 780 | static inline unsigned int queue_max_active_zones(const struct request_queue *q) |
| 781 | { |
| 782 | return q->max_active_zones; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 783 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 784 | #else /* CONFIG_BLK_DEV_ZONED */ |
| 785 | static inline unsigned int blk_queue_nr_zones(struct request_queue *q) |
| 786 | { |
| 787 | return 0; |
| 788 | } |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 789 | static inline bool blk_queue_zone_is_seq(struct request_queue *q, |
| 790 | sector_t sector) |
| 791 | { |
| 792 | return false; |
| 793 | } |
| 794 | static inline unsigned int blk_queue_zone_no(struct request_queue *q, |
| 795 | sector_t sector) |
| 796 | { |
| 797 | return 0; |
| 798 | } |
| 799 | static inline unsigned int queue_max_open_zones(const struct request_queue *q) |
| 800 | { |
| 801 | return 0; |
| 802 | } |
| 803 | static inline unsigned int queue_max_active_zones(const struct request_queue *q) |
| 804 | { |
| 805 | return 0; |
| 806 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 807 | #endif /* CONFIG_BLK_DEV_ZONED */ |
| 808 | |
| 809 | static inline bool rq_is_sync(struct request *rq) |
| 810 | { |
| 811 | return op_is_sync(rq->cmd_flags); |
| 812 | } |
| 813 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 814 | static inline bool rq_mergeable(struct request *rq) |
| 815 | { |
| 816 | if (blk_rq_is_passthrough(rq)) |
| 817 | return false; |
| 818 | |
| 819 | if (req_op(rq) == REQ_OP_FLUSH) |
| 820 | return false; |
| 821 | |
| 822 | if (req_op(rq) == REQ_OP_WRITE_ZEROES) |
| 823 | return false; |
| 824 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 825 | if (req_op(rq) == REQ_OP_ZONE_APPEND) |
| 826 | return false; |
| 827 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 828 | if (rq->cmd_flags & REQ_NOMERGE_FLAGS) |
| 829 | return false; |
| 830 | if (rq->rq_flags & RQF_NOMERGE_FLAGS) |
| 831 | return false; |
| 832 | |
| 833 | return true; |
| 834 | } |
| 835 | |
| 836 | static inline bool blk_write_same_mergeable(struct bio *a, struct bio *b) |
| 837 | { |
| 838 | if (bio_page(a) == bio_page(b) && |
| 839 | bio_offset(a) == bio_offset(b)) |
| 840 | return true; |
| 841 | |
| 842 | return false; |
| 843 | } |
| 844 | |
| 845 | static inline unsigned int blk_queue_depth(struct request_queue *q) |
| 846 | { |
| 847 | if (q->queue_depth) |
| 848 | return q->queue_depth; |
| 849 | |
| 850 | return q->nr_requests; |
| 851 | } |
| 852 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 853 | extern unsigned long blk_max_low_pfn, blk_max_pfn; |
| 854 | |
| 855 | /* |
| 856 | * standard bounce addresses: |
| 857 | * |
| 858 | * BLK_BOUNCE_HIGH : bounce all highmem pages |
| 859 | * BLK_BOUNCE_ANY : don't bounce anything |
| 860 | * BLK_BOUNCE_ISA : bounce pages above ISA DMA boundary |
| 861 | */ |
| 862 | |
| 863 | #if BITS_PER_LONG == 32 |
| 864 | #define BLK_BOUNCE_HIGH ((u64)blk_max_low_pfn << PAGE_SHIFT) |
| 865 | #else |
| 866 | #define BLK_BOUNCE_HIGH -1ULL |
| 867 | #endif |
| 868 | #define BLK_BOUNCE_ANY (-1ULL) |
| 869 | #define BLK_BOUNCE_ISA (DMA_BIT_MASK(24)) |
| 870 | |
| 871 | /* |
| 872 | * default timeout for SG_IO if none specified |
| 873 | */ |
| 874 | #define BLK_DEFAULT_SG_TIMEOUT (60 * HZ) |
| 875 | #define BLK_MIN_SG_TIMEOUT (7 * HZ) |
| 876 | |
| 877 | struct rq_map_data { |
| 878 | struct page **pages; |
| 879 | int page_order; |
| 880 | int nr_entries; |
| 881 | unsigned long offset; |
| 882 | int null_mapped; |
| 883 | int from_user; |
| 884 | }; |
| 885 | |
| 886 | struct req_iterator { |
| 887 | struct bvec_iter iter; |
| 888 | struct bio *bio; |
| 889 | }; |
| 890 | |
| 891 | /* This should not be used directly - use rq_for_each_segment */ |
| 892 | #define for_each_bio(_bio) \ |
| 893 | for (; _bio; _bio = _bio->bi_next) |
| 894 | #define __rq_for_each_bio(_bio, rq) \ |
| 895 | if ((rq->bio)) \ |
| 896 | for (_bio = (rq)->bio; _bio; _bio = _bio->bi_next) |
| 897 | |
| 898 | #define rq_for_each_segment(bvl, _rq, _iter) \ |
| 899 | __rq_for_each_bio(_iter.bio, _rq) \ |
| 900 | bio_for_each_segment(bvl, _iter.bio, _iter.iter) |
| 901 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 902 | #define rq_for_each_bvec(bvl, _rq, _iter) \ |
| 903 | __rq_for_each_bio(_iter.bio, _rq) \ |
| 904 | bio_for_each_bvec(bvl, _iter.bio, _iter.iter) |
| 905 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 906 | #define rq_iter_last(bvec, _iter) \ |
| 907 | (_iter.bio->bi_next == NULL && \ |
| 908 | bio_iter_last(bvec, _iter.iter)) |
| 909 | |
| 910 | #ifndef ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE |
| 911 | # error "You should define ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE for your platform" |
| 912 | #endif |
| 913 | #if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE |
| 914 | extern void rq_flush_dcache_pages(struct request *rq); |
| 915 | #else |
| 916 | static inline void rq_flush_dcache_pages(struct request *rq) |
| 917 | { |
| 918 | } |
| 919 | #endif |
| 920 | |
| 921 | extern int blk_register_queue(struct gendisk *disk); |
| 922 | extern void blk_unregister_queue(struct gendisk *disk); |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 923 | blk_qc_t submit_bio_noacct(struct bio *bio); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 924 | extern void blk_rq_init(struct request_queue *q, struct request *rq); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 925 | extern void blk_put_request(struct request *); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 926 | extern struct request *blk_get_request(struct request_queue *, unsigned int op, |
| 927 | blk_mq_req_flags_t flags); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 928 | extern int blk_lld_busy(struct request_queue *q); |
| 929 | extern int blk_rq_prep_clone(struct request *rq, struct request *rq_src, |
| 930 | struct bio_set *bs, gfp_t gfp_mask, |
| 931 | int (*bio_ctr)(struct bio *, struct bio *, void *), |
| 932 | void *data); |
| 933 | extern void blk_rq_unprep_clone(struct request *rq); |
| 934 | extern blk_status_t blk_insert_cloned_request(struct request_queue *q, |
| 935 | struct request *rq); |
| 936 | extern int blk_rq_append_bio(struct request *rq, struct bio **bio); |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 937 | extern void blk_queue_split(struct bio **); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 938 | extern int scsi_verify_blk_ioctl(struct block_device *, unsigned int); |
| 939 | extern int scsi_cmd_blk_ioctl(struct block_device *, fmode_t, |
| 940 | unsigned int, void __user *); |
| 941 | extern int scsi_cmd_ioctl(struct request_queue *, struct gendisk *, fmode_t, |
| 942 | unsigned int, void __user *); |
| 943 | extern int sg_scsi_ioctl(struct request_queue *, struct gendisk *, fmode_t, |
| 944 | struct scsi_ioctl_command __user *); |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 945 | extern int get_sg_io_hdr(struct sg_io_hdr *hdr, const void __user *argp); |
| 946 | extern int put_sg_io_hdr(const struct sg_io_hdr *hdr, void __user *argp); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 947 | |
| 948 | extern int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags); |
| 949 | extern void blk_queue_exit(struct request_queue *q); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 950 | extern void blk_sync_queue(struct request_queue *q); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 951 | extern int blk_rq_map_user(struct request_queue *, struct request *, |
| 952 | struct rq_map_data *, void __user *, unsigned long, |
| 953 | gfp_t); |
| 954 | extern int blk_rq_unmap_user(struct bio *); |
| 955 | extern int blk_rq_map_kern(struct request_queue *, struct request *, void *, unsigned int, gfp_t); |
| 956 | extern int blk_rq_map_user_iov(struct request_queue *, struct request *, |
| 957 | struct rq_map_data *, const struct iov_iter *, |
| 958 | gfp_t); |
| 959 | extern void blk_execute_rq(struct request_queue *, struct gendisk *, |
| 960 | struct request *, int); |
| 961 | extern void blk_execute_rq_nowait(struct request_queue *, struct gendisk *, |
| 962 | struct request *, int, rq_end_io_fn *); |
| 963 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 964 | /* Helper to convert REQ_OP_XXX to its string format XXX */ |
| 965 | extern const char *blk_op_str(unsigned int op); |
| 966 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 967 | int blk_status_to_errno(blk_status_t status); |
| 968 | blk_status_t errno_to_blk_status(int errno); |
| 969 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 970 | int blk_poll(struct request_queue *q, blk_qc_t cookie, bool spin); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 971 | |
| 972 | static inline struct request_queue *bdev_get_queue(struct block_device *bdev) |
| 973 | { |
| 974 | return bdev->bd_disk->queue; /* this is never NULL */ |
| 975 | } |
| 976 | |
| 977 | /* |
| 978 | * The basic unit of block I/O is a sector. It is used in a number of contexts |
| 979 | * in Linux (blk, bio, genhd). The size of one sector is 512 = 2**9 |
| 980 | * bytes. Variables of type sector_t represent an offset or size that is a |
| 981 | * multiple of 512 bytes. Hence these two constants. |
| 982 | */ |
| 983 | #ifndef SECTOR_SHIFT |
| 984 | #define SECTOR_SHIFT 9 |
| 985 | #endif |
| 986 | #ifndef SECTOR_SIZE |
| 987 | #define SECTOR_SIZE (1 << SECTOR_SHIFT) |
| 988 | #endif |
| 989 | |
| 990 | /* |
| 991 | * blk_rq_pos() : the current sector |
| 992 | * blk_rq_bytes() : bytes left in the entire request |
| 993 | * blk_rq_cur_bytes() : bytes left in the current segment |
| 994 | * blk_rq_err_bytes() : bytes left till the next error boundary |
| 995 | * blk_rq_sectors() : sectors left in the entire request |
| 996 | * blk_rq_cur_sectors() : sectors left in the current segment |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 997 | * blk_rq_stats_sectors() : sectors of the entire request used for stats |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 998 | */ |
| 999 | static inline sector_t blk_rq_pos(const struct request *rq) |
| 1000 | { |
| 1001 | return rq->__sector; |
| 1002 | } |
| 1003 | |
| 1004 | static inline unsigned int blk_rq_bytes(const struct request *rq) |
| 1005 | { |
| 1006 | return rq->__data_len; |
| 1007 | } |
| 1008 | |
| 1009 | static inline int blk_rq_cur_bytes(const struct request *rq) |
| 1010 | { |
| 1011 | return rq->bio ? bio_cur_bytes(rq->bio) : 0; |
| 1012 | } |
| 1013 | |
| 1014 | extern unsigned int blk_rq_err_bytes(const struct request *rq); |
| 1015 | |
| 1016 | static inline unsigned int blk_rq_sectors(const struct request *rq) |
| 1017 | { |
| 1018 | return blk_rq_bytes(rq) >> SECTOR_SHIFT; |
| 1019 | } |
| 1020 | |
| 1021 | static inline unsigned int blk_rq_cur_sectors(const struct request *rq) |
| 1022 | { |
| 1023 | return blk_rq_cur_bytes(rq) >> SECTOR_SHIFT; |
| 1024 | } |
| 1025 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1026 | static inline unsigned int blk_rq_stats_sectors(const struct request *rq) |
| 1027 | { |
| 1028 | return rq->stats_sectors; |
| 1029 | } |
| 1030 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1031 | #ifdef CONFIG_BLK_DEV_ZONED |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1032 | |
| 1033 | /* Helper to convert BLK_ZONE_ZONE_XXX to its string format XXX */ |
| 1034 | const char *blk_zone_cond_str(enum blk_zone_cond zone_cond); |
| 1035 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1036 | static inline unsigned int blk_rq_zone_no(struct request *rq) |
| 1037 | { |
| 1038 | return blk_queue_zone_no(rq->q, blk_rq_pos(rq)); |
| 1039 | } |
| 1040 | |
| 1041 | static inline unsigned int blk_rq_zone_is_seq(struct request *rq) |
| 1042 | { |
| 1043 | return blk_queue_zone_is_seq(rq->q, blk_rq_pos(rq)); |
| 1044 | } |
| 1045 | #endif /* CONFIG_BLK_DEV_ZONED */ |
| 1046 | |
| 1047 | /* |
| 1048 | * Some commands like WRITE SAME have a payload or data transfer size which |
| 1049 | * is different from the size of the request. Any driver that supports such |
| 1050 | * commands using the RQF_SPECIAL_PAYLOAD flag needs to use this helper to |
| 1051 | * calculate the data transfer size. |
| 1052 | */ |
| 1053 | static inline unsigned int blk_rq_payload_bytes(struct request *rq) |
| 1054 | { |
| 1055 | if (rq->rq_flags & RQF_SPECIAL_PAYLOAD) |
| 1056 | return rq->special_vec.bv_len; |
| 1057 | return blk_rq_bytes(rq); |
| 1058 | } |
| 1059 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1060 | /* |
| 1061 | * Return the first full biovec in the request. The caller needs to check that |
| 1062 | * there are any bvecs before calling this helper. |
| 1063 | */ |
| 1064 | static inline struct bio_vec req_bvec(struct request *rq) |
| 1065 | { |
| 1066 | if (rq->rq_flags & RQF_SPECIAL_PAYLOAD) |
| 1067 | return rq->special_vec; |
| 1068 | return mp_bvec_iter_bvec(rq->bio->bi_io_vec, rq->bio->bi_iter); |
| 1069 | } |
| 1070 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1071 | static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q, |
| 1072 | int op) |
| 1073 | { |
| 1074 | if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE)) |
| 1075 | return min(q->limits.max_discard_sectors, |
| 1076 | UINT_MAX >> SECTOR_SHIFT); |
| 1077 | |
| 1078 | if (unlikely(op == REQ_OP_WRITE_SAME)) |
| 1079 | return q->limits.max_write_same_sectors; |
| 1080 | |
| 1081 | if (unlikely(op == REQ_OP_WRITE_ZEROES)) |
| 1082 | return q->limits.max_write_zeroes_sectors; |
| 1083 | |
| 1084 | return q->limits.max_sectors; |
| 1085 | } |
| 1086 | |
| 1087 | /* |
| 1088 | * Return maximum size of a request at given offset. Only valid for |
| 1089 | * file system requests. |
| 1090 | */ |
| 1091 | static inline unsigned int blk_max_size_offset(struct request_queue *q, |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1092 | sector_t offset, |
| 1093 | unsigned int chunk_sectors) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1094 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1095 | if (!chunk_sectors) { |
| 1096 | if (q->limits.chunk_sectors) |
| 1097 | chunk_sectors = q->limits.chunk_sectors; |
| 1098 | else |
| 1099 | return q->limits.max_sectors; |
| 1100 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1101 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1102 | if (likely(is_power_of_2(chunk_sectors))) |
| 1103 | chunk_sectors -= offset & (chunk_sectors - 1); |
| 1104 | else |
| 1105 | chunk_sectors -= sector_div(offset, chunk_sectors); |
| 1106 | |
| 1107 | return min(q->limits.max_sectors, chunk_sectors); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | static inline unsigned int blk_rq_get_max_sectors(struct request *rq, |
| 1111 | sector_t offset) |
| 1112 | { |
| 1113 | struct request_queue *q = rq->q; |
| 1114 | |
| 1115 | if (blk_rq_is_passthrough(rq)) |
| 1116 | return q->limits.max_hw_sectors; |
| 1117 | |
| 1118 | if (!q->limits.chunk_sectors || |
| 1119 | req_op(rq) == REQ_OP_DISCARD || |
| 1120 | req_op(rq) == REQ_OP_SECURE_ERASE) |
| 1121 | return blk_queue_get_max_sectors(q, req_op(rq)); |
| 1122 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1123 | return min(blk_max_size_offset(q, offset, 0), |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1124 | blk_queue_get_max_sectors(q, req_op(rq))); |
| 1125 | } |
| 1126 | |
| 1127 | static inline unsigned int blk_rq_count_bios(struct request *rq) |
| 1128 | { |
| 1129 | unsigned int nr_bios = 0; |
| 1130 | struct bio *bio; |
| 1131 | |
| 1132 | __rq_for_each_bio(bio, rq) |
| 1133 | nr_bios++; |
| 1134 | |
| 1135 | return nr_bios; |
| 1136 | } |
| 1137 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1138 | void blk_steal_bios(struct bio_list *list, struct request *rq); |
| 1139 | |
| 1140 | /* |
| 1141 | * Request completion related functions. |
| 1142 | * |
| 1143 | * blk_update_request() completes given number of bytes and updates |
| 1144 | * the request without completing it. |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1145 | */ |
| 1146 | extern bool blk_update_request(struct request *rq, blk_status_t error, |
| 1147 | unsigned int nr_bytes); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1148 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1149 | extern void blk_abort_request(struct request *); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1150 | |
| 1151 | /* |
| 1152 | * Access functions for manipulating queue properties |
| 1153 | */ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1154 | extern void blk_cleanup_queue(struct request_queue *); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1155 | extern void blk_queue_bounce_limit(struct request_queue *, u64); |
| 1156 | extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int); |
| 1157 | extern void blk_queue_chunk_sectors(struct request_queue *, unsigned int); |
| 1158 | extern void blk_queue_max_segments(struct request_queue *, unsigned short); |
| 1159 | extern void blk_queue_max_discard_segments(struct request_queue *, |
| 1160 | unsigned short); |
| 1161 | extern void blk_queue_max_segment_size(struct request_queue *, unsigned int); |
| 1162 | extern void blk_queue_max_discard_sectors(struct request_queue *q, |
| 1163 | unsigned int max_discard_sectors); |
| 1164 | extern void blk_queue_max_write_same_sectors(struct request_queue *q, |
| 1165 | unsigned int max_write_same_sectors); |
| 1166 | extern void blk_queue_max_write_zeroes_sectors(struct request_queue *q, |
| 1167 | unsigned int max_write_same_sectors); |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 1168 | extern void blk_queue_logical_block_size(struct request_queue *, unsigned int); |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1169 | extern void blk_queue_max_zone_append_sectors(struct request_queue *q, |
| 1170 | unsigned int max_zone_append_sectors); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1171 | extern void blk_queue_physical_block_size(struct request_queue *, unsigned int); |
| 1172 | extern void blk_queue_alignment_offset(struct request_queue *q, |
| 1173 | unsigned int alignment); |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1174 | void blk_queue_update_readahead(struct request_queue *q); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1175 | extern void blk_limits_io_min(struct queue_limits *limits, unsigned int min); |
| 1176 | extern void blk_queue_io_min(struct request_queue *q, unsigned int min); |
| 1177 | extern void blk_limits_io_opt(struct queue_limits *limits, unsigned int opt); |
| 1178 | extern void blk_queue_io_opt(struct request_queue *q, unsigned int opt); |
| 1179 | extern void blk_set_queue_depth(struct request_queue *q, unsigned int depth); |
| 1180 | extern void blk_set_default_limits(struct queue_limits *lim); |
| 1181 | extern void blk_set_stacking_limits(struct queue_limits *lim); |
| 1182 | extern int blk_stack_limits(struct queue_limits *t, struct queue_limits *b, |
| 1183 | sector_t offset); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1184 | extern void disk_stack_limits(struct gendisk *disk, struct block_device *bdev, |
| 1185 | sector_t offset); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1186 | extern void blk_queue_update_dma_pad(struct request_queue *, unsigned int); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1187 | extern void blk_queue_segment_boundary(struct request_queue *, unsigned long); |
| 1188 | extern void blk_queue_virt_boundary(struct request_queue *, unsigned long); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1189 | extern void blk_queue_dma_alignment(struct request_queue *, int); |
| 1190 | extern void blk_queue_update_dma_alignment(struct request_queue *, int); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1191 | extern void blk_queue_rq_timeout(struct request_queue *, unsigned int); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1192 | extern void blk_queue_write_cache(struct request_queue *q, bool enabled, bool fua); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1193 | extern void blk_queue_required_elevator_features(struct request_queue *q, |
| 1194 | unsigned int features); |
| 1195 | extern bool blk_queue_can_use_dma_map_merging(struct request_queue *q, |
| 1196 | struct device *dev); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1197 | |
| 1198 | /* |
| 1199 | * Number of physical segments as sent to the device. |
| 1200 | * |
| 1201 | * Normally this is the number of discontiguous data segments sent by the |
| 1202 | * submitter. But for data-less command like discard we might have no |
| 1203 | * actual data segments submitted, but the driver might have to add it's |
| 1204 | * own special payload. In that case we still return 1 here so that this |
| 1205 | * special payload will be mapped. |
| 1206 | */ |
| 1207 | static inline unsigned short blk_rq_nr_phys_segments(struct request *rq) |
| 1208 | { |
| 1209 | if (rq->rq_flags & RQF_SPECIAL_PAYLOAD) |
| 1210 | return 1; |
| 1211 | return rq->nr_phys_segments; |
| 1212 | } |
| 1213 | |
| 1214 | /* |
| 1215 | * Number of discard segments (or ranges) the driver needs to fill in. |
| 1216 | * Each discard bio merged into a request is counted as one segment. |
| 1217 | */ |
| 1218 | static inline unsigned short blk_rq_nr_discard_segments(struct request *rq) |
| 1219 | { |
| 1220 | return max_t(unsigned short, rq->nr_phys_segments, 1); |
| 1221 | } |
| 1222 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1223 | int __blk_rq_map_sg(struct request_queue *q, struct request *rq, |
| 1224 | struct scatterlist *sglist, struct scatterlist **last_sg); |
| 1225 | static inline int blk_rq_map_sg(struct request_queue *q, struct request *rq, |
| 1226 | struct scatterlist *sglist) |
| 1227 | { |
| 1228 | struct scatterlist *last_sg = NULL; |
| 1229 | |
| 1230 | return __blk_rq_map_sg(q, rq, sglist, &last_sg); |
| 1231 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1232 | extern void blk_dump_rq_flags(struct request *, char *); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1233 | |
| 1234 | bool __must_check blk_get_queue(struct request_queue *); |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1235 | struct request_queue *blk_alloc_queue(int node_id); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1236 | extern void blk_put_queue(struct request_queue *); |
| 1237 | extern void blk_set_queue_dying(struct request_queue *); |
| 1238 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1239 | #ifdef CONFIG_BLOCK |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1240 | /* |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1241 | * blk_plug permits building a queue of related requests by holding the I/O |
| 1242 | * fragments for a short period. This allows merging of sequential requests |
| 1243 | * into single larger request. As the requests are moved from a per-task list to |
| 1244 | * the device's request_queue in a batch, this results in improved scalability |
| 1245 | * as the lock contention for request_queue lock is reduced. |
| 1246 | * |
| 1247 | * It is ok not to disable preemption when adding the request to the plug list |
| 1248 | * or when attempting a merge, because blk_schedule_flush_list() will only flush |
| 1249 | * the plug list when the task sleeps by itself. For details, please see |
| 1250 | * schedule() where blk_schedule_flush_plug() is called. |
| 1251 | */ |
| 1252 | struct blk_plug { |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1253 | struct list_head mq_list; /* blk-mq requests */ |
| 1254 | struct list_head cb_list; /* md requires an unplug callback */ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1255 | unsigned short rq_count; |
| 1256 | bool multiple_queues; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1257 | bool nowait; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1258 | }; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1259 | |
| 1260 | struct blk_plug_cb; |
| 1261 | typedef void (*blk_plug_cb_fn)(struct blk_plug_cb *, bool); |
| 1262 | struct blk_plug_cb { |
| 1263 | struct list_head list; |
| 1264 | blk_plug_cb_fn callback; |
| 1265 | void *data; |
| 1266 | }; |
| 1267 | extern struct blk_plug_cb *blk_check_plugged(blk_plug_cb_fn unplug, |
| 1268 | void *data, int size); |
| 1269 | extern void blk_start_plug(struct blk_plug *); |
| 1270 | extern void blk_finish_plug(struct blk_plug *); |
| 1271 | extern void blk_flush_plug_list(struct blk_plug *, bool); |
| 1272 | |
| 1273 | static inline void blk_flush_plug(struct task_struct *tsk) |
| 1274 | { |
| 1275 | struct blk_plug *plug = tsk->plug; |
| 1276 | |
| 1277 | if (plug) |
| 1278 | blk_flush_plug_list(plug, false); |
| 1279 | } |
| 1280 | |
| 1281 | static inline void blk_schedule_flush_plug(struct task_struct *tsk) |
| 1282 | { |
| 1283 | struct blk_plug *plug = tsk->plug; |
| 1284 | |
| 1285 | if (plug) |
| 1286 | blk_flush_plug_list(plug, true); |
| 1287 | } |
| 1288 | |
| 1289 | static inline bool blk_needs_flush_plug(struct task_struct *tsk) |
| 1290 | { |
| 1291 | struct blk_plug *plug = tsk->plug; |
| 1292 | |
| 1293 | return plug && |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1294 | (!list_empty(&plug->mq_list) || |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1295 | !list_empty(&plug->cb_list)); |
| 1296 | } |
| 1297 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1298 | int blkdev_issue_flush(struct block_device *, gfp_t); |
| 1299 | long nr_blockdev_pages(void); |
| 1300 | #else /* CONFIG_BLOCK */ |
| 1301 | struct blk_plug { |
| 1302 | }; |
| 1303 | |
| 1304 | static inline void blk_start_plug(struct blk_plug *plug) |
| 1305 | { |
| 1306 | } |
| 1307 | |
| 1308 | static inline void blk_finish_plug(struct blk_plug *plug) |
| 1309 | { |
| 1310 | } |
| 1311 | |
| 1312 | static inline void blk_flush_plug(struct task_struct *task) |
| 1313 | { |
| 1314 | } |
| 1315 | |
| 1316 | static inline void blk_schedule_flush_plug(struct task_struct *task) |
| 1317 | { |
| 1318 | } |
| 1319 | |
| 1320 | |
| 1321 | static inline bool blk_needs_flush_plug(struct task_struct *tsk) |
| 1322 | { |
| 1323 | return false; |
| 1324 | } |
| 1325 | |
| 1326 | static inline int blkdev_issue_flush(struct block_device *bdev, gfp_t gfp_mask) |
| 1327 | { |
| 1328 | return 0; |
| 1329 | } |
| 1330 | |
| 1331 | static inline long nr_blockdev_pages(void) |
| 1332 | { |
| 1333 | return 0; |
| 1334 | } |
| 1335 | #endif /* CONFIG_BLOCK */ |
| 1336 | |
| 1337 | extern void blk_io_schedule(void); |
| 1338 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1339 | extern int blkdev_issue_write_same(struct block_device *bdev, sector_t sector, |
| 1340 | sector_t nr_sects, gfp_t gfp_mask, struct page *page); |
| 1341 | |
| 1342 | #define BLKDEV_DISCARD_SECURE (1 << 0) /* issue a secure erase */ |
| 1343 | |
| 1344 | extern int blkdev_issue_discard(struct block_device *bdev, sector_t sector, |
| 1345 | sector_t nr_sects, gfp_t gfp_mask, unsigned long flags); |
| 1346 | extern int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, |
| 1347 | sector_t nr_sects, gfp_t gfp_mask, int flags, |
| 1348 | struct bio **biop); |
| 1349 | |
| 1350 | #define BLKDEV_ZERO_NOUNMAP (1 << 0) /* do not free blocks */ |
| 1351 | #define BLKDEV_ZERO_NOFALLBACK (1 << 1) /* don't write explicit zeroes */ |
| 1352 | |
| 1353 | extern int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, |
| 1354 | sector_t nr_sects, gfp_t gfp_mask, struct bio **biop, |
| 1355 | unsigned flags); |
| 1356 | extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, |
| 1357 | sector_t nr_sects, gfp_t gfp_mask, unsigned flags); |
| 1358 | |
| 1359 | static inline int sb_issue_discard(struct super_block *sb, sector_t block, |
| 1360 | sector_t nr_blocks, gfp_t gfp_mask, unsigned long flags) |
| 1361 | { |
| 1362 | return blkdev_issue_discard(sb->s_bdev, |
| 1363 | block << (sb->s_blocksize_bits - |
| 1364 | SECTOR_SHIFT), |
| 1365 | nr_blocks << (sb->s_blocksize_bits - |
| 1366 | SECTOR_SHIFT), |
| 1367 | gfp_mask, flags); |
| 1368 | } |
| 1369 | static inline int sb_issue_zeroout(struct super_block *sb, sector_t block, |
| 1370 | sector_t nr_blocks, gfp_t gfp_mask) |
| 1371 | { |
| 1372 | return blkdev_issue_zeroout(sb->s_bdev, |
| 1373 | block << (sb->s_blocksize_bits - |
| 1374 | SECTOR_SHIFT), |
| 1375 | nr_blocks << (sb->s_blocksize_bits - |
| 1376 | SECTOR_SHIFT), |
| 1377 | gfp_mask, 0); |
| 1378 | } |
| 1379 | |
| 1380 | extern int blk_verify_command(unsigned char *cmd, fmode_t mode); |
| 1381 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1382 | static inline bool bdev_is_partition(struct block_device *bdev) |
| 1383 | { |
| 1384 | return bdev->bd_partno; |
| 1385 | } |
| 1386 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1387 | enum blk_default_limits { |
| 1388 | BLK_MAX_SEGMENTS = 128, |
| 1389 | BLK_SAFE_MAX_SECTORS = 255, |
| 1390 | BLK_DEF_MAX_SECTORS = 2560, |
| 1391 | BLK_MAX_SEGMENT_SIZE = 65536, |
| 1392 | BLK_SEG_BOUNDARY_MASK = 0xFFFFFFFFUL, |
| 1393 | }; |
| 1394 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1395 | static inline unsigned long queue_segment_boundary(const struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1396 | { |
| 1397 | return q->limits.seg_boundary_mask; |
| 1398 | } |
| 1399 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1400 | static inline unsigned long queue_virt_boundary(const struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1401 | { |
| 1402 | return q->limits.virt_boundary_mask; |
| 1403 | } |
| 1404 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1405 | static inline unsigned int queue_max_sectors(const struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1406 | { |
| 1407 | return q->limits.max_sectors; |
| 1408 | } |
| 1409 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1410 | static inline unsigned int queue_max_hw_sectors(const struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1411 | { |
| 1412 | return q->limits.max_hw_sectors; |
| 1413 | } |
| 1414 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1415 | static inline unsigned short queue_max_segments(const struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1416 | { |
| 1417 | return q->limits.max_segments; |
| 1418 | } |
| 1419 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1420 | static inline unsigned short queue_max_discard_segments(const struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1421 | { |
| 1422 | return q->limits.max_discard_segments; |
| 1423 | } |
| 1424 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1425 | static inline unsigned int queue_max_segment_size(const struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1426 | { |
| 1427 | return q->limits.max_segment_size; |
| 1428 | } |
| 1429 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1430 | static inline unsigned int queue_max_zone_append_sectors(const struct request_queue *q) |
| 1431 | { |
| 1432 | |
| 1433 | const struct queue_limits *l = &q->limits; |
| 1434 | |
| 1435 | return min(l->max_zone_append_sectors, l->max_sectors); |
| 1436 | } |
| 1437 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 1438 | static inline unsigned queue_logical_block_size(const struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1439 | { |
| 1440 | int retval = 512; |
| 1441 | |
| 1442 | if (q && q->limits.logical_block_size) |
| 1443 | retval = q->limits.logical_block_size; |
| 1444 | |
| 1445 | return retval; |
| 1446 | } |
| 1447 | |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame] | 1448 | static inline unsigned int bdev_logical_block_size(struct block_device *bdev) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1449 | { |
| 1450 | return queue_logical_block_size(bdev_get_queue(bdev)); |
| 1451 | } |
| 1452 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1453 | static inline unsigned int queue_physical_block_size(const struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1454 | { |
| 1455 | return q->limits.physical_block_size; |
| 1456 | } |
| 1457 | |
| 1458 | static inline unsigned int bdev_physical_block_size(struct block_device *bdev) |
| 1459 | { |
| 1460 | return queue_physical_block_size(bdev_get_queue(bdev)); |
| 1461 | } |
| 1462 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1463 | static inline unsigned int queue_io_min(const struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1464 | { |
| 1465 | return q->limits.io_min; |
| 1466 | } |
| 1467 | |
| 1468 | static inline int bdev_io_min(struct block_device *bdev) |
| 1469 | { |
| 1470 | return queue_io_min(bdev_get_queue(bdev)); |
| 1471 | } |
| 1472 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1473 | static inline unsigned int queue_io_opt(const struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1474 | { |
| 1475 | return q->limits.io_opt; |
| 1476 | } |
| 1477 | |
| 1478 | static inline int bdev_io_opt(struct block_device *bdev) |
| 1479 | { |
| 1480 | return queue_io_opt(bdev_get_queue(bdev)); |
| 1481 | } |
| 1482 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1483 | static inline int queue_alignment_offset(const struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1484 | { |
| 1485 | if (q->limits.misaligned) |
| 1486 | return -1; |
| 1487 | |
| 1488 | return q->limits.alignment_offset; |
| 1489 | } |
| 1490 | |
| 1491 | static inline int queue_limit_alignment_offset(struct queue_limits *lim, sector_t sector) |
| 1492 | { |
| 1493 | unsigned int granularity = max(lim->physical_block_size, lim->io_min); |
| 1494 | unsigned int alignment = sector_div(sector, granularity >> SECTOR_SHIFT) |
| 1495 | << SECTOR_SHIFT; |
| 1496 | |
| 1497 | return (granularity + lim->alignment_offset - alignment) % granularity; |
| 1498 | } |
| 1499 | |
| 1500 | static inline int bdev_alignment_offset(struct block_device *bdev) |
| 1501 | { |
| 1502 | struct request_queue *q = bdev_get_queue(bdev); |
| 1503 | |
| 1504 | if (q->limits.misaligned) |
| 1505 | return -1; |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1506 | if (bdev_is_partition(bdev)) |
| 1507 | return queue_limit_alignment_offset(&q->limits, |
| 1508 | bdev->bd_part->start_sect); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1509 | return q->limits.alignment_offset; |
| 1510 | } |
| 1511 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1512 | static inline int queue_discard_alignment(const struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1513 | { |
| 1514 | if (q->limits.discard_misaligned) |
| 1515 | return -1; |
| 1516 | |
| 1517 | return q->limits.discard_alignment; |
| 1518 | } |
| 1519 | |
| 1520 | static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector_t sector) |
| 1521 | { |
| 1522 | unsigned int alignment, granularity, offset; |
| 1523 | |
| 1524 | if (!lim->max_discard_sectors) |
| 1525 | return 0; |
| 1526 | |
| 1527 | /* Why are these in bytes, not sectors? */ |
| 1528 | alignment = lim->discard_alignment >> SECTOR_SHIFT; |
| 1529 | granularity = lim->discard_granularity >> SECTOR_SHIFT; |
| 1530 | if (!granularity) |
| 1531 | return 0; |
| 1532 | |
| 1533 | /* Offset of the partition start in 'granularity' sectors */ |
| 1534 | offset = sector_div(sector, granularity); |
| 1535 | |
| 1536 | /* And why do we do this modulus *again* in blkdev_issue_discard()? */ |
| 1537 | offset = (granularity + alignment - offset) % granularity; |
| 1538 | |
| 1539 | /* Turn it back into bytes, gaah */ |
| 1540 | return offset << SECTOR_SHIFT; |
| 1541 | } |
| 1542 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1543 | /* |
| 1544 | * Two cases of handling DISCARD merge: |
| 1545 | * If max_discard_segments > 1, the driver takes every bio |
| 1546 | * as a range and send them to controller together. The ranges |
| 1547 | * needn't to be contiguous. |
| 1548 | * Otherwise, the bios/requests will be handled as same as |
| 1549 | * others which should be contiguous. |
| 1550 | */ |
| 1551 | static inline bool blk_discard_mergable(struct request *req) |
| 1552 | { |
| 1553 | if (req_op(req) == REQ_OP_DISCARD && |
| 1554 | queue_max_discard_segments(req->q) > 1) |
| 1555 | return true; |
| 1556 | return false; |
| 1557 | } |
| 1558 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1559 | static inline int bdev_discard_alignment(struct block_device *bdev) |
| 1560 | { |
| 1561 | struct request_queue *q = bdev_get_queue(bdev); |
| 1562 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1563 | if (bdev_is_partition(bdev)) |
| 1564 | return queue_limit_discard_alignment(&q->limits, |
| 1565 | bdev->bd_part->start_sect); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1566 | return q->limits.discard_alignment; |
| 1567 | } |
| 1568 | |
| 1569 | static inline unsigned int bdev_write_same(struct block_device *bdev) |
| 1570 | { |
| 1571 | struct request_queue *q = bdev_get_queue(bdev); |
| 1572 | |
| 1573 | if (q) |
| 1574 | return q->limits.max_write_same_sectors; |
| 1575 | |
| 1576 | return 0; |
| 1577 | } |
| 1578 | |
| 1579 | static inline unsigned int bdev_write_zeroes_sectors(struct block_device *bdev) |
| 1580 | { |
| 1581 | struct request_queue *q = bdev_get_queue(bdev); |
| 1582 | |
| 1583 | if (q) |
| 1584 | return q->limits.max_write_zeroes_sectors; |
| 1585 | |
| 1586 | return 0; |
| 1587 | } |
| 1588 | |
| 1589 | static inline enum blk_zoned_model bdev_zoned_model(struct block_device *bdev) |
| 1590 | { |
| 1591 | struct request_queue *q = bdev_get_queue(bdev); |
| 1592 | |
| 1593 | if (q) |
| 1594 | return blk_queue_zoned_model(q); |
| 1595 | |
| 1596 | return BLK_ZONED_NONE; |
| 1597 | } |
| 1598 | |
| 1599 | static inline bool bdev_is_zoned(struct block_device *bdev) |
| 1600 | { |
| 1601 | struct request_queue *q = bdev_get_queue(bdev); |
| 1602 | |
| 1603 | if (q) |
| 1604 | return blk_queue_is_zoned(q); |
| 1605 | |
| 1606 | return false; |
| 1607 | } |
| 1608 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1609 | static inline sector_t bdev_zone_sectors(struct block_device *bdev) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1610 | { |
| 1611 | struct request_queue *q = bdev_get_queue(bdev); |
| 1612 | |
| 1613 | if (q) |
| 1614 | return blk_queue_zone_sectors(q); |
| 1615 | return 0; |
| 1616 | } |
| 1617 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1618 | static inline unsigned int bdev_max_open_zones(struct block_device *bdev) |
| 1619 | { |
| 1620 | struct request_queue *q = bdev_get_queue(bdev); |
| 1621 | |
| 1622 | if (q) |
| 1623 | return queue_max_open_zones(q); |
| 1624 | return 0; |
| 1625 | } |
| 1626 | |
| 1627 | static inline unsigned int bdev_max_active_zones(struct block_device *bdev) |
| 1628 | { |
| 1629 | struct request_queue *q = bdev_get_queue(bdev); |
| 1630 | |
| 1631 | if (q) |
| 1632 | return queue_max_active_zones(q); |
| 1633 | return 0; |
| 1634 | } |
| 1635 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1636 | static inline int queue_dma_alignment(const struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1637 | { |
| 1638 | return q ? q->dma_alignment : 511; |
| 1639 | } |
| 1640 | |
| 1641 | static inline int blk_rq_aligned(struct request_queue *q, unsigned long addr, |
| 1642 | unsigned int len) |
| 1643 | { |
| 1644 | unsigned int alignment = queue_dma_alignment(q) | q->dma_pad_mask; |
| 1645 | return !(addr & alignment) && !(len & alignment); |
| 1646 | } |
| 1647 | |
| 1648 | /* assumes size > 256 */ |
| 1649 | static inline unsigned int blksize_bits(unsigned int size) |
| 1650 | { |
| 1651 | unsigned int bits = 8; |
| 1652 | do { |
| 1653 | bits++; |
| 1654 | size >>= 1; |
| 1655 | } while (size > 256); |
| 1656 | return bits; |
| 1657 | } |
| 1658 | |
| 1659 | static inline unsigned int block_size(struct block_device *bdev) |
| 1660 | { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1661 | return 1 << bdev->bd_inode->i_blkbits; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1662 | } |
| 1663 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1664 | int kblockd_schedule_work(struct work_struct *work); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1665 | int kblockd_mod_delayed_work_on(int cpu, struct delayed_work *dwork, unsigned long delay); |
| 1666 | |
| 1667 | #define MODULE_ALIAS_BLOCKDEV(major,minor) \ |
| 1668 | MODULE_ALIAS("block-major-" __stringify(major) "-" __stringify(minor)) |
| 1669 | #define MODULE_ALIAS_BLOCKDEV_MAJOR(major) \ |
| 1670 | MODULE_ALIAS("block-major-" __stringify(major) "-*") |
| 1671 | |
| 1672 | #if defined(CONFIG_BLK_DEV_INTEGRITY) |
| 1673 | |
| 1674 | enum blk_integrity_flags { |
| 1675 | BLK_INTEGRITY_VERIFY = 1 << 0, |
| 1676 | BLK_INTEGRITY_GENERATE = 1 << 1, |
| 1677 | BLK_INTEGRITY_DEVICE_CAPABLE = 1 << 2, |
| 1678 | BLK_INTEGRITY_IP_CHECKSUM = 1 << 3, |
| 1679 | }; |
| 1680 | |
| 1681 | struct blk_integrity_iter { |
| 1682 | void *prot_buf; |
| 1683 | void *data_buf; |
| 1684 | sector_t seed; |
| 1685 | unsigned int data_size; |
| 1686 | unsigned short interval; |
| 1687 | const char *disk_name; |
| 1688 | }; |
| 1689 | |
| 1690 | typedef blk_status_t (integrity_processing_fn) (struct blk_integrity_iter *); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1691 | typedef void (integrity_prepare_fn) (struct request *); |
| 1692 | typedef void (integrity_complete_fn) (struct request *, unsigned int); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1693 | |
| 1694 | struct blk_integrity_profile { |
| 1695 | integrity_processing_fn *generate_fn; |
| 1696 | integrity_processing_fn *verify_fn; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1697 | integrity_prepare_fn *prepare_fn; |
| 1698 | integrity_complete_fn *complete_fn; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1699 | const char *name; |
| 1700 | }; |
| 1701 | |
| 1702 | extern void blk_integrity_register(struct gendisk *, struct blk_integrity *); |
| 1703 | extern void blk_integrity_unregister(struct gendisk *); |
| 1704 | extern int blk_integrity_compare(struct gendisk *, struct gendisk *); |
| 1705 | extern int blk_rq_map_integrity_sg(struct request_queue *, struct bio *, |
| 1706 | struct scatterlist *); |
| 1707 | extern int blk_rq_count_integrity_sg(struct request_queue *, struct bio *); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1708 | |
| 1709 | static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk) |
| 1710 | { |
| 1711 | struct blk_integrity *bi = &disk->queue->integrity; |
| 1712 | |
| 1713 | if (!bi->profile) |
| 1714 | return NULL; |
| 1715 | |
| 1716 | return bi; |
| 1717 | } |
| 1718 | |
| 1719 | static inline |
| 1720 | struct blk_integrity *bdev_get_integrity(struct block_device *bdev) |
| 1721 | { |
| 1722 | return blk_get_integrity(bdev->bd_disk); |
| 1723 | } |
| 1724 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1725 | static inline bool |
| 1726 | blk_integrity_queue_supports_integrity(struct request_queue *q) |
| 1727 | { |
| 1728 | return q->integrity.profile; |
| 1729 | } |
| 1730 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1731 | static inline bool blk_integrity_rq(struct request *rq) |
| 1732 | { |
| 1733 | return rq->cmd_flags & REQ_INTEGRITY; |
| 1734 | } |
| 1735 | |
| 1736 | static inline void blk_queue_max_integrity_segments(struct request_queue *q, |
| 1737 | unsigned int segs) |
| 1738 | { |
| 1739 | q->limits.max_integrity_segments = segs; |
| 1740 | } |
| 1741 | |
| 1742 | static inline unsigned short |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1743 | queue_max_integrity_segments(const struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1744 | { |
| 1745 | return q->limits.max_integrity_segments; |
| 1746 | } |
| 1747 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1748 | /** |
| 1749 | * bio_integrity_intervals - Return number of integrity intervals for a bio |
| 1750 | * @bi: blk_integrity profile for device |
| 1751 | * @sectors: Size of the bio in 512-byte sectors |
| 1752 | * |
| 1753 | * Description: The block layer calculates everything in 512 byte |
| 1754 | * sectors but integrity metadata is done in terms of the data integrity |
| 1755 | * interval size of the storage device. Convert the block layer sectors |
| 1756 | * to the appropriate number of integrity intervals. |
| 1757 | */ |
| 1758 | static inline unsigned int bio_integrity_intervals(struct blk_integrity *bi, |
| 1759 | unsigned int sectors) |
| 1760 | { |
| 1761 | return sectors >> (bi->interval_exp - 9); |
| 1762 | } |
| 1763 | |
| 1764 | static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi, |
| 1765 | unsigned int sectors) |
| 1766 | { |
| 1767 | return bio_integrity_intervals(bi, sectors) * bi->tuple_size; |
| 1768 | } |
| 1769 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1770 | /* |
| 1771 | * Return the first bvec that contains integrity data. Only drivers that are |
| 1772 | * limited to a single integrity segment should use this helper. |
| 1773 | */ |
| 1774 | static inline struct bio_vec *rq_integrity_vec(struct request *rq) |
| 1775 | { |
| 1776 | if (WARN_ON_ONCE(queue_max_integrity_segments(rq->q) > 1)) |
| 1777 | return NULL; |
| 1778 | return rq->bio->bi_integrity->bip_vec; |
| 1779 | } |
| 1780 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1781 | #else /* CONFIG_BLK_DEV_INTEGRITY */ |
| 1782 | |
| 1783 | struct bio; |
| 1784 | struct block_device; |
| 1785 | struct gendisk; |
| 1786 | struct blk_integrity; |
| 1787 | |
| 1788 | static inline int blk_integrity_rq(struct request *rq) |
| 1789 | { |
| 1790 | return 0; |
| 1791 | } |
| 1792 | static inline int blk_rq_count_integrity_sg(struct request_queue *q, |
| 1793 | struct bio *b) |
| 1794 | { |
| 1795 | return 0; |
| 1796 | } |
| 1797 | static inline int blk_rq_map_integrity_sg(struct request_queue *q, |
| 1798 | struct bio *b, |
| 1799 | struct scatterlist *s) |
| 1800 | { |
| 1801 | return 0; |
| 1802 | } |
| 1803 | static inline struct blk_integrity *bdev_get_integrity(struct block_device *b) |
| 1804 | { |
| 1805 | return NULL; |
| 1806 | } |
| 1807 | static inline struct blk_integrity *blk_get_integrity(struct gendisk *disk) |
| 1808 | { |
| 1809 | return NULL; |
| 1810 | } |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1811 | static inline bool |
| 1812 | blk_integrity_queue_supports_integrity(struct request_queue *q) |
| 1813 | { |
| 1814 | return false; |
| 1815 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1816 | static inline int blk_integrity_compare(struct gendisk *a, struct gendisk *b) |
| 1817 | { |
| 1818 | return 0; |
| 1819 | } |
| 1820 | static inline void blk_integrity_register(struct gendisk *d, |
| 1821 | struct blk_integrity *b) |
| 1822 | { |
| 1823 | } |
| 1824 | static inline void blk_integrity_unregister(struct gendisk *d) |
| 1825 | { |
| 1826 | } |
| 1827 | static inline void blk_queue_max_integrity_segments(struct request_queue *q, |
| 1828 | unsigned int segs) |
| 1829 | { |
| 1830 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1831 | static inline unsigned short queue_max_integrity_segments(const struct request_queue *q) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1832 | { |
| 1833 | return 0; |
| 1834 | } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1835 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1836 | static inline unsigned int bio_integrity_intervals(struct blk_integrity *bi, |
| 1837 | unsigned int sectors) |
| 1838 | { |
| 1839 | return 0; |
| 1840 | } |
| 1841 | |
| 1842 | static inline unsigned int bio_integrity_bytes(struct blk_integrity *bi, |
| 1843 | unsigned int sectors) |
| 1844 | { |
| 1845 | return 0; |
| 1846 | } |
| 1847 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1848 | static inline struct bio_vec *rq_integrity_vec(struct request *rq) |
| 1849 | { |
| 1850 | return NULL; |
| 1851 | } |
| 1852 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1853 | #endif /* CONFIG_BLK_DEV_INTEGRITY */ |
| 1854 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1855 | #ifdef CONFIG_BLK_INLINE_ENCRYPTION |
| 1856 | |
| 1857 | bool blk_ksm_register(struct blk_keyslot_manager *ksm, struct request_queue *q); |
| 1858 | |
| 1859 | void blk_ksm_unregister(struct request_queue *q); |
| 1860 | |
| 1861 | #else /* CONFIG_BLK_INLINE_ENCRYPTION */ |
| 1862 | |
| 1863 | static inline bool blk_ksm_register(struct blk_keyslot_manager *ksm, |
| 1864 | struct request_queue *q) |
| 1865 | { |
| 1866 | return true; |
| 1867 | } |
| 1868 | |
| 1869 | static inline void blk_ksm_unregister(struct request_queue *q) { } |
| 1870 | |
| 1871 | #endif /* CONFIG_BLK_INLINE_ENCRYPTION */ |
| 1872 | |
| 1873 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1874 | struct block_device_operations { |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1875 | blk_qc_t (*submit_bio) (struct bio *bio); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1876 | int (*open) (struct block_device *, fmode_t); |
| 1877 | void (*release) (struct gendisk *, fmode_t); |
| 1878 | int (*rw_page)(struct block_device *, sector_t, struct page *, unsigned int); |
| 1879 | int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long); |
| 1880 | int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long); |
| 1881 | unsigned int (*check_events) (struct gendisk *disk, |
| 1882 | unsigned int clearing); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1883 | void (*unlock_native_capacity) (struct gendisk *); |
| 1884 | int (*revalidate_disk) (struct gendisk *); |
| 1885 | int (*getgeo)(struct block_device *, struct hd_geometry *); |
| 1886 | /* this callback is with swap_lock and sometimes page table lock held */ |
| 1887 | void (*swap_slot_free_notify) (struct block_device *, unsigned long); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1888 | int (*report_zones)(struct gendisk *, sector_t sector, |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1889 | unsigned int nr_zones, report_zones_cb cb, void *data); |
| 1890 | char *(*devnode)(struct gendisk *disk, umode_t *mode); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1891 | struct module *owner; |
| 1892 | const struct pr_ops *pr_ops; |
| 1893 | }; |
| 1894 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1895 | #ifdef CONFIG_COMPAT |
| 1896 | extern int blkdev_compat_ptr_ioctl(struct block_device *, fmode_t, |
| 1897 | unsigned int, unsigned long); |
| 1898 | #else |
| 1899 | #define blkdev_compat_ptr_ioctl NULL |
| 1900 | #endif |
| 1901 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1902 | extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int, |
| 1903 | unsigned long); |
| 1904 | extern int bdev_read_page(struct block_device *, sector_t, struct page *); |
| 1905 | extern int bdev_write_page(struct block_device *, sector_t, struct page *, |
| 1906 | struct writeback_control *); |
| 1907 | |
| 1908 | #ifdef CONFIG_BLK_DEV_ZONED |
| 1909 | bool blk_req_needs_zone_write_lock(struct request *rq); |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1910 | bool blk_req_zone_write_trylock(struct request *rq); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1911 | void __blk_req_zone_write_lock(struct request *rq); |
| 1912 | void __blk_req_zone_write_unlock(struct request *rq); |
| 1913 | |
| 1914 | static inline void blk_req_zone_write_lock(struct request *rq) |
| 1915 | { |
| 1916 | if (blk_req_needs_zone_write_lock(rq)) |
| 1917 | __blk_req_zone_write_lock(rq); |
| 1918 | } |
| 1919 | |
| 1920 | static inline void blk_req_zone_write_unlock(struct request *rq) |
| 1921 | { |
| 1922 | if (rq->rq_flags & RQF_ZONE_WRITE_LOCKED) |
| 1923 | __blk_req_zone_write_unlock(rq); |
| 1924 | } |
| 1925 | |
| 1926 | static inline bool blk_req_zone_is_write_locked(struct request *rq) |
| 1927 | { |
| 1928 | return rq->q->seq_zones_wlock && |
| 1929 | test_bit(blk_rq_zone_no(rq), rq->q->seq_zones_wlock); |
| 1930 | } |
| 1931 | |
| 1932 | static inline bool blk_req_can_dispatch_to_zone(struct request *rq) |
| 1933 | { |
| 1934 | if (!blk_req_needs_zone_write_lock(rq)) |
| 1935 | return true; |
| 1936 | return !blk_req_zone_is_write_locked(rq); |
| 1937 | } |
| 1938 | #else |
| 1939 | static inline bool blk_req_needs_zone_write_lock(struct request *rq) |
| 1940 | { |
| 1941 | return false; |
| 1942 | } |
| 1943 | |
| 1944 | static inline void blk_req_zone_write_lock(struct request *rq) |
| 1945 | { |
| 1946 | } |
| 1947 | |
| 1948 | static inline void blk_req_zone_write_unlock(struct request *rq) |
| 1949 | { |
| 1950 | } |
| 1951 | static inline bool blk_req_zone_is_write_locked(struct request *rq) |
| 1952 | { |
| 1953 | return false; |
| 1954 | } |
| 1955 | |
| 1956 | static inline bool blk_req_can_dispatch_to_zone(struct request *rq) |
| 1957 | { |
| 1958 | return true; |
| 1959 | } |
| 1960 | #endif /* CONFIG_BLK_DEV_ZONED */ |
| 1961 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 1962 | static inline void blk_wake_io_task(struct task_struct *waiter) |
| 1963 | { |
| 1964 | /* |
| 1965 | * If we're polling, the task itself is doing the completions. For |
| 1966 | * that case, we don't need to signal a wakeup, it's enough to just |
| 1967 | * mark us as RUNNING. |
| 1968 | */ |
| 1969 | if (waiter == current) |
| 1970 | __set_current_state(TASK_RUNNING); |
| 1971 | else |
| 1972 | wake_up_process(waiter); |
| 1973 | } |
| 1974 | |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 1975 | unsigned long disk_start_io_acct(struct gendisk *disk, unsigned int sectors, |
| 1976 | unsigned int op); |
| 1977 | void disk_end_io_acct(struct gendisk *disk, unsigned int op, |
| 1978 | unsigned long start_time); |
| 1979 | |
| 1980 | unsigned long part_start_io_acct(struct gendisk *disk, struct hd_struct **part, |
| 1981 | struct bio *bio); |
| 1982 | void part_end_io_acct(struct hd_struct *part, struct bio *bio, |
| 1983 | unsigned long start_time); |
| 1984 | |
| 1985 | /** |
| 1986 | * bio_start_io_acct - start I/O accounting for bio based drivers |
| 1987 | * @bio: bio to start account for |
| 1988 | * |
| 1989 | * Returns the start time that should be passed back to bio_end_io_acct(). |
| 1990 | */ |
| 1991 | static inline unsigned long bio_start_io_acct(struct bio *bio) |
| 1992 | { |
| 1993 | return disk_start_io_acct(bio->bi_disk, bio_sectors(bio), bio_op(bio)); |
| 1994 | } |
| 1995 | |
| 1996 | /** |
| 1997 | * bio_end_io_acct - end I/O accounting for bio based drivers |
| 1998 | * @bio: bio to end account for |
| 1999 | * @start: start time returned by bio_start_io_acct() |
| 2000 | */ |
| 2001 | static inline void bio_end_io_acct(struct bio *bio, unsigned long start_time) |
| 2002 | { |
| 2003 | return disk_end_io_acct(bio->bi_disk, bio_op(bio), start_time); |
| 2004 | } |
| 2005 | |
| 2006 | int bdev_read_only(struct block_device *bdev); |
| 2007 | int set_blocksize(struct block_device *bdev, int size); |
| 2008 | |
| 2009 | const char *bdevname(struct block_device *bdev, char *buffer); |
| 2010 | struct block_device *lookup_bdev(const char *); |
| 2011 | |
| 2012 | void blkdev_show(struct seq_file *seqf, off_t offset); |
| 2013 | |
| 2014 | #define BDEVNAME_SIZE 32 /* Largest string for a blockdev identifier */ |
| 2015 | #define BDEVT_SIZE 10 /* Largest string for MAJ:MIN for blkdev */ |
| 2016 | #ifdef CONFIG_BLOCK |
| 2017 | #define BLKDEV_MAJOR_MAX 512 |
| 2018 | #else |
| 2019 | #define BLKDEV_MAJOR_MAX 0 |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 2020 | #endif |
Olivier Deprez | 157378f | 2022-04-04 15:47:50 +0200 | [diff] [blame^] | 2021 | |
| 2022 | struct block_device *blkdev_get_by_path(const char *path, fmode_t mode, |
| 2023 | void *holder); |
| 2024 | struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder); |
| 2025 | int bd_prepare_to_claim(struct block_device *bdev, struct block_device *whole, |
| 2026 | void *holder); |
| 2027 | void bd_abort_claiming(struct block_device *bdev, struct block_device *whole, |
| 2028 | void *holder); |
| 2029 | void blkdev_put(struct block_device *bdev, fmode_t mode); |
| 2030 | |
| 2031 | struct block_device *I_BDEV(struct inode *inode); |
| 2032 | struct block_device *bdget_part(struct hd_struct *part); |
| 2033 | struct block_device *bdgrab(struct block_device *bdev); |
| 2034 | void bdput(struct block_device *); |
| 2035 | |
| 2036 | #ifdef CONFIG_BLOCK |
| 2037 | void invalidate_bdev(struct block_device *bdev); |
| 2038 | int truncate_bdev_range(struct block_device *bdev, fmode_t mode, loff_t lstart, |
| 2039 | loff_t lend); |
| 2040 | int sync_blockdev(struct block_device *bdev); |
| 2041 | #else |
| 2042 | static inline void invalidate_bdev(struct block_device *bdev) |
| 2043 | { |
| 2044 | } |
| 2045 | static inline int truncate_bdev_range(struct block_device *bdev, fmode_t mode, |
| 2046 | loff_t lstart, loff_t lend) |
| 2047 | { |
| 2048 | return 0; |
| 2049 | } |
| 2050 | static inline int sync_blockdev(struct block_device *bdev) |
| 2051 | { |
| 2052 | return 0; |
| 2053 | } |
| 2054 | #endif |
| 2055 | int fsync_bdev(struct block_device *bdev); |
| 2056 | |
| 2057 | struct super_block *freeze_bdev(struct block_device *bdev); |
| 2058 | int thaw_bdev(struct block_device *bdev, struct super_block *sb); |
| 2059 | |
| 2060 | #endif /* _LINUX_BLKDEV_H */ |