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

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