ispvar.h revision 160080
150477Speter/* $FreeBSD: head/sys/dev/isp/ispvar.h 160080 2006-07-03 08:24:09Z mjacob $ */
2139749Simp/*-
335388Smjacob * Soft Definitions for for Qlogic ISP SCSI adapters.
435388Smjacob *
5154704Smjacob * Copyright (c) 1997-2006 by Matthew Jacob
635388Smjacob * All rights reserved.
752347Smjacob *
835388Smjacob * Redistribution and use in source and binary forms, with or without
935388Smjacob * modification, are permitted provided that the following conditions
1035388Smjacob * are met:
1135388Smjacob * 1. Redistributions of source code must retain the above copyright
1235388Smjacob *    notice immediately at the beginning of the file, without modification,
1335388Smjacob *    this list of conditions, and the following disclaimer.
1466189Smjacob * 2. The name of the author may not be used to endorse or promote products
1535388Smjacob *    derived from this software without specific prior written permission.
1635388Smjacob *
1735388Smjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1835388Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1935388Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2035388Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
2135388Smjacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2235388Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2335388Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2435388Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2535388Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2635388Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2735388Smjacob * SUCH DAMAGE.
2835388Smjacob */
2935388Smjacob
3035388Smjacob#ifndef	_ISPVAR_H
3135388Smjacob#define	_ISPVAR_H
3235388Smjacob
3344819Smjacob#if defined(__NetBSD__) || defined(__OpenBSD__)
3435388Smjacob#include <dev/ic/ispmbox.h>
3535388Smjacob#endif
3635388Smjacob#ifdef	__FreeBSD__
3735388Smjacob#include <dev/isp/ispmbox.h>
3835388Smjacob#endif
3935388Smjacob#ifdef	__linux__
4042131Smjacob#include "ispmbox.h"
4135388Smjacob#endif
42155704Smjacob#ifdef	__svr4__
43155704Smjacob#include "ispmbox.h"
4453487Smjacob#endif
4535388Smjacob
4664087Smjacob#define	ISP_CORE_VERSION_MAJOR	2
47155704Smjacob#define	ISP_CORE_VERSION_MINOR	11
4839235Sgibbs
4935388Smjacob/*
5043420Smjacob * Vector for bus specific code to provide specific services.
5135388Smjacob */
52155704Smjacobtypedef struct ispsoftc ispsoftc_t;
5335388Smjacobstruct ispmdvec {
5482689Smjacob	int		(*dv_rd_isr)
55155704Smjacob	    (ispsoftc_t *, uint16_t *, uint16_t *, uint16_t *);
56155704Smjacob	uint16_t	(*dv_rd_reg) (ispsoftc_t *, int);
57155704Smjacob	void		(*dv_wr_reg) (ispsoftc_t *, int, uint16_t);
58155704Smjacob	int		(*dv_mbxdma) (ispsoftc_t *);
59155704Smjacob	int		(*dv_dmaset)
60155704Smjacob	    (ispsoftc_t *, XS_T *, ispreq_t *, uint16_t *, uint16_t);
61155704Smjacob	void		(*dv_dmaclr) (ispsoftc_t *, XS_T *, uint16_t);
62155704Smjacob	void		(*dv_reset0) (ispsoftc_t *);
63155704Smjacob	void		(*dv_reset1) (ispsoftc_t *);
64155704Smjacob	void		(*dv_dregs) (ispsoftc_t *, const char *);
65155704Smjacob	uint16_t	*dv_ispfw;	/* ptr to f/w */
66155704Smjacob	uint16_t	dv_conf1;
67155704Smjacob	uint16_t	dv_clock;	/* clock frequency */
6835388Smjacob};
6935388Smjacob
7064087Smjacob/*
7164087Smjacob * Overall parameters
7264087Smjacob */
7382689Smjacob#define	MAX_TARGETS		16
7482689Smjacob#define	MAX_FC_TARG		256
7549909Smjacob#define	ISP_MAX_TARGETS(isp)	(IS_FC(isp)? MAX_FC_TARG : MAX_TARGETS)
7661772Smjacob#define	ISP_MAX_LUNS(isp)	(isp)->isp_maxluns
7749909Smjacob
7882689Smjacob/*
7964087Smjacob * Macros to access ISP registers through bus specific layers-
8064087Smjacob * mostly wrappers to vector through the mdvec structure.
8153487Smjacob */
8282689Smjacob#define	ISP_READ_ISR(isp, isrp, semap, mbox0p)	\
8382689Smjacob	(*(isp)->isp_mdvec->dv_rd_isr)(isp, isrp, semap, mbox0p)
8453487Smjacob
8553487Smjacob#define	ISP_READ(isp, reg)	\
8653487Smjacob	(*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
8753487Smjacob
8853487Smjacob#define	ISP_WRITE(isp, reg, val)	\
8953487Smjacob	(*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
9053487Smjacob
9153487Smjacob#define	ISP_MBOXDMASETUP(isp)	\
9253487Smjacob	(*(isp)->isp_mdvec->dv_mbxdma)((isp))
9353487Smjacob
9453487Smjacob#define	ISP_DMASETUP(isp, xs, req, iptrp, optr)	\
9553487Smjacob	(*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr))
9653487Smjacob
97155704Smjacob#define	ISP_DMAFREE(isp, xs, hndl)		\
98155704Smjacob	if ((isp)->isp_mdvec->dv_dmaclr)	\
9953487Smjacob	    (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (hndl))
10053487Smjacob
10153487Smjacob#define	ISP_RESET0(isp)	\
10253487Smjacob	if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp))
10353487Smjacob#define	ISP_RESET1(isp)	\
10453487Smjacob	if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp))
10564087Smjacob#define	ISP_DUMPREGS(isp, m)	\
10664087Smjacob	if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp),(m))
10753487Smjacob
10853487Smjacob#define	ISP_SETBITS(isp, reg, val)	\
10953487Smjacob (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
11053487Smjacob
11153487Smjacob#define	ISP_CLRBITS(isp, reg, val)	\
11253487Smjacob (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
11353487Smjacob
11464087Smjacob/*
11564087Smjacob * The MEMORYBARRIER macro is defined per platform (to provide synchronization
11664087Smjacob * on Request and Response Queues, Scratch DMA areas, and Registers)
11764087Smjacob *
11864087Smjacob * Defined Memory Barrier Synchronization Types
11964087Smjacob */
12064087Smjacob#define	SYNC_REQUEST	0	/* request queue synchronization */
12164087Smjacob#define	SYNC_RESULT	1	/* result queue synchronization */
12264087Smjacob#define	SYNC_SFORDEV	2	/* scratch, sync for ISP */
12364087Smjacob#define	SYNC_SFORCPU	3	/* scratch, sync for CPU */
12464087Smjacob#define	SYNC_REG	4	/* for registers */
12564087Smjacob
12664087Smjacob/*
12764087Smjacob * Request/Response Queue defines and macros.
12864087Smjacob * The maximum is defined per platform (and can be based on board type).
12964087Smjacob */
13064087Smjacob/* This is the size of a queue entry (request and response) */
13139235Sgibbs#define	QENTRY_LEN			64
13264087Smjacob/* Both request and result queue length must be a power of two */
13364087Smjacob#define	RQUEST_QUEUE_LEN(x)		MAXISPREQUEST(x)
13493706Smjacob#ifdef	ISP_TARGET_MODE
13593706Smjacob#define	RESULT_QUEUE_LEN(x)		MAXISPREQUEST(x)
13693706Smjacob#else
13764087Smjacob#define	RESULT_QUEUE_LEN(x)		\
13864087Smjacob	(((MAXISPREQUEST(x) >> 2) < 64)? 64 : MAXISPREQUEST(x) >> 2)
13993706Smjacob#endif
140155704Smjacob#define	ISP_QUEUE_ENTRY(q, idx)		(((uint8_t *)q) + ((idx) * QENTRY_LEN))
14139235Sgibbs#define	ISP_QUEUE_SIZE(n)		((n) * QENTRY_LEN)
14239235Sgibbs#define	ISP_NXT_QENTRY(idx, qlen)	(((idx) + 1) & ((qlen)-1))
14365140Smjacob#define	ISP_QFREE(in, out, qlen)	\
14439235Sgibbs	((in == out)? (qlen - 1) : ((in > out)? \
14552347Smjacob	((qlen - 1) - (in - out)) : (out - in - 1)))
14665140Smjacob#define	ISP_QAVAIL(isp)	\
14765140Smjacob	ISP_QFREE(isp->isp_reqidx, isp->isp_reqodx, RQUEST_QUEUE_LEN(isp))
14853487Smjacob
14987635Smjacob#define	ISP_ADD_REQUEST(isp, nxti)					\
15087635Smjacob	MEMORYBARRIER(isp, SYNC_REQUEST, isp->isp_reqidx, QENTRY_LEN);	\
15187635Smjacob	WRITE_REQUEST_QUEUE_IN_POINTER(isp, nxti);			\
15287635Smjacob	isp->isp_reqidx = nxti
15353487Smjacob
15435388Smjacob/*
15546968Smjacob * SCSI Specific Host Adapter Parameters- per bus, per target
15635388Smjacob */
15735388Smjacobtypedef struct {
158155704Smjacob	uint32_t	isp_gotdparms		: 1,
15952347Smjacob			isp_req_ack_active_neg	: 1,
16052347Smjacob			isp_data_line_active_neg: 1,
16135388Smjacob			isp_cmd_dma_burst_enable: 1,
16235388Smjacob			isp_data_dma_burst_enabl: 1,
16342461Smjacob			isp_fifo_threshold	: 3,
16443420Smjacob			isp_ultramode		: 1,
16535388Smjacob			isp_diffmode		: 1,
16645040Smjacob			isp_lvdmode		: 1,
16765140Smjacob			isp_fast_mttr		: 1,	/* fast sram */
16835388Smjacob			isp_initiator_id	: 4,
16952347Smjacob			isp_async_data_setup	: 4;
170155704Smjacob	uint16_t	isp_selection_timeout;
171155704Smjacob	uint16_t	isp_max_queue_depth;
172155704Smjacob	uint8_t		isp_tag_aging;
173155704Smjacob	uint8_t		isp_bus_reset_delay;
174155704Smjacob	uint8_t		isp_retry_count;
175155704Smjacob	uint8_t		isp_retry_delay;
17635388Smjacob	struct {
177155704Smjacob		uint32_t
17880582Smjacob			exc_throttle	:	8,
17946968Smjacob					:	1,
18080582Smjacob			dev_enable	:	1,	/* ignored */
18143420Smjacob			dev_update	:	1,
18243420Smjacob			dev_refresh	:	1,
18380582Smjacob			actv_offset	:	4,
18480582Smjacob			goal_offset	:	4,
18580582Smjacob			nvrm_offset	:	4;
186155704Smjacob		uint8_t		actv_period;	/* current sync period */
187155704Smjacob		uint8_t		goal_period;	/* goal sync period */
188155704Smjacob		uint8_t		nvrm_period;	/* nvram sync period */
189155704Smjacob		uint16_t	actv_flags;	/* current device flags */
190155704Smjacob		uint16_t	goal_flags;	/* goal device flags */
191155704Smjacob		uint16_t	nvrm_flags;	/* nvram device flags */
19235388Smjacob	} isp_devparam[MAX_TARGETS];
19346968Smjacob} sdparam;
19435388Smjacob
19535388Smjacob/*
19635388Smjacob * Device Flags
19735388Smjacob */
19839235Sgibbs#define	DPARM_DISC	0x8000
19939235Sgibbs#define	DPARM_PARITY	0x4000
20039235Sgibbs#define	DPARM_WIDE	0x2000
20139235Sgibbs#define	DPARM_SYNC	0x1000
20239235Sgibbs#define	DPARM_TQING	0x0800
20339235Sgibbs#define	DPARM_ARQ	0x0400
20439235Sgibbs#define	DPARM_QFRZ	0x0200
20539235Sgibbs#define	DPARM_RENEG	0x0100
20665140Smjacob#define	DPARM_NARROW	0x0080
20765140Smjacob#define	DPARM_ASYNC	0x0040
20865140Smjacob#define	DPARM_PPR	0x0020
20943793Smjacob#define	DPARM_DEFAULT	(0xFF00 & ~DPARM_QFRZ)
21039235Sgibbs#define	DPARM_SAFE_DFLT	(DPARM_DEFAULT & ~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING))
21135388Smjacob
21245040Smjacob/* technically, not really correct, as they need to be rated based upon clock */
21365140Smjacob#define	ISP_80M_SYNCPARMS	0x0c09
21465140Smjacob#define	ISP_40M_SYNCPARMS	0x0c0a
21565140Smjacob#define	ISP_20M_SYNCPARMS	0x0c0c
21665140Smjacob#define	ISP_20M_SYNCPARMS_1040	0x080c
21752347Smjacob#define	ISP_10M_SYNCPARMS	0x0c19
21852347Smjacob#define	ISP_08M_SYNCPARMS	0x0c25
21952347Smjacob#define	ISP_05M_SYNCPARMS	0x0c32
22052347Smjacob#define	ISP_04M_SYNCPARMS	0x0c41
22135388Smjacob
22235388Smjacob/*
22335388Smjacob * Fibre Channel Specifics
22435388Smjacob */
22552347Smjacob#define	FL_PORT_ID		0x7e	/* FL_Port Special ID */
22652347Smjacob#define	FC_PORT_ID		0x7f	/* Fabric Controller Special ID */
22752347Smjacob#define	FC_SNS_ID		0x80	/* SNS Server Special ID */
22852347Smjacob
22993837Smjacob/* #define	ISP_USE_GA_NXT	1 */	/* Use GA_NXT with switches */
23093837Smjacob#ifndef	GA_NXT_MAX
23193837Smjacob#define	GA_NXT_MAX	256
23293837Smjacob#endif
23393837Smjacob
23435388Smjacobtypedef struct {
235155704Smjacob	uint32_t				: 13,
236154704Smjacob				isp_gbspeed	: 3,
237160080Smjacob						: 1,
23872355Smjacob				isp_iid_set	: 1,
23948484Smjacob				loop_seen_once	: 1,
24077776Smjacob				isp_loopstate	: 4,	/* Current Loop State */
241160080Smjacob				isp_fwstate	: 4,	/* ISP F/W state */
24248484Smjacob				isp_gotdparms	: 1,
24359454Smjacob				isp_topo	: 3,
24448484Smjacob				isp_onfabric	: 1;
245155704Smjacob	uint32_t				: 8,
246154704Smjacob				isp_portid	: 24;	/* S_ID */
247155704Smjacob	uint16_t		isp_fwoptions;
248160080Smjacob	uint16_t		isp_xfwoptions;
249160080Smjacob	uint16_t		isp_zfwoptions;
250155704Smjacob	uint16_t		isp_iid;	/* 'initiator' id */
251155704Smjacob	uint16_t		isp_loopid;	/* hard loop id */
252155704Smjacob	uint16_t		isp_fwattr;	/* firmware attributes */
253158813Smjacob	uint16_t		isp_execthrottle;
254155704Smjacob	uint8_t			isp_retry_delay;
255155704Smjacob	uint8_t			isp_retry_count;
256155704Smjacob	uint8_t			isp_reserved;
257155704Smjacob	uint16_t		isp_maxalloc;
258155704Smjacob	uint16_t		isp_maxfrmlen;
259155704Smjacob	uint64_t		isp_nodewwn;
260155704Smjacob	uint64_t		isp_portwwn;
26135388Smjacob	/*
26248484Smjacob	 * Port Data Base. This is indexed by 'target', which is invariate.
26348484Smjacob	 * However, elements within can move around due to loop changes,
26448484Smjacob	 * so the actual loop ID passed to the F/W is in this structure.
26548484Smjacob	 * The first time the loop is seen up, loopid will match the index
26648484Smjacob	 * (except for fabric nodes which are above mapped above FC_SNS_ID
26748484Smjacob	 * and are completely virtual), but subsequent LIPs can cause things
26848484Smjacob	 * to move around.
26944819Smjacob	 */
27048484Smjacob	struct lportdb {
271155704Smjacob		uint32_t		loopid		: 16,
272154704Smjacob							: 2,
27393837Smjacob					fc4_type	: 4,
27493837Smjacob					last_fabric_dev	: 1,
27598281Smjacob					relogin		: 1,
27677776Smjacob					force_logout	: 1,
27771079Smjacob					was_fabric_dev	: 1,
27871079Smjacob					fabric_dev	: 1,
27960221Smjacob					loggedin	: 1,
28060221Smjacob					roles		: 2,
281154704Smjacob					tvalid		: 1,
28260221Smjacob					valid		: 1;
283155704Smjacob		uint32_t		port_type	: 8,
284154704Smjacob					portid		: 24;
285155704Smjacob		uint64_t		node_wwn;
286155704Smjacob		uint64_t		port_wwn;
28772355Smjacob	} portdb[MAX_FC_TARG], tport[FC_PORT_ID];
28844819Smjacob
28944819Smjacob	/*
29035388Smjacob	 * Scratch DMA mapped in area to fetch Port Database stuff, etc.
29135388Smjacob	 */
292155704Smjacob	void *			isp_scratch;
293155704Smjacob	XS_DMA_ADDR_T		isp_scdma;
29490752Smjacob#ifdef	ISP_FW_CRASH_DUMP
295155704Smjacob	uint16_t *		isp_dump_data;
29690752Smjacob#endif
29735388Smjacob} fcparam;
29835388Smjacob
29948484Smjacob#define	FW_CONFIG_WAIT		0
30048484Smjacob#define	FW_WAIT_AL_PA		1
30148484Smjacob#define	FW_WAIT_LOGIN		2
30248484Smjacob#define	FW_READY		3
30348484Smjacob#define	FW_LOSS_OF_SYNC		4
30448484Smjacob#define	FW_ERROR		5
30548484Smjacob#define	FW_REINIT		6
30648484Smjacob#define	FW_NON_PART		7
30735388Smjacob
30848484Smjacob#define	LOOP_NIL		0
30948484Smjacob#define	LOOP_LIP_RCVD		1
31048484Smjacob#define	LOOP_PDB_RCVD		2
31172355Smjacob#define	LOOP_SCANNING_FABRIC	3
31272355Smjacob#define	LOOP_FSCAN_DONE		4
31372355Smjacob#define	LOOP_SCANNING_LOOP	5
31477776Smjacob#define	LOOP_LSCAN_DONE		6
31577776Smjacob#define	LOOP_SYNCING_PDB	7
31677776Smjacob#define	LOOP_READY		8
31735388Smjacob
31859454Smjacob#define	TOPO_NL_PORT		0
31959454Smjacob#define	TOPO_FL_PORT		1
32059454Smjacob#define	TOPO_N_PORT		2
32159454Smjacob#define	TOPO_F_PORT		3
32259454Smjacob#define	TOPO_PTP_STUB		4
32359454Smjacob
32442131Smjacob/*
32535388Smjacob * Soft Structure per host adapter
32635388Smjacob */
327155704Smjacobstruct ispsoftc {
32835388Smjacob	/*
32935388Smjacob	 * Platform (OS) specific data
33035388Smjacob	 */
33135388Smjacob	struct isposinfo	isp_osinfo;
33235388Smjacob
33335388Smjacob	/*
33453487Smjacob	 * Pointer to bus specific functions and data
33535388Smjacob	 */
33635388Smjacob	struct ispmdvec *	isp_mdvec;
33735388Smjacob
33835388Smjacob	/*
33953487Smjacob	 * (Mostly) nonvolatile state. Board specific parameters
34053487Smjacob	 * may contain some volatile state (e.g., current loop state).
34135388Smjacob	 */
34235388Smjacob
34353487Smjacob	void * 			isp_param;	/* type specific */
344155704Smjacob	uint16_t		isp_fwrev[3];	/* Loaded F/W revision */
345155704Smjacob	uint16_t		isp_romfw_rev[3]; /* PROM F/W revision */
346155704Smjacob	uint16_t		isp_maxcmds;	/* max possible I/O cmds */
347155704Smjacob	uint8_t			isp_type;	/* HBA Chip Type */
348155704Smjacob	uint8_t			isp_revision;	/* HBA Chip H/W Revision */
349155704Smjacob	uint32_t		isp_maxluns;	/* maximum luns supported */
35035388Smjacob
351155704Smjacob	uint32_t		isp_clock	: 8,	/* input clock */
35290224Smjacob						: 4,
35390224Smjacob				isp_port	: 1,	/* 23XX only */
35487635Smjacob				isp_failed	: 1,	/* board failed */
35587635Smjacob				isp_open	: 1,	/* opened (ioctl) */
35653487Smjacob				isp_touched	: 1,	/* board ever seen? */
35753487Smjacob				isp_bustype	: 1,	/* SBus or PCI */
35865140Smjacob				isp_loaded_fw	: 1,	/* loaded firmware */
35987635Smjacob				isp_role	: 2,	/* roles supported */
36071079Smjacob				isp_dblev	: 12;	/* debug log mask */
36171079Smjacob
362155704Smjacob	uint32_t		isp_confopts;		/* config options */
36371079Smjacob
364155704Smjacob	uint16_t		isp_rqstinrp;	/* register for REQINP */
365155704Smjacob	uint16_t		isp_rqstoutrp;	/* register for REQOUTP */
366155704Smjacob	uint16_t		isp_respinrp;	/* register for RESINP */
367155704Smjacob	uint16_t		isp_respoutrp;	/* register for RESOUTP */
36882689Smjacob
36969522Smjacob	/*
37069522Smjacob	 * Instrumentation
37169522Smjacob	 */
372155704Smjacob	uint64_t		isp_intcnt;		/* total int count */
373155704Smjacob	uint64_t		isp_intbogus;		/* spurious int count */
374155704Smjacob	uint64_t		isp_intmboxc;		/* mbox completions */
375155704Smjacob	uint64_t		isp_intoasync;		/* other async */
376155704Smjacob	uint64_t		isp_rsltccmplt;		/* CMDs on result q */
377155704Smjacob	uint64_t		isp_fphccmplt;		/* CMDs via fastpost */
378155704Smjacob	uint16_t		isp_rscchiwater;
379155704Smjacob	uint16_t		isp_fpcchiwater;
38039235Sgibbs
38135388Smjacob	/*
38239235Sgibbs	 * Volatile state
38335388Smjacob	 */
38435388Smjacob
385160080Smjacob	volatile uint32_t	:	8,
38687635Smjacob		isp_mboxbsy	:	1,	/* mailbox command active */
38739235Sgibbs		isp_state	:	3,
38846968Smjacob		isp_sendmarker	:	2,	/* send a marker entry */
38946968Smjacob		isp_update	:	2,	/* update parameters */
39052347Smjacob		isp_nactive	:	16;	/* how many commands active */
391155704Smjacob	volatile uint16_t	isp_reqodx;	/* index of last ISP pickup */
392155704Smjacob	volatile uint16_t	isp_reqidx;	/* index of next request */
393155704Smjacob	volatile uint16_t	isp_residx;	/* index of next result */
394155704Smjacob	volatile uint16_t	isp_resodx;	/* index of next result */
395155704Smjacob	volatile uint16_t	isp_rspbsy;
396155704Smjacob	volatile uint16_t	isp_lasthdls;	/* last handle seed */
397160080Smjacob	volatile uint16_t	isp_obits;	/* mailbox command output */
398155704Smjacob	volatile uint16_t	isp_mboxtmp[MAILBOX_STORAGE];
399155704Smjacob	volatile uint16_t	isp_lastmbxcmd;	/* last mbox command sent */
400155704Smjacob	volatile uint16_t	isp_mbxwrk0;
401155704Smjacob	volatile uint16_t	isp_mbxwrk1;
402155704Smjacob	volatile uint16_t	isp_mbxwrk2;
403160080Smjacob	volatile uint16_t	isp_mbxwrk8;
40490224Smjacob	void *			isp_mbxworkp;
40535388Smjacob
40635388Smjacob	/*
40753487Smjacob	 * Active commands are stored here, indexed by handle functions.
40835388Smjacob	 */
40964087Smjacob	XS_T **isp_xflist;
41035388Smjacob
411129643Snjl#ifdef	ISP_TARGET_MODE
41235388Smjacob	/*
413129643Snjl	 * Active target commands are stored here, indexed by handle function.
414129643Snjl	 */
415129643Snjl	void **isp_tgtlist;
416129643Snjl#endif
417129643Snjl
418129643Snjl	/*
419120018Smjacob	 * request/result queue pointers and DMA handles for them.
42035388Smjacob	 */
421155704Smjacob	void *			isp_rquest;
422155704Smjacob	void *			isp_result;
423155704Smjacob	XS_DMA_ADDR_T		isp_rquest_dma;
424155704Smjacob	XS_DMA_ADDR_T		isp_result_dma;
425155704Smjacob};
42635388Smjacob
42749909Smjacob#define	SDPARAM(isp)	((sdparam *) (isp)->isp_param)
42849909Smjacob#define	FCPARAM(isp)	((fcparam *) (isp)->isp_param)
42949909Smjacob
43035388Smjacob/*
43164087Smjacob * ISP Driver Run States
43235388Smjacob */
43335388Smjacob#define	ISP_NILSTATE	0
434160080Smjacob#define	ISP_CRASHED	1
435160080Smjacob#define	ISP_RESETSTATE	2
436160080Smjacob#define	ISP_INITSTATE	3
437160080Smjacob#define	ISP_RUNSTATE	4
43835388Smjacob
43935388Smjacob/*
44035388Smjacob * ISP Configuration Options
44135388Smjacob */
44235388Smjacob#define	ISP_CFG_NORELOAD	0x80	/* don't download f/w */
44343793Smjacob#define	ISP_CFG_NONVRAM		0x40	/* ignore NVRAM */
44484241Smjacob#define	ISP_CFG_TWOGB		0x20	/* force 2GB connection (23XX only) */
44584241Smjacob#define	ISP_CFG_ONEGB		0x10	/* force 1GB connection (23XX only) */
44653487Smjacob#define	ISP_CFG_FULL_DUPLEX	0x01	/* Full Duplex (Fibre Channel only) */
44769522Smjacob#define	ISP_CFG_PORT_PREF	0x0C	/* Mask for Port Prefs (2200 only) */
44869522Smjacob#define	ISP_CFG_LPORT		0x00	/* prefer {N/F}L-Port connection */
44969522Smjacob#define	ISP_CFG_NPORT		0x04	/* prefer {N/F}-Port connection */
45069522Smjacob#define	ISP_CFG_NPORT_ONLY	0x08	/* insist on {N/F}-Port connection */
45169522Smjacob#define	ISP_CFG_LPORT_ONLY	0x0C	/* insist on {N/F}L-Port connection */
45290752Smjacob#define	ISP_CFG_OWNWWPN		0x100	/* override NVRAM wwpn */
45390752Smjacob#define	ISP_CFG_OWNWWNN		0x200	/* override NVRAM wwnn */
45498281Smjacob#define	ISP_CFG_OWNFSZ		0x400	/* override NVRAM frame size */
45598281Smjacob#define	ISP_CFG_OWNLOOPID	0x800	/* override NVRAM loopid */
45698281Smjacob#define	ISP_CFG_OWNEXCTHROTTLE	0x1000	/* override NVRAM execution throttle */
45735388Smjacob
45864087Smjacob/*
45971079Smjacob * Prior to calling isp_reset for the first time, the outer layer
46071079Smjacob * should set isp_role to one of NONE, INITIATOR, TARGET, BOTH.
46171079Smjacob *
46271079Smjacob * If you set ISP_ROLE_NONE, the cards will be reset, new firmware loaded,
46371079Smjacob * NVRAM read, and defaults set, but any further initialization (e.g.
46471079Smjacob * INITIALIZE CONTROL BLOCK commands for 2X00 cards) won't be done.
46571079Smjacob *
46671079Smjacob * If INITIATOR MODE isn't set, attempts to run commands will be stopped
46771079Smjacob * at isp_start and completed with the moral equivalent of SELECTION TIMEOUT.
46871079Smjacob *
46971079Smjacob * If TARGET MODE is set, it doesn't mean that the rest of target mode support
47071079Smjacob * needs to be enabled, or will even work. What happens with the 2X00 cards
47171079Smjacob * here is that if you have enabled it with TARGET MODE as part of the ICB
47271079Smjacob * options, but you haven't given the f/w any ram resources for ATIOs or
47371079Smjacob * Immediate Notifies, the f/w just handles what it can and you never see
47471079Smjacob * anything. Basically, it sends a single byte of data (the first byte,
47571079Smjacob * which you can set as part of the INITIALIZE CONTROL BLOCK command) for
47671079Smjacob * INQUIRY, and sends back QUEUE FULL status for any other command.
47779235Smjacob *
47871079Smjacob */
47971079Smjacob#define	ISP_ROLE_NONE		0x0
480125544Smjacob#define	ISP_ROLE_TARGET		0x1
481125544Smjacob#define	ISP_ROLE_INITIATOR	0x2
48271079Smjacob#define	ISP_ROLE_BOTH		(ISP_ROLE_TARGET|ISP_ROLE_INITIATOR)
48371079Smjacob#define	ISP_ROLE_EITHER		ISP_ROLE_BOTH
48471079Smjacob#ifndef	ISP_DEFAULT_ROLES
48571079Smjacob#define	ISP_DEFAULT_ROLES	ISP_ROLE_INITIATOR
48671079Smjacob#endif
48771079Smjacob
48871079Smjacob
48971079Smjacob/*
49064087Smjacob * Firmware related defines
49164087Smjacob */
49271079Smjacob#define	ISP_CODE_ORG			0x1000	/* default f/w code start */
49382689Smjacob#define	ISP_CODE_ORG_2300		0x0800	/* ..except for 2300s */
49445282Smjacob#define	ISP_FW_REV(maj, min, mic)	((maj << 24) | (min << 16) | mic)
49582841Smjacob#define	ISP_FW_MAJOR(code)		((code >> 24) & 0xff)
49682841Smjacob#define	ISP_FW_MINOR(code)		((code >> 16) & 0xff)
49782841Smjacob#define	ISP_FW_MICRO(code)		((code >>  8) & 0xff)
49871079Smjacob#define	ISP_FW_REVX(xp)			((xp[0]<<24) | (xp[1] << 16) | xp[2])
49982841Smjacob#define	ISP_FW_MAJORX(xp)		(xp[0])
50082841Smjacob#define	ISP_FW_MINORX(xp)		(xp[1])
50182841Smjacob#define	ISP_FW_MICROX(xp)		(xp[2])
502102012Smjacob#define	ISP_FW_NEWER_THAN(i, major, minor, micro)		\
503102012Smjacob (ISP_FW_REVX((i)->isp_fwrev) > ISP_FW_REV(major, minor, micro))
50439235Sgibbs
50535388Smjacob/*
50639235Sgibbs * Bus (implementation) types
50735388Smjacob */
50839235Sgibbs#define	ISP_BT_PCI		0	/* PCI Implementations */
50939235Sgibbs#define	ISP_BT_SBUS		1	/* SBus Implementations */
51039235Sgibbs
51139235Sgibbs/*
51287635Smjacob * If we have not otherwise defined SBus support away make sure
51387635Smjacob * it is defined here such that the code is included as default
51487635Smjacob */
51587635Smjacob#ifndef	ISP_SBUS_SUPPORTED
51687635Smjacob#define	ISP_SBUS_SUPPORTED	1
51787635Smjacob#endif
51887635Smjacob
51987635Smjacob/*
52039235Sgibbs * Chip Types
52139235Sgibbs */
52235388Smjacob#define	ISP_HA_SCSI		0xf
52339235Sgibbs#define	ISP_HA_SCSI_UNKNOWN	0x1
52439235Sgibbs#define	ISP_HA_SCSI_1020	0x2
52539235Sgibbs#define	ISP_HA_SCSI_1020A	0x3
52639235Sgibbs#define	ISP_HA_SCSI_1040	0x4
52739235Sgibbs#define	ISP_HA_SCSI_1040A	0x5
52839235Sgibbs#define	ISP_HA_SCSI_1040B	0x6
52945282Smjacob#define	ISP_HA_SCSI_1040C	0x7
53054671Smjacob#define	ISP_HA_SCSI_1240	0x8
53154671Smjacob#define	ISP_HA_SCSI_1080	0x9
53254671Smjacob#define	ISP_HA_SCSI_1280	0xa
533104916Smjacob#define	ISP_HA_SCSI_10160	0xb
534104916Smjacob#define	ISP_HA_SCSI_12160	0xc
53535388Smjacob#define	ISP_HA_FC		0xf0
53635388Smjacob#define	ISP_HA_FC_2100		0x10
53748484Smjacob#define	ISP_HA_FC_2200		0x20
53877365Smjacob#define	ISP_HA_FC_2300		0x30
53988855Smjacob#define	ISP_HA_FC_2312		0x40
540154704Smjacob#define	ISP_HA_FC_2322		0x50
541154704Smjacob#define	ISP_HA_FC_2400		0x60
542154704Smjacob#define	ISP_HA_FC_2422		0x61
54335388Smjacob
54444819Smjacob#define	IS_SCSI(isp)	(isp->isp_type & ISP_HA_SCSI)
54554671Smjacob#define	IS_1240(isp)	(isp->isp_type == ISP_HA_SCSI_1240)
54644819Smjacob#define	IS_1080(isp)	(isp->isp_type == ISP_HA_SCSI_1080)
54754671Smjacob#define	IS_1280(isp)	(isp->isp_type == ISP_HA_SCSI_1280)
548104916Smjacob#define	IS_10160(isp)	(isp->isp_type == ISP_HA_SCSI_10160)
54957145Smjacob#define	IS_12160(isp)	(isp->isp_type == ISP_HA_SCSI_12160)
55057145Smjacob
55157145Smjacob#define	IS_12X0(isp)	(IS_1240(isp) || IS_1280(isp))
552104916Smjacob#define	IS_1X160(isp)	(IS_10160(isp) || IS_12160(isp))
55357145Smjacob#define	IS_DUALBUS(isp)	(IS_12X0(isp) || IS_12160(isp))
554104916Smjacob#define	IS_ULTRA2(isp)	(IS_1080(isp) || IS_1280(isp) || IS_1X160(isp))
555104916Smjacob#define	IS_ULTRA3(isp)	(IS_1X160(isp))
55657145Smjacob
55777365Smjacob#define	IS_FC(isp)	((isp)->isp_type & ISP_HA_FC)
55877365Smjacob#define	IS_2100(isp)	((isp)->isp_type == ISP_HA_FC_2100)
55977365Smjacob#define	IS_2200(isp)	((isp)->isp_type == ISP_HA_FC_2200)
56088855Smjacob#define	IS_23XX(isp)	((isp)->isp_type >= ISP_HA_FC_2300)
56188855Smjacob#define	IS_2300(isp)	((isp)->isp_type == ISP_HA_FC_2300)
56288855Smjacob#define	IS_2312(isp)	((isp)->isp_type == ISP_HA_FC_2312)
563154704Smjacob#define	IS_2322(isp)	((isp)->isp_type == ISP_HA_FC_2322)
564154704Smjacob#define	IS_24XX(isp)	((isp)->isp_type >= ISP_HA_FC_2400)
56544819Smjacob
56664087Smjacob/*
567155704Smjacob * DMA related macros
56864087Smjacob */
569155704Smjacob#define	DMA_WD3(x)	((((uint64_t)x) >> 48) & 0xffff)
570155704Smjacob#define	DMA_WD2(x)	((((uint64_t)x) >> 32) & 0xffff)
57182689Smjacob#define	DMA_WD1(x)	(((x) >> 16) & 0xffff)
57282689Smjacob#define	DMA_WD0(x)	(((x) & 0xffff))
57357145Smjacob
574155704Smjacob#define	DMA_LO32(x)	((uint32_t) (x))
575155704Smjacob#define	DMA_HI32(x)	((uint32_t)(((uint64_t)x) >> 32))
576155704Smjacob
57735388Smjacob/*
57864087Smjacob * Core System Function Prototypes
57935388Smjacob */
58035388Smjacob
58135388Smjacob/*
58239235Sgibbs * Reset Hardware. Totally. Assumes that you'll follow this with
58339235Sgibbs * a call to isp_init.
58435388Smjacob */
585155704Smjacobvoid isp_reset(ispsoftc_t *);
58635388Smjacob
58735388Smjacob/*
58835388Smjacob * Initialize Hardware to known state
58935388Smjacob */
590155704Smjacobvoid isp_init(ispsoftc_t *);
59135388Smjacob
59235388Smjacob/*
59339235Sgibbs * Reset the ISP and call completion for any orphaned commands.
59439235Sgibbs */
595155704Smjacobvoid isp_reinit(ispsoftc_t *);
59639235Sgibbs
59790752Smjacob#ifdef	ISP_FW_CRASH_DUMP
59839235Sgibbs/*
59990752Smjacob * Dump firmware entry point.
60090752Smjacob */
601155704Smjacobvoid isp_fw_dump(ispsoftc_t *isp);
60290752Smjacob#endif
60390752Smjacob
60490752Smjacob/*
60582689Smjacob * Internal Interrupt Service Routine
60682689Smjacob *
60782689Smjacob * The outer layers do the spade work to get the appropriate status register,
60882689Smjacob * semaphore register and first mailbox register (if appropriate). This also
60982689Smjacob * means that most spurious/bogus interrupts not for us can be filtered first.
61035388Smjacob */
611155704Smjacobvoid isp_intr(ispsoftc_t *, uint16_t, uint16_t, uint16_t);
61235388Smjacob
61382689Smjacob
61435388Smjacob/*
61564087Smjacob * Command Entry Point- Platform Dependent layers call into this
61635388Smjacob */
61774229Smjacobint isp_start(XS_T *);
618155704Smjacob
61964087Smjacob/* these values are what isp_start returns */
62064087Smjacob#define	CMD_COMPLETE	101	/* command completed */
62164087Smjacob#define	CMD_EAGAIN	102	/* busy- maybe retry later */
62264087Smjacob#define	CMD_QUEUED	103	/* command has been queued for execution */
62364087Smjacob#define	CMD_RQLATER 	104	/* requeue this command later */
62435388Smjacob
62539235Sgibbs/*
62664087Smjacob * Command Completion Point- Core layers call out from this with completed cmds
62764087Smjacob */
62874229Smjacobvoid isp_done(XS_T *);
62964087Smjacob
63064087Smjacob/*
63143420Smjacob * Platform Dependent to External to Internal Control Function
63239235Sgibbs *
63372355Smjacob * Assumes locks are held on entry. You should note that with many of
63472355Smjacob * these commands and locks may be released while this is occurring.
63539235Sgibbs *
63672355Smjacob * A few notes about some of these functions:
63772355Smjacob *
63872355Smjacob * ISPCTL_FCLINK_TEST tests to make sure we have good fibre channel link.
63972355Smjacob * The argument is a pointer to an integer which is the time, in microseconds,
64072355Smjacob * we should wait to see whether we have good link. This test, if successful,
64172355Smjacob * lets us know our connection topology and our Loop ID/AL_PA and so on.
64272355Smjacob * You can't get anywhere without this.
64372355Smjacob *
64472355Smjacob * ISPCTL_SCAN_FABRIC queries the name server (if we're on a fabric) for
64572355Smjacob * all entities using the FC Generic Services subcommand GET ALL NEXT.
64672355Smjacob * For each found entity, an ISPASYNC_FABRICDEV event is generated (see
64772355Smjacob * below).
64872355Smjacob *
64972355Smjacob * ISPCTL_SCAN_LOOP does a local loop scan. This is only done if the connection
65072355Smjacob * topology is NL or FL port (private or public loop). Since the Qlogic f/w
65172355Smjacob * 'automatically' manages local loop connections, this function essentially
65272355Smjacob * notes the arrival, departure, and possible shuffling around of local loop
65372355Smjacob * entities. Thus for each arrival and departure this generates an isp_async
65472355Smjacob * event of ISPASYNC_PROMENADE (see below).
65572355Smjacob *
65672355Smjacob * ISPCTL_PDB_SYNC is somewhat misnamed. It actually is the final step, in
65772355Smjacob * order, of ISPCTL_FCLINK_TEST, ISPCTL_SCAN_FABRIC, and ISPCTL_SCAN_LOOP.
65872355Smjacob * The main purpose of ISPCTL_PDB_SYNC is to complete management of logging
65972355Smjacob * and logging out of fabric devices (if one is on a fabric) and then marking
66072355Smjacob * the 'loop state' as being ready to now be used for sending commands to
66172355Smjacob * devices. Originally fabric name server and local loop scanning were
66281794Smjacob * part of this function. It's now been separated to allow for finer control.
66339235Sgibbs */
66439235Sgibbstypedef enum {
66548484Smjacob	ISPCTL_RESET_BUS,		/* Reset Bus */
66648484Smjacob	ISPCTL_RESET_DEV,		/* Reset Device */
66748484Smjacob	ISPCTL_ABORT_CMD,		/* Abort Command */
66872355Smjacob	ISPCTL_UPDATE_PARAMS,		/* Update Operating Parameters (SCSI) */
66955364Smjacob	ISPCTL_FCLINK_TEST,		/* Test FC Link Status */
67072355Smjacob	ISPCTL_SCAN_FABRIC,		/* (Re)scan Fabric Name Server */
67172355Smjacob	ISPCTL_SCAN_LOOP,		/* (Re)scan Local Loop */
67255364Smjacob	ISPCTL_PDB_SYNC,		/* Synchronize Port Database */
67372355Smjacob	ISPCTL_SEND_LIP,		/* Send a LIP */
67472355Smjacob	ISPCTL_GET_POSMAP,		/* Get FC-AL position map */
67572938Smjacob	ISPCTL_RUN_MBOXCMD,		/* run a mailbox command */
676125544Smjacob	ISPCTL_TOGGLE_TMODE,		/* toggle target mode */
677125544Smjacob	ISPCTL_GET_PDB			/* get a single port database entry */
67839235Sgibbs} ispctl_t;
679155704Smjacobint isp_control(ispsoftc_t *, ispctl_t, void *);
68039235Sgibbs
68143420Smjacob
68239235Sgibbs/*
68343420Smjacob * Platform Dependent to Internal to External Control Function
68443420Smjacob * (each platform must provide such a function)
68543420Smjacob *
68672355Smjacob * Assumes locks are held.
68772355Smjacob *
68872355Smjacob * A few notes about some of these functions:
68972355Smjacob *
69072355Smjacob * ISPASYNC_CHANGE_NOTIFY notifies the outer layer that a change has
69172355Smjacob * occurred that invalidates the list of fabric devices known and/or
69272355Smjacob * the list of known loop devices. The argument passed is a pointer
69372355Smjacob * whose values are defined below  (local loop change, name server
69472355Smjacob * change, other). 'Other' may simply be a LIP, or a change in
69572355Smjacob * connection topology.
69672355Smjacob *
69772355Smjacob * ISPASYNC_FABRIC_DEV announces the next element in a list of
69872355Smjacob * fabric device names we're getting out of the name server. The
69972355Smjacob * argument points to a GET ALL NEXT response structure. The list
70072355Smjacob * is known to terminate with an entry that refers to ourselves.
70172355Smjacob * One of the main purposes of this function is to allow outer
70272355Smjacob * layers, which are OS dependent, to set policy as to which fabric
70372355Smjacob * devices might actually be logged into (and made visible) later
70472355Smjacob * at ISPCTL_PDB_SYNC time. Since there's a finite number of fabric
70572355Smjacob * devices that we can log into (256 less 3 'reserved' for F-port
70672355Smjacob * topologies), and fabrics can grow up to 8 million or so entries
70772355Smjacob * (24 bits of Port Address, less a wad of reserved spaces), clearly
70872355Smjacob * we had better let the OS determine login policy.
70972355Smjacob *
71072355Smjacob * ISPASYNC_PROMENADE has an argument that is a pointer to an integer which
711103826Smjacob * is an index into the portdb in the softc ('target'). Whether that entry's
71272355Smjacob * valid tag is set or not says whether something has arrived or departed.
71372355Smjacob * The name refers to a favorite pastime of many city dwellers- watching
71472355Smjacob * people come and go, talking of Michaelangelo, and so on..
71572938Smjacob *
71672938Smjacob * ISPASYNC_UNHANDLED_RESPONSE gives outer layers a chance to parse a
71772938Smjacob * response queue entry not otherwise handled. The outer layer should
71887635Smjacob * return non-zero if it handled it. The 'arg' points to an unmassaged
71987635Smjacob * response queue entry.
72043420Smjacob */
72143420Smjacob
72243420Smjacobtypedef enum {
72372355Smjacob	ISPASYNC_NEW_TGT_PARAMS,	/* New Target Parameters Negotiated */
72448484Smjacob	ISPASYNC_BUS_RESET,		/* Bus Was Reset */
72548484Smjacob	ISPASYNC_LOOP_DOWN,		/* FC Loop Down */
72648484Smjacob	ISPASYNC_LOOP_UP,		/* FC Loop Up */
72777365Smjacob	ISPASYNC_LIP,			/* LIP Received */
72877365Smjacob	ISPASYNC_LOOP_RESET,		/* Loop Reset Received */
72972355Smjacob	ISPASYNC_CHANGE_NOTIFY,		/* FC Change Notification */
73072355Smjacob	ISPASYNC_FABRIC_DEV,		/* FC Fabric Device Arrival */
73172355Smjacob	ISPASYNC_PROMENADE,		/* FC Objects coming && going */
732154704Smjacob	ISPASYNC_TARGET_NOTIFY,		/* target asynchronous notification event */
733154704Smjacob	ISPASYNC_TARGET_ACTION,		/* target action requested */
73472938Smjacob	ISPASYNC_CONF_CHANGE,		/* Platform Configuration Change */
73579235Smjacob	ISPASYNC_UNHANDLED_RESPONSE,	/* Unhandled Response Entry */
73698281Smjacob	ISPASYNC_FW_CRASH,		/* Firmware has crashed */
737102012Smjacob	ISPASYNC_FW_DUMPED,		/* Firmware crashdump taken */
73898281Smjacob	ISPASYNC_FW_RESTARTED		/* Firmware has been restarted */
73943420Smjacob} ispasync_t;
740155704Smjacobint isp_async(ispsoftc_t *, ispasync_t, void *);
74143420Smjacob
74272355Smjacob#define	ISPASYNC_CHANGE_PDB	((void *) 0)
74372355Smjacob#define	ISPASYNC_CHANGE_SNS	((void *) 1)
74472355Smjacob#define	ISPASYNC_CHANGE_OTHER	((void *) 2)
74572355Smjacob
74643420Smjacob/*
74764087Smjacob * Platform Dependent Error and Debug Printout
748146073Smjacob *
749146073Smjacob * Generally this is:
750146073Smjacob *
751155704Smjacob *    void isp_prt(ispsoftc_t *, int level, const char *, ...)
752146073Smjacob *
753146073Smjacob * but due to compiler differences on different platforms this won't be
754146073Smjacob * formally done here. Instead, it goes in each platform definition file.
75539235Sgibbs */
75670490Smjacob
75764087Smjacob#define	ISP_LOGALL	0x0	/* log always */
75864087Smjacob#define	ISP_LOGCONFIG	0x1	/* log configuration messages */
75964087Smjacob#define	ISP_LOGINFO	0x2	/* log informational messages */
76064087Smjacob#define	ISP_LOGWARN	0x4	/* log warning messages */
76164087Smjacob#define	ISP_LOGERR	0x8	/* log error messages */
76264087Smjacob#define	ISP_LOGDEBUG0	0x10	/* log simple debug messages */
76364087Smjacob#define	ISP_LOGDEBUG1	0x20	/* log intermediate debug messages */
76464087Smjacob#define	ISP_LOGDEBUG2	0x40	/* log most debug messages */
76579235Smjacob#define	ISP_LOGDEBUG3	0x80	/* log high frequency debug messages */
76679235Smjacob#define	ISP_LOGDEBUG4	0x100	/* log high frequency debug messages */
76764087Smjacob#define	ISP_LOGTDEBUG0	0x200	/* log simple debug messages (target mode) */
76864087Smjacob#define	ISP_LOGTDEBUG1	0x400	/* log intermediate debug messages (target) */
76964087Smjacob#define	ISP_LOGTDEBUG2	0x800	/* log all debug messages (target) */
77039235Sgibbs
77164087Smjacob/*
77264087Smjacob * Each Platform provides it's own isposinfo substructure of the ispsoftc
77364087Smjacob * defined above.
77464087Smjacob *
77564087Smjacob * Each platform must also provide the following macros/defines:
77664087Smjacob *
77764087Smjacob *
77864087Smjacob *	ISP2100_SCRLEN	-	length for the Fibre Channel scratch DMA area
77964087Smjacob *
78064087Smjacob *	MEMZERO(dst, src)			platform zeroing function
78164087Smjacob *	MEMCPY(dst, src, count)			platform copying function
78264087Smjacob *	SNPRINTF(buf, bufsize, fmt, ...)	snprintf
78364087Smjacob *	USEC_DELAY(usecs)			microsecond spindelay function
78469522Smjacob *	USEC_SLEEP(isp, usecs)			microsecond sleep function
78564087Smjacob *
78664087Smjacob *	NANOTIME_T				nanosecond time type
78764087Smjacob *
78864087Smjacob *	GET_NANOTIME(NANOTIME_T *)		get current nanotime.
78964087Smjacob *
790155704Smjacob *	GET_NANOSEC(NANOTIME_T *)		get uint64_t from NANOTIME_T
79164087Smjacob *
79264087Smjacob *	NANOTIME_SUB(NANOTIME_T *, NANOTIME_T *)
79364087Smjacob *						subtract two NANOTIME_T values
79464087Smjacob *
79564087Smjacob *
796155704Smjacob *	MAXISPREQUEST(ispsoftc_t *)	maximum request queue size
79764087Smjacob *						for this particular board type
79864087Smjacob *
799155704Smjacob *	MEMORYBARRIER(ispsoftc_t *, barrier_type, offset, size)
80064087Smjacob *
80164087Smjacob *		Function/Macro the provides memory synchronization on
80264087Smjacob *		various objects so that the ISP's and the system's view
80364087Smjacob *		of the same object is consistent.
80464087Smjacob *
805155704Smjacob *	MBOX_ACQUIRE(ispsoftc_t *)		acquire lock on mailbox regs
806155704Smjacob *	MBOX_WAIT_COMPLETE(ispsoftc_t *)	wait for mailbox cmd to be done
807155704Smjacob *	MBOX_NOTIFY_COMPLETE(ispsoftc_t *)	notification of mbox cmd donee
808155704Smjacob *	MBOX_RELEASE(ispsoftc_t *)		release lock on mailbox regs
80964087Smjacob *
810155704Smjacob *	FC_SCRATCH_ACQUIRE(ispsoftc_t *)	acquire lock on FC scratch area
811155704Smjacob *	FC_SCRATCH_RELEASE(ispsoftc_t *)	acquire lock on FC scratch area
81272355Smjacob *
81364087Smjacob *	SCSI_GOOD	SCSI 'Good' Status
81464087Smjacob *	SCSI_CHECK	SCSI 'Check Condition' Status
81564087Smjacob *	SCSI_BUSY	SCSI 'Busy' Status
81664087Smjacob *	SCSI_QFULL	SCSI 'Queue Full' Status
81764087Smjacob *
81864087Smjacob *	XS_T		Platform SCSI transaction type (i.e., command for HBA)
819155704Smjacob *	XS_DMA_ADDR_T	Platform PCI DMA Address Type
82064087Smjacob *	XS_ISP(xs)	gets an instance out of an XS_T
82164087Smjacob *	XS_CHANNEL(xs)	gets the channel (bus # for DUALBUS cards) ""
82264087Smjacob *	XS_TGT(xs)	gets the target ""
82364087Smjacob *	XS_LUN(xs)	gets the lun ""
82464087Smjacob *	XS_CDBP(xs)	gets a pointer to the scsi CDB ""
82564087Smjacob *	XS_CDBLEN(xs)	gets the CDB's length ""
82664087Smjacob *	XS_XFRLEN(xs)	gets the associated data transfer length ""
82764087Smjacob *	XS_TIME(xs)	gets the time (in milliseconds) for this command
82864087Smjacob *	XS_RESID(xs)	gets the current residual count
82964087Smjacob *	XS_STSP(xs)	gets a pointer to the SCSI status byte ""
83064087Smjacob *	XS_SNSP(xs)	gets a pointer to the associate sense data
83164087Smjacob *	XS_SNSLEN(xs)	gets the length of sense data storage
83264087Smjacob *	XS_SNSKEY(xs)	dereferences XS_SNSP to get the current stored Sense Key
83364087Smjacob *	XS_TAG_P(xs)	predicate of whether this command should be tagged
83464087Smjacob *	XS_TAG_TYPE(xs)	which type of tag to use
83564087Smjacob *	XS_SETERR(xs)	set error state
83664087Smjacob *
83764087Smjacob *		HBA_NOERROR	command has no erros
83864087Smjacob *		HBA_BOTCH	hba botched something
83964087Smjacob *		HBA_CMDTIMEOUT	command timed out
84064087Smjacob *		HBA_SELTIMEOUT	selection timed out (also port logouts for FC)
84164087Smjacob *		HBA_TGTBSY	target returned a BUSY status
84264087Smjacob *		HBA_BUSRESET	bus reset destroyed command
84364087Smjacob *		HBA_ABORTED	command was aborted (by request)
84464087Smjacob *		HBA_DATAOVR	a data overrun was detected
84564087Smjacob *		HBA_ARQFAIL	Automatic Request Sense failed
84664087Smjacob *
84764087Smjacob *	XS_ERR(xs)	return current error state
84864087Smjacob *	XS_NOERR(xs)	there is no error currently set
84964087Smjacob *	XS_INITERR(xs)	initialize error state
85064087Smjacob *
85164087Smjacob *	XS_SAVE_SENSE(xs, sp)		save sense data
85264087Smjacob *
85364087Smjacob *	XS_SET_STATE_STAT(isp, sp, xs)	platform dependent interpreter of
85464087Smjacob *					response queue entry status bits
85564087Smjacob *
85664087Smjacob *
857155704Smjacob *	DEFAULT_IID(ispsoftc_t *)		Default SCSI initiator ID
858155704Smjacob *	DEFAULT_LOOPID(ispsoftc_t *)	Default FC Loop ID
859155704Smjacob *	DEFAULT_NODEWWN(ispsoftc_t *)	Default Node WWN
860155704Smjacob *	DEFAULT_PORTWWN(ispsoftc_t *)	Default Port WWN
861155704Smjacob *	DEFAULT_FRAMESIZE(ispsoftc_t *)	Default Frame Size
862155704Smjacob *	DEFAULT_EXEC_THROTTLE(ispsoftc_t *) Default Execution Throttle
86367047Smjacob *		These establish reasonable defaults for each platform.
86467047Smjacob * 		These must be available independent of card NVRAM and are
86567047Smjacob *		to be used should NVRAM not be readable.
86664087Smjacob *
867155704Smjacob *	ISP_NODEWWN(ispsoftc_t *)	FC Node WWN to use
868155704Smjacob *	ISP_PORTWWN(ispsoftc_t *)	FC Port WWN to use
86964087Smjacob *
87067047Smjacob *		These are to be used after NVRAM is read. The tags
87167047Smjacob *		in fcparam.isp_{node,port}wwn reflect the values
87267047Smjacob *		read from NVRAM (possibly corrected for card botches).
87367047Smjacob *		Each platform can take that information and override
87467047Smjacob *		it or ignore and return the Node and Port WWNs to be
87567047Smjacob * 		used when sending the Qlogic f/w the Initialization Control
87667047Smjacob *		Block.
87764087Smjacob *
87864087Smjacob *	(XXX these do endian specific transformations- in transition XXX)
87987635Smjacob *
880155704Smjacob *	ISP_IOXPUT_8(ispsoftc_t *, uint8_t srcval, uint8_t *dstptr)
881155704Smjacob *	ISP_IOXPUT_16(ispsoftc_t *, uint16_t srcval, uint16_t *dstptr)
882155704Smjacob *	ISP_IOXPUT_32(ispsoftc_t *, uint32_t srcval, uint32_t *dstptr)
88387635Smjacob *
884155704Smjacob *	ISP_IOXGET_8(ispsoftc_t *, uint8_t *srcptr, uint8_t dstrval)
885155704Smjacob *	ISP_IOXGET_16(ispsoftc_t *, uint16_t *srcptr, uint16_t dstrval)
886155704Smjacob *	ISP_IOXGET_32(ispsoftc_t *, uint32_t *srcptr, uint32_t dstrval)
88787635Smjacob *
888155704Smjacob *	ISP_SWIZZLE_NVRAM_WORD(ispsoftc_t *, uint16_t *)
88964087Smjacob */
89077365Smjacob
89135388Smjacob#endif	/* _ISPVAR_H */
892