patch-2.0.34 linux/drivers/scsi/wd7000.c

Next file: linux/drivers/sound/lowlevel/aci.c
Previous file: linux/drivers/scsi/u14-34f.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.0.33/linux/drivers/scsi/wd7000.c linux/drivers/scsi/wd7000.c
@@ -131,6 +131,11 @@
  *
  *  Added support for /proc file system (/proc/scsi/wd7000/[0...] files).
  *  Now, driver can handle hard disks with capacity >1GB.
+ *
+ *  01/15/1998
+ *
+ *  Added support for BUS_ON and BUS_OFF parameters in config line.
+ *  Miscellaneous cleanup.
  */
 
 #ifdef MODULE
@@ -156,11 +161,10 @@
 #include <scsi/scsicam.h>
 
 #define ANY2SCSI_INLINE		/* undef this to use old macros */
-#undef BIOSPARAM_DEBUG
-#undef DEBUG                    /* general debug */
+#undef WD7000_DEBUG		/* general debug                */
 
 #include "wd7000.h"
-#include<linux/stat.h>
+#include <linux/stat.h>
 
 
 struct proc_dir_entry proc_scsi_wd7000 =
@@ -195,36 +199,63 @@
  *  WD7000-specific mailbox structure
  *
  */
-typedef volatile struct mailbox{
-  unchar status;
-  unchar scbptr[3];		/* SCSI-style - MSB first (big endian) */
+typedef volatile struct mailbox {
+    unchar status;
+    unchar scbptr[3];		/* SCSI-style - MSB first (big endian) */
 } Mailbox;
 
 /*
  *  This structure should contain all per-adapter global data.  I.e., any
  *  new global per-adapter data should put in here.
- *
  */
 typedef struct adapter {
-  struct Scsi_Host *sh;		/* Pointer to Scsi_Host structure */
-  int iobase;			/* This adapter's I/O base address */
-  int irq;			/* This adapter's IRQ level */
-  int dma;			/* This adapter's DMA channel */
-  struct {			/* This adapter's mailboxes */
-    Mailbox ogmb[OGMB_CNT];	/* Outgoing mailboxes */
-    Mailbox icmb[ICMB_CNT];	/* Incoming mailboxes */
-  } mb;
-  int next_ogmb;		/* to reduce contention at mailboxes */
-  unchar control;		/* shadows CONTROL port value */
-  unchar rev1, rev2;		/* filled in by wd7000_revision */
+    struct Scsi_Host *sh;	/* Pointer to Scsi_Host structure    */
+    int iobase;			/* This adapter's I/O base address   */
+    int irq;			/* This adapter's IRQ level          */
+    int dma;			/* This adapter's DMA channel        */
+    int int_counter;		/* This adapter's interrupt counter  */
+    int bus_on;			/* This adapter's BUS_ON time        */
+    int bus_off;		/* This adapter's BUS_OFF time       */
+    struct {			/* This adapter's mailboxes          */
+	Mailbox ogmb[OGMB_CNT];	/* Outgoing mailboxes                */
+	Mailbox icmb[ICMB_CNT];	/* Incoming mailboxes                */
+    } mb;
+    int next_ogmb;		/* to reduce contention at mailboxes */
+    unchar control;		/* shadows CONTROL port value        */
+    unchar rev1, rev2;		/* filled in by wd7000_revision      */
 } Adapter;
 
 /*
+ * (linear) base address for ROM BIOS
+ */
+static const long wd7000_biosaddr[] =
+{
+    0xc0000, 0xc2000, 0xc4000, 0xc6000, 0xc8000, 0xca000, 0xcc000, 0xce000,
+    0xd0000, 0xd2000, 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0xde000
+};
+#define NUM_ADDRS (sizeof(wd7000_biosaddr)/sizeof(long))
+
+static const unsigned short wd7000_iobase[] =
+{
+    0x0300, 0x0308, 0x0310, 0x0318, 0x0320, 0x0328, 0x0330, 0x0338,
+    0x0340, 0x0348, 0x0350, 0x0358, 0x0360, 0x0368, 0x0370, 0x0378,
+    0x0380, 0x0388, 0x0390, 0x0398, 0x03a0, 0x03a8, 0x03b0, 0x03b8,
+    0x03c0, 0x03c8, 0x03d0, 0x03d8, 0x03e0, 0x03e8, 0x03f0, 0x03f8
+};
+#define NUM_IOPORTS (sizeof(wd7000_iobase)/sizeof(unsigned short))
+
+static const short wd7000_irq[] = { 3, 4, 5, 7, 9, 10, 11, 12, 14, 15 };
+#define NUM_IRQS (sizeof(wd7000_irq)/sizeof(short))
+
+static const short wd7000_dma[] = { 5, 6, 7 };
+#define NUM_DMAS (sizeof(wd7000_dma)/sizeof(short))
+
+/*
  * possible irq range
  */
 #define IRQ_MIN   3
 #define IRQ_MAX   15
-#define IRQS      (IRQ_MAX-IRQ_MIN + 1)
+#define IRQS      (IRQ_MAX - IRQ_MIN + 1)
 
 /*
  * The following is set up by wd7000_detect, and used thereafter by
@@ -234,46 +265,32 @@
  */
 static struct Scsi_Host *wd7000_host[IRQS];
 
-/*
- * (linear) base address for ROM BIOS
- */
-static const long wd7000_biosaddr[] = {
-  0xc0000, 0xc2000, 0xc4000, 0xc6000, 0xc8000, 0xca000, 0xcc000, 0xce000,
-  0xd0000, 0xd2000, 0xd4000, 0xd6000, 0xd8000, 0xda000, 0xdc000, 0xde000
-};
-#define NUM_ADDRS (sizeof(wd7000_biosaddr)/sizeof(long))
-
-static const unsigned short wd7000_iobase[] = {
-  0x0300, 0x0308, 0x0310, 0x0318, 0x0320, 0x0328, 0x0330, 0x0338,
-  0x0340, 0x0348, 0x0350, 0x0358, 0x0360, 0x0368, 0x0370, 0x0378,
-  0x0380, 0x0388, 0x0390, 0x0398, 0x03a0, 0x03a8, 0x03b0, 0x03b8,
-  0x03c0, 0x03c8, 0x03d0, 0x03d8, 0x03e0, 0x03e8, 0x03f0, 0x03f8
-};
-#define NUM_IOPORTS (sizeof(wd7000_iobase)/sizeof(unsigned short))
-
-static const short wd7000_irq[] = { 3, 4, 5, 7, 9, 10, 11, 12, 14, 15 };
-#define NUM_IRQS (sizeof(wd7000_irq)/sizeof(short))
+#define BUS_ON    64	/* x 125ns = 8000ns (BIOS default) */
+#define BUS_OFF   15	/* x 125ns = 1875ns (BIOS default) */
 
-static const short wd7000_dma[] = { 5, 6, 7 };
-#define NUM_DMAS (sizeof(wd7000_dma)/sizeof(short))
-  
 /*
  *  Standard Adapter Configurations - used by wd7000_detect
  */
 typedef struct {
-  int      irq;			/* IRQ level        */
-  int      dma;			/* DMA channel      */
-  unsigned iobase;		/* I/O base address */
+    short irq;		/* IRQ level                                  */
+    short dma;		/* DMA channel                                */
+    unsigned iobase;	/* I/O base address                           */
+    short bus_on;	/* Time that WD7000 spends on the AT-bus when */
+			/* transferring data. BIOS default is 8000ns. */
+    short bus_off;	/* Time that WD7000 spends OFF THE BUS after  */
+			/* while it is transferring data.             */
+			/* BIOS default is 1875ns                     */
 } Config;
 
 /*
  * Add here your configuration...
  */
-static const Config configs[] = {
-  { 15,  6, 0x350 },		/* defaults for single adapter */
-  { 11,  5, 0x320 },		/* defaults for second adapter */
-  {  7,  6, 0x350 },		/* My configuration (Zaga)     */
-  { -1, -1, 0x0   }		/* Empty slot                  */
+static Config configs[] =
+{
+    { 15,  6, 0x350, BUS_ON, BUS_OFF },	/* defaults for single adapter */
+    { 11,  5, 0x320, BUS_ON, BUS_OFF },	/* defaults for second adapter */
+    {  7,  6, 0x350, BUS_ON, BUS_OFF },	/* My configuration (Zaga)     */
+    { -1, -1, 0x0,   BUS_ON, BUS_OFF }	/* Empty slot                  */
 };
 #define NUM_CONFIGS (sizeof(configs)/sizeof(Config))
 
@@ -283,13 +300,14 @@
  *  added for the Future Domain version.
  */
 typedef struct signature {
-    const void *sig;		/* String to look for */
-    unsigned    ofs;		/* offset from BIOS base address */
-    unsigned    len;		/* length of string */
+    const void *sig;		/* String to look for            */
+    unsigned ofs;		/* offset from BIOS base address */
+    unsigned len;		/* length of string              */
 } Signature;
 
-static const Signature signatures[] = {
-  { "SSTBIOS", 0x0000d, 7 }	/* "SSTBIOS" @ offset 0x0000d */
+static const Signature signatures[] =
+{
+    {"SSTBIOS", 0x0000d, 7}	/* "SSTBIOS" @ offset 0x0000d */
 };
 #define NUM_SIGNATURES (sizeof(signatures)/sizeof(Signature))
 
@@ -298,22 +316,23 @@
  *  I/O Port Offsets and Bit Definitions
  *  4 addresses are used.  Those not defined here are reserved.
  */
-#define ASC_STAT        0	/* Status,  Read */
-#define ASC_COMMAND     0	/* Command, Write */
+#define ASC_STAT        0	/* Status,  Read          */
+#define ASC_COMMAND     0	/* Command, Write         */
 #define ASC_INTR_STAT   1	/* Interrupt Status, Read */
-#define ASC_INTR_ACK    1	/* Acknowledge, Write */
-#define ASC_CONTROL     2	/* Control, Write */
+#define ASC_INTR_ACK    1	/* Acknowledge, Write     */
+#define ASC_CONTROL     2	/* Control, Write         */
 
 /*
  * ASC Status Port
  */
-#define INT_IM		0x80	/* Interrupt Image Flag */
-#define CMD_RDY		0x40	/* Command Port Ready */
-#define CMD_REJ		0x20	/* Command Port Byte Rejected */
-#define ASC_INIT        0x10	/* ASC Initialized Flag */
+#define INT_IM		0x80	/* Interrupt Image Flag           */
+#define CMD_RDY		0x40	/* Command Port Ready             */
+#define CMD_REJ		0x20	/* Command Port Byte Rejected     */
+#define ASC_INIT        0x10	/* ASC Initialized Flag           */
 #define ASC_STATMASK    0xf0	/* The lower 4 Bytes are reserved */
 
-/* COMMAND opcodes
+/*
+ * COMMAND opcodes
  *
  *  Unfortunately, I have no idea how to properly use some of these commands,
  *  as the OEM manual does not make it clear.  I have not been able to use
@@ -321,39 +340,38 @@
  *  discernible effect whatsoever.  I think they may be related to certain
  *  ICB commands, but again, the OEM manual doesn't make that clear.
  */
-#define NO_OP             0	/* NO-OP toggles CMD_RDY bit in ASC_STAT */
-#define INITIALIZATION    1	/* initialization (10 bytes) */
-#define DISABLE_UNS_INTR  2	/* disable unsolicited interrupts */
-#define ENABLE_UNS_INTR   3	/* enable unsolicited interrupts */
-#define INTR_ON_FREE_OGMB 4	/* interrupt on free OGMB */
-#define SOFT_RESET        5	/* SCSI bus soft reset */
-#define HARD_RESET_ACK    6	/* SCSI bus hard reset acknowledge */
-#define START_OGMB        0x80	/* start command in OGMB (n) */
+#define NO_OP             0	/* NO-OP toggles CMD_RDY bit in ASC_STAT  */
+#define INITIALIZATION    1	/* initialization (10 bytes)              */
+#define DISABLE_UNS_INTR  2	/* disable unsolicited interrupts         */
+#define ENABLE_UNS_INTR   3	/* enable unsolicited interrupts          */
+#define INTR_ON_FREE_OGMB 4	/* interrupt on free OGMB                 */
+#define SOFT_RESET        5	/* SCSI bus soft reset                    */
+#define HARD_RESET_ACK    6	/* SCSI bus hard reset acknowledge        */
+#define START_OGMB        0x80	/* start command in OGMB (n)              */
 #define SCAN_OGMBS        0xc0	/* start multiple commands, signature (n) */
-				/*    where (n) = lower 6 bits */
-/* For INITIALIZATION:
+				/*    where (n) = lower 6 bits            */
+/*
+ * For INITIALIZATION:
  */
 typedef struct initCmd {
-  unchar op;			/* command opcode (= 1) */
-  unchar ID;			/* Adapter's SCSI ID */
-  unchar bus_on;		/* Bus on time, x 125ns (see below) */
-  unchar bus_off;		/* Bus off time, ""         ""      */
-  unchar rsvd;			/* Reserved */
-  unchar mailboxes[3];		/* Address of Mailboxes, MSB first  */
-  unchar ogmbs;			/* Number of outgoing MBs, max 64, 0,1 = 1 */
-  unchar icmbs;			/* Number of incoming MBs,   ""       ""   */
+    unchar op;			/* command opcode (= 1)                    */
+    unchar ID;			/* Adapter's SCSI ID                       */
+    unchar bus_on;		/* Bus on time, x 125ns (see below)        */
+    unchar bus_off;		/* Bus off time, ""         ""             */
+    unchar rsvd;		/* Reserved                                */
+    unchar mailboxes[3];	/* Address of Mailboxes, MSB first         */
+    unchar ogmbs;		/* Number of outgoing MBs, max 64, 0,1 = 1 */
+    unchar icmbs;		/* Number of incoming MBs,   ""       ""   */
 } InitCmd;
 
-#define BUS_ON            64	/* x 125ns = 8000ns (BIOS default) */
-#define BUS_OFF           15	/* x 125ns = 1875ns (BIOS default) */
- 
-/* Interrupt Status Port - also returns diagnostic codes at ASC reset
+/*
+ * Interrupt Status Port - also returns diagnostic codes at ASC reset
  *
  * if msb is zero, the lower bits are diagnostic status
  * Diagnostics:
- * 01	No diagnostic error occurred
- * 02	RAM failure
- * 03	FIFO R/W failed
+ * 01   No diagnostic error occurred
+ * 02   RAM failure
+ * 03   FIFO R/W failed
  * 04   SBIC register read/write failed
  * 05   Initialization D-FF failed
  * 06   Host IRQ D-FF failed
@@ -362,19 +380,20 @@
  * 10NNNNNN   outgoing mailbox NNNNNN is free
  * 11NNNNNN   incoming mailbox NNNNNN needs service
  */
-#define MB_INTR	 0xC0		/* Mailbox Service possible/required */
-#define IMB_INTR 0x40		/* 1 Incoming / 0 Outgoing */
-#define MB_MASK  0x3f           /* mask for mailbox number */
+#define MB_INTR    0xC0		/* Mailbox Service possible/required */
+#define IMB_INTR   0x40		/* 1 Incoming / 0 Outgoing           */
+#define MB_MASK    0x3f		/* mask for mailbox number           */
 
-/* CONTROL port bits
+/*
+ * CONTROL port bits
  */
-#define INT_EN		0x08	/* Interrupt Enable	*/
-#define DMA_EN		0x04	/* DMA Enable		*/
-#define SCSI_RES	0x02	/* SCSI Reset		*/
-#define ASC_RES		0x01	/* ASC Reset		*/
+#define INT_EN     0x08		/* Interrupt Enable */
+#define DMA_EN     0x04		/* DMA Enable       */
+#define SCSI_RES   0x02		/* SCSI Reset       */
+#define ASC_RES    0x01		/* ASC Reset        */
 
 /*
- *   Driver data structures:
+ * Driver data structures:
  *   - mb and scbs are required for interfacing with the host adapter.
  *     An SCB has extra fields not visible to the adapter; mb's
  *     _cannot_ do this, since the adapter assumes they are contiguous in
@@ -403,28 +422,28 @@
  */
 typedef struct sgb {
     unchar len[3];
-    unchar ptr[3];              /* Also SCSI-style - MSB first */
+    unchar ptr[3];		/* Also SCSI-style - MSB first */
 } Sgb;
 
-typedef struct scb {		/* Command Control Block 5.4.1 */
-  unchar op;			/* Command Control Block Operation Code */
-  unchar idlun;			/* op=0,2:Target Id, op=1:Initiator Id */
-				/* Outbound data transfer, length is checked*/
-				/* Inbound data transfer, length is checked */
-				/* Logical Unit Number */
-  unchar cdb[12];		/* SCSI Command Block */
-  volatile unchar status;       /* SCSI Return Status */
-  volatile unchar vue;		/* Vendor Unique Error Code */
-  unchar maxlen[3];		/* Maximum Data Transfer Length */
-  unchar dataptr[3];		/* SCSI Data Block Pointer */
-  unchar linkptr[3];		/* Next Command Link Pointer */
-  unchar direc;			/* Transfer Direction */
-  unchar reserved2[6];		/* SCSI Command Descriptor Block */
-				/* end of hardware SCB */
-  Scsi_Cmnd *SCpnt;             /* Scsi_Cmnd using this SCB */
-  Sgb sgb[WD7000_SG];           /* Scatter/gather list for this SCB */
-  Adapter *host;                /* host adapter */
-  struct scb *next;             /* for lists of scbs */
+typedef struct scb {		/* Command Control Block 5.4.1               */
+    unchar op;			/* Command Control Block Operation Code      */
+    unchar idlun;		/* op=0,2:Target Id, op=1:Initiator Id       */
+				/* Outbound data transfer, length is checked */
+				/* Inbound data transfer, length is checked  */
+				/* Logical Unit Number                       */
+    unchar cdb[12];		/* SCSI Command Block                        */
+    volatile unchar status;	/* SCSI Return Status                        */
+    volatile unchar vue;	/* Vendor Unique Error Code                  */
+    unchar maxlen[3];		/* Maximum Data Transfer Length              */
+    unchar dataptr[3];		/* SCSI Data Block Pointer                   */
+    unchar linkptr[3];		/* Next Command Link Pointer                 */
+    unchar direc;		/* Transfer Direction                        */
+    unchar reserved2[6];	/* SCSI Command Descriptor Block             */
+				/* end of hardware SCB                       */
+    Scsi_Cmnd *SCpnt;		/* Scsi_Cmnd using this SCB                  */
+    Sgb sgb[WD7000_SG];		/* Scatter/gather list for this SCB          */
+    Adapter *host;		/* host adapter                              */
+    struct scb *next;		/* for lists of scbs                         */
 } Scb;
 
 /*
@@ -438,110 +457,110 @@
  *  (notably, get/set unsolicited interrupt status) in my copy of the OEM
  *  manual, and others are ambiguous/hard to follow.
  */
-#define ICB_OP_MASK             0x80  /* distinguishes scbs from icbs */
-#define ICB_OP_OPEN_RBUF        0x80  /* open receive buffer */
-#define ICB_OP_RECV_CMD         0x81  /* receive command from initiator */
-#define ICB_OP_RECV_DATA        0x82  /* receive data from initiator */
-#define ICB_OP_RECV_SDATA       0x83  /* receive data with status from init. */
-#define ICB_OP_SEND_DATA        0x84  /* send data with status to initiator */
-#define ICB_OP_SEND_STAT        0x86  /* send command status to initiator */
-			     /* 0x87 is reserved */
-#define ICB_OP_READ_INIT        0x88  /* read initialization bytes */
-#define ICB_OP_READ_ID          0x89  /* read adapter's SCSI ID */
-#define ICB_OP_SET_UMASK        0x8A  /* set unsolicited interrupt mask */
-#define ICB_OP_GET_UMASK        0x8B  /* read unsolicited interrupt mask */
-#define ICB_OP_GET_REVISION     0x8C  /* read firmware revision level */
-#define ICB_OP_DIAGNOSTICS      0x8D  /* execute diagnostics */
-#define ICB_OP_SET_EPARMS       0x8E  /* set execution parameters */
-#define ICB_OP_GET_EPARMS       0x8F  /* read execution parameters */
+#define ICB_OP_MASK           0x80	/* distinguishes scbs from icbs        */
+#define ICB_OP_OPEN_RBUF      0x80	/* open receive buffer                 */
+#define ICB_OP_RECV_CMD       0x81	/* receive command from initiator      */
+#define ICB_OP_RECV_DATA      0x82	/* receive data from initiator         */
+#define ICB_OP_RECV_SDATA     0x83	/* receive data with status from init. */
+#define ICB_OP_SEND_DATA      0x84	/* send data with status to initiator  */
+#define ICB_OP_SEND_STAT      0x86	/* send command status to initiator    */
+					/* 0x87 is reserved                    */
+#define ICB_OP_READ_INIT      0x88	/* read initialization bytes           */
+#define ICB_OP_READ_ID        0x89	/* read adapter's SCSI ID              */
+#define ICB_OP_SET_UMASK      0x8A	/* set unsolicited interrupt mask      */
+#define ICB_OP_GET_UMASK      0x8B	/* read unsolicited interrupt mask     */
+#define ICB_OP_GET_REVISION   0x8C	/* read firmware revision level        */
+#define ICB_OP_DIAGNOSTICS    0x8D	/* execute diagnostics                 */
+#define ICB_OP_SET_EPARMS     0x8E	/* set execution parameters            */
+#define ICB_OP_GET_EPARMS     0x8F	/* read execution parameters           */
 
 typedef struct icbRecvCmd {
-  unchar op;
-  unchar IDlun;                 /* Initiator SCSI ID/lun */
-  unchar len[3];                /* command buffer length */
-  unchar ptr[3];                /* command buffer address */
-  unchar rsvd[7];               /* reserved */
-  volatile unchar vue;          /* vendor-unique error code */
-  volatile unchar status;       /* returned (icmb) status */
-  volatile unchar phase;        /* used by interrupt handler */
+    unchar op;
+    unchar IDlun;		/* Initiator SCSI ID/lun     */
+    unchar len[3];		/* command buffer length     */
+    unchar ptr[3];		/* command buffer address    */
+    unchar rsvd[7];		/* reserved                  */
+    volatile unchar vue;	/* vendor-unique error code  */
+    volatile unchar status;	/* returned (icmb) status    */
+    volatile unchar phase;	/* used by interrupt handler */
 } IcbRecvCmd;
 
 typedef struct icbSendStat {
-  unchar op;
-  unchar IDlun;                 /* Target SCSI ID/lun */
-  unchar stat;                  /* (outgoing) completion status byte 1 */
-  unchar rsvd[12];              /* reserved */
-  volatile unchar vue;          /* vendor-unique error code */
-  volatile unchar status;       /* returned (icmb) status */
-  volatile unchar phase;        /* used by interrupt handler */
+    unchar op;
+    unchar IDlun;		/* Target SCSI ID/lun                  */
+    unchar stat;		/* (outgoing) completion status byte 1 */
+    unchar rsvd[12];		/* reserved                            */
+    volatile unchar vue;	/* vendor-unique error code            */
+    volatile unchar status;	/* returned (icmb) status              */
+    volatile unchar phase;	/* used by interrupt handler           */
 } IcbSendStat;
 
 typedef struct icbRevLvl {
-  unchar op;
-  volatile unchar primary;      /* primary revision level (returned) */
-  volatile unchar secondary;    /* secondary revision level (returned) */
-  unchar rsvd[12];              /* reserved */
-  volatile unchar vue;          /* vendor-unique error code */
-  volatile unchar status;       /* returned (icmb) status */
-  volatile unchar phase;        /* used by interrupt handler */
+    unchar op;
+    volatile unchar primary;	/* primary revision level (returned)   */
+    volatile unchar secondary;	/* secondary revision level (returned) */
+    unchar rsvd[12];		/* reserved                            */
+    volatile unchar vue;	/* vendor-unique error code            */
+    volatile unchar status;	/* returned (icmb) status              */
+    volatile unchar phase;	/* used by interrupt handler           */
 } IcbRevLvl;
 
-typedef struct icbUnsMask {     /* I'm totally guessing here */
-  unchar op;
-  volatile unchar mask[14];     /* mask bits */
+typedef struct icbUnsMask {	/* I'm totally guessing here */
+    unchar op;
+    volatile unchar mask[14];	/* mask bits                 */
 #ifdef 0
-  unchar rsvd[12];              /* reserved */
+    unchar rsvd[12];		/* reserved                  */
 #endif
-  volatile unchar vue;          /* vendor-unique error code */
-  volatile unchar status;       /* returned (icmb) status */
-  volatile unchar phase;        /* used by interrupt handler */
+    volatile unchar vue;	/* vendor-unique error code  */
+    volatile unchar status;	/* returned (icmb) status    */
+    volatile unchar phase;	/* used by interrupt handler */
 } IcbUnsMask;
 
 typedef struct icbDiag {
-  unchar op;
-  unchar type;                  /* diagnostics type code (0-3) */
-  unchar len[3];                /* buffer length */
-  unchar ptr[3];                /* buffer address */
-  unchar rsvd[7];               /* reserved */
-  volatile unchar vue;          /* vendor-unique error code */
-  volatile unchar status;       /* returned (icmb) status */
-  volatile unchar phase;        /* used by interrupt handler */
+    unchar op;
+    unchar type;		/* diagnostics type code (0-3) */
+    unchar len[3];		/* buffer length               */
+    unchar ptr[3];		/* buffer address              */
+    unchar rsvd[7];		/* reserved                    */
+    volatile unchar vue;	/* vendor-unique error code    */
+    volatile unchar status;	/* returned (icmb) status      */
+    volatile unchar phase;	/* used by interrupt handler   */
 } IcbDiag;
 
-#define ICB_DIAG_POWERUP        0     /* Power-up diags only */
-#define ICB_DIAG_WALKING        1     /* walking 1's pattern */
-#define ICB_DIAG_DMA            2     /* DMA - system memory diags */
-#define ICB_DIAG_FULL           3     /* do both 1 & 2 */
+#define ICB_DIAG_POWERUP   0	/* Power-up diags only       */
+#define ICB_DIAG_WALKING   1	/* walking 1's pattern       */
+#define ICB_DIAG_DMA       2	/* DMA - system memory diags */
+#define ICB_DIAG_FULL      3	/* do both 1 & 2             */
 
 typedef struct icbParms {
-  unchar op;
-  unchar rsvd1;                 /* reserved */
-  unchar len[3];                /* parms buffer length */
-  unchar ptr[3];                /* parms buffer address */
-  unchar idx[2];                /* index (MSB-LSB) */
-  unchar rsvd2[5];              /* reserved */
-  volatile unchar vue;          /* vendor-unique error code */
-  volatile unchar status;       /* returned (icmb) status */
-  volatile unchar phase;        /* used by interrupt handler */
+    unchar op;
+    unchar rsvd1;		/* reserved                  */
+    unchar len[3];		/* parms buffer length       */
+    unchar ptr[3];		/* parms buffer address      */
+    unchar idx[2];		/* index (MSB-LSB)           */
+    unchar rsvd2[5];		/* reserved                  */
+    volatile unchar vue;	/* vendor-unique error code  */
+    volatile unchar status;	/* returned (icmb) status    */
+    volatile unchar phase;	/* used by interrupt handler */
 } IcbParms;
 
 typedef struct icbAny {
-  unchar op;
-  unchar data[14];              /* format-specific data */
-  volatile unchar vue;          /* vendor-unique error code */
-  volatile unchar status;       /* returned (icmb) status */
-  volatile unchar phase;        /* used by interrupt handler */
+    unchar op;
+    unchar data[14];		/* format-specific data      */
+    volatile unchar vue;	/* vendor-unique error code  */
+    volatile unchar status;	/* returned (icmb) status    */
+    volatile unchar phase;	/* used by interrupt handler */
 } IcbAny;
 
 typedef union icb {
-  unchar op;                    /* ICB opcode */
-  IcbRecvCmd recv_cmd;          /* format for receive command */
-  IcbSendStat send_stat;        /* format for send status */
-  IcbRevLvl rev_lvl;            /* format for get revision level */
-  IcbDiag diag;                 /* format for execute diagnostics */
-  IcbParms eparms;              /* format for get/set exec parms */
-  IcbAny icb;                   /* generic format */
-  unchar data[18];
+    unchar op;			/* ICB opcode                     */
+    IcbRecvCmd recv_cmd;	/* format for receive command     */
+    IcbSendStat send_stat;	/* format for send status         */
+    IcbRevLvl rev_lvl;		/* format for get revision level  */
+    IcbDiag diag;		/* format for execute diagnostics */
+    IcbParms eparms;		/* format for get/set exec parms  */
+    IcbAny icb;			/* generic format                 */
+    unchar data[18];
 } Icb;
 
 
@@ -552,27 +571,34 @@
  *  structure is not part of the Adapter structure.
  */
 static Scb scbs[MAX_SCBS];
-static Scb *scbfree = NULL;      /* free list */
-static int freescbs = MAX_SCBS;  /* free list counter */
-
-/*
- *
- */
-static short wd7000_setupIRQ[NUM_CONFIGS];
-static short wd7000_setupDMA[NUM_CONFIGS];
-static short wd7000_setupIO[NUM_CONFIGS];
-static short wd7000_card_num = 0;
+static Scb *scbfree = NULL;	/* free list         */
+static int freescbs = MAX_SCBS;	/* free list counter */
 
 /*
  *  END of data/declarations - code follows.
  */
+static void setup_error (char *mesg, int *ints)
+{
+    if (ints[0] == 3)
+        printk ("wd7000_setup: \"wd7000=%d,%d,0x%x\" -> %s\n",
+                ints[1], ints[2], ints[3], mesg);
+    else if (ints[0] == 4)
+        printk ("wd7000_setup: \"wd7000=%d,%d,0x%x,%d\" -> %s\n",
+                ints[1], ints[2], ints[3], ints[4], mesg);
+    else
+        printk ("wd7000_setup: \"wd7000=%d,%d,0x%x,%d,%d\" -> %s\n",
+                ints[1], ints[2], ints[3], ints[4], ints[5], mesg);
+}
 
 
 /*
  * Note: You can now set these options from the kernel's "command line".
  * The syntax is:
  *
- *     wd7000=IRQ,DMA,IO
+ *     wd7000=<IRQ>,<DMA>,<IO>[,<BUS_ON>[,<BUS_OFF>]]
+ *
+ * , where BUS_ON and BUS_OFF are in nanoseconds. BIOS default values
+ * are 8000ns for BUS_ON and 1875ns for BUS_OFF.
  * eg:
  *     wd7000=7,6,0x350
  *
@@ -581,82 +607,99 @@
  */
 void wd7000_setup (char *str, int *ints)
 {
+    static short wd7000_card_num = 0;
     short i, j;
 
     if (wd7000_card_num >= NUM_CONFIGS) {
-        printk ("wd7000_setup: Too many \"wd7000=\" configurations in "
-	        "command line!\n");
-
-        return;
+	printk ("wd7000_setup: Too many \"wd7000=\" configurations in "
+		"command line!\n");
+	return;
     }
 
-    if (ints[0] != 3)
+    if ((ints[0] < 3) || (ints[0] > 5))
 	printk ("wd7000_setup: Error in command line!  "
-	        "Usage: wd7000=IRQ,DMA,IO\n");
+		"Usage: wd7000=<IRQ>,<DMA>,IO>[,<BUS_ON>[,<BUS_OFF>]]\n");
     else {
 	for (i = 0; i < NUM_IRQS; i++)
 	    if (ints[1] == wd7000_irq[i])
 		break;
 
 	if (i == NUM_IRQS) {
-	    printk ("wd7000_setup: \"wd7000=%d,%d,0x%x\" -> "
-		    "invalid IRQ.\n", ints[1], ints[2], ints[3]);
+	    setup_error ("invalid IRQ.", ints);
 	    return;
 	}
 	else
- 	    wd7000_setupIRQ[wd7000_card_num] = ints[1];
+	    configs[wd7000_card_num].irq = ints[1];
 
 	for (i = 0; i < NUM_DMAS; i++)
 	    if (ints[2] == wd7000_dma[i])
 		break;
 
 	if (i == NUM_DMAS) {
-	    printk ("wd7000_setup: \"wd7000=%d,%d,0x%x\" -> "
-		    "invalid DMA channel.\n", ints[1], ints[2], ints[3]);
+	    setup_error ("invalid DMA channel.", ints);
 	    return;
 	}
 	else
-	    wd7000_setupDMA[wd7000_card_num] = ints[2];
+	    configs[wd7000_card_num].dma = ints[2];
 
 	for (i = 0; i < NUM_IOPORTS; i++)
 	    if (ints[3] == wd7000_iobase[i])
 		break;
 
 	if (i == NUM_IOPORTS) {
-	    printk ("wd7000_setup: \"wd7000=%d,%d,0x%x\" -> "
-		    "invalid I/O base address.\n", ints[1], ints[2], ints[3]);
+	    setup_error ("invalid I/O base address.", ints);
 	    return;
 	}
 	else
-	    wd7000_setupIO[wd7000_card_num] = ints[3];
+	    configs[wd7000_card_num].iobase = ints[3];
+
+	if (ints[0] > 3) {
+	    if ((ints[4] < 500) || (ints[4] > 31875)) {
+	        setup_error ("BUS_ON value is out of range (500 to 31875 nanoseconds)!",
+		             ints);
+	        configs[wd7000_card_num].bus_on = BUS_ON;
+	    }
+	    else
+	        configs[wd7000_card_num].bus_on = ints[4] / 125.0;
+	}
+	else
+	    configs[wd7000_card_num].bus_on = BUS_ON;
+
+	if (ints[0] > 4) {
+	    if ((ints[5] < 500) || (ints[5] > 31875)) {
+	        setup_error ("BUS_OFF value is out of range (500 to 31875 nanoseconds)!",
+		             ints);
+	        configs[wd7000_card_num].bus_off = BUS_OFF;
+	    }
+	    else
+	        configs[wd7000_card_num].bus_off = ints[5] / 125.0;
+	}
+	else
+	    configs[wd7000_card_num].bus_off = BUS_OFF;
 
 	if (wd7000_card_num)
 	    for (i = 0; i < (wd7000_card_num - 1); i++)
-	        for (j = i + 1; j < wd7000_card_num; j++)
-	            if (wd7000_setupIRQ[i] == wd7000_setupIRQ[j]) {
-	                printk ("wd7000_setup: \"wd7000=%d,%d,0x%x\" -> "
-			        "duplicated IRQ!\n",
-				ints[1], ints[2], ints[3]);
-		        return;
-	            }
-	            else if (wd7000_setupDMA[i] == wd7000_setupDMA[j]) {
-	                printk ("wd7000_setup: \"wd7000=%d,%d,0x%x\" -> "
-			        "duplicated DMA channel!\n",
-				ints[1], ints[2], ints[3]);
-		        return;
-	            }
-	            else if (wd7000_setupIO[i] == wd7000_setupIO[j]) {
-	                printk ("wd7000_setup: \"wd7000=%d,%d,0x%x\" -> "
-			        "duplicated I/O base address!\n",
-				ints[1], ints[2], ints[3]);
-		        return;
-	            }
-
-#ifdef DEBUG
-	printk ("wd7000_setup: IRQ=%d, DMA=%d, I/O=0x%x\n",
-	        wd7000_setupIRQ[wd7000_card_num],
-		wd7000_setupDMA[wd7000_card_num],
-		wd7000_setupIO[wd7000_card_num]);
+		for (j = i + 1; j < wd7000_card_num; j++)
+		    if (configs[i].irq == configs[j].irq) {
+	                setup_error ("duplicated IRQ!", ints);
+			return;
+		    }
+		    else if (configs[i].dma == configs[j].dma) {
+	                setup_error ("duplicated DMA channel!", ints);
+			return;
+		    }
+		    else if (configs[i].iobase == configs[j].iobase) {
+	                setup_error ("duplicated I/O base address!", ints);
+			return;
+		    }
+
+#ifdef WD7000_DEBUG
+	printk ("wd7000_setup: IRQ=%d, DMA=%d, I/O=0x%x, BUS_ON=%dns, BUS_OFF=%dns\n",
+		configs[wd7000_card_num].irq,
+		configs[wd7000_card_num].dma,
+		configs[wd7000_card_num].iobase,
+		configs[wd7000_card_num].bus_on * 125,
+		configs[wd7000_card_num].bus_off * 125);
 #endif
 
 	wd7000_card_num++;
@@ -666,21 +709,20 @@
 
 #ifdef ANY2SCSI_INLINE
 /*
-   Since they're used a lot, I've redone the following from the macros
-   formerly in wd7000.h, hopefully to speed them up by getting rid of
-   all the shifting (it may not matter; GCC might have done as well anyway).
-
-   xany2scsi and xscsi2int were not being used, and are no longer defined.
-   (They were simply 4-byte versions of these routines).
-*/
-
-typedef union {  /* let's cheat... */
-  int i;
-  unchar u[sizeof(int)];  /* the sizeof(int) makes it more portable */
+ * Since they're used a lot, I've redone the following from the macros
+ * formerly in wd7000.h, hopefully to speed them up by getting rid of
+ * all the shifting (it may not matter; GCC might have done as well anyway).
+ *
+ * xany2scsi and xscsi2int were not being used, and are no longer defined.
+ * (They were simply 4-byte versions of these routines).
+ */
+typedef union {			/* let's cheat... */
+    int i;
+    unchar u[sizeof (int)];	/* the sizeof(int) makes it more portable */
 } i_u;
 
 
-static inline void any2scsi( unchar *scsi, int any )
+static inline void any2scsi (unchar * scsi, int any)
 {
     *scsi++ = ((i_u) any).u[2];
     *scsi++ = ((i_u) any).u[1];
@@ -688,49 +730,50 @@
 }
 
 
-static inline int scsi2int( unchar *scsi )
+static inline int scsi2int (unchar * scsi)
 {
     i_u result;
 
-    result.i = 0;  /* clears unused bytes */
-    *(result.u+2) = *scsi++;
-    *(result.u+1) = *scsi++;
-      *(result.u) = *scsi++;
-    return result.i;
+    result.i = 0;		/* clears unused bytes */
+    *(result.u + 2) = *scsi++;
+    *(result.u + 1) = *scsi++;
+    *(result.u) = *scsi++;
+
+    return (result.i);
 }
 #else
 /*
-   These are the old ones - I've just moved them here...
-*/
+ * These are the old ones - I've just moved them here...
+ */
 #undef any2scsi
-#define any2scsi(up, p)			\
-(up)[0] = (((unsigned long)(p)) >> 16);		\
-(up)[1] = ((unsigned long)(p)) >> 8;		\
-(up)[2] = ((unsigned long)(p));
+#define any2scsi(up, p)   (up)[0] = (((unsigned long) (p)) >> 16);	\
+			  (up)[1] = ((unsigned long) (p)) >> 8;		\
+			  (up)[2] = ((unsigned long) (p));
 
 #undef scsi2int
-#define scsi2int(up) ( (((unsigned long)*(up)) << 16) + \
- (((unsigned long)(up)[1]) << 8) + ((unsigned long)(up)[2]) )
+#define scsi2int(up)   ( (((unsigned long) *(up)) << 16) +	\
+			 (((unsigned long) (up)[1]) << 8) +	\
+			 ((unsigned long) (up)[2]) )
 #endif
 
-    
-static inline void wd7000_enable_intr(Adapter *host)
+
+static inline void wd7000_enable_intr (Adapter *host)
 {
     host->control |= INT_EN;
-    outb(host->control, host->iobase+ASC_CONTROL);
+    outb (host->control, host->iobase + ASC_CONTROL);
 }
 
 
-static inline void wd7000_enable_dma(Adapter *host)
+static inline void wd7000_enable_dma (Adapter *host)
 {
     host->control |= DMA_EN;
-    outb(host->control,host->iobase+ASC_CONTROL);
-    set_dma_mode(host->dma, DMA_MODE_CASCADE);
-    enable_dma(host->dma);
+    outb (host->control, host->iobase + ASC_CONTROL);
+    set_dma_mode (host->dma, DMA_MODE_CASCADE);
+    enable_dma (host->dma);
 }
 
 
-#define WAITnexttimeout 200  /* 2 seconds */
+#define WAITnexttimeout 200	/* 2 seconds */
 
 static inline short WAIT (unsigned port, unsigned mask, unsigned allof, unsigned noneof)
 {
@@ -738,7 +781,7 @@
     register unsigned long WAITtimeout = jiffies + WAITnexttimeout;
 
     while (jiffies <= WAITtimeout) {
-     	WAITbits = inb (port) & mask;
+	WAITbits = inb (port) & mask;
 
 	if (((WAITbits & allof) == allof) && ((WAITbits & noneof) == 0))
 	    return (0);
@@ -748,31 +791,32 @@
 }
 
 
-static inline void delay( unsigned how_long )
+static inline void delay (unsigned how_long)
 {
-     register unsigned long time = jiffies + how_long;
+    register unsigned long time = jiffies + how_long;
 
-     while (jiffies < time);
+    while (jiffies < time);
 }
 
 
-static inline int command_out(Adapter *host, unchar *cmd, int len)
+static inline int command_out (Adapter * host, unchar * cmd, int len)
 {
-    if (! WAIT (host->iobase+ASC_STAT,ASC_STATMASK,CMD_RDY,0)) {
-	while (len--)  {
-	    do  {
-		outb(*cmd, host->iobase+ASC_COMMAND);
-		WAIT(host->iobase+ASC_STAT, ASC_STATMASK, CMD_RDY, 0);
-	    }  while (inb(host->iobase+ASC_STAT) & CMD_REJ);
+    if (!WAIT (host->iobase + ASC_STAT, ASC_STATMASK, CMD_RDY, 0)) {
+	while (len--) {
+	    do {
+		outb (*cmd, host->iobase + ASC_COMMAND);
+		WAIT (host->iobase + ASC_STAT, ASC_STATMASK, CMD_RDY, 0);
+	    } while (inb (host->iobase + ASC_STAT) & CMD_REJ);
 
 	    cmd++;
 	}
 
-	return 1;
+	return (1);
     }
 
-    printk("wd7000 command_out: WAIT failed(%d)\n", len+1);
-    return 0;
+    printk ("wd7000 command_out: WAIT failed(%d)\n", len + 1);
+
+    return (0);
 }
 
 
@@ -786,7 +830,7 @@
  *  the satisfiability of a request is not dependent on the size of the
  *  request.
  */
-static inline Scb *alloc_scbs(int needed)
+static inline Scb *alloc_scbs (int needed)
 {
     register Scb *scb, *p;
     register unsigned long flags;
@@ -795,85 +839,89 @@
     static int busy = 0;
     int i;
 
-    if (needed <= 0)  return NULL;  /* sanity check */
+    if (needed <= 0)
+	return (NULL);		/* sanity check */
 
-    save_flags(flags);
-    cli();
-    while (busy)  { /* someone else is allocating */
-	sti();	/* Yes this is really needed here */
-	now = jiffies;  while (jiffies == now)  /* wait a jiffy */;
-	cli();
+    save_flags (flags);
+    cli ();
+    while (busy) {		/* someone else is allocating */
+	sti ();			/* Yes this is really needed here */
+	for (now = jiffies; now == jiffies; );	/* wait a jiffy */
+	cli ();
     }
-    busy = 1;          /* not busy now; it's our turn */
+    busy = 1;			/* not busy now; it's our turn */
 
-    while (freescbs < needed)  {
+    while (freescbs < needed) {
 	timeout = jiffies + WAITnexttimeout;
 	do {
-	    sti();	/* Yes this is really needed here */
-	    now = jiffies;
-	    while (jiffies == now); /* wait a jiffy */
-	    cli();
-	}  while (freescbs < needed && jiffies <= timeout);
+	    sti ();		/* Yes this is really needed here */
+	    for (now = jiffies; now == jiffies; );	/* wait a jiffy */
+	    cli ();
+	} while (freescbs < needed && jiffies <= timeout);
 	/*
 	 *  If we get here with enough free Scbs, we can take them.
 	 *  Otherwise, we timed out and didn't get enough.
 	 */
-	if (freescbs < needed)  {
+	if (freescbs < needed) {
 	    busy = 0;
-	    panic("wd7000: can't get enough free SCBs.\n");
-	    restore_flags(flags);
-	    return NULL;
+	    panic ("wd7000: can't get enough free SCBs.\n");
+	    restore_flags (flags);
+	    return (NULL);
 	}
     }
-    scb = scbfree;  freescbs -= needed;
-    for (i = 0; i < needed; i++)  { p = scbfree;  scbfree = p->next; }
+    scb = scbfree;
+    freescbs -= needed;
+    for (i = 0; i < needed; i++) {
+	p = scbfree;
+	scbfree = p->next;
+    }
     p->next = NULL;
-    
-    busy = 0;   /* we're done */
+    busy = 0;			/* we're done */
 
-    restore_flags(flags);
+    restore_flags (flags);
 
-    return scb;
+    return (scb);
 }
 
 
-static inline void free_scb( Scb *scb )
+static inline void free_scb (Scb *scb)
 {
     register unsigned long flags;
 
-    save_flags(flags);
-    cli();
+    save_flags (flags);
+    cli ();
 
-    memset(scb, 0, sizeof(Scb));
+    memset (scb, 0, sizeof (Scb));
     scb->next = scbfree;
     scbfree = scb;
     freescbs++;
 
-    restore_flags(flags);
+    restore_flags (flags);
 }
 
 
-static inline void init_scbs(void)
+static inline void init_scbs (void)
 {
     int i;
     unsigned long flags;
 
-    save_flags(flags);
-    cli();
+    save_flags (flags);
+    cli ();
 
     scbfree = &(scbs[0]);
-    memset(scbs, 0, sizeof(scbs));
-    for (i = 0;  i < MAX_SCBS-1;  i++)  {
-      scbs[i].next = &(scbs[i+1]);  scbs[i].SCpnt = NULL;
-    }
-    scbs[MAX_SCBS-1].next = NULL;
-    scbs[MAX_SCBS-1].SCpnt = NULL;
-
-    restore_flags(flags);
-}    
-    
+    memset (scbs, 0, sizeof (scbs));
+    for (i = 0; i < MAX_SCBS - 1; i++) {
+	scbs[i].next = &(scbs[i + 1]);
+	scbs[i].SCpnt = NULL;
+    }
+    scbs[MAX_SCBS - 1].next = NULL;
+    scbs[MAX_SCBS - 1].SCpnt = NULL;
+
+    restore_flags (flags);
+}
 
-static int mail_out( Adapter *host, Scb *scbptr )
+
+static int mail_out (Adapter *host, Scb *scbptr)
 /*
  *  Note: this can also be used for ICBs; just cast to the parm type.
  */
@@ -883,30 +931,35 @@
     unchar start_ogmb;
     Mailbox *ogmbs = host->mb.ogmb;
     int *next_ogmb = &(host->next_ogmb);
-#ifdef DEBUG
-    printk("wd7000 mail_out: 0x%06lx",(long) scbptr);
+
+#ifdef WD7000_DEBUG
+    printk ("wd7000 mail_out: 0x%06lx", (long) scbptr);
 #endif
+
     /* We first look for a free outgoing mailbox */
-    save_flags(flags);
-    cli();
+    save_flags (flags);
+    cli ();
     ogmb = *next_ogmb;
     for (i = 0; i < OGMB_CNT; i++) {
-	if (ogmbs[ogmb].status == 0)  {
-#ifdef DEBUG
-	    printk(" using OGMB 0x%x",ogmb);
+	if (ogmbs[ogmb].status == 0) {
+#ifdef WD7000_DEBUG
+	    printk (" using OGMB 0x%x", ogmb);
 #endif
 	    ogmbs[ogmb].status = 1;
-	    any2scsi((unchar *) ogmbs[ogmb].scbptr, (int) scbptr);
+	    any2scsi ((unchar *) ogmbs[ogmb].scbptr, (int) scbptr);
 
-	    *next_ogmb = (ogmb+1) % OGMB_CNT;
+	    *next_ogmb = (ogmb + 1) % OGMB_CNT;
 	    break;
-	}  else
+	}
+	else
 	    ogmb = (++ogmb) % OGMB_CNT;
     }
-    restore_flags(flags);
-#ifdef DEBUG
-    printk(", scb is 0x%06lx",(long) scbptr);
+    restore_flags (flags);
+
+#ifdef WD7000_DEBUG
+    printk (", scb is 0x%06lx", (long) scbptr);
 #endif
+
     if (i >= OGMB_CNT) {
 	/*
 	 *  Alternatively, we might issue the "interrupt on free OGMB",
@@ -916,75 +969,76 @@
 	 *  that marks OGMB's free, waiting even with interrupts off
 	 *  should work, since they are freed very quickly in most cases.
 	 */
-	#ifdef DEBUG
-	printk(", no free OGMBs.\n");
+#ifdef WD7000_DEBUG
+	printk (", no free OGMBs.\n");
 #endif
-	return 0;
+	return (0);
     }
 
-    wd7000_enable_intr(host); 
+    wd7000_enable_intr (host);
 
     start_ogmb = START_OGMB | ogmb;
-    command_out( host, &start_ogmb, 1 );
-#ifdef DEBUG
-    printk(", awaiting interrupt.\n");
+    command_out (host, &start_ogmb, 1);
+
+#ifdef WD7000_DEBUG
+    printk (", awaiting interrupt.\n");
 #endif
-    return 1;
+
+    return (1);
 }
 
 
-int make_code(unsigned hosterr, unsigned scsierr)
-{   
-#ifdef DEBUG
+int make_code (unsigned hosterr, unsigned scsierr)
+{
+#ifdef WD7000_DEBUG
     int in_error = hosterr;
 #endif
 
-    switch ((hosterr>>8)&0xff){
-	case 0:	/* Reserved */
-		hosterr = DID_ERROR;
-		break;
-	case 1:	/* Command Complete, no errors */
-		hosterr = DID_OK;
-		break;
-	case 2: /* Command complete, error logged in scb status (scsierr) */ 
-		hosterr = DID_OK;
-		break;
-	case 4:	/* Command failed to complete - timeout */
-		hosterr = DID_TIME_OUT;
-		break;
-	case 5:	/* Command terminated; Bus reset by external device */
-		hosterr = DID_RESET;
-		break;
-	case 6:	/* Unexpected Command Received w/ host as target */
-		hosterr = DID_BAD_TARGET;
-		break;
+    switch ((hosterr >> 8) & 0xff) {
+	case 0:  /* Reserved */
+                 hosterr = DID_ERROR;
+                 break;
+	case 1:  /* Command Complete, no errors */
+                 hosterr = DID_OK;
+                 break;
+	case 2:  /* Command complete, error logged in scb status (scsierr) */
+                 hosterr = DID_OK;
+                 break;
+	case 4:  /* Command failed to complete - timeout */
+                 hosterr = DID_TIME_OUT;
+                 break;
+	case 5:  /* Command terminated; Bus reset by external device */
+                 hosterr = DID_RESET;
+                 break;
+	case 6:  /* Unexpected Command Received w/ host as target */
+                 hosterr = DID_BAD_TARGET;
+                 break;
 	case 80: /* Unexpected Reselection */
 	case 81: /* Unexpected Selection */
-		hosterr = DID_BAD_INTR;
-		break;
+                 hosterr = DID_BAD_INTR;
+                 break;
 	case 82: /* Abort Command Message  */
-		hosterr = DID_ABORT;
-		break;
+                 hosterr = DID_ABORT;
+                 break;
 	case 83: /* SCSI Bus Software Reset */
 	case 84: /* SCSI Bus Hardware Reset */
-		hosterr = DID_RESET;
-		break;
+                 hosterr = DID_RESET;
+                 break;
 	default: /* Reserved */
-		hosterr = DID_ERROR;
-		break;
-	}
-#ifdef DEBUG
-    if (scsierr||hosterr)
-	printk("\nSCSI command error: SCSI 0x%02x host 0x%04x return %d\n",
-	       scsierr,in_error,hosterr);
+                 hosterr = DID_ERROR;
+    }
+#ifdef WD7000_DEBUG
+    if (scsierr || hosterr)
+	printk ("\nSCSI command error: SCSI 0x%02x host 0x%04x return %d\n",
+		scsierr, in_error, hosterr);
 #endif
-    return scsierr | (hosterr << 16);
+    return (scsierr | (hosterr << 16));
 }
 
 
-static void wd7000_scsi_done(Scsi_Cmnd * SCpnt)
+static void wd7000_scsi_done (Scsi_Cmnd *SCpnt)
 {
-#ifdef DEBUG
+#ifdef WD7000_DEBUG
     printk ("wd7000_scsi_done: 0x%06lx\n", (long) SCpnt);
 #endif
 
@@ -992,97 +1046,100 @@
 }
 
 
-#define wd7000_intr_ack(host)  outb(0,host->iobase+ASC_INTR_ACK)
+#define wd7000_intr_ack(host)   outb (0, host->iobase + ASC_INTR_ACK)
 
-void wd7000_intr_handle(int irq, void *dev_id, struct pt_regs * regs)
+void wd7000_intr_handle (int irq, void *dev_id, struct pt_regs *regs)
 {
     register int flag, icmb, errstatus, icmb_status;
     register int host_error, scsi_error;
-    register Scb *scb;             /* for SCSI commands */
-    register IcbAny *icb;          /* for host commands */
+    register Scb *scb;		/* for SCSI commands */
+    register IcbAny *icb;	/* for host commands */
     register Scsi_Cmnd *SCpnt;
-    Adapter *host = (Adapter *) wd7000_host[irq - IRQ_MIN]->hostdata; /* This MUST be set!!! */
+    Adapter *host = (Adapter *) wd7000_host[irq - IRQ_MIN]->hostdata;	/* This MUST be set!!! */
     Mailbox *icmbs = host->mb.icmb;
 
-#ifdef DEBUG
-    printk("wd7000_intr_handle: irq = %d, host = 0x%06lx\n", irq, (long) host);
+    host->int_counter++;
+
+#ifdef WD7000_DEBUG
+    printk ("wd7000_intr_handle: irq = %d, host = 0x%06lx\n", irq, (long) host);
 #endif
 
-    flag = inb(host->iobase+ASC_INTR_STAT);
+    flag = inb (host->iobase + ASC_INTR_STAT);
 
-#ifdef DEBUG
-    printk("wd7000_intr_handle: intr stat = 0x%02x\n",flag);
+#ifdef WD7000_DEBUG
+    printk ("wd7000_intr_handle: intr stat = 0x%02x\n", flag);
 #endif
 
-    if (!(inb(host->iobase+ASC_STAT) & INT_IM))  {
+    if (!(inb (host->iobase + ASC_STAT) & INT_IM)) {
 	/* NB: these are _very_ possible if IRQ 15 is being used, since
-	   it's the "garbage collector" on the 2nd 8259 PIC.  Specifically,
-	   any interrupt signal into the 8259 which can't be identified
-	   comes out as 7 from the 8259, which is 15 to the host.  Thus, it
-	   is a good thing the WD7000 has an interrupt status port, so we
-	   can sort these out.  Otherwise, electrical noise and other such
-	   problems would be indistinguishable from valid interrupts...
-	*/
-#ifdef DEBUG 
-	printk("wd7000_intr_handle: phantom interrupt...\n");
+	 * it's the "garbage collector" on the 2nd 8259 PIC.  Specifically,
+	 * any interrupt signal into the 8259 which can't be identified
+	 * comes out as 7 from the 8259, which is 15 to the host.  Thus, it
+	 * is a good thing the WD7000 has an interrupt status port, so we
+	 * can sort these out.  Otherwise, electrical noise and other such
+	 * problems would be indistinguishable from valid interrupts...
+	 */
+#ifdef WD7000_DEBUG
+	printk ("wd7000_intr_handle: phantom interrupt...\n");
 #endif
-	wd7000_intr_ack(host);
-	return; 
+	wd7000_intr_ack (host);
+	return;
     }
 
-    if (flag & MB_INTR)  {
+    if (flag & MB_INTR) {
 	/* The interrupt is for a mailbox */
 	if (!(flag & IMB_INTR)) {
-#ifdef DEBUG
-	    printk("wd7000_intr_handle: free outgoing mailbox\n");
+#ifdef WD7000_DEBUG
+	    printk ("wd7000_intr_handle: free outgoing mailbox\n");
 #endif
 	    /*
 	     * If sleep_on() and the "interrupt on free OGMB" command are
 	     * used in mail_out(), wake_up() should correspondingly be called
 	     * here.  For now, we don't need to do anything special.
 	     */
-	    wd7000_intr_ack(host);
+	    wd7000_intr_ack (host);
 	    return;
-	}  else  {
+	}
+	else {
 	    /* The interrupt is for an incoming mailbox */
 	    icmb = flag & MB_MASK;
 	    icmb_status = icmbs[icmb].status;
-	    if (icmb_status & 0x80)  {  /* unsolicited - result in ICMB */
-#ifdef DEBUG
- 		printk("wd7000_intr_handle: unsolicited interrupt 0x%02xh\n",
-		       icmb_status);
+	    if (icmb_status & 0x80) {	/* unsolicited - result in ICMB */
+#ifdef WD7000_DEBUG
+		printk ("wd7000_intr_handle: unsolicited interrupt 0x%02xh\n",
+			icmb_status);
 #endif
-		wd7000_intr_ack(host);
+		wd7000_intr_ack (host);
 		return;
 	    }
-	    scb = (struct scb *) scsi2int((unchar *)icmbs[icmb].scbptr);
+	    scb = (struct scb *) scsi2int ((unchar *) icmbs[icmb].scbptr);
 	    icmbs[icmb].status = 0;
-	    if (!(scb->op & ICB_OP_MASK))  {   /* an SCB is done */
+	    if (!(scb->op & ICB_OP_MASK)) {	/* an SCB is done */
 		SCpnt = scb->SCpnt;
-		if (--(SCpnt->SCp.phase) <= 0)  {  /* all scbs are done */
+		if (--(SCpnt->SCp.phase) <= 0) {	/* all scbs are done */
 		    host_error = scb->vue | (icmb_status << 8);
 		    scsi_error = scb->status;
-		    errstatus = make_code(host_error,scsi_error);    
+		    errstatus = make_code (host_error, scsi_error);
 		    SCpnt->result = errstatus;
 
-		    free_scb(scb);
+		    free_scb (scb);
 
-		    SCpnt->scsi_done(SCpnt);
+		    SCpnt->scsi_done (SCpnt);
 		}
-	    }  else  {    /* an ICB is done */
+	    }
+	    else {		/* an ICB is done */
 		icb = (IcbAny *) scb;
 		icb->status = icmb_status;
-		icb->phase  = 0;
+		icb->phase = 0;
 	    }
-	}  /* incoming mailbox */
+	}			/* incoming mailbox */
     }
 
-    wd7000_intr_ack(host);
-    return;
+    wd7000_intr_ack (host);
 }
 
 
-int wd7000_queuecommand(Scsi_Cmnd * SCpnt, void (*done)(Scsi_Cmnd *))
+int wd7000_queuecommand (Scsi_Cmnd *SCpnt, void (*done) (Scsi_Cmnd *))
 {
     register Scb *scb;
     register Sgb *sgb;
@@ -1095,94 +1152,106 @@
     idlun = ((SCpnt->target << 5) & 0xe0) | (SCpnt->lun & 7);
     SCpnt->scsi_done = done;
     SCpnt->SCp.phase = 1;
-    scb = alloc_scbs(1);
+    scb = alloc_scbs (1);
     scb->idlun = idlun;
-    memcpy(scb->cdb, cdb, cdblen);
+    memcpy (scb->cdb, cdb, cdblen);
     scb->direc = 0x40;		/* Disable direction check */
 
-    scb->SCpnt = SCpnt;         /* so we can find stuff later */
+    scb->SCpnt = SCpnt;		/* so we can find stuff later */
     SCpnt->host_scribble = (unchar *) scb;
     scb->host = host;
 
-    if (SCpnt->use_sg)  {
+    if (SCpnt->use_sg) {
 	struct scatterlist *sg = (struct scatterlist *) SCpnt->request_buffer;
 	unsigned i;
 
-	if (SCpnt->host->sg_tablesize == SG_NONE)  {
-	    panic("wd7000_queuecommand: scatter/gather not supported.\n");
+	if (SCpnt->host->sg_tablesize == SG_NONE) {
+	    panic ("wd7000_queuecommand: scatter/gather not supported.\n");
 	}
-#ifdef DEBUG
- 	printk("Using scatter/gather with %d elements.\n",SCpnt->use_sg);
+#ifdef WD7000_DEBUG
+	printk ("Using scatter/gather with %d elements.\n", SCpnt->use_sg);
 #endif
 
 	sgb = scb->sgb;
- 	scb->op = 1;
- 	any2scsi(scb->dataptr, (int) sgb);
- 	any2scsi(scb->maxlen, SCpnt->use_sg * sizeof (Sgb) );
-
-	for (i = 0;  i < SCpnt->use_sg;  i++)  {
- 	    any2scsi(sgb[i].ptr, (int) sg[i].address);
- 	    any2scsi(sgb[i].len, sg[i].length);
+	scb->op = 1;
+	any2scsi (scb->dataptr, (int) sgb);
+	any2scsi (scb->maxlen, SCpnt->use_sg * sizeof (Sgb));
+
+	for (i = 0; i < SCpnt->use_sg; i++) {
+	    any2scsi (sgb[i].ptr, (int) sg[i].address);
+	    any2scsi (sgb[i].len, sg[i].length);
 	}
-    }  else  {
+    }
+    else {
 	scb->op = 0;
-	any2scsi(scb->dataptr, (int) SCpnt->request_buffer);
-	any2scsi(scb->maxlen, SCpnt->request_bufflen);
+	any2scsi (scb->dataptr, (int) SCpnt->request_buffer);
+	any2scsi (scb->maxlen, SCpnt->request_bufflen);
     }
-    while (!mail_out(host, scb)) /* keep trying */;
 
-    return 1;
+    while (!mail_out (host, scb));	/* keep trying */
+
+    return (1);
 }
 
 
-int wd7000_command(Scsi_Cmnd *SCpnt)
+int wd7000_command (Scsi_Cmnd *SCpnt)
 {
-    wd7000_queuecommand(SCpnt, wd7000_scsi_done);
+    wd7000_queuecommand (SCpnt, wd7000_scsi_done);
 
-    while (SCpnt->SCp.phase > 0) barrier();  /* phase counts scbs down to 0 */
+    while (SCpnt->SCp.phase > 0)
+	barrier ();		/* phase counts scbs down to 0 */
 
-    return SCpnt->result;
+    return (SCpnt->result);
 }
 
 
-int wd7000_diagnostics( Adapter *host, int code )
+int wd7000_diagnostics (Adapter *host, int code)
 {
-    static IcbDiag icb = {ICB_OP_DIAGNOSTICS};
+    static IcbDiag icb =
+    {ICB_OP_DIAGNOSTICS};
     static unchar buf[256];
     unsigned long timeout;
 
     icb.type = code;
-    any2scsi(icb.len, sizeof(buf));
-    any2scsi(icb.ptr, (int) &buf);
+    any2scsi (icb.len, sizeof (buf));
+    any2scsi (icb.ptr, (int) &buf);
     icb.phase = 1;
     /*
      * This routine is only called at init, so there should be OGMBs
      * available.  I'm assuming so here.  If this is going to
      * fail, I can just let the timeout catch the failure.
      */
-    mail_out(host, (struct scb *) &icb);
-    timeout = jiffies + WAITnexttimeout;  /* wait up to 2 seconds */
+    mail_out (host, (struct scb *) &icb);
+    timeout = jiffies + WAITnexttimeout;	/* wait up to 2 seconds */
     while (icb.phase && jiffies < timeout)
-    	barrier(); /* wait for completion */
+	barrier ();		/* wait for completion */
 
-    if (icb.phase)  {
-	printk("wd7000_diagnostics: timed out.\n");
-	return 0;
-    }
-    if (make_code(icb.vue|(icb.status << 8),0))  {
-	printk("wd7000_diagnostics: failed (0x%02x,0x%02x)\n",
-	       icb.vue, icb.status);
-	return 0;
+    if (icb.phase) {
+	printk ("wd7000_diagnostics: timed out.\n");
+	return (0);
+    }
+    if (make_code (icb.vue | (icb.status << 8), 0)) {
+	printk ("wd7000_diagnostics: failed (0x%02x,0x%02x)\n",
+		icb.vue, icb.status);
+	return (0);
     }
 
-    return 1;
+    return (1);
 }
 
 
-int wd7000_init( Adapter *host )
+int wd7000_init (Adapter *host)
 {
-    InitCmd init_cmd = {
-	INITIALIZATION, 7, BUS_ON, BUS_OFF, 0, {0,0,0}, OGMB_CNT, ICMB_CNT
+    InitCmd init_cmd =
+    {
+	INITIALIZATION,
+ 	7,
+	host->bus_on,
+	host->bus_off,
+	0,
+	{ 0, 0, 0 },
+	OGMB_CNT,
+	ICMB_CNT
     };
     int diag;
 
@@ -1190,84 +1259,78 @@
      *  Reset the adapter - only.  The SCSI bus was initialized at power-up,
      *  and we need to do this just so we control the mailboxes, etc.
      */
-    outb(ASC_RES, host->iobase+ASC_CONTROL);
-    delay(1);  /* reset pulse: this is 10ms, only need 25us */
-    outb(0,host->iobase+ASC_CONTROL);
-    host->control = 0;   /* this must always shadow ASC_CONTROL */
-
-    if (WAIT (host->iobase+ASC_STAT, ASC_STATMASK, CMD_RDY, 0)) {
-        printk ("wd7000_init: WAIT timed out.\n"); 
-        return 0;					/* 0 = not ok */
-    }
-
-    if ((diag = inb(host->iobase+ASC_INTR_STAT)) != 1) {
-	printk("wd7000_init: ");
-
-	switch (diag)  {
-	case 2:
-	  printk("RAM failure.\n");
-	  break;
-	case 3:
-	  printk("FIFO R/W failed\n");
-	  break;
-	case 4:
-	  printk("SBIC register R/W failed\n");
-	  break;
-	case 5:
-	  printk("Initialization D-FF failed.\n");
-	  break;
-	case 6:
-	  printk("Host IRQ D-FF failed.\n");
-	  break;
-	case 7:
-	  printk("ROM checksum error.\n");
-	  break;
-	default:
-	  printk("diagnostic code 0x%02Xh received.\n", diag);
+    outb (ASC_RES, host->iobase + ASC_CONTROL);
+    delay (1);			/* reset pulse: this is 10ms, only need 25us */
+    outb (0, host->iobase + ASC_CONTROL);
+    host->control = 0;		/* this must always shadow ASC_CONTROL */
+
+    if (WAIT (host->iobase + ASC_STAT, ASC_STATMASK, CMD_RDY, 0)) {
+	printk ("wd7000_init: WAIT timed out.\n");
+	return (0);		/* 0 = not ok */
+    }
+
+    if ((diag = inb (host->iobase + ASC_INTR_STAT)) != 1) {
+	printk ("wd7000_init: ");
+
+	switch (diag) {
+	    case 2:  printk ("RAM failure.\n");
+		     break;
+	    case 3:  printk ("FIFO R/W failed\n");
+		     break;
+	    case 4:  printk ("SBIC register R/W failed\n");
+		     break;
+	    case 5:  printk ("Initialization D-FF failed.\n");
+		     break;
+	    case 6:  printk ("Host IRQ D-FF failed.\n");
+		     break;
+	    case 7:  printk ("ROM checksum error.\n");
+		     break;
+	    default: printk ("diagnostic code 0x%02Xh received.\n", diag);
 	}
-	return 0;
+	return (0);
     }
-    
+
     /* Clear mailboxes */
-    memset(&(host->mb), 0, sizeof(host->mb));
+    memset (&(host->mb), 0, sizeof (host->mb));
 
     /* Execute init command */
-    any2scsi((unchar *) &(init_cmd.mailboxes), (int) &(host->mb));
-    if (!command_out(host, (unchar *) &init_cmd, sizeof(init_cmd)))  {
-	printk("wd7000_init: adapter initialization failed.\n"); 
-	return 0;
+    any2scsi ((unchar *) & (init_cmd.mailboxes), (int) &(host->mb));
+    if (!command_out (host, (unchar *) &init_cmd, sizeof (init_cmd))) {
+	printk ("wd7000_init: adapter initialization failed.\n");
+	return (0);
     }
 
-    if (WAIT (host->iobase+ASC_STAT, ASC_STATMASK, ASC_INIT, 0)) {
-        printk ("wd7000_init: WAIT timed out.\n"); 
-        return 0;
+    if (WAIT (host->iobase + ASC_STAT, ASC_STATMASK, ASC_INIT, 0)) {
+	printk ("wd7000_init: WAIT timed out.\n");
+	return (0);
     }
 
-    if (request_irq(host->irq, wd7000_intr_handle, SA_INTERRUPT, "wd7000", NULL)) {
-	printk("wd7000_init: can't get IRQ %d.\n", host->irq);
-	return 0;
+    if (request_irq (host->irq, wd7000_intr_handle, SA_INTERRUPT, "wd7000", NULL)) {
+	printk ("wd7000_init: can't get IRQ %d.\n", host->irq);
+	return (0);
     }
-    if (request_dma(host->dma,"wd7000"))  {
-	printk("wd7000_init: can't get DMA channel %d.\n", host->dma);
-	free_irq(host->irq, NULL);
-	return 0;
+    if (request_dma (host->dma, "wd7000")) {
+	printk ("wd7000_init: can't get DMA channel %d.\n", host->dma);
+	free_irq (host->irq, NULL);
+	return (0);
     }
-    wd7000_enable_dma(host);
-    wd7000_enable_intr(host);
+    wd7000_enable_dma (host);
+    wd7000_enable_intr (host);
 
-    if (!wd7000_diagnostics(host,ICB_DIAG_FULL))  {
-	free_dma(host->dma);
-	free_irq(host->irq, NULL);
-	return 0;
+    if (!wd7000_diagnostics (host, ICB_DIAG_FULL)) {
+	free_dma (host->dma);
+	free_irq (host->irq, NULL);
+	return (0);
     }
 
-    return 1;
+    return (1);
 }
 
 
-void wd7000_revision(Adapter *host)
+void wd7000_revision (Adapter *host)
 {
-    static IcbRevLvl icb = {ICB_OP_GET_REVISION};
+    static IcbRevLvl icb =
+    {ICB_OP_GET_REVISION};
 
     icb.phase = 1;
     /*
@@ -1276,9 +1339,9 @@
      * the only damage will be that the revision will show up as 0.0,
      * which in turn means that scatter/gather will be disabled.
      */
-    mail_out(host, (struct scb *) &icb);
+    mail_out (host, (struct scb *) &icb);
     while (icb.phase)
-    	barrier(); /* wait for completion */
+	barrier ();		/* wait for completion */
     host->rev1 = icb.primary;
     host->rev2 = icb.secondary;
 }
@@ -1294,7 +1357,7 @@
     save_flags (flags);
     cli ();
 
-#ifdef DEBUG
+#ifdef WD7000_DEBUG
     printk ("Buffer = <%.*s>, length = %d\n", length, buffer, length);
 #endif
 
@@ -1314,12 +1377,12 @@
     struct Scsi_Host *host = NULL;
     Scsi_Device *scd = scsi_devices;
     Adapter *adapter;
-    Mailbox *ogmbs, *icmbs;
     unsigned long flags;
     char *pos = buffer;
     short i;
 
-#ifdef DEBUG
+#ifdef WD7000_DEBUG
+    Mailbox *ogmbs, *icmbs;
     short count;
 #endif
 
@@ -1327,8 +1390,8 @@
      * Find the specified host board.
      */
     for (i = 0; i < IRQS; i++)
-        if (wd7000_host[i] && (wd7000_host[i]->host_no == hostno)) {
-            host = wd7000_host[i];
+	if (wd7000_host[i] && (wd7000_host[i]->host_no == hostno)) {
+	    host = wd7000_host[i];
 
 	    break;
 	}
@@ -1336,35 +1399,39 @@
     /*
      * Host not found!
      */
-    if (! host)
-        return (-ESRCH);
+    if (!host)
+	return (-ESRCH);
 
     /*
      * Has data been written to the file ?
-     */ 
+     */
     if (inout)
-        return (wd7000_set_info (buffer, length, host));
+	return (wd7000_set_info (buffer, length, host));
 
     adapter = (Adapter *) host->hostdata;
-    ogmbs = adapter->mb.ogmb;
-    icmbs = adapter->mb.icmb;
 
     save_flags (flags);
     cli ();
 
     SPRINTF ("Host scsi%d: Western Digital WD-7000 (rev %d.%d)\n", hostno, adapter->rev1, adapter->rev2);
-    SPRINTF ("  IO base:     0x%x\n", adapter->iobase);
-    SPRINTF ("  IRQ:         %d\n", adapter->irq);
-    SPRINTF ("  DMA channel: %d\n", adapter->dma);
+    SPRINTF ("  IO base:      0x%x\n", adapter->iobase);
+    SPRINTF ("  IRQ:          %d\n", adapter->irq);
+    SPRINTF ("  DMA channel:  %d\n", adapter->dma);
+    SPRINTF ("  Interrupts:   %d\n", adapter->int_counter);
+    SPRINTF ("  BUS_ON time:  %d nanoseconds\n", adapter->bus_on * 125);
+    SPRINTF ("  BUS_OFF time: %d nanoseconds\n", adapter->bus_off * 125);
 
-#ifdef DEBUG
-    SPRINTF ("Control port value: 0x%x\n", adapter->control);
+#ifdef WD7000_DEBUG
+    ogmbs = adapter->mb.ogmb;
+    icmbs = adapter->mb.icmb;
+
+    SPRINTF ("\nControl port value: 0x%x\n", adapter->control);
     SPRINTF ("Incoming mailbox:\n");
     SPRINTF ("  size: %d\n", ICMB_CNT);
     SPRINTF ("  queued messages: ");
 
     for (i = count = 0; i < ICMB_CNT; i++)
-        if (icmbs[i].status) {
+	if (icmbs[i].status) {
 	    count++;
 	    SPRINTF ("0x%x ", i);
 	}
@@ -1377,7 +1444,7 @@
     SPRINTF ("  queued messages: ");
 
     for (i = count = 0; i < OGMB_CNT; i++)
-        if (ogmbs[i].status) {
+	if (ogmbs[i].status) {
 	    count++;
 	    SPRINTF ("0x%x ", i);
 	}
@@ -1388,23 +1455,25 @@
     /*
      * Display driver information for each device attached to the board.
      */
-    SPRINTF ("Attached devices: %s\n", scd ? "" : "none");
+    SPRINTF ("\nAttached devices: %s\n", scd ? "" : "none");
 
-    for ( ; scd; scd = scd->next)
-        if (scd->host->host_no == hostno) {
+    for (; scd; scd = scd->next)
+	if (scd->host->host_no == hostno) {
 	    SPRINTF ("  [Channel: %02d, Id: %02d, Lun: %02d]  ",
 		     scd->channel, scd->id, scd->lun);
 	    SPRINTF ("%s ", (scd->type < MAX_SCSI_DEVICE_CODE) ?
 		     scsi_device_types[(short) scd->type] : "Unknown device");
 
 	    for (i = 0; (i < 8) && (scd->vendor[i] >= 0x20); i++)
-	        SPRINTF ("%c", scd->vendor[i]);
+		SPRINTF ("%c", scd->vendor[i]);
 	    SPRINTF (" ");
 
 	    for (i = 0; (i < 16) && (scd->model[i] >= 0x20); i++)
-	        SPRINTF ("%c", scd->model[i]);
+		SPRINTF ("%c", scd->model[i]);
 	    SPRINTF ("\n");
-        }
+	}
+
+    SPRINTF ("\n");
 
     restore_flags (flags);
 
@@ -1414,11 +1483,11 @@
     *start = buffer + offset;
 
     if ((pos - buffer) < offset)
-        return (0);
+	return (0);
     else if ((pos - buffer - offset) < length)
-        return (pos - buffer - offset);
+	return (pos - buffer - offset);
     else
-        return (length);
+	return (length);
 }
 
 
@@ -1434,14 +1503,14 @@
  */
 int wd7000_detect (Scsi_Host_Template *tpnt)
 {
-    short present = 0, biosaddr_ptr, cfg_ptr, sig_ptr, i, pass;
+    short present = 0, biosaddr_ptr, sig_ptr, i, pass;
     short biosptr[NUM_CONFIGS];
     unsigned iobase;
     Adapter *host = NULL;
     struct Scsi_Host *sh;
 
-    for (i = 0; i < IRQS; wd7000_host[i++] = NULL);
-    for (i = 0; i < NUM_CONFIGS; biosptr[i++] = -1);
+    for (i = 0; i < IRQS; wd7000_host[i++] = NULL) ;
+    for (i = 0; i < NUM_CONFIGS; biosptr[i++] = -1) ;
 
     tpnt->proc_dir = &proc_scsi_wd7000;
     tpnt->proc_info = &wd7000_proc_info;
@@ -1451,72 +1520,68 @@
      */
     init_scbs ();
 
-    for (pass = 0, cfg_ptr = 0; pass < NUM_CONFIGS; pass++) {
-        /*
+    for (pass = 0; pass < NUM_CONFIGS; pass++) {
+	/*
 	 * First, search for BIOS SIGNATURE...
 	 */
-        for (biosaddr_ptr = 0; biosaddr_ptr < NUM_ADDRS; biosaddr_ptr++)
+	for (biosaddr_ptr = 0; biosaddr_ptr < NUM_ADDRS; biosaddr_ptr++)
 	    for (sig_ptr = 0; sig_ptr < NUM_SIGNATURES; sig_ptr++) {
-	        for (i = 0; i < pass; i++)
-	            if (biosptr[i] == biosaddr_ptr)
-		        break;
+		for (i = 0; i < pass; i++)
+		    if (biosptr[i] == biosaddr_ptr)
+			break;
 
 		if ((i == pass) &&
 		    !memcmp ((void *) (wd7000_biosaddr[biosaddr_ptr] +
-		             signatures[sig_ptr].ofs), signatures[sig_ptr].sig,
-		             signatures[sig_ptr].len))
+				       signatures[sig_ptr].ofs), signatures[sig_ptr].sig,
+			     signatures[sig_ptr].len))
 		    goto bios_matched;
 	    }
 
-bios_matched:
+      bios_matched:
 	/*
 	 * BIOS SIGNATURE has been found.
 	 */
-#ifdef DEBUG
+#ifdef WD7000_DEBUG
 	printk ("wd7000_detect: pass %d\n", pass + 1);
 
-        if (biosaddr_ptr == NUM_ADDRS)
+	if (biosaddr_ptr == NUM_ADDRS)
 	    printk ("WD-7000 SST BIOS not detected...\n");
 	else
 	    printk ("WD-7000 SST BIOS detected at 0x%lx: checking...\n",
-	            wd7000_biosaddr[biosaddr_ptr]);
+		    wd7000_biosaddr[biosaddr_ptr]);
 #endif
 
-	if (wd7000_card_num) 
-	    iobase = wd7000_setupIO[wd7000_card_num - 1];
-	else {
-	    if (configs[cfg_ptr++].irq < 0)
-		continue;
+	if (configs[pass].irq < 0)
+	    continue;
 
-	    iobase = configs[cfg_ptr - 1].iobase;
-	}
+	iobase = configs[pass].iobase;
 
-#ifdef DEBUG
- 	printk ("wd7000_detect: check IO 0x%x region...\n", iobase);
+#ifdef WD7000_DEBUG
+	printk ("wd7000_detect: check IO 0x%x region...\n", iobase);
 #endif
 
-	if (! check_region (iobase, 4)) {
+	if (!check_region (iobase, 4)) {
 
-#ifdef DEBUG
- 	    printk ("wd7000_detect: ASC reset (IO 0x%x) ...", iobase);
+#ifdef WD7000_DEBUG
+	    printk ("wd7000_detect: ASC reset (IO 0x%x) ...", iobase);
 #endif
- 	    /*
-  	     * ASC reset...
- 	     */
- 	    outb (ASC_RES, iobase + ASC_CONTROL);
- 	    delay (1);
- 	    outb (0, iobase + ASC_CONTROL);
-
- 	    if (WAIT (iobase + ASC_STAT, ASC_STATMASK, CMD_RDY, 0))
-#ifdef DEBUG
- 	    {
-  		printk ("failed!\n");
-  		continue;
- 	    }
- 	    else
-  		printk ("ok!\n");
+	    /*
+	     * ASC reset...
+	     */
+	    outb (ASC_RES, iobase + ASC_CONTROL);
+	    delay (1);
+	    outb (0, iobase + ASC_CONTROL);
+
+	    if (WAIT (iobase + ASC_STAT, ASC_STATMASK, CMD_RDY, 0))
+#ifdef WD7000_DEBUG
+	    {
+		printk ("failed!\n");
+		continue;
+	    }
+	    else
+		printk ("ok!\n");
 #else
-	    continue;
+		continue;
 #endif
 
 	    if (inb (iobase + ASC_INTR_STAT) == 1) {
@@ -1530,31 +1595,27 @@
 		sh = scsi_register (tpnt, sizeof (Adapter));
 		host = (Adapter *) sh->hostdata;
 
-#ifdef DEBUG
+#ifdef WD7000_DEBUG
 		printk ("wd7000_detect: adapter allocated at 0x%x\n", (int) host);
 #endif
 
 		memset (host, 0, sizeof (Adapter));
 
-		if (wd7000_card_num) {
-		    host->irq = wd7000_setupIRQ[--wd7000_card_num];
-		    host->dma = wd7000_setupDMA[wd7000_card_num];
-		}
-		else {
-		    host->irq = configs[cfg_ptr - 1].irq;
-		    host->dma = configs[cfg_ptr - 1].dma;
-		}
-
-	    	host->sh = wd7000_host[host->irq - IRQ_MIN] = sh;
-    		host->iobase = iobase;
+		host->irq = configs[pass].irq;
+		host->dma = configs[pass].dma;
+		host->iobase = iobase;
+		host->int_counter = 0;
+		host->bus_on = configs[pass].bus_on;
+		host->bus_off = configs[pass].bus_off;
+		host->sh = wd7000_host[host->irq - IRQ_MIN] = sh;
 
-#ifdef DEBUG
+#ifdef WD7000_DEBUG
 		printk ("wd7000_detect: Trying init WD-7000 card at IO "
 			"0x%x, IRQ %d, DMA %d...\n",
 			host->iobase, host->irq, host->dma);
 #endif
 
-		if (! wd7000_init (host)) {  /* Initialization failed */
+		if (!wd7000_init (host)) {	/* Initialization failed */
 		    scsi_unregister (sh);
 
 		    continue;
@@ -1563,7 +1624,7 @@
 		/*
 		 *  OK from here - we'll use this adapter/configuration.
 		 */
-		wd7000_revision (host);   /* important for scatter/gather */
+		wd7000_revision (host);		/* important for scatter/gather */
 
 		/*
 		 * Register our ports.
@@ -1576,27 +1637,29 @@
 		if (host->rev1 < 6)
 		    sh->sg_tablesize = SG_NONE;
 
-		present++;		/* count it */
+		present++;	/* count it */
 
 		if (biosaddr_ptr != NUM_ADDRS)
 		    biosptr[pass] = biosaddr_ptr;
 
 		printk ("Western Digital WD-7000 (rev %d.%d) ",
 			host->rev1, host->rev2);
-		printk ("using IO 0x%x, IRQ %d, DMA %d.\n", 
+		printk ("using IO 0x%x, IRQ %d, DMA %d.\n",
 			host->iobase, host->irq, host->dma);
+                printk ("  BUS_ON time: %dns, BUS_OFF time: %dns\n",
+                        host->bus_on * 125, host->bus_off * 125);
 	    }
 	}
 
-#ifdef DEBUG
+#ifdef WD7000_DEBUG
 	else
- 	    printk ("wd7000_detect: IO 0x%x region already allocated!\n", iobase);
+	    printk ("wd7000_detect: IO 0x%x region already allocated!\n", iobase);
 #endif
 
     }
 
-    if (! present)
-       printk ("Failed initialization of WD-7000 SCSI card!\n");
+    if (!present)
+	printk ("Failed initialization of WD-7000 SCSI card!\n");
 
     return (present);
 }
@@ -1605,26 +1668,27 @@
 /*
  *  I have absolutely NO idea how to do an abort with the WD7000...
  */
-int wd7000_abort(Scsi_Cmnd * SCpnt)
+int wd7000_abort (Scsi_Cmnd *SCpnt)
 {
     Adapter *host = (Adapter *) SCpnt->host->hostdata;
 
-    if (inb(host->iobase+ASC_STAT) & INT_IM)  {
-	printk("wd7000_abort: lost interrupt\n");
-	wd7000_intr_handle(host->irq, NULL, NULL);
-	return SCSI_ABORT_SUCCESS;
+    if (inb (host->iobase + ASC_STAT) & INT_IM) {
+	printk ("wd7000_abort: lost interrupt\n");
+	wd7000_intr_handle (host->irq, NULL, NULL);
+
+	return (SCSI_ABORT_SUCCESS);
     }
 
-    return SCSI_ABORT_SNOOZE;
+    return (SCSI_ABORT_SNOOZE);
 }
 
 
 /*
  *  I also have no idea how to do a reset...
  */
-int wd7000_reset(Scsi_Cmnd * SCpnt)
+int wd7000_reset (Scsi_Cmnd *SCpnt)
 {
-    return SCSI_RESET_PUNT;
+    return (SCSI_RESET_PUNT);
 }
 
 
@@ -1633,8 +1697,8 @@
  */
 int wd7000_biosparam (Disk *disk, kdev_t dev, int *ip)
 {
-#ifdef BIOSPARAM_DEBUG
-    printk("wd7000_biosparam: dev=%s, size=%d, ", kdevname (dev), disk->capacity);
+#ifdef WD7000_DEBUG
+    printk ("wd7000_biosparam: dev=%s, size=%d, ", kdevname (dev), disk->capacity);
 #endif
 
     /*
@@ -1655,14 +1719,15 @@
 	 */
 	if ((scsicam_bios_param (disk, dev, info) < 0) ||
 	    !(((info[0] == 64) && (info[1] == 32)) ||
-	    ((info[0] == 255) && (info[1] == 63)))) {
+	      ((info[0] == 255) && (info[1] == 63)))) {
 	    printk ("wd7000_biosparam: unable to verify geometry for disk with >1GB.\n"
 		    "                  using extended translation.\n");
 
 	    ip[0] = 255;
 	    ip[1] = 63;
 	    ip[2] = disk->capacity / (255 * 63);
-	} else {
+	}
+	else {
 	    ip[0] = info[0];
 	    ip[1] = info[1];
 	    ip[2] = info[2];
@@ -1672,7 +1737,7 @@
 	}
     }
 
-#ifdef BIOSPARAM_DEBUG
+#ifdef WD7000_DEBUG
     printk ("bios geometry: head=%d, sec=%d, cyl=%d\n", ip[0], ip[1], ip[2]);
     printk ("WARNING: check, if the bios geometry is correct.\n");
 #endif

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov