ide-lib.c 16 KB

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