Home | History | Annotate | Line # | Download | only in ic
aic79xxvar.h revision 1.9
      1  1.1     fvdl /*
      2  1.1     fvdl  * Core definitions and data structures shareable across OS platforms.
      3  1.1     fvdl  *
      4  1.1     fvdl  * Copyright (c) 1994-2002 Justin T. Gibbs.
      5  1.1     fvdl  * Copyright (c) 2000-2002 Adaptec Inc.
      6  1.1     fvdl  * All rights reserved.
      7  1.1     fvdl  *
      8  1.1     fvdl  * Redistribution and use in source and binary forms, with or without
      9  1.1     fvdl  * modification, are permitted provided that the following conditions
     10  1.1     fvdl  * are met:
     11  1.1     fvdl  * 1. Redistributions of source code must retain the above copyright
     12  1.1     fvdl  *    notice, this list of conditions, and the following disclaimer,
     13  1.1     fvdl  *    without modification.
     14  1.1     fvdl  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     15  1.1     fvdl  *    substantially similar to the "NO WARRANTY" disclaimer below
     16  1.1     fvdl  *    ("Disclaimer") and any redistribution must be conditioned upon
     17  1.1     fvdl  *    including a substantially similar Disclaimer requirement for further
     18  1.1     fvdl  *    binary redistribution.
     19  1.1     fvdl  * 3. Neither the names of the above-listed copyright holders nor the names
     20  1.1     fvdl  *    of any contributors may be used to endorse or promote products derived
     21  1.1     fvdl  *    from this software without specific prior written permission.
     22  1.1     fvdl  *
     23  1.1     fvdl  * Alternatively, this software may be distributed under the terms of the
     24  1.1     fvdl  * GNU General Public License ("GPL") version 2 as published by the Free
     25  1.1     fvdl  * Software Foundation.
     26  1.1     fvdl  *
     27  1.1     fvdl  * NO WARRANTY
     28  1.1     fvdl  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     29  1.1     fvdl  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     30  1.1     fvdl  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     31  1.1     fvdl  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     32  1.1     fvdl  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33  1.1     fvdl  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34  1.1     fvdl  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35  1.1     fvdl  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     36  1.1     fvdl  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     37  1.1     fvdl  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     38  1.1     fvdl  * POSSIBILITY OF SUCH DAMAGES.
     39  1.1     fvdl  *
     40  1.8  thorpej  * Id: //depot/aic7xxx/aic7xxx/aic79xx.h#92 $
     41  1.1     fvdl  *
     42  1.8  thorpej  * $FreeBSD: src/sys/dev/aic7xxx/aic79xx.h,v 1.13 2003/06/06 23:48:18 gibbs Exp $
     43  1.1     fvdl  */
     44  1.1     fvdl /*
     45  1.1     fvdl  * Ported from FreeBSD by Pascal Renauld, Network Storage Solutions, Inc. - April 2003
     46  1.1     fvdl  */
     47  1.1     fvdl 
     48  1.1     fvdl #ifndef _AIC79XXVAR_H_
     49  1.1     fvdl #define _AIC79XXVAR_H_
     50  1.1     fvdl 
     51  1.1     fvdl /* Register Definitions */
     52  1.1     fvdl #include <dev/microcode/aic7xxx/aic79xx_reg.h>
     53  1.1     fvdl 
     54  1.1     fvdl /************************* Forward Declarations *******************************/
     55  1.1     fvdl struct ahd_platform_data;
     56  1.1     fvdl struct scb_platform_data;
     57  1.1     fvdl 
     58  1.1     fvdl /****************************** Useful Macros *********************************/
     59  1.1     fvdl #ifndef MAX
     60  1.1     fvdl #define MAX(a,b) (((a) > (b)) ? (a) : (b))
     61  1.1     fvdl #endif
     62  1.1     fvdl 
     63  1.1     fvdl #ifndef MIN
     64  1.1     fvdl #define MIN(a,b) (((a) < (b)) ? (a) : (b))
     65  1.1     fvdl #endif
     66  1.1     fvdl 
     67  1.1     fvdl #ifndef TRUE
     68  1.1     fvdl #define TRUE 1
     69  1.1     fvdl #endif
     70  1.1     fvdl #ifndef FALSE
     71  1.1     fvdl #define FALSE 0
     72  1.1     fvdl #endif
     73  1.1     fvdl 
     74  1.1     fvdl #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array))
     75  1.1     fvdl 
     76  1.1     fvdl #define ALL_CHANNELS '\0'
     77  1.1     fvdl #define ALL_TARGETS_MASK 0xFFFF
     78  1.1     fvdl #define INITIATOR_WILDCARD	(~0)
     79  1.1     fvdl #define	SCB_LIST_NULL		0xFF00
     80  1.1     fvdl #define	SCB_LIST_NULL_LE	(ahd_htole16(SCB_LIST_NULL))
     81  1.1     fvdl #define QOUTFIFO_ENTRY_VALID 0x8000
     82  1.1     fvdl #define QOUTFIFO_ENTRY_VALID_LE (ahd_htole16(0x8000))
     83  1.1     fvdl #define SCBID_IS_NULL(scbid) (((scbid) & 0xFF00 ) == SCB_LIST_NULL)
     84  1.1     fvdl 
     85  1.1     fvdl #define SCSIID_TARGET(ahd, scsiid)	\
     86  1.1     fvdl 	(((scsiid) & TID) >> TID_SHIFT)
     87  1.1     fvdl #define SCSIID_OUR_ID(scsiid)		\
     88  1.1     fvdl 	((scsiid) & OID)
     89  1.1     fvdl #define SCSIID_CHANNEL(ahd, scsiid) ('A')
     90  1.1     fvdl #define	SCB_IS_SCSIBUS_B(ahd, scb) (0)
     91  1.1     fvdl #define	SCB_GET_OUR_ID(scb) \
     92  1.1     fvdl 	SCSIID_OUR_ID((scb)->hscb->scsiid)
     93  1.1     fvdl #define	SCB_GET_TARGET(ahd, scb) \
     94  1.1     fvdl 	SCSIID_TARGET((ahd), (scb)->hscb->scsiid)
     95  1.1     fvdl #define	SCB_GET_CHANNEL(ahd, scb) \
     96  1.1     fvdl 	SCSIID_CHANNEL(ahd, (scb)->hscb->scsiid)
     97  1.1     fvdl #define	SCB_GET_LUN(scb) \
     98  1.1     fvdl 	((scb)->hscb->lun)
     99  1.1     fvdl #define SCB_GET_TARGET_OFFSET(ahd, scb)	\
    100  1.1     fvdl 	SCB_GET_TARGET(ahd, scb)
    101  1.1     fvdl #define SCB_GET_TARGET_MASK(ahd, scb) \
    102  1.1     fvdl 	(0x01 << (SCB_GET_TARGET_OFFSET(ahd, scb)))
    103  1.1     fvdl #ifdef AHD_DEBUG
    104  1.1     fvdl #define SCB_IS_SILENT(scb)					\
    105  1.1     fvdl 	((ahd_debug & AHD_SHOW_MASKED_ERRORS) == 0		\
    106  1.1     fvdl       && (((scb)->flags & SCB_SILENT) != 0))
    107  1.1     fvdl #else
    108  1.1     fvdl #define SCB_IS_SILENT(scb)					\
    109  1.1     fvdl 	(((scb)->flags & SCB_SILENT) != 0)
    110  1.1     fvdl #endif
    111  1.1     fvdl /*
    112  1.1     fvdl  * TCLs have the following format: TTTTLLLLLLLL
    113  1.1     fvdl  */
    114  1.1     fvdl #define TCL_TARGET_OFFSET(tcl) \
    115  1.1     fvdl 	((((tcl) >> 4) & TID) >> 4)
    116  1.1     fvdl #define TCL_LUN(tcl) \
    117  1.1     fvdl 	(tcl & (AHD_NUM_LUNS - 1))
    118  1.1     fvdl #define BUILD_TCL(scsiid, lun) \
    119  1.1     fvdl 	((lun) | (((scsiid) & TID) << 4))
    120  1.1     fvdl #define BUILD_TCL_RAW(target, channel, lun) \
    121  1.1     fvdl 	((lun) | ((target) << 8))
    122  1.1     fvdl 
    123  1.1     fvdl #define SCB_GET_TAG(scb) \
    124  1.1     fvdl 	ahd_le16toh(scb->hscb->tag)
    125  1.1     fvdl 
    126  1.1     fvdl #ifndef	AHD_TARGET_MODE
    127  1.1     fvdl #undef	AHD_TMODE_ENABLE
    128  1.1     fvdl #define	AHD_TMODE_ENABLE 0
    129  1.1     fvdl #endif
    130  1.1     fvdl 
    131  1.1     fvdl #define AHD_BUILD_COL_IDX(target, lun)				\
    132  1.1     fvdl 	(((lun) << 4) | target)
    133  1.1     fvdl 
    134  1.1     fvdl #define AHD_GET_SCB_COL_IDX(ahd, scb)				\
    135  1.1     fvdl 	((SCB_GET_LUN(scb) << 4) | SCB_GET_TARGET(ahd, scb))
    136  1.1     fvdl 
    137  1.1     fvdl #define AHD_SET_SCB_COL_IDX(scb, col_idx)				\
    138  1.1     fvdl do {									\
    139  1.1     fvdl 	(scb)->hscb->scsiid = ((col_idx) << TID_SHIFT) & TID;		\
    140  1.1     fvdl 	(scb)->hscb->lun = ((col_idx) >> 4) & (AHD_NUM_LUNS_NONPKT-1);	\
    141  1.1     fvdl } while (0)
    142  1.1     fvdl 
    143  1.1     fvdl #define AHD_COPY_SCB_COL_IDX(dst, src)				\
    144  1.1     fvdl do {								\
    145  1.1     fvdl 	dst->hscb->scsiid = src->hscb->scsiid;			\
    146  1.1     fvdl 	dst->hscb->lun = src->hscb->lun;			\
    147  1.1     fvdl } while (0)
    148  1.1     fvdl 
    149  1.1     fvdl #define	AHD_NEVER_COL_IDX 0xFFFF
    150  1.1     fvdl 
    151  1.1     fvdl /**************************** Driver Constants ********************************/
    152  1.1     fvdl /*
    153  1.1     fvdl  * The maximum number of supported targets.
    154  1.1     fvdl  */
    155  1.1     fvdl #define AHD_NUM_TARGETS 16
    156  1.1     fvdl 
    157  1.1     fvdl /*
    158  1.1     fvdl  * The maximum number of supported luns.
    159  1.1     fvdl  * The identify message only supports 64 luns in non-packetized transfers.
    160  1.1     fvdl  * You can have 2^64 luns when information unit transfers are enabled,
    161  1.1     fvdl  * but until we see a need to support that many, we support 256.
    162  1.1     fvdl  */
    163  1.1     fvdl #define AHD_NUM_LUNS_NONPKT 64
    164  1.1     fvdl #define AHD_NUM_LUNS 256
    165  1.1     fvdl 
    166  1.1     fvdl /*
    167  1.1     fvdl  * The maximum transfer per S/G segment.
    168  1.1     fvdl  */
    169  1.1     fvdl #define AHD_MAXTRANSFER_SIZE	 0x00ffffff	/* limited by 24bit counter */
    170  1.1     fvdl 
    171  1.1     fvdl /*
    172  1.1     fvdl  * The maximum amount of SCB storage in hardware on a controller.
    173  1.1     fvdl  * This value represents an upper bound.  Due to software design,
    174  1.1     fvdl  * we may not be able to use this number.
    175  1.1     fvdl  */
    176  1.1     fvdl #define AHD_SCB_MAX	512
    177  1.1     fvdl 
    178  1.1     fvdl /*
    179  1.1     fvdl  * The maximum number of concurrent transactions supported per driver instance.
    180  1.1     fvdl  * Sequencer Control Blocks (SCBs) store per-transaction information.
    181  1.1     fvdl  */
    182  1.1     fvdl #define AHD_MAX_QUEUE	AHD_SCB_MAX
    183  1.1     fvdl 
    184  1.1     fvdl /*
    185  1.1     fvdl  * Define the size of our QIN and QOUT FIFOs.  They must be a power of 2
    186  1.7  thorpej  * in size and accommodate as many transactions as can be queued concurrently.
    187  1.1     fvdl  */
    188  1.1     fvdl #define	AHD_QIN_SIZE	AHD_MAX_QUEUE
    189  1.1     fvdl #define	AHD_QOUT_SIZE	AHD_MAX_QUEUE
    190  1.1     fvdl 
    191  1.1     fvdl #define AHD_QIN_WRAP(x) ((x) & (AHD_QIN_SIZE-1))
    192  1.1     fvdl /*
    193  1.1     fvdl  * The maximum amount of SCB storage we allocate in host memory.
    194  1.1     fvdl  */
    195  1.1     fvdl #define AHD_SCB_MAX_ALLOC AHD_MAX_QUEUE
    196  1.1     fvdl 
    197  1.1     fvdl /*
    198  1.1     fvdl  * Ring Buffer of incoming target commands.
    199  1.1     fvdl  * We allocate 256 to simplify the logic in the sequencer
    200  1.1     fvdl  * by using the natural wrap point of an 8bit counter.
    201  1.1     fvdl  */
    202  1.1     fvdl #define AHD_TMODE_CMDS	256
    203  1.1     fvdl 
    204  1.1     fvdl /* Reset line assertion time in us */
    205  1.1     fvdl #define AHD_BUSRESET_DELAY	25
    206  1.1     fvdl 
    207  1.1     fvdl /******************* Chip Characteristics/Operating Settings  *****************/
    208  1.1     fvdl /*
    209  1.1     fvdl  * Chip Type
    210  1.1     fvdl  * The chip order is from least sophisticated to most sophisticated.
    211  1.1     fvdl  */
    212  1.1     fvdl typedef enum {
    213  1.1     fvdl 	AHD_NONE	= 0x0000,
    214  1.1     fvdl 	AHD_CHIPID_MASK	= 0x00FF,
    215  1.1     fvdl 	AHD_AIC7901	= 0x0001,
    216  1.1     fvdl 	AHD_AIC7902	= 0x0002,
    217  1.1     fvdl 	AHD_AIC7901A	= 0x0003,
    218  1.1     fvdl 	AHD_PCI		= 0x0100,	/* Bus type PCI */
    219  1.1     fvdl 	AHD_PCIX	= 0x0200,	/* Bus type PCIX */
    220  1.1     fvdl 	AHD_BUS_MASK	= 0x0F00
    221  1.1     fvdl } ahd_chip;
    222  1.1     fvdl 
    223  1.1     fvdl /*
    224  1.1     fvdl  * Features available in each chip type.
    225  1.1     fvdl  */
    226  1.1     fvdl typedef enum {
    227  1.1     fvdl 	AHD_FENONE		= 0x00000,
    228  1.1     fvdl 	AHD_WIDE  		= 0x00001,/* Wide Channel */
    229  1.1     fvdl 	AHD_MULTI_FUNC		= 0x00100,/* Multi-Function/Channel Device */
    230  1.1     fvdl 	AHD_TARGETMODE		= 0x01000,/* Has tested target mode support */
    231  1.1     fvdl 	AHD_MULTIROLE		= 0x02000,/* Space for two roles at a time */
    232  1.1     fvdl 	AHD_RTI			= 0x04000,/* Retained Training Support */
    233  1.1     fvdl 	AHD_NEW_IOCELL_OPTS	= 0x08000,/* More Signal knobs in the IOCELL */
    234  1.1     fvdl 	AHD_NEW_DFCNTRL_OPTS	= 0x10000,/* SCSIENWRDIS bit */
    235  1.1     fvdl 	AHD_REMOVABLE		= 0x00000,/* Hot-Swap supported - None so far*/
    236  1.1     fvdl 	AHD_AIC7901_FE		= AHD_FENONE,
    237  1.1     fvdl 	AHD_AIC7902_FE		= AHD_MULTI_FUNC
    238  1.1     fvdl } ahd_feature;
    239  1.1     fvdl 
    240  1.1     fvdl /*
    241  1.1     fvdl  * Bugs in the silicon that we work around in software.
    242  1.1     fvdl  */
    243  1.1     fvdl typedef enum {
    244  1.1     fvdl 	AHD_BUGNONE		= 0x0000,
    245  1.1     fvdl 	/*
    246  1.1     fvdl 	 * Rev A hardware fails to update LAST/CURR/NEXTSCB
    247  1.1     fvdl 	 * correctly in certain packetized selection cases.
    248  1.1     fvdl 	 */
    249  1.1     fvdl 	AHD_SENT_SCB_UPDATE_BUG	= 0x0001,
    250  1.1     fvdl 	/* The wrong SCB is accessed to check the abort pending bit. */
    251  1.1     fvdl 	AHD_ABORT_LQI_BUG	= 0x0002,
    252  1.1     fvdl 	/* Packetized bitbucket crosses packet boundaries. */
    253  1.1     fvdl 	AHD_PKT_BITBUCKET_BUG	= 0x0004,
    254  1.1     fvdl 	/* The selection timer runs twice as long as its setting. */
    255  1.1     fvdl 	AHD_LONG_SETIMO_BUG	= 0x0008,
    256  1.1     fvdl 	/* The Non-LQ CRC error status is delayed until phase change. */
    257  1.1     fvdl 	AHD_NLQICRC_DELAYED_BUG	= 0x0010,
    258  1.1     fvdl 	/* The chip must be reset for all outgoing bus resets.  */
    259  1.1     fvdl 	AHD_SCSIRST_BUG		= 0x0020,
    260  1.1     fvdl 	/* Some PCIX fields must be saved and restored across chip reset. */
    261  1.1     fvdl 	AHD_PCIX_CHIPRST_BUG	= 0x0040,
    262  1.1     fvdl 	/* MMAPIO is not functional in PCI-X mode.  */
    263  1.1     fvdl 	AHD_PCIX_MMAPIO_BUG	= 0x0080,
    264  1.1     fvdl 	/* Reads to SCBRAM fail to reset the discard timer. */
    265  1.1     fvdl 	AHD_PCIX_SCBRAM_RD_BUG  = 0x0100,
    266  1.1     fvdl 	/* Bug workarounds that can be disabled on non-PCIX busses. */
    267  1.1     fvdl 	AHD_PCIX_BUG_MASK	= AHD_PCIX_CHIPRST_BUG
    268  1.1     fvdl 				| AHD_PCIX_MMAPIO_BUG
    269  1.1     fvdl 				| AHD_PCIX_SCBRAM_RD_BUG,
    270  1.1     fvdl 	/*
    271  1.1     fvdl 	 * LQOSTOP0 status set even for forced selections with ATN
    272  1.1     fvdl 	 * to perform non-packetized message delivery.
    273  1.1     fvdl 	 */
    274  1.1     fvdl 	AHD_LQO_ATNO_BUG	= 0x0200,
    275  1.1     fvdl 	/* FIFO auto-flush does not always trigger.  */
    276  1.1     fvdl 	AHD_AUTOFLUSH_BUG	= 0x0400,
    277  1.1     fvdl 	/* The CLRLQO registers are not self-clearing. */
    278  1.1     fvdl 	AHD_CLRLQO_AUTOCLR_BUG	= 0x0800,
    279  1.1     fvdl 	/* The PACKETIZED status bit refers to the previous connection. */
    280  1.1     fvdl 	AHD_PKTIZED_STATUS_BUG  = 0x1000,
    281  1.1     fvdl 	/* "Short Luns" are not placed into outgoing LQ packets correctly. */
    282  1.1     fvdl 	AHD_PKT_LUN_BUG		= 0x2000,
    283  1.1     fvdl 	/*
    284  1.1     fvdl 	 * Only the FIFO allocated to the non-packetized connection may
    285  1.1     fvdl 	 * be in use during a non-packetzied connection.
    286  1.1     fvdl 	 */
    287  1.1     fvdl 	AHD_NONPACKFIFO_BUG	= 0x4000,
    288  1.1     fvdl 	/*
    289  1.1     fvdl 	 * Writing to a DFF SCBPTR register may fail if concurent with
    290  1.1     fvdl 	 * a hardware write to the other DFF SCBPTR register.  This is
    291  1.1     fvdl 	 * not currently a concern in our sequencer since all chips with
    292  1.1     fvdl 	 * this bug have the AHD_NONPACKFIFO_BUG and all writes of concern
    293  1.1     fvdl 	 * occur in non-packetized connections.
    294  1.1     fvdl 	 */
    295  1.1     fvdl 	AHD_MDFF_WSCBPTR_BUG	= 0x8000,
    296  1.1     fvdl 	/* SGHADDR updates are slow. */
    297  1.1     fvdl 	AHD_REG_SLOW_SETTLE_BUG	= 0x10000,
    298  1.1     fvdl 	/*
    299  1.1     fvdl 	 * Changing the MODE_PTR coincident with an interrupt that
    300  1.1     fvdl 	 * switches to a different mode will cause the interrupt to
    301  1.1     fvdl 	 * be in the mode written outside of interrupt context.
    302  1.1     fvdl 	 */
    303  1.1     fvdl 	AHD_SET_MODE_BUG	= 0x20000,
    304  1.1     fvdl 	/* Non-packetized busfree revision does not work. */
    305  1.1     fvdl 	AHD_BUSFREEREV_BUG	= 0x40000,
    306  1.1     fvdl 	/*
    307  1.1     fvdl 	 * Paced transfers are indicated with a non-standard PPR
    308  1.1     fvdl 	 * option bit in the neg table, 160MHz is indicated by
    309  1.1     fvdl 	 * sync factor 0x7, and the offset if off by a factor of 2.
    310  1.1     fvdl 	 */
    311  1.1     fvdl 	AHD_PACED_NEGTABLE_BUG	= 0x80000,
    312  1.1     fvdl 	/* LQOOVERRUN false positives. */
    313  1.1     fvdl 	AHD_LQOOVERRUN_BUG	= 0x100000,
    314  1.1     fvdl 	/*
    315  1.1     fvdl 	 * Controller write to INTSTAT will lose to a host
    316  1.1     fvdl 	 * write to CLRINT.
    317  1.1     fvdl 	 */
    318  1.1     fvdl 	AHD_INTCOLLISION_BUG	= 0x200000,
    319  1.1     fvdl 	/*
    320  1.1     fvdl 	 * The GEM318 violates the SCSI spec by not waiting
    321  1.1     fvdl 	 * the mandated bus settle delay between phase changes
    322  1.1     fvdl 	 * in some situations.  Some aic79xx chip revs. are more
    323  1.1     fvdl 	 * strict in this regard and will treat REQ assertions
    324  1.1     fvdl 	 * that fall within the bus settle delay window as
    325  1.1     fvdl 	 * glitches.  This flag tells the firmware to tolerate
    326  1.1     fvdl 	 * early REQ assertions.
    327  1.1     fvdl 	 */
    328  1.7  thorpej 	AHD_EARLY_REQ_BUG	= 0x400000,
    329  1.7  thorpej 	/*
    330  1.7  thorpej 	 * The LED does not stay on long enough in packetized modes.
    331  1.7  thorpej 	 */
    332  1.7  thorpej 	AHD_FAINT_LED_BUG	= 0x800000
    333  1.1     fvdl } ahd_bug;
    334  1.1     fvdl 
    335  1.1     fvdl /*
    336  1.1     fvdl  * Configuration specific settings.
    337  1.1     fvdl  * The driver determines these settings by probing the
    338  1.1     fvdl  * chip/controller's configuration.
    339  1.1     fvdl  */
    340  1.1     fvdl typedef enum {
    341  1.1     fvdl 	AHD_FNONE	      = 0x00000,
    342  1.7  thorpej 	AHD_BOOT_CHANNEL      = 0x00001,/* We were set as the boot channel. */
    343  1.1     fvdl 	AHD_USEDEFAULTS	      = 0x00004,/*
    344  1.1     fvdl 					 * For cards without an seeprom
    345  1.1     fvdl 					 * or a BIOS to initialize the chip's
    346  1.1     fvdl 					 * SRAM, we use the default target
    347  1.1     fvdl 					 * settings.
    348  1.1     fvdl 					 */
    349  1.1     fvdl 	AHD_SEQUENCER_DEBUG   = 0x00008,
    350  1.1     fvdl 	AHD_RESET_BUS_A	      = 0x00010,
    351  1.1     fvdl 	AHD_EXTENDED_TRANS_A  = 0x00020,
    352  1.1     fvdl 	AHD_TERM_ENB_A	      = 0x00040,
    353  1.1     fvdl 	AHD_SPCHK_ENB_A	      = 0x00080,
    354  1.1     fvdl 	AHD_STPWLEVEL_A	      = 0x00100,
    355  1.1     fvdl 	AHD_INITIATORROLE     = 0x00200,/*
    356  1.1     fvdl 					 * Allow initiator operations on
    357  1.1     fvdl 					 * this controller.
    358  1.1     fvdl 					 */
    359  1.1     fvdl 	AHD_TARGETROLE	      = 0x00400,/*
    360  1.1     fvdl 					 * Allow target operations on this
    361  1.1     fvdl 					 * controller.
    362  1.1     fvdl 					 */
    363  1.1     fvdl 	AHD_RESOURCE_SHORTAGE = 0x00800,
    364  1.1     fvdl 	AHD_TQINFIFO_BLOCKED  = 0x01000,/* Blocked waiting for ATIOs */
    365  1.1     fvdl 	AHD_INT50_SPEEDFLEX   = 0x02000,/*
    366  1.1     fvdl 					 * Internal 50pin connector
    367  1.1     fvdl 					 * sits behind an aic3860
    368  1.1     fvdl 					 */
    369  1.1     fvdl 	AHD_BIOS_ENABLED      = 0x04000,
    370  1.1     fvdl 	AHD_ALL_INTERRUPTS    = 0x08000,
    371  1.1     fvdl 	AHD_39BIT_ADDRESSING  = 0x10000,/* Use 39 bit addressing scheme. */
    372  1.1     fvdl 	AHD_64BIT_ADDRESSING  = 0x20000,/* Use 64 bit addressing scheme. */
    373  1.1     fvdl 	AHD_CURRENT_SENSING   = 0x40000,
    374  1.1     fvdl 	AHD_SCB_CONFIG_USED   = 0x80000,/* No SEEPROM but SCB had info. */
    375  1.1     fvdl 	AHD_HP_BOARD	      = 0x100000,
    376  1.1     fvdl 	AHD_RESET_POLL_ACTIVE = 0x200000,
    377  1.1     fvdl 	AHD_UPDATE_PEND_CMDS  = 0x400000,
    378  1.1     fvdl 	AHD_RUNNING_QOUTFIFO  = 0x800000
    379  1.1     fvdl } ahd_flag;
    380  1.1     fvdl 
    381  1.1     fvdl /************************* Hardware  SCB Definition ***************************/
    382  1.1     fvdl 
    383  1.1     fvdl /*
    384  1.1     fvdl  * The driver keeps up to MAX_SCB scb structures per card in memory.  The SCB
    385  1.1     fvdl  * consists of a "hardware SCB" mirroring the fields available on the card
    386  1.1     fvdl  * and additional information the kernel stores for each transaction.
    387  1.1     fvdl  *
    388  1.1     fvdl  * To minimize space utilization, a portion of the hardware scb stores
    389  1.1     fvdl  * different data during different portions of a SCSI transaction.
    390  1.1     fvdl  * As initialized by the host driver for the initiator role, this area
    391  1.1     fvdl  * contains the SCSI cdb (or a pointer to the  cdb) to be executed.  After
    392  1.1     fvdl  * the cdb has been presented to the target, this area serves to store
    393  1.1     fvdl  * residual transfer information and the SCSI status byte.
    394  1.1     fvdl  * For the target role, the contents of this area do not change, but
    395  1.1     fvdl  * still serve a different purpose than for the initiator role.  See
    396  1.1     fvdl  * struct target_data for details.
    397  1.1     fvdl  */
    398  1.1     fvdl 
    399  1.1     fvdl /*
    400  1.1     fvdl  * Status information embedded in the shared portion of
    401  1.1     fvdl  * an SCB after passing the cdb to the target.  The kernel
    402  1.1     fvdl  * driver will only read this data for transactions that
    403  1.1     fvdl  * complete abnormally.
    404  1.1     fvdl  */
    405  1.1     fvdl struct initiator_status {
    406  1.1     fvdl 	uint32_t residual_datacnt;	/* Residual in the current S/G seg */
    407  1.1     fvdl 	uint32_t residual_sgptr;	/* The next S/G for this transfer */
    408  1.1     fvdl 	uint8_t	 scsi_status;		/* Standard SCSI status byte */
    409  1.1     fvdl };
    410  1.1     fvdl 
    411  1.1     fvdl struct target_status {
    412  1.1     fvdl 	uint32_t residual_datacnt;	/* Residual in the current S/G seg */
    413  1.1     fvdl 	uint32_t residual_sgptr;	/* The next S/G for this transfer */
    414  1.1     fvdl 	uint8_t  scsi_status;		/* SCSI status to give to initiator */
    415  1.1     fvdl 	uint8_t  target_phases;		/* Bitmap of phases to execute */
    416  1.1     fvdl 	uint8_t  data_phase;		/* Data-In or Data-Out */
    417  1.1     fvdl 	uint8_t  initiator_tag;		/* Initiator's transaction tag */
    418  1.1     fvdl };
    419  1.1     fvdl 
    420  1.1     fvdl /*
    421  1.1     fvdl  * Initiator mode SCB shared data area.
    422  1.1     fvdl  * If the embedded CDB is 12 bytes or less, we embed
    423  1.1     fvdl  * the sense buffer address in the SCB.  This allows
    424  1.1     fvdl  * us to retrieve sense information without interrupting
    425  1.1     fvdl  * the host in packetized mode.
    426  1.1     fvdl  */
    427  1.1     fvdl typedef uint32_t sense_addr_t;
    428  1.1     fvdl #define MAX_CDB_LEN 16
    429  1.1     fvdl #define MAX_CDB_LEN_WITH_SENSE_ADDR (MAX_CDB_LEN - sizeof(sense_addr_t))
    430  1.1     fvdl union initiator_data {
    431  1.1     fvdl 	struct {
    432  1.1     fvdl 		uint64_t cdbptr;
    433  1.1     fvdl 		uint8_t  cdblen;
    434  1.1     fvdl 	} cdb_from_host;
    435  1.1     fvdl 	uint8_t	 cdb[MAX_CDB_LEN];
    436  1.1     fvdl 	struct {
    437  1.1     fvdl 		uint8_t	 cdb[MAX_CDB_LEN_WITH_SENSE_ADDR];
    438  1.1     fvdl 		sense_addr_t sense_addr;
    439  1.1     fvdl 	} cdb_plus_saddr;
    440  1.1     fvdl };
    441  1.1     fvdl 
    442  1.1     fvdl /*
    443  1.1     fvdl  * Target mode version of the shared data SCB segment.
    444  1.1     fvdl  */
    445  1.1     fvdl struct target_data {
    446  1.1     fvdl 	uint32_t spare[2];
    447  1.1     fvdl 	uint8_t  scsi_status;		/* SCSI status to give to initiator */
    448  1.1     fvdl 	uint8_t  target_phases;		/* Bitmap of phases to execute */
    449  1.1     fvdl 	uint8_t  data_phase;		/* Data-In or Data-Out */
    450  1.1     fvdl 	uint8_t  initiator_tag;		/* Initiator's transaction tag */
    451  1.1     fvdl };
    452  1.1     fvdl 
    453  1.1     fvdl struct hardware_scb {
    454  1.1     fvdl /*0*/	union {
    455  1.1     fvdl 		union	initiator_data idata;
    456  1.1     fvdl 		struct	target_data tdata;
    457  1.1     fvdl 		struct	initiator_status istatus;
    458  1.1     fvdl 		struct	target_status tstatus;
    459  1.1     fvdl 	} shared_data;
    460  1.1     fvdl /*
    461  1.1     fvdl  * A word about residuals.
    462  1.1     fvdl  * The scb is presented to the sequencer with the dataptr and datacnt
    463  1.1     fvdl  * fields initialized to the contents of the first S/G element to
    464  1.1     fvdl  * transfer.  The sgptr field is initialized to the bus address for
    465  1.1     fvdl  * the S/G element that follows the first in the in core S/G array
    466  1.1     fvdl  * or'ed with the SG_FULL_RESID flag.  Sgptr may point to an invalid
    467  1.1     fvdl  * S/G entry for this transfer (single S/G element transfer with the
    468  1.1     fvdl  * first elements address and length preloaded in the dataptr/datacnt
    469  1.1     fvdl  * fields).  If no transfer is to occur, sgptr is set to SG_LIST_NULL.
    470  1.1     fvdl  * The SG_FULL_RESID flag ensures that the residual will be correctly
    471  1.1     fvdl  * noted even if no data transfers occur.  Once the data phase is entered,
    472  1.1     fvdl  * the residual sgptr and datacnt are loaded from the sgptr and the
    473  1.1     fvdl  * datacnt fields.  After each S/G element's dataptr and length are
    474  1.1     fvdl  * loaded into the hardware, the residual sgptr is advanced.  After
    475  1.1     fvdl  * each S/G element is expired, its datacnt field is checked to see
    476  1.1     fvdl  * if the LAST_SEG flag is set.  If so, SG_LIST_NULL is set in the
    477  1.1     fvdl  * residual sg ptr and the transfer is considered complete.  If the
    478  1.1     fvdl  * sequencer determines that there is a residual in the tranfer, or
    479  1.1     fvdl  * there is non-zero status, it will set the SG_STATUS_VALID flag in
    480  1.3      wiz  * sgptr and DMA the scb back into host memory.  To summarize:
    481  1.1     fvdl  *
    482  1.1     fvdl  * Sequencer:
    483  1.1     fvdl  *	o A residual has occurred if SG_FULL_RESID is set in sgptr,
    484  1.1     fvdl  *	  or residual_sgptr does not have SG_LIST_NULL set.
    485  1.1     fvdl  *
    486  1.1     fvdl  *	o We are transfering the last segment if residual_datacnt has
    487  1.1     fvdl  *	  the SG_LAST_SEG flag set.
    488  1.1     fvdl  *
    489  1.1     fvdl  * Host:
    490  1.1     fvdl  *	o A residual can only have occurred if a completed scb has the
    491  1.1     fvdl  *	  SG_STATUS_VALID flag set.  Inspection of the SCSI status field,
    492  1.1     fvdl  *	  the residual_datacnt, and the residual_sgptr field will tell
    493  1.1     fvdl  *	  for sure.
    494  1.1     fvdl  *
    495  1.1     fvdl  *	o residual_sgptr and sgptr refer to the "next" sg entry
    496  1.1     fvdl  *	  and so may point beyond the last valid sg entry for the
    497  1.1     fvdl  *	  transfer.
    498  1.1     fvdl  */
    499  1.1     fvdl #define SG_PTR_MASK	0xFFFFFFF8
    500  1.9  thorpej /*16*/	uint16_t tag;		/* Reused by Sequencer. */
    501  1.9  thorpej /*18*/	uint8_t  control;	/* See SCB_CONTROL in aic79xx.reg for details */
    502  1.9  thorpej /*19*/	uint8_t	 scsiid;	/*
    503  1.1     fvdl 				 * Selection out Id
    504  1.1     fvdl 				 * Our Id (bits 0-3) Their ID (bits 4-7)
    505  1.1     fvdl 				 */
    506  1.9  thorpej /*20*/	uint8_t  lun;
    507  1.9  thorpej /*21*/	uint8_t  task_attribute;
    508  1.9  thorpej /*22*/	uint8_t  cdb_len;
    509  1.9  thorpej /*23*/	uint8_t  task_management;
    510  1.9  thorpej /*24*/	uint64_t dataptr;
    511  1.9  thorpej /*32*/	uint32_t datacnt;	/* Byte 3 is spare. */
    512  1.9  thorpej /*36*/	uint32_t sgptr;
    513  1.9  thorpej /*40*/	uint32_t hscb_busaddr;
    514  1.9  thorpej /*44*/	uint32_t next_hscb_busaddr;
    515  1.7  thorpej /********** Long lun field only downloaded for full 8 byte lun support ********/
    516  1.1     fvdl /*48*/  uint8_t	 pkt_long_lun[8];
    517  1.1     fvdl /******* Fields below are not Downloaded (Sequencer may use for scratch) ******/
    518  1.1     fvdl /*56*/  uint8_t	 spare[8];
    519  1.1     fvdl };
    520  1.1     fvdl 
    521  1.1     fvdl /************************ Kernel SCB Definitions ******************************/
    522  1.1     fvdl /*
    523  1.1     fvdl  * Some fields of the SCB are OS dependent.  Here we collect the
    524  1.1     fvdl  * definitions for elements that all OS platforms need to include
    525  1.1     fvdl  * in there SCB definition.
    526  1.1     fvdl  */
    527  1.1     fvdl 
    528  1.1     fvdl /*
    529  1.1     fvdl  * Definition of a scatter/gather element as transfered to the controller.
    530  1.1     fvdl  * The aic7xxx chips only support a 24bit length.  We use the top byte of
    531  1.1     fvdl  * the length to store additional address bits and a flag to indicate
    532  1.1     fvdl  * that a given segment terminates the transfer.  This gives us an
    533  1.1     fvdl  * addressable range of 512GB on machines with 64bit PCI or with chips
    534  1.1     fvdl  * that can support dual address cycles on 32bit PCI busses.
    535  1.1     fvdl  */
    536  1.1     fvdl struct ahd_dma_seg {
    537  1.1     fvdl 	uint32_t	addr;
    538  1.1     fvdl 	uint32_t	len;
    539  1.1     fvdl #define	AHD_DMA_LAST_SEG	0x80000000
    540  1.1     fvdl #define	AHD_SG_HIGH_ADDR_MASK	0x7F000000
    541  1.1     fvdl #define	AHD_SG_LEN_MASK		0x00FFFFFF
    542  1.1     fvdl };
    543  1.1     fvdl 
    544  1.1     fvdl struct ahd_dma64_seg {
    545  1.1     fvdl 	uint64_t	addr;
    546  1.1     fvdl 	uint32_t	len;
    547  1.1     fvdl 	uint32_t	pad;
    548  1.1     fvdl };
    549  1.1     fvdl 
    550  1.1     fvdl struct map_node {
    551  1.1     fvdl 	bus_dmamap_t		 dmamap;
    552  1.1     fvdl 	bus_addr_t		 physaddr;
    553  1.1     fvdl 	uint8_t			*vaddr;
    554  1.1     fvdl 	bus_dma_segment_t	 dmasegs;
    555  1.1     fvdl 	int			 nseg;
    556  1.1     fvdl 	SLIST_ENTRY(map_node)	 links;
    557  1.1     fvdl };
    558  1.1     fvdl 
    559  1.1     fvdl struct ahd_pci_busdata {
    560  1.1     fvdl 	pci_chipset_tag_t pc;
    561  1.1     fvdl 	pcitag_t tag;
    562  1.1     fvdl 	u_int dev;
    563  1.1     fvdl 	u_int func;
    564  1.1     fvdl 	int pcix_off;
    565  1.1     fvdl };
    566  1.1     fvdl 
    567  1.1     fvdl /*
    568  1.1     fvdl  * The current state of this SCB.
    569  1.1     fvdl  */
    570  1.1     fvdl typedef enum {
    571  1.1     fvdl 	SCB_FLAG_NONE		= 0x00000,
    572  1.1     fvdl 	SCB_TRANSMISSION_ERROR	= 0x00001,/*
    573  1.1     fvdl 					   * We detected a parity or CRC
    574  1.1     fvdl 					   * error that has effected the
    575  1.1     fvdl 					   * payload of the command.  This
    576  1.1     fvdl 					   * flag is checked when normal
    577  1.1     fvdl 					   * status is returned to catch
    578  1.1     fvdl 					   * the case of a target not
    579  1.1     fvdl 					   * responding to our attempt
    580  1.1     fvdl 					   * to report the error.
    581  1.1     fvdl 					   */
    582  1.1     fvdl 	SCB_OTHERTCL_TIMEOUT	= 0x00002,/*
    583  1.1     fvdl 					   * Another device was active
    584  1.1     fvdl 					   * during the first timeout for
    585  1.1     fvdl 					   * this SCB so we gave ourselves
    586  1.1     fvdl 					   * an additional timeout period
    587  1.1     fvdl 					   * in case it was hogging the
    588  1.1     fvdl 					   * bus.
    589  1.1     fvdl 				           */
    590  1.1     fvdl 	SCB_DEVICE_RESET	= 0x00004,
    591  1.1     fvdl 	SCB_SENSE		= 0x00008,
    592  1.1     fvdl 	SCB_CDB32_PTR		= 0x00010,
    593  1.1     fvdl 	SCB_RECOVERY_SCB	= 0x00020,
    594  1.1     fvdl 	SCB_AUTO_NEGOTIATE	= 0x00040,/* Negotiate to achieve goal. */
    595  1.1     fvdl 	SCB_NEGOTIATE		= 0x00080,/* Negotiation forced for command. */
    596  1.1     fvdl 	SCB_ABORT		= 0x00100,
    597  1.1     fvdl 	SCB_ACTIVE		= 0x00200,
    598  1.1     fvdl 	SCB_TARGET_IMMEDIATE	= 0x00400,
    599  1.1     fvdl 	SCB_PACKETIZED		= 0x00800,
    600  1.1     fvdl 	SCB_EXPECT_PPR_BUSFREE	= 0x01000,
    601  1.1     fvdl 	SCB_PKT_SENSE		= 0x02000,
    602  1.1     fvdl 	SCB_CMDPHASE_ABORT	= 0x04000,
    603  1.1     fvdl 	SCB_ON_COL_LIST		= 0x08000,
    604  1.1     fvdl 	SCB_SILENT		= 0x10000,/*
    605  1.1     fvdl 					   * Be quiet about transmission type
    606  1.1     fvdl 					   * errors.  They are expected and we
    607  1.1     fvdl 					   * don't want to upset the user.  This
    608  1.1     fvdl 					   * flag is typically used during DV.
    609  1.1     fvdl 					   */
    610  1.1     fvdl 	SCB_FREEZE_QUEUE        = 0x20000,
    611  1.1     fvdl 	SCB_REQUEUE		= 0x40000,
    612  1.1     fvdl } scb_flag;
    613  1.1     fvdl 
    614  1.1     fvdl struct scb {
    615  1.1     fvdl 	struct	hardware_scb	 *hscb;
    616  1.1     fvdl 	union {
    617  1.1     fvdl 		SLIST_ENTRY(scb)  sle;
    618  1.1     fvdl 		LIST_ENTRY(scb)	  le;
    619  1.1     fvdl 		TAILQ_ENTRY(scb)  tqe;
    620  1.1     fvdl 	} links;
    621  1.1     fvdl 	union {
    622  1.1     fvdl 		SLIST_ENTRY(scb)  sle;
    623  1.1     fvdl 		LIST_ENTRY(scb)	  le;
    624  1.1     fvdl 		TAILQ_ENTRY(scb)  tqe;
    625  1.1     fvdl 	} links2;
    626  1.1     fvdl #define pending_links links2.le
    627  1.1     fvdl #define collision_links links2.le
    628  1.1     fvdl 	struct scb		 *col_scb;
    629  1.1     fvdl 	struct scsipi_xfer	 *xs;
    630  1.1     fvdl 
    631  1.1     fvdl 	struct ahd_softc	 *ahd_softc;
    632  1.1     fvdl 	scb_flag		  flags;
    633  1.1     fvdl 	bus_dmamap_t		  dmamap;
    634  1.1     fvdl 	struct scb_platform_data *platform_data;
    635  1.1     fvdl 	struct map_node	 	 *hscb_map;
    636  1.1     fvdl 	struct map_node	 	 *sg_map;
    637  1.1     fvdl 	struct map_node	 	 *sense_map;
    638  1.1     fvdl 	void			 *sg_list;
    639  1.1     fvdl 	uint8_t			 *sense_data;
    640  1.1     fvdl 	bus_addr_t		  sg_list_busaddr;
    641  1.1     fvdl 	bus_addr_t		  sense_busaddr;
    642  1.1     fvdl 	u_int			  sg_count;/* How full ahd_dma_seg is */
    643  1.1     fvdl #define	AHD_MAX_LQ_CRC_ERRORS 5
    644  1.1     fvdl 	u_int			  crc_retry_count;
    645  1.1     fvdl };
    646  1.1     fvdl 
    647  1.1     fvdl TAILQ_HEAD(scb_tailq, scb);
    648  1.1     fvdl LIST_HEAD(scb_list, scb);
    649  1.1     fvdl 
    650  1.1     fvdl struct scb_data {
    651  1.1     fvdl 	/*
    652  1.1     fvdl 	 * TAILQ of lists of free SCBs grouped by device
    653  1.1     fvdl 	 * collision domains.
    654  1.1     fvdl 	 */
    655  1.1     fvdl 	struct scb_tailq free_scbs;
    656  1.1     fvdl 
    657  1.1     fvdl 	/*
    658  1.1     fvdl 	 * Per-device lists of SCBs whose tag ID would collide
    659  1.1     fvdl 	 * with an already active tag on the device.
    660  1.1     fvdl 	 */
    661  1.1     fvdl 	struct scb_list free_scb_lists[AHD_NUM_TARGETS * AHD_NUM_LUNS_NONPKT];
    662  1.1     fvdl 
    663  1.1     fvdl 	/*
    664  1.1     fvdl 	 * SCBs that will not collide with any active device.
    665  1.1     fvdl 	 */
    666  1.1     fvdl 	struct scb_list any_dev_free_scb_list;
    667  1.1     fvdl 
    668  1.1     fvdl 	/*
    669  1.1     fvdl 	 * Mapping from tag to SCB.
    670  1.1     fvdl 	 */
    671  1.1     fvdl 	struct	scb *scbindex[AHD_SCB_MAX];
    672  1.1     fvdl 
    673  1.1     fvdl 	SLIST_HEAD(, map_node) hscb_maps;
    674  1.1     fvdl 	SLIST_HEAD(, map_node) sg_maps;
    675  1.1     fvdl 	SLIST_HEAD(, map_node) sense_maps;
    676  1.1     fvdl 
    677  1.1     fvdl 	int		 scbs_left;	/* unallocated scbs in head map_node */
    678  1.1     fvdl 	int		 sgs_left;	/* unallocated sgs in head map_node */
    679  1.1     fvdl 	int		 sense_left;	/* unallocated sense in head map_node */
    680  1.1     fvdl 	uint16_t	 numscbs;
    681  1.1     fvdl 	uint16_t	 maxhscbs;	/* Number of SCBs on the card */
    682  1.1     fvdl 	uint8_t		 init_level;	/*
    683  1.1     fvdl 					 * How far we've initialized
    684  1.1     fvdl 					 * this structure.
    685  1.1     fvdl 					 */
    686  1.1     fvdl };
    687  1.1     fvdl 
    688  1.1     fvdl /************************ Target Mode Definitions *****************************/
    689  1.1     fvdl 
    690  1.1     fvdl /*
    691  1.1     fvdl  * Connection desciptor for select-in requests in target mode.
    692  1.1     fvdl  */
    693  1.1     fvdl struct target_cmd {
    694  1.1     fvdl 	uint8_t scsiid;		/* Our ID and the initiator's ID */
    695  1.1     fvdl 	uint8_t identify;	/* Identify message */
    696  1.1     fvdl 	uint8_t bytes[22];	/*
    697  1.1     fvdl 				 * Bytes contains any additional message
    698  1.1     fvdl 				 * bytes terminated by 0xFF.  The remainder
    699  1.1     fvdl 				 * is the cdb to execute.
    700  1.1     fvdl 				 */
    701  1.1     fvdl 	uint8_t cmd_valid;	/*
    702  1.1     fvdl 				 * When a command is complete, the firmware
    703  1.1     fvdl 				 * will set cmd_valid to all bits set.
    704  1.1     fvdl 				 * After the host has seen the command,
    705  1.1     fvdl 				 * the bits are cleared.  This allows us
    706  1.1     fvdl 				 * to just peek at host memory to determine
    707  1.1     fvdl 				 * if more work is complete. cmd_valid is on
    708  1.1     fvdl 				 * an 8 byte boundary to simplify setting
    709  1.1     fvdl 				 * it on aic7880 hardware which only has
    710  1.1     fvdl 				 * limited direct access to the DMA FIFO.
    711  1.1     fvdl 				 */
    712  1.1     fvdl 	uint8_t pad[7];
    713  1.1     fvdl };
    714  1.1     fvdl 
    715  1.1     fvdl /*
    716  1.1     fvdl  * Number of events we can buffer up if we run out
    717  1.1     fvdl  * of immediate notify ccbs.
    718  1.1     fvdl  */
    719  1.1     fvdl #define AHD_TMODE_EVENT_BUFFER_SIZE 8
    720  1.1     fvdl struct ahd_tmode_event {
    721  1.1     fvdl 	uint8_t initiator_id;
    722  1.1     fvdl 	uint8_t event_type;	/* MSG type or EVENT_TYPE_BUS_RESET */
    723  1.1     fvdl #define	EVENT_TYPE_BUS_RESET 0xFF
    724  1.1     fvdl 	uint8_t event_arg;
    725  1.1     fvdl };
    726  1.1     fvdl 
    727  1.1     fvdl /*
    728  1.1     fvdl  * Per enabled lun target mode state.
    729  1.1     fvdl  * As this state is directly influenced by the host OS'es target mode
    730  1.1     fvdl  * environment, we let the OS module define it.  Forward declare the
    731  1.1     fvdl  * structure here so we can store arrays of them, etc. in OS neutral
    732  1.1     fvdl  * data structures.
    733  1.1     fvdl  */
    734  1.1     fvdl #ifdef AHD_TARGET_MODE
    735  1.1     fvdl struct ahd_tmode_lstate {
    736  1.1     fvdl 	struct cam_path *path;
    737  1.1     fvdl 	struct ccb_hdr_slist accept_tios;
    738  1.1     fvdl 	struct ccb_hdr_slist immed_notifies;
    739  1.1     fvdl 	struct ahd_tmode_event event_buffer[AHD_TMODE_EVENT_BUFFER_SIZE];
    740  1.1     fvdl 	uint8_t event_r_idx;
    741  1.1     fvdl 	uint8_t event_w_idx;
    742  1.1     fvdl };
    743  1.1     fvdl #else
    744  1.1     fvdl struct ahd_tmode_lstate;
    745  1.1     fvdl #endif
    746  1.1     fvdl 
    747  1.1     fvdl /******************** Transfer Negotiation Datastructures *********************/
    748  1.1     fvdl #define AHD_TRANS_CUR		0x01	/* Modify current neogtiation status */
    749  1.1     fvdl #define AHD_TRANS_ACTIVE	0x03	/* Assume this target is on the bus */
    750  1.1     fvdl #define AHD_TRANS_GOAL		0x04	/* Modify negontiation goal */
    751  1.1     fvdl #define AHD_TRANS_USER		0x08	/* Modify user negotiation settings */
    752  1.1     fvdl #define AHD_PERIOD_10MHz	0x19
    753  1.1     fvdl 
    754  1.1     fvdl #define AHD_WIDTH_UNKNOWN	0xFF
    755  1.1     fvdl #define AHD_PERIOD_UNKNOWN	0xFF
    756  1.1     fvdl #define AHD_OFFSET_UNKNOWN	0xFF
    757  1.1     fvdl #define AHD_PPR_OPTS_UNKNOWN	0xFF
    758  1.1     fvdl 
    759  1.1     fvdl /*
    760  1.1     fvdl  * Transfer Negotiation Information.
    761  1.1     fvdl  */
    762  1.1     fvdl struct ahd_transinfo {
    763  1.1     fvdl 	uint8_t protocol_version;	/* SCSI Revision level */
    764  1.1     fvdl 	uint8_t transport_version;	/* SPI Revision level */
    765  1.1     fvdl 	uint8_t width;			/* Bus width */
    766  1.1     fvdl 	uint8_t period;			/* Sync rate factor */
    767  1.1     fvdl 	uint8_t offset;			/* Sync offset */
    768  1.1     fvdl 	uint8_t ppr_options;		/* Parallel Protocol Request options */
    769  1.1     fvdl };
    770  1.1     fvdl 
    771  1.1     fvdl /*
    772  1.1     fvdl  * Per-initiator current, goal and user transfer negotiation information. */
    773  1.1     fvdl struct ahd_initiator_tinfo {
    774  1.1     fvdl 	struct ahd_transinfo curr;
    775  1.1     fvdl 	struct ahd_transinfo goal;
    776  1.1     fvdl 	struct ahd_transinfo user;
    777  1.1     fvdl };
    778  1.1     fvdl 
    779  1.1     fvdl /*
    780  1.1     fvdl  * Per enabled target ID state.
    781  1.1     fvdl  * Pointers to lun target state as well as sync/wide negotiation information
    782  1.1     fvdl  * for each initiator<->target mapping.  For the initiator role we pretend
    783  1.1     fvdl  * that we are the target and the targets are the initiators since the
    784  1.1     fvdl  * negotiation is the same regardless of role.
    785  1.1     fvdl  */
    786  1.1     fvdl struct ahd_tmode_tstate {
    787  1.1     fvdl 	struct ahd_tmode_lstate*	enabled_luns[AHD_NUM_LUNS];
    788  1.1     fvdl 	struct ahd_initiator_tinfo	transinfo[AHD_NUM_TARGETS];
    789  1.1     fvdl 
    790  1.1     fvdl 	/*
    791  1.1     fvdl 	 * Per initiator state bitmasks.
    792  1.1     fvdl 	 */
    793  1.1     fvdl 	uint16_t	 auto_negotiate;/* Auto Negotiation Required */
    794  1.1     fvdl 	uint16_t	 discenable;	/* Disconnection allowed  */
    795  1.1     fvdl 	uint16_t	 tagenable;	/* Tagged Queuing allowed */
    796  1.1     fvdl };
    797  1.1     fvdl 
    798  1.1     fvdl /*
    799  1.1     fvdl  * Points of interest along the negotiated transfer scale.
    800  1.1     fvdl  */
    801  1.1     fvdl #define AHD_SYNCRATE_160	0x8
    802  1.1     fvdl #define AHD_SYNCRATE_PACED	0x8
    803  1.1     fvdl #define AHD_SYNCRATE_DT		0x9
    804  1.1     fvdl #define AHD_SYNCRATE_ULTRA2	0xa
    805  1.1     fvdl #define AHD_SYNCRATE_ULTRA	0xc
    806  1.1     fvdl #define AHD_SYNCRATE_FAST	0x19
    807  1.1     fvdl #define AHD_SYNCRATE_MIN_DT	AHD_SYNCRATE_FAST
    808  1.1     fvdl #define AHD_SYNCRATE_SYNC	0x32
    809  1.1     fvdl #define AHD_SYNCRATE_MIN	0x60
    810  1.1     fvdl #define	AHD_SYNCRATE_ASYNC	0xFF
    811  1.1     fvdl #define AHD_SYNCRATE_MAX	AHD_SYNCRATE_160
    812  1.1     fvdl 
    813  1.1     fvdl /* Safe and valid period for async negotiations. */
    814  1.1     fvdl #define	AHD_ASYNC_XFER_PERIOD	0x44
    815  1.1     fvdl 
    816  1.1     fvdl /*
    817  1.1     fvdl  * In RevA, the synctable uses a 120MHz rate for the period
    818  1.1     fvdl  * factor 8 and 160MHz for the period factor 7.  The 120MHz
    819  1.1     fvdl  * rate never made it into the official SCSI spec, so we must
    820  1.1     fvdl  * compensate when setting the negotiation table for Rev A
    821  1.1     fvdl  * parts.
    822  1.1     fvdl  */
    823  1.1     fvdl #define AHD_SYNCRATE_REVA_120	0x8
    824  1.1     fvdl #define AHD_SYNCRATE_REVA_160	0x7
    825  1.1     fvdl 
    826  1.1     fvdl /***************************** Lookup Tables **********************************/
    827  1.1     fvdl /*
    828  1.1     fvdl  * Phase -> name and message out response
    829  1.1     fvdl  * to parity errors in each phase table.
    830  1.1     fvdl  */
    831  1.1     fvdl struct ahd_phase_table_entry {
    832  1.1     fvdl         uint8_t phase;
    833  1.1     fvdl         uint8_t mesg_out; /* Message response to parity errors */
    834  1.1     fvdl 	char *phasemsg;
    835  1.1     fvdl };
    836  1.1     fvdl 
    837  1.1     fvdl /************************** Serial EEPROM Format ******************************/
    838  1.1     fvdl 
    839  1.1     fvdl struct seeprom_config {
    840  1.1     fvdl /*
    841  1.1     fvdl  * Per SCSI ID Configuration Flags
    842  1.1     fvdl  */
    843  1.1     fvdl 	uint16_t device_flags[16];	/* words 0-15 */
    844  1.1     fvdl #define		CFXFER		0x003F	/* synchronous transfer rate */
    845  1.1     fvdl #define			CFXFER_ASYNC	0x3F
    846  1.1     fvdl #define		CFQAS		0x0040	/* Negotiate QAS */
    847  1.1     fvdl #define		CFPACKETIZED	0x0080	/* Negotiate Packetized Transfers */
    848  1.1     fvdl #define		CFSTART		0x0100	/* send start unit SCSI command */
    849  1.1     fvdl #define		CFINCBIOS	0x0200	/* include in BIOS scan */
    850  1.1     fvdl #define		CFDISC		0x0400	/* enable disconnection */
    851  1.1     fvdl #define		CFMULTILUNDEV	0x0800	/* Probe multiple luns in BIOS scan */
    852  1.1     fvdl #define		CFWIDEB		0x1000	/* wide bus device */
    853  1.1     fvdl #define		CFHOSTMANAGED	0x8000	/* Managed by a RAID controller */
    854  1.1     fvdl 
    855  1.1     fvdl /*
    856  1.1     fvdl  * BIOS Control Bits
    857  1.1     fvdl  */
    858  1.1     fvdl 	uint16_t bios_control;		/* word 16 */
    859  1.1     fvdl #define		CFSUPREM	0x0001	/* support all removeable drives */
    860  1.1     fvdl #define		CFSUPREMB	0x0002	/* support removeable boot drives */
    861  1.1     fvdl #define		CFBIOSSTATE	0x000C	/* BIOS Action State */
    862  1.1     fvdl #define		    CFBS_DISABLED	0x00
    863  1.1     fvdl #define		    CFBS_ENABLED	0x04
    864  1.1     fvdl #define		    CFBS_DISABLED_SCAN	0x08
    865  1.1     fvdl #define		CFENABLEDV	0x0010	/* Perform Domain Validation */
    866  1.1     fvdl #define		CFCTRL_A	0x0020	/* BIOS displays Ctrl-A message */
    867  1.1     fvdl #define		CFSPARITY	0x0040	/* SCSI parity */
    868  1.1     fvdl #define		CFEXTEND	0x0080	/* extended translation enabled */
    869  1.1     fvdl #define		CFBOOTCD	0x0100  /* Support Bootable CD-ROM */
    870  1.1     fvdl #define		CFMSG_LEVEL	0x0600	/* BIOS Message Level */
    871  1.1     fvdl #define			CFMSG_VERBOSE	0x0000
    872  1.1     fvdl #define			CFMSG_SILENT	0x0200
    873  1.1     fvdl #define			CFMSG_DIAG	0x0400
    874  1.1     fvdl #define		CFRESETB	0x0800	/* reset SCSI bus at boot */
    875  1.1     fvdl /*		UNUSED		0xf000	*/
    876  1.1     fvdl 
    877  1.1     fvdl /*
    878  1.1     fvdl  * Host Adapter Control Bits
    879  1.1     fvdl  */
    880  1.1     fvdl 	uint16_t adapter_control;	/* word 17 */
    881  1.1     fvdl #define		CFAUTOTERM	0x0001	/* Perform Auto termination */
    882  1.1     fvdl #define		CFSTERM		0x0002	/* SCSI low byte termination */
    883  1.1     fvdl #define		CFWSTERM	0x0004	/* SCSI high byte termination */
    884  1.1     fvdl #define		CFSEAUTOTERM	0x0008	/* Ultra2 Perform secondary Auto Term*/
    885  1.1     fvdl #define		CFSELOWTERM	0x0010	/* Ultra2 secondary low term */
    886  1.1     fvdl #define		CFSEHIGHTERM	0x0020	/* Ultra2 secondary high term */
    887  1.1     fvdl #define		CFSTPWLEVEL	0x0040	/* Termination level control */
    888  1.1     fvdl #define		CFBIOSAUTOTERM	0x0080	/* Perform Auto termination */
    889  1.1     fvdl #define		CFTERM_MENU	0x0100	/* BIOS displays termination menu */
    890  1.1     fvdl #define		CFCLUSTERENB	0x8000	/* Cluster Enable */
    891  1.1     fvdl 
    892  1.1     fvdl /*
    893  1.1     fvdl  * Bus Release Time, Host Adapter ID
    894  1.1     fvdl  */
    895  1.1     fvdl 	uint16_t brtime_id;		/* word 18 */
    896  1.1     fvdl #define		CFSCSIID	0x000f	/* host adapter SCSI ID */
    897  1.1     fvdl /*		UNUSED		0x00f0	*/
    898  1.1     fvdl #define		CFBRTIME	0xff00	/* bus release time/PCI Latency Time */
    899  1.1     fvdl 
    900  1.1     fvdl /*
    901  1.1     fvdl  * Maximum targets
    902  1.1     fvdl  */
    903  1.1     fvdl 	uint16_t max_targets;		/* word 19 */
    904  1.1     fvdl #define		CFMAXTARG	0x00ff	/* maximum targets */
    905  1.1     fvdl #define		CFBOOTLUN	0x0f00	/* Lun to boot from */
    906  1.1     fvdl #define		CFBOOTID	0xf000	/* Target to boot from */
    907  1.1     fvdl 	uint16_t res_1[10];		/* words 20-29 */
    908  1.1     fvdl 	uint16_t signature;		/* BIOS Signature */
    909  1.1     fvdl #define		CFSIGNATURE	0x400
    910  1.1     fvdl 	uint16_t checksum;		/* word 31 */
    911  1.1     fvdl };
    912  1.1     fvdl 
    913  1.7  thorpej /*
    914  1.7  thorpej  * Vital Product Data used during POST and by the BIOS.
    915  1.7  thorpej  */
    916  1.7  thorpej struct vpd_config {
    917  1.7  thorpej 	uint8_t  bios_flags;
    918  1.7  thorpej #define		VPDMASTERBIOS	0x0001
    919  1.7  thorpej #define		VPDBOOTHOST	0x0002
    920  1.7  thorpej 	uint8_t  reserved_1[21];
    921  1.7  thorpej 	uint8_t  resource_type;
    922  1.7  thorpej 	uint8_t  resource_len[2];
    923  1.7  thorpej 	uint8_t  resource_data[8];
    924  1.7  thorpej 	uint8_t  vpd_tag;
    925  1.7  thorpej 	uint16_t vpd_len;
    926  1.7  thorpej 	uint8_t  vpd_keyword[2];
    927  1.7  thorpej 	uint8_t  length;
    928  1.7  thorpej 	uint8_t  revision;
    929  1.7  thorpej 	uint8_t  device_flags;
    930  1.7  thorpej 	uint8_t  termnation_menus[2];
    931  1.7  thorpej 	uint8_t  fifo_threshold;
    932  1.7  thorpej 	uint8_t  end_tag;
    933  1.7  thorpej 	uint8_t  vpd_checksum;
    934  1.7  thorpej 	uint16_t default_target_flags;
    935  1.7  thorpej 	uint16_t default_bios_flags;
    936  1.7  thorpej 	uint16_t default_ctrl_flags;
    937  1.7  thorpej 	uint8_t  default_irq;
    938  1.7  thorpej 	uint8_t  pci_lattime;
    939  1.7  thorpej 	uint8_t  max_target;
    940  1.7  thorpej 	uint8_t  boot_lun;
    941  1.7  thorpej 	uint16_t signature;
    942  1.7  thorpej 	uint8_t  reserved_2;
    943  1.7  thorpej 	uint8_t  checksum;
    944  1.7  thorpej 	uint8_t  reserved_3[4];
    945  1.7  thorpej };
    946  1.7  thorpej 
    947  1.1     fvdl /****************************** Flexport Logic ********************************/
    948  1.1     fvdl #define FLXADDR_TERMCTL			0x0
    949  1.1     fvdl #define		FLX_TERMCTL_ENSECHIGH	0x8
    950  1.1     fvdl #define		FLX_TERMCTL_ENSECLOW	0x4
    951  1.1     fvdl #define		FLX_TERMCTL_ENPRIHIGH	0x2
    952  1.1     fvdl #define		FLX_TERMCTL_ENPRILOW	0x1
    953  1.1     fvdl #define FLXADDR_ROMSTAT_CURSENSECTL	0x1
    954  1.1     fvdl #define		FLX_ROMSTAT_SEECFG	0xF0
    955  1.1     fvdl #define		FLX_ROMSTAT_EECFG	0x0F
    956  1.1     fvdl #define		FLX_ROMSTAT_SEE_93C66	0x00
    957  1.1     fvdl #define		FLX_ROMSTAT_SEE_NONE	0xF0
    958  1.1     fvdl #define		FLX_ROMSTAT_EE_512x8	0x0
    959  1.1     fvdl #define		FLX_ROMSTAT_EE_1MBx8	0x1
    960  1.1     fvdl #define		FLX_ROMSTAT_EE_2MBx8	0x2
    961  1.1     fvdl #define		FLX_ROMSTAT_EE_4MBx8	0x3
    962  1.1     fvdl #define		FLX_ROMSTAT_EE_16MBx8	0x4
    963  1.1     fvdl #define 		CURSENSE_ENB	0x1
    964  1.1     fvdl #define	FLXADDR_FLEXSTAT		0x2
    965  1.1     fvdl #define		FLX_FSTAT_BUSY		0x1
    966  1.1     fvdl #define FLXADDR_CURRENT_STAT		0x4
    967  1.1     fvdl #define		FLX_CSTAT_SEC_HIGH	0xC0
    968  1.1     fvdl #define		FLX_CSTAT_SEC_LOW	0x30
    969  1.1     fvdl #define		FLX_CSTAT_PRI_HIGH	0x0C
    970  1.1     fvdl #define		FLX_CSTAT_PRI_LOW	0x03
    971  1.1     fvdl #define		FLX_CSTAT_MASK		0x03
    972  1.1     fvdl #define		FLX_CSTAT_SHIFT		2
    973  1.1     fvdl #define		FLX_CSTAT_OKAY		0x0
    974  1.1     fvdl #define		FLX_CSTAT_OVER		0x1
    975  1.1     fvdl #define		FLX_CSTAT_UNDER		0x2
    976  1.1     fvdl #define		FLX_CSTAT_INVALID	0x3
    977  1.1     fvdl 
    978  1.7  thorpej int		ahd_read_seeprom(struct ahd_softc *, uint16_t *, u_int, u_int,
    979  1.7  thorpej 				 int);
    980  1.1     fvdl 
    981  1.5   itojun int		ahd_write_seeprom(struct ahd_softc *, uint16_t *, u_int, u_int);
    982  1.5   itojun int		ahd_wait_seeprom(struct ahd_softc *);
    983  1.7  thorpej int		ahd_verify_vpd_cksum(struct vpd_config *);
    984  1.5   itojun int		ahd_verify_cksum(struct seeprom_config *);
    985  1.5   itojun int		ahd_acquire_seeprom(struct ahd_softc *);
    986  1.5   itojun void		ahd_release_seeprom(struct ahd_softc *);
    987  1.1     fvdl 
    988  1.1     fvdl /****************************  Message Buffer *********************************/
    989  1.1     fvdl typedef enum {
    990  1.1     fvdl 	MSG_FLAG_NONE			= 0x00,
    991  1.1     fvdl 	MSG_FLAG_EXPECT_PPR_BUSFREE	= 0x01,
    992  1.1     fvdl 	MSG_FLAG_IU_REQ_CHANGED		= 0x02,
    993  1.1     fvdl 	MSG_FLAG_EXPECT_IDE_BUSFREE	= 0x04,
    994  1.1     fvdl 	MSG_FLAG_EXPECT_QASREJ_BUSFREE	= 0x08,
    995  1.1     fvdl 	MSG_FLAG_PACKETIZED		= 0x10
    996  1.1     fvdl } ahd_msg_flags;
    997  1.1     fvdl 
    998  1.1     fvdl typedef enum {
    999  1.1     fvdl 	MSG_TYPE_NONE			= 0x00,
   1000  1.1     fvdl 	MSG_TYPE_INITIATOR_MSGOUT	= 0x01,
   1001  1.1     fvdl 	MSG_TYPE_INITIATOR_MSGIN	= 0x02,
   1002  1.1     fvdl 	MSG_TYPE_TARGET_MSGOUT		= 0x03,
   1003  1.1     fvdl 	MSG_TYPE_TARGET_MSGIN		= 0x04
   1004  1.1     fvdl } ahd_msg_type;
   1005  1.1     fvdl 
   1006  1.1     fvdl typedef enum {
   1007  1.1     fvdl 	MSGLOOP_IN_PROG,
   1008  1.1     fvdl 	MSGLOOP_MSGCOMPLETE,
   1009  1.1     fvdl 	MSGLOOP_TERMINATED
   1010  1.1     fvdl } msg_loop_stat;
   1011  1.1     fvdl 
   1012  1.1     fvdl /*********************** Software Configuration Structure *********************/
   1013  1.1     fvdl struct ahd_suspend_channel_state {
   1014  1.1     fvdl 	uint8_t	scsiseq;
   1015  1.1     fvdl 	uint8_t	sxfrctl0;
   1016  1.1     fvdl 	uint8_t	sxfrctl1;
   1017  1.1     fvdl 	uint8_t	simode0;
   1018  1.1     fvdl 	uint8_t	simode1;
   1019  1.1     fvdl 	uint8_t	seltimer;
   1020  1.1     fvdl 	uint8_t	seqctl;
   1021  1.1     fvdl };
   1022  1.1     fvdl 
   1023  1.1     fvdl struct ahd_suspend_state {
   1024  1.1     fvdl 	struct	ahd_suspend_channel_state channel[2];
   1025  1.1     fvdl 	uint8_t	optionmode;
   1026  1.1     fvdl 	uint8_t	dscommand0;
   1027  1.1     fvdl 	uint8_t	dspcistatus;
   1028  1.1     fvdl 	/* hsmailbox */
   1029  1.1     fvdl 	uint8_t	crccontrol1;
   1030  1.1     fvdl 	uint8_t	scbbaddr;
   1031  1.1     fvdl 	/* Host and sequencer SCB counts */
   1032  1.1     fvdl 	uint8_t	dff_thrsh;
   1033  1.1     fvdl 	uint8_t	*scratch_ram;
   1034  1.1     fvdl 	uint8_t	*btt;
   1035  1.1     fvdl };
   1036  1.1     fvdl 
   1037  1.1     fvdl typedef int (*ahd_bus_intr_t)(struct ahd_softc *);
   1038  1.1     fvdl 
   1039  1.1     fvdl typedef enum {
   1040  1.1     fvdl 	AHD_MODE_DFF0,
   1041  1.1     fvdl 	AHD_MODE_DFF1,
   1042  1.1     fvdl 	AHD_MODE_CCHAN,
   1043  1.1     fvdl 	AHD_MODE_SCSI,
   1044  1.1     fvdl 	AHD_MODE_CFG,
   1045  1.1     fvdl 	AHD_MODE_UNKNOWN
   1046  1.1     fvdl } ahd_mode;
   1047  1.1     fvdl 
   1048  1.1     fvdl #define AHD_MK_MSK(x) (0x01 << (x))
   1049  1.1     fvdl #define AHD_MODE_DFF0_MSK	AHD_MK_MSK(AHD_MODE_DFF0)
   1050  1.1     fvdl #define AHD_MODE_DFF1_MSK	AHD_MK_MSK(AHD_MODE_DFF1)
   1051  1.1     fvdl #define AHD_MODE_CCHAN_MSK	AHD_MK_MSK(AHD_MODE_CCHAN)
   1052  1.1     fvdl #define AHD_MODE_SCSI_MSK	AHD_MK_MSK(AHD_MODE_SCSI)
   1053  1.1     fvdl #define AHD_MODE_CFG_MSK	AHD_MK_MSK(AHD_MODE_CFG)
   1054  1.1     fvdl #define AHD_MODE_UNKNOWN_MSK	AHD_MK_MSK(AHD_MODE_UNKNOWN)
   1055  1.1     fvdl #define AHD_MODE_ANY_MSK (~0)
   1056  1.1     fvdl 
   1057  1.1     fvdl typedef uint8_t ahd_mode_state;
   1058  1.1     fvdl 
   1059  1.1     fvdl typedef void ahd_callback_t (void *);
   1060  1.1     fvdl 
   1061  1.1     fvdl struct ahd_softc {
   1062  1.1     fvdl 	struct device 		  sc_dev;
   1063  1.1     fvdl 
   1064  1.1     fvdl 	struct scsipi_channel	  sc_channel;
   1065  1.1     fvdl 	struct device *		  sc_child;
   1066  1.1     fvdl 	struct scsipi_adapter	  sc_adapter;
   1067  1.1     fvdl 
   1068  1.1     fvdl 	bus_space_tag_t           tags[2];
   1069  1.1     fvdl 	bus_space_handle_t        bshs[2];
   1070  1.1     fvdl 
   1071  1.1     fvdl 	scsipi_adapter_req_t	  sc_req;
   1072  1.1     fvdl 
   1073  1.1     fvdl 	void 			 *shutdown_hook;
   1074  1.1     fvdl 	struct scb_data		  scb_data;
   1075  1.1     fvdl 
   1076  1.1     fvdl 	struct hardware_scb	 *next_queued_hscb;
   1077  1.6  thorpej 	struct map_node		 *next_queued_hscb_map;
   1078  1.1     fvdl 
   1079  1.1     fvdl 	/*
   1080  1.1     fvdl 	 * SCBs that have been sent to the controller
   1081  1.1     fvdl 	 */
   1082  1.1     fvdl 	LIST_HEAD(, scb)	  pending_scbs;
   1083  1.1     fvdl 
   1084  1.1     fvdl 	/*
   1085  1.1     fvdl 	 * Current register window mode information.
   1086  1.1     fvdl 	 */
   1087  1.1     fvdl 	ahd_mode		  dst_mode;
   1088  1.1     fvdl 	ahd_mode		  src_mode;
   1089  1.1     fvdl 
   1090  1.1     fvdl 	/*
   1091  1.1     fvdl 	 * Saved register window mode information
   1092  1.1     fvdl 	 * used for restore on next unpause.
   1093  1.1     fvdl 	 */
   1094  1.1     fvdl 	ahd_mode		  saved_dst_mode;
   1095  1.1     fvdl 	ahd_mode		  saved_src_mode;
   1096  1.1     fvdl 
   1097  1.1     fvdl 	/*
   1098  1.1     fvdl 	 * Platform specific data.
   1099  1.1     fvdl 	 */
   1100  1.1     fvdl 	struct ahd_platform_data *platform_data;
   1101  1.1     fvdl 
   1102  1.1     fvdl 	/*
   1103  1.1     fvdl 	 * Bus specific device information.
   1104  1.1     fvdl 	 */
   1105  1.1     fvdl 	ahd_bus_intr_t		  bus_intr;
   1106  1.1     fvdl 
   1107  1.1     fvdl 	/*
   1108  1.1     fvdl 	 * Target mode related state kept on a per enabled lun basis.
   1109  1.1     fvdl 	 * Targets that are not enabled will have null entries.
   1110  1.1     fvdl 	 * As an initiator, we keep one target entry for our initiator
   1111  1.1     fvdl 	 * ID to store our sync/wide transfer settings.
   1112  1.1     fvdl 	 */
   1113  1.1     fvdl 	struct ahd_tmode_tstate  *enabled_targets[AHD_NUM_TARGETS];
   1114  1.1     fvdl 
   1115  1.1     fvdl 	char			  inited_target[AHD_NUM_TARGETS];
   1116  1.1     fvdl 
   1117  1.1     fvdl 	/*
   1118  1.1     fvdl 	 * The black hole device responsible for handling requests for
   1119  1.1     fvdl 	 * disabled luns on enabled targets.
   1120  1.1     fvdl 	 */
   1121  1.1     fvdl 	struct ahd_tmode_lstate  *black_hole;
   1122  1.1     fvdl 
   1123  1.1     fvdl 	/*
   1124  1.1     fvdl 	 * Device instance currently on the bus awaiting a continue TIO
   1125  1.1     fvdl 	 * for a command that was not given the disconnect priveledge.
   1126  1.1     fvdl 	 */
   1127  1.1     fvdl 	struct ahd_tmode_lstate  *pending_device;
   1128  1.1     fvdl 
   1129  1.1     fvdl 	/*
   1130  1.1     fvdl 	 * Timer handles for timer driven callbacks.
   1131  1.1     fvdl 	 */
   1132  1.1     fvdl 	ahd_timer_t		  reset_timer;
   1133  1.1     fvdl 	ahd_timer_t		  stat_timer;
   1134  1.1     fvdl 
   1135  1.1     fvdl 	/*
   1136  1.1     fvdl 	 * Statistics.
   1137  1.1     fvdl 	 */
   1138  1.1     fvdl #define	AHD_STAT_UPDATE_US	250000 /* 250ms */
   1139  1.1     fvdl #define	AHD_STAT_BUCKETS	4
   1140  1.1     fvdl 	u_int			  cmdcmplt_bucket;
   1141  1.1     fvdl 	uint32_t		  cmdcmplt_counts[AHD_STAT_BUCKETS];
   1142  1.1     fvdl 	uint32_t		  cmdcmplt_total;
   1143  1.1     fvdl 
   1144  1.1     fvdl 	/*
   1145  1.1     fvdl 	 * Card characteristics
   1146  1.1     fvdl 	 */
   1147  1.1     fvdl 	ahd_chip		  chip;
   1148  1.1     fvdl 	ahd_feature		  features;
   1149  1.1     fvdl 	ahd_bug			  bugs;
   1150  1.1     fvdl 	ahd_flag		  flags;
   1151  1.1     fvdl 	struct seeprom_config	 *seep_config;
   1152  1.1     fvdl 
   1153  1.1     fvdl 	/* Values to store in the SEQCTL register for pause and unpause */
   1154  1.1     fvdl 	uint8_t			  unpause;
   1155  1.1     fvdl 	uint8_t			  pause;
   1156  1.1     fvdl 
   1157  1.1     fvdl 	/* Command Queues */
   1158  1.1     fvdl 	uint16_t		  qoutfifonext;
   1159  1.1     fvdl 	uint16_t		  qoutfifonext_valid_tag;
   1160  1.1     fvdl 	uint16_t		  qinfifonext;
   1161  1.1     fvdl 	uint16_t		  qinfifo[AHD_SCB_MAX];
   1162  1.1     fvdl 	uint16_t		 *qoutfifo;
   1163  1.1     fvdl 
   1164  1.1     fvdl 	/* Critical Section Data */
   1165  1.1     fvdl 	struct cs		 *critical_sections;
   1166  1.1     fvdl 	u_int			  num_critical_sections;
   1167  1.1     fvdl 
   1168  1.1     fvdl 	/* Buffer for handling packetized bitbucket. */
   1169  1.1     fvdl 	uint8_t			 *overrun_buf;
   1170  1.1     fvdl 
   1171  1.1     fvdl 	/* Links for chaining softcs */
   1172  1.1     fvdl 	TAILQ_ENTRY(ahd_softc)	  links;
   1173  1.1     fvdl 
   1174  1.1     fvdl 	/* Channel Names ('A', 'B', etc.) */
   1175  1.1     fvdl 	char			  channel;
   1176  1.1     fvdl 
   1177  1.1     fvdl 	/* Initiator Bus ID */
   1178  1.1     fvdl 	uint8_t			  our_id;
   1179  1.1     fvdl 
   1180  1.1     fvdl 	/*
   1181  1.1     fvdl 	 * Target incoming command FIFO.
   1182  1.1     fvdl 	 */
   1183  1.1     fvdl 	struct target_cmd	 *targetcmds;
   1184  1.1     fvdl 	uint8_t			  tqinfifonext;
   1185  1.1     fvdl 
   1186  1.1     fvdl 	/*
   1187  1.1     fvdl 	 * Cached verson of the hs_mailbox so we can avoid
   1188  1.1     fvdl 	 * pausing the sequencer during mailbox updates.
   1189  1.1     fvdl 	 */
   1190  1.1     fvdl 	uint8_t			  hs_mailbox;
   1191  1.1     fvdl 
   1192  1.1     fvdl 	/*
   1193  1.1     fvdl 	 * Incoming and outgoing message handling.
   1194  1.1     fvdl 	 */
   1195  1.1     fvdl 	uint8_t			  send_msg_perror;
   1196  1.1     fvdl 	ahd_msg_flags		  msg_flags;
   1197  1.1     fvdl 	ahd_msg_type		  msg_type;
   1198  1.1     fvdl 	uint8_t			  msgout_buf[12];/* Message we are sending */
   1199  1.1     fvdl 	uint8_t			  msgin_buf[12];/* Message we are receiving */
   1200  1.1     fvdl 	u_int			  msgout_len;	/* Length of message to send */
   1201  1.1     fvdl 	u_int			  msgout_index;	/* Current index in msgout */
   1202  1.1     fvdl 	u_int			  msgin_index;	/* Current index in msgin */
   1203  1.1     fvdl 
   1204  1.1     fvdl 	/*
   1205  1.1     fvdl 	 * Mapping information for data structures shared
   1206  1.1     fvdl 	 * between the sequencer and kernel.
   1207  1.1     fvdl 	 */
   1208  1.1     fvdl 	bus_dma_tag_t		  parent_dmat;
   1209  1.1     fvdl 	bus_dma_tag_t		  shared_data_dmat;
   1210  1.6  thorpej 	struct map_node		  shared_data_map;
   1211  1.1     fvdl 	int			  shared_data_size;
   1212  1.1     fvdl 	int			  sc_dmaflags;
   1213  1.1     fvdl 
   1214  1.1     fvdl 	/* Information saved through suspend/resume cycles */
   1215  1.1     fvdl 	struct ahd_suspend_state  suspend_state;
   1216  1.1     fvdl 
   1217  1.1     fvdl 	/* Number of enabled target mode device on this card */
   1218  1.1     fvdl 	u_int			  enabled_luns;
   1219  1.1     fvdl 
   1220  1.1     fvdl 	/* Initialization level of this data structure */
   1221  1.1     fvdl 	u_int			  init_level;
   1222  1.1     fvdl 
   1223  1.1     fvdl 	/* PCI cacheline size. */
   1224  1.1     fvdl 	u_int			  pci_cachesize;
   1225  1.1     fvdl 
   1226  1.1     fvdl 	/* IO Cell Parameters */
   1227  1.1     fvdl 	uint8_t			  iocell_opts[AHD_NUM_PER_DEV_ANNEXCOLS];
   1228  1.1     fvdl 
   1229  1.1     fvdl 	u_int			  stack_size;
   1230  1.1     fvdl 	uint16_t		 *saved_stack;
   1231  1.1     fvdl 
   1232  1.1     fvdl 	/* Per-Unit descriptive information */
   1233  1.1     fvdl 	const char		 *description;
   1234  1.1     fvdl 	const char		 *bus_description;
   1235  1.1     fvdl 	char			 *name;
   1236  1.1     fvdl 	int			  unit;
   1237  1.1     fvdl 
   1238  1.1     fvdl 	/* Selection Timer settings */
   1239  1.1     fvdl 	int			  seltime;
   1240  1.1     fvdl 
   1241  1.1     fvdl 	/*
   1242  1.4      wiz 	 * Interrupt coalescing settings.
   1243  1.1     fvdl 	 */
   1244  1.4      wiz #define	AHD_INT_COALESCING_TIMER_DEFAULT		250 /*us*/
   1245  1.4      wiz #define	AHD_INT_COALESCING_MAXCMDS_DEFAULT		10
   1246  1.4      wiz #define	AHD_INT_COALESCING_MAXCMDS_MAX			127
   1247  1.4      wiz #define	AHD_INT_COALESCING_MINCMDS_DEFAULT		5
   1248  1.4      wiz #define	AHD_INT_COALESCING_MINCMDS_MAX			127
   1249  1.4      wiz #define	AHD_INT_COALESCING_THRESHOLD_DEFAULT		2000
   1250  1.4      wiz #define	AHD_INT_COALESCING_STOP_THRESHOLD_DEFAULT	1000
   1251  1.4      wiz 	u_int			  int_coalescing_timer;
   1252  1.4      wiz 	u_int			  int_coalescing_maxcmds;
   1253  1.4      wiz 	u_int			  int_coalescing_mincmds;
   1254  1.4      wiz 	u_int			  int_coalescing_threshold;
   1255  1.4      wiz 	u_int			  int_coalescing_stop_threshold;
   1256  1.1     fvdl 
   1257  1.1     fvdl 	uint16_t	 	  user_discenable;/* Disconnection allowed  */
   1258  1.1     fvdl 	uint16_t		  user_tagenable;/* Tagged Queuing allowed */
   1259  1.1     fvdl 
   1260  1.1     fvdl         /* Adapter interrupt routine */
   1261  1.1     fvdl 	void*                     ih;
   1262  1.1     fvdl 	struct ahd_pci_busdata	  *bus_data;
   1263  1.1     fvdl };
   1264  1.1     fvdl 
   1265  1.1     fvdl TAILQ_HEAD(ahd_softc_tailq, ahd_softc);
   1266  1.1     fvdl extern struct ahd_softc_tailq ahd_tailq;
   1267  1.1     fvdl 
   1268  1.1     fvdl /*************************** IO Cell Configuration ****************************/
   1269  1.1     fvdl #define	AHD_PRECOMP_SLEW_INDEX						\
   1270  1.1     fvdl     (AHD_ANNEXCOL_PRECOMP_SLEW - AHD_ANNEXCOL_PER_DEV0)
   1271  1.1     fvdl 
   1272  1.1     fvdl #define	AHD_AMPLITUDE_INDEX						\
   1273  1.1     fvdl     (AHD_ANNEXCOL_AMPLITUDE - AHD_ANNEXCOL_PER_DEV0)
   1274  1.1     fvdl 
   1275  1.1     fvdl #define AHD_SET_SLEWRATE(ahd, new_slew)					\
   1276  1.1     fvdl do {									\
   1277  1.1     fvdl     (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_SLEWRATE_MASK;	\
   1278  1.1     fvdl     (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] |=			\
   1279  1.1     fvdl 	(((new_slew) << AHD_SLEWRATE_SHIFT) & AHD_SLEWRATE_MASK);	\
   1280  1.1     fvdl } while (0)
   1281  1.1     fvdl 
   1282  1.1     fvdl #define AHD_SET_PRECOMP(ahd, new_pcomp)					\
   1283  1.1     fvdl do {									\
   1284  1.1     fvdl     (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_PRECOMP_MASK;	\
   1285  1.1     fvdl     (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] |=			\
   1286  1.1     fvdl 	(((new_pcomp) << AHD_PRECOMP_SHIFT) & AHD_PRECOMP_MASK);	\
   1287  1.1     fvdl } while (0)
   1288  1.1     fvdl 
   1289  1.1     fvdl #define AHD_SET_AMPLITUDE(ahd, new_amp)					\
   1290  1.1     fvdl do {									\
   1291  1.1     fvdl     (ahd)->iocell_opts[AHD_AMPLITUDE_INDEX] &= ~AHD_AMPLITUDE_MASK;	\
   1292  1.1     fvdl     (ahd)->iocell_opts[AHD_AMPLITUDE_INDEX] |=				\
   1293  1.1     fvdl 	(((new_amp) << AHD_AMPLITUDE_SHIFT) & AHD_AMPLITUDE_MASK);	\
   1294  1.1     fvdl } while (0)
   1295  1.1     fvdl 
   1296  1.1     fvdl /************************ Active Device Information ***************************/
   1297  1.1     fvdl typedef enum {
   1298  1.1     fvdl 	ROLE_UNKNOWN,
   1299  1.1     fvdl 	ROLE_INITIATOR,
   1300  1.1     fvdl 	ROLE_TARGET
   1301  1.1     fvdl } role_t;
   1302  1.1     fvdl 
   1303  1.1     fvdl struct ahd_devinfo {
   1304  1.1     fvdl 	int	 our_scsiid;
   1305  1.1     fvdl 	int	 target_offset;
   1306  1.1     fvdl 	uint16_t target_mask;
   1307  1.1     fvdl 	u_int	 target;
   1308  1.1     fvdl 	u_int	 lun;
   1309  1.1     fvdl 	char	 channel;
   1310  1.1     fvdl 	role_t	 role;		/*
   1311  1.1     fvdl 				 * Only guaranteed to be correct if not
   1312  1.1     fvdl 				 * in the busfree state.
   1313  1.1     fvdl 				 */
   1314  1.1     fvdl };
   1315  1.1     fvdl 
   1316  1.1     fvdl /****************************** PCI Structures ********************************/
   1317  1.1     fvdl #define AHD_PCI_IOADDR0	PCI_MAPREG_START	/* I/O BAR*/
   1318  1.1     fvdl #define AHD_PCI_MEMADDR	(PCI_MAPREG_START + 4)	/* Memory BAR */
   1319  1.1     fvdl #define AHD_PCI_IOADDR1	(PCI_MAPREG_START + 12)/* Second I/O BAR */
   1320  1.1     fvdl 
   1321  1.1     fvdl typedef int (ahd_device_setup_t)(struct ahd_softc *, struct pci_attach_args *);
   1322  1.1     fvdl 
   1323  1.1     fvdl struct ahd_pci_identity {
   1324  1.1     fvdl 	uint64_t		 full_id;
   1325  1.1     fvdl 	uint64_t		 id_mask;
   1326  1.1     fvdl 	char			*name;
   1327  1.1     fvdl 	ahd_device_setup_t	*setup;
   1328  1.1     fvdl };
   1329  1.1     fvdl extern struct ahd_pci_identity ahd_pci_ident_table [];
   1330  1.1     fvdl extern const u_int ahd_num_pci_devs;
   1331  1.1     fvdl 
   1332  1.1     fvdl /***************************** VL/EISA Declarations ***************************/
   1333  1.1     fvdl struct aic7770_identity {
   1334  1.1     fvdl 	uint32_t		 full_id;
   1335  1.1     fvdl 	uint32_t		 id_mask;
   1336  1.1     fvdl 	char			*name;
   1337  1.1     fvdl 	ahd_device_setup_t	*setup;
   1338  1.1     fvdl };
   1339  1.1     fvdl extern struct aic7770_identity aic7770_ident_table [];
   1340  1.1     fvdl extern const int ahd_num_aic7770_devs;
   1341  1.1     fvdl 
   1342  1.1     fvdl #define AHD_EISA_SLOT_OFFSET	0xc00
   1343  1.1     fvdl #define AHD_EISA_IOSIZE		0x100
   1344  1.1     fvdl 
   1345  1.1     fvdl /*************************** Function Declarations ****************************/
   1346  1.1     fvdl /******************************************************************************/
   1347  1.5   itojun void			ahd_reset_cmds_pending(struct ahd_softc *);
   1348  1.5   itojun u_int			ahd_find_busy_tcl(struct ahd_softc *, u_int);
   1349  1.5   itojun void			ahd_busy_tcl(struct ahd_softc *, u_int, u_int);
   1350  1.5   itojun static __inline void	ahd_unbusy_tcl(struct ahd_softc *, u_int);
   1351  1.1     fvdl static __inline void
   1352  1.1     fvdl ahd_unbusy_tcl(struct ahd_softc *ahd, u_int tcl)
   1353  1.1     fvdl {
   1354  1.1     fvdl 	ahd_busy_tcl(ahd, tcl, SCB_LIST_NULL);
   1355  1.1     fvdl }
   1356  1.1     fvdl 
   1357  1.1     fvdl /***************************** PCI Front End *********************************/
   1358  1.5   itojun const struct ahd_pci_identity *ahd_find_pci_device(pcireg_t, pcireg_t); /*ahd_dev_softc_t);*/
   1359  1.1     fvdl int			ahd_pci_config(struct ahd_softc *,
   1360  1.1     fvdl 				       struct ahd_pci_identity *);
   1361  1.1     fvdl int			ahd_pci_test_register_access(struct ahd_softc *);
   1362  1.1     fvdl 
   1363  1.1     fvdl /************************** SCB and SCB queue management **********************/
   1364  1.1     fvdl int			ahd_probe_scbs(struct ahd_softc *);
   1365  1.5   itojun void			ahd_qinfifo_requeue_tail(struct ahd_softc *,
   1366  1.5   itojun 			    struct scb *);
   1367  1.5   itojun int			ahd_match_scb(struct ahd_softc *, struct scb *,
   1368  1.5   itojun 			    int, char, int, u_int, role_t);
   1369  1.1     fvdl 
   1370  1.1     fvdl /****************************** Initialization ********************************/
   1371  1.5   itojun /*struct ahd_softc	*ahd_alloc(void *, char *);*/
   1372  1.1     fvdl int			 ahd_softc_init(struct ahd_softc *);
   1373  1.5   itojun void			 ahd_controller_info(struct ahd_softc *, char *);
   1374  1.5   itojun int			 ahd_init(struct ahd_softc *);
   1375  1.5   itojun int			 ahd_default_config(struct ahd_softc *);
   1376  1.7  thorpej int			 ahd_parse_vpddata(struct ahd_softc *,
   1377  1.7  thorpej 					   struct vpd_config *);
   1378  1.5   itojun int			 ahd_parse_cfgdata(struct ahd_softc *,
   1379  1.5   itojun 			    struct seeprom_config *);
   1380  1.5   itojun void			 ahd_intr_enable(struct ahd_softc *, int);
   1381  1.5   itojun void			 ahd_update_coalescing_values(struct ahd_softc *,
   1382  1.5   itojun 			    u_int, u_int, u_int);
   1383  1.5   itojun void			 ahd_enable_coalescing(struct ahd_softc *, int);
   1384  1.5   itojun void			 ahd_pause_and_flushwork(struct ahd_softc *);
   1385  1.5   itojun int			 ahd_suspend(struct ahd_softc *);
   1386  1.5   itojun int			 ahd_resume(struct ahd_softc *);
   1387  1.1     fvdl void			 ahd_set_unit(struct ahd_softc *, int);
   1388  1.1     fvdl void			 ahd_set_name(struct ahd_softc *, char *);
   1389  1.5   itojun struct scb		*ahd_get_scb(struct ahd_softc *, u_int);
   1390  1.5   itojun void			 ahd_free_scb(struct ahd_softc *, struct scb *);
   1391  1.5   itojun void			 ahd_alloc_scbs(struct ahd_softc *);
   1392  1.5   itojun void			 ahd_free(struct ahd_softc *);
   1393  1.8  thorpej int			 ahd_reset(struct ahd_softc *, int);
   1394  1.5   itojun void			 ahd_shutdown(void *);
   1395  1.8  thorpej int			 ahd_write_flexport(struct ahd_softc *,
   1396  1.8  thorpej 					    u_int, u_int);
   1397  1.8  thorpej int			 ahd_read_flexport(struct ahd_softc *, u_int,
   1398  1.8  thorpej 					   uint8_t *);
   1399  1.8  thorpej int			 ahd_wait_flexport(struct ahd_softc *);
   1400  1.1     fvdl 
   1401  1.1     fvdl /*************************** Interrupt Services *******************************/
   1402  1.5   itojun int			ahd_pci_intr(struct ahd_softc *);
   1403  1.5   itojun void			ahd_clear_intstat(struct ahd_softc *);
   1404  1.5   itojun void			ahd_flush_qoutfifo(struct ahd_softc *);
   1405  1.5   itojun void			ahd_run_qoutfifo(struct ahd_softc *);
   1406  1.5   itojun void			ahd_run_post_qoutfifo(struct ahd_softc *);
   1407  1.1     fvdl #ifdef AHD_TARGET_MODE
   1408  1.5   itojun void			ahd_run_tqinfifo(struct ahd_softc *, int);
   1409  1.1     fvdl #endif
   1410  1.5   itojun void			ahd_handle_hwerrint(struct ahd_softc *);
   1411  1.5   itojun void			ahd_handle_seqint(struct ahd_softc *, u_int);
   1412  1.5   itojun void			ahd_handle_scsiint(struct ahd_softc *, u_int);
   1413  1.5   itojun void			ahd_clear_critical_section(struct ahd_softc *);
   1414  1.1     fvdl 
   1415  1.1     fvdl /***************************** Error Recovery *********************************/
   1416  1.1     fvdl typedef enum {
   1417  1.1     fvdl 	SEARCH_COMPLETE,
   1418  1.1     fvdl 	SEARCH_COUNT,
   1419  1.1     fvdl 	SEARCH_REMOVE,
   1420  1.1     fvdl 	SEARCH_PRINT
   1421  1.1     fvdl } ahd_search_action;
   1422  1.5   itojun int			ahd_search_qinfifo(struct ahd_softc *, int, char, int,
   1423  1.5   itojun 			    u_int, role_t, uint32_t, ahd_search_action);
   1424  1.5   itojun int			ahd_search_disc_list(struct ahd_softc *, int, char,
   1425  1.5   itojun 			    int, u_int, int, int, int);
   1426  1.5   itojun void			ahd_freeze_devq(struct ahd_softc *, struct scb *);
   1427  1.5   itojun int			ahd_reset_channel(struct ahd_softc *, char, int);
   1428  1.5   itojun int			ahd_abort_scbs(struct ahd_softc *, int, char, int,
   1429  1.5   itojun 			    u_int, role_t, uint32_t);
   1430  1.5   itojun void			ahd_restart(struct ahd_softc *);
   1431  1.5   itojun void			ahd_clear_fifo(struct ahd_softc *, u_int);
   1432  1.5   itojun void			ahd_handle_scb_status(struct ahd_softc *, struct scb *);
   1433  1.5   itojun void			ahd_handle_scsi_status(struct ahd_softc *,
   1434  1.5   itojun 			    struct scb *);
   1435  1.5   itojun void			ahd_calc_residual(struct ahd_softc *, struct scb *);
   1436  1.1     fvdl /*************************** Utility Functions ********************************/
   1437  1.1     fvdl struct ahd_phase_table_entry*
   1438  1.5   itojun 			ahd_lookup_phase_entry(int);
   1439  1.5   itojun void			ahd_compile_devinfo(struct ahd_devinfo *, u_int, u_int,
   1440  1.5   itojun 			    u_int, char, role_t);
   1441  1.1     fvdl /************************** Transfer Negotiation ******************************/
   1442  1.5   itojun void			ahd_find_syncrate(struct ahd_softc *, u_int *,
   1443  1.5   itojun 			    u_int *, u_int);
   1444  1.5   itojun void			ahd_validate_offset(struct ahd_softc *,
   1445  1.5   itojun 			    struct ahd_initiator_tinfo *, u_int, u_int *,
   1446  1.5   itojun 			    int, role_t);
   1447  1.5   itojun void			ahd_validate_width(struct ahd_softc *,
   1448  1.5   itojun 			    struct ahd_initiator_tinfo *, u_int *, role_t);
   1449  1.1     fvdl /*
   1450  1.1     fvdl  * Negotiation types.  These are used to qualify if we should renegotiate
   1451  1.1     fvdl  * even if our goal and current transport parameters are identical.
   1452  1.1     fvdl  */
   1453  1.1     fvdl typedef enum {
   1454  1.1     fvdl 	AHD_NEG_TO_GOAL,	/* Renegotiate only if goal and curr differ. */
   1455  1.1     fvdl 	AHD_NEG_IF_NON_ASYNC,	/* Renegotiate so long as goal is non-async. */
   1456  1.1     fvdl 	AHD_NEG_ALWAYS		/* Renegotiat even if goal is async. */
   1457  1.1     fvdl } ahd_neg_type;
   1458  1.5   itojun int			ahd_update_neg_request(struct ahd_softc *,
   1459  1.5   itojun 			    struct ahd_devinfo *, struct ahd_tmode_tstate *,
   1460  1.5   itojun 			    struct ahd_initiator_tinfo *, ahd_neg_type);
   1461  1.5   itojun void			ahd_set_width(struct ahd_softc *,
   1462  1.5   itojun 			    struct ahd_devinfo *, u_int, u_int, int);
   1463  1.5   itojun void			ahd_set_syncrate(struct ahd_softc *,
   1464  1.5   itojun 			    struct ahd_devinfo *, u_int, u_int, u_int,
   1465  1.5   itojun 			    u_int, int);
   1466  1.1     fvdl typedef enum {
   1467  1.1     fvdl 	AHD_QUEUE_NONE,
   1468  1.1     fvdl 	AHD_QUEUE_BASIC,
   1469  1.1     fvdl 	AHD_QUEUE_TAGGED
   1470  1.1     fvdl } ahd_queue_alg;
   1471  1.1     fvdl 
   1472  1.5   itojun void			ahd_set_tags(struct ahd_softc *, struct ahd_devinfo *,
   1473  1.5   itojun 			    ahd_queue_alg);
   1474  1.1     fvdl 
   1475  1.1     fvdl /**************************** Target Mode *************************************/
   1476  1.1     fvdl #ifdef AHD_TARGET_MODE
   1477  1.1     fvdl void		ahd_send_lstate_events(struct ahd_softc *,
   1478  1.5   itojun 		    struct ahd_tmode_lstate *);
   1479  1.5   itojun void		ahd_handle_en_lun(struct ahd_softc *,
   1480  1.5   itojun 		    struct cam_sim *, union ccb *);
   1481  1.5   itojun cam_status	ahd_find_tmode_devs(struct ahd_softc *, struct cam_sim *,
   1482  1.5   itojun 		    union ccb *, struct ahd_tmode_tstate **,
   1483  1.5   itojun 		    struct ahd_tmode_lstate **, int);
   1484  1.1     fvdl #ifndef AHD_TMODE_ENABLE
   1485  1.1     fvdl #define AHD_TMODE_ENABLE 0
   1486  1.1     fvdl #endif
   1487  1.1     fvdl #endif
   1488  1.1     fvdl /******************************* Debug ***************************************/
   1489  1.1     fvdl #ifdef AHD_DEBUG
   1490  1.1     fvdl extern uint32_t ahd_debug;
   1491  1.1     fvdl #define AHD_SHOW_MISC		0x00001
   1492  1.1     fvdl #define AHD_SHOW_SENSE		0x00002
   1493  1.1     fvdl #define AHD_SHOW_RECOVERY	0x00004
   1494  1.1     fvdl #define AHD_DUMP_SEEPROM	0x00008
   1495  1.1     fvdl #define AHD_SHOW_TERMCTL	0x00010
   1496  1.1     fvdl #define AHD_SHOW_MEMORY		0x00020
   1497  1.1     fvdl #define AHD_SHOW_MESSAGES	0x00040
   1498  1.1     fvdl #define AHD_SHOW_MODEPTR	0x00080
   1499  1.1     fvdl #define AHD_SHOW_SELTO		0x00100
   1500  1.1     fvdl #define AHD_SHOW_FIFOS		0x00200
   1501  1.1     fvdl #define AHD_SHOW_QFULL		0x00400
   1502  1.1     fvdl #define	AHD_SHOW_DV		0x00800
   1503  1.1     fvdl #define AHD_SHOW_MASKED_ERRORS	0x01000
   1504  1.1     fvdl #define AHD_SHOW_QUEUE		0x02000
   1505  1.1     fvdl #define AHD_SHOW_TQIN		0x04000
   1506  1.1     fvdl #define AHD_SHOW_SG		0x08000
   1507  1.4      wiz #define AHD_SHOW_INT_COALESCING	0x10000
   1508  1.1     fvdl #define AHD_DEBUG_SEQUENCER	0x20000
   1509  1.1     fvdl #endif
   1510  1.5   itojun void			ahd_print_scb(struct scb *);
   1511  1.5   itojun void			ahd_print_devinfo(struct ahd_softc *,
   1512  1.5   itojun 			    struct ahd_devinfo *);
   1513  1.5   itojun void			ahd_dump_sglist(struct scb *);
   1514  1.1     fvdl void			ahd_dump_all_cards_state(void);
   1515  1.5   itojun void			ahd_dump_card_state(struct ahd_softc *);
   1516  1.5   itojun int			ahd_print_register(ahd_reg_parse_entry_t *, u_int,
   1517  1.5   itojun 			    const char *, u_int, u_int, u_int *, u_int);
   1518  1.5   itojun void			ahd_dump_scbs(struct ahd_softc *);
   1519  1.1     fvdl #endif /* _AIC79XXVAR_H_ */
   1520