xref: /freebsd/sys/dev/isp/ispvar.h (revision 6e8394b8baa7d5d9153ab90de6824bcd19b3b4e1)
1 /* $Id: ispvar.h,v 1.13 1999/04/04 01:26:08 mjacob Exp $ */
2 /* release_5_11_99 */
3 /*
4  * Soft Definitions for for Qlogic ISP SCSI adapters.
5  *
6  *---------------------------------------
7  * Copyright (c) 1997, 1998 by Matthew Jacob
8  * NASA/Ames Research Center
9  * All rights reserved.
10  *---------------------------------------
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice immediately at the beginning of the file, without modification,
16  *    this list of conditions, and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  */
36 
37 #ifndef	_ISPVAR_H
38 #define	_ISPVAR_H
39 
40 #if defined(__NetBSD__) || defined(__OpenBSD__)
41 #include <dev/ic/ispmbox.h>
42 #endif
43 #ifdef	__FreeBSD__
44 #include <dev/isp/ispmbox.h>
45 #endif
46 #ifdef	__linux__
47 #include "ispmbox.h"
48 #endif
49 
50 #define	ISP_CORE_VERSION_MAJOR	1
51 #define	ISP_CORE_VERSION_MINOR	8
52 
53 /*
54  * Vector for bus specific code to provide specific services.
55  */
56 struct ispsoftc;
57 struct ispmdvec {
58 	u_int16_t	(*dv_rd_reg) __P((struct ispsoftc *, int));
59 	void		(*dv_wr_reg) __P((struct ispsoftc *, int, u_int16_t));
60 	int		(*dv_mbxdma) __P((struct ispsoftc *));
61 	int		(*dv_dmaset) __P((struct ispsoftc *,
62 		ISP_SCSI_XFER_T *, ispreq_t *, u_int8_t *, u_int8_t));
63 	void		(*dv_dmaclr)
64 		__P((struct ispsoftc *, ISP_SCSI_XFER_T *, u_int32_t));
65 	void		(*dv_reset0) __P((struct ispsoftc *));
66 	void		(*dv_reset1) __P((struct ispsoftc *));
67 	void		(*dv_dregs) __P((struct ispsoftc *));
68 	const u_int16_t *dv_ispfw;	/* ptr to f/w */
69 	u_int16_t 	dv_fwlen;	/* length of f/w */
70 	u_int16_t	dv_codeorg;	/* code ORG for f/w */
71 	u_int16_t	dv_fwrev;	/* f/w revision */
72 	/*
73 	 * Initial values for conf1 register
74 	 */
75 	u_int16_t	dv_conf1;
76 	u_int16_t	dv_clock;	/* clock frequency */
77 };
78 
79 #define	MAX_TARGETS	16
80 #ifdef	ISP2100_FABRIC
81 #define	MAX_FC_TARG	256
82 #else
83 #define	MAX_FC_TARG	126
84 #endif
85 #define	DEFAULT_LOOPID	113
86 
87 /* queue length must be a power of two */
88 #define	QENTRY_LEN			64
89 #define	RQUEST_QUEUE_LEN		MAXISPREQUEST
90 #define	RESULT_QUEUE_LEN		(MAXISPREQUEST/2)
91 #define	ISP_QUEUE_ENTRY(q, idx)		((q) + ((idx) * QENTRY_LEN))
92 #define	ISP_QUEUE_SIZE(n)		((n) * QENTRY_LEN)
93 #define	ISP_NXT_QENTRY(idx, qlen)	(((idx) + 1) & ((qlen)-1))
94 #define ISP_QAVAIL(in, out, qlen)	\
95 	((in == out)? (qlen - 1) : ((in > out)? \
96 		((qlen - 1) - (in - out)) : (out - in - 1)))
97 /*
98  * SCSI Specific Host Adapter Parameters- per bus, per target
99  */
100 
101 typedef struct {
102 	u_int		isp_gotdparms		: 1,
103         		isp_req_ack_active_neg	: 1,
104 	        	isp_data_line_active_neg: 1,
105 			isp_cmd_dma_burst_enable: 1,
106 			isp_data_dma_burst_enabl: 1,
107 			isp_fifo_threshold	: 3,
108 			isp_ultramode		: 1,
109 			isp_diffmode		: 1,
110 			isp_lvdmode		: 1,
111 						: 1,
112 			isp_initiator_id	: 4,
113         		isp_async_data_setup	: 4;
114         u_int16_t	isp_selection_timeout;
115         u_int16_t	isp_max_queue_depth;
116 	u_int8_t	isp_tag_aging;
117        	u_int8_t	isp_bus_reset_delay;
118         u_int8_t	isp_retry_count;
119         u_int8_t	isp_retry_delay;
120 	struct {
121 		u_int	dev_enable	:	1,	/* ignored */
122 					:	1,
123 			dev_update	:	1,
124 			dev_refresh	:	1,
125 			exc_throttle	:	8,
126 			cur_offset	:	4,
127 			sync_offset	:	4;
128 		u_int8_t	cur_period;	/* current sync period */
129 		u_int8_t	sync_period;	/* goal sync period */
130 		u_int16_t	dev_flags;	/* goal device flags */
131 		u_int16_t	cur_dflags;	/* current device flags */
132 	} isp_devparam[MAX_TARGETS];
133 } sdparam;
134 
135 /*
136  * Device Flags
137  */
138 #define	DPARM_DISC	0x8000
139 #define	DPARM_PARITY	0x4000
140 #define	DPARM_WIDE	0x2000
141 #define	DPARM_SYNC	0x1000
142 #define	DPARM_TQING	0x0800
143 #define	DPARM_ARQ	0x0400
144 #define	DPARM_QFRZ	0x0200
145 #define	DPARM_RENEG	0x0100
146 #define	DPARM_NARROW	0x0080	/* Possibly only available with >= 7.55 fw */
147 #define	DPARM_ASYNC	0x0040	/* Possibly only available with >= 7.55 fw */
148 #define	DPARM_DEFAULT	(0xFF00 & ~DPARM_QFRZ)
149 #define	DPARM_SAFE_DFLT	(DPARM_DEFAULT & ~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING))
150 
151 
152 /* technically, not really correct, as they need to be rated based upon clock */
153 #define	ISP_40M_SYNCPARMS	0x080a
154 #define ISP_20M_SYNCPARMS	0x080c
155 #define ISP_10M_SYNCPARMS	0x0c19
156 #define ISP_08M_SYNCPARMS	0x0c25
157 #define ISP_05M_SYNCPARMS	0x0c32
158 #define ISP_04M_SYNCPARMS	0x0c41
159 
160 /*
161  * Fibre Channel Specifics
162  */
163 typedef struct {
164 	u_int8_t		isp_gotdparms;
165 	u_int8_t		isp_reserved;
166 	u_int8_t		isp_loopid;	/* hard loop id */
167 	u_int8_t		isp_alpa;	/* ALPA */
168 	u_int8_t		isp_execthrottle;
169         u_int8_t		isp_retry_delay;
170         u_int8_t		isp_retry_count;
171 	u_int8_t		isp_fwstate;	/* ISP F/W state */
172 	u_int64_t		isp_wwn;	/* WWN of adapter */
173 	u_int16_t		isp_maxalloc;
174 	u_int16_t		isp_maxfrmlen;
175 	u_int16_t		isp_fwoptions;
176 	/*
177 	 * Port Data Base
178 	 */
179 	isp_pdb_t		isp_pdb[MAX_FC_TARG];
180 
181 	/*
182 	 * Scratch DMA mapped in area to fetch Port Database stuff, etc.
183 	 */
184 	volatile caddr_t	isp_scratch;
185 	u_int32_t		isp_scdma;
186 } fcparam;
187 
188 #define	ISP2100_SCRLEN		0x100
189 
190 #define	FW_CONFIG_WAIT		0x0000
191 #define	FW_WAIT_AL_PA		0x0001
192 #define	FW_WAIT_LOGIN		0x0002
193 #define	FW_READY		0x0003
194 #define	FW_LOSS_OF_SYNC		0x0004
195 #define	FW_ERROR		0x0005
196 #define	FW_REINIT		0x0006
197 #define	FW_NON_PART		0x0007
198 
199 #ifdef	ISP_TARGET_MODE
200 /*
201  * Some temporary Target Mode definitions
202  */
203 typedef struct tmd_cmd {
204 	u_int8_t	cd_iid;		/* initiator */
205 	u_int8_t	cd_tgt;		/* target */
206 	u_int8_t	cd_lun;		/* LUN for this command */
207 	u_int8_t	cd_state;
208 	u_int8_t	cd_cdb[16];	/* command bytes */
209 	u_int8_t	cd_sensedata[20];
210 	u_int16_t	cd_rxid;
211 	u_int32_t	cd_datalen;
212 	u_int32_t	cd_totbytes;
213 	void *		cd_hba;
214 } tmd_cmd_t;
215 
216 /*
217  * Async Target Mode Event Definitions
218  */
219 #define	TMD_BUS_RESET	0
220 #define	TMD_BDR		1
221 
222 /*
223  * Immediate Notify data structure.
224  */
225 #define NOTIFY_MSGLEN	5
226 typedef struct {
227 	u_int8_t	nt_iid;			/* initiator */
228 	u_int8_t	nt_tgt;			/* target */
229 	u_int8_t	nt_lun;			/* LUN for this command */
230 	u_int8_t	nt_msg[NOTIFY_MSGLEN];	/* SCSI message byte(s) */
231 } tmd_notify_t;
232 
233 #endif
234 
235 /*
236  * Soft Structure per host adapter
237  */
238 struct ispsoftc {
239 	/*
240 	 * Platform (OS) specific data
241 	 */
242 	struct isposinfo	isp_osinfo;
243 
244 	/*
245 	 * Pointer to bus specific data
246 	 */
247 	struct ispmdvec *	isp_mdvec;
248 
249 	/*
250 	 * Mostly nonvolatile state.
251 	 */
252 
253 	u_int		isp_clock	: 8,
254 			isp_confopts	: 8,
255 			isp_fast_mttr	: 1,
256 					: 1,
257 			isp_used	: 1,
258 			isp_dblev	: 3,
259 			isp_dogactive	: 1,
260 			isp_bustype	: 1,	/* BUS Implementation */
261 			isp_type	: 8;	/* HBA Type and Revision */
262 
263 	u_int16_t		isp_fwrev[3];	/* Running F/W revision */
264 	u_int16_t		isp_romfw_rev[3]; /* 'ROM' F/W revision */
265 	void * 			isp_param;
266 
267 	/*
268 	 * Volatile state
269 	 */
270 
271 	volatile u_int
272 				:	13,
273 		isp_state	:	3,
274 				:	2,
275 		isp_sendmarker	:	2,	/* send a marker entry */
276 		isp_update	:	2,	/* update parameters */
277 		isp_nactive	:	10;	/* how many commands active */
278 
279 	/*
280 	 * Result and Request Queue indices.
281 	 */
282 	volatile u_int8_t	isp_reqodx;	/* index of last ISP pickup */
283 	volatile u_int8_t	isp_reqidx;	/* index of next request */
284 	volatile u_int8_t	isp_residx;	/* index of next result */
285 	volatile u_int8_t	isp_seqno;	/* rolling sequence # */
286 
287 	/*
288 	 * Sheer laziness, but it gets us around the problem
289 	 * where we don't have a clean way of remembering
290 	 * which transaction is bound to which ISP queue entry.
291 	 *
292 	 * There are other more clever ways to do this, but,
293 	 * jeez, so I blow a couple of KB per host adapter...
294 	 * and it *is* faster.
295 	 */
296 	ISP_SCSI_XFER_T *isp_xflist[RQUEST_QUEUE_LEN];
297 
298 	/*
299 	 * request/result queues and dma handles for them.
300 	 */
301 	volatile caddr_t	isp_rquest;
302 	volatile caddr_t	isp_result;
303 	u_int32_t		isp_rquest_dma;
304 	u_int32_t		isp_result_dma;
305 
306 #ifdef	ISP_TARGET_MODE
307 	/*
308 	 * Vectors for handling target mode support.
309 	 *
310 	 * isp_tmd_newcmd is for feeding a newly arrived command to some
311 	 * upper layer.
312 	 *
313 	 * isp_tmd_event is for notifying some upper layer that an event has
314 	 * occurred that is not necessarily tied to any target (e.g., a SCSI
315 	 * Bus Reset).
316 	 *
317 	 * isp_tmd_notify is for notifying some upper layer that some
318 	 * event is now occurring that is either pertinent for a specific
319 	 * device or for a specific command (e.g., BDR or ABORT TAG).
320 	 *
321 	 * It is left undefined (for now) how pools of commands are managed.
322 	 */
323 	void		(*isp_tmd_newcmd) __P((void *, tmd_cmd_t *));
324 	void		(*isp_tmd_event) __P((void *, int));
325 	void		(*isp_tmd_notify) __P((void *, tmd_notify_t *));
326 #endif
327 };
328 
329 /*
330  * ISP States
331  */
332 #define	ISP_NILSTATE	0
333 #define	ISP_RESETSTATE	1
334 #define	ISP_INITSTATE	2
335 #define	ISP_RUNSTATE	3
336 
337 /*
338  * ISP Configuration Options
339  */
340 #define	ISP_CFG_NORELOAD	0x80	/* don't download f/w */
341 #define	ISP_CFG_NONVRAM		0x40	/* ignore NVRAM */
342 
343 #define	ISP_FW_REV(maj, min, mic)	((maj << 24) | (min << 16) | mic)
344 #define	ISP_FW_REVX(xp)	((xp[0]<<24) | (xp[1] << 16) | xp[2])
345 
346 
347 /*
348  * Bus (implementation) types
349  */
350 #define	ISP_BT_PCI		0	/* PCI Implementations */
351 #define	ISP_BT_SBUS		1	/* SBus Implementations */
352 
353 /*
354  * Chip Types
355  */
356 #define	ISP_HA_SCSI		0xf
357 #define	ISP_HA_SCSI_UNKNOWN	0x1
358 #define	ISP_HA_SCSI_1020	0x2
359 #define	ISP_HA_SCSI_1020A	0x3
360 #define	ISP_HA_SCSI_1040	0x4
361 #define	ISP_HA_SCSI_1040A	0x5
362 #define	ISP_HA_SCSI_1040B	0x6
363 #define	ISP_HA_SCSI_1040C	0x7
364 #define	ISP_HA_SCSI_1080	0xd
365 #define	ISP_HA_SCSI_12X0	0xe
366 #define	ISP_HA_FC		0xf0
367 #define	ISP_HA_FC_2100		0x10
368 
369 #define	IS_SCSI(isp)	(isp->isp_type & ISP_HA_SCSI)
370 #define	IS_1080(isp)	(isp->isp_type == ISP_HA_SCSI_1080)
371 #define	IS_12X0(isp)	(isp->isp_type == ISP_HA_SCSI_12X0)
372 #define	IS_FC(isp)	(isp->isp_type & ISP_HA_FC)
373 
374 /*
375  * Macros to read, write ISP registers through bus specific code.
376  */
377 
378 #define	ISP_READ(isp, reg)	\
379 	(*(isp)->isp_mdvec->dv_rd_reg)((isp), (reg))
380 
381 #define	ISP_WRITE(isp, reg, val)	\
382 	(*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), (val))
383 
384 #define	ISP_MBOXDMASETUP(isp)	\
385 	(*(isp)->isp_mdvec->dv_mbxdma)((isp))
386 
387 #define	ISP_DMASETUP(isp, xs, req, iptrp, optr)	\
388 	(*(isp)->isp_mdvec->dv_dmaset)((isp), (xs), (req), (iptrp), (optr))
389 
390 #define	ISP_DMAFREE(isp, xs, seqno)	\
391 	if ((isp)->isp_mdvec->dv_dmaclr) \
392 		 (*(isp)->isp_mdvec->dv_dmaclr)((isp), (xs), (seqno))
393 
394 #define	ISP_RESET0(isp)	\
395 	if ((isp)->isp_mdvec->dv_reset0) (*(isp)->isp_mdvec->dv_reset0)((isp))
396 #define	ISP_RESET1(isp)	\
397 	if ((isp)->isp_mdvec->dv_reset1) (*(isp)->isp_mdvec->dv_reset1)((isp))
398 #define	ISP_DUMPREGS(isp)	\
399 	if ((isp)->isp_mdvec->dv_dregs) (*(isp)->isp_mdvec->dv_dregs)((isp))
400 
401 #define	ISP_SETBITS(isp, reg, val)	\
402  (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) | (val))
403 
404 #define	ISP_CLRBITS(isp, reg, val)	\
405  (*(isp)->isp_mdvec->dv_wr_reg)((isp), (reg), ISP_READ((isp), (reg)) & ~(val))
406 
407 /*
408  * Function Prototypes
409  */
410 
411 /*
412  * Reset Hardware. Totally. Assumes that you'll follow this with
413  * a call to isp_init.
414  */
415 void isp_reset __P((struct ispsoftc *));
416 
417 /*
418  * Initialize Hardware to known state
419  */
420 void isp_init __P((struct ispsoftc *));
421 
422 /*
423  * Reset the ISP and call completion for any orphaned commands.
424  */
425 void isp_restart __P((struct ispsoftc *));
426 
427 /*
428  * Interrupt Service Routine
429  */
430 int isp_intr __P((void *));
431 
432 /*
433  * Command Entry Point
434  */
435 int32_t ispscsicmd __P((ISP_SCSI_XFER_T *));
436 
437 /*
438  * Platform Dependent to External to Internal Control Function
439  *
440  * For: 	Aborting a running command	- arg is an ISP_SCSI_XFER_T *
441  *		Resetting a Device		- arg is target to reset
442  *		Resetting a BUS			- arg is ignored
443  *		Updating parameters		- arg is ignored
444  *
445  * First argument is this instance's softc pointer.
446  * Second argument is an index into xflist array.
447  * Assumes all locks must be held already.
448  */
449 typedef enum {
450 	ISPCTL_RESET_BUS,
451 	ISPCTL_RESET_DEV,
452 	ISPCTL_ABORT_CMD,
453 	ISPCTL_UPDATE_PARAMS,
454 	ISPCTL_FCLINK_TEST
455 } ispctl_t;
456 int isp_control __P((struct ispsoftc *, ispctl_t, void *));
457 
458 
459 /*
460  * Platform Dependent to Internal to External Control Function
461  * (each platform must provide such a function)
462  *
463  * For: 	Announcing Target Paramter Changes (arg is target)
464  *
465  * Assumes all locks are held.
466  */
467 
468 typedef enum {
469 	ISPASYNC_NEW_TGT_PARAMS,
470 	ISPASYNC_BUS_RESET,		/* Bus Reset */
471 	ISPASYNC_LOOP_DOWN,		/* Obvious FC only */
472 	ISPASYNC_LOOP_UP,		/* "" */
473 	ISPASYNC_PDB_CHANGE_COMPLETE,	/* "" */
474 	ISPASYNC_CHANGE_NOTIFY		/* "" */
475 } ispasync_t;
476 int isp_async __P((struct ispsoftc *, ispasync_t, void *));
477 
478 /*
479  * lost command routine (XXXX IN TRANSITION XXXX)
480  */
481 void isp_lostcmd __P((struct ispsoftc *, ISP_SCSI_XFER_T *));
482 
483 
484 #endif	/* _ISPVAR_H */
485