Home | History | Annotate | Line # | Download | only in ic
isp_netbsd.h revision 1.48
      1  1.48   mjacob /* $NetBSD: isp_netbsd.h,v 1.48 2002/02/21 22:32:42 mjacob 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.43   mjacob #include <sys/kthread.h>
     75   1.1   mjacob 
     76  1.47   mjacob #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.47   mjacob /*
     88  1.47   mjacob  * Efficiency- get rid of SBus code && tests unless we need them.
     89  1.47   mjacob  */
     90  1.47   mjacob #if	defined(__sparcv9__ ) || defined(__sparc__)
     91  1.47   mjacob #define	ISP_SBUS_SUPPORTED	1
     92  1.47   mjacob #else
     93  1.47   mjacob #define	ISP_SBUS_SUPPORTED	0
     94  1.47   mjacob #endif
     95  1.15   mjacob 
     96  1.43   mjacob #define	ISP_PLATFORM_VERSION_MAJOR	2
     97  1.47   mjacob #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.40   bouyer 	struct scsipi_channel	_chan;
    102  1.40   bouyer 	struct scsipi_channel	_chan_b;
    103   1.6   mjacob 	struct scsipi_adapter   _adapter;
    104  1.47   mjacob 	bus_dma_tag_t		dmatag;
    105  1.47   mjacob 	bus_dmamap_t		rqdmap;
    106  1.47   mjacob 	bus_dmamap_t		rsdmap;
    107  1.47   mjacob 	bus_dmamap_t		scdmap;	/* FC only */
    108  1.47   mjacob 	int			splsaved;
    109  1.47   mjacob 	int			mboxwaiting;
    110  1.47   mjacob 	u_int32_t		islocked;
    111  1.47   mjacob 	u_int32_t		onintstack;
    112  1.43   mjacob 	unsigned int		: 26,
    113  1.43   mjacob 		loop_checked	: 1,
    114  1.41   mjacob 		mbox_wanted	: 1,
    115  1.41   mjacob 		mbox_locked	: 1,
    116  1.41   mjacob 		no_mbox_ints	: 1,
    117  1.43   mjacob 		paused		: 1,
    118  1.41   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.47   mjacob 	u_int32_t		threadwork;
    126  1.47   mjacob 	struct proc *		thread;
    127   1.1   mjacob };
    128  1.47   mjacob #define	isp_dmatag		isp_osinfo.dmatag
    129  1.47   mjacob #define	isp_rqdmap		isp_osinfo.rqdmap
    130  1.47   mjacob #define	isp_rsdmap		isp_osinfo.rsdmap
    131  1.47   mjacob #define	isp_scdmap		isp_osinfo.scdmap
    132  1.47   mjacob 
    133  1.32   mjacob #define	ISP_MUSTPOLL(isp)	\
    134  1.32   mjacob 	(isp->isp_osinfo.onintstack || isp->isp_osinfo.no_mbox_ints)
    135  1.18   mjacob 
    136  1.43   mjacob #define	HANDLE_LOOPSTATE_IN_OUTER_LAYERS	1
    137  1.43   mjacob 
    138  1.27   mjacob /*
    139  1.27   mjacob  * Required Macros/Defines
    140  1.27   mjacob  */
    141  1.27   mjacob 
    142  1.42   mjacob #define	INLINE			__inline
    143  1.27   mjacob 
    144  1.15   mjacob #define	ISP2100_SCRLEN		0x400
    145   1.1   mjacob 
    146  1.45  thorpej #define	MEMZERO(dst, amt)	memset((dst), 0, (amt))
    147  1.44  thorpej #define	MEMCPY(dst, src, amt)	memcpy((dst), (src), (amt))
    148  1.27   mjacob #define	SNPRINTF		snprintf
    149  1.27   mjacob #define	STRNCAT			strncat
    150  1.27   mjacob #define	USEC_DELAY		DELAY
    151  1.32   mjacob #define	USEC_SLEEP(isp, x)		\
    152  1.32   mjacob 	if (!ISP_MUSTPOLL(isp))		\
    153  1.32   mjacob 		ISP_UNLOCK(isp);	\
    154  1.32   mjacob 	DELAY(x);			\
    155  1.32   mjacob 	if (!ISP_MUSTPOLL(isp))		\
    156  1.32   mjacob 		ISP_LOCK(isp)
    157  1.27   mjacob 
    158  1.27   mjacob #define	NANOTIME_T		struct timeval
    159  1.27   mjacob #define	GET_NANOTIME		microtime
    160  1.27   mjacob #define	GET_NANOSEC(x)		(((x)->tv_sec * 1000000 + (x)->tv_usec) * 1000)
    161  1.27   mjacob #define	NANOTIME_SUB		isp_microtime_sub
    162   1.1   mjacob 
    163  1.27   mjacob #define	MAXISPREQUEST(isp)	256
    164   1.8   mjacob 
    165  1.47   mjacob 
    166  1.47   mjacob #define	MEMORYBARRIER(isp, type, offset, size)			\
    167  1.47   mjacob switch (type) {							\
    168  1.47   mjacob case SYNC_REQUEST:						\
    169  1.47   mjacob {								\
    170  1.47   mjacob 	off_t off = (off_t) offset * QENTRY_LEN;		\
    171  1.47   mjacob 	bus_dmamap_sync(isp->isp_dmatag, isp->isp_rqdmap,	\
    172  1.47   mjacob 	    off, size, BUS_DMASYNC_PREWRITE);			\
    173  1.47   mjacob 	break;							\
    174  1.47   mjacob }								\
    175  1.47   mjacob case SYNC_RESULT:						\
    176  1.47   mjacob {								\
    177  1.47   mjacob 	off_t off = (off_t) offset * QENTRY_LEN;		\
    178  1.47   mjacob 	off += ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp));		\
    179  1.47   mjacob 	bus_dmamap_sync(isp->isp_dmatag, isp->isp_rsdmap,	\
    180  1.47   mjacob 	    off, size, BUS_DMASYNC_POSTREAD);			\
    181  1.47   mjacob 	break;							\
    182  1.47   mjacob }								\
    183  1.47   mjacob case SYNC_SFORDEV:						\
    184  1.47   mjacob {								\
    185  1.47   mjacob 	off_t off =						\
    186  1.47   mjacob 	    ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) +		\
    187  1.47   mjacob 	    ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp)) + offset;	\
    188  1.47   mjacob 	bus_dmamap_sync(isp->isp_dmatag, isp->isp_scdmap,	\
    189  1.47   mjacob 	    off, size, BUS_DMASYNC_PREWRITE);			\
    190  1.47   mjacob 	break;							\
    191  1.47   mjacob }								\
    192  1.47   mjacob case SYNC_SFORCPU:						\
    193  1.47   mjacob {								\
    194  1.47   mjacob 	off_t off =						\
    195  1.47   mjacob 	    ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) +		\
    196  1.47   mjacob 	    ISP_QUEUE_SIZE(RESULT_QUEUE_LEN(isp)) + offset;	\
    197  1.47   mjacob 	bus_dmamap_sync(isp->isp_dmatag, isp->isp_scdmap,	\
    198  1.47   mjacob 	    off, size, BUS_DMASYNC_POSTREAD);			\
    199  1.47   mjacob 	break;							\
    200  1.47   mjacob }								\
    201  1.47   mjacob case SYNC_REG:							\
    202  1.47   mjacob default:							\
    203  1.47   mjacob 	break;							\
    204  1.47   mjacob }
    205   1.3   mjacob 
    206  1.41   mjacob #define	MBOX_ACQUIRE(isp)						\
    207  1.41   mjacob 	if (isp->isp_osinfo.onintstack) {				\
    208  1.41   mjacob 		if (isp->isp_osinfo.mbox_locked) {			\
    209  1.41   mjacob 			mbp->param[0] = MBOX_HOST_INTERFACE_ERROR;	\
    210  1.41   mjacob 			isp_prt(isp, ISP_LOGERR, "cannot acquire MBOX lock"); \
    211  1.41   mjacob 			return;						\
    212  1.41   mjacob 		}							\
    213  1.41   mjacob 	} else {							\
    214  1.41   mjacob 		while (isp->isp_osinfo.mbox_locked) {			\
    215  1.41   mjacob 			isp->isp_osinfo.mbox_wanted = 1;		\
    216  1.41   mjacob 			(void) tsleep(&isp->isp_osinfo.mboxwaiting+1,	\
    217  1.41   mjacob 			    PRIBIO, "mbox_acquire", 0);			\
    218  1.41   mjacob 		}							\
    219  1.41   mjacob 	}								\
    220  1.41   mjacob 	isp->isp_osinfo.mbox_locked = 1
    221  1.41   mjacob 
    222  1.27   mjacob #define	MBOX_WAIT_COMPLETE	isp_wait_complete
    223  1.13   mjacob 
    224  1.27   mjacob #define	MBOX_NOTIFY_COMPLETE(isp)					\
    225  1.27   mjacob 	if (isp->isp_osinfo.mboxwaiting) {				\
    226  1.27   mjacob                 isp->isp_osinfo.mboxwaiting = 0;			\
    227  1.27   mjacob                 wakeup(&isp->isp_osinfo.mboxwaiting);			\
    228  1.27   mjacob         }								\
    229  1.27   mjacob 	isp->isp_mboxbsy = 0
    230   1.1   mjacob 
    231  1.41   mjacob #define	MBOX_RELEASE(isp)						\
    232  1.41   mjacob 	if (isp->isp_osinfo.mbox_wanted) {				\
    233  1.41   mjacob 		isp->isp_osinfo.mbox_wanted = 0;			\
    234  1.41   mjacob 		wakeup(&isp->isp_osinfo.mboxwaiting+1);			\
    235  1.41   mjacob 	}								\
    236  1.41   mjacob 	isp->isp_osinfo.mbox_locked = 0
    237  1.26   mjacob 
    238  1.48   mjacob #define	FC_SCRATCH_ACQUIRE(isp)
    239  1.48   mjacob #define	FC_SCRATCH_RELEASE(isp)
    240  1.48   mjacob 
    241  1.27   mjacob #ifndef	SCSI_GOOD
    242  1.27   mjacob #define	SCSI_GOOD	0x0
    243  1.27   mjacob #endif
    244  1.27   mjacob #ifndef	SCSI_CHECK
    245  1.27   mjacob #define	SCSI_CHECK	0x2
    246  1.27   mjacob #endif
    247  1.27   mjacob #ifndef	SCSI_BUSY
    248  1.27   mjacob #define	SCSI_BUSY	0x8
    249  1.27   mjacob #endif
    250  1.27   mjacob #ifndef	SCSI_QFULL
    251  1.27   mjacob #define	SCSI_QFULL	0x28
    252  1.27   mjacob #endif
    253  1.26   mjacob 
    254  1.27   mjacob #define	XS_T			struct scsipi_xfer
    255  1.40   bouyer #define	XS_CHANNEL(xs)		((int) (xs)->xs_periph->periph_channel->chan_channel)
    256  1.40   bouyer #define	XS_ISP(xs)		\
    257  1.40   bouyer 	((void *)(xs)->xs_periph->periph_channel->chan_adapter->adapt_dev)
    258  1.40   bouyer #define	XS_LUN(xs)		((int) (xs)->xs_periph->periph_lun)
    259  1.40   bouyer #define	XS_TGT(xs)		((int) (xs)->xs_periph->periph_target)
    260  1.27   mjacob #define	XS_CDBP(xs)		((caddr_t) (xs)->cmd)
    261  1.27   mjacob #define	XS_CDBLEN(xs)		(xs)->cmdlen
    262   1.1   mjacob #define	XS_XFRLEN(xs)		(xs)->datalen
    263   1.1   mjacob #define	XS_TIME(xs)		(xs)->timeout
    264  1.27   mjacob #define	XS_RESID(xs)		(xs)->resid
    265  1.27   mjacob #define	XS_STSP(xs)		(&(xs)->status)
    266   1.1   mjacob #define	XS_SNSP(xs)		(&(xs)->sense.scsi_sense)
    267  1.27   mjacob #define	XS_SNSLEN(xs)		(sizeof (xs)->sense)
    268   1.1   mjacob #define	XS_SNSKEY(xs)		((xs)->sense.scsi_sense.flags)
    269  1.27   mjacob #define	XS_TAG_P(ccb)		(((xs)->xs_control & XS_CTL_POLL) != 0)
    270  1.27   mjacob #define	XS_TAG_TYPE(xs)	\
    271  1.28      tls 	(((xs)->xs_control & XS_CTL_URGENT) ? REQFLAG_HTAG : \
    272  1.28      tls 	((xs)->bp && xs->bp->b_flags & B_ASYNC) ? REQFLAG_STAG : REQFLAG_OTAG)
    273  1.27   mjacob 
    274  1.27   mjacob #define	XS_SETERR(xs, v)	(xs)->error = v
    275  1.27   mjacob 
    276  1.27   mjacob #	define	HBA_NOERROR		XS_NOERROR
    277  1.27   mjacob #	define	HBA_BOTCH		XS_DRIVER_STUFFUP
    278  1.27   mjacob #	define	HBA_CMDTIMEOUT		XS_TIMEOUT
    279  1.27   mjacob #	define	HBA_SELTIMEOUT		XS_SELTIMEOUT
    280  1.27   mjacob #	define	HBA_TGTBSY		XS_BUSY
    281  1.27   mjacob #	define	HBA_BUSRESET		XS_RESET
    282  1.27   mjacob #	define	HBA_ABORTED		XS_DRIVER_STUFFUP
    283  1.27   mjacob #	define	HBA_DATAOVR		XS_DRIVER_STUFFUP
    284  1.27   mjacob #	define	HBA_ARQFAIL		XS_DRIVER_STUFFUP
    285   1.1   mjacob 
    286  1.27   mjacob #define	XS_ERR(xs)		(xs)->error
    287  1.27   mjacob 
    288  1.27   mjacob #define	XS_NOERR(xs)		(xs)->error == XS_NOERROR
    289  1.27   mjacob 
    290  1.27   mjacob #define	XS_INITERR(xs)		(xs)->error = 0, XS_CMD_S_CLEAR(xs)
    291  1.27   mjacob 
    292  1.27   mjacob #define	XS_SAVE_SENSE(xs, sp)				\
    293  1.34   mjacob 	if (xs->error == XS_NOERROR) {			\
    294  1.34   mjacob 		xs->error = XS_SENSE;			\
    295  1.34   mjacob 	}						\
    296  1.44  thorpej 	memcpy(&(xs)->sense, sp->req_sense_data,	\
    297  1.27   mjacob 	    imin(XS_SNSLEN(xs), sp->req_sense_len))
    298  1.27   mjacob 
    299  1.27   mjacob #define	XS_SET_STATE_STAT(a, b, c)
    300  1.27   mjacob 
    301  1.27   mjacob #define	DEFAULT_IID(x)		7
    302  1.27   mjacob #define	DEFAULT_LOOPID(x)	108
    303  1.27   mjacob #define	DEFAULT_NODEWWN(isp)	(isp)->isp_osinfo.un._wwn
    304  1.30   mjacob #define	DEFAULT_PORTWWN(isp)	(isp)->isp_osinfo.un._wwn
    305  1.30   mjacob #define	ISP_NODEWWN(isp)	FCPARAM(isp)->isp_nodewwn
    306  1.30   mjacob #define	ISP_PORTWWN(isp)	FCPARAM(isp)->isp_portwwn
    307  1.27   mjacob 
    308  1.32   mjacob #if	_BYTE_ORDER == _BIG_ENDIAN
    309  1.47   mjacob #ifdef	ISP_SBUS_SUPPORTED
    310  1.47   mjacob #define	ISP_IOXPUT_8(isp, s, d)		*(d) = s
    311  1.47   mjacob #define	ISP_IOXPUT_16(isp, s, d)				\
    312  1.47   mjacob 	*(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap16(s)
    313  1.47   mjacob #define	ISP_IOXPUT_32(isp, s, d)				\
    314  1.47   mjacob 	*(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap32(s)
    315  1.47   mjacob 
    316  1.47   mjacob #define	ISP_IOXGET_8(isp, s, d)		d = (*((u_int8_t *)s))
    317  1.47   mjacob #define	ISP_IOXGET_16(isp, s, d)				\
    318  1.47   mjacob 	d = (isp->isp_bustype == ISP_BT_SBUS)?			\
    319  1.47   mjacob 	*((u_int16_t *)s) : bswap16(*((u_int16_t *)s))
    320  1.47   mjacob #define	ISP_IOXGET_32(isp, s, d)				\
    321  1.47   mjacob 	d = (isp->isp_bustype == ISP_BT_SBUS)?			\
    322  1.47   mjacob 	*((u_int32_t *)s) : bswap32(*((u_int32_t *)s))
    323  1.47   mjacob #else
    324  1.47   mjacob #define	ISP_IOXPUT_8(isp, s, d)		*(d) = s
    325  1.47   mjacob #define	ISP_IOXPUT_16(isp, s, d)	*(d) = bswap16(s)
    326  1.47   mjacob #define	ISP_IOXPUT_32(isp, s, d)	*(d) = bswap32(s)
    327  1.47   mjacob #define	ISP_IOXGET_8(isp, s, d)		d = (*((u_int8_t *)s))
    328  1.47   mjacob #define	ISP_IOXGET_16(isp, s, d)	d = bswap16(*((u_int16_t *)s))
    329  1.47   mjacob #define	ISP_IOXGET_32(isp, s, d)	d = bswap32(*((u_int32_t *)s))
    330  1.47   mjacob #endif
    331  1.32   mjacob #define	ISP_SWIZZLE_NVRAM_WORD(isp, rp)	*rp = bswap16(*rp)
    332   1.3   mjacob #else
    333  1.47   mjacob #define	ISP_IOXPUT_8(isp, s, d)		*(d) = s
    334  1.47   mjacob #define	ISP_IOXPUT_16(isp, s, d)	*(d) = s
    335  1.47   mjacob #define	ISP_IOXPUT_32(isp, s, d)	*(d) = s
    336  1.47   mjacob #define	ISP_IOXGET_8(isp, s, d)		d = *(s)
    337  1.47   mjacob #define	ISP_IOXGET_16(isp, s, d)	d = *(s)
    338  1.47   mjacob #define	ISP_IOXGET_32(isp, s, d)	d = *(s)
    339  1.27   mjacob #define	ISP_SWIZZLE_NVRAM_WORD(isp, rp)
    340  1.27   mjacob #endif
    341  1.27   mjacob 
    342  1.27   mjacob /*
    343  1.27   mjacob  * Includes of common header files
    344  1.27   mjacob  */
    345   1.1   mjacob 
    346  1.27   mjacob #include <dev/ic/ispreg.h>
    347  1.27   mjacob #include <dev/ic/ispvar.h>
    348  1.27   mjacob #include <dev/ic/ispmbox.h>
    349  1.39   mjacob #include <dev/ic/isp_ioctl.h>
    350  1.27   mjacob 
    351  1.27   mjacob /*
    352  1.27   mjacob  * isp_osinfo definitions, extensions and shorthand.
    353  1.27   mjacob  */
    354  1.27   mjacob #define	isp_name	isp_osinfo._dev.dv_xname
    355  1.27   mjacob #define	isp_unit	isp_osinfo._dev.dv_unit
    356  1.43   mjacob #define	isp_chanA	isp_osinfo._chan
    357  1.43   mjacob #define	isp_chanB	isp_osinfo._chan_b
    358  1.43   mjacob 
    359  1.27   mjacob 
    360  1.27   mjacob /*
    361  1.27   mjacob  * Driver prototypes..
    362  1.27   mjacob  */
    363  1.38   mjacob void isp_attach(struct ispsoftc *);
    364  1.38   mjacob void isp_uninit(struct ispsoftc *);
    365  1.27   mjacob 
    366  1.42   mjacob static INLINE void isp_lock(struct ispsoftc *);
    367  1.42   mjacob static INLINE void isp_unlock(struct ispsoftc *);
    368  1.42   mjacob static INLINE char *strncat(char *, const char *, size_t);
    369  1.42   mjacob static INLINE u_int64_t
    370  1.38   mjacob isp_microtime_sub(struct timeval *, struct timeval *);
    371  1.38   mjacob static void isp_wait_complete(struct ispsoftc *);
    372  1.27   mjacob 
    373  1.27   mjacob /*
    374  1.27   mjacob  * Driver wide data...
    375  1.27   mjacob  */
    376  1.27   mjacob 
    377  1.27   mjacob /*
    378  1.27   mjacob  * Locking macros...
    379  1.27   mjacob  */
    380  1.27   mjacob #define	ISP_LOCK		isp_lock
    381  1.27   mjacob #define	ISP_UNLOCK		isp_unlock
    382  1.29   mjacob #define	ISP_ILOCK(x)		isp_lock(x); isp->isp_osinfo.onintstack++
    383  1.29   mjacob #define	ISP_IUNLOCK(x)		isp->isp_osinfo.onintstack--; isp_unlock(x)
    384  1.27   mjacob 
    385  1.27   mjacob /*
    386  1.27   mjacob  * Platform private flags
    387  1.27   mjacob  */
    388   1.1   mjacob 
    389  1.26   mjacob #define	XS_PSTS_INWDOG		0x10000000
    390  1.26   mjacob #define	XS_PSTS_GRACE		0x20000000
    391  1.26   mjacob #define	XS_PSTS_ALL		0x30000000
    392  1.26   mjacob 
    393  1.26   mjacob #define	XS_CMD_S_WDOG(xs)	(xs)->xs_status |= XS_PSTS_INWDOG
    394  1.26   mjacob #define	XS_CMD_C_WDOG(xs)	(xs)->xs_status &= ~XS_PSTS_INWDOG
    395  1.26   mjacob #define	XS_CMD_WDOG_P(xs)	(((xs)->xs_status & XS_PSTS_INWDOG) != 0)
    396  1.26   mjacob 
    397  1.26   mjacob #define	XS_CMD_S_GRACE(xs)	(xs)->xs_status |= XS_PSTS_GRACE
    398  1.26   mjacob #define	XS_CMD_C_GRACE(xs)	(xs)->xs_status &= ~XS_PSTS_GRACE
    399  1.26   mjacob #define	XS_CMD_GRACE_P(xs)	(((xs)->xs_status & XS_PSTS_GRACE) != 0)
    400  1.26   mjacob 
    401  1.26   mjacob #define	XS_CMD_S_DONE(xs)	(xs)->xs_status |= XS_STS_DONE
    402  1.26   mjacob #define	XS_CMD_C_DONE(xs)	(xs)->xs_status &= ~XS_STS_DONE
    403  1.26   mjacob #define	XS_CMD_DONE_P(xs)	(((xs)->xs_status & XS_STS_DONE) != 0)
    404  1.26   mjacob 
    405  1.26   mjacob #define	XS_CMD_S_CLEAR(xs)	(xs)->xs_status &= ~XS_PSTS_ALL
    406  1.26   mjacob 
    407   1.1   mjacob /*
    408  1.27   mjacob  * Platform specific 'inline' or support functions
    409   1.1   mjacob  */
    410  1.42   mjacob static INLINE void
    411  1.38   mjacob isp_lock(struct ispsoftc *isp)
    412  1.27   mjacob {
    413  1.27   mjacob 	int s = splbio();
    414  1.29   mjacob 	if (isp->isp_osinfo.islocked++ == 0) {
    415  1.27   mjacob 		isp->isp_osinfo.splsaved = s;
    416  1.27   mjacob 	} else {
    417  1.27   mjacob 		splx(s);
    418  1.27   mjacob 	}
    419  1.27   mjacob }
    420   1.1   mjacob 
    421  1.42   mjacob static INLINE void
    422  1.38   mjacob isp_unlock(struct ispsoftc *isp)
    423  1.27   mjacob {
    424  1.30   mjacob 	if (isp->isp_osinfo.islocked-- <= 1) {
    425  1.27   mjacob 		isp->isp_osinfo.islocked = 0;
    426  1.27   mjacob 		splx(isp->isp_osinfo.splsaved);
    427  1.27   mjacob 	}
    428  1.27   mjacob }
    429   1.1   mjacob 
    430  1.42   mjacob static INLINE char *
    431  1.38   mjacob strncat(char *d, const char *s, size_t c)
    432  1.26   mjacob {
    433  1.26   mjacob         char *t = d;
    434  1.26   mjacob 
    435  1.26   mjacob         if (c) {
    436  1.26   mjacob                 while (*d)
    437  1.26   mjacob                         d++;
    438  1.26   mjacob                 while ((*d++ = *s++)) {
    439  1.26   mjacob                         if (--c == 0) {
    440  1.26   mjacob                                 *d = '\0';
    441  1.26   mjacob                                 break;
    442  1.26   mjacob                         }
    443  1.26   mjacob                 }
    444  1.26   mjacob         }
    445  1.26   mjacob         return (t);
    446  1.26   mjacob }
    447  1.26   mjacob 
    448  1.42   mjacob static INLINE u_int64_t
    449  1.38   mjacob isp_microtime_sub(struct timeval *b, struct timeval *a)
    450  1.27   mjacob {
    451  1.27   mjacob 	struct timeval x;
    452  1.27   mjacob 	u_int64_t elapsed;
    453  1.27   mjacob 	timersub(b, a, &x);
    454  1.27   mjacob 	elapsed = GET_NANOSEC(&x);
    455  1.27   mjacob 	if (elapsed == 0)
    456  1.27   mjacob 		elapsed++;
    457  1.27   mjacob 	return (elapsed);
    458  1.27   mjacob }
    459  1.18   mjacob 
    460  1.42   mjacob static INLINE void
    461  1.38   mjacob isp_wait_complete(struct ispsoftc *isp)
    462  1.27   mjacob {
    463  1.48   mjacob 	int lim;
    464  1.48   mjacob 	if (isp->isp_mbxwrk0)
    465  1.48   mjacob 		lim = 60;
    466  1.48   mjacob 	else
    467  1.48   mjacob 		lim = 5;
    468  1.27   mjacob 	if (isp->isp_osinfo.onintstack || isp->isp_osinfo.no_mbox_ints) {
    469  1.48   mjacob 		int useclim = 1000000 * lim, usecs = 0;
    470  1.34   mjacob 		/*
    471  1.34   mjacob 		 * For sanity's sake, we don't delay longer
    472  1.34   mjacob 		 * than 5 seconds for polled commands.
    473  1.34   mjacob 		 */
    474  1.48   mjacob 		while (usecs < useclim) {
    475  1.46   mjacob 			u_int16_t isr, sema, mbox;
    476  1.27   mjacob 			if (isp->isp_mboxbsy == 0) {
    477  1.27   mjacob 				break;
    478  1.46   mjacob 			}
    479  1.46   mjacob 			if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
    480  1.46   mjacob 				isp_intr(isp, isr, sema, mbox);
    481  1.46   mjacob 				if (isp->isp_mboxbsy == 0) {
    482  1.46   mjacob 					break;
    483  1.46   mjacob 				}
    484  1.27   mjacob 			}
    485  1.27   mjacob 			USEC_DELAY(500);
    486  1.27   mjacob 			usecs += 500;
    487  1.27   mjacob 		}
    488  1.27   mjacob 		if (isp->isp_mboxbsy != 0) {
    489  1.34   mjacob 			isp_prt(isp, ISP_LOGWARN,
    490  1.34   mjacob 			    "Polled Mailbox Command (0x%x) Timeout",
    491  1.36   mjacob 			    isp->isp_lastmbxcmd);
    492  1.27   mjacob 		}
    493  1.27   mjacob 	} else {
    494  1.27   mjacob 		int rv = 0;
    495  1.27   mjacob                 isp->isp_osinfo.mboxwaiting = 1;
    496  1.27   mjacob                 while (isp->isp_osinfo.mboxwaiting && rv == 0) {
    497  1.48   mjacob 			struct timeval dtime;
    498  1.27   mjacob 			int timo;
    499  1.27   mjacob 			struct timeval tv;
    500  1.48   mjacob 
    501  1.48   mjacob 			dtime.tv_sec = lim;
    502  1.48   mjacob 			dtime.tv_usec = 0;
    503  1.27   mjacob 			microtime(&tv);
    504  1.34   mjacob 			timeradd(&tv, &dtime, &tv);
    505  1.27   mjacob 			if ((timo = hzto(&tv)) == 0) {
    506  1.27   mjacob 				timo = 1;
    507  1.27   mjacob 			}
    508  1.27   mjacob 			rv = tsleep(&isp->isp_osinfo.mboxwaiting,
    509  1.27   mjacob 			    PRIBIO, "isp_mboxcmd", timo);
    510  1.27   mjacob 		}
    511  1.27   mjacob 		if (rv == EWOULDBLOCK) {
    512  1.27   mjacob 			isp->isp_mboxbsy = 0;
    513  1.27   mjacob 			isp->isp_osinfo.mboxwaiting = 0;
    514  1.34   mjacob 			isp_prt(isp, ISP_LOGWARN,
    515  1.34   mjacob 			    "Interrupting Mailbox Command (0x%x) Timeout",
    516  1.36   mjacob 			    isp->isp_lastmbxcmd);
    517  1.27   mjacob 		}
    518  1.27   mjacob 	}
    519  1.27   mjacob }
    520  1.32   mjacob 
    521  1.27   mjacob 
    522  1.27   mjacob /*
    523  1.27   mjacob  * Common inline functions
    524  1.27   mjacob  */
    525  1.18   mjacob #include <dev/ic/isp_inline.h>
    526  1.18   mjacob 
    527  1.19   mjacob #if	!defined(ISP_DISABLE_FW) && !defined(ISP_COMPILE_FW)
    528  1.19   mjacob #define	ISP_COMPILE_FW	1
    529  1.19   mjacob #endif
    530   1.1   mjacob #endif	/* _ISP_NETBSD_H */
    531