isp_netbsd.h revision 1.18.2.11 1 1.18.2.11 bouyer /* $NetBSD: isp_netbsd.h,v 1.18.2.11 2001/03/27 13:08:12 bouyer Exp $ */
2 1.18.2.6 bouyer /*
3 1.18.2.6 bouyer * This driver, which is contained in NetBSD in the files:
4 1.18.2.6 bouyer *
5 1.18.2.6 bouyer * sys/dev/ic/isp.c
6 1.18.2.9 bouyer * sys/dev/ic/isp_inline.h
7 1.18.2.9 bouyer * sys/dev/ic/isp_netbsd.c
8 1.18.2.9 bouyer * sys/dev/ic/isp_netbsd.h
9 1.18.2.9 bouyer * sys/dev/ic/isp_target.c
10 1.18.2.9 bouyer * sys/dev/ic/isp_target.h
11 1.18.2.9 bouyer * sys/dev/ic/isp_tpublic.h
12 1.18.2.9 bouyer * sys/dev/ic/ispmbox.h
13 1.18.2.9 bouyer * sys/dev/ic/ispreg.h
14 1.18.2.9 bouyer * sys/dev/ic/ispvar.h
15 1.18.2.6 bouyer * sys/microcode/isp/asm_sbus.h
16 1.18.2.6 bouyer * sys/microcode/isp/asm_1040.h
17 1.18.2.6 bouyer * sys/microcode/isp/asm_1080.h
18 1.18.2.6 bouyer * sys/microcode/isp/asm_12160.h
19 1.18.2.6 bouyer * sys/microcode/isp/asm_2100.h
20 1.18.2.6 bouyer * sys/microcode/isp/asm_2200.h
21 1.18.2.6 bouyer * sys/pci/isp_pci.c
22 1.18.2.6 bouyer * sys/sbus/isp_sbus.c
23 1.18.2.6 bouyer *
24 1.18.2.6 bouyer * Is being actively maintained by Matthew Jacob (mjacob (at) netbsd.org).
25 1.18.2.6 bouyer * This driver also is shared source with FreeBSD, OpenBSD, Linux, Solaris,
26 1.18.2.6 bouyer * Linux versions. This tends to be an interesting maintenance problem.
27 1.18.2.6 bouyer *
28 1.18.2.6 bouyer * Please coordinate with Matthew Jacob on changes you wish to make here.
29 1.18.2.6 bouyer */
30 1.1 mjacob /*
31 1.1 mjacob * NetBSD Specific definitions for the Qlogic ISP Host Adapter
32 1.15 mjacob * Matthew Jacob <mjacob (at) nas.nasa.gov>
33 1.15 mjacob */
34 1.15 mjacob /*
35 1.15 mjacob * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
36 1.1 mjacob * All rights reserved.
37 1.1 mjacob *
38 1.1 mjacob * Redistribution and use in source and binary forms, with or without
39 1.1 mjacob * modification, are permitted provided that the following conditions
40 1.1 mjacob * are met:
41 1.1 mjacob * 1. Redistributions of source code must retain the above copyright
42 1.15 mjacob * notice, this list of conditions and the following disclaimer.
43 1.1 mjacob * 2. Redistributions in binary form must reproduce the above copyright
44 1.1 mjacob * notice, this list of conditions and the following disclaimer in the
45 1.1 mjacob * documentation and/or other materials provided with the distribution.
46 1.1 mjacob * 3. The name of the author may not be used to endorse or promote products
47 1.15 mjacob * derived from this software without specific prior written permission
48 1.1 mjacob *
49 1.15 mjacob * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
50 1.15 mjacob * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
51 1.15 mjacob * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
52 1.15 mjacob * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
53 1.15 mjacob * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
54 1.15 mjacob * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
55 1.15 mjacob * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
56 1.15 mjacob * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57 1.15 mjacob * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
58 1.15 mjacob * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 1.1 mjacob */
60 1.1 mjacob #ifndef _ISP_NETBSD_H
61 1.1 mjacob #define _ISP_NETBSD_H
62 1.1 mjacob
63 1.1 mjacob #include <sys/types.h>
64 1.1 mjacob #include <sys/param.h>
65 1.1 mjacob #include <sys/systm.h>
66 1.1 mjacob #include <sys/kernel.h>
67 1.1 mjacob #include <sys/errno.h>
68 1.1 mjacob #include <sys/ioctl.h>
69 1.1 mjacob #include <sys/device.h>
70 1.1 mjacob #include <sys/malloc.h>
71 1.1 mjacob #include <sys/buf.h>
72 1.1 mjacob #include <sys/proc.h>
73 1.1 mjacob #include <sys/user.h>
74 1.1 mjacob
75 1.1 mjacob
76 1.1 mjacob #include <dev/scsipi/scsi_all.h>
77 1.1 mjacob #include <dev/scsipi/scsipi_all.h>
78 1.1 mjacob #include <dev/scsipi/scsiconf.h>
79 1.1 mjacob
80 1.1 mjacob #include <dev/scsipi/scsi_message.h>
81 1.1 mjacob #include <dev/scsipi/scsipi_debug.h>
82 1.1 mjacob
83 1.15 mjacob #include "opt_isp.h"
84 1.15 mjacob
85 1.1 mjacob
86 1.18.2.6 bouyer #define ISP_PLATFORM_VERSION_MAJOR 1
87 1.18.2.10 bouyer #define ISP_PLATFORM_VERSION_MINOR 1
88 1.18.2.6 bouyer
89 1.1 mjacob struct isposinfo {
90 1.1 mjacob struct device _dev;
91 1.18.2.11 bouyer struct scsipi_channel _chan;
92 1.18.2.11 bouyer struct scsipi_channel _chan_b;
93 1.6 mjacob struct scsipi_adapter _adapter;
94 1.18.2.6 bouyer int splsaved;
95 1.18.2.6 bouyer int mboxwaiting;
96 1.18.2.6 bouyer u_int32_t islocked;
97 1.18.2.6 bouyer u_int32_t onintstack;
98 1.18.2.6 bouyer unsigned int : 30,
99 1.18.2.11 bouyer no_mbox_ints : 1;
100 1.18.2.6 bouyer union {
101 1.18.2.6 bouyer u_int64_t _wwn;
102 1.18.2.6 bouyer u_int16_t _discovered[2];
103 1.18.2.6 bouyer #define wwn_seed un._wwn
104 1.18.2.6 bouyer #define discovered un._discovered
105 1.18.2.6 bouyer } un;
106 1.18.2.6 bouyer TAILQ_HEAD(, scsipi_xfer) waitq;
107 1.18.2.6 bouyer struct callout _restart;
108 1.1 mjacob };
109 1.18.2.8 bouyer #define ISP_MUSTPOLL(isp) \
110 1.18.2.8 bouyer (isp->isp_osinfo.onintstack || isp->isp_osinfo.no_mbox_ints)
111 1.18 mjacob
112 1.18.2.6 bouyer /*
113 1.18.2.6 bouyer * Required Macros/Defines
114 1.18.2.6 bouyer */
115 1.1 mjacob
116 1.18.2.6 bouyer #define INLINE inline
117 1.1 mjacob
118 1.18.2.6 bouyer #define ISP2100_SCRLEN 0x400
119 1.8 mjacob
120 1.8 mjacob #define MEMZERO bzero
121 1.18.2.6 bouyer #define MEMCPY(dst, src, amt) bcopy((src), (dst), (amt))
122 1.18.2.6 bouyer #define SNPRINTF snprintf
123 1.18.2.6 bouyer #define STRNCAT strncat
124 1.18.2.6 bouyer #define USEC_DELAY DELAY
125 1.18.2.8 bouyer #define USEC_SLEEP(isp, x) \
126 1.18.2.8 bouyer if (!ISP_MUSTPOLL(isp)) \
127 1.18.2.8 bouyer ISP_UNLOCK(isp); \
128 1.18.2.8 bouyer DELAY(x); \
129 1.18.2.8 bouyer if (!ISP_MUSTPOLL(isp)) \
130 1.18.2.8 bouyer ISP_LOCK(isp)
131 1.18.2.6 bouyer
132 1.18.2.6 bouyer #define NANOTIME_T struct timeval
133 1.18.2.6 bouyer #define GET_NANOTIME microtime
134 1.18.2.6 bouyer #define GET_NANOSEC(x) (((x)->tv_sec * 1000000 + (x)->tv_usec) * 1000)
135 1.18.2.6 bouyer #define NANOTIME_SUB isp_microtime_sub
136 1.18.2.6 bouyer
137 1.18.2.6 bouyer #define MAXISPREQUEST(isp) 256
138 1.18.2.6 bouyer
139 1.11 mjacob #ifdef __alpha__
140 1.18.2.6 bouyer #define MEMORYBARRIER(isp, type, offset, size) alpha_mb()
141 1.11 mjacob #else
142 1.18.2.6 bouyer #define MEMORYBARRIER(isp, type, offset, size)
143 1.11 mjacob #endif
144 1.3 mjacob
145 1.18.2.6 bouyer #define MBOX_ACQUIRE(isp)
146 1.18.2.6 bouyer #define MBOX_WAIT_COMPLETE isp_wait_complete
147 1.13 mjacob
148 1.18.2.6 bouyer #define MBOX_NOTIFY_COMPLETE(isp) \
149 1.18.2.6 bouyer if (isp->isp_osinfo.mboxwaiting) { \
150 1.18.2.6 bouyer isp->isp_osinfo.mboxwaiting = 0; \
151 1.18.2.6 bouyer wakeup(&isp->isp_osinfo.mboxwaiting); \
152 1.18.2.6 bouyer } \
153 1.18.2.6 bouyer isp->isp_mboxbsy = 0
154 1.1 mjacob
155 1.18.2.6 bouyer #define MBOX_RELEASE(isp)
156 1.1 mjacob
157 1.18.2.6 bouyer #ifndef SCSI_GOOD
158 1.18.2.6 bouyer #define SCSI_GOOD 0x0
159 1.18.2.6 bouyer #endif
160 1.18.2.6 bouyer #ifndef SCSI_CHECK
161 1.18.2.6 bouyer #define SCSI_CHECK 0x2
162 1.18.2.6 bouyer #endif
163 1.18.2.6 bouyer #ifndef SCSI_BUSY
164 1.18.2.6 bouyer #define SCSI_BUSY 0x8
165 1.18.2.6 bouyer #endif
166 1.18.2.6 bouyer #ifndef SCSI_QFULL
167 1.18.2.6 bouyer #define SCSI_QFULL 0x28
168 1.18.2.6 bouyer #endif
169 1.1 mjacob
170 1.18.2.6 bouyer #define XS_T struct scsipi_xfer
171 1.18.2.11 bouyer #define XS_CHANNEL(xs) ((int) (xs)->xs_periph->periph_channel)
172 1.18.2.11 bouyer #define XS_ISP(xs) \
173 1.18.2.11 bouyer ((void *)(xs)->xs_periph->periph_channel->chan_adapter->adapt_dev)
174 1.18.2.11 bouyer #define XS_LUN(xs) ((int) (xs)->xs_periph->periph_lun)
175 1.18.2.11 bouyer #define XS_TGT(xs) ((int) (xs)->xs_periph->periph_target)
176 1.14 mjacob #define XS_CDBP(xs) ((caddr_t) (xs)->cmd)
177 1.18.2.6 bouyer #define XS_CDBLEN(xs) (xs)->cmdlen
178 1.18.2.6 bouyer #define XS_XFRLEN(xs) (xs)->datalen
179 1.1 mjacob #define XS_TIME(xs) (xs)->timeout
180 1.18.2.6 bouyer #define XS_RESID(xs) (xs)->resid
181 1.18.2.6 bouyer #define XS_STSP(xs) (&(xs)->status)
182 1.1 mjacob #define XS_SNSP(xs) (&(xs)->sense.scsi_sense)
183 1.18.2.6 bouyer #define XS_SNSLEN(xs) (sizeof (xs)->sense)
184 1.1 mjacob #define XS_SNSKEY(xs) ((xs)->sense.scsi_sense.flags)
185 1.18.2.6 bouyer #define XS_TAG_P(ccb) (((xs)->xs_control & XS_CTL_POLL) != 0)
186 1.18.2.6 bouyer #define XS_TAG_TYPE(xs) \
187 1.18.2.6 bouyer (((xs)->xs_control & XS_CTL_URGENT) ? REQFLAG_HTAG : \
188 1.18.2.6 bouyer ((xs)->bp && xs->bp->b_flags & B_ASYNC) ? REQFLAG_STAG : REQFLAG_OTAG)
189 1.1 mjacob
190 1.18.2.6 bouyer #define XS_SETERR(xs, v) (xs)->error = v
191 1.1 mjacob
192 1.18.2.6 bouyer # define HBA_NOERROR XS_NOERROR
193 1.18.2.6 bouyer # define HBA_BOTCH XS_DRIVER_STUFFUP
194 1.18.2.6 bouyer # define HBA_CMDTIMEOUT XS_TIMEOUT
195 1.18.2.6 bouyer # define HBA_SELTIMEOUT XS_SELTIMEOUT
196 1.18.2.6 bouyer # define HBA_TGTBSY XS_BUSY
197 1.18.2.6 bouyer # define HBA_BUSRESET XS_RESET
198 1.18.2.6 bouyer # define HBA_ABORTED XS_DRIVER_STUFFUP
199 1.18.2.6 bouyer # define HBA_DATAOVR XS_DRIVER_STUFFUP
200 1.18.2.6 bouyer # define HBA_ARQFAIL XS_DRIVER_STUFFUP
201 1.1 mjacob
202 1.1 mjacob #define XS_ERR(xs) (xs)->error
203 1.18.2.6 bouyer
204 1.1 mjacob #define XS_NOERR(xs) (xs)->error == XS_NOERROR
205 1.1 mjacob
206 1.18.2.6 bouyer #define XS_INITERR(xs) (xs)->error = 0, XS_CMD_S_CLEAR(xs)
207 1.18.2.6 bouyer
208 1.18.2.6 bouyer #define XS_SAVE_SENSE(xs, sp) \
209 1.18.2.9 bouyer if (xs->error == XS_NOERROR) { \
210 1.18.2.9 bouyer xs->error = XS_SENSE; \
211 1.18.2.9 bouyer } \
212 1.18.2.6 bouyer bcopy(sp->req_sense_data, &(xs)->sense, \
213 1.18.2.6 bouyer imin(XS_SNSLEN(xs), sp->req_sense_len))
214 1.18.2.6 bouyer
215 1.18.2.6 bouyer #define XS_SET_STATE_STAT(a, b, c)
216 1.18.2.6 bouyer
217 1.18.2.6 bouyer #define DEFAULT_IID(x) 7
218 1.18.2.6 bouyer #define DEFAULT_LOOPID(x) 108
219 1.18.2.6 bouyer #define DEFAULT_NODEWWN(isp) (isp)->isp_osinfo.un._wwn
220 1.18.2.6 bouyer #define DEFAULT_PORTWWN(isp) (isp)->isp_osinfo.un._wwn
221 1.18.2.6 bouyer #define ISP_NODEWWN(isp) FCPARAM(isp)->isp_nodewwn
222 1.18.2.6 bouyer #define ISP_PORTWWN(isp) FCPARAM(isp)->isp_portwwn
223 1.18.2.6 bouyer
224 1.18.2.8 bouyer #if _BYTE_ORDER == _BIG_ENDIAN
225 1.18.2.8 bouyer #define ISP_SWIZZLE_REQUEST isp_swizzle_request
226 1.18.2.8 bouyer #define ISP_UNSWIZZLE_RESPONSE isp_unswizzle_response
227 1.18.2.8 bouyer #define ISP_SWIZZLE_ICB isp_swizzle_icb
228 1.18.2.8 bouyer #define ISP_UNSWIZZLE_AND_COPY_PDBP isp_unswizzle_and_copy_pdbp
229 1.18.2.8 bouyer #define ISP_SWIZZLE_SNS_REQ isp_swizzle_sns_req
230 1.18.2.8 bouyer #define ISP_UNSWIZZLE_SNS_RSP isp_unswizzle_sns_rsp
231 1.18.2.8 bouyer #define ISP_SWIZZLE_NVRAM_WORD(isp, rp) *rp = bswap16(*rp)
232 1.18.2.6 bouyer #else
233 1.18.2.6 bouyer #define ISP_SWIZZLE_REQUEST(a, b)
234 1.18.2.6 bouyer #define ISP_UNSWIZZLE_RESPONSE(a, b, c)
235 1.18.2.8 bouyer #define ISP_SWIZZLE_ICB(a, b)
236 1.18.2.8 bouyer #define ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src) \
237 1.18.2.8 bouyer if((void *)src != (void *)dest) bcopy(src, dest, sizeof (isp_pdb_t))
238 1.18.2.6 bouyer #define ISP_SWIZZLE_SNS_REQ(a, b)
239 1.18.2.6 bouyer #define ISP_UNSWIZZLE_SNS_RSP(a, b, c)
240 1.18.2.6 bouyer #define ISP_SWIZZLE_NVRAM_WORD(isp, rp)
241 1.18.2.6 bouyer #endif
242 1.1 mjacob
243 1.1 mjacob /*
244 1.18.2.6 bouyer * Includes of common header files
245 1.1 mjacob */
246 1.18.2.6 bouyer
247 1.18.2.6 bouyer #include <dev/ic/ispreg.h>
248 1.18.2.6 bouyer #include <dev/ic/ispvar.h>
249 1.18.2.6 bouyer #include <dev/ic/ispmbox.h>
250 1.1 mjacob
251 1.1 mjacob /*
252 1.18.2.6 bouyer * isp_osinfo definitions, extensions and shorthand.
253 1.1 mjacob */
254 1.18.2.6 bouyer #define isp_name isp_osinfo._dev.dv_xname
255 1.18.2.6 bouyer #define isp_unit isp_osinfo._dev.dv_unit
256 1.1 mjacob
257 1.18 mjacob /*
258 1.18.2.6 bouyer * Driver prototypes..
259 1.18 mjacob */
260 1.18.2.6 bouyer void isp_attach __P((struct ispsoftc *));
261 1.18.2.6 bouyer void isp_uninit __P((struct ispsoftc *));
262 1.1 mjacob
263 1.18.2.6 bouyer static inline void isp_lock __P((struct ispsoftc *));
264 1.18.2.6 bouyer static inline void isp_unlock __P((struct ispsoftc *));
265 1.18.2.6 bouyer static inline char *strncat __P((char *, const char *, size_t));
266 1.18.2.6 bouyer static inline u_int64_t
267 1.18.2.6 bouyer isp_microtime_sub __P((struct timeval *, struct timeval *));
268 1.18.2.6 bouyer static void isp_wait_complete __P((struct ispsoftc *));
269 1.18.2.8 bouyer #if _BYTE_ORDER == _BIG_ENDIAN
270 1.18.2.8 bouyer static inline void isp_swizzle_request(struct ispsoftc *, ispreq_t *);
271 1.18.2.8 bouyer static inline void isp_unswizzle_response(struct ispsoftc *, void *, u_int16_t);
272 1.18.2.8 bouyer static inline void isp_swizzle_icb(struct ispsoftc *, isp_icb_t *);
273 1.18.2.8 bouyer static inline void
274 1.18.2.8 bouyer isp_unswizzle_and_copy_pdbp(struct ispsoftc *, isp_pdb_t *, void *);
275 1.18.2.8 bouyer static inline void isp_swizzle_sns_req(struct ispsoftc *, sns_screq_t *);
276 1.18.2.8 bouyer static inline void isp_unswizzle_sns_rsp(struct ispsoftc *, sns_scrsp_t *, int);
277 1.18.2.8 bouyer #endif
278 1.1 mjacob
279 1.18.2.6 bouyer /*
280 1.18.2.6 bouyer * Driver wide data...
281 1.18.2.6 bouyer */
282 1.14 mjacob
283 1.18.2.6 bouyer /*
284 1.18.2.6 bouyer * Locking macros...
285 1.18.2.6 bouyer */
286 1.18.2.6 bouyer #define ISP_LOCK isp_lock
287 1.18.2.6 bouyer #define ISP_UNLOCK isp_unlock
288 1.18.2.6 bouyer #define ISP_ILOCK(x) isp_lock(x); isp->isp_osinfo.onintstack++
289 1.18.2.6 bouyer #define ISP_IUNLOCK(x) isp->isp_osinfo.onintstack--; isp_unlock(x)
290 1.1 mjacob
291 1.18.2.6 bouyer /*
292 1.18.2.6 bouyer * Platform private flags
293 1.18.2.6 bouyer */
294 1.1 mjacob
295 1.18.2.6 bouyer #define XS_PSTS_INWDOG 0x10000000
296 1.18.2.6 bouyer #define XS_PSTS_GRACE 0x20000000
297 1.18.2.6 bouyer #define XS_PSTS_ALL 0x30000000
298 1.18.2.6 bouyer
299 1.18.2.6 bouyer #define XS_CMD_S_WDOG(xs) (xs)->xs_status |= XS_PSTS_INWDOG
300 1.18.2.6 bouyer #define XS_CMD_C_WDOG(xs) (xs)->xs_status &= ~XS_PSTS_INWDOG
301 1.18.2.6 bouyer #define XS_CMD_WDOG_P(xs) (((xs)->xs_status & XS_PSTS_INWDOG) != 0)
302 1.18.2.6 bouyer
303 1.18.2.6 bouyer #define XS_CMD_S_GRACE(xs) (xs)->xs_status |= XS_PSTS_GRACE
304 1.18.2.6 bouyer #define XS_CMD_C_GRACE(xs) (xs)->xs_status &= ~XS_PSTS_GRACE
305 1.18.2.6 bouyer #define XS_CMD_GRACE_P(xs) (((xs)->xs_status & XS_PSTS_GRACE) != 0)
306 1.18.2.6 bouyer
307 1.18.2.6 bouyer #define XS_CMD_S_DONE(xs) (xs)->xs_status |= XS_STS_DONE
308 1.18.2.6 bouyer #define XS_CMD_C_DONE(xs) (xs)->xs_status &= ~XS_STS_DONE
309 1.18.2.6 bouyer #define XS_CMD_DONE_P(xs) (((xs)->xs_status & XS_STS_DONE) != 0)
310 1.11 mjacob
311 1.18.2.6 bouyer #define XS_CMD_S_CLEAR(xs) (xs)->xs_status &= ~XS_PSTS_ALL
312 1.11 mjacob
313 1.18.2.6 bouyer /*
314 1.18.2.6 bouyer * Platform specific 'inline' or support functions
315 1.18.2.6 bouyer */
316 1.18.2.6 bouyer static inline void
317 1.18.2.6 bouyer isp_lock(isp)
318 1.18.2.6 bouyer struct ispsoftc *isp;
319 1.18.2.6 bouyer {
320 1.18.2.6 bouyer int s = splbio();
321 1.18.2.6 bouyer if (isp->isp_osinfo.islocked++ == 0) {
322 1.18.2.6 bouyer isp->isp_osinfo.splsaved = s;
323 1.18.2.6 bouyer } else {
324 1.18.2.6 bouyer splx(s);
325 1.18.2.6 bouyer }
326 1.18.2.6 bouyer }
327 1.18.2.6 bouyer
328 1.18.2.6 bouyer static inline void
329 1.18.2.6 bouyer isp_unlock(isp)
330 1.18.2.6 bouyer struct ispsoftc *isp;
331 1.18.2.6 bouyer {
332 1.18.2.6 bouyer if (isp->isp_osinfo.islocked-- <= 1) {
333 1.18.2.6 bouyer isp->isp_osinfo.islocked = 0;
334 1.18.2.6 bouyer splx(isp->isp_osinfo.splsaved);
335 1.18.2.6 bouyer }
336 1.18.2.6 bouyer }
337 1.18.2.6 bouyer
338 1.18.2.6 bouyer static inline char *
339 1.18.2.6 bouyer strncat(d, s, c)
340 1.18.2.6 bouyer char *d;
341 1.18.2.6 bouyer const char *s;
342 1.18.2.6 bouyer size_t c;
343 1.18.2.6 bouyer {
344 1.18.2.6 bouyer char *t = d;
345 1.18.2.6 bouyer
346 1.18.2.6 bouyer if (c) {
347 1.18.2.6 bouyer while (*d)
348 1.18.2.6 bouyer d++;
349 1.18.2.6 bouyer while ((*d++ = *s++)) {
350 1.18.2.6 bouyer if (--c == 0) {
351 1.18.2.6 bouyer *d = '\0';
352 1.18.2.6 bouyer break;
353 1.18.2.6 bouyer }
354 1.18.2.6 bouyer }
355 1.18.2.6 bouyer }
356 1.18.2.6 bouyer return (t);
357 1.18.2.6 bouyer }
358 1.18.2.6 bouyer
359 1.18.2.6 bouyer static inline u_int64_t
360 1.18.2.6 bouyer isp_microtime_sub(b, a)
361 1.18.2.6 bouyer struct timeval *b;
362 1.18.2.6 bouyer struct timeval *a;
363 1.18.2.6 bouyer {
364 1.18.2.6 bouyer struct timeval x;
365 1.18.2.6 bouyer u_int64_t elapsed;
366 1.18.2.6 bouyer timersub(b, a, &x);
367 1.18.2.6 bouyer elapsed = GET_NANOSEC(&x);
368 1.18.2.6 bouyer if (elapsed == 0)
369 1.18.2.6 bouyer elapsed++;
370 1.18.2.6 bouyer return (elapsed);
371 1.18.2.6 bouyer }
372 1.18.2.6 bouyer
373 1.18.2.6 bouyer static inline void
374 1.18.2.6 bouyer isp_wait_complete(isp)
375 1.18.2.6 bouyer struct ispsoftc *isp;
376 1.18.2.6 bouyer {
377 1.18.2.6 bouyer if (isp->isp_osinfo.onintstack || isp->isp_osinfo.no_mbox_ints) {
378 1.18.2.6 bouyer int usecs = 0;
379 1.18.2.9 bouyer /*
380 1.18.2.9 bouyer * For sanity's sake, we don't delay longer
381 1.18.2.9 bouyer * than 5 seconds for polled commands.
382 1.18.2.9 bouyer */
383 1.18.2.9 bouyer while (usecs < 5 * 1000000) {
384 1.18.2.6 bouyer (void) isp_intr(isp);
385 1.18.2.6 bouyer if (isp->isp_mboxbsy == 0) {
386 1.18.2.6 bouyer break;
387 1.18.2.6 bouyer }
388 1.18.2.6 bouyer USEC_DELAY(500);
389 1.18.2.6 bouyer usecs += 500;
390 1.18.2.6 bouyer }
391 1.18.2.6 bouyer if (isp->isp_mboxbsy != 0) {
392 1.18.2.9 bouyer isp_prt(isp, ISP_LOGWARN,
393 1.18.2.9 bouyer "Polled Mailbox Command (0x%x) Timeout",
394 1.18.2.10 bouyer isp->isp_lastmbxcmd);
395 1.18.2.6 bouyer }
396 1.18.2.6 bouyer } else {
397 1.18.2.6 bouyer int rv = 0;
398 1.18.2.6 bouyer isp->isp_osinfo.mboxwaiting = 1;
399 1.18.2.6 bouyer while (isp->isp_osinfo.mboxwaiting && rv == 0) {
400 1.18.2.9 bouyer static const struct timeval dtime = { 5, 0 };
401 1.18.2.6 bouyer int timo;
402 1.18.2.6 bouyer struct timeval tv;
403 1.18.2.6 bouyer microtime(&tv);
404 1.18.2.9 bouyer timeradd(&tv, &dtime, &tv);
405 1.18.2.6 bouyer if ((timo = hzto(&tv)) == 0) {
406 1.18.2.6 bouyer timo = 1;
407 1.18.2.6 bouyer }
408 1.18.2.6 bouyer rv = tsleep(&isp->isp_osinfo.mboxwaiting,
409 1.18.2.6 bouyer PRIBIO, "isp_mboxcmd", timo);
410 1.18.2.6 bouyer }
411 1.18.2.6 bouyer if (rv == EWOULDBLOCK) {
412 1.18.2.6 bouyer isp->isp_mboxbsy = 0;
413 1.18.2.6 bouyer isp->isp_osinfo.mboxwaiting = 0;
414 1.18.2.9 bouyer isp_prt(isp, ISP_LOGWARN,
415 1.18.2.9 bouyer "Interrupting Mailbox Command (0x%x) Timeout",
416 1.18.2.10 bouyer isp->isp_lastmbxcmd);
417 1.18.2.6 bouyer }
418 1.18.2.6 bouyer }
419 1.18.2.6 bouyer }
420 1.18.2.8 bouyer
421 1.18.2.8 bouyer #if _BYTE_ORDER == _BIG_ENDIAN
422 1.18.2.8 bouyer static inline void
423 1.18.2.8 bouyer isp_swizzle_request(struct ispsoftc *isp, ispreq_t *rq)
424 1.18.2.8 bouyer {
425 1.18.2.8 bouyer if (IS_FC(isp)) {
426 1.18.2.8 bouyer ispreqt2_t *tq = (ispreqt2_t *) rq;
427 1.18.2.8 bouyer tq->req_handle = bswap32(tq->req_handle);
428 1.18.2.8 bouyer tq->req_scclun = bswap16(tq->req_scclun);
429 1.18.2.8 bouyer tq->req_flags = bswap16(tq->req_flags);
430 1.18.2.8 bouyer tq->req_time = bswap16(tq->req_time);
431 1.18.2.8 bouyer tq->req_totalcnt = bswap32(tq->req_totalcnt);
432 1.18.2.8 bouyer } else if (isp->isp_bustype == ISP_BT_SBUS) {
433 1.18.2.8 bouyer _ISP_SWAP8(rq->req_header.rqs_entry_count,
434 1.18.2.8 bouyer rq->req_header.rqs_entry_type);
435 1.18.2.8 bouyer _ISP_SWAP8(rq->req_header.rqs_flags, rq->req_header.rqs_seqno);
436 1.18.2.8 bouyer _ISP_SWAP8(rq->req_target, rq->req_lun_trn);
437 1.18.2.8 bouyer } else {
438 1.18.2.8 bouyer rq->req_handle = bswap32(rq->req_handle);
439 1.18.2.8 bouyer rq->req_cdblen = bswap16(rq->req_cdblen);
440 1.18.2.8 bouyer rq->req_flags = bswap16(rq->req_flags);
441 1.18.2.8 bouyer rq->req_time = bswap16(rq->req_time);
442 1.18.2.8 bouyer }
443 1.18.2.8 bouyer }
444 1.18.2.8 bouyer
445 1.18.2.8 bouyer static inline void
446 1.18.2.8 bouyer isp_unswizzle_response(struct ispsoftc *isp, void *rp, u_int16_t optr)
447 1.18.2.8 bouyer {
448 1.18.2.8 bouyer ispstatusreq_t *sp = rp;
449 1.18.2.8 bouyer MEMORYBARRIER(isp, SYNC_RESPONSE, optr * QENTRY_LEN, QENTRY_LEN);
450 1.18.2.8 bouyer if (isp->isp_bustype == ISP_BT_SBUS) {
451 1.18.2.8 bouyer _ISP_SWAP8(sp->req_header.rqs_entry_count,
452 1.18.2.8 bouyer sp->req_header.rqs_entry_type);
453 1.18.2.8 bouyer _ISP_SWAP8(sp->req_header.rqs_flags, sp->req_header.rqs_seqno);
454 1.18.2.8 bouyer } else switch (sp->req_header.rqs_entry_type) {
455 1.18.2.8 bouyer case RQSTYPE_RESPONSE:
456 1.18.2.8 bouyer sp->req_handle = bswap32(sp->req_handle);
457 1.18.2.8 bouyer sp->req_scsi_status = bswap16(sp->req_scsi_status);
458 1.18.2.8 bouyer sp->req_completion_status = bswap16(sp->req_completion_status);
459 1.18.2.8 bouyer sp->req_state_flags = bswap16(sp->req_state_flags);
460 1.18.2.8 bouyer sp->req_status_flags = bswap16(sp->req_status_flags);
461 1.18.2.8 bouyer sp->req_time = bswap16(sp->req_time);
462 1.18.2.8 bouyer sp->req_sense_len = bswap16(sp->req_sense_len);
463 1.18.2.8 bouyer sp->req_resid = bswap32(sp->req_resid);
464 1.18.2.8 bouyer break;
465 1.18.2.8 bouyer default:
466 1.18.2.8 bouyer break;
467 1.18.2.8 bouyer }
468 1.18.2.8 bouyer }
469 1.18.2.8 bouyer
470 1.18.2.8 bouyer static inline void
471 1.18.2.8 bouyer isp_swizzle_icb(struct ispsoftc *isp, isp_icb_t *icbp)
472 1.18.2.8 bouyer {
473 1.18.2.8 bouyer _ISP_SWAP8(icbp->icb_version, icbp->_reserved0);
474 1.18.2.8 bouyer _ISP_SWAP8(icbp->icb_retry_count, icbp->icb_retry_delay);
475 1.18.2.8 bouyer _ISP_SWAP8(icbp->icb_iqdevtype, icbp->icb_logintime);
476 1.18.2.8 bouyer _ISP_SWAP8(icbp->icb_ccnt, icbp->icb_icnt);
477 1.18.2.8 bouyer _ISP_SWAP8(icbp->icb_racctimer, icbp->icb_idelaytimer);
478 1.18.2.8 bouyer icbp->icb_fwoptions = bswap16(icbp->icb_fwoptions);
479 1.18.2.8 bouyer icbp->icb_maxfrmlen = bswap16(icbp->icb_maxfrmlen);
480 1.18.2.8 bouyer icbp->icb_maxalloc = bswap16(icbp->icb_maxalloc);
481 1.18.2.8 bouyer icbp->icb_execthrottle = bswap16(icbp->icb_execthrottle);
482 1.18.2.8 bouyer icbp->icb_hardaddr = bswap16(icbp->icb_hardaddr);
483 1.18.2.8 bouyer icbp->icb_rqstout = bswap16(icbp->icb_rqstout);
484 1.18.2.8 bouyer icbp->icb_rspnsin = bswap16(icbp->icb_rspnsin);
485 1.18.2.8 bouyer icbp->icb_rqstqlen = bswap16(icbp->icb_rqstqlen);
486 1.18.2.8 bouyer icbp->icb_rsltqlen = bswap16(icbp->icb_rsltqlen);
487 1.18.2.8 bouyer icbp->icb_lunenables = bswap16(icbp->icb_lunenables);
488 1.18.2.8 bouyer icbp->icb_lunetimeout = bswap16(icbp->icb_lunetimeout);
489 1.18.2.8 bouyer icbp->icb_xfwoptions = bswap16(icbp->icb_xfwoptions);
490 1.18.2.8 bouyer icbp->icb_zfwoptions = bswap16(icbp->icb_zfwoptions);
491 1.18.2.8 bouyer icbp->icb_rqstaddr[0] = bswap16(icbp->icb_rqstaddr[0]);
492 1.18.2.8 bouyer icbp->icb_rqstaddr[1] = bswap16(icbp->icb_rqstaddr[1]);
493 1.18.2.8 bouyer icbp->icb_rqstaddr[2] = bswap16(icbp->icb_rqstaddr[2]);
494 1.18.2.8 bouyer icbp->icb_rqstaddr[3] = bswap16(icbp->icb_rqstaddr[3]);
495 1.18.2.8 bouyer icbp->icb_respaddr[0] = bswap16(icbp->icb_respaddr[0]);
496 1.18.2.8 bouyer icbp->icb_respaddr[1] = bswap16(icbp->icb_respaddr[1]);
497 1.18.2.8 bouyer icbp->icb_respaddr[2] = bswap16(icbp->icb_respaddr[2]);
498 1.18.2.8 bouyer icbp->icb_respaddr[3] = bswap16(icbp->icb_respaddr[3]);
499 1.18.2.8 bouyer }
500 1.18.2.8 bouyer
501 1.18.2.8 bouyer static inline void
502 1.18.2.8 bouyer isp_unswizzle_and_copy_pdbp(struct ispsoftc *isp, isp_pdb_t *dst, void *src)
503 1.18.2.8 bouyer {
504 1.18.2.8 bouyer isp_pdb_t *pdbp = src;
505 1.18.2.8 bouyer dst->pdb_options = bswap16(pdbp->pdb_options);
506 1.18.2.8 bouyer dst->pdb_mstate = pdbp->pdb_sstate;
507 1.18.2.8 bouyer dst->pdb_sstate = pdbp->pdb_mstate;
508 1.18.2.8 bouyer dst->pdb_hardaddr_bits[0] = pdbp->pdb_hardaddr_bits[0];
509 1.18.2.8 bouyer dst->pdb_hardaddr_bits[1] = pdbp->pdb_hardaddr_bits[1];
510 1.18.2.8 bouyer dst->pdb_hardaddr_bits[2] = pdbp->pdb_hardaddr_bits[2];
511 1.18.2.8 bouyer dst->pdb_hardaddr_bits[3] = pdbp->pdb_hardaddr_bits[3];
512 1.18.2.8 bouyer dst->pdb_portid_bits[0] = pdbp->pdb_portid_bits[0];
513 1.18.2.8 bouyer dst->pdb_portid_bits[1] = pdbp->pdb_portid_bits[1];
514 1.18.2.8 bouyer dst->pdb_portid_bits[2] = pdbp->pdb_portid_bits[2];
515 1.18.2.8 bouyer dst->pdb_portid_bits[3] = pdbp->pdb_portid_bits[3];
516 1.18.2.8 bouyer dst->pdb_nodename[0] = pdbp->pdb_nodename[0];
517 1.18.2.8 bouyer dst->pdb_nodename[1] = pdbp->pdb_nodename[1];
518 1.18.2.8 bouyer dst->pdb_nodename[2] = pdbp->pdb_nodename[2];
519 1.18.2.8 bouyer dst->pdb_nodename[3] = pdbp->pdb_nodename[3];
520 1.18.2.8 bouyer dst->pdb_nodename[4] = pdbp->pdb_nodename[4];
521 1.18.2.8 bouyer dst->pdb_nodename[5] = pdbp->pdb_nodename[5];
522 1.18.2.8 bouyer dst->pdb_nodename[6] = pdbp->pdb_nodename[6];
523 1.18.2.8 bouyer dst->pdb_nodename[7] = pdbp->pdb_nodename[7];
524 1.18.2.8 bouyer dst->pdb_portname[0] = pdbp->pdb_portname[0];
525 1.18.2.8 bouyer dst->pdb_portname[1] = pdbp->pdb_portname[1];
526 1.18.2.8 bouyer dst->pdb_portname[2] = pdbp->pdb_portname[2];
527 1.18.2.8 bouyer dst->pdb_portname[3] = pdbp->pdb_portname[3];
528 1.18.2.8 bouyer dst->pdb_portname[4] = pdbp->pdb_portname[4];
529 1.18.2.8 bouyer dst->pdb_portname[5] = pdbp->pdb_portname[5];
530 1.18.2.8 bouyer dst->pdb_portname[6] = pdbp->pdb_portname[6];
531 1.18.2.8 bouyer dst->pdb_portname[7] = pdbp->pdb_portname[7];
532 1.18.2.8 bouyer dst->pdb_execthrottle = bswap16(pdbp->pdb_execthrottle);
533 1.18.2.8 bouyer dst->pdb_exec_count = bswap16(pdbp->pdb_exec_count);
534 1.18.2.8 bouyer dst->pdb_resalloc = bswap16(pdbp->pdb_resalloc);
535 1.18.2.8 bouyer dst->pdb_curalloc = bswap16(pdbp->pdb_curalloc);
536 1.18.2.8 bouyer dst->pdb_qhead = bswap16(pdbp->pdb_qhead);
537 1.18.2.8 bouyer dst->pdb_qtail = bswap16(pdbp->pdb_qtail);
538 1.18.2.8 bouyer dst->pdb_tl_next = bswap16(pdbp->pdb_tl_next);
539 1.18.2.8 bouyer dst->pdb_tl_last = bswap16(pdbp->pdb_tl_last);
540 1.18.2.8 bouyer dst->pdb_features = bswap16(pdbp->pdb_features);
541 1.18.2.8 bouyer dst->pdb_pconcurrnt = bswap16(pdbp->pdb_pconcurrnt);
542 1.18.2.8 bouyer dst->pdb_roi = bswap16(pdbp->pdb_roi);
543 1.18.2.8 bouyer dst->pdb_rdsiz = bswap16(pdbp->pdb_rdsiz);
544 1.18.2.8 bouyer dst->pdb_ncseq = bswap16(pdbp->pdb_ncseq);
545 1.18.2.8 bouyer dst->pdb_noseq = bswap16(pdbp->pdb_noseq);
546 1.18.2.8 bouyer dst->pdb_labrtflg = bswap16(pdbp->pdb_labrtflg);
547 1.18.2.8 bouyer dst->pdb_lstopflg = bswap16(pdbp->pdb_lstopflg);
548 1.18.2.8 bouyer dst->pdb_sqhead = bswap16(pdbp->pdb_sqhead);
549 1.18.2.8 bouyer dst->pdb_sqtail = bswap16(pdbp->pdb_sqtail);
550 1.18.2.8 bouyer dst->pdb_ptimer = bswap16(pdbp->pdb_ptimer);
551 1.18.2.8 bouyer dst->pdb_nxt_seqid = bswap16(pdbp->pdb_nxt_seqid);
552 1.18.2.8 bouyer dst->pdb_fcount = bswap16(pdbp->pdb_fcount);
553 1.18.2.8 bouyer dst->pdb_prli_len = bswap16(pdbp->pdb_prli_len);
554 1.18.2.8 bouyer dst->pdb_prli_svc0 = bswap16(pdbp->pdb_prli_svc0);
555 1.18.2.8 bouyer dst->pdb_prli_svc3 = bswap16(pdbp->pdb_prli_svc3);
556 1.18.2.8 bouyer dst->pdb_loopid = bswap16(pdbp->pdb_loopid);
557 1.18.2.8 bouyer dst->pdb_il_ptr = bswap16(pdbp->pdb_il_ptr);
558 1.18.2.8 bouyer dst->pdb_sl_ptr = bswap16(pdbp->pdb_sl_ptr);
559 1.18.2.8 bouyer dst->pdb_retry_count = pdbp->pdb_retry_delay;
560 1.18.2.8 bouyer dst->pdb_retry_delay = pdbp->pdb_retry_count;
561 1.18.2.8 bouyer dst->pdb_target = pdbp->pdb_initiator;
562 1.18.2.8 bouyer dst->pdb_initiator = pdbp->pdb_target;
563 1.18.2.8 bouyer }
564 1.18.2.8 bouyer
565 1.18.2.8 bouyer static inline void
566 1.18.2.8 bouyer isp_swizzle_sns_req(struct ispsoftc *isp, sns_screq_t *reqp)
567 1.18.2.8 bouyer {
568 1.18.2.8 bouyer u_int16_t index, nwords = reqp->snscb_sblen;
569 1.18.2.8 bouyer reqp->snscb_rblen = bswap16(reqp->snscb_rblen);
570 1.18.2.8 bouyer reqp->snscb_addr[0] = bswap16(reqp->snscb_addr[0]);
571 1.18.2.8 bouyer reqp->snscb_addr[1] = bswap16(reqp->snscb_addr[1]);
572 1.18.2.8 bouyer reqp->snscb_addr[2] = bswap16(reqp->snscb_addr[2]);
573 1.18.2.8 bouyer reqp->snscb_addr[3] = bswap16(reqp->snscb_addr[3]);
574 1.18.2.8 bouyer reqp->snscb_sblen = bswap16(reqp->snscb_sblen);
575 1.18.2.8 bouyer for (index = 0; index < nwords; index++) {
576 1.18.2.8 bouyer reqp->snscb_data[index] = bswap16(reqp->snscb_data[index]);
577 1.18.2.8 bouyer }
578 1.18.2.8 bouyer }
579 1.18.2.8 bouyer
580 1.18.2.8 bouyer static inline void
581 1.18.2.8 bouyer isp_unswizzle_sns_rsp(struct ispsoftc *isp, sns_scrsp_t *resp, int nwords)
582 1.18.2.8 bouyer {
583 1.18.2.8 bouyer int index;
584 1.18.2.10 bouyer /*
585 1.18.2.10 bouyer * Don't even think about asking. This. Is. So. Lame.
586 1.18.2.10 bouyer */
587 1.18.2.10 bouyer if (IS_2200(isp) &&
588 1.18.2.10 bouyer ISP_FW_REVX(isp->isp_fwrev) == ISP_FW_REV(2, 1, 26)) {
589 1.18.2.10 bouyer nwords = 128;
590 1.18.2.10 bouyer }
591 1.18.2.8 bouyer for (index = 0; index < nwords; index++) {
592 1.18.2.8 bouyer resp->snscb_data[index] = bswap16(resp->snscb_data[index]);
593 1.18.2.8 bouyer }
594 1.18.2.8 bouyer }
595 1.18.2.8 bouyer #endif
596 1.18 mjacob
597 1.18.2.6 bouyer /*
598 1.18.2.6 bouyer * Common inline functions
599 1.18.2.6 bouyer */
600 1.18 mjacob #define INLINE inline
601 1.18 mjacob #include <dev/ic/isp_inline.h>
602 1.18 mjacob
603 1.18.2.6 bouyer #if !defined(ISP_DISABLE_FW) && !defined(ISP_COMPILE_FW)
604 1.18.2.6 bouyer #define ISP_COMPILE_FW 1
605 1.18.2.6 bouyer #endif
606 1.1 mjacob #endif /* _ISP_NETBSD_H */
607