Commit | Line | Data |
---|---|---|
457c8996 | 1 | // SPDX-License-Identifier: GPL-2.0-only |
1da177e4 LT |
2 | #include <linux/types.h> |
3 | #include <linux/string.h> | |
4 | #include <linux/kernel.h> | |
38789fda | 5 | #include <linux/export.h> |
1da177e4 | 6 | #include <linux/interrupt.h> |
1da177e4 LT |
7 | #include <linux/ide.h> |
8 | #include <linux/bitops.h> | |
9 | ||
745483f1 | 10 | u64 ide_get_lba_addr(struct ide_cmd *cmd, int lba48) |
c2b57cdc | 11 | { |
745483f1 | 12 | struct ide_taskfile *tf = &cmd->tf; |
c2b57cdc BZ |
13 | u32 high, low; |
14 | ||
c2b57cdc | 15 | low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal; |
745483f1 SS |
16 | if (lba48) { |
17 | tf = &cmd->hob; | |
18 | high = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal; | |
19 | } else | |
20 | high = tf->device & 0xf; | |
c2b57cdc BZ |
21 | |
22 | return ((u64)high << 24) | low; | |
23 | } | |
a501633c | 24 | EXPORT_SYMBOL_GPL(ide_get_lba_addr); |
c2b57cdc BZ |
25 | |
26 | static void ide_dump_sector(ide_drive_t *drive) | |
27 | { | |
22aa4b32 BZ |
28 | struct ide_cmd cmd; |
29 | struct ide_taskfile *tf = &cmd.tf; | |
97100fc8 | 30 | u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48); |
c2b57cdc | 31 | |
22aa4b32 | 32 | memset(&cmd, 0, sizeof(cmd)); |
60f85019 SS |
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; | |
c2b57cdc | 39 | |
3153c26b | 40 | ide_tf_readback(drive, &cmd); |
c2b57cdc BZ |
41 | |
42 | if (lba48 || (tf->device & ATA_LBA)) | |
2f996acb | 43 | printk(KERN_CONT ", LBAsect=%llu", |
745483f1 | 44 | (unsigned long long)ide_get_lba_addr(&cmd, lba48)); |
c2b57cdc | 45 | else |
2f996acb BZ |
46 | printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam, |
47 | tf->device & 0xf, tf->lbal); | |
c2b57cdc BZ |
48 | } |
49 | ||
e62925dd | 50 | static void ide_dump_ata_error(ide_drive_t *drive, u8 err) |
1da177e4 | 51 | { |
26bfcf21 | 52 | printk(KERN_CONT "{ "); |
2f996acb BZ |
53 | if (err & ATA_ABORTED) |
54 | printk(KERN_CONT "DriveStatusError "); | |
3a7d2484 | 55 | if (err & ATA_ICRC) |
2f996acb BZ |
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 "}"); | |
3a7d2484 BZ |
67 | if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK || |
68 | (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) { | |
b65fac32 BZ |
69 | struct request *rq = drive->hwif->rq; |
70 | ||
e62925dd | 71 | ide_dump_sector(drive); |
b65fac32 BZ |
72 | |
73 | if (rq) | |
2f996acb | 74 | printk(KERN_CONT ", sector=%llu", |
9780e2dd | 75 | (unsigned long long)blk_rq_pos(rq)); |
1da177e4 | 76 | } |
2f996acb | 77 | printk(KERN_CONT "\n"); |
e62925dd BZ |
78 | } |
79 | ||
80 | static void ide_dump_atapi_error(ide_drive_t *drive, u8 err) | |
81 | { | |
26bfcf21 | 82 | printk(KERN_CONT "{ "); |
2f996acb BZ |
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"); | |
1da177e4 LT |
95 | } |
96 | ||
97 | /** | |
e62925dd | 98 | * ide_dump_status - translate ATA/ATAPI error |
1da177e4 LT |
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). | |
e62925dd BZ |
104 | * Combines the drive name, message and status byte to provide a |
105 | * user understandable explanation of the device error. | |
1da177e4 LT |
106 | */ |
107 | ||
e62925dd | 108 | u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat) |
1da177e4 | 109 | { |
0e38a66a | 110 | u8 err = 0; |
1da177e4 | 111 | |
2f996acb | 112 | printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat); |
3a7d2484 | 113 | if (stat & ATA_BUSY) |
2f996acb | 114 | printk(KERN_CONT "Busy "); |
1da177e4 | 115 | else { |
2f996acb BZ |
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 "); | |
27f00e53 HR |
126 | if (stat & ATA_SENSE) |
127 | printk(KERN_CONT "Sense "); | |
2f996acb BZ |
128 | if (stat & ATA_ERR) |
129 | printk(KERN_CONT "Error "); | |
1da177e4 | 130 | } |
2f996acb | 131 | printk(KERN_CONT "}\n"); |
3a7d2484 | 132 | if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) { |
64a57fe4 | 133 | err = ide_read_error(drive); |
2f996acb | 134 | printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err); |
e62925dd BZ |
135 | if (drive->media == ide_disk) |
136 | ide_dump_ata_error(drive, err); | |
137 | else | |
138 | ide_dump_atapi_error(drive, err); | |
1da177e4 | 139 | } |
cc30137a BZ |
140 | |
141 | printk(KERN_ERR "%s: possibly failed opcode: 0x%02x\n", | |
142 | drive->name, drive->hwif->cmd.tf.command); | |
143 | ||
0e38a66a | 144 | return err; |
1da177e4 | 145 | } |
1da177e4 | 146 | EXPORT_SYMBOL(ide_dump_status); |