Home | History | Annotate | Line # | Download | only in ic
isp_netbsd.h revision 1.31
      1 /* $NetBSD: isp_netbsd.h,v 1.31 2000/11/14 18:35:10 thorpej Exp $ */
      2 /*
      3  * This driver, which is contained in NetBSD in the files:
      4  *
      5  *	sys/dev/ic/isp.c
      6  *	sys/dev/ic/ic/isp.c
      7  *	sys/dev/ic/ic/isp_inline.h
      8  *	sys/dev/ic/ic/isp_netbsd.c
      9  *	sys/dev/ic/ic/isp_netbsd.h
     10  *	sys/dev/ic/ic/isp_target.c
     11  *	sys/dev/ic/ic/isp_target.h
     12  *	sys/dev/ic/ic/isp_tpublic.h
     13  *	sys/dev/ic/ic/ispmbox.h
     14  *	sys/dev/ic/ic/ispreg.h
     15  *	sys/dev/ic/ic/ispvar.h
     16  *	sys/microcode/isp/asm_sbus.h
     17  *	sys/microcode/isp/asm_1040.h
     18  *	sys/microcode/isp/asm_1080.h
     19  *	sys/microcode/isp/asm_12160.h
     20  *	sys/microcode/isp/asm_2100.h
     21  *	sys/microcode/isp/asm_2200.h
     22  *	sys/pci/isp_pci.c
     23  *	sys/sbus/isp_sbus.c
     24  *
     25  * Is being actively maintained by Matthew Jacob (mjacob (at) netbsd.org).
     26  * This driver also is shared source with FreeBSD, OpenBSD, Linux, Solaris,
     27  * Linux versions. This tends to be an interesting maintenance problem.
     28  *
     29  * Please coordinate with Matthew Jacob on changes you wish to make here.
     30  */
     31 /*
     32  * NetBSD Specific definitions for the Qlogic ISP Host Adapter
     33  * Matthew Jacob <mjacob (at) nas.nasa.gov>
     34  */
     35 /*
     36  * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
     37  * All rights reserved.
     38  *
     39  * Redistribution and use in source and binary forms, with or without
     40  * modification, are permitted provided that the following conditions
     41  * are met:
     42  * 1. Redistributions of source code must retain the above copyright
     43  *    notice, this list of conditions and the following disclaimer.
     44  * 2. Redistributions in binary form must reproduce the above copyright
     45  *    notice, this list of conditions and the following disclaimer in the
     46  *    documentation and/or other materials provided with the distribution.
     47  * 3. The name of the author may not be used to endorse or promote products
     48  *    derived from this software without specific prior written permission
     49  *
     50  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     51  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     52  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     53  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     54  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     55  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     56  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     57  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     58  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     59  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     60  */
     61 #ifndef	_ISP_NETBSD_H
     62 #define	_ISP_NETBSD_H
     63 
     64 #include <sys/types.h>
     65 #include <sys/param.h>
     66 #include <sys/systm.h>
     67 #include <sys/kernel.h>
     68 #include <sys/errno.h>
     69 #include <sys/ioctl.h>
     70 #include <sys/device.h>
     71 #include <sys/malloc.h>
     72 #include <sys/buf.h>
     73 #include <sys/proc.h>
     74 #include <sys/user.h>
     75 
     76 #include <uvm/uvm_extern.h>
     77 
     78 #include <dev/scsipi/scsi_all.h>
     79 #include <dev/scsipi/scsipi_all.h>
     80 #include <dev/scsipi/scsiconf.h>
     81 
     82 #include <dev/scsipi/scsi_message.h>
     83 #include <dev/scsipi/scsipi_debug.h>
     84 
     85 #include "opt_isp.h"
     86 
     87 
     88 #define	ISP_PLATFORM_VERSION_MAJOR	1
     89 #define	ISP_PLATFORM_VERSION_MINOR	0
     90 
     91 struct isposinfo {
     92 	struct device		_dev;
     93 	struct scsipi_link	_link;
     94 	struct scsipi_link	_link_b;
     95 	struct scsipi_adapter   _adapter;
     96 	int	splsaved;
     97 	int	mboxwaiting;
     98 	u_int32_t	islocked;
     99 	u_int32_t	onintstack;
    100 	unsigned int		: 30,
    101 		no_mbox_ints	: 1,
    102 		blocked		: 1;
    103 	union {
    104 		u_int64_t	_wwn;
    105 		u_int16_t	_discovered[2];
    106 #define	wwn_seed	un._wwn
    107 #define	discovered	un._discovered
    108 	} un;
    109 	TAILQ_HEAD(, scsipi_xfer) waitq;
    110 	struct callout _restart;
    111 };
    112 
    113 /*
    114  * Required Macros/Defines
    115  */
    116 
    117 #define	INLINE			inline
    118 
    119 #define	ISP2100_FABRIC		1
    120 #define	ISP2100_SCRLEN		0x400
    121 
    122 #define	MEMZERO			bzero
    123 #define	MEMCPY(dst, src, amt)	bcopy((src), (dst), (amt))
    124 #define	SNPRINTF		snprintf
    125 #define	STRNCAT			strncat
    126 #define	USEC_DELAY		DELAY
    127 
    128 #define	NANOTIME_T		struct timeval
    129 #define	GET_NANOTIME		microtime
    130 #define	GET_NANOSEC(x)		(((x)->tv_sec * 1000000 + (x)->tv_usec) * 1000)
    131 #define	NANOTIME_SUB		isp_microtime_sub
    132 
    133 #define	MAXISPREQUEST(isp)	256
    134 
    135 #ifdef	__alpha__
    136 #define	MEMORYBARRIER(isp, type, offset, size)	alpha_mb()
    137 #else
    138 #define	MEMORYBARRIER(isp, type, offset, size)
    139 #endif
    140 
    141 #define	MBOX_ACQUIRE(isp)
    142 #define	MBOX_WAIT_COMPLETE	isp_wait_complete
    143 
    144 #define	MBOX_NOTIFY_COMPLETE(isp)					\
    145 	if (isp->isp_osinfo.mboxwaiting) {				\
    146                 isp->isp_osinfo.mboxwaiting = 0;			\
    147                 wakeup(&isp->isp_osinfo.mboxwaiting);			\
    148         }								\
    149 	isp->isp_mboxbsy = 0
    150 
    151 #define	MBOX_RELEASE(isp)
    152 
    153 #ifndef	SCSI_GOOD
    154 #define	SCSI_GOOD	0x0
    155 #endif
    156 #ifndef	SCSI_CHECK
    157 #define	SCSI_CHECK	0x2
    158 #endif
    159 #ifndef	SCSI_BUSY
    160 #define	SCSI_BUSY	0x8
    161 #endif
    162 #ifndef	SCSI_QFULL
    163 #define	SCSI_QFULL	0x28
    164 #endif
    165 
    166 #define	XS_T			struct scsipi_xfer
    167 #define	XS_CHANNEL(xs)		\
    168 	(((int) (xs)->sc_link->scsipi_scsi.channel == SCSI_CHANNEL_ONLY_ONE) ? \
    169 	    0 : (xs)->sc_link->scsipi_scsi.channel)
    170 #define	XS_ISP(xs)		(xs)->sc_link->adapter_softc
    171 #define	XS_LUN(xs)		((int) (xs)->sc_link->scsipi_scsi.lun)
    172 #define	XS_TGT(xs)		((int) (xs)->sc_link->scsipi_scsi.target)
    173 #define	XS_CDBP(xs)		((caddr_t) (xs)->cmd)
    174 #define	XS_CDBLEN(xs)		(xs)->cmdlen
    175 #define	XS_XFRLEN(xs)		(xs)->datalen
    176 #define	XS_TIME(xs)		(xs)->timeout
    177 #define	XS_RESID(xs)		(xs)->resid
    178 #define	XS_STSP(xs)		(&(xs)->status)
    179 #define	XS_SNSP(xs)		(&(xs)->sense.scsi_sense)
    180 #define	XS_SNSLEN(xs)		(sizeof (xs)->sense)
    181 #define	XS_SNSKEY(xs)		((xs)->sense.scsi_sense.flags)
    182 #define	XS_TAG_P(ccb)		(((xs)->xs_control & XS_CTL_POLL) != 0)
    183 #define	XS_TAG_TYPE(xs)	\
    184 	(((xs)->xs_control & XS_CTL_URGENT) ? REQFLAG_HTAG : \
    185 	((xs)->bp && xs->bp->b_flags & B_ASYNC) ? REQFLAG_STAG : REQFLAG_OTAG)
    186 
    187 #define	XS_SETERR(xs, v)	(xs)->error = v
    188 
    189 #	define	HBA_NOERROR		XS_NOERROR
    190 #	define	HBA_BOTCH		XS_DRIVER_STUFFUP
    191 #	define	HBA_CMDTIMEOUT		XS_TIMEOUT
    192 #	define	HBA_SELTIMEOUT		XS_SELTIMEOUT
    193 #	define	HBA_TGTBSY		XS_BUSY
    194 #	define	HBA_BUSRESET		XS_RESET
    195 #	define	HBA_ABORTED		XS_DRIVER_STUFFUP
    196 #	define	HBA_DATAOVR		XS_DRIVER_STUFFUP
    197 #	define	HBA_ARQFAIL		XS_DRIVER_STUFFUP
    198 
    199 #define	XS_ERR(xs)		(xs)->error
    200 
    201 #define	XS_NOERR(xs)		(xs)->error == XS_NOERROR
    202 
    203 #define	XS_INITERR(xs)		(xs)->error = 0, XS_CMD_S_CLEAR(xs)
    204 
    205 #define	XS_SAVE_SENSE(xs, sp)				\
    206 	bcopy(sp->req_sense_data, &(xs)->sense,		\
    207 	    imin(XS_SNSLEN(xs), sp->req_sense_len))
    208 
    209 #define	XS_SET_STATE_STAT(a, b, c)
    210 
    211 #define	DEFAULT_IID(x)		7
    212 #define	DEFAULT_LOOPID(x)	108
    213 #define	DEFAULT_NODEWWN(isp)	(isp)->isp_osinfo.un._wwn
    214 #define	DEFAULT_PORTWWN(isp)	(isp)->isp_osinfo.un._wwn
    215 #define	ISP_NODEWWN(isp)	FCPARAM(isp)->isp_nodewwn
    216 #define	ISP_PORTWWN(isp)	FCPARAM(isp)->isp_portwwn
    217 
    218 #define	ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src)	\
    219 	if((void *)src != (void *)dest) bcopy(src, dest, sizeof (isp_pdb_t))
    220 #define	ISP_SWIZZLE_ICB(a, b)
    221 #ifdef	__sparc__
    222 #define ISP_SWIZZLE_REQUEST(a, b)			\
    223 	ISP_SBUSIFY_ISPHDR(a, &(b)->req_header);	\
    224         ISP_SBUSIFY_ISPREQ(a, b)
    225 #define ISP_UNSWIZZLE_RESPONSE(a, b, c)			\
    226 	ISP_SBUSIFY_ISPHDR(a, &(b)->req_header)
    227 #else
    228 #define	ISP_SWIZZLE_REQUEST(a, b)
    229 #define	ISP_UNSWIZZLE_RESPONSE(a, b, c)
    230 #endif
    231 #define	ISP_SWIZZLE_SNS_REQ(a, b)
    232 #define	ISP_UNSWIZZLE_SNS_RSP(a, b, c)
    233 #ifdef	__sparc__
    234 #define	ISP_SWIZZLE_NVRAM_WORD(isp, rp)	\
    235 	{								\
    236 		u_int16_t tmp = *rp >> 8;				\
    237 		tmp |= ((*rp & 0xff) << 8);				\
    238 		*rp = tmp;						\
    239 	}
    240 #else
    241 #define	ISP_SWIZZLE_NVRAM_WORD(isp, rp)
    242 #endif
    243 
    244 /*
    245  * Includes of common header files
    246  */
    247 
    248 #include <dev/ic/ispreg.h>
    249 #include <dev/ic/ispvar.h>
    250 #include <dev/ic/ispmbox.h>
    251 
    252 /*
    253  * isp_osinfo definitions, extensions and shorthand.
    254  */
    255 #define	isp_name	isp_osinfo._dev.dv_xname
    256 #define	isp_unit	isp_osinfo._dev.dv_unit
    257 
    258 /*
    259  * Driver prototypes..
    260  */
    261 void isp_attach __P((struct ispsoftc *));
    262 void isp_uninit __P((struct ispsoftc *));
    263 
    264 static inline void isp_lock __P((struct ispsoftc *));
    265 static inline void isp_unlock __P((struct ispsoftc *));
    266 static inline char *strncat __P((char *, const char *, size_t));
    267 static inline u_int64_t
    268 isp_microtime_sub __P((struct timeval *, struct timeval *));
    269 static void isp_wait_complete __P((struct ispsoftc *));
    270 
    271 /*
    272  * Driver wide data...
    273  */
    274 
    275 /*
    276  * Locking macros...
    277  */
    278 #define	ISP_LOCK		isp_lock
    279 #define	ISP_UNLOCK		isp_unlock
    280 #define	ISP_ILOCK(x)		isp_lock(x); isp->isp_osinfo.onintstack++
    281 #define	ISP_IUNLOCK(x)		isp->isp_osinfo.onintstack--; isp_unlock(x)
    282 
    283 /*
    284  * Platform private flags
    285  */
    286 
    287 #define	XS_PSTS_INWDOG		0x10000000
    288 #define	XS_PSTS_GRACE		0x20000000
    289 #define	XS_PSTS_ALL		0x30000000
    290 
    291 #define	XS_CMD_S_WDOG(xs)	(xs)->xs_status |= XS_PSTS_INWDOG
    292 #define	XS_CMD_C_WDOG(xs)	(xs)->xs_status &= ~XS_PSTS_INWDOG
    293 #define	XS_CMD_WDOG_P(xs)	(((xs)->xs_status & XS_PSTS_INWDOG) != 0)
    294 
    295 #define	XS_CMD_S_GRACE(xs)	(xs)->xs_status |= XS_PSTS_GRACE
    296 #define	XS_CMD_C_GRACE(xs)	(xs)->xs_status &= ~XS_PSTS_GRACE
    297 #define	XS_CMD_GRACE_P(xs)	(((xs)->xs_status & XS_PSTS_GRACE) != 0)
    298 
    299 #define	XS_CMD_S_DONE(xs)	(xs)->xs_status |= XS_STS_DONE
    300 #define	XS_CMD_C_DONE(xs)	(xs)->xs_status &= ~XS_STS_DONE
    301 #define	XS_CMD_DONE_P(xs)	(((xs)->xs_status & XS_STS_DONE) != 0)
    302 
    303 #define	XS_CMD_S_CLEAR(xs)	(xs)->xs_status &= ~XS_PSTS_ALL
    304 
    305 /*
    306  * Platform specific 'inline' or support functions
    307  */
    308 static inline void
    309 isp_lock(isp)
    310 	struct ispsoftc *isp;
    311 {
    312 	int s = splbio();
    313 	if (isp->isp_osinfo.islocked++ == 0) {
    314 		isp->isp_osinfo.splsaved = s;
    315 	} else {
    316 		splx(s);
    317 	}
    318 }
    319 
    320 static inline void
    321 isp_unlock(isp)
    322 	struct ispsoftc *isp;
    323 {
    324 	if (isp->isp_osinfo.islocked-- <= 1) {
    325 		isp->isp_osinfo.islocked = 0;
    326 		splx(isp->isp_osinfo.splsaved);
    327 	}
    328 }
    329 
    330 static inline char *
    331 strncat(d, s, c)
    332 	char *d;
    333 	const char *s;
    334 	size_t c;
    335 {
    336         char *t = d;
    337 
    338         if (c) {
    339                 while (*d)
    340                         d++;
    341                 while ((*d++ = *s++)) {
    342                         if (--c == 0) {
    343                                 *d = '\0';
    344                                 break;
    345                         }
    346                 }
    347         }
    348         return (t);
    349 }
    350 
    351 static inline u_int64_t
    352 isp_microtime_sub(b, a)
    353 	struct timeval *b;
    354 	struct timeval *a;
    355 {
    356 	struct timeval x;
    357 	u_int64_t elapsed;
    358 	timersub(b, a, &x);
    359 	elapsed = GET_NANOSEC(&x);
    360 	if (elapsed == 0)
    361 		elapsed++;
    362 	return (elapsed);
    363 }
    364 
    365 static inline void
    366 isp_wait_complete(isp)
    367 	struct ispsoftc *isp;
    368 {
    369 	if (isp->isp_osinfo.onintstack || isp->isp_osinfo.no_mbox_ints) {
    370 		int usecs = 0;
    371 		while (usecs < 2 * 1000000) {
    372 			(void) isp_intr(isp);
    373 			if (isp->isp_mboxbsy == 0) {
    374 				break;
    375 			}
    376 			USEC_DELAY(500);
    377 			usecs += 500;
    378 		}
    379 		if (isp->isp_mboxbsy != 0) {
    380 			isp_prt(isp, ISP_LOGWARN, "Mailbox Cmd (poll) Timeout");
    381 		}
    382 	} else {
    383 		int rv = 0;
    384                 isp->isp_osinfo.mboxwaiting = 1;
    385                 while (isp->isp_osinfo.mboxwaiting && rv == 0) {
    386 			static struct timeval twosec = { 2, 0 };
    387 			int timo;
    388 			struct timeval tv;
    389 			microtime(&tv);
    390 			timeradd(&tv, &twosec, &tv);
    391 			if ((timo = hzto(&tv)) == 0) {
    392 				timo = 1;
    393 			}
    394 			rv = tsleep(&isp->isp_osinfo.mboxwaiting,
    395 			    PRIBIO, "isp_mboxcmd", timo);
    396 		}
    397 		if (rv == EWOULDBLOCK) {
    398 			isp->isp_mboxbsy = 0;
    399 			isp->isp_osinfo.mboxwaiting = 0;
    400 			isp_prt(isp, ISP_LOGWARN, "Mailbox Cmd (intr) Timeout");
    401 		}
    402 	}
    403 }
    404 
    405 /*
    406  * Common inline functions
    407  */
    408 #define	INLINE	inline
    409 #include <dev/ic/isp_inline.h>
    410 
    411 #if	!defined(ISP_DISABLE_FW) && !defined(ISP_COMPILE_FW)
    412 #define	ISP_COMPILE_FW	1
    413 #endif
    414 #endif	/* _ISP_NETBSD_H */
    415