1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/types.h>
3 #include <linux/string.h>
4 #include <linux/kernel.h>
5 #include <linux/export.h>
6 #include <linux/interrupt.h>
8 #include <linux/bitops.h>
10 u64
ide_get_lba_addr(struct ide_cmd
*cmd
, int lba48
)
12 struct ide_taskfile
*tf
= &cmd
->tf
;
15 low
= (tf
->lbah
<< 16) | (tf
->lbam
<< 8) | tf
->lbal
;
18 high
= (tf
->lbah
<< 16) | (tf
->lbam
<< 8) | tf
->lbal
;
20 high
= tf
->device
& 0xf;
22 return ((u64
)high
<< 24) | low
;
24 EXPORT_SYMBOL_GPL(ide_get_lba_addr
);
26 static void ide_dump_sector(ide_drive_t
*drive
)
29 struct ide_taskfile
*tf
= &cmd
.tf
;
30 u8 lba48
= !!(drive
->dev_flags
& IDE_DFLAG_LBA48
);
32 memset(&cmd
, 0, sizeof(cmd
));
34 cmd
.valid
.in
.tf
= IDE_VALID_LBA
;
35 cmd
.valid
.in
.hob
= IDE_VALID_LBA
;
36 cmd
.tf_flags
= IDE_TFLAG_LBA48
;
38 cmd
.valid
.in
.tf
= IDE_VALID_LBA
| IDE_VALID_DEVICE
;
40 ide_tf_readback(drive
, &cmd
);
42 if (lba48
|| (tf
->device
& ATA_LBA
))
43 printk(KERN_CONT
", LBAsect=%llu",
44 (unsigned long long)ide_get_lba_addr(&cmd
, lba48
));
46 printk(KERN_CONT
", CHS=%d/%d/%d", (tf
->lbah
<< 8) + tf
->lbam
,
47 tf
->device
& 0xf, tf
->lbal
);
50 static void ide_dump_ata_error(ide_drive_t
*drive
, u8 err
)
52 printk(KERN_CONT
"{ ");
53 if (err
& ATA_ABORTED
)
54 printk(KERN_CONT
"DriveStatusError ");
56 printk(KERN_CONT
"%s",
57 (err
& ATA_ABORTED
) ? "BadCRC " : "BadSector ");
59 printk(KERN_CONT
"UncorrectableError ");
61 printk(KERN_CONT
"SectorIdNotFound ");
63 printk(KERN_CONT
"TrackZeroNotFound ");
65 printk(KERN_CONT
"AddrMarkNotFound ");
66 printk(KERN_CONT
"}");
67 if ((err
& (ATA_BBK
| ATA_ABORTED
)) == ATA_BBK
||
68 (err
& (ATA_UNC
| ATA_IDNF
| ATA_AMNF
))) {
69 struct request
*rq
= drive
->hwif
->rq
;
71 ide_dump_sector(drive
);
74 printk(KERN_CONT
", sector=%llu",
75 (unsigned long long)blk_rq_pos(rq
));
77 printk(KERN_CONT
"\n");
80 static void ide_dump_atapi_error(ide_drive_t
*drive
, u8 err
)
82 printk(KERN_CONT
"{ ");
84 printk(KERN_CONT
"IllegalLengthIndication ");
86 printk(KERN_CONT
"EndOfMedia ");
87 if (err
& ATA_ABORTED
)
88 printk(KERN_CONT
"AbortedCommand ");
90 printk(KERN_CONT
"MediaChangeRequested ");
92 printk(KERN_CONT
"LastFailedSense=0x%02x ",
93 (err
& ATAPI_LFS
) >> 4);
94 printk(KERN_CONT
"}\n");
98 * ide_dump_status - translate ATA/ATAPI error
99 * @drive: drive that status applies to
100 * @msg: text message to print
101 * @stat: status byte to decode
103 * Error reporting, in human readable form (luxurious, but a memory hog).
104 * Combines the drive name, message and status byte to provide a
105 * user understandable explanation of the device error.
108 u8
ide_dump_status(ide_drive_t
*drive
, const char *msg
, u8 stat
)
112 printk(KERN_ERR
"%s: %s: status=0x%02x { ", drive
->name
, msg
, stat
);
114 printk(KERN_CONT
"Busy ");
117 printk(KERN_CONT
"DriveReady ");
119 printk(KERN_CONT
"DeviceFault ");
121 printk(KERN_CONT
"SeekComplete ");
123 printk(KERN_CONT
"DataRequest ");
125 printk(KERN_CONT
"CorrectedError ");
126 if (stat
& ATA_SENSE
)
127 printk(KERN_CONT
"Sense ");
129 printk(KERN_CONT
"Error ");
131 printk(KERN_CONT
"}\n");
132 if ((stat
& (ATA_BUSY
| ATA_ERR
)) == ATA_ERR
) {
133 err
= ide_read_error(drive
);
134 printk(KERN_ERR
"%s: %s: error=0x%02x ", drive
->name
, msg
, err
);
135 if (drive
->media
== ide_disk
)
136 ide_dump_ata_error(drive
, err
);
138 ide_dump_atapi_error(drive
, err
);
141 printk(KERN_ERR
"%s: possibly failed opcode: 0x%02x\n",
142 drive
->name
, drive
->hwif
->cmd
.tf
.command
);
146 EXPORT_SYMBOL(ide_dump_status
);