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 | |
Bartlomiej Zolnierkiewicz | 3ab7efe | 2007-12-12 23:31:58 +0100 | [diff] [blame] | 8 | static const char *udma_str[] = |
| 9 | { "UDMA/16", "UDMA/25", "UDMA/33", "UDMA/44", |
| 10 | "UDMA/66", "UDMA/100", "UDMA/133", "UDMA7" }; |
| 11 | static const char *mwdma_str[] = |
| 12 | { "MWDMA0", "MWDMA1", "MWDMA2" }; |
| 13 | static const char *swdma_str[] = |
| 14 | { "SWDMA0", "SWDMA1", "SWDMA2" }; |
| 15 | static const char *pio_str[] = |
| 16 | { "PIO0", "PIO1", "PIO2", "PIO3", "PIO4", "PIO5" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | /** |
| 19 | * ide_xfer_verbose - return IDE mode names |
Bartlomiej Zolnierkiewicz | 3ab7efe | 2007-12-12 23:31:58 +0100 | [diff] [blame] | 20 | * @mode: transfer mode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | * |
| 22 | * Returns a constant string giving the name of the mode |
| 23 | * requested. |
| 24 | */ |
| 25 | |
Bartlomiej Zolnierkiewicz | 3ab7efe | 2007-12-12 23:31:58 +0100 | [diff] [blame] | 26 | const char *ide_xfer_verbose(u8 mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | { |
Bartlomiej Zolnierkiewicz | 3ab7efe | 2007-12-12 23:31:58 +0100 | [diff] [blame] | 28 | const char *s; |
| 29 | u8 i = mode & 0xf; |
| 30 | |
| 31 | if (mode >= XFER_UDMA_0 && mode <= XFER_UDMA_7) |
| 32 | s = udma_str[i]; |
| 33 | else if (mode >= XFER_MW_DMA_0 && mode <= XFER_MW_DMA_2) |
| 34 | s = mwdma_str[i]; |
| 35 | else if (mode >= XFER_SW_DMA_0 && mode <= XFER_SW_DMA_2) |
| 36 | s = swdma_str[i]; |
| 37 | else if (mode >= XFER_PIO_0 && mode <= XFER_PIO_5) |
| 38 | s = pio_str[i & 0x7]; |
| 39 | else if (mode == XFER_PIO_SLOW) |
| 40 | s = "PIO SLOW"; |
| 41 | else |
| 42 | s = "XFER ERROR"; |
| 43 | |
| 44 | return s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | EXPORT_SYMBOL(ide_xfer_verbose); |
| 47 | |
| 48 | /** |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 49 | * ide_rate_filter - filter transfer mode |
| 50 | * @drive: IDE device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | * @speed: desired speed |
| 52 | * |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 53 | * Given the available transfer modes this function returns |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | * the best available speed at or below the speed requested. |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 55 | * |
Bartlomiej Zolnierkiewicz | 7670df7 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 56 | * TODO: check device PIO capabilities |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | */ |
| 58 | |
Bartlomiej Zolnierkiewicz | f212ff2 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 59 | static u8 ide_rate_filter(ide_drive_t *drive, u8 speed) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 61 | ide_hwif_t *hwif = drive->hwif; |
Bartlomiej Zolnierkiewicz | 7670df7 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 62 | u8 mode = ide_find_dma_mode(drive, speed); |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 63 | |
Bartlomiej Zolnierkiewicz | 7670df7 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 64 | if (mode == 0) { |
| 65 | if (hwif->pio_mask) |
| 66 | mode = fls(hwif->pio_mask) - 1 + XFER_PIO_0; |
| 67 | else |
| 68 | mode = XFER_PIO_4; |
Bartlomiej Zolnierkiewicz | 7f8f48a | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 69 | } |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 70 | |
Harvey Harrison | eb63963 | 2008-04-26 22:25:20 +0200 | [diff] [blame] | 71 | /* printk("%s: mode 0x%02x, speed 0x%02x\n", __func__, mode, speed); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 73 | return min(speed, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | /** |
| 77 | * ide_get_best_pio_mode - get PIO mode from drive |
Sergei Shtylyov | 81d368e | 2007-03-03 17:48:53 +0100 | [diff] [blame] | 78 | * @drive: drive to consider |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | * @mode_wanted: preferred mode |
Sergei Shtylyov | 81d368e | 2007-03-03 17:48:53 +0100 | [diff] [blame] | 80 | * @max_mode: highest allowed mode |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | * |
| 82 | * This routine returns the recommended PIO settings for a given drive, |
| 83 | * based on the drive->id information and the ide_pio_blacklist[]. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | * |
Sergei Shtylyov | 81d368e | 2007-03-03 17:48:53 +0100 | [diff] [blame] | 85 | * Drive PIO mode is auto-selected if 255 is passed as mode_wanted. |
| 86 | * This is used by most chipset support modules when "auto-tuning". |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | */ |
| 88 | |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 89 | u8 ide_get_best_pio_mode(ide_drive_t *drive, u8 mode_wanted, u8 max_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 91 | u16 *id = drive->id; |
| 92 | int pio_mode = -1, overridden = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Bartlomiej Zolnierkiewicz | 6a824c9 | 2007-07-20 01:11:58 +0200 | [diff] [blame] | 94 | if (mode_wanted != 255) |
| 95 | return min_t(u8, mode_wanted, max_mode); |
| 96 | |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 97 | if ((drive->hwif->host_flags & IDE_HFLAG_PIO_NO_BLACKLIST) == 0) |
| 98 | pio_mode = ide_scan_pio_blacklist((char *)&id[ATA_ID_PROD]); |
| 99 | |
| 100 | if (pio_mode != -1) { |
Bartlomiej Zolnierkiewicz | 342cdb6 | 2007-07-20 01:11:55 +0200 | [diff] [blame] | 101 | printk(KERN_INFO "%s: is on PIO blacklist\n", drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } else { |
Bartlomiej Zolnierkiewicz | 48fb268 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 103 | pio_mode = id[ATA_ID_OLD_PIO_MODES] >> 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | if (pio_mode > 2) { /* 2 is maximum allowed tPIO value */ |
| 105 | pio_mode = 2; |
| 106 | overridden = 1; |
| 107 | } |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 108 | |
| 109 | if (id[ATA_ID_FIELD_VALID] & 2) { /* ATA2? */ |
Bartlomiej Zolnierkiewicz | 48fb268 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 110 | if (ata_id_has_iordy(id)) { |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 111 | if (id[ATA_ID_PIO_MODES] & 7) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | overridden = 0; |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 113 | if (id[ATA_ID_PIO_MODES] & 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | pio_mode = 5; |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 115 | else if (id[ATA_ID_PIO_MODES] & 2) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | pio_mode = 4; |
| 117 | else |
| 118 | pio_mode = 3; |
| 119 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | } |
| 121 | } |
| 122 | |
Bartlomiej Zolnierkiewicz | 342cdb6 | 2007-07-20 01:11:55 +0200 | [diff] [blame] | 123 | if (overridden) |
| 124 | printk(KERN_INFO "%s: tPIO > 2, assuming tPIO = 2\n", |
| 125 | drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | } |
Bartlomiej Zolnierkiewicz | 7dd0008 | 2007-07-20 01:11:56 +0200 | [diff] [blame] | 127 | |
| 128 | if (pio_mode > max_mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | pio_mode = max_mode; |
Bartlomiej Zolnierkiewicz | 7dd0008 | 2007-07-20 01:11:56 +0200 | [diff] [blame] | 130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | return pio_mode; |
| 132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | EXPORT_SYMBOL_GPL(ide_get_best_pio_mode); |
| 134 | |
Bartlomiej Zolnierkiewicz | 26bcb87 | 2007-10-11 23:54:00 +0200 | [diff] [blame] | 135 | /* req_pio == "255" for auto-tune */ |
| 136 | void ide_set_pio(ide_drive_t *drive, u8 req_pio) |
| 137 | { |
| 138 | ide_hwif_t *hwif = drive->hwif; |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 139 | const struct ide_port_ops *port_ops = hwif->port_ops; |
Bartlomiej Zolnierkiewicz | 26bcb87 | 2007-10-11 23:54:00 +0200 | [diff] [blame] | 140 | u8 host_pio, pio; |
| 141 | |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 142 | if (port_ops == NULL || port_ops->set_pio_mode == NULL || |
Bartlomiej Zolnierkiewicz | 784506c | 2008-04-26 17:36:43 +0200 | [diff] [blame] | 143 | (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)) |
Bartlomiej Zolnierkiewicz | 26bcb87 | 2007-10-11 23:54:00 +0200 | [diff] [blame] | 144 | return; |
| 145 | |
| 146 | BUG_ON(hwif->pio_mask == 0x00); |
| 147 | |
| 148 | host_pio = fls(hwif->pio_mask) - 1; |
| 149 | |
| 150 | pio = ide_get_best_pio_mode(drive, req_pio, host_pio); |
| 151 | |
| 152 | /* |
| 153 | * TODO: |
| 154 | * - report device max PIO mode |
| 155 | * - check req_pio != 255 against device max PIO mode |
| 156 | */ |
| 157 | printk(KERN_DEBUG "%s: host max PIO%d wanted PIO%d%s selected PIO%d\n", |
| 158 | drive->name, host_pio, req_pio, |
| 159 | req_pio == 255 ? "(auto-tune)" : "", pio); |
| 160 | |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 161 | (void)ide_set_pio_mode(drive, XFER_PIO_0 + pio); |
Bartlomiej Zolnierkiewicz | 26bcb87 | 2007-10-11 23:54:00 +0200 | [diff] [blame] | 162 | } |
Bartlomiej Zolnierkiewicz | 26bcb87 | 2007-10-11 23:54:00 +0200 | [diff] [blame] | 163 | EXPORT_SYMBOL_GPL(ide_set_pio); |
| 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | /** |
| 166 | * ide_toggle_bounce - handle bounce buffering |
| 167 | * @drive: drive to update |
| 168 | * @on: on/off boolean |
| 169 | * |
| 170 | * Enable or disable bounce buffering for the device. Drives move |
| 171 | * between PIO and DMA and that changes the rules we need. |
| 172 | */ |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 173 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | void ide_toggle_bounce(ide_drive_t *drive, int on) |
| 175 | { |
| 176 | u64 addr = BLK_BOUNCE_HIGH; /* dma64_addr_t */ |
| 177 | |
James Bottomley | 6593178 | 2005-11-18 23:13:33 +0100 | [diff] [blame] | 178 | if (!PCI_DMA_BUS_IS_PHYS) { |
| 179 | addr = BLK_BOUNCE_ANY; |
| 180 | } else if (on && drive->media == ide_disk) { |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 181 | struct device *dev = drive->hwif->dev; |
| 182 | |
| 183 | if (dev && dev->dma_mask) |
| 184 | addr = *dev->dma_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | if (drive->queue) |
| 188 | blk_queue_bounce_limit(drive->queue, addr); |
| 189 | } |
| 190 | |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 191 | int ide_set_pio_mode(ide_drive_t *drive, const u8 mode) |
| 192 | { |
| 193 | ide_hwif_t *hwif = drive->hwif; |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 194 | const struct ide_port_ops *port_ops = hwif->port_ops; |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 195 | |
Bartlomiej Zolnierkiewicz | 784506c | 2008-04-26 17:36:43 +0200 | [diff] [blame] | 196 | if (hwif->host_flags & IDE_HFLAG_NO_SET_MODE) |
| 197 | return 0; |
| 198 | |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 199 | if (port_ops == NULL || port_ops->set_pio_mode == NULL) |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 200 | return -1; |
| 201 | |
| 202 | /* |
| 203 | * TODO: temporary hack for some legacy host drivers that didn't |
| 204 | * set transfer mode on the device in ->set_pio_mode method... |
| 205 | */ |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 206 | if (port_ops->set_dma_mode == NULL) { |
| 207 | port_ops->set_pio_mode(drive, mode - XFER_PIO_0); |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | if (hwif->host_flags & IDE_HFLAG_POST_SET_MODE) { |
| 212 | if (ide_config_drive_speed(drive, mode)) |
| 213 | return -1; |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 214 | port_ops->set_pio_mode(drive, mode - XFER_PIO_0); |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 215 | return 0; |
| 216 | } else { |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 217 | port_ops->set_pio_mode(drive, mode - XFER_PIO_0); |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 218 | return ide_config_drive_speed(drive, mode); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | int ide_set_dma_mode(ide_drive_t *drive, const u8 mode) |
| 223 | { |
| 224 | ide_hwif_t *hwif = drive->hwif; |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 225 | const struct ide_port_ops *port_ops = hwif->port_ops; |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 226 | |
Bartlomiej Zolnierkiewicz | 784506c | 2008-04-26 17:36:43 +0200 | [diff] [blame] | 227 | if (hwif->host_flags & IDE_HFLAG_NO_SET_MODE) |
| 228 | return 0; |
| 229 | |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 230 | if (port_ops == NULL || port_ops->set_dma_mode == NULL) |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 231 | return -1; |
| 232 | |
| 233 | if (hwif->host_flags & IDE_HFLAG_POST_SET_MODE) { |
| 234 | if (ide_config_drive_speed(drive, mode)) |
| 235 | return -1; |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 236 | port_ops->set_dma_mode(drive, mode); |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 237 | return 0; |
| 238 | } else { |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 239 | port_ops->set_dma_mode(drive, mode); |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 240 | return ide_config_drive_speed(drive, mode); |
| 241 | } |
| 242 | } |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 243 | EXPORT_SYMBOL_GPL(ide_set_dma_mode); |
| 244 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | /** |
| 246 | * ide_set_xfer_rate - set transfer rate |
| 247 | * @drive: drive to set |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 248 | * @rate: speed to attempt to set |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 249 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | * General helper for setting the speed of an IDE device. This |
| 251 | * function knows about user enforced limits from the configuration |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 252 | * which ->set_pio_mode/->set_dma_mode does not. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | */ |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | int ide_set_xfer_rate(ide_drive_t *drive, u8 rate) |
| 256 | { |
Bartlomiej Zolnierkiewicz | f212ff2 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 257 | ide_hwif_t *hwif = drive->hwif; |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 258 | const struct ide_port_ops *port_ops = hwif->port_ops; |
Bartlomiej Zolnierkiewicz | f212ff2 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 259 | |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 260 | if (port_ops == NULL || port_ops->set_dma_mode == NULL || |
Bartlomiej Zolnierkiewicz | 784506c | 2008-04-26 17:36:43 +0200 | [diff] [blame] | 261 | (hwif->host_flags & IDE_HFLAG_NO_SET_MODE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | return -1; |
Bartlomiej Zolnierkiewicz | f212ff2 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 263 | |
| 264 | rate = ide_rate_filter(drive, rate); |
| 265 | |
Bartlomiej Zolnierkiewicz | 3b2a5c7 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 266 | BUG_ON(rate < XFER_PIO_0); |
| 267 | |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 268 | if (rate >= XFER_PIO_0 && rate <= XFER_PIO_5) |
| 269 | return ide_set_pio_mode(drive, rate); |
Bartlomiej Zolnierkiewicz | 8f4dd2e | 2007-10-11 23:54:02 +0200 | [diff] [blame] | 270 | |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 271 | return ide_set_dma_mode(drive, rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | static void ide_dump_opcode(ide_drive_t *drive) |
| 275 | { |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 276 | struct request *rq = drive->hwif->rq; |
Bartlomiej Zolnierkiewicz | 7267c33 | 2008-01-26 20:13:13 +0100 | [diff] [blame] | 277 | ide_task_t *task = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | if (!rq) |
| 280 | return; |
Bartlomiej Zolnierkiewicz | 7267c33 | 2008-01-26 20:13:13 +0100 | [diff] [blame] | 281 | |
| 282 | if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) |
| 283 | task = rq->special; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 285 | printk(KERN_ERR "ide: failed opcode was: "); |
Bartlomiej Zolnierkiewicz | 7267c33 | 2008-01-26 20:13:13 +0100 | [diff] [blame] | 286 | if (task == NULL) |
| 287 | printk(KERN_CONT "unknown\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | else |
Bartlomiej Zolnierkiewicz | 7267c33 | 2008-01-26 20:13:13 +0100 | [diff] [blame] | 289 | printk(KERN_CONT "0x%02x\n", task->tf.command); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Bartlomiej Zolnierkiewicz | a501633 | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 292 | u64 ide_get_lba_addr(struct ide_taskfile *tf, int lba48) |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 293 | { |
| 294 | u32 high, low; |
| 295 | |
| 296 | if (lba48) |
| 297 | high = (tf->hob_lbah << 16) | (tf->hob_lbam << 8) | |
| 298 | tf->hob_lbal; |
| 299 | else |
| 300 | high = tf->device & 0xf; |
| 301 | low = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal; |
| 302 | |
| 303 | return ((u64)high << 24) | low; |
| 304 | } |
Bartlomiej Zolnierkiewicz | a501633 | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 305 | EXPORT_SYMBOL_GPL(ide_get_lba_addr); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 306 | |
| 307 | static void ide_dump_sector(ide_drive_t *drive) |
| 308 | { |
| 309 | ide_task_t task; |
| 310 | struct ide_taskfile *tf = &task.tf; |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 311 | u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 312 | |
| 313 | memset(&task, 0, sizeof(task)); |
| 314 | if (lba48) |
| 315 | task.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_HOB_LBA | |
| 316 | IDE_TFLAG_LBA48; |
| 317 | else |
| 318 | task.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_DEVICE; |
| 319 | |
Bartlomiej Zolnierkiewicz | 374e042 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 320 | drive->hwif->tp_ops->tf_read(drive, &task); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 321 | |
| 322 | if (lba48 || (tf->device & ATA_LBA)) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 323 | printk(KERN_CONT ", LBAsect=%llu", |
Andrew Morton | 1c904fc | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 324 | (unsigned long long)ide_get_lba_addr(tf, lba48)); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 325 | else |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 326 | printk(KERN_CONT ", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam, |
| 327 | tf->device & 0xf, tf->lbal); |
Bartlomiej Zolnierkiewicz | c2b57cd | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 328 | } |
| 329 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 330 | static void ide_dump_ata_error(ide_drive_t *drive, u8 err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | { |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 332 | printk(KERN_ERR "{ "); |
| 333 | if (err & ATA_ABORTED) |
| 334 | printk(KERN_CONT "DriveStatusError "); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 335 | if (err & ATA_ICRC) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 336 | printk(KERN_CONT "%s", |
| 337 | (err & ATA_ABORTED) ? "BadCRC " : "BadSector "); |
| 338 | if (err & ATA_UNC) |
| 339 | printk(KERN_CONT "UncorrectableError "); |
| 340 | if (err & ATA_IDNF) |
| 341 | printk(KERN_CONT "SectorIdNotFound "); |
| 342 | if (err & ATA_TRK0NF) |
| 343 | printk(KERN_CONT "TrackZeroNotFound "); |
| 344 | if (err & ATA_AMNF) |
| 345 | printk(KERN_CONT "AddrMarkNotFound "); |
| 346 | printk(KERN_CONT "}"); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 347 | if ((err & (ATA_BBK | ATA_ABORTED)) == ATA_BBK || |
| 348 | (err & (ATA_UNC | ATA_IDNF | ATA_AMNF))) { |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 349 | struct request *rq = drive->hwif->rq; |
| 350 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 351 | ide_dump_sector(drive); |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 352 | |
| 353 | if (rq) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 354 | printk(KERN_CONT ", sector=%llu", |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 355 | (unsigned long long)rq->sector); |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 356 | } |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 357 | printk(KERN_CONT "\n"); |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 358 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 360 | static void ide_dump_atapi_error(ide_drive_t *drive, u8 err) |
| 361 | { |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 362 | printk(KERN_ERR "{ "); |
| 363 | if (err & ATAPI_ILI) |
| 364 | printk(KERN_CONT "IllegalLengthIndication "); |
| 365 | if (err & ATAPI_EOM) |
| 366 | printk(KERN_CONT "EndOfMedia "); |
| 367 | if (err & ATA_ABORTED) |
| 368 | printk(KERN_CONT "AbortedCommand "); |
| 369 | if (err & ATA_MCR) |
| 370 | printk(KERN_CONT "MediaChangeRequested "); |
| 371 | if (err & ATAPI_LFS) |
| 372 | printk(KERN_CONT "LastFailedSense=0x%02x ", |
| 373 | (err & ATAPI_LFS) >> 4); |
| 374 | printk(KERN_CONT "}\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | /** |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 378 | * ide_dump_status - translate ATA/ATAPI error |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | * @drive: drive that status applies to |
| 380 | * @msg: text message to print |
| 381 | * @stat: status byte to decode |
| 382 | * |
| 383 | * Error reporting, in human readable form (luxurious, but a memory hog). |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 384 | * Combines the drive name, message and status byte to provide a |
| 385 | * user understandable explanation of the device error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | */ |
| 387 | |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 388 | 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] | 389 | { |
Bartlomiej Zolnierkiewicz | 0e38a66 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 390 | u8 err = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 392 | printk(KERN_ERR "%s: %s: status=0x%02x { ", drive->name, msg, stat); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 393 | if (stat & ATA_BUSY) |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 394 | printk(KERN_CONT "Busy "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | else { |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 396 | if (stat & ATA_DRDY) |
| 397 | printk(KERN_CONT "DriveReady "); |
| 398 | if (stat & ATA_DF) |
| 399 | printk(KERN_CONT "DeviceFault "); |
| 400 | if (stat & ATA_DSC) |
| 401 | printk(KERN_CONT "SeekComplete "); |
| 402 | if (stat & ATA_DRQ) |
| 403 | printk(KERN_CONT "DataRequest "); |
| 404 | if (stat & ATA_CORR) |
| 405 | printk(KERN_CONT "CorrectedError "); |
| 406 | if (stat & ATA_IDX) |
| 407 | printk(KERN_CONT "Index "); |
| 408 | if (stat & ATA_ERR) |
| 409 | printk(KERN_CONT "Error "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | } |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 411 | printk(KERN_CONT "}\n"); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 412 | if ((stat & (ATA_BUSY | ATA_ERR)) == ATA_ERR) { |
Bartlomiej Zolnierkiewicz | 64a57fe | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 413 | err = ide_read_error(drive); |
Bartlomiej Zolnierkiewicz | 2f996ac | 2008-12-29 20:27:36 +0100 | [diff] [blame] | 414 | printk(KERN_ERR "%s: %s: error=0x%02x ", drive->name, msg, err); |
Bartlomiej Zolnierkiewicz | e62925d | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 415 | if (drive->media == ide_disk) |
| 416 | ide_dump_ata_error(drive, err); |
| 417 | else |
| 418 | ide_dump_atapi_error(drive, err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | ide_dump_opcode(drive); |
Bartlomiej Zolnierkiewicz | 0e38a66 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 421 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | EXPORT_SYMBOL(ide_dump_status); |