xref: /freebsd/sys/dev/isp/isp_freebsd.h (revision 9811e1f1a10f4fc6801ec5848aaa1ef4c286dd9b)
1 /* $FreeBSD$ */
2 /*
3  * Qlogic ISP SCSI Host Adapter FreeBSD Wrapper Definitions (CAM version)
4  *---------------------------------------
5  * Copyright (c) 1997, 1998, 1999 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	992
39 
40 
41 #include <sys/param.h>
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/kernel.h>
45 #include <sys/queue.h>
46 
47 #include <machine/bus_memio.h>
48 #include <machine/bus_pio.h>
49 #include <machine/bus.h>
50 #include <machine/clock.h>
51 
52 #include <cam/cam.h>
53 #include <cam/cam_debug.h>
54 #include <cam/cam_ccb.h>
55 #include <cam/cam_sim.h>
56 #include <cam/cam_xpt.h>
57 #include <cam/cam_xpt_sim.h>
58 #include <cam/cam_debug.h>
59 #include <cam/scsi/scsi_all.h>
60 #include <cam/scsi/scsi_message.h>
61 
62 #include "opt_isp.h"
63 #ifdef	SCSI_ISP_FABRIC
64 #define	ISP2100_FABRIC		1
65 #define	ISP2100_SCRLEN		0x400
66 #else
67 #define	ISP2100_SCRLEN		0x100
68 #endif
69 #ifdef	SCSI_ISP_SCCLUN
70 #define	ISP2100_SCCLUN	1
71 #endif
72 
73 #ifndef	SCSI_CHECK
74 #define	SCSI_CHECK	SCSI_STATUS_CHECK_COND
75 #endif
76 #ifndef	SCSI_BUSY
77 #define	SCSI_BUSY	SCSI_STATUS_BUSY
78 #endif
79 #ifndef	SCSI_QFULL
80 #define	SCSI_QFULL	SCSI_STATUS_QUEUE_FULL
81 #endif
82 
83 #define	ISP_SCSI_XFER_T		struct ccb_scsiio
84 struct isposinfo {
85 	char			name[8];
86 	int			unit;
87 	int			seed;
88 	struct cam_sim		*sim;
89 	struct cam_path		*path;
90 	struct cam_sim		*sim2;
91 	struct cam_path		*path2;
92 	volatile char		simqfrozen;
93 };
94 #define	SIMQFRZ_RESOURCE	0x1
95 #define	SIMQFRZ_LOOPDOWN	0x2
96 #define	SIMQFRZ_TIMED		0x4
97 
98 #define	isp_sim		isp_osinfo.sim
99 #define	isp_path	isp_osinfo.path
100 #define	isp_sim2	isp_osinfo.sim2
101 #define	isp_path2	isp_osinfo.path2
102 #define	isp_unit	isp_osinfo.unit
103 #define	isp_name	isp_osinfo.name
104 
105 #define	MAXISPREQUEST		256
106 
107 #include <dev/isp/ispreg.h>
108 #include <dev/isp/ispvar.h>
109 #include <dev/isp/ispmbox.h>
110 
111 #define	PVS			"Qlogic ISP Driver, FreeBSD CAM"
112 #ifdef	CAMDEBUG
113 #define	DFLT_DBLEVEL		2
114 #else
115 #define	DFLT_DBLEVEL		1
116 #endif
117 #define	ISP_LOCKVAL_DECL	int isp_spl_save
118 #define	ISP_ILOCKVAL_DECL	ISP_LOCKVAL_DECL
119 #define	ISP_UNLOCK(isp)		(void) splx(isp_spl_save)
120 #define	ISP_LOCK(isp)		isp_spl_save = splcam()
121 #define	ISP_ILOCK(isp)		ISP_LOCK(isp)
122 #define	ISP_IUNLOCK(isp)	ISP_UNLOCK(isp)
123 #define	IMASK			cam_imask
124 
125 #define	XS_NULL(ccb)		ccb == NULL
126 #define	XS_ISP(ccb)		((struct ispsoftc *) (ccb)->ccb_h.spriv_ptr1)
127 
128 #define	XS_LUN(ccb)		(ccb)->ccb_h.target_lun
129 #define	XS_TGT(ccb)		(ccb)->ccb_h.target_id
130 #define	XS_CHANNEL(ccb)		cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path))
131 #define	XS_RESID(ccb)		(ccb)->resid
132 #define	XS_XFRLEN(ccb)		(ccb)->dxfer_len
133 #define	XS_CDBLEN(ccb)		(ccb)->cdb_len
134 #define	XS_CDBP(ccb)		(((ccb)->ccb_h.flags & CAM_CDB_POINTER)? \
135 	(ccb)->cdb_io.cdb_ptr : (ccb)->cdb_io.cdb_bytes)
136 #define	XS_STS(ccb)		(ccb)->scsi_status
137 #define	XS_TIME(ccb)		(ccb)->ccb_h.timeout
138 #define	XS_SNSP(ccb)		(&(ccb)->sense_data)
139 #define	XS_SNSLEN(ccb)		imin((sizeof((ccb)->sense_data)), ccb->sense_len)
140 #define	XS_SNSKEY(ccb)		((ccb)->sense_data.flags & 0xf)
141 
142 /*
143  * A little tricky- HBA_NOERROR is "in progress" so
144  * that XS_CMD_DONE can transition this to CAM_REQ_CMP.
145  */
146 #define	HBA_NOERROR		CAM_REQ_INPROG
147 #define	HBA_BOTCH		CAM_UNREC_HBA_ERROR
148 #define	HBA_CMDTIMEOUT		CAM_CMD_TIMEOUT
149 #define	HBA_SELTIMEOUT		CAM_SEL_TIMEOUT
150 #define	HBA_TGTBSY		CAM_SCSI_STATUS_ERROR
151 #define	HBA_BUSRESET		CAM_SCSI_BUS_RESET
152 #define	HBA_ABORTED		CAM_REQ_ABORTED
153 #define	HBA_DATAOVR		CAM_DATA_RUN_ERR
154 #define	HBA_ARQFAIL		CAM_AUTOSENSE_FAIL
155 
156 #define	XS_SNS_IS_VALID(ccb) ((ccb)->ccb_h.status |= CAM_AUTOSNS_VALID)
157 #define	XS_IS_SNS_VALID(ccb) (((ccb)->ccb_h.status & CAM_AUTOSNS_VALID) != 0)
158 
159 #define	XS_INITERR(ccb)		\
160 	(ccb)->ccb_h.status &= ~CAM_STATUS_MASK, \
161 	(ccb)->ccb_h.status |= CAM_REQ_INPROG, \
162 	(ccb)->ccb_h.spriv_field0 = CAM_REQ_INPROG
163 #define	XS_SETERR(ccb, v)	(ccb)->ccb_h.spriv_field0 = v
164 #define	XS_ERR(ccb)		(ccb)->ccb_h.spriv_field0
165 #define	XS_NOERR(ccb)		\
166 	((ccb)->ccb_h.spriv_field0 == CAM_REQ_INPROG)
167 
168 extern void isp_done(struct ccb_scsiio *);
169 #define	XS_CMD_DONE(sccb)	isp_done(sccb)
170 
171 #define	XS_IS_CMD_DONE(ccb)	\
172 	(((ccb)->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG)
173 
174 /*
175  * Can we tag?
176  */
177 #define	XS_CANTAG(ccb)		(((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) \
178 				  && (ccb)->tag_action != CAM_TAG_ACTION_NONE)
179 /*
180  * And our favorite tag is....
181  */
182 #define	XS_KINDOF_TAG(ccb)	\
183 	((ccb->tag_action == MSG_SIMPLE_Q_TAG)? REQFLAG_STAG : \
184 	  ((ccb->tag_action == MSG_HEAD_OF_Q_TAG)? REQFLAG_HTAG : REQFLAG_OTAG))
185 
186 
187 
188 #define	CMD_COMPLETE		0
189 #define	CMD_EAGAIN		1
190 #define	CMD_QUEUED		2
191 #define	CMD_RQLATER		3
192 #define	STOP_WATCHDOG(f, s)
193 
194 extern void isp_attach(struct ispsoftc *);
195 extern void isp_uninit(struct ispsoftc *);
196 
197 #define	MEMZERO			bzero
198 #define	MEMCPY(dst, src, amt)	bcopy((src), (dst), (amt))
199 #ifdef	__alpha__
200 #define	MemoryBarrier	alpha_mb
201 #else
202 #define	MemoryBarrier()
203 #endif
204 
205 
206 #define	DMA_MSW(x)	(((x) >> 16) & 0xffff)
207 #define	DMA_LSW(x)	(((x) & 0xffff))
208 
209 #define	IDPRINTF(lev, x)	if (isp->isp_dblev >= lev) printf x
210 #define	PRINTF			printf
211 
212 #define	SYS_DELAY(x)	DELAY(x)
213 
214 #define	FC_FW_READY_DELAY	(5 * 1000000)
215 #define	DEFAULT_LOOPID(x)	109
216 #define	DEFAULT_WWN(x)		(0x0000feeb00000000LL + (x)->isp_osinfo.seed)
217 
218 static __inline void isp_prtstst(ispstatusreq_t *sp);
219 static __inline const char *isp2100_fw_statename(int state);
220 static __inline const char *isp2100_pdb_statename(int pdb_state);
221 
222 static __inline void isp_prtstst(ispstatusreq_t *sp)
223 {
224 	char buf[128];
225 	sprintf(buf, "states->");
226 	if (sp->req_state_flags & RQSF_GOT_BUS)
227 		sprintf(buf, "%s%s", buf, "GOT_BUS ");
228 	if (sp->req_state_flags & RQSF_GOT_TARGET)
229 		sprintf(buf, "%s%s", buf, "GOT_TGT ");
230 	if (sp->req_state_flags & RQSF_SENT_CDB)
231 		sprintf(buf, "%s%s", buf, "SENT_CDB ");
232 	if (sp->req_state_flags & RQSF_XFRD_DATA)
233 		sprintf(buf, "%s%s", buf, "XFRD_DATA ");
234 	if (sp->req_state_flags & RQSF_GOT_STATUS)
235 		sprintf(buf, "%s%s", buf, "GOT_STS ");
236 	if (sp->req_state_flags & RQSF_GOT_SENSE)
237 		sprintf(buf, "%s%s", buf, "GOT_SNS ");
238 	if (sp->req_state_flags & RQSF_XFER_COMPLETE)
239 		sprintf(buf, "%s%s", buf, "XFR_CMPLT ");
240 	sprintf(buf, "%s%s", buf, "\n");
241 	sprintf(buf, "%s%s", buf, "status->");
242 	if (sp->req_status_flags & RQSTF_DISCONNECT)
243 		sprintf(buf, "%s%s", buf, "Disconnect ");
244 	if (sp->req_status_flags & RQSTF_SYNCHRONOUS)
245 		sprintf(buf, "%s%s", buf, "Sync_xfr ");
246 	if (sp->req_status_flags & RQSTF_PARITY_ERROR)
247 		sprintf(buf, "%s%s", buf, "Parity ");
248 	if (sp->req_status_flags & RQSTF_BUS_RESET)
249 		sprintf(buf, "%s%s", buf, "Bus_Reset ");
250 	if (sp->req_status_flags & RQSTF_DEVICE_RESET)
251 		sprintf(buf, "%s%s", buf, "Device_Reset ");
252 	if (sp->req_status_flags & RQSTF_ABORTED)
253 		sprintf(buf, "%s%s", buf, "Aborted ");
254 	if (sp->req_status_flags & RQSTF_TIMEOUT)
255 		sprintf(buf, "%s%s", buf, "Timeout ");
256 	if (sp->req_status_flags & RQSTF_NEGOTIATION)
257 		sprintf(buf, "%s%s", buf, "Negotiation ");
258 	printf(buf, "%s\n", buf);
259 }
260 
261 static __inline const char *isp2100_fw_statename(int state)
262 {
263 	static char buf[16];
264 	switch(state) {
265 	case FW_CONFIG_WAIT:	return "Config Wait";
266 	case FW_WAIT_AL_PA:	return "Waiting for AL_PA";
267 	case FW_WAIT_LOGIN:	return "Wait Login";
268 	case FW_READY:		return "Ready";
269 	case FW_LOSS_OF_SYNC:	return "Loss Of Sync";
270 	case FW_ERROR:		return "Error";
271 	case FW_REINIT:		return "Re-Init";
272 	case FW_NON_PART:	return "Nonparticipating";
273 	default:
274 		sprintf(buf, "0x%x", state);
275 		return buf;
276 	}
277 }
278 
279 static __inline const char *isp2100_pdb_statename(int pdb_state)
280 {
281 	static char buf[16];
282 	switch(pdb_state) {
283 	case PDB_STATE_DISCOVERY:	return "Port Discovery";
284 	case PDB_STATE_WDISC_ACK:	return "Waiting Port Discovery ACK";
285 	case PDB_STATE_PLOGI:		return "Port Login";
286 	case PDB_STATE_PLOGI_ACK:	return "Wait Port Login ACK";
287 	case PDB_STATE_PRLI:		return "Process Login";
288 	case PDB_STATE_PRLI_ACK:	return "Wait Process Login ACK";
289 	case PDB_STATE_LOGGED_IN:	return "Logged In";
290 	case PDB_STATE_PORT_UNAVAIL:	return "Port Unavailable";
291 	case PDB_STATE_PRLO:		return "Process Logout";
292 	case PDB_STATE_PRLO_ACK:	return "Wait Process Logout ACK";
293 	case PDB_STATE_PLOGO:		return "Port Logout";
294 	case PDB_STATE_PLOG_ACK:	return "Wait Port Logout ACK";
295 	default:
296 		sprintf(buf, "0x%x", pdb_state);
297 		return buf;
298 	}
299 }
300 
301 #endif	/* _ISP_FREEBSD_H */
302