blob: 43be785778d97754b625d293fe82a027939d3ca1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
Linus Torvalds1da177e2005-04-16 15:20:36 -07002#define PSEUDO_DMA
3#define DONT_USE_INTR
4#define UNSAFE /* Leave interrupts enabled during pseudo-dma I/O */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005#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.
Finn Thain3f9e9862014-11-12 16:11:55 +110022 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070025 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include <linux/module.h>
55#include <linux/signal.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#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>
Matthew Wilcox53d5ed62006-10-11 01:22:01 -070062#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070063#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
Linus Torvalds1da177e2005-04-16 15:20:36 -070072/*
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
111static struct override {
112 unsigned int address;
113 int irq;
114} overrides
115#ifdef OVERRIDE
116[] __initdata = OVERRIDE;
117#else
Alan Cox1fbe8522007-08-10 14:50:41 -0700118[4] __initdata = {
119 { 0, IRQ_AUTO }, { 0, IRQ_AUTO }, { 0, IRQ_AUTO }, { 0, IRQ_AUTO }
120};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121#endif
122
Tobias Klauser6391a112006-06-08 22:23:48 -0700123#define NO_OVERRIDES ARRAY_SIZE(overrides)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
125static struct base {
126 unsigned long address;
127 int noauto;
Tobias Klauser6391a112006-06-08 22:23:48 -0700128} bases[] __initdata = {
129 { 0xcc000, 0 },
130 { 0xc8000, 0 },
131 { 0xdc000, 0 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 { 0xd8000, 0 }
133};
134
Tobias Klauser6391a112006-06-08 22:23:48 -0700135#define NO_BASES ARRAY_SIZE(bases)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137static const struct signature {
138 const char *string;
139 int offset;
Tobias Klauser6391a112006-06-08 22:23:48 -0700140} signatures[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 {"DATA TECHNOLOGY CORPORATION BIOS", 0x25},
142};
143
Tobias Klauser6391a112006-06-08 22:23:48 -0700144#define NO_SIGNATURES ARRAY_SIZE(signatures)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146#ifndef MODULE
147/*
148 * Function : dtc_setup(char *str, int *ints)
149 *
150 * Purpose : LILO command line initialization of the overrides array,
Tobias Klauser6391a112006-06-08 22:23:48 -0700151 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 * Inputs : str - unused, ints - array of integer parameters with ints[0]
153 * equal to the number of ints.
154 *
Alan Cox1fbe8522007-08-10 14:50:41 -0700155 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Finn Thain925e4612014-11-12 16:11:49 +1100157static int __init dtc_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
159 static int commandline_current = 0;
160 int i;
Finn Thain925e4612014-11-12 16:11:49 +1100161 int ints[10];
162
163 get_options(str, ARRAY_SIZE(ints), ints);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 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 }
Finn Thain925e4612014-11-12 16:11:49 +1100176 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177}
Finn Thain925e4612014-11-12 16:11:49 +1100178
179__setup("dtc=", dtc_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180#endif
181
182/*
Christoph Hellwigd0be4a7d2005-10-31 18:31:40 +0100183 * Function : int dtc_detect(struct scsi_host_template * tpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 *
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
Christoph Hellwigd0be4a7d2005-10-31 18:31:40 +0100195static int __init dtc_detect(struct scsi_host_template * tpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 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)
Alan Cox1fbe8522007-08-10 14:50:41 -0700215 printk(KERN_DEBUG "scsi-dtc : probing address %08x\n", bases[current_base].address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216#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)
Alan Cox5307b1e2007-09-20 15:12:11 +0100226 printk(KERN_DEBUG "scsi-dtc : detected board.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227#endif
228 goto found;
229 }
230 }
231 iounmap(base);
232 }
233
234#if defined(DTCDEBUG) && (DTCDEBUG & DTCDEBUG_INIT)
Alan Cox1fbe8522007-08-10 14:50:41 -0700235 printk(KERN_DEBUG "scsi-dtc : base = %08x\n", addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236#endif
237
238 if (!addr)
239 break;
240
241found:
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
257#ifndef DONT_USE_INTR
258 /* With interrupts enabled, it will sometimes hang when doing heavy
259 * reads. So better not enable them until I finger it out. */
260 if (instance->irq != SCSI_IRQ_NONE)
Michael Opdenacker4909cc22014-03-05 06:09:41 +0100261 if (request_irq(instance->irq, dtc_intr, 0,
Jeff Garzik1e641662007-11-11 19:52:05 -0500262 "dtc", instance)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 printk(KERN_ERR "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq);
264 instance->irq = SCSI_IRQ_NONE;
265 }
266
267 if (instance->irq == SCSI_IRQ_NONE) {
268 printk(KERN_WARNING "scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
269 printk(KERN_WARNING "scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
270 }
271#else
272 if (instance->irq != SCSI_IRQ_NONE)
273 printk(KERN_WARNING "scsi%d : interrupts not used. Might as well not jumper it.\n", instance->host_no);
274 instance->irq = SCSI_IRQ_NONE;
275#endif
276#if defined(DTCDEBUG) && (DTCDEBUG & DTCDEBUG_INIT)
277 printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
278#endif
279
280 printk(KERN_INFO "scsi%d : at 0x%05X", instance->host_no, (int) instance->base);
281 if (instance->irq == SCSI_IRQ_NONE)
282 printk(" interrupts disabled");
283 else
284 printk(" irq %d", instance->irq);
285 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d", CAN_QUEUE, CMD_PER_LUN, DTC_PUBLIC_RELEASE);
286 NCR5380_print_options(instance);
287 printk("\n");
288
289 ++current_override;
290 ++count;
291 }
292 return count;
293}
294
295/*
296 * Function : int dtc_biosparam(Disk * disk, struct block_device *dev, int *ip)
297 *
298 * Purpose : Generates a BIOS / DOS compatible H-C-S mapping for
299 * the specified device / size.
300 *
301 * Inputs : size = size of device in sectors (512 bytes), dev = block device
302 * major / minor, ip[] = {heads, sectors, cylinders}
303 *
304 * Returns : always 0 (success), initializes ip
305 *
306*/
307
308/*
309 * XXX Most SCSI boards use this mapping, I could be incorrect. Some one
310 * using hard disks on a trantor should verify that this mapping corresponds
311 * to that used by the BIOS / ASPI driver by running the linux fdisk program
312 * and matching the H_C_S coordinates to what DOS uses.
313*/
314
315static int dtc_biosparam(struct scsi_device *sdev, struct block_device *dev,
316 sector_t capacity, int *ip)
317{
318 int size = capacity;
319
320 ip[0] = 64;
321 ip[1] = 32;
322 ip[2] = size >> 11;
323 return 0;
324}
325
326
327/****************************************************************
328 * Function : int NCR5380_pread (struct Scsi_Host *instance,
329 * unsigned char *dst, int len)
330 *
331 * Purpose : Fast 5380 pseudo-dma read function, reads len bytes to
332 * dst
333 *
334 * Inputs : dst = destination, len = length in bytes
335 *
336 * Returns : 0 on success, non zero on a failure such as a watchdog
337 * timeout.
338*/
339
340static int dtc_maxi = 0;
341static int dtc_wmaxi = 0;
342
343static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst, int len)
344{
345 unsigned char *d = dst;
346 int i; /* For counting time spent in the poll-loop */
347 NCR5380_local_declare();
348 NCR5380_setup(instance);
349
350 i = 0;
351 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
352 NCR5380_write(MODE_REG, MR_ENABLE_EOP_INTR | MR_DMA_MODE);
353 if (instance->irq == SCSI_IRQ_NONE)
354 NCR5380_write(DTC_CONTROL_REG, CSR_DIR_READ);
355 else
356 NCR5380_write(DTC_CONTROL_REG, CSR_DIR_READ | CSR_INT_BASE);
357 NCR5380_write(DTC_BLK_CNT, len >> 7); /* Block count */
358 rtrc(1);
359 while (len > 0) {
360 rtrc(2);
361 while (NCR5380_read(DTC_CONTROL_REG) & CSR_HOST_BUF_NOT_RDY)
362 ++i;
363 rtrc(3);
364 memcpy_fromio(d, base + DTC_DATA_BUF, 128);
365 d += 128;
366 len -= 128;
367 rtrc(7);
368 /*** with int's on, it sometimes hangs after here.
369 * Looks like something makes HBNR go away. */
370 }
371 rtrc(4);
372 while (!(NCR5380_read(DTC_CONTROL_REG) & D_CR_ACCESS))
373 ++i;
374 NCR5380_write(MODE_REG, 0); /* Clear the operating mode */
375 rtrc(0);
376 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
377 if (i > dtc_maxi)
378 dtc_maxi = i;
379 return (0);
380}
381
382/****************************************************************
383 * Function : int NCR5380_pwrite (struct Scsi_Host *instance,
384 * unsigned char *src, int len)
385 *
386 * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from
387 * src
388 *
389 * Inputs : src = source, len = length in bytes
390 *
391 * Returns : 0 on success, non zero on a failure such as a watchdog
392 * timeout.
393*/
394
395static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src, int len)
396{
397 int i;
398 NCR5380_local_declare();
399 NCR5380_setup(instance);
400
401 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
402 NCR5380_write(MODE_REG, MR_ENABLE_EOP_INTR | MR_DMA_MODE);
403 /* set direction (write) */
404 if (instance->irq == SCSI_IRQ_NONE)
405 NCR5380_write(DTC_CONTROL_REG, 0);
406 else
407 NCR5380_write(DTC_CONTROL_REG, CSR_5380_INTR);
408 NCR5380_write(DTC_BLK_CNT, len >> 7); /* Block count */
409 for (i = 0; len > 0; ++i) {
410 rtrc(5);
411 /* Poll until the host buffer can accept data. */
412 while (NCR5380_read(DTC_CONTROL_REG) & CSR_HOST_BUF_NOT_RDY)
413 ++i;
414 rtrc(3);
415 memcpy_toio(base + DTC_DATA_BUF, src, 128);
416 src += 128;
417 len -= 128;
418 }
419 rtrc(4);
420 while (!(NCR5380_read(DTC_CONTROL_REG) & D_CR_ACCESS))
421 ++i;
422 rtrc(6);
423 /* Wait until the last byte has been sent to the disk */
424 while (!(NCR5380_read(TARGET_COMMAND_REG) & TCR_LAST_BYTE_SENT))
425 ++i;
426 rtrc(7);
427 /* Check for parity error here. fixme. */
428 NCR5380_write(MODE_REG, 0); /* Clear the operating mode */
429 rtrc(0);
430 if (i > dtc_wmaxi)
431 dtc_wmaxi = i;
432 return (0);
433}
434
435MODULE_LICENSE("GPL");
436
437#include "NCR5380.c"
438
439static int dtc_release(struct Scsi_Host *shost)
440{
441 NCR5380_local_declare();
442 NCR5380_setup(shost);
443 if (shost->irq)
Jeff Garzik1e641662007-11-11 19:52:05 -0500444 free_irq(shost->irq, shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 NCR5380_exit(shost);
446 if (shost->io_port && shost->n_io_port)
447 release_region(shost->io_port, shost->n_io_port);
448 scsi_unregister(shost);
449 iounmap(base);
450 return 0;
451}
452
Christoph Hellwigd0be4a7d2005-10-31 18:31:40 +0100453static struct scsi_host_template driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 .name = "DTC 3180/3280 ",
455 .detect = dtc_detect,
456 .release = dtc_release,
Finn Thain4d3d2a52014-11-12 16:11:52 +1100457 .proc_name = "dtc3x80",
458 .show_info = dtc_show_info,
459 .write_info = dtc_write_info,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 .queuecommand = dtc_queue_command,
461 .eh_abort_handler = dtc_abort,
462 .eh_bus_reset_handler = dtc_bus_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 .bios_param = dtc_biosparam,
464 .can_queue = CAN_QUEUE,
465 .this_id = 7,
466 .sg_tablesize = SG_ALL,
467 .cmd_per_lun = CMD_PER_LUN,
468 .use_clustering = DISABLE_CLUSTERING,
469};
470#include "scsi_module.c"