ide-iops.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. /*
  2. * Copyright (C) 2000-2002 Andre Hedrick <andre@linux-ide.org>
  3. * Copyright (C) 2003 Red Hat
  4. *
  5. */
  6. #include <linux/module.h>
  7. #include <linux/types.h>
  8. #include <linux/string.h>
  9. #include <linux/kernel.h>
  10. #include <linux/timer.h>
  11. #include <linux/mm.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/major.h>
  14. #include <linux/errno.h>
  15. #include <linux/genhd.h>
  16. #include <linux/blkpg.h>
  17. #include <linux/slab.h>
  18. #include <linux/pci.h>
  19. #include <linux/delay.h>
  20. #include <linux/ide.h>
  21. #include <linux/bitops.h>
  22. #include <linux/nmi.h>
  23. #include <asm/byteorder.h>
  24. #include <asm/irq.h>
  25. #include <asm/uaccess.h>
  26. #include <asm/io.h>
  27. /*
  28. * Conventional PIO operations for ATA devices
  29. */
  30. static u8 ide_inb (unsigned long port)
  31. {
  32. return (u8) inb(port);
  33. }
  34. static void ide_outb (u8 val, unsigned long port)
  35. {
  36. outb(val, port);
  37. }
  38. /*
  39. * MMIO operations, typically used for SATA controllers
  40. */
  41. static u8 ide_mm_inb (unsigned long port)
  42. {
  43. return (u8) readb((void __iomem *) port);
  44. }
  45. static void ide_mm_outb (u8 value, unsigned long port)
  46. {
  47. writeb(value, (void __iomem *) port);
  48. }
  49. void SELECT_DRIVE (ide_drive_t *drive)
  50. {
  51. ide_hwif_t *hwif = drive->hwif;
  52. const struct ide_port_ops *port_ops = hwif->port_ops;
  53. ide_task_t task;
  54. if (port_ops && port_ops->selectproc)
  55. port_ops->selectproc(drive);
  56. memset(&task, 0, sizeof(task));
  57. task.tf_flags = IDE_TFLAG_OUT_DEVICE;
  58. drive->hwif->tp_ops->tf_load(drive, &task);
  59. }
  60. void SELECT_MASK(ide_drive_t *drive, int mask)
  61. {
  62. const struct ide_port_ops *port_ops = drive->hwif->port_ops;
  63. if (port_ops && port_ops->maskproc)
  64. port_ops->maskproc(drive, mask);
  65. }
  66. void ide_exec_command(ide_hwif_t *hwif, u8 cmd)
  67. {
  68. if (hwif->host_flags & IDE_HFLAG_MMIO)
  69. writeb(cmd, (void __iomem *)hwif->io_ports.command_addr);
  70. else
  71. outb(cmd, hwif->io_ports.command_addr);
  72. }
  73. EXPORT_SYMBOL_GPL(ide_exec_command);
  74. u8 ide_read_status(ide_hwif_t *hwif)
  75. {
  76. if (hwif->host_flags & IDE_HFLAG_MMIO)
  77. return readb((void __iomem *)hwif->io_ports.status_addr);
  78. else
  79. return inb(hwif->io_ports.status_addr);
  80. }
  81. EXPORT_SYMBOL_GPL(ide_read_status);
  82. u8 ide_read_altstatus(ide_hwif_t *hwif)
  83. {
  84. if (hwif->host_flags & IDE_HFLAG_MMIO)
  85. return readb((void __iomem *)hwif->io_ports.ctl_addr);
  86. else
  87. return inb(hwif->io_ports.ctl_addr);
  88. }
  89. EXPORT_SYMBOL_GPL(ide_read_altstatus);
  90. void ide_set_irq(ide_hwif_t *hwif, int on)
  91. {
  92. u8 ctl = ATA_DEVCTL_OBS;
  93. if (on == 4) { /* hack for SRST */
  94. ctl |= 4;
  95. on &= ~4;
  96. }
  97. ctl |= on ? 0 : 2;
  98. if (hwif->host_flags & IDE_HFLAG_MMIO)
  99. writeb(ctl, (void __iomem *)hwif->io_ports.ctl_addr);
  100. else
  101. outb(ctl, hwif->io_ports.ctl_addr);
  102. }
  103. EXPORT_SYMBOL_GPL(ide_set_irq);
  104. void ide_tf_load(ide_drive_t *drive, ide_task_t *task)
  105. {
  106. ide_hwif_t *hwif = drive->hwif;
  107. struct ide_io_ports *io_ports = &hwif->io_ports;
  108. struct ide_taskfile *tf = &task->tf;
  109. void (*tf_outb)(u8 addr, unsigned long port);
  110. u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
  111. u8 HIHI = (task->tf_flags & IDE_TFLAG_LBA48) ? 0xE0 : 0xEF;
  112. if (mmio)
  113. tf_outb = ide_mm_outb;
  114. else
  115. tf_outb = ide_outb;
  116. if (task->tf_flags & IDE_TFLAG_FLAGGED)
  117. HIHI = 0xFF;
  118. if (task->tf_flags & IDE_TFLAG_OUT_DATA) {
  119. u16 data = (tf->hob_data << 8) | tf->data;
  120. if (mmio)
  121. writew(data, (void __iomem *)io_ports->data_addr);
  122. else
  123. outw(data, io_ports->data_addr);
  124. }
  125. if (task->tf_flags & IDE_TFLAG_OUT_HOB_FEATURE)
  126. tf_outb(tf->hob_feature, io_ports->feature_addr);
  127. if (task->tf_flags & IDE_TFLAG_OUT_HOB_NSECT)
  128. tf_outb(tf->hob_nsect, io_ports->nsect_addr);
  129. if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAL)
  130. tf_outb(tf->hob_lbal, io_ports->lbal_addr);
  131. if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAM)
  132. tf_outb(tf->hob_lbam, io_ports->lbam_addr);
  133. if (task->tf_flags & IDE_TFLAG_OUT_HOB_LBAH)
  134. tf_outb(tf->hob_lbah, io_ports->lbah_addr);
  135. if (task->tf_flags & IDE_TFLAG_OUT_FEATURE)
  136. tf_outb(tf->feature, io_ports->feature_addr);
  137. if (task->tf_flags & IDE_TFLAG_OUT_NSECT)
  138. tf_outb(tf->nsect, io_ports->nsect_addr);
  139. if (task->tf_flags & IDE_TFLAG_OUT_LBAL)
  140. tf_outb(tf->lbal, io_ports->lbal_addr);
  141. if (task->tf_flags & IDE_TFLAG_OUT_LBAM)
  142. tf_outb(tf->lbam, io_ports->lbam_addr);
  143. if (task->tf_flags & IDE_TFLAG_OUT_LBAH)
  144. tf_outb(tf->lbah, io_ports->lbah_addr);
  145. if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
  146. tf_outb((tf->device & HIHI) | drive->select,
  147. io_ports->device_addr);
  148. }
  149. EXPORT_SYMBOL_GPL(ide_tf_load);
  150. void ide_tf_read(ide_drive_t *drive, ide_task_t *task)
  151. {
  152. ide_hwif_t *hwif = drive->hwif;
  153. struct ide_io_ports *io_ports = &hwif->io_ports;
  154. struct ide_taskfile *tf = &task->tf;
  155. void (*tf_outb)(u8 addr, unsigned long port);
  156. u8 (*tf_inb)(unsigned long port);
  157. u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
  158. if (mmio) {
  159. tf_outb = ide_mm_outb;
  160. tf_inb = ide_mm_inb;
  161. } else {
  162. tf_outb = ide_outb;
  163. tf_inb = ide_inb;
  164. }
  165. if (task->tf_flags & IDE_TFLAG_IN_DATA) {
  166. u16 data;
  167. if (mmio)
  168. data = readw((void __iomem *)io_ports->data_addr);
  169. else
  170. data = inw(io_ports->data_addr);
  171. tf->data = data & 0xff;
  172. tf->hob_data = (data >> 8) & 0xff;
  173. }
  174. /* be sure we're looking at the low order bits */
  175. tf_outb(ATA_DEVCTL_OBS & ~0x80, io_ports->ctl_addr);
  176. if (task->tf_flags & IDE_TFLAG_IN_FEATURE)
  177. tf->feature = tf_inb(io_ports->feature_addr);
  178. if (task->tf_flags & IDE_TFLAG_IN_NSECT)
  179. tf->nsect = tf_inb(io_ports->nsect_addr);
  180. if (task->tf_flags & IDE_TFLAG_IN_LBAL)
  181. tf->lbal = tf_inb(io_ports->lbal_addr);
  182. if (task->tf_flags & IDE_TFLAG_IN_LBAM)
  183. tf->lbam = tf_inb(io_ports->lbam_addr);
  184. if (task->tf_flags & IDE_TFLAG_IN_LBAH)
  185. tf->lbah = tf_inb(io_ports->lbah_addr);
  186. if (task->tf_flags & IDE_TFLAG_IN_DEVICE)
  187. tf->device = tf_inb(io_ports->device_addr);
  188. if (task->tf_flags & IDE_TFLAG_LBA48) {
  189. tf_outb(ATA_DEVCTL_OBS | 0x80, io_ports->ctl_addr);
  190. if (task->tf_flags & IDE_TFLAG_IN_HOB_FEATURE)
  191. tf->hob_feature = tf_inb(io_ports->feature_addr);
  192. if (task->tf_flags & IDE_TFLAG_IN_HOB_NSECT)
  193. tf->hob_nsect = tf_inb(io_ports->nsect_addr);
  194. if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAL)
  195. tf->hob_lbal = tf_inb(io_ports->lbal_addr);
  196. if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAM)
  197. tf->hob_lbam = tf_inb(io_ports->lbam_addr);
  198. if (task->tf_flags & IDE_TFLAG_IN_HOB_LBAH)
  199. tf->hob_lbah = tf_inb(io_ports->lbah_addr);
  200. }
  201. }
  202. EXPORT_SYMBOL_GPL(ide_tf_read);
  203. /*
  204. * Some localbus EIDE interfaces require a special access sequence
  205. * when using 32-bit I/O instructions to transfer data. We call this
  206. * the "vlb_sync" sequence, which consists of three successive reads
  207. * of the sector count register location, with interrupts disabled
  208. * to ensure that the reads all happen together.
  209. */
  210. static void ata_vlb_sync(unsigned long port)
  211. {
  212. (void)inb(port);
  213. (void)inb(port);
  214. (void)inb(port);
  215. }
  216. /*
  217. * This is used for most PIO data transfers *from* the IDE interface
  218. *
  219. * These routines will round up any request for an odd number of bytes,
  220. * so if an odd len is specified, be sure that there's at least one
  221. * extra byte allocated for the buffer.
  222. */
  223. void ide_input_data(ide_drive_t *drive, struct request *rq, void *buf,
  224. unsigned int len)
  225. {
  226. ide_hwif_t *hwif = drive->hwif;
  227. struct ide_io_ports *io_ports = &hwif->io_ports;
  228. unsigned long data_addr = io_ports->data_addr;
  229. u8 io_32bit = drive->io_32bit;
  230. u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
  231. len++;
  232. if (io_32bit) {
  233. unsigned long uninitialized_var(flags);
  234. if ((io_32bit & 2) && !mmio) {
  235. local_irq_save(flags);
  236. ata_vlb_sync(io_ports->nsect_addr);
  237. }
  238. if (mmio)
  239. __ide_mm_insl((void __iomem *)data_addr, buf, len / 4);
  240. else
  241. insl(data_addr, buf, len / 4);
  242. if ((io_32bit & 2) && !mmio)
  243. local_irq_restore(flags);
  244. if ((len & 3) >= 2) {
  245. if (mmio)
  246. __ide_mm_insw((void __iomem *)data_addr,
  247. (u8 *)buf + (len & ~3), 1);
  248. else
  249. insw(data_addr, (u8 *)buf + (len & ~3), 1);
  250. }
  251. } else {
  252. if (mmio)
  253. __ide_mm_insw((void __iomem *)data_addr, buf, len / 2);
  254. else
  255. insw(data_addr, buf, len / 2);
  256. }
  257. }
  258. EXPORT_SYMBOL_GPL(ide_input_data);
  259. /*
  260. * This is used for most PIO data transfers *to* the IDE interface
  261. */
  262. void ide_output_data(ide_drive_t *drive, struct request *rq, void *buf,
  263. unsigned int len)
  264. {
  265. ide_hwif_t *hwif = drive->hwif;
  266. struct ide_io_ports *io_ports = &hwif->io_ports;
  267. unsigned long data_addr = io_ports->data_addr;
  268. u8 io_32bit = drive->io_32bit;
  269. u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
  270. len++;
  271. if (io_32bit) {
  272. unsigned long uninitialized_var(flags);
  273. if ((io_32bit & 2) && !mmio) {
  274. local_irq_save(flags);
  275. ata_vlb_sync(io_ports->nsect_addr);
  276. }
  277. if (mmio)
  278. __ide_mm_outsl((void __iomem *)data_addr, buf, len / 4);
  279. else
  280. outsl(data_addr, buf, len / 4);
  281. if ((io_32bit & 2) && !mmio)
  282. local_irq_restore(flags);
  283. if ((len & 3) >= 2) {
  284. if (mmio)
  285. __ide_mm_outsw((void __iomem *)data_addr,
  286. (u8 *)buf + (len & ~3), 1);
  287. else
  288. outsw(data_addr, (u8 *)buf + (len & ~3), 1);
  289. }
  290. } else {
  291. if (mmio)
  292. __ide_mm_outsw((void __iomem *)data_addr, buf, len / 2);
  293. else
  294. outsw(data_addr, buf, len / 2);
  295. }
  296. }
  297. EXPORT_SYMBOL_GPL(ide_output_data);
  298. u8 ide_read_error(ide_drive_t *drive)
  299. {
  300. ide_task_t task;
  301. memset(&task, 0, sizeof(task));
  302. task.tf_flags = IDE_TFLAG_IN_FEATURE;
  303. drive->hwif->tp_ops->tf_read(drive, &task);
  304. return task.tf.error;
  305. }
  306. EXPORT_SYMBOL_GPL(ide_read_error);
  307. void ide_read_bcount_and_ireason(ide_drive_t *drive, u16 *bcount, u8 *ireason)
  308. {
  309. ide_task_t task;
  310. memset(&task, 0, sizeof(task));
  311. task.tf_flags = IDE_TFLAG_IN_LBAH | IDE_TFLAG_IN_LBAM |
  312. IDE_TFLAG_IN_NSECT;
  313. drive->hwif->tp_ops->tf_read(drive, &task);
  314. *bcount = (task.tf.lbah << 8) | task.tf.lbam;
  315. *ireason = task.tf.nsect & 3;
  316. }
  317. EXPORT_SYMBOL_GPL(ide_read_bcount_and_ireason);
  318. const struct ide_tp_ops default_tp_ops = {
  319. .exec_command = ide_exec_command,
  320. .read_status = ide_read_status,
  321. .read_altstatus = ide_read_altstatus,
  322. .set_irq = ide_set_irq,
  323. .tf_load = ide_tf_load,
  324. .tf_read = ide_tf_read,
  325. .input_data = ide_input_data,
  326. .output_data = ide_output_data,
  327. };
  328. void ide_fix_driveid(u16 *id)
  329. {
  330. #ifndef __LITTLE_ENDIAN
  331. # ifdef __BIG_ENDIAN
  332. int i;
  333. for (i = 0; i < 256; i++)
  334. id[i] = __le16_to_cpu(id[i]);
  335. # else
  336. # error "Please fix <asm/byteorder.h>"
  337. # endif
  338. #endif
  339. }
  340. /*
  341. * ide_fixstring() cleans up and (optionally) byte-swaps a text string,
  342. * removing leading/trailing blanks and compressing internal blanks.
  343. * It is primarily used to tidy up the model name/number fields as
  344. * returned by the ATA_CMD_ID_ATA[PI] commands.
  345. */
  346. void ide_fixstring (u8 *s, const int bytecount, const int byteswap)
  347. {
  348. u8 *p, *end = &s[bytecount & ~1]; /* bytecount must be even */
  349. if (byteswap) {
  350. /* convert from big-endian to host byte order */
  351. for (p = s ; p != end ; p += 2)
  352. be16_to_cpus((u16 *) p);
  353. }
  354. /* strip leading blanks */
  355. p = s;
  356. while (s != end && *s == ' ')
  357. ++s;
  358. /* compress internal blanks and strip trailing blanks */
  359. while (s != end && *s) {
  360. if (*s++ != ' ' || (s != end && *s && *s != ' '))
  361. *p++ = *(s-1);
  362. }
  363. /* wipe out trailing garbage */
  364. while (p != end)
  365. *p++ = '\0';
  366. }
  367. EXPORT_SYMBOL(ide_fixstring);
  368. /*
  369. * Needed for PCI irq sharing
  370. */
  371. int drive_is_ready (ide_drive_t *drive)
  372. {
  373. ide_hwif_t *hwif = drive->hwif;
  374. u8 stat = 0;
  375. if (drive->waiting_for_dma)
  376. return hwif->dma_ops->dma_test_irq(drive);
  377. /*
  378. * We do a passive status test under shared PCI interrupts on
  379. * cards that truly share the ATA side interrupt, but may also share
  380. * an interrupt with another pci card/device. We make no assumptions
  381. * about possible isa-pnp and pci-pnp issues yet.
  382. */
  383. if (hwif->io_ports.ctl_addr &&
  384. (hwif->host_flags & IDE_HFLAG_BROKEN_ALTSTATUS) == 0)
  385. stat = hwif->tp_ops->read_altstatus(hwif);
  386. else
  387. /* Note: this may clear a pending IRQ!! */
  388. stat = hwif->tp_ops->read_status(hwif);
  389. if (stat & ATA_BUSY)
  390. /* drive busy: definitely not interrupting */
  391. return 0;
  392. /* drive ready: *might* be interrupting */
  393. return 1;
  394. }
  395. EXPORT_SYMBOL(drive_is_ready);
  396. /*
  397. * This routine busy-waits for the drive status to be not "busy".
  398. * It then checks the status for all of the "good" bits and none
  399. * of the "bad" bits, and if all is okay it returns 0. All other
  400. * cases return error -- caller may then invoke ide_error().
  401. *
  402. * This routine should get fixed to not hog the cpu during extra long waits..
  403. * That could be done by busy-waiting for the first jiffy or two, and then
  404. * setting a timer to wake up at half second intervals thereafter,
  405. * until timeout is achieved, before timing out.
  406. */
  407. static int __ide_wait_stat(ide_drive_t *drive, u8 good, u8 bad, unsigned long timeout, u8 *rstat)
  408. {
  409. ide_hwif_t *hwif = drive->hwif;
  410. const struct ide_tp_ops *tp_ops = hwif->tp_ops;
  411. unsigned long flags;
  412. int i;
  413. u8 stat;
  414. udelay(1); /* spec allows drive 400ns to assert "BUSY" */
  415. stat = tp_ops->read_status(hwif);
  416. if (stat & ATA_BUSY) {
  417. local_save_flags(flags);
  418. local_irq_enable_in_hardirq();
  419. timeout += jiffies;
  420. while ((stat = tp_ops->read_status(hwif)) & ATA_BUSY) {
  421. if (time_after(jiffies, timeout)) {
  422. /*
  423. * One last read after the timeout in case
  424. * heavy interrupt load made us not make any
  425. * progress during the timeout..
  426. */
  427. stat = tp_ops->read_status(hwif);
  428. if ((stat & ATA_BUSY) == 0)
  429. break;
  430. local_irq_restore(flags);
  431. *rstat = stat;
  432. return -EBUSY;
  433. }
  434. }
  435. local_irq_restore(flags);
  436. }
  437. /*
  438. * Allow status to settle, then read it again.
  439. * A few rare drives vastly violate the 400ns spec here,
  440. * so we'll wait up to 10usec for a "good" status
  441. * rather than expensively fail things immediately.
  442. * This fix courtesy of Matthew Faupel & Niccolo Rigacci.
  443. */
  444. for (i = 0; i < 10; i++) {
  445. udelay(1);
  446. stat = tp_ops->read_status(hwif);
  447. if (OK_STAT(stat, good, bad)) {
  448. *rstat = stat;
  449. return 0;
  450. }
  451. }
  452. *rstat = stat;
  453. return -EFAULT;
  454. }
  455. /*
  456. * In case of error returns error value after doing "*startstop = ide_error()".
  457. * The caller should return the updated value of "startstop" in this case,
  458. * "startstop" is unchanged when the function returns 0.
  459. */
  460. int ide_wait_stat(ide_startstop_t *startstop, ide_drive_t *drive, u8 good, u8 bad, unsigned long timeout)
  461. {
  462. int err;
  463. u8 stat;
  464. /* bail early if we've exceeded max_failures */
  465. if (drive->max_failures && (drive->failures > drive->max_failures)) {
  466. *startstop = ide_stopped;
  467. return 1;
  468. }
  469. err = __ide_wait_stat(drive, good, bad, timeout, &stat);
  470. if (err) {
  471. char *s = (err == -EBUSY) ? "status timeout" : "status error";
  472. *startstop = ide_error(drive, s, stat);
  473. }
  474. return err;
  475. }
  476. EXPORT_SYMBOL(ide_wait_stat);
  477. /**
  478. * ide_in_drive_list - look for drive in black/white list
  479. * @id: drive identifier
  480. * @table: list to inspect
  481. *
  482. * Look for a drive in the blacklist and the whitelist tables
  483. * Returns 1 if the drive is found in the table.
  484. */
  485. int ide_in_drive_list(u16 *id, const struct drive_list_entry *table)
  486. {
  487. for ( ; table->id_model; table++)
  488. if ((!strcmp(table->id_model, (char *)&id[ATA_ID_PROD])) &&
  489. (!table->id_firmware ||
  490. strstr((char *)&id[ATA_ID_FW_REV], table->id_firmware)))
  491. return 1;
  492. return 0;
  493. }
  494. EXPORT_SYMBOL_GPL(ide_in_drive_list);
  495. /*
  496. * Early UDMA66 devices don't set bit14 to 1, only bit13 is valid.
  497. * We list them here and depend on the device side cable detection for them.
  498. *
  499. * Some optical devices with the buggy firmwares have the same problem.
  500. */
  501. static const struct drive_list_entry ivb_list[] = {
  502. { "QUANTUM FIREBALLlct10 05" , "A03.0900" },
  503. { "TSSTcorp CDDVDW SH-S202J" , "SB00" },
  504. { "TSSTcorp CDDVDW SH-S202J" , "SB01" },
  505. { "TSSTcorp CDDVDW SH-S202N" , "SB00" },
  506. { "TSSTcorp CDDVDW SH-S202N" , "SB01" },
  507. { "TSSTcorp CDDVDW SH-S202H" , "SB00" },
  508. { "TSSTcorp CDDVDW SH-S202H" , "SB01" },
  509. { "SAMSUNG SP0822N" , "WA100-10" },
  510. { NULL , NULL }
  511. };
  512. /*
  513. * All hosts that use the 80c ribbon must use!
  514. * The name is derived from upper byte of word 93 and the 80c ribbon.
  515. */
  516. u8 eighty_ninty_three (ide_drive_t *drive)
  517. {
  518. ide_hwif_t *hwif = drive->hwif;
  519. u16 *id = drive->id;
  520. int ivb = ide_in_drive_list(id, ivb_list);
  521. if (hwif->cbl == ATA_CBL_PATA40_SHORT)
  522. return 1;
  523. if (ivb)
  524. printk(KERN_DEBUG "%s: skipping word 93 validity check\n",
  525. drive->name);
  526. if (ata_id_is_sata(id) && !ivb)
  527. return 1;
  528. if (hwif->cbl != ATA_CBL_PATA80 && !ivb)
  529. goto no_80w;
  530. /*
  531. * FIXME:
  532. * - change master/slave IDENTIFY order
  533. * - force bit13 (80c cable present) check also for !ivb devices
  534. * (unless the slave device is pre-ATA3)
  535. */
  536. if ((id[ATA_ID_HW_CONFIG] & 0x4000) ||
  537. (ivb && (id[ATA_ID_HW_CONFIG] & 0x2000)))
  538. return 1;
  539. no_80w:
  540. if (drive->dev_flags & IDE_DFLAG_UDMA33_WARNED)
  541. return 0;
  542. printk(KERN_WARNING "%s: %s side 80-wire cable detection failed, "
  543. "limiting max speed to UDMA33\n",
  544. drive->name,
  545. hwif->cbl == ATA_CBL_PATA80 ? "drive" : "host");
  546. drive->dev_flags |= IDE_DFLAG_UDMA33_WARNED;
  547. return 0;
  548. }
  549. int ide_driveid_update(ide_drive_t *drive)
  550. {
  551. ide_hwif_t *hwif = drive->hwif;
  552. const struct ide_tp_ops *tp_ops = hwif->tp_ops;
  553. u16 *id;
  554. unsigned long flags;
  555. u8 stat;
  556. /*
  557. * Re-read drive->id for possible DMA mode
  558. * change (copied from ide-probe.c)
  559. */
  560. SELECT_MASK(drive, 1);
  561. tp_ops->set_irq(hwif, 0);
  562. msleep(50);
  563. tp_ops->exec_command(hwif, ATA_CMD_ID_ATA);
  564. if (ide_busy_sleep(hwif, WAIT_WORSTCASE, 1)) {
  565. SELECT_MASK(drive, 0);
  566. return 0;
  567. }
  568. msleep(50); /* wait for IRQ and ATA_DRQ */
  569. stat = tp_ops->read_status(hwif);
  570. if (!OK_STAT(stat, ATA_DRQ, BAD_R_STAT)) {
  571. SELECT_MASK(drive, 0);
  572. printk("%s: CHECK for good STATUS\n", drive->name);
  573. return 0;
  574. }
  575. local_irq_save(flags);
  576. SELECT_MASK(drive, 0);
  577. id = kmalloc(SECTOR_SIZE, GFP_ATOMIC);
  578. if (!id) {
  579. local_irq_restore(flags);
  580. return 0;
  581. }
  582. tp_ops->input_data(drive, NULL, id, SECTOR_SIZE);
  583. (void)tp_ops->read_status(hwif); /* clear drive IRQ */
  584. local_irq_enable();
  585. local_irq_restore(flags);
  586. ide_fix_driveid(id);
  587. drive->id[ATA_ID_UDMA_MODES] = id[ATA_ID_UDMA_MODES];
  588. drive->id[ATA_ID_MWDMA_MODES] = id[ATA_ID_MWDMA_MODES];
  589. drive->id[ATA_ID_SWDMA_MODES] = id[ATA_ID_SWDMA_MODES];
  590. /* anything more ? */
  591. kfree(id);
  592. if ((drive->dev_flags & IDE_DFLAG_USING_DMA) && ide_id_dma_bug(drive))
  593. ide_dma_off(drive);
  594. return 1;
  595. }
  596. int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
  597. {
  598. ide_hwif_t *hwif = drive->hwif;
  599. const struct ide_tp_ops *tp_ops = hwif->tp_ops;
  600. u16 *id = drive->id, i;
  601. int error = 0;
  602. u8 stat;
  603. ide_task_t task;
  604. #ifdef CONFIG_BLK_DEV_IDEDMA
  605. if (hwif->dma_ops) /* check if host supports DMA */
  606. hwif->dma_ops->dma_host_set(drive, 0);
  607. #endif
  608. /* Skip setting PIO flow-control modes on pre-EIDE drives */
  609. if ((speed & 0xf8) == XFER_PIO_0 && ata_id_has_iordy(drive->id) == 0)
  610. goto skip;
  611. /*
  612. * Don't use ide_wait_cmd here - it will
  613. * attempt to set_geometry and recalibrate,
  614. * but for some reason these don't work at
  615. * this point (lost interrupt).
  616. */
  617. /*
  618. * Select the drive, and issue the SETFEATURES command
  619. */
  620. disable_irq_nosync(hwif->irq);
  621. /*
  622. * FIXME: we race against the running IRQ here if
  623. * this is called from non IRQ context. If we use
  624. * disable_irq() we hang on the error path. Work
  625. * is needed.
  626. */
  627. udelay(1);
  628. SELECT_DRIVE(drive);
  629. SELECT_MASK(drive, 1);
  630. udelay(1);
  631. tp_ops->set_irq(hwif, 0);
  632. memset(&task, 0, sizeof(task));
  633. task.tf_flags = IDE_TFLAG_OUT_FEATURE | IDE_TFLAG_OUT_NSECT;
  634. task.tf.feature = SETFEATURES_XFER;
  635. task.tf.nsect = speed;
  636. tp_ops->tf_load(drive, &task);
  637. tp_ops->exec_command(hwif, ATA_CMD_SET_FEATURES);
  638. if (drive->quirk_list == 2)
  639. tp_ops->set_irq(hwif, 1);
  640. error = __ide_wait_stat(drive, drive->ready_stat,
  641. ATA_BUSY | ATA_DRQ | ATA_ERR,
  642. WAIT_CMD, &stat);
  643. SELECT_MASK(drive, 0);
  644. enable_irq(hwif->irq);
  645. if (error) {
  646. (void) ide_dump_status(drive, "set_drive_speed_status", stat);
  647. return error;
  648. }
  649. id[ATA_ID_UDMA_MODES] &= ~0xFF00;
  650. id[ATA_ID_MWDMA_MODES] &= ~0x0F00;
  651. id[ATA_ID_SWDMA_MODES] &= ~0x0F00;
  652. skip:
  653. #ifdef CONFIG_BLK_DEV_IDEDMA
  654. if (speed >= XFER_SW_DMA_0 && (drive->dev_flags & IDE_DFLAG_USING_DMA))
  655. hwif->dma_ops->dma_host_set(drive, 1);
  656. else if (hwif->dma_ops) /* check if host supports DMA */
  657. ide_dma_off_quietly(drive);
  658. #endif
  659. if (speed >= XFER_UDMA_0) {
  660. i = 1 << (speed - XFER_UDMA_0);
  661. id[ATA_ID_UDMA_MODES] |= (i << 8 | i);
  662. } else if (speed >= XFER_MW_DMA_0) {
  663. i = 1 << (speed - XFER_MW_DMA_0);
  664. id[ATA_ID_MWDMA_MODES] |= (i << 8 | i);
  665. } else if (speed >= XFER_SW_DMA_0) {
  666. i = 1 << (speed - XFER_SW_DMA_0);
  667. id[ATA_ID_SWDMA_MODES] |= (i << 8 | i);
  668. }
  669. if (!drive->init_speed)
  670. drive->init_speed = speed;
  671. drive->current_speed = speed;
  672. return error;
  673. }
  674. /*
  675. * This should get invoked any time we exit the driver to
  676. * wait for an interrupt response from a drive. handler() points
  677. * at the appropriate code to handle the next interrupt, and a
  678. * timer is started to prevent us from waiting forever in case
  679. * something goes wrong (see the ide_timer_expiry() handler later on).
  680. *
  681. * See also ide_execute_command
  682. */
  683. static void __ide_set_handler (ide_drive_t *drive, ide_handler_t *handler,
  684. unsigned int timeout, ide_expiry_t *expiry)
  685. {
  686. ide_hwif_t *hwif = drive->hwif;
  687. BUG_ON(hwif->handler);
  688. hwif->handler = handler;
  689. hwif->expiry = expiry;
  690. hwif->timer.expires = jiffies + timeout;
  691. hwif->req_gen_timer = hwif->req_gen;
  692. add_timer(&hwif->timer);
  693. }
  694. void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler,
  695. unsigned int timeout, ide_expiry_t *expiry)
  696. {
  697. ide_hwif_t *hwif = drive->hwif;
  698. unsigned long flags;
  699. spin_lock_irqsave(&hwif->lock, flags);
  700. __ide_set_handler(drive, handler, timeout, expiry);
  701. spin_unlock_irqrestore(&hwif->lock, flags);
  702. }
  703. EXPORT_SYMBOL(ide_set_handler);
  704. /**
  705. * ide_execute_command - execute an IDE command
  706. * @drive: IDE drive to issue the command against
  707. * @command: command byte to write
  708. * @handler: handler for next phase
  709. * @timeout: timeout for command
  710. * @expiry: handler to run on timeout
  711. *
  712. * Helper function to issue an IDE command. This handles the
  713. * atomicity requirements, command timing and ensures that the
  714. * handler and IRQ setup do not race. All IDE command kick off
  715. * should go via this function or do equivalent locking.
  716. */
  717. void ide_execute_command(ide_drive_t *drive, u8 cmd, ide_handler_t *handler,
  718. unsigned timeout, ide_expiry_t *expiry)
  719. {
  720. ide_hwif_t *hwif = drive->hwif;
  721. unsigned long flags;
  722. spin_lock_irqsave(&hwif->lock, flags);
  723. __ide_set_handler(drive, handler, timeout, expiry);
  724. hwif->tp_ops->exec_command(hwif, cmd);
  725. /*
  726. * Drive takes 400nS to respond, we must avoid the IRQ being
  727. * serviced before that.
  728. *
  729. * FIXME: we could skip this delay with care on non shared devices
  730. */
  731. ndelay(400);
  732. spin_unlock_irqrestore(&hwif->lock, flags);
  733. }
  734. EXPORT_SYMBOL(ide_execute_command);
  735. void ide_execute_pkt_cmd(ide_drive_t *drive)
  736. {
  737. ide_hwif_t *hwif = drive->hwif;
  738. unsigned long flags;
  739. spin_lock_irqsave(&hwif->lock, flags);
  740. hwif->tp_ops->exec_command(hwif, ATA_CMD_PACKET);
  741. ndelay(400);
  742. spin_unlock_irqrestore(&hwif->lock, flags);
  743. }
  744. EXPORT_SYMBOL_GPL(ide_execute_pkt_cmd);
  745. static inline void ide_complete_drive_reset(ide_drive_t *drive, int err)
  746. {
  747. struct request *rq = drive->hwif->rq;
  748. if (rq && blk_special_request(rq) && rq->cmd[0] == REQ_DRIVE_RESET)
  749. ide_end_request(drive, err ? err : 1, 0);
  750. }
  751. /* needed below */
  752. static ide_startstop_t do_reset1 (ide_drive_t *, int);
  753. /*
  754. * atapi_reset_pollfunc() gets invoked to poll the interface for completion every 50ms
  755. * during an atapi drive reset operation. If the drive has not yet responded,
  756. * and we have not yet hit our maximum waiting time, then the timer is restarted
  757. * for another 50ms.
  758. */
  759. static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive)
  760. {
  761. ide_hwif_t *hwif = drive->hwif;
  762. u8 stat;
  763. SELECT_DRIVE(drive);
  764. udelay (10);
  765. stat = hwif->tp_ops->read_status(hwif);
  766. if (OK_STAT(stat, 0, ATA_BUSY))
  767. printk("%s: ATAPI reset complete\n", drive->name);
  768. else {
  769. if (time_before(jiffies, hwif->poll_timeout)) {
  770. ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL);
  771. /* continue polling */
  772. return ide_started;
  773. }
  774. /* end of polling */
  775. hwif->polling = 0;
  776. printk("%s: ATAPI reset timed-out, status=0x%02x\n",
  777. drive->name, stat);
  778. /* do it the old fashioned way */
  779. return do_reset1(drive, 1);
  780. }
  781. /* done polling */
  782. hwif->polling = 0;
  783. ide_complete_drive_reset(drive, 0);
  784. return ide_stopped;
  785. }
  786. static void ide_reset_report_error(ide_hwif_t *hwif, u8 err)
  787. {
  788. static const char *err_master_vals[] =
  789. { NULL, "passed", "formatter device error",
  790. "sector buffer error", "ECC circuitry error",
  791. "controlling MPU error" };
  792. u8 err_master = err & 0x7f;
  793. printk(KERN_ERR "%s: reset: master: ", hwif->name);
  794. if (err_master && err_master < 6)
  795. printk(KERN_CONT "%s", err_master_vals[err_master]);
  796. else
  797. printk(KERN_CONT "error (0x%02x?)", err);
  798. if (err & 0x80)
  799. printk(KERN_CONT "; slave: failed");
  800. printk(KERN_CONT "\n");
  801. }
  802. /*
  803. * reset_pollfunc() gets invoked to poll the interface for completion every 50ms
  804. * during an ide reset operation. If the drives have not yet responded,
  805. * and we have not yet hit our maximum waiting time, then the timer is restarted
  806. * for another 50ms.
  807. */
  808. static ide_startstop_t reset_pollfunc (ide_drive_t *drive)
  809. {
  810. ide_hwif_t *hwif = drive->hwif;
  811. const struct ide_port_ops *port_ops = hwif->port_ops;
  812. u8 tmp;
  813. int err = 0;
  814. if (port_ops && port_ops->reset_poll) {
  815. err = port_ops->reset_poll(drive);
  816. if (err) {
  817. printk(KERN_ERR "%s: host reset_poll failure for %s.\n",
  818. hwif->name, drive->name);
  819. goto out;
  820. }
  821. }
  822. tmp = hwif->tp_ops->read_status(hwif);
  823. if (!OK_STAT(tmp, 0, ATA_BUSY)) {
  824. if (time_before(jiffies, hwif->poll_timeout)) {
  825. ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL);
  826. /* continue polling */
  827. return ide_started;
  828. }
  829. printk("%s: reset timed-out, status=0x%02x\n", hwif->name, tmp);
  830. drive->failures++;
  831. err = -EIO;
  832. } else {
  833. tmp = ide_read_error(drive);
  834. if (tmp == 1) {
  835. printk(KERN_INFO "%s: reset: success\n", hwif->name);
  836. drive->failures = 0;
  837. } else {
  838. ide_reset_report_error(hwif, tmp);
  839. drive->failures++;
  840. err = -EIO;
  841. }
  842. }
  843. out:
  844. hwif->polling = 0; /* done polling */
  845. ide_complete_drive_reset(drive, err);
  846. return ide_stopped;
  847. }
  848. static void ide_disk_pre_reset(ide_drive_t *drive)
  849. {
  850. int legacy = (drive->id[ATA_ID_CFS_ENABLE_2] & 0x0400) ? 0 : 1;
  851. drive->special.all = 0;
  852. drive->special.b.set_geometry = legacy;
  853. drive->special.b.recalibrate = legacy;
  854. drive->mult_count = 0;
  855. drive->dev_flags &= ~IDE_DFLAG_PARKED;
  856. if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0 &&
  857. (drive->dev_flags & IDE_DFLAG_USING_DMA) == 0)
  858. drive->mult_req = 0;
  859. if (drive->mult_req != drive->mult_count)
  860. drive->special.b.set_multmode = 1;
  861. }
  862. static void pre_reset(ide_drive_t *drive)
  863. {
  864. const struct ide_port_ops *port_ops = drive->hwif->port_ops;
  865. if (drive->media == ide_disk)
  866. ide_disk_pre_reset(drive);
  867. else
  868. drive->dev_flags |= IDE_DFLAG_POST_RESET;
  869. if (drive->dev_flags & IDE_DFLAG_USING_DMA) {
  870. if (drive->crc_count)
  871. ide_check_dma_crc(drive);
  872. else
  873. ide_dma_off(drive);
  874. }
  875. if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0) {
  876. if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0) {
  877. drive->dev_flags &= ~IDE_DFLAG_UNMASK;
  878. drive->io_32bit = 0;
  879. }
  880. return;
  881. }
  882. if (port_ops && port_ops->pre_reset)
  883. port_ops->pre_reset(drive);
  884. if (drive->current_speed != 0xff)
  885. drive->desired_speed = drive->current_speed;
  886. drive->current_speed = 0xff;
  887. }
  888. /*
  889. * do_reset1() attempts to recover a confused drive by resetting it.
  890. * Unfortunately, resetting a disk drive actually resets all devices on
  891. * the same interface, so it can really be thought of as resetting the
  892. * interface rather than resetting the drive.
  893. *
  894. * ATAPI devices have their own reset mechanism which allows them to be
  895. * individually reset without clobbering other devices on the same interface.
  896. *
  897. * Unfortunately, the IDE interface does not generate an interrupt to let
  898. * us know when the reset operation has finished, so we must poll for this.
  899. * Equally poor, though, is the fact that this may a very long time to complete,
  900. * (up to 30 seconds worstcase). So, instead of busy-waiting here for it,
  901. * we set a timer to poll at 50ms intervals.
  902. */
  903. static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
  904. {
  905. ide_hwif_t *hwif = drive->hwif;
  906. struct ide_io_ports *io_ports = &hwif->io_ports;
  907. const struct ide_tp_ops *tp_ops = hwif->tp_ops;
  908. const struct ide_port_ops *port_ops;
  909. ide_drive_t *tdrive;
  910. unsigned long flags, timeout;
  911. int i;
  912. DEFINE_WAIT(wait);
  913. spin_lock_irqsave(&hwif->lock, flags);
  914. /* We must not reset with running handlers */
  915. BUG_ON(hwif->handler != NULL);
  916. /* For an ATAPI device, first try an ATAPI SRST. */
  917. if (drive->media != ide_disk && !do_not_try_atapi) {
  918. pre_reset(drive);
  919. SELECT_DRIVE(drive);
  920. udelay (20);
  921. tp_ops->exec_command(hwif, ATA_CMD_DEV_RESET);
  922. ndelay(400);
  923. hwif->poll_timeout = jiffies + WAIT_WORSTCASE;
  924. hwif->polling = 1;
  925. __ide_set_handler(drive, &atapi_reset_pollfunc, HZ/20, NULL);
  926. spin_unlock_irqrestore(&hwif->lock, flags);
  927. return ide_started;
  928. }
  929. /* We must not disturb devices in the IDE_DFLAG_PARKED state. */
  930. do {
  931. unsigned long now;
  932. prepare_to_wait(&ide_park_wq, &wait, TASK_UNINTERRUPTIBLE);
  933. timeout = jiffies;
  934. ide_port_for_each_dev(i, tdrive, hwif) {
  935. if (tdrive->dev_flags & IDE_DFLAG_PRESENT &&
  936. tdrive->dev_flags & IDE_DFLAG_PARKED &&
  937. time_after(tdrive->sleep, timeout))
  938. timeout = tdrive->sleep;
  939. }
  940. now = jiffies;
  941. if (time_before_eq(timeout, now))
  942. break;
  943. spin_unlock_irqrestore(&hwif->lock, flags);
  944. timeout = schedule_timeout_uninterruptible(timeout - now);
  945. spin_lock_irqsave(&hwif->lock, flags);
  946. } while (timeout);
  947. finish_wait(&ide_park_wq, &wait);
  948. /*
  949. * First, reset any device state data we were maintaining
  950. * for any of the drives on this interface.
  951. */
  952. ide_port_for_each_dev(i, tdrive, hwif)
  953. pre_reset(tdrive);
  954. if (io_ports->ctl_addr == 0) {
  955. spin_unlock_irqrestore(&hwif->lock, flags);
  956. ide_complete_drive_reset(drive, -ENXIO);
  957. return ide_stopped;
  958. }
  959. /*
  960. * Note that we also set nIEN while resetting the device,
  961. * to mask unwanted interrupts from the interface during the reset.
  962. * However, due to the design of PC hardware, this will cause an
  963. * immediate interrupt due to the edge transition it produces.
  964. * This single interrupt gives us a "fast poll" for drives that
  965. * recover from reset very quickly, saving us the first 50ms wait time.
  966. *
  967. * TODO: add ->softreset method and stop abusing ->set_irq
  968. */
  969. /* set SRST and nIEN */
  970. tp_ops->set_irq(hwif, 4);
  971. /* more than enough time */
  972. udelay(10);
  973. /* clear SRST, leave nIEN (unless device is on the quirk list) */
  974. tp_ops->set_irq(hwif, drive->quirk_list == 2);
  975. /* more than enough time */
  976. udelay(10);
  977. hwif->poll_timeout = jiffies + WAIT_WORSTCASE;
  978. hwif->polling = 1;
  979. __ide_set_handler(drive, &reset_pollfunc, HZ/20, NULL);
  980. /*
  981. * Some weird controller like resetting themselves to a strange
  982. * state when the disks are reset this way. At least, the Winbond
  983. * 553 documentation says that
  984. */
  985. port_ops = hwif->port_ops;
  986. if (port_ops && port_ops->resetproc)
  987. port_ops->resetproc(drive);
  988. spin_unlock_irqrestore(&hwif->lock, flags);
  989. return ide_started;
  990. }
  991. /*
  992. * ide_do_reset() is the entry point to the drive/interface reset code.
  993. */
  994. ide_startstop_t ide_do_reset (ide_drive_t *drive)
  995. {
  996. return do_reset1(drive, 0);
  997. }
  998. EXPORT_SYMBOL(ide_do_reset);
  999. /*
  1000. * ide_wait_not_busy() waits for the currently selected device on the hwif
  1001. * to report a non-busy status, see comments in ide_probe_port().
  1002. */
  1003. int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout)
  1004. {
  1005. u8 stat = 0;
  1006. while(timeout--) {
  1007. /*
  1008. * Turn this into a schedule() sleep once I'm sure
  1009. * about locking issues (2.5 work ?).
  1010. */
  1011. mdelay(1);
  1012. stat = hwif->tp_ops->read_status(hwif);
  1013. if ((stat & ATA_BUSY) == 0)
  1014. return 0;
  1015. /*
  1016. * Assume a value of 0xff means nothing is connected to
  1017. * the interface and it doesn't implement the pull-down
  1018. * resistor on D7.
  1019. */
  1020. if (stat == 0xff)
  1021. return -ENODEV;
  1022. touch_softlockup_watchdog();
  1023. touch_nmi_watchdog();
  1024. }
  1025. return -EBUSY;
  1026. }