2 * Functions related to setting various queue properties from drivers
4 #include <linux/kernel.h>
5 #include <linux/module.h>
6 #include <linux/init.h>
8 #include <linux/blkdev.h>
9 #include <linux/bootmem.h> /* for max_pfn/max_low_pfn */
10 #include <linux/gcd.h>
11 #include <linux/lcm.h>
12 #include <linux/jiffies.h>
13 #include <linux/gfp.h>
18 unsigned long blk_max_low_pfn
;
19 EXPORT_SYMBOL(blk_max_low_pfn
);
21 unsigned long blk_max_pfn
;
24 * blk_queue_prep_rq - set a prepare_request function for queue
26 * @pfn: prepare_request function
28 * It's possible for a queue to register a prepare_request callback which
29 * is invoked before the request is handed to the request_fn. The goal of
30 * the function is to prepare a request for I/O, it can be used to build a
31 * cdb from the request data for instance.
34 void blk_queue_prep_rq(struct request_queue
*q
, prep_rq_fn
*pfn
)
38 EXPORT_SYMBOL(blk_queue_prep_rq
);
41 * blk_queue_unprep_rq - set an unprepare_request function for queue
43 * @ufn: unprepare_request function
45 * It's possible for a queue to register an unprepare_request callback
46 * which is invoked before the request is finally completed. The goal
47 * of the function is to deallocate any data that was allocated in the
48 * prepare_request callback.
51 void blk_queue_unprep_rq(struct request_queue
*q
, unprep_rq_fn
*ufn
)
53 q
->unprep_rq_fn
= ufn
;
55 EXPORT_SYMBOL(blk_queue_unprep_rq
);
57 void blk_queue_softirq_done(struct request_queue
*q
, softirq_done_fn
*fn
)
59 q
->softirq_done_fn
= fn
;
61 EXPORT_SYMBOL(blk_queue_softirq_done
);
63 void blk_queue_rq_timeout(struct request_queue
*q
, unsigned int timeout
)
65 q
->rq_timeout
= timeout
;
67 EXPORT_SYMBOL_GPL(blk_queue_rq_timeout
);
69 void blk_queue_rq_timed_out(struct request_queue
*q
, rq_timed_out_fn
*fn
)
71 q
->rq_timed_out_fn
= fn
;
73 EXPORT_SYMBOL_GPL(blk_queue_rq_timed_out
);
75 void blk_queue_lld_busy(struct request_queue
*q
, lld_busy_fn
*fn
)
79 EXPORT_SYMBOL_GPL(blk_queue_lld_busy
);
82 * blk_set_default_limits - reset limits to default values
83 * @lim: the queue_limits structure to reset
86 * Returns a queue_limit struct to its default state.
88 void blk_set_default_limits(struct queue_limits
*lim
)
90 lim
->max_segments
= BLK_MAX_SEGMENTS
;
91 lim
->max_integrity_segments
= 0;
92 lim
->seg_boundary_mask
= BLK_SEG_BOUNDARY_MASK
;
93 lim
->virt_boundary_mask
= 0;
94 lim
->max_segment_size
= BLK_MAX_SEGMENT_SIZE
;
95 lim
->max_sectors
= lim
->max_hw_sectors
= BLK_SAFE_MAX_SECTORS
;
96 lim
->max_dev_sectors
= 0;
97 lim
->chunk_sectors
= 0;
98 lim
->max_write_same_sectors
= 0;
99 lim
->max_discard_sectors
= 0;
100 lim
->max_hw_discard_sectors
= 0;
101 lim
->discard_granularity
= 0;
102 lim
->discard_alignment
= 0;
103 lim
->discard_misaligned
= 0;
104 lim
->discard_zeroes_data
= 0;
105 lim
->logical_block_size
= lim
->physical_block_size
= lim
->io_min
= 512;
106 lim
->bounce_pfn
= (unsigned long)(BLK_BOUNCE_ANY
>> PAGE_SHIFT
);
107 lim
->alignment_offset
= 0;
111 lim
->zoned
= BLK_ZONED_NONE
;
113 EXPORT_SYMBOL(blk_set_default_limits
);
116 * blk_set_stacking_limits - set default limits for stacking devices
117 * @lim: the queue_limits structure to reset
120 * Returns a queue_limit struct to its default state. Should be used
121 * by stacking drivers like DM that have no internal limits.
123 void blk_set_stacking_limits(struct queue_limits
*lim
)
125 blk_set_default_limits(lim
);
127 /* Inherit limits from component devices */
128 lim
->discard_zeroes_data
= 1;
129 lim
->max_segments
= USHRT_MAX
;
130 lim
->max_hw_sectors
= UINT_MAX
;
131 lim
->max_segment_size
= UINT_MAX
;
132 lim
->max_sectors
= UINT_MAX
;
133 lim
->max_dev_sectors
= UINT_MAX
;
134 lim
->max_write_same_sectors
= UINT_MAX
;
136 EXPORT_SYMBOL(blk_set_stacking_limits
);
139 * blk_queue_make_request - define an alternate make_request function for a device
140 * @q: the request queue for the device to be affected
141 * @mfn: the alternate make_request function
144 * The normal way for &struct bios to be passed to a device
145 * driver is for them to be collected into requests on a request
146 * queue, and then to allow the device driver to select requests
147 * off that queue when it is ready. This works well for many block
148 * devices. However some block devices (typically virtual devices
149 * such as md or lvm) do not benefit from the processing on the
150 * request queue, and are served best by having the requests passed
151 * directly to them. This can be achieved by providing a function
152 * to blk_queue_make_request().
155 * The driver that does this *must* be able to deal appropriately
156 * with buffers in "highmemory". This can be accomplished by either calling
157 * __bio_kmap_atomic() to get a temporary kernel mapping, or by calling
158 * blk_queue_bounce() to create a buffer in normal memory.
160 void blk_queue_make_request(struct request_queue
*q
, make_request_fn
*mfn
)
165 q
->nr_requests
= BLKDEV_MAX_RQ
;
167 q
->make_request_fn
= mfn
;
168 blk_queue_dma_alignment(q
, 511);
169 blk_queue_congestion_threshold(q
);
170 q
->nr_batching
= BLK_BATCH_REQ
;
172 blk_set_default_limits(&q
->limits
);
175 * by default assume old behaviour and bounce for any highmem page
177 blk_queue_bounce_limit(q
, BLK_BOUNCE_HIGH
);
179 EXPORT_SYMBOL(blk_queue_make_request
);
182 * blk_queue_bounce_limit - set bounce buffer limit for queue
183 * @q: the request queue for the device
184 * @max_addr: the maximum address the device can handle
187 * Different hardware can have different requirements as to what pages
188 * it can do I/O directly to. A low level driver can call
189 * blk_queue_bounce_limit to have lower memory pages allocated as bounce
190 * buffers for doing I/O to pages residing above @max_addr.
192 void blk_queue_bounce_limit(struct request_queue
*q
, u64 max_addr
)
194 unsigned long b_pfn
= max_addr
>> PAGE_SHIFT
;
197 q
->bounce_gfp
= GFP_NOIO
;
198 #if BITS_PER_LONG == 64
200 * Assume anything <= 4GB can be handled by IOMMU. Actually
201 * some IOMMUs can handle everything, but I don't know of a
202 * way to test this here.
204 if (b_pfn
< (min_t(u64
, 0xffffffffUL
, BLK_BOUNCE_HIGH
) >> PAGE_SHIFT
))
206 q
->limits
.bounce_pfn
= max(max_low_pfn
, b_pfn
);
208 if (b_pfn
< blk_max_low_pfn
)
210 q
->limits
.bounce_pfn
= b_pfn
;
213 init_emergency_isa_pool();
214 q
->bounce_gfp
= GFP_NOIO
| GFP_DMA
;
215 q
->limits
.bounce_pfn
= b_pfn
;
218 EXPORT_SYMBOL(blk_queue_bounce_limit
);
221 * blk_queue_max_hw_sectors - set max sectors for a request for this queue
222 * @q: the request queue for the device
223 * @max_hw_sectors: max hardware sectors in the usual 512b unit
226 * Enables a low level driver to set a hard upper limit,
227 * max_hw_sectors, on the size of requests. max_hw_sectors is set by
228 * the device driver based upon the capabilities of the I/O
231 * max_dev_sectors is a hard limit imposed by the storage device for
232 * READ/WRITE requests. It is set by the disk driver.
234 * max_sectors is a soft limit imposed by the block layer for
235 * filesystem type requests. This value can be overridden on a
236 * per-device basis in /sys/block/<device>/queue/max_sectors_kb.
237 * The soft limit can not exceed max_hw_sectors.
239 void blk_queue_max_hw_sectors(struct request_queue
*q
, unsigned int max_hw_sectors
)
241 struct queue_limits
*limits
= &q
->limits
;
242 unsigned int max_sectors
;
244 if ((max_hw_sectors
<< 9) < PAGE_SIZE
) {
245 max_hw_sectors
= 1 << (PAGE_SHIFT
- 9);
246 printk(KERN_INFO
"%s: set to minimum %d\n",
247 __func__
, max_hw_sectors
);
250 limits
->max_hw_sectors
= max_hw_sectors
;
251 max_sectors
= min_not_zero(max_hw_sectors
, limits
->max_dev_sectors
);
252 max_sectors
= min_t(unsigned int, max_sectors
, BLK_DEF_MAX_SECTORS
);
253 limits
->max_sectors
= max_sectors
;
255 EXPORT_SYMBOL(blk_queue_max_hw_sectors
);
258 * blk_queue_chunk_sectors - set size of the chunk for this queue
259 * @q: the request queue for the device
260 * @chunk_sectors: chunk sectors in the usual 512b unit
263 * If a driver doesn't want IOs to cross a given chunk size, it can set
264 * this limit and prevent merging across chunks. Note that the chunk size
265 * must currently be a power-of-2 in sectors. Also note that the block
266 * layer must accept a page worth of data at any offset. So if the
267 * crossing of chunks is a hard limitation in the driver, it must still be
268 * prepared to split single page bios.
270 void blk_queue_chunk_sectors(struct request_queue
*q
, unsigned int chunk_sectors
)
272 BUG_ON(!is_power_of_2(chunk_sectors
));
273 q
->limits
.chunk_sectors
= chunk_sectors
;
275 EXPORT_SYMBOL(blk_queue_chunk_sectors
);
278 * blk_queue_max_discard_sectors - set max sectors for a single discard
279 * @q: the request queue for the device
280 * @max_discard_sectors: maximum number of sectors to discard
282 void blk_queue_max_discard_sectors(struct request_queue
*q
,
283 unsigned int max_discard_sectors
)
285 q
->limits
.max_hw_discard_sectors
= max_discard_sectors
;
286 q
->limits
.max_discard_sectors
= max_discard_sectors
;
288 EXPORT_SYMBOL(blk_queue_max_discard_sectors
);
291 * blk_queue_max_write_same_sectors - set max sectors for a single write same
292 * @q: the request queue for the device
293 * @max_write_same_sectors: maximum number of sectors to write per command
295 void blk_queue_max_write_same_sectors(struct request_queue
*q
,
296 unsigned int max_write_same_sectors
)
298 q
->limits
.max_write_same_sectors
= max_write_same_sectors
;
300 EXPORT_SYMBOL(blk_queue_max_write_same_sectors
);
303 * blk_queue_max_segments - set max hw segments for a request for this queue
304 * @q: the request queue for the device
305 * @max_segments: max number of segments
308 * Enables a low level driver to set an upper limit on the number of
309 * hw data segments in a request.
311 void blk_queue_max_segments(struct request_queue
*q
, unsigned short max_segments
)
315 printk(KERN_INFO
"%s: set to minimum %d\n",
316 __func__
, max_segments
);
319 q
->limits
.max_segments
= max_segments
;
321 EXPORT_SYMBOL(blk_queue_max_segments
);
324 * blk_queue_max_segment_size - set max segment size for blk_rq_map_sg
325 * @q: the request queue for the device
326 * @max_size: max size of segment in bytes
329 * Enables a low level driver to set an upper limit on the size of a
332 void blk_queue_max_segment_size(struct request_queue
*q
, unsigned int max_size
)
334 if (max_size
< PAGE_SIZE
) {
335 max_size
= PAGE_SIZE
;
336 printk(KERN_INFO
"%s: set to minimum %d\n",
340 q
->limits
.max_segment_size
= max_size
;
342 EXPORT_SYMBOL(blk_queue_max_segment_size
);
345 * blk_queue_logical_block_size - set logical block size for the queue
346 * @q: the request queue for the device
347 * @size: the logical block size, in bytes
350 * This should be set to the lowest possible block size that the
351 * storage device can address. The default of 512 covers most
354 void blk_queue_logical_block_size(struct request_queue
*q
, unsigned short size
)
356 q
->limits
.logical_block_size
= size
;
358 if (q
->limits
.physical_block_size
< size
)
359 q
->limits
.physical_block_size
= size
;
361 if (q
->limits
.io_min
< q
->limits
.physical_block_size
)
362 q
->limits
.io_min
= q
->limits
.physical_block_size
;
364 EXPORT_SYMBOL(blk_queue_logical_block_size
);
367 * blk_queue_physical_block_size - set physical block size for the queue
368 * @q: the request queue for the device
369 * @size: the physical block size, in bytes
372 * This should be set to the lowest possible sector size that the
373 * hardware can operate on without reverting to read-modify-write
376 void blk_queue_physical_block_size(struct request_queue
*q
, unsigned int size
)
378 q
->limits
.physical_block_size
= size
;
380 if (q
->limits
.physical_block_size
< q
->limits
.logical_block_size
)
381 q
->limits
.physical_block_size
= q
->limits
.logical_block_size
;
383 if (q
->limits
.io_min
< q
->limits
.physical_block_size
)
384 q
->limits
.io_min
= q
->limits
.physical_block_size
;
386 EXPORT_SYMBOL(blk_queue_physical_block_size
);
389 * blk_queue_alignment_offset - set physical block alignment offset
390 * @q: the request queue for the device
391 * @offset: alignment offset in bytes
394 * Some devices are naturally misaligned to compensate for things like
395 * the legacy DOS partition table 63-sector offset. Low-level drivers
396 * should call this function for devices whose first sector is not
399 void blk_queue_alignment_offset(struct request_queue
*q
, unsigned int offset
)
401 q
->limits
.alignment_offset
=
402 offset
& (q
->limits
.physical_block_size
- 1);
403 q
->limits
.misaligned
= 0;
405 EXPORT_SYMBOL(blk_queue_alignment_offset
);
408 * blk_limits_io_min - set minimum request size for a device
409 * @limits: the queue limits
410 * @min: smallest I/O size in bytes
413 * Some devices have an internal block size bigger than the reported
414 * hardware sector size. This function can be used to signal the
415 * smallest I/O the device can perform without incurring a performance
418 void blk_limits_io_min(struct queue_limits
*limits
, unsigned int min
)
420 limits
->io_min
= min
;
422 if (limits
->io_min
< limits
->logical_block_size
)
423 limits
->io_min
= limits
->logical_block_size
;
425 if (limits
->io_min
< limits
->physical_block_size
)
426 limits
->io_min
= limits
->physical_block_size
;
428 EXPORT_SYMBOL(blk_limits_io_min
);
431 * blk_queue_io_min - set minimum request size for the queue
432 * @q: the request queue for the device
433 * @min: smallest I/O size in bytes
436 * Storage devices may report a granularity or preferred minimum I/O
437 * size which is the smallest request the device can perform without
438 * incurring a performance penalty. For disk drives this is often the
439 * physical block size. For RAID arrays it is often the stripe chunk
440 * size. A properly aligned multiple of minimum_io_size is the
441 * preferred request size for workloads where a high number of I/O
442 * operations is desired.
444 void blk_queue_io_min(struct request_queue
*q
, unsigned int min
)
446 blk_limits_io_min(&q
->limits
, min
);
448 EXPORT_SYMBOL(blk_queue_io_min
);
451 * blk_limits_io_opt - set optimal request size for a device
452 * @limits: the queue limits
453 * @opt: smallest I/O size in bytes
456 * Storage devices may report an optimal I/O size, which is the
457 * device's preferred unit for sustained I/O. This is rarely reported
458 * for disk drives. For RAID arrays it is usually the stripe width or
459 * the internal track size. A properly aligned multiple of
460 * optimal_io_size is the preferred request size for workloads where
461 * sustained throughput is desired.
463 void blk_limits_io_opt(struct queue_limits
*limits
, unsigned int opt
)
465 limits
->io_opt
= opt
;
467 EXPORT_SYMBOL(blk_limits_io_opt
);
470 * blk_queue_io_opt - set optimal request size for the queue
471 * @q: the request queue for the device
472 * @opt: optimal request size in bytes
475 * Storage devices may report an optimal I/O size, which is the
476 * device's preferred unit for sustained I/O. This is rarely reported
477 * for disk drives. For RAID arrays it is usually the stripe width or
478 * the internal track size. A properly aligned multiple of
479 * optimal_io_size is the preferred request size for workloads where
480 * sustained throughput is desired.
482 void blk_queue_io_opt(struct request_queue
*q
, unsigned int opt
)
484 blk_limits_io_opt(&q
->limits
, opt
);
486 EXPORT_SYMBOL(blk_queue_io_opt
);
489 * blk_queue_stack_limits - inherit underlying queue limits for stacked drivers
490 * @t: the stacking driver (top)
491 * @b: the underlying device (bottom)
493 void blk_queue_stack_limits(struct request_queue
*t
, struct request_queue
*b
)
495 blk_stack_limits(&t
->limits
, &b
->limits
, 0);
497 EXPORT_SYMBOL(blk_queue_stack_limits
);
500 * blk_stack_limits - adjust queue_limits for stacked devices
501 * @t: the stacking driver limits (top device)
502 * @b: the underlying queue limits (bottom, component device)
503 * @start: first data sector within component device
506 * This function is used by stacking drivers like MD and DM to ensure
507 * that all component devices have compatible block sizes and
508 * alignments. The stacking driver must provide a queue_limits
509 * struct (top) and then iteratively call the stacking function for
510 * all component (bottom) devices. The stacking function will
511 * attempt to combine the values and ensure proper alignment.
513 * Returns 0 if the top and bottom queue_limits are compatible. The
514 * top device's block sizes and alignment offsets may be adjusted to
515 * ensure alignment with the bottom device. If no compatible sizes
516 * and alignments exist, -1 is returned and the resulting top
517 * queue_limits will have the misaligned flag set to indicate that
518 * the alignment_offset is undefined.
520 int blk_stack_limits(struct queue_limits
*t
, struct queue_limits
*b
,
523 unsigned int top
, bottom
, alignment
, ret
= 0;
525 t
->max_sectors
= min_not_zero(t
->max_sectors
, b
->max_sectors
);
526 t
->max_hw_sectors
= min_not_zero(t
->max_hw_sectors
, b
->max_hw_sectors
);
527 t
->max_dev_sectors
= min_not_zero(t
->max_dev_sectors
, b
->max_dev_sectors
);
528 t
->max_write_same_sectors
= min(t
->max_write_same_sectors
,
529 b
->max_write_same_sectors
);
530 t
->bounce_pfn
= min_not_zero(t
->bounce_pfn
, b
->bounce_pfn
);
532 t
->seg_boundary_mask
= min_not_zero(t
->seg_boundary_mask
,
533 b
->seg_boundary_mask
);
534 t
->virt_boundary_mask
= min_not_zero(t
->virt_boundary_mask
,
535 b
->virt_boundary_mask
);
537 t
->max_segments
= min_not_zero(t
->max_segments
, b
->max_segments
);
538 t
->max_integrity_segments
= min_not_zero(t
->max_integrity_segments
,
539 b
->max_integrity_segments
);
541 t
->max_segment_size
= min_not_zero(t
->max_segment_size
,
542 b
->max_segment_size
);
544 t
->misaligned
|= b
->misaligned
;
546 alignment
= queue_limit_alignment_offset(b
, start
);
548 /* Bottom device has different alignment. Check that it is
549 * compatible with the current top alignment.
551 if (t
->alignment_offset
!= alignment
) {
553 top
= max(t
->physical_block_size
, t
->io_min
)
554 + t
->alignment_offset
;
555 bottom
= max(b
->physical_block_size
, b
->io_min
) + alignment
;
557 /* Verify that top and bottom intervals line up */
558 if (max(top
, bottom
) % min(top
, bottom
)) {
564 t
->logical_block_size
= max(t
->logical_block_size
,
565 b
->logical_block_size
);
567 t
->physical_block_size
= max(t
->physical_block_size
,
568 b
->physical_block_size
);
570 t
->io_min
= max(t
->io_min
, b
->io_min
);
571 t
->io_opt
= lcm_not_zero(t
->io_opt
, b
->io_opt
);
573 t
->cluster
&= b
->cluster
;
574 t
->discard_zeroes_data
&= b
->discard_zeroes_data
;
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 t
->raid_partial_stripes_expensive
=
598 max(t
->raid_partial_stripes_expensive
,
599 b
->raid_partial_stripes_expensive
);
601 /* Find lowest common alignment_offset */
602 t
->alignment_offset
= lcm_not_zero(t
->alignment_offset
, alignment
)
603 % max(t
->physical_block_size
, t
->io_min
);
605 /* Verify that new alignment_offset is on a logical block boundary */
606 if (t
->alignment_offset
& (t
->logical_block_size
- 1)) {
611 /* Discard alignment and granularity */
612 if (b
->discard_granularity
) {
613 alignment
= queue_limit_discard_alignment(b
, start
);
615 if (t
->discard_granularity
!= 0 &&
616 t
->discard_alignment
!= alignment
) {
617 top
= t
->discard_granularity
+ t
->discard_alignment
;
618 bottom
= b
->discard_granularity
+ alignment
;
620 /* Verify that top and bottom intervals line up */
621 if ((max(top
, bottom
) % min(top
, bottom
)) != 0)
622 t
->discard_misaligned
= 1;
625 t
->max_discard_sectors
= min_not_zero(t
->max_discard_sectors
,
626 b
->max_discard_sectors
);
627 t
->max_hw_discard_sectors
= min_not_zero(t
->max_hw_discard_sectors
,
628 b
->max_hw_discard_sectors
);
629 t
->discard_granularity
= max(t
->discard_granularity
,
630 b
->discard_granularity
);
631 t
->discard_alignment
= lcm_not_zero(t
->discard_alignment
, alignment
) %
632 t
->discard_granularity
;
635 if (b
->chunk_sectors
)
636 t
->chunk_sectors
= min_not_zero(t
->chunk_sectors
,
641 EXPORT_SYMBOL(blk_stack_limits
);
644 * bdev_stack_limits - adjust queue limits for stacked drivers
645 * @t: the stacking driver limits (top device)
646 * @bdev: the component block_device (bottom)
647 * @start: first data sector within component device
650 * Merges queue limits for a top device and a block_device. Returns
651 * 0 if alignment didn't change. Returns -1 if adding the bottom
652 * device caused misalignment.
654 int bdev_stack_limits(struct queue_limits
*t
, struct block_device
*bdev
,
657 struct request_queue
*bq
= bdev_get_queue(bdev
);
659 start
+= get_start_sect(bdev
);
661 return blk_stack_limits(t
, &bq
->limits
, start
);
663 EXPORT_SYMBOL(bdev_stack_limits
);
666 * disk_stack_limits - adjust queue limits for stacked drivers
667 * @disk: MD/DM gendisk (top)
668 * @bdev: the underlying block device (bottom)
669 * @offset: offset to beginning of data within component device
672 * Merges the limits for a top level gendisk and a bottom level
675 void disk_stack_limits(struct gendisk
*disk
, struct block_device
*bdev
,
678 struct request_queue
*t
= disk
->queue
;
680 if (bdev_stack_limits(&t
->limits
, bdev
, offset
>> 9) < 0) {
681 char top
[BDEVNAME_SIZE
], bottom
[BDEVNAME_SIZE
];
683 disk_name(disk
, 0, top
);
684 bdevname(bdev
, bottom
);
686 printk(KERN_NOTICE
"%s: Warning: Device %s is misaligned\n",
690 EXPORT_SYMBOL(disk_stack_limits
);
693 * blk_queue_dma_pad - set pad mask
694 * @q: the request queue for the device
699 * Appending pad buffer to a request modifies the last entry of a
700 * scatter list such that it includes the pad buffer.
702 void blk_queue_dma_pad(struct request_queue
*q
, unsigned int mask
)
704 q
->dma_pad_mask
= mask
;
706 EXPORT_SYMBOL(blk_queue_dma_pad
);
709 * blk_queue_update_dma_pad - update pad mask
710 * @q: the request queue for the device
713 * Update dma pad mask.
715 * Appending pad buffer to a request modifies the last entry of a
716 * scatter list such that it includes the pad buffer.
718 void blk_queue_update_dma_pad(struct request_queue
*q
, unsigned int mask
)
720 if (mask
> q
->dma_pad_mask
)
721 q
->dma_pad_mask
= mask
;
723 EXPORT_SYMBOL(blk_queue_update_dma_pad
);
726 * blk_queue_dma_drain - Set up a drain buffer for excess dma.
727 * @q: the request queue for the device
728 * @dma_drain_needed: fn which returns non-zero if drain is necessary
729 * @buf: physically contiguous buffer
730 * @size: size of the buffer in bytes
732 * Some devices have excess DMA problems and can't simply discard (or
733 * zero fill) the unwanted piece of the transfer. They have to have a
734 * real area of memory to transfer it into. The use case for this is
735 * ATAPI devices in DMA mode. If the packet command causes a transfer
736 * bigger than the transfer size some HBAs will lock up if there
737 * aren't DMA elements to contain the excess transfer. What this API
738 * does is adjust the queue so that the buf is always appended
739 * silently to the scatterlist.
741 * Note: This routine adjusts max_hw_segments to make room for appending
742 * the drain buffer. If you call blk_queue_max_segments() after calling
743 * this routine, you must set the limit to one fewer than your device
744 * can support otherwise there won't be room for the drain buffer.
746 int blk_queue_dma_drain(struct request_queue
*q
,
747 dma_drain_needed_fn
*dma_drain_needed
,
748 void *buf
, unsigned int size
)
750 if (queue_max_segments(q
) < 2)
752 /* make room for appending the drain */
753 blk_queue_max_segments(q
, queue_max_segments(q
) - 1);
754 q
->dma_drain_needed
= dma_drain_needed
;
755 q
->dma_drain_buffer
= buf
;
756 q
->dma_drain_size
= size
;
760 EXPORT_SYMBOL_GPL(blk_queue_dma_drain
);
763 * blk_queue_segment_boundary - set boundary rules for segment merging
764 * @q: the request queue for the device
765 * @mask: the memory boundary mask
767 void blk_queue_segment_boundary(struct request_queue
*q
, unsigned long mask
)
769 if (mask
< PAGE_SIZE
- 1) {
770 mask
= PAGE_SIZE
- 1;
771 printk(KERN_INFO
"%s: set to minimum %lx\n",
775 q
->limits
.seg_boundary_mask
= mask
;
777 EXPORT_SYMBOL(blk_queue_segment_boundary
);
780 * blk_queue_virt_boundary - set boundary rules for bio merging
781 * @q: the request queue for the device
782 * @mask: the memory boundary mask
784 void blk_queue_virt_boundary(struct request_queue
*q
, unsigned long mask
)
786 q
->limits
.virt_boundary_mask
= mask
;
788 EXPORT_SYMBOL(blk_queue_virt_boundary
);
791 * blk_queue_dma_alignment - set dma length and memory alignment
792 * @q: the request queue for the device
793 * @mask: alignment mask
796 * set required memory and length alignment for direct dma transactions.
797 * this is used when building direct io requests for the queue.
800 void blk_queue_dma_alignment(struct request_queue
*q
, int mask
)
802 q
->dma_alignment
= mask
;
804 EXPORT_SYMBOL(blk_queue_dma_alignment
);
807 * blk_queue_update_dma_alignment - update dma length and memory alignment
808 * @q: the request queue for the device
809 * @mask: alignment mask
812 * update required memory and length alignment for direct dma transactions.
813 * If the requested alignment is larger than the current alignment, then
814 * the current queue alignment is updated to the new value, otherwise it
815 * is left alone. The design of this is to allow multiple objects
816 * (driver, device, transport etc) to set their respective
817 * alignments without having them interfere.
820 void blk_queue_update_dma_alignment(struct request_queue
*q
, int mask
)
822 BUG_ON(mask
> PAGE_SIZE
);
824 if (mask
> q
->dma_alignment
)
825 q
->dma_alignment
= mask
;
827 EXPORT_SYMBOL(blk_queue_update_dma_alignment
);
829 void blk_queue_flush_queueable(struct request_queue
*q
, bool queueable
)
831 spin_lock_irq(q
->queue_lock
);
833 clear_bit(QUEUE_FLAG_FLUSH_NQ
, &q
->queue_flags
);
835 set_bit(QUEUE_FLAG_FLUSH_NQ
, &q
->queue_flags
);
836 spin_unlock_irq(q
->queue_lock
);
838 EXPORT_SYMBOL_GPL(blk_queue_flush_queueable
);
841 * blk_set_queue_depth - tell the block layer about the device queue depth
842 * @q: the request queue for the device
843 * @depth: queue depth
846 void blk_set_queue_depth(struct request_queue
*q
, unsigned int depth
)
848 q
->queue_depth
= depth
;
849 wbt_set_queue_depth(q
->rq_wb
, depth
);
851 EXPORT_SYMBOL(blk_set_queue_depth
);
854 * blk_queue_write_cache - configure queue's write cache
855 * @q: the request queue for the device
856 * @wc: write back cache on or off
857 * @fua: device supports FUA writes, if true
859 * Tell the block layer about the write cache of @q.
861 void blk_queue_write_cache(struct request_queue
*q
, bool wc
, bool fua
)
863 spin_lock_irq(q
->queue_lock
);
865 queue_flag_set(QUEUE_FLAG_WC
, q
);
867 queue_flag_clear(QUEUE_FLAG_WC
, q
);
869 queue_flag_set(QUEUE_FLAG_FUA
, q
);
871 queue_flag_clear(QUEUE_FLAG_FUA
, q
);
872 spin_unlock_irq(q
->queue_lock
);
874 wbt_set_write_cache(q
->rq_wb
, test_bit(QUEUE_FLAG_WC
, &q
->queue_flags
));
876 EXPORT_SYMBOL_GPL(blk_queue_write_cache
);
878 static int __init
blk_settings_init(void)
880 blk_max_low_pfn
= max_low_pfn
- 1;
881 blk_max_pfn
= max_pfn
- 1;
884 subsys_initcall(blk_settings_init
);