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 */
22 if (!PCI_DMA_BUS_IS_PHYS) {
23 addr = BLK_BOUNCE_ANY;
24 } else if (on && drive->media == ide_disk) {
25 struct device *dev = drive->hwif->dev;
27 if (dev && dev->dma_mask)
28 addr = *dev->dma_mask;
32 blk_queue_bounce_limit(drive->queue, addr);
35 u64 ide_get_lba_addr(struct ide_cmd *cmd, int lba48)
37 struct ide_taskfile *tf = &cmd->tf;
40 low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
43 high = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
45 high = tf->device & 0xf;
47 return ((u64)high << 24) | low;
49 EXPORT_SYMBOL_GPL(ide_get_lba_addr);
51 static void ide_dump_sector(ide_drive_t *drive)
54 struct ide_taskfile *tf = &cmd.tf;
55 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
57 memset(&cmd, 0, sizeof(cmd));
59 cmd.valid.in.tf = IDE_VALID_LBA;
60 cmd.valid.in.hob = IDE_VALID_LBA;
61 cmd.tf_flags = IDE_TFLAG_LBA48;
63 cmd.valid.in.tf = IDE_VALID_LBA | IDE_VALID_DEVICE;
65 ide_tf_readback(drive, &cmd);
67 if (lba48 || (tf->device & ATA_LBA))
68 printk(KERN_CONT ", LBAsect=%llu",
69 (unsigned long long)ide_get_lba_addr(&cmd, lba48));
71 printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam,
72 tf->device & 0xf, tf->lbal);
75 static void ide_dump_ata_error(ide_drive_t *drive, u8 err)
77 printk(KERN_CONT "{ ");
78 if (err & ATA_ABORTED)
79 printk(KERN_CONT "DriveStatusError ");
81 printk(KERN_CONT "%s",
82 (err & ATA_ABORTED) ? "BadCRC " : "BadSector ");
84 printk(KERN_CONT "UncorrectableError ");
86 printk(KERN_CONT "SectorIdNotFound ");
88 printk(KERN_CONT "TrackZeroNotFound ");
90 printk(KERN_CONT "AddrMarkNotFound ");
91 printk(KERN_CONT "}");
92 if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK ||
93 (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) {
94 struct request *rq = drive->hwif->rq;
96 ide_dump_sector(drive);
99 printk(KERN_CONT ", sector=%llu",
100 (unsigned long long)blk_rq_pos(rq));
102 printk(KERN_CONT "\n");
105 static void ide_dump_atapi_error(ide_drive_t *drive, u8 err)
107 printk(KERN_CONT "{ ");
109 printk(KERN_CONT "IllegalLengthIndication ");
111 printk(KERN_CONT "EndOfMedia ");
112 if (err & ATA_ABORTED)
113 printk(KERN_CONT "AbortedCommand ");
115 printk(KERN_CONT "MediaChangeRequested ");
117 printk(KERN_CONT "LastFailedSense=0x%02x ",
118 (err & ATAPI_LFS) >> 4);
119 printk(KERN_CONT "}\n");
123 * ide_dump_status - translate ATA/ATAPI error
124 * @drive: drive that status applies to
125 * @msg: text message to print
126 * @stat: status byte to decode
128 * Error reporting, in human readable form (luxurious, but a memory hog).
129 * Combines the drive name, message and status byte to provide a
130 * user understandable explanation of the device error.
133 u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat)
137 printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat);
139 printk(KERN_CONT "Busy ");
142 printk(KERN_CONT "DriveReady ");
144 printk(KERN_CONT "DeviceFault ");
146 printk(KERN_CONT "SeekComplete ");
148 printk(KERN_CONT "DataRequest ");
150 printk(KERN_CONT "CorrectedError ");
151 if (stat & ATA_SENSE)
152 printk(KERN_CONT "Sense ");
154 printk(KERN_CONT "Error ");
156 printk(KERN_CONT "}\n");
157 if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) {
158 err = ide_read_error(drive);
159 printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err);
160 if (drive->media == ide_disk)
161 ide_dump_ata_error(drive, err);
163 ide_dump_atapi_error(drive, err);
166 printk(KERN_ERR "%s: possibly failed opcode: 0x%02x\n",
167 drive->name, drive->hwif->cmd.tf.command);
171 EXPORT_SYMBOL(ide_dump_status);