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