Home | History | Annotate | Line # | Download | only in ic
isp_netbsd.h revision 1.26
      1  1.26   mjacob /* $NetBSD: isp_netbsd.h,v 1.26 2000/07/05 22:25:06 mjacob Exp $ */
      2   1.1   mjacob /*
      3   1.1   mjacob  * NetBSD Specific definitions for the Qlogic ISP Host Adapter
      4  1.15   mjacob  * Matthew Jacob <mjacob (at) nas.nasa.gov>
      5  1.15   mjacob  */
      6  1.15   mjacob /*
      7  1.15   mjacob  * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
      8   1.1   mjacob  * All rights reserved.
      9   1.1   mjacob  *
     10   1.1   mjacob  * Redistribution and use in source and binary forms, with or without
     11   1.1   mjacob  * modification, are permitted provided that the following conditions
     12   1.1   mjacob  * are met:
     13   1.1   mjacob  * 1. Redistributions of source code must retain the above copyright
     14  1.15   mjacob  *    notice, this list of conditions and the following disclaimer.
     15   1.1   mjacob  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1   mjacob  *    notice, this list of conditions and the following disclaimer in the
     17   1.1   mjacob  *    documentation and/or other materials provided with the distribution.
     18   1.1   mjacob  * 3. The name of the author may not be used to endorse or promote products
     19  1.15   mjacob  *    derived from this software without specific prior written permission
     20   1.1   mjacob  *
     21  1.15   mjacob  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.15   mjacob  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.15   mjacob  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.15   mjacob  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.15   mjacob  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.15   mjacob  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.15   mjacob  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.15   mjacob  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.15   mjacob  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.15   mjacob  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31   1.1   mjacob  */
     32   1.1   mjacob #ifndef	_ISP_NETBSD_H
     33   1.1   mjacob #define	_ISP_NETBSD_H
     34   1.1   mjacob 
     35   1.1   mjacob #include <sys/types.h>
     36   1.1   mjacob #include <sys/param.h>
     37   1.1   mjacob #include <sys/systm.h>
     38   1.1   mjacob #include <sys/kernel.h>
     39   1.1   mjacob #include <sys/errno.h>
     40   1.1   mjacob #include <sys/ioctl.h>
     41   1.1   mjacob #include <sys/device.h>
     42   1.1   mjacob #include <sys/malloc.h>
     43   1.1   mjacob #include <sys/buf.h>
     44   1.1   mjacob #include <sys/proc.h>
     45   1.1   mjacob #include <sys/user.h>
     46   1.1   mjacob 
     47   1.1   mjacob 
     48   1.1   mjacob #include <dev/scsipi/scsi_all.h>
     49   1.1   mjacob #include <dev/scsipi/scsipi_all.h>
     50   1.1   mjacob #include <dev/scsipi/scsiconf.h>
     51   1.1   mjacob 
     52   1.1   mjacob #include <dev/scsipi/scsi_message.h>
     53   1.1   mjacob #include <dev/scsipi/scsipi_debug.h>
     54   1.1   mjacob 
     55  1.15   mjacob #include "opt_isp.h"
     56  1.26   mjacob /*
     57  1.26   mjacob  * We always support fabric now
     58  1.26   mjacob  */
     59  1.26   mjacob #ifndef	ISP2100_FABRIC
     60  1.26   mjacob #define	ISP2100_FABRIC
     61  1.26   mjacob #endif
     62  1.26   mjacob 
     63  1.15   mjacob 
     64   1.2   mjacob #define	ISP_PLATFORM_VERSION_MAJOR	0
     65  1.26   mjacob #define	ISP_PLATFORM_VERSION_MINOR	998
     66   1.1   mjacob 
     67   1.1   mjacob #define	ISP_SCSI_XFER_T		struct scsipi_xfer
     68   1.1   mjacob struct isposinfo {
     69   1.1   mjacob 	struct device		_dev;
     70   1.1   mjacob 	struct scsipi_link	_link;
     71  1.14   mjacob 	struct scsipi_link	_link_b;
     72   1.6   mjacob 	struct scsipi_adapter   _adapter;
     73  1.10   mjacob 	int			blocked;
     74  1.18   mjacob 	union {
     75  1.18   mjacob 		int		_seed;
     76  1.18   mjacob 		u_int16_t	_discovered[2];
     77  1.18   mjacob 	} un;
     78  1.18   mjacob #define	seed		un._seed
     79  1.18   mjacob #define	discovered	un._discovered
     80  1.10   mjacob 	TAILQ_HEAD(, scsipi_xfer) waitq;
     81  1.23  thorpej 	struct callout _restart;
     82   1.1   mjacob };
     83  1.18   mjacob 
     84   1.1   mjacob #define	MAXISPREQUEST	256
     85  1.15   mjacob #ifdef	ISP2100_FABRIC
     86  1.15   mjacob #define	ISP2100_SCRLEN		0x400
     87  1.15   mjacob #else
     88  1.15   mjacob #define	ISP2100_SCRLEN		0x100
     89  1.15   mjacob #endif
     90   1.1   mjacob 
     91   1.1   mjacob #include <dev/ic/ispreg.h>
     92   1.1   mjacob #include <dev/ic/ispvar.h>
     93   1.1   mjacob #include <dev/ic/ispmbox.h>
     94   1.1   mjacob 
     95  1.19   mjacob #define	IDPRINTF(lev, x)	if (isp->isp_dblev >= lev) printf x
     96   1.1   mjacob #define	PRINTF			printf
     97   1.8   mjacob 
     98   1.8   mjacob #define	MEMZERO			bzero
     99   1.9   mjacob #define	MEMCPY(dst, src, count)	bcopy((src), (dst), (count))
    100  1.11   mjacob #ifdef	__alpha__
    101  1.11   mjacob #define	MemoryBarrier	alpha_mb
    102  1.11   mjacob #else
    103  1.11   mjacob #define	MemoryBarrier()
    104  1.11   mjacob #endif
    105   1.3   mjacob 
    106  1.13   mjacob #define	DMA_MSW(x)	(((x) >> 16) & 0xffff)
    107  1.13   mjacob #define	DMA_LSW(x)	(((x) & 0xffff))
    108  1.13   mjacob 
    109   1.3   mjacob #if	defined(SCSIDEBUG)
    110   1.3   mjacob #define	DFLT_DBLEVEL		3
    111  1.18   mjacob #define	CFGPRINTF		printf
    112  1.19   mjacob #elif	defined(DEBUG)
    113  1.19   mjacob #define	DFLT_DBLEVEL		2
    114  1.19   mjacob #define	CFGPRINTF		printf
    115  1.19   mjacob #elif	defined(DIAGNOSTIC)
    116  1.18   mjacob #define	DFLT_DBLEVEL		1
    117  1.21   mjacob #define	CFGPRINTF		printf
    118   1.1   mjacob #else
    119  1.18   mjacob #define	DFLT_DBLEVEL		0
    120  1.18   mjacob #define	CFGPRINTF		if (0) printf
    121   1.1   mjacob #endif
    122   1.1   mjacob 
    123   1.1   mjacob #define	ISP_LOCKVAL_DECL	int isp_spl_save
    124   1.7   mjacob #define	ISP_ILOCKVAL_DECL	ISP_LOCKVAL_DECL
    125   1.1   mjacob #define	ISP_LOCK(x)		isp_spl_save = splbio()
    126   1.1   mjacob #define	ISP_UNLOCK(x)		(void) splx(isp_spl_save)
    127   1.1   mjacob #define	ISP_ILOCK		ISP_LOCK
    128   1.1   mjacob #define	ISP_IUNLOCK		ISP_UNLOCK
    129   1.1   mjacob 
    130  1.26   mjacob #define	MBOX_WAIT_COMPLETE(isp)		\
    131  1.26   mjacob 	{ \
    132  1.26   mjacob 		int j; \
    133  1.26   mjacob 		for (j = 0; j < 60 * 2000; j++) { \
    134  1.26   mjacob 			if (isp_intr(isp) == 0) { \
    135  1.26   mjacob 				SYS_DELAY(500); \
    136  1.26   mjacob 			} \
    137  1.26   mjacob 			if (isp->isp_mboxbsy == 0) \
    138  1.26   mjacob 				break; \
    139  1.26   mjacob 		} \
    140  1.26   mjacob 		if (isp->isp_mboxbsy != 0) \
    141  1.26   mjacob 			printf("%s: mailbox timeout\n", isp->isp_name); \
    142  1.26   mjacob 	}
    143  1.26   mjacob 
    144  1.26   mjacob #define	MBOX_NOTIFY_COMPLETE(isp)	isp->isp_mboxbsy = 0
    145  1.26   mjacob 
    146   1.1   mjacob 
    147   1.1   mjacob #define	XS_NULL(xs)		xs == NULL || xs->sc_link == NULL
    148   1.1   mjacob #define	XS_ISP(xs)		(xs)->sc_link->adapter_softc
    149  1.11   mjacob #define	XS_LUN(xs)		((int) (xs)->sc_link->scsipi_scsi.lun)
    150  1.11   mjacob #define	XS_TGT(xs)		((int) (xs)->sc_link->scsipi_scsi.target)
    151  1.14   mjacob #define	XS_CHANNEL(xs)		\
    152  1.20   mjacob 	(((int) (xs)->sc_link->scsipi_scsi.channel == SCSI_CHANNEL_ONLY_ONE) ? \
    153  1.20   mjacob 	    0 : (xs)->sc_link->scsipi_scsi.channel)
    154   1.1   mjacob #define	XS_RESID(xs)		(xs)->resid
    155   1.1   mjacob #define	XS_XFRLEN(xs)		(xs)->datalen
    156   1.1   mjacob #define	XS_CDBLEN(xs)		(xs)->cmdlen
    157  1.14   mjacob #define	XS_CDBP(xs)		((caddr_t) (xs)->cmd)
    158   1.1   mjacob #define	XS_STS(xs)		(xs)->status
    159   1.1   mjacob #define	XS_TIME(xs)		(xs)->timeout
    160   1.1   mjacob #define	XS_SNSP(xs)		(&(xs)->sense.scsi_sense)
    161   1.1   mjacob #define	XS_SNSLEN(xs)		(sizeof (xs)->sense.scsi_sense)
    162   1.1   mjacob #define	XS_SNSKEY(xs)		((xs)->sense.scsi_sense.flags)
    163   1.1   mjacob 
    164   1.1   mjacob #define	HBA_NOERROR		XS_NOERROR
    165   1.1   mjacob #define	HBA_BOTCH		XS_DRIVER_STUFFUP
    166   1.1   mjacob #define	HBA_CMDTIMEOUT		XS_TIMEOUT
    167   1.1   mjacob #define	HBA_SELTIMEOUT		XS_SELTIMEOUT
    168   1.1   mjacob #define	HBA_TGTBSY		XS_BUSY
    169   1.3   mjacob #ifdef	XS_RESET
    170   1.3   mjacob #define	HBA_BUSRESET		XS_RESET
    171   1.3   mjacob #else
    172   1.1   mjacob #define	HBA_BUSRESET		XS_DRIVER_STUFFUP
    173   1.3   mjacob #endif
    174   1.1   mjacob #define	HBA_ABORTED		XS_DRIVER_STUFFUP
    175   1.1   mjacob #define	HBA_DATAOVR		XS_DRIVER_STUFFUP
    176   1.1   mjacob #define	HBA_ARQFAIL		XS_DRIVER_STUFFUP
    177   1.1   mjacob 
    178   1.1   mjacob #define	XS_SNS_IS_VALID(xs)	(xs)->error = XS_SENSE
    179   1.1   mjacob #define	XS_IS_SNS_VALID(xs)	((xs)->error == XS_SENSE)
    180   1.1   mjacob 
    181  1.26   mjacob #define	XS_PSTS_INWDOG		0x10000000
    182  1.26   mjacob #define	XS_PSTS_GRACE		0x20000000
    183  1.26   mjacob #define	XS_PSTS_ALL		0x30000000
    184  1.26   mjacob 
    185  1.26   mjacob #define	XS_CMD_S_WDOG(xs)	(xs)->xs_status |= XS_PSTS_INWDOG
    186  1.26   mjacob #define	XS_CMD_C_WDOG(xs)	(xs)->xs_status &= ~XS_PSTS_INWDOG
    187  1.26   mjacob #define	XS_CMD_WDOG_P(xs)	(((xs)->xs_status & XS_PSTS_INWDOG) != 0)
    188  1.26   mjacob 
    189  1.26   mjacob #define	XS_CMD_S_GRACE(xs)	(xs)->xs_status |= XS_PSTS_GRACE
    190  1.26   mjacob #define	XS_CMD_C_GRACE(xs)	(xs)->xs_status &= ~XS_PSTS_GRACE
    191  1.26   mjacob #define	XS_CMD_GRACE_P(xs)	(((xs)->xs_status & XS_PSTS_GRACE) != 0)
    192  1.26   mjacob 
    193  1.26   mjacob #define	XS_CMD_S_DONE(xs)	(xs)->xs_status |= XS_STS_DONE
    194  1.26   mjacob #define	XS_CMD_C_DONE(xs)	(xs)->xs_status &= ~XS_STS_DONE
    195  1.26   mjacob #define	XS_CMD_DONE_P(xs)	(((xs)->xs_status & XS_STS_DONE) != 0)
    196  1.26   mjacob 
    197  1.26   mjacob #define	XS_CMD_S_CLEAR(xs)	(xs)->xs_status &= ~XS_PSTS_ALL
    198  1.26   mjacob 
    199  1.26   mjacob #define	XS_INITERR(xs)		(xs)->error = 0, XS_CMD_S_CLEAR(xs)
    200   1.1   mjacob #define	XS_SETERR(xs, v)	(xs)->error = v
    201   1.1   mjacob #define	XS_ERR(xs)		(xs)->error
    202   1.1   mjacob #define	XS_NOERR(xs)		(xs)->error == XS_NOERROR
    203   1.1   mjacob 
    204  1.26   mjacob #define	XS_CMD_DONE		isp_done
    205   1.1   mjacob 
    206   1.1   mjacob /*
    207   1.1   mjacob  * We use whether or not we're a polled command to decide about tagging.
    208   1.1   mjacob  */
    209  1.17  thorpej #define	XS_CANTAG(xs)		(((xs)->xs_control & XS_CTL_POLL) != 0)
    210   1.1   mjacob 
    211   1.1   mjacob /*
    212  1.16   mjacob  * This is our default tag (simple).
    213   1.1   mjacob  */
    214   1.1   mjacob #define	XS_KINDOF_TAG(xs)	\
    215  1.17  thorpej 	(((xs)->xs_control & XS_CTL_URGENT) ? REQFLAG_HTAG : REQFLAG_OTAG)
    216   1.1   mjacob 
    217  1.18   mjacob /*
    218  1.18   mjacob  * These get turned into NetBSD midlayer codes
    219  1.18   mjacob  */
    220  1.18   mjacob #define	CMD_COMPLETE		100
    221  1.18   mjacob #define	CMD_EAGAIN		101
    222  1.18   mjacob #define	CMD_QUEUED		102
    223  1.18   mjacob #define	CMD_RQLATER		103
    224   1.1   mjacob 
    225   1.1   mjacob 
    226   1.1   mjacob #define	isp_name	isp_osinfo._dev.dv_xname
    227  1.15   mjacob #define	isp_unit	isp_osinfo._dev.dv_unit
    228   1.1   mjacob 
    229  1.14   mjacob #define	SCSI_QFULL	0x28
    230  1.14   mjacob 
    231   1.1   mjacob #define	SYS_DELAY(x)	delay(x)
    232   1.1   mjacob 
    233   1.7   mjacob #define	WATCH_INTERVAL	30
    234   1.1   mjacob 
    235  1.11   mjacob #define	FC_FW_READY_DELAY	(12 * 1000000)
    236  1.15   mjacob #define	DEFAULT_LOOPID(x)	108
    237  1.15   mjacob #define	DEFAULT_WWN(x)		(0x1000beed00000000LL + (x)->isp_osinfo.seed)
    238  1.11   mjacob 
    239   1.1   mjacob extern void isp_attach __P((struct ispsoftc *));
    240   1.7   mjacob extern void isp_uninit __P((struct ispsoftc *));
    241  1.11   mjacob 
    242  1.18   mjacob #define ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src)	\
    243  1.18   mjacob         bcopy(src, dest, sizeof (isp_pdb_t))
    244  1.18   mjacob #define ISP_SWIZZLE_ICB(a, b)
    245  1.18   mjacob #ifdef	__sparc__
    246  1.22   mjacob #define	ISP_SWIZZLE_CONTINUATION(a, b)	ISP_SBUSIFY_ISPHDR(a, &(b)->req_header)
    247  1.18   mjacob #define ISP_SWIZZLE_REQUEST(a, b)			\
    248  1.18   mjacob 	ISP_SBUSIFY_ISPHDR(a, &(b)->req_header);	\
    249  1.18   mjacob         ISP_SBUSIFY_ISPREQ(a, b)
    250  1.18   mjacob #define ISP_UNSWIZZLE_RESPONSE(a, b)			\
    251  1.18   mjacob 	ISP_SBUSIFY_ISPHDR(a, &(b)->req_header)
    252  1.18   mjacob #else
    253  1.22   mjacob #define	ISP_SWIZZLE_CONTINUATION(a, b)
    254  1.18   mjacob #define ISP_SWIZZLE_REQUEST(a, b)
    255  1.18   mjacob #define ISP_UNSWIZZLE_RESPONSE(a, b)
    256  1.18   mjacob #endif
    257  1.18   mjacob #define	ISP_SWIZZLE_SNS_REQ(a, b)
    258  1.18   mjacob #define	ISP_UNSWIZZLE_SNS_RSP(a, b, c)
    259  1.26   mjacob 
    260  1.26   mjacob extern void isp_done	__P((ISP_SCSI_XFER_T *));
    261  1.26   mjacob #define	STRNCAT			strncat
    262  1.26   mjacob static inline char *strncat(char *, const char *, size_t);
    263  1.26   mjacob static inline char *
    264  1.26   mjacob strncat(char *d, const char *s, size_t c)
    265  1.26   mjacob {
    266  1.26   mjacob         char *t = d;
    267  1.26   mjacob 
    268  1.26   mjacob         if (c) {
    269  1.26   mjacob                 while (*d)
    270  1.26   mjacob                         d++;
    271  1.26   mjacob                 while ((*d++ = *s++)) {
    272  1.26   mjacob                         if (--c == 0) {
    273  1.26   mjacob                                 *d = '\0';
    274  1.26   mjacob                                 break;
    275  1.26   mjacob                         }
    276  1.26   mjacob                 }
    277  1.26   mjacob         }
    278  1.26   mjacob         return (t);
    279  1.26   mjacob }
    280  1.26   mjacob 
    281  1.18   mjacob 
    282  1.18   mjacob #define	INLINE	inline
    283  1.18   mjacob #include <dev/ic/isp_inline.h>
    284  1.18   mjacob 
    285  1.19   mjacob #if	!defined(ISP_DISABLE_FW) && !defined(ISP_COMPILE_FW)
    286  1.19   mjacob #define	ISP_COMPILE_FW	1
    287  1.19   mjacob #endif
    288   1.1   mjacob #endif	/* _ISP_NETBSD_H */
    289