3 #define BOARD_REQUIRES_NO_UDELAY /* PAS16 needs no I/O recovery delays */
4 #define UNSAFE /* Not unsafe for PAS16 -- use it */
7 * This driver adapted from Drew Eckhardt's Trantor T128 driver
9 * Copyright 1993, Drew Eckhardt
11 * (Unix and Linux consulting and custom programming)
15 * ( Based on T128 - DISTRIBUTION RELEASE 3. )
17 * Modified to work with the Pro Audio Spectrum/Studio 16
21 * For more information, please consult
30 * SCSI Protocol Controller
33 * NCR Microelectronics
34 * 1635 Aeroplaza Drive
35 * Colorado Springs, CO 80916
42 * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
43 * for commands that return with a CHECK CONDITION status.
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.
50 * PSEUDO_DMA - enables PSEUDO-DMA hardware, should give a 3-4X performance
51 * increase compared to polled I/O.
53 * PARITY - enable parity checking. Not supported.
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.
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.
72 * 2. With command line overrides - pas16=port,irq may be
73 * used on the LILO command line to override the defaults.
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}}
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"
86 * Note that if the override methods are used, place holders must
87 * be specified for other boards in the system.
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
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
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.
106 * (IRQ_AUTO == 254, SCSI_IRQ_NONE == 255 in NCR5380.h)
109 #include <linux/module.h>
111 #include <asm/system.h>
112 #include <linux/signal.h>
113 #include <linux/proc_fs.h>
114 #include <linux/sched.h>
116 #include <linux/blk.h>
120 #define AUTOPROBE_IRQ
122 #include "constants.h"
125 #include <linux/stat.h>
126 #include <linux/init.h>
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;
133 static int scsi_irq_translate[] = { 0, 0, 1, 2, 3, 4, 5, 6, 0, 0, 7, 8, 9, 0, 10, 11 };
135 /* The default_irqs array contains values used to set the irq into the
136 * board via software (as must be done on newer model boards without
137 * irq jumpers on the board). The first value in the array will be
138 * assigned to logical board 0, the next to board 1, etc.
141 static int default_irqs[] __initdata = {
142 PAS16_DEFAULT_BOARD_1_IRQ,
143 PAS16_DEFAULT_BOARD_2_IRQ,
144 PAS16_DEFAULT_BOARD_3_IRQ,
145 PAS16_DEFAULT_BOARD_4_IRQ
148 static struct override {
149 unsigned short io_port;
152 #ifdef PAS16_OVERRIDE
153 [] __initdata = PAS16_OVERRIDE;
163 #define NO_OVERRIDES (sizeof(overrides) / sizeof(struct override))
166 unsigned short io_port;
168 } bases[] __initdata = {
169 {PAS16_DEFAULT_BASE_1, 0},
170 {PAS16_DEFAULT_BASE_2, 0},
171 {PAS16_DEFAULT_BASE_3, 0},
172 {PAS16_DEFAULT_BASE_4, 0}
175 #define NO_BASES (sizeof (bases) / sizeof (struct base))
177 unsigned short pas16_offset[8] = {
178 0x1c00, /* OUTPUT_DATA_REG */
179 0x1c01, /* INITIATOR_COMMAND_REG */
180 0x1c02, /* MODE_REG */
181 0x1c03, /* TARGET_COMMAND_REG */
182 0x3c00, /* STATUS_REG ro, SELECT_ENABLE_REG wo */
183 0x3c01, /* BUS_AND_STATUS_REG ro, START_DMA_SEND_REG wo */
184 0x3c02, /* INPUT_DATA_REGISTER ro, (N/A on PAS16 ?)
185 * START_DMA_TARGET_RECEIVE_REG wo
187 0x3c03, /* RESET_PARITY_INTERRUPT_REG ro,
188 * START_DMA_INITIATOR_RECEIVE_REG wo
191 /*----------------------------------------------------------------*/
194 * enable_board - enable a pas16 board
195 * @board_num: logical board id
196 * @port: port to assign it
198 * Sets the address on new model PAS16 hardware
201 static void __init enable_board(int board_num, unsigned short port)
203 outb(0xbc + board_num, MASTER_ADDRESS_PTR);
204 outb(port >> 2, MASTER_ADDRESS_PTR);
208 * init_board - set up board
209 * @port: board address
210 * @irq: interrupt line
211 * @force_irq: if true allow scsi/audio on the same int
213 * Set the board up to handle the SCSI interface
216 static void __init init_board(unsigned short io_port, int irq, int force_irq)
219 unsigned int pas_irq_code;
221 /* Initialize the SCSI part of the board */
223 outb(0x30, io_port + P_TIMEOUT_COUNTER_REG); /* Timeout counter */
224 outb(0x01, io_port + P_TIMEOUT_STATUS_REG_OFFSET); /* Reset TC */
225 outb(0x01, io_port + WAIT_STATE); /* 1 Wait state */
227 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
230 * Set the SCSI interrupt pointer without mucking up the sound
231 * interrupt pointer in the same byte.
234 pas_irq_code = (irq < 16) ? scsi_irq_translate[irq] : 0;
235 tmp = inb(io_port + IO_CONFIG_3);
237 if (((tmp & 0x0f) == pas_irq_code) && pas_irq_code > 0 && !force_irq) {
238 printk(KERN_WARNING "pas16: WARNING: Can't use same irq as sound " "driver -- interrupts disabled\n");
239 /* Set up the drive parameters, disable 5380 interrupts */
240 outb(0x4d, io_port + SYS_CONFIG_4);
242 tmp = (tmp & 0x0f) | (pas_irq_code << 4);
243 outb(tmp, io_port + IO_CONFIG_3);
245 /* Set up the drive parameters and enable 5380 interrupts */
246 outb(0x6d, io_port + SYS_CONFIG_4);
252 * pas16_hw_detect - probe for hardware
253 * @board_num: logical board ID to probe for
255 * Determine if a pas16 board is present
258 static int __init pas16_hw_detect(unsigned short board_num)
260 unsigned char board_rev, tmp;
261 unsigned short io_port = bases[board_num].io_port;
263 /* See if we can find a PAS16 board at the address associated
264 * with this logical board number.
267 /* First, attempt to take a newer model board out of reset and
268 * give it a base address. This shouldn't affect older boards.
270 enable_board(board_num, io_port);
272 /* Now see if it looks like a PAS16 board */
273 board_rev = inb(io_port + PCB_CONFIG);
275 if (board_rev == 0xff)
278 tmp = board_rev ^ 0xe0;
280 outb(tmp, io_port + PCB_CONFIG);
281 tmp = inb(io_port + PCB_CONFIG);
282 outb(board_rev, io_port + PCB_CONFIG);
284 if (board_rev != tmp) /* Not a PAS-16 */
287 if ((inb(io_port + OPERATION_MODE_1) & 0x03) != 0x03)
288 return 0; /* return if no SCSI interface found */
290 /* Mediavision has some new model boards that return ID bits
291 * that indicate a SCSI interface, but they're not (LMS). We'll
292 * put in an additional test to try to weed them out.
295 outb(0x01, io_port + WAIT_STATE); /* 1 Wait state */
296 NCR5380_write(MODE_REG, 0x20); /* Is it really SCSI? */
297 if (NCR5380_read(MODE_REG) != 0x20) /* Write to a reg. */
298 return 0; /* and try to read */
299 NCR5380_write(MODE_REG, 0x00); /* it back. */
300 if (NCR5380_read(MODE_REG) != 0x00)
307 * pas16_setup - parse command line
308 * @str: command line block
310 * LILO command line initialization of the overrides array from
311 * the passed in pas16= options
314 int __init pas16_setup(char *str)
316 static int commandline_current = 0;
320 get_options(str, sizeof(ints) / sizeof(int), ints);
322 printk(KERN_ERR "pas16_setup : usage pas16=io_port,irq\n");
323 else if (commandline_current < NO_OVERRIDES) {
324 overrides[commandline_current].io_port = (unsigned short) ints[1];
325 overrides[commandline_current].irq = ints[2];
326 for (i = 0; i < NO_BASES; ++i)
327 if (bases[i].io_port == (unsigned short) ints[1]) {
331 ++commandline_current;
336 __setup("pas16=", pas16_setup);
339 * pas16_detect - detect and configure a pas16
342 * Detects and initializes PAS16 controllers that were autoprobed,
343 * overridden on the LILO command line, or specified at compile time.
346 int __init pas16_detect(Scsi_Host_Template * tpnt)
348 static int current_override = 0;
349 static unsigned short current_base = 0;
350 struct Scsi_Host *instance;
351 unsigned short io_port;
354 tpnt->proc_name = "pas16";
355 tpnt->proc_info = &pas16_proc_info;
357 if (pas16_addr != 0) {
358 overrides[0].io_port = pas16_addr;
360 * This is how we avoid seeing more than
361 * one host adapter at the same I/O port.
362 * Cribbed shamelessly from pas16_setup().
364 for (count = 0; count < NO_BASES; ++count)
365 if (bases[count].io_port == pas16_addr) {
366 bases[count].noauto = 1;
371 overrides[0].irq = pas16_irq;
373 for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
376 if (overrides[current_override].io_port) {
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);
383 for (; !io_port && (current_base < NO_BASES); ++current_base) {
384 if (!bases[current_base].noauto && pas16_hw_detect(current_base)) {
385 io_port = bases[current_base].io_port;
386 init_board(io_port, default_irqs[current_base], 0);
394 instance = scsi_register(tpnt, sizeof(struct NCR5380_hostdata));
395 if (instance == NULL)
398 instance->io_port = io_port;
400 NCR5380_init(instance, 0);
402 if (overrides[current_override].irq != IRQ_AUTO)
403 instance->irq = overrides[current_override].irq;
405 instance->irq = NCR5380_probe_irq(instance, PAS16_IRQS);
407 if (instance->irq != SCSI_IRQ_NONE)
408 if (request_irq(instance->irq, do_pas16_intr, SA_INTERRUPT, "pas16", NULL)) {
409 printk(KERN_WARNING "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq);
410 instance->irq = SCSI_IRQ_NONE;
413 if (instance->irq == SCSI_IRQ_NONE) {
414 printk(KERN_INFO "scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
415 printk(KERN_INFO "scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
416 /* Disable 5380 interrupts, leave drive params the same */
417 outb(0x4d, io_port + SYS_CONFIG_4);
418 outb((inb(io_port + IO_CONFIG_3) & 0x0f), io_port + IO_CONFIG_3);
421 printk(KERN_INFO "scsi%d : at 0x%04x", instance->host_no, (int)
423 if (instance->irq == SCSI_IRQ_NONE)
424 printk(" interrupts disabled");
426 printk(" irq %d", instance->irq);
427 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d", CAN_QUEUE, CMD_PER_LUN, PAS16_PUBLIC_RELEASE);
428 NCR5380_print_options(instance);
438 * pas16_biosparam - generate C/H/S data
439 * @disk: Disk to set up
440 * @dev: device ident of disk
441 * @ip: array to return C/H/S mapping
443 * Generates a BIOS / DOS compatible H-C-S mapping for
444 * the specified device / size.
447 int pas16_biosparam(Disk * disk, kdev_t dev, int *ip)
449 int size = disk->capacity;
452 ip[2] = size >> 11; /* I think I have it as /(32*64) */
453 if (ip[2] > 1024) { /* yes, >, not >= */
456 ip[2] = size / (63 * 255);
457 if (ip[2] > 1023) /* yes >1023... */
465 * NCR5380_pread - pseudo DMA read
466 * @instance: board to read from
467 * @dst: destination for data
468 * @len: expected/max block length
470 * Fast 5380 pseudo-dma read function, transfers len bytes to
471 * dst. Unlike most boards the PAS has IRQs enabled here, which
475 static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst, int len)
477 unsigned char *d = dst;
478 unsigned short reg = (unsigned short) (instance->io_port + P_DATA_REG_OFFSET);
482 while (!(inb(instance->io_port + P_STATUS_REG_OFFSET) & P_ST_RDY))
487 if (inb(instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET) & P_TS_TIM) {
488 outb(P_TS_CT, instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET);
489 printk(KERN_ERR "scsi%d : watchdog timer fired in NCR5380_pread()\n", instance->host_no);
498 * NCR5380_pwrite - pseudo DMA write
499 * @instance: board to write to
500 * @src: source for data
501 * @len: expected/max block length
503 * Fast 5380 pseudo-dma write function, transfers len bytes from
504 * src. Unlike most boards the PAS has IRQs enabled here, which
508 static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src, int len)
510 unsigned char *s = src;
511 unsigned short reg = (instance->io_port + P_DATA_REG_OFFSET);
515 while (!((inb(instance->io_port + P_STATUS_REG_OFFSET)) & P_ST_RDY))
520 if (inb(instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET) & P_TS_TIM) {
521 outb(P_TS_CT, instance->io_port + P_TIMEOUT_STATUS_REG_OFFSET);
522 printk(KERN_ERR "scsi%d : watchdog timer fired in NCR5380_pwrite()\n", instance->host_no);
532 /* Eventually this will go into an include file, but this will be later */
533 static Scsi_Host_Template driver_template = MV_PAS16;
535 #include "scsi_module.c"
538 MODULE_PARM(pas16_addr, "h");
539 MODULE_PARM(pas16_irq, "i");
541 MODULE_LICENSE("GPL");