blk-settings.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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 */
  10. #include "blk.h"
  11. unsigned long blk_max_low_pfn;
  12. EXPORT_SYMBOL(blk_max_low_pfn);
  13. unsigned long blk_max_pfn;
  14. /**
  15. * blk_queue_prep_rq - set a prepare_request function for queue
  16. * @q: queue
  17. * @pfn: prepare_request function
  18. *
  19. * It's possible for a queue to register a prepare_request callback which
  20. * is invoked before the request is handed to the request_fn. The goal of
  21. * the function is to prepare a request for I/O, it can be used to build a
  22. * cdb from the request data for instance.
  23. *
  24. */
  25. void blk_queue_prep_rq(struct request_queue *q, prep_rq_fn *pfn)
  26. {
  27. q->prep_rq_fn = pfn;
  28. }
  29. EXPORT_SYMBOL(blk_queue_prep_rq);
  30. /**
  31. * blk_queue_set_discard - set a discard_sectors function for queue
  32. * @q: queue
  33. * @dfn: prepare_discard function
  34. *
  35. * It's possible for a queue to register a discard callback which is used
  36. * to transform a discard request into the appropriate type for the
  37. * hardware. If none is registered, then discard requests are failed
  38. * with %EOPNOTSUPP.
  39. *
  40. */
  41. void blk_queue_set_discard(struct request_queue *q, prepare_discard_fn *dfn)
  42. {
  43. q->prepare_discard_fn = dfn;
  44. }
  45. EXPORT_SYMBOL(blk_queue_set_discard);
  46. /**
  47. * blk_queue_merge_bvec - set a merge_bvec function for queue
  48. * @q: queue
  49. * @mbfn: merge_bvec_fn
  50. *
  51. * Usually queues have static limitations on the max sectors or segments that
  52. * we can put in a request. Stacking drivers may have some settings that
  53. * are dynamic, and thus we have to query the queue whether it is ok to
  54. * add a new bio_vec to a bio at a given offset or not. If the block device
  55. * has such limitations, it needs to register a merge_bvec_fn to control
  56. * the size of bio's sent to it. Note that a block device *must* allow a
  57. * single page to be added to an empty bio. The block device driver may want
  58. * to use the bio_split() function to deal with these bio's. By default
  59. * no merge_bvec_fn is defined for a queue, and only the fixed limits are
  60. * honored.
  61. */
  62. void blk_queue_merge_bvec(struct request_queue *q, merge_bvec_fn *mbfn)
  63. {
  64. q->merge_bvec_fn = mbfn;
  65. }
  66. EXPORT_SYMBOL(blk_queue_merge_bvec);
  67. void blk_queue_softirq_done(struct request_queue *q, softirq_done_fn *fn)
  68. {
  69. q->softirq_done_fn = fn;
  70. }
  71. EXPORT_SYMBOL(blk_queue_softirq_done);
  72. void blk_queue_rq_timeout(struct request_queue *q, unsigned int timeout)
  73. {
  74. q->rq_timeout = timeout;
  75. }
  76. EXPORT_SYMBOL_GPL(blk_queue_rq_timeout);
  77. void blk_queue_rq_timed_out(struct request_queue *q, rq_timed_out_fn *fn)
  78. {
  79. q->rq_timed_out_fn = fn;
  80. }
  81. EXPORT_SYMBOL_GPL(blk_queue_rq_timed_out);
  82. void blk_queue_lld_busy(struct request_queue *q, lld_busy_fn *fn)
  83. {
  84. q->lld_busy_fn = fn;
  85. }
  86. EXPORT_SYMBOL_GPL(blk_queue_lld_busy);
  87. /**
  88. * 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
  106. * __bio_kmap_atomic() to get a temporary kernel mapping, or by calling
  107. * blk_queue_bounce() to create a buffer in normal memory.
  108. **/
  109. void blk_queue_make_request(struct request_queue *q, make_request_fn *mfn)
  110. {
  111. /*
  112. * set defaults
  113. */
  114. q->nr_requests = BLKDEV_MAX_RQ;
  115. blk_queue_max_phys_segments(q, MAX_PHYS_SEGMENTS);
  116. blk_queue_max_hw_segments(q, MAX_HW_SEGMENTS);
  117. blk_queue_segment_boundary(q, BLK_SEG_BOUNDARY_MASK);
  118. blk_queue_max_segment_size(q, MAX_SEGMENT_SIZE);
  119. q->make_request_fn = mfn;
  120. blk_queue_max_sectors(q, SAFE_MAX_SECTORS);
  121. blk_queue_logical_block_size(q, 512);
  122. blk_queue_dma_alignment(q, 511);
  123. blk_queue_congestion_threshold(q);
  124. q->nr_batching = BLK_BATCH_REQ;
  125. q->unplug_thresh = 4; /* hmm */
  126. q->unplug_delay = (3 * HZ) / 1000; /* 3 milliseconds */
  127. if (q->unplug_delay == 0)
  128. q->unplug_delay = 1;
  129. q->unplug_timer.function = blk_unplug_timeout;
  130. q->unplug_timer.data = (unsigned long)q;
  131. /*
  132. * by default assume old behaviour and bounce for any highmem page
  133. */
  134. blk_queue_bounce_limit(q, BLK_BOUNCE_HIGH);
  135. }
  136. EXPORT_SYMBOL(blk_queue_make_request);
  137. /**
  138. * blk_queue_bounce_limit - set bounce buffer limit for queue
  139. * @q: the request queue for the device
  140. * @dma_mask: the maximum address the device can handle
  141. *
  142. * Description:
  143. * Different hardware can have different requirements as to what pages
  144. * it can do I/O directly to. A low level driver can call
  145. * blk_queue_bounce_limit to have lower memory pages allocated as bounce
  146. * buffers for doing I/O to pages residing above @dma_mask.
  147. **/
  148. void blk_queue_bounce_limit(struct request_queue *q, u64 dma_mask)
  149. {
  150. unsigned long b_pfn = dma_mask >> PAGE_SHIFT;
  151. int dma = 0;
  152. q->bounce_gfp = GFP_NOIO;
  153. #if BITS_PER_LONG == 64
  154. /*
  155. * Assume anything <= 4GB can be handled by IOMMU. Actually
  156. * some IOMMUs can handle everything, but I don't know of a
  157. * way to test this here.
  158. */
  159. if (b_pfn < (min_t(u64, 0xffffffffUL, BLK_BOUNCE_HIGH) >> PAGE_SHIFT))
  160. dma = 1;
  161. q->limits.bounce_pfn = max_low_pfn;
  162. #else
  163. if (b_pfn < blk_max_low_pfn)
  164. dma = 1;
  165. q->limits.bounce_pfn = b_pfn;
  166. #endif
  167. if (dma) {
  168. init_emergency_isa_pool();
  169. q->bounce_gfp = GFP_NOIO | GFP_DMA;
  170. q->limits.bounce_pfn = b_pfn;
  171. }
  172. }
  173. EXPORT_SYMBOL(blk_queue_bounce_limit);
  174. /**
  175. * blk_queue_max_sectors - set max sectors for a request for this queue
  176. * @q: the request queue for the device
  177. * @max_sectors: max sectors in the usual 512b unit
  178. *
  179. * Description:
  180. * Enables a low level driver to set an upper limit on the size of
  181. * received requests.
  182. **/
  183. void blk_queue_max_sectors(struct request_queue *q, unsigned int max_sectors)
  184. {
  185. if ((max_sectors << 9) < PAGE_CACHE_SIZE) {
  186. max_sectors = 1 << (PAGE_CACHE_SHIFT - 9);
  187. printk(KERN_INFO "%s: set to minimum %d\n",
  188. __func__, max_sectors);
  189. }
  190. if (BLK_DEF_MAX_SECTORS > max_sectors)
  191. q->limits.max_hw_sectors = q->limits.max_sectors = max_sectors;
  192. else {
  193. q->limits.max_sectors = BLK_DEF_MAX_SECTORS;
  194. q->limits.max_hw_sectors = max_sectors;
  195. }
  196. }
  197. EXPORT_SYMBOL(blk_queue_max_sectors);
  198. void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_sectors)
  199. {
  200. if (BLK_DEF_MAX_SECTORS > max_sectors)
  201. q->limits.max_hw_sectors = BLK_DEF_MAX_SECTORS;
  202. else
  203. q->limits.max_hw_sectors = max_sectors;
  204. }
  205. EXPORT_SYMBOL(blk_queue_max_hw_sectors);
  206. /**
  207. * blk_queue_max_phys_segments - set max phys segments for a request for this queue
  208. * @q: the request queue for the device
  209. * @max_segments: max number of segments
  210. *
  211. * Description:
  212. * Enables a low level driver to set an upper limit on the number of
  213. * physical data segments in a request. This would be the largest sized
  214. * scatter list the driver could handle.
  215. **/
  216. void blk_queue_max_phys_segments(struct request_queue *q,
  217. unsigned short max_segments)
  218. {
  219. if (!max_segments) {
  220. max_segments = 1;
  221. printk(KERN_INFO "%s: set to minimum %d\n",
  222. __func__, max_segments);
  223. }
  224. q->limits.max_phys_segments = max_segments;
  225. }
  226. EXPORT_SYMBOL(blk_queue_max_phys_segments);
  227. /**
  228. * blk_queue_max_hw_segments - set max hw segments for a request for this queue
  229. * @q: the request queue for the device
  230. * @max_segments: max number of segments
  231. *
  232. * Description:
  233. * Enables a low level driver to set an upper limit on the number of
  234. * hw data segments in a request. This would be the largest number of
  235. * address/length pairs the host adapter can actually give at once
  236. * to the device.
  237. **/
  238. void blk_queue_max_hw_segments(struct request_queue *q,
  239. unsigned short max_segments)
  240. {
  241. if (!max_segments) {
  242. max_segments = 1;
  243. printk(KERN_INFO "%s: set to minimum %d\n",
  244. __func__, max_segments);
  245. }
  246. q->limits.max_hw_segments = max_segments;
  247. }
  248. EXPORT_SYMBOL(blk_queue_max_hw_segments);
  249. /**
  250. * blk_queue_max_segment_size - set max segment size for blk_rq_map_sg
  251. * @q: the request queue for the device
  252. * @max_size: max size of segment in bytes
  253. *
  254. * Description:
  255. * Enables a low level driver to set an upper limit on the size of a
  256. * coalesced segment
  257. **/
  258. void blk_queue_max_segment_size(struct request_queue *q, unsigned int max_size)
  259. {
  260. if (max_size < PAGE_CACHE_SIZE) {
  261. max_size = PAGE_CACHE_SIZE;
  262. printk(KERN_INFO "%s: set to minimum %d\n",
  263. __func__, max_size);
  264. }
  265. q->limits.max_segment_size = max_size;
  266. }
  267. EXPORT_SYMBOL(blk_queue_max_segment_size);
  268. /**
  269. * blk_queue_logical_block_size - set logical block size for the queue
  270. * @q: the request queue for the device
  271. * @size: the logical block size, in bytes
  272. *
  273. * Description:
  274. * This should be set to the lowest possible block size that the
  275. * storage device can address. The default of 512 covers most
  276. * hardware.
  277. **/
  278. void blk_queue_logical_block_size(struct request_queue *q, unsigned short size)
  279. {
  280. q->limits.logical_block_size = size;
  281. if (q->limits.physical_block_size < size)
  282. q->limits.physical_block_size = size;
  283. if (q->limits.io_min < q->limits.physical_block_size)
  284. q->limits.io_min = q->limits.physical_block_size;
  285. }
  286. EXPORT_SYMBOL(blk_queue_logical_block_size);
  287. /**
  288. * blk_queue_physical_block_size - set physical block size for the queue
  289. * @q: the request queue for the device
  290. * @size: the physical block size, in bytes
  291. *
  292. * Description:
  293. * This should be set to the lowest possible sector size that the
  294. * hardware can operate on without reverting to read-modify-write
  295. * operations.
  296. */
  297. void blk_queue_physical_block_size(struct request_queue *q, unsigned short size)
  298. {
  299. q->limits.physical_block_size = size;
  300. if (q->limits.physical_block_size < q->limits.logical_block_size)
  301. q->limits.physical_block_size = q->limits.logical_block_size;
  302. if (q->limits.io_min < q->limits.physical_block_size)
  303. q->limits.io_min = q->limits.physical_block_size;
  304. }
  305. EXPORT_SYMBOL(blk_queue_physical_block_size);
  306. /**
  307. * blk_queue_alignment_offset - set physical block alignment offset
  308. * @q: the request queue for the device
  309. * @offset: alignment offset in bytes
  310. *
  311. * Description:
  312. * Some devices are naturally misaligned to compensate for things like
  313. * the legacy DOS partition table 63-sector offset. Low-level drivers
  314. * should call this function for devices whose first sector is not
  315. * naturally aligned.
  316. */
  317. void blk_queue_alignment_offset(struct request_queue *q, unsigned int offset)
  318. {
  319. q->limits.alignment_offset =
  320. offset & (q->limits.physical_block_size - 1);
  321. q->limits.misaligned = 0;
  322. }
  323. EXPORT_SYMBOL(blk_queue_alignment_offset);
  324. /**
  325. * blk_queue_io_min - set minimum request size for the queue
  326. * @q: the request queue for the device
  327. * @min: smallest I/O size in bytes
  328. *
  329. * Description:
  330. * Some devices have an internal block size bigger than the reported
  331. * hardware sector size. This function can be used to signal the
  332. * smallest I/O the device can perform without incurring a performance
  333. * penalty.
  334. */
  335. void blk_queue_io_min(struct request_queue *q, unsigned int min)
  336. {
  337. q->limits.io_min = min;
  338. if (q->limits.io_min < q->limits.logical_block_size)
  339. q->limits.io_min = q->limits.logical_block_size;
  340. if (q->limits.io_min < q->limits.physical_block_size)
  341. q->limits.io_min = q->limits.physical_block_size;
  342. }
  343. EXPORT_SYMBOL(blk_queue_io_min);
  344. /**
  345. * blk_queue_io_opt - set optimal request size for the queue
  346. * @q: the request queue for the device
  347. * @opt: optimal request size in bytes
  348. *
  349. * Description:
  350. * Drivers can call this function to set the preferred I/O request
  351. * size for devices that report such a value.
  352. */
  353. void blk_queue_io_opt(struct request_queue *q, unsigned int opt)
  354. {
  355. q->limits.io_opt = opt;
  356. }
  357. EXPORT_SYMBOL(blk_queue_io_opt);
  358. /*
  359. * Returns the minimum that is _not_ zero, unless both are zero.
  360. */
  361. #define min_not_zero(l, r) (l == 0) ? r : ((r == 0) ? l : min(l, r))
  362. /**
  363. * blk_queue_stack_limits - inherit underlying queue limits for stacked drivers
  364. * @t: the stacking driver (top)
  365. * @b: the underlying device (bottom)
  366. **/
  367. void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b)
  368. {
  369. /* zero is "infinity" */
  370. t->limits.max_sectors = min_not_zero(queue_max_sectors(t),
  371. queue_max_sectors(b));
  372. t->limits.max_hw_sectors = min_not_zero(queue_max_hw_sectors(t),
  373. queue_max_hw_sectors(b));
  374. t->limits.seg_boundary_mask = min_not_zero(queue_segment_boundary(t),
  375. queue_segment_boundary(b));
  376. t->limits.max_phys_segments = min_not_zero(queue_max_phys_segments(t),
  377. queue_max_phys_segments(b));
  378. t->limits.max_hw_segments = min_not_zero(queue_max_hw_segments(t),
  379. queue_max_hw_segments(b));
  380. t->limits.max_segment_size = min_not_zero(queue_max_segment_size(t),
  381. queue_max_segment_size(b));
  382. t->limits.logical_block_size = max(queue_logical_block_size(t),
  383. queue_logical_block_size(b));
  384. if (!t->queue_lock)
  385. WARN_ON_ONCE(1);
  386. else if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags)) {
  387. unsigned long flags;
  388. spin_lock_irqsave(t->queue_lock, flags);
  389. queue_flag_clear(QUEUE_FLAG_CLUSTER, t);
  390. spin_unlock_irqrestore(t->queue_lock, flags);
  391. }
  392. }
  393. EXPORT_SYMBOL(blk_queue_stack_limits);
  394. /**
  395. * blk_stack_limits - adjust queue_limits for stacked devices
  396. * @t: the stacking driver limits (top)
  397. * @b: the underlying queue limits (bottom)
  398. * @offset: offset to beginning of data within component device
  399. *
  400. * Description:
  401. * Merges two queue_limit structs. Returns 0 if alignment didn't
  402. * change. Returns -1 if adding the bottom device caused
  403. * misalignment.
  404. */
  405. int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
  406. sector_t offset)
  407. {
  408. t->max_sectors = min_not_zero(t->max_sectors, b->max_sectors);
  409. t->max_hw_sectors = min_not_zero(t->max_hw_sectors, b->max_hw_sectors);
  410. t->bounce_pfn = min_not_zero(t->bounce_pfn, b->bounce_pfn);
  411. t->seg_boundary_mask = min_not_zero(t->seg_boundary_mask,
  412. b->seg_boundary_mask);
  413. t->max_phys_segments = min_not_zero(t->max_phys_segments,
  414. b->max_phys_segments);
  415. t->max_hw_segments = min_not_zero(t->max_hw_segments,
  416. b->max_hw_segments);
  417. t->max_segment_size = min_not_zero(t->max_segment_size,
  418. b->max_segment_size);
  419. t->logical_block_size = max(t->logical_block_size,
  420. b->logical_block_size);
  421. t->physical_block_size = max(t->physical_block_size,
  422. b->physical_block_size);
  423. t->io_min = max(t->io_min, b->io_min);
  424. t->no_cluster |= b->no_cluster;
  425. /* Bottom device offset aligned? */
  426. if (offset &&
  427. (offset & (b->physical_block_size - 1)) != b->alignment_offset) {
  428. t->misaligned = 1;
  429. return -1;
  430. }
  431. /* If top has no alignment offset, inherit from bottom */
  432. if (!t->alignment_offset)
  433. t->alignment_offset =
  434. b->alignment_offset & (b->physical_block_size - 1);
  435. /* Top device aligned on logical block boundary? */
  436. if (t->alignment_offset & (t->logical_block_size - 1)) {
  437. t->misaligned = 1;
  438. return -1;
  439. }
  440. return 0;
  441. }
  442. EXPORT_SYMBOL(blk_stack_limits);
  443. /**
  444. * disk_stack_limits - adjust queue limits for stacked drivers
  445. * @disk: MD/DM gendisk (top)
  446. * @bdev: the underlying block device (bottom)
  447. * @offset: offset to beginning of data within component device
  448. *
  449. * Description:
  450. * Merges the limits for two queues. Returns 0 if alignment
  451. * didn't change. Returns -1 if adding the bottom device caused
  452. * misalignment.
  453. */
  454. void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
  455. sector_t offset)
  456. {
  457. struct request_queue *t = disk->queue;
  458. struct request_queue *b = bdev_get_queue(bdev);
  459. offset += get_start_sect(bdev) << 9;
  460. if (blk_stack_limits(&t->limits, &b->limits, offset) < 0) {
  461. char top[BDEVNAME_SIZE], bottom[BDEVNAME_SIZE];
  462. disk_name(disk, 0, top);
  463. bdevname(bdev, bottom);
  464. printk(KERN_NOTICE "%s: Warning: Device %s is misaligned\n",
  465. top, bottom);
  466. }
  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);
  472. if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags))
  473. queue_flag_clear(QUEUE_FLAG_CLUSTER, t);
  474. spin_unlock_irqrestore(t->queue_lock, flags);
  475. }
  476. }
  477. EXPORT_SYMBOL(disk_stack_limits);
  478. /**
  479. * blk_queue_dma_pad - set pad mask
  480. * @q: the request queue for the device
  481. * @mask: pad mask
  482. *
  483. * Set dma pad mask.
  484. *
  485. * Appending pad buffer to a request modifies the last entry of a
  486. * scatter list such that it includes the pad buffer.
  487. **/
  488. void blk_queue_dma_pad(struct request_queue *q, unsigned int mask)
  489. {
  490. q->dma_pad_mask = mask;
  491. }
  492. EXPORT_SYMBOL(blk_queue_dma_pad);
  493. /**
  494. * blk_queue_update_dma_pad - update pad mask
  495. * @q: the request queue for the device
  496. * @mask: pad mask
  497. *
  498. * Update dma pad mask.
  499. *
  500. * Appending pad buffer to a request modifies the last entry of a
  501. * scatter list such that it includes the pad buffer.
  502. **/
  503. void blk_queue_update_dma_pad(struct request_queue *q, unsigned int mask)
  504. {
  505. if (mask > q->dma_pad_mask)
  506. q->dma_pad_mask = mask;
  507. }
  508. EXPORT_SYMBOL(blk_queue_update_dma_pad);
  509. /**
  510. * blk_queue_dma_drain - Set up a drain buffer for excess dma.
  511. * @q: the request queue for the device
  512. * @dma_drain_needed: fn which returns non-zero if drain is necessary
  513. * @buf: physically contiguous buffer
  514. * @size: size of the buffer in bytes
  515. *
  516. * Some devices have excess DMA problems and can't simply discard (or
  517. * zero fill) the unwanted piece of the transfer. They have to have a
  518. * real area of memory to transfer it into. The use case for this is
  519. * ATAPI devices in DMA mode. If the packet command causes a transfer
  520. * bigger than the transfer size some HBAs will lock up if there
  521. * aren't DMA elements to contain the excess transfer. What this API
  522. * does is adjust the queue so that the buf is always appended
  523. * silently to the scatterlist.
  524. *
  525. * Note: This routine adjusts max_hw_segments to make room for
  526. * appending the drain buffer. If you call
  527. * blk_queue_max_hw_segments() or blk_queue_max_phys_segments() after
  528. * calling this routine, you must set the limit to one fewer than your
  529. * device can support otherwise there won't be room for the drain
  530. * buffer.
  531. */
  532. int blk_queue_dma_drain(struct request_queue *q,
  533. dma_drain_needed_fn *dma_drain_needed,
  534. void *buf, unsigned int size)
  535. {
  536. if (queue_max_hw_segments(q) < 2 || queue_max_phys_segments(q) < 2)
  537. return -EINVAL;
  538. /* make room for appending the drain */
  539. blk_queue_max_hw_segments(q, queue_max_hw_segments(q) - 1);
  540. blk_queue_max_phys_segments(q, queue_max_phys_segments(q) - 1);
  541. q->dma_drain_needed = dma_drain_needed;
  542. q->dma_drain_buffer = buf;
  543. q->dma_drain_size = size;
  544. return 0;
  545. }
  546. EXPORT_SYMBOL_GPL(blk_queue_dma_drain);
  547. /**
  548. * blk_queue_segment_boundary - set boundary rules for segment merging
  549. * @q: the request queue for the device
  550. * @mask: the memory boundary mask
  551. **/
  552. void blk_queue_segment_boundary(struct request_queue *q, unsigned long mask)
  553. {
  554. if (mask < PAGE_CACHE_SIZE - 1) {
  555. mask = PAGE_CACHE_SIZE - 1;
  556. printk(KERN_INFO "%s: set to minimum %lx\n",
  557. __func__, mask);
  558. }
  559. q->limits.seg_boundary_mask = mask;
  560. }
  561. EXPORT_SYMBOL(blk_queue_segment_boundary);
  562. /**
  563. * blk_queue_dma_alignment - set dma length and memory alignment
  564. * @q: the request queue for the device
  565. * @mask: alignment mask
  566. *
  567. * description:
  568. * set required memory and length alignment for direct dma transactions.
  569. * this is used when building direct io requests for the queue.
  570. *
  571. **/
  572. void blk_queue_dma_alignment(struct request_queue *q, int mask)
  573. {
  574. q->dma_alignment = mask;
  575. }
  576. EXPORT_SYMBOL(blk_queue_dma_alignment);
  577. /**
  578. * blk_queue_update_dma_alignment - update dma length and memory alignment
  579. * @q: the request queue for the device
  580. * @mask: alignment mask
  581. *
  582. * description:
  583. * update required memory and length alignment for direct dma transactions.
  584. * If the requested alignment is larger than the current alignment, then
  585. * the current queue alignment is updated to the new value, otherwise it
  586. * is left alone. The design of this is to allow multiple objects
  587. * (driver, device, transport etc) to set their respective
  588. * alignments without having them interfere.
  589. *
  590. **/
  591. void blk_queue_update_dma_alignment(struct request_queue *q, int mask)
  592. {
  593. BUG_ON(mask > PAGE_SIZE);
  594. if (mask > q->dma_alignment)
  595. q->dma_alignment = mask;
  596. }
  597. EXPORT_SYMBOL(blk_queue_update_dma_alignment);
  598. static int __init blk_settings_init(void)
  599. {
  600. blk_max_low_pfn = max_low_pfn - 1;
  601. blk_max_pfn = max_pfn - 1;
  602. return 0;
  603. }
  604. subsys_initcall(blk_settings_init);