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