ide: replace IDE_TFLAG_* flags by IDE_VALID_*
[linux-2.6] / drivers / ide / ide-lib.c
1 #include <linux/types.h>
2 #include <linux/string.h>
3 #include <linux/kernel.h>
4 #include <linux/interrupt.h>
5 #include <linux/ide.h>
6 #include <linux/bitops.h>
7
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  */
16
17 void ide_toggle_bounce(ide_drive_t *drive, int on)
18 {
19         u64 addr = BLK_BOUNCE_HIGH;     /* dma64_addr_t */
20
21         if (!PCI_DMA_BUS_IS_PHYS) {
22                 addr = BLK_BOUNCE_ANY;
23         } else if (on && drive->media == ide_disk) {
24                 struct device *dev = drive->hwif->dev;
25
26                 if (dev && dev->dma_mask)
27                         addr = *dev->dma_mask;
28         }
29
30         if (drive->queue)
31                 blk_queue_bounce_limit(drive->queue, addr);
32 }
33
34 static void ide_dump_opcode(ide_drive_t *drive)
35 {
36         struct request *rq = drive->hwif->rq;
37         struct ide_cmd *cmd = NULL;
38
39         if (!rq)
40                 return;
41
42         if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
43                 cmd = rq->special;
44
45         printk(KERN_ERR "ide: failed opcode was: ");
46         if (cmd == NULL)
47                 printk(KERN_CONT "unknown\n");
48         else
49                 printk(KERN_CONT "0x%02x\n", cmd->tf.command);
50 }
51
52 u64 ide_get_lba_addr(struct ide_taskfile *tf, int lba48)
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 }
65 EXPORT_SYMBOL_GPL(ide_get_lba_addr);
66
67 static void ide_dump_sector(ide_drive_t *drive)
68 {
69         struct ide_cmd cmd;
70         struct ide_taskfile *tf = &cmd.tf;
71         u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
72
73         memset(&cmd, 0, sizeof(cmd));
74         if (lba48) {
75                 cmd.valid.in.tf  = IDE_VALID_LBA;
76                 cmd.valid.in.hob = IDE_VALID_LBA;
77                 cmd.tf_flags = IDE_TFLAG_LBA48;
78         } else
79                 cmd.valid.in.tf  = IDE_VALID_LBA | IDE_VALID_DEVICE;
80
81         drive->hwif->tp_ops->tf_read(drive, &cmd);
82
83         if (lba48 || (tf->device & ATA_LBA))
84                 printk(KERN_CONT ", LBAsect=%llu",
85                         (unsigned long long)ide_get_lba_addr(tf, lba48));
86         else
87                 printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam,
88                         tf->device & 0xf, tf->lbal);
89 }
90
91 static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
92 {
93         printk(KERN_ERR "{ ");
94         if (err & ATA_ABORTED)
95                 printk(KERN_CONT "DriveStatusError ");
96         if (err & ATA_ICRC)
97                 printk(KERN_CONT "%s",
98                         (err & ATA_ABORTED) ? "BadCRC " : "BadSector ");
99         if (err & ATA_UNC)
100                 printk(KERN_CONT "UncorrectableError ");
101         if (err & ATA_IDNF)
102                 printk(KERN_CONT "SectorIdNotFound ");
103         if (err & ATA_TRK0NF)
104                 printk(KERN_CONT "TrackZeroNotFound ");
105         if (err & ATA_AMNF)
106                 printk(KERN_CONT "AddrMarkNotFound ");
107         printk(KERN_CONT "}");
108         if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK ||
109             (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) {
110                 struct request *rq = drive->hwif->rq;
111
112                 ide_dump_sector(drive);
113
114                 if (rq)
115                         printk(KERN_CONT ", sector=%llu",
116                                (unsigned long long)rq->sector);
117         }
118         printk(KERN_CONT "\n");
119 }
120
121 static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
122 {
123         printk(KERN_ERR "{ ");
124         if (err & ATAPI_ILI)
125                 printk(KERN_CONT "IllegalLengthIndication ");
126         if (err & ATAPI_EOM)
127                 printk(KERN_CONT "EndOfMedia ");
128         if (err & ATA_ABORTED)
129                 printk(KERN_CONT "AbortedCommand ");
130         if (err & ATA_MCR)
131                 printk(KERN_CONT "MediaChangeRequested ");
132         if (err & ATAPI_LFS)
133                 printk(KERN_CONT "LastFailedSense=0x%02x ",
134                         (err & ATAPI_LFS) >> 4);
135         printk(KERN_CONT "}\n");
136 }
137
138 /**
139  *      ide_dump_status         -       translate ATA/ATAPI error
140  *      @drive: drive that status applies to
141  *      @msg: text message to print
142  *      @stat: status byte to decode
143  *
144  *      Error reporting, in human readable form (luxurious, but a memory hog).
145  *      Combines the drive name, message and status byte to provide a
146  *      user understandable explanation of the device error.
147  */
148
149 u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
150 {
151         u8 err = 0;
152
153         printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat);
154         if (stat & ATA_BUSY)
155                 printk(KERN_CONT "Busy ");
156         else {
157                 if (stat & ATA_DRDY)
158                         printk(KERN_CONT "DriveReady ");
159                 if (stat & ATA_DF)
160                         printk(KERN_CONT "DeviceFault ");
161                 if (stat & ATA_DSC)
162                         printk(KERN_CONT "SeekComplete ");
163                 if (stat & ATA_DRQ)
164                         printk(KERN_CONT "DataRequest ");
165                 if (stat & ATA_CORR)
166                         printk(KERN_CONT "CorrectedError ");
167                 if (stat & ATA_IDX)
168                         printk(KERN_CONT "Index ");
169                 if (stat & ATA_ERR)
170                         printk(KERN_CONT "Error ");
171         }
172         printk(KERN_CONT "}\n");
173         if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) {
174                 err = ide_read_error(drive);
175                 printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err);
176                 if (drive->media == ide_disk)
177                         ide_dump_ata_error(drive, err);
178                 else
179                         ide_dump_atapi_error(drive, err);
180         }
181         ide_dump_opcode(drive);
182         return err;
183 }
184 EXPORT_SYMBOL(ide_dump_status);