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