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