Home | History | Annotate | Line # | Download | only in ic
ispvar.h revision 1.1
      1 /*	$NetBSD: ispvar.h,v 1.1 1997/03/12 20:44:51 cgd Exp $ */
      2 
      3 /*
      4  * Soft Definitions for for Qlogic ISP SCSI adapters.
      5  *
      6  * Copyright (c) 1997 by Matthew Jacob (for NASA/Ames Research Center)
      7  * All rights reserved.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice immediately at the beginning of the file, without modification,
     14  *    this list of conditions, and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     24  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     25  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  * SUCH DAMAGE.
     32  *
     33  */
     34 #ifndef	_ISPVAR_H
     35 #define	_ISPVAR_H
     36 
     37 #include <dev/ic/ispmbox.h>
     38 
     39 /*
     40  * Vector for MD code to provide specific services.
     41  */
     42 struct ispsoftc;
     43 struct ispmdvec {
     44 	u_int16_t	(*dv_rd_reg) __P((struct ispsoftc *, int));
     45 	void		(*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t));
     46 	vm_offset_t	(*dv_mbxdma)
     47 		__P((struct ispsoftc *, vm_offset_t, u_int32_t));
     48 	int		(*dv_dmaset) __P((struct ispsoftc *,
     49 		struct scsi_xfer *, ispreq_t *, u_int8_t *, u_int8_t));
     50 	void		(*dv_dmaclr)
     51 		__P((struct ispsoftc *, struct scsi_xfer *, u_int32_t));
     52 	void		(*dv_reset0) __P((struct ispsoftc *));
     53 	void		(*dv_reset1) __P((struct ispsoftc *));
     54 	u_int16_t *	dv_ispfw;	/* ptr to f/w */
     55 	u_int16_t 	dv_fwlen;	/* length of f/w */
     56 	u_int16_t	dv_codeorg;	/* code ORG for f/w */
     57 	/*
     58 	 * Initial values for conf1 register
     59 	 */
     60 	u_int16_t	dv_conf1;
     61 };
     62 
     63 #define	MAX_TARGETS	16
     64 #define	MAX_LUNS	8
     65 
     66 #define	RQUEST_QUEUE_LEN	256
     67 #define	RESULT_QUEUE_LEN	(RQUEST_QUEUE_LEN >> 3)
     68 #define	QENTRY_LEN		64
     69 
     70 /*
     71  * Soft Structure per host adapter
     72  */
     73 struct ispsoftc {
     74 	struct device		isp_dev;
     75 	struct ispmdvec *	isp_mdvec;
     76 #define	isp_name	isp_dev.dv_xname
     77 	struct scsi_link	isp_link;
     78 	u_int8_t		isp_max_target;
     79 	u_int8_t		isp_state;
     80 	/*
     81 	 * Host Adapter Parameters, nominally stored in NVRAM
     82 	 */
     83         u_int16_t		isp_adapter_enabled	: 1,
     84         			isp_req_ack_active_neg	: 1,
     85 	        		isp_data_line_active_neg: 1,
     86 				isp_cmd_dma_burst_enable: 1,
     87 				isp_data_dma_burst_enabl: 1,
     88 				isp_fifo_threshold	: 2,
     89 							: 1,
     90 				isp_initiator_id	: 4,
     91         			isp_async_data_setup	: 4;
     92         u_int16_t		isp_selection_timeout;
     93         u_int16_t		isp_max_queue_depth;
     94 	u_int8_t		isp_tag_aging;
     95        	u_int8_t		isp_bus_reset_delay;
     96         u_int8_t		isp_retry_count;
     97         u_int8_t		isp_retry_delay;
     98 	struct {
     99 		u_int8_t	dev_flags;	/* Device Flags - see below */
    100 		u_int8_t	exc_throttle;
    101 		u_int8_t	sync_period;
    102 		u_int8_t	sync_offset	: 4,
    103 				dev_enable	: 1;
    104 	} isp_devparam[MAX_TARGETS];
    105 	/*
    106 	 * Result and Request Queues.
    107 	 */
    108 	volatile u_int8_t	isp_reqidx;	/* index of next request */
    109 	volatile u_int8_t	isp_residx;	/* index of next result */
    110 	volatile u_int8_t	isp_sendmarker;
    111 	volatile u_int8_t	isp_seqno;
    112 	/*
    113 	 * Sheer laziness, but it gets us around the problem
    114 	 * where we don't have a clean way of remembering
    115 	 * which scsi_xfer is bound to which ISP queue entry.
    116 	 *
    117 	 * There are other more clever ways to do this, but,
    118 	 * jeez, so I blow a couple of KB per host adapter...
    119 	 * and it *is* faster.
    120 	 */
    121 	volatile struct scsi_xfer *isp_xflist[RQUEST_QUEUE_LEN];
    122 	/*
    123 	 * request/result queue
    124 	 */
    125 	volatile u_int8_t	isp_rquest[RQUEST_QUEUE_LEN][QENTRY_LEN];
    126 	volatile u_int8_t	isp_result[RESULT_QUEUE_LEN][QENTRY_LEN];
    127 };
    128 
    129 /*
    130  * ISP States
    131  */
    132 #define	ISP_NILSTATE	0
    133 #define	ISP_RESETSTATE	1
    134 #define	ISP_INITSTATE	2
    135 #define	ISP_RUNSTATE	3
    136 
    137 
    138 /*
    139  * Device Flags
    140  */
    141 #define	DPARM_DISC	0x80
    142 #define	DPARM_PARITY	0x40
    143 #define	DPARM_WIDE	0x20
    144 #define	DPARM_SYNC	0x10
    145 #define	DPARM_TQING	0x08
    146 #define	DPARM_ARQ	0x04
    147 #define	DPARM_QFRZ	0x02
    148 #define	DPARM_RENEG	0x01
    149 
    150 #define	DPARM_DEFAULT	(0xff & ~DPARM_QFRZ)
    151 
    152 
    153 /*
    154  * Macros to read, write ISP registers through MD code
    155  */
    156 
    157 #define	ISP_READ(isp, reg)	\
    158 	(*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
    159 
    160 #define	ISP_WRITE(isp, reg, val)	\
    161 	(*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
    162 
    163 #define	ISP_MBOXDMASETUP(isp, kva, len)	\
    164 	(*(isp)->isp_mdvec->dv_mbxdma)((isp), (vm_offset_t) (kva), (len))
    165 
    166 #define	ISP_DMASETUP(isp, xs, req, iptrp, optr)	\
    167 	(*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr))
    168 
    169 #define	ISP_DMAFREE(isp, xs, seqno)	\
    170 	if ((isp)->isp_mdvec->dv_dmaclr) \
    171 		 (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (seqno))
    172 
    173 #define	ISP_RESET0(isp)	\
    174 	if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp))
    175 #define	ISP_RESET1(isp)	\
    176 	if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp))
    177 
    178 
    179 #define	ISP_SETBITS(isp, reg, val)	\
    180  (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
    181 
    182 #define	ISP_CLRBITS(isp, reg, val)	\
    183  (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
    184 
    185 /*
    186  * Function Prototypes
    187  */
    188 /*
    189  * Reset Hardware.
    190  *
    191  * Only looks at sc_dev.dv_xname, sc_iot and sc_ioh fields.
    192  */
    193 void isp_reset __P((struct ispsoftc *));
    194 
    195 /*
    196  * Initialize Hardware to known state
    197  */
    198 void isp_init __P((struct ispsoftc *));
    199 
    200 /*
    201  * Complete attachment of Hardware
    202  */
    203 void isp_attach __P((struct ispsoftc *));
    204 
    205 /*
    206  * Free any associated resources prior to decommissioning.
    207  */
    208 void isp_uninit __P((struct ispsoftc *));
    209 
    210 /*
    211  * Interrupt Service Routine
    212  */
    213 int isp_intr __P((void *));
    214 
    215 
    216 
    217 
    218 #endif	/* _ISPVAR_H */
    219