ide-io.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238
  1. /*
  2. * IDE I/O functions
  3. *
  4. * Basic PIO and command management functionality.
  5. *
  6. * This code was split off from ide.c. See ide.c for history and original
  7. * copyrights.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2, or (at your option) any
  12. * later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * For the avoidance of doubt the "preferred form" of this code is one which
  20. * is in an open non patent encumbered format. Where cryptographic key signing
  21. * forms part of the process of creating an executable the information
  22. * including keys needed to generate an equivalently functional executable
  23. * are deemed to be part of the source code.
  24. */
  25. #include <linux/module.h>
  26. #include <linux/types.h>
  27. #include <linux/string.h>
  28. #include <linux/kernel.h>
  29. #include <linux/timer.h>
  30. #include <linux/mm.h>
  31. #include <linux/interrupt.h>
  32. #include <linux/major.h>
  33. #include <linux/errno.h>
  34. #include <linux/genhd.h>
  35. #include <linux/blkpg.h>
  36. #include <linux/slab.h>
  37. #include <linux/init.h>
  38. #include <linux/pci.h>
  39. #include <linux/delay.h>
  40. #include <linux/ide.h>
  41. #include <linux/hdreg.h>
  42. #include <linux/completion.h>
  43. #include <linux/reboot.h>
  44. #include <linux/cdrom.h>
  45. #include <linux/seq_file.h>
  46. #include <linux/device.h>
  47. #include <linux/kmod.h>
  48. #include <linux/scatterlist.h>
  49. #include <linux/bitops.h>
  50. #include <asm/byteorder.h>
  51. #include <asm/irq.h>
  52. #include <asm/uaccess.h>
  53. #include <asm/io.h>
  54. static int __ide_end_request(ide_drive_t *drive, struct request *rq,
  55. int uptodate, unsigned int nr_bytes, int dequeue)
  56. {
  57. int ret = 1;
  58. int error = 0;
  59. if (uptodate <= 0)
  60. error = uptodate ? uptodate : -EIO;
  61. /*
  62. * if failfast is set on a request, override number of sectors and
  63. * complete the whole request right now
  64. */
  65. if (blk_noretry_request(rq) && error)
  66. nr_bytes = rq->hard_nr_sectors << 9;
  67. if (!blk_fs_request(rq) && error && !rq->errors)
  68. rq->errors = -EIO;
  69. /*
  70. * decide whether to reenable DMA -- 3 is a random magic for now,
  71. * if we DMA timeout more than 3 times, just stay in PIO
  72. */
  73. if ((drive->dev_flags & IDE_DFLAG_DMA_PIO_RETRY) &&
  74. drive->retry_pio <= 3) {
  75. drive->dev_flags &= ~IDE_DFLAG_DMA_PIO_RETRY;
  76. ide_dma_on(drive);
  77. }
  78. if (!blk_end_request(rq, error, nr_bytes))
  79. ret = 0;
  80. if (ret == 0 && dequeue)
  81. drive->hwif->hwgroup->rq = NULL;
  82. return ret;
  83. }
  84. /**
  85. * ide_end_request - complete an IDE I/O
  86. * @drive: IDE device for the I/O
  87. * @uptodate:
  88. * @nr_sectors: number of sectors completed
  89. *
  90. * This is our end_request wrapper function. We complete the I/O
  91. * update random number input and dequeue the request, which if
  92. * it was tagged may be out of order.
  93. */
  94. int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors)
  95. {
  96. unsigned int nr_bytes = nr_sectors << 9;
  97. struct request *rq = drive->hwif->hwgroup->rq;
  98. if (!nr_bytes) {
  99. if (blk_pc_request(rq))
  100. nr_bytes = rq->data_len;
  101. else
  102. nr_bytes = rq->hard_cur_sectors << 9;
  103. }
  104. return __ide_end_request(drive, rq, uptodate, nr_bytes, 1);
  105. }
  106. EXPORT_SYMBOL(ide_end_request);
  107. /**
  108. * ide_end_dequeued_request - complete an IDE I/O
  109. * @drive: IDE device for the I/O
  110. * @uptodate:
  111. * @nr_sectors: number of sectors completed
  112. *
  113. * Complete an I/O that is no longer on the request queue. This
  114. * typically occurs when we pull the request and issue a REQUEST_SENSE.
  115. * We must still finish the old request but we must not tamper with the
  116. * queue in the meantime.
  117. *
  118. * NOTE: This path does not handle barrier, but barrier is not supported
  119. * on ide-cd anyway.
  120. */
  121. int ide_end_dequeued_request(ide_drive_t *drive, struct request *rq,
  122. int uptodate, int nr_sectors)
  123. {
  124. BUG_ON(!blk_rq_started(rq));
  125. return __ide_end_request(drive, rq, uptodate, nr_sectors << 9, 0);
  126. }
  127. EXPORT_SYMBOL_GPL(ide_end_dequeued_request);
  128. /**
  129. * ide_end_drive_cmd - end an explicit drive command
  130. * @drive: command
  131. * @stat: status bits
  132. * @err: error bits
  133. *
  134. * Clean up after success/failure of an explicit drive command.
  135. * These get thrown onto the queue so they are synchronized with
  136. * real I/O operations on the drive.
  137. *
  138. * In LBA48 mode we have to read the register set twice to get
  139. * all the extra information out.
  140. */
  141. void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
  142. {
  143. ide_hwgroup_t *hwgroup = drive->hwif->hwgroup;
  144. struct request *rq = hwgroup->rq;
  145. if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
  146. ide_task_t *task = (ide_task_t *)rq->special;
  147. if (task) {
  148. struct ide_taskfile *tf = &task->tf;
  149. tf->error = err;
  150. tf->status = stat;
  151. drive->hwif->tp_ops->tf_read(drive, task);
  152. if (task->tf_flags & IDE_TFLAG_DYN)
  153. kfree(task);
  154. }
  155. } else if (blk_pm_request(rq)) {
  156. struct request_pm_state *pm = rq->data;
  157. ide_complete_power_step(drive, rq);
  158. if (pm->pm_step == IDE_PM_COMPLETED)
  159. ide_complete_pm_request(drive, rq);
  160. return;
  161. }
  162. hwgroup->rq = NULL;
  163. rq->errors = err;
  164. if (unlikely(blk_end_request(rq, (rq->errors ? -EIO : 0),
  165. blk_rq_bytes(rq))))
  166. BUG();
  167. }
  168. EXPORT_SYMBOL(ide_end_drive_cmd);
  169. static void ide_kill_rq(ide_drive_t *drive, struct request *rq)
  170. {
  171. if (rq->rq_disk) {
  172. ide_driver_t *drv;
  173. drv = *(ide_driver_t **)rq->rq_disk->private_data;
  174. drv->end_request(drive, 0, 0);
  175. } else
  176. ide_end_request(drive, 0, 0);
  177. }
  178. static ide_startstop_t ide_ata_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
  179. {
  180. ide_hwif_t *hwif = drive->hwif;
  181. if ((stat & ATA_BUSY) ||
  182. ((stat & ATA_DF) && (drive->dev_flags & IDE_DFLAG_NOWERR) == 0)) {
  183. /* other bits are useless when BUSY */
  184. rq->errors |= ERROR_RESET;
  185. } else if (stat & ATA_ERR) {
  186. /* err has different meaning on cdrom and tape */
  187. if (err == ATA_ABORTED) {
  188. if ((drive->dev_flags & IDE_DFLAG_LBA) &&
  189. /* some newer drives don't support ATA_CMD_INIT_DEV_PARAMS */
  190. hwif->tp_ops->read_status(hwif) == ATA_CMD_INIT_DEV_PARAMS)
  191. return ide_stopped;
  192. } else if ((err & BAD_CRC) == BAD_CRC) {
  193. /* UDMA crc error, just retry the operation */
  194. drive->crc_count++;
  195. } else if (err & (ATA_BBK | ATA_UNC)) {
  196. /* retries won't help these */
  197. rq->errors = ERROR_MAX;
  198. } else if (err & ATA_TRK0NF) {
  199. /* help it find track zero */
  200. rq->errors |= ERROR_RECAL;
  201. }
  202. }
  203. if ((stat & ATA_DRQ) && rq_data_dir(rq) == READ &&
  204. (hwif->host_flags & IDE_HFLAG_ERROR_STOPS_FIFO) == 0) {
  205. int nsect = drive->mult_count ? drive->mult_count : 1;
  206. ide_pad_transfer(drive, READ, nsect * SECTOR_SIZE);
  207. }
  208. if (rq->errors >= ERROR_MAX || blk_noretry_request(rq)) {
  209. ide_kill_rq(drive, rq);
  210. return ide_stopped;
  211. }
  212. if (hwif->tp_ops->read_status(hwif) & (ATA_BUSY | ATA_DRQ))
  213. rq->errors |= ERROR_RESET;
  214. if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
  215. ++rq->errors;
  216. return ide_do_reset(drive);
  217. }
  218. if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)
  219. drive->special.b.recalibrate = 1;
  220. ++rq->errors;
  221. return ide_stopped;
  222. }
  223. static ide_startstop_t ide_atapi_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
  224. {
  225. ide_hwif_t *hwif = drive->hwif;
  226. if ((stat & ATA_BUSY) ||
  227. ((stat & ATA_DF) && (drive->dev_flags & IDE_DFLAG_NOWERR) == 0)) {
  228. /* other bits are useless when BUSY */
  229. rq->errors |= ERROR_RESET;
  230. } else {
  231. /* add decoding error stuff */
  232. }
  233. if (hwif->tp_ops->read_status(hwif) & (ATA_BUSY | ATA_DRQ))
  234. /* force an abort */
  235. hwif->tp_ops->exec_command(hwif, ATA_CMD_IDLEIMMEDIATE);
  236. if (rq->errors >= ERROR_MAX) {
  237. ide_kill_rq(drive, rq);
  238. } else {
  239. if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
  240. ++rq->errors;
  241. return ide_do_reset(drive);
  242. }
  243. ++rq->errors;
  244. }
  245. return ide_stopped;
  246. }
  247. ide_startstop_t
  248. __ide_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
  249. {
  250. if (drive->media == ide_disk)
  251. return ide_ata_error(drive, rq, stat, err);
  252. return ide_atapi_error(drive, rq, stat, err);
  253. }
  254. EXPORT_SYMBOL_GPL(__ide_error);
  255. /**
  256. * ide_error - handle an error on the IDE
  257. * @drive: drive the error occurred on
  258. * @msg: message to report
  259. * @stat: status bits
  260. *
  261. * ide_error() takes action based on the error returned by the drive.
  262. * For normal I/O that may well include retries. We deal with
  263. * both new-style (taskfile) and old style command handling here.
  264. * In the case of taskfile command handling there is work left to
  265. * do
  266. */
  267. ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, u8 stat)
  268. {
  269. struct request *rq;
  270. u8 err;
  271. err = ide_dump_status(drive, msg, stat);
  272. if ((rq = HWGROUP(drive)->rq) == NULL)
  273. return ide_stopped;
  274. /* retry only "normal" I/O: */
  275. if (!blk_fs_request(rq)) {
  276. rq->errors = 1;
  277. ide_end_drive_cmd(drive, stat, err);
  278. return ide_stopped;
  279. }
  280. if (rq->rq_disk) {
  281. ide_driver_t *drv;
  282. drv = *(ide_driver_t **)rq->rq_disk->private_data;
  283. return drv->error(drive, rq, stat, err);
  284. } else
  285. return __ide_error(drive, rq, stat, err);
  286. }
  287. EXPORT_SYMBOL_GPL(ide_error);
  288. static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
  289. {
  290. tf->nsect = drive->sect;
  291. tf->lbal = drive->sect;
  292. tf->lbam = drive->cyl;
  293. tf->lbah = drive->cyl >> 8;
  294. tf->device = (drive->head - 1) | drive->select;
  295. tf->command = ATA_CMD_INIT_DEV_PARAMS;
  296. }
  297. static void ide_tf_set_restore_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
  298. {
  299. tf->nsect = drive->sect;
  300. tf->command = ATA_CMD_RESTORE;
  301. }
  302. static void ide_tf_set_setmult_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
  303. {
  304. tf->nsect = drive->mult_req;
  305. tf->command = ATA_CMD_SET_MULTI;
  306. }
  307. static ide_startstop_t ide_disk_special(ide_drive_t *drive)
  308. {
  309. special_t *s = &drive->special;
  310. ide_task_t args;
  311. memset(&args, 0, sizeof(ide_task_t));
  312. args.data_phase = TASKFILE_NO_DATA;
  313. if (s->b.set_geometry) {
  314. s->b.set_geometry = 0;
  315. ide_tf_set_specify_cmd(drive, &args.tf);
  316. } else if (s->b.recalibrate) {
  317. s->b.recalibrate = 0;
  318. ide_tf_set_restore_cmd(drive, &args.tf);
  319. } else if (s->b.set_multmode) {
  320. s->b.set_multmode = 0;
  321. ide_tf_set_setmult_cmd(drive, &args.tf);
  322. } else if (s->all) {
  323. int special = s->all;
  324. s->all = 0;
  325. printk(KERN_ERR "%s: bad special flag: 0x%02x\n", drive->name, special);
  326. return ide_stopped;
  327. }
  328. args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE |
  329. IDE_TFLAG_CUSTOM_HANDLER;
  330. do_rw_taskfile(drive, &args);
  331. return ide_started;
  332. }
  333. /**
  334. * do_special - issue some special commands
  335. * @drive: drive the command is for
  336. *
  337. * do_special() is used to issue ATA_CMD_INIT_DEV_PARAMS,
  338. * ATA_CMD_RESTORE and ATA_CMD_SET_MULTI commands to a drive.
  339. *
  340. * It used to do much more, but has been scaled back.
  341. */
  342. static ide_startstop_t do_special (ide_drive_t *drive)
  343. {
  344. special_t *s = &drive->special;
  345. #ifdef DEBUG
  346. printk("%s: do_special: 0x%02x\n", drive->name, s->all);
  347. #endif
  348. if (drive->media == ide_disk)
  349. return ide_disk_special(drive);
  350. s->all = 0;
  351. drive->mult_req = 0;
  352. return ide_stopped;
  353. }
  354. void ide_map_sg(ide_drive_t *drive, struct request *rq)
  355. {
  356. ide_hwif_t *hwif = drive->hwif;
  357. struct scatterlist *sg = hwif->sg_table;
  358. if (rq->cmd_type != REQ_TYPE_ATA_TASKFILE) {
  359. hwif->sg_nents = blk_rq_map_sg(drive->queue, rq, sg);
  360. } else {
  361. sg_init_one(sg, rq->buffer, rq->nr_sectors * SECTOR_SIZE);
  362. hwif->sg_nents = 1;
  363. }
  364. }
  365. EXPORT_SYMBOL_GPL(ide_map_sg);
  366. void ide_init_sg_cmd(ide_drive_t *drive, struct request *rq)
  367. {
  368. ide_hwif_t *hwif = drive->hwif;
  369. hwif->nsect = hwif->nleft = rq->nr_sectors;
  370. hwif->cursg_ofs = 0;
  371. hwif->cursg = NULL;
  372. }
  373. EXPORT_SYMBOL_GPL(ide_init_sg_cmd);
  374. /**
  375. * execute_drive_command - issue special drive command
  376. * @drive: the drive to issue the command on
  377. * @rq: the request structure holding the command
  378. *
  379. * execute_drive_cmd() issues a special drive command, usually
  380. * initiated by ioctl() from the external hdparm program. The
  381. * command can be a drive command, drive task or taskfile
  382. * operation. Weirdly you can call it with NULL to wait for
  383. * all commands to finish. Don't do this as that is due to change
  384. */
  385. static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
  386. struct request *rq)
  387. {
  388. ide_hwif_t *hwif = HWIF(drive);
  389. ide_task_t *task = rq->special;
  390. if (task) {
  391. hwif->data_phase = task->data_phase;
  392. switch (hwif->data_phase) {
  393. case TASKFILE_MULTI_OUT:
  394. case TASKFILE_OUT:
  395. case TASKFILE_MULTI_IN:
  396. case TASKFILE_IN:
  397. ide_init_sg_cmd(drive, rq);
  398. ide_map_sg(drive, rq);
  399. default:
  400. break;
  401. }
  402. return do_rw_taskfile(drive, task);
  403. }
  404. /*
  405. * NULL is actually a valid way of waiting for
  406. * all current requests to be flushed from the queue.
  407. */
  408. #ifdef DEBUG
  409. printk("%s: DRIVE_CMD (null)\n", drive->name);
  410. #endif
  411. ide_end_drive_cmd(drive, hwif->tp_ops->read_status(hwif),
  412. ide_read_error(drive));
  413. return ide_stopped;
  414. }
  415. int ide_devset_execute(ide_drive_t *drive, const struct ide_devset *setting,
  416. int arg)
  417. {
  418. struct request_queue *q = drive->queue;
  419. struct request *rq;
  420. int ret = 0;
  421. if (!(setting->flags & DS_SYNC))
  422. return setting->set(drive, arg);
  423. rq = blk_get_request(q, READ, __GFP_WAIT);
  424. rq->cmd_type = REQ_TYPE_SPECIAL;
  425. rq->cmd_len = 5;
  426. rq->cmd[0] = REQ_DEVSET_EXEC;
  427. *(int *)&rq->cmd[1] = arg;
  428. rq->special = setting->set;
  429. if (blk_execute_rq(q, NULL, rq, 0))
  430. ret = rq->errors;
  431. blk_put_request(rq);
  432. return ret;
  433. }
  434. EXPORT_SYMBOL_GPL(ide_devset_execute);
  435. static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq)
  436. {
  437. u8 cmd = rq->cmd[0];
  438. if (cmd == REQ_PARK_HEADS || cmd == REQ_UNPARK_HEADS) {
  439. ide_task_t task;
  440. struct ide_taskfile *tf = &task.tf;
  441. memset(&task, 0, sizeof(task));
  442. if (cmd == REQ_PARK_HEADS) {
  443. drive->sleep = *(unsigned long *)rq->special;
  444. drive->dev_flags |= IDE_DFLAG_SLEEPING;
  445. tf->command = ATA_CMD_IDLEIMMEDIATE;
  446. tf->feature = 0x44;
  447. tf->lbal = 0x4c;
  448. tf->lbam = 0x4e;
  449. tf->lbah = 0x55;
  450. task.tf_flags |= IDE_TFLAG_CUSTOM_HANDLER;
  451. } else /* cmd == REQ_UNPARK_HEADS */
  452. tf->command = ATA_CMD_CHK_POWER;
  453. task.tf_flags |= IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
  454. task.rq = rq;
  455. drive->hwif->data_phase = task.data_phase = TASKFILE_NO_DATA;
  456. return do_rw_taskfile(drive, &task);
  457. }
  458. switch (cmd) {
  459. case REQ_DEVSET_EXEC:
  460. {
  461. int err, (*setfunc)(ide_drive_t *, int) = rq->special;
  462. err = setfunc(drive, *(int *)&rq->cmd[1]);
  463. if (err)
  464. rq->errors = err;
  465. else
  466. err = 1;
  467. ide_end_request(drive, err, 0);
  468. return ide_stopped;
  469. }
  470. case REQ_DRIVE_RESET:
  471. return ide_do_reset(drive);
  472. default:
  473. blk_dump_rq_flags(rq, "ide_special_rq - bad request");
  474. ide_end_request(drive, 0, 0);
  475. return ide_stopped;
  476. }
  477. }
  478. /**
  479. * start_request - start of I/O and command issuing for IDE
  480. *
  481. * start_request() initiates handling of a new I/O request. It
  482. * accepts commands and I/O (read/write) requests.
  483. *
  484. * FIXME: this function needs a rename
  485. */
  486. static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
  487. {
  488. ide_startstop_t startstop;
  489. BUG_ON(!blk_rq_started(rq));
  490. #ifdef DEBUG
  491. printk("%s: start_request: current=0x%08lx\n",
  492. HWIF(drive)->name, (unsigned long) rq);
  493. #endif
  494. /* bail early if we've exceeded max_failures */
  495. if (drive->max_failures && (drive->failures > drive->max_failures)) {
  496. rq->cmd_flags |= REQ_FAILED;
  497. goto kill_rq;
  498. }
  499. if (blk_pm_request(rq))
  500. ide_check_pm_state(drive, rq);
  501. SELECT_DRIVE(drive);
  502. if (ide_wait_stat(&startstop, drive, drive->ready_stat,
  503. ATA_BUSY | ATA_DRQ, WAIT_READY)) {
  504. printk(KERN_ERR "%s: drive not ready for command\n", drive->name);
  505. return startstop;
  506. }
  507. if (!drive->special.all) {
  508. ide_driver_t *drv;
  509. /*
  510. * We reset the drive so we need to issue a SETFEATURES.
  511. * Do it _after_ do_special() restored device parameters.
  512. */
  513. if (drive->current_speed == 0xff)
  514. ide_config_drive_speed(drive, drive->desired_speed);
  515. if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
  516. return execute_drive_cmd(drive, rq);
  517. else if (blk_pm_request(rq)) {
  518. struct request_pm_state *pm = rq->data;
  519. #ifdef DEBUG_PM
  520. printk("%s: start_power_step(step: %d)\n",
  521. drive->name, pm->pm_step);
  522. #endif
  523. startstop = ide_start_power_step(drive, rq);
  524. if (startstop == ide_stopped &&
  525. pm->pm_step == IDE_PM_COMPLETED)
  526. ide_complete_pm_request(drive, rq);
  527. return startstop;
  528. } else if (!rq->rq_disk && blk_special_request(rq))
  529. /*
  530. * TODO: Once all ULDs have been modified to
  531. * check for specific op codes rather than
  532. * blindly accepting any special request, the
  533. * check for ->rq_disk above may be replaced
  534. * by a more suitable mechanism or even
  535. * dropped entirely.
  536. */
  537. return ide_special_rq(drive, rq);
  538. drv = *(ide_driver_t **)rq->rq_disk->private_data;
  539. return drv->do_request(drive, rq, rq->sector);
  540. }
  541. return do_special(drive);
  542. kill_rq:
  543. ide_kill_rq(drive, rq);
  544. return ide_stopped;
  545. }
  546. /**
  547. * ide_stall_queue - pause an IDE device
  548. * @drive: drive to stall
  549. * @timeout: time to stall for (jiffies)
  550. *
  551. * ide_stall_queue() can be used by a drive to give excess bandwidth back
  552. * to the hwgroup by sleeping for timeout jiffies.
  553. */
  554. void ide_stall_queue (ide_drive_t *drive, unsigned long timeout)
  555. {
  556. if (timeout > WAIT_WORSTCASE)
  557. timeout = WAIT_WORSTCASE;
  558. drive->sleep = timeout + jiffies;
  559. drive->dev_flags |= IDE_DFLAG_SLEEPING;
  560. }
  561. EXPORT_SYMBOL(ide_stall_queue);
  562. /*
  563. * Issue a new request to a drive from hwgroup
  564. *
  565. * A hwgroup is a serialized group of IDE interfaces. Usually there is
  566. * exactly one hwif (interface) per hwgroup, but buggy controllers (eg. CMD640)
  567. * may have both interfaces in a single hwgroup to "serialize" access.
  568. * Or possibly multiple ISA interfaces can share a common IRQ by being grouped
  569. * together into one hwgroup for serialized access.
  570. *
  571. * Note also that several hwgroups can end up sharing a single IRQ,
  572. * possibly along with many other devices. This is especially common in
  573. * PCI-based systems with off-board IDE controller cards.
  574. *
  575. * The IDE driver uses a per-hwgroup lock to protect the hwgroup->busy flag.
  576. *
  577. * The first thread into the driver for a particular hwgroup sets the
  578. * hwgroup->busy flag to indicate that this hwgroup is now active,
  579. * and then initiates processing of the top request from the request queue.
  580. *
  581. * Other threads attempting entry notice the busy setting, and will simply
  582. * queue their new requests and exit immediately. Note that hwgroup->busy
  583. * remains set even when the driver is merely awaiting the next interrupt.
  584. * Thus, the meaning is "this hwgroup is busy processing a request".
  585. *
  586. * When processing of a request completes, the completing thread or IRQ-handler
  587. * will start the next request from the queue. If no more work remains,
  588. * the driver will clear the hwgroup->busy flag and exit.
  589. *
  590. * The per-hwgroup spinlock is used to protect all access to the
  591. * hwgroup->busy flag, but is otherwise not needed for most processing in
  592. * the driver. This makes the driver much more friendlier to shared IRQs
  593. * than previous designs, while remaining 100% (?) SMP safe and capable.
  594. */
  595. void do_ide_request(struct request_queue *q)
  596. {
  597. ide_drive_t *drive = q->queuedata;
  598. ide_hwif_t *hwif = drive->hwif;
  599. ide_hwgroup_t *hwgroup = hwif->hwgroup;
  600. struct request *rq;
  601. ide_startstop_t startstop;
  602. /*
  603. * drive is doing pre-flush, ordered write, post-flush sequence. even
  604. * though that is 3 requests, it must be seen as a single transaction.
  605. * we must not preempt this drive until that is complete
  606. */
  607. if (blk_queue_flushing(q))
  608. /*
  609. * small race where queue could get replugged during
  610. * the 3-request flush cycle, just yank the plug since
  611. * we want it to finish asap
  612. */
  613. blk_remove_plug(q);
  614. spin_unlock_irq(q->queue_lock);
  615. spin_lock_irq(&hwgroup->lock);
  616. if (!ide_lock_hwgroup(hwgroup)) {
  617. repeat:
  618. hwgroup->rq = NULL;
  619. if (drive->dev_flags & IDE_DFLAG_SLEEPING) {
  620. if (time_before(drive->sleep, jiffies)) {
  621. ide_unlock_hwgroup(hwgroup);
  622. goto plug_device;
  623. }
  624. }
  625. if (hwif != hwgroup->hwif) {
  626. /*
  627. * set nIEN for previous hwif, drives in the
  628. * quirk_list may not like intr setups/cleanups
  629. */
  630. if (drive->quirk_list == 0)
  631. hwif->tp_ops->set_irq(hwif, 0);
  632. }
  633. hwgroup->hwif = hwif;
  634. hwgroup->drive = drive;
  635. drive->dev_flags &= ~(IDE_DFLAG_SLEEPING | IDE_DFLAG_PARKED);
  636. spin_unlock_irq(&hwgroup->lock);
  637. spin_lock_irq(q->queue_lock);
  638. /*
  639. * we know that the queue isn't empty, but this can happen
  640. * if the q->prep_rq_fn() decides to kill a request
  641. */
  642. rq = elv_next_request(drive->queue);
  643. spin_unlock_irq(q->queue_lock);
  644. spin_lock_irq(&hwgroup->lock);
  645. if (!rq) {
  646. ide_unlock_hwgroup(hwgroup);
  647. goto out;
  648. }
  649. /*
  650. * Sanity: don't accept a request that isn't a PM request
  651. * if we are currently power managed. This is very important as
  652. * blk_stop_queue() doesn't prevent the elv_next_request()
  653. * above to return us whatever is in the queue. Since we call
  654. * ide_do_request() ourselves, we end up taking requests while
  655. * the queue is blocked...
  656. *
  657. * We let requests forced at head of queue with ide-preempt
  658. * though. I hope that doesn't happen too much, hopefully not
  659. * unless the subdriver triggers such a thing in its own PM
  660. * state machine.
  661. */
  662. if ((drive->dev_flags & IDE_DFLAG_BLOCKED) &&
  663. blk_pm_request(rq) == 0 &&
  664. (rq->cmd_flags & REQ_PREEMPT) == 0) {
  665. /* there should be no pending command at this point */
  666. ide_unlock_hwgroup(hwgroup);
  667. goto plug_device;
  668. }
  669. hwgroup->rq = rq;
  670. spin_unlock_irq(&hwgroup->lock);
  671. startstop = start_request(drive, rq);
  672. spin_lock_irq(&hwgroup->lock);
  673. if (startstop == ide_stopped)
  674. goto repeat;
  675. } else
  676. goto plug_device;
  677. out:
  678. spin_unlock_irq(&hwgroup->lock);
  679. spin_lock_irq(q->queue_lock);
  680. return;
  681. plug_device:
  682. spin_unlock_irq(&hwgroup->lock);
  683. spin_lock_irq(q->queue_lock);
  684. if (!elv_queue_empty(q))
  685. blk_plug_device(q);
  686. }
  687. /*
  688. * un-busy the hwgroup etc, and clear any pending DMA status. we want to
  689. * retry the current request in pio mode instead of risking tossing it
  690. * all away
  691. */
  692. static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
  693. {
  694. ide_hwif_t *hwif = HWIF(drive);
  695. struct request *rq;
  696. ide_startstop_t ret = ide_stopped;
  697. /*
  698. * end current dma transaction
  699. */
  700. if (error < 0) {
  701. printk(KERN_WARNING "%s: DMA timeout error\n", drive->name);
  702. (void)hwif->dma_ops->dma_end(drive);
  703. ret = ide_error(drive, "dma timeout error",
  704. hwif->tp_ops->read_status(hwif));
  705. } else {
  706. printk(KERN_WARNING "%s: DMA timeout retry\n", drive->name);
  707. hwif->dma_ops->dma_timeout(drive);
  708. }
  709. /*
  710. * disable dma for now, but remember that we did so because of
  711. * a timeout -- we'll reenable after we finish this next request
  712. * (or rather the first chunk of it) in pio.
  713. */
  714. drive->dev_flags |= IDE_DFLAG_DMA_PIO_RETRY;
  715. drive->retry_pio++;
  716. ide_dma_off_quietly(drive);
  717. /*
  718. * un-busy drive etc (hwgroup->busy is cleared on return) and
  719. * make sure request is sane
  720. */
  721. rq = HWGROUP(drive)->rq;
  722. if (!rq)
  723. goto out;
  724. HWGROUP(drive)->rq = NULL;
  725. rq->errors = 0;
  726. if (!rq->bio)
  727. goto out;
  728. rq->sector = rq->bio->bi_sector;
  729. rq->current_nr_sectors = bio_iovec(rq->bio)->bv_len >> 9;
  730. rq->hard_cur_sectors = rq->current_nr_sectors;
  731. rq->buffer = bio_data(rq->bio);
  732. out:
  733. return ret;
  734. }
  735. static void ide_plug_device(ide_drive_t *drive)
  736. {
  737. struct request_queue *q = drive->queue;
  738. unsigned long flags;
  739. spin_lock_irqsave(q->queue_lock, flags);
  740. if (!elv_queue_empty(q))
  741. blk_plug_device(q);
  742. spin_unlock_irqrestore(q->queue_lock, flags);
  743. }
  744. /**
  745. * ide_timer_expiry - handle lack of an IDE interrupt
  746. * @data: timer callback magic (hwgroup)
  747. *
  748. * An IDE command has timed out before the expected drive return
  749. * occurred. At this point we attempt to clean up the current
  750. * mess. If the current handler includes an expiry handler then
  751. * we invoke the expiry handler, and providing it is happy the
  752. * work is done. If that fails we apply generic recovery rules
  753. * invoking the handler and checking the drive DMA status. We
  754. * have an excessively incestuous relationship with the DMA
  755. * logic that wants cleaning up.
  756. */
  757. void ide_timer_expiry (unsigned long data)
  758. {
  759. ide_hwgroup_t *hwgroup = (ide_hwgroup_t *) data;
  760. ide_drive_t *uninitialized_var(drive);
  761. ide_handler_t *handler;
  762. ide_expiry_t *expiry;
  763. unsigned long flags;
  764. unsigned long wait = -1;
  765. int plug_device = 0;
  766. spin_lock_irqsave(&hwgroup->lock, flags);
  767. if (((handler = hwgroup->handler) == NULL) ||
  768. (hwgroup->req_gen != hwgroup->req_gen_timer)) {
  769. /*
  770. * Either a marginal timeout occurred
  771. * (got the interrupt just as timer expired),
  772. * or we were "sleeping" to give other devices a chance.
  773. * Either way, we don't really want to complain about anything.
  774. */
  775. } else {
  776. drive = hwgroup->drive;
  777. if (!drive) {
  778. printk(KERN_ERR "ide_timer_expiry: hwgroup->drive was NULL\n");
  779. hwgroup->handler = NULL;
  780. } else {
  781. ide_hwif_t *hwif;
  782. ide_startstop_t startstop = ide_stopped;
  783. if ((expiry = hwgroup->expiry) != NULL) {
  784. /* continue */
  785. if ((wait = expiry(drive)) > 0) {
  786. /* reset timer */
  787. hwgroup->timer.expires = jiffies + wait;
  788. hwgroup->req_gen_timer = hwgroup->req_gen;
  789. add_timer(&hwgroup->timer);
  790. spin_unlock_irqrestore(&hwgroup->lock, flags);
  791. return;
  792. }
  793. }
  794. hwgroup->handler = NULL;
  795. /*
  796. * We need to simulate a real interrupt when invoking
  797. * the handler() function, which means we need to
  798. * globally mask the specific IRQ:
  799. */
  800. spin_unlock(&hwgroup->lock);
  801. hwif = HWIF(drive);
  802. /* disable_irq_nosync ?? */
  803. disable_irq(hwif->irq);
  804. /* local CPU only,
  805. * as if we were handling an interrupt */
  806. local_irq_disable();
  807. if (hwgroup->polling) {
  808. startstop = handler(drive);
  809. } else if (drive_is_ready(drive)) {
  810. if (drive->waiting_for_dma)
  811. hwif->dma_ops->dma_lost_irq(drive);
  812. (void)ide_ack_intr(hwif);
  813. printk(KERN_WARNING "%s: lost interrupt\n", drive->name);
  814. startstop = handler(drive);
  815. } else {
  816. if (drive->waiting_for_dma) {
  817. startstop = ide_dma_timeout_retry(drive, wait);
  818. } else
  819. startstop =
  820. ide_error(drive, "irq timeout",
  821. hwif->tp_ops->read_status(hwif));
  822. }
  823. spin_lock_irq(&hwgroup->lock);
  824. enable_irq(hwif->irq);
  825. if (startstop == ide_stopped) {
  826. ide_unlock_hwgroup(hwgroup);
  827. plug_device = 1;
  828. }
  829. }
  830. }
  831. spin_unlock_irqrestore(&hwgroup->lock, flags);
  832. if (plug_device)
  833. ide_plug_device(drive);
  834. }
  835. /**
  836. * unexpected_intr - handle an unexpected IDE interrupt
  837. * @irq: interrupt line
  838. * @hwgroup: hwgroup being processed
  839. *
  840. * There's nothing really useful we can do with an unexpected interrupt,
  841. * other than reading the status register (to clear it), and logging it.
  842. * There should be no way that an irq can happen before we're ready for it,
  843. * so we needn't worry much about losing an "important" interrupt here.
  844. *
  845. * On laptops (and "green" PCs), an unexpected interrupt occurs whenever
  846. * the drive enters "idle", "standby", or "sleep" mode, so if the status
  847. * looks "good", we just ignore the interrupt completely.
  848. *
  849. * This routine assumes __cli() is in effect when called.
  850. *
  851. * If an unexpected interrupt happens on irq15 while we are handling irq14
  852. * and if the two interfaces are "serialized" (CMD640), then it looks like
  853. * we could screw up by interfering with a new request being set up for
  854. * irq15.
  855. *
  856. * In reality, this is a non-issue. The new command is not sent unless
  857. * the drive is ready to accept one, in which case we know the drive is
  858. * not trying to interrupt us. And ide_set_handler() is always invoked
  859. * before completing the issuance of any new drive command, so we will not
  860. * be accidentally invoked as a result of any valid command completion
  861. * interrupt.
  862. *
  863. * Note that we must walk the entire hwgroup here. We know which hwif
  864. * is doing the current command, but we don't know which hwif burped
  865. * mysteriously.
  866. */
  867. static void unexpected_intr (int irq, ide_hwgroup_t *hwgroup)
  868. {
  869. u8 stat;
  870. ide_hwif_t *hwif = hwgroup->hwif;
  871. /*
  872. * handle the unexpected interrupt
  873. */
  874. do {
  875. if (hwif->irq == irq) {
  876. stat = hwif->tp_ops->read_status(hwif);
  877. if (!OK_STAT(stat, ATA_DRDY, BAD_STAT)) {
  878. /* Try to not flood the console with msgs */
  879. static unsigned long last_msgtime, count;
  880. ++count;
  881. if (time_after(jiffies, last_msgtime + HZ)) {
  882. last_msgtime = jiffies;
  883. printk(KERN_ERR "%s%s: unexpected interrupt, "
  884. "status=0x%02x, count=%ld\n",
  885. hwif->name,
  886. (hwif->next==hwgroup->hwif) ? "" : "(?)", stat, count);
  887. }
  888. }
  889. }
  890. } while ((hwif = hwif->next) != hwgroup->hwif);
  891. }
  892. /**
  893. * ide_intr - default IDE interrupt handler
  894. * @irq: interrupt number
  895. * @dev_id: hwif group
  896. * @regs: unused weirdness from the kernel irq layer
  897. *
  898. * This is the default IRQ handler for the IDE layer. You should
  899. * not need to override it. If you do be aware it is subtle in
  900. * places
  901. *
  902. * hwgroup->hwif is the interface in the group currently performing
  903. * a command. hwgroup->drive is the drive and hwgroup->handler is
  904. * the IRQ handler to call. As we issue a command the handlers
  905. * step through multiple states, reassigning the handler to the
  906. * next step in the process. Unlike a smart SCSI controller IDE
  907. * expects the main processor to sequence the various transfer
  908. * stages. We also manage a poll timer to catch up with most
  909. * timeout situations. There are still a few where the handlers
  910. * don't ever decide to give up.
  911. *
  912. * The handler eventually returns ide_stopped to indicate the
  913. * request completed. At this point we issue the next request
  914. * on the hwgroup and the process begins again.
  915. */
  916. irqreturn_t ide_intr (int irq, void *dev_id)
  917. {
  918. unsigned long flags;
  919. ide_hwgroup_t *hwgroup = (ide_hwgroup_t *)dev_id;
  920. ide_hwif_t *hwif = hwgroup->hwif;
  921. ide_drive_t *uninitialized_var(drive);
  922. ide_handler_t *handler;
  923. ide_startstop_t startstop;
  924. irqreturn_t irq_ret = IRQ_NONE;
  925. int plug_device = 0;
  926. spin_lock_irqsave(&hwgroup->lock, flags);
  927. if (!ide_ack_intr(hwif))
  928. goto out;
  929. if ((handler = hwgroup->handler) == NULL || hwgroup->polling) {
  930. /*
  931. * Not expecting an interrupt from this drive.
  932. * That means this could be:
  933. * (1) an interrupt from another PCI device
  934. * sharing the same PCI INT# as us.
  935. * or (2) a drive just entered sleep or standby mode,
  936. * and is interrupting to let us know.
  937. * or (3) a spurious interrupt of unknown origin.
  938. *
  939. * For PCI, we cannot tell the difference,
  940. * so in that case we just ignore it and hope it goes away.
  941. *
  942. * FIXME: unexpected_intr should be hwif-> then we can
  943. * remove all the ifdef PCI crap
  944. */
  945. #ifdef CONFIG_BLK_DEV_IDEPCI
  946. if (hwif->chipset != ide_pci)
  947. #endif /* CONFIG_BLK_DEV_IDEPCI */
  948. {
  949. /*
  950. * Probably not a shared PCI interrupt,
  951. * so we can safely try to do something about it:
  952. */
  953. unexpected_intr(irq, hwgroup);
  954. #ifdef CONFIG_BLK_DEV_IDEPCI
  955. } else {
  956. /*
  957. * Whack the status register, just in case
  958. * we have a leftover pending IRQ.
  959. */
  960. (void)hwif->tp_ops->read_status(hwif);
  961. #endif /* CONFIG_BLK_DEV_IDEPCI */
  962. }
  963. goto out;
  964. }
  965. drive = hwgroup->drive;
  966. if (!drive) {
  967. /*
  968. * This should NEVER happen, and there isn't much
  969. * we could do about it here.
  970. *
  971. * [Note - this can occur if the drive is hot unplugged]
  972. */
  973. goto out_handled;
  974. }
  975. if (!drive_is_ready(drive))
  976. /*
  977. * This happens regularly when we share a PCI IRQ with
  978. * another device. Unfortunately, it can also happen
  979. * with some buggy drives that trigger the IRQ before
  980. * their status register is up to date. Hopefully we have
  981. * enough advance overhead that the latter isn't a problem.
  982. */
  983. goto out;
  984. hwgroup->handler = NULL;
  985. hwgroup->req_gen++;
  986. del_timer(&hwgroup->timer);
  987. spin_unlock(&hwgroup->lock);
  988. if (hwif->port_ops && hwif->port_ops->clear_irq)
  989. hwif->port_ops->clear_irq(drive);
  990. if (drive->dev_flags & IDE_DFLAG_UNMASK)
  991. local_irq_enable_in_hardirq();
  992. /* service this interrupt, may set handler for next interrupt */
  993. startstop = handler(drive);
  994. spin_lock_irq(&hwgroup->lock);
  995. /*
  996. * Note that handler() may have set things up for another
  997. * interrupt to occur soon, but it cannot happen until
  998. * we exit from this routine, because it will be the
  999. * same irq as is currently being serviced here, and Linux
  1000. * won't allow another of the same (on any CPU) until we return.
  1001. */
  1002. if (startstop == ide_stopped) {
  1003. if (hwgroup->handler == NULL) { /* paranoia */
  1004. ide_unlock_hwgroup(hwgroup);
  1005. plug_device = 1;
  1006. } else
  1007. printk(KERN_ERR "%s: %s: huh? expected NULL handler "
  1008. "on exit\n", __func__, drive->name);
  1009. }
  1010. out_handled:
  1011. irq_ret = IRQ_HANDLED;
  1012. out:
  1013. spin_unlock_irqrestore(&hwgroup->lock, flags);
  1014. if (plug_device)
  1015. ide_plug_device(drive);
  1016. return irq_ret;
  1017. }
  1018. /**
  1019. * ide_do_drive_cmd - issue IDE special command
  1020. * @drive: device to issue command
  1021. * @rq: request to issue
  1022. *
  1023. * This function issues a special IDE device request
  1024. * onto the request queue.
  1025. *
  1026. * the rq is queued at the head of the request queue, displacing
  1027. * the currently-being-processed request and this function
  1028. * returns immediately without waiting for the new rq to be
  1029. * completed. This is VERY DANGEROUS, and is intended for
  1030. * careful use by the ATAPI tape/cdrom driver code.
  1031. */
  1032. void ide_do_drive_cmd(ide_drive_t *drive, struct request *rq)
  1033. {
  1034. ide_hwgroup_t *hwgroup = drive->hwif->hwgroup;
  1035. struct request_queue *q = drive->queue;
  1036. unsigned long flags;
  1037. hwgroup->rq = NULL;
  1038. spin_lock_irqsave(q->queue_lock, flags);
  1039. __elv_add_request(q, rq, ELEVATOR_INSERT_FRONT, 0);
  1040. blk_start_queueing(q);
  1041. spin_unlock_irqrestore(q->queue_lock, flags);
  1042. }
  1043. EXPORT_SYMBOL(ide_do_drive_cmd);
  1044. void ide_pktcmd_tf_load(ide_drive_t *drive, u32 tf_flags, u16 bcount, u8 dma)
  1045. {
  1046. ide_hwif_t *hwif = drive->hwif;
  1047. ide_task_t task;
  1048. memset(&task, 0, sizeof(task));
  1049. task.tf_flags = IDE_TFLAG_OUT_LBAH | IDE_TFLAG_OUT_LBAM |
  1050. IDE_TFLAG_OUT_FEATURE | tf_flags;
  1051. task.tf.feature = dma; /* Use PIO/DMA */
  1052. task.tf.lbam = bcount & 0xff;
  1053. task.tf.lbah = (bcount >> 8) & 0xff;
  1054. ide_tf_dump(drive->name, &task.tf);
  1055. hwif->tp_ops->set_irq(hwif, 1);
  1056. SELECT_MASK(drive, 0);
  1057. hwif->tp_ops->tf_load(drive, &task);
  1058. }
  1059. EXPORT_SYMBOL_GPL(ide_pktcmd_tf_load);
  1060. void ide_pad_transfer(ide_drive_t *drive, int write, int len)
  1061. {
  1062. ide_hwif_t *hwif = drive->hwif;
  1063. u8 buf[4] = { 0 };
  1064. while (len > 0) {
  1065. if (write)
  1066. hwif->tp_ops->output_data(drive, NULL, buf, min(4, len));
  1067. else
  1068. hwif->tp_ops->input_data(drive, NULL, buf, min(4, len));
  1069. len -= 4;
  1070. }
  1071. }
  1072. EXPORT_SYMBOL_GPL(ide_pad_transfer);