Home | History | Annotate | Line # | Download | only in ic
aic7xxxvar.h revision 1.53.40.1
      1        1.1   mycroft /*
      2       1.44       wiz  * Core definitions and data structures sharable across OS platforms.
      3        1.1   mycroft  *
      4       1.33      fvdl  * Copyright (c) 1994-2001 Justin T. Gibbs.
      5       1.33      fvdl  * Copyright (c) 2000-2001 Adaptec Inc.
      6        1.1   mycroft  * All rights reserved.
      7        1.1   mycroft  *
      8        1.1   mycroft  * Redistribution and use in source and binary forms, with or without
      9        1.1   mycroft  * modification, are permitted provided that the following conditions
     10        1.1   mycroft  * are met:
     11        1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     12       1.21      fvdl  *    notice, this list of conditions, and the following disclaimer,
     13       1.21      fvdl  *    without modification.
     14       1.33      fvdl  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     15       1.33      fvdl  *    substantially similar to the "NO WARRANTY" disclaimer below
     16       1.33      fvdl  *    ("Disclaimer") and any redistribution must be conditioned upon
     17       1.33      fvdl  *    including a substantially similar Disclaimer requirement for further
     18       1.33      fvdl  *    binary redistribution.
     19       1.33      fvdl  * 3. Neither the names of the above-listed copyright holders nor the names
     20       1.33      fvdl  *    of any contributors may be used to endorse or promote products derived
     21       1.33      fvdl  *    from this software without specific prior written permission.
     22        1.4   mycroft  *
     23       1.21      fvdl  * Alternatively, this software may be distributed under the terms of the
     24       1.33      fvdl  * GNU General Public License ("GPL") version 2 as published by the Free
     25       1.33      fvdl  * Software Foundation.
     26       1.21      fvdl  *
     27       1.33      fvdl  * NO WARRANTY
     28       1.33      fvdl  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     29       1.33      fvdl  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     30       1.33      fvdl  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     31       1.33      fvdl  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     32       1.33      fvdl  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     33        1.4   mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     34        1.4   mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     35       1.33      fvdl  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     36       1.33      fvdl  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     37       1.33      fvdl  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     38       1.33      fvdl  * POSSIBILITY OF SUCH DAMAGES.
     39       1.33      fvdl  *
     40  1.53.40.1       mjf  * $Id: aic7xxxvar.h,v 1.53.40.1 2008/02/18 21:05:40 mjf Exp $
     41        1.8  explorer  *
     42       1.33      fvdl  * $FreeBSD: /repoman/r/ncvs/src/sys/dev/aic7xxx/aic7xxx.h,v 1.44 2003/01/20 20:44:55 gibbs Exp $
     43        1.1   mycroft  */
     44       1.33      fvdl /*
     45       1.33      fvdl  * Ported from FreeBSD by Pascal Renauld, Network Storage Solutions, Inc. - April 2003
     46       1.33      fvdl  */
     47       1.33      fvdl 
     48       1.33      fvdl #ifndef _AIC7XXXVAR_H_
     49       1.33      fvdl #define _AIC7XXXVAR_H_
     50       1.33      fvdl 
     51       1.35      fvdl #undef AHC_DEBUG
     52       1.33      fvdl 
     53       1.33      fvdl /* Register Definitions */
     54       1.33      fvdl #include <dev/microcode/aic7xxx/aic7xxx_reg.h>
     55       1.33      fvdl 
     56       1.33      fvdl #include <dev/ic/aic7xxx_cam.h>
     57       1.33      fvdl 
     58       1.33      fvdl #define	AIC_OP_OR	0x0
     59       1.33      fvdl #define	AIC_OP_AND	0x1
     60       1.33      fvdl #define AIC_OP_XOR	0x2
     61       1.33      fvdl #define	AIC_OP_ADD	0x3
     62       1.33      fvdl #define	AIC_OP_ADC	0x4
     63       1.33      fvdl #define	AIC_OP_ROL	0x5
     64       1.33      fvdl #define	AIC_OP_BMOV	0x6
     65       1.33      fvdl 
     66       1.33      fvdl #define	AIC_OP_JMP	0x8
     67       1.33      fvdl #define AIC_OP_JC	0x9
     68       1.33      fvdl #define AIC_OP_JNC	0xa
     69       1.33      fvdl #define AIC_OP_CALL	0xb
     70       1.33      fvdl #define	AIC_OP_JNE	0xc
     71       1.33      fvdl #define	AIC_OP_JNZ	0xd
     72       1.33      fvdl #define	AIC_OP_JE	0xe
     73       1.33      fvdl #define	AIC_OP_JZ	0xf
     74       1.33      fvdl 
     75       1.33      fvdl /* Pseudo Ops */
     76       1.33      fvdl #define	AIC_OP_SHL	0x10
     77       1.33      fvdl #define	AIC_OP_SHR	0x20
     78       1.33      fvdl #define	AIC_OP_ROR	0x30
     79       1.33      fvdl 
     80       1.33      fvdl struct ins_format1 {
     81       1.33      fvdl #if BYTE_ORDER == LITTLE_ENDIAN
     82       1.33      fvdl 	uint32_t	immediate	: 8,
     83       1.33      fvdl 			source		: 9,
     84       1.33      fvdl 			destination	: 9,
     85       1.33      fvdl 			ret		: 1,
     86       1.33      fvdl 			opcode		: 4,
     87       1.33      fvdl 			parity		: 1;
     88       1.33      fvdl #else
     89       1.33      fvdl 	uint32_t	parity		: 1,
     90       1.33      fvdl 			opcode		: 4,
     91       1.33      fvdl 			ret		: 1,
     92       1.33      fvdl 			destination	: 9,
     93       1.33      fvdl 			source		: 9,
     94       1.33      fvdl 			immediate	: 8;
     95       1.33      fvdl #endif
     96       1.33      fvdl };
     97       1.33      fvdl 
     98       1.33      fvdl struct ins_format2 {
     99       1.33      fvdl #if BYTE_ORDER == LITTLE_ENDIAN
    100       1.33      fvdl 	uint32_t	shift_control	: 8,
    101       1.33      fvdl 			source		: 9,
    102       1.33      fvdl 			destination	: 9,
    103       1.33      fvdl 			ret		: 1,
    104       1.33      fvdl 			opcode		: 4,
    105       1.33      fvdl 			parity		: 1;
    106       1.33      fvdl #else
    107       1.33      fvdl 	uint32_t	parity		: 1,
    108       1.33      fvdl 			opcode		: 4,
    109       1.33      fvdl 			ret		: 1,
    110       1.33      fvdl 			destination	: 9,
    111       1.33      fvdl 			source		: 9,
    112       1.33      fvdl 			shift_control	: 8;
    113       1.33      fvdl #endif
    114       1.33      fvdl };
    115       1.33      fvdl 
    116       1.33      fvdl struct ins_format3 {
    117       1.33      fvdl #if BYTE_ORDER == LITTLE_ENDIAN
    118       1.33      fvdl 	uint32_t	immediate	: 8,
    119       1.33      fvdl 			source		: 9,
    120       1.33      fvdl 			address		: 10,
    121       1.33      fvdl 			opcode		: 4,
    122       1.33      fvdl 			parity		: 1;
    123       1.33      fvdl #else
    124       1.33      fvdl 	uint32_t	parity		: 1,
    125       1.33      fvdl 			opcode		: 4,
    126       1.33      fvdl 			address		: 10,
    127       1.33      fvdl 			source		: 9,
    128       1.33      fvdl 			immediate	: 8;
    129       1.33      fvdl #endif
    130       1.33      fvdl };
    131       1.33      fvdl 
    132       1.33      fvdl union ins_formats {
    133       1.33      fvdl 		struct ins_format1 format1;
    134       1.33      fvdl 		struct ins_format2 format2;
    135       1.33      fvdl 		struct ins_format3 format3;
    136       1.33      fvdl 		uint8_t		   bytes[4];
    137       1.33      fvdl 		uint32_t	   integer;
    138       1.33      fvdl };
    139       1.33      fvdl 
    140       1.33      fvdl /************************* Forward Declarations *******************************/
    141       1.33      fvdl struct ahc_platform_data;
    142       1.33      fvdl struct scb_platform_data;
    143       1.33      fvdl struct seeprom_descriptor;
    144       1.33      fvdl 
    145       1.33      fvdl /****************************** Useful Macros *********************************/
    146       1.33      fvdl #ifndef MAX
    147       1.33      fvdl #define MAX(a,b) (((a) > (b)) ? (a) : (b))
    148       1.33      fvdl #endif
    149       1.17  sommerfe 
    150       1.33      fvdl #ifndef MIN
    151       1.33      fvdl #define MIN(a,b) (((a) < (b)) ? (a) : (b))
    152       1.33      fvdl #endif
    153       1.33      fvdl 
    154       1.33      fvdl #ifndef TRUE
    155       1.33      fvdl #define TRUE 1
    156       1.33      fvdl #endif
    157       1.21      fvdl #ifndef FALSE
    158       1.21      fvdl #define FALSE 0
    159       1.21      fvdl #endif
    160       1.21      fvdl 
    161       1.33      fvdl #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array))
    162       1.33      fvdl 
    163       1.33      fvdl #define ALL_CHANNELS '\0'
    164       1.33      fvdl #define ALL_TARGETS_MASK 0xFFFF
    165       1.33      fvdl #define INITIATOR_WILDCARD	(~0)
    166       1.33      fvdl 
    167       1.33      fvdl #define SCSIID_TARGET(ahc, scsiid) \
    168       1.33      fvdl 	(((scsiid) & ((((ahc)->features & AHC_TWIN) != 0) ? TWIN_TID : TID)) \
    169       1.33      fvdl 	>> TID_SHIFT)
    170       1.33      fvdl #define SCSIID_OUR_ID(scsiid) \
    171       1.33      fvdl 	((scsiid) & OID)
    172       1.33      fvdl #define SCSIID_CHANNEL(ahc, scsiid) \
    173       1.33      fvdl 	((((ahc)->features & AHC_TWIN) != 0) \
    174       1.51   tsutsui 	? ((((scsiid) & TWIN_CHNLB) != 0) ? 'B' : 'A') \
    175       1.51   tsutsui 	: 'A')
    176       1.33      fvdl #define	SCB_IS_SCSIBUS_B(ahc, scb) \
    177       1.33      fvdl 	(SCSIID_CHANNEL(ahc, (scb)->hscb->scsiid) == 'B')
    178       1.33      fvdl #define	SCB_GET_OUR_ID(scb) \
    179       1.33      fvdl 	SCSIID_OUR_ID((scb)->hscb->scsiid)
    180       1.33      fvdl #define	SCB_GET_TARGET(ahc, scb) \
    181       1.33      fvdl 	SCSIID_TARGET((ahc), (scb)->hscb->scsiid)
    182       1.33      fvdl #define	SCB_GET_CHANNEL(ahc, scb) \
    183       1.33      fvdl 	SCSIID_CHANNEL(ahc, (scb)->hscb->scsiid)
    184       1.33      fvdl #define	SCB_GET_LUN(scb) \
    185       1.33      fvdl 	((scb)->hscb->lun)
    186       1.33      fvdl #define SCB_GET_TARGET_OFFSET(ahc, scb)	\
    187       1.33      fvdl 	(SCB_GET_TARGET(ahc, scb))
    188       1.33      fvdl #define SCB_GET_TARGET_MASK(ahc, scb) \
    189       1.33      fvdl 	(0x01 << (SCB_GET_TARGET_OFFSET(ahc, scb)))
    190       1.33      fvdl #ifdef AHC_DEBUG
    191       1.33      fvdl #define SCB_IS_SILENT(scb)					\
    192       1.33      fvdl 	((ahc_debug & AHC_SHOW_MASKED_ERRORS) == 0		\
    193       1.51   tsutsui 	&& (((scb)->flags & SCB_SILENT) != 0))
    194       1.33      fvdl #else
    195       1.33      fvdl #define SCB_IS_SILENT(scb)					\
    196       1.33      fvdl 	(((scb)->flags & SCB_SILENT) != 0)
    197       1.33      fvdl #endif
    198       1.33      fvdl #define TCL_TARGET_OFFSET(tcl) \
    199       1.33      fvdl 	((((tcl) >> 4) & TID) >> 4)
    200       1.33      fvdl #define TCL_LUN(tcl) \
    201       1.33      fvdl 	(tcl & (AHC_NUM_LUNS - 1))
    202       1.33      fvdl #define BUILD_TCL(scsiid, lun) \
    203       1.33      fvdl 	((lun) | (((scsiid) & TID) << 4))
    204       1.33      fvdl 
    205       1.33      fvdl #ifndef	AHC_TARGET_MODE
    206       1.33      fvdl #undef	AHC_TMODE_ENABLE
    207       1.33      fvdl #define	AHC_TMODE_ENABLE 0
    208       1.21      fvdl #endif
    209       1.17  sommerfe 
    210       1.33      fvdl /**************************** Driver Constants ********************************/
    211       1.33      fvdl /*
    212       1.33      fvdl  * The maximum number of supported targets.
    213       1.33      fvdl  */
    214       1.33      fvdl #define AHC_NUM_TARGETS 16
    215       1.33      fvdl 
    216       1.33      fvdl /*
    217       1.33      fvdl  * The maximum number of supported luns.
    218       1.33      fvdl  * The identify message only supports 64 luns in SPI3.
    219       1.33      fvdl  * You can have 2^64 luns when information unit transfers are enabled,
    220       1.33      fvdl  * but it is doubtful this driver will ever support IUTs.
    221       1.33      fvdl  */
    222       1.33      fvdl #define AHC_NUM_LUNS 64
    223       1.33      fvdl 
    224        1.8  explorer /*
    225       1.21      fvdl  * The maximum transfer per S/G segment.
    226       1.42      fvdl  * Limited by MAXPHYS or a 24-bit counter.
    227        1.8  explorer  */
    228       1.51   tsutsui #define AHC_MAXTRANSFER_SIZE	MIN(MAXPHYS,0x00ffffff)
    229       1.33      fvdl 
    230       1.33      fvdl /*
    231       1.33      fvdl  * The maximum amount of SCB storage in hardware on a controller.
    232       1.33      fvdl  * This value represents an upper bound.  Controllers vary in the number
    233       1.33      fvdl  * they actually support.
    234       1.33      fvdl  */
    235       1.33      fvdl #define AHC_SCB_MAX	255
    236       1.33      fvdl 
    237       1.33      fvdl /*
    238       1.33      fvdl  * The maximum number of concurrent transactions supported per driver instance.
    239       1.33      fvdl  * Sequencer Control Blocks (SCBs) store per-transaction information.  Although
    240       1.33      fvdl  * the space for SCBs on the host adapter varies by model, the driver will
    241       1.33      fvdl  * page the SCBs between host and controller memory as needed.  We are limited
    242       1.33      fvdl  * to 253 because:
    243       1.33      fvdl  * 	1) The 8bit nature of the RISC engine holds us to an 8bit value.
    244       1.33      fvdl  * 	2) We reserve one value, 255, to represent the invalid element.
    245       1.33      fvdl  *	3) Our input queue scheme requires one SCB to always be reserved
    246       1.33      fvdl  *	   in advance of queuing any SCBs.  This takes us down to 254.
    247       1.33      fvdl  *	4) To handle our output queue correctly on machines that only
    248       1.33      fvdl  * 	   support 32bit stores, we must clear the array 4 bytes at a
    249       1.33      fvdl  *	   time.  To avoid colliding with a DMA write from the sequencer,
    250       1.33      fvdl  *	   we must be sure that 4 slots are empty when we write to clear
    251       1.33      fvdl  *	   the queue.  This reduces us to 253 SCBs: 1 that just completed
    252       1.33      fvdl  *	   and the known three additional empty slots in the queue that
    253       1.33      fvdl  *	   precede it.
    254       1.33      fvdl  */
    255       1.33      fvdl #define AHC_MAX_QUEUE	253
    256       1.16       leo 
    257       1.21      fvdl /*
    258       1.33      fvdl  * The maximum amount of SCB storage we allocate in host memory.  This
    259       1.33      fvdl  * number should reflect the 1 additional SCB we require to handle our
    260       1.33      fvdl  * qinfifo mechanism.
    261       1.33      fvdl  */
    262       1.33      fvdl #define AHC_SCB_MAX_ALLOC (AHC_MAX_QUEUE+1)
    263        1.1   mycroft 
    264       1.33      fvdl /*
    265       1.33      fvdl  * Ring Buffer of incoming target commands.
    266       1.33      fvdl  * We allocate 256 to simplify the logic in the sequencer
    267       1.33      fvdl  * by using the natural wrap point of an 8bit counter.
    268       1.33      fvdl  */
    269       1.33      fvdl #define AHC_TMODE_CMDS	256
    270        1.1   mycroft 
    271       1.33      fvdl /* Reset line assertion time in us */
    272       1.33      fvdl #define AHC_BUSRESET_DELAY	25
    273        1.4   mycroft 
    274       1.33      fvdl /******************* Chip Characteristics/Operating Settings  *****************/
    275       1.33      fvdl /*
    276       1.33      fvdl  * Chip Type
    277       1.33      fvdl  * The chip order is from least sophisticated to most sophisticated.
    278       1.33      fvdl  */
    279        1.4   mycroft typedef enum {
    280       1.21      fvdl 	AHC_NONE	= 0x0000,
    281       1.21      fvdl 	AHC_CHIPID_MASK	= 0x00FF,
    282       1.21      fvdl 	AHC_AIC7770	= 0x0001,
    283       1.21      fvdl 	AHC_AIC7850	= 0x0002,
    284       1.21      fvdl 	AHC_AIC7855	= 0x0003,
    285       1.21      fvdl 	AHC_AIC7859	= 0x0004,
    286       1.21      fvdl 	AHC_AIC7860	= 0x0005,
    287       1.21      fvdl 	AHC_AIC7870	= 0x0006,
    288       1.21      fvdl 	AHC_AIC7880	= 0x0007,
    289       1.33      fvdl 	AHC_AIC7895	= 0x0008,
    290       1.33      fvdl 	AHC_AIC7895C	= 0x0009,
    291       1.33      fvdl 	AHC_AIC7890	= 0x000a,
    292       1.21      fvdl 	AHC_AIC7896	= 0x000b,
    293       1.33      fvdl 	AHC_AIC7892	= 0x000c,
    294       1.33      fvdl 	AHC_AIC7899	= 0x000d,
    295       1.21      fvdl 	AHC_VL		= 0x0100,	/* Bus type VL */
    296       1.21      fvdl 	AHC_EISA	= 0x0200,	/* Bus type EISA */
    297       1.21      fvdl 	AHC_PCI		= 0x0400,	/* Bus type PCI */
    298       1.21      fvdl 	AHC_BUS_MASK	= 0x0F00
    299       1.21      fvdl } ahc_chip;
    300       1.21      fvdl 
    301       1.33      fvdl /*
    302       1.33      fvdl  * Features available in each chip type.
    303       1.33      fvdl  */
    304       1.21      fvdl typedef enum {
    305       1.33      fvdl 	AHC_FENONE	= 0x00000,
    306       1.33      fvdl 	AHC_ULTRA	= 0x00001,	/* Supports 20MHz Transfers */
    307       1.33      fvdl 	AHC_ULTRA2	= 0x00002,	/* Supports 40MHz Transfers */
    308       1.33      fvdl 	AHC_WIDE  	= 0x00004,	/* Wide Channel */
    309       1.33      fvdl 	AHC_TWIN	= 0x00008,	/* Twin Channel */
    310       1.33      fvdl 	AHC_MORE_SRAM	= 0x00010,	/* 80 bytes instead of 64 */
    311       1.33      fvdl 	AHC_CMD_CHAN	= 0x00020,	/* Has a Command DMA Channel */
    312       1.33      fvdl 	AHC_QUEUE_REGS	= 0x00040,	/* Has Queue management registers */
    313       1.33      fvdl 	AHC_SG_PRELOAD	= 0x00080,	/* Can perform auto-SG preload */
    314       1.33      fvdl 	AHC_SPIOCAP	= 0x00100,	/* Has a Serial Port I/O Cap Register */
    315       1.33      fvdl 	AHC_MULTI_TID	= 0x00200,	/* Has bitmask of TIDs for select-in */
    316       1.33      fvdl 	AHC_HS_MAILBOX	= 0x00400,	/* Has HS_MAILBOX register */
    317       1.33      fvdl 	AHC_DT		= 0x00800,	/* Double Transition transfers */
    318       1.33      fvdl 	AHC_NEW_TERMCTL	= 0x01000,	/* Newer termination scheme */
    319       1.33      fvdl 	AHC_MULTI_FUNC	= 0x02000,	/* Multi-Function Twin Channel Device */
    320       1.33      fvdl 	AHC_LARGE_SCBS	= 0x04000,	/* 64byte SCBs */
    321       1.33      fvdl 	AHC_AUTORATE	= 0x08000,	/* Automatic update of SCSIRATE/OFFSET*/
    322       1.33      fvdl 	AHC_AUTOPAUSE	= 0x10000,	/* Automatic pause on register access */
    323       1.33      fvdl 	AHC_TARGETMODE	= 0x20000,	/* Has tested target mode support */
    324       1.33      fvdl 	AHC_MULTIROLE	= 0x40000,	/* Space for two roles at a time */
    325       1.33      fvdl 	AHC_REMOVABLE	= 0x80000,	/* Hot-Swap supported */
    326       1.33      fvdl 	AHC_AIC7770_FE	= AHC_FENONE,
    327       1.33      fvdl 	/*
    328       1.33      fvdl 	 * The real 7850 does not support Ultra modes, but there are
    329       1.33      fvdl 	 * several cards that use the generic 7850 PCI ID even though
    330       1.33      fvdl 	 * they are using an Ultra capable chip (7859/7860).  We start
    331       1.33      fvdl 	 * out with the AHC_ULTRA feature set and then check the DEVSTATUS
    332       1.33      fvdl 	 * register to determine if the capability is really present.
    333       1.33      fvdl 	 */
    334       1.33      fvdl 	AHC_AIC7850_FE	= AHC_SPIOCAP|AHC_AUTOPAUSE|AHC_TARGETMODE|AHC_ULTRA,
    335       1.33      fvdl 	AHC_AIC7860_FE	= AHC_AIC7850_FE,
    336       1.33      fvdl 	AHC_AIC7870_FE	= AHC_TARGETMODE,
    337       1.33      fvdl 	AHC_AIC7880_FE	= AHC_AIC7870_FE|AHC_ULTRA,
    338       1.33      fvdl 	/*
    339       1.33      fvdl 	 * Although we have space for both the initiator and
    340       1.33      fvdl 	 * target roles on ULTRA2 chips, we currently disable
    341       1.33      fvdl 	 * the initiator role to allow multi-scsi-id target mode
    342       1.33      fvdl 	 * configurations.  We can only respond on the same SCSI
    343       1.33      fvdl 	 * ID as our initiator role if we allow initiator operation.
    344       1.33      fvdl 	 * At some point, we should add a configuration knob to
    345       1.33      fvdl 	 * allow both roles to be loaded.
    346       1.33      fvdl 	 */
    347       1.33      fvdl 	AHC_AIC7890_FE	= AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA2
    348       1.33      fvdl 			  |AHC_QUEUE_REGS|AHC_SG_PRELOAD|AHC_MULTI_TID
    349       1.33      fvdl 			  |AHC_HS_MAILBOX|AHC_NEW_TERMCTL|AHC_LARGE_SCBS
    350       1.33      fvdl 			  |AHC_TARGETMODE,
    351       1.33      fvdl 	AHC_AIC7892_FE	= AHC_AIC7890_FE|AHC_DT|AHC_AUTORATE|AHC_AUTOPAUSE,
    352       1.33      fvdl 	AHC_AIC7895_FE	= AHC_AIC7880_FE|AHC_MORE_SRAM|AHC_AUTOPAUSE
    353       1.33      fvdl 			  |AHC_CMD_CHAN|AHC_MULTI_FUNC|AHC_LARGE_SCBS,
    354       1.21      fvdl 	AHC_AIC7895C_FE	= AHC_AIC7895_FE|AHC_MULTI_TID,
    355       1.21      fvdl 	AHC_AIC7896_FE	= AHC_AIC7890_FE|AHC_MULTI_FUNC,
    356       1.21      fvdl 	AHC_AIC7899_FE	= AHC_AIC7892_FE|AHC_MULTI_FUNC
    357       1.21      fvdl } ahc_feature;
    358        1.4   mycroft 
    359       1.33      fvdl /*
    360       1.33      fvdl  * Bugs in the silicon that we work around in software.
    361       1.33      fvdl  */
    362       1.33      fvdl typedef enum {
    363       1.33      fvdl 	AHC_BUGNONE		= 0x00,
    364       1.33      fvdl 	/*
    365       1.33      fvdl 	 * On all chips prior to the U2 product line,
    366       1.33      fvdl 	 * the WIDEODD S/G segment feature does not
    367       1.33      fvdl 	 * work during scsi->HostBus transfers.
    368       1.33      fvdl 	 */
    369       1.33      fvdl 	AHC_TMODE_WIDEODD_BUG	= 0x01,
    370       1.33      fvdl 	/*
    371       1.33      fvdl 	 * On the aic7890/91 Rev 0 chips, the autoflush
    372       1.33      fvdl 	 * feature does not work.  A manual flush of
    373       1.33      fvdl 	 * the DMA FIFO is required.
    374       1.33      fvdl 	 */
    375       1.33      fvdl 	AHC_AUTOFLUSH_BUG	= 0x02,
    376       1.33      fvdl 	/*
    377       1.33      fvdl 	 * On many chips, cacheline streaming does not work.
    378       1.33      fvdl 	 */
    379       1.33      fvdl 	AHC_CACHETHEN_BUG	= 0x04,
    380       1.33      fvdl 	/*
    381       1.33      fvdl 	 * On the aic7896/97 chips, cacheline
    382       1.33      fvdl 	 * streaming must be enabled.
    383       1.33      fvdl 	 */
    384       1.33      fvdl 	AHC_CACHETHEN_DIS_BUG	= 0x08,
    385       1.33      fvdl 	/*
    386       1.33      fvdl 	 * PCI 2.1 Retry failure on non-empty data fifo.
    387       1.33      fvdl 	 */
    388       1.33      fvdl 	AHC_PCI_2_1_RETRY_BUG	= 0x10,
    389       1.33      fvdl 	/*
    390       1.33      fvdl 	 * Controller does not handle cacheline residuals
    391       1.33      fvdl 	 * properly on S/G segments if PCI MWI instructions
    392       1.33      fvdl 	 * are allowed.
    393       1.33      fvdl 	 */
    394       1.33      fvdl 	AHC_PCI_MWI_BUG		= 0x20,
    395       1.33      fvdl 	/*
    396       1.33      fvdl 	 * An SCB upload using the SCB channel's
    397       1.47     perry 	 * auto array entry copy feature may
    398       1.33      fvdl 	 * corrupt data.  This appears to only
    399       1.33      fvdl 	 * occur on 66MHz systems.
    400       1.33      fvdl 	 */
    401       1.33      fvdl 	AHC_SCBCHAN_UPLOAD_BUG	= 0x40
    402       1.33      fvdl } ahc_bug;
    403       1.33      fvdl 
    404       1.33      fvdl /*
    405       1.33      fvdl  * Configuration specific settings.
    406       1.33      fvdl  * The driver determines these settings by probing the
    407       1.33      fvdl  * chip/controller's configuration.
    408       1.33      fvdl  */
    409        1.4   mycroft typedef enum {
    410       1.33      fvdl 	AHC_FNONE	      = 0x000,
    411       1.33      fvdl 	AHC_PRIMARY_CHANNEL   = 0x003,  /*
    412       1.33      fvdl 					 * The channel that should
    413       1.33      fvdl 					 * be probed first.
    414        1.4   mycroft 					 */
    415       1.33      fvdl 	AHC_USEDEFAULTS	      = 0x004,  /*
    416        1.4   mycroft 					 * For cards without an seeprom
    417        1.4   mycroft 					 * or a BIOS to initialize the chip's
    418       1.52   tsutsui 					 * SRAM, we use the default settings.
    419        1.4   mycroft 					 */
    420       1.33      fvdl 	AHC_SEQUENCER_DEBUG   = 0x008,
    421       1.33      fvdl 	AHC_SHARED_SRAM	      = 0x010,
    422       1.33      fvdl 	AHC_LARGE_SEEPROM     = 0x020,  /* Uses C56_66 not C46 */
    423       1.33      fvdl 	AHC_RESET_BUS_A	      = 0x040,
    424       1.33      fvdl 	AHC_RESET_BUS_B	      = 0x080,
    425       1.33      fvdl 	AHC_EXTENDED_TRANS_A  = 0x100,
    426       1.33      fvdl 	AHC_EXTENDED_TRANS_B  = 0x200,
    427       1.33      fvdl 	AHC_TERM_ENB_A	      = 0x400,
    428       1.33      fvdl 	AHC_TERM_ENB_B	      = 0x800,
    429       1.33      fvdl 	AHC_INITIATORROLE     = 0x1000,  /*
    430       1.21      fvdl 					  * Allow initiator operations on
    431       1.21      fvdl 					  * this controller.
    432       1.21      fvdl 					  */
    433       1.33      fvdl 	AHC_TARGETROLE	      = 0x2000,  /*
    434       1.21      fvdl 					  * Allow target operations on this
    435       1.21      fvdl 					  * controller.
    436       1.21      fvdl 					  */
    437       1.33      fvdl 	AHC_NEWEEPROM_FMT     = 0x4000,
    438       1.33      fvdl 	AHC_RESOURCE_SHORTAGE = 0x8000,
    439       1.33      fvdl 	AHC_TQINFIFO_BLOCKED  = 0x10000,  /* Blocked waiting for ATIOs */
    440       1.33      fvdl 	AHC_INT50_SPEEDFLEX   = 0x20000,  /*
    441       1.21      fvdl 					   * Internal 50pin connector
    442       1.21      fvdl 					   * sits behind an aic3860
    443       1.21      fvdl 					   */
    444       1.33      fvdl 	AHC_SCB_BTT	      = 0x40000,  /*
    445       1.33      fvdl 					   * The busy targets table is
    446       1.33      fvdl 					   * stored in SCB space rather
    447       1.33      fvdl 					   * than SRAM.
    448       1.33      fvdl 					   */
    449       1.33      fvdl 	AHC_BIOS_ENABLED      = 0x80000,
    450       1.33      fvdl 	AHC_ALL_INTERRUPTS    = 0x100000,
    451       1.33      fvdl 	AHC_PAGESCBS	      = 0x400000,  /* Enable SCB paging */
    452       1.33      fvdl 	AHC_EDGE_INTERRUPT    = 0x800000,  /* Device uses edge triggered ints */
    453       1.33      fvdl 	AHC_39BIT_ADDRESSING  = 0x1000000, /* Use 39 bit addressing scheme. */
    454       1.33      fvdl 	AHC_LSCBS_ENABLED     = 0x2000000, /* 64Byte SCBs enabled */
    455       1.33      fvdl 	AHC_SCB_CONFIG_USED   = 0x4000000, /* No SEEPROM but SCB2 had info. */
    456       1.33      fvdl 	AHC_NO_BIOS_INIT      = 0x8000000, /* No BIOS left over settings. */
    457       1.52   tsutsui 	AHC_DISABLE_PCI_PERR  = 0x10000000,
    458       1.52   tsutsui 	AHC_USETARGETDEFAULTS = 0x20000000 /*
    459       1.52   tsutsui 					    * For cards without an seeprom but
    460       1.52   tsutsui 					    * with BIOS which initializes chip's
    461       1.52   tsutsui 					    * SRAM with some conservative target
    462       1.52   tsutsui 					    * settings, we use the default
    463       1.52   tsutsui 					    * SCSI target settings.
    464       1.52   tsutsui 					    */
    465       1.21      fvdl } ahc_flag;
    466        1.4   mycroft 
    467       1.33      fvdl /************************* Hardware  SCB Definition ***************************/
    468       1.33      fvdl 
    469       1.33      fvdl /*
    470       1.33      fvdl  * The driver keeps up to MAX_SCB scb structures per card in memory.  The SCB
    471       1.43       wiz  * consists of a "hardware SCB" mirroring the fields available on the card
    472       1.33      fvdl  * and additional information the kernel stores for each transaction.
    473       1.33      fvdl  *
    474       1.33      fvdl  * To minimize space utilization, a portion of the hardware scb stores
    475       1.33      fvdl  * different data during different portions of a SCSI transaction.
    476       1.33      fvdl  * As initialized by the host driver for the initiator role, this area
    477       1.33      fvdl  * contains the SCSI cdb (or a pointer to the  cdb) to be executed.  After
    478       1.33      fvdl  * the cdb has been presented to the target, this area serves to store
    479       1.33      fvdl  * residual transfer information and the SCSI status byte.
    480       1.33      fvdl  * For the target role, the contents of this area do not change, but
    481       1.33      fvdl  * still serve a different purpose than for the initiator role.  See
    482       1.33      fvdl  * struct target_data for details.
    483       1.33      fvdl  */
    484       1.33      fvdl 
    485       1.33      fvdl /*
    486       1.43       wiz  * Status information embedded in the shared portion of
    487       1.33      fvdl  * an SCB after passing the cdb to the target.  The kernel
    488       1.33      fvdl  * driver will only read this data for transactions that
    489       1.33      fvdl  * complete abnormally (non-zero status byte).
    490       1.33      fvdl  */
    491       1.33      fvdl struct status_pkt {
    492       1.33      fvdl 	uint32_t residual_datacnt;	/* Residual in the current S/G seg */
    493       1.33      fvdl 	uint32_t residual_sg_ptr;	/* The next S/G for this transfer */
    494       1.33      fvdl 	uint8_t	 scsi_status;		/* Standard SCSI status byte */
    495       1.33      fvdl };
    496       1.33      fvdl 
    497       1.33      fvdl /*
    498       1.33      fvdl  * Target mode version of the shared data SCB segment.
    499       1.33      fvdl  */
    500       1.33      fvdl struct target_data {
    501       1.33      fvdl 	uint32_t residual_datacnt;	/* Residual in the current S/G seg */
    502       1.33      fvdl 	uint32_t residual_sg_ptr;	/* The next S/G for this transfer */
    503       1.33      fvdl 	uint8_t  scsi_status;		/* SCSI status to give to initiator */
    504       1.33      fvdl 	uint8_t  target_phases;		/* Bitmap of phases to execute */
    505       1.33      fvdl 	uint8_t  data_phase;		/* Data-In or Data-Out */
    506       1.33      fvdl 	uint8_t  initiator_tag;		/* Initiator's transaction tag */
    507       1.33      fvdl };
    508       1.33      fvdl 
    509       1.33      fvdl struct hardware_scb {
    510       1.33      fvdl /*0*/	union {
    511       1.33      fvdl 		/*
    512       1.33      fvdl 		 * If the cdb is 12 bytes or less, we embed it directly
    513       1.33      fvdl 		 * in the SCB.  For longer cdbs, we embed the address
    514       1.33      fvdl 		 * of the cdb payload as seen by the chip and a DMA
    515       1.33      fvdl 		 * is used to pull it in.
    516       1.33      fvdl 		 */
    517       1.33      fvdl 		uint8_t	 cdb[12];
    518       1.33      fvdl 		uint32_t cdb_ptr;
    519       1.33      fvdl 		struct	 status_pkt status;
    520       1.33      fvdl 		struct	 target_data tdata;
    521       1.33      fvdl 	} shared_data;
    522       1.33      fvdl /*
    523       1.33      fvdl  * A word about residuals.
    524       1.33      fvdl  * The scb is presented to the sequencer with the dataptr and datacnt
    525       1.33      fvdl  * fields initialized to the contents of the first S/G element to
    526       1.33      fvdl  * transfer.  The sgptr field is initialized to the bus address for
    527       1.33      fvdl  * the S/G element that follows the first in the in core S/G array
    528       1.33      fvdl  * or'ed with the SG_FULL_RESID flag.  Sgptr may point to an invalid
    529       1.33      fvdl  * S/G entry for this transfer (single S/G element transfer with the
    530       1.33      fvdl  * first elements address and length preloaded in the dataptr/datacnt
    531       1.33      fvdl  * fields).  If no transfer is to occur, sgptr is set to SG_LIST_NULL.
    532       1.33      fvdl  * The SG_FULL_RESID flag ensures that the residual will be correctly
    533       1.33      fvdl  * noted even if no data transfers occur.  Once the data phase is entered,
    534       1.33      fvdl  * the residual sgptr and datacnt are loaded from the sgptr and the
    535       1.33      fvdl  * datacnt fields.  After each S/G element's dataptr and length are
    536       1.33      fvdl  * loaded into the hardware, the residual sgptr is advanced.  After
    537       1.33      fvdl  * each S/G element is expired, its datacnt field is checked to see
    538       1.33      fvdl  * if the LAST_SEG flag is set.  If so, SG_LIST_NULL is set in the
    539       1.33      fvdl  * residual sg ptr and the transfer is considered complete.  If the
    540       1.43       wiz  * sequencer determines that there is a residual in the transfer, it
    541       1.38       wiz  * will set the SG_RESID_VALID flag in sgptr and DMA the scb back into
    542       1.39       wiz  * host memory.  To summarize:
    543       1.33      fvdl  *
    544       1.33      fvdl  * Sequencer:
    545       1.33      fvdl  *	o A residual has occurred if SG_FULL_RESID is set in sgptr,
    546       1.33      fvdl  *	  or residual_sgptr does not have SG_LIST_NULL set.
    547       1.33      fvdl  *
    548       1.33      fvdl  *	o We are transfering the last segment if residual_datacnt has
    549       1.33      fvdl  *	  the SG_LAST_SEG flag set.
    550       1.33      fvdl  *
    551       1.33      fvdl  * Host:
    552       1.33      fvdl  *	o A residual has occurred if a completed scb has the
    553       1.33      fvdl  *	  SG_RESID_VALID flag set.
    554       1.33      fvdl  *
    555       1.33      fvdl  *	o residual_sgptr and sgptr refer to the "next" sg entry
    556       1.33      fvdl  *	  and so may point beyond the last valid sg entry for the
    557       1.33      fvdl  *	  transfer.
    558       1.47     perry  */
    559       1.33      fvdl /*12*/	uint32_t dataptr;
    560       1.33      fvdl /*16*/	uint32_t datacnt;		/*
    561       1.33      fvdl 					 * Byte 3 (numbered from 0) of
    562       1.33      fvdl 					 * the datacnt is really the
    563       1.33      fvdl 					 * 4th byte in that data address.
    564       1.33      fvdl 					 */
    565       1.33      fvdl /*20*/	uint32_t sgptr;
    566       1.33      fvdl #define SG_PTR_MASK	0xFFFFFFF8
    567       1.33      fvdl /*24*/	uint8_t  control;	/* See SCB_CONTROL in aic7xxx.reg for details */
    568       1.33      fvdl /*25*/	uint8_t  scsiid;	/* what to load in the SCSIID register */
    569       1.33      fvdl /*26*/	uint8_t  lun;
    570       1.33      fvdl /*27*/	uint8_t  tag;			/*
    571       1.33      fvdl 					 * Index into our kernel SCB array.
    572       1.33      fvdl 					 * Also used as the tag for tagged I/O
    573       1.33      fvdl 					 */
    574       1.33      fvdl /*28*/	uint8_t  cdb_len;
    575       1.33      fvdl /*29*/	uint8_t  scsirate;		/* Value for SCSIRATE register */
    576       1.33      fvdl /*30*/	uint8_t  scsioffset;		/* Value for SCSIOFFSET register */
    577       1.33      fvdl /*31*/	uint8_t  next;			/*
    578       1.33      fvdl 					 * Used for threading SCBs in the
    579       1.33      fvdl 					 * "Waiting for Selection" and
    580       1.33      fvdl 					 * "Disconnected SCB" lists down
    581       1.33      fvdl 					 * in the sequencer.
    582       1.33      fvdl 					 */
    583       1.33      fvdl /*32*/	uint8_t  cdb32[32];		/*
    584       1.33      fvdl 					 * CDB storage for cdbs of size
    585       1.33      fvdl 					 * 13->32.  We store them here
    586       1.33      fvdl 					 * because hardware scbs are
    587       1.33      fvdl 					 * allocated from DMA safe
    588       1.33      fvdl 					 * memory so we are guaranteed
    589       1.33      fvdl 					 * the controller can access
    590       1.33      fvdl 					 * this data.
    591       1.33      fvdl 					 */
    592       1.33      fvdl };
    593       1.33      fvdl 
    594       1.33      fvdl /************************ Kernel SCB Definitions ******************************/
    595       1.33      fvdl /*
    596       1.33      fvdl  * Some fields of the SCB are OS dependent.  Here we collect the
    597       1.33      fvdl  * definitions for elements that all OS platforms need to include
    598       1.33      fvdl  * in there SCB definition.
    599       1.33      fvdl  */
    600       1.33      fvdl 
    601       1.33      fvdl /*
    602       1.43       wiz  * Definition of a scatter/gather element as transferred to the controller.
    603       1.33      fvdl  * The aic7xxx chips only support a 24bit length.  We use the top byte of
    604       1.33      fvdl  * the length to store additional address bits and a flag to indicate
    605       1.33      fvdl  * that a given segment terminates the transfer.  This gives us an
    606       1.33      fvdl  * addressable range of 512GB on machines with 64bit PCI or with chips
    607       1.33      fvdl  * that can support dual address cycles on 32bit PCI busses.
    608       1.33      fvdl  */
    609       1.33      fvdl struct ahc_dma_seg {
    610       1.33      fvdl 	uint32_t	addr;
    611       1.33      fvdl 	uint32_t	len;
    612       1.33      fvdl #define	AHC_DMA_LAST_SEG	0x80000000
    613       1.33      fvdl #define	AHC_SG_HIGH_ADDR_MASK	0x7F000000
    614       1.33      fvdl #define	AHC_SG_LEN_MASK		0x00FFFFFF
    615       1.33      fvdl };
    616       1.33      fvdl 
    617       1.33      fvdl struct sg_map_node {
    618       1.33      fvdl 	bus_dmamap_t		 sg_dmamap;
    619       1.33      fvdl 	bus_addr_t		 sg_physaddr;
    620       1.33      fvdl 	bus_dma_segment_t	 sg_dmasegs;
    621       1.33      fvdl 	int			 sg_nseg;
    622       1.33      fvdl 	struct ahc_dma_seg*	 sg_vaddr;
    623       1.33      fvdl 	SLIST_ENTRY(sg_map_node) links;
    624       1.33      fvdl };
    625       1.33      fvdl 
    626       1.33      fvdl struct ahc_pci_busdata {
    627       1.33      fvdl 	pci_chipset_tag_t pc;
    628       1.33      fvdl 	pcitag_t tag;
    629       1.33      fvdl 	u_int dev;
    630       1.33      fvdl 	u_int func;
    631       1.33      fvdl 	pcireg_t class;
    632       1.33      fvdl };
    633       1.33      fvdl 
    634       1.33      fvdl /*
    635       1.33      fvdl  * The current state of this SCB.
    636       1.33      fvdl  */
    637        1.4   mycroft typedef enum {
    638        1.9     gibbs 	SCB_FREE		= 0x0000,
    639       1.21      fvdl 	SCB_OTHERTCL_TIMEOUT	= 0x0002,/*
    640       1.21      fvdl 					  * Another device was active
    641       1.21      fvdl 					  * during the first timeout for
    642       1.21      fvdl 					  * this SCB so we gave ourselves
    643       1.21      fvdl 					  * an additional timeout period
    644       1.21      fvdl 					  * in case it was hogging the
    645       1.21      fvdl 					  * bus.
    646       1.21      fvdl 				          */
    647        1.9     gibbs 	SCB_DEVICE_RESET	= 0x0004,
    648       1.21      fvdl 	SCB_SENSE		= 0x0008,
    649       1.33      fvdl 	SCB_CDB32_PTR		= 0x0010,
    650       1.33      fvdl 	SCB_RECOVERY_SCB	= 0x0020,
    651       1.33      fvdl 	SCB_AUTO_NEGOTIATE	= 0x0040,/* Negotiate to achieve goal. */
    652       1.33      fvdl 	SCB_NEGOTIATE		= 0x0080,/* Negotiation forced for command. */
    653       1.33      fvdl 	SCB_ABORT		= 0x0100,
    654       1.33      fvdl 	SCB_UNTAGGEDQ		= 0x0200,
    655       1.33      fvdl 	SCB_ACTIVE		= 0x0400,
    656       1.33      fvdl 	SCB_TARGET_IMMEDIATE	= 0x0800,
    657       1.33      fvdl 	SCB_TRANSMISSION_ERROR	= 0x1000,/*
    658       1.33      fvdl 					  * We detected a parity or CRC
    659       1.33      fvdl 					  * error that has effected the
    660       1.33      fvdl 					  * payload of the command.  This
    661       1.33      fvdl 					  * flag is checked when normal
    662       1.33      fvdl 					  * status is returned to catch
    663       1.33      fvdl 					  * the case of a target not
    664       1.33      fvdl 					  * responding to our attempt
    665       1.33      fvdl 					  * to report the error.
    666       1.33      fvdl 					  */
    667       1.33      fvdl 	SCB_TARGET_SCB		= 0x2000,
    668       1.33      fvdl 	SCB_SILENT		= 0x4000,/*
    669       1.33      fvdl 					  * Be quiet about transmission type
    670       1.33      fvdl 					  * errors.  They are expected and we
    671       1.33      fvdl 					  * don't want to upset the user.  This
    672       1.33      fvdl 					  * flag is typically used during DV.
    673       1.33      fvdl 					  */
    674       1.33      fvdl 	SCB_FREEZE_QUEUE	= 0x8000
    675       1.21      fvdl } scb_flag;
    676       1.21      fvdl 
    677       1.33      fvdl struct scb {
    678       1.33      fvdl 	struct	hardware_scb	 *hscb;
    679       1.33      fvdl 	union {
    680       1.33      fvdl 		SLIST_ENTRY(scb)  sle;
    681       1.33      fvdl 		TAILQ_ENTRY(scb)  tqe;
    682       1.33      fvdl 	} links;
    683       1.33      fvdl 	LIST_ENTRY(scb)		  pending_links;
    684       1.33      fvdl 
    685       1.33      fvdl 	struct scsipi_xfer	 *xs;
    686       1.33      fvdl 	struct ahc_softc	 *ahc_softc;
    687       1.33      fvdl 	scb_flag		  flags;
    688       1.33      fvdl #ifndef __linux__
    689       1.33      fvdl 	bus_dmamap_t		  dmamap;
    690       1.33      fvdl #endif
    691       1.33      fvdl 	struct scb_platform_data *platform_data;
    692       1.33      fvdl 	struct sg_map_node	 *sg_map;
    693       1.33      fvdl 	struct ahc_dma_seg 	 *sg_list;
    694       1.33      fvdl 	bus_addr_t		  sg_list_phys;
    695       1.33      fvdl 	u_int			  sg_count;/* How full ahc_dma_seg is */
    696       1.33      fvdl };
    697       1.21      fvdl 
    698       1.33      fvdl struct scb_data {
    699       1.33      fvdl 	SLIST_HEAD(, scb) free_scbs;	/*
    700       1.33      fvdl 					 * Pool of SCBs ready to be assigned
    701       1.33      fvdl 					 * commands to execute.
    702        1.4   mycroft 					 */
    703       1.33      fvdl 	struct	scb *scbindex[256];	/*
    704       1.33      fvdl 					 * Mapping from tag to SCB.
    705       1.33      fvdl 					 * As tag identifiers are an
    706       1.33      fvdl 					 * 8bit value, we provide space
    707       1.33      fvdl 					 * for all possible tag values.
    708       1.33      fvdl 					 * Any lookups to entries at or
    709       1.33      fvdl 					 * above AHC_SCB_MAX_ALLOC will
    710       1.33      fvdl 					 * always fail.
    711        1.4   mycroft 					 */
    712       1.33      fvdl 	struct	hardware_scb	*hscbs;	/* Array of hardware SCBs */
    713       1.33      fvdl 	struct	scb *scbarray;		/* Array of kernel SCBs */
    714       1.46   thorpej 	struct	scsi_sense_data *sense; /* Per SCB sense data */
    715       1.33      fvdl 
    716       1.33      fvdl 	/*
    717       1.33      fvdl 	 * "Bus" addresses of our data structures.
    718       1.33      fvdl 	 */
    719       1.33      fvdl 	bus_dmamap_t	 hscb_dmamap;
    720       1.33      fvdl 	bus_addr_t	 hscb_busaddr;
    721       1.33      fvdl 	bus_dma_segment_t hscb_seg;
    722       1.33      fvdl 	int		  hscb_nseg;
    723       1.33      fvdl 	int		  hscb_size;
    724       1.33      fvdl 
    725       1.33      fvdl 	bus_dmamap_t	 sense_dmamap;
    726       1.33      fvdl 	bus_addr_t	 sense_busaddr;
    727       1.33      fvdl 	bus_dma_segment_t sense_seg;
    728       1.33      fvdl 	int		  sense_nseg;
    729       1.33      fvdl 	int		  sense_size;
    730       1.33      fvdl 
    731       1.33      fvdl 	SLIST_HEAD(, sg_map_node) sg_maps;
    732       1.33      fvdl 	uint8_t	numscbs;
    733       1.33      fvdl 	uint8_t	maxhscbs;		/* Number of SCBs on the card */
    734       1.33      fvdl 	uint8_t	init_level;		/*
    735       1.33      fvdl 					 * How far we've initialized
    736       1.33      fvdl 					 * this structure.
    737       1.21      fvdl 					 */
    738       1.21      fvdl };
    739       1.21      fvdl 
    740       1.33      fvdl /************************ Target Mode Definitions *****************************/
    741       1.21      fvdl 
    742       1.21      fvdl /*
    743       1.21      fvdl  * Connection desciptor for select-in requests in target mode.
    744       1.21      fvdl  */
    745       1.21      fvdl struct target_cmd {
    746       1.33      fvdl 	uint8_t scsiid;		/* Our ID and the initiator's ID */
    747       1.33      fvdl 	uint8_t identify;	/* Identify message */
    748       1.47     perry 	uint8_t bytes[22];	/*
    749       1.33      fvdl 				 * Bytes contains any additional message
    750       1.33      fvdl 				 * bytes terminated by 0xFF.  The remainder
    751       1.33      fvdl 				 * is the cdb to execute.
    752       1.33      fvdl 				 */
    753       1.33      fvdl 	uint8_t cmd_valid;	/*
    754       1.33      fvdl 				 * When a command is complete, the firmware
    755       1.33      fvdl 				 * will set cmd_valid to all bits set.
    756       1.33      fvdl 				 * After the host has seen the command,
    757       1.33      fvdl 				 * the bits are cleared.  This allows us
    758       1.33      fvdl 				 * to just peek at host memory to determine
    759       1.33      fvdl 				 * if more work is complete. cmd_valid is on
    760       1.33      fvdl 				 * an 8 byte boundary to simplify setting
    761       1.33      fvdl 				 * it on aic7880 hardware which only has
    762       1.33      fvdl 				 * limited direct access to the DMA FIFO.
    763       1.33      fvdl 				 */
    764       1.33      fvdl 	uint8_t pad[7];
    765       1.21      fvdl };
    766       1.21      fvdl 
    767       1.21      fvdl /*
    768       1.21      fvdl  * Number of events we can buffer up if we run out
    769       1.21      fvdl  * of immediate notify ccbs.
    770       1.21      fvdl  */
    771       1.21      fvdl #define AHC_TMODE_EVENT_BUFFER_SIZE 8
    772       1.21      fvdl struct ahc_tmode_event {
    773       1.33      fvdl 	uint8_t initiator_id;
    774       1.33      fvdl 	uint8_t event_type;	/* MSG type or EVENT_TYPE_BUS_RESET */
    775       1.21      fvdl #define	EVENT_TYPE_BUS_RESET 0xFF
    776       1.33      fvdl 	uint8_t event_arg;
    777       1.21      fvdl };
    778       1.21      fvdl 
    779       1.21      fvdl /*
    780       1.33      fvdl  * Per enabled lun target mode state.
    781       1.33      fvdl  * As this state is directly influenced by the host OS'es target mode
    782       1.33      fvdl  * environment, we let the OS module define it.  Forward declare the
    783       1.33      fvdl  * structure here so we can store arrays of them, etc. in OS neutral
    784       1.33      fvdl  * data structures.
    785       1.21      fvdl  */
    786       1.47     perry #ifdef AHC_TARGET_MODE
    787       1.33      fvdl struct ahc_tmode_lstate {
    788       1.33      fvdl #if 0
    789       1.21      fvdl 	struct cam_path *path;
    790       1.21      fvdl 	struct ccb_hdr_slist accept_tios;
    791       1.21      fvdl 	struct ccb_hdr_slist immed_notifies;
    792       1.33      fvdl #endif
    793       1.21      fvdl 	struct ahc_tmode_event event_buffer[AHC_TMODE_EVENT_BUFFER_SIZE];
    794       1.33      fvdl 	uint8_t event_r_idx;
    795       1.33      fvdl 	uint8_t event_w_idx;
    796       1.33      fvdl };
    797       1.21      fvdl #else
    798       1.33      fvdl struct ahc_tmode_lstate;
    799       1.21      fvdl #endif
    800       1.21      fvdl 
    801       1.33      fvdl /******************** Transfer Negotiation Datastructures *********************/
    802       1.43       wiz #define AHC_TRANS_CUR		0x01	/* Modify current negotiation status */
    803       1.33      fvdl #define AHC_TRANS_ACTIVE	0x03	/* Assume this target is on the bus */
    804       1.21      fvdl #define AHC_TRANS_GOAL		0x04	/* Modify negotiation goal */
    805       1.21      fvdl #define AHC_TRANS_USER		0x08	/* Modify user negotiation settings */
    806       1.21      fvdl 
    807       1.33      fvdl #define AHC_WIDTH_UNKNOWN	0xFF
    808       1.33      fvdl #define AHC_PERIOD_UNKNOWN	0xFF
    809       1.33      fvdl #define AHC_OFFSET_UNKNOWN	0x0
    810       1.33      fvdl #define AHC_PPR_OPTS_UNKNOWN	0xFF
    811       1.33      fvdl 
    812       1.33      fvdl /*
    813       1.33      fvdl  * Transfer Negotiation Information.
    814       1.33      fvdl  */
    815       1.21      fvdl struct ahc_transinfo {
    816       1.33      fvdl 	uint8_t protocol_version;	/* SCSI Revision level */
    817       1.33      fvdl 	uint8_t transport_version;	/* SPI Revision level */
    818       1.33      fvdl 	uint8_t width;			/* Bus width */
    819       1.33      fvdl 	uint8_t period;			/* Sync rate factor */
    820       1.33      fvdl 	uint8_t offset;			/* Sync offset */
    821       1.33      fvdl 	uint8_t ppr_options;		/* Parallel Protocol Request options */
    822       1.21      fvdl };
    823       1.21      fvdl 
    824       1.33      fvdl /*
    825       1.33      fvdl  * Per-initiator current, goal and user transfer negotiation information. */
    826       1.21      fvdl struct ahc_initiator_tinfo {
    827       1.33      fvdl 	uint8_t scsirate;		/* Computed value for SCSIRATE reg */
    828       1.33      fvdl 	struct ahc_transinfo curr;
    829       1.21      fvdl 	struct ahc_transinfo goal;
    830       1.21      fvdl 	struct ahc_transinfo user;
    831       1.21      fvdl };
    832       1.21      fvdl 
    833       1.21      fvdl /*
    834       1.33      fvdl  * Per enabled target ID state.
    835       1.33      fvdl  * Pointers to lun target state as well as sync/wide negotiation information
    836       1.33      fvdl  * for each initiator<->target mapping.  For the initiator role we pretend
    837       1.33      fvdl  * that we are the target and the targets are the initiators since the
    838       1.33      fvdl  * negotiation is the same regardless of role.
    839       1.21      fvdl  */
    840       1.33      fvdl struct ahc_tmode_tstate {
    841       1.33      fvdl 	struct ahc_tmode_lstate*	enabled_luns[AHC_NUM_LUNS];
    842       1.33      fvdl 	struct ahc_initiator_tinfo	transinfo[AHC_NUM_TARGETS];
    843       1.15       leo 
    844       1.15       leo 	/*
    845       1.21      fvdl 	 * Per initiator state bitmasks.
    846       1.15       leo 	 */
    847       1.33      fvdl 	uint16_t	 auto_negotiate;/* Auto Negotiation Required */
    848       1.33      fvdl 	uint16_t	 ultraenb;	/* Using ultra sync rate  */
    849       1.33      fvdl 	uint16_t	 discenable;	/* Disconnection allowed  */
    850       1.33      fvdl 	uint16_t	 tagenable;	/* Tagged Queuing allowed */
    851       1.21      fvdl };
    852       1.21      fvdl 
    853       1.33      fvdl /*
    854       1.33      fvdl  * Data structure for our table of allowed synchronous transfer rates.
    855       1.33      fvdl  */
    856       1.33      fvdl struct ahc_syncrate {
    857       1.33      fvdl 	u_int sxfr_u2;	/* Value of the SXFR parameter for Ultra2+ Chips */
    858       1.33      fvdl 	u_int sxfr;	/* Value of the SXFR parameter for <= Ultra Chips */
    859       1.33      fvdl #define		ULTRA_SXFR 0x100	/* Rate Requires Ultra Mode set */
    860       1.33      fvdl #define		ST_SXFR	   0x010	/* Rate Single Transition Only */
    861       1.33      fvdl #define		DT_SXFR	   0x040	/* Rate Double Transition Only */
    862       1.33      fvdl 	uint8_t period; /* Period to send to SCSI target */
    863       1.48  christos 	const char *rate;
    864       1.33      fvdl };
    865       1.33      fvdl 
    866       1.33      fvdl /* Safe and valid period for async negotiations. */
    867       1.33      fvdl #define	AHC_ASYNC_XFER_PERIOD 0x45
    868       1.33      fvdl #define	AHC_ULTRA2_XFER_PERIOD 0x0a
    869       1.15       leo 
    870       1.21      fvdl /*
    871       1.33      fvdl  * Indexes into our table of syncronous transfer rates.
    872       1.21      fvdl  */
    873       1.33      fvdl #define AHC_SYNCRATE_DT		0
    874       1.33      fvdl #define AHC_SYNCRATE_ULTRA2	1
    875       1.33      fvdl #define AHC_SYNCRATE_ULTRA	3
    876       1.33      fvdl #define AHC_SYNCRATE_FAST	6
    877       1.33      fvdl #define AHC_SYNCRATE_MAX	AHC_SYNCRATE_DT
    878       1.33      fvdl #define	AHC_SYNCRATE_MIN	13
    879       1.21      fvdl 
    880       1.33      fvdl /***************************** Lookup Tables **********************************/
    881       1.21      fvdl /*
    882       1.33      fvdl  * Phase -> name and message out response
    883       1.47     perry  * to parity errors in each phase table.
    884       1.21      fvdl  */
    885       1.33      fvdl struct ahc_phase_table_entry {
    886       1.51   tsutsui 	uint8_t phase;
    887       1.51   tsutsui 	uint8_t mesg_out; /* Message response to parity errors */
    888       1.48  christos 	const char *phasemsg;
    889       1.33      fvdl };
    890       1.33      fvdl 
    891       1.33      fvdl /************************** Serial EEPROM Format ******************************/
    892       1.21      fvdl 
    893       1.21      fvdl struct seeprom_config {
    894       1.21      fvdl /*
    895       1.33      fvdl  * Per SCSI ID Configuration Flags
    896       1.21      fvdl  */
    897       1.33      fvdl 	uint16_t device_flags[16];	/* words 0-15 */
    898       1.21      fvdl #define		CFXFER		0x0007	/* synchronous transfer rate */
    899       1.21      fvdl #define		CFSYNCH		0x0008	/* enable synchronous transfer */
    900       1.21      fvdl #define		CFDISC		0x0010	/* enable disconnection */
    901       1.21      fvdl #define		CFWIDEB		0x0020	/* wide bus device */
    902       1.21      fvdl #define		CFSYNCHISULTRA	0x0040	/* CFSYNCH is an ultra offset (2940AU)*/
    903       1.21      fvdl #define		CFSYNCSINGLE	0x0080	/* Single-Transition signalling */
    904       1.21      fvdl #define		CFSTART		0x0100	/* send start unit SCSI command */
    905       1.21      fvdl #define		CFINCBIOS	0x0200	/* include in BIOS scan */
    906       1.21      fvdl #define		CFRNFOUND	0x0400	/* report even if not found */
    907       1.33      fvdl #define		CFMULTILUNDEV	0x0800	/* Probe multiple luns in BIOS scan */
    908       1.21      fvdl #define		CFWBCACHEENB	0x4000	/* Enable W-Behind Cache on disks */
    909       1.21      fvdl #define		CFWBCACHENOP	0xc000	/* Don't touch W-Behind Cache */
    910       1.21      fvdl 
    911       1.21      fvdl /*
    912       1.21      fvdl  * BIOS Control Bits
    913       1.21      fvdl  */
    914       1.33      fvdl 	uint16_t bios_control;		/* word 16 */
    915       1.44       wiz #define		CFSUPREM	0x0001	/* support all removable drives */
    916       1.44       wiz #define		CFSUPREMB	0x0002	/* support removable boot drives */
    917       1.21      fvdl #define		CFBIOSEN	0x0004	/* BIOS enabled */
    918       1.33      fvdl #define		CFBIOS_BUSSCAN	0x0008	/* Have the BIOS Scan the Bus */
    919       1.21      fvdl #define		CFSM2DRV	0x0010	/* support more than two drives */
    920       1.33      fvdl #define		CFSTPWLEVEL	0x0010	/* Termination level control */
    921       1.47     perry #define		CF284XEXTEND	0x0020	/* extended translation (284x cards) */
    922       1.47     perry #define		CFCTRL_A	0x0020	/* BIOS displays Ctrl-A message */
    923       1.47     perry #define		CFTERM_MENU	0x0040	/* BIOS displays termination menu */
    924       1.21      fvdl #define		CFEXTEND	0x0080	/* extended translation enabled */
    925       1.33      fvdl #define		CFSCAMEN	0x0100	/* SCAM enable */
    926       1.33      fvdl #define		CFMSG_LEVEL	0x0600	/* BIOS Message Level */
    927       1.33      fvdl #define			CFMSG_VERBOSE	0x0000
    928       1.33      fvdl #define			CFMSG_SILENT	0x0200
    929       1.33      fvdl #define			CFMSG_DIAG	0x0400
    930       1.33      fvdl #define		CFBOOTCD	0x0800  /* Support Bootable CD-ROM */
    931       1.21      fvdl /*		UNUSED		0xff00	*/
    932       1.21      fvdl 
    933       1.21      fvdl /*
    934       1.21      fvdl  * Host Adapter Control Bits
    935       1.21      fvdl  */
    936       1.47     perry 	uint16_t adapter_control;	/* word 17 */
    937       1.21      fvdl #define		CFAUTOTERM	0x0001	/* Perform Auto termination */
    938       1.21      fvdl #define		CFULTRAEN	0x0002	/* Ultra SCSI speed enable */
    939       1.21      fvdl #define		CF284XSELTO     0x0003	/* Selection timeout (284x cards) */
    940       1.21      fvdl #define		CF284XFIFO      0x000C	/* FIFO Threshold (284x cards) */
    941       1.21      fvdl #define		CFSTERM		0x0004	/* SCSI low byte termination */
    942       1.21      fvdl #define		CFWSTERM	0x0008	/* SCSI high byte termination */
    943       1.21      fvdl #define		CFSPARITY	0x0010	/* SCSI parity */
    944       1.47     perry #define		CF284XSTERM     0x0020	/* SCSI low byte term (284x cards) */
    945       1.33      fvdl #define		CFMULTILUN	0x0020
    946       1.21      fvdl #define		CFRESETB	0x0040	/* reset SCSI bus at boot */
    947       1.33      fvdl #define		CFCLUSTERENB	0x0080	/* Cluster Enable */
    948       1.33      fvdl #define		CFBOOTCHAN	0x0300	/* probe this channel first */
    949       1.33      fvdl #define		CFBOOTCHANSHIFT 8
    950       1.33      fvdl #define		CFSEAUTOTERM	0x0400	/* Ultra2 Perform secondary Auto Term*/
    951       1.33      fvdl #define		CFSELOWTERM	0x0800	/* Ultra2 secondary low term */
    952       1.33      fvdl #define		CFSEHIGHTERM	0x1000	/* Ultra2 secondary high term */
    953       1.33      fvdl #define		CFENABLEDV	0x4000	/* Perform Domain Validation*/
    954       1.21      fvdl 
    955       1.21      fvdl /*
    956       1.33      fvdl  * Bus Release Time, Host Adapter ID
    957       1.21      fvdl  */
    958       1.33      fvdl 	uint16_t brtime_id;		/* word 18 */
    959       1.21      fvdl #define		CFSCSIID	0x000f	/* host adapter SCSI ID */
    960       1.21      fvdl /*		UNUSED		0x00f0	*/
    961       1.21      fvdl #define		CFBRTIME	0xff00	/* bus release time */
    962       1.21      fvdl 
    963       1.21      fvdl /*
    964       1.21      fvdl  * Maximum targets
    965       1.21      fvdl  */
    966       1.47     perry 	uint16_t max_targets;		/* word 19 */
    967       1.21      fvdl #define		CFMAXTARG	0x00ff	/* maximum targets */
    968       1.33      fvdl #define		CFBOOTLUN	0x0f00	/* Lun to boot from */
    969       1.33      fvdl #define		CFBOOTID	0xf000	/* Target to boot from */
    970       1.33      fvdl 	uint16_t res_1[10];		/* words 20-29 */
    971       1.33      fvdl 	uint16_t signature;		/* Signature == 0x250 */
    972       1.33      fvdl #define		CFSIGNATURE	0x250
    973       1.33      fvdl #define		CFSIGNATURE2	0x300
    974       1.33      fvdl 	uint16_t checksum;		/* word 31 */
    975       1.21      fvdl };
    976       1.21      fvdl 
    977       1.33      fvdl /****************************  Message Buffer *********************************/
    978       1.21      fvdl typedef enum {
    979       1.21      fvdl 	MSG_TYPE_NONE			= 0x00,
    980       1.21      fvdl 	MSG_TYPE_INITIATOR_MSGOUT	= 0x01,
    981       1.21      fvdl 	MSG_TYPE_INITIATOR_MSGIN	= 0x02,
    982       1.21      fvdl 	MSG_TYPE_TARGET_MSGOUT		= 0x03,
    983       1.21      fvdl 	MSG_TYPE_TARGET_MSGIN		= 0x04
    984       1.21      fvdl } ahc_msg_type;
    985       1.21      fvdl 
    986       1.33      fvdl typedef enum {
    987       1.33      fvdl 	MSGLOOP_IN_PROG,
    988       1.33      fvdl 	MSGLOOP_MSGCOMPLETE,
    989       1.33      fvdl 	MSGLOOP_TERMINATED
    990       1.33      fvdl } msg_loop_stat;
    991       1.21      fvdl 
    992       1.33      fvdl /*********************** Software Configuration Structure *********************/
    993       1.33      fvdl TAILQ_HEAD(scb_tailq, scb);
    994       1.21      fvdl 
    995       1.33      fvdl struct ahc_suspend_channel_state {
    996       1.33      fvdl 	uint8_t	scsiseq;
    997       1.33      fvdl 	uint8_t	sxfrctl0;
    998       1.33      fvdl 	uint8_t	sxfrctl1;
    999       1.33      fvdl 	uint8_t	simode0;
   1000       1.33      fvdl 	uint8_t	simode1;
   1001       1.33      fvdl 	uint8_t	seltimer;
   1002       1.33      fvdl 	uint8_t	seqctl;
   1003       1.33      fvdl };
   1004       1.21      fvdl 
   1005       1.33      fvdl struct ahc_suspend_state {
   1006       1.33      fvdl 	struct	ahc_suspend_channel_state channel[2];
   1007       1.33      fvdl 	uint8_t	optionmode;
   1008       1.33      fvdl 	uint8_t	dscommand0;
   1009       1.33      fvdl 	uint8_t	dspcistatus;
   1010       1.33      fvdl 	/* hsmailbox */
   1011       1.33      fvdl 	uint8_t	crccontrol1;
   1012       1.33      fvdl 	uint8_t	scbbaddr;
   1013       1.33      fvdl 	/* Host and sequencer SCB counts */
   1014       1.33      fvdl 	uint8_t	dff_thrsh;
   1015       1.33      fvdl 	uint8_t	*scratch_ram;
   1016       1.33      fvdl 	uint8_t	*btt;
   1017        1.1   mycroft };
   1018        1.1   mycroft 
   1019       1.33      fvdl typedef void (*ahc_bus_intr_t)(struct ahc_softc *);
   1020       1.33      fvdl typedef void ahc_callback_t (void *);
   1021       1.33      fvdl 
   1022       1.21      fvdl struct ahc_softc {
   1023       1.47     perry 	struct device 		  sc_dev;
   1024       1.33      fvdl 
   1025       1.33      fvdl 	struct scsipi_channel	  sc_channel;
   1026       1.33      fvdl 	struct scsipi_channel 	  sc_channel_b;
   1027       1.33      fvdl 	struct device *		  sc_child;
   1028       1.33      fvdl 	struct device *		  sc_child_b;
   1029       1.33      fvdl 	struct scsipi_adapter	  sc_adapter;
   1030       1.33      fvdl 
   1031       1.33      fvdl 	bus_space_tag_t           tag;
   1032       1.33      fvdl 	bus_space_handle_t        bsh;
   1033       1.21      fvdl 
   1034       1.33      fvdl #ifndef __linux__
   1035       1.33      fvdl 	bus_dma_tag_t		  buffer_dmat;   /* dmat for buffer I/O */
   1036       1.33      fvdl #endif
   1037       1.33      fvdl 	struct scb_data		 *scb_data;
   1038       1.33      fvdl 
   1039       1.33      fvdl 	struct scb		 *next_queued_scb;
   1040       1.33      fvdl 
   1041       1.33      fvdl 	/*
   1042       1.33      fvdl 	 * SCBs that have been sent to the controller
   1043       1.33      fvdl 	 */
   1044       1.33      fvdl 	LIST_HEAD(, scb)	  pending_scbs;
   1045       1.21      fvdl 
   1046       1.33      fvdl 	/*
   1047       1.33      fvdl 	 * Counting lock for deferring the release of additional
   1048       1.33      fvdl 	 * untagged transactions from the untagged_queues.  When
   1049       1.33      fvdl 	 * the lock is decremented to 0, all queues in the
   1050       1.33      fvdl 	 * untagged_queues array are run.
   1051       1.33      fvdl 	 */
   1052       1.33      fvdl 	u_int			  untagged_queue_lock;
   1053       1.21      fvdl 
   1054       1.33      fvdl 	/*
   1055       1.33      fvdl 	 * Per-target queue of untagged-transactions.  The
   1056       1.33      fvdl 	 * transaction at the head of the queue is the
   1057       1.33      fvdl 	 * currently pending untagged transaction for the
   1058       1.33      fvdl 	 * target.  The driver only allows a single untagged
   1059       1.33      fvdl 	 * transaction per target.
   1060       1.33      fvdl 	 */
   1061       1.33      fvdl 	struct scb_tailq	  untagged_queues[AHC_NUM_TARGETS];
   1062       1.21      fvdl 
   1063       1.33      fvdl 	/*
   1064       1.33      fvdl 	 * Platform specific data.
   1065       1.33      fvdl 	 */
   1066       1.33      fvdl 	struct ahc_platform_data *platform_data;
   1067       1.30    ichiro 
   1068       1.21      fvdl 	/*
   1069       1.33      fvdl 	 * Platform specific device information.
   1070       1.21      fvdl 	 */
   1071       1.33      fvdl 	/* ahc_dev_softc_t		  dev_softc; */
   1072       1.33      fvdl 
   1073       1.33      fvdl 	/*
   1074       1.33      fvdl 	 * Bus specific device information.
   1075       1.33      fvdl 	 */
   1076       1.33      fvdl 	ahc_bus_intr_t		  bus_intr;
   1077       1.21      fvdl 
   1078       1.21      fvdl 	/*
   1079       1.21      fvdl 	 * Target mode related state kept on a per enabled lun basis.
   1080       1.21      fvdl 	 * Targets that are not enabled will have null entries.
   1081       1.21      fvdl 	 * As an initiator, we keep one target entry for our initiator
   1082       1.21      fvdl 	 * ID to store our sync/wide transfer settings.
   1083       1.21      fvdl 	 */
   1084       1.33      fvdl 	struct ahc_tmode_tstate  *enabled_targets[AHC_NUM_TARGETS];
   1085       1.33      fvdl 
   1086       1.33      fvdl 	char inited_target[AHC_NUM_TARGETS];
   1087       1.21      fvdl 
   1088       1.21      fvdl 	/*
   1089       1.21      fvdl 	 * The black hole device responsible for handling requests for
   1090       1.21      fvdl 	 * disabled luns on enabled targets.
   1091       1.21      fvdl 	 */
   1092       1.33      fvdl 	struct ahc_tmode_lstate  *black_hole;
   1093       1.21      fvdl 
   1094       1.21      fvdl 	/*
   1095       1.21      fvdl 	 * Device instance currently on the bus awaiting a continue TIO
   1096       1.43       wiz 	 * for a command that was not given the disconnect priviledge.
   1097       1.21      fvdl 	 */
   1098       1.33      fvdl 	struct ahc_tmode_lstate  *pending_device;
   1099       1.21      fvdl 
   1100       1.21      fvdl 	/*
   1101       1.21      fvdl 	 * Card characteristics
   1102       1.21      fvdl 	 */
   1103       1.33      fvdl 	ahc_chip		  chip;
   1104       1.33      fvdl 	ahc_feature		  features;
   1105       1.33      fvdl 	ahc_bug			  bugs;
   1106       1.33      fvdl 	ahc_flag		  flags;
   1107       1.33      fvdl 	struct seeprom_config	 *seep_config;
   1108       1.21      fvdl 
   1109       1.21      fvdl 	/* Values to store in the SEQCTL register for pause and unpause */
   1110       1.33      fvdl 	uint8_t			  unpause;
   1111       1.33      fvdl 	uint8_t			  pause;
   1112       1.21      fvdl 
   1113       1.21      fvdl 	/* Command Queues */
   1114       1.33      fvdl 	uint8_t			  qoutfifonext;
   1115       1.33      fvdl 	uint8_t			  qinfifonext;
   1116       1.33      fvdl 	uint8_t			 *qoutfifo;
   1117       1.33      fvdl 	uint8_t			 *qinfifo;
   1118       1.33      fvdl 
   1119       1.33      fvdl 	/* Critical Section Data */
   1120       1.33      fvdl 	struct cs		 *critical_sections;
   1121       1.33      fvdl 	u_int			  num_critical_sections;
   1122       1.21      fvdl 
   1123       1.33      fvdl 	/* Links for chaining softcs */
   1124       1.33      fvdl 	TAILQ_ENTRY(ahc_softc)	  links;
   1125       1.21      fvdl 
   1126       1.21      fvdl 	/* Channel Names ('A', 'B', etc.) */
   1127       1.33      fvdl 	char			  channel;
   1128       1.21      fvdl 
   1129       1.21      fvdl 	/* Initiator Bus ID */
   1130       1.33      fvdl 	uint8_t			  our_id;
   1131       1.33      fvdl 	uint8_t			  our_id_b;
   1132       1.21      fvdl 
   1133       1.21      fvdl 	/*
   1134       1.33      fvdl 	 * PCI error detection.
   1135       1.21      fvdl 	 */
   1136       1.33      fvdl 	int			  unsolicited_ints;
   1137       1.21      fvdl 
   1138       1.21      fvdl 	/*
   1139       1.21      fvdl 	 * Target incoming command FIFO.
   1140       1.21      fvdl 	 */
   1141       1.33      fvdl 	struct target_cmd	 *targetcmds;
   1142       1.33      fvdl 	uint8_t			  tqinfifonext;
   1143       1.21      fvdl 
   1144       1.21      fvdl 	/*
   1145       1.21      fvdl 	 * Incoming and outgoing message handling.
   1146       1.21      fvdl 	 */
   1147       1.33      fvdl 	uint8_t			  send_msg_perror;
   1148       1.33      fvdl 	ahc_msg_type		  msg_type;
   1149       1.33      fvdl 	uint8_t			  msgout_buf[12];/* Message we are sending */
   1150       1.33      fvdl 	uint8_t			  msgin_buf[12];/* Message we are receiving */
   1151       1.33      fvdl 	u_int			  msgout_len;	/* Length of message to send */
   1152       1.33      fvdl 	u_int			  msgout_index;	/* Current index in msgout */
   1153       1.33      fvdl 	u_int			  msgin_index;	/* Current index in msgin */
   1154       1.33      fvdl 
   1155       1.33      fvdl 	/* Interrupt routine */
   1156       1.33      fvdl 	void 			 *ih;
   1157       1.33      fvdl 
   1158       1.33      fvdl 	/*
   1159       1.33      fvdl 	 * Mapping information for data structures shared
   1160       1.33      fvdl 	 * between the sequencer and kernel.
   1161       1.33      fvdl 	 */
   1162       1.33      fvdl 	bus_dma_tag_t		  parent_dmat;
   1163       1.33      fvdl 	bus_dmamap_t		  shared_data_dmamap;
   1164       1.33      fvdl 	bus_addr_t		  shared_data_busaddr;
   1165       1.33      fvdl 
   1166       1.33      fvdl 	bus_dma_segment_t	  shared_data_seg;
   1167       1.33      fvdl 	int			  shared_data_nseg;
   1168       1.33      fvdl 	int			  shared_data_size;
   1169       1.33      fvdl 	int			  sc_dmaflags;
   1170       1.33      fvdl 
   1171       1.33      fvdl 	/*
   1172       1.33      fvdl 	 * Bus address of the one byte buffer used to
   1173       1.33      fvdl 	 * work-around a DMA bug for chips <= aic7880
   1174       1.33      fvdl 	 * in target mode.
   1175       1.33      fvdl 	 */
   1176       1.33      fvdl 	bus_addr_t		  dma_bug_buf;
   1177       1.33      fvdl 
   1178       1.33      fvdl 	/* Information saved through suspend/resume cycles */
   1179       1.33      fvdl 	struct ahc_suspend_state  suspend_state;
   1180       1.21      fvdl 
   1181       1.21      fvdl 	/* Number of enabled target mode device on this card */
   1182       1.33      fvdl 	u_int			  enabled_luns;
   1183       1.21      fvdl 
   1184       1.21      fvdl 	/* Initialization level of this data structure */
   1185       1.33      fvdl 	u_int			  init_level;
   1186       1.21      fvdl 
   1187       1.33      fvdl 	/* PCI cacheline size. */
   1188       1.33      fvdl 	u_int			  pci_cachesize;
   1189       1.21      fvdl 
   1190       1.33      fvdl 	u_int			  stack_size;
   1191       1.21      fvdl 
   1192       1.33      fvdl 	/* Per-Unit descriptive information */
   1193       1.33      fvdl 	const char		 *description;
   1194  1.53.40.1       mjf 	const char		 *name;
   1195       1.33      fvdl 	int			  unit;
   1196        1.4   mycroft 
   1197       1.33      fvdl 	/* Selection Timer settings */
   1198       1.33      fvdl 	int			  seltime;
   1199       1.33      fvdl 	int			  seltime_b;
   1200       1.21      fvdl 
   1201       1.33      fvdl 	uint16_t	 	  user_discenable;/* Disconnection allowed  */
   1202       1.33      fvdl 	uint16_t		  user_tagenable;/* Tagged Queuing allowed */
   1203        1.4   mycroft 
   1204       1.33      fvdl 	struct ahc_pci_busdata 	  *bd;
   1205       1.33      fvdl };
   1206       1.21      fvdl 
   1207       1.33      fvdl TAILQ_HEAD(ahc_softc_tailq, ahc_softc);
   1208       1.33      fvdl extern struct ahc_softc_tailq ahc_tailq;
   1209       1.21      fvdl 
   1210       1.33      fvdl /************************ Active Device Information ***************************/
   1211       1.33      fvdl typedef enum {
   1212       1.33      fvdl 	ROLE_UNKNOWN,
   1213       1.33      fvdl 	ROLE_INITIATOR,
   1214       1.33      fvdl 	ROLE_TARGET
   1215       1.33      fvdl } role_t;
   1216       1.33      fvdl 
   1217       1.33      fvdl struct ahc_devinfo {
   1218       1.33      fvdl 	int	 our_scsiid;
   1219       1.33      fvdl 	int	 target_offset;
   1220       1.33      fvdl 	uint16_t target_mask;
   1221       1.33      fvdl 	u_int	 target;
   1222       1.33      fvdl 	u_int	 lun;
   1223       1.33      fvdl 	char	 channel;
   1224       1.33      fvdl 	role_t	 role;		/*
   1225       1.33      fvdl 				 * Only guaranteed to be correct if not
   1226       1.33      fvdl 				 * in the busfree state.
   1227       1.33      fvdl 				 */
   1228       1.33      fvdl };
   1229        1.4   mycroft 
   1230       1.33      fvdl /****************************** PCI Structures ********************************/
   1231       1.33      fvdl typedef int (ahc_device_setup_t)(struct ahc_softc *);
   1232        1.4   mycroft 
   1233       1.33      fvdl struct ahc_pci_identity {
   1234       1.33      fvdl 	uint64_t		 full_id;
   1235       1.33      fvdl 	uint64_t		 id_mask;
   1236       1.48  christos 	const char		*name;
   1237       1.33      fvdl 	ahc_device_setup_t	*setup;
   1238       1.33      fvdl };
   1239        1.4   mycroft 
   1240       1.33      fvdl /***************************** VL/EISA Declarations ***************************/
   1241       1.33      fvdl struct aic7770_identity {
   1242       1.33      fvdl 	uint32_t		 full_id;
   1243       1.33      fvdl 	uint32_t		 id_mask;
   1244       1.33      fvdl 	char			*name;
   1245       1.33      fvdl 	ahc_device_setup_t	*setup;
   1246       1.33      fvdl };
   1247       1.33      fvdl extern struct aic7770_identity aic7770_ident_table [];
   1248       1.33      fvdl extern const int ahc_num_aic7770_devs;
   1249       1.33      fvdl 
   1250       1.33      fvdl #define AHC_EISA_SLOT_OFFSET	0xc00
   1251       1.33      fvdl #define AHC_EISA_IOSIZE		0x100
   1252        1.4   mycroft 
   1253       1.33      fvdl /*************************** Function Declarations ****************************/
   1254       1.33      fvdl /******************************************************************************/
   1255       1.40    itojun u_int			ahc_index_busy_tcl(struct ahc_softc *, u_int);
   1256       1.40    itojun void			ahc_unbusy_tcl(struct ahc_softc *, u_int);
   1257       1.40    itojun void			ahc_busy_tcl(struct ahc_softc *, u_int, u_int);
   1258       1.33      fvdl 
   1259       1.33      fvdl /*************************** EISA/VL Front End ********************************/
   1260       1.33      fvdl struct aic7770_identity *aic7770_find_device(uint32_t);
   1261       1.40    itojun int			 aic7770_config(struct ahc_softc *,
   1262       1.40    itojun 			    struct aic7770_identity *, u_int);
   1263       1.33      fvdl 
   1264       1.33      fvdl /************************** SCB and SCB queue management **********************/
   1265       1.33      fvdl int		ahc_probe_scbs(struct ahc_softc *);
   1266       1.40    itojun void		ahc_run_untagged_queues(struct ahc_softc *);
   1267       1.40    itojun void		ahc_run_untagged_queue(struct ahc_softc *, struct scb_tailq *);
   1268       1.40    itojun void		ahc_qinfifo_requeue_tail(struct ahc_softc *, struct scb *);
   1269       1.40    itojun int		ahc_match_scb(struct ahc_softc *, struct scb *,
   1270       1.40    itojun 		    int, char, int, u_int, role_t);
   1271       1.33      fvdl 
   1272       1.33      fvdl /****************************** Initialization ********************************/
   1273       1.33      fvdl int			 ahc_softc_init(struct ahc_softc *);
   1274       1.45    itojun void			 ahc_controller_info(struct ahc_softc *, char *, size_t);
   1275       1.40    itojun int			 ahc_init(struct ahc_softc *);
   1276       1.40    itojun void			 ahc_intr_enable(struct ahc_softc *, int);
   1277       1.40    itojun void			 ahc_pause_and_flushwork(struct ahc_softc *);
   1278       1.47     perry int			 ahc_suspend(struct ahc_softc *);
   1279       1.40    itojun int			 ahc_resume(struct ahc_softc *);
   1280       1.33      fvdl void			 ahc_softc_insert(struct ahc_softc *);
   1281       1.40    itojun struct ahc_softc	*ahc_find_softc(struct ahc_softc *);
   1282       1.33      fvdl void			 ahc_set_unit(struct ahc_softc *, int);
   1283  1.53.40.1       mjf void			 ahc_set_name(struct ahc_softc *, const char *);
   1284       1.50    bouyer int			 ahc_alloc_scbs(struct ahc_softc *);
   1285       1.40    itojun void			 ahc_free(struct ahc_softc *);
   1286       1.40    itojun int			 ahc_reset(struct ahc_softc *);
   1287       1.40    itojun void			 ahc_shutdown(void *);
   1288       1.33      fvdl 
   1289       1.33      fvdl /*************************** Interrupt Services *******************************/
   1290       1.40    itojun void			ahc_clear_intstat(struct ahc_softc *);
   1291       1.40    itojun void			ahc_run_qoutfifo(struct ahc_softc *);
   1292       1.33      fvdl #ifdef AHC_TARGET_MODE
   1293       1.40    itojun void			ahc_run_tqinfifo(struct ahc_softc *, int);
   1294       1.33      fvdl #endif
   1295       1.40    itojun void			ahc_handle_brkadrint(struct ahc_softc *);
   1296       1.40    itojun void			ahc_handle_seqint(struct ahc_softc *, u_int);
   1297       1.40    itojun void			ahc_handle_scsiint(struct ahc_softc *, u_int);
   1298       1.40    itojun void			ahc_clear_critical_section(struct ahc_softc *);
   1299       1.20   thorpej 
   1300       1.33      fvdl /***************************** Error Recovery *********************************/
   1301       1.33      fvdl typedef enum {
   1302       1.33      fvdl 	SEARCH_COMPLETE,
   1303       1.33      fvdl 	SEARCH_COUNT,
   1304       1.33      fvdl 	SEARCH_REMOVE
   1305       1.33      fvdl } ahc_search_action;
   1306       1.40    itojun int			ahc_search_qinfifo(struct ahc_softc *, int, char,
   1307       1.40    itojun 			    int, u_int, role_t, uint32_t, ahc_search_action);
   1308       1.40    itojun int			ahc_search_untagged_queues(struct ahc_softc *,
   1309       1.40    itojun 			    struct scsipi_xfer *, int, char, int, uint32_t,
   1310       1.40    itojun 			    ahc_search_action);
   1311       1.40    itojun int			ahc_search_disc_list(struct ahc_softc *, int, char,
   1312       1.40    itojun 			    int, u_int, int, int, int);
   1313       1.40    itojun void			ahc_freeze_devq(struct ahc_softc *, struct scb *);
   1314       1.40    itojun int			ahc_reset_channel(struct ahc_softc *, char, int);
   1315       1.40    itojun int			ahc_abort_scbs(struct ahc_softc *, int, char, int,
   1316       1.40    itojun 			    u_int, role_t, uint32_t);
   1317       1.40    itojun void			ahc_restart(struct ahc_softc *);
   1318       1.40    itojun void			ahc_calc_residual(struct ahc_softc *, struct scb *);
   1319       1.33      fvdl /*************************** Utility Functions ********************************/
   1320       1.33      fvdl struct ahc_phase_table_entry*
   1321       1.40    itojun 			ahc_lookup_phase_entry(int);
   1322       1.40    itojun void			ahc_compile_devinfo(struct ahc_devinfo *, u_int, u_int,
   1323       1.40    itojun 			    u_int, char, role_t);
   1324       1.33      fvdl /************************** Transfer Negotiation ******************************/
   1325       1.40    itojun struct ahc_syncrate*	ahc_find_syncrate(struct ahc_softc *, u_int *,
   1326       1.40    itojun 			    u_int *, u_int);
   1327       1.40    itojun u_int			ahc_find_period(struct ahc_softc *, u_int, u_int);
   1328       1.40    itojun void			ahc_validate_offset(struct ahc_softc *,
   1329       1.40    itojun 			    struct ahc_initiator_tinfo *, struct ahc_syncrate *,
   1330       1.40    itojun 			    u_int *, int, role_t);
   1331       1.40    itojun void			ahc_validate_width(struct ahc_softc *,
   1332       1.40    itojun 			    struct ahc_initiator_tinfo *, u_int *, role_t);
   1333       1.33      fvdl /*
   1334       1.33      fvdl  * Negotiation types.  These are used to qualify if we should renegotiate
   1335       1.33      fvdl  * even if our goal and current transport parameters are identical.
   1336       1.33      fvdl  */
   1337       1.33      fvdl typedef enum {
   1338       1.33      fvdl 	AHC_NEG_TO_GOAL,	/* Renegotiate only if goal and curr differ. */
   1339       1.33      fvdl 	AHC_NEG_IF_NON_ASYNC,	/* Renegotiate so long as goal is non-async. */
   1340       1.33      fvdl 	AHC_NEG_ALWAYS		/* Renegotiat even if goal is async. */
   1341       1.33      fvdl } ahc_neg_type;
   1342       1.40    itojun int			ahc_update_neg_request(struct ahc_softc *,
   1343       1.40    itojun 			    struct ahc_devinfo *, struct ahc_tmode_tstate *,
   1344       1.40    itojun 			    struct ahc_initiator_tinfo*, ahc_neg_type);
   1345       1.40    itojun void			ahc_set_width(struct ahc_softc *, struct ahc_devinfo *,
   1346       1.40    itojun 			    u_int, u_int, int);
   1347       1.40    itojun void			ahc_set_syncrate(struct ahc_softc *,
   1348       1.40    itojun 			    struct ahc_devinfo *, struct ahc_syncrate *,
   1349       1.40    itojun 			    u_int, u_int, u_int, u_int, int);
   1350       1.33      fvdl typedef enum {
   1351       1.33      fvdl 	AHC_QUEUE_NONE,
   1352       1.33      fvdl 	AHC_QUEUE_BASIC,
   1353       1.33      fvdl 	AHC_QUEUE_TAGGED
   1354       1.33      fvdl } ahc_queue_alg;
   1355       1.33      fvdl 
   1356       1.40    itojun void			ahc_set_tags(struct ahc_softc *, struct ahc_devinfo *,
   1357       1.40    itojun 			    ahc_queue_alg);
   1358       1.33      fvdl 
   1359       1.33      fvdl /**************************** Target Mode *************************************/
   1360       1.33      fvdl #ifdef AHC_TARGET_MODE
   1361       1.33      fvdl void		ahc_send_lstate_events(struct ahc_softc *,
   1362       1.40    itojun 		    struct ahc_tmode_lstate *);
   1363       1.40    itojun void		ahc_handle_en_lun(struct ahc_softc *, struct scsipi_xfer *);
   1364       1.40    itojun cam_status	ahc_find_tmode_devs(struct ahc_softc *,
   1365       1.40    itojun 		    struct ahc_tmode_tstate **, struct ahc_tmode_lstate **,
   1366       1.40    itojun 		    int);
   1367       1.33      fvdl #ifndef AHC_TMODE_ENABLE
   1368       1.33      fvdl #define AHC_TMODE_ENABLE 0
   1369       1.33      fvdl #endif
   1370       1.33      fvdl #endif
   1371       1.33      fvdl /******************************* Debug ***************************************/
   1372       1.33      fvdl #ifdef AHC_DEBUG
   1373       1.33      fvdl extern uint32_t ahc_debug;
   1374       1.33      fvdl #define	AHC_SHOW_MISC		0x0001
   1375       1.33      fvdl #define	AHC_SHOW_SENSE		0x0002
   1376       1.33      fvdl #define AHC_DUMP_SEEPROM	0x0004
   1377       1.33      fvdl #define AHC_SHOW_TERMCTL	0x0008
   1378       1.33      fvdl #define AHC_SHOW_MEMORY		0x0010
   1379       1.33      fvdl #define AHC_SHOW_MESSAGES	0x0020
   1380       1.33      fvdl #define	AHC_SHOW_DV		0x0040
   1381       1.33      fvdl #define AHC_SHOW_SELTO		0x0080
   1382       1.33      fvdl #define AHC_SHOW_QFULL		0x0200
   1383       1.33      fvdl #define AHC_SHOW_QUEUE		0x0400
   1384       1.33      fvdl #define AHC_SHOW_TQIN		0x0800
   1385       1.33      fvdl #define AHC_SHOW_MASKED_ERRORS	0x1000
   1386       1.33      fvdl #define AHC_DEBUG_SEQUENCER	0x2000
   1387       1.33      fvdl #endif
   1388       1.40    itojun void			ahc_print_scb(struct scb *);
   1389       1.40    itojun void			ahc_print_devinfo(struct ahc_softc *,
   1390       1.40    itojun 			    struct ahc_devinfo *);
   1391       1.40    itojun void			ahc_dump_card_state(struct ahc_softc *);
   1392       1.40    itojun int			ahc_print_register(ahc_reg_parse_entry_t *, u_int,
   1393       1.40    itojun 			    const char *, u_int, u_int, u_int *, u_int);
   1394       1.33      fvdl /******************************* SEEPROM *************************************/
   1395       1.40    itojun int		ahc_acquire_seeprom(struct ahc_softc *,
   1396       1.40    itojun 		    struct seeprom_descriptor *);
   1397       1.40    itojun void		ahc_release_seeprom(struct seeprom_descriptor *);
   1398        1.1   mycroft 
   1399       1.40    itojun void		ahc_check_extport(struct ahc_softc *, u_int *);
   1400       1.33      fvdl #endif /* _AIC7XXXVAR_H_ */
   1401