VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / drivers / scsi / t128.c
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  
105 /*
106  * $Log: t128.c,v $
107  */
108
109 #include <asm/system.h>
110 #include <linux/signal.h>
111 #include <linux/sched.h>
112 #include <asm/io.h>
113 #include <linux/blkdev.h>
114 #include <linux/interrupt.h>
115 #include <linux/stat.h>
116 #include <linux/init.h>
117 #include <linux/module.h>
118 #include <linux/delay.h>
119
120 #include "scsi.h"
121 #include <scsi/scsi_host.h>
122 #include "t128.h"
123 #define AUTOPROBE_IRQ
124 #include "NCR5380.h"
125
126 static struct override {
127     unsigned long address;
128     int irq;
129 } overrides 
130 #ifdef T128_OVERRIDE
131     [] __initdata = T128_OVERRIDE;
132 #else
133     [4] __initdata = {{0, IRQ_AUTO}, {0, IRQ_AUTO}, 
134         {0 ,IRQ_AUTO}, {0, IRQ_AUTO}};
135 #endif
136
137 #define NO_OVERRIDES (sizeof(overrides) / sizeof(struct override))
138
139 static struct base {
140     unsigned int address;
141     int noauto;
142 } bases[] __initdata = {
143     { 0xcc000, 0}, { 0xc8000, 0}, { 0xdc000, 0}, { 0xd8000, 0}
144 };
145
146 #define NO_BASES (sizeof (bases) / sizeof (struct base))
147
148 static struct signature {
149     const char *string;
150     int offset;
151 } signatures[] __initdata = {
152 {"TSROM: SCSI BIOS, Version 1.12", 0x36},
153 };
154
155 #define NO_SIGNATURES (sizeof (signatures) /  sizeof (struct signature))
156
157 /*
158  * Function : t128_setup(char *str, int *ints)
159  *
160  * Purpose : LILO command line initialization of the overrides array,
161  * 
162  * Inputs : str - unused, ints - array of integer parameters with ints[0]
163  *      equal to the number of ints.
164  *
165  */
166
167 void __init t128_setup(char *str, int *ints){
168     static int commandline_current = 0;
169     int i;
170     if (ints[0] != 2) 
171         printk("t128_setup : usage t128=address,irq\n");
172     else 
173         if (commandline_current < NO_OVERRIDES) {
174             overrides[commandline_current].address = ints[1];
175             overrides[commandline_current].irq = ints[2];
176             for (i = 0; i < NO_BASES; ++i)
177                 if (bases[i].address == ints[1]) {
178                     bases[i].noauto = 1;
179                     break;
180                 }
181             ++commandline_current;
182         }
183 }
184
185 /* 
186  * Function : int t128_detect(Scsi_Host_Template * tpnt)
187  *
188  * Purpose : detects and initializes T128,T128F, or T228 controllers
189  *      that were autoprobed, overridden on the LILO command line, 
190  *      or specified at compile time.
191  *
192  * Inputs : tpnt - template for this SCSI adapter.
193  * 
194  * Returns : 1 if a host adapter was found, 0 if not.
195  *
196  */
197
198 int __init t128_detect(Scsi_Host_Template * tpnt){
199     static int current_override = 0, current_base = 0;
200     struct Scsi_Host *instance;
201     unsigned long base;
202     int sig, count;
203
204     tpnt->proc_name = "t128";
205     tpnt->proc_info = &t128_proc_info;
206
207     for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
208         base = 0;
209
210         if (overrides[current_override].address)
211             base = overrides[current_override].address;
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                 for (sig = 0; sig < NO_SIGNATURES; ++sig) 
218                     if (!bases[current_base].noauto && 
219                         isa_check_signature(bases[current_base].address +
220                                         signatures[sig].offset,
221                                         signatures[sig].string,
222                                         strlen(signatures[sig].string))) {
223                         base = bases[current_base].address;
224 #if (TDEBUG & TDEBUG_INIT)
225                         printk("scsi-t128 : detected board.\n");
226 #endif
227                         break;
228                     }
229             }
230
231 #if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
232         printk("scsi-t128 : base = %08x\n", (unsigned int) base);
233 #endif
234
235         if (!base)
236             break;
237
238         instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
239         if(instance == NULL)
240                 break;
241                 
242         instance->base = base;
243
244         NCR5380_init(instance, 0);
245
246         if (overrides[current_override].irq != IRQ_AUTO)
247             instance->irq = overrides[current_override].irq;
248         else 
249             instance->irq = NCR5380_probe_irq(instance, T128_IRQS);
250
251         if (instance->irq != SCSI_IRQ_NONE) 
252             if (request_irq(instance->irq, t128_intr, SA_INTERRUPT, "t128", instance)) {
253                 printk("scsi%d : IRQ%d not free, interrupts disabled\n", 
254                     instance->host_no, instance->irq);
255                 instance->irq = SCSI_IRQ_NONE;
256             } 
257
258         if (instance->irq == SCSI_IRQ_NONE) {
259             printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
260             printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
261         }
262
263 #if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
264         printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
265 #endif
266
267         printk("scsi%d : at 0x%08lx", instance->host_no, instance->base);
268         if (instance->irq == SCSI_IRQ_NONE)
269             printk (" interrupts disabled");
270         else 
271             printk (" irq %d", instance->irq);
272         printk(" options CAN_QUEUE=%d  CMD_PER_LUN=%d release=%d",
273             CAN_QUEUE, CMD_PER_LUN, T128_PUBLIC_RELEASE);
274         NCR5380_print_options(instance);
275         printk("\n");
276
277         ++current_override;
278         ++count;
279     }
280     return count;
281 }
282
283 static int t128_release(struct Scsi_Host *shost)
284 {
285         if (shost->irq)
286                 free_irq(shost->irq, NULL);
287         if (shost->io_port && shost->n_io_port)
288                 release_region(shost->io_port, shost->n_io_port);
289         scsi_unregister(shost);
290         return 0;
291 }
292
293 /*
294  * Function : int t128_biosparam(Disk * disk, struct block_device *dev, int *ip)
295  *
296  * Purpose : Generates a BIOS / DOS compatible H-C-S mapping for 
297  *      the specified device / size.
298  * 
299  * Inputs : size = size of device in sectors (512 bytes), dev = block device
300  *      major / minor, ip[] = {heads, sectors, cylinders}  
301  *
302  * Returns : always 0 (success), initializes ip
303  *      
304  */
305
306 /* 
307  * XXX Most SCSI boards use this mapping, I could be incorrect.  Some one
308  * using hard disks on a trantor should verify that this mapping corresponds
309  * to that used by the BIOS / ASPI driver by running the linux fdisk program
310  * and matching the H_C_S coordinates to what DOS uses.
311  */
312
313 int t128_biosparam(struct scsi_device *sdev, struct block_device *bdev,
314                 sector_t capacity, int * ip)
315 {
316   ip[0] = 64;
317   ip[1] = 32;
318   ip[2] = capacity >> 11;
319   return 0;
320 }
321
322 /*
323  * Function : int NCR5380_pread (struct Scsi_Host *instance, 
324  *      unsigned char *dst, int len)
325  *
326  * Purpose : Fast 5380 pseudo-dma read function, transfers len bytes to 
327  *      dst
328  * 
329  * Inputs : dst = destination, len = length in bytes
330  *
331  * Returns : 0 on success, non zero on a failure such as a watchdog 
332  *      timeout.
333  */
334
335 static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst,
336     int len) {
337     unsigned long reg = instance->base + T_DATA_REG_OFFSET;
338     unsigned char *d = dst;
339     register int i = len;
340
341
342 #if 0
343     for (; i; --i) {
344         while (!(isa_readb(instance->base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
345 #else
346     while (!(isa_readb(instance->base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
347     for (; i; --i) {
348 #endif
349         *d++ = isa_readb(reg);
350     }
351
352     if (isa_readb(instance->base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
353         unsigned char tmp;
354         unsigned long foo;
355         foo = instance->base + T_CONTROL_REG_OFFSET;
356         tmp = isa_readb(foo);
357         isa_writeb(tmp | T_CR_CT, foo);
358         isa_writeb(tmp, foo);
359         printk("scsi%d : watchdog timer fired in NCR5380_pread()\n",
360             instance->host_no);
361         return -1;
362     } else
363         return 0;
364 }
365
366 /*
367  * Function : int NCR5380_pwrite (struct Scsi_Host *instance, 
368  *      unsigned char *src, int len)
369  *
370  * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from
371  *      src
372  * 
373  * Inputs : src = source, len = length in bytes
374  *
375  * Returns : 0 on success, non zero on a failure such as a watchdog 
376  *      timeout.
377  */
378
379 static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src,
380     int len) {
381     unsigned long reg = instance->base + T_DATA_REG_OFFSET;
382     unsigned char *s = src;
383     register int i = len;
384
385 #if 0
386     for (; i; --i) {
387         while (!(isa_readb(instance->base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
388 #else
389     while (!(isa_readb(instance->base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
390     for (; i; --i) {
391 #endif
392         isa_writeb(*s++, reg);
393     }
394
395     if (isa_readb(instance->base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
396         unsigned char tmp;
397         unsigned long foo;
398         foo = instance->base + T_CONTROL_REG_OFFSET;
399         tmp = isa_readb(foo);
400         isa_writeb(tmp | T_CR_CT, foo);
401         isa_writeb(tmp, foo);
402         printk("scsi%d : watchdog timer fired in NCR5380_pwrite()\n",
403             instance->host_no);
404         return -1;
405     } else 
406         return 0;
407 }
408
409 MODULE_LICENSE("GPL");
410
411 #include "NCR5380.c"
412
413 static Scsi_Host_Template driver_template = {
414         .name           = "Trantor T128/T128F/T228",
415         .detect         = t128_detect,
416         .release        = t128_release,
417         .queuecommand   = t128_queue_command,
418         .eh_abort_handler = t128_abort,
419         .eh_bus_reset_handler    = t128_bus_reset,
420         .eh_host_reset_handler   = t128_host_reset,
421         .eh_device_reset_handler = t128_device_reset,
422         .bios_param     = t128_biosparam,
423         .can_queue      = CAN_QUEUE,
424         .this_id        = 7,
425         .sg_tablesize   = SG_ALL,
426         .cmd_per_lun    = CMD_PER_LUN,
427         .use_clustering = DISABLE_CLUSTERING,
428 };
429 #include "scsi_module.c"