ide-iops.c 32 KB

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