Home | History | Annotate | Line # | Download | only in ic
isp_netbsd.h revision 1.57.14.1
      1  1.57.14.1    rmind /* $NetBSD: isp_netbsd.h,v 1.57.14.1 2007/03/12 05:53:36 rmind 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.52   keihan  * 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.53    perry #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.53    perry #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.51   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.56    perry #define	INLINE			__inline
    143       1.27   mjacob 
    144       1.50   mjacob #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	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.47   mjacob 
    165       1.47   mjacob #define	MEMORYBARRIER(isp, type, offset, size)			\
    166       1.47   mjacob switch (type) {							\
    167       1.47   mjacob case SYNC_REQUEST:						\
    168       1.47   mjacob {								\
    169       1.47   mjacob 	off_t off = (off_t) offset * QENTRY_LEN;		\
    170       1.47   mjacob 	bus_dmamap_sync(isp->isp_dmatag, isp->isp_rqdmap,	\
    171       1.47   mjacob 	    off, size, BUS_DMASYNC_PREWRITE);			\
    172       1.47   mjacob 	break;							\
    173       1.47   mjacob }								\
    174       1.47   mjacob case SYNC_RESULT:						\
    175       1.47   mjacob {								\
    176       1.47   mjacob 	off_t off = (off_t) offset * QENTRY_LEN;		\
    177       1.47   mjacob 	bus_dmamap_sync(isp->isp_dmatag, isp->isp_rsdmap,	\
    178       1.47   mjacob 	    off, size, BUS_DMASYNC_POSTREAD);			\
    179       1.47   mjacob 	break;							\
    180       1.47   mjacob }								\
    181       1.47   mjacob case SYNC_SFORDEV:						\
    182       1.47   mjacob {								\
    183       1.49   mjacob 	off_t off = (off_t) offset;				\
    184       1.47   mjacob 	bus_dmamap_sync(isp->isp_dmatag, isp->isp_scdmap,	\
    185       1.47   mjacob 	    off, size, BUS_DMASYNC_PREWRITE);			\
    186       1.47   mjacob 	break;							\
    187       1.47   mjacob }								\
    188       1.47   mjacob case SYNC_SFORCPU:						\
    189       1.47   mjacob {								\
    190       1.49   mjacob 	off_t off = (off_t) offset;				\
    191       1.47   mjacob 	bus_dmamap_sync(isp->isp_dmatag, isp->isp_scdmap,	\
    192       1.47   mjacob 	    off, size, BUS_DMASYNC_POSTREAD);			\
    193       1.47   mjacob 	break;							\
    194       1.47   mjacob }								\
    195       1.47   mjacob case SYNC_REG:							\
    196       1.47   mjacob default:							\
    197       1.47   mjacob 	break;							\
    198       1.47   mjacob }
    199        1.3   mjacob 
    200       1.41   mjacob #define	MBOX_ACQUIRE(isp)						\
    201       1.41   mjacob 	if (isp->isp_osinfo.onintstack) {				\
    202       1.41   mjacob 		if (isp->isp_osinfo.mbox_locked) {			\
    203       1.41   mjacob 			mbp->param[0] = MBOX_HOST_INTERFACE_ERROR;	\
    204       1.41   mjacob 			isp_prt(isp, ISP_LOGERR, "cannot acquire MBOX lock"); \
    205       1.41   mjacob 			return;						\
    206       1.41   mjacob 		}							\
    207       1.41   mjacob 	} else {							\
    208       1.41   mjacob 		while (isp->isp_osinfo.mbox_locked) {			\
    209       1.41   mjacob 			isp->isp_osinfo.mbox_wanted = 1;		\
    210       1.41   mjacob 			(void) tsleep(&isp->isp_osinfo.mboxwaiting+1,	\
    211       1.41   mjacob 			    PRIBIO, "mbox_acquire", 0);			\
    212       1.41   mjacob 		}							\
    213       1.41   mjacob 	}								\
    214       1.41   mjacob 	isp->isp_osinfo.mbox_locked = 1
    215       1.41   mjacob 
    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.41   mjacob #define	MBOX_RELEASE(isp)						\
    226       1.41   mjacob 	if (isp->isp_osinfo.mbox_wanted) {				\
    227       1.41   mjacob 		isp->isp_osinfo.mbox_wanted = 0;			\
    228       1.41   mjacob 		wakeup(&isp->isp_osinfo.mboxwaiting+1);			\
    229       1.41   mjacob 	}								\
    230       1.41   mjacob 	isp->isp_osinfo.mbox_locked = 0
    231       1.26   mjacob 
    232       1.48   mjacob #define	FC_SCRATCH_ACQUIRE(isp)
    233       1.48   mjacob #define	FC_SCRATCH_RELEASE(isp)
    234       1.48   mjacob 
    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.40   bouyer #define	XS_CHANNEL(xs)		((int) (xs)->xs_periph->periph_channel->chan_channel)
    250       1.40   bouyer #define	XS_ISP(xs)		\
    251       1.40   bouyer 	((void *)(xs)->xs_periph->periph_channel->chan_adapter->adapt_dev)
    252       1.40   bouyer #define	XS_LUN(xs)		((int) (xs)->xs_periph->periph_lun)
    253       1.40   bouyer #define	XS_TGT(xs)		((int) (xs)->xs_periph->periph_target)
    254  1.57.14.1    rmind #define	XS_CDBP(xs)		((char *) (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.44  thorpej 	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.47   mjacob #ifdef	ISP_SBUS_SUPPORTED
    304       1.47   mjacob #define	ISP_IOXPUT_8(isp, s, d)		*(d) = s
    305       1.47   mjacob #define	ISP_IOXPUT_16(isp, s, d)				\
    306       1.47   mjacob 	*(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap16(s)
    307       1.47   mjacob #define	ISP_IOXPUT_32(isp, s, d)				\
    308       1.47   mjacob 	*(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap32(s)
    309       1.47   mjacob 
    310       1.47   mjacob #define	ISP_IOXGET_8(isp, s, d)		d = (*((u_int8_t *)s))
    311       1.47   mjacob #define	ISP_IOXGET_16(isp, s, d)				\
    312       1.47   mjacob 	d = (isp->isp_bustype == ISP_BT_SBUS)?			\
    313       1.47   mjacob 	*((u_int16_t *)s) : bswap16(*((u_int16_t *)s))
    314       1.47   mjacob #define	ISP_IOXGET_32(isp, s, d)				\
    315       1.47   mjacob 	d = (isp->isp_bustype == ISP_BT_SBUS)?			\
    316       1.47   mjacob 	*((u_int32_t *)s) : bswap32(*((u_int32_t *)s))
    317       1.47   mjacob #else
    318       1.47   mjacob #define	ISP_IOXPUT_8(isp, s, d)		*(d) = s
    319       1.47   mjacob #define	ISP_IOXPUT_16(isp, s, d)	*(d) = bswap16(s)
    320       1.47   mjacob #define	ISP_IOXPUT_32(isp, s, d)	*(d) = bswap32(s)
    321       1.47   mjacob #define	ISP_IOXGET_8(isp, s, d)		d = (*((u_int8_t *)s))
    322       1.47   mjacob #define	ISP_IOXGET_16(isp, s, d)	d = bswap16(*((u_int16_t *)s))
    323       1.47   mjacob #define	ISP_IOXGET_32(isp, s, d)	d = bswap32(*((u_int32_t *)s))
    324       1.47   mjacob #endif
    325       1.32   mjacob #define	ISP_SWIZZLE_NVRAM_WORD(isp, rp)	*rp = bswap16(*rp)
    326        1.3   mjacob #else
    327       1.47   mjacob #define	ISP_IOXPUT_8(isp, s, d)		*(d) = s
    328       1.47   mjacob #define	ISP_IOXPUT_16(isp, s, d)	*(d) = s
    329       1.47   mjacob #define	ISP_IOXPUT_32(isp, s, d)	*(d) = s
    330       1.47   mjacob #define	ISP_IOXGET_8(isp, s, d)		d = *(s)
    331       1.47   mjacob #define	ISP_IOXGET_16(isp, s, d)	d = *(s)
    332       1.47   mjacob #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.39   mjacob #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.43   mjacob #define	isp_chanA	isp_osinfo._chan
    350       1.43   mjacob #define	isp_chanB	isp_osinfo._chan_b
    351       1.43   mjacob 
    352       1.27   mjacob 
    353       1.27   mjacob /*
    354       1.27   mjacob  * Driver prototypes..
    355       1.27   mjacob  */
    356       1.38   mjacob void isp_attach(struct ispsoftc *);
    357       1.38   mjacob void isp_uninit(struct ispsoftc *);
    358       1.27   mjacob 
    359       1.42   mjacob static INLINE void isp_lock(struct ispsoftc *);
    360       1.42   mjacob static INLINE void isp_unlock(struct ispsoftc *);
    361       1.42   mjacob static INLINE char *strncat(char *, const char *, size_t);
    362       1.42   mjacob static INLINE u_int64_t
    363       1.38   mjacob isp_microtime_sub(struct timeval *, struct timeval *);
    364       1.38   mjacob static void isp_wait_complete(struct ispsoftc *);
    365       1.27   mjacob 
    366       1.27   mjacob /*
    367       1.27   mjacob  * Driver wide data...
    368       1.27   mjacob  */
    369       1.27   mjacob 
    370       1.27   mjacob /*
    371       1.27   mjacob  * Locking macros...
    372       1.27   mjacob  */
    373       1.27   mjacob #define	ISP_LOCK		isp_lock
    374       1.27   mjacob #define	ISP_UNLOCK		isp_unlock
    375       1.29   mjacob #define	ISP_ILOCK(x)		isp_lock(x); isp->isp_osinfo.onintstack++
    376       1.29   mjacob #define	ISP_IUNLOCK(x)		isp->isp_osinfo.onintstack--; isp_unlock(x)
    377       1.27   mjacob 
    378       1.53    perry /*
    379       1.53    perry  * Platform private flags
    380       1.27   mjacob  */
    381        1.1   mjacob 
    382       1.26   mjacob #define	XS_PSTS_INWDOG		0x10000000
    383       1.26   mjacob #define	XS_PSTS_GRACE		0x20000000
    384       1.26   mjacob #define	XS_PSTS_ALL		0x30000000
    385       1.26   mjacob 
    386       1.26   mjacob #define	XS_CMD_S_WDOG(xs)	(xs)->xs_status |= XS_PSTS_INWDOG
    387       1.26   mjacob #define	XS_CMD_C_WDOG(xs)	(xs)->xs_status &= ~XS_PSTS_INWDOG
    388       1.26   mjacob #define	XS_CMD_WDOG_P(xs)	(((xs)->xs_status & XS_PSTS_INWDOG) != 0)
    389       1.26   mjacob 
    390       1.26   mjacob #define	XS_CMD_S_GRACE(xs)	(xs)->xs_status |= XS_PSTS_GRACE
    391       1.26   mjacob #define	XS_CMD_C_GRACE(xs)	(xs)->xs_status &= ~XS_PSTS_GRACE
    392       1.26   mjacob #define	XS_CMD_GRACE_P(xs)	(((xs)->xs_status & XS_PSTS_GRACE) != 0)
    393       1.26   mjacob 
    394       1.26   mjacob #define	XS_CMD_S_DONE(xs)	(xs)->xs_status |= XS_STS_DONE
    395       1.26   mjacob #define	XS_CMD_C_DONE(xs)	(xs)->xs_status &= ~XS_STS_DONE
    396       1.26   mjacob #define	XS_CMD_DONE_P(xs)	(((xs)->xs_status & XS_STS_DONE) != 0)
    397       1.26   mjacob 
    398       1.26   mjacob #define	XS_CMD_S_CLEAR(xs)	(xs)->xs_status &= ~XS_PSTS_ALL
    399       1.26   mjacob 
    400        1.1   mjacob /*
    401       1.27   mjacob  * Platform specific 'inline' or support functions
    402        1.1   mjacob  */
    403       1.42   mjacob static INLINE void
    404       1.38   mjacob isp_lock(struct ispsoftc *isp)
    405       1.27   mjacob {
    406       1.27   mjacob 	int s = splbio();
    407       1.29   mjacob 	if (isp->isp_osinfo.islocked++ == 0) {
    408       1.27   mjacob 		isp->isp_osinfo.splsaved = s;
    409       1.27   mjacob 	} else {
    410       1.27   mjacob 		splx(s);
    411       1.27   mjacob 	}
    412       1.27   mjacob }
    413        1.1   mjacob 
    414       1.42   mjacob static INLINE void
    415       1.38   mjacob isp_unlock(struct ispsoftc *isp)
    416       1.27   mjacob {
    417       1.30   mjacob 	if (isp->isp_osinfo.islocked-- <= 1) {
    418       1.27   mjacob 		isp->isp_osinfo.islocked = 0;
    419       1.27   mjacob 		splx(isp->isp_osinfo.splsaved);
    420       1.27   mjacob 	}
    421       1.27   mjacob }
    422        1.1   mjacob 
    423       1.42   mjacob static INLINE char *
    424       1.38   mjacob strncat(char *d, const char *s, size_t c)
    425       1.26   mjacob {
    426       1.26   mjacob         char *t = d;
    427       1.26   mjacob 
    428       1.26   mjacob         if (c) {
    429       1.26   mjacob                 while (*d)
    430       1.26   mjacob                         d++;
    431       1.26   mjacob                 while ((*d++ = *s++)) {
    432       1.26   mjacob                         if (--c == 0) {
    433       1.26   mjacob                                 *d = '\0';
    434       1.26   mjacob                                 break;
    435       1.26   mjacob                         }
    436       1.26   mjacob                 }
    437       1.26   mjacob         }
    438       1.26   mjacob         return (t);
    439       1.26   mjacob }
    440       1.26   mjacob 
    441       1.42   mjacob static INLINE u_int64_t
    442       1.38   mjacob isp_microtime_sub(struct timeval *b, struct timeval *a)
    443       1.27   mjacob {
    444       1.27   mjacob 	struct timeval x;
    445       1.27   mjacob 	u_int64_t elapsed;
    446       1.27   mjacob 	timersub(b, a, &x);
    447       1.27   mjacob 	elapsed = GET_NANOSEC(&x);
    448       1.27   mjacob 	if (elapsed == 0)
    449       1.27   mjacob 		elapsed++;
    450       1.27   mjacob 	return (elapsed);
    451       1.27   mjacob }
    452       1.18   mjacob 
    453       1.42   mjacob static INLINE void
    454       1.38   mjacob isp_wait_complete(struct ispsoftc *isp)
    455       1.27   mjacob {
    456       1.48   mjacob 	int lim;
    457       1.48   mjacob 	if (isp->isp_mbxwrk0)
    458       1.48   mjacob 		lim = 60;
    459       1.48   mjacob 	else
    460       1.48   mjacob 		lim = 5;
    461       1.51   mjacob 	if (ISP_MUSTPOLL(isp)) {
    462       1.48   mjacob 		int useclim = 1000000 * lim, usecs = 0;
    463       1.34   mjacob 		/*
    464       1.34   mjacob 		 * For sanity's sake, we don't delay longer
    465       1.34   mjacob 		 * than 5 seconds for polled commands.
    466       1.34   mjacob 		 */
    467       1.48   mjacob 		while (usecs < useclim) {
    468       1.46   mjacob 			u_int16_t isr, sema, mbox;
    469       1.27   mjacob 			if (isp->isp_mboxbsy == 0) {
    470       1.27   mjacob 				break;
    471       1.46   mjacob 			}
    472       1.46   mjacob 			if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
    473       1.46   mjacob 				isp_intr(isp, isr, sema, mbox);
    474       1.46   mjacob 				if (isp->isp_mboxbsy == 0) {
    475       1.46   mjacob 					break;
    476       1.46   mjacob 				}
    477       1.27   mjacob 			}
    478       1.27   mjacob 			USEC_DELAY(500);
    479       1.27   mjacob 			usecs += 500;
    480       1.27   mjacob 		}
    481       1.27   mjacob 		if (isp->isp_mboxbsy != 0) {
    482       1.34   mjacob 			isp_prt(isp, ISP_LOGWARN,
    483       1.34   mjacob 			    "Polled Mailbox Command (0x%x) Timeout",
    484       1.36   mjacob 			    isp->isp_lastmbxcmd);
    485       1.27   mjacob 		}
    486       1.27   mjacob 	} else {
    487       1.27   mjacob 		int rv = 0;
    488       1.27   mjacob                 isp->isp_osinfo.mboxwaiting = 1;
    489       1.27   mjacob                 while (isp->isp_osinfo.mboxwaiting && rv == 0) {
    490       1.48   mjacob 			struct timeval dtime;
    491       1.27   mjacob 			int timo;
    492       1.27   mjacob 			struct timeval tv;
    493       1.48   mjacob 
    494       1.48   mjacob 			dtime.tv_sec = lim;
    495       1.48   mjacob 			dtime.tv_usec = 0;
    496       1.27   mjacob 			microtime(&tv);
    497       1.34   mjacob 			timeradd(&tv, &dtime, &tv);
    498       1.27   mjacob 			if ((timo = hzto(&tv)) == 0) {
    499       1.27   mjacob 				timo = 1;
    500       1.27   mjacob 			}
    501       1.27   mjacob 			rv = tsleep(&isp->isp_osinfo.mboxwaiting,
    502       1.27   mjacob 			    PRIBIO, "isp_mboxcmd", timo);
    503       1.27   mjacob 		}
    504       1.27   mjacob 		if (rv == EWOULDBLOCK) {
    505       1.27   mjacob 			isp->isp_mboxbsy = 0;
    506       1.27   mjacob 			isp->isp_osinfo.mboxwaiting = 0;
    507       1.34   mjacob 			isp_prt(isp, ISP_LOGWARN,
    508       1.34   mjacob 			    "Interrupting Mailbox Command (0x%x) Timeout",
    509       1.36   mjacob 			    isp->isp_lastmbxcmd);
    510       1.27   mjacob 		}
    511       1.27   mjacob 	}
    512       1.27   mjacob }
    513       1.32   mjacob 
    514       1.27   mjacob 
    515       1.27   mjacob /*
    516       1.27   mjacob  * Common inline functions
    517       1.27   mjacob  */
    518       1.18   mjacob #include <dev/ic/isp_inline.h>
    519       1.18   mjacob 
    520       1.19   mjacob #if	!defined(ISP_DISABLE_FW) && !defined(ISP_COMPILE_FW)
    521       1.19   mjacob #define	ISP_COMPILE_FW	1
    522       1.19   mjacob #endif
    523        1.1   mjacob #endif	/* _ISP_NETBSD_H */
    524