Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | * | |
1da177e4 LT |
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 | |
1da177e4 LT |
24 | */ |
25 | ||
26 | /* | |
1da177e4 LT |
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 | ||
1da177e4 | 71 | #include <linux/signal.h> |
53d5ed62 | 72 | #include <linux/io.h> |
1da177e4 LT |
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 | ||
1da177e4 LT |
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; | |
6391a113 | 88 | } overrides |
1da177e4 LT |
89 | #ifdef T128_OVERRIDE |
90 | [] __initdata = T128_OVERRIDE; | |
91 | #else | |
6391a113 | 92 | [4] __initdata = {{0, IRQ_AUTO}, {0, IRQ_AUTO}, |
1da177e4 LT |
93 | {0 ,IRQ_AUTO}, {0, IRQ_AUTO}}; |
94 | #endif | |
95 | ||
6391a113 | 96 | #define NO_OVERRIDES ARRAY_SIZE(overrides) |
1da177e4 LT |
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 | ||
6391a113 | 105 | #define NO_BASES ARRAY_SIZE(bases) |
1da177e4 LT |
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 | ||
6391a113 | 114 | #define NO_SIGNATURES ARRAY_SIZE(signatures) |
1da177e4 | 115 | |
925e4610 | 116 | #ifndef MODULE |
1da177e4 LT |
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 | ||
925e4610 FT |
127 | static int __init t128_setup(char *str) |
128 | { | |
d5f7e65d | 129 | static int commandline_current; |
1da177e4 | 130 | int i; |
925e4610 FT |
131 | int ints[10]; |
132 | ||
133 | get_options(str, ARRAY_SIZE(ints), ints); | |
1da177e4 LT |
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 | } | |
925e4610 | 147 | return 1; |
1da177e4 LT |
148 | } |
149 | ||
925e4610 FT |
150 | __setup("t128=", t128_setup); |
151 | #endif | |
152 | ||
1da177e4 | 153 | /* |
d0be4a7d | 154 | * Function : int t128_detect(struct scsi_host_template * tpnt) |
1da177e4 LT |
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 | ||
ed8b9e7f FT |
166 | static int __init t128_detect(struct scsi_host_template *tpnt) |
167 | { | |
d5f7e65d | 168 | static int current_override, current_base; |
1da177e4 LT |
169 | struct Scsi_Host *instance; |
170 | unsigned long base; | |
171 | void __iomem *p; | |
172 | int sig, count; | |
173 | ||
1da177e4 LT |
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) { | |
2f7dba9f FT |
185 | dprintk(NDEBUG_INIT, "t128: probing address 0x%08x\n", |
186 | bases[current_base].address); | |
1da177e4 LT |
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; | |
2f7dba9f | 197 | dprintk(NDEBUG_INIT, "t128: detected board\n"); |
1da177e4 LT |
198 | goto found; |
199 | } | |
200 | iounmap(p); | |
201 | } | |
202 | ||
2f7dba9f | 203 | dprintk(NDEBUG_INIT, "t128: base = 0x%08x\n", (unsigned int)base); |
1da177e4 LT |
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 | ||
b6488f97 FT |
218 | NCR5380_maybe_reset_bus(instance); |
219 | ||
1da177e4 LT |
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 | ||
22f5f10d FT |
225 | /* Compatibility with documented NCR5380 kernel parameters */ |
226 | if (instance->irq == 255) | |
227 | instance->irq = NO_IRQ; | |
228 | ||
229 | if (instance->irq != NO_IRQ) | |
4909cc2b | 230 | if (request_irq(instance->irq, t128_intr, 0, "t128", |
1e641664 | 231 | instance)) { |
1da177e4 LT |
232 | printk("scsi%d : IRQ%d not free, interrupts disabled\n", |
233 | instance->host_no, instance->irq); | |
22f5f10d | 234 | instance->irq = NO_IRQ; |
1da177e4 LT |
235 | } |
236 | ||
22f5f10d | 237 | if (instance->irq == NO_IRQ) { |
1da177e4 LT |
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 | ||
2f7dba9f FT |
242 | dprintk(NDEBUG_INIT, "scsi%d: irq = %d\n", |
243 | instance->host_no, instance->irq); | |
1da177e4 | 244 | |
1da177e4 LT |
245 | ++current_override; |
246 | ++count; | |
247 | } | |
248 | return count; | |
249 | } | |
250 | ||
251 | static int t128_release(struct Scsi_Host *shost) | |
252 | { | |
54d8fe44 FT |
253 | struct NCR5380_hostdata *hostdata = shost_priv(shost); |
254 | ||
22f5f10d | 255 | if (shost->irq != NO_IRQ) |
1e641664 | 256 | free_irq(shost->irq, shost); |
1da177e4 | 257 | NCR5380_exit(shost); |
1da177e4 | 258 | scsi_unregister(shost); |
54d8fe44 | 259 | iounmap(hostdata->base); |
1da177e4 LT |
260 | return 0; |
261 | } | |
262 | ||
263 | /* | |
264 | * Function : int t128_biosparam(Disk * disk, struct block_device *dev, int *ip) | |
265 | * | |
266 | * Purpose : Generates a BIOS / DOS compatible H-C-S mapping for | |
267 | * the specified device / size. | |
268 | * | |
269 | * Inputs : size = size of device in sectors (512 bytes), dev = block device | |
270 | * major / minor, ip[] = {heads, sectors, cylinders} | |
271 | * | |
272 | * Returns : always 0 (success), initializes ip | |
273 | * | |
274 | */ | |
275 | ||
276 | /* | |
277 | * XXX Most SCSI boards use this mapping, I could be incorrect. Some one | |
278 | * using hard disks on a trantor should verify that this mapping corresponds | |
279 | * to that used by the BIOS / ASPI driver by running the linux fdisk program | |
280 | * and matching the H_C_S coordinates to what DOS uses. | |
281 | */ | |
282 | ||
ed8b9e7f FT |
283 | static int t128_biosparam(struct scsi_device *sdev, struct block_device *bdev, |
284 | sector_t capacity, int *ip) | |
1da177e4 LT |
285 | { |
286 | ip[0] = 64; | |
287 | ip[1] = 32; | |
288 | ip[2] = capacity >> 11; | |
289 | return 0; | |
290 | } | |
291 | ||
292 | /* | |
293 | * Function : int NCR5380_pread (struct Scsi_Host *instance, | |
294 | * unsigned char *dst, int len) | |
295 | * | |
296 | * Purpose : Fast 5380 pseudo-dma read function, transfers len bytes to | |
297 | * dst | |
298 | * | |
299 | * Inputs : dst = destination, len = length in bytes | |
300 | * | |
301 | * Returns : 0 on success, non zero on a failure such as a watchdog | |
302 | * timeout. | |
303 | */ | |
304 | ||
54d8fe44 FT |
305 | static inline int |
306 | NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst, int len) | |
307 | { | |
308 | struct NCR5380_hostdata *hostdata = shost_priv(instance); | |
309 | void __iomem *reg, *base = hostdata->base; | |
1da177e4 LT |
310 | unsigned char *d = dst; |
311 | register int i = len; | |
312 | ||
1da177e4 LT |
313 | reg = base + T_DATA_REG_OFFSET; |
314 | ||
315 | #if 0 | |
316 | for (; i; --i) { | |
317 | while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier(); | |
318 | #else | |
319 | while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier(); | |
320 | for (; i; --i) { | |
321 | #endif | |
322 | *d++ = readb(reg); | |
323 | } | |
324 | ||
325 | if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) { | |
326 | unsigned char tmp; | |
327 | void __iomem *foo = base + T_CONTROL_REG_OFFSET; | |
328 | tmp = readb(foo); | |
329 | writeb(tmp | T_CR_CT, foo); | |
330 | writeb(tmp, foo); | |
331 | printk("scsi%d : watchdog timer fired in NCR5380_pread()\n", | |
332 | instance->host_no); | |
333 | return -1; | |
334 | } else | |
335 | return 0; | |
336 | } | |
337 | ||
338 | /* | |
339 | * Function : int NCR5380_pwrite (struct Scsi_Host *instance, | |
340 | * unsigned char *src, int len) | |
341 | * | |
342 | * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from | |
343 | * src | |
344 | * | |
345 | * Inputs : src = source, len = length in bytes | |
346 | * | |
347 | * Returns : 0 on success, non zero on a failure such as a watchdog | |
348 | * timeout. | |
349 | */ | |
350 | ||
54d8fe44 FT |
351 | static inline int |
352 | NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src, int len) | |
353 | { | |
354 | struct NCR5380_hostdata *hostdata = shost_priv(instance); | |
355 | void __iomem *reg, *base = hostdata->base; | |
1da177e4 LT |
356 | unsigned char *s = src; |
357 | register int i = len; | |
358 | ||
1da177e4 LT |
359 | reg = base + T_DATA_REG_OFFSET; |
360 | ||
361 | #if 0 | |
362 | for (; i; --i) { | |
363 | while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier(); | |
364 | #else | |
365 | while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier(); | |
366 | for (; i; --i) { | |
367 | #endif | |
368 | writeb(*s++, reg); | |
369 | } | |
370 | ||
371 | if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) { | |
372 | unsigned char tmp; | |
373 | void __iomem *foo = base + T_CONTROL_REG_OFFSET; | |
374 | tmp = readb(foo); | |
375 | writeb(tmp | T_CR_CT, foo); | |
376 | writeb(tmp, foo); | |
377 | printk("scsi%d : watchdog timer fired in NCR5380_pwrite()\n", | |
378 | instance->host_no); | |
379 | return -1; | |
380 | } else | |
381 | return 0; | |
382 | } | |
383 | ||
384 | MODULE_LICENSE("GPL"); | |
385 | ||
386 | #include "NCR5380.c" | |
387 | ||
d0be4a7d | 388 | static struct scsi_host_template driver_template = { |
1da177e4 LT |
389 | .name = "Trantor T128/T128F/T228", |
390 | .detect = t128_detect, | |
391 | .release = t128_release, | |
4d3d2a54 FT |
392 | .proc_name = "t128", |
393 | .show_info = t128_show_info, | |
394 | .write_info = t128_write_info, | |
8c32513b | 395 | .info = t128_info, |
1da177e4 LT |
396 | .queuecommand = t128_queue_command, |
397 | .eh_abort_handler = t128_abort, | |
398 | .eh_bus_reset_handler = t128_bus_reset, | |
1da177e4 LT |
399 | .bios_param = t128_biosparam, |
400 | .can_queue = CAN_QUEUE, | |
401 | .this_id = 7, | |
402 | .sg_tablesize = SG_ALL, | |
403 | .cmd_per_lun = CMD_PER_LUN, | |
404 | .use_clustering = DISABLE_CLUSTERING, | |
405 | }; | |
406 | #include "scsi_module.c" |