* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / drivers / scsi / g_NCR5380.c
blob875da3846e8bfa3b9a0e5e17d1c7e7b919b382f0
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 * ALPHA RELEASE 1.
21 * For more information, please consult
23 * NCR 5380 Family
24 * SCSI Protocol Controller
25 * Databook
27 * NCR Microelectronics
28 * 1635 Aeroplaza Drive
29 * Colorado Springs, CO 80916
30 * 1+ (719) 578-3400
31 * 1+ (800) 334-5454
34 /*
35 * TODO : flesh out DMA support, find some one actually using this (I have
36 * a memory mapped Trantor board that works fine)
40 * Options :
42 * PARITY - enable parity checking. Not supported.
44 * SCSI2 - enable support for SCSI-II tagged queueing. Untested.
46 * USLEEP - enable support for devices that don't disconnect. Untested.
48 * The card is detected and initialized in one of several ways :
49 * 1. With command line overrides - NCR5380=port,irq may be
50 * used on the LILO command line to override the defaults.
52 * 2. With the GENERIC_NCR5380_OVERRIDE compile time define. This is
53 * specified as an array of address, irq, dma, board tuples. Ie, for
54 * one board at 0x350, IRQ5, no dma, I could say
55 * -DGENERIC_NCR5380_OVERRIDE={{0xcc000, 5, DMA_NONE, BOARD_NCR5380}}
57 * -1 should be specified for no or DMA interrupt, -2 to autoprobe for an
58 * IRQ line if overridden on the command line.
60 * 3. When included as a module, with arguments passed on the command line:
61 * ncr_irq=xx the interrupt
62 * ncr_addr=xx the port or base address (for port or memory
63 * mapped, resp.)
64 * ncr_dma=xx the DMA
65 * ncr_5380=1 to set up for a NCR5380 board
66 * ncr_53c400=1 to set up for a NCR53C400 board
67 * e.g.
68 * modprobe g_NCR5380 ncr_irq=5 ncr_addr=0x350 ncr_5380=1
69 * for a port mapped NCR5380 board or
70 * modprobe g_NCR5380 ncr_irq=255 ncr_addr=0xc8000 ncr_53c400=1
71 * for a memory mapped NCR53C400 board with interrupts disabled.
73 * 255 should be specified for no or DMA interrupt, 254 to autoprobe for an
74 * IRQ line if overridden on the command line.
79 * $Log: generic_NCR5380.c,v $
82 /* settings for DTC3181E card with only Mustek scanner attached */
83 #define USLEEP
84 #define USLEEP_POLL 1
85 #define USLEEP_SLEEP 20
86 #define USLEEP_WAITLONG 500
88 #define AUTOPROBE_IRQ
89 #define AUTOSENSE
91 #include <linux/config.h>
93 #ifdef CONFIG_SCSI_GENERIC_NCR53C400
94 #define NCR53C400_PSEUDO_DMA 1
95 #define PSEUDO_DMA
96 #define NCR53C400
97 #define NCR5380_STATS
98 #undef NCR5380_STAT_LIMIT
99 #endif
100 #if defined(CONFIG_SCSI_G_NCR5380_PORT) && defined(CONFIG_SCSI_G_NCR5380_MEM)
101 #error You can not configure the Generic NCR 5380 SCSI Driver for memory mapped I/O and port mapped I/O at the same time (yet)
102 #endif
103 #if !defined(CONFIG_SCSI_G_NCR5380_PORT) && !defined(CONFIG_SCSI_G_NCR5380_MEM)
104 #error You must configure the Generic NCR 5380 SCSI Driver for one of memory mapped I/O and port mapped I/O.
105 #endif
107 #include <asm/system.h>
108 #include <asm/io.h>
109 #include <linux/signal.h>
110 #include <linux/sched.h>
111 #include <linux/blk.h>
112 #include "scsi.h"
113 #include "hosts.h"
114 #include "g_NCR5380.h"
115 #include "NCR5380.h"
116 #include "constants.h"
117 #include "sd.h"
118 #include <linux/stat.h>
119 #include <linux/init.h>
120 #include<linux/ioport.h>
122 struct proc_dir_entry proc_scsi_g_ncr5380 = {
123 PROC_SCSI_GENERIC_NCR5380, 9, "g_NCR5380",
124 S_IFDIR | S_IRUGO | S_IXUGO, 2
127 #define NCR_NOT_SET 0
128 static int ncr_irq=NCR_NOT_SET;
129 static int ncr_dma=NCR_NOT_SET;
130 static int ncr_addr=NCR_NOT_SET;
131 static int ncr_5380=NCR_NOT_SET;
132 static int ncr_53c400=NCR_NOT_SET;
133 static int ncr_53c400a=NCR_NOT_SET;
134 static int dtc_3181e=NCR_NOT_SET;
136 static struct override {
137 NCR5380_implementation_fields;
138 int irq;
139 int dma;
140 int board; /* Use NCR53c400, Ricoh, etc. extensions ? */
141 } overrides
142 #ifdef GENERIC_NCR5380_OVERRIDE
143 [] __initdata = GENERIC_NCR5380_OVERRIDE
144 #else
145 [1] __initdata = {{0,},};
146 #endif
148 #define NO_OVERRIDES (sizeof(overrides) / sizeof(struct override))
151 * Function : static internal_setup(int board, char *str, int *ints)
153 * Purpose : LILO command line initialization of the overrides array,
155 * Inputs : board - either BOARD_NCR5380 for a normal NCR5380 board,
156 * or BOARD_NCR53C400 for a NCR53C400 board. str - unused, ints -
157 * array of integer parameters with ints[0] equal to the number of ints.
161 static void __init internal_setup(int board, char *str, int *ints){
162 static int commandline_current = 0;
163 switch (board) {
164 case BOARD_NCR5380:
165 if (ints[0] != 2 && ints[0] != 3) {
166 printk("generic_NCR5380_setup : usage ncr5380=" STRVAL(NCR5380_map_name) ",irq,dma\n");
167 return;
169 case BOARD_NCR53C400:
170 if (ints[0] != 2) {
171 printk("generic_NCR53C400_setup : usage ncr53c400=" STRVAL(NCR5380_map_name) ",irq\n");
172 return;
174 case BOARD_NCR53C400A:
175 if (ints[0] != 2) {
176 printk("generic_NCR53C400A_setup : usage ncr53c400a=" STRVAL(NCR5380_map_name) ",irq\n");
177 return;
179 case BOARD_DTC3181E:
180 if (ints[0] != 2) {
181 printk("generic_DTC3181E_setup : usage dtc3181e=" STRVAL(NCR5380_map_name) ",irq\n");
182 return;
186 if (commandline_current < NO_OVERRIDES) {
187 overrides[commandline_current].NCR5380_map_name = (NCR5380_map_type)ints[1];
188 overrides[commandline_current].irq = ints[2];
189 if (ints[0] == 3)
190 overrides[commandline_current].dma = ints[3];
191 else
192 overrides[commandline_current].dma = DMA_NONE;
193 overrides[commandline_current].board = board;
194 ++commandline_current;
199 * Function : generic_NCR5380_setup (char *str, int *ints)
201 * Purpose : LILO command line initialization of the overrides array,
203 * Inputs : str - unused, ints - array of integer parameters with ints[0]
204 * equal to the number of ints.
207 void __init generic_NCR5380_setup (char *str, int *ints){
208 internal_setup (BOARD_NCR5380, str, ints);
212 * Function : generic_NCR53C400_setup (char *str, int *ints)
214 * Purpose : LILO command line initialization of the overrides array,
216 * Inputs : str - unused, ints - array of integer parameters with ints[0]
217 * equal to the number of ints.
220 void __init generic_NCR53C400_setup (char *str, int *ints){
221 internal_setup (BOARD_NCR53C400, str, ints);
225 * Function : generic_NCR53C400A_setup (char *str, int *ints)
227 * Purpose : LILO command line initialization of the overrides array,
229 * Inputs : str - unused, ints - array of integer parameters with ints[0]
230 * equal to the number of ints.
233 void generic_NCR53C400A_setup (char *str, int *ints) {
234 internal_setup (BOARD_NCR53C400A, str, ints);
238 * Function : generic_DTC3181E_setup (char *str, int *ints)
240 * Purpose : LILO command line initialization of the overrides array,
242 * Inputs : str - unused, ints - array of integer parameters with ints[0]
243 * equal to the number of ints.
246 void generic_DTC3181E_setup (char *str, int *ints) {
247 internal_setup (BOARD_DTC3181E, str, ints);
251 * Function : int generic_NCR5380_detect(Scsi_Host_Template * tpnt)
253 * Purpose : initializes generic NCR5380 driver based on the
254 * command line / compile time port and irq definitions.
256 * Inputs : tpnt - template for this SCSI adapter.
258 * Returns : 1 if a host adapter was found, 0 if not.
262 int __init generic_NCR5380_detect(Scsi_Host_Template * tpnt){
263 static int current_override = 0;
264 int count, i;
265 u_int *ports;
266 u_int ncr_53c400a_ports[] = {0x280, 0x290, 0x300, 0x310, 0x330,
267 0x340, 0x348, 0x350, 0};
268 u_int dtc_3181e_ports[] = {0x220, 0x240, 0x280, 0x2a0, 0x2c0,
269 0x300, 0x320, 0x340, 0};
270 int flags = 0;
271 struct Scsi_Host *instance;
273 if (ncr_irq != NCR_NOT_SET)
274 overrides[0].irq=ncr_irq;
275 if (ncr_dma != NCR_NOT_SET)
276 overrides[0].dma=ncr_dma;
277 if (ncr_addr != NCR_NOT_SET)
278 overrides[0].NCR5380_map_name=(NCR5380_map_type)ncr_addr;
279 if (ncr_5380 != NCR_NOT_SET)
280 overrides[0].board=BOARD_NCR5380;
281 else if (ncr_53c400 != NCR_NOT_SET)
282 overrides[0].board=BOARD_NCR53C400;
283 else if (ncr_53c400a != NCR_NOT_SET)
284 overrides[0].board=BOARD_NCR53C400A;
285 else if (dtc_3181e != NCR_NOT_SET)
286 overrides[0].board=BOARD_DTC3181E;
288 tpnt->proc_dir = &proc_scsi_g_ncr5380;
290 for (count = 0; current_override < NO_OVERRIDES; ++current_override) {
291 if (!(overrides[current_override].NCR5380_map_name))
292 continue;
294 ports = 0;
295 switch (overrides[current_override].board) {
296 case BOARD_NCR5380:
297 flags = FLAG_NO_PSEUDO_DMA;
298 break;
299 case BOARD_NCR53C400:
300 flags = FLAG_NCR53C400;
301 break;
302 case BOARD_NCR53C400A:
303 flags = FLAG_NO_PSEUDO_DMA;
304 ports = ncr_53c400a_ports;
305 break;
306 case BOARD_DTC3181E:
307 flags = FLAG_NO_PSEUDO_DMA | FLAG_DTC3181E;
308 ports = dtc_3181e_ports;
309 break;
312 if (ports) {
313 /* wakeup sequence for the NCR53C400A and DTC3181E*/
315 /* Disable the adapter and look for a free io port */
316 outb(0x59, 0x779);
317 outb(0xb9, 0x379);
318 outb(0xc5, 0x379);
319 outb(0xae, 0x379);
320 outb(0xa6, 0x379);
321 outb(0x00, 0x379);
323 if (overrides[current_override].NCR5380_map_name != PORT_AUTO)
324 for(i=0; ports[i]; i++) {
325 if (overrides[current_override].NCR5380_map_name == ports[i])
326 break;
328 else
329 for(i=0; ports[i]; i++) {
330 if ((!check_region(ports[i], 16)) && (inb(ports[i]) == 0xff))
331 break;
333 if (ports[i]) {
334 outb(0x59, 0x779);
335 outb(0xb9, 0x379);
336 outb(0xc5, 0x379);
337 outb(0xae, 0x379);
338 outb(0xa6, 0x379);
339 outb(0x80 | i, 0x379); /* set io port to be used */
340 outb(0xc0, ports[i] + 9);
341 if (inb(ports[i] + 9) != 0x80)
342 continue;
343 else
344 overrides[current_override].NCR5380_map_name=ports[i];
345 } else
346 continue;
349 request_region(overrides[current_override].NCR5380_map_name,
350 NCR5380_region_size, "ncr5380");
352 instance = scsi_register (tpnt, sizeof(struct NCR5380_hostdata));
353 instance->NCR5380_instance_name = overrides[current_override].NCR5380_map_name;
355 NCR5380_init(instance, flags);
357 if (overrides[current_override].irq != IRQ_AUTO)
358 instance->irq = overrides[current_override].irq;
359 else
360 instance->irq = NCR5380_probe_irq(instance, 0xffff);
362 if (instance->irq != IRQ_NONE)
363 if (request_irq(instance->irq, do_generic_NCR5380_intr, SA_INTERRUPT, "NCR5380", NULL)) {
364 printk("scsi%d : IRQ%d not free, interrupts disabled\n",
365 instance->host_no, instance->irq);
366 instance->irq = IRQ_NONE;
369 if (instance->irq == IRQ_NONE) {
370 printk("scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
371 printk("scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
374 printk("scsi%d : at " STRVAL(NCR5380_map_name) " 0x%x", instance->host_no, (unsigned int)instance->NCR5380_instance_name);
375 if (instance->irq == IRQ_NONE)
376 printk (" interrupts disabled");
377 else
378 printk (" irq %d", instance->irq);
379 printk(" options CAN_QUEUE=%d CMD_PER_LUN=%d release=%d",
380 CAN_QUEUE, CMD_PER_LUN, GENERIC_NCR5380_PUBLIC_RELEASE);
381 NCR5380_print_options(instance);
382 printk("\n");
384 ++current_override;
385 ++count;
387 return count;
390 const char * generic_NCR5380_info (struct Scsi_Host* host) {
391 static const char string[]="Generic NCR5380/53C400 Driver";
392 return string;
395 int generic_NCR5380_release_resources(struct Scsi_Host * instance)
397 NCR5380_local_declare();
399 NCR5380_setup(instance);
401 release_region(instance->NCR5380_instance_name, NCR5380_region_size);
403 if (instance->irq != IRQ_NONE)
404 free_irq(instance->irq, NULL);
406 return 0;
409 #ifdef BIOSPARAM
411 * Function : int generic_NCR5380_biosparam(Disk * disk, kdev_t dev, int *ip)
413 * Purpose : Generates a BIOS / DOS compatible H-C-S mapping for
414 * the specified device / size.
416 * Inputs : size = size of device in sectors (512 bytes), dev = block device
417 * major / minor, ip[] = {heads, sectors, cylinders}
419 * Returns : always 0 (success), initializes ip
424 * XXX Most SCSI boards use this mapping, I could be incorrect. Some one
425 * using hard disks on a trantor should verify that this mapping corresponds
426 * to that used by the BIOS / ASPI driver by running the linux fdisk program
427 * and matching the H_C_S coordinates to what DOS uses.
430 int generic_NCR5380_biosparam(Disk * disk, kdev_t dev, int *ip)
432 int size = disk->capacity;
433 ip[0] = 64;
434 ip[1] = 32;
435 ip[2] = size >> 11;
436 return 0;
438 #endif
440 #if NCR53C400_PSEUDO_DMA
441 static inline int NCR5380_pread (struct Scsi_Host *instance, unsigned char *dst, int len)
443 int blocks = len / 128;
444 int start = 0;
445 int bl;
446 #ifdef CONFIG_SCSI_G_NCR5380_PORT
447 int i;
448 #endif
450 NCR5380_local_declare();
452 NCR5380_setup(instance);
454 #if (NDEBUG & NDEBUG_C400_PREAD)
455 printk("53C400r: About to read %d blocks for %d bytes\n", blocks, len);
456 #endif
458 NCR5380_write(C400_CONTROL_STATUS_REG, CSR_BASE | CSR_TRANS_DIR);
459 NCR5380_write(C400_BLOCK_COUNTER_REG, blocks);
460 while (1) {
462 #if (NDEBUG & NDEBUG_C400_PREAD)
463 printk("53C400r: %d blocks left\n", blocks);
464 #endif
466 if ((bl=NCR5380_read(C400_BLOCK_COUNTER_REG)) == 0) {
467 #if (NDEBUG & NDEBUG_C400_PREAD)
468 if (blocks)
469 printk("53C400r: blocks still == %d\n", blocks);
470 else
471 printk("53C400r: Exiting loop\n");
472 #endif
473 break;
476 #if 1
477 if (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_GATED_53C80_IRQ) {
478 printk("53C400r: Got 53C80_IRQ start=%d, blocks=%d\n", start, blocks);
479 return -1;
481 #endif
483 #if (NDEBUG & NDEBUG_C400_PREAD)
484 printk("53C400r: Waiting for buffer, bl=%d\n", bl);
485 #endif
487 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY)
489 #if (NDEBUG & NDEBUG_C400_PREAD)
490 printk("53C400r: Transferring 128 bytes\n");
491 #endif
493 #ifdef CONFIG_SCSI_G_NCR5380_PORT
494 for (i=0; i<128; i++)
495 dst[start+i] = NCR5380_read(C400_HOST_BUFFER);
496 #else
497 /* implies CONFIG_SCSI_G_NCR5380_MEM */
498 memcpy(dst+start,NCR53C400_host_buffer+NCR5380_map_name,128);
499 #endif
500 start+=128;
501 blocks--;
504 if (blocks) {
505 #if (NDEBUG & NDEBUG_C400_PREAD)
506 printk("53C400r: EXTRA: Waiting for buffer\n");
507 #endif
508 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY)
511 #if (NDEBUG & NDEBUG_C400_PREAD)
512 printk("53C400r: Transferring EXTRA 128 bytes\n");
513 #endif
514 #ifdef CONFIG_SCSI_G_NCR5380_PORT
515 for (i=0; i<128; i++)
516 dst[start+i] = NCR5380_read(C400_HOST_BUFFER);
517 #else
518 /* implies CONFIG_SCSI_G_NCR5380_MEM */
519 memcpy(dst+start,NCR53C400_host_buffer+NCR5380_map_name,128);
520 #endif
521 start+=128;
522 blocks--;
524 #if (NDEBUG & NDEBUG_C400_PREAD)
525 else
526 printk("53C400r: No EXTRA required\n");
527 #endif
529 #if (NDEBUG & NDEBUG_C400_PREAD)
530 printk("53C400r: Final values: blocks=%d start=%d\n", blocks, start);
531 #endif
533 if (!(NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_GATED_53C80_IRQ))
534 printk("53C400r: no 53C80 gated irq after transfer");
535 #if (NDEBUG & NDEBUG_C400_PREAD)
536 else
537 printk("53C400r: Got 53C80 interrupt and tried to clear it\n");
538 #endif
540 /* DON'T DO THIS - THEY NEVER ARRIVE!
541 printk("53C400r: Waiting for 53C80 registers\n");
542 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_53C80_REG)
546 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_END_DMA_TRANSFER))
547 printk("53C400r: no end dma signal\n");
548 #if (NDEBUG & NDEBUG_C400_PREAD)
549 else
550 printk("53C400r: end dma as expected\n");
551 #endif
553 NCR5380_write(MODE_REG, MR_BASE);
554 NCR5380_read(RESET_PARITY_INTERRUPT_REG);
555 return 0;
558 static inline int NCR5380_pwrite (struct Scsi_Host *instance, unsigned char *src, int len)
560 int blocks = len / 128;
561 int start = 0;
562 int i;
563 int bl;
564 NCR5380_local_declare();
566 NCR5380_setup(instance);
568 #if (NDEBUG & NDEBUG_C400_PWRITE)
569 printk("53C400w: About to write %d blocks for %d bytes\n", blocks, len);
570 #endif
572 NCR5380_write(C400_CONTROL_STATUS_REG, CSR_BASE);
573 NCR5380_write(C400_BLOCK_COUNTER_REG, blocks);
574 while (1) {
575 if (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_GATED_53C80_IRQ) {
576 printk("53C400w: Got 53C80_IRQ start=%d, blocks=%d\n", start, blocks);
577 return -1;
580 if ((bl=NCR5380_read(C400_BLOCK_COUNTER_REG)) == 0) {
581 #if (NDEBUG & NDEBUG_C400_PWRITE)
582 if (blocks)
583 printk("53C400w: exiting loop, blocks still == %d\n", blocks);
584 else
585 printk("53C400w: exiting loop\n");
586 #endif
587 break;
590 #if (NDEBUG & NDEBUG_C400_PWRITE)
591 printk("53C400w: %d blocks left\n", blocks);
593 printk("53C400w: waiting for buffer, bl=%d\n", bl);
594 #endif
595 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY)
598 #if (NDEBUG & NDEBUG_C400_PWRITE)
599 printk("53C400w: transferring 128 bytes\n");
600 #endif
601 #ifdef CONFIG_SCSI_G_NCR5380_PORT
602 for (i=0; i<128; i++)
603 NCR5380_write(C400_HOST_BUFFER, src[start+i]);
604 #else
605 /* implies CONFIG_SCSI_G_NCR5380_MEM */
606 memcpy(NCR53C400_host_buffer+NCR5380_map_name,src+start,128);
607 #endif
608 start+=128;
609 blocks--;
611 if (blocks) {
612 #if (NDEBUG & NDEBUG_C400_PWRITE)
613 printk("53C400w: EXTRA waiting for buffer\n");
614 #endif
615 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_HOST_BUF_NOT_RDY)
618 #if (NDEBUG & NDEBUG_C400_PWRITE)
619 printk("53C400w: transferring EXTRA 128 bytes\n");
620 #endif
621 #ifdef CONFIG_SCSI_G_NCR5380_PORT
622 for (i=0; i<128; i++)
623 NCR5380_write(C400_HOST_BUFFER, src[start+i]);
624 #else
625 /* implies CONFIG_SCSI_G_NCR5380_MEM */
626 memcpy(NCR53C400_host_buffer+NCR5380_map_name,src+start,128);
627 #endif
628 start+=128;
629 blocks--;
631 #if (NDEBUG & NDEBUG_C400_PWRITE)
632 else
633 printk("53C400w: No EXTRA required\n");
634 #endif
636 #if (NDEBUG & NDEBUG_C400_PWRITE)
637 printk("53C400w: Final values: blocks=%d start=%d\n", blocks, start);
638 #endif
640 #if 0
641 printk("53C400w: waiting for registers to be available\n");
642 THEY NEVER DO!
643 while (NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_53C80_REG)
645 printk("53C400w: Got em\n");
646 #endif
648 /* Let's wait for this instead - could be ugly */
649 /* All documentation says to check for this. Maybe my hardware is too
650 * fast. Waiting for it seems to work fine! KLL
652 while (!(i = NCR5380_read(C400_CONTROL_STATUS_REG) & CSR_GATED_53C80_IRQ))
656 * I know. i is certainly != 0 here but the loop is new. See previous
657 * comment.
659 if (i) {
660 #if (NDEBUG & NDEBUG_C400_PWRITE)
661 printk("53C400w: got 53C80 gated irq (last block)\n");
662 #endif
663 if (!((i=NCR5380_read(BUS_AND_STATUS_REG)) & BASR_END_DMA_TRANSFER))
664 printk("53C400w: No END OF DMA bit - WHOOPS! BASR=%0x\n",i);
665 #if (NDEBUG & NDEBUG_C400_PWRITE)
666 else
667 printk("53C400w: Got END OF DMA\n");
668 #endif
670 else
671 printk("53C400w: no 53C80 gated irq after transfer (last block)\n");
673 #if 0
674 if (!(NCR5380_read(BUS_AND_STATUS_REG) & BASR_END_DMA_TRANSFER)) {
675 printk("53C400w: no end dma signal\n");
677 #endif
679 #if (NDEBUG & NDEBUG_C400_PWRITE)
680 printk("53C400w: waiting for last byte...\n");
681 #endif
682 while (!(NCR5380_read(TARGET_COMMAND_REG) & TCR_LAST_BYTE_SENT))
685 #if (NDEBUG & NDEBUG_C400_PWRITE)
686 printk("53C400w: got last byte.\n");
687 printk("53C400w: pwrite exiting with status 0, whoopee!\n");
688 #endif
689 return 0;
691 #endif /* PSEUDO_DMA */
693 #include "NCR5380.c"
695 #define PRINTP(x) len += sprintf(buffer+len, x)
696 #define ANDP ,
698 static int sprint_opcode(char* buffer, int len, int opcode) {
699 int start = len;
700 PRINTP("0x%02x " ANDP opcode);
701 return len-start;
704 static int sprint_command (char* buffer, int len, unsigned char *command) {
705 int i,s,start=len;
706 len += sprint_opcode(buffer, len, command[0]);
707 for ( i = 1, s = COMMAND_SIZE(command[0]); i < s; ++i)
708 PRINTP("%02x " ANDP command[i]);
709 PRINTP("\n");
710 return len-start;
713 static int sprint_Scsi_Cmnd (char* buffer, int len, Scsi_Cmnd *cmd) {
714 int start = len;
715 PRINTP("host number %d destination target %d, lun %d\n" ANDP
716 cmd->host->host_no ANDP
717 cmd->target ANDP
718 cmd->lun);
719 PRINTP(" command = ");
720 len += sprint_command (buffer, len, cmd->cmnd);
721 return len-start;
724 int generic_NCR5380_proc_info(char* buffer, char** start, off_t offset, int length, int hostno, int inout)
726 int len = 0;
727 NCR5380_local_declare();
728 unsigned long flags;
729 unsigned char status;
730 int i;
731 struct Scsi_Host *scsi_ptr;
732 Scsi_Cmnd *ptr;
733 struct NCR5380_hostdata *hostdata;
734 #ifdef NCR5380_STATS
735 Scsi_Device *dev;
736 extern const char *const scsi_device_types[MAX_SCSI_DEVICE_CODE];
737 #endif
738 save_flags(flags);
739 cli();
741 for (scsi_ptr = first_instance; scsi_ptr; scsi_ptr=scsi_ptr->next)
742 if (scsi_ptr->host_no == hostno)
743 break;
744 NCR5380_setup(scsi_ptr);
745 hostdata = (struct NCR5380_hostdata *)scsi_ptr->hostdata;
747 PRINTP("SCSI host number %d : %s\n" ANDP scsi_ptr->host_no ANDP scsi_ptr->hostt->name);
748 PRINTP("Generic NCR5380 driver version %d\n" ANDP GENERIC_NCR5380_PUBLIC_RELEASE);
749 PRINTP("NCR5380 core version %d\n" ANDP NCR5380_PUBLIC_RELEASE);
750 #ifdef NCR53C400
751 PRINTP("NCR53C400 extension version %d\n" ANDP NCR53C400_PUBLIC_RELEASE);
752 PRINTP("NCR53C400 card%s detected\n" ANDP (((struct NCR5380_hostdata *)scsi_ptr->hostdata)->flags & FLAG_NCR53C400)?"":" not");
753 # if NCR53C400_PSEUDO_DMA
754 PRINTP("NCR53C400 pseudo DMA used\n");
755 # endif
756 #else
757 PRINTP("NO NCR53C400 driver extensions\n");
758 #endif
759 PRINTP("Using %s mapping at %s 0x%lx, " ANDP STRVAL(NCR5380_map_config) ANDP STRVAL(NCR5380_map_name) ANDP scsi_ptr->NCR5380_instance_name);
760 if (scsi_ptr->irq == IRQ_NONE)
761 PRINTP("no interrupt\n");
762 else
763 PRINTP("on interrupt %d\n" ANDP scsi_ptr->irq);
765 #ifdef NCR5380_STATS
766 if (hostdata->connected || hostdata->issue_queue || hostdata->disconnected_queue)
767 PRINTP("There are commands pending, transfer rates may be crud\n");
768 if (hostdata->pendingr)
769 PRINTP(" %d pending reads" ANDP hostdata->pendingr);
770 if (hostdata->pendingw)
771 PRINTP(" %d pending writes" ANDP hostdata->pendingw);
772 if (hostdata->pendingr || hostdata->pendingw)
773 PRINTP("\n");
774 for (dev = scsi_ptr->host_queue; dev; dev=dev->next) {
775 unsigned long br = hostdata->bytes_read[dev->id];
776 unsigned long bw = hostdata->bytes_write[dev->id];
777 long tr = hostdata->time_read[dev->id] / HZ;
778 long tw = hostdata->time_write[dev->id] / HZ;
780 PRINTP(" T:%d %s " ANDP dev->id ANDP (dev->type < MAX_SCSI_DEVICE_CODE) ? scsi_device_types[(int)dev->type] : "Unknown");
781 for (i=0; i<8; i++)
782 if (dev->vendor[i] >= 0x20)
783 *(buffer+(len++)) = dev->vendor[i];
784 *(buffer+(len++)) = ' ';
785 for (i=0; i<16; i++)
786 if (dev->model[i] >= 0x20)
787 *(buffer+(len++)) = dev->model[i];
788 *(buffer+(len++)) = ' ';
789 for (i=0; i<4; i++)
790 if (dev->rev[i] >= 0x20)
791 *(buffer+(len++)) = dev->rev[i];
792 *(buffer+(len++)) = ' ';
794 PRINTP("\n%10ld kb read in %5ld secs" ANDP br/1024 ANDP tr);
795 if (tr)
796 PRINTP(" @ %5ld bps" ANDP br / tr);
798 PRINTP("\n%10ld kb written in %5ld secs" ANDP bw/1024 ANDP tw);
799 if (tw)
800 PRINTP(" @ %5ld bps" ANDP bw / tw);
801 PRINTP("\n");
803 #endif
805 status = NCR5380_read(STATUS_REG);
806 if (!(status & SR_REQ))
807 PRINTP("REQ not asserted, phase unknown.\n");
808 else {
809 for (i = 0; (phases[i].value != PHASE_UNKNOWN) &&
810 (phases[i].value != (status & PHASE_MASK)); ++i)
812 PRINTP("Phase %s\n" ANDP phases[i].name);
815 if (!hostdata->connected) {
816 PRINTP("No currently connected command\n");
817 } else {
818 len += sprint_Scsi_Cmnd (buffer, len, (Scsi_Cmnd *) hostdata->connected);
821 PRINTP("issue_queue\n");
823 for (ptr = (Scsi_Cmnd *) hostdata->issue_queue; ptr;
824 ptr = (Scsi_Cmnd *) ptr->host_scribble)
825 len += sprint_Scsi_Cmnd (buffer, len, ptr);
827 PRINTP("disconnected_queue\n");
829 for (ptr = (Scsi_Cmnd *) hostdata->disconnected_queue; ptr;
830 ptr = (Scsi_Cmnd *) ptr->host_scribble)
831 len += sprint_Scsi_Cmnd (buffer, len, ptr);
833 *start = buffer + offset;
834 len -= offset;
835 if (len > length)
836 len = length;
837 restore_flags(flags);
838 return len;
841 #undef PRINTP
842 #undef ANDP
844 #ifdef MODULE
845 /* Eventually this will go into an include file, but this will be later */
846 Scsi_Host_Template driver_template = GENERIC_NCR5380;
848 #include <linux/module.h>
849 #include "scsi_module.c"
851 MODULE_PARM(ncr_irq, "i");
852 MODULE_PARM(ncr_dma, "i");
853 MODULE_PARM(ncr_addr, "i");
854 MODULE_PARM(ncr_5380, "i");
855 MODULE_PARM(ncr_53c400, "i");
856 MODULE_PARM(ncr_53c400a, "i");
857 MODULE_PARM(dtc_3181e, "i");
859 #endif