ispvar.h revision 70490
150477Speter/* $FreeBSD: head/sys/dev/isp/ispvar.h 70490 2000-12-29 19:17:18Z mjacob $ */
235388Smjacob/*
335388Smjacob * Soft Definitions for for Qlogic ISP SCSI adapters.
435388Smjacob *
566189Smjacob * Copyright (c) 1997, 1998, 1999, 2000 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
3135388Smjacob#ifndef	_ISPVAR_H
3235388Smjacob#define	_ISPVAR_H
3335388Smjacob
3444819Smjacob#if defined(__NetBSD__) || defined(__OpenBSD__)
3535388Smjacob#include <dev/ic/ispmbox.h>
3653487Smjacob#ifdef	ISP_TARGET_MODE
3753487Smjacob#include <dev/ic/isp_target.h>
3856004Smjacob#include <dev/ic/isp_tpublic.h>
3935388Smjacob#endif
4053487Smjacob#endif
4135388Smjacob#ifdef	__FreeBSD__
4235388Smjacob#include <dev/isp/ispmbox.h>
4353487Smjacob#ifdef	ISP_TARGET_MODE
4453487Smjacob#include <dev/isp/isp_target.h>
4556004Smjacob#include <dev/isp/isp_tpublic.h>
4635388Smjacob#endif
4753487Smjacob#endif
4835388Smjacob#ifdef	__linux__
4942131Smjacob#include "ispmbox.h"
5053487Smjacob#ifdef	ISP_TARGET_MODE
5153487Smjacob#include "isp_target.h"
5256004Smjacob#include "isp_tpublic.h"
5335388Smjacob#endif
5453487Smjacob#endif
5535388Smjacob
5664087Smjacob#define	ISP_CORE_VERSION_MAJOR	2
5764087Smjacob#define	ISP_CORE_VERSION_MINOR	0
5839235Sgibbs
5935388Smjacob/*
6043420Smjacob * Vector for bus specific code to provide specific services.
6135388Smjacob */
6235388Smjacobstruct ispsoftc;
6335388Smjacobstruct ispmdvec {
6435388Smjacob	u_int16_t	(*dv_rd_reg) __P((struct ispsoftc *, int));
6535388Smjacob	void		(*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t));
6635388Smjacob	int		(*dv_mbxdma) __P((struct ispsoftc *));
6735388Smjacob	int		(*dv_dmaset) __P((struct ispsoftc *,
6864087Smjacob		XS_T *, ispreq_t *, u_int16_t *, u_int16_t));
6935388Smjacob	void		(*dv_dmaclr)
7064087Smjacob		__P((struct ispsoftc *, XS_T *, u_int32_t));
7135388Smjacob	void		(*dv_reset0) __P((struct ispsoftc *));
7235388Smjacob	void		(*dv_reset1) __P((struct ispsoftc *));
7364087Smjacob	void		(*dv_dregs) __P((struct ispsoftc *, const char *));
7461772Smjacob	const u_int16_t	*dv_ispfw;	/* ptr to f/w */
7535388Smjacob	u_int16_t	dv_conf1;
7635388Smjacob	u_int16_t	dv_clock;	/* clock frequency */
7735388Smjacob};
7835388Smjacob
7964087Smjacob/*
8064087Smjacob * Overall parameters
8164087Smjacob */
8235388Smjacob#define	MAX_TARGETS	16
8344819Smjacob#ifdef	ISP2100_FABRIC
8444819Smjacob#define	MAX_FC_TARG	256
8544819Smjacob#else
8635388Smjacob#define	MAX_FC_TARG	126
8744819Smjacob#endif
8835388Smjacob
8949909Smjacob#define	ISP_MAX_TARGETS(isp)	(IS_FC(isp)? MAX_FC_TARG : MAX_TARGETS)
9061772Smjacob#define	ISP_MAX_LUNS(isp)	(isp)->isp_maxluns
9149909Smjacob
9253487Smjacob
9353487Smjacob/*
9464087Smjacob * Macros to access ISP registers through bus specific layers-
9564087Smjacob * mostly wrappers to vector through the mdvec structure.
9653487Smjacob */
9753487Smjacob
9853487Smjacob#define	ISP_READ(isp, reg)	\
9953487Smjacob	(*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
10053487Smjacob
10153487Smjacob#define	ISP_WRITE(isp, reg, val)	\
10253487Smjacob	(*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
10353487Smjacob
10453487Smjacob#define	ISP_MBOXDMASETUP(isp)	\
10553487Smjacob	(*(isp)->isp_mdvec->dv_mbxdma)((isp))
10653487Smjacob
10753487Smjacob#define	ISP_DMASETUP(isp, xs, req, iptrp, optr)	\
10853487Smjacob	(*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr))
10953487Smjacob
11053487Smjacob#define	ISP_DMAFREE(isp, xs, hndl)	\
11153487Smjacob	if ((isp)->isp_mdvec->dv_dmaclr) \
11253487Smjacob	    (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (hndl))
11353487Smjacob
11453487Smjacob#define	ISP_RESET0(isp)	\
11553487Smjacob	if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp))
11653487Smjacob#define	ISP_RESET1(isp)	\
11753487Smjacob	if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp))
11864087Smjacob#define	ISP_DUMPREGS(isp, m)	\
11964087Smjacob	if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp),(m))
12053487Smjacob
12153487Smjacob#define	ISP_SETBITS(isp, reg, val)	\
12253487Smjacob (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
12353487Smjacob
12453487Smjacob#define	ISP_CLRBITS(isp, reg, val)	\
12553487Smjacob (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
12653487Smjacob
12764087Smjacob/*
12864087Smjacob * The MEMORYBARRIER macro is defined per platform (to provide synchronization
12964087Smjacob * on Request and Response Queues, Scratch DMA areas, and Registers)
13064087Smjacob *
13164087Smjacob * Defined Memory Barrier Synchronization Types
13264087Smjacob */
13364087Smjacob#define	SYNC_REQUEST	0	/* request queue synchronization */
13464087Smjacob#define	SYNC_RESULT	1	/* result queue synchronization */
13564087Smjacob#define	SYNC_SFORDEV	2	/* scratch, sync for ISP */
13664087Smjacob#define	SYNC_SFORCPU	3	/* scratch, sync for CPU */
13764087Smjacob#define	SYNC_REG	4	/* for registers */
13864087Smjacob
13964087Smjacob/*
14064087Smjacob * Request/Response Queue defines and macros.
14164087Smjacob * The maximum is defined per platform (and can be based on board type).
14264087Smjacob */
14364087Smjacob/* This is the size of a queue entry (request and response) */
14439235Sgibbs#define	QENTRY_LEN			64
14564087Smjacob/* Both request and result queue length must be a power of two */
14664087Smjacob#define	RQUEST_QUEUE_LEN(x)		MAXISPREQUEST(x)
14764087Smjacob#define	RESULT_QUEUE_LEN(x)		\
14864087Smjacob	(((MAXISPREQUEST(x) >> 2) < 64)? 64 : MAXISPREQUEST(x) >> 2)
14939235Sgibbs#define	ISP_QUEUE_ENTRY(q, idx)		((q) + ((idx) * QENTRY_LEN))
15039235Sgibbs#define	ISP_QUEUE_SIZE(n)		((n) * QENTRY_LEN)
15139235Sgibbs#define	ISP_NXT_QENTRY(idx, qlen)	(((idx) + 1) & ((qlen)-1))
15265140Smjacob#define	ISP_QFREE(in, out, qlen)	\
15339235Sgibbs	((in == out)? (qlen - 1) : ((in > out)? \
15452347Smjacob	((qlen - 1) - (in - out)) : (out - in - 1)))
15565140Smjacob#define	ISP_QAVAIL(isp)	\
15665140Smjacob	ISP_QFREE(isp->isp_reqidx, isp->isp_reqodx, RQUEST_QUEUE_LEN(isp))
15753487Smjacob
15853487Smjacob#define	ISP_ADD_REQUEST(isp, iptr)	\
15964087Smjacob	MEMORYBARRIER(isp, SYNC_REQUEST, iptr, QENTRY_LEN); \
16064087Smjacob	ISP_WRITE(isp, INMAILBOX4, iptr); \
16164087Smjacob	isp->isp_reqidx = iptr
16253487Smjacob
16335388Smjacob/*
16446968Smjacob * SCSI Specific Host Adapter Parameters- per bus, per target
16535388Smjacob */
16635388Smjacob
16735388Smjacobtypedef struct {
16846968Smjacob	u_int		isp_gotdparms		: 1,
16952347Smjacob			isp_req_ack_active_neg	: 1,
17052347Smjacob			isp_data_line_active_neg: 1,
17135388Smjacob			isp_cmd_dma_burst_enable: 1,
17235388Smjacob			isp_data_dma_burst_enabl: 1,
17342461Smjacob			isp_fifo_threshold	: 3,
17443420Smjacob			isp_ultramode		: 1,
17535388Smjacob			isp_diffmode		: 1,
17645040Smjacob			isp_lvdmode		: 1,
17765140Smjacob			isp_fast_mttr		: 1,	/* fast sram */
17835388Smjacob			isp_initiator_id	: 4,
17952347Smjacob			isp_async_data_setup	: 4;
18052347Smjacob	u_int16_t	isp_selection_timeout;
18152347Smjacob	u_int16_t	isp_max_queue_depth;
18235388Smjacob	u_int8_t	isp_tag_aging;
18352347Smjacob	u_int8_t	isp_bus_reset_delay;
18452347Smjacob	u_int8_t	isp_retry_count;
18552347Smjacob	u_int8_t	isp_retry_delay;
18635388Smjacob	struct {
18746968Smjacob		u_int	dev_enable	:	1,	/* ignored */
18846968Smjacob					:	1,
18943420Smjacob			dev_update	:	1,
19043420Smjacob			dev_refresh	:	1,
19145040Smjacob			exc_throttle	:	8,
19245040Smjacob			cur_offset	:	4,
19345040Smjacob			sync_offset	:	4;
19445040Smjacob		u_int8_t	cur_period;	/* current sync period */
19545040Smjacob		u_int8_t	sync_period;	/* goal sync period */
19645040Smjacob		u_int16_t	dev_flags;	/* goal device flags */
19745040Smjacob		u_int16_t	cur_dflags;	/* current device flags */
19835388Smjacob	} isp_devparam[MAX_TARGETS];
19946968Smjacob} sdparam;
20035388Smjacob
20135388Smjacob/*
20235388Smjacob * Device Flags
20335388Smjacob */
20439235Sgibbs#define	DPARM_DISC	0x8000
20539235Sgibbs#define	DPARM_PARITY	0x4000
20639235Sgibbs#define	DPARM_WIDE	0x2000
20739235Sgibbs#define	DPARM_SYNC	0x1000
20839235Sgibbs#define	DPARM_TQING	0x0800
20939235Sgibbs#define	DPARM_ARQ	0x0400
21039235Sgibbs#define	DPARM_QFRZ	0x0200
21139235Sgibbs#define	DPARM_RENEG	0x0100
21265140Smjacob#define	DPARM_NARROW	0x0080
21365140Smjacob#define	DPARM_ASYNC	0x0040
21465140Smjacob#define	DPARM_PPR	0x0020
21543793Smjacob#define	DPARM_DEFAULT	(0xFF00 & ~DPARM_QFRZ)
21639235Sgibbs#define	DPARM_SAFE_DFLT	(DPARM_DEFAULT & ~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING))
21735388Smjacob
21839235Sgibbs
21945040Smjacob/* technically, not really correct, as they need to be rated based upon clock */
22065140Smjacob#define	ISP_80M_SYNCPARMS	0x0c09
22165140Smjacob#define	ISP_40M_SYNCPARMS	0x0c0a
22265140Smjacob#define	ISP_20M_SYNCPARMS	0x0c0c
22365140Smjacob#define	ISP_20M_SYNCPARMS_1040	0x080c
22452347Smjacob#define	ISP_10M_SYNCPARMS	0x0c19
22552347Smjacob#define	ISP_08M_SYNCPARMS	0x0c25
22652347Smjacob#define	ISP_05M_SYNCPARMS	0x0c32
22752347Smjacob#define	ISP_04M_SYNCPARMS	0x0c41
22835388Smjacob
22935388Smjacob/*
23035388Smjacob * Fibre Channel Specifics
23135388Smjacob */
23252347Smjacob#define	FL_PORT_ID		0x7e	/* FL_Port Special ID */
23352347Smjacob#define	FC_PORT_ID		0x7f	/* Fabric Controller Special ID */
23452347Smjacob#define	FC_SNS_ID		0x80	/* SNS Server Special ID */
23552347Smjacob
23635388Smjacobtypedef struct {
23752347Smjacob	u_int32_t		isp_fwoptions	: 16,
23859454Smjacob						: 4,
23948484Smjacob				loop_seen_once	: 1,
24048484Smjacob				isp_loopstate	: 3,	/* Current Loop State */
24148484Smjacob				isp_fwstate	: 3,	/* ISP F/W state */
24248484Smjacob				isp_gotdparms	: 1,
24359454Smjacob				isp_topo	: 3,
24448484Smjacob				isp_onfabric	: 1;
24539235Sgibbs	u_int8_t		isp_loopid;	/* hard loop id */
24639235Sgibbs	u_int8_t		isp_alpa;	/* ALPA */
24752347Smjacob	volatile u_int16_t	isp_lipseq;	/* LIP sequence # */
24848484Smjacob	u_int32_t		isp_portid;
24939235Sgibbs	u_int8_t		isp_execthrottle;
25052347Smjacob	u_int8_t		isp_retry_delay;
25152347Smjacob	u_int8_t		isp_retry_count;
25252347Smjacob	u_int8_t		isp_reserved;
25339235Sgibbs	u_int16_t		isp_maxalloc;
25439235Sgibbs	u_int16_t		isp_maxfrmlen;
25548484Smjacob	u_int64_t		isp_nodewwn;
25648484Smjacob	u_int64_t		isp_portwwn;
25735388Smjacob	/*
25848484Smjacob	 * Port Data Base. This is indexed by 'target', which is invariate.
25948484Smjacob	 * However, elements within can move around due to loop changes,
26048484Smjacob	 * so the actual loop ID passed to the F/W is in this structure.
26148484Smjacob	 * The first time the loop is seen up, loopid will match the index
26248484Smjacob	 * (except for fabric nodes which are above mapped above FC_SNS_ID
26348484Smjacob	 * and are completely virtual), but subsequent LIPs can cause things
26448484Smjacob	 * to move around.
26544819Smjacob	 */
26648484Smjacob	struct lportdb {
26752347Smjacob		u_int
26860221Smjacob					loopid		: 8,
26960221Smjacob							: 4,
27060221Smjacob					loggedin	: 1,
27160221Smjacob					roles		: 2,
27260221Smjacob					valid		: 1;
27352347Smjacob		u_int32_t		portid;
27448484Smjacob		u_int64_t		node_wwn;
27548484Smjacob		u_int64_t		port_wwn;
27652347Smjacob	} portdb[MAX_FC_TARG], tport[FL_PORT_ID];
27744819Smjacob
27844819Smjacob	/*
27935388Smjacob	 * Scratch DMA mapped in area to fetch Port Database stuff, etc.
28035388Smjacob	 */
28148195Smjacob	caddr_t			isp_scratch;
28235388Smjacob	u_int32_t		isp_scdma;
28335388Smjacob} fcparam;
28435388Smjacob
28548484Smjacob#define	FW_CONFIG_WAIT		0
28648484Smjacob#define	FW_WAIT_AL_PA		1
28748484Smjacob#define	FW_WAIT_LOGIN		2
28848484Smjacob#define	FW_READY		3
28948484Smjacob#define	FW_LOSS_OF_SYNC		4
29048484Smjacob#define	FW_ERROR		5
29148484Smjacob#define	FW_REINIT		6
29248484Smjacob#define	FW_NON_PART		7
29335388Smjacob
29448484Smjacob#define	LOOP_NIL		0
29548484Smjacob#define	LOOP_LIP_RCVD		1
29648484Smjacob#define	LOOP_PDB_RCVD		2
29748484Smjacob#define	LOOP_READY		7
29835388Smjacob
29959454Smjacob#define	TOPO_NL_PORT		0
30059454Smjacob#define	TOPO_FL_PORT		1
30159454Smjacob#define	TOPO_N_PORT		2
30259454Smjacob#define	TOPO_F_PORT		3
30359454Smjacob#define	TOPO_PTP_STUB		4
30459454Smjacob
30542131Smjacob/*
30635388Smjacob * Soft Structure per host adapter
30735388Smjacob */
30865140Smjacobtypedef struct ispsoftc {
30935388Smjacob	/*
31035388Smjacob	 * Platform (OS) specific data
31135388Smjacob	 */
31235388Smjacob	struct isposinfo	isp_osinfo;
31335388Smjacob
31435388Smjacob	/*
31553487Smjacob	 * Pointer to bus specific functions and data
31635388Smjacob	 */
31735388Smjacob	struct ispmdvec *	isp_mdvec;
31835388Smjacob
31935388Smjacob	/*
32053487Smjacob	 * (Mostly) nonvolatile state. Board specific parameters
32153487Smjacob	 * may contain some volatile state (e.g., current loop state).
32235388Smjacob	 */
32335388Smjacob
32453487Smjacob	void * 			isp_param;	/* type specific */
32553487Smjacob	u_int16_t		isp_fwrev[3];	/* Loaded F/W revision */
32653487Smjacob	u_int16_t		isp_romfw_rev[3]; /* PROM F/W revision */
32753487Smjacob	u_int16_t		isp_maxcmds;	/* max possible I/O cmds */
32853487Smjacob	u_int8_t		isp_type;	/* HBA Chip Type */
32953487Smjacob	u_int8_t		isp_revision;	/* HBA Chip H/W Revision */
33061772Smjacob	u_int32_t		isp_maxluns;	/* maximum luns supported */
33135388Smjacob
33264087Smjacob	u_int32_t
33353487Smjacob				isp_touched	: 1,	/* board ever seen? */
33465140Smjacob						: 1,
33553487Smjacob				isp_bustype	: 1,	/* SBus or PCI */
33665140Smjacob				isp_loaded_fw	: 1,	/* loaded firmware */
33764087Smjacob				isp_dblev	: 12,	/* debug log mask */
33853487Smjacob				isp_clock	: 8,	/* input clock */
33953487Smjacob				isp_confopts	: 8;	/* config options */
34069522Smjacob	/*
34169522Smjacob	 * Instrumentation
34269522Smjacob	 */
34369522Smjacob	u_int64_t		isp_intcnt;		/* total int count */
34469522Smjacob	u_int64_t		isp_intbogus;		/* spurious int count */
34539235Sgibbs
34635388Smjacob	/*
34739235Sgibbs	 * Volatile state
34835388Smjacob	 */
34935388Smjacob
35062171Smjacob	volatile u_int32_t
35162171Smjacob		isp_mboxbsy	:	8,	/* mailbox command active */
35262171Smjacob				:	1,
35339235Sgibbs		isp_state	:	3,
35446968Smjacob		isp_sendmarker	:	2,	/* send a marker entry */
35546968Smjacob		isp_update	:	2,	/* update parameters */
35652347Smjacob		isp_nactive	:	16;	/* how many commands active */
35752347Smjacob	volatile u_int16_t	isp_reqodx;	/* index of last ISP pickup */
35852347Smjacob	volatile u_int16_t	isp_reqidx;	/* index of next request */
35952347Smjacob	volatile u_int16_t	isp_residx;	/* index of next result */
36052347Smjacob	volatile u_int16_t	isp_lasthdls;	/* last handle seed */
36162171Smjacob	volatile u_int16_t	isp_mboxtmp[MAX_MAILBOX];
36235388Smjacob
36335388Smjacob	/*
36453487Smjacob	 * Active commands are stored here, indexed by handle functions.
36535388Smjacob	 */
36664087Smjacob	XS_T **isp_xflist;
36735388Smjacob
36835388Smjacob	/*
36952347Smjacob	 * request/result queue pointers and dma handles for them.
37035388Smjacob	 */
37148195Smjacob	caddr_t			isp_rquest;
37248195Smjacob	caddr_t			isp_result;
37335388Smjacob	u_int32_t		isp_rquest_dma;
37435388Smjacob	u_int32_t		isp_result_dma;
37565140Smjacob} ispsoftc_t;
37635388Smjacob
37749909Smjacob#define	SDPARAM(isp)	((sdparam *) (isp)->isp_param)
37849909Smjacob#define	FCPARAM(isp)	((fcparam *) (isp)->isp_param)
37949909Smjacob
38035388Smjacob/*
38164087Smjacob * ISP Driver Run States
38235388Smjacob */
38335388Smjacob#define	ISP_NILSTATE	0
38435388Smjacob#define	ISP_RESETSTATE	1
38535388Smjacob#define	ISP_INITSTATE	2
38635388Smjacob#define	ISP_RUNSTATE	3
38735388Smjacob
38835388Smjacob/*
38935388Smjacob * ISP Configuration Options
39035388Smjacob */
39135388Smjacob#define	ISP_CFG_NORELOAD	0x80	/* don't download f/w */
39243793Smjacob#define	ISP_CFG_NONVRAM		0x40	/* ignore NVRAM */
39370490Smjacob#define	ISP_CFG_NOINIT		0x20	/* just set defaults- don't init */
39453487Smjacob#define	ISP_CFG_FULL_DUPLEX	0x01	/* Full Duplex (Fibre Channel only) */
39553487Smjacob#define	ISP_CFG_OWNWWN		0x02	/* override NVRAM wwn */
39669522Smjacob#define	ISP_CFG_PORT_PREF	0x0C	/* Mask for Port Prefs (2200 only) */
39769522Smjacob#define	ISP_CFG_LPORT		0x00	/* prefer {N/F}L-Port connection */
39869522Smjacob#define	ISP_CFG_NPORT		0x04	/* prefer {N/F}-Port connection */
39969522Smjacob#define	ISP_CFG_NPORT_ONLY	0x08	/* insist on {N/F}-Port connection */
40069522Smjacob#define	ISP_CFG_LPORT_ONLY	0x0C	/* insist on {N/F}L-Port connection */
40135388Smjacob
40264087Smjacob/*
40364087Smjacob * Firmware related defines
40464087Smjacob */
40564087Smjacob#define	ISP_CODE_ORG		0x1000	/* default f/w code start */
40645282Smjacob#define	ISP_FW_REV(maj, min, mic)	((maj << 24) | (min << 16) | mic)
40746968Smjacob#define	ISP_FW_REVX(xp)	((xp[0]<<24) | (xp[1] << 16) | xp[2])
40839235Sgibbs
40935388Smjacob/*
41039235Sgibbs * Bus (implementation) types
41135388Smjacob */
41239235Sgibbs#define	ISP_BT_PCI		0	/* PCI Implementations */
41339235Sgibbs#define	ISP_BT_SBUS		1	/* SBus Implementations */
41439235Sgibbs
41539235Sgibbs/*
41639235Sgibbs * Chip Types
41739235Sgibbs */
41835388Smjacob#define	ISP_HA_SCSI		0xf
41939235Sgibbs#define	ISP_HA_SCSI_UNKNOWN	0x1
42039235Sgibbs#define	ISP_HA_SCSI_1020	0x2
42139235Sgibbs#define	ISP_HA_SCSI_1020A	0x3
42239235Sgibbs#define	ISP_HA_SCSI_1040	0x4
42339235Sgibbs#define	ISP_HA_SCSI_1040A	0x5
42439235Sgibbs#define	ISP_HA_SCSI_1040B	0x6
42545282Smjacob#define	ISP_HA_SCSI_1040C	0x7
42654671Smjacob#define	ISP_HA_SCSI_1240	0x8
42754671Smjacob#define	ISP_HA_SCSI_1080	0x9
42854671Smjacob#define	ISP_HA_SCSI_1280	0xa
42957145Smjacob#define	ISP_HA_SCSI_12160	0xb
43035388Smjacob#define	ISP_HA_FC		0xf0
43135388Smjacob#define	ISP_HA_FC_2100		0x10
43248484Smjacob#define	ISP_HA_FC_2200		0x20
43335388Smjacob
43444819Smjacob#define	IS_SCSI(isp)	(isp->isp_type & ISP_HA_SCSI)
43554671Smjacob#define	IS_1240(isp)	(isp->isp_type == ISP_HA_SCSI_1240)
43644819Smjacob#define	IS_1080(isp)	(isp->isp_type == ISP_HA_SCSI_1080)
43754671Smjacob#define	IS_1280(isp)	(isp->isp_type == ISP_HA_SCSI_1280)
43857145Smjacob#define	IS_12160(isp)	(isp->isp_type == ISP_HA_SCSI_12160)
43957145Smjacob
44057145Smjacob#define	IS_12X0(isp)	(IS_1240(isp) || IS_1280(isp))
44157145Smjacob#define	IS_DUALBUS(isp)	(IS_12X0(isp) || IS_12160(isp))
44257145Smjacob#define	IS_ULTRA2(isp)	(IS_1080(isp) || IS_1280(isp) || IS_12160(isp))
44357145Smjacob#define	IS_ULTRA3(isp)	(IS_12160(isp))
44457145Smjacob
44544819Smjacob#define	IS_FC(isp)	(isp->isp_type & ISP_HA_FC)
44657145Smjacob#define	IS_2100(isp)	(isp->isp_type == ISP_HA_FC_2100)
44757145Smjacob#define	IS_2200(isp)	(isp->isp_type == ISP_HA_FC_2200)
44844819Smjacob
44964087Smjacob/*
45064087Smjacob * DMA cookie macros
45164087Smjacob */
45264087Smjacob#define	DMA_MSW(x)	(((x) >> 16) & 0xffff)
45364087Smjacob#define	DMA_LSW(x)	(((x) & 0xffff))
45457145Smjacob
45535388Smjacob/*
45664087Smjacob * Core System Function Prototypes
45735388Smjacob */
45835388Smjacob
45935388Smjacob/*
46039235Sgibbs * Reset Hardware. Totally. Assumes that you'll follow this with
46139235Sgibbs * a call to isp_init.
46235388Smjacob */
46335388Smjacobvoid isp_reset __P((struct ispsoftc *));
46435388Smjacob
46535388Smjacob/*
46635388Smjacob * Initialize Hardware to known state
46735388Smjacob */
46835388Smjacobvoid isp_init __P((struct ispsoftc *));
46935388Smjacob
47035388Smjacob/*
47139235Sgibbs * Reset the ISP and call completion for any orphaned commands.
47239235Sgibbs */
47364087Smjacobvoid isp_reinit __P((struct ispsoftc *));
47439235Sgibbs
47539235Sgibbs/*
47635388Smjacob * Interrupt Service Routine
47735388Smjacob */
47835388Smjacobint isp_intr __P((void *));
47935388Smjacob
48035388Smjacob/*
48164087Smjacob * Command Entry Point- Platform Dependent layers call into this
48235388Smjacob */
48364087Smjacobint isp_start __P((XS_T *));
48464087Smjacob/* these values are what isp_start returns */
48564087Smjacob#define	CMD_COMPLETE	101	/* command completed */
48664087Smjacob#define	CMD_EAGAIN	102	/* busy- maybe retry later */
48764087Smjacob#define	CMD_QUEUED	103	/* command has been queued for execution */
48864087Smjacob#define	CMD_RQLATER 	104	/* requeue this command later */
48935388Smjacob
49039235Sgibbs/*
49164087Smjacob * Command Completion Point- Core layers call out from this with completed cmds
49264087Smjacob */
49364087Smjacobvoid isp_done __P((XS_T *));
49464087Smjacob
49564087Smjacob/*
49643420Smjacob * Platform Dependent to External to Internal Control Function
49739235Sgibbs *
49848484Smjacob * Assumes all locks are held and that no reentrancy issues need be dealt with.
49939235Sgibbs *
50039235Sgibbs */
50139235Sgibbstypedef enum {
50248484Smjacob	ISPCTL_RESET_BUS,		/* Reset Bus */
50348484Smjacob	ISPCTL_RESET_DEV,		/* Reset Device */
50448484Smjacob	ISPCTL_ABORT_CMD,		/* Abort Command */
50548484Smjacob	ISPCTL_UPDATE_PARAMS,		/* Update Operating Parameters */
50655364Smjacob	ISPCTL_FCLINK_TEST,		/* Test FC Link Status */
50755364Smjacob	ISPCTL_PDB_SYNC,		/* Synchronize Port Database */
50855364Smjacob	ISPCTL_TOGGLE_TMODE		/* toggle target mode */
50939235Sgibbs} ispctl_t;
51039235Sgibbsint isp_control __P((struct ispsoftc *, ispctl_t, void *));
51139235Sgibbs
51243420Smjacob
51339235Sgibbs/*
51443420Smjacob * Platform Dependent to Internal to External Control Function
51543420Smjacob * (each platform must provide such a function)
51643420Smjacob *
51748484Smjacob * Assumes all locks are held and that no reentrancy issues need be dealt with.
51843420Smjacob *
51943420Smjacob */
52043420Smjacob
52143420Smjacobtypedef enum {
52243793Smjacob	ISPASYNC_NEW_TGT_PARAMS,
52348484Smjacob	ISPASYNC_BUS_RESET,		/* Bus Was Reset */
52448484Smjacob	ISPASYNC_LOOP_DOWN,		/* FC Loop Down */
52548484Smjacob	ISPASYNC_LOOP_UP,		/* FC Loop Up */
52648484Smjacob	ISPASYNC_PDB_CHANGED,		/* FC Port Data Base Changed */
52748484Smjacob	ISPASYNC_CHANGE_NOTIFY,		/* FC SNS Change Notification */
52848484Smjacob	ISPASYNC_FABRIC_DEV,		/* FC New Fabric Device */
52955364Smjacob	ISPASYNC_TARGET_MESSAGE,	/* target message */
53055364Smjacob	ISPASYNC_TARGET_EVENT,		/* target asynchronous event */
53155364Smjacob	ISPASYNC_TARGET_ACTION		/* other target command action */
53243420Smjacob} ispasync_t;
53343420Smjacobint isp_async __P((struct ispsoftc *, ispasync_t, void *));
53443420Smjacob
53543420Smjacob/*
53664087Smjacob * Platform Dependent Error and Debug Printout
53739235Sgibbs */
53870490Smjacob#ifdef	__GNUC__
53970490Smjacobvoid isp_prt __P((struct ispsoftc *, int level, const char *, ...))
54070490Smjacob	__attribute__((__format__(__printf__,3,4)));
54170490Smjacob#else
54264087Smjacobvoid isp_prt __P((struct ispsoftc *, int level, const char *, ...));
54370490Smjacob#endif
54470490Smjacob
54564087Smjacob#define	ISP_LOGALL	0x0	/* log always */
54664087Smjacob#define	ISP_LOGCONFIG	0x1	/* log configuration messages */
54764087Smjacob#define	ISP_LOGINFO	0x2	/* log informational messages */
54864087Smjacob#define	ISP_LOGWARN	0x4	/* log warning messages */
54964087Smjacob#define	ISP_LOGERR	0x8	/* log error messages */
55064087Smjacob#define	ISP_LOGDEBUG0	0x10	/* log simple debug messages */
55164087Smjacob#define	ISP_LOGDEBUG1	0x20	/* log intermediate debug messages */
55264087Smjacob#define	ISP_LOGDEBUG2	0x40	/* log most debug messages */
55364087Smjacob#define	ISP_LOGDEBUG3	0x100	/* log high frequency debug messages */
55464087Smjacob#define	ISP_LOGTDEBUG0	0x200	/* log simple debug messages (target mode) */
55564087Smjacob#define	ISP_LOGTDEBUG1	0x400	/* log intermediate debug messages (target) */
55664087Smjacob#define	ISP_LOGTDEBUG2	0x800	/* log all debug messages (target) */
55739235Sgibbs
55864087Smjacob/*
55964087Smjacob * Each Platform provides it's own isposinfo substructure of the ispsoftc
56064087Smjacob * defined above.
56164087Smjacob *
56264087Smjacob * Each platform must also provide the following macros/defines:
56364087Smjacob *
56464087Smjacob *
56564087Smjacob *	INLINE		-	platform specific define for 'inline' functions
56664087Smjacob *
56764087Smjacob *	ISP2100_FABRIC	-	defines whether FABRIC support is enabled
56864087Smjacob *	ISP2100_SCRLEN	-	length for the Fibre Channel scratch DMA area
56964087Smjacob *
57064087Smjacob *	MEMZERO(dst, src)			platform zeroing function
57164087Smjacob *	MEMCPY(dst, src, count)			platform copying function
57264087Smjacob *	SNPRINTF(buf, bufsize, fmt, ...)	snprintf
57364087Smjacob *	STRNCAT(dstbuf, size, srcbuf)		strncat
57464087Smjacob *	USEC_DELAY(usecs)			microsecond spindelay function
57569522Smjacob *	USEC_SLEEP(isp, usecs)			microsecond sleep function
57664087Smjacob *
57764087Smjacob *	NANOTIME_T				nanosecond time type
57864087Smjacob *
57964087Smjacob *	GET_NANOTIME(NANOTIME_T *)		get current nanotime.
58064087Smjacob *
58164087Smjacob *	GET_NANOSEC(NANOTIME_T *)		get u_int64_t from NANOTIME_T
58264087Smjacob *
58364087Smjacob *	NANOTIME_SUB(NANOTIME_T *, NANOTIME_T *)
58464087Smjacob *						subtract two NANOTIME_T values
58564087Smjacob *
58664087Smjacob *
58764087Smjacob *	MAXISPREQUEST(struct ispsoftc *)	maximum request queue size
58864087Smjacob *						for this particular board type
58964087Smjacob *
59064087Smjacob *	MEMORYBARRIER(struct ispsoftc *, barrier_type, offset, size)
59164087Smjacob *
59264087Smjacob *		Function/Macro the provides memory synchronization on
59364087Smjacob *		various objects so that the ISP's and the system's view
59464087Smjacob *		of the same object is consistent.
59564087Smjacob *
59664087Smjacob *	MBOX_ACQUIRE(struct ispsoftc *)		acquire lock on mailbox regs
59764087Smjacob *	MBOX_WAIT_COMPLETE(struct ispsoftc *)	wait for mailbox cmd to be done
59864087Smjacob *	MBOX_NOTIFY_COMPLETE(struct ispsoftc *)	notification of mbox cmd donee
59964087Smjacob *	MBOX_RELEASE(struct ispsoftc *)		release lock on mailbox regs
60064087Smjacob *
60164087Smjacob *
60264087Smjacob *	SCSI_GOOD	SCSI 'Good' Status
60364087Smjacob *	SCSI_CHECK	SCSI 'Check Condition' Status
60464087Smjacob *	SCSI_BUSY	SCSI 'Busy' Status
60564087Smjacob *	SCSI_QFULL	SCSI 'Queue Full' Status
60664087Smjacob *
60764087Smjacob *	XS_T		Platform SCSI transaction type (i.e., command for HBA)
60864087Smjacob *	XS_ISP(xs)	gets an instance out of an XS_T
60964087Smjacob *	XS_CHANNEL(xs)	gets the channel (bus # for DUALBUS cards) ""
61064087Smjacob *	XS_TGT(xs)	gets the target ""
61164087Smjacob *	XS_LUN(xs)	gets the lun ""
61264087Smjacob *	XS_CDBP(xs)	gets a pointer to the scsi CDB ""
61364087Smjacob *	XS_CDBLEN(xs)	gets the CDB's length ""
61464087Smjacob *	XS_XFRLEN(xs)	gets the associated data transfer length ""
61564087Smjacob *	XS_TIME(xs)	gets the time (in milliseconds) for this command
61664087Smjacob *	XS_RESID(xs)	gets the current residual count
61764087Smjacob *	XS_STSP(xs)	gets a pointer to the SCSI status byte ""
61864087Smjacob *	XS_SNSP(xs)	gets a pointer to the associate sense data
61964087Smjacob *	XS_SNSLEN(xs)	gets the length of sense data storage
62064087Smjacob *	XS_SNSKEY(xs)	dereferences XS_SNSP to get the current stored Sense Key
62164087Smjacob *	XS_TAG_P(xs)	predicate of whether this command should be tagged
62264087Smjacob *	XS_TAG_TYPE(xs)	which type of tag to use
62364087Smjacob *	XS_SETERR(xs)	set error state
62464087Smjacob *
62564087Smjacob *		HBA_NOERROR	command has no erros
62664087Smjacob *		HBA_BOTCH	hba botched something
62764087Smjacob *		HBA_CMDTIMEOUT	command timed out
62864087Smjacob *		HBA_SELTIMEOUT	selection timed out (also port logouts for FC)
62964087Smjacob *		HBA_TGTBSY	target returned a BUSY status
63064087Smjacob *		HBA_BUSRESET	bus reset destroyed command
63164087Smjacob *		HBA_ABORTED	command was aborted (by request)
63264087Smjacob *		HBA_DATAOVR	a data overrun was detected
63364087Smjacob *		HBA_ARQFAIL	Automatic Request Sense failed
63464087Smjacob *
63564087Smjacob *	XS_ERR(xs)	return current error state
63664087Smjacob *	XS_NOERR(xs)	there is no error currently set
63764087Smjacob *	XS_INITERR(xs)	initialize error state
63864087Smjacob *
63964087Smjacob *	XS_SAVE_SENSE(xs, sp)		save sense data
64064087Smjacob *
64164087Smjacob *	XS_SET_STATE_STAT(isp, sp, xs)	platform dependent interpreter of
64264087Smjacob *					response queue entry status bits
64364087Smjacob *
64464087Smjacob *
64564087Smjacob *	DEFAULT_IID(struct ispsoftc *)		Default SCSI initiator ID
64664087Smjacob *	DEFAULT_LOOPID(struct ispsoftc *)	Default FC Loop ID
64767047Smjacob *	DEFAULT_NODEWWN(struct ispsoftc *)	Default Node WWN
64867047Smjacob *	DEFAULT_PORTWWN(struct ispsoftc *)	Default Port WWN
64967047Smjacob *		These establish reasonable defaults for each platform.
65067047Smjacob * 		These must be available independent of card NVRAM and are
65167047Smjacob *		to be used should NVRAM not be readable.
65264087Smjacob *
65367047Smjacob *	ISP_NODEWWN(struct ispsoftc *)	FC Node WWN to use
65467047Smjacob *	ISP_PORTWWN(struct ispsoftc *)	FC Port WWN to use
65564087Smjacob *
65667047Smjacob *		These are to be used after NVRAM is read. The tags
65767047Smjacob *		in fcparam.isp_{node,port}wwn reflect the values
65867047Smjacob *		read from NVRAM (possibly corrected for card botches).
65967047Smjacob *		Each platform can take that information and override
66067047Smjacob *		it or ignore and return the Node and Port WWNs to be
66167047Smjacob * 		used when sending the Qlogic f/w the Initialization Control
66267047Smjacob *		Block.
66364087Smjacob *
66464087Smjacob *	(XXX these do endian specific transformations- in transition XXX)
66564087Smjacob *	ISP_SWIZZLE_ICB
66664087Smjacob *	ISP_UNSWIZZLE_AND_COPY_PDBP
66764087Smjacob *	ISP_SWIZZLE_CONTINUATION
66864087Smjacob *	ISP_SWIZZLE_REQUEST
66964087Smjacob *	ISP_UNSWIZZLE_RESPONSE
67064087Smjacob *	ISP_SWIZZLE_SNS_REQ
67164087Smjacob *	ISP_UNSWIZZLE_SNS_RSP
67264087Smjacob *	ISP_SWIZZLE_NVRAM_WORD
67364087Smjacob *
67464087Smjacob *
67564087Smjacob */
67635388Smjacob#endif	/* _ISPVAR_H */
677