* add p cc
[mascara-docs.git] / i386 / linux / linux-0.99 / drivers / scsi / aha152x.c
blob4939e6f0a75ff350fc2f094d72606f3ee3def983
1 /* aha152x.c -- Adaptec AHA-152x driver
2 * Author: Juergen E. Fischer, fischer@server.et-inf.fho-emden.de
3 * Copyright 1993 Juergen E. Fischer
6 * This driver is based on
7 * fdomain.c -- Future Domain TMC-16x0 driver
8 * which is
9 * Copyright 1992, 1993 Rickard E. Faith (faith@cs.unc.edu)
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2, or (at your option) any
15 * later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
23 * $Id: aha152x.c,v 0.101 1993/12/13 01:16:27 root Exp $
26 * $Log: aha152x.c,v $
27 * Revision 0.101 1993/12/13 01:16:27 root
28 * - fixed STATUS phase (non-GOOD stati were dropped sometimes;
29 * fixes problems with CD-ROM sector size detection & media change)
31 * Revision 0.100 1993/12/10 16:58:47 root
32 * - fix for unsuccessful selections in case of non-continuous id assignments
33 * on the scsi bus.
35 * Revision 0.99 1993/10/24 16:19:59 root
36 * - fixed DATA IN (rare read errors gone)
38 * Revision 0.98 1993/10/17 12:54:44 root
39 * - fixed some recent fixes (shame on me)
40 * - moved initialization of scratch area to aha152x_queue
42 * Revision 0.97 1993/10/09 18:53:53 root
43 * - DATA IN fixed. Rarely left data in the fifo.
45 * Revision 0.96 1993/10/03 00:53:59 root
46 * - minor changes on DATA IN
48 * Revision 0.95 1993/09/24 10:36:01 root
49 * - change handling of MSGI after reselection
50 * - fixed sti/cli
51 * - minor changes
53 * Revision 0.94 1993/09/18 14:08:22 root
54 * - fixed bug in multiple outstanding command code
55 * - changed detection
56 * - support for kernel command line configuration
57 * - reset corrected
58 * - changed message handling
60 * Revision 0.93 1993/09/15 20:41:19 root
61 * - fixed bugs with multiple outstanding commands
63 * Revision 0.92 1993/09/13 02:46:33 root
64 * - multiple outstanding commands work (no problems with IBM drive)
66 * Revision 0.91 1993/09/12 20:51:46 root
67 * added multiple outstanding commands
68 * (some problem with this $%&? IBM device remain)
70 * Revision 0.9 1993/09/12 11:11:22 root
71 * - corrected auto-configuration
72 * - changed the auto-configuration (added some '#define's)
73 * - added support for dis-/reconnection
75 * Revision 0.8 1993/09/06 23:09:39 root
76 * - added support for the drive activity light
77 * - minor changes
79 * Revision 0.7 1993/09/05 14:30:15 root
80 * - improved phase detection
81 * - now using the new snarf_region code of 0.99pl13
83 * Revision 0.6 1993/09/02 11:01:38 root
84 * first public release; added some signatures and biosparam()
86 * Revision 0.5 1993/08/30 10:23:30 root
87 * fixed timing problems with my IBM drive
89 * Revision 0.4 1993/08/29 14:06:52 root
90 * fixed some problems with timeouts due incomplete commands
92 * Revision 0.3 1993/08/28 15:55:03 root
93 * writing data works too. mounted and worked on a dos partition
95 * Revision 0.2 1993/08/27 22:42:07 root
96 * reading data works. Mounted a msdos partition.
98 * Revision 0.1 1993/08/25 13:38:30 root
99 * first "damn thing doesn't work" version
101 * Revision 0.0 1993/08/14 19:54:25 root
102 * empty function bodies; detect() works.
105 **************************************************************************
109 DESCRIPTION:
111 This is the Linux low-level SCSI driver for Adaptec AHA-1520/1522
112 SCSI host adapters.
115 PER-DEFINE CONFIGURABLE OPTIONS:
117 AUTOCONF : use configuration the controller reports (only 152x)
118 IRQ : override interrupt channel (9,10,11 or 12) (default 11)
119 SCSI_ID : override scsiid of AIC-6260 (0-7) (default 7)
120 RECONNECT : override target dis-/reconnection/multiple outstanding commands
121 SKIP_BIOSTEST : Don't test for BIOS signature (AHA-1510 or disabled BIOS)
122 PORTBASE : Force port base. Don't try to probe
125 LILO COMMAND LINE OPTIONS:
127 aha152x=<PORTBASE>,<IRQ>,<SCSI-ID>,<RECONNECT>
129 The normal configuration can be overridden by specifying a command line.
130 When you do this, the BIOS test is skipped. Entered values have to be
131 valid (known). Don't use values that aren't support under normal operation.
132 If you think that you need other value: contact me.
135 REFERENCES USED:
137 "AIC-6260 SCSI Chip Specification", Adaptec Corporation.
139 "SCSI COMPUTER SYSTEM INTERFACE - 2 (SCSI-2)", X3T9.2/86-109 rev. 10h
141 "Writing a SCSI device driver for Linux", Rik Faith (faith@cs.unc.edu)
143 "Kernel Hacker's Guide", Michael K. Johnson (johnsonm@sunsite.unc.edu)
145 "Adaptec 1520/1522 User's Guide", Adaptec Corporation.
147 Michael K. Johnson (johnsonm@sunsite.unc.edu)
149 Drew Eckhardt (drew@cs.colorado.edu)
151 Eric Youngdale (eric@tantalus.nrl.navy.mil)
153 special thanks to Eric Youngdale for the free(!) supplying the
154 documentation on the chip.
156 **************************************************************************/
158 #include "aha152x.h"
160 #include <linux/sched.h>
161 #include <asm/io.h>
162 #include "../block/blk.h"
163 #include "scsi.h"
164 #include "hosts.h"
165 #include "constants.h"
166 #include <asm/system.h>
167 #include <linux/errno.h>
168 #include <linux/string.h>
169 #include <linux/wait.h>
170 #include <linux/ioport.h>
172 /* DEFINES */
175 /* If auto configuration is disabled, IRQ, SCSI_ID and RECONNECT have to
176 be predefined */
177 #if !defined(AUTOCONF)
178 #if !defined(IRQ)
179 #error undefined IRQ; define AUTOCONF or IRQ
180 #endif
181 #if !defined(SCSI_ID)
182 #error undefined SCSI_ID; define AUTOCONF or SCSI_ID
183 #endif
184 #if !defined(RECONNECT)
185 #error undefined RECONNECT; define AUTOCONF or RECONNECT
186 #endif
187 #endif
189 /* I use this when I'm looking for weird bugs */
190 #define DEBUG_TIMING
192 #if defined(DEBUG)
194 #undef SKIP_PORTS /* don't display ports */
196 #undef DEBUG_QUEUE /* debug queue() */
197 #undef DEBUG_RESET /* debug reset() */
198 #undef DEBUG_INTR /* debug intr() */
199 #undef DEBUG_SELECTION /* debug selection part in intr() */
200 #undef DEBUG_MSGO /* debug message out phase in intr() */
201 #undef DEBUG_MSGI /* debug message in phase in intr() */
202 #undef DEBUG_STATUS /* debug status phase in intr() */
203 #undef DEBUG_CMD /* debug command phase in intr() */
204 #undef DEBUG_DATAI /* debug data in phase in intr() */
205 #undef DEBUG_DATAO /* debug data out phase in intr() */
206 #undef DEBUG_ABORT /* debug abort() */
207 #undef DEBUG_DONE /* debug done() */
208 #undef DEBUG_BIOSPARAM /* debug biosparam() */
210 #undef DEBUG_RACE /* debug race conditions */
211 #undef DEBUG_PHASES /* debug phases (useful to trace) */
212 #undef DEBUG_QUEUES /* debug reselection */
214 /* recently used for debugging */
215 #if 0
216 #define DEBUG_PHASES
217 #define DEBUG_DATAI
218 #endif
220 #endif
222 #define DEBUG_RESET /* resets should be rare */
223 #define DEBUG_ABORT /* aborts too */
225 /* END OF DEFINES */
227 /* some additional "phases" for getphase() */
228 #define P_BUSFREE 1
229 #define P_PARITY 2
231 char *aha152x_id = "Adaptec 152x SCSI driver; $Revision: 0.101 $\n";
233 static int port_base = 0;
234 static int this_host = 0;
235 static int can_disconnect = 0;
236 static int commands = 0;
238 /* set by aha152x_setup according to the command line */
239 static int setup_called = 0;
240 static int setup_portbase = 0;
241 static int setup_irq = 0;
242 static int setup_scsiid = 0;
243 static int setup_reconnect = 0;
245 static char *setup_str = (char *)NULL;
247 enum {
248 not_issued = 0x01,
249 in_selection = 0x02,
250 disconnected = 0x04,
251 aborted = 0x08,
252 sent_ident = 0x10,
253 in_other = 0x20,
257 * Command queues:
258 * issue_SC : commands that are queued to be issued
259 * current_SC : command that's currently using the bus
260 * disconnected_SC : commands that that have been disconnected
262 static Scsi_Cmnd *issue_SC = NULL;
263 static Scsi_Cmnd *current_SC = NULL;
264 static Scsi_Cmnd *disconnected_SC = NULL;
266 static struct wait_queue *abortion_complete;
267 static int abort_result;
269 void aha152x_intr( int irqno );
270 void aha152x_done( int error );
271 void aha152x_setup( char *str, int *ints );
273 static void aha152x_reset_ports(void);
274 static void aha152x_panic(char *msg);
276 static void disp_ports(void);
277 static void show_command(Scsi_Cmnd *ptr);
278 static void show_queues(void);
279 static void disp_enintr(void);
281 #if defined(DEBUG_RACE)
282 static void enter_driver(const char *);
283 static void leave_driver(const char *);
284 #endif
286 /* possible locations for the Adaptec BIOS */
287 static void *addresses[] =
289 (void *) 0xdc000, /* default first */
290 (void *) 0xc8000,
291 (void *) 0xcc000,
292 (void *) 0xd0000,
293 (void *) 0xd4000,
294 (void *) 0xd8000,
295 (void *) 0xe0000,
296 (void *) 0xf0000,
298 #define ADDRESS_COUNT (sizeof( addresses ) / sizeof( unsigned ))
300 /* possible i/o adresses for the AIC-6260 */
301 static unsigned short ports[] =
303 0x340, /* default first */
304 0x140
306 #define PORT_COUNT (sizeof( ports ) / sizeof( unsigned short ))
308 /* possible interrupt channels */
309 static unsigned short ints[] = { 9, 10, 11, 12 };
311 /* signatures for various AIC-6260 based controllers */
312 static struct signature {
313 char *signature;
314 int sig_offset;
315 int sig_length;
316 } signatures[] =
319 "Adaptec AHA-1520 BIOS\r\n\0\
320 Version 1.4 \r\n\0\
321 Copyright 1990 Adaptec, Inc.\r\n\
322 All Rights Reserved\r\n \r\n \r\n", 0x102e, 101
323 }, /* Adaptec 152x */
325 "Adaptec ASW-B626 BIOS\r\n\0\
326 Version 1.0 \r\n\0\
327 Copyright 1990 Adaptec, Inc.\r\n\
328 All Rights Reserved\r\n\0 \r\n \r\n", 0x1029, 102
329 }, /* on-board controller */
330 { "Adaptec BIOS: ASW-B626", 0x0F, 22}, /* on-board controller */
331 { "Adaptec ASW-B626 S2 BIOS", 0x2e6c, 24}, /* on-board controller */
333 #define SIGNATURE_COUNT (sizeof( signatures ) / sizeof( struct signature ))
336 static void do_pause( unsigned amount ) /* Pause for amount*10 milliseconds */
338 unsigned long the_time = jiffies + amount; /* 0.01 seconds per jiffy */
340 while (jiffies < the_time)
345 * queue services:
347 static inline void append_SC( Scsi_Cmnd **SC, Scsi_Cmnd *new_SC)
349 Scsi_Cmnd *end;
351 new_SC->host_scribble = (unsigned char *) NULL;
352 if(!*SC)
353 *SC=new_SC;
354 else
356 for( end=*SC;
357 end->host_scribble;
358 end = (Scsi_Cmnd *) end->host_scribble )
360 end->host_scribble = (unsigned char *) new_SC;
364 static inline Scsi_Cmnd *remove_first_SC( Scsi_Cmnd **SC )
366 Scsi_Cmnd *ptr;
368 ptr=*SC;
369 if(ptr)
370 *SC= (Scsi_Cmnd *) (*SC)->host_scribble;
371 return ptr;
374 static inline Scsi_Cmnd *remove_SC( Scsi_Cmnd **SC, int target, int lun )
376 Scsi_Cmnd *ptr, *prev;
378 for( ptr=*SC, prev=NULL;
379 ptr && ((ptr->target!=target) || (ptr->lun!=lun));
380 prev = ptr, ptr = (Scsi_Cmnd *) ptr->host_scribble )
383 if(ptr)
384 if(prev)
385 prev->host_scribble = ptr->host_scribble;
386 else
387 *SC= (Scsi_Cmnd *) ptr->host_scribble;
388 return ptr;
392 * read inbound byte and wait for ACK to get low
394 static void make_acklow(void)
396 SETPORT( SXFRCTL0, CH1|SPIOEN );
397 GETPORT(SCSIDAT);
398 SETPORT( SXFRCTL0, CH1 );
400 while( TESTHI( SCSISIG, ACKI ) )
405 * detect current phase more reliable:
406 * phase is valid, when the target asserts REQ after we've deasserted ACK.
408 * return value is a valid phase or an error code.
410 * errorcodes:
411 * P_BUSFREE BUS FREE phase detected
412 * P_PARITY parity error in DATA phase
414 static int getphase(void)
416 int phase, sstat1;
418 while( 1 )
422 while( !( ( sstat1 = GETPORT( SSTAT1 ) ) & (BUSFREE|SCSIRSTI|REQINIT ) ) )
424 if( sstat1 & BUSFREE )
425 return P_BUSFREE;
426 if( sstat1 & SCSIRSTI )
428 /* IBM drive responds with RSTI to RSTO */
429 printk("aha152x: RESET IN\n");
430 SETPORT( SSTAT1, SCSIRSTI );
433 while( TESTHI( SCSISIG, ACKI ) || TESTLO( SSTAT1, REQINIT ) );
435 SETPORT( SSTAT1, CLRSCSIPERR );
437 phase = GETPORT( SCSISIG ) & P_MASK ;
439 if( TESTHI( SSTAT1, SCSIPERR ) )
441 if( (phase & (CDO|MSGO))==0 ) /* DATA phase */
442 return P_PARITY;
444 make_acklow();
446 else
447 return phase;
451 /* called from init/main.c */
452 void aha152x_setup( char *str, int *ints)
454 if(setup_called)
455 panic("aha152x: aha152x_setup called twice.\n");
457 setup_called=ints[0];
458 setup_str=str;
460 if(ints[0] != 4)
461 return;
463 setup_portbase = ints[1];
464 setup_irq = ints[2];
465 setup_scsiid = ints[3];
466 setup_reconnect = ints[4];
470 Test, if port_base is valid.
472 static int aha152x_porttest(int port_base)
474 int i;
476 if(check_region(port_base, TEST-SCSISEQ))
477 return 0;
479 SETPORT( DMACNTRL1, 0 ); /* reset stack pointer */
480 for(i=0; i<16; i++)
481 SETPORT( STACK, i );
483 SETPORT( DMACNTRL1, 0 ); /* reset stack pointer */
484 for(i=0; i<16 && GETPORT(STACK)==i; i++)
487 return(i==16);
490 int aha152x_detect(int hostno)
492 int i, j, ok;
493 aha152x_config conf;
494 struct sigaction sa;
495 int interrupt_level;
497 #if defined(DEBUG_RACE)
498 enter_driver("detect");
499 #endif
501 printk("aha152x: Probing: ");
503 if(setup_called)
505 printk("processing commandline: ");
507 if(setup_called!=4)
509 printk("\naha152x: %s\n", setup_str );
510 printk("aha152x: usage: aha152x=<PORTBASE>,<IRQ>,<SCSI ID>,<RECONNECT>\n");
511 panic("aha152x panics in line %d", __LINE__);
514 port_base = setup_portbase;
515 interrupt_level = setup_irq;
516 this_host = setup_scsiid;
517 can_disconnect = setup_reconnect;
519 for( i=0; i<PORT_COUNT && (port_base != ports[i]); i++)
522 if(i==PORT_COUNT)
524 printk("unknown portbase 0x%03x\n", port_base);
525 panic("aha152x panics in line %d", __LINE__);
528 if(!aha152x_porttest(port_base))
530 printk("portbase 0x%03x fails probe\n", port_base);
531 panic("aha152x panics in line %d", __LINE__);
534 i=0;
535 while(ints[i] && (interrupt_level!=ints[i]))
536 i++;
537 if(!ints[i])
539 printk("illegal IRQ %d\n", interrupt_level);
540 panic("aha152x panics in line %d", __LINE__);
543 if( (this_host < 0) || (this_host > 7) )
545 printk("illegal SCSI ID %d\n", this_host);
546 panic("aha152x panics in line %d", __LINE__);
549 if( (can_disconnect < 0) || (can_disconnect > 1) )
551 printk("reconnect %d should be 0 or 1\n", can_disconnect);
552 panic("aha152x panics in line %d", __LINE__);
554 printk("ok, ");
556 else
558 #if !defined(SKIP_BIOSTEST)
559 printk("BIOS test: ");
560 ok=0;
561 for( i=0; i < ADDRESS_COUNT && !ok; i++)
562 for( j=0; (j < SIGNATURE_COUNT) && !ok; j++)
563 ok=!memcmp((void *) addresses[i]+signatures[j].sig_offset,
564 (void *) signatures[j].signature,
565 (int) signatures[j].sig_length);
567 if(!ok)
569 #if defined(DEBUG_RACE)
570 leave_driver("(1) detect");
571 #endif
572 printk("failed\n");
573 return 0;
575 printk("ok, ");
576 #endif /* !SKIP_BIOSTEST */
578 #if !defined(PORTBASE)
579 printk("porttest: ");
580 for( i=0; i<PORT_COUNT && !aha152x_porttest(ports[i]); i++)
583 if(i==PORT_COUNT)
585 printk("failed\n");
586 #if defined(DEBUG_RACE)
587 leave_driver("(2) detect");
588 #endif
589 return 0;
591 else
592 port_base=ports[i];
593 printk("ok, ");
594 #else
595 port_base=PORTBASE;
596 #endif /* !PORTBASE */
598 #if defined(AUTOCONF)
600 conf.cf_port = (GETPORT(PORTA)<<8) + GETPORT(PORTB);
602 interrupt_level = ints[conf.cf_irq];
603 this_host = conf.cf_id;
604 can_disconnect = conf.cf_tardisc;
606 printk("auto configuration: ok, ");
608 #endif /* AUTOCONF */
610 #if defined(IRQ)
611 interrupt_level = IRQ;
612 #endif
614 #if defined(SCSI_ID)
615 this_host = SCSI_ID;
616 #endif
618 #if defined(RECONNECT)
619 can_disconnect=RECONNECT;
620 #endif
623 printk("detection complete\n");
625 sa.sa_handler = aha152x_intr;
626 sa.sa_flags = SA_INTERRUPT;
627 sa.sa_mask = 0;
628 sa.sa_restorer = NULL;
630 ok = irqaction( interrupt_level, &sa);
632 if(ok<0)
634 if(ok == -EINVAL)
636 printk("aha152x: bad IRQ %d.\n", interrupt_level);
637 printk(" Contact author.\n");
639 else
640 if( ok == -EBUSY)
641 printk( "aha152x: IRQ %d already in use. Configure another.\n",
642 interrupt_level);
643 else
645 printk( "\naha152x: Unexpected error code on requesting IRQ %d.\n",
646 interrupt_level);
647 printk(" Contact author.\n");
649 panic("aha152x: driver needs an IRQ.\n");
652 SETPORT( SCSIID, this_host << 4 );
653 scsi_hosts[hostno].this_id=this_host;
655 if(can_disconnect)
656 scsi_hosts[hostno].can_queue=AHA152X_MAXQUEUE;
658 /* RESET OUT */
659 SETBITS(SCSISEQ, SCSIRSTO );
660 do_pause(5);
661 CLRBITS(SCSISEQ, SCSIRSTO );
662 do_pause(10);
664 aha152x_reset(NULL);
666 printk("aha152x: vital data: PORTBASE=0x%03x, IRQ=%d, SCSI ID=%d, reconnect=%s, parity=enabled\n",
667 port_base, interrupt_level, this_host, can_disconnect ? "enabled" : "disabled" );
669 snarf_region(port_base, TEST-SCSISEQ); /* Register */
671 /* not expecting any interrupts */
672 SETPORT(SIMODE0, 0);
673 SETPORT(SIMODE1, 0);
675 #if defined(DEBUG_RACE)
676 leave_driver("(3) detect");
677 #endif
679 SETBITS( DMACNTRL0, INTEN);
680 return 1;
684 * return the name of the thing
686 const char *aha152x_info(void)
688 #if defined(DEBUG_RACE)
689 enter_driver("info");
690 leave_driver("info");
691 #else
692 #if defined(DEBUG_INFO)
693 printk("\naha152x: info()\n");
694 #endif
695 #endif
696 return(aha152x_id);
700 * Queue a command and setup interrupts for a free bus.
702 int aha152x_queue( Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *))
704 #if defined(DEBUG_RACE)
705 enter_driver("queue");
706 #else
707 #if defined(DEBUG_QUEUE)
708 printk("aha152x: queue(), ");
709 #endif
710 #endif
713 #if defined(DEBUG_QUEUE)
714 printk( "SCpnt (target = %d lun = %d cmnd = 0x%02x pieces = %d size = %u), ",
715 SCpnt->target,
716 SCpnt->lun,
717 *(unsigned char *)SCpnt->cmnd,
718 SCpnt->use_sg,
719 SCpnt->request_bufflen );
720 disp_ports();
721 #endif
723 SCpnt->scsi_done = done;
725 /* setup scratch area
726 SCp.ptr : buffer pointer
727 SCp.this_residual : buffer length
728 SCp.buffer : next buffer
729 SCp.buffers_residual : left buffers in list
730 SCp.phase : current state of the command */
731 SCpnt->SCp.phase = not_issued;
732 if (SCpnt->use_sg)
734 SCpnt->SCp.buffer = (struct scatterlist *)SCpnt->request_buffer;
735 SCpnt->SCp.ptr = SCpnt->SCp.buffer->address;
736 SCpnt->SCp.this_residual = SCpnt->SCp.buffer->length;
737 SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1;
739 else
741 SCpnt->SCp.ptr = (char *)SCpnt->request_buffer;
742 SCpnt->SCp.this_residual = SCpnt->request_bufflen;
743 SCpnt->SCp.buffer = NULL;
744 SCpnt->SCp.buffers_residual = 0;
747 SCpnt->SCp.Status = CHECK_CONDITION;
748 SCpnt->SCp.Message = 0;
749 SCpnt->SCp.have_data_in = 0;
750 SCpnt->SCp.sent_command = 0;
752 /* Turn led on, when this is the first command. */
753 cli();
754 commands++;
755 if(commands==1)
756 SETPORT( PORTA, 1 );
758 #if defined(DEBUG_QUEUES)
759 printk("i+ (%d), ", commands );
760 #endif
761 append_SC( &issue_SC, SCpnt);
763 /* Enable bus free interrupt, when we aren't currently on the bus */
764 if(!current_SC)
766 SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
767 SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
769 sti();
771 return 0;
775 * We only support command in interrupt-driven fashion
777 int aha152x_command( Scsi_Cmnd *SCpnt )
779 printk( "aha152x: interrupt driven driver; use aha152x_queue()\n" );
780 return -1;
784 * Abort a queued command
785 * (commands that are on the bus can't be aborted easily)
787 int aha152x_abort( Scsi_Cmnd *SCpnt, int code )
789 Scsi_Cmnd *ptr, *prev;
791 cli();
793 #if defined(DEBUG_ABORT)
794 printk("aha152x: abort(), SCpnt=0x%08x, ", (unsigned long) SCpnt );
795 #endif
797 show_queues();
799 /* look for command in issue queue */
800 for( ptr=issue_SC, prev=NULL;
801 ptr && ptr!=SCpnt;
802 prev=ptr, ptr=(Scsi_Cmnd *) ptr->host_scribble)
805 if(ptr)
807 /* dequeue */
808 if(prev)
809 prev->host_scribble = ptr->host_scribble;
810 else
811 issue_SC = (Scsi_Cmnd *) ptr->host_scribble;
812 sti();
814 ptr->host_scribble = NULL;
815 ptr->result = (code ? code : DID_ABORT ) << 16;
816 ptr->done(ptr);
817 return 0;
820 /* Fail abortion, if we're on the bus */
821 if (current_SC)
823 sti();
824 return -1;
827 /* look for command in disconnected queue */
828 for( ptr=disconnected_SC, prev=NULL;
829 ptr && ptr!=SCpnt;
830 prev=ptr, ptr=(Scsi_Cmnd *) ptr->host_scribble)
833 if(ptr && TESTLO(SSTAT1, BUSFREE) )
834 printk("bus busy but no current command, ");
836 if(ptr && TESTHI(SSTAT1, BUSFREE) )
838 /* dequeue */
839 if(prev)
840 prev->host_scribble = ptr->host_scribble;
841 else
842 issue_SC = (Scsi_Cmnd *) ptr->host_scribble;
844 /* set command current and initiate selection,
845 let the interrupt routine take care of the abortion */
846 current_SC = ptr;
847 ptr->SCp.phase = in_selection|aborted;
848 SETPORT( SCSIID, (this_host << OID_) | current_SC->target );
850 /* enable interrupts for SELECTION OUT DONE and SELECTION TIME OUT */
851 SETPORT( SIMODE0, ENSELDO | (disconnected_SC ? ENSELDI : 0) );
852 SETPORT( SIMODE1, ENSELTIMO );
854 /* Enable SELECTION OUT sequence */
855 SETBITS(SCSISEQ, ENSELO | ENAUTOATNO );
857 SETBITS( DMACNTRL0, INTEN );
858 abort_result=0;
859 sti();
861 /* sleep until the abortion is complete */
862 sleep_on( &abortion_complete );
863 return abort_result;
865 else
866 printk("aha152x: bus busy but no current command\n");
868 /* command wasn't found */
869 sti();
870 return 0;
874 * Restore default values to the AIC-6260 registers and reset the fifos
876 static void aha152x_reset_ports(void)
878 /* disable interrupts */
879 SETPORT(DMACNTRL0, RSTFIFO);
881 SETPORT(SCSISEQ, 0);
883 SETPORT(SXFRCTL1, 0);
884 SETPORT( SCSISIG, 0);
885 SETPORT(SCSIRATE, 0);
887 /* clear all interrupt conditions */
888 SETPORT(SSTAT0, 0x7f);
889 SETPORT(SSTAT1, 0xef);
891 SETPORT(SSTAT4, SYNCERR|FWERR|FRERR);
893 SETPORT(DMACNTRL0, 0);
894 SETPORT(DMACNTRL1, 0);
896 SETPORT(BRSTCNTRL, 0xf1);
898 /* clear SCSI fifo and transfer count */
899 SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
900 SETPORT(SXFRCTL0, CH1);
902 /* enable interrupts */
903 SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
904 SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
908 * Reset registers, reset a hanging bus and
909 * kill active and disconnected commands
911 int aha152x_reset(Scsi_Cmnd * __unused)
913 Scsi_Cmnd *ptr;
915 aha152x_reset_ports();
917 /* Reset, if bus hangs */
918 if( TESTLO( SSTAT1, BUSFREE ) )
920 CLRBITS( DMACNTRL0, INTEN );
922 #if defined( DEBUG_RESET )
923 printk("aha152x: reset(), bus not free: SCSI RESET OUT\n");
924 #endif
926 show_queues();
928 if(current_SC)
930 current_SC->host_scribble = NULL;
931 current_SC->result = DID_RESET << 16;
932 current_SC->done(current_SC);
933 current_SC=NULL;
936 while(disconnected_SC)
938 ptr = disconnected_SC;
939 disconnected_SC = (Scsi_Cmnd *) ptr->host_scribble;
940 ptr->host_scribble = NULL;
941 ptr->result = DID_RESET << 16;
942 ptr->done(ptr);
945 /* RESET OUT */
946 SETPORT(SCSISEQ, SCSIRSTO);
947 do_pause(5);
948 SETPORT(SCSISEQ, 0);
949 do_pause(10);
951 SETPORT(SIMODE0, 0 );
952 SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
954 SETPORT( DMACNTRL0, INTEN );
957 return 0;
961 * Return the "logical geometry"
963 int aha152x_biosparam( int size, int dev, int *info_array )
965 #if defined(DEBUG_RACE)
966 enter_driver("biosparam");
967 #else
968 #if defined(DEBUG_BIOSPARAM)
969 printk("\naha152x: biosparam(), ");
970 #endif
971 #endif
973 #if defined(DEBUG_BIOSPARAM)
974 printk("dev=%x, size=%d, ", dev, size);
975 #endif
977 /* I took this from other SCSI drivers, since it provides
978 the correct data for my devices. */
979 info_array[0]=64;
980 info_array[1]=32;
981 info_array[2]=size>>11;
983 #if defined(DEBUG_BIOSPARAM)
984 printk("bios geometry: head=%d, sec=%d, cyl=%d\n",
985 info_array[0], info_array[1], info_array[2]);
986 printk("WARNING: check, if the bios geometry is correct.\n");
987 #endif
989 #if defined(DEBUG_RACE)
990 leave_driver("biosparam");
991 #endif
992 return 0;
996 * Internal done function
998 void aha152x_done( int error )
1000 Scsi_Cmnd *done_SC;
1002 #if defined(DEBUG_DONE)
1003 printk("\naha152x: done(), ");
1004 disp_ports();
1005 #endif
1007 if (current_SC)
1009 #if defined(DEBUG_DONE)
1010 printk("done(%x), ", error);
1011 #endif
1013 cli();
1015 done_SC = current_SC;
1016 current_SC = NULL;
1018 /* turn led off, when no commands are in the driver */
1019 commands--;
1020 if(!commands)
1021 SETPORT( PORTA, 0 ); /* turn led off */
1023 #if defined(DEBUG_QUEUES)
1024 printk("ok (%d), ", commands);
1025 #endif
1026 sti();
1028 SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
1029 SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
1031 #if defined(DEBUG_PHASES)
1032 printk("BUS FREE loop, ");
1033 #endif
1034 while( TESTLO( SSTAT1, BUSFREE ) )
1036 #if defined(DEBUG_PHASES)
1037 printk("BUS FREE\n");
1038 #endif
1040 done_SC->result = error;
1041 if(done_SC->scsi_done)
1043 #if defined(DEBUG_DONE)
1044 printk("calling scsi_done, ");
1045 #endif
1046 done_SC->scsi_done( done_SC );
1047 #if defined(DEBUG_DONE)
1048 printk("done returned, ");
1049 #endif
1051 else
1052 panic( "aha152x: current_SC->scsi_done() == NULL" );
1054 else
1055 aha152x_panic( "done() called outside of command" );
1059 * Interrupts handler (main routine of the driver)
1061 void aha152x_intr( int irqno )
1063 int done=0, phase;
1065 #if defined(DEBUG_RACE)
1066 enter_driver("intr");
1067 #else
1068 #if defined(DEBUG_INTR)
1069 printk("\naha152x: intr(), ");
1070 #endif
1071 #endif
1073 /* no more interrupts from the controller, while we busy.
1074 INTEN has to be restored, when we're ready to leave
1075 intr(). To avoid race conditions we have to return
1076 immediately afterwards. */
1077 CLRBITS( DMACNTRL0, INTEN);
1078 sti();
1080 /* disconnected target is trying to reconnect.
1081 Only possible, if we have disconnected nexuses and
1082 nothing is occuping the bus.
1084 if( TESTHI( SSTAT0, SELDI ) &&
1085 disconnected_SC &&
1086 ( !current_SC || ( current_SC->SCp.phase & in_selection ) )
1089 int identify_msg, target, i;
1091 /* Avoid conflicts when a target reconnects
1092 while we are trying to connect to another. */
1093 if(current_SC)
1095 #if defined(DEBUG_QUEUES)
1096 printk("i+, ");
1097 #endif
1098 cli();
1099 append_SC( &issue_SC, current_SC);
1100 current_SC=NULL;
1101 sti();
1104 /* disable sequences */
1105 SETPORT( SCSISEQ, 0 );
1106 SETPORT( SSTAT0, CLRSELDI );
1107 SETPORT( SSTAT1, CLRBUSFREE );
1109 #if defined(DEBUG_QUEUES) || defined(DEBUG_PHASES)
1110 printk("reselected, ");
1111 #endif
1113 i = GETPORT(SELID) & ~(1 << this_host);
1114 target=0;
1115 if(i)
1116 for( ; (i & 1)==0; target++, i>>=1)
1118 else
1119 aha152x_panic("reconnecting target unknown");
1121 #if defined(DEBUG_QUEUES)
1122 printk("SELID=%02x, target=%d, ", GETPORT(SELID), target );
1123 #endif
1124 SETPORT( SCSIID, (this_host << OID_) | target );
1125 SETPORT( SCSISEQ, ENRESELI );
1127 if(TESTLO( SSTAT0, SELDI ))
1128 aha152x_panic("RESELI failed");
1130 SETPORT( SCSISIG, P_MSGI );
1132 /* Get identify message */
1133 if((i=getphase())!=P_MSGI)
1135 printk("target doesn't enter MSGI to identify (phase=%02x)\n", i);
1136 aha152x_panic("unknown lun");
1138 SETPORT( SCSISEQ, 0 );
1140 SETPORT( SXFRCTL0, CH1);
1142 identify_msg = GETPORT(SCSIBUS);
1144 if(!(identify_msg & IDENTIFY_BASE))
1146 printk("target=%d, inbound message (%02x) != IDENTIFY\n",
1147 target, identify_msg);
1148 aha152x_panic("unknown lun");
1151 make_acklow();
1152 getphase();
1154 #if defined(DEBUG_QUEUES)
1155 printk("identify=%02x, lun=%d, ", identify_msg, identify_msg & 0x3f );
1156 #endif
1158 cli();
1159 #if defined(DEBUG_QUEUES)
1160 printk("d-, ");
1161 #endif
1162 current_SC = remove_SC( &disconnected_SC,
1163 target,
1164 identify_msg & 0x3f );
1166 if(!current_SC)
1168 printk("lun=%d, ", identify_msg & 0x3f );
1169 aha152x_panic("no disconnected command for that lun");
1172 current_SC->SCp.phase &= ~disconnected;
1173 sti();
1175 SETPORT( SIMODE0, 0 );
1176 SETPORT( SIMODE1, ENPHASEMIS );
1177 #if defined(DEBUG_RACE)
1178 leave_driver("(reselected) intr");
1179 #endif
1180 SETBITS( DMACNTRL0, INTEN);
1181 return;
1184 /* Check, if we aren't busy with a command */
1185 if(!current_SC)
1187 /* bus is free to issue a queued command */
1188 if(TESTHI( SSTAT1, BUSFREE) && issue_SC)
1190 cli();
1191 #if defined(DEBUG_QUEUES)
1192 printk("i-, ");
1193 #endif
1194 current_SC = remove_first_SC( &issue_SC );
1195 sti();
1197 #if defined(DEBUG_INTR) || defined(DEBUG_SELECTION) || defined(DEBUG_PHASES)
1198 printk("issueing command, ");
1199 #endif
1200 current_SC->SCp.phase = in_selection;
1202 #if defined(DEBUG_INTR) || defined(DEBUG_SELECTION) || defined(DEBUG_PHASES)
1203 printk("selecting %d, ", current_SC->target);
1204 #endif
1205 SETPORT( SCSIID, (this_host << OID_) | current_SC->target );
1207 /* Enable interrupts for SELECTION OUT DONE and SELECTION OUT INITIATED */
1208 SETPORT( SXFRCTL1, ENSPCHK|ENSTIMER);
1210 /* enable interrupts for SELECTION OUT DONE and SELECTION TIME OUT */
1211 SETPORT( SIMODE0, ENSELDO | (disconnected_SC ? ENSELDI : 0) );
1212 SETPORT( SIMODE1, ENSELTIMO );
1214 /* Enable SELECTION OUT sequence */
1215 SETBITS(SCSISEQ, ENSELO | ENAUTOATNO );
1217 #if defined(DEBUG_RACE)
1218 leave_driver("(selecting) intr");
1219 #endif
1220 SETBITS( DMACNTRL0, INTEN );
1221 return;
1224 /* No command we are busy with and no new to issue */
1225 printk("aha152x: ignoring spurious interrupt, nothing to do\n");
1226 return;
1229 /* the bus is busy with something */
1231 #if defined(DEBUG_INTR)
1232 disp_ports();
1233 #endif
1235 /* we are waiting for the result of a selection attempt */
1236 if(current_SC->SCp.phase & in_selection)
1238 if( TESTLO( SSTAT1, SELTO ) )
1239 /* no timeout */
1240 if( TESTHI( SSTAT0, SELDO ) )
1242 /* clear BUS FREE interrupt */
1243 SETPORT( SSTAT1, CLRBUSFREE);
1245 /* Disable SELECTION OUT sequence */
1246 CLRBITS(SCSISEQ, ENSELO|ENAUTOATNO );
1248 /* Disable SELECTION OUT DONE interrupt */
1249 CLRBITS(SIMODE0, ENSELDO);
1250 CLRBITS(SIMODE1, ENSELTIMO);
1252 if( TESTLO(SSTAT0, SELDO) )
1254 printk("aha152x: passing bus free condition\n");
1256 #if defined(DEBUG_RACE)
1257 leave_driver("(passing bus free) intr");
1258 #endif
1259 SETBITS( DMACNTRL0, INTEN);
1261 if(current_SC->SCp.phase & aborted)
1263 abort_result=1;
1264 wake_up( &abortion_complete );
1267 aha152x_done( DID_NO_CONNECT << 16 );
1268 return;
1270 #if defined(DEBUG_SELECTION) || defined(DEBUG_PHASES)
1271 printk("SELDO (SELID=%x), ", GETPORT(SELID));
1272 #endif
1274 /* selection was done */
1275 SETPORT( SSTAT0, CLRSELDO );
1277 #if defined(DEBUG_ABORT)
1278 if(current_SC->SCp.phase & aborted)
1279 printk("(ABORT) target selected, ");
1280 #endif
1282 current_SC->SCp.phase &= ~in_selection;
1283 current_SC->SCp.phase |= in_other;
1285 #if defined(DEBUG_RACE)
1286 leave_driver("(SELDO) intr");
1287 #endif
1289 SETPORT( SCSISIG, P_MSGO );
1291 SETPORT( SIMODE0, 0 );
1292 SETPORT( SIMODE1, ENREQINIT );
1293 SETBITS( DMACNTRL0, INTEN);
1294 return;
1296 else
1297 aha152x_panic("neither timeout nor selection\007");
1298 else
1300 #if defined(DEBUG_SELECTION) || defined(DEBUG_PHASES)
1301 printk("SELTO, ");
1302 #endif
1303 /* end selection attempt */
1304 CLRBITS(SCSISEQ, ENSELO|ENAUTOATNO );
1306 /* timeout */
1307 SETPORT( SSTAT1, CLRSELTIMO );
1309 SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
1310 SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
1311 SETBITS( DMACNTRL0, INTEN );
1312 #if defined(DEBUG_RACE)
1313 leave_driver("(SELTO) intr");
1314 #endif
1316 if(current_SC->SCp.phase & aborted)
1318 #if defined(DEBUG_ABORT)
1319 printk("(ABORT) selection timeout, ");
1320 #endif
1321 abort_result=1;
1322 wake_up( &abortion_complete );
1325 if( TESTLO( SSTAT0, SELINGO ) )
1326 /* ARBITRATION not won */
1327 aha152x_done( DID_BUS_BUSY << 16 );
1328 else
1329 /* ARBITRATION won, but SELECTION failed */
1330 aha152x_done( DID_NO_CONNECT << 16 );
1331 return;
1335 /* enable interrupt, when target leaves current phase */
1336 phase = getphase();
1337 if(!(phase & ~P_MASK)) /* "real" phase */
1338 SETPORT(SCSISIG, phase);
1339 SETPORT(SSTAT1, CLRPHASECHG);
1340 current_SC->SCp.phase =
1341 (current_SC->SCp.phase & ~((P_MASK|1)<<16)) | (phase << 16 );
1343 /* information transfer phase */
1344 switch( phase )
1346 case P_MSGO: /* MESSAGE OUT */
1348 unsigned char message;
1350 #if defined(DEBUG_INTR) || defined(DEBUG_MSGO) || defined(DEBUG_PHASES)
1351 printk("MESSAGE OUT, ");
1352 #endif
1354 if( current_SC->SCp.phase & aborted )
1356 #if defined(DEBUG_MSGO) || defined(DEBUG_ABORT)
1357 printk("ABORT, ");
1358 #endif
1359 message=ABORT;
1361 else
1362 /* If we didn't identify yet, do it. Otherwise there's nothing to do,
1363 but reject (probably we got an message before, that we have to
1364 reject (SDTR, WDTR, etc.) */
1365 if( !(current_SC->SCp.phase & sent_ident))
1367 message=IDENTIFY(can_disconnect,current_SC->lun);
1368 #if defined(DEBUG_MSGO)
1369 printk("IDENTIFY (reconnect=%s;lun=%d), ",
1370 can_disconnect ? "enabled" : "disabled", current_SC->lun);
1371 #endif
1373 else
1375 message=MESSAGE_REJECT;
1376 #if defined(DEBUG_MSGO)
1377 printk("REJECT, ");
1378 #endif
1381 CLRBITS( SXFRCTL0, ENDMA);
1383 SETPORT( SIMODE0, 0 );
1384 SETPORT( SIMODE1, ENPHASEMIS|ENREQINIT );
1386 /* wait for data latch to become ready or a phase change */
1387 while( TESTLO( DMASTAT, INTSTAT ) )
1390 if( TESTHI( SSTAT1, PHASEMIS ) )
1391 aha152x_panic("unable to send message");
1393 /* Leave MESSAGE OUT after transfer */
1394 SETPORT( SSTAT1, CLRATNO);
1396 SETPORT( SCSIDAT, message );
1398 make_acklow();
1399 getphase();
1401 if(message==IDENTIFY(can_disconnect,current_SC->lun))
1402 current_SC->SCp.phase |= sent_ident;
1404 if(message==ABORT)
1406 /* revive abort(); abort() enables interrupts */
1407 abort_result=0;
1408 wake_up( &abortion_complete );
1410 current_SC->SCp.phase = (current_SC->SCp.phase & ~(P_MASK<<16));
1412 /* exit */
1413 SETBITS( DMACNTRL0, INTEN );
1414 #if defined(DEBUG_RACE)
1415 leave_driver("(ABORT) intr");
1416 #endif
1417 aha152x_done(DID_ABORT<<16);
1418 return;
1421 break;
1423 case P_CMD: /* COMMAND phase */
1424 #if defined(DEBUG_INTR) || defined(DEBUG_CMD) || defined(DEBUG_PHASES)
1425 printk("COMMAND, ");
1426 #endif
1427 if( !(current_SC->SCp.sent_command) )
1429 if(GETPORT(FIFOSTAT) || GETPORT(SSTAT2) & (SFULL|SFCNT))
1430 printk("aha152x: P_CMD: %d(%d) bytes left in FIFO, resetting\n",
1431 GETPORT(FIFOSTAT), GETPORT(SSTAT2) & (SFULL|SFCNT));
1433 /* reset fifo and enable writes */
1434 SETPORT(DMACNTRL0, WRITE_READ|RSTFIFO);
1435 SETPORT(DMACNTRL0, ENDMA|WRITE_READ);
1437 /* clear transfer count and scsi fifo */
1438 SETPORT(SXFRCTL0, CH1|CLRSTCNT|CLRCH1 );
1439 SETPORT(SXFRCTL0, SCSIEN|DMAEN|CH1);
1441 /* missing phase raises INTSTAT */
1442 SETPORT( SIMODE0, 0 );
1443 SETPORT( SIMODE1, ENPHASEMIS );
1445 #if defined(DEBUG_CMD)
1446 printk("waiting, ");
1447 #endif
1448 /* wait for FIFO to get empty */
1449 while( TESTLO ( DMASTAT, DFIFOEMP|INTSTAT ) )
1452 if( TESTHI( SSTAT1, PHASEMIS ) )
1453 aha152x_panic("target left COMMAND phase");
1455 #if defined(DEBUG_CMD)
1456 printk("DFIFOEMP, outsw (%d words), ",
1457 COMMAND_SIZE(current_SC->cmnd[0])>>1);
1458 disp_ports();
1459 #endif
1461 outsw( DATAPORT,
1462 &current_SC->cmnd,
1463 COMMAND_SIZE(current_SC->cmnd[0])>>1 );
1465 #if defined(DEBUG_CMD)
1466 printk("FCNT=%d, STCNT=%d, ", GETPORT(FIFOSTAT), GETSTCNT() );
1467 disp_ports();
1468 #endif
1470 /* wait for SCSI FIFO to get empty.
1471 very important to send complete commands. */
1472 while( TESTLO ( SSTAT2, SEMPTY ) )
1475 CLRBITS(SXFRCTL0, SCSIEN|DMAEN);
1476 /* transfer can be considered ended, when SCSIEN reads back zero */
1477 while( TESTHI( SXFRCTL0, SCSIEN ) )
1480 CLRBITS(DMACNTRL0, ENDMA);
1482 #if defined(DEBUG_CMD) || defined(DEBUG_INTR)
1483 printk("sent %d/%d command bytes, ", GETSTCNT(),
1484 COMMAND_SIZE(current_SC->cmnd[0]));
1485 #endif
1488 else
1489 aha152x_panic("Nothing to sent while in COMMAND OUT");
1490 break;
1492 case P_MSGI: /* MESSAGE IN phase */
1493 #if defined(DEBUG_INTR) || defined(DEBUG_MSGI) || defined(DEBUG_PHASES)
1494 printk("MESSAGE IN, ");
1495 #endif
1496 SETPORT( SXFRCTL0, CH1);
1498 SETPORT( SIMODE0, 0);
1499 SETPORT( SIMODE1, ENBUSFREE);
1501 while( phase == P_MSGI )
1503 current_SC->SCp.Message = GETPORT( SCSIBUS );
1504 switch(current_SC->SCp.Message)
1506 case DISCONNECT:
1507 #if defined(DEBUG_MSGI) || defined(DEBUG_PHASES)
1508 printk("target disconnected, ");
1509 #endif
1510 current_SC->SCp.Message = 0;
1511 current_SC->SCp.phase |= disconnected;
1512 if(!can_disconnect)
1513 aha152x_panic("target was not allowed to disconnect");
1514 break;
1516 case COMMAND_COMPLETE:
1517 #if defined(DEBUG_MSGI) || defined(DEBUG_PHASES)
1518 printk("inbound message ( COMMAND COMPLETE ), ");
1519 #endif
1520 done++;
1521 break;
1523 case MESSAGE_REJECT:
1524 #if defined(DEBUG_MSGI) || defined(DEBUG_TIMING)
1525 printk("inbound message ( MESSAGE REJECT ), ");
1526 #endif
1527 break;
1529 case SAVE_POINTERS:
1530 #if defined(DEBUG_MSGI)
1531 printk("inbound message ( SAVE DATA POINTERS ), ");
1532 #endif
1533 break;
1535 case EXTENDED_MESSAGE:
1537 int i, code;
1539 #if defined(DEBUG_MSGI)
1540 printk("inbound message ( EXTENDED MESSAGE ), ");
1541 #endif
1542 make_acklow();
1543 if(getphase()!=P_MSGI)
1544 break;
1546 i=GETPORT(SCSIBUS);
1548 #if defined(DEBUG_MSGI)
1549 printk("length (%d), ", i);
1550 #endif
1552 #if defined(DEBUG_MSGI)
1553 printk("code ( ");
1554 #endif
1556 make_acklow();
1557 if(getphase()!=P_MSGI)
1558 break;
1560 code = GETPORT(SCSIBUS);
1562 switch( code )
1564 case 0x00:
1565 #if defined(DEBUG_MSGI)
1566 printk("MODIFY DATA POINTER ");
1567 #endif
1568 SETPORT(SCSISIG, P_MSGI|ATNO);
1569 break;
1570 case 0x01:
1571 #if defined(DEBUG_MSGI)
1572 printk("SYNCHRONOUS DATA TRANSFER REQUEST ");
1573 #endif
1574 SETPORT(SCSISIG, P_MSGI|ATNO);
1575 break;
1576 case 0x02:
1577 #if defined(DEBUG_MSGI)
1578 printk("EXTENDED IDENTIFY ");
1579 #endif
1580 break;
1581 case 0x03:
1582 #if defined(DEBUG_MSGI)
1583 printk("WIDE DATA TRANSFER REQUEST ");
1584 #endif
1585 SETPORT(SCSISIG, P_MSGI|ATNO);
1586 break;
1587 default:
1588 #if defined(DEBUG_MSGI)
1589 if( code & 0x80 )
1590 printk("reserved (%d) ", code );
1591 else
1592 printk("vendor specific (%d) ", code);
1593 #endif
1594 SETPORT(SCSISIG, P_MSGI|ATNO);
1595 break;
1597 #if defined(DEBUG_MSGI)
1598 printk(" ), data ( ");
1599 #endif
1600 while( --i && (make_acklow(), getphase()==P_MSGI))
1602 #if defined(DEBUG_MSGI)
1603 printk("%x ", GETPORT(SCSIBUS) );
1604 #else
1605 GETPORT(SCSIBUS);
1606 #endif
1608 #if defined(DEBUG_MSGI)
1609 printk(" ), ");
1610 #endif
1611 /* We reject all extended messages. To do this
1612 we just enter MSGO by asserting ATN. Since
1613 we have already identified a REJECT message
1614 will be sent. */
1615 SETPORT(SCSISIG, P_MSGI|ATNO);
1617 break;
1619 default:
1620 printk("unsupported inbound message %x, ", current_SC->SCp.Message);
1621 break;
1625 make_acklow();
1626 phase=getphase();
1629 /* clear SCSI fifo on BUSFREE */
1630 if(phase==P_BUSFREE)
1631 SETPORT(SXFRCTL0, CH1|CLRCH1);
1633 if(current_SC->SCp.phase & disconnected)
1635 cli();
1636 #if defined(DEBUG_QUEUES)
1637 printk("d+, ");
1638 #endif
1639 append_SC( &disconnected_SC, current_SC);
1640 current_SC = NULL;
1641 sti();
1643 SETBITS( SCSISEQ, ENRESELI );
1645 SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
1646 SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
1648 SETBITS( DMACNTRL0, INTEN );
1649 return;
1651 break;
1653 case P_STATUS: /* STATUS IN phase */
1654 #if defined(DEBUG_STATUS) || defined(DEBUG_INTR) || defined(DEBUG_PHASES)
1655 printk("STATUS, ");
1656 #endif
1657 SETPORT( SXFRCTL0, CH1);
1659 SETPORT( SIMODE0, 0 );
1660 SETPORT( SIMODE1, ENREQINIT );
1662 if( TESTHI( SSTAT1, PHASEMIS ) )
1663 printk("aha152x: passing STATUS phase");
1665 current_SC->SCp.Status = GETPORT( SCSIBUS );
1666 make_acklow();
1667 getphase();
1669 #if defined(DEBUG_STATUS)
1670 printk("inbound status ");
1671 print_status( current_SC->SCp.Status );
1672 printk(", ");
1673 #endif
1674 break;
1676 case P_DATAI: /* DATA IN phase */
1678 int fifodata, data_count, done;
1680 #if defined(DEBUG_DATAI) || defined(DEBUG_INTR) || defined(DEBUG_PHASES)
1681 printk("DATA IN, ");
1682 #endif
1684 if(GETPORT(FIFOSTAT) || GETPORT(SSTAT2) & (SFULL|SFCNT))
1685 printk("aha152x: P_DATAI: %d(%d) bytes left in FIFO, resetting\n",
1686 GETPORT(FIFOSTAT), GETPORT(SSTAT2) & (SFULL|SFCNT));
1688 /* reset host fifo */
1689 SETPORT(DMACNTRL0, RSTFIFO);
1690 SETPORT(DMACNTRL0, RSTFIFO|ENDMA);
1692 SETPORT(SXFRCTL0, CH1|SCSIEN|DMAEN );
1694 SETPORT( SIMODE0, 0 );
1695 SETPORT( SIMODE1, ENPHASEMIS|ENBUSFREE );
1697 /* done is set when the FIFO is empty after the target left DATA IN */
1698 done=0;
1700 /* while the target stays in DATA to transfer data */
1701 while ( !done )
1703 #if defined(DEBUG_DATAI)
1704 printk("expecting data, ");
1705 #endif
1706 /* wait for PHASEMIS or full FIFO */
1707 while( TESTLO ( DMASTAT, DFIFOFULL|INTSTAT ) )
1710 if( TESTHI( DMASTAT, DFIFOFULL ) )
1711 fifodata=132;
1712 else
1714 /* wait for SCSI fifo to get empty */
1715 while( TESTLO( SSTAT2, SEMPTY ) )
1718 /* rest of data in FIFO */
1719 fifodata=GETPORT(FIFOSTAT);
1720 #if defined(DEBUG_DATAI)
1721 printk("last transfer, ");
1722 #endif
1723 done=1;
1726 #if defined(DEBUG_DATAI)
1727 printk("fifodata=%d, ", fifodata);
1728 #endif
1730 while( fifodata && current_SC->SCp.this_residual )
1732 data_count=fifodata;
1734 /* limit data transfer to size of first sg buffer */
1735 if (data_count > current_SC->SCp.this_residual)
1736 data_count = current_SC->SCp.this_residual;
1738 fifodata -= data_count;
1740 #if defined(DEBUG_DATAI)
1741 printk("data_count=%d, ", data_count);
1742 #endif
1744 if(data_count == 1)
1746 /* get a single byte in byte mode */
1747 SETBITS(DMACNTRL0, _8BIT );
1748 *current_SC->SCp.ptr++ = GETPORT( DATAPORT );
1749 current_SC->SCp.this_residual--;
1751 else
1753 CLRBITS(DMACNTRL0, _8BIT );
1754 data_count >>= 1; /* Number of words */
1755 insw( DATAPORT, current_SC->SCp.ptr, data_count );
1756 #if defined(DEBUG_DATAI)
1757 /* show what comes with the last transfer */
1758 if(done)
1760 int i;
1761 unsigned char *data;
1763 printk("data on last transfer (%d bytes: ",
1764 2*data_count);
1765 data = (unsigned char *) current_SC->SCp.ptr;
1766 for( i=0; i<2*data_count; i++)
1767 printk("%2x ", *data++);
1768 printk("), ");
1770 #endif
1771 current_SC->SCp.ptr += 2 * data_count;
1772 current_SC->SCp.this_residual -= 2 * data_count;
1775 /* if this buffer is full and there are more buffers left */
1776 if (!current_SC->SCp.this_residual &&
1777 current_SC->SCp.buffers_residual)
1779 /* advance to next buffer */
1780 current_SC->SCp.buffers_residual--;
1781 current_SC->SCp.buffer++;
1782 current_SC->SCp.ptr =
1783 current_SC->SCp.buffer->address;
1784 current_SC->SCp.this_residual =
1785 current_SC->SCp.buffer->length;
1789 /* rare (but possible) status bytes (probably also DISCONNECT
1790 messages) get transfered in the data phase, so I assume 1
1791 additional byte is ok */
1792 if(fifodata>1)
1794 printk("aha152x: more data than expected (%d bytes)\n",
1795 GETPORT(FIFOSTAT));
1798 #if defined(DEBUG_DATAI)
1799 if(!fifodata)
1800 printk("fifo empty, ");
1801 else
1802 printk("something left in fifo, ");
1803 #endif
1806 #if defined(DEBUG_DATAI)
1807 if(current_SC->SCp.buffers_residual || current_SC->SCp.this_residual)
1808 printk("left buffers (buffers=%d, bytes=%d), ",
1809 current_SC->SCp.buffers_residual,
1810 current_SC->SCp.this_residual);
1811 #endif
1812 /* transfer can be considered ended, when SCSIEN reads back zero */
1813 CLRBITS(SXFRCTL0, SCSIEN|DMAEN);
1814 while( TESTHI( SXFRCTL0, SCSIEN ) )
1816 CLRBITS(DMACNTRL0, ENDMA );
1818 #if defined(DEBUG_DATAI) || defined(DEBUG_INTR)
1819 printk("got %d bytes, ", GETSTCNT());
1820 #endif
1822 current_SC->SCp.have_data_in++;
1824 break;
1826 case P_DATAO: /* DATA OUT phase */
1828 int data_count;
1830 #if defined(DEBUG_DATAO) || defined(DEBUG_INTR) || defined(DEBUG_PHASES)
1831 printk("DATA OUT, ");
1832 #endif
1833 #if defined(DEBUG_DATAO)
1834 printk("got data to send (bytes=%d, buffers=%d), ",
1835 current_SC->SCp.this_residual,
1836 current_SC->SCp.buffers_residual );
1837 #endif
1839 if(GETPORT(FIFOSTAT) || GETPORT(SSTAT2) & (SFULL|SFCNT) )
1841 printk("%d(%d) left in FIFO, ", GETPORT(FIFOSTAT), GETPORT(SSTAT2) & (SFULL|SFCNT) );
1842 aha152x_panic("FIFO should be empty");
1845 SETPORT(DMACNTRL0, WRITE_READ|RSTFIFO);
1846 SETPORT(DMACNTRL0, ENDMA|WRITE_READ);
1848 SETPORT(SXFRCTL0, CH1|CLRSTCNT|CLRCH1 );
1849 SETPORT(SXFRCTL0, SCSIEN|DMAEN|CH1);
1851 SETPORT( SIMODE0, 0 );
1852 SETPORT( SIMODE1, ENPHASEMIS );
1854 /* while current buffer is not empty or
1855 there are more buffers to transfer */
1856 while( TESTLO( SSTAT1, PHASEMIS ) &&
1857 (current_SC->SCp.this_residual ||
1858 current_SC->SCp.buffers_residual) )
1860 #if defined(DEBUG_DATAO)
1861 printk("sending data (left: bytes=%d, buffers=%d), waiting, ",
1862 current_SC->SCp.this_residual,
1863 current_SC->SCp.buffers_residual);
1864 #endif
1865 /* transfer rest of buffer, but max. 128 byte */
1866 data_count = current_SC->SCp.this_residual > 128 ?
1867 128 : current_SC->SCp.this_residual ;
1869 #if defined(DEBUG_DATAO)
1870 printk("data_count=%d, ", data_count);
1871 #endif
1873 if(data_count == 1)
1875 /* put a single byte in byte mode */
1876 SETBITS(DMACNTRL0, _8BIT );
1877 SETPORT(DATAPORT, *current_SC->SCp.ptr++);
1878 current_SC->SCp.this_residual--;
1880 else
1882 CLRBITS(DMACNTRL0, _8BIT );
1883 data_count >>= 1; /* Number of words */
1884 outsw( DATAPORT, current_SC->SCp.ptr, data_count );
1885 current_SC->SCp.ptr += 2 * data_count;
1886 current_SC->SCp.this_residual -= 2 * data_count;
1889 /* wait for FIFO to get empty */
1890 while( TESTLO ( DMASTAT, DFIFOEMP|INTSTAT ) )
1893 #if defined(DEBUG_DATAO)
1894 printk("fifo (%d bytes), transfered (%d bytes), ",
1895 GETPORT(FIFOSTAT), GETSTCNT() );
1896 #endif
1898 /* if this buffer is empty and there are more buffers left */
1899 if ( TESTLO( SSTAT1, PHASEMIS ) &&
1900 !current_SC->SCp.this_residual &&
1901 current_SC->SCp.buffers_residual)
1903 /* advance to next buffer */
1904 current_SC->SCp.buffers_residual--;
1905 current_SC->SCp.buffer++;
1906 current_SC->SCp.ptr =
1907 current_SC->SCp.buffer->address;
1908 current_SC->SCp.this_residual =
1909 current_SC->SCp.buffer->length;
1913 if ( current_SC->SCp.this_residual ||
1914 current_SC->SCp.buffers_residual )
1916 /* target leaves DATA OUT for an other phase
1917 (perhaps disconnect) */
1919 /* data in fifos has to be resend */
1920 data_count = GETPORT(SSTAT2) & (SFULL|SFCNT);
1922 data_count += GETPORT(FIFOSTAT) ;
1923 current_SC->SCp.ptr -= data_count;
1924 current_SC->SCp.this_residual += data_count;
1925 #if defined(DEBUG_DATAO)
1926 printk("left data (bytes=%d, buffers=%d), fifos (bytes=%d), transfer incomplete, resetting fifo, ",
1927 current_SC->SCp.this_residual,
1928 current_SC->SCp.buffers_residual,
1929 data_count );
1930 #endif
1931 SETPORT(DMACNTRL0, WRITE_READ|RSTFIFO);
1932 CLRBITS(SXFRCTL0, SCSIEN|DMAEN );
1933 CLRBITS(DMACNTRL0, ENDMA);
1935 else
1937 #if defined(DEBUG_DATAO)
1938 printk("waiting for SCSI fifo to get empty, ");
1939 #endif
1940 /* wait for SCSI fifo to get empty */
1941 while( TESTLO( SSTAT2, SEMPTY ) )
1943 #if defined(DEBUG_DATAO)
1944 printk("ok, ");
1945 #endif
1947 #if defined(DEBUG_DATAO)
1948 printk("left data (bytes=%d, buffers=%d) ",
1949 current_SC->SCp.this_residual,
1950 current_SC->SCp.buffers_residual);
1951 #endif
1952 CLRBITS(SXFRCTL0, SCSIEN|DMAEN);
1954 /* transfer can be considered ended, when SCSIEN reads back zero */
1955 while( TESTHI( SXFRCTL0, SCSIEN ) )
1958 CLRBITS(DMACNTRL0, ENDMA);
1961 #if defined(DEBUG_DATAO) || defined(DEBUG_INTR)
1962 printk("sent %d data bytes, ", GETSTCNT() );
1963 #endif
1965 break;
1967 case P_BUSFREE: /* BUSFREE */
1968 #if defined(DEBUG_RACE)
1969 leave_driver("(BUSFREE) intr");
1970 #endif
1971 #if defined(DEBUG_PHASES)
1972 printk("unexpected BUS FREE, ");
1973 #endif
1974 current_SC->SCp.phase = (current_SC->SCp.phase & ~(P_MASK<<16));
1976 aha152x_done( DID_ERROR << 16 ); /* Don't know any better */
1977 return;
1978 break;
1980 case P_PARITY: /* parity error in DATA phase */
1981 #if defined(DEBUG_RACE)
1982 leave_driver("(DID_PARITY) intr");
1983 #endif
1984 printk("PARITY error in DATA phase, ");
1986 current_SC->SCp.phase = (current_SC->SCp.phase & ~(P_MASK<<16));
1988 SETBITS( DMACNTRL0, INTEN );
1989 aha152x_done( DID_PARITY << 16 );
1990 return;
1991 break;
1993 default:
1994 printk("aha152x: unexpected phase\n");
1995 break;
1998 if(done)
2000 #if defined(DEBUG_INTR)
2001 printk("command done.\n");
2002 #endif
2003 #if defined(DEBUG_RACE)
2004 leave_driver("(done) intr");
2005 #endif
2007 SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
2008 SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
2009 SETPORT( SCSISEQ, disconnected_SC ? ENRESELI : 0 );
2011 SETBITS( DMACNTRL0, INTEN );
2013 aha152x_done( (current_SC->SCp.Status & 0xff)
2014 | ( (current_SC->SCp.Message & 0xff) << 8)
2015 | ( DID_OK << 16) );
2017 #if defined(DEBUG_RACE)
2018 printk("done returned (DID_OK: Status=%x; Message=%x).\n",
2019 current_SC->SCp.Status, current_SC->SCp.Message);
2020 #endif
2021 return;
2024 if(current_SC)
2025 current_SC->SCp.phase |= 1<<16 ;
2027 SETPORT( SIMODE0, 0 );
2028 SETPORT( SIMODE1, ENPHASEMIS );
2029 #if defined(DEBUG_INTR)
2030 disp_enintr();
2031 #endif
2032 #if defined(DEBUG_RACE)
2033 leave_driver("(PHASEEND) intr");
2034 #endif
2036 SETBITS( DMACNTRL0, INTEN);
2037 return;
2041 * Dump the current driver status and panic...
2043 static void aha152x_panic(char *msg)
2045 printk("\naha152x_panic: %s\n", msg);
2046 show_queues();
2047 panic("aha152x panic");
2051 * Display registers of AIC-6260
2053 static void disp_ports(void)
2055 #if !defined(SKIP_PORTS)
2056 int s;
2058 printk("\n%s: ", current_SC ? "on bus" : "waiting");
2060 s=GETPORT(SCSISEQ);
2061 printk("SCSISEQ ( ");
2062 if( s & TEMODEO ) printk("TARGET MODE ");
2063 if( s & ENSELO ) printk("SELO ");
2064 if( s & ENSELI ) printk("SELI ");
2065 if( s & ENRESELI ) printk("RESELI ");
2066 if( s & ENAUTOATNO ) printk("AUTOATNO ");
2067 if( s & ENAUTOATNI ) printk("AUTOATNI ");
2068 if( s & ENAUTOATNP ) printk("AUTOATNP ");
2069 if( s & SCSIRSTO ) printk("SCSIRSTO ");
2070 printk(");");
2072 printk(" SCSISIG ( ");
2073 s=GETPORT(SCSISIG);
2074 switch(s & P_MASK)
2076 case P_DATAO:
2077 printk("DATA OUT");
2078 break;
2079 case P_DATAI:
2080 printk("DATA IN");
2081 break;
2082 case P_CMD:
2083 printk("COMMAND");
2084 break;
2085 case P_STATUS:
2086 printk("STATUS");
2087 break;
2088 case P_MSGO:
2089 printk("MESSAGE OUT");
2090 break;
2091 case P_MSGI:
2092 printk("MESSAGE IN");
2093 break;
2094 default:
2095 printk("*illegal*");
2096 break;
2099 printk(" ); ");
2101 printk("INTSTAT ( %s ); ", TESTHI(DMASTAT, INTSTAT) ? "hi" : "lo");
2103 printk("SSTAT ( ");
2104 s=GETPORT(SSTAT0);
2105 if( s & TARGET ) printk("TARGET ");
2106 if( s & SELDO ) printk("SELDO ");
2107 if( s & SELDI ) printk("SELDI ");
2108 if( s & SELINGO ) printk("SELINGO ");
2109 if( s & SWRAP ) printk("SWRAP ");
2110 if( s & SDONE ) printk("SDONE ");
2111 if( s & SPIORDY ) printk("SPIORDY ");
2112 if( s & DMADONE ) printk("DMADONE ");
2114 s=GETPORT(SSTAT1);
2115 if( s & SELTO ) printk("SELTO ");
2116 if( s & ATNTARG ) printk("ATNTARG ");
2117 if( s & SCSIRSTI ) printk("SCSIRSTI ");
2118 if( s & PHASEMIS ) printk("PHASEMIS ");
2119 if( s & BUSFREE ) printk("BUSFREE ");
2120 if( s & SCSIPERR ) printk("SCSIPERR ");
2121 if( s & PHASECHG ) printk("PHASECHG ");
2122 if( s & REQINIT ) printk("REQINIT ");
2123 printk("); ");
2126 printk("SSTAT ( ");
2128 s=GETPORT(SSTAT0) & GETPORT(SIMODE0);
2130 if( s & TARGET ) printk("TARGET ");
2131 if( s & SELDO ) printk("SELDO ");
2132 if( s & SELDI ) printk("SELDI ");
2133 if( s & SELINGO ) printk("SELINGO ");
2134 if( s & SWRAP ) printk("SWRAP ");
2135 if( s & SDONE ) printk("SDONE ");
2136 if( s & SPIORDY ) printk("SPIORDY ");
2137 if( s & DMADONE ) printk("DMADONE ");
2139 s=GETPORT(SSTAT1) & GETPORT(SIMODE1);
2141 if( s & SELTO ) printk("SELTO ");
2142 if( s & ATNTARG ) printk("ATNTARG ");
2143 if( s & SCSIRSTI ) printk("SCSIRSTI ");
2144 if( s & PHASEMIS ) printk("PHASEMIS ");
2145 if( s & BUSFREE ) printk("BUSFREE ");
2146 if( s & SCSIPERR ) printk("SCSIPERR ");
2147 if( s & PHASECHG ) printk("PHASECHG ");
2148 if( s & REQINIT ) printk("REQINIT ");
2149 printk("); ");
2151 printk("SXFRCTL0 ( ");
2153 s=GETPORT(SXFRCTL0);
2154 if( s & SCSIEN ) printk("SCSIEN ");
2155 if( s & DMAEN ) printk("DMAEN ");
2156 if( s & CH1 ) printk("CH1 ");
2157 if( s & CLRSTCNT ) printk("CLRSTCNT ");
2158 if( s & SPIOEN ) printk("SPIOEN ");
2159 if( s & CLRCH1 ) printk("CLRCH1 ");
2160 printk("); ");
2162 printk("SIGNAL ( ");
2164 s=GETPORT(SCSISIG);
2165 if( s & ATNI ) printk("ATNI ");
2166 if( s & SELI ) printk("SELI ");
2167 if( s & BSYI ) printk("BSYI ");
2168 if( s & REQI ) printk("REQI ");
2169 if( s & ACKI ) printk("ACKI ");
2170 printk("); ");
2172 printk("SELID ( %02x ), ", GETPORT(SELID) );
2174 printk("SSTAT2 ( ");
2176 s=GETPORT(SSTAT2);
2177 if( s & SOFFSET) printk("SOFFSET ");
2178 if( s & SEMPTY) printk("SEMPTY ");
2179 if( s & SFULL) printk("SFULL ");
2180 printk("); SFCNT ( %d ); ", s & (SFULL|SFCNT) );
2182 #if 0
2183 printk("SSTAT4 ( ");
2184 s=GETPORT(SSTAT4);
2185 if( s & SYNCERR) printk("SYNCERR ");
2186 if( s & FWERR) printk("FWERR ");
2187 if( s & FRERR) printk("FRERR ");
2188 printk("); ");
2189 #endif
2191 printk("FCNT ( %d ); ", GETPORT(FIFOSTAT) );
2193 printk("DMACNTRL0 ( ");
2194 s=GETPORT(DMACNTRL0);
2195 printk( "%s ", s & _8BIT ? "8BIT" : "16BIT" );
2196 printk( "%s ", s & DMA ? "DMA" : "PIO" );
2197 printk( "%s ", s & WRITE_READ ? "WRITE" : "READ" );
2198 if( s & ENDMA ) printk("ENDMA ");
2199 if( s & INTEN ) printk("INTEN ");
2200 if( s & RSTFIFO ) printk("RSTFIFO ");
2201 if( s & SWINT ) printk("SWINT ");
2202 printk("); ");
2205 #if 0
2206 printk("DMACNTRL1 ( ");
2208 s=GETPORT(DMACNTRL1);
2209 if( s & PWRDWN ) printk("PWRDN ");
2210 printk("); ");
2213 printk("STK ( %d ); ", s & 0xf);
2215 printk("DMASTAT (");
2216 s=GETPORT(DMASTAT);
2217 if( s & ATDONE ) printk("ATDONE ");
2218 if( s & WORDRDY ) printk("WORDRDY ");
2219 if( s & DFIFOFULL ) printk("DFIFOFULL ");
2220 if( s & DFIFOEMP ) printk("DFIFOEMP ");
2221 printk(")");
2223 #endif
2225 printk("\n");
2226 #endif
2230 * display enabled interrupts
2232 static void disp_enintr(void)
2234 int s;
2236 printk("enabled interrupts ( ");
2238 s=GETPORT(SIMODE0);
2239 if( s & ENSELDO ) printk("ENSELDO ");
2240 if( s & ENSELDI ) printk("ENSELDI ");
2241 if( s & ENSELINGO ) printk("ENSELINGO ");
2242 if( s & ENSWRAP ) printk("ENSWRAP ");
2243 if( s & ENSDONE ) printk("ENSDONE ");
2244 if( s & ENSPIORDY ) printk("ENSPIORDY ");
2245 if( s & ENDMADONE ) printk("ENDMADONE ");
2247 s=GETPORT(SIMODE1);
2248 if( s & ENSELTIMO ) printk("ENSELTIMO ");
2249 if( s & ENATNTARG ) printk("ENATNTARG ");
2250 if( s & ENPHASEMIS ) printk("ENPHASEMIS ");
2251 if( s & ENBUSFREE ) printk("ENBUSFREE ");
2252 if( s & ENSCSIPERR ) printk("ENSCSIPERR ");
2253 if( s & ENPHASECHG ) printk("ENPHASECHG ");
2254 if( s & ENREQINIT ) printk("ENREQINIT ");
2255 printk(")\n");
2258 #if defined(DEBUG_RACE)
2260 static const char *should_leave;
2261 static int in_driver=0;
2264 * Only one routine can be in the driver at once.
2266 static void enter_driver(const char *func)
2268 cli();
2269 printk("aha152x: entering %s() (%x)\n", func, jiffies);
2270 if(in_driver)
2272 printk("%s should leave first.\n", should_leave);
2273 panic("aha152x: already in driver\n");
2276 in_driver++;
2277 should_leave=func;
2278 sti();
2281 static void leave_driver(const char *func)
2283 cli();
2284 printk("\naha152x: leaving %s() (%x)\n", func, jiffies);
2285 if(!in_driver)
2287 printk("aha152x: %s already left.\n", should_leave);
2288 panic("aha152x: %s already left driver.\n");
2291 in_driver--;
2292 should_leave=func;
2293 sti();
2295 #endif
2298 * Show the command data of a command
2300 static void show_command(Scsi_Cmnd *ptr)
2302 int i;
2304 printk("0x%08x: target=%d; lun=%d; cmnd=( ",
2305 (unsigned long) ptr, ptr->target, ptr->lun);
2307 for(i=0; i<COMMAND_SIZE(ptr->cmnd[0]); i++)
2308 printk("%02x ", ptr->cmnd[i]);
2310 printk("); residual=%d; buffers=%d; phase |",
2311 ptr->SCp.this_residual, ptr->SCp.buffers_residual);
2313 if( ptr->SCp.phase & not_issued ) printk("not issued|");
2314 if( ptr->SCp.phase & in_selection ) printk("in selection|");
2315 if( ptr->SCp.phase & disconnected ) printk("disconnected|");
2316 if( ptr->SCp.phase & aborted ) printk("aborted|");
2317 if( ptr->SCp.phase & sent_ident ) printk("send_ident|");
2318 if( ptr->SCp.phase & in_other )
2320 printk("; in other(");
2321 switch( (ptr->SCp.phase >> 16) & P_MASK )
2323 case P_DATAO:
2324 printk("DATA OUT");
2325 break;
2326 case P_DATAI:
2327 printk("DATA IN");
2328 break;
2329 case P_CMD:
2330 printk("COMMAND");
2331 break;
2332 case P_STATUS:
2333 printk("STATUS");
2334 break;
2335 case P_MSGO:
2336 printk("MESSAGE OUT");
2337 break;
2338 case P_MSGI:
2339 printk("MESSAGE IN");
2340 break;
2341 default:
2342 printk("*illegal*");
2343 break;
2345 printk(")");
2346 if(ptr->SCp.phase & (1<<16))
2347 printk("; phaseend");
2349 printk("; next=0x%08x\n", (unsigned long) ptr->host_scribble);
2353 * Dump the queued data
2355 static void show_queues(void)
2357 Scsi_Cmnd *ptr;
2359 cli();
2360 printk("QUEUE STATUS:\nissue_SC:\n");
2361 for(ptr=issue_SC; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble )
2362 show_command(ptr);
2364 printk("current_SC:\n");
2365 if(current_SC)
2366 show_command(current_SC);
2367 else
2368 printk("none\n");
2370 printk("disconnected_SC:\n");
2371 for(ptr=disconnected_SC; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble )
2372 show_command(ptr);
2374 disp_ports();
2375 disp_enintr();
2376 sti();