Thomas Gleixner | 457c899 | 2019-05-19 13:08:55 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | #include <linux/types.h> |
| 3 | #include <linux/string.h> |
| 4 | #include <linux/kernel.h> |
Paul Gortmaker | 38789fd | 2011-07-17 15:33:58 -0400 | [diff] [blame] | 5 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include <linux/ide.h> |
| 8 | #include <linux/bitops.h> |
| 9 | |
Sergei Shtylyov | 745483f | 2009-04-08 14:13:02 +0200 | [diff] [blame] | 10 | u64 ide_get_lba_addr(struct ide_cmd *cmd, int lba48) |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 11 | { |
Sergei Shtylyov | 745483f | 2009-04-08 14:13:02 +0200 | [diff] [blame] | 12 | struct ide_taskfile *tf = &cmd->tf; |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 13 | u32 high, low; |
| 14 | |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 15 | low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal; |
Sergei Shtylyov | 745483f | 2009-04-08 14:13:02 +0200 | [diff] [blame] | 16 | if (lba48) { |
| 17 | tf = &cmd->hob; |
| 18 | high = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal; |
| 19 | } else |
| 20 | high = tf->device & 0xf; |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 21 | |
| 22 | return ((u64)high << 24) | low; |
| 23 | } |
Bartlomiej Zolnierkiewicz | a501633 | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 24 | EXPORT_SYMBOL_GPL(ide_get_lba_addr); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 25 | |
| 26 | static void ide_dump_sector(ide_drive_t *drive) |
| 27 | { |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 28 | struct ide_cmd cmd; |
| 29 | struct ide_taskfile *tf = &cmd.tf; |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 30 | u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 31 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 32 | memset(&cmd, 0, sizeof(cmd)); |
Sergei Shtylyov | 60f8501 | 2009-04-08 14:13:01 +0200 | [diff] [blame] | 33 | if (lba48) { |
| 34 | cmd.valid.in.tf = IDE_VALID_LBA; |
| 35 | cmd.valid.in.hob = IDE_VALID_LBA; |
| 36 | cmd.tf_flags = IDE_TFLAG_LBA48; |
| 37 | } else |
| 38 | cmd.valid.in.tf = IDE_VALID_LBA | IDE_VALID_DEVICE; |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 39 | |
Sergei Shtylyov | 3153c26 | 2009-04-08 14:13:03 +0200 | [diff] [blame] | 40 | ide_tf_readback(drive, &cmd); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 41 | |
| 42 | if (lba48 || (tf->device & ATA_LBA)) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 43 | printk(KERN_CONT ", LBAsect=%llu", |
Sergei Shtylyov | 745483f | 2009-04-08 14:13:02 +0200 | [diff] [blame] | 44 | (unsigned long long)ide_get_lba_addr(&cmd, lba48)); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 45 | else |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 46 | printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam, |
| 47 | tf->device & 0xf, tf->lbal); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 48 | } |
| 49 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 50 | static void ide_dump_ata_error(ide_drive_t *drive, u8 err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
Bartlomiej Zolnierkiewicz | 26bfcf2 | 2009-05-22 16:23:37 +0200 | [diff] [blame] | 52 | printk(KERN_CONT "{ "); |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 53 | if (err & ATA_ABORTED) |
| 54 | printk(KERN_CONT "DriveStatusError "); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 55 | if (err & ATA_ICRC) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 56 | printk(KERN_CONT "%s", |
| 57 | (err & ATA_ABORTED) ? "BadCRC " : "BadSector "); |
| 58 | if (err & ATA_UNC) |
| 59 | printk(KERN_CONT "UncorrectableError "); |
| 60 | if (err & ATA_IDNF) |
| 61 | printk(KERN_CONT "SectorIdNotFound "); |
| 62 | if (err & ATA_TRK0NF) |
| 63 | printk(KERN_CONT "TrackZeroNotFound "); |
| 64 | if (err & ATA_AMNF) |
| 65 | printk(KERN_CONT "AddrMarkNotFound "); |
| 66 | printk(KERN_CONT "}"); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 67 | if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK || |
| 68 | (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) { |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 69 | struct request *rq = drive->hwif->rq; |
| 70 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 71 | ide_dump_sector(drive); |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 72 | |
| 73 | if (rq) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 74 | printk(KERN_CONT ", sector=%llu", |
Tejun Heo | 9780e2dd | 2009-05-07 22:24:40 +0900 | [diff] [blame] | 75 | (unsigned long long)blk_rq_pos(rq)); |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 76 | } |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 77 | printk(KERN_CONT "\n"); |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 78 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 80 | static void ide_dump_atapi_error(ide_drive_t *drive, u8 err) |
| 81 | { |
Bartlomiej Zolnierkiewicz | 26bfcf2 | 2009-05-22 16:23:37 +0200 | [diff] [blame] | 82 | printk(KERN_CONT "{ "); |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 83 | if (err & ATAPI_ILI) |
| 84 | printk(KERN_CONT "IllegalLengthIndication "); |
| 85 | if (err & ATAPI_EOM) |
| 86 | printk(KERN_CONT "EndOfMedia "); |
| 87 | if (err & ATA_ABORTED) |
| 88 | printk(KERN_CONT "AbortedCommand "); |
| 89 | if (err & ATA_MCR) |
| 90 | printk(KERN_CONT "MediaChangeRequested "); |
| 91 | if (err & ATAPI_LFS) |
| 92 | printk(KERN_CONT "LastFailedSense=0x%02x ", |
| 93 | (err & ATAPI_LFS) >> 4); |
| 94 | printk(KERN_CONT "}\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /** |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 98 | * ide_dump_status - translate ATA/ATAPI error |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | * @drive: drive that status applies to |
| 100 | * @msg: text message to print |
| 101 | * @stat: status byte to decode |
| 102 | * |
| 103 | * Error reporting, in human readable form (luxurious, but a memory hog). |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 104 | * Combines the drive name, message and status byte to provide a |
| 105 | * user understandable explanation of the device error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | */ |
| 107 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 108 | 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] | 109 | { |
Bartlomiej Zolnierkiewicz | 0e38a66 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 110 | u8 err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 112 | printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 113 | if (stat & ATA_BUSY) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 114 | printk(KERN_CONT "Busy "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | else { |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 116 | if (stat & ATA_DRDY) |
| 117 | printk(KERN_CONT "DriveReady "); |
| 118 | if (stat & ATA_DF) |
| 119 | printk(KERN_CONT "DeviceFault "); |
| 120 | if (stat & ATA_DSC) |
| 121 | printk(KERN_CONT "SeekComplete "); |
| 122 | if (stat & ATA_DRQ) |
| 123 | printk(KERN_CONT "DataRequest "); |
| 124 | if (stat & ATA_CORR) |
| 125 | printk(KERN_CONT "CorrectedError "); |
Hannes Reinecke | 27f00e5 | 2015-03-27 16:46:33 +0100 | [diff] [blame] | 126 | if (stat & ATA_SENSE) |
| 127 | printk(KERN_CONT "Sense "); |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 128 | if (stat & ATA_ERR) |
| 129 | printk(KERN_CONT "Error "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 131 | printk(KERN_CONT "}\n"); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 132 | if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) { |
Bartlomiej Zolnierkiewicz | 64a57fe | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 133 | err = ide_read_error(drive); |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 134 | printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err); |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 135 | if (drive->media == ide_disk) |
| 136 | ide_dump_ata_error(drive, err); |
| 137 | else |
| 138 | ide_dump_atapi_error(drive, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
Bartlomiej Zolnierkiewicz | cc30137 | 2009-05-22 16:23:38 +0200 | [diff] [blame] | 140 | |
| 141 | printk(KERN_ERR "%s: possibly failed opcode: 0x%02x\n", |
| 142 | drive->name, drive->hwif->cmd.tf.command); |
| 143 | |
Bartlomiej Zolnierkiewicz | 0e38a66 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 144 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | EXPORT_SYMBOL(ide_dump_status); |