ide-iops.c 34 KB

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