blob: 6375afaedcec1a5e1046a23441e5e410f080cec8 [file] [log] [blame]
Jens Axboe86db1e22008-01-29 14:53:40 +01001/*
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>
Mike Rapoport57c8a662018-10-30 15:09:49 -07009#include <linux/memblock.h> /* for max_pfn/max_low_pfn */
Martin K. Petersen70dd5bf2009-07-31 11:49:12 -040010#include <linux/gcd.h>
Martin K. Petersen2cda2722010-03-15 12:46:51 +010011#include <linux/lcm.h>
Randy Dunlapad5ebd22009-11-11 13:47:45 +010012#include <linux/jiffies.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/gfp.h>
Jens Axboe86db1e22008-01-29 14:53:40 +010014
15#include "blk.h"
Jens Axboe87760e52016-11-09 12:38:14 -070016#include "blk-wbt.h"
Jens Axboe86db1e22008-01-29 14:53:40 +010017
Jens Axboe6728cb02008-01-31 13:03:55 +010018unsigned long blk_max_low_pfn;
Jens Axboe86db1e22008-01-29 14:53:40 +010019EXPORT_SYMBOL(blk_max_low_pfn);
Jens Axboe6728cb02008-01-31 13:03:55 +010020
21unsigned long blk_max_pfn;
Jens Axboe86db1e22008-01-29 14:53:40 +010022
Jens Axboe242f9dc2008-09-14 05:55:09 -070023void blk_queue_rq_timeout(struct request_queue *q, unsigned int timeout)
24{
25 q->rq_timeout = timeout;
26}
27EXPORT_SYMBOL_GPL(blk_queue_rq_timeout);
28
Jens Axboe86db1e22008-01-29 14:53:40 +010029/**
Martin K. Petersene475bba2009-06-16 08:23:52 +020030 * blk_set_default_limits - reset limits to default values
Randy Dunlapf740f5ca2009-06-19 09:18:32 +020031 * @lim: the queue_limits structure to reset
Martin K. Petersene475bba2009-06-16 08:23:52 +020032 *
33 * Description:
Martin K. Petersenb1bd0552012-01-11 16:27:11 +010034 * Returns a queue_limit struct to its default state.
Martin K. Petersene475bba2009-06-16 08:23:52 +020035 */
36void blk_set_default_limits(struct queue_limits *lim)
37{
Martin K. Petersen8a783622010-02-26 00:20:39 -050038 lim->max_segments = BLK_MAX_SEGMENTS;
Christoph Hellwig1e739732017-02-08 14:46:49 +010039 lim->max_discard_segments = 1;
Martin K. Petersen13f05c82010-09-10 20:50:10 +020040 lim->max_integrity_segments = 0;
Martin K. Petersene475bba2009-06-16 08:23:52 +020041 lim->seg_boundary_mask = BLK_SEG_BOUNDARY_MASK;
Keith Busch03100aa2015-08-19 14:24:05 -070042 lim->virt_boundary_mask = 0;
Martin K. Peterseneb28d312010-02-26 00:20:37 -050043 lim->max_segment_size = BLK_MAX_SEGMENT_SIZE;
Keith Busch5f009d32016-02-10 16:52:47 -070044 lim->max_sectors = lim->max_hw_sectors = BLK_SAFE_MAX_SECTORS;
45 lim->max_dev_sectors = 0;
Jens Axboe762380a2014-06-05 13:38:39 -060046 lim->chunk_sectors = 0;
Martin K. Petersen4363ac72012-09-18 12:19:27 -040047 lim->max_write_same_sectors = 0;
Chaitanya Kulkarnia6f07882016-11-30 12:28:59 -080048 lim->max_write_zeroes_sectors = 0;
Martin K. Petersen86b37282009-11-10 11:50:21 +010049 lim->max_discard_sectors = 0;
Jens Axboe0034af02015-07-16 09:14:26 -060050 lim->max_hw_discard_sectors = 0;
Martin K. Petersen86b37282009-11-10 11:50:21 +010051 lim->discard_granularity = 0;
52 lim->discard_alignment = 0;
53 lim->discard_misaligned = 0;
Martin K. Petersene475bba2009-06-16 08:23:52 +020054 lim->logical_block_size = lim->physical_block_size = lim->io_min = 512;
Martin K. Petersen3a02c8e2009-06-18 09:56:03 +020055 lim->bounce_pfn = (unsigned long)(BLK_BOUNCE_ANY >> PAGE_SHIFT);
Martin K. Petersene475bba2009-06-16 08:23:52 +020056 lim->alignment_offset = 0;
57 lim->io_opt = 0;
58 lim->misaligned = 0;
Damien Le Moal797476b2016-10-18 15:40:29 +090059 lim->zoned = BLK_ZONED_NONE;
Martin K. Petersene475bba2009-06-16 08:23:52 +020060}
61EXPORT_SYMBOL(blk_set_default_limits);
62
63/**
Martin K. Petersenb1bd0552012-01-11 16:27:11 +010064 * blk_set_stacking_limits - set default limits for stacking devices
65 * @lim: the queue_limits structure to reset
66 *
67 * Description:
68 * Returns a queue_limit struct to its default state. Should be used
69 * by stacking drivers like DM that have no internal limits.
70 */
71void blk_set_stacking_limits(struct queue_limits *lim)
72{
73 blk_set_default_limits(lim);
74
75 /* Inherit limits from component devices */
Martin K. Petersenb1bd0552012-01-11 16:27:11 +010076 lim->max_segments = USHRT_MAX;
Mike Snitzer42c9cdf2018-07-20 14:57:38 -040077 lim->max_discard_segments = USHRT_MAX;
Martin K. Petersenb1bd0552012-01-11 16:27:11 +010078 lim->max_hw_sectors = UINT_MAX;
Mike Snitzerd82ae522013-10-18 09:44:49 -060079 lim->max_segment_size = UINT_MAX;
Mike Snitzerfe86cdc2012-08-01 10:44:28 +020080 lim->max_sectors = UINT_MAX;
Martin K. Petersenca369d52015-11-13 16:46:48 -050081 lim->max_dev_sectors = UINT_MAX;
Martin K. Petersen4363ac72012-09-18 12:19:27 -040082 lim->max_write_same_sectors = UINT_MAX;
Chaitanya Kulkarnia6f07882016-11-30 12:28:59 -080083 lim->max_write_zeroes_sectors = UINT_MAX;
Martin K. Petersenb1bd0552012-01-11 16:27:11 +010084}
85EXPORT_SYMBOL(blk_set_stacking_limits);
86
87/**
Jens Axboe86db1e22008-01-29 14:53:40 +010088 * blk_queue_make_request - define an alternate make_request function for a device
89 * @q: the request queue for the device to be affected
90 * @mfn: the alternate make_request function
91 *
92 * Description:
93 * The normal way for &struct bios to be passed to a device
94 * driver is for them to be collected into requests on a request
95 * queue, and then to allow the device driver to select requests
96 * off that queue when it is ready. This works well for many block
97 * devices. However some block devices (typically virtual devices
98 * such as md or lvm) do not benefit from the processing on the
99 * request queue, and are served best by having the requests passed
100 * directly to them. This can be achieved by providing a function
101 * to blk_queue_make_request().
102 *
103 * Caveat:
104 * The driver that does this *must* be able to deal appropriately
105 * with buffers in "highmemory". This can be accomplished by either calling
Christoph Hellwigd004a5e72017-11-08 19:13:48 +0100106 * kmap_atomic() to get a temporary kernel mapping, or by calling
Jens Axboe86db1e22008-01-29 14:53:40 +0100107 * blk_queue_bounce() to create a buffer in normal memory.
108 **/
Jens Axboe6728cb02008-01-31 13:03:55 +0100109void blk_queue_make_request(struct request_queue *q, make_request_fn *mfn)
Jens Axboe86db1e22008-01-29 14:53:40 +0100110{
111 /*
112 * set defaults
113 */
114 q->nr_requests = BLKDEV_MAX_RQ;
Milan Broz0e435ac2008-12-03 12:55:08 +0100115
Jens Axboe86db1e22008-01-29 14:53:40 +0100116 q->make_request_fn = mfn;
Jens Axboe86db1e22008-01-29 14:53:40 +0100117 blk_queue_dma_alignment(q, 511);
Jens Axboe86db1e22008-01-29 14:53:40 +0100118
Martin K. Petersene475bba2009-06-16 08:23:52 +0200119 blk_set_default_limits(&q->limits);
Jens Axboe86db1e22008-01-29 14:53:40 +0100120}
Jens Axboe86db1e22008-01-29 14:53:40 +0100121EXPORT_SYMBOL(blk_queue_make_request);
122
123/**
124 * blk_queue_bounce_limit - set bounce buffer limit for queue
Tejun Heocd0aca22009-04-15 22:10:25 +0900125 * @q: the request queue for the device
Santosh Shilimkar9f7e45d2013-07-29 14:17:54 +0100126 * @max_addr: the maximum address the device can handle
Jens Axboe86db1e22008-01-29 14:53:40 +0100127 *
128 * Description:
129 * Different hardware can have different requirements as to what pages
130 * it can do I/O directly to. A low level driver can call
131 * blk_queue_bounce_limit to have lower memory pages allocated as bounce
Santosh Shilimkar9f7e45d2013-07-29 14:17:54 +0100132 * buffers for doing I/O to pages residing above @max_addr.
Jens Axboe86db1e22008-01-29 14:53:40 +0100133 **/
Santosh Shilimkar9f7e45d2013-07-29 14:17:54 +0100134void blk_queue_bounce_limit(struct request_queue *q, u64 max_addr)
Jens Axboe86db1e22008-01-29 14:53:40 +0100135{
Santosh Shilimkar9f7e45d2013-07-29 14:17:54 +0100136 unsigned long b_pfn = max_addr >> PAGE_SHIFT;
Jens Axboe86db1e22008-01-29 14:53:40 +0100137 int dma = 0;
138
139 q->bounce_gfp = GFP_NOIO;
140#if BITS_PER_LONG == 64
Tejun Heocd0aca22009-04-15 22:10:25 +0900141 /*
142 * Assume anything <= 4GB can be handled by IOMMU. Actually
143 * some IOMMUs can handle everything, but I don't know of a
144 * way to test this here.
145 */
146 if (b_pfn < (min_t(u64, 0xffffffffUL, BLK_BOUNCE_HIGH) >> PAGE_SHIFT))
Jens Axboe86db1e22008-01-29 14:53:40 +0100147 dma = 1;
Malahal Naineniefb012b2010-10-01 14:45:27 +0200148 q->limits.bounce_pfn = max(max_low_pfn, b_pfn);
Jens Axboe86db1e22008-01-29 14:53:40 +0100149#else
Jens Axboe6728cb02008-01-31 13:03:55 +0100150 if (b_pfn < blk_max_low_pfn)
Jens Axboe86db1e22008-01-29 14:53:40 +0100151 dma = 1;
Malahal Nainenic49825f2010-09-24 20:25:49 +0200152 q->limits.bounce_pfn = b_pfn;
Jens Axboe260a67a2010-10-01 14:42:43 +0200153#endif
Jens Axboe86db1e22008-01-29 14:53:40 +0100154 if (dma) {
155 init_emergency_isa_pool();
156 q->bounce_gfp = GFP_NOIO | GFP_DMA;
Jens Axboe260a67a2010-10-01 14:42:43 +0200157 q->limits.bounce_pfn = b_pfn;
Jens Axboe86db1e22008-01-29 14:53:40 +0100158 }
159}
Jens Axboe86db1e22008-01-29 14:53:40 +0100160EXPORT_SYMBOL(blk_queue_bounce_limit);
161
162/**
Martin K. Petersenca369d52015-11-13 16:46:48 -0500163 * blk_queue_max_hw_sectors - set max sectors for a request for this queue
164 * @q: the request queue for the device
Martin K. Petersen2800aac2010-02-26 00:20:35 -0500165 * @max_hw_sectors: max hardware sectors in the usual 512b unit
Jens Axboe86db1e22008-01-29 14:53:40 +0100166 *
167 * Description:
Martin K. Petersen2800aac2010-02-26 00:20:35 -0500168 * Enables a low level driver to set a hard upper limit,
169 * max_hw_sectors, on the size of requests. max_hw_sectors is set by
Martin K. Petersen4f258a42015-06-23 12:13:59 -0400170 * the device driver based upon the capabilities of the I/O
171 * controller.
Martin K. Petersen2800aac2010-02-26 00:20:35 -0500172 *
Martin K. Petersenca369d52015-11-13 16:46:48 -0500173 * max_dev_sectors is a hard limit imposed by the storage device for
174 * READ/WRITE requests. It is set by the disk driver.
175 *
Martin K. Petersen2800aac2010-02-26 00:20:35 -0500176 * max_sectors is a soft limit imposed by the block layer for
177 * filesystem type requests. This value can be overridden on a
178 * per-device basis in /sys/block/<device>/queue/max_sectors_kb.
179 * The soft limit can not exceed max_hw_sectors.
Jens Axboe86db1e22008-01-29 14:53:40 +0100180 **/
Martin K. Petersenca369d52015-11-13 16:46:48 -0500181void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_sectors)
Jens Axboe86db1e22008-01-29 14:53:40 +0100182{
Martin K. Petersenca369d52015-11-13 16:46:48 -0500183 struct queue_limits *limits = &q->limits;
184 unsigned int max_sectors;
185
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300186 if ((max_hw_sectors << 9) < PAGE_SIZE) {
187 max_hw_sectors = 1 << (PAGE_SHIFT - 9);
Harvey Harrison24c03d42008-05-01 04:35:17 -0700188 printk(KERN_INFO "%s: set to minimum %d\n",
Martin K. Petersen2800aac2010-02-26 00:20:35 -0500189 __func__, max_hw_sectors);
Jens Axboe86db1e22008-01-29 14:53:40 +0100190 }
191
Jeff Moyer30e2bc02015-08-13 14:57:56 -0400192 limits->max_hw_sectors = max_hw_sectors;
Martin K. Petersenca369d52015-11-13 16:46:48 -0500193 max_sectors = min_not_zero(max_hw_sectors, limits->max_dev_sectors);
194 max_sectors = min_t(unsigned int, max_sectors, BLK_DEF_MAX_SECTORS);
195 limits->max_sectors = max_sectors;
Jan Karadc3b17c2017-02-02 15:56:50 +0100196 q->backing_dev_info->io_pages = max_sectors >> (PAGE_SHIFT - 9);
Jens Axboe86db1e22008-01-29 14:53:40 +0100197}
Martin K. Petersen086fa5f2010-02-26 00:20:38 -0500198EXPORT_SYMBOL(blk_queue_max_hw_sectors);
Jens Axboe86db1e22008-01-29 14:53:40 +0100199
200/**
Jens Axboe762380a2014-06-05 13:38:39 -0600201 * blk_queue_chunk_sectors - set size of the chunk for this queue
202 * @q: the request queue for the device
203 * @chunk_sectors: chunk sectors in the usual 512b unit
204 *
205 * Description:
206 * If a driver doesn't want IOs to cross a given chunk size, it can set
207 * this limit and prevent merging across chunks. Note that the chunk size
Jens Axboe58a49152014-06-10 12:53:56 -0600208 * must currently be a power-of-2 in sectors. Also note that the block
209 * layer must accept a page worth of data at any offset. So if the
210 * crossing of chunks is a hard limitation in the driver, it must still be
211 * prepared to split single page bios.
Jens Axboe762380a2014-06-05 13:38:39 -0600212 **/
213void blk_queue_chunk_sectors(struct request_queue *q, unsigned int chunk_sectors)
214{
215 BUG_ON(!is_power_of_2(chunk_sectors));
216 q->limits.chunk_sectors = chunk_sectors;
217}
218EXPORT_SYMBOL(blk_queue_chunk_sectors);
219
220/**
Christoph Hellwig67efc922009-09-30 13:54:20 +0200221 * blk_queue_max_discard_sectors - set max sectors for a single discard
222 * @q: the request queue for the device
Randy Dunlapc7ebf062009-10-12 08:20:47 +0200223 * @max_discard_sectors: maximum number of sectors to discard
Christoph Hellwig67efc922009-09-30 13:54:20 +0200224 **/
225void blk_queue_max_discard_sectors(struct request_queue *q,
226 unsigned int max_discard_sectors)
227{
Jens Axboe0034af02015-07-16 09:14:26 -0600228 q->limits.max_hw_discard_sectors = max_discard_sectors;
Christoph Hellwig67efc922009-09-30 13:54:20 +0200229 q->limits.max_discard_sectors = max_discard_sectors;
230}
231EXPORT_SYMBOL(blk_queue_max_discard_sectors);
232
233/**
Martin K. Petersen4363ac72012-09-18 12:19:27 -0400234 * blk_queue_max_write_same_sectors - set max sectors for a single write same
235 * @q: the request queue for the device
236 * @max_write_same_sectors: maximum number of sectors to write per command
237 **/
238void blk_queue_max_write_same_sectors(struct request_queue *q,
239 unsigned int max_write_same_sectors)
240{
241 q->limits.max_write_same_sectors = max_write_same_sectors;
242}
243EXPORT_SYMBOL(blk_queue_max_write_same_sectors);
244
245/**
Chaitanya Kulkarnia6f07882016-11-30 12:28:59 -0800246 * blk_queue_max_write_zeroes_sectors - set max sectors for a single
247 * write zeroes
248 * @q: the request queue for the device
249 * @max_write_zeroes_sectors: maximum number of sectors to write per command
250 **/
251void blk_queue_max_write_zeroes_sectors(struct request_queue *q,
252 unsigned int max_write_zeroes_sectors)
253{
254 q->limits.max_write_zeroes_sectors = max_write_zeroes_sectors;
255}
256EXPORT_SYMBOL(blk_queue_max_write_zeroes_sectors);
257
258/**
Martin K. Petersen8a783622010-02-26 00:20:39 -0500259 * blk_queue_max_segments - set max hw segments for a request for this queue
Jens Axboe86db1e22008-01-29 14:53:40 +0100260 * @q: the request queue for the device
261 * @max_segments: max number of segments
262 *
263 * Description:
264 * Enables a low level driver to set an upper limit on the number of
Martin K. Petersen8a783622010-02-26 00:20:39 -0500265 * hw data segments in a request.
Jens Axboe86db1e22008-01-29 14:53:40 +0100266 **/
Martin K. Petersen8a783622010-02-26 00:20:39 -0500267void blk_queue_max_segments(struct request_queue *q, unsigned short max_segments)
Jens Axboe86db1e22008-01-29 14:53:40 +0100268{
269 if (!max_segments) {
270 max_segments = 1;
Harvey Harrison24c03d42008-05-01 04:35:17 -0700271 printk(KERN_INFO "%s: set to minimum %d\n",
272 __func__, max_segments);
Jens Axboe86db1e22008-01-29 14:53:40 +0100273 }
274
Martin K. Petersen8a783622010-02-26 00:20:39 -0500275 q->limits.max_segments = max_segments;
Jens Axboe86db1e22008-01-29 14:53:40 +0100276}
Martin K. Petersen8a783622010-02-26 00:20:39 -0500277EXPORT_SYMBOL(blk_queue_max_segments);
Jens Axboe86db1e22008-01-29 14:53:40 +0100278
279/**
Christoph Hellwig1e739732017-02-08 14:46:49 +0100280 * blk_queue_max_discard_segments - set max segments for discard requests
281 * @q: the request queue for the device
282 * @max_segments: max number of segments
283 *
284 * Description:
285 * Enables a low level driver to set an upper limit on the number of
286 * segments in a discard request.
287 **/
288void blk_queue_max_discard_segments(struct request_queue *q,
289 unsigned short max_segments)
290{
291 q->limits.max_discard_segments = max_segments;
292}
293EXPORT_SYMBOL_GPL(blk_queue_max_discard_segments);
294
295/**
Jens Axboe86db1e22008-01-29 14:53:40 +0100296 * blk_queue_max_segment_size - set max segment size for blk_rq_map_sg
297 * @q: the request queue for the device
298 * @max_size: max size of segment in bytes
299 *
300 * Description:
301 * Enables a low level driver to set an upper limit on the size of a
302 * coalesced segment
303 **/
304void blk_queue_max_segment_size(struct request_queue *q, unsigned int max_size)
305{
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300306 if (max_size < PAGE_SIZE) {
307 max_size = PAGE_SIZE;
Harvey Harrison24c03d42008-05-01 04:35:17 -0700308 printk(KERN_INFO "%s: set to minimum %d\n",
309 __func__, max_size);
Jens Axboe86db1e22008-01-29 14:53:40 +0100310 }
311
Martin K. Petersen025146e2009-05-22 17:17:51 -0400312 q->limits.max_segment_size = max_size;
Jens Axboe86db1e22008-01-29 14:53:40 +0100313}
Jens Axboe86db1e22008-01-29 14:53:40 +0100314EXPORT_SYMBOL(blk_queue_max_segment_size);
315
316/**
Martin K. Petersene1defc42009-05-22 17:17:49 -0400317 * blk_queue_logical_block_size - set logical block size for the queue
Jens Axboe86db1e22008-01-29 14:53:40 +0100318 * @q: the request queue for the device
Martin K. Petersene1defc42009-05-22 17:17:49 -0400319 * @size: the logical block size, in bytes
Jens Axboe86db1e22008-01-29 14:53:40 +0100320 *
321 * Description:
Martin K. Petersene1defc42009-05-22 17:17:49 -0400322 * This should be set to the lowest possible block size that the
323 * storage device can address. The default of 512 covers most
324 * hardware.
Jens Axboe86db1e22008-01-29 14:53:40 +0100325 **/
Martin K. Petersene1defc42009-05-22 17:17:49 -0400326void blk_queue_logical_block_size(struct request_queue *q, unsigned short size)
Jens Axboe86db1e22008-01-29 14:53:40 +0100327{
Martin K. Petersen025146e2009-05-22 17:17:51 -0400328 q->limits.logical_block_size = size;
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400329
330 if (q->limits.physical_block_size < size)
331 q->limits.physical_block_size = size;
332
333 if (q->limits.io_min < q->limits.physical_block_size)
334 q->limits.io_min = q->limits.physical_block_size;
Jens Axboe86db1e22008-01-29 14:53:40 +0100335}
Martin K. Petersene1defc42009-05-22 17:17:49 -0400336EXPORT_SYMBOL(blk_queue_logical_block_size);
Jens Axboe86db1e22008-01-29 14:53:40 +0100337
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400338/**
339 * blk_queue_physical_block_size - set physical block size for the queue
340 * @q: the request queue for the device
341 * @size: the physical block size, in bytes
342 *
343 * Description:
344 * This should be set to the lowest possible sector size that the
345 * hardware can operate on without reverting to read-modify-write
346 * operations.
347 */
Martin K. Petersen892b6f92010-10-13 21:18:03 +0200348void blk_queue_physical_block_size(struct request_queue *q, unsigned int size)
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400349{
350 q->limits.physical_block_size = size;
351
352 if (q->limits.physical_block_size < q->limits.logical_block_size)
353 q->limits.physical_block_size = q->limits.logical_block_size;
354
355 if (q->limits.io_min < q->limits.physical_block_size)
356 q->limits.io_min = q->limits.physical_block_size;
357}
358EXPORT_SYMBOL(blk_queue_physical_block_size);
359
360/**
361 * blk_queue_alignment_offset - set physical block alignment offset
362 * @q: the request queue for the device
Randy Dunlap8ebf9752009-06-11 20:00:41 -0700363 * @offset: alignment offset in bytes
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400364 *
365 * Description:
366 * Some devices are naturally misaligned to compensate for things like
367 * the legacy DOS partition table 63-sector offset. Low-level drivers
368 * should call this function for devices whose first sector is not
369 * naturally aligned.
370 */
371void blk_queue_alignment_offset(struct request_queue *q, unsigned int offset)
372{
373 q->limits.alignment_offset =
374 offset & (q->limits.physical_block_size - 1);
375 q->limits.misaligned = 0;
376}
377EXPORT_SYMBOL(blk_queue_alignment_offset);
378
379/**
Martin K. Petersen7c958e32009-07-31 11:49:11 -0400380 * blk_limits_io_min - set minimum request size for a device
381 * @limits: the queue limits
382 * @min: smallest I/O size in bytes
383 *
384 * Description:
385 * Some devices have an internal block size bigger than the reported
386 * hardware sector size. This function can be used to signal the
387 * smallest I/O the device can perform without incurring a performance
388 * penalty.
389 */
390void blk_limits_io_min(struct queue_limits *limits, unsigned int min)
391{
392 limits->io_min = min;
393
394 if (limits->io_min < limits->logical_block_size)
395 limits->io_min = limits->logical_block_size;
396
397 if (limits->io_min < limits->physical_block_size)
398 limits->io_min = limits->physical_block_size;
399}
400EXPORT_SYMBOL(blk_limits_io_min);
401
402/**
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400403 * blk_queue_io_min - set minimum request size for the queue
404 * @q: the request queue for the device
Randy Dunlap8ebf9752009-06-11 20:00:41 -0700405 * @min: smallest I/O size in bytes
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400406 *
407 * Description:
Martin K. Petersen7e5f5fb2009-07-31 11:49:13 -0400408 * Storage devices may report a granularity or preferred minimum I/O
409 * size which is the smallest request the device can perform without
410 * incurring a performance penalty. For disk drives this is often the
411 * physical block size. For RAID arrays it is often the stripe chunk
412 * size. A properly aligned multiple of minimum_io_size is the
413 * preferred request size for workloads where a high number of I/O
414 * operations is desired.
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400415 */
416void blk_queue_io_min(struct request_queue *q, unsigned int min)
417{
Martin K. Petersen7c958e32009-07-31 11:49:11 -0400418 blk_limits_io_min(&q->limits, min);
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400419}
420EXPORT_SYMBOL(blk_queue_io_min);
421
422/**
Martin K. Petersen3c5820c2009-09-11 21:54:52 +0200423 * blk_limits_io_opt - set optimal request size for a device
424 * @limits: the queue limits
425 * @opt: smallest I/O size in bytes
426 *
427 * Description:
428 * Storage devices may report an optimal I/O size, which is the
429 * device's preferred unit for sustained I/O. This is rarely reported
430 * for disk drives. For RAID arrays it is usually the stripe width or
431 * the internal track size. A properly aligned multiple of
432 * optimal_io_size is the preferred request size for workloads where
433 * sustained throughput is desired.
434 */
435void blk_limits_io_opt(struct queue_limits *limits, unsigned int opt)
436{
437 limits->io_opt = opt;
438}
439EXPORT_SYMBOL(blk_limits_io_opt);
440
441/**
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400442 * blk_queue_io_opt - set optimal request size for the queue
443 * @q: the request queue for the device
Randy Dunlap8ebf9752009-06-11 20:00:41 -0700444 * @opt: optimal request size in bytes
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400445 *
446 * Description:
Martin K. Petersen7e5f5fb2009-07-31 11:49:13 -0400447 * Storage devices may report an optimal I/O size, which is the
448 * device's preferred unit for sustained I/O. This is rarely reported
449 * for disk drives. For RAID arrays it is usually the stripe width or
450 * the internal track size. A properly aligned multiple of
451 * optimal_io_size is the preferred request size for workloads where
452 * sustained throughput is desired.
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400453 */
454void blk_queue_io_opt(struct request_queue *q, unsigned int opt)
455{
Martin K. Petersen3c5820c2009-09-11 21:54:52 +0200456 blk_limits_io_opt(&q->limits, opt);
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400457}
458EXPORT_SYMBOL(blk_queue_io_opt);
459
Jens Axboe86db1e22008-01-29 14:53:40 +0100460/**
461 * blk_queue_stack_limits - inherit underlying queue limits for stacked drivers
462 * @t: the stacking driver (top)
463 * @b: the underlying device (bottom)
464 **/
465void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b)
466{
Martin K. Petersenfef24662009-07-31 11:49:10 -0400467 blk_stack_limits(&t->limits, &b->limits, 0);
Jens Axboe86db1e22008-01-29 14:53:40 +0100468}
Jens Axboe86db1e22008-01-29 14:53:40 +0100469EXPORT_SYMBOL(blk_queue_stack_limits);
470
471/**
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400472 * blk_stack_limits - adjust queue_limits for stacked devices
Martin K. Petersen81744ee2009-12-29 08:35:35 +0100473 * @t: the stacking driver limits (top device)
474 * @b: the underlying queue limits (bottom, component device)
Martin K. Petersene03a72e2010-01-11 03:21:51 -0500475 * @start: first data sector within component device
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400476 *
477 * Description:
Martin K. Petersen81744ee2009-12-29 08:35:35 +0100478 * This function is used by stacking drivers like MD and DM to ensure
479 * that all component devices have compatible block sizes and
480 * alignments. The stacking driver must provide a queue_limits
481 * struct (top) and then iteratively call the stacking function for
482 * all component (bottom) devices. The stacking function will
483 * attempt to combine the values and ensure proper alignment.
484 *
485 * Returns 0 if the top and bottom queue_limits are compatible. The
486 * top device's block sizes and alignment offsets may be adjusted to
487 * ensure alignment with the bottom device. If no compatible sizes
488 * and alignments exist, -1 is returned and the resulting top
489 * queue_limits will have the misaligned flag set to indicate that
490 * the alignment_offset is undefined.
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400491 */
492int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
Martin K. Petersene03a72e2010-01-11 03:21:51 -0500493 sector_t start)
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400494{
Martin K. Petersene03a72e2010-01-11 03:21:51 -0500495 unsigned int top, bottom, alignment, ret = 0;
Martin K. Petersen86b37282009-11-10 11:50:21 +0100496
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400497 t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors);
498 t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors);
Martin K. Petersenca369d52015-11-13 16:46:48 -0500499 t->max_dev_sectors = min_not_zero(t->max_dev_sectors, b->max_dev_sectors);
Martin K. Petersen4363ac72012-09-18 12:19:27 -0400500 t->max_write_same_sectors = min(t->max_write_same_sectors,
501 b->max_write_same_sectors);
Chaitanya Kulkarnia6f07882016-11-30 12:28:59 -0800502 t->max_write_zeroes_sectors = min(t->max_write_zeroes_sectors,
503 b->max_write_zeroes_sectors);
Martin K. Petersen77634f32009-06-09 06:23:22 +0200504 t->bounce_pfn = min_not_zero(t->bounce_pfn, b->bounce_pfn);
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400505
506 t->seg_boundary_mask = min_not_zero(t->seg_boundary_mask,
507 b->seg_boundary_mask);
Keith Busch03100aa2015-08-19 14:24:05 -0700508 t->virt_boundary_mask = min_not_zero(t->virt_boundary_mask,
509 b->virt_boundary_mask);
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400510
Martin K. Petersen8a783622010-02-26 00:20:39 -0500511 t->max_segments = min_not_zero(t->max_segments, b->max_segments);
Christoph Hellwig1e739732017-02-08 14:46:49 +0100512 t->max_discard_segments = min_not_zero(t->max_discard_segments,
513 b->max_discard_segments);
Martin K. Petersen13f05c82010-09-10 20:50:10 +0200514 t->max_integrity_segments = min_not_zero(t->max_integrity_segments,
515 b->max_integrity_segments);
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400516
517 t->max_segment_size = min_not_zero(t->max_segment_size,
518 b->max_segment_size);
519
Martin K. Petersenfe0b3932010-01-11 03:21:47 -0500520 t->misaligned |= b->misaligned;
521
Martin K. Petersene03a72e2010-01-11 03:21:51 -0500522 alignment = queue_limit_alignment_offset(b, start);
Martin K. Petersen9504e082009-12-21 15:55:51 +0100523
Martin K. Petersen81744ee2009-12-29 08:35:35 +0100524 /* Bottom device has different alignment. Check that it is
525 * compatible with the current top alignment.
526 */
Martin K. Petersen9504e082009-12-21 15:55:51 +0100527 if (t->alignment_offset != alignment) {
528
529 top = max(t->physical_block_size, t->io_min)
530 + t->alignment_offset;
Martin K. Petersen81744ee2009-12-29 08:35:35 +0100531 bottom = max(b->physical_block_size, b->io_min) + alignment;
Martin K. Petersen9504e082009-12-21 15:55:51 +0100532
Martin K. Petersen81744ee2009-12-29 08:35:35 +0100533 /* Verify that top and bottom intervals line up */
Mike Snitzerb8839b82014-10-08 18:26:13 -0400534 if (max(top, bottom) % min(top, bottom)) {
Martin K. Petersen9504e082009-12-21 15:55:51 +0100535 t->misaligned = 1;
Martin K. Petersenfe0b3932010-01-11 03:21:47 -0500536 ret = -1;
537 }
Martin K. Petersen9504e082009-12-21 15:55:51 +0100538 }
539
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400540 t->logical_block_size = max(t->logical_block_size,
541 b->logical_block_size);
542
543 t->physical_block_size = max(t->physical_block_size,
544 b->physical_block_size);
545
546 t->io_min = max(t->io_min, b->io_min);
Mike Snitzere9637412015-03-30 13:39:09 -0400547 t->io_opt = lcm_not_zero(t->io_opt, b->io_opt);
Martin K. Petersen9504e082009-12-21 15:55:51 +0100548
Martin K. Petersen81744ee2009-12-29 08:35:35 +0100549 /* Physical block size a multiple of the logical block size? */
Martin K. Petersen9504e082009-12-21 15:55:51 +0100550 if (t->physical_block_size & (t->logical_block_size - 1)) {
551 t->physical_block_size = t->logical_block_size;
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400552 t->misaligned = 1;
Martin K. Petersenfe0b3932010-01-11 03:21:47 -0500553 ret = -1;
Martin K. Petersen86b37282009-11-10 11:50:21 +0100554 }
555
Martin K. Petersen81744ee2009-12-29 08:35:35 +0100556 /* Minimum I/O a multiple of the physical block size? */
Martin K. Petersen9504e082009-12-21 15:55:51 +0100557 if (t->io_min & (t->physical_block_size - 1)) {
558 t->io_min = t->physical_block_size;
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400559 t->misaligned = 1;
Martin K. Petersenfe0b3932010-01-11 03:21:47 -0500560 ret = -1;
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400561 }
562
Martin K. Petersen81744ee2009-12-29 08:35:35 +0100563 /* Optimal I/O a multiple of the physical block size? */
Martin K. Petersen9504e082009-12-21 15:55:51 +0100564 if (t->io_opt & (t->physical_block_size - 1)) {
565 t->io_opt = 0;
566 t->misaligned = 1;
Martin K. Petersenfe0b3932010-01-11 03:21:47 -0500567 ret = -1;
Martin K. Petersen9504e082009-12-21 15:55:51 +0100568 }
Martin K. Petersen70dd5bf2009-07-31 11:49:12 -0400569
Kent Overstreetc78afc62013-07-11 22:39:53 -0700570 t->raid_partial_stripes_expensive =
571 max(t->raid_partial_stripes_expensive,
572 b->raid_partial_stripes_expensive);
573
Martin K. Petersen81744ee2009-12-29 08:35:35 +0100574 /* Find lowest common alignment_offset */
Mike Snitzere9637412015-03-30 13:39:09 -0400575 t->alignment_offset = lcm_not_zero(t->alignment_offset, alignment)
Mike Snitzerb8839b82014-10-08 18:26:13 -0400576 % max(t->physical_block_size, t->io_min);
Martin K. Petersen70dd5bf2009-07-31 11:49:12 -0400577
Martin K. Petersen81744ee2009-12-29 08:35:35 +0100578 /* Verify that new alignment_offset is on a logical block boundary */
Martin K. Petersenfe0b3932010-01-11 03:21:47 -0500579 if (t->alignment_offset & (t->logical_block_size - 1)) {
Martin K. Petersen9504e082009-12-21 15:55:51 +0100580 t->misaligned = 1;
Martin K. Petersenfe0b3932010-01-11 03:21:47 -0500581 ret = -1;
582 }
Martin K. Petersen9504e082009-12-21 15:55:51 +0100583
584 /* Discard alignment and granularity */
585 if (b->discard_granularity) {
Martin K. Petersene03a72e2010-01-11 03:21:51 -0500586 alignment = queue_limit_discard_alignment(b, start);
Martin K. Petersen9504e082009-12-21 15:55:51 +0100587
588 if (t->discard_granularity != 0 &&
589 t->discard_alignment != alignment) {
590 top = t->discard_granularity + t->discard_alignment;
591 bottom = b->discard_granularity + alignment;
592
593 /* Verify that top and bottom intervals line up */
Shaohua Li8dd2cb72012-12-14 11:15:36 +0800594 if ((max(top, bottom) % min(top, bottom)) != 0)
Martin K. Petersen9504e082009-12-21 15:55:51 +0100595 t->discard_misaligned = 1;
596 }
597
Martin K. Petersen81744ee2009-12-29 08:35:35 +0100598 t->max_discard_sectors = min_not_zero(t->max_discard_sectors,
599 b->max_discard_sectors);
Jens Axboe0034af02015-07-16 09:14:26 -0600600 t->max_hw_discard_sectors = min_not_zero(t->max_hw_discard_sectors,
601 b->max_hw_discard_sectors);
Martin K. Petersen9504e082009-12-21 15:55:51 +0100602 t->discard_granularity = max(t->discard_granularity,
603 b->discard_granularity);
Mike Snitzere9637412015-03-30 13:39:09 -0400604 t->discard_alignment = lcm_not_zero(t->discard_alignment, alignment) %
Shaohua Li8dd2cb72012-12-14 11:15:36 +0800605 t->discard_granularity;
Martin K. Petersen9504e082009-12-21 15:55:51 +0100606 }
607
Hannes Reinecke987b3b22016-10-18 15:40:31 +0900608 if (b->chunk_sectors)
609 t->chunk_sectors = min_not_zero(t->chunk_sectors,
610 b->chunk_sectors);
611
Martin K. Petersenfe0b3932010-01-11 03:21:47 -0500612 return ret;
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400613}
Mike Snitzer5d85d322009-05-28 11:04:53 +0200614EXPORT_SYMBOL(blk_stack_limits);
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400615
616/**
Martin K. Petersen17be8c22010-01-11 03:21:49 -0500617 * bdev_stack_limits - adjust queue limits for stacked drivers
618 * @t: the stacking driver limits (top device)
619 * @bdev: the component block_device (bottom)
620 * @start: first data sector within component device
621 *
622 * Description:
623 * Merges queue limits for a top device and a block_device. Returns
624 * 0 if alignment didn't change. Returns -1 if adding the bottom
625 * device caused misalignment.
626 */
627int bdev_stack_limits(struct queue_limits *t, struct block_device *bdev,
628 sector_t start)
629{
630 struct request_queue *bq = bdev_get_queue(bdev);
631
632 start += get_start_sect(bdev);
633
Martin K. Petersene03a72e2010-01-11 03:21:51 -0500634 return blk_stack_limits(t, &bq->limits, start);
Martin K. Petersen17be8c22010-01-11 03:21:49 -0500635}
636EXPORT_SYMBOL(bdev_stack_limits);
637
638/**
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400639 * disk_stack_limits - adjust queue limits for stacked drivers
Martin K. Petersen77634f32009-06-09 06:23:22 +0200640 * @disk: MD/DM gendisk (top)
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400641 * @bdev: the underlying block device (bottom)
642 * @offset: offset to beginning of data within component device
643 *
644 * Description:
Martin K. Petersene03a72e2010-01-11 03:21:51 -0500645 * Merges the limits for a top level gendisk and a bottom level
646 * block_device.
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400647 */
648void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
649 sector_t offset)
650{
651 struct request_queue *t = disk->queue;
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400652
Martin K. Petersene03a72e2010-01-11 03:21:51 -0500653 if (bdev_stack_limits(&t->limits, bdev, offset >> 9) < 0) {
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400654 char top[BDEVNAME_SIZE], bottom[BDEVNAME_SIZE];
655
656 disk_name(disk, 0, top);
657 bdevname(bdev, bottom);
658
659 printk(KERN_NOTICE "%s: Warning: Device %s is misaligned\n",
660 top, bottom);
661 }
Martin K. Petersenc72758f2009-05-22 17:17:53 -0400662}
663EXPORT_SYMBOL(disk_stack_limits);
664
665/**
Tejun Heoe3790c72008-03-04 11:18:17 +0100666 * blk_queue_dma_pad - set pad mask
667 * @q: the request queue for the device
668 * @mask: pad mask
669 *
FUJITA Tomonori27f82212008-07-04 09:30:03 +0200670 * Set dma pad mask.
Tejun Heoe3790c72008-03-04 11:18:17 +0100671 *
FUJITA Tomonori27f82212008-07-04 09:30:03 +0200672 * Appending pad buffer to a request modifies the last entry of a
673 * scatter list such that it includes the pad buffer.
Tejun Heoe3790c72008-03-04 11:18:17 +0100674 **/
675void blk_queue_dma_pad(struct request_queue *q, unsigned int mask)
676{
677 q->dma_pad_mask = mask;
678}
679EXPORT_SYMBOL(blk_queue_dma_pad);
680
681/**
FUJITA Tomonori27f82212008-07-04 09:30:03 +0200682 * blk_queue_update_dma_pad - update pad mask
683 * @q: the request queue for the device
684 * @mask: pad mask
685 *
686 * Update dma pad mask.
687 *
688 * Appending pad buffer to a request modifies the last entry of a
689 * scatter list such that it includes the pad buffer.
690 **/
691void blk_queue_update_dma_pad(struct request_queue *q, unsigned int mask)
692{
693 if (mask > q->dma_pad_mask)
694 q->dma_pad_mask = mask;
695}
696EXPORT_SYMBOL(blk_queue_update_dma_pad);
697
698/**
Jens Axboe86db1e22008-01-29 14:53:40 +0100699 * blk_queue_dma_drain - Set up a drain buffer for excess dma.
Jens Axboe86db1e22008-01-29 14:53:40 +0100700 * @q: the request queue for the device
Tejun Heo2fb98e82008-02-19 11:36:53 +0100701 * @dma_drain_needed: fn which returns non-zero if drain is necessary
Jens Axboe86db1e22008-01-29 14:53:40 +0100702 * @buf: physically contiguous buffer
703 * @size: size of the buffer in bytes
704 *
705 * Some devices have excess DMA problems and can't simply discard (or
706 * zero fill) the unwanted piece of the transfer. They have to have a
707 * real area of memory to transfer it into. The use case for this is
708 * ATAPI devices in DMA mode. If the packet command causes a transfer
709 * bigger than the transfer size some HBAs will lock up if there
710 * aren't DMA elements to contain the excess transfer. What this API
711 * does is adjust the queue so that the buf is always appended
712 * silently to the scatterlist.
713 *
Martin K. Petersen8a783622010-02-26 00:20:39 -0500714 * Note: This routine adjusts max_hw_segments to make room for appending
715 * the drain buffer. If you call blk_queue_max_segments() after calling
716 * this routine, you must set the limit to one fewer than your device
717 * can support otherwise there won't be room for the drain buffer.
Jens Axboe86db1e22008-01-29 14:53:40 +0100718 */
Harvey Harrison448da4d2008-03-04 11:30:18 +0100719int blk_queue_dma_drain(struct request_queue *q,
Tejun Heo2fb98e82008-02-19 11:36:53 +0100720 dma_drain_needed_fn *dma_drain_needed,
721 void *buf, unsigned int size)
Jens Axboe86db1e22008-01-29 14:53:40 +0100722{
Martin K. Petersen8a783622010-02-26 00:20:39 -0500723 if (queue_max_segments(q) < 2)
Jens Axboe86db1e22008-01-29 14:53:40 +0100724 return -EINVAL;
725 /* make room for appending the drain */
Martin K. Petersen8a783622010-02-26 00:20:39 -0500726 blk_queue_max_segments(q, queue_max_segments(q) - 1);
Tejun Heo2fb98e82008-02-19 11:36:53 +0100727 q->dma_drain_needed = dma_drain_needed;
Jens Axboe86db1e22008-01-29 14:53:40 +0100728 q->dma_drain_buffer = buf;
729 q->dma_drain_size = size;
730
731 return 0;
732}
Jens Axboe86db1e22008-01-29 14:53:40 +0100733EXPORT_SYMBOL_GPL(blk_queue_dma_drain);
734
735/**
736 * blk_queue_segment_boundary - set boundary rules for segment merging
737 * @q: the request queue for the device
738 * @mask: the memory boundary mask
739 **/
740void blk_queue_segment_boundary(struct request_queue *q, unsigned long mask)
741{
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300742 if (mask < PAGE_SIZE - 1) {
743 mask = PAGE_SIZE - 1;
Harvey Harrison24c03d42008-05-01 04:35:17 -0700744 printk(KERN_INFO "%s: set to minimum %lx\n",
745 __func__, mask);
Jens Axboe86db1e22008-01-29 14:53:40 +0100746 }
747
Martin K. Petersen025146e2009-05-22 17:17:51 -0400748 q->limits.seg_boundary_mask = mask;
Jens Axboe86db1e22008-01-29 14:53:40 +0100749}
Jens Axboe86db1e22008-01-29 14:53:40 +0100750EXPORT_SYMBOL(blk_queue_segment_boundary);
751
752/**
Keith Busch03100aa2015-08-19 14:24:05 -0700753 * blk_queue_virt_boundary - set boundary rules for bio merging
754 * @q: the request queue for the device
755 * @mask: the memory boundary mask
756 **/
757void blk_queue_virt_boundary(struct request_queue *q, unsigned long mask)
758{
759 q->limits.virt_boundary_mask = mask;
760}
761EXPORT_SYMBOL(blk_queue_virt_boundary);
762
763/**
Jens Axboe86db1e22008-01-29 14:53:40 +0100764 * blk_queue_dma_alignment - set dma length and memory alignment
765 * @q: the request queue for the device
766 * @mask: alignment mask
767 *
768 * description:
Randy Dunlap710027a2008-08-19 20:13:11 +0200769 * set required memory and length alignment for direct dma transactions.
Alan Cox8feb4d22009-04-01 15:01:39 +0100770 * this is used when building direct io requests for the queue.
Jens Axboe86db1e22008-01-29 14:53:40 +0100771 *
772 **/
773void blk_queue_dma_alignment(struct request_queue *q, int mask)
774{
775 q->dma_alignment = mask;
776}
Jens Axboe86db1e22008-01-29 14:53:40 +0100777EXPORT_SYMBOL(blk_queue_dma_alignment);
778
779/**
780 * blk_queue_update_dma_alignment - update dma length and memory alignment
781 * @q: the request queue for the device
782 * @mask: alignment mask
783 *
784 * description:
Randy Dunlap710027a2008-08-19 20:13:11 +0200785 * update required memory and length alignment for direct dma transactions.
Jens Axboe86db1e22008-01-29 14:53:40 +0100786 * If the requested alignment is larger than the current alignment, then
787 * the current queue alignment is updated to the new value, otherwise it
788 * is left alone. The design of this is to allow multiple objects
789 * (driver, device, transport etc) to set their respective
790 * alignments without having them interfere.
791 *
792 **/
793void blk_queue_update_dma_alignment(struct request_queue *q, int mask)
794{
795 BUG_ON(mask > PAGE_SIZE);
796
797 if (mask > q->dma_alignment)
798 q->dma_alignment = mask;
799}
Jens Axboe86db1e22008-01-29 14:53:40 +0100800EXPORT_SYMBOL(blk_queue_update_dma_alignment);
801
Jens Axboe93e9d8e2016-04-12 12:32:46 -0600802/**
Jens Axboed278d4a2016-03-30 10:21:08 -0600803 * blk_set_queue_depth - tell the block layer about the device queue depth
804 * @q: the request queue for the device
805 * @depth: queue depth
806 *
807 */
808void blk_set_queue_depth(struct request_queue *q, unsigned int depth)
809{
810 q->queue_depth = depth;
Josef Bacika7905042018-07-03 09:32:35 -0600811 wbt_set_queue_depth(q, depth);
Jens Axboed278d4a2016-03-30 10:21:08 -0600812}
813EXPORT_SYMBOL(blk_set_queue_depth);
814
815/**
Jens Axboe93e9d8e2016-04-12 12:32:46 -0600816 * blk_queue_write_cache - configure queue's write cache
817 * @q: the request queue for the device
818 * @wc: write back cache on or off
819 * @fua: device supports FUA writes, if true
820 *
821 * Tell the block layer about the write cache of @q.
822 */
823void blk_queue_write_cache(struct request_queue *q, bool wc, bool fua)
824{
Jens Axboec888a8f2016-04-13 13:33:19 -0600825 if (wc)
Christoph Hellwig57d74df2018-11-14 17:02:07 +0100826 blk_queue_flag_set(QUEUE_FLAG_WC, q);
Jens Axboec888a8f2016-04-13 13:33:19 -0600827 else
Christoph Hellwig57d74df2018-11-14 17:02:07 +0100828 blk_queue_flag_clear(QUEUE_FLAG_WC, q);
Jens Axboec888a8f2016-04-13 13:33:19 -0600829 if (fua)
Christoph Hellwig57d74df2018-11-14 17:02:07 +0100830 blk_queue_flag_set(QUEUE_FLAG_FUA, q);
Jens Axboec888a8f2016-04-13 13:33:19 -0600831 else
Christoph Hellwig57d74df2018-11-14 17:02:07 +0100832 blk_queue_flag_clear(QUEUE_FLAG_FUA, q);
Jens Axboe87760e52016-11-09 12:38:14 -0700833
Josef Bacika7905042018-07-03 09:32:35 -0600834 wbt_set_write_cache(q, test_bit(QUEUE_FLAG_WC, &q->queue_flags));
Jens Axboe93e9d8e2016-04-12 12:32:46 -0600835}
836EXPORT_SYMBOL_GPL(blk_queue_write_cache);
837
Harvey Harrisonaeb3d3a2008-08-28 09:27:42 +0200838static int __init blk_settings_init(void)
Jens Axboe86db1e22008-01-29 14:53:40 +0100839{
840 blk_max_low_pfn = max_low_pfn - 1;
841 blk_max_pfn = max_pfn - 1;
842 return 0;
843}
844subsys_initcall(blk_settings_init);