Commit | Line | Data |
---|---|---|
1da177e4 | 1 | |
1da177e4 LT |
2 | #define PSEUDO_DMA |
3 | #define DONT_USE_INTR | |
4 | #define UNSAFE /* Leave interrupts enabled during pseudo-dma I/O */ | |
1da177e4 LT |
5 | #define DMA_WORKS_RIGHT |
6 | ||
7 | ||
8 | /* | |
9 | * DTC 3180/3280 driver, by | |
10 | * Ray Van Tassle rayvt@comm.mot.com | |
11 | * | |
12 | * taken from ... | |
13 | * Trantor T128/T128F/T228 driver by... | |
14 | * | |
15 | * Drew Eckhardt | |
16 | * Visionary Computing | |
17 | * (Unix and Linux consulting and custom programming) | |
18 | * drew@colorado.edu | |
19 | * +1 (303) 440-4894 | |
20 | * | |
21 | * DISTRIBUTION RELEASE 1. | |
3f9e986e | 22 | */ |
1da177e4 LT |
23 | |
24 | /* | |
1da177e4 LT |
25 | * The card is detected and initialized in one of several ways : |
26 | * 1. Autoprobe (default) - since the board is memory mapped, | |
27 | * a BIOS signature is scanned for to locate the registers. | |
28 | * An interrupt is triggered to autoprobe for the interrupt | |
29 | * line. | |
30 | * | |
31 | * 2. With command line overrides - dtc=address,irq may be | |
32 | * used on the LILO command line to override the defaults. | |
33 | * | |
34 | */ | |
35 | ||
36 | /*----------------------------------------------------------------*/ | |
37 | /* the following will set the monitor border color (useful to find | |
38 | where something crashed or gets stuck at */ | |
39 | /* 1 = blue | |
40 | 2 = green | |
41 | 3 = cyan | |
42 | 4 = red | |
43 | 5 = magenta | |
44 | 6 = yellow | |
45 | 7 = white | |
46 | */ | |
47 | #if 0 | |
48 | #define rtrc(i) {inb(0x3da); outb(0x31, 0x3c0); outb((i), 0x3c0);} | |
49 | #else | |
50 | #define rtrc(i) {} | |
51 | #endif | |
52 | ||
53 | ||
1da177e4 LT |
54 | #include <linux/module.h> |
55 | #include <linux/signal.h> | |
1da177e4 LT |
56 | #include <linux/blkdev.h> |
57 | #include <linux/delay.h> | |
58 | #include <linux/stat.h> | |
59 | #include <linux/string.h> | |
60 | #include <linux/init.h> | |
61 | #include <linux/interrupt.h> | |
53d5ed62 | 62 | #include <linux/io.h> |
1da177e4 LT |
63 | #include "scsi.h" |
64 | #include <scsi/scsi_host.h> | |
65 | #include "dtc.h" | |
66 | #define AUTOPROBE_IRQ | |
67 | #include "NCR5380.h" | |
68 | ||
69 | ||
70 | #define DTC_PUBLIC_RELEASE 2 | |
71 | ||
1da177e4 LT |
72 | /* |
73 | * The DTC3180 & 3280 boards are memory mapped. | |
74 | * | |
75 | */ | |
76 | ||
77 | /* | |
78 | */ | |
79 | /* Offset from DTC_5380_OFFSET */ | |
80 | #define DTC_CONTROL_REG 0x100 /* rw */ | |
81 | #define D_CR_ACCESS 0x80 /* ro set=can access 3280 registers */ | |
82 | #define CSR_DIR_READ 0x40 /* rw direction, 1 = read 0 = write */ | |
83 | ||
84 | #define CSR_RESET 0x80 /* wo Resets 53c400 */ | |
85 | #define CSR_5380_REG 0x80 /* ro 5380 registers can be accessed */ | |
86 | #define CSR_TRANS_DIR 0x40 /* rw Data transfer direction */ | |
87 | #define CSR_SCSI_BUFF_INTR 0x20 /* rw Enable int on transfer ready */ | |
88 | #define CSR_5380_INTR 0x10 /* rw Enable 5380 interrupts */ | |
89 | #define CSR_SHARED_INTR 0x08 /* rw Interrupt sharing */ | |
90 | #define CSR_HOST_BUF_NOT_RDY 0x04 /* ro Host buffer not ready */ | |
91 | #define CSR_SCSI_BUF_RDY 0x02 /* ro SCSI buffer ready */ | |
92 | #define CSR_GATED_5380_IRQ 0x01 /* ro Last block xferred */ | |
93 | #define CSR_INT_BASE (CSR_SCSI_BUFF_INTR | CSR_5380_INTR) | |
94 | ||
95 | ||
96 | #define DTC_BLK_CNT 0x101 /* rw | |
97 | * # of 128-byte blocks to transfer */ | |
98 | ||
99 | ||
100 | #define D_CR_ACCESS 0x80 /* ro set=can access 3280 registers */ | |
101 | ||
102 | #define DTC_SWITCH_REG 0x3982 /* ro - DIP switches */ | |
103 | #define DTC_RESUME_XFER 0x3982 /* wo - resume data xfer | |
104 | * after disconnect/reconnect*/ | |
105 | ||
106 | #define DTC_5380_OFFSET 0x3880 /* 8 registers here, see NCR5380.h */ | |
107 | ||
108 | /*!!!! for dtc, it's a 128 byte buffer at 3900 !!! */ | |
109 | #define DTC_DATA_BUF 0x3900 /* rw 128 bytes long */ | |
110 | ||
111 | static struct override { | |
112 | unsigned int address; | |
113 | int irq; | |
114 | } overrides | |
115 | #ifdef OVERRIDE | |
116 | [] __initdata = OVERRIDE; | |
117 | #else | |
1fbe8529 AC |
118 | [4] __initdata = { |
119 | { 0, IRQ_AUTO }, { 0, IRQ_AUTO }, { 0, IRQ_AUTO }, { 0, IRQ_AUTO } | |
120 | }; | |
1da177e4 LT |
121 | #endif |
122 | ||
6391a113 | 123 | #define NO_OVERRIDES ARRAY_SIZE(overrides) |
1da177e4 LT |
124 | |
125 | static struct base { | |
126 | unsigned long address; | |
127 | int noauto; | |
6391a113 TK |
128 | } bases[] __initdata = { |
129 | { 0xcc000, 0 }, | |
130 | { 0xc8000, 0 }, | |
131 | { 0xdc000, 0 }, | |
1da177e4 LT |
132 | { 0xd8000, 0 } |
133 | }; | |
134 | ||
6391a113 | 135 | #define NO_BASES ARRAY_SIZE(bases) |
1da177e4 LT |
136 | |
137 | static const struct signature { | |
138 | const char *string; | |
139 | int offset; | |
6391a113 | 140 | } signatures[] = { |
1da177e4 LT |
141 | {"DATA TECHNOLOGY CORPORATION BIOS", 0x25}, |
142 | }; | |
143 | ||
6391a113 | 144 | #define NO_SIGNATURES ARRAY_SIZE(signatures) |
1da177e4 LT |
145 | |
146 | #ifndef MODULE | |
147 | /* | |
148 | * Function : dtc_setup(char *str, int *ints) | |
149 | * | |
150 | * Purpose : LILO command line initialization of the overrides array, | |
6391a113 | 151 | * |
1da177e4 LT |
152 | * Inputs : str - unused, ints - array of integer parameters with ints[0] |
153 | * equal to the number of ints. | |
154 | * | |
1fbe8529 | 155 | */ |
1da177e4 | 156 | |
925e4610 | 157 | static int __init dtc_setup(char *str) |
1da177e4 LT |
158 | { |
159 | static int commandline_current = 0; | |
160 | int i; | |
925e4610 FT |
161 | int ints[10]; |
162 | ||
163 | get_options(str, ARRAY_SIZE(ints), ints); | |
1da177e4 LT |
164 | if (ints[0] != 2) |
165 | printk("dtc_setup: usage dtc=address,irq\n"); | |
166 | else if (commandline_current < NO_OVERRIDES) { | |
167 | overrides[commandline_current].address = ints[1]; | |
168 | overrides[commandline_current].irq = ints[2]; | |
169 | for (i = 0; i < NO_BASES; ++i) | |
170 | if (bases[i].address == ints[1]) { | |
171 | bases[i].noauto = 1; | |
172 | break; | |
173 | } | |
174 | ++commandline_current; | |
175 | } | |
925e4610 | 176 | return 1; |
1da177e4 | 177 | } |
925e4610 FT |
178 | |
179 | __setup("dtc=", dtc_setup); | |
1da177e4 LT |
180 | #endif |
181 | ||
182 | /* | |
d0be4a7d | 183 | * Function : int dtc_detect(struct scsi_host_template * tpnt) |
1da177e4 LT |
184 | * |
185 | * Purpose : detects and initializes DTC 3180/3280 controllers | |
186 | * that were autoprobed, overridden on the LILO command line, | |
187 | * or specified at compile time. | |
188 | * | |
189 | * Inputs : tpnt - template for this SCSI adapter. | |
190 | * | |
191 | * Returns : 1 if a host adapter was found, 0 if not. | |
192 | * | |
193 | */ | |
194 | ||
d0be4a7d | 195 | static int __init dtc_detect(struct scsi_host_template * tpnt) |
1da177e4 LT |
196 | { |
197 | static int current_override = 0, current_base = 0; | |
198 | struct Scsi_Host *instance; | |
199 | unsigned int addr; | |
200 | void __iomem *base; | |
201 | int sig, count; | |
202 | ||
1da177e4 LT |
203 | for (count = 0; current_override < NO_OVERRIDES; ++current_override) { |
204 | addr = 0; | |
205 | base = NULL; | |
206 | ||
207 | if (overrides[current_override].address) { | |
208 | addr = overrides[current_override].address; | |
209 | base = ioremap(addr, 0x2000); | |
210 | if (!base) | |
211 | addr = 0; | |
212 | } else | |
213 | for (; !addr && (current_base < NO_BASES); ++current_base) { | |
214 | #if (DTCDEBUG & DTCDEBUG_INIT) | |
1fbe8529 | 215 | printk(KERN_DEBUG "scsi-dtc : probing address %08x\n", bases[current_base].address); |
1da177e4 LT |
216 | #endif |
217 | if (bases[current_base].noauto) | |
218 | continue; | |
219 | base = ioremap(bases[current_base].address, 0x2000); | |
220 | if (!base) | |
221 | continue; | |
222 | for (sig = 0; sig < NO_SIGNATURES; ++sig) { | |
223 | if (check_signature(base + signatures[sig].offset, signatures[sig].string, strlen(signatures[sig].string))) { | |
224 | addr = bases[current_base].address; | |
225 | #if (DTCDEBUG & DTCDEBUG_INIT) | |
5307b1e8 | 226 | printk(KERN_DEBUG "scsi-dtc : detected board.\n"); |
1da177e4 LT |
227 | #endif |
228 | goto found; | |
229 | } | |
230 | } | |
231 | iounmap(base); | |
232 | } | |
233 | ||
234 | #if defined(DTCDEBUG) && (DTCDEBUG & DTCDEBUG_INIT) | |
1fbe8529 | 235 | printk(KERN_DEBUG "scsi-dtc : base = %08x\n", addr); |
1da177e4 LT |
236 | #endif |
237 | ||
238 | if (!addr) | |
239 | break; | |
240 | ||
241 | found: | |
242 | instance = scsi_register(tpnt, sizeof(struct NCR5380_hostdata)); | |
243 | if (instance == NULL) | |
244 | break; | |
245 | ||
246 | instance->base = addr; | |
247 | ((struct NCR5380_hostdata *)(instance)->hostdata)->base = base; | |
248 | ||
249 | NCR5380_init(instance, 0); | |
250 | ||
251 | NCR5380_write(DTC_CONTROL_REG, CSR_5380_INTR); /* Enable int's */ | |
252 | if (overrides[current_override].irq != IRQ_AUTO) | |
253 | instance->irq = overrides[current_override].irq; | |
254 | else | |
255 | instance->irq = NCR5380_probe_irq(instance, DTC_IRQS); | |
256 | ||
22f5f10d FT |
257 | /* Compatibility with documented NCR5380 kernel parameters */ |
258 | if (instance->irq == 255) | |
259 | instance->irq = NO_IRQ; | |
260 | ||
1da177e4 LT |
261 | #ifndef DONT_USE_INTR |
262 | /* With interrupts enabled, it will sometimes hang when doing heavy | |
263 | * reads. So better not enable them until I finger it out. */ | |
22f5f10d | 264 | if (instance->irq != NO_IRQ) |
4909cc2b | 265 | if (request_irq(instance->irq, dtc_intr, 0, |
1e641664 | 266 | "dtc", instance)) { |
1da177e4 | 267 | printk(KERN_ERR "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq); |
22f5f10d | 268 | instance->irq = NO_IRQ; |
1da177e4 LT |
269 | } |
270 | ||
22f5f10d | 271 | if (instance->irq == NO_IRQ) { |
1da177e4 LT |
272 | printk(KERN_WARNING "scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no); |
273 | printk(KERN_WARNING "scsi%d : please jumper the board for a free IRQ.\n", instance->host_no); | |
274 | } | |
275 | #else | |
22f5f10d | 276 | if (instance->irq != NO_IRQ) |
1da177e4 | 277 | printk(KERN_WARNING "scsi%d : interrupts not used. Might as well not jumper it.\n", instance->host_no); |
22f5f10d | 278 | instance->irq = NO_IRQ; |
1da177e4 LT |
279 | #endif |
280 | #if defined(DTCDEBUG) && (DTCDEBUG & DTCDEBUG_INIT) | |
281 | printk("scsi%d : irq = %d\n", instance->host_no, instance->irq); | |
282 | #endif | |
283 | ||
1da177e4 LT |
284 | ++current_override; |
285 | ++count; | |
286 | } | |
287 | return count; | |
288 | } | |
289 | ||
290 | /* | |
291 | * Function : int dtc_biosparam(Disk * disk, struct block_device *dev, int *ip) | |
292 | * | |
293 | * Purpose : Generates a BIOS / DOS compatible H-C-S mapping for | |
294 | * the specified device / size. | |
295 | * | |
296 | * Inputs : size = size of device in sectors (512 bytes), dev = block device | |
297 | * major / minor, ip[] = {heads, sectors, cylinders} | |
298 | * | |
299 | * Returns : always 0 (success), initializes ip | |
300 | * | |
301 | */ | |
302 | ||
303 | /* | |
304 | * XXX Most SCSI boards use this mapping, I could be incorrect. Some one | |
305 | * using hard disks on a trantor should verify that this mapping corresponds | |
306 | * to that used by the BIOS / ASPI driver by running the linux fdisk program | |
307 | * and matching the H_C_S coordinates to what DOS uses. | |
308 | */ | |
309 | ||
310 | static int dtc_biosparam(struct scsi_device *sdev, struct block_device *dev, | |
311 | sector_t capacity, int *ip) | |
312 | { | |
313 | int size = capacity; | |
314 | ||
315 | ip[0] = 64; | |
316 | ip[1] = 32; | |
317 | ip[2] = size >> 11; | |
318 | return 0; | |
319 | } | |
320 | ||
321 | ||
322 | /**************************************************************** | |
323 | * Function : int NCR5380_pread (struct Scsi_Host *instance, | |
324 | * unsigned char *dst, int len) | |
325 | * | |
326 | * Purpose : Fast 5380 pseudo-dma read function, reads len bytes to | |
327 | * dst | |
328 | * | |
329 | * Inputs : dst = destination, len = length in bytes | |
330 | * | |
331 | * Returns : 0 on success, non zero on a failure such as a watchdog | |
332 | * timeout. | |
333 | */ | |
334 | ||
1da177e4 LT |
335 | static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst, int len) |
336 | { | |
337 | unsigned char *d = dst; | |
338 | int i; /* For counting time spent in the poll-loop */ | |
a9c2dc43 | 339 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
1da177e4 LT |
340 | NCR5380_local_declare(); |
341 | NCR5380_setup(instance); | |
342 | ||
343 | i = 0; | |
344 | NCR5380_read(RESET_PARITY_INTERRUPT_REG); | |
345 | NCR5380_write(MODE_REG, MR_ENABLE_EOP_INTR | MR_DMA_MODE); | |
22f5f10d | 346 | if (instance->irq == NO_IRQ) |
1da177e4 LT |
347 | NCR5380_write(DTC_CONTROL_REG, CSR_DIR_READ); |
348 | else | |
349 | NCR5380_write(DTC_CONTROL_REG, CSR_DIR_READ | CSR_INT_BASE); | |
350 | NCR5380_write(DTC_BLK_CNT, len >> 7); /* Block count */ | |
351 | rtrc(1); | |
352 | while (len > 0) { | |
353 | rtrc(2); | |
354 | while (NCR5380_read(DTC_CONTROL_REG) & CSR_HOST_BUF_NOT_RDY) | |
355 | ++i; | |
356 | rtrc(3); | |
357 | memcpy_fromio(d, base + DTC_DATA_BUF, 128); | |
358 | d += 128; | |
359 | len -= 128; | |
360 | rtrc(7); | |
361 | /*** with int's on, it sometimes hangs after here. | |
362 | * Looks like something makes HBNR go away. */ | |
363 | } | |
364 | rtrc(4); | |
365 | while (!(NCR5380_read(DTC_CONTROL_REG) & D_CR_ACCESS)) | |
366 | ++i; | |
367 | NCR5380_write(MODE_REG, 0); /* Clear the operating mode */ | |
368 | rtrc(0); | |
369 | NCR5380_read(RESET_PARITY_INTERRUPT_REG); | |
a9c2dc43 FT |
370 | if (i > hostdata->spin_max_r) |
371 | hostdata->spin_max_r = i; | |
1da177e4 LT |
372 | return (0); |
373 | } | |
374 | ||
375 | /**************************************************************** | |
376 | * Function : int NCR5380_pwrite (struct Scsi_Host *instance, | |
377 | * unsigned char *src, int len) | |
378 | * | |
379 | * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from | |
380 | * src | |
381 | * | |
382 | * Inputs : src = source, len = length in bytes | |
383 | * | |
384 | * Returns : 0 on success, non zero on a failure such as a watchdog | |
385 | * timeout. | |
386 | */ | |
387 | ||
388 | static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src, int len) | |
389 | { | |
390 | int i; | |
a9c2dc43 | 391 | struct NCR5380_hostdata *hostdata = shost_priv(instance); |
1da177e4 LT |
392 | NCR5380_local_declare(); |
393 | NCR5380_setup(instance); | |
394 | ||
395 | NCR5380_read(RESET_PARITY_INTERRUPT_REG); | |
396 | NCR5380_write(MODE_REG, MR_ENABLE_EOP_INTR | MR_DMA_MODE); | |
397 | /* set direction (write) */ | |
22f5f10d | 398 | if (instance->irq == NO_IRQ) |
1da177e4 LT |
399 | NCR5380_write(DTC_CONTROL_REG, 0); |
400 | else | |
401 | NCR5380_write(DTC_CONTROL_REG, CSR_5380_INTR); | |
402 | NCR5380_write(DTC_BLK_CNT, len >> 7); /* Block count */ | |
403 | for (i = 0; len > 0; ++i) { | |
404 | rtrc(5); | |
405 | /* Poll until the host buffer can accept data. */ | |
406 | while (NCR5380_read(DTC_CONTROL_REG) & CSR_HOST_BUF_NOT_RDY) | |
407 | ++i; | |
408 | rtrc(3); | |
409 | memcpy_toio(base + DTC_DATA_BUF, src, 128); | |
410 | src += 128; | |
411 | len -= 128; | |
412 | } | |
413 | rtrc(4); | |
414 | while (!(NCR5380_read(DTC_CONTROL_REG) & D_CR_ACCESS)) | |
415 | ++i; | |
416 | rtrc(6); | |
417 | /* Wait until the last byte has been sent to the disk */ | |
418 | while (!(NCR5380_read(TARGET_COMMAND_REG) & TCR_LAST_BYTE_SENT)) | |
419 | ++i; | |
420 | rtrc(7); | |
421 | /* Check for parity error here. fixme. */ | |
422 | NCR5380_write(MODE_REG, 0); /* Clear the operating mode */ | |
423 | rtrc(0); | |
a9c2dc43 FT |
424 | if (i > hostdata->spin_max_w) |
425 | hostdata->spin_max_w = i; | |
1da177e4 LT |
426 | return (0); |
427 | } | |
428 | ||
429 | MODULE_LICENSE("GPL"); | |
430 | ||
431 | #include "NCR5380.c" | |
432 | ||
433 | static int dtc_release(struct Scsi_Host *shost) | |
434 | { | |
435 | NCR5380_local_declare(); | |
436 | NCR5380_setup(shost); | |
22f5f10d | 437 | if (shost->irq != NO_IRQ) |
1e641664 | 438 | free_irq(shost->irq, shost); |
1da177e4 LT |
439 | NCR5380_exit(shost); |
440 | if (shost->io_port && shost->n_io_port) | |
441 | release_region(shost->io_port, shost->n_io_port); | |
442 | scsi_unregister(shost); | |
443 | iounmap(base); | |
444 | return 0; | |
445 | } | |
446 | ||
d0be4a7d | 447 | static struct scsi_host_template driver_template = { |
1da177e4 LT |
448 | .name = "DTC 3180/3280 ", |
449 | .detect = dtc_detect, | |
450 | .release = dtc_release, | |
4d3d2a54 FT |
451 | .proc_name = "dtc3x80", |
452 | .show_info = dtc_show_info, | |
453 | .write_info = dtc_write_info, | |
8c32513b | 454 | .info = dtc_info, |
1da177e4 LT |
455 | .queuecommand = dtc_queue_command, |
456 | .eh_abort_handler = dtc_abort, | |
457 | .eh_bus_reset_handler = dtc_bus_reset, | |
1da177e4 LT |
458 | .bios_param = dtc_biosparam, |
459 | .can_queue = CAN_QUEUE, | |
460 | .this_id = 7, | |
461 | .sg_tablesize = SG_ALL, | |
462 | .cmd_per_lun = CMD_PER_LUN, | |
463 | .use_clustering = DISABLE_CLUSTERING, | |
464 | }; | |
465 | #include "scsi_module.c" |