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/gcd.h>
11 #include <linux/lcm.h>
12 #include <linux/jiffies.h>
13 #include <linux/gfp.h>
14 #include <linux/dma-mapping.h>
19 void blk_queue_rq_timeout(struct request_queue *q, unsigned int timeout)
21 q->rq_timeout = timeout;
23 EXPORT_SYMBOL_GPL(blk_queue_rq_timeout);
26 * blk_set_default_limits - reset limits to default values
27 * @lim: the queue_limits structure to reset
30 * Returns a queue_limit struct to its default state.
32 void blk_set_default_limits(struct queue_limits *lim)
34 lim->max_segments = BLK_MAX_SEGMENTS;
35 lim->max_discard_segments = 1;
36 lim->max_integrity_segments = 0;
37 lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK;
38 lim->virt_boundary_mask = 0;
39 lim->max_segment_size = BLK_MAX_SEGMENT_SIZE;
40 lim->max_sectors = lim->max_hw_sectors = BLK_SAFE_MAX_SECTORS;
41 lim->max_dev_sectors = 0;
42 lim->chunk_sectors = 0;
43 lim->max_write_same_sectors = 0;
44 lim->max_write_zeroes_sectors = 0;
45 lim->max_zone_append_sectors = 0;
46 lim->max_discard_sectors = 0;
47 lim->max_hw_discard_sectors = 0;
48 lim->discard_granularity = 0;
49 lim->discard_alignment = 0;
50 lim->discard_misaligned = 0;
51 lim->logical_block_size = lim->physical_block_size = lim->io_min = 512;
52 lim->bounce = BLK_BOUNCE_NONE;
53 lim->alignment_offset = 0;
56 lim->zoned = BLK_ZONED_NONE;
57 lim->zone_write_granularity = 0;
59 EXPORT_SYMBOL(blk_set_default_limits);
62 * blk_set_stacking_limits - set default limits for stacking devices
63 * @lim: the queue_limits structure to reset
66 * Returns a queue_limit struct to its default state. Should be used
67 * by stacking drivers like DM that have no internal limits.
69 void blk_set_stacking_limits(struct queue_limits *lim)
71 blk_set_default_limits(lim);
73 /* Inherit limits from component devices */
74 lim->max_segments = USHRT_MAX;
75 lim->max_discard_segments = USHRT_MAX;
76 lim->max_hw_sectors = UINT_MAX;
77 lim->max_segment_size = UINT_MAX;
78 lim->max_sectors = UINT_MAX;
79 lim->max_dev_sectors = UINT_MAX;
80 lim->max_write_same_sectors = UINT_MAX;
81 lim->max_write_zeroes_sectors = UINT_MAX;
82 lim->max_zone_append_sectors = UINT_MAX;
84 EXPORT_SYMBOL(blk_set_stacking_limits);
87 * blk_queue_bounce_limit - set bounce buffer limit for queue
88 * @q: the request queue for the device
89 * @bounce: bounce limit to enforce
92 * Force bouncing for ISA DMA ranges or highmem.
94 * DEPRECATED, don't use in new code.
96 void blk_queue_bounce_limit(struct request_queue *q, enum blk_bounce bounce)
98 q->limits.bounce = bounce;
100 EXPORT_SYMBOL(blk_queue_bounce_limit);
103 * blk_queue_max_hw_sectors - set max sectors for a request for this queue
104 * @q: the request queue for the device
105 * @max_hw_sectors: max hardware sectors in the usual 512b unit
108 * Enables a low level driver to set a hard upper limit,
109 * max_hw_sectors, on the size of requests. max_hw_sectors is set by
110 * the device driver based upon the capabilities of the I/O
113 * max_dev_sectors is a hard limit imposed by the storage device for
114 * READ/WRITE requests. It is set by the disk driver.
116 * max_sectors is a soft limit imposed by the block layer for
117 * filesystem type requests. This value can be overridden on a
118 * per-device basis in /sys/block/<device>/queue/max_sectors_kb.
119 * The soft limit can not exceed max_hw_sectors.
121 void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_sectors)
123 struct queue_limits *limits = &q->limits;
124 unsigned int max_sectors;
126 if ((max_hw_sectors << 9) < PAGE_SIZE) {
127 max_hw_sectors = 1 << (PAGE_SHIFT - 9);
128 printk(KERN_INFO "%s: set to minimum %d\n",
129 __func__, max_hw_sectors);
132 max_hw_sectors = round_down(max_hw_sectors,
133 limits->logical_block_size >> SECTOR_SHIFT);
134 limits->max_hw_sectors = max_hw_sectors;
136 max_sectors = min_not_zero(max_hw_sectors, limits->max_dev_sectors);
137 max_sectors = min_t(unsigned int, max_sectors, BLK_DEF_MAX_SECTORS);
138 max_sectors = round_down(max_sectors,
139 limits->logical_block_size >> SECTOR_SHIFT);
140 limits->max_sectors = max_sectors;
142 q->backing_dev_info->io_pages = max_sectors >> (PAGE_SHIFT - 9);
144 EXPORT_SYMBOL(blk_queue_max_hw_sectors);
147 * blk_queue_chunk_sectors - set size of the chunk for this queue
148 * @q: the request queue for the device
149 * @chunk_sectors: chunk sectors in the usual 512b unit
152 * If a driver doesn't want IOs to cross a given chunk size, it can set
153 * this limit and prevent merging across chunks. Note that the block layer
154 * must accept a page worth of data at any offset. So if the crossing of
155 * chunks is a hard limitation in the driver, it must still be prepared
156 * to split single page bios.
158 void blk_queue_chunk_sectors(struct request_queue *q, unsigned int chunk_sectors)
160 q->limits.chunk_sectors = chunk_sectors;
162 EXPORT_SYMBOL(blk_queue_chunk_sectors);
165 * blk_queue_max_discard_sectors - set max sectors for a single discard
166 * @q: the request queue for the device
167 * @max_discard_sectors: maximum number of sectors to discard
169 void blk_queue_max_discard_sectors(struct request_queue *q,
170 unsigned int max_discard_sectors)
172 q->limits.max_hw_discard_sectors = max_discard_sectors;
173 q->limits.max_discard_sectors = max_discard_sectors;
175 EXPORT_SYMBOL(blk_queue_max_discard_sectors);
178 * blk_queue_max_write_same_sectors - set max sectors for a single write same
179 * @q: the request queue for the device
180 * @max_write_same_sectors: maximum number of sectors to write per command
182 void blk_queue_max_write_same_sectors(struct request_queue *q,
183 unsigned int max_write_same_sectors)
185 q->limits.max_write_same_sectors = max_write_same_sectors;
187 EXPORT_SYMBOL(blk_queue_max_write_same_sectors);
190 * blk_queue_max_write_zeroes_sectors - set max sectors for a single
192 * @q: the request queue for the device
193 * @max_write_zeroes_sectors: maximum number of sectors to write per command
195 void blk_queue_max_write_zeroes_sectors(struct request_queue *q,
196 unsigned int max_write_zeroes_sectors)
198 q->limits.max_write_zeroes_sectors = max_write_zeroes_sectors;
200 EXPORT_SYMBOL(blk_queue_max_write_zeroes_sectors);
203 * blk_queue_max_zone_append_sectors - set max sectors for a single zone append
204 * @q: the request queue for the device
205 * @max_zone_append_sectors: maximum number of sectors to write per command
207 void blk_queue_max_zone_append_sectors(struct request_queue *q,
208 unsigned int max_zone_append_sectors)
210 unsigned int max_sectors;
212 if (WARN_ON(!blk_queue_is_zoned(q)))
215 max_sectors = min(q->limits.max_hw_sectors, max_zone_append_sectors);
216 max_sectors = min(q->limits.chunk_sectors, max_sectors);
219 * Signal eventual driver bugs resulting in the max_zone_append sectors limit
220 * being 0 due to a 0 argument, the chunk_sectors limit (zone size) not set,
221 * or the max_hw_sectors limit not set.
223 WARN_ON(!max_sectors);
225 q->limits.max_zone_append_sectors = max_sectors;
227 EXPORT_SYMBOL_GPL(blk_queue_max_zone_append_sectors);
230 * blk_queue_max_segments - set max hw segments for a request for this queue
231 * @q: the request queue for the device
232 * @max_segments: max number of segments
235 * Enables a low level driver to set an upper limit on the number of
236 * hw data segments in a request.
238 void blk_queue_max_segments(struct request_queue *q, unsigned short max_segments)
242 printk(KERN_INFO "%s: set to minimum %d\n",
243 __func__, max_segments);
246 q->limits.max_segments = max_segments;
248 EXPORT_SYMBOL(blk_queue_max_segments);
251 * blk_queue_max_discard_segments - set max segments for discard requests
252 * @q: the request queue for the device
253 * @max_segments: max number of segments
256 * Enables a low level driver to set an upper limit on the number of
257 * segments in a discard request.
259 void blk_queue_max_discard_segments(struct request_queue *q,
260 unsigned short max_segments)
262 q->limits.max_discard_segments = max_segments;
264 EXPORT_SYMBOL_GPL(blk_queue_max_discard_segments);
267 * blk_queue_max_segment_size - set max segment size for blk_rq_map_sg
268 * @q: the request queue for the device
269 * @max_size: max size of segment in bytes
272 * Enables a low level driver to set an upper limit on the size of a
275 void blk_queue_max_segment_size(struct request_queue *q, unsigned int max_size)
277 if (max_size < PAGE_SIZE) {
278 max_size = PAGE_SIZE;
279 printk(KERN_INFO "%s: set to minimum %d\n",
283 /* see blk_queue_virt_boundary() for the explanation */
284 WARN_ON_ONCE(q->limits.virt_boundary_mask);
286 q->limits.max_segment_size = max_size;
288 EXPORT_SYMBOL(blk_queue_max_segment_size);
291 * blk_queue_logical_block_size - set logical block size for the queue
292 * @q: the request queue for the device
293 * @size: the logical block size, in bytes
296 * This should be set to the lowest possible block size that the
297 * storage device can address. The default of 512 covers most
300 void blk_queue_logical_block_size(struct request_queue *q, unsigned int size)
302 struct queue_limits *limits = &q->limits;
304 limits->logical_block_size = size;
306 if (limits->physical_block_size < size)
307 limits->physical_block_size = size;
309 if (limits->io_min < limits->physical_block_size)
310 limits->io_min = limits->physical_block_size;
312 limits->max_hw_sectors =
313 round_down(limits->max_hw_sectors, size >> SECTOR_SHIFT);
314 limits->max_sectors =
315 round_down(limits->max_sectors, size >> SECTOR_SHIFT);
317 EXPORT_SYMBOL(blk_queue_logical_block_size);
320 * blk_queue_physical_block_size - set physical block size for the queue
321 * @q: the request queue for the device
322 * @size: the physical block size, in bytes
325 * This should be set to the lowest possible sector size that the
326 * hardware can operate on without reverting to read-modify-write
329 void blk_queue_physical_block_size(struct request_queue *q, unsigned int size)
331 q->limits.physical_block_size = size;
333 if (q->limits.physical_block_size < q->limits.logical_block_size)
334 q->limits.physical_block_size = q->limits.logical_block_size;
336 if (q->limits.io_min < q->limits.physical_block_size)
337 q->limits.io_min = q->limits.physical_block_size;
339 EXPORT_SYMBOL(blk_queue_physical_block_size);
342 * blk_queue_zone_write_granularity - set zone write granularity for the queue
343 * @q: the request queue for the zoned device
344 * @size: the zone write granularity size, in bytes
347 * This should be set to the lowest possible size allowing to write in
348 * sequential zones of a zoned block device.
350 void blk_queue_zone_write_granularity(struct request_queue *q,
353 if (WARN_ON_ONCE(!blk_queue_is_zoned(q)))
356 q->limits.zone_write_granularity = size;
358 if (q->limits.zone_write_granularity < q->limits.logical_block_size)
359 q->limits.zone_write_granularity = q->limits.logical_block_size;
361 EXPORT_SYMBOL_GPL(blk_queue_zone_write_granularity);
364 * blk_queue_alignment_offset - set physical block alignment offset
365 * @q: the request queue for the device
366 * @offset: alignment offset in bytes
369 * Some devices are naturally misaligned to compensate for things like
370 * the legacy DOS partition table 63-sector offset. Low-level drivers
371 * should call this function for devices whose first sector is not
374 void blk_queue_alignment_offset(struct request_queue *q, unsigned int offset)
376 q->limits.alignment_offset =
377 offset & (q->limits.physical_block_size - 1);
378 q->limits.misaligned = 0;
380 EXPORT_SYMBOL(blk_queue_alignment_offset);
382 void blk_queue_update_readahead(struct request_queue *q)
385 * For read-ahead of large files to be effective, we need to read ahead
386 * at least twice the optimal I/O size.
388 q->backing_dev_info->ra_pages =
389 max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES);
390 q->backing_dev_info->io_pages =
391 queue_max_sectors(q) >> (PAGE_SHIFT - 9);
393 EXPORT_SYMBOL_GPL(blk_queue_update_readahead);
396 * blk_limits_io_min - set minimum request size for a device
397 * @limits: the queue limits
398 * @min: smallest I/O size in bytes
401 * Some devices have an internal block size bigger than the reported
402 * hardware sector size. This function can be used to signal the
403 * smallest I/O the device can perform without incurring a performance
406 void blk_limits_io_min(struct queue_limits *limits, unsigned int min)
408 limits->io_min = min;
410 if (limits->io_min < limits->logical_block_size)
411 limits->io_min = limits->logical_block_size;
413 if (limits->io_min < limits->physical_block_size)
414 limits->io_min = limits->physical_block_size;
416 EXPORT_SYMBOL(blk_limits_io_min);
419 * blk_queue_io_min - set minimum request size for the queue
420 * @q: the request queue for the device
421 * @min: smallest I/O size in bytes
424 * Storage devices may report a granularity or preferred minimum I/O
425 * size which is the smallest request the device can perform without
426 * incurring a performance penalty. For disk drives this is often the
427 * physical block size. For RAID arrays it is often the stripe chunk
428 * size. A properly aligned multiple of minimum_io_size is the
429 * preferred request size for workloads where a high number of I/O
430 * operations is desired.
432 void blk_queue_io_min(struct request_queue *q, unsigned int min)
434 blk_limits_io_min(&q->limits, min);
436 EXPORT_SYMBOL(blk_queue_io_min);
439 * blk_limits_io_opt - set optimal request size for a device
440 * @limits: the queue limits
441 * @opt: smallest I/O size in bytes
444 * Storage devices may report an optimal I/O size, which is the
445 * device's preferred unit for sustained I/O. This is rarely reported
446 * for disk drives. For RAID arrays it is usually the stripe width or
447 * the internal track size. A properly aligned multiple of
448 * optimal_io_size is the preferred request size for workloads where
449 * sustained throughput is desired.
451 void blk_limits_io_opt(struct queue_limits *limits, unsigned int opt)
453 limits->io_opt = opt;
455 EXPORT_SYMBOL(blk_limits_io_opt);
458 * blk_queue_io_opt - set optimal request size for the queue
459 * @q: the request queue for the device
460 * @opt: optimal request size in bytes
463 * Storage devices may report an optimal I/O size, which is the
464 * device's preferred unit for sustained I/O. This is rarely reported
465 * for disk drives. For RAID arrays it is usually the stripe width or
466 * the internal track size. A properly aligned multiple of
467 * optimal_io_size is the preferred request size for workloads where
468 * sustained throughput is desired.
470 void blk_queue_io_opt(struct request_queue *q, unsigned int opt)
472 blk_limits_io_opt(&q->limits, opt);
473 q->backing_dev_info->ra_pages =
474 max(queue_io_opt(q) * 2 / PAGE_SIZE, VM_READAHEAD_PAGES);
476 EXPORT_SYMBOL(blk_queue_io_opt);
478 static unsigned int blk_round_down_sectors(unsigned int sectors, unsigned int lbs)
480 sectors = round_down(sectors, lbs >> SECTOR_SHIFT);
481 if (sectors < PAGE_SIZE >> SECTOR_SHIFT)
482 sectors = PAGE_SIZE >> SECTOR_SHIFT;
487 * blk_stack_limits - adjust queue_limits for stacked devices
488 * @t: the stacking driver limits (top device)
489 * @b: the underlying queue limits (bottom, component device)
490 * @start: first data sector within component device
493 * This function is used by stacking drivers like MD and DM to ensure
494 * that all component devices have compatible block sizes and
495 * alignments. The stacking driver must provide a queue_limits
496 * struct (top) and then iteratively call the stacking function for
497 * all component (bottom) devices. The stacking function will
498 * attempt to combine the values and ensure proper alignment.
500 * Returns 0 if the top and bottom queue_limits are compatible. The
501 * top device's block sizes and alignment offsets may be adjusted to
502 * ensure alignment with the bottom device. If no compatible sizes
503 * and alignments exist, -1 is returned and the resulting top
504 * queue_limits will have the misaligned flag set to indicate that
505 * the alignment_offset is undefined.
507 int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
510 unsigned int top, bottom, alignment, ret = 0;
512 t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors);
513 t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors);
514 t->max_dev_sectors = min_not_zero(t->max_dev_sectors, b->max_dev_sectors);
515 t->max_write_same_sectors = min(t->max_write_same_sectors,
516 b->max_write_same_sectors);
517 t->max_write_zeroes_sectors = min(t->max_write_zeroes_sectors,
518 b->max_write_zeroes_sectors);
519 t->max_zone_append_sectors = min(t->max_zone_append_sectors,
520 b->max_zone_append_sectors);
521 t->bounce = max(t->bounce, b->bounce);
523 t->seg_boundary_mask = min_not_zero(t->seg_boundary_mask,
524 b->seg_boundary_mask);
525 t->virt_boundary_mask = min_not_zero(t->virt_boundary_mask,
526 b->virt_boundary_mask);
528 t->max_segments = min_not_zero(t->max_segments, b->max_segments);
529 t->max_discard_segments = min_not_zero(t->max_discard_segments,
530 b->max_discard_segments);
531 t->max_integrity_segments = min_not_zero(t->max_integrity_segments,
532 b->max_integrity_segments);
534 t->max_segment_size = min_not_zero(t->max_segment_size,
535 b->max_segment_size);
537 t->misaligned |= b->misaligned;
539 alignment = queue_limit_alignment_offset(b, start);
541 /* Bottom device has different alignment. Check that it is
542 * compatible with the current top alignment.
544 if (t->alignment_offset != alignment) {
546 top = max(t->physical_block_size, t->io_min)
547 + t->alignment_offset;
548 bottom = max(b->physical_block_size, b->io_min) + alignment;
550 /* Verify that top and bottom intervals line up */
551 if (max(top, bottom) % min(top, bottom)) {
557 t->logical_block_size = max(t->logical_block_size,
558 b->logical_block_size);
560 t->physical_block_size = max(t->physical_block_size,
561 b->physical_block_size);
563 t->io_min = max(t->io_min, b->io_min);
564 t->io_opt = lcm_not_zero(t->io_opt, b->io_opt);
566 /* Set non-power-of-2 compatible chunk_sectors boundary */
567 if (b->chunk_sectors)
568 t->chunk_sectors = gcd(t->chunk_sectors, b->chunk_sectors);
570 /* Physical block size a multiple of the logical block size? */
571 if (t->physical_block_size & (t->logical_block_size - 1)) {
572 t->physical_block_size = t->logical_block_size;
577 /* Minimum I/O a multiple of the physical block size? */
578 if (t->io_min & (t->physical_block_size - 1)) {
579 t->io_min = t->physical_block_size;
584 /* Optimal I/O a multiple of the physical block size? */
585 if (t->io_opt & (t->physical_block_size - 1)) {
591 /* chunk_sectors a multiple of the physical block size? */
592 if ((t->chunk_sectors << 9) & (t->physical_block_size - 1)) {
593 t->chunk_sectors = 0;
598 t->raid_partial_stripes_expensive =
599 max(t->raid_partial_stripes_expensive,
600 b->raid_partial_stripes_expensive);
602 /* Find lowest common alignment_offset */
603 t->alignment_offset = lcm_not_zero(t->alignment_offset, alignment)
604 % max(t->physical_block_size, t->io_min);
606 /* Verify that new alignment_offset is on a logical block boundary */
607 if (t->alignment_offset & (t->logical_block_size - 1)) {
612 t->max_sectors = blk_round_down_sectors(t->max_sectors, t->logical_block_size);
613 t->max_hw_sectors = blk_round_down_sectors(t->max_hw_sectors, t->logical_block_size);
614 t->max_dev_sectors = blk_round_down_sectors(t->max_dev_sectors, t->logical_block_size);
616 /* Discard alignment and granularity */
617 if (b->discard_granularity) {
618 alignment = queue_limit_discard_alignment(b, start);
620 if (t->discard_granularity != 0 &&
621 t->discard_alignment != alignment) {
622 top = t->discard_granularity + t->discard_alignment;
623 bottom = b->discard_granularity + alignment;
625 /* Verify that top and bottom intervals line up */
626 if ((max(top, bottom) % min(top, bottom)) != 0)
627 t->discard_misaligned = 1;
630 t->max_discard_sectors = min_not_zero(t->max_discard_sectors,
631 b->max_discard_sectors);
632 t->max_hw_discard_sectors = min_not_zero(t->max_hw_discard_sectors,
633 b->max_hw_discard_sectors);
634 t->discard_granularity = max(t->discard_granularity,
635 b->discard_granularity);
636 t->discard_alignment = lcm_not_zero(t->discard_alignment, alignment) %
637 t->discard_granularity;
640 t->zone_write_granularity = max(t->zone_write_granularity,
641 b->zone_write_granularity);
642 t->zoned = max(t->zoned, b->zoned);
645 EXPORT_SYMBOL(blk_stack_limits);
648 * disk_stack_limits - adjust queue limits for stacked drivers
649 * @disk: MD/DM gendisk (top)
650 * @bdev: the underlying block device (bottom)
651 * @offset: offset to beginning of data within component device
654 * Merges the limits for a top level gendisk and a bottom level
657 void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
660 struct request_queue *t = disk->queue;
662 if (blk_stack_limits(&t->limits, &bdev_get_queue(bdev)->limits,
663 get_start_sect(bdev) + (offset >> 9)) < 0) {
664 char top[BDEVNAME_SIZE], bottom[BDEVNAME_SIZE];
666 disk_name(disk, 0, top);
667 bdevname(bdev, bottom);
669 printk(KERN_NOTICE "%s: Warning: Device %s is misaligned\n",
673 blk_queue_update_readahead(disk->queue);
675 EXPORT_SYMBOL(disk_stack_limits);
678 * blk_queue_update_dma_pad - update pad mask
679 * @q: the request queue for the device
682 * Update dma pad mask.
684 * Appending pad buffer to a request modifies the last entry of a
685 * scatter list such that it includes the pad buffer.
687 void blk_queue_update_dma_pad(struct request_queue *q, unsigned int mask)
689 if (mask > q->dma_pad_mask)
690 q->dma_pad_mask = mask;
692 EXPORT_SYMBOL(blk_queue_update_dma_pad);
695 * blk_queue_segment_boundary - set boundary rules for segment merging
696 * @q: the request queue for the device
697 * @mask: the memory boundary mask
699 void blk_queue_segment_boundary(struct request_queue *q, unsigned long mask)
701 if (mask < PAGE_SIZE - 1) {
702 mask = PAGE_SIZE - 1;
703 printk(KERN_INFO "%s: set to minimum %lx\n",
707 q->limits.seg_boundary_mask = mask;
709 EXPORT_SYMBOL(blk_queue_segment_boundary);
712 * blk_queue_virt_boundary - set boundary rules for bio merging
713 * @q: the request queue for the device
714 * @mask: the memory boundary mask
716 void blk_queue_virt_boundary(struct request_queue *q, unsigned long mask)
718 q->limits.virt_boundary_mask = mask;
721 * Devices that require a virtual boundary do not support scatter/gather
722 * I/O natively, but instead require a descriptor list entry for each
723 * page (which might not be idential to the Linux PAGE_SIZE). Because
724 * of that they are not limited by our notion of "segment size".
727 q->limits.max_segment_size = UINT_MAX;
729 EXPORT_SYMBOL(blk_queue_virt_boundary);
732 * blk_queue_dma_alignment - set dma length and memory alignment
733 * @q: the request queue for the device
734 * @mask: alignment mask
737 * set required memory and length alignment for direct dma transactions.
738 * this is used when building direct io requests for the queue.
741 void blk_queue_dma_alignment(struct request_queue *q, int mask)
743 q->dma_alignment = mask;
745 EXPORT_SYMBOL(blk_queue_dma_alignment);
748 * blk_queue_update_dma_alignment - update dma length and memory alignment
749 * @q: the request queue for the device
750 * @mask: alignment mask
753 * update required memory and length alignment for direct dma transactions.
754 * If the requested alignment is larger than the current alignment, then
755 * the current queue alignment is updated to the new value, otherwise it
756 * is left alone. The design of this is to allow multiple objects
757 * (driver, device, transport etc) to set their respective
758 * alignments without having them interfere.
761 void blk_queue_update_dma_alignment(struct request_queue *q, int mask)
763 BUG_ON(mask > PAGE_SIZE);
765 if (mask > q->dma_alignment)
766 q->dma_alignment = mask;
768 EXPORT_SYMBOL(blk_queue_update_dma_alignment);
771 * blk_set_queue_depth - tell the block layer about the device queue depth
772 * @q: the request queue for the device
773 * @depth: queue depth
776 void blk_set_queue_depth(struct request_queue *q, unsigned int depth)
778 q->queue_depth = depth;
779 rq_qos_queue_depth_changed(q);
781 EXPORT_SYMBOL(blk_set_queue_depth);
784 * blk_queue_write_cache - configure queue's write cache
785 * @q: the request queue for the device
786 * @wc: write back cache on or off
787 * @fua: device supports FUA writes, if true
789 * Tell the block layer about the write cache of @q.
791 void blk_queue_write_cache(struct request_queue *q, bool wc, bool fua)
794 blk_queue_flag_set(QUEUE_FLAG_WC, q);
796 blk_queue_flag_clear(QUEUE_FLAG_WC, q);
798 blk_queue_flag_set(QUEUE_FLAG_FUA, q);
800 blk_queue_flag_clear(QUEUE_FLAG_FUA, q);
802 wbt_set_write_cache(q, test_bit(QUEUE_FLAG_WC, &q->queue_flags));
804 EXPORT_SYMBOL_GPL(blk_queue_write_cache);
807 * blk_queue_required_elevator_features - Set a queue required elevator features
808 * @q: the request queue for the target device
809 * @features: Required elevator features OR'ed together
811 * Tell the block layer that for the device controlled through @q, only the
812 * only elevators that can be used are those that implement at least the set of
813 * features specified by @features.
815 void blk_queue_required_elevator_features(struct request_queue *q,
816 unsigned int features)
818 q->required_elevator_features = features;
820 EXPORT_SYMBOL_GPL(blk_queue_required_elevator_features);
823 * blk_queue_can_use_dma_map_merging - configure queue for merging segments.
824 * @q: the request queue for the device
825 * @dev: the device pointer for dma
827 * Tell the block layer about merging the segments by dma map of @q.
829 bool blk_queue_can_use_dma_map_merging(struct request_queue *q,
832 unsigned long boundary = dma_get_merge_boundary(dev);
837 /* No need to update max_segment_size. see blk_queue_virt_boundary() */
838 blk_queue_virt_boundary(q, boundary);
842 EXPORT_SYMBOL_GPL(blk_queue_can_use_dma_map_merging);
845 * blk_queue_set_zoned - configure a disk queue zoned model.
846 * @disk: the gendisk of the queue to configure
847 * @model: the zoned model to set
849 * Set the zoned model of the request queue of @disk according to @model.
850 * When @model is BLK_ZONED_HM (host managed), this should be called only
851 * if zoned block device support is enabled (CONFIG_BLK_DEV_ZONED option).
852 * If @model specifies BLK_ZONED_HA (host aware), the effective model used
853 * depends on CONFIG_BLK_DEV_ZONED settings and on the existence of partitions
856 void blk_queue_set_zoned(struct gendisk *disk, enum blk_zoned_model model)
858 struct request_queue *q = disk->queue;
863 * Host managed devices are supported only if
864 * CONFIG_BLK_DEV_ZONED is enabled.
866 WARN_ON_ONCE(!IS_ENABLED(CONFIG_BLK_DEV_ZONED));
870 * Host aware devices can be treated either as regular block
871 * devices (similar to drive managed devices) or as zoned block
872 * devices to take advantage of the zone command set, similarly
873 * to host managed devices. We try the latter if there are no
874 * partitions and zoned block device support is enabled, else
875 * we do nothing special as far as the block layer is concerned.
877 if (!IS_ENABLED(CONFIG_BLK_DEV_ZONED) ||
878 !xa_empty(&disk->part_tbl))
879 model = BLK_ZONED_NONE;
883 if (WARN_ON_ONCE(model != BLK_ZONED_NONE))
884 model = BLK_ZONED_NONE;
888 q->limits.zoned = model;
889 if (model != BLK_ZONED_NONE) {
891 * Set the zone write granularity to the device logical block
892 * size by default. The driver can change this value if needed.
894 blk_queue_zone_write_granularity(q,
895 queue_logical_block_size(q));
897 blk_queue_clear_zone_settings(q);
900 EXPORT_SYMBOL_GPL(blk_queue_set_zoned);