Home | History | Annotate | Line # | Download | only in ic
ispvar.h revision 1.33
      1  1.33   mjacob /* $NetBSD: ispvar.h,v 1.33 2000/08/08 22:58:32 mjacob Exp $ */
      2   1.1      cgd /*
      3  1.24   mjacob  * Copyright (C) 1999 National Aeronautics & Space Administration
      4  1.23   mjacob  * All rights reserved.
      5   1.1      cgd  *
      6   1.1      cgd  * Redistribution and use in source and binary forms, with or without
      7   1.1      cgd  * modification, are permitted provided that the following conditions
      8   1.1      cgd  * are met:
      9   1.1      cgd  * 1. Redistributions of source code must retain the above copyright
     10  1.23   mjacob  *    notice, this list of conditions and the following disclaimer.
     11   1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     13   1.1      cgd  *    documentation and/or other materials provided with the distribution.
     14   1.1      cgd  * 3. The name of the author may not be used to endorse or promote products
     15  1.23   mjacob  *    derived from this software without specific prior written permission
     16   1.9   mjacob  *
     17  1.23   mjacob  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  1.23   mjacob  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  1.23   mjacob  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  1.23   mjacob  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  1.23   mjacob  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  1.23   mjacob  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  1.23   mjacob  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  1.23   mjacob  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  1.23   mjacob  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26  1.23   mjacob  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27   1.1      cgd  */
     28   1.2      cgd 
     29  1.23   mjacob /*
     30  1.23   mjacob  * Soft Definitions for for Qlogic ISP SCSI adapters.
     31  1.23   mjacob  * Matthew Jacob <mjacob (at) nas.nasa.gov>
     32  1.23   mjacob  */
     33   1.1      cgd #ifndef	_ISPVAR_H
     34   1.1      cgd #define	_ISPVAR_H
     35   1.1      cgd 
     36  1.19   mjacob #if defined(__NetBSD__) || defined(__OpenBSD__)
     37   1.1      cgd #include <dev/ic/ispmbox.h>
     38  1.26   mjacob #ifdef	ISP_TARGET_MODE
     39  1.26   mjacob #include <dev/ic/isp_target.h>
     40  1.29   mjacob #include <dev/ic/isp_tpublic.h>
     41  1.26   mjacob #endif
     42   1.9   mjacob #endif
     43   1.9   mjacob #ifdef	__FreeBSD__
     44   1.9   mjacob #include <dev/isp/ispmbox.h>
     45  1.26   mjacob #ifdef	ISP_TARGET_MODE
     46  1.26   mjacob #include <dev/isp/isp_target.h>
     47  1.29   mjacob #include <dev/isp/isp_tpublic.h>
     48  1.26   mjacob #endif
     49   1.9   mjacob #endif
     50   1.9   mjacob #ifdef	__linux__
     51  1.15   mjacob #include "ispmbox.h"
     52  1.26   mjacob #ifdef	ISP_TARGET_MODE
     53  1.26   mjacob #include "isp_target.h"
     54  1.29   mjacob #include "isp_tpublic.h"
     55  1.26   mjacob #endif
     56   1.9   mjacob #endif
     57   1.1      cgd 
     58  1.32   mjacob #define	ISP_CORE_VERSION_MAJOR	2
     59  1.32   mjacob #define	ISP_CORE_VERSION_MINOR	0
     60  1.10   mjacob 
     61   1.1      cgd /*
     62  1.17   mjacob  * Vector for bus specific code to provide specific services.
     63   1.1      cgd  */
     64   1.1      cgd struct ispsoftc;
     65   1.1      cgd struct ispmdvec {
     66   1.1      cgd 	u_int16_t	(*dv_rd_reg) __P((struct ispsoftc *, int));
     67   1.1      cgd 	void		(*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t));
     68   1.5  thorpej 	int		(*dv_mbxdma) __P((struct ispsoftc *));
     69   1.1      cgd 	int		(*dv_dmaset) __P((struct ispsoftc *,
     70  1.32   mjacob 		XS_T *, ispreq_t *, u_int16_t *, u_int16_t));
     71   1.1      cgd 	void		(*dv_dmaclr)
     72  1.32   mjacob 		__P((struct ispsoftc *, XS_T *, u_int32_t));
     73   1.1      cgd 	void		(*dv_reset0) __P((struct ispsoftc *));
     74   1.1      cgd 	void		(*dv_reset1) __P((struct ispsoftc *));
     75  1.32   mjacob 	void		(*dv_dregs) __P((struct ispsoftc *, const char *));
     76  1.31   mjacob 	const u_int16_t	*dv_ispfw;	/* ptr to f/w */
     77   1.1      cgd 	u_int16_t	dv_conf1;
     78   1.4   mjacob 	u_int16_t	dv_clock;	/* clock frequency */
     79   1.1      cgd };
     80   1.1      cgd 
     81  1.32   mjacob /*
     82  1.32   mjacob  * Overall parameters
     83  1.32   mjacob  */
     84   1.1      cgd #define	MAX_TARGETS	16
     85  1.19   mjacob #ifdef	ISP2100_FABRIC
     86  1.19   mjacob #define	MAX_FC_TARG	256
     87  1.19   mjacob #else
     88   1.6   mjacob #define	MAX_FC_TARG	126
     89  1.19   mjacob #endif
     90   1.1      cgd 
     91  1.24   mjacob #define	ISP_MAX_TARGETS(isp)	(IS_FC(isp)? MAX_FC_TARG : MAX_TARGETS)
     92  1.31   mjacob #define	ISP_MAX_LUNS(isp)	(isp)->isp_maxluns
     93  1.24   mjacob 
     94  1.26   mjacob 
     95  1.26   mjacob /*
     96  1.32   mjacob  * Macros to access ISP registers through bus specific layers-
     97  1.32   mjacob  * mostly wrappers to vector through the mdvec structure.
     98  1.26   mjacob  */
     99  1.26   mjacob 
    100  1.26   mjacob #define	ISP_READ(isp, reg)	\
    101  1.26   mjacob 	(*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
    102  1.26   mjacob 
    103  1.26   mjacob #define	ISP_WRITE(isp, reg, val)	\
    104  1.26   mjacob 	(*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
    105  1.26   mjacob 
    106  1.26   mjacob #define	ISP_MBOXDMASETUP(isp)	\
    107  1.26   mjacob 	(*(isp)->isp_mdvec->dv_mbxdma)((isp))
    108  1.26   mjacob 
    109  1.26   mjacob #define	ISP_DMASETUP(isp, xs, req, iptrp, optr)	\
    110  1.26   mjacob 	(*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr))
    111  1.26   mjacob 
    112  1.26   mjacob #define	ISP_DMAFREE(isp, xs, hndl)	\
    113  1.26   mjacob 	if ((isp)->isp_mdvec->dv_dmaclr) \
    114  1.26   mjacob 	    (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (hndl))
    115  1.26   mjacob 
    116  1.26   mjacob #define	ISP_RESET0(isp)	\
    117  1.26   mjacob 	if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp))
    118  1.26   mjacob #define	ISP_RESET1(isp)	\
    119  1.26   mjacob 	if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp))
    120  1.32   mjacob #define	ISP_DUMPREGS(isp, m)	\
    121  1.32   mjacob 	if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp),(m))
    122  1.26   mjacob 
    123  1.26   mjacob #define	ISP_SETBITS(isp, reg, val)	\
    124  1.26   mjacob  (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
    125  1.26   mjacob 
    126  1.26   mjacob #define	ISP_CLRBITS(isp, reg, val)	\
    127  1.26   mjacob  (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
    128  1.26   mjacob 
    129  1.32   mjacob /*
    130  1.32   mjacob  * The MEMORYBARRIER macro is defined per platform (to provide synchronization
    131  1.32   mjacob  * on Request and Response Queues, Scratch DMA areas, and Registers)
    132  1.32   mjacob  *
    133  1.32   mjacob  * Defined Memory Barrier Synchronization Types
    134  1.32   mjacob  */
    135  1.32   mjacob #define	SYNC_REQUEST	0	/* request queue synchronization */
    136  1.32   mjacob #define	SYNC_RESULT	1	/* result queue synchronization */
    137  1.32   mjacob #define	SYNC_SFORDEV	2	/* scratch, sync for ISP */
    138  1.32   mjacob #define	SYNC_SFORCPU	3	/* scratch, sync for CPU */
    139  1.32   mjacob #define	SYNC_REG	4	/* for registers */
    140  1.32   mjacob 
    141  1.32   mjacob /*
    142  1.32   mjacob  * Request/Response Queue defines and macros.
    143  1.32   mjacob  * The maximum is defined per platform (and can be based on board type).
    144  1.32   mjacob  */
    145  1.32   mjacob /* This is the size of a queue entry (request and response) */
    146  1.11   mjacob #define	QENTRY_LEN			64
    147  1.32   mjacob /* Both request and result queue length must be a power of two */
    148  1.32   mjacob #define	RQUEST_QUEUE_LEN(x)		MAXISPREQUEST(x)
    149  1.32   mjacob #define	RESULT_QUEUE_LEN(x)		\
    150  1.32   mjacob 	(((MAXISPREQUEST(x) >> 2) < 64)? 64 : MAXISPREQUEST(x) >> 2)
    151  1.11   mjacob #define	ISP_QUEUE_ENTRY(q, idx)		((q) + ((idx) * QENTRY_LEN))
    152  1.11   mjacob #define	ISP_QUEUE_SIZE(n)		((n) * QENTRY_LEN)
    153  1.11   mjacob #define	ISP_NXT_QENTRY(idx, qlen)	(((idx) + 1) & ((qlen)-1))
    154  1.25   mjacob #define	ISP_QAVAIL(in, out, qlen)	\
    155  1.13   mjacob 	((in == out)? (qlen - 1) : ((in > out)? \
    156  1.25   mjacob 	((qlen - 1) - (in - out)) : (out - in - 1)))
    157  1.26   mjacob 
    158  1.26   mjacob #define	ISP_ADD_REQUEST(isp, iptr)	\
    159  1.32   mjacob 	MEMORYBARRIER(isp, SYNC_REQUEST, iptr, QENTRY_LEN); \
    160  1.32   mjacob 	ISP_WRITE(isp, INMAILBOX4, iptr); \
    161  1.32   mjacob 	isp->isp_reqidx = iptr
    162  1.26   mjacob 
    163   1.1      cgd /*
    164  1.22   mjacob  * SCSI Specific Host Adapter Parameters- per bus, per target
    165   1.6   mjacob  */
    166   1.6   mjacob 
    167   1.6   mjacob typedef struct {
    168  1.22   mjacob 	u_int		isp_gotdparms		: 1,
    169  1.25   mjacob 			isp_req_ack_active_neg	: 1,
    170  1.25   mjacob 			isp_data_line_active_neg: 1,
    171   1.6   mjacob 			isp_cmd_dma_burst_enable: 1,
    172   1.6   mjacob 			isp_data_dma_burst_enabl: 1,
    173  1.16   mjacob 			isp_fifo_threshold	: 3,
    174  1.17   mjacob 			isp_ultramode		: 1,
    175   1.6   mjacob 			isp_diffmode		: 1,
    176  1.20   mjacob 			isp_lvdmode		: 1,
    177  1.33   mjacob 			isp_fast_mttr		: 1,	/* fast sram */
    178   1.6   mjacob 			isp_initiator_id	: 4,
    179  1.25   mjacob 			isp_async_data_setup	: 4;
    180  1.25   mjacob 	u_int16_t	isp_selection_timeout;
    181  1.25   mjacob 	u_int16_t	isp_max_queue_depth;
    182   1.6   mjacob 	u_int8_t	isp_tag_aging;
    183  1.25   mjacob 	u_int8_t	isp_bus_reset_delay;
    184  1.25   mjacob 	u_int8_t	isp_retry_count;
    185  1.25   mjacob 	u_int8_t	isp_retry_delay;
    186   1.6   mjacob 	struct {
    187  1.22   mjacob 		u_int	dev_enable	:	1,	/* ignored */
    188  1.22   mjacob 					:	1,
    189  1.17   mjacob 			dev_update	:	1,
    190  1.17   mjacob 			dev_refresh	:	1,
    191  1.20   mjacob 			exc_throttle	:	8,
    192  1.20   mjacob 			cur_offset	:	4,
    193  1.20   mjacob 			sync_offset	:	4;
    194  1.20   mjacob 		u_int8_t	cur_period;	/* current sync period */
    195  1.20   mjacob 		u_int8_t	sync_period;	/* goal sync period */
    196  1.20   mjacob 		u_int16_t	dev_flags;	/* goal device flags */
    197  1.20   mjacob 		u_int16_t	cur_dflags;	/* current device flags */
    198   1.6   mjacob 	} isp_devparam[MAX_TARGETS];
    199  1.22   mjacob } sdparam;
    200   1.6   mjacob 
    201   1.6   mjacob /*
    202   1.6   mjacob  * Device Flags
    203   1.6   mjacob  */
    204  1.11   mjacob #define	DPARM_DISC	0x8000
    205  1.11   mjacob #define	DPARM_PARITY	0x4000
    206  1.11   mjacob #define	DPARM_WIDE	0x2000
    207  1.11   mjacob #define	DPARM_SYNC	0x1000
    208  1.11   mjacob #define	DPARM_TQING	0x0800
    209  1.11   mjacob #define	DPARM_ARQ	0x0400
    210  1.11   mjacob #define	DPARM_QFRZ	0x0200
    211  1.11   mjacob #define	DPARM_RENEG	0x0100
    212  1.33   mjacob #define	DPARM_NARROW	0x0080
    213  1.33   mjacob #define	DPARM_ASYNC	0x0040
    214  1.33   mjacob #define	DPARM_PPR	0x0020
    215  1.18   mjacob #define	DPARM_DEFAULT	(0xFF00 & ~DPARM_QFRZ)
    216  1.11   mjacob #define	DPARM_SAFE_DFLT	(DPARM_DEFAULT & ~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING))
    217  1.11   mjacob 
    218   1.6   mjacob 
    219  1.20   mjacob /* technically, not really correct, as they need to be rated based upon clock */
    220  1.33   mjacob #define	ISP_80M_SYNCPARMS	0x0c09
    221  1.33   mjacob #define	ISP_40M_SYNCPARMS	0x0c0a
    222  1.33   mjacob #define	ISP_20M_SYNCPARMS	0x0c0c
    223  1.33   mjacob #define	ISP_20M_SYNCPARMS_1040	0x080c
    224  1.25   mjacob #define	ISP_10M_SYNCPARMS	0x0c19
    225  1.25   mjacob #define	ISP_08M_SYNCPARMS	0x0c25
    226  1.25   mjacob #define	ISP_05M_SYNCPARMS	0x0c32
    227  1.25   mjacob #define	ISP_04M_SYNCPARMS	0x0c41
    228   1.6   mjacob 
    229   1.6   mjacob /*
    230   1.6   mjacob  * Fibre Channel Specifics
    231   1.6   mjacob  */
    232  1.24   mjacob #define	FL_PORT_ID		0x7e	/* FL_Port Special ID */
    233  1.24   mjacob #define	FC_PORT_ID		0x7f	/* Fabric Controller Special ID */
    234  1.24   mjacob #define	FC_SNS_ID		0x80	/* SNS Server Special ID */
    235  1.24   mjacob 
    236   1.6   mjacob typedef struct {
    237  1.25   mjacob 	u_int32_t		isp_fwoptions	: 16,
    238  1.30       he 						: 4,
    239  1.23   mjacob 				loop_seen_once	: 1,
    240  1.23   mjacob 				isp_loopstate	: 3,	/* Current Loop State */
    241  1.23   mjacob 				isp_fwstate	: 3,	/* ISP F/W state */
    242  1.23   mjacob 				isp_gotdparms	: 1,
    243  1.30       he 				isp_topo	: 3,
    244  1.23   mjacob 				isp_onfabric	: 1;
    245  1.11   mjacob 	u_int8_t		isp_loopid;	/* hard loop id */
    246  1.11   mjacob 	u_int8_t		isp_alpa;	/* ALPA */
    247  1.25   mjacob 	volatile u_int16_t	isp_lipseq;	/* LIP sequence # */
    248  1.23   mjacob 	u_int32_t		isp_portid;
    249  1.11   mjacob 	u_int8_t		isp_execthrottle;
    250  1.25   mjacob 	u_int8_t		isp_retry_delay;
    251  1.25   mjacob 	u_int8_t		isp_retry_count;
    252  1.25   mjacob 	u_int8_t		isp_reserved;
    253  1.11   mjacob 	u_int16_t		isp_maxalloc;
    254  1.11   mjacob 	u_int16_t		isp_maxfrmlen;
    255  1.23   mjacob 	u_int64_t		isp_nodewwn;
    256  1.23   mjacob 	u_int64_t		isp_portwwn;
    257   1.6   mjacob 	/*
    258  1.23   mjacob 	 * Port Data Base. This is indexed by 'target', which is invariate.
    259  1.23   mjacob 	 * However, elements within can move around due to loop changes,
    260  1.23   mjacob 	 * so the actual loop ID passed to the F/W is in this structure.
    261  1.23   mjacob 	 * The first time the loop is seen up, loopid will match the index
    262  1.23   mjacob 	 * (except for fabric nodes which are above mapped above FC_SNS_ID
    263  1.23   mjacob 	 * and are completely virtual), but subsequent LIPs can cause things
    264  1.23   mjacob 	 * to move around.
    265  1.23   mjacob 	 */
    266  1.23   mjacob 	struct lportdb {
    267  1.25   mjacob 		u_int
    268  1.30       he 					loopid		: 8,
    269  1.30       he 							: 4,
    270  1.30       he 					loggedin	: 1,
    271  1.30       he 					roles		: 2,
    272  1.30       he 					valid		: 1;
    273  1.25   mjacob 		u_int32_t		portid;
    274  1.23   mjacob 		u_int64_t		node_wwn;
    275  1.23   mjacob 		u_int64_t		port_wwn;
    276  1.24   mjacob 	} portdb[MAX_FC_TARG], tport[FL_PORT_ID];
    277  1.19   mjacob 
    278  1.19   mjacob 	/*
    279   1.6   mjacob 	 * Scratch DMA mapped in area to fetch Port Database stuff, etc.
    280   1.6   mjacob 	 */
    281  1.23   mjacob 	caddr_t			isp_scratch;
    282   1.6   mjacob 	u_int32_t		isp_scdma;
    283   1.6   mjacob } fcparam;
    284   1.6   mjacob 
    285  1.23   mjacob #define	FW_CONFIG_WAIT		0
    286  1.23   mjacob #define	FW_WAIT_AL_PA		1
    287  1.23   mjacob #define	FW_WAIT_LOGIN		2
    288  1.23   mjacob #define	FW_READY		3
    289  1.23   mjacob #define	FW_LOSS_OF_SYNC		4
    290  1.23   mjacob #define	FW_ERROR		5
    291  1.23   mjacob #define	FW_REINIT		6
    292  1.23   mjacob #define	FW_NON_PART		7
    293  1.23   mjacob 
    294  1.23   mjacob #define	LOOP_NIL		0
    295  1.23   mjacob #define	LOOP_LIP_RCVD		1
    296  1.23   mjacob #define	LOOP_PDB_RCVD		2
    297  1.23   mjacob #define	LOOP_READY		7
    298  1.30       he 
    299  1.30       he #define	TOPO_NL_PORT		0
    300  1.30       he #define	TOPO_FL_PORT		1
    301  1.30       he #define	TOPO_N_PORT		2
    302  1.30       he #define	TOPO_F_PORT		3
    303  1.30       he #define	TOPO_PTP_STUB		4
    304  1.23   mjacob 
    305   1.6   mjacob /*
    306   1.1      cgd  * Soft Structure per host adapter
    307   1.1      cgd  */
    308  1.33   mjacob typedef struct ispsoftc {
    309   1.9   mjacob 	/*
    310   1.9   mjacob 	 * Platform (OS) specific data
    311   1.9   mjacob 	 */
    312   1.9   mjacob 	struct isposinfo	isp_osinfo;
    313   1.9   mjacob 
    314   1.9   mjacob 	/*
    315  1.26   mjacob 	 * Pointer to bus specific functions and data
    316   1.9   mjacob 	 */
    317   1.1      cgd 	struct ispmdvec *	isp_mdvec;
    318   1.9   mjacob 
    319   1.9   mjacob 	/*
    320  1.26   mjacob 	 * (Mostly) nonvolatile state. Board specific parameters
    321  1.26   mjacob 	 * may contain some volatile state (e.g., current loop state).
    322   1.9   mjacob 	 */
    323   1.9   mjacob 
    324  1.26   mjacob 	void * 			isp_param;	/* type specific */
    325  1.26   mjacob 	u_int16_t		isp_fwrev[3];	/* Loaded F/W revision */
    326  1.26   mjacob 	u_int16_t		isp_romfw_rev[3]; /* PROM F/W revision */
    327  1.26   mjacob 	u_int16_t		isp_maxcmds;	/* max possible I/O cmds */
    328  1.26   mjacob 	u_int8_t		isp_type;	/* HBA Chip Type */
    329  1.26   mjacob 	u_int8_t		isp_revision;	/* HBA Chip H/W Revision */
    330  1.31   mjacob 	u_int32_t		isp_maxluns;	/* maximum luns supported */
    331  1.26   mjacob 
    332  1.32   mjacob 	u_int32_t
    333  1.26   mjacob 				isp_touched	: 1,	/* board ever seen? */
    334  1.33   mjacob 						: 1,
    335  1.26   mjacob 				isp_bustype	: 1,	/* SBus or PCI */
    336  1.33   mjacob 				isp_loaded_fw	: 1,	/* loaded firmware */
    337  1.32   mjacob 				isp_dblev	: 12,	/* debug log mask */
    338  1.26   mjacob 				isp_clock	: 8,	/* input clock */
    339  1.26   mjacob 				isp_confopts	: 8;	/* config options */
    340   1.6   mjacob 
    341   1.1      cgd 	/*
    342  1.11   mjacob 	 * Volatile state
    343   1.1      cgd 	 */
    344  1.11   mjacob 
    345  1.31   mjacob 	volatile u_int32_t
    346  1.31   mjacob 		isp_mboxbsy	:	8,	/* mailbox command active */
    347  1.31   mjacob 				:	1,
    348  1.11   mjacob 		isp_state	:	3,
    349  1.22   mjacob 		isp_sendmarker	:	2,	/* send a marker entry */
    350  1.22   mjacob 		isp_update	:	2,	/* update parameters */
    351  1.24   mjacob 		isp_nactive	:	16;	/* how many commands active */
    352  1.24   mjacob 	volatile u_int16_t	isp_reqodx;	/* index of last ISP pickup */
    353  1.24   mjacob 	volatile u_int16_t	isp_reqidx;	/* index of next request */
    354  1.24   mjacob 	volatile u_int16_t	isp_residx;	/* index of next result */
    355  1.24   mjacob 	volatile u_int16_t	isp_lasthdls;	/* last handle seed */
    356  1.31   mjacob 	volatile u_int16_t	isp_mboxtmp[MAX_MAILBOX];
    357   1.6   mjacob 
    358   1.1      cgd 	/*
    359  1.26   mjacob 	 * Active commands are stored here, indexed by handle functions.
    360   1.1      cgd 	 */
    361  1.32   mjacob 	XS_T **isp_xflist;
    362   1.6   mjacob 
    363   1.1      cgd 	/*
    364  1.24   mjacob 	 * request/result queue pointers and dma handles for them.
    365   1.1      cgd 	 */
    366  1.23   mjacob 	caddr_t			isp_rquest;
    367  1.23   mjacob 	caddr_t			isp_result;
    368   1.5  thorpej 	u_int32_t		isp_rquest_dma;
    369   1.5  thorpej 	u_int32_t		isp_result_dma;
    370  1.33   mjacob } ispsoftc_t;
    371  1.14   mjacob 
    372  1.24   mjacob #define	SDPARAM(isp)	((sdparam *) (isp)->isp_param)
    373  1.24   mjacob #define	FCPARAM(isp)	((fcparam *) (isp)->isp_param)
    374   1.1      cgd 
    375   1.1      cgd /*
    376  1.32   mjacob  * ISP Driver Run States
    377   1.9   mjacob  */
    378   1.9   mjacob #define	ISP_NILSTATE	0
    379   1.9   mjacob #define	ISP_RESETSTATE	1
    380   1.9   mjacob #define	ISP_INITSTATE	2
    381   1.9   mjacob #define	ISP_RUNSTATE	3
    382   1.9   mjacob 
    383   1.9   mjacob /*
    384   1.9   mjacob  * ISP Configuration Options
    385   1.9   mjacob  */
    386   1.9   mjacob #define	ISP_CFG_NORELOAD	0x80	/* don't download f/w */
    387  1.18   mjacob #define	ISP_CFG_NONVRAM		0x40	/* ignore NVRAM */
    388  1.26   mjacob #define	ISP_CFG_FULL_DUPLEX	0x01	/* Full Duplex (Fibre Channel only) */
    389  1.26   mjacob #define	ISP_CFG_OWNWWN		0x02	/* override NVRAM wwn */
    390  1.29   mjacob #define	ISP_CFG_NPORT		0x04	/* try to force N- instead of L-Port */
    391   1.9   mjacob 
    392  1.32   mjacob /*
    393  1.32   mjacob  * Firmware related defines
    394  1.32   mjacob  */
    395  1.32   mjacob #define	ISP_CODE_ORG		0x1000	/* default f/w code start */
    396  1.21   mjacob #define	ISP_FW_REV(maj, min, mic)	((maj << 24) | (min << 16) | mic)
    397  1.22   mjacob #define	ISP_FW_REVX(xp)	((xp[0]<<24) | (xp[1] << 16) | xp[2])
    398  1.11   mjacob 
    399   1.9   mjacob /*
    400  1.11   mjacob  * Bus (implementation) types
    401  1.11   mjacob  */
    402  1.11   mjacob #define	ISP_BT_PCI		0	/* PCI Implementations */
    403  1.11   mjacob #define	ISP_BT_SBUS		1	/* SBus Implementations */
    404  1.11   mjacob 
    405  1.11   mjacob /*
    406  1.11   mjacob  * Chip Types
    407   1.6   mjacob  */
    408   1.6   mjacob #define	ISP_HA_SCSI		0xf
    409  1.11   mjacob #define	ISP_HA_SCSI_UNKNOWN	0x1
    410  1.11   mjacob #define	ISP_HA_SCSI_1020	0x2
    411  1.11   mjacob #define	ISP_HA_SCSI_1020A	0x3
    412  1.11   mjacob #define	ISP_HA_SCSI_1040	0x4
    413  1.11   mjacob #define	ISP_HA_SCSI_1040A	0x5
    414  1.11   mjacob #define	ISP_HA_SCSI_1040B	0x6
    415  1.21   mjacob #define	ISP_HA_SCSI_1040C	0x7
    416  1.27   mjacob #define	ISP_HA_SCSI_1240	0x8
    417  1.27   mjacob #define	ISP_HA_SCSI_1080	0x9
    418  1.27   mjacob #define	ISP_HA_SCSI_1280	0xa
    419  1.29   mjacob #define	ISP_HA_SCSI_12160	0xb
    420   1.6   mjacob #define	ISP_HA_FC		0xf0
    421   1.6   mjacob #define	ISP_HA_FC_2100		0x10
    422  1.23   mjacob #define	ISP_HA_FC_2200		0x20
    423   1.6   mjacob 
    424  1.19   mjacob #define	IS_SCSI(isp)	(isp->isp_type & ISP_HA_SCSI)
    425  1.27   mjacob #define	IS_1240(isp)	(isp->isp_type == ISP_HA_SCSI_1240)
    426  1.19   mjacob #define	IS_1080(isp)	(isp->isp_type == ISP_HA_SCSI_1080)
    427  1.27   mjacob #define	IS_1280(isp)	(isp->isp_type == ISP_HA_SCSI_1280)
    428  1.29   mjacob #define	IS_12160(isp)	(isp->isp_type == ISP_HA_SCSI_12160)
    429  1.29   mjacob 
    430  1.29   mjacob #define	IS_12X0(isp)	(IS_1240(isp) || IS_1280(isp))
    431  1.29   mjacob #define	IS_DUALBUS(isp)	(IS_12X0(isp) || IS_12160(isp))
    432  1.29   mjacob #define	IS_ULTRA2(isp)	(IS_1080(isp) || IS_1280(isp) || IS_12160(isp))
    433  1.29   mjacob #define	IS_ULTRA3(isp)	(IS_12160(isp))
    434  1.29   mjacob 
    435  1.19   mjacob #define	IS_FC(isp)	(isp->isp_type & ISP_HA_FC)
    436  1.29   mjacob #define	IS_2100(isp)	(isp->isp_type == ISP_HA_FC_2100)
    437  1.29   mjacob #define	IS_2200(isp)	(isp->isp_type == ISP_HA_FC_2200)
    438  1.29   mjacob 
    439  1.32   mjacob /*
    440  1.32   mjacob  * DMA cookie macros
    441  1.32   mjacob  */
    442  1.32   mjacob #define	DMA_MSW(x)	(((x) >> 16) & 0xffff)
    443  1.32   mjacob #define	DMA_LSW(x)	(((x) & 0xffff))
    444  1.19   mjacob 
    445   1.6   mjacob /*
    446  1.32   mjacob  * Core System Function Prototypes
    447   1.1      cgd  */
    448   1.9   mjacob 
    449   1.1      cgd /*
    450   1.9   mjacob  * Reset Hardware. Totally. Assumes that you'll follow this with
    451   1.9   mjacob  * a call to isp_init.
    452   1.1      cgd  */
    453   1.1      cgd void isp_reset __P((struct ispsoftc *));
    454   1.1      cgd 
    455   1.1      cgd /*
    456   1.1      cgd  * Initialize Hardware to known state
    457   1.1      cgd  */
    458   1.1      cgd void isp_init __P((struct ispsoftc *));
    459   1.1      cgd 
    460   1.1      cgd /*
    461  1.10   mjacob  * Reset the ISP and call completion for any orphaned commands.
    462  1.10   mjacob  */
    463  1.32   mjacob void isp_reinit __P((struct ispsoftc *));
    464   1.1      cgd 
    465   1.1      cgd /*
    466   1.1      cgd  * Interrupt Service Routine
    467   1.1      cgd  */
    468   1.1      cgd int isp_intr __P((void *));
    469   1.9   mjacob 
    470   1.9   mjacob /*
    471  1.32   mjacob  * Command Entry Point- Platform Dependent layers call into this
    472  1.32   mjacob  */
    473  1.32   mjacob int isp_start __P((XS_T *));
    474  1.32   mjacob /* these values are what isp_start returns */
    475  1.32   mjacob #define	CMD_COMPLETE	101	/* command completed */
    476  1.32   mjacob #define	CMD_EAGAIN	102	/* busy- maybe retry later */
    477  1.32   mjacob #define	CMD_QUEUED	103	/* command has been queued for execution */
    478  1.32   mjacob #define	CMD_RQLATER 	104	/* requeue this command later */
    479  1.32   mjacob 
    480  1.32   mjacob /*
    481  1.32   mjacob  * Command Completion Point- Core layers call out from this with completed cmds
    482   1.9   mjacob  */
    483  1.32   mjacob void isp_done __P((XS_T *));
    484   1.1      cgd 
    485   1.9   mjacob /*
    486  1.17   mjacob  * Platform Dependent to External to Internal Control Function
    487   1.9   mjacob  *
    488  1.23   mjacob  * Assumes all locks are held and that no reentrancy issues need be dealt with.
    489   1.9   mjacob  *
    490   1.9   mjacob  */
    491   1.9   mjacob typedef enum {
    492  1.23   mjacob 	ISPCTL_RESET_BUS,		/* Reset Bus */
    493  1.23   mjacob 	ISPCTL_RESET_DEV,		/* Reset Device */
    494  1.23   mjacob 	ISPCTL_ABORT_CMD,		/* Abort Command */
    495  1.23   mjacob 	ISPCTL_UPDATE_PARAMS,		/* Update Operating Parameters */
    496  1.28   mjacob 	ISPCTL_FCLINK_TEST,		/* Test FC Link Status */
    497  1.28   mjacob 	ISPCTL_PDB_SYNC,		/* Synchronize Port Database */
    498  1.28   mjacob 	ISPCTL_TOGGLE_TMODE		/* toggle target mode */
    499   1.9   mjacob } ispctl_t;
    500   1.9   mjacob int isp_control __P((struct ispsoftc *, ispctl_t, void *));
    501  1.17   mjacob 
    502  1.17   mjacob 
    503  1.17   mjacob /*
    504  1.17   mjacob  * Platform Dependent to Internal to External Control Function
    505  1.17   mjacob  * (each platform must provide such a function)
    506  1.17   mjacob  *
    507  1.23   mjacob  * Assumes all locks are held and that no reentrancy issues need be dealt with.
    508  1.17   mjacob  *
    509  1.17   mjacob  */
    510  1.17   mjacob 
    511  1.17   mjacob typedef enum {
    512  1.18   mjacob 	ISPASYNC_NEW_TGT_PARAMS,
    513  1.23   mjacob 	ISPASYNC_BUS_RESET,		/* Bus Was Reset */
    514  1.23   mjacob 	ISPASYNC_LOOP_DOWN,		/* FC Loop Down */
    515  1.23   mjacob 	ISPASYNC_LOOP_UP,		/* FC Loop Up */
    516  1.23   mjacob 	ISPASYNC_PDB_CHANGED,		/* FC Port Data Base Changed */
    517  1.23   mjacob 	ISPASYNC_CHANGE_NOTIFY,		/* FC SNS Change Notification */
    518  1.23   mjacob 	ISPASYNC_FABRIC_DEV,		/* FC New Fabric Device */
    519  1.28   mjacob 	ISPASYNC_TARGET_MESSAGE,	/* target message */
    520  1.28   mjacob 	ISPASYNC_TARGET_EVENT,		/* target asynchronous event */
    521  1.28   mjacob 	ISPASYNC_TARGET_ACTION		/* other target command action */
    522  1.17   mjacob } ispasync_t;
    523  1.17   mjacob int isp_async __P((struct ispsoftc *, ispasync_t, void *));
    524   1.1      cgd 
    525   1.9   mjacob /*
    526  1.32   mjacob  * Platform Dependent Error and Debug Printout
    527   1.9   mjacob  */
    528  1.32   mjacob void isp_prt __P((struct ispsoftc *, int level, const char *, ...));
    529  1.32   mjacob #define	ISP_LOGALL	0x0	/* log always */
    530  1.32   mjacob #define	ISP_LOGCONFIG	0x1	/* log configuration messages */
    531  1.32   mjacob #define	ISP_LOGINFO	0x2	/* log informational messages */
    532  1.32   mjacob #define	ISP_LOGWARN	0x4	/* log warning messages */
    533  1.32   mjacob #define	ISP_LOGERR	0x8	/* log error messages */
    534  1.32   mjacob #define	ISP_LOGDEBUG0	0x10	/* log simple debug messages */
    535  1.32   mjacob #define	ISP_LOGDEBUG1	0x20	/* log intermediate debug messages */
    536  1.32   mjacob #define	ISP_LOGDEBUG2	0x40	/* log most debug messages */
    537  1.32   mjacob #define	ISP_LOGDEBUG3	0x100	/* log high frequency debug messages */
    538  1.32   mjacob #define	ISP_LOGTDEBUG0	0x200	/* log simple debug messages (target mode) */
    539  1.32   mjacob #define	ISP_LOGTDEBUG1	0x400	/* log intermediate debug messages (target) */
    540  1.32   mjacob #define	ISP_LOGTDEBUG2	0x800	/* log all debug messages (target) */
    541   1.1      cgd 
    542  1.32   mjacob /*
    543  1.32   mjacob  * Each Platform provides it's own isposinfo substructure of the ispsoftc
    544  1.32   mjacob  * defined above.
    545  1.32   mjacob  *
    546  1.32   mjacob  * Each platform must also provide the following macros/defines:
    547  1.32   mjacob  *
    548  1.32   mjacob  *
    549  1.32   mjacob  *	INLINE		-	platform specific define for 'inline' functions
    550  1.32   mjacob  *
    551  1.32   mjacob  *	ISP2100_FABRIC	-	defines whether FABRIC support is enabled
    552  1.32   mjacob  *	ISP2100_SCRLEN	-	length for the Fibre Channel scratch DMA area
    553  1.32   mjacob  *
    554  1.32   mjacob  *	MEMZERO(dst, src)			platform zeroing function
    555  1.32   mjacob  *	MEMCPY(dst, src, count)			platform copying function
    556  1.32   mjacob  *	SNPRINTF(buf, bufsize, fmt, ...)	snprintf
    557  1.32   mjacob  *	STRNCAT(dstbuf, size, srcbuf)		strncat
    558  1.32   mjacob  *	USEC_DELAY(usecs)			microsecond spindelay function
    559  1.32   mjacob  *
    560  1.32   mjacob  *	NANOTIME_T				nanosecond time type
    561  1.32   mjacob  *
    562  1.32   mjacob  *	GET_NANOTIME(NANOTIME_T *)		get current nanotime.
    563  1.32   mjacob  *
    564  1.32   mjacob  *	GET_NANOSEC(NANOTIME_T *)		get u_int64_t from NANOTIME_T
    565  1.32   mjacob  *
    566  1.32   mjacob  *	NANOTIME_SUB(NANOTIME_T *, NANOTIME_T *)
    567  1.32   mjacob  *						subtract two NANOTIME_T values
    568  1.32   mjacob  *
    569  1.32   mjacob  *
    570  1.32   mjacob  *	MAXISPREQUEST(struct ispsoftc *)	maximum request queue size
    571  1.32   mjacob  *						for this particular board type
    572  1.32   mjacob  *
    573  1.32   mjacob  *	MEMORYBARRIER(struct ispsoftc *, barrier_type, offset, size)
    574  1.32   mjacob  *
    575  1.32   mjacob  *		Function/Macro the provides memory synchronization on
    576  1.32   mjacob  *		various objects so that the ISP's and the system's view
    577  1.32   mjacob  *		of the same object is consistent.
    578  1.32   mjacob  *
    579  1.32   mjacob  *	MBOX_ACQUIRE(struct ispsoftc *)		acquire lock on mailbox regs
    580  1.32   mjacob  *	MBOX_WAIT_COMPLETE(struct ispsoftc *)	wait for mailbox cmd to be done
    581  1.32   mjacob  *	MBOX_NOTIFY_COMPLETE(struct ispsoftc *)	notification of mbox cmd donee
    582  1.32   mjacob  *	MBOX_RELEASE(struct ispsoftc *)		release lock on mailbox regs
    583  1.32   mjacob  *
    584  1.32   mjacob  *
    585  1.32   mjacob  *	SCSI_GOOD	SCSI 'Good' Status
    586  1.32   mjacob  *	SCSI_CHECK	SCSI 'Check Condition' Status
    587  1.32   mjacob  *	SCSI_BUSY	SCSI 'Busy' Status
    588  1.32   mjacob  *	SCSI_QFULL	SCSI 'Queue Full' Status
    589  1.32   mjacob  *
    590  1.32   mjacob  *	XS_T		Platform SCSI transaction type (i.e., command for HBA)
    591  1.32   mjacob  *	XS_ISP(xs)	gets an instance out of an XS_T
    592  1.32   mjacob  *	XS_CHANNEL(xs)	gets the channel (bus # for DUALBUS cards) ""
    593  1.32   mjacob  *	XS_TGT(xs)	gets the target ""
    594  1.32   mjacob  *	XS_LUN(xs)	gets the lun ""
    595  1.32   mjacob  *	XS_CDBP(xs)	gets a pointer to the scsi CDB ""
    596  1.32   mjacob  *	XS_CDBLEN(xs)	gets the CDB's length ""
    597  1.32   mjacob  *	XS_XFRLEN(xs)	gets the associated data transfer length ""
    598  1.32   mjacob  *	XS_TIME(xs)	gets the time (in milliseconds) for this command
    599  1.32   mjacob  *	XS_RESID(xs)	gets the current residual count
    600  1.32   mjacob  *	XS_STSP(xs)	gets a pointer to the SCSI status byte ""
    601  1.32   mjacob  *	XS_SNSP(xs)	gets a pointer to the associate sense data
    602  1.32   mjacob  *	XS_SNSLEN(xs)	gets the length of sense data storage
    603  1.32   mjacob  *	XS_SNSKEY(xs)	dereferences XS_SNSP to get the current stored Sense Key
    604  1.32   mjacob  *	XS_TAG_P(xs)	predicate of whether this command should be tagged
    605  1.32   mjacob  *	XS_TAG_TYPE(xs)	which type of tag to use
    606  1.32   mjacob  *	XS_SETERR(xs)	set error state
    607  1.32   mjacob  *
    608  1.32   mjacob  *		HBA_NOERROR	command has no erros
    609  1.32   mjacob  *		HBA_BOTCH	hba botched something
    610  1.32   mjacob  *		HBA_CMDTIMEOUT	command timed out
    611  1.32   mjacob  *		HBA_SELTIMEOUT	selection timed out (also port logouts for FC)
    612  1.32   mjacob  *		HBA_TGTBSY	target returned a BUSY status
    613  1.32   mjacob  *		HBA_BUSRESET	bus reset destroyed command
    614  1.32   mjacob  *		HBA_ABORTED	command was aborted (by request)
    615  1.32   mjacob  *		HBA_DATAOVR	a data overrun was detected
    616  1.32   mjacob  *		HBA_ARQFAIL	Automatic Request Sense failed
    617  1.32   mjacob  *
    618  1.32   mjacob  *	XS_ERR(xs)	return current error state
    619  1.32   mjacob  *	XS_NOERR(xs)	there is no error currently set
    620  1.32   mjacob  *	XS_INITERR(xs)	initialize error state
    621  1.32   mjacob  *
    622  1.32   mjacob  *	XS_SAVE_SENSE(xs, sp)		save sense data
    623  1.32   mjacob  *
    624  1.32   mjacob  *	XS_SET_STATE_STAT(isp, sp, xs)	platform dependent interpreter of
    625  1.32   mjacob  *					response queue entry status bits
    626  1.32   mjacob  *
    627  1.32   mjacob  *
    628  1.32   mjacob  *	DEFAULT_IID(struct ispsoftc *)		Default SCSI initiator ID
    629  1.32   mjacob  *
    630  1.32   mjacob  *	DEFAULT_LOOPID(struct ispsoftc *)	Default FC Loop ID
    631  1.32   mjacob  *	DEFAULT_NODEWWN(struct ispsoftc *)	Default FC Node WWN
    632  1.32   mjacob  *	DEFAULT_PORTWWN(struct ispsoftc *)	Default FC Port WWN
    633  1.32   mjacob  *
    634  1.32   mjacob  *	PORT_FROM_NODE_WWN(struct ispsoftc *, u_int64_t nwwn)
    635  1.32   mjacob  *
    636  1.32   mjacob  *		Node to Port WWN generator- this needs to be platform
    637  1.32   mjacob  *		specific so that given a NAA=2 WWN dragged from the Qlogic
    638  1.32   mjacob  *		card's NVRAM, a Port WWN can be generated that has the
    639  1.32   mjacob  *		appropriate bits set in bits 48..60 that are likely to be
    640  1.32   mjacob  *		based on the device instance number.
    641  1.32   mjacob  *
    642  1.32   mjacob  *	(XXX these do endian specific transformations- in transition XXX)
    643  1.32   mjacob  *	ISP_SWIZZLE_ICB
    644  1.32   mjacob  *	ISP_UNSWIZZLE_AND_COPY_PDBP
    645  1.32   mjacob  *	ISP_SWIZZLE_CONTINUATION
    646  1.32   mjacob  *	ISP_SWIZZLE_REQUEST
    647  1.32   mjacob  *	ISP_UNSWIZZLE_RESPONSE
    648  1.32   mjacob  *	ISP_SWIZZLE_SNS_REQ
    649  1.32   mjacob  *	ISP_UNSWIZZLE_SNS_RSP
    650  1.32   mjacob  *	ISP_SWIZZLE_NVRAM_WORD
    651  1.32   mjacob  *
    652  1.32   mjacob  *
    653  1.32   mjacob  */
    654   1.1      cgd #endif	/* _ISPVAR_H */
    655