isp_netbsd.h revision 1.28 1 /* $NetBSD: isp_netbsd.h,v 1.28 2000/08/11 21:31:20 tls Exp $ */
2 /*
3 * NetBSD Specific definitions for the Qlogic ISP Host Adapter
4 * Matthew Jacob <mjacob (at) nas.nasa.gov>
5 */
6 /*
7 * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
8 * All rights reserved.
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, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 #ifndef _ISP_NETBSD_H
33 #define _ISP_NETBSD_H
34
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/errno.h>
40 #include <sys/ioctl.h>
41 #include <sys/device.h>
42 #include <sys/malloc.h>
43 #include <sys/buf.h>
44 #include <sys/proc.h>
45 #include <sys/user.h>
46
47
48 #include <dev/scsipi/scsi_all.h>
49 #include <dev/scsipi/scsipi_all.h>
50 #include <dev/scsipi/scsiconf.h>
51
52 #include <dev/scsipi/scsi_message.h>
53 #include <dev/scsipi/scsipi_debug.h>
54
55 #include "opt_isp.h"
56
57
58 #define ISP_PLATFORM_VERSION_MAJOR 1
59 #define ISP_PLATFORM_VERSION_MINOR 0
60
61 struct isposinfo {
62 struct device _dev;
63 struct scsipi_link _link;
64 struct scsipi_link _link_b;
65 struct scsipi_adapter _adapter;
66 int splsaved;
67 int mboxwaiting;
68 unsigned int
69 : 28,
70 onintstack : 1,
71 no_mbox_ints : 1,
72 blocked : 1,
73 islocked : 1;
74 union {
75 u_int64_t _wwn;
76 u_int16_t _discovered[2];
77 #define wwn_seed un._wwn
78 #define discovered un._discovered
79 } un;
80 TAILQ_HEAD(, scsipi_xfer) waitq;
81 struct callout _restart;
82 };
83
84 /*
85 * Required Macros/Defines
86 */
87
88 #define INLINE inline
89
90 #define ISP2100_FABRIC 1
91 #define ISP2100_SCRLEN 0x400
92
93 #define MEMZERO bzero
94 #define MEMCPY(dst, src, amt) bcopy((src), (dst), (amt))
95 #define SNPRINTF snprintf
96 #define STRNCAT strncat
97 #define USEC_DELAY DELAY
98
99 #define NANOTIME_T struct timeval
100 #define GET_NANOTIME microtime
101 #define GET_NANOSEC(x) (((x)->tv_sec * 1000000 + (x)->tv_usec) * 1000)
102 #define NANOTIME_SUB isp_microtime_sub
103
104 #define MAXISPREQUEST(isp) 256
105
106 #ifdef __alpha__
107 #define MEMORYBARRIER(isp, type, offset, size) alpha_mb()
108 #else
109 #define MEMORYBARRIER(isp, type, offset, size)
110 #endif
111
112 #define MBOX_ACQUIRE(isp)
113 #define MBOX_WAIT_COMPLETE isp_wait_complete
114
115 #define MBOX_NOTIFY_COMPLETE(isp) \
116 if (isp->isp_osinfo.mboxwaiting) { \
117 isp->isp_osinfo.mboxwaiting = 0; \
118 wakeup(&isp->isp_osinfo.mboxwaiting); \
119 } \
120 isp->isp_mboxbsy = 0
121
122 #define MBOX_RELEASE(isp)
123
124 #ifndef SCSI_GOOD
125 #define SCSI_GOOD 0x0
126 #endif
127 #ifndef SCSI_CHECK
128 #define SCSI_CHECK 0x2
129 #endif
130 #ifndef SCSI_BUSY
131 #define SCSI_BUSY 0x8
132 #endif
133 #ifndef SCSI_QFULL
134 #define SCSI_QFULL 0x28
135 #endif
136
137 #define XS_T struct scsipi_xfer
138 #define XS_CHANNEL(xs) \
139 (((int) (xs)->sc_link->scsipi_scsi.channel == SCSI_CHANNEL_ONLY_ONE) ? \
140 0 : (xs)->sc_link->scsipi_scsi.channel)
141 #define XS_ISP(xs) (xs)->sc_link->adapter_softc
142 #define XS_LUN(xs) ((int) (xs)->sc_link->scsipi_scsi.lun)
143 #define XS_TGT(xs) ((int) (xs)->sc_link->scsipi_scsi.target)
144 #define XS_CDBP(xs) ((caddr_t) (xs)->cmd)
145 #define XS_CDBLEN(xs) (xs)->cmdlen
146 #define XS_XFRLEN(xs) (xs)->datalen
147 #define XS_TIME(xs) (xs)->timeout
148 #define XS_RESID(xs) (xs)->resid
149 #define XS_STSP(xs) (&(xs)->status)
150 #define XS_SNSP(xs) (&(xs)->sense.scsi_sense)
151 #define XS_SNSLEN(xs) (sizeof (xs)->sense)
152 #define XS_SNSKEY(xs) ((xs)->sense.scsi_sense.flags)
153 #define XS_TAG_P(ccb) (((xs)->xs_control & XS_CTL_POLL) != 0)
154 #define XS_TAG_TYPE(xs) \
155 (((xs)->xs_control & XS_CTL_URGENT) ? REQFLAG_HTAG : \
156 ((xs)->bp && xs->bp->b_flags & B_ASYNC) ? REQFLAG_STAG : REQFLAG_OTAG)
157
158 #define XS_SETERR(xs, v) (xs)->error = v
159
160 # define HBA_NOERROR XS_NOERROR
161 # define HBA_BOTCH XS_DRIVER_STUFFUP
162 # define HBA_CMDTIMEOUT XS_TIMEOUT
163 # define HBA_SELTIMEOUT XS_SELTIMEOUT
164 # define HBA_TGTBSY XS_BUSY
165 # define HBA_BUSRESET XS_RESET
166 # define HBA_ABORTED XS_DRIVER_STUFFUP
167 # define HBA_DATAOVR XS_DRIVER_STUFFUP
168 # define HBA_ARQFAIL XS_DRIVER_STUFFUP
169
170 #define XS_ERR(xs) (xs)->error
171
172 #define XS_NOERR(xs) (xs)->error == XS_NOERROR
173
174 #define XS_INITERR(xs) (xs)->error = 0, XS_CMD_S_CLEAR(xs)
175
176 #define XS_SAVE_SENSE(xs, sp) \
177 bcopy(sp->req_sense_data, &(xs)->sense, \
178 imin(XS_SNSLEN(xs), sp->req_sense_len))
179
180 #define XS_SET_STATE_STAT(a, b, c)
181
182 #define DEFAULT_IID(x) 7
183 #define DEFAULT_LOOPID(x) 108
184 #define DEFAULT_NODEWWN(isp) (isp)->isp_osinfo.un._wwn
185 #define DEFAULT_PORTWWN(isp) \
186 isp_port_from_node_wwn((isp), DEFAULT_NODEWWN(isp))
187 #define PORT_FROM_NODE_WWN isp_port_from_node_wwn
188
189 #define ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src) \
190 if((void *)src != (void *)dest) bcopy(src, dest, sizeof (isp_pdb_t))
191 #define ISP_SWIZZLE_ICB(a, b)
192 #ifdef __sparc__
193 #define ISP_SWIZZLE_REQUEST(a, b) \
194 ISP_SBUSIFY_ISPHDR(a, &(b)->req_header); \
195 ISP_SBUSIFY_ISPREQ(a, b)
196 #define ISP_UNSWIZZLE_RESPONSE(a, b, c) \
197 ISP_SBUSIFY_ISPHDR(a, &(b)->req_header)
198 #else
199 #define ISP_SWIZZLE_REQUEST(a, b)
200 #define ISP_UNSWIZZLE_RESPONSE(a, b, c)
201 #endif
202 #define ISP_SWIZZLE_SNS_REQ(a, b)
203 #define ISP_UNSWIZZLE_SNS_RSP(a, b, c)
204 #ifdef __sparc__
205 #define ISP_SWIZZLE_NVRAM_WORD(isp, rp) \
206 { \
207 u_int16_t tmp = *rp >> 8; \
208 tmp |= ((*rp & 0xff) << 8); \
209 *rp = tmp; \
210 }
211 #else
212 #define ISP_SWIZZLE_NVRAM_WORD(isp, rp)
213 #endif
214
215 /*
216 * Includes of common header files
217 */
218
219 #include <dev/ic/ispreg.h>
220 #include <dev/ic/ispvar.h>
221 #include <dev/ic/ispmbox.h>
222
223 /*
224 * isp_osinfo definitions, extensions and shorthand.
225 */
226 #define isp_name isp_osinfo._dev.dv_xname
227 #define isp_unit isp_osinfo._dev.dv_unit
228
229 /*
230 * Driver prototypes..
231 */
232 void isp_attach __P((struct ispsoftc *));
233 void isp_uninit __P((struct ispsoftc *));
234
235 static inline void isp_lock __P((struct ispsoftc *));
236 static inline void isp_unlock __P((struct ispsoftc *));
237 static inline char *strncat __P((char *, const char *, size_t));
238 static inline u_int64_t
239 isp_port_from_node_wwn __P((struct ispsoftc *, u_int64_t));
240 static inline u_int64_t
241 isp_microtime_sub __P((struct timeval *, struct timeval *));
242 static void isp_wait_complete __P((struct ispsoftc *));
243
244 /*
245 * Driver wide data...
246 */
247
248 /*
249 * Locking macros...
250 */
251 #define ISP_LOCK isp_lock
252 #define ISP_UNLOCK isp_unlock
253
254 /*
255 * Platform private flags
256 */
257
258 #define XS_PSTS_INWDOG 0x10000000
259 #define XS_PSTS_GRACE 0x20000000
260 #define XS_PSTS_ALL 0x30000000
261
262 #define XS_CMD_S_WDOG(xs) (xs)->xs_status |= XS_PSTS_INWDOG
263 #define XS_CMD_C_WDOG(xs) (xs)->xs_status &= ~XS_PSTS_INWDOG
264 #define XS_CMD_WDOG_P(xs) (((xs)->xs_status & XS_PSTS_INWDOG) != 0)
265
266 #define XS_CMD_S_GRACE(xs) (xs)->xs_status |= XS_PSTS_GRACE
267 #define XS_CMD_C_GRACE(xs) (xs)->xs_status &= ~XS_PSTS_GRACE
268 #define XS_CMD_GRACE_P(xs) (((xs)->xs_status & XS_PSTS_GRACE) != 0)
269
270 #define XS_CMD_S_DONE(xs) (xs)->xs_status |= XS_STS_DONE
271 #define XS_CMD_C_DONE(xs) (xs)->xs_status &= ~XS_STS_DONE
272 #define XS_CMD_DONE_P(xs) (((xs)->xs_status & XS_STS_DONE) != 0)
273
274 #define XS_CMD_S_CLEAR(xs) (xs)->xs_status &= ~XS_PSTS_ALL
275
276 /*
277 * Platform specific 'inline' or support functions
278 */
279 static inline void
280 isp_lock(isp)
281 struct ispsoftc *isp;
282 {
283 int s = splbio();
284 if (isp->isp_osinfo.islocked == 0) {
285 isp->isp_osinfo.islocked = 1;
286 isp->isp_osinfo.splsaved = s;
287 } else {
288 splx(s);
289 }
290 }
291
292 static inline void
293 isp_unlock(isp)
294 struct ispsoftc *isp;
295 {
296 if (isp->isp_osinfo.islocked) {
297 isp->isp_osinfo.islocked = 0;
298 splx(isp->isp_osinfo.splsaved);
299 }
300 }
301
302 static inline char *
303 strncat(d, s, c)
304 char *d;
305 const char *s;
306 size_t c;
307 {
308 char *t = d;
309
310 if (c) {
311 while (*d)
312 d++;
313 while ((*d++ = *s++)) {
314 if (--c == 0) {
315 *d = '\0';
316 break;
317 }
318 }
319 }
320 return (t);
321 }
322
323 static inline u_int64_t
324 isp_microtime_sub(b, a)
325 struct timeval *b;
326 struct timeval *a;
327 {
328 struct timeval x;
329 u_int64_t elapsed;
330 timersub(b, a, &x);
331 elapsed = GET_NANOSEC(&x);
332 if (elapsed == 0)
333 elapsed++;
334 return (elapsed);
335 }
336
337 static inline void
338 isp_wait_complete(isp)
339 struct ispsoftc *isp;
340 {
341 if (isp->isp_osinfo.onintstack || isp->isp_osinfo.no_mbox_ints) {
342 int usecs = 0;
343 while (usecs < 2 * 1000000) {
344 (void) isp_intr(isp);
345 if (isp->isp_mboxbsy == 0) {
346 break;
347 }
348 USEC_DELAY(500);
349 usecs += 500;
350 }
351 if (isp->isp_mboxbsy != 0) {
352 isp_prt(isp, ISP_LOGWARN, "Mailbox Cmd (poll) Timeout");
353 }
354 } else {
355 int rv = 0;
356 isp->isp_osinfo.mboxwaiting = 1;
357 while (isp->isp_osinfo.mboxwaiting && rv == 0) {
358 static struct timeval twosec = { 2, 0 };
359 int timo;
360 struct timeval tv;
361 microtime(&tv);
362 timeradd(&tv, &twosec, &tv);
363 if ((timo = hzto(&tv)) == 0) {
364 timo = 1;
365 }
366 rv = tsleep(&isp->isp_osinfo.mboxwaiting,
367 PRIBIO, "isp_mboxcmd", timo);
368 }
369 if (rv == EWOULDBLOCK) {
370 isp->isp_mboxbsy = 0;
371 isp->isp_osinfo.mboxwaiting = 0;
372 isp_prt(isp, ISP_LOGWARN, "Mailbox Cmd (intr) Timeout");
373 }
374 }
375 }
376
377 static inline u_int64_t
378 isp_port_from_node_wwn(struct ispsoftc *isp, u_int64_t node_wwn)
379 {
380 u_int64_t rv = node_wwn;
381 if ((node_wwn >> 60) == 2) {
382 rv = node_wwn |
383 (((u_int64_t)(isp->isp_unit+1)) << 48);
384 }
385 return (rv);
386 }
387
388 /*
389 * Common inline functions
390 */
391 #define INLINE inline
392 #include <dev/ic/isp_inline.h>
393
394 #if !defined(ISP_DISABLE_FW) && !defined(ISP_COMPILE_FW)
395 #define ISP_COMPILE_FW 1
396 #endif
397 #endif /* _ISP_NETBSD_H */
398