Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Generic Generic NCR5380 driver |
| 3 | * |
| 4 | * Copyright 1993, Drew Eckhardt |
| 5 | * Visionary Computing |
| 6 | * (Unix and Linux consulting and custom programming) |
| 7 | * drew@colorado.edu |
| 8 | * +1 (303) 440-4894 |
| 9 | * |
| 10 | * NCR53C400 extensions (c) 1994,1995,1996, Kevin Lentin |
| 11 | * K.Lentin@cs.monash.edu.au |
| 12 | * |
| 13 | * NCR53C400A extensions (c) 1996, Ingmar Baumgart |
| 14 | * ingmar@gonzo.schwaben.de |
| 15 | * |
| 16 | * DTC3181E extensions (c) 1997, Ronald van Cuijlenborg |
| 17 | * ronald.van.cuijlenborg@tip.nl or nutty@dds.nl |
| 18 | * |
| 19 | * Added ISAPNP support for DTC436 adapters, |
| 20 | * Thomas Sailer, sailer@ife.ee.ethz.ch |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * TODO : flesh out DMA support, find some one actually using this (I have |
| 25 | * a memory mapped Trantor board that works fine) |
| 26 | */ |
| 27 | |
| 28 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | * The card is detected and initialized in one of several ways : |
| 30 | * 1. With command line overrides - NCR5380=port,irq may be |
| 31 | * used on the LILO command line to override the defaults. |
| 32 | * |
| 33 | * 2. With the GENERIC_NCR5380_OVERRIDE compile time define. This is |
| 34 | * specified as an array of address, irq, dma, board tuples. Ie, for |
| 35 | * one board at 0x350, IRQ5, no dma, I could say |
| 36 | * -DGENERIC_NCR5380_OVERRIDE={{0xcc000, 5, DMA_NONE, BOARD_NCR5380}} |
| 37 | * |
| 38 | * -1 should be specified for no or DMA interrupt, -2 to autoprobe for an |
| 39 | * IRQ line if overridden on the command line. |
| 40 | * |
| 41 | * 3. When included as a module, with arguments passed on the command line: |
| 42 | * ncr_irq=xx the interrupt |
| 43 | * ncr_addr=xx the port or base address (for port or memory |
| 44 | * mapped, resp.) |
| 45 | * ncr_dma=xx the DMA |
| 46 | * ncr_5380=1 to set up for a NCR5380 board |
| 47 | * ncr_53c400=1 to set up for a NCR53C400 board |
| 48 | * e.g. |
| 49 | * modprobe g_NCR5380 ncr_irq=5 ncr_addr=0x350 ncr_5380=1 |
| 50 | * for a port mapped NCR5380 board or |
| 51 | * modprobe g_NCR5380 ncr_irq=255 ncr_addr=0xc8000 ncr_53c400=1 |
| 52 | * for a memory mapped NCR53C400 board with interrupts disabled. |
| 53 | * |
| 54 | * 255 should be specified for no or DMA interrupt, 254 to autoprobe for an |
| 55 | * IRQ line if overridden on the command line. |
| 56 | * |
| 57 | */ |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | #define AUTOPROBE_IRQ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #define PSEUDO_DMA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #include <linux/blkdev.h> |
Finn Thain | 161c005 | 2016-01-03 16:05:46 +1100 | [diff] [blame] | 64 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #include <scsi/scsi_host.h> |
| 66 | #include "g_NCR5380.h" |
| 67 | #include "NCR5380.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #include <linux/init.h> |
| 69 | #include <linux/ioport.h> |
| 70 | #include <linux/isapnp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #include <linux/interrupt.h> |
| 72 | |
Finn Thain | c0965e6 | 2016-01-03 16:05:05 +1100 | [diff] [blame] | 73 | static int ncr_irq; |
| 74 | static int ncr_dma; |
| 75 | static int ncr_addr; |
| 76 | static int ncr_5380; |
| 77 | static int ncr_53c400; |
| 78 | static int ncr_53c400a; |
| 79 | static int dtc_3181e; |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 80 | static int hp_c2502; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | static struct override { |
Al Viro | c818cb6 | 2006-03-24 03:15:37 -0800 | [diff] [blame] | 83 | NCR5380_map_type NCR5380_map_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | int irq; |
| 85 | int dma; |
| 86 | int board; /* Use NCR53c400, Ricoh, etc. extensions ? */ |
| 87 | } overrides |
| 88 | #ifdef GENERIC_NCR5380_OVERRIDE |
| 89 | [] __initdata = GENERIC_NCR5380_OVERRIDE; |
| 90 | #else |
| 91 | [1] __initdata = { { 0,},}; |
| 92 | #endif |
| 93 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 94 | #define NO_OVERRIDES ARRAY_SIZE(overrides) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 96 | #ifndef MODULE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * internal_setup - handle lilo command string override |
| 100 | * @board: BOARD_* identifier for the board |
| 101 | * @str: unused |
| 102 | * @ints: numeric parameters |
| 103 | * |
| 104 | * Do LILO command line initialization of the overrides array. Display |
| 105 | * errors when needed |
| 106 | * |
| 107 | * Locks: none |
| 108 | */ |
| 109 | |
| 110 | static void __init internal_setup(int board, char *str, int *ints) |
| 111 | { |
Finn Thain | d5f7e65 | 2016-01-03 16:05:03 +1100 | [diff] [blame] | 112 | static int commandline_current; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | switch (board) { |
| 114 | case BOARD_NCR5380: |
| 115 | if (ints[0] != 2 && ints[0] != 3) { |
| 116 | printk(KERN_ERR "generic_NCR5380_setup : usage ncr5380=" STRVAL(NCR5380_map_name) ",irq,dma\n"); |
| 117 | return; |
| 118 | } |
| 119 | break; |
| 120 | case BOARD_NCR53C400: |
| 121 | if (ints[0] != 2) { |
| 122 | printk(KERN_ERR "generic_NCR53C400_setup : usage ncr53c400=" STRVAL(NCR5380_map_name) ",irq\n"); |
| 123 | return; |
| 124 | } |
| 125 | break; |
| 126 | case BOARD_NCR53C400A: |
| 127 | if (ints[0] != 2) { |
| 128 | printk(KERN_ERR "generic_NCR53C400A_setup : usage ncr53c400a=" STRVAL(NCR5380_map_name) ",irq\n"); |
| 129 | return; |
| 130 | } |
| 131 | break; |
| 132 | case BOARD_DTC3181E: |
| 133 | if (ints[0] != 2) { |
| 134 | printk("generic_DTC3181E_setup : usage dtc3181e=" STRVAL(NCR5380_map_name) ",irq\n"); |
| 135 | return; |
| 136 | } |
| 137 | break; |
| 138 | } |
| 139 | |
| 140 | if (commandline_current < NO_OVERRIDES) { |
| 141 | overrides[commandline_current].NCR5380_map_name = (NCR5380_map_type) ints[1]; |
| 142 | overrides[commandline_current].irq = ints[2]; |
| 143 | if (ints[0] == 3) |
| 144 | overrides[commandline_current].dma = ints[3]; |
| 145 | else |
| 146 | overrides[commandline_current].dma = DMA_NONE; |
| 147 | overrides[commandline_current].board = board; |
| 148 | ++commandline_current; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | |
| 153 | /** |
| 154 | * do_NCR53C80_setup - set up entry point |
| 155 | * @str: unused |
| 156 | * |
| 157 | * Setup function invoked at boot to parse the ncr5380= command |
| 158 | * line. |
| 159 | */ |
| 160 | |
| 161 | static int __init do_NCR5380_setup(char *str) |
| 162 | { |
| 163 | int ints[10]; |
| 164 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 165 | get_options(str, ARRAY_SIZE(ints), ints); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | internal_setup(BOARD_NCR5380, str, ints); |
| 167 | return 1; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * do_NCR53C400_setup - set up entry point |
| 172 | * @str: unused |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 173 | * @ints: integer parameters from kernel setup code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | * |
| 175 | * Setup function invoked at boot to parse the ncr53c400= command |
| 176 | * line. |
| 177 | */ |
| 178 | |
| 179 | static int __init do_NCR53C400_setup(char *str) |
| 180 | { |
| 181 | int ints[10]; |
| 182 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 183 | get_options(str, ARRAY_SIZE(ints), ints); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | internal_setup(BOARD_NCR53C400, str, ints); |
| 185 | return 1; |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * do_NCR53C400A_setup - set up entry point |
| 190 | * @str: unused |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 191 | * @ints: integer parameters from kernel setup code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | * |
| 193 | * Setup function invoked at boot to parse the ncr53c400a= command |
| 194 | * line. |
| 195 | */ |
| 196 | |
| 197 | static int __init do_NCR53C400A_setup(char *str) |
| 198 | { |
| 199 | int ints[10]; |
| 200 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 201 | get_options(str, ARRAY_SIZE(ints), ints); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | internal_setup(BOARD_NCR53C400A, str, ints); |
| 203 | return 1; |
| 204 | } |
| 205 | |
| 206 | /** |
| 207 | * do_DTC3181E_setup - set up entry point |
| 208 | * @str: unused |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 209 | * @ints: integer parameters from kernel setup code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | * |
| 211 | * Setup function invoked at boot to parse the dtc3181e= command |
| 212 | * line. |
| 213 | */ |
| 214 | |
| 215 | static int __init do_DTC3181E_setup(char *str) |
| 216 | { |
| 217 | int ints[10]; |
| 218 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 219 | get_options(str, ARRAY_SIZE(ints), ints); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | internal_setup(BOARD_DTC3181E, str, ints); |
| 221 | return 1; |
| 222 | } |
| 223 | |
| 224 | #endif |
| 225 | |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 226 | #ifndef SCSI_G_NCR5380_MEM |
| 227 | /* |
| 228 | * Configure I/O address of 53C400A or DTC436 by writing magic numbers |
| 229 | * to ports 0x779 and 0x379. |
| 230 | */ |
| 231 | static void magic_configure(int idx, u8 irq, u8 magic[]) |
| 232 | { |
| 233 | u8 cfg = 0; |
| 234 | |
| 235 | outb(magic[0], 0x779); |
| 236 | outb(magic[1], 0x379); |
| 237 | outb(magic[2], 0x379); |
| 238 | outb(magic[3], 0x379); |
| 239 | outb(magic[4], 0x379); |
| 240 | |
| 241 | /* allowed IRQs for HP C2502 */ |
| 242 | if (irq != 2 && irq != 3 && irq != 4 && irq != 5 && irq != 7) |
| 243 | irq = 0; |
| 244 | if (idx >= 0 && idx <= 7) |
| 245 | cfg = 0x80 | idx | (irq << 4); |
| 246 | outb(cfg, 0x379); |
| 247 | } |
| 248 | #endif |
| 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | /** |
| 251 | * generic_NCR5380_detect - look for NCR5380 controllers |
| 252 | * @tpnt: the scsi template |
| 253 | * |
| 254 | * Scan for the present of NCR5380, NCR53C400, NCR53C400A, DTC3181E |
| 255 | * and DTC436(ISAPnP) controllers. If overrides have been set we use |
| 256 | * them. |
| 257 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | * Locks: none |
| 259 | */ |
| 260 | |
Finn Thain | ed8b9e7 | 2014-11-12 16:11:51 +1100 | [diff] [blame] | 261 | static int __init generic_NCR5380_detect(struct scsi_host_template *tpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | { |
Finn Thain | d5f7e65 | 2016-01-03 16:05:03 +1100 | [diff] [blame] | 263 | static int current_override; |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 264 | int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | unsigned int *ports; |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 266 | u8 *magic = NULL; |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 267 | #ifndef SCSI_G_NCR5380_MEM |
| 268 | int i; |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 269 | int port_idx = -1; |
Finn Thain | 9d37640 | 2016-03-23 21:10:10 +1100 | [diff] [blame] | 270 | unsigned long region_size; |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 271 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | static unsigned int __initdata ncr_53c400a_ports[] = { |
| 273 | 0x280, 0x290, 0x300, 0x310, 0x330, 0x340, 0x348, 0x350, 0 |
| 274 | }; |
| 275 | static unsigned int __initdata dtc_3181e_ports[] = { |
| 276 | 0x220, 0x240, 0x280, 0x2a0, 0x2c0, 0x300, 0x320, 0x340, 0 |
| 277 | }; |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 278 | static u8 ncr_53c400a_magic[] __initdata = { /* 53C400A & DTC436 */ |
| 279 | 0x59, 0xb9, 0xc5, 0xae, 0xa6 |
| 280 | }; |
| 281 | static u8 hp_c2502_magic[] __initdata = { /* HP C2502 */ |
| 282 | 0x0f, 0x22, 0xf0, 0x20, 0x80 |
| 283 | }; |
Finn Thain | 4d8c08c | 2016-01-03 16:05:09 +1100 | [diff] [blame] | 284 | int flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | struct Scsi_Host *instance; |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 286 | struct NCR5380_hostdata *hostdata; |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 287 | #ifdef SCSI_G_NCR5380_MEM |
Al Viro | c818cb6 | 2006-03-24 03:15:37 -0800 | [diff] [blame] | 288 | unsigned long base; |
| 289 | void __iomem *iomem; |
Finn Thain | 9d37640 | 2016-03-23 21:10:10 +1100 | [diff] [blame] | 290 | resource_size_t iomem_size; |
Al Viro | c818cb6 | 2006-03-24 03:15:37 -0800 | [diff] [blame] | 291 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Finn Thain | c0965e6 | 2016-01-03 16:05:05 +1100 | [diff] [blame] | 293 | if (ncr_irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | overrides[0].irq = ncr_irq; |
Finn Thain | c0965e6 | 2016-01-03 16:05:05 +1100 | [diff] [blame] | 295 | if (ncr_dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | overrides[0].dma = ncr_dma; |
Finn Thain | c0965e6 | 2016-01-03 16:05:05 +1100 | [diff] [blame] | 297 | if (ncr_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | overrides[0].NCR5380_map_name = (NCR5380_map_type) ncr_addr; |
Finn Thain | c0965e6 | 2016-01-03 16:05:05 +1100 | [diff] [blame] | 299 | if (ncr_5380) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | overrides[0].board = BOARD_NCR5380; |
Finn Thain | c0965e6 | 2016-01-03 16:05:05 +1100 | [diff] [blame] | 301 | else if (ncr_53c400) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | overrides[0].board = BOARD_NCR53C400; |
Finn Thain | c0965e6 | 2016-01-03 16:05:05 +1100 | [diff] [blame] | 303 | else if (ncr_53c400a) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | overrides[0].board = BOARD_NCR53C400A; |
Finn Thain | c0965e6 | 2016-01-03 16:05:05 +1100 | [diff] [blame] | 305 | else if (dtc_3181e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | overrides[0].board = BOARD_DTC3181E; |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 307 | else if (hp_c2502) |
| 308 | overrides[0].board = BOARD_HP_C2502; |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 309 | #ifndef SCSI_G_NCR5380_MEM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | if (!current_override && isapnp_present()) { |
| 311 | struct pnp_dev *dev = NULL; |
| 312 | count = 0; |
| 313 | while ((dev = pnp_find_dev(NULL, ISAPNP_VENDOR('D', 'T', 'C'), ISAPNP_FUNCTION(0x436e), dev))) { |
| 314 | if (count >= NO_OVERRIDES) |
| 315 | break; |
Ondrej Zary | c94babb | 2010-08-10 18:01:15 -0700 | [diff] [blame] | 316 | if (pnp_device_attach(dev) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | if (pnp_activate_dev(dev) < 0) { |
| 319 | printk(KERN_ERR "dtc436e probe: activate failed\n"); |
| 320 | pnp_device_detach(dev); |
| 321 | continue; |
| 322 | } |
| 323 | if (!pnp_port_valid(dev, 0)) { |
| 324 | printk(KERN_ERR "dtc436e probe: no valid port\n"); |
| 325 | pnp_device_detach(dev); |
| 326 | continue; |
| 327 | } |
| 328 | if (pnp_irq_valid(dev, 0)) |
| 329 | overrides[count].irq = pnp_irq(dev, 0); |
| 330 | else |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 331 | overrides[count].irq = NO_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | if (pnp_dma_valid(dev, 0)) |
| 333 | overrides[count].dma = pnp_dma(dev, 0); |
| 334 | else |
| 335 | overrides[count].dma = DMA_NONE; |
| 336 | overrides[count].NCR5380_map_name = (NCR5380_map_type) pnp_port_start(dev, 0); |
| 337 | overrides[count].board = BOARD_DTC3181E; |
| 338 | count++; |
| 339 | } |
| 340 | } |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 341 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | for (count = 0; current_override < NO_OVERRIDES; ++current_override) { |
| 344 | if (!(overrides[current_override].NCR5380_map_name)) |
| 345 | continue; |
| 346 | |
| 347 | ports = NULL; |
Finn Thain | 4d8c08c | 2016-01-03 16:05:09 +1100 | [diff] [blame] | 348 | flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | switch (overrides[current_override].board) { |
| 350 | case BOARD_NCR5380: |
| 351 | flags = FLAG_NO_PSEUDO_DMA; |
| 352 | break; |
| 353 | case BOARD_NCR53C400: |
Finn Thain | 55181be | 2016-01-03 16:05:42 +1100 | [diff] [blame] | 354 | flags = FLAG_NO_DMA_FIXUP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | break; |
| 356 | case BOARD_NCR53C400A: |
Ondrej Zary | cecf3be | 2016-01-03 16:06:16 +1100 | [diff] [blame] | 357 | flags = FLAG_NO_DMA_FIXUP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | ports = ncr_53c400a_ports; |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 359 | magic = ncr_53c400a_magic; |
| 360 | break; |
| 361 | case BOARD_HP_C2502: |
| 362 | flags = FLAG_NO_DMA_FIXUP; |
| 363 | ports = ncr_53c400a_ports; |
| 364 | magic = hp_c2502_magic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | break; |
| 366 | case BOARD_DTC3181E: |
Ondrej Zary | aeb5115 | 2016-01-03 16:06:17 +1100 | [diff] [blame] | 367 | flags = FLAG_NO_DMA_FIXUP; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | ports = dtc_3181e_ports; |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 369 | magic = ncr_53c400a_magic; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | break; |
| 371 | } |
| 372 | |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 373 | #ifndef SCSI_G_NCR5380_MEM |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 374 | if (ports && magic) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | /* wakeup sequence for the NCR53C400A and DTC3181E */ |
| 376 | |
| 377 | /* Disable the adapter and look for a free io port */ |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 378 | magic_configure(-1, 0, magic); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
Finn Thain | 9d37640 | 2016-03-23 21:10:10 +1100 | [diff] [blame] | 380 | region_size = 16; |
| 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | if (overrides[current_override].NCR5380_map_name != PORT_AUTO) |
| 383 | for (i = 0; ports[i]; i++) { |
Finn Thain | 9d37640 | 2016-03-23 21:10:10 +1100 | [diff] [blame] | 384 | if (!request_region(ports[i], region_size, "ncr53c80")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | continue; |
| 386 | if (overrides[current_override].NCR5380_map_name == ports[i]) |
| 387 | break; |
Finn Thain | 9d37640 | 2016-03-23 21:10:10 +1100 | [diff] [blame] | 388 | release_region(ports[i], region_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } else |
| 390 | for (i = 0; ports[i]; i++) { |
Finn Thain | 9d37640 | 2016-03-23 21:10:10 +1100 | [diff] [blame] | 391 | if (!request_region(ports[i], region_size, "ncr53c80")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | continue; |
| 393 | if (inb(ports[i]) == 0xff) |
| 394 | break; |
Finn Thain | 9d37640 | 2016-03-23 21:10:10 +1100 | [diff] [blame] | 395 | release_region(ports[i], region_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
| 397 | if (ports[i]) { |
| 398 | /* At this point we have our region reserved */ |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 399 | magic_configure(i, 0, magic); /* no IRQ yet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | outb(0xc0, ports[i] + 9); |
| 401 | if (inb(ports[i] + 9) != 0x80) |
| 402 | continue; |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 403 | overrides[current_override].NCR5380_map_name = ports[i]; |
| 404 | port_idx = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } else |
| 406 | continue; |
| 407 | } |
| 408 | else |
| 409 | { |
| 410 | /* Not a 53C400A style setup - just grab */ |
Finn Thain | 9d37640 | 2016-03-23 21:10:10 +1100 | [diff] [blame] | 411 | region_size = 8; |
| 412 | if (!request_region(overrides[current_override].NCR5380_map_name, |
| 413 | region_size, "ncr5380")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | } |
| 416 | #else |
Al Viro | c818cb6 | 2006-03-24 03:15:37 -0800 | [diff] [blame] | 417 | base = overrides[current_override].NCR5380_map_name; |
Finn Thain | 9d37640 | 2016-03-23 21:10:10 +1100 | [diff] [blame] | 418 | iomem_size = NCR53C400_region_size; |
| 419 | if (!request_mem_region(base, iomem_size, "ncr5380")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | continue; |
Finn Thain | 9d37640 | 2016-03-23 21:10:10 +1100 | [diff] [blame] | 421 | iomem = ioremap(base, iomem_size); |
Al Viro | c818cb6 | 2006-03-24 03:15:37 -0800 | [diff] [blame] | 422 | if (!iomem) { |
Finn Thain | 9d37640 | 2016-03-23 21:10:10 +1100 | [diff] [blame] | 423 | release_mem_region(base, iomem_size); |
Al Viro | c818cb6 | 2006-03-24 03:15:37 -0800 | [diff] [blame] | 424 | continue; |
| 425 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | #endif |
| 427 | instance = scsi_register(tpnt, sizeof(struct NCR5380_hostdata)); |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 428 | if (instance == NULL) |
| 429 | goto out_release; |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 430 | hostdata = shost_priv(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 432 | #ifndef SCSI_G_NCR5380_MEM |
Finn Thain | b01ec34 | 2016-01-03 16:05:07 +1100 | [diff] [blame] | 433 | instance->io_port = overrides[current_override].NCR5380_map_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | instance->n_io_port = region_size; |
Ondrej Zary | aeb5115 | 2016-01-03 16:06:17 +1100 | [diff] [blame] | 435 | hostdata->io_width = 1; /* 8-bit PDMA by default */ |
Finn Thain | 4d8c08c | 2016-01-03 16:05:09 +1100 | [diff] [blame] | 436 | |
| 437 | /* |
| 438 | * On NCR53C400 boards, NCR5380 registers are mapped 8 past |
| 439 | * the base address. |
| 440 | */ |
Ondrej Zary | cecf3be | 2016-01-03 16:06:16 +1100 | [diff] [blame] | 441 | switch (overrides[current_override].board) { |
| 442 | case BOARD_NCR53C400: |
Finn Thain | 4d8c08c | 2016-01-03 16:05:09 +1100 | [diff] [blame] | 443 | instance->io_port += 8; |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 444 | hostdata->c400_ctl_status = 0; |
| 445 | hostdata->c400_blk_cnt = 1; |
| 446 | hostdata->c400_host_buf = 4; |
Ondrej Zary | cecf3be | 2016-01-03 16:06:16 +1100 | [diff] [blame] | 447 | break; |
Ondrej Zary | aeb5115 | 2016-01-03 16:06:17 +1100 | [diff] [blame] | 448 | case BOARD_DTC3181E: |
| 449 | hostdata->io_width = 2; /* 16-bit PDMA */ |
| 450 | /* fall through */ |
Ondrej Zary | cecf3be | 2016-01-03 16:06:16 +1100 | [diff] [blame] | 451 | case BOARD_NCR53C400A: |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 452 | case BOARD_HP_C2502: |
Ondrej Zary | cecf3be | 2016-01-03 16:06:16 +1100 | [diff] [blame] | 453 | hostdata->c400_ctl_status = 9; |
| 454 | hostdata->c400_blk_cnt = 10; |
| 455 | hostdata->c400_host_buf = 8; |
| 456 | break; |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 457 | } |
Al Viro | c818cb6 | 2006-03-24 03:15:37 -0800 | [diff] [blame] | 458 | #else |
Finn Thain | b01ec34 | 2016-01-03 16:05:07 +1100 | [diff] [blame] | 459 | instance->base = overrides[current_override].NCR5380_map_name; |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 460 | hostdata->iomem = iomem; |
Finn Thain | 9d37640 | 2016-03-23 21:10:10 +1100 | [diff] [blame] | 461 | hostdata->iomem_size = iomem_size; |
Ondrej Zary | cecf3be | 2016-01-03 16:06:16 +1100 | [diff] [blame] | 462 | switch (overrides[current_override].board) { |
| 463 | case BOARD_NCR53C400: |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 464 | hostdata->c400_ctl_status = 0x100; |
| 465 | hostdata->c400_blk_cnt = 0x101; |
| 466 | hostdata->c400_host_buf = 0x104; |
Ondrej Zary | cecf3be | 2016-01-03 16:06:16 +1100 | [diff] [blame] | 467 | break; |
Ondrej Zary | aeb5115 | 2016-01-03 16:06:17 +1100 | [diff] [blame] | 468 | case BOARD_DTC3181E: |
Ondrej Zary | cecf3be | 2016-01-03 16:06:16 +1100 | [diff] [blame] | 469 | case BOARD_NCR53C400A: |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 470 | case BOARD_HP_C2502: |
Ondrej Zary | cecf3be | 2016-01-03 16:06:16 +1100 | [diff] [blame] | 471 | pr_err(DRV_MODULE_NAME ": unknown register offsets\n"); |
| 472 | goto out_unregister; |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 473 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | #endif |
| 475 | |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 476 | if (NCR5380_init(instance, flags)) |
| 477 | goto out_unregister; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
Ondrej Zary | cecf3be | 2016-01-03 16:06:16 +1100 | [diff] [blame] | 479 | switch (overrides[current_override].board) { |
| 480 | case BOARD_NCR53C400: |
Ondrej Zary | aeb5115 | 2016-01-03 16:06:17 +1100 | [diff] [blame] | 481 | case BOARD_DTC3181E: |
Ondrej Zary | cecf3be | 2016-01-03 16:06:16 +1100 | [diff] [blame] | 482 | case BOARD_NCR53C400A: |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 483 | case BOARD_HP_C2502: |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 484 | NCR5380_write(hostdata->c400_ctl_status, CSR_BASE); |
Ondrej Zary | cecf3be | 2016-01-03 16:06:16 +1100 | [diff] [blame] | 485 | } |
Finn Thain | 4d8c08c | 2016-01-03 16:05:09 +1100 | [diff] [blame] | 486 | |
Finn Thain | b6488f9 | 2016-01-03 16:05:08 +1100 | [diff] [blame] | 487 | NCR5380_maybe_reset_bus(instance); |
| 488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | if (overrides[current_override].irq != IRQ_AUTO) |
| 490 | instance->irq = overrides[current_override].irq; |
| 491 | else |
| 492 | instance->irq = NCR5380_probe_irq(instance, 0xffff); |
| 493 | |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 494 | /* Compatibility with documented NCR5380 kernel parameters */ |
| 495 | if (instance->irq == 255) |
| 496 | instance->irq = NO_IRQ; |
| 497 | |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 498 | if (instance->irq != NO_IRQ) { |
| 499 | #ifndef SCSI_G_NCR5380_MEM |
| 500 | /* set IRQ for HP C2502 */ |
| 501 | if (overrides[current_override].board == BOARD_HP_C2502) |
| 502 | magic_configure(port_idx, instance->irq, magic); |
| 503 | #endif |
Jeff Garzik | 1e64166 | 2007-11-11 19:52:05 -0500 | [diff] [blame] | 504 | if (request_irq(instance->irq, generic_NCR5380_intr, |
Michael Opdenacker | 4909cc2 | 2014-03-05 06:09:41 +0100 | [diff] [blame] | 505 | 0, "NCR5380", instance)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | printk(KERN_WARNING "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq); |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 507 | instance->irq = NO_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | } |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 509 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 511 | if (instance->irq == NO_IRQ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | printk(KERN_INFO "scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no); |
| 513 | printk(KERN_INFO "scsi%d : please jumper the board for a free IRQ.\n", instance->host_no); |
| 514 | } |
| 515 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | ++current_override; |
| 517 | ++count; |
| 518 | } |
| 519 | return count; |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 520 | |
| 521 | out_unregister: |
| 522 | scsi_unregister(instance); |
| 523 | out_release: |
| 524 | #ifndef SCSI_G_NCR5380_MEM |
| 525 | release_region(overrides[current_override].NCR5380_map_name, region_size); |
| 526 | #else |
| 527 | iounmap(iomem); |
Finn Thain | 9d37640 | 2016-03-23 21:10:10 +1100 | [diff] [blame] | 528 | release_mem_region(base, iomem_size); |
Finn Thain | 0ad0eff | 2016-01-03 16:05:21 +1100 | [diff] [blame] | 529 | #endif |
| 530 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | * generic_NCR5380_release_resources - free resources |
| 535 | * @instance: host adapter to clean up |
| 536 | * |
| 537 | * Free the generic interface resources from this adapter. |
| 538 | * |
| 539 | * Locks: none |
| 540 | */ |
| 541 | |
Finn Thain | ed8b9e7 | 2014-11-12 16:11:51 +1100 | [diff] [blame] | 542 | static int generic_NCR5380_release_resources(struct Scsi_Host *instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | { |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 544 | if (instance->irq != NO_IRQ) |
Jeff Garzik | 1e64166 | 2007-11-11 19:52:05 -0500 | [diff] [blame] | 545 | free_irq(instance->irq, instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | NCR5380_exit(instance); |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 547 | #ifndef SCSI_G_NCR5380_MEM |
Finn Thain | b01ec34 | 2016-01-03 16:05:07 +1100 | [diff] [blame] | 548 | release_region(instance->io_port, instance->n_io_port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | #else |
Finn Thain | 9d37640 | 2016-03-23 21:10:10 +1100 | [diff] [blame] | 550 | { |
| 551 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
| 552 | |
| 553 | iounmap(hostdata->iomem); |
| 554 | release_mem_region(instance->base, hostdata->iomem_size); |
| 555 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | return 0; |
| 558 | } |
| 559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | /** |
| 561 | * NCR5380_pread - pseudo DMA read |
| 562 | * @instance: adapter to read from |
| 563 | * @dst: buffer to read into |
| 564 | * @len: buffer length |
| 565 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 566 | * Perform a pseudo DMA mode read from an NCR53C400 or equivalent |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | * controller |
| 568 | */ |
| 569 | |
| 570 | static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst, int len) |
| 571 | { |
Finn Thain | 54d8fe4 | 2016-01-03 16:05:06 +1100 | [diff] [blame] | 572 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | int blocks = len / 128; |
| 574 | int start = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 576 | NCR5380_write(hostdata->c400_ctl_status, CSR_BASE | CSR_TRANS_DIR); |
| 577 | NCR5380_write(hostdata->c400_blk_cnt, blocks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | while (1) { |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 579 | if (NCR5380_read(hostdata->c400_blk_cnt) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | break; |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 581 | if (NCR5380_read(hostdata->c400_ctl_status) & CSR_GATED_53C80_IRQ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | printk(KERN_ERR "53C400r: Got 53C80_IRQ start=%d, blocks=%d\n", start, blocks); |
| 583 | return -1; |
| 584 | } |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 585 | while (NCR5380_read(hostdata->c400_ctl_status) & CSR_HOST_BUF_NOT_RDY) |
| 586 | ; /* FIXME - no timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 588 | #ifndef SCSI_G_NCR5380_MEM |
Ondrej Zary | aeb5115 | 2016-01-03 16:06:17 +1100 | [diff] [blame] | 589 | if (hostdata->io_width == 2) |
| 590 | insw(instance->io_port + hostdata->c400_host_buf, |
| 591 | dst + start, 64); |
| 592 | else |
| 593 | insb(instance->io_port + hostdata->c400_host_buf, |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 594 | dst + start, 128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | #else |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 596 | /* implies SCSI_G_NCR5380_MEM */ |
Finn Thain | 54d8fe4 | 2016-01-03 16:05:06 +1100 | [diff] [blame] | 597 | memcpy_fromio(dst + start, |
| 598 | hostdata->iomem + NCR53C400_host_buffer, 128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | #endif |
| 600 | start += 128; |
| 601 | blocks--; |
| 602 | } |
| 603 | |
| 604 | if (blocks) { |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 605 | while (NCR5380_read(hostdata->c400_ctl_status) & CSR_HOST_BUF_NOT_RDY) |
| 606 | ; /* FIXME - no timeout */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 608 | #ifndef SCSI_G_NCR5380_MEM |
Ondrej Zary | aeb5115 | 2016-01-03 16:06:17 +1100 | [diff] [blame] | 609 | if (hostdata->io_width == 2) |
| 610 | insw(instance->io_port + hostdata->c400_host_buf, |
| 611 | dst + start, 64); |
| 612 | else |
| 613 | insb(instance->io_port + hostdata->c400_host_buf, |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 614 | dst + start, 128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | #else |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 616 | /* implies SCSI_G_NCR5380_MEM */ |
Finn Thain | 54d8fe4 | 2016-01-03 16:05:06 +1100 | [diff] [blame] | 617 | memcpy_fromio(dst + start, |
| 618 | hostdata->iomem + NCR53C400_host_buffer, 128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | #endif |
| 620 | start += 128; |
| 621 | blocks--; |
| 622 | } |
| 623 | |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 624 | if (!(NCR5380_read(hostdata->c400_ctl_status) & CSR_GATED_53C80_IRQ)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | printk("53C400r: no 53C80 gated irq after transfer"); |
| 626 | |
Ondrej Zary | 42fc637 | 2016-01-03 16:06:18 +1100 | [diff] [blame] | 627 | /* wait for 53C80 registers to be available */ |
| 628 | while (!(NCR5380_read(hostdata->c400_ctl_status) & CSR_53C80_REG)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | ; |
Ondrej Zary | 42fc637 | 2016-01-03 16:06:18 +1100 | [diff] [blame] | 630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_END_DMA_TRANSFER)) |
| 632 | printk(KERN_ERR "53C400r: no end dma signal\n"); |
| 633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | return 0; |
| 635 | } |
| 636 | |
| 637 | /** |
| 638 | * NCR5380_write - pseudo DMA write |
| 639 | * @instance: adapter to read from |
| 640 | * @dst: buffer to read into |
| 641 | * @len: buffer length |
| 642 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 643 | * Perform a pseudo DMA mode read from an NCR53C400 or equivalent |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | * controller |
| 645 | */ |
| 646 | |
| 647 | static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src, int len) |
| 648 | { |
Finn Thain | 54d8fe4 | 2016-01-03 16:05:06 +1100 | [diff] [blame] | 649 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | int blocks = len / 128; |
| 651 | int start = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 653 | NCR5380_write(hostdata->c400_ctl_status, CSR_BASE); |
| 654 | NCR5380_write(hostdata->c400_blk_cnt, blocks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | while (1) { |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 656 | if (NCR5380_read(hostdata->c400_ctl_status) & CSR_GATED_53C80_IRQ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | printk(KERN_ERR "53C400w: Got 53C80_IRQ start=%d, blocks=%d\n", start, blocks); |
| 658 | return -1; |
| 659 | } |
| 660 | |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 661 | if (NCR5380_read(hostdata->c400_blk_cnt) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | break; |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 663 | while (NCR5380_read(hostdata->c400_ctl_status) & CSR_HOST_BUF_NOT_RDY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | ; // FIXME - timeout |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 665 | #ifndef SCSI_G_NCR5380_MEM |
Ondrej Zary | aeb5115 | 2016-01-03 16:06:17 +1100 | [diff] [blame] | 666 | if (hostdata->io_width == 2) |
| 667 | outsw(instance->io_port + hostdata->c400_host_buf, |
| 668 | src + start, 64); |
| 669 | else |
| 670 | outsb(instance->io_port + hostdata->c400_host_buf, |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 671 | src + start, 128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | #else |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 673 | /* implies SCSI_G_NCR5380_MEM */ |
Finn Thain | 54d8fe4 | 2016-01-03 16:05:06 +1100 | [diff] [blame] | 674 | memcpy_toio(hostdata->iomem + NCR53C400_host_buffer, |
| 675 | src + start, 128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | #endif |
| 677 | start += 128; |
| 678 | blocks--; |
| 679 | } |
| 680 | if (blocks) { |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 681 | while (NCR5380_read(hostdata->c400_ctl_status) & CSR_HOST_BUF_NOT_RDY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | ; // FIXME - no timeout |
| 683 | |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 684 | #ifndef SCSI_G_NCR5380_MEM |
Ondrej Zary | aeb5115 | 2016-01-03 16:06:17 +1100 | [diff] [blame] | 685 | if (hostdata->io_width == 2) |
| 686 | outsw(instance->io_port + hostdata->c400_host_buf, |
| 687 | src + start, 64); |
| 688 | else |
| 689 | outsb(instance->io_port + hostdata->c400_host_buf, |
Ondrej Zary | 1215079 | 2016-01-03 16:06:15 +1100 | [diff] [blame] | 690 | src + start, 128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | #else |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 692 | /* implies SCSI_G_NCR5380_MEM */ |
Finn Thain | 54d8fe4 | 2016-01-03 16:05:06 +1100 | [diff] [blame] | 693 | memcpy_toio(hostdata->iomem + NCR53C400_host_buffer, |
| 694 | src + start, 128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | #endif |
| 696 | start += 128; |
| 697 | blocks--; |
| 698 | } |
| 699 | |
Ondrej Zary | 42fc637 | 2016-01-03 16:06:18 +1100 | [diff] [blame] | 700 | /* wait for 53C80 registers to be available */ |
| 701 | while (!(NCR5380_read(hostdata->c400_ctl_status) & CSR_53C80_REG)) { |
Ondrej Zary | aeb5115 | 2016-01-03 16:06:17 +1100 | [diff] [blame] | 702 | udelay(4); /* DTC436 chip hangs without this */ |
| 703 | /* FIXME - no timeout */ |
| 704 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_END_DMA_TRANSFER)) { |
| 707 | printk(KERN_ERR "53C400w: no end dma signal\n"); |
| 708 | } |
Ondrej Zary | 42fc637 | 2016-01-03 16:06:18 +1100 | [diff] [blame] | 709 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | while (!(NCR5380_read(TARGET_COMMAND_REG) & TCR_LAST_BYTE_SENT)) |
| 711 | ; // TIMEOUT |
| 712 | return 0; |
| 713 | } |
Finn Thain | ff3d457 | 2016-01-03 16:05:25 +1100 | [diff] [blame] | 714 | |
Finn Thain | 7e9ec8d | 2016-03-23 21:10:11 +1100 | [diff] [blame^] | 715 | static int generic_NCR5380_dma_xfer_len(struct Scsi_Host *instance, |
| 716 | struct scsi_cmnd *cmd) |
Finn Thain | ff3d457 | 2016-01-03 16:05:25 +1100 | [diff] [blame] | 717 | { |
Finn Thain | 7e9ec8d | 2016-03-23 21:10:11 +1100 | [diff] [blame^] | 718 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
Finn Thain | ff3d457 | 2016-01-03 16:05:25 +1100 | [diff] [blame] | 719 | int transfersize = cmd->transfersize; |
| 720 | |
Finn Thain | 7e9ec8d | 2016-03-23 21:10:11 +1100 | [diff] [blame^] | 721 | if (hostdata->flags & FLAG_NO_PSEUDO_DMA) |
| 722 | return 0; |
| 723 | |
Finn Thain | ff3d457 | 2016-01-03 16:05:25 +1100 | [diff] [blame] | 724 | /* Limit transfers to 32K, for xx400 & xx406 |
| 725 | * pseudoDMA that transfers in 128 bytes blocks. |
| 726 | */ |
| 727 | if (transfersize > 32 * 1024 && cmd->SCp.this_residual && |
| 728 | !(cmd->SCp.this_residual % transfersize)) |
| 729 | transfersize = 32 * 1024; |
| 730 | |
Ondrej Zary | f039462 | 2016-01-03 16:06:14 +1100 | [diff] [blame] | 731 | /* 53C400 datasheet: non-modulo-128-byte transfers should use PIO */ |
| 732 | if (transfersize % 128) |
| 733 | transfersize = 0; |
| 734 | |
Finn Thain | ff3d457 | 2016-01-03 16:05:25 +1100 | [diff] [blame] | 735 | return transfersize; |
| 736 | } |
| 737 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | /* |
| 739 | * Include the NCR5380 core code that we build our driver around |
| 740 | */ |
| 741 | |
| 742 | #include "NCR5380.c" |
| 743 | |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 744 | static struct scsi_host_template driver_template = { |
Finn Thain | aa2e2cb1 | 2016-01-03 16:05:48 +1100 | [diff] [blame] | 745 | .proc_name = DRV_MODULE_NAME, |
Finn Thain | aa2e2cb1 | 2016-01-03 16:05:48 +1100 | [diff] [blame] | 746 | .name = "Generic NCR5380/NCR53C400 SCSI", |
| 747 | .detect = generic_NCR5380_detect, |
| 748 | .release = generic_NCR5380_release_resources, |
| 749 | .info = generic_NCR5380_info, |
| 750 | .queuecommand = generic_NCR5380_queue_command, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | .eh_abort_handler = generic_NCR5380_abort, |
| 752 | .eh_bus_reset_handler = generic_NCR5380_bus_reset, |
Finn Thain | aa2e2cb1 | 2016-01-03 16:05:48 +1100 | [diff] [blame] | 753 | .can_queue = 16, |
| 754 | .this_id = 7, |
| 755 | .sg_tablesize = SG_ALL, |
| 756 | .cmd_per_lun = 2, |
| 757 | .use_clustering = DISABLE_CLUSTERING, |
Finn Thain | 32b26a1 | 2016-01-03 16:05:58 +1100 | [diff] [blame] | 758 | .cmd_size = NCR5380_CMD_SIZE, |
Finn Thain | 0a4e361 | 2016-01-03 16:06:07 +1100 | [diff] [blame] | 759 | .max_sectors = 128, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | }; |
Finn Thain | 161c005 | 2016-01-03 16:05:46 +1100 | [diff] [blame] | 761 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | #include "scsi_module.c" |
| 763 | |
| 764 | module_param(ncr_irq, int, 0); |
| 765 | module_param(ncr_dma, int, 0); |
| 766 | module_param(ncr_addr, int, 0); |
| 767 | module_param(ncr_5380, int, 0); |
| 768 | module_param(ncr_53c400, int, 0); |
| 769 | module_param(ncr_53c400a, int, 0); |
| 770 | module_param(dtc_3181e, int, 0); |
Ondrej Zary | c6084cb | 2016-01-03 16:06:19 +1100 | [diff] [blame] | 771 | module_param(hp_c2502, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | MODULE_LICENSE("GPL"); |
| 773 | |
Geert Uytterhoeven | b026e8e | 2015-01-03 23:00:16 +0100 | [diff] [blame] | 774 | #if !defined(SCSI_G_NCR5380_MEM) && defined(MODULE) |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 775 | static struct isapnp_device_id id_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | { |
| 777 | ISAPNP_ANY_ID, ISAPNP_ANY_ID, |
| 778 | ISAPNP_VENDOR('D', 'T', 'C'), ISAPNP_FUNCTION(0x436e), |
| 779 | 0}, |
| 780 | {0} |
| 781 | }; |
| 782 | |
| 783 | MODULE_DEVICE_TABLE(isapnp, id_table); |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 784 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | |
| 786 | __setup("ncr5380=", do_NCR5380_setup); |
| 787 | __setup("ncr53c400=", do_NCR53C400_setup); |
| 788 | __setup("ncr53c400a=", do_NCR53C400A_setup); |
| 789 | __setup("dtc3181e=", do_DTC3181E_setup); |