Annotation of Gnu-Mach/linux/src/drivers/scsi/aha152x.c, revision 1.1.1.2

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.