ncr5380: Remove unused macros
[linux-2.6/btrfs-unstable.git] / drivers / scsi / g_NCR5380.c
blobeeb8da5b2d4a165391e199c53c4ecf8bc9841a58
1 /*
2 * Generic Generic NCR5380 driver
3 *
4 * Copyright 1993, Drew Eckhardt
5 * Visionary Computing
6 * (Unix and Linux consulting and custom programming)
7 * drew@colorado.edu
8 * +1 (303) 440-4894
10 * NCR53C400 extensions (c) 1994,1995,1996, Kevin Lentin
11 * K.Lentin@cs.monash.edu.au
13 * NCR53C400A extensions (c) 1996, Ingmar Baumgart
14 * ingmar@gonzo.schwaben.de
16 * DTC3181E extensions (c) 1997, Ronald van Cuijlenborg
17 * ronald.van.cuijlenborg@tip.nl or nutty@dds.nl
19 * Added ISAPNP support for DTC436 adapters,
20 * Thomas Sailer, sailer@ife.ee.ethz.ch
22 * ALPHA RELEASE 1.
24 * For more information, please consult
26 * NCR 5380 Family
27 * SCSI Protocol Controller
28 * Databook
30 * NCR Microelectronics
31 * 1635 Aeroplaza Drive
32 * Colorado Springs, CO 80916
33 * 1+ (719) 578-3400
34 * 1+ (800) 334-5454
37 /*
38 * TODO : flesh out DMA support, find some one actually using this (I have
39 * a memory mapped Trantor board that works fine)
43 * Options :
45 * PARITY - enable parity checking. Not supported.
47 * The card is detected and initialized in one of several ways :
48 * 1. With command line overrides - NCR5380=port,irq may be
49 * used on the LILO command line to override the defaults.
51 * 2. With the GENERIC_NCR5380_OVERRIDE compile time define. This is
52 * specified as an array of address, irq, dma, board tuples. Ie, for
53 * one board at 0x350, IRQ5, no dma, I could say
54 * -DGENERIC_NCR5380_OVERRIDE={{0xcc000, 5, DMA_NONE, BOARD_NCR5380}}
56 * -1 should be specified for no or DMA interrupt, -2 to autoprobe for an
57 * IRQ line if overridden on the command line.
59 * 3. When included as a module, with arguments passed on the command line:
60 * ncr_irq=xx the interrupt
61 * ncr_addr=xx the port or base address (for port or memory
62 * mapped, resp.)
63 * ncr_dma=xx the DMA
64 * ncr_5380=1 to set up for a NCR5380 board
65 * ncr_53c400=1 to set up for a NCR53C400 board
66 * e.g.
67 * modprobe g_NCR5380 ncr_irq=5 ncr_addr=0x350 ncr_5380=1
68 * for a port mapped NCR5380 board or
69 * modprobe g_NCR5380 ncr_irq=255 ncr_addr=0xc8000 ncr_53c400=1
70 * for a memory mapped NCR53C400 board with interrupts disabled.
72 * 255 should be specified for no or DMA interrupt, 254 to autoprobe for an
73 * IRQ line if overridden on the command line.
77 /* settings for DTC3181E card with only Mustek scanner attached */
78 #define USLEEP_POLL 1
79 #define USLEEP_SLEEP 20
80 #define USLEEP_WAITLONG 500
82 #define AUTOPROBE_IRQ
83 #define AUTOSENSE
86 #ifdef CONFIG_SCSI_GENERIC_NCR53C400
87 #define NCR53C400_PSEUDO_DMA 1
88 #define PSEUDO_DMA
89 #define NCR53C400
90 #define NCR5380_STATS
91 #undef NCR5380_STAT_LIMIT
92 #endif
94 #include <asm/io.h>
95 #include <linux/signal.h>
96 #include <linux/blkdev.h>
97 #include "scsi.h"
98 #include <scsi/scsi_host.h>
99 #include "g_NCR5380.h"
100 #include "NCR5380.h"
101 #include <linux/stat.h>
102 #include <linux/init.h>
103 #include <linux/ioport.h>
104 #include <linux/isapnp.h>
105 #include <linux/delay.h>
106 #include <linux/interrupt.h>
108 #define NCR_NOT_SET 0
109 static int ncr_irq = NCR_NOT_SET;
110 static int ncr_dma = NCR_NOT_SET;
111 static int ncr_addr = NCR_NOT_SET;
112 static int ncr_5380 = NCR_NOT_SET;
113 static int ncr_53c400 = NCR_NOT_SET;
114 static int ncr_53c400a = NCR_NOT_SET;
115 static int dtc_3181e = NCR_NOT_SET;
117 static struct override {
118 NCR5380_map_type NCR5380_map_name;
119 int irq;
120 int dma;
121 int board; /* Use NCR53c400, Ricoh, etc. extensions ? */
122 } overrides
123 #ifdef GENERIC_NCR5380_OVERRIDE
124 [] __initdata = GENERIC_NCR5380_OVERRIDE;
125 #else
126 [1] __initdata = { { 0,},};
127 #endif
129 #define NO_OVERRIDES ARRAY_SIZE(overrides)
131 #ifndef MODULE
134 * internal_setup - handle lilo command string override
135 * @board: BOARD_* identifier for the board
136 * @str: unused
137 * @ints: numeric parameters
139 * Do LILO command line initialization of the overrides array. Display
140 * errors when needed
142 * Locks: none
145 static void __init internal_setup(int board, char *str, int *ints)
147 static int commandline_current = 0;
148 switch (board) {
149 case BOARD_NCR5380:
150 if (ints[0] != 2 && ints[0] != 3) {
151 printk(KERN_ERR "generic_NCR5380_setup : usage ncr5380=" STRVAL(NCR5380_map_name) ",irq,dma\n");
152 return;
154 break;
155 case BOARD_NCR53C400:
156 if (ints[0] != 2) {
157 printk(KERN_ERR "generic_NCR53C400_setup : usage ncr53c400=" STRVAL(NCR5380_map_name) ",irq\n");
158 return;
160 break;
161 case BOARD_NCR53C400A:
162 if (ints[0] != 2) {
163 printk(KERN_ERR "generic_NCR53C400A_setup : usage ncr53c400a=" STRVAL(NCR5380_map_name) ",irq\n");
164 return;
166 break;
167 case BOARD_DTC3181E:
168 if (ints[0] != 2) {
169 printk("generic_DTC3181E_setup : usage dtc3181e=" STRVAL(NCR5380_map_name) ",irq\n");
170 return;
172 break;
175 if (commandline_current < NO_OVERRIDES) {
176 overrides[commandline_current].NCR5380_map_name = (NCR5380_map_type) ints[1];
177 overrides[commandline_current].irq = ints[2];
178 if (ints[0] == 3)
179 overrides[commandline_current].dma = ints[3];
180 else
181 overrides[commandline_current].dma = DMA_NONE;
182 overrides[commandline_current].board = board;
183 ++commandline_current;
189 * do_NCR53C80_setup - set up entry point
190 * @str: unused
192 * Setup function invoked at boot to parse the ncr5380= command
193 * line.
196 static int __init do_NCR5380_setup(char *str)
198 int ints[10];
200 get_options(str, ARRAY_SIZE(ints), ints);
201 internal_setup(BOARD_NCR5380, str, ints);
202 return 1;
206 * do_NCR53C400_setup - set up entry point
207 * @str: unused
208 * @ints: integer parameters from kernel setup code
210 * Setup function invoked at boot to parse the ncr53c400= command
211 * line.
214 static int __init do_NCR53C400_setup(char *str)
216 int ints[10];
218 get_options(str, ARRAY_SIZE(ints), ints);
219 internal_setup(BOARD_NCR53C400, str, ints);
220 return 1;
224 * do_NCR53C400A_setup - set up entry point
225 * @str: unused
226 * @ints: integer parameters from kernel setup code
228 * Setup function invoked at boot to parse the ncr53c400a= command
229 * line.
232 static int __init do_NCR53C400A_setup(char *str)
234 int ints[10];
236 get_options(str, ARRAY_SIZE(ints), ints);
237 internal_setup(BOARD_NCR53C400A, str, ints);
238 return 1;
242 * do_DTC3181E_setup - set up entry point
243 * @str: unused
244 * @ints: integer parameters from kernel setup code
246 * Setup function invoked at boot to parse the dtc3181e= command
247 * line.
250 static int __init do_DTC3181E_setup(char *str)
252 int ints[10];
254 get_options(str, ARRAY_SIZE(ints), ints);
255 internal_setup(BOARD_DTC3181E, str, ints);
256 return 1;
259 #endif
262 * generic_NCR5380_detect - look for NCR5380 controllers
263 * @tpnt: the scsi template
265 * Scan for the present of NCR5380, NCR53C400, NCR53C400A, DTC3181E
266 * and DTC436(ISAPnP) controllers. If overrides have been set we use
267 * them.
269 * The caller supplied NCR5380_init function is invoked from here, before
270 * the interrupt line is taken.
272 * Locks: none
275 int __init generic_NCR5380_detect(struct scsi_host_template * tpnt)
277 static int current_override = 0;
278 int count;
279 unsigned int *ports;
280 #ifndef SCSI_G_NCR5380_MEM
281 int i;
282 unsigned long region_size = 16;
283 #endif
284 static unsigned int __initdata ncr_53c400a_ports[] = {
285 0x280, 0x290, 0x300, 0x310, 0x330, 0x340, 0x348, 0x350, 0
287 static unsigned int __initdata dtc_3181e_ports[] = {
288 0x220, 0x240, 0x280, 0x2a0, 0x2c0, 0x300, 0x320, 0x340, 0
290 int flags = 0;
291 struct Scsi_Host *instance;
292 #ifdef SCSI_G_NCR5380_MEM
293 unsigned long base;
294 void __iomem *iomem;
295 #endif
297 if (ncr_irq != NCR_NOT_SET)
298 overrides[0].irq = ncr_irq;
299 if (ncr_dma != NCR_NOT_SET)
300 overrides[0].dma = ncr_dma;
301 if (ncr_addr != NCR_NOT_SET)
302 overrides[0].NCR5380_map_name = (NCR5380_map_type) ncr_addr;
303 if (ncr_5380 != NCR_NOT_SET)
304 overrides[0].board = BOARD_NCR5380;
305 else if (ncr_53c400 != NCR_NOT_SET)
306 overrides[0].board = BOARD_NCR53C400;
307 else if (ncr_53c400a != NCR_NOT_SET)
308 overrides[0].board = BOARD_NCR53C400A;
309 else if (dtc_3181e != NCR_NOT_SET)
310 overrides[0].board = BOARD_DTC3181E;
311 #ifndef SCSI_G_NCR5380_MEM
312 if (!current_override && isapnp_present()) {
313 struct pnp_dev *dev = NULL;
314 count = 0;
315 while ((dev = pnp_find_dev(NULL, ISAPNP_VENDOR('D', 'T', 'C'), ISAPNP_FUNCTION(0x436e), dev))) {
316 if (count >= NO_OVERRIDES)
317 break;
318 if (pnp_device_attach(dev) < 0)
319 continue;
320 if (pnp_activate_dev(dev) < 0) {
321 printk(KERN_ERR "dtc436e probe: activate failed\n");
322 pnp_device_detach(dev);
323 continue;
325 if (!pnp_port_valid(dev, 0)) {
326 printk(KERN_ERR "dtc436e probe: no valid port\n");
327 pnp_device_detach(dev);
328 continue;
330 if (pnp_irq_valid(dev, 0))
331 overrides[count].irq = pnp_irq(dev, 0);
332 else
333 overrides[count].irq = SCSI_IRQ_NONE;
334 if (pnp_dma_valid(dev, 0))
335 overrides[count].dma = pnp_dma(dev, 0);
336 else
337 overrides[count].dma = DMA_NONE;
338 overrides[count].NCR5380_map_name = (NCR5380_map_type) pnp_port_start(dev, 0);
339 overrides[count].board = BOARD_DTC3181E;
340 count++;
343 #endif
344 tpnt->proc_name = "g_NCR5380";
346 for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
347 if (!(overrides[current_override].NCR5380_map_name))
348 continue;
350 ports = NULL;
351 switch (overrides[current_override].board) {
352 case BOARD_NCR5380:
353 flags = FLAG_NO_PSEUDO_DMA;
354 break;
355 case BOARD_NCR53C400:
356 flags = FLAG_NCR53C400;
357 break;
358 case BOARD_NCR53C400A:
359 flags = FLAG_NO_PSEUDO_DMA;
360 ports = ncr_53c400a_ports;
361 break;
362 case BOARD_DTC3181E:
363 flags = FLAG_NO_PSEUDO_DMA | FLAG_DTC3181E;
364 ports = dtc_3181e_ports;
365 break;
368 #ifndef SCSI_G_NCR5380_MEM
369 if (ports) {
370 /* wakeup sequence for the NCR53C400A and DTC3181E */
372 /* Disable the adapter and look for a free io port */
373 outb(0x59, 0x779);
374 outb(0xb9, 0x379);
375 outb(0xc5, 0x379);
376 outb(0xae, 0x379);
377 outb(0xa6, 0x379);
378 outb(0x00, 0x379);
380 if (overrides[current_override].NCR5380_map_name != PORT_AUTO)
381 for (i = 0; ports[i]; i++) {
382 if (!request_region(ports[i], 16, "ncr53c80"))
383 continue;
384 if (overrides[current_override].NCR5380_map_name == ports[i])
385 break;
386 release_region(ports[i], 16);
387 } else
388 for (i = 0; ports[i]; i++) {
389 if (!request_region(ports[i], 16, "ncr53c80"))
390 continue;
391 if (inb(ports[i]) == 0xff)
392 break;
393 release_region(ports[i], 16);
395 if (ports[i]) {
396 /* At this point we have our region reserved */
397 outb(0x59, 0x779);
398 outb(0xb9, 0x379);
399 outb(0xc5, 0x379);
400 outb(0xae, 0x379);
401 outb(0xa6, 0x379);
402 outb(0x80 | i, 0x379); /* set io port to be used */
403 outb(0xc0, ports[i] + 9);
404 if (inb(ports[i] + 9) != 0x80)
405 continue;
406 else
407 overrides[current_override].NCR5380_map_name = ports[i];
408 } else
409 continue;
411 else
413 /* Not a 53C400A style setup - just grab */
414 if(!(request_region(overrides[current_override].NCR5380_map_name, NCR5380_region_size, "ncr5380")))
415 continue;
416 region_size = NCR5380_region_size;
418 #else
419 base = overrides[current_override].NCR5380_map_name;
420 if (!request_mem_region(base, NCR5380_region_size, "ncr5380"))
421 continue;
422 iomem = ioremap(base, NCR5380_region_size);
423 if (!iomem) {
424 release_mem_region(base, NCR5380_region_size);
425 continue;
427 #endif
428 instance = scsi_register(tpnt, sizeof(struct NCR5380_hostdata));
429 if (instance == NULL) {
430 #ifndef SCSI_G_NCR5380_MEM
431 release_region(overrides[current_override].NCR5380_map_name, region_size);
432 #else
433 iounmap(iomem);
434 release_mem_region(base, NCR5380_region_size);
435 #endif
436 continue;
439 instance->NCR5380_instance_name = overrides[current_override].NCR5380_map_name;
440 #ifndef SCSI_G_NCR5380_MEM
441 instance->n_io_port = region_size;
442 #else
443 ((struct NCR5380_hostdata *)instance->hostdata)->iomem = iomem;
444 #endif
446 NCR5380_init(instance, flags);
448 if (overrides[current_override].irq != IRQ_AUTO)
449 instance->irq = overrides[current_override].irq;
450 else
451 instance->irq = NCR5380_probe_irq(instance, 0xffff);
453 if (instance->irq != SCSI_IRQ_NONE)
454 if (request_irq(instance->irq, generic_NCR5380_intr,
455 0, "NCR5380", instance)) {
456 printk(KERN_WARNING "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq);
457 instance->irq = SCSI_IRQ_NONE;
460 if (instance->irq == SCSI_IRQ_NONE) {
461 printk(KERN_INFO "scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
462 printk(KERN_INFO "scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
465 printk(KERN_INFO "scsi%d : at " STRVAL(NCR5380_map_name) " 0x%x", instance->host_no, (unsigned int) instance->NCR5380_instance_name);
466 if (instance->irq == SCSI_IRQ_NONE)
467 printk(" interrupts disabled");
468 else
469 printk(" irq %d", instance->irq);
470 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d", CAN_QUEUE, CMD_PER_LUN, GENERIC_NCR5380_PUBLIC_RELEASE);
471 NCR5380_print_options(instance);
472 printk("\n");
474 ++current_override;
475 ++count;
477 return count;
481 * generic_NCR5380_info - reporting string
482 * @host: NCR5380 to report on
484 * Report driver information for the NCR5380
487 const char *generic_NCR5380_info(struct Scsi_Host *host)
489 static const char string[] = "Generic NCR5380/53C400 Driver";
490 return string;
494 * generic_NCR5380_release_resources - free resources
495 * @instance: host adapter to clean up
497 * Free the generic interface resources from this adapter.
499 * Locks: none
502 int generic_NCR5380_release_resources(struct Scsi_Host *instance)
504 NCR5380_local_declare();
505 NCR5380_setup(instance);
507 if (instance->irq != SCSI_IRQ_NONE)
508 free_irq(instance->irq, instance);
509 NCR5380_exit(instance);
511 #ifndef SCSI_G_NCR5380_MEM
512 release_region(instance->NCR5380_instance_name, instance->n_io_port);
513 #else
514 iounmap(((struct NCR5380_hostdata *)instance->hostdata)->iomem);
515 release_mem_region(instance->NCR5380_instance_name, NCR5380_region_size);
516 #endif
519 return 0;
522 #ifdef BIOSPARAM
524 * generic_NCR5380_biosparam
525 * @disk: disk to compute geometry for
526 * @dev: device identifier for this disk
527 * @ip: sizes to fill in
529 * Generates a BIOS / DOS compatible H-C-S mapping for the specified
530 * device / size.
532 * XXX Most SCSI boards use this mapping, I could be incorrect. Someone
533 * using hard disks on a trantor should verify that this mapping
534 * corresponds to that used by the BIOS / ASPI driver by running the linux
535 * fdisk program and matching the H_C_S coordinates to what DOS uses.
537 * Locks: none
540 static int
541 generic_NCR5380_biosparam(struct scsi_device *sdev, struct block_device *bdev,
542 sector_t capacity, int *ip)
544 ip[0] = 64;
545 ip[1] = 32;
546 ip[2] = capacity >> 11;
547 return 0;
549 #endif
551 #ifdef NCR53C400_PSEUDO_DMA
554 * NCR5380_pread - pseudo DMA read
555 * @instance: adapter to read from
556 * @dst: buffer to read into
557 * @len: buffer length
559 * Perform a pseudo DMA mode read from an NCR53C400 or equivalent
560 * controller
563 static inline int NCR5380_pread(struct Scsi_Host *instance, unsigned char *dst, int len)
565 int blocks = len / 128;
566 int start = 0;
567 int bl;
569 NCR5380_local_declare();
570 NCR5380_setup(instance);
572 NCR5380_write(C400_CONTROL_STATUS_REG, CSR_BASE | CSR_TRANS_DIR);
573 NCR5380_write(C400_BLOCK_COUNTER_REG, blocks);
574 while (1) {
575 if ((bl = NCR5380_read(C400_BLOCK_COUNTER_REG)) == 0) {
576 break;
578 if (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_GATED_53C80_IRQ) {
579 printk(KERN_ERR "53C400r: Got 53C80_IRQ start=%d, blocks=%d\n", start, blocks);
580 return -1;
582 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY);
584 #ifndef SCSI_G_NCR5380_MEM
586 int i;
587 for (i = 0; i < 128; i++)
588 dst[start + i] = NCR5380_read(C400_HOST_BUFFER);
590 #else
591 /* implies SCSI_G_NCR5380_MEM */
592 memcpy_fromio(dst + start, iomem + NCR53C400_host_buffer, 128);
593 #endif
594 start += 128;
595 blocks--;
598 if (blocks) {
599 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY)
601 // FIXME - no timeout
604 #ifndef SCSI_G_NCR5380_MEM
606 int i;
607 for (i = 0; i < 128; i++)
608 dst[start + i] = NCR5380_read(C400_HOST_BUFFER);
610 #else
611 /* implies SCSI_G_NCR5380_MEM */
612 memcpy_fromio(dst + start, iomem + NCR53C400_host_buffer, 128);
613 #endif
614 start += 128;
615 blocks--;
618 if (!(NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_GATED_53C80_IRQ))
619 printk("53C400r: no 53C80 gated irq after transfer");
621 #if 0
623 * DON'T DO THIS - THEY NEVER ARRIVE!
625 printk("53C400r: Waiting for 53C80 registers\n");
626 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_53C80_REG)
628 #endif
629 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_END_DMA_TRANSFER))
630 printk(KERN_ERR "53C400r: no end dma signal\n");
632 NCR5380_write(MODE_REG, MR_BASE);
633 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
634 return 0;
638 * NCR5380_write - pseudo DMA write
639 * @instance: adapter to read from
640 * @dst: buffer to read into
641 * @len: buffer length
643 * Perform a pseudo DMA mode read from an NCR53C400 or equivalent
644 * controller
647 static inline int NCR5380_pwrite(struct Scsi_Host *instance, unsigned char *src, int len)
649 int blocks = len / 128;
650 int start = 0;
651 int bl;
652 int i;
654 NCR5380_local_declare();
655 NCR5380_setup(instance);
657 NCR5380_write(C400_CONTROL_STATUS_REG, CSR_BASE);
658 NCR5380_write(C400_BLOCK_COUNTER_REG, blocks);
659 while (1) {
660 if (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_GATED_53C80_IRQ) {
661 printk(KERN_ERR "53C400w: Got 53C80_IRQ start=%d, blocks=%d\n", start, blocks);
662 return -1;
665 if ((bl = NCR5380_read(C400_BLOCK_COUNTER_REG)) == 0) {
666 break;
668 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY)
669 ; // FIXME - timeout
670 #ifndef SCSI_G_NCR5380_MEM
672 for (i = 0; i < 128; i++)
673 NCR5380_write(C400_HOST_BUFFER, src[start + i]);
675 #else
676 /* implies SCSI_G_NCR5380_MEM */
677 memcpy_toio(iomem + NCR53C400_host_buffer, src + start, 128);
678 #endif
679 start += 128;
680 blocks--;
682 if (blocks) {
683 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY)
684 ; // FIXME - no timeout
686 #ifndef SCSI_G_NCR5380_MEM
688 for (i = 0; i < 128; i++)
689 NCR5380_write(C400_HOST_BUFFER, src[start + i]);
691 #else
692 /* implies SCSI_G_NCR5380_MEM */
693 memcpy_toio(iomem + NCR53C400_host_buffer, src + start, 128);
694 #endif
695 start += 128;
696 blocks--;
699 #if 0
700 printk("53C400w: waiting for registers to be available\n");
701 THEY NEVER DO ! while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_53C80_REG);
702 printk("53C400w: Got em\n");
703 #endif
705 /* Let's wait for this instead - could be ugly */
706 /* All documentation says to check for this. Maybe my hardware is too
707 * fast. Waiting for it seems to work fine! KLL
709 while (!(i = NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_GATED_53C80_IRQ))
710 ; // FIXME - no timeout
713 * I know. i is certainly != 0 here but the loop is new. See previous
714 * comment.
716 if (i) {
717 if (!((i = NCR5380_read(BUS_AND_STATUS_REG)) & BASR_END_DMA_TRANSFER))
718 printk(KERN_ERR "53C400w: No END OF DMA bit - WHOOPS! BASR=%0x\n", i);
719 } else
720 printk(KERN_ERR "53C400w: no 53C80 gated irq after transfer (last block)\n");
722 #if 0
723 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_END_DMA_TRANSFER)) {
724 printk(KERN_ERR "53C400w: no end dma signal\n");
726 #endif
727 while (!(NCR5380_read(TARGET_COMMAND_REG) & TCR_LAST_BYTE_SENT))
728 ; // TIMEOUT
729 return 0;
731 #endif /* PSEUDO_DMA */
734 * Include the NCR5380 core code that we build our driver around
737 #include "NCR5380.c"
739 #define PRINTP(x) seq_printf(m, x)
740 #define ANDP ,
742 static void sprint_opcode(struct seq_file *m, int opcode)
744 PRINTP("0x%02x " ANDP opcode);
747 static void sprint_command(struct seq_file *m, unsigned char *command)
749 int i, s;
750 sprint_opcode(m, command[0]);
751 for (i = 1, s = COMMAND_SIZE(command[0]); i < s; ++i)
752 PRINTP("%02x " ANDP command[i]);
753 PRINTP("\n");
757 * sprintf_Scsi_Cmnd - print a scsi command
758 * @m: seq_fil to print into
759 * @cmd: SCSI command block
761 * Print out the target and command data in hex
764 static void sprint_Scsi_Cmnd(struct seq_file *m, Scsi_Cmnd * cmd)
766 PRINTP("host number %d destination target %d, lun %llu\n" ANDP cmd->device->host->host_no ANDP cmd->device->id ANDP cmd->device->lun);
767 PRINTP(" command = ");
768 sprint_command(m, cmd->cmnd);
772 * generic_NCR5380_proc_info - /proc for NCR5380 driver
773 * @buffer: buffer to print into
774 * @start: start position
775 * @offset: offset into buffer
776 * @len: length
777 * @hostno: instance to affect
778 * @inout: read/write
780 * Provide the procfs information for the 5380 controller. We fill
781 * this with useful debugging information including the commands
782 * being executed, disconnected command queue and the statistical
783 * data
785 * Locks: global cli/lock for queue walk
788 static int generic_NCR5380_show_info(struct seq_file *m, struct Scsi_Host *scsi_ptr)
790 NCR5380_local_declare();
791 unsigned long flags;
792 unsigned char status;
793 int i;
794 Scsi_Cmnd *ptr;
795 struct NCR5380_hostdata *hostdata;
796 #ifdef NCR5380_STATS
797 struct scsi_device *dev;
798 #endif
800 NCR5380_setup(scsi_ptr);
801 hostdata = (struct NCR5380_hostdata *) scsi_ptr->hostdata;
803 spin_lock_irqsave(scsi_ptr->host_lock, flags);
804 PRINTP("SCSI host number %d : %s\n" ANDP scsi_ptr->host_no ANDP scsi_ptr->hostt->name);
805 PRINTP("Generic NCR5380 driver version %d\n" ANDP GENERIC_NCR5380_PUBLIC_RELEASE);
806 PRINTP("NCR5380 core version %d\n" ANDP NCR5380_PUBLIC_RELEASE);
807 #ifdef NCR53C400
808 PRINTP("NCR53C400 extension version %d\n" ANDP NCR53C400_PUBLIC_RELEASE);
809 PRINTP("NCR53C400 card%s detected\n" ANDP(((struct NCR5380_hostdata *) scsi_ptr->hostdata)->flags & FLAG_NCR53C400) ? "" : " not");
810 # if NCR53C400_PSEUDO_DMA
811 PRINTP("NCR53C400 pseudo DMA used\n");
812 # endif
813 #else
814 PRINTP("NO NCR53C400 driver extensions\n");
815 #endif
816 PRINTP("Using %s mapping at %s 0x%lx, " ANDP STRVAL(NCR5380_map_config) ANDP STRVAL(NCR5380_map_name) ANDP scsi_ptr->NCR5380_instance_name);
817 if (scsi_ptr->irq == SCSI_IRQ_NONE)
818 PRINTP("no interrupt\n");
819 else
820 PRINTP("on interrupt %d\n" ANDP scsi_ptr->irq);
822 #ifdef NCR5380_STATS
823 if (hostdata->connected || hostdata->issue_queue || hostdata->disconnected_queue)
824 PRINTP("There are commands pending, transfer rates may be crud\n");
825 if (hostdata->pendingr)
826 PRINTP(" %d pending reads" ANDP hostdata->pendingr);
827 if (hostdata->pendingw)
828 PRINTP(" %d pending writes" ANDP hostdata->pendingw);
829 if (hostdata->pendingr || hostdata->pendingw)
830 PRINTP("\n");
831 shost_for_each_device(dev, scsi_ptr) {
832 unsigned long br = hostdata->bytes_read[dev->id];
833 unsigned long bw = hostdata->bytes_write[dev->id];
834 long tr = hostdata->time_read[dev->id] / HZ;
835 long tw = hostdata->time_write[dev->id] / HZ;
837 PRINTP(" T:%d %s " ANDP dev->id ANDP scsi_device_type(dev->type));
838 for (i = 0; i < 8; i++)
839 if (dev->vendor[i] >= 0x20)
840 seq_putc(m, dev->vendor[i]);
841 seq_putc(m, ' ');
842 for (i = 0; i < 16; i++)
843 if (dev->model[i] >= 0x20)
844 seq_putc(m, dev->model[i]);
845 seq_putc(m, ' ');
846 for (i = 0; i < 4; i++)
847 if (dev->rev[i] >= 0x20)
848 seq_putc(m, dev->rev[i]);
849 seq_putc(m, ' ');
851 PRINTP("\n%10ld kb read in %5ld secs" ANDP br / 1024 ANDP tr);
852 if (tr)
853 PRINTP(" @ %5ld bps" ANDP br / tr);
855 PRINTP("\n%10ld kb written in %5ld secs" ANDP bw / 1024 ANDP tw);
856 if (tw)
857 PRINTP(" @ %5ld bps" ANDP bw / tw);
858 PRINTP("\n");
860 #endif
862 status = NCR5380_read(STATUS_REG);
863 if (!(status & SR_REQ))
864 PRINTP("REQ not asserted, phase unknown.\n");
865 else {
866 for (i = 0; (phases[i].value != PHASE_UNKNOWN) && (phases[i].value != (status & PHASE_MASK)); ++i);
867 PRINTP("Phase %s\n" ANDP phases[i].name);
870 if (!hostdata->connected) {
871 PRINTP("No currently connected command\n");
872 } else {
873 sprint_Scsi_Cmnd(m, (Scsi_Cmnd *) hostdata->connected);
876 PRINTP("issue_queue\n");
878 for (ptr = (Scsi_Cmnd *) hostdata->issue_queue; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble)
879 sprint_Scsi_Cmnd(m, ptr);
881 PRINTP("disconnected_queue\n");
883 for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble)
884 sprint_Scsi_Cmnd(m, ptr);
886 spin_unlock_irqrestore(scsi_ptr->host_lock, flags);
887 return 0;
890 #undef PRINTP
891 #undef ANDP
893 static struct scsi_host_template driver_template = {
894 .show_info = generic_NCR5380_show_info,
895 .name = "Generic NCR5380/NCR53C400 Scsi Driver",
896 .detect = generic_NCR5380_detect,
897 .release = generic_NCR5380_release_resources,
898 .info = generic_NCR5380_info,
899 .queuecommand = generic_NCR5380_queue_command,
900 .eh_abort_handler = generic_NCR5380_abort,
901 .eh_bus_reset_handler = generic_NCR5380_bus_reset,
902 .bios_param = NCR5380_BIOSPARAM,
903 .can_queue = CAN_QUEUE,
904 .this_id = 7,
905 .sg_tablesize = SG_ALL,
906 .cmd_per_lun = CMD_PER_LUN,
907 .use_clustering = DISABLE_CLUSTERING,
909 #include <linux/module.h>
910 #include "scsi_module.c"
912 module_param(ncr_irq, int, 0);
913 module_param(ncr_dma, int, 0);
914 module_param(ncr_addr, int, 0);
915 module_param(ncr_5380, int, 0);
916 module_param(ncr_53c400, int, 0);
917 module_param(ncr_53c400a, int, 0);
918 module_param(dtc_3181e, int, 0);
919 MODULE_LICENSE("GPL");
921 #ifndef SCSI_G_NCR5380_MEM
922 static struct isapnp_device_id id_table[] = {
924 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
925 ISAPNP_VENDOR('D', 'T', 'C'), ISAPNP_FUNCTION(0x436e),
930 MODULE_DEVICE_TABLE(isapnp, id_table);
931 #endif
933 __setup("ncr5380=", do_NCR5380_setup);
934 __setup("ncr53c400=", do_NCR53C400_setup);
935 __setup("ncr53c400a=", do_NCR53C400A_setup);
936 __setup("dtc3181e=", do_DTC3181E_setup);