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