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_checksetup
  10. aha152x_detect
  11. aha152x_queue
  12. aha152x_command
  13. aha152x_abort
  14. aha152x_reset_ports
  15. aha152x_reset
  16. aha152x_biosparam
  17. aha152x_done
  18. aha152x_intr
  19. aha152x_panic
  20. disp_ports
  21. disp_enintr
  22. enter_driver
  23. leave_driver
  24. show_command
  25. show_queues
  26. aha152x_set_info
  27. get_command
  28. aha152x_proc_info

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

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