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

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