ispvar.h revision 41519
141519Smjacob/* $Id: $ */
241519Smjacob/* ispvar.h 1.21 */
335388Smjacob/*
435388Smjacob * Soft Definitions for for Qlogic ISP SCSI adapters.
535388Smjacob *
635388Smjacob *---------------------------------------
735388Smjacob * Copyright (c) 1997, 1998 by Matthew Jacob
835388Smjacob * NASA/Ames Research Center
935388Smjacob * All rights reserved.
1035388Smjacob *---------------------------------------
1135388Smjacob * Redistribution and use in source and binary forms, with or without
1235388Smjacob * modification, are permitted provided that the following conditions
1335388Smjacob * are met:
1435388Smjacob * 1. Redistributions of source code must retain the above copyright
1535388Smjacob *    notice immediately at the beginning of the file, without modification,
1635388Smjacob *    this list of conditions, and the following disclaimer.
1735388Smjacob * 2. Redistributions in binary form must reproduce the above copyright
1835388Smjacob *    notice, this list of conditions and the following disclaimer in the
1935388Smjacob *    documentation and/or other materials provided with the distribution.
2035388Smjacob * 3. The name of the author may not be used to endorse or promote products
2135388Smjacob *    derived from this software without specific prior written permission.
2235388Smjacob *
2335388Smjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2435388Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2535388Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2635388Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
2735388Smjacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2835388Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2935388Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3035388Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3135388Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3235388Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3335388Smjacob * SUCH DAMAGE.
3435388Smjacob *
3535388Smjacob */
3635388Smjacob
3735388Smjacob#ifndef	_ISPVAR_H
3835388Smjacob#define	_ISPVAR_H
3935388Smjacob
4035388Smjacob#ifdef	__NetBSD__
4135388Smjacob#include <dev/ic/ispmbox.h>
4235388Smjacob#endif
4335388Smjacob#ifdef	__FreeBSD__
4435388Smjacob#include <dev/isp/ispmbox.h>
4535388Smjacob#endif
4635388Smjacob#ifdef	__linux__
4735388Smjacob#include <ispmbox.h>
4835388Smjacob#endif
4935388Smjacob
5039235Sgibbs#define	ISP_CORE_VERSION_MAJOR	1
5141519Smjacob#define	ISP_CORE_VERSION_MINOR	4
5239235Sgibbs
5335388Smjacob/*
5435388Smjacob * Vector for MD code to provide specific services.
5535388Smjacob */
5635388Smjacobstruct ispsoftc;
5735388Smjacobstruct ispmdvec {
5835388Smjacob	u_int16_t	(*dv_rd_reg) __P((struct ispsoftc *, int));
5935388Smjacob	void		(*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t));
6035388Smjacob	int		(*dv_mbxdma) __P((struct ispsoftc *));
6135388Smjacob	int		(*dv_dmaset) __P((struct ispsoftc *,
6235388Smjacob		ISP_SCSI_XFER_T *, ispreq_t *, u_int8_t *, u_int8_t));
6335388Smjacob	void		(*dv_dmaclr)
6435388Smjacob		__P((struct ispsoftc *, ISP_SCSI_XFER_T *, u_int32_t));
6535388Smjacob	void		(*dv_reset0) __P((struct ispsoftc *));
6635388Smjacob	void		(*dv_reset1) __P((struct ispsoftc *));
6735388Smjacob	void		(*dv_dregs) __P((struct ispsoftc *));
6835388Smjacob	const u_int16_t *dv_ispfw;	/* ptr to f/w */
6935388Smjacob	u_int16_t 	dv_fwlen;	/* length of f/w */
7035388Smjacob	u_int16_t	dv_codeorg;	/* code ORG for f/w */
7135388Smjacob	u_int16_t	dv_fwrev;	/* f/w revision */
7235388Smjacob	/*
7335388Smjacob	 * Initial values for conf1 register
7435388Smjacob	 */
7535388Smjacob	u_int16_t	dv_conf1;
7635388Smjacob	u_int16_t	dv_clock;	/* clock frequency */
7735388Smjacob};
7835388Smjacob
7935388Smjacob#define	MAX_TARGETS	16
8035388Smjacob#define	MAX_FC_TARG	126
8141519Smjacob#define	DEFAULT_LOOPID	113
8235388Smjacob
8339235Sgibbs/* queue length must be a power of two */
8439235Sgibbs#define	QENTRY_LEN			64
8539235Sgibbs#define	RQUEST_QUEUE_LEN		MAXISPREQUEST
8639235Sgibbs#define	RESULT_QUEUE_LEN		(MAXISPREQUEST/4)
8739235Sgibbs#define	ISP_QUEUE_ENTRY(q, idx)		((q) + ((idx) * QENTRY_LEN))
8839235Sgibbs#define	ISP_QUEUE_SIZE(n)		((n) * QENTRY_LEN)
8939235Sgibbs#define	ISP_NXT_QENTRY(idx, qlen)	(((idx) + 1) & ((qlen)-1))
9039235Sgibbs#define ISP_QAVAIL(in, out, qlen)	\
9139235Sgibbs	((in == out)? (qlen - 1) : ((in > out)? \
9239235Sgibbs		((qlen - 1) - (in - out)) : (out - in - 1)))
9335388Smjacob/*
9435388Smjacob * SCSI (as opposed to FC-PH) Specific Host Adapter Parameters
9535388Smjacob */
9635388Smjacob
9735388Smjacobtypedef struct {
9839235Sgibbs        u_int		isp_req_ack_active_neg	: 1,
9935388Smjacob	        	isp_data_line_active_neg: 1,
10035388Smjacob			isp_cmd_dma_burst_enable: 1,
10135388Smjacob			isp_data_dma_burst_enabl: 1,
10235388Smjacob			isp_fifo_threshold	: 2,
10335388Smjacob			isp_diffmode		: 1,
10439235Sgibbs			isp_fast_mttr		: 1,
10535388Smjacob			isp_initiator_id	: 4,
10635388Smjacob        		isp_async_data_setup	: 4;
10735388Smjacob        u_int16_t	isp_selection_timeout;
10835388Smjacob        u_int16_t	isp_max_queue_depth;
10935388Smjacob	u_int16_t	isp_clock;
11035388Smjacob	u_int8_t	isp_tag_aging;
11135388Smjacob       	u_int8_t	isp_bus_reset_delay;
11235388Smjacob        u_int8_t	isp_retry_count;
11335388Smjacob        u_int8_t	isp_retry_delay;
11435388Smjacob	struct {
11539235Sgibbs		u_int	dev_update	:	1,
11639235Sgibbs			dev_enable	:	1,
11739235Sgibbs			exc_throttle	:	7,
11839235Sgibbs			sync_offset	:	4,
11939235Sgibbs			sync_period	:	8;
12039235Sgibbs		u_int16_t dev_flags;		/* persistent device flags */
12139235Sgibbs		u_int16_t cur_dflags;		/* current device flags */
12235388Smjacob	} isp_devparam[MAX_TARGETS];
12335388Smjacob} sdparam;	/* scsi device parameters */
12435388Smjacob
12535388Smjacob/*
12635388Smjacob * Device Flags
12735388Smjacob */
12839235Sgibbs#define	DPARM_DISC	0x8000
12939235Sgibbs#define	DPARM_PARITY	0x4000
13039235Sgibbs#define	DPARM_WIDE	0x2000
13139235Sgibbs#define	DPARM_SYNC	0x1000
13239235Sgibbs#define	DPARM_TQING	0x0800
13339235Sgibbs#define	DPARM_ARQ	0x0400
13439235Sgibbs#define	DPARM_QFRZ	0x0200
13539235Sgibbs#define	DPARM_RENEG	0x0100
13639235Sgibbs#define	DPARM_NARROW	0x0080	/* Possibly only available with >= 7.55 fw */
13739235Sgibbs#define	DPARM_ASYNC	0x0040	/* Possibly only available with >= 7.55 fw */
13839235Sgibbs#define	DPARM_DEFAULT	(0xFFFF & ~DPARM_QFRZ)
13939235Sgibbs#define	DPARM_SAFE_DFLT	(DPARM_DEFAULT & ~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING))
14035388Smjacob
14139235Sgibbs
14235388Smjacob#define ISP_20M_SYNCPARMS	0x080c
14335388Smjacob#define ISP_10M_SYNCPARMS	0x0c19
14435388Smjacob#define ISP_08M_SYNCPARMS	0x0c25
14535388Smjacob#define ISP_05M_SYNCPARMS	0x0c32
14635388Smjacob#define ISP_04M_SYNCPARMS	0x0c41
14735388Smjacob
14835388Smjacob/*
14935388Smjacob * Fibre Channel Specifics
15035388Smjacob */
15135388Smjacobtypedef struct {
15235388Smjacob	u_int64_t		isp_wwn;	/* WWN of adapter */
15339235Sgibbs	u_int8_t		isp_loopid;	/* hard loop id */
15439235Sgibbs	u_int8_t		isp_alpa;	/* ALPA */
15539235Sgibbs	u_int8_t		isp_execthrottle;
15639235Sgibbs        u_int8_t		isp_retry_delay;
15735388Smjacob        u_int8_t		isp_retry_count;
15835388Smjacob	u_int8_t		isp_fwstate;	/* ISP F/W state */
15939235Sgibbs	u_int16_t		isp_maxalloc;
16039235Sgibbs	u_int16_t		isp_maxfrmlen;
16139235Sgibbs	u_int16_t		isp_fwoptions;
16235388Smjacob	/*
16335388Smjacob	 * Scratch DMA mapped in area to fetch Port Database stuff, etc.
16435388Smjacob	 */
16535388Smjacob	volatile caddr_t	isp_scratch;
16635388Smjacob	u_int32_t		isp_scdma;
16735388Smjacob} fcparam;
16835388Smjacob
16935388Smjacob#define	ISP2100_SCRLEN		0x100
17035388Smjacob
17135388Smjacob#define	FW_CONFIG_WAIT		0x0000
17235388Smjacob#define	FW_WAIT_AL_PA		0x0001
17335388Smjacob#define	FW_WAIT_LOGIN		0x0002
17435388Smjacob#define	FW_READY		0x0003
17535388Smjacob#define	FW_LOSS_OF_SYNC		0x0004
17635388Smjacob#define	FW_ERROR		0x0005
17735388Smjacob#define	FW_REINIT		0x0006
17835388Smjacob#define	FW_NON_PART		0x0007
17935388Smjacob
18041519Smjacob
18135388Smjacob/*
18235388Smjacob * Soft Structure per host adapter
18335388Smjacob */
18435388Smjacobstruct ispsoftc {
18535388Smjacob	/*
18635388Smjacob	 * Platform (OS) specific data
18735388Smjacob	 */
18835388Smjacob	struct isposinfo	isp_osinfo;
18935388Smjacob
19035388Smjacob	/*
19135388Smjacob	 * Pointer to bus specific data
19235388Smjacob	 */
19335388Smjacob	struct ispmdvec *	isp_mdvec;
19435388Smjacob
19535388Smjacob	/*
19641519Smjacob	 * Mostly nonvolatile state, debugging, etc..
19735388Smjacob	 */
19835388Smjacob
19939235Sgibbs	u_int				: 8,
20039235Sgibbs			isp_confopts	: 8,
20139235Sgibbs					: 2,
20239235Sgibbs			isp_dblev	: 3,
20339235Sgibbs			isp_gotdparms	: 1,
20435388Smjacob			isp_dogactive	: 1,
20539235Sgibbs			isp_bustype	: 1,	/* BUS Implementation */
20639235Sgibbs			isp_type	: 8;	/* HBA Type and Revision */
20735388Smjacob
20839235Sgibbs	u_int16_t		isp_fwrev;	/* Running F/W revision */
20939235Sgibbs	u_int16_t		isp_romfw_rev;	/* 'ROM' F/W revision */
21039235Sgibbs	void * 			isp_param;
21139235Sgibbs
21235388Smjacob	/*
21339235Sgibbs	 * Volatile state
21435388Smjacob	 */
21535388Smjacob
21639235Sgibbs	volatile u_int
21739235Sgibbs				:	19,
21839235Sgibbs		isp_state	:	3,
21939235Sgibbs		isp_sendmarker	:	1,	/* send a marker entry */
22039235Sgibbs		isp_update	:	1,	/* update paramters */
22139235Sgibbs		isp_nactive	:	9;	/* how many commands active */
22239235Sgibbs
22335388Smjacob	/*
22439235Sgibbs	 * Result and Request Queue indices.
22535388Smjacob	 */
22639235Sgibbs	volatile u_int8_t	isp_reqodx;	/* index of last ISP pickup */
22735388Smjacob	volatile u_int8_t	isp_reqidx;	/* index of next request */
22835388Smjacob	volatile u_int8_t	isp_residx;	/* index of next result */
22939235Sgibbs	volatile u_int8_t	isp_seqno;	/* rolling sequence # */
23035388Smjacob
23135388Smjacob	/*
23235388Smjacob	 * Sheer laziness, but it gets us around the problem
23335388Smjacob	 * where we don't have a clean way of remembering
23435388Smjacob	 * which transaction is bound to which ISP queue entry.
23535388Smjacob	 *
23635388Smjacob	 * There are other more clever ways to do this, but,
23735388Smjacob	 * jeez, so I blow a couple of KB per host adapter...
23835388Smjacob	 * and it *is* faster.
23935388Smjacob	 */
24039235Sgibbs	volatile ISP_SCSI_XFER_T *isp_xflist[RQUEST_QUEUE_LEN];
24135388Smjacob
24235388Smjacob	/*
24339235Sgibbs	 * request/result queues and dma handles for them.
24435388Smjacob	 */
24535388Smjacob	volatile caddr_t	isp_rquest;
24635388Smjacob	volatile caddr_t	isp_result;
24735388Smjacob	u_int32_t		isp_rquest_dma;
24835388Smjacob	u_int32_t		isp_result_dma;
24941519Smjacob
25035388Smjacob};
25135388Smjacob
25235388Smjacob/*
25335388Smjacob * ISP States
25435388Smjacob */
25535388Smjacob#define	ISP_NILSTATE	0
25635388Smjacob#define	ISP_RESETSTATE	1
25735388Smjacob#define	ISP_INITSTATE	2
25835388Smjacob#define	ISP_RUNSTATE	3
25935388Smjacob
26035388Smjacob/*
26135388Smjacob * ISP Configuration Options
26235388Smjacob */
26335388Smjacob#define	ISP_CFG_NORELOAD	0x80	/* don't download f/w */
26435388Smjacob
26539235Sgibbs#define	ISP_FW_REV(maj, min)	((maj) << 10| (min))
26639235Sgibbs
26735388Smjacob/*
26839235Sgibbs * Bus (implementation) types
26935388Smjacob */
27039235Sgibbs#define	ISP_BT_PCI		0	/* PCI Implementations */
27139235Sgibbs#define	ISP_BT_SBUS		1	/* SBus Implementations */
27239235Sgibbs
27339235Sgibbs/*
27439235Sgibbs * Chip Types
27539235Sgibbs */
27635388Smjacob#define	ISP_HA_SCSI		0xf
27739235Sgibbs#define	ISP_HA_SCSI_UNKNOWN	0x1
27839235Sgibbs#define	ISP_HA_SCSI_1020	0x2
27939235Sgibbs#define	ISP_HA_SCSI_1020A	0x3
28039235Sgibbs#define	ISP_HA_SCSI_1040	0x4
28139235Sgibbs#define	ISP_HA_SCSI_1040A	0x5
28239235Sgibbs#define	ISP_HA_SCSI_1040B	0x6
28335388Smjacob#define	ISP_HA_FC		0xf0
28435388Smjacob#define	ISP_HA_FC_2100		0x10
28535388Smjacob
28635388Smjacob/*
28735388Smjacob * Macros to read, write ISP registers through MD code
28835388Smjacob */
28935388Smjacob
29035388Smjacob#define	ISP_READ(isp, reg)	\
29135388Smjacob	(*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
29235388Smjacob
29335388Smjacob#define	ISP_WRITE(isp, reg, val)	\
29435388Smjacob	(*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
29535388Smjacob
29635388Smjacob#define	ISP_MBOXDMASETUP(isp)	\
29735388Smjacob	(*(isp)->isp_mdvec->dv_mbxdma)((isp))
29835388Smjacob
29935388Smjacob#define	ISP_DMASETUP(isp, xs, req, iptrp, optr)	\
30035388Smjacob	(*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr))
30135388Smjacob
30235388Smjacob#define	ISP_DMAFREE(isp, xs, seqno)	\
30335388Smjacob	if ((isp)->isp_mdvec->dv_dmaclr) \
30435388Smjacob		 (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (seqno))
30535388Smjacob
30635388Smjacob#define	ISP_RESET0(isp)	\
30735388Smjacob	if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp))
30835388Smjacob#define	ISP_RESET1(isp)	\
30935388Smjacob	if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp))
31035388Smjacob#define	ISP_DUMPREGS(isp)	\
31135388Smjacob	if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp))
31235388Smjacob
31335388Smjacob#define	ISP_SETBITS(isp, reg, val)	\
31435388Smjacob (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
31535388Smjacob
31635388Smjacob#define	ISP_CLRBITS(isp, reg, val)	\
31735388Smjacob (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
31835388Smjacob
31935388Smjacob/*
32035388Smjacob * Function Prototypes
32135388Smjacob */
32235388Smjacob
32335388Smjacob/*
32439235Sgibbs * Reset Hardware. Totally. Assumes that you'll follow this with
32539235Sgibbs * a call to isp_init.
32635388Smjacob */
32735388Smjacobvoid isp_reset __P((struct ispsoftc *));
32835388Smjacob
32935388Smjacob/*
33035388Smjacob * Initialize Hardware to known state
33135388Smjacob */
33235388Smjacobvoid isp_init __P((struct ispsoftc *));
33335388Smjacob
33435388Smjacob/*
33535388Smjacob * Free any associated resources prior to decommissioning.
33635388Smjacob */
33735388Smjacobvoid isp_uninit __P((struct ispsoftc *));
33835388Smjacob
33935388Smjacob/*
34039235Sgibbs * Reset the ISP and call completion for any orphaned commands.
34139235Sgibbs */
34239235Sgibbsvoid isp_restart __P((struct ispsoftc *));
34339235Sgibbs
34439235Sgibbs/*
34535388Smjacob * Interrupt Service Routine
34635388Smjacob */
34735388Smjacobint isp_intr __P((void *));
34835388Smjacob
34935388Smjacob/*
35035388Smjacob * Watchdog Routine
35135388Smjacob */
35235388Smjacobvoid isp_watch __P((void *));
35335388Smjacob
35435388Smjacob/*
35535388Smjacob * Command Entry Point
35635388Smjacob */
35739235Sgibbsint32_t ispscsicmd __P((ISP_SCSI_XFER_T *));
35835388Smjacob
35939235Sgibbs/*
36039235Sgibbs * Platform Dependent to Internal Control Point
36139235Sgibbs *
36239235Sgibbs * For: 	Aborting a running command	- arg is an ISP_SCSI_XFER_T *
36339235Sgibbs *		Resetting a Device		- arg is target to reset
36439235Sgibbs *		Resetting a BUS			- arg is ignored
36539235Sgibbs *		Updating parameters		- arg is ignored
36639235Sgibbs *
36739235Sgibbs * Second argument is an index into xflist array.
36839235Sgibbs * Assumes all locks must be held already.
36939235Sgibbs */
37039235Sgibbstypedef enum {
37139235Sgibbs	ISPCTL_RESET_BUS,
37239235Sgibbs	ISPCTL_RESET_DEV,
37339235Sgibbs	ISPCTL_ABORT_CMD,
37439235Sgibbs	ISPCTL_UPDATE_PARAMS,
37539235Sgibbs} ispctl_t;
37639235Sgibbsint isp_control __P((struct ispsoftc *, ispctl_t, void *));
37739235Sgibbs
37839235Sgibbs/*
37939235Sgibbs * lost command routine (XXXX IN TRANSITION XXXX)
38039235Sgibbs */
38139235Sgibbsvoid isp_lostcmd __P((struct ispsoftc *, ISP_SCSI_XFER_T *));
38239235Sgibbs
38339235Sgibbs
38435388Smjacob#endif	/* _ISPVAR_H */
385