OSDN Git Service

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