root/drivers/scsi/aha152x.c

/* [previous][next][first][last][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. do_pause
  2. append_SC
  3. remove_first_SC
  4. remove_SC
  5. make_acklow
  6. getphase
  7. aha152x_setup
  8. aha152x_porttest
  9. aha152x_detect
  10. aha152x_queue
  11. aha152x_command
  12. aha152x_abort
  13. aha152x_reset_ports
  14. aha152x_reset
  15. aha152x_biosparam
  16. aha152x_done
  17. aha152x_intr
  18. aha152x_panic
  19. disp_ports
  20. disp_enintr
  21. enter_driver
  22. leave_driver
  23. show_command
  24. show_queues

   1 /* aha152x.c -- Adaptec AHA-152x driver
   2  * Author: Juergen E. Fischer, fischer@server.et-inf.fho-emden.de
   3  * Copyright 1993, 1994 Juergen E. Fischer
   4  *
   5  *
   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)
  10  *
  11 
  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.
  16 
  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.
  21  
  22  *
  23  * $Id: aha152x.c,v 1.9 1995/03/18 09:20:24 root Exp root $
  24  *
  25 
  26  * $Log: aha152x.c,v $
  27  * Revision 1.9  1995/03/18  09:20:24  root
  28  * - patches for PCMCIA and modules
  29  *
  30  * Revision 1.8  1995/01/21  22:07:19  root
  31  * - snarf_region => request_region
  32  * - aha152x_intr interface change
  33  *
  34  * Revision 1.7  1995/01/02  23:19:36  root
  35  * - updated COMMAND_SIZE to cmd_len
  36  * - changed sti() to restore_flags()
  37  * - fixed some #ifdef which generated warnings
  38  *
  39  * Revision 1.6  1994/11/24  20:35:27  root
  40  * - problem with odd number of bytes in fifo fixed
  41  *
  42  * Revision 1.5  1994/10/30  14:39:56  root
  43  * - abort code fixed
  44  * - debugging improved
  45  *
  46  * Revision 1.4  1994/09/12  11:33:01  root
  47  * - irqaction to request_irq
  48  * - abortion updated
  49  *
  50  * Revision 1.3  1994/08/04  13:53:05  root
  51  * - updates for mid-level-driver changes
  52  * - accept unexpected BUSFREE phase as error condition
  53  * - parity check now configurable
  54  *
  55  * Revision 1.2  1994/07/03  12:56:36  root
  56  * - cleaned up debugging code
  57  * - more tweaking on reset delays
  58  * - updated abort/reset code (pretty untested...)
  59  *
  60  * Revision 1.1  1994/05/28  21:18:49  root
  61  * - update for mid-level interface change (abort-reset)
  62  * - delays after resets adjusted for some slow devices
  63  *
  64  * Revision 1.0  1994/03/25  12:52:00  root
  65  * - Fixed "more data than expected" problem
  66  * - added new BIOS signatures
  67  *
  68  * Revision 0.102  1994/01/31  20:44:12  root
  69  * - minor changes in insw/outsw handling
  70  *
  71  * Revision 0.101  1993/12/13  01:16:27  root
  72  * - fixed STATUS phase (non-GOOD stati were dropped sometimes;
  73  *   fixes problems with CD-ROM sector size detection & media change)
  74  *
  75  * Revision 0.100  1993/12/10  16:58:47  root
  76  * - fix for unsuccessful selections in case of non-continuous id assignments
  77  *   on the scsi bus.
  78  *
  79  * Revision 0.99  1993/10/24  16:19:59  root
  80  * - fixed DATA IN (rare read errors gone)
  81  *
  82  * Revision 0.98  1993/10/17  12:54:44  root
  83  * - fixed some recent fixes (shame on me)
  84  * - moved initialization of scratch area to aha152x_queue
  85  *
  86  * Revision 0.97  1993/10/09  18:53:53  root
  87  * - DATA IN fixed. Rarely left data in the fifo.
  88  *
  89  * Revision 0.96  1993/10/03  00:53:59  root
  90  * - minor changes on DATA IN
  91  *
  92  * Revision 0.95  1993/09/24  10:36:01  root
  93  * - change handling of MSGI after reselection
  94  * - fixed sti/cli
  95  * - minor changes
  96  *
  97  * Revision 0.94  1993/09/18  14:08:22  root
  98  * - fixed bug in multiple outstanding command code
  99  * - changed detection
 100  * - support for kernel command line configuration
 101  * - reset corrected
 102  * - changed message handling
 103  *
 104  * Revision 0.93  1993/09/15  20:41:19  root
 105  * - fixed bugs with multiple outstanding commands
 106  *
 107  * Revision 0.92  1993/09/13  02:46:33  root
 108  * - multiple outstanding commands work (no problems with IBM drive)
 109  *
 110  * Revision 0.91  1993/09/12  20:51:46  root
 111  * added multiple outstanding commands
 112  * (some problem with this $%&? IBM device remain)
 113  *
 114  * Revision 0.9  1993/09/12  11:11:22  root
 115  * - corrected auto-configuration
 116  * - changed the auto-configuration (added some '#define's)
 117  * - added support for dis-/reconnection
 118  *
 119  * Revision 0.8  1993/09/06  23:09:39  root
 120  * - added support for the drive activity light
 121  * - minor changes
 122  *
 123  * Revision 0.7  1993/09/05  14:30:15  root
 124  * - improved phase detection
 125  * - now using the new snarf_region code of 0.99pl13
 126  *
 127  * Revision 0.6  1993/09/02  11:01:38  root
 128  * first public release; added some signatures and biosparam()
 129  *
 130  * Revision 0.5  1993/08/30  10:23:30  root
 131  * fixed timing problems with my IBM drive
 132  *
 133  * Revision 0.4  1993/08/29  14:06:52  root
 134  * fixed some problems with timeouts due incomplete commands
 135  *
 136  * Revision 0.3  1993/08/28  15:55:03  root
 137  * writing data works too.  mounted and worked on a dos partition
 138  *
 139  * Revision 0.2  1993/08/27  22:42:07  root
 140  * reading data works.  Mounted a msdos partition.
 141  *
 142  * Revision 0.1  1993/08/25  13:38:30  root
 143  * first "damn thing doesn't work" version
 144  *
 145  * Revision 0.0  1993/08/14  19:54:25  root
 146  * empty function bodies; detect() works.
 147  *
 148 
 149  **************************************************************************
 150 
 151 
 152  
 153  DESCRIPTION:
 154 
 155  This is the Linux low-level SCSI driver for Adaptec AHA-1520/1522
 156  SCSI host adapters.
 157 
 158 
 159  PER-DEFINE CONFIGURABLE OPTIONS:
 160 
 161  AUTOCONF       : use configuration the controller reports (only 152x)
 162  IRQ            : override interrupt channel (9,10,11 or 12) (default 11)
 163  SCSI_ID        : override scsiid of AIC-6260 (0-7) (default 7)
 164  RECONNECT      : override target dis-/reconnection/multiple outstanding commands (default on)
 165  PARITY         : override parity check (default on)
 166  SKIP_BIOSTEST  : Don't test for BIOS signature (AHA-1510 or disabled BIOS)
 167  PORTBASE       : Force port base. Don't try to probe
 168 
 169 
 170  LILO COMMAND LINE OPTIONS:
 171 
 172  aha152x=<PORTBASE>[,<IRQ>[,<SCSI-ID>[,<RECONNECT>[,<PARITY>]]]]
 173 
 174  The normal configuration can be overridden by specifying a command line.
 175  When you do this, the BIOS test is skipped. Entered values have to be
 176  valid (known). Don't use values that aren't support under normal operation.
 177  If you think that you need other values: contact me.
 178 
 179 
 180  REFERENCES USED:
 181 
 182  "AIC-6260 SCSI Chip Specification", Adaptec Corporation.
 183 
 184  "SCSI COMPUTER SYSTEM INTERFACE - 2 (SCSI-2)", X3T9.2/86-109 rev. 10h
 185 
 186  "Writing a SCSI device driver for Linux", Rik Faith (faith@cs.unc.edu)
 187 
 188  "Kernel Hacker's Guide", Michael K. Johnson (johnsonm@sunsite.unc.edu)
 189 
 190  "Adaptec 1520/1522 User's Guide", Adaptec Corporation.
 191  
 192  Michael K. Johnson (johnsonm@sunsite.unc.edu)
 193 
 194  Drew Eckhardt (drew@cs.colorado.edu)
 195 
 196  Eric Youngdale (ericy@cais.com) 
 197 
 198  special thanks to Eric Youngdale for the free(!) supplying the
 199  documentation on the chip.
 200 
 201  **************************************************************************/
 202 
 203 #ifdef PCMCIA
 204 #define MODULE
 205 #endif
 206 
 207 #ifdef MODULE
 208 #include <linux/config.h>
 209 #include <linux/module.h>
 210 #endif
 211 
 212 #ifdef PCMCIA
 213 #undef MODULE
 214 #endif
 215 
 216 #include <linux/sched.h>
 217 #include <asm/io.h>
 218 #include "../block/blk.h"
 219 #include "scsi.h"
 220 #include "sd.h"
 221 #include "hosts.h"
 222 #include "constants.h"
 223 #include <asm/system.h>
 224 #include <linux/errno.h>
 225 #include <linux/string.h>
 226 #include <linux/wait.h>
 227 #include <linux/ioport.h>
 228 #include <linux/proc_fs.h>
 229 
 230 #include "aha152x.h"
 231 #include<linux/stat.h>
 232 
 233 struct proc_dir_entry proc_scsi_aha152x = {
 234     PROC_SCSI_AHA152X, 7, "aha152x",
 235     S_IFDIR | S_IRUGO | S_IXUGO, 2
 236 };
 237 
 238 /* DEFINES */
 239 
 240 /* For PCMCIA cards, always use AUTOCONF */
 241 #if defined(PCMCIA) || defined(MODULE)
 242 #if !defined(AUTOCONF)
 243 #define AUTOCONF
 244 #endif
 245 #endif
 246 
 247 /* If auto configuration is disabled, IRQ, SCSI_ID and RECONNECT have to
 248    be predefined */
 249 #if !defined(AUTOCONF)
 250 #if !defined(IRQ)
 251 #error undefined IRQ; define AUTOCONF or IRQ
 252 #endif
 253 #if !defined(SCSI_ID)
 254 #error undefined SCSI_ID; define AUTOCONF or SCSI_ID
 255 #endif
 256 #if !defined(RECONNECT)
 257 #error undefined RECONNECT; define AUTOCONF or RECONNECT
 258 #endif
 259 #if !defined(PARITY)
 260 #error undefined PARITY; define AUTOCONF or PARITY
 261 #endif
 262 #endif
 263 
 264 /* I use this when I'm looking for weird bugs */
 265 #define DEBUG_TIMING 
 266 
 267 #if defined(DEBUG_AHA152X)
 268 
 269 #undef  SKIP_PORTS              /* don't display ports */
 270 
 271 #undef  DEBUG_QUEUE             /* debug queue() */
 272 #undef  DEBUG_RESET             /* debug reset() */
 273 #undef  DEBUG_INTR              /* debug intr() */
 274 #undef  DEBUG_SELECTION         /* debug selection part in intr() */
 275 #undef  DEBUG_MSGO              /* debug message out phase in intr() */
 276 #undef  DEBUG_MSGI              /* debug message in phase in intr() */
 277 #undef  DEBUG_STATUS            /* debug status phase in intr() */
 278 #undef  DEBUG_CMD               /* debug command phase in intr() */
 279 #undef  DEBUG_DATAI             /* debug data in phase in intr() */
 280 #undef  DEBUG_DATAO             /* debug data out phase in intr() */
 281 #undef  DEBUG_ABORT             /* debug abort() */
 282 #undef  DEBUG_DONE              /* debug done() */
 283 #undef  DEBUG_BIOSPARAM         /* debug biosparam() */
 284 
 285 #undef  DEBUG_RACE              /* debug race conditions */
 286 #undef  DEBUG_PHASES            /* debug phases (useful to trace) */
 287 #undef  DEBUG_QUEUES            /* debug reselection */
 288 
 289 /* recently used for debugging */
 290 #if 0
 291 #endif
 292 
 293 #define DEBUG_PHASES
 294 #define DEBUG_RESET
 295 #define DEBUG_ABORT
 296 
 297 #define DEBUG_DEFAULT (debug_reset|debug_abort)
 298 
 299 #endif
 300 
 301 /* END OF DEFINES */
 302 
 303 /* some additional "phases" for getphase() */
 304 #define P_BUSFREE  1
 305 #define P_PARITY   2
 306 
 307 static int port_base      = 0;
 308 static int this_host      = 0;
 309 static int can_disconnect = 0;
 310 static int can_doparity   = 0;
 311 static int commands       = 0;
 312 
 313 #ifdef DEBUG_AHA152X
 314 unsigned int aha152x_debug  = DEBUG_DEFAULT;
 315 #endif
 316 
 317 /* set by aha152x_setup according to the command line */
 318 static int setup_called    = 0;
 319 static int setup_portbase  = 0;
 320 static int setup_irq       = 0;
 321 static int setup_scsiid    = 0;
 322 static int setup_reconnect = 0;
 323 static int setup_doparity  = 0;
 324 
 325 #ifdef DEBUG_AHA152X
 326 static int setup_debug     = 0;
 327 #endif
 328 
 329 static char *setup_str = (char *)NULL;
 330 
 331 enum {
 332    not_issued   = 0x01,
 333    in_selection = 0x02,
 334    disconnected = 0x04,
 335    aborted      = 0x08,
 336    sent_ident   = 0x10,
 337    in_other     = 0x20,
 338 };
 339  
 340 /*
 341  * Command queues:
 342  * issue_SC        : commands that are queued to be issued 
 343  * current_SC      : command that's currently using the bus
 344  * disconnected_SC : commands that that have been disconnected 
 345  */
 346 static Scsi_Cmnd            *issue_SC        = NULL;
 347 static Scsi_Cmnd            *current_SC      = NULL;
 348 static Scsi_Cmnd            *disconnected_SC = NULL;
 349 
 350 static int aborting=0, abortion_complete=0, abort_result;
 351 
 352 void aha152x_intr( int irq, struct pt_regs * );
 353 void aha152x_done( int error );
 354 void aha152x_setup( char *str, int *ints );
 355 
 356 static void aha152x_reset_ports(void);
 357 static void aha152x_panic(const char *msg);
 358 
 359 static void disp_ports(void);
 360 static void show_command(Scsi_Cmnd *ptr);
 361 static void show_queues(void);
 362 static void disp_enintr(void);
 363 
 364 #if defined(DEBUG_RACE)
 365 static void enter_driver(const char *);
 366 static void leave_driver(const char *);
 367 #endif
 368 
 369 /* possible i/o addresses for the AIC-6260 */
 370 static unsigned short ports[] =
 371 {
 372   0x340,      /* default first */
 373   0x140
 374 };
 375 #define PORT_COUNT (sizeof( ports ) / sizeof( unsigned short ))
 376 
 377 /* possible interrupt channels */
 378 static unsigned short irqs[] = { 9, 10, 11, 12, 0 };
 379 
 380 #if !defined(SKIP_BIOSTEST)
 381 /* possible locations for the Adaptec BIOS */
 382 static void *addresses[] =
 383 {
 384   (void *) 0xdc000,   /* default first */
 385   (void *) 0xc8000,
 386   (void *) 0xcc000,
 387   (void *) 0xd0000,
 388   (void *) 0xd4000,
 389   (void *) 0xd8000,
 390   (void *) 0xe0000,
 391   (void *) 0xf0000,
 392   (void *) 0xeb800,   /* VTech Platinum SMP */
 393 };
 394 #define ADDRESS_COUNT (sizeof( addresses ) / sizeof( void * ))
 395 
 396 /* signatures for various AIC-6[23]60 based controllers.
 397    The point in detecting signatures is to avoid useless
 398    and maybe harmful probes on ports. I'm not sure that
 399    all listed boards pass auto-configuration. For those
 400    which fail the BIOS signature is obsolete, because
 401    user intervention to supply the configuration is 
 402    needed anyway. */
 403 static struct signature {
 404   char *signature;
 405   int  sig_offset;
 406   int  sig_length;
 407 } signatures[] =
 408 {
 409   { "Adaptec AHA-1520 BIOS",      0x102e, 21 },  /* Adaptec 152x */
 410   { "Adaptec ASW-B626 BIOS",      0x1029, 21 },  /* on-board controller */
 411   { "Adaptec BIOS: ASW-B626",       0x0f, 22 },  /* on-board controller */
 412   { "Adaptec ASW-B626 S2",        0x2e6c, 19 },  /* on-board controller */
 413   { "Adaptec BIOS:AIC-6360",         0xc, 21 },  /* on-board controller */
 414   { "ScsiPro SP-360 BIOS",        0x2873, 19 },  /* ScsiPro-Controller with AIC-6360 */
 415   { "GA-400 LOCAL BUS SCSI BIOS", 0x102e, 26 },  /* Gigabyte Local-Bus-SCSI */
 416 };
 417 #define SIGNATURE_COUNT (sizeof( signatures ) / sizeof( struct signature ))
 418 #endif
 419 
 420 
 421 static void do_pause( unsigned amount ) /* Pause for amount*10 milliseconds */
     /* [previous][next][first][last][top][bottom][index][help] */
 422 {
 423    unsigned long the_time = jiffies + amount; /* 0.01 seconds per jiffy */
 424 
 425    while (jiffies < the_time)
 426      ;
 427 }
 428 
 429 /*
 430  *  queue services:
 431  */
 432 static inline void append_SC( Scsi_Cmnd **SC, Scsi_Cmnd *new_SC)
     /* [previous][next][first][last][top][bottom][index][help] */
 433 {
 434   Scsi_Cmnd *end;
 435 
 436   new_SC->host_scribble = (unsigned char *) NULL;
 437   if(!*SC)
 438     *SC=new_SC;
 439   else
 440     {
 441       for( end=*SC;
 442            end->host_scribble;
 443            end = (Scsi_Cmnd *) end->host_scribble )
 444         ;
 445       end->host_scribble = (unsigned char *) new_SC;
 446     }
 447 }
 448 
 449 static inline Scsi_Cmnd *remove_first_SC( Scsi_Cmnd **SC )
     /* [previous][next][first][last][top][bottom][index][help] */
 450 {
 451   Scsi_Cmnd *ptr;
 452 
 453   ptr=*SC;
 454   if(ptr)
 455     *SC= (Scsi_Cmnd *) (*SC)->host_scribble;
 456   return ptr;
 457 }
 458 
 459 static inline Scsi_Cmnd *remove_SC( Scsi_Cmnd **SC, int target, int lun )
     /* [previous][next][first][last][top][bottom][index][help] */
 460 {
 461   Scsi_Cmnd *ptr, *prev;
 462 
 463   for( ptr=*SC, prev=NULL;
 464        ptr && ((ptr->target!=target) || (ptr->lun!=lun));
 465        prev = ptr, ptr = (Scsi_Cmnd *) ptr->host_scribble )
 466     ;
 467 
 468   if(ptr)
 469     if(prev)
 470       prev->host_scribble = ptr->host_scribble;
 471     else
 472       *SC= (Scsi_Cmnd *) ptr->host_scribble;
 473   return ptr;
 474 }
 475 
 476 /*
 477  * read inbound byte and wait for ACK to get low
 478  */
 479 static void make_acklow(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 480 {
 481   SETPORT( SXFRCTL0, CH1|SPIOEN );
 482   GETPORT(SCSIDAT);
 483   SETPORT( SXFRCTL0, CH1 );
 484 
 485   while( TESTHI( SCSISIG, ACKI ) )
 486     ;
 487 }
 488 
 489 /*
 490  * detect current phase more reliable:
 491  * phase is valid, when the target asserts REQ after we've deasserted ACK.
 492  *
 493  * return value is a valid phase or an error code.
 494  *
 495  * errorcodes:
 496  *   P_BUSFREE   BUS FREE phase detected
 497  *   P_PARITY    parity error in DATA phase
 498  */
 499 static int getphase(void)
     /* [previous][next][first][last][top][bottom][index][help] */
 500 {
 501   int phase, sstat1;
 502   
 503   while( 1 )
 504     {
 505       do
 506         {
 507           while( !( ( sstat1 = GETPORT( SSTAT1 ) ) & (BUSFREE|SCSIRSTI|REQINIT ) ) )
 508             ;
 509           if( sstat1 & BUSFREE )
 510             return P_BUSFREE;
 511           if( sstat1 & SCSIRSTI )
 512             {
 513               /* IBM drive responds with RSTI to RSTO */
 514               printk("aha152x: RESET IN\n");
 515               SETPORT( SSTAT1, SCSIRSTI );
 516             }
 517         }
 518       while( TESTHI( SCSISIG, ACKI ) || TESTLO( SSTAT1, REQINIT ) );
 519 
 520       SETPORT( SSTAT1, CLRSCSIPERR );
 521   
 522       phase = GETPORT( SCSISIG ) & P_MASK ;
 523 
 524       if( TESTHI( SSTAT1, SCSIPERR ) )
 525         {
 526           if( (phase & (CDO|MSGO))==0 )                         /* DATA phase */
 527             return P_PARITY;
 528 
 529           make_acklow();
 530         }
 531       else
 532         return phase;
 533     }
 534 }
 535 
 536 /* called from init/main.c */
 537 void aha152x_setup( char *str, int *ints)
     /* [previous][next][first][last][top][bottom][index][help] */
 538 {
 539   if(setup_called)
 540     panic("aha152x: aha152x_setup called twice.\n");
 541 
 542   setup_called=ints[0];
 543   setup_str=str;
 544 
 545   setup_portbase  = ints[0] >= 1 ? ints[1] : 0x340;
 546   setup_irq       = ints[0] >= 2 ? ints[2] : 11;
 547   setup_scsiid    = ints[0] >= 3 ? ints[3] : 7;
 548   setup_reconnect = ints[0] >= 4 ? ints[4] : 1;
 549   setup_doparity  = ints[0] >= 5 ? ints[5] : 1;
 550 #ifdef DEBUG_AHA152X
 551   setup_debug     = ints[0] >= 6 ? ints[6] : DEBUG_DEFAULT;
 552 #endif
 553 }
 554 
 555 /*
 556    Test, if port_base is valid.
 557  */
 558 static int aha152x_porttest(int port_base)
     /* [previous][next][first][last][top][bottom][index][help] */
 559 {
 560   int i;
 561 
 562   if(check_region(port_base, 0x20))
 563     return 0;
 564 
 565   SETPORT( DMACNTRL1, 0 );          /* reset stack pointer */
 566   for(i=0; i<16; i++)
 567     SETPORT( STACK, i );
 568 
 569   SETPORT( DMACNTRL1, 0 );          /* reset stack pointer */
 570   for(i=0; i<16 && GETPORT(STACK)==i; i++)
 571     ;
 572 
 573   return(i==16);
 574 }
 575 
 576 int aha152x_detect(Scsi_Host_Template * tpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 577 {
 578   int                 i, ok;
 579 #if defined(AUTOCONF)
 580   aha152x_config      conf;
 581 #endif
 582   int                 interrupt_level;
 583   struct Scsi_Host    *hreg;
 584   
 585   tpnt->proc_dir = &proc_scsi_aha152x;
 586 
 587   if(setup_called)
 588     {
 589       printk("aha152x: processing commandline: ");
 590    
 591 #ifdef DEBUG_AHA152X
 592       if(setup_called>6)
 593 #else
 594       if(setup_called>5)
 595 #endif
 596         {
 597           printk("\naha152x: %s\n", setup_str );
 598 #ifdef DEBUG_AHA152X
 599           printk("aha152x: usage: aha152x=<PORTBASE>[,<IRQ>[,<SCSI ID>[,<RECONNECT>[,<PARITY>[,<DEBUG>]]]]]\n");
 600 #else
 601           printk("aha152x: usage: aha152x=<PORTBASE>[,<IRQ>[,<SCSI ID>[,<RECONNECT>[,<PARITY>]]]]\n");
 602 #endif
 603           panic("aha152x panics in line %d", __LINE__);
 604         }
 605 
 606       port_base       = setup_portbase;
 607       interrupt_level = setup_irq;
 608       this_host       = setup_scsiid;
 609       can_disconnect  = setup_reconnect;
 610       can_doparity    = setup_doparity;
 611 #ifdef DEBUG_AHA152X
 612       aha152x_debug   = setup_debug;
 613 #endif
 614 
 615 #ifndef PCMCIA
 616       for( i=0; i<PORT_COUNT && (port_base != ports[i]); i++)
 617         ;
 618 
 619       if(i==PORT_COUNT)
 620         {
 621           printk("unknown portbase 0x%03x\n", port_base);
 622           panic("aha152x panics in line %d", __LINE__);
 623         }
 624 #endif
 625 
 626       if(!aha152x_porttest(port_base))
 627         {
 628           printk("portbase 0x%03x fails probe\n", port_base);
 629 #ifdef PCMCIA
 630           return 0;
 631 #else
 632           panic("aha152x panics in line %d", __LINE__);
 633 #endif
 634         }
 635 
 636 #ifndef PCMCIA
 637       i=0;
 638       while(irqs[i] && (interrupt_level!=irqs[i]))
 639         i++;
 640       if(!irqs[i])
 641         {
 642           printk("illegal IRQ %d\n", interrupt_level);
 643           panic("aha152x panics in line %d", __LINE__);
 644         }
 645 #endif
 646       
 647       if( (this_host < 0) || (this_host > 7) )
 648         {
 649           printk("illegal SCSI ID %d\n", this_host);
 650           panic("aha152x panics in line %d", __LINE__);
 651         }
 652 
 653       if( (can_disconnect < 0) || (can_disconnect > 1) )
 654         {
 655           printk("reconnect %d should be 0 or 1\n", can_disconnect);
 656           panic("aha152x panics in line %d", __LINE__);
 657         }
 658 
 659       if( (can_doparity < 0) || (can_doparity > 1) )
 660         {
 661           printk("parity %d should be 0 or 1\n", can_doparity);
 662           panic("aha152x panics in line %d", __LINE__);
 663         }
 664       printk("ok\n");
 665     }
 666   else
 667     {
 668 #if !defined(SKIP_BIOSTEST)
 669       int j;
 670 
 671       ok=0;
 672       for( i=0; i < ADDRESS_COUNT && !ok; i++)
 673         for( j=0; (j < SIGNATURE_COUNT) && !ok; j++)
 674           ok=!memcmp((void *) addresses[i]+signatures[j].sig_offset,
 675                      (void *) signatures[j].signature,
 676                      (int) signatures[j].sig_length);
 677 
 678       if(!ok)
 679         return 0;
 680 
 681       printk("aha152x: BIOS test: passed, ");
 682 #else
 683       printk("aha152x: ");
 684 #endif /* !SKIP_BIOSTEST */
 685  
 686 #if !defined(PORTBASE)
 687       printk("porttest: ");
 688       for( i=0; i<PORT_COUNT && !aha152x_porttest(ports[i]); i++)
 689         ;
 690 
 691       if(i==PORT_COUNT)
 692         {
 693           printk("failed\n");
 694           return 0;
 695         }
 696       else
 697         port_base=ports[i];
 698       printk("ok, ");
 699 #else
 700       port_base=PORTBASE;
 701 #endif /* !PORTBASE */
 702 
 703 #if defined(AUTOCONF)
 704 
 705       conf.cf_port = (GETPORT(PORTA)<<8) + GETPORT(PORTB);
 706 
 707       interrupt_level = irqs[conf.cf_irq];
 708       this_host       = conf.cf_id;
 709       can_disconnect  = conf.cf_tardisc;
 710       can_doparity    = !conf.cf_parity;
 711 
 712       printk("auto configuration: ok, ");
 713 
 714 #endif /* AUTOCONF */
 715 
 716 #if defined(IRQ)
 717       interrupt_level = IRQ; 
 718 #endif
 719 
 720 #if defined(SCSI_ID)
 721       this_host = SCSI_ID;
 722 #endif
 723 
 724 #if defined(RECONNECT)
 725       can_disconnect=RECONNECT;
 726 #endif
 727 
 728 #if defined(PARITY)
 729       can_doparity=PARITY;
 730 #endif
 731     }
 732 
 733   printk("detection complete\n");
 734  
 735   ok = request_irq(interrupt_level, aha152x_intr, SA_INTERRUPT, "aha152x");
 736   
 737   if(ok<0)
 738     {
 739       if(ok == -EINVAL)
 740         {
 741            printk("aha152x: bad IRQ %d.\n", interrupt_level);
 742            printk("         Contact author.\n");
 743         }
 744       else
 745         if( ok == -EBUSY)
 746           printk( "aha152x: IRQ %d already in use. Configure another.\n",
 747                   interrupt_level);
 748         else
 749           {
 750             printk( "\naha152x: Unexpected error code on requesting IRQ %d.\n",
 751                     interrupt_level);
 752             printk("         Contact author.\n");
 753           }
 754       panic("aha152x: driver needs an IRQ.\n");
 755     }
 756 
 757   SETPORT( SCSIID, this_host << 4 );
 758   tpnt->this_id=this_host;
 759   
 760   if(can_disconnect)
 761     tpnt->can_queue=AHA152X_MAXQUEUE;
 762 
 763   /* RESET OUT */
 764   SETBITS(SCSISEQ, SCSIRSTO );
 765   do_pause(30);
 766   CLRBITS(SCSISEQ, SCSIRSTO );
 767   do_pause(60);
 768 
 769   aha152x_reset(NULL);
 770 
 771   printk("aha152x: vital data: PORTBASE=0x%03x, IRQ=%d, SCSI ID=%d, reconnect=%s, parity=%s\n",
 772          port_base,
 773          interrupt_level,
 774          this_host,
 775          can_disconnect ? "enabled" : "disabled",
 776          can_doparity ? "enabled" : "disabled");
 777 
 778   request_region(port_base, 0x20, "aha152x");        /* Register */
 779 
 780   hreg = scsi_register(tpnt, 0);
 781   hreg->io_port = port_base;
 782   hreg->n_io_port = 0x20;
 783   hreg->irq = interrupt_level;
 784   
 785   /* not expecting any interrupts */
 786   SETPORT(SIMODE0, 0);
 787   SETPORT(SIMODE1, 0);
 788 
 789   SETBITS( DMACNTRL0, INTEN);
 790   return 1;
 791 }
 792 
 793 /* 
 794  *  Queue a command and setup interrupts for a free bus.
 795  */
 796 int aha152x_queue( Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *))
     /* [previous][next][first][last][top][bottom][index][help] */
 797 {
 798   unsigned long flags;
 799 
 800 #if defined(DEBUG_RACE)
 801   enter_driver("queue");
 802 #else
 803 #if defined(DEBUG_QUEUE)
 804   if(aha152x_debug & debug_queue)
 805     printk("aha152x: queue(), ");
 806 #endif
 807 #endif
 808 
 809 #if defined(DEBUG_QUEUE)
 810   if(aha152x_debug & debug_queue)
 811   {
 812     printk( "SCpnt (target = %d lun = %d cmnd = ", SCpnt->target, SCpnt->lun);
 813     print_command(SCpnt->cmnd);
 814     printk( ", cmd_len=%d, pieces = %d size = %u), ",
 815             SCpnt->cmd_len, SCpnt->use_sg, SCpnt->request_bufflen );
 816     disp_ports();
 817   }
 818 #endif
 819 
 820   SCpnt->scsi_done =       done;
 821 
 822   /* setup scratch area
 823      SCp.ptr              : buffer pointer
 824      SCp.this_residual    : buffer length
 825      SCp.buffer           : next buffer
 826      SCp.buffers_residual : left buffers in list
 827      SCp.phase            : current state of the command */
 828   SCpnt->SCp.phase = not_issued;
 829   if (SCpnt->use_sg)
 830     {
 831       SCpnt->SCp.buffer           = (struct scatterlist *)SCpnt->request_buffer;
 832       SCpnt->SCp.ptr              = SCpnt->SCp.buffer->address;
 833       SCpnt->SCp.this_residual    = SCpnt->SCp.buffer->length;
 834       SCpnt->SCp.buffers_residual = SCpnt->use_sg - 1;
 835     }
 836   else
 837     {
 838       SCpnt->SCp.ptr              = (char *)SCpnt->request_buffer;
 839       SCpnt->SCp.this_residual    = SCpnt->request_bufflen;
 840       SCpnt->SCp.buffer           = NULL;
 841       SCpnt->SCp.buffers_residual = 0;
 842     }
 843           
 844   SCpnt->SCp.Status              = CHECK_CONDITION;
 845   SCpnt->SCp.Message             = 0;
 846   SCpnt->SCp.have_data_in        = 0;
 847   SCpnt->SCp.sent_command        = 0;
 848 
 849   /* Turn led on, when this is the first command. */
 850   save_flags(flags);
 851   cli();
 852   commands++;
 853   if(commands==1)
 854     SETPORT( PORTA, 1 );
 855 
 856 #if defined(DEBUG_QUEUES)
 857   if(aha152x_debug & debug_queues)
 858     printk("i+ (%d), ", commands );
 859 #endif
 860   append_SC( &issue_SC, SCpnt);
 861   
 862   /* Enable bus free interrupt, when we aren't currently on the bus */
 863   if(!current_SC)
 864     {
 865       SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
 866       SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
 867     }
 868   restore_flags(flags);
 869 
 870 #if defined(DEBUG_RACE)
 871   leave_driver("queue");
 872 #endif
 873 
 874   return 0;
 875 }
 876 
 877 /*
 878  *  We only support command in interrupt-driven fashion
 879  */
 880 int aha152x_command( Scsi_Cmnd *SCpnt )
     /* [previous][next][first][last][top][bottom][index][help] */
 881 {
 882   printk( "aha152x: interrupt driven driver; use aha152x_queue()\n" );
 883   return -1;
 884 }
 885 
 886 /*
 887  *  Abort a queued command
 888  *  (commands that are on the bus can't be aborted easily)
 889  */
 890 int aha152x_abort( Scsi_Cmnd *SCpnt)
     /* [previous][next][first][last][top][bottom][index][help] */
 891 {
 892   unsigned long flags;
 893   Scsi_Cmnd *ptr, *prev;
 894 
 895   save_flags(flags);
 896   cli();
 897 
 898 #if defined(DEBUG_ABORT)
 899   if(aha152x_debug & debug_abort)
 900   { 
 901     printk("aha152x: abort(), SCpnt=0x%08x, ", (unsigned int) SCpnt );
 902 
 903     show_queues();
 904   }
 905 #endif
 906 
 907   /* look for command in issue queue */
 908   for( ptr=issue_SC, prev=NULL;
 909        ptr && ptr!=SCpnt;
 910        prev=ptr, ptr=(Scsi_Cmnd *) ptr->host_scribble)
 911     ;
 912 
 913   if(ptr)
 914     {
 915       /* dequeue */
 916       if(prev)
 917         prev->host_scribble = ptr->host_scribble;
 918       else
 919         issue_SC = (Scsi_Cmnd *) ptr->host_scribble;
 920       restore_flags(flags);
 921 
 922       ptr->host_scribble = NULL;
 923       ptr->result = DID_ABORT << 16;
 924       ptr->done(ptr);
 925       return SCSI_ABORT_SUCCESS;
 926     }
 927 
 928   /* if the bus is busy or a command is currently processed,
 929      we can't do anything more */
 930   if ( TESTLO(SSTAT1, BUSFREE) || (current_SC && current_SC!=SCpnt))
 931     {
 932       /* fail abortion, if bus is busy */
 933 
 934       if(!current_SC)
 935         printk("bus busy w/o current command, ");
 936  
 937       restore_flags(flags);
 938       return SCSI_ABORT_BUSY;
 939     }
 940 
 941   /* bus is free */
 942 
 943   if(current_SC)
 944   { 
 945     /* target entered bus free before COMMAND COMPLETE, nothing to abort */
 946     restore_flags(flags);
 947     current_SC->result = DID_ERROR << 16;
 948     current_SC->done(current_SC);
 949     current_SC = (Scsi_Cmnd *) NULL;
 950     return SCSI_ABORT_SUCCESS;
 951   }
 952 
 953   /* look for command in disconnected queue */
 954   for( ptr=disconnected_SC, prev=NULL;
 955        ptr && ptr!=SCpnt;
 956        prev=ptr, ptr=(Scsi_Cmnd *) ptr->host_scribble)
 957     ;
 958 
 959   if(ptr)
 960     if(!aborting)
 961       {
 962         /* dequeue */
 963         if(prev)
 964           prev->host_scribble = ptr->host_scribble;
 965         else
 966           disconnected_SC = (Scsi_Cmnd *) ptr->host_scribble;
 967   
 968         /* set command current and initiate selection,
 969            let the interrupt routine take care of the abortion */
 970         current_SC     = ptr;
 971         ptr->SCp.phase = in_selection|aborted;
 972         SETPORT( SCSIID, (this_host << OID_) | current_SC->target );
 973   
 974         /* enable interrupts for SELECTION OUT DONE and SELECTION TIME OUT */
 975         SETPORT( SIMODE0, ENSELDO | (disconnected_SC ? ENSELDI : 0) );
 976         SETPORT( SIMODE1, ENSELTIMO );
 977   
 978         /* Enable SELECTION OUT sequence */
 979         SETBITS(SCSISEQ, ENSELO | ENAUTOATNO );
 980   
 981         SETBITS( DMACNTRL0, INTEN );
 982         abort_result=SCSI_ABORT_SUCCESS;
 983         aborting++;
 984         abortion_complete=0;
 985 
 986         sti();  /* Hi Eric, guess what ;-) */
 987   
 988         /* sleep until the abortion is complete */
 989         while(!abortion_complete)
 990           barrier();
 991         aborting=0;
 992         return abort_result;
 993       }
 994     else
 995       {
 996         /* we're already aborting a command */
 997         restore_flags(flags);
 998         return SCSI_ABORT_BUSY;
 999       }
1000 
1001   /* command wasn't found */
1002   printk("command not found\n");
1003   restore_flags(flags);
1004   return SCSI_ABORT_NOT_RUNNING;
1005 }
1006 
1007 /*
1008  *  Restore default values to the AIC-6260 registers and reset the fifos
1009  */
1010 static void aha152x_reset_ports(void)
     /* [previous][next][first][last][top][bottom][index][help] */
1011 {
1012   /* disable interrupts */
1013   SETPORT(DMACNTRL0, RSTFIFO);
1014 
1015   SETPORT(SCSISEQ, 0);
1016 
1017   SETPORT(SXFRCTL1, 0);
1018   SETPORT( SCSISIG, 0);
1019   SETPORT(SCSIRATE, 0);
1020 
1021   /* clear all interrupt conditions */
1022   SETPORT(SSTAT0, 0x7f);
1023   SETPORT(SSTAT1, 0xef);
1024 
1025   SETPORT(SSTAT4, SYNCERR|FWERR|FRERR);
1026 
1027   SETPORT(DMACNTRL0, 0);
1028   SETPORT(DMACNTRL1, 0);
1029 
1030   SETPORT(BRSTCNTRL, 0xf1);
1031 
1032   /* clear SCSI fifo and transfer count */
1033   SETPORT(SXFRCTL0, CH1|CLRCH1|CLRSTCNT);
1034   SETPORT(SXFRCTL0, CH1);
1035 
1036   /* enable interrupts */
1037   SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
1038   SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
1039 }
1040 
1041 /*
1042  *  Reset registers, reset a hanging bus and
1043  *  kill active and disconnected commands for target w/o soft reset
1044  */
1045 int aha152x_reset(Scsi_Cmnd * __unused)
     /* [previous][next][first][last][top][bottom][index][help] */
1046 {
1047   unsigned long flags;
1048   Scsi_Cmnd *ptr, *prev, *next;
1049 
1050   aha152x_reset_ports();
1051 
1052   /* Reset, if bus hangs */
1053   if( TESTLO( SSTAT1, BUSFREE ) )
1054     {
1055        CLRBITS( DMACNTRL0, INTEN );
1056 
1057 #if defined(DEBUG_RESET)
1058   if(aha152x_debug & debug_reset)
1059   {
1060        printk("aha152x: reset(), bus not free: SCSI RESET OUT\n");
1061        show_queues();
1062   }
1063 #endif
1064 
1065        if(current_SC && !current_SC->device->soft_reset)
1066          {
1067            current_SC->host_scribble = NULL;
1068            current_SC->result = DID_RESET << 16;
1069            current_SC->done(current_SC);
1070            current_SC=NULL;
1071          }
1072 
1073        save_flags(flags);
1074        cli();
1075        prev=NULL; ptr=disconnected_SC;
1076        while(ptr)
1077          {
1078            if(!ptr->device->soft_reset)
1079              {
1080                if(prev)
1081                  prev->host_scribble = ptr->host_scribble;
1082                else
1083                  disconnected_SC = (Scsi_Cmnd *) ptr->host_scribble;
1084 
1085                next = (Scsi_Cmnd *) ptr->host_scribble;
1086   
1087                ptr->host_scribble = NULL;
1088                ptr->result        = DID_RESET << 16;
1089                ptr->done(ptr);
1090   
1091                ptr = next; 
1092              }
1093            else
1094              {
1095                prev=ptr;
1096                ptr = (Scsi_Cmnd *) ptr->host_scribble;
1097              }
1098          }
1099        restore_flags(flags);
1100 
1101 #if defined( DEBUG_RESET )
1102        if(aha152x_debug & debug_reset)
1103        {
1104          printk("commands on targets w/ soft-resets:\n");
1105          show_queues();
1106        }
1107 #endif
1108 
1109        /* RESET OUT */
1110        SETPORT(SCSISEQ, SCSIRSTO);
1111        do_pause(30);
1112        SETPORT(SCSISEQ, 0);
1113        do_pause(60);
1114 
1115        SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
1116        SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
1117 
1118        SETPORT( DMACNTRL0, INTEN );
1119     }
1120 
1121   return SCSI_RESET_SUCCESS;
1122 }
1123 
1124 /*
1125  * Return the "logical geometry"
1126  */
1127 int aha152x_biosparam(Scsi_Disk * disk, kdev_t dev, int *info_array )
     /* [previous][next][first][last][top][bottom][index][help] */
1128 {
1129   int size = disk->capacity;
1130 
1131 #if defined(DEBUG_BIOSPARAM)
1132   if(aha152x_debug & debug_biosparam)
1133     printk("aha152x_biosparam: dev=%s, size=%d, ",
1134            kdevname(dev), size);
1135 #endif
1136   
1137 /* I took this from other SCSI drivers, since it provides
1138    the correct data for my devices. */
1139   info_array[0]=64;
1140   info_array[1]=32;
1141   info_array[2]=size>>11;
1142 
1143 #if defined(DEBUG_BIOSPARAM)
1144   if(aha152x_debug & debug_biosparam)
1145   {
1146     printk("bios geometry: head=%d, sec=%d, cyl=%d\n",
1147            info_array[0], info_array[1], info_array[2]);
1148     printk("WARNING: check, if the bios geometry is correct.\n");
1149   }
1150 #endif
1151 
1152   return 0;
1153 }
1154 
1155 /*
1156  *  Internal done function
1157  */
1158 void aha152x_done( int error )
     /* [previous][next][first][last][top][bottom][index][help] */
1159 {
1160   unsigned long flags;
1161   Scsi_Cmnd *done_SC;
1162 
1163 #if defined(DEBUG_DONE)
1164   if(aha152x_debug & debug_done)
1165   {
1166     printk("\naha152x: done(), ");
1167     disp_ports();
1168   }
1169 #endif
1170 
1171   if (current_SC)
1172     {
1173 #if defined(DEBUG_DONE)
1174       if(aha152x_debug & debug_done)
1175         printk("done(%x), ", error);
1176 #endif
1177 
1178       save_flags(flags);
1179       cli();
1180 
1181       done_SC = current_SC;
1182       current_SC = NULL;
1183 
1184       /* turn led off, when no commands are in the driver */
1185       commands--;
1186       if(!commands)
1187         SETPORT( PORTA, 0 );                                  /* turn led off */
1188 
1189 #if defined(DEBUG_QUEUES)
1190       if(aha152x_debug & debug_queues) 
1191         printk("ok (%d), ", commands);
1192 #endif
1193       restore_flags(flags);
1194 
1195       SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
1196       SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
1197 
1198 #if defined(DEBUG_PHASES)
1199       if(aha152x_debug & debug_phases)
1200         printk("BUS FREE loop, ");
1201 #endif
1202       while( TESTLO( SSTAT1, BUSFREE ) )
1203         ;
1204 #if defined(DEBUG_PHASES)
1205       if(aha152x_debug & debug_phases)
1206         printk("BUS FREE\n");
1207 #endif
1208 
1209       done_SC->result = error;
1210       if(done_SC->scsi_done)
1211         {
1212 #if defined(DEBUG_DONE)
1213           if(aha152x_debug & debug_done)
1214             printk("calling scsi_done, ");
1215 #endif
1216           done_SC->scsi_done( done_SC );
1217 #if defined(DEBUG_DONE)
1218           if(aha152x_debug & debug_done)
1219             printk("done returned, ");
1220 #endif
1221         }
1222       else
1223         panic( "aha152x: current_SC->scsi_done() == NULL" );
1224     }
1225   else
1226     aha152x_panic( "done() called outside of command" );
1227 }
1228 
1229 /*
1230  * Interrupts handler (main routine of the driver)
1231  */
1232 void aha152x_intr( int irqno, struct pt_regs * regs )
     /* [previous][next][first][last][top][bottom][index][help] */
1233 {
1234   unsigned int flags;
1235   int done=0, phase;
1236 
1237 #if defined(DEBUG_RACE)
1238   enter_driver("intr");
1239 #else
1240 #if defined(DEBUG_INTR)
1241   if(aha152x_debug & debug_intr)
1242     printk("\naha152x: intr(), ");
1243 #endif
1244 #endif
1245 
1246   /* no more interrupts from the controller, while we busy.
1247      INTEN has to be restored, when we're ready to leave
1248      intr(). To avoid race conditions we have to return
1249      immediately afterwards. */
1250   CLRBITS( DMACNTRL0, INTEN);
1251   sti();  /* Yes, sti() really needs to be here */
1252 
1253   /* disconnected target is trying to reconnect.
1254      Only possible, if we have disconnected nexuses and
1255      nothing is occupying the bus.
1256   */
1257   if( TESTHI( SSTAT0, SELDI ) &&
1258       disconnected_SC &&
1259       ( !current_SC || ( current_SC->SCp.phase & in_selection ) )
1260     )
1261     {
1262       int identify_msg, target, i;
1263 
1264       /* Avoid conflicts when a target reconnects
1265          while we are trying to connect to another. */
1266       if(current_SC)
1267         {
1268 #if defined(DEBUG_QUEUES)
1269           if(aha152x_debug & debug_queues)
1270           printk("i+, ");
1271 #endif
1272           save_flags(flags);
1273           cli();
1274           append_SC( &issue_SC, current_SC);
1275           current_SC=NULL;
1276           restore_flags(flags);
1277         }
1278 
1279       /* disable sequences */
1280       SETPORT( SCSISEQ, 0 );
1281       SETPORT( SSTAT0, CLRSELDI );
1282       SETPORT( SSTAT1, CLRBUSFREE );
1283 
1284 #if defined(DEBUG_QUEUES) || defined(DEBUG_PHASES)
1285       if(aha152x_debug & (debug_queues|debug_phases))
1286         printk("reselected, ");
1287 #endif
1288 
1289       i = GETPORT(SELID) & ~(1 << this_host);
1290       target=0;
1291       if(i)
1292         for( ; (i & 1)==0; target++, i>>=1)
1293           ;
1294       else
1295         aha152x_panic("reconnecting target unknown");
1296 
1297 #if defined(DEBUG_QUEUES)
1298       if(aha152x_debug & debug_queues)
1299         printk("SELID=%02x, target=%d, ", GETPORT(SELID), target );
1300 #endif
1301       SETPORT( SCSIID, (this_host << OID_) | target );
1302       SETPORT( SCSISEQ, ENRESELI );
1303 
1304       if(TESTLO( SSTAT0, SELDI ))
1305         aha152x_panic("RESELI failed");
1306 
1307       SETPORT( SCSISIG, P_MSGI );
1308 
1309       /* Get identify message */
1310       if((i=getphase())!=P_MSGI)
1311         {
1312           printk("target doesn't enter MSGI to identify (phase=%02x)\n", i);
1313           aha152x_panic("unknown lun");
1314         }
1315       SETPORT( SCSISEQ, 0 );
1316 
1317       SETPORT( SXFRCTL0, CH1);
1318 
1319       identify_msg = GETPORT(SCSIBUS);
1320 
1321       if(!(identify_msg & IDENTIFY_BASE))
1322         {
1323           printk("target=%d, inbound message (%02x) != IDENTIFY\n",
1324                  target, identify_msg);
1325           aha152x_panic("unknown lun");
1326         }
1327 
1328       make_acklow();
1329       getphase();
1330 
1331 #if defined(DEBUG_QUEUES)
1332       if(aha152x_debug & debug_queues)
1333         printk("identify=%02x, lun=%d, ", identify_msg, identify_msg & 0x3f );
1334 #endif
1335 
1336       save_flags(flags);
1337       cli();
1338 
1339 #if defined(DEBUG_QUEUES)
1340       if(aha152x_debug & debug_queues)
1341         printk("d-, ");
1342 #endif
1343       current_SC = remove_SC( &disconnected_SC,
1344                               target,
1345                               identify_msg & 0x3f );
1346 
1347       if(!current_SC)
1348         {
1349           printk("lun=%d, ", identify_msg & 0x3f );
1350           aha152x_panic("no disconnected command for that lun");
1351         }
1352 
1353       current_SC->SCp.phase &= ~disconnected;
1354       restore_flags(flags);
1355 
1356       SETPORT( SIMODE0, 0 );
1357       SETPORT( SIMODE1, ENPHASEMIS|ENBUSFREE );
1358 #if defined(DEBUG_RACE)
1359       leave_driver("(reselected) intr");
1360 #endif
1361       SETBITS( DMACNTRL0, INTEN);
1362       return;
1363     }
1364   
1365   /* Check, if we aren't busy with a command */
1366   if(!current_SC)
1367     {
1368       /* bus is free to issue a queued command */
1369       if(TESTHI( SSTAT1, BUSFREE) && issue_SC)
1370         {
1371           save_flags(flags);
1372           cli();
1373 #if defined(DEBUG_QUEUES)
1374           if(aha152x_debug & debug_queues)
1375             printk("i-, ");
1376 #endif
1377           current_SC = remove_first_SC( &issue_SC );
1378           restore_flags(flags);
1379 
1380 #if defined(DEBUG_INTR) || defined(DEBUG_SELECTION) || defined(DEBUG_PHASES)
1381           if(aha152x_debug & (debug_intr|debug_selection|debug_phases))
1382             printk("issuing command, ");
1383 #endif
1384           current_SC->SCp.phase = in_selection;
1385 
1386   #if defined(DEBUG_INTR) || defined(DEBUG_SELECTION) || defined(DEBUG_PHASES)
1387           if(aha152x_debug & (debug_intr|debug_selection|debug_phases))
1388             printk("selecting %d, ", current_SC->target); 
1389   #endif
1390           SETPORT( SCSIID, (this_host << OID_) | current_SC->target );
1391 
1392           /* Enable interrupts for SELECTION OUT DONE and SELECTION OUT INITIATED */
1393           SETPORT( SXFRCTL1, can_doparity ? (ENSPCHK|ENSTIMER) : ENSTIMER);
1394 
1395           /* enable interrupts for SELECTION OUT DONE and SELECTION TIME OUT */
1396           SETPORT( SIMODE0, ENSELDO | (disconnected_SC ? ENSELDI : 0) );
1397           SETPORT( SIMODE1, ENSELTIMO );
1398 
1399           /* Enable SELECTION OUT sequence */
1400           SETBITS(SCSISEQ, ENSELO | ENAUTOATNO );
1401         
1402   #if defined(DEBUG_RACE)
1403           leave_driver("(selecting) intr");
1404   #endif
1405           SETBITS( DMACNTRL0, INTEN );
1406           return;
1407         }
1408 
1409       /* No command we are busy with and no new to issue */
1410       printk("aha152x: ignoring spurious interrupt, nothing to do\n");
1411       return;
1412     }
1413 
1414   /* the bus is busy with something */
1415 
1416 #if defined(DEBUG_INTR)
1417   if(aha152x_debug & debug_intr)
1418     disp_ports();
1419 #endif
1420 
1421   /* we are waiting for the result of a selection attempt */
1422   if(current_SC->SCp.phase & in_selection)
1423     {
1424       if( TESTLO( SSTAT1, SELTO ) )
1425         /* no timeout */
1426         if( TESTHI( SSTAT0, SELDO ) )
1427           {
1428             /* clear BUS FREE interrupt */
1429             SETPORT( SSTAT1, CLRBUSFREE);
1430 
1431             /* Disable SELECTION OUT sequence */
1432             CLRBITS(SCSISEQ, ENSELO|ENAUTOATNO );
1433 
1434             /* Disable SELECTION OUT DONE interrupt */
1435             CLRBITS(SIMODE0, ENSELDO);
1436             CLRBITS(SIMODE1, ENSELTIMO);
1437 
1438             if( TESTLO(SSTAT0, SELDO) )
1439               {
1440                 printk("aha152x: passing bus free condition\n");
1441 
1442 #if defined(DEBUG_RACE)
1443                 leave_driver("(passing bus free) intr");
1444 #endif
1445                 SETBITS( DMACNTRL0, INTEN);
1446 
1447                 if(current_SC->SCp.phase & aborted)
1448                   {
1449                     abort_result=SCSI_ABORT_ERROR;
1450                     abortion_complete++;
1451                   }
1452 
1453                 aha152x_done( DID_NO_CONNECT << 16 );
1454                 return;
1455               }
1456 #if defined(DEBUG_SELECTION) || defined(DEBUG_PHASES)
1457             if(aha152x_debug & (debug_selection|debug_phases))
1458               printk("SELDO (SELID=%x), ", GETPORT(SELID));
1459 #endif
1460 
1461             /* selection was done */
1462             SETPORT( SSTAT0, CLRSELDO );
1463 
1464 #if defined(DEBUG_ABORT)
1465             if((aha152x_debug & debug_abort) && (current_SC->SCp.phase & aborted))
1466               printk("(ABORT) target selected, ");
1467 #endif
1468 
1469             current_SC->SCp.phase &= ~in_selection;
1470             current_SC->SCp.phase |= in_other;
1471 
1472 #if defined(DEBUG_RACE)
1473             leave_driver("(SELDO) intr");
1474 #endif
1475 
1476             SETPORT( SCSISIG, P_MSGO );
1477 
1478             SETPORT( SIMODE0, 0 );
1479             SETPORT( SIMODE1, ENREQINIT|ENBUSFREE );
1480             SETBITS( DMACNTRL0, INTEN);
1481             return;
1482           }
1483         else
1484           aha152x_panic("neither timeout nor selection\007");
1485       else
1486         {
1487 #if defined(DEBUG_SELECTION) || defined(DEBUG_PHASES)
1488           if(aha152x_debug & (debug_selection|debug_phases))
1489           printk("SELTO, ");
1490 #endif
1491           /* end selection attempt */
1492           CLRBITS(SCSISEQ, ENSELO|ENAUTOATNO );
1493 
1494           /* timeout */
1495           SETPORT( SSTAT1, CLRSELTIMO );
1496 
1497           SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
1498           SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
1499           SETBITS( DMACNTRL0, INTEN );
1500 #if defined(DEBUG_RACE)
1501           leave_driver("(SELTO) intr");
1502 #endif
1503 
1504           if(current_SC->SCp.phase & aborted)
1505             {
1506 #if defined(DEBUG_ABORT)
1507               if(aha152x_debug & debug_abort)
1508                 printk("(ABORT) selection timeout, ");
1509 #endif
1510               abort_result=SCSI_ABORT_ERROR;
1511               abortion_complete++;
1512             }
1513 
1514           if( TESTLO( SSTAT0, SELINGO ) )
1515             /* ARBITRATION not won */
1516             aha152x_done( DID_BUS_BUSY << 16 );
1517           else
1518             /* ARBITRATION won, but SELECTION failed */
1519             aha152x_done( DID_NO_CONNECT << 16 );
1520           return;
1521         }
1522     }
1523 
1524   /* enable interrupt, when target leaves current phase */
1525   phase = getphase();
1526   if(!(phase & ~P_MASK))                                      /* "real" phase */
1527     SETPORT(SCSISIG, phase);
1528   SETPORT(SSTAT1, CLRPHASECHG);
1529   current_SC->SCp.phase =
1530     (current_SC->SCp.phase & ~((P_MASK|1)<<16)) | (phase << 16 );
1531 
1532   /* information transfer phase */
1533   switch( phase )
1534     {
1535     case P_MSGO:                                               /* MESSAGE OUT */
1536       {
1537         unsigned char message;
1538 
1539 #if defined(DEBUG_INTR) || defined(DEBUG_MSGO) || defined(DEBUG_PHASES)
1540         if(aha152x_debug & (debug_intr|debug_msgo|debug_phases))
1541           printk("MESSAGE OUT, ");
1542 #endif
1543 
1544         if( current_SC->SCp.phase & aborted )
1545           {
1546 #if defined(DEBUG_MSGO) || defined(DEBUG_ABORT)
1547             if(aha152x_debug & (debug_msgo|debug_abort))
1548               printk("ABORT, ");
1549 #endif
1550             message=ABORT;
1551           }
1552         else
1553           /* If we didn't identify yet, do it. Otherwise there's nothing to do,
1554              but reject (probably we got an message before, that we have to
1555              reject (SDTR, WDTR, etc.) */
1556           if( !(current_SC->SCp.phase & sent_ident))
1557             {
1558               message=IDENTIFY(can_disconnect,current_SC->lun);
1559 #if defined(DEBUG_MSGO)
1560               if(aha152x_debug & debug_msgo)
1561                 printk("IDENTIFY (reconnect=%s;lun=%d), ", 
1562                         can_disconnect ? "enabled" : "disabled", current_SC->lun);
1563 #endif
1564             }
1565           else
1566             {
1567               message=MESSAGE_REJECT;
1568 #if defined(DEBUG_MSGO)
1569               if(aha152x_debug & debug_msgo)
1570                 printk("REJECT, ");
1571 #endif
1572             }
1573           
1574         CLRBITS( SXFRCTL0, ENDMA);
1575 
1576         SETPORT( SIMODE0, 0 );
1577         SETPORT( SIMODE1, ENPHASEMIS|ENREQINIT|ENBUSFREE );
1578 
1579         /* wait for data latch to become ready or a phase change */
1580         while( TESTLO( DMASTAT, INTSTAT ) )
1581           ;
1582 
1583         if( TESTHI( SSTAT1, PHASEMIS ) )
1584           aha152x_panic("unable to send message");
1585 
1586         /* Leave MESSAGE OUT after transfer */
1587         SETPORT( SSTAT1, CLRATNO);
1588 
1589         SETPORT( SCSIDAT, message );
1590 
1591         make_acklow();
1592         getphase();
1593 
1594         if(message==IDENTIFY(can_disconnect,current_SC->lun))
1595           current_SC->SCp.phase |= sent_ident;
1596 
1597         if(message==ABORT)
1598           {
1599             /* revive abort(); abort() enables interrupts */
1600             abort_result=SCSI_ABORT_SUCCESS;
1601             abortion_complete++;
1602 
1603             current_SC->SCp.phase = (current_SC->SCp.phase & ~(P_MASK<<16));
1604 
1605             /* exit */
1606             SETBITS( DMACNTRL0, INTEN );
1607 #if defined(DEBUG_RACE)
1608             leave_driver("(ABORT) intr");
1609 #endif
1610             aha152x_done(DID_ABORT<<16);
1611             return;
1612           }
1613       }
1614       break;
1615 
1616     case P_CMD:                                          /* COMMAND phase */
1617 #if defined(DEBUG_INTR) || defined(DEBUG_CMD) || defined(DEBUG_PHASES)
1618       if(aha152x_debug & (debug_intr|debug_cmd|debug_phases))
1619         printk("COMMAND, ");
1620 #endif
1621       if( !(current_SC->SCp.sent_command) )
1622         {
1623           if(GETPORT(FIFOSTAT) || GETPORT(SSTAT2) & (SFULL|SFCNT))
1624             printk("aha152x: P_CMD: %d(%d) bytes left in FIFO, resetting\n",
1625                    GETPORT(FIFOSTAT), GETPORT(SSTAT2) & (SFULL|SFCNT));
1626 
1627           /* reset fifo and enable writes */
1628           SETPORT(DMACNTRL0, WRITE_READ|RSTFIFO);
1629           SETPORT(DMACNTRL0, ENDMA|WRITE_READ);
1630 
1631           /* clear transfer count and scsi fifo */
1632           SETPORT(SXFRCTL0, CH1|CLRSTCNT|CLRCH1 );
1633           SETPORT(SXFRCTL0, SCSIEN|DMAEN|CH1);
1634   
1635           /* missing phase raises INTSTAT */
1636           SETPORT( SIMODE0, 0 );
1637           SETPORT( SIMODE1, ENPHASEMIS|ENBUSFREE );
1638   
1639 #if defined(DEBUG_CMD)
1640           if(aha152x_debug & debug_cmd)
1641             printk("waiting, ");
1642 #endif
1643           /* wait for FIFO to get empty */
1644           while( TESTLO ( DMASTAT, DFIFOEMP|INTSTAT ) )
1645             ;
1646   
1647           if( TESTHI( SSTAT1, PHASEMIS ) )
1648             aha152x_panic("target left COMMAND phase");
1649 
1650 #if defined(DEBUG_CMD)
1651           if(aha152x_debug & debug_cmd)
1652           {
1653             printk("DFIFOEMP, outsw (%d bytes, %d words), ",
1654                    current_SC->cmd_len, current_SC->cmd_len >> 1 );
1655             disp_ports();
1656           }
1657 #endif
1658   
1659           outsw( DATAPORT, &current_SC->cmnd, current_SC->cmd_len >> 1 );
1660 
1661 #if defined(DEBUG_CMD)
1662           if(aha152x_debug & debug_cmd)
1663           {
1664             printk("FCNT=%d, STCNT=%d, ", GETPORT(FIFOSTAT), GETSTCNT() );
1665             disp_ports();
1666           }
1667 #endif
1668 
1669 #if defined(DEBUG_CMD)
1670           if(aha152x_debug & debug_cmd)
1671             printk("waiting for SEMPTY, ");
1672 #endif
1673 
1674           /* wait for SCSI FIFO to get empty.
1675              very important to send complete commands. */
1676           while( TESTLO ( SSTAT2, SEMPTY ) )
1677             ;
1678 
1679 #if defined(DEBUG_CMD)
1680           if(aha152x_debug & debug_cmd)
1681             printk("SEMPTY, ");
1682 #endif
1683 
1684           CLRBITS(SXFRCTL0, SCSIEN|DMAEN);
1685           /* transfer can be considered ended, when SCSIEN reads back zero */
1686           while( TESTHI( SXFRCTL0, SCSIEN ) )
1687             ;
1688 
1689 #if defined(DEBUG_CMD)
1690           if(aha152x_debug & debug_cmd)
1691             printk("!SEMPTY, ");
1692 #endif
1693 
1694           CLRBITS(DMACNTRL0, ENDMA);
1695 
1696 #if defined(DEBUG_CMD) || defined(DEBUG_INTR)
1697           if(debug_cmd & debug_intr)
1698             printk("sent %d/%d command bytes, ", GETSTCNT(),
1699                    current_SC->cmd_len);
1700 #endif
1701 
1702         }
1703       else
1704         aha152x_panic("Nothing to sent while in COMMAND OUT");
1705       break;
1706 
1707     case P_MSGI:                                          /* MESSAGE IN phase */
1708 #if defined(DEBUG_INTR) || defined(DEBUG_MSGI) || defined(DEBUG_PHASES)
1709       if(aha152x_debug & (debug_intr|debug_msgi|debug_phases))
1710         printk("MESSAGE IN, ");
1711 #endif
1712       SETPORT( SXFRCTL0, CH1);
1713 
1714       SETPORT( SIMODE0, 0);
1715       SETPORT( SIMODE1, ENBUSFREE);
1716   
1717       while( phase == P_MSGI ) 
1718         {
1719           current_SC->SCp.Message = GETPORT( SCSIBUS );
1720           switch(current_SC->SCp.Message)
1721             {
1722             case DISCONNECT:
1723 #if defined(DEBUG_MSGI) || defined(DEBUG_PHASES)
1724               if(aha152x_debug & (debug_msgi|debug_phases))
1725                 printk("target disconnected, ");
1726 #endif
1727               current_SC->SCp.Message = 0;
1728               current_SC->SCp.phase   |= disconnected;
1729               if(!can_disconnect)
1730                 aha152x_panic("target was not allowed to disconnect");
1731               break;
1732         
1733             case COMMAND_COMPLETE:
1734 #if defined(DEBUG_MSGI) || defined(DEBUG_PHASES)
1735               if(aha152x_debug & (debug_msgi|debug_phases))
1736                 printk("inbound message ( COMMAND COMPLETE ), ");
1737 #endif
1738               done++;
1739               break;
1740 
1741             case MESSAGE_REJECT:
1742 #if defined(DEBUG_MSGI)
1743               if(aha152x_debug & debug_msgi)
1744                 printk("inbound message ( MESSAGE REJECT ), ");
1745 #endif
1746               break;
1747 
1748             case SAVE_POINTERS:
1749 #if defined(DEBUG_MSGI)
1750               if(aha152x_debug & debug_msgi)
1751                 printk("inbound message ( SAVE DATA POINTERS ), ");
1752 #endif
1753               break;
1754 
1755             case EXTENDED_MESSAGE:
1756               { 
1757                 int           i, code;
1758 
1759 #if defined(DEBUG_MSGI)
1760                 if(aha152x_debug & debug_msgi)
1761                   printk("inbound message ( EXTENDED MESSAGE ), ");
1762 #endif
1763                 make_acklow();
1764                 if(getphase()!=P_MSGI)
1765                   break;
1766   
1767                 i=GETPORT(SCSIBUS);
1768 
1769 #if defined(DEBUG_MSGI)
1770                 if(aha152x_debug & debug_msgi)
1771                   printk("length (%d), code ( ", i);
1772 #endif
1773 
1774                 make_acklow();
1775                 if(getphase()!=P_MSGI)
1776                   break;
1777 
1778                 code = GETPORT(SCSIBUS);
1779 
1780                 switch( code )
1781                   {
1782                   case 0x00:
1783 #if defined(DEBUG_MSGI)
1784                     if(aha152x_debug & debug_msgi)
1785                       printk("MODIFY DATA POINTER ");
1786 #endif
1787                     SETPORT(SCSISIG, P_MSGI|ATNO);
1788                     break;
1789                   case 0x01:
1790 #if defined(DEBUG_MSGI)
1791                     if(aha152x_debug & debug_msgi)
1792                       printk("SYNCHRONOUS DATA TRANSFER REQUEST ");
1793 #endif
1794                     SETPORT(SCSISIG, P_MSGI|ATNO);
1795                     break;
1796                   case 0x02:
1797 #if defined(DEBUG_MSGI)
1798                     if(aha152x_debug & debug_msgi)
1799                       printk("EXTENDED IDENTIFY ");
1800 #endif
1801                     break;
1802                   case 0x03:
1803 #if defined(DEBUG_MSGI)
1804                     if(aha152x_debug & debug_msgi)
1805                       printk("WIDE DATA TRANSFER REQUEST ");
1806 #endif
1807                     SETPORT(SCSISIG, P_MSGI|ATNO);
1808                     break;
1809                   default:
1810 #if defined(DEBUG_MSGI)
1811                     if(aha152x_debug & debug_msgi)
1812                       if( code & 0x80 )
1813                         printk("reserved (%d) ", code );
1814                       else
1815                         printk("vendor specific (%d) ", code);
1816 #endif
1817                     SETPORT(SCSISIG, P_MSGI|ATNO);
1818                     break;
1819                   }
1820 #if defined(DEBUG_MSGI)
1821                 if(aha152x_debug & debug_msgi)
1822                   printk(" ), data ( ");
1823 #endif
1824                 while( --i && (make_acklow(), getphase()==P_MSGI))
1825                   {
1826 #if defined(DEBUG_MSGI)
1827                     if(aha152x_debug & debug_msgi)
1828                       printk("%x ", GETPORT(SCSIBUS) );
1829 #else
1830                     GETPORT(SCSIBUS);
1831 #endif
1832                   }
1833 #if defined(DEBUG_MSGI)
1834                 if(aha152x_debug & debug_msgi)
1835                   printk(" ), ");
1836 #endif
1837                 /* We reject all extended messages. To do this
1838                    we just enter MSGO by asserting ATN. Since
1839                    we have already identified a REJECT message
1840                    will be sent. */
1841                 SETPORT(SCSISIG, P_MSGI|ATNO);
1842               }
1843               break;
1844        
1845             default:
1846               printk("unsupported inbound message %x, ", current_SC->SCp.Message);
1847               break;
1848 
1849             }
1850 
1851           make_acklow();
1852           phase=getphase();
1853         } 
1854 
1855       /* clear SCSI fifo on BUSFREE */
1856       if(phase==P_BUSFREE)
1857         SETPORT(SXFRCTL0, CH1|CLRCH1);
1858 
1859       if(current_SC->SCp.phase & disconnected)
1860         {
1861           save_flags(flags);
1862           cli();
1863 #if defined(DEBUG_QUEUES)
1864           if(aha152x_debug & debug_queues)
1865             printk("d+, ");
1866 #endif
1867           append_SC( &disconnected_SC, current_SC);
1868           current_SC = NULL;
1869           restore_flags(flags);
1870 
1871           SETBITS( SCSISEQ, ENRESELI );
1872 
1873           SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
1874           SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
1875 
1876           SETBITS( DMACNTRL0, INTEN );
1877           return;
1878         }
1879       break;
1880 
1881     case P_STATUS:                                         /* STATUS IN phase */
1882 #if defined(DEBUG_STATUS) || defined(DEBUG_INTR) || defined(DEBUG_PHASES)
1883       if(aha152x_debug & (debug_status|debug_intr|debug_phases))
1884         printk("STATUS, ");
1885 #endif
1886       SETPORT( SXFRCTL0, CH1);
1887 
1888       SETPORT( SIMODE0, 0 );
1889       SETPORT( SIMODE1, ENREQINIT|ENBUSFREE );
1890 
1891       if( TESTHI( SSTAT1, PHASEMIS ) )
1892         printk("aha152x: passing STATUS phase");
1893         
1894       current_SC->SCp.Status = GETPORT( SCSIBUS );
1895       make_acklow();
1896       getphase();
1897 
1898 #if defined(DEBUG_STATUS)
1899       if(aha152x_debug & debug_status)
1900       {
1901         printk("inbound status ");
1902         print_status( current_SC->SCp.Status );
1903         printk(", ");
1904       }
1905 #endif
1906       break;
1907 
1908     case P_DATAI:                                            /* DATA IN phase */
1909       {
1910         int fifodata, data_count, done;
1911 
1912 #if defined(DEBUG_DATAI) || defined(DEBUG_INTR) || defined(DEBUG_PHASES)
1913         if(aha152x_debug & (debug_datai|debug_intr|debug_phases))
1914           printk("DATA IN, ");
1915 #endif
1916 
1917         if(GETPORT(FIFOSTAT) || GETPORT(SSTAT2) & (SFULL|SFCNT))
1918           printk("aha152x: P_DATAI: %d(%d) bytes left in FIFO, resetting\n",
1919                  GETPORT(FIFOSTAT), GETPORT(SSTAT2) & (SFULL|SFCNT));
1920 
1921         /* reset host fifo */
1922         SETPORT(DMACNTRL0, RSTFIFO);
1923         SETPORT(DMACNTRL0, RSTFIFO|ENDMA);
1924 
1925         SETPORT(SXFRCTL0, CH1|SCSIEN|DMAEN );
1926 
1927         SETPORT( SIMODE0, 0 );
1928         SETPORT( SIMODE1, ENPHASEMIS|ENBUSFREE );
1929 
1930         /* done is set when the FIFO is empty after the target left DATA IN */
1931         done=0;
1932       
1933         /* while the target stays in DATA to transfer data */
1934         while ( !done ) 
1935           {
1936 #if defined(DEBUG_DATAI)
1937             if(aha152x_debug & debug_datai)
1938               printk("expecting data, ");
1939 #endif
1940             /* wait for PHASEMIS or full FIFO */
1941             while( TESTLO ( DMASTAT, DFIFOFULL|INTSTAT ) )
1942               ;
1943 
1944             if( TESTHI( DMASTAT, DFIFOFULL ) )
1945               fifodata=GETPORT(FIFOSTAT);
1946             else
1947               {
1948                 /* wait for SCSI fifo to get empty */
1949                 while( TESTLO( SSTAT2, SEMPTY ) )
1950                   ;
1951 
1952                 /* rest of data in FIFO */
1953                 fifodata=GETPORT(FIFOSTAT);
1954 #if defined(DEBUG_DATAI)
1955                 if(aha152x_debug & debug_datai)
1956                   printk("last transfer, ");
1957 #endif
1958                 done=1;
1959               }
1960   
1961 #if defined(DEBUG_DATAI)
1962             if(aha152x_debug & debug_datai)
1963               printk("fifodata=%d, ", fifodata);
1964 #endif
1965 
1966             while( fifodata && current_SC->SCp.this_residual )
1967               {
1968                 data_count=fifodata;
1969   
1970                 /* limit data transfer to size of first sg buffer */
1971                 if (data_count > current_SC->SCp.this_residual)
1972                   data_count = current_SC->SCp.this_residual;
1973   
1974                 fifodata -= data_count;
1975 
1976 #if defined(DEBUG_DATAI)
1977                 if(aha152x_debug & debug_datai)
1978                   printk("data_count=%d, ", data_count);
1979 #endif
1980   
1981                 if(data_count&1)
1982                   {
1983                     /* get a single byte in byte mode */
1984                     SETBITS(DMACNTRL0, _8BIT );
1985                     *current_SC->SCp.ptr++ = GETPORT( DATAPORT );
1986                     current_SC->SCp.this_residual--;
1987                   }
1988                 if(data_count>1)
1989                   {
1990                     CLRBITS(DMACNTRL0, _8BIT );
1991                     data_count >>= 1; /* Number of words */
1992                     insw( DATAPORT, current_SC->SCp.ptr, data_count );
1993 #if defined(DEBUG_DATAI)
1994                     if(aha152x_debug & debug_datai)
1995 /* show what comes with the last transfer */
1996                       if(done)
1997                         {
1998                           int           i;
1999                           unsigned char *data;
2000   
2001                           printk("data on last transfer (%d bytes: ",
2002                                  2*data_count);
2003                           data = (unsigned char *) current_SC->SCp.ptr;
2004                           for( i=0; i<2*data_count; i++)
2005                             printk("%2x ", *data++);
2006                           printk("), ");
2007                         }
2008 #endif
2009                     current_SC->SCp.ptr           += 2 * data_count;
2010                     current_SC->SCp.this_residual -= 2 * data_count;
2011                   }
2012               
2013                 /* if this buffer is full and there are more buffers left */
2014                 if (!current_SC->SCp.this_residual &&
2015                      current_SC->SCp.buffers_residual)
2016                   {
2017                     /* advance to next buffer */
2018                     current_SC->SCp.buffers_residual--;
2019                     current_SC->SCp.buffer++;
2020                     current_SC->SCp.ptr =
2021                       current_SC->SCp.buffer->address;
2022                     current_SC->SCp.this_residual =
2023                       current_SC->SCp.buffer->length;
2024                   } 
2025               }
2026  
2027             /*
2028              * Fifo should be empty
2029              */
2030             if(fifodata>0)
2031               {
2032                 printk("aha152x: more data than expected (%d bytes)\n",
2033                        GETPORT(FIFOSTAT));
2034                 SETBITS(DMACNTRL0, _8BIT );
2035                 printk("aha152x: data ( ");
2036                 while(fifodata--)
2037                   printk("%2x ", GETPORT( DATAPORT ));
2038                 printk(")\n");
2039               }
2040 
2041 #if defined(DEBUG_DATAI)
2042             if(aha152x_debug & debug_datai)
2043               if(!fifodata)
2044                 printk("fifo empty, ");
2045               else
2046                 printk("something left in fifo, ");
2047 #endif
2048           }
2049 
2050 #if defined(DEBUG_DATAI)
2051         if((aha152x_debug & debug_datai) && (current_SC->SCp.buffers_residual || current_SC->SCp.this_residual))
2052           printk("left buffers (buffers=%d, bytes=%d), ",
2053                  current_SC->SCp.buffers_residual, 
2054                  current_SC->SCp.this_residual);
2055 #endif
2056         /* transfer can be considered ended, when SCSIEN reads back zero */
2057         CLRBITS(SXFRCTL0, SCSIEN|DMAEN);
2058         while( TESTHI( SXFRCTL0, SCSIEN ) )
2059           ;
2060         CLRBITS(DMACNTRL0, ENDMA );
2061 
2062 #if defined(DEBUG_DATAI) || defined(DEBUG_INTR)
2063         if(aha152x_debug & (debug_datai|debug_intr))
2064           printk("got %d bytes, ", GETSTCNT());
2065 #endif
2066 
2067         current_SC->SCp.have_data_in++;
2068       }
2069       break;
2070 
2071     case P_DATAO:                                           /* DATA OUT phase */
2072       {
2073         int data_count;
2074 
2075 #if defined(DEBUG_DATAO) || defined(DEBUG_INTR) || defined(DEBUG_PHASES)
2076         if(aha152x_debug & (debug_datao|debug_intr|debug_phases))
2077           printk("DATA OUT, ");
2078 #endif
2079 #if defined(DEBUG_DATAO)
2080         if(aha152x_debug & debug_datao)
2081           printk("got data to send (bytes=%d, buffers=%d), ",
2082                  current_SC->SCp.this_residual,
2083                  current_SC->SCp.buffers_residual );
2084 #endif
2085 
2086         if(GETPORT(FIFOSTAT) || GETPORT(SSTAT2) & (SFULL|SFCNT) )
2087           {
2088             printk("%d(%d) left in FIFO, ", GETPORT(FIFOSTAT), GETPORT(SSTAT2) & (SFULL|SFCNT) );
2089             aha152x_panic("FIFO should be empty");
2090           }
2091 
2092         SETPORT(DMACNTRL0, WRITE_READ|RSTFIFO);
2093         SETPORT(DMACNTRL0, ENDMA|WRITE_READ);
2094 
2095         SETPORT(SXFRCTL0, CH1|CLRSTCNT|CLRCH1 );
2096         SETPORT(SXFRCTL0, SCSIEN|DMAEN|CH1);
2097  
2098         SETPORT( SIMODE0, 0 );
2099         SETPORT( SIMODE1, ENPHASEMIS|ENBUSFREE );
2100 
2101         /* while current buffer is not empty or
2102            there are more buffers to transfer */
2103         while( TESTLO( SSTAT1, PHASEMIS ) &&
2104                  (current_SC->SCp.this_residual ||
2105                   current_SC->SCp.buffers_residual) )
2106           {
2107 #if defined(DEBUG_DATAO)
2108             if(aha152x_debug & debug_datao)
2109               printk("sending data (left: bytes=%d, buffers=%d), waiting, ",
2110                      current_SC->SCp.this_residual,
2111                      current_SC->SCp.buffers_residual);
2112 #endif
2113             /* transfer rest of buffer, but max. 128 byte */
2114             data_count = current_SC->SCp.this_residual > 128 ?
2115                          128 : current_SC->SCp.this_residual ;
2116 
2117 #if defined(DEBUG_DATAO)
2118             if(aha152x_debug & debug_datao)
2119               printk("data_count=%d, ", data_count);
2120 #endif
2121   
2122             if(data_count&1)
2123               {
2124                 /* put a single byte in byte mode */
2125                 SETBITS(DMACNTRL0, _8BIT );
2126                 SETPORT(DATAPORT, *current_SC->SCp.ptr++);
2127                 current_SC->SCp.this_residual--;
2128               }
2129             if(data_count>1)
2130               {
2131                 CLRBITS(DMACNTRL0, _8BIT );
2132                 data_count >>= 1; /* Number of words */
2133                 outsw( DATAPORT, current_SC->SCp.ptr, data_count );
2134                 current_SC->SCp.ptr           += 2 * data_count;
2135                 current_SC->SCp.this_residual -= 2 * data_count;
2136               }
2137 
2138             /* wait for FIFO to get empty */
2139             while( TESTLO ( DMASTAT, DFIFOEMP|INTSTAT ) )
2140               ;
2141 
2142 #if defined(DEBUG_DATAO)
2143             if(aha152x_debug & debug_datao)
2144               printk("fifo (%d bytes), transfered (%d bytes), ",
2145                      GETPORT(FIFOSTAT), GETSTCNT() );
2146 #endif
2147 
2148             /* if this buffer is empty and there are more buffers left */
2149             if ( TESTLO( SSTAT1, PHASEMIS ) &&
2150                  !current_SC->SCp.this_residual &&
2151                   current_SC->SCp.buffers_residual)
2152               {
2153                  /* advance to next buffer */
2154                  current_SC->SCp.buffers_residual--;
2155                  current_SC->SCp.buffer++;
2156                  current_SC->SCp.ptr =
2157                    current_SC->SCp.buffer->address;
2158                  current_SC->SCp.this_residual =
2159                  current_SC->SCp.buffer->length;
2160               }
2161           }
2162 
2163         if ( current_SC->SCp.this_residual ||
2164              current_SC->SCp.buffers_residual )
2165           {
2166             /* target leaves DATA OUT for an other phase
2167                (perhaps disconnect) */
2168 
2169             /* data in fifos has to be resend */
2170             data_count = GETPORT(SSTAT2) & (SFULL|SFCNT);
2171 
2172             data_count += GETPORT(FIFOSTAT) ;
2173             current_SC->SCp.ptr           -= data_count;
2174             current_SC->SCp.this_residual += data_count;
2175 #if defined(DEBUG_DATAO)
2176             if(aha152x_debug & debug_datao)
2177               printk("left data (bytes=%d, buffers=%d), fifos (bytes=%d), transfer incomplete, resetting fifo, ",
2178                      current_SC->SCp.this_residual,
2179                      current_SC->SCp.buffers_residual,
2180                      data_count );
2181 #endif
2182             SETPORT(DMACNTRL0, WRITE_READ|RSTFIFO);
2183             CLRBITS(SXFRCTL0, SCSIEN|DMAEN );
2184             CLRBITS(DMACNTRL0, ENDMA);
2185           }
2186         else
2187           {
2188 #if defined(DEBUG_DATAO)
2189             if(aha152x_debug & debug_datao)
2190               printk("waiting for SCSI fifo to get empty, ");
2191 #endif
2192             /* wait for SCSI fifo to get empty */
2193             while( TESTLO( SSTAT2, SEMPTY ) )
2194               ;
2195 #if defined(DEBUG_DATAO)
2196             if(aha152x_debug & debug_datao)
2197               printk("ok, left data (bytes=%d, buffers=%d) ",
2198                      current_SC->SCp.this_residual,
2199                      current_SC->SCp.buffers_residual);
2200 #endif
2201             CLRBITS(SXFRCTL0, SCSIEN|DMAEN);
2202 
2203             /* transfer can be considered ended, when SCSIEN reads back zero */
2204             while( TESTHI( SXFRCTL0, SCSIEN ) )
2205               ;
2206 
2207             CLRBITS(DMACNTRL0, ENDMA);
2208           }
2209 
2210 #if defined(DEBUG_DATAO) || defined(DEBUG_INTR)
2211         if(aha152x_debug & (debug_datao|debug_intr))
2212           printk("sent %d data bytes, ", GETSTCNT() );
2213 #endif
2214       }
2215       break;
2216 
2217     case P_BUSFREE:                                                /* BUSFREE */
2218 #if defined(DEBUG_RACE)
2219       leave_driver("(BUSFREE) intr");
2220 #endif
2221 #if defined(DEBUG_PHASES)
2222       if(aha152x_debug & debug_phases)
2223         printk("unexpected BUS FREE, ");
2224 #endif
2225       current_SC->SCp.phase = (current_SC->SCp.phase & ~(P_MASK<<16));
2226 
2227       aha152x_done( DID_ERROR << 16 );               /* Don't know any better */
2228       return;
2229       break;
2230 
2231     case P_PARITY:                              /* parity error in DATA phase */
2232 #if defined(DEBUG_RACE)
2233       leave_driver("(DID_PARITY) intr");
2234 #endif
2235       printk("PARITY error in DATA phase, ");
2236 
2237       current_SC->SCp.phase = (current_SC->SCp.phase & ~(P_MASK<<16));
2238 
2239       SETBITS( DMACNTRL0, INTEN );
2240       aha152x_done( DID_PARITY << 16 );
2241       return;
2242       break;
2243 
2244     default:
2245       printk("aha152x: unexpected phase\n");
2246       break;
2247     }
2248 
2249   if(done)
2250     {
2251 #if defined(DEBUG_INTR)
2252       if(aha152x_debug & debug_intr)
2253         printk("command done.\n");
2254 #endif
2255 #if defined(DEBUG_RACE)
2256       leave_driver("(done) intr");
2257 #endif
2258 
2259       SETPORT(SIMODE0, disconnected_SC ? ENSELDI : 0 );
2260       SETPORT(SIMODE1, issue_SC ? ENBUSFREE : 0);
2261       SETPORT(SCSISEQ, disconnected_SC ? ENRESELI : 0 );
2262 
2263       SETBITS( DMACNTRL0, INTEN );
2264 
2265       aha152x_done(   (current_SC->SCp.Status  & 0xff)
2266                     | ( (current_SC->SCp.Message & 0xff) << 8)
2267                     | ( DID_OK << 16) );
2268 
2269 #if defined(DEBUG_RACE)
2270       printk("done returned (DID_OK: Status=%x; Message=%x).\n",
2271              current_SC->SCp.Status, current_SC->SCp.Message);
2272 #endif
2273       return;
2274     }
2275 
2276   if(current_SC)
2277     current_SC->SCp.phase |= 1<<16 ;
2278 
2279   SETPORT( SIMODE0, 0 );
2280   SETPORT( SIMODE1, ENPHASEMIS|ENBUSFREE );
2281 #if defined(DEBUG_INTR)
2282   if(aha152x_debug & debug_intr)
2283     disp_enintr();
2284 #endif
2285 #if defined(DEBUG_RACE)
2286   leave_driver("(PHASEEND) intr");
2287 #endif
2288 
2289   SETBITS( DMACNTRL0, INTEN);
2290   return;
2291 }
2292 
2293 /* 
2294  * Dump the current driver status and panic...
2295  */
2296 static void aha152x_panic(const char *msg)
     /* [previous][next][first][last][top][bottom][index][help] */
2297 {
2298   printk("\naha152x_panic: %s\n", msg);
2299   show_queues();
2300   panic("aha152x panic");
2301 }
2302 
2303 /*
2304  * Display registers of AIC-6260
2305  */
2306 static void disp_ports(void)
     /* [previous][next][first][last][top][bottom][index][help] */
2307 {
2308 #ifdef DEBUG_AHA152X
2309   int s;
2310 
2311 #ifdef SKIP_PORTS
2312   if(aha152x_debug & debug_skipports)
2313         return;
2314 #endif
2315 
2316   printk("\n%s: ", current_SC ? "on bus" : "waiting");
2317 
2318   s=GETPORT(SCSISEQ);
2319   printk("SCSISEQ ( ");
2320   if( s & TEMODEO )     printk("TARGET MODE ");
2321   if( s & ENSELO )      printk("SELO ");
2322   if( s & ENSELI )      printk("SELI ");
2323   if( s & ENRESELI )    printk("RESELI ");
2324   if( s & ENAUTOATNO )  printk("AUTOATNO ");
2325   if( s & ENAUTOATNI )  printk("AUTOATNI ");
2326   if( s & ENAUTOATNP )  printk("AUTOATNP ");
2327   if( s & SCSIRSTO )    printk("SCSIRSTO ");
2328   printk(");");
2329 
2330   printk(" SCSISIG ( ");
2331   s=GETPORT(SCSISIG);
2332   switch(s & P_MASK)
2333     {
2334     case P_DATAO:
2335       printk("DATA OUT");
2336       break;
2337     case P_DATAI:
2338       printk("DATA IN");
2339       break;
2340     case P_CMD:
2341       printk("COMMAND"); 
2342       break;
2343     case P_STATUS:
2344       printk("STATUS"); 
2345       break;
2346     case P_MSGO:
2347       printk("MESSAGE OUT");
2348       break;
2349     case P_MSGI:
2350       printk("MESSAGE IN");
2351       break;
2352     default:
2353       printk("*illegal*");
2354       break;
2355     }
2356   
2357   printk(" ); ");
2358 
2359   printk("INTSTAT ( %s ); ", TESTHI(DMASTAT, INTSTAT) ? "hi" : "lo");
2360 
2361   printk("SSTAT ( ");
2362   s=GETPORT(SSTAT0);
2363   if( s & TARGET )   printk("TARGET ");
2364   if( s & SELDO )    printk("SELDO ");
2365   if( s & SELDI )    printk("SELDI ");
2366   if( s & SELINGO )  printk("SELINGO ");
2367   if( s & SWRAP )    printk("SWRAP ");
2368   if( s & SDONE )    printk("SDONE ");
2369   if( s & SPIORDY )  printk("SPIORDY ");
2370   if( s & DMADONE )  printk("DMADONE ");
2371 
2372   s=GETPORT(SSTAT1);
2373   if( s & SELTO )     printk("SELTO ");
2374   if( s & ATNTARG )   printk("ATNTARG ");
2375   if( s & SCSIRSTI )  printk("SCSIRSTI ");
2376   if( s & PHASEMIS )  printk("PHASEMIS ");
2377   if( s & BUSFREE )   printk("BUSFREE ");
2378   if( s & SCSIPERR )  printk("SCSIPERR ");
2379   if( s & PHASECHG )  printk("PHASECHG ");
2380   if( s & REQINIT )   printk("REQINIT ");
2381   printk("); ");
2382 
2383 
2384   printk("SSTAT ( ");
2385 
2386   s=GETPORT(SSTAT0) & GETPORT(SIMODE0);
2387 
2388   if( s & TARGET )    printk("TARGET ");
2389   if( s & SELDO )     printk("SELDO ");
2390   if( s & SELDI )     printk("SELDI ");
2391   if( s & SELINGO )   printk("SELINGO ");
2392   if( s & SWRAP )     printk("SWRAP ");
2393   if( s & SDONE )     printk("SDONE ");
2394   if( s & SPIORDY )   printk("SPIORDY ");
2395   if( s & DMADONE )   printk("DMADONE ");
2396 
2397   s=GETPORT(SSTAT1) & GETPORT(SIMODE1);
2398 
2399   if( s & SELTO )     printk("SELTO ");
2400   if( s & ATNTARG )   printk("ATNTARG ");
2401   if( s & SCSIRSTI )  printk("SCSIRSTI ");
2402   if( s & PHASEMIS )  printk("PHASEMIS ");
2403   if( s & BUSFREE )   printk("BUSFREE ");
2404   if( s & SCSIPERR )  printk("SCSIPERR ");
2405   if( s & PHASECHG )  printk("PHASECHG ");
2406   if( s & REQINIT )   printk("REQINIT ");
2407   printk("); ");
2408 
2409   printk("SXFRCTL0 ( ");
2410 
2411   s=GETPORT(SXFRCTL0);
2412   if( s & SCSIEN )    printk("SCSIEN ");
2413   if( s & DMAEN )     printk("DMAEN ");
2414   if( s & CH1 )       printk("CH1 ");
2415   if( s & CLRSTCNT )  printk("CLRSTCNT ");
2416   if( s & SPIOEN )    printk("SPIOEN ");
2417   if( s & CLRCH1 )    printk("CLRCH1 ");
2418   printk("); ");
2419 
2420   printk("SIGNAL ( ");
2421 
2422   s=GETPORT(SCSISIG);
2423   if( s & ATNI )  printk("ATNI ");
2424   if( s & SELI )  printk("SELI ");
2425   if( s & BSYI )  printk("BSYI ");
2426   if( s & REQI )  printk("REQI ");
2427   if( s & ACKI )  printk("ACKI ");
2428   printk("); ");
2429 
2430   printk("SELID ( %02x ), ", GETPORT(SELID) );
2431 
2432   printk("SSTAT2 ( ");
2433 
2434   s=GETPORT(SSTAT2);
2435   if( s & SOFFSET)  printk("SOFFSET ");
2436   if( s & SEMPTY)   printk("SEMPTY ");
2437   if( s & SFULL)    printk("SFULL ");
2438   printk("); SFCNT ( %d ); ", s & (SFULL|SFCNT) );
2439 
2440 #if 0
2441   printk("SSTAT4 ( ");
2442   s=GETPORT(SSTAT4);
2443   if( s & SYNCERR)   printk("SYNCERR ");
2444   if( s & FWERR)     printk("FWERR ");
2445   if( s & FRERR)     printk("FRERR ");
2446   printk("); ");
2447 #endif
2448 
2449   printk("FCNT ( %d ); ", GETPORT(FIFOSTAT) );
2450 
2451   printk("DMACNTRL0 ( ");
2452   s=GETPORT(DMACNTRL0);
2453   printk( "%s ", s & _8BIT      ? "8BIT"  : "16BIT" );
2454   printk( "%s ", s & DMA        ? "DMA"   : "PIO"   );
2455   printk( "%s ", s & WRITE_READ ? "WRITE" : "READ"  );
2456   if( s & ENDMA )    printk("ENDMA ");
2457   if( s & INTEN )    printk("INTEN ");
2458   if( s & RSTFIFO )  printk("RSTFIFO ");
2459   if( s & SWINT )    printk("SWINT ");
2460   printk("); ");
2461 
2462 
2463 #if 0
2464   printk("DMACNTRL1 ( ");
2465 
2466   s=GETPORT(DMACNTRL1);
2467   if( s & PWRDWN )    printk("PWRDN ");
2468   printk("); ");
2469 
2470 
2471   printk("STK ( %d ); ", s & 0xf);
2472 
2473   printk("DMASTAT (");
2474   s=GETPORT(DMASTAT);
2475   if( s & ATDONE )     printk("ATDONE ");
2476   if( s & WORDRDY )    printk("WORDRDY ");
2477   if( s & DFIFOFULL )  printk("DFIFOFULL ");
2478   if( s & DFIFOEMP )   printk("DFIFOEMP ");
2479   printk(")");
2480 
2481 #endif
2482 
2483   printk("\n");
2484 #endif
2485 }
2486 
2487 /*
2488  * display enabled interrupts
2489  */
2490 static void disp_enintr(void)
     /* [previous][next][first][last][top][bottom][index][help] */
2491 {
2492   int s;
2493 
2494   printk("enabled interrupts ( ");
2495   
2496   s=GETPORT(SIMODE0);
2497   if( s & ENSELDO )    printk("ENSELDO ");
2498   if( s & ENSELDI )    printk("ENSELDI ");
2499   if( s & ENSELINGO )  printk("ENSELINGO ");
2500   if( s & ENSWRAP )    printk("ENSWRAP ");
2501   if( s & ENSDONE )    printk("ENSDONE ");
2502   if( s & ENSPIORDY )  printk("ENSPIORDY ");
2503   if( s & ENDMADONE )  printk("ENDMADONE ");
2504 
2505   s=GETPORT(SIMODE1);
2506   if( s & ENSELTIMO )    printk("ENSELTIMO ");
2507   if( s & ENATNTARG )    printk("ENATNTARG ");
2508   if( s & ENPHASEMIS )   printk("ENPHASEMIS ");
2509   if( s & ENBUSFREE )    printk("ENBUSFREE ");
2510   if( s & ENSCSIPERR )   printk("ENSCSIPERR ");
2511   if( s & ENPHASECHG )   printk("ENPHASECHG ");
2512   if( s & ENREQINIT )    printk("ENREQINIT ");
2513   printk(")\n");
2514 }
2515 
2516 #if defined(DEBUG_RACE)
2517 
2518 static const char *should_leave;
2519 static int in_driver=0;
2520 
2521 /*
2522  * Only one routine can be in the driver at once.
2523  */
2524 static void enter_driver(const char *func)
     /* [previous][next][first][last][top][bottom][index][help] */
2525 {
2526   unsigned long flags;
2527 
2528   save_flags(flags);
2529   cli();
2530   printk("aha152x: entering %s() (%x)\n", func, jiffies);
2531   if(in_driver)
2532     {
2533       printk("%s should leave first.\n", should_leave);
2534       panic("aha152x: already in driver\n");
2535     }
2536 
2537   in_driver++;
2538   should_leave=func;
2539   restore_flags(flags);
2540 }
2541 
2542 static void leave_driver(const char *func)
     /* [previous][next][first][last][top][bottom][index][help] */
2543 {
2544   unsigned long flags;
2545 
2546   save_flags(flags);
2547   cli();
2548   printk("\naha152x: leaving %s() (%x)\n", func, jiffies);
2549   if(!in_driver)
2550     {
2551       printk("aha152x: %s already left.\n", should_leave);
2552       panic("aha152x: %s already left driver.\n");
2553     }
2554 
2555   in_driver--;
2556   should_leave=func;
2557   restore_flags(flags);
2558 }
2559 #endif
2560 
2561 /*
2562  * Show the command data of a command
2563  */
2564 static void show_command(Scsi_Cmnd *ptr)
     /* [previous][next][first][last][top][bottom][index][help] */
2565 {
2566   printk("0x%08x: target=%d; lun=%d; cmnd=( ",
2567          (unsigned int) ptr, ptr->target, ptr->lun);
2568   
2569   print_command(ptr->cmnd);
2570 
2571   printk("); residual=%d; buffers=%d; phase |",
2572          ptr->SCp.this_residual, ptr->SCp.buffers_residual);
2573 
2574   if( ptr->SCp.phase & not_issued   )  printk("not issued|");
2575   if( ptr->SCp.phase & in_selection )  printk("in selection|");
2576   if( ptr->SCp.phase & disconnected )  printk("disconnected|");
2577   if( ptr->SCp.phase & aborted      )  printk("aborted|");
2578   if( ptr->SCp.phase & sent_ident   )  printk("send_ident|");
2579   if( ptr->SCp.phase & in_other )
2580     { 
2581       printk("; in other(");
2582       switch( (ptr->SCp.phase >> 16) & P_MASK )
2583         {
2584         case P_DATAO:
2585           printk("DATA OUT");
2586           break;
2587         case P_DATAI:
2588           printk("DATA IN");
2589           break;
2590         case P_CMD:
2591           printk("COMMAND");
2592           break;
2593         case P_STATUS:
2594           printk("STATUS");
2595           break;
2596         case P_MSGO:
2597           printk("MESSAGE OUT");
2598           break;
2599         case P_MSGI:
2600           printk("MESSAGE IN");
2601           break;
2602         default: 
2603           printk("*illegal*");
2604           break;
2605         }
2606       printk(")");
2607       if(ptr->SCp.phase & (1<<16))
2608         printk("; phaseend");
2609     }
2610   printk("; next=0x%08x\n", (unsigned int) ptr->host_scribble);
2611 }
2612  
2613 /*
2614  * Dump the queued data
2615  */
2616 static void show_queues(void)
     /* [previous][next][first][last][top][bottom][index][help] */
2617 {
2618   unsigned long flags;
2619   Scsi_Cmnd *ptr;
2620 
2621   save_flags(flags);
2622   cli();
2623   printk("QUEUE STATUS:\nissue_SC:\n");
2624   for(ptr=issue_SC; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble )
2625     show_command(ptr);
2626 
2627   printk("current_SC:\n");
2628   if(current_SC)
2629     show_command(current_SC);
2630   else
2631     printk("none\n");
2632 
2633   printk("disconnected_SC:\n");
2634   for(ptr=disconnected_SC; ptr; ptr = (Scsi_Cmnd *) ptr->host_scribble )
2635     show_command(ptr);
2636 
2637   disp_ports();
2638   disp_enintr();
2639   restore_flags(flags);
2640 }
2641 
2642 #ifdef MODULE
2643 /* Eventually this will go into an include file, but this will be later */
2644 Scsi_Host_Template driver_template = AHA152X;
2645 
2646 #include "scsi_module.c"
2647 #endif

/* [previous][next][first][last][top][bottom][index][help] */