Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #define AUTOSENSE |
| 2 | #define PSEUDO_DMA |
| 3 | |
| 4 | /* |
| 5 | * Trantor T128/T128F/T228 driver |
| 6 | * Note : architecturally, the T100 and T130 are different and won't |
| 7 | * work |
| 8 | * |
| 9 | * Copyright 1993, Drew Eckhardt |
| 10 | * Visionary Computing |
| 11 | * (Unix and Linux consulting and custom programming) |
| 12 | * drew@colorado.edu |
| 13 | * +1 (303) 440-4894 |
| 14 | * |
| 15 | * DISTRIBUTION RELEASE 3. |
| 16 | * |
| 17 | * For more information, please consult |
| 18 | * |
| 19 | * Trantor Systems, Ltd. |
| 20 | * T128/T128F/T228 SCSI Host Adapter |
| 21 | * Hardware Specifications |
| 22 | * |
| 23 | * Trantor Systems, Ltd. |
| 24 | * 5415 Randall Place |
| 25 | * Fremont, CA 94538 |
| 26 | * 1+ (415) 770-1400, FAX 1+ (415) 770-9910 |
| 27 | * |
| 28 | * and |
| 29 | * |
| 30 | * NCR 5380 Family |
| 31 | * SCSI Protocol Controller |
| 32 | * Databook |
| 33 | * |
| 34 | * NCR Microelectronics |
| 35 | * 1635 Aeroplaza Drive |
| 36 | * Colorado Springs, CO 80916 |
| 37 | * 1+ (719) 578-3400 |
| 38 | * 1+ (800) 334-5454 |
| 39 | */ |
| 40 | |
| 41 | /* |
| 42 | * Options : |
| 43 | * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically |
| 44 | * for commands that return with a CHECK CONDITION status. |
| 45 | * |
| 46 | * PSEUDO_DMA - enables PSEUDO-DMA hardware, should give a 3-4X performance |
| 47 | * increase compared to polled I/O. |
| 48 | * |
| 49 | * PARITY - enable parity checking. Not supported. |
| 50 | * |
| 51 | * SCSI2 - enable support for SCSI-II tagged queueing. Untested. |
| 52 | * |
| 53 | * |
| 54 | * UNSAFE - leave interrupts enabled during pseudo-DMA transfers. You |
| 55 | * only really want to use this if you're having a problem with |
| 56 | * dropped characters during high speed communications, and even |
| 57 | * then, you're going to be better off twiddling with transfersize. |
| 58 | * |
| 59 | * USLEEP - enable support for devices that don't disconnect. Untested. |
| 60 | * |
| 61 | * The card is detected and initialized in one of several ways : |
| 62 | * 1. Autoprobe (default) - since the board is memory mapped, |
| 63 | * a BIOS signature is scanned for to locate the registers. |
| 64 | * An interrupt is triggered to autoprobe for the interrupt |
| 65 | * line. |
| 66 | * |
| 67 | * 2. With command line overrides - t128=address,irq may be |
| 68 | * used on the LILO command line to override the defaults. |
| 69 | * |
| 70 | * 3. With the T128_OVERRIDE compile time define. This is |
| 71 | * specified as an array of address, irq tuples. Ie, for |
| 72 | * one board at the default 0xcc000 address, IRQ5, I could say |
| 73 | * -DT128_OVERRIDE={{0xcc000, 5}} |
| 74 | * |
| 75 | * Note that if the override methods are used, place holders must |
| 76 | * be specified for other boards in the system. |
| 77 | * |
| 78 | * T128/T128F jumper/dipswitch settings (note : on my sample, the switches |
| 79 | * were epoxy'd shut, meaning I couldn't change the 0xcc000 base address) : |
| 80 | * |
| 81 | * T128 Sw7 Sw8 Sw6 = 0ws Sw5 = boot |
| 82 | * T128F Sw6 Sw7 Sw5 = 0ws Sw4 = boot Sw8 = floppy disable |
| 83 | * cc000 off off |
| 84 | * c8000 off on |
| 85 | * dc000 on off |
| 86 | * d8000 on on |
| 87 | * |
| 88 | * |
| 89 | * Interrupts |
| 90 | * There is a 12 pin jumper block, jp1, numbered as follows : |
| 91 | * T128 (JP1) T128F (J5) |
| 92 | * 2 4 6 8 10 12 11 9 7 5 3 1 |
| 93 | * 1 3 5 7 9 11 12 10 8 6 4 2 |
| 94 | * |
| 95 | * 3 2-4 |
| 96 | * 5 1-3 |
| 97 | * 7 3-5 |
| 98 | * T128F only |
| 99 | * 10 8-10 |
| 100 | * 12 7-9 |
| 101 | * 14 10-12 |
| 102 | * 15 9-11 |
| 103 | */ |
| 104 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | #include <linux/signal.h> |
Matthew Wilcox | 53d5ed6 | 2006-10-11 01:22:01 -0700 | [diff] [blame] | 106 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | #include <linux/blkdev.h> |
| 108 | #include <linux/interrupt.h> |
| 109 | #include <linux/stat.h> |
| 110 | #include <linux/init.h> |
| 111 | #include <linux/module.h> |
| 112 | #include <linux/delay.h> |
| 113 | |
| 114 | #include "scsi.h" |
| 115 | #include <scsi/scsi_host.h> |
| 116 | #include "t128.h" |
| 117 | #define AUTOPROBE_IRQ |
| 118 | #include "NCR5380.h" |
| 119 | |
| 120 | static struct override { |
| 121 | unsigned long address; |
| 122 | int irq; |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 123 | } overrides |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | #ifdef T128_OVERRIDE |
| 125 | [] __initdata = T128_OVERRIDE; |
| 126 | #else |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 127 | [4] __initdata = {{0, IRQ_AUTO}, {0, IRQ_AUTO}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | {0 ,IRQ_AUTO}, {0, IRQ_AUTO}}; |
| 129 | #endif |
| 130 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 131 | #define NO_OVERRIDES ARRAY_SIZE(overrides) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
| 133 | static struct base { |
| 134 | unsigned int address; |
| 135 | int noauto; |
| 136 | } bases[] __initdata = { |
| 137 | { 0xcc000, 0}, { 0xc8000, 0}, { 0xdc000, 0}, { 0xd8000, 0} |
| 138 | }; |
| 139 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 140 | #define NO_BASES ARRAY_SIZE(bases) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | static struct signature { |
| 143 | const char *string; |
| 144 | int offset; |
| 145 | } signatures[] __initdata = { |
| 146 | {"TSROM: SCSI BIOS, Version 1.12", 0x36}, |
| 147 | }; |
| 148 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 149 | #define NO_SIGNATURES ARRAY_SIZE(signatures) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | /* |
| 152 | * Function : t128_setup(char *str, int *ints) |
| 153 | * |
| 154 | * Purpose : LILO command line initialization of the overrides array, |
| 155 | * |
| 156 | * Inputs : str - unused, ints - array of integer parameters with ints[0] |
| 157 | * equal to the number of ints. |
| 158 | * |
| 159 | */ |
| 160 | |
| 161 | void __init t128_setup(char *str, int *ints){ |
| 162 | static int commandline_current = 0; |
| 163 | int i; |
| 164 | if (ints[0] != 2) |
| 165 | printk("t128_setup : usage t128=address,irq\n"); |
| 166 | else |
| 167 | if (commandline_current < NO_OVERRIDES) { |
| 168 | overrides[commandline_current].address = ints[1]; |
| 169 | overrides[commandline_current].irq = ints[2]; |
| 170 | for (i = 0; i < NO_BASES; ++i) |
| 171 | if (bases[i].address == ints[1]) { |
| 172 | bases[i].noauto = 1; |
| 173 | break; |
| 174 | } |
| 175 | ++commandline_current; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | /* |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 180 | * Function : int t128_detect(struct scsi_host_template * tpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | * |
| 182 | * Purpose : detects and initializes T128,T128F, or T228 controllers |
| 183 | * that were autoprobed, overridden on the LILO command line, |
| 184 | * or specified at compile time. |
| 185 | * |
| 186 | * Inputs : tpnt - template for this SCSI adapter. |
| 187 | * |
| 188 | * Returns : 1 if a host adapter was found, 0 if not. |
| 189 | * |
| 190 | */ |
| 191 | |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 192 | int __init t128_detect(struct scsi_host_template * tpnt){ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | static int current_override = 0, current_base = 0; |
| 194 | struct Scsi_Host *instance; |
| 195 | unsigned long base; |
| 196 | void __iomem *p; |
| 197 | int sig, count; |
| 198 | |
| 199 | tpnt->proc_name = "t128"; |
Al Viro | dd7ab71 | 2013-03-31 01:15:54 -0400 | [diff] [blame] | 200 | tpnt->show_info = t128_show_info; |
| 201 | tpnt->write_info = t128_write_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | for (count = 0; current_override < NO_OVERRIDES; ++current_override) { |
| 204 | base = 0; |
| 205 | p = NULL; |
| 206 | |
| 207 | if (overrides[current_override].address) { |
| 208 | base = overrides[current_override].address; |
| 209 | p = ioremap(bases[current_base].address, 0x2000); |
| 210 | if (!p) |
| 211 | base = 0; |
| 212 | } else |
| 213 | for (; !base && (current_base < NO_BASES); ++current_base) { |
| 214 | #if (TDEBUG & TDEBUG_INIT) |
| 215 | printk("scsi-t128 : probing address %08x\n", bases[current_base].address); |
| 216 | #endif |
| 217 | if (bases[current_base].noauto) |
| 218 | continue; |
| 219 | p = ioremap(bases[current_base].address, 0x2000); |
| 220 | if (!p) |
| 221 | continue; |
| 222 | for (sig = 0; sig < NO_SIGNATURES; ++sig) |
| 223 | if (check_signature(p + signatures[sig].offset, |
| 224 | signatures[sig].string, |
| 225 | strlen(signatures[sig].string))) { |
| 226 | base = bases[current_base].address; |
| 227 | #if (TDEBUG & TDEBUG_INIT) |
| 228 | printk("scsi-t128 : detected board.\n"); |
| 229 | #endif |
| 230 | goto found; |
| 231 | } |
| 232 | iounmap(p); |
| 233 | } |
| 234 | |
| 235 | #if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT) |
| 236 | printk("scsi-t128 : base = %08x\n", (unsigned int) base); |
| 237 | #endif |
| 238 | |
| 239 | if (!base) |
| 240 | break; |
| 241 | |
| 242 | found: |
| 243 | instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata)); |
| 244 | if(instance == NULL) |
| 245 | break; |
| 246 | |
| 247 | instance->base = base; |
| 248 | ((struct NCR5380_hostdata *)instance->hostdata)->base = p; |
| 249 | |
| 250 | NCR5380_init(instance, 0); |
| 251 | |
| 252 | if (overrides[current_override].irq != IRQ_AUTO) |
| 253 | instance->irq = overrides[current_override].irq; |
| 254 | else |
| 255 | instance->irq = NCR5380_probe_irq(instance, T128_IRQS); |
| 256 | |
| 257 | if (instance->irq != SCSI_IRQ_NONE) |
Michael Opdenacker | 4909cc2 | 2014-03-05 06:09:41 +0100 | [diff] [blame] | 258 | if (request_irq(instance->irq, t128_intr, 0, "t128", |
Jeff Garzik | 1e64166 | 2007-11-11 19:52:05 -0500 | [diff] [blame] | 259 | instance)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | printk("scsi%d : IRQ%d not free, interrupts disabled\n", |
| 261 | instance->host_no, instance->irq); |
| 262 | instance->irq = SCSI_IRQ_NONE; |
| 263 | } |
| 264 | |
| 265 | if (instance->irq == SCSI_IRQ_NONE) { |
| 266 | printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no); |
| 267 | printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no); |
| 268 | } |
| 269 | |
| 270 | #if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT) |
| 271 | printk("scsi%d : irq = %d\n", instance->host_no, instance->irq); |
| 272 | #endif |
| 273 | |
| 274 | printk("scsi%d : at 0x%08lx", instance->host_no, instance->base); |
| 275 | if (instance->irq == SCSI_IRQ_NONE) |
| 276 | printk (" interrupts disabled"); |
| 277 | else |
| 278 | printk (" irq %d", instance->irq); |
| 279 | printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d", |
| 280 | CAN_QUEUE, CMD_PER_LUN, T128_PUBLIC_RELEASE); |
| 281 | NCR5380_print_options(instance); |
| 282 | printk("\n"); |
| 283 | |
| 284 | ++current_override; |
| 285 | ++count; |
| 286 | } |
| 287 | return count; |
| 288 | } |
| 289 | |
| 290 | static int t128_release(struct Scsi_Host *shost) |
| 291 | { |
| 292 | NCR5380_local_declare(); |
| 293 | NCR5380_setup(shost); |
| 294 | if (shost->irq) |
Jeff Garzik | 1e64166 | 2007-11-11 19:52:05 -0500 | [diff] [blame] | 295 | free_irq(shost->irq, shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | NCR5380_exit(shost); |
| 297 | if (shost->io_port && shost->n_io_port) |
| 298 | release_region(shost->io_port, shost->n_io_port); |
| 299 | scsi_unregister(shost); |
| 300 | iounmap(base); |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | /* |
| 305 | * Function : int t128_biosparam(Disk * disk, struct block_device *dev, int *ip) |
| 306 | * |
| 307 | * Purpose : Generates a BIOS / DOS compatible H-C-S mapping for |
| 308 | * the specified device / size. |
| 309 | * |
| 310 | * Inputs : size = size of device in sectors (512 bytes), dev = block device |
| 311 | * major / minor, ip[] = {heads, sectors, cylinders} |
| 312 | * |
| 313 | * Returns : always 0 (success), initializes ip |
| 314 | * |
| 315 | */ |
| 316 | |
| 317 | /* |
| 318 | * XXX Most SCSI boards use this mapping, I could be incorrect. Some one |
| 319 | * using hard disks on a trantor should verify that this mapping corresponds |
| 320 | * to that used by the BIOS / ASPI driver by running the linux fdisk program |
| 321 | * and matching the H_C_S coordinates to what DOS uses. |
| 322 | */ |
| 323 | |
| 324 | int t128_biosparam(struct scsi_device *sdev, struct block_device *bdev, |
| 325 | sector_t capacity, int * ip) |
| 326 | { |
| 327 | ip[0] = 64; |
| 328 | ip[1] = 32; |
| 329 | ip[2] = capacity >> 11; |
| 330 | return 0; |
| 331 | } |
| 332 | |
| 333 | /* |
| 334 | * Function : int NCR5380_pread (struct Scsi_Host *instance, |
| 335 | * unsigned char *dst, int len) |
| 336 | * |
| 337 | * Purpose : Fast 5380 pseudo-dma read function, transfers len bytes to |
| 338 | * dst |
| 339 | * |
| 340 | * Inputs : dst = destination, len = length in bytes |
| 341 | * |
| 342 | * Returns : 0 on success, non zero on a failure such as a watchdog |
| 343 | * timeout. |
| 344 | */ |
| 345 | |
| 346 | static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst, |
| 347 | int len) { |
| 348 | NCR5380_local_declare(); |
| 349 | void __iomem *reg; |
| 350 | unsigned char *d = dst; |
| 351 | register int i = len; |
| 352 | |
| 353 | NCR5380_setup(instance); |
| 354 | reg = base + T_DATA_REG_OFFSET; |
| 355 | |
| 356 | #if 0 |
| 357 | for (; i; --i) { |
| 358 | while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier(); |
| 359 | #else |
| 360 | while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier(); |
| 361 | for (; i; --i) { |
| 362 | #endif |
| 363 | *d++ = readb(reg); |
| 364 | } |
| 365 | |
| 366 | if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) { |
| 367 | unsigned char tmp; |
| 368 | void __iomem *foo = base + T_CONTROL_REG_OFFSET; |
| 369 | tmp = readb(foo); |
| 370 | writeb(tmp | T_CR_CT, foo); |
| 371 | writeb(tmp, foo); |
| 372 | printk("scsi%d : watchdog timer fired in NCR5380_pread()\n", |
| 373 | instance->host_no); |
| 374 | return -1; |
| 375 | } else |
| 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | /* |
| 380 | * Function : int NCR5380_pwrite (struct Scsi_Host *instance, |
| 381 | * unsigned char *src, int len) |
| 382 | * |
| 383 | * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from |
| 384 | * src |
| 385 | * |
| 386 | * Inputs : src = source, len = length in bytes |
| 387 | * |
| 388 | * Returns : 0 on success, non zero on a failure such as a watchdog |
| 389 | * timeout. |
| 390 | */ |
| 391 | |
| 392 | static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src, |
| 393 | int len) { |
| 394 | NCR5380_local_declare(); |
| 395 | void __iomem *reg; |
| 396 | unsigned char *s = src; |
| 397 | register int i = len; |
| 398 | |
| 399 | NCR5380_setup(instance); |
| 400 | reg = base + T_DATA_REG_OFFSET; |
| 401 | |
| 402 | #if 0 |
| 403 | for (; i; --i) { |
| 404 | while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier(); |
| 405 | #else |
| 406 | while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier(); |
| 407 | for (; i; --i) { |
| 408 | #endif |
| 409 | writeb(*s++, reg); |
| 410 | } |
| 411 | |
| 412 | if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) { |
| 413 | unsigned char tmp; |
| 414 | void __iomem *foo = base + T_CONTROL_REG_OFFSET; |
| 415 | tmp = readb(foo); |
| 416 | writeb(tmp | T_CR_CT, foo); |
| 417 | writeb(tmp, foo); |
| 418 | printk("scsi%d : watchdog timer fired in NCR5380_pwrite()\n", |
| 419 | instance->host_no); |
| 420 | return -1; |
| 421 | } else |
| 422 | return 0; |
| 423 | } |
| 424 | |
| 425 | MODULE_LICENSE("GPL"); |
| 426 | |
| 427 | #include "NCR5380.c" |
| 428 | |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 429 | static struct scsi_host_template driver_template = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | .name = "Trantor T128/T128F/T228", |
| 431 | .detect = t128_detect, |
| 432 | .release = t128_release, |
| 433 | .queuecommand = t128_queue_command, |
| 434 | .eh_abort_handler = t128_abort, |
| 435 | .eh_bus_reset_handler = t128_bus_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | .bios_param = t128_biosparam, |
| 437 | .can_queue = CAN_QUEUE, |
| 438 | .this_id = 7, |
| 439 | .sg_tablesize = SG_ALL, |
| 440 | .cmd_per_lun = CMD_PER_LUN, |
| 441 | .use_clustering = DISABLE_CLUSTERING, |
| 442 | }; |
| 443 | #include "scsi_module.c" |