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