Home | History | Annotate | Line # | Download | only in ic
isp_netbsd.h revision 1.37.2.8
      1  1.37.2.7  nathanw /* $NetBSD: isp_netbsd.h,v 1.37.2.8 2002/11/11 22:09:44 nathanw Exp $ */
      2      1.29   mjacob /*
      3      1.29   mjacob  * This driver, which is contained in NetBSD in the files:
      4      1.29   mjacob  *
      5      1.29   mjacob  *	sys/dev/ic/isp.c
      6      1.33      wiz  *	sys/dev/ic/isp_inline.h
      7      1.33      wiz  *	sys/dev/ic/isp_netbsd.c
      8      1.33      wiz  *	sys/dev/ic/isp_netbsd.h
      9      1.33      wiz  *	sys/dev/ic/isp_target.c
     10      1.33      wiz  *	sys/dev/ic/isp_target.h
     11      1.33      wiz  *	sys/dev/ic/isp_tpublic.h
     12      1.33      wiz  *	sys/dev/ic/ispmbox.h
     13      1.33      wiz  *	sys/dev/ic/ispreg.h
     14      1.33      wiz  *	sys/dev/ic/ispvar.h
     15      1.29   mjacob  *	sys/microcode/isp/asm_sbus.h
     16      1.29   mjacob  *	sys/microcode/isp/asm_1040.h
     17      1.29   mjacob  *	sys/microcode/isp/asm_1080.h
     18      1.29   mjacob  *	sys/microcode/isp/asm_12160.h
     19      1.29   mjacob  *	sys/microcode/isp/asm_2100.h
     20      1.29   mjacob  *	sys/microcode/isp/asm_2200.h
     21      1.29   mjacob  *	sys/pci/isp_pci.c
     22      1.29   mjacob  *	sys/sbus/isp_sbus.c
     23      1.29   mjacob  *
     24      1.29   mjacob  * Is being actively maintained by Matthew Jacob (mjacob (at) netbsd.org).
     25      1.29   mjacob  * This driver also is shared source with FreeBSD, OpenBSD, Linux, Solaris,
     26      1.29   mjacob  * Linux versions. This tends to be an interesting maintenance problem.
     27      1.29   mjacob  *
     28      1.29   mjacob  * Please coordinate with Matthew Jacob on changes you wish to make here.
     29      1.29   mjacob  */
     30       1.1   mjacob /*
     31       1.1   mjacob  * NetBSD Specific definitions for the Qlogic ISP Host Adapter
     32      1.15   mjacob  * Matthew Jacob <mjacob (at) nas.nasa.gov>
     33      1.15   mjacob  */
     34      1.15   mjacob /*
     35      1.15   mjacob  * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
     36       1.1   mjacob  * All rights reserved.
     37       1.1   mjacob  *
     38       1.1   mjacob  * Redistribution and use in source and binary forms, with or without
     39       1.1   mjacob  * modification, are permitted provided that the following conditions
     40       1.1   mjacob  * are met:
     41       1.1   mjacob  * 1. Redistributions of source code must retain the above copyright
     42      1.15   mjacob  *    notice, this list of conditions and the following disclaimer.
     43       1.1   mjacob  * 2. Redistributions in binary form must reproduce the above copyright
     44       1.1   mjacob  *    notice, this list of conditions and the following disclaimer in the
     45       1.1   mjacob  *    documentation and/or other materials provided with the distribution.
     46       1.1   mjacob  * 3. The name of the author may not be used to endorse or promote products
     47      1.15   mjacob  *    derived from this software without specific prior written permission
     48       1.1   mjacob  *
     49      1.15   mjacob  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     50      1.15   mjacob  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     51      1.15   mjacob  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     52      1.15   mjacob  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     53      1.15   mjacob  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     54      1.15   mjacob  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     55      1.15   mjacob  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     56      1.15   mjacob  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     57      1.15   mjacob  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     58      1.15   mjacob  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     59       1.1   mjacob  */
     60       1.1   mjacob #ifndef	_ISP_NETBSD_H
     61       1.1   mjacob #define	_ISP_NETBSD_H
     62       1.1   mjacob 
     63       1.1   mjacob #include <sys/types.h>
     64       1.1   mjacob #include <sys/param.h>
     65       1.1   mjacob #include <sys/systm.h>
     66       1.1   mjacob #include <sys/kernel.h>
     67       1.1   mjacob #include <sys/errno.h>
     68       1.1   mjacob #include <sys/ioctl.h>
     69       1.1   mjacob #include <sys/device.h>
     70       1.1   mjacob #include <sys/malloc.h>
     71       1.1   mjacob #include <sys/buf.h>
     72       1.1   mjacob #include <sys/proc.h>
     73       1.1   mjacob #include <sys/user.h>
     74  1.37.2.2  nathanw #include <sys/kthread.h>
     75       1.1   mjacob 
     76  1.37.2.5  nathanw #include <machine/bus.h>
     77       1.1   mjacob 
     78       1.1   mjacob #include <dev/scsipi/scsi_all.h>
     79       1.1   mjacob #include <dev/scsipi/scsipi_all.h>
     80       1.1   mjacob #include <dev/scsipi/scsiconf.h>
     81       1.1   mjacob 
     82       1.1   mjacob #include <dev/scsipi/scsi_message.h>
     83       1.1   mjacob #include <dev/scsipi/scsipi_debug.h>
     84       1.1   mjacob 
     85      1.15   mjacob #include "opt_isp.h"
     86      1.26   mjacob 
     87  1.37.2.5  nathanw /*
     88  1.37.2.5  nathanw  * Efficiency- get rid of SBus code && tests unless we need them.
     89  1.37.2.5  nathanw  */
     90  1.37.2.5  nathanw #if	defined(__sparcv9__ ) || defined(__sparc__)
     91  1.37.2.5  nathanw #define	ISP_SBUS_SUPPORTED	1
     92  1.37.2.5  nathanw #else
     93  1.37.2.5  nathanw #define	ISP_SBUS_SUPPORTED	0
     94  1.37.2.5  nathanw #endif
     95      1.15   mjacob 
     96  1.37.2.2  nathanw #define	ISP_PLATFORM_VERSION_MAJOR	2
     97  1.37.2.5  nathanw #define	ISP_PLATFORM_VERSION_MINOR	1
     98       1.1   mjacob 
     99       1.1   mjacob struct isposinfo {
    100       1.1   mjacob 	struct device		_dev;
    101  1.37.2.2  nathanw 	struct scsipi_channel	_chan;
    102  1.37.2.2  nathanw 	struct scsipi_channel	_chan_b;
    103       1.6   mjacob 	struct scsipi_adapter   _adapter;
    104  1.37.2.5  nathanw 	bus_dma_tag_t		dmatag;
    105  1.37.2.5  nathanw 	bus_dmamap_t		rqdmap;
    106  1.37.2.5  nathanw 	bus_dmamap_t		rsdmap;
    107  1.37.2.5  nathanw 	bus_dmamap_t		scdmap;	/* FC only */
    108  1.37.2.5  nathanw 	int			splsaved;
    109  1.37.2.5  nathanw 	int			mboxwaiting;
    110  1.37.2.5  nathanw 	u_int32_t		islocked;
    111  1.37.2.5  nathanw 	u_int32_t		onintstack;
    112  1.37.2.2  nathanw 	unsigned int		: 26,
    113  1.37.2.2  nathanw 		loop_checked	: 1,
    114  1.37.2.2  nathanw 		mbox_wanted	: 1,
    115  1.37.2.2  nathanw 		mbox_locked	: 1,
    116      1.27   mjacob 		no_mbox_ints	: 1,
    117  1.37.2.2  nathanw 		paused		: 1,
    118      1.29   mjacob 		blocked		: 1;
    119      1.18   mjacob 	union {
    120      1.27   mjacob 		u_int64_t	_wwn;
    121      1.18   mjacob 		u_int16_t	_discovered[2];
    122      1.27   mjacob #define	wwn_seed	un._wwn
    123      1.27   mjacob #define	discovered	un._discovered
    124      1.18   mjacob 	} un;
    125  1.37.2.5  nathanw 	u_int32_t		threadwork;
    126  1.37.2.5  nathanw 	struct proc *		thread;
    127       1.1   mjacob };
    128  1.37.2.5  nathanw #define	isp_dmatag		isp_osinfo.dmatag
    129  1.37.2.5  nathanw #define	isp_rqdmap		isp_osinfo.rqdmap
    130  1.37.2.5  nathanw #define	isp_rsdmap		isp_osinfo.rsdmap
    131  1.37.2.5  nathanw #define	isp_scdmap		isp_osinfo.scdmap
    132  1.37.2.5  nathanw 
    133      1.32   mjacob #define	ISP_MUSTPOLL(isp)	\
    134  1.37.2.8  nathanw  	(isp->isp_osinfo.onintstack || isp->isp_osinfo.no_mbox_ints)
    135      1.18   mjacob 
    136  1.37.2.2  nathanw #define	HANDLE_LOOPSTATE_IN_OUTER_LAYERS	1
    137  1.37.2.2  nathanw 
    138      1.27   mjacob /*
    139      1.27   mjacob  * Required Macros/Defines
    140      1.27   mjacob  */
    141      1.27   mjacob 
    142  1.37.2.2  nathanw #define	INLINE			__inline
    143      1.27   mjacob 
    144  1.37.2.7  nathanw #define	ISP2100_SCRLEN		0x800
    145       1.1   mjacob 
    146  1.37.2.3  nathanw #define	MEMZERO(dst, amt)	memset((dst), 0, (amt))
    147  1.37.2.3  nathanw #define	MEMCPY(dst, src, amt)	memcpy((dst), (src), (amt))
    148      1.27   mjacob #define	SNPRINTF		snprintf
    149      1.27   mjacob #define	USEC_DELAY		DELAY
    150      1.32   mjacob #define	USEC_SLEEP(isp, x)		\
    151      1.32   mjacob 	if (!ISP_MUSTPOLL(isp))		\
    152      1.32   mjacob 		ISP_UNLOCK(isp);	\
    153      1.32   mjacob 	DELAY(x);			\
    154      1.32   mjacob 	if (!ISP_MUSTPOLL(isp))		\
    155      1.32   mjacob 		ISP_LOCK(isp)
    156      1.27   mjacob 
    157      1.27   mjacob #define	NANOTIME_T		struct timeval
    158      1.27   mjacob #define	GET_NANOTIME		microtime
    159      1.27   mjacob #define	GET_NANOSEC(x)		(((x)->tv_sec * 1000000 + (x)->tv_usec) * 1000)
    160      1.27   mjacob #define	NANOTIME_SUB		isp_microtime_sub
    161       1.1   mjacob 
    162      1.27   mjacob #define	MAXISPREQUEST(isp)	256
    163       1.8   mjacob 
    164  1.37.2.5  nathanw 
    165  1.37.2.5  nathanw #define	MEMORYBARRIER(isp, type, offset, size)			\
    166  1.37.2.5  nathanw switch (type) {							\
    167  1.37.2.5  nathanw case SYNC_REQUEST:						\
    168  1.37.2.5  nathanw {								\
    169  1.37.2.5  nathanw 	off_t off = (off_t) offset * QENTRY_LEN;		\
    170  1.37.2.5  nathanw 	bus_dmamap_sync(isp->isp_dmatag, isp->isp_rqdmap,	\
    171  1.37.2.5  nathanw 	    off, size, BUS_DMASYNC_PREWRITE);			\
    172  1.37.2.5  nathanw 	break;							\
    173  1.37.2.5  nathanw }								\
    174  1.37.2.5  nathanw case SYNC_RESULT:						\
    175  1.37.2.5  nathanw {								\
    176  1.37.2.5  nathanw 	off_t off = (off_t) offset * QENTRY_LEN;		\
    177  1.37.2.5  nathanw 	bus_dmamap_sync(isp->isp_dmatag, isp->isp_rsdmap,	\
    178  1.37.2.5  nathanw 	    off, size, BUS_DMASYNC_POSTREAD);			\
    179  1.37.2.5  nathanw 	break;							\
    180  1.37.2.5  nathanw }								\
    181  1.37.2.5  nathanw case SYNC_SFORDEV:						\
    182  1.37.2.5  nathanw {								\
    183  1.37.2.7  nathanw 	off_t off = (off_t) offset;				\
    184  1.37.2.5  nathanw 	bus_dmamap_sync(isp->isp_dmatag, isp->isp_scdmap,	\
    185  1.37.2.5  nathanw 	    off, size, BUS_DMASYNC_PREWRITE);			\
    186  1.37.2.5  nathanw 	break;							\
    187  1.37.2.5  nathanw }								\
    188  1.37.2.5  nathanw case SYNC_SFORCPU:						\
    189  1.37.2.5  nathanw {								\
    190  1.37.2.7  nathanw 	off_t off = (off_t) offset;				\
    191  1.37.2.5  nathanw 	bus_dmamap_sync(isp->isp_dmatag, isp->isp_scdmap,	\
    192  1.37.2.5  nathanw 	    off, size, BUS_DMASYNC_POSTREAD);			\
    193  1.37.2.5  nathanw 	break;							\
    194  1.37.2.5  nathanw }								\
    195  1.37.2.5  nathanw case SYNC_REG:							\
    196  1.37.2.5  nathanw default:							\
    197  1.37.2.5  nathanw 	break;							\
    198  1.37.2.5  nathanw }
    199       1.3   mjacob 
    200  1.37.2.2  nathanw #define	MBOX_ACQUIRE(isp)						\
    201  1.37.2.2  nathanw 	if (isp->isp_osinfo.onintstack) {				\
    202  1.37.2.2  nathanw 		if (isp->isp_osinfo.mbox_locked) {			\
    203  1.37.2.2  nathanw 			mbp->param[0] = MBOX_HOST_INTERFACE_ERROR;	\
    204  1.37.2.2  nathanw 			isp_prt(isp, ISP_LOGERR, "cannot acquire MBOX lock"); \
    205  1.37.2.2  nathanw 			return;						\
    206  1.37.2.2  nathanw 		}							\
    207  1.37.2.2  nathanw 	} else {							\
    208  1.37.2.2  nathanw 		while (isp->isp_osinfo.mbox_locked) {			\
    209  1.37.2.2  nathanw 			isp->isp_osinfo.mbox_wanted = 1;		\
    210  1.37.2.2  nathanw 			(void) tsleep(&isp->isp_osinfo.mboxwaiting+1,	\
    211  1.37.2.2  nathanw 			    PRIBIO, "mbox_acquire", 0);			\
    212  1.37.2.2  nathanw 		}							\
    213  1.37.2.2  nathanw 	}								\
    214  1.37.2.2  nathanw 	isp->isp_osinfo.mbox_locked = 1
    215  1.37.2.2  nathanw 
    216      1.27   mjacob #define	MBOX_WAIT_COMPLETE	isp_wait_complete
    217      1.13   mjacob 
    218      1.27   mjacob #define	MBOX_NOTIFY_COMPLETE(isp)					\
    219      1.27   mjacob 	if (isp->isp_osinfo.mboxwaiting) {				\
    220      1.27   mjacob                 isp->isp_osinfo.mboxwaiting = 0;			\
    221      1.27   mjacob                 wakeup(&isp->isp_osinfo.mboxwaiting);			\
    222      1.27   mjacob         }								\
    223      1.27   mjacob 	isp->isp_mboxbsy = 0
    224       1.1   mjacob 
    225  1.37.2.2  nathanw #define	MBOX_RELEASE(isp)						\
    226  1.37.2.2  nathanw 	if (isp->isp_osinfo.mbox_wanted) {				\
    227  1.37.2.2  nathanw 		isp->isp_osinfo.mbox_wanted = 0;			\
    228  1.37.2.2  nathanw 		wakeup(&isp->isp_osinfo.mboxwaiting+1);			\
    229  1.37.2.2  nathanw 	}								\
    230  1.37.2.2  nathanw 	isp->isp_osinfo.mbox_locked = 0
    231      1.26   mjacob 
    232  1.37.2.6  nathanw #define	FC_SCRATCH_ACQUIRE(isp)
    233  1.37.2.6  nathanw #define	FC_SCRATCH_RELEASE(isp)
    234  1.37.2.6  nathanw 
    235      1.27   mjacob #ifndef	SCSI_GOOD
    236      1.27   mjacob #define	SCSI_GOOD	0x0
    237      1.27   mjacob #endif
    238      1.27   mjacob #ifndef	SCSI_CHECK
    239      1.27   mjacob #define	SCSI_CHECK	0x2
    240      1.27   mjacob #endif
    241      1.27   mjacob #ifndef	SCSI_BUSY
    242      1.27   mjacob #define	SCSI_BUSY	0x8
    243      1.27   mjacob #endif
    244      1.27   mjacob #ifndef	SCSI_QFULL
    245      1.27   mjacob #define	SCSI_QFULL	0x28
    246      1.27   mjacob #endif
    247      1.26   mjacob 
    248      1.27   mjacob #define	XS_T			struct scsipi_xfer
    249  1.37.2.2  nathanw #define	XS_CHANNEL(xs)		((int) (xs)->xs_periph->periph_channel->chan_channel)
    250  1.37.2.2  nathanw #define	XS_ISP(xs)		\
    251  1.37.2.2  nathanw 	((void *)(xs)->xs_periph->periph_channel->chan_adapter->adapt_dev)
    252  1.37.2.2  nathanw #define	XS_LUN(xs)		((int) (xs)->xs_periph->periph_lun)
    253  1.37.2.2  nathanw #define	XS_TGT(xs)		((int) (xs)->xs_periph->periph_target)
    254      1.27   mjacob #define	XS_CDBP(xs)		((caddr_t) (xs)->cmd)
    255      1.27   mjacob #define	XS_CDBLEN(xs)		(xs)->cmdlen
    256       1.1   mjacob #define	XS_XFRLEN(xs)		(xs)->datalen
    257       1.1   mjacob #define	XS_TIME(xs)		(xs)->timeout
    258      1.27   mjacob #define	XS_RESID(xs)		(xs)->resid
    259      1.27   mjacob #define	XS_STSP(xs)		(&(xs)->status)
    260       1.1   mjacob #define	XS_SNSP(xs)		(&(xs)->sense.scsi_sense)
    261      1.27   mjacob #define	XS_SNSLEN(xs)		(sizeof (xs)->sense)
    262       1.1   mjacob #define	XS_SNSKEY(xs)		((xs)->sense.scsi_sense.flags)
    263      1.27   mjacob #define	XS_TAG_P(ccb)		(((xs)->xs_control & XS_CTL_POLL) != 0)
    264      1.27   mjacob #define	XS_TAG_TYPE(xs)	\
    265      1.28      tls 	(((xs)->xs_control & XS_CTL_URGENT) ? REQFLAG_HTAG : \
    266      1.28      tls 	((xs)->bp && xs->bp->b_flags & B_ASYNC) ? REQFLAG_STAG : REQFLAG_OTAG)
    267      1.27   mjacob 
    268      1.27   mjacob #define	XS_SETERR(xs, v)	(xs)->error = v
    269      1.27   mjacob 
    270      1.27   mjacob #	define	HBA_NOERROR		XS_NOERROR
    271      1.27   mjacob #	define	HBA_BOTCH		XS_DRIVER_STUFFUP
    272      1.27   mjacob #	define	HBA_CMDTIMEOUT		XS_TIMEOUT
    273      1.27   mjacob #	define	HBA_SELTIMEOUT		XS_SELTIMEOUT
    274      1.27   mjacob #	define	HBA_TGTBSY		XS_BUSY
    275      1.27   mjacob #	define	HBA_BUSRESET		XS_RESET
    276      1.27   mjacob #	define	HBA_ABORTED		XS_DRIVER_STUFFUP
    277      1.27   mjacob #	define	HBA_DATAOVR		XS_DRIVER_STUFFUP
    278      1.27   mjacob #	define	HBA_ARQFAIL		XS_DRIVER_STUFFUP
    279       1.1   mjacob 
    280      1.27   mjacob #define	XS_ERR(xs)		(xs)->error
    281      1.27   mjacob 
    282      1.27   mjacob #define	XS_NOERR(xs)		(xs)->error == XS_NOERROR
    283      1.27   mjacob 
    284      1.27   mjacob #define	XS_INITERR(xs)		(xs)->error = 0, XS_CMD_S_CLEAR(xs)
    285      1.27   mjacob 
    286      1.27   mjacob #define	XS_SAVE_SENSE(xs, sp)				\
    287      1.34   mjacob 	if (xs->error == XS_NOERROR) {			\
    288      1.34   mjacob 		xs->error = XS_SENSE;			\
    289      1.34   mjacob 	}						\
    290  1.37.2.3  nathanw 	memcpy(&(xs)->sense, sp->req_sense_data,	\
    291      1.27   mjacob 	    imin(XS_SNSLEN(xs), sp->req_sense_len))
    292      1.27   mjacob 
    293      1.27   mjacob #define	XS_SET_STATE_STAT(a, b, c)
    294      1.27   mjacob 
    295      1.27   mjacob #define	DEFAULT_IID(x)		7
    296      1.27   mjacob #define	DEFAULT_LOOPID(x)	108
    297      1.27   mjacob #define	DEFAULT_NODEWWN(isp)	(isp)->isp_osinfo.un._wwn
    298      1.30   mjacob #define	DEFAULT_PORTWWN(isp)	(isp)->isp_osinfo.un._wwn
    299      1.30   mjacob #define	ISP_NODEWWN(isp)	FCPARAM(isp)->isp_nodewwn
    300      1.30   mjacob #define	ISP_PORTWWN(isp)	FCPARAM(isp)->isp_portwwn
    301      1.27   mjacob 
    302      1.32   mjacob #if	_BYTE_ORDER == _BIG_ENDIAN
    303  1.37.2.5  nathanw #ifdef	ISP_SBUS_SUPPORTED
    304  1.37.2.5  nathanw #define	ISP_IOXPUT_8(isp, s, d)		*(d) = s
    305  1.37.2.5  nathanw #define	ISP_IOXPUT_16(isp, s, d)				\
    306  1.37.2.5  nathanw 	*(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap16(s)
    307  1.37.2.5  nathanw #define	ISP_IOXPUT_32(isp, s, d)				\
    308  1.37.2.5  nathanw 	*(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap32(s)
    309  1.37.2.5  nathanw 
    310  1.37.2.5  nathanw #define	ISP_IOXGET_8(isp, s, d)		d = (*((u_int8_t *)s))
    311  1.37.2.5  nathanw #define	ISP_IOXGET_16(isp, s, d)				\
    312  1.37.2.5  nathanw 	d = (isp->isp_bustype == ISP_BT_SBUS)?			\
    313  1.37.2.5  nathanw 	*((u_int16_t *)s) : bswap16(*((u_int16_t *)s))
    314  1.37.2.5  nathanw #define	ISP_IOXGET_32(isp, s, d)				\
    315  1.37.2.5  nathanw 	d = (isp->isp_bustype == ISP_BT_SBUS)?			\
    316  1.37.2.5  nathanw 	*((u_int32_t *)s) : bswap32(*((u_int32_t *)s))
    317  1.37.2.5  nathanw #else
    318  1.37.2.5  nathanw #define	ISP_IOXPUT_8(isp, s, d)		*(d) = s
    319  1.37.2.5  nathanw #define	ISP_IOXPUT_16(isp, s, d)	*(d) = bswap16(s)
    320  1.37.2.5  nathanw #define	ISP_IOXPUT_32(isp, s, d)	*(d) = bswap32(s)
    321  1.37.2.5  nathanw #define	ISP_IOXGET_8(isp, s, d)		d = (*((u_int8_t *)s))
    322  1.37.2.5  nathanw #define	ISP_IOXGET_16(isp, s, d)	d = bswap16(*((u_int16_t *)s))
    323  1.37.2.5  nathanw #define	ISP_IOXGET_32(isp, s, d)	d = bswap32(*((u_int32_t *)s))
    324  1.37.2.5  nathanw #endif
    325      1.32   mjacob #define	ISP_SWIZZLE_NVRAM_WORD(isp, rp)	*rp = bswap16(*rp)
    326       1.3   mjacob #else
    327  1.37.2.5  nathanw #define	ISP_IOXPUT_8(isp, s, d)		*(d) = s
    328  1.37.2.5  nathanw #define	ISP_IOXPUT_16(isp, s, d)	*(d) = s
    329  1.37.2.5  nathanw #define	ISP_IOXPUT_32(isp, s, d)	*(d) = s
    330  1.37.2.5  nathanw #define	ISP_IOXGET_8(isp, s, d)		d = *(s)
    331  1.37.2.5  nathanw #define	ISP_IOXGET_16(isp, s, d)	d = *(s)
    332  1.37.2.5  nathanw #define	ISP_IOXGET_32(isp, s, d)	d = *(s)
    333      1.27   mjacob #define	ISP_SWIZZLE_NVRAM_WORD(isp, rp)
    334      1.27   mjacob #endif
    335      1.27   mjacob 
    336      1.27   mjacob /*
    337      1.27   mjacob  * Includes of common header files
    338      1.27   mjacob  */
    339       1.1   mjacob 
    340      1.27   mjacob #include <dev/ic/ispreg.h>
    341      1.27   mjacob #include <dev/ic/ispvar.h>
    342      1.27   mjacob #include <dev/ic/ispmbox.h>
    343  1.37.2.2  nathanw #include <dev/ic/isp_ioctl.h>
    344      1.27   mjacob 
    345      1.27   mjacob /*
    346      1.27   mjacob  * isp_osinfo definitions, extensions and shorthand.
    347      1.27   mjacob  */
    348      1.27   mjacob #define	isp_name	isp_osinfo._dev.dv_xname
    349      1.27   mjacob #define	isp_unit	isp_osinfo._dev.dv_unit
    350  1.37.2.2  nathanw #define	isp_chanA	isp_osinfo._chan
    351  1.37.2.2  nathanw #define	isp_chanB	isp_osinfo._chan_b
    352  1.37.2.2  nathanw 
    353      1.27   mjacob 
    354      1.27   mjacob /*
    355      1.27   mjacob  * Driver prototypes..
    356      1.27   mjacob  */
    357  1.37.2.1  nathanw void isp_attach(struct ispsoftc *);
    358  1.37.2.1  nathanw void isp_uninit(struct ispsoftc *);
    359      1.27   mjacob 
    360  1.37.2.2  nathanw static INLINE void isp_lock(struct ispsoftc *);
    361  1.37.2.2  nathanw static INLINE void isp_unlock(struct ispsoftc *);
    362  1.37.2.2  nathanw static INLINE char *strncat(char *, const char *, size_t);
    363  1.37.2.2  nathanw static INLINE u_int64_t
    364  1.37.2.1  nathanw isp_microtime_sub(struct timeval *, struct timeval *);
    365  1.37.2.1  nathanw static void isp_wait_complete(struct ispsoftc *);
    366      1.27   mjacob 
    367      1.27   mjacob /*
    368      1.27   mjacob  * Driver wide data...
    369      1.27   mjacob  */
    370      1.27   mjacob 
    371      1.27   mjacob /*
    372      1.27   mjacob  * Locking macros...
    373      1.27   mjacob  */
    374      1.27   mjacob #define	ISP_LOCK		isp_lock
    375      1.27   mjacob #define	ISP_UNLOCK		isp_unlock
    376      1.29   mjacob #define	ISP_ILOCK(x)		isp_lock(x); isp->isp_osinfo.onintstack++
    377      1.29   mjacob #define	ISP_IUNLOCK(x)		isp->isp_osinfo.onintstack--; isp_unlock(x)
    378      1.27   mjacob 
    379      1.27   mjacob /*
    380      1.27   mjacob  * Platform private flags
    381      1.27   mjacob  */
    382       1.1   mjacob 
    383      1.26   mjacob #define	XS_PSTS_INWDOG		0x10000000
    384      1.26   mjacob #define	XS_PSTS_GRACE		0x20000000
    385      1.26   mjacob #define	XS_PSTS_ALL		0x30000000
    386      1.26   mjacob 
    387      1.26   mjacob #define	XS_CMD_S_WDOG(xs)	(xs)->xs_status |= XS_PSTS_INWDOG
    388      1.26   mjacob #define	XS_CMD_C_WDOG(xs)	(xs)->xs_status &= ~XS_PSTS_INWDOG
    389      1.26   mjacob #define	XS_CMD_WDOG_P(xs)	(((xs)->xs_status & XS_PSTS_INWDOG) != 0)
    390      1.26   mjacob 
    391      1.26   mjacob #define	XS_CMD_S_GRACE(xs)	(xs)->xs_status |= XS_PSTS_GRACE
    392      1.26   mjacob #define	XS_CMD_C_GRACE(xs)	(xs)->xs_status &= ~XS_PSTS_GRACE
    393      1.26   mjacob #define	XS_CMD_GRACE_P(xs)	(((xs)->xs_status & XS_PSTS_GRACE) != 0)
    394      1.26   mjacob 
    395      1.26   mjacob #define	XS_CMD_S_DONE(xs)	(xs)->xs_status |= XS_STS_DONE
    396      1.26   mjacob #define	XS_CMD_C_DONE(xs)	(xs)->xs_status &= ~XS_STS_DONE
    397      1.26   mjacob #define	XS_CMD_DONE_P(xs)	(((xs)->xs_status & XS_STS_DONE) != 0)
    398      1.26   mjacob 
    399      1.26   mjacob #define	XS_CMD_S_CLEAR(xs)	(xs)->xs_status &= ~XS_PSTS_ALL
    400      1.26   mjacob 
    401       1.1   mjacob /*
    402      1.27   mjacob  * Platform specific 'inline' or support functions
    403       1.1   mjacob  */
    404  1.37.2.2  nathanw static INLINE void
    405  1.37.2.1  nathanw isp_lock(struct ispsoftc *isp)
    406      1.27   mjacob {
    407      1.27   mjacob 	int s = splbio();
    408      1.29   mjacob 	if (isp->isp_osinfo.islocked++ == 0) {
    409      1.27   mjacob 		isp->isp_osinfo.splsaved = s;
    410      1.27   mjacob 	} else {
    411      1.27   mjacob 		splx(s);
    412      1.27   mjacob 	}
    413      1.27   mjacob }
    414       1.1   mjacob 
    415  1.37.2.2  nathanw static INLINE void
    416  1.37.2.1  nathanw isp_unlock(struct ispsoftc *isp)
    417      1.27   mjacob {
    418      1.30   mjacob 	if (isp->isp_osinfo.islocked-- <= 1) {
    419      1.27   mjacob 		isp->isp_osinfo.islocked = 0;
    420      1.27   mjacob 		splx(isp->isp_osinfo.splsaved);
    421      1.27   mjacob 	}
    422      1.27   mjacob }
    423       1.1   mjacob 
    424  1.37.2.2  nathanw static INLINE char *
    425  1.37.2.1  nathanw strncat(char *d, const char *s, size_t c)
    426      1.26   mjacob {
    427      1.26   mjacob         char *t = d;
    428      1.26   mjacob 
    429      1.26   mjacob         if (c) {
    430      1.26   mjacob                 while (*d)
    431      1.26   mjacob                         d++;
    432      1.26   mjacob                 while ((*d++ = *s++)) {
    433      1.26   mjacob                         if (--c == 0) {
    434      1.26   mjacob                                 *d = '\0';
    435      1.26   mjacob                                 break;
    436      1.26   mjacob                         }
    437      1.26   mjacob                 }
    438      1.26   mjacob         }
    439      1.26   mjacob         return (t);
    440      1.26   mjacob }
    441      1.26   mjacob 
    442  1.37.2.2  nathanw static INLINE u_int64_t
    443  1.37.2.1  nathanw isp_microtime_sub(struct timeval *b, struct timeval *a)
    444      1.27   mjacob {
    445      1.27   mjacob 	struct timeval x;
    446      1.27   mjacob 	u_int64_t elapsed;
    447      1.27   mjacob 	timersub(b, a, &x);
    448      1.27   mjacob 	elapsed = GET_NANOSEC(&x);
    449      1.27   mjacob 	if (elapsed == 0)
    450      1.27   mjacob 		elapsed++;
    451      1.27   mjacob 	return (elapsed);
    452      1.27   mjacob }
    453      1.18   mjacob 
    454  1.37.2.2  nathanw static INLINE void
    455  1.37.2.1  nathanw isp_wait_complete(struct ispsoftc *isp)
    456      1.27   mjacob {
    457  1.37.2.6  nathanw 	int lim;
    458  1.37.2.6  nathanw 	if (isp->isp_mbxwrk0)
    459  1.37.2.6  nathanw 		lim = 60;
    460  1.37.2.6  nathanw 	else
    461  1.37.2.6  nathanw 		lim = 5;
    462  1.37.2.8  nathanw 	if (ISP_MUSTPOLL(isp)) {
    463  1.37.2.6  nathanw 		int useclim = 1000000 * lim, usecs = 0;
    464      1.34   mjacob 		/*
    465      1.34   mjacob 		 * For sanity's sake, we don't delay longer
    466      1.34   mjacob 		 * than 5 seconds for polled commands.
    467      1.34   mjacob 		 */
    468  1.37.2.6  nathanw 		while (usecs < useclim) {
    469  1.37.2.4  nathanw 			u_int16_t isr, sema, mbox;
    470      1.27   mjacob 			if (isp->isp_mboxbsy == 0) {
    471      1.27   mjacob 				break;
    472  1.37.2.4  nathanw 			}
    473  1.37.2.4  nathanw 			if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
    474  1.37.2.4  nathanw 				isp_intr(isp, isr, sema, mbox);
    475  1.37.2.4  nathanw 				if (isp->isp_mboxbsy == 0) {
    476  1.37.2.4  nathanw 					break;
    477  1.37.2.4  nathanw 				}
    478      1.27   mjacob 			}
    479      1.27   mjacob 			USEC_DELAY(500);
    480      1.27   mjacob 			usecs += 500;
    481      1.27   mjacob 		}
    482      1.27   mjacob 		if (isp->isp_mboxbsy != 0) {
    483      1.34   mjacob 			isp_prt(isp, ISP_LOGWARN,
    484      1.34   mjacob 			    "Polled Mailbox Command (0x%x) Timeout",
    485      1.36   mjacob 			    isp->isp_lastmbxcmd);
    486      1.27   mjacob 		}
    487      1.27   mjacob 	} else {
    488      1.27   mjacob 		int rv = 0;
    489      1.27   mjacob                 isp->isp_osinfo.mboxwaiting = 1;
    490      1.27   mjacob                 while (isp->isp_osinfo.mboxwaiting && rv == 0) {
    491  1.37.2.6  nathanw 			struct timeval dtime;
    492      1.27   mjacob 			int timo;
    493      1.27   mjacob 			struct timeval tv;
    494  1.37.2.6  nathanw 
    495  1.37.2.6  nathanw 			dtime.tv_sec = lim;
    496  1.37.2.6  nathanw 			dtime.tv_usec = 0;
    497      1.27   mjacob 			microtime(&tv);
    498      1.34   mjacob 			timeradd(&tv, &dtime, &tv);
    499      1.27   mjacob 			if ((timo = hzto(&tv)) == 0) {
    500      1.27   mjacob 				timo = 1;
    501      1.27   mjacob 			}
    502      1.27   mjacob 			rv = tsleep(&isp->isp_osinfo.mboxwaiting,
    503      1.27   mjacob 			    PRIBIO, "isp_mboxcmd", timo);
    504      1.27   mjacob 		}
    505      1.27   mjacob 		if (rv == EWOULDBLOCK) {
    506      1.27   mjacob 			isp->isp_mboxbsy = 0;
    507      1.27   mjacob 			isp->isp_osinfo.mboxwaiting = 0;
    508      1.34   mjacob 			isp_prt(isp, ISP_LOGWARN,
    509      1.34   mjacob 			    "Interrupting Mailbox Command (0x%x) Timeout",
    510      1.36   mjacob 			    isp->isp_lastmbxcmd);
    511      1.27   mjacob 		}
    512      1.27   mjacob 	}
    513      1.27   mjacob }
    514      1.32   mjacob 
    515      1.27   mjacob 
    516      1.27   mjacob /*
    517      1.27   mjacob  * Common inline functions
    518      1.27   mjacob  */
    519      1.18   mjacob #include <dev/ic/isp_inline.h>
    520      1.18   mjacob 
    521      1.19   mjacob #if	!defined(ISP_DISABLE_FW) && !defined(ISP_COMPILE_FW)
    522      1.19   mjacob #define	ISP_COMPILE_FW	1
    523      1.19   mjacob #endif
    524       1.1   mjacob #endif	/* _ISP_NETBSD_H */
    525