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