xref: /freebsd/sys/dev/isp/isp_freebsd.h (revision 0640d357f29fb1c0daaaffadd0416c5981413afd)
1 /* $FreeBSD$ */
2 /*
3  * Qlogic ISP SCSI Host Adapter FreeBSD Wrapper Definitions (non CAM version)
4  *---------------------------------------
5  * Copyright (c) 1997, 1998 by Matthew Jacob
6  * NASA/Ames Research Center
7  * All rights reserved.
8  *---------------------------------------
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice immediately at the beginning of the file, without modification,
15  *    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 AND CONTRIBUTORS ``AS IS'' AND
23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
26  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 #ifndef	_ISP_FREEBSD_H
35 #define	_ISP_FREEBSD_H
36 
37 #define	ISP_PLATFORM_VERSION_MAJOR	0
38 #define	ISP_PLATFORM_VERSION_MINOR	97
39 
40 #include <sys/param.h>
41 
42 #ifndef	__FreeBSD_version
43 #define	__FreeBSD_version	226000
44 #endif
45 
46 #if	__FreeBSD_version >= 300004
47 #include <dev/isp/isp_freebsd_cam.h>
48 #else
49 
50 #include <sys/systm.h>
51 #include <sys/malloc.h>
52 #include <sys/buf.h>
53 #include <sys/proc.h>
54 
55 #include <scsi/scsiconf.h>
56 #include <machine/clock.h>
57 #include <vm/vm.h>
58 #include <vm/vm_param.h>
59 #include <vm/pmap.h>
60 #include <sys/kernel.h>
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 #define	MAXISPREQUEST	64
73 
74 #include <dev/isp/ispreg.h>
75 #include <dev/isp/ispvar.h>
76 #include <dev/isp/ispmbox.h>
77 
78 #define	PRINTF			printf
79 #define	IDPRINTF(lev, x)	if (isp->isp_dblev >= lev) printf x
80 #define	DFLT_DBLEVEL		1
81 
82 #define	ISP_LOCKVAL_DECL	int isp_spl_save
83 #define	ISP_UNLOCK(isp)		(void) splx(isp_spl_save)
84 #define	ISP_LOCK(isp)		isp_spl_save = splbio()
85 #define	ISP_ILOCK(isp)		ISP_LOCK(isp)
86 #define	ISP_IUNLOCK(isp)	ISP_UNLOCK(isp)
87 #define	IMASK			bio_imask
88 
89 #define	XS_NULL(xs)		xs == NULL || xs->sc_link == NULL
90 #define	XS_ISP(xs)		\
91 	((struct ispsoftc *) (xs)->sc_link->adapter_softc)
92 #define	XS_LUN(xs)		(xs)->sc_link->lun
93 #define	XS_TGT(xs)		(xs)->sc_link->target
94 #define	XS_RESID(xs)		(xs)->resid
95 #define	XS_XFRLEN(xs)		(xs)->datalen
96 #define	XS_CDBLEN(xs)		(xs)->cmdlen
97 #define	XS_CDBP(xs)		(xs)->cmd
98 #define	XS_STS(xs)		(xs)->status
99 #define	XS_TIME(xs)		(xs)->timeout
100 #define	XS_SNSP(xs)		(&(xs)->sense)
101 #define	XS_SNSLEN(xs)		(sizeof (xs)->sense)
102 #define	XS_SNSKEY(xs)		((xs)->sense.ext.extended.flags)
103 
104 #define	HBA_NOERROR		XS_NOERROR
105 #define	HBA_BOTCH		XS_DRIVER_STUFFUP
106 #define	HBA_CMDTIMEOUT		XS_TIMEOUT
107 #define	HBA_SELTIMEOUT		XS_SELTIMEOUT
108 #define	HBA_TGTBSY		XS_BUSY
109 #define	HBA_BUSRESET		XS_DRIVER_STUFFUP
110 #define	HBA_ABORTED		XS_DRIVER_STUFFUP
111 #define	HBA_DATAOVR		XS_DRIVER_STUFFUP
112 #define	HBA_ARQFAIL		XS_DRIVER_STUFFUP
113 
114 #define	XS_SNS_IS_VALID(xs)	(xs)->error = XS_SENSE
115 #define	XS_IS_SNS_VALID(xs)	((xs)->error == XS_SENSE)
116 
117 #define	XS_INITERR(xs)		(xs)->error = 0
118 #define	XS_SETERR(xs, v)	(xs)->error = v
119 #define	XS_ERR(xs)		(xs)->error
120 #define	XS_NOERR(xs)		(xs)->error == XS_NOERROR
121 
122 #define	XS_CMD_DONE(xs)		(xs)->flags |= ITSDONE, scsi_done(xs)
123 #define	XS_IS_CMD_DONE(xs)	(((xs)->flags & ITSDONE) != 0)
124 
125 /*
126  * We decide whether to use tags based upon whether we're polling.
127  */
128 #define	XS_CANTAG(xs)		(((xs)->flags & SCSI_NOMASK) != 0)
129 
130 /*
131  * Our default tag
132  */
133 #define	XS_KINDOF_TAG(xs)	REQFLAG_OTAG
134 
135 
136 #define	CMD_COMPLETE		COMPLETE
137 #define	CMD_EAGAIN		TRY_AGAIN_LATER
138 #define	CMD_QUEUED		SUCCESSFULLY_QUEUED
139 
140 
141 
142 #define	isp_name	isp_osinfo.name
143 
144 
145 #define	SYS_DELAY(x)	DELAY(x)
146 
147 #define	WATCH_INTERVAL		30
148 #if	__FreeBSD_version >=	300001
149 #define	START_WATCHDOG(f, s)	\
150 	(s)->isp_osinfo.watchid = timeout(f, s, WATCH_INTERVAL * hz), \
151 	s->isp_dogactive = 1
152 #define	STOP_WATCHDOG(f, s)	untimeout(f, s, (s)->isp_osinfo.watchid),\
153 	(s)->isp_dogactive = 0
154 #else
155 #define	START_WATCHDOG(f, s)	\
156 	timeout(f, s, WATCH_INTERVAL * hz), s->isp_dogactive = 1
157 #define	STOP_WATCHDOG(f, s)	untimeout(f, s), (s)->isp_dogactive = 0
158 #endif
159 
160 #define	RESTART_WATCHDOG(f, s)	START_WATCHDOG(f, s)
161 extern void isp_attach __P((struct ispsoftc *));
162 
163 #define	PVS 				"Qlogic ISP Driver, FreeBSD Non-Cam"
164 
165 #endif	/* __FreeBSD_version >= 300004 */
166 #endif	/* _ISP_FREEBSD_H */
167