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

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