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