ide-iops.c 33 KB

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