ide-iops.c 32 KB

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