ide-lib.c 17 KB

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