1 #include <linux/types.h>
2 #include <linux/string.h>
3 #include <linux/kernel.h>
4 #include <linux/export.h>
5 #include <linux/interrupt.h>
7 #include <linux/bitops.h>
9 u64 ide_get_lba_addr(struct ide_cmd *cmd, int lba48)
11 struct ide_taskfile *tf = &cmd->tf;
14 low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
17 high = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
19 high = tf->device & 0xf;
21 return ((u64)high << 24) | low;
23 EXPORT_SYMBOL_GPL(ide_get_lba_addr);
25 static void ide_dump_sector(ide_drive_t *drive)
28 struct ide_taskfile *tf = &cmd.tf;
29 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
31 memset(&cmd, 0, sizeof(cmd));
33 cmd.valid.in.tf = IDE_VALID_LBA;
34 cmd.valid.in.hob = IDE_VALID_LBA;
35 cmd.tf_flags = IDE_TFLAG_LBA48;
37 cmd.valid.in.tf = IDE_VALID_LBA | IDE_VALID_DEVICE;
39 ide_tf_readback(drive, &cmd);
41 if (lba48 || (tf->device & ATA_LBA))
42 printk(KERN_CONT ", LBAsect=%llu",
43 (unsigned long long)ide_get_lba_addr(&cmd, lba48));
45 printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam,
46 tf->device & 0xf, tf->lbal);
49 static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
51 printk(KERN_CONT "{ ");
52 if (err & ATA_ABORTED)
53 printk(KERN_CONT "DriveStatusError ");
55 printk(KERN_CONT "%s",
56 (err & ATA_ABORTED) ? "BadCRC " : "BadSector ");
58 printk(KERN_CONT "UncorrectableError ");
60 printk(KERN_CONT "SectorIdNotFound ");
62 printk(KERN_CONT "TrackZeroNotFound ");
64 printk(KERN_CONT "AddrMarkNotFound ");
65 printk(KERN_CONT "}");
66 if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK ||
67 (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) {
68 struct request *rq = drive->hwif->rq;
70 ide_dump_sector(drive);
73 printk(KERN_CONT ", sector=%llu",
74 (unsigned long long)blk_rq_pos(rq));
76 printk(KERN_CONT "\n");
79 static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
81 printk(KERN_CONT "{ ");
83 printk(KERN_CONT "IllegalLengthIndication ");
85 printk(KERN_CONT "EndOfMedia ");
86 if (err & ATA_ABORTED)
87 printk(KERN_CONT "AbortedCommand ");
89 printk(KERN_CONT "MediaChangeRequested ");
91 printk(KERN_CONT "LastFailedSense=0x%02x ",
92 (err & ATAPI_LFS) >> 4);
93 printk(KERN_CONT "}\n");
97 * ide_dump_status - translate ATA/ATAPI error
98 * @drive: drive that status applies to
99 * @msg: text message to print
100 * @stat: status byte to decode
102 * Error reporting, in human readable form (luxurious, but a memory hog).
103 * Combines the drive name, message and status byte to provide a
104 * user understandable explanation of the device error.
107 u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
111 printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat);
113 printk(KERN_CONT "Busy ");
116 printk(KERN_CONT "DriveReady ");
118 printk(KERN_CONT "DeviceFault ");
120 printk(KERN_CONT "SeekComplete ");
122 printk(KERN_CONT "DataRequest ");
124 printk(KERN_CONT "CorrectedError ");
125 if (stat & ATA_SENSE)
126 printk(KERN_CONT "Sense ");
128 printk(KERN_CONT "Error ");
130 printk(KERN_CONT "}\n");
131 if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) {
132 err = ide_read_error(drive);
133 printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err);
134 if (drive->media == ide_disk)
135 ide_dump_ata_error(drive, err);
137 ide_dump_atapi_error(drive, err);
140 printk(KERN_ERR "%s: possibly failed opcode: 0x%02x\n",
141 drive->name, drive->hwif->cmd.tf.command);
145 EXPORT_SYMBOL(ide_dump_status);