Deleted Added
full compact
isp_freebsd.h (155285) isp_freebsd.h (155704)
1/* $FreeBSD: head/sys/dev/isp/isp_freebsd.h 155285 2006-02-04 08:39:02Z mjacob $ */
1/* $FreeBSD: head/sys/dev/isp/isp_freebsd.h 155704 2006-02-15 00:31:48Z mjacob $ */
2/*-
3 * Qlogic ISP SCSI Host Adapter FreeBSD Wrapper Definitions
4 *
5 * Copyright (c) 1997-2006 by Matthew Jacob
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice immediately at the beginning of the file, without modification,
13 * this list of conditions, and the following disclaimer.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29#ifndef _ISP_FREEBSD_H
30#define _ISP_FREEBSD_H
31
32#define ISP_PLATFORM_VERSION_MAJOR 5
33#define ISP_PLATFORM_VERSION_MINOR 9
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/endian.h>
38#include <sys/kernel.h>
39#include <sys/queue.h>
40#include <sys/lock.h>
41#include <sys/malloc.h>
42#include <sys/mutex.h>
43#include <sys/condvar.h>
44#include <sys/proc.h>
45#include <sys/bus.h>
46
47#include <machine/bus.h>
48#include <machine/clock.h>
49#include <machine/cpu.h>
50
51#include <cam/cam.h>
52#include <cam/cam_debug.h>
53#include <cam/cam_ccb.h>
54#include <cam/cam_sim.h>
55#include <cam/cam_xpt.h>
56#include <cam/cam_xpt_sim.h>
57#include <cam/cam_debug.h>
58#include <cam/scsi/scsi_all.h>
59#include <cam/scsi/scsi_message.h>
60
61#include "opt_ddb.h"
62#include "opt_isp.h"
63
2/*-
3 * Qlogic ISP SCSI Host Adapter FreeBSD Wrapper Definitions
4 *
5 * Copyright (c) 1997-2006 by Matthew Jacob
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice immediately at the beginning of the file, without modification,
13 * this list of conditions, and the following disclaimer.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29#ifndef _ISP_FREEBSD_H
30#define _ISP_FREEBSD_H
31
32#define ISP_PLATFORM_VERSION_MAJOR 5
33#define ISP_PLATFORM_VERSION_MINOR 9
34
35#include <sys/param.h>
36#include <sys/systm.h>
37#include <sys/endian.h>
38#include <sys/kernel.h>
39#include <sys/queue.h>
40#include <sys/lock.h>
41#include <sys/malloc.h>
42#include <sys/mutex.h>
43#include <sys/condvar.h>
44#include <sys/proc.h>
45#include <sys/bus.h>
46
47#include <machine/bus.h>
48#include <machine/clock.h>
49#include <machine/cpu.h>
50
51#include <cam/cam.h>
52#include <cam/cam_debug.h>
53#include <cam/cam_ccb.h>
54#include <cam/cam_sim.h>
55#include <cam/cam_xpt.h>
56#include <cam/cam_xpt_sim.h>
57#include <cam/cam_debug.h>
58#include <cam/scsi/scsi_all.h>
59#include <cam/scsi/scsi_message.h>
60
61#include "opt_ddb.h"
62#include "opt_isp.h"
63
64/* disabled until done correctly */
65/* #define ISP_DAC_SUPPORTED 1 */
66
67/*
68 * Efficiency- get rid of SBus code && tests unless we need them.
69 */
70#ifdef __sparc64__
71#define ISP_SBUS_SUPPORTED 1
72#else
73#define ISP_SBUS_SUPPORTED 0
74#endif
75
76#define HANDLE_LOOPSTATE_IN_OUTER_LAYERS 1
77/* #define ISP_SMPLOCK 1 */
78
79#ifdef ISP_SMPLOCK
80#define ISP_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY | INTR_MPSAFE
81#else
82#define ISP_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY
83#endif
84
64/*
65 * Efficiency- get rid of SBus code && tests unless we need them.
66 */
67#ifdef __sparc64__
68#define ISP_SBUS_SUPPORTED 1
69#else
70#define ISP_SBUS_SUPPORTED 0
71#endif
72
73#define HANDLE_LOOPSTATE_IN_OUTER_LAYERS 1
74/* #define ISP_SMPLOCK 1 */
75
76#ifdef ISP_SMPLOCK
77#define ISP_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY | INTR_MPSAFE
78#else
79#define ISP_IFLAGS INTR_TYPE_CAM | INTR_ENTROPY
80#endif
81
85typedef void ispfwfunc(int, int, int, u_int16_t **);
82typedef void ispfwfunc(int, int, int, uint16_t **);
86
87#ifdef ISP_TARGET_MODE
88#define ISP_TARGET_FUNCTIONS 1
89#define ATPDPSIZE 256
90typedef struct {
83
84#ifdef ISP_TARGET_MODE
85#define ISP_TARGET_FUNCTIONS 1
86#define ATPDPSIZE 256
87typedef struct {
91 u_int32_t orig_datalen;
92 u_int32_t bytes_xfered;
93 u_int32_t last_xframt;
94 u_int32_t tag : 16,
88 uint32_t orig_datalen;
89 uint32_t bytes_xfered;
90 uint32_t last_xframt;
91 uint32_t tag : 16,
95 lun : 13, /* not enough */
96 state : 3;
97} atio_private_data_t;
98#define ATPD_STATE_FREE 0
99#define ATPD_STATE_ATIO 1
100#define ATPD_STATE_CAM 2
101#define ATPD_STATE_CTIO 3
102#define ATPD_STATE_LAST_CTIO 4
103#define ATPD_STATE_PDON 5
104
105typedef struct tstate {
106 struct tstate *next;
107 struct cam_path *owner;
108 struct ccb_hdr_slist atios;
109 struct ccb_hdr_slist inots;
110 lun_id_t lun;
111 int bus;
92 lun : 13, /* not enough */
93 state : 3;
94} atio_private_data_t;
95#define ATPD_STATE_FREE 0
96#define ATPD_STATE_ATIO 1
97#define ATPD_STATE_CAM 2
98#define ATPD_STATE_CTIO 3
99#define ATPD_STATE_LAST_CTIO 4
100#define ATPD_STATE_PDON 5
101
102typedef struct tstate {
103 struct tstate *next;
104 struct cam_path *owner;
105 struct ccb_hdr_slist atios;
106 struct ccb_hdr_slist inots;
107 lun_id_t lun;
108 int bus;
112 u_int32_t hold;
109 uint32_t hold;
113 int atio_count;
114 int inot_count;
115} tstate_t;
116
117#define LUN_HASH_SIZE 32
118#define LUN_HASH_FUNC(isp, port, lun) \
119 ((IS_DUALBUS(isp)) ? \
120 (((lun) & ((LUN_HASH_SIZE >> 1) - 1)) << (port)) : \
121 ((lun) & (LUN_HASH_SIZE - 1)))
122#endif
123
124struct isposinfo {
125 struct ispsoftc * next;
110 int atio_count;
111 int inot_count;
112} tstate_t;
113
114#define LUN_HASH_SIZE 32
115#define LUN_HASH_FUNC(isp, port, lun) \
116 ((IS_DUALBUS(isp)) ? \
117 (((lun) & ((LUN_HASH_SIZE >> 1) - 1)) << (port)) : \
118 ((lun) & (LUN_HASH_SIZE - 1)))
119#endif
120
121struct isposinfo {
122 struct ispsoftc * next;
126 u_int64_t default_port_wwn;
127 u_int64_t default_node_wwn;
128 u_int32_t default_id;
123 uint64_t default_port_wwn;
124 uint64_t default_node_wwn;
125 uint32_t default_id;
129 device_t dev;
130 struct cam_sim *sim;
131 struct cam_path *path;
132 struct cam_sim *sim2;
133 struct cam_path *path2;
134 struct intr_config_hook ehook;
126 device_t dev;
127 struct cam_sim *sim;
128 struct cam_path *path;
129 struct cam_sim *sim2;
130 struct cam_path *path2;
131 struct intr_config_hook ehook;
135 u_int8_t : 1,
132 uint8_t : 1,
136 fcbsy : 1,
137 ktmature : 1,
138 mboxwaiting : 1,
139 intsok : 1,
140 simqfrozen : 3;
141 struct mtx lock;
142 struct cv kthread_cv;
143 struct proc *kproc;
144 bus_dma_tag_t cdmat;
145 bus_dmamap_t cdmap;
146#define isp_cdmat isp_osinfo.cdmat
147#define isp_cdmap isp_osinfo.cdmap
148#ifdef ISP_TARGET_MODE
149#define TM_WILDCARD_ENABLED 0x02
150#define TM_TMODE_ENABLED 0x01
133 fcbsy : 1,
134 ktmature : 1,
135 mboxwaiting : 1,
136 intsok : 1,
137 simqfrozen : 3;
138 struct mtx lock;
139 struct cv kthread_cv;
140 struct proc *kproc;
141 bus_dma_tag_t cdmat;
142 bus_dmamap_t cdmap;
143#define isp_cdmat isp_osinfo.cdmat
144#define isp_cdmap isp_osinfo.cdmap
145#ifdef ISP_TARGET_MODE
146#define TM_WILDCARD_ENABLED 0x02
147#define TM_TMODE_ENABLED 0x01
151 u_int8_t tmflags[2]; /* two busses */
148 uint8_t tmflags[2]; /* two busses */
152#define NLEACT 4
153 union ccb * leact[NLEACT];
154 tstate_t tsdflt[2]; /* two busses */
155 tstate_t *lun_hash[LUN_HASH_SIZE];
156 atio_private_data_t atpdp[ATPDPSIZE];
157#endif
158};
159
160#define isp_lock isp_osinfo.lock
161
162/*
163 * Locking macros...
164 */
165
166#ifdef ISP_SMPLOCK
167#define ISP_LOCK(x) mtx_lock(&(x)->isp_lock)
168#define ISP_UNLOCK(x) mtx_unlock(&(x)->isp_lock)
169#define ISPLOCK_2_CAMLOCK(isp) \
170 mtx_unlock(&(isp)->isp_lock); mtx_lock(&Giant)
171#define CAMLOCK_2_ISPLOCK(isp) \
172 mtx_unlock(&Giant); mtx_lock(&(isp)->isp_lock)
173#else
174#define ISP_LOCK(x) do { } while (0)
175#define ISP_UNLOCK(x) do { } while (0)
176#define ISPLOCK_2_CAMLOCK(isp) do { } while (0)
177#define CAMLOCK_2_ISPLOCK(isp) do { } while (0)
178#endif
179
180/*
181 * Required Macros/Defines
182 */
183
184#define ISP2100_SCRLEN 0x800
185
186#define MEMZERO bzero
187#define MEMCPY(dst, src, amt) bcopy((src), (dst), (amt))
188#define SNPRINTF snprintf
189#define USEC_DELAY DELAY
190#define USEC_SLEEP(isp, x) \
191 if (isp->isp_osinfo.intsok) \
192 ISP_UNLOCK(isp); \
193 DELAY(x); \
194 if (isp->isp_osinfo.intsok) \
195 ISP_LOCK(isp)
196
197#define NANOTIME_T struct timespec
198#define GET_NANOTIME nanotime
199#define GET_NANOSEC(x) ((x)->tv_sec * 1000000000 + (x)->tv_nsec)
200#define NANOTIME_SUB nanotime_sub
201
202#define MAXISPREQUEST(isp) ((IS_FC(isp) || IS_ULTRA2(isp))? 1024 : 256)
203
204#define MEMORYBARRIER(isp, type, offset, size) \
205switch (type) { \
206case SYNC_SFORDEV: \
207case SYNC_REQUEST: \
208 bus_dmamap_sync(isp->isp_cdmat, isp->isp_cdmap, \
209 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); \
210 break; \
211case SYNC_SFORCPU: \
212case SYNC_RESULT: \
213 bus_dmamap_sync(isp->isp_cdmat, isp->isp_cdmap, \
214 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); \
215 break; \
216default: \
217 break; \
218}
219
220#define MBOX_ACQUIRE(isp)
221#define MBOX_WAIT_COMPLETE isp_mbox_wait_complete
222#define MBOX_NOTIFY_COMPLETE(isp) \
223 if (isp->isp_osinfo.mboxwaiting) { \
224 isp->isp_osinfo.mboxwaiting = 0; \
225 wakeup(&isp->isp_mbxworkp); \
226 } \
227 isp->isp_mboxbsy = 0
228#define MBOX_RELEASE(isp)
229
230#define FC_SCRATCH_ACQUIRE(isp) \
231 if (isp->isp_osinfo.fcbsy) { \
232 isp_prt(isp, ISP_LOGWARN, \
233 "FC scratch area busy (line %d)!", __LINE__); \
234 } else \
235 isp->isp_osinfo.fcbsy = 1
236#define FC_SCRATCH_RELEASE(isp) isp->isp_osinfo.fcbsy = 0
237
238#ifndef SCSI_GOOD
239#define SCSI_GOOD SCSI_STATUS_OK
240#endif
241#ifndef SCSI_CHECK
242#define SCSI_CHECK SCSI_STATUS_CHECK_COND
243#endif
244#ifndef SCSI_BUSY
245#define SCSI_BUSY SCSI_STATUS_BUSY
246#endif
247#ifndef SCSI_QFULL
248#define SCSI_QFULL SCSI_STATUS_QUEUE_FULL
249#endif
250
251#define XS_T struct ccb_scsiio
149#define NLEACT 4
150 union ccb * leact[NLEACT];
151 tstate_t tsdflt[2]; /* two busses */
152 tstate_t *lun_hash[LUN_HASH_SIZE];
153 atio_private_data_t atpdp[ATPDPSIZE];
154#endif
155};
156
157#define isp_lock isp_osinfo.lock
158
159/*
160 * Locking macros...
161 */
162
163#ifdef ISP_SMPLOCK
164#define ISP_LOCK(x) mtx_lock(&(x)->isp_lock)
165#define ISP_UNLOCK(x) mtx_unlock(&(x)->isp_lock)
166#define ISPLOCK_2_CAMLOCK(isp) \
167 mtx_unlock(&(isp)->isp_lock); mtx_lock(&Giant)
168#define CAMLOCK_2_ISPLOCK(isp) \
169 mtx_unlock(&Giant); mtx_lock(&(isp)->isp_lock)
170#else
171#define ISP_LOCK(x) do { } while (0)
172#define ISP_UNLOCK(x) do { } while (0)
173#define ISPLOCK_2_CAMLOCK(isp) do { } while (0)
174#define CAMLOCK_2_ISPLOCK(isp) do { } while (0)
175#endif
176
177/*
178 * Required Macros/Defines
179 */
180
181#define ISP2100_SCRLEN 0x800
182
183#define MEMZERO bzero
184#define MEMCPY(dst, src, amt) bcopy((src), (dst), (amt))
185#define SNPRINTF snprintf
186#define USEC_DELAY DELAY
187#define USEC_SLEEP(isp, x) \
188 if (isp->isp_osinfo.intsok) \
189 ISP_UNLOCK(isp); \
190 DELAY(x); \
191 if (isp->isp_osinfo.intsok) \
192 ISP_LOCK(isp)
193
194#define NANOTIME_T struct timespec
195#define GET_NANOTIME nanotime
196#define GET_NANOSEC(x) ((x)->tv_sec * 1000000000 + (x)->tv_nsec)
197#define NANOTIME_SUB nanotime_sub
198
199#define MAXISPREQUEST(isp) ((IS_FC(isp) || IS_ULTRA2(isp))? 1024 : 256)
200
201#define MEMORYBARRIER(isp, type, offset, size) \
202switch (type) { \
203case SYNC_SFORDEV: \
204case SYNC_REQUEST: \
205 bus_dmamap_sync(isp->isp_cdmat, isp->isp_cdmap, \
206 BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE); \
207 break; \
208case SYNC_SFORCPU: \
209case SYNC_RESULT: \
210 bus_dmamap_sync(isp->isp_cdmat, isp->isp_cdmap, \
211 BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); \
212 break; \
213default: \
214 break; \
215}
216
217#define MBOX_ACQUIRE(isp)
218#define MBOX_WAIT_COMPLETE isp_mbox_wait_complete
219#define MBOX_NOTIFY_COMPLETE(isp) \
220 if (isp->isp_osinfo.mboxwaiting) { \
221 isp->isp_osinfo.mboxwaiting = 0; \
222 wakeup(&isp->isp_mbxworkp); \
223 } \
224 isp->isp_mboxbsy = 0
225#define MBOX_RELEASE(isp)
226
227#define FC_SCRATCH_ACQUIRE(isp) \
228 if (isp->isp_osinfo.fcbsy) { \
229 isp_prt(isp, ISP_LOGWARN, \
230 "FC scratch area busy (line %d)!", __LINE__); \
231 } else \
232 isp->isp_osinfo.fcbsy = 1
233#define FC_SCRATCH_RELEASE(isp) isp->isp_osinfo.fcbsy = 0
234
235#ifndef SCSI_GOOD
236#define SCSI_GOOD SCSI_STATUS_OK
237#endif
238#ifndef SCSI_CHECK
239#define SCSI_CHECK SCSI_STATUS_CHECK_COND
240#endif
241#ifndef SCSI_BUSY
242#define SCSI_BUSY SCSI_STATUS_BUSY
243#endif
244#ifndef SCSI_QFULL
245#define SCSI_QFULL SCSI_STATUS_QUEUE_FULL
246#endif
247
248#define XS_T struct ccb_scsiio
249#define XS_DMA_ADDR_T bus_addr_t
252#define XS_ISP(ccb) ((struct ispsoftc *) (ccb)->ccb_h.spriv_ptr1)
253#define XS_CHANNEL(ccb) cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path))
254#define XS_TGT(ccb) (ccb)->ccb_h.target_id
255#define XS_LUN(ccb) (ccb)->ccb_h.target_lun
256
257#define XS_CDBP(ccb) \
258 (((ccb)->ccb_h.flags & CAM_CDB_POINTER)? \
259 (ccb)->cdb_io.cdb_ptr : (ccb)->cdb_io.cdb_bytes)
260
261#define XS_CDBLEN(ccb) (ccb)->cdb_len
262#define XS_XFRLEN(ccb) (ccb)->dxfer_len
263#define XS_TIME(ccb) (ccb)->ccb_h.timeout
264#define XS_RESID(ccb) (ccb)->resid
265#define XS_STSP(ccb) (&(ccb)->scsi_status)
266#define XS_SNSP(ccb) (&(ccb)->sense_data)
267
268#define XS_SNSLEN(ccb) \
269 imin((sizeof((ccb)->sense_data)), ccb->sense_len)
270
271#define XS_SNSKEY(ccb) ((ccb)->sense_data.flags & 0xf)
272#define XS_TAG_P(ccb) \
273 (((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) && \
274 (ccb)->tag_action != CAM_TAG_ACTION_NONE)
275
276#define XS_TAG_TYPE(ccb) \
277 ((ccb->tag_action == MSG_SIMPLE_Q_TAG)? REQFLAG_STAG : \
278 ((ccb->tag_action == MSG_HEAD_OF_Q_TAG)? REQFLAG_HTAG : REQFLAG_OTAG))
279
280
281#define XS_SETERR(ccb, v) (ccb)->ccb_h.status &= ~CAM_STATUS_MASK, \
282 (ccb)->ccb_h.status |= v, \
283 (ccb)->ccb_h.spriv_field0 |= ISP_SPRIV_ERRSET
284
285# define HBA_NOERROR CAM_REQ_INPROG
286# define HBA_BOTCH CAM_UNREC_HBA_ERROR
287# define HBA_CMDTIMEOUT CAM_CMD_TIMEOUT
288# define HBA_SELTIMEOUT CAM_SEL_TIMEOUT
289# define HBA_TGTBSY CAM_SCSI_STATUS_ERROR
290# define HBA_BUSRESET CAM_SCSI_BUS_RESET
291# define HBA_ABORTED CAM_REQ_ABORTED
292# define HBA_DATAOVR CAM_DATA_RUN_ERR
293# define HBA_ARQFAIL CAM_AUTOSENSE_FAIL
294
295
296#define XS_ERR(ccb) ((ccb)->ccb_h.status & CAM_STATUS_MASK)
297
298#define XS_NOERR(ccb) \
299 (((ccb)->ccb_h.spriv_field0 & ISP_SPRIV_ERRSET) == 0 || \
300 ((ccb)->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG)
301
302#define XS_INITERR(ccb) \
303 XS_SETERR(ccb, CAM_REQ_INPROG), (ccb)->ccb_h.spriv_field0 = 0
304
305#define XS_SAVE_SENSE(xs, sp) \
306 (xs)->ccb_h.status |= CAM_AUTOSNS_VALID, \
307 bcopy(sp->req_sense_data, &(xs)->sense_data, \
308 imin(XS_SNSLEN(xs), sp->req_sense_len))
309
310#define XS_SET_STATE_STAT(a, b, c)
311
312#define DEFAULT_IID(x) (isp)->isp_osinfo.default_id
313#define DEFAULT_LOOPID(x) (isp)->isp_osinfo.default_id
314#define DEFAULT_NODEWWN(isp) (isp)->isp_osinfo.default_node_wwn
315#define DEFAULT_PORTWWN(isp) (isp)->isp_osinfo.default_port_wwn
316#define ISP_NODEWWN(isp) FCPARAM(isp)->isp_nodewwn
317#define ISP_PORTWWN(isp) FCPARAM(isp)->isp_portwwn
318
319#if BYTE_ORDER == BIG_ENDIAN
320#ifdef ISP_SBUS_SUPPORTED
321#define ISP_IOXPUT_8(isp, s, d) *(d) = s
322#define ISP_IOXPUT_16(isp, s, d) \
323 *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap16(s)
324#define ISP_IOXPUT_32(isp, s, d) \
325 *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap32(s)
250#define XS_ISP(ccb) ((struct ispsoftc *) (ccb)->ccb_h.spriv_ptr1)
251#define XS_CHANNEL(ccb) cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path))
252#define XS_TGT(ccb) (ccb)->ccb_h.target_id
253#define XS_LUN(ccb) (ccb)->ccb_h.target_lun
254
255#define XS_CDBP(ccb) \
256 (((ccb)->ccb_h.flags & CAM_CDB_POINTER)? \
257 (ccb)->cdb_io.cdb_ptr : (ccb)->cdb_io.cdb_bytes)
258
259#define XS_CDBLEN(ccb) (ccb)->cdb_len
260#define XS_XFRLEN(ccb) (ccb)->dxfer_len
261#define XS_TIME(ccb) (ccb)->ccb_h.timeout
262#define XS_RESID(ccb) (ccb)->resid
263#define XS_STSP(ccb) (&(ccb)->scsi_status)
264#define XS_SNSP(ccb) (&(ccb)->sense_data)
265
266#define XS_SNSLEN(ccb) \
267 imin((sizeof((ccb)->sense_data)), ccb->sense_len)
268
269#define XS_SNSKEY(ccb) ((ccb)->sense_data.flags & 0xf)
270#define XS_TAG_P(ccb) \
271 (((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) && \
272 (ccb)->tag_action != CAM_TAG_ACTION_NONE)
273
274#define XS_TAG_TYPE(ccb) \
275 ((ccb->tag_action == MSG_SIMPLE_Q_TAG)? REQFLAG_STAG : \
276 ((ccb->tag_action == MSG_HEAD_OF_Q_TAG)? REQFLAG_HTAG : REQFLAG_OTAG))
277
278
279#define XS_SETERR(ccb, v) (ccb)->ccb_h.status &= ~CAM_STATUS_MASK, \
280 (ccb)->ccb_h.status |= v, \
281 (ccb)->ccb_h.spriv_field0 |= ISP_SPRIV_ERRSET
282
283# define HBA_NOERROR CAM_REQ_INPROG
284# define HBA_BOTCH CAM_UNREC_HBA_ERROR
285# define HBA_CMDTIMEOUT CAM_CMD_TIMEOUT
286# define HBA_SELTIMEOUT CAM_SEL_TIMEOUT
287# define HBA_TGTBSY CAM_SCSI_STATUS_ERROR
288# define HBA_BUSRESET CAM_SCSI_BUS_RESET
289# define HBA_ABORTED CAM_REQ_ABORTED
290# define HBA_DATAOVR CAM_DATA_RUN_ERR
291# define HBA_ARQFAIL CAM_AUTOSENSE_FAIL
292
293
294#define XS_ERR(ccb) ((ccb)->ccb_h.status & CAM_STATUS_MASK)
295
296#define XS_NOERR(ccb) \
297 (((ccb)->ccb_h.spriv_field0 & ISP_SPRIV_ERRSET) == 0 || \
298 ((ccb)->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG)
299
300#define XS_INITERR(ccb) \
301 XS_SETERR(ccb, CAM_REQ_INPROG), (ccb)->ccb_h.spriv_field0 = 0
302
303#define XS_SAVE_SENSE(xs, sp) \
304 (xs)->ccb_h.status |= CAM_AUTOSNS_VALID, \
305 bcopy(sp->req_sense_data, &(xs)->sense_data, \
306 imin(XS_SNSLEN(xs), sp->req_sense_len))
307
308#define XS_SET_STATE_STAT(a, b, c)
309
310#define DEFAULT_IID(x) (isp)->isp_osinfo.default_id
311#define DEFAULT_LOOPID(x) (isp)->isp_osinfo.default_id
312#define DEFAULT_NODEWWN(isp) (isp)->isp_osinfo.default_node_wwn
313#define DEFAULT_PORTWWN(isp) (isp)->isp_osinfo.default_port_wwn
314#define ISP_NODEWWN(isp) FCPARAM(isp)->isp_nodewwn
315#define ISP_PORTWWN(isp) FCPARAM(isp)->isp_portwwn
316
317#if BYTE_ORDER == BIG_ENDIAN
318#ifdef ISP_SBUS_SUPPORTED
319#define ISP_IOXPUT_8(isp, s, d) *(d) = s
320#define ISP_IOXPUT_16(isp, s, d) \
321 *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap16(s)
322#define ISP_IOXPUT_32(isp, s, d) \
323 *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap32(s)
326#define ISP_IOXGET_8(isp, s, d) d = (*((u_int8_t *)s))
324#define ISP_IOXGET_8(isp, s, d) d = (*((uint8_t *)s))
327#define ISP_IOXGET_16(isp, s, d) \
328 d = (isp->isp_bustype == ISP_BT_SBUS)? \
325#define ISP_IOXGET_16(isp, s, d) \
326 d = (isp->isp_bustype == ISP_BT_SBUS)? \
329 *((u_int16_t *)s) : bswap16(*((u_int16_t *)s))
327 *((uint16_t *)s) : bswap16(*((uint16_t *)s))
330#define ISP_IOXGET_32(isp, s, d) \
331 d = (isp->isp_bustype == ISP_BT_SBUS)? \
328#define ISP_IOXGET_32(isp, s, d) \
329 d = (isp->isp_bustype == ISP_BT_SBUS)? \
332 *((u_int32_t *)s) : bswap32(*((u_int32_t *)s))
330 *((uint32_t *)s) : bswap32(*((uint32_t *)s))
333#else
334#define ISP_IOXPUT_8(isp, s, d) *(d) = s
335#define ISP_IOXPUT_16(isp, s, d) *(d) = bswap16(s)
336#define ISP_IOXPUT_32(isp, s, d) *(d) = bswap32(s)
331#else
332#define ISP_IOXPUT_8(isp, s, d) *(d) = s
333#define ISP_IOXPUT_16(isp, s, d) *(d) = bswap16(s)
334#define ISP_IOXPUT_32(isp, s, d) *(d) = bswap32(s)
337#define ISP_IOXGET_8(isp, s, d) d = (*((u_int8_t *)s))
338#define ISP_IOXGET_16(isp, s, d) d = bswap16(*((u_int16_t *)s))
339#define ISP_IOXGET_32(isp, s, d) d = bswap32(*((u_int32_t *)s))
335#define ISP_IOXGET_8(isp, s, d) d = (*((uint8_t *)s))
336#define ISP_IOXGET_16(isp, s, d) d = bswap16(*((uint16_t *)s))
337#define ISP_IOXGET_32(isp, s, d) d = bswap32(*((uint32_t *)s))
340#endif
341#define ISP_SWIZZLE_NVRAM_WORD(isp, rp) *rp = bswap16(*rp)
342#else
343#define ISP_IOXPUT_8(isp, s, d) *(d) = s
344#define ISP_IOXPUT_16(isp, s, d) *(d) = s
345#define ISP_IOXPUT_32(isp, s, d) *(d) = s
346#define ISP_IOXGET_8(isp, s, d) d = *(s)
347#define ISP_IOXGET_16(isp, s, d) d = *(s)
348#define ISP_IOXGET_32(isp, s, d) d = *(s)
349#define ISP_SWIZZLE_NVRAM_WORD(isp, rp)
350#endif
351
352/*
353 * Includes of common header files
354 */
355
356#include <dev/isp/ispreg.h>
357#include <dev/isp/ispvar.h>
358#include <dev/isp/ispmbox.h>
359
338#endif
339#define ISP_SWIZZLE_NVRAM_WORD(isp, rp) *rp = bswap16(*rp)
340#else
341#define ISP_IOXPUT_8(isp, s, d) *(d) = s
342#define ISP_IOXPUT_16(isp, s, d) *(d) = s
343#define ISP_IOXPUT_32(isp, s, d) *(d) = s
344#define ISP_IOXGET_8(isp, s, d) d = *(s)
345#define ISP_IOXGET_16(isp, s, d) d = *(s)
346#define ISP_IOXGET_32(isp, s, d) d = *(s)
347#define ISP_SWIZZLE_NVRAM_WORD(isp, rp)
348#endif
349
350/*
351 * Includes of common header files
352 */
353
354#include <dev/isp/ispreg.h>
355#include <dev/isp/ispvar.h>
356#include <dev/isp/ispmbox.h>
357
358#ifdef ISP_TARGET_MODE
359#include <dev/isp/isp_tpublic.h>
360#endif
361
360void isp_prt(struct ispsoftc *, int level, const char *, ...)
361 __printflike(3, 4);
362/*
363 * isp_osinfo definiitions && shorthand
364 */
365#define SIMQFRZ_RESOURCE 0x1
366#define SIMQFRZ_LOOPDOWN 0x2
367#define SIMQFRZ_TIMED 0x4
368
369#define isp_sim isp_osinfo.sim
370#define isp_path isp_osinfo.path
371#define isp_sim2 isp_osinfo.sim2
372#define isp_path2 isp_osinfo.path2
373#define isp_dev isp_osinfo.dev
374
375/*
376 * prototypes for isp_pci && isp_freebsd to share
377 */
378extern void isp_attach(struct ispsoftc *);
379extern void isp_uninit(struct ispsoftc *);
380
381/*
382 * driver global data
383 */
384extern int isp_announced;
385
386/*
387 * Platform private flags
388 */
389#define ISP_SPRIV_ERRSET 0x1
390#define ISP_SPRIV_INWDOG 0x2
391#define ISP_SPRIV_GRACE 0x4
392#define ISP_SPRIV_DONE 0x8
393
394#define XS_CMD_S_WDOG(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_INWDOG
395#define XS_CMD_C_WDOG(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_INWDOG
396#define XS_CMD_WDOG_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_INWDOG)
397
398#define XS_CMD_S_GRACE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_GRACE
399#define XS_CMD_C_GRACE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_GRACE
400#define XS_CMD_GRACE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_GRACE)
401
402#define XS_CMD_S_DONE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_DONE
403#define XS_CMD_C_DONE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_DONE
404#define XS_CMD_DONE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_DONE)
405
406#define XS_CMD_S_CLEAR(sccb) (sccb)->ccb_h.spriv_field0 = 0
407
408/*
409 * Platform specific inline functions
410 */
411
412static __inline void isp_mbox_wait_complete(struct ispsoftc *);
413static __inline void
414isp_mbox_wait_complete(struct ispsoftc *isp)
415{
416 if (isp->isp_osinfo.intsok) {
417 int lim = ((isp->isp_mbxwrk0)? 120 : 20) * hz;
418 isp->isp_osinfo.mboxwaiting = 1;
419#ifdef ISP_SMPLOCK
420 (void) msleep(&isp->isp_mbxworkp,
421 &isp->isp_lock, PRIBIO, "isp_mboxwaiting", lim);
422#else
423 (void) tsleep(&isp->isp_mbxworkp,
424 PRIBIO, "isp_mboxwaiting", lim);
425#endif
426 if (isp->isp_mboxbsy != 0) {
427 isp_prt(isp, ISP_LOGWARN,
428 "Interrupting Mailbox Command (0x%x) Timeout",
429 isp->isp_lastmbxcmd);
430 isp->isp_mboxbsy = 0;
431 }
432 isp->isp_osinfo.mboxwaiting = 0;
433 } else {
434 int lim = ((isp->isp_mbxwrk0)? 240 : 60) * 10000;
435 int j;
436 for (j = 0; j < lim; j++) {
362void isp_prt(struct ispsoftc *, int level, const char *, ...)
363 __printflike(3, 4);
364/*
365 * isp_osinfo definiitions && shorthand
366 */
367#define SIMQFRZ_RESOURCE 0x1
368#define SIMQFRZ_LOOPDOWN 0x2
369#define SIMQFRZ_TIMED 0x4
370
371#define isp_sim isp_osinfo.sim
372#define isp_path isp_osinfo.path
373#define isp_sim2 isp_osinfo.sim2
374#define isp_path2 isp_osinfo.path2
375#define isp_dev isp_osinfo.dev
376
377/*
378 * prototypes for isp_pci && isp_freebsd to share
379 */
380extern void isp_attach(struct ispsoftc *);
381extern void isp_uninit(struct ispsoftc *);
382
383/*
384 * driver global data
385 */
386extern int isp_announced;
387
388/*
389 * Platform private flags
390 */
391#define ISP_SPRIV_ERRSET 0x1
392#define ISP_SPRIV_INWDOG 0x2
393#define ISP_SPRIV_GRACE 0x4
394#define ISP_SPRIV_DONE 0x8
395
396#define XS_CMD_S_WDOG(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_INWDOG
397#define XS_CMD_C_WDOG(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_INWDOG
398#define XS_CMD_WDOG_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_INWDOG)
399
400#define XS_CMD_S_GRACE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_GRACE
401#define XS_CMD_C_GRACE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_GRACE
402#define XS_CMD_GRACE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_GRACE)
403
404#define XS_CMD_S_DONE(sccb) (sccb)->ccb_h.spriv_field0 |= ISP_SPRIV_DONE
405#define XS_CMD_C_DONE(sccb) (sccb)->ccb_h.spriv_field0 &= ~ISP_SPRIV_DONE
406#define XS_CMD_DONE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_DONE)
407
408#define XS_CMD_S_CLEAR(sccb) (sccb)->ccb_h.spriv_field0 = 0
409
410/*
411 * Platform specific inline functions
412 */
413
414static __inline void isp_mbox_wait_complete(struct ispsoftc *);
415static __inline void
416isp_mbox_wait_complete(struct ispsoftc *isp)
417{
418 if (isp->isp_osinfo.intsok) {
419 int lim = ((isp->isp_mbxwrk0)? 120 : 20) * hz;
420 isp->isp_osinfo.mboxwaiting = 1;
421#ifdef ISP_SMPLOCK
422 (void) msleep(&isp->isp_mbxworkp,
423 &isp->isp_lock, PRIBIO, "isp_mboxwaiting", lim);
424#else
425 (void) tsleep(&isp->isp_mbxworkp,
426 PRIBIO, "isp_mboxwaiting", lim);
427#endif
428 if (isp->isp_mboxbsy != 0) {
429 isp_prt(isp, ISP_LOGWARN,
430 "Interrupting Mailbox Command (0x%x) Timeout",
431 isp->isp_lastmbxcmd);
432 isp->isp_mboxbsy = 0;
433 }
434 isp->isp_osinfo.mboxwaiting = 0;
435 } else {
436 int lim = ((isp->isp_mbxwrk0)? 240 : 60) * 10000;
437 int j;
438 for (j = 0; j < lim; j++) {
437 u_int16_t isr, sema, mbox;
439 uint16_t isr, sema, mbox;
438 if (isp->isp_mboxbsy == 0) {
439 break;
440 }
441 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
442 isp_intr(isp, isr, sema, mbox);
443 if (isp->isp_mboxbsy == 0) {
444 break;
445 }
446 }
447 USEC_DELAY(500);
448 }
449 if (isp->isp_mboxbsy != 0) {
450 isp_prt(isp, ISP_LOGWARN,
451 "Polled Mailbox Command (0x%x) Timeout",
452 isp->isp_lastmbxcmd);
453 }
454 }
455}
456
440 if (isp->isp_mboxbsy == 0) {
441 break;
442 }
443 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
444 isp_intr(isp, isr, sema, mbox);
445 if (isp->isp_mboxbsy == 0) {
446 break;
447 }
448 }
449 USEC_DELAY(500);
450 }
451 if (isp->isp_mboxbsy != 0) {
452 isp_prt(isp, ISP_LOGWARN,
453 "Polled Mailbox Command (0x%x) Timeout",
454 isp->isp_lastmbxcmd);
455 }
456 }
457}
458
457static __inline u_int64_t nanotime_sub(struct timespec *, struct timespec *);
458static __inline u_int64_t
459static __inline uint64_t nanotime_sub(struct timespec *, struct timespec *);
460static __inline uint64_t
459nanotime_sub(struct timespec *b, struct timespec *a)
460{
461nanotime_sub(struct timespec *b, struct timespec *a)
462{
461 u_int64_t elapsed;
463 uint64_t elapsed;
462 struct timespec x = *b;
463 timespecsub(&x, a);
464 elapsed = GET_NANOSEC(&x);
465 if (elapsed == 0)
466 elapsed++;
467 return (elapsed);
468}
469
470static __inline char *strncat(char *, const char *, size_t);
471static __inline char *
472strncat(char *d, const char *s, size_t c)
473{
474 char *t = d;
475
476 if (c) {
477 while (*d)
478 d++;
479 while ((*d++ = *s++)) {
480 if (--c == 0) {
481 *d = '\0';
482 break;
483 }
484 }
485 }
486 return (t);
487}
488
489/*
490 * ISP Library functions
491 */
492
493#include <dev/isp/isp_library.h>
494
495#endif /* _ISP_FREEBSD_H */
464 struct timespec x = *b;
465 timespecsub(&x, a);
466 elapsed = GET_NANOSEC(&x);
467 if (elapsed == 0)
468 elapsed++;
469 return (elapsed);
470}
471
472static __inline char *strncat(char *, const char *, size_t);
473static __inline char *
474strncat(char *d, const char *s, size_t c)
475{
476 char *t = d;
477
478 if (c) {
479 while (*d)
480 d++;
481 while ((*d++ = *s++)) {
482 if (--c == 0) {
483 *d = '\0';
484 break;
485 }
486 }
487 }
488 return (t);
489}
490
491/*
492 * ISP Library functions
493 */
494
495#include <dev/isp/isp_library.h>
496
497#endif /* _ISP_FREEBSD_H */