Home | History | Annotate | Line # | Download | only in ic
isp_netbsd.h revision 1.30
      1 /* $NetBSD: isp_netbsd.h,v 1.30 2000/10/16 05:18:15 mjacob 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 
     77 #include <dev/scsipi/scsi_all.h>
     78 #include <dev/scsipi/scsipi_all.h>
     79 #include <dev/scsipi/scsiconf.h>
     80 
     81 #include <dev/scsipi/scsi_message.h>
     82 #include <dev/scsipi/scsipi_debug.h>
     83 
     84 #include "opt_isp.h"
     85 
     86 
     87 #define	ISP_PLATFORM_VERSION_MAJOR	1
     88 #define	ISP_PLATFORM_VERSION_MINOR	0
     89 
     90 struct isposinfo {
     91 	struct device		_dev;
     92 	struct scsipi_link	_link;
     93 	struct scsipi_link	_link_b;
     94 	struct scsipi_adapter   _adapter;
     95 	int	splsaved;
     96 	int	mboxwaiting;
     97 	u_int32_t	islocked;
     98 	u_int32_t	onintstack;
     99 	unsigned int		: 30,
    100 		no_mbox_ints	: 1,
    101 		blocked		: 1;
    102 	union {
    103 		u_int64_t	_wwn;
    104 		u_int16_t	_discovered[2];
    105 #define	wwn_seed	un._wwn
    106 #define	discovered	un._discovered
    107 	} un;
    108 	TAILQ_HEAD(, scsipi_xfer) waitq;
    109 	struct callout _restart;
    110 };
    111 
    112 /*
    113  * Required Macros/Defines
    114  */
    115 
    116 #define	INLINE			inline
    117 
    118 #define	ISP2100_FABRIC		1
    119 #define	ISP2100_SCRLEN		0x400
    120 
    121 #define	MEMZERO			bzero
    122 #define	MEMCPY(dst, src, amt)	bcopy((src), (dst), (amt))
    123 #define	SNPRINTF		snprintf
    124 #define	STRNCAT			strncat
    125 #define	USEC_DELAY		DELAY
    126 
    127 #define	NANOTIME_T		struct timeval
    128 #define	GET_NANOTIME		microtime
    129 #define	GET_NANOSEC(x)		(((x)->tv_sec * 1000000 + (x)->tv_usec) * 1000)
    130 #define	NANOTIME_SUB		isp_microtime_sub
    131 
    132 #define	MAXISPREQUEST(isp)	256
    133 
    134 #ifdef	__alpha__
    135 #define	MEMORYBARRIER(isp, type, offset, size)	alpha_mb()
    136 #else
    137 #define	MEMORYBARRIER(isp, type, offset, size)
    138 #endif
    139 
    140 #define	MBOX_ACQUIRE(isp)
    141 #define	MBOX_WAIT_COMPLETE	isp_wait_complete
    142 
    143 #define	MBOX_NOTIFY_COMPLETE(isp)					\
    144 	if (isp->isp_osinfo.mboxwaiting) {				\
    145                 isp->isp_osinfo.mboxwaiting = 0;			\
    146                 wakeup(&isp->isp_osinfo.mboxwaiting);			\
    147         }								\
    148 	isp->isp_mboxbsy = 0
    149 
    150 #define	MBOX_RELEASE(isp)
    151 
    152 #ifndef	SCSI_GOOD
    153 #define	SCSI_GOOD	0x0
    154 #endif
    155 #ifndef	SCSI_CHECK
    156 #define	SCSI_CHECK	0x2
    157 #endif
    158 #ifndef	SCSI_BUSY
    159 #define	SCSI_BUSY	0x8
    160 #endif
    161 #ifndef	SCSI_QFULL
    162 #define	SCSI_QFULL	0x28
    163 #endif
    164 
    165 #define	XS_T			struct scsipi_xfer
    166 #define	XS_CHANNEL(xs)		\
    167 	(((int) (xs)->sc_link->scsipi_scsi.channel == SCSI_CHANNEL_ONLY_ONE) ? \
    168 	    0 : (xs)->sc_link->scsipi_scsi.channel)
    169 #define	XS_ISP(xs)		(xs)->sc_link->adapter_softc
    170 #define	XS_LUN(xs)		((int) (xs)->sc_link->scsipi_scsi.lun)
    171 #define	XS_TGT(xs)		((int) (xs)->sc_link->scsipi_scsi.target)
    172 #define	XS_CDBP(xs)		((caddr_t) (xs)->cmd)
    173 #define	XS_CDBLEN(xs)		(xs)->cmdlen
    174 #define	XS_XFRLEN(xs)		(xs)->datalen
    175 #define	XS_TIME(xs)		(xs)->timeout
    176 #define	XS_RESID(xs)		(xs)->resid
    177 #define	XS_STSP(xs)		(&(xs)->status)
    178 #define	XS_SNSP(xs)		(&(xs)->sense.scsi_sense)
    179 #define	XS_SNSLEN(xs)		(sizeof (xs)->sense)
    180 #define	XS_SNSKEY(xs)		((xs)->sense.scsi_sense.flags)
    181 #define	XS_TAG_P(ccb)		(((xs)->xs_control & XS_CTL_POLL) != 0)
    182 #define	XS_TAG_TYPE(xs)	\
    183 	(((xs)->xs_control & XS_CTL_URGENT) ? REQFLAG_HTAG : \
    184 	((xs)->bp && xs->bp->b_flags & B_ASYNC) ? REQFLAG_STAG : REQFLAG_OTAG)
    185 
    186 #define	XS_SETERR(xs, v)	(xs)->error = v
    187 
    188 #	define	HBA_NOERROR		XS_NOERROR
    189 #	define	HBA_BOTCH		XS_DRIVER_STUFFUP
    190 #	define	HBA_CMDTIMEOUT		XS_TIMEOUT
    191 #	define	HBA_SELTIMEOUT		XS_SELTIMEOUT
    192 #	define	HBA_TGTBSY		XS_BUSY
    193 #	define	HBA_BUSRESET		XS_RESET
    194 #	define	HBA_ABORTED		XS_DRIVER_STUFFUP
    195 #	define	HBA_DATAOVR		XS_DRIVER_STUFFUP
    196 #	define	HBA_ARQFAIL		XS_DRIVER_STUFFUP
    197 
    198 #define	XS_ERR(xs)		(xs)->error
    199 
    200 #define	XS_NOERR(xs)		(xs)->error == XS_NOERROR
    201 
    202 #define	XS_INITERR(xs)		(xs)->error = 0, XS_CMD_S_CLEAR(xs)
    203 
    204 #define	XS_SAVE_SENSE(xs, sp)				\
    205 	bcopy(sp->req_sense_data, &(xs)->sense,		\
    206 	    imin(XS_SNSLEN(xs), sp->req_sense_len))
    207 
    208 #define	XS_SET_STATE_STAT(a, b, c)
    209 
    210 #define	DEFAULT_IID(x)		7
    211 #define	DEFAULT_LOOPID(x)	108
    212 #define	DEFAULT_NODEWWN(isp)	(isp)->isp_osinfo.un._wwn
    213 #define	DEFAULT_PORTWWN(isp)	(isp)->isp_osinfo.un._wwn
    214 #define	ISP_NODEWWN(isp)	FCPARAM(isp)->isp_nodewwn
    215 #define	ISP_PORTWWN(isp)	FCPARAM(isp)->isp_portwwn
    216 
    217 #define	ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src)	\
    218 	if((void *)src != (void *)dest) bcopy(src, dest, sizeof (isp_pdb_t))
    219 #define	ISP_SWIZZLE_ICB(a, b)
    220 #ifdef	__sparc__
    221 #define ISP_SWIZZLE_REQUEST(a, b)			\
    222 	ISP_SBUSIFY_ISPHDR(a, &(b)->req_header);	\
    223         ISP_SBUSIFY_ISPREQ(a, b)
    224 #define ISP_UNSWIZZLE_RESPONSE(a, b, c)			\
    225 	ISP_SBUSIFY_ISPHDR(a, &(b)->req_header)
    226 #else
    227 #define	ISP_SWIZZLE_REQUEST(a, b)
    228 #define	ISP_UNSWIZZLE_RESPONSE(a, b, c)
    229 #endif
    230 #define	ISP_SWIZZLE_SNS_REQ(a, b)
    231 #define	ISP_UNSWIZZLE_SNS_RSP(a, b, c)
    232 #ifdef	__sparc__
    233 #define	ISP_SWIZZLE_NVRAM_WORD(isp, rp)	\
    234 	{								\
    235 		u_int16_t tmp = *rp >> 8;				\
    236 		tmp |= ((*rp & 0xff) << 8);				\
    237 		*rp = tmp;						\
    238 	}
    239 #else
    240 #define	ISP_SWIZZLE_NVRAM_WORD(isp, rp)
    241 #endif
    242 
    243 /*
    244  * Includes of common header files
    245  */
    246 
    247 #include <dev/ic/ispreg.h>
    248 #include <dev/ic/ispvar.h>
    249 #include <dev/ic/ispmbox.h>
    250 
    251 /*
    252  * isp_osinfo definitions, extensions and shorthand.
    253  */
    254 #define	isp_name	isp_osinfo._dev.dv_xname
    255 #define	isp_unit	isp_osinfo._dev.dv_unit
    256 
    257 /*
    258  * Driver prototypes..
    259  */
    260 void isp_attach __P((struct ispsoftc *));
    261 void isp_uninit __P((struct ispsoftc *));
    262 
    263 static inline void isp_lock __P((struct ispsoftc *));
    264 static inline void isp_unlock __P((struct ispsoftc *));
    265 static inline char *strncat __P((char *, const char *, size_t));
    266 static inline u_int64_t
    267 isp_microtime_sub __P((struct timeval *, struct timeval *));
    268 static void isp_wait_complete __P((struct ispsoftc *));
    269 
    270 /*
    271  * Driver wide data...
    272  */
    273 
    274 /*
    275  * Locking macros...
    276  */
    277 #define	ISP_LOCK		isp_lock
    278 #define	ISP_UNLOCK		isp_unlock
    279 #define	ISP_ILOCK(x)		isp_lock(x); isp->isp_osinfo.onintstack++
    280 #define	ISP_IUNLOCK(x)		isp->isp_osinfo.onintstack--; isp_unlock(x)
    281 
    282 /*
    283  * Platform private flags
    284  */
    285 
    286 #define	XS_PSTS_INWDOG		0x10000000
    287 #define	XS_PSTS_GRACE		0x20000000
    288 #define	XS_PSTS_ALL		0x30000000
    289 
    290 #define	XS_CMD_S_WDOG(xs)	(xs)->xs_status |= XS_PSTS_INWDOG
    291 #define	XS_CMD_C_WDOG(xs)	(xs)->xs_status &= ~XS_PSTS_INWDOG
    292 #define	XS_CMD_WDOG_P(xs)	(((xs)->xs_status & XS_PSTS_INWDOG) != 0)
    293 
    294 #define	XS_CMD_S_GRACE(xs)	(xs)->xs_status |= XS_PSTS_GRACE
    295 #define	XS_CMD_C_GRACE(xs)	(xs)->xs_status &= ~XS_PSTS_GRACE
    296 #define	XS_CMD_GRACE_P(xs)	(((xs)->xs_status & XS_PSTS_GRACE) != 0)
    297 
    298 #define	XS_CMD_S_DONE(xs)	(xs)->xs_status |= XS_STS_DONE
    299 #define	XS_CMD_C_DONE(xs)	(xs)->xs_status &= ~XS_STS_DONE
    300 #define	XS_CMD_DONE_P(xs)	(((xs)->xs_status & XS_STS_DONE) != 0)
    301 
    302 #define	XS_CMD_S_CLEAR(xs)	(xs)->xs_status &= ~XS_PSTS_ALL
    303 
    304 /*
    305  * Platform specific 'inline' or support functions
    306  */
    307 static inline void
    308 isp_lock(isp)
    309 	struct ispsoftc *isp;
    310 {
    311 	int s = splbio();
    312 	if (isp->isp_osinfo.islocked++ == 0) {
    313 		isp->isp_osinfo.splsaved = s;
    314 	} else {
    315 		splx(s);
    316 	}
    317 }
    318 
    319 static inline void
    320 isp_unlock(isp)
    321 	struct ispsoftc *isp;
    322 {
    323 	if (isp->isp_osinfo.islocked-- <= 1) {
    324 		isp->isp_osinfo.islocked = 0;
    325 		splx(isp->isp_osinfo.splsaved);
    326 	}
    327 }
    328 
    329 static inline char *
    330 strncat(d, s, c)
    331 	char *d;
    332 	const char *s;
    333 	size_t c;
    334 {
    335         char *t = d;
    336 
    337         if (c) {
    338                 while (*d)
    339                         d++;
    340                 while ((*d++ = *s++)) {
    341                         if (--c == 0) {
    342                                 *d = '\0';
    343                                 break;
    344                         }
    345                 }
    346         }
    347         return (t);
    348 }
    349 
    350 static inline u_int64_t
    351 isp_microtime_sub(b, a)
    352 	struct timeval *b;
    353 	struct timeval *a;
    354 {
    355 	struct timeval x;
    356 	u_int64_t elapsed;
    357 	timersub(b, a, &x);
    358 	elapsed = GET_NANOSEC(&x);
    359 	if (elapsed == 0)
    360 		elapsed++;
    361 	return (elapsed);
    362 }
    363 
    364 static inline void
    365 isp_wait_complete(isp)
    366 	struct ispsoftc *isp;
    367 {
    368 	if (isp->isp_osinfo.onintstack || isp->isp_osinfo.no_mbox_ints) {
    369 		int usecs = 0;
    370 		while (usecs < 2 * 1000000) {
    371 			(void) isp_intr(isp);
    372 			if (isp->isp_mboxbsy == 0) {
    373 				break;
    374 			}
    375 			USEC_DELAY(500);
    376 			usecs += 500;
    377 		}
    378 		if (isp->isp_mboxbsy != 0) {
    379 			isp_prt(isp, ISP_LOGWARN, "Mailbox Cmd (poll) Timeout");
    380 		}
    381 	} else {
    382 		int rv = 0;
    383                 isp->isp_osinfo.mboxwaiting = 1;
    384                 while (isp->isp_osinfo.mboxwaiting && rv == 0) {
    385 			static struct timeval twosec = { 2, 0 };
    386 			int timo;
    387 			struct timeval tv;
    388 			microtime(&tv);
    389 			timeradd(&tv, &twosec, &tv);
    390 			if ((timo = hzto(&tv)) == 0) {
    391 				timo = 1;
    392 			}
    393 			rv = tsleep(&isp->isp_osinfo.mboxwaiting,
    394 			    PRIBIO, "isp_mboxcmd", timo);
    395 		}
    396 		if (rv == EWOULDBLOCK) {
    397 			isp->isp_mboxbsy = 0;
    398 			isp->isp_osinfo.mboxwaiting = 0;
    399 			isp_prt(isp, ISP_LOGWARN, "Mailbox Cmd (intr) Timeout");
    400 		}
    401 	}
    402 }
    403 
    404 /*
    405  * Common inline functions
    406  */
    407 #define	INLINE	inline
    408 #include <dev/ic/isp_inline.h>
    409 
    410 #if	!defined(ISP_DISABLE_FW) && !defined(ISP_COMPILE_FW)
    411 #define	ISP_COMPILE_FW	1
    412 #endif
    413 #endif	/* _ISP_NETBSD_H */
    414