Home | History | Annotate | Line # | Download | only in ic
ispvar.h revision 1.24
      1 /* $NetBSD: ispvar.h,v 1.24 1999/10/14 02:21:50 mjacob Exp $ */
      2 /*
      3  * Copyright (C) 1999 National Aeronautics & Space Administration
      4  * All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. The name of the author may not be used to endorse or promote products
     15  *    derived from this software without specific prior written permission
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 /*
     30  * Soft Definitions for for Qlogic ISP SCSI adapters.
     31  * Matthew Jacob <mjacob (at) nas.nasa.gov>
     32  */
     33 #ifndef	_ISPVAR_H
     34 #define	_ISPVAR_H
     35 
     36 #if defined(__NetBSD__) || defined(__OpenBSD__)
     37 #include <dev/ic/ispmbox.h>
     38 #endif
     39 #ifdef	__FreeBSD__
     40 #include <dev/isp/ispmbox.h>
     41 #endif
     42 #ifdef	__linux__
     43 #include "ispmbox.h"
     44 #endif
     45 
     46 #define	ISP_CORE_VERSION_MAJOR	1
     47 #define	ISP_CORE_VERSION_MINOR	10
     48 
     49 /*
     50  * Vector for bus specific code to provide specific services.
     51  */
     52 struct ispsoftc;
     53 struct ispmdvec {
     54 	u_int16_t	(*dv_rd_reg) __P((struct ispsoftc *, int));
     55 	void		(*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t));
     56 	int		(*dv_mbxdma) __P((struct ispsoftc *));
     57 	int		(*dv_dmaset) __P((struct ispsoftc *,
     58 		ISP_SCSI_XFER_T *, ispreq_t *, u_int8_t *, u_int8_t));
     59 	void		(*dv_dmaclr)
     60 		__P((struct ispsoftc *, ISP_SCSI_XFER_T *, u_int32_t));
     61 	void		(*dv_reset0) __P((struct ispsoftc *));
     62 	void		(*dv_reset1) __P((struct ispsoftc *));
     63 	void		(*dv_dregs) __P((struct ispsoftc *));
     64 	const u_int16_t *dv_ispfw;	/* ptr to f/w */
     65 	u_int16_t 	dv_fwlen;	/* length of f/w */
     66 	u_int16_t	dv_codeorg;	/* code ORG for f/w */
     67 	u_int32_t	dv_fwrev;	/* f/w revision */
     68 	/*
     69 	 * Initial values for conf1 register
     70 	 */
     71 	u_int16_t	dv_conf1;
     72 	u_int16_t	dv_clock;	/* clock frequency */
     73 };
     74 
     75 #define	MAX_TARGETS	16
     76 #ifdef	ISP2100_FABRIC
     77 #define	MAX_FC_TARG	256
     78 #else
     79 #define	MAX_FC_TARG	126
     80 #endif
     81 
     82 #define	ISP_MAX_TARGETS(isp)	(IS_FC(isp)? MAX_FC_TARG : MAX_TARGETS)
     83 #ifdef	ISP2100_SCCLUN
     84 #define	_ISP_FC_LUN(isp)	65536
     85 #else
     86 #define	_ISP_FC_LUN(isp)	16
     87 #endif
     88 #define	_ISP_SCSI_LUN(isp)	\
     89  	((ISP_FW_REVX(isp->isp_fwrev) >= ISP_FW_REV(7, 55, 0))? 32 : 8)
     90 #define	ISP_MAX_LUNS(isp)	\
     91 	(IS_FC(isp)? _ISP_FC_LUN(isp) : _ISP_SCSI_LUN(isp))
     92 
     93 /* this is the size of a queue entry (request and response) */
     94 #define	QENTRY_LEN			64
     95 /* both request and result queue length must be a power of two */
     96 #define	RQUEST_QUEUE_LEN		MAXISPREQUEST
     97 /* I've seen wierdnesses with the result queue < 64 */
     98 #if	MAXISPREQUEST > 64
     99 #define	RESULT_QUEUE_LEN		(MAXISPREQUEST/2)
    100 #else
    101 #define	RESULT_QUEUE_LEN		MAXISPREQUEST
    102 #endif
    103 #define	ISP_QUEUE_ENTRY(q, idx)		((q) + ((idx) * QENTRY_LEN))
    104 #define	ISP_QUEUE_SIZE(n)		((n) * QENTRY_LEN)
    105 #define	ISP_NXT_QENTRY(idx, qlen)	(((idx) + 1) & ((qlen)-1))
    106 #define ISP_QAVAIL(in, out, qlen)	\
    107 	((in == out)? (qlen - 1) : ((in > out)? \
    108 		((qlen - 1) - (in - out)) : (out - in - 1)))
    109 /*
    110  * SCSI Specific Host Adapter Parameters- per bus, per target
    111  */
    112 
    113 typedef struct {
    114 	u_int		isp_gotdparms		: 1,
    115         		isp_req_ack_active_neg	: 1,
    116 	        	isp_data_line_active_neg: 1,
    117 			isp_cmd_dma_burst_enable: 1,
    118 			isp_data_dma_burst_enabl: 1,
    119 			isp_fifo_threshold	: 3,
    120 			isp_ultramode		: 1,
    121 			isp_diffmode		: 1,
    122 			isp_lvdmode		: 1,
    123 						: 1,
    124 			isp_initiator_id	: 4,
    125         		isp_async_data_setup	: 4;
    126         u_int16_t	isp_selection_timeout;
    127         u_int16_t	isp_max_queue_depth;
    128 	u_int8_t	isp_tag_aging;
    129        	u_int8_t	isp_bus_reset_delay;
    130         u_int8_t	isp_retry_count;
    131         u_int8_t	isp_retry_delay;
    132 	struct {
    133 		u_int	dev_enable	:	1,	/* ignored */
    134 					:	1,
    135 			dev_update	:	1,
    136 			dev_refresh	:	1,
    137 			exc_throttle	:	8,
    138 			cur_offset	:	4,
    139 			sync_offset	:	4;
    140 		u_int8_t	cur_period;	/* current sync period */
    141 		u_int8_t	sync_period;	/* goal sync period */
    142 		u_int16_t	dev_flags;	/* goal device flags */
    143 		u_int16_t	cur_dflags;	/* current device flags */
    144 	} isp_devparam[MAX_TARGETS];
    145 } sdparam;
    146 
    147 /*
    148  * Device Flags
    149  */
    150 #define	DPARM_DISC	0x8000
    151 #define	DPARM_PARITY	0x4000
    152 #define	DPARM_WIDE	0x2000
    153 #define	DPARM_SYNC	0x1000
    154 #define	DPARM_TQING	0x0800
    155 #define	DPARM_ARQ	0x0400
    156 #define	DPARM_QFRZ	0x0200
    157 #define	DPARM_RENEG	0x0100
    158 #define	DPARM_NARROW	0x0080	/* Possibly only available with >= 7.55 fw */
    159 #define	DPARM_ASYNC	0x0040	/* Possibly only available with >= 7.55 fw */
    160 #define	DPARM_DEFAULT	(0xFF00 & ~DPARM_QFRZ)
    161 #define	DPARM_SAFE_DFLT	(DPARM_DEFAULT & ~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING))
    162 
    163 
    164 /* technically, not really correct, as they need to be rated based upon clock */
    165 #define	ISP_40M_SYNCPARMS	0x080a
    166 #define ISP_20M_SYNCPARMS	0x080c
    167 #define ISP_10M_SYNCPARMS	0x0c19
    168 #define ISP_08M_SYNCPARMS	0x0c25
    169 #define ISP_05M_SYNCPARMS	0x0c32
    170 #define ISP_04M_SYNCPARMS	0x0c41
    171 
    172 /*
    173  * Fibre Channel Specifics
    174  */
    175 #define	FL_PORT_ID		0x7e	/* FL_Port Special ID */
    176 #define	FC_PORT_ID		0x7f	/* Fabric Controller Special ID */
    177 #define	FC_SNS_ID		0x80	/* SNS Server Special ID */
    178 
    179 typedef struct {
    180 	u_int			isp_fwoptions	: 16,
    181 						: 7,
    182 				loop_seen_once	: 1,
    183 				isp_loopstate	: 3,	/* Current Loop State */
    184 				isp_fwstate	: 3,	/* ISP F/W state */
    185 				isp_gotdparms	: 1,
    186 				isp_onfabric	: 1;
    187 	u_int8_t		isp_loopid;	/* hard loop id */
    188 	u_int8_t		isp_alpa;	/* ALPA */
    189 	u_int32_t		isp_portid;
    190 	u_int8_t		isp_execthrottle;
    191         u_int8_t		isp_retry_delay;
    192         u_int8_t		isp_retry_count;
    193 	u_int16_t		isp_maxalloc;
    194 	u_int16_t		isp_maxfrmlen;
    195 	u_int64_t		isp_nodewwn;
    196 	u_int64_t		isp_portwwn;
    197 	/*
    198 	 * Port Data Base. This is indexed by 'target', which is invariate.
    199 	 * However, elements within can move around due to loop changes,
    200 	 * so the actual loop ID passed to the F/W is in this structure.
    201 	 * The first time the loop is seen up, loopid will match the index
    202 	 * (except for fabric nodes which are above mapped above FC_SNS_ID
    203 	 * and are completely virtual), but subsequent LIPs can cause things
    204 	 * to move around.
    205 	 */
    206 	struct lportdb {
    207 		u_int
    208 					loopid	: 8,
    209 						: 4,
    210 					fabdev	: 1,
    211 					roles	: 2,
    212 					valid	: 1;
    213 		u_int32_t		portid;
    214 		u_int64_t		node_wwn;
    215 		u_int64_t		port_wwn;
    216 	} portdb[MAX_FC_TARG], tport[FL_PORT_ID];
    217 
    218 	/*
    219 	 * Scratch DMA mapped in area to fetch Port Database stuff, etc.
    220 	 */
    221 	caddr_t			isp_scratch;
    222 	u_int32_t		isp_scdma;
    223 } fcparam;
    224 
    225 #define	FW_CONFIG_WAIT		0
    226 #define	FW_WAIT_AL_PA		1
    227 #define	FW_WAIT_LOGIN		2
    228 #define	FW_READY		3
    229 #define	FW_LOSS_OF_SYNC		4
    230 #define	FW_ERROR		5
    231 #define	FW_REINIT		6
    232 #define	FW_NON_PART		7
    233 
    234 #define	LOOP_NIL		0
    235 #define	LOOP_LIP_RCVD		1
    236 #define	LOOP_PDB_RCVD		2
    237 #define	LOOP_READY		7
    238 
    239 /*
    240  * Soft Structure per host adapter
    241  */
    242 struct ispsoftc {
    243 	/*
    244 	 * Platform (OS) specific data
    245 	 */
    246 	struct isposinfo	isp_osinfo;
    247 
    248 	/*
    249 	 * Pointer to bus specific data
    250 	 */
    251 	struct ispmdvec *	isp_mdvec;
    252 
    253 	/*
    254 	 * Mostly nonvolatile state.
    255 	 */
    256 
    257 	u_int		isp_clock	: 8,
    258 			isp_confopts	: 8,
    259 			isp_fast_mttr	: 1,
    260 					: 1,
    261 			isp_used	: 1,
    262 			isp_dblev	: 3,
    263 			isp_dogactive	: 1,
    264 			isp_bustype	: 1,	/* BUS Implementation */
    265 			isp_type	: 8;	/* HBA Type and Revision */
    266 
    267 	u_int16_t		isp_fwrev[3];	/* Running F/W revision */
    268 	u_int16_t		isp_romfw_rev[3]; /* 'ROM' F/W revision */
    269 	u_int16_t		isp_maxcmds;	/* max active I/O cmds */
    270 	void * 			isp_param;
    271 
    272 	/*
    273 	 * Volatile state
    274 	 */
    275 
    276 	volatile u_int		:	9,
    277 		isp_state	:	3,
    278 		isp_sendmarker	:	2,	/* send a marker entry */
    279 		isp_update	:	2,	/* update parameters */
    280 		isp_nactive	:	16;	/* how many commands active */
    281 
    282 	volatile u_int16_t	isp_reqodx;	/* index of last ISP pickup */
    283 	volatile u_int16_t	isp_reqidx;	/* index of next request */
    284 	volatile u_int16_t	isp_residx;	/* index of next result */
    285 	volatile u_int16_t	isp_lasthdls;	/* last handle seed */
    286 
    287 	/*
    288 	 * Active commands are stored here, found by handle functions.
    289 	 */
    290 	ISP_SCSI_XFER_T **isp_xflist;
    291 
    292 	/*
    293 	 * request/result queue pointers and dma handles for them.
    294 	 */
    295 	caddr_t			isp_rquest;
    296 	caddr_t			isp_result;
    297 	u_int32_t		isp_rquest_dma;
    298 	u_int32_t		isp_result_dma;
    299 };
    300 
    301 #define	SDPARAM(isp)	((sdparam *) (isp)->isp_param)
    302 #define	FCPARAM(isp)	((fcparam *) (isp)->isp_param)
    303 
    304 /*
    305  * ISP States
    306  */
    307 #define	ISP_NILSTATE	0
    308 #define	ISP_RESETSTATE	1
    309 #define	ISP_INITSTATE	2
    310 #define	ISP_RUNSTATE	3
    311 
    312 /*
    313  * ISP Configuration Options
    314  */
    315 #define	ISP_CFG_NORELOAD	0x80	/* don't download f/w */
    316 #define	ISP_CFG_NONVRAM		0x40	/* ignore NVRAM */
    317 #define	ISP_CFG_FULL_DUPLEX	0x01	/* Fibre Channel Only */
    318 
    319 #define	ISP_FW_REV(maj, min, mic)	((maj << 24) | (min << 16) | mic)
    320 #define	ISP_FW_REVX(xp)	((xp[0]<<24) | (xp[1] << 16) | xp[2])
    321 
    322 
    323 /*
    324  * Bus (implementation) types
    325  */
    326 #define	ISP_BT_PCI		0	/* PCI Implementations */
    327 #define	ISP_BT_SBUS		1	/* SBus Implementations */
    328 
    329 /*
    330  * Chip Types
    331  */
    332 #define	ISP_HA_SCSI		0xf
    333 #define	ISP_HA_SCSI_UNKNOWN	0x1
    334 #define	ISP_HA_SCSI_1020	0x2
    335 #define	ISP_HA_SCSI_1020A	0x3
    336 #define	ISP_HA_SCSI_1040	0x4
    337 #define	ISP_HA_SCSI_1040A	0x5
    338 #define	ISP_HA_SCSI_1040B	0x6
    339 #define	ISP_HA_SCSI_1040C	0x7
    340 #define	ISP_HA_SCSI_1080	0xd
    341 #define	ISP_HA_SCSI_12X0	0xe
    342 #define	ISP_HA_FC		0xf0
    343 #define	ISP_HA_FC_2100		0x10
    344 #define	ISP_HA_FC_2200		0x20
    345 
    346 #define	IS_SCSI(isp)	(isp->isp_type & ISP_HA_SCSI)
    347 #define	IS_1080(isp)	(isp->isp_type == ISP_HA_SCSI_1080)
    348 #define	IS_12X0(isp)	(isp->isp_type == ISP_HA_SCSI_12X0)
    349 #define	IS_FC(isp)	(isp->isp_type & ISP_HA_FC)
    350 
    351 /*
    352  * Macros to read, write ISP registers through bus specific code.
    353  */
    354 
    355 #define	ISP_READ(isp, reg)	\
    356 	(*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
    357 
    358 #define	ISP_WRITE(isp, reg, val)	\
    359 	(*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
    360 
    361 #define	ISP_MBOXDMASETUP(isp)	\
    362 	(*(isp)->isp_mdvec->dv_mbxdma)((isp))
    363 
    364 #define	ISP_DMASETUP(isp, xs, req, iptrp, optr)	\
    365 	(*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr))
    366 
    367 #define	ISP_DMAFREE(isp, xs, hndl)	\
    368 	if ((isp)->isp_mdvec->dv_dmaclr) \
    369 		 (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (hndl))
    370 
    371 #define	ISP_RESET0(isp)	\
    372 	if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp))
    373 #define	ISP_RESET1(isp)	\
    374 	if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp))
    375 #define	ISP_DUMPREGS(isp)	\
    376 	if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp))
    377 
    378 #define	ISP_SETBITS(isp, reg, val)	\
    379  (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
    380 
    381 #define	ISP_CLRBITS(isp, reg, val)	\
    382  (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
    383 
    384 /*
    385  * Function Prototypes
    386  */
    387 
    388 /*
    389  * Reset Hardware. Totally. Assumes that you'll follow this with
    390  * a call to isp_init.
    391  */
    392 void isp_reset __P((struct ispsoftc *));
    393 
    394 /*
    395  * Initialize Hardware to known state
    396  */
    397 void isp_init __P((struct ispsoftc *));
    398 
    399 /*
    400  * Reset the ISP and call completion for any orphaned commands.
    401  */
    402 void isp_restart __P((struct ispsoftc *));
    403 
    404 /*
    405  * Interrupt Service Routine
    406  */
    407 int isp_intr __P((void *));
    408 
    409 /*
    410  * Command Entry Point
    411  */
    412 int32_t ispscsicmd __P((ISP_SCSI_XFER_T *));
    413 
    414 /*
    415  * Platform Dependent to External to Internal Control Function
    416  *
    417  * Assumes all locks are held and that no reentrancy issues need be dealt with.
    418  *
    419  */
    420 typedef enum {
    421 	ISPCTL_RESET_BUS,		/* Reset Bus */
    422 	ISPCTL_RESET_DEV,		/* Reset Device */
    423 	ISPCTL_ABORT_CMD,		/* Abort Command */
    424 	ISPCTL_UPDATE_PARAMS,		/* Update Operating Parameters */
    425 	ISPCTL_FCLINK_TEST		/* Test FC Link Status */
    426 } ispctl_t;
    427 int isp_control __P((struct ispsoftc *, ispctl_t, void *));
    428 
    429 
    430 /*
    431  * Platform Dependent to Internal to External Control Function
    432  * (each platform must provide such a function)
    433  *
    434  * Assumes all locks are held and that no reentrancy issues need be dealt with.
    435  *
    436  */
    437 
    438 typedef enum {
    439 	ISPASYNC_NEW_TGT_PARAMS,
    440 	ISPASYNC_BUS_RESET,		/* Bus Was Reset */
    441 	ISPASYNC_LOOP_DOWN,		/* FC Loop Down */
    442 	ISPASYNC_LOOP_UP,		/* FC Loop Up */
    443 	ISPASYNC_PDB_CHANGED,		/* FC Port Data Base Changed */
    444 	ISPASYNC_CHANGE_NOTIFY,		/* FC SNS Change Notification */
    445 	ISPASYNC_FABRIC_DEV,		/* FC New Fabric Device */
    446 } ispasync_t;
    447 int isp_async __P((struct ispsoftc *, ispasync_t, void *));
    448 
    449 /*
    450  * lost command routine (XXXX IN TRANSITION XXXX)
    451  */
    452 void isp_lostcmd __P((struct ispsoftc *, ISP_SCSI_XFER_T *));
    453 
    454 #endif	/* _ISPVAR_H */
    455