Blame view
drivers/ide/ide-lib.c
4.38 KB
1da177e4c
|
1 2 3 |
#include <linux/types.h> #include <linux/string.h> #include <linux/kernel.h> |
38789fda2
|
4 |
#include <linux/export.h> |
1da177e4c
|
5 |
#include <linux/interrupt.h> |
1da177e4c
|
6 7 |
#include <linux/ide.h> #include <linux/bitops.h> |
1da177e4c
|
8 9 10 11 12 13 14 15 |
/** * ide_toggle_bounce - handle bounce buffering * @drive: drive to update * @on: on/off boolean * * Enable or disable bounce buffering for the device. Drives move * between PIO and DMA and that changes the rules we need. */ |
2f996acb6
|
16 |
|
1da177e4c
|
17 18 19 |
void ide_toggle_bounce(ide_drive_t *drive, int on) { u64 addr = BLK_BOUNCE_HIGH; /* dma64_addr_t */ |
6593178dd
|
20 21 22 |
if (!PCI_DMA_BUS_IS_PHYS) { addr = BLK_BOUNCE_ANY; } else if (on && drive->media == ide_disk) { |
36501650e
|
23 24 25 26 |
struct device *dev = drive->hwif->dev; if (dev && dev->dma_mask) addr = *dev->dma_mask; |
1da177e4c
|
27 28 29 30 31 |
} if (drive->queue) blk_queue_bounce_limit(drive->queue, addr); } |
745483f10
|
32 |
u64 ide_get_lba_addr(struct ide_cmd *cmd, int lba48) |
c2b57cdc1
|
33 |
{ |
745483f10
|
34 |
struct ide_taskfile *tf = &cmd->tf; |
c2b57cdc1
|
35 |
u32 high, low; |
c2b57cdc1
|
36 |
low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal; |
745483f10
|
37 38 39 40 41 |
if (lba48) { tf = &cmd->hob; high = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal; } else high = tf->device & 0xf; |
c2b57cdc1
|
42 43 44 |
return ((u64)high << 24) | low; } |
a501633c7
|
45 |
EXPORT_SYMBOL_GPL(ide_get_lba_addr); |
c2b57cdc1
|
46 47 48 |
static void ide_dump_sector(ide_drive_t *drive) { |
22aa4b32a
|
49 50 |
struct ide_cmd cmd; struct ide_taskfile *tf = &cmd.tf; |
97100fc81
|
51 |
u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48); |
c2b57cdc1
|
52 |
|
22aa4b32a
|
53 |
memset(&cmd, 0, sizeof(cmd)); |
60f85019c
|
54 55 56 57 58 59 |
if (lba48) { cmd.valid.in.tf = IDE_VALID_LBA; cmd.valid.in.hob = IDE_VALID_LBA; cmd.tf_flags = IDE_TFLAG_LBA48; } else cmd.valid.in.tf = IDE_VALID_LBA | IDE_VALID_DEVICE; |
c2b57cdc1
|
60 |
|
3153c26b5
|
61 |
ide_tf_readback(drive, &cmd); |
c2b57cdc1
|
62 63 |
if (lba48 || (tf->device & ATA_LBA)) |
2f996acb6
|
64 |
printk(KERN_CONT ", LBAsect=%llu", |
745483f10
|
65 |
(unsigned long long)ide_get_lba_addr(&cmd, lba48)); |
c2b57cdc1
|
66 |
else |
2f996acb6
|
67 68 |
printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam, tf->device & 0xf, tf->lbal); |
c2b57cdc1
|
69 |
} |
e62925dd2
|
70 |
static void ide_dump_ata_error(ide_drive_t *drive, u8 err) |
1da177e4c
|
71 |
{ |
26bfcf21e
|
72 |
printk(KERN_CONT "{ "); |
2f996acb6
|
73 74 |
if (err & ATA_ABORTED) printk(KERN_CONT "DriveStatusError "); |
3a7d24841
|
75 |
if (err & ATA_ICRC) |
2f996acb6
|
76 77 78 79 80 81 82 83 84 85 86 |
printk(KERN_CONT "%s", (err & ATA_ABORTED) ? "BadCRC " : "BadSector "); if (err & ATA_UNC) printk(KERN_CONT "UncorrectableError "); if (err & ATA_IDNF) printk(KERN_CONT "SectorIdNotFound "); if (err & ATA_TRK0NF) printk(KERN_CONT "TrackZeroNotFound "); if (err & ATA_AMNF) printk(KERN_CONT "AddrMarkNotFound "); printk(KERN_CONT "}"); |
3a7d24841
|
87 88 |
if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK || (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) { |
b65fac32c
|
89 |
struct request *rq = drive->hwif->rq; |
e62925dd2
|
90 |
ide_dump_sector(drive); |
b65fac32c
|
91 92 |
if (rq) |
2f996acb6
|
93 |
printk(KERN_CONT ", sector=%llu", |
9780e2dd8
|
94 |
(unsigned long long)blk_rq_pos(rq)); |
1da177e4c
|
95 |
} |
2f996acb6
|
96 97 |
printk(KERN_CONT " "); |
e62925dd2
|
98 99 100 101 |
} static void ide_dump_atapi_error(ide_drive_t *drive, u8 err) { |
26bfcf21e
|
102 |
printk(KERN_CONT "{ "); |
2f996acb6
|
103 104 105 106 107 108 109 110 111 112 113 114 115 |
if (err & ATAPI_ILI) printk(KERN_CONT "IllegalLengthIndication "); if (err & ATAPI_EOM) printk(KERN_CONT "EndOfMedia "); if (err & ATA_ABORTED) printk(KERN_CONT "AbortedCommand "); if (err & ATA_MCR) printk(KERN_CONT "MediaChangeRequested "); if (err & ATAPI_LFS) printk(KERN_CONT "LastFailedSense=0x%02x ", (err & ATAPI_LFS) >> 4); printk(KERN_CONT "} "); |
1da177e4c
|
116 117 118 |
} /** |
e62925dd2
|
119 |
* ide_dump_status - translate ATA/ATAPI error |
1da177e4c
|
120 121 122 123 124 |
* @drive: drive that status applies to * @msg: text message to print * @stat: status byte to decode * * Error reporting, in human readable form (luxurious, but a memory hog). |
e62925dd2
|
125 126 |
* Combines the drive name, message and status byte to provide a * user understandable explanation of the device error. |
1da177e4c
|
127 |
*/ |
e62925dd2
|
128 |
u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat) |
1da177e4c
|
129 |
{ |
0e38a66a1
|
130 |
u8 err = 0; |
1da177e4c
|
131 |
|
2f996acb6
|
132 |
printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat); |
3a7d24841
|
133 |
if (stat & ATA_BUSY) |
2f996acb6
|
134 |
printk(KERN_CONT "Busy "); |
1da177e4c
|
135 |
else { |
2f996acb6
|
136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
if (stat & ATA_DRDY) printk(KERN_CONT "DriveReady "); if (stat & ATA_DF) printk(KERN_CONT "DeviceFault "); if (stat & ATA_DSC) printk(KERN_CONT "SeekComplete "); if (stat & ATA_DRQ) printk(KERN_CONT "DataRequest "); if (stat & ATA_CORR) printk(KERN_CONT "CorrectedError "); if (stat & ATA_IDX) printk(KERN_CONT "Index "); if (stat & ATA_ERR) printk(KERN_CONT "Error "); |
1da177e4c
|
150 |
} |
2f996acb6
|
151 152 |
printk(KERN_CONT "} "); |
3a7d24841
|
153 |
if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) { |
64a57fe43
|
154 |
err = ide_read_error(drive); |
2f996acb6
|
155 |
printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err); |
e62925dd2
|
156 157 158 159 |
if (drive->media == ide_disk) ide_dump_ata_error(drive, err); else ide_dump_atapi_error(drive, err); |
1da177e4c
|
160 |
} |
cc30137a2
|
161 162 163 164 |
printk(KERN_ERR "%s: possibly failed opcode: 0x%02x ", drive->name, drive->hwif->cmd.tf.command); |
0e38a66a1
|
165 |
return err; |
1da177e4c
|
166 |
} |
1da177e4c
|
167 |
EXPORT_SYMBOL(ide_dump_status); |