Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #define AUTOSENSE |
| 2 | #define PSEUDO_DMA |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | #define UNSAFE /* Not unsafe for PAS16 -- use it */ |
Olaf Hering | 44456d3 | 2005-07-27 11:45:17 -0700 | [diff] [blame] | 4 | #define PDEBUG 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | |
| 6 | /* |
| 7 | * This driver adapted from Drew Eckhardt's Trantor T128 driver |
| 8 | * |
| 9 | * Copyright 1993, Drew Eckhardt |
| 10 | * Visionary Computing |
| 11 | * (Unix and Linux consulting and custom programming) |
| 12 | * drew@colorado.edu |
| 13 | * +1 (303) 666-5836 |
| 14 | * |
| 15 | * ( Based on T128 - DISTRIBUTION RELEASE 3. ) |
| 16 | * |
| 17 | * Modified to work with the Pro Audio Spectrum/Studio 16 |
| 18 | * by John Weidman. |
| 19 | * |
| 20 | * |
| 21 | * For more information, please consult |
| 22 | * |
| 23 | * Media Vision |
| 24 | * (510) 770-8600 |
| 25 | * (800) 348-7116 |
| 26 | * |
| 27 | * and |
| 28 | * |
| 29 | * NCR 5380 Family |
| 30 | * SCSI Protocol Controller |
| 31 | * Databook |
| 32 | * |
| 33 | * NCR Microelectronics |
| 34 | * 1635 Aeroplaza Drive |
| 35 | * Colorado Springs, CO 80916 |
| 36 | * 1+ (719) 578-3400 |
| 37 | * 1+ (800) 334-5454 |
| 38 | */ |
| 39 | |
| 40 | /* |
| 41 | * Options : |
| 42 | * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically |
| 43 | * for commands that return with a CHECK CONDITION status. |
| 44 | * |
| 45 | * LIMIT_TRANSFERSIZE - if defined, limit the pseudo-dma transfers to 512 |
| 46 | * bytes at a time. Since interrupts are disabled by default during |
| 47 | * these transfers, we might need this to give reasonable interrupt |
| 48 | * service time if the transfer size gets too large. |
| 49 | * |
| 50 | * PSEUDO_DMA - enables PSEUDO-DMA hardware, should give a 3-4X performance |
| 51 | * increase compared to polled I/O. |
| 52 | * |
| 53 | * PARITY - enable parity checking. Not supported. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | * |
| 55 | * UNSAFE - leave interrupts enabled during pseudo-DMA transfers. This |
| 56 | * parameter comes from the NCR5380 code. It is NOT unsafe with |
| 57 | * the PAS16 and you should use it. If you don't you will have |
| 58 | * a problem with dropped characters during high speed |
| 59 | * communications during SCSI transfers. If you really don't |
| 60 | * want to use UNSAFE you can try defining LIMIT_TRANSFERSIZE or |
| 61 | * twiddle with the transfer size in the high level code. |
| 62 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | * The card is detected and initialized in one of several ways : |
| 64 | * 1. Autoprobe (default) - There are many different models of |
| 65 | * the Pro Audio Spectrum/Studio 16, and I only have one of |
| 66 | * them, so this may require a little tweaking. An interrupt |
| 67 | * is triggered to autoprobe for the interrupt line. Note: |
| 68 | * with the newer model boards, the interrupt is set via |
| 69 | * software after reset using the default_irq for the |
| 70 | * current board number. |
| 71 | * |
| 72 | * 2. With command line overrides - pas16=port,irq may be |
| 73 | * used on the LILO command line to override the defaults. |
| 74 | * |
| 75 | * 3. With the PAS16_OVERRIDE compile time define. This is |
| 76 | * specified as an array of address, irq tuples. Ie, for |
| 77 | * one board at the default 0x388 address, IRQ10, I could say |
| 78 | * -DPAS16_OVERRIDE={{0x388, 10}} |
| 79 | * NOTE: Untested. |
| 80 | * |
| 81 | * 4. When included as a module, with arguments passed on the command line: |
| 82 | * pas16_irq=xx the interrupt |
| 83 | * pas16_addr=xx the port |
| 84 | * e.g. "modprobe pas16 pas16_addr=0x388 pas16_irq=5" |
| 85 | * |
| 86 | * Note that if the override methods are used, place holders must |
| 87 | * be specified for other boards in the system. |
| 88 | * |
| 89 | * |
| 90 | * Configuration notes : |
| 91 | * The current driver does not support interrupt sharing with the |
| 92 | * sound portion of the card. If you use the same irq for the |
| 93 | * scsi port and sound you will have problems. Either use |
| 94 | * a different irq for the scsi port or don't use interrupts |
| 95 | * for the scsi port. |
| 96 | * |
| 97 | * If you have problems with your card not being recognized, use |
| 98 | * the LILO command line override. Try to get it recognized without |
| 99 | * interrupts. Ie, for a board at the default 0x388 base port, |
| 100 | * boot: linux pas16=0x388,255 |
| 101 | * |
| 102 | * SCSI_IRQ_NONE (255) should be specified for no interrupt, |
| 103 | * IRQ_AUTO (254) to autoprobe for an IRQ line if overridden |
| 104 | * on the command line. |
| 105 | * |
| 106 | * (IRQ_AUTO == 254, SCSI_IRQ_NONE == 255 in NCR5380.h) |
| 107 | */ |
| 108 | |
| 109 | #include <linux/module.h> |
| 110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | #include <linux/signal.h> |
| 112 | #include <linux/proc_fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | #include <asm/io.h> |
| 114 | #include <asm/dma.h> |
| 115 | #include <linux/blkdev.h> |
| 116 | #include <linux/delay.h> |
| 117 | #include <linux/interrupt.h> |
| 118 | #include <linux/stat.h> |
| 119 | #include <linux/init.h> |
| 120 | |
| 121 | #include "scsi.h" |
| 122 | #include <scsi/scsi_host.h> |
| 123 | #include "pas16.h" |
| 124 | #define AUTOPROBE_IRQ |
| 125 | #include "NCR5380.h" |
| 126 | |
| 127 | |
| 128 | static int pas_maxi = 0; |
| 129 | static int pas_wmaxi = 0; |
| 130 | static unsigned short pas16_addr = 0; |
| 131 | static int pas16_irq = 0; |
| 132 | |
| 133 | |
Adrian Bunk | 408b664 | 2005-05-01 08:59:29 -0700 | [diff] [blame] | 134 | static const int scsi_irq_translate[] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | { 0, 0, 1, 2, 3, 4, 5, 6, 0, 0, 7, 8, 9, 0, 10, 11 }; |
| 136 | |
| 137 | /* The default_irqs array contains values used to set the irq into the |
| 138 | * board via software (as must be done on newer model boards without |
| 139 | * irq jumpers on the board). The first value in the array will be |
| 140 | * assigned to logical board 0, the next to board 1, etc. |
| 141 | */ |
Adrian Bunk | 408b664 | 2005-05-01 08:59:29 -0700 | [diff] [blame] | 142 | static int default_irqs[] __initdata = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | { PAS16_DEFAULT_BOARD_1_IRQ, |
| 144 | PAS16_DEFAULT_BOARD_2_IRQ, |
| 145 | PAS16_DEFAULT_BOARD_3_IRQ, |
| 146 | PAS16_DEFAULT_BOARD_4_IRQ |
| 147 | }; |
| 148 | |
| 149 | static struct override { |
| 150 | unsigned short io_port; |
| 151 | int irq; |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 152 | } overrides |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | #ifdef PAS16_OVERRIDE |
| 154 | [] __initdata = PAS16_OVERRIDE; |
| 155 | #else |
| 156 | [4] __initdata = {{0,IRQ_AUTO}, {0,IRQ_AUTO}, {0,IRQ_AUTO}, |
| 157 | {0,IRQ_AUTO}}; |
| 158 | #endif |
| 159 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 160 | #define NO_OVERRIDES ARRAY_SIZE(overrides) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | static struct base { |
| 163 | unsigned short io_port; |
| 164 | int noauto; |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 165 | } bases[] __initdata = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | { {PAS16_DEFAULT_BASE_1, 0}, |
| 167 | {PAS16_DEFAULT_BASE_2, 0}, |
| 168 | {PAS16_DEFAULT_BASE_3, 0}, |
| 169 | {PAS16_DEFAULT_BASE_4, 0} |
| 170 | }; |
| 171 | |
Tobias Klauser | 6391a11 | 2006-06-08 22:23:48 -0700 | [diff] [blame] | 172 | #define NO_BASES ARRAY_SIZE(bases) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
Adrian Bunk | 408b664 | 2005-05-01 08:59:29 -0700 | [diff] [blame] | 174 | static const unsigned short pas16_offset[ 8 ] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { |
| 176 | 0x1c00, /* OUTPUT_DATA_REG */ |
| 177 | 0x1c01, /* INITIATOR_COMMAND_REG */ |
| 178 | 0x1c02, /* MODE_REG */ |
| 179 | 0x1c03, /* TARGET_COMMAND_REG */ |
| 180 | 0x3c00, /* STATUS_REG ro, SELECT_ENABLE_REG wo */ |
| 181 | 0x3c01, /* BUS_AND_STATUS_REG ro, START_DMA_SEND_REG wo */ |
| 182 | 0x3c02, /* INPUT_DATA_REGISTER ro, (N/A on PAS16 ?) |
| 183 | * START_DMA_TARGET_RECEIVE_REG wo |
| 184 | */ |
| 185 | 0x3c03, /* RESET_PARITY_INTERRUPT_REG ro, |
| 186 | * START_DMA_INITIATOR_RECEIVE_REG wo |
| 187 | */ |
| 188 | }; |
| 189 | /*----------------------------------------------------------------*/ |
| 190 | /* the following will set the monitor border color (useful to find |
| 191 | where something crashed or gets stuck at */ |
| 192 | /* 1 = blue |
| 193 | 2 = green |
| 194 | 3 = cyan |
| 195 | 4 = red |
| 196 | 5 = magenta |
| 197 | 6 = yellow |
| 198 | 7 = white |
| 199 | */ |
| 200 | #if 1 |
| 201 | #define rtrc(i) {inb(0x3da); outb(0x31, 0x3c0); outb((i), 0x3c0);} |
| 202 | #else |
| 203 | #define rtrc(i) {} |
| 204 | #endif |
| 205 | |
| 206 | |
| 207 | /* |
| 208 | * Function : enable_board( int board_num, unsigned short port ) |
| 209 | * |
| 210 | * Purpose : set address in new model board |
| 211 | * |
| 212 | * Inputs : board_num - logical board number 0-3, port - base address |
| 213 | * |
| 214 | */ |
| 215 | |
| 216 | static void __init |
| 217 | enable_board( int board_num, unsigned short port ) |
| 218 | { |
| 219 | outb( 0xbc + board_num, MASTER_ADDRESS_PTR ); |
| 220 | outb( port >> 2, MASTER_ADDRESS_PTR ); |
| 221 | } |
| 222 | |
| 223 | |
| 224 | |
| 225 | /* |
| 226 | * Function : init_board( unsigned short port, int irq ) |
| 227 | * |
| 228 | * Purpose : Set the board up to handle the SCSI interface |
| 229 | * |
| 230 | * Inputs : port - base address of the board, |
| 231 | * irq - irq to assign to the SCSI port |
| 232 | * force_irq - set it even if it conflicts with sound driver |
| 233 | * |
| 234 | */ |
| 235 | |
| 236 | static void __init |
| 237 | init_board( unsigned short io_port, int irq, int force_irq ) |
| 238 | { |
| 239 | unsigned int tmp; |
| 240 | unsigned int pas_irq_code; |
| 241 | |
| 242 | /* Initialize the SCSI part of the board */ |
| 243 | |
| 244 | outb( 0x30, io_port + P_TIMEOUT_COUNTER_REG ); /* Timeout counter */ |
| 245 | outb( 0x01, io_port + P_TIMEOUT_STATUS_REG_OFFSET ); /* Reset TC */ |
| 246 | outb( 0x01, io_port + WAIT_STATE ); /* 1 Wait state */ |
| 247 | |
| 248 | NCR5380_read( RESET_PARITY_INTERRUPT_REG ); |
| 249 | |
| 250 | /* Set the SCSI interrupt pointer without mucking up the sound |
| 251 | * interrupt pointer in the same byte. |
| 252 | */ |
| 253 | pas_irq_code = ( irq < 16 ) ? scsi_irq_translate[irq] : 0; |
| 254 | tmp = inb( io_port + IO_CONFIG_3 ); |
| 255 | |
| 256 | if( (( tmp & 0x0f ) == pas_irq_code) && pas_irq_code > 0 |
| 257 | && !force_irq ) |
| 258 | { |
| 259 | printk( "pas16: WARNING: Can't use same irq as sound " |
| 260 | "driver -- interrupts disabled\n" ); |
| 261 | /* Set up the drive parameters, disable 5380 interrupts */ |
| 262 | outb( 0x4d, io_port + SYS_CONFIG_4 ); |
| 263 | } |
| 264 | else |
| 265 | { |
| 266 | tmp = ( tmp & 0x0f ) | ( pas_irq_code << 4 ); |
| 267 | outb( tmp, io_port + IO_CONFIG_3 ); |
| 268 | |
| 269 | /* Set up the drive parameters and enable 5380 interrupts */ |
| 270 | outb( 0x6d, io_port + SYS_CONFIG_4 ); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | |
| 275 | /* |
| 276 | * Function : pas16_hw_detect( unsigned short board_num ) |
| 277 | * |
| 278 | * Purpose : determine if a pas16 board is present |
| 279 | * |
| 280 | * Inputs : board_num - logical board number ( 0 - 3 ) |
| 281 | * |
| 282 | * Returns : 0 if board not found, 1 if found. |
| 283 | */ |
| 284 | |
| 285 | static int __init |
| 286 | pas16_hw_detect( unsigned short board_num ) |
| 287 | { |
| 288 | unsigned char board_rev, tmp; |
| 289 | unsigned short io_port = bases[ board_num ].io_port; |
| 290 | |
| 291 | /* See if we can find a PAS16 board at the address associated |
| 292 | * with this logical board number. |
| 293 | */ |
| 294 | |
| 295 | /* First, attempt to take a newer model board out of reset and |
| 296 | * give it a base address. This shouldn't affect older boards. |
| 297 | */ |
| 298 | enable_board( board_num, io_port ); |
| 299 | |
| 300 | /* Now see if it looks like a PAS16 board */ |
| 301 | board_rev = inb( io_port + PCB_CONFIG ); |
| 302 | |
| 303 | if( board_rev == 0xff ) |
| 304 | return 0; |
| 305 | |
| 306 | tmp = board_rev ^ 0xe0; |
| 307 | |
| 308 | outb( tmp, io_port + PCB_CONFIG ); |
| 309 | tmp = inb( io_port + PCB_CONFIG ); |
| 310 | outb( board_rev, io_port + PCB_CONFIG ); |
| 311 | |
| 312 | if( board_rev != tmp ) /* Not a PAS-16 */ |
| 313 | return 0; |
| 314 | |
| 315 | if( ( inb( io_port + OPERATION_MODE_1 ) & 0x03 ) != 0x03 ) |
| 316 | return 0; /* return if no SCSI interface found */ |
| 317 | |
| 318 | /* Mediavision has some new model boards that return ID bits |
| 319 | * that indicate a SCSI interface, but they're not (LMS). We'll |
| 320 | * put in an additional test to try to weed them out. |
| 321 | */ |
| 322 | |
| 323 | outb( 0x01, io_port + WAIT_STATE ); /* 1 Wait state */ |
| 324 | NCR5380_write( MODE_REG, 0x20 ); /* Is it really SCSI? */ |
| 325 | if( NCR5380_read( MODE_REG ) != 0x20 ) /* Write to a reg. */ |
| 326 | return 0; /* and try to read */ |
| 327 | NCR5380_write( MODE_REG, 0x00 ); /* it back. */ |
| 328 | if( NCR5380_read( MODE_REG ) != 0x00 ) |
| 329 | return 0; |
| 330 | |
| 331 | return 1; |
| 332 | } |
| 333 | |
| 334 | |
Finn Thain | 925e461 | 2014-11-12 16:11:49 +1100 | [diff] [blame] | 335 | #ifndef MODULE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | /* |
| 337 | * Function : pas16_setup(char *str, int *ints) |
| 338 | * |
| 339 | * Purpose : LILO command line initialization of the overrides array, |
| 340 | * |
| 341 | * Inputs : str - unused, ints - array of integer parameters with ints[0] |
| 342 | * equal to the number of ints. |
| 343 | * |
| 344 | */ |
| 345 | |
Finn Thain | 925e461 | 2014-11-12 16:11:49 +1100 | [diff] [blame] | 346 | static int __init pas16_setup(char *str) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | { |
| 348 | static int commandline_current = 0; |
| 349 | int i; |
Finn Thain | 925e461 | 2014-11-12 16:11:49 +1100 | [diff] [blame] | 350 | int ints[10]; |
| 351 | |
| 352 | get_options(str, ARRAY_SIZE(ints), ints); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | if (ints[0] != 2) |
| 354 | printk("pas16_setup : usage pas16=io_port,irq\n"); |
| 355 | else |
| 356 | if (commandline_current < NO_OVERRIDES) { |
| 357 | overrides[commandline_current].io_port = (unsigned short) ints[1]; |
| 358 | overrides[commandline_current].irq = ints[2]; |
| 359 | for (i = 0; i < NO_BASES; ++i) |
| 360 | if (bases[i].io_port == (unsigned short) ints[1]) { |
| 361 | bases[i].noauto = 1; |
| 362 | break; |
| 363 | } |
| 364 | ++commandline_current; |
| 365 | } |
Finn Thain | 925e461 | 2014-11-12 16:11:49 +1100 | [diff] [blame] | 366 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Finn Thain | 925e461 | 2014-11-12 16:11:49 +1100 | [diff] [blame] | 369 | __setup("pas16=", pas16_setup); |
| 370 | #endif |
| 371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | /* |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 373 | * Function : int pas16_detect(struct scsi_host_template * tpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | * |
| 375 | * Purpose : detects and initializes PAS16 controllers |
| 376 | * that were autoprobed, overridden on the LILO command line, |
| 377 | * or specified at compile time. |
| 378 | * |
| 379 | * Inputs : tpnt - template for this SCSI adapter. |
| 380 | * |
| 381 | * Returns : 1 if a host adapter was found, 0 if not. |
| 382 | * |
| 383 | */ |
| 384 | |
Finn Thain | ed8b9e7 | 2014-11-12 16:11:51 +1100 | [diff] [blame^] | 385 | static int __init pas16_detect(struct scsi_host_template *tpnt) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | { |
| 387 | static int current_override = 0; |
| 388 | static unsigned short current_base = 0; |
| 389 | struct Scsi_Host *instance; |
| 390 | unsigned short io_port; |
| 391 | int count; |
| 392 | |
| 393 | tpnt->proc_name = "pas16"; |
Al Viro | dd7ab71 | 2013-03-31 01:15:54 -0400 | [diff] [blame] | 394 | tpnt->show_info = pas16_show_info; |
| 395 | tpnt->write_info = pas16_write_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
| 397 | if (pas16_addr != 0) { |
| 398 | overrides[0].io_port = pas16_addr; |
| 399 | /* |
| 400 | * This is how we avoid seeing more than |
| 401 | * one host adapter at the same I/O port. |
| 402 | * Cribbed shamelessly from pas16_setup(). |
| 403 | */ |
| 404 | for (count = 0; count < NO_BASES; ++count) |
| 405 | if (bases[count].io_port == pas16_addr) { |
| 406 | bases[count].noauto = 1; |
| 407 | break; |
| 408 | } |
| 409 | } |
| 410 | if (pas16_irq != 0) |
| 411 | overrides[0].irq = pas16_irq; |
| 412 | |
| 413 | for (count = 0; current_override < NO_OVERRIDES; ++current_override) { |
| 414 | io_port = 0; |
| 415 | |
| 416 | if (overrides[current_override].io_port) |
| 417 | { |
| 418 | io_port = overrides[current_override].io_port; |
| 419 | enable_board( current_override, io_port ); |
| 420 | init_board( io_port, overrides[current_override].irq, 1 ); |
| 421 | } |
| 422 | else |
| 423 | for (; !io_port && (current_base < NO_BASES); ++current_base) { |
| 424 | #if (PDEBUG & PDEBUG_INIT) |
| 425 | printk("scsi-pas16 : probing io_port %04x\n", (unsigned int) bases[current_base].io_port); |
| 426 | #endif |
| 427 | if ( !bases[current_base].noauto && |
| 428 | pas16_hw_detect( current_base ) ){ |
| 429 | io_port = bases[current_base].io_port; |
| 430 | init_board( io_port, default_irqs[ current_base ], 0 ); |
| 431 | #if (PDEBUG & PDEBUG_INIT) |
| 432 | printk("scsi-pas16 : detected board.\n"); |
| 433 | #endif |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | |
| 438 | #if defined(PDEBUG) && (PDEBUG & PDEBUG_INIT) |
| 439 | printk("scsi-pas16 : io_port = %04x\n", (unsigned int) io_port); |
| 440 | #endif |
| 441 | |
| 442 | if (!io_port) |
| 443 | break; |
| 444 | |
| 445 | instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata)); |
| 446 | if(instance == NULL) |
| 447 | break; |
| 448 | |
| 449 | instance->io_port = io_port; |
| 450 | |
| 451 | NCR5380_init(instance, 0); |
| 452 | |
| 453 | if (overrides[current_override].irq != IRQ_AUTO) |
| 454 | instance->irq = overrides[current_override].irq; |
| 455 | else |
| 456 | instance->irq = NCR5380_probe_irq(instance, PAS16_IRQS); |
| 457 | |
| 458 | if (instance->irq != SCSI_IRQ_NONE) |
Michael Opdenacker | 4909cc2 | 2014-03-05 06:09:41 +0100 | [diff] [blame] | 459 | if (request_irq(instance->irq, pas16_intr, 0, |
Jeff Garzik | 1e64166 | 2007-11-11 19:52:05 -0500 | [diff] [blame] | 460 | "pas16", instance)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | printk("scsi%d : IRQ%d not free, interrupts disabled\n", |
| 462 | instance->host_no, instance->irq); |
| 463 | instance->irq = SCSI_IRQ_NONE; |
| 464 | } |
| 465 | |
| 466 | if (instance->irq == SCSI_IRQ_NONE) { |
| 467 | printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no); |
| 468 | printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no); |
| 469 | /* Disable 5380 interrupts, leave drive params the same */ |
| 470 | outb( 0x4d, io_port + SYS_CONFIG_4 ); |
| 471 | outb( (inb(io_port + IO_CONFIG_3) & 0x0f), io_port + IO_CONFIG_3 ); |
| 472 | } |
| 473 | |
| 474 | #if defined(PDEBUG) && (PDEBUG & PDEBUG_INIT) |
| 475 | printk("scsi%d : irq = %d\n", instance->host_no, instance->irq); |
| 476 | #endif |
| 477 | |
| 478 | printk("scsi%d : at 0x%04x", instance->host_no, (int) |
| 479 | instance->io_port); |
| 480 | if (instance->irq == SCSI_IRQ_NONE) |
| 481 | printk (" interrupts disabled"); |
| 482 | else |
| 483 | printk (" irq %d", instance->irq); |
| 484 | printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d", |
| 485 | CAN_QUEUE, CMD_PER_LUN, PAS16_PUBLIC_RELEASE); |
| 486 | NCR5380_print_options(instance); |
| 487 | printk("\n"); |
| 488 | |
| 489 | ++current_override; |
| 490 | ++count; |
| 491 | } |
| 492 | return count; |
| 493 | } |
| 494 | |
| 495 | /* |
| 496 | * Function : int pas16_biosparam(Disk *disk, struct block_device *dev, int *ip) |
| 497 | * |
| 498 | * Purpose : Generates a BIOS / DOS compatible H-C-S mapping for |
| 499 | * the specified device / size. |
| 500 | * |
| 501 | * Inputs : size = size of device in sectors (512 bytes), dev = block device |
| 502 | * major / minor, ip[] = {heads, sectors, cylinders} |
| 503 | * |
| 504 | * Returns : always 0 (success), initializes ip |
| 505 | * |
| 506 | */ |
| 507 | |
| 508 | /* |
| 509 | * XXX Most SCSI boards use this mapping, I could be incorrect. Some one |
| 510 | * using hard disks on a trantor should verify that this mapping corresponds |
| 511 | * to that used by the BIOS / ASPI driver by running the linux fdisk program |
| 512 | * and matching the H_C_S coordinates to what DOS uses. |
| 513 | */ |
| 514 | |
Finn Thain | ed8b9e7 | 2014-11-12 16:11:51 +1100 | [diff] [blame^] | 515 | static int pas16_biosparam(struct scsi_device *sdev, struct block_device *dev, |
| 516 | sector_t capacity, int *ip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | { |
| 518 | int size = capacity; |
| 519 | ip[0] = 64; |
| 520 | ip[1] = 32; |
| 521 | ip[2] = size >> 11; /* I think I have it as /(32*64) */ |
| 522 | if( ip[2] > 1024 ) { /* yes, >, not >= */ |
| 523 | ip[0]=255; |
| 524 | ip[1]=63; |
| 525 | ip[2]=size/(63*255); |
| 526 | if( ip[2] > 1023 ) /* yes >1023... */ |
| 527 | ip[2] = 1023; |
| 528 | } |
| 529 | |
| 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | /* |
| 534 | * Function : int NCR5380_pread (struct Scsi_Host *instance, |
| 535 | * unsigned char *dst, int len) |
| 536 | * |
| 537 | * Purpose : Fast 5380 pseudo-dma read function, transfers len bytes to |
| 538 | * dst |
| 539 | * |
| 540 | * Inputs : dst = destination, len = length in bytes |
| 541 | * |
| 542 | * Returns : 0 on success, non zero on a failure such as a watchdog |
| 543 | * timeout. |
| 544 | */ |
| 545 | |
| 546 | static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst, |
| 547 | int len) { |
| 548 | register unsigned char *d = dst; |
| 549 | register unsigned short reg = (unsigned short) (instance->io_port + |
| 550 | P_DATA_REG_OFFSET); |
| 551 | register int i = len; |
| 552 | int ii = 0; |
| 553 | |
| 554 | while ( !(inb(instance->io_port + P_STATUS_REG_OFFSET) & P_ST_RDY) ) |
| 555 | ++ii; |
| 556 | |
| 557 | insb( reg, d, i ); |
| 558 | |
| 559 | if ( inb(instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET) & P_TS_TIM) { |
| 560 | outb( P_TS_CT, instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET); |
| 561 | printk("scsi%d : watchdog timer fired in NCR5380_pread()\n", |
| 562 | instance->host_no); |
| 563 | return -1; |
| 564 | } |
| 565 | if (ii > pas_maxi) |
| 566 | pas_maxi = ii; |
| 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | /* |
| 571 | * Function : int NCR5380_pwrite (struct Scsi_Host *instance, |
| 572 | * unsigned char *src, int len) |
| 573 | * |
| 574 | * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from |
| 575 | * src |
| 576 | * |
| 577 | * Inputs : src = source, len = length in bytes |
| 578 | * |
| 579 | * Returns : 0 on success, non zero on a failure such as a watchdog |
| 580 | * timeout. |
| 581 | */ |
| 582 | |
| 583 | static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src, |
| 584 | int len) { |
| 585 | register unsigned char *s = src; |
| 586 | register unsigned short reg = (instance->io_port + P_DATA_REG_OFFSET); |
| 587 | register int i = len; |
| 588 | int ii = 0; |
| 589 | |
| 590 | while ( !((inb(instance->io_port + P_STATUS_REG_OFFSET)) & P_ST_RDY) ) |
| 591 | ++ii; |
| 592 | |
| 593 | outsb( reg, s, i ); |
| 594 | |
| 595 | if (inb(instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET) & P_TS_TIM) { |
| 596 | outb( P_TS_CT, instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET); |
| 597 | printk("scsi%d : watchdog timer fired in NCR5380_pwrite()\n", |
| 598 | instance->host_no); |
| 599 | return -1; |
| 600 | } |
| 601 | if (ii > pas_maxi) |
| 602 | pas_wmaxi = ii; |
| 603 | return 0; |
| 604 | } |
| 605 | |
| 606 | #include "NCR5380.c" |
| 607 | |
| 608 | static int pas16_release(struct Scsi_Host *shost) |
| 609 | { |
| 610 | if (shost->irq) |
Jeff Garzik | 1e64166 | 2007-11-11 19:52:05 -0500 | [diff] [blame] | 611 | free_irq(shost->irq, shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | NCR5380_exit(shost); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | if (shost->io_port && shost->n_io_port) |
| 614 | release_region(shost->io_port, shost->n_io_port); |
| 615 | scsi_unregister(shost); |
| 616 | return 0; |
| 617 | } |
| 618 | |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 619 | static struct scsi_host_template driver_template = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | .name = "Pro Audio Spectrum-16 SCSI", |
| 621 | .detect = pas16_detect, |
| 622 | .release = pas16_release, |
| 623 | .queuecommand = pas16_queue_command, |
| 624 | .eh_abort_handler = pas16_abort, |
| 625 | .eh_bus_reset_handler = pas16_bus_reset, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | .bios_param = pas16_biosparam, |
| 627 | .can_queue = CAN_QUEUE, |
| 628 | .this_id = 7, |
| 629 | .sg_tablesize = SG_ALL, |
| 630 | .cmd_per_lun = CMD_PER_LUN, |
| 631 | .use_clustering = DISABLE_CLUSTERING, |
| 632 | }; |
| 633 | #include "scsi_module.c" |
| 634 | |
| 635 | #ifdef MODULE |
| 636 | module_param(pas16_addr, ushort, 0); |
| 637 | module_param(pas16_irq, int, 0); |
| 638 | #endif |
| 639 | MODULE_LICENSE("GPL"); |