blob: 78cb79eddc8b9f2bb9e491c977b9ae95bae7b992 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/types.h>
2#include <linux/string.h>
3#include <linux/kernel.h>
Paul Gortmaker38789fd2011-07-17 15:33:58 -04004#include <linux/export.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <linux/ide.h>
7#include <linux/bitops.h>
8
Sergei Shtylyov745483f2009-04-08 14:13:02 +02009u64 ide_get_lba_addr(struct ide_cmd *cmd, int lba48)
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +010010{
Sergei Shtylyov745483f2009-04-08 14:13:02 +020011 struct ide_taskfile *tf = &cmd->tf;
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +010012 u32 high, low;
13
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +010014 low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
Sergei Shtylyov745483f2009-04-08 14:13:02 +020015 if (lba48) {
16 tf = &cmd->hob;
17 high = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
18 } else
19 high = tf->device & 0xf;
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +010020
21 return ((u64)high << 24) | low;
22}
Bartlomiej Zolnierkiewicza5016332008-01-25 22:17:17 +010023EXPORT_SYMBOL_GPL(ide_get_lba_addr);
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +010024
25static void ide_dump_sector(ide_drive_t *drive)
26{
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010027 struct ide_cmd cmd;
28 struct ide_taskfile *tf = &cmd.tf;
Bartlomiej Zolnierkiewicz97100fc2008-10-13 21:39:36 +020029 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +010030
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010031 memset(&cmd, 0, sizeof(cmd));
Sergei Shtylyov60f85012009-04-08 14:13:01 +020032 if (lba48) {
33 cmd.valid.in.tf = IDE_VALID_LBA;
34 cmd.valid.in.hob = IDE_VALID_LBA;
35 cmd.tf_flags = IDE_TFLAG_LBA48;
36 } else
37 cmd.valid.in.tf = IDE_VALID_LBA | IDE_VALID_DEVICE;
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +010038
Sergei Shtylyov3153c262009-04-08 14:13:03 +020039 ide_tf_readback(drive, &cmd);
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +010040
41 if (lba48 || (tf->device & ATA_LBA))
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +010042 printk(KERN_CONT ", LBAsect=%llu",
Sergei Shtylyov745483f2009-04-08 14:13:02 +020043 (unsigned long long)ide_get_lba_addr(&cmd, lba48));
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +010044 else
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +010045 printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam,
46 tf->device & 0xf, tf->lbal);
Bartlomiej Zolnierkiewiczc2b57cd2008-01-25 22:17:17 +010047}
48
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +010049static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
Bartlomiej Zolnierkiewicz26bfcf22009-05-22 16:23:37 +020051 printk(KERN_CONT "{ ");
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +010052 if (err & ATA_ABORTED)
53 printk(KERN_CONT "DriveStatusError ");
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +020054 if (err & ATA_ICRC)
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +010055 printk(KERN_CONT "%s",
56 (err & ATA_ABORTED) ? "BadCRC " : "BadSector ");
57 if (err & ATA_UNC)
58 printk(KERN_CONT "UncorrectableError ");
59 if (err & ATA_IDNF)
60 printk(KERN_CONT "SectorIdNotFound ");
61 if (err & ATA_TRK0NF)
62 printk(KERN_CONT "TrackZeroNotFound ");
63 if (err & ATA_AMNF)
64 printk(KERN_CONT "AddrMarkNotFound ");
65 printk(KERN_CONT "}");
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +020066 if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK ||
67 (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) {
Bartlomiej Zolnierkiewiczb65fac32009-01-06 17:20:50 +010068 struct request *rq = drive->hwif->rq;
69
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +010070 ide_dump_sector(drive);
Bartlomiej Zolnierkiewiczb65fac32009-01-06 17:20:50 +010071
72 if (rq)
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +010073 printk(KERN_CONT ", sector=%llu",
Tejun Heo9780e2dd2009-05-07 22:24:40 +090074 (unsigned long long)blk_rq_pos(rq));
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +010075 }
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +010076 printk(KERN_CONT "\n");
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +010077}
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +010079static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
80{
Bartlomiej Zolnierkiewicz26bfcf22009-05-22 16:23:37 +020081 printk(KERN_CONT "{ ");
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +010082 if (err & ATAPI_ILI)
83 printk(KERN_CONT "IllegalLengthIndication ");
84 if (err & ATAPI_EOM)
85 printk(KERN_CONT "EndOfMedia ");
86 if (err & ATA_ABORTED)
87 printk(KERN_CONT "AbortedCommand ");
88 if (err & ATA_MCR)
89 printk(KERN_CONT "MediaChangeRequested ");
90 if (err & ATAPI_LFS)
91 printk(KERN_CONT "LastFailedSense=0x%02x ",
92 (err & ATAPI_LFS) >> 4);
93 printk(KERN_CONT "}\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070094}
95
96/**
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +010097 * ide_dump_status - translate ATA/ATAPI error
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 * @drive: drive that status applies to
99 * @msg: text message to print
100 * @stat: status byte to decode
101 *
102 * Error reporting, in human readable form (luxurious, but a memory hog).
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100103 * Combines the drive name, message and status byte to provide a
104 * user understandable explanation of the device error.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 */
106
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100107u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
Bartlomiej Zolnierkiewicz0e38a662008-01-25 22:17:12 +0100109 u8 err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100111 printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat);
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200112 if (stat & ATA_BUSY)
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100113 printk(KERN_CONT "Busy ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 else {
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100115 if (stat & ATA_DRDY)
116 printk(KERN_CONT "DriveReady ");
117 if (stat & ATA_DF)
118 printk(KERN_CONT "DeviceFault ");
119 if (stat & ATA_DSC)
120 printk(KERN_CONT "SeekComplete ");
121 if (stat & ATA_DRQ)
122 printk(KERN_CONT "DataRequest ");
123 if (stat & ATA_CORR)
124 printk(KERN_CONT "CorrectedError ");
Hannes Reinecke27f00e52015-03-27 16:46:33 +0100125 if (stat & ATA_SENSE)
126 printk(KERN_CONT "Sense ");
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100127 if (stat & ATA_ERR)
128 printk(KERN_CONT "Error ");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 }
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100130 printk(KERN_CONT "}\n");
Bartlomiej Zolnierkiewicz3a7d2482008-10-10 22:39:21 +0200131 if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) {
Bartlomiej Zolnierkiewicz64a57fe2008-02-06 02:57:51 +0100132 err = ide_read_error(drive);
Bartlomiej Zolnierkiewicz2f996ac2008-12-29 20:27:36 +0100133 printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err);
Bartlomiej Zolnierkiewicze62925d2008-01-25 22:17:17 +0100134 if (drive->media == ide_disk)
135 ide_dump_ata_error(drive, err);
136 else
137 ide_dump_atapi_error(drive, err);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 }
Bartlomiej Zolnierkiewiczcc301372009-05-22 16:23:38 +0200139
140 printk(KERN_ERR "%s: possibly failed opcode: 0x%02x\n",
141 drive->name, drive->hwif->cmd.tf.command);
142
Bartlomiej Zolnierkiewicz0e38a662008-01-25 22:17:12 +0100143 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145EXPORT_SYMBOL(ide_dump_status);