1#define AUTOSENSE
2#define PSEUDO_DMA
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109#include <asm/system.h>
110#include <linux/signal.h>
111#include <linux/io.h>
112#include <linux/blkdev.h>
113#include <linux/interrupt.h>
114#include <linux/stat.h>
115#include <linux/init.h>
116#include <linux/module.h>
117#include <linux/delay.h>
118
119#include "scsi.h"
120#include <scsi/scsi_host.h>
121#include "t128.h"
122#define AUTOPROBE_IRQ
123#include "NCR5380.h"
124
125static struct override {
126 unsigned long address;
127 int irq;
128} overrides
129#ifdef T128_OVERRIDE
130 [] __initdata = T128_OVERRIDE;
131#else
132 [4] __initdata = {{0, IRQ_AUTO}, {0, IRQ_AUTO},
133 {0 ,IRQ_AUTO}, {0, IRQ_AUTO}};
134#endif
135
136#define NO_OVERRIDES ARRAY_SIZE(overrides)
137
138static struct base {
139 unsigned int address;
140 int noauto;
141} bases[] __initdata = {
142 { 0xcc000, 0}, { 0xc8000, 0}, { 0xdc000, 0}, { 0xd8000, 0}
143};
144
145#define NO_BASES ARRAY_SIZE(bases)
146
147static struct signature {
148 const char *string;
149 int offset;
150} signatures[] __initdata = {
151{"TSROM: SCSI BIOS, Version 1.12", 0x36},
152};
153
154#define NO_SIGNATURES ARRAY_SIZE(signatures)
155
156
157
158
159
160
161
162
163
164
165
166void __init t128_setup(char *str, int *ints){
167 static int commandline_current = 0;
168 int i;
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}
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197int __init t128_detect(struct scsi_host_template * tpnt){
198 static int current_override = 0, current_base = 0;
199 struct Scsi_Host *instance;
200 unsigned long base;
201 void __iomem *p;
202 int sig, count;
203
204 tpnt->proc_name = "t128";
205 tpnt->proc_info = &t128_proc_info;
206
207 for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
208 base = 0;
209 p = NULL;
210
211 if (overrides[current_override].address) {
212 base = overrides[current_override].address;
213 p = ioremap(bases[current_base].address, 0x2000);
214 if (!p)
215 base = 0;
216 } else
217 for (; !base && (current_base < NO_BASES); ++current_base) {
218#if (TDEBUG & TDEBUG_INIT)
219 printk("scsi-t128 : probing address %08x\n", bases[current_base].address);
220#endif
221 if (bases[current_base].noauto)
222 continue;
223 p = ioremap(bases[current_base].address, 0x2000);
224 if (!p)
225 continue;
226 for (sig = 0; sig < NO_SIGNATURES; ++sig)
227 if (check_signature(p + signatures[sig].offset,
228 signatures[sig].string,
229 strlen(signatures[sig].string))) {
230 base = bases[current_base].address;
231#if (TDEBUG & TDEBUG_INIT)
232 printk("scsi-t128 : detected board.\n");
233#endif
234 goto found;
235 }
236 iounmap(p);
237 }
238
239#if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
240 printk("scsi-t128 : base = %08x\n", (unsigned int) base);
241#endif
242
243 if (!base)
244 break;
245
246found:
247 instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
248 if(instance == NULL)
249 break;
250
251 instance->base = base;
252 ((struct NCR5380_hostdata *)instance->hostdata)->base = p;
253
254 NCR5380_init(instance, 0);
255
256 if (overrides[current_override].irq != IRQ_AUTO)
257 instance->irq = overrides[current_override].irq;
258 else
259 instance->irq = NCR5380_probe_irq(instance, T128_IRQS);
260
261 if (instance->irq != SCSI_IRQ_NONE)
262 if (request_irq(instance->irq, t128_intr, IRQF_DISABLED, "t128",
263 instance)) {
264 printk("scsi%d : IRQ%d not free, interrupts disabled\n",
265 instance->host_no, instance->irq);
266 instance->irq = SCSI_IRQ_NONE;
267 }
268
269 if (instance->irq == SCSI_IRQ_NONE) {
270 printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
271 printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
272 }
273
274#if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
275 printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
276#endif
277
278 printk("scsi%d : at 0x%08lx", instance->host_no, instance->base);
279 if (instance->irq == SCSI_IRQ_NONE)
280 printk (" interrupts disabled");
281 else
282 printk (" irq %d", instance->irq);
283 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
284 CAN_QUEUE, CMD_PER_LUN, T128_PUBLIC_RELEASE);
285 NCR5380_print_options(instance);
286 printk("\n");
287
288 ++current_override;
289 ++count;
290 }
291 return count;
292}
293
294static int t128_release(struct Scsi_Host *shost)
295{
296 NCR5380_local_declare();
297 NCR5380_setup(shost);
298 if (shost->irq)
299 free_irq(shost->irq, shost);
300 NCR5380_exit(shost);
301 if (shost->io_port && shost->n_io_port)
302 release_region(shost->io_port, shost->n_io_port);
303 scsi_unregister(shost);
304 iounmap(base);
305 return 0;
306}
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328int t128_biosparam(struct scsi_device *sdev, struct block_device *bdev,
329 sector_t capacity, int * ip)
330{
331 ip[0] = 64;
332 ip[1] = 32;
333 ip[2] = capacity >> 11;
334 return 0;
335}
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst,
351 int len) {
352 NCR5380_local_declare();
353 void __iomem *reg;
354 unsigned char *d = dst;
355 register int i = len;
356
357 NCR5380_setup(instance);
358 reg = base + T_DATA_REG_OFFSET;
359
360#if 0
361 for (; i; --i) {
362 while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
363#else
364 while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
365 for (; i; --i) {
366#endif
367 *d++ = readb(reg);
368 }
369
370 if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
371 unsigned char tmp;
372 void __iomem *foo = base + T_CONTROL_REG_OFFSET;
373 tmp = readb(foo);
374 writeb(tmp | T_CR_CT, foo);
375 writeb(tmp, foo);
376 printk("scsi%d : watchdog timer fired in NCR5380_pread()\n",
377 instance->host_no);
378 return -1;
379 } else
380 return 0;
381}
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src,
397 int len) {
398 NCR5380_local_declare();
399 void __iomem *reg;
400 unsigned char *s = src;
401 register int i = len;
402
403 NCR5380_setup(instance);
404 reg = base + T_DATA_REG_OFFSET;
405
406#if 0
407 for (; i; --i) {
408 while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
409#else
410 while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
411 for (; i; --i) {
412#endif
413 writeb(*s++, reg);
414 }
415
416 if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
417 unsigned char tmp;
418 void __iomem *foo = base + T_CONTROL_REG_OFFSET;
419 tmp = readb(foo);
420 writeb(tmp | T_CR_CT, foo);
421 writeb(tmp, foo);
422 printk("scsi%d : watchdog timer fired in NCR5380_pwrite()\n",
423 instance->host_no);
424 return -1;
425 } else
426 return 0;
427}
428
429MODULE_LICENSE("GPL");
430
431#include "NCR5380.c"
432
433static struct scsi_host_template driver_template = {
434 .name = "Trantor T128/T128F/T228",
435 .detect = t128_detect,
436 .release = t128_release,
437 .queuecommand = t128_queue_command,
438 .eh_abort_handler = t128_abort,
439 .eh_bus_reset_handler = t128_bus_reset,
440 .bios_param = t128_biosparam,
441 .can_queue = CAN_QUEUE,
442 .this_id = 7,
443 .sg_tablesize = SG_ALL,
444 .cmd_per_lun = CMD_PER_LUN,
445 .use_clustering = DISABLE_CLUSTERING,
446};
447#include "scsi_module.c"
448