isp_freebsd.h revision 59452
150477Speter/* $FreeBSD: head/sys/dev/isp/isp_freebsd.h 59452 2000-04-21 02:05:13Z 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>
4659452Smjacob#include <sys/malloc.h>
4739445Smjacob
4848487Smjacob#include <machine/bus_memio.h>
4948487Smjacob#include <machine/bus_pio.h>
5048487Smjacob#include <machine/bus.h>
5148487Smjacob#include <machine/clock.h>
5239445Smjacob
5348487Smjacob#include <cam/cam.h>
5448487Smjacob#include <cam/cam_debug.h>
5548487Smjacob#include <cam/cam_ccb.h>
5648487Smjacob#include <cam/cam_sim.h>
5748487Smjacob#include <cam/cam_xpt.h>
5848487Smjacob#include <cam/cam_xpt_sim.h>
5948487Smjacob#include <cam/cam_debug.h>
6048487Smjacob#include <cam/scsi/scsi_all.h>
6148487Smjacob#include <cam/scsi/scsi_message.h>
6248487Smjacob
6352348Smjacob#include "opt_ddb.h"
6448487Smjacob#include "opt_isp.h"
6548487Smjacob#ifdef	SCSI_ISP_FABRIC
6648487Smjacob#define	ISP2100_FABRIC		1
6748487Smjacob#define	ISP2100_SCRLEN		0x400
6839235Sgibbs#else
6948602Smjacob#define	ISP2100_SCRLEN		0x100
7045284Smjacob#endif
7148487Smjacob#ifdef	SCSI_ISP_SCCLUN
7248487Smjacob#define	ISP2100_SCCLUN	1
7348487Smjacob#endif
7439235Sgibbs
7548487Smjacob#ifndef	SCSI_CHECK
7648487Smjacob#define	SCSI_CHECK	SCSI_STATUS_CHECK_COND
7748487Smjacob#endif
7848487Smjacob#ifndef	SCSI_BUSY
7948487Smjacob#define	SCSI_BUSY	SCSI_STATUS_BUSY
8048487Smjacob#endif
8148487Smjacob#ifndef	SCSI_QFULL
8248487Smjacob#define	SCSI_QFULL	SCSI_STATUS_QUEUE_FULL
8348487Smjacob#endif
8435388Smjacob
8548487Smjacob#define	ISP_SCSI_XFER_T		struct ccb_scsiio
8655366Smjacob
8755366Smjacob#ifdef	ISP_TARGET_MODE
8855366Smjacobtypedef struct tstate {
8955366Smjacob	struct tstate *next;
9055366Smjacob	struct cam_path *owner;
9155366Smjacob	struct ccb_hdr_slist atios;
9255366Smjacob	struct ccb_hdr_slist inots;
9355366Smjacob	lun_id_t lun;
9455366Smjacob	u_int32_t hold;
9555366Smjacob} tstate_t;
9655366Smjacob
9755366Smjacob/*
9855366Smjacob * This should work very well for 100% of parallel SCSI cases, 100%
9955366Smjacob * of non-SCCLUN FC cases, and hopefully some larger fraction of the
10055366Smjacob * SCCLUN FC cases. Basically, we index by the low 5 bits of lun and
10155366Smjacob * then linear search. This has to be reasonably zippy, but not crucially
10255366Smjacob * so.
10355366Smjacob */
10455366Smjacob#define	LUN_HASH_SIZE		32
10555366Smjacob#define	LUN_HASH_FUNC(lun)	((lun) & 0x1f)
10655366Smjacob
10755366Smjacob#endif
10855366Smjacob
10935388Smjacobstruct isposinfo {
11055366Smjacob	struct ispsoftc *	next;
11153489Smjacob	u_int64_t		default_wwn;
11235388Smjacob	char			name[8];
11335388Smjacob	int			unit;
11448487Smjacob	struct cam_sim		*sim;
11548487Smjacob	struct cam_path		*path;
11648487Smjacob	struct cam_sim		*sim2;
11748487Smjacob	struct cam_path		*path2;
11848487Smjacob	volatile char		simqfrozen;
11955366Smjacob#ifdef	ISP_TARGET_MODE
12055366Smjacob#define	TM_WANTED		0x01
12155366Smjacob#define	TM_BUSY			0x02
12255366Smjacob#define	TM_TMODE_ENABLED	0x80
12355366Smjacob	u_int8_t		tmflags;
12455366Smjacob	u_int8_t		rstatus;
12555366Smjacob	u_int16_t		rollinfo;
12655366Smjacob	tstate_t		tsdflt;
12755366Smjacob	tstate_t		*lun_hash[LUN_HASH_SIZE];
12855366Smjacob#endif
12935388Smjacob};
13048487Smjacob#define	SIMQFRZ_RESOURCE	0x1
13148487Smjacob#define	SIMQFRZ_LOOPDOWN	0x2
13249913Smjacob#define	SIMQFRZ_TIMED		0x4
13339235Sgibbs
13448487Smjacob#define	isp_sim		isp_osinfo.sim
13548487Smjacob#define	isp_path	isp_osinfo.path
13648487Smjacob#define	isp_sim2	isp_osinfo.sim2
13748487Smjacob#define	isp_path2	isp_osinfo.path2
13848487Smjacob#define	isp_unit	isp_osinfo.unit
13948487Smjacob#define	isp_name	isp_osinfo.name
14048487Smjacob
14148487Smjacob#define	MAXISPREQUEST		256
14248487Smjacob
14345284Smjacob#include <dev/isp/ispreg.h>
14445284Smjacob#include <dev/isp/ispvar.h>
14545284Smjacob#include <dev/isp/ispmbox.h>
14645284Smjacob
14752348Smjacob#define	DFLT_DBLEVEL		isp_debug
14852348Smjacobextern int isp_debug;
14935388Smjacob#define	ISP_LOCKVAL_DECL	int isp_spl_save
15042131Smjacob#define	ISP_ILOCKVAL_DECL	ISP_LOCKVAL_DECL
15139235Sgibbs#define	ISP_UNLOCK(isp)		(void) splx(isp_spl_save)
15248487Smjacob#define	ISP_LOCK(isp)		isp_spl_save = splcam()
15339235Sgibbs#define	ISP_ILOCK(isp)		ISP_LOCK(isp)
15439235Sgibbs#define	ISP_IUNLOCK(isp)	ISP_UNLOCK(isp)
15548487Smjacob#define	IMASK			cam_imask
15635388Smjacob
15748487Smjacob#define	XS_NULL(ccb)		ccb == NULL
15848487Smjacob#define	XS_ISP(ccb)		((struct ispsoftc *) (ccb)->ccb_h.spriv_ptr1)
15935388Smjacob
16048487Smjacob#define	XS_LUN(ccb)		(ccb)->ccb_h.target_lun
16148487Smjacob#define	XS_TGT(ccb)		(ccb)->ccb_h.target_id
16248487Smjacob#define	XS_CHANNEL(ccb)		cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path))
16348487Smjacob#define	XS_RESID(ccb)		(ccb)->resid
16448487Smjacob#define	XS_XFRLEN(ccb)		(ccb)->dxfer_len
16548487Smjacob#define	XS_CDBLEN(ccb)		(ccb)->cdb_len
16648487Smjacob#define	XS_CDBP(ccb)		(((ccb)->ccb_h.flags & CAM_CDB_POINTER)? \
16748487Smjacob	(ccb)->cdb_io.cdb_ptr : (ccb)->cdb_io.cdb_bytes)
16848487Smjacob#define	XS_STS(ccb)		(ccb)->scsi_status
16948487Smjacob#define	XS_TIME(ccb)		(ccb)->ccb_h.timeout
17048487Smjacob#define	XS_SNSP(ccb)		(&(ccb)->sense_data)
17152348Smjacob#define	XS_SNSLEN(ccb)		\
17252348Smjacob	imin((sizeof((ccb)->sense_data)), ccb->sense_len)
17348487Smjacob#define	XS_SNSKEY(ccb)		((ccb)->sense_data.flags & 0xf)
17435388Smjacob
17548487Smjacob/*
17648487Smjacob * A little tricky- HBA_NOERROR is "in progress" so
17748487Smjacob * that XS_CMD_DONE can transition this to CAM_REQ_CMP.
17848487Smjacob */
17948487Smjacob#define	HBA_NOERROR		CAM_REQ_INPROG
18048487Smjacob#define	HBA_BOTCH		CAM_UNREC_HBA_ERROR
18148487Smjacob#define	HBA_CMDTIMEOUT		CAM_CMD_TIMEOUT
18248487Smjacob#define	HBA_SELTIMEOUT		CAM_SEL_TIMEOUT
18348487Smjacob#define	HBA_TGTBSY		CAM_SCSI_STATUS_ERROR
18448487Smjacob#define	HBA_BUSRESET		CAM_SCSI_BUS_RESET
18548487Smjacob#define	HBA_ABORTED		CAM_REQ_ABORTED
18648487Smjacob#define	HBA_DATAOVR		CAM_DATA_RUN_ERR
18748487Smjacob#define	HBA_ARQFAIL		CAM_AUTOSENSE_FAIL
18835388Smjacob
18948487Smjacob#define	XS_SNS_IS_VALID(ccb) ((ccb)->ccb_h.status |= CAM_AUTOSNS_VALID)
19048487Smjacob#define	XS_IS_SNS_VALID(ccb) (((ccb)->ccb_h.status & CAM_AUTOSNS_VALID) != 0)
19135388Smjacob
19248487Smjacob#define	XS_INITERR(ccb)		\
19348487Smjacob	(ccb)->ccb_h.status &= ~CAM_STATUS_MASK, \
19448487Smjacob	(ccb)->ccb_h.status |= CAM_REQ_INPROG, \
19548487Smjacob	(ccb)->ccb_h.spriv_field0 = CAM_REQ_INPROG
19648487Smjacob#define	XS_SETERR(ccb, v)	(ccb)->ccb_h.spriv_field0 = v
19748487Smjacob#define	XS_ERR(ccb)		(ccb)->ccb_h.spriv_field0
19848487Smjacob#define	XS_NOERR(ccb)		\
19948487Smjacob	((ccb)->ccb_h.spriv_field0 == CAM_REQ_INPROG)
20035388Smjacob
20148487Smjacobextern void isp_done(struct ccb_scsiio *);
20248487Smjacob#define	XS_CMD_DONE(sccb)	isp_done(sccb)
20348487Smjacob
20448487Smjacob#define	XS_IS_CMD_DONE(ccb)	\
20548487Smjacob	(((ccb)->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG)
20648487Smjacob
20739235Sgibbs/*
20848487Smjacob * Can we tag?
20939235Sgibbs */
21048487Smjacob#define	XS_CANTAG(ccb)		(((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) \
21148487Smjacob				  && (ccb)->tag_action != CAM_TAG_ACTION_NONE)
21239235Sgibbs/*
21348487Smjacob * And our favorite tag is....
21439235Sgibbs */
21548487Smjacob#define	XS_KINDOF_TAG(ccb)	\
21648487Smjacob	((ccb->tag_action == MSG_SIMPLE_Q_TAG)? REQFLAG_STAG : \
21748487Smjacob	  ((ccb->tag_action == MSG_HEAD_OF_Q_TAG)? REQFLAG_HTAG : REQFLAG_OTAG))
21848487Smjacob
21948487Smjacob#define	CMD_COMPLETE		0
22048487Smjacob#define	CMD_EAGAIN		1
22148487Smjacob#define	CMD_QUEUED		2
22249913Smjacob#define	CMD_RQLATER		3
22348487Smjacob#define	STOP_WATCHDOG(f, s)
22435388Smjacob
22544819Smjacobextern void isp_attach(struct ispsoftc *);
22644819Smjacobextern void isp_uninit(struct ispsoftc *);
22744819Smjacob
22844819Smjacob#define	MEMZERO			bzero
22944819Smjacob#define	MEMCPY(dst, src, amt)	bcopy((src), (dst), (amt))
23044819Smjacob#ifdef	__alpha__
23144819Smjacob#define	MemoryBarrier	alpha_mb
23244819Smjacob#else
23344819Smjacob#define	MemoryBarrier()
23444819Smjacob#endif
23544819Smjacob
23644819Smjacob
23745284Smjacob#define	DMA_MSW(x)	(((x) >> 16) & 0xffff)
23845284Smjacob#define	DMA_LSW(x)	(((x) & 0xffff))
23945284Smjacob
24052348Smjacob#define	ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src)	\
24152348Smjacob	bcopy(src, dest, sizeof (isp_pdb_t))
24252348Smjacob#define	ISP_SWIZZLE_ICB(a, b)
24352348Smjacob#define	ISP_SWIZZLE_REQUEST(a, b)
24452348Smjacob#define	ISP_UNSWIZZLE_RESPONSE(a, b)
24552348Smjacob#define	ISP_SWIZZLE_SNS_REQ(a, b)
24652348Smjacob#define	ISP_UNSWIZZLE_SNS_RSP(a, b, c)
24752348Smjacob
24853489Smjacob#define	IDPRINTF(lev, x)	if (isp->isp_dblev >= (u_int8_t) lev) printf x
24944819Smjacob#define	PRINTF			printf
25054671Smjacob#define	CFGPRINTF		if (bootverbose || DFLT_DBLEVEL > 1) printf
25144819Smjacob
25244819Smjacob#define	SYS_DELAY(x)	DELAY(x)
25344819Smjacob
25444819Smjacob#define	FC_FW_READY_DELAY	(5 * 1000000)
25548487Smjacob#define	DEFAULT_LOOPID(x)	109
25653489Smjacob#define	DEFAULT_WWN(x)		(x)->isp_osinfo.default_wwn
25744819Smjacob
25852348Smjacob#define	INLINE	__inline
25952348Smjacob#include <dev/isp/isp_inline.h>
26035388Smjacob#endif	/* _ISP_FREEBSD_H */
261