Home | History | Annotate | Line # | Download | only in ic
isp_netbsd.h revision 1.15
      1 /* $NetBSD: isp_netbsd.h,v 1.15 1999/07/05 20:31:36 mjacob Exp $ */
      2 /* release_6_5_99 */
      3 /*
      4  * NetBSD Specific definitions for the Qlogic ISP Host Adapter
      5  * Matthew Jacob <mjacob (at) nas.nasa.gov>
      6  */
      7 /*
      8  * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
      9  * All rights reserved.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 #ifndef	_ISP_NETBSD_H
     34 #define	_ISP_NETBSD_H
     35 
     36 #include <sys/types.h>
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/kernel.h>
     40 #include <sys/errno.h>
     41 #include <sys/ioctl.h>
     42 #include <sys/device.h>
     43 #include <sys/malloc.h>
     44 #include <sys/buf.h>
     45 #include <sys/proc.h>
     46 #include <sys/user.h>
     47 
     48 
     49 #include <dev/scsipi/scsi_all.h>
     50 #include <dev/scsipi/scsipi_all.h>
     51 #include <dev/scsipi/scsiconf.h>
     52 
     53 #include <dev/scsipi/scsi_message.h>
     54 #include <dev/scsipi/scsipi_debug.h>
     55 
     56 #include <vm/vm.h>
     57 #include <vm/vm_param.h>
     58 #include <vm/pmap.h>
     59 
     60 #include "opt_isp.h"
     61 
     62 #define	ISP_PLATFORM_VERSION_MAJOR	0
     63 #define	ISP_PLATFORM_VERSION_MINOR	996
     64 
     65 #define	ISP_SCSI_XFER_T		struct scsipi_xfer
     66 struct isposinfo {
     67 	struct device		_dev;
     68 	struct scsipi_link	_link;
     69 	struct scsipi_link	_link_b;
     70 	struct scsipi_adapter   _adapter;
     71 	int			seed;
     72 	int			blocked;
     73 	TAILQ_HEAD(, scsipi_xfer) waitq;
     74 };
     75 #define	MAXISPREQUEST	256
     76 #ifdef	ISP2100_FABRIC
     77 #define	ISP2100_SCRLEN		0x400
     78 #else
     79 #define	ISP2100_SCRLEN		0x100
     80 #endif
     81 
     82 #include <dev/ic/ispreg.h>
     83 #include <dev/ic/ispvar.h>
     84 #include <dev/ic/ispmbox.h>
     85 
     86 #define	PRINTF			printf
     87 #define	IDPRINTF(lev, x)	if (isp->isp_dblev >= lev) printf x
     88 
     89 #define	MEMZERO			bzero
     90 #define	MEMCPY(dst, src, count)	bcopy((src), (dst), (count))
     91 #ifdef	__alpha__
     92 #define	MemoryBarrier	alpha_mb
     93 #else
     94 #define	MemoryBarrier()
     95 #endif
     96 
     97 #define	DMA_MSW(x)	(((x) >> 16) & 0xffff)
     98 #define	DMA_LSW(x)	(((x) & 0xffff))
     99 
    100 #if	defined(SCSIDEBUG)
    101 #define	DFLT_DBLEVEL		3
    102 #else
    103 #if	defined(DEBUG)
    104 #define	DFLT_DBLEVEL		2
    105 #else
    106 #define	DFLT_DBLEVEL		1
    107 #endif
    108 #endif
    109 
    110 #define	ISP_LOCKVAL_DECL	int isp_spl_save
    111 #define	ISP_ILOCKVAL_DECL	ISP_LOCKVAL_DECL
    112 #define	ISP_LOCK(x)		isp_spl_save = splbio()
    113 #define	ISP_UNLOCK(x)		(void) splx(isp_spl_save)
    114 #define	ISP_ILOCK		ISP_LOCK
    115 #define	ISP_IUNLOCK		ISP_UNLOCK
    116 
    117 
    118 #define	XS_NULL(xs)		xs == NULL || xs->sc_link == NULL
    119 #define	XS_ISP(xs)		(xs)->sc_link->adapter_softc
    120 #define	XS_LUN(xs)		((int) (xs)->sc_link->scsipi_scsi.lun)
    121 #define	XS_TGT(xs)		((int) (xs)->sc_link->scsipi_scsi.target)
    122 #define	XS_CHANNEL(xs)		\
    123     (((xs)->sc_link == &(((struct ispsoftc *)XS_ISP(xs))->isp_osinfo._link_b))?\
    124     1 : 0)
    125 #define	XS_RESID(xs)		(xs)->resid
    126 #define	XS_XFRLEN(xs)		(xs)->datalen
    127 #define	XS_CDBLEN(xs)		(xs)->cmdlen
    128 #define	XS_CDBP(xs)		((caddr_t) (xs)->cmd)
    129 #define	XS_STS(xs)		(xs)->status
    130 #define	XS_TIME(xs)		(xs)->timeout
    131 #define	XS_SNSP(xs)		(&(xs)->sense.scsi_sense)
    132 #define	XS_SNSLEN(xs)		(sizeof (xs)->sense.scsi_sense)
    133 #define	XS_SNSKEY(xs)		((xs)->sense.scsi_sense.flags)
    134 
    135 #define	HBA_NOERROR		XS_NOERROR
    136 #define	HBA_BOTCH		XS_DRIVER_STUFFUP
    137 #define	HBA_CMDTIMEOUT		XS_TIMEOUT
    138 #define	HBA_SELTIMEOUT		XS_SELTIMEOUT
    139 #define	HBA_TGTBSY		XS_BUSY
    140 #ifdef	XS_RESET
    141 #define	HBA_BUSRESET		XS_RESET
    142 #else
    143 #define	HBA_BUSRESET		XS_DRIVER_STUFFUP
    144 #endif
    145 #define	HBA_ABORTED		XS_DRIVER_STUFFUP
    146 #define	HBA_DATAOVR		XS_DRIVER_STUFFUP
    147 #define	HBA_ARQFAIL		XS_DRIVER_STUFFUP
    148 
    149 #define	XS_SNS_IS_VALID(xs)	(xs)->error = XS_SENSE
    150 #define	XS_IS_SNS_VALID(xs)	((xs)->error == XS_SENSE)
    151 
    152 #define	XS_INITERR(xs)		(xs)->error = 0
    153 #define	XS_SETERR(xs, v)	(xs)->error = v
    154 #define	XS_ERR(xs)		(xs)->error
    155 #define	XS_NOERR(xs)		(xs)->error == XS_NOERROR
    156 
    157 #define	XS_CMD_DONE(xs)		(xs)->flags |= ITSDONE, scsipi_done(xs)
    158 #define	XS_IS_CMD_DONE(xs)	(((xs)->flags & ITSDONE) != 0)
    159 
    160 /*
    161  * We use whether or not we're a polled command to decide about tagging.
    162  */
    163 #define	XS_CANTAG(xs)		(((xs)->flags & SCSI_POLL) != 0)
    164 
    165 /*
    166  * This is our default tag (ordered).
    167  */
    168 #define	XS_KINDOF_TAG(xs)	\
    169 	(((xs)->flags & SCSI_URGENT)? REQFLAG_HTAG : REQFLAG_STAG)
    170 
    171 #define	CMD_COMPLETE		COMPLETE
    172 #define	CMD_EAGAIN		TRY_AGAIN_LATER
    173 #define	CMD_QUEUED		SUCCESSFULLY_QUEUED
    174 
    175 
    176 
    177 #define	isp_name	isp_osinfo._dev.dv_xname
    178 #define	isp_unit	isp_osinfo._dev.dv_unit
    179 
    180 #define	SCSI_QFULL	0x28
    181 
    182 
    183 #define	SYS_DELAY(x)	delay(x)
    184 
    185 #define	WATCH_INTERVAL	30
    186 
    187 #define	FC_FW_READY_DELAY	(12 * 1000000)
    188 #define	DEFAULT_LOOPID(x)	108
    189 #define	DEFAULT_WWN(x)		(0x1000beed00000000LL + (x)->isp_osinfo.seed)
    190 
    191 extern void isp_attach __P((struct ispsoftc *));
    192 extern void isp_uninit __P((struct ispsoftc *));
    193 
    194 static inline void isp_prtstst(ispstatusreq_t *sp)
    195 {
    196 	char buf[128];
    197 	sprintf(buf, "states->");
    198 	if (sp->req_state_flags & RQSF_GOT_BUS)
    199 		sprintf(buf, "%s%s", buf, "GOT_BUS ");
    200 	if (sp->req_state_flags & RQSF_GOT_TARGET)
    201 		sprintf(buf, "%s%s", buf, "GOT_TGT ");
    202 	if (sp->req_state_flags & RQSF_SENT_CDB)
    203 		sprintf(buf, "%s%s", buf, "SENT_CDB ");
    204 	if (sp->req_state_flags & RQSF_XFRD_DATA)
    205 		sprintf(buf, "%s%s", buf, "XFRD_DATA ");
    206 	if (sp->req_state_flags & RQSF_GOT_STATUS)
    207 		sprintf(buf, "%s%s", buf, "GOT_STS ");
    208 	if (sp->req_state_flags & RQSF_GOT_SENSE)
    209 		sprintf(buf, "%s%s", buf, "GOT_SNS ");
    210 	if (sp->req_state_flags & RQSF_XFER_COMPLETE)
    211 		sprintf(buf, "%s%s", buf, "XFR_CMPLT ");
    212 	sprintf(buf, "%s%s", buf, "\n");
    213 	sprintf(buf, "%s%s", buf, "status->");
    214 	if (sp->req_status_flags & RQSTF_DISCONNECT)
    215 		sprintf(buf, "%s%s", buf, "Disconnect ");
    216 	if (sp->req_status_flags & RQSTF_SYNCHRONOUS)
    217 		sprintf(buf, "%s%s", buf, "Sync_xfr ");
    218 	if (sp->req_status_flags & RQSTF_PARITY_ERROR)
    219 		sprintf(buf, "%s%s", buf, "Parity ");
    220 	if (sp->req_status_flags & RQSTF_BUS_RESET)
    221 		sprintf(buf, "%s%s", buf, "Bus_Reset ");
    222 	if (sp->req_status_flags & RQSTF_DEVICE_RESET)
    223 		sprintf(buf, "%s%s", buf, "Device_Reset ");
    224 	if (sp->req_status_flags & RQSTF_ABORTED)
    225 		sprintf(buf, "%s%s", buf, "Aborted ");
    226 	if (sp->req_status_flags & RQSTF_TIMEOUT)
    227 		sprintf(buf, "%s%s", buf, "Timeout ");
    228 	if (sp->req_status_flags & RQSTF_NEGOTIATION)
    229 		sprintf(buf, "%s%s", buf, "Negotiation ");
    230 	printf("%s\n", buf);
    231 }
    232 
    233 static inline const char *isp2100_fw_statename(int state)
    234 {
    235 	static char buf[16];
    236 	switch(state) {
    237 	case FW_CONFIG_WAIT:	return "Config Wait";
    238 	case FW_WAIT_AL_PA:	return "Waiting for AL_PA";
    239 	case FW_WAIT_LOGIN:	return "Wait Login";
    240 	case FW_READY:		return "Ready";
    241 	case FW_LOSS_OF_SYNC:	return "Loss Of Sync";
    242 	case FW_ERROR:		return "Error";
    243 	case FW_REINIT:		return "Re-Init";
    244 	case FW_NON_PART:	return "Nonparticipating";
    245 	default:
    246 		sprintf(buf, "0x%x", state);
    247 		return buf;
    248     }
    249 }
    250 
    251 static inline const char *isp2100_pdb_statename(int pdb_state)
    252 {
    253 	static char buf[16];
    254 	switch(pdb_state) {
    255 	case PDB_STATE_DISCOVERY:	return "Port Discovery";
    256 	case PDB_STATE_WDISC_ACK:	return "Waiting Port Discovery ACK";
    257 	case PDB_STATE_PLOGI:		return "Port Login";
    258 	case PDB_STATE_PLOGI_ACK:	return "Wait Port Login ACK";
    259 	case PDB_STATE_PRLI:		return "Process Login";
    260 	case PDB_STATE_PRLI_ACK:	return "Wait Process Login ACK";
    261 	case PDB_STATE_LOGGED_IN:	return "Logged In";
    262 	case PDB_STATE_PORT_UNAVAIL:	return "Port Unavailable";
    263 	case PDB_STATE_PRLO:		return "Process Logout";
    264 	case PDB_STATE_PRLO_ACK:	return "Wait Process Logout ACK";
    265 	case PDB_STATE_PLOGO:		return "Port Logout";
    266 	case PDB_STATE_PLOG_ACK:	return "Wait Port Logout ACK";
    267 	default:
    268 		sprintf(buf, "0x%x", pdb_state);
    269 		return buf;
    270 	}
    271 }
    272 #endif	/* _ISP_NETBSD_H */
    273