Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Bartlomiej Zolnierkiewicz | 204f47c | 2008-02-26 21:50:36 +0100 | [diff] [blame] | 2 | * IDE DMA support (including IDE PCI BM-DMA). |
| 3 | * |
Bartlomiej Zolnierkiewicz | 59bca8c | 2008-02-01 23:09:33 +0100 | [diff] [blame] | 4 | * Copyright (C) 1995-1998 Mark Lord |
| 5 | * Copyright (C) 1999-2000 Andre Hedrick <andre@linux-ide.org> |
| 6 | * Copyright (C) 2004, 2007 Bartlomiej Zolnierkiewicz |
Bartlomiej Zolnierkiewicz | 58f189f | 2008-02-01 23:09:33 +0100 | [diff] [blame] | 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * May be copied or modified under the terms of the GNU General Public License |
Bartlomiej Zolnierkiewicz | 204f47c | 2008-02-26 21:50:36 +0100 | [diff] [blame] | 9 | * |
| 10 | * DMA is supported for all IDE devices (disk drives, cdroms, tapes, floppies). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | /* |
| 14 | * Special Thanks to Mark for his Six years of work. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * Thanks to "Christopher J. Reimer" <reimer@doe.carleton.ca> for |
| 19 | * fixing the problem with the BIOS on some Acer motherboards. |
| 20 | * |
| 21 | * Thanks to "Benoit Poulot-Cazajous" <poulot@chorus.fr> for testing |
| 22 | * "TX" chipset compatibility and for providing patches for the "TX" chipset. |
| 23 | * |
| 24 | * Thanks to Christian Brunner <chb@muc.de> for taking a good first crack |
| 25 | * at generic DMA -- his patches were referred to when preparing this code. |
| 26 | * |
| 27 | * Most importantly, thanks to Robert Bringman <rob@mars.trion.com> |
| 28 | * for supplying a Promise UDMA board & WD UDMA drive for this work! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | */ |
| 30 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/module.h> |
| 32 | #include <linux/types.h> |
| 33 | #include <linux/kernel.h> |
| 34 | #include <linux/timer.h> |
| 35 | #include <linux/mm.h> |
| 36 | #include <linux/interrupt.h> |
| 37 | #include <linux/pci.h> |
| 38 | #include <linux/init.h> |
| 39 | #include <linux/ide.h> |
| 40 | #include <linux/delay.h> |
| 41 | #include <linux/scatterlist.h> |
Bartlomiej Zolnierkiewicz | 5c05ff6 | 2008-02-01 23:09:32 +0100 | [diff] [blame] | 42 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | |
| 44 | #include <asm/io.h> |
| 45 | #include <asm/irq.h> |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | static const struct drive_list_entry drive_whitelist [] = { |
| 48 | |
Junio C Hamano | c2d3ce8 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 49 | { "Micropolis 2112A" , NULL }, |
| 50 | { "CONNER CTMA 4000" , NULL }, |
| 51 | { "CONNER CTT8000-A" , NULL }, |
| 52 | { "ST34342A" , NULL }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | { NULL , NULL } |
| 54 | }; |
| 55 | |
| 56 | static const struct drive_list_entry drive_blacklist [] = { |
| 57 | |
Junio C Hamano | c2d3ce8 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 58 | { "WDC AC11000H" , NULL }, |
| 59 | { "WDC AC22100H" , NULL }, |
| 60 | { "WDC AC32500H" , NULL }, |
| 61 | { "WDC AC33100H" , NULL }, |
| 62 | { "WDC AC31600H" , NULL }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | { "WDC AC32100H" , "24.09P07" }, |
| 64 | { "WDC AC23200L" , "21.10N21" }, |
Junio C Hamano | c2d3ce8 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 65 | { "Compaq CRD-8241B" , NULL }, |
| 66 | { "CRD-8400B" , NULL }, |
| 67 | { "CRD-8480B", NULL }, |
| 68 | { "CRD-8482B", NULL }, |
| 69 | { "CRD-84" , NULL }, |
| 70 | { "SanDisk SDP3B" , NULL }, |
| 71 | { "SanDisk SDP3B-64" , NULL }, |
| 72 | { "SANYO CD-ROM CRD" , NULL }, |
| 73 | { "HITACHI CDR-8" , NULL }, |
| 74 | { "HITACHI CDR-8335" , NULL }, |
| 75 | { "HITACHI CDR-8435" , NULL }, |
| 76 | { "Toshiba CD-ROM XM-6202B" , NULL }, |
| 77 | { "TOSHIBA CD-ROM XM-1702BC", NULL }, |
| 78 | { "CD-532E-A" , NULL }, |
| 79 | { "E-IDE CD-ROM CR-840", NULL }, |
| 80 | { "CD-ROM Drive/F5A", NULL }, |
| 81 | { "WPI CDD-820", NULL }, |
| 82 | { "SAMSUNG CD-ROM SC-148C", NULL }, |
| 83 | { "SAMSUNG CD-ROM SC", NULL }, |
| 84 | { "ATAPI CD-ROM DRIVE 40X MAXIMUM", NULL }, |
| 85 | { "_NEC DV5800A", NULL }, |
Junio C Hamano | 5a6248c | 2007-05-24 02:42:38 +0200 | [diff] [blame] | 86 | { "SAMSUNG CD-ROM SN-124", "N001" }, |
Junio C Hamano | c2d3ce8 | 2007-07-09 23:17:56 +0200 | [diff] [blame] | 87 | { "Seagate STT20000A", NULL }, |
Bartlomiej Zolnierkiewicz | b0bc65b | 2007-11-27 21:35:56 +0100 | [diff] [blame] | 88 | { "CD-ROM CDR_U200", "1.09" }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { NULL , NULL } |
| 90 | |
| 91 | }; |
| 92 | |
| 93 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | * ide_dma_intr - IDE DMA interrupt handler |
| 95 | * @drive: the drive the interrupt is for |
| 96 | * |
| 97 | * Handle an interrupt completing a read/write DMA transfer on an |
| 98 | * IDE device |
| 99 | */ |
| 100 | |
| 101 | ide_startstop_t ide_dma_intr (ide_drive_t *drive) |
| 102 | { |
Bartlomiej Zolnierkiewicz | b73c7ee | 2008-07-23 19:55:52 +0200 | [diff] [blame] | 103 | ide_hwif_t *hwif = drive->hwif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | u8 stat = 0, dma_stat = 0; |
| 105 | |
Bartlomiej Zolnierkiewicz | b73c7ee | 2008-07-23 19:55:52 +0200 | [diff] [blame] | 106 | dma_stat = hwif->dma_ops->dma_end(drive); |
Bartlomiej Zolnierkiewicz | 374e042 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 107 | stat = hwif->tp_ops->read_status(hwif); |
Bartlomiej Zolnierkiewicz | c47137a | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | if (OK_STAT(stat,DRIVE_READY,drive->bad_wstat|DRQ_STAT)) { |
| 110 | if (!dma_stat) { |
| 111 | struct request *rq = HWGROUP(drive)->rq; |
| 112 | |
Tejun Heo | 4d7a984 | 2008-01-26 20:13:11 +0100 | [diff] [blame] | 113 | task_end_request(drive, rq, stat); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | return ide_stopped; |
| 115 | } |
| 116 | printk(KERN_ERR "%s: dma_intr: bad DMA status (dma_stat=%x)\n", |
| 117 | drive->name, dma_stat); |
| 118 | } |
| 119 | return ide_error(drive, "dma_intr", stat); |
| 120 | } |
| 121 | |
| 122 | EXPORT_SYMBOL_GPL(ide_dma_intr); |
| 123 | |
Bartlomiej Zolnierkiewicz | 75d7d96 | 2007-10-13 17:47:50 +0200 | [diff] [blame] | 124 | static int ide_dma_good_drive(ide_drive_t *drive) |
| 125 | { |
| 126 | return ide_in_drive_list(drive->id, drive_whitelist); |
| 127 | } |
| 128 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | /** |
| 130 | * ide_build_sglist - map IDE scatter gather for DMA I/O |
| 131 | * @drive: the drive to build the DMA table for |
| 132 | * @rq: the request holding the sg list |
| 133 | * |
Bartlomiej Zolnierkiewicz | 5c05ff6 | 2008-02-01 23:09:32 +0100 | [diff] [blame] | 134 | * Perform the DMA mapping magic necessary to access the source or |
| 135 | * target buffers of a request via DMA. The lower layers of the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | * kernel provide the necessary cache management so that we can |
Bartlomiej Zolnierkiewicz | 5c05ff6 | 2008-02-01 23:09:32 +0100 | [diff] [blame] | 137 | * operate in a portable fashion. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | */ |
| 139 | |
| 140 | int ide_build_sglist(ide_drive_t *drive, struct request *rq) |
| 141 | { |
| 142 | ide_hwif_t *hwif = HWIF(drive); |
| 143 | struct scatterlist *sg = hwif->sg_table; |
| 144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | ide_map_sg(drive, rq); |
| 146 | |
| 147 | if (rq_data_dir(rq) == READ) |
Bartlomiej Zolnierkiewicz | 5c05ff6 | 2008-02-01 23:09:32 +0100 | [diff] [blame] | 148 | hwif->sg_dma_direction = DMA_FROM_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | else |
Bartlomiej Zolnierkiewicz | 5c05ff6 | 2008-02-01 23:09:32 +0100 | [diff] [blame] | 150 | hwif->sg_dma_direction = DMA_TO_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Bartlomiej Zolnierkiewicz | 5c05ff6 | 2008-02-01 23:09:32 +0100 | [diff] [blame] | 152 | return dma_map_sg(hwif->dev, sg, hwif->sg_nents, |
| 153 | hwif->sg_dma_direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | EXPORT_SYMBOL_GPL(ide_build_sglist); |
| 157 | |
Sergei Shtylyov | 8e882ba | 2008-02-11 00:32:14 +0100 | [diff] [blame] | 158 | #ifdef CONFIG_BLK_DEV_IDEDMA_SFF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | /** |
| 160 | * ide_build_dmatable - build IDE DMA table |
| 161 | * |
| 162 | * ide_build_dmatable() prepares a dma request. We map the command |
| 163 | * to get the pci bus addresses of the buffers and then build up |
| 164 | * the PRD table that the IDE layer wants to be fed. The code |
| 165 | * knows about the 64K wrap bug in the CS5530. |
| 166 | * |
| 167 | * Returns the number of built PRD entries if all went okay, |
| 168 | * returns 0 otherwise. |
| 169 | * |
| 170 | * May also be invoked from trm290.c |
| 171 | */ |
| 172 | |
| 173 | int ide_build_dmatable (ide_drive_t *drive, struct request *rq) |
| 174 | { |
| 175 | ide_hwif_t *hwif = HWIF(drive); |
Harvey Harrison | 7fa897b | 2008-07-24 22:53:34 +0200 | [diff] [blame] | 176 | __le32 *table = (__le32 *)hwif->dmatable_cpu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | unsigned int is_trm290 = (hwif->chipset == ide_trm290) ? 1 : 0; |
| 178 | unsigned int count = 0; |
| 179 | int i; |
| 180 | struct scatterlist *sg; |
| 181 | |
| 182 | hwif->sg_nents = i = ide_build_sglist(drive, rq); |
| 183 | |
| 184 | if (!i) |
| 185 | return 0; |
| 186 | |
| 187 | sg = hwif->sg_table; |
| 188 | while (i) { |
| 189 | u32 cur_addr; |
| 190 | u32 cur_len; |
| 191 | |
| 192 | cur_addr = sg_dma_address(sg); |
| 193 | cur_len = sg_dma_len(sg); |
| 194 | |
| 195 | /* |
| 196 | * Fill in the dma table, without crossing any 64kB boundaries. |
| 197 | * Most hardware requires 16-bit alignment of all blocks, |
| 198 | * but the trm290 requires 32-bit alignment. |
| 199 | */ |
| 200 | |
| 201 | while (cur_len) { |
| 202 | if (count++ >= PRD_ENTRIES) { |
| 203 | printk(KERN_ERR "%s: DMA table too small\n", drive->name); |
| 204 | goto use_pio_instead; |
| 205 | } else { |
| 206 | u32 xcount, bcount = 0x10000 - (cur_addr & 0xffff); |
| 207 | |
| 208 | if (bcount > cur_len) |
| 209 | bcount = cur_len; |
| 210 | *table++ = cpu_to_le32(cur_addr); |
| 211 | xcount = bcount & 0xffff; |
| 212 | if (is_trm290) |
| 213 | xcount = ((xcount >> 2) - 1) << 16; |
Sergei Shtylylov | 22e05b4 | 2008-10-05 18:23:27 +0200 | [diff] [blame] | 214 | else if (xcount == 0x0000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | /* |
| 216 | * Most chipsets correctly interpret a length of 0x0000 as 64KB, |
| 217 | * but at least one (e.g. CS5530) misinterprets it as zero (!). |
| 218 | * So here we break the 64KB entry into two 32KB entries instead. |
| 219 | */ |
| 220 | if (count++ >= PRD_ENTRIES) { |
| 221 | printk(KERN_ERR "%s: DMA table too small\n", drive->name); |
| 222 | goto use_pio_instead; |
| 223 | } |
| 224 | *table++ = cpu_to_le32(0x8000); |
| 225 | *table++ = cpu_to_le32(cur_addr + 0x8000); |
| 226 | xcount = 0x8000; |
| 227 | } |
| 228 | *table++ = cpu_to_le32(xcount); |
| 229 | cur_addr += bcount; |
| 230 | cur_len -= bcount; |
| 231 | } |
| 232 | } |
| 233 | |
Jens Axboe | 55c16a7 | 2007-07-25 08:13:56 +0200 | [diff] [blame] | 234 | sg = sg_next(sg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | i--; |
| 236 | } |
| 237 | |
| 238 | if (count) { |
| 239 | if (!is_trm290) |
| 240 | *--table |= cpu_to_le32(0x80000000); |
| 241 | return count; |
| 242 | } |
Bartlomiej Zolnierkiewicz | f6fb786 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | printk(KERN_ERR "%s: empty DMA table?\n", drive->name); |
Bartlomiej Zolnierkiewicz | f6fb786 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | use_pio_instead: |
Bartlomiej Zolnierkiewicz | f6fb786 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 247 | ide_destroy_dmatable(drive); |
| 248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | return 0; /* revert to PIO for this request */ |
| 250 | } |
| 251 | |
| 252 | EXPORT_SYMBOL_GPL(ide_build_dmatable); |
Bartlomiej Zolnierkiewicz | 062f9f0 | 2008-02-01 23:09:32 +0100 | [diff] [blame] | 253 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | /** |
| 256 | * ide_destroy_dmatable - clean up DMA mapping |
| 257 | * @drive: The drive to unmap |
| 258 | * |
| 259 | * Teardown mappings after DMA has completed. This must be called |
| 260 | * after the completion of each use of ide_build_dmatable and before |
| 261 | * the next use of ide_build_dmatable. Failure to do so will cause |
| 262 | * an oops as only one mapping can be live for each target at a given |
| 263 | * time. |
| 264 | */ |
| 265 | |
| 266 | void ide_destroy_dmatable (ide_drive_t *drive) |
| 267 | { |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 268 | ide_hwif_t *hwif = drive->hwif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Bartlomiej Zolnierkiewicz | 5c05ff6 | 2008-02-01 23:09:32 +0100 | [diff] [blame] | 270 | dma_unmap_sg(hwif->dev, hwif->sg_table, hwif->sg_nents, |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 271 | hwif->sg_dma_direction); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | EXPORT_SYMBOL_GPL(ide_destroy_dmatable); |
| 275 | |
Sergei Shtylyov | 8e882ba | 2008-02-11 00:32:14 +0100 | [diff] [blame] | 276 | #ifdef CONFIG_BLK_DEV_IDEDMA_SFF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | /** |
| 278 | * config_drive_for_dma - attempt to activate IDE DMA |
| 279 | * @drive: the drive to place in DMA mode |
| 280 | * |
| 281 | * If the drive supports at least mode 2 DMA or UDMA of any kind |
| 282 | * then attempt to place it into DMA mode. Drives that are known to |
| 283 | * support DMA but predate the DMA properties or that are known |
| 284 | * to have DMA handling bugs are also set up appropriately based |
| 285 | * on the good/bad drive lists. |
| 286 | */ |
| 287 | |
| 288 | static int config_drive_for_dma (ide_drive_t *drive) |
| 289 | { |
Bartlomiej Zolnierkiewicz | 1116fae | 2007-08-20 22:42:55 +0200 | [diff] [blame] | 290 | ide_hwif_t *hwif = drive->hwif; |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 291 | u16 *id = drive->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Bartlomiej Zolnierkiewicz | 33c1002 | 2007-10-19 00:30:06 +0200 | [diff] [blame] | 293 | if (drive->media != ide_disk) { |
| 294 | if (hwif->host_flags & IDE_HFLAG_NO_ATAPI_DMA) |
Bartlomiej Zolnierkiewicz | bcbf6ee | 2007-11-05 21:42:30 +0100 | [diff] [blame] | 295 | return 0; |
Bartlomiej Zolnierkiewicz | 33c1002 | 2007-10-19 00:30:06 +0200 | [diff] [blame] | 296 | } |
Bartlomiej Zolnierkiewicz | 1116fae | 2007-08-20 22:42:55 +0200 | [diff] [blame] | 297 | |
Bartlomiej Zolnierkiewicz | 0ae2e17 | 2007-10-16 22:29:55 +0200 | [diff] [blame] | 298 | /* |
| 299 | * Enable DMA on any drive that has |
| 300 | * UltraDMA (mode 0/1/2/3/4/5/6) enabled |
| 301 | */ |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 302 | if ((id[ATA_ID_FIELD_VALID] & 4) && |
| 303 | ((id[ATA_ID_UDMA_MODES] >> 8) & 0x7f)) |
Bartlomiej Zolnierkiewicz | 0ae2e17 | 2007-10-16 22:29:55 +0200 | [diff] [blame] | 304 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
Bartlomiej Zolnierkiewicz | 0ae2e17 | 2007-10-16 22:29:55 +0200 | [diff] [blame] | 306 | /* |
| 307 | * Enable DMA on any drive that has mode2 DMA |
| 308 | * (multi or single) enabled |
| 309 | */ |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 310 | if (id[ATA_ID_FIELD_VALID] & 2) /* regular DMA */ |
| 311 | if ((id[ATA_ID_MWDMA_MODES] & 0x404) == 0x404 || |
| 312 | (id[ATA_ID_SWDMA_MODES] & 0x404) == 0x404) |
Bartlomiej Zolnierkiewicz | 0ae2e17 | 2007-10-16 22:29:55 +0200 | [diff] [blame] | 313 | return 1; |
Bartlomiej Zolnierkiewicz | 3608b5d | 2007-02-17 02:40:26 +0100 | [diff] [blame] | 314 | |
Bartlomiej Zolnierkiewicz | 0ae2e17 | 2007-10-16 22:29:55 +0200 | [diff] [blame] | 315 | /* Consult the list of known "good" drives */ |
| 316 | if (ide_dma_good_drive(drive)) |
| 317 | return 1; |
| 318 | |
| 319 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | /** |
| 323 | * dma_timer_expiry - handle a DMA timeout |
| 324 | * @drive: Drive that timed out |
| 325 | * |
| 326 | * An IDE DMA transfer timed out. In the event of an error we ask |
| 327 | * the driver to resolve the problem, if a DMA transfer is still |
| 328 | * in progress we continue to wait (arguably we need to add a |
| 329 | * secondary 'I don't care what the drive thinks' timeout here) |
| 330 | * Finally if we have an interrupt we let it complete the I/O. |
| 331 | * But only one time - we clear expiry and if it's still not |
| 332 | * completed after WAIT_CMD, we error and retry in PIO. |
| 333 | * This can occur if an interrupt is lost or due to hang or bugs. |
| 334 | */ |
| 335 | |
| 336 | static int dma_timer_expiry (ide_drive_t *drive) |
| 337 | { |
| 338 | ide_hwif_t *hwif = HWIF(drive); |
Bartlomiej Zolnierkiewicz | 374e042 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 339 | u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
| 341 | printk(KERN_WARNING "%s: dma_timer_expiry: dma status == 0x%02x\n", |
| 342 | drive->name, dma_stat); |
| 343 | |
| 344 | if ((dma_stat & 0x18) == 0x18) /* BUSY Stupid Early Timer !! */ |
| 345 | return WAIT_CMD; |
| 346 | |
| 347 | HWGROUP(drive)->expiry = NULL; /* one free ride for now */ |
| 348 | |
| 349 | /* 1 dmaing, 2 error, 4 intr */ |
| 350 | if (dma_stat & 2) /* ERROR */ |
| 351 | return -1; |
| 352 | |
| 353 | if (dma_stat & 1) /* DMAing */ |
| 354 | return WAIT_CMD; |
| 355 | |
| 356 | if (dma_stat & 4) /* Got an Interrupt */ |
| 357 | return WAIT_CMD; |
| 358 | |
| 359 | return 0; /* Status is unknown -- reset the bus */ |
| 360 | } |
| 361 | |
| 362 | /** |
Bartlomiej Zolnierkiewicz | 15ce926 | 2008-01-26 20:13:03 +0100 | [diff] [blame] | 363 | * ide_dma_host_set - Enable/disable DMA on a host |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | * @drive: drive to control |
| 365 | * |
Bartlomiej Zolnierkiewicz | 15ce926 | 2008-01-26 20:13:03 +0100 | [diff] [blame] | 366 | * Enable/disable DMA on an IDE controller following generic |
| 367 | * bus-mastering IDE controller behaviour. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | */ |
| 369 | |
Bartlomiej Zolnierkiewicz | 15ce926 | 2008-01-26 20:13:03 +0100 | [diff] [blame] | 370 | void ide_dma_host_set(ide_drive_t *drive, int on) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | { |
| 372 | ide_hwif_t *hwif = HWIF(drive); |
| 373 | u8 unit = (drive->select.b.unit & 0x01); |
Bartlomiej Zolnierkiewicz | 374e042 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 374 | u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
Bartlomiej Zolnierkiewicz | 15ce926 | 2008-01-26 20:13:03 +0100 | [diff] [blame] | 376 | if (on) |
| 377 | dma_stat |= (1 << (5 + unit)); |
| 378 | else |
| 379 | dma_stat &= ~(1 << (5 + unit)); |
| 380 | |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 381 | if (hwif->host_flags & IDE_HFLAG_MMIO) |
Bartlomiej Zolnierkiewicz | cab7f8e | 2008-07-23 19:55:51 +0200 | [diff] [blame] | 382 | writeb(dma_stat, |
| 383 | (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS)); |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 384 | else |
Bartlomiej Zolnierkiewicz | cab7f8e | 2008-07-23 19:55:51 +0200 | [diff] [blame] | 385 | outb(dma_stat, hwif->dma_base + ATA_DMA_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
| 387 | |
Bartlomiej Zolnierkiewicz | 15ce926 | 2008-01-26 20:13:03 +0100 | [diff] [blame] | 388 | EXPORT_SYMBOL_GPL(ide_dma_host_set); |
Sergei Shtylyov | 8e882ba | 2008-02-11 00:32:14 +0100 | [diff] [blame] | 389 | #endif /* CONFIG_BLK_DEV_IDEDMA_SFF */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
| 391 | /** |
Bartlomiej Zolnierkiewicz | 7469aaf | 2007-02-17 02:40:26 +0100 | [diff] [blame] | 392 | * ide_dma_off_quietly - Generic DMA kill |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | * @drive: drive to control |
| 394 | * |
| 395 | * Turn off the current DMA on this IDE controller. |
| 396 | */ |
| 397 | |
Bartlomiej Zolnierkiewicz | 7469aaf | 2007-02-17 02:40:26 +0100 | [diff] [blame] | 398 | void ide_dma_off_quietly(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | { |
| 400 | drive->using_dma = 0; |
| 401 | ide_toggle_bounce(drive, 0); |
| 402 | |
Bartlomiej Zolnierkiewicz | 5e37bdc | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 403 | drive->hwif->dma_ops->dma_host_set(drive, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Bartlomiej Zolnierkiewicz | 7469aaf | 2007-02-17 02:40:26 +0100 | [diff] [blame] | 406 | EXPORT_SYMBOL(ide_dma_off_quietly); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
| 408 | /** |
Bartlomiej Zolnierkiewicz | 7469aaf | 2007-02-17 02:40:26 +0100 | [diff] [blame] | 409 | * ide_dma_off - disable DMA on a device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | * @drive: drive to disable DMA on |
| 411 | * |
| 412 | * Disable IDE DMA for a device on this IDE controller. |
| 413 | * Inform the user that DMA has been disabled. |
| 414 | */ |
| 415 | |
Bartlomiej Zolnierkiewicz | 7469aaf | 2007-02-17 02:40:26 +0100 | [diff] [blame] | 416 | void ide_dma_off(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | { |
| 418 | printk(KERN_INFO "%s: DMA disabled\n", drive->name); |
Bartlomiej Zolnierkiewicz | 4a546e0 | 2008-01-26 20:13:01 +0100 | [diff] [blame] | 419 | ide_dma_off_quietly(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | } |
| 421 | |
Bartlomiej Zolnierkiewicz | 7469aaf | 2007-02-17 02:40:26 +0100 | [diff] [blame] | 422 | EXPORT_SYMBOL(ide_dma_off); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | /** |
Bartlomiej Zolnierkiewicz | 4a546e0 | 2008-01-26 20:13:01 +0100 | [diff] [blame] | 425 | * ide_dma_on - Enable DMA on a device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | * @drive: drive to enable DMA on |
| 427 | * |
| 428 | * Enable IDE DMA for a device on this IDE controller. |
| 429 | */ |
Bartlomiej Zolnierkiewicz | 4a546e0 | 2008-01-26 20:13:01 +0100 | [diff] [blame] | 430 | |
| 431 | void ide_dma_on(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | drive->using_dma = 1; |
| 434 | ide_toggle_bounce(drive, 1); |
| 435 | |
Bartlomiej Zolnierkiewicz | 5e37bdc | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 436 | drive->hwif->dma_ops->dma_host_set(drive, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } |
| 438 | |
Sergei Shtylyov | 8e882ba | 2008-02-11 00:32:14 +0100 | [diff] [blame] | 439 | #ifdef CONFIG_BLK_DEV_IDEDMA_SFF |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | * ide_dma_setup - begin a DMA phase |
| 442 | * @drive: target device |
| 443 | * |
| 444 | * Build an IDE DMA PRD (IDE speak for scatter gather table) |
| 445 | * and then set up the DMA transfer registers for a device |
| 446 | * that follows generic IDE PCI DMA behaviour. Controllers can |
| 447 | * override this function if they need to |
| 448 | * |
| 449 | * Returns 0 on success. If a PIO fallback is required then 1 |
| 450 | * is returned. |
| 451 | */ |
| 452 | |
| 453 | int ide_dma_setup(ide_drive_t *drive) |
| 454 | { |
| 455 | ide_hwif_t *hwif = drive->hwif; |
| 456 | struct request *rq = HWGROUP(drive)->rq; |
| 457 | unsigned int reading; |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 458 | u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | u8 dma_stat; |
| 460 | |
| 461 | if (rq_data_dir(rq)) |
| 462 | reading = 0; |
| 463 | else |
| 464 | reading = 1 << 3; |
| 465 | |
| 466 | /* fall back to pio! */ |
| 467 | if (!ide_build_dmatable(drive, rq)) { |
| 468 | ide_map_sg(drive, rq); |
| 469 | return 1; |
| 470 | } |
| 471 | |
| 472 | /* PRD table */ |
Bartlomiej Zolnierkiewicz | 1357214 | 2008-07-15 21:21:49 +0200 | [diff] [blame] | 473 | if (hwif->host_flags & IDE_HFLAG_MMIO) |
Bartlomiej Zolnierkiewicz | 55224bc | 2008-04-28 23:44:42 +0200 | [diff] [blame] | 474 | writel(hwif->dmatable_dma, |
| 475 | (void __iomem *)(hwif->dma_base + ATA_DMA_TABLE_OFS)); |
Bartlomiej Zolnierkiewicz | 0ecdca2 | 2007-02-17 02:40:25 +0100 | [diff] [blame] | 476 | else |
Bartlomiej Zolnierkiewicz | 55224bc | 2008-04-28 23:44:42 +0200 | [diff] [blame] | 477 | outl(hwif->dmatable_dma, hwif->dma_base + ATA_DMA_TABLE_OFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
| 479 | /* specify r/w */ |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 480 | if (mmio) |
Bartlomiej Zolnierkiewicz | cab7f8e | 2008-07-23 19:55:51 +0200 | [diff] [blame] | 481 | writeb(reading, (void __iomem *)(hwif->dma_base + ATA_DMA_CMD)); |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 482 | else |
Bartlomiej Zolnierkiewicz | cab7f8e | 2008-07-23 19:55:51 +0200 | [diff] [blame] | 483 | outb(reading, hwif->dma_base + ATA_DMA_CMD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
Bartlomiej Zolnierkiewicz | b2f951a | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 485 | /* read DMA status for INTR & ERROR flags */ |
Bartlomiej Zolnierkiewicz | 374e042 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 486 | dma_stat = hwif->tp_ops->read_sff_dma_status(hwif); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
| 488 | /* clear INTR & ERROR flags */ |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 489 | if (mmio) |
Bartlomiej Zolnierkiewicz | cab7f8e | 2008-07-23 19:55:51 +0200 | [diff] [blame] | 490 | writeb(dma_stat | 6, |
| 491 | (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS)); |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 492 | else |
Bartlomiej Zolnierkiewicz | cab7f8e | 2008-07-23 19:55:51 +0200 | [diff] [blame] | 493 | outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS); |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | drive->waiting_for_dma = 1; |
| 496 | return 0; |
| 497 | } |
| 498 | |
| 499 | EXPORT_SYMBOL_GPL(ide_dma_setup); |
| 500 | |
Bartlomiej Zolnierkiewicz | f37afda | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 501 | void ide_dma_exec_cmd(ide_drive_t *drive, u8 command) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | { |
| 503 | /* issue cmd to drive */ |
| 504 | ide_execute_command(drive, command, &ide_dma_intr, 2*WAIT_CMD, dma_timer_expiry); |
| 505 | } |
Bartlomiej Zolnierkiewicz | f37afda | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 506 | EXPORT_SYMBOL_GPL(ide_dma_exec_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
| 508 | void ide_dma_start(ide_drive_t *drive) |
| 509 | { |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 510 | ide_hwif_t *hwif = drive->hwif; |
| 511 | u8 dma_cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
| 513 | /* Note that this is done *after* the cmd has |
| 514 | * been issued to the drive, as per the BM-IDE spec. |
| 515 | * The Promise Ultra33 doesn't work correctly when |
| 516 | * we do this part before issuing the drive cmd. |
| 517 | */ |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 518 | if (hwif->host_flags & IDE_HFLAG_MMIO) { |
Bartlomiej Zolnierkiewicz | cab7f8e | 2008-07-23 19:55:51 +0200 | [diff] [blame] | 519 | dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD)); |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 520 | /* start DMA */ |
Bartlomiej Zolnierkiewicz | cab7f8e | 2008-07-23 19:55:51 +0200 | [diff] [blame] | 521 | writeb(dma_cmd | 1, |
| 522 | (void __iomem *)(hwif->dma_base + ATA_DMA_CMD)); |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 523 | } else { |
Bartlomiej Zolnierkiewicz | cab7f8e | 2008-07-23 19:55:51 +0200 | [diff] [blame] | 524 | dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD); |
| 525 | outb(dma_cmd | 1, hwif->dma_base + ATA_DMA_CMD); |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 526 | } |
| 527 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | hwif->dma = 1; |
| 529 | wmb(); |
| 530 | } |
| 531 | |
| 532 | EXPORT_SYMBOL_GPL(ide_dma_start); |
| 533 | |
| 534 | /* returns 1 on error, 0 otherwise */ |
| 535 | int __ide_dma_end (ide_drive_t *drive) |
| 536 | { |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 537 | ide_hwif_t *hwif = drive->hwif; |
| 538 | u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | u8 dma_stat = 0, dma_cmd = 0; |
| 540 | |
| 541 | drive->waiting_for_dma = 0; |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 542 | |
| 543 | if (mmio) { |
| 544 | /* get DMA command mode */ |
Bartlomiej Zolnierkiewicz | cab7f8e | 2008-07-23 19:55:51 +0200 | [diff] [blame] | 545 | dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD)); |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 546 | /* stop DMA */ |
Bartlomiej Zolnierkiewicz | cab7f8e | 2008-07-23 19:55:51 +0200 | [diff] [blame] | 547 | writeb(dma_cmd & ~1, |
| 548 | (void __iomem *)(hwif->dma_base + ATA_DMA_CMD)); |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 549 | } else { |
Bartlomiej Zolnierkiewicz | cab7f8e | 2008-07-23 19:55:51 +0200 | [diff] [blame] | 550 | dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD); |
| 551 | outb(dma_cmd & ~1, hwif->dma_base + ATA_DMA_CMD); |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 552 | } |
| 553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | /* get DMA status */ |
Bartlomiej Zolnierkiewicz | 374e042 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 555 | dma_stat = hwif->tp_ops->read_sff_dma_status(hwif); |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 556 | |
| 557 | if (mmio) |
| 558 | /* clear the INTR & ERROR bits */ |
Bartlomiej Zolnierkiewicz | cab7f8e | 2008-07-23 19:55:51 +0200 | [diff] [blame] | 559 | writeb(dma_stat | 6, |
| 560 | (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS)); |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 561 | else |
Bartlomiej Zolnierkiewicz | cab7f8e | 2008-07-23 19:55:51 +0200 | [diff] [blame] | 562 | outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS); |
Bartlomiej Zolnierkiewicz | ab86f91 | 2008-07-23 19:55:50 +0200 | [diff] [blame] | 563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | /* purge DMA mappings */ |
| 565 | ide_destroy_dmatable(drive); |
| 566 | /* verify good DMA status */ |
| 567 | hwif->dma = 0; |
| 568 | wmb(); |
| 569 | return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0; |
| 570 | } |
| 571 | |
| 572 | EXPORT_SYMBOL(__ide_dma_end); |
| 573 | |
| 574 | /* returns 1 if dma irq issued, 0 otherwise */ |
Bartlomiej Zolnierkiewicz | f37afda | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 575 | int ide_dma_test_irq(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | { |
| 577 | ide_hwif_t *hwif = HWIF(drive); |
Bartlomiej Zolnierkiewicz | 374e042 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 578 | u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | /* return 1 if INTR asserted */ |
| 581 | if ((dma_stat & 4) == 4) |
| 582 | return 1; |
| 583 | if (!drive->waiting_for_dma) |
| 584 | printk(KERN_WARNING "%s: (%s) called while not waiting\n", |
Harvey Harrison | eb63963 | 2008-04-26 22:25:20 +0200 | [diff] [blame] | 585 | drive->name, __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | return 0; |
| 587 | } |
Bartlomiej Zolnierkiewicz | f37afda | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 588 | EXPORT_SYMBOL_GPL(ide_dma_test_irq); |
Bartlomiej Zolnierkiewicz | 0ae2e17 | 2007-10-16 22:29:55 +0200 | [diff] [blame] | 589 | #else |
| 590 | static inline int config_drive_for_dma(ide_drive_t *drive) { return 0; } |
Sergei Shtylyov | 8e882ba | 2008-02-11 00:32:14 +0100 | [diff] [blame] | 591 | #endif /* CONFIG_BLK_DEV_IDEDMA_SFF */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
| 593 | int __ide_dma_bad_drive (ide_drive_t *drive) |
| 594 | { |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 595 | u16 *id = drive->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | |
Jordan Crouse | 65e5f2e | 2005-12-15 02:16:18 +0100 | [diff] [blame] | 597 | int blacklist = ide_in_drive_list(id, drive_blacklist); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | if (blacklist) { |
| 599 | printk(KERN_WARNING "%s: Disabling (U)DMA for %s (blacklisted)\n", |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 600 | drive->name, (char *)&id[ATA_ID_PROD]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | return blacklist; |
| 602 | } |
| 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | EXPORT_SYMBOL(__ide_dma_bad_drive); |
| 607 | |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 608 | static const u8 xfer_mode_bases[] = { |
| 609 | XFER_UDMA_0, |
| 610 | XFER_MW_DMA_0, |
| 611 | XFER_SW_DMA_0, |
| 612 | }; |
| 613 | |
Bartlomiej Zolnierkiewicz | 7670df7 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 614 | static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base, u8 req_mode) |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 615 | { |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 616 | u16 *id = drive->id; |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 617 | ide_hwif_t *hwif = drive->hwif; |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 618 | const struct ide_port_ops *port_ops = hwif->port_ops; |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 619 | unsigned int mask = 0; |
| 620 | |
| 621 | switch(base) { |
| 622 | case XFER_UDMA_0: |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 623 | if ((id[ATA_ID_FIELD_VALID] & 4) == 0) |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 624 | break; |
| 625 | |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 626 | if (port_ops && port_ops->udma_filter) |
| 627 | mask = port_ops->udma_filter(drive); |
Sergei Shtylyov | 851dd33 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 628 | else |
| 629 | mask = hwif->ultra_mask; |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 630 | mask &= id[ATA_ID_UDMA_MODES]; |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 631 | |
Bartlomiej Zolnierkiewicz | 7670df7 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 632 | /* |
| 633 | * avoid false cable warning from eighty_ninty_three() |
| 634 | */ |
| 635 | if (req_mode > XFER_UDMA_2) { |
| 636 | if ((mask & 0x78) && (eighty_ninty_three(drive) == 0)) |
| 637 | mask &= 0x07; |
| 638 | } |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 639 | break; |
| 640 | case XFER_MW_DMA_0: |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 641 | if ((id[ATA_ID_FIELD_VALID] & 2) == 0) |
Sergei Shtylyov | b4e4436 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 642 | break; |
Bartlomiej Zolnierkiewicz | ac95bee | 2008-04-26 22:25:14 +0200 | [diff] [blame] | 643 | if (port_ops && port_ops->mdma_filter) |
| 644 | mask = port_ops->mdma_filter(drive); |
Sergei Shtylyov | b4e4436 | 2007-10-11 23:53:58 +0200 | [diff] [blame] | 645 | else |
| 646 | mask = hwif->mwdma_mask; |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 647 | mask &= id[ATA_ID_MWDMA_MODES]; |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 648 | break; |
| 649 | case XFER_SW_DMA_0: |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 650 | if (id[ATA_ID_FIELD_VALID] & 2) { |
| 651 | mask = id[ATA_ID_SWDMA_MODES] & hwif->swdma_mask; |
Bartlomiej Zolnierkiewicz | 48fb268 | 2008-10-10 22:39:19 +0200 | [diff] [blame^] | 652 | } else if (id[ATA_ID_OLD_DMA_MODES] >> 8) { |
| 653 | u8 mode = id[ATA_ID_OLD_DMA_MODES] >> 8; |
Bartlomiej Zolnierkiewicz | 15a4f94 | 2007-07-09 23:17:57 +0200 | [diff] [blame] | 654 | |
| 655 | /* |
| 656 | * if the mode is valid convert it to the mask |
| 657 | * (the maximum allowed mode is XFER_SW_DMA_2) |
| 658 | */ |
| 659 | if (mode <= 2) |
| 660 | mask = ((2 << mode) - 1) & hwif->swdma_mask; |
| 661 | } |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 662 | break; |
| 663 | default: |
| 664 | BUG(); |
| 665 | break; |
| 666 | } |
| 667 | |
| 668 | return mask; |
| 669 | } |
| 670 | |
| 671 | /** |
Bartlomiej Zolnierkiewicz | 7670df7 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 672 | * ide_find_dma_mode - compute DMA speed |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 673 | * @drive: IDE device |
Bartlomiej Zolnierkiewicz | 7670df7 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 674 | * @req_mode: requested mode |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 675 | * |
Bartlomiej Zolnierkiewicz | 7670df7 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 676 | * Checks the drive/host capabilities and finds the speed to use for |
| 677 | * the DMA transfer. The speed is then limited by the requested mode. |
| 678 | * |
| 679 | * Returns 0 if the drive/host combination is incapable of DMA transfers |
| 680 | * or if the requested mode is not a DMA mode. |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 681 | */ |
| 682 | |
Bartlomiej Zolnierkiewicz | 7670df7 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 683 | u8 ide_find_dma_mode(ide_drive_t *drive, u8 req_mode) |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 684 | { |
| 685 | ide_hwif_t *hwif = drive->hwif; |
| 686 | unsigned int mask; |
| 687 | int x, i; |
| 688 | u8 mode = 0; |
| 689 | |
Bartlomiej Zolnierkiewicz | 33c1002 | 2007-10-19 00:30:06 +0200 | [diff] [blame] | 690 | if (drive->media != ide_disk) { |
| 691 | if (hwif->host_flags & IDE_HFLAG_NO_ATAPI_DMA) |
| 692 | return 0; |
| 693 | } |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 694 | |
| 695 | for (i = 0; i < ARRAY_SIZE(xfer_mode_bases); i++) { |
Bartlomiej Zolnierkiewicz | 7670df7 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 696 | if (req_mode < xfer_mode_bases[i]) |
| 697 | continue; |
| 698 | mask = ide_get_mode_mask(drive, xfer_mode_bases[i], req_mode); |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 699 | x = fls(mask) - 1; |
| 700 | if (x >= 0) { |
| 701 | mode = xfer_mode_bases[i] + x; |
| 702 | break; |
| 703 | } |
| 704 | } |
| 705 | |
Bartlomiej Zolnierkiewicz | 75d7d96 | 2007-10-13 17:47:50 +0200 | [diff] [blame] | 706 | if (hwif->chipset == ide_acorn && mode == 0) { |
| 707 | /* |
| 708 | * is this correct? |
| 709 | */ |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 710 | if (ide_dma_good_drive(drive) && |
| 711 | drive->id[ATA_ID_EIDE_DMA_TIME] < 150) |
Bartlomiej Zolnierkiewicz | 75d7d96 | 2007-10-13 17:47:50 +0200 | [diff] [blame] | 712 | mode = XFER_MW_DMA_1; |
| 713 | } |
| 714 | |
Bartlomiej Zolnierkiewicz | 3ab7efe | 2007-12-12 23:31:58 +0100 | [diff] [blame] | 715 | mode = min(mode, req_mode); |
| 716 | |
| 717 | printk(KERN_INFO "%s: %s mode selected\n", drive->name, |
Bartlomiej Zolnierkiewicz | d34887d | 2007-11-05 21:42:27 +0100 | [diff] [blame] | 718 | mode ? ide_xfer_verbose(mode) : "no DMA"); |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 719 | |
Bartlomiej Zolnierkiewicz | 3ab7efe | 2007-12-12 23:31:58 +0100 | [diff] [blame] | 720 | return mode; |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 721 | } |
| 722 | |
Bartlomiej Zolnierkiewicz | 7670df7 | 2007-10-11 23:53:59 +0200 | [diff] [blame] | 723 | EXPORT_SYMBOL_GPL(ide_find_dma_mode); |
Bartlomiej Zolnierkiewicz | 2d5eaa6 | 2007-05-10 00:01:08 +0200 | [diff] [blame] | 724 | |
Bartlomiej Zolnierkiewicz | 0ae2e17 | 2007-10-16 22:29:55 +0200 | [diff] [blame] | 725 | static int ide_tune_dma(ide_drive_t *drive) |
Bartlomiej Zolnierkiewicz | 29e744d | 2007-05-10 00:01:09 +0200 | [diff] [blame] | 726 | { |
Bartlomiej Zolnierkiewicz | 8704de8 | 2008-01-26 20:13:00 +0100 | [diff] [blame] | 727 | ide_hwif_t *hwif = drive->hwif; |
Bartlomiej Zolnierkiewicz | 29e744d | 2007-05-10 00:01:09 +0200 | [diff] [blame] | 728 | u8 speed; |
| 729 | |
Bartlomiej Zolnierkiewicz | 48fb268 | 2008-10-10 22:39:19 +0200 | [diff] [blame^] | 730 | if (drive->nodma || ata_id_has_dma(drive->id) == 0) |
Bartlomiej Zolnierkiewicz | 122ab08 | 2007-05-16 00:51:46 +0200 | [diff] [blame] | 731 | return 0; |
| 732 | |
| 733 | /* consult the list of known "bad" drives */ |
| 734 | if (__ide_dma_bad_drive(drive)) |
Bartlomiej Zolnierkiewicz | 29e744d | 2007-05-10 00:01:09 +0200 | [diff] [blame] | 735 | return 0; |
| 736 | |
Bartlomiej Zolnierkiewicz | 3ab7efe | 2007-12-12 23:31:58 +0100 | [diff] [blame] | 737 | if (ide_id_dma_bug(drive)) |
| 738 | return 0; |
| 739 | |
Bartlomiej Zolnierkiewicz | 8704de8 | 2008-01-26 20:13:00 +0100 | [diff] [blame] | 740 | if (hwif->host_flags & IDE_HFLAG_TRUST_BIOS_FOR_DMA) |
Bartlomiej Zolnierkiewicz | 0ae2e17 | 2007-10-16 22:29:55 +0200 | [diff] [blame] | 741 | return config_drive_for_dma(drive); |
| 742 | |
Bartlomiej Zolnierkiewicz | 29e744d | 2007-05-10 00:01:09 +0200 | [diff] [blame] | 743 | speed = ide_max_dma_mode(drive); |
| 744 | |
Bartlomiej Zolnierkiewicz | 951784b | 2008-04-26 17:36:38 +0200 | [diff] [blame] | 745 | if (!speed) |
| 746 | return 0; |
Bartlomiej Zolnierkiewicz | 29e744d | 2007-05-10 00:01:09 +0200 | [diff] [blame] | 747 | |
Bartlomiej Zolnierkiewicz | 88b2b32 | 2007-10-13 17:47:51 +0200 | [diff] [blame] | 748 | if (ide_set_dma_mode(drive, speed)) |
Bartlomiej Zolnierkiewicz | 4728d54 | 2007-05-16 00:51:46 +0200 | [diff] [blame] | 749 | return 0; |
Bartlomiej Zolnierkiewicz | 29e744d | 2007-05-10 00:01:09 +0200 | [diff] [blame] | 750 | |
Bartlomiej Zolnierkiewicz | 4728d54 | 2007-05-16 00:51:46 +0200 | [diff] [blame] | 751 | return 1; |
Bartlomiej Zolnierkiewicz | 29e744d | 2007-05-10 00:01:09 +0200 | [diff] [blame] | 752 | } |
| 753 | |
Bartlomiej Zolnierkiewicz | 0ae2e17 | 2007-10-16 22:29:55 +0200 | [diff] [blame] | 754 | static int ide_dma_check(ide_drive_t *drive) |
| 755 | { |
| 756 | ide_hwif_t *hwif = drive->hwif; |
Bartlomiej Zolnierkiewicz | 0ae2e17 | 2007-10-16 22:29:55 +0200 | [diff] [blame] | 757 | |
Bartlomiej Zolnierkiewicz | ba4b2e6 | 2008-07-23 19:55:55 +0200 | [diff] [blame] | 758 | if (ide_tune_dma(drive)) |
Bartlomiej Zolnierkiewicz | 0ae2e17 | 2007-10-16 22:29:55 +0200 | [diff] [blame] | 759 | return 0; |
| 760 | |
| 761 | /* TODO: always do PIO fallback */ |
| 762 | if (hwif->host_flags & IDE_HFLAG_TRUST_BIOS_FOR_DMA) |
| 763 | return -1; |
| 764 | |
| 765 | ide_set_max_pio(drive); |
| 766 | |
Bartlomiej Zolnierkiewicz | ba4b2e6 | 2008-07-23 19:55:55 +0200 | [diff] [blame] | 767 | return -1; |
Bartlomiej Zolnierkiewicz | 0ae2e17 | 2007-10-16 22:29:55 +0200 | [diff] [blame] | 768 | } |
| 769 | |
Bartlomiej Zolnierkiewicz | 3ab7efe | 2007-12-12 23:31:58 +0100 | [diff] [blame] | 770 | int ide_id_dma_bug(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | { |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 772 | u16 *id = drive->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 774 | if (id[ATA_ID_FIELD_VALID] & 4) { |
| 775 | if ((id[ATA_ID_UDMA_MODES] >> 8) && |
| 776 | (id[ATA_ID_MWDMA_MODES] >> 8)) |
Bartlomiej Zolnierkiewicz | 3ab7efe | 2007-12-12 23:31:58 +0100 | [diff] [blame] | 777 | goto err_out; |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 778 | } else if (id[ATA_ID_FIELD_VALID] & 2) { |
| 779 | if ((id[ATA_ID_MWDMA_MODES] >> 8) && |
| 780 | (id[ATA_ID_SWDMA_MODES] >> 8)) |
Bartlomiej Zolnierkiewicz | 3ab7efe | 2007-12-12 23:31:58 +0100 | [diff] [blame] | 781 | goto err_out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | } |
Bartlomiej Zolnierkiewicz | 3ab7efe | 2007-12-12 23:31:58 +0100 | [diff] [blame] | 783 | return 0; |
| 784 | err_out: |
| 785 | printk(KERN_ERR "%s: bad DMA info in identify block\n", drive->name); |
| 786 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | } |
| 788 | |
Bartlomiej Zolnierkiewicz | 3608b5d | 2007-02-17 02:40:26 +0100 | [diff] [blame] | 789 | int ide_set_dma(ide_drive_t *drive) |
| 790 | { |
Bartlomiej Zolnierkiewicz | 3608b5d | 2007-02-17 02:40:26 +0100 | [diff] [blame] | 791 | int rc; |
| 792 | |
Bartlomiej Zolnierkiewicz | 7b90599 | 2008-01-25 22:17:19 +0100 | [diff] [blame] | 793 | /* |
| 794 | * Force DMAing for the beginning of the check. |
| 795 | * Some chipsets appear to do interesting |
| 796 | * things, if not checked and cleared. |
| 797 | * PARANOIA!!! |
| 798 | */ |
Bartlomiej Zolnierkiewicz | 4a546e0 | 2008-01-26 20:13:01 +0100 | [diff] [blame] | 799 | ide_dma_off_quietly(drive); |
Bartlomiej Zolnierkiewicz | 7b90599 | 2008-01-25 22:17:19 +0100 | [diff] [blame] | 800 | |
Bartlomiej Zolnierkiewicz | 0ae2e17 | 2007-10-16 22:29:55 +0200 | [diff] [blame] | 801 | rc = ide_dma_check(drive); |
Bartlomiej Zolnierkiewicz | 7b90599 | 2008-01-25 22:17:19 +0100 | [diff] [blame] | 802 | if (rc) |
| 803 | return rc; |
Bartlomiej Zolnierkiewicz | 3608b5d | 2007-02-17 02:40:26 +0100 | [diff] [blame] | 804 | |
Bartlomiej Zolnierkiewicz | 4a546e0 | 2008-01-26 20:13:01 +0100 | [diff] [blame] | 805 | ide_dma_on(drive); |
| 806 | |
| 807 | return 0; |
Bartlomiej Zolnierkiewicz | 3608b5d | 2007-02-17 02:40:26 +0100 | [diff] [blame] | 808 | } |
| 809 | |
Bartlomiej Zolnierkiewicz | 578cfa0 | 2008-02-02 19:56:47 +0100 | [diff] [blame] | 810 | void ide_check_dma_crc(ide_drive_t *drive) |
| 811 | { |
| 812 | u8 mode; |
| 813 | |
| 814 | ide_dma_off_quietly(drive); |
| 815 | drive->crc_count = 0; |
| 816 | mode = drive->current_speed; |
| 817 | /* |
| 818 | * Don't try non Ultra-DMA modes without iCRC's. Force the |
| 819 | * device to PIO and make the user enable SWDMA/MWDMA modes. |
| 820 | */ |
| 821 | if (mode > XFER_UDMA_0 && mode <= XFER_UDMA_7) |
| 822 | mode--; |
| 823 | else |
| 824 | mode = XFER_PIO_4; |
| 825 | ide_set_xfer_rate(drive, mode); |
| 826 | if (drive->current_speed >= XFER_SW_DMA_0) |
| 827 | ide_dma_on(drive); |
| 828 | } |
| 829 | |
Sergei Shtylyov | 8e882ba | 2008-02-11 00:32:14 +0100 | [diff] [blame] | 830 | #ifdef CONFIG_BLK_DEV_IDEDMA_SFF |
Sergei Shtylyov | 841d2a9 | 2007-07-09 23:17:54 +0200 | [diff] [blame] | 831 | void ide_dma_lost_irq (ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | { |
| 833 | printk("%s: DMA interrupt recovery\n", drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | } |
| 835 | |
Sergei Shtylyov | 841d2a9 | 2007-07-09 23:17:54 +0200 | [diff] [blame] | 836 | EXPORT_SYMBOL(ide_dma_lost_irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | |
Sergei Shtylyov | c283f5d | 2007-07-09 23:17:54 +0200 | [diff] [blame] | 838 | void ide_dma_timeout (ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | { |
Sergei Shtylyov | c283f5d | 2007-07-09 23:17:54 +0200 | [diff] [blame] | 840 | ide_hwif_t *hwif = HWIF(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | |
Sergei Shtylyov | c283f5d | 2007-07-09 23:17:54 +0200 | [diff] [blame] | 842 | printk(KERN_ERR "%s: timeout waiting for DMA\n", drive->name); |
| 843 | |
Bartlomiej Zolnierkiewicz | 5e37bdc | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 844 | if (hwif->dma_ops->dma_test_irq(drive)) |
Sergei Shtylyov | c283f5d | 2007-07-09 23:17:54 +0200 | [diff] [blame] | 845 | return; |
| 846 | |
Bartlomiej Zolnierkiewicz | 5e37bdc | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 847 | hwif->dma_ops->dma_end(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | } |
| 849 | |
Sergei Shtylyov | c283f5d | 2007-07-09 23:17:54 +0200 | [diff] [blame] | 850 | EXPORT_SYMBOL(ide_dma_timeout); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | |
Bartlomiej Zolnierkiewicz | 0d1bad2 | 2008-04-26 22:25:19 +0200 | [diff] [blame] | 852 | void ide_release_dma_engine(ide_hwif_t *hwif) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | { |
| 854 | if (hwif->dmatable_cpu) { |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 855 | struct pci_dev *pdev = to_pci_dev(hwif->dev); |
| 856 | |
| 857 | pci_free_consistent(pdev, PRD_ENTRIES * PRD_BYTES, |
| 858 | hwif->dmatable_cpu, hwif->dmatable_dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | hwif->dmatable_cpu = NULL; |
| 860 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | } |
| 862 | |
Bartlomiej Zolnierkiewicz | b8e73fb | 2008-04-26 22:25:21 +0200 | [diff] [blame] | 863 | int ide_allocate_dma_engine(ide_hwif_t *hwif) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | { |
Bartlomiej Zolnierkiewicz | 3650165 | 2008-02-01 23:09:31 +0100 | [diff] [blame] | 865 | struct pci_dev *pdev = to_pci_dev(hwif->dev); |
| 866 | |
| 867 | hwif->dmatable_cpu = pci_alloc_consistent(pdev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | PRD_ENTRIES * PRD_BYTES, |
| 869 | &hwif->dmatable_dma); |
| 870 | |
| 871 | if (hwif->dmatable_cpu) |
| 872 | return 0; |
| 873 | |
Sergei Shtylylov | dc844e0 | 2006-10-03 01:14:14 -0700 | [diff] [blame] | 874 | printk(KERN_ERR "%s: -- Error, unable to allocate DMA table.\n", |
Bartlomiej Zolnierkiewicz | 5e59c23 | 2008-04-26 22:25:20 +0200 | [diff] [blame] | 875 | hwif->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | return 1; |
| 878 | } |
Bartlomiej Zolnierkiewicz | b8e73fb | 2008-04-26 22:25:21 +0200 | [diff] [blame] | 879 | EXPORT_SYMBOL_GPL(ide_allocate_dma_engine); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
Bartlomiej Zolnierkiewicz | 81e8d5a | 2008-07-23 19:55:51 +0200 | [diff] [blame] | 881 | const struct ide_dma_ops sff_dma_ops = { |
Bartlomiej Zolnierkiewicz | 5e37bdc | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 882 | .dma_host_set = ide_dma_host_set, |
| 883 | .dma_setup = ide_dma_setup, |
| 884 | .dma_exec_cmd = ide_dma_exec_cmd, |
| 885 | .dma_start = ide_dma_start, |
| 886 | .dma_end = __ide_dma_end, |
Bartlomiej Zolnierkiewicz | f37afda | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 887 | .dma_test_irq = ide_dma_test_irq, |
Bartlomiej Zolnierkiewicz | 5e37bdc | 2008-04-26 22:25:24 +0200 | [diff] [blame] | 888 | .dma_timeout = ide_dma_timeout, |
| 889 | .dma_lost_irq = ide_dma_lost_irq, |
| 890 | }; |
Bartlomiej Zolnierkiewicz | 81e8d5a | 2008-07-23 19:55:51 +0200 | [diff] [blame] | 891 | EXPORT_SYMBOL_GPL(sff_dma_ops); |
Sergei Shtylyov | 8e882ba | 2008-02-11 00:32:14 +0100 | [diff] [blame] | 892 | #endif /* CONFIG_BLK_DEV_IDEDMA_SFF */ |