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