1 // SPDX-License-Identifier: GPL-2.0
3 * Functions related to setting various queue properties from drivers
5 #include <linux/kernel.h>
6 #include <linux/module.h>
7 #include <linux/init.h>
9 #include <linux/blkdev.h>
10 #include <linux/pagemap.h>
11 #include <linux/gcd.h>
12 #include <linux/lcm.h>
13 #include <linux/jiffies.h>
14 #include <linux/gfp.h>
15 #include <linux/dma-mapping.h>
20 void blk_queue_rq_timeout(struct request_queue *q, unsigned int timeout)
22 q->rq_timeout = timeout;
24 EXPORT_SYMBOL_GPL(blk_queue_rq_timeout);
27 * blk_set_default_limits - reset limits to default values
28 * @lim: the queue_limits structure to reset
31 * Returns a queue_limit struct to its default state.
33 void blk_set_default_limits(struct queue_limits *lim)
35 lim->bio_max_bytes = UINT_MAX;
36 lim->max_segments = BLK_MAX_SEGMENTS;
37 lim->max_discard_segments = 1;
38 lim->max_integrity_segments = 0;
39 lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK;
40 lim->virt_boundary_mask = 0;
41 lim->max_segment_size = BLK_MAX_SEGMENT_SIZE;
42 lim->max_sectors = lim->max_hw_sectors = BLK_SAFE_MAX_SECTORS;
43 lim->max_dev_sectors = 0;
44 lim->chunk_sectors = 0;
45 lim->max_write_same_sectors = 0;
46 lim->max_write_zeroes_sectors = 0;
47 lim->max_zone_append_sectors = 0;
48 lim->max_discard_sectors = 0;
49 lim->max_hw_discard_sectors = 0;
50 lim->discard_granularity = 0;
51 lim->discard_alignment = 0;
52 lim->discard_misaligned = 0;
53 lim->logical_block_size = lim->physical_block_size = lim->io_min = 512;
54 lim->bounce = BLK_BOUNCE_NONE;
55 lim->alignment_offset = 0;
58 lim->zoned = BLK_ZONED_NONE;
59 lim->zone_write_granularity = 0;
61 EXPORT_SYMBOL(blk_set_default_limits);
64 * blk_set_stacking_limits - set default limits for stacking devices
65 * @lim: the queue_limits structure to reset
68 * Returns a queue_limit struct to its default state. Should be used
69 * by stacking drivers like DM that have no internal limits.
71 void blk_set_stacking_limits(struct queue_limits *lim)
73 blk_set_default_limits(lim);
75 /* Inherit limits from component devices */
76 lim->max_segments = USHRT_MAX;
77 lim->max_discard_segments = USHRT_MAX;
78 lim->max_hw_sectors = UINT_MAX;
79 lim->max_segment_size = UINT_MAX;
80 lim->max_sectors = UINT_MAX;
81 lim->max_dev_sectors = UINT_MAX;
82 lim->max_write_same_sectors = UINT_MAX;
83 lim->max_write_zeroes_sectors = UINT_MAX;
84 lim->max_zone_append_sectors = UINT_MAX;
86 EXPORT_SYMBOL(blk_set_stacking_limits);
89 * blk_queue_bounce_limit - set bounce buffer limit for queue
90 * @q: the request queue for the device
91 * @bounce: bounce limit to enforce
94 * Force bouncing for ISA DMA ranges or highmem.
96 * DEPRECATED, don't use in new code.
98 void blk_queue_bounce_limit(struct request_queue *q, enum blk_bounce bounce)
100 q->limits.bounce = bounce;
102 EXPORT_SYMBOL(blk_queue_bounce_limit);
105 * blk_queue_max_hw_sectors - set max sectors for a request for this queue
106 * @q: the request queue for the device
107 * @max_hw_sectors: max hardware sectors in the usual 512b unit
110 * Enables a low level driver to set a hard upper limit,
111 * max_hw_sectors, on the size of requests. max_hw_sectors is set by
112 * the device driver based upon the capabilities of the I/O
115 * max_dev_sectors is a hard limit imposed by the storage device for
116 * READ/WRITE requests. It is set by the disk driver.
118 * max_sectors is a soft limit imposed by the block layer for
119 * filesystem type requests. This value can be overridden on a
120 * per-device basis in /sys/block/<device>/queue/max_sectors_kb.
121 * The soft limit can not exceed max_hw_sectors.
123 void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_sectors)
125 struct queue_limits *limits = &q->limits;
126 unsigned int max_sectors;
128 if ((max_hw_sectors << 9) < PAGE_SIZE) {
129 max_hw_sectors = 1 << (PAGE_SHIFT - 9);
130 printk(KERN_INFO "%s: set to minimum %d\n",
131 __func__, max_hw_sectors);
134 max_hw_sectors = round_down(max_hw_sectors,
135 limits->logical_block_size >> SECTOR_SHIFT);
136 limits->max_hw_sectors = max_hw_sectors;
138 max_sectors = min_not_zero(max_hw_sectors, limits->max_dev_sectors);
139 max_sectors = min_t(unsigned int, max_sectors, BLK_DEF_MAX_SECTORS);
140 max_sectors = round_down(max_sectors,
141 limits->logical_block_size >> SECTOR_SHIFT);
142 limits->max_sectors = max_sectors;
144 if (check_shl_overflow(max_sectors, SECTOR_SHIFT,
145 &limits->bio_max_bytes))
146 limits->bio_max_bytes = UINT_MAX;
148 q->backing_dev_info->io_pages = max_sectors >> (PAGE_SHIFT - 9);
150 EXPORT_SYMBOL(blk_queue_max_hw_sectors);
153 * blk_queue_chunk_sectors - set size of the chunk for this queue
154 * @q: the request queue for the device
155 * @chunk_sectors: chunk sectors in the usual 512b unit
158 * If a driver doesn't want IOs to cross a given chunk size, it can set
159 * this limit and prevent merging across chunks. Note that the block layer
160 * must accept a page worth of data at any offset. So if the crossing of
161 * chunks is a hard limitation in the driver, it must still be prepared
162 * to split single page bios.
164 void blk_queue_chunk_sectors(struct request_queue *q, unsigned int chunk_sectors)
166 q->limits.chunk_sectors = chunk_sectors;
168 EXPORT_SYMBOL(blk_queue_chunk_sectors);
171 * blk_queue_max_discard_sectors - set max sectors for a single discard
172 * @q: the request queue for the device
173 * @max_discard_sectors: maximum number of sectors to discard
175 void blk_queue_max_discard_sectors(struct request_queue *q,
176 unsigned int max_discard_sectors)
178 q->limits.max_hw_discard_sectors = max_discard_sectors;
179 q->limits.max_discard_sectors = max_discard_sectors;
181 EXPORT_SYMBOL(blk_queue_max_discard_sectors);
184 * blk_queue_max_write_same_sectors - set max sectors for a single write same
185 * @q: the request queue for the device
186 * @max_write_same_sectors: maximum number of sectors to write per command
188 void blk_queue_max_write_same_sectors(struct request_queue *q,
189 unsigned int max_write_same_sectors)
191 q->limits.max_write_same_sectors = max_write_same_sectors;
193 EXPORT_SYMBOL(blk_queue_max_write_same_sectors);
196 * blk_queue_max_write_zeroes_sectors - set max sectors for a single
198 * @q: the request queue for the device
199 * @max_write_zeroes_sectors: maximum number of sectors to write per command
201 void blk_queue_max_write_zeroes_sectors(struct request_queue *q,
202 unsigned int max_write_zeroes_sectors)
204 q->limits.max_write_zeroes_sectors = max_write_zeroes_sectors;
206 EXPORT_SYMBOL(blk_queue_max_write_zeroes_sectors);
209 * blk_queue_max_zone_append_sectors - set max sectors for a single zone append
210 * @q: the request queue for the device
211 * @max_zone_append_sectors: maximum number of sectors to write per command
213 void blk_queue_max_zone_append_sectors(struct request_queue *q,
214 unsigned int max_zone_append_sectors)
216 unsigned int max_sectors;
218 if (WARN_ON(!blk_queue_is_zoned(q)))
221 max_sectors = min(q->limits.max_hw_sectors, max_zone_append_sectors);
222 max_sectors = min(q->limits.chunk_sectors, max_sectors);
225 * Signal eventual driver bugs resulting in the max_zone_append sectors limit
226 * being 0 due to a 0 argument, the chunk_sectors limit (zone size) not set,
227 * or the max_hw_sectors limit not set.
229 WARN_ON(!max_sectors);
231 q->limits.max_zone_append_sectors = max_sectors;
233 EXPORT_SYMBOL_GPL(blk_queue_max_zone_append_sectors);
236 * blk_queue_max_segments - set max hw segments for a request for this queue
237 * @q: the request queue for the device
238 * @max_segments: max number of segments
241 * Enables a low level driver to set an upper limit on the number of
242 * hw data segments in a request.
244 void blk_queue_max_segments(struct request_queue *q, unsigned short max_segments)
248 printk(KERN_INFO "%s: set to minimum %d\n",
249 __func__, max_segments);
252 q->limits.max_segments = max_segments;
254 EXPORT_SYMBOL(blk_queue_max_segments);
257 * blk_queue_max_discard_segments - set max segments for discard requests
258 * @q: the request queue for the device
259 * @max_segments: max number of segments
262 * Enables a low level driver to set an upper limit on the number of
263 * segments in a discard request.
265 void blk_queue_max_discard_segments(struct request_queue *q,
266 unsigned short max_segments)
268 q->limits.max_discard_segments = max_segments;
270 EXPORT_SYMBOL_GPL(blk_queue_max_discard_segments);
273 * blk_queue_max_segment_size - set max segment size for blk_rq_map_sg
274 * @q: the request queue for the device
275 * @max_size: max size of segment in bytes
278 * Enables a low level driver to set an upper limit on the size of a
281 void blk_queue_max_segment_size(struct request_queue *q, unsigned int max_size)
283 if (max_size < PAGE_SIZE) {
284 max_size = PAGE_SIZE;
285 printk(KERN_INFO "%s: set to minimum %d\n",
289 /* see blk_queue_virt_boundary() for the explanation */
290 WARN_ON_ONCE(q->limits.virt_boundary_mask);
292 q->limits.max_segment_size = max_size;
294 EXPORT_SYMBOL(blk_queue_max_segment_size);
297 * blk_queue_logical_block_size - set logical block size for the queue
298 * @q: the request queue for the device
299 * @size: the logical block size, in bytes
302 * This should be set to the lowest possible block size that the
303 * storage device can address. The default of 512 covers most
306 void blk_queue_logical_block_size(struct request_queue *q, unsigned int size)
308 struct queue_limits *limits = &q->limits;
310 limits->logical_block_size = size;
312 if (limits->physical_block_size < size)
313 limits->physical_block_size = size;
315 if (limits->io_min < limits->physical_block_size)
316 limits->io_min = limits->physical_block_size;
318 limits->max_hw_sectors =
319 round_down(limits->max_hw_sectors, size >> SECTOR_SHIFT);
320 limits->max_sectors =
321 round_down(limits->max_sectors, size >> SECTOR_SHIFT);
323 EXPORT_SYMBOL(blk_queue_logical_block_size);
326 * blk_queue_physical_block_size - set physical block size for the queue
327 * @q: the request queue for the device
328 * @size: the physical block size, in bytes
331 * This should be set to the lowest possible sector size that the
332 * hardware can operate on without reverting to read-modify-write
335 void blk_queue_physical_block_size(struct request_queue *q, unsigned int size)
337 q->limits.physical_block_size = size;
339 if (q->limits.physical_block_size < q->limits.logical_block_size)
340 q->limits.physical_block_size = q->limits.logical_block_size;
342 if (q->limits.io_min < q->limits.physical_block_size)
343 q->limits.io_min = q->limits.physical_block_size;
345 EXPORT_SYMBOL(blk_queue_physical_block_size);
348 * blk_queue_zone_write_granularity - set zone write granularity for the queue
349 * @q: the request queue for the zoned device
350 * @size: the zone write granularity size, in bytes
353 * This should be set to the lowest possible size allowing to write in
354 * sequential zones of a zoned block device.
356 void blk_queue_zone_write_granularity(struct request_queue *q,
359 if (WARN_ON_ONCE(!blk_queue_is_zoned(q)))
362 q->limits.zone_write_granularity = size;
364 if (q->limits.zone_write_granularity < q->limits.logical_block_size)
365 q->limits.zone_write_granularity = q->limits.logical_block_size;
367 EXPORT_SYMBOL_GPL(blk_queue_zone_write_granularity);
370 * blk_queue_alignment_offset - set physical block alignment offset
371 * @q: the request queue for the device
372 * @offset: alignment offset in bytes
375 * Some devices are naturally misaligned to compensate for things like
376 * the legacy DOS partition table 63-sector offset. Low-level drivers
377 * should call this function for devices whose first sector is not
380 void blk_queue_alignment_offset(struct request_queue *q, unsigned int offset)
382 q->limits.alignment_offset =
383 offset & (q->limits.physical_block_size - 1);
384 q->limits.misaligned = 0;
386 EXPORT_SYMBOL(blk_queue_alignment_offset);
388 void blk_queue_update_readahead(struct request_queue *q)
391 * For read-ahead of large files to be effective, we need to read ahead
392 * at least twice the optimal I/O size.
394 q->backing_dev_info->ra_pages =
395 max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES);
396 q->backing_dev_info->io_pages =
397 queue_max_sectors(q) >> (PAGE_SHIFT - 9);
399 EXPORT_SYMBOL_GPL(blk_queue_update_readahead);
402 * blk_limits_io_min - set minimum request size for a device
403 * @limits: the queue limits
404 * @min: smallest I/O size in bytes
407 * Some devices have an internal block size bigger than the reported
408 * hardware sector size. This function can be used to signal the
409 * smallest I/O the device can perform without incurring a performance
412 void blk_limits_io_min(struct queue_limits *limits, unsigned int min)
414 limits->io_min = min;
416 if (limits->io_min < limits->logical_block_size)
417 limits->io_min = limits->logical_block_size;
419 if (limits->io_min < limits->physical_block_size)
420 limits->io_min = limits->physical_block_size;
422 EXPORT_SYMBOL(blk_limits_io_min);
425 * blk_queue_io_min - set minimum request size for the queue
426 * @q: the request queue for the device
427 * @min: smallest I/O size in bytes
430 * Storage devices may report a granularity or preferred minimum I/O
431 * size which is the smallest request the device can perform without
432 * incurring a performance penalty. For disk drives this is often the
433 * physical block size. For RAID arrays it is often the stripe chunk
434 * size. A properly aligned multiple of minimum_io_size is the
435 * preferred request size for workloads where a high number of I/O
436 * operations is desired.
438 void blk_queue_io_min(struct request_queue *q, unsigned int min)
440 blk_limits_io_min(&q->limits, min);
442 EXPORT_SYMBOL(blk_queue_io_min);
445 * blk_limits_io_opt - set optimal request size for a device
446 * @limits: the queue limits
447 * @opt: smallest I/O size in bytes
450 * Storage devices may report an optimal I/O size, which is the
451 * device's preferred unit for sustained I/O. This is rarely reported
452 * for disk drives. For RAID arrays it is usually the stripe width or
453 * the internal track size. A properly aligned multiple of
454 * optimal_io_size is the preferred request size for workloads where
455 * sustained throughput is desired.
457 void blk_limits_io_opt(struct queue_limits *limits, unsigned int opt)
459 limits->io_opt = opt;
461 EXPORT_SYMBOL(blk_limits_io_opt);
464 * blk_queue_io_opt - set optimal request size for the queue
465 * @q: the request queue for the device
466 * @opt: optimal request size in bytes
469 * Storage devices may report an optimal I/O size, which is the
470 * device's preferred unit for sustained I/O. This is rarely reported
471 * for disk drives. For RAID arrays it is usually the stripe width or
472 * the internal track size. A properly aligned multiple of
473 * optimal_io_size is the preferred request size for workloads where
474 * sustained throughput is desired.
476 void blk_queue_io_opt(struct request_queue *q, unsigned int opt)
478 blk_limits_io_opt(&q->limits, opt);
479 q->backing_dev_info->ra_pages =
480 max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES);
482 EXPORT_SYMBOL(blk_queue_io_opt);
484 static unsigned int blk_round_down_sectors(unsigned int sectors, unsigned int lbs)
486 sectors = round_down(sectors, lbs >> SECTOR_SHIFT);
487 if (sectors < PAGE_SIZE >> SECTOR_SHIFT)
488 sectors = PAGE_SIZE >> SECTOR_SHIFT;
493 * blk_stack_limits - adjust queue_limits for stacked devices
494 * @t: the stacking driver limits (top device)
495 * @b: the underlying queue limits (bottom, component device)
496 * @start: first data sector within component device
499 * This function is used by stacking drivers like MD and DM to ensure
500 * that all component devices have compatible block sizes and
501 * alignments. The stacking driver must provide a queue_limits
502 * struct (top) and then iteratively call the stacking function for
503 * all component (bottom) devices. The stacking function will
504 * attempt to combine the values and ensure proper alignment.
506 * Returns 0 if the top and bottom queue_limits are compatible. The
507 * top device's block sizes and alignment offsets may be adjusted to
508 * ensure alignment with the bottom device. If no compatible sizes
509 * and alignments exist, -1 is returned and the resulting top
510 * queue_limits will have the misaligned flag set to indicate that
511 * the alignment_offset is undefined.
513 int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
516 unsigned int top, bottom, alignment, ret = 0;
518 t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors);
519 t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors);
520 t->max_dev_sectors = min_not_zero(t->max_dev_sectors, b->max_dev_sectors);
521 t->max_write_same_sectors = min(t->max_write_same_sectors,
522 b->max_write_same_sectors);
523 t->max_write_zeroes_sectors = min(t->max_write_zeroes_sectors,
524 b->max_write_zeroes_sectors);
525 t->max_zone_append_sectors = min(t->max_zone_append_sectors,
526 b->max_zone_append_sectors);
527 t->bounce = max(t->bounce, b->bounce);
529 t->seg_boundary_mask = min_not_zero(t->seg_boundary_mask,
530 b->seg_boundary_mask);
531 t->virt_boundary_mask = min_not_zero(t->virt_boundary_mask,
532 b->virt_boundary_mask);
534 t->max_segments = min_not_zero(t->max_segments, b->max_segments);
535 t->max_discard_segments = min_not_zero(t->max_discard_segments,
536 b->max_discard_segments);
537 t->max_integrity_segments = min_not_zero(t->max_integrity_segments,
538 b->max_integrity_segments);
540 t->max_segment_size = min_not_zero(t->max_segment_size,
541 b->max_segment_size);
543 t->misaligned |= b->misaligned;
545 alignment = queue_limit_alignment_offset(b, start);
547 /* Bottom device has different alignment. Check that it is
548 * compatible with the current top alignment.
550 if (t->alignment_offset != alignment) {
552 top = max(t->physical_block_size, t->io_min)
553 + t->alignment_offset;
554 bottom = max(b->physical_block_size, b->io_min) + alignment;
556 /* Verify that top and bottom intervals line up */
557 if (max(top, bottom) % min(top, bottom)) {
563 t->logical_block_size = max(t->logical_block_size,
564 b->logical_block_size);
566 t->physical_block_size = max(t->physical_block_size,
567 b->physical_block_size);
569 t->io_min = max(t->io_min, b->io_min);
570 t->io_opt = lcm_not_zero(t->io_opt, b->io_opt);
572 /* Set non-power-of-2 compatible chunk_sectors boundary */
573 if (b->chunk_sectors)
574 t->chunk_sectors = gcd(t->chunk_sectors, b->chunk_sectors);
576 /* Physical block size a multiple of the logical block size? */
577 if (t->physical_block_size & (t->logical_block_size - 1)) {
578 t->physical_block_size = t->logical_block_size;
583 /* Minimum I/O a multiple of the physical block size? */
584 if (t->io_min & (t->physical_block_size - 1)) {
585 t->io_min = t->physical_block_size;
590 /* Optimal I/O a multiple of the physical block size? */
591 if (t->io_opt & (t->physical_block_size - 1)) {
597 /* chunk_sectors a multiple of the physical block size? */
598 if ((t->chunk_sectors << 9) & (t->physical_block_size - 1)) {
599 t->chunk_sectors = 0;
604 t->raid_partial_stripes_expensive =
605 max(t->raid_partial_stripes_expensive,
606 b->raid_partial_stripes_expensive);
608 /* Find lowest common alignment_offset */
609 t->alignment_offset = lcm_not_zero(t->alignment_offset, alignment)
610 % max(t->physical_block_size, t->io_min);
612 /* Verify that new alignment_offset is on a logical block boundary */
613 if (t->alignment_offset & (t->logical_block_size - 1)) {
618 t->max_sectors = blk_round_down_sectors(t->max_sectors, t->logical_block_size);
619 t->max_hw_sectors = blk_round_down_sectors(t->max_hw_sectors, t->logical_block_size);
620 t->max_dev_sectors = blk_round_down_sectors(t->max_dev_sectors, t->logical_block_size);
622 /* Discard alignment and granularity */
623 if (b->discard_granularity) {
624 alignment = queue_limit_discard_alignment(b, start);
626 if (t->discard_granularity != 0 &&
627 t->discard_alignment != alignment) {
628 top = t->discard_granularity + t->discard_alignment;
629 bottom = b->discard_granularity + alignment;
631 /* Verify that top and bottom intervals line up */
632 if ((max(top, bottom) % min(top, bottom)) != 0)
633 t->discard_misaligned = 1;
636 t->max_discard_sectors = min_not_zero(t->max_discard_sectors,
637 b->max_discard_sectors);
638 t->max_hw_discard_sectors = min_not_zero(t->max_hw_discard_sectors,
639 b->max_hw_discard_sectors);
640 t->discard_granularity = max(t->discard_granularity,
641 b->discard_granularity);
642 t->discard_alignment = lcm_not_zero(t->discard_alignment, alignment) %
643 t->discard_granularity;
646 t->zone_write_granularity = max(t->zone_write_granularity,
647 b->zone_write_granularity);
648 t->zoned = max(t->zoned, b->zoned);
651 EXPORT_SYMBOL(blk_stack_limits);
654 * disk_stack_limits - adjust queue limits for stacked drivers
655 * @disk: MD/DM gendisk (top)
656 * @bdev: the underlying block device (bottom)
657 * @offset: offset to beginning of data within component device
660 * Merges the limits for a top level gendisk and a bottom level
663 void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
666 struct request_queue *t = disk->queue;
668 if (blk_stack_limits(&t->limits, &bdev_get_queue(bdev)->limits,
669 get_start_sect(bdev) + (offset >> 9)) < 0) {
670 char top[BDEVNAME_SIZE], bottom[BDEVNAME_SIZE];
672 disk_name(disk, 0, top);
673 bdevname(bdev, bottom);
675 printk(KERN_NOTICE "%s: Warning: Device %s is misaligned\n",
679 blk_queue_update_readahead(disk->queue);
681 EXPORT_SYMBOL(disk_stack_limits);
684 * blk_queue_update_dma_pad - update pad mask
685 * @q: the request queue for the device
688 * Update dma pad mask.
690 * Appending pad buffer to a request modifies the last entry of a
691 * scatter list such that it includes the pad buffer.
693 void blk_queue_update_dma_pad(struct request_queue *q, unsigned int mask)
695 if (mask > q->dma_pad_mask)
696 q->dma_pad_mask = mask;
698 EXPORT_SYMBOL(blk_queue_update_dma_pad);
701 * blk_queue_segment_boundary - set boundary rules for segment merging
702 * @q: the request queue for the device
703 * @mask: the memory boundary mask
705 void blk_queue_segment_boundary(struct request_queue *q, unsigned long mask)
707 if (mask < PAGE_SIZE - 1) {
708 mask = PAGE_SIZE - 1;
709 printk(KERN_INFO "%s: set to minimum %lx\n",
713 q->limits.seg_boundary_mask = mask;
715 EXPORT_SYMBOL(blk_queue_segment_boundary);
718 * blk_queue_virt_boundary - set boundary rules for bio merging
719 * @q: the request queue for the device
720 * @mask: the memory boundary mask
722 void blk_queue_virt_boundary(struct request_queue *q, unsigned long mask)
724 q->limits.virt_boundary_mask = mask;
727 * Devices that require a virtual boundary do not support scatter/gather
728 * I/O natively, but instead require a descriptor list entry for each
729 * page (which might not be idential to the Linux PAGE_SIZE). Because
730 * of that they are not limited by our notion of "segment size".
733 q->limits.max_segment_size = UINT_MAX;
735 EXPORT_SYMBOL(blk_queue_virt_boundary);
738 * blk_queue_dma_alignment - set dma length and memory alignment
739 * @q: the request queue for the device
740 * @mask: alignment mask
743 * set required memory and length alignment for direct dma transactions.
744 * this is used when building direct io requests for the queue.
747 void blk_queue_dma_alignment(struct request_queue *q, int mask)
749 q->dma_alignment = mask;
751 EXPORT_SYMBOL(blk_queue_dma_alignment);
754 * blk_queue_update_dma_alignment - update dma length and memory alignment
755 * @q: the request queue for the device
756 * @mask: alignment mask
759 * update required memory and length alignment for direct dma transactions.
760 * If the requested alignment is larger than the current alignment, then
761 * the current queue alignment is updated to the new value, otherwise it
762 * is left alone. The design of this is to allow multiple objects
763 * (driver, device, transport etc) to set their respective
764 * alignments without having them interfere.
767 void blk_queue_update_dma_alignment(struct request_queue *q, int mask)
769 BUG_ON(mask > PAGE_SIZE);
771 if (mask > q->dma_alignment)
772 q->dma_alignment = mask;
774 EXPORT_SYMBOL(blk_queue_update_dma_alignment);
777 * blk_set_queue_depth - tell the block layer about the device queue depth
778 * @q: the request queue for the device
779 * @depth: queue depth
782 void blk_set_queue_depth(struct request_queue *q, unsigned int depth)
784 q->queue_depth = depth;
785 rq_qos_queue_depth_changed(q);
787 EXPORT_SYMBOL(blk_set_queue_depth);
790 * blk_queue_write_cache - configure queue's write cache
791 * @q: the request queue for the device
792 * @wc: write back cache on or off
793 * @fua: device supports FUA writes, if true
795 * Tell the block layer about the write cache of @q.
797 void blk_queue_write_cache(struct request_queue *q, bool wc, bool fua)
800 blk_queue_flag_set(QUEUE_FLAG_WC, q);
802 blk_queue_flag_clear(QUEUE_FLAG_WC, q);
804 blk_queue_flag_set(QUEUE_FLAG_FUA, q);
806 blk_queue_flag_clear(QUEUE_FLAG_FUA, q);
808 wbt_set_write_cache(q, test_bit(QUEUE_FLAG_WC, &q->queue_flags));
810 EXPORT_SYMBOL_GPL(blk_queue_write_cache);
813 * blk_queue_required_elevator_features - Set a queue required elevator features
814 * @q: the request queue for the target device
815 * @features: Required elevator features OR'ed together
817 * Tell the block layer that for the device controlled through @q, only the
818 * only elevators that can be used are those that implement at least the set of
819 * features specified by @features.
821 void blk_queue_required_elevator_features(struct request_queue *q,
822 unsigned int features)
824 q->required_elevator_features = features;
826 EXPORT_SYMBOL_GPL(blk_queue_required_elevator_features);
829 * blk_queue_can_use_dma_map_merging - configure queue for merging segments.
830 * @q: the request queue for the device
831 * @dev: the device pointer for dma
833 * Tell the block layer about merging the segments by dma map of @q.
835 bool blk_queue_can_use_dma_map_merging(struct request_queue *q,
838 unsigned long boundary = dma_get_merge_boundary(dev);
843 /* No need to update max_segment_size. see blk_queue_virt_boundary() */
844 blk_queue_virt_boundary(q, boundary);
848 EXPORT_SYMBOL_GPL(blk_queue_can_use_dma_map_merging);
851 * blk_queue_set_zoned - configure a disk queue zoned model.
852 * @disk: the gendisk of the queue to configure
853 * @model: the zoned model to set
855 * Set the zoned model of the request queue of @disk according to @model.
856 * When @model is BLK_ZONED_HM (host managed), this should be called only
857 * if zoned block device support is enabled (CONFIG_BLK_DEV_ZONED option).
858 * If @model specifies BLK_ZONED_HA (host aware), the effective model used
859 * depends on CONFIG_BLK_DEV_ZONED settings and on the existence of partitions
862 void blk_queue_set_zoned(struct gendisk *disk, enum blk_zoned_model model)
864 struct request_queue *q = disk->queue;
869 * Host managed devices are supported only if
870 * CONFIG_BLK_DEV_ZONED is enabled.
872 WARN_ON_ONCE(!IS_ENABLED(CONFIG_BLK_DEV_ZONED));
876 * Host aware devices can be treated either as regular block
877 * devices (similar to drive managed devices) or as zoned block
878 * devices to take advantage of the zone command set, similarly
879 * to host managed devices. We try the latter if there are no
880 * partitions and zoned block device support is enabled, else
881 * we do nothing special as far as the block layer is concerned.
883 if (!IS_ENABLED(CONFIG_BLK_DEV_ZONED) ||
884 !xa_empty(&disk->part_tbl))
885 model = BLK_ZONED_NONE;
889 if (WARN_ON_ONCE(model != BLK_ZONED_NONE))
890 model = BLK_ZONED_NONE;
894 q->limits.zoned = model;
895 if (model != BLK_ZONED_NONE) {
897 * Set the zone write granularity to the device logical block
898 * size by default. The driver can change this value if needed.
900 blk_queue_zone_write_granularity(q,
901 queue_logical_block_size(q));
903 blk_queue_clear_zone_settings(q);
906 EXPORT_SYMBOL_GPL(blk_queue_set_zoned);