ide-iops.c 31 KB

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