xref: /netbsd-src/sys/dev/ic/isp_netbsd.h (revision bcc8ec9959e7b01e313d813067bfb43a3ad70551)
1 /* $NetBSD: isp_netbsd.h,v 1.35 2001/01/05 07:03:54 mjacob Exp $ */
2 /*
3  * This driver, which is contained in NetBSD in the files:
4  *
5  *	sys/dev/ic/isp.c
6  *	sys/dev/ic/isp_inline.h
7  *	sys/dev/ic/isp_netbsd.c
8  *	sys/dev/ic/isp_netbsd.h
9  *	sys/dev/ic/isp_target.c
10  *	sys/dev/ic/isp_target.h
11  *	sys/dev/ic/isp_tpublic.h
12  *	sys/dev/ic/ispmbox.h
13  *	sys/dev/ic/ispreg.h
14  *	sys/dev/ic/ispvar.h
15  *	sys/microcode/isp/asm_sbus.h
16  *	sys/microcode/isp/asm_1040.h
17  *	sys/microcode/isp/asm_1080.h
18  *	sys/microcode/isp/asm_12160.h
19  *	sys/microcode/isp/asm_2100.h
20  *	sys/microcode/isp/asm_2200.h
21  *	sys/pci/isp_pci.c
22  *	sys/sbus/isp_sbus.c
23  *
24  * Is being actively maintained by Matthew Jacob (mjacob@netbsd.org).
25  * This driver also is shared source with FreeBSD, OpenBSD, Linux, Solaris,
26  * Linux versions. This tends to be an interesting maintenance problem.
27  *
28  * Please coordinate with Matthew Jacob on changes you wish to make here.
29  */
30 /*
31  * NetBSD Specific definitions for the Qlogic ISP Host Adapter
32  * Matthew Jacob <mjacob@nas.nasa.gov>
33  */
34 /*
35  * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
36  * All rights reserved.
37  *
38  * Redistribution and use in source and binary forms, with or without
39  * modification, are permitted provided that the following conditions
40  * are met:
41  * 1. Redistributions of source code must retain the above copyright
42  *    notice, this list of conditions and the following disclaimer.
43  * 2. Redistributions in binary form must reproduce the above copyright
44  *    notice, this list of conditions and the following disclaimer in the
45  *    documentation and/or other materials provided with the distribution.
46  * 3. The name of the author may not be used to endorse or promote products
47  *    derived from this software without specific prior written permission
48  *
49  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
50  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
51  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
52  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
53  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
54  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
55  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
56  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
58  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59  */
60 #ifndef	_ISP_NETBSD_H
61 #define	_ISP_NETBSD_H
62 
63 #include <sys/types.h>
64 #include <sys/param.h>
65 #include <sys/systm.h>
66 #include <sys/kernel.h>
67 #include <sys/errno.h>
68 #include <sys/ioctl.h>
69 #include <sys/device.h>
70 #include <sys/malloc.h>
71 #include <sys/buf.h>
72 #include <sys/proc.h>
73 #include <sys/user.h>
74 
75 
76 #include <dev/scsipi/scsi_all.h>
77 #include <dev/scsipi/scsipi_all.h>
78 #include <dev/scsipi/scsiconf.h>
79 
80 #include <dev/scsipi/scsi_message.h>
81 #include <dev/scsipi/scsipi_debug.h>
82 
83 #include "opt_isp.h"
84 
85 
86 #define	ISP_PLATFORM_VERSION_MAJOR	1
87 #define	ISP_PLATFORM_VERSION_MINOR	0
88 
89 struct isposinfo {
90 	struct device		_dev;
91 	struct scsipi_link	_link;
92 	struct scsipi_link	_link_b;
93 	struct scsipi_adapter   _adapter;
94 	int	splsaved;
95 	int	mboxwaiting;
96 	u_int32_t	islocked;
97 	u_int32_t	onintstack;
98 	unsigned int		: 30,
99 		no_mbox_ints	: 1,
100 		blocked		: 1;
101 	union {
102 		u_int64_t	_wwn;
103 		u_int16_t	_discovered[2];
104 #define	wwn_seed	un._wwn
105 #define	discovered	un._discovered
106 	} un;
107 	TAILQ_HEAD(, scsipi_xfer) waitq;
108 	struct callout _restart;
109 };
110 #define	ISP_MUSTPOLL(isp)	\
111 	(isp->isp_osinfo.onintstack || isp->isp_osinfo.no_mbox_ints)
112 
113 /*
114  * Required Macros/Defines
115  */
116 
117 #define	INLINE			inline
118 
119 #define	ISP2100_FABRIC		1
120 #define	ISP2100_SCRLEN		0x400
121 
122 #define	MEMZERO			bzero
123 #define	MEMCPY(dst, src, amt)	bcopy((src), (dst), (amt))
124 #define	SNPRINTF		snprintf
125 #define	STRNCAT			strncat
126 #define	USEC_DELAY		DELAY
127 #define	USEC_SLEEP(isp, x)		\
128 	if (!ISP_MUSTPOLL(isp))		\
129 		ISP_UNLOCK(isp);	\
130 	DELAY(x);			\
131 	if (!ISP_MUSTPOLL(isp))		\
132 		ISP_LOCK(isp)
133 
134 #define	NANOTIME_T		struct timeval
135 #define	GET_NANOTIME		microtime
136 #define	GET_NANOSEC(x)		(((x)->tv_sec * 1000000 + (x)->tv_usec) * 1000)
137 #define	NANOTIME_SUB		isp_microtime_sub
138 
139 #define	MAXISPREQUEST(isp)	256
140 
141 #ifdef	__alpha__
142 #define	MEMORYBARRIER(isp, type, offset, size)	alpha_mb()
143 #else
144 #define	MEMORYBARRIER(isp, type, offset, size)
145 #endif
146 
147 #define	MBOX_ACQUIRE(isp)
148 #define	MBOX_WAIT_COMPLETE	isp_wait_complete
149 
150 #define	MBOX_NOTIFY_COMPLETE(isp)					\
151 	if (isp->isp_osinfo.mboxwaiting) {				\
152                 isp->isp_osinfo.mboxwaiting = 0;			\
153                 wakeup(&isp->isp_osinfo.mboxwaiting);			\
154         }								\
155 	isp->isp_mboxbsy = 0
156 
157 #define	MBOX_RELEASE(isp)
158 
159 #ifndef	SCSI_GOOD
160 #define	SCSI_GOOD	0x0
161 #endif
162 #ifndef	SCSI_CHECK
163 #define	SCSI_CHECK	0x2
164 #endif
165 #ifndef	SCSI_BUSY
166 #define	SCSI_BUSY	0x8
167 #endif
168 #ifndef	SCSI_QFULL
169 #define	SCSI_QFULL	0x28
170 #endif
171 
172 #define	XS_T			struct scsipi_xfer
173 #define	XS_CHANNEL(xs)		\
174 	(((int) (xs)->sc_link->scsipi_scsi.channel == SCSI_CHANNEL_ONLY_ONE) ? \
175 	    0 : (xs)->sc_link->scsipi_scsi.channel)
176 #define	XS_ISP(xs)		(xs)->sc_link->adapter_softc
177 #define	XS_LUN(xs)		((int) (xs)->sc_link->scsipi_scsi.lun)
178 #define	XS_TGT(xs)		((int) (xs)->sc_link->scsipi_scsi.target)
179 #define	XS_CDBP(xs)		((caddr_t) (xs)->cmd)
180 #define	XS_CDBLEN(xs)		(xs)->cmdlen
181 #define	XS_XFRLEN(xs)		(xs)->datalen
182 #define	XS_TIME(xs)		(xs)->timeout
183 #define	XS_RESID(xs)		(xs)->resid
184 #define	XS_STSP(xs)		(&(xs)->status)
185 #define	XS_SNSP(xs)		(&(xs)->sense.scsi_sense)
186 #define	XS_SNSLEN(xs)		(sizeof (xs)->sense)
187 #define	XS_SNSKEY(xs)		((xs)->sense.scsi_sense.flags)
188 #define	XS_TAG_P(ccb)		(((xs)->xs_control & XS_CTL_POLL) != 0)
189 #define	XS_TAG_TYPE(xs)	\
190 	(((xs)->xs_control & XS_CTL_URGENT) ? REQFLAG_HTAG : \
191 	((xs)->bp && xs->bp->b_flags & B_ASYNC) ? REQFLAG_STAG : REQFLAG_OTAG)
192 
193 #define	XS_SETERR(xs, v)	(xs)->error = v
194 
195 #	define	HBA_NOERROR		XS_NOERROR
196 #	define	HBA_BOTCH		XS_DRIVER_STUFFUP
197 #	define	HBA_CMDTIMEOUT		XS_TIMEOUT
198 #	define	HBA_SELTIMEOUT		XS_SELTIMEOUT
199 #	define	HBA_TGTBSY		XS_BUSY
200 #	define	HBA_BUSRESET		XS_RESET
201 #	define	HBA_ABORTED		XS_DRIVER_STUFFUP
202 #	define	HBA_DATAOVR		XS_DRIVER_STUFFUP
203 #	define	HBA_ARQFAIL		XS_DRIVER_STUFFUP
204 
205 #define	XS_ERR(xs)		(xs)->error
206 
207 #define	XS_NOERR(xs)		(xs)->error == XS_NOERROR
208 
209 #define	XS_INITERR(xs)		(xs)->error = 0, XS_CMD_S_CLEAR(xs)
210 
211 #define	XS_SAVE_SENSE(xs, sp)				\
212 	if (xs->error == XS_NOERROR) {			\
213 		xs->error = XS_SENSE;			\
214 	}						\
215 	bcopy(sp->req_sense_data, &(xs)->sense,		\
216 	    imin(XS_SNSLEN(xs), sp->req_sense_len))
217 
218 #define	XS_SET_STATE_STAT(a, b, c)
219 
220 #define	DEFAULT_IID(x)		7
221 #define	DEFAULT_LOOPID(x)	108
222 #define	DEFAULT_NODEWWN(isp)	(isp)->isp_osinfo.un._wwn
223 #define	DEFAULT_PORTWWN(isp)	(isp)->isp_osinfo.un._wwn
224 #define	ISP_NODEWWN(isp)	FCPARAM(isp)->isp_nodewwn
225 #define	ISP_PORTWWN(isp)	FCPARAM(isp)->isp_portwwn
226 
227 #if	_BYTE_ORDER == _BIG_ENDIAN
228 #define	ISP_SWIZZLE_REQUEST		isp_swizzle_request
229 #define	ISP_UNSWIZZLE_RESPONSE		isp_unswizzle_response
230 #define	ISP_SWIZZLE_ICB			isp_swizzle_icb
231 #define	ISP_UNSWIZZLE_AND_COPY_PDBP	isp_unswizzle_and_copy_pdbp
232 #define	ISP_SWIZZLE_SNS_REQ		isp_swizzle_sns_req
233 #define	ISP_UNSWIZZLE_SNS_RSP		isp_unswizzle_sns_rsp
234 #define	ISP_SWIZZLE_NVRAM_WORD(isp, rp)	*rp = bswap16(*rp)
235 #else
236 #define	ISP_SWIZZLE_REQUEST(a, b)
237 #define	ISP_UNSWIZZLE_RESPONSE(a, b, c)
238 #define	ISP_SWIZZLE_ICB(a, b)
239 #define	ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src)	\
240 	if((void *)src != (void *)dest) bcopy(src, dest, sizeof (isp_pdb_t))
241 #define	ISP_SWIZZLE_SNS_REQ(a, b)
242 #define	ISP_UNSWIZZLE_SNS_RSP(a, b, c)
243 #define	ISP_SWIZZLE_NVRAM_WORD(isp, rp)
244 #endif
245 
246 /*
247  * Includes of common header files
248  */
249 
250 #include <dev/ic/ispreg.h>
251 #include <dev/ic/ispvar.h>
252 #include <dev/ic/ispmbox.h>
253 
254 /*
255  * isp_osinfo definitions, extensions and shorthand.
256  */
257 #define	isp_name	isp_osinfo._dev.dv_xname
258 #define	isp_unit	isp_osinfo._dev.dv_unit
259 
260 /*
261  * Driver prototypes..
262  */
263 void isp_attach __P((struct ispsoftc *));
264 void isp_uninit __P((struct ispsoftc *));
265 
266 static inline void isp_lock __P((struct ispsoftc *));
267 static inline void isp_unlock __P((struct ispsoftc *));
268 static inline char *strncat __P((char *, const char *, size_t));
269 static inline u_int64_t
270 isp_microtime_sub __P((struct timeval *, struct timeval *));
271 static void isp_wait_complete __P((struct ispsoftc *));
272 #if	_BYTE_ORDER == _BIG_ENDIAN
273 static inline void isp_swizzle_request(struct ispsoftc *, ispreq_t *);
274 static inline void isp_unswizzle_response(struct ispsoftc *, void *, u_int16_t);
275 static inline void isp_swizzle_icb(struct ispsoftc *, isp_icb_t *);
276 static inline void
277 isp_unswizzle_and_copy_pdbp(struct ispsoftc *, isp_pdb_t *, void *);
278 static inline void isp_swizzle_sns_req(struct ispsoftc *, sns_screq_t *);
279 static inline void isp_unswizzle_sns_rsp(struct ispsoftc *, sns_scrsp_t *, int);
280 #endif
281 
282 /*
283  * Driver wide data...
284  */
285 
286 /*
287  * Locking macros...
288  */
289 #define	ISP_LOCK		isp_lock
290 #define	ISP_UNLOCK		isp_unlock
291 #define	ISP_ILOCK(x)		isp_lock(x); isp->isp_osinfo.onintstack++
292 #define	ISP_IUNLOCK(x)		isp->isp_osinfo.onintstack--; isp_unlock(x)
293 
294 /*
295  * Platform private flags
296  */
297 
298 #define	XS_PSTS_INWDOG		0x10000000
299 #define	XS_PSTS_GRACE		0x20000000
300 #define	XS_PSTS_ALL		0x30000000
301 
302 #define	XS_CMD_S_WDOG(xs)	(xs)->xs_status |= XS_PSTS_INWDOG
303 #define	XS_CMD_C_WDOG(xs)	(xs)->xs_status &= ~XS_PSTS_INWDOG
304 #define	XS_CMD_WDOG_P(xs)	(((xs)->xs_status & XS_PSTS_INWDOG) != 0)
305 
306 #define	XS_CMD_S_GRACE(xs)	(xs)->xs_status |= XS_PSTS_GRACE
307 #define	XS_CMD_C_GRACE(xs)	(xs)->xs_status &= ~XS_PSTS_GRACE
308 #define	XS_CMD_GRACE_P(xs)	(((xs)->xs_status & XS_PSTS_GRACE) != 0)
309 
310 #define	XS_CMD_S_DONE(xs)	(xs)->xs_status |= XS_STS_DONE
311 #define	XS_CMD_C_DONE(xs)	(xs)->xs_status &= ~XS_STS_DONE
312 #define	XS_CMD_DONE_P(xs)	(((xs)->xs_status & XS_STS_DONE) != 0)
313 
314 #define	XS_CMD_S_CLEAR(xs)	(xs)->xs_status &= ~XS_PSTS_ALL
315 
316 /*
317  * Platform specific 'inline' or support functions
318  */
319 static inline void
320 isp_lock(isp)
321 	struct ispsoftc *isp;
322 {
323 	int s = splbio();
324 	if (isp->isp_osinfo.islocked++ == 0) {
325 		isp->isp_osinfo.splsaved = s;
326 	} else {
327 		splx(s);
328 	}
329 }
330 
331 static inline void
332 isp_unlock(isp)
333 	struct ispsoftc *isp;
334 {
335 	if (isp->isp_osinfo.islocked-- <= 1) {
336 		isp->isp_osinfo.islocked = 0;
337 		splx(isp->isp_osinfo.splsaved);
338 	}
339 }
340 
341 static inline char *
342 strncat(d, s, c)
343 	char *d;
344 	const char *s;
345 	size_t c;
346 {
347         char *t = d;
348 
349         if (c) {
350                 while (*d)
351                         d++;
352                 while ((*d++ = *s++)) {
353                         if (--c == 0) {
354                                 *d = '\0';
355                                 break;
356                         }
357                 }
358         }
359         return (t);
360 }
361 
362 static inline u_int64_t
363 isp_microtime_sub(b, a)
364 	struct timeval *b;
365 	struct timeval *a;
366 {
367 	struct timeval x;
368 	u_int64_t elapsed;
369 	timersub(b, a, &x);
370 	elapsed = GET_NANOSEC(&x);
371 	if (elapsed == 0)
372 		elapsed++;
373 	return (elapsed);
374 }
375 
376 static inline void
377 isp_wait_complete(isp)
378 	struct ispsoftc *isp;
379 {
380 	if (isp->isp_osinfo.onintstack || isp->isp_osinfo.no_mbox_ints) {
381 		int usecs = 0;
382 		/*
383 		 * For sanity's sake, we don't delay longer
384 		 * than 5 seconds for polled commands.
385 		 */
386 		while (usecs < 5 * 1000000) {
387 			(void) isp_intr(isp);
388 			if (isp->isp_mboxbsy == 0) {
389 				break;
390 			}
391 			USEC_DELAY(500);
392 			usecs += 500;
393 		}
394 		if (isp->isp_mboxbsy != 0) {
395 			isp_prt(isp, ISP_LOGWARN,
396 			    "Polled Mailbox Command (0x%x) Timeout",
397 			    isp->isp_mboxtmp[0]);
398 		}
399 	} else {
400 		int rv = 0;
401                 isp->isp_osinfo.mboxwaiting = 1;
402                 while (isp->isp_osinfo.mboxwaiting && rv == 0) {
403 			static const struct timeval dtime = { 5, 0 };
404 			int timo;
405 			struct timeval tv;
406 			microtime(&tv);
407 			timeradd(&tv, &dtime, &tv);
408 			if ((timo = hzto(&tv)) == 0) {
409 				timo = 1;
410 			}
411 			rv = tsleep(&isp->isp_osinfo.mboxwaiting,
412 			    PRIBIO, "isp_mboxcmd", timo);
413 		}
414 		if (rv == EWOULDBLOCK) {
415 			isp->isp_mboxbsy = 0;
416 			isp->isp_osinfo.mboxwaiting = 0;
417 			isp_prt(isp, ISP_LOGWARN,
418 			    "Interrupting Mailbox Command (0x%x) Timeout",
419 			    isp->isp_mboxtmp[0]);
420 		}
421 	}
422 }
423 
424 #if	_BYTE_ORDER == _BIG_ENDIAN
425 static inline void
426 isp_swizzle_request(struct ispsoftc *isp, ispreq_t *rq)
427 {
428 	if (IS_FC(isp)) {
429 		ispreqt2_t *tq = (ispreqt2_t *) rq;
430 		tq->req_handle = bswap32(tq->req_handle);
431 		tq->req_scclun = bswap16(tq->req_scclun);
432 		tq->req_flags = bswap16(tq->req_flags);
433 		tq->req_time = bswap16(tq->req_time);
434 		tq->req_totalcnt = bswap32(tq->req_totalcnt);
435 	} else if (isp->isp_bustype == ISP_BT_SBUS) {
436 		_ISP_SWAP8(rq->req_header.rqs_entry_count,
437 		    rq->req_header.rqs_entry_type);
438 		_ISP_SWAP8(rq->req_header.rqs_flags, rq->req_header.rqs_seqno);
439 		_ISP_SWAP8(rq->req_target, rq->req_lun_trn);
440 	} else {
441 		rq->req_handle = bswap32(rq->req_handle);
442 		rq->req_cdblen = bswap16(rq->req_cdblen);
443 		rq->req_flags = bswap16(rq->req_flags);
444 		rq->req_time = bswap16(rq->req_time);
445 	}
446 }
447 
448 static inline void
449 isp_unswizzle_response(struct ispsoftc *isp, void *rp, u_int16_t optr)
450 {
451 	ispstatusreq_t *sp = rp;
452 	MEMORYBARRIER(isp, SYNC_RESPONSE, optr * QENTRY_LEN, QENTRY_LEN);
453 	if (isp->isp_bustype == ISP_BT_SBUS) {
454 		_ISP_SWAP8(sp->req_header.rqs_entry_count,
455 		    sp->req_header.rqs_entry_type);
456 		_ISP_SWAP8(sp->req_header.rqs_flags, sp->req_header.rqs_seqno);
457 	} else switch (sp->req_header.rqs_entry_type) {
458 	case RQSTYPE_RESPONSE:
459 		sp->req_handle = bswap32(sp->req_handle);
460 		sp->req_scsi_status = bswap16(sp->req_scsi_status);
461 		sp->req_completion_status = bswap16(sp->req_completion_status);
462 		sp->req_state_flags = bswap16(sp->req_state_flags);
463 		sp->req_status_flags = bswap16(sp->req_status_flags);
464 		sp->req_time = bswap16(sp->req_time);
465 		sp->req_sense_len = bswap16(sp->req_sense_len);
466 		sp->req_resid = bswap32(sp->req_resid);
467 		break;
468 	default:
469 		break;
470 	}
471 }
472 
473 static inline void
474 isp_swizzle_icb(struct ispsoftc *isp, isp_icb_t *icbp)
475 {
476 	_ISP_SWAP8(icbp->icb_version, icbp->_reserved0);
477 	_ISP_SWAP8(icbp->icb_retry_count, icbp->icb_retry_delay);
478 	_ISP_SWAP8(icbp->icb_iqdevtype, icbp->icb_logintime);
479 	_ISP_SWAP8(icbp->icb_ccnt, icbp->icb_icnt);
480 	_ISP_SWAP8(icbp->icb_racctimer, icbp->icb_idelaytimer);
481 	icbp->icb_fwoptions = bswap16(icbp->icb_fwoptions);
482 	icbp->icb_maxfrmlen = bswap16(icbp->icb_maxfrmlen);
483 	icbp->icb_maxalloc = bswap16(icbp->icb_maxalloc);
484 	icbp->icb_execthrottle = bswap16(icbp->icb_execthrottle);
485 	icbp->icb_hardaddr = bswap16(icbp->icb_hardaddr);
486 	icbp->icb_rqstout = bswap16(icbp->icb_rqstout);
487 	icbp->icb_rspnsin = bswap16(icbp->icb_rspnsin);
488 	icbp->icb_rqstqlen = bswap16(icbp->icb_rqstqlen);
489 	icbp->icb_rsltqlen = bswap16(icbp->icb_rsltqlen);
490 	icbp->icb_lunenables = bswap16(icbp->icb_lunenables);
491 	icbp->icb_lunetimeout = bswap16(icbp->icb_lunetimeout);
492 	icbp->icb_xfwoptions = bswap16(icbp->icb_xfwoptions);
493 	icbp->icb_zfwoptions = bswap16(icbp->icb_zfwoptions);
494 	icbp->icb_rqstaddr[0] = bswap16(icbp->icb_rqstaddr[0]);
495 	icbp->icb_rqstaddr[1] = bswap16(icbp->icb_rqstaddr[1]);
496 	icbp->icb_rqstaddr[2] = bswap16(icbp->icb_rqstaddr[2]);
497 	icbp->icb_rqstaddr[3] = bswap16(icbp->icb_rqstaddr[3]);
498 	icbp->icb_respaddr[0] = bswap16(icbp->icb_respaddr[0]);
499 	icbp->icb_respaddr[1] = bswap16(icbp->icb_respaddr[1]);
500 	icbp->icb_respaddr[2] = bswap16(icbp->icb_respaddr[2]);
501 	icbp->icb_respaddr[3] = bswap16(icbp->icb_respaddr[3]);
502 }
503 
504 static inline void
505 isp_unswizzle_and_copy_pdbp(struct ispsoftc *isp, isp_pdb_t *dst, void *src)
506 {
507 	isp_pdb_t *pdbp = src;
508 	dst->pdb_options = bswap16(pdbp->pdb_options);
509 	dst->pdb_mstate = pdbp->pdb_sstate;
510 	dst->pdb_sstate = pdbp->pdb_mstate;
511 	dst->pdb_hardaddr_bits[0] = pdbp->pdb_hardaddr_bits[0];
512 	dst->pdb_hardaddr_bits[1] = pdbp->pdb_hardaddr_bits[1];
513 	dst->pdb_hardaddr_bits[2] = pdbp->pdb_hardaddr_bits[2];
514 	dst->pdb_hardaddr_bits[3] = pdbp->pdb_hardaddr_bits[3];
515 	dst->pdb_portid_bits[0] = pdbp->pdb_portid_bits[0];
516 	dst->pdb_portid_bits[1] = pdbp->pdb_portid_bits[1];
517 	dst->pdb_portid_bits[2] = pdbp->pdb_portid_bits[2];
518 	dst->pdb_portid_bits[3] = pdbp->pdb_portid_bits[3];
519 	dst->pdb_nodename[0] = pdbp->pdb_nodename[0];
520 	dst->pdb_nodename[1] = pdbp->pdb_nodename[1];
521 	dst->pdb_nodename[2] = pdbp->pdb_nodename[2];
522 	dst->pdb_nodename[3] = pdbp->pdb_nodename[3];
523 	dst->pdb_nodename[4] = pdbp->pdb_nodename[4];
524 	dst->pdb_nodename[5] = pdbp->pdb_nodename[5];
525 	dst->pdb_nodename[6] = pdbp->pdb_nodename[6];
526 	dst->pdb_nodename[7] = pdbp->pdb_nodename[7];
527 	dst->pdb_portname[0] = pdbp->pdb_portname[0];
528 	dst->pdb_portname[1] = pdbp->pdb_portname[1];
529 	dst->pdb_portname[2] = pdbp->pdb_portname[2];
530 	dst->pdb_portname[3] = pdbp->pdb_portname[3];
531 	dst->pdb_portname[4] = pdbp->pdb_portname[4];
532 	dst->pdb_portname[5] = pdbp->pdb_portname[5];
533 	dst->pdb_portname[6] = pdbp->pdb_portname[6];
534 	dst->pdb_portname[7] = pdbp->pdb_portname[7];
535 	dst->pdb_execthrottle = bswap16(pdbp->pdb_execthrottle);
536 	dst->pdb_exec_count = bswap16(pdbp->pdb_exec_count);
537 	dst->pdb_resalloc = bswap16(pdbp->pdb_resalloc);
538 	dst->pdb_curalloc = bswap16(pdbp->pdb_curalloc);
539 	dst->pdb_qhead = bswap16(pdbp->pdb_qhead);
540 	dst->pdb_qtail = bswap16(pdbp->pdb_qtail);
541 	dst->pdb_tl_next = bswap16(pdbp->pdb_tl_next);
542 	dst->pdb_tl_last = bswap16(pdbp->pdb_tl_last);
543 	dst->pdb_features = bswap16(pdbp->pdb_features);
544 	dst->pdb_pconcurrnt = bswap16(pdbp->pdb_pconcurrnt);
545 	dst->pdb_roi = bswap16(pdbp->pdb_roi);
546 	dst->pdb_rdsiz = bswap16(pdbp->pdb_rdsiz);
547 	dst->pdb_ncseq = bswap16(pdbp->pdb_ncseq);
548 	dst->pdb_noseq = bswap16(pdbp->pdb_noseq);
549 	dst->pdb_labrtflg = bswap16(pdbp->pdb_labrtflg);
550 	dst->pdb_lstopflg = bswap16(pdbp->pdb_lstopflg);
551 	dst->pdb_sqhead = bswap16(pdbp->pdb_sqhead);
552 	dst->pdb_sqtail = bswap16(pdbp->pdb_sqtail);
553 	dst->pdb_ptimer = bswap16(pdbp->pdb_ptimer);
554 	dst->pdb_nxt_seqid = bswap16(pdbp->pdb_nxt_seqid);
555 	dst->pdb_fcount = bswap16(pdbp->pdb_fcount);
556 	dst->pdb_prli_len = bswap16(pdbp->pdb_prli_len);
557 	dst->pdb_prli_svc0 = bswap16(pdbp->pdb_prli_svc0);
558 	dst->pdb_prli_svc3 = bswap16(pdbp->pdb_prli_svc3);
559 	dst->pdb_loopid = bswap16(pdbp->pdb_loopid);
560 	dst->pdb_il_ptr = bswap16(pdbp->pdb_il_ptr);
561 	dst->pdb_sl_ptr = bswap16(pdbp->pdb_sl_ptr);
562 	dst->pdb_retry_count = pdbp->pdb_retry_delay;
563 	dst->pdb_retry_delay = pdbp->pdb_retry_count;
564 	dst->pdb_target = pdbp->pdb_initiator;
565 	dst->pdb_initiator = pdbp->pdb_target;
566 }
567 
568 static inline void
569 isp_swizzle_sns_req(struct ispsoftc *isp, sns_screq_t *reqp)
570 {
571 	u_int16_t index, nwords = reqp->snscb_sblen;
572 	reqp->snscb_rblen = bswap16(reqp->snscb_rblen);
573 	reqp->snscb_addr[0] = bswap16(reqp->snscb_addr[0]);
574 	reqp->snscb_addr[1] = bswap16(reqp->snscb_addr[1]);
575 	reqp->snscb_addr[2] = bswap16(reqp->snscb_addr[2]);
576 	reqp->snscb_addr[3] = bswap16(reqp->snscb_addr[3]);
577 	reqp->snscb_sblen = bswap16(reqp->snscb_sblen);
578 	for (index = 0; index < nwords; index++) {
579 		reqp->snscb_data[index] = bswap16(reqp->snscb_data[index]);
580 	}
581 }
582 
583 static inline void
584 isp_unswizzle_sns_rsp(struct ispsoftc *isp, sns_scrsp_t *resp, int nwords)
585 {
586 	int index;
587 	for (index = 0; index < nwords; index++) {
588 		resp->snscb_data[index] = bswap16(resp->snscb_data[index]);
589 	}
590 }
591 #endif
592 
593 /*
594  * Common inline functions
595  */
596 #define	INLINE	inline
597 #include <dev/ic/isp_inline.h>
598 
599 #if	!defined(ISP_DISABLE_FW) && !defined(ISP_COMPILE_FW)
600 #define	ISP_COMPILE_FW	1
601 #endif
602 #endif	/* _ISP_NETBSD_H */
603