Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/types.h> |
| 2 | #include <linux/string.h> |
| 3 | #include <linux/kernel.h> |
Paul Gortmaker | 38789fd | 2011-07-17 15:33:58 -0400 | [diff] [blame] | 4 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <linux/ide.h> |
| 7 | #include <linux/bitops.h> |
| 8 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | /** |
| 10 | * ide_toggle_bounce - handle bounce buffering |
| 11 | * @drive: drive to update |
| 12 | * @on: on/off boolean |
| 13 | * |
| 14 | * Enable or disable bounce buffering for the device. Drives move |
| 15 | * between PIO and DMA and that changes the rules we need. |
| 16 | */ |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 17 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | void ide_toggle_bounce(ide_drive_t *drive, int on) |
| 19 | { |
| 20 | u64 addr = BLK_BOUNCE_HIGH; /* dma64_addr_t */ |
| 21 | |
James Bottomley | 6593178 | 2005-11-18 23:13:33 +0100 | [diff] [blame] | 22 | if (!PCI_DMA_BUS_IS_PHYS) { |
| 23 | addr = BLK_BOUNCE_ANY; |
| 24 | } else if (on && drive->media == ide_disk) { |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 25 | struct device *dev = drive->hwif->dev; |
| 26 | |
| 27 | if (dev && dev->dma_mask) |
| 28 | addr = *dev->dma_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | if (drive->queue) |
| 32 | blk_queue_bounce_limit(drive->queue, addr); |
| 33 | } |
| 34 | |
Sergei Shtylyov | 745483f | 2009-04-08 14:13:02 +0200 | [diff] [blame] | 35 | u64 ide_get_lba_addr(struct ide_cmd *cmd, int lba48) |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 36 | { |
Sergei Shtylyov | 745483f | 2009-04-08 14:13:02 +0200 | [diff] [blame] | 37 | struct ide_taskfile *tf = &cmd->tf; |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 38 | u32 high, low; |
| 39 | |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 40 | low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal; |
Sergei Shtylyov | 745483f | 2009-04-08 14:13:02 +0200 | [diff] [blame] | 41 | if (lba48) { |
| 42 | tf = &cmd->hob; |
| 43 | high = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal; |
| 44 | } else |
| 45 | high = tf->device & 0xf; |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 46 | |
| 47 | return ((u64)high << 24) | low; |
| 48 | } |
Bartlomiej Zolnierkiewicz | a501633 | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 49 | EXPORT_SYMBOL_GPL(ide_get_lba_addr); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 50 | |
| 51 | static void ide_dump_sector(ide_drive_t *drive) |
| 52 | { |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 53 | struct ide_cmd cmd; |
| 54 | struct ide_taskfile *tf = &cmd.tf; |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 55 | u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 56 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 57 | memset(&cmd, 0, sizeof(cmd)); |
Sergei Shtylyov | 60f8501 | 2009-04-08 14:13:01 +0200 | [diff] [blame] | 58 | if (lba48) { |
| 59 | cmd.valid.in.tf = IDE_VALID_LBA; |
| 60 | cmd.valid.in.hob = IDE_VALID_LBA; |
| 61 | cmd.tf_flags = IDE_TFLAG_LBA48; |
| 62 | } else |
| 63 | cmd.valid.in.tf = IDE_VALID_LBA | IDE_VALID_DEVICE; |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 64 | |
Sergei Shtylyov | 3153c26 | 2009-04-08 14:13:03 +0200 | [diff] [blame] | 65 | ide_tf_readback(drive, &cmd); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 66 | |
| 67 | if (lba48 || (tf->device & ATA_LBA)) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 68 | printk(KERN_CONT ", LBAsect=%llu", |
Sergei Shtylyov | 745483f | 2009-04-08 14:13:02 +0200 | [diff] [blame] | 69 | (unsigned long long)ide_get_lba_addr(&cmd, lba48)); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 70 | else |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 71 | printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam, |
| 72 | tf->device & 0xf, tf->lbal); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 73 | } |
| 74 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 75 | static void ide_dump_ata_error(ide_drive_t *drive, u8 err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
Bartlomiej Zolnierkiewicz | 26bfcf2 | 2009-05-22 16:23:37 +0200 | [diff] [blame] | 77 | printk(KERN_CONT "{ "); |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 78 | if (err & ATA_ABORTED) |
| 79 | printk(KERN_CONT "DriveStatusError "); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 80 | if (err & ATA_ICRC) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 81 | printk(KERN_CONT "%s", |
| 82 | (err & ATA_ABORTED) ? "BadCRC " : "BadSector "); |
| 83 | if (err & ATA_UNC) |
| 84 | printk(KERN_CONT "UncorrectableError "); |
| 85 | if (err & ATA_IDNF) |
| 86 | printk(KERN_CONT "SectorIdNotFound "); |
| 87 | if (err & ATA_TRK0NF) |
| 88 | printk(KERN_CONT "TrackZeroNotFound "); |
| 89 | if (err & ATA_AMNF) |
| 90 | printk(KERN_CONT "AddrMarkNotFound "); |
| 91 | printk(KERN_CONT "}"); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 92 | if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK || |
| 93 | (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) { |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 94 | struct request *rq = drive->hwif->rq; |
| 95 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 96 | ide_dump_sector(drive); |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 97 | |
| 98 | if (rq) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 99 | printk(KERN_CONT ", sector=%llu", |
Tejun Heo | 9780e2d | 2009-05-07 22:24:40 +0900 | [diff] [blame] | 100 | (unsigned long long)blk_rq_pos(rq)); |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 101 | } |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 102 | printk(KERN_CONT "\n"); |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 103 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 105 | static void ide_dump_atapi_error(ide_drive_t *drive, u8 err) |
| 106 | { |
Bartlomiej Zolnierkiewicz | 26bfcf2 | 2009-05-22 16:23:37 +0200 | [diff] [blame] | 107 | printk(KERN_CONT "{ "); |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 108 | if (err & ATAPI_ILI) |
| 109 | printk(KERN_CONT "IllegalLengthIndication "); |
| 110 | if (err & ATAPI_EOM) |
| 111 | printk(KERN_CONT "EndOfMedia "); |
| 112 | if (err & ATA_ABORTED) |
| 113 | printk(KERN_CONT "AbortedCommand "); |
| 114 | if (err & ATA_MCR) |
| 115 | printk(KERN_CONT "MediaChangeRequested "); |
| 116 | if (err & ATAPI_LFS) |
| 117 | printk(KERN_CONT "LastFailedSense=0x%02x ", |
| 118 | (err & ATAPI_LFS) >> 4); |
| 119 | printk(KERN_CONT "}\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | /** |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 123 | * ide_dump_status - translate ATA/ATAPI error |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | * @drive: drive that status applies to |
| 125 | * @msg: text message to print |
| 126 | * @stat: status byte to decode |
| 127 | * |
| 128 | * Error reporting, in human readable form (luxurious, but a memory hog). |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 129 | * Combines the drive name, message and status byte to provide a |
| 130 | * user understandable explanation of the device error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | */ |
| 132 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 133 | u8 ide_dump_status(ide_drive_t *drive, const char *msg, u8 stat) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
Bartlomiej Zolnierkiewicz | 0e38a66 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 135 | u8 err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 137 | printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 138 | if (stat & ATA_BUSY) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 139 | printk(KERN_CONT "Busy "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | else { |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 141 | if (stat & ATA_DRDY) |
| 142 | printk(KERN_CONT "DriveReady "); |
| 143 | if (stat & ATA_DF) |
| 144 | printk(KERN_CONT "DeviceFault "); |
| 145 | if (stat & ATA_DSC) |
| 146 | printk(KERN_CONT "SeekComplete "); |
| 147 | if (stat & ATA_DRQ) |
| 148 | printk(KERN_CONT "DataRequest "); |
| 149 | if (stat & ATA_CORR) |
| 150 | printk(KERN_CONT "CorrectedError "); |
Hannes Reinecke | 27f00e5 | 2015-03-27 16:46:33 +0100 | [diff] [blame^] | 151 | if (stat & ATA_SENSE) |
| 152 | printk(KERN_CONT "Sense "); |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 153 | if (stat & ATA_ERR) |
| 154 | printk(KERN_CONT "Error "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | } |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 156 | printk(KERN_CONT "}\n"); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 157 | if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) { |
Bartlomiej Zolnierkiewicz | 64a57fe | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 158 | err = ide_read_error(drive); |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 159 | printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err); |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 160 | if (drive->media == ide_disk) |
| 161 | ide_dump_ata_error(drive, err); |
| 162 | else |
| 163 | ide_dump_atapi_error(drive, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | } |
Bartlomiej Zolnierkiewicz | cc30137 | 2009-05-22 16:23:38 +0200 | [diff] [blame] | 165 | |
| 166 | printk(KERN_ERR "%s: possibly failed opcode: 0x%02x\n", |
| 167 | drive->name, drive->hwif->cmd.tf.command); |
| 168 | |
Bartlomiej Zolnierkiewicz | 0e38a66 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 169 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | EXPORT_SYMBOL(ide_dump_status); |