ide-io.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771
  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/completion.h>
  42. #include <linux/reboot.h>
  43. #include <linux/cdrom.h>
  44. #include <linux/seq_file.h>
  45. #include <linux/device.h>
  46. #include <linux/kmod.h>
  47. #include <linux/scatterlist.h>
  48. #include <linux/bitops.h>
  49. #include <asm/byteorder.h>
  50. #include <asm/irq.h>
  51. #include <asm/uaccess.h>
  52. #include <asm/io.h>
  53. static int __ide_end_request(ide_drive_t *drive, struct request *rq,
  54. int uptodate, unsigned int nr_bytes, int dequeue)
  55. {
  56. int ret = 1;
  57. /*
  58. * if failfast is set on a request, override number of sectors and
  59. * complete the whole request right now
  60. */
  61. if (blk_noretry_request(rq) && end_io_error(uptodate))
  62. nr_bytes = rq->hard_nr_sectors << 9;
  63. if (!blk_fs_request(rq) && end_io_error(uptodate) && !rq->errors)
  64. rq->errors = -EIO;
  65. /*
  66. * decide whether to reenable DMA -- 3 is a random magic for now,
  67. * if we DMA timeout more than 3 times, just stay in PIO
  68. */
  69. if (drive->state == DMA_PIO_RETRY && drive->retry_pio <= 3) {
  70. drive->state = 0;
  71. HWGROUP(drive)->hwif->ide_dma_on(drive);
  72. }
  73. if (!end_that_request_chunk(rq, uptodate, nr_bytes)) {
  74. add_disk_randomness(rq->rq_disk);
  75. if (dequeue) {
  76. if (!list_empty(&rq->queuelist))
  77. blkdev_dequeue_request(rq);
  78. HWGROUP(drive)->rq = NULL;
  79. }
  80. end_that_request_last(rq, uptodate);
  81. ret = 0;
  82. }
  83. return ret;
  84. }
  85. /**
  86. * ide_end_request - complete an IDE I/O
  87. * @drive: IDE device for the I/O
  88. * @uptodate:
  89. * @nr_sectors: number of sectors completed
  90. *
  91. * This is our end_request wrapper function. We complete the I/O
  92. * update random number input and dequeue the request, which if
  93. * it was tagged may be out of order.
  94. */
  95. int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors)
  96. {
  97. unsigned int nr_bytes = nr_sectors << 9;
  98. struct request *rq;
  99. unsigned long flags;
  100. int ret = 1;
  101. /*
  102. * room for locking improvements here, the calls below don't
  103. * need the queue lock held at all
  104. */
  105. spin_lock_irqsave(&ide_lock, flags);
  106. rq = HWGROUP(drive)->rq;
  107. if (!nr_bytes) {
  108. if (blk_pc_request(rq))
  109. nr_bytes = rq->data_len;
  110. else
  111. nr_bytes = rq->hard_cur_sectors << 9;
  112. }
  113. ret = __ide_end_request(drive, rq, uptodate, nr_bytes, 1);
  114. spin_unlock_irqrestore(&ide_lock, flags);
  115. return ret;
  116. }
  117. EXPORT_SYMBOL(ide_end_request);
  118. /*
  119. * Power Management state machine. This one is rather trivial for now,
  120. * we should probably add more, like switching back to PIO on suspend
  121. * to help some BIOSes, re-do the door locking on resume, etc...
  122. */
  123. enum {
  124. ide_pm_flush_cache = ide_pm_state_start_suspend,
  125. idedisk_pm_standby,
  126. idedisk_pm_restore_pio = ide_pm_state_start_resume,
  127. idedisk_pm_idle,
  128. ide_pm_restore_dma,
  129. };
  130. static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 stat, u8 error)
  131. {
  132. struct request_pm_state *pm = rq->data;
  133. if (drive->media != ide_disk)
  134. return;
  135. switch (pm->pm_step) {
  136. case ide_pm_flush_cache: /* Suspend step 1 (flush cache) complete */
  137. if (pm->pm_state == PM_EVENT_FREEZE)
  138. pm->pm_step = ide_pm_state_completed;
  139. else
  140. pm->pm_step = idedisk_pm_standby;
  141. break;
  142. case idedisk_pm_standby: /* Suspend step 2 (standby) complete */
  143. pm->pm_step = ide_pm_state_completed;
  144. break;
  145. case idedisk_pm_restore_pio: /* Resume step 1 complete */
  146. pm->pm_step = idedisk_pm_idle;
  147. break;
  148. case idedisk_pm_idle: /* Resume step 2 (idle) complete */
  149. pm->pm_step = ide_pm_restore_dma;
  150. break;
  151. }
  152. }
  153. static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *rq)
  154. {
  155. struct request_pm_state *pm = rq->data;
  156. ide_task_t *args = rq->special;
  157. memset(args, 0, sizeof(*args));
  158. switch (pm->pm_step) {
  159. case ide_pm_flush_cache: /* Suspend step 1 (flush cache) */
  160. if (drive->media != ide_disk)
  161. break;
  162. /* Not supported? Switch to next step now. */
  163. if (!drive->wcache || !ide_id_has_flush_cache(drive->id)) {
  164. ide_complete_power_step(drive, rq, 0, 0);
  165. return ide_stopped;
  166. }
  167. if (ide_id_has_flush_cache_ext(drive->id))
  168. args->tf.command = WIN_FLUSH_CACHE_EXT;
  169. else
  170. args->tf.command = WIN_FLUSH_CACHE;
  171. goto out_do_tf;
  172. case idedisk_pm_standby: /* Suspend step 2 (standby) */
  173. args->tf.command = WIN_STANDBYNOW1;
  174. goto out_do_tf;
  175. case idedisk_pm_restore_pio: /* Resume step 1 (restore PIO) */
  176. ide_set_max_pio(drive);
  177. /*
  178. * skip idedisk_pm_idle for ATAPI devices
  179. */
  180. if (drive->media != ide_disk)
  181. pm->pm_step = ide_pm_restore_dma;
  182. else
  183. ide_complete_power_step(drive, rq, 0, 0);
  184. return ide_stopped;
  185. case idedisk_pm_idle: /* Resume step 2 (idle) */
  186. args->tf.command = WIN_IDLEIMMEDIATE;
  187. goto out_do_tf;
  188. case ide_pm_restore_dma: /* Resume step 3 (restore DMA) */
  189. /*
  190. * Right now, all we do is call ide_set_dma(drive),
  191. * we could be smarter and check for current xfer_speed
  192. * in struct drive etc...
  193. */
  194. if (drive->hwif->ide_dma_on == NULL)
  195. break;
  196. drive->hwif->dma_off_quietly(drive);
  197. /*
  198. * TODO: respect ->using_dma setting
  199. */
  200. ide_set_dma(drive);
  201. break;
  202. }
  203. pm->pm_step = ide_pm_state_completed;
  204. return ide_stopped;
  205. out_do_tf:
  206. args->tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE;
  207. if (drive->addressing == 1)
  208. args->tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_OUT_HOB);
  209. args->command_type = IDE_DRIVE_TASK_NO_DATA;
  210. args->handler = task_no_data_intr;
  211. return do_rw_taskfile(drive, args);
  212. }
  213. /**
  214. * ide_end_dequeued_request - complete an IDE I/O
  215. * @drive: IDE device for the I/O
  216. * @uptodate:
  217. * @nr_sectors: number of sectors completed
  218. *
  219. * Complete an I/O that is no longer on the request queue. This
  220. * typically occurs when we pull the request and issue a REQUEST_SENSE.
  221. * We must still finish the old request but we must not tamper with the
  222. * queue in the meantime.
  223. *
  224. * NOTE: This path does not handle barrier, but barrier is not supported
  225. * on ide-cd anyway.
  226. */
  227. int ide_end_dequeued_request(ide_drive_t *drive, struct request *rq,
  228. int uptodate, int nr_sectors)
  229. {
  230. unsigned long flags;
  231. int ret;
  232. spin_lock_irqsave(&ide_lock, flags);
  233. BUG_ON(!blk_rq_started(rq));
  234. ret = __ide_end_request(drive, rq, uptodate, nr_sectors << 9, 0);
  235. spin_unlock_irqrestore(&ide_lock, flags);
  236. return ret;
  237. }
  238. EXPORT_SYMBOL_GPL(ide_end_dequeued_request);
  239. /**
  240. * ide_complete_pm_request - end the current Power Management request
  241. * @drive: target drive
  242. * @rq: request
  243. *
  244. * This function cleans up the current PM request and stops the queue
  245. * if necessary.
  246. */
  247. static void ide_complete_pm_request (ide_drive_t *drive, struct request *rq)
  248. {
  249. unsigned long flags;
  250. #ifdef DEBUG_PM
  251. printk("%s: completing PM request, %s\n", drive->name,
  252. blk_pm_suspend_request(rq) ? "suspend" : "resume");
  253. #endif
  254. spin_lock_irqsave(&ide_lock, flags);
  255. if (blk_pm_suspend_request(rq)) {
  256. blk_stop_queue(drive->queue);
  257. } else {
  258. drive->blocked = 0;
  259. blk_start_queue(drive->queue);
  260. }
  261. blkdev_dequeue_request(rq);
  262. HWGROUP(drive)->rq = NULL;
  263. end_that_request_last(rq, 1);
  264. spin_unlock_irqrestore(&ide_lock, flags);
  265. }
  266. /**
  267. * ide_end_drive_cmd - end an explicit drive command
  268. * @drive: command
  269. * @stat: status bits
  270. * @err: error bits
  271. *
  272. * Clean up after success/failure of an explicit drive command.
  273. * These get thrown onto the queue so they are synchronized with
  274. * real I/O operations on the drive.
  275. *
  276. * In LBA48 mode we have to read the register set twice to get
  277. * all the extra information out.
  278. */
  279. void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
  280. {
  281. ide_hwif_t *hwif = HWIF(drive);
  282. unsigned long flags;
  283. struct request *rq;
  284. spin_lock_irqsave(&ide_lock, flags);
  285. rq = HWGROUP(drive)->rq;
  286. spin_unlock_irqrestore(&ide_lock, flags);
  287. if (rq->cmd_type == REQ_TYPE_ATA_CMD) {
  288. u8 *args = (u8 *) rq->buffer;
  289. if (rq->errors == 0)
  290. rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT);
  291. if (args) {
  292. args[0] = stat;
  293. args[1] = err;
  294. args[2] = hwif->INB(IDE_NSECTOR_REG);
  295. }
  296. } else if (rq->cmd_type == REQ_TYPE_ATA_TASK) {
  297. u8 *args = (u8 *) rq->buffer;
  298. if (rq->errors == 0)
  299. rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT);
  300. if (args) {
  301. args[0] = stat;
  302. args[1] = err;
  303. /* be sure we're looking at the low order bits */
  304. hwif->OUTB(drive->ctl & ~0x80, IDE_CONTROL_REG);
  305. args[2] = hwif->INB(IDE_NSECTOR_REG);
  306. args[3] = hwif->INB(IDE_SECTOR_REG);
  307. args[4] = hwif->INB(IDE_LCYL_REG);
  308. args[5] = hwif->INB(IDE_HCYL_REG);
  309. args[6] = hwif->INB(IDE_SELECT_REG);
  310. }
  311. } else if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
  312. ide_task_t *args = (ide_task_t *) rq->special;
  313. if (rq->errors == 0)
  314. rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT);
  315. if (args) {
  316. struct ide_taskfile *tf = &args->tf;
  317. if (args->tf_in_flags.b.data) {
  318. u16 data = hwif->INW(IDE_DATA_REG);
  319. tf->data = data & 0xff;
  320. tf->hob_data = (data >> 8) & 0xff;
  321. }
  322. tf->error = err;
  323. /* be sure we're looking at the low order bits */
  324. hwif->OUTB(drive->ctl & ~0x80, IDE_CONTROL_REG);
  325. tf->nsect = hwif->INB(IDE_NSECTOR_REG);
  326. tf->lbal = hwif->INB(IDE_SECTOR_REG);
  327. tf->lbam = hwif->INB(IDE_LCYL_REG);
  328. tf->lbah = hwif->INB(IDE_HCYL_REG);
  329. tf->device = hwif->INB(IDE_SELECT_REG);
  330. tf->status = stat;
  331. if (args->tf_flags & IDE_TFLAG_LBA48) {
  332. hwif->OUTB(drive->ctl|0x80, IDE_CONTROL_REG);
  333. tf->hob_feature = hwif->INB(IDE_FEATURE_REG);
  334. tf->hob_nsect = hwif->INB(IDE_NSECTOR_REG);
  335. tf->hob_lbal = hwif->INB(IDE_SECTOR_REG);
  336. tf->hob_lbam = hwif->INB(IDE_LCYL_REG);
  337. tf->hob_lbah = hwif->INB(IDE_HCYL_REG);
  338. }
  339. }
  340. } else if (blk_pm_request(rq)) {
  341. struct request_pm_state *pm = rq->data;
  342. #ifdef DEBUG_PM
  343. printk("%s: complete_power_step(step: %d, stat: %x, err: %x)\n",
  344. drive->name, rq->pm->pm_step, stat, err);
  345. #endif
  346. ide_complete_power_step(drive, rq, stat, err);
  347. if (pm->pm_step == ide_pm_state_completed)
  348. ide_complete_pm_request(drive, rq);
  349. return;
  350. }
  351. spin_lock_irqsave(&ide_lock, flags);
  352. blkdev_dequeue_request(rq);
  353. HWGROUP(drive)->rq = NULL;
  354. rq->errors = err;
  355. end_that_request_last(rq, !rq->errors);
  356. spin_unlock_irqrestore(&ide_lock, flags);
  357. }
  358. EXPORT_SYMBOL(ide_end_drive_cmd);
  359. /**
  360. * try_to_flush_leftover_data - flush junk
  361. * @drive: drive to flush
  362. *
  363. * try_to_flush_leftover_data() is invoked in response to a drive
  364. * unexpectedly having its DRQ_STAT bit set. As an alternative to
  365. * resetting the drive, this routine tries to clear the condition
  366. * by read a sector's worth of data from the drive. Of course,
  367. * this may not help if the drive is *waiting* for data from *us*.
  368. */
  369. static void try_to_flush_leftover_data (ide_drive_t *drive)
  370. {
  371. int i = (drive->mult_count ? drive->mult_count : 1) * SECTOR_WORDS;
  372. if (drive->media != ide_disk)
  373. return;
  374. while (i > 0) {
  375. u32 buffer[16];
  376. u32 wcount = (i > 16) ? 16 : i;
  377. i -= wcount;
  378. HWIF(drive)->ata_input_data(drive, buffer, wcount);
  379. }
  380. }
  381. static void ide_kill_rq(ide_drive_t *drive, struct request *rq)
  382. {
  383. if (rq->rq_disk) {
  384. ide_driver_t *drv;
  385. drv = *(ide_driver_t **)rq->rq_disk->private_data;
  386. drv->end_request(drive, 0, 0);
  387. } else
  388. ide_end_request(drive, 0, 0);
  389. }
  390. static ide_startstop_t ide_ata_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
  391. {
  392. ide_hwif_t *hwif = drive->hwif;
  393. if (stat & BUSY_STAT || ((stat & WRERR_STAT) && !drive->nowerr)) {
  394. /* other bits are useless when BUSY */
  395. rq->errors |= ERROR_RESET;
  396. } else if (stat & ERR_STAT) {
  397. /* err has different meaning on cdrom and tape */
  398. if (err == ABRT_ERR) {
  399. if (drive->select.b.lba &&
  400. /* some newer drives don't support WIN_SPECIFY */
  401. hwif->INB(IDE_COMMAND_REG) == WIN_SPECIFY)
  402. return ide_stopped;
  403. } else if ((err & BAD_CRC) == BAD_CRC) {
  404. /* UDMA crc error, just retry the operation */
  405. drive->crc_count++;
  406. } else if (err & (BBD_ERR | ECC_ERR)) {
  407. /* retries won't help these */
  408. rq->errors = ERROR_MAX;
  409. } else if (err & TRK0_ERR) {
  410. /* help it find track zero */
  411. rq->errors |= ERROR_RECAL;
  412. }
  413. }
  414. if ((stat & DRQ_STAT) && rq_data_dir(rq) == READ &&
  415. (hwif->host_flags & IDE_HFLAG_ERROR_STOPS_FIFO) == 0)
  416. try_to_flush_leftover_data(drive);
  417. if (rq->errors >= ERROR_MAX || blk_noretry_request(rq)) {
  418. ide_kill_rq(drive, rq);
  419. return ide_stopped;
  420. }
  421. if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
  422. rq->errors |= ERROR_RESET;
  423. if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
  424. ++rq->errors;
  425. return ide_do_reset(drive);
  426. }
  427. if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)
  428. drive->special.b.recalibrate = 1;
  429. ++rq->errors;
  430. return ide_stopped;
  431. }
  432. static ide_startstop_t ide_atapi_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
  433. {
  434. ide_hwif_t *hwif = drive->hwif;
  435. if (stat & BUSY_STAT || ((stat & WRERR_STAT) && !drive->nowerr)) {
  436. /* other bits are useless when BUSY */
  437. rq->errors |= ERROR_RESET;
  438. } else {
  439. /* add decoding error stuff */
  440. }
  441. if (hwif->INB(IDE_STATUS_REG) & (BUSY_STAT|DRQ_STAT))
  442. /* force an abort */
  443. hwif->OUTB(WIN_IDLEIMMEDIATE, IDE_COMMAND_REG);
  444. if (rq->errors >= ERROR_MAX) {
  445. ide_kill_rq(drive, rq);
  446. } else {
  447. if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
  448. ++rq->errors;
  449. return ide_do_reset(drive);
  450. }
  451. ++rq->errors;
  452. }
  453. return ide_stopped;
  454. }
  455. ide_startstop_t
  456. __ide_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
  457. {
  458. if (drive->media == ide_disk)
  459. return ide_ata_error(drive, rq, stat, err);
  460. return ide_atapi_error(drive, rq, stat, err);
  461. }
  462. EXPORT_SYMBOL_GPL(__ide_error);
  463. /**
  464. * ide_error - handle an error on the IDE
  465. * @drive: drive the error occurred on
  466. * @msg: message to report
  467. * @stat: status bits
  468. *
  469. * ide_error() takes action based on the error returned by the drive.
  470. * For normal I/O that may well include retries. We deal with
  471. * both new-style (taskfile) and old style command handling here.
  472. * In the case of taskfile command handling there is work left to
  473. * do
  474. */
  475. ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, u8 stat)
  476. {
  477. struct request *rq;
  478. u8 err;
  479. err = ide_dump_status(drive, msg, stat);
  480. if ((rq = HWGROUP(drive)->rq) == NULL)
  481. return ide_stopped;
  482. /* retry only "normal" I/O: */
  483. if (!blk_fs_request(rq)) {
  484. rq->errors = 1;
  485. ide_end_drive_cmd(drive, stat, err);
  486. return ide_stopped;
  487. }
  488. if (rq->rq_disk) {
  489. ide_driver_t *drv;
  490. drv = *(ide_driver_t **)rq->rq_disk->private_data;
  491. return drv->error(drive, rq, stat, err);
  492. } else
  493. return __ide_error(drive, rq, stat, err);
  494. }
  495. EXPORT_SYMBOL_GPL(ide_error);
  496. ide_startstop_t __ide_abort(ide_drive_t *drive, struct request *rq)
  497. {
  498. if (drive->media != ide_disk)
  499. rq->errors |= ERROR_RESET;
  500. ide_kill_rq(drive, rq);
  501. return ide_stopped;
  502. }
  503. EXPORT_SYMBOL_GPL(__ide_abort);
  504. /**
  505. * ide_abort - abort pending IDE operations
  506. * @drive: drive the error occurred on
  507. * @msg: message to report
  508. *
  509. * ide_abort kills and cleans up when we are about to do a
  510. * host initiated reset on active commands. Longer term we
  511. * want handlers to have sensible abort handling themselves
  512. *
  513. * This differs fundamentally from ide_error because in
  514. * this case the command is doing just fine when we
  515. * blow it away.
  516. */
  517. ide_startstop_t ide_abort(ide_drive_t *drive, const char *msg)
  518. {
  519. struct request *rq;
  520. if (drive == NULL || (rq = HWGROUP(drive)->rq) == NULL)
  521. return ide_stopped;
  522. /* retry only "normal" I/O: */
  523. if (!blk_fs_request(rq)) {
  524. rq->errors = 1;
  525. ide_end_drive_cmd(drive, BUSY_STAT, 0);
  526. return ide_stopped;
  527. }
  528. if (rq->rq_disk) {
  529. ide_driver_t *drv;
  530. drv = *(ide_driver_t **)rq->rq_disk->private_data;
  531. return drv->abort(drive, rq);
  532. } else
  533. return __ide_abort(drive, rq);
  534. }
  535. /**
  536. * drive_cmd_intr - drive command completion interrupt
  537. * @drive: drive the completion interrupt occurred on
  538. *
  539. * drive_cmd_intr() is invoked on completion of a special DRIVE_CMD.
  540. * We do any necessary data reading and then wait for the drive to
  541. * go non busy. At that point we may read the error data and complete
  542. * the request
  543. */
  544. static ide_startstop_t drive_cmd_intr (ide_drive_t *drive)
  545. {
  546. struct request *rq = HWGROUP(drive)->rq;
  547. ide_hwif_t *hwif = HWIF(drive);
  548. u8 *args = (u8 *) rq->buffer;
  549. u8 stat = hwif->INB(IDE_STATUS_REG);
  550. int retries = 10;
  551. local_irq_enable_in_hardirq();
  552. if (rq->cmd_type == REQ_TYPE_ATA_CMD &&
  553. (stat & DRQ_STAT) && args && args[3]) {
  554. u8 io_32bit = drive->io_32bit;
  555. drive->io_32bit = 0;
  556. hwif->ata_input_data(drive, &args[4], args[3] * SECTOR_WORDS);
  557. drive->io_32bit = io_32bit;
  558. while (((stat = hwif->INB(IDE_STATUS_REG)) & BUSY_STAT) && retries--)
  559. udelay(100);
  560. }
  561. if (!OK_STAT(stat, READY_STAT, BAD_STAT))
  562. return ide_error(drive, "drive_cmd", stat);
  563. /* calls ide_end_drive_cmd */
  564. ide_end_drive_cmd(drive, stat, hwif->INB(IDE_ERROR_REG));
  565. return ide_stopped;
  566. }
  567. static void ide_init_specify_cmd(ide_drive_t *drive, ide_task_t *task)
  568. {
  569. task->tf.nsect = drive->sect;
  570. task->tf.lbal = drive->sect;
  571. task->tf.lbam = drive->cyl;
  572. task->tf.lbah = drive->cyl >> 8;
  573. task->tf.device = ((drive->head - 1) | drive->select.all) & ~ATA_LBA;
  574. task->tf.command = WIN_SPECIFY;
  575. task->handler = &set_geometry_intr;
  576. }
  577. static void ide_init_restore_cmd(ide_drive_t *drive, ide_task_t *task)
  578. {
  579. task->tf.nsect = drive->sect;
  580. task->tf.command = WIN_RESTORE;
  581. task->handler = &recal_intr;
  582. }
  583. static void ide_init_setmult_cmd(ide_drive_t *drive, ide_task_t *task)
  584. {
  585. task->tf.nsect = drive->mult_req;
  586. task->tf.command = WIN_SETMULT;
  587. task->handler = &set_multmode_intr;
  588. }
  589. static ide_startstop_t ide_disk_special(ide_drive_t *drive)
  590. {
  591. special_t *s = &drive->special;
  592. ide_task_t args;
  593. memset(&args, 0, sizeof(ide_task_t));
  594. args.command_type = IDE_DRIVE_TASK_NO_DATA;
  595. if (s->b.set_geometry) {
  596. s->b.set_geometry = 0;
  597. ide_init_specify_cmd(drive, &args);
  598. } else if (s->b.recalibrate) {
  599. s->b.recalibrate = 0;
  600. ide_init_restore_cmd(drive, &args);
  601. } else if (s->b.set_multmode) {
  602. s->b.set_multmode = 0;
  603. if (drive->mult_req > drive->id->max_multsect)
  604. drive->mult_req = drive->id->max_multsect;
  605. ide_init_setmult_cmd(drive, &args);
  606. } else if (s->all) {
  607. int special = s->all;
  608. s->all = 0;
  609. printk(KERN_ERR "%s: bad special flag: 0x%02x\n", drive->name, special);
  610. return ide_stopped;
  611. }
  612. args.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE;
  613. if (drive->addressing == 1)
  614. args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_OUT_HOB);
  615. do_rw_taskfile(drive, &args);
  616. return ide_started;
  617. }
  618. /*
  619. * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
  620. */
  621. static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
  622. {
  623. switch (req_pio) {
  624. case 202:
  625. case 201:
  626. case 200:
  627. case 102:
  628. case 101:
  629. case 100:
  630. return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
  631. case 9:
  632. case 8:
  633. return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
  634. case 7:
  635. case 6:
  636. return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
  637. default:
  638. return 0;
  639. }
  640. }
  641. /**
  642. * do_special - issue some special commands
  643. * @drive: drive the command is for
  644. *
  645. * do_special() is used to issue WIN_SPECIFY, WIN_RESTORE, and WIN_SETMULT
  646. * commands to a drive. It used to do much more, but has been scaled
  647. * back.
  648. */
  649. static ide_startstop_t do_special (ide_drive_t *drive)
  650. {
  651. special_t *s = &drive->special;
  652. #ifdef DEBUG
  653. printk("%s: do_special: 0x%02x\n", drive->name, s->all);
  654. #endif
  655. if (s->b.set_tune) {
  656. ide_hwif_t *hwif = drive->hwif;
  657. u8 req_pio = drive->tune_req;
  658. s->b.set_tune = 0;
  659. if (set_pio_mode_abuse(drive->hwif, req_pio)) {
  660. if (hwif->set_pio_mode == NULL)
  661. return ide_stopped;
  662. /*
  663. * take ide_lock for drive->[no_]unmask/[no_]io_32bit
  664. */
  665. if (req_pio == 8 || req_pio == 9) {
  666. unsigned long flags;
  667. spin_lock_irqsave(&ide_lock, flags);
  668. hwif->set_pio_mode(drive, req_pio);
  669. spin_unlock_irqrestore(&ide_lock, flags);
  670. } else
  671. hwif->set_pio_mode(drive, req_pio);
  672. } else {
  673. int keep_dma = drive->using_dma;
  674. ide_set_pio(drive, req_pio);
  675. if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) {
  676. if (keep_dma)
  677. hwif->ide_dma_on(drive);
  678. }
  679. }
  680. return ide_stopped;
  681. } else {
  682. if (drive->media == ide_disk)
  683. return ide_disk_special(drive);
  684. s->all = 0;
  685. drive->mult_req = 0;
  686. return ide_stopped;
  687. }
  688. }
  689. void ide_map_sg(ide_drive_t *drive, struct request *rq)
  690. {
  691. ide_hwif_t *hwif = drive->hwif;
  692. struct scatterlist *sg = hwif->sg_table;
  693. if (hwif->sg_mapped) /* needed by ide-scsi */
  694. return;
  695. if (rq->cmd_type != REQ_TYPE_ATA_TASKFILE) {
  696. hwif->sg_nents = blk_rq_map_sg(drive->queue, rq, sg);
  697. } else {
  698. sg_init_one(sg, rq->buffer, rq->nr_sectors * SECTOR_SIZE);
  699. hwif->sg_nents = 1;
  700. }
  701. }
  702. EXPORT_SYMBOL_GPL(ide_map_sg);
  703. void ide_init_sg_cmd(ide_drive_t *drive, struct request *rq)
  704. {
  705. ide_hwif_t *hwif = drive->hwif;
  706. hwif->nsect = hwif->nleft = rq->nr_sectors;
  707. hwif->cursg_ofs = 0;
  708. hwif->cursg = NULL;
  709. }
  710. EXPORT_SYMBOL_GPL(ide_init_sg_cmd);
  711. /**
  712. * execute_drive_command - issue special drive command
  713. * @drive: the drive to issue the command on
  714. * @rq: the request structure holding the command
  715. *
  716. * execute_drive_cmd() issues a special drive command, usually
  717. * initiated by ioctl() from the external hdparm program. The
  718. * command can be a drive command, drive task or taskfile
  719. * operation. Weirdly you can call it with NULL to wait for
  720. * all commands to finish. Don't do this as that is due to change
  721. */
  722. static ide_startstop_t execute_drive_cmd (ide_drive_t *drive,
  723. struct request *rq)
  724. {
  725. ide_hwif_t *hwif = HWIF(drive);
  726. u8 *args = rq->buffer;
  727. ide_task_t ltask;
  728. struct ide_taskfile *tf = &ltask.tf;
  729. if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
  730. ide_task_t *task = rq->special;
  731. if (task == NULL)
  732. goto done;
  733. hwif->data_phase = task->data_phase;
  734. switch (hwif->data_phase) {
  735. case TASKFILE_MULTI_OUT:
  736. case TASKFILE_OUT:
  737. case TASKFILE_MULTI_IN:
  738. case TASKFILE_IN:
  739. ide_init_sg_cmd(drive, rq);
  740. ide_map_sg(drive, rq);
  741. default:
  742. break;
  743. }
  744. task->tf_flags |= IDE_TFLAG_OUT_DEVICE;
  745. if (drive->addressing == 1)
  746. task->tf_flags |= IDE_TFLAG_LBA48;
  747. if (task->tf_flags & IDE_TFLAG_FLAGGED)
  748. return flagged_taskfile(drive, task);
  749. task->tf_flags |= IDE_TFLAG_OUT_TF;
  750. if (task->tf_flags & IDE_TFLAG_LBA48)
  751. task->tf_flags |= IDE_TFLAG_OUT_HOB;
  752. return do_rw_taskfile(drive, task);
  753. }
  754. if (args == NULL)
  755. goto done;
  756. memset(&ltask, 0, sizeof(ltask));
  757. if (rq->cmd_type == REQ_TYPE_ATA_TASK) {
  758. #ifdef DEBUG
  759. printk("%s: DRIVE_TASK_CMD\n", drive->name);
  760. #endif
  761. memcpy(&ltask.tf_array[7], &args[1], 6);
  762. ltask.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE;
  763. } else { /* rq->cmd_type == REQ_TYPE_ATA_CMD */
  764. #ifdef DEBUG
  765. printk("%s: DRIVE_CMD\n", drive->name);
  766. #endif
  767. tf->feature = args[2];
  768. if (args[0] == WIN_SMART) {
  769. tf->nsect = args[3];
  770. tf->lbal = args[1];
  771. tf->lbam = 0x4f;
  772. tf->lbah = 0xc2;
  773. ltask.tf_flags = IDE_TFLAG_OUT_TF;
  774. } else {
  775. tf->nsect = args[1];
  776. ltask.tf_flags = IDE_TFLAG_OUT_FEATURE |
  777. IDE_TFLAG_OUT_NSECT;
  778. }
  779. }
  780. tf->command = args[0];
  781. ide_tf_load(drive, &ltask);
  782. ide_execute_command(drive, args[0], &drive_cmd_intr, WAIT_CMD, NULL);
  783. return ide_started;
  784. done:
  785. /*
  786. * NULL is actually a valid way of waiting for
  787. * all current requests to be flushed from the queue.
  788. */
  789. #ifdef DEBUG
  790. printk("%s: DRIVE_CMD (null)\n", drive->name);
  791. #endif
  792. ide_end_drive_cmd(drive,
  793. hwif->INB(IDE_STATUS_REG),
  794. hwif->INB(IDE_ERROR_REG));
  795. return ide_stopped;
  796. }
  797. static void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
  798. {
  799. struct request_pm_state *pm = rq->data;
  800. if (blk_pm_suspend_request(rq) &&
  801. pm->pm_step == ide_pm_state_start_suspend)
  802. /* Mark drive blocked when starting the suspend sequence. */
  803. drive->blocked = 1;
  804. else if (blk_pm_resume_request(rq) &&
  805. pm->pm_step == ide_pm_state_start_resume) {
  806. /*
  807. * The first thing we do on wakeup is to wait for BSY bit to
  808. * go away (with a looong timeout) as a drive on this hwif may
  809. * just be POSTing itself.
  810. * We do that before even selecting as the "other" device on
  811. * the bus may be broken enough to walk on our toes at this
  812. * point.
  813. */
  814. int rc;
  815. #ifdef DEBUG_PM
  816. printk("%s: Wakeup request inited, waiting for !BSY...\n", drive->name);
  817. #endif
  818. rc = ide_wait_not_busy(HWIF(drive), 35000);
  819. if (rc)
  820. printk(KERN_WARNING "%s: bus not ready on wakeup\n", drive->name);
  821. SELECT_DRIVE(drive);
  822. if (IDE_CONTROL_REG)
  823. HWIF(drive)->OUTB(drive->ctl, IDE_CONTROL_REG);
  824. rc = ide_wait_not_busy(HWIF(drive), 100000);
  825. if (rc)
  826. printk(KERN_WARNING "%s: drive not ready on wakeup\n", drive->name);
  827. }
  828. }
  829. /**
  830. * start_request - start of I/O and command issuing for IDE
  831. *
  832. * start_request() initiates handling of a new I/O request. It
  833. * accepts commands and I/O (read/write) requests. It also does
  834. * the final remapping for weird stuff like EZDrive. Once
  835. * device mapper can work sector level the EZDrive stuff can go away
  836. *
  837. * FIXME: this function needs a rename
  838. */
  839. static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
  840. {
  841. ide_startstop_t startstop;
  842. sector_t block;
  843. BUG_ON(!blk_rq_started(rq));
  844. #ifdef DEBUG
  845. printk("%s: start_request: current=0x%08lx\n",
  846. HWIF(drive)->name, (unsigned long) rq);
  847. #endif
  848. /* bail early if we've exceeded max_failures */
  849. if (drive->max_failures && (drive->failures > drive->max_failures)) {
  850. rq->cmd_flags |= REQ_FAILED;
  851. goto kill_rq;
  852. }
  853. block = rq->sector;
  854. if (blk_fs_request(rq) &&
  855. (drive->media == ide_disk || drive->media == ide_floppy)) {
  856. block += drive->sect0;
  857. }
  858. /* Yecch - this will shift the entire interval,
  859. possibly killing some innocent following sector */
  860. if (block == 0 && drive->remap_0_to_1 == 1)
  861. block = 1; /* redirect MBR access to EZ-Drive partn table */
  862. if (blk_pm_request(rq))
  863. ide_check_pm_state(drive, rq);
  864. SELECT_DRIVE(drive);
  865. if (ide_wait_stat(&startstop, drive, drive->ready_stat, BUSY_STAT|DRQ_STAT, WAIT_READY)) {
  866. printk(KERN_ERR "%s: drive not ready for command\n", drive->name);
  867. return startstop;
  868. }
  869. if (!drive->special.all) {
  870. ide_driver_t *drv;
  871. /*
  872. * We reset the drive so we need to issue a SETFEATURES.
  873. * Do it _after_ do_special() restored device parameters.
  874. */
  875. if (drive->current_speed == 0xff)
  876. ide_config_drive_speed(drive, drive->desired_speed);
  877. if (rq->cmd_type == REQ_TYPE_ATA_CMD ||
  878. rq->cmd_type == REQ_TYPE_ATA_TASK ||
  879. rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
  880. return execute_drive_cmd(drive, rq);
  881. else if (blk_pm_request(rq)) {
  882. struct request_pm_state *pm = rq->data;
  883. #ifdef DEBUG_PM
  884. printk("%s: start_power_step(step: %d)\n",
  885. drive->name, rq->pm->pm_step);
  886. #endif
  887. startstop = ide_start_power_step(drive, rq);
  888. if (startstop == ide_stopped &&
  889. pm->pm_step == ide_pm_state_completed)
  890. ide_complete_pm_request(drive, rq);
  891. return startstop;
  892. }
  893. drv = *(ide_driver_t **)rq->rq_disk->private_data;
  894. return drv->do_request(drive, rq, block);
  895. }
  896. return do_special(drive);
  897. kill_rq:
  898. ide_kill_rq(drive, rq);
  899. return ide_stopped;
  900. }
  901. /**
  902. * ide_stall_queue - pause an IDE device
  903. * @drive: drive to stall
  904. * @timeout: time to stall for (jiffies)
  905. *
  906. * ide_stall_queue() can be used by a drive to give excess bandwidth back
  907. * to the hwgroup by sleeping for timeout jiffies.
  908. */
  909. void ide_stall_queue (ide_drive_t *drive, unsigned long timeout)
  910. {
  911. if (timeout > WAIT_WORSTCASE)
  912. timeout = WAIT_WORSTCASE;
  913. drive->sleep = timeout + jiffies;
  914. drive->sleeping = 1;
  915. }
  916. EXPORT_SYMBOL(ide_stall_queue);
  917. #define WAKEUP(drive) ((drive)->service_start + 2 * (drive)->service_time)
  918. /**
  919. * choose_drive - select a drive to service
  920. * @hwgroup: hardware group to select on
  921. *
  922. * choose_drive() selects the next drive which will be serviced.
  923. * This is necessary because the IDE layer can't issue commands
  924. * to both drives on the same cable, unlike SCSI.
  925. */
  926. static inline ide_drive_t *choose_drive (ide_hwgroup_t *hwgroup)
  927. {
  928. ide_drive_t *drive, *best;
  929. repeat:
  930. best = NULL;
  931. drive = hwgroup->drive;
  932. /*
  933. * drive is doing pre-flush, ordered write, post-flush sequence. even
  934. * though that is 3 requests, it must be seen as a single transaction.
  935. * we must not preempt this drive until that is complete
  936. */
  937. if (blk_queue_flushing(drive->queue)) {
  938. /*
  939. * small race where queue could get replugged during
  940. * the 3-request flush cycle, just yank the plug since
  941. * we want it to finish asap
  942. */
  943. blk_remove_plug(drive->queue);
  944. return drive;
  945. }
  946. do {
  947. if ((!drive->sleeping || time_after_eq(jiffies, drive->sleep))
  948. && !elv_queue_empty(drive->queue)) {
  949. if (!best
  950. || (drive->sleeping && (!best->sleeping || time_before(drive->sleep, best->sleep)))
  951. || (!best->sleeping && time_before(WAKEUP(drive), WAKEUP(best))))
  952. {
  953. if (!blk_queue_plugged(drive->queue))
  954. best = drive;
  955. }
  956. }
  957. } while ((drive = drive->next) != hwgroup->drive);
  958. if (best && best->nice1 && !best->sleeping && best != hwgroup->drive && best->service_time > WAIT_MIN_SLEEP) {
  959. long t = (signed long)(WAKEUP(best) - jiffies);
  960. if (t >= WAIT_MIN_SLEEP) {
  961. /*
  962. * We *may* have some time to spare, but first let's see if
  963. * someone can potentially benefit from our nice mood today..
  964. */
  965. drive = best->next;
  966. do {
  967. if (!drive->sleeping
  968. && time_before(jiffies - best->service_time, WAKEUP(drive))
  969. && time_before(WAKEUP(drive), jiffies + t))
  970. {
  971. ide_stall_queue(best, min_t(long, t, 10 * WAIT_MIN_SLEEP));
  972. goto repeat;
  973. }
  974. } while ((drive = drive->next) != best);
  975. }
  976. }
  977. return best;
  978. }
  979. /*
  980. * Issue a new request to a drive from hwgroup
  981. * Caller must have already done spin_lock_irqsave(&ide_lock, ..);
  982. *
  983. * A hwgroup is a serialized group of IDE interfaces. Usually there is
  984. * exactly one hwif (interface) per hwgroup, but buggy controllers (eg. CMD640)
  985. * may have both interfaces in a single hwgroup to "serialize" access.
  986. * Or possibly multiple ISA interfaces can share a common IRQ by being grouped
  987. * together into one hwgroup for serialized access.
  988. *
  989. * Note also that several hwgroups can end up sharing a single IRQ,
  990. * possibly along with many other devices. This is especially common in
  991. * PCI-based systems with off-board IDE controller cards.
  992. *
  993. * The IDE driver uses the single global ide_lock spinlock to protect
  994. * access to the request queues, and to protect the hwgroup->busy flag.
  995. *
  996. * The first thread into the driver for a particular hwgroup sets the
  997. * hwgroup->busy flag to indicate that this hwgroup is now active,
  998. * and then initiates processing of the top request from the request queue.
  999. *
  1000. * Other threads attempting entry notice the busy setting, and will simply
  1001. * queue their new requests and exit immediately. Note that hwgroup->busy
  1002. * remains set even when the driver is merely awaiting the next interrupt.
  1003. * Thus, the meaning is "this hwgroup is busy processing a request".
  1004. *
  1005. * When processing of a request completes, the completing thread or IRQ-handler
  1006. * will start the next request from the queue. If no more work remains,
  1007. * the driver will clear the hwgroup->busy flag and exit.
  1008. *
  1009. * The ide_lock (spinlock) is used to protect all access to the
  1010. * hwgroup->busy flag, but is otherwise not needed for most processing in
  1011. * the driver. This makes the driver much more friendlier to shared IRQs
  1012. * than previous designs, while remaining 100% (?) SMP safe and capable.
  1013. */
  1014. static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
  1015. {
  1016. ide_drive_t *drive;
  1017. ide_hwif_t *hwif;
  1018. struct request *rq;
  1019. ide_startstop_t startstop;
  1020. int loops = 0;
  1021. /* for atari only: POSSIBLY BROKEN HERE(?) */
  1022. ide_get_lock(ide_intr, hwgroup);
  1023. /* caller must own ide_lock */
  1024. BUG_ON(!irqs_disabled());
  1025. while (!hwgroup->busy) {
  1026. hwgroup->busy = 1;
  1027. drive = choose_drive(hwgroup);
  1028. if (drive == NULL) {
  1029. int sleeping = 0;
  1030. unsigned long sleep = 0; /* shut up, gcc */
  1031. hwgroup->rq = NULL;
  1032. drive = hwgroup->drive;
  1033. do {
  1034. if (drive->sleeping && (!sleeping || time_before(drive->sleep, sleep))) {
  1035. sleeping = 1;
  1036. sleep = drive->sleep;
  1037. }
  1038. } while ((drive = drive->next) != hwgroup->drive);
  1039. if (sleeping) {
  1040. /*
  1041. * Take a short snooze, and then wake up this hwgroup again.
  1042. * This gives other hwgroups on the same a chance to
  1043. * play fairly with us, just in case there are big differences
  1044. * in relative throughputs.. don't want to hog the cpu too much.
  1045. */
  1046. if (time_before(sleep, jiffies + WAIT_MIN_SLEEP))
  1047. sleep = jiffies + WAIT_MIN_SLEEP;
  1048. #if 1
  1049. if (timer_pending(&hwgroup->timer))
  1050. printk(KERN_CRIT "ide_set_handler: timer already active\n");
  1051. #endif
  1052. /* so that ide_timer_expiry knows what to do */
  1053. hwgroup->sleeping = 1;
  1054. hwgroup->req_gen_timer = hwgroup->req_gen;
  1055. mod_timer(&hwgroup->timer, sleep);
  1056. /* we purposely leave hwgroup->busy==1
  1057. * while sleeping */
  1058. } else {
  1059. /* Ugly, but how can we sleep for the lock
  1060. * otherwise? perhaps from tq_disk?
  1061. */
  1062. /* for atari only */
  1063. ide_release_lock();
  1064. hwgroup->busy = 0;
  1065. }
  1066. /* no more work for this hwgroup (for now) */
  1067. return;
  1068. }
  1069. again:
  1070. hwif = HWIF(drive);
  1071. if (hwgroup->hwif->sharing_irq &&
  1072. hwif != hwgroup->hwif &&
  1073. hwif->io_ports[IDE_CONTROL_OFFSET]) {
  1074. /* set nIEN for previous hwif */
  1075. SELECT_INTERRUPT(drive);
  1076. }
  1077. hwgroup->hwif = hwif;
  1078. hwgroup->drive = drive;
  1079. drive->sleeping = 0;
  1080. drive->service_start = jiffies;
  1081. if (blk_queue_plugged(drive->queue)) {
  1082. printk(KERN_ERR "ide: huh? queue was plugged!\n");
  1083. break;
  1084. }
  1085. /*
  1086. * we know that the queue isn't empty, but this can happen
  1087. * if the q->prep_rq_fn() decides to kill a request
  1088. */
  1089. rq = elv_next_request(drive->queue);
  1090. if (!rq) {
  1091. hwgroup->busy = 0;
  1092. break;
  1093. }
  1094. /*
  1095. * Sanity: don't accept a request that isn't a PM request
  1096. * if we are currently power managed. This is very important as
  1097. * blk_stop_queue() doesn't prevent the elv_next_request()
  1098. * above to return us whatever is in the queue. Since we call
  1099. * ide_do_request() ourselves, we end up taking requests while
  1100. * the queue is blocked...
  1101. *
  1102. * We let requests forced at head of queue with ide-preempt
  1103. * though. I hope that doesn't happen too much, hopefully not
  1104. * unless the subdriver triggers such a thing in its own PM
  1105. * state machine.
  1106. *
  1107. * We count how many times we loop here to make sure we service
  1108. * all drives in the hwgroup without looping for ever
  1109. */
  1110. if (drive->blocked && !blk_pm_request(rq) && !(rq->cmd_flags & REQ_PREEMPT)) {
  1111. drive = drive->next ? drive->next : hwgroup->drive;
  1112. if (loops++ < 4 && !blk_queue_plugged(drive->queue))
  1113. goto again;
  1114. /* We clear busy, there should be no pending ATA command at this point. */
  1115. hwgroup->busy = 0;
  1116. break;
  1117. }
  1118. hwgroup->rq = rq;
  1119. /*
  1120. * Some systems have trouble with IDE IRQs arriving while
  1121. * the driver is still setting things up. So, here we disable
  1122. * the IRQ used by this interface while the request is being started.
  1123. * This may look bad at first, but pretty much the same thing
  1124. * happens anyway when any interrupt comes in, IDE or otherwise
  1125. * -- the kernel masks the IRQ while it is being handled.
  1126. */
  1127. if (masked_irq != IDE_NO_IRQ && hwif->irq != masked_irq)
  1128. disable_irq_nosync(hwif->irq);
  1129. spin_unlock(&ide_lock);
  1130. local_irq_enable_in_hardirq();
  1131. /* allow other IRQs while we start this request */
  1132. startstop = start_request(drive, rq);
  1133. spin_lock_irq(&ide_lock);
  1134. if (masked_irq != IDE_NO_IRQ && hwif->irq != masked_irq)
  1135. enable_irq(hwif->irq);
  1136. if (startstop == ide_stopped)
  1137. hwgroup->busy = 0;
  1138. }
  1139. }
  1140. /*
  1141. * Passes the stuff to ide_do_request
  1142. */
  1143. void do_ide_request(struct request_queue *q)
  1144. {
  1145. ide_drive_t *drive = q->queuedata;
  1146. ide_do_request(HWGROUP(drive), IDE_NO_IRQ);
  1147. }
  1148. /*
  1149. * un-busy the hwgroup etc, and clear any pending DMA status. we want to
  1150. * retry the current request in pio mode instead of risking tossing it
  1151. * all away
  1152. */
  1153. static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
  1154. {
  1155. ide_hwif_t *hwif = HWIF(drive);
  1156. struct request *rq;
  1157. ide_startstop_t ret = ide_stopped;
  1158. /*
  1159. * end current dma transaction
  1160. */
  1161. if (error < 0) {
  1162. printk(KERN_WARNING "%s: DMA timeout error\n", drive->name);
  1163. (void)HWIF(drive)->ide_dma_end(drive);
  1164. ret = ide_error(drive, "dma timeout error",
  1165. hwif->INB(IDE_STATUS_REG));
  1166. } else {
  1167. printk(KERN_WARNING "%s: DMA timeout retry\n", drive->name);
  1168. hwif->dma_timeout(drive);
  1169. }
  1170. /*
  1171. * disable dma for now, but remember that we did so because of
  1172. * a timeout -- we'll reenable after we finish this next request
  1173. * (or rather the first chunk of it) in pio.
  1174. */
  1175. drive->retry_pio++;
  1176. drive->state = DMA_PIO_RETRY;
  1177. hwif->dma_off_quietly(drive);
  1178. /*
  1179. * un-busy drive etc (hwgroup->busy is cleared on return) and
  1180. * make sure request is sane
  1181. */
  1182. rq = HWGROUP(drive)->rq;
  1183. if (!rq)
  1184. goto out;
  1185. HWGROUP(drive)->rq = NULL;
  1186. rq->errors = 0;
  1187. if (!rq->bio)
  1188. goto out;
  1189. rq->sector = rq->bio->bi_sector;
  1190. rq->current_nr_sectors = bio_iovec(rq->bio)->bv_len >> 9;
  1191. rq->hard_cur_sectors = rq->current_nr_sectors;
  1192. rq->buffer = bio_data(rq->bio);
  1193. out:
  1194. return ret;
  1195. }
  1196. /**
  1197. * ide_timer_expiry - handle lack of an IDE interrupt
  1198. * @data: timer callback magic (hwgroup)
  1199. *
  1200. * An IDE command has timed out before the expected drive return
  1201. * occurred. At this point we attempt to clean up the current
  1202. * mess. If the current handler includes an expiry handler then
  1203. * we invoke the expiry handler, and providing it is happy the
  1204. * work is done. If that fails we apply generic recovery rules
  1205. * invoking the handler and checking the drive DMA status. We
  1206. * have an excessively incestuous relationship with the DMA
  1207. * logic that wants cleaning up.
  1208. */
  1209. void ide_timer_expiry (unsigned long data)
  1210. {
  1211. ide_hwgroup_t *hwgroup = (ide_hwgroup_t *) data;
  1212. ide_handler_t *handler;
  1213. ide_expiry_t *expiry;
  1214. unsigned long flags;
  1215. unsigned long wait = -1;
  1216. spin_lock_irqsave(&ide_lock, flags);
  1217. if (((handler = hwgroup->handler) == NULL) ||
  1218. (hwgroup->req_gen != hwgroup->req_gen_timer)) {
  1219. /*
  1220. * Either a marginal timeout occurred
  1221. * (got the interrupt just as timer expired),
  1222. * or we were "sleeping" to give other devices a chance.
  1223. * Either way, we don't really want to complain about anything.
  1224. */
  1225. if (hwgroup->sleeping) {
  1226. hwgroup->sleeping = 0;
  1227. hwgroup->busy = 0;
  1228. }
  1229. } else {
  1230. ide_drive_t *drive = hwgroup->drive;
  1231. if (!drive) {
  1232. printk(KERN_ERR "ide_timer_expiry: hwgroup->drive was NULL\n");
  1233. hwgroup->handler = NULL;
  1234. } else {
  1235. ide_hwif_t *hwif;
  1236. ide_startstop_t startstop = ide_stopped;
  1237. if (!hwgroup->busy) {
  1238. hwgroup->busy = 1; /* paranoia */
  1239. printk(KERN_ERR "%s: ide_timer_expiry: hwgroup->busy was 0 ??\n", drive->name);
  1240. }
  1241. if ((expiry = hwgroup->expiry) != NULL) {
  1242. /* continue */
  1243. if ((wait = expiry(drive)) > 0) {
  1244. /* reset timer */
  1245. hwgroup->timer.expires = jiffies + wait;
  1246. hwgroup->req_gen_timer = hwgroup->req_gen;
  1247. add_timer(&hwgroup->timer);
  1248. spin_unlock_irqrestore(&ide_lock, flags);
  1249. return;
  1250. }
  1251. }
  1252. hwgroup->handler = NULL;
  1253. /*
  1254. * We need to simulate a real interrupt when invoking
  1255. * the handler() function, which means we need to
  1256. * globally mask the specific IRQ:
  1257. */
  1258. spin_unlock(&ide_lock);
  1259. hwif = HWIF(drive);
  1260. /* disable_irq_nosync ?? */
  1261. disable_irq(hwif->irq);
  1262. /* local CPU only,
  1263. * as if we were handling an interrupt */
  1264. local_irq_disable();
  1265. if (hwgroup->polling) {
  1266. startstop = handler(drive);
  1267. } else if (drive_is_ready(drive)) {
  1268. if (drive->waiting_for_dma)
  1269. hwgroup->hwif->dma_lost_irq(drive);
  1270. (void)ide_ack_intr(hwif);
  1271. printk(KERN_WARNING "%s: lost interrupt\n", drive->name);
  1272. startstop = handler(drive);
  1273. } else {
  1274. if (drive->waiting_for_dma) {
  1275. startstop = ide_dma_timeout_retry(drive, wait);
  1276. } else
  1277. startstop =
  1278. ide_error(drive, "irq timeout", hwif->INB(IDE_STATUS_REG));
  1279. }
  1280. drive->service_time = jiffies - drive->service_start;
  1281. spin_lock_irq(&ide_lock);
  1282. enable_irq(hwif->irq);
  1283. if (startstop == ide_stopped)
  1284. hwgroup->busy = 0;
  1285. }
  1286. }
  1287. ide_do_request(hwgroup, IDE_NO_IRQ);
  1288. spin_unlock_irqrestore(&ide_lock, flags);
  1289. }
  1290. /**
  1291. * unexpected_intr - handle an unexpected IDE interrupt
  1292. * @irq: interrupt line
  1293. * @hwgroup: hwgroup being processed
  1294. *
  1295. * There's nothing really useful we can do with an unexpected interrupt,
  1296. * other than reading the status register (to clear it), and logging it.
  1297. * There should be no way that an irq can happen before we're ready for it,
  1298. * so we needn't worry much about losing an "important" interrupt here.
  1299. *
  1300. * On laptops (and "green" PCs), an unexpected interrupt occurs whenever
  1301. * the drive enters "idle", "standby", or "sleep" mode, so if the status
  1302. * looks "good", we just ignore the interrupt completely.
  1303. *
  1304. * This routine assumes __cli() is in effect when called.
  1305. *
  1306. * If an unexpected interrupt happens on irq15 while we are handling irq14
  1307. * and if the two interfaces are "serialized" (CMD640), then it looks like
  1308. * we could screw up by interfering with a new request being set up for
  1309. * irq15.
  1310. *
  1311. * In reality, this is a non-issue. The new command is not sent unless
  1312. * the drive is ready to accept one, in which case we know the drive is
  1313. * not trying to interrupt us. And ide_set_handler() is always invoked
  1314. * before completing the issuance of any new drive command, so we will not
  1315. * be accidentally invoked as a result of any valid command completion
  1316. * interrupt.
  1317. *
  1318. * Note that we must walk the entire hwgroup here. We know which hwif
  1319. * is doing the current command, but we don't know which hwif burped
  1320. * mysteriously.
  1321. */
  1322. static void unexpected_intr (int irq, ide_hwgroup_t *hwgroup)
  1323. {
  1324. u8 stat;
  1325. ide_hwif_t *hwif = hwgroup->hwif;
  1326. /*
  1327. * handle the unexpected interrupt
  1328. */
  1329. do {
  1330. if (hwif->irq == irq) {
  1331. stat = hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]);
  1332. if (!OK_STAT(stat, READY_STAT, BAD_STAT)) {
  1333. /* Try to not flood the console with msgs */
  1334. static unsigned long last_msgtime, count;
  1335. ++count;
  1336. if (time_after(jiffies, last_msgtime + HZ)) {
  1337. last_msgtime = jiffies;
  1338. printk(KERN_ERR "%s%s: unexpected interrupt, "
  1339. "status=0x%02x, count=%ld\n",
  1340. hwif->name,
  1341. (hwif->next==hwgroup->hwif) ? "" : "(?)", stat, count);
  1342. }
  1343. }
  1344. }
  1345. } while ((hwif = hwif->next) != hwgroup->hwif);
  1346. }
  1347. /**
  1348. * ide_intr - default IDE interrupt handler
  1349. * @irq: interrupt number
  1350. * @dev_id: hwif group
  1351. * @regs: unused weirdness from the kernel irq layer
  1352. *
  1353. * This is the default IRQ handler for the IDE layer. You should
  1354. * not need to override it. If you do be aware it is subtle in
  1355. * places
  1356. *
  1357. * hwgroup->hwif is the interface in the group currently performing
  1358. * a command. hwgroup->drive is the drive and hwgroup->handler is
  1359. * the IRQ handler to call. As we issue a command the handlers
  1360. * step through multiple states, reassigning the handler to the
  1361. * next step in the process. Unlike a smart SCSI controller IDE
  1362. * expects the main processor to sequence the various transfer
  1363. * stages. We also manage a poll timer to catch up with most
  1364. * timeout situations. There are still a few where the handlers
  1365. * don't ever decide to give up.
  1366. *
  1367. * The handler eventually returns ide_stopped to indicate the
  1368. * request completed. At this point we issue the next request
  1369. * on the hwgroup and the process begins again.
  1370. */
  1371. irqreturn_t ide_intr (int irq, void *dev_id)
  1372. {
  1373. unsigned long flags;
  1374. ide_hwgroup_t *hwgroup = (ide_hwgroup_t *)dev_id;
  1375. ide_hwif_t *hwif;
  1376. ide_drive_t *drive;
  1377. ide_handler_t *handler;
  1378. ide_startstop_t startstop;
  1379. spin_lock_irqsave(&ide_lock, flags);
  1380. hwif = hwgroup->hwif;
  1381. if (!ide_ack_intr(hwif)) {
  1382. spin_unlock_irqrestore(&ide_lock, flags);
  1383. return IRQ_NONE;
  1384. }
  1385. if ((handler = hwgroup->handler) == NULL || hwgroup->polling) {
  1386. /*
  1387. * Not expecting an interrupt from this drive.
  1388. * That means this could be:
  1389. * (1) an interrupt from another PCI device
  1390. * sharing the same PCI INT# as us.
  1391. * or (2) a drive just entered sleep or standby mode,
  1392. * and is interrupting to let us know.
  1393. * or (3) a spurious interrupt of unknown origin.
  1394. *
  1395. * For PCI, we cannot tell the difference,
  1396. * so in that case we just ignore it and hope it goes away.
  1397. *
  1398. * FIXME: unexpected_intr should be hwif-> then we can
  1399. * remove all the ifdef PCI crap
  1400. */
  1401. #ifdef CONFIG_BLK_DEV_IDEPCI
  1402. if (hwif->pci_dev && !hwif->pci_dev->vendor)
  1403. #endif /* CONFIG_BLK_DEV_IDEPCI */
  1404. {
  1405. /*
  1406. * Probably not a shared PCI interrupt,
  1407. * so we can safely try to do something about it:
  1408. */
  1409. unexpected_intr(irq, hwgroup);
  1410. #ifdef CONFIG_BLK_DEV_IDEPCI
  1411. } else {
  1412. /*
  1413. * Whack the status register, just in case
  1414. * we have a leftover pending IRQ.
  1415. */
  1416. (void) hwif->INB(hwif->io_ports[IDE_STATUS_OFFSET]);
  1417. #endif /* CONFIG_BLK_DEV_IDEPCI */
  1418. }
  1419. spin_unlock_irqrestore(&ide_lock, flags);
  1420. return IRQ_NONE;
  1421. }
  1422. drive = hwgroup->drive;
  1423. if (!drive) {
  1424. /*
  1425. * This should NEVER happen, and there isn't much
  1426. * we could do about it here.
  1427. *
  1428. * [Note - this can occur if the drive is hot unplugged]
  1429. */
  1430. spin_unlock_irqrestore(&ide_lock, flags);
  1431. return IRQ_HANDLED;
  1432. }
  1433. if (!drive_is_ready(drive)) {
  1434. /*
  1435. * This happens regularly when we share a PCI IRQ with
  1436. * another device. Unfortunately, it can also happen
  1437. * with some buggy drives that trigger the IRQ before
  1438. * their status register is up to date. Hopefully we have
  1439. * enough advance overhead that the latter isn't a problem.
  1440. */
  1441. spin_unlock_irqrestore(&ide_lock, flags);
  1442. return IRQ_NONE;
  1443. }
  1444. if (!hwgroup->busy) {
  1445. hwgroup->busy = 1; /* paranoia */
  1446. printk(KERN_ERR "%s: ide_intr: hwgroup->busy was 0 ??\n", drive->name);
  1447. }
  1448. hwgroup->handler = NULL;
  1449. hwgroup->req_gen++;
  1450. del_timer(&hwgroup->timer);
  1451. spin_unlock(&ide_lock);
  1452. /* Some controllers might set DMA INTR no matter DMA or PIO;
  1453. * bmdma status might need to be cleared even for
  1454. * PIO interrupts to prevent spurious/lost irq.
  1455. */
  1456. if (hwif->ide_dma_clear_irq && !(drive->waiting_for_dma))
  1457. /* ide_dma_end() needs bmdma status for error checking.
  1458. * So, skip clearing bmdma status here and leave it
  1459. * to ide_dma_end() if this is dma interrupt.
  1460. */
  1461. hwif->ide_dma_clear_irq(drive);
  1462. if (drive->unmask)
  1463. local_irq_enable_in_hardirq();
  1464. /* service this interrupt, may set handler for next interrupt */
  1465. startstop = handler(drive);
  1466. spin_lock_irq(&ide_lock);
  1467. /*
  1468. * Note that handler() may have set things up for another
  1469. * interrupt to occur soon, but it cannot happen until
  1470. * we exit from this routine, because it will be the
  1471. * same irq as is currently being serviced here, and Linux
  1472. * won't allow another of the same (on any CPU) until we return.
  1473. */
  1474. drive->service_time = jiffies - drive->service_start;
  1475. if (startstop == ide_stopped) {
  1476. if (hwgroup->handler == NULL) { /* paranoia */
  1477. hwgroup->busy = 0;
  1478. ide_do_request(hwgroup, hwif->irq);
  1479. } else {
  1480. printk(KERN_ERR "%s: ide_intr: huh? expected NULL handler "
  1481. "on exit\n", drive->name);
  1482. }
  1483. }
  1484. spin_unlock_irqrestore(&ide_lock, flags);
  1485. return IRQ_HANDLED;
  1486. }
  1487. /**
  1488. * ide_init_drive_cmd - initialize a drive command request
  1489. * @rq: request object
  1490. *
  1491. * Initialize a request before we fill it in and send it down to
  1492. * ide_do_drive_cmd. Commands must be set up by this function. Right
  1493. * now it doesn't do a lot, but if that changes abusers will have a
  1494. * nasty surprise.
  1495. */
  1496. void ide_init_drive_cmd (struct request *rq)
  1497. {
  1498. memset(rq, 0, sizeof(*rq));
  1499. rq->cmd_type = REQ_TYPE_ATA_CMD;
  1500. rq->ref_count = 1;
  1501. }
  1502. EXPORT_SYMBOL(ide_init_drive_cmd);
  1503. /**
  1504. * ide_do_drive_cmd - issue IDE special command
  1505. * @drive: device to issue command
  1506. * @rq: request to issue
  1507. * @action: action for processing
  1508. *
  1509. * This function issues a special IDE device request
  1510. * onto the request queue.
  1511. *
  1512. * If action is ide_wait, then the rq is queued at the end of the
  1513. * request queue, and the function sleeps until it has been processed.
  1514. * This is for use when invoked from an ioctl handler.
  1515. *
  1516. * If action is ide_preempt, then the rq is queued at the head of
  1517. * the request queue, displacing the currently-being-processed
  1518. * request and this function returns immediately without waiting
  1519. * for the new rq to be completed. This is VERY DANGEROUS, and is
  1520. * intended for careful use by the ATAPI tape/cdrom driver code.
  1521. *
  1522. * If action is ide_end, then the rq is queued at the end of the
  1523. * request queue, and the function returns immediately without waiting
  1524. * for the new rq to be completed. This is again intended for careful
  1525. * use by the ATAPI tape/cdrom driver code.
  1526. */
  1527. int ide_do_drive_cmd (ide_drive_t *drive, struct request *rq, ide_action_t action)
  1528. {
  1529. unsigned long flags;
  1530. ide_hwgroup_t *hwgroup = HWGROUP(drive);
  1531. DECLARE_COMPLETION_ONSTACK(wait);
  1532. int where = ELEVATOR_INSERT_BACK, err;
  1533. int must_wait = (action == ide_wait || action == ide_head_wait);
  1534. rq->errors = 0;
  1535. /*
  1536. * we need to hold an extra reference to request for safe inspection
  1537. * after completion
  1538. */
  1539. if (must_wait) {
  1540. rq->ref_count++;
  1541. rq->end_io_data = &wait;
  1542. rq->end_io = blk_end_sync_rq;
  1543. }
  1544. spin_lock_irqsave(&ide_lock, flags);
  1545. if (action == ide_preempt)
  1546. hwgroup->rq = NULL;
  1547. if (action == ide_preempt || action == ide_head_wait) {
  1548. where = ELEVATOR_INSERT_FRONT;
  1549. rq->cmd_flags |= REQ_PREEMPT;
  1550. }
  1551. __elv_add_request(drive->queue, rq, where, 0);
  1552. ide_do_request(hwgroup, IDE_NO_IRQ);
  1553. spin_unlock_irqrestore(&ide_lock, flags);
  1554. err = 0;
  1555. if (must_wait) {
  1556. wait_for_completion(&wait);
  1557. if (rq->errors)
  1558. err = -EIO;
  1559. blk_put_request(rq);
  1560. }
  1561. return err;
  1562. }
  1563. EXPORT_SYMBOL(ide_do_drive_cmd);