blob: ccfdc427c4c7449e2a38766c58f7f916538444f3 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#define AUTOSENSE
2#define PSEUDO_DMA
3
4/*
5 * Trantor T128/T128F/T228 driver
6 * Note : architecturally, the T100 and T130 are different and won't
7 * work
8 *
9 * Copyright 1993, Drew Eckhardt
10 * Visionary Computing
11 * (Unix and Linux consulting and custom programming)
12 * drew@colorado.edu
13 * +1 (303) 440-4894
14 *
15 * DISTRIBUTION RELEASE 3.
16 *
17 * For more information, please consult
18 *
19 * Trantor Systems, Ltd.
20 * T128/T128F/T228 SCSI Host Adapter
21 * Hardware Specifications
22 *
23 * Trantor Systems, Ltd.
24 * 5415 Randall Place
25 * Fremont, CA 94538
26 * 1+ (415) 770-1400, FAX 1+ (415) 770-9910
27 *
28 * and
29 *
30 * NCR 5380 Family
31 * SCSI Protocol Controller
32 * Databook
33 *
34 * NCR Microelectronics
35 * 1635 Aeroplaza Drive
36 * Colorado Springs, CO 80916
37 * 1+ (719) 578-3400
38 * 1+ (800) 334-5454
39 */
40
41/*
42 * Options :
43 * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
44 * for commands that return with a CHECK CONDITION status.
45 *
46 * PSEUDO_DMA - enables PSEUDO-DMA hardware, should give a 3-4X performance
47 * increase compared to polled I/O.
48 *
49 * PARITY - enable parity checking. Not supported.
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 *
51 * UNSAFE - leave interrupts enabled during pseudo-DMA transfers. You
52 * only really want to use this if you're having a problem with
53 * dropped characters during high speed communications, and even
54 * then, you're going to be better off twiddling with transfersize.
55 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 * The card is detected and initialized in one of several ways :
57 * 1. Autoprobe (default) - since the board is memory mapped,
58 * a BIOS signature is scanned for to locate the registers.
59 * An interrupt is triggered to autoprobe for the interrupt
60 * line.
61 *
62 * 2. With command line overrides - t128=address,irq may be
63 * used on the LILO command line to override the defaults.
64 *
65 * 3. With the T128_OVERRIDE compile time define. This is
66 * specified as an array of address, irq tuples. Ie, for
67 * one board at the default 0xcc000 address, IRQ5, I could say
68 * -DT128_OVERRIDE={{0xcc000, 5}}
69 *
70 * Note that if the override methods are used, place holders must
71 * be specified for other boards in the system.
72 *
73 * T128/T128F jumper/dipswitch settings (note : on my sample, the switches
74 * were epoxy'd shut, meaning I couldn't change the 0xcc000 base address) :
75 *
76 * T128 Sw7 Sw8 Sw6 = 0ws Sw5 = boot
77 * T128F Sw6 Sw7 Sw5 = 0ws Sw4 = boot Sw8 = floppy disable
78 * cc000 off off
79 * c8000 off on
80 * dc000 on off
81 * d8000 on on
82 *
83 *
84 * Interrupts
85 * There is a 12 pin jumper block, jp1, numbered as follows :
86 * T128 (JP1) T128F (J5)
87 * 2 4 6 8 10 12 11 9 7 5 3 1
88 * 1 3 5 7 9 11 12 10 8 6 4 2
89 *
90 * 3 2-4
91 * 5 1-3
92 * 7 3-5
93 * T128F only
94 * 10 8-10
95 * 12 7-9
96 * 14 10-12
97 * 15 9-11
98 */
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#include <linux/signal.h>
Matthew Wilcox53d5ed62006-10-11 01:22:01 -0700101#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#include <linux/blkdev.h>
103#include <linux/interrupt.h>
104#include <linux/stat.h>
105#include <linux/init.h>
106#include <linux/module.h>
107#include <linux/delay.h>
108
109#include "scsi.h"
110#include <scsi/scsi_host.h>
111#include "t128.h"
112#define AUTOPROBE_IRQ
113#include "NCR5380.h"
114
115static struct override {
116 unsigned long address;
117 int irq;
Tobias Klauser6391a112006-06-08 22:23:48 -0700118} overrides
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#ifdef T128_OVERRIDE
120 [] __initdata = T128_OVERRIDE;
121#else
Tobias Klauser6391a112006-06-08 22:23:48 -0700122 [4] __initdata = {{0, IRQ_AUTO}, {0, IRQ_AUTO},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 {0 ,IRQ_AUTO}, {0, IRQ_AUTO}};
124#endif
125
Tobias Klauser6391a112006-06-08 22:23:48 -0700126#define NO_OVERRIDES ARRAY_SIZE(overrides)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128static struct base {
129 unsigned int address;
130 int noauto;
131} bases[] __initdata = {
132 { 0xcc000, 0}, { 0xc8000, 0}, { 0xdc000, 0}, { 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 struct signature {
138 const char *string;
139 int offset;
140} signatures[] __initdata = {
141{"TSROM: SCSI BIOS, Version 1.12", 0x36},
142};
143
Tobias Klauser6391a112006-06-08 22:23:48 -0700144#define NO_SIGNATURES ARRAY_SIZE(signatures)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Finn Thain925e4612014-11-12 16:11:49 +1100146#ifndef MODULE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147/*
148 * Function : t128_setup(char *str, int *ints)
149 *
150 * Purpose : LILO command line initialization of the overrides array,
151 *
152 * Inputs : str - unused, ints - array of integer parameters with ints[0]
153 * equal to the number of ints.
154 *
155 */
156
Finn Thain925e4612014-11-12 16:11:49 +1100157static int __init t128_setup(char *str)
158{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 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("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 }
Finn Thain925e4612014-11-12 16:11:49 +1100177 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178}
179
Finn Thain925e4612014-11-12 16:11:49 +1100180__setup("t128=", t128_setup);
181#endif
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183/*
Christoph Hellwigd0be4a7d2005-10-31 18:31:40 +0100184 * Function : int t128_detect(struct scsi_host_template * tpnt)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 *
186 * Purpose : detects and initializes T128,T128F, or T228 controllers
187 * that were autoprobed, overridden on the LILO command line,
188 * or specified at compile time.
189 *
190 * Inputs : tpnt - template for this SCSI adapter.
191 *
192 * Returns : 1 if a host adapter was found, 0 if not.
193 *
194 */
195
Finn Thained8b9e72014-11-12 16:11:51 +1100196static int __init t128_detect(struct scsi_host_template *tpnt)
197{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 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";
Al Virodd7ab712013-03-31 01:15:54 -0400205 tpnt->show_info = t128_show_info;
206 tpnt->write_info = t128_write_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208 for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
209 base = 0;
210 p = NULL;
211
212 if (overrides[current_override].address) {
213 base = overrides[current_override].address;
214 p = ioremap(bases[current_base].address, 0x2000);
215 if (!p)
216 base = 0;
217 } else
218 for (; !base && (current_base < NO_BASES); ++current_base) {
219#if (TDEBUG & TDEBUG_INIT)
220 printk("scsi-t128 : probing address %08x\n", bases[current_base].address);
221#endif
222 if (bases[current_base].noauto)
223 continue;
224 p = ioremap(bases[current_base].address, 0x2000);
225 if (!p)
226 continue;
227 for (sig = 0; sig < NO_SIGNATURES; ++sig)
228 if (check_signature(p + signatures[sig].offset,
229 signatures[sig].string,
230 strlen(signatures[sig].string))) {
231 base = bases[current_base].address;
232#if (TDEBUG & TDEBUG_INIT)
233 printk("scsi-t128 : detected board.\n");
234#endif
235 goto found;
236 }
237 iounmap(p);
238 }
239
240#if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
241 printk("scsi-t128 : base = %08x\n", (unsigned int) base);
242#endif
243
244 if (!base)
245 break;
246
247found:
248 instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
249 if(instance == NULL)
250 break;
251
252 instance->base = base;
253 ((struct NCR5380_hostdata *)instance->hostdata)->base = p;
254
255 NCR5380_init(instance, 0);
256
257 if (overrides[current_override].irq != IRQ_AUTO)
258 instance->irq = overrides[current_override].irq;
259 else
260 instance->irq = NCR5380_probe_irq(instance, T128_IRQS);
261
262 if (instance->irq != SCSI_IRQ_NONE)
Michael Opdenacker4909cc22014-03-05 06:09:41 +0100263 if (request_irq(instance->irq, t128_intr, 0, "t128",
Jeff Garzik1e641662007-11-11 19:52:05 -0500264 instance)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265 printk("scsi%d : IRQ%d not free, interrupts disabled\n",
266 instance->host_no, instance->irq);
267 instance->irq = SCSI_IRQ_NONE;
268 }
269
270 if (instance->irq == SCSI_IRQ_NONE) {
271 printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
272 printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
273 }
274
275#if defined(TDEBUG) && (TDEBUG & TDEBUG_INIT)
276 printk("scsi%d : irq = %d\n", instance->host_no, instance->irq);
277#endif
278
279 printk("scsi%d : at 0x%08lx", instance->host_no, instance->base);
280 if (instance->irq == SCSI_IRQ_NONE)
281 printk (" interrupts disabled");
282 else
283 printk (" irq %d", instance->irq);
284 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
285 CAN_QUEUE, CMD_PER_LUN, T128_PUBLIC_RELEASE);
286 NCR5380_print_options(instance);
287 printk("\n");
288
289 ++current_override;
290 ++count;
291 }
292 return count;
293}
294
295static int t128_release(struct Scsi_Host *shost)
296{
297 NCR5380_local_declare();
298 NCR5380_setup(shost);
299 if (shost->irq)
Jeff Garzik1e641662007-11-11 19:52:05 -0500300 free_irq(shost->irq, shost);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 NCR5380_exit(shost);
302 if (shost->io_port && shost->n_io_port)
303 release_region(shost->io_port, shost->n_io_port);
304 scsi_unregister(shost);
305 iounmap(base);
306 return 0;
307}
308
309/*
310 * Function : int t128_biosparam(Disk * disk, struct block_device *dev, int *ip)
311 *
312 * Purpose : Generates a BIOS / DOS compatible H-C-S mapping for
313 * the specified device / size.
314 *
315 * Inputs : size = size of device in sectors (512 bytes), dev = block device
316 * major / minor, ip[] = {heads, sectors, cylinders}
317 *
318 * Returns : always 0 (success), initializes ip
319 *
320 */
321
322/*
323 * XXX Most SCSI boards use this mapping, I could be incorrect. Some one
324 * using hard disks on a trantor should verify that this mapping corresponds
325 * to that used by the BIOS / ASPI driver by running the linux fdisk program
326 * and matching the H_C_S coordinates to what DOS uses.
327 */
328
Finn Thained8b9e72014-11-12 16:11:51 +1100329static int t128_biosparam(struct scsi_device *sdev, struct block_device *bdev,
330 sector_t capacity, int *ip)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
332 ip[0] = 64;
333 ip[1] = 32;
334 ip[2] = capacity >> 11;
335 return 0;
336}
337
338/*
339 * Function : int NCR5380_pread (struct Scsi_Host *instance,
340 * unsigned char *dst, int len)
341 *
342 * Purpose : Fast 5380 pseudo-dma read function, transfers len bytes to
343 * dst
344 *
345 * Inputs : dst = destination, len = length in bytes
346 *
347 * Returns : 0 on success, non zero on a failure such as a watchdog
348 * timeout.
349 */
350
351static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst,
352 int len) {
353 NCR5380_local_declare();
354 void __iomem *reg;
355 unsigned char *d = dst;
356 register int i = len;
357
358 NCR5380_setup(instance);
359 reg = base + T_DATA_REG_OFFSET;
360
361#if 0
362 for (; i; --i) {
363 while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
364#else
365 while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
366 for (; i; --i) {
367#endif
368 *d++ = readb(reg);
369 }
370
371 if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
372 unsigned char tmp;
373 void __iomem *foo = base + T_CONTROL_REG_OFFSET;
374 tmp = readb(foo);
375 writeb(tmp | T_CR_CT, foo);
376 writeb(tmp, foo);
377 printk("scsi%d : watchdog timer fired in NCR5380_pread()\n",
378 instance->host_no);
379 return -1;
380 } else
381 return 0;
382}
383
384/*
385 * Function : int NCR5380_pwrite (struct Scsi_Host *instance,
386 * unsigned char *src, int len)
387 *
388 * Purpose : Fast 5380 pseudo-dma write function, transfers len bytes from
389 * src
390 *
391 * Inputs : src = source, len = length in bytes
392 *
393 * Returns : 0 on success, non zero on a failure such as a watchdog
394 * timeout.
395 */
396
397static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src,
398 int len) {
399 NCR5380_local_declare();
400 void __iomem *reg;
401 unsigned char *s = src;
402 register int i = len;
403
404 NCR5380_setup(instance);
405 reg = base + T_DATA_REG_OFFSET;
406
407#if 0
408 for (; i; --i) {
409 while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
410#else
411 while (!(readb(base+T_STATUS_REG_OFFSET) & T_ST_RDY)) barrier();
412 for (; i; --i) {
413#endif
414 writeb(*s++, reg);
415 }
416
417 if (readb(base + T_STATUS_REG_OFFSET) & T_ST_TIM) {
418 unsigned char tmp;
419 void __iomem *foo = base + T_CONTROL_REG_OFFSET;
420 tmp = readb(foo);
421 writeb(tmp | T_CR_CT, foo);
422 writeb(tmp, foo);
423 printk("scsi%d : watchdog timer fired in NCR5380_pwrite()\n",
424 instance->host_no);
425 return -1;
426 } else
427 return 0;
428}
429
430MODULE_LICENSE("GPL");
431
432#include "NCR5380.c"
433
Christoph Hellwigd0be4a7d2005-10-31 18:31:40 +0100434static struct scsi_host_template driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 .name = "Trantor T128/T128F/T228",
436 .detect = t128_detect,
437 .release = t128_release,
438 .queuecommand = t128_queue_command,
439 .eh_abort_handler = t128_abort,
440 .eh_bus_reset_handler = t128_bus_reset,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 .bios_param = t128_biosparam,
442 .can_queue = CAN_QUEUE,
443 .this_id = 7,
444 .sg_tablesize = SG_ALL,
445 .cmd_per_lun = CMD_PER_LUN,
446 .use_clustering = DISABLE_CLUSTERING,
447};
448#include "scsi_module.c"