blk-settings.c 23 KB

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