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