ispvar.h revision 35388
1/* $Id: ispvar.h,v 1.6 1998/04/14 17:51:32 mjacob Exp $ */
2/*
3 * Soft Definitions for for Qlogic ISP SCSI adapters.
4 *
5 *---------------------------------------
6 * Copyright (c) 1997, 1998 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
36#ifndef	_ISPVAR_H
37#define	_ISPVAR_H
38
39#ifdef	__NetBSD__
40#include <dev/ic/ispmbox.h>
41#endif
42#ifdef	__FreeBSD__
43#include <dev/isp/ispmbox.h>
44#endif
45#ifdef	__linux__
46#include <ispmbox.h>
47#endif
48
49/*
50 * Vector for MD code to provide specific services.
51 */
52struct ispsoftc;
53struct 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_int16_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#define	MAX_LUNS	8
77#define	MAX_FC_TARG	126
78
79#define	RQUEST_QUEUE_LEN(isp)	MAXISPREQUEST
80#define	RESULT_QUEUE_LEN(isp)	(MAXISPREQUEST/4)
81
82#define	QENTRY_LEN		64
83
84#define	ISP_QUEUE_ENTRY(q, idx)	((q) + ((idx) * QENTRY_LEN))
85#define	ISP_QUEUE_SIZE(n)	((n) * QENTRY_LEN)
86
87/*
88 * SCSI (as opposed to FC-PH) Specific Host Adapter Parameters
89 */
90
91typedef struct {
92        u_int16_t	isp_adapter_enabled	: 1,
93        		isp_req_ack_active_neg	: 1,
94	        	isp_data_line_active_neg: 1,
95			isp_cmd_dma_burst_enable: 1,
96			isp_data_dma_burst_enabl: 1,
97			isp_fifo_threshold	: 2,
98			isp_diffmode		: 1,
99			isp_initiator_id	: 4,
100        		isp_async_data_setup	: 4;
101        u_int16_t	isp_selection_timeout;
102        u_int16_t	isp_max_queue_depth;
103	u_int16_t	isp_clock;
104	u_int8_t	isp_tag_aging;
105       	u_int8_t	isp_bus_reset_delay;
106        u_int8_t	isp_retry_count;
107        u_int8_t	isp_retry_delay;
108	struct {
109		u_int8_t	dev_flags;	/* Device Flags - see below */
110		u_int8_t	exc_throttle;
111		u_int8_t	sync_period;
112		u_int8_t	sync_offset	: 4,
113				dev_enable	: 1;
114	} isp_devparam[MAX_TARGETS];
115} sdparam;	/* scsi device parameters */
116
117/*
118 * Device Flags
119 */
120#define	DPARM_DISC	0x80
121#define	DPARM_PARITY	0x40
122#define	DPARM_WIDE	0x20
123#define	DPARM_SYNC	0x10
124#define	DPARM_TQING	0x08
125#define	DPARM_ARQ	0x04
126#define	DPARM_QFRZ	0x02
127#define	DPARM_RENEG	0x01
128#define	DPARM_DEFAULT	(0xff & ~DPARM_QFRZ)
129
130#define ISP_20M_SYNCPARMS	0x080c
131#define ISP_10M_SYNCPARMS	0x0c19
132#define ISP_08M_SYNCPARMS	0x0c25
133#define ISP_05M_SYNCPARMS	0x0c32
134#define ISP_04M_SYNCPARMS	0x0c41
135
136/*
137 * Fibre Channel Specifics
138 */
139typedef struct {
140	u_int64_t		isp_wwn;	/* WWN of adapter */
141	u_int8_t		isp_loopid;	/* FCAL of this adapter inst */
142        u_int8_t		isp_retry_count;
143        u_int8_t		isp_retry_delay;
144	u_int8_t		isp_fwstate;	/* ISP F/W state */
145
146	/*
147	 * Scratch DMA mapped in area to fetch Port Database stuff, etc.
148	 */
149	volatile caddr_t	isp_scratch;
150	u_int32_t		isp_scdma;
151} fcparam;
152
153#define	ISP2100_SCRLEN		0x100
154
155#define	FW_CONFIG_WAIT		0x0000
156#define	FW_WAIT_AL_PA		0x0001
157#define	FW_WAIT_LOGIN		0x0002
158#define	FW_READY		0x0003
159#define	FW_LOSS_OF_SYNC		0x0004
160#define	FW_ERROR		0x0005
161#define	FW_REINIT		0x0006
162#define	FW_NON_PART		0x0007
163
164static inline char *fw_statename __P((u_int8_t x))
165{
166	switch(x) {
167	case FW_CONFIG_WAIT:	return "Config Wait";
168	case FW_WAIT_AL_PA:	return "Waiting for AL/PA";
169	case FW_WAIT_LOGIN:	return "Wait Login";
170	case FW_READY:		return "Ready";
171	case FW_LOSS_OF_SYNC:	return "Loss Of Sync";
172	case FW_ERROR:		return "Error";
173	case FW_REINIT:		return "Re-Init";
174	case FW_NON_PART:	return "Nonparticipating";
175	default:		return "eh?";
176	}
177}
178
179/*
180 * Soft Structure per host adapter
181 */
182struct ispsoftc {
183	/*
184	 * Platform (OS) specific data
185	 */
186	struct isposinfo	isp_osinfo;
187
188	/*
189	 * Pointer to bus specific data
190	 */
191	struct ispmdvec *	isp_mdvec;
192
193	/*
194	 * State, debugging, etc..
195	 */
196
197	u_int32_t	isp_state	: 3,
198			isp_dogactive	: 1,
199			isp_dblev	: 4,
200			isp_confopts	: 8,
201			isp_fwrev	: 16;
202
203	/*
204	 * Host Adapter Type and Parameters.
205	 * Some parameters nominally stored in NVRAM on card.
206	 */
207	void * 			isp_param;
208	u_int8_t		isp_type;
209	int16_t			isp_nactive;
210
211	/*
212	 * Result and Request Queues.
213	 */
214	volatile u_int8_t	isp_reqidx;	/* index of next request */
215	volatile u_int8_t	isp_residx;	/* index of next result */
216	volatile u_int8_t	isp_sendmarker;
217	volatile u_int8_t	isp_seqno;
218
219	/*
220	 * Sheer laziness, but it gets us around the problem
221	 * where we don't have a clean way of remembering
222	 * which transaction is bound to which ISP queue entry.
223	 *
224	 * There are other more clever ways to do this, but,
225	 * jeez, so I blow a couple of KB per host adapter...
226	 * and it *is* faster.
227	 */
228	volatile ISP_SCSI_XFER_T *isp_xflist[MAXISPREQUEST];
229
230	/*
231	 * request/result queues
232	 */
233	volatile caddr_t	isp_rquest;
234	volatile caddr_t	isp_result;
235	u_int32_t		isp_rquest_dma;
236	u_int32_t		isp_result_dma;
237};
238
239/*
240 * ISP States
241 */
242#define	ISP_NILSTATE	0
243#define	ISP_RESETSTATE	1
244#define	ISP_INITSTATE	2
245#define	ISP_RUNSTATE	3
246
247/*
248 * ISP Configuration Options
249 */
250#define	ISP_CFG_NORELOAD	0x80	/* don't download f/w */
251
252/*
253 * Adapter Types
254 */
255#define	ISP_HA_SCSI		0xf
256#define	ISP_HA_SCSI_UNKNOWN	0x0
257#define	ISP_HA_SCSI_1020	0x1
258#define	ISP_HA_SCSI_1040A	0x2
259#define	ISP_HA_SCSI_1040B	0x3
260#define	ISP_HA_FC		0xf0
261#define	ISP_HA_FC_2100		0x10
262
263/*
264 * Macros to read, write ISP registers through MD code
265 */
266
267#define	ISP_READ(isp, reg)	\
268	(*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
269
270#define	ISP_WRITE(isp, reg, val)	\
271	(*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
272
273#define	ISP_MBOXDMASETUP(isp)	\
274	(*(isp)->isp_mdvec->dv_mbxdma)((isp))
275
276#define	ISP_DMASETUP(isp, xs, req, iptrp, optr)	\
277	(*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr))
278
279#define	ISP_DMAFREE(isp, xs, seqno)	\
280	if ((isp)->isp_mdvec->dv_dmaclr) \
281		 (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (seqno))
282
283#define	ISP_RESET0(isp)	\
284	if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp))
285#define	ISP_RESET1(isp)	\
286	if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp))
287#define	ISP_DUMPREGS(isp)	\
288	if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp))
289
290#define	ISP_SETBITS(isp, reg, val)	\
291 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
292
293#define	ISP_CLRBITS(isp, reg, val)	\
294 (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
295
296/*
297 * Function Prototypes
298 */
299
300/*
301 * Reset Hardware.
302 */
303void isp_reset __P((struct ispsoftc *));
304
305/*
306 * Abort this running command..
307 *
308 * Second argument is an index into xflist array.
309 * All locks must be held already.
310 */
311int isp_abortcmd __P((struct ispsoftc *, int));
312
313/*
314 * Initialize Hardware to known state
315 */
316void isp_init __P((struct ispsoftc *));
317
318/*
319 * Free any associated resources prior to decommissioning.
320 */
321void isp_uninit __P((struct ispsoftc *));
322
323/*
324 * Interrupt Service Routine
325 */
326int isp_intr __P((void *));
327
328/*
329 * Watchdog Routine
330 */
331void isp_watch __P((void *));
332
333/*
334 * Command Entry Point
335 */
336extern int32_t ispscsicmd __P((ISP_SCSI_XFER_T *));
337
338#endif	/* _ISPVAR_H */
339