]>
Commit | Line | Data |
---|---|---|
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 |
17 | void 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 | ||
745483f1 | 34 | u64 ide_get_lba_addr(struct ide_cmd *cmd, int lba48) |
c2b57cdc | 35 | { |
745483f1 | 36 | struct ide_taskfile *tf = &cmd->tf; |
c2b57cdc BZ |
37 | u32 high, low; |
38 | ||
c2b57cdc | 39 | low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal; |
745483f1 SS |
40 | if (lba48) { |
41 | tf = &cmd->hob; | |
42 | high = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal; | |
43 | } else | |
44 | high = tf->device & 0xf; | |
c2b57cdc BZ |
45 | |
46 | return ((u64)high << 24) | low; | |
47 | } | |
a501633c | 48 | EXPORT_SYMBOL_GPL(ide_get_lba_addr); |
c2b57cdc BZ |
49 | |
50 | static void ide_dump_sector(ide_drive_t *drive) | |
51 | { | |
22aa4b32 BZ |
52 | struct ide_cmd cmd; |
53 | struct ide_taskfile *tf = &cmd.tf; | |
97100fc8 | 54 | u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48); |
c2b57cdc | 55 | |
22aa4b32 | 56 | memset(&cmd, 0, sizeof(cmd)); |
60f85019 SS |
57 | if (lba48) { |
58 | cmd.valid.in.tf = IDE_VALID_LBA; | |
59 | cmd.valid.in.hob = IDE_VALID_LBA; | |
60 | cmd.tf_flags = IDE_TFLAG_LBA48; | |
61 | } else | |
62 | cmd.valid.in.tf = IDE_VALID_LBA | IDE_VALID_DEVICE; | |
c2b57cdc | 63 | |
3153c26b | 64 | ide_tf_readback(drive, &cmd); |
c2b57cdc BZ |
65 | |
66 | if (lba48 || (tf->device & ATA_LBA)) | |
2f996acb | 67 | printk(KERN_CONT ", LBAsect=%llu", |
745483f1 | 68 | (unsigned long long)ide_get_lba_addr(&cmd, lba48)); |
c2b57cdc | 69 | else |
2f996acb BZ |
70 | printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam, |
71 | tf->device & 0xf, tf->lbal); | |
c2b57cdc BZ |
72 | } |
73 | ||
e62925dd | 74 | static void ide_dump_ata_error(ide_drive_t *drive, u8 err) |
1da177e4 | 75 | { |
26bfcf21 | 76 | printk(KERN_CONT "{ "); |
2f996acb BZ |
77 | if (err & ATA_ABORTED) |
78 | printk(KERN_CONT "DriveStatusError "); | |
3a7d2484 | 79 | if (err & ATA_ICRC) |
2f996acb BZ |
80 | printk(KERN_CONT "%s", |
81 | (err & ATA_ABORTED) ? "BadCRC " : "BadSector "); | |
82 | if (err & ATA_UNC) | |
83 | printk(KERN_CONT "UncorrectableError "); | |
84 | if (err & ATA_IDNF) | |
85 | printk(KERN_CONT "SectorIdNotFound "); | |
86 | if (err & ATA_TRK0NF) | |
87 | printk(KERN_CONT "TrackZeroNotFound "); | |
88 | if (err & ATA_AMNF) | |
89 | printk(KERN_CONT "AddrMarkNotFound "); | |
90 | printk(KERN_CONT "}"); | |
3a7d2484 BZ |
91 | if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK || |
92 | (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) { | |
b65fac32 BZ |
93 | struct request *rq = drive->hwif->rq; |
94 | ||
e62925dd | 95 | ide_dump_sector(drive); |
b65fac32 BZ |
96 | |
97 | if (rq) | |
2f996acb | 98 | printk(KERN_CONT ", sector=%llu", |
9780e2dd | 99 | (unsigned long long)blk_rq_pos(rq)); |
1da177e4 | 100 | } |
2f996acb | 101 | printk(KERN_CONT "\n"); |
e62925dd BZ |
102 | } |
103 | ||
104 | static void ide_dump_atapi_error(ide_drive_t *drive, u8 err) | |
105 | { | |
26bfcf21 | 106 | printk(KERN_CONT "{ "); |
2f996acb BZ |
107 | if (err & ATAPI_ILI) |
108 | printk(KERN_CONT "IllegalLengthIndication "); | |
109 | if (err & ATAPI_EOM) | |
110 | printk(KERN_CONT "EndOfMedia "); | |
111 | if (err & ATA_ABORTED) | |
112 | printk(KERN_CONT "AbortedCommand "); | |
113 | if (err & ATA_MCR) | |
114 | printk(KERN_CONT "MediaChangeRequested "); | |
115 | if (err & ATAPI_LFS) | |
116 | printk(KERN_CONT "LastFailedSense=0x%02x ", | |
117 | (err & ATAPI_LFS) >> 4); | |
118 | printk(KERN_CONT "}\n"); | |
1da177e4 LT |
119 | } |
120 | ||
121 | /** | |
e62925dd | 122 | * ide_dump_status - translate ATA/ATAPI error |
1da177e4 LT |
123 | * @drive: drive that status applies to |
124 | * @msg: text message to print | |
125 | * @stat: status byte to decode | |
126 | * | |
127 | * Error reporting, in human readable form (luxurious, but a memory hog). | |
e62925dd BZ |
128 | * Combines the drive name, message and status byte to provide a |
129 | * user understandable explanation of the device error. | |
1da177e4 LT |
130 | */ |
131 | ||
e62925dd | 132 | u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat) |
1da177e4 | 133 | { |
0e38a66a | 134 | u8 err = 0; |
1da177e4 | 135 | |
2f996acb | 136 | printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat); |
3a7d2484 | 137 | if (stat & ATA_BUSY) |
2f996acb | 138 | printk(KERN_CONT "Busy "); |
1da177e4 | 139 | else { |
2f996acb BZ |
140 | if (stat & ATA_DRDY) |
141 | printk(KERN_CONT "DriveReady "); | |
142 | if (stat & ATA_DF) | |
143 | printk(KERN_CONT "DeviceFault "); | |
144 | if (stat & ATA_DSC) | |
145 | printk(KERN_CONT "SeekComplete "); | |
146 | if (stat & ATA_DRQ) | |
147 | printk(KERN_CONT "DataRequest "); | |
148 | if (stat & ATA_CORR) | |
149 | printk(KERN_CONT "CorrectedError "); | |
150 | if (stat & ATA_IDX) | |
151 | printk(KERN_CONT "Index "); | |
152 | if (stat & ATA_ERR) | |
153 | printk(KERN_CONT "Error "); | |
1da177e4 | 154 | } |
2f996acb | 155 | printk(KERN_CONT "}\n"); |
3a7d2484 | 156 | if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) { |
64a57fe4 | 157 | err = ide_read_error(drive); |
2f996acb | 158 | printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err); |
e62925dd BZ |
159 | if (drive->media == ide_disk) |
160 | ide_dump_ata_error(drive, err); | |
161 | else | |
162 | ide_dump_atapi_error(drive, err); | |
1da177e4 | 163 | } |
cc30137a BZ |
164 | |
165 | printk(KERN_ERR "%s: possibly failed opcode: 0x%02x\n", | |
166 | drive->name, drive->hwif->cmd.tf.command); | |
167 | ||
0e38a66a | 168 | return err; |
1da177e4 | 169 | } |
1da177e4 | 170 | EXPORT_SYMBOL(ide_dump_status); |