ispvar.h revision 64087
150477Speter/* $FreeBSD: head/sys/dev/isp/ispvar.h 64087 2000-08-01 06:10:21Z mjacob $ */
235388Smjacob/*
335388Smjacob * Soft Definitions for for Qlogic ISP SCSI adapters.
435388Smjacob *
548484Smjacob * Copyright (c) 1997, 1998, 1999 by Matthew Jacob
635388Smjacob * NASA/Ames Research Center
735388Smjacob * All rights reserved.
852347Smjacob *
935388Smjacob * Redistribution and use in source and binary forms, with or without
1035388Smjacob * modification, are permitted provided that the following conditions
1135388Smjacob * are met:
1235388Smjacob * 1. Redistributions of source code must retain the above copyright
1335388Smjacob *    notice immediately at the beginning of the file, without modification,
1435388Smjacob *    this list of conditions, and the following disclaimer.
1535388Smjacob * 2. Redistributions in binary form must reproduce the above copyright
1635388Smjacob *    notice, this list of conditions and the following disclaimer in the
1735388Smjacob *    documentation and/or other materials provided with the distribution.
1835388Smjacob * 3. The name of the author may not be used to endorse or promote products
1935388Smjacob *    derived from this software without specific prior written permission.
2035388Smjacob *
2135388Smjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2235388Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2335388Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2435388Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
2535388Smjacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2635388Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2735388Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2835388Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2935388Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3035388Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3135388Smjacob * SUCH DAMAGE.
3235388Smjacob *
3335388Smjacob */
3435388Smjacob
3535388Smjacob#ifndef	_ISPVAR_H
3635388Smjacob#define	_ISPVAR_H
3735388Smjacob
3844819Smjacob#if defined(__NetBSD__) || defined(__OpenBSD__)
3935388Smjacob#include <dev/ic/ispmbox.h>
4053487Smjacob#ifdef	ISP_TARGET_MODE
4153487Smjacob#include <dev/ic/isp_target.h>
4256004Smjacob#include <dev/ic/isp_tpublic.h>
4335388Smjacob#endif
4453487Smjacob#endif
4535388Smjacob#ifdef	__FreeBSD__
4635388Smjacob#include <dev/isp/ispmbox.h>
4753487Smjacob#ifdef	ISP_TARGET_MODE
4853487Smjacob#include <dev/isp/isp_target.h>
4956004Smjacob#include <dev/isp/isp_tpublic.h>
5035388Smjacob#endif
5153487Smjacob#endif
5235388Smjacob#ifdef	__linux__
5342131Smjacob#include "ispmbox.h"
5453487Smjacob#ifdef	ISP_TARGET_MODE
5553487Smjacob#include "isp_target.h"
5656004Smjacob#include "isp_tpublic.h"
5735388Smjacob#endif
5853487Smjacob#endif
5935388Smjacob
6064087Smjacob#define	ISP_CORE_VERSION_MAJOR	2
6164087Smjacob#define	ISP_CORE_VERSION_MINOR	0
6239235Sgibbs
6335388Smjacob/*
6443420Smjacob * Vector for bus specific code to provide specific services.
6535388Smjacob */
6635388Smjacobstruct ispsoftc;
6735388Smjacobstruct ispmdvec {
6835388Smjacob	u_int16_t	(*dv_rd_reg) __P((struct ispsoftc *, int));
6935388Smjacob	void		(*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t));
7035388Smjacob	int		(*dv_mbxdma) __P((struct ispsoftc *));
7135388Smjacob	int		(*dv_dmaset) __P((struct ispsoftc *,
7264087Smjacob		XS_T *, ispreq_t *, u_int16_t *, u_int16_t));
7335388Smjacob	void		(*dv_dmaclr)
7464087Smjacob		__P((struct ispsoftc *, XS_T *, u_int32_t));
7535388Smjacob	void		(*dv_reset0) __P((struct ispsoftc *));
7635388Smjacob	void		(*dv_reset1) __P((struct ispsoftc *));
7764087Smjacob	void		(*dv_dregs) __P((struct ispsoftc *, const char *));
7861772Smjacob	const u_int16_t	*dv_ispfw;	/* ptr to f/w */
7935388Smjacob	u_int16_t	dv_conf1;
8035388Smjacob	u_int16_t	dv_clock;	/* clock frequency */
8135388Smjacob};
8235388Smjacob
8364087Smjacob/*
8464087Smjacob * Overall parameters
8564087Smjacob */
8635388Smjacob#define	MAX_TARGETS	16
8744819Smjacob#ifdef	ISP2100_FABRIC
8844819Smjacob#define	MAX_FC_TARG	256
8944819Smjacob#else
9035388Smjacob#define	MAX_FC_TARG	126
9144819Smjacob#endif
9235388Smjacob
9349909Smjacob#define	ISP_MAX_TARGETS(isp)	(IS_FC(isp)? MAX_FC_TARG : MAX_TARGETS)
9461772Smjacob#define	ISP_MAX_LUNS(isp)	(isp)->isp_maxluns
9549909Smjacob
9653487Smjacob
9753487Smjacob/*
9864087Smjacob * Macros to access ISP registers through bus specific layers-
9964087Smjacob * mostly wrappers to vector through the mdvec structure.
10053487Smjacob */
10153487Smjacob
10253487Smjacob#define	ISP_READ(isp, reg)	\
10353487Smjacob	(*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
10453487Smjacob
10553487Smjacob#define	ISP_WRITE(isp, reg, val)	\
10653487Smjacob	(*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
10753487Smjacob
10853487Smjacob#define	ISP_MBOXDMASETUP(isp)	\
10953487Smjacob	(*(isp)->isp_mdvec->dv_mbxdma)((isp))
11053487Smjacob
11153487Smjacob#define	ISP_DMASETUP(isp, xs, req, iptrp, optr)	\
11253487Smjacob	(*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr))
11353487Smjacob
11453487Smjacob#define	ISP_DMAFREE(isp, xs, hndl)	\
11553487Smjacob	if ((isp)->isp_mdvec->dv_dmaclr) \
11653487Smjacob	    (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (hndl))
11753487Smjacob
11853487Smjacob#define	ISP_RESET0(isp)	\
11953487Smjacob	if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp))
12053487Smjacob#define	ISP_RESET1(isp)	\
12153487Smjacob	if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp))
12264087Smjacob#define	ISP_DUMPREGS(isp, m)	\
12364087Smjacob	if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp),(m))
12453487Smjacob
12553487Smjacob#define	ISP_SETBITS(isp, reg, val)	\
12653487Smjacob (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
12753487Smjacob
12853487Smjacob#define	ISP_CLRBITS(isp, reg, val)	\
12953487Smjacob (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
13053487Smjacob
13164087Smjacob/*
13264087Smjacob * The MEMORYBARRIER macro is defined per platform (to provide synchronization
13364087Smjacob * on Request and Response Queues, Scratch DMA areas, and Registers)
13464087Smjacob *
13564087Smjacob * Defined Memory Barrier Synchronization Types
13664087Smjacob */
13764087Smjacob#define	SYNC_REQUEST	0	/* request queue synchronization */
13864087Smjacob#define	SYNC_RESULT	1	/* result queue synchronization */
13964087Smjacob#define	SYNC_SFORDEV	2	/* scratch, sync for ISP */
14064087Smjacob#define	SYNC_SFORCPU	3	/* scratch, sync for CPU */
14164087Smjacob#define	SYNC_REG	4	/* for registers */
14264087Smjacob
14364087Smjacob/*
14464087Smjacob * Request/Response Queue defines and macros.
14564087Smjacob * The maximum is defined per platform (and can be based on board type).
14664087Smjacob */
14764087Smjacob/* This is the size of a queue entry (request and response) */
14839235Sgibbs#define	QENTRY_LEN			64
14964087Smjacob/* Both request and result queue length must be a power of two */
15064087Smjacob#define	RQUEST_QUEUE_LEN(x)		MAXISPREQUEST(x)
15164087Smjacob#define	RESULT_QUEUE_LEN(x)		\
15264087Smjacob	(((MAXISPREQUEST(x) >> 2) < 64)? 64 : MAXISPREQUEST(x) >> 2)
15339235Sgibbs#define	ISP_QUEUE_ENTRY(q, idx)		((q) + ((idx) * QENTRY_LEN))
15439235Sgibbs#define	ISP_QUEUE_SIZE(n)		((n) * QENTRY_LEN)
15539235Sgibbs#define	ISP_NXT_QENTRY(idx, qlen)	(((idx) + 1) & ((qlen)-1))
15652347Smjacob#define	ISP_QAVAIL(in, out, qlen)	\
15739235Sgibbs	((in == out)? (qlen - 1) : ((in > out)? \
15852347Smjacob	((qlen - 1) - (in - out)) : (out - in - 1)))
15953487Smjacob
16053487Smjacob#define	ISP_ADD_REQUEST(isp, iptr)	\
16164087Smjacob	MEMORYBARRIER(isp, SYNC_REQUEST, iptr, QENTRY_LEN); \
16264087Smjacob	ISP_WRITE(isp, INMAILBOX4, iptr); \
16364087Smjacob	isp->isp_reqidx = iptr
16453487Smjacob
16535388Smjacob/*
16646968Smjacob * SCSI Specific Host Adapter Parameters- per bus, per target
16735388Smjacob */
16835388Smjacob
16935388Smjacobtypedef struct {
17046968Smjacob	u_int		isp_gotdparms		: 1,
17152347Smjacob			isp_req_ack_active_neg	: 1,
17252347Smjacob			isp_data_line_active_neg: 1,
17335388Smjacob			isp_cmd_dma_burst_enable: 1,
17435388Smjacob			isp_data_dma_burst_enabl: 1,
17542461Smjacob			isp_fifo_threshold	: 3,
17643420Smjacob			isp_ultramode		: 1,
17735388Smjacob			isp_diffmode		: 1,
17845040Smjacob			isp_lvdmode		: 1,
17946968Smjacob						: 1,
18035388Smjacob			isp_initiator_id	: 4,
18152347Smjacob			isp_async_data_setup	: 4;
18252347Smjacob	u_int16_t	isp_selection_timeout;
18352347Smjacob	u_int16_t	isp_max_queue_depth;
18435388Smjacob	u_int8_t	isp_tag_aging;
18552347Smjacob	u_int8_t	isp_bus_reset_delay;
18652347Smjacob	u_int8_t	isp_retry_count;
18752347Smjacob	u_int8_t	isp_retry_delay;
18835388Smjacob	struct {
18946968Smjacob		u_int	dev_enable	:	1,	/* ignored */
19046968Smjacob					:	1,
19143420Smjacob			dev_update	:	1,
19243420Smjacob			dev_refresh	:	1,
19345040Smjacob			exc_throttle	:	8,
19445040Smjacob			cur_offset	:	4,
19545040Smjacob			sync_offset	:	4;
19645040Smjacob		u_int8_t	cur_period;	/* current sync period */
19745040Smjacob		u_int8_t	sync_period;	/* goal sync period */
19845040Smjacob		u_int16_t	dev_flags;	/* goal device flags */
19945040Smjacob		u_int16_t	cur_dflags;	/* current device flags */
20035388Smjacob	} isp_devparam[MAX_TARGETS];
20146968Smjacob} sdparam;
20235388Smjacob
20335388Smjacob/*
20435388Smjacob * Device Flags
20535388Smjacob */
20639235Sgibbs#define	DPARM_DISC	0x8000
20739235Sgibbs#define	DPARM_PARITY	0x4000
20839235Sgibbs#define	DPARM_WIDE	0x2000
20939235Sgibbs#define	DPARM_SYNC	0x1000
21039235Sgibbs#define	DPARM_TQING	0x0800
21139235Sgibbs#define	DPARM_ARQ	0x0400
21239235Sgibbs#define	DPARM_QFRZ	0x0200
21339235Sgibbs#define	DPARM_RENEG	0x0100
21439235Sgibbs#define	DPARM_NARROW	0x0080	/* Possibly only available with >= 7.55 fw */
21539235Sgibbs#define	DPARM_ASYNC	0x0040	/* Possibly only available with >= 7.55 fw */
21643793Smjacob#define	DPARM_DEFAULT	(0xFF00 & ~DPARM_QFRZ)
21739235Sgibbs#define	DPARM_SAFE_DFLT	(DPARM_DEFAULT & ~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING))
21835388Smjacob
21939235Sgibbs
22045040Smjacob/* technically, not really correct, as they need to be rated based upon clock */
22145040Smjacob#define	ISP_40M_SYNCPARMS	0x080a
22252347Smjacob#define	ISP_20M_SYNCPARMS	0x080c
22352347Smjacob#define	ISP_10M_SYNCPARMS	0x0c19
22452347Smjacob#define	ISP_08M_SYNCPARMS	0x0c25
22552347Smjacob#define	ISP_05M_SYNCPARMS	0x0c32
22652347Smjacob#define	ISP_04M_SYNCPARMS	0x0c41
22735388Smjacob
22835388Smjacob/*
22935388Smjacob * Fibre Channel Specifics
23035388Smjacob */
23152347Smjacob#define	FL_PORT_ID		0x7e	/* FL_Port Special ID */
23252347Smjacob#define	FC_PORT_ID		0x7f	/* Fabric Controller Special ID */
23352347Smjacob#define	FC_SNS_ID		0x80	/* SNS Server Special ID */
23452347Smjacob
23535388Smjacobtypedef struct {
23652347Smjacob	u_int32_t		isp_fwoptions	: 16,
23759454Smjacob						: 4,
23848484Smjacob				loop_seen_once	: 1,
23948484Smjacob				isp_loopstate	: 3,	/* Current Loop State */
24048484Smjacob				isp_fwstate	: 3,	/* ISP F/W state */
24148484Smjacob				isp_gotdparms	: 1,
24259454Smjacob				isp_topo	: 3,
24348484Smjacob				isp_onfabric	: 1;
24439235Sgibbs	u_int8_t		isp_loopid;	/* hard loop id */
24539235Sgibbs	u_int8_t		isp_alpa;	/* ALPA */
24652347Smjacob	volatile u_int16_t	isp_lipseq;	/* LIP sequence # */
24748484Smjacob	u_int32_t		isp_portid;
24839235Sgibbs	u_int8_t		isp_execthrottle;
24952347Smjacob	u_int8_t		isp_retry_delay;
25052347Smjacob	u_int8_t		isp_retry_count;
25152347Smjacob	u_int8_t		isp_reserved;
25239235Sgibbs	u_int16_t		isp_maxalloc;
25339235Sgibbs	u_int16_t		isp_maxfrmlen;
25448484Smjacob	u_int64_t		isp_nodewwn;
25548484Smjacob	u_int64_t		isp_portwwn;
25635388Smjacob	/*
25748484Smjacob	 * Port Data Base. This is indexed by 'target', which is invariate.
25848484Smjacob	 * However, elements within can move around due to loop changes,
25948484Smjacob	 * so the actual loop ID passed to the F/W is in this structure.
26048484Smjacob	 * The first time the loop is seen up, loopid will match the index
26148484Smjacob	 * (except for fabric nodes which are above mapped above FC_SNS_ID
26248484Smjacob	 * and are completely virtual), but subsequent LIPs can cause things
26348484Smjacob	 * to move around.
26444819Smjacob	 */
26548484Smjacob	struct lportdb {
26652347Smjacob		u_int
26760221Smjacob					loopid		: 8,
26860221Smjacob							: 4,
26960221Smjacob					loggedin	: 1,
27060221Smjacob					roles		: 2,
27160221Smjacob					valid		: 1;
27252347Smjacob		u_int32_t		portid;
27348484Smjacob		u_int64_t		node_wwn;
27448484Smjacob		u_int64_t		port_wwn;
27552347Smjacob	} portdb[MAX_FC_TARG], tport[FL_PORT_ID];
27644819Smjacob
27744819Smjacob	/*
27835388Smjacob	 * Scratch DMA mapped in area to fetch Port Database stuff, etc.
27935388Smjacob	 */
28048195Smjacob	caddr_t			isp_scratch;
28135388Smjacob	u_int32_t		isp_scdma;
28235388Smjacob} fcparam;
28335388Smjacob
28448484Smjacob#define	FW_CONFIG_WAIT		0
28548484Smjacob#define	FW_WAIT_AL_PA		1
28648484Smjacob#define	FW_WAIT_LOGIN		2
28748484Smjacob#define	FW_READY		3
28848484Smjacob#define	FW_LOSS_OF_SYNC		4
28948484Smjacob#define	FW_ERROR		5
29048484Smjacob#define	FW_REINIT		6
29148484Smjacob#define	FW_NON_PART		7
29235388Smjacob
29348484Smjacob#define	LOOP_NIL		0
29448484Smjacob#define	LOOP_LIP_RCVD		1
29548484Smjacob#define	LOOP_PDB_RCVD		2
29648484Smjacob#define	LOOP_READY		7
29735388Smjacob
29859454Smjacob#define	TOPO_NL_PORT		0
29959454Smjacob#define	TOPO_FL_PORT		1
30059454Smjacob#define	TOPO_N_PORT		2
30159454Smjacob#define	TOPO_F_PORT		3
30259454Smjacob#define	TOPO_PTP_STUB		4
30359454Smjacob
30442131Smjacob/*
30535388Smjacob * Soft Structure per host adapter
30635388Smjacob */
30735388Smjacobstruct ispsoftc {
30835388Smjacob	/*
30935388Smjacob	 * Platform (OS) specific data
31035388Smjacob	 */
31135388Smjacob	struct isposinfo	isp_osinfo;
31235388Smjacob
31335388Smjacob	/*
31453487Smjacob	 * Pointer to bus specific functions and data
31535388Smjacob	 */
31635388Smjacob	struct ispmdvec *	isp_mdvec;
31735388Smjacob
31835388Smjacob	/*
31953487Smjacob	 * (Mostly) nonvolatile state. Board specific parameters
32053487Smjacob	 * may contain some volatile state (e.g., current loop state).
32135388Smjacob	 */
32235388Smjacob
32353487Smjacob	void * 			isp_param;	/* type specific */
32453487Smjacob	u_int16_t		isp_fwrev[3];	/* Loaded F/W revision */
32553487Smjacob	u_int16_t		isp_romfw_rev[3]; /* PROM F/W revision */
32653487Smjacob	u_int16_t		isp_maxcmds;	/* max possible I/O cmds */
32753487Smjacob	u_int8_t		isp_type;	/* HBA Chip Type */
32853487Smjacob	u_int8_t		isp_revision;	/* HBA Chip H/W Revision */
32961772Smjacob	u_int32_t		isp_maxluns;	/* maximum luns supported */
33035388Smjacob
33164087Smjacob	u_int32_t
33253487Smjacob				isp_touched	: 1,	/* board ever seen? */
33353487Smjacob				isp_fast_mttr	: 1,	/* fast sram */
33453487Smjacob				isp_bustype	: 1,	/* SBus or PCI */
33562500Smjacob						: 1,
33664087Smjacob				isp_dblev	: 12,	/* debug log mask */
33753487Smjacob				isp_clock	: 8,	/* input clock */
33853487Smjacob				isp_confopts	: 8;	/* config options */
33939235Sgibbs
34035388Smjacob	/*
34139235Sgibbs	 * Volatile state
34235388Smjacob	 */
34335388Smjacob
34462171Smjacob	volatile u_int32_t
34562171Smjacob		isp_mboxbsy	:	8,	/* mailbox command active */
34662171Smjacob				:	1,
34739235Sgibbs		isp_state	:	3,
34846968Smjacob		isp_sendmarker	:	2,	/* send a marker entry */
34946968Smjacob		isp_update	:	2,	/* update parameters */
35052347Smjacob		isp_nactive	:	16;	/* how many commands active */
35152347Smjacob	volatile u_int16_t	isp_reqodx;	/* index of last ISP pickup */
35252347Smjacob	volatile u_int16_t	isp_reqidx;	/* index of next request */
35352347Smjacob	volatile u_int16_t	isp_residx;	/* index of next result */
35452347Smjacob	volatile u_int16_t	isp_lasthdls;	/* last handle seed */
35562171Smjacob	volatile u_int16_t	isp_mboxtmp[MAX_MAILBOX];
35635388Smjacob
35735388Smjacob	/*
35853487Smjacob	 * Active commands are stored here, indexed by handle functions.
35935388Smjacob	 */
36064087Smjacob	XS_T **isp_xflist;
36135388Smjacob
36235388Smjacob	/*
36352347Smjacob	 * request/result queue pointers and dma handles for them.
36435388Smjacob	 */
36548195Smjacob	caddr_t			isp_rquest;
36648195Smjacob	caddr_t			isp_result;
36735388Smjacob	u_int32_t		isp_rquest_dma;
36835388Smjacob	u_int32_t		isp_result_dma;
36935388Smjacob};
37035388Smjacob
37149909Smjacob#define	SDPARAM(isp)	((sdparam *) (isp)->isp_param)
37249909Smjacob#define	FCPARAM(isp)	((fcparam *) (isp)->isp_param)
37349909Smjacob
37435388Smjacob/*
37564087Smjacob * ISP Driver Run States
37635388Smjacob */
37735388Smjacob#define	ISP_NILSTATE	0
37835388Smjacob#define	ISP_RESETSTATE	1
37935388Smjacob#define	ISP_INITSTATE	2
38035388Smjacob#define	ISP_RUNSTATE	3
38135388Smjacob
38235388Smjacob/*
38335388Smjacob * ISP Configuration Options
38435388Smjacob */
38535388Smjacob#define	ISP_CFG_NORELOAD	0x80	/* don't download f/w */
38643793Smjacob#define	ISP_CFG_NONVRAM		0x40	/* ignore NVRAM */
38753487Smjacob#define	ISP_CFG_FULL_DUPLEX	0x01	/* Full Duplex (Fibre Channel only) */
38853487Smjacob#define	ISP_CFG_OWNWWN		0x02	/* override NVRAM wwn */
38957145Smjacob#define	ISP_CFG_NPORT		0x04	/* try to force N- instead of L-Port */
39035388Smjacob
39164087Smjacob/*
39264087Smjacob * Firmware related defines
39364087Smjacob */
39464087Smjacob#define	ISP_CODE_ORG		0x1000	/* default f/w code start */
39545282Smjacob#define	ISP_FW_REV(maj, min, mic)	((maj << 24) | (min << 16) | mic)
39646968Smjacob#define	ISP_FW_REVX(xp)	((xp[0]<<24) | (xp[1] << 16) | xp[2])
39739235Sgibbs
39835388Smjacob/*
39939235Sgibbs * Bus (implementation) types
40035388Smjacob */
40139235Sgibbs#define	ISP_BT_PCI		0	/* PCI Implementations */
40239235Sgibbs#define	ISP_BT_SBUS		1	/* SBus Implementations */
40339235Sgibbs
40439235Sgibbs/*
40539235Sgibbs * Chip Types
40639235Sgibbs */
40735388Smjacob#define	ISP_HA_SCSI		0xf
40839235Sgibbs#define	ISP_HA_SCSI_UNKNOWN	0x1
40939235Sgibbs#define	ISP_HA_SCSI_1020	0x2
41039235Sgibbs#define	ISP_HA_SCSI_1020A	0x3
41139235Sgibbs#define	ISP_HA_SCSI_1040	0x4
41239235Sgibbs#define	ISP_HA_SCSI_1040A	0x5
41339235Sgibbs#define	ISP_HA_SCSI_1040B	0x6
41445282Smjacob#define	ISP_HA_SCSI_1040C	0x7
41554671Smjacob#define	ISP_HA_SCSI_1240	0x8
41654671Smjacob#define	ISP_HA_SCSI_1080	0x9
41754671Smjacob#define	ISP_HA_SCSI_1280	0xa
41857145Smjacob#define	ISP_HA_SCSI_12160	0xb
41935388Smjacob#define	ISP_HA_FC		0xf0
42035388Smjacob#define	ISP_HA_FC_2100		0x10
42148484Smjacob#define	ISP_HA_FC_2200		0x20
42235388Smjacob
42344819Smjacob#define	IS_SCSI(isp)	(isp->isp_type & ISP_HA_SCSI)
42454671Smjacob#define	IS_1240(isp)	(isp->isp_type == ISP_HA_SCSI_1240)
42544819Smjacob#define	IS_1080(isp)	(isp->isp_type == ISP_HA_SCSI_1080)
42654671Smjacob#define	IS_1280(isp)	(isp->isp_type == ISP_HA_SCSI_1280)
42757145Smjacob#define	IS_12160(isp)	(isp->isp_type == ISP_HA_SCSI_12160)
42857145Smjacob
42957145Smjacob#define	IS_12X0(isp)	(IS_1240(isp) || IS_1280(isp))
43057145Smjacob#define	IS_DUALBUS(isp)	(IS_12X0(isp) || IS_12160(isp))
43157145Smjacob#define	IS_ULTRA2(isp)	(IS_1080(isp) || IS_1280(isp) || IS_12160(isp))
43257145Smjacob#define	IS_ULTRA3(isp)	(IS_12160(isp))
43357145Smjacob
43444819Smjacob#define	IS_FC(isp)	(isp->isp_type & ISP_HA_FC)
43557145Smjacob#define	IS_2100(isp)	(isp->isp_type == ISP_HA_FC_2100)
43657145Smjacob#define	IS_2200(isp)	(isp->isp_type == ISP_HA_FC_2200)
43744819Smjacob
43864087Smjacob/*
43964087Smjacob * DMA cookie macros
44064087Smjacob */
44164087Smjacob#define	DMA_MSW(x)	(((x) >> 16) & 0xffff)
44264087Smjacob#define	DMA_LSW(x)	(((x) & 0xffff))
44357145Smjacob
44435388Smjacob/*
44564087Smjacob * Core System Function Prototypes
44635388Smjacob */
44735388Smjacob
44835388Smjacob/*
44939235Sgibbs * Reset Hardware. Totally. Assumes that you'll follow this with
45039235Sgibbs * a call to isp_init.
45135388Smjacob */
45235388Smjacobvoid isp_reset __P((struct ispsoftc *));
45335388Smjacob
45435388Smjacob/*
45535388Smjacob * Initialize Hardware to known state
45635388Smjacob */
45735388Smjacobvoid isp_init __P((struct ispsoftc *));
45835388Smjacob
45935388Smjacob/*
46039235Sgibbs * Reset the ISP and call completion for any orphaned commands.
46139235Sgibbs */
46264087Smjacobvoid isp_reinit __P((struct ispsoftc *));
46339235Sgibbs
46439235Sgibbs/*
46535388Smjacob * Interrupt Service Routine
46635388Smjacob */
46735388Smjacobint isp_intr __P((void *));
46835388Smjacob
46935388Smjacob/*
47064087Smjacob * Command Entry Point- Platform Dependent layers call into this
47135388Smjacob */
47264087Smjacobint isp_start __P((XS_T *));
47364087Smjacob/* these values are what isp_start returns */
47464087Smjacob#define	CMD_COMPLETE	101	/* command completed */
47564087Smjacob#define	CMD_EAGAIN	102	/* busy- maybe retry later */
47664087Smjacob#define	CMD_QUEUED	103	/* command has been queued for execution */
47764087Smjacob#define	CMD_RQLATER 	104	/* requeue this command later */
47835388Smjacob
47939235Sgibbs/*
48064087Smjacob * Command Completion Point- Core layers call out from this with completed cmds
48164087Smjacob */
48264087Smjacobvoid isp_done __P((XS_T *));
48364087Smjacob
48464087Smjacob/*
48543420Smjacob * Platform Dependent to External to Internal Control Function
48639235Sgibbs *
48748484Smjacob * Assumes all locks are held and that no reentrancy issues need be dealt with.
48839235Sgibbs *
48939235Sgibbs */
49039235Sgibbstypedef enum {
49148484Smjacob	ISPCTL_RESET_BUS,		/* Reset Bus */
49248484Smjacob	ISPCTL_RESET_DEV,		/* Reset Device */
49348484Smjacob	ISPCTL_ABORT_CMD,		/* Abort Command */
49448484Smjacob	ISPCTL_UPDATE_PARAMS,		/* Update Operating Parameters */
49555364Smjacob	ISPCTL_FCLINK_TEST,		/* Test FC Link Status */
49655364Smjacob	ISPCTL_PDB_SYNC,		/* Synchronize Port Database */
49755364Smjacob	ISPCTL_TOGGLE_TMODE		/* toggle target mode */
49839235Sgibbs} ispctl_t;
49939235Sgibbsint isp_control __P((struct ispsoftc *, ispctl_t, void *));
50039235Sgibbs
50143420Smjacob
50239235Sgibbs/*
50343420Smjacob * Platform Dependent to Internal to External Control Function
50443420Smjacob * (each platform must provide such a function)
50543420Smjacob *
50648484Smjacob * Assumes all locks are held and that no reentrancy issues need be dealt with.
50743420Smjacob *
50843420Smjacob */
50943420Smjacob
51043420Smjacobtypedef enum {
51143793Smjacob	ISPASYNC_NEW_TGT_PARAMS,
51248484Smjacob	ISPASYNC_BUS_RESET,		/* Bus Was Reset */
51348484Smjacob	ISPASYNC_LOOP_DOWN,		/* FC Loop Down */
51448484Smjacob	ISPASYNC_LOOP_UP,		/* FC Loop Up */
51548484Smjacob	ISPASYNC_PDB_CHANGED,		/* FC Port Data Base Changed */
51648484Smjacob	ISPASYNC_CHANGE_NOTIFY,		/* FC SNS Change Notification */
51748484Smjacob	ISPASYNC_FABRIC_DEV,		/* FC New Fabric Device */
51855364Smjacob	ISPASYNC_TARGET_MESSAGE,	/* target message */
51955364Smjacob	ISPASYNC_TARGET_EVENT,		/* target asynchronous event */
52055364Smjacob	ISPASYNC_TARGET_ACTION		/* other target command action */
52143420Smjacob} ispasync_t;
52243420Smjacobint isp_async __P((struct ispsoftc *, ispasync_t, void *));
52343420Smjacob
52443420Smjacob/*
52564087Smjacob * Platform Dependent Error and Debug Printout
52639235Sgibbs */
52764087Smjacobvoid isp_prt __P((struct ispsoftc *, int level, const char *, ...));
52864087Smjacob#define	ISP_LOGALL	0x0	/* log always */
52964087Smjacob#define	ISP_LOGCONFIG	0x1	/* log configuration messages */
53064087Smjacob#define	ISP_LOGINFO	0x2	/* log informational messages */
53164087Smjacob#define	ISP_LOGWARN	0x4	/* log warning messages */
53264087Smjacob#define	ISP_LOGERR	0x8	/* log error messages */
53364087Smjacob#define	ISP_LOGDEBUG0	0x10	/* log simple debug messages */
53464087Smjacob#define	ISP_LOGDEBUG1	0x20	/* log intermediate debug messages */
53564087Smjacob#define	ISP_LOGDEBUG2	0x40	/* log most debug messages */
53664087Smjacob#define	ISP_LOGDEBUG3	0x100	/* log high frequency debug messages */
53764087Smjacob#define	ISP_LOGTDEBUG0	0x200	/* log simple debug messages (target mode) */
53864087Smjacob#define	ISP_LOGTDEBUG1	0x400	/* log intermediate debug messages (target) */
53964087Smjacob#define	ISP_LOGTDEBUG2	0x800	/* log all debug messages (target) */
54039235Sgibbs
54164087Smjacob/*
54264087Smjacob * Each Platform provides it's own isposinfo substructure of the ispsoftc
54364087Smjacob * defined above.
54464087Smjacob *
54564087Smjacob * Each platform must also provide the following macros/defines:
54664087Smjacob *
54764087Smjacob *
54864087Smjacob *	INLINE		-	platform specific define for 'inline' functions
54964087Smjacob *
55064087Smjacob *	ISP2100_FABRIC	-	defines whether FABRIC support is enabled
55164087Smjacob *	ISP2100_SCRLEN	-	length for the Fibre Channel scratch DMA area
55264087Smjacob *
55364087Smjacob *	MEMZERO(dst, src)			platform zeroing function
55464087Smjacob *	MEMCPY(dst, src, count)			platform copying function
55564087Smjacob *	SNPRINTF(buf, bufsize, fmt, ...)	snprintf
55664087Smjacob *	STRNCAT(dstbuf, size, srcbuf)		strncat
55764087Smjacob *	USEC_DELAY(usecs)			microsecond spindelay function
55864087Smjacob *
55964087Smjacob *	NANOTIME_T				nanosecond time type
56064087Smjacob *
56164087Smjacob *	GET_NANOTIME(NANOTIME_T *)		get current nanotime.
56264087Smjacob *
56364087Smjacob *	GET_NANOSEC(NANOTIME_T *)		get u_int64_t from NANOTIME_T
56464087Smjacob *
56564087Smjacob *	NANOTIME_SUB(NANOTIME_T *, NANOTIME_T *)
56664087Smjacob *						subtract two NANOTIME_T values
56764087Smjacob *
56864087Smjacob *
56964087Smjacob *	MAXISPREQUEST(struct ispsoftc *)	maximum request queue size
57064087Smjacob *						for this particular board type
57164087Smjacob *
57264087Smjacob *	MEMORYBARRIER(struct ispsoftc *, barrier_type, offset, size)
57364087Smjacob *
57464087Smjacob *		Function/Macro the provides memory synchronization on
57564087Smjacob *		various objects so that the ISP's and the system's view
57664087Smjacob *		of the same object is consistent.
57764087Smjacob *
57864087Smjacob *	MBOX_ACQUIRE(struct ispsoftc *)		acquire lock on mailbox regs
57964087Smjacob *	MBOX_WAIT_COMPLETE(struct ispsoftc *)	wait for mailbox cmd to be done
58064087Smjacob *	MBOX_NOTIFY_COMPLETE(struct ispsoftc *)	notification of mbox cmd donee
58164087Smjacob *	MBOX_RELEASE(struct ispsoftc *)		release lock on mailbox regs
58264087Smjacob *
58364087Smjacob *
58464087Smjacob *	SCSI_GOOD	SCSI 'Good' Status
58564087Smjacob *	SCSI_CHECK	SCSI 'Check Condition' Status
58664087Smjacob *	SCSI_BUSY	SCSI 'Busy' Status
58764087Smjacob *	SCSI_QFULL	SCSI 'Queue Full' Status
58864087Smjacob *
58964087Smjacob *	XS_T		Platform SCSI transaction type (i.e., command for HBA)
59064087Smjacob *	XS_ISP(xs)	gets an instance out of an XS_T
59164087Smjacob *	XS_CHANNEL(xs)	gets the channel (bus # for DUALBUS cards) ""
59264087Smjacob *	XS_TGT(xs)	gets the target ""
59364087Smjacob *	XS_LUN(xs)	gets the lun ""
59464087Smjacob *	XS_CDBP(xs)	gets a pointer to the scsi CDB ""
59564087Smjacob *	XS_CDBLEN(xs)	gets the CDB's length ""
59664087Smjacob *	XS_XFRLEN(xs)	gets the associated data transfer length ""
59764087Smjacob *	XS_TIME(xs)	gets the time (in milliseconds) for this command
59864087Smjacob *	XS_RESID(xs)	gets the current residual count
59964087Smjacob *	XS_STSP(xs)	gets a pointer to the SCSI status byte ""
60064087Smjacob *	XS_SNSP(xs)	gets a pointer to the associate sense data
60164087Smjacob *	XS_SNSLEN(xs)	gets the length of sense data storage
60264087Smjacob *	XS_SNSKEY(xs)	dereferences XS_SNSP to get the current stored Sense Key
60364087Smjacob *	XS_TAG_P(xs)	predicate of whether this command should be tagged
60464087Smjacob *	XS_TAG_TYPE(xs)	which type of tag to use
60564087Smjacob *	XS_SETERR(xs)	set error state
60664087Smjacob *
60764087Smjacob *		HBA_NOERROR	command has no erros
60864087Smjacob *		HBA_BOTCH	hba botched something
60964087Smjacob *		HBA_CMDTIMEOUT	command timed out
61064087Smjacob *		HBA_SELTIMEOUT	selection timed out (also port logouts for FC)
61164087Smjacob *		HBA_TGTBSY	target returned a BUSY status
61264087Smjacob *		HBA_BUSRESET	bus reset destroyed command
61364087Smjacob *		HBA_ABORTED	command was aborted (by request)
61464087Smjacob *		HBA_DATAOVR	a data overrun was detected
61564087Smjacob *		HBA_ARQFAIL	Automatic Request Sense failed
61664087Smjacob *
61764087Smjacob *	XS_ERR(xs)	return current error state
61864087Smjacob *	XS_NOERR(xs)	there is no error currently set
61964087Smjacob *	XS_INITERR(xs)	initialize error state
62064087Smjacob *
62164087Smjacob *	XS_SAVE_SENSE(xs, sp)		save sense data
62264087Smjacob *
62364087Smjacob *	XS_SET_STATE_STAT(isp, sp, xs)	platform dependent interpreter of
62464087Smjacob *					response queue entry status bits
62564087Smjacob *
62664087Smjacob *
62764087Smjacob *	DEFAULT_IID(struct ispsoftc *)		Default SCSI initiator ID
62864087Smjacob *
62964087Smjacob *	DEFAULT_LOOPID(struct ispsoftc *)	Default FC Loop ID
63064087Smjacob *	DEFAULT_NODEWWN(struct ispsoftc *)	Default FC Node WWN
63164087Smjacob *	DEFAULT_PORTWWN(struct ispsoftc *)	Default FC Port WWN
63264087Smjacob *
63364087Smjacob *	PORT_FROM_NODE_WWN(struct ispsoftc *, u_int64_t nwwn)
63464087Smjacob *
63564087Smjacob *		Node to Port WWN generator- this needs to be platform
63664087Smjacob *		specific so that given a NAA=2 WWN dragged from the Qlogic
63764087Smjacob *		card's NVRAM, a Port WWN can be generated that has the
63864087Smjacob *		appropriate bits set in bits 48..60 that are likely to be
63964087Smjacob *		based on the device instance number.
64064087Smjacob *
64164087Smjacob *	(XXX these do endian specific transformations- in transition XXX)
64264087Smjacob *	ISP_SWIZZLE_ICB
64364087Smjacob *	ISP_UNSWIZZLE_AND_COPY_PDBP
64464087Smjacob *	ISP_SWIZZLE_CONTINUATION
64564087Smjacob *	ISP_SWIZZLE_REQUEST
64664087Smjacob *	ISP_UNSWIZZLE_RESPONSE
64764087Smjacob *	ISP_SWIZZLE_SNS_REQ
64864087Smjacob *	ISP_UNSWIZZLE_SNS_RSP
64964087Smjacob *	ISP_SWIZZLE_NVRAM_WORD
65064087Smjacob *
65164087Smjacob *
65264087Smjacob */
65335388Smjacob#endif	/* _ISPVAR_H */
654