xref: /freebsd/sys/dev/isp/isp_freebsd.h (revision f05ebe73)
1 /* $FreeBSD$ */
2 /* $Id: isp_freebsd.h,v 1.1 1998/04/22 17:54:52 mjacob Exp $ */
3 /*
4  * Qlogic ISP SCSI Host Adapter FreeBSD Wrapper Definitions (non CAM version)
5  *---------------------------------------
6  * Copyright (c) 1997, 1998 by Matthew Jacob
7  * NASA/Ames Research Center
8  * All rights reserved.
9  *---------------------------------------
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 immediately at the beginning of the file, without modification,
16  *    this list of conditions, and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. The name of the author may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
27  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  */
35 #ifndef	_ISP_FREEBSD_H
36 #define	_ISP_FREEBSD_H
37 
38 #include <pci.h>
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/malloc.h>
42 #include <sys/buf.h>
43 #include <sys/proc.h>
44 
45 #include <scsi/scsiconf.h>
46 #include <scsi/scsi_debug.h>
47 
48 #include <machine/clock.h>
49 #include <vm/vm.h>
50 #include <vm/vm_param.h>
51 #include <vm/pmap.h>
52 #include <sys/kernel.h>
53 
54 /*
55  * Quick hack fix to get around osreldate.h not being present.
56  * #include <osreldate.h>
57  */
58 #ifndef	__FreeBSD_version
59 #define	__FreeBSD_version	300002
60 #endif
61 
62 #define	ISP_SCSI_XFER_T		struct scsi_xfer
63 struct isposinfo {
64 	char			name[8];
65 	int			unit;
66 	struct scsi_link	_link;
67 #if	__FreeBSD_version >=	300001
68 	struct callout_handle	watchid;
69 #endif
70 };
71 /*
72  * XXXX: UNTIL WE PUT CODE IN THAT CHECKS RETURNS FROM MALLOC
73  * XXXX: FOR CONTIGOUS PAGES, WE LIMIT TO PAGE_SIZE THE SIZE
74  * XXXX: OF MAILBOXES.
75  */
76 #define	MAXISPREQUEST	64
77 
78 #define	ISP_VERSION_STRING	\
79 	"Version 0.92 Alpha Fri Apr 17 09:34:03 PDT 1998"
80 
81 #include <dev/isp/ispreg.h>
82 #include <dev/isp/ispvar.h>
83 #include <dev/isp/ispmbox.h>
84 
85 #define	PRINTF			printf
86 #define	IDPRINTF(lev, x)	if (isp->isp_dblev >= lev) printf x
87 #ifdef	SCSIDEBUG
88 #define	DFLT_DBLEVEL		2
89 #else
90 #define	DFLT_DBLEVEL		1
91 #endif
92 
93 #define	ISP_LOCKVAL_DECL	int isp_spl_save
94 #define	ISP_UNLOCK		(void) splx(isp_spl_save)
95 #define	ISP_LOCK		isp_spl_save = splbio()
96 #define	IMASK			bio_imask
97 
98 #define	XS_NULL(xs)		xs == NULL || xs->sc_link == NULL
99 #define	XS_ISP(xs)		(xs)->sc_link->adapter_softc
100 #define	XS_LUN(xs)		(xs)->sc_link->lun
101 #define	XS_TGT(xs)		(xs)->sc_link->target
102 #define	XS_RESID(xs)		(xs)->resid
103 #define	XS_XFRLEN(xs)		(xs)->datalen
104 #define	XS_CDBLEN(xs)		(xs)->cmdlen
105 #define	XS_CDBP(xs)		(xs)->cmd
106 #define	XS_STS(xs)		(xs)->status
107 #define	XS_TIME(xs)		(xs)->timeout
108 #define	XS_SNSP(xs)		(&(xs)->sense)
109 #define	XS_SNSLEN(xs)		(sizeof (xs)->sense)
110 #define	XS_SNSKEY(xs)		((xs)->sense.ext.extended.flags)
111 
112 #define	HBA_NOERROR		XS_NOERROR
113 #define	HBA_BOTCH		XS_DRIVER_STUFFUP
114 #define	HBA_CMDTIMEOUT		XS_TIMEOUT
115 #define	HBA_SELTIMEOUT		XS_SELTIMEOUT
116 #define	HBA_TGTBSY		XS_BUSY
117 #define	HBA_BUSRESET		XS_DRIVER_STUFFUP
118 #define	HBA_ABORTED		XS_DRIVER_STUFFUP
119 
120 #define	XS_SNS_IS_VALID(xs)	(xs)->error = XS_SENSE
121 #define	XS_IS_SNS_VALID(xs)	((xs)->error == XS_SENSE)
122 
123 #define	XS_INITERR(xs)		(xs)->error = 0
124 #define	XS_SETERR(xs, v)	(xs)->error = v
125 #define	XS_ERR(xs)		(xs)->error
126 #define	XS_NOERR(xs)		(xs)->error == XS_NOERROR
127 
128 #define	XS_CMD_DONE(xs)		(xs)->flags |= ITSDONE, scsi_done(xs)
129 #define	XS_IS_CMD_DONE(xs)	(((xs)->flags & ITSDONE) != 0)
130 
131 #define	XS_POLLDCMD(xs)		((xs)->flags & SCSI_NOMASK)
132 
133 #define	CMD_COMPLETE		COMPLETE
134 #define	CMD_EAGAIN		TRY_AGAIN_LATER
135 #define	CMD_QUEUED		SUCCESSFULLY_QUEUED
136 
137 
138 
139 #define	isp_name	isp_osinfo.name
140 
141 
142 #define	SYS_DELAY(x)	DELAY(x)
143 
144 #define	WATCH_INTERVAL		30
145 #if	__FreeBSD_version >=	300001
146 #define	START_WATCHDOG(f, s)	\
147 	(s)->isp_osinfo.watchid = timeout(f, s, WATCH_INTERVAL * hz), \
148 	s->isp_dogactive = 1
149 #define	STOP_WATCHDOG(f, s)	untimeout(f, s, (s)->isp_osinfo.watchid),\
150 	(s)->isp_dogactive = 0
151 #else
152 #define	START_WATCHDOG(f, s)	\
153 	timeout(f, s, WATCH_INTERVAL * hz), s->isp_dogactive = 1
154 #define	STOP_WATCHDOG(f, s)	untimeout(f, s), (s)->isp_dogactive = 0
155 #endif
156 
157 #define	RESTART_WATCHDOG(f, s)	START_WATCHDOG(f, s)
158 extern void isp_attach __P((struct ispsoftc *));
159 
160 #endif	/* _ISP_FREEBSD_H */
161