18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Core definitions and data structures shareable across OS platforms.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (c) 1994-2002 Justin T. Gibbs.
58c2ecf20Sopenharmony_ci * Copyright (c) 2000-2002 Adaptec Inc.
68c2ecf20Sopenharmony_ci * All rights reserved.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
98c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions
108c2ecf20Sopenharmony_ci * are met:
118c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
128c2ecf20Sopenharmony_ci *    notice, this list of conditions, and the following disclaimer,
138c2ecf20Sopenharmony_ci *    without modification.
148c2ecf20Sopenharmony_ci * 2. Redistributions in binary form must reproduce at minimum a disclaimer
158c2ecf20Sopenharmony_ci *    substantially similar to the "NO WARRANTY" disclaimer below
168c2ecf20Sopenharmony_ci *    ("Disclaimer") and any redistribution must be conditioned upon
178c2ecf20Sopenharmony_ci *    including a substantially similar Disclaimer requirement for further
188c2ecf20Sopenharmony_ci *    binary redistribution.
198c2ecf20Sopenharmony_ci * 3. Neither the names of the above-listed copyright holders nor the names
208c2ecf20Sopenharmony_ci *    of any contributors may be used to endorse or promote products derived
218c2ecf20Sopenharmony_ci *    from this software without specific prior written permission.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the
248c2ecf20Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free
258c2ecf20Sopenharmony_ci * Software Foundation.
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * NO WARRANTY
288c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
298c2ecf20Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
308c2ecf20Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
318c2ecf20Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
328c2ecf20Sopenharmony_ci * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
338c2ecf20Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
348c2ecf20Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
358c2ecf20Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
368c2ecf20Sopenharmony_ci * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
378c2ecf20Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
388c2ecf20Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGES.
398c2ecf20Sopenharmony_ci *
408c2ecf20Sopenharmony_ci * $Id: //depot/aic7xxx/aic7xxx/aic79xx.h#109 $
418c2ecf20Sopenharmony_ci *
428c2ecf20Sopenharmony_ci * $FreeBSD$
438c2ecf20Sopenharmony_ci */
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#ifndef _AIC79XX_H_
468c2ecf20Sopenharmony_ci#define _AIC79XX_H_
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/* Register Definitions */
498c2ecf20Sopenharmony_ci#include "aic79xx_reg.h"
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci/************************* Forward Declarations *******************************/
528c2ecf20Sopenharmony_cistruct ahd_platform_data;
538c2ecf20Sopenharmony_cistruct scb_platform_data;
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/****************************** Useful Macros *********************************/
568c2ecf20Sopenharmony_ci#ifndef TRUE
578c2ecf20Sopenharmony_ci#define TRUE 1
588c2ecf20Sopenharmony_ci#endif
598c2ecf20Sopenharmony_ci#ifndef FALSE
608c2ecf20Sopenharmony_ci#define FALSE 0
618c2ecf20Sopenharmony_ci#endif
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci#define ALL_CHANNELS '\0'
648c2ecf20Sopenharmony_ci#define ALL_TARGETS_MASK 0xFFFF
658c2ecf20Sopenharmony_ci#define INITIATOR_WILDCARD	(~0)
668c2ecf20Sopenharmony_ci#define	SCB_LIST_NULL		0xFF00
678c2ecf20Sopenharmony_ci#define	SCB_LIST_NULL_LE	(ahd_htole16(SCB_LIST_NULL))
688c2ecf20Sopenharmony_ci#define QOUTFIFO_ENTRY_VALID 0x80
698c2ecf20Sopenharmony_ci#define SCBID_IS_NULL(scbid) (((scbid) & 0xFF00 ) == SCB_LIST_NULL)
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci#define SCSIID_TARGET(ahd, scsiid)	\
728c2ecf20Sopenharmony_ci	(((scsiid) & TID) >> TID_SHIFT)
738c2ecf20Sopenharmony_ci#define SCSIID_OUR_ID(scsiid)		\
748c2ecf20Sopenharmony_ci	((scsiid) & OID)
758c2ecf20Sopenharmony_ci#define SCSIID_CHANNEL(ahd, scsiid) ('A')
768c2ecf20Sopenharmony_ci#define	SCB_IS_SCSIBUS_B(ahd, scb) (0)
778c2ecf20Sopenharmony_ci#define	SCB_GET_OUR_ID(scb) \
788c2ecf20Sopenharmony_ci	SCSIID_OUR_ID((scb)->hscb->scsiid)
798c2ecf20Sopenharmony_ci#define	SCB_GET_TARGET(ahd, scb) \
808c2ecf20Sopenharmony_ci	SCSIID_TARGET((ahd), (scb)->hscb->scsiid)
818c2ecf20Sopenharmony_ci#define	SCB_GET_CHANNEL(ahd, scb) \
828c2ecf20Sopenharmony_ci	SCSIID_CHANNEL(ahd, (scb)->hscb->scsiid)
838c2ecf20Sopenharmony_ci#define	SCB_GET_LUN(scb) \
848c2ecf20Sopenharmony_ci	((scb)->hscb->lun)
858c2ecf20Sopenharmony_ci#define SCB_GET_TARGET_OFFSET(ahd, scb)	\
868c2ecf20Sopenharmony_ci	SCB_GET_TARGET(ahd, scb)
878c2ecf20Sopenharmony_ci#define SCB_GET_TARGET_MASK(ahd, scb) \
888c2ecf20Sopenharmony_ci	(0x01 << (SCB_GET_TARGET_OFFSET(ahd, scb)))
898c2ecf20Sopenharmony_ci#ifdef AHD_DEBUG
908c2ecf20Sopenharmony_ci#define SCB_IS_SILENT(scb)					\
918c2ecf20Sopenharmony_ci	((ahd_debug & AHD_SHOW_MASKED_ERRORS) == 0		\
928c2ecf20Sopenharmony_ci      && (((scb)->flags & SCB_SILENT) != 0))
938c2ecf20Sopenharmony_ci#else
948c2ecf20Sopenharmony_ci#define SCB_IS_SILENT(scb)					\
958c2ecf20Sopenharmony_ci	(((scb)->flags & SCB_SILENT) != 0)
968c2ecf20Sopenharmony_ci#endif
978c2ecf20Sopenharmony_ci/*
988c2ecf20Sopenharmony_ci * TCLs have the following format: TTTTLLLLLLLL
998c2ecf20Sopenharmony_ci */
1008c2ecf20Sopenharmony_ci#define TCL_TARGET_OFFSET(tcl) \
1018c2ecf20Sopenharmony_ci	((((tcl) >> 4) & TID) >> 4)
1028c2ecf20Sopenharmony_ci#define TCL_LUN(tcl) \
1038c2ecf20Sopenharmony_ci	(tcl & (AHD_NUM_LUNS - 1))
1048c2ecf20Sopenharmony_ci#define BUILD_TCL(scsiid, lun) \
1058c2ecf20Sopenharmony_ci	((lun) | (((scsiid) & TID) << 4))
1068c2ecf20Sopenharmony_ci#define BUILD_TCL_RAW(target, channel, lun) \
1078c2ecf20Sopenharmony_ci	((lun) | ((target) << 8))
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci#define SCB_GET_TAG(scb) \
1108c2ecf20Sopenharmony_ci	ahd_le16toh(scb->hscb->tag)
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#ifndef	AHD_TARGET_MODE
1138c2ecf20Sopenharmony_ci#undef	AHD_TMODE_ENABLE
1148c2ecf20Sopenharmony_ci#define	AHD_TMODE_ENABLE 0
1158c2ecf20Sopenharmony_ci#endif
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#define AHD_BUILD_COL_IDX(target, lun)				\
1188c2ecf20Sopenharmony_ci	((((u8)lun) << 4) | target)
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_ci#define AHD_GET_SCB_COL_IDX(ahd, scb)				\
1218c2ecf20Sopenharmony_ci	((SCB_GET_LUN(scb) << 4) | SCB_GET_TARGET(ahd, scb))
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci#define AHD_SET_SCB_COL_IDX(scb, col_idx)				\
1248c2ecf20Sopenharmony_cido {									\
1258c2ecf20Sopenharmony_ci	(scb)->hscb->scsiid = ((col_idx) << TID_SHIFT) & TID;		\
1268c2ecf20Sopenharmony_ci	(scb)->hscb->lun = ((col_idx) >> 4) & (AHD_NUM_LUNS_NONPKT-1);	\
1278c2ecf20Sopenharmony_ci} while (0)
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci#define AHD_COPY_SCB_COL_IDX(dst, src)				\
1308c2ecf20Sopenharmony_cido {								\
1318c2ecf20Sopenharmony_ci	dst->hscb->scsiid = src->hscb->scsiid;			\
1328c2ecf20Sopenharmony_ci	dst->hscb->lun = src->hscb->lun;			\
1338c2ecf20Sopenharmony_ci} while (0)
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci#define	AHD_NEVER_COL_IDX 0xFFFF
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci/**************************** Driver Constants ********************************/
1388c2ecf20Sopenharmony_ci/*
1398c2ecf20Sopenharmony_ci * The maximum number of supported targets.
1408c2ecf20Sopenharmony_ci */
1418c2ecf20Sopenharmony_ci#define AHD_NUM_TARGETS 16
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci/*
1448c2ecf20Sopenharmony_ci * The maximum number of supported luns.
1458c2ecf20Sopenharmony_ci * The identify message only supports 64 luns in non-packetized transfers.
1468c2ecf20Sopenharmony_ci * You can have 2^64 luns when information unit transfers are enabled,
1478c2ecf20Sopenharmony_ci * but until we see a need to support that many, we support 256.
1488c2ecf20Sopenharmony_ci */
1498c2ecf20Sopenharmony_ci#define AHD_NUM_LUNS_NONPKT 64
1508c2ecf20Sopenharmony_ci#define AHD_NUM_LUNS 256
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/*
1538c2ecf20Sopenharmony_ci * The maximum transfer per S/G segment.
1548c2ecf20Sopenharmony_ci */
1558c2ecf20Sopenharmony_ci#define AHD_MAXTRANSFER_SIZE	 0x00ffffff	/* limited by 24bit counter */
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci/*
1588c2ecf20Sopenharmony_ci * The maximum amount of SCB storage in hardware on a controller.
1598c2ecf20Sopenharmony_ci * This value represents an upper bound.  Due to software design,
1608c2ecf20Sopenharmony_ci * we may not be able to use this number.
1618c2ecf20Sopenharmony_ci */
1628c2ecf20Sopenharmony_ci#define AHD_SCB_MAX	512
1638c2ecf20Sopenharmony_ci
1648c2ecf20Sopenharmony_ci/*
1658c2ecf20Sopenharmony_ci * The maximum number of concurrent transactions supported per driver instance.
1668c2ecf20Sopenharmony_ci * Sequencer Control Blocks (SCBs) store per-transaction information.
1678c2ecf20Sopenharmony_ci */
1688c2ecf20Sopenharmony_ci#define AHD_MAX_QUEUE	AHD_SCB_MAX
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci/*
1718c2ecf20Sopenharmony_ci * Define the size of our QIN and QOUT FIFOs.  They must be a power of 2
1728c2ecf20Sopenharmony_ci * in size and accommodate as many transactions as can be queued concurrently.
1738c2ecf20Sopenharmony_ci */
1748c2ecf20Sopenharmony_ci#define	AHD_QIN_SIZE	AHD_MAX_QUEUE
1758c2ecf20Sopenharmony_ci#define	AHD_QOUT_SIZE	AHD_MAX_QUEUE
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci#define AHD_QIN_WRAP(x) ((x) & (AHD_QIN_SIZE-1))
1788c2ecf20Sopenharmony_ci/*
1798c2ecf20Sopenharmony_ci * The maximum amount of SCB storage we allocate in host memory.
1808c2ecf20Sopenharmony_ci */
1818c2ecf20Sopenharmony_ci#define AHD_SCB_MAX_ALLOC AHD_MAX_QUEUE
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci/*
1848c2ecf20Sopenharmony_ci * Ring Buffer of incoming target commands.
1858c2ecf20Sopenharmony_ci * We allocate 256 to simplify the logic in the sequencer
1868c2ecf20Sopenharmony_ci * by using the natural wrap point of an 8bit counter.
1878c2ecf20Sopenharmony_ci */
1888c2ecf20Sopenharmony_ci#define AHD_TMODE_CMDS	256
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci/* Reset line assertion time in us */
1918c2ecf20Sopenharmony_ci#define AHD_BUSRESET_DELAY	25
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci/******************* Chip Characteristics/Operating Settings  *****************/
1948c2ecf20Sopenharmony_ci/*
1958c2ecf20Sopenharmony_ci * Chip Type
1968c2ecf20Sopenharmony_ci * The chip order is from least sophisticated to most sophisticated.
1978c2ecf20Sopenharmony_ci */
1988c2ecf20Sopenharmony_citypedef enum {
1998c2ecf20Sopenharmony_ci	AHD_NONE	= 0x0000,
2008c2ecf20Sopenharmony_ci	AHD_CHIPID_MASK	= 0x00FF,
2018c2ecf20Sopenharmony_ci	AHD_AIC7901	= 0x0001,
2028c2ecf20Sopenharmony_ci	AHD_AIC7902	= 0x0002,
2038c2ecf20Sopenharmony_ci	AHD_AIC7901A	= 0x0003,
2048c2ecf20Sopenharmony_ci	AHD_PCI		= 0x0100,	/* Bus type PCI */
2058c2ecf20Sopenharmony_ci	AHD_PCIX	= 0x0200,	/* Bus type PCIX */
2068c2ecf20Sopenharmony_ci	AHD_BUS_MASK	= 0x0F00
2078c2ecf20Sopenharmony_ci} ahd_chip;
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci/*
2108c2ecf20Sopenharmony_ci * Features available in each chip type.
2118c2ecf20Sopenharmony_ci */
2128c2ecf20Sopenharmony_citypedef enum {
2138c2ecf20Sopenharmony_ci	AHD_FENONE		= 0x00000,
2148c2ecf20Sopenharmony_ci	AHD_WIDE  		= 0x00001,/* Wide Channel */
2158c2ecf20Sopenharmony_ci	AHD_AIC79XXB_SLOWCRC    = 0x00002,/* SLOWCRC bit should be set */
2168c2ecf20Sopenharmony_ci	AHD_MULTI_FUNC		= 0x00100,/* Multi-Function/Channel Device */
2178c2ecf20Sopenharmony_ci	AHD_TARGETMODE		= 0x01000,/* Has tested target mode support */
2188c2ecf20Sopenharmony_ci	AHD_MULTIROLE		= 0x02000,/* Space for two roles at a time */
2198c2ecf20Sopenharmony_ci	AHD_RTI			= 0x04000,/* Retained Training Support */
2208c2ecf20Sopenharmony_ci	AHD_NEW_IOCELL_OPTS	= 0x08000,/* More Signal knobs in the IOCELL */
2218c2ecf20Sopenharmony_ci	AHD_NEW_DFCNTRL_OPTS	= 0x10000,/* SCSIENWRDIS bit */
2228c2ecf20Sopenharmony_ci	AHD_FAST_CDB_DELIVERY	= 0x20000,/* CDB acks released to Output Sync */
2238c2ecf20Sopenharmony_ci	AHD_REMOVABLE		= 0x00000,/* Hot-Swap supported - None so far*/
2248c2ecf20Sopenharmony_ci	AHD_AIC7901_FE		= AHD_FENONE,
2258c2ecf20Sopenharmony_ci	AHD_AIC7901A_FE		= AHD_FENONE,
2268c2ecf20Sopenharmony_ci	AHD_AIC7902_FE		= AHD_MULTI_FUNC
2278c2ecf20Sopenharmony_ci} ahd_feature;
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci/*
2308c2ecf20Sopenharmony_ci * Bugs in the silicon that we work around in software.
2318c2ecf20Sopenharmony_ci */
2328c2ecf20Sopenharmony_citypedef enum {
2338c2ecf20Sopenharmony_ci	AHD_BUGNONE		= 0x0000,
2348c2ecf20Sopenharmony_ci	/*
2358c2ecf20Sopenharmony_ci	 * Rev A hardware fails to update LAST/CURR/NEXTSCB
2368c2ecf20Sopenharmony_ci	 * correctly in certain packetized selection cases.
2378c2ecf20Sopenharmony_ci	 */
2388c2ecf20Sopenharmony_ci	AHD_SENT_SCB_UPDATE_BUG	= 0x0001,
2398c2ecf20Sopenharmony_ci	/* The wrong SCB is accessed to check the abort pending bit. */
2408c2ecf20Sopenharmony_ci	AHD_ABORT_LQI_BUG	= 0x0002,
2418c2ecf20Sopenharmony_ci	/* Packetized bitbucket crosses packet boundaries. */
2428c2ecf20Sopenharmony_ci	AHD_PKT_BITBUCKET_BUG	= 0x0004,
2438c2ecf20Sopenharmony_ci	/* The selection timer runs twice as long as its setting. */
2448c2ecf20Sopenharmony_ci	AHD_LONG_SETIMO_BUG	= 0x0008,
2458c2ecf20Sopenharmony_ci	/* The Non-LQ CRC error status is delayed until phase change. */
2468c2ecf20Sopenharmony_ci	AHD_NLQICRC_DELAYED_BUG	= 0x0010,
2478c2ecf20Sopenharmony_ci	/* The chip must be reset for all outgoing bus resets.  */
2488c2ecf20Sopenharmony_ci	AHD_SCSIRST_BUG		= 0x0020,
2498c2ecf20Sopenharmony_ci	/* Some PCIX fields must be saved and restored across chip reset. */
2508c2ecf20Sopenharmony_ci	AHD_PCIX_CHIPRST_BUG	= 0x0040,
2518c2ecf20Sopenharmony_ci	/* MMAPIO is not functional in PCI-X mode.  */
2528c2ecf20Sopenharmony_ci	AHD_PCIX_MMAPIO_BUG	= 0x0080,
2538c2ecf20Sopenharmony_ci	/* Reads to SCBRAM fail to reset the discard timer. */
2548c2ecf20Sopenharmony_ci	AHD_PCIX_SCBRAM_RD_BUG  = 0x0100,
2558c2ecf20Sopenharmony_ci	/* Bug workarounds that can be disabled on non-PCIX busses. */
2568c2ecf20Sopenharmony_ci	AHD_PCIX_BUG_MASK	= AHD_PCIX_CHIPRST_BUG
2578c2ecf20Sopenharmony_ci				| AHD_PCIX_MMAPIO_BUG
2588c2ecf20Sopenharmony_ci				| AHD_PCIX_SCBRAM_RD_BUG,
2598c2ecf20Sopenharmony_ci	/*
2608c2ecf20Sopenharmony_ci	 * LQOSTOP0 status set even for forced selections with ATN
2618c2ecf20Sopenharmony_ci	 * to perform non-packetized message delivery.
2628c2ecf20Sopenharmony_ci	 */
2638c2ecf20Sopenharmony_ci	AHD_LQO_ATNO_BUG	= 0x0200,
2648c2ecf20Sopenharmony_ci	/* FIFO auto-flush does not always trigger.  */
2658c2ecf20Sopenharmony_ci	AHD_AUTOFLUSH_BUG	= 0x0400,
2668c2ecf20Sopenharmony_ci	/* The CLRLQO registers are not self-clearing. */
2678c2ecf20Sopenharmony_ci	AHD_CLRLQO_AUTOCLR_BUG	= 0x0800,
2688c2ecf20Sopenharmony_ci	/* The PACKETIZED status bit refers to the previous connection. */
2698c2ecf20Sopenharmony_ci	AHD_PKTIZED_STATUS_BUG  = 0x1000,
2708c2ecf20Sopenharmony_ci	/* "Short Luns" are not placed into outgoing LQ packets correctly. */
2718c2ecf20Sopenharmony_ci	AHD_PKT_LUN_BUG		= 0x2000,
2728c2ecf20Sopenharmony_ci	/*
2738c2ecf20Sopenharmony_ci	 * Only the FIFO allocated to the non-packetized connection may
2748c2ecf20Sopenharmony_ci	 * be in use during a non-packetzied connection.
2758c2ecf20Sopenharmony_ci	 */
2768c2ecf20Sopenharmony_ci	AHD_NONPACKFIFO_BUG	= 0x4000,
2778c2ecf20Sopenharmony_ci	/*
2788c2ecf20Sopenharmony_ci	 * Writing to a DFF SCBPTR register may fail if concurent with
2798c2ecf20Sopenharmony_ci	 * a hardware write to the other DFF SCBPTR register.  This is
2808c2ecf20Sopenharmony_ci	 * not currently a concern in our sequencer since all chips with
2818c2ecf20Sopenharmony_ci	 * this bug have the AHD_NONPACKFIFO_BUG and all writes of concern
2828c2ecf20Sopenharmony_ci	 * occur in non-packetized connections.
2838c2ecf20Sopenharmony_ci	 */
2848c2ecf20Sopenharmony_ci	AHD_MDFF_WSCBPTR_BUG	= 0x8000,
2858c2ecf20Sopenharmony_ci	/* SGHADDR updates are slow. */
2868c2ecf20Sopenharmony_ci	AHD_REG_SLOW_SETTLE_BUG	= 0x10000,
2878c2ecf20Sopenharmony_ci	/*
2888c2ecf20Sopenharmony_ci	 * Changing the MODE_PTR coincident with an interrupt that
2898c2ecf20Sopenharmony_ci	 * switches to a different mode will cause the interrupt to
2908c2ecf20Sopenharmony_ci	 * be in the mode written outside of interrupt context.
2918c2ecf20Sopenharmony_ci	 */
2928c2ecf20Sopenharmony_ci	AHD_SET_MODE_BUG	= 0x20000,
2938c2ecf20Sopenharmony_ci	/* Non-packetized busfree revision does not work. */
2948c2ecf20Sopenharmony_ci	AHD_BUSFREEREV_BUG	= 0x40000,
2958c2ecf20Sopenharmony_ci	/*
2968c2ecf20Sopenharmony_ci	 * Paced transfers are indicated with a non-standard PPR
2978c2ecf20Sopenharmony_ci	 * option bit in the neg table, 160MHz is indicated by
2988c2ecf20Sopenharmony_ci	 * sync factor 0x7, and the offset if off by a factor of 2.
2998c2ecf20Sopenharmony_ci	 */
3008c2ecf20Sopenharmony_ci	AHD_PACED_NEGTABLE_BUG	= 0x80000,
3018c2ecf20Sopenharmony_ci	/* LQOOVERRUN false positives. */
3028c2ecf20Sopenharmony_ci	AHD_LQOOVERRUN_BUG	= 0x100000,
3038c2ecf20Sopenharmony_ci	/*
3048c2ecf20Sopenharmony_ci	 * Controller write to INTSTAT will lose to a host
3058c2ecf20Sopenharmony_ci	 * write to CLRINT.
3068c2ecf20Sopenharmony_ci	 */
3078c2ecf20Sopenharmony_ci	AHD_INTCOLLISION_BUG	= 0x200000,
3088c2ecf20Sopenharmony_ci	/*
3098c2ecf20Sopenharmony_ci	 * The GEM318 violates the SCSI spec by not waiting
3108c2ecf20Sopenharmony_ci	 * the mandated bus settle delay between phase changes
3118c2ecf20Sopenharmony_ci	 * in some situations.  Some aic79xx chip revs. are more
3128c2ecf20Sopenharmony_ci	 * strict in this regard and will treat REQ assertions
3138c2ecf20Sopenharmony_ci	 * that fall within the bus settle delay window as
3148c2ecf20Sopenharmony_ci	 * glitches.  This flag tells the firmware to tolerate
3158c2ecf20Sopenharmony_ci	 * early REQ assertions.
3168c2ecf20Sopenharmony_ci	 */
3178c2ecf20Sopenharmony_ci	AHD_EARLY_REQ_BUG	= 0x400000,
3188c2ecf20Sopenharmony_ci	/*
3198c2ecf20Sopenharmony_ci	 * The LED does not stay on long enough in packetized modes.
3208c2ecf20Sopenharmony_ci	 */
3218c2ecf20Sopenharmony_ci	AHD_FAINT_LED_BUG	= 0x800000
3228c2ecf20Sopenharmony_ci} ahd_bug;
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_ci/*
3258c2ecf20Sopenharmony_ci * Configuration specific settings.
3268c2ecf20Sopenharmony_ci * The driver determines these settings by probing the
3278c2ecf20Sopenharmony_ci * chip/controller's configuration.
3288c2ecf20Sopenharmony_ci */
3298c2ecf20Sopenharmony_citypedef enum {
3308c2ecf20Sopenharmony_ci	AHD_FNONE	      = 0x00000,
3318c2ecf20Sopenharmony_ci	AHD_BOOT_CHANNEL      = 0x00001,/* We were set as the boot channel. */
3328c2ecf20Sopenharmony_ci	AHD_USEDEFAULTS	      = 0x00004,/*
3338c2ecf20Sopenharmony_ci					 * For cards without an seeprom
3348c2ecf20Sopenharmony_ci					 * or a BIOS to initialize the chip's
3358c2ecf20Sopenharmony_ci					 * SRAM, we use the default target
3368c2ecf20Sopenharmony_ci					 * settings.
3378c2ecf20Sopenharmony_ci					 */
3388c2ecf20Sopenharmony_ci	AHD_SEQUENCER_DEBUG   = 0x00008,
3398c2ecf20Sopenharmony_ci	AHD_RESET_BUS_A	      = 0x00010,
3408c2ecf20Sopenharmony_ci	AHD_EXTENDED_TRANS_A  = 0x00020,
3418c2ecf20Sopenharmony_ci	AHD_TERM_ENB_A	      = 0x00040,
3428c2ecf20Sopenharmony_ci	AHD_SPCHK_ENB_A	      = 0x00080,
3438c2ecf20Sopenharmony_ci	AHD_STPWLEVEL_A	      = 0x00100,
3448c2ecf20Sopenharmony_ci	AHD_INITIATORROLE     = 0x00200,/*
3458c2ecf20Sopenharmony_ci					 * Allow initiator operations on
3468c2ecf20Sopenharmony_ci					 * this controller.
3478c2ecf20Sopenharmony_ci					 */
3488c2ecf20Sopenharmony_ci	AHD_TARGETROLE	      = 0x00400,/*
3498c2ecf20Sopenharmony_ci					 * Allow target operations on this
3508c2ecf20Sopenharmony_ci					 * controller.
3518c2ecf20Sopenharmony_ci					 */
3528c2ecf20Sopenharmony_ci	AHD_RESOURCE_SHORTAGE = 0x00800,
3538c2ecf20Sopenharmony_ci	AHD_TQINFIFO_BLOCKED  = 0x01000,/* Blocked waiting for ATIOs */
3548c2ecf20Sopenharmony_ci	AHD_INT50_SPEEDFLEX   = 0x02000,/*
3558c2ecf20Sopenharmony_ci					 * Internal 50pin connector
3568c2ecf20Sopenharmony_ci					 * sits behind an aic3860
3578c2ecf20Sopenharmony_ci					 */
3588c2ecf20Sopenharmony_ci	AHD_BIOS_ENABLED      = 0x04000,
3598c2ecf20Sopenharmony_ci	AHD_ALL_INTERRUPTS    = 0x08000,
3608c2ecf20Sopenharmony_ci	AHD_39BIT_ADDRESSING  = 0x10000,/* Use 39 bit addressing scheme. */
3618c2ecf20Sopenharmony_ci	AHD_64BIT_ADDRESSING  = 0x20000,/* Use 64 bit addressing scheme. */
3628c2ecf20Sopenharmony_ci	AHD_CURRENT_SENSING   = 0x40000,
3638c2ecf20Sopenharmony_ci	AHD_SCB_CONFIG_USED   = 0x80000,/* No SEEPROM but SCB had info. */
3648c2ecf20Sopenharmony_ci	AHD_HP_BOARD	      = 0x100000,
3658c2ecf20Sopenharmony_ci	AHD_BUS_RESET_ACTIVE  = 0x200000,
3668c2ecf20Sopenharmony_ci	AHD_UPDATE_PEND_CMDS  = 0x400000,
3678c2ecf20Sopenharmony_ci	AHD_RUNNING_QOUTFIFO  = 0x800000,
3688c2ecf20Sopenharmony_ci	AHD_HAD_FIRST_SEL     = 0x1000000
3698c2ecf20Sopenharmony_ci} ahd_flag;
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci/************************* Hardware  SCB Definition ***************************/
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_ci/*
3748c2ecf20Sopenharmony_ci * The driver keeps up to MAX_SCB scb structures per card in memory.  The SCB
3758c2ecf20Sopenharmony_ci * consists of a "hardware SCB" mirroring the fields available on the card
3768c2ecf20Sopenharmony_ci * and additional information the kernel stores for each transaction.
3778c2ecf20Sopenharmony_ci *
3788c2ecf20Sopenharmony_ci * To minimize space utilization, a portion of the hardware scb stores
3798c2ecf20Sopenharmony_ci * different data during different portions of a SCSI transaction.
3808c2ecf20Sopenharmony_ci * As initialized by the host driver for the initiator role, this area
3818c2ecf20Sopenharmony_ci * contains the SCSI cdb (or a pointer to the  cdb) to be executed.  After
3828c2ecf20Sopenharmony_ci * the cdb has been presented to the target, this area serves to store
3838c2ecf20Sopenharmony_ci * residual transfer information and the SCSI status byte.
3848c2ecf20Sopenharmony_ci * For the target role, the contents of this area do not change, but
3858c2ecf20Sopenharmony_ci * still serve a different purpose than for the initiator role.  See
3868c2ecf20Sopenharmony_ci * struct target_data for details.
3878c2ecf20Sopenharmony_ci */
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci/*
3908c2ecf20Sopenharmony_ci * Status information embedded in the shared poriton of
3918c2ecf20Sopenharmony_ci * an SCB after passing the cdb to the target.  The kernel
3928c2ecf20Sopenharmony_ci * driver will only read this data for transactions that
3938c2ecf20Sopenharmony_ci * complete abnormally.
3948c2ecf20Sopenharmony_ci */
3958c2ecf20Sopenharmony_cistruct initiator_status {
3968c2ecf20Sopenharmony_ci	uint32_t residual_datacnt;	/* Residual in the current S/G seg */
3978c2ecf20Sopenharmony_ci	uint32_t residual_sgptr;	/* The next S/G for this transfer */
3988c2ecf20Sopenharmony_ci	uint8_t	 scsi_status;		/* Standard SCSI status byte */
3998c2ecf20Sopenharmony_ci};
4008c2ecf20Sopenharmony_ci
4018c2ecf20Sopenharmony_cistruct target_status {
4028c2ecf20Sopenharmony_ci	uint32_t residual_datacnt;	/* Residual in the current S/G seg */
4038c2ecf20Sopenharmony_ci	uint32_t residual_sgptr;	/* The next S/G for this transfer */
4048c2ecf20Sopenharmony_ci	uint8_t  scsi_status;		/* SCSI status to give to initiator */
4058c2ecf20Sopenharmony_ci	uint8_t  target_phases;		/* Bitmap of phases to execute */
4068c2ecf20Sopenharmony_ci	uint8_t  data_phase;		/* Data-In or Data-Out */
4078c2ecf20Sopenharmony_ci	uint8_t  initiator_tag;		/* Initiator's transaction tag */
4088c2ecf20Sopenharmony_ci};
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci/*
4118c2ecf20Sopenharmony_ci * Initiator mode SCB shared data area.
4128c2ecf20Sopenharmony_ci * If the embedded CDB is 12 bytes or less, we embed
4138c2ecf20Sopenharmony_ci * the sense buffer address in the SCB.  This allows
4148c2ecf20Sopenharmony_ci * us to retrieve sense information without interrupting
4158c2ecf20Sopenharmony_ci * the host in packetized mode.
4168c2ecf20Sopenharmony_ci */
4178c2ecf20Sopenharmony_citypedef uint32_t sense_addr_t;
4188c2ecf20Sopenharmony_ci#define MAX_CDB_LEN 16
4198c2ecf20Sopenharmony_ci#define MAX_CDB_LEN_WITH_SENSE_ADDR (MAX_CDB_LEN - sizeof(sense_addr_t))
4208c2ecf20Sopenharmony_ciunion initiator_data {
4218c2ecf20Sopenharmony_ci	struct {
4228c2ecf20Sopenharmony_ci		uint64_t cdbptr;
4238c2ecf20Sopenharmony_ci		uint8_t  cdblen;
4248c2ecf20Sopenharmony_ci	} cdb_from_host;
4258c2ecf20Sopenharmony_ci	uint8_t	 cdb[MAX_CDB_LEN];
4268c2ecf20Sopenharmony_ci	struct {
4278c2ecf20Sopenharmony_ci		uint8_t	 cdb[MAX_CDB_LEN_WITH_SENSE_ADDR];
4288c2ecf20Sopenharmony_ci		sense_addr_t sense_addr;
4298c2ecf20Sopenharmony_ci	} cdb_plus_saddr;
4308c2ecf20Sopenharmony_ci};
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_ci/*
4338c2ecf20Sopenharmony_ci * Target mode version of the shared data SCB segment.
4348c2ecf20Sopenharmony_ci */
4358c2ecf20Sopenharmony_cistruct target_data {
4368c2ecf20Sopenharmony_ci	uint32_t spare[2];
4378c2ecf20Sopenharmony_ci	uint8_t  scsi_status;		/* SCSI status to give to initiator */
4388c2ecf20Sopenharmony_ci	uint8_t  target_phases;		/* Bitmap of phases to execute */
4398c2ecf20Sopenharmony_ci	uint8_t  data_phase;		/* Data-In or Data-Out */
4408c2ecf20Sopenharmony_ci	uint8_t  initiator_tag;		/* Initiator's transaction tag */
4418c2ecf20Sopenharmony_ci};
4428c2ecf20Sopenharmony_ci
4438c2ecf20Sopenharmony_cistruct hardware_scb {
4448c2ecf20Sopenharmony_ci/*0*/	union {
4458c2ecf20Sopenharmony_ci		union	initiator_data idata;
4468c2ecf20Sopenharmony_ci		struct	target_data tdata;
4478c2ecf20Sopenharmony_ci		struct	initiator_status istatus;
4488c2ecf20Sopenharmony_ci		struct	target_status tstatus;
4498c2ecf20Sopenharmony_ci	} shared_data;
4508c2ecf20Sopenharmony_ci/*
4518c2ecf20Sopenharmony_ci * A word about residuals.
4528c2ecf20Sopenharmony_ci * The scb is presented to the sequencer with the dataptr and datacnt
4538c2ecf20Sopenharmony_ci * fields initialized to the contents of the first S/G element to
4548c2ecf20Sopenharmony_ci * transfer.  The sgptr field is initialized to the bus address for
4558c2ecf20Sopenharmony_ci * the S/G element that follows the first in the in core S/G array
4568c2ecf20Sopenharmony_ci * or'ed with the SG_FULL_RESID flag.  Sgptr may point to an invalid
4578c2ecf20Sopenharmony_ci * S/G entry for this transfer (single S/G element transfer with the
4588c2ecf20Sopenharmony_ci * first elements address and length preloaded in the dataptr/datacnt
4598c2ecf20Sopenharmony_ci * fields).  If no transfer is to occur, sgptr is set to SG_LIST_NULL.
4608c2ecf20Sopenharmony_ci * The SG_FULL_RESID flag ensures that the residual will be correctly
4618c2ecf20Sopenharmony_ci * noted even if no data transfers occur.  Once the data phase is entered,
4628c2ecf20Sopenharmony_ci * the residual sgptr and datacnt are loaded from the sgptr and the
4638c2ecf20Sopenharmony_ci * datacnt fields.  After each S/G element's dataptr and length are
4648c2ecf20Sopenharmony_ci * loaded into the hardware, the residual sgptr is advanced.  After
4658c2ecf20Sopenharmony_ci * each S/G element is expired, its datacnt field is checked to see
4668c2ecf20Sopenharmony_ci * if the LAST_SEG flag is set.  If so, SG_LIST_NULL is set in the
4678c2ecf20Sopenharmony_ci * residual sg ptr and the transfer is considered complete.  If the
4688c2ecf20Sopenharmony_ci * sequencer determines that there is a residual in the tranfer, or
4698c2ecf20Sopenharmony_ci * there is non-zero status, it will set the SG_STATUS_VALID flag in
4708c2ecf20Sopenharmony_ci * sgptr and dma the scb back into host memory.  To sumarize:
4718c2ecf20Sopenharmony_ci *
4728c2ecf20Sopenharmony_ci * Sequencer:
4738c2ecf20Sopenharmony_ci *	o A residual has occurred if SG_FULL_RESID is set in sgptr,
4748c2ecf20Sopenharmony_ci *	  or residual_sgptr does not have SG_LIST_NULL set.
4758c2ecf20Sopenharmony_ci *
4768c2ecf20Sopenharmony_ci *	o We are transferring the last segment if residual_datacnt has
4778c2ecf20Sopenharmony_ci *	  the SG_LAST_SEG flag set.
4788c2ecf20Sopenharmony_ci *
4798c2ecf20Sopenharmony_ci * Host:
4808c2ecf20Sopenharmony_ci *	o A residual can only have occurred if a completed scb has the
4818c2ecf20Sopenharmony_ci *	  SG_STATUS_VALID flag set.  Inspection of the SCSI status field,
4828c2ecf20Sopenharmony_ci *	  the residual_datacnt, and the residual_sgptr field will tell
4838c2ecf20Sopenharmony_ci *	  for sure.
4848c2ecf20Sopenharmony_ci *
4858c2ecf20Sopenharmony_ci *	o residual_sgptr and sgptr refer to the "next" sg entry
4868c2ecf20Sopenharmony_ci *	  and so may point beyond the last valid sg entry for the
4878c2ecf20Sopenharmony_ci *	  transfer.
4888c2ecf20Sopenharmony_ci */
4898c2ecf20Sopenharmony_ci#define SG_PTR_MASK	0xFFFFFFF8
4908c2ecf20Sopenharmony_ci/*16*/	uint16_t tag;		/* Reused by Sequencer. */
4918c2ecf20Sopenharmony_ci/*18*/	uint8_t  control;	/* See SCB_CONTROL in aic79xx.reg for details */
4928c2ecf20Sopenharmony_ci/*19*/	uint8_t	 scsiid;	/*
4938c2ecf20Sopenharmony_ci				 * Selection out Id
4948c2ecf20Sopenharmony_ci				 * Our Id (bits 0-3) Their ID (bits 4-7)
4958c2ecf20Sopenharmony_ci				 */
4968c2ecf20Sopenharmony_ci/*20*/	uint8_t  lun;
4978c2ecf20Sopenharmony_ci/*21*/	uint8_t  task_attribute;
4988c2ecf20Sopenharmony_ci/*22*/	uint8_t  cdb_len;
4998c2ecf20Sopenharmony_ci/*23*/	uint8_t  task_management;
5008c2ecf20Sopenharmony_ci/*24*/	uint64_t dataptr;
5018c2ecf20Sopenharmony_ci/*32*/	uint32_t datacnt;	/* Byte 3 is spare. */
5028c2ecf20Sopenharmony_ci/*36*/	uint32_t sgptr;
5038c2ecf20Sopenharmony_ci/*40*/	uint32_t hscb_busaddr;
5048c2ecf20Sopenharmony_ci/*44*/	uint32_t next_hscb_busaddr;
5058c2ecf20Sopenharmony_ci/********** Long lun field only downloaded for full 8 byte lun support ********/
5068c2ecf20Sopenharmony_ci/*48*/  uint8_t	 pkt_long_lun[8];
5078c2ecf20Sopenharmony_ci/******* Fields below are not Downloaded (Sequencer may use for scratch) ******/
5088c2ecf20Sopenharmony_ci/*56*/  uint8_t	 spare[8];
5098c2ecf20Sopenharmony_ci};
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_ci/************************ Kernel SCB Definitions ******************************/
5128c2ecf20Sopenharmony_ci/*
5138c2ecf20Sopenharmony_ci * Some fields of the SCB are OS dependent.  Here we collect the
5148c2ecf20Sopenharmony_ci * definitions for elements that all OS platforms need to include
5158c2ecf20Sopenharmony_ci * in there SCB definition.
5168c2ecf20Sopenharmony_ci */
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_ci/*
5198c2ecf20Sopenharmony_ci * Definition of a scatter/gather element as transferred to the controller.
5208c2ecf20Sopenharmony_ci * The aic7xxx chips only support a 24bit length.  We use the top byte of
5218c2ecf20Sopenharmony_ci * the length to store additional address bits and a flag to indicate
5228c2ecf20Sopenharmony_ci * that a given segment terminates the transfer.  This gives us an
5238c2ecf20Sopenharmony_ci * addressable range of 512GB on machines with 64bit PCI or with chips
5248c2ecf20Sopenharmony_ci * that can support dual address cycles on 32bit PCI busses.
5258c2ecf20Sopenharmony_ci */
5268c2ecf20Sopenharmony_cistruct ahd_dma_seg {
5278c2ecf20Sopenharmony_ci	uint32_t	addr;
5288c2ecf20Sopenharmony_ci	uint32_t	len;
5298c2ecf20Sopenharmony_ci#define	AHD_DMA_LAST_SEG	0x80000000
5308c2ecf20Sopenharmony_ci#define	AHD_SG_HIGH_ADDR_MASK	0x7F000000
5318c2ecf20Sopenharmony_ci#define	AHD_SG_LEN_MASK		0x00FFFFFF
5328c2ecf20Sopenharmony_ci};
5338c2ecf20Sopenharmony_ci
5348c2ecf20Sopenharmony_cistruct ahd_dma64_seg {
5358c2ecf20Sopenharmony_ci	uint64_t	addr;
5368c2ecf20Sopenharmony_ci	uint32_t	len;
5378c2ecf20Sopenharmony_ci	uint32_t	pad;
5388c2ecf20Sopenharmony_ci};
5398c2ecf20Sopenharmony_ci
5408c2ecf20Sopenharmony_cistruct map_node {
5418c2ecf20Sopenharmony_ci	bus_dmamap_t		 dmamap;
5428c2ecf20Sopenharmony_ci	dma_addr_t		 physaddr;
5438c2ecf20Sopenharmony_ci	uint8_t			*vaddr;
5448c2ecf20Sopenharmony_ci	SLIST_ENTRY(map_node)	 links;
5458c2ecf20Sopenharmony_ci};
5468c2ecf20Sopenharmony_ci
5478c2ecf20Sopenharmony_ci/*
5488c2ecf20Sopenharmony_ci * The current state of this SCB.
5498c2ecf20Sopenharmony_ci */
5508c2ecf20Sopenharmony_citypedef enum {
5518c2ecf20Sopenharmony_ci	SCB_FLAG_NONE		= 0x00000,
5528c2ecf20Sopenharmony_ci	SCB_TRANSMISSION_ERROR	= 0x00001,/*
5538c2ecf20Sopenharmony_ci					   * We detected a parity or CRC
5548c2ecf20Sopenharmony_ci					   * error that has effected the
5558c2ecf20Sopenharmony_ci					   * payload of the command.  This
5568c2ecf20Sopenharmony_ci					   * flag is checked when normal
5578c2ecf20Sopenharmony_ci					   * status is returned to catch
5588c2ecf20Sopenharmony_ci					   * the case of a target not
5598c2ecf20Sopenharmony_ci					   * responding to our attempt
5608c2ecf20Sopenharmony_ci					   * to report the error.
5618c2ecf20Sopenharmony_ci					   */
5628c2ecf20Sopenharmony_ci	SCB_OTHERTCL_TIMEOUT	= 0x00002,/*
5638c2ecf20Sopenharmony_ci					   * Another device was active
5648c2ecf20Sopenharmony_ci					   * during the first timeout for
5658c2ecf20Sopenharmony_ci					   * this SCB so we gave ourselves
5668c2ecf20Sopenharmony_ci					   * an additional timeout period
5678c2ecf20Sopenharmony_ci					   * in case it was hogging the
5688c2ecf20Sopenharmony_ci					   * bus.
5698c2ecf20Sopenharmony_ci				           */
5708c2ecf20Sopenharmony_ci	SCB_DEVICE_RESET	= 0x00004,
5718c2ecf20Sopenharmony_ci	SCB_SENSE		= 0x00008,
5728c2ecf20Sopenharmony_ci	SCB_CDB32_PTR		= 0x00010,
5738c2ecf20Sopenharmony_ci	SCB_RECOVERY_SCB	= 0x00020,
5748c2ecf20Sopenharmony_ci	SCB_AUTO_NEGOTIATE	= 0x00040,/* Negotiate to achieve goal. */
5758c2ecf20Sopenharmony_ci	SCB_NEGOTIATE		= 0x00080,/* Negotiation forced for command. */
5768c2ecf20Sopenharmony_ci	SCB_ABORT		= 0x00100,
5778c2ecf20Sopenharmony_ci	SCB_ACTIVE		= 0x00200,
5788c2ecf20Sopenharmony_ci	SCB_TARGET_IMMEDIATE	= 0x00400,
5798c2ecf20Sopenharmony_ci	SCB_PACKETIZED		= 0x00800,
5808c2ecf20Sopenharmony_ci	SCB_EXPECT_PPR_BUSFREE	= 0x01000,
5818c2ecf20Sopenharmony_ci	SCB_PKT_SENSE		= 0x02000,
5828c2ecf20Sopenharmony_ci	SCB_EXTERNAL_RESET	= 0x04000,/* Device was reset externally */
5838c2ecf20Sopenharmony_ci	SCB_ON_COL_LIST		= 0x08000,
5848c2ecf20Sopenharmony_ci	SCB_SILENT		= 0x10000 /*
5858c2ecf20Sopenharmony_ci					   * Be quiet about transmission type
5868c2ecf20Sopenharmony_ci					   * errors.  They are expected and we
5878c2ecf20Sopenharmony_ci					   * don't want to upset the user.  This
5888c2ecf20Sopenharmony_ci					   * flag is typically used during DV.
5898c2ecf20Sopenharmony_ci					   */
5908c2ecf20Sopenharmony_ci} scb_flag;
5918c2ecf20Sopenharmony_ci
5928c2ecf20Sopenharmony_cistruct scb {
5938c2ecf20Sopenharmony_ci	struct	hardware_scb	 *hscb;
5948c2ecf20Sopenharmony_ci	union {
5958c2ecf20Sopenharmony_ci		SLIST_ENTRY(scb)  sle;
5968c2ecf20Sopenharmony_ci		LIST_ENTRY(scb)	  le;
5978c2ecf20Sopenharmony_ci		TAILQ_ENTRY(scb)  tqe;
5988c2ecf20Sopenharmony_ci	} links;
5998c2ecf20Sopenharmony_ci	union {
6008c2ecf20Sopenharmony_ci		SLIST_ENTRY(scb)  sle;
6018c2ecf20Sopenharmony_ci		LIST_ENTRY(scb)	  le;
6028c2ecf20Sopenharmony_ci		TAILQ_ENTRY(scb)  tqe;
6038c2ecf20Sopenharmony_ci	} links2;
6048c2ecf20Sopenharmony_ci#define pending_links links2.le
6058c2ecf20Sopenharmony_ci#define collision_links links2.le
6068c2ecf20Sopenharmony_ci	struct scb		 *col_scb;
6078c2ecf20Sopenharmony_ci	ahd_io_ctx_t		  io_ctx;
6088c2ecf20Sopenharmony_ci	struct ahd_softc	 *ahd_softc;
6098c2ecf20Sopenharmony_ci	scb_flag		  flags;
6108c2ecf20Sopenharmony_ci	struct scb_platform_data *platform_data;
6118c2ecf20Sopenharmony_ci	struct map_node	 	 *hscb_map;
6128c2ecf20Sopenharmony_ci	struct map_node	 	 *sg_map;
6138c2ecf20Sopenharmony_ci	struct map_node	 	 *sense_map;
6148c2ecf20Sopenharmony_ci	void			 *sg_list;
6158c2ecf20Sopenharmony_ci	uint8_t			 *sense_data;
6168c2ecf20Sopenharmony_ci	dma_addr_t		  sg_list_busaddr;
6178c2ecf20Sopenharmony_ci	dma_addr_t		  sense_busaddr;
6188c2ecf20Sopenharmony_ci	u_int			  sg_count;/* How full ahd_dma_seg is */
6198c2ecf20Sopenharmony_ci#define	AHD_MAX_LQ_CRC_ERRORS 5
6208c2ecf20Sopenharmony_ci	u_int			  crc_retry_count;
6218c2ecf20Sopenharmony_ci};
6228c2ecf20Sopenharmony_ci
6238c2ecf20Sopenharmony_ciTAILQ_HEAD(scb_tailq, scb);
6248c2ecf20Sopenharmony_ciBSD_LIST_HEAD(scb_list, scb);
6258c2ecf20Sopenharmony_ci
6268c2ecf20Sopenharmony_cistruct scb_data {
6278c2ecf20Sopenharmony_ci	/*
6288c2ecf20Sopenharmony_ci	 * TAILQ of lists of free SCBs grouped by device
6298c2ecf20Sopenharmony_ci	 * collision domains.
6308c2ecf20Sopenharmony_ci	 */
6318c2ecf20Sopenharmony_ci	struct scb_tailq free_scbs;
6328c2ecf20Sopenharmony_ci
6338c2ecf20Sopenharmony_ci	/*
6348c2ecf20Sopenharmony_ci	 * Per-device lists of SCBs whose tag ID would collide
6358c2ecf20Sopenharmony_ci	 * with an already active tag on the device.
6368c2ecf20Sopenharmony_ci	 */
6378c2ecf20Sopenharmony_ci	struct scb_list free_scb_lists[AHD_NUM_TARGETS * AHD_NUM_LUNS_NONPKT];
6388c2ecf20Sopenharmony_ci
6398c2ecf20Sopenharmony_ci	/*
6408c2ecf20Sopenharmony_ci	 * SCBs that will not collide with any active device.
6418c2ecf20Sopenharmony_ci	 */
6428c2ecf20Sopenharmony_ci	struct scb_list any_dev_free_scb_list;
6438c2ecf20Sopenharmony_ci
6448c2ecf20Sopenharmony_ci	/*
6458c2ecf20Sopenharmony_ci	 * Mapping from tag to SCB.
6468c2ecf20Sopenharmony_ci	 */
6478c2ecf20Sopenharmony_ci	struct	scb *scbindex[AHD_SCB_MAX];
6488c2ecf20Sopenharmony_ci
6498c2ecf20Sopenharmony_ci	/*
6508c2ecf20Sopenharmony_ci	 * "Bus" addresses of our data structures.
6518c2ecf20Sopenharmony_ci	 */
6528c2ecf20Sopenharmony_ci	bus_dma_tag_t	 hscb_dmat;	/* dmat for our hardware SCB array */
6538c2ecf20Sopenharmony_ci	bus_dma_tag_t	 sg_dmat;	/* dmat for our sg segments */
6548c2ecf20Sopenharmony_ci	bus_dma_tag_t	 sense_dmat;	/* dmat for our sense buffers */
6558c2ecf20Sopenharmony_ci	SLIST_HEAD(, map_node) hscb_maps;
6568c2ecf20Sopenharmony_ci	SLIST_HEAD(, map_node) sg_maps;
6578c2ecf20Sopenharmony_ci	SLIST_HEAD(, map_node) sense_maps;
6588c2ecf20Sopenharmony_ci	int		 scbs_left;	/* unallocated scbs in head map_node */
6598c2ecf20Sopenharmony_ci	int		 sgs_left;	/* unallocated sgs in head map_node */
6608c2ecf20Sopenharmony_ci	int		 sense_left;	/* unallocated sense in head map_node */
6618c2ecf20Sopenharmony_ci	uint16_t	 numscbs;
6628c2ecf20Sopenharmony_ci	uint16_t	 maxhscbs;	/* Number of SCBs on the card */
6638c2ecf20Sopenharmony_ci	uint8_t		 init_level;	/*
6648c2ecf20Sopenharmony_ci					 * How far we've initialized
6658c2ecf20Sopenharmony_ci					 * this structure.
6668c2ecf20Sopenharmony_ci					 */
6678c2ecf20Sopenharmony_ci};
6688c2ecf20Sopenharmony_ci
6698c2ecf20Sopenharmony_ci/************************ Target Mode Definitions *****************************/
6708c2ecf20Sopenharmony_ci
6718c2ecf20Sopenharmony_ci/*
6728c2ecf20Sopenharmony_ci * Connection descriptor for select-in requests in target mode.
6738c2ecf20Sopenharmony_ci */
6748c2ecf20Sopenharmony_cistruct target_cmd {
6758c2ecf20Sopenharmony_ci	uint8_t scsiid;		/* Our ID and the initiator's ID */
6768c2ecf20Sopenharmony_ci	uint8_t identify;	/* Identify message */
6778c2ecf20Sopenharmony_ci	uint8_t bytes[22];	/*
6788c2ecf20Sopenharmony_ci				 * Bytes contains any additional message
6798c2ecf20Sopenharmony_ci				 * bytes terminated by 0xFF.  The remainder
6808c2ecf20Sopenharmony_ci				 * is the cdb to execute.
6818c2ecf20Sopenharmony_ci				 */
6828c2ecf20Sopenharmony_ci	uint8_t cmd_valid;	/*
6838c2ecf20Sopenharmony_ci				 * When a command is complete, the firmware
6848c2ecf20Sopenharmony_ci				 * will set cmd_valid to all bits set.
6858c2ecf20Sopenharmony_ci				 * After the host has seen the command,
6868c2ecf20Sopenharmony_ci				 * the bits are cleared.  This allows us
6878c2ecf20Sopenharmony_ci				 * to just peek at host memory to determine
6888c2ecf20Sopenharmony_ci				 * if more work is complete. cmd_valid is on
6898c2ecf20Sopenharmony_ci				 * an 8 byte boundary to simplify setting
6908c2ecf20Sopenharmony_ci				 * it on aic7880 hardware which only has
6918c2ecf20Sopenharmony_ci				 * limited direct access to the DMA FIFO.
6928c2ecf20Sopenharmony_ci				 */
6938c2ecf20Sopenharmony_ci	uint8_t pad[7];
6948c2ecf20Sopenharmony_ci};
6958c2ecf20Sopenharmony_ci
6968c2ecf20Sopenharmony_ci/*
6978c2ecf20Sopenharmony_ci * Number of events we can buffer up if we run out
6988c2ecf20Sopenharmony_ci * of immediate notify ccbs.
6998c2ecf20Sopenharmony_ci */
7008c2ecf20Sopenharmony_ci#define AHD_TMODE_EVENT_BUFFER_SIZE 8
7018c2ecf20Sopenharmony_cistruct ahd_tmode_event {
7028c2ecf20Sopenharmony_ci	uint8_t initiator_id;
7038c2ecf20Sopenharmony_ci	uint8_t event_type;	/* MSG type or EVENT_TYPE_BUS_RESET */
7048c2ecf20Sopenharmony_ci#define	EVENT_TYPE_BUS_RESET 0xFF
7058c2ecf20Sopenharmony_ci	uint8_t event_arg;
7068c2ecf20Sopenharmony_ci};
7078c2ecf20Sopenharmony_ci
7088c2ecf20Sopenharmony_ci/*
7098c2ecf20Sopenharmony_ci * Per enabled lun target mode state.
7108c2ecf20Sopenharmony_ci * As this state is directly influenced by the host OS'es target mode
7118c2ecf20Sopenharmony_ci * environment, we let the OS module define it.  Forward declare the
7128c2ecf20Sopenharmony_ci * structure here so we can store arrays of them, etc. in OS neutral
7138c2ecf20Sopenharmony_ci * data structures.
7148c2ecf20Sopenharmony_ci */
7158c2ecf20Sopenharmony_ci#ifdef AHD_TARGET_MODE
7168c2ecf20Sopenharmony_cistruct ahd_tmode_lstate {
7178c2ecf20Sopenharmony_ci	struct cam_path *path;
7188c2ecf20Sopenharmony_ci	struct ccb_hdr_slist accept_tios;
7198c2ecf20Sopenharmony_ci	struct ccb_hdr_slist immed_notifies;
7208c2ecf20Sopenharmony_ci	struct ahd_tmode_event event_buffer[AHD_TMODE_EVENT_BUFFER_SIZE];
7218c2ecf20Sopenharmony_ci	uint8_t event_r_idx;
7228c2ecf20Sopenharmony_ci	uint8_t event_w_idx;
7238c2ecf20Sopenharmony_ci};
7248c2ecf20Sopenharmony_ci#else
7258c2ecf20Sopenharmony_cistruct ahd_tmode_lstate;
7268c2ecf20Sopenharmony_ci#endif
7278c2ecf20Sopenharmony_ci
7288c2ecf20Sopenharmony_ci/******************** Transfer Negotiation Datastructures *********************/
7298c2ecf20Sopenharmony_ci#define AHD_TRANS_CUR		0x01	/* Modify current neogtiation status */
7308c2ecf20Sopenharmony_ci#define AHD_TRANS_ACTIVE	0x03	/* Assume this target is on the bus */
7318c2ecf20Sopenharmony_ci#define AHD_TRANS_GOAL		0x04	/* Modify negotiation goal */
7328c2ecf20Sopenharmony_ci#define AHD_TRANS_USER		0x08	/* Modify user negotiation settings */
7338c2ecf20Sopenharmony_ci#define AHD_PERIOD_10MHz	0x19
7348c2ecf20Sopenharmony_ci
7358c2ecf20Sopenharmony_ci#define AHD_WIDTH_UNKNOWN	0xFF
7368c2ecf20Sopenharmony_ci#define AHD_PERIOD_UNKNOWN	0xFF
7378c2ecf20Sopenharmony_ci#define AHD_OFFSET_UNKNOWN	0xFF
7388c2ecf20Sopenharmony_ci#define AHD_PPR_OPTS_UNKNOWN	0xFF
7398c2ecf20Sopenharmony_ci
7408c2ecf20Sopenharmony_ci/*
7418c2ecf20Sopenharmony_ci * Transfer Negotiation Information.
7428c2ecf20Sopenharmony_ci */
7438c2ecf20Sopenharmony_cistruct ahd_transinfo {
7448c2ecf20Sopenharmony_ci	uint8_t protocol_version;	/* SCSI Revision level */
7458c2ecf20Sopenharmony_ci	uint8_t transport_version;	/* SPI Revision level */
7468c2ecf20Sopenharmony_ci	uint8_t width;			/* Bus width */
7478c2ecf20Sopenharmony_ci	uint8_t period;			/* Sync rate factor */
7488c2ecf20Sopenharmony_ci	uint8_t offset;			/* Sync offset */
7498c2ecf20Sopenharmony_ci	uint8_t ppr_options;		/* Parallel Protocol Request options */
7508c2ecf20Sopenharmony_ci};
7518c2ecf20Sopenharmony_ci
7528c2ecf20Sopenharmony_ci/*
7538c2ecf20Sopenharmony_ci * Per-initiator current, goal and user transfer negotiation information. */
7548c2ecf20Sopenharmony_cistruct ahd_initiator_tinfo {
7558c2ecf20Sopenharmony_ci	struct ahd_transinfo curr;
7568c2ecf20Sopenharmony_ci	struct ahd_transinfo goal;
7578c2ecf20Sopenharmony_ci	struct ahd_transinfo user;
7588c2ecf20Sopenharmony_ci};
7598c2ecf20Sopenharmony_ci
7608c2ecf20Sopenharmony_ci/*
7618c2ecf20Sopenharmony_ci * Per enabled target ID state.
7628c2ecf20Sopenharmony_ci * Pointers to lun target state as well as sync/wide negotiation information
7638c2ecf20Sopenharmony_ci * for each initiator<->target mapping.  For the initiator role we pretend
7648c2ecf20Sopenharmony_ci * that we are the target and the targets are the initiators since the
7658c2ecf20Sopenharmony_ci * negotiation is the same regardless of role.
7668c2ecf20Sopenharmony_ci */
7678c2ecf20Sopenharmony_cistruct ahd_tmode_tstate {
7688c2ecf20Sopenharmony_ci	struct ahd_tmode_lstate*	enabled_luns[AHD_NUM_LUNS];
7698c2ecf20Sopenharmony_ci	struct ahd_initiator_tinfo	transinfo[AHD_NUM_TARGETS];
7708c2ecf20Sopenharmony_ci
7718c2ecf20Sopenharmony_ci	/*
7728c2ecf20Sopenharmony_ci	 * Per initiator state bitmasks.
7738c2ecf20Sopenharmony_ci	 */
7748c2ecf20Sopenharmony_ci	uint16_t	 auto_negotiate;/* Auto Negotiation Required */
7758c2ecf20Sopenharmony_ci	uint16_t	 discenable;	/* Disconnection allowed  */
7768c2ecf20Sopenharmony_ci	uint16_t	 tagenable;	/* Tagged Queuing allowed */
7778c2ecf20Sopenharmony_ci};
7788c2ecf20Sopenharmony_ci
7798c2ecf20Sopenharmony_ci/*
7808c2ecf20Sopenharmony_ci * Points of interest along the negotiated transfer scale.
7818c2ecf20Sopenharmony_ci */
7828c2ecf20Sopenharmony_ci#define AHD_SYNCRATE_160	0x8
7838c2ecf20Sopenharmony_ci#define AHD_SYNCRATE_PACED	0x8
7848c2ecf20Sopenharmony_ci#define AHD_SYNCRATE_DT		0x9
7858c2ecf20Sopenharmony_ci#define AHD_SYNCRATE_ULTRA2	0xa
7868c2ecf20Sopenharmony_ci#define AHD_SYNCRATE_ULTRA	0xc
7878c2ecf20Sopenharmony_ci#define AHD_SYNCRATE_FAST	0x19
7888c2ecf20Sopenharmony_ci#define AHD_SYNCRATE_MIN_DT	AHD_SYNCRATE_FAST
7898c2ecf20Sopenharmony_ci#define AHD_SYNCRATE_SYNC	0x32
7908c2ecf20Sopenharmony_ci#define AHD_SYNCRATE_MIN	0x60
7918c2ecf20Sopenharmony_ci#define	AHD_SYNCRATE_ASYNC	0xFF
7928c2ecf20Sopenharmony_ci#define AHD_SYNCRATE_MAX	AHD_SYNCRATE_160
7938c2ecf20Sopenharmony_ci
7948c2ecf20Sopenharmony_ci/* Safe and valid period for async negotiations. */
7958c2ecf20Sopenharmony_ci#define	AHD_ASYNC_XFER_PERIOD	0x44
7968c2ecf20Sopenharmony_ci
7978c2ecf20Sopenharmony_ci/*
7988c2ecf20Sopenharmony_ci * In RevA, the synctable uses a 120MHz rate for the period
7998c2ecf20Sopenharmony_ci * factor 8 and 160MHz for the period factor 7.  The 120MHz
8008c2ecf20Sopenharmony_ci * rate never made it into the official SCSI spec, so we must
8018c2ecf20Sopenharmony_ci * compensate when setting the negotiation table for Rev A
8028c2ecf20Sopenharmony_ci * parts.
8038c2ecf20Sopenharmony_ci */
8048c2ecf20Sopenharmony_ci#define AHD_SYNCRATE_REVA_120	0x8
8058c2ecf20Sopenharmony_ci#define AHD_SYNCRATE_REVA_160	0x7
8068c2ecf20Sopenharmony_ci
8078c2ecf20Sopenharmony_ci/***************************** Lookup Tables **********************************/
8088c2ecf20Sopenharmony_ci/*
8098c2ecf20Sopenharmony_ci * Phase -> name and message out response
8108c2ecf20Sopenharmony_ci * to parity errors in each phase table.
8118c2ecf20Sopenharmony_ci */
8128c2ecf20Sopenharmony_cistruct ahd_phase_table_entry {
8138c2ecf20Sopenharmony_ci        uint8_t phase;
8148c2ecf20Sopenharmony_ci        uint8_t mesg_out; /* Message response to parity errors */
8158c2ecf20Sopenharmony_ci	const char *phasemsg;
8168c2ecf20Sopenharmony_ci};
8178c2ecf20Sopenharmony_ci
8188c2ecf20Sopenharmony_ci/************************** Serial EEPROM Format ******************************/
8198c2ecf20Sopenharmony_ci
8208c2ecf20Sopenharmony_cistruct seeprom_config {
8218c2ecf20Sopenharmony_ci/*
8228c2ecf20Sopenharmony_ci * Per SCSI ID Configuration Flags
8238c2ecf20Sopenharmony_ci */
8248c2ecf20Sopenharmony_ci	uint16_t device_flags[16];	/* words 0-15 */
8258c2ecf20Sopenharmony_ci#define		CFXFER		0x003F	/* synchronous transfer rate */
8268c2ecf20Sopenharmony_ci#define			CFXFER_ASYNC	0x3F
8278c2ecf20Sopenharmony_ci#define		CFQAS		0x0040	/* Negotiate QAS */
8288c2ecf20Sopenharmony_ci#define		CFPACKETIZED	0x0080	/* Negotiate Packetized Transfers */
8298c2ecf20Sopenharmony_ci#define		CFSTART		0x0100	/* send start unit SCSI command */
8308c2ecf20Sopenharmony_ci#define		CFINCBIOS	0x0200	/* include in BIOS scan */
8318c2ecf20Sopenharmony_ci#define		CFDISC		0x0400	/* enable disconnection */
8328c2ecf20Sopenharmony_ci#define		CFMULTILUNDEV	0x0800	/* Probe multiple luns in BIOS scan */
8338c2ecf20Sopenharmony_ci#define		CFWIDEB		0x1000	/* wide bus device */
8348c2ecf20Sopenharmony_ci#define		CFHOSTMANAGED	0x8000	/* Managed by a RAID controller */
8358c2ecf20Sopenharmony_ci
8368c2ecf20Sopenharmony_ci/*
8378c2ecf20Sopenharmony_ci * BIOS Control Bits
8388c2ecf20Sopenharmony_ci */
8398c2ecf20Sopenharmony_ci	uint16_t bios_control;		/* word 16 */
8408c2ecf20Sopenharmony_ci#define		CFSUPREM	0x0001	/* support all removeable drives */
8418c2ecf20Sopenharmony_ci#define		CFSUPREMB	0x0002	/* support removeable boot drives */
8428c2ecf20Sopenharmony_ci#define		CFBIOSSTATE	0x000C	/* BIOS Action State */
8438c2ecf20Sopenharmony_ci#define		    CFBS_DISABLED	0x00
8448c2ecf20Sopenharmony_ci#define		    CFBS_ENABLED	0x04
8458c2ecf20Sopenharmony_ci#define		    CFBS_DISABLED_SCAN	0x08
8468c2ecf20Sopenharmony_ci#define		CFENABLEDV	0x0010	/* Perform Domain Validation */
8478c2ecf20Sopenharmony_ci#define		CFCTRL_A	0x0020	/* BIOS displays Ctrl-A message */
8488c2ecf20Sopenharmony_ci#define		CFSPARITY	0x0040	/* SCSI parity */
8498c2ecf20Sopenharmony_ci#define		CFEXTEND	0x0080	/* extended translation enabled */
8508c2ecf20Sopenharmony_ci#define		CFBOOTCD	0x0100  /* Support Bootable CD-ROM */
8518c2ecf20Sopenharmony_ci#define		CFMSG_LEVEL	0x0600	/* BIOS Message Level */
8528c2ecf20Sopenharmony_ci#define			CFMSG_VERBOSE	0x0000
8538c2ecf20Sopenharmony_ci#define			CFMSG_SILENT	0x0200
8548c2ecf20Sopenharmony_ci#define			CFMSG_DIAG	0x0400
8558c2ecf20Sopenharmony_ci#define		CFRESETB	0x0800	/* reset SCSI bus at boot */
8568c2ecf20Sopenharmony_ci/*		UNUSED		0xf000	*/
8578c2ecf20Sopenharmony_ci
8588c2ecf20Sopenharmony_ci/*
8598c2ecf20Sopenharmony_ci * Host Adapter Control Bits
8608c2ecf20Sopenharmony_ci */
8618c2ecf20Sopenharmony_ci	uint16_t adapter_control;	/* word 17 */
8628c2ecf20Sopenharmony_ci#define		CFAUTOTERM	0x0001	/* Perform Auto termination */
8638c2ecf20Sopenharmony_ci#define		CFSTERM		0x0002	/* SCSI low byte termination */
8648c2ecf20Sopenharmony_ci#define		CFWSTERM	0x0004	/* SCSI high byte termination */
8658c2ecf20Sopenharmony_ci#define		CFSEAUTOTERM	0x0008	/* Ultra2 Perform secondary Auto Term*/
8668c2ecf20Sopenharmony_ci#define		CFSELOWTERM	0x0010	/* Ultra2 secondary low term */
8678c2ecf20Sopenharmony_ci#define		CFSEHIGHTERM	0x0020	/* Ultra2 secondary high term */
8688c2ecf20Sopenharmony_ci#define		CFSTPWLEVEL	0x0040	/* Termination level control */
8698c2ecf20Sopenharmony_ci#define		CFBIOSAUTOTERM	0x0080	/* Perform Auto termination */
8708c2ecf20Sopenharmony_ci#define		CFTERM_MENU	0x0100	/* BIOS displays termination menu */
8718c2ecf20Sopenharmony_ci#define		CFCLUSTERENB	0x8000	/* Cluster Enable */
8728c2ecf20Sopenharmony_ci
8738c2ecf20Sopenharmony_ci/*
8748c2ecf20Sopenharmony_ci * Bus Release Time, Host Adapter ID
8758c2ecf20Sopenharmony_ci */
8768c2ecf20Sopenharmony_ci	uint16_t brtime_id;		/* word 18 */
8778c2ecf20Sopenharmony_ci#define		CFSCSIID	0x000f	/* host adapter SCSI ID */
8788c2ecf20Sopenharmony_ci/*		UNUSED		0x00f0	*/
8798c2ecf20Sopenharmony_ci#define		CFBRTIME	0xff00	/* bus release time/PCI Latency Time */
8808c2ecf20Sopenharmony_ci
8818c2ecf20Sopenharmony_ci/*
8828c2ecf20Sopenharmony_ci * Maximum targets
8838c2ecf20Sopenharmony_ci */
8848c2ecf20Sopenharmony_ci	uint16_t max_targets;		/* word 19 */
8858c2ecf20Sopenharmony_ci#define		CFMAXTARG	0x00ff	/* maximum targets */
8868c2ecf20Sopenharmony_ci#define		CFBOOTLUN	0x0f00	/* Lun to boot from */
8878c2ecf20Sopenharmony_ci#define		CFBOOTID	0xf000	/* Target to boot from */
8888c2ecf20Sopenharmony_ci	uint16_t res_1[10];		/* words 20-29 */
8898c2ecf20Sopenharmony_ci	uint16_t signature;		/* BIOS Signature */
8908c2ecf20Sopenharmony_ci#define		CFSIGNATURE	0x400
8918c2ecf20Sopenharmony_ci	uint16_t checksum;		/* word 31 */
8928c2ecf20Sopenharmony_ci};
8938c2ecf20Sopenharmony_ci
8948c2ecf20Sopenharmony_ci/*
8958c2ecf20Sopenharmony_ci * Vital Product Data used during POST and by the BIOS.
8968c2ecf20Sopenharmony_ci */
8978c2ecf20Sopenharmony_cistruct vpd_config {
8988c2ecf20Sopenharmony_ci	uint8_t  bios_flags;
8998c2ecf20Sopenharmony_ci#define		VPDMASTERBIOS	0x0001
9008c2ecf20Sopenharmony_ci#define		VPDBOOTHOST	0x0002
9018c2ecf20Sopenharmony_ci	uint8_t  reserved_1[21];
9028c2ecf20Sopenharmony_ci	uint8_t  resource_type;
9038c2ecf20Sopenharmony_ci	uint8_t  resource_len[2];
9048c2ecf20Sopenharmony_ci	uint8_t  resource_data[8];
9058c2ecf20Sopenharmony_ci	uint8_t  vpd_tag;
9068c2ecf20Sopenharmony_ci	uint16_t vpd_len;
9078c2ecf20Sopenharmony_ci	uint8_t  vpd_keyword[2];
9088c2ecf20Sopenharmony_ci	uint8_t  length;
9098c2ecf20Sopenharmony_ci	uint8_t  revision;
9108c2ecf20Sopenharmony_ci	uint8_t  device_flags;
9118c2ecf20Sopenharmony_ci	uint8_t  termination_menus[2];
9128c2ecf20Sopenharmony_ci	uint8_t  fifo_threshold;
9138c2ecf20Sopenharmony_ci	uint8_t  end_tag;
9148c2ecf20Sopenharmony_ci	uint8_t  vpd_checksum;
9158c2ecf20Sopenharmony_ci	uint16_t default_target_flags;
9168c2ecf20Sopenharmony_ci	uint16_t default_bios_flags;
9178c2ecf20Sopenharmony_ci	uint16_t default_ctrl_flags;
9188c2ecf20Sopenharmony_ci	uint8_t  default_irq;
9198c2ecf20Sopenharmony_ci	uint8_t  pci_lattime;
9208c2ecf20Sopenharmony_ci	uint8_t  max_target;
9218c2ecf20Sopenharmony_ci	uint8_t  boot_lun;
9228c2ecf20Sopenharmony_ci	uint16_t signature;
9238c2ecf20Sopenharmony_ci	uint8_t  reserved_2;
9248c2ecf20Sopenharmony_ci	uint8_t  checksum;
9258c2ecf20Sopenharmony_ci	uint8_t	 reserved_3[4];
9268c2ecf20Sopenharmony_ci};
9278c2ecf20Sopenharmony_ci
9288c2ecf20Sopenharmony_ci/****************************** Flexport Logic ********************************/
9298c2ecf20Sopenharmony_ci#define FLXADDR_TERMCTL			0x0
9308c2ecf20Sopenharmony_ci#define		FLX_TERMCTL_ENSECHIGH	0x8
9318c2ecf20Sopenharmony_ci#define		FLX_TERMCTL_ENSECLOW	0x4
9328c2ecf20Sopenharmony_ci#define		FLX_TERMCTL_ENPRIHIGH	0x2
9338c2ecf20Sopenharmony_ci#define		FLX_TERMCTL_ENPRILOW	0x1
9348c2ecf20Sopenharmony_ci#define FLXADDR_ROMSTAT_CURSENSECTL	0x1
9358c2ecf20Sopenharmony_ci#define		FLX_ROMSTAT_SEECFG	0xF0
9368c2ecf20Sopenharmony_ci#define		FLX_ROMSTAT_EECFG	0x0F
9378c2ecf20Sopenharmony_ci#define		FLX_ROMSTAT_SEE_93C66	0x00
9388c2ecf20Sopenharmony_ci#define		FLX_ROMSTAT_SEE_NONE	0xF0
9398c2ecf20Sopenharmony_ci#define		FLX_ROMSTAT_EE_512x8	0x0
9408c2ecf20Sopenharmony_ci#define		FLX_ROMSTAT_EE_1MBx8	0x1
9418c2ecf20Sopenharmony_ci#define		FLX_ROMSTAT_EE_2MBx8	0x2
9428c2ecf20Sopenharmony_ci#define		FLX_ROMSTAT_EE_4MBx8	0x3
9438c2ecf20Sopenharmony_ci#define		FLX_ROMSTAT_EE_16MBx8	0x4
9448c2ecf20Sopenharmony_ci#define 		CURSENSE_ENB	0x1
9458c2ecf20Sopenharmony_ci#define	FLXADDR_FLEXSTAT		0x2
9468c2ecf20Sopenharmony_ci#define		FLX_FSTAT_BUSY		0x1
9478c2ecf20Sopenharmony_ci#define FLXADDR_CURRENT_STAT		0x4
9488c2ecf20Sopenharmony_ci#define		FLX_CSTAT_SEC_HIGH	0xC0
9498c2ecf20Sopenharmony_ci#define		FLX_CSTAT_SEC_LOW	0x30
9508c2ecf20Sopenharmony_ci#define		FLX_CSTAT_PRI_HIGH	0x0C
9518c2ecf20Sopenharmony_ci#define		FLX_CSTAT_PRI_LOW	0x03
9528c2ecf20Sopenharmony_ci#define		FLX_CSTAT_MASK		0x03
9538c2ecf20Sopenharmony_ci#define		FLX_CSTAT_SHIFT		2
9548c2ecf20Sopenharmony_ci#define		FLX_CSTAT_OKAY		0x0
9558c2ecf20Sopenharmony_ci#define		FLX_CSTAT_OVER		0x1
9568c2ecf20Sopenharmony_ci#define		FLX_CSTAT_UNDER		0x2
9578c2ecf20Sopenharmony_ci#define		FLX_CSTAT_INVALID	0x3
9588c2ecf20Sopenharmony_ci
9598c2ecf20Sopenharmony_ciint		ahd_read_seeprom(struct ahd_softc *ahd, uint16_t *buf,
9608c2ecf20Sopenharmony_ci				 u_int start_addr, u_int count, int bstream);
9618c2ecf20Sopenharmony_ci
9628c2ecf20Sopenharmony_ciint		ahd_write_seeprom(struct ahd_softc *ahd, uint16_t *buf,
9638c2ecf20Sopenharmony_ci				  u_int start_addr, u_int count);
9648c2ecf20Sopenharmony_ciint		ahd_verify_cksum(struct seeprom_config *sc);
9658c2ecf20Sopenharmony_ciint		ahd_acquire_seeprom(struct ahd_softc *ahd);
9668c2ecf20Sopenharmony_civoid		ahd_release_seeprom(struct ahd_softc *ahd);
9678c2ecf20Sopenharmony_ci
9688c2ecf20Sopenharmony_ci/****************************  Message Buffer *********************************/
9698c2ecf20Sopenharmony_citypedef enum {
9708c2ecf20Sopenharmony_ci	MSG_FLAG_NONE			= 0x00,
9718c2ecf20Sopenharmony_ci	MSG_FLAG_EXPECT_PPR_BUSFREE	= 0x01,
9728c2ecf20Sopenharmony_ci	MSG_FLAG_IU_REQ_CHANGED		= 0x02,
9738c2ecf20Sopenharmony_ci	MSG_FLAG_EXPECT_IDE_BUSFREE	= 0x04,
9748c2ecf20Sopenharmony_ci	MSG_FLAG_EXPECT_QASREJ_BUSFREE	= 0x08,
9758c2ecf20Sopenharmony_ci	MSG_FLAG_PACKETIZED		= 0x10
9768c2ecf20Sopenharmony_ci} ahd_msg_flags;
9778c2ecf20Sopenharmony_ci
9788c2ecf20Sopenharmony_citypedef enum {
9798c2ecf20Sopenharmony_ci	MSG_TYPE_NONE			= 0x00,
9808c2ecf20Sopenharmony_ci	MSG_TYPE_INITIATOR_MSGOUT	= 0x01,
9818c2ecf20Sopenharmony_ci	MSG_TYPE_INITIATOR_MSGIN	= 0x02,
9828c2ecf20Sopenharmony_ci	MSG_TYPE_TARGET_MSGOUT		= 0x03,
9838c2ecf20Sopenharmony_ci	MSG_TYPE_TARGET_MSGIN		= 0x04
9848c2ecf20Sopenharmony_ci} ahd_msg_type;
9858c2ecf20Sopenharmony_ci
9868c2ecf20Sopenharmony_citypedef enum {
9878c2ecf20Sopenharmony_ci	MSGLOOP_IN_PROG,
9888c2ecf20Sopenharmony_ci	MSGLOOP_MSGCOMPLETE,
9898c2ecf20Sopenharmony_ci	MSGLOOP_TERMINATED
9908c2ecf20Sopenharmony_ci} msg_loop_stat;
9918c2ecf20Sopenharmony_ci
9928c2ecf20Sopenharmony_ci/*********************** Software Configuration Structure *********************/
9938c2ecf20Sopenharmony_cistruct ahd_suspend_channel_state {
9948c2ecf20Sopenharmony_ci	uint8_t	scsiseq;
9958c2ecf20Sopenharmony_ci	uint8_t	sxfrctl0;
9968c2ecf20Sopenharmony_ci	uint8_t	sxfrctl1;
9978c2ecf20Sopenharmony_ci	uint8_t	simode0;
9988c2ecf20Sopenharmony_ci	uint8_t	simode1;
9998c2ecf20Sopenharmony_ci	uint8_t	seltimer;
10008c2ecf20Sopenharmony_ci	uint8_t	seqctl;
10018c2ecf20Sopenharmony_ci};
10028c2ecf20Sopenharmony_ci
10038c2ecf20Sopenharmony_cistruct ahd_suspend_pci_state {
10048c2ecf20Sopenharmony_ci	uint32_t  devconfig;
10058c2ecf20Sopenharmony_ci	uint8_t   command;
10068c2ecf20Sopenharmony_ci	uint8_t   csize_lattime;
10078c2ecf20Sopenharmony_ci};
10088c2ecf20Sopenharmony_ci
10098c2ecf20Sopenharmony_cistruct ahd_suspend_state {
10108c2ecf20Sopenharmony_ci	struct	ahd_suspend_channel_state channel[2];
10118c2ecf20Sopenharmony_ci	struct  ahd_suspend_pci_state pci_state;
10128c2ecf20Sopenharmony_ci	uint8_t	optionmode;
10138c2ecf20Sopenharmony_ci	uint8_t	dscommand0;
10148c2ecf20Sopenharmony_ci	uint8_t	dspcistatus;
10158c2ecf20Sopenharmony_ci	/* hsmailbox */
10168c2ecf20Sopenharmony_ci	uint8_t	crccontrol1;
10178c2ecf20Sopenharmony_ci	uint8_t	scbbaddr;
10188c2ecf20Sopenharmony_ci	/* Host and sequencer SCB counts */
10198c2ecf20Sopenharmony_ci	uint8_t	dff_thrsh;
10208c2ecf20Sopenharmony_ci	uint8_t	*scratch_ram;
10218c2ecf20Sopenharmony_ci	uint8_t	*btt;
10228c2ecf20Sopenharmony_ci};
10238c2ecf20Sopenharmony_ci
10248c2ecf20Sopenharmony_citypedef void (*ahd_bus_intr_t)(struct ahd_softc *);
10258c2ecf20Sopenharmony_ci
10268c2ecf20Sopenharmony_citypedef enum {
10278c2ecf20Sopenharmony_ci	AHD_MODE_DFF0,
10288c2ecf20Sopenharmony_ci	AHD_MODE_DFF1,
10298c2ecf20Sopenharmony_ci	AHD_MODE_CCHAN,
10308c2ecf20Sopenharmony_ci	AHD_MODE_SCSI,
10318c2ecf20Sopenharmony_ci	AHD_MODE_CFG,
10328c2ecf20Sopenharmony_ci	AHD_MODE_UNKNOWN
10338c2ecf20Sopenharmony_ci} ahd_mode;
10348c2ecf20Sopenharmony_ci
10358c2ecf20Sopenharmony_ci#define AHD_MK_MSK(x) (0x01 << (x))
10368c2ecf20Sopenharmony_ci#define AHD_MODE_DFF0_MSK	AHD_MK_MSK(AHD_MODE_DFF0)
10378c2ecf20Sopenharmony_ci#define AHD_MODE_DFF1_MSK	AHD_MK_MSK(AHD_MODE_DFF1)
10388c2ecf20Sopenharmony_ci#define AHD_MODE_CCHAN_MSK	AHD_MK_MSK(AHD_MODE_CCHAN)
10398c2ecf20Sopenharmony_ci#define AHD_MODE_SCSI_MSK	AHD_MK_MSK(AHD_MODE_SCSI)
10408c2ecf20Sopenharmony_ci#define AHD_MODE_CFG_MSK	AHD_MK_MSK(AHD_MODE_CFG)
10418c2ecf20Sopenharmony_ci#define AHD_MODE_UNKNOWN_MSK	AHD_MK_MSK(AHD_MODE_UNKNOWN)
10428c2ecf20Sopenharmony_ci#define AHD_MODE_ANY_MSK (~0)
10438c2ecf20Sopenharmony_ci
10448c2ecf20Sopenharmony_citypedef uint8_t ahd_mode_state;
10458c2ecf20Sopenharmony_ci
10468c2ecf20Sopenharmony_cistruct ahd_completion
10478c2ecf20Sopenharmony_ci{
10488c2ecf20Sopenharmony_ci	uint16_t	tag;
10498c2ecf20Sopenharmony_ci	uint8_t		sg_status;
10508c2ecf20Sopenharmony_ci	uint8_t		valid_tag;
10518c2ecf20Sopenharmony_ci};
10528c2ecf20Sopenharmony_ci
10538c2ecf20Sopenharmony_cistruct ahd_softc {
10548c2ecf20Sopenharmony_ci	bus_space_tag_t           tags[2];
10558c2ecf20Sopenharmony_ci	bus_space_handle_t        bshs[2];
10568c2ecf20Sopenharmony_ci	struct scb_data		  scb_data;
10578c2ecf20Sopenharmony_ci
10588c2ecf20Sopenharmony_ci	struct hardware_scb	 *next_queued_hscb;
10598c2ecf20Sopenharmony_ci	struct map_node		 *next_queued_hscb_map;
10608c2ecf20Sopenharmony_ci
10618c2ecf20Sopenharmony_ci	/*
10628c2ecf20Sopenharmony_ci	 * SCBs that have been sent to the controller
10638c2ecf20Sopenharmony_ci	 */
10648c2ecf20Sopenharmony_ci	BSD_LIST_HEAD(, scb)	  pending_scbs;
10658c2ecf20Sopenharmony_ci
10668c2ecf20Sopenharmony_ci	/*
10678c2ecf20Sopenharmony_ci	 * Current register window mode information.
10688c2ecf20Sopenharmony_ci	 */
10698c2ecf20Sopenharmony_ci	ahd_mode		  dst_mode;
10708c2ecf20Sopenharmony_ci	ahd_mode		  src_mode;
10718c2ecf20Sopenharmony_ci
10728c2ecf20Sopenharmony_ci	/*
10738c2ecf20Sopenharmony_ci	 * Saved register window mode information
10748c2ecf20Sopenharmony_ci	 * used for restore on next unpause.
10758c2ecf20Sopenharmony_ci	 */
10768c2ecf20Sopenharmony_ci	ahd_mode		  saved_dst_mode;
10778c2ecf20Sopenharmony_ci	ahd_mode		  saved_src_mode;
10788c2ecf20Sopenharmony_ci
10798c2ecf20Sopenharmony_ci	/*
10808c2ecf20Sopenharmony_ci	 * Platform specific data.
10818c2ecf20Sopenharmony_ci	 */
10828c2ecf20Sopenharmony_ci	struct ahd_platform_data *platform_data;
10838c2ecf20Sopenharmony_ci
10848c2ecf20Sopenharmony_ci	/*
10858c2ecf20Sopenharmony_ci	 * Platform specific device information.
10868c2ecf20Sopenharmony_ci	 */
10878c2ecf20Sopenharmony_ci	ahd_dev_softc_t		  dev_softc;
10888c2ecf20Sopenharmony_ci
10898c2ecf20Sopenharmony_ci	/*
10908c2ecf20Sopenharmony_ci	 * Bus specific device information.
10918c2ecf20Sopenharmony_ci	 */
10928c2ecf20Sopenharmony_ci	ahd_bus_intr_t		  bus_intr;
10938c2ecf20Sopenharmony_ci
10948c2ecf20Sopenharmony_ci	/*
10958c2ecf20Sopenharmony_ci	 * Target mode related state kept on a per enabled lun basis.
10968c2ecf20Sopenharmony_ci	 * Targets that are not enabled will have null entries.
10978c2ecf20Sopenharmony_ci	 * As an initiator, we keep one target entry for our initiator
10988c2ecf20Sopenharmony_ci	 * ID to store our sync/wide transfer settings.
10998c2ecf20Sopenharmony_ci	 */
11008c2ecf20Sopenharmony_ci	struct ahd_tmode_tstate  *enabled_targets[AHD_NUM_TARGETS];
11018c2ecf20Sopenharmony_ci
11028c2ecf20Sopenharmony_ci	/*
11038c2ecf20Sopenharmony_ci	 * The black hole device responsible for handling requests for
11048c2ecf20Sopenharmony_ci	 * disabled luns on enabled targets.
11058c2ecf20Sopenharmony_ci	 */
11068c2ecf20Sopenharmony_ci	struct ahd_tmode_lstate  *black_hole;
11078c2ecf20Sopenharmony_ci
11088c2ecf20Sopenharmony_ci	/*
11098c2ecf20Sopenharmony_ci	 * Device instance currently on the bus awaiting a continue TIO
11108c2ecf20Sopenharmony_ci	 * for a command that was not given the disconnect priveledge.
11118c2ecf20Sopenharmony_ci	 */
11128c2ecf20Sopenharmony_ci	struct ahd_tmode_lstate  *pending_device;
11138c2ecf20Sopenharmony_ci
11148c2ecf20Sopenharmony_ci	/*
11158c2ecf20Sopenharmony_ci	 * Timer handles for timer driven callbacks.
11168c2ecf20Sopenharmony_ci	 */
11178c2ecf20Sopenharmony_ci	struct timer_list	stat_timer;
11188c2ecf20Sopenharmony_ci
11198c2ecf20Sopenharmony_ci	/*
11208c2ecf20Sopenharmony_ci	 * Statistics.
11218c2ecf20Sopenharmony_ci	 */
11228c2ecf20Sopenharmony_ci#define	AHD_STAT_UPDATE_US	250000 /* 250ms */
11238c2ecf20Sopenharmony_ci#define	AHD_STAT_BUCKETS	4
11248c2ecf20Sopenharmony_ci	u_int			  cmdcmplt_bucket;
11258c2ecf20Sopenharmony_ci	uint32_t		  cmdcmplt_counts[AHD_STAT_BUCKETS];
11268c2ecf20Sopenharmony_ci	uint32_t		  cmdcmplt_total;
11278c2ecf20Sopenharmony_ci
11288c2ecf20Sopenharmony_ci	/*
11298c2ecf20Sopenharmony_ci	 * Card characteristics
11308c2ecf20Sopenharmony_ci	 */
11318c2ecf20Sopenharmony_ci	ahd_chip		  chip;
11328c2ecf20Sopenharmony_ci	ahd_feature		  features;
11338c2ecf20Sopenharmony_ci	ahd_bug			  bugs;
11348c2ecf20Sopenharmony_ci	ahd_flag		  flags;
11358c2ecf20Sopenharmony_ci	struct seeprom_config	 *seep_config;
11368c2ecf20Sopenharmony_ci
11378c2ecf20Sopenharmony_ci	/* Command Queues */
11388c2ecf20Sopenharmony_ci	struct ahd_completion	  *qoutfifo;
11398c2ecf20Sopenharmony_ci	uint16_t		  qoutfifonext;
11408c2ecf20Sopenharmony_ci	uint16_t		  qoutfifonext_valid_tag;
11418c2ecf20Sopenharmony_ci	uint16_t		  qinfifonext;
11428c2ecf20Sopenharmony_ci	uint16_t		  qinfifo[AHD_SCB_MAX];
11438c2ecf20Sopenharmony_ci
11448c2ecf20Sopenharmony_ci	/*
11458c2ecf20Sopenharmony_ci	 * Our qfreeze count.  The sequencer compares
11468c2ecf20Sopenharmony_ci	 * this value with its own counter to determine
11478c2ecf20Sopenharmony_ci	 * whether to allow selections to occur.
11488c2ecf20Sopenharmony_ci	 */
11498c2ecf20Sopenharmony_ci	uint16_t		  qfreeze_cnt;
11508c2ecf20Sopenharmony_ci
11518c2ecf20Sopenharmony_ci	/* Values to store in the SEQCTL register for pause and unpause */
11528c2ecf20Sopenharmony_ci	uint8_t			  unpause;
11538c2ecf20Sopenharmony_ci	uint8_t			  pause;
11548c2ecf20Sopenharmony_ci
11558c2ecf20Sopenharmony_ci	/* Critical Section Data */
11568c2ecf20Sopenharmony_ci	struct cs		 *critical_sections;
11578c2ecf20Sopenharmony_ci	u_int			  num_critical_sections;
11588c2ecf20Sopenharmony_ci
11598c2ecf20Sopenharmony_ci	/* Buffer for handling packetized bitbucket. */
11608c2ecf20Sopenharmony_ci	uint8_t			 *overrun_buf;
11618c2ecf20Sopenharmony_ci
11628c2ecf20Sopenharmony_ci	/* Links for chaining softcs */
11638c2ecf20Sopenharmony_ci	TAILQ_ENTRY(ahd_softc)	  links;
11648c2ecf20Sopenharmony_ci
11658c2ecf20Sopenharmony_ci	/* Channel Names ('A', 'B', etc.) */
11668c2ecf20Sopenharmony_ci	char			  channel;
11678c2ecf20Sopenharmony_ci
11688c2ecf20Sopenharmony_ci	/* Initiator Bus ID */
11698c2ecf20Sopenharmony_ci	uint8_t			  our_id;
11708c2ecf20Sopenharmony_ci
11718c2ecf20Sopenharmony_ci	/*
11728c2ecf20Sopenharmony_ci	 * Target incoming command FIFO.
11738c2ecf20Sopenharmony_ci	 */
11748c2ecf20Sopenharmony_ci	struct target_cmd	 *targetcmds;
11758c2ecf20Sopenharmony_ci	uint8_t			  tqinfifonext;
11768c2ecf20Sopenharmony_ci
11778c2ecf20Sopenharmony_ci	/*
11788c2ecf20Sopenharmony_ci	 * Cached verson of the hs_mailbox so we can avoid
11798c2ecf20Sopenharmony_ci	 * pausing the sequencer during mailbox updates.
11808c2ecf20Sopenharmony_ci	 */
11818c2ecf20Sopenharmony_ci	uint8_t			  hs_mailbox;
11828c2ecf20Sopenharmony_ci
11838c2ecf20Sopenharmony_ci	/*
11848c2ecf20Sopenharmony_ci	 * Incoming and outgoing message handling.
11858c2ecf20Sopenharmony_ci	 */
11868c2ecf20Sopenharmony_ci	uint8_t			  send_msg_perror;
11878c2ecf20Sopenharmony_ci	ahd_msg_flags		  msg_flags;
11888c2ecf20Sopenharmony_ci	ahd_msg_type		  msg_type;
11898c2ecf20Sopenharmony_ci	uint8_t			  msgout_buf[12];/* Message we are sending */
11908c2ecf20Sopenharmony_ci	uint8_t			  msgin_buf[12];/* Message we are receiving */
11918c2ecf20Sopenharmony_ci	u_int			  msgout_len;	/* Length of message to send */
11928c2ecf20Sopenharmony_ci	u_int			  msgout_index;	/* Current index in msgout */
11938c2ecf20Sopenharmony_ci	u_int			  msgin_index;	/* Current index in msgin */
11948c2ecf20Sopenharmony_ci
11958c2ecf20Sopenharmony_ci	/*
11968c2ecf20Sopenharmony_ci	 * Mapping information for data structures shared
11978c2ecf20Sopenharmony_ci	 * between the sequencer and kernel.
11988c2ecf20Sopenharmony_ci	 */
11998c2ecf20Sopenharmony_ci	bus_dma_tag_t		  parent_dmat;
12008c2ecf20Sopenharmony_ci	bus_dma_tag_t		  shared_data_dmat;
12018c2ecf20Sopenharmony_ci	struct map_node		  shared_data_map;
12028c2ecf20Sopenharmony_ci
12038c2ecf20Sopenharmony_ci	/* Information saved through suspend/resume cycles */
12048c2ecf20Sopenharmony_ci	struct ahd_suspend_state  suspend_state;
12058c2ecf20Sopenharmony_ci
12068c2ecf20Sopenharmony_ci	/* Number of enabled target mode device on this card */
12078c2ecf20Sopenharmony_ci	u_int			  enabled_luns;
12088c2ecf20Sopenharmony_ci
12098c2ecf20Sopenharmony_ci	/* Initialization level of this data structure */
12108c2ecf20Sopenharmony_ci	u_int			  init_level;
12118c2ecf20Sopenharmony_ci
12128c2ecf20Sopenharmony_ci	/* PCI cacheline size. */
12138c2ecf20Sopenharmony_ci	u_int			  pci_cachesize;
12148c2ecf20Sopenharmony_ci
12158c2ecf20Sopenharmony_ci	/* IO Cell Parameters */
12168c2ecf20Sopenharmony_ci	uint8_t			  iocell_opts[AHD_NUM_PER_DEV_ANNEXCOLS];
12178c2ecf20Sopenharmony_ci
12188c2ecf20Sopenharmony_ci	u_int			  stack_size;
12198c2ecf20Sopenharmony_ci	uint16_t		 *saved_stack;
12208c2ecf20Sopenharmony_ci
12218c2ecf20Sopenharmony_ci	/* Per-Unit descriptive information */
12228c2ecf20Sopenharmony_ci	const char		 *description;
12238c2ecf20Sopenharmony_ci	const char		 *bus_description;
12248c2ecf20Sopenharmony_ci	char			 *name;
12258c2ecf20Sopenharmony_ci	int			  unit;
12268c2ecf20Sopenharmony_ci
12278c2ecf20Sopenharmony_ci	/* Selection Timer settings */
12288c2ecf20Sopenharmony_ci	int			  seltime;
12298c2ecf20Sopenharmony_ci
12308c2ecf20Sopenharmony_ci	/*
12318c2ecf20Sopenharmony_ci	 * Interrupt coalescing settings.
12328c2ecf20Sopenharmony_ci	 */
12338c2ecf20Sopenharmony_ci#define	AHD_INT_COALESCING_TIMER_DEFAULT		250 /*us*/
12348c2ecf20Sopenharmony_ci#define	AHD_INT_COALESCING_MAXCMDS_DEFAULT		10
12358c2ecf20Sopenharmony_ci#define	AHD_INT_COALESCING_MAXCMDS_MAX			127
12368c2ecf20Sopenharmony_ci#define	AHD_INT_COALESCING_MINCMDS_DEFAULT		5
12378c2ecf20Sopenharmony_ci#define	AHD_INT_COALESCING_MINCMDS_MAX			127
12388c2ecf20Sopenharmony_ci#define	AHD_INT_COALESCING_THRESHOLD_DEFAULT		2000
12398c2ecf20Sopenharmony_ci#define	AHD_INT_COALESCING_STOP_THRESHOLD_DEFAULT	1000
12408c2ecf20Sopenharmony_ci	u_int			  int_coalescing_timer;
12418c2ecf20Sopenharmony_ci	u_int			  int_coalescing_maxcmds;
12428c2ecf20Sopenharmony_ci	u_int			  int_coalescing_mincmds;
12438c2ecf20Sopenharmony_ci	u_int			  int_coalescing_threshold;
12448c2ecf20Sopenharmony_ci	u_int			  int_coalescing_stop_threshold;
12458c2ecf20Sopenharmony_ci
12468c2ecf20Sopenharmony_ci	uint16_t	 	  user_discenable;/* Disconnection allowed  */
12478c2ecf20Sopenharmony_ci	uint16_t		  user_tagenable;/* Tagged Queuing allowed */
12488c2ecf20Sopenharmony_ci};
12498c2ecf20Sopenharmony_ci
12508c2ecf20Sopenharmony_ci/*************************** IO Cell Configuration ****************************/
12518c2ecf20Sopenharmony_ci#define	AHD_PRECOMP_SLEW_INDEX						\
12528c2ecf20Sopenharmony_ci    (AHD_ANNEXCOL_PRECOMP_SLEW - AHD_ANNEXCOL_PER_DEV0)
12538c2ecf20Sopenharmony_ci
12548c2ecf20Sopenharmony_ci#define	AHD_AMPLITUDE_INDEX						\
12558c2ecf20Sopenharmony_ci    (AHD_ANNEXCOL_AMPLITUDE - AHD_ANNEXCOL_PER_DEV0)
12568c2ecf20Sopenharmony_ci
12578c2ecf20Sopenharmony_ci#define AHD_SET_SLEWRATE(ahd, new_slew)					\
12588c2ecf20Sopenharmony_cido {									\
12598c2ecf20Sopenharmony_ci    (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_SLEWRATE_MASK;	\
12608c2ecf20Sopenharmony_ci    (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] |=			\
12618c2ecf20Sopenharmony_ci	(((new_slew) << AHD_SLEWRATE_SHIFT) & AHD_SLEWRATE_MASK);	\
12628c2ecf20Sopenharmony_ci} while (0)
12638c2ecf20Sopenharmony_ci
12648c2ecf20Sopenharmony_ci#define AHD_SET_PRECOMP(ahd, new_pcomp)					\
12658c2ecf20Sopenharmony_cido {									\
12668c2ecf20Sopenharmony_ci    (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_PRECOMP_MASK;	\
12678c2ecf20Sopenharmony_ci    (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] |=			\
12688c2ecf20Sopenharmony_ci	(((new_pcomp) << AHD_PRECOMP_SHIFT) & AHD_PRECOMP_MASK);	\
12698c2ecf20Sopenharmony_ci} while (0)
12708c2ecf20Sopenharmony_ci
12718c2ecf20Sopenharmony_ci#define AHD_SET_AMPLITUDE(ahd, new_amp)					\
12728c2ecf20Sopenharmony_cido {									\
12738c2ecf20Sopenharmony_ci    (ahd)->iocell_opts[AHD_AMPLITUDE_INDEX] &= ~AHD_AMPLITUDE_MASK;	\
12748c2ecf20Sopenharmony_ci    (ahd)->iocell_opts[AHD_AMPLITUDE_INDEX] |=				\
12758c2ecf20Sopenharmony_ci	(((new_amp) << AHD_AMPLITUDE_SHIFT) & AHD_AMPLITUDE_MASK);	\
12768c2ecf20Sopenharmony_ci} while (0)
12778c2ecf20Sopenharmony_ci
12788c2ecf20Sopenharmony_ci/************************ Active Device Information ***************************/
12798c2ecf20Sopenharmony_citypedef enum {
12808c2ecf20Sopenharmony_ci	ROLE_UNKNOWN,
12818c2ecf20Sopenharmony_ci	ROLE_INITIATOR,
12828c2ecf20Sopenharmony_ci	ROLE_TARGET
12838c2ecf20Sopenharmony_ci} role_t;
12848c2ecf20Sopenharmony_ci
12858c2ecf20Sopenharmony_cistruct ahd_devinfo {
12868c2ecf20Sopenharmony_ci	int	 our_scsiid;
12878c2ecf20Sopenharmony_ci	int	 target_offset;
12888c2ecf20Sopenharmony_ci	uint16_t target_mask;
12898c2ecf20Sopenharmony_ci	u_int	 target;
12908c2ecf20Sopenharmony_ci	u_int	 lun;
12918c2ecf20Sopenharmony_ci	char	 channel;
12928c2ecf20Sopenharmony_ci	role_t	 role;		/*
12938c2ecf20Sopenharmony_ci				 * Only guaranteed to be correct if not
12948c2ecf20Sopenharmony_ci				 * in the busfree state.
12958c2ecf20Sopenharmony_ci				 */
12968c2ecf20Sopenharmony_ci};
12978c2ecf20Sopenharmony_ci
12988c2ecf20Sopenharmony_ci/****************************** PCI Structures ********************************/
12998c2ecf20Sopenharmony_ci#define AHD_PCI_IOADDR0	PCIR_BAR(0)	/* I/O BAR*/
13008c2ecf20Sopenharmony_ci#define AHD_PCI_MEMADDR	PCIR_BAR(1)	/* Memory BAR */
13018c2ecf20Sopenharmony_ci#define AHD_PCI_IOADDR1	PCIR_BAR(3)	/* Second I/O BAR */
13028c2ecf20Sopenharmony_ci
13038c2ecf20Sopenharmony_citypedef int (ahd_device_setup_t)(struct ahd_softc *);
13048c2ecf20Sopenharmony_ci
13058c2ecf20Sopenharmony_cistruct ahd_pci_identity {
13068c2ecf20Sopenharmony_ci	uint64_t		 full_id;
13078c2ecf20Sopenharmony_ci	uint64_t		 id_mask;
13088c2ecf20Sopenharmony_ci	const char		*name;
13098c2ecf20Sopenharmony_ci	ahd_device_setup_t	*setup;
13108c2ecf20Sopenharmony_ci};
13118c2ecf20Sopenharmony_ci
13128c2ecf20Sopenharmony_ci/***************************** VL/EISA Declarations ***************************/
13138c2ecf20Sopenharmony_cistruct aic7770_identity {
13148c2ecf20Sopenharmony_ci	uint32_t		 full_id;
13158c2ecf20Sopenharmony_ci	uint32_t		 id_mask;
13168c2ecf20Sopenharmony_ci	const char		*name;
13178c2ecf20Sopenharmony_ci	ahd_device_setup_t	*setup;
13188c2ecf20Sopenharmony_ci};
13198c2ecf20Sopenharmony_ciextern struct aic7770_identity aic7770_ident_table [];
13208c2ecf20Sopenharmony_ciextern const int ahd_num_aic7770_devs;
13218c2ecf20Sopenharmony_ci
13228c2ecf20Sopenharmony_ci#define AHD_EISA_SLOT_OFFSET	0xc00
13238c2ecf20Sopenharmony_ci#define AHD_EISA_IOSIZE		0x100
13248c2ecf20Sopenharmony_ci
13258c2ecf20Sopenharmony_ci/*************************** Function Declarations ****************************/
13268c2ecf20Sopenharmony_ci/******************************************************************************/
13278c2ecf20Sopenharmony_ci
13288c2ecf20Sopenharmony_ci/***************************** PCI Front End *********************************/
13298c2ecf20Sopenharmony_ciconst struct	ahd_pci_identity *ahd_find_pci_device(ahd_dev_softc_t);
13308c2ecf20Sopenharmony_ciint			  ahd_pci_config(struct ahd_softc *,
13318c2ecf20Sopenharmony_ci					 const struct ahd_pci_identity *);
13328c2ecf20Sopenharmony_ciint	ahd_pci_test_register_access(struct ahd_softc *);
13338c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
13348c2ecf20Sopenharmony_civoid	ahd_pci_suspend(struct ahd_softc *);
13358c2ecf20Sopenharmony_civoid	ahd_pci_resume(struct ahd_softc *);
13368c2ecf20Sopenharmony_ci#endif
13378c2ecf20Sopenharmony_ci
13388c2ecf20Sopenharmony_ci/************************** SCB and SCB queue management **********************/
13398c2ecf20Sopenharmony_civoid		ahd_qinfifo_requeue_tail(struct ahd_softc *ahd,
13408c2ecf20Sopenharmony_ci					 struct scb *scb);
13418c2ecf20Sopenharmony_ci
13428c2ecf20Sopenharmony_ci/****************************** Initialization ********************************/
13438c2ecf20Sopenharmony_cistruct ahd_softc	*ahd_alloc(void *platform_arg, char *name);
13448c2ecf20Sopenharmony_ciint			 ahd_softc_init(struct ahd_softc *);
13458c2ecf20Sopenharmony_civoid			 ahd_controller_info(struct ahd_softc *ahd, char *buf);
13468c2ecf20Sopenharmony_ciint			 ahd_init(struct ahd_softc *ahd);
13478c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
13488c2ecf20Sopenharmony_ciint			 ahd_suspend(struct ahd_softc *ahd);
13498c2ecf20Sopenharmony_civoid			 ahd_resume(struct ahd_softc *ahd);
13508c2ecf20Sopenharmony_ci#endif
13518c2ecf20Sopenharmony_ciint			 ahd_default_config(struct ahd_softc *ahd);
13528c2ecf20Sopenharmony_ciint			 ahd_parse_vpddata(struct ahd_softc *ahd,
13538c2ecf20Sopenharmony_ci					   struct vpd_config *vpd);
13548c2ecf20Sopenharmony_ciint			 ahd_parse_cfgdata(struct ahd_softc *ahd,
13558c2ecf20Sopenharmony_ci					   struct seeprom_config *sc);
13568c2ecf20Sopenharmony_civoid			 ahd_intr_enable(struct ahd_softc *ahd, int enable);
13578c2ecf20Sopenharmony_civoid			 ahd_pause_and_flushwork(struct ahd_softc *ahd);
13588c2ecf20Sopenharmony_civoid			 ahd_set_unit(struct ahd_softc *, int);
13598c2ecf20Sopenharmony_civoid			 ahd_set_name(struct ahd_softc *, char *);
13608c2ecf20Sopenharmony_cistruct scb		*ahd_get_scb(struct ahd_softc *ahd, u_int col_idx);
13618c2ecf20Sopenharmony_civoid			 ahd_free_scb(struct ahd_softc *ahd, struct scb *scb);
13628c2ecf20Sopenharmony_civoid			 ahd_free(struct ahd_softc *ahd);
13638c2ecf20Sopenharmony_ciint			 ahd_reset(struct ahd_softc *ahd, int reinit);
13648c2ecf20Sopenharmony_ciint			 ahd_write_flexport(struct ahd_softc *ahd,
13658c2ecf20Sopenharmony_ci					    u_int addr, u_int value);
13668c2ecf20Sopenharmony_ciint			 ahd_read_flexport(struct ahd_softc *ahd, u_int addr,
13678c2ecf20Sopenharmony_ci					   uint8_t *value);
13688c2ecf20Sopenharmony_ci
13698c2ecf20Sopenharmony_ci/***************************** Error Recovery *********************************/
13708c2ecf20Sopenharmony_citypedef enum {
13718c2ecf20Sopenharmony_ci	SEARCH_COMPLETE,
13728c2ecf20Sopenharmony_ci	SEARCH_COUNT,
13738c2ecf20Sopenharmony_ci	SEARCH_REMOVE,
13748c2ecf20Sopenharmony_ci	SEARCH_PRINT
13758c2ecf20Sopenharmony_ci} ahd_search_action;
13768c2ecf20Sopenharmony_ciint			ahd_search_qinfifo(struct ahd_softc *ahd, int target,
13778c2ecf20Sopenharmony_ci					   char channel, int lun, u_int tag,
13788c2ecf20Sopenharmony_ci					   role_t role, uint32_t status,
13798c2ecf20Sopenharmony_ci					   ahd_search_action action);
13808c2ecf20Sopenharmony_ciint			ahd_search_disc_list(struct ahd_softc *ahd, int target,
13818c2ecf20Sopenharmony_ci					     char channel, int lun, u_int tag,
13828c2ecf20Sopenharmony_ci					     int stop_on_first, int remove,
13838c2ecf20Sopenharmony_ci					     int save_state);
13848c2ecf20Sopenharmony_ciint			ahd_reset_channel(struct ahd_softc *ahd, char channel,
13858c2ecf20Sopenharmony_ci					  int initiate_reset);
13868c2ecf20Sopenharmony_ci/*************************** Utility Functions ********************************/
13878c2ecf20Sopenharmony_civoid			ahd_compile_devinfo(struct ahd_devinfo *devinfo,
13888c2ecf20Sopenharmony_ci					    u_int our_id, u_int target,
13898c2ecf20Sopenharmony_ci					    u_int lun, char channel,
13908c2ecf20Sopenharmony_ci					    role_t role);
13918c2ecf20Sopenharmony_ci/************************** Transfer Negotiation ******************************/
13928c2ecf20Sopenharmony_civoid			ahd_find_syncrate(struct ahd_softc *ahd, u_int *period,
13938c2ecf20Sopenharmony_ci					  u_int *ppr_options, u_int maxsync);
13948c2ecf20Sopenharmony_ci/*
13958c2ecf20Sopenharmony_ci * Negotiation types.  These are used to qualify if we should renegotiate
13968c2ecf20Sopenharmony_ci * even if our goal and current transport parameters are identical.
13978c2ecf20Sopenharmony_ci */
13988c2ecf20Sopenharmony_citypedef enum {
13998c2ecf20Sopenharmony_ci	AHD_NEG_TO_GOAL,	/* Renegotiate only if goal and curr differ. */
14008c2ecf20Sopenharmony_ci	AHD_NEG_IF_NON_ASYNC,	/* Renegotiate so long as goal is non-async. */
14018c2ecf20Sopenharmony_ci	AHD_NEG_ALWAYS		/* Renegotiat even if goal is async. */
14028c2ecf20Sopenharmony_ci} ahd_neg_type;
14038c2ecf20Sopenharmony_ciint			ahd_update_neg_request(struct ahd_softc*,
14048c2ecf20Sopenharmony_ci					       struct ahd_devinfo*,
14058c2ecf20Sopenharmony_ci					       struct ahd_tmode_tstate*,
14068c2ecf20Sopenharmony_ci					       struct ahd_initiator_tinfo*,
14078c2ecf20Sopenharmony_ci					       ahd_neg_type);
14088c2ecf20Sopenharmony_civoid			ahd_set_width(struct ahd_softc *ahd,
14098c2ecf20Sopenharmony_ci				      struct ahd_devinfo *devinfo,
14108c2ecf20Sopenharmony_ci				      u_int width, u_int type, int paused);
14118c2ecf20Sopenharmony_civoid			ahd_set_syncrate(struct ahd_softc *ahd,
14128c2ecf20Sopenharmony_ci					 struct ahd_devinfo *devinfo,
14138c2ecf20Sopenharmony_ci					 u_int period, u_int offset,
14148c2ecf20Sopenharmony_ci					 u_int ppr_options,
14158c2ecf20Sopenharmony_ci					 u_int type, int paused);
14168c2ecf20Sopenharmony_citypedef enum {
14178c2ecf20Sopenharmony_ci	AHD_QUEUE_NONE,
14188c2ecf20Sopenharmony_ci	AHD_QUEUE_BASIC,
14198c2ecf20Sopenharmony_ci	AHD_QUEUE_TAGGED
14208c2ecf20Sopenharmony_ci} ahd_queue_alg;
14218c2ecf20Sopenharmony_ci
14228c2ecf20Sopenharmony_ci/**************************** Target Mode *************************************/
14238c2ecf20Sopenharmony_ci#ifdef AHD_TARGET_MODE
14248c2ecf20Sopenharmony_civoid		ahd_send_lstate_events(struct ahd_softc *,
14258c2ecf20Sopenharmony_ci				       struct ahd_tmode_lstate *);
14268c2ecf20Sopenharmony_civoid		ahd_handle_en_lun(struct ahd_softc *ahd,
14278c2ecf20Sopenharmony_ci				  struct cam_sim *sim, union ccb *ccb);
14288c2ecf20Sopenharmony_cicam_status	ahd_find_tmode_devs(struct ahd_softc *ahd,
14298c2ecf20Sopenharmony_ci				    struct cam_sim *sim, union ccb *ccb,
14308c2ecf20Sopenharmony_ci				    struct ahd_tmode_tstate **tstate,
14318c2ecf20Sopenharmony_ci				    struct ahd_tmode_lstate **lstate,
14328c2ecf20Sopenharmony_ci				    int notfound_failure);
14338c2ecf20Sopenharmony_ci#ifndef AHD_TMODE_ENABLE
14348c2ecf20Sopenharmony_ci#define AHD_TMODE_ENABLE 0
14358c2ecf20Sopenharmony_ci#endif
14368c2ecf20Sopenharmony_ci#endif
14378c2ecf20Sopenharmony_ci/******************************* Debug ***************************************/
14388c2ecf20Sopenharmony_ci#ifdef AHD_DEBUG
14398c2ecf20Sopenharmony_ciextern uint32_t ahd_debug;
14408c2ecf20Sopenharmony_ci#define AHD_SHOW_MISC		0x00001
14418c2ecf20Sopenharmony_ci#define AHD_SHOW_SENSE		0x00002
14428c2ecf20Sopenharmony_ci#define AHD_SHOW_RECOVERY	0x00004
14438c2ecf20Sopenharmony_ci#define AHD_DUMP_SEEPROM	0x00008
14448c2ecf20Sopenharmony_ci#define AHD_SHOW_TERMCTL	0x00010
14458c2ecf20Sopenharmony_ci#define AHD_SHOW_MEMORY		0x00020
14468c2ecf20Sopenharmony_ci#define AHD_SHOW_MESSAGES	0x00040
14478c2ecf20Sopenharmony_ci#define AHD_SHOW_MODEPTR	0x00080
14488c2ecf20Sopenharmony_ci#define AHD_SHOW_SELTO		0x00100
14498c2ecf20Sopenharmony_ci#define AHD_SHOW_FIFOS		0x00200
14508c2ecf20Sopenharmony_ci#define AHD_SHOW_QFULL		0x00400
14518c2ecf20Sopenharmony_ci#define	AHD_SHOW_DV		0x00800
14528c2ecf20Sopenharmony_ci#define AHD_SHOW_MASKED_ERRORS	0x01000
14538c2ecf20Sopenharmony_ci#define AHD_SHOW_QUEUE		0x02000
14548c2ecf20Sopenharmony_ci#define AHD_SHOW_TQIN		0x04000
14558c2ecf20Sopenharmony_ci#define AHD_SHOW_SG		0x08000
14568c2ecf20Sopenharmony_ci#define AHD_SHOW_INT_COALESCING	0x10000
14578c2ecf20Sopenharmony_ci#define AHD_DEBUG_SEQUENCER	0x20000
14588c2ecf20Sopenharmony_ci#endif
14598c2ecf20Sopenharmony_civoid			ahd_print_devinfo(struct ahd_softc *ahd,
14608c2ecf20Sopenharmony_ci					  struct ahd_devinfo *devinfo);
14618c2ecf20Sopenharmony_civoid			ahd_dump_card_state(struct ahd_softc *ahd);
14628c2ecf20Sopenharmony_ciint			ahd_print_register(const ahd_reg_parse_entry_t *table,
14638c2ecf20Sopenharmony_ci					   u_int num_entries,
14648c2ecf20Sopenharmony_ci					   const char *name,
14658c2ecf20Sopenharmony_ci					   u_int address,
14668c2ecf20Sopenharmony_ci					   u_int value,
14678c2ecf20Sopenharmony_ci					   u_int *cur_column,
14688c2ecf20Sopenharmony_ci					   u_int wrap_point);
14698c2ecf20Sopenharmony_ci#endif /* _AIC79XX_H_ */
1470