xref: /freebsd/sys/dev/aic7xxx/aic7xxx.h (revision 65971073d935e8314bff8bca26d1445e9e336fce)
1098ca2bdSWarner Losh /*-
2717d4247SJustin T. Gibbs  * Core definitions and data structures shareable across OS platforms.
33bafc9d4SJustin T. Gibbs  *
4718cf2ccSPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
5718cf2ccSPedro F. Giffuni  *
664a3876fSJustin T. Gibbs  * Copyright (c) 1994-2001 Justin T. Gibbs.
78f214efcSJustin T. Gibbs  * Copyright (c) 2000-2001 Adaptec Inc.
83bafc9d4SJustin T. Gibbs  * All rights reserved.
93bafc9d4SJustin T. Gibbs  *
103bafc9d4SJustin T. Gibbs  * Redistribution and use in source and binary forms, with or without
113bafc9d4SJustin T. Gibbs  * modification, are permitted provided that the following conditions
123bafc9d4SJustin T. Gibbs  * are met:
133bafc9d4SJustin T. Gibbs  * 1. Redistributions of source code must retain the above copyright
143bafc9d4SJustin T. Gibbs  *    notice, this list of conditions, and the following disclaimer,
1541c47eeeSJustin T. Gibbs  *    without modification.
168f214efcSJustin T. Gibbs  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
178f214efcSJustin T. Gibbs  *    substantially similar to the "NO WARRANTY" disclaimer below
188f214efcSJustin T. Gibbs  *    ("Disclaimer") and any redistribution must be conditioned upon
198f214efcSJustin T. Gibbs  *    including a substantially similar Disclaimer requirement for further
208f214efcSJustin T. Gibbs  *    binary redistribution.
218f214efcSJustin T. Gibbs  * 3. Neither the names of the above-listed copyright holders nor the names
228f214efcSJustin T. Gibbs  *    of any contributors may be used to endorse or promote products derived
238f214efcSJustin T. Gibbs  *    from this software without specific prior written permission.
243bafc9d4SJustin T. Gibbs  *
2541c47eeeSJustin T. Gibbs  * Alternatively, this software may be distributed under the terms of the
268f214efcSJustin T. Gibbs  * GNU General Public License ("GPL") version 2 as published by the Free
278f214efcSJustin T. Gibbs  * Software Foundation.
283bafc9d4SJustin T. Gibbs  *
298f214efcSJustin T. Gibbs  * NO WARRANTY
308f214efcSJustin T. Gibbs  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
318f214efcSJustin T. Gibbs  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
328f214efcSJustin T. Gibbs  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
338f214efcSJustin T. Gibbs  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
348f214efcSJustin T. Gibbs  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
353bafc9d4SJustin T. Gibbs  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
363bafc9d4SJustin T. Gibbs  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
378f214efcSJustin T. Gibbs  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
388f214efcSJustin T. Gibbs  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
398f214efcSJustin T. Gibbs  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
408f214efcSJustin T. Gibbs  * POSSIBILITY OF SUCH DAMAGES.
413bafc9d4SJustin T. Gibbs  *
42b3b25f2cSJustin T. Gibbs  * $Id: //depot/aic7xxx/aic7xxx/aic7xxx.h#85 $
433bafc9d4SJustin T. Gibbs  */
443bafc9d4SJustin T. Gibbs 
453bafc9d4SJustin T. Gibbs #ifndef _AIC7XXX_H_
463bafc9d4SJustin T. Gibbs #define _AIC7XXX_H_
473bafc9d4SJustin T. Gibbs 
48717d4247SJustin T. Gibbs /* Register Definitions */
49aa6dfd9dSJustin T. Gibbs #include "aic7xxx_reg.h"
503bafc9d4SJustin T. Gibbs 
51717d4247SJustin T. Gibbs /************************* Forward Declarations *******************************/
52717d4247SJustin T. Gibbs struct ahc_platform_data;
53717d4247SJustin T. Gibbs struct scb_platform_data;
548f214efcSJustin T. Gibbs struct seeprom_descriptor;
553bafc9d4SJustin T. Gibbs 
56717d4247SJustin T. Gibbs /****************************** Useful Macros *********************************/
5700fa2b1fSJustin T. Gibbs #ifndef MAX
5800fa2b1fSJustin T. Gibbs #define MAX(a,b) (((a) > (b)) ? (a) : (b))
5900fa2b1fSJustin T. Gibbs #endif
6000fa2b1fSJustin T. Gibbs 
6100fa2b1fSJustin T. Gibbs #ifndef MIN
6200fa2b1fSJustin T. Gibbs #define MIN(a,b) (((a) < (b)) ? (a) : (b))
6300fa2b1fSJustin T. Gibbs #endif
6400fa2b1fSJustin T. Gibbs 
65717d4247SJustin T. Gibbs #ifndef TRUE
66717d4247SJustin T. Gibbs #define TRUE 1
67717d4247SJustin T. Gibbs #endif
68717d4247SJustin T. Gibbs #ifndef FALSE
69717d4247SJustin T. Gibbs #define FALSE 0
70717d4247SJustin T. Gibbs #endif
71717d4247SJustin T. Gibbs 
72717d4247SJustin T. Gibbs #define NUM_ELEMENTS(array) (sizeof(array) / sizeof(*array))
73717d4247SJustin T. Gibbs 
74717d4247SJustin T. Gibbs #define ALL_CHANNELS '\0'
75717d4247SJustin T. Gibbs #define ALL_TARGETS_MASK 0xFFFF
76717d4247SJustin T. Gibbs #define INITIATOR_WILDCARD	(~0)
77717d4247SJustin T. Gibbs 
78717d4247SJustin T. Gibbs #define SCSIID_TARGET(ahc, scsiid) \
79717d4247SJustin T. Gibbs 	(((scsiid) & ((((ahc)->features & AHC_TWIN) != 0) ? TWIN_TID : TID)) \
80717d4247SJustin T. Gibbs 	>> TID_SHIFT)
81717d4247SJustin T. Gibbs #define SCSIID_OUR_ID(scsiid) \
82717d4247SJustin T. Gibbs 	((scsiid) & OID)
83717d4247SJustin T. Gibbs #define SCSIID_CHANNEL(ahc, scsiid) \
84717d4247SJustin T. Gibbs 	((((ahc)->features & AHC_TWIN) != 0) \
85717d4247SJustin T. Gibbs         ? ((((scsiid) & TWIN_CHNLB) != 0) ? 'B' : 'A') \
86717d4247SJustin T. Gibbs        : 'A')
87717d4247SJustin T. Gibbs #define	SCB_IS_SCSIBUS_B(ahc, scb) \
88717d4247SJustin T. Gibbs 	(SCSIID_CHANNEL(ahc, (scb)->hscb->scsiid) == 'B')
89717d4247SJustin T. Gibbs #define	SCB_GET_OUR_ID(scb) \
90717d4247SJustin T. Gibbs 	SCSIID_OUR_ID((scb)->hscb->scsiid)
91717d4247SJustin T. Gibbs #define	SCB_GET_TARGET(ahc, scb) \
92717d4247SJustin T. Gibbs 	SCSIID_TARGET((ahc), (scb)->hscb->scsiid)
93717d4247SJustin T. Gibbs #define	SCB_GET_CHANNEL(ahc, scb) \
94717d4247SJustin T. Gibbs 	SCSIID_CHANNEL(ahc, (scb)->hscb->scsiid)
95717d4247SJustin T. Gibbs #define	SCB_GET_LUN(scb) \
9692931c12SJustin T. Gibbs 	((scb)->hscb->lun & LID)
97717d4247SJustin T. Gibbs #define SCB_GET_TARGET_OFFSET(ahc, scb)	\
98717d4247SJustin T. Gibbs 	(SCB_GET_TARGET(ahc, scb) + (SCB_IS_SCSIBUS_B(ahc, scb) ? 8 : 0))
99717d4247SJustin T. Gibbs #define SCB_GET_TARGET_MASK(ahc, scb) \
100717d4247SJustin T. Gibbs 	(0x01 << (SCB_GET_TARGET_OFFSET(ahc, scb)))
10170b41139SJustin T. Gibbs #ifdef AHC_DEBUG
10270b41139SJustin T. Gibbs #define SCB_IS_SILENT(scb)					\
10370b41139SJustin T. Gibbs 	((ahc_debug & AHC_SHOW_MASKED_ERRORS) == 0		\
10470b41139SJustin T. Gibbs       && (((scb)->flags & SCB_SILENT) != 0))
10570b41139SJustin T. Gibbs #else
10670b41139SJustin T. Gibbs #define SCB_IS_SILENT(scb)					\
10770b41139SJustin T. Gibbs 	(((scb)->flags & SCB_SILENT) != 0)
10870b41139SJustin T. Gibbs #endif
109717d4247SJustin T. Gibbs #define TCL_TARGET_OFFSET(tcl) \
110717d4247SJustin T. Gibbs 	((((tcl) >> 4) & TID) >> 4)
111717d4247SJustin T. Gibbs #define TCL_LUN(tcl) \
112717d4247SJustin T. Gibbs 	(tcl & (AHC_NUM_LUNS - 1))
113717d4247SJustin T. Gibbs #define BUILD_TCL(scsiid, lun) \
114717d4247SJustin T. Gibbs 	((lun) | (((scsiid) & TID) << 4))
115717d4247SJustin T. Gibbs 
11672df3c56SJustin T. Gibbs #ifndef	AHC_TARGET_MODE
11772df3c56SJustin T. Gibbs #undef	AHC_TMODE_ENABLE
11872df3c56SJustin T. Gibbs #define	AHC_TMODE_ENABLE 0
11972df3c56SJustin T. Gibbs #endif
12072df3c56SJustin T. Gibbs 
121717d4247SJustin T. Gibbs /**************************** Driver Constants ********************************/
12200fa2b1fSJustin T. Gibbs /*
123aa6dfd9dSJustin T. Gibbs  * The maximum number of supported targets.
124aa6dfd9dSJustin T. Gibbs  */
125aa6dfd9dSJustin T. Gibbs #define AHC_NUM_TARGETS 16
126aa6dfd9dSJustin T. Gibbs 
127aa6dfd9dSJustin T. Gibbs /*
128aa6dfd9dSJustin T. Gibbs  * The maximum number of supported luns.
12956a7c4a8SJustin T. Gibbs  * The identify message only supports 64 luns in SPI3.
13056a7c4a8SJustin T. Gibbs  * You can have 2^64 luns when information unit transfers are enabled,
13156a7c4a8SJustin T. Gibbs  * but it is doubtful this driver will ever support IUTs.
132aa6dfd9dSJustin T. Gibbs  */
13356a7c4a8SJustin T. Gibbs #define AHC_NUM_LUNS 64
134aa6dfd9dSJustin T. Gibbs 
135aa6dfd9dSJustin T. Gibbs /*
13600fa2b1fSJustin T. Gibbs  * The maximum transfer per S/G segment.
1373bafc9d4SJustin T. Gibbs  */
13800fa2b1fSJustin T. Gibbs #define AHC_MAXTRANSFER_SIZE	 0x00ffffff	/* limited by 24bit counter */
13900fa2b1fSJustin T. Gibbs 
14000fa2b1fSJustin T. Gibbs /*
141a5847d5cSJustin T. Gibbs  * The maximum amount of SCB storage in hardware on a controller.
142a5847d5cSJustin T. Gibbs  * This value represents an upper bound.  Controllers vary in the number
143a5847d5cSJustin T. Gibbs  * they actually support.
144a5847d5cSJustin T. Gibbs  */
145a5847d5cSJustin T. Gibbs #define AHC_SCB_MAX	255
146a5847d5cSJustin T. Gibbs 
147a5847d5cSJustin T. Gibbs /*
148717d4247SJustin T. Gibbs  * The maximum number of concurrent transactions supported per driver instance.
149717d4247SJustin T. Gibbs  * Sequencer Control Blocks (SCBs) store per-transaction information.  Although
150717d4247SJustin T. Gibbs  * the space for SCBs on the host adapter varies by model, the driver will
151717d4247SJustin T. Gibbs  * page the SCBs between host and controller memory as needed.  We are limited
152a5847d5cSJustin T. Gibbs  * to 253 because:
153a5847d5cSJustin T. Gibbs  * 	1) The 8bit nature of the RISC engine holds us to an 8bit value.
154a5847d5cSJustin T. Gibbs  * 	2) We reserve one value, 255, to represent the invalid element.
155a5847d5cSJustin T. Gibbs  *	3) Our input queue scheme requires one SCB to always be reserved
156a5847d5cSJustin T. Gibbs  *	   in advance of queuing any SCBs.  This takes us down to 254.
157a5847d5cSJustin T. Gibbs  *	4) To handle our output queue correctly on machines that only
158a5847d5cSJustin T. Gibbs  * 	   support 32bit stores, we must clear the array 4 bytes at a
159a5847d5cSJustin T. Gibbs  *	   time.  To avoid colliding with a DMA write from the sequencer,
160a5847d5cSJustin T. Gibbs  *	   we must be sure that 4 slots are empty when we write to clear
161a5847d5cSJustin T. Gibbs  *	   the queue.  This reduces us to 253 SCBs: 1 that just completed
162a5847d5cSJustin T. Gibbs  *	   and the known three additional empty slots in the queue that
1637c637968SJeroen Ruigrok van der Werven  *	   precede it.
16400fa2b1fSJustin T. Gibbs  */
165a5847d5cSJustin T. Gibbs #define AHC_MAX_QUEUE	253
1663bafc9d4SJustin T. Gibbs 
167aa6dfd9dSJustin T. Gibbs /*
1688f214efcSJustin T. Gibbs  * The maximum amount of SCB storage we allocate in host memory.  This
1698f214efcSJustin T. Gibbs  * number should reflect the 1 additional SCB we require to handle our
1708f214efcSJustin T. Gibbs  * qinfifo mechanism.
1718f214efcSJustin T. Gibbs  */
1728f214efcSJustin T. Gibbs #define AHC_SCB_MAX_ALLOC (AHC_MAX_QUEUE+1)
1738f214efcSJustin T. Gibbs 
1748f214efcSJustin T. Gibbs /*
175717d4247SJustin T. Gibbs  * Ring Buffer of incoming target commands.
176717d4247SJustin T. Gibbs  * We allocate 256 to simplify the logic in the sequencer
177717d4247SJustin T. Gibbs  * by using the natural wrap point of an 8bit counter.
178aa6dfd9dSJustin T. Gibbs  */
179717d4247SJustin T. Gibbs #define AHC_TMODE_CMDS	256
1803bafc9d4SJustin T. Gibbs 
181717d4247SJustin T. Gibbs /* Reset line assertion time in us */
1823b06611aSJustin T. Gibbs #define AHC_BUSRESET_DELAY	25
183717d4247SJustin T. Gibbs 
184a9c6886aSJustin T. Gibbs /* Phase change constants used in target mode. */
185a9c6886aSJustin T. Gibbs #define	AHC_BUSSETTLE_DELAY	400
186a9c6886aSJustin T. Gibbs #define	AHC_DATARELEASE_DELAY	400
187a9c6886aSJustin T. Gibbs 
188717d4247SJustin T. Gibbs /******************* Chip Characteristics/Operating Settings  *****************/
189717d4247SJustin T. Gibbs /*
190717d4247SJustin T. Gibbs  * Chip Type
191717d4247SJustin T. Gibbs  * The chip order is from least sophisticated to most sophisticated.
192717d4247SJustin T. Gibbs  */
1933bafc9d4SJustin T. Gibbs typedef enum {
1943bafc9d4SJustin T. Gibbs 	AHC_NONE	= 0x0000,
1953bafc9d4SJustin T. Gibbs 	AHC_CHIPID_MASK	= 0x00FF,
1963bafc9d4SJustin T. Gibbs 	AHC_AIC7770	= 0x0001,
1973bafc9d4SJustin T. Gibbs 	AHC_AIC7850	= 0x0002,
1989be376ccSJustin T. Gibbs 	AHC_AIC7855	= 0x0003,
1999be376ccSJustin T. Gibbs 	AHC_AIC7859	= 0x0004,
2009be376ccSJustin T. Gibbs 	AHC_AIC7860	= 0x0005,
2019be376ccSJustin T. Gibbs 	AHC_AIC7870	= 0x0006,
2029be376ccSJustin T. Gibbs 	AHC_AIC7880	= 0x0007,
203aa6dfd9dSJustin T. Gibbs 	AHC_AIC7895	= 0x0008,
204717d4247SJustin T. Gibbs 	AHC_AIC7895C	= 0x0009,
205717d4247SJustin T. Gibbs 	AHC_AIC7890	= 0x000a,
206717d4247SJustin T. Gibbs 	AHC_AIC7896	= 0x000b,
207717d4247SJustin T. Gibbs 	AHC_AIC7892	= 0x000c,
208717d4247SJustin T. Gibbs 	AHC_AIC7899	= 0x000d,
2093bafc9d4SJustin T. Gibbs 	AHC_VL		= 0x0100,	/* Bus type VL */
210a4e4cebfSWarner Losh 	AHC_EISA	= 0x0200,	/* Bus type EISA/ISA */
2113bafc9d4SJustin T. Gibbs 	AHC_PCI		= 0x0400,	/* Bus type PCI */
21241c47eeeSJustin T. Gibbs 	AHC_BUS_MASK	= 0x0F00
2133bafc9d4SJustin T. Gibbs } ahc_chip;
2143bafc9d4SJustin T. Gibbs 
215717d4247SJustin T. Gibbs /*
216717d4247SJustin T. Gibbs  * Features available in each chip type.
217717d4247SJustin T. Gibbs  */
2183bafc9d4SJustin T. Gibbs typedef enum {
219717d4247SJustin T. Gibbs 	AHC_FENONE	= 0x00000,
220717d4247SJustin T. Gibbs 	AHC_ULTRA	= 0x00001,	/* Supports 20MHz Transfers */
221717d4247SJustin T. Gibbs 	AHC_ULTRA2	= 0x00002,	/* Supports 40MHz Transfers */
222717d4247SJustin T. Gibbs 	AHC_WIDE  	= 0x00004,	/* Wide Channel */
223717d4247SJustin T. Gibbs 	AHC_TWIN	= 0x00008,	/* Twin Channel */
224717d4247SJustin T. Gibbs 	AHC_MORE_SRAM	= 0x00010,	/* 80 bytes instead of 64 */
225717d4247SJustin T. Gibbs 	AHC_CMD_CHAN	= 0x00020,	/* Has a Command DMA Channel */
226717d4247SJustin T. Gibbs 	AHC_QUEUE_REGS	= 0x00040,	/* Has Queue management registers */
227717d4247SJustin T. Gibbs 	AHC_SG_PRELOAD	= 0x00080,	/* Can perform auto-SG preload */
228717d4247SJustin T. Gibbs 	AHC_SPIOCAP	= 0x00100,	/* Has a Serial Port I/O Cap Register */
229717d4247SJustin T. Gibbs 	AHC_MULTI_TID	= 0x00200,	/* Has bitmask of TIDs for select-in */
230717d4247SJustin T. Gibbs 	AHC_HS_MAILBOX	= 0x00400,	/* Has HS_MAILBOX register */
231717d4247SJustin T. Gibbs 	AHC_DT		= 0x00800,	/* Double Transition transfers */
232717d4247SJustin T. Gibbs 	AHC_NEW_TERMCTL	= 0x01000,	/* Newer termination scheme */
233717d4247SJustin T. Gibbs 	AHC_MULTI_FUNC	= 0x02000,	/* Multi-Function Twin Channel Device */
234717d4247SJustin T. Gibbs 	AHC_LARGE_SCBS	= 0x04000,	/* 64byte SCBs */
235717d4247SJustin T. Gibbs 	AHC_AUTORATE	= 0x08000,	/* Automatic update of SCSIRATE/OFFSET*/
236717d4247SJustin T. Gibbs 	AHC_AUTOPAUSE	= 0x10000,	/* Automatic pause on register access */
237dd1290f0SJustin T. Gibbs 	AHC_TARGETMODE	= 0x20000,	/* Has tested target mode support */
238dd1290f0SJustin T. Gibbs 	AHC_MULTIROLE	= 0x40000,	/* Space for two roles at a time */
239a5847d5cSJustin T. Gibbs 	AHC_REMOVABLE	= 0x80000,	/* Hot-Swap supported */
240aa6dfd9dSJustin T. Gibbs 	AHC_AIC7770_FE	= AHC_FENONE,
24158fb7d8eSJustin T. Gibbs 	/*
24258fb7d8eSJustin T. Gibbs 	 * The real 7850 does not support Ultra modes, but there are
24358fb7d8eSJustin T. Gibbs 	 * several cards that use the generic 7850 PCI ID even though
24458fb7d8eSJustin T. Gibbs 	 * they are using an Ultra capable chip (7859/7860).  We start
24558fb7d8eSJustin T. Gibbs 	 * out with the AHC_ULTRA feature set and then check the DEVSTATUS
24658fb7d8eSJustin T. Gibbs 	 * register to determine if the capability is really present.
24758fb7d8eSJustin T. Gibbs 	 */
24858fb7d8eSJustin T. Gibbs 	AHC_AIC7850_FE	= AHC_SPIOCAP|AHC_AUTOPAUSE|AHC_TARGETMODE|AHC_ULTRA,
24958fb7d8eSJustin T. Gibbs 	AHC_AIC7860_FE	= AHC_AIC7850_FE,
250b3b25f2cSJustin T. Gibbs 	AHC_AIC7870_FE	= AHC_TARGETMODE|AHC_AUTOPAUSE,
251dd1290f0SJustin T. Gibbs 	AHC_AIC7880_FE	= AHC_AIC7870_FE|AHC_ULTRA,
252dd1290f0SJustin T. Gibbs 	/*
253dd1290f0SJustin T. Gibbs 	 * Although we have space for both the initiator and
254dd1290f0SJustin T. Gibbs 	 * target roles on ULTRA2 chips, we currently disable
255dd1290f0SJustin T. Gibbs 	 * the initiator role to allow multi-scsi-id target mode
256dd1290f0SJustin T. Gibbs 	 * configurations.  We can only respond on the same SCSI
257dd1290f0SJustin T. Gibbs 	 * ID as our initiator role if we allow initiator operation.
258dd1290f0SJustin T. Gibbs 	 * At some point, we should add a configuration knob to
259dd1290f0SJustin T. Gibbs 	 * allow both roles to be loaded.
260dd1290f0SJustin T. Gibbs 	 */
261dd1290f0SJustin T. Gibbs 	AHC_AIC7890_FE	= AHC_MORE_SRAM|AHC_CMD_CHAN|AHC_ULTRA2
262dd1290f0SJustin T. Gibbs 			  |AHC_QUEUE_REGS|AHC_SG_PRELOAD|AHC_MULTI_TID
263dd1290f0SJustin T. Gibbs 			  |AHC_HS_MAILBOX|AHC_NEW_TERMCTL|AHC_LARGE_SCBS
264dd1290f0SJustin T. Gibbs 			  |AHC_TARGETMODE,
265717d4247SJustin T. Gibbs 	AHC_AIC7892_FE	= AHC_AIC7890_FE|AHC_DT|AHC_AUTORATE|AHC_AUTOPAUSE,
266717d4247SJustin T. Gibbs 	AHC_AIC7895_FE	= AHC_AIC7880_FE|AHC_MORE_SRAM|AHC_AUTOPAUSE
267aa6dfd9dSJustin T. Gibbs 			  |AHC_CMD_CHAN|AHC_MULTI_FUNC|AHC_LARGE_SCBS,
268ba099011SJustin T. Gibbs 	AHC_AIC7895C_FE	= AHC_AIC7895_FE|AHC_MULTI_TID,
269ba099011SJustin T. Gibbs 	AHC_AIC7896_FE	= AHC_AIC7890_FE|AHC_MULTI_FUNC,
270ba099011SJustin T. Gibbs 	AHC_AIC7899_FE	= AHC_AIC7892_FE|AHC_MULTI_FUNC
2713bafc9d4SJustin T. Gibbs } ahc_feature;
2723bafc9d4SJustin T. Gibbs 
273717d4247SJustin T. Gibbs /*
274717d4247SJustin T. Gibbs  * Bugs in the silicon that we work around in software.
275717d4247SJustin T. Gibbs  */
2763bafc9d4SJustin T. Gibbs typedef enum {
277aa6dfd9dSJustin T. Gibbs 	AHC_BUGNONE		= 0x00,
278aa6dfd9dSJustin T. Gibbs 	/*
279aa6dfd9dSJustin T. Gibbs 	 * On all chips prior to the U2 product line,
280aa6dfd9dSJustin T. Gibbs 	 * the WIDEODD S/G segment feature does not
281aa6dfd9dSJustin T. Gibbs 	 * work during scsi->HostBus transfers.
282aa6dfd9dSJustin T. Gibbs 	 */
283aa6dfd9dSJustin T. Gibbs 	AHC_TMODE_WIDEODD_BUG	= 0x01,
284aa6dfd9dSJustin T. Gibbs 	/*
285aa6dfd9dSJustin T. Gibbs 	 * On the aic7890/91 Rev 0 chips, the autoflush
286aa6dfd9dSJustin T. Gibbs 	 * feature does not work.  A manual flush of
287aa6dfd9dSJustin T. Gibbs 	 * the DMA FIFO is required.
288aa6dfd9dSJustin T. Gibbs 	 */
289957790c3SJustin T. Gibbs 	AHC_AUTOFLUSH_BUG	= 0x02,
290957790c3SJustin T. Gibbs 	/*
291717d4247SJustin T. Gibbs 	 * On many chips, cacheline streaming does not work.
292957790c3SJustin T. Gibbs 	 */
293957790c3SJustin T. Gibbs 	AHC_CACHETHEN_BUG	= 0x04,
294957790c3SJustin T. Gibbs 	/*
295957790c3SJustin T. Gibbs 	 * On the aic7896/97 chips, cacheline
296957790c3SJustin T. Gibbs 	 * streaming must be enabled.
297957790c3SJustin T. Gibbs 	 */
298717d4247SJustin T. Gibbs 	AHC_CACHETHEN_DIS_BUG	= 0x08,
299717d4247SJustin T. Gibbs 	/*
300717d4247SJustin T. Gibbs 	 * PCI 2.1 Retry failure on non-empty data fifo.
301717d4247SJustin T. Gibbs 	 */
302717d4247SJustin T. Gibbs 	AHC_PCI_2_1_RETRY_BUG	= 0x10,
303717d4247SJustin T. Gibbs 	/*
304717d4247SJustin T. Gibbs 	 * Controller does not handle cacheline residuals
305717d4247SJustin T. Gibbs 	 * properly on S/G segments if PCI MWI instructions
306717d4247SJustin T. Gibbs 	 * are allowed.
307717d4247SJustin T. Gibbs 	 */
308717d4247SJustin T. Gibbs 	AHC_PCI_MWI_BUG		= 0x20,
309717d4247SJustin T. Gibbs 	/*
310717d4247SJustin T. Gibbs 	 * An SCB upload using the SCB channel's
311717d4247SJustin T. Gibbs 	 * auto array entry copy feature may
312717d4247SJustin T. Gibbs 	 * corrupt data.  This appears to only
313717d4247SJustin T. Gibbs 	 * occur on 66MHz systems.
314717d4247SJustin T. Gibbs 	 */
315717d4247SJustin T. Gibbs 	AHC_SCBCHAN_UPLOAD_BUG	= 0x40
316aa6dfd9dSJustin T. Gibbs } ahc_bug;
317aa6dfd9dSJustin T. Gibbs 
318717d4247SJustin T. Gibbs /*
319717d4247SJustin T. Gibbs  * Configuration specific settings.
320717d4247SJustin T. Gibbs  * The driver determines these settings by probing the
321717d4247SJustin T. Gibbs  * chip/controller's configuration.
322717d4247SJustin T. Gibbs  */
323aa6dfd9dSJustin T. Gibbs typedef enum {
3243bafc9d4SJustin T. Gibbs 	AHC_FNONE	      = 0x000,
3256fb77fefSJustin T. Gibbs 	AHC_PRIMARY_CHANNEL   = 0x003,  /*
3266fb77fefSJustin T. Gibbs 					 * The channel that should
3276fb77fefSJustin T. Gibbs 					 * be probed first.
3283bafc9d4SJustin T. Gibbs 					 */
3293bafc9d4SJustin T. Gibbs 	AHC_USEDEFAULTS	      = 0x004,  /*
3303bafc9d4SJustin T. Gibbs 					 * For cards without an seeprom
3313bafc9d4SJustin T. Gibbs 					 * or a BIOS to initialize the chip's
3323bafc9d4SJustin T. Gibbs 					 * SRAM, we use the default target
3333bafc9d4SJustin T. Gibbs 					 * settings.
3343bafc9d4SJustin T. Gibbs 					 */
335dd1290f0SJustin T. Gibbs 	AHC_SEQUENCER_DEBUG   = 0x008,
3363bafc9d4SJustin T. Gibbs 	AHC_SHARED_SRAM	      = 0x010,
3373bafc9d4SJustin T. Gibbs 	AHC_LARGE_SEEPROM     = 0x020,  /* Uses C56_66 not C46 */
3380ca48af7SJustin T. Gibbs 	AHC_RESET_BUS_A	      = 0x040,
3390ca48af7SJustin T. Gibbs 	AHC_RESET_BUS_B	      = 0x080,
3403bafc9d4SJustin T. Gibbs 	AHC_EXTENDED_TRANS_A  = 0x100,
3413bafc9d4SJustin T. Gibbs 	AHC_EXTENDED_TRANS_B  = 0x200,
3423bafc9d4SJustin T. Gibbs 	AHC_TERM_ENB_A	      = 0x400,
3433bafc9d4SJustin T. Gibbs 	AHC_TERM_ENB_B	      = 0x800,
344dd1290f0SJustin T. Gibbs 	AHC_INITIATORROLE     = 0x1000,  /*
3454dd5dcaeSJustin T. Gibbs 					  * Allow initiator operations on
3464dd5dcaeSJustin T. Gibbs 					  * this controller.
3474dd5dcaeSJustin T. Gibbs 					  */
348dd1290f0SJustin T. Gibbs 	AHC_TARGETROLE	      = 0x2000,  /*
3493bafc9d4SJustin T. Gibbs 					  * Allow target operations on this
3503bafc9d4SJustin T. Gibbs 					  * controller.
3513bafc9d4SJustin T. Gibbs 					  */
3523bafc9d4SJustin T. Gibbs 	AHC_NEWEEPROM_FMT     = 0x4000,
353c5621898SJustin T. Gibbs 	AHC_RESOURCE_SHORTAGE = 0x8000,
354c5621898SJustin T. Gibbs 	AHC_TQINFIFO_BLOCKED  = 0x10000,  /* Blocked waiting for ATIOs */
355ba099011SJustin T. Gibbs 	AHC_INT50_SPEEDFLEX   = 0x20000,  /*
356ba099011SJustin T. Gibbs 					   * Internal 50pin connector
357ba099011SJustin T. Gibbs 					   * sits behind an aic3860
358ba099011SJustin T. Gibbs 					   */
359717d4247SJustin T. Gibbs 	AHC_SCB_BTT	      = 0x40000,  /*
360aa6dfd9dSJustin T. Gibbs 					   * The busy targets table is
361aa6dfd9dSJustin T. Gibbs 					   * stored in SCB space rather
362aa6dfd9dSJustin T. Gibbs 					   * than SRAM.
363aa6dfd9dSJustin T. Gibbs 					   */
36456a7c4a8SJustin T. Gibbs 	AHC_BIOS_ENABLED      = 0x80000,
3656fb77fefSJustin T. Gibbs 	AHC_ALL_INTERRUPTS    = 0x100000,
3666fb77fefSJustin T. Gibbs 	AHC_PAGESCBS	      = 0x400000,  /* Enable SCB paging */
367cd036e89SJustin T. Gibbs 	AHC_EDGE_INTERRUPT    = 0x800000,  /* Device uses edge triggered ints */
3683b06611aSJustin T. Gibbs 	AHC_39BIT_ADDRESSING  = 0x1000000, /* Use 39 bit addressing scheme. */
3693b06611aSJustin T. Gibbs 	AHC_LSCBS_ENABLED     = 0x2000000, /* 64Byte SCBs enabled */
37070b41139SJustin T. Gibbs 	AHC_SCB_CONFIG_USED   = 0x4000000, /* No SEEPROM but SCB2 had info. */
37170b41139SJustin T. Gibbs 	AHC_NO_BIOS_INIT      = 0x8000000, /* No BIOS left over settings. */
3729bf327a7SJustin T. Gibbs 	AHC_DISABLE_PCI_PERR  = 0x10000000,
373b3b25f2cSJustin T. Gibbs 	AHC_HAS_TERM_LOGIC    = 0x20000000,
374b3b25f2cSJustin T. Gibbs 	AHC_SHUTDOWN_RECOVERY = 0x40000000 /* Terminate recovery thread. */
3753bafc9d4SJustin T. Gibbs } ahc_flag;
3763bafc9d4SJustin T. Gibbs 
377717d4247SJustin T. Gibbs /************************* Hardware  SCB Definition ***************************/
378717d4247SJustin T. Gibbs 
379717d4247SJustin T. Gibbs /*
380717d4247SJustin T. Gibbs  * The driver keeps up to MAX_SCB scb structures per card in memory.  The SCB
3819bf327a7SJustin T. Gibbs  * consists of a "hardware SCB" mirroring the fields available on the card
382717d4247SJustin T. Gibbs  * and additional information the kernel stores for each transaction.
383717d4247SJustin T. Gibbs  *
384717d4247SJustin T. Gibbs  * To minimize space utilization, a portion of the hardware scb stores
385717d4247SJustin T. Gibbs  * different data during different portions of a SCSI transaction.
386717d4247SJustin T. Gibbs  * As initialized by the host driver for the initiator role, this area
387717d4247SJustin T. Gibbs  * contains the SCSI cdb (or a pointer to the  cdb) to be executed.  After
388717d4247SJustin T. Gibbs  * the cdb has been presented to the target, this area serves to store
389717d4247SJustin T. Gibbs  * residual transfer information and the SCSI status byte.
390717d4247SJustin T. Gibbs  * For the target role, the contents of this area do not change, but
391717d4247SJustin T. Gibbs  * still serve a different purpose than for the initiator role.  See
392717d4247SJustin T. Gibbs  * struct target_data for details.
393717d4247SJustin T. Gibbs  */
394717d4247SJustin T. Gibbs 
395717d4247SJustin T. Gibbs /*
396717d4247SJustin T. Gibbs  * Status information embedded in the shared poriton of
397717d4247SJustin T. Gibbs  * an SCB after passing the cdb to the target.  The kernel
398717d4247SJustin T. Gibbs  * driver will only read this data for transactions that
399717d4247SJustin T. Gibbs  * complete abnormally (non-zero status byte).
400717d4247SJustin T. Gibbs  */
401717d4247SJustin T. Gibbs struct status_pkt {
402717d4247SJustin T. Gibbs 	uint32_t residual_datacnt;	/* Residual in the current S/G seg */
403717d4247SJustin T. Gibbs 	uint32_t residual_sg_ptr;	/* The next S/G for this transfer */
404717d4247SJustin T. Gibbs 	uint8_t	 scsi_status;		/* Standard SCSI status byte */
405717d4247SJustin T. Gibbs };
406717d4247SJustin T. Gibbs 
407717d4247SJustin T. Gibbs /*
408717d4247SJustin T. Gibbs  * Target mode version of the shared data SCB segment.
409717d4247SJustin T. Gibbs  */
410717d4247SJustin T. Gibbs struct target_data {
4118f214efcSJustin T. Gibbs 	uint32_t residual_datacnt;	/* Residual in the current S/G seg */
4128f214efcSJustin T. Gibbs 	uint32_t residual_sg_ptr;	/* The next S/G for this transfer */
4138f214efcSJustin T. Gibbs 	uint8_t  scsi_status;		/* SCSI status to give to initiator */
414717d4247SJustin T. Gibbs 	uint8_t  target_phases;		/* Bitmap of phases to execute */
415717d4247SJustin T. Gibbs 	uint8_t  data_phase;		/* Data-In or Data-Out */
416717d4247SJustin T. Gibbs 	uint8_t  initiator_tag;		/* Initiator's transaction tag */
417717d4247SJustin T. Gibbs };
418717d4247SJustin T. Gibbs 
419b3b25f2cSJustin T. Gibbs #define MAX_CDB_LEN 16
420717d4247SJustin T. Gibbs struct hardware_scb {
421717d4247SJustin T. Gibbs /*0*/	union {
422717d4247SJustin T. Gibbs 		/*
423717d4247SJustin T. Gibbs 		 * If the cdb is 12 bytes or less, we embed it directly
424717d4247SJustin T. Gibbs 		 * in the SCB.  For longer cdbs, we embed the address
425717d4247SJustin T. Gibbs 		 * of the cdb payload as seen by the chip and a DMA
426717d4247SJustin T. Gibbs 		 * is used to pull it in.
427717d4247SJustin T. Gibbs 		 */
428717d4247SJustin T. Gibbs 		uint8_t	 cdb[12];
429717d4247SJustin T. Gibbs 		uint32_t cdb_ptr;
430717d4247SJustin T. Gibbs 		struct	 status_pkt status;
431717d4247SJustin T. Gibbs 		struct	 target_data tdata;
432717d4247SJustin T. Gibbs 	} shared_data;
433717d4247SJustin T. Gibbs /*
434717d4247SJustin T. Gibbs  * A word about residuals.
435717d4247SJustin T. Gibbs  * The scb is presented to the sequencer with the dataptr and datacnt
436717d4247SJustin T. Gibbs  * fields initialized to the contents of the first S/G element to
437717d4247SJustin T. Gibbs  * transfer.  The sgptr field is initialized to the bus address for
438717d4247SJustin T. Gibbs  * the S/G element that follows the first in the in core S/G array
439717d4247SJustin T. Gibbs  * or'ed with the SG_FULL_RESID flag.  Sgptr may point to an invalid
440717d4247SJustin T. Gibbs  * S/G entry for this transfer (single S/G element transfer with the
441717d4247SJustin T. Gibbs  * first elements address and length preloaded in the dataptr/datacnt
442717d4247SJustin T. Gibbs  * fields).  If no transfer is to occur, sgptr is set to SG_LIST_NULL.
443717d4247SJustin T. Gibbs  * The SG_FULL_RESID flag ensures that the residual will be correctly
444717d4247SJustin T. Gibbs  * noted even if no data transfers occur.  Once the data phase is entered,
445717d4247SJustin T. Gibbs  * the residual sgptr and datacnt are loaded from the sgptr and the
446717d4247SJustin T. Gibbs  * datacnt fields.  After each S/G element's dataptr and length are
447717d4247SJustin T. Gibbs  * loaded into the hardware, the residual sgptr is advanced.  After
448717d4247SJustin T. Gibbs  * each S/G element is expired, its datacnt field is checked to see
449717d4247SJustin T. Gibbs  * if the LAST_SEG flag is set.  If so, SG_LIST_NULL is set in the
450717d4247SJustin T. Gibbs  * residual sg ptr and the transfer is considered complete.  If the
451594c945aSPedro F. Giffuni  * sequencer determines that there is a residual in the transfer, it
452717d4247SJustin T. Gibbs  * will set the SG_RESID_VALID flag in sgptr and dma the scb back into
453717d4247SJustin T. Gibbs  * host memory.  To sumarize:
454717d4247SJustin T. Gibbs  *
455717d4247SJustin T. Gibbs  * Sequencer:
456717d4247SJustin T. Gibbs  *	o A residual has occurred if SG_FULL_RESID is set in sgptr,
457717d4247SJustin T. Gibbs  *	  or residual_sgptr does not have SG_LIST_NULL set.
458717d4247SJustin T. Gibbs  *
459594c945aSPedro F. Giffuni  *	o We are transferring the last segment if residual_datacnt has
460717d4247SJustin T. Gibbs  *	  the SG_LAST_SEG flag set.
461717d4247SJustin T. Gibbs  *
462717d4247SJustin T. Gibbs  * Host:
463717d4247SJustin T. Gibbs  *	o A residual has occurred if a completed scb has the
464717d4247SJustin T. Gibbs  *	  SG_RESID_VALID flag set.
465717d4247SJustin T. Gibbs  *
466717d4247SJustin T. Gibbs  *	o residual_sgptr and sgptr refer to the "next" sg entry
467717d4247SJustin T. Gibbs  *	  and so may point beyond the last valid sg entry for the
468717d4247SJustin T. Gibbs  *	  transfer.
469717d4247SJustin T. Gibbs  */
470717d4247SJustin T. Gibbs /*12*/	uint32_t dataptr;
471717d4247SJustin T. Gibbs /*16*/	uint32_t datacnt;		/*
472717d4247SJustin T. Gibbs 					 * Byte 3 (numbered from 0) of
473717d4247SJustin T. Gibbs 					 * the datacnt is really the
474717d4247SJustin T. Gibbs 					 * 4th byte in that data address.
475717d4247SJustin T. Gibbs 					 */
476717d4247SJustin T. Gibbs /*20*/	uint32_t sgptr;
477717d4247SJustin T. Gibbs #define SG_PTR_MASK	0xFFFFFFF8
478717d4247SJustin T. Gibbs /*24*/	uint8_t  control;	/* See SCB_CONTROL in aic7xxx.reg for details */
479717d4247SJustin T. Gibbs /*25*/	uint8_t  scsiid;	/* what to load in the SCSIID register */
480717d4247SJustin T. Gibbs /*26*/	uint8_t  lun;
481717d4247SJustin T. Gibbs /*27*/	uint8_t  tag;			/*
482717d4247SJustin T. Gibbs 					 * Index into our kernel SCB array.
483717d4247SJustin T. Gibbs 					 * Also used as the tag for tagged I/O
484717d4247SJustin T. Gibbs 					 */
485717d4247SJustin T. Gibbs /*28*/	uint8_t  cdb_len;
486717d4247SJustin T. Gibbs /*29*/	uint8_t  scsirate;		/* Value for SCSIRATE register */
487717d4247SJustin T. Gibbs /*30*/	uint8_t  scsioffset;		/* Value for SCSIOFFSET register */
488717d4247SJustin T. Gibbs /*31*/	uint8_t  next;			/*
489717d4247SJustin T. Gibbs 					 * Used for threading SCBs in the
490717d4247SJustin T. Gibbs 					 * "Waiting for Selection" and
491717d4247SJustin T. Gibbs 					 * "Disconnected SCB" lists down
492717d4247SJustin T. Gibbs 					 * in the sequencer.
493717d4247SJustin T. Gibbs 					 */
494717d4247SJustin T. Gibbs /*32*/	uint8_t  cdb32[32];		/*
495717d4247SJustin T. Gibbs 					 * CDB storage for cdbs of size
496717d4247SJustin T. Gibbs 					 * 13->32.  We store them here
497717d4247SJustin T. Gibbs 					 * because hardware scbs are
498717d4247SJustin T. Gibbs 					 * allocated from DMA safe
499717d4247SJustin T. Gibbs 					 * memory so we are guaranteed
500717d4247SJustin T. Gibbs 					 * the controller can access
501717d4247SJustin T. Gibbs 					 * this data.
502717d4247SJustin T. Gibbs 					 */
503717d4247SJustin T. Gibbs };
504717d4247SJustin T. Gibbs 
505717d4247SJustin T. Gibbs /************************ Kernel SCB Definitions ******************************/
506717d4247SJustin T. Gibbs /*
507717d4247SJustin T. Gibbs  * Some fields of the SCB are OS dependent.  Here we collect the
508717d4247SJustin T. Gibbs  * definitions for elements that all OS platforms need to include
509717d4247SJustin T. Gibbs  * in there SCB definition.
510717d4247SJustin T. Gibbs  */
511717d4247SJustin T. Gibbs 
512717d4247SJustin T. Gibbs /*
513594c945aSPedro F. Giffuni  * Definition of a scatter/gather element as transferred to the controller.
514717d4247SJustin T. Gibbs  * The aic7xxx chips only support a 24bit length.  We use the top byte of
515717d4247SJustin T. Gibbs  * the length to store additional address bits and a flag to indicate
516717d4247SJustin T. Gibbs  * that a given segment terminates the transfer.  This gives us an
517717d4247SJustin T. Gibbs  * addressable range of 512GB on machines with 64bit PCI or with chips
518717d4247SJustin T. Gibbs  * that can support dual address cycles on 32bit PCI busses.
519717d4247SJustin T. Gibbs  */
520717d4247SJustin T. Gibbs struct ahc_dma_seg {
521717d4247SJustin T. Gibbs 	uint32_t	addr;
522717d4247SJustin T. Gibbs 	uint32_t	len;
523717d4247SJustin T. Gibbs #define	AHC_DMA_LAST_SEG	0x80000000
524717d4247SJustin T. Gibbs #define	AHC_SG_HIGH_ADDR_MASK	0x7F000000
525717d4247SJustin T. Gibbs #define	AHC_SG_LEN_MASK		0x00FFFFFF
526717d4247SJustin T. Gibbs };
527717d4247SJustin T. Gibbs 
528cd036e89SJustin T. Gibbs struct sg_map_node {
529cd036e89SJustin T. Gibbs 	bus_dmamap_t		 sg_dmamap;
530cd036e89SJustin T. Gibbs 	bus_addr_t		 sg_physaddr;
531cd036e89SJustin T. Gibbs 	struct ahc_dma_seg*	 sg_vaddr;
532cd036e89SJustin T. Gibbs 	SLIST_ENTRY(sg_map_node) links;
533cd036e89SJustin T. Gibbs };
534cd036e89SJustin T. Gibbs 
535717d4247SJustin T. Gibbs /*
536717d4247SJustin T. Gibbs  * The current state of this SCB.
537717d4247SJustin T. Gibbs  */
5383bafc9d4SJustin T. Gibbs typedef enum {
539b3b25f2cSJustin T. Gibbs 	SCB_FLAG_NONE		= 0x0000,
5403bafc9d4SJustin T. Gibbs 	SCB_OTHERTCL_TIMEOUT	= 0x0002,/*
5413bafc9d4SJustin T. Gibbs 					  * Another device was active
5423bafc9d4SJustin T. Gibbs 					  * during the first timeout for
5433bafc9d4SJustin T. Gibbs 					  * this SCB so we gave ourselves
5443bafc9d4SJustin T. Gibbs 					  * an additional timeout period
5453bafc9d4SJustin T. Gibbs 					  * in case it was hogging the
5463bafc9d4SJustin T. Gibbs 					  * bus.
5473bafc9d4SJustin T. Gibbs 				          */
5483bafc9d4SJustin T. Gibbs 	SCB_DEVICE_RESET	= 0x0004,
5493bafc9d4SJustin T. Gibbs 	SCB_SENSE		= 0x0008,
550dd1290f0SJustin T. Gibbs 	SCB_CDB32_PTR		= 0x0010,
551b95de6daSJustin T. Gibbs 	SCB_RECOVERY_SCB	= 0x0020,
552b95de6daSJustin T. Gibbs 	SCB_AUTO_NEGOTIATE	= 0x0040,/* Negotiate to achieve goal. */
553b95de6daSJustin T. Gibbs 	SCB_NEGOTIATE		= 0x0080,/* Negotiation forced for command. */
5544d22994eSScott Long 	SCB_ABORT		= 0x0100,
5554d22994eSScott Long 	SCB_UNTAGGEDQ		= 0x0200,
5564d22994eSScott Long 	SCB_ACTIVE		= 0x0400,
5574d22994eSScott Long 	SCB_TARGET_IMMEDIATE	= 0x0800,
5584d22994eSScott Long 	SCB_TRANSMISSION_ERROR	= 0x1000,/*
5594d22994eSScott Long 					  * We detected a parity or CRC
5604d22994eSScott Long 					  * error that has effected the
5614d22994eSScott Long 					  * payload of the command.  This
5624d22994eSScott Long 					  * flag is checked when normal
5634d22994eSScott Long 					  * status is returned to catch
5644d22994eSScott Long 					  * the case of a target not
5654d22994eSScott Long 					  * responding to our attempt
5664d22994eSScott Long 					  * to report the error.
5674d22994eSScott Long 					  */
56870b41139SJustin T. Gibbs 	SCB_TARGET_SCB		= 0x2000,
569b3b25f2cSJustin T. Gibbs 	SCB_SILENT		= 0x4000,/*
57070b41139SJustin T. Gibbs 					  * Be quiet about transmission type
57170b41139SJustin T. Gibbs 					  * errors.  They are expected and we
57270b41139SJustin T. Gibbs 					  * don't want to upset the user.  This
57370b41139SJustin T. Gibbs 					  * flag is typically used during DV.
57470b41139SJustin T. Gibbs 					  */
575b3b25f2cSJustin T. Gibbs 	SCB_TIMEDOUT		= 0x8000 /*
576b3b25f2cSJustin T. Gibbs 					  * SCB has timed out and is on the
577b3b25f2cSJustin T. Gibbs 					  * timedout list.
578b3b25f2cSJustin T. Gibbs 					  */
5793bafc9d4SJustin T. Gibbs } scb_flag;
5803bafc9d4SJustin T. Gibbs 
5813bafc9d4SJustin T. Gibbs struct scb {
5823bafc9d4SJustin T. Gibbs 	struct	hardware_scb	 *hscb;
583aa6dfd9dSJustin T. Gibbs 	union {
584aa6dfd9dSJustin T. Gibbs 		SLIST_ENTRY(scb)  sle;
585aa6dfd9dSJustin T. Gibbs 		TAILQ_ENTRY(scb)  tqe;
586aa6dfd9dSJustin T. Gibbs 	} links;
587717d4247SJustin T. Gibbs 	LIST_ENTRY(scb)		  pending_links;
588b3b25f2cSJustin T. Gibbs 	LIST_ENTRY(scb)		  timedout_links;
589b3b25f2cSJustin T. Gibbs 	aic_io_ctx_t		  io_ctx;
59070351c9aSJustin T. Gibbs 	struct ahc_softc	 *ahc_softc;
5913bafc9d4SJustin T. Gibbs 	scb_flag		  flags;
5923bafc9d4SJustin T. Gibbs 	bus_dmamap_t		  dmamap;
593717d4247SJustin T. Gibbs 	struct scb_platform_data *platform_data;
594cd036e89SJustin T. Gibbs 	struct sg_map_node	 *sg_map;
59500fa2b1fSJustin T. Gibbs 	struct ahc_dma_seg 	 *sg_list;
59600fa2b1fSJustin T. Gibbs 	bus_addr_t		  sg_list_phys;
5973bafc9d4SJustin T. Gibbs 	u_int			  sg_count;/* How full ahc_dma_seg is */
598032b0a17SScott Long 	aic_timer_t		  io_timer;
5993bafc9d4SJustin T. Gibbs };
6003bafc9d4SJustin T. Gibbs 
601717d4247SJustin T. Gibbs struct scb_data {
602717d4247SJustin T. Gibbs 	SLIST_HEAD(, scb) free_scbs;	/*
603717d4247SJustin T. Gibbs 					 * Pool of SCBs ready to be assigned
604717d4247SJustin T. Gibbs 					 * commands to execute.
605717d4247SJustin T. Gibbs 					 */
6068f214efcSJustin T. Gibbs 	struct	scb *scbindex[256];	/*
6078f214efcSJustin T. Gibbs 					 * Mapping from tag to SCB.
6088f214efcSJustin T. Gibbs 					 * As tag identifiers are an
6098f214efcSJustin T. Gibbs 					 * 8bit value, we provide space
6108f214efcSJustin T. Gibbs 					 * for all possible tag values.
6118f214efcSJustin T. Gibbs 					 * Any lookups to entries at or
6128f214efcSJustin T. Gibbs 					 * above AHC_SCB_MAX_ALLOC will
6138f214efcSJustin T. Gibbs 					 * always fail.
6148f214efcSJustin T. Gibbs 					 */
615a49630acSJustin T. Gibbs 	struct	hardware_scb	*hscbs;	/* Array of hardware SCBs */
616a49630acSJustin T. Gibbs 	struct	scb *scbarray;		/* Array of kernel SCBs */
617717d4247SJustin T. Gibbs 	struct	scsi_sense_data *sense; /* Per SCB sense data */
618717d4247SJustin T. Gibbs 
6197afc0218SJustin T. Gibbs 	u_int	recovery_scbs;		/* Transactions currently in recovery */
6207afc0218SJustin T. Gibbs 
621717d4247SJustin T. Gibbs 	/*
622717d4247SJustin T. Gibbs 	 * "Bus" addresses of our data structures.
623717d4247SJustin T. Gibbs 	 */
624717d4247SJustin T. Gibbs 	bus_dma_tag_t	 hscb_dmat;	/* dmat for our hardware SCB array */
625717d4247SJustin T. Gibbs 	bus_dmamap_t	 hscb_dmamap;
626717d4247SJustin T. Gibbs 	bus_addr_t	 hscb_busaddr;
627717d4247SJustin T. Gibbs 	bus_dma_tag_t	 sense_dmat;
628717d4247SJustin T. Gibbs 	bus_dmamap_t	 sense_dmamap;
629717d4247SJustin T. Gibbs 	bus_addr_t	 sense_busaddr;
630717d4247SJustin T. Gibbs 	bus_dma_tag_t	 sg_dmat;	/* dmat for our sg segments */
631717d4247SJustin T. Gibbs 	SLIST_HEAD(, sg_map_node) sg_maps;
632717d4247SJustin T. Gibbs 	uint8_t	numscbs;
633717d4247SJustin T. Gibbs 	uint8_t	maxhscbs;		/* Number of SCBs on the card */
634717d4247SJustin T. Gibbs 	uint8_t	init_level;		/*
635717d4247SJustin T. Gibbs 					 * How far we've initialized
636717d4247SJustin T. Gibbs 					 * this structure.
637717d4247SJustin T. Gibbs 					 */
638717d4247SJustin T. Gibbs };
639717d4247SJustin T. Gibbs 
640717d4247SJustin T. Gibbs /************************ Target Mode Definitions *****************************/
641717d4247SJustin T. Gibbs 
6423bafc9d4SJustin T. Gibbs /*
643*b1603638SGordon Bergling  * Connection descriptor for select-in requests in target mode.
6443bafc9d4SJustin T. Gibbs  */
6453bafc9d4SJustin T. Gibbs struct target_cmd {
646717d4247SJustin T. Gibbs 	uint8_t scsiid;		/* Our ID and the initiator's ID */
647aa6dfd9dSJustin T. Gibbs 	uint8_t identify;	/* Identify message */
648717d4247SJustin T. Gibbs 	uint8_t bytes[22];	/*
649717d4247SJustin T. Gibbs 				 * Bytes contains any additional message
650717d4247SJustin T. Gibbs 				 * bytes terminated by 0xFF.  The remainder
651717d4247SJustin T. Gibbs 				 * is the cdb to execute.
652717d4247SJustin T. Gibbs 				 */
653717d4247SJustin T. Gibbs 	uint8_t cmd_valid;	/*
654717d4247SJustin T. Gibbs 				 * When a command is complete, the firmware
655717d4247SJustin T. Gibbs 				 * will set cmd_valid to all bits set.
656717d4247SJustin T. Gibbs 				 * After the host has seen the command,
657717d4247SJustin T. Gibbs 				 * the bits are cleared.  This allows us
658717d4247SJustin T. Gibbs 				 * to just peek at host memory to determine
659717d4247SJustin T. Gibbs 				 * if more work is complete. cmd_valid is on
660717d4247SJustin T. Gibbs 				 * an 8 byte boundary to simplify setting
661717d4247SJustin T. Gibbs 				 * it on aic7880 hardware which only has
662717d4247SJustin T. Gibbs 				 * limited direct access to the DMA FIFO.
663717d4247SJustin T. Gibbs 				 */
664aa6dfd9dSJustin T. Gibbs 	uint8_t pad[7];
6653bafc9d4SJustin T. Gibbs };
6663bafc9d4SJustin T. Gibbs 
6673bafc9d4SJustin T. Gibbs /*
6687457cf2dSJustin T. Gibbs  * Number of events we can buffer up if we run out
6697457cf2dSJustin T. Gibbs  * of immediate notify ccbs.
6707457cf2dSJustin T. Gibbs  */
6717457cf2dSJustin T. Gibbs #define AHC_TMODE_EVENT_BUFFER_SIZE 8
6727457cf2dSJustin T. Gibbs struct ahc_tmode_event {
673aa6dfd9dSJustin T. Gibbs 	uint8_t initiator_id;
674aa6dfd9dSJustin T. Gibbs 	uint8_t event_type;	/* MSG type or EVENT_TYPE_BUS_RESET */
6757457cf2dSJustin T. Gibbs #define	EVENT_TYPE_BUS_RESET 0xFF
676aa6dfd9dSJustin T. Gibbs 	uint8_t event_arg;
6777457cf2dSJustin T. Gibbs };
6787457cf2dSJustin T. Gibbs 
6797457cf2dSJustin T. Gibbs /*
680717d4247SJustin T. Gibbs  * Per enabled lun target mode state.
681717d4247SJustin T. Gibbs  * As this state is directly influenced by the host OS'es target mode
682717d4247SJustin T. Gibbs  * environment, we let the OS module define it.  Forward declare the
683717d4247SJustin T. Gibbs  * structure here so we can store arrays of them, etc. in OS neutral
684717d4247SJustin T. Gibbs  * data structures.
6853bafc9d4SJustin T. Gibbs  */
686717d4247SJustin T. Gibbs #ifdef AHC_TARGET_MODE
687b95de6daSJustin T. Gibbs struct ahc_tmode_lstate {
6887457cf2dSJustin T. Gibbs 	struct cam_path *path;
6890ca48af7SJustin T. Gibbs 	struct ccb_hdr_slist accept_tios;
6900ca48af7SJustin T. Gibbs 	struct ccb_hdr_slist immed_notifies;
6917457cf2dSJustin T. Gibbs 	struct ahc_tmode_event event_buffer[AHC_TMODE_EVENT_BUFFER_SIZE];
692aa6dfd9dSJustin T. Gibbs 	uint8_t event_r_idx;
693aa6dfd9dSJustin T. Gibbs 	uint8_t event_w_idx;
6943bafc9d4SJustin T. Gibbs };
695717d4247SJustin T. Gibbs #else
696b95de6daSJustin T. Gibbs struct ahc_tmode_lstate;
697717d4247SJustin T. Gibbs #endif
6983bafc9d4SJustin T. Gibbs 
699717d4247SJustin T. Gibbs /******************** Transfer Negotiation Datastructures *********************/
700c5621898SJustin T. Gibbs #define AHC_TRANS_CUR		0x01	/* Modify current neogtiation status */
701717d4247SJustin T. Gibbs #define AHC_TRANS_ACTIVE	0x03	/* Assume this target is on the bus */
702c5621898SJustin T. Gibbs #define AHC_TRANS_GOAL		0x04	/* Modify negotiation goal */
703c5621898SJustin T. Gibbs #define AHC_TRANS_USER		0x08	/* Modify user negotiation settings */
704c5621898SJustin T. Gibbs 
7054d22994eSScott Long #define AHC_WIDTH_UNKNOWN	0xFF
7064d22994eSScott Long #define AHC_PERIOD_UNKNOWN	0xFF
7079bf327a7SJustin T. Gibbs #define AHC_OFFSET_UNKNOWN	0xFF
7084d22994eSScott Long #define AHC_PPR_OPTS_UNKNOWN	0xFF
7094d22994eSScott Long 
710717d4247SJustin T. Gibbs /*
711717d4247SJustin T. Gibbs  * Transfer Negotiation Information.
712717d4247SJustin T. Gibbs  */
713c5621898SJustin T. Gibbs struct ahc_transinfo {
714717d4247SJustin T. Gibbs 	uint8_t protocol_version;	/* SCSI Revision level */
715717d4247SJustin T. Gibbs 	uint8_t transport_version;	/* SPI Revision level */
716717d4247SJustin T. Gibbs 	uint8_t width;			/* Bus width */
717717d4247SJustin T. Gibbs 	uint8_t period;			/* Sync rate factor */
718717d4247SJustin T. Gibbs 	uint8_t offset;			/* Sync offset */
719717d4247SJustin T. Gibbs 	uint8_t ppr_options;		/* Parallel Protocol Request options */
720c5621898SJustin T. Gibbs };
721c5621898SJustin T. Gibbs 
722717d4247SJustin T. Gibbs /*
723717d4247SJustin T. Gibbs  * Per-initiator current, goal and user transfer negotiation information. */
724c5621898SJustin T. Gibbs struct ahc_initiator_tinfo {
725717d4247SJustin T. Gibbs 	uint8_t scsirate;		/* Computed value for SCSIRATE reg */
72658fb7d8eSJustin T. Gibbs 	struct ahc_transinfo curr;
727c5621898SJustin T. Gibbs 	struct ahc_transinfo goal;
728c5621898SJustin T. Gibbs 	struct ahc_transinfo user;
729c5621898SJustin T. Gibbs };
730c5621898SJustin T. Gibbs 
7313bafc9d4SJustin T. Gibbs /*
732717d4247SJustin T. Gibbs  * Per enabled target ID state.
733717d4247SJustin T. Gibbs  * Pointers to lun target state as well as sync/wide negotiation information
734717d4247SJustin T. Gibbs  * for each initiator<->target mapping.  For the initiator role we pretend
735717d4247SJustin T. Gibbs  * that we are the target and the targets are the initiators since the
736717d4247SJustin T. Gibbs  * negotiation is the same regardless of role.
7373bafc9d4SJustin T. Gibbs  */
738b95de6daSJustin T. Gibbs struct ahc_tmode_tstate {
739b95de6daSJustin T. Gibbs 	struct ahc_tmode_lstate*	enabled_luns[AHC_NUM_LUNS];
74056a7c4a8SJustin T. Gibbs 	struct ahc_initiator_tinfo	transinfo[AHC_NUM_TARGETS];
741c5621898SJustin T. Gibbs 
742c5621898SJustin T. Gibbs 	/*
743c5621898SJustin T. Gibbs 	 * Per initiator state bitmasks.
744c5621898SJustin T. Gibbs 	 */
745b95de6daSJustin T. Gibbs 	uint16_t	 auto_negotiate;/* Auto Negotiation Required */
746aa6dfd9dSJustin T. Gibbs 	uint16_t	 ultraenb;	/* Using ultra sync rate  */
747aa6dfd9dSJustin T. Gibbs 	uint16_t	 discenable;	/* Disconnection allowed  */
748aa6dfd9dSJustin T. Gibbs 	uint16_t	 tagenable;	/* Tagged Queuing allowed */
7493bafc9d4SJustin T. Gibbs };
7503bafc9d4SJustin T. Gibbs 
7513bafc9d4SJustin T. Gibbs /*
752717d4247SJustin T. Gibbs  * Data structure for our table of allowed synchronous transfer rates.
7533bafc9d4SJustin T. Gibbs  */
754717d4247SJustin T. Gibbs struct ahc_syncrate {
755717d4247SJustin T. Gibbs 	u_int sxfr_u2;	/* Value of the SXFR parameter for Ultra2+ Chips */
756717d4247SJustin T. Gibbs 	u_int sxfr;	/* Value of the SXFR parameter for <= Ultra Chips */
757717d4247SJustin T. Gibbs #define		ULTRA_SXFR 0x100	/* Rate Requires Ultra Mode set */
758717d4247SJustin T. Gibbs #define		ST_SXFR	   0x010	/* Rate Single Transition Only */
759717d4247SJustin T. Gibbs #define		DT_SXFR	   0x040	/* Rate Double Transition Only */
760717d4247SJustin T. Gibbs 	uint8_t period; /* Period to send to SCSI target */
761717d4247SJustin T. Gibbs 	char *rate;
762717d4247SJustin T. Gibbs };
763717d4247SJustin T. Gibbs 
7644d22994eSScott Long /* Safe and valid period for async negotiations. */
76570b41139SJustin T. Gibbs #define	AHC_ASYNC_XFER_PERIOD 0x45
7664d22994eSScott Long #define	AHC_ULTRA2_XFER_PERIOD 0x0a
7674d22994eSScott Long 
768717d4247SJustin T. Gibbs /*
7697a2b450fSEitan Adler  * Indexes into our table of synchronous transfer rates.
770717d4247SJustin T. Gibbs  */
771717d4247SJustin T. Gibbs #define AHC_SYNCRATE_DT		0
772717d4247SJustin T. Gibbs #define AHC_SYNCRATE_ULTRA2	1
773717d4247SJustin T. Gibbs #define AHC_SYNCRATE_ULTRA	3
774717d4247SJustin T. Gibbs #define AHC_SYNCRATE_FAST	6
77570b41139SJustin T. Gibbs #define AHC_SYNCRATE_MAX	AHC_SYNCRATE_DT
77670b41139SJustin T. Gibbs #define	AHC_SYNCRATE_MIN	13
777717d4247SJustin T. Gibbs 
778717d4247SJustin T. Gibbs /***************************** Lookup Tables **********************************/
779717d4247SJustin T. Gibbs /*
780717d4247SJustin T. Gibbs  * Phase -> name and message out response
781717d4247SJustin T. Gibbs  * to parity errors in each phase table.
782717d4247SJustin T. Gibbs  */
7836fb77fefSJustin T. Gibbs struct ahc_phase_table_entry {
784717d4247SJustin T. Gibbs         uint8_t phase;
785717d4247SJustin T. Gibbs         uint8_t mesg_out; /* Message response to parity errors */
786717d4247SJustin T. Gibbs 	char *phasemsg;
787717d4247SJustin T. Gibbs };
788717d4247SJustin T. Gibbs 
789717d4247SJustin T. Gibbs /************************** Serial EEPROM Format ******************************/
7903bafc9d4SJustin T. Gibbs 
7913bafc9d4SJustin T. Gibbs struct seeprom_config {
7923bafc9d4SJustin T. Gibbs /*
793717d4247SJustin T. Gibbs  * Per SCSI ID Configuration Flags
7943bafc9d4SJustin T. Gibbs  */
795aa6dfd9dSJustin T. Gibbs 	uint16_t device_flags[16];	/* words 0-15 */
7963bafc9d4SJustin T. Gibbs #define		CFXFER		0x0007	/* synchronous transfer rate */
7973bafc9d4SJustin T. Gibbs #define		CFSYNCH		0x0008	/* enable synchronous transfer */
7983bafc9d4SJustin T. Gibbs #define		CFDISC		0x0010	/* enable disconnection */
7993bafc9d4SJustin T. Gibbs #define		CFWIDEB		0x0020	/* wide bus device */
8003bafc9d4SJustin T. Gibbs #define		CFSYNCHISULTRA	0x0040	/* CFSYNCH is an ultra offset (2940AU)*/
801ba099011SJustin T. Gibbs #define		CFSYNCSINGLE	0x0080	/* Single-Transition signalling */
8023bafc9d4SJustin T. Gibbs #define		CFSTART		0x0100	/* send start unit SCSI command */
8033bafc9d4SJustin T. Gibbs #define		CFINCBIOS	0x0200	/* include in BIOS scan */
8043bafc9d4SJustin T. Gibbs #define		CFRNFOUND	0x0400	/* report even if not found */
805aa6dfd9dSJustin T. Gibbs #define		CFMULTILUNDEV	0x0800	/* Probe multiple luns in BIOS scan */
806ba099011SJustin T. Gibbs #define		CFWBCACHEENB	0x4000	/* Enable W-Behind Cache on disks */
807ba099011SJustin T. Gibbs #define		CFWBCACHENOP	0xc000	/* Don't touch W-Behind Cache */
8083bafc9d4SJustin T. Gibbs 
8093bafc9d4SJustin T. Gibbs /*
8103bafc9d4SJustin T. Gibbs  * BIOS Control Bits
8113bafc9d4SJustin T. Gibbs  */
812aa6dfd9dSJustin T. Gibbs 	uint16_t bios_control;		/* word 16 */
8133bafc9d4SJustin T. Gibbs #define		CFSUPREM	0x0001	/* support all removeable drives */
814ba099011SJustin T. Gibbs #define		CFSUPREMB	0x0002	/* support removeable boot drives */
8153bafc9d4SJustin T. Gibbs #define		CFBIOSEN	0x0004	/* BIOS enabled */
81658fb7d8eSJustin T. Gibbs #define		CFBIOS_BUSSCAN	0x0008	/* Have the BIOS Scan the Bus */
8173bafc9d4SJustin T. Gibbs #define		CFSM2DRV	0x0010	/* support more than two drives */
818aa6dfd9dSJustin T. Gibbs #define		CFSTPWLEVEL	0x0010	/* Termination level control */
81958fb7d8eSJustin T. Gibbs #define		CF284XEXTEND	0x0020	/* extended translation (284x cards) */
82058fb7d8eSJustin T. Gibbs #define		CFCTRL_A	0x0020	/* BIOS displays Ctrl-A message */
82158fb7d8eSJustin T. Gibbs #define		CFTERM_MENU	0x0040	/* BIOS displays termination menu */
8223bafc9d4SJustin T. Gibbs #define		CFEXTEND	0x0080	/* extended translation enabled */
823aa6dfd9dSJustin T. Gibbs #define		CFSCAMEN	0x0100	/* SCAM enable */
82458fb7d8eSJustin T. Gibbs #define		CFMSG_LEVEL	0x0600	/* BIOS Message Level */
82558fb7d8eSJustin T. Gibbs #define			CFMSG_VERBOSE	0x0000
82658fb7d8eSJustin T. Gibbs #define			CFMSG_SILENT	0x0200
82758fb7d8eSJustin T. Gibbs #define			CFMSG_DIAG	0x0400
82858fb7d8eSJustin T. Gibbs #define		CFBOOTCD	0x0800  /* Support Bootable CD-ROM */
8293bafc9d4SJustin T. Gibbs /*		UNUSED		0xff00	*/
8303bafc9d4SJustin T. Gibbs 
8313bafc9d4SJustin T. Gibbs /*
8323bafc9d4SJustin T. Gibbs  * Host Adapter Control Bits
8333bafc9d4SJustin T. Gibbs  */
834aa6dfd9dSJustin T. Gibbs 	uint16_t adapter_control;	/* word 17 */
8353bafc9d4SJustin T. Gibbs #define		CFAUTOTERM	0x0001	/* Perform Auto termination */
8363bafc9d4SJustin T. Gibbs #define		CFULTRAEN	0x0002	/* Ultra SCSI speed enable */
8373bafc9d4SJustin T. Gibbs #define		CF284XSELTO     0x0003	/* Selection timeout (284x cards) */
8383bafc9d4SJustin T. Gibbs #define		CF284XFIFO      0x000C	/* FIFO Threshold (284x cards) */
8393bafc9d4SJustin T. Gibbs #define		CFSTERM		0x0004	/* SCSI low byte termination */
8403bafc9d4SJustin T. Gibbs #define		CFWSTERM	0x0008	/* SCSI high byte termination */
8413bafc9d4SJustin T. Gibbs #define		CFSPARITY	0x0010	/* SCSI parity */
8423bafc9d4SJustin T. Gibbs #define		CF284XSTERM     0x0020	/* SCSI low byte term (284x cards) */
84358fb7d8eSJustin T. Gibbs #define		CFMULTILUN	0x0020
8443bafc9d4SJustin T. Gibbs #define		CFRESETB	0x0040	/* reset SCSI bus at boot */
845aa6dfd9dSJustin T. Gibbs #define		CFCLUSTERENB	0x0080	/* Cluster Enable */
8466fb77fefSJustin T. Gibbs #define		CFBOOTCHAN	0x0300	/* probe this channel first */
8476fb77fefSJustin T. Gibbs #define		CFBOOTCHANSHIFT 8
848aa6dfd9dSJustin T. Gibbs #define		CFSEAUTOTERM	0x0400	/* Ultra2 Perform secondary Auto Term*/
849aa6dfd9dSJustin T. Gibbs #define		CFSELOWTERM	0x0800	/* Ultra2 secondary low term */
850aa6dfd9dSJustin T. Gibbs #define		CFSEHIGHTERM	0x1000	/* Ultra2 secondary high term */
8514d22994eSScott Long #define		CFENABLEDV	0x4000	/* Perform Domain Validation*/
8523bafc9d4SJustin T. Gibbs 
8533bafc9d4SJustin T. Gibbs /*
854717d4247SJustin T. Gibbs  * Bus Release Time, Host Adapter ID
8553bafc9d4SJustin T. Gibbs  */
856aa6dfd9dSJustin T. Gibbs 	uint16_t brtime_id;		/* word 18 */
8573bafc9d4SJustin T. Gibbs #define		CFSCSIID	0x000f	/* host adapter SCSI ID */
8583bafc9d4SJustin T. Gibbs /*		UNUSED		0x00f0	*/
8593bafc9d4SJustin T. Gibbs #define		CFBRTIME	0xff00	/* bus release time */
8603bafc9d4SJustin T. Gibbs 
8613bafc9d4SJustin T. Gibbs /*
8623bafc9d4SJustin T. Gibbs  * Maximum targets
8633bafc9d4SJustin T. Gibbs  */
864aa6dfd9dSJustin T. Gibbs 	uint16_t max_targets;		/* word 19 */
8653bafc9d4SJustin T. Gibbs #define		CFMAXTARG	0x00ff	/* maximum targets */
866aa6dfd9dSJustin T. Gibbs #define		CFBOOTLUN	0x0f00	/* Lun to boot from */
867aa6dfd9dSJustin T. Gibbs #define		CFBOOTID	0xf000	/* Target to boot from */
868aa6dfd9dSJustin T. Gibbs 	uint16_t res_1[10];		/* words 20-29 */
869aa6dfd9dSJustin T. Gibbs 	uint16_t signature;		/* Signature == 0x250 */
870aa6dfd9dSJustin T. Gibbs #define		CFSIGNATURE	0x250
8716fb77fefSJustin T. Gibbs #define		CFSIGNATURE2	0x300
872aa6dfd9dSJustin T. Gibbs 	uint16_t checksum;		/* word 31 */
8733bafc9d4SJustin T. Gibbs };
8743bafc9d4SJustin T. Gibbs 
875717d4247SJustin T. Gibbs /****************************  Message Buffer *********************************/
8763bafc9d4SJustin T. Gibbs typedef enum {
8773bafc9d4SJustin T. Gibbs 	MSG_TYPE_NONE			= 0x00,
8783bafc9d4SJustin T. Gibbs 	MSG_TYPE_INITIATOR_MSGOUT	= 0x01,
8794dd5dcaeSJustin T. Gibbs 	MSG_TYPE_INITIATOR_MSGIN	= 0x02,
8804dd5dcaeSJustin T. Gibbs 	MSG_TYPE_TARGET_MSGOUT		= 0x03,
8814dd5dcaeSJustin T. Gibbs 	MSG_TYPE_TARGET_MSGIN		= 0x04
8823bafc9d4SJustin T. Gibbs } ahc_msg_type;
8833bafc9d4SJustin T. Gibbs 
884717d4247SJustin T. Gibbs typedef enum {
885717d4247SJustin T. Gibbs 	MSGLOOP_IN_PROG,
886717d4247SJustin T. Gibbs 	MSGLOOP_MSGCOMPLETE,
887717d4247SJustin T. Gibbs 	MSGLOOP_TERMINATED
888717d4247SJustin T. Gibbs } msg_loop_stat;
88900fa2b1fSJustin T. Gibbs 
890717d4247SJustin T. Gibbs /*********************** Software Configuration Structure *********************/
891aa6dfd9dSJustin T. Gibbs TAILQ_HEAD(scb_tailq, scb);
892aa6dfd9dSJustin T. Gibbs 
8939bf327a7SJustin T. Gibbs struct ahc_aic7770_softc {
8949bf327a7SJustin T. Gibbs 	/*
8959bf327a7SJustin T. Gibbs 	 * Saved register state used for chip_init().
8969bf327a7SJustin T. Gibbs 	 */
8979bf327a7SJustin T. Gibbs 	uint8_t busspd;
8989bf327a7SJustin T. Gibbs 	uint8_t bustime;
899f8838555SJustin T. Gibbs };
900f8838555SJustin T. Gibbs 
9019bf327a7SJustin T. Gibbs struct ahc_pci_softc {
9029bf327a7SJustin T. Gibbs 	/*
9039bf327a7SJustin T. Gibbs 	 * Saved register state used for chip_init().
9049bf327a7SJustin T. Gibbs 	 */
9059bf327a7SJustin T. Gibbs 	uint32_t  devconfig;
9069bf327a7SJustin T. Gibbs 	uint16_t  targcrccnt;
9079bf327a7SJustin T. Gibbs 	uint8_t   command;
9089bf327a7SJustin T. Gibbs 	uint8_t   csize_lattime;
909f8838555SJustin T. Gibbs 	uint8_t   optionmode;
9109bf327a7SJustin T. Gibbs 	uint8_t   crccontrol1;
91156a7c4a8SJustin T. Gibbs 	uint8_t   dscommand0;
91256a7c4a8SJustin T. Gibbs 	uint8_t   dspcistatus;
91356a7c4a8SJustin T. Gibbs 	uint8_t   scbbaddr;
91456a7c4a8SJustin T. Gibbs 	uint8_t   dff_thrsh;
9159bf327a7SJustin T. Gibbs };
9169bf327a7SJustin T. Gibbs 
9179bf327a7SJustin T. Gibbs union ahc_bus_softc {
9189bf327a7SJustin T. Gibbs 	struct ahc_aic7770_softc aic7770_softc;
9199bf327a7SJustin T. Gibbs 	struct ahc_pci_softc pci_softc;
92056a7c4a8SJustin T. Gibbs };
92156a7c4a8SJustin T. Gibbs 
922b95de6daSJustin T. Gibbs typedef void (*ahc_bus_intr_t)(struct ahc_softc *);
9239bf327a7SJustin T. Gibbs typedef int (*ahc_bus_chip_init_t)(struct ahc_softc *);
9249bf327a7SJustin T. Gibbs typedef int (*ahc_bus_suspend_t)(struct ahc_softc *);
9259bf327a7SJustin T. Gibbs typedef int (*ahc_bus_resume_t)(struct ahc_softc *);
9264d22994eSScott Long typedef void ahc_callback_t (void *);
927b95de6daSJustin T. Gibbs 
9287afc0218SJustin T. Gibbs #define AIC_SCB_DATA(softc) ((softc)->scb_data)
9297afc0218SJustin T. Gibbs 
9303bafc9d4SJustin T. Gibbs struct ahc_softc {
9313bafc9d4SJustin T. Gibbs 	bus_space_tag_t           tag;
9323bafc9d4SJustin T. Gibbs 	bus_space_handle_t        bsh;
93300fa2b1fSJustin T. Gibbs 	bus_dma_tag_t		  buffer_dmat;   /* dmat for buffer I/O */
9343bafc9d4SJustin T. Gibbs 	struct scb_data		 *scb_data;
9353bafc9d4SJustin T. Gibbs 
936a49630acSJustin T. Gibbs 	struct scb		 *next_queued_scb;
937a49630acSJustin T. Gibbs 
9383bafc9d4SJustin T. Gibbs 	/*
939717d4247SJustin T. Gibbs 	 * SCBs that have been sent to the controller
9403bafc9d4SJustin T. Gibbs 	 */
941717d4247SJustin T. Gibbs 	LIST_HEAD(, scb)	  pending_scbs;
9423bafc9d4SJustin T. Gibbs 
9433bafc9d4SJustin T. Gibbs 	/*
944b3b25f2cSJustin T. Gibbs 	 * SCBs whose timeout routine has been called.
945b3b25f2cSJustin T. Gibbs 	 */
946b3b25f2cSJustin T. Gibbs 	LIST_HEAD(, scb)	  timedout_scbs;
947b3b25f2cSJustin T. Gibbs 
948b3b25f2cSJustin T. Gibbs 	/*
949aa6dfd9dSJustin T. Gibbs 	 * Counting lock for deferring the release of additional
950aa6dfd9dSJustin T. Gibbs 	 * untagged transactions from the untagged_queues.  When
951aa6dfd9dSJustin T. Gibbs 	 * the lock is decremented to 0, all queues in the
952aa6dfd9dSJustin T. Gibbs 	 * untagged_queues array are run.
953aa6dfd9dSJustin T. Gibbs 	 */
954aa6dfd9dSJustin T. Gibbs 	u_int			  untagged_queue_lock;
955aa6dfd9dSJustin T. Gibbs 
956aa6dfd9dSJustin T. Gibbs 	/*
957aa6dfd9dSJustin T. Gibbs 	 * Per-target queue of untagged-transactions.  The
958aa6dfd9dSJustin T. Gibbs 	 * transaction at the head of the queue is the
959aa6dfd9dSJustin T. Gibbs 	 * currently pending untagged transaction for the
960aa6dfd9dSJustin T. Gibbs 	 * target.  The driver only allows a single untagged
961aa6dfd9dSJustin T. Gibbs 	 * transaction per target.
962aa6dfd9dSJustin T. Gibbs 	 */
96356a7c4a8SJustin T. Gibbs 	struct scb_tailq	  untagged_queues[AHC_NUM_TARGETS];
964aa6dfd9dSJustin T. Gibbs 
965aa6dfd9dSJustin T. Gibbs 	/*
9669bf327a7SJustin T. Gibbs 	 * Bus attachment specific data.
9679bf327a7SJustin T. Gibbs 	 */
9689bf327a7SJustin T. Gibbs 	union ahc_bus_softc	  bus_softc;
9699bf327a7SJustin T. Gibbs 
9709bf327a7SJustin T. Gibbs 	/*
971717d4247SJustin T. Gibbs 	 * Platform specific data.
972717d4247SJustin T. Gibbs 	 */
973717d4247SJustin T. Gibbs 	struct ahc_platform_data *platform_data;
974717d4247SJustin T. Gibbs 
975717d4247SJustin T. Gibbs 	/*
976717d4247SJustin T. Gibbs 	 * Platform specific device information.
977717d4247SJustin T. Gibbs 	 */
978b3b25f2cSJustin T. Gibbs 	aic_dev_softc_t		  dev_softc;
979717d4247SJustin T. Gibbs 
980717d4247SJustin T. Gibbs 	/*
981b95de6daSJustin T. Gibbs 	 * Bus specific device information.
982b95de6daSJustin T. Gibbs 	 */
983b95de6daSJustin T. Gibbs 	ahc_bus_intr_t		  bus_intr;
984b95de6daSJustin T. Gibbs 
985b95de6daSJustin T. Gibbs 	/*
9869bf327a7SJustin T. Gibbs 	 * Bus specific initialization required
9879bf327a7SJustin T. Gibbs 	 * after a chip reset.
9889bf327a7SJustin T. Gibbs 	 */
9899bf327a7SJustin T. Gibbs 	ahc_bus_chip_init_t	  bus_chip_init;
9909bf327a7SJustin T. Gibbs 
9919bf327a7SJustin T. Gibbs 	/*
9929bf327a7SJustin T. Gibbs 	 * Bus specific suspend routine.
9939bf327a7SJustin T. Gibbs 	 */
9949bf327a7SJustin T. Gibbs 	ahc_bus_suspend_t	  bus_suspend;
9959bf327a7SJustin T. Gibbs 
9969bf327a7SJustin T. Gibbs 	/*
9979bf327a7SJustin T. Gibbs 	 * Bus specific resume routine.
9989bf327a7SJustin T. Gibbs 	 */
9999bf327a7SJustin T. Gibbs 	ahc_bus_resume_t	  bus_resume;
10009bf327a7SJustin T. Gibbs 
10019bf327a7SJustin T. Gibbs 	/*
10023bafc9d4SJustin T. Gibbs 	 * Target mode related state kept on a per enabled lun basis.
10033bafc9d4SJustin T. Gibbs 	 * Targets that are not enabled will have null entries.
1004c5621898SJustin T. Gibbs 	 * As an initiator, we keep one target entry for our initiator
1005c5621898SJustin T. Gibbs 	 * ID to store our sync/wide transfer settings.
10063bafc9d4SJustin T. Gibbs 	 */
1007b95de6daSJustin T. Gibbs 	struct ahc_tmode_tstate  *enabled_targets[AHC_NUM_TARGETS];
10083bafc9d4SJustin T. Gibbs 
10093bafc9d4SJustin T. Gibbs 	/*
1010863c6026SJustin T. Gibbs 	 * The black hole device responsible for handling requests for
1011863c6026SJustin T. Gibbs 	 * disabled luns on enabled targets.
1012863c6026SJustin T. Gibbs 	 */
1013b95de6daSJustin T. Gibbs 	struct ahc_tmode_lstate  *black_hole;
1014863c6026SJustin T. Gibbs 
1015863c6026SJustin T. Gibbs 	/*
10163bafc9d4SJustin T. Gibbs 	 * Device instance currently on the bus awaiting a continue TIO
10173bafc9d4SJustin T. Gibbs 	 * for a command that was not given the disconnect priveledge.
10183bafc9d4SJustin T. Gibbs 	 */
1019b95de6daSJustin T. Gibbs 	struct ahc_tmode_lstate  *pending_device;
10203bafc9d4SJustin T. Gibbs 
10213bafc9d4SJustin T. Gibbs 	/*
10223bafc9d4SJustin T. Gibbs 	 * Card characteristics
10233bafc9d4SJustin T. Gibbs 	 */
10243bafc9d4SJustin T. Gibbs 	ahc_chip		  chip;
10253bafc9d4SJustin T. Gibbs 	ahc_feature		  features;
1026aa6dfd9dSJustin T. Gibbs 	ahc_bug			  bugs;
10273bafc9d4SJustin T. Gibbs 	ahc_flag		  flags;
10283b06611aSJustin T. Gibbs 	struct seeprom_config	 *seep_config;
10293bafc9d4SJustin T. Gibbs 
10303bafc9d4SJustin T. Gibbs 	/* Values to store in the SEQCTL register for pause and unpause */
1031aa6dfd9dSJustin T. Gibbs 	uint8_t			  unpause;
1032aa6dfd9dSJustin T. Gibbs 	uint8_t			  pause;
10333bafc9d4SJustin T. Gibbs 
10343bafc9d4SJustin T. Gibbs 	/* Command Queues */
1035aa6dfd9dSJustin T. Gibbs 	uint8_t			  qoutfifonext;
1036aa6dfd9dSJustin T. Gibbs 	uint8_t			  qinfifonext;
1037aa6dfd9dSJustin T. Gibbs 	uint8_t			 *qoutfifo;
1038aa6dfd9dSJustin T. Gibbs 	uint8_t			 *qinfifo;
10393bafc9d4SJustin T. Gibbs 
1040a49630acSJustin T. Gibbs 	/* Critical Section Data */
1041a49630acSJustin T. Gibbs 	struct cs		 *critical_sections;
1042a49630acSJustin T. Gibbs 	u_int			  num_critical_sections;
1043a49630acSJustin T. Gibbs 
1044717d4247SJustin T. Gibbs 	/* Links for chaining softcs */
1045717d4247SJustin T. Gibbs 	TAILQ_ENTRY(ahc_softc)	  links;
10463bafc9d4SJustin T. Gibbs 
10473bafc9d4SJustin T. Gibbs 	/* Channel Names ('A', 'B', etc.) */
10483bafc9d4SJustin T. Gibbs 	char			  channel;
10493bafc9d4SJustin T. Gibbs 	char			  channel_b;
10503bafc9d4SJustin T. Gibbs 
10513bafc9d4SJustin T. Gibbs 	/* Initiator Bus ID */
1052aa6dfd9dSJustin T. Gibbs 	uint8_t			  our_id;
1053aa6dfd9dSJustin T. Gibbs 	uint8_t			  our_id_b;
10543bafc9d4SJustin T. Gibbs 
10553bafc9d4SJustin T. Gibbs 	/*
1056717d4247SJustin T. Gibbs 	 * PCI error detection.
10573bafc9d4SJustin T. Gibbs 	 */
10583bafc9d4SJustin T. Gibbs 	int			  unsolicited_ints;
10593bafc9d4SJustin T. Gibbs 
106008c6fbfaSJustin T. Gibbs 	/*
106108c6fbfaSJustin T. Gibbs 	 * Target incoming command FIFO.
106208c6fbfaSJustin T. Gibbs 	 */
10633bafc9d4SJustin T. Gibbs 	struct target_cmd	 *targetcmds;
1064aa6dfd9dSJustin T. Gibbs 	uint8_t			  tqinfifonext;
10653bafc9d4SJustin T. Gibbs 
10663bafc9d4SJustin T. Gibbs 	/*
1067e4e6e6d6SJustin T. Gibbs 	 * Cached copy of the sequencer control register.
1068e4e6e6d6SJustin T. Gibbs 	 */
1069e4e6e6d6SJustin T. Gibbs 	uint8_t			  seqctl;
1070e4e6e6d6SJustin T. Gibbs 
1071e4e6e6d6SJustin T. Gibbs 	/*
10723bafc9d4SJustin T. Gibbs 	 * Incoming and outgoing message handling.
10733bafc9d4SJustin T. Gibbs 	 */
1074aa6dfd9dSJustin T. Gibbs 	uint8_t			  send_msg_perror;
10753bafc9d4SJustin T. Gibbs 	ahc_msg_type		  msg_type;
1076c498406dSJustin T. Gibbs 	uint8_t			  msgout_buf[12];/* Message we are sending */
1077c498406dSJustin T. Gibbs 	uint8_t			  msgin_buf[12];/* Message we are receiving */
10784dd5dcaeSJustin T. Gibbs 	u_int			  msgout_len;	/* Length of message to send */
10794dd5dcaeSJustin T. Gibbs 	u_int			  msgout_index;	/* Current index in msgout */
10804dd5dcaeSJustin T. Gibbs 	u_int			  msgin_index;	/* Current index in msgin */
10813bafc9d4SJustin T. Gibbs 
1082717d4247SJustin T. Gibbs 	/*
1083717d4247SJustin T. Gibbs 	 * Mapping information for data structures shared
1084717d4247SJustin T. Gibbs 	 * between the sequencer and kernel.
1085717d4247SJustin T. Gibbs 	 */
108600fa2b1fSJustin T. Gibbs 	bus_dma_tag_t		  parent_dmat;
108700fa2b1fSJustin T. Gibbs 	bus_dma_tag_t		  shared_data_dmat;
108800fa2b1fSJustin T. Gibbs 	bus_dmamap_t		  shared_data_dmamap;
108900fa2b1fSJustin T. Gibbs 	bus_addr_t		  shared_data_busaddr;
1090717d4247SJustin T. Gibbs 
1091717d4247SJustin T. Gibbs 	/*
1092717d4247SJustin T. Gibbs 	 * Bus address of the one byte buffer used to
1093717d4247SJustin T. Gibbs 	 * work-around a DMA bug for chips <= aic7880
1094717d4247SJustin T. Gibbs 	 * in target mode.
1095717d4247SJustin T. Gibbs 	 */
109685ac786bSJustin T. Gibbs 	bus_addr_t		  dma_bug_buf;
109700fa2b1fSJustin T. Gibbs 
1098c5621898SJustin T. Gibbs 	/* Number of enabled target mode device on this card */
1099863c6026SJustin T. Gibbs 	u_int			  enabled_luns;
1100863c6026SJustin T. Gibbs 
110100fa2b1fSJustin T. Gibbs 	/* Initialization level of this data structure */
110200fa2b1fSJustin T. Gibbs 	u_int			  init_level;
11037457cf2dSJustin T. Gibbs 
1104717d4247SJustin T. Gibbs 	/* PCI cacheline size. */
1105717d4247SJustin T. Gibbs 	u_int			  pci_cachesize;
1106717d4247SJustin T. Gibbs 
11079bf327a7SJustin T. Gibbs 	/*
11089bf327a7SJustin T. Gibbs 	 * Count of parity errors we have seen as a target.
11099bf327a7SJustin T. Gibbs 	 * We auto-disable parity error checking after seeing
11109bf327a7SJustin T. Gibbs 	 * AHC_PCI_TARGET_PERR_THRESH number of errors.
11119bf327a7SJustin T. Gibbs 	 */
11129bf327a7SJustin T. Gibbs 	u_int			  pci_target_perr_count;
11139bf327a7SJustin T. Gibbs #define		AHC_PCI_TARGET_PERR_THRESH	10
11149bf327a7SJustin T. Gibbs 
11159bf327a7SJustin T. Gibbs 	/* Maximum number of sequencer instructions supported. */
11169bf327a7SJustin T. Gibbs 	u_int			  instruction_ram_size;
11174d22994eSScott Long 
1118717d4247SJustin T. Gibbs 	/* Per-Unit descriptive information */
1119717d4247SJustin T. Gibbs 	const char		 *description;
1120717d4247SJustin T. Gibbs 	char			 *name;
1121717d4247SJustin T. Gibbs 	int			  unit;
1122717d4247SJustin T. Gibbs 
1123f8838555SJustin T. Gibbs 	/* Selection Timer settings */
1124f8838555SJustin T. Gibbs 	int			  seltime;
1125f8838555SJustin T. Gibbs 	int			  seltime_b;
1126f8838555SJustin T. Gibbs 
1127aa6dfd9dSJustin T. Gibbs 	uint16_t	 	  user_discenable;/* Disconnection allowed  */
1128aa6dfd9dSJustin T. Gibbs 	uint16_t		  user_tagenable;/* Tagged Queuing allowed */
11293bafc9d4SJustin T. Gibbs };
11303bafc9d4SJustin T. Gibbs 
1131717d4247SJustin T. Gibbs TAILQ_HEAD(ahc_softc_tailq, ahc_softc);
1132717d4247SJustin T. Gibbs extern struct ahc_softc_tailq ahc_tailq;
1133717d4247SJustin T. Gibbs 
1134717d4247SJustin T. Gibbs /************************ Active Device Information ***************************/
1135717d4247SJustin T. Gibbs typedef enum {
1136717d4247SJustin T. Gibbs 	ROLE_UNKNOWN,
1137717d4247SJustin T. Gibbs 	ROLE_INITIATOR,
1138717d4247SJustin T. Gibbs 	ROLE_TARGET
1139717d4247SJustin T. Gibbs } role_t;
1140717d4247SJustin T. Gibbs 
1141717d4247SJustin T. Gibbs struct ahc_devinfo {
1142717d4247SJustin T. Gibbs 	int	 our_scsiid;
1143717d4247SJustin T. Gibbs 	int	 target_offset;
1144717d4247SJustin T. Gibbs 	uint16_t target_mask;
1145717d4247SJustin T. Gibbs 	u_int	 target;
1146717d4247SJustin T. Gibbs 	u_int	 lun;
1147717d4247SJustin T. Gibbs 	char	 channel;
1148717d4247SJustin T. Gibbs 	role_t	 role;		/*
1149717d4247SJustin T. Gibbs 				 * Only guaranteed to be correct if not
1150717d4247SJustin T. Gibbs 				 * in the busfree state.
1151717d4247SJustin T. Gibbs 				 */
11523bafc9d4SJustin T. Gibbs };
11533bafc9d4SJustin T. Gibbs 
1154717d4247SJustin T. Gibbs /****************************** PCI Structures ********************************/
1155b3b25f2cSJustin T. Gibbs #define	AHC_PCI_IOADDR  PCIR_BAR(0)	/* I/O Address */
1156b3b25f2cSJustin T. Gibbs #define	AHC_PCI_MEMADDR PCIR_BAR(1)	/* Mem I/O Address */
1157b3b25f2cSJustin T. Gibbs 
1158cd036e89SJustin T. Gibbs typedef int (ahc_device_setup_t)(struct ahc_softc *);
11593bafc9d4SJustin T. Gibbs 
1160717d4247SJustin T. Gibbs struct ahc_pci_identity {
1161717d4247SJustin T. Gibbs 	uint64_t		 full_id;
1162717d4247SJustin T. Gibbs 	uint64_t		 id_mask;
1163717d4247SJustin T. Gibbs 	char			*name;
1164717d4247SJustin T. Gibbs 	ahc_device_setup_t	*setup;
1165717d4247SJustin T. Gibbs };
1166717d4247SJustin T. Gibbs extern struct ahc_pci_identity ahc_pci_ident_table[];
116756a7c4a8SJustin T. Gibbs extern const u_int ahc_num_pci_devs;
11683bafc9d4SJustin T. Gibbs 
1169a4e4cebfSWarner Losh /*************************** VL/EISA/ISA Declarations *************************/
1170717d4247SJustin T. Gibbs struct aic7770_identity {
1171717d4247SJustin T. Gibbs 	uint32_t		 full_id;
1172717d4247SJustin T. Gibbs 	uint32_t		 id_mask;
1173d6b641deSJustin T. Gibbs 	const char		*name;
1174717d4247SJustin T. Gibbs 	ahc_device_setup_t	*setup;
1175717d4247SJustin T. Gibbs };
1176717d4247SJustin T. Gibbs extern struct aic7770_identity aic7770_ident_table[];
1177717d4247SJustin T. Gibbs extern const int ahc_num_aic7770_devs;
11783bafc9d4SJustin T. Gibbs 
1179eaa73a36SJustin T. Gibbs #define AHC_EISA_SLOT_SIZE	0x1000
1180717d4247SJustin T. Gibbs #define AHC_EISA_SLOT_OFFSET	0xc00
1181717d4247SJustin T. Gibbs #define AHC_EISA_IOSIZE		0x100
11823bafc9d4SJustin T. Gibbs 
1183717d4247SJustin T. Gibbs /*************************** Function Declarations ****************************/
1184717d4247SJustin T. Gibbs /******************************************************************************/
118556a7c4a8SJustin T. Gibbs u_int			ahc_index_busy_tcl(struct ahc_softc *ahc, u_int tcl);
118656a7c4a8SJustin T. Gibbs void			ahc_unbusy_tcl(struct ahc_softc *ahc, u_int tcl);
118756a7c4a8SJustin T. Gibbs void			ahc_busy_tcl(struct ahc_softc *ahc,
118856a7c4a8SJustin T. Gibbs 				     u_int tcl, u_int busyid);
11893bafc9d4SJustin T. Gibbs 
1190717d4247SJustin T. Gibbs /***************************** PCI Front End *********************************/
1191b3b25f2cSJustin T. Gibbs struct ahc_pci_identity	*ahc_find_pci_device(aic_dev_softc_t);
1192717d4247SJustin T. Gibbs int			 ahc_pci_config(struct ahc_softc *,
1193717d4247SJustin T. Gibbs 					struct ahc_pci_identity *);
11944d22994eSScott Long int			 ahc_pci_test_register_access(struct ahc_softc *);
119541c47eeeSJustin T. Gibbs 
1196a4e4cebfSWarner Losh /*************************** ISA/EISA/VL Front End ****************************/
1197717d4247SJustin T. Gibbs struct aic7770_identity *aic7770_find_device(uint32_t);
1198717d4247SJustin T. Gibbs int			 aic7770_config(struct ahc_softc *ahc,
11998f214efcSJustin T. Gibbs 					struct aic7770_identity *,
12008f214efcSJustin T. Gibbs 					u_int port);
1201aa6dfd9dSJustin T. Gibbs 
1202717d4247SJustin T. Gibbs /************************** SCB and SCB queue management **********************/
1203aa6dfd9dSJustin T. Gibbs int		ahc_probe_scbs(struct ahc_softc *);
1204717d4247SJustin T. Gibbs void		ahc_run_untagged_queues(struct ahc_softc *ahc);
1205717d4247SJustin T. Gibbs void		ahc_run_untagged_queue(struct ahc_softc *ahc,
1206717d4247SJustin T. Gibbs 				       struct scb_tailq *queue);
1207dd1290f0SJustin T. Gibbs void		ahc_qinfifo_requeue_tail(struct ahc_softc *ahc,
1208039c6f36SJustin T. Gibbs 					 struct scb *scb);
1209dd1290f0SJustin T. Gibbs int		ahc_match_scb(struct ahc_softc *ahc, struct scb *scb,
1210dd1290f0SJustin T. Gibbs 			      int target, char channel, int lun,
1211dd1290f0SJustin T. Gibbs 			      u_int tag, role_t role);
1212aa6dfd9dSJustin T. Gibbs 
1213717d4247SJustin T. Gibbs /****************************** Initialization ********************************/
1214717d4247SJustin T. Gibbs struct ahc_softc	*ahc_alloc(void *platform_arg, char *name);
1215cd036e89SJustin T. Gibbs int			 ahc_softc_init(struct ahc_softc *);
1216717d4247SJustin T. Gibbs void			 ahc_controller_info(struct ahc_softc *ahc, char *buf);
12179bf327a7SJustin T. Gibbs int			 ahc_chip_init(struct ahc_softc *ahc);
1218717d4247SJustin T. Gibbs int			 ahc_init(struct ahc_softc *ahc);
1219b95de6daSJustin T. Gibbs void			 ahc_intr_enable(struct ahc_softc *ahc, int enable);
122056a7c4a8SJustin T. Gibbs void			 ahc_pause_and_flushwork(struct ahc_softc *ahc);
122156a7c4a8SJustin T. Gibbs int			 ahc_suspend(struct ahc_softc *ahc);
122256a7c4a8SJustin T. Gibbs int			 ahc_resume(struct ahc_softc *ahc);
1223717d4247SJustin T. Gibbs void			 ahc_softc_insert(struct ahc_softc *);
1224717d4247SJustin T. Gibbs void			 ahc_set_unit(struct ahc_softc *, int);
1225717d4247SJustin T. Gibbs void			 ahc_set_name(struct ahc_softc *, char *);
12267628acd8SScott Long int			 ahc_alloc_scbs(struct ahc_softc *ahc);
1227717d4247SJustin T. Gibbs void			 ahc_free(struct ahc_softc *ahc);
12281d528d67SJustin T. Gibbs int			 ahc_reset(struct ahc_softc *ahc, int reinit);
1229717d4247SJustin T. Gibbs void			 ahc_shutdown(void *arg);
1230aa6dfd9dSJustin T. Gibbs 
1231717d4247SJustin T. Gibbs /*************************** Interrupt Services *******************************/
1232717d4247SJustin T. Gibbs void			ahc_clear_intstat(struct ahc_softc *ahc);
1233717d4247SJustin T. Gibbs void			ahc_run_qoutfifo(struct ahc_softc *ahc);
1234717d4247SJustin T. Gibbs #ifdef AHC_TARGET_MODE
1235717d4247SJustin T. Gibbs void			ahc_run_tqinfifo(struct ahc_softc *ahc, int paused);
1236717d4247SJustin T. Gibbs #endif
1237717d4247SJustin T. Gibbs void			ahc_handle_brkadrint(struct ahc_softc *ahc);
1238717d4247SJustin T. Gibbs void			ahc_handle_seqint(struct ahc_softc *ahc, u_int intstat);
1239717d4247SJustin T. Gibbs void			ahc_handle_scsiint(struct ahc_softc *ahc,
1240717d4247SJustin T. Gibbs 					   u_int intstat);
1241a49630acSJustin T. Gibbs void			ahc_clear_critical_section(struct ahc_softc *ahc);
1242aa6dfd9dSJustin T. Gibbs 
1243717d4247SJustin T. Gibbs /***************************** Error Recovery *********************************/
1244717d4247SJustin T. Gibbs typedef enum {
1245717d4247SJustin T. Gibbs 	SEARCH_COMPLETE,
1246717d4247SJustin T. Gibbs 	SEARCH_COUNT,
1247717d4247SJustin T. Gibbs 	SEARCH_REMOVE
1248717d4247SJustin T. Gibbs } ahc_search_action;
1249717d4247SJustin T. Gibbs int			ahc_search_qinfifo(struct ahc_softc *ahc, int target,
1250717d4247SJustin T. Gibbs 					   char channel, int lun, u_int tag,
1251717d4247SJustin T. Gibbs 					   role_t role, uint32_t status,
1252717d4247SJustin T. Gibbs 					   ahc_search_action action);
12533b06611aSJustin T. Gibbs int			ahc_search_untagged_queues(struct ahc_softc *ahc,
1254b3b25f2cSJustin T. Gibbs 						   aic_io_ctx_t ctx,
12553b06611aSJustin T. Gibbs 						   int target, char channel,
12563b06611aSJustin T. Gibbs 						   int lun, uint32_t status,
12573b06611aSJustin T. Gibbs 						   ahc_search_action action);
1258717d4247SJustin T. Gibbs int			ahc_search_disc_list(struct ahc_softc *ahc, int target,
1259717d4247SJustin T. Gibbs 					     char channel, int lun, u_int tag,
1260717d4247SJustin T. Gibbs 					     int stop_on_first, int remove,
1261717d4247SJustin T. Gibbs 					     int save_state);
1262717d4247SJustin T. Gibbs void			ahc_freeze_devq(struct ahc_softc *ahc, struct scb *scb);
1263717d4247SJustin T. Gibbs int			ahc_reset_channel(struct ahc_softc *ahc, char channel,
1264717d4247SJustin T. Gibbs 					  int initiate_reset);
12658f214efcSJustin T. Gibbs int			ahc_abort_scbs(struct ahc_softc *ahc, int target,
12668f214efcSJustin T. Gibbs 				       char channel, int lun, u_int tag,
12678f214efcSJustin T. Gibbs 				       role_t role, uint32_t status);
12686fb77fefSJustin T. Gibbs void			ahc_restart(struct ahc_softc *ahc);
12698f214efcSJustin T. Gibbs void			ahc_calc_residual(struct ahc_softc *ahc,
12708f214efcSJustin T. Gibbs 					  struct scb *scb);
1271b3b25f2cSJustin T. Gibbs void			ahc_timeout(struct scb *scb);
1272b3b25f2cSJustin T. Gibbs void			ahc_recover_commands(struct ahc_softc *ahc);
1273717d4247SJustin T. Gibbs /*************************** Utility Functions ********************************/
12746fb77fefSJustin T. Gibbs struct ahc_phase_table_entry*
12756fb77fefSJustin T. Gibbs 			ahc_lookup_phase_entry(int phase);
1276717d4247SJustin T. Gibbs void			ahc_compile_devinfo(struct ahc_devinfo *devinfo,
1277717d4247SJustin T. Gibbs 					    u_int our_id, u_int target,
1278717d4247SJustin T. Gibbs 					    u_int lun, char channel,
1279717d4247SJustin T. Gibbs 					    role_t role);
1280717d4247SJustin T. Gibbs /************************** Transfer Negotiation ******************************/
1281717d4247SJustin T. Gibbs struct ahc_syncrate*	ahc_find_syncrate(struct ahc_softc *ahc, u_int *period,
1282717d4247SJustin T. Gibbs 					  u_int *ppr_options, u_int maxsync);
1283717d4247SJustin T. Gibbs u_int			ahc_find_period(struct ahc_softc *ahc,
1284717d4247SJustin T. Gibbs 					u_int scsirate, u_int maxsync);
1285717d4247SJustin T. Gibbs void			ahc_validate_offset(struct ahc_softc *ahc,
1286dd1290f0SJustin T. Gibbs 					    struct ahc_initiator_tinfo *tinfo,
1287717d4247SJustin T. Gibbs 					    struct ahc_syncrate *syncrate,
1288dd1290f0SJustin T. Gibbs 					    u_int *offset, int wide,
1289dd1290f0SJustin T. Gibbs 					    role_t role);
1290717d4247SJustin T. Gibbs void			ahc_validate_width(struct ahc_softc *ahc,
1291dd1290f0SJustin T. Gibbs 					   struct ahc_initiator_tinfo *tinfo,
1292dd1290f0SJustin T. Gibbs 					   u_int *bus_width,
1293dd1290f0SJustin T. Gibbs 					   role_t role);
12944d22994eSScott Long /*
12954d22994eSScott Long  * Negotiation types.  These are used to qualify if we should renegotiate
12964d22994eSScott Long  * even if our goal and current transport parameters are identical.
12974d22994eSScott Long  */
12984d22994eSScott Long typedef enum {
12994d22994eSScott Long 	AHC_NEG_TO_GOAL,	/* Renegotiate only if goal and curr differ. */
13004d22994eSScott Long 	AHC_NEG_IF_NON_ASYNC,	/* Renegotiate so long as goal is non-async. */
13014d22994eSScott Long 	AHC_NEG_ALWAYS		/* Renegotiat even if goal is async. */
13024d22994eSScott Long } ahc_neg_type;
1303b95de6daSJustin T. Gibbs int			ahc_update_neg_request(struct ahc_softc*,
1304b95de6daSJustin T. Gibbs 					       struct ahc_devinfo*,
1305b95de6daSJustin T. Gibbs 					       struct ahc_tmode_tstate*,
1306b95de6daSJustin T. Gibbs 					       struct ahc_initiator_tinfo*,
13074d22994eSScott Long 					       ahc_neg_type);
1308717d4247SJustin T. Gibbs void			ahc_set_width(struct ahc_softc *ahc,
1309717d4247SJustin T. Gibbs 				      struct ahc_devinfo *devinfo,
1310717d4247SJustin T. Gibbs 				      u_int width, u_int type, int paused);
1311717d4247SJustin T. Gibbs void			ahc_set_syncrate(struct ahc_softc *ahc,
1312717d4247SJustin T. Gibbs 					 struct ahc_devinfo *devinfo,
1313717d4247SJustin T. Gibbs 					 struct ahc_syncrate *syncrate,
1314717d4247SJustin T. Gibbs 					 u_int period, u_int offset,
1315717d4247SJustin T. Gibbs 					 u_int ppr_options,
1316717d4247SJustin T. Gibbs 					 u_int type, int paused);
131758fb7d8eSJustin T. Gibbs typedef enum {
131858fb7d8eSJustin T. Gibbs 	AHC_QUEUE_NONE,
131958fb7d8eSJustin T. Gibbs 	AHC_QUEUE_BASIC,
132058fb7d8eSJustin T. Gibbs 	AHC_QUEUE_TAGGED
132158fb7d8eSJustin T. Gibbs } ahc_queue_alg;
132258fb7d8eSJustin T. Gibbs 
1323717d4247SJustin T. Gibbs void			ahc_set_tags(struct ahc_softc *ahc,
132458fb7d8eSJustin T. Gibbs 				     struct ahc_devinfo *devinfo,
132558fb7d8eSJustin T. Gibbs 				     ahc_queue_alg alg);
1326aa6dfd9dSJustin T. Gibbs 
1327717d4247SJustin T. Gibbs /**************************** Target Mode *************************************/
1328717d4247SJustin T. Gibbs #ifdef AHC_TARGET_MODE
1329717d4247SJustin T. Gibbs void		ahc_send_lstate_events(struct ahc_softc *,
1330b95de6daSJustin T. Gibbs 				       struct ahc_tmode_lstate *);
1331717d4247SJustin T. Gibbs void		ahc_handle_en_lun(struct ahc_softc *ahc,
1332717d4247SJustin T. Gibbs 				  struct cam_sim *sim, union ccb *ccb);
1333717d4247SJustin T. Gibbs cam_status	ahc_find_tmode_devs(struct ahc_softc *ahc,
1334717d4247SJustin T. Gibbs 				    struct cam_sim *sim, union ccb *ccb,
1335b95de6daSJustin T. Gibbs 				    struct ahc_tmode_tstate **tstate,
1336b95de6daSJustin T. Gibbs 				    struct ahc_tmode_lstate **lstate,
1337717d4247SJustin T. Gibbs 				    int notfound_failure);
1338dd1290f0SJustin T. Gibbs #ifndef AHC_TMODE_ENABLE
1339dd1290f0SJustin T. Gibbs #define AHC_TMODE_ENABLE 0
1340dd1290f0SJustin T. Gibbs #endif
1341717d4247SJustin T. Gibbs #endif
1342717d4247SJustin T. Gibbs /******************************* Debug ***************************************/
13438f214efcSJustin T. Gibbs #ifdef AHC_DEBUG
13443b06611aSJustin T. Gibbs extern uint32_t ahc_debug;
13453b06611aSJustin T. Gibbs #define	AHC_SHOW_MISC		0x0001
13463b06611aSJustin T. Gibbs #define	AHC_SHOW_SENSE		0x0002
13473b06611aSJustin T. Gibbs #define AHC_DUMP_SEEPROM	0x0004
13483b06611aSJustin T. Gibbs #define AHC_SHOW_TERMCTL	0x0008
13493b06611aSJustin T. Gibbs #define AHC_SHOW_MEMORY		0x0010
13503b06611aSJustin T. Gibbs #define AHC_SHOW_MESSAGES	0x0020
13514d22994eSScott Long #define	AHC_SHOW_DV		0x0040
13523b06611aSJustin T. Gibbs #define AHC_SHOW_SELTO		0x0080
13533b06611aSJustin T. Gibbs #define AHC_SHOW_QFULL		0x0200
13543b06611aSJustin T. Gibbs #define AHC_SHOW_QUEUE		0x0400
13553b06611aSJustin T. Gibbs #define AHC_SHOW_TQIN		0x0800
135670b41139SJustin T. Gibbs #define AHC_SHOW_MASKED_ERRORS	0x1000
135770b41139SJustin T. Gibbs #define AHC_DEBUG_SEQUENCER	0x2000
13588f214efcSJustin T. Gibbs #endif
1359717d4247SJustin T. Gibbs void			ahc_print_scb(struct scb *scb);
13604d22994eSScott Long void			ahc_print_devinfo(struct ahc_softc *ahc,
13614d22994eSScott Long 					  struct ahc_devinfo *dev);
1362717d4247SJustin T. Gibbs void			ahc_dump_card_state(struct ahc_softc *ahc);
13633b06611aSJustin T. Gibbs int			ahc_print_register(ahc_reg_parse_entry_t *table,
13643b06611aSJustin T. Gibbs 					   u_int num_entries,
13653b06611aSJustin T. Gibbs 					   const char *name,
13663b06611aSJustin T. Gibbs 					   u_int address,
13673b06611aSJustin T. Gibbs 					   u_int value,
13683b06611aSJustin T. Gibbs 					   u_int *cur_column,
13693b06611aSJustin T. Gibbs 					   u_int wrap_point);
13708f214efcSJustin T. Gibbs /******************************* SEEPROM *************************************/
13718f214efcSJustin T. Gibbs int		ahc_acquire_seeprom(struct ahc_softc *ahc,
13728f214efcSJustin T. Gibbs 				    struct seeprom_descriptor *sd);
13738f214efcSJustin T. Gibbs void		ahc_release_seeprom(struct seeprom_descriptor *sd);
13743bafc9d4SJustin T. Gibbs #endif /* _AIC7XXX_H_ */
1375