isp_freebsd.h revision 58100
150477Speter/* $FreeBSD: head/sys/dev/isp/isp_freebsd.h 58100 2000-03-15 18:49:44Z mjacob $ */
235388Smjacob/*
348487Smjacob * Qlogic ISP SCSI Host Adapter FreeBSD Wrapper Definitions (CAM version)
435388Smjacob *---------------------------------------
548487Smjacob * Copyright (c) 1997, 1998, 1999 by Matthew Jacob
635388Smjacob * NASA/Ames Research Center
735388Smjacob * All rights reserved.
835388Smjacob *---------------------------------------
935388Smjacob *
1035388Smjacob * Redistribution and use in source and binary forms, with or without
1135388Smjacob * modification, are permitted provided that the following conditions
1235388Smjacob * are met:
1335388Smjacob * 1. Redistributions of source code must retain the above copyright
1435388Smjacob *    notice immediately at the beginning of the file, without modification,
1535388Smjacob *    this list of conditions, and the following disclaimer.
1635388Smjacob * 2. Redistributions in binary form must reproduce the above copyright
1735388Smjacob *    notice, this list of conditions and the following disclaimer in the
1835388Smjacob *    documentation and/or other materials provided with the distribution.
1935388Smjacob * 3. The name of the author may not be used to endorse or promote products
2035388Smjacob *    derived from this software without specific prior written permission.
2135388Smjacob *
2235388Smjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
2335388Smjacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2435388Smjacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2535388Smjacob * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
2635388Smjacob * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2735388Smjacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2835388Smjacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2935388Smjacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3035388Smjacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3135388Smjacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3235388Smjacob * SUCH DAMAGE.
3335388Smjacob */
3435388Smjacob#ifndef	_ISP_FREEBSD_H
3535388Smjacob#define	_ISP_FREEBSD_H
3635388Smjacob
3758100Smjacob#define	ISP_PLATFORM_VERSION_MAJOR	5
3858100Smjacob#define	ISP_PLATFORM_VERSION_MINOR	0
3939235Sgibbs
4048487Smjacob
4139445Smjacob#include <sys/param.h>
4248487Smjacob#include <sys/param.h>
4348487Smjacob#include <sys/systm.h>
4448487Smjacob#include <sys/kernel.h>
4548487Smjacob#include <sys/queue.h>
4639445Smjacob
4748487Smjacob#include <machine/bus_memio.h>
4848487Smjacob#include <machine/bus_pio.h>
4948487Smjacob#include <machine/bus.h>
5048487Smjacob#include <machine/clock.h>
5139445Smjacob
5248487Smjacob#include <cam/cam.h>
5348487Smjacob#include <cam/cam_debug.h>
5448487Smjacob#include <cam/cam_ccb.h>
5548487Smjacob#include <cam/cam_sim.h>
5648487Smjacob#include <cam/cam_xpt.h>
5748487Smjacob#include <cam/cam_xpt_sim.h>
5848487Smjacob#include <cam/cam_debug.h>
5948487Smjacob#include <cam/scsi/scsi_all.h>
6048487Smjacob#include <cam/scsi/scsi_message.h>
6148487Smjacob
6252348Smjacob#include "opt_ddb.h"
6348487Smjacob#include "opt_isp.h"
6448487Smjacob#ifdef	SCSI_ISP_FABRIC
6548487Smjacob#define	ISP2100_FABRIC		1
6648487Smjacob#define	ISP2100_SCRLEN		0x400
6739235Sgibbs#else
6848602Smjacob#define	ISP2100_SCRLEN		0x100
6945284Smjacob#endif
7048487Smjacob#ifdef	SCSI_ISP_SCCLUN
7148487Smjacob#define	ISP2100_SCCLUN	1
7248487Smjacob#endif
7339235Sgibbs
7448487Smjacob#ifndef	SCSI_CHECK
7548487Smjacob#define	SCSI_CHECK	SCSI_STATUS_CHECK_COND
7648487Smjacob#endif
7748487Smjacob#ifndef	SCSI_BUSY
7848487Smjacob#define	SCSI_BUSY	SCSI_STATUS_BUSY
7948487Smjacob#endif
8048487Smjacob#ifndef	SCSI_QFULL
8148487Smjacob#define	SCSI_QFULL	SCSI_STATUS_QUEUE_FULL
8248487Smjacob#endif
8335388Smjacob
8448487Smjacob#define	ISP_SCSI_XFER_T		struct ccb_scsiio
8555366Smjacob
8655366Smjacob#ifdef	ISP_TARGET_MODE
8755366Smjacobtypedef struct tstate {
8855366Smjacob	struct tstate *next;
8955366Smjacob	struct cam_path *owner;
9055366Smjacob	struct ccb_hdr_slist atios;
9155366Smjacob	struct ccb_hdr_slist inots;
9255366Smjacob	lun_id_t lun;
9355366Smjacob	u_int32_t hold;
9455366Smjacob} tstate_t;
9555366Smjacob
9655366Smjacob/*
9755366Smjacob * This should work very well for 100% of parallel SCSI cases, 100%
9855366Smjacob * of non-SCCLUN FC cases, and hopefully some larger fraction of the
9955366Smjacob * SCCLUN FC cases. Basically, we index by the low 5 bits of lun and
10055366Smjacob * then linear search. This has to be reasonably zippy, but not crucially
10155366Smjacob * so.
10255366Smjacob */
10355366Smjacob#define	LUN_HASH_SIZE		32
10455366Smjacob#define	LUN_HASH_FUNC(lun)	((lun) & 0x1f)
10555366Smjacob
10655366Smjacob#endif
10755366Smjacob
10835388Smjacobstruct isposinfo {
10955366Smjacob	struct ispsoftc *	next;
11053489Smjacob	u_int64_t		default_wwn;
11135388Smjacob	char			name[8];
11235388Smjacob	int			unit;
11348487Smjacob	struct cam_sim		*sim;
11448487Smjacob	struct cam_path		*path;
11548487Smjacob	struct cam_sim		*sim2;
11648487Smjacob	struct cam_path		*path2;
11748487Smjacob	volatile char		simqfrozen;
11855366Smjacob#ifdef	ISP_TARGET_MODE
11955366Smjacob#define	TM_WANTED		0x01
12055366Smjacob#define	TM_BUSY			0x02
12155366Smjacob#define	TM_TMODE_ENABLED	0x80
12255366Smjacob	u_int8_t		tmflags;
12355366Smjacob	u_int8_t		rstatus;
12455366Smjacob	u_int16_t		rollinfo;
12555366Smjacob	tstate_t		tsdflt;
12655366Smjacob	tstate_t		*lun_hash[LUN_HASH_SIZE];
12755366Smjacob#endif
12835388Smjacob};
12948487Smjacob#define	SIMQFRZ_RESOURCE	0x1
13048487Smjacob#define	SIMQFRZ_LOOPDOWN	0x2
13149913Smjacob#define	SIMQFRZ_TIMED		0x4
13239235Sgibbs
13348487Smjacob#define	isp_sim		isp_osinfo.sim
13448487Smjacob#define	isp_path	isp_osinfo.path
13548487Smjacob#define	isp_sim2	isp_osinfo.sim2
13648487Smjacob#define	isp_path2	isp_osinfo.path2
13748487Smjacob#define	isp_unit	isp_osinfo.unit
13848487Smjacob#define	isp_name	isp_osinfo.name
13948487Smjacob
14048487Smjacob#define	MAXISPREQUEST		256
14148487Smjacob
14245284Smjacob#include <dev/isp/ispreg.h>
14345284Smjacob#include <dev/isp/ispvar.h>
14445284Smjacob#include <dev/isp/ispmbox.h>
14545284Smjacob
14652348Smjacob#define	DFLT_DBLEVEL		isp_debug
14752348Smjacobextern int isp_debug;
14835388Smjacob#define	ISP_LOCKVAL_DECL	int isp_spl_save
14942131Smjacob#define	ISP_ILOCKVAL_DECL	ISP_LOCKVAL_DECL
15039235Sgibbs#define	ISP_UNLOCK(isp)		(void) splx(isp_spl_save)
15148487Smjacob#define	ISP_LOCK(isp)		isp_spl_save = splcam()
15239235Sgibbs#define	ISP_ILOCK(isp)		ISP_LOCK(isp)
15339235Sgibbs#define	ISP_IUNLOCK(isp)	ISP_UNLOCK(isp)
15448487Smjacob#define	IMASK			cam_imask
15535388Smjacob
15648487Smjacob#define	XS_NULL(ccb)		ccb == NULL
15748487Smjacob#define	XS_ISP(ccb)		((struct ispsoftc *) (ccb)->ccb_h.spriv_ptr1)
15835388Smjacob
15948487Smjacob#define	XS_LUN(ccb)		(ccb)->ccb_h.target_lun
16048487Smjacob#define	XS_TGT(ccb)		(ccb)->ccb_h.target_id
16148487Smjacob#define	XS_CHANNEL(ccb)		cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path))
16248487Smjacob#define	XS_RESID(ccb)		(ccb)->resid
16348487Smjacob#define	XS_XFRLEN(ccb)		(ccb)->dxfer_len
16448487Smjacob#define	XS_CDBLEN(ccb)		(ccb)->cdb_len
16548487Smjacob#define	XS_CDBP(ccb)		(((ccb)->ccb_h.flags & CAM_CDB_POINTER)? \
16648487Smjacob	(ccb)->cdb_io.cdb_ptr : (ccb)->cdb_io.cdb_bytes)
16748487Smjacob#define	XS_STS(ccb)		(ccb)->scsi_status
16848487Smjacob#define	XS_TIME(ccb)		(ccb)->ccb_h.timeout
16948487Smjacob#define	XS_SNSP(ccb)		(&(ccb)->sense_data)
17052348Smjacob#define	XS_SNSLEN(ccb)		\
17152348Smjacob	imin((sizeof((ccb)->sense_data)), ccb->sense_len)
17248487Smjacob#define	XS_SNSKEY(ccb)		((ccb)->sense_data.flags & 0xf)
17335388Smjacob
17448487Smjacob/*
17548487Smjacob * A little tricky- HBA_NOERROR is "in progress" so
17648487Smjacob * that XS_CMD_DONE can transition this to CAM_REQ_CMP.
17748487Smjacob */
17848487Smjacob#define	HBA_NOERROR		CAM_REQ_INPROG
17948487Smjacob#define	HBA_BOTCH		CAM_UNREC_HBA_ERROR
18048487Smjacob#define	HBA_CMDTIMEOUT		CAM_CMD_TIMEOUT
18148487Smjacob#define	HBA_SELTIMEOUT		CAM_SEL_TIMEOUT
18248487Smjacob#define	HBA_TGTBSY		CAM_SCSI_STATUS_ERROR
18348487Smjacob#define	HBA_BUSRESET		CAM_SCSI_BUS_RESET
18448487Smjacob#define	HBA_ABORTED		CAM_REQ_ABORTED
18548487Smjacob#define	HBA_DATAOVR		CAM_DATA_RUN_ERR
18648487Smjacob#define	HBA_ARQFAIL		CAM_AUTOSENSE_FAIL
18735388Smjacob
18848487Smjacob#define	XS_SNS_IS_VALID(ccb) ((ccb)->ccb_h.status |= CAM_AUTOSNS_VALID)
18948487Smjacob#define	XS_IS_SNS_VALID(ccb) (((ccb)->ccb_h.status & CAM_AUTOSNS_VALID) != 0)
19035388Smjacob
19148487Smjacob#define	XS_INITERR(ccb)		\
19248487Smjacob	(ccb)->ccb_h.status &= ~CAM_STATUS_MASK, \
19348487Smjacob	(ccb)->ccb_h.status |= CAM_REQ_INPROG, \
19448487Smjacob	(ccb)->ccb_h.spriv_field0 = CAM_REQ_INPROG
19548487Smjacob#define	XS_SETERR(ccb, v)	(ccb)->ccb_h.spriv_field0 = v
19648487Smjacob#define	XS_ERR(ccb)		(ccb)->ccb_h.spriv_field0
19748487Smjacob#define	XS_NOERR(ccb)		\
19848487Smjacob	((ccb)->ccb_h.spriv_field0 == CAM_REQ_INPROG)
19935388Smjacob
20048487Smjacobextern void isp_done(struct ccb_scsiio *);
20148487Smjacob#define	XS_CMD_DONE(sccb)	isp_done(sccb)
20248487Smjacob
20348487Smjacob#define	XS_IS_CMD_DONE(ccb)	\
20448487Smjacob	(((ccb)->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG)
20548487Smjacob
20639235Sgibbs/*
20748487Smjacob * Can we tag?
20839235Sgibbs */
20948487Smjacob#define	XS_CANTAG(ccb)		(((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) \
21048487Smjacob				  && (ccb)->tag_action != CAM_TAG_ACTION_NONE)
21139235Sgibbs/*
21248487Smjacob * And our favorite tag is....
21339235Sgibbs */
21448487Smjacob#define	XS_KINDOF_TAG(ccb)	\
21548487Smjacob	((ccb->tag_action == MSG_SIMPLE_Q_TAG)? REQFLAG_STAG : \
21648487Smjacob	  ((ccb->tag_action == MSG_HEAD_OF_Q_TAG)? REQFLAG_HTAG : REQFLAG_OTAG))
21748487Smjacob
21848487Smjacob#define	CMD_COMPLETE		0
21948487Smjacob#define	CMD_EAGAIN		1
22048487Smjacob#define	CMD_QUEUED		2
22149913Smjacob#define	CMD_RQLATER		3
22248487Smjacob#define	STOP_WATCHDOG(f, s)
22335388Smjacob
22444819Smjacobextern void isp_attach(struct ispsoftc *);
22544819Smjacobextern void isp_uninit(struct ispsoftc *);
22644819Smjacob
22744819Smjacob#define	MEMZERO			bzero
22844819Smjacob#define	MEMCPY(dst, src, amt)	bcopy((src), (dst), (amt))
22944819Smjacob#ifdef	__alpha__
23044819Smjacob#define	MemoryBarrier	alpha_mb
23144819Smjacob#else
23244819Smjacob#define	MemoryBarrier()
23344819Smjacob#endif
23444819Smjacob
23544819Smjacob
23645284Smjacob#define	DMA_MSW(x)	(((x) >> 16) & 0xffff)
23745284Smjacob#define	DMA_LSW(x)	(((x) & 0xffff))
23845284Smjacob
23952348Smjacob#define	ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src)	\
24052348Smjacob	bcopy(src, dest, sizeof (isp_pdb_t))
24152348Smjacob#define	ISP_SWIZZLE_ICB(a, b)
24252348Smjacob#define	ISP_SWIZZLE_REQUEST(a, b)
24352348Smjacob#define	ISP_UNSWIZZLE_RESPONSE(a, b)
24452348Smjacob#define	ISP_SWIZZLE_SNS_REQ(a, b)
24552348Smjacob#define	ISP_UNSWIZZLE_SNS_RSP(a, b, c)
24652348Smjacob
24753489Smjacob#define	IDPRINTF(lev, x)	if (isp->isp_dblev >= (u_int8_t) lev) printf x
24844819Smjacob#define	PRINTF			printf
24954671Smjacob#define	CFGPRINTF		if (bootverbose || DFLT_DBLEVEL > 1) printf
25044819Smjacob
25144819Smjacob#define	SYS_DELAY(x)	DELAY(x)
25244819Smjacob
25344819Smjacob#define	FC_FW_READY_DELAY	(5 * 1000000)
25448487Smjacob#define	DEFAULT_LOOPID(x)	109
25553489Smjacob#define	DEFAULT_WWN(x)		(x)->isp_osinfo.default_wwn
25644819Smjacob
25752348Smjacob#define	INLINE	__inline
25852348Smjacob#include <dev/isp/isp_inline.h>
25935388Smjacob#endif	/* _ISP_FREEBSD_H */
260