1 /* $NetBSD: isp_netbsd.h,v 1.52 2003/12/04 13:57:30 keihan Exp $ */
2 /*
3 * This driver, which is contained in NetBSD in the files:
4 *
5 * sys/dev/ic/isp.c
6 * sys/dev/ic/isp_inline.h
7 * sys/dev/ic/isp_netbsd.c
8 * sys/dev/ic/isp_netbsd.h
9 * sys/dev/ic/isp_target.c
10 * sys/dev/ic/isp_target.h
11 * sys/dev/ic/isp_tpublic.h
12 * sys/dev/ic/ispmbox.h
13 * sys/dev/ic/ispreg.h
14 * sys/dev/ic/ispvar.h
15 * sys/microcode/isp/asm_sbus.h
16 * sys/microcode/isp/asm_1040.h
17 * sys/microcode/isp/asm_1080.h
18 * sys/microcode/isp/asm_12160.h
19 * sys/microcode/isp/asm_2100.h
20 * sys/microcode/isp/asm_2200.h
21 * sys/pci/isp_pci.c
22 * sys/sbus/isp_sbus.c
23 *
24 * Is being actively maintained by Matthew Jacob (mjacob@NetBSD.org).
25 * This driver also is shared source with FreeBSD, OpenBSD, Linux, Solaris,
26 * Linux versions. This tends to be an interesting maintenance problem.
27 *
28 * Please coordinate with Matthew Jacob on changes you wish to make here.
29 */
30 /*
31 * NetBSD Specific definitions for the Qlogic ISP Host Adapter
32 * Matthew Jacob <mjacob@nas.nasa.gov>
33 */
34 /*
35 * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
36 * All rights reserved.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. The name of the author may not be used to endorse or promote products
47 * derived from this software without specific prior written permission
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
50 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
51 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
52 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
53 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
54 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
55 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
56 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
57 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
58 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59 */
60 #ifndef _ISP_NETBSD_H
61 #define _ISP_NETBSD_H
62
63 #include <sys/types.h>
64 #include <sys/param.h>
65 #include <sys/systm.h>
66 #include <sys/kernel.h>
67 #include <sys/errno.h>
68 #include <sys/ioctl.h>
69 #include <sys/device.h>
70 #include <sys/malloc.h>
71 #include <sys/buf.h>
72 #include <sys/proc.h>
73 #include <sys/user.h>
74 #include <sys/kthread.h>
75
76 #include <machine/bus.h>
77
78 #include <dev/scsipi/scsi_all.h>
79 #include <dev/scsipi/scsipi_all.h>
80 #include <dev/scsipi/scsiconf.h>
81
82 #include <dev/scsipi/scsi_message.h>
83 #include <dev/scsipi/scsipi_debug.h>
84
85 #include "opt_isp.h"
86
87 /*
88 * Efficiency- get rid of SBus code && tests unless we need them.
89 */
90 #if defined(__sparcv9__ ) || defined(__sparc__)
91 #define ISP_SBUS_SUPPORTED 1
92 #else
93 #define ISP_SBUS_SUPPORTED 0
94 #endif
95
96 #define ISP_PLATFORM_VERSION_MAJOR 2
97 #define ISP_PLATFORM_VERSION_MINOR 1
98
99 struct isposinfo {
100 struct device _dev;
101 struct scsipi_channel _chan;
102 struct scsipi_channel _chan_b;
103 struct scsipi_adapter _adapter;
104 bus_dma_tag_t dmatag;
105 bus_dmamap_t rqdmap;
106 bus_dmamap_t rsdmap;
107 bus_dmamap_t scdmap; /* FC only */
108 int splsaved;
109 int mboxwaiting;
110 u_int32_t islocked;
111 u_int32_t onintstack;
112 unsigned int : 26,
113 loop_checked : 1,
114 mbox_wanted : 1,
115 mbox_locked : 1,
116 no_mbox_ints : 1,
117 paused : 1,
118 blocked : 1;
119 union {
120 u_int64_t _wwn;
121 u_int16_t _discovered[2];
122 #define wwn_seed un._wwn
123 #define discovered un._discovered
124 } un;
125 u_int32_t threadwork;
126 struct proc * thread;
127 };
128 #define isp_dmatag isp_osinfo.dmatag
129 #define isp_rqdmap isp_osinfo.rqdmap
130 #define isp_rsdmap isp_osinfo.rsdmap
131 #define isp_scdmap isp_osinfo.scdmap
132
133 #define ISP_MUSTPOLL(isp) \
134 (isp->isp_osinfo.onintstack || isp->isp_osinfo.no_mbox_ints)
135
136 #define HANDLE_LOOPSTATE_IN_OUTER_LAYERS 1
137
138 /*
139 * Required Macros/Defines
140 */
141
142 #define INLINE __inline
143
144 #define ISP2100_SCRLEN 0x800
145
146 #define MEMZERO(dst, amt) memset((dst), 0, (amt))
147 #define MEMCPY(dst, src, amt) memcpy((dst), (src), (amt))
148 #define SNPRINTF snprintf
149 #define USEC_DELAY DELAY
150 #define USEC_SLEEP(isp, x) \
151 if (!ISP_MUSTPOLL(isp)) \
152 ISP_UNLOCK(isp); \
153 DELAY(x); \
154 if (!ISP_MUSTPOLL(isp)) \
155 ISP_LOCK(isp)
156
157 #define NANOTIME_T struct timeval
158 #define GET_NANOTIME microtime
159 #define GET_NANOSEC(x) (((x)->tv_sec * 1000000 + (x)->tv_usec) * 1000)
160 #define NANOTIME_SUB isp_microtime_sub
161
162 #define MAXISPREQUEST(isp) 256
163
164
165 #define MEMORYBARRIER(isp, type, offset, size) \
166 switch (type) { \
167 case SYNC_REQUEST: \
168 { \
169 off_t off = (off_t) offset * QENTRY_LEN; \
170 bus_dmamap_sync(isp->isp_dmatag, isp->isp_rqdmap, \
171 off, size, BUS_DMASYNC_PREWRITE); \
172 break; \
173 } \
174 case SYNC_RESULT: \
175 { \
176 off_t off = (off_t) offset * QENTRY_LEN; \
177 bus_dmamap_sync(isp->isp_dmatag, isp->isp_rsdmap, \
178 off, size, BUS_DMASYNC_POSTREAD); \
179 break; \
180 } \
181 case SYNC_SFORDEV: \
182 { \
183 off_t off = (off_t) offset; \
184 bus_dmamap_sync(isp->isp_dmatag, isp->isp_scdmap, \
185 off, size, BUS_DMASYNC_PREWRITE); \
186 break; \
187 } \
188 case SYNC_SFORCPU: \
189 { \
190 off_t off = (off_t) offset; \
191 bus_dmamap_sync(isp->isp_dmatag, isp->isp_scdmap, \
192 off, size, BUS_DMASYNC_POSTREAD); \
193 break; \
194 } \
195 case SYNC_REG: \
196 default: \
197 break; \
198 }
199
200 #define MBOX_ACQUIRE(isp) \
201 if (isp->isp_osinfo.onintstack) { \
202 if (isp->isp_osinfo.mbox_locked) { \
203 mbp->param[0] = MBOX_HOST_INTERFACE_ERROR; \
204 isp_prt(isp, ISP_LOGERR, "cannot acquire MBOX lock"); \
205 return; \
206 } \
207 } else { \
208 while (isp->isp_osinfo.mbox_locked) { \
209 isp->isp_osinfo.mbox_wanted = 1; \
210 (void) tsleep(&isp->isp_osinfo.mboxwaiting+1, \
211 PRIBIO, "mbox_acquire", 0); \
212 } \
213 } \
214 isp->isp_osinfo.mbox_locked = 1
215
216 #define MBOX_WAIT_COMPLETE isp_wait_complete
217
218 #define MBOX_NOTIFY_COMPLETE(isp) \
219 if (isp->isp_osinfo.mboxwaiting) { \
220 isp->isp_osinfo.mboxwaiting = 0; \
221 wakeup(&isp->isp_osinfo.mboxwaiting); \
222 } \
223 isp->isp_mboxbsy = 0
224
225 #define MBOX_RELEASE(isp) \
226 if (isp->isp_osinfo.mbox_wanted) { \
227 isp->isp_osinfo.mbox_wanted = 0; \
228 wakeup(&isp->isp_osinfo.mboxwaiting+1); \
229 } \
230 isp->isp_osinfo.mbox_locked = 0
231
232 #define FC_SCRATCH_ACQUIRE(isp)
233 #define FC_SCRATCH_RELEASE(isp)
234
235 #ifndef SCSI_GOOD
236 #define SCSI_GOOD 0x0
237 #endif
238 #ifndef SCSI_CHECK
239 #define SCSI_CHECK 0x2
240 #endif
241 #ifndef SCSI_BUSY
242 #define SCSI_BUSY 0x8
243 #endif
244 #ifndef SCSI_QFULL
245 #define SCSI_QFULL 0x28
246 #endif
247
248 #define XS_T struct scsipi_xfer
249 #define XS_CHANNEL(xs) ((int) (xs)->xs_periph->periph_channel->chan_channel)
250 #define XS_ISP(xs) \
251 ((void *)(xs)->xs_periph->periph_channel->chan_adapter->adapt_dev)
252 #define XS_LUN(xs) ((int) (xs)->xs_periph->periph_lun)
253 #define XS_TGT(xs) ((int) (xs)->xs_periph->periph_target)
254 #define XS_CDBP(xs) ((caddr_t) (xs)->cmd)
255 #define XS_CDBLEN(xs) (xs)->cmdlen
256 #define XS_XFRLEN(xs) (xs)->datalen
257 #define XS_TIME(xs) (xs)->timeout
258 #define XS_RESID(xs) (xs)->resid
259 #define XS_STSP(xs) (&(xs)->status)
260 #define XS_SNSP(xs) (&(xs)->sense.scsi_sense)
261 #define XS_SNSLEN(xs) (sizeof (xs)->sense)
262 #define XS_SNSKEY(xs) ((xs)->sense.scsi_sense.flags)
263 #define XS_TAG_P(ccb) (((xs)->xs_control & XS_CTL_POLL) != 0)
264 #define XS_TAG_TYPE(xs) \
265 (((xs)->xs_control & XS_CTL_URGENT) ? REQFLAG_HTAG : \
266 ((xs)->bp && xs->bp->b_flags & B_ASYNC) ? REQFLAG_STAG : REQFLAG_OTAG)
267
268 #define XS_SETERR(xs, v) (xs)->error = v
269
270 # define HBA_NOERROR XS_NOERROR
271 # define HBA_BOTCH XS_DRIVER_STUFFUP
272 # define HBA_CMDTIMEOUT XS_TIMEOUT
273 # define HBA_SELTIMEOUT XS_SELTIMEOUT
274 # define HBA_TGTBSY XS_BUSY
275 # define HBA_BUSRESET XS_RESET
276 # define HBA_ABORTED XS_DRIVER_STUFFUP
277 # define HBA_DATAOVR XS_DRIVER_STUFFUP
278 # define HBA_ARQFAIL XS_DRIVER_STUFFUP
279
280 #define XS_ERR(xs) (xs)->error
281
282 #define XS_NOERR(xs) (xs)->error == XS_NOERROR
283
284 #define XS_INITERR(xs) (xs)->error = 0, XS_CMD_S_CLEAR(xs)
285
286 #define XS_SAVE_SENSE(xs, sp) \
287 if (xs->error == XS_NOERROR) { \
288 xs->error = XS_SENSE; \
289 } \
290 memcpy(&(xs)->sense, sp->req_sense_data, \
291 imin(XS_SNSLEN(xs), sp->req_sense_len))
292
293 #define XS_SET_STATE_STAT(a, b, c)
294
295 #define DEFAULT_IID(x) 7
296 #define DEFAULT_LOOPID(x) 108
297 #define DEFAULT_NODEWWN(isp) (isp)->isp_osinfo.un._wwn
298 #define DEFAULT_PORTWWN(isp) (isp)->isp_osinfo.un._wwn
299 #define ISP_NODEWWN(isp) FCPARAM(isp)->isp_nodewwn
300 #define ISP_PORTWWN(isp) FCPARAM(isp)->isp_portwwn
301
302 #if _BYTE_ORDER == _BIG_ENDIAN
303 #ifdef ISP_SBUS_SUPPORTED
304 #define ISP_IOXPUT_8(isp, s, d) *(d) = s
305 #define ISP_IOXPUT_16(isp, s, d) \
306 *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap16(s)
307 #define ISP_IOXPUT_32(isp, s, d) \
308 *(d) = (isp->isp_bustype == ISP_BT_SBUS)? s : bswap32(s)
309
310 #define ISP_IOXGET_8(isp, s, d) d = (*((u_int8_t *)s))
311 #define ISP_IOXGET_16(isp, s, d) \
312 d = (isp->isp_bustype == ISP_BT_SBUS)? \
313 *((u_int16_t *)s) : bswap16(*((u_int16_t *)s))
314 #define ISP_IOXGET_32(isp, s, d) \
315 d = (isp->isp_bustype == ISP_BT_SBUS)? \
316 *((u_int32_t *)s) : bswap32(*((u_int32_t *)s))
317 #else
318 #define ISP_IOXPUT_8(isp, s, d) *(d) = s
319 #define ISP_IOXPUT_16(isp, s, d) *(d) = bswap16(s)
320 #define ISP_IOXPUT_32(isp, s, d) *(d) = bswap32(s)
321 #define ISP_IOXGET_8(isp, s, d) d = (*((u_int8_t *)s))
322 #define ISP_IOXGET_16(isp, s, d) d = bswap16(*((u_int16_t *)s))
323 #define ISP_IOXGET_32(isp, s, d) d = bswap32(*((u_int32_t *)s))
324 #endif
325 #define ISP_SWIZZLE_NVRAM_WORD(isp, rp) *rp = bswap16(*rp)
326 #else
327 #define ISP_IOXPUT_8(isp, s, d) *(d) = s
328 #define ISP_IOXPUT_16(isp, s, d) *(d) = s
329 #define ISP_IOXPUT_32(isp, s, d) *(d) = s
330 #define ISP_IOXGET_8(isp, s, d) d = *(s)
331 #define ISP_IOXGET_16(isp, s, d) d = *(s)
332 #define ISP_IOXGET_32(isp, s, d) d = *(s)
333 #define ISP_SWIZZLE_NVRAM_WORD(isp, rp)
334 #endif
335
336 /*
337 * Includes of common header files
338 */
339
340 #include <dev/ic/ispreg.h>
341 #include <dev/ic/ispvar.h>
342 #include <dev/ic/ispmbox.h>
343 #include <dev/ic/isp_ioctl.h>
344
345 /*
346 * isp_osinfo definitions, extensions and shorthand.
347 */
348 #define isp_name isp_osinfo._dev.dv_xname
349 #define isp_unit isp_osinfo._dev.dv_unit
350 #define isp_chanA isp_osinfo._chan
351 #define isp_chanB isp_osinfo._chan_b
352
353
354 /*
355 * Driver prototypes..
356 */
357 void isp_attach(struct ispsoftc *);
358 void isp_uninit(struct ispsoftc *);
359
360 static INLINE void isp_lock(struct ispsoftc *);
361 static INLINE void isp_unlock(struct ispsoftc *);
362 static INLINE char *strncat(char *, const char *, size_t);
363 static INLINE u_int64_t
364 isp_microtime_sub(struct timeval *, struct timeval *);
365 static void isp_wait_complete(struct ispsoftc *);
366
367 /*
368 * Driver wide data...
369 */
370
371 /*
372 * Locking macros...
373 */
374 #define ISP_LOCK isp_lock
375 #define ISP_UNLOCK isp_unlock
376 #define ISP_ILOCK(x) isp_lock(x); isp->isp_osinfo.onintstack++
377 #define ISP_IUNLOCK(x) isp->isp_osinfo.onintstack--; isp_unlock(x)
378
379 /*
380 * Platform private flags
381 */
382
383 #define XS_PSTS_INWDOG 0x10000000
384 #define XS_PSTS_GRACE 0x20000000
385 #define XS_PSTS_ALL 0x30000000
386
387 #define XS_CMD_S_WDOG(xs) (xs)->xs_status |= XS_PSTS_INWDOG
388 #define XS_CMD_C_WDOG(xs) (xs)->xs_status &= ~XS_PSTS_INWDOG
389 #define XS_CMD_WDOG_P(xs) (((xs)->xs_status & XS_PSTS_INWDOG) != 0)
390
391 #define XS_CMD_S_GRACE(xs) (xs)->xs_status |= XS_PSTS_GRACE
392 #define XS_CMD_C_GRACE(xs) (xs)->xs_status &= ~XS_PSTS_GRACE
393 #define XS_CMD_GRACE_P(xs) (((xs)->xs_status & XS_PSTS_GRACE) != 0)
394
395 #define XS_CMD_S_DONE(xs) (xs)->xs_status |= XS_STS_DONE
396 #define XS_CMD_C_DONE(xs) (xs)->xs_status &= ~XS_STS_DONE
397 #define XS_CMD_DONE_P(xs) (((xs)->xs_status & XS_STS_DONE) != 0)
398
399 #define XS_CMD_S_CLEAR(xs) (xs)->xs_status &= ~XS_PSTS_ALL
400
401 /*
402 * Platform specific 'inline' or support functions
403 */
404 static INLINE void
405 isp_lock(struct ispsoftc *isp)
406 {
407 int s = splbio();
408 if (isp->isp_osinfo.islocked++ == 0) {
409 isp->isp_osinfo.splsaved = s;
410 } else {
411 splx(s);
412 }
413 }
414
415 static INLINE void
416 isp_unlock(struct ispsoftc *isp)
417 {
418 if (isp->isp_osinfo.islocked-- <= 1) {
419 isp->isp_osinfo.islocked = 0;
420 splx(isp->isp_osinfo.splsaved);
421 }
422 }
423
424 static INLINE char *
425 strncat(char *d, const char *s, size_t c)
426 {
427 char *t = d;
428
429 if (c) {
430 while (*d)
431 d++;
432 while ((*d++ = *s++)) {
433 if (--c == 0) {
434 *d = '\0';
435 break;
436 }
437 }
438 }
439 return (t);
440 }
441
442 static INLINE u_int64_t
443 isp_microtime_sub(struct timeval *b, struct timeval *a)
444 {
445 struct timeval x;
446 u_int64_t elapsed;
447 timersub(b, a, &x);
448 elapsed = GET_NANOSEC(&x);
449 if (elapsed == 0)
450 elapsed++;
451 return (elapsed);
452 }
453
454 static INLINE void
455 isp_wait_complete(struct ispsoftc *isp)
456 {
457 int lim;
458 if (isp->isp_mbxwrk0)
459 lim = 60;
460 else
461 lim = 5;
462 if (ISP_MUSTPOLL(isp)) {
463 int useclim = 1000000 * lim, usecs = 0;
464 /*
465 * For sanity's sake, we don't delay longer
466 * than 5 seconds for polled commands.
467 */
468 while (usecs < useclim) {
469 u_int16_t isr, sema, mbox;
470 if (isp->isp_mboxbsy == 0) {
471 break;
472 }
473 if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
474 isp_intr(isp, isr, sema, mbox);
475 if (isp->isp_mboxbsy == 0) {
476 break;
477 }
478 }
479 USEC_DELAY(500);
480 usecs += 500;
481 }
482 if (isp->isp_mboxbsy != 0) {
483 isp_prt(isp, ISP_LOGWARN,
484 "Polled Mailbox Command (0x%x) Timeout",
485 isp->isp_lastmbxcmd);
486 }
487 } else {
488 int rv = 0;
489 isp->isp_osinfo.mboxwaiting = 1;
490 while (isp->isp_osinfo.mboxwaiting && rv == 0) {
491 struct timeval dtime;
492 int timo;
493 struct timeval tv;
494
495 dtime.tv_sec = lim;
496 dtime.tv_usec = 0;
497 microtime(&tv);
498 timeradd(&tv, &dtime, &tv);
499 if ((timo = hzto(&tv)) == 0) {
500 timo = 1;
501 }
502 rv = tsleep(&isp->isp_osinfo.mboxwaiting,
503 PRIBIO, "isp_mboxcmd", timo);
504 }
505 if (rv == EWOULDBLOCK) {
506 isp->isp_mboxbsy = 0;
507 isp->isp_osinfo.mboxwaiting = 0;
508 isp_prt(isp, ISP_LOGWARN,
509 "Interrupting Mailbox Command (0x%x) Timeout",
510 isp->isp_lastmbxcmd);
511 }
512 }
513 }
514
515
516 /*
517 * Common inline functions
518 */
519 #include <dev/ic/isp_inline.h>
520
521 #if !defined(ISP_DISABLE_FW) && !defined(ISP_COMPILE_FW)
522 #define ISP_COMPILE_FW 1
523 #endif
524 #endif /* _ISP_NETBSD_H */
Cache object: 2cff982557b76b6c4f299efca2a2a656
|