ncr5380: Remove *_RELEASE macros
[cascardo/linux.git] / drivers / scsi / t128.c
1 #define PSEUDO_DMA
2
3 /*
4  * Trantor T128/T128F/T228 driver
5  *      Note : architecturally, the T100 and T130 are different and won't 
6  *      work
7  *
8  * Copyright 1993, Drew Eckhardt
9  *      Visionary Computing
10  *      (Unix and Linux consulting and custom programming)
11  *      drew@colorado.edu
12  *      +1 (303) 440-4894
13  *
14  * For more information, please consult 
15  *
16  * Trantor Systems, Ltd.
17  * T128/T128F/T228 SCSI Host Adapter
18  * Hardware Specifications
19  * 
20  * Trantor Systems, Ltd. 
21  * 5415 Randall Place
22  * Fremont, CA 94538
23  * 1+ (415) 770-1400, FAX 1+ (415) 770-9910
24  */
25
26 /*
27  * The card is detected and initialized in one of several ways : 
28  * 1.  Autoprobe (default) - since the board is memory mapped, 
29  *     a BIOS signature is scanned for to locate the registers.
30  *     An interrupt is triggered to autoprobe for the interrupt
31  *     line.
32  *
33  * 2.  With command line overrides - t128=address,irq may be 
34  *     used on the LILO command line to override the defaults.
35  *
36  * 3.  With the T128_OVERRIDE compile time define.  This is 
37  *     specified as an array of address, irq tuples.  Ie, for
38  *     one board at the default 0xcc000 address, IRQ5, I could say 
39  *     -DT128_OVERRIDE={{0xcc000, 5}}
40  *      
41  *     Note that if the override methods are used, place holders must
42  *     be specified for other boards in the system.
43  * 
44  * T128/T128F jumper/dipswitch settings (note : on my sample, the switches 
45  * were epoxy'd shut, meaning I couldn't change the 0xcc000 base address) :
46  *
47  * T128    Sw7 Sw8 Sw6 = 0ws Sw5 = boot 
48  * T128F   Sw6 Sw7 Sw5 = 0ws Sw4 = boot Sw8 = floppy disable
49  * cc000   off off      
50  * c8000   off on
51  * dc000   on  off
52  * d8000   on  on
53  *
54  * 
55  * Interrupts 
56  * There is a 12 pin jumper block, jp1, numbered as follows : 
57  *   T128 (JP1)          T128F (J5)
58  * 2 4 6 8 10 12        11 9  7 5 3 1
59  * 1 3 5 7 9  11        12 10 8 6 4 2
60  *
61  * 3   2-4
62  * 5   1-3
63  * 7   3-5
64  * T128F only 
65  * 10 8-10
66  * 12 7-9
67  * 14 10-12
68  * 15 9-11
69  */
70  
71 #include <linux/signal.h>
72 #include <linux/io.h>
73 #include <linux/blkdev.h>
74 #include <linux/interrupt.h>
75 #include <linux/stat.h>
76 #include <linux/init.h>
77 #include <linux/module.h>
78 #include <linux/delay.h>
79
80 #include "scsi.h"
81 #include <scsi/scsi_host.h>
82 #include "t128.h"
83 #define AUTOPROBE_IRQ
84 #include "NCR5380.h"
85
86 static struct override {
87     unsigned long address;
88     int irq;
89 } overrides
90 #ifdef T128_OVERRIDE
91     [] __initdata = T128_OVERRIDE;
92 #else
93     [4] __initdata = {{0, IRQ_AUTO}, {0, IRQ_AUTO},
94         {0 ,IRQ_AUTO}, {0, IRQ_AUTO}};
95 #endif
96
97 #define NO_OVERRIDES ARRAY_SIZE(overrides)
98
99 static struct base {
100     unsigned int address;
101     int noauto;
102 } bases[] __initdata = {
103     { 0xcc000, 0}, { 0xc8000, 0}, { 0xdc000, 0}, { 0xd8000, 0}
104 };
105
106 #define NO_BASES ARRAY_SIZE(bases)
107
108 static struct signature {
109     const char *string;
110     int offset;
111 } signatures[] __initdata = {
112 {"TSROM: SCSI BIOS, Version 1.12", 0x36},
113 };
114
115 #define NO_SIGNATURES ARRAY_SIZE(signatures)
116
117 #ifndef MODULE
118 /*
119  * Function : t128_setup(char *str, int *ints)
120  *
121  * Purpose : LILO command line initialization of the overrides array,
122  * 
123  * Inputs : str - unused, ints - array of integer parameters with ints[0]
124  *      equal to the number of ints.
125  *
126  */
127
128 static int __init t128_setup(char *str)
129 {
130     static int commandline_current = 0;
131     int i;
132     int ints[10];
133
134     get_options(str, ARRAY_SIZE(ints), ints);
135     if (ints[0] != 2) 
136         printk("t128_setup : usage t128=address,irq\n");
137     else 
138         if (commandline_current < NO_OVERRIDES) {
139             overrides[commandline_current].address = ints[1];
140             overrides[commandline_current].irq = ints[2];
141             for (i = 0; i < NO_BASES; ++i)
142                 if (bases[i].address == ints[1]) {
143                     bases[i].noauto = 1;
144                     break;
145                 }
146             ++commandline_current;
147         }
148     return 1;
149 }
150
151 __setup("t128=", t128_setup);
152 #endif
153
154 /* 
155  * Function : int t128_detect(struct scsi_host_template * tpnt)
156  *
157  * Purpose : detects and initializes T128,T128F, or T228 controllers
158  *      that were autoprobed, overridden on the LILO command line, 
159  *      or specified at compile time.
160  *
161  * Inputs : tpnt - template for this SCSI adapter.
162  * 
163  * Returns : 1 if a host adapter was found, 0 if not.
164  *
165  */
166
167 static int __init t128_detect(struct scsi_host_template *tpnt)
168 {
169     static int current_override = 0, current_base = 0;
170     struct Scsi_Host *instance;
171     unsigned long base;
172     void __iomem *p;
173     int sig, count;
174
175     for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
176         base = 0;
177         p = NULL;
178
179         if (overrides[current_override].address) {
180             base = overrides[current_override].address;
181             p = ioremap(bases[current_base].address, 0x2000);
182             if (!p)
183                 base = 0;
184         } else 
185             for (; !base && (current_base < NO_BASES); ++current_base) {
186 #if (TDEBUG & TDEBUG_INIT)
187     printk("scsi-t128 : probing address %08x\n", bases[current_base].address);
188 #endif
189                 if (bases[current_base].noauto)
190                         continue;
191                 p = ioremap(bases[current_base].address, 0x2000);
192                 if (!p)
193                         continue;
194                 for (sig = 0; sig < NO_SIGNATURES; ++sig) 
195                     if (check_signature(p + signatures[sig].offset,
196                                         signatures[sig].string,
197                                         strlen(signatures[sig].string))) {
198                         base = bases[current_base].address;
199 #if (TDEBUG & TDEBUG_INIT)
200                         printk("scsi-t128 : detected board.\n");
201 #endif
202                         goto found;
203                     }
204                 iounmap(p);
205             }
206
207 #if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
208         printk("scsi-t128 : base = %08x\n", (unsigned int) base);
209 #endif
210
211         if (!base)
212             break;
213
214 found:
215         instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
216         if(instance == NULL)
217                 break;
218                 
219         instance->base = base;
220         ((struct NCR5380_hostdata *)instance->hostdata)->base = p;
221
222         NCR5380_init(instance, 0);
223
224         if (overrides[current_override].irq != IRQ_AUTO)
225             instance->irq = overrides[current_override].irq;
226         else 
227             instance->irq = NCR5380_probe_irq(instance, T128_IRQS);
228
229         /* Compatibility with documented NCR5380 kernel parameters */
230         if (instance->irq == 255)
231                 instance->irq = NO_IRQ;
232
233         if (instance->irq != NO_IRQ)
234             if (request_irq(instance->irq, t128_intr, 0, "t128",
235                             instance)) {
236                 printk("scsi%d : IRQ%d not free, interrupts disabled\n", 
237                     instance->host_no, instance->irq);
238                 instance->irq = NO_IRQ;
239             } 
240
241         if (instance->irq == NO_IRQ) {
242             printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
243             printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
244         }
245
246 #if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
247         printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
248 #endif
249
250         ++current_override;
251         ++count;
252     }
253     return count;
254 }
255
256 static int t128_release(struct Scsi_Host *shost)
257 {
258         NCR5380_local_declare();
259         NCR5380_setup(shost);
260         if (shost->irq != NO_IRQ)
261                 free_irq(shost->irq, shost);
262         NCR5380_exit(shost);
263         if (shost->io_port && shost->n_io_port)
264                 release_region(shost->io_port, shost->n_io_port);
265         scsi_unregister(shost);
266         iounmap(base);
267         return 0;
268 }
269
270 /*
271  * Function : int t128_biosparam(Disk * disk, struct block_device *dev, int *ip)
272  *
273  * Purpose : Generates a BIOS / DOS compatible H-C-S mapping for 
274  *      the specified device / size.
275  * 
276  * Inputs : size = size of device in sectors (512 bytes), dev = block device
277  *      major / minor, ip[] = {heads, sectors, cylinders}  
278  *
279  * Returns : always 0 (success), initializes ip
280  *      
281  */
282
283 /* 
284  * XXX Most SCSI boards use this mapping, I could be incorrect.  Some one
285  * using hard disks on a trantor should verify that this mapping corresponds
286  * to that used by the BIOS / ASPI driver by running the linux fdisk program
287  * and matching the H_C_S coordinates to what DOS uses.
288  */
289
290 static int t128_biosparam(struct scsi_device *sdev, struct block_device *bdev,
291                           sector_t capacity, int *ip)
292 {
293   ip[0] = 64;
294   ip[1] = 32;
295   ip[2] = capacity >> 11;
296   return 0;
297 }
298
299 /*
300  * Function : int NCR5380_pread (struct Scsi_Host *instance, 
301  *      unsigned char *dst, int len)
302  *
303  * Purpose : Fast 5380 pseudo-dma read function, transfers len bytes to 
304  *      dst
305  * 
306  * Inputs : dst = destination, len = length in bytes
307  *
308  * Returns : 0 on success, non zero on a failure such as a watchdog 
309  *      timeout.
310  */
311
312 static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst,
313     int len) {
314     NCR5380_local_declare();
315     void __iomem *reg;
316     unsigned char *d = dst;
317     register int i = len;
318
319     NCR5380_setup(instance);
320     reg = base + T_DATA_REG_OFFSET;
321
322 #if 0
323     for (; i; --i) {
324         while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
325 #else
326     while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
327     for (; i; --i) {
328 #endif
329         *d++ = readb(reg);
330     }
331
332     if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
333         unsigned char tmp;
334         void __iomem *foo = base + T_CONTROL_REG_OFFSET;
335         tmp = readb(foo);
336         writeb(tmp | T_CR_CT, foo);
337         writeb(tmp, foo);
338         printk("scsi%d : watchdog timer fired in NCR5380_pread()\n",
339             instance->host_no);
340         return -1;
341     } else
342         return 0;
343 }
344
345 /*
346  * Function : int NCR5380_pwrite (struct Scsi_Host *instance, 
347  *      unsigned char *src, int len)
348  *
349  * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from
350  *      src
351  * 
352  * Inputs : src = source, len = length in bytes
353  *
354  * Returns : 0 on success, non zero on a failure such as a watchdog 
355  *      timeout.
356  */
357
358 static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src,
359     int len) {
360     NCR5380_local_declare();
361     void __iomem *reg;
362     unsigned char *s = src;
363     register int i = len;
364
365     NCR5380_setup(instance);
366     reg = base + T_DATA_REG_OFFSET;
367
368 #if 0
369     for (; i; --i) {
370         while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
371 #else
372     while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
373     for (; i; --i) {
374 #endif
375         writeb(*s++, reg);
376     }
377
378     if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
379         unsigned char tmp;
380         void __iomem *foo = base + T_CONTROL_REG_OFFSET;
381         tmp = readb(foo);
382         writeb(tmp | T_CR_CT, foo);
383         writeb(tmp, foo);
384         printk("scsi%d : watchdog timer fired in NCR5380_pwrite()\n",
385             instance->host_no);
386         return -1;
387     } else 
388         return 0;
389 }
390
391 MODULE_LICENSE("GPL");
392
393 #include "NCR5380.c"
394
395 static struct scsi_host_template driver_template = {
396         .name           = "Trantor T128/T128F/T228",
397         .detect         = t128_detect,
398         .release        = t128_release,
399         .proc_name      = "t128",
400         .show_info      = t128_show_info,
401         .write_info     = t128_write_info,
402         .info           = t128_info,
403         .queuecommand   = t128_queue_command,
404         .eh_abort_handler = t128_abort,
405         .eh_bus_reset_handler    = t128_bus_reset,
406         .bios_param     = t128_biosparam,
407         .can_queue      = CAN_QUEUE,
408         .this_id        = 7,
409         .sg_tablesize   = SG_ALL,
410         .cmd_per_lun    = CMD_PER_LUN,
411         .use_clustering = DISABLE_CLUSTERING,
412 };
413 #include "scsi_module.c"