Home | History | Annotate | Line # | Download | only in ic
isp_netbsd.h revision 1.18.2.6
      1  1.18.2.6  bouyer /* $NetBSD: isp_netbsd.h,v 1.18.2.6 2000/11/20 11:40:39 bouyer Exp $ */
      2  1.18.2.6  bouyer /*
      3  1.18.2.6  bouyer  * This driver, which is contained in NetBSD in the files:
      4  1.18.2.6  bouyer  *
      5  1.18.2.6  bouyer  *	sys/dev/ic/isp.c
      6  1.18.2.6  bouyer  *	sys/dev/ic/ic/isp.c
      7  1.18.2.6  bouyer  *	sys/dev/ic/ic/isp_inline.h
      8  1.18.2.6  bouyer  *	sys/dev/ic/ic/isp_netbsd.c
      9  1.18.2.6  bouyer  *	sys/dev/ic/ic/isp_netbsd.h
     10  1.18.2.6  bouyer  *	sys/dev/ic/ic/isp_target.c
     11  1.18.2.6  bouyer  *	sys/dev/ic/ic/isp_target.h
     12  1.18.2.6  bouyer  *	sys/dev/ic/ic/isp_tpublic.h
     13  1.18.2.6  bouyer  *	sys/dev/ic/ic/ispmbox.h
     14  1.18.2.6  bouyer  *	sys/dev/ic/ic/ispreg.h
     15  1.18.2.6  bouyer  *	sys/dev/ic/ic/ispvar.h
     16  1.18.2.6  bouyer  *	sys/microcode/isp/asm_sbus.h
     17  1.18.2.6  bouyer  *	sys/microcode/isp/asm_1040.h
     18  1.18.2.6  bouyer  *	sys/microcode/isp/asm_1080.h
     19  1.18.2.6  bouyer  *	sys/microcode/isp/asm_12160.h
     20  1.18.2.6  bouyer  *	sys/microcode/isp/asm_2100.h
     21  1.18.2.6  bouyer  *	sys/microcode/isp/asm_2200.h
     22  1.18.2.6  bouyer  *	sys/pci/isp_pci.c
     23  1.18.2.6  bouyer  *	sys/sbus/isp_sbus.c
     24  1.18.2.6  bouyer  *
     25  1.18.2.6  bouyer  * Is being actively maintained by Matthew Jacob (mjacob (at) netbsd.org).
     26  1.18.2.6  bouyer  * This driver also is shared source with FreeBSD, OpenBSD, Linux, Solaris,
     27  1.18.2.6  bouyer  * Linux versions. This tends to be an interesting maintenance problem.
     28  1.18.2.6  bouyer  *
     29  1.18.2.6  bouyer  * Please coordinate with Matthew Jacob on changes you wish to make here.
     30  1.18.2.6  bouyer  */
     31       1.1  mjacob /*
     32       1.1  mjacob  * NetBSD Specific definitions for the Qlogic ISP Host Adapter
     33      1.15  mjacob  * Matthew Jacob <mjacob (at) nas.nasa.gov>
     34      1.15  mjacob  */
     35      1.15  mjacob /*
     36      1.15  mjacob  * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
     37       1.1  mjacob  * All rights reserved.
     38       1.1  mjacob  *
     39       1.1  mjacob  * Redistribution and use in source and binary forms, with or without
     40       1.1  mjacob  * modification, are permitted provided that the following conditions
     41       1.1  mjacob  * are met:
     42       1.1  mjacob  * 1. Redistributions of source code must retain the above copyright
     43      1.15  mjacob  *    notice, this list of conditions and the following disclaimer.
     44       1.1  mjacob  * 2. Redistributions in binary form must reproduce the above copyright
     45       1.1  mjacob  *    notice, this list of conditions and the following disclaimer in the
     46       1.1  mjacob  *    documentation and/or other materials provided with the distribution.
     47       1.1  mjacob  * 3. The name of the author may not be used to endorse or promote products
     48      1.15  mjacob  *    derived from this software without specific prior written permission
     49       1.1  mjacob  *
     50      1.15  mjacob  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     51      1.15  mjacob  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     52      1.15  mjacob  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     53      1.15  mjacob  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     54      1.15  mjacob  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     55      1.15  mjacob  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     56      1.15  mjacob  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     57      1.15  mjacob  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     58      1.15  mjacob  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     59      1.15  mjacob  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     60       1.1  mjacob  */
     61       1.1  mjacob #ifndef	_ISP_NETBSD_H
     62       1.1  mjacob #define	_ISP_NETBSD_H
     63       1.1  mjacob 
     64       1.1  mjacob #include <sys/types.h>
     65       1.1  mjacob #include <sys/param.h>
     66       1.1  mjacob #include <sys/systm.h>
     67       1.1  mjacob #include <sys/kernel.h>
     68       1.1  mjacob #include <sys/errno.h>
     69       1.1  mjacob #include <sys/ioctl.h>
     70       1.1  mjacob #include <sys/device.h>
     71       1.1  mjacob #include <sys/malloc.h>
     72       1.1  mjacob #include <sys/buf.h>
     73       1.1  mjacob #include <sys/proc.h>
     74       1.1  mjacob #include <sys/user.h>
     75       1.1  mjacob 
     76       1.1  mjacob 
     77       1.1  mjacob #include <dev/scsipi/scsi_all.h>
     78       1.1  mjacob #include <dev/scsipi/scsipi_all.h>
     79       1.1  mjacob #include <dev/scsipi/scsiconf.h>
     80       1.1  mjacob 
     81       1.1  mjacob #include <dev/scsipi/scsi_message.h>
     82       1.1  mjacob #include <dev/scsipi/scsipi_debug.h>
     83       1.1  mjacob 
     84      1.15  mjacob #include "opt_isp.h"
     85      1.15  mjacob 
     86       1.1  mjacob 
     87  1.18.2.6  bouyer #define	ISP_PLATFORM_VERSION_MAJOR	1
     88  1.18.2.6  bouyer #define	ISP_PLATFORM_VERSION_MINOR	0
     89  1.18.2.6  bouyer 
     90       1.1  mjacob struct isposinfo {
     91       1.1  mjacob 	struct device		_dev;
     92  1.18.2.6  bouyer 	struct scsipi_link	_link;
     93  1.18.2.6  bouyer 	struct scsipi_link	_link_b;
     94       1.6  mjacob 	struct scsipi_adapter   _adapter;
     95  1.18.2.6  bouyer 	int	splsaved;
     96  1.18.2.6  bouyer 	int	mboxwaiting;
     97  1.18.2.6  bouyer 	u_int32_t	islocked;
     98  1.18.2.6  bouyer 	u_int32_t	onintstack;
     99  1.18.2.6  bouyer 	unsigned int		: 30,
    100  1.18.2.6  bouyer 		no_mbox_ints	: 1,
    101  1.18.2.6  bouyer 		blocked		: 1;
    102  1.18.2.6  bouyer 	union {
    103  1.18.2.6  bouyer 		u_int64_t	_wwn;
    104  1.18.2.6  bouyer 		u_int16_t	_discovered[2];
    105  1.18.2.6  bouyer #define	wwn_seed	un._wwn
    106  1.18.2.6  bouyer #define	discovered	un._discovered
    107  1.18.2.6  bouyer 	} un;
    108  1.18.2.6  bouyer 	TAILQ_HEAD(, scsipi_xfer) waitq;
    109  1.18.2.6  bouyer 	struct callout _restart;
    110       1.1  mjacob };
    111      1.18  mjacob 
    112  1.18.2.6  bouyer /*
    113  1.18.2.6  bouyer  * Required Macros/Defines
    114  1.18.2.6  bouyer  */
    115       1.1  mjacob 
    116  1.18.2.6  bouyer #define	INLINE			inline
    117       1.1  mjacob 
    118  1.18.2.6  bouyer #define	ISP2100_FABRIC		1
    119  1.18.2.6  bouyer #define	ISP2100_SCRLEN		0x400
    120       1.8  mjacob 
    121       1.8  mjacob #define	MEMZERO			bzero
    122  1.18.2.6  bouyer #define	MEMCPY(dst, src, amt)	bcopy((src), (dst), (amt))
    123  1.18.2.6  bouyer #define	SNPRINTF		snprintf
    124  1.18.2.6  bouyer #define	STRNCAT			strncat
    125  1.18.2.6  bouyer #define	USEC_DELAY		DELAY
    126  1.18.2.6  bouyer 
    127  1.18.2.6  bouyer #define	NANOTIME_T		struct timeval
    128  1.18.2.6  bouyer #define	GET_NANOTIME		microtime
    129  1.18.2.6  bouyer #define	GET_NANOSEC(x)		(((x)->tv_sec * 1000000 + (x)->tv_usec) * 1000)
    130  1.18.2.6  bouyer #define	NANOTIME_SUB		isp_microtime_sub
    131  1.18.2.6  bouyer 
    132  1.18.2.6  bouyer #define	MAXISPREQUEST(isp)	256
    133  1.18.2.6  bouyer 
    134      1.11  mjacob #ifdef	__alpha__
    135  1.18.2.6  bouyer #define	MEMORYBARRIER(isp, type, offset, size)	alpha_mb()
    136      1.11  mjacob #else
    137  1.18.2.6  bouyer #define	MEMORYBARRIER(isp, type, offset, size)
    138      1.11  mjacob #endif
    139       1.3  mjacob 
    140  1.18.2.6  bouyer #define	MBOX_ACQUIRE(isp)
    141  1.18.2.6  bouyer #define	MBOX_WAIT_COMPLETE	isp_wait_complete
    142      1.13  mjacob 
    143  1.18.2.6  bouyer #define	MBOX_NOTIFY_COMPLETE(isp)					\
    144  1.18.2.6  bouyer 	if (isp->isp_osinfo.mboxwaiting) {				\
    145  1.18.2.6  bouyer                 isp->isp_osinfo.mboxwaiting = 0;			\
    146  1.18.2.6  bouyer                 wakeup(&isp->isp_osinfo.mboxwaiting);			\
    147  1.18.2.6  bouyer         }								\
    148  1.18.2.6  bouyer 	isp->isp_mboxbsy = 0
    149       1.1  mjacob 
    150  1.18.2.6  bouyer #define	MBOX_RELEASE(isp)
    151       1.1  mjacob 
    152  1.18.2.6  bouyer #ifndef	SCSI_GOOD
    153  1.18.2.6  bouyer #define	SCSI_GOOD	0x0
    154  1.18.2.6  bouyer #endif
    155  1.18.2.6  bouyer #ifndef	SCSI_CHECK
    156  1.18.2.6  bouyer #define	SCSI_CHECK	0x2
    157  1.18.2.6  bouyer #endif
    158  1.18.2.6  bouyer #ifndef	SCSI_BUSY
    159  1.18.2.6  bouyer #define	SCSI_BUSY	0x8
    160  1.18.2.6  bouyer #endif
    161  1.18.2.6  bouyer #ifndef	SCSI_QFULL
    162  1.18.2.6  bouyer #define	SCSI_QFULL	0x28
    163  1.18.2.6  bouyer #endif
    164       1.1  mjacob 
    165  1.18.2.6  bouyer #define	XS_T			struct scsipi_xfer
    166      1.14  mjacob #define	XS_CHANNEL(xs)		\
    167  1.18.2.6  bouyer 	(((int) (xs)->sc_link->scsipi_scsi.channel == SCSI_CHANNEL_ONLY_ONE) ? \
    168  1.18.2.6  bouyer 	    0 : (xs)->sc_link->scsipi_scsi.channel)
    169  1.18.2.6  bouyer #define	XS_ISP(xs)		(xs)->sc_link->adapter_softc
    170  1.18.2.6  bouyer #define	XS_LUN(xs)		((int) (xs)->sc_link->scsipi_scsi.lun)
    171  1.18.2.6  bouyer #define	XS_TGT(xs)		((int) (xs)->sc_link->scsipi_scsi.target)
    172      1.14  mjacob #define	XS_CDBP(xs)		((caddr_t) (xs)->cmd)
    173  1.18.2.6  bouyer #define	XS_CDBLEN(xs)		(xs)->cmdlen
    174  1.18.2.6  bouyer #define	XS_XFRLEN(xs)		(xs)->datalen
    175       1.1  mjacob #define	XS_TIME(xs)		(xs)->timeout
    176  1.18.2.6  bouyer #define	XS_RESID(xs)		(xs)->resid
    177  1.18.2.6  bouyer #define	XS_STSP(xs)		(&(xs)->status)
    178       1.1  mjacob #define	XS_SNSP(xs)		(&(xs)->sense.scsi_sense)
    179  1.18.2.6  bouyer #define	XS_SNSLEN(xs)		(sizeof (xs)->sense)
    180       1.1  mjacob #define	XS_SNSKEY(xs)		((xs)->sense.scsi_sense.flags)
    181  1.18.2.6  bouyer #define	XS_TAG_P(ccb)		(((xs)->xs_control & XS_CTL_POLL) != 0)
    182  1.18.2.6  bouyer #define	XS_TAG_TYPE(xs)	\
    183  1.18.2.6  bouyer 	(((xs)->xs_control & XS_CTL_URGENT) ? REQFLAG_HTAG : \
    184  1.18.2.6  bouyer 	((xs)->bp && xs->bp->b_flags & B_ASYNC) ? REQFLAG_STAG : REQFLAG_OTAG)
    185       1.1  mjacob 
    186  1.18.2.6  bouyer #define	XS_SETERR(xs, v)	(xs)->error = v
    187       1.1  mjacob 
    188  1.18.2.6  bouyer #	define	HBA_NOERROR		XS_NOERROR
    189  1.18.2.6  bouyer #	define	HBA_BOTCH		XS_DRIVER_STUFFUP
    190  1.18.2.6  bouyer #	define	HBA_CMDTIMEOUT		XS_TIMEOUT
    191  1.18.2.6  bouyer #	define	HBA_SELTIMEOUT		XS_SELTIMEOUT
    192  1.18.2.6  bouyer #	define	HBA_TGTBSY		XS_BUSY
    193  1.18.2.6  bouyer #	define	HBA_BUSRESET		XS_RESET
    194  1.18.2.6  bouyer #	define	HBA_ABORTED		XS_DRIVER_STUFFUP
    195  1.18.2.6  bouyer #	define	HBA_DATAOVR		XS_DRIVER_STUFFUP
    196  1.18.2.6  bouyer #	define	HBA_ARQFAIL		XS_DRIVER_STUFFUP
    197       1.1  mjacob 
    198       1.1  mjacob #define	XS_ERR(xs)		(xs)->error
    199  1.18.2.6  bouyer 
    200       1.1  mjacob #define	XS_NOERR(xs)		(xs)->error == XS_NOERROR
    201       1.1  mjacob 
    202  1.18.2.6  bouyer #define	XS_INITERR(xs)		(xs)->error = 0, XS_CMD_S_CLEAR(xs)
    203  1.18.2.6  bouyer 
    204  1.18.2.6  bouyer #define	XS_SAVE_SENSE(xs, sp)				\
    205  1.18.2.6  bouyer 	bcopy(sp->req_sense_data, &(xs)->sense,		\
    206  1.18.2.6  bouyer 	    imin(XS_SNSLEN(xs), sp->req_sense_len))
    207  1.18.2.6  bouyer 
    208  1.18.2.6  bouyer #define	XS_SET_STATE_STAT(a, b, c)
    209  1.18.2.6  bouyer 
    210  1.18.2.6  bouyer #define	DEFAULT_IID(x)		7
    211  1.18.2.6  bouyer #define	DEFAULT_LOOPID(x)	108
    212  1.18.2.6  bouyer #define	DEFAULT_NODEWWN(isp)	(isp)->isp_osinfo.un._wwn
    213  1.18.2.6  bouyer #define	DEFAULT_PORTWWN(isp)	(isp)->isp_osinfo.un._wwn
    214  1.18.2.6  bouyer #define	ISP_NODEWWN(isp)	FCPARAM(isp)->isp_nodewwn
    215  1.18.2.6  bouyer #define	ISP_PORTWWN(isp)	FCPARAM(isp)->isp_portwwn
    216  1.18.2.6  bouyer 
    217  1.18.2.6  bouyer #define	ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src)	\
    218  1.18.2.6  bouyer 	if((void *)src != (void *)dest) bcopy(src, dest, sizeof (isp_pdb_t))
    219  1.18.2.6  bouyer #define	ISP_SWIZZLE_ICB(a, b)
    220  1.18.2.6  bouyer #ifdef	__sparc__
    221  1.18.2.6  bouyer #define ISP_SWIZZLE_REQUEST(a, b)			\
    222  1.18.2.6  bouyer 	ISP_SBUSIFY_ISPHDR(a, &(b)->req_header);	\
    223  1.18.2.6  bouyer         ISP_SBUSIFY_ISPREQ(a, b)
    224  1.18.2.6  bouyer #define ISP_UNSWIZZLE_RESPONSE(a, b, c)			\
    225  1.18.2.6  bouyer 	ISP_SBUSIFY_ISPHDR(a, &(b)->req_header)
    226  1.18.2.6  bouyer #else
    227  1.18.2.6  bouyer #define	ISP_SWIZZLE_REQUEST(a, b)
    228  1.18.2.6  bouyer #define	ISP_UNSWIZZLE_RESPONSE(a, b, c)
    229  1.18.2.6  bouyer #endif
    230  1.18.2.6  bouyer #define	ISP_SWIZZLE_SNS_REQ(a, b)
    231  1.18.2.6  bouyer #define	ISP_UNSWIZZLE_SNS_RSP(a, b, c)
    232  1.18.2.6  bouyer #ifdef	__sparc__
    233  1.18.2.6  bouyer #define	ISP_SWIZZLE_NVRAM_WORD(isp, rp)	\
    234  1.18.2.6  bouyer 	{								\
    235  1.18.2.6  bouyer 		u_int16_t tmp = *rp >> 8;				\
    236  1.18.2.6  bouyer 		tmp |= ((*rp & 0xff) << 8);				\
    237  1.18.2.6  bouyer 		*rp = tmp;						\
    238  1.18.2.6  bouyer 	}
    239  1.18.2.6  bouyer #else
    240  1.18.2.6  bouyer #define	ISP_SWIZZLE_NVRAM_WORD(isp, rp)
    241  1.18.2.6  bouyer #endif
    242       1.1  mjacob 
    243       1.1  mjacob /*
    244  1.18.2.6  bouyer  * Includes of common header files
    245       1.1  mjacob  */
    246  1.18.2.6  bouyer 
    247  1.18.2.6  bouyer #include <dev/ic/ispreg.h>
    248  1.18.2.6  bouyer #include <dev/ic/ispvar.h>
    249  1.18.2.6  bouyer #include <dev/ic/ispmbox.h>
    250       1.1  mjacob 
    251       1.1  mjacob /*
    252  1.18.2.6  bouyer  * isp_osinfo definitions, extensions and shorthand.
    253       1.1  mjacob  */
    254  1.18.2.6  bouyer #define	isp_name	isp_osinfo._dev.dv_xname
    255  1.18.2.6  bouyer #define	isp_unit	isp_osinfo._dev.dv_unit
    256       1.1  mjacob 
    257      1.18  mjacob /*
    258  1.18.2.6  bouyer  * Driver prototypes..
    259      1.18  mjacob  */
    260  1.18.2.6  bouyer void isp_attach __P((struct ispsoftc *));
    261  1.18.2.6  bouyer void isp_uninit __P((struct ispsoftc *));
    262       1.1  mjacob 
    263  1.18.2.6  bouyer static inline void isp_lock __P((struct ispsoftc *));
    264  1.18.2.6  bouyer static inline void isp_unlock __P((struct ispsoftc *));
    265  1.18.2.6  bouyer static inline char *strncat __P((char *, const char *, size_t));
    266  1.18.2.6  bouyer static inline u_int64_t
    267  1.18.2.6  bouyer isp_microtime_sub __P((struct timeval *, struct timeval *));
    268  1.18.2.6  bouyer static void isp_wait_complete __P((struct ispsoftc *));
    269       1.1  mjacob 
    270  1.18.2.6  bouyer /*
    271  1.18.2.6  bouyer  * Driver wide data...
    272  1.18.2.6  bouyer  */
    273      1.14  mjacob 
    274  1.18.2.6  bouyer /*
    275  1.18.2.6  bouyer  * Locking macros...
    276  1.18.2.6  bouyer  */
    277  1.18.2.6  bouyer #define	ISP_LOCK		isp_lock
    278  1.18.2.6  bouyer #define	ISP_UNLOCK		isp_unlock
    279  1.18.2.6  bouyer #define	ISP_ILOCK(x)		isp_lock(x); isp->isp_osinfo.onintstack++
    280  1.18.2.6  bouyer #define	ISP_IUNLOCK(x)		isp->isp_osinfo.onintstack--; isp_unlock(x)
    281       1.1  mjacob 
    282  1.18.2.6  bouyer /*
    283  1.18.2.6  bouyer  * Platform private flags
    284  1.18.2.6  bouyer  */
    285       1.1  mjacob 
    286  1.18.2.6  bouyer #define	XS_PSTS_INWDOG		0x10000000
    287  1.18.2.6  bouyer #define	XS_PSTS_GRACE		0x20000000
    288  1.18.2.6  bouyer #define	XS_PSTS_ALL		0x30000000
    289  1.18.2.6  bouyer 
    290  1.18.2.6  bouyer #define	XS_CMD_S_WDOG(xs)	(xs)->xs_status |= XS_PSTS_INWDOG
    291  1.18.2.6  bouyer #define	XS_CMD_C_WDOG(xs)	(xs)->xs_status &= ~XS_PSTS_INWDOG
    292  1.18.2.6  bouyer #define	XS_CMD_WDOG_P(xs)	(((xs)->xs_status & XS_PSTS_INWDOG) != 0)
    293  1.18.2.6  bouyer 
    294  1.18.2.6  bouyer #define	XS_CMD_S_GRACE(xs)	(xs)->xs_status |= XS_PSTS_GRACE
    295  1.18.2.6  bouyer #define	XS_CMD_C_GRACE(xs)	(xs)->xs_status &= ~XS_PSTS_GRACE
    296  1.18.2.6  bouyer #define	XS_CMD_GRACE_P(xs)	(((xs)->xs_status & XS_PSTS_GRACE) != 0)
    297  1.18.2.6  bouyer 
    298  1.18.2.6  bouyer #define	XS_CMD_S_DONE(xs)	(xs)->xs_status |= XS_STS_DONE
    299  1.18.2.6  bouyer #define	XS_CMD_C_DONE(xs)	(xs)->xs_status &= ~XS_STS_DONE
    300  1.18.2.6  bouyer #define	XS_CMD_DONE_P(xs)	(((xs)->xs_status & XS_STS_DONE) != 0)
    301      1.11  mjacob 
    302  1.18.2.6  bouyer #define	XS_CMD_S_CLEAR(xs)	(xs)->xs_status &= ~XS_PSTS_ALL
    303      1.11  mjacob 
    304  1.18.2.6  bouyer /*
    305  1.18.2.6  bouyer  * Platform specific 'inline' or support functions
    306  1.18.2.6  bouyer  */
    307  1.18.2.6  bouyer static inline void
    308  1.18.2.6  bouyer isp_lock(isp)
    309  1.18.2.6  bouyer 	struct ispsoftc *isp;
    310  1.18.2.6  bouyer {
    311  1.18.2.6  bouyer 	int s = splbio();
    312  1.18.2.6  bouyer 	if (isp->isp_osinfo.islocked++ == 0) {
    313  1.18.2.6  bouyer 		isp->isp_osinfo.splsaved = s;
    314  1.18.2.6  bouyer 	} else {
    315  1.18.2.6  bouyer 		splx(s);
    316  1.18.2.6  bouyer 	}
    317  1.18.2.6  bouyer }
    318  1.18.2.6  bouyer 
    319  1.18.2.6  bouyer static inline void
    320  1.18.2.6  bouyer isp_unlock(isp)
    321  1.18.2.6  bouyer 	struct ispsoftc *isp;
    322  1.18.2.6  bouyer {
    323  1.18.2.6  bouyer 	if (isp->isp_osinfo.islocked-- <= 1) {
    324  1.18.2.6  bouyer 		isp->isp_osinfo.islocked = 0;
    325  1.18.2.6  bouyer 		splx(isp->isp_osinfo.splsaved);
    326  1.18.2.6  bouyer 	}
    327  1.18.2.6  bouyer }
    328  1.18.2.6  bouyer 
    329  1.18.2.6  bouyer static inline char *
    330  1.18.2.6  bouyer strncat(d, s, c)
    331  1.18.2.6  bouyer 	char *d;
    332  1.18.2.6  bouyer 	const char *s;
    333  1.18.2.6  bouyer 	size_t c;
    334  1.18.2.6  bouyer {
    335  1.18.2.6  bouyer         char *t = d;
    336  1.18.2.6  bouyer 
    337  1.18.2.6  bouyer         if (c) {
    338  1.18.2.6  bouyer                 while (*d)
    339  1.18.2.6  bouyer                         d++;
    340  1.18.2.6  bouyer                 while ((*d++ = *s++)) {
    341  1.18.2.6  bouyer                         if (--c == 0) {
    342  1.18.2.6  bouyer                                 *d = '\0';
    343  1.18.2.6  bouyer                                 break;
    344  1.18.2.6  bouyer                         }
    345  1.18.2.6  bouyer                 }
    346  1.18.2.6  bouyer         }
    347  1.18.2.6  bouyer         return (t);
    348  1.18.2.6  bouyer }
    349  1.18.2.6  bouyer 
    350  1.18.2.6  bouyer static inline u_int64_t
    351  1.18.2.6  bouyer isp_microtime_sub(b, a)
    352  1.18.2.6  bouyer 	struct timeval *b;
    353  1.18.2.6  bouyer 	struct timeval *a;
    354  1.18.2.6  bouyer {
    355  1.18.2.6  bouyer 	struct timeval x;
    356  1.18.2.6  bouyer 	u_int64_t elapsed;
    357  1.18.2.6  bouyer 	timersub(b, a, &x);
    358  1.18.2.6  bouyer 	elapsed = GET_NANOSEC(&x);
    359  1.18.2.6  bouyer 	if (elapsed == 0)
    360  1.18.2.6  bouyer 		elapsed++;
    361  1.18.2.6  bouyer 	return (elapsed);
    362  1.18.2.6  bouyer }
    363  1.18.2.6  bouyer 
    364  1.18.2.6  bouyer static inline void
    365  1.18.2.6  bouyer isp_wait_complete(isp)
    366  1.18.2.6  bouyer 	struct ispsoftc *isp;
    367  1.18.2.6  bouyer {
    368  1.18.2.6  bouyer 	if (isp->isp_osinfo.onintstack || isp->isp_osinfo.no_mbox_ints) {
    369  1.18.2.6  bouyer 		int usecs = 0;
    370  1.18.2.6  bouyer 		while (usecs < 2 * 1000000) {
    371  1.18.2.6  bouyer 			(void) isp_intr(isp);
    372  1.18.2.6  bouyer 			if (isp->isp_mboxbsy == 0) {
    373  1.18.2.6  bouyer 				break;
    374  1.18.2.6  bouyer 			}
    375  1.18.2.6  bouyer 			USEC_DELAY(500);
    376  1.18.2.6  bouyer 			usecs += 500;
    377  1.18.2.6  bouyer 		}
    378  1.18.2.6  bouyer 		if (isp->isp_mboxbsy != 0) {
    379  1.18.2.6  bouyer 			isp_prt(isp, ISP_LOGWARN, "Mailbox Cmd (poll) Timeout");
    380  1.18.2.6  bouyer 		}
    381  1.18.2.6  bouyer 	} else {
    382  1.18.2.6  bouyer 		int rv = 0;
    383  1.18.2.6  bouyer                 isp->isp_osinfo.mboxwaiting = 1;
    384  1.18.2.6  bouyer                 while (isp->isp_osinfo.mboxwaiting && rv == 0) {
    385  1.18.2.6  bouyer 			static struct timeval twosec = { 2, 0 };
    386  1.18.2.6  bouyer 			int timo;
    387  1.18.2.6  bouyer 			struct timeval tv;
    388  1.18.2.6  bouyer 			microtime(&tv);
    389  1.18.2.6  bouyer 			timeradd(&tv, &twosec, &tv);
    390  1.18.2.6  bouyer 			if ((timo = hzto(&tv)) == 0) {
    391  1.18.2.6  bouyer 				timo = 1;
    392  1.18.2.6  bouyer 			}
    393  1.18.2.6  bouyer 			rv = tsleep(&isp->isp_osinfo.mboxwaiting,
    394  1.18.2.6  bouyer 			    PRIBIO, "isp_mboxcmd", timo);
    395  1.18.2.6  bouyer 		}
    396  1.18.2.6  bouyer 		if (rv == EWOULDBLOCK) {
    397  1.18.2.6  bouyer 			isp->isp_mboxbsy = 0;
    398  1.18.2.6  bouyer 			isp->isp_osinfo.mboxwaiting = 0;
    399  1.18.2.6  bouyer 			isp_prt(isp, ISP_LOGWARN, "Mailbox Cmd (intr) Timeout");
    400  1.18.2.6  bouyer 		}
    401  1.18.2.6  bouyer 	}
    402  1.18.2.6  bouyer }
    403      1.18  mjacob 
    404  1.18.2.6  bouyer /*
    405  1.18.2.6  bouyer  * Common inline functions
    406  1.18.2.6  bouyer  */
    407      1.18  mjacob #define	INLINE	inline
    408      1.18  mjacob #include <dev/ic/isp_inline.h>
    409      1.18  mjacob 
    410  1.18.2.6  bouyer #if	!defined(ISP_DISABLE_FW) && !defined(ISP_COMPILE_FW)
    411  1.18.2.6  bouyer #define	ISP_COMPILE_FW	1
    412  1.18.2.6  bouyer #endif
    413       1.1  mjacob #endif	/* _ISP_NETBSD_H */
    414