ide-iops.c 34 KB

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