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#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
120static 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
133static 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
142static 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
152
153
154
155
156
157
158
159
160
161void __init t128_setup(char *str, int *ints){
162 static int commandline_current = 0;
163 int i;
164 if (ints[0] != 2)
165 printk("t128_setup : usage t128=address,irq\n");
166 else
167 if (commandline_current < NO_OVERRIDES) {
168 overrides[commandline_current].address = ints[1];
169 overrides[commandline_current].irq = ints[2];
170 for (i = 0; i < NO_BASES; ++i)
171 if (bases[i].address == ints[1]) {
172 bases[i].noauto = 1;
173 break;
174 }
175 ++commandline_current;
176 }
177}
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192int __init t128_detect(struct scsi_host_template * tpnt){
193 static int current_override = 0, current_base = 0;
194 struct Scsi_Host *instance;
195 unsigned long base;
196 void __iomem *p;
197 int sig, count;
198
199 tpnt->proc_name = "t128";
200 tpnt->show_info = t128_show_info;
201 tpnt->write_info = t128_write_info;
202
203 for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
204 base = 0;
205 p = NULL;
206
207 if (overrides[current_override].address) {
208 base = overrides[current_override].address;
209 p = ioremap(bases[current_base].address, 0x2000);
210 if (!p)
211 base = 0;
212 } else
213 for (; !base && (current_base < NO_BASES); ++current_base) {
214#if (TDEBUG & TDEBUG_INIT)
215 printk("scsi-t128 : probing address %08x\n", bases[current_base].address);
216#endif
217 if (bases[current_base].noauto)
218 continue;
219 p = ioremap(bases[current_base].address, 0x2000);
220 if (!p)
221 continue;
222 for (sig = 0; sig < NO_SIGNATURES; ++sig)
223 if (check_signature(p + signatures[sig].offset,
224 signatures[sig].string,
225 strlen(signatures[sig].string))) {
226 base = bases[current_base].address;
227#if (TDEBUG & TDEBUG_INIT)
228 printk("scsi-t128 : detected board.\n");
229#endif
230 goto found;
231 }
232 iounmap(p);
233 }
234
235#if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
236 printk("scsi-t128 : base = %08x\n", (unsigned int) base);
237#endif
238
239 if (!base)
240 break;
241
242found:
243 instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
244 if(instance == NULL)
245 break;
246
247 instance->base = base;
248 ((struct NCR5380_hostdata *)instance->hostdata)->base = p;
249
250 NCR5380_init(instance, 0);
251
252 if (overrides[current_override].irq != IRQ_AUTO)
253 instance->irq = overrides[current_override].irq;
254 else
255 instance->irq = NCR5380_probe_irq(instance, T128_IRQS);
256
257 if (instance->irq != SCSI_IRQ_NONE)
258 if (request_irq(instance->irq, t128_intr, 0, "t128",
259 instance)) {
260 printk("scsi%d : IRQ%d not free, interrupts disabled\n",
261 instance->host_no, instance->irq);
262 instance->irq = SCSI_IRQ_NONE;
263 }
264
265 if (instance->irq == SCSI_IRQ_NONE) {
266 printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
267 printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
268 }
269
270#if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
271 printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
272#endif
273
274 printk("scsi%d : at 0x%08lx", instance->host_no, instance->base);
275 if (instance->irq == SCSI_IRQ_NONE)
276 printk (" interrupts disabled");
277 else
278 printk (" irq %d", instance->irq);
279 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
280 CAN_QUEUE, CMD_PER_LUN, T128_PUBLIC_RELEASE);
281 NCR5380_print_options(instance);
282 printk("\n");
283
284 ++current_override;
285 ++count;
286 }
287 return count;
288}
289
290static int t128_release(struct Scsi_Host *shost)
291{
292 NCR5380_local_declare();
293 NCR5380_setup(shost);
294 if (shost->irq)
295 free_irq(shost->irq, shost);
296 NCR5380_exit(shost);
297 if (shost->io_port && shost->n_io_port)
298 release_region(shost->io_port, shost->n_io_port);
299 scsi_unregister(shost);
300 iounmap(base);
301 return 0;
302}
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324int t128_biosparam(struct scsi_device *sdev, struct block_device *bdev,
325 sector_t capacity, int * ip)
326{
327 ip[0] = 64;
328 ip[1] = 32;
329 ip[2] = capacity >> 11;
330 return 0;
331}
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst,
347 int len) {
348 NCR5380_local_declare();
349 void __iomem *reg;
350 unsigned char *d = dst;
351 register int i = len;
352
353 NCR5380_setup(instance);
354 reg = base + T_DATA_REG_OFFSET;
355
356#if 0
357 for (; i; --i) {
358 while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
359#else
360 while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
361 for (; i; --i) {
362#endif
363 *d++ = readb(reg);
364 }
365
366 if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
367 unsigned char tmp;
368 void __iomem *foo = base + T_CONTROL_REG_OFFSET;
369 tmp = readb(foo);
370 writeb(tmp | T_CR_CT, foo);
371 writeb(tmp, foo);
372 printk("scsi%d : watchdog timer fired in NCR5380_pread()\n",
373 instance->host_no);
374 return -1;
375 } else
376 return 0;
377}
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src,
393 int len) {
394 NCR5380_local_declare();
395 void __iomem *reg;
396 unsigned char *s = src;
397 register int i = len;
398
399 NCR5380_setup(instance);
400 reg = base + T_DATA_REG_OFFSET;
401
402#if 0
403 for (; i; --i) {
404 while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
405#else
406 while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
407 for (; i; --i) {
408#endif
409 writeb(*s++, reg);
410 }
411
412 if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
413 unsigned char tmp;
414 void __iomem *foo = base + T_CONTROL_REG_OFFSET;
415 tmp = readb(foo);
416 writeb(tmp | T_CR_CT, foo);
417 writeb(tmp, foo);
418 printk("scsi%d : watchdog timer fired in NCR5380_pwrite()\n",
419 instance->host_no);
420 return -1;
421 } else
422 return 0;
423}
424
425MODULE_LICENSE("GPL");
426
427#include "NCR5380.c"
428
429static struct scsi_host_template driver_template = {
430 .name = "Trantor T128/T128F/T228",
431 .detect = t128_detect,
432 .release = t128_release,
433 .queuecommand = t128_queue_command,
434 .eh_abort_handler = t128_abort,
435 .eh_bus_reset_handler = t128_bus_reset,
436 .bios_param = t128_biosparam,
437 .can_queue = CAN_QUEUE,
438 .this_id = 7,
439 .sg_tablesize = SG_ALL,
440 .cmd_per_lun = CMD_PER_LUN,
441 .use_clustering = DISABLE_CLUSTERING,
442};
443#include "scsi_module.c"
444