Home | History | Annotate | Line # | Download | only in ic
ispvar.h revision 1.6
      1  1.5  thorpej /*	$NetBSD: ispvar.h,v 1.6 1997/08/16 00:18:36 mjacob Exp $	*/
      2  1.1      cgd 
      3  1.1      cgd /*
      4  1.1      cgd  * Soft Definitions for for Qlogic ISP SCSI adapters.
      5  1.1      cgd  *
      6  1.2      cgd  * Copyright (c) 1997 by Matthew Jacob
      7  1.2      cgd  * NASA/Ames Research Center
      8  1.1      cgd  * All rights reserved.
      9  1.1      cgd  *
     10  1.1      cgd  * Redistribution and use in source and binary forms, with or without
     11  1.1      cgd  * modification, are permitted provided that the following conditions
     12  1.1      cgd  * are met:
     13  1.1      cgd  * 1. Redistributions of source code must retain the above copyright
     14  1.1      cgd  *    notice immediately at the beginning of the file, without modification,
     15  1.1      cgd  *    this list of conditions, and the following disclaimer.
     16  1.1      cgd  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1      cgd  *    notice, this list of conditions and the following disclaimer in the
     18  1.1      cgd  *    documentation and/or other materials provided with the distribution.
     19  1.1      cgd  * 3. The name of the author may not be used to endorse or promote products
     20  1.1      cgd  *    derived from this software without specific prior written permission.
     21  1.1      cgd  *
     22  1.1      cgd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     23  1.1      cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.1      cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.1      cgd  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     26  1.1      cgd  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.1      cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.1      cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.1      cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.1      cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1      cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1      cgd  * SUCH DAMAGE.
     33  1.1      cgd  */
     34  1.2      cgd 
     35  1.1      cgd #ifndef	_ISPVAR_H
     36  1.1      cgd #define	_ISPVAR_H
     37  1.1      cgd 
     38  1.1      cgd #include <dev/ic/ispmbox.h>
     39  1.1      cgd 
     40  1.1      cgd /*
     41  1.1      cgd  * Vector for MD code to provide specific services.
     42  1.1      cgd  */
     43  1.1      cgd struct ispsoftc;
     44  1.1      cgd struct ispmdvec {
     45  1.1      cgd 	u_int16_t	(*dv_rd_reg) __P((struct ispsoftc *, int));
     46  1.1      cgd 	void		(*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t));
     47  1.5  thorpej 	int		(*dv_mbxdma) __P((struct ispsoftc *));
     48  1.1      cgd 	int		(*dv_dmaset) __P((struct ispsoftc *,
     49  1.1      cgd 		struct scsi_xfer *, ispreq_t *, u_int8_t *, u_int8_t));
     50  1.1      cgd 	void		(*dv_dmaclr)
     51  1.1      cgd 		__P((struct ispsoftc *, struct scsi_xfer *, u_int32_t));
     52  1.1      cgd 	void		(*dv_reset0) __P((struct ispsoftc *));
     53  1.1      cgd 	void		(*dv_reset1) __P((struct ispsoftc *));
     54  1.6   mjacob 	void		(*dv_dregs) __P((struct ispsoftc *));
     55  1.3  mycroft 	const u_int16_t *dv_ispfw;	/* ptr to f/w */
     56  1.1      cgd 	u_int16_t 	dv_fwlen;	/* length of f/w */
     57  1.1      cgd 	u_int16_t	dv_codeorg;	/* code ORG for f/w */
     58  1.6   mjacob 	u_int16_t	dv_fwrev;	/* f/w revision */
     59  1.1      cgd 	/*
     60  1.1      cgd 	 * Initial values for conf1 register
     61  1.1      cgd 	 */
     62  1.1      cgd 	u_int16_t	dv_conf1;
     63  1.4   mjacob 	u_int16_t	dv_clock;	/* clock frequency */
     64  1.1      cgd };
     65  1.1      cgd 
     66  1.1      cgd #define	MAX_TARGETS	16
     67  1.1      cgd #define	MAX_LUNS	8
     68  1.6   mjacob #define	MAX_FC_TARG	126
     69  1.1      cgd 
     70  1.6   mjacob #define	MAXISPREQUEST	256
     71  1.6   mjacob #define	RQUEST_QUEUE_LEN(isp)	MAXISPREQUEST
     72  1.6   mjacob #define	RESULT_QUEUE_LEN(isp)	(RQUEST_QUEUE_LEN(isp) >> 2)
     73  1.1      cgd #define	QENTRY_LEN		64
     74  1.1      cgd 
     75  1.5  thorpej #define	ISP_QUEUE_ENTRY(q, idx)	((q) + ((idx) * QENTRY_LEN))
     76  1.5  thorpej #define	ISP_QUEUE_SIZE(n)	((n) * QENTRY_LEN)
     77  1.5  thorpej 
     78  1.1      cgd /*
     79  1.6   mjacob  * SCSI (as opposed to FC-PH) Specific Host Adapter Parameters
     80  1.6   mjacob  */
     81  1.6   mjacob 
     82  1.6   mjacob typedef struct {
     83  1.6   mjacob         u_int16_t	isp_adapter_enabled	: 1,
     84  1.6   mjacob         		isp_req_ack_active_neg	: 1,
     85  1.6   mjacob 	        	isp_data_line_active_neg: 1,
     86  1.6   mjacob 			isp_cmd_dma_burst_enable: 1,
     87  1.6   mjacob 			isp_data_dma_burst_enabl: 1,
     88  1.6   mjacob 			isp_fifo_threshold	: 2,
     89  1.6   mjacob 			isp_diffmode		: 1,
     90  1.6   mjacob 			isp_initiator_id	: 4,
     91  1.6   mjacob         		isp_async_data_setup	: 4;
     92  1.6   mjacob         u_int16_t	isp_selection_timeout;
     93  1.6   mjacob         u_int16_t	isp_max_queue_depth;
     94  1.6   mjacob 	u_int16_t	isp_clock;
     95  1.6   mjacob 	u_int8_t	isp_tag_aging;
     96  1.6   mjacob        	u_int8_t	isp_bus_reset_delay;
     97  1.6   mjacob         u_int8_t	isp_retry_count;
     98  1.6   mjacob         u_int8_t	isp_retry_delay;
     99  1.6   mjacob 	struct {
    100  1.6   mjacob 		u_int8_t	dev_flags;	/* Device Flags - see below */
    101  1.6   mjacob 		u_int8_t	exc_throttle;
    102  1.6   mjacob 		u_int8_t	sync_period;
    103  1.6   mjacob 		u_int8_t	sync_offset	: 4,
    104  1.6   mjacob 				dev_enable	: 1;
    105  1.6   mjacob 	} isp_devparam[MAX_TARGETS];
    106  1.6   mjacob } sdparam;	/* scsi device parameters */
    107  1.6   mjacob 
    108  1.6   mjacob /*
    109  1.6   mjacob  * Device Flags
    110  1.6   mjacob  */
    111  1.6   mjacob #define	DPARM_DISC	0x80
    112  1.6   mjacob #define	DPARM_PARITY	0x40
    113  1.6   mjacob #define	DPARM_WIDE	0x20
    114  1.6   mjacob #define	DPARM_SYNC	0x10
    115  1.6   mjacob #define	DPARM_TQING	0x08
    116  1.6   mjacob #define	DPARM_ARQ	0x04
    117  1.6   mjacob #define	DPARM_QFRZ	0x02
    118  1.6   mjacob #define	DPARM_RENEG	0x01
    119  1.6   mjacob #define	DPARM_DEFAULT	(0xff & ~DPARM_QFRZ)
    120  1.6   mjacob 
    121  1.6   mjacob #define ISP_20M_SYNCPARMS	0x080c
    122  1.6   mjacob #define ISP_10M_SYNCPARMS	0x0c19
    123  1.6   mjacob #define ISP_08M_SYNCPARMS	0x0c25
    124  1.6   mjacob #define ISP_05M_SYNCPARMS	0x0c32
    125  1.6   mjacob #define ISP_04M_SYNCPARMS	0x0c41
    126  1.6   mjacob 
    127  1.6   mjacob /*
    128  1.6   mjacob  * Fibre Channel Specifics
    129  1.6   mjacob  */
    130  1.6   mjacob typedef struct {
    131  1.6   mjacob 	u_int64_t		isp_wwn;	/* WWN of adapter */
    132  1.6   mjacob 	u_int8_t		isp_loopid;	/* FCAL of this adapter inst */
    133  1.6   mjacob         u_int8_t		isp_retry_count;
    134  1.6   mjacob         u_int8_t		isp_retry_delay;
    135  1.6   mjacob 	u_int8_t		isp_fwstate;	/* ISP F/W state */
    136  1.6   mjacob 
    137  1.6   mjacob 	/*
    138  1.6   mjacob 	 * Scratch DMA mapped in area to fetch Port Database stuff, etc.
    139  1.6   mjacob 	 */
    140  1.6   mjacob 	volatile caddr_t	isp_scratch;
    141  1.6   mjacob 	u_int32_t		isp_scdma;
    142  1.6   mjacob } fcparam;
    143  1.6   mjacob 
    144  1.6   mjacob #define	ISP2100_SCRLEN		0x100
    145  1.6   mjacob 
    146  1.6   mjacob #define	FW_CONFIG_WAIT		0x0000
    147  1.6   mjacob #define	FW_WAIT_AL_PA		0x0001
    148  1.6   mjacob #define	FW_WAIT_LOGIN		0x0002
    149  1.6   mjacob #define	FW_READY		0x0003
    150  1.6   mjacob #define	FW_LOSS_OF_SYNC		0x0004
    151  1.6   mjacob #define	FW_ERROR		0x0005
    152  1.6   mjacob #define	FW_REINIT		0x0006
    153  1.6   mjacob #define	FW_NON_PART		0x0007
    154  1.6   mjacob 
    155  1.6   mjacob /*
    156  1.1      cgd  * Soft Structure per host adapter
    157  1.1      cgd  */
    158  1.1      cgd struct ispsoftc {
    159  1.1      cgd 	struct device		isp_dev;
    160  1.1      cgd 	struct ispmdvec *	isp_mdvec;
    161  1.1      cgd #define	isp_name	isp_dev.dv_xname
    162  1.1      cgd 	struct scsi_link	isp_link;
    163  1.1      cgd 	u_int8_t		isp_state;
    164  1.6   mjacob 	int8_t			isp_dblev;
    165  1.6   mjacob 	u_int16_t		isp_fwrev;
    166  1.6   mjacob 
    167  1.1      cgd 	/*
    168  1.6   mjacob 	 * Host Adapter Type and Parameters.
    169  1.6   mjacob 	 * Some parameters nominally stored in NVRAM on card.
    170  1.1      cgd 	 */
    171  1.6   mjacob 	u_int8_t		isp_type;
    172  1.6   mjacob 	void * 			isp_param;
    173  1.6   mjacob 
    174  1.1      cgd 	/*
    175  1.1      cgd 	 * Result and Request Queues.
    176  1.1      cgd 	 */
    177  1.1      cgd 	volatile u_int8_t	isp_reqidx;	/* index of next request */
    178  1.1      cgd 	volatile u_int8_t	isp_residx;	/* index of next result */
    179  1.1      cgd 	volatile u_int8_t	isp_sendmarker;
    180  1.1      cgd 	volatile u_int8_t	isp_seqno;
    181  1.6   mjacob 
    182  1.1      cgd 	/*
    183  1.1      cgd 	 * Sheer laziness, but it gets us around the problem
    184  1.1      cgd 	 * where we don't have a clean way of remembering
    185  1.1      cgd 	 * which scsi_xfer is bound to which ISP queue entry.
    186  1.1      cgd 	 *
    187  1.1      cgd 	 * There are other more clever ways to do this, but,
    188  1.1      cgd 	 * jeez, so I blow a couple of KB per host adapter...
    189  1.1      cgd 	 * and it *is* faster.
    190  1.1      cgd 	 */
    191  1.6   mjacob 	volatile struct scsi_xfer *isp_xflist[MAXISPREQUEST];
    192  1.6   mjacob 
    193  1.1      cgd 	/*
    194  1.6   mjacob 	 * request/result queues
    195  1.1      cgd 	 */
    196  1.5  thorpej 	volatile caddr_t	isp_rquest;
    197  1.5  thorpej 	volatile caddr_t	isp_result;
    198  1.5  thorpej 	u_int32_t		isp_rquest_dma;
    199  1.5  thorpej 	u_int32_t		isp_result_dma;
    200  1.1      cgd };
    201  1.1      cgd 
    202  1.1      cgd /*
    203  1.6   mjacob  * Adapter Variants
    204  1.6   mjacob  */
    205  1.6   mjacob #define	ISP_HA_SCSI		0xf
    206  1.6   mjacob #define	ISP_HA_SCSI_UNKNOWN	0x0
    207  1.6   mjacob #define	ISP_HA_SCSI_1020	0x1
    208  1.6   mjacob #define	ISP_HA_SCSI_1040A	0x2
    209  1.6   mjacob #define	ISP_HA_SCSI_1040B	0x3
    210  1.6   mjacob #define	ISP_HA_FC		0xf0
    211  1.6   mjacob #define	ISP_HA_FC_2100		0x10
    212  1.6   mjacob 
    213  1.6   mjacob /*
    214  1.1      cgd  * ISP States
    215  1.1      cgd  */
    216  1.1      cgd #define	ISP_NILSTATE	0
    217  1.1      cgd #define	ISP_RESETSTATE	1
    218  1.1      cgd #define	ISP_INITSTATE	2
    219  1.1      cgd #define	ISP_RUNSTATE	3
    220  1.1      cgd 
    221  1.1      cgd 
    222  1.1      cgd 
    223  1.1      cgd 
    224  1.1      cgd /*
    225  1.1      cgd  * Macros to read, write ISP registers through MD code
    226  1.1      cgd  */
    227  1.1      cgd 
    228  1.1      cgd #define	ISP_READ(isp, reg)	\
    229  1.1      cgd 	(*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
    230  1.1      cgd 
    231  1.1      cgd #define	ISP_WRITE(isp, reg, val)	\
    232  1.1      cgd 	(*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
    233  1.1      cgd 
    234  1.5  thorpej #define	ISP_MBOXDMASETUP(isp)	\
    235  1.5  thorpej 	(*(isp)->isp_mdvec->dv_mbxdma)((isp))
    236  1.1      cgd 
    237  1.1      cgd #define	ISP_DMASETUP(isp, xs, req, iptrp, optr)	\
    238  1.1      cgd 	(*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr))
    239  1.1      cgd 
    240  1.1      cgd #define	ISP_DMAFREE(isp, xs, seqno)	\
    241  1.1      cgd 	if ((isp)->isp_mdvec->dv_dmaclr) \
    242  1.1      cgd 		 (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (seqno))
    243  1.1      cgd 
    244  1.1      cgd #define	ISP_RESET0(isp)	\
    245  1.1      cgd 	if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp))
    246  1.1      cgd #define	ISP_RESET1(isp)	\
    247  1.1      cgd 	if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp))
    248  1.6   mjacob #define	ISP_DUMPREGS(isp)	\
    249  1.6   mjacob 	if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp))
    250  1.1      cgd 
    251  1.1      cgd #define	ISP_SETBITS(isp, reg, val)	\
    252  1.1      cgd  (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
    253  1.1      cgd 
    254  1.1      cgd #define	ISP_CLRBITS(isp, reg, val)	\
    255  1.1      cgd  (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
    256  1.1      cgd 
    257  1.1      cgd /*
    258  1.1      cgd  * Function Prototypes
    259  1.1      cgd  */
    260  1.1      cgd /*
    261  1.1      cgd  * Reset Hardware.
    262  1.1      cgd  *
    263  1.1      cgd  * Only looks at sc_dev.dv_xname, sc_iot and sc_ioh fields.
    264  1.1      cgd  */
    265  1.1      cgd void isp_reset __P((struct ispsoftc *));
    266  1.1      cgd 
    267  1.1      cgd /*
    268  1.1      cgd  * Initialize Hardware to known state
    269  1.1      cgd  */
    270  1.1      cgd void isp_init __P((struct ispsoftc *));
    271  1.1      cgd 
    272  1.1      cgd /*
    273  1.1      cgd  * Complete attachment of Hardware
    274  1.1      cgd  */
    275  1.1      cgd void isp_attach __P((struct ispsoftc *));
    276  1.1      cgd 
    277  1.1      cgd /*
    278  1.1      cgd  * Free any associated resources prior to decommissioning.
    279  1.1      cgd  */
    280  1.1      cgd void isp_uninit __P((struct ispsoftc *));
    281  1.1      cgd 
    282  1.1      cgd /*
    283  1.1      cgd  * Interrupt Service Routine
    284  1.1      cgd  */
    285  1.1      cgd int isp_intr __P((void *));
    286  1.1      cgd 
    287  1.1      cgd 
    288  1.1      cgd 
    289  1.1      cgd 
    290  1.1      cgd #endif	/* _ISPVAR_H */
    291