ide-iops.c 33 KB

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