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 */
13 unsigned long blk_max_low_pfn
;
14 EXPORT_SYMBOL(blk_max_low_pfn
);
16 unsigned long blk_max_pfn
;
17 EXPORT_SYMBOL(blk_max_pfn
);
20 * blk_queue_prep_rq - set a prepare_request function for queue
22 * @pfn: prepare_request function
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.
30 void blk_queue_prep_rq(struct request_queue
*q
, prep_rq_fn
*pfn
)
34 EXPORT_SYMBOL(blk_queue_prep_rq
);
37 * blk_queue_merge_bvec - set a merge_bvec function for queue
39 * @mbfn: merge_bvec_fn
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
52 void blk_queue_merge_bvec(struct request_queue
*q
, merge_bvec_fn
*mbfn
)
54 q
->merge_bvec_fn
= mbfn
;
56 EXPORT_SYMBOL(blk_queue_merge_bvec
);
58 void blk_queue_softirq_done(struct request_queue
*q
, softirq_done_fn
*fn
)
60 q
->softirq_done_fn
= fn
;
62 EXPORT_SYMBOL(blk_queue_softirq_done
);
65 * blk_queue_make_request - define an alternate make_request function for a device
66 * @q: the request queue for the device to be affected
67 * @mfn: the alternate make_request function
70 * The normal way for &struct bios to be passed to a device
71 * driver is for them to be collected into requests on a request
72 * queue, and then to allow the device driver to select requests
73 * off that queue when it is ready. This works well for many block
74 * devices. However some block devices (typically virtual devices
75 * such as md or lvm) do not benefit from the processing on the
76 * request queue, and are served best by having the requests passed
77 * directly to them. This can be achieved by providing a function
78 * to blk_queue_make_request().
81 * The driver that does this *must* be able to deal appropriately
82 * with buffers in "highmemory". This can be accomplished by either calling
83 * __bio_kmap_atomic() to get a temporary kernel mapping, or by calling
84 * blk_queue_bounce() to create a buffer in normal memory.
86 void blk_queue_make_request(struct request_queue
*q
, make_request_fn
*mfn
)
91 q
->nr_requests
= BLKDEV_MAX_RQ
;
92 blk_queue_max_phys_segments(q
, MAX_PHYS_SEGMENTS
);
93 blk_queue_max_hw_segments(q
, MAX_HW_SEGMENTS
);
94 q
->make_request_fn
= mfn
;
95 q
->backing_dev_info
.ra_pages
=
96 (VM_MAX_READAHEAD
* 1024) / PAGE_CACHE_SIZE
;
97 q
->backing_dev_info
.state
= 0;
98 q
->backing_dev_info
.capabilities
= BDI_CAP_MAP_COPY
;
99 blk_queue_max_sectors(q
, SAFE_MAX_SECTORS
);
100 blk_queue_hardsect_size(q
, 512);
101 blk_queue_dma_alignment(q
, 511);
102 blk_queue_congestion_threshold(q
);
103 q
->nr_batching
= BLK_BATCH_REQ
;
105 q
->unplug_thresh
= 4; /* hmm */
106 q
->unplug_delay
= (3 * HZ
) / 1000; /* 3 milliseconds */
107 if (q
->unplug_delay
== 0)
110 INIT_WORK(&q
->unplug_work
, blk_unplug_work
);
112 q
->unplug_timer
.function
= blk_unplug_timeout
;
113 q
->unplug_timer
.data
= (unsigned long)q
;
116 * by default assume old behaviour and bounce for any highmem page
118 blk_queue_bounce_limit(q
, BLK_BOUNCE_HIGH
);
120 EXPORT_SYMBOL(blk_queue_make_request
);
123 * blk_queue_bounce_limit - set bounce buffer limit for queue
124 * @q: the request queue for the device
125 * @dma_addr: bus address limit
128 * Different hardware can have different requirements as to what pages
129 * it can do I/O directly to. A low level driver can call
130 * blk_queue_bounce_limit to have lower memory pages allocated as bounce
131 * buffers for doing I/O to pages residing above @page.
133 void blk_queue_bounce_limit(struct request_queue
*q
, u64 dma_addr
)
135 unsigned long b_pfn
= dma_addr
>> PAGE_SHIFT
;
138 q
->bounce_gfp
= GFP_NOIO
;
139 #if BITS_PER_LONG == 64
140 /* Assume anything <= 4GB can be handled by IOMMU.
141 Actually some IOMMUs can handle everything, but I don't
142 know of a way to test this here. */
143 <<<<<<< HEAD
:block
/blk
-settings
.c
144 if (b_pfn
< (min_t(u64
, 0xffffffff, BLK_BOUNCE_HIGH
) >> PAGE_SHIFT
))
146 if (b_pfn
<= (min_t(u64
, 0xffffffff, BLK_BOUNCE_HIGH
) >> PAGE_SHIFT
))
147 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:block
/blk
-settings
.c
149 q
->bounce_pfn
= max_low_pfn
;
151 if (b_pfn
< blk_max_low_pfn
)
153 q
->bounce_pfn
= b_pfn
;
156 init_emergency_isa_pool();
157 q
->bounce_gfp
= GFP_NOIO
| GFP_DMA
;
158 q
->bounce_pfn
= b_pfn
;
161 EXPORT_SYMBOL(blk_queue_bounce_limit
);
164 * blk_queue_max_sectors - set max sectors for a request for this queue
165 * @q: the request queue for the device
166 * @max_sectors: max sectors in the usual 512b unit
169 * Enables a low level driver to set an upper limit on the size of
172 void blk_queue_max_sectors(struct request_queue
*q
, unsigned int max_sectors
)
174 if ((max_sectors
<< 9) < PAGE_CACHE_SIZE
) {
175 max_sectors
= 1 << (PAGE_CACHE_SHIFT
- 9);
176 printk(KERN_INFO
"%s: set to minimum %d\n", __FUNCTION__
,
180 if (BLK_DEF_MAX_SECTORS
> max_sectors
)
181 q
->max_hw_sectors
= q
->max_sectors
= max_sectors
;
183 q
->max_sectors
= BLK_DEF_MAX_SECTORS
;
184 q
->max_hw_sectors
= max_sectors
;
187 EXPORT_SYMBOL(blk_queue_max_sectors
);
190 * blk_queue_max_phys_segments - set max phys segments for a request for this queue
191 * @q: the request queue for the device
192 * @max_segments: max number of segments
195 * Enables a low level driver to set an upper limit on the number of
196 * physical data segments in a request. This would be the largest sized
197 * scatter list the driver could handle.
199 void blk_queue_max_phys_segments(struct request_queue
*q
,
200 unsigned short max_segments
)
204 printk(KERN_INFO
"%s: set to minimum %d\n", __FUNCTION__
,
208 q
->max_phys_segments
= max_segments
;
210 EXPORT_SYMBOL(blk_queue_max_phys_segments
);
213 * blk_queue_max_hw_segments - set max hw segments for a request for this queue
214 * @q: the request queue for the device
215 * @max_segments: max number of segments
218 * Enables a low level driver to set an upper limit on the number of
219 * hw data segments in a request. This would be the largest number of
220 * address/length pairs the host adapter can actually give as once
223 void blk_queue_max_hw_segments(struct request_queue
*q
,
224 unsigned short max_segments
)
228 printk(KERN_INFO
"%s: set to minimum %d\n", __FUNCTION__
,
232 q
->max_hw_segments
= max_segments
;
234 EXPORT_SYMBOL(blk_queue_max_hw_segments
);
237 * blk_queue_max_segment_size - set max segment size for blk_rq_map_sg
238 * @q: the request queue for the device
239 * @max_size: max size of segment in bytes
242 * Enables a low level driver to set an upper limit on the size of a
245 void blk_queue_max_segment_size(struct request_queue
*q
, unsigned int max_size
)
247 if (max_size
< PAGE_CACHE_SIZE
) {
248 max_size
= PAGE_CACHE_SIZE
;
249 printk(KERN_INFO
"%s: set to minimum %d\n", __FUNCTION__
,
253 q
->max_segment_size
= max_size
;
255 EXPORT_SYMBOL(blk_queue_max_segment_size
);
258 * blk_queue_hardsect_size - set hardware sector size for the queue
259 * @q: the request queue for the device
260 * @size: the hardware sector size, in bytes
263 * This should typically be set to the lowest possible sector size
264 * that the hardware can operate on (possible without reverting to
265 * even internal read-modify-write operations). Usually the default
266 * of 512 covers most hardware.
268 void blk_queue_hardsect_size(struct request_queue
*q
, unsigned short size
)
270 q
->hardsect_size
= size
;
272 EXPORT_SYMBOL(blk_queue_hardsect_size
);
275 * Returns the minimum that is _not_ zero, unless both are zero.
277 #define min_not_zero(l, r) (l == 0) ? r : ((r == 0) ? l : min(l, r))
280 * blk_queue_stack_limits - inherit underlying queue limits for stacked drivers
281 * @t: the stacking driver (top)
282 * @b: the underlying device (bottom)
284 void blk_queue_stack_limits(struct request_queue
*t
, struct request_queue
*b
)
286 /* zero is "infinity" */
287 t
->max_sectors
= min_not_zero(t
->max_sectors
, b
->max_sectors
);
288 t
->max_hw_sectors
= min_not_zero(t
->max_hw_sectors
, b
->max_hw_sectors
);
290 t
->max_phys_segments
= min(t
->max_phys_segments
, b
->max_phys_segments
);
291 t
->max_hw_segments
= min(t
->max_hw_segments
, b
->max_hw_segments
);
292 t
->max_segment_size
= min(t
->max_segment_size
, b
->max_segment_size
);
293 t
->hardsect_size
= max(t
->hardsect_size
, b
->hardsect_size
);
294 if (!test_bit(QUEUE_FLAG_CLUSTER
, &b
->queue_flags
))
295 clear_bit(QUEUE_FLAG_CLUSTER
, &t
->queue_flags
);
297 EXPORT_SYMBOL(blk_queue_stack_limits
);
300 <<<<<<< HEAD:block/blk-settings.c
301 * blk_queue_dma_drain - Set up a drain buffer for excess dma.
303 * blk_queue_dma_pad - set pad mask
304 * @q: the request queue for the device
307 * Set pad mask. Direct IO requests are padded to the mask specified.
308 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:block/blk-settings.c
310 <<<<<<< HEAD:block/blk-settings.c
312 * Appending pad buffer to a request modifies ->data_len such that it
313 * includes the pad buffer. The original requested data length can be
314 * obtained using blk_rq_raw_data_len().
316 void blk_queue_dma_pad(struct request_queue
*q
, unsigned int mask
)
318 q
->dma_pad_mask
= mask
;
320 EXPORT_SYMBOL(blk_queue_dma_pad
);
323 * blk_queue_dma_drain - Set up a drain buffer for excess dma.
324 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:block/blk-settings.c
325 * @q: the request queue for the device
326 <<<<<<< HEAD:block/blk-settings.c
328 * @dma_drain_needed: fn which returns non-zero if drain is necessary
329 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:block/blk-settings.c
330 * @buf: physically contiguous buffer
331 * @size: size of the buffer in bytes
333 * Some devices have excess DMA problems and can't simply discard (or
334 * zero fill) the unwanted piece of the transfer. They have to have a
335 * real area of memory to transfer it into. The use case for this is
336 * ATAPI devices in DMA mode. If the packet command causes a transfer
337 * bigger than the transfer size some HBAs will lock up if there
338 * aren't DMA elements to contain the excess transfer. What this API
339 * does is adjust the queue so that the buf is always appended
340 * silently to the scatterlist.
342 * Note: This routine adjusts max_hw_segments to make room for
343 * appending the drain buffer. If you call
344 * blk_queue_max_hw_segments() or blk_queue_max_phys_segments() after
345 * calling this routine, you must set the limit to one fewer than your
346 * device can support otherwise there won't be room for the drain
349 <<<<<<< HEAD
:block
/blk
-settings
.c
350 int blk_queue_dma_drain(struct request_queue
*q
, void *buf
,
353 int blk_queue_dma_drain(struct request_queue
*q
,
354 dma_drain_needed_fn
*dma_drain_needed
,
355 void *buf
, unsigned int size
)
356 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:block
/blk
-settings
.c
358 if (q
->max_hw_segments
< 2 || q
->max_phys_segments
< 2)
360 /* make room for appending the drain */
361 --q
->max_hw_segments
;
362 --q
->max_phys_segments
;
363 <<<<<<< HEAD
:block
/blk
-settings
.c
365 q
->dma_drain_needed
= dma_drain_needed
;
366 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:block
/blk
-settings
.c
367 q
->dma_drain_buffer
= buf
;
368 q
->dma_drain_size
= size
;
372 EXPORT_SYMBOL_GPL(blk_queue_dma_drain
);
375 * blk_queue_segment_boundary - set boundary rules for segment merging
376 * @q: the request queue for the device
377 * @mask: the memory boundary mask
379 void blk_queue_segment_boundary(struct request_queue
*q
, unsigned long mask
)
381 if (mask
< PAGE_CACHE_SIZE
- 1) {
382 mask
= PAGE_CACHE_SIZE
- 1;
383 printk(KERN_INFO
"%s: set to minimum %lx\n", __FUNCTION__
,
387 q
->seg_boundary_mask
= mask
;
389 EXPORT_SYMBOL(blk_queue_segment_boundary
);
392 * blk_queue_dma_alignment - set dma length and memory alignment
393 * @q: the request queue for the device
394 * @mask: alignment mask
397 * set required memory and length aligment for direct dma transactions.
398 * this is used when buiding direct io requests for the queue.
401 void blk_queue_dma_alignment(struct request_queue
*q
, int mask
)
403 q
->dma_alignment
= mask
;
405 EXPORT_SYMBOL(blk_queue_dma_alignment
);
408 * blk_queue_update_dma_alignment - update dma length and memory alignment
409 * @q: the request queue for the device
410 * @mask: alignment mask
413 * update required memory and length aligment for direct dma transactions.
414 * If the requested alignment is larger than the current alignment, then
415 * the current queue alignment is updated to the new value, otherwise it
416 * is left alone. The design of this is to allow multiple objects
417 * (driver, device, transport etc) to set their respective
418 * alignments without having them interfere.
421 void blk_queue_update_dma_alignment(struct request_queue
*q
, int mask
)
423 BUG_ON(mask
> PAGE_SIZE
);
425 if (mask
> q
->dma_alignment
)
426 q
->dma_alignment
= mask
;
428 EXPORT_SYMBOL(blk_queue_update_dma_alignment
);
430 <<<<<<< HEAD
:block
/blk
-settings
.c
431 int __init
blk_settings_init(void)
433 static int __init
blk_settings_init(void)
434 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:block
/blk
-settings
.c
436 blk_max_low_pfn
= max_low_pfn
- 1;
437 blk_max_pfn
= max_pfn
- 1;
440 subsys_initcall(blk_settings_init
);