1 #include <linux/types.h>
2 #include <linux/string.h>
3 #include <linux/kernel.h>
4 #include <linux/interrupt.h>
6 #include <linux/bitops.h>
9 * ide_toggle_bounce - handle bounce buffering
10 * @drive: drive to update
13 * Enable or disable bounce buffering for the device. Drives move
14 * between PIO and DMA and that changes the rules we need.
17 void ide_toggle_bounce(ide_drive_t
*drive
, int on
)
19 u64 addr
= BLK_BOUNCE_HIGH
; /* dma64_addr_t */
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
;
26 if (dev
&& dev
->dma_mask
)
27 addr
= *dev
->dma_mask
;
31 blk_queue_bounce_limit(drive
->queue
, addr
);
34 static void ide_dump_opcode(ide_drive_t
*drive
)
36 struct request
*rq
= drive
->hwif
->rq
;
37 struct ide_cmd
*cmd
= NULL
;
42 if (rq
->cmd_type
== REQ_TYPE_ATA_TASKFILE
)
45 printk(KERN_ERR
"ide: failed opcode was: ");
47 printk(KERN_CONT
"unknown\n");
49 printk(KERN_CONT
"0x%02x\n", cmd
->tf
.command
);
52 u64
ide_get_lba_addr(struct ide_cmd
*cmd
, int lba48
)
54 struct ide_taskfile
*tf
= &cmd
->tf
;
57 low
= (tf
->lbah
<< 16) | (tf
->lbam
<< 8) | tf
->lbal
;
60 high
= (tf
->lbah
<< 16) | (tf
->lbam
<< 8) | tf
->lbal
;
62 high
= tf
->device
& 0xf;
64 return ((u64
)high
<< 24) | low
;
66 EXPORT_SYMBOL_GPL(ide_get_lba_addr
);
68 static void ide_dump_sector(ide_drive_t
*drive
)
71 struct ide_taskfile
*tf
= &cmd
.tf
;
72 u8 lba48
= !!(drive
->dev_flags
& IDE_DFLAG_LBA48
);
74 memset(&cmd
, 0, sizeof(cmd
));
76 cmd
.valid
.in
.tf
= IDE_VALID_LBA
;
77 cmd
.valid
.in
.hob
= IDE_VALID_LBA
;
78 cmd
.tf_flags
= IDE_TFLAG_LBA48
;
80 cmd
.valid
.in
.tf
= IDE_VALID_LBA
| IDE_VALID_DEVICE
;
82 ide_tf_readback(drive
, &cmd
);
84 if (lba48
|| (tf
->device
& ATA_LBA
))
85 printk(KERN_CONT
", LBAsect=%llu",
86 (unsigned long long)ide_get_lba_addr(&cmd
, lba48
));
88 printk(KERN_CONT
", CHS=%d/%d/%d", (tf
->lbah
<< 8) + tf
->lbam
,
89 tf
->device
& 0xf, tf
->lbal
);
92 static void ide_dump_ata_error(ide_drive_t
*drive
, u8 err
)
94 printk(KERN_ERR
"{ ");
95 if (err
& ATA_ABORTED
)
96 printk(KERN_CONT
"DriveStatusError ");
98 printk(KERN_CONT
"%s",
99 (err
& ATA_ABORTED
) ? "BadCRC " : "BadSector ");
101 printk(KERN_CONT
"UncorrectableError ");
103 printk(KERN_CONT
"SectorIdNotFound ");
104 if (err
& ATA_TRK0NF
)
105 printk(KERN_CONT
"TrackZeroNotFound ");
107 printk(KERN_CONT
"AddrMarkNotFound ");
108 printk(KERN_CONT
"}");
109 if ((err
& (ATA_BBK
| ATA_ABORTED
)) == ATA_BBK
||
110 (err
& (ATA_UNC
| ATA_IDNF
| ATA_AMNF
))) {
111 struct request
*rq
= drive
->hwif
->rq
;
113 ide_dump_sector(drive
);
116 printk(KERN_CONT
", sector=%llu",
117 (unsigned long long)rq
->sector
);
119 printk(KERN_CONT
"\n");
122 static void ide_dump_atapi_error(ide_drive_t
*drive
, u8 err
)
124 printk(KERN_ERR
"{ ");
126 printk(KERN_CONT
"IllegalLengthIndication ");
128 printk(KERN_CONT
"EndOfMedia ");
129 if (err
& ATA_ABORTED
)
130 printk(KERN_CONT
"AbortedCommand ");
132 printk(KERN_CONT
"MediaChangeRequested ");
134 printk(KERN_CONT
"LastFailedSense=0x%02x ",
135 (err
& ATAPI_LFS
) >> 4);
136 printk(KERN_CONT
"}\n");
140 * ide_dump_status - translate ATA/ATAPI error
141 * @drive: drive that status applies to
142 * @msg: text message to print
143 * @stat: status byte to decode
145 * Error reporting, in human readable form (luxurious, but a memory hog).
146 * Combines the drive name, message and status byte to provide a
147 * user understandable explanation of the device error.
150 u8
ide_dump_status(ide_drive_t
*drive
, const char *msg
, u8 stat
)
154 printk(KERN_ERR
"%s: %s: status=0x%02x { ", drive
->name
, msg
, stat
);
156 printk(KERN_CONT
"Busy ");
159 printk(KERN_CONT
"DriveReady ");
161 printk(KERN_CONT
"DeviceFault ");
163 printk(KERN_CONT
"SeekComplete ");
165 printk(KERN_CONT
"DataRequest ");
167 printk(KERN_CONT
"CorrectedError ");
169 printk(KERN_CONT
"Index ");
171 printk(KERN_CONT
"Error ");
173 printk(KERN_CONT
"}\n");
174 if ((stat
& (ATA_BUSY
| ATA_ERR
)) == ATA_ERR
) {
175 err
= ide_read_error(drive
);
176 printk(KERN_ERR
"%s: %s: error=0x%02x ", drive
->name
, msg
, err
);
177 if (drive
->media
== ide_disk
)
178 ide_dump_ata_error(drive
, err
);
180 ide_dump_atapi_error(drive
, err
);
182 ide_dump_opcode(drive
);
185 EXPORT_SYMBOL(ide_dump_status
);