Home | History | Annotate | Line # | Download | only in ic
ispvar.h revision 1.14
      1 /* $NetBSD: ispvar.h,v 1.14 1998/12/05 19:48:23 mjacob Exp $ */
      2 /* ispvar.h 1.21 */
      3 /*
      4  * Soft Definitions for for Qlogic ISP SCSI adapters.
      5  *
      6  *---------------------------------------
      7  * Copyright (c) 1997, 1998 by Matthew Jacob
      8  * NASA/Ames Research Center
      9  * All rights reserved.
     10  *---------------------------------------
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice immediately at the beginning of the file, without modification,
     16  *    this list of conditions, and the following disclaimer.
     17  * 2. Redistributions in binary form must reproduce the above copyright
     18  *    notice, this list of conditions and the following disclaimer in the
     19  *    documentation and/or other materials provided with the distribution.
     20  * 3. The name of the author may not be used to endorse or promote products
     21  *    derived from this software without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  */
     36 
     37 #ifndef	_ISPVAR_H
     38 #define	_ISPVAR_H
     39 
     40 #ifdef	__NetBSD__
     41 #include <dev/ic/ispmbox.h>
     42 #endif
     43 #ifdef	__FreeBSD__
     44 #include <dev/isp/ispmbox.h>
     45 #endif
     46 #ifdef	__linux__
     47 #include <ispmbox.h>
     48 #endif
     49 
     50 #define	ISP_CORE_VERSION_MAJOR	1
     51 #define	ISP_CORE_VERSION_MINOR	4
     52 
     53 /*
     54  * Vector for MD code to provide specific services.
     55  */
     56 struct ispsoftc;
     57 struct ispmdvec {
     58 	u_int16_t	(*dv_rd_reg) __P((struct ispsoftc *, int));
     59 	void		(*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t));
     60 	int		(*dv_mbxdma) __P((struct ispsoftc *));
     61 	int		(*dv_dmaset) __P((struct ispsoftc *,
     62 		ISP_SCSI_XFER_T *, ispreq_t *, u_int8_t *, u_int8_t));
     63 	void		(*dv_dmaclr)
     64 		__P((struct ispsoftc *, ISP_SCSI_XFER_T *, u_int32_t));
     65 	void		(*dv_reset0) __P((struct ispsoftc *));
     66 	void		(*dv_reset1) __P((struct ispsoftc *));
     67 	void		(*dv_dregs) __P((struct ispsoftc *));
     68 	const u_int16_t *dv_ispfw;	/* ptr to f/w */
     69 	u_int16_t 	dv_fwlen;	/* length of f/w */
     70 	u_int16_t	dv_codeorg;	/* code ORG for f/w */
     71 	u_int16_t	dv_fwrev;	/* f/w revision */
     72 	/*
     73 	 * Initial values for conf1 register
     74 	 */
     75 	u_int16_t	dv_conf1;
     76 	u_int16_t	dv_clock;	/* clock frequency */
     77 };
     78 
     79 #define	MAX_TARGETS	16
     80 #define	MAX_FC_TARG	126
     81 #define	DEFAULT_LOOPID	113
     82 
     83 /* queue length must be a power of two */
     84 #define	QENTRY_LEN			64
     85 #define	RQUEST_QUEUE_LEN		MAXISPREQUEST
     86 #define	RESULT_QUEUE_LEN		(MAXISPREQUEST/4)
     87 #define	ISP_QUEUE_ENTRY(q, idx)		((q) + ((idx) * QENTRY_LEN))
     88 #define	ISP_QUEUE_SIZE(n)		((n) * QENTRY_LEN)
     89 #define	ISP_NXT_QENTRY(idx, qlen)	(((idx) + 1) & ((qlen)-1))
     90 #define ISP_QAVAIL(in, out, qlen)	\
     91 	((in == out)? (qlen - 1) : ((in > out)? \
     92 		((qlen - 1) - (in - out)) : (out - in - 1)))
     93 /*
     94  * SCSI (as opposed to FC-PH) Specific Host Adapter Parameters
     95  */
     96 
     97 typedef struct {
     98         u_int		isp_req_ack_active_neg	: 1,
     99 	        	isp_data_line_active_neg: 1,
    100 			isp_cmd_dma_burst_enable: 1,
    101 			isp_data_dma_burst_enabl: 1,
    102 			isp_fifo_threshold	: 2,
    103 			isp_diffmode		: 1,
    104 			isp_fast_mttr		: 1,
    105 			isp_initiator_id	: 4,
    106         		isp_async_data_setup	: 4;
    107         u_int16_t	isp_selection_timeout;
    108         u_int16_t	isp_max_queue_depth;
    109 	u_int16_t	isp_clock;
    110 	u_int8_t	isp_tag_aging;
    111        	u_int8_t	isp_bus_reset_delay;
    112         u_int8_t	isp_retry_count;
    113         u_int8_t	isp_retry_delay;
    114 	struct {
    115 		u_int	dev_update	:	1,
    116 			dev_enable	:	1,
    117 			exc_throttle	:	7,
    118 			sync_offset	:	4,
    119 			sync_period	:	8;
    120 		u_int16_t dev_flags;		/* persistent device flags */
    121 		u_int16_t cur_dflags;		/* current device flags */
    122 	} isp_devparam[MAX_TARGETS];
    123 } sdparam;	/* scsi device parameters */
    124 
    125 /*
    126  * Device Flags
    127  */
    128 #define	DPARM_DISC	0x8000
    129 #define	DPARM_PARITY	0x4000
    130 #define	DPARM_WIDE	0x2000
    131 #define	DPARM_SYNC	0x1000
    132 #define	DPARM_TQING	0x0800
    133 #define	DPARM_ARQ	0x0400
    134 #define	DPARM_QFRZ	0x0200
    135 #define	DPARM_RENEG	0x0100
    136 #define	DPARM_NARROW	0x0080	/* Possibly only available with >= 7.55 fw */
    137 #define	DPARM_ASYNC	0x0040	/* Possibly only available with >= 7.55 fw */
    138 #define	DPARM_DEFAULT	(0xFFFF & ~DPARM_QFRZ)
    139 #define	DPARM_SAFE_DFLT	(DPARM_DEFAULT & ~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING))
    140 
    141 
    142 #define ISP_20M_SYNCPARMS	0x080c
    143 #define ISP_10M_SYNCPARMS	0x0c19
    144 #define ISP_08M_SYNCPARMS	0x0c25
    145 #define ISP_05M_SYNCPARMS	0x0c32
    146 #define ISP_04M_SYNCPARMS	0x0c41
    147 
    148 /*
    149  * Fibre Channel Specifics
    150  */
    151 typedef struct {
    152 	u_int64_t		isp_wwn;	/* WWN of adapter */
    153 	u_int8_t		isp_loopid;	/* hard loop id */
    154 	u_int8_t		isp_alpa;	/* ALPA */
    155 	u_int8_t		isp_execthrottle;
    156         u_int8_t		isp_retry_delay;
    157         u_int8_t		isp_retry_count;
    158 	u_int8_t		isp_fwstate;	/* ISP F/W state */
    159 	u_int16_t		isp_maxalloc;
    160 	u_int16_t		isp_maxfrmlen;
    161 	u_int16_t		isp_fwoptions;
    162 	/*
    163 	 * Scratch DMA mapped in area to fetch Port Database stuff, etc.
    164 	 */
    165 	volatile caddr_t	isp_scratch;
    166 	u_int32_t		isp_scdma;
    167 } fcparam;
    168 
    169 #define	ISP2100_SCRLEN		0x100
    170 
    171 #define	FW_CONFIG_WAIT		0x0000
    172 #define	FW_WAIT_AL_PA		0x0001
    173 #define	FW_WAIT_LOGIN		0x0002
    174 #define	FW_READY		0x0003
    175 #define	FW_LOSS_OF_SYNC		0x0004
    176 #define	FW_ERROR		0x0005
    177 #define	FW_REINIT		0x0006
    178 #define	FW_NON_PART		0x0007
    179 
    180 
    181 /*
    182  * Soft Structure per host adapter
    183  */
    184 struct ispsoftc {
    185 	/*
    186 	 * Platform (OS) specific data
    187 	 */
    188 	struct isposinfo	isp_osinfo;
    189 
    190 	/*
    191 	 * Pointer to bus specific data
    192 	 */
    193 	struct ispmdvec *	isp_mdvec;
    194 
    195 	/*
    196 	 * Mostly nonvolatile state, debugging, etc..
    197 	 */
    198 
    199 	u_int				: 8,
    200 			isp_confopts	: 8,
    201 					: 2,
    202 			isp_dblev	: 3,
    203 			isp_gotdparms	: 1,
    204 			isp_dogactive	: 1,
    205 			isp_bustype	: 1,	/* BUS Implementation */
    206 			isp_type	: 8;	/* HBA Type and Revision */
    207 
    208 	u_int16_t		isp_fwrev;	/* Running F/W revision */
    209 	u_int16_t		isp_romfw_rev;	/* 'ROM' F/W revision */
    210 	void * 			isp_param;
    211 
    212 	/*
    213 	 * Volatile state
    214 	 */
    215 
    216 	volatile u_int
    217 				:	19,
    218 		isp_state	:	3,
    219 		isp_sendmarker	:	1,	/* send a marker entry */
    220 		isp_update	:	1,	/* update paramters */
    221 		isp_nactive	:	9;	/* how many commands active */
    222 
    223 	/*
    224 	 * Result and Request Queue indices.
    225 	 */
    226 	volatile u_int8_t	isp_reqodx;	/* index of last ISP pickup */
    227 	volatile u_int8_t	isp_reqidx;	/* index of next request */
    228 	volatile u_int8_t	isp_residx;	/* index of next result */
    229 	volatile u_int8_t	isp_seqno;	/* rolling sequence # */
    230 
    231 	/*
    232 	 * Sheer laziness, but it gets us around the problem
    233 	 * where we don't have a clean way of remembering
    234 	 * which transaction is bound to which ISP queue entry.
    235 	 *
    236 	 * There are other more clever ways to do this, but,
    237 	 * jeez, so I blow a couple of KB per host adapter...
    238 	 * and it *is* faster.
    239 	 */
    240 	volatile ISP_SCSI_XFER_T *isp_xflist[RQUEST_QUEUE_LEN];
    241 
    242 	/*
    243 	 * request/result queues and dma handles for them.
    244 	 */
    245 	volatile caddr_t	isp_rquest;
    246 	volatile caddr_t	isp_result;
    247 	u_int32_t		isp_rquest_dma;
    248 	u_int32_t		isp_result_dma;
    249 
    250 };
    251 
    252 /*
    253  * ISP States
    254  */
    255 #define	ISP_NILSTATE	0
    256 #define	ISP_RESETSTATE	1
    257 #define	ISP_INITSTATE	2
    258 #define	ISP_RUNSTATE	3
    259 
    260 /*
    261  * ISP Configuration Options
    262  */
    263 #define	ISP_CFG_NORELOAD	0x80	/* don't download f/w */
    264 
    265 #define	ISP_FW_REV(maj, min)	((maj) << 10| (min))
    266 
    267 /*
    268  * Bus (implementation) types
    269  */
    270 #define	ISP_BT_PCI		0	/* PCI Implementations */
    271 #define	ISP_BT_SBUS		1	/* SBus Implementations */
    272 
    273 /*
    274  * Chip Types
    275  */
    276 #define	ISP_HA_SCSI		0xf
    277 #define	ISP_HA_SCSI_UNKNOWN	0x1
    278 #define	ISP_HA_SCSI_1020	0x2
    279 #define	ISP_HA_SCSI_1020A	0x3
    280 #define	ISP_HA_SCSI_1040	0x4
    281 #define	ISP_HA_SCSI_1040A	0x5
    282 #define	ISP_HA_SCSI_1040B	0x6
    283 #define	ISP_HA_FC		0xf0
    284 #define	ISP_HA_FC_2100		0x10
    285 
    286 /*
    287  * Macros to read, write ISP registers through MD code
    288  */
    289 
    290 #define	ISP_READ(isp, reg)	\
    291 	(*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
    292 
    293 #define	ISP_WRITE(isp, reg, val)	\
    294 	(*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
    295 
    296 #define	ISP_MBOXDMASETUP(isp)	\
    297 	(*(isp)->isp_mdvec->dv_mbxdma)((isp))
    298 
    299 #define	ISP_DMASETUP(isp, xs, req, iptrp, optr)	\
    300 	(*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr))
    301 
    302 #define	ISP_DMAFREE(isp, xs, seqno)	\
    303 	if ((isp)->isp_mdvec->dv_dmaclr) \
    304 		 (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (seqno))
    305 
    306 #define	ISP_RESET0(isp)	\
    307 	if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp))
    308 #define	ISP_RESET1(isp)	\
    309 	if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp))
    310 #define	ISP_DUMPREGS(isp)	\
    311 	if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp))
    312 
    313 #define	ISP_SETBITS(isp, reg, val)	\
    314  (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
    315 
    316 #define	ISP_CLRBITS(isp, reg, val)	\
    317  (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
    318 
    319 /*
    320  * Function Prototypes
    321  */
    322 
    323 /*
    324  * Reset Hardware. Totally. Assumes that you'll follow this with
    325  * a call to isp_init.
    326  */
    327 void isp_reset __P((struct ispsoftc *));
    328 
    329 /*
    330  * Initialize Hardware to known state
    331  */
    332 void isp_init __P((struct ispsoftc *));
    333 
    334 /*
    335  * Free any associated resources prior to decommissioning.
    336  */
    337 void isp_uninit __P((struct ispsoftc *));
    338 
    339 /*
    340  * Reset the ISP and call completion for any orphaned commands.
    341  */
    342 void isp_restart __P((struct ispsoftc *));
    343 
    344 /*
    345  * Interrupt Service Routine
    346  */
    347 int isp_intr __P((void *));
    348 
    349 /*
    350  * Watchdog Routine
    351  */
    352 void isp_watch __P((void *));
    353 
    354 /*
    355  * Command Entry Point
    356  */
    357 int32_t ispscsicmd __P((ISP_SCSI_XFER_T *));
    358 
    359 /*
    360  * Platform Dependent to Internal Control Point
    361  *
    362  * For: 	Aborting a running command	- arg is an ISP_SCSI_XFER_T *
    363  *		Resetting a Device		- arg is target to reset
    364  *		Resetting a BUS			- arg is ignored
    365  *		Updating parameters		- arg is ignored
    366  *
    367  * Second argument is an index into xflist array.
    368  * Assumes all locks must be held already.
    369  */
    370 typedef enum {
    371 	ISPCTL_RESET_BUS,
    372 	ISPCTL_RESET_DEV,
    373 	ISPCTL_ABORT_CMD,
    374 	ISPCTL_UPDATE_PARAMS,
    375 } ispctl_t;
    376 int isp_control __P((struct ispsoftc *, ispctl_t, void *));
    377 
    378 /*
    379  * lost command routine (XXXX IN TRANSITION XXXX)
    380  */
    381 void isp_lostcmd __P((struct ispsoftc *, ISP_SCSI_XFER_T *));
    382 
    383 
    384 #endif	/* _ISPVAR_H */
    385