Import 2.3.18pre1
[davej-history.git] / drivers / scsi / t128.c
blob2fdf0c3cd781c84fff2f92542708ba84f7eeed17
1 #define AUTOSENSE
2 #define PSEUDO_DMA
4 /*
5 * Trantor T128/T128F/T228 driver
6 * Note : architecturally, the T100 and T130 are different and won't
7 * work
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
15 * DISTRIBUTION RELEASE 3.
17 * For more information, please consult
19 * Trantor Systems, Ltd.
20 * T128/T128F/T228 SCSI Host Adapter
21 * Hardware Specifications
23 * Trantor Systems, Ltd.
24 * 5415 Randall Place
25 * Fremont, CA 94538
26 * 1+ (415) 770-1400, FAX 1+ (415) 770-9910
28 * and
30 * NCR 5380 Family
31 * SCSI Protocol Controller
32 * Databook
34 * NCR Microelectronics
35 * 1635 Aeroplaza Drive
36 * Colorado Springs, CO 80916
37 * 1+ (719) 578-3400
38 * 1+ (800) 334-5454
42 * Options :
43 * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
44 * for commands that return with a CHECK CONDITION status.
46 * PSEUDO_DMA - enables PSEUDO-DMA hardware, should give a 3-4X performance
47 * increase compared to polled I/O.
49 * PARITY - enable parity checking. Not supported.
51 * SCSI2 - enable support for SCSI-II tagged queueing. Untested.
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.
59 * USLEEP - enable support for devices that don't disconnect. Untested.
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.
67 * 2. With command line overrides - t128=address,irq may be
68 * used on the LILO command line to override the defaults.
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}}
75 * Note that if the override methods are used, place holders must
76 * be specified for other boards in the system.
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) :
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
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
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
106 * $Log: t128.c,v $
109 #include <asm/system.h>
110 #include <linux/signal.h>
111 #include <linux/sched.h>
112 #include <asm/io.h>
113 #include <linux/blk.h>
114 #include "scsi.h"
115 #include "hosts.h"
116 #include "t128.h"
117 #define AUTOPROBE_IRQ
118 #include "NCR5380.h"
119 #include "constants.h"
120 #include "sd.h"
121 #include <linux/stat.h>
122 #include <linux/init.h>
124 struct proc_dir_entry proc_scsi_t128 = {
125 PROC_SCSI_T128, 4, "t128",
126 S_IFDIR | S_IRUGO | S_IXUGO, 2
130 static struct override {
131 unsigned char *address;
132 int irq;
133 } overrides
134 #ifdef T128_OVERRIDE
135 [] __initdata = T128_OVERRIDE;
136 #else
137 [4] __initdata = {{NULL,IRQ_AUTO}, {NULL,IRQ_AUTO},
138 {NULL,IRQ_AUTO}, {NULL,IRQ_AUTO}};
139 #endif
141 #define NO_OVERRIDES (sizeof(overrides) / sizeof(struct override))
143 static struct base {
144 unsigned int address;
145 int noauto;
146 } bases[] __initdata = {
147 { 0xcc000, 0}, { 0xc8000, 0}, { 0xdc000, 0}, { 0xd8000, 0}
150 #define NO_BASES (sizeof (bases) / sizeof (struct base))
152 static const struct signature {
153 const char *string;
154 int offset;
155 } signatures[] __initdata = {
156 {"TSROM: SCSI BIOS, Version 1.12", 0x36},
159 #define NO_SIGNATURES (sizeof (signatures) / sizeof (struct signature))
162 * Function : t128_setup(char *str, int *ints)
164 * Purpose : LILO command line initialization of the overrides array,
166 * Inputs : str - unused, ints - array of integer parameters with ints[0]
167 * equal to the number of ints.
171 void __init t128_setup(char *str, int *ints){
172 static int commandline_current = 0;
173 int i;
174 if (ints[0] != 2)
175 printk("t128_setup : usage t128=address,irq\n");
176 else
177 if (commandline_current < NO_OVERRIDES) {
178 overrides[commandline_current].address = (unsigned char *) ints[1];
179 overrides[commandline_current].irq = ints[2];
180 for (i = 0; i < NO_BASES; ++i)
181 if (bases[i].address == ints[1]) {
182 bases[i].noauto = 1;
183 break;
185 ++commandline_current;
190 * Function : int t128_detect(Scsi_Host_Template * tpnt)
192 * Purpose : detects and initializes T128,T128F, or T228 controllers
193 * that were autoprobed, overridden on the LILO command line,
194 * or specified at compile time.
196 * Inputs : tpnt - template for this SCSI adapter.
198 * Returns : 1 if a host adapter was found, 0 if not.
202 int __init t128_detect(Scsi_Host_Template * tpnt){
203 static int current_override = 0, current_base = 0;
204 struct Scsi_Host *instance;
205 unsigned char *base;
206 int sig, count;
208 tpnt->proc_dir = &proc_scsi_t128;
209 tpnt->proc_info = &t128_proc_info;
211 for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
212 base = NULL;
214 if (overrides[current_override].address)
215 base = overrides[current_override].address;
216 else
217 for (; !base && (current_base < NO_BASES); ++current_base) {
218 #if (TDEBUG & TDEBUG_INIT)
219 printk("scsi-t128 : probing address %08x\n", bases[current_base].address);
220 #endif
221 for (sig = 0; sig < NO_SIGNATURES; ++sig)
222 if (!bases[current_base].noauto &&
223 check_signature(bases[current_base].address +
224 signatures[sig].offset,
225 signatures[sig].string,
226 strlen(signatures[sig].string))) {
227 base = (unsigned char *) bases[current_base].address;
228 #if (TDEBUG & TDEBUG_INIT)
229 printk("scsi-t128 : detected board.\n");
230 #endif
231 break;
235 #if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
236 printk("scsi-t128 : base = %08x\n", (unsigned int) base);
237 #endif
239 if (!base)
240 break;
242 instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
243 instance->base = phys_to_virt((unsigned int)base);
245 NCR5380_init(instance, 0);
247 if (overrides[current_override].irq != IRQ_AUTO)
248 instance->irq = overrides[current_override].irq;
249 else
250 instance->irq = NCR5380_probe_irq(instance, T128_IRQS);
252 if (instance->irq != IRQ_NONE)
253 if (request_irq(instance->irq, do_t128_intr, SA_INTERRUPT, "t128", NULL)) {
254 printk("scsi%d : IRQ%d not free, interrupts disabled\n",
255 instance->host_no, instance->irq);
256 instance->irq = IRQ_NONE;
259 if (instance->irq == IRQ_NONE) {
260 printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
261 printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
264 #if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
265 printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
266 #endif
268 printk("scsi%d : at 0x%08x", instance->host_no, (int)
269 instance->base);
270 if (instance->irq == IRQ_NONE)
271 printk (" interrupts disabled");
272 else
273 printk (" irq %d", instance->irq);
274 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
275 CAN_QUEUE, CMD_PER_LUN, T128_PUBLIC_RELEASE);
276 NCR5380_print_options(instance);
277 printk("\n");
279 ++current_override;
280 ++count;
282 return count;
286 * Function : int t128_biosparam(Disk * disk, kdev_t dev, int *ip)
288 * Purpose : Generates a BIOS / DOS compatible H-C-S mapping for
289 * the specified device / size.
291 * Inputs : size = size of device in sectors (512 bytes), dev = block device
292 * major / minor, ip[] = {heads, sectors, cylinders}
294 * Returns : always 0 (success), initializes ip
299 * XXX Most SCSI boards use this mapping, I could be incorrect. Some one
300 * using hard disks on a trantor should verify that this mapping corresponds
301 * to that used by the BIOS / ASPI driver by running the linux fdisk program
302 * and matching the H_C_S coordinates to what DOS uses.
305 int t128_biosparam(Disk * disk, kdev_t dev, int * ip)
307 int size = disk->capacity;
308 ip[0] = 64;
309 ip[1] = 32;
310 ip[2] = size >> 11;
311 return 0;
315 * Function : int NCR5380_pread (struct Scsi_Host *instance,
316 * unsigned char *dst, int len)
318 * Purpose : Fast 5380 pseudo-dma read function, transfers len bytes to
319 * dst
321 * Inputs : dst = destination, len = length in bytes
323 * Returns : 0 on success, non zero on a failure such as a watchdog
324 * timeout.
327 static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst,
328 int len) {
329 register unsigned char *reg = (unsigned char *) (instance->base +
330 T_DATA_REG_OFFSET), *d = dst;
331 register int i = len;
334 #if 0
335 for (; i; --i) {
336 while (!(instance->base[T_STATUS_REG_OFFSET]) & T_ST_RDY) barrier();
337 #else
338 while (!(instance->base[T_STATUS_REG_OFFSET]) & T_ST_RDY) barrier();
339 for (; i; --i) {
340 #endif
341 *d++ = *reg;
344 if (*(instance->base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
345 unsigned char tmp;
346 volatile unsigned char *foo;
347 foo = instance->base + T_CONTROL_REG_OFFSET;
348 tmp = *foo;
349 *foo = tmp | T_CR_CT;
350 *foo = tmp;
351 printk("scsi%d : watchdog timer fired in NCR5380_pread()\n",
352 instance->host_no);
353 return -1;
354 } else
355 return 0;
359 * Function : int NCR5380_pwrite (struct Scsi_Host *instance,
360 * unsigned char *src, int len)
362 * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from
363 * src
365 * Inputs : src = source, len = length in bytes
367 * Returns : 0 on success, non zero on a failure such as a watchdog
368 * timeout.
371 static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src,
372 int len) {
373 register unsigned char *reg = (unsigned char *) (instance->base +
374 T_DATA_REG_OFFSET), *s = src;
375 register int i = len;
377 #if 0
378 for (; i; --i) {
379 while (!(instance->base[T_STATUS_REG_OFFSET]) & T_ST_RDY) barrier();
380 #else
381 while (!(instance->base[T_STATUS_REG_OFFSET]) & T_ST_RDY) barrier();
382 for (; i; --i) {
383 #endif
384 *reg = *s++;
387 if (*(instance->base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
388 unsigned char tmp;
389 volatile unsigned char *foo;
390 foo = instance->base + T_CONTROL_REG_OFFSET;
391 tmp = *foo;
392 *foo = tmp | T_CR_CT;
393 *foo = tmp;
394 printk("scsi%d : watchdog timer fired in NCR5380_pwrite()\n",
395 instance->host_no);
396 return -1;
397 } else
398 return 0;
401 #include "NCR5380.c"
403 #ifdef MODULE
404 /* Eventually this will go into an include file, but this will be later */
405 Scsi_Host_Template driver_template = TRANTOR_T128;
407 #include "scsi_module.c"
408 #endif