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