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