1 #include <linux/types.h>
2 #include <linux/string.h>
3 #include <linux/kernel.h>
4 #include <linux/export.h>
5 #include <linux/interrupt.h>
7 #include <linux/bitops.h>
10 * ide_toggle_bounce - handle bounce buffering
11 * @drive: drive to update
14 * Enable or disable bounce buffering for the device. Drives move
15 * between PIO and DMA and that changes the rules we need.
18 void ide_toggle_bounce(ide_drive_t *drive, int on)
20 u64 addr = BLK_BOUNCE_HIGH; /* dma64_addr_t */
23 if (!PCI_DMA_BUS_IS_PHYS) {
24 addr = BLK_BOUNCE_ANY;
25 } else if (on && drive->media == ide_disk) {
26 struct device *dev = drive->hwif->dev;
28 if (dev && dev->dma_mask)
29 addr = *dev->dma_mask;
32 if (on && drive->media == ide_disk) {
33 struct device *dev = drive->hwif->dev;
35 if (!PCI_DMA_BUS_IS_PHYS)
36 addr = BLK_BOUNCE_ANY;
37 else if (dev && dev->dma_mask)
38 addr = *dev->dma_mask;
43 blk_queue_bounce_limit(drive->queue, addr);
46 u64 ide_get_lba_addr(struct ide_cmd *cmd, int lba48)
48 struct ide_taskfile *tf = &cmd->tf;
51 low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
54 high = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
56 high = tf->device & 0xf;
58 return ((u64)high << 24) | low;
60 EXPORT_SYMBOL_GPL(ide_get_lba_addr);
62 static void ide_dump_sector(ide_drive_t *drive)
65 struct ide_taskfile *tf = &cmd.tf;
66 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
68 memset(&cmd, 0, sizeof(cmd));
70 cmd.valid.in.tf = IDE_VALID_LBA;
71 cmd.valid.in.hob = IDE_VALID_LBA;
72 cmd.tf_flags = IDE_TFLAG_LBA48;
74 cmd.valid.in.tf = IDE_VALID_LBA | IDE_VALID_DEVICE;
76 ide_tf_readback(drive, &cmd);
78 if (lba48 || (tf->device & ATA_LBA))
79 printk(KERN_CONT ", LBAsect=%llu",
80 (unsigned long long)ide_get_lba_addr(&cmd, lba48));
82 printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam,
83 tf->device & 0xf, tf->lbal);
86 static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
88 printk(KERN_CONT "{ ");
89 if (err & ATA_ABORTED)
90 printk(KERN_CONT "DriveStatusError ");
92 printk(KERN_CONT "%s",
93 (err & ATA_ABORTED) ? "BadCRC " : "BadSector ");
95 printk(KERN_CONT "UncorrectableError ");
97 printk(KERN_CONT "SectorIdNotFound ");
99 printk(KERN_CONT "TrackZeroNotFound ");
101 printk(KERN_CONT "AddrMarkNotFound ");
102 printk(KERN_CONT "}");
103 if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK ||
104 (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) {
105 struct request *rq = drive->hwif->rq;
107 ide_dump_sector(drive);
110 printk(KERN_CONT ", sector=%llu",
111 (unsigned long long)blk_rq_pos(rq));
113 printk(KERN_CONT "\n");
116 static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
118 printk(KERN_CONT "{ ");
120 printk(KERN_CONT "IllegalLengthIndication ");
122 printk(KERN_CONT "EndOfMedia ");
123 if (err & ATA_ABORTED)
124 printk(KERN_CONT "AbortedCommand ");
126 printk(KERN_CONT "MediaChangeRequested ");
128 printk(KERN_CONT "LastFailedSense=0x%02x ",
129 (err & ATAPI_LFS) >> 4);
130 printk(KERN_CONT "}\n");
134 * ide_dump_status - translate ATA/ATAPI error
135 * @drive: drive that status applies to
136 * @msg: text message to print
137 * @stat: status byte to decode
139 * Error reporting, in human readable form (luxurious, but a memory hog).
140 * Combines the drive name, message and status byte to provide a
141 * user understandable explanation of the device error.
144 u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
148 printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat);
150 printk(KERN_CONT "Busy ");
153 printk(KERN_CONT "DriveReady ");
155 printk(KERN_CONT "DeviceFault ");
157 printk(KERN_CONT "SeekComplete ");
159 printk(KERN_CONT "DataRequest ");
161 printk(KERN_CONT "CorrectedError ");
163 printk(KERN_CONT "Index ");
165 printk(KERN_CONT "Error ");
167 printk(KERN_CONT "}\n");
168 if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) {
169 err = ide_read_error(drive);
170 printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err);
171 if (drive->media == ide_disk)
172 ide_dump_ata_error(drive, err);
174 ide_dump_atapi_error(drive, err);
177 printk(KERN_ERR "%s: possibly failed opcode: 0x%02x\n",
178 drive->name, drive->hwif->cmd.tf.command);
182 EXPORT_SYMBOL(ide_dump_status);