isp_netbsd.c revision 1.18.2.15 1 /* $NetBSD: isp_netbsd.c,v 1.18.2.15 2001/04/21 17:48:32 bouyer 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 (at) 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 * Platform (NetBSD) dependent common attachment code for Qlogic adapters.
32 * Matthew Jacob <mjacob (at) 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
61 #include <dev/ic/isp_netbsd.h>
62 #include <sys/scsiio.h>
63
64
65 /*
66 * Set a timeout for the watchdogging of a command.
67 *
68 * The dimensional analysis is
69 *
70 * milliseconds * (seconds/millisecond) * (ticks/second) = ticks
71 *
72 * =
73 *
74 * (milliseconds / 1000) * hz = ticks
75 *
76 *
77 * For timeouts less than 1 second, we'll get zero. Because of this, and
78 * because we want to establish *our* timeout to be longer than what the
79 * firmware might do, we just add 3 seconds at the back end.
80 */
81 #define _XT(xs) ((((xs)->timeout/1000) * hz) + (3 * hz))
82
83 static void ispminphys(struct buf *);
84 static void isprequest (struct scsipi_channel *,
85 scsipi_adapter_req_t, void *);
86 static int
87 ispioctl(struct scsipi_channel *, u_long, caddr_t, int, struct proc *);
88
89 static void isp_polled_cmd(struct ispsoftc *, XS_T *);
90 static void isp_dog(void *);
91
92 /*
93 * Complete attachment of hardware, include subdevices.
94 */
95 void
96 isp_attach(struct ispsoftc *isp)
97 {
98 isp->isp_state = ISP_RUNSTATE;
99
100 isp->isp_osinfo._adapter.adapt_dev = &isp->isp_osinfo._dev;
101 isp->isp_osinfo._adapter.adapt_nchannels = IS_DUALBUS(isp) ? 2 : 1;
102 isp->isp_osinfo._adapter.adapt_openings = isp->isp_maxcmds; /* XXX per adapter or per channel ? */
103 isp->isp_osinfo._adapter.adapt_max_periph =
104 (isp->isp_maxcmds > 256) ? 256 : isp->isp_maxcmds;
105 isp->isp_osinfo._adapter.adapt_ioctl = ispioctl;
106 isp->isp_osinfo._adapter.adapt_request = isprequest;
107 isp->isp_osinfo._adapter.adapt_minphys = ispminphys;
108
109 isp->isp_osinfo._chan.chan_adapter = &isp->isp_osinfo._adapter;
110 isp->isp_osinfo._chan.chan_bustype = &scsi_bustype;
111 isp->isp_osinfo._chan.chan_channel = 0;
112 /*
113 * Until the midlayer is fixed to use REPORT LUNS, limit to 8 luns.
114 */
115 isp->isp_osinfo._chan.chan_nluns =
116 (isp->isp_maxluns < 7)? isp->isp_maxluns : 8;
117
118 TAILQ_INIT(&isp->isp_osinfo.waitq); /* The 2nd bus will share.. */
119
120 if (IS_FC(isp)) {
121 isp->isp_osinfo._chan.chan_ntargets = MAX_FC_TARG;
122 } else {
123 sdparam *sdp = isp->isp_param;
124 isp->isp_osinfo._chan.chan_ntargets = MAX_TARGETS;
125 isp->isp_osinfo._chan.chan_id = sdp->isp_initiator_id;
126 isp->isp_osinfo.discovered[0] = 1 << sdp->isp_initiator_id;
127 if (IS_DUALBUS(isp)) {
128 isp->isp_osinfo._chan_b = isp->isp_osinfo._chan;
129 sdp++;
130 isp->isp_osinfo.discovered[1] =
131 1 << sdp->isp_initiator_id;
132 isp->isp_osinfo._chan_b.chan_id = sdp->isp_initiator_id;
133 isp->isp_osinfo._chan_b.chan_channel = 1;
134 }
135 }
136
137 /*
138 * Send a SCSI Bus Reset.
139 */
140 if (IS_SCSI(isp)) {
141 int bus = 0;
142 ISP_LOCK(isp);
143 (void) isp_control(isp, ISPCTL_RESET_BUS, &bus);
144 if (IS_DUALBUS(isp)) {
145 bus++;
146 (void) isp_control(isp, ISPCTL_RESET_BUS, &bus);
147 }
148 ISP_UNLOCK(isp);
149 } else {
150 int defid;
151 fcparam *fcp = isp->isp_param;
152 delay(2 * 1000000);
153 defid = MAX_FC_TARG;
154 ISP_LOCK(isp);
155 /*
156 * We probably won't have clock interrupts running,
157 * so we'll be really short (smoke test, really)
158 * at this time.
159 */
160 if (isp_control(isp, ISPCTL_FCLINK_TEST, NULL)) {
161 (void) isp_control(isp, ISPCTL_PDB_SYNC, NULL);
162 if (fcp->isp_fwstate == FW_READY &&
163 fcp->isp_loopstate >= LOOP_PDB_RCVD) {
164 defid = fcp->isp_loopid;
165 }
166 }
167 ISP_UNLOCK(isp);
168 isp->isp_osinfo._chan.chan_id = defid;
169 }
170
171 /*
172 * After this point, we'll be doing the new configuration
173 * schema which allows interrups, so we can do tsleep/wakeup
174 * for mailbox stuff at that point.
175 */
176 isp->isp_osinfo.no_mbox_ints = 0;
177
178 /*
179 * And attach children (if any).
180 */
181 config_found((void *)isp, &isp->isp_osinfo._chan, scsiprint);
182 if (IS_DUALBUS(isp)) {
183 config_found((void *)isp, &isp->isp_osinfo._chan_b, scsiprint);
184 }
185 }
186
187 /*
188 * minphys our xfers
189 *
190 * Unfortunately, the buffer pointer describes the target device- not the
191 * adapter device, so we can't use the pointer to find out what kind of
192 * adapter we are and adjust accordingly.
193 */
194
195 static void
196 ispminphys(struct buf *bp)
197 {
198 /*
199 * XX: Only the 1020 has a 24 bit limit.
200 */
201 if (bp->b_bcount >= (1 << 24)) {
202 bp->b_bcount = (1 << 24);
203 }
204 minphys(bp);
205 }
206
207 static int
208 ispioctl(struct scsipi_channel *chan, u_long cmd, caddr_t addr, int flag,
209 struct proc *p)
210 {
211 struct ispsoftc *isp = (void *)chan->chan_adapter->adapt_dev;
212 int s, retval = ENOTTY;
213
214 switch (cmd) {
215 case SCBUSIORESET:
216 s = splbio();
217 if (isp_control(isp, ISPCTL_RESET_BUS, &chan->chan_channel))
218 retval = EIO;
219 else
220 retval = 0;
221 (void) splx(s);
222 break;
223 case ISP_SDBLEV:
224 {
225 int olddblev = isp->isp_dblev;
226 isp->isp_dblev = *(int *)addr;
227 *(int *)addr = olddblev;
228 retval = 0;
229 break;
230 }
231 case ISP_RESETHBA:
232 ISP_LOCK(isp);
233 isp_reinit(isp);
234 ISP_UNLOCK(isp);
235 retval = 0;
236 break;
237 case ISP_FC_RESCAN:
238 if (IS_FC(isp)) {
239 ISP_LOCK(isp);
240 if (isp_fc_runstate(isp, 5 * 1000000)) {
241 retval = EIO;
242 } else {
243 retval = 0;
244 }
245 ISP_UNLOCK(isp);
246 }
247 break;
248 case ISP_FC_LIP:
249 if (IS_FC(isp)) {
250 ISP_LOCK(isp);
251 if (isp_control(isp, ISPCTL_SEND_LIP, 0)) {
252 retval = EIO;
253 } else {
254 retval = 0;
255 }
256 ISP_UNLOCK(isp);
257 }
258 break;
259 case ISP_FC_GETDINFO:
260 {
261 struct isp_fc_device *ifc = (struct isp_fc_device *) addr;
262 struct lportdb *lp;
263
264 if (ifc->loopid < 0 || ifc->loopid >= MAX_FC_TARG) {
265 retval = EINVAL;
266 break;
267 }
268 ISP_LOCK(isp);
269 lp = &FCPARAM(isp)->portdb[ifc->loopid];
270 if (lp->valid) {
271 ifc->loopid = lp->loopid;
272 ifc->portid = lp->portid;
273 ifc->node_wwn = lp->node_wwn;
274 ifc->port_wwn = lp->port_wwn;
275 retval = 0;
276 } else {
277 retval = ENODEV;
278 }
279 ISP_UNLOCK(isp);
280 break;
281 }
282 default:
283 break;
284 }
285 return (retval);
286 }
287
288
289 static void
290 isprequest(struct scsipi_channel *chan, scsipi_adapter_req_t req, void *arg)
291 {
292 struct scsipi_periph *periph;
293 struct ispsoftc *isp = (void *)chan->chan_adapter->adapt_dev;
294 XS_T *xs;
295 int s, result;
296
297 switch (req) {
298 case ADAPTER_REQ_RUN_XFER:
299 xs = arg;
300 periph = xs->xs_periph;
301 s = splbio();
302 if (isp->isp_state < ISP_RUNSTATE) {
303 DISABLE_INTS(isp);
304 isp_init(isp);
305 if (isp->isp_state != ISP_INITSTATE) {
306 ENABLE_INTS(isp);
307 (void) splx(s);
308 XS_SETERR(xs, HBA_BOTCH);
309 scsipi_done(xs);
310 return;
311 }
312 isp->isp_state = ISP_RUNSTATE;
313 ENABLE_INTS(isp);
314 }
315
316 if (xs->xs_control & XS_CTL_POLL) {
317 volatile u_int8_t ombi = isp->isp_osinfo.no_mbox_ints;
318 isp->isp_osinfo.no_mbox_ints = 1;
319 isp_polled_cmd(isp, xs);
320 isp->isp_osinfo.no_mbox_ints = ombi;
321 (void) splx(s);
322 return;
323 }
324
325 result = isp_start(xs);
326 #if 0
327 {
328 static int na[16] = { 0 };
329 if (na[isp->isp_unit] < isp->isp_nactive) {
330 isp_prt(isp, ISP_LOGALL, "active hiwater %d", isp->isp_nactive);
331 na[isp->isp_unit] = isp->isp_nactive;
332 }
333 }
334 #endif
335 switch (result) {
336 case CMD_QUEUED:
337 if (xs->timeout) {
338 callout_reset(&xs->xs_callout, _XT(xs), isp_dog, xs);
339 }
340 break;
341 case CMD_EAGAIN:
342 xs->error = XS_REQUEUE;
343 scsipi_done(xs);
344 break;
345 case CMD_RQLATER:
346 xs->error = XS_RESOURCE_SHORTAGE;
347 scsipi_done(xs);
348 break;
349 case CMD_COMPLETE:
350 scsipi_done(xs);
351 break;
352 }
353 (void) splx(s);
354 return;
355
356 case ADAPTER_REQ_GROW_RESOURCES:
357 /* XXX Not supported. */
358 return;
359
360 case ADAPTER_REQ_SET_XFER_MODE:
361 {
362 struct scsipi_xfer_mode *xm = arg;
363 if (IS_SCSI(isp)) {
364 int dflags = 0;
365 sdparam *sdp = SDPARAM(isp);
366
367 sdp += chan->chan_channel;
368 if (xm->xm_mode & PERIPH_CAP_TQING)
369 dflags |= DPARM_TQING;
370 if (xm->xm_mode & PERIPH_CAP_WIDE16)
371 dflags |= DPARM_WIDE;
372 if (xm->xm_mode & PERIPH_CAP_SYNC)
373 dflags |= DPARM_SYNC;
374 s = splbio();
375 sdp->isp_devparam[xm->xm_target].dev_flags |= dflags;
376 dflags = sdp->isp_devparam[xm->xm_target].dev_flags;
377 sdp->isp_devparam[xm->xm_target].dev_update = 1;
378 isp->isp_update |= (1 << chan->chan_channel);
379 splx(s);
380 isp_prt(isp, ISP_LOGDEBUG1,
381 "ispioctl: device flags 0x%x for %d.%d.X",
382 dflags, chan->chan_channel, xm->xm_target);
383 }
384 }
385 }
386 }
387
388 static void
389 isp_polled_cmd( struct ispsoftc *isp, XS_T *xs)
390 {
391 int result;
392 int infinite = 0, mswait;
393
394 result = isp_start(xs);
395
396 switch (result) {
397 case CMD_QUEUED:
398 break;
399 case CMD_RQLATER:
400 case CMD_EAGAIN:
401 if (XS_NOERR(xs)) {
402 xs->error = XS_REQUEUE;
403 }
404 /* FALLTHROUGH */
405 case CMD_COMPLETE:
406 scsipi_done(xs);
407 return;
408
409 }
410
411 /*
412 * If we can't use interrupts, poll on completion.
413 */
414 if ((mswait = XS_TIME(xs)) == 0)
415 infinite = 1;
416
417 while (mswait || infinite) {
418 if (isp_intr((void *)isp)) {
419 if (XS_CMD_DONE_P(xs)) {
420 break;
421 }
422 }
423 USEC_DELAY(1000);
424 mswait -= 1;
425 }
426
427 /*
428 * If no other error occurred but we didn't finish,
429 * something bad happened.
430 */
431 if (XS_CMD_DONE_P(xs) == 0) {
432 if (isp_control(isp, ISPCTL_ABORT_CMD, xs)) {
433 isp_reinit(isp);
434 }
435 if (XS_NOERR(xs)) {
436 XS_SETERR(xs, HBA_BOTCH);
437 }
438 }
439 scsipi_done(xs);
440 }
441
442 void
443 isp_done(XS_T *xs)
444 {
445 XS_CMD_S_DONE(xs);
446 if (XS_CMD_WDOG_P(xs) == 0) {
447 struct ispsoftc *isp = XS_ISP(xs);
448 callout_stop(&xs->xs_callout);
449 if (XS_CMD_GRACE_P(xs)) {
450 isp_prt(isp, ISP_LOGDEBUG1,
451 "finished command on borrowed time");
452 }
453 XS_CMD_S_CLEAR(xs);
454 scsipi_done(xs);
455 }
456 }
457
458 static void
459 isp_dog(void *arg)
460 {
461 XS_T *xs = arg;
462 struct ispsoftc *isp = XS_ISP(xs);
463 u_int16_t handle;
464
465 ISP_ILOCK(isp);
466 /*
467 * We've decided this command is dead. Make sure we're not trying
468 * to kill a command that's already dead by getting it's handle and
469 * and seeing whether it's still alive.
470 */
471 handle = isp_find_handle(isp, xs);
472 if (handle) {
473 u_int16_t r, r1, i;
474
475 if (XS_CMD_DONE_P(xs)) {
476 isp_prt(isp, ISP_LOGDEBUG1,
477 "watchdog found done cmd (handle 0x%x)", handle);
478 ISP_IUNLOCK(isp);
479 return;
480 }
481
482 if (XS_CMD_WDOG_P(xs)) {
483 isp_prt(isp, ISP_LOGDEBUG1,
484 "recursive watchdog (handle 0x%x)", handle);
485 ISP_IUNLOCK(isp);
486 return;
487 }
488
489 XS_CMD_S_WDOG(xs);
490
491 i = 0;
492 do {
493 r = ISP_READ(isp, BIU_ISR);
494 USEC_DELAY(1);
495 r1 = ISP_READ(isp, BIU_ISR);
496 } while (r != r1 && ++i < 1000);
497
498 if (INT_PENDING(isp, r) && isp_intr(isp) && XS_CMD_DONE_P(xs)) {
499 isp_prt(isp, ISP_LOGDEBUG1, "watchdog cleanup (%x, %x)",
500 handle, r);
501 XS_CMD_C_WDOG(xs);
502 isp_done(xs);
503 } else if (XS_CMD_GRACE_P(xs)) {
504 isp_prt(isp, ISP_LOGDEBUG1, "watchdog timeout (%x, %x)",
505 handle, r);
506 /*
507 * Make sure the command is *really* dead before we
508 * release the handle (and DMA resources) for reuse.
509 */
510 (void) isp_control(isp, ISPCTL_ABORT_CMD, arg);
511
512 /*
513 * After this point, the comamnd is really dead.
514 */
515 if (XS_XFRLEN(xs)) {
516 ISP_DMAFREE(isp, xs, handle);
517 }
518 isp_destroy_handle(isp, handle);
519 XS_SETERR(xs, XS_TIMEOUT);
520 XS_CMD_S_CLEAR(xs);
521 isp_done(xs);
522 } else {
523 u_int16_t iptr, optr;
524 ispreq_t *mp;
525 isp_prt(isp, ISP_LOGDEBUG2,
526 "possible command timeout (%x, %x)", handle, r);
527 XS_CMD_C_WDOG(xs);
528 callout_reset(&xs->xs_callout, hz, isp_dog, xs);
529 if (isp_getrqentry(isp, &iptr, &optr, (void **) &mp)) {
530 ISP_UNLOCK(isp);
531 return;
532 }
533 XS_CMD_S_GRACE(xs);
534 MEMZERO((void *) mp, sizeof (*mp));
535 mp->req_header.rqs_entry_count = 1;
536 mp->req_header.rqs_entry_type = RQSTYPE_MARKER;
537 mp->req_modifier = SYNC_ALL;
538 mp->req_target = XS_CHANNEL(xs) << 7;
539 ISP_SWIZZLE_REQUEST(isp, mp);
540 ISP_ADD_REQUEST(isp, iptr);
541 }
542 } else {
543 isp_prt(isp, ISP_LOGDEBUG0, "watchdog with no command");
544 }
545 ISP_IUNLOCK(isp);
546 }
547
548 /*
549 * Free any associated resources prior to decommissioning and
550 * set the card to a known state (so it doesn't wake up and kick
551 * us when we aren't expecting it to).
552 *
553 * Locks are held before coming here.
554 */
555 void
556 isp_uninit(struct ispsoftc *isp)
557 {
558 isp_lock(isp);
559 /*
560 * Leave with interrupts disabled.
561 */
562 DISABLE_INTS(isp);
563 isp_unlock(isp);
564 }
565
566 int
567 isp_async(struct ispsoftc *isp, ispasync_t cmd, void *arg)
568 {
569 int bus, tgt;
570 int s = splbio();
571 switch (cmd) {
572 case ISPASYNC_NEW_TGT_PARAMS:
573 if (IS_SCSI(isp) && isp->isp_dblev) {
574 sdparam *sdp = isp->isp_param;
575 int flags;
576 struct scsipi_xfer_mode xm;
577
578 tgt = *((int *) arg);
579 bus = (tgt >> 16) & 0xffff;
580 tgt &= 0xffff;
581 sdp += bus;
582 flags = sdp->isp_devparam[tgt].cur_dflags;
583
584 xm.xm_mode = 0;
585 xm.xm_period = sdp->isp_devparam[tgt].cur_period;
586 xm.xm_offset = sdp->isp_devparam[tgt].cur_offset;
587 xm.xm_target = tgt;
588
589 if ((flags & DPARM_SYNC) && xm.xm_period && xm.xm_offset)
590 xm.xm_mode |= PERIPH_CAP_SYNC;
591 if (flags & DPARM_WIDE)
592 xm.xm_mode |= PERIPH_CAP_WIDE16;
593 if (flags & DPARM_TQING)
594 xm.xm_mode |= PERIPH_CAP_TQING;
595 scsipi_async_event(
596 bus ? (&isp->isp_osinfo._chan_b) : (&isp->isp_osinfo._chan),
597 ASYNC_EVENT_XFER_MODE,
598 &xm);
599 break;
600 }
601 case ISPASYNC_BUS_RESET:
602 if (arg)
603 bus = *((int *) arg);
604 else
605 bus = 0;
606 isp_prt(isp, ISP_LOGINFO, "SCSI bus %d reset detected", bus);
607 break;
608 case ISPASYNC_LOOP_DOWN:
609 /*
610 * Hopefully we get here in time to minimize the number
611 * of commands we are firing off that are sure to die.
612 */
613 scsipi_channel_freeze(&isp->isp_osinfo._chan, 1);
614 if (IS_DUALBUS(isp))
615 scsipi_channel_freeze(&isp->isp_osinfo._chan_b, 1);
616 isp_prt(isp, ISP_LOGINFO, "Loop DOWN");
617 break;
618 case ISPASYNC_LOOP_UP:
619 callout_reset(&isp->isp_osinfo._restart, 1,
620 scsipi_channel_timed_thaw, &isp->isp_osinfo._chan);
621 if (IS_DUALBUS(isp)) {
622 callout_reset(&isp->isp_osinfo._restart, 1,
623 scsipi_channel_timed_thaw,
624 &isp->isp_osinfo._chan_b);
625 }
626 isp_prt(isp, ISP_LOGINFO, "Loop UP");
627 break;
628 case ISPASYNC_PROMENADE:
629 if (IS_FC(isp) && isp->isp_dblev) {
630 const char fmt[] = "Target %d (Loop 0x%x) Port ID 0x%x "
631 "(role %s) %s\n Port WWN 0x%08x%08x\n Node WWN 0x%08x%08x";
632 const static char *roles[4] = {
633 "No", "Target", "Initiator", "Target/Initiator"
634 };
635 fcparam *fcp = isp->isp_param;
636 int tgt = *((int *) arg);
637 struct lportdb *lp = &fcp->portdb[tgt];
638
639 isp_prt(isp, ISP_LOGINFO, fmt, tgt, lp->loopid, lp->portid,
640 roles[lp->roles & 0x3],
641 (lp->valid)? "Arrived" : "Departed",
642 (u_int32_t) (lp->port_wwn >> 32),
643 (u_int32_t) (lp->port_wwn & 0xffffffffLL),
644 (u_int32_t) (lp->node_wwn >> 32),
645 (u_int32_t) (lp->node_wwn & 0xffffffffLL));
646 break;
647 }
648 case ISPASYNC_CHANGE_NOTIFY:
649 if (arg == (void *) 1) {
650 isp_prt(isp, ISP_LOGINFO,
651 "Name Server Database Changed");
652 } else {
653 isp_prt(isp, ISP_LOGINFO,
654 "Name Server Database Changed");
655 }
656 break;
657 case ISPASYNC_FABRIC_DEV:
658 {
659 int target, lrange;
660 struct lportdb *lp = NULL;
661 char *pt;
662 sns_ganrsp_t *resp = (sns_ganrsp_t *) arg;
663 u_int32_t portid;
664 u_int64_t wwpn, wwnn;
665 fcparam *fcp = isp->isp_param;
666
667 portid =
668 (((u_int32_t) resp->snscb_port_id[0]) << 16) |
669 (((u_int32_t) resp->snscb_port_id[1]) << 8) |
670 (((u_int32_t) resp->snscb_port_id[2]));
671
672 wwpn =
673 (((u_int64_t)resp->snscb_portname[0]) << 56) |
674 (((u_int64_t)resp->snscb_portname[1]) << 48) |
675 (((u_int64_t)resp->snscb_portname[2]) << 40) |
676 (((u_int64_t)resp->snscb_portname[3]) << 32) |
677 (((u_int64_t)resp->snscb_portname[4]) << 24) |
678 (((u_int64_t)resp->snscb_portname[5]) << 16) |
679 (((u_int64_t)resp->snscb_portname[6]) << 8) |
680 (((u_int64_t)resp->snscb_portname[7]));
681
682 wwnn =
683 (((u_int64_t)resp->snscb_nodename[0]) << 56) |
684 (((u_int64_t)resp->snscb_nodename[1]) << 48) |
685 (((u_int64_t)resp->snscb_nodename[2]) << 40) |
686 (((u_int64_t)resp->snscb_nodename[3]) << 32) |
687 (((u_int64_t)resp->snscb_nodename[4]) << 24) |
688 (((u_int64_t)resp->snscb_nodename[5]) << 16) |
689 (((u_int64_t)resp->snscb_nodename[6]) << 8) |
690 (((u_int64_t)resp->snscb_nodename[7]));
691 if (portid == 0 || wwpn == 0) {
692 break;
693 }
694
695 switch (resp->snscb_port_type) {
696 case 1:
697 pt = " N_Port";
698 break;
699 case 2:
700 pt = " NL_Port";
701 break;
702 case 3:
703 pt = "F/NL_Port";
704 break;
705 case 0x7f:
706 pt = " Nx_Port";
707 break;
708 case 0x81:
709 pt = " F_port";
710 break;
711 case 0x82:
712 pt = " FL_Port";
713 break;
714 case 0x84:
715 pt = " E_port";
716 break;
717 default:
718 pt = "?";
719 break;
720 }
721 isp_prt(isp, ISP_LOGINFO,
722 "%s @ 0x%x, Node 0x%08x%08x Port %08x%08x",
723 pt, portid, ((u_int32_t) (wwnn >> 32)), ((u_int32_t) wwnn),
724 ((u_int32_t) (wwpn >> 32)), ((u_int32_t) wwpn));
725 /*
726 * We're only interested in SCSI_FCP types (for now)
727 */
728 if ((resp->snscb_fc4_types[2] & 1) == 0) {
729 break;
730 }
731 if (fcp->isp_topo != TOPO_F_PORT)
732 lrange = FC_SNS_ID+1;
733 else
734 lrange = 0;
735 /*
736 * Is it already in our list?
737 */
738 for (target = lrange; target < MAX_FC_TARG; target++) {
739 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
740 continue;
741 }
742 lp = &fcp->portdb[target];
743 if (lp->port_wwn == wwpn && lp->node_wwn == wwnn) {
744 lp->fabric_dev = 1;
745 break;
746 }
747 }
748 if (target < MAX_FC_TARG) {
749 break;
750 }
751 for (target = lrange; target < MAX_FC_TARG; target++) {
752 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
753 continue;
754 }
755 lp = &fcp->portdb[target];
756 if (lp->port_wwn == 0) {
757 break;
758 }
759 }
760 if (target == MAX_FC_TARG) {
761 isp_prt(isp, ISP_LOGWARN,
762 "no more space for fabric devices");
763 break;
764 }
765 lp->node_wwn = wwnn;
766 lp->port_wwn = wwpn;
767 lp->portid = portid;
768 lp->fabric_dev = 1;
769 break;
770 }
771 default:
772 break;
773 }
774 (void) splx(s);
775 return (0);
776 }
777
778 #include <machine/stdarg.h>
779 void
780 isp_prt(struct ispsoftc *isp, int level, const char *fmt, ...)
781 {
782 va_list ap;
783 if (level != ISP_LOGALL && (level & isp->isp_dblev) == 0) {
784 return;
785 }
786 printf("%s: ", isp->isp_name);
787 va_start(ap, fmt);
788 vprintf(fmt, ap);
789 va_end(ap);
790 printf("\n");
791 }
792