ide-iops.c 33 KB

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