Deleted Added
full compact
isp_freebsd.h (64092) isp_freebsd.h (65140)
1/* $FreeBSD: head/sys/dev/isp/isp_freebsd.h 64092 2000-08-01 06:29:55Z mjacob $ */
1/* $FreeBSD: head/sys/dev/isp/isp_freebsd.h 65140 2000-08-27 23:38:44Z mjacob $ */
2/*
3 * Qlogic ISP SCSI Host Adapter FreeBSD Wrapper Definitions (CAM version)
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 *---------------------------------------
4 * Copyright (c) 1997, 1998, 1999, 2000 by Matthew Jacob
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.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice immediately at the beginning of the file, without modification,
11 * this list of conditions, and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * 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 5
38#define ISP_PLATFORM_VERSION_MINOR 3
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#include <sys/malloc.h>
47#include <sys/proc.h>
48
49#include <machine/bus_memio.h>
50#include <machine/bus_pio.h>
51#include <machine/bus.h>
52#include <machine/clock.h>
53#include <machine/cpu.h>
54
55#include <cam/cam.h>
56#include <cam/cam_debug.h>
57#include <cam/cam_ccb.h>
58#include <cam/cam_sim.h>
59#include <cam/cam_xpt.h>
60#include <cam/cam_xpt_sim.h>
61#include <cam/cam_debug.h>
62#include <cam/scsi/scsi_all.h>
63#include <cam/scsi/scsi_message.h>
64
65#include "opt_ddb.h"
66#include "opt_isp.h"
67
68typedef void ispfwfunc __P((int, int, int, const u_int16_t **));
69
70#ifdef ISP_TARGET_MODE
71typedef struct tstate {
72 struct tstate *next;
73 struct cam_path *owner;
74 struct ccb_hdr_slist atios;
75 struct ccb_hdr_slist inots;
76 lun_id_t lun;
77 u_int32_t hold;
78} tstate_t;
79
80/*
81 * This should work very well for 100% of parallel SCSI cases, 100%
82 * of non-SCCLUN FC cases, and hopefully some larger fraction of the
83 * SCCLUN FC cases. Basically, we index by the low 5 bits of lun and
84 * then linear search. This has to be reasonably zippy, but not crucially
85 * so.
86 */
87#define LUN_HASH_SIZE 32
88#define LUN_HASH_FUNC(lun) ((lun) & 0x1f)
89
90#endif
91
92struct isposinfo {
93 struct ispsoftc * next;
94 u_int64_t default_wwn;
95 char name[8];
96 int unit;
97 struct cam_sim *sim;
98 struct cam_path *path;
99 struct cam_sim *sim2;
100 struct cam_path *path2;
101 struct intr_config_hook ehook;
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28#ifndef _ISP_FREEBSD_H
29#define _ISP_FREEBSD_H
30
31#define ISP_PLATFORM_VERSION_MAJOR 5
32#define ISP_PLATFORM_VERSION_MINOR 3
33
34
35#include <sys/param.h>
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/kernel.h>
39#include <sys/queue.h>
40#include <sys/malloc.h>
41#include <sys/proc.h>
42
43#include <machine/bus_memio.h>
44#include <machine/bus_pio.h>
45#include <machine/bus.h>
46#include <machine/clock.h>
47#include <machine/cpu.h>
48
49#include <cam/cam.h>
50#include <cam/cam_debug.h>
51#include <cam/cam_ccb.h>
52#include <cam/cam_sim.h>
53#include <cam/cam_xpt.h>
54#include <cam/cam_xpt_sim.h>
55#include <cam/cam_debug.h>
56#include <cam/scsi/scsi_all.h>
57#include <cam/scsi/scsi_message.h>
58
59#include "opt_ddb.h"
60#include "opt_isp.h"
61
62typedef void ispfwfunc __P((int, int, int, const u_int16_t **));
63
64#ifdef ISP_TARGET_MODE
65typedef struct tstate {
66 struct tstate *next;
67 struct cam_path *owner;
68 struct ccb_hdr_slist atios;
69 struct ccb_hdr_slist inots;
70 lun_id_t lun;
71 u_int32_t hold;
72} tstate_t;
73
74/*
75 * This should work very well for 100% of parallel SCSI cases, 100%
76 * of non-SCCLUN FC cases, and hopefully some larger fraction of the
77 * SCCLUN FC cases. Basically, we index by the low 5 bits of lun and
78 * then linear search. This has to be reasonably zippy, but not crucially
79 * so.
80 */
81#define LUN_HASH_SIZE 32
82#define LUN_HASH_FUNC(lun) ((lun) & 0x1f)
83
84#endif
85
86struct isposinfo {
87 struct ispsoftc * next;
88 u_int64_t default_wwn;
89 char name[8];
90 int unit;
91 struct cam_sim *sim;
92 struct cam_path *path;
93 struct cam_sim *sim2;
94 struct cam_path *path2;
95 struct intr_config_hook ehook;
102 volatile u_int16_t : 14,
103 islocked : 1,
104 intsok : 1;
105 u_int8_t mboxwaiting;
106 u_int8_t simqfrozen;
96 u_int8_t mboxwaiting;
97 u_int8_t simqfrozen;
98 u_int8_t drain;
99#ifdef SERVICING_INTERRUPT
100 u_int8_t intsok;
101#else
102 u_int8_t padding;
103#endif
104 volatile u_int32_t islocked;
107 int splsaved;
108#ifdef ISP_TARGET_MODE
109#define TM_WANTED 0x01
110#define TM_BUSY 0x02
111#define TM_TMODE_ENABLED 0x80
112 u_int8_t tmflags;
113 u_int8_t rstatus;
114 u_int16_t rollinfo;
115 tstate_t tsdflt;
116 tstate_t *lun_hash[LUN_HASH_SIZE];
117#endif
118};
119
120/*
121 * Required Macros/Defines
122 */
123
124#define INLINE __inline
125
126#define ISP2100_FABRIC 1
127#define ISP2100_SCRLEN 0x400
128
129#define MEMZERO bzero
130#define MEMCPY(dst, src, amt) bcopy((src), (dst), (amt))
131#define SNPRINTF snprintf
132#define STRNCAT strncat
133#define USEC_DELAY DELAY
134
135#define NANOTIME_T struct timespec
136#define GET_NANOTIME nanotime
137#define GET_NANOSEC(x) ((x)->tv_sec * 1000000000 + (x)->tv_nsec)
138#define NANOTIME_SUB nanotime_sub
139
140#define MAXISPREQUEST(isp) 256
141
142#ifdef __alpha__
143#define MEMORYBARRIER(isp, type, offset, size) alpha_mb()
144#else
145#define MEMORYBARRIER(isp, type, offset, size)
146#endif
147
148#define MBOX_ACQUIRE(isp)
149#define MBOX_WAIT_COMPLETE isp_mbox_wait_complete
150#define MBOX_NOTIFY_COMPLETE(isp) \
151 if (isp->isp_osinfo.mboxwaiting) { \
152 isp->isp_osinfo.mboxwaiting = 0; \
153 wakeup(&isp->isp_osinfo.mboxwaiting); \
154 } \
155 isp->isp_mboxbsy = 0
156#define MBOX_RELEASE(isp)
157
158#ifndef SCSI_GOOD
159#define SCSI_GOOD SCSI_STATUS_OK
160#endif
161#ifndef SCSI_CHECK
162#define SCSI_CHECK SCSI_STATUS_CHECK_COND
163#endif
164#ifndef SCSI_BUSY
165#define SCSI_BUSY SCSI_STATUS_BUSY
166#endif
167#ifndef SCSI_QFULL
168#define SCSI_QFULL SCSI_STATUS_QUEUE_FULL
169#endif
170
171#define XS_T struct ccb_scsiio
172#define XS_ISP(ccb) ((struct ispsoftc *) (ccb)->ccb_h.spriv_ptr1)
173#define XS_CHANNEL(ccb) cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path))
174#define XS_TGT(ccb) (ccb)->ccb_h.target_id
175#define XS_LUN(ccb) (ccb)->ccb_h.target_lun
176
177#define XS_CDBP(ccb) \
178 (((ccb)->ccb_h.flags & CAM_CDB_POINTER)? \
179 (ccb)->cdb_io.cdb_ptr : (ccb)->cdb_io.cdb_bytes)
180
181#define XS_CDBLEN(ccb) (ccb)->cdb_len
182#define XS_XFRLEN(ccb) (ccb)->dxfer_len
183#define XS_TIME(ccb) (ccb)->ccb_h.timeout
184#define XS_RESID(ccb) (ccb)->resid
185#define XS_STSP(ccb) (&(ccb)->scsi_status)
186#define XS_SNSP(ccb) (&(ccb)->sense_data)
187
188#define XS_SNSLEN(ccb) \
189 imin((sizeof((ccb)->sense_data)), ccb->sense_len)
190
191#define XS_SNSKEY(ccb) ((ccb)->sense_data.flags & 0xf)
192#define XS_TAG_P(ccb) \
193 (((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) && \
194 (ccb)->tag_action != CAM_TAG_ACTION_NONE)
195
196#define XS_TAG_TYPE(ccb) \
197 ((ccb->tag_action == MSG_SIMPLE_Q_TAG)? REQFLAG_STAG : \
198 ((ccb->tag_action == MSG_HEAD_OF_Q_TAG)? REQFLAG_HTAG : REQFLAG_OTAG))
199
200
201#define XS_SETERR(ccb, v) (ccb)->ccb_h.status &= ~CAM_STATUS_MASK, \
202 (ccb)->ccb_h.status |= v, \
203 (ccb)->ccb_h.spriv_field0 |= ISP_SPRIV_ERRSET
204
205# define HBA_NOERROR CAM_REQ_INPROG
206# define HBA_BOTCH CAM_UNREC_HBA_ERROR
207# define HBA_CMDTIMEOUT CAM_CMD_TIMEOUT
208# define HBA_SELTIMEOUT CAM_SEL_TIMEOUT
209# define HBA_TGTBSY CAM_SCSI_STATUS_ERROR
210# define HBA_BUSRESET CAM_SCSI_BUS_RESET
211# define HBA_ABORTED CAM_REQ_ABORTED
212# define HBA_DATAOVR CAM_DATA_RUN_ERR
213# define HBA_ARQFAIL CAM_AUTOSENSE_FAIL
214
215
216#define XS_ERR(ccb) ((ccb)->ccb_h.status & CAM_STATUS_MASK)
217
218#define XS_NOERR(ccb) \
219 (((ccb)->ccb_h.spriv_field0 & ISP_SPRIV_ERRSET) == 0 || \
220 ((ccb)->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG)
221
222#define XS_INITERR(ccb) \
223 XS_SETERR(ccb, CAM_REQ_INPROG), (ccb)->ccb_h.spriv_field0 = 0
224
225#define XS_SAVE_SENSE(xs, sp) \
226 bcopy(sp->req_sense_data, &(xs)->sense_data, \
227 imin(XS_SNSLEN(xs), sp->req_sense_len))
228
229#define XS_SET_STATE_STAT(a, b, c)
230
231#define DEFAULT_IID(x) 7
232#define DEFAULT_LOOPID(x) 109
233#define DEFAULT_NODEWWN(isp) (isp)->isp_osinfo.default_wwn
234#define DEFAULT_PORTWWN(isp) \
235 isp_port_from_node_wwn((isp), (isp)->isp_osinfo.default_wwn)
236#define PORT_FROM_NODE_WWN isp_port_from_node_wwn
237
238#define ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src) \
239 if((void *)src != (void *)dest) bcopy(src, dest, sizeof (isp_pdb_t))
240#define ISP_SWIZZLE_ICB(a, b)
241#define ISP_SWIZZLE_REQUEST(a, b)
242#define ISP_UNSWIZZLE_RESPONSE(a, b, c)
243#define ISP_SWIZZLE_SNS_REQ(a, b)
244#define ISP_UNSWIZZLE_SNS_RSP(a, b, c)
245#define ISP_SWIZZLE_NVRAM_WORD(isp, x)
246
247/*
248 * Includes of common header files
249 */
250
251#include <dev/isp/ispreg.h>
252#include <dev/isp/ispvar.h>
253#include <dev/isp/ispmbox.h>
254
255/*
256 * isp_osinfo definiitions && shorthand
257 */
258#define SIMQFRZ_RESOURCE 0x1
259#define SIMQFRZ_LOOPDOWN 0x2
260#define SIMQFRZ_TIMED 0x4
261
262#define isp_sim isp_osinfo.sim
263#define isp_path isp_osinfo.path
264#define isp_sim2 isp_osinfo.sim2
265#define isp_path2 isp_osinfo.path2
266#define isp_unit isp_osinfo.unit
267#define isp_name isp_osinfo.name
268
269/*
270 * prototypes for isp_pci && isp_freebsd to share
271 */
272extern void isp_attach(struct ispsoftc *);
273extern void isp_uninit(struct ispsoftc *);
274
275/*
276 * Locking macros...
277 */
278
279#define ISP_LOCK isp_lock
280#define ISP_UNLOCK isp_unlock
281
282/* not safely working yet */
283#if 0
284#define SERVICING_INTERRUPT(isp) (intr_nesting_level != 0)
285#endif
286
287/*
288 * Platform private flags
289 */
290#define ISP_SPRIV_ERRSET 0x1
291#define ISP_SPRIV_INWDOG 0x2
292#define ISP_SPRIV_GRACE 0x4
293#define ISP_SPRIV_DONE 0x8
294
295#define XS_CMD_S_WDOG(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_INWDOG
296#define XS_CMD_C_WDOG(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_INWDOG
297#define XS_CMD_WDOG_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_INWDOG)
298
299#define XS_CMD_S_GRACE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_GRACE
300#define XS_CMD_C_GRACE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_GRACE
301#define XS_CMD_GRACE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_GRACE)
302
303#define XS_CMD_S_DONE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_DONE
304#define XS_CMD_C_DONE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_DONE
305#define XS_CMD_DONE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_DONE)
306
307#define XS_CMD_S_CLEAR(sccb) (sccb)->ccb_h.spriv_field0 = 0
308/*
309 * Platform specific inline functions
310 */
311
312static INLINE void isp_lock(struct ispsoftc *);
313static INLINE void
314isp_lock(struct ispsoftc *isp)
315{
316 int s = splcam();
105 int splsaved;
106#ifdef ISP_TARGET_MODE
107#define TM_WANTED 0x01
108#define TM_BUSY 0x02
109#define TM_TMODE_ENABLED 0x80
110 u_int8_t tmflags;
111 u_int8_t rstatus;
112 u_int16_t rollinfo;
113 tstate_t tsdflt;
114 tstate_t *lun_hash[LUN_HASH_SIZE];
115#endif
116};
117
118/*
119 * Required Macros/Defines
120 */
121
122#define INLINE __inline
123
124#define ISP2100_FABRIC 1
125#define ISP2100_SCRLEN 0x400
126
127#define MEMZERO bzero
128#define MEMCPY(dst, src, amt) bcopy((src), (dst), (amt))
129#define SNPRINTF snprintf
130#define STRNCAT strncat
131#define USEC_DELAY DELAY
132
133#define NANOTIME_T struct timespec
134#define GET_NANOTIME nanotime
135#define GET_NANOSEC(x) ((x)->tv_sec * 1000000000 + (x)->tv_nsec)
136#define NANOTIME_SUB nanotime_sub
137
138#define MAXISPREQUEST(isp) 256
139
140#ifdef __alpha__
141#define MEMORYBARRIER(isp, type, offset, size) alpha_mb()
142#else
143#define MEMORYBARRIER(isp, type, offset, size)
144#endif
145
146#define MBOX_ACQUIRE(isp)
147#define MBOX_WAIT_COMPLETE isp_mbox_wait_complete
148#define MBOX_NOTIFY_COMPLETE(isp) \
149 if (isp->isp_osinfo.mboxwaiting) { \
150 isp->isp_osinfo.mboxwaiting = 0; \
151 wakeup(&isp->isp_osinfo.mboxwaiting); \
152 } \
153 isp->isp_mboxbsy = 0
154#define MBOX_RELEASE(isp)
155
156#ifndef SCSI_GOOD
157#define SCSI_GOOD SCSI_STATUS_OK
158#endif
159#ifndef SCSI_CHECK
160#define SCSI_CHECK SCSI_STATUS_CHECK_COND
161#endif
162#ifndef SCSI_BUSY
163#define SCSI_BUSY SCSI_STATUS_BUSY
164#endif
165#ifndef SCSI_QFULL
166#define SCSI_QFULL SCSI_STATUS_QUEUE_FULL
167#endif
168
169#define XS_T struct ccb_scsiio
170#define XS_ISP(ccb) ((struct ispsoftc *) (ccb)->ccb_h.spriv_ptr1)
171#define XS_CHANNEL(ccb) cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path))
172#define XS_TGT(ccb) (ccb)->ccb_h.target_id
173#define XS_LUN(ccb) (ccb)->ccb_h.target_lun
174
175#define XS_CDBP(ccb) \
176 (((ccb)->ccb_h.flags & CAM_CDB_POINTER)? \
177 (ccb)->cdb_io.cdb_ptr : (ccb)->cdb_io.cdb_bytes)
178
179#define XS_CDBLEN(ccb) (ccb)->cdb_len
180#define XS_XFRLEN(ccb) (ccb)->dxfer_len
181#define XS_TIME(ccb) (ccb)->ccb_h.timeout
182#define XS_RESID(ccb) (ccb)->resid
183#define XS_STSP(ccb) (&(ccb)->scsi_status)
184#define XS_SNSP(ccb) (&(ccb)->sense_data)
185
186#define XS_SNSLEN(ccb) \
187 imin((sizeof((ccb)->sense_data)), ccb->sense_len)
188
189#define XS_SNSKEY(ccb) ((ccb)->sense_data.flags & 0xf)
190#define XS_TAG_P(ccb) \
191 (((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) && \
192 (ccb)->tag_action != CAM_TAG_ACTION_NONE)
193
194#define XS_TAG_TYPE(ccb) \
195 ((ccb->tag_action == MSG_SIMPLE_Q_TAG)? REQFLAG_STAG : \
196 ((ccb->tag_action == MSG_HEAD_OF_Q_TAG)? REQFLAG_HTAG : REQFLAG_OTAG))
197
198
199#define XS_SETERR(ccb, v) (ccb)->ccb_h.status &= ~CAM_STATUS_MASK, \
200 (ccb)->ccb_h.status |= v, \
201 (ccb)->ccb_h.spriv_field0 |= ISP_SPRIV_ERRSET
202
203# define HBA_NOERROR CAM_REQ_INPROG
204# define HBA_BOTCH CAM_UNREC_HBA_ERROR
205# define HBA_CMDTIMEOUT CAM_CMD_TIMEOUT
206# define HBA_SELTIMEOUT CAM_SEL_TIMEOUT
207# define HBA_TGTBSY CAM_SCSI_STATUS_ERROR
208# define HBA_BUSRESET CAM_SCSI_BUS_RESET
209# define HBA_ABORTED CAM_REQ_ABORTED
210# define HBA_DATAOVR CAM_DATA_RUN_ERR
211# define HBA_ARQFAIL CAM_AUTOSENSE_FAIL
212
213
214#define XS_ERR(ccb) ((ccb)->ccb_h.status & CAM_STATUS_MASK)
215
216#define XS_NOERR(ccb) \
217 (((ccb)->ccb_h.spriv_field0 & ISP_SPRIV_ERRSET) == 0 || \
218 ((ccb)->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG)
219
220#define XS_INITERR(ccb) \
221 XS_SETERR(ccb, CAM_REQ_INPROG), (ccb)->ccb_h.spriv_field0 = 0
222
223#define XS_SAVE_SENSE(xs, sp) \
224 bcopy(sp->req_sense_data, &(xs)->sense_data, \
225 imin(XS_SNSLEN(xs), sp->req_sense_len))
226
227#define XS_SET_STATE_STAT(a, b, c)
228
229#define DEFAULT_IID(x) 7
230#define DEFAULT_LOOPID(x) 109
231#define DEFAULT_NODEWWN(isp) (isp)->isp_osinfo.default_wwn
232#define DEFAULT_PORTWWN(isp) \
233 isp_port_from_node_wwn((isp), (isp)->isp_osinfo.default_wwn)
234#define PORT_FROM_NODE_WWN isp_port_from_node_wwn
235
236#define ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src) \
237 if((void *)src != (void *)dest) bcopy(src, dest, sizeof (isp_pdb_t))
238#define ISP_SWIZZLE_ICB(a, b)
239#define ISP_SWIZZLE_REQUEST(a, b)
240#define ISP_UNSWIZZLE_RESPONSE(a, b, c)
241#define ISP_SWIZZLE_SNS_REQ(a, b)
242#define ISP_UNSWIZZLE_SNS_RSP(a, b, c)
243#define ISP_SWIZZLE_NVRAM_WORD(isp, x)
244
245/*
246 * Includes of common header files
247 */
248
249#include <dev/isp/ispreg.h>
250#include <dev/isp/ispvar.h>
251#include <dev/isp/ispmbox.h>
252
253/*
254 * isp_osinfo definiitions && shorthand
255 */
256#define SIMQFRZ_RESOURCE 0x1
257#define SIMQFRZ_LOOPDOWN 0x2
258#define SIMQFRZ_TIMED 0x4
259
260#define isp_sim isp_osinfo.sim
261#define isp_path isp_osinfo.path
262#define isp_sim2 isp_osinfo.sim2
263#define isp_path2 isp_osinfo.path2
264#define isp_unit isp_osinfo.unit
265#define isp_name isp_osinfo.name
266
267/*
268 * prototypes for isp_pci && isp_freebsd to share
269 */
270extern void isp_attach(struct ispsoftc *);
271extern void isp_uninit(struct ispsoftc *);
272
273/*
274 * Locking macros...
275 */
276
277#define ISP_LOCK isp_lock
278#define ISP_UNLOCK isp_unlock
279
280/* not safely working yet */
281#if 0
282#define SERVICING_INTERRUPT(isp) (intr_nesting_level != 0)
283#endif
284
285/*
286 * Platform private flags
287 */
288#define ISP_SPRIV_ERRSET 0x1
289#define ISP_SPRIV_INWDOG 0x2
290#define ISP_SPRIV_GRACE 0x4
291#define ISP_SPRIV_DONE 0x8
292
293#define XS_CMD_S_WDOG(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_INWDOG
294#define XS_CMD_C_WDOG(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_INWDOG
295#define XS_CMD_WDOG_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_INWDOG)
296
297#define XS_CMD_S_GRACE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_GRACE
298#define XS_CMD_C_GRACE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_GRACE
299#define XS_CMD_GRACE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_GRACE)
300
301#define XS_CMD_S_DONE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_DONE
302#define XS_CMD_C_DONE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_DONE
303#define XS_CMD_DONE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_DONE)
304
305#define XS_CMD_S_CLEAR(sccb) (sccb)->ccb_h.spriv_field0 = 0
306/*
307 * Platform specific inline functions
308 */
309
310static INLINE void isp_lock(struct ispsoftc *);
311static INLINE void
312isp_lock(struct ispsoftc *isp)
313{
314 int s = splcam();
317 if (isp->isp_osinfo.islocked == 0) {
318 isp->isp_osinfo.islocked = 1;
315 if (isp->isp_osinfo.islocked++ == 0) {
319 isp->isp_osinfo.splsaved = s;
320 } else {
321 splx(s);
322 }
323}
324
325static INLINE void isp_unlock(struct ispsoftc *);
326static INLINE void
327isp_unlock(struct ispsoftc *isp)
328{
316 isp->isp_osinfo.splsaved = s;
317 } else {
318 splx(s);
319 }
320}
321
322static INLINE void isp_unlock(struct ispsoftc *);
323static INLINE void
324isp_unlock(struct ispsoftc *isp)
325{
329 if (isp->isp_osinfo.islocked) {
330 isp->isp_osinfo.islocked = 0;
326 if (--isp->isp_osinfo.islocked == 0) {
331 splx(isp->isp_osinfo.splsaved);
332 }
333}
334
335static INLINE void isp_mbox_wait_complete(struct ispsoftc *);
336static INLINE void
337isp_mbox_wait_complete(struct ispsoftc *isp)
338{
339#ifdef SERVICING_INTERRUPT
340 if (isp->isp_osinfo.intsok == 0 || SERVICING_INTERRUPT(isp)) {
341 int j;
342 for (j = 0; j < 60 * 2000; j++) {
343 if (isp_intr(isp) == 0) {
344 USEC_DELAY(500);
345 }
346 if (isp->isp_mboxbsy == 0) {
347 break;
348 }
349 }
350 if (isp->isp_mboxbsy != 0) {
351 isp_prt(isp, ISP_LOGWARN, "mailbox timeout");
352 }
353 } else {
354 isp->isp_osinfo.mboxwaiting = 1;
355 while (isp->isp_mboxbsy != 0) {
356 (void) tsleep(&isp->isp_osinfo.mboxwaiting, PRIBIO,
357 "isp_mailbox", 0);
358 }
359 }
360#else
361 int j;
362 for (j = 0; j < 60 * 2000; j++) {
363 if (isp_intr(isp) == 0) {
364 USEC_DELAY(500);
365 }
366 if (isp->isp_mboxbsy == 0) {
367 break;
368 }
369 }
370 if (isp->isp_mboxbsy != 0) {
371 isp_prt(isp, ISP_LOGWARN, "mailbox timeout");
372 }
373#endif
374}
375
376static INLINE u_int64_t nanotime_sub(struct timespec *, struct timespec *);
377static INLINE u_int64_t
378nanotime_sub(struct timespec *b, struct timespec *a)
379{
380 u_int64_t elapsed;
381 struct timespec x = *b;
382 timespecsub(&x, a);
383 elapsed = GET_NANOSEC(&x);
384 if (elapsed == 0)
385 elapsed++;
386 return (elapsed);
387}
388
389static INLINE char *strncat(char *, const char *, size_t);
390static INLINE char *
391strncat(char *d, const char *s, size_t c)
392{
393 char *t = d;
394
395 if (c) {
396 while (*d)
397 d++;
398 while ((*d++ = *s++)) {
399 if (--c == 0) {
400 *d = '\0';
401 break;
402 }
403 }
404 }
405 return (t);
406}
407
408static INLINE u_int64_t isp_port_from_node_wwn(struct ispsoftc *, u_int64_t);
409static INLINE u_int64_t
410isp_port_from_node_wwn(struct ispsoftc *isp, u_int64_t node_wwn)
411{
412 u_int64_t rv = node_wwn;
413 if ((node_wwn >> 60) == 2) {
414 rv = node_wwn |
415 (((u_int64_t)(isp->isp_unit+1)) << 48);
416 }
417 return (rv);
418}
419
420/*
421 * Common inline functions
422 */
423
424#include <dev/isp/isp_inline.h>
425#endif /* _ISP_FREEBSD_H */
327 splx(isp->isp_osinfo.splsaved);
328 }
329}
330
331static INLINE void isp_mbox_wait_complete(struct ispsoftc *);
332static INLINE void
333isp_mbox_wait_complete(struct ispsoftc *isp)
334{
335#ifdef SERVICING_INTERRUPT
336 if (isp->isp_osinfo.intsok == 0 || SERVICING_INTERRUPT(isp)) {
337 int j;
338 for (j = 0; j < 60 * 2000; j++) {
339 if (isp_intr(isp) == 0) {
340 USEC_DELAY(500);
341 }
342 if (isp->isp_mboxbsy == 0) {
343 break;
344 }
345 }
346 if (isp->isp_mboxbsy != 0) {
347 isp_prt(isp, ISP_LOGWARN, "mailbox timeout");
348 }
349 } else {
350 isp->isp_osinfo.mboxwaiting = 1;
351 while (isp->isp_mboxbsy != 0) {
352 (void) tsleep(&isp->isp_osinfo.mboxwaiting, PRIBIO,
353 "isp_mailbox", 0);
354 }
355 }
356#else
357 int j;
358 for (j = 0; j < 60 * 2000; j++) {
359 if (isp_intr(isp) == 0) {
360 USEC_DELAY(500);
361 }
362 if (isp->isp_mboxbsy == 0) {
363 break;
364 }
365 }
366 if (isp->isp_mboxbsy != 0) {
367 isp_prt(isp, ISP_LOGWARN, "mailbox timeout");
368 }
369#endif
370}
371
372static INLINE u_int64_t nanotime_sub(struct timespec *, struct timespec *);
373static INLINE u_int64_t
374nanotime_sub(struct timespec *b, struct timespec *a)
375{
376 u_int64_t elapsed;
377 struct timespec x = *b;
378 timespecsub(&x, a);
379 elapsed = GET_NANOSEC(&x);
380 if (elapsed == 0)
381 elapsed++;
382 return (elapsed);
383}
384
385static INLINE char *strncat(char *, const char *, size_t);
386static INLINE char *
387strncat(char *d, const char *s, size_t c)
388{
389 char *t = d;
390
391 if (c) {
392 while (*d)
393 d++;
394 while ((*d++ = *s++)) {
395 if (--c == 0) {
396 *d = '\0';
397 break;
398 }
399 }
400 }
401 return (t);
402}
403
404static INLINE u_int64_t isp_port_from_node_wwn(struct ispsoftc *, u_int64_t);
405static INLINE u_int64_t
406isp_port_from_node_wwn(struct ispsoftc *isp, u_int64_t node_wwn)
407{
408 u_int64_t rv = node_wwn;
409 if ((node_wwn >> 60) == 2) {
410 rv = node_wwn |
411 (((u_int64_t)(isp->isp_unit+1)) << 48);
412 }
413 return (rv);
414}
415
416/*
417 * Common inline functions
418 */
419
420#include <dev/isp/isp_inline.h>
421#endif /* _ISP_FREEBSD_H */