Home | History | Annotate | Line # | Download | only in ic
isp_netbsd.h revision 1.23.4.2
      1 /* $NetBSD: isp_netbsd.h,v 1.23.4.2 2000/08/28 17:45:10 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)	\
    214 	isp_port_from_node_wwn((isp), DEFAULT_NODEWWN(isp))
    215 #define	PORT_FROM_NODE_WWN	isp_port_from_node_wwn
    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_port_from_node_wwn __P((struct ispsoftc *, u_int64_t));
    268 static inline u_int64_t
    269 isp_microtime_sub __P((struct timeval *, struct timeval *));
    270 static void isp_wait_complete __P((struct ispsoftc *));
    271 
    272 /*
    273  * Driver wide data...
    274  */
    275 
    276 /*
    277  * Locking macros...
    278  */
    279 #define	ISP_LOCK		isp_lock
    280 #define	ISP_UNLOCK		isp_unlock
    281 #define	ISP_ILOCK(x)		isp_lock(x); isp->isp_osinfo.onintstack++
    282 #define	ISP_IUNLOCK(x)		isp->isp_osinfo.onintstack--; isp_unlock(x)
    283 
    284 /*
    285  * Platform private flags
    286  */
    287 
    288 #define	XS_PSTS_INWDOG		0x10000000
    289 #define	XS_PSTS_GRACE		0x20000000
    290 #define	XS_PSTS_ALL		0x30000000
    291 
    292 #define	XS_CMD_S_WDOG(xs)	(xs)->xs_status |= XS_PSTS_INWDOG
    293 #define	XS_CMD_C_WDOG(xs)	(xs)->xs_status &= ~XS_PSTS_INWDOG
    294 #define	XS_CMD_WDOG_P(xs)	(((xs)->xs_status & XS_PSTS_INWDOG) != 0)
    295 
    296 #define	XS_CMD_S_GRACE(xs)	(xs)->xs_status |= XS_PSTS_GRACE
    297 #define	XS_CMD_C_GRACE(xs)	(xs)->xs_status &= ~XS_PSTS_GRACE
    298 #define	XS_CMD_GRACE_P(xs)	(((xs)->xs_status & XS_PSTS_GRACE) != 0)
    299 
    300 #define	XS_CMD_S_DONE(xs)	(xs)->xs_status |= XS_STS_DONE
    301 #define	XS_CMD_C_DONE(xs)	(xs)->xs_status &= ~XS_STS_DONE
    302 #define	XS_CMD_DONE_P(xs)	(((xs)->xs_status & XS_STS_DONE) != 0)
    303 
    304 #define	XS_CMD_S_CLEAR(xs)	(xs)->xs_status &= ~XS_PSTS_ALL
    305 
    306 /*
    307  * Platform specific 'inline' or support functions
    308  */
    309 static inline void
    310 isp_lock(isp)
    311 	struct ispsoftc *isp;
    312 {
    313 	int s = splbio();
    314 	if (isp->isp_osinfo.islocked++ == 0) {
    315 		isp->isp_osinfo.splsaved = s;
    316 	} else {
    317 		splx(s);
    318 	}
    319 }
    320 
    321 static inline void
    322 isp_unlock(isp)
    323 	struct ispsoftc *isp;
    324 {
    325 	if (isp->isp_osinfo.islocked <= 1) {
    326 		isp->isp_osinfo.islocked = 0;
    327 		splx(isp->isp_osinfo.splsaved);
    328 	}
    329 }
    330 
    331 static inline char *
    332 strncat(d, s, c)
    333 	char *d;
    334 	const char *s;
    335 	size_t c;
    336 {
    337         char *t = d;
    338 
    339         if (c) {
    340                 while (*d)
    341                         d++;
    342                 while ((*d++ = *s++)) {
    343                         if (--c == 0) {
    344                                 *d = '\0';
    345                                 break;
    346                         }
    347                 }
    348         }
    349         return (t);
    350 }
    351 
    352 static inline u_int64_t
    353 isp_microtime_sub(b, a)
    354 	struct timeval *b;
    355 	struct timeval *a;
    356 {
    357 	struct timeval x;
    358 	u_int64_t elapsed;
    359 	timersub(b, a, &x);
    360 	elapsed = GET_NANOSEC(&x);
    361 	if (elapsed == 0)
    362 		elapsed++;
    363 	return (elapsed);
    364 }
    365 
    366 static inline void
    367 isp_wait_complete(isp)
    368 	struct ispsoftc *isp;
    369 {
    370 	if (isp->isp_osinfo.onintstack || isp->isp_osinfo.no_mbox_ints) {
    371 		int usecs = 0;
    372 		while (usecs < 2 * 1000000) {
    373 			(void) isp_intr(isp);
    374 			if (isp->isp_mboxbsy == 0) {
    375 				break;
    376 			}
    377 			USEC_DELAY(500);
    378 			usecs += 500;
    379 		}
    380 		if (isp->isp_mboxbsy != 0) {
    381 			isp_prt(isp, ISP_LOGWARN, "Mailbox Cmd (poll) Timeout");
    382 		}
    383 	} else {
    384 		int rv = 0;
    385                 isp->isp_osinfo.mboxwaiting = 1;
    386                 while (isp->isp_osinfo.mboxwaiting && rv == 0) {
    387 			static struct timeval twosec = { 2, 0 };
    388 			int timo;
    389 			struct timeval tv;
    390 			microtime(&tv);
    391 			timeradd(&tv, &twosec, &tv);
    392 			if ((timo = hzto(&tv)) == 0) {
    393 				timo = 1;
    394 			}
    395 			rv = tsleep(&isp->isp_osinfo.mboxwaiting,
    396 			    PRIBIO, "isp_mboxcmd", timo);
    397 		}
    398 		if (rv == EWOULDBLOCK) {
    399 			isp->isp_mboxbsy = 0;
    400 			isp->isp_osinfo.mboxwaiting = 0;
    401 			isp_prt(isp, ISP_LOGWARN, "Mailbox Cmd (intr) Timeout");
    402 		}
    403 	}
    404 }
    405 
    406 static inline u_int64_t
    407 isp_port_from_node_wwn(struct ispsoftc *isp, u_int64_t node_wwn)
    408 {
    409 	u_int64_t rv = node_wwn;
    410 	if ((node_wwn >> 60) == 2) {
    411 		rv = node_wwn |
    412 		    (((u_int64_t)(isp->isp_unit+1)) << 48);
    413 	}
    414 	return (rv);
    415 }
    416 
    417 /*
    418  * Common inline functions
    419  */
    420 #define	INLINE	inline
    421 #include <dev/ic/isp_inline.h>
    422 
    423 #if	!defined(ISP_DISABLE_FW) && !defined(ISP_COMPILE_FW)
    424 #define	ISP_COMPILE_FW	1
    425 #endif
    426 #endif	/* _ISP_NETBSD_H */
    427