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