xref: /netbsd-src/sys/dev/ic/isp_netbsd.h (revision 481fca6e59249d8ffcf24fef7cfbe7b131bfb080)
1 /* $NetBSD: isp_netbsd.h,v 1.26 2000/07/05 22:25:06 mjacob Exp $ */
2 /*
3  * NetBSD Specific definitions for the Qlogic ISP Host Adapter
4  * Matthew Jacob <mjacob@nas.nasa.gov>
5  */
6 /*
7  * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
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, 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 ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 #ifndef	_ISP_NETBSD_H
33 #define	_ISP_NETBSD_H
34 
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/errno.h>
40 #include <sys/ioctl.h>
41 #include <sys/device.h>
42 #include <sys/malloc.h>
43 #include <sys/buf.h>
44 #include <sys/proc.h>
45 #include <sys/user.h>
46 
47 
48 #include <dev/scsipi/scsi_all.h>
49 #include <dev/scsipi/scsipi_all.h>
50 #include <dev/scsipi/scsiconf.h>
51 
52 #include <dev/scsipi/scsi_message.h>
53 #include <dev/scsipi/scsipi_debug.h>
54 
55 #include "opt_isp.h"
56 /*
57  * We always support fabric now
58  */
59 #ifndef	ISP2100_FABRIC
60 #define	ISP2100_FABRIC
61 #endif
62 
63 
64 #define	ISP_PLATFORM_VERSION_MAJOR	0
65 #define	ISP_PLATFORM_VERSION_MINOR	998
66 
67 #define	ISP_SCSI_XFER_T		struct scsipi_xfer
68 struct isposinfo {
69 	struct device		_dev;
70 	struct scsipi_link	_link;
71 	struct scsipi_link	_link_b;
72 	struct scsipi_adapter   _adapter;
73 	int			blocked;
74 	union {
75 		int		_seed;
76 		u_int16_t	_discovered[2];
77 	} un;
78 #define	seed		un._seed
79 #define	discovered	un._discovered
80 	TAILQ_HEAD(, scsipi_xfer) waitq;
81 	struct callout _restart;
82 };
83 
84 #define	MAXISPREQUEST	256
85 #ifdef	ISP2100_FABRIC
86 #define	ISP2100_SCRLEN		0x400
87 #else
88 #define	ISP2100_SCRLEN		0x100
89 #endif
90 
91 #include <dev/ic/ispreg.h>
92 #include <dev/ic/ispvar.h>
93 #include <dev/ic/ispmbox.h>
94 
95 #define	IDPRINTF(lev, x)	if (isp->isp_dblev >= lev) printf x
96 #define	PRINTF			printf
97 
98 #define	MEMZERO			bzero
99 #define	MEMCPY(dst, src, count)	bcopy((src), (dst), (count))
100 #ifdef	__alpha__
101 #define	MemoryBarrier	alpha_mb
102 #else
103 #define	MemoryBarrier()
104 #endif
105 
106 #define	DMA_MSW(x)	(((x) >> 16) & 0xffff)
107 #define	DMA_LSW(x)	(((x) & 0xffff))
108 
109 #if	defined(SCSIDEBUG)
110 #define	DFLT_DBLEVEL		3
111 #define	CFGPRINTF		printf
112 #elif	defined(DEBUG)
113 #define	DFLT_DBLEVEL		2
114 #define	CFGPRINTF		printf
115 #elif	defined(DIAGNOSTIC)
116 #define	DFLT_DBLEVEL		1
117 #define	CFGPRINTF		printf
118 #else
119 #define	DFLT_DBLEVEL		0
120 #define	CFGPRINTF		if (0) printf
121 #endif
122 
123 #define	ISP_LOCKVAL_DECL	int isp_spl_save
124 #define	ISP_ILOCKVAL_DECL	ISP_LOCKVAL_DECL
125 #define	ISP_LOCK(x)		isp_spl_save = splbio()
126 #define	ISP_UNLOCK(x)		(void) splx(isp_spl_save)
127 #define	ISP_ILOCK		ISP_LOCK
128 #define	ISP_IUNLOCK		ISP_UNLOCK
129 
130 #define	MBOX_WAIT_COMPLETE(isp)		\
131 	{ \
132 		int j; \
133 		for (j = 0; j < 60 * 2000; j++) { \
134 			if (isp_intr(isp) == 0) { \
135 				SYS_DELAY(500); \
136 			} \
137 			if (isp->isp_mboxbsy == 0) \
138 				break; \
139 		} \
140 		if (isp->isp_mboxbsy != 0) \
141 			printf("%s: mailbox timeout\n", isp->isp_name); \
142 	}
143 
144 #define	MBOX_NOTIFY_COMPLETE(isp)	isp->isp_mboxbsy = 0
145 
146 
147 #define	XS_NULL(xs)		xs == NULL || xs->sc_link == NULL
148 #define	XS_ISP(xs)		(xs)->sc_link->adapter_softc
149 #define	XS_LUN(xs)		((int) (xs)->sc_link->scsipi_scsi.lun)
150 #define	XS_TGT(xs)		((int) (xs)->sc_link->scsipi_scsi.target)
151 #define	XS_CHANNEL(xs)		\
152 	(((int) (xs)->sc_link->scsipi_scsi.channel == SCSI_CHANNEL_ONLY_ONE) ? \
153 	    0 : (xs)->sc_link->scsipi_scsi.channel)
154 #define	XS_RESID(xs)		(xs)->resid
155 #define	XS_XFRLEN(xs)		(xs)->datalen
156 #define	XS_CDBLEN(xs)		(xs)->cmdlen
157 #define	XS_CDBP(xs)		((caddr_t) (xs)->cmd)
158 #define	XS_STS(xs)		(xs)->status
159 #define	XS_TIME(xs)		(xs)->timeout
160 #define	XS_SNSP(xs)		(&(xs)->sense.scsi_sense)
161 #define	XS_SNSLEN(xs)		(sizeof (xs)->sense.scsi_sense)
162 #define	XS_SNSKEY(xs)		((xs)->sense.scsi_sense.flags)
163 
164 #define	HBA_NOERROR		XS_NOERROR
165 #define	HBA_BOTCH		XS_DRIVER_STUFFUP
166 #define	HBA_CMDTIMEOUT		XS_TIMEOUT
167 #define	HBA_SELTIMEOUT		XS_SELTIMEOUT
168 #define	HBA_TGTBSY		XS_BUSY
169 #ifdef	XS_RESET
170 #define	HBA_BUSRESET		XS_RESET
171 #else
172 #define	HBA_BUSRESET		XS_DRIVER_STUFFUP
173 #endif
174 #define	HBA_ABORTED		XS_DRIVER_STUFFUP
175 #define	HBA_DATAOVR		XS_DRIVER_STUFFUP
176 #define	HBA_ARQFAIL		XS_DRIVER_STUFFUP
177 
178 #define	XS_SNS_IS_VALID(xs)	(xs)->error = XS_SENSE
179 #define	XS_IS_SNS_VALID(xs)	((xs)->error == XS_SENSE)
180 
181 #define	XS_PSTS_INWDOG		0x10000000
182 #define	XS_PSTS_GRACE		0x20000000
183 #define	XS_PSTS_ALL		0x30000000
184 
185 #define	XS_CMD_S_WDOG(xs)	(xs)->xs_status |= XS_PSTS_INWDOG
186 #define	XS_CMD_C_WDOG(xs)	(xs)->xs_status &= ~XS_PSTS_INWDOG
187 #define	XS_CMD_WDOG_P(xs)	(((xs)->xs_status & XS_PSTS_INWDOG) != 0)
188 
189 #define	XS_CMD_S_GRACE(xs)	(xs)->xs_status |= XS_PSTS_GRACE
190 #define	XS_CMD_C_GRACE(xs)	(xs)->xs_status &= ~XS_PSTS_GRACE
191 #define	XS_CMD_GRACE_P(xs)	(((xs)->xs_status & XS_PSTS_GRACE) != 0)
192 
193 #define	XS_CMD_S_DONE(xs)	(xs)->xs_status |= XS_STS_DONE
194 #define	XS_CMD_C_DONE(xs)	(xs)->xs_status &= ~XS_STS_DONE
195 #define	XS_CMD_DONE_P(xs)	(((xs)->xs_status & XS_STS_DONE) != 0)
196 
197 #define	XS_CMD_S_CLEAR(xs)	(xs)->xs_status &= ~XS_PSTS_ALL
198 
199 #define	XS_INITERR(xs)		(xs)->error = 0, XS_CMD_S_CLEAR(xs)
200 #define	XS_SETERR(xs, v)	(xs)->error = v
201 #define	XS_ERR(xs)		(xs)->error
202 #define	XS_NOERR(xs)		(xs)->error == XS_NOERROR
203 
204 #define	XS_CMD_DONE		isp_done
205 
206 /*
207  * We use whether or not we're a polled command to decide about tagging.
208  */
209 #define	XS_CANTAG(xs)		(((xs)->xs_control & XS_CTL_POLL) != 0)
210 
211 /*
212  * This is our default tag (simple).
213  */
214 #define	XS_KINDOF_TAG(xs)	\
215 	(((xs)->xs_control & XS_CTL_URGENT) ? REQFLAG_HTAG : REQFLAG_OTAG)
216 
217 /*
218  * These get turned into NetBSD midlayer codes
219  */
220 #define	CMD_COMPLETE		100
221 #define	CMD_EAGAIN		101
222 #define	CMD_QUEUED		102
223 #define	CMD_RQLATER		103
224 
225 
226 #define	isp_name	isp_osinfo._dev.dv_xname
227 #define	isp_unit	isp_osinfo._dev.dv_unit
228 
229 #define	SCSI_QFULL	0x28
230 
231 #define	SYS_DELAY(x)	delay(x)
232 
233 #define	WATCH_INTERVAL	30
234 
235 #define	FC_FW_READY_DELAY	(12 * 1000000)
236 #define	DEFAULT_LOOPID(x)	108
237 #define	DEFAULT_WWN(x)		(0x1000beed00000000LL + (x)->isp_osinfo.seed)
238 
239 extern void isp_attach __P((struct ispsoftc *));
240 extern void isp_uninit __P((struct ispsoftc *));
241 
242 #define ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src)	\
243         bcopy(src, dest, sizeof (isp_pdb_t))
244 #define ISP_SWIZZLE_ICB(a, b)
245 #ifdef	__sparc__
246 #define	ISP_SWIZZLE_CONTINUATION(a, b)	ISP_SBUSIFY_ISPHDR(a, &(b)->req_header)
247 #define ISP_SWIZZLE_REQUEST(a, b)			\
248 	ISP_SBUSIFY_ISPHDR(a, &(b)->req_header);	\
249         ISP_SBUSIFY_ISPREQ(a, b)
250 #define ISP_UNSWIZZLE_RESPONSE(a, b)			\
251 	ISP_SBUSIFY_ISPHDR(a, &(b)->req_header)
252 #else
253 #define	ISP_SWIZZLE_CONTINUATION(a, b)
254 #define ISP_SWIZZLE_REQUEST(a, b)
255 #define ISP_UNSWIZZLE_RESPONSE(a, b)
256 #endif
257 #define	ISP_SWIZZLE_SNS_REQ(a, b)
258 #define	ISP_UNSWIZZLE_SNS_RSP(a, b, c)
259 
260 extern void isp_done	__P((ISP_SCSI_XFER_T *));
261 #define	STRNCAT			strncat
262 static inline char *strncat(char *, const char *, size_t);
263 static inline char *
264 strncat(char *d, const char *s, size_t c)
265 {
266         char *t = d;
267 
268         if (c) {
269                 while (*d)
270                         d++;
271                 while ((*d++ = *s++)) {
272                         if (--c == 0) {
273                                 *d = '\0';
274                                 break;
275                         }
276                 }
277         }
278         return (t);
279 }
280 
281 
282 #define	INLINE	inline
283 #include <dev/ic/isp_inline.h>
284 
285 #if	!defined(ISP_DISABLE_FW) && !defined(ISP_COMPILE_FW)
286 #define	ISP_COMPILE_FW	1
287 #endif
288 #endif	/* _ISP_NETBSD_H */
289