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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | #include <linux/ide.h> |
| 6 | #include <linux/bitops.h> |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | void ide_toggle_bounce(ide_drive_t *drive, int on) |
| 18 | { |
| 19 | u64 addr = BLK_BOUNCE_HIGH; /* dma64_addr_t */ |
| 20 | |
James Bottomley | 6593178 | 2005-11-18 23:13:33 +0100 | [diff] [blame] | 21 | if (!PCI_DMA_BUS_IS_PHYS) { |
| 22 | addr = BLK_BOUNCE_ANY; |
| 23 | } else if (on && drive->media == ide_disk) { |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 24 | struct device *dev = drive->hwif->dev; |
| 25 | |
| 26 | if (dev && dev->dma_mask) |
| 27 | addr = *dev->dma_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | if (drive->queue) |
| 31 | blk_queue_bounce_limit(drive->queue, addr); |
| 32 | } |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | static void ide_dump_opcode(ide_drive_t *drive) |
| 35 | { |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 36 | struct request *rq = drive->hwif->rq; |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 37 | struct ide_cmd *cmd = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | if (!rq) |
| 40 | return; |
Bartlomiej Zolnierkiewicz | 7267c33 | 2008-01-26 20:13:13 +0100 | [diff] [blame] | 41 | |
| 42 | if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 43 | cmd = rq->special; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 45 | printk(KERN_ERR "ide: failed opcode was: "); |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 46 | if (cmd == NULL) |
Bartlomiej Zolnierkiewicz | 7267c33 | 2008-01-26 20:13:13 +0100 | [diff] [blame] | 47 | printk(KERN_CONT "unknown\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | else |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 49 | printk(KERN_CONT "0x%02x\n", cmd->tf.command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Bartlomiej Zolnierkiewicz | a501633 | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 52 | u64 ide_get_lba_addr(struct ide_taskfile *tf, int lba48) |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 53 | { |
| 54 | u32 high, low; |
| 55 | |
| 56 | if (lba48) |
| 57 | high = (tf->hob_lbah << 16) | (tf->hob_lbam << 8) | |
| 58 | tf->hob_lbal; |
| 59 | else |
| 60 | high = tf->device & 0xf; |
| 61 | low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal; |
| 62 | |
| 63 | return ((u64)high << 24) | low; |
| 64 | } |
Bartlomiej Zolnierkiewicz | a501633 | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 65 | EXPORT_SYMBOL_GPL(ide_get_lba_addr); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 66 | |
| 67 | static void ide_dump_sector(ide_drive_t *drive) |
| 68 | { |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 69 | struct ide_cmd cmd; |
| 70 | struct ide_taskfile *tf = &cmd.tf; |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 71 | u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 72 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 73 | memset(&cmd, 0, sizeof(cmd)); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 74 | if (lba48) |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 75 | cmd.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_HOB_LBA | |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 76 | IDE_TFLAG_LBA48; |
| 77 | else |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 78 | cmd.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_DEVICE; |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 79 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 80 | drive->hwif->tp_ops->tf_read(drive, &cmd); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 81 | |
| 82 | if (lba48 || (tf->device & ATA_LBA)) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 83 | printk(KERN_CONT ", LBAsect=%llu", |
Andrew Morton | 1c904fc | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 84 | (unsigned long long)ide_get_lba_addr(tf, lba48)); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 85 | else |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 86 | printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam, |
| 87 | tf->device & 0xf, tf->lbal); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 88 | } |
| 89 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 90 | static void ide_dump_ata_error(ide_drive_t *drive, u8 err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 92 | printk(KERN_ERR "{ "); |
| 93 | if (err & ATA_ABORTED) |
| 94 | printk(KERN_CONT "DriveStatusError "); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 95 | if (err & ATA_ICRC) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 96 | printk(KERN_CONT "%s", |
| 97 | (err & ATA_ABORTED) ? "BadCRC " : "BadSector "); |
| 98 | if (err & ATA_UNC) |
| 99 | printk(KERN_CONT "UncorrectableError "); |
| 100 | if (err & ATA_IDNF) |
| 101 | printk(KERN_CONT "SectorIdNotFound "); |
| 102 | if (err & ATA_TRK0NF) |
| 103 | printk(KERN_CONT "TrackZeroNotFound "); |
| 104 | if (err & ATA_AMNF) |
| 105 | printk(KERN_CONT "AddrMarkNotFound "); |
| 106 | printk(KERN_CONT "}"); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 107 | if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK || |
| 108 | (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) { |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 109 | struct request *rq = drive->hwif->rq; |
| 110 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 111 | ide_dump_sector(drive); |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 112 | |
| 113 | if (rq) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 114 | printk(KERN_CONT ", sector=%llu", |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 115 | (unsigned long long)rq->sector); |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 116 | } |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 117 | printk(KERN_CONT "\n"); |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 120 | static void ide_dump_atapi_error(ide_drive_t *drive, u8 err) |
| 121 | { |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 122 | printk(KERN_ERR "{ "); |
| 123 | if (err & ATAPI_ILI) |
| 124 | printk(KERN_CONT "IllegalLengthIndication "); |
| 125 | if (err & ATAPI_EOM) |
| 126 | printk(KERN_CONT "EndOfMedia "); |
| 127 | if (err & ATA_ABORTED) |
| 128 | printk(KERN_CONT "AbortedCommand "); |
| 129 | if (err & ATA_MCR) |
| 130 | printk(KERN_CONT "MediaChangeRequested "); |
| 131 | if (err & ATAPI_LFS) |
| 132 | printk(KERN_CONT "LastFailedSense=0x%02x ", |
| 133 | (err & ATAPI_LFS) >> 4); |
| 134 | printk(KERN_CONT "}\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /** |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 138 | * ide_dump_status - translate ATA/ATAPI error |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | * @drive: drive that status applies to |
| 140 | * @msg: text message to print |
| 141 | * @stat: status byte to decode |
| 142 | * |
| 143 | * Error reporting, in human readable form (luxurious, but a memory hog). |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 144 | * Combines the drive name, message and status byte to provide a |
| 145 | * user understandable explanation of the device error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | */ |
| 147 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 148 | 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] | 149 | { |
Bartlomiej Zolnierkiewicz | 0e38a66 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 150 | u8 err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 152 | printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 153 | if (stat & ATA_BUSY) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 154 | printk(KERN_CONT "Busy "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | else { |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 156 | if (stat & ATA_DRDY) |
| 157 | printk(KERN_CONT "DriveReady "); |
| 158 | if (stat & ATA_DF) |
| 159 | printk(KERN_CONT "DeviceFault "); |
| 160 | if (stat & ATA_DSC) |
| 161 | printk(KERN_CONT "SeekComplete "); |
| 162 | if (stat & ATA_DRQ) |
| 163 | printk(KERN_CONT "DataRequest "); |
| 164 | if (stat & ATA_CORR) |
| 165 | printk(KERN_CONT "CorrectedError "); |
| 166 | if (stat & ATA_IDX) |
| 167 | printk(KERN_CONT "Index "); |
| 168 | if (stat & ATA_ERR) |
| 169 | printk(KERN_CONT "Error "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 171 | printk(KERN_CONT "}\n"); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 172 | if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) { |
Bartlomiej Zolnierkiewicz | 64a57fe | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 173 | err = ide_read_error(drive); |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 174 | printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err); |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 175 | if (drive->media == ide_disk) |
| 176 | ide_dump_ata_error(drive, err); |
| 177 | else |
| 178 | ide_dump_atapi_error(drive, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | ide_dump_opcode(drive); |
Bartlomiej Zolnierkiewicz | 0e38a66 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 181 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | EXPORT_SYMBOL(ide_dump_status); |