162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Core definitions and data structures shareable across OS platforms.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (c) 1994-2002 Justin T. Gibbs.
562306a36Sopenharmony_ci * Copyright (c) 2000-2002 Adaptec Inc.
662306a36Sopenharmony_ci * All rights reserved.
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
962306a36Sopenharmony_ci * modification, are permitted provided that the following conditions
1062306a36Sopenharmony_ci * are met:
1162306a36Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
1262306a36Sopenharmony_ci *    notice, this list of conditions, and the following disclaimer,
1362306a36Sopenharmony_ci *    without modification.
1462306a36Sopenharmony_ci * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1562306a36Sopenharmony_ci *    substantially similar to the "NO WARRANTY" disclaimer below
1662306a36Sopenharmony_ci *    ("Disclaimer") and any redistribution must be conditioned upon
1762306a36Sopenharmony_ci *    including a substantially similar Disclaimer requirement for further
1862306a36Sopenharmony_ci *    binary redistribution.
1962306a36Sopenharmony_ci * 3. Neither the names of the above-listed copyright holders nor the names
2062306a36Sopenharmony_ci *    of any contributors may be used to endorse or promote products derived
2162306a36Sopenharmony_ci *    from this software without specific prior written permission.
2262306a36Sopenharmony_ci *
2362306a36Sopenharmony_ci * Alternatively, this software may be distributed under the terms of the
2462306a36Sopenharmony_ci * GNU General Public License ("GPL") version 2 as published by the Free
2562306a36Sopenharmony_ci * Software Foundation.
2662306a36Sopenharmony_ci *
2762306a36Sopenharmony_ci * NO WARRANTY
2862306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2962306a36Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3062306a36Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3162306a36Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3262306a36Sopenharmony_ci * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3362306a36Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3462306a36Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3562306a36Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3662306a36Sopenharmony_ci * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
3762306a36Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3862306a36Sopenharmony_ci * POSSIBILITY OF SUCH DAMAGES.
3962306a36Sopenharmony_ci *
4062306a36Sopenharmony_ci * $Id: //depot/aic7xxx/aic7xxx/aic79xx.h#109 $
4162306a36Sopenharmony_ci *
4262306a36Sopenharmony_ci * $FreeBSD$
4362306a36Sopenharmony_ci */
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci#ifndef _AIC79XX_H_
4662306a36Sopenharmony_ci#define _AIC79XX_H_
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci/* Register Definitions */
4962306a36Sopenharmony_ci#include "aic79xx_reg.h"
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci/************************* Forward Declarations *******************************/
5262306a36Sopenharmony_cistruct ahd_platform_data;
5362306a36Sopenharmony_cistruct scb_platform_data;
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci/****************************** Useful Macros *********************************/
5662306a36Sopenharmony_ci#ifndef TRUE
5762306a36Sopenharmony_ci#define TRUE 1
5862306a36Sopenharmony_ci#endif
5962306a36Sopenharmony_ci#ifndef FALSE
6062306a36Sopenharmony_ci#define FALSE 0
6162306a36Sopenharmony_ci#endif
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci#define ALL_CHANNELS '\0'
6462306a36Sopenharmony_ci#define ALL_TARGETS_MASK 0xFFFF
6562306a36Sopenharmony_ci#define INITIATOR_WILDCARD	(~0)
6662306a36Sopenharmony_ci#define	SCB_LIST_NULL		0xFF00
6762306a36Sopenharmony_ci#define	SCB_LIST_NULL_LE	(ahd_htole16(SCB_LIST_NULL))
6862306a36Sopenharmony_ci#define QOUTFIFO_ENTRY_VALID 0x80
6962306a36Sopenharmony_ci#define SCBID_IS_NULL(scbid) (((scbid) & 0xFF00 ) == SCB_LIST_NULL)
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci#define SCSIID_TARGET(ahd, scsiid)	\
7262306a36Sopenharmony_ci	(((scsiid) & TID) >> TID_SHIFT)
7362306a36Sopenharmony_ci#define SCSIID_OUR_ID(scsiid)		\
7462306a36Sopenharmony_ci	((scsiid) & OID)
7562306a36Sopenharmony_ci#define SCSIID_CHANNEL(ahd, scsiid) ('A')
7662306a36Sopenharmony_ci#define	SCB_IS_SCSIBUS_B(ahd, scb) (0)
7762306a36Sopenharmony_ci#define	SCB_GET_OUR_ID(scb) \
7862306a36Sopenharmony_ci	SCSIID_OUR_ID((scb)->hscb->scsiid)
7962306a36Sopenharmony_ci#define	SCB_GET_TARGET(ahd, scb) \
8062306a36Sopenharmony_ci	SCSIID_TARGET((ahd), (scb)->hscb->scsiid)
8162306a36Sopenharmony_ci#define	SCB_GET_CHANNEL(ahd, scb) \
8262306a36Sopenharmony_ci	SCSIID_CHANNEL(ahd, (scb)->hscb->scsiid)
8362306a36Sopenharmony_ci#define	SCB_GET_LUN(scb) \
8462306a36Sopenharmony_ci	((scb)->hscb->lun)
8562306a36Sopenharmony_ci#define SCB_GET_TARGET_OFFSET(ahd, scb)	\
8662306a36Sopenharmony_ci	SCB_GET_TARGET(ahd, scb)
8762306a36Sopenharmony_ci#define SCB_GET_TARGET_MASK(ahd, scb) \
8862306a36Sopenharmony_ci	(0x01 << (SCB_GET_TARGET_OFFSET(ahd, scb)))
8962306a36Sopenharmony_ci#ifdef AHD_DEBUG
9062306a36Sopenharmony_ci#define SCB_IS_SILENT(scb)					\
9162306a36Sopenharmony_ci	((ahd_debug & AHD_SHOW_MASKED_ERRORS) == 0		\
9262306a36Sopenharmony_ci      && (((scb)->flags & SCB_SILENT) != 0))
9362306a36Sopenharmony_ci#else
9462306a36Sopenharmony_ci#define SCB_IS_SILENT(scb)					\
9562306a36Sopenharmony_ci	(((scb)->flags & SCB_SILENT) != 0)
9662306a36Sopenharmony_ci#endif
9762306a36Sopenharmony_ci/*
9862306a36Sopenharmony_ci * TCLs have the following format: TTTTLLLLLLLL
9962306a36Sopenharmony_ci */
10062306a36Sopenharmony_ci#define TCL_TARGET_OFFSET(tcl) \
10162306a36Sopenharmony_ci	((((tcl) >> 4) & TID) >> 4)
10262306a36Sopenharmony_ci#define TCL_LUN(tcl) \
10362306a36Sopenharmony_ci	(tcl & (AHD_NUM_LUNS - 1))
10462306a36Sopenharmony_ci#define BUILD_TCL(scsiid, lun) \
10562306a36Sopenharmony_ci	((lun) | (((scsiid) & TID) << 4))
10662306a36Sopenharmony_ci#define BUILD_TCL_RAW(target, channel, lun) \
10762306a36Sopenharmony_ci	((lun) | ((target) << 8))
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ci#define SCB_GET_TAG(scb) \
11062306a36Sopenharmony_ci	ahd_le16toh(scb->hscb->tag)
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ci#ifndef	AHD_TARGET_MODE
11362306a36Sopenharmony_ci#undef	AHD_TMODE_ENABLE
11462306a36Sopenharmony_ci#define	AHD_TMODE_ENABLE 0
11562306a36Sopenharmony_ci#endif
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci#define AHD_BUILD_COL_IDX(target, lun)				\
11862306a36Sopenharmony_ci	((((u8)lun) << 4) | target)
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci#define AHD_GET_SCB_COL_IDX(ahd, scb)				\
12162306a36Sopenharmony_ci	((SCB_GET_LUN(scb) << 4) | SCB_GET_TARGET(ahd, scb))
12262306a36Sopenharmony_ci
12362306a36Sopenharmony_ci#define AHD_SET_SCB_COL_IDX(scb, col_idx)				\
12462306a36Sopenharmony_cido {									\
12562306a36Sopenharmony_ci	(scb)->hscb->scsiid = ((col_idx) << TID_SHIFT) & TID;		\
12662306a36Sopenharmony_ci	(scb)->hscb->lun = ((col_idx) >> 4) & (AHD_NUM_LUNS_NONPKT-1);	\
12762306a36Sopenharmony_ci} while (0)
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci#define AHD_COPY_SCB_COL_IDX(dst, src)				\
13062306a36Sopenharmony_cido {								\
13162306a36Sopenharmony_ci	dst->hscb->scsiid = src->hscb->scsiid;			\
13262306a36Sopenharmony_ci	dst->hscb->lun = src->hscb->lun;			\
13362306a36Sopenharmony_ci} while (0)
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_ci#define	AHD_NEVER_COL_IDX 0xFFFF
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci/**************************** Driver Constants ********************************/
13862306a36Sopenharmony_ci/*
13962306a36Sopenharmony_ci * The maximum number of supported targets.
14062306a36Sopenharmony_ci */
14162306a36Sopenharmony_ci#define AHD_NUM_TARGETS 16
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci/*
14462306a36Sopenharmony_ci * The maximum number of supported luns.
14562306a36Sopenharmony_ci * The identify message only supports 64 luns in non-packetized transfers.
14662306a36Sopenharmony_ci * You can have 2^64 luns when information unit transfers are enabled,
14762306a36Sopenharmony_ci * but until we see a need to support that many, we support 256.
14862306a36Sopenharmony_ci */
14962306a36Sopenharmony_ci#define AHD_NUM_LUNS_NONPKT 64
15062306a36Sopenharmony_ci#define AHD_NUM_LUNS 256
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ci/*
15362306a36Sopenharmony_ci * The maximum transfer per S/G segment.
15462306a36Sopenharmony_ci */
15562306a36Sopenharmony_ci#define AHD_MAXTRANSFER_SIZE	 0x00ffffff	/* limited by 24bit counter */
15662306a36Sopenharmony_ci
15762306a36Sopenharmony_ci/*
15862306a36Sopenharmony_ci * The maximum amount of SCB storage in hardware on a controller.
15962306a36Sopenharmony_ci * This value represents an upper bound.  Due to software design,
16062306a36Sopenharmony_ci * we may not be able to use this number.
16162306a36Sopenharmony_ci */
16262306a36Sopenharmony_ci#define AHD_SCB_MAX	512
16362306a36Sopenharmony_ci
16462306a36Sopenharmony_ci/*
16562306a36Sopenharmony_ci * The maximum number of concurrent transactions supported per driver instance.
16662306a36Sopenharmony_ci * Sequencer Control Blocks (SCBs) store per-transaction information.
16762306a36Sopenharmony_ci */
16862306a36Sopenharmony_ci#define AHD_MAX_QUEUE	AHD_SCB_MAX
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ci/*
17162306a36Sopenharmony_ci * Define the size of our QIN and QOUT FIFOs.  They must be a power of 2
17262306a36Sopenharmony_ci * in size and accommodate as many transactions as can be queued concurrently.
17362306a36Sopenharmony_ci */
17462306a36Sopenharmony_ci#define	AHD_QIN_SIZE	AHD_MAX_QUEUE
17562306a36Sopenharmony_ci#define	AHD_QOUT_SIZE	AHD_MAX_QUEUE
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci#define AHD_QIN_WRAP(x) ((x) & (AHD_QIN_SIZE-1))
17862306a36Sopenharmony_ci/*
17962306a36Sopenharmony_ci * The maximum amount of SCB storage we allocate in host memory.
18062306a36Sopenharmony_ci */
18162306a36Sopenharmony_ci#define AHD_SCB_MAX_ALLOC AHD_MAX_QUEUE
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_ci/*
18462306a36Sopenharmony_ci * Ring Buffer of incoming target commands.
18562306a36Sopenharmony_ci * We allocate 256 to simplify the logic in the sequencer
18662306a36Sopenharmony_ci * by using the natural wrap point of an 8bit counter.
18762306a36Sopenharmony_ci */
18862306a36Sopenharmony_ci#define AHD_TMODE_CMDS	256
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci/* Reset line assertion time in us */
19162306a36Sopenharmony_ci#define AHD_BUSRESET_DELAY	25
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ci/******************* Chip Characteristics/Operating Settings  *****************/
19462306a36Sopenharmony_ci/*
19562306a36Sopenharmony_ci * Chip Type
19662306a36Sopenharmony_ci * The chip order is from least sophisticated to most sophisticated.
19762306a36Sopenharmony_ci */
19862306a36Sopenharmony_citypedef enum {
19962306a36Sopenharmony_ci	AHD_NONE	= 0x0000,
20062306a36Sopenharmony_ci	AHD_CHIPID_MASK	= 0x00FF,
20162306a36Sopenharmony_ci	AHD_AIC7901	= 0x0001,
20262306a36Sopenharmony_ci	AHD_AIC7902	= 0x0002,
20362306a36Sopenharmony_ci	AHD_AIC7901A	= 0x0003,
20462306a36Sopenharmony_ci	AHD_PCI		= 0x0100,	/* Bus type PCI */
20562306a36Sopenharmony_ci	AHD_PCIX	= 0x0200,	/* Bus type PCIX */
20662306a36Sopenharmony_ci	AHD_BUS_MASK	= 0x0F00
20762306a36Sopenharmony_ci} ahd_chip;
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_ci/*
21062306a36Sopenharmony_ci * Features available in each chip type.
21162306a36Sopenharmony_ci */
21262306a36Sopenharmony_citypedef enum {
21362306a36Sopenharmony_ci	AHD_FENONE		= 0x00000,
21462306a36Sopenharmony_ci	AHD_WIDE		= 0x00001,/* Wide Channel */
21562306a36Sopenharmony_ci	AHD_AIC79XXB_SLOWCRC    = 0x00002,/* SLOWCRC bit should be set */
21662306a36Sopenharmony_ci	AHD_MULTI_FUNC		= 0x00100,/* Multi-Function/Channel Device */
21762306a36Sopenharmony_ci	AHD_TARGETMODE		= 0x01000,/* Has tested target mode support */
21862306a36Sopenharmony_ci	AHD_MULTIROLE		= 0x02000,/* Space for two roles at a time */
21962306a36Sopenharmony_ci	AHD_RTI			= 0x04000,/* Retained Training Support */
22062306a36Sopenharmony_ci	AHD_NEW_IOCELL_OPTS	= 0x08000,/* More Signal knobs in the IOCELL */
22162306a36Sopenharmony_ci	AHD_NEW_DFCNTRL_OPTS	= 0x10000,/* SCSIENWRDIS bit */
22262306a36Sopenharmony_ci	AHD_FAST_CDB_DELIVERY	= 0x20000,/* CDB acks released to Output Sync */
22362306a36Sopenharmony_ci	AHD_REMOVABLE		= 0x00000,/* Hot-Swap supported - None so far*/
22462306a36Sopenharmony_ci	AHD_AIC7901_FE		= AHD_FENONE,
22562306a36Sopenharmony_ci	AHD_AIC7901A_FE		= AHD_FENONE,
22662306a36Sopenharmony_ci	AHD_AIC7902_FE		= AHD_MULTI_FUNC
22762306a36Sopenharmony_ci} ahd_feature;
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci/*
23062306a36Sopenharmony_ci * Bugs in the silicon that we work around in software.
23162306a36Sopenharmony_ci */
23262306a36Sopenharmony_citypedef enum {
23362306a36Sopenharmony_ci	AHD_BUGNONE		= 0x0000,
23462306a36Sopenharmony_ci	/*
23562306a36Sopenharmony_ci	 * Rev A hardware fails to update LAST/CURR/NEXTSCB
23662306a36Sopenharmony_ci	 * correctly in certain packetized selection cases.
23762306a36Sopenharmony_ci	 */
23862306a36Sopenharmony_ci	AHD_SENT_SCB_UPDATE_BUG	= 0x0001,
23962306a36Sopenharmony_ci	/* The wrong SCB is accessed to check the abort pending bit. */
24062306a36Sopenharmony_ci	AHD_ABORT_LQI_BUG	= 0x0002,
24162306a36Sopenharmony_ci	/* Packetized bitbucket crosses packet boundaries. */
24262306a36Sopenharmony_ci	AHD_PKT_BITBUCKET_BUG	= 0x0004,
24362306a36Sopenharmony_ci	/* The selection timer runs twice as long as its setting. */
24462306a36Sopenharmony_ci	AHD_LONG_SETIMO_BUG	= 0x0008,
24562306a36Sopenharmony_ci	/* The Non-LQ CRC error status is delayed until phase change. */
24662306a36Sopenharmony_ci	AHD_NLQICRC_DELAYED_BUG	= 0x0010,
24762306a36Sopenharmony_ci	/* The chip must be reset for all outgoing bus resets.  */
24862306a36Sopenharmony_ci	AHD_SCSIRST_BUG		= 0x0020,
24962306a36Sopenharmony_ci	/* Some PCIX fields must be saved and restored across chip reset. */
25062306a36Sopenharmony_ci	AHD_PCIX_CHIPRST_BUG	= 0x0040,
25162306a36Sopenharmony_ci	/* MMAPIO is not functional in PCI-X mode.  */
25262306a36Sopenharmony_ci	AHD_PCIX_MMAPIO_BUG	= 0x0080,
25362306a36Sopenharmony_ci	/* Reads to SCBRAM fail to reset the discard timer. */
25462306a36Sopenharmony_ci	AHD_PCIX_SCBRAM_RD_BUG  = 0x0100,
25562306a36Sopenharmony_ci	/* Bug workarounds that can be disabled on non-PCIX busses. */
25662306a36Sopenharmony_ci	AHD_PCIX_BUG_MASK	= AHD_PCIX_CHIPRST_BUG
25762306a36Sopenharmony_ci				| AHD_PCIX_MMAPIO_BUG
25862306a36Sopenharmony_ci				| AHD_PCIX_SCBRAM_RD_BUG,
25962306a36Sopenharmony_ci	/*
26062306a36Sopenharmony_ci	 * LQOSTOP0 status set even for forced selections with ATN
26162306a36Sopenharmony_ci	 * to perform non-packetized message delivery.
26262306a36Sopenharmony_ci	 */
26362306a36Sopenharmony_ci	AHD_LQO_ATNO_BUG	= 0x0200,
26462306a36Sopenharmony_ci	/* FIFO auto-flush does not always trigger.  */
26562306a36Sopenharmony_ci	AHD_AUTOFLUSH_BUG	= 0x0400,
26662306a36Sopenharmony_ci	/* The CLRLQO registers are not self-clearing. */
26762306a36Sopenharmony_ci	AHD_CLRLQO_AUTOCLR_BUG	= 0x0800,
26862306a36Sopenharmony_ci	/* The PACKETIZED status bit refers to the previous connection. */
26962306a36Sopenharmony_ci	AHD_PKTIZED_STATUS_BUG  = 0x1000,
27062306a36Sopenharmony_ci	/* "Short Luns" are not placed into outgoing LQ packets correctly. */
27162306a36Sopenharmony_ci	AHD_PKT_LUN_BUG		= 0x2000,
27262306a36Sopenharmony_ci	/*
27362306a36Sopenharmony_ci	 * Only the FIFO allocated to the non-packetized connection may
27462306a36Sopenharmony_ci	 * be in use during a non-packetzied connection.
27562306a36Sopenharmony_ci	 */
27662306a36Sopenharmony_ci	AHD_NONPACKFIFO_BUG	= 0x4000,
27762306a36Sopenharmony_ci	/*
27862306a36Sopenharmony_ci	 * Writing to a DFF SCBPTR register may fail if concurent with
27962306a36Sopenharmony_ci	 * a hardware write to the other DFF SCBPTR register.  This is
28062306a36Sopenharmony_ci	 * not currently a concern in our sequencer since all chips with
28162306a36Sopenharmony_ci	 * this bug have the AHD_NONPACKFIFO_BUG and all writes of concern
28262306a36Sopenharmony_ci	 * occur in non-packetized connections.
28362306a36Sopenharmony_ci	 */
28462306a36Sopenharmony_ci	AHD_MDFF_WSCBPTR_BUG	= 0x8000,
28562306a36Sopenharmony_ci	/* SGHADDR updates are slow. */
28662306a36Sopenharmony_ci	AHD_REG_SLOW_SETTLE_BUG	= 0x10000,
28762306a36Sopenharmony_ci	/*
28862306a36Sopenharmony_ci	 * Changing the MODE_PTR coincident with an interrupt that
28962306a36Sopenharmony_ci	 * switches to a different mode will cause the interrupt to
29062306a36Sopenharmony_ci	 * be in the mode written outside of interrupt context.
29162306a36Sopenharmony_ci	 */
29262306a36Sopenharmony_ci	AHD_SET_MODE_BUG	= 0x20000,
29362306a36Sopenharmony_ci	/* Non-packetized busfree revision does not work. */
29462306a36Sopenharmony_ci	AHD_BUSFREEREV_BUG	= 0x40000,
29562306a36Sopenharmony_ci	/*
29662306a36Sopenharmony_ci	 * Paced transfers are indicated with a non-standard PPR
29762306a36Sopenharmony_ci	 * option bit in the neg table, 160MHz is indicated by
29862306a36Sopenharmony_ci	 * sync factor 0x7, and the offset if off by a factor of 2.
29962306a36Sopenharmony_ci	 */
30062306a36Sopenharmony_ci	AHD_PACED_NEGTABLE_BUG	= 0x80000,
30162306a36Sopenharmony_ci	/* LQOOVERRUN false positives. */
30262306a36Sopenharmony_ci	AHD_LQOOVERRUN_BUG	= 0x100000,
30362306a36Sopenharmony_ci	/*
30462306a36Sopenharmony_ci	 * Controller write to INTSTAT will lose to a host
30562306a36Sopenharmony_ci	 * write to CLRINT.
30662306a36Sopenharmony_ci	 */
30762306a36Sopenharmony_ci	AHD_INTCOLLISION_BUG	= 0x200000,
30862306a36Sopenharmony_ci	/*
30962306a36Sopenharmony_ci	 * The GEM318 violates the SCSI spec by not waiting
31062306a36Sopenharmony_ci	 * the mandated bus settle delay between phase changes
31162306a36Sopenharmony_ci	 * in some situations.  Some aic79xx chip revs. are more
31262306a36Sopenharmony_ci	 * strict in this regard and will treat REQ assertions
31362306a36Sopenharmony_ci	 * that fall within the bus settle delay window as
31462306a36Sopenharmony_ci	 * glitches.  This flag tells the firmware to tolerate
31562306a36Sopenharmony_ci	 * early REQ assertions.
31662306a36Sopenharmony_ci	 */
31762306a36Sopenharmony_ci	AHD_EARLY_REQ_BUG	= 0x400000,
31862306a36Sopenharmony_ci	/*
31962306a36Sopenharmony_ci	 * The LED does not stay on long enough in packetized modes.
32062306a36Sopenharmony_ci	 */
32162306a36Sopenharmony_ci	AHD_FAINT_LED_BUG	= 0x800000
32262306a36Sopenharmony_ci} ahd_bug;
32362306a36Sopenharmony_ci
32462306a36Sopenharmony_ci/*
32562306a36Sopenharmony_ci * Configuration specific settings.
32662306a36Sopenharmony_ci * The driver determines these settings by probing the
32762306a36Sopenharmony_ci * chip/controller's configuration.
32862306a36Sopenharmony_ci */
32962306a36Sopenharmony_citypedef enum {
33062306a36Sopenharmony_ci	AHD_FNONE	      = 0x00000,
33162306a36Sopenharmony_ci	AHD_BOOT_CHANNEL      = 0x00001,/* We were set as the boot channel. */
33262306a36Sopenharmony_ci	AHD_USEDEFAULTS	      = 0x00004,/*
33362306a36Sopenharmony_ci					 * For cards without an seeprom
33462306a36Sopenharmony_ci					 * or a BIOS to initialize the chip's
33562306a36Sopenharmony_ci					 * SRAM, we use the default target
33662306a36Sopenharmony_ci					 * settings.
33762306a36Sopenharmony_ci					 */
33862306a36Sopenharmony_ci	AHD_SEQUENCER_DEBUG   = 0x00008,
33962306a36Sopenharmony_ci	AHD_RESET_BUS_A	      = 0x00010,
34062306a36Sopenharmony_ci	AHD_EXTENDED_TRANS_A  = 0x00020,
34162306a36Sopenharmony_ci	AHD_TERM_ENB_A	      = 0x00040,
34262306a36Sopenharmony_ci	AHD_SPCHK_ENB_A	      = 0x00080,
34362306a36Sopenharmony_ci	AHD_STPWLEVEL_A	      = 0x00100,
34462306a36Sopenharmony_ci	AHD_INITIATORROLE     = 0x00200,/*
34562306a36Sopenharmony_ci					 * Allow initiator operations on
34662306a36Sopenharmony_ci					 * this controller.
34762306a36Sopenharmony_ci					 */
34862306a36Sopenharmony_ci	AHD_TARGETROLE	      = 0x00400,/*
34962306a36Sopenharmony_ci					 * Allow target operations on this
35062306a36Sopenharmony_ci					 * controller.
35162306a36Sopenharmony_ci					 */
35262306a36Sopenharmony_ci	AHD_RESOURCE_SHORTAGE = 0x00800,
35362306a36Sopenharmony_ci	AHD_TQINFIFO_BLOCKED  = 0x01000,/* Blocked waiting for ATIOs */
35462306a36Sopenharmony_ci	AHD_INT50_SPEEDFLEX   = 0x02000,/*
35562306a36Sopenharmony_ci					 * Internal 50pin connector
35662306a36Sopenharmony_ci					 * sits behind an aic3860
35762306a36Sopenharmony_ci					 */
35862306a36Sopenharmony_ci	AHD_BIOS_ENABLED      = 0x04000,
35962306a36Sopenharmony_ci	AHD_ALL_INTERRUPTS    = 0x08000,
36062306a36Sopenharmony_ci	AHD_39BIT_ADDRESSING  = 0x10000,/* Use 39 bit addressing scheme. */
36162306a36Sopenharmony_ci	AHD_64BIT_ADDRESSING  = 0x20000,/* Use 64 bit addressing scheme. */
36262306a36Sopenharmony_ci	AHD_CURRENT_SENSING   = 0x40000,
36362306a36Sopenharmony_ci	AHD_SCB_CONFIG_USED   = 0x80000,/* No SEEPROM but SCB had info. */
36462306a36Sopenharmony_ci	AHD_HP_BOARD	      = 0x100000,
36562306a36Sopenharmony_ci	AHD_BUS_RESET_ACTIVE  = 0x200000,
36662306a36Sopenharmony_ci	AHD_UPDATE_PEND_CMDS  = 0x400000,
36762306a36Sopenharmony_ci	AHD_RUNNING_QOUTFIFO  = 0x800000,
36862306a36Sopenharmony_ci	AHD_HAD_FIRST_SEL     = 0x1000000
36962306a36Sopenharmony_ci} ahd_flag;
37062306a36Sopenharmony_ci
37162306a36Sopenharmony_ci/************************* Hardware  SCB Definition ***************************/
37262306a36Sopenharmony_ci
37362306a36Sopenharmony_ci/*
37462306a36Sopenharmony_ci * The driver keeps up to MAX_SCB scb structures per card in memory.  The SCB
37562306a36Sopenharmony_ci * consists of a "hardware SCB" mirroring the fields available on the card
37662306a36Sopenharmony_ci * and additional information the kernel stores for each transaction.
37762306a36Sopenharmony_ci *
37862306a36Sopenharmony_ci * To minimize space utilization, a portion of the hardware scb stores
37962306a36Sopenharmony_ci * different data during different portions of a SCSI transaction.
38062306a36Sopenharmony_ci * As initialized by the host driver for the initiator role, this area
38162306a36Sopenharmony_ci * contains the SCSI cdb (or a pointer to the  cdb) to be executed.  After
38262306a36Sopenharmony_ci * the cdb has been presented to the target, this area serves to store
38362306a36Sopenharmony_ci * residual transfer information and the SCSI status byte.
38462306a36Sopenharmony_ci * For the target role, the contents of this area do not change, but
38562306a36Sopenharmony_ci * still serve a different purpose than for the initiator role.  See
38662306a36Sopenharmony_ci * struct target_data for details.
38762306a36Sopenharmony_ci */
38862306a36Sopenharmony_ci
38962306a36Sopenharmony_ci/*
39062306a36Sopenharmony_ci * Status information embedded in the shared poriton of
39162306a36Sopenharmony_ci * an SCB after passing the cdb to the target.  The kernel
39262306a36Sopenharmony_ci * driver will only read this data for transactions that
39362306a36Sopenharmony_ci * complete abnormally.
39462306a36Sopenharmony_ci */
39562306a36Sopenharmony_cistruct initiator_status {
39662306a36Sopenharmony_ci	uint32_t residual_datacnt;	/* Residual in the current S/G seg */
39762306a36Sopenharmony_ci	uint32_t residual_sgptr;	/* The next S/G for this transfer */
39862306a36Sopenharmony_ci	uint8_t	 scsi_status;		/* Standard SCSI status byte */
39962306a36Sopenharmony_ci};
40062306a36Sopenharmony_ci
40162306a36Sopenharmony_cistruct target_status {
40262306a36Sopenharmony_ci	uint32_t residual_datacnt;	/* Residual in the current S/G seg */
40362306a36Sopenharmony_ci	uint32_t residual_sgptr;	/* The next S/G for this transfer */
40462306a36Sopenharmony_ci	uint8_t  scsi_status;		/* SCSI status to give to initiator */
40562306a36Sopenharmony_ci	uint8_t  target_phases;		/* Bitmap of phases to execute */
40662306a36Sopenharmony_ci	uint8_t  data_phase;		/* Data-In or Data-Out */
40762306a36Sopenharmony_ci	uint8_t  initiator_tag;		/* Initiator's transaction tag */
40862306a36Sopenharmony_ci};
40962306a36Sopenharmony_ci
41062306a36Sopenharmony_ci/*
41162306a36Sopenharmony_ci * Initiator mode SCB shared data area.
41262306a36Sopenharmony_ci * If the embedded CDB is 12 bytes or less, we embed
41362306a36Sopenharmony_ci * the sense buffer address in the SCB.  This allows
41462306a36Sopenharmony_ci * us to retrieve sense information without interrupting
41562306a36Sopenharmony_ci * the host in packetized mode.
41662306a36Sopenharmony_ci */
41762306a36Sopenharmony_citypedef uint32_t sense_addr_t;
41862306a36Sopenharmony_ci#define MAX_CDB_LEN 16
41962306a36Sopenharmony_ci#define MAX_CDB_LEN_WITH_SENSE_ADDR (MAX_CDB_LEN - sizeof(sense_addr_t))
42062306a36Sopenharmony_ciunion initiator_data {
42162306a36Sopenharmony_ci	struct {
42262306a36Sopenharmony_ci		uint64_t cdbptr;
42362306a36Sopenharmony_ci		uint8_t  cdblen;
42462306a36Sopenharmony_ci	} cdb_from_host;
42562306a36Sopenharmony_ci	uint8_t	 cdb[MAX_CDB_LEN];
42662306a36Sopenharmony_ci	struct {
42762306a36Sopenharmony_ci		uint8_t	 cdb[MAX_CDB_LEN_WITH_SENSE_ADDR];
42862306a36Sopenharmony_ci		sense_addr_t sense_addr;
42962306a36Sopenharmony_ci	} cdb_plus_saddr;
43062306a36Sopenharmony_ci};
43162306a36Sopenharmony_ci
43262306a36Sopenharmony_ci/*
43362306a36Sopenharmony_ci * Target mode version of the shared data SCB segment.
43462306a36Sopenharmony_ci */
43562306a36Sopenharmony_cistruct target_data {
43662306a36Sopenharmony_ci	uint32_t spare[2];
43762306a36Sopenharmony_ci	uint8_t  scsi_status;		/* SCSI status to give to initiator */
43862306a36Sopenharmony_ci	uint8_t  target_phases;		/* Bitmap of phases to execute */
43962306a36Sopenharmony_ci	uint8_t  data_phase;		/* Data-In or Data-Out */
44062306a36Sopenharmony_ci	uint8_t  initiator_tag;		/* Initiator's transaction tag */
44162306a36Sopenharmony_ci};
44262306a36Sopenharmony_ci
44362306a36Sopenharmony_cistruct hardware_scb {
44462306a36Sopenharmony_ci/*0*/	union {
44562306a36Sopenharmony_ci		union	initiator_data idata;
44662306a36Sopenharmony_ci		struct	target_data tdata;
44762306a36Sopenharmony_ci		struct	initiator_status istatus;
44862306a36Sopenharmony_ci		struct	target_status tstatus;
44962306a36Sopenharmony_ci	} shared_data;
45062306a36Sopenharmony_ci/*
45162306a36Sopenharmony_ci * A word about residuals.
45262306a36Sopenharmony_ci * The scb is presented to the sequencer with the dataptr and datacnt
45362306a36Sopenharmony_ci * fields initialized to the contents of the first S/G element to
45462306a36Sopenharmony_ci * transfer.  The sgptr field is initialized to the bus address for
45562306a36Sopenharmony_ci * the S/G element that follows the first in the in core S/G array
45662306a36Sopenharmony_ci * or'ed with the SG_FULL_RESID flag.  Sgptr may point to an invalid
45762306a36Sopenharmony_ci * S/G entry for this transfer (single S/G element transfer with the
45862306a36Sopenharmony_ci * first elements address and length preloaded in the dataptr/datacnt
45962306a36Sopenharmony_ci * fields).  If no transfer is to occur, sgptr is set to SG_LIST_NULL.
46062306a36Sopenharmony_ci * The SG_FULL_RESID flag ensures that the residual will be correctly
46162306a36Sopenharmony_ci * noted even if no data transfers occur.  Once the data phase is entered,
46262306a36Sopenharmony_ci * the residual sgptr and datacnt are loaded from the sgptr and the
46362306a36Sopenharmony_ci * datacnt fields.  After each S/G element's dataptr and length are
46462306a36Sopenharmony_ci * loaded into the hardware, the residual sgptr is advanced.  After
46562306a36Sopenharmony_ci * each S/G element is expired, its datacnt field is checked to see
46662306a36Sopenharmony_ci * if the LAST_SEG flag is set.  If so, SG_LIST_NULL is set in the
46762306a36Sopenharmony_ci * residual sg ptr and the transfer is considered complete.  If the
46862306a36Sopenharmony_ci * sequencer determines that there is a residual in the tranfer, or
46962306a36Sopenharmony_ci * there is non-zero status, it will set the SG_STATUS_VALID flag in
47062306a36Sopenharmony_ci * sgptr and dma the scb back into host memory.  To sumarize:
47162306a36Sopenharmony_ci *
47262306a36Sopenharmony_ci * Sequencer:
47362306a36Sopenharmony_ci *	o A residual has occurred if SG_FULL_RESID is set in sgptr,
47462306a36Sopenharmony_ci *	  or residual_sgptr does not have SG_LIST_NULL set.
47562306a36Sopenharmony_ci *
47662306a36Sopenharmony_ci *	o We are transferring the last segment if residual_datacnt has
47762306a36Sopenharmony_ci *	  the SG_LAST_SEG flag set.
47862306a36Sopenharmony_ci *
47962306a36Sopenharmony_ci * Host:
48062306a36Sopenharmony_ci *	o A residual can only have occurred if a completed scb has the
48162306a36Sopenharmony_ci *	  SG_STATUS_VALID flag set.  Inspection of the SCSI status field,
48262306a36Sopenharmony_ci *	  the residual_datacnt, and the residual_sgptr field will tell
48362306a36Sopenharmony_ci *	  for sure.
48462306a36Sopenharmony_ci *
48562306a36Sopenharmony_ci *	o residual_sgptr and sgptr refer to the "next" sg entry
48662306a36Sopenharmony_ci *	  and so may point beyond the last valid sg entry for the
48762306a36Sopenharmony_ci *	  transfer.
48862306a36Sopenharmony_ci */
48962306a36Sopenharmony_ci#define SG_PTR_MASK	0xFFFFFFF8
49062306a36Sopenharmony_ci/*16*/	uint16_t tag;		/* Reused by Sequencer. */
49162306a36Sopenharmony_ci/*18*/	uint8_t  control;	/* See SCB_CONTROL in aic79xx.reg for details */
49262306a36Sopenharmony_ci/*19*/	uint8_t	 scsiid;	/*
49362306a36Sopenharmony_ci				 * Selection out Id
49462306a36Sopenharmony_ci				 * Our Id (bits 0-3) Their ID (bits 4-7)
49562306a36Sopenharmony_ci				 */
49662306a36Sopenharmony_ci/*20*/	uint8_t  lun;
49762306a36Sopenharmony_ci/*21*/	uint8_t  task_attribute;
49862306a36Sopenharmony_ci/*22*/	uint8_t  cdb_len;
49962306a36Sopenharmony_ci/*23*/	uint8_t  task_management;
50062306a36Sopenharmony_ci/*24*/	uint64_t dataptr;
50162306a36Sopenharmony_ci/*32*/	uint32_t datacnt;	/* Byte 3 is spare. */
50262306a36Sopenharmony_ci/*36*/	uint32_t sgptr;
50362306a36Sopenharmony_ci/*40*/	uint32_t hscb_busaddr;
50462306a36Sopenharmony_ci/*44*/	uint32_t next_hscb_busaddr;
50562306a36Sopenharmony_ci/********** Long lun field only downloaded for full 8 byte lun support ********/
50662306a36Sopenharmony_ci/*48*/  uint8_t	 pkt_long_lun[8];
50762306a36Sopenharmony_ci/******* Fields below are not Downloaded (Sequencer may use for scratch) ******/
50862306a36Sopenharmony_ci/*56*/  uint8_t	 spare[8];
50962306a36Sopenharmony_ci};
51062306a36Sopenharmony_ci
51162306a36Sopenharmony_ci/************************ Kernel SCB Definitions ******************************/
51262306a36Sopenharmony_ci/*
51362306a36Sopenharmony_ci * Some fields of the SCB are OS dependent.  Here we collect the
51462306a36Sopenharmony_ci * definitions for elements that all OS platforms need to include
51562306a36Sopenharmony_ci * in there SCB definition.
51662306a36Sopenharmony_ci */
51762306a36Sopenharmony_ci
51862306a36Sopenharmony_ci/*
51962306a36Sopenharmony_ci * Definition of a scatter/gather element as transferred to the controller.
52062306a36Sopenharmony_ci * The aic7xxx chips only support a 24bit length.  We use the top byte of
52162306a36Sopenharmony_ci * the length to store additional address bits and a flag to indicate
52262306a36Sopenharmony_ci * that a given segment terminates the transfer.  This gives us an
52362306a36Sopenharmony_ci * addressable range of 512GB on machines with 64bit PCI or with chips
52462306a36Sopenharmony_ci * that can support dual address cycles on 32bit PCI busses.
52562306a36Sopenharmony_ci */
52662306a36Sopenharmony_cistruct ahd_dma_seg {
52762306a36Sopenharmony_ci	uint32_t	addr;
52862306a36Sopenharmony_ci	uint32_t	len;
52962306a36Sopenharmony_ci#define	AHD_DMA_LAST_SEG	0x80000000
53062306a36Sopenharmony_ci#define	AHD_SG_HIGH_ADDR_MASK	0x7F000000
53162306a36Sopenharmony_ci#define	AHD_SG_LEN_MASK		0x00FFFFFF
53262306a36Sopenharmony_ci};
53362306a36Sopenharmony_ci
53462306a36Sopenharmony_cistruct ahd_dma64_seg {
53562306a36Sopenharmony_ci	uint64_t	addr;
53662306a36Sopenharmony_ci	uint32_t	len;
53762306a36Sopenharmony_ci	uint32_t	pad;
53862306a36Sopenharmony_ci};
53962306a36Sopenharmony_ci
54062306a36Sopenharmony_cistruct map_node {
54162306a36Sopenharmony_ci	bus_dmamap_t		 dmamap;
54262306a36Sopenharmony_ci	dma_addr_t		 physaddr;
54362306a36Sopenharmony_ci	uint8_t			*vaddr;
54462306a36Sopenharmony_ci	SLIST_ENTRY(map_node)	 links;
54562306a36Sopenharmony_ci};
54662306a36Sopenharmony_ci
54762306a36Sopenharmony_ci/*
54862306a36Sopenharmony_ci * The current state of this SCB.
54962306a36Sopenharmony_ci */
55062306a36Sopenharmony_citypedef enum {
55162306a36Sopenharmony_ci	SCB_FLAG_NONE		= 0x00000,
55262306a36Sopenharmony_ci	SCB_TRANSMISSION_ERROR	= 0x00001,/*
55362306a36Sopenharmony_ci					   * We detected a parity or CRC
55462306a36Sopenharmony_ci					   * error that has effected the
55562306a36Sopenharmony_ci					   * payload of the command.  This
55662306a36Sopenharmony_ci					   * flag is checked when normal
55762306a36Sopenharmony_ci					   * status is returned to catch
55862306a36Sopenharmony_ci					   * the case of a target not
55962306a36Sopenharmony_ci					   * responding to our attempt
56062306a36Sopenharmony_ci					   * to report the error.
56162306a36Sopenharmony_ci					   */
56262306a36Sopenharmony_ci	SCB_OTHERTCL_TIMEOUT	= 0x00002,/*
56362306a36Sopenharmony_ci					   * Another device was active
56462306a36Sopenharmony_ci					   * during the first timeout for
56562306a36Sopenharmony_ci					   * this SCB so we gave ourselves
56662306a36Sopenharmony_ci					   * an additional timeout period
56762306a36Sopenharmony_ci					   * in case it was hogging the
56862306a36Sopenharmony_ci					   * bus.
56962306a36Sopenharmony_ci				           */
57062306a36Sopenharmony_ci	SCB_DEVICE_RESET	= 0x00004,
57162306a36Sopenharmony_ci	SCB_SENSE		= 0x00008,
57262306a36Sopenharmony_ci	SCB_CDB32_PTR		= 0x00010,
57362306a36Sopenharmony_ci	SCB_RECOVERY_SCB	= 0x00020,
57462306a36Sopenharmony_ci	SCB_AUTO_NEGOTIATE	= 0x00040,/* Negotiate to achieve goal. */
57562306a36Sopenharmony_ci	SCB_NEGOTIATE		= 0x00080,/* Negotiation forced for command. */
57662306a36Sopenharmony_ci	SCB_ABORT		= 0x00100,
57762306a36Sopenharmony_ci	SCB_ACTIVE		= 0x00200,
57862306a36Sopenharmony_ci	SCB_TARGET_IMMEDIATE	= 0x00400,
57962306a36Sopenharmony_ci	SCB_PACKETIZED		= 0x00800,
58062306a36Sopenharmony_ci	SCB_EXPECT_PPR_BUSFREE	= 0x01000,
58162306a36Sopenharmony_ci	SCB_PKT_SENSE		= 0x02000,
58262306a36Sopenharmony_ci	SCB_EXTERNAL_RESET	= 0x04000,/* Device was reset externally */
58362306a36Sopenharmony_ci	SCB_ON_COL_LIST		= 0x08000,
58462306a36Sopenharmony_ci	SCB_SILENT		= 0x10000 /*
58562306a36Sopenharmony_ci					   * Be quiet about transmission type
58662306a36Sopenharmony_ci					   * errors.  They are expected and we
58762306a36Sopenharmony_ci					   * don't want to upset the user.  This
58862306a36Sopenharmony_ci					   * flag is typically used during DV.
58962306a36Sopenharmony_ci					   */
59062306a36Sopenharmony_ci} scb_flag;
59162306a36Sopenharmony_ci
59262306a36Sopenharmony_cistruct scb {
59362306a36Sopenharmony_ci	struct	hardware_scb	 *hscb;
59462306a36Sopenharmony_ci	union {
59562306a36Sopenharmony_ci		SLIST_ENTRY(scb)  sle;
59662306a36Sopenharmony_ci		LIST_ENTRY(scb)	  le;
59762306a36Sopenharmony_ci		TAILQ_ENTRY(scb)  tqe;
59862306a36Sopenharmony_ci	} links;
59962306a36Sopenharmony_ci	union {
60062306a36Sopenharmony_ci		SLIST_ENTRY(scb)  sle;
60162306a36Sopenharmony_ci		LIST_ENTRY(scb)	  le;
60262306a36Sopenharmony_ci		TAILQ_ENTRY(scb)  tqe;
60362306a36Sopenharmony_ci	} links2;
60462306a36Sopenharmony_ci#define pending_links links2.le
60562306a36Sopenharmony_ci#define collision_links links2.le
60662306a36Sopenharmony_ci	struct scb		 *col_scb;
60762306a36Sopenharmony_ci	ahd_io_ctx_t		  io_ctx;
60862306a36Sopenharmony_ci	struct ahd_softc	 *ahd_softc;
60962306a36Sopenharmony_ci	scb_flag		  flags;
61062306a36Sopenharmony_ci	struct scb_platform_data *platform_data;
61162306a36Sopenharmony_ci	struct map_node		 *hscb_map;
61262306a36Sopenharmony_ci	struct map_node		 *sg_map;
61362306a36Sopenharmony_ci	struct map_node		 *sense_map;
61462306a36Sopenharmony_ci	void			 *sg_list;
61562306a36Sopenharmony_ci	uint8_t			 *sense_data;
61662306a36Sopenharmony_ci	dma_addr_t		  sg_list_busaddr;
61762306a36Sopenharmony_ci	dma_addr_t		  sense_busaddr;
61862306a36Sopenharmony_ci	u_int			  sg_count;/* How full ahd_dma_seg is */
61962306a36Sopenharmony_ci#define	AHD_MAX_LQ_CRC_ERRORS 5
62062306a36Sopenharmony_ci	u_int			  crc_retry_count;
62162306a36Sopenharmony_ci};
62262306a36Sopenharmony_ci
62362306a36Sopenharmony_ciTAILQ_HEAD(scb_tailq, scb);
62462306a36Sopenharmony_ciBSD_LIST_HEAD(scb_list, scb);
62562306a36Sopenharmony_ci
62662306a36Sopenharmony_cistruct scb_data {
62762306a36Sopenharmony_ci	/*
62862306a36Sopenharmony_ci	 * TAILQ of lists of free SCBs grouped by device
62962306a36Sopenharmony_ci	 * collision domains.
63062306a36Sopenharmony_ci	 */
63162306a36Sopenharmony_ci	struct scb_tailq free_scbs;
63262306a36Sopenharmony_ci
63362306a36Sopenharmony_ci	/*
63462306a36Sopenharmony_ci	 * Per-device lists of SCBs whose tag ID would collide
63562306a36Sopenharmony_ci	 * with an already active tag on the device.
63662306a36Sopenharmony_ci	 */
63762306a36Sopenharmony_ci	struct scb_list free_scb_lists[AHD_NUM_TARGETS * AHD_NUM_LUNS_NONPKT];
63862306a36Sopenharmony_ci
63962306a36Sopenharmony_ci	/*
64062306a36Sopenharmony_ci	 * SCBs that will not collide with any active device.
64162306a36Sopenharmony_ci	 */
64262306a36Sopenharmony_ci	struct scb_list any_dev_free_scb_list;
64362306a36Sopenharmony_ci
64462306a36Sopenharmony_ci	/*
64562306a36Sopenharmony_ci	 * Mapping from tag to SCB.
64662306a36Sopenharmony_ci	 */
64762306a36Sopenharmony_ci	struct	scb *scbindex[AHD_SCB_MAX];
64862306a36Sopenharmony_ci
64962306a36Sopenharmony_ci	/*
65062306a36Sopenharmony_ci	 * "Bus" addresses of our data structures.
65162306a36Sopenharmony_ci	 */
65262306a36Sopenharmony_ci	bus_dma_tag_t	 hscb_dmat;	/* dmat for our hardware SCB array */
65362306a36Sopenharmony_ci	bus_dma_tag_t	 sg_dmat;	/* dmat for our sg segments */
65462306a36Sopenharmony_ci	bus_dma_tag_t	 sense_dmat;	/* dmat for our sense buffers */
65562306a36Sopenharmony_ci	SLIST_HEAD(, map_node) hscb_maps;
65662306a36Sopenharmony_ci	SLIST_HEAD(, map_node) sg_maps;
65762306a36Sopenharmony_ci	SLIST_HEAD(, map_node) sense_maps;
65862306a36Sopenharmony_ci	int		 scbs_left;	/* unallocated scbs in head map_node */
65962306a36Sopenharmony_ci	int		 sgs_left;	/* unallocated sgs in head map_node */
66062306a36Sopenharmony_ci	int		 sense_left;	/* unallocated sense in head map_node */
66162306a36Sopenharmony_ci	uint16_t	 numscbs;
66262306a36Sopenharmony_ci	uint16_t	 maxhscbs;	/* Number of SCBs on the card */
66362306a36Sopenharmony_ci	uint8_t		 init_level;	/*
66462306a36Sopenharmony_ci					 * How far we've initialized
66562306a36Sopenharmony_ci					 * this structure.
66662306a36Sopenharmony_ci					 */
66762306a36Sopenharmony_ci};
66862306a36Sopenharmony_ci
66962306a36Sopenharmony_ci/************************ Target Mode Definitions *****************************/
67062306a36Sopenharmony_ci
67162306a36Sopenharmony_ci/*
67262306a36Sopenharmony_ci * Connection descriptor for select-in requests in target mode.
67362306a36Sopenharmony_ci */
67462306a36Sopenharmony_cistruct target_cmd {
67562306a36Sopenharmony_ci	uint8_t scsiid;		/* Our ID and the initiator's ID */
67662306a36Sopenharmony_ci	uint8_t identify;	/* Identify message */
67762306a36Sopenharmony_ci	uint8_t bytes[22];	/*
67862306a36Sopenharmony_ci				 * Bytes contains any additional message
67962306a36Sopenharmony_ci				 * bytes terminated by 0xFF.  The remainder
68062306a36Sopenharmony_ci				 * is the cdb to execute.
68162306a36Sopenharmony_ci				 */
68262306a36Sopenharmony_ci	uint8_t cmd_valid;	/*
68362306a36Sopenharmony_ci				 * When a command is complete, the firmware
68462306a36Sopenharmony_ci				 * will set cmd_valid to all bits set.
68562306a36Sopenharmony_ci				 * After the host has seen the command,
68662306a36Sopenharmony_ci				 * the bits are cleared.  This allows us
68762306a36Sopenharmony_ci				 * to just peek at host memory to determine
68862306a36Sopenharmony_ci				 * if more work is complete. cmd_valid is on
68962306a36Sopenharmony_ci				 * an 8 byte boundary to simplify setting
69062306a36Sopenharmony_ci				 * it on aic7880 hardware which only has
69162306a36Sopenharmony_ci				 * limited direct access to the DMA FIFO.
69262306a36Sopenharmony_ci				 */
69362306a36Sopenharmony_ci	uint8_t pad[7];
69462306a36Sopenharmony_ci};
69562306a36Sopenharmony_ci
69662306a36Sopenharmony_ci/*
69762306a36Sopenharmony_ci * Number of events we can buffer up if we run out
69862306a36Sopenharmony_ci * of immediate notify ccbs.
69962306a36Sopenharmony_ci */
70062306a36Sopenharmony_ci#define AHD_TMODE_EVENT_BUFFER_SIZE 8
70162306a36Sopenharmony_cistruct ahd_tmode_event {
70262306a36Sopenharmony_ci	uint8_t initiator_id;
70362306a36Sopenharmony_ci	uint8_t event_type;	/* MSG type or EVENT_TYPE_BUS_RESET */
70462306a36Sopenharmony_ci#define	EVENT_TYPE_BUS_RESET 0xFF
70562306a36Sopenharmony_ci	uint8_t event_arg;
70662306a36Sopenharmony_ci};
70762306a36Sopenharmony_ci
70862306a36Sopenharmony_ci/*
70962306a36Sopenharmony_ci * Per enabled lun target mode state.
71062306a36Sopenharmony_ci * As this state is directly influenced by the host OS'es target mode
71162306a36Sopenharmony_ci * environment, we let the OS module define it.  Forward declare the
71262306a36Sopenharmony_ci * structure here so we can store arrays of them, etc. in OS neutral
71362306a36Sopenharmony_ci * data structures.
71462306a36Sopenharmony_ci */
71562306a36Sopenharmony_ci#ifdef AHD_TARGET_MODE
71662306a36Sopenharmony_cistruct ahd_tmode_lstate {
71762306a36Sopenharmony_ci	struct cam_path *path;
71862306a36Sopenharmony_ci	struct ccb_hdr_slist accept_tios;
71962306a36Sopenharmony_ci	struct ccb_hdr_slist immed_notifies;
72062306a36Sopenharmony_ci	struct ahd_tmode_event event_buffer[AHD_TMODE_EVENT_BUFFER_SIZE];
72162306a36Sopenharmony_ci	uint8_t event_r_idx;
72262306a36Sopenharmony_ci	uint8_t event_w_idx;
72362306a36Sopenharmony_ci};
72462306a36Sopenharmony_ci#else
72562306a36Sopenharmony_cistruct ahd_tmode_lstate;
72662306a36Sopenharmony_ci#endif
72762306a36Sopenharmony_ci
72862306a36Sopenharmony_ci/******************** Transfer Negotiation Datastructures *********************/
72962306a36Sopenharmony_ci#define AHD_TRANS_CUR		0x01	/* Modify current neogtiation status */
73062306a36Sopenharmony_ci#define AHD_TRANS_ACTIVE	0x03	/* Assume this target is on the bus */
73162306a36Sopenharmony_ci#define AHD_TRANS_GOAL		0x04	/* Modify negotiation goal */
73262306a36Sopenharmony_ci#define AHD_TRANS_USER		0x08	/* Modify user negotiation settings */
73362306a36Sopenharmony_ci#define AHD_PERIOD_10MHz	0x19
73462306a36Sopenharmony_ci
73562306a36Sopenharmony_ci#define AHD_WIDTH_UNKNOWN	0xFF
73662306a36Sopenharmony_ci#define AHD_PERIOD_UNKNOWN	0xFF
73762306a36Sopenharmony_ci#define AHD_OFFSET_UNKNOWN	0xFF
73862306a36Sopenharmony_ci#define AHD_PPR_OPTS_UNKNOWN	0xFF
73962306a36Sopenharmony_ci
74062306a36Sopenharmony_ci/*
74162306a36Sopenharmony_ci * Transfer Negotiation Information.
74262306a36Sopenharmony_ci */
74362306a36Sopenharmony_cistruct ahd_transinfo {
74462306a36Sopenharmony_ci	uint8_t protocol_version;	/* SCSI Revision level */
74562306a36Sopenharmony_ci	uint8_t transport_version;	/* SPI Revision level */
74662306a36Sopenharmony_ci	uint8_t width;			/* Bus width */
74762306a36Sopenharmony_ci	uint8_t period;			/* Sync rate factor */
74862306a36Sopenharmony_ci	uint8_t offset;			/* Sync offset */
74962306a36Sopenharmony_ci	uint8_t ppr_options;		/* Parallel Protocol Request options */
75062306a36Sopenharmony_ci};
75162306a36Sopenharmony_ci
75262306a36Sopenharmony_ci/*
75362306a36Sopenharmony_ci * Per-initiator current, goal and user transfer negotiation information. */
75462306a36Sopenharmony_cistruct ahd_initiator_tinfo {
75562306a36Sopenharmony_ci	struct ahd_transinfo curr;
75662306a36Sopenharmony_ci	struct ahd_transinfo goal;
75762306a36Sopenharmony_ci	struct ahd_transinfo user;
75862306a36Sopenharmony_ci};
75962306a36Sopenharmony_ci
76062306a36Sopenharmony_ci/*
76162306a36Sopenharmony_ci * Per enabled target ID state.
76262306a36Sopenharmony_ci * Pointers to lun target state as well as sync/wide negotiation information
76362306a36Sopenharmony_ci * for each initiator<->target mapping.  For the initiator role we pretend
76462306a36Sopenharmony_ci * that we are the target and the targets are the initiators since the
76562306a36Sopenharmony_ci * negotiation is the same regardless of role.
76662306a36Sopenharmony_ci */
76762306a36Sopenharmony_cistruct ahd_tmode_tstate {
76862306a36Sopenharmony_ci	struct ahd_tmode_lstate*	enabled_luns[AHD_NUM_LUNS];
76962306a36Sopenharmony_ci	struct ahd_initiator_tinfo	transinfo[AHD_NUM_TARGETS];
77062306a36Sopenharmony_ci
77162306a36Sopenharmony_ci	/*
77262306a36Sopenharmony_ci	 * Per initiator state bitmasks.
77362306a36Sopenharmony_ci	 */
77462306a36Sopenharmony_ci	uint16_t	 auto_negotiate;/* Auto Negotiation Required */
77562306a36Sopenharmony_ci	uint16_t	 discenable;	/* Disconnection allowed  */
77662306a36Sopenharmony_ci	uint16_t	 tagenable;	/* Tagged Queuing allowed */
77762306a36Sopenharmony_ci};
77862306a36Sopenharmony_ci
77962306a36Sopenharmony_ci/*
78062306a36Sopenharmony_ci * Points of interest along the negotiated transfer scale.
78162306a36Sopenharmony_ci */
78262306a36Sopenharmony_ci#define AHD_SYNCRATE_160	0x8
78362306a36Sopenharmony_ci#define AHD_SYNCRATE_PACED	0x8
78462306a36Sopenharmony_ci#define AHD_SYNCRATE_DT		0x9
78562306a36Sopenharmony_ci#define AHD_SYNCRATE_ULTRA2	0xa
78662306a36Sopenharmony_ci#define AHD_SYNCRATE_ULTRA	0xc
78762306a36Sopenharmony_ci#define AHD_SYNCRATE_FAST	0x19
78862306a36Sopenharmony_ci#define AHD_SYNCRATE_MIN_DT	AHD_SYNCRATE_FAST
78962306a36Sopenharmony_ci#define AHD_SYNCRATE_SYNC	0x32
79062306a36Sopenharmony_ci#define AHD_SYNCRATE_MIN	0x60
79162306a36Sopenharmony_ci#define	AHD_SYNCRATE_ASYNC	0xFF
79262306a36Sopenharmony_ci#define AHD_SYNCRATE_MAX	AHD_SYNCRATE_160
79362306a36Sopenharmony_ci
79462306a36Sopenharmony_ci/* Safe and valid period for async negotiations. */
79562306a36Sopenharmony_ci#define	AHD_ASYNC_XFER_PERIOD	0x44
79662306a36Sopenharmony_ci
79762306a36Sopenharmony_ci/*
79862306a36Sopenharmony_ci * In RevA, the synctable uses a 120MHz rate for the period
79962306a36Sopenharmony_ci * factor 8 and 160MHz for the period factor 7.  The 120MHz
80062306a36Sopenharmony_ci * rate never made it into the official SCSI spec, so we must
80162306a36Sopenharmony_ci * compensate when setting the negotiation table for Rev A
80262306a36Sopenharmony_ci * parts.
80362306a36Sopenharmony_ci */
80462306a36Sopenharmony_ci#define AHD_SYNCRATE_REVA_120	0x8
80562306a36Sopenharmony_ci#define AHD_SYNCRATE_REVA_160	0x7
80662306a36Sopenharmony_ci
80762306a36Sopenharmony_ci/***************************** Lookup Tables **********************************/
80862306a36Sopenharmony_ci/*
80962306a36Sopenharmony_ci * Phase -> name and message out response
81062306a36Sopenharmony_ci * to parity errors in each phase table.
81162306a36Sopenharmony_ci */
81262306a36Sopenharmony_cistruct ahd_phase_table_entry {
81362306a36Sopenharmony_ci	uint8_t phase;
81462306a36Sopenharmony_ci	uint8_t mesg_out; /* Message response to parity errors */
81562306a36Sopenharmony_ci	const char *phasemsg;
81662306a36Sopenharmony_ci};
81762306a36Sopenharmony_ci
81862306a36Sopenharmony_ci/************************** Serial EEPROM Format ******************************/
81962306a36Sopenharmony_ci
82062306a36Sopenharmony_cistruct seeprom_config {
82162306a36Sopenharmony_ci/*
82262306a36Sopenharmony_ci * Per SCSI ID Configuration Flags
82362306a36Sopenharmony_ci */
82462306a36Sopenharmony_ci	uint16_t device_flags[16];	/* words 0-15 */
82562306a36Sopenharmony_ci#define		CFXFER		0x003F	/* synchronous transfer rate */
82662306a36Sopenharmony_ci#define			CFXFER_ASYNC	0x3F
82762306a36Sopenharmony_ci#define		CFQAS		0x0040	/* Negotiate QAS */
82862306a36Sopenharmony_ci#define		CFPACKETIZED	0x0080	/* Negotiate Packetized Transfers */
82962306a36Sopenharmony_ci#define		CFSTART		0x0100	/* send start unit SCSI command */
83062306a36Sopenharmony_ci#define		CFINCBIOS	0x0200	/* include in BIOS scan */
83162306a36Sopenharmony_ci#define		CFDISC		0x0400	/* enable disconnection */
83262306a36Sopenharmony_ci#define		CFMULTILUNDEV	0x0800	/* Probe multiple luns in BIOS scan */
83362306a36Sopenharmony_ci#define		CFWIDEB		0x1000	/* wide bus device */
83462306a36Sopenharmony_ci#define		CFHOSTMANAGED	0x8000	/* Managed by a RAID controller */
83562306a36Sopenharmony_ci
83662306a36Sopenharmony_ci/*
83762306a36Sopenharmony_ci * BIOS Control Bits
83862306a36Sopenharmony_ci */
83962306a36Sopenharmony_ci	uint16_t bios_control;		/* word 16 */
84062306a36Sopenharmony_ci#define		CFSUPREM	0x0001	/* support all removeable drives */
84162306a36Sopenharmony_ci#define		CFSUPREMB	0x0002	/* support removeable boot drives */
84262306a36Sopenharmony_ci#define		CFBIOSSTATE	0x000C	/* BIOS Action State */
84362306a36Sopenharmony_ci#define		    CFBS_DISABLED	0x00
84462306a36Sopenharmony_ci#define		    CFBS_ENABLED	0x04
84562306a36Sopenharmony_ci#define		    CFBS_DISABLED_SCAN	0x08
84662306a36Sopenharmony_ci#define		CFENABLEDV	0x0010	/* Perform Domain Validation */
84762306a36Sopenharmony_ci#define		CFCTRL_A	0x0020	/* BIOS displays Ctrl-A message */
84862306a36Sopenharmony_ci#define		CFSPARITY	0x0040	/* SCSI parity */
84962306a36Sopenharmony_ci#define		CFEXTEND	0x0080	/* extended translation enabled */
85062306a36Sopenharmony_ci#define		CFBOOTCD	0x0100  /* Support Bootable CD-ROM */
85162306a36Sopenharmony_ci#define		CFMSG_LEVEL	0x0600	/* BIOS Message Level */
85262306a36Sopenharmony_ci#define			CFMSG_VERBOSE	0x0000
85362306a36Sopenharmony_ci#define			CFMSG_SILENT	0x0200
85462306a36Sopenharmony_ci#define			CFMSG_DIAG	0x0400
85562306a36Sopenharmony_ci#define		CFRESETB	0x0800	/* reset SCSI bus at boot */
85662306a36Sopenharmony_ci/*		UNUSED		0xf000	*/
85762306a36Sopenharmony_ci
85862306a36Sopenharmony_ci/*
85962306a36Sopenharmony_ci * Host Adapter Control Bits
86062306a36Sopenharmony_ci */
86162306a36Sopenharmony_ci	uint16_t adapter_control;	/* word 17 */
86262306a36Sopenharmony_ci#define		CFAUTOTERM	0x0001	/* Perform Auto termination */
86362306a36Sopenharmony_ci#define		CFSTERM		0x0002	/* SCSI low byte termination */
86462306a36Sopenharmony_ci#define		CFWSTERM	0x0004	/* SCSI high byte termination */
86562306a36Sopenharmony_ci#define		CFSEAUTOTERM	0x0008	/* Ultra2 Perform secondary Auto Term*/
86662306a36Sopenharmony_ci#define		CFSELOWTERM	0x0010	/* Ultra2 secondary low term */
86762306a36Sopenharmony_ci#define		CFSEHIGHTERM	0x0020	/* Ultra2 secondary high term */
86862306a36Sopenharmony_ci#define		CFSTPWLEVEL	0x0040	/* Termination level control */
86962306a36Sopenharmony_ci#define		CFBIOSAUTOTERM	0x0080	/* Perform Auto termination */
87062306a36Sopenharmony_ci#define		CFTERM_MENU	0x0100	/* BIOS displays termination menu */
87162306a36Sopenharmony_ci#define		CFCLUSTERENB	0x8000	/* Cluster Enable */
87262306a36Sopenharmony_ci
87362306a36Sopenharmony_ci/*
87462306a36Sopenharmony_ci * Bus Release Time, Host Adapter ID
87562306a36Sopenharmony_ci */
87662306a36Sopenharmony_ci	uint16_t brtime_id;		/* word 18 */
87762306a36Sopenharmony_ci#define		CFSCSIID	0x000f	/* host adapter SCSI ID */
87862306a36Sopenharmony_ci/*		UNUSED		0x00f0	*/
87962306a36Sopenharmony_ci#define		CFBRTIME	0xff00	/* bus release time/PCI Latency Time */
88062306a36Sopenharmony_ci
88162306a36Sopenharmony_ci/*
88262306a36Sopenharmony_ci * Maximum targets
88362306a36Sopenharmony_ci */
88462306a36Sopenharmony_ci	uint16_t max_targets;		/* word 19 */
88562306a36Sopenharmony_ci#define		CFMAXTARG	0x00ff	/* maximum targets */
88662306a36Sopenharmony_ci#define		CFBOOTLUN	0x0f00	/* Lun to boot from */
88762306a36Sopenharmony_ci#define		CFBOOTID	0xf000	/* Target to boot from */
88862306a36Sopenharmony_ci	uint16_t res_1[10];		/* words 20-29 */
88962306a36Sopenharmony_ci	uint16_t signature;		/* BIOS Signature */
89062306a36Sopenharmony_ci#define		CFSIGNATURE	0x400
89162306a36Sopenharmony_ci	uint16_t checksum;		/* word 31 */
89262306a36Sopenharmony_ci};
89362306a36Sopenharmony_ci
89462306a36Sopenharmony_ci/*
89562306a36Sopenharmony_ci * Vital Product Data used during POST and by the BIOS.
89662306a36Sopenharmony_ci */
89762306a36Sopenharmony_cistruct vpd_config {
89862306a36Sopenharmony_ci	uint8_t  bios_flags;
89962306a36Sopenharmony_ci#define		VPDMASTERBIOS	0x0001
90062306a36Sopenharmony_ci#define		VPDBOOTHOST	0x0002
90162306a36Sopenharmony_ci	uint8_t  reserved_1[21];
90262306a36Sopenharmony_ci	uint8_t  resource_type;
90362306a36Sopenharmony_ci	uint8_t  resource_len[2];
90462306a36Sopenharmony_ci	uint8_t  resource_data[8];
90562306a36Sopenharmony_ci	uint8_t  vpd_tag;
90662306a36Sopenharmony_ci	uint16_t vpd_len;
90762306a36Sopenharmony_ci	uint8_t  vpd_keyword[2];
90862306a36Sopenharmony_ci	uint8_t  length;
90962306a36Sopenharmony_ci	uint8_t  revision;
91062306a36Sopenharmony_ci	uint8_t  device_flags;
91162306a36Sopenharmony_ci	uint8_t  termination_menus[2];
91262306a36Sopenharmony_ci	uint8_t  fifo_threshold;
91362306a36Sopenharmony_ci	uint8_t  end_tag;
91462306a36Sopenharmony_ci	uint8_t  vpd_checksum;
91562306a36Sopenharmony_ci	uint16_t default_target_flags;
91662306a36Sopenharmony_ci	uint16_t default_bios_flags;
91762306a36Sopenharmony_ci	uint16_t default_ctrl_flags;
91862306a36Sopenharmony_ci	uint8_t  default_irq;
91962306a36Sopenharmony_ci	uint8_t  pci_lattime;
92062306a36Sopenharmony_ci	uint8_t  max_target;
92162306a36Sopenharmony_ci	uint8_t  boot_lun;
92262306a36Sopenharmony_ci	uint16_t signature;
92362306a36Sopenharmony_ci	uint8_t  reserved_2;
92462306a36Sopenharmony_ci	uint8_t  checksum;
92562306a36Sopenharmony_ci	uint8_t	 reserved_3[4];
92662306a36Sopenharmony_ci};
92762306a36Sopenharmony_ci
92862306a36Sopenharmony_ci/****************************** Flexport Logic ********************************/
92962306a36Sopenharmony_ci#define FLXADDR_TERMCTL			0x0
93062306a36Sopenharmony_ci#define		FLX_TERMCTL_ENSECHIGH	0x8
93162306a36Sopenharmony_ci#define		FLX_TERMCTL_ENSECLOW	0x4
93262306a36Sopenharmony_ci#define		FLX_TERMCTL_ENPRIHIGH	0x2
93362306a36Sopenharmony_ci#define		FLX_TERMCTL_ENPRILOW	0x1
93462306a36Sopenharmony_ci#define FLXADDR_ROMSTAT_CURSENSECTL	0x1
93562306a36Sopenharmony_ci#define		FLX_ROMSTAT_SEECFG	0xF0
93662306a36Sopenharmony_ci#define		FLX_ROMSTAT_EECFG	0x0F
93762306a36Sopenharmony_ci#define		FLX_ROMSTAT_SEE_93C66	0x00
93862306a36Sopenharmony_ci#define		FLX_ROMSTAT_SEE_NONE	0xF0
93962306a36Sopenharmony_ci#define		FLX_ROMSTAT_EE_512x8	0x0
94062306a36Sopenharmony_ci#define		FLX_ROMSTAT_EE_1MBx8	0x1
94162306a36Sopenharmony_ci#define		FLX_ROMSTAT_EE_2MBx8	0x2
94262306a36Sopenharmony_ci#define		FLX_ROMSTAT_EE_4MBx8	0x3
94362306a36Sopenharmony_ci#define		FLX_ROMSTAT_EE_16MBx8	0x4
94462306a36Sopenharmony_ci#define			CURSENSE_ENB	0x1
94562306a36Sopenharmony_ci#define	FLXADDR_FLEXSTAT		0x2
94662306a36Sopenharmony_ci#define		FLX_FSTAT_BUSY		0x1
94762306a36Sopenharmony_ci#define FLXADDR_CURRENT_STAT		0x4
94862306a36Sopenharmony_ci#define		FLX_CSTAT_SEC_HIGH	0xC0
94962306a36Sopenharmony_ci#define		FLX_CSTAT_SEC_LOW	0x30
95062306a36Sopenharmony_ci#define		FLX_CSTAT_PRI_HIGH	0x0C
95162306a36Sopenharmony_ci#define		FLX_CSTAT_PRI_LOW	0x03
95262306a36Sopenharmony_ci#define		FLX_CSTAT_MASK		0x03
95362306a36Sopenharmony_ci#define		FLX_CSTAT_SHIFT		2
95462306a36Sopenharmony_ci#define		FLX_CSTAT_OKAY		0x0
95562306a36Sopenharmony_ci#define		FLX_CSTAT_OVER		0x1
95662306a36Sopenharmony_ci#define		FLX_CSTAT_UNDER		0x2
95762306a36Sopenharmony_ci#define		FLX_CSTAT_INVALID	0x3
95862306a36Sopenharmony_ci
95962306a36Sopenharmony_ciint		ahd_read_seeprom(struct ahd_softc *ahd, uint16_t *buf,
96062306a36Sopenharmony_ci				 u_int start_addr, u_int count, int bstream);
96162306a36Sopenharmony_ci
96262306a36Sopenharmony_ciint		ahd_write_seeprom(struct ahd_softc *ahd, uint16_t *buf,
96362306a36Sopenharmony_ci				  u_int start_addr, u_int count);
96462306a36Sopenharmony_ciint		ahd_verify_cksum(struct seeprom_config *sc);
96562306a36Sopenharmony_ciint		ahd_acquire_seeprom(struct ahd_softc *ahd);
96662306a36Sopenharmony_civoid		ahd_release_seeprom(struct ahd_softc *ahd);
96762306a36Sopenharmony_ci
96862306a36Sopenharmony_ci/****************************  Message Buffer *********************************/
96962306a36Sopenharmony_citypedef enum {
97062306a36Sopenharmony_ci	MSG_FLAG_NONE			= 0x00,
97162306a36Sopenharmony_ci	MSG_FLAG_EXPECT_PPR_BUSFREE	= 0x01,
97262306a36Sopenharmony_ci	MSG_FLAG_IU_REQ_CHANGED		= 0x02,
97362306a36Sopenharmony_ci	MSG_FLAG_EXPECT_IDE_BUSFREE	= 0x04,
97462306a36Sopenharmony_ci	MSG_FLAG_EXPECT_QASREJ_BUSFREE	= 0x08,
97562306a36Sopenharmony_ci	MSG_FLAG_PACKETIZED		= 0x10
97662306a36Sopenharmony_ci} ahd_msg_flags;
97762306a36Sopenharmony_ci
97862306a36Sopenharmony_citypedef enum {
97962306a36Sopenharmony_ci	MSG_TYPE_NONE			= 0x00,
98062306a36Sopenharmony_ci	MSG_TYPE_INITIATOR_MSGOUT	= 0x01,
98162306a36Sopenharmony_ci	MSG_TYPE_INITIATOR_MSGIN	= 0x02,
98262306a36Sopenharmony_ci	MSG_TYPE_TARGET_MSGOUT		= 0x03,
98362306a36Sopenharmony_ci	MSG_TYPE_TARGET_MSGIN		= 0x04
98462306a36Sopenharmony_ci} ahd_msg_type;
98562306a36Sopenharmony_ci
98662306a36Sopenharmony_citypedef enum {
98762306a36Sopenharmony_ci	MSGLOOP_IN_PROG,
98862306a36Sopenharmony_ci	MSGLOOP_MSGCOMPLETE,
98962306a36Sopenharmony_ci	MSGLOOP_TERMINATED
99062306a36Sopenharmony_ci} msg_loop_stat;
99162306a36Sopenharmony_ci
99262306a36Sopenharmony_ci/*********************** Software Configuration Structure *********************/
99362306a36Sopenharmony_cistruct ahd_suspend_channel_state {
99462306a36Sopenharmony_ci	uint8_t	scsiseq;
99562306a36Sopenharmony_ci	uint8_t	sxfrctl0;
99662306a36Sopenharmony_ci	uint8_t	sxfrctl1;
99762306a36Sopenharmony_ci	uint8_t	simode0;
99862306a36Sopenharmony_ci	uint8_t	simode1;
99962306a36Sopenharmony_ci	uint8_t	seltimer;
100062306a36Sopenharmony_ci	uint8_t	seqctl;
100162306a36Sopenharmony_ci};
100262306a36Sopenharmony_ci
100362306a36Sopenharmony_cistruct ahd_suspend_pci_state {
100462306a36Sopenharmony_ci	uint32_t  devconfig;
100562306a36Sopenharmony_ci	uint8_t   command;
100662306a36Sopenharmony_ci	uint8_t   csize_lattime;
100762306a36Sopenharmony_ci};
100862306a36Sopenharmony_ci
100962306a36Sopenharmony_cistruct ahd_suspend_state {
101062306a36Sopenharmony_ci	struct	ahd_suspend_channel_state channel[2];
101162306a36Sopenharmony_ci	struct  ahd_suspend_pci_state pci_state;
101262306a36Sopenharmony_ci	uint8_t	optionmode;
101362306a36Sopenharmony_ci	uint8_t	dscommand0;
101462306a36Sopenharmony_ci	uint8_t	dspcistatus;
101562306a36Sopenharmony_ci	/* hsmailbox */
101662306a36Sopenharmony_ci	uint8_t	crccontrol1;
101762306a36Sopenharmony_ci	uint8_t	scbbaddr;
101862306a36Sopenharmony_ci	/* Host and sequencer SCB counts */
101962306a36Sopenharmony_ci	uint8_t	dff_thrsh;
102062306a36Sopenharmony_ci	uint8_t	*scratch_ram;
102162306a36Sopenharmony_ci	uint8_t	*btt;
102262306a36Sopenharmony_ci};
102362306a36Sopenharmony_ci
102462306a36Sopenharmony_citypedef void (*ahd_bus_intr_t)(struct ahd_softc *);
102562306a36Sopenharmony_ci
102662306a36Sopenharmony_citypedef enum {
102762306a36Sopenharmony_ci	AHD_MODE_DFF0,
102862306a36Sopenharmony_ci	AHD_MODE_DFF1,
102962306a36Sopenharmony_ci	AHD_MODE_CCHAN,
103062306a36Sopenharmony_ci	AHD_MODE_SCSI,
103162306a36Sopenharmony_ci	AHD_MODE_CFG,
103262306a36Sopenharmony_ci	AHD_MODE_UNKNOWN
103362306a36Sopenharmony_ci} ahd_mode;
103462306a36Sopenharmony_ci
103562306a36Sopenharmony_ci#define AHD_MK_MSK(x) (0x01 << (x))
103662306a36Sopenharmony_ci#define AHD_MODE_DFF0_MSK	AHD_MK_MSK(AHD_MODE_DFF0)
103762306a36Sopenharmony_ci#define AHD_MODE_DFF1_MSK	AHD_MK_MSK(AHD_MODE_DFF1)
103862306a36Sopenharmony_ci#define AHD_MODE_CCHAN_MSK	AHD_MK_MSK(AHD_MODE_CCHAN)
103962306a36Sopenharmony_ci#define AHD_MODE_SCSI_MSK	AHD_MK_MSK(AHD_MODE_SCSI)
104062306a36Sopenharmony_ci#define AHD_MODE_CFG_MSK	AHD_MK_MSK(AHD_MODE_CFG)
104162306a36Sopenharmony_ci#define AHD_MODE_UNKNOWN_MSK	AHD_MK_MSK(AHD_MODE_UNKNOWN)
104262306a36Sopenharmony_ci#define AHD_MODE_ANY_MSK (~0)
104362306a36Sopenharmony_ci
104462306a36Sopenharmony_citypedef uint8_t ahd_mode_state;
104562306a36Sopenharmony_ci
104662306a36Sopenharmony_cistruct ahd_completion
104762306a36Sopenharmony_ci{
104862306a36Sopenharmony_ci	uint16_t	tag;
104962306a36Sopenharmony_ci	uint8_t		sg_status;
105062306a36Sopenharmony_ci	uint8_t		valid_tag;
105162306a36Sopenharmony_ci};
105262306a36Sopenharmony_ci
105362306a36Sopenharmony_cistruct ahd_softc {
105462306a36Sopenharmony_ci	bus_space_tag_t		  tags[2];
105562306a36Sopenharmony_ci	bus_space_handle_t	  bshs[2];
105662306a36Sopenharmony_ci	struct scb_data		  scb_data;
105762306a36Sopenharmony_ci
105862306a36Sopenharmony_ci	struct hardware_scb	 *next_queued_hscb;
105962306a36Sopenharmony_ci	struct map_node		 *next_queued_hscb_map;
106062306a36Sopenharmony_ci
106162306a36Sopenharmony_ci	/*
106262306a36Sopenharmony_ci	 * SCBs that have been sent to the controller
106362306a36Sopenharmony_ci	 */
106462306a36Sopenharmony_ci	BSD_LIST_HEAD(, scb)	  pending_scbs;
106562306a36Sopenharmony_ci
106662306a36Sopenharmony_ci	/*
106762306a36Sopenharmony_ci	 * Current register window mode information.
106862306a36Sopenharmony_ci	 */
106962306a36Sopenharmony_ci	ahd_mode		  dst_mode;
107062306a36Sopenharmony_ci	ahd_mode		  src_mode;
107162306a36Sopenharmony_ci
107262306a36Sopenharmony_ci	/*
107362306a36Sopenharmony_ci	 * Saved register window mode information
107462306a36Sopenharmony_ci	 * used for restore on next unpause.
107562306a36Sopenharmony_ci	 */
107662306a36Sopenharmony_ci	ahd_mode		  saved_dst_mode;
107762306a36Sopenharmony_ci	ahd_mode		  saved_src_mode;
107862306a36Sopenharmony_ci
107962306a36Sopenharmony_ci	/*
108062306a36Sopenharmony_ci	 * Platform specific data.
108162306a36Sopenharmony_ci	 */
108262306a36Sopenharmony_ci	struct ahd_platform_data *platform_data;
108362306a36Sopenharmony_ci
108462306a36Sopenharmony_ci	/*
108562306a36Sopenharmony_ci	 * Platform specific device information.
108662306a36Sopenharmony_ci	 */
108762306a36Sopenharmony_ci	ahd_dev_softc_t		  dev_softc;
108862306a36Sopenharmony_ci
108962306a36Sopenharmony_ci	/*
109062306a36Sopenharmony_ci	 * Bus specific device information.
109162306a36Sopenharmony_ci	 */
109262306a36Sopenharmony_ci	ahd_bus_intr_t		  bus_intr;
109362306a36Sopenharmony_ci
109462306a36Sopenharmony_ci	/*
109562306a36Sopenharmony_ci	 * Target mode related state kept on a per enabled lun basis.
109662306a36Sopenharmony_ci	 * Targets that are not enabled will have null entries.
109762306a36Sopenharmony_ci	 * As an initiator, we keep one target entry for our initiator
109862306a36Sopenharmony_ci	 * ID to store our sync/wide transfer settings.
109962306a36Sopenharmony_ci	 */
110062306a36Sopenharmony_ci	struct ahd_tmode_tstate  *enabled_targets[AHD_NUM_TARGETS];
110162306a36Sopenharmony_ci
110262306a36Sopenharmony_ci	/*
110362306a36Sopenharmony_ci	 * The black hole device responsible for handling requests for
110462306a36Sopenharmony_ci	 * disabled luns on enabled targets.
110562306a36Sopenharmony_ci	 */
110662306a36Sopenharmony_ci	struct ahd_tmode_lstate  *black_hole;
110762306a36Sopenharmony_ci
110862306a36Sopenharmony_ci	/*
110962306a36Sopenharmony_ci	 * Device instance currently on the bus awaiting a continue TIO
111062306a36Sopenharmony_ci	 * for a command that was not given the disconnect priveledge.
111162306a36Sopenharmony_ci	 */
111262306a36Sopenharmony_ci	struct ahd_tmode_lstate  *pending_device;
111362306a36Sopenharmony_ci
111462306a36Sopenharmony_ci	/*
111562306a36Sopenharmony_ci	 * Timer handles for timer driven callbacks.
111662306a36Sopenharmony_ci	 */
111762306a36Sopenharmony_ci	struct timer_list	stat_timer;
111862306a36Sopenharmony_ci
111962306a36Sopenharmony_ci	/*
112062306a36Sopenharmony_ci	 * Statistics.
112162306a36Sopenharmony_ci	 */
112262306a36Sopenharmony_ci#define	AHD_STAT_UPDATE_US	250000 /* 250ms */
112362306a36Sopenharmony_ci#define	AHD_STAT_BUCKETS	4
112462306a36Sopenharmony_ci	u_int			  cmdcmplt_bucket;
112562306a36Sopenharmony_ci	uint32_t		  cmdcmplt_counts[AHD_STAT_BUCKETS];
112662306a36Sopenharmony_ci	uint32_t		  cmdcmplt_total;
112762306a36Sopenharmony_ci
112862306a36Sopenharmony_ci	/*
112962306a36Sopenharmony_ci	 * Card characteristics
113062306a36Sopenharmony_ci	 */
113162306a36Sopenharmony_ci	ahd_chip		  chip;
113262306a36Sopenharmony_ci	ahd_feature		  features;
113362306a36Sopenharmony_ci	ahd_bug			  bugs;
113462306a36Sopenharmony_ci	ahd_flag		  flags;
113562306a36Sopenharmony_ci	struct seeprom_config	 *seep_config;
113662306a36Sopenharmony_ci
113762306a36Sopenharmony_ci	/* Command Queues */
113862306a36Sopenharmony_ci	struct ahd_completion	  *qoutfifo;
113962306a36Sopenharmony_ci	uint16_t		  qoutfifonext;
114062306a36Sopenharmony_ci	uint16_t		  qoutfifonext_valid_tag;
114162306a36Sopenharmony_ci	uint16_t		  qinfifonext;
114262306a36Sopenharmony_ci	uint16_t		  qinfifo[AHD_SCB_MAX];
114362306a36Sopenharmony_ci
114462306a36Sopenharmony_ci	/*
114562306a36Sopenharmony_ci	 * Our qfreeze count.  The sequencer compares
114662306a36Sopenharmony_ci	 * this value with its own counter to determine
114762306a36Sopenharmony_ci	 * whether to allow selections to occur.
114862306a36Sopenharmony_ci	 */
114962306a36Sopenharmony_ci	uint16_t		  qfreeze_cnt;
115062306a36Sopenharmony_ci
115162306a36Sopenharmony_ci	/* Values to store in the SEQCTL register for pause and unpause */
115262306a36Sopenharmony_ci	uint8_t			  unpause;
115362306a36Sopenharmony_ci	uint8_t			  pause;
115462306a36Sopenharmony_ci
115562306a36Sopenharmony_ci	/* Critical Section Data */
115662306a36Sopenharmony_ci	struct cs		 *critical_sections;
115762306a36Sopenharmony_ci	u_int			  num_critical_sections;
115862306a36Sopenharmony_ci
115962306a36Sopenharmony_ci	/* Buffer for handling packetized bitbucket. */
116062306a36Sopenharmony_ci	uint8_t			 *overrun_buf;
116162306a36Sopenharmony_ci
116262306a36Sopenharmony_ci	/* Links for chaining softcs */
116362306a36Sopenharmony_ci	TAILQ_ENTRY(ahd_softc)	  links;
116462306a36Sopenharmony_ci
116562306a36Sopenharmony_ci	/* Channel Names ('A', 'B', etc.) */
116662306a36Sopenharmony_ci	char			  channel;
116762306a36Sopenharmony_ci
116862306a36Sopenharmony_ci	/* Initiator Bus ID */
116962306a36Sopenharmony_ci	uint8_t			  our_id;
117062306a36Sopenharmony_ci
117162306a36Sopenharmony_ci	/*
117262306a36Sopenharmony_ci	 * Target incoming command FIFO.
117362306a36Sopenharmony_ci	 */
117462306a36Sopenharmony_ci	struct target_cmd	 *targetcmds;
117562306a36Sopenharmony_ci	uint8_t			  tqinfifonext;
117662306a36Sopenharmony_ci
117762306a36Sopenharmony_ci	/*
117862306a36Sopenharmony_ci	 * Cached version of the hs_mailbox so we can avoid
117962306a36Sopenharmony_ci	 * pausing the sequencer during mailbox updates.
118062306a36Sopenharmony_ci	 */
118162306a36Sopenharmony_ci	uint8_t			  hs_mailbox;
118262306a36Sopenharmony_ci
118362306a36Sopenharmony_ci	/*
118462306a36Sopenharmony_ci	 * Incoming and outgoing message handling.
118562306a36Sopenharmony_ci	 */
118662306a36Sopenharmony_ci	uint8_t			  send_msg_perror;
118762306a36Sopenharmony_ci	ahd_msg_flags		  msg_flags;
118862306a36Sopenharmony_ci	ahd_msg_type		  msg_type;
118962306a36Sopenharmony_ci	uint8_t			  msgout_buf[12];/* Message we are sending */
119062306a36Sopenharmony_ci	uint8_t			  msgin_buf[12];/* Message we are receiving */
119162306a36Sopenharmony_ci	u_int			  msgout_len;	/* Length of message to send */
119262306a36Sopenharmony_ci	u_int			  msgout_index;	/* Current index in msgout */
119362306a36Sopenharmony_ci	u_int			  msgin_index;	/* Current index in msgin */
119462306a36Sopenharmony_ci
119562306a36Sopenharmony_ci	/*
119662306a36Sopenharmony_ci	 * Mapping information for data structures shared
119762306a36Sopenharmony_ci	 * between the sequencer and kernel.
119862306a36Sopenharmony_ci	 */
119962306a36Sopenharmony_ci	bus_dma_tag_t		  parent_dmat;
120062306a36Sopenharmony_ci	bus_dma_tag_t		  shared_data_dmat;
120162306a36Sopenharmony_ci	struct map_node		  shared_data_map;
120262306a36Sopenharmony_ci
120362306a36Sopenharmony_ci	/* Information saved through suspend/resume cycles */
120462306a36Sopenharmony_ci	struct ahd_suspend_state  suspend_state;
120562306a36Sopenharmony_ci
120662306a36Sopenharmony_ci	/* Number of enabled target mode device on this card */
120762306a36Sopenharmony_ci	u_int			  enabled_luns;
120862306a36Sopenharmony_ci
120962306a36Sopenharmony_ci	/* Initialization level of this data structure */
121062306a36Sopenharmony_ci	u_int			  init_level;
121162306a36Sopenharmony_ci
121262306a36Sopenharmony_ci	/* PCI cacheline size. */
121362306a36Sopenharmony_ci	u_int			  pci_cachesize;
121462306a36Sopenharmony_ci
121562306a36Sopenharmony_ci	/* IO Cell Parameters */
121662306a36Sopenharmony_ci	uint8_t			  iocell_opts[AHD_NUM_PER_DEV_ANNEXCOLS];
121762306a36Sopenharmony_ci
121862306a36Sopenharmony_ci	u_int			  stack_size;
121962306a36Sopenharmony_ci	uint16_t		 *saved_stack;
122062306a36Sopenharmony_ci
122162306a36Sopenharmony_ci	/* Per-Unit descriptive information */
122262306a36Sopenharmony_ci	const char		 *description;
122362306a36Sopenharmony_ci	const char		 *bus_description;
122462306a36Sopenharmony_ci	char			 *name;
122562306a36Sopenharmony_ci	int			  unit;
122662306a36Sopenharmony_ci
122762306a36Sopenharmony_ci	/* Selection Timer settings */
122862306a36Sopenharmony_ci	int			  seltime;
122962306a36Sopenharmony_ci
123062306a36Sopenharmony_ci	/*
123162306a36Sopenharmony_ci	 * Interrupt coalescing settings.
123262306a36Sopenharmony_ci	 */
123362306a36Sopenharmony_ci#define	AHD_INT_COALESCING_TIMER_DEFAULT		250 /*us*/
123462306a36Sopenharmony_ci#define	AHD_INT_COALESCING_MAXCMDS_DEFAULT		10
123562306a36Sopenharmony_ci#define	AHD_INT_COALESCING_MAXCMDS_MAX			127
123662306a36Sopenharmony_ci#define	AHD_INT_COALESCING_MINCMDS_DEFAULT		5
123762306a36Sopenharmony_ci#define	AHD_INT_COALESCING_MINCMDS_MAX			127
123862306a36Sopenharmony_ci#define	AHD_INT_COALESCING_THRESHOLD_DEFAULT		2000
123962306a36Sopenharmony_ci#define	AHD_INT_COALESCING_STOP_THRESHOLD_DEFAULT	1000
124062306a36Sopenharmony_ci	u_int			  int_coalescing_timer;
124162306a36Sopenharmony_ci	u_int			  int_coalescing_maxcmds;
124262306a36Sopenharmony_ci	u_int			  int_coalescing_mincmds;
124362306a36Sopenharmony_ci	u_int			  int_coalescing_threshold;
124462306a36Sopenharmony_ci	u_int			  int_coalescing_stop_threshold;
124562306a36Sopenharmony_ci
124662306a36Sopenharmony_ci	uint16_t		  user_discenable;/* Disconnection allowed  */
124762306a36Sopenharmony_ci	uint16_t		  user_tagenable;/* Tagged Queuing allowed */
124862306a36Sopenharmony_ci};
124962306a36Sopenharmony_ci
125062306a36Sopenharmony_ci/*************************** IO Cell Configuration ****************************/
125162306a36Sopenharmony_ci#define	AHD_PRECOMP_SLEW_INDEX						\
125262306a36Sopenharmony_ci    (AHD_ANNEXCOL_PRECOMP_SLEW - AHD_ANNEXCOL_PER_DEV0)
125362306a36Sopenharmony_ci
125462306a36Sopenharmony_ci#define	AHD_AMPLITUDE_INDEX						\
125562306a36Sopenharmony_ci    (AHD_ANNEXCOL_AMPLITUDE - AHD_ANNEXCOL_PER_DEV0)
125662306a36Sopenharmony_ci
125762306a36Sopenharmony_ci#define AHD_SET_SLEWRATE(ahd, new_slew)					\
125862306a36Sopenharmony_cido {									\
125962306a36Sopenharmony_ci    (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_SLEWRATE_MASK;	\
126062306a36Sopenharmony_ci    (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] |=			\
126162306a36Sopenharmony_ci	(((new_slew) << AHD_SLEWRATE_SHIFT) & AHD_SLEWRATE_MASK);	\
126262306a36Sopenharmony_ci} while (0)
126362306a36Sopenharmony_ci
126462306a36Sopenharmony_ci#define AHD_SET_PRECOMP(ahd, new_pcomp)					\
126562306a36Sopenharmony_cido {									\
126662306a36Sopenharmony_ci    (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] &= ~AHD_PRECOMP_MASK;	\
126762306a36Sopenharmony_ci    (ahd)->iocell_opts[AHD_PRECOMP_SLEW_INDEX] |=			\
126862306a36Sopenharmony_ci	(((new_pcomp) << AHD_PRECOMP_SHIFT) & AHD_PRECOMP_MASK);	\
126962306a36Sopenharmony_ci} while (0)
127062306a36Sopenharmony_ci
127162306a36Sopenharmony_ci#define AHD_SET_AMPLITUDE(ahd, new_amp)					\
127262306a36Sopenharmony_cido {									\
127362306a36Sopenharmony_ci    (ahd)->iocell_opts[AHD_AMPLITUDE_INDEX] &= ~AHD_AMPLITUDE_MASK;	\
127462306a36Sopenharmony_ci    (ahd)->iocell_opts[AHD_AMPLITUDE_INDEX] |=				\
127562306a36Sopenharmony_ci	(((new_amp) << AHD_AMPLITUDE_SHIFT) & AHD_AMPLITUDE_MASK);	\
127662306a36Sopenharmony_ci} while (0)
127762306a36Sopenharmony_ci
127862306a36Sopenharmony_ci/************************ Active Device Information ***************************/
127962306a36Sopenharmony_citypedef enum {
128062306a36Sopenharmony_ci	ROLE_UNKNOWN,
128162306a36Sopenharmony_ci	ROLE_INITIATOR,
128262306a36Sopenharmony_ci	ROLE_TARGET
128362306a36Sopenharmony_ci} role_t;
128462306a36Sopenharmony_ci
128562306a36Sopenharmony_cistruct ahd_devinfo {
128662306a36Sopenharmony_ci	int	 our_scsiid;
128762306a36Sopenharmony_ci	int	 target_offset;
128862306a36Sopenharmony_ci	uint16_t target_mask;
128962306a36Sopenharmony_ci	u_int	 target;
129062306a36Sopenharmony_ci	u_int	 lun;
129162306a36Sopenharmony_ci	char	 channel;
129262306a36Sopenharmony_ci	role_t	 role;		/*
129362306a36Sopenharmony_ci				 * Only guaranteed to be correct if not
129462306a36Sopenharmony_ci				 * in the busfree state.
129562306a36Sopenharmony_ci				 */
129662306a36Sopenharmony_ci};
129762306a36Sopenharmony_ci
129862306a36Sopenharmony_ci/****************************** PCI Structures ********************************/
129962306a36Sopenharmony_ci#define AHD_PCI_IOADDR0	PCIR_BAR(0)	/* I/O BAR*/
130062306a36Sopenharmony_ci#define AHD_PCI_MEMADDR	PCIR_BAR(1)	/* Memory BAR */
130162306a36Sopenharmony_ci#define AHD_PCI_IOADDR1	PCIR_BAR(3)	/* Second I/O BAR */
130262306a36Sopenharmony_ci
130362306a36Sopenharmony_citypedef int (ahd_device_setup_t)(struct ahd_softc *);
130462306a36Sopenharmony_ci
130562306a36Sopenharmony_cistruct ahd_pci_identity {
130662306a36Sopenharmony_ci	uint64_t		 full_id;
130762306a36Sopenharmony_ci	uint64_t		 id_mask;
130862306a36Sopenharmony_ci	const char		*name;
130962306a36Sopenharmony_ci	ahd_device_setup_t	*setup;
131062306a36Sopenharmony_ci};
131162306a36Sopenharmony_ci
131262306a36Sopenharmony_ci/***************************** VL/EISA Declarations ***************************/
131362306a36Sopenharmony_cistruct aic7770_identity {
131462306a36Sopenharmony_ci	uint32_t		 full_id;
131562306a36Sopenharmony_ci	uint32_t		 id_mask;
131662306a36Sopenharmony_ci	const char		*name;
131762306a36Sopenharmony_ci	ahd_device_setup_t	*setup;
131862306a36Sopenharmony_ci};
131962306a36Sopenharmony_ciextern struct aic7770_identity aic7770_ident_table [];
132062306a36Sopenharmony_ciextern const int ahd_num_aic7770_devs;
132162306a36Sopenharmony_ci
132262306a36Sopenharmony_ci#define AHD_EISA_SLOT_OFFSET	0xc00
132362306a36Sopenharmony_ci#define AHD_EISA_IOSIZE		0x100
132462306a36Sopenharmony_ci
132562306a36Sopenharmony_ci/*************************** Function Declarations ****************************/
132662306a36Sopenharmony_ci/******************************************************************************/
132762306a36Sopenharmony_ci
132862306a36Sopenharmony_ci/***************************** PCI Front End *********************************/
132962306a36Sopenharmony_ciconst struct	ahd_pci_identity *ahd_find_pci_device(ahd_dev_softc_t);
133062306a36Sopenharmony_ciint			  ahd_pci_config(struct ahd_softc *,
133162306a36Sopenharmony_ci					 const struct ahd_pci_identity *);
133262306a36Sopenharmony_ciint	ahd_pci_test_register_access(struct ahd_softc *);
133362306a36Sopenharmony_civoid __maybe_unused	ahd_pci_suspend(struct ahd_softc *);
133462306a36Sopenharmony_civoid __maybe_unused	ahd_pci_resume(struct ahd_softc *);
133562306a36Sopenharmony_ci
133662306a36Sopenharmony_ci/************************** SCB and SCB queue management **********************/
133762306a36Sopenharmony_civoid		ahd_qinfifo_requeue_tail(struct ahd_softc *ahd,
133862306a36Sopenharmony_ci					 struct scb *scb);
133962306a36Sopenharmony_ci
134062306a36Sopenharmony_ci/****************************** Initialization ********************************/
134162306a36Sopenharmony_cistruct ahd_softc	*ahd_alloc(void *platform_arg, char *name);
134262306a36Sopenharmony_ciint			 ahd_softc_init(struct ahd_softc *);
134362306a36Sopenharmony_civoid			 ahd_controller_info(struct ahd_softc *ahd, char *buf);
134462306a36Sopenharmony_ciint			 ahd_init(struct ahd_softc *ahd);
134562306a36Sopenharmony_ciint __maybe_unused	 ahd_suspend(struct ahd_softc *ahd);
134662306a36Sopenharmony_civoid __maybe_unused	 ahd_resume(struct ahd_softc *ahd);
134762306a36Sopenharmony_ciint			 ahd_default_config(struct ahd_softc *ahd);
134862306a36Sopenharmony_ciint			 ahd_parse_vpddata(struct ahd_softc *ahd,
134962306a36Sopenharmony_ci					   struct vpd_config *vpd);
135062306a36Sopenharmony_ciint			 ahd_parse_cfgdata(struct ahd_softc *ahd,
135162306a36Sopenharmony_ci					   struct seeprom_config *sc);
135262306a36Sopenharmony_civoid			 ahd_intr_enable(struct ahd_softc *ahd, int enable);
135362306a36Sopenharmony_civoid			 ahd_pause_and_flushwork(struct ahd_softc *ahd);
135462306a36Sopenharmony_civoid			 ahd_set_unit(struct ahd_softc *, int);
135562306a36Sopenharmony_civoid			 ahd_set_name(struct ahd_softc *, char *);
135662306a36Sopenharmony_cistruct scb		*ahd_get_scb(struct ahd_softc *ahd, u_int col_idx);
135762306a36Sopenharmony_civoid			 ahd_free_scb(struct ahd_softc *ahd, struct scb *scb);
135862306a36Sopenharmony_civoid			 ahd_free(struct ahd_softc *ahd);
135962306a36Sopenharmony_ciint			 ahd_reset(struct ahd_softc *ahd, int reinit);
136062306a36Sopenharmony_ciint			 ahd_write_flexport(struct ahd_softc *ahd,
136162306a36Sopenharmony_ci					    u_int addr, u_int value);
136262306a36Sopenharmony_ciint			 ahd_read_flexport(struct ahd_softc *ahd, u_int addr,
136362306a36Sopenharmony_ci					   uint8_t *value);
136462306a36Sopenharmony_ci
136562306a36Sopenharmony_ci/***************************** Error Recovery *********************************/
136662306a36Sopenharmony_citypedef enum {
136762306a36Sopenharmony_ci	SEARCH_COMPLETE,
136862306a36Sopenharmony_ci	SEARCH_COUNT,
136962306a36Sopenharmony_ci	SEARCH_REMOVE,
137062306a36Sopenharmony_ci	SEARCH_PRINT
137162306a36Sopenharmony_ci} ahd_search_action;
137262306a36Sopenharmony_ciint			ahd_search_qinfifo(struct ahd_softc *ahd, int target,
137362306a36Sopenharmony_ci					   char channel, int lun, u_int tag,
137462306a36Sopenharmony_ci					   role_t role, uint32_t status,
137562306a36Sopenharmony_ci					   ahd_search_action action);
137662306a36Sopenharmony_ciint			ahd_search_disc_list(struct ahd_softc *ahd, int target,
137762306a36Sopenharmony_ci					     char channel, int lun, u_int tag,
137862306a36Sopenharmony_ci					     int stop_on_first, int remove,
137962306a36Sopenharmony_ci					     int save_state);
138062306a36Sopenharmony_ciint			ahd_reset_channel(struct ahd_softc *ahd, char channel,
138162306a36Sopenharmony_ci					  int initiate_reset);
138262306a36Sopenharmony_ci/*************************** Utility Functions ********************************/
138362306a36Sopenharmony_civoid			ahd_compile_devinfo(struct ahd_devinfo *devinfo,
138462306a36Sopenharmony_ci					    u_int our_id, u_int target,
138562306a36Sopenharmony_ci					    u_int lun, char channel,
138662306a36Sopenharmony_ci					    role_t role);
138762306a36Sopenharmony_ci/************************** Transfer Negotiation ******************************/
138862306a36Sopenharmony_civoid			ahd_find_syncrate(struct ahd_softc *ahd, u_int *period,
138962306a36Sopenharmony_ci					  u_int *ppr_options, u_int maxsync);
139062306a36Sopenharmony_ci/*
139162306a36Sopenharmony_ci * Negotiation types.  These are used to qualify if we should renegotiate
139262306a36Sopenharmony_ci * even if our goal and current transport parameters are identical.
139362306a36Sopenharmony_ci */
139462306a36Sopenharmony_citypedef enum {
139562306a36Sopenharmony_ci	AHD_NEG_TO_GOAL,	/* Renegotiate only if goal and curr differ. */
139662306a36Sopenharmony_ci	AHD_NEG_IF_NON_ASYNC,	/* Renegotiate so long as goal is non-async. */
139762306a36Sopenharmony_ci	AHD_NEG_ALWAYS		/* Renegotiat even if goal is async. */
139862306a36Sopenharmony_ci} ahd_neg_type;
139962306a36Sopenharmony_ciint			ahd_update_neg_request(struct ahd_softc*,
140062306a36Sopenharmony_ci					       struct ahd_devinfo*,
140162306a36Sopenharmony_ci					       struct ahd_tmode_tstate*,
140262306a36Sopenharmony_ci					       struct ahd_initiator_tinfo*,
140362306a36Sopenharmony_ci					       ahd_neg_type);
140462306a36Sopenharmony_civoid			ahd_set_width(struct ahd_softc *ahd,
140562306a36Sopenharmony_ci				      struct ahd_devinfo *devinfo,
140662306a36Sopenharmony_ci				      u_int width, u_int type, int paused);
140762306a36Sopenharmony_civoid			ahd_set_syncrate(struct ahd_softc *ahd,
140862306a36Sopenharmony_ci					 struct ahd_devinfo *devinfo,
140962306a36Sopenharmony_ci					 u_int period, u_int offset,
141062306a36Sopenharmony_ci					 u_int ppr_options,
141162306a36Sopenharmony_ci					 u_int type, int paused);
141262306a36Sopenharmony_citypedef enum {
141362306a36Sopenharmony_ci	AHD_QUEUE_NONE,
141462306a36Sopenharmony_ci	AHD_QUEUE_BASIC,
141562306a36Sopenharmony_ci	AHD_QUEUE_TAGGED
141662306a36Sopenharmony_ci} ahd_queue_alg;
141762306a36Sopenharmony_ci
141862306a36Sopenharmony_ci/**************************** Target Mode *************************************/
141962306a36Sopenharmony_ci#ifdef AHD_TARGET_MODE
142062306a36Sopenharmony_civoid		ahd_send_lstate_events(struct ahd_softc *,
142162306a36Sopenharmony_ci				       struct ahd_tmode_lstate *);
142262306a36Sopenharmony_civoid		ahd_handle_en_lun(struct ahd_softc *ahd,
142362306a36Sopenharmony_ci				  struct cam_sim *sim, union ccb *ccb);
142462306a36Sopenharmony_cicam_status	ahd_find_tmode_devs(struct ahd_softc *ahd,
142562306a36Sopenharmony_ci				    struct cam_sim *sim, union ccb *ccb,
142662306a36Sopenharmony_ci				    struct ahd_tmode_tstate **tstate,
142762306a36Sopenharmony_ci				    struct ahd_tmode_lstate **lstate,
142862306a36Sopenharmony_ci				    int notfound_failure);
142962306a36Sopenharmony_ci#ifndef AHD_TMODE_ENABLE
143062306a36Sopenharmony_ci#define AHD_TMODE_ENABLE 0
143162306a36Sopenharmony_ci#endif
143262306a36Sopenharmony_ci#endif
143362306a36Sopenharmony_ci/******************************* Debug ***************************************/
143462306a36Sopenharmony_ci#ifdef AHD_DEBUG
143562306a36Sopenharmony_ciextern uint32_t ahd_debug;
143662306a36Sopenharmony_ci#define AHD_SHOW_MISC		0x00001
143762306a36Sopenharmony_ci#define AHD_SHOW_SENSE		0x00002
143862306a36Sopenharmony_ci#define AHD_SHOW_RECOVERY	0x00004
143962306a36Sopenharmony_ci#define AHD_DUMP_SEEPROM	0x00008
144062306a36Sopenharmony_ci#define AHD_SHOW_TERMCTL	0x00010
144162306a36Sopenharmony_ci#define AHD_SHOW_MEMORY		0x00020
144262306a36Sopenharmony_ci#define AHD_SHOW_MESSAGES	0x00040
144362306a36Sopenharmony_ci#define AHD_SHOW_MODEPTR	0x00080
144462306a36Sopenharmony_ci#define AHD_SHOW_SELTO		0x00100
144562306a36Sopenharmony_ci#define AHD_SHOW_FIFOS		0x00200
144662306a36Sopenharmony_ci#define AHD_SHOW_QFULL		0x00400
144762306a36Sopenharmony_ci#define	AHD_SHOW_DV		0x00800
144862306a36Sopenharmony_ci#define AHD_SHOW_MASKED_ERRORS	0x01000
144962306a36Sopenharmony_ci#define AHD_SHOW_QUEUE		0x02000
145062306a36Sopenharmony_ci#define AHD_SHOW_TQIN		0x04000
145162306a36Sopenharmony_ci#define AHD_SHOW_SG		0x08000
145262306a36Sopenharmony_ci#define AHD_SHOW_INT_COALESCING	0x10000
145362306a36Sopenharmony_ci#define AHD_DEBUG_SEQUENCER	0x20000
145462306a36Sopenharmony_ci#endif
145562306a36Sopenharmony_civoid			ahd_print_devinfo(struct ahd_softc *ahd,
145662306a36Sopenharmony_ci					  struct ahd_devinfo *devinfo);
145762306a36Sopenharmony_civoid			ahd_dump_card_state(struct ahd_softc *ahd);
145862306a36Sopenharmony_ciint			ahd_print_register(const ahd_reg_parse_entry_t *table,
145962306a36Sopenharmony_ci					   u_int num_entries,
146062306a36Sopenharmony_ci					   const char *name,
146162306a36Sopenharmony_ci					   u_int address,
146262306a36Sopenharmony_ci					   u_int value,
146362306a36Sopenharmony_ci					   u_int *cur_column,
146462306a36Sopenharmony_ci					   u_int wrap_point);
146562306a36Sopenharmony_ci#endif /* _AIC79XX_H_ */
1466