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