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 | /* settings for DTC3181E card with only Mustek scanner attached */ |
Nicholas Mc Guire | 4e5a800 | 2015-02-04 13:30:20 -0500 | [diff] [blame] | 60 | #define USLEEP_POLL msecs_to_jiffies(10) |
| 61 | #define USLEEP_SLEEP msecs_to_jiffies(200) |
| 62 | #define USLEEP_WAITLONG msecs_to_jiffies(5000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | #define AUTOPROBE_IRQ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
| 66 | #ifdef CONFIG_SCSI_GENERIC_NCR53C400 |
| 67 | #define NCR53C400_PSEUDO_DMA 1 |
| 68 | #define PSEUDO_DMA |
| 69 | #define NCR53C400 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | #endif |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #include <asm/io.h> |
| 73 | #include <linux/signal.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #include <linux/blkdev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #include <scsi/scsi_host.h> |
| 76 | #include "g_NCR5380.h" |
| 77 | #include "NCR5380.h" |
| 78 | #include <linux/stat.h> |
| 79 | #include <linux/init.h> |
| 80 | #include <linux/ioport.h> |
| 81 | #include <linux/isapnp.h> |
| 82 | #include <linux/delay.h> |
| 83 | #include <linux/interrupt.h> |
| 84 | |
Finn Thain | c0965e6 | 2016-01-03 16:05:05 +1100 | [diff] [blame^] | 85 | static int ncr_irq; |
| 86 | static int ncr_dma; |
| 87 | static int ncr_addr; |
| 88 | static int ncr_5380; |
| 89 | static int ncr_53c400; |
| 90 | static int ncr_53c400a; |
| 91 | static int dtc_3181e; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | |
| 93 | static struct override { |
Al Viro | c818cb6 | 2006-03-24 03:15:37 -0800 | [diff] [blame] | 94 | NCR5380_map_type NCR5380_map_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | int irq; |
| 96 | int dma; |
| 97 | int board; /* Use NCR53c400, Ricoh, etc. extensions ? */ |
| 98 | } overrides |
| 99 | #ifdef GENERIC_NCR5380_OVERRIDE |
| 100 | [] __initdata = GENERIC_NCR5380_OVERRIDE; |
| 101 | #else |
| 102 | [1] __initdata = { { 0,},}; |
| 103 | #endif |
| 104 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 105 | #define NO_OVERRIDES ARRAY_SIZE(overrides) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 107 | #ifndef MODULE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 109 | /** |
| 110 | * internal_setup - handle lilo command string override |
| 111 | * @board: BOARD_* identifier for the board |
| 112 | * @str: unused |
| 113 | * @ints: numeric parameters |
| 114 | * |
| 115 | * Do LILO command line initialization of the overrides array. Display |
| 116 | * errors when needed |
| 117 | * |
| 118 | * Locks: none |
| 119 | */ |
| 120 | |
| 121 | static void __init internal_setup(int board, char *str, int *ints) |
| 122 | { |
Finn Thain | d5f7e65 | 2016-01-03 16:05:03 +1100 | [diff] [blame] | 123 | static int commandline_current; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | switch (board) { |
| 125 | case BOARD_NCR5380: |
| 126 | if (ints[0] != 2 && ints[0] != 3) { |
| 127 | printk(KERN_ERR "generic_NCR5380_setup : usage ncr5380=" STRVAL(NCR5380_map_name) ",irq,dma\n"); |
| 128 | return; |
| 129 | } |
| 130 | break; |
| 131 | case BOARD_NCR53C400: |
| 132 | if (ints[0] != 2) { |
| 133 | printk(KERN_ERR "generic_NCR53C400_setup : usage ncr53c400=" STRVAL(NCR5380_map_name) ",irq\n"); |
| 134 | return; |
| 135 | } |
| 136 | break; |
| 137 | case BOARD_NCR53C400A: |
| 138 | if (ints[0] != 2) { |
| 139 | printk(KERN_ERR "generic_NCR53C400A_setup : usage ncr53c400a=" STRVAL(NCR5380_map_name) ",irq\n"); |
| 140 | return; |
| 141 | } |
| 142 | break; |
| 143 | case BOARD_DTC3181E: |
| 144 | if (ints[0] != 2) { |
| 145 | printk("generic_DTC3181E_setup : usage dtc3181e=" STRVAL(NCR5380_map_name) ",irq\n"); |
| 146 | return; |
| 147 | } |
| 148 | break; |
| 149 | } |
| 150 | |
| 151 | if (commandline_current < NO_OVERRIDES) { |
| 152 | overrides[commandline_current].NCR5380_map_name = (NCR5380_map_type) ints[1]; |
| 153 | overrides[commandline_current].irq = ints[2]; |
| 154 | if (ints[0] == 3) |
| 155 | overrides[commandline_current].dma = ints[3]; |
| 156 | else |
| 157 | overrides[commandline_current].dma = DMA_NONE; |
| 158 | overrides[commandline_current].board = board; |
| 159 | ++commandline_current; |
| 160 | } |
| 161 | } |
| 162 | |
| 163 | |
| 164 | /** |
| 165 | * do_NCR53C80_setup - set up entry point |
| 166 | * @str: unused |
| 167 | * |
| 168 | * Setup function invoked at boot to parse the ncr5380= command |
| 169 | * line. |
| 170 | */ |
| 171 | |
| 172 | static int __init do_NCR5380_setup(char *str) |
| 173 | { |
| 174 | int ints[10]; |
| 175 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 176 | get_options(str, ARRAY_SIZE(ints), ints); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | internal_setup(BOARD_NCR5380, str, ints); |
| 178 | return 1; |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * do_NCR53C400_setup - set up entry point |
| 183 | * @str: unused |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 184 | * @ints: integer parameters from kernel setup code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | * |
| 186 | * Setup function invoked at boot to parse the ncr53c400= command |
| 187 | * line. |
| 188 | */ |
| 189 | |
| 190 | static int __init do_NCR53C400_setup(char *str) |
| 191 | { |
| 192 | int ints[10]; |
| 193 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 194 | get_options(str, ARRAY_SIZE(ints), ints); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | internal_setup(BOARD_NCR53C400, str, ints); |
| 196 | return 1; |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * do_NCR53C400A_setup - set up entry point |
| 201 | * @str: unused |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 202 | * @ints: integer parameters from kernel setup code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | * |
| 204 | * Setup function invoked at boot to parse the ncr53c400a= command |
| 205 | * line. |
| 206 | */ |
| 207 | |
| 208 | static int __init do_NCR53C400A_setup(char *str) |
| 209 | { |
| 210 | int ints[10]; |
| 211 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 212 | get_options(str, ARRAY_SIZE(ints), ints); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | internal_setup(BOARD_NCR53C400A, str, ints); |
| 214 | return 1; |
| 215 | } |
| 216 | |
| 217 | /** |
| 218 | * do_DTC3181E_setup - set up entry point |
| 219 | * @str: unused |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 220 | * @ints: integer parameters from kernel setup code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | * |
| 222 | * Setup function invoked at boot to parse the dtc3181e= command |
| 223 | * line. |
| 224 | */ |
| 225 | |
| 226 | static int __init do_DTC3181E_setup(char *str) |
| 227 | { |
| 228 | int ints[10]; |
| 229 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 230 | get_options(str, ARRAY_SIZE(ints), ints); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | internal_setup(BOARD_DTC3181E, str, ints); |
| 232 | return 1; |
| 233 | } |
| 234 | |
| 235 | #endif |
| 236 | |
| 237 | /** |
| 238 | * generic_NCR5380_detect - look for NCR5380 controllers |
| 239 | * @tpnt: the scsi template |
| 240 | * |
| 241 | * Scan for the present of NCR5380, NCR53C400, NCR53C400A, DTC3181E |
| 242 | * and DTC436(ISAPnP) controllers. If overrides have been set we use |
| 243 | * them. |
| 244 | * |
| 245 | * The caller supplied NCR5380_init function is invoked from here, before |
| 246 | * the interrupt line is taken. |
| 247 | * |
| 248 | * Locks: none |
| 249 | */ |
| 250 | |
Finn Thain | ed8b9e7 | 2014-11-12 16:11:51 +1100 | [diff] [blame] | 251 | static int __init generic_NCR5380_detect(struct scsi_host_template *tpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | { |
Finn Thain | d5f7e65 | 2016-01-03 16:05:03 +1100 | [diff] [blame] | 253 | static int current_override; |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 254 | int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | unsigned int *ports; |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 256 | #ifndef SCSI_G_NCR5380_MEM |
| 257 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | unsigned long region_size = 16; |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 259 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | static unsigned int __initdata ncr_53c400a_ports[] = { |
| 261 | 0x280, 0x290, 0x300, 0x310, 0x330, 0x340, 0x348, 0x350, 0 |
| 262 | }; |
| 263 | static unsigned int __initdata dtc_3181e_ports[] = { |
| 264 | 0x220, 0x240, 0x280, 0x2a0, 0x2c0, 0x300, 0x320, 0x340, 0 |
| 265 | }; |
| 266 | int flags = 0; |
| 267 | struct Scsi_Host *instance; |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 268 | #ifdef SCSI_G_NCR5380_MEM |
Al Viro | c818cb6 | 2006-03-24 03:15:37 -0800 | [diff] [blame] | 269 | unsigned long base; |
| 270 | void __iomem *iomem; |
| 271 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
Finn Thain | c0965e6 | 2016-01-03 16:05:05 +1100 | [diff] [blame^] | 273 | if (ncr_irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | overrides[0].irq = ncr_irq; |
Finn Thain | c0965e6 | 2016-01-03 16:05:05 +1100 | [diff] [blame^] | 275 | if (ncr_dma) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | overrides[0].dma = ncr_dma; |
Finn Thain | c0965e6 | 2016-01-03 16:05:05 +1100 | [diff] [blame^] | 277 | if (ncr_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | overrides[0].NCR5380_map_name = (NCR5380_map_type) ncr_addr; |
Finn Thain | c0965e6 | 2016-01-03 16:05:05 +1100 | [diff] [blame^] | 279 | if (ncr_5380) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | overrides[0].board = BOARD_NCR5380; |
Finn Thain | c0965e6 | 2016-01-03 16:05:05 +1100 | [diff] [blame^] | 281 | else if (ncr_53c400) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | overrides[0].board = BOARD_NCR53C400; |
Finn Thain | c0965e6 | 2016-01-03 16:05:05 +1100 | [diff] [blame^] | 283 | else if (ncr_53c400a) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | overrides[0].board = BOARD_NCR53C400A; |
Finn Thain | c0965e6 | 2016-01-03 16:05:05 +1100 | [diff] [blame^] | 285 | else if (dtc_3181e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | overrides[0].board = BOARD_DTC3181E; |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 287 | #ifndef SCSI_G_NCR5380_MEM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | if (!current_override && isapnp_present()) { |
| 289 | struct pnp_dev *dev = NULL; |
| 290 | count = 0; |
| 291 | while ((dev = pnp_find_dev(NULL, ISAPNP_VENDOR('D', 'T', 'C'), ISAPNP_FUNCTION(0x436e), dev))) { |
| 292 | if (count >= NO_OVERRIDES) |
| 293 | break; |
Ondrej Zary | c94babb | 2010-08-10 18:01:15 -0700 | [diff] [blame] | 294 | if (pnp_device_attach(dev) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | if (pnp_activate_dev(dev) < 0) { |
| 297 | printk(KERN_ERR "dtc436e probe: activate failed\n"); |
| 298 | pnp_device_detach(dev); |
| 299 | continue; |
| 300 | } |
| 301 | if (!pnp_port_valid(dev, 0)) { |
| 302 | printk(KERN_ERR "dtc436e probe: no valid port\n"); |
| 303 | pnp_device_detach(dev); |
| 304 | continue; |
| 305 | } |
| 306 | if (pnp_irq_valid(dev, 0)) |
| 307 | overrides[count].irq = pnp_irq(dev, 0); |
| 308 | else |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 309 | overrides[count].irq = NO_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | if (pnp_dma_valid(dev, 0)) |
| 311 | overrides[count].dma = pnp_dma(dev, 0); |
| 312 | else |
| 313 | overrides[count].dma = DMA_NONE; |
| 314 | overrides[count].NCR5380_map_name = (NCR5380_map_type) pnp_port_start(dev, 0); |
| 315 | overrides[count].board = BOARD_DTC3181E; |
| 316 | count++; |
| 317 | } |
| 318 | } |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 319 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | tpnt->proc_name = "g_NCR5380"; |
| 321 | |
| 322 | for (count = 0; current_override < NO_OVERRIDES; ++current_override) { |
| 323 | if (!(overrides[current_override].NCR5380_map_name)) |
| 324 | continue; |
| 325 | |
| 326 | ports = NULL; |
| 327 | switch (overrides[current_override].board) { |
| 328 | case BOARD_NCR5380: |
| 329 | flags = FLAG_NO_PSEUDO_DMA; |
| 330 | break; |
| 331 | case BOARD_NCR53C400: |
| 332 | flags = FLAG_NCR53C400; |
| 333 | break; |
| 334 | case BOARD_NCR53C400A: |
| 335 | flags = FLAG_NO_PSEUDO_DMA; |
| 336 | ports = ncr_53c400a_ports; |
| 337 | break; |
| 338 | case BOARD_DTC3181E: |
| 339 | flags = FLAG_NO_PSEUDO_DMA | FLAG_DTC3181E; |
| 340 | ports = dtc_3181e_ports; |
| 341 | break; |
| 342 | } |
| 343 | |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 344 | #ifndef SCSI_G_NCR5380_MEM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | if (ports) { |
| 346 | /* wakeup sequence for the NCR53C400A and DTC3181E */ |
| 347 | |
| 348 | /* Disable the adapter and look for a free io port */ |
| 349 | outb(0x59, 0x779); |
| 350 | outb(0xb9, 0x379); |
| 351 | outb(0xc5, 0x379); |
| 352 | outb(0xae, 0x379); |
| 353 | outb(0xa6, 0x379); |
| 354 | outb(0x00, 0x379); |
| 355 | |
| 356 | if (overrides[current_override].NCR5380_map_name != PORT_AUTO) |
| 357 | for (i = 0; ports[i]; i++) { |
| 358 | if (!request_region(ports[i], 16, "ncr53c80")) |
| 359 | continue; |
| 360 | if (overrides[current_override].NCR5380_map_name == ports[i]) |
| 361 | break; |
| 362 | release_region(ports[i], 16); |
| 363 | } else |
| 364 | for (i = 0; ports[i]; i++) { |
| 365 | if (!request_region(ports[i], 16, "ncr53c80")) |
| 366 | continue; |
| 367 | if (inb(ports[i]) == 0xff) |
| 368 | break; |
| 369 | release_region(ports[i], 16); |
| 370 | } |
| 371 | if (ports[i]) { |
| 372 | /* At this point we have our region reserved */ |
| 373 | outb(0x59, 0x779); |
| 374 | outb(0xb9, 0x379); |
| 375 | outb(0xc5, 0x379); |
| 376 | outb(0xae, 0x379); |
| 377 | outb(0xa6, 0x379); |
| 378 | outb(0x80 | i, 0x379); /* set io port to be used */ |
| 379 | outb(0xc0, ports[i] + 9); |
| 380 | if (inb(ports[i] + 9) != 0x80) |
| 381 | continue; |
| 382 | else |
| 383 | overrides[current_override].NCR5380_map_name = ports[i]; |
| 384 | } else |
| 385 | continue; |
| 386 | } |
| 387 | else |
| 388 | { |
| 389 | /* Not a 53C400A style setup - just grab */ |
| 390 | if(!(request_region(overrides[current_override].NCR5380_map_name, NCR5380_region_size, "ncr5380"))) |
| 391 | continue; |
| 392 | region_size = NCR5380_region_size; |
| 393 | } |
| 394 | #else |
Al Viro | c818cb6 | 2006-03-24 03:15:37 -0800 | [diff] [blame] | 395 | base = overrides[current_override].NCR5380_map_name; |
| 396 | if (!request_mem_region(base, NCR5380_region_size, "ncr5380")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | continue; |
Al Viro | c818cb6 | 2006-03-24 03:15:37 -0800 | [diff] [blame] | 398 | iomem = ioremap(base, NCR5380_region_size); |
| 399 | if (!iomem) { |
| 400 | release_mem_region(base, NCR5380_region_size); |
| 401 | continue; |
| 402 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | #endif |
| 404 | instance = scsi_register(tpnt, sizeof(struct NCR5380_hostdata)); |
| 405 | if (instance == NULL) { |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 406 | #ifndef SCSI_G_NCR5380_MEM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | release_region(overrides[current_override].NCR5380_map_name, region_size); |
| 408 | #else |
Al Viro | c818cb6 | 2006-03-24 03:15:37 -0800 | [diff] [blame] | 409 | iounmap(iomem); |
| 410 | release_mem_region(base, NCR5380_region_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | #endif |
| 412 | continue; |
| 413 | } |
| 414 | |
| 415 | instance->NCR5380_instance_name = overrides[current_override].NCR5380_map_name; |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 416 | #ifndef SCSI_G_NCR5380_MEM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | instance->n_io_port = region_size; |
Al Viro | c818cb6 | 2006-03-24 03:15:37 -0800 | [diff] [blame] | 418 | #else |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 419 | ((struct NCR5380_hostdata *)instance->hostdata)->iomem = iomem; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | #endif |
| 421 | |
| 422 | NCR5380_init(instance, flags); |
| 423 | |
| 424 | if (overrides[current_override].irq != IRQ_AUTO) |
| 425 | instance->irq = overrides[current_override].irq; |
| 426 | else |
| 427 | instance->irq = NCR5380_probe_irq(instance, 0xffff); |
| 428 | |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 429 | /* Compatibility with documented NCR5380 kernel parameters */ |
| 430 | if (instance->irq == 255) |
| 431 | instance->irq = NO_IRQ; |
| 432 | |
| 433 | if (instance->irq != NO_IRQ) |
Jeff Garzik | 1e64166 | 2007-11-11 19:52:05 -0500 | [diff] [blame] | 434 | if (request_irq(instance->irq, generic_NCR5380_intr, |
Michael Opdenacker | 4909cc2 | 2014-03-05 06:09:41 +0100 | [diff] [blame] | 435 | 0, "NCR5380", instance)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | 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] | 437 | instance->irq = NO_IRQ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 440 | if (instance->irq == NO_IRQ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | printk(KERN_INFO "scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no); |
| 442 | printk(KERN_INFO "scsi%d : please jumper the board for a free IRQ.\n", instance->host_no); |
| 443 | } |
| 444 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | ++current_override; |
| 446 | ++count; |
| 447 | } |
| 448 | return count; |
| 449 | } |
| 450 | |
| 451 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | * generic_NCR5380_release_resources - free resources |
| 453 | * @instance: host adapter to clean up |
| 454 | * |
| 455 | * Free the generic interface resources from this adapter. |
| 456 | * |
| 457 | * Locks: none |
| 458 | */ |
| 459 | |
Finn Thain | ed8b9e7 | 2014-11-12 16:11:51 +1100 | [diff] [blame] | 460 | static int generic_NCR5380_release_resources(struct Scsi_Host *instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | { |
| 462 | NCR5380_local_declare(); |
| 463 | NCR5380_setup(instance); |
| 464 | |
Finn Thain | 22f5f10 | 2014-11-12 16:11:56 +1100 | [diff] [blame] | 465 | if (instance->irq != NO_IRQ) |
Jeff Garzik | 1e64166 | 2007-11-11 19:52:05 -0500 | [diff] [blame] | 466 | free_irq(instance->irq, instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | NCR5380_exit(instance); |
| 468 | |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 469 | #ifndef SCSI_G_NCR5380_MEM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | release_region(instance->NCR5380_instance_name, instance->n_io_port); |
| 471 | #else |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 472 | iounmap(((struct NCR5380_hostdata *)instance->hostdata)->iomem); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | release_mem_region(instance->NCR5380_instance_name, NCR5380_region_size); |
| 474 | #endif |
| 475 | |
| 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | #ifdef BIOSPARAM |
| 481 | /** |
| 482 | * generic_NCR5380_biosparam |
| 483 | * @disk: disk to compute geometry for |
| 484 | * @dev: device identifier for this disk |
| 485 | * @ip: sizes to fill in |
| 486 | * |
| 487 | * Generates a BIOS / DOS compatible H-C-S mapping for the specified |
| 488 | * device / size. |
| 489 | * |
| 490 | * XXX Most SCSI boards use this mapping, I could be incorrect. Someone |
| 491 | * using hard disks on a trantor should verify that this mapping |
| 492 | * corresponds to that used by the BIOS / ASPI driver by running the linux |
| 493 | * fdisk program and matching the H_C_S coordinates to what DOS uses. |
| 494 | * |
| 495 | * Locks: none |
| 496 | */ |
| 497 | |
| 498 | static int |
| 499 | generic_NCR5380_biosparam(struct scsi_device *sdev, struct block_device *bdev, |
| 500 | sector_t capacity, int *ip) |
| 501 | { |
| 502 | ip[0] = 64; |
| 503 | ip[1] = 32; |
| 504 | ip[2] = capacity >> 11; |
| 505 | return 0; |
| 506 | } |
| 507 | #endif |
| 508 | |
Gabriel C | 8d9e0f4 | 2007-08-10 14:50:39 -0700 | [diff] [blame] | 509 | #ifdef NCR53C400_PSEUDO_DMA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
| 511 | /** |
| 512 | * NCR5380_pread - pseudo DMA read |
| 513 | * @instance: adapter to read from |
| 514 | * @dst: buffer to read into |
| 515 | * @len: buffer length |
| 516 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 517 | * Perform a pseudo DMA mode read from an NCR53C400 or equivalent |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | * controller |
| 519 | */ |
| 520 | |
| 521 | static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst, int len) |
| 522 | { |
| 523 | int blocks = len / 128; |
| 524 | int start = 0; |
| 525 | int bl; |
| 526 | |
| 527 | NCR5380_local_declare(); |
| 528 | NCR5380_setup(instance); |
| 529 | |
| 530 | NCR5380_write(C400_CONTROL_STATUS_REG, CSR_BASE | CSR_TRANS_DIR); |
| 531 | NCR5380_write(C400_BLOCK_COUNTER_REG, blocks); |
| 532 | while (1) { |
| 533 | if ((bl = NCR5380_read(C400_BLOCK_COUNTER_REG)) == 0) { |
| 534 | break; |
| 535 | } |
| 536 | if (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_GATED_53C80_IRQ) { |
| 537 | printk(KERN_ERR "53C400r: Got 53C80_IRQ start=%d, blocks=%d\n", start, blocks); |
| 538 | return -1; |
| 539 | } |
| 540 | while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY); |
| 541 | |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 542 | #ifndef SCSI_G_NCR5380_MEM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | { |
| 544 | int i; |
| 545 | for (i = 0; i < 128; i++) |
| 546 | dst[start + i] = NCR5380_read(C400_HOST_BUFFER); |
| 547 | } |
| 548 | #else |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 549 | /* implies SCSI_G_NCR5380_MEM */ |
Al Viro | c818cb6 | 2006-03-24 03:15:37 -0800 | [diff] [blame] | 550 | memcpy_fromio(dst + start, iomem + NCR53C400_host_buffer, 128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | #endif |
| 552 | start += 128; |
| 553 | blocks--; |
| 554 | } |
| 555 | |
| 556 | if (blocks) { |
| 557 | while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY) |
| 558 | { |
| 559 | // FIXME - no timeout |
| 560 | } |
| 561 | |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 562 | #ifndef SCSI_G_NCR5380_MEM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | { |
| 564 | int i; |
| 565 | for (i = 0; i < 128; i++) |
| 566 | dst[start + i] = NCR5380_read(C400_HOST_BUFFER); |
| 567 | } |
| 568 | #else |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 569 | /* implies SCSI_G_NCR5380_MEM */ |
Al Viro | c818cb6 | 2006-03-24 03:15:37 -0800 | [diff] [blame] | 570 | memcpy_fromio(dst + start, iomem + NCR53C400_host_buffer, 128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | #endif |
| 572 | start += 128; |
| 573 | blocks--; |
| 574 | } |
| 575 | |
| 576 | if (!(NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_GATED_53C80_IRQ)) |
| 577 | printk("53C400r: no 53C80 gated irq after transfer"); |
| 578 | |
| 579 | #if 0 |
| 580 | /* |
| 581 | * DON'T DO THIS - THEY NEVER ARRIVE! |
| 582 | */ |
| 583 | printk("53C400r: Waiting for 53C80 registers\n"); |
| 584 | while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_53C80_REG) |
| 585 | ; |
| 586 | #endif |
| 587 | if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_END_DMA_TRANSFER)) |
| 588 | printk(KERN_ERR "53C400r: no end dma signal\n"); |
| 589 | |
| 590 | NCR5380_write(MODE_REG, MR_BASE); |
| 591 | NCR5380_read(RESET_PARITY_INTERRUPT_REG); |
| 592 | return 0; |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * NCR5380_write - pseudo DMA write |
| 597 | * @instance: adapter to read from |
| 598 | * @dst: buffer to read into |
| 599 | * @len: buffer length |
| 600 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 601 | * Perform a pseudo DMA mode read from an NCR53C400 or equivalent |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | * controller |
| 603 | */ |
| 604 | |
| 605 | static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src, int len) |
| 606 | { |
| 607 | int blocks = len / 128; |
| 608 | int start = 0; |
| 609 | int bl; |
| 610 | int i; |
| 611 | |
| 612 | NCR5380_local_declare(); |
| 613 | NCR5380_setup(instance); |
| 614 | |
| 615 | NCR5380_write(C400_CONTROL_STATUS_REG, CSR_BASE); |
| 616 | NCR5380_write(C400_BLOCK_COUNTER_REG, blocks); |
| 617 | while (1) { |
| 618 | if (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_GATED_53C80_IRQ) { |
| 619 | printk(KERN_ERR "53C400w: Got 53C80_IRQ start=%d, blocks=%d\n", start, blocks); |
| 620 | return -1; |
| 621 | } |
| 622 | |
| 623 | if ((bl = NCR5380_read(C400_BLOCK_COUNTER_REG)) == 0) { |
| 624 | break; |
| 625 | } |
| 626 | while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY) |
| 627 | ; // FIXME - timeout |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 628 | #ifndef SCSI_G_NCR5380_MEM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | { |
| 630 | for (i = 0; i < 128; i++) |
| 631 | NCR5380_write(C400_HOST_BUFFER, src[start + i]); |
| 632 | } |
| 633 | #else |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 634 | /* implies SCSI_G_NCR5380_MEM */ |
Al Viro | c818cb6 | 2006-03-24 03:15:37 -0800 | [diff] [blame] | 635 | memcpy_toio(iomem + NCR53C400_host_buffer, src + start, 128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | #endif |
| 637 | start += 128; |
| 638 | blocks--; |
| 639 | } |
| 640 | if (blocks) { |
| 641 | while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY) |
| 642 | ; // FIXME - no timeout |
| 643 | |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 644 | #ifndef SCSI_G_NCR5380_MEM |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | { |
| 646 | for (i = 0; i < 128; i++) |
| 647 | NCR5380_write(C400_HOST_BUFFER, src[start + i]); |
| 648 | } |
| 649 | #else |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 650 | /* implies SCSI_G_NCR5380_MEM */ |
Al Viro | c818cb6 | 2006-03-24 03:15:37 -0800 | [diff] [blame] | 651 | memcpy_toio(iomem + NCR53C400_host_buffer, src + start, 128); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | #endif |
| 653 | start += 128; |
| 654 | blocks--; |
| 655 | } |
| 656 | |
| 657 | #if 0 |
| 658 | printk("53C400w: waiting for registers to be available\n"); |
| 659 | THEY NEVER DO ! while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_53C80_REG); |
| 660 | printk("53C400w: Got em\n"); |
| 661 | #endif |
| 662 | |
| 663 | /* Let's wait for this instead - could be ugly */ |
| 664 | /* All documentation says to check for this. Maybe my hardware is too |
| 665 | * fast. Waiting for it seems to work fine! KLL |
| 666 | */ |
| 667 | while (!(i = NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_GATED_53C80_IRQ)) |
| 668 | ; // FIXME - no timeout |
| 669 | |
| 670 | /* |
| 671 | * I know. i is certainly != 0 here but the loop is new. See previous |
| 672 | * comment. |
| 673 | */ |
| 674 | if (i) { |
| 675 | if (!((i = NCR5380_read(BUS_AND_STATUS_REG)) & BASR_END_DMA_TRANSFER)) |
| 676 | printk(KERN_ERR "53C400w: No END OF DMA bit - WHOOPS! BASR=%0x\n", i); |
| 677 | } else |
| 678 | printk(KERN_ERR "53C400w: no 53C80 gated irq after transfer (last block)\n"); |
| 679 | |
| 680 | #if 0 |
| 681 | if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_END_DMA_TRANSFER)) { |
| 682 | printk(KERN_ERR "53C400w: no end dma signal\n"); |
| 683 | } |
| 684 | #endif |
| 685 | while (!(NCR5380_read(TARGET_COMMAND_REG) & TCR_LAST_BYTE_SENT)) |
| 686 | ; // TIMEOUT |
| 687 | return 0; |
| 688 | } |
| 689 | #endif /* PSEUDO_DMA */ |
| 690 | |
| 691 | /* |
| 692 | * Include the NCR5380 core code that we build our driver around |
| 693 | */ |
| 694 | |
| 695 | #include "NCR5380.c" |
| 696 | |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 697 | static struct scsi_host_template driver_template = { |
Al Viro | dd7ab71 | 2013-03-31 01:15:54 -0400 | [diff] [blame] | 698 | .show_info = generic_NCR5380_show_info, |
Finn Thain | 8c32513 | 2014-11-12 16:11:58 +1100 | [diff] [blame] | 699 | .name = "Generic NCR5380/NCR53C400 SCSI", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | .detect = generic_NCR5380_detect, |
| 701 | .release = generic_NCR5380_release_resources, |
| 702 | .info = generic_NCR5380_info, |
| 703 | .queuecommand = generic_NCR5380_queue_command, |
| 704 | .eh_abort_handler = generic_NCR5380_abort, |
| 705 | .eh_bus_reset_handler = generic_NCR5380_bus_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | .bios_param = NCR5380_BIOSPARAM, |
| 707 | .can_queue = CAN_QUEUE, |
| 708 | .this_id = 7, |
| 709 | .sg_tablesize = SG_ALL, |
| 710 | .cmd_per_lun = CMD_PER_LUN, |
| 711 | .use_clustering = DISABLE_CLUSTERING, |
| 712 | }; |
| 713 | #include <linux/module.h> |
| 714 | #include "scsi_module.c" |
| 715 | |
| 716 | module_param(ncr_irq, int, 0); |
| 717 | module_param(ncr_dma, int, 0); |
| 718 | module_param(ncr_addr, int, 0); |
| 719 | module_param(ncr_5380, int, 0); |
| 720 | module_param(ncr_53c400, int, 0); |
| 721 | module_param(ncr_53c400a, int, 0); |
| 722 | module_param(dtc_3181e, int, 0); |
| 723 | MODULE_LICENSE("GPL"); |
| 724 | |
Geert Uytterhoeven | b026e8e | 2015-01-03 23:00:16 +0100 | [diff] [blame] | 725 | #if !defined(SCSI_G_NCR5380_MEM) && defined(MODULE) |
Greg Kroah-Hartman | 6f03979 | 2012-12-21 13:08:55 -0800 | [diff] [blame] | 726 | static struct isapnp_device_id id_table[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | { |
| 728 | ISAPNP_ANY_ID, ISAPNP_ANY_ID, |
| 729 | ISAPNP_VENDOR('D', 'T', 'C'), ISAPNP_FUNCTION(0x436e), |
| 730 | 0}, |
| 731 | {0} |
| 732 | }; |
| 733 | |
| 734 | MODULE_DEVICE_TABLE(isapnp, id_table); |
Ondrej Zary | 702a98c | 2010-08-10 18:01:16 -0700 | [diff] [blame] | 735 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | |
| 737 | __setup("ncr5380=", do_NCR5380_setup); |
| 738 | __setup("ncr53c400=", do_NCR53C400_setup); |
| 739 | __setup("ncr53c400a=", do_NCR53C400A_setup); |
| 740 | __setup("dtc3181e=", do_DTC3181E_setup); |