1#define PSEUDO_DMA
2
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#include <linux/io.h>
72#include <linux/blkdev.h>
73#include <linux/interrupt.h>
74#include <linux/init.h>
75#include <linux/module.h>
76
77#include <scsi/scsi_host.h>
78#include "t128.h"
79#define AUTOPROBE_IRQ
80#include "NCR5380.h"
81
82static struct override {
83 unsigned long address;
84 int irq;
85} overrides
86#ifdef T128_OVERRIDE
87 [] __initdata = T128_OVERRIDE;
88#else
89 [4] __initdata = {{0, IRQ_AUTO}, {0, IRQ_AUTO},
90 {0 ,IRQ_AUTO}, {0, IRQ_AUTO}};
91#endif
92
93#define NO_OVERRIDES ARRAY_SIZE(overrides)
94
95static struct base {
96 unsigned int address;
97 int noauto;
98} bases[] __initdata = {
99 { 0xcc000, 0}, { 0xc8000, 0}, { 0xdc000, 0}, { 0xd8000, 0}
100};
101
102#define NO_BASES ARRAY_SIZE(bases)
103
104static struct signature {
105 const char *string;
106 int offset;
107} signatures[] __initdata = {
108{"TSROM: SCSI BIOS, Version 1.12", 0x36},
109};
110
111#define NO_SIGNATURES ARRAY_SIZE(signatures)
112
113#ifndef MODULE
114
115
116
117
118
119
120
121
122
123
124static int __init t128_setup(char *str)
125{
126 static int commandline_current;
127 int i;
128 int ints[10];
129
130 get_options(str, ARRAY_SIZE(ints), ints);
131 if (ints[0] != 2)
132 printk("t128_setup : usage t128=address,irq\n");
133 else
134 if (commandline_current < NO_OVERRIDES) {
135 overrides[commandline_current].address = ints[1];
136 overrides[commandline_current].irq = ints[2];
137 for (i = 0; i < NO_BASES; ++i)
138 if (bases[i].address == ints[1]) {
139 bases[i].noauto = 1;
140 break;
141 }
142 ++commandline_current;
143 }
144 return 1;
145}
146
147__setup("t128=", t128_setup);
148#endif
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163static int __init t128_detect(struct scsi_host_template *tpnt)
164{
165 static int current_override, current_base;
166 struct Scsi_Host *instance;
167 unsigned long base;
168 void __iomem *p;
169 int sig, count;
170
171 for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
172 base = 0;
173 p = NULL;
174
175 if (overrides[current_override].address) {
176 base = overrides[current_override].address;
177 p = ioremap(bases[current_base].address, 0x2000);
178 if (!p)
179 base = 0;
180 } else
181 for (; !base && (current_base < NO_BASES); ++current_base) {
182 dprintk(NDEBUG_INIT, "t128: probing address 0x%08x\n",
183 bases[current_base].address);
184 if (bases[current_base].noauto)
185 continue;
186 p = ioremap(bases[current_base].address, 0x2000);
187 if (!p)
188 continue;
189 for (sig = 0; sig < NO_SIGNATURES; ++sig)
190 if (check_signature(p + signatures[sig].offset,
191 signatures[sig].string,
192 strlen(signatures[sig].string))) {
193 base = bases[current_base].address;
194 dprintk(NDEBUG_INIT, "t128: detected board\n");
195 goto found;
196 }
197 iounmap(p);
198 }
199
200 dprintk(NDEBUG_INIT, "t128: base = 0x%08x\n", (unsigned int)base);
201
202 if (!base)
203 break;
204
205found:
206 instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
207 if(instance == NULL)
208 goto out_unmap;
209
210 instance->base = base;
211 ((struct NCR5380_hostdata *)instance->hostdata)->base = p;
212
213 if (NCR5380_init(instance, 0))
214 goto out_unregister;
215
216 NCR5380_maybe_reset_bus(instance);
217
218 if (overrides[current_override].irq != IRQ_AUTO)
219 instance->irq = overrides[current_override].irq;
220 else
221 instance->irq = NCR5380_probe_irq(instance, T128_IRQS);
222
223
224 if (instance->irq == 255)
225 instance->irq = NO_IRQ;
226
227 if (instance->irq != NO_IRQ)
228 if (request_irq(instance->irq, t128_intr, 0, "t128",
229 instance)) {
230 printk("scsi%d : IRQ%d not free, interrupts disabled\n",
231 instance->host_no, instance->irq);
232 instance->irq = NO_IRQ;
233 }
234
235 if (instance->irq == NO_IRQ) {
236 printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
237 printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
238 }
239
240 dprintk(NDEBUG_INIT, "scsi%d: irq = %d\n",
241 instance->host_no, instance->irq);
242
243 ++current_override;
244 ++count;
245 }
246 return count;
247
248out_unregister:
249 scsi_unregister(instance);
250out_unmap:
251 iounmap(p);
252 return count;
253}
254
255static int t128_release(struct Scsi_Host *shost)
256{
257 struct NCR5380_hostdata *hostdata = shost_priv(shost);
258
259 if (shost->irq != NO_IRQ)
260 free_irq(shost->irq, shost);
261 NCR5380_exit(shost);
262 scsi_unregister(shost);
263 iounmap(hostdata->base);
264 return 0;
265}
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287static int t128_biosparam(struct scsi_device *sdev, struct block_device *bdev,
288 sector_t capacity, int *ip)
289{
290 ip[0] = 64;
291 ip[1] = 32;
292 ip[2] = capacity >> 11;
293 return 0;
294}
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309static inline int
310NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst, int len)
311{
312 struct NCR5380_hostdata *hostdata = shost_priv(instance);
313 void __iomem *reg, *base = hostdata->base;
314 unsigned char *d = dst;
315 register int i = len;
316
317 reg = base + T_DATA_REG_OFFSET;
318
319#if 0
320 for (; i; --i) {
321 while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
322#else
323 while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
324 for (; i; --i) {
325#endif
326 *d++ = readb(reg);
327 }
328
329 if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
330 unsigned char tmp;
331 void __iomem *foo = base + T_CONTROL_REG_OFFSET;
332 tmp = readb(foo);
333 writeb(tmp | T_CR_CT, foo);
334 writeb(tmp, foo);
335 printk("scsi%d : watchdog timer fired in NCR5380_pread()\n",
336 instance->host_no);
337 return -1;
338 } else
339 return 0;
340}
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355static inline int
356NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src, int len)
357{
358 struct NCR5380_hostdata *hostdata = shost_priv(instance);
359 void __iomem *reg, *base = hostdata->base;
360 unsigned char *s = src;
361 register int i = len;
362
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 writeb(*s++, 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_pwrite()\n",
382 instance->host_no);
383 return -1;
384 } else
385 return 0;
386}
387
388MODULE_LICENSE("GPL");
389
390#include "NCR5380.c"
391
392static struct scsi_host_template driver_template = {
393 .name = "Trantor T128/T128F/T228",
394 .detect = t128_detect,
395 .release = t128_release,
396 .proc_name = "t128",
397 .show_info = t128_show_info,
398 .write_info = t128_write_info,
399 .info = t128_info,
400 .queuecommand = t128_queue_command,
401 .eh_abort_handler = t128_abort,
402 .eh_bus_reset_handler = t128_bus_reset,
403 .bios_param = t128_biosparam,
404 .can_queue = 32,
405 .this_id = 7,
406 .sg_tablesize = SG_ALL,
407 .cmd_per_lun = 2,
408 .use_clustering = DISABLE_CLUSTERING,
409 .cmd_size = NCR5380_CMD_SIZE,
410 .max_sectors = 128,
411};
412#include "scsi_module.c"
413