ide-lib.c 17 KB

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