ide-cd: fix intendation in cdrom_decode_status()
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / ide / ide-lib.c
CommitLineData
1da177e4
LT
1#include <linux/types.h>
2#include <linux/string.h>
3#include <linux/kernel.h>
1da177e4 4#include <linux/interrupt.h>
1da177e4
LT
5#include <linux/ide.h>
6#include <linux/bitops.h>
7
1da177e4
LT
8/**
9 * ide_toggle_bounce - handle bounce buffering
10 * @drive: drive to update
11 * @on: on/off boolean
12 *
13 * Enable or disable bounce buffering for the device. Drives move
14 * between PIO and DMA and that changes the rules we need.
15 */
2f996acb 16
1da177e4
LT
17void ide_toggle_bounce(ide_drive_t *drive, int on)
18{
19 u64 addr = BLK_BOUNCE_HIGH; /* dma64_addr_t */
20
6593178d
JB
21 if (!PCI_DMA_BUS_IS_PHYS) {
22 addr = BLK_BOUNCE_ANY;
23 } else if (on && drive->media == ide_disk) {
36501650
BZ
24 struct device *dev = drive->hwif->dev;
25
26 if (dev && dev->dma_mask)
27 addr = *dev->dma_mask;
1da177e4
LT
28 }
29
30 if (drive->queue)
31 blk_queue_bounce_limit(drive->queue, addr);
32}
33
1da177e4
LT
34static void ide_dump_opcode(ide_drive_t *drive)
35{
b65fac32 36 struct request *rq = drive->hwif->rq;
22aa4b32 37 struct ide_cmd *cmd = NULL;
1da177e4 38
1da177e4
LT
39 if (!rq)
40 return;
7267c337
BZ
41
42 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
22aa4b32 43 cmd = rq->special;
1da177e4 44
2f996acb 45 printk(KERN_ERR "ide: failed opcode was: ");
22aa4b32 46 if (cmd == NULL)
7267c337 47 printk(KERN_CONT "unknown\n");
1da177e4 48 else
22aa4b32 49 printk(KERN_CONT "0x%02x\n", cmd->tf.command);
1da177e4
LT
50}
51
a501633c 52u64 ide_get_lba_addr(struct ide_taskfile *tf, int lba48)
c2b57cdc
BZ
53{
54 u32 high, low;
55
56 if (lba48)
57 high = (tf->hob_lbah << 16) | (tf->hob_lbam << 8) |
58 tf->hob_lbal;
59 else
60 high = tf->device & 0xf;
61 low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
62
63 return ((u64)high << 24) | low;
64}
a501633c 65EXPORT_SYMBOL_GPL(ide_get_lba_addr);
c2b57cdc
BZ
66
67static void ide_dump_sector(ide_drive_t *drive)
68{
22aa4b32
BZ
69 struct ide_cmd cmd;
70 struct ide_taskfile *tf = &cmd.tf;
97100fc8 71 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
c2b57cdc 72
22aa4b32 73 memset(&cmd, 0, sizeof(cmd));
c2b57cdc 74 if (lba48)
22aa4b32 75 cmd.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_HOB_LBA |
c2b57cdc
BZ
76 IDE_TFLAG_LBA48;
77 else
22aa4b32 78 cmd.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_DEVICE;
c2b57cdc 79
22aa4b32 80 drive->hwif->tp_ops->tf_read(drive, &cmd);
c2b57cdc
BZ
81
82 if (lba48 || (tf->device & ATA_LBA))
2f996acb 83 printk(KERN_CONT ", LBAsect=%llu",
1c904fcf 84 (unsigned long long)ide_get_lba_addr(tf, lba48));
c2b57cdc 85 else
2f996acb
BZ
86 printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam,
87 tf->device & 0xf, tf->lbal);
c2b57cdc
BZ
88}
89
e62925dd 90static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
1da177e4 91{
2f996acb
BZ
92 printk(KERN_ERR "{ ");
93 if (err & ATA_ABORTED)
94 printk(KERN_CONT "DriveStatusError ");
3a7d2484 95 if (err & ATA_ICRC)
2f996acb
BZ
96 printk(KERN_CONT "%s",
97 (err & ATA_ABORTED) ? "BadCRC " : "BadSector ");
98 if (err & ATA_UNC)
99 printk(KERN_CONT "UncorrectableError ");
100 if (err & ATA_IDNF)
101 printk(KERN_CONT "SectorIdNotFound ");
102 if (err & ATA_TRK0NF)
103 printk(KERN_CONT "TrackZeroNotFound ");
104 if (err & ATA_AMNF)
105 printk(KERN_CONT "AddrMarkNotFound ");
106 printk(KERN_CONT "}");
3a7d2484
BZ
107 if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK ||
108 (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) {
b65fac32
BZ
109 struct request *rq = drive->hwif->rq;
110
e62925dd 111 ide_dump_sector(drive);
b65fac32
BZ
112
113 if (rq)
2f996acb 114 printk(KERN_CONT ", sector=%llu",
b65fac32 115 (unsigned long long)rq->sector);
1da177e4 116 }
2f996acb 117 printk(KERN_CONT "\n");
e62925dd
BZ
118}
119
120static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
121{
2f996acb
BZ
122 printk(KERN_ERR "{ ");
123 if (err & ATAPI_ILI)
124 printk(KERN_CONT "IllegalLengthIndication ");
125 if (err & ATAPI_EOM)
126 printk(KERN_CONT "EndOfMedia ");
127 if (err & ATA_ABORTED)
128 printk(KERN_CONT "AbortedCommand ");
129 if (err & ATA_MCR)
130 printk(KERN_CONT "MediaChangeRequested ");
131 if (err & ATAPI_LFS)
132 printk(KERN_CONT "LastFailedSense=0x%02x ",
133 (err & ATAPI_LFS) >> 4);
134 printk(KERN_CONT "}\n");
1da177e4
LT
135}
136
137/**
e62925dd 138 * ide_dump_status - translate ATA/ATAPI error
1da177e4
LT
139 * @drive: drive that status applies to
140 * @msg: text message to print
141 * @stat: status byte to decode
142 *
143 * Error reporting, in human readable form (luxurious, but a memory hog).
e62925dd
BZ
144 * Combines the drive name, message and status byte to provide a
145 * user understandable explanation of the device error.
1da177e4
LT
146 */
147
e62925dd 148u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
1da177e4 149{
0e38a66a 150 u8 err = 0;
1da177e4 151
2f996acb 152 printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat);
3a7d2484 153 if (stat & ATA_BUSY)
2f996acb 154 printk(KERN_CONT "Busy ");
1da177e4 155 else {
2f996acb
BZ
156 if (stat & ATA_DRDY)
157 printk(KERN_CONT "DriveReady ");
158 if (stat & ATA_DF)
159 printk(KERN_CONT "DeviceFault ");
160 if (stat & ATA_DSC)
161 printk(KERN_CONT "SeekComplete ");
162 if (stat & ATA_DRQ)
163 printk(KERN_CONT "DataRequest ");
164 if (stat & ATA_CORR)
165 printk(KERN_CONT "CorrectedError ");
166 if (stat & ATA_IDX)
167 printk(KERN_CONT "Index ");
168 if (stat & ATA_ERR)
169 printk(KERN_CONT "Error ");
1da177e4 170 }
2f996acb 171 printk(KERN_CONT "}\n");
3a7d2484 172 if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) {
64a57fe4 173 err = ide_read_error(drive);
2f996acb 174 printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err);
e62925dd
BZ
175 if (drive->media == ide_disk)
176 ide_dump_ata_error(drive, err);
177 else
178 ide_dump_atapi_error(drive, err);
1da177e4
LT
179 }
180 ide_dump_opcode(drive);
0e38a66a 181 return err;
1da177e4 182}
1da177e4 183EXPORT_SYMBOL(ide_dump_status);