ide-iops.c 33 KB

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