]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - block/blk-settings.c
block: use normal I/O path for discard requests
[mirror_ubuntu-artful-kernel.git] / block / blk-settings.c
CommitLineData
86db1e29
JA
1/*
2 * Functions related to setting various queue properties from drivers
3 */
4#include <linux/kernel.h>
5#include <linux/module.h>
6#include <linux/init.h>
7#include <linux/bio.h>
8#include <linux/blkdev.h>
9#include <linux/bootmem.h> /* for max_pfn/max_low_pfn */
70dd5bf3 10#include <linux/gcd.h>
86db1e29
JA
11
12#include "blk.h"
13
6728cb0e 14unsigned long blk_max_low_pfn;
86db1e29 15EXPORT_SYMBOL(blk_max_low_pfn);
6728cb0e
JA
16
17unsigned long blk_max_pfn;
86db1e29
JA
18
19/**
20 * blk_queue_prep_rq - set a prepare_request function for queue
21 * @q: queue
22 * @pfn: prepare_request function
23 *
24 * It's possible for a queue to register a prepare_request callback which
25 * is invoked before the request is handed to the request_fn. The goal of
26 * the function is to prepare a request for I/O, it can be used to build a
27 * cdb from the request data for instance.
28 *
29 */
30void blk_queue_prep_rq(struct request_queue *q, prep_rq_fn *pfn)
31{
32 q->prep_rq_fn = pfn;
33}
86db1e29
JA
34EXPORT_SYMBOL(blk_queue_prep_rq);
35
36/**
37 * blk_queue_merge_bvec - set a merge_bvec function for queue
38 * @q: queue
39 * @mbfn: merge_bvec_fn
40 *
41 * Usually queues have static limitations on the max sectors or segments that
42 * we can put in a request. Stacking drivers may have some settings that
43 * are dynamic, and thus we have to query the queue whether it is ok to
44 * add a new bio_vec to a bio at a given offset or not. If the block device
45 * has such limitations, it needs to register a merge_bvec_fn to control
46 * the size of bio's sent to it. Note that a block device *must* allow a
47 * single page to be added to an empty bio. The block device driver may want
48 * to use the bio_split() function to deal with these bio's. By default
49 * no merge_bvec_fn is defined for a queue, and only the fixed limits are
50 * honored.
51 */
52void blk_queue_merge_bvec(struct request_queue *q, merge_bvec_fn *mbfn)
53{
54 q->merge_bvec_fn = mbfn;
55}
86db1e29
JA
56EXPORT_SYMBOL(blk_queue_merge_bvec);
57
58void blk_queue_softirq_done(struct request_queue *q, softirq_done_fn *fn)
59{
60 q->softirq_done_fn = fn;
61}
86db1e29
JA
62EXPORT_SYMBOL(blk_queue_softirq_done);
63
242f9dcb
JA
64void blk_queue_rq_timeout(struct request_queue *q, unsigned int timeout)
65{
66 q->rq_timeout = timeout;
67}
68EXPORT_SYMBOL_GPL(blk_queue_rq_timeout);
69
70void blk_queue_rq_timed_out(struct request_queue *q, rq_timed_out_fn *fn)
71{
72 q->rq_timed_out_fn = fn;
73}
74EXPORT_SYMBOL_GPL(blk_queue_rq_timed_out);
75
ef9e3fac
KU
76void blk_queue_lld_busy(struct request_queue *q, lld_busy_fn *fn)
77{
78 q->lld_busy_fn = fn;
79}
80EXPORT_SYMBOL_GPL(blk_queue_lld_busy);
81
e475bba2
MP
82/**
83 * blk_set_default_limits - reset limits to default values
f740f5ca 84 * @lim: the queue_limits structure to reset
e475bba2
MP
85 *
86 * Description:
87 * Returns a queue_limit struct to its default state. Can be used by
88 * stacking drivers like DM that stage table swaps and reuse an
89 * existing device queue.
90 */
91void blk_set_default_limits(struct queue_limits *lim)
92{
93 lim->max_phys_segments = MAX_PHYS_SEGMENTS;
94 lim->max_hw_segments = MAX_HW_SEGMENTS;
95 lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK;
96 lim->max_segment_size = MAX_SEGMENT_SIZE;
5dee2477
MP
97 lim->max_sectors = BLK_DEF_MAX_SECTORS;
98 lim->max_hw_sectors = INT_MAX;
e475bba2 99 lim->logical_block_size = lim->physical_block_size = lim->io_min = 512;
3a02c8e8 100 lim->bounce_pfn = (unsigned long)(BLK_BOUNCE_ANY >> PAGE_SHIFT);
e475bba2
MP
101 lim->alignment_offset = 0;
102 lim->io_opt = 0;
103 lim->misaligned = 0;
104 lim->no_cluster = 0;
105}
106EXPORT_SYMBOL(blk_set_default_limits);
107
86db1e29
JA
108/**
109 * blk_queue_make_request - define an alternate make_request function for a device
110 * @q: the request queue for the device to be affected
111 * @mfn: the alternate make_request function
112 *
113 * Description:
114 * The normal way for &struct bios to be passed to a device
115 * driver is for them to be collected into requests on a request
116 * queue, and then to allow the device driver to select requests
117 * off that queue when it is ready. This works well for many block
118 * devices. However some block devices (typically virtual devices
119 * such as md or lvm) do not benefit from the processing on the
120 * request queue, and are served best by having the requests passed
121 * directly to them. This can be achieved by providing a function
122 * to blk_queue_make_request().
123 *
124 * Caveat:
125 * The driver that does this *must* be able to deal appropriately
126 * with buffers in "highmemory". This can be accomplished by either calling
127 * __bio_kmap_atomic() to get a temporary kernel mapping, or by calling
128 * blk_queue_bounce() to create a buffer in normal memory.
129 **/
6728cb0e 130void blk_queue_make_request(struct request_queue *q, make_request_fn *mfn)
86db1e29
JA
131{
132 /*
133 * set defaults
134 */
135 q->nr_requests = BLKDEV_MAX_RQ;
0e435ac2 136
86db1e29 137 q->make_request_fn = mfn;
86db1e29
JA
138 blk_queue_dma_alignment(q, 511);
139 blk_queue_congestion_threshold(q);
140 q->nr_batching = BLK_BATCH_REQ;
141
142 q->unplug_thresh = 4; /* hmm */
143 q->unplug_delay = (3 * HZ) / 1000; /* 3 milliseconds */
144 if (q->unplug_delay == 0)
145 q->unplug_delay = 1;
146
86db1e29
JA
147 q->unplug_timer.function = blk_unplug_timeout;
148 q->unplug_timer.data = (unsigned long)q;
149
e475bba2 150 blk_set_default_limits(&q->limits);
80ddf247 151 blk_queue_max_sectors(q, SAFE_MAX_SECTORS);
e475bba2 152
a4e7d464
JA
153 /*
154 * If the caller didn't supply a lock, fall back to our embedded
155 * per-queue locks
156 */
157 if (!q->queue_lock)
158 q->queue_lock = &q->__queue_lock;
159
86db1e29
JA
160 /*
161 * by default assume old behaviour and bounce for any highmem page
162 */
163 blk_queue_bounce_limit(q, BLK_BOUNCE_HIGH);
164}
86db1e29
JA
165EXPORT_SYMBOL(blk_queue_make_request);
166
167/**
168 * blk_queue_bounce_limit - set bounce buffer limit for queue
cd0aca2d
TH
169 * @q: the request queue for the device
170 * @dma_mask: the maximum address the device can handle
86db1e29
JA
171 *
172 * Description:
173 * Different hardware can have different requirements as to what pages
174 * it can do I/O directly to. A low level driver can call
175 * blk_queue_bounce_limit to have lower memory pages allocated as bounce
cd0aca2d 176 * buffers for doing I/O to pages residing above @dma_mask.
86db1e29 177 **/
cd0aca2d 178void blk_queue_bounce_limit(struct request_queue *q, u64 dma_mask)
86db1e29 179{
cd0aca2d 180 unsigned long b_pfn = dma_mask >> PAGE_SHIFT;
86db1e29
JA
181 int dma = 0;
182
183 q->bounce_gfp = GFP_NOIO;
184#if BITS_PER_LONG == 64
cd0aca2d
TH
185 /*
186 * Assume anything <= 4GB can be handled by IOMMU. Actually
187 * some IOMMUs can handle everything, but I don't know of a
188 * way to test this here.
189 */
190 if (b_pfn < (min_t(u64, 0xffffffffUL, BLK_BOUNCE_HIGH) >> PAGE_SHIFT))
86db1e29 191 dma = 1;
025146e1 192 q->limits.bounce_pfn = max_low_pfn;
86db1e29 193#else
6728cb0e 194 if (b_pfn < blk_max_low_pfn)
86db1e29 195 dma = 1;
025146e1 196 q->limits.bounce_pfn = b_pfn;
86db1e29
JA
197#endif
198 if (dma) {
199 init_emergency_isa_pool();
200 q->bounce_gfp = GFP_NOIO | GFP_DMA;
025146e1 201 q->limits.bounce_pfn = b_pfn;
86db1e29
JA
202 }
203}
86db1e29
JA
204EXPORT_SYMBOL(blk_queue_bounce_limit);
205
206/**
207 * blk_queue_max_sectors - set max sectors for a request for this queue
208 * @q: the request queue for the device
209 * @max_sectors: max sectors in the usual 512b unit
210 *
211 * Description:
212 * Enables a low level driver to set an upper limit on the size of
213 * received requests.
214 **/
215void blk_queue_max_sectors(struct request_queue *q, unsigned int max_sectors)
216{
217 if ((max_sectors << 9) < PAGE_CACHE_SIZE) {
218 max_sectors = 1 << (PAGE_CACHE_SHIFT - 9);
24c03d47
HH
219 printk(KERN_INFO "%s: set to minimum %d\n",
220 __func__, max_sectors);
86db1e29
JA
221 }
222
223 if (BLK_DEF_MAX_SECTORS > max_sectors)
025146e1 224 q->limits.max_hw_sectors = q->limits.max_sectors = max_sectors;
86db1e29 225 else {
025146e1
MP
226 q->limits.max_sectors = BLK_DEF_MAX_SECTORS;
227 q->limits.max_hw_sectors = max_sectors;
86db1e29
JA
228 }
229}
86db1e29
JA
230EXPORT_SYMBOL(blk_queue_max_sectors);
231
ae03bf63
MP
232void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_sectors)
233{
234 if (BLK_DEF_MAX_SECTORS > max_sectors)
025146e1 235 q->limits.max_hw_sectors = BLK_DEF_MAX_SECTORS;
ae03bf63 236 else
025146e1 237 q->limits.max_hw_sectors = max_sectors;
ae03bf63
MP
238}
239EXPORT_SYMBOL(blk_queue_max_hw_sectors);
240
86db1e29
JA
241/**
242 * blk_queue_max_phys_segments - set max phys segments for a request for this queue
243 * @q: the request queue for the device
244 * @max_segments: max number of segments
245 *
246 * Description:
247 * Enables a low level driver to set an upper limit on the number of
248 * physical data segments in a request. This would be the largest sized
249 * scatter list the driver could handle.
250 **/
251void blk_queue_max_phys_segments(struct request_queue *q,
252 unsigned short max_segments)
253{
254 if (!max_segments) {
255 max_segments = 1;
24c03d47
HH
256 printk(KERN_INFO "%s: set to minimum %d\n",
257 __func__, max_segments);
86db1e29
JA
258 }
259
025146e1 260 q->limits.max_phys_segments = max_segments;
86db1e29 261}
86db1e29
JA
262EXPORT_SYMBOL(blk_queue_max_phys_segments);
263
264/**
265 * blk_queue_max_hw_segments - set max hw segments for a request for this queue
266 * @q: the request queue for the device
267 * @max_segments: max number of segments
268 *
269 * Description:
270 * Enables a low level driver to set an upper limit on the number of
271 * hw data segments in a request. This would be the largest number of
710027a4 272 * address/length pairs the host adapter can actually give at once
86db1e29
JA
273 * to the device.
274 **/
275void blk_queue_max_hw_segments(struct request_queue *q,
276 unsigned short max_segments)
277{
278 if (!max_segments) {
279 max_segments = 1;
24c03d47
HH
280 printk(KERN_INFO "%s: set to minimum %d\n",
281 __func__, max_segments);
86db1e29
JA
282 }
283
025146e1 284 q->limits.max_hw_segments = max_segments;
86db1e29 285}
86db1e29
JA
286EXPORT_SYMBOL(blk_queue_max_hw_segments);
287
288/**
289 * blk_queue_max_segment_size - set max segment size for blk_rq_map_sg
290 * @q: the request queue for the device
291 * @max_size: max size of segment in bytes
292 *
293 * Description:
294 * Enables a low level driver to set an upper limit on the size of a
295 * coalesced segment
296 **/
297void blk_queue_max_segment_size(struct request_queue *q, unsigned int max_size)
298{
299 if (max_size < PAGE_CACHE_SIZE) {
300 max_size = PAGE_CACHE_SIZE;
24c03d47
HH
301 printk(KERN_INFO "%s: set to minimum %d\n",
302 __func__, max_size);
86db1e29
JA
303 }
304
025146e1 305 q->limits.max_segment_size = max_size;
86db1e29 306}
86db1e29
JA
307EXPORT_SYMBOL(blk_queue_max_segment_size);
308
309/**
e1defc4f 310 * blk_queue_logical_block_size - set logical block size for the queue
86db1e29 311 * @q: the request queue for the device
e1defc4f 312 * @size: the logical block size, in bytes
86db1e29
JA
313 *
314 * Description:
e1defc4f
MP
315 * This should be set to the lowest possible block size that the
316 * storage device can address. The default of 512 covers most
317 * hardware.
86db1e29 318 **/
e1defc4f 319void blk_queue_logical_block_size(struct request_queue *q, unsigned short size)
86db1e29 320{
025146e1 321 q->limits.logical_block_size = size;
c72758f3
MP
322
323 if (q->limits.physical_block_size < size)
324 q->limits.physical_block_size = size;
325
326 if (q->limits.io_min < q->limits.physical_block_size)
327 q->limits.io_min = q->limits.physical_block_size;
86db1e29 328}
e1defc4f 329EXPORT_SYMBOL(blk_queue_logical_block_size);
86db1e29 330
c72758f3
MP
331/**
332 * blk_queue_physical_block_size - set physical block size for the queue
333 * @q: the request queue for the device
334 * @size: the physical block size, in bytes
335 *
336 * Description:
337 * This should be set to the lowest possible sector size that the
338 * hardware can operate on without reverting to read-modify-write
339 * operations.
340 */
341void blk_queue_physical_block_size(struct request_queue *q, unsigned short size)
342{
343 q->limits.physical_block_size = size;
344
345 if (q->limits.physical_block_size < q->limits.logical_block_size)
346 q->limits.physical_block_size = q->limits.logical_block_size;
347
348 if (q->limits.io_min < q->limits.physical_block_size)
349 q->limits.io_min = q->limits.physical_block_size;
350}
351EXPORT_SYMBOL(blk_queue_physical_block_size);
352
353/**
354 * blk_queue_alignment_offset - set physical block alignment offset
355 * @q: the request queue for the device
8ebf9756 356 * @offset: alignment offset in bytes
c72758f3
MP
357 *
358 * Description:
359 * Some devices are naturally misaligned to compensate for things like
360 * the legacy DOS partition table 63-sector offset. Low-level drivers
361 * should call this function for devices whose first sector is not
362 * naturally aligned.
363 */
364void blk_queue_alignment_offset(struct request_queue *q, unsigned int offset)
365{
366 q->limits.alignment_offset =
367 offset & (q->limits.physical_block_size - 1);
368 q->limits.misaligned = 0;
369}
370EXPORT_SYMBOL(blk_queue_alignment_offset);
371
7c958e32
MP
372/**
373 * blk_limits_io_min - set minimum request size for a device
374 * @limits: the queue limits
375 * @min: smallest I/O size in bytes
376 *
377 * Description:
378 * Some devices have an internal block size bigger than the reported
379 * hardware sector size. This function can be used to signal the
380 * smallest I/O the device can perform without incurring a performance
381 * penalty.
382 */
383void blk_limits_io_min(struct queue_limits *limits, unsigned int min)
384{
385 limits->io_min = min;
386
387 if (limits->io_min < limits->logical_block_size)
388 limits->io_min = limits->logical_block_size;
389
390 if (limits->io_min < limits->physical_block_size)
391 limits->io_min = limits->physical_block_size;
392}
393EXPORT_SYMBOL(blk_limits_io_min);
394
c72758f3
MP
395/**
396 * blk_queue_io_min - set minimum request size for the queue
397 * @q: the request queue for the device
8ebf9756 398 * @min: smallest I/O size in bytes
c72758f3
MP
399 *
400 * Description:
7e5f5fb0
MP
401 * Storage devices may report a granularity or preferred minimum I/O
402 * size which is the smallest request the device can perform without
403 * incurring a performance penalty. For disk drives this is often the
404 * physical block size. For RAID arrays it is often the stripe chunk
405 * size. A properly aligned multiple of minimum_io_size is the
406 * preferred request size for workloads where a high number of I/O
407 * operations is desired.
c72758f3
MP
408 */
409void blk_queue_io_min(struct request_queue *q, unsigned int min)
410{
7c958e32 411 blk_limits_io_min(&q->limits, min);
c72758f3
MP
412}
413EXPORT_SYMBOL(blk_queue_io_min);
414
3c5820c7
MP
415/**
416 * blk_limits_io_opt - set optimal request size for a device
417 * @limits: the queue limits
418 * @opt: smallest I/O size in bytes
419 *
420 * Description:
421 * Storage devices may report an optimal I/O size, which is the
422 * device's preferred unit for sustained I/O. This is rarely reported
423 * for disk drives. For RAID arrays it is usually the stripe width or
424 * the internal track size. A properly aligned multiple of
425 * optimal_io_size is the preferred request size for workloads where
426 * sustained throughput is desired.
427 */
428void blk_limits_io_opt(struct queue_limits *limits, unsigned int opt)
429{
430 limits->io_opt = opt;
431}
432EXPORT_SYMBOL(blk_limits_io_opt);
433
c72758f3
MP
434/**
435 * blk_queue_io_opt - set optimal request size for the queue
436 * @q: the request queue for the device
8ebf9756 437 * @opt: optimal request size in bytes
c72758f3
MP
438 *
439 * Description:
7e5f5fb0
MP
440 * Storage devices may report an optimal I/O size, which is the
441 * device's preferred unit for sustained I/O. This is rarely reported
442 * for disk drives. For RAID arrays it is usually the stripe width or
443 * the internal track size. A properly aligned multiple of
444 * optimal_io_size is the preferred request size for workloads where
445 * sustained throughput is desired.
c72758f3
MP
446 */
447void blk_queue_io_opt(struct request_queue *q, unsigned int opt)
448{
3c5820c7 449 blk_limits_io_opt(&q->limits, opt);
c72758f3
MP
450}
451EXPORT_SYMBOL(blk_queue_io_opt);
452
86db1e29
JA
453/*
454 * Returns the minimum that is _not_ zero, unless both are zero.
455 */
456#define min_not_zero(l, r) (l == 0) ? r : ((r == 0) ? l : min(l, r))
457
458/**
459 * blk_queue_stack_limits - inherit underlying queue limits for stacked drivers
460 * @t: the stacking driver (top)
461 * @b: the underlying device (bottom)
462 **/
463void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b)
464{
fef24667 465 blk_stack_limits(&t->limits, &b->limits, 0);
025146e1 466
e7e72bf6
NB
467 if (!t->queue_lock)
468 WARN_ON_ONCE(1);
469 else if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags)) {
470 unsigned long flags;
471 spin_lock_irqsave(t->queue_lock, flags);
75ad23bc 472 queue_flag_clear(QUEUE_FLAG_CLUSTER, t);
e7e72bf6
NB
473 spin_unlock_irqrestore(t->queue_lock, flags);
474 }
86db1e29 475}
86db1e29
JA
476EXPORT_SYMBOL(blk_queue_stack_limits);
477
c72758f3
MP
478/**
479 * blk_stack_limits - adjust queue_limits for stacked devices
480 * @t: the stacking driver limits (top)
77634f33 481 * @b: the underlying queue limits (bottom)
c72758f3
MP
482 * @offset: offset to beginning of data within component device
483 *
484 * Description:
485 * Merges two queue_limit structs. Returns 0 if alignment didn't
486 * change. Returns -1 if adding the bottom device caused
487 * misalignment.
488 */
489int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
490 sector_t offset)
491{
492 t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors);
493 t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors);
77634f33 494 t->bounce_pfn = min_not_zero(t->bounce_pfn, b->bounce_pfn);
c72758f3
MP
495
496 t->seg_boundary_mask = min_not_zero(t->seg_boundary_mask,
497 b->seg_boundary_mask);
498
499 t->max_phys_segments = min_not_zero(t->max_phys_segments,
500 b->max_phys_segments);
501
502 t->max_hw_segments = min_not_zero(t->max_hw_segments,
503 b->max_hw_segments);
504
505 t->max_segment_size = min_not_zero(t->max_segment_size,
506 b->max_segment_size);
507
508 t->logical_block_size = max(t->logical_block_size,
509 b->logical_block_size);
510
511 t->physical_block_size = max(t->physical_block_size,
512 b->physical_block_size);
513
514 t->io_min = max(t->io_min, b->io_min);
515 t->no_cluster |= b->no_cluster;
516
517 /* Bottom device offset aligned? */
518 if (offset &&
519 (offset & (b->physical_block_size - 1)) != b->alignment_offset) {
520 t->misaligned = 1;
521 return -1;
522 }
523
524 /* If top has no alignment offset, inherit from bottom */
525 if (!t->alignment_offset)
526 t->alignment_offset =
527 b->alignment_offset & (b->physical_block_size - 1);
528
529 /* Top device aligned on logical block boundary? */
530 if (t->alignment_offset & (t->logical_block_size - 1)) {
531 t->misaligned = 1;
532 return -1;
533 }
534
70dd5bf3
MP
535 /* Find lcm() of optimal I/O size */
536 if (t->io_opt && b->io_opt)
537 t->io_opt = (t->io_opt * b->io_opt) / gcd(t->io_opt, b->io_opt);
538 else if (b->io_opt)
539 t->io_opt = b->io_opt;
540
541 /* Verify that optimal I/O size is a multiple of io_min */
542 if (t->io_min && t->io_opt % t->io_min)
543 return -1;
544
c72758f3
MP
545 return 0;
546}
5d85d324 547EXPORT_SYMBOL(blk_stack_limits);
c72758f3
MP
548
549/**
550 * disk_stack_limits - adjust queue limits for stacked drivers
77634f33 551 * @disk: MD/DM gendisk (top)
c72758f3
MP
552 * @bdev: the underlying block device (bottom)
553 * @offset: offset to beginning of data within component device
554 *
555 * Description:
556 * Merges the limits for two queues. Returns 0 if alignment
557 * didn't change. Returns -1 if adding the bottom device caused
558 * misalignment.
559 */
560void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
561 sector_t offset)
562{
563 struct request_queue *t = disk->queue;
564 struct request_queue *b = bdev_get_queue(bdev);
565
566 offset += get_start_sect(bdev) << 9;
567
568 if (blk_stack_limits(&t->limits, &b->limits, offset) < 0) {
569 char top[BDEVNAME_SIZE], bottom[BDEVNAME_SIZE];
570
571 disk_name(disk, 0, top);
572 bdevname(bdev, bottom);
573
574 printk(KERN_NOTICE "%s: Warning: Device %s is misaligned\n",
575 top, bottom);
576 }
577
578 if (!t->queue_lock)
579 WARN_ON_ONCE(1);
580 else if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags)) {
581 unsigned long flags;
582
583 spin_lock_irqsave(t->queue_lock, flags);
584 if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags))
585 queue_flag_clear(QUEUE_FLAG_CLUSTER, t);
586 spin_unlock_irqrestore(t->queue_lock, flags);
587 }
588}
589EXPORT_SYMBOL(disk_stack_limits);
590
e3790c7d
TH
591/**
592 * blk_queue_dma_pad - set pad mask
593 * @q: the request queue for the device
594 * @mask: pad mask
595 *
27f8221a 596 * Set dma pad mask.
e3790c7d 597 *
27f8221a
FT
598 * Appending pad buffer to a request modifies the last entry of a
599 * scatter list such that it includes the pad buffer.
e3790c7d
TH
600 **/
601void blk_queue_dma_pad(struct request_queue *q, unsigned int mask)
602{
603 q->dma_pad_mask = mask;
604}
605EXPORT_SYMBOL(blk_queue_dma_pad);
606
27f8221a
FT
607/**
608 * blk_queue_update_dma_pad - update pad mask
609 * @q: the request queue for the device
610 * @mask: pad mask
611 *
612 * Update dma pad mask.
613 *
614 * Appending pad buffer to a request modifies the last entry of a
615 * scatter list such that it includes the pad buffer.
616 **/
617void blk_queue_update_dma_pad(struct request_queue *q, unsigned int mask)
618{
619 if (mask > q->dma_pad_mask)
620 q->dma_pad_mask = mask;
621}
622EXPORT_SYMBOL(blk_queue_update_dma_pad);
623
86db1e29
JA
624/**
625 * blk_queue_dma_drain - Set up a drain buffer for excess dma.
86db1e29 626 * @q: the request queue for the device
2fb98e84 627 * @dma_drain_needed: fn which returns non-zero if drain is necessary
86db1e29
JA
628 * @buf: physically contiguous buffer
629 * @size: size of the buffer in bytes
630 *
631 * Some devices have excess DMA problems and can't simply discard (or
632 * zero fill) the unwanted piece of the transfer. They have to have a
633 * real area of memory to transfer it into. The use case for this is
634 * ATAPI devices in DMA mode. If the packet command causes a transfer
635 * bigger than the transfer size some HBAs will lock up if there
636 * aren't DMA elements to contain the excess transfer. What this API
637 * does is adjust the queue so that the buf is always appended
638 * silently to the scatterlist.
639 *
640 * Note: This routine adjusts max_hw_segments to make room for
641 * appending the drain buffer. If you call
642 * blk_queue_max_hw_segments() or blk_queue_max_phys_segments() after
643 * calling this routine, you must set the limit to one fewer than your
644 * device can support otherwise there won't be room for the drain
645 * buffer.
646 */
448da4d2 647int blk_queue_dma_drain(struct request_queue *q,
2fb98e84
TH
648 dma_drain_needed_fn *dma_drain_needed,
649 void *buf, unsigned int size)
86db1e29 650{
ae03bf63 651 if (queue_max_hw_segments(q) < 2 || queue_max_phys_segments(q) < 2)
86db1e29
JA
652 return -EINVAL;
653 /* make room for appending the drain */
ae03bf63
MP
654 blk_queue_max_hw_segments(q, queue_max_hw_segments(q) - 1);
655 blk_queue_max_phys_segments(q, queue_max_phys_segments(q) - 1);
2fb98e84 656 q->dma_drain_needed = dma_drain_needed;
86db1e29
JA
657 q->dma_drain_buffer = buf;
658 q->dma_drain_size = size;
659
660 return 0;
661}
86db1e29
JA
662EXPORT_SYMBOL_GPL(blk_queue_dma_drain);
663
664/**
665 * blk_queue_segment_boundary - set boundary rules for segment merging
666 * @q: the request queue for the device
667 * @mask: the memory boundary mask
668 **/
669void blk_queue_segment_boundary(struct request_queue *q, unsigned long mask)
670{
671 if (mask < PAGE_CACHE_SIZE - 1) {
672 mask = PAGE_CACHE_SIZE - 1;
24c03d47
HH
673 printk(KERN_INFO "%s: set to minimum %lx\n",
674 __func__, mask);
86db1e29
JA
675 }
676
025146e1 677 q->limits.seg_boundary_mask = mask;
86db1e29 678}
86db1e29
JA
679EXPORT_SYMBOL(blk_queue_segment_boundary);
680
681/**
682 * blk_queue_dma_alignment - set dma length and memory alignment
683 * @q: the request queue for the device
684 * @mask: alignment mask
685 *
686 * description:
710027a4 687 * set required memory and length alignment for direct dma transactions.
8feb4d20 688 * this is used when building direct io requests for the queue.
86db1e29
JA
689 *
690 **/
691void blk_queue_dma_alignment(struct request_queue *q, int mask)
692{
693 q->dma_alignment = mask;
694}
86db1e29
JA
695EXPORT_SYMBOL(blk_queue_dma_alignment);
696
697/**
698 * blk_queue_update_dma_alignment - update dma length and memory alignment
699 * @q: the request queue for the device
700 * @mask: alignment mask
701 *
702 * description:
710027a4 703 * update required memory and length alignment for direct dma transactions.
86db1e29
JA
704 * If the requested alignment is larger than the current alignment, then
705 * the current queue alignment is updated to the new value, otherwise it
706 * is left alone. The design of this is to allow multiple objects
707 * (driver, device, transport etc) to set their respective
708 * alignments without having them interfere.
709 *
710 **/
711void blk_queue_update_dma_alignment(struct request_queue *q, int mask)
712{
713 BUG_ON(mask > PAGE_SIZE);
714
715 if (mask > q->dma_alignment)
716 q->dma_alignment = mask;
717}
86db1e29
JA
718EXPORT_SYMBOL(blk_queue_update_dma_alignment);
719
aeb3d3a8 720static int __init blk_settings_init(void)
86db1e29
JA
721{
722 blk_max_low_pfn = max_low_pfn - 1;
723 blk_max_pfn = max_pfn - 1;
724 return 0;
725}
726subsys_initcall(blk_settings_init);