Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/types.h> |
| 2 | #include <linux/string.h> |
| 3 | #include <linux/kernel.h> |
Paul Gortmaker | 38789fd | 2011-07-17 15:33:58 -0400 | [diff] [blame] | 4 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/ide.h> |
| 7 | #include <linux/bitops.h> |
| 8 | |
Sergei Shtylyov | 745483f | 2009-04-08 14:13:02 +0200 | [diff] [blame] | 9 | u64 ide_get_lba_addr(struct ide_cmd *cmd, int lba48) |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 10 | { |
Sergei Shtylyov | 745483f | 2009-04-08 14:13:02 +0200 | [diff] [blame] | 11 | struct ide_taskfile *tf = &cmd->tf; |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 12 | u32 high, low; |
| 13 | |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 14 | low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal; |
Sergei Shtylyov | 745483f | 2009-04-08 14:13:02 +0200 | [diff] [blame] | 15 | if (lba48) { |
| 16 | tf = &cmd->hob; |
| 17 | high = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal; |
| 18 | } else |
| 19 | high = tf->device & 0xf; |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 20 | |
| 21 | return ((u64)high << 24) | low; |
| 22 | } |
Bartlomiej Zolnierkiewicz | a501633 | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 23 | EXPORT_SYMBOL_GPL(ide_get_lba_addr); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 24 | |
| 25 | static void ide_dump_sector(ide_drive_t *drive) |
| 26 | { |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 27 | struct ide_cmd cmd; |
| 28 | struct ide_taskfile *tf = &cmd.tf; |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 29 | u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 30 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 31 | memset(&cmd, 0, sizeof(cmd)); |
Sergei Shtylyov | 60f8501 | 2009-04-08 14:13:01 +0200 | [diff] [blame] | 32 | 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 Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 38 | |
Sergei Shtylyov | 3153c26 | 2009-04-08 14:13:03 +0200 | [diff] [blame] | 39 | ide_tf_readback(drive, &cmd); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 40 | |
| 41 | if (lba48 || (tf->device & ATA_LBA)) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 42 | printk(KERN_CONT ", LBAsect=%llu", |
Sergei Shtylyov | 745483f | 2009-04-08 14:13:02 +0200 | [diff] [blame] | 43 | (unsigned long long)ide_get_lba_addr(&cmd, lba48)); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 44 | else |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 45 | printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam, |
| 46 | tf->device & 0xf, tf->lbal); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 47 | } |
| 48 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 49 | static void ide_dump_ata_error(ide_drive_t *drive, u8 err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { |
Bartlomiej Zolnierkiewicz | 26bfcf2 | 2009-05-22 16:23:37 +0200 | [diff] [blame] | 51 | printk(KERN_CONT "{ "); |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 52 | if (err & ATA_ABORTED) |
| 53 | printk(KERN_CONT "DriveStatusError "); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 54 | if (err & ATA_ICRC) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 55 | 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 Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 66 | if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK || |
| 67 | (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) { |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 68 | struct request *rq = drive->hwif->rq; |
| 69 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 70 | ide_dump_sector(drive); |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 71 | |
| 72 | if (rq) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 73 | printk(KERN_CONT ", sector=%llu", |
Tejun Heo | 9780e2dd | 2009-05-07 22:24:40 +0900 | [diff] [blame] | 74 | (unsigned long long)blk_rq_pos(rq)); |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 75 | } |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 76 | printk(KERN_CONT "\n"); |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 77 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 79 | static void ide_dump_atapi_error(ide_drive_t *drive, u8 err) |
| 80 | { |
Bartlomiej Zolnierkiewicz | 26bfcf2 | 2009-05-22 16:23:37 +0200 | [diff] [blame] | 81 | printk(KERN_CONT "{ "); |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 82 | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /** |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 97 | * ide_dump_status - translate ATA/ATAPI error |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | * @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 Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 103 | * Combines the drive name, message and status byte to provide a |
| 104 | * user understandable explanation of the device error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | */ |
| 106 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 107 | u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | { |
Bartlomiej Zolnierkiewicz | 0e38a66 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 109 | u8 err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 111 | printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 112 | if (stat & ATA_BUSY) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 113 | printk(KERN_CONT "Busy "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | else { |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 115 | 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 Reinecke | 27f00e5 | 2015-03-27 16:46:33 +0100 | [diff] [blame] | 125 | if (stat & ATA_SENSE) |
| 126 | printk(KERN_CONT "Sense "); |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 127 | if (stat & ATA_ERR) |
| 128 | printk(KERN_CONT "Error "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 130 | printk(KERN_CONT "}\n"); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 131 | if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) { |
Bartlomiej Zolnierkiewicz | 64a57fe | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 132 | err = ide_read_error(drive); |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 133 | printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err); |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 134 | if (drive->media == ide_disk) |
| 135 | ide_dump_ata_error(drive, err); |
| 136 | else |
| 137 | ide_dump_atapi_error(drive, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
Bartlomiej Zolnierkiewicz | cc30137 | 2009-05-22 16:23:38 +0200 | [diff] [blame] | 139 | |
| 140 | printk(KERN_ERR "%s: possibly failed opcode: 0x%02x\n", |
| 141 | drive->name, drive->hwif->cmd.tf.command); |
| 142 | |
Bartlomiej Zolnierkiewicz | 0e38a66 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 143 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | EXPORT_SYMBOL(ide_dump_status); |