Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 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> |
| 6 | #include <linux/ide.h> |
| 7 | #include <linux/bitops.h> |
| 8 | |
| 9 | u64 ide_get_lba_addr(struct ide_cmd *cmd, int lba48) |
| 10 | { |
| 11 | struct ide_taskfile *tf = &cmd->tf; |
| 12 | u32 high, low; |
| 13 | |
| 14 | low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal; |
| 15 | if (lba48) { |
| 16 | tf = &cmd->hob; |
| 17 | high = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal; |
| 18 | } else |
| 19 | high = tf->device & 0xf; |
| 20 | |
| 21 | return ((u64)high << 24) | low; |
| 22 | } |
| 23 | EXPORT_SYMBOL_GPL(ide_get_lba_addr); |
| 24 | |
| 25 | static void ide_dump_sector(ide_drive_t *drive) |
| 26 | { |
| 27 | struct ide_cmd cmd; |
| 28 | struct ide_taskfile *tf = &cmd.tf; |
| 29 | u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48); |
| 30 | |
| 31 | memset(&cmd, 0, sizeof(cmd)); |
| 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; |
| 38 | |
| 39 | ide_tf_readback(drive, &cmd); |
| 40 | |
| 41 | if (lba48 || (tf->device & ATA_LBA)) |
| 42 | printk(KERN_CONT ", LBAsect=%llu", |
| 43 | (unsigned long long)ide_get_lba_addr(&cmd, lba48)); |
| 44 | else |
| 45 | printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam, |
| 46 | tf->device & 0xf, tf->lbal); |
| 47 | } |
| 48 | |
| 49 | static void ide_dump_ata_error(ide_drive_t *drive, u8 err) |
| 50 | { |
| 51 | printk(KERN_CONT "{ "); |
| 52 | if (err & ATA_ABORTED) |
| 53 | printk(KERN_CONT "DriveStatusError "); |
| 54 | if (err & ATA_ICRC) |
| 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 "}"); |
| 66 | if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK || |
| 67 | (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) { |
| 68 | struct request *rq = drive->hwif->rq; |
| 69 | |
| 70 | ide_dump_sector(drive); |
| 71 | |
| 72 | if (rq) |
| 73 | printk(KERN_CONT ", sector=%llu", |
| 74 | (unsigned long long)blk_rq_pos(rq)); |
| 75 | } |
| 76 | printk(KERN_CONT "\n"); |
| 77 | } |
| 78 | |
| 79 | static void ide_dump_atapi_error(ide_drive_t *drive, u8 err) |
| 80 | { |
| 81 | printk(KERN_CONT "{ "); |
| 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"); |
| 94 | } |
| 95 | |
| 96 | /** |
| 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 |
| 101 | * |
| 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. |
| 105 | */ |
| 106 | |
| 107 | u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat) |
| 108 | { |
| 109 | u8 err = 0; |
| 110 | |
| 111 | printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat); |
| 112 | if (stat & ATA_BUSY) |
| 113 | printk(KERN_CONT "Busy "); |
| 114 | else { |
| 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 "); |
| 125 | if (stat & ATA_SENSE) |
| 126 | printk(KERN_CONT "Sense "); |
| 127 | if (stat & ATA_ERR) |
| 128 | printk(KERN_CONT "Error "); |
| 129 | } |
| 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); |
| 136 | else |
| 137 | ide_dump_atapi_error(drive, err); |
| 138 | } |
| 139 | |
| 140 | printk(KERN_ERR "%s: possibly failed opcode: 0x%02x\n", |
| 141 | drive->name, drive->hwif->cmd.tf.command); |
| 142 | |
| 143 | return err; |
| 144 | } |
| 145 | EXPORT_SYMBOL(ide_dump_status); |