xref: /netbsd-src/sys/dev/ic/isp_netbsd.h (revision 3b01aba77a7a698587faaae455bbfe740923c1f5)
1 /* $NetBSD: isp_netbsd.h,v 1.45 2001/07/07 16:15:03 thorpej 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 #include <sys/kthread.h>
75 
76 
77 #include <dev/scsipi/scsi_all.h>
78 #include <dev/scsipi/scsipi_all.h>
79 #include <dev/scsipi/scsiconf.h>
80 
81 #include <dev/scsipi/scsi_message.h>
82 #include <dev/scsipi/scsipi_debug.h>
83 
84 #include "opt_isp.h"
85 
86 
87 #define	ISP_PLATFORM_VERSION_MAJOR	2
88 #define	ISP_PLATFORM_VERSION_MINOR	0
89 
90 struct isposinfo {
91 	struct device		_dev;
92 	struct scsipi_channel	_chan;
93 	struct scsipi_channel	_chan_b;
94 	struct scsipi_adapter   _adapter;
95 	int	splsaved;
96 	int	mboxwaiting;
97 	u_int32_t	islocked;
98 	u_int32_t	onintstack;
99 	unsigned int		: 26,
100 		loop_checked	: 1,
101 		mbox_wanted	: 1,
102 		mbox_locked	: 1,
103 		no_mbox_ints	: 1,
104 		paused		: 1,
105 		blocked		: 1;
106 	union {
107 		u_int64_t	_wwn;
108 		u_int16_t	_discovered[2];
109 #define	wwn_seed	un._wwn
110 #define	discovered	un._discovered
111 	} un;
112 	u_int32_t threadwork;
113 	struct proc *thread;
114 };
115 #define	ISP_MUSTPOLL(isp)	\
116 	(isp->isp_osinfo.onintstack || isp->isp_osinfo.no_mbox_ints)
117 
118 #define	HANDLE_LOOPSTATE_IN_OUTER_LAYERS	1
119 
120 /*
121  * Required Macros/Defines
122  */
123 
124 #define	INLINE			__inline
125 
126 #define	ISP2100_SCRLEN		0x400
127 
128 #define	MEMZERO(dst, amt)	memset((dst), 0, (amt))
129 #define	MEMCPY(dst, src, amt)	memcpy((dst), (src), (amt))
130 #define	SNPRINTF		snprintf
131 #define	STRNCAT			strncat
132 #define	USEC_DELAY		DELAY
133 #define	USEC_SLEEP(isp, x)		\
134 	if (!ISP_MUSTPOLL(isp))		\
135 		ISP_UNLOCK(isp);	\
136 	DELAY(x);			\
137 	if (!ISP_MUSTPOLL(isp))		\
138 		ISP_LOCK(isp)
139 
140 #define	NANOTIME_T		struct timeval
141 #define	GET_NANOTIME		microtime
142 #define	GET_NANOSEC(x)		(((x)->tv_sec * 1000000 + (x)->tv_usec) * 1000)
143 #define	NANOTIME_SUB		isp_microtime_sub
144 
145 #define	MAXISPREQUEST(isp)	256
146 
147 #ifdef	__alpha__
148 #define	MEMORYBARRIER(isp, type, offset, size)	alpha_mb()
149 #else
150 #define	MEMORYBARRIER(isp, type, offset, size)
151 #endif
152 
153 #define	MBOX_ACQUIRE(isp)						\
154 	if (isp->isp_osinfo.onintstack) {				\
155 		if (isp->isp_osinfo.mbox_locked) {			\
156 			mbp->param[0] = MBOX_HOST_INTERFACE_ERROR;	\
157 			isp_prt(isp, ISP_LOGERR, "cannot acquire MBOX lock"); \
158 			return;						\
159 		}							\
160 	} else {							\
161 		while (isp->isp_osinfo.mbox_locked) {			\
162 			isp->isp_osinfo.mbox_wanted = 1;		\
163 			(void) tsleep(&isp->isp_osinfo.mboxwaiting+1,	\
164 			    PRIBIO, "mbox_acquire", 0);			\
165 		}							\
166 	}								\
167 	isp->isp_osinfo.mbox_locked = 1
168 
169 #define	MBOX_WAIT_COMPLETE	isp_wait_complete
170 
171 #define	MBOX_NOTIFY_COMPLETE(isp)					\
172 	if (isp->isp_osinfo.mboxwaiting) {				\
173                 isp->isp_osinfo.mboxwaiting = 0;			\
174                 wakeup(&isp->isp_osinfo.mboxwaiting);			\
175         }								\
176 	isp->isp_mboxbsy = 0
177 
178 #define	MBOX_RELEASE(isp)						\
179 	if (isp->isp_osinfo.mbox_wanted) {				\
180 		isp->isp_osinfo.mbox_wanted = 0;			\
181 		wakeup(&isp->isp_osinfo.mboxwaiting+1);			\
182 	}								\
183 	isp->isp_osinfo.mbox_locked = 0
184 
185 #ifndef	SCSI_GOOD
186 #define	SCSI_GOOD	0x0
187 #endif
188 #ifndef	SCSI_CHECK
189 #define	SCSI_CHECK	0x2
190 #endif
191 #ifndef	SCSI_BUSY
192 #define	SCSI_BUSY	0x8
193 #endif
194 #ifndef	SCSI_QFULL
195 #define	SCSI_QFULL	0x28
196 #endif
197 
198 #define	XS_T			struct scsipi_xfer
199 #define	XS_CHANNEL(xs)		((int) (xs)->xs_periph->periph_channel->chan_channel)
200 #define	XS_ISP(xs)		\
201 	((void *)(xs)->xs_periph->periph_channel->chan_adapter->adapt_dev)
202 #define	XS_LUN(xs)		((int) (xs)->xs_periph->periph_lun)
203 #define	XS_TGT(xs)		((int) (xs)->xs_periph->periph_target)
204 #define	XS_CDBP(xs)		((caddr_t) (xs)->cmd)
205 #define	XS_CDBLEN(xs)		(xs)->cmdlen
206 #define	XS_XFRLEN(xs)		(xs)->datalen
207 #define	XS_TIME(xs)		(xs)->timeout
208 #define	XS_RESID(xs)		(xs)->resid
209 #define	XS_STSP(xs)		(&(xs)->status)
210 #define	XS_SNSP(xs)		(&(xs)->sense.scsi_sense)
211 #define	XS_SNSLEN(xs)		(sizeof (xs)->sense)
212 #define	XS_SNSKEY(xs)		((xs)->sense.scsi_sense.flags)
213 #define	XS_TAG_P(ccb)		(((xs)->xs_control & XS_CTL_POLL) != 0)
214 #define	XS_TAG_TYPE(xs)	\
215 	(((xs)->xs_control & XS_CTL_URGENT) ? REQFLAG_HTAG : \
216 	((xs)->bp && xs->bp->b_flags & B_ASYNC) ? REQFLAG_STAG : REQFLAG_OTAG)
217 
218 #define	XS_SETERR(xs, v)	(xs)->error = v
219 
220 #	define	HBA_NOERROR		XS_NOERROR
221 #	define	HBA_BOTCH		XS_DRIVER_STUFFUP
222 #	define	HBA_CMDTIMEOUT		XS_TIMEOUT
223 #	define	HBA_SELTIMEOUT		XS_SELTIMEOUT
224 #	define	HBA_TGTBSY		XS_BUSY
225 #	define	HBA_BUSRESET		XS_RESET
226 #	define	HBA_ABORTED		XS_DRIVER_STUFFUP
227 #	define	HBA_DATAOVR		XS_DRIVER_STUFFUP
228 #	define	HBA_ARQFAIL		XS_DRIVER_STUFFUP
229 
230 #define	XS_ERR(xs)		(xs)->error
231 
232 #define	XS_NOERR(xs)		(xs)->error == XS_NOERROR
233 
234 #define	XS_INITERR(xs)		(xs)->error = 0, XS_CMD_S_CLEAR(xs)
235 
236 #define	XS_SAVE_SENSE(xs, sp)				\
237 	if (xs->error == XS_NOERROR) {			\
238 		xs->error = XS_SENSE;			\
239 	}						\
240 	memcpy(&(xs)->sense, sp->req_sense_data,	\
241 	    imin(XS_SNSLEN(xs), sp->req_sense_len))
242 
243 #define	XS_SET_STATE_STAT(a, b, c)
244 
245 #define	DEFAULT_IID(x)		7
246 #define	DEFAULT_LOOPID(x)	108
247 #define	DEFAULT_NODEWWN(isp)	(isp)->isp_osinfo.un._wwn
248 #define	DEFAULT_PORTWWN(isp)	(isp)->isp_osinfo.un._wwn
249 #define	ISP_NODEWWN(isp)	FCPARAM(isp)->isp_nodewwn
250 #define	ISP_PORTWWN(isp)	FCPARAM(isp)->isp_portwwn
251 
252 #if	_BYTE_ORDER == _BIG_ENDIAN
253 #define	ISP_SWIZZLE_REQUEST		isp_swizzle_request
254 #define	ISP_UNSWIZZLE_RESPONSE		isp_unswizzle_response
255 #define	ISP_SWIZZLE_ICB			isp_swizzle_icb
256 #define	ISP_UNSWIZZLE_AND_COPY_PDBP	isp_unswizzle_and_copy_pdbp
257 #define	ISP_SWIZZLE_SNS_REQ		isp_swizzle_sns_req
258 #define	ISP_UNSWIZZLE_SNS_RSP		isp_unswizzle_sns_rsp
259 #define	ISP_SWIZZLE_NVRAM_WORD(isp, rp)	*rp = bswap16(*rp)
260 #else
261 #define	ISP_SWIZZLE_REQUEST(a, b)
262 #define	ISP_UNSWIZZLE_RESPONSE(a, b, c)
263 #define	ISP_SWIZZLE_ICB(a, b)
264 #define	ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src)	\
265 	if((void *)src != (void *)dest) memcpy(dest, src, sizeof (isp_pdb_t))
266 #define	ISP_SWIZZLE_SNS_REQ(a, b)
267 #define	ISP_UNSWIZZLE_SNS_RSP(a, b, c)
268 #define	ISP_SWIZZLE_NVRAM_WORD(isp, rp)
269 #endif
270 
271 /*
272  * Includes of common header files
273  */
274 
275 #include <dev/ic/ispreg.h>
276 #include <dev/ic/ispvar.h>
277 #include <dev/ic/ispmbox.h>
278 #include <dev/ic/isp_ioctl.h>
279 
280 /*
281  * isp_osinfo definitions, extensions and shorthand.
282  */
283 #define	isp_name	isp_osinfo._dev.dv_xname
284 #define	isp_unit	isp_osinfo._dev.dv_unit
285 #define	isp_chanA	isp_osinfo._chan
286 #define	isp_chanB	isp_osinfo._chan_b
287 
288 
289 /*
290  * Driver prototypes..
291  */
292 void isp_attach(struct ispsoftc *);
293 void isp_uninit(struct ispsoftc *);
294 
295 static INLINE void isp_lock(struct ispsoftc *);
296 static INLINE void isp_unlock(struct ispsoftc *);
297 static INLINE char *strncat(char *, const char *, size_t);
298 static INLINE u_int64_t
299 isp_microtime_sub(struct timeval *, struct timeval *);
300 static void isp_wait_complete(struct ispsoftc *);
301 #if	_BYTE_ORDER == _BIG_ENDIAN
302 static INLINE void isp_swizzle_request(struct ispsoftc *, ispreq_t *);
303 static INLINE void isp_unswizzle_response(struct ispsoftc *, void *, u_int16_t);
304 static INLINE void isp_swizzle_icb(struct ispsoftc *, isp_icb_t *);
305 static INLINE void
306 isp_unswizzle_and_copy_pdbp(struct ispsoftc *, isp_pdb_t *, void *);
307 static INLINE void isp_swizzle_sns_req(struct ispsoftc *, sns_screq_t *);
308 static INLINE void isp_unswizzle_sns_rsp(struct ispsoftc *, sns_scrsp_t *, int);
309 #endif
310 
311 /*
312  * Driver wide data...
313  */
314 
315 /*
316  * Locking macros...
317  */
318 #define	ISP_LOCK		isp_lock
319 #define	ISP_UNLOCK		isp_unlock
320 #define	ISP_ILOCK(x)		isp_lock(x); isp->isp_osinfo.onintstack++
321 #define	ISP_IUNLOCK(x)		isp->isp_osinfo.onintstack--; isp_unlock(x)
322 
323 /*
324  * Platform private flags
325  */
326 
327 #define	XS_PSTS_INWDOG		0x10000000
328 #define	XS_PSTS_GRACE		0x20000000
329 #define	XS_PSTS_ALL		0x30000000
330 
331 #define	XS_CMD_S_WDOG(xs)	(xs)->xs_status |= XS_PSTS_INWDOG
332 #define	XS_CMD_C_WDOG(xs)	(xs)->xs_status &= ~XS_PSTS_INWDOG
333 #define	XS_CMD_WDOG_P(xs)	(((xs)->xs_status & XS_PSTS_INWDOG) != 0)
334 
335 #define	XS_CMD_S_GRACE(xs)	(xs)->xs_status |= XS_PSTS_GRACE
336 #define	XS_CMD_C_GRACE(xs)	(xs)->xs_status &= ~XS_PSTS_GRACE
337 #define	XS_CMD_GRACE_P(xs)	(((xs)->xs_status & XS_PSTS_GRACE) != 0)
338 
339 #define	XS_CMD_S_DONE(xs)	(xs)->xs_status |= XS_STS_DONE
340 #define	XS_CMD_C_DONE(xs)	(xs)->xs_status &= ~XS_STS_DONE
341 #define	XS_CMD_DONE_P(xs)	(((xs)->xs_status & XS_STS_DONE) != 0)
342 
343 #define	XS_CMD_S_CLEAR(xs)	(xs)->xs_status &= ~XS_PSTS_ALL
344 
345 /*
346  * Platform specific 'inline' or support functions
347  */
348 static INLINE void
349 isp_lock(struct ispsoftc *isp)
350 {
351 	int s = splbio();
352 	if (isp->isp_osinfo.islocked++ == 0) {
353 		isp->isp_osinfo.splsaved = s;
354 	} else {
355 		splx(s);
356 	}
357 }
358 
359 static INLINE void
360 isp_unlock(struct ispsoftc *isp)
361 {
362 	if (isp->isp_osinfo.islocked-- <= 1) {
363 		isp->isp_osinfo.islocked = 0;
364 		splx(isp->isp_osinfo.splsaved);
365 	}
366 }
367 
368 static INLINE char *
369 strncat(char *d, const char *s, size_t c)
370 {
371         char *t = d;
372 
373         if (c) {
374                 while (*d)
375                         d++;
376                 while ((*d++ = *s++)) {
377                         if (--c == 0) {
378                                 *d = '\0';
379                                 break;
380                         }
381                 }
382         }
383         return (t);
384 }
385 
386 static INLINE u_int64_t
387 isp_microtime_sub(struct timeval *b, struct timeval *a)
388 {
389 	struct timeval x;
390 	u_int64_t elapsed;
391 	timersub(b, a, &x);
392 	elapsed = GET_NANOSEC(&x);
393 	if (elapsed == 0)
394 		elapsed++;
395 	return (elapsed);
396 }
397 
398 static INLINE void
399 isp_wait_complete(struct ispsoftc *isp)
400 {
401 	if (isp->isp_osinfo.onintstack || isp->isp_osinfo.no_mbox_ints) {
402 		int usecs = 0;
403 		/*
404 		 * For sanity's sake, we don't delay longer
405 		 * than 5 seconds for polled commands.
406 		 */
407 		while (usecs < 5 * 1000000) {
408 			(void) isp_intr(isp);
409 			if (isp->isp_mboxbsy == 0) {
410 				break;
411 			}
412 			USEC_DELAY(500);
413 			usecs += 500;
414 		}
415 		if (isp->isp_mboxbsy != 0) {
416 			isp_prt(isp, ISP_LOGWARN,
417 			    "Polled Mailbox Command (0x%x) Timeout",
418 			    isp->isp_lastmbxcmd);
419 		}
420 	} else {
421 		int rv = 0;
422                 isp->isp_osinfo.mboxwaiting = 1;
423                 while (isp->isp_osinfo.mboxwaiting && rv == 0) {
424 			static const struct timeval dtime = { 5, 0 };
425 			int timo;
426 			struct timeval tv;
427 			microtime(&tv);
428 			timeradd(&tv, &dtime, &tv);
429 			if ((timo = hzto(&tv)) == 0) {
430 				timo = 1;
431 			}
432 			rv = tsleep(&isp->isp_osinfo.mboxwaiting,
433 			    PRIBIO, "isp_mboxcmd", timo);
434 		}
435 		if (rv == EWOULDBLOCK) {
436 			isp->isp_mboxbsy = 0;
437 			isp->isp_osinfo.mboxwaiting = 0;
438 			isp_prt(isp, ISP_LOGWARN,
439 			    "Interrupting Mailbox Command (0x%x) Timeout",
440 			    isp->isp_lastmbxcmd);
441 		}
442 	}
443 }
444 
445 #if	_BYTE_ORDER == _BIG_ENDIAN
446 static INLINE void
447 isp_swizzle_request(struct ispsoftc *isp, ispreq_t *rq)
448 {
449 	if (IS_FC(isp)) {
450 		ispreqt2_t *tq = (ispreqt2_t *) rq;
451 		tq->req_handle = bswap32(tq->req_handle);
452 		tq->req_scclun = bswap16(tq->req_scclun);
453 		tq->req_flags = bswap16(tq->req_flags);
454 		tq->req_time = bswap16(tq->req_time);
455 		tq->req_totalcnt = bswap32(tq->req_totalcnt);
456 	} else if (isp->isp_bustype == ISP_BT_SBUS) {
457 		_ISP_SWAP8(rq->req_header.rqs_entry_count,
458 		    rq->req_header.rqs_entry_type);
459 		_ISP_SWAP8(rq->req_header.rqs_flags, rq->req_header.rqs_seqno);
460 		_ISP_SWAP8(rq->req_target, rq->req_lun_trn);
461 	} else {
462 		rq->req_handle = bswap32(rq->req_handle);
463 		rq->req_cdblen = bswap16(rq->req_cdblen);
464 		rq->req_flags = bswap16(rq->req_flags);
465 		rq->req_time = bswap16(rq->req_time);
466 	}
467 }
468 
469 static INLINE void
470 isp_unswizzle_response(struct ispsoftc *isp, void *rp, u_int16_t optr)
471 {
472 	ispstatusreq_t *sp = rp;
473 	MEMORYBARRIER(isp, SYNC_RESPONSE, optr * QENTRY_LEN, QENTRY_LEN);
474 	if (isp->isp_bustype == ISP_BT_SBUS) {
475 		_ISP_SWAP8(sp->req_header.rqs_entry_count,
476 		    sp->req_header.rqs_entry_type);
477 		_ISP_SWAP8(sp->req_header.rqs_flags, sp->req_header.rqs_seqno);
478 	} else switch (sp->req_header.rqs_entry_type) {
479 	case RQSTYPE_RESPONSE:
480 		sp->req_handle = bswap32(sp->req_handle);
481 		sp->req_scsi_status = bswap16(sp->req_scsi_status);
482 		sp->req_completion_status = bswap16(sp->req_completion_status);
483 		sp->req_state_flags = bswap16(sp->req_state_flags);
484 		sp->req_status_flags = bswap16(sp->req_status_flags);
485 		sp->req_time = bswap16(sp->req_time);
486 		sp->req_sense_len = bswap16(sp->req_sense_len);
487 		sp->req_resid = bswap32(sp->req_resid);
488 		break;
489 	default:
490 		break;
491 	}
492 }
493 
494 static INLINE void
495 isp_swizzle_icb(struct ispsoftc *isp, isp_icb_t *icbp)
496 {
497 	_ISP_SWAP8(icbp->icb_version, icbp->_reserved0);
498 	_ISP_SWAP8(icbp->icb_retry_count, icbp->icb_retry_delay);
499 	_ISP_SWAP8(icbp->icb_iqdevtype, icbp->icb_logintime);
500 	_ISP_SWAP8(icbp->icb_ccnt, icbp->icb_icnt);
501 	_ISP_SWAP8(icbp->icb_racctimer, icbp->icb_idelaytimer);
502 	icbp->icb_fwoptions = bswap16(icbp->icb_fwoptions);
503 	icbp->icb_maxfrmlen = bswap16(icbp->icb_maxfrmlen);
504 	icbp->icb_maxalloc = bswap16(icbp->icb_maxalloc);
505 	icbp->icb_execthrottle = bswap16(icbp->icb_execthrottle);
506 	icbp->icb_hardaddr = bswap16(icbp->icb_hardaddr);
507 	icbp->icb_rqstout = bswap16(icbp->icb_rqstout);
508 	icbp->icb_rspnsin = bswap16(icbp->icb_rspnsin);
509 	icbp->icb_rqstqlen = bswap16(icbp->icb_rqstqlen);
510 	icbp->icb_rsltqlen = bswap16(icbp->icb_rsltqlen);
511 	icbp->icb_lunenables = bswap16(icbp->icb_lunenables);
512 	icbp->icb_lunetimeout = bswap16(icbp->icb_lunetimeout);
513 	icbp->icb_xfwoptions = bswap16(icbp->icb_xfwoptions);
514 	icbp->icb_zfwoptions = bswap16(icbp->icb_zfwoptions);
515 	icbp->icb_rqstaddr[0] = bswap16(icbp->icb_rqstaddr[0]);
516 	icbp->icb_rqstaddr[1] = bswap16(icbp->icb_rqstaddr[1]);
517 	icbp->icb_rqstaddr[2] = bswap16(icbp->icb_rqstaddr[2]);
518 	icbp->icb_rqstaddr[3] = bswap16(icbp->icb_rqstaddr[3]);
519 	icbp->icb_respaddr[0] = bswap16(icbp->icb_respaddr[0]);
520 	icbp->icb_respaddr[1] = bswap16(icbp->icb_respaddr[1]);
521 	icbp->icb_respaddr[2] = bswap16(icbp->icb_respaddr[2]);
522 	icbp->icb_respaddr[3] = bswap16(icbp->icb_respaddr[3]);
523 }
524 
525 static INLINE void
526 isp_unswizzle_and_copy_pdbp(struct ispsoftc *isp, isp_pdb_t *dst, void *src)
527 {
528 	isp_pdb_t *pdbp = src;
529 	dst->pdb_options = bswap16(pdbp->pdb_options);
530 	dst->pdb_mstate = pdbp->pdb_sstate;
531 	dst->pdb_sstate = pdbp->pdb_mstate;
532 	dst->pdb_hardaddr_bits[0] = pdbp->pdb_hardaddr_bits[0];
533 	dst->pdb_hardaddr_bits[1] = pdbp->pdb_hardaddr_bits[1];
534 	dst->pdb_hardaddr_bits[2] = pdbp->pdb_hardaddr_bits[2];
535 	dst->pdb_hardaddr_bits[3] = pdbp->pdb_hardaddr_bits[3];
536 	dst->pdb_portid_bits[0] = pdbp->pdb_portid_bits[0];
537 	dst->pdb_portid_bits[1] = pdbp->pdb_portid_bits[1];
538 	dst->pdb_portid_bits[2] = pdbp->pdb_portid_bits[2];
539 	dst->pdb_portid_bits[3] = pdbp->pdb_portid_bits[3];
540 	dst->pdb_nodename[0] = pdbp->pdb_nodename[0];
541 	dst->pdb_nodename[1] = pdbp->pdb_nodename[1];
542 	dst->pdb_nodename[2] = pdbp->pdb_nodename[2];
543 	dst->pdb_nodename[3] = pdbp->pdb_nodename[3];
544 	dst->pdb_nodename[4] = pdbp->pdb_nodename[4];
545 	dst->pdb_nodename[5] = pdbp->pdb_nodename[5];
546 	dst->pdb_nodename[6] = pdbp->pdb_nodename[6];
547 	dst->pdb_nodename[7] = pdbp->pdb_nodename[7];
548 	dst->pdb_portname[0] = pdbp->pdb_portname[0];
549 	dst->pdb_portname[1] = pdbp->pdb_portname[1];
550 	dst->pdb_portname[2] = pdbp->pdb_portname[2];
551 	dst->pdb_portname[3] = pdbp->pdb_portname[3];
552 	dst->pdb_portname[4] = pdbp->pdb_portname[4];
553 	dst->pdb_portname[5] = pdbp->pdb_portname[5];
554 	dst->pdb_portname[6] = pdbp->pdb_portname[6];
555 	dst->pdb_portname[7] = pdbp->pdb_portname[7];
556 	dst->pdb_execthrottle = bswap16(pdbp->pdb_execthrottle);
557 	dst->pdb_exec_count = bswap16(pdbp->pdb_exec_count);
558 	dst->pdb_resalloc = bswap16(pdbp->pdb_resalloc);
559 	dst->pdb_curalloc = bswap16(pdbp->pdb_curalloc);
560 	dst->pdb_qhead = bswap16(pdbp->pdb_qhead);
561 	dst->pdb_qtail = bswap16(pdbp->pdb_qtail);
562 	dst->pdb_tl_next = bswap16(pdbp->pdb_tl_next);
563 	dst->pdb_tl_last = bswap16(pdbp->pdb_tl_last);
564 	dst->pdb_features = bswap16(pdbp->pdb_features);
565 	dst->pdb_pconcurrnt = bswap16(pdbp->pdb_pconcurrnt);
566 	dst->pdb_roi = bswap16(pdbp->pdb_roi);
567 	dst->pdb_rdsiz = bswap16(pdbp->pdb_rdsiz);
568 	dst->pdb_ncseq = bswap16(pdbp->pdb_ncseq);
569 	dst->pdb_noseq = bswap16(pdbp->pdb_noseq);
570 	dst->pdb_labrtflg = bswap16(pdbp->pdb_labrtflg);
571 	dst->pdb_lstopflg = bswap16(pdbp->pdb_lstopflg);
572 	dst->pdb_sqhead = bswap16(pdbp->pdb_sqhead);
573 	dst->pdb_sqtail = bswap16(pdbp->pdb_sqtail);
574 	dst->pdb_ptimer = bswap16(pdbp->pdb_ptimer);
575 	dst->pdb_nxt_seqid = bswap16(pdbp->pdb_nxt_seqid);
576 	dst->pdb_fcount = bswap16(pdbp->pdb_fcount);
577 	dst->pdb_prli_len = bswap16(pdbp->pdb_prli_len);
578 	dst->pdb_prli_svc0 = bswap16(pdbp->pdb_prli_svc0);
579 	dst->pdb_prli_svc3 = bswap16(pdbp->pdb_prli_svc3);
580 	dst->pdb_loopid = bswap16(pdbp->pdb_loopid);
581 	dst->pdb_il_ptr = bswap16(pdbp->pdb_il_ptr);
582 	dst->pdb_sl_ptr = bswap16(pdbp->pdb_sl_ptr);
583 	dst->pdb_retry_count = pdbp->pdb_retry_delay;
584 	dst->pdb_retry_delay = pdbp->pdb_retry_count;
585 	dst->pdb_target = pdbp->pdb_initiator;
586 	dst->pdb_initiator = pdbp->pdb_target;
587 }
588 
589 static INLINE void
590 isp_swizzle_sns_req(struct ispsoftc *isp, sns_screq_t *reqp)
591 {
592 	u_int16_t index, nwords = reqp->snscb_sblen;
593 	reqp->snscb_rblen = bswap16(reqp->snscb_rblen);
594 	reqp->snscb_addr[0] = bswap16(reqp->snscb_addr[0]);
595 	reqp->snscb_addr[1] = bswap16(reqp->snscb_addr[1]);
596 	reqp->snscb_addr[2] = bswap16(reqp->snscb_addr[2]);
597 	reqp->snscb_addr[3] = bswap16(reqp->snscb_addr[3]);
598 	reqp->snscb_sblen = bswap16(reqp->snscb_sblen);
599 	for (index = 0; index < nwords; index++) {
600 		reqp->snscb_data[index] = bswap16(reqp->snscb_data[index]);
601 	}
602 }
603 
604 static INLINE void
605 isp_unswizzle_sns_rsp(struct ispsoftc *isp, sns_scrsp_t *resp, int nwords)
606 {
607 	int index;
608 	/*
609 	 * Don't even think about asking. This. Is. So. Lame.
610 	 */
611 	if (IS_2200(isp) &&
612 	    ISP_FW_REVX(isp->isp_fwrev) == ISP_FW_REV(2, 1, 26)) {
613 		nwords = 128;
614 	}
615 	for (index = 0; index < nwords; index++) {
616 		resp->snscb_data[index] = bswap16(resp->snscb_data[index]);
617 	}
618 }
619 #endif
620 
621 /*
622  * Common inline functions
623  */
624 #include <dev/ic/isp_inline.h>
625 
626 #if	!defined(ISP_DISABLE_FW) && !defined(ISP_COMPILE_FW)
627 #define	ISP_COMPILE_FW	1
628 #endif
629 #endif	/* _ISP_NETBSD_H */
630