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