ide-iops.c 33 KB

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