ide-lib.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. #include <linux/config.h>
  2. #include <linux/module.h>
  3. #include <linux/types.h>
  4. #include <linux/string.h>
  5. #include <linux/kernel.h>
  6. #include <linux/timer.h>
  7. #include <linux/mm.h>
  8. #include <linux/interrupt.h>
  9. #include <linux/major.h>
  10. #include <linux/errno.h>
  11. #include <linux/genhd.h>
  12. #include <linux/blkpg.h>
  13. #include <linux/slab.h>
  14. #include <linux/pci.h>
  15. #include <linux/delay.h>
  16. #include <linux/hdreg.h>
  17. #include <linux/ide.h>
  18. #include <linux/bitops.h>
  19. #include <asm/byteorder.h>
  20. #include <asm/irq.h>
  21. #include <asm/uaccess.h>
  22. #include <asm/io.h>
  23. /*
  24. * IDE library routines. These are plug in code that most
  25. * drivers can use but occasionally may be weird enough
  26. * to want to do their own thing with
  27. *
  28. * Add common non I/O op stuff here. Make sure it has proper
  29. * kernel-doc function headers or your patch will be rejected
  30. */
  31. /**
  32. * ide_xfer_verbose - return IDE mode names
  33. * @xfer_rate: rate to name
  34. *
  35. * Returns a constant string giving the name of the mode
  36. * requested.
  37. */
  38. char *ide_xfer_verbose (u8 xfer_rate)
  39. {
  40. switch(xfer_rate) {
  41. case XFER_UDMA_7: return("UDMA 7");
  42. case XFER_UDMA_6: return("UDMA 6");
  43. case XFER_UDMA_5: return("UDMA 5");
  44. case XFER_UDMA_4: return("UDMA 4");
  45. case XFER_UDMA_3: return("UDMA 3");
  46. case XFER_UDMA_2: return("UDMA 2");
  47. case XFER_UDMA_1: return("UDMA 1");
  48. case XFER_UDMA_0: return("UDMA 0");
  49. case XFER_MW_DMA_2: return("MW DMA 2");
  50. case XFER_MW_DMA_1: return("MW DMA 1");
  51. case XFER_MW_DMA_0: return("MW DMA 0");
  52. case XFER_SW_DMA_2: return("SW DMA 2");
  53. case XFER_SW_DMA_1: return("SW DMA 1");
  54. case XFER_SW_DMA_0: return("SW DMA 0");
  55. case XFER_PIO_4: return("PIO 4");
  56. case XFER_PIO_3: return("PIO 3");
  57. case XFER_PIO_2: return("PIO 2");
  58. case XFER_PIO_1: return("PIO 1");
  59. case XFER_PIO_0: return("PIO 0");
  60. case XFER_PIO_SLOW: return("PIO SLOW");
  61. default: return("XFER ERROR");
  62. }
  63. }
  64. EXPORT_SYMBOL(ide_xfer_verbose);
  65. /**
  66. * ide_dma_speed - compute DMA speed
  67. * @drive: drive
  68. * @mode; intended mode
  69. *
  70. * Checks the drive capabilities and returns the speed to use
  71. * for the transfer. Returns -1 if the requested mode is unknown
  72. * (eg PIO)
  73. */
  74. u8 ide_dma_speed(ide_drive_t *drive, u8 mode)
  75. {
  76. struct hd_driveid *id = drive->id;
  77. ide_hwif_t *hwif = HWIF(drive);
  78. u8 speed = 0;
  79. if (drive->media != ide_disk && hwif->atapi_dma == 0)
  80. return 0;
  81. switch(mode) {
  82. case 0x04:
  83. if ((id->dma_ultra & 0x0040) &&
  84. (id->dma_ultra & hwif->ultra_mask))
  85. { speed = XFER_UDMA_6; break; }
  86. case 0x03:
  87. if ((id->dma_ultra & 0x0020) &&
  88. (id->dma_ultra & hwif->ultra_mask))
  89. { speed = XFER_UDMA_5; break; }
  90. case 0x02:
  91. if ((id->dma_ultra & 0x0010) &&
  92. (id->dma_ultra & hwif->ultra_mask))
  93. { speed = XFER_UDMA_4; break; }
  94. if ((id->dma_ultra & 0x0008) &&
  95. (id->dma_ultra & hwif->ultra_mask))
  96. { speed = XFER_UDMA_3; break; }
  97. case 0x01:
  98. if ((id->dma_ultra & 0x0004) &&
  99. (id->dma_ultra & hwif->ultra_mask))
  100. { speed = XFER_UDMA_2; break; }
  101. if ((id->dma_ultra & 0x0002) &&
  102. (id->dma_ultra & hwif->ultra_mask))
  103. { speed = XFER_UDMA_1; break; }
  104. if ((id->dma_ultra & 0x0001) &&
  105. (id->dma_ultra & hwif->ultra_mask))
  106. { speed = XFER_UDMA_0; break; }
  107. case 0x00:
  108. if ((id->dma_mword & 0x0004) &&
  109. (id->dma_mword & hwif->mwdma_mask))
  110. { speed = XFER_MW_DMA_2; break; }
  111. if ((id->dma_mword & 0x0002) &&
  112. (id->dma_mword & hwif->mwdma_mask))
  113. { speed = XFER_MW_DMA_1; break; }
  114. if ((id->dma_mword & 0x0001) &&
  115. (id->dma_mword & hwif->mwdma_mask))
  116. { speed = XFER_MW_DMA_0; break; }
  117. if ((id->dma_1word & 0x0004) &&
  118. (id->dma_1word & hwif->swdma_mask))
  119. { speed = XFER_SW_DMA_2; break; }
  120. if ((id->dma_1word & 0x0002) &&
  121. (id->dma_1word & hwif->swdma_mask))
  122. { speed = XFER_SW_DMA_1; break; }
  123. if ((id->dma_1word & 0x0001) &&
  124. (id->dma_1word & hwif->swdma_mask))
  125. { speed = XFER_SW_DMA_0; break; }
  126. }
  127. // printk("%s: %s: mode 0x%02x, speed 0x%02x\n",
  128. // __FUNCTION__, drive->name, mode, speed);
  129. return speed;
  130. }
  131. EXPORT_SYMBOL(ide_dma_speed);
  132. /**
  133. * ide_rate_filter - return best speed for mode
  134. * @mode: modes available
  135. * @speed: desired speed
  136. *
  137. * Given the available DMA/UDMA mode this function returns
  138. * the best available speed at or below the speed requested.
  139. */
  140. u8 ide_rate_filter (u8 mode, u8 speed)
  141. {
  142. #ifdef CONFIG_BLK_DEV_IDEDMA
  143. static u8 speed_max[] = {
  144. XFER_MW_DMA_2, XFER_UDMA_2, XFER_UDMA_4,
  145. XFER_UDMA_5, XFER_UDMA_6
  146. };
  147. // printk("%s: mode 0x%02x, speed 0x%02x\n", __FUNCTION__, mode, speed);
  148. /* So that we remember to update this if new modes appear */
  149. if (mode > 4)
  150. BUG();
  151. return min(speed, speed_max[mode]);
  152. #else /* !CONFIG_BLK_DEV_IDEDMA */
  153. return min(speed, (u8)XFER_PIO_4);
  154. #endif /* CONFIG_BLK_DEV_IDEDMA */
  155. }
  156. EXPORT_SYMBOL(ide_rate_filter);
  157. int ide_dma_enable (ide_drive_t *drive)
  158. {
  159. ide_hwif_t *hwif = HWIF(drive);
  160. struct hd_driveid *id = drive->id;
  161. return ((int) ((((id->dma_ultra >> 8) & hwif->ultra_mask) ||
  162. ((id->dma_mword >> 8) & hwif->mwdma_mask) ||
  163. ((id->dma_1word >> 8) & hwif->swdma_mask)) ? 1 : 0));
  164. }
  165. EXPORT_SYMBOL(ide_dma_enable);
  166. /*
  167. * Standard (generic) timings for PIO modes, from ATA2 specification.
  168. * These timings are for access to the IDE data port register *only*.
  169. * Some drives may specify a mode, while also specifying a different
  170. * value for cycle_time (from drive identification data).
  171. */
  172. const ide_pio_timings_t ide_pio_timings[6] = {
  173. { 70, 165, 600 }, /* PIO Mode 0 */
  174. { 50, 125, 383 }, /* PIO Mode 1 */
  175. { 30, 100, 240 }, /* PIO Mode 2 */
  176. { 30, 80, 180 }, /* PIO Mode 3 with IORDY */
  177. { 25, 70, 120 }, /* PIO Mode 4 with IORDY */
  178. { 20, 50, 100 } /* PIO Mode 5 with IORDY (nonstandard) */
  179. };
  180. EXPORT_SYMBOL_GPL(ide_pio_timings);
  181. /*
  182. * Shared data/functions for determining best PIO mode for an IDE drive.
  183. * Most of this stuff originally lived in cmd640.c, and changes to the
  184. * ide_pio_blacklist[] table should be made with EXTREME CAUTION to avoid
  185. * breaking the fragile cmd640.c support.
  186. */
  187. /*
  188. * Black list. Some drives incorrectly report their maximal PIO mode,
  189. * at least in respect to CMD640. Here we keep info on some known drives.
  190. */
  191. static struct ide_pio_info {
  192. const char *name;
  193. int pio;
  194. } ide_pio_blacklist [] = {
  195. /* { "Conner Peripherals 1275MB - CFS1275A", 4 }, */
  196. { "Conner Peripherals 540MB - CFS540A", 3 },
  197. { "WDC AC2700", 3 },
  198. { "WDC AC2540", 3 },
  199. { "WDC AC2420", 3 },
  200. { "WDC AC2340", 3 },
  201. { "WDC AC2250", 0 },
  202. { "WDC AC2200", 0 },
  203. { "WDC AC21200", 4 },
  204. { "WDC AC2120", 0 },
  205. { "WDC AC2850", 3 },
  206. { "WDC AC1270", 3 },
  207. { "WDC AC1170", 1 },
  208. { "WDC AC1210", 1 },
  209. { "WDC AC280", 0 },
  210. /* { "WDC AC21000", 4 }, */
  211. { "WDC AC31000", 3 },
  212. { "WDC AC31200", 3 },
  213. /* { "WDC AC31600", 4 }, */
  214. { "Maxtor 7131 AT", 1 },
  215. { "Maxtor 7171 AT", 1 },
  216. { "Maxtor 7213 AT", 1 },
  217. { "Maxtor 7245 AT", 1 },
  218. { "Maxtor 7345 AT", 1 },
  219. { "Maxtor 7546 AT", 3 },
  220. { "Maxtor 7540 AV", 3 },
  221. { "SAMSUNG SHD-3121A", 1 },
  222. { "SAMSUNG SHD-3122A", 1 },
  223. { "SAMSUNG SHD-3172A", 1 },
  224. /* { "ST51080A", 4 },
  225. * { "ST51270A", 4 },
  226. * { "ST31220A", 4 },
  227. * { "ST31640A", 4 },
  228. * { "ST32140A", 4 },
  229. * { "ST3780A", 4 },
  230. */
  231. { "ST5660A", 3 },
  232. { "ST3660A", 3 },
  233. { "ST3630A", 3 },
  234. { "ST3655A", 3 },
  235. { "ST3391A", 3 },
  236. { "ST3390A", 1 },
  237. { "ST3600A", 1 },
  238. { "ST3290A", 0 },
  239. { "ST3144A", 0 },
  240. { "ST3491A", 1 }, /* reports 3, should be 1 or 2 (depending on */
  241. /* drive) according to Seagates FIND-ATA program */
  242. { "QUANTUM ELS127A", 0 },
  243. { "QUANTUM ELS170A", 0 },
  244. { "QUANTUM LPS240A", 0 },
  245. { "QUANTUM LPS210A", 3 },
  246. { "QUANTUM LPS270A", 3 },
  247. { "QUANTUM LPS365A", 3 },
  248. { "QUANTUM LPS540A", 3 },
  249. { "QUANTUM LIGHTNING 540A", 3 },
  250. { "QUANTUM LIGHTNING 730A", 3 },
  251. { "QUANTUM FIREBALL_540", 3 }, /* Older Quantum Fireballs don't work */
  252. { "QUANTUM FIREBALL_640", 3 },
  253. { "QUANTUM FIREBALL_1080", 3 },
  254. { "QUANTUM FIREBALL_1280", 3 },
  255. { NULL, 0 }
  256. };
  257. /**
  258. * ide_scan_pio_blacklist - check for a blacklisted drive
  259. * @model: Drive model string
  260. *
  261. * This routine searches the ide_pio_blacklist for an entry
  262. * matching the start/whole of the supplied model name.
  263. *
  264. * Returns -1 if no match found.
  265. * Otherwise returns the recommended PIO mode from ide_pio_blacklist[].
  266. */
  267. static int ide_scan_pio_blacklist (char *model)
  268. {
  269. struct ide_pio_info *p;
  270. for (p = ide_pio_blacklist; p->name != NULL; p++) {
  271. if (strncmp(p->name, model, strlen(p->name)) == 0)
  272. return p->pio;
  273. }
  274. return -1;
  275. }
  276. /**
  277. * ide_get_best_pio_mode - get PIO mode from drive
  278. * @driver: drive to consider
  279. * @mode_wanted: preferred mode
  280. * @max_mode: highest allowed
  281. * @d: pio data
  282. *
  283. * This routine returns the recommended PIO settings for a given drive,
  284. * based on the drive->id information and the ide_pio_blacklist[].
  285. * This is used by most chipset support modules when "auto-tuning".
  286. *
  287. * Drive PIO mode auto selection
  288. */
  289. u8 ide_get_best_pio_mode (ide_drive_t *drive, u8 mode_wanted, u8 max_mode, ide_pio_data_t *d)
  290. {
  291. int pio_mode;
  292. int cycle_time = 0;
  293. int use_iordy = 0;
  294. struct hd_driveid* id = drive->id;
  295. int overridden = 0;
  296. int blacklisted = 0;
  297. if (mode_wanted != 255) {
  298. pio_mode = mode_wanted;
  299. } else if (!drive->id) {
  300. pio_mode = 0;
  301. } else if ((pio_mode = ide_scan_pio_blacklist(id->model)) != -1) {
  302. overridden = 1;
  303. blacklisted = 1;
  304. use_iordy = (pio_mode > 2);
  305. } else {
  306. pio_mode = id->tPIO;
  307. if (pio_mode > 2) { /* 2 is maximum allowed tPIO value */
  308. pio_mode = 2;
  309. overridden = 1;
  310. }
  311. if (id->field_valid & 2) { /* drive implements ATA2? */
  312. if (id->capability & 8) { /* drive supports use_iordy? */
  313. use_iordy = 1;
  314. cycle_time = id->eide_pio_iordy;
  315. if (id->eide_pio_modes & 7) {
  316. overridden = 0;
  317. if (id->eide_pio_modes & 4)
  318. pio_mode = 5;
  319. else if (id->eide_pio_modes & 2)
  320. pio_mode = 4;
  321. else
  322. pio_mode = 3;
  323. }
  324. } else {
  325. cycle_time = id->eide_pio;
  326. }
  327. }
  328. #if 0
  329. if (drive->id->major_rev_num & 0x0004) printk("ATA-2 ");
  330. #endif
  331. /*
  332. * Conservative "downgrade" for all pre-ATA2 drives
  333. */
  334. if (pio_mode && pio_mode < 4) {
  335. pio_mode--;
  336. overridden = 1;
  337. #if 0
  338. use_iordy = (pio_mode > 2);
  339. #endif
  340. if (cycle_time && cycle_time < ide_pio_timings[pio_mode].cycle_time)
  341. cycle_time = 0; /* use standard timing */
  342. }
  343. }
  344. if (pio_mode > max_mode) {
  345. pio_mode = max_mode;
  346. cycle_time = 0;
  347. }
  348. if (d) {
  349. d->pio_mode = pio_mode;
  350. d->cycle_time = cycle_time ? cycle_time : ide_pio_timings[pio_mode].cycle_time;
  351. d->use_iordy = use_iordy;
  352. d->overridden = overridden;
  353. d->blacklisted = blacklisted;
  354. }
  355. return pio_mode;
  356. }
  357. EXPORT_SYMBOL_GPL(ide_get_best_pio_mode);
  358. /**
  359. * ide_toggle_bounce - handle bounce buffering
  360. * @drive: drive to update
  361. * @on: on/off boolean
  362. *
  363. * Enable or disable bounce buffering for the device. Drives move
  364. * between PIO and DMA and that changes the rules we need.
  365. */
  366. void ide_toggle_bounce(ide_drive_t *drive, int on)
  367. {
  368. u64 addr = BLK_BOUNCE_HIGH; /* dma64_addr_t */
  369. if (!PCI_DMA_BUS_IS_PHYS) {
  370. addr = BLK_BOUNCE_ANY;
  371. } else if (on && drive->media == ide_disk) {
  372. if (HWIF(drive)->pci_dev)
  373. addr = HWIF(drive)->pci_dev->dma_mask;
  374. }
  375. if (drive->queue)
  376. blk_queue_bounce_limit(drive->queue, addr);
  377. }
  378. /**
  379. * ide_set_xfer_rate - set transfer rate
  380. * @drive: drive to set
  381. * @speed: speed to attempt to set
  382. *
  383. * General helper for setting the speed of an IDE device. This
  384. * function knows about user enforced limits from the configuration
  385. * which speedproc() does not. High level drivers should never
  386. * invoke speedproc() directly.
  387. */
  388. int ide_set_xfer_rate(ide_drive_t *drive, u8 rate)
  389. {
  390. #ifndef CONFIG_BLK_DEV_IDEDMA
  391. rate = min(rate, (u8) XFER_PIO_4);
  392. #endif
  393. if(HWIF(drive)->speedproc)
  394. return HWIF(drive)->speedproc(drive, rate);
  395. else
  396. return -1;
  397. }
  398. EXPORT_SYMBOL_GPL(ide_set_xfer_rate);
  399. static void ide_dump_opcode(ide_drive_t *drive)
  400. {
  401. struct request *rq;
  402. u8 opcode = 0;
  403. int found = 0;
  404. spin_lock(&ide_lock);
  405. rq = NULL;
  406. if (HWGROUP(drive))
  407. rq = HWGROUP(drive)->rq;
  408. spin_unlock(&ide_lock);
  409. if (!rq)
  410. return;
  411. if (rq->flags & (REQ_DRIVE_CMD | REQ_DRIVE_TASK)) {
  412. char *args = rq->buffer;
  413. if (args) {
  414. opcode = args[0];
  415. found = 1;
  416. }
  417. } else if (rq->flags & REQ_DRIVE_TASKFILE) {
  418. ide_task_t *args = rq->special;
  419. if (args) {
  420. task_struct_t *tf = (task_struct_t *) args->tfRegister;
  421. opcode = tf->command;
  422. found = 1;
  423. }
  424. }
  425. printk("ide: failed opcode was: ");
  426. if (!found)
  427. printk("unknown\n");
  428. else
  429. printk("0x%02x\n", opcode);
  430. }
  431. static u8 ide_dump_ata_status(ide_drive_t *drive, const char *msg, u8 stat)
  432. {
  433. ide_hwif_t *hwif = HWIF(drive);
  434. unsigned long flags;
  435. u8 err = 0;
  436. local_irq_set(flags);
  437. printk("%s: %s: status=0x%02x { ", drive->name, msg, stat);
  438. if (stat & BUSY_STAT)
  439. printk("Busy ");
  440. else {
  441. if (stat & READY_STAT) printk("DriveReady ");
  442. if (stat & WRERR_STAT) printk("DeviceFault ");
  443. if (stat & SEEK_STAT) printk("SeekComplete ");
  444. if (stat & DRQ_STAT) printk("DataRequest ");
  445. if (stat & ECC_STAT) printk("CorrectedError ");
  446. if (stat & INDEX_STAT) printk("Index ");
  447. if (stat & ERR_STAT) printk("Error ");
  448. }
  449. printk("}\n");
  450. if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) {
  451. err = hwif->INB(IDE_ERROR_REG);
  452. printk("%s: %s: error=0x%02x { ", drive->name, msg, err);
  453. if (err & ABRT_ERR) printk("DriveStatusError ");
  454. if (err & ICRC_ERR)
  455. printk((err & ABRT_ERR) ? "BadCRC " : "BadSector ");
  456. if (err & ECC_ERR) printk("UncorrectableError ");
  457. if (err & ID_ERR) printk("SectorIdNotFound ");
  458. if (err & TRK0_ERR) printk("TrackZeroNotFound ");
  459. if (err & MARK_ERR) printk("AddrMarkNotFound ");
  460. printk("}");
  461. if ((err & (BBD_ERR | ABRT_ERR)) == BBD_ERR ||
  462. (err & (ECC_ERR|ID_ERR|MARK_ERR))) {
  463. if (drive->addressing == 1) {
  464. __u64 sectors = 0;
  465. u32 low = 0, high = 0;
  466. low = ide_read_24(drive);
  467. hwif->OUTB(drive->ctl|0x80, IDE_CONTROL_REG);
  468. high = ide_read_24(drive);
  469. sectors = ((__u64)high << 24) | low;
  470. printk(", LBAsect=%llu, high=%d, low=%d",
  471. (unsigned long long) sectors,
  472. high, low);
  473. } else {
  474. u8 cur = hwif->INB(IDE_SELECT_REG);
  475. if (cur & 0x40) { /* using LBA? */
  476. printk(", LBAsect=%ld", (unsigned long)
  477. ((cur&0xf)<<24)
  478. |(hwif->INB(IDE_HCYL_REG)<<16)
  479. |(hwif->INB(IDE_LCYL_REG)<<8)
  480. | hwif->INB(IDE_SECTOR_REG));
  481. } else {
  482. printk(", CHS=%d/%d/%d",
  483. (hwif->INB(IDE_HCYL_REG)<<8) +
  484. hwif->INB(IDE_LCYL_REG),
  485. cur & 0xf,
  486. hwif->INB(IDE_SECTOR_REG));
  487. }
  488. }
  489. if (HWGROUP(drive) && HWGROUP(drive)->rq)
  490. printk(", sector=%llu",
  491. (unsigned long long)HWGROUP(drive)->rq->sector);
  492. }
  493. printk("\n");
  494. }
  495. ide_dump_opcode(drive);
  496. local_irq_restore(flags);
  497. return err;
  498. }
  499. /**
  500. * ide_dump_atapi_status - print human readable atapi status
  501. * @drive: drive that status applies to
  502. * @msg: text message to print
  503. * @stat: status byte to decode
  504. *
  505. * Error reporting, in human readable form (luxurious, but a memory hog).
  506. */
  507. static u8 ide_dump_atapi_status(ide_drive_t *drive, const char *msg, u8 stat)
  508. {
  509. unsigned long flags;
  510. atapi_status_t status;
  511. atapi_error_t error;
  512. status.all = stat;
  513. error.all = 0;
  514. local_irq_set(flags);
  515. printk("%s: %s: status=0x%02x { ", drive->name, msg, stat);
  516. if (status.b.bsy)
  517. printk("Busy ");
  518. else {
  519. if (status.b.drdy) printk("DriveReady ");
  520. if (status.b.df) printk("DeviceFault ");
  521. if (status.b.dsc) printk("SeekComplete ");
  522. if (status.b.drq) printk("DataRequest ");
  523. if (status.b.corr) printk("CorrectedError ");
  524. if (status.b.idx) printk("Index ");
  525. if (status.b.check) printk("Error ");
  526. }
  527. printk("}\n");
  528. if (status.b.check && !status.b.bsy) {
  529. error.all = HWIF(drive)->INB(IDE_ERROR_REG);
  530. printk("%s: %s: error=0x%02x { ", drive->name, msg, error.all);
  531. if (error.b.ili) printk("IllegalLengthIndication ");
  532. if (error.b.eom) printk("EndOfMedia ");
  533. if (error.b.abrt) printk("AbortedCommand ");
  534. if (error.b.mcr) printk("MediaChangeRequested ");
  535. if (error.b.sense_key) printk("LastFailedSense=0x%02x ",
  536. error.b.sense_key);
  537. printk("}\n");
  538. }
  539. ide_dump_opcode(drive);
  540. local_irq_restore(flags);
  541. return error.all;
  542. }
  543. /**
  544. * ide_dump_status - translate ATA/ATAPI error
  545. * @drive: drive the error occured on
  546. * @msg: information string
  547. * @stat: status byte
  548. *
  549. * Error reporting, in human readable form (luxurious, but a memory hog).
  550. * Combines the drive name, message and status byte to provide a
  551. * user understandable explanation of the device error.
  552. */
  553. u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
  554. {
  555. if (drive->media == ide_disk)
  556. return ide_dump_ata_status(drive, msg, stat);
  557. return ide_dump_atapi_status(drive, msg, stat);
  558. }
  559. EXPORT_SYMBOL(ide_dump_status);