isp_netbsd.c revision 1.19 1 /* $NetBSD: isp_netbsd.c,v 1.19 1999/12/04 03:04:59 mjacob Exp $ */
2 /*
3 * Platform (NetBSD) dependent common attachment code for Qlogic adapters.
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
33 #include <dev/ic/isp_netbsd.h>
34 #include <sys/scsiio.h>
35
36 static void ispminphys __P((struct buf *));
37 static int32_t ispcmd_slow __P((ISP_SCSI_XFER_T *));
38 static int32_t ispcmd __P((ISP_SCSI_XFER_T *));
39 static int
40 ispioctl __P((struct scsipi_link *, u_long, caddr_t, int, struct proc *));
41
42 static struct scsipi_device isp_dev = { NULL, NULL, NULL, NULL };
43 static int isp_poll __P((struct ispsoftc *, ISP_SCSI_XFER_T *, int));
44 static void isp_watch __P((void *));
45 static void isp_command_requeue __P((void *));
46 static void isp_internal_restart __P((void *));
47
48 /*
49 * Complete attachment of hardware, include subdevices.
50 */
51 void
52 isp_attach(isp)
53 struct ispsoftc *isp;
54 {
55
56 isp->isp_osinfo._adapter.scsipi_minphys = ispminphys;
57 isp->isp_osinfo._adapter.scsipi_ioctl = ispioctl;
58
59 isp->isp_state = ISP_RUNSTATE;
60 isp->isp_osinfo._link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
61 isp->isp_osinfo._link.adapter_softc = isp;
62 isp->isp_osinfo._link.device = &isp_dev;
63 isp->isp_osinfo._link.adapter = &isp->isp_osinfo._adapter;
64 isp->isp_osinfo._link.openings = isp->isp_maxcmds;
65 TAILQ_INIT(&isp->isp_osinfo.waitq); /* XXX 2nd Bus? */
66
67 if (IS_FC(isp)) {
68 /*
69 * Give it another chance here to come alive...
70 */
71 isp->isp_osinfo._adapter.scsipi_cmd = ispcmd;
72 isp->isp_osinfo._link.scsipi_scsi.max_target = MAX_FC_TARG-1;
73 #ifdef ISP2100_SCCLUN
74 /*
75 * 16 bits worth, but let's be reasonable..
76 */
77 isp->isp_osinfo._link.scsipi_scsi.max_lun = 255;
78 #else
79 isp->isp_osinfo._link.scsipi_scsi.max_lun = 15;
80 #endif
81 /* set below */
82 } else {
83 sdparam *sdp = isp->isp_param;
84 isp->isp_osinfo._adapter.scsipi_cmd = ispcmd_slow;
85 isp->isp_osinfo._link.scsipi_scsi.max_target = MAX_TARGETS-1;
86 if (isp->isp_bustype == ISP_BT_SBUS) {
87 isp->isp_osinfo._link.scsipi_scsi.max_lun = 7;
88 } else {
89 /*
90 * Too much target breakage at present.
91 */
92 #if 0
93 if (isp->isp_fwrev >= ISP_FW_REV(7,55,0))
94 isp->isp_osinfo._link.scsipi_scsi.max_lun = 31;
95 else
96 #endif
97 isp->isp_osinfo._link.scsipi_scsi.max_lun = 7;
98 }
99 isp->isp_osinfo._link.scsipi_scsi.adapter_target =
100 sdp->isp_initiator_id;
101 isp->isp_osinfo.discovered[0] = 1 << sdp->isp_initiator_id;
102 if (IS_12X0(isp)) {
103 isp->isp_osinfo._link_b = isp->isp_osinfo._link;
104 sdp++;
105 isp->isp_osinfo.discovered[1] =
106 1 << sdp->isp_initiator_id;
107 isp->isp_osinfo._link_b.scsipi_scsi.adapter_target =
108 sdp->isp_initiator_id;
109 isp->isp_osinfo._link_b.scsipi_scsi.channel = 1;
110 }
111 }
112 isp->isp_osinfo._link.type = BUS_SCSI;
113
114 /*
115 * Send a SCSI Bus Reset (used to be done as part of attach,
116 * but now left to the OS outer layers).
117 */
118 if (IS_SCSI(isp)) {
119 int bus = 0;
120 (void) isp_control(isp, ISPCTL_RESET_BUS, &bus);
121 if (IS_12X0(isp)) {
122 bus++;
123 (void) isp_control(isp, ISPCTL_RESET_BUS, &bus);
124 }
125 SYS_DELAY(2*1000000);
126 } else {
127 int i, j;
128 fcparam *fcp = isp->isp_param;
129 delay(2 * 1000000);
130 for (j = 0; j < 5; j++) {
131 for (i = 0; i < 5; i++) {
132 if (isp_control(isp, ISPCTL_FCLINK_TEST, NULL))
133 continue;
134 #ifdef ISP2100_FABRIC
135 /*
136 * Wait extra time to see if the f/w
137 * eventually completed an FLOGI that
138 * will allow us to know we're on a
139 * fabric.
140 */
141 if (fcp->isp_onfabric == 0) {
142 delay(1 * 1000000);
143 continue;
144 }
145 #endif
146 break;
147 }
148 if (fcp->isp_fwstate == FW_READY &&
149 fcp->isp_loopstate >= LOOP_PDB_RCVD) {
150 break;
151 }
152 }
153 isp->isp_osinfo._link.scsipi_scsi.adapter_target =
154 fcp->isp_loopid;
155 }
156
157 /*
158 * Start the watchdog.
159 */
160 isp->isp_dogactive = 1;
161 timeout(isp_watch, isp, WATCH_INTERVAL * hz);
162
163 /*
164 * And attach children (if any).
165 */
166 config_found((void *)isp, &isp->isp_osinfo._link, scsiprint);
167 if (IS_12X0(isp)) {
168 config_found((void *)isp, &isp->isp_osinfo._link_b, scsiprint);
169 }
170 }
171
172 /*
173 * minphys our xfers
174 *
175 * Unfortunately, the buffer pointer describes the target device- not the
176 * adapter device, so we can't use the pointer to find out what kind of
177 * adapter we are and adjust accordingly.
178 */
179
180 static void
181 ispminphys(bp)
182 struct buf *bp;
183 {
184 /*
185 * XX: Only the 1020 has a 24 bit limit.
186 */
187 if (bp->b_bcount >= (1 << 24)) {
188 bp->b_bcount = (1 << 24);
189 }
190 minphys(bp);
191 }
192
193 static int32_t
194 ispcmd_slow(xs)
195 ISP_SCSI_XFER_T *xs;
196 {
197 sdparam *sdp;
198 int tgt, chan;
199 u_int16_t f;
200 struct ispsoftc *isp = XS_ISP(xs);
201
202 /*
203 * Have we completed discovery for this target on this adapter?
204 */
205 sdp = isp->isp_param;
206 sdp += chan;
207 tgt = XS_TGT(xs);
208 chan = XS_CHANNEL(xs);
209 if ((xs->xs_control & XS_CTL_DISCOVERY) != 0 ||
210 (isp->isp_osinfo.discovered[chan] & (1 << tgt)) != 0) {
211 return (ispcmd(xs));
212 }
213
214 f = DPARM_DEFAULT;
215 if (xs->sc_link->quirks & SDEV_NOSYNC) {
216 f ^= DPARM_SYNC;
217 #ifdef DEBUG
218 } else {
219 printf("%s: channel %d target %d can do SYNC xfers\n",
220 isp->isp_name, chan, tgt);
221 #endif
222 }
223 if (xs->sc_link->quirks & SDEV_NOWIDE) {
224 f ^= DPARM_WIDE;
225 #ifdef DEBUG
226 } else {
227 printf("%s: channel %d target %d can do WIDE xfers\n",
228 isp->isp_name, chan, tgt);
229 #endif
230 }
231 if (xs->sc_link->quirks & SDEV_NOTAG) {
232 f ^= DPARM_TQING;
233 #ifdef DEBUG
234 } else {
235 printf("%s: channel %d target %d can do TAGGED xfers\n",
236 isp->isp_name, chan, tgt);
237 #endif
238 }
239 /*
240 * Okay, we know about this device now,
241 * so mark parameters to be updated for it.
242 */
243 sdp->isp_devparam[tgt].dev_flags = f;
244 sdp->isp_devparam[tgt].dev_update = 1;
245 isp->isp_update |= (1 << chan);
246
247 /*
248 * Now check to see whether we can get out of this checking mode now.
249 * XXX: WE CANNOT AS YET BECAUSE THERE IS NO MECHANISM TO TELL US
250 * XXX: WHEN WE'RE DONE DISCOVERY BECAUSE WE NEED ONE COMMAND AFTER
251 * XXX: DISCOVERY IS DONE FOR EACH TARGET TO TELL US THAT WE'RE DONE
252 * XXX: AND THAT DOESN'T HAPPEN HERE. AT BEST WE CAN MARK OURSELVES
253 * XXX: DONE WITH DISCOVERY FOR THIS TARGET AND SO SAVE MAYBE 20
254 * XXX: LINES OF C CODE.
255 */
256 isp->isp_osinfo.discovered[chan] |= (1 << tgt);
257 /* do not bother with these lines- they'll never execute correctly */
258 #if 0
259 sdp = isp->isp_param;
260 for (chan = 0; chan < (IS_12X0(isp)? 2 : 1); chan++, sdp++) {
261 f = 0xffff & ~(1 << sdp->isp_initiator_id);
262 if (isp->isp_osinfo.discovered[chan] != f) {
263 break;
264 }
265 }
266 if (chan == (IS_12X0(isp)? 2 : 1)) {
267 CFGPRINTF("%s: allowing sync/wide negotiation and "
268 "tag usage\n", isp->isp_name);
269 isp->isp_osinfo._adapter.scsipi_cmd = ispcmd;
270 if (IS_12X0(isp))
271 isp->isp_update |= 2;
272 }
273 #endif
274 return (ispcmd(xs));
275 }
276
277 static int
278 ispioctl(sc_link, cmd, addr, flag, p)
279 struct scsipi_link *sc_link;
280 u_long cmd;
281 caddr_t addr;
282 int flag;
283 struct proc *p;
284 {
285 struct ispsoftc *isp = sc_link->adapter_softc;
286 int s, chan, retval = ENOTTY;
287
288 switch (cmd) {
289 case SCBUSIORESET:
290 chan = sc_link->scsipi_scsi.channel;
291 s = splbio();
292 if (isp_control(isp, ISPCTL_RESET_BUS, &chan))
293 retval = EIO;
294 else
295 retval = 0;
296 (void) splx(s);
297 break;
298 default:
299 break;
300 }
301 return (retval);
302 }
303
304
305 static int32_t
306 ispcmd(xs)
307 ISP_SCSI_XFER_T *xs;
308 {
309 struct ispsoftc *isp;
310 int result, s;
311
312 isp = XS_ISP(xs);
313 s = splbio();
314 if (isp->isp_state < ISP_RUNSTATE) {
315 DISABLE_INTS(isp);
316 isp_init(isp);
317 if (isp->isp_state != ISP_INITSTATE) {
318 ENABLE_INTS(isp);
319 (void) splx(s);
320 XS_SETERR(xs, HBA_BOTCH);
321 return (COMPLETE);
322 }
323 isp->isp_state = ISP_RUNSTATE;
324 ENABLE_INTS(isp);
325 }
326
327 /*
328 * Check for queue blockage...
329 */
330 if (isp->isp_osinfo.blocked) {
331 if (xs->xs_control & XS_CTL_POLL) {
332 xs->error = XS_DRIVER_STUFFUP;
333 splx(s);
334 return (TRY_AGAIN_LATER);
335 }
336 TAILQ_INSERT_TAIL(&isp->isp_osinfo.waitq, xs, adapter_q);
337 splx(s);
338 return (SUCCESSFULLY_QUEUED);
339 }
340 DISABLE_INTS(isp);
341 result = ispscsicmd(xs);
342 ENABLE_INTS(isp);
343
344 if ((xs->xs_control & XS_CTL_POLL) == 0) {
345 switch (result) {
346 case CMD_QUEUED:
347 result = SUCCESSFULLY_QUEUED;
348 break;
349 case CMD_EAGAIN:
350 result = TRY_AGAIN_LATER;
351 break;
352 case CMD_RQLATER:
353 result = SUCCESSFULLY_QUEUED;
354 timeout(isp_command_requeue, xs, hz);
355 break;
356 case CMD_COMPLETE:
357 result = COMPLETE;
358 break;
359 }
360 (void) splx(s);
361 return (result);
362 }
363
364 switch (result) {
365 case CMD_QUEUED:
366 result = SUCCESSFULLY_QUEUED;
367 break;
368 case CMD_RQLATER:
369 case CMD_EAGAIN:
370 if (XS_NOERR(xs)) {
371 xs->error = XS_DRIVER_STUFFUP;
372 }
373 result = TRY_AGAIN_LATER;
374 break;
375 case CMD_COMPLETE:
376 result = COMPLETE;
377 break;
378
379 }
380 /*
381 * If we can't use interrupts, poll on completion.
382 */
383 if (result == SUCCESSFULLY_QUEUED) {
384 if (isp_poll(isp, xs, XS_TIME(xs))) {
385 /*
386 * If no other error occurred but we didn't finish,
387 * something bad happened.
388 */
389 if (XS_IS_CMD_DONE(xs) == 0) {
390 if (isp_control(isp, ISPCTL_ABORT_CMD, xs)) {
391 isp_restart(isp);
392 }
393 if (XS_NOERR(xs)) {
394 XS_SETERR(xs, HBA_BOTCH);
395 }
396 }
397 }
398 result = COMPLETE;
399 }
400 (void) splx(s);
401 return (result);
402 }
403
404 static int
405 isp_poll(isp, xs, mswait)
406 struct ispsoftc *isp;
407 ISP_SCSI_XFER_T *xs;
408 int mswait;
409 {
410
411 while (mswait) {
412 /* Try the interrupt handling routine */
413 (void)isp_intr((void *)isp);
414
415 /* See if the xs is now done */
416 if (XS_IS_CMD_DONE(xs)) {
417 return (0);
418 }
419 SYS_DELAY(1000); /* wait one millisecond */
420 mswait--;
421 }
422 return (1);
423 }
424
425 static void
426 isp_watch(arg)
427 void *arg;
428 {
429 int i;
430 struct ispsoftc *isp = arg;
431 struct scsipi_xfer *xs;
432 int s;
433
434 /*
435 * Look for completely dead commands (but not polled ones).
436 */
437 s = splbio();
438 for (i = 0; i < isp->isp_maxcmds; i++) {
439 xs = isp->isp_xflist[i];
440 if (xs == NULL) {
441 continue;
442 }
443 if (xs->timeout == 0 || (xs->xs_control & XS_CTL_POLL)) {
444 continue;
445 }
446 xs->timeout -= (WATCH_INTERVAL * 1000);
447 /*
448 * Avoid later thinking that this
449 * transaction is not being timed.
450 * Then give ourselves to watchdog
451 * periods of grace.
452 */
453 if (xs->timeout == 0) {
454 xs->timeout = 1;
455 } else if (xs->timeout > -(2 * WATCH_INTERVAL * 1000)) {
456 continue;
457 }
458 if (isp_control(isp, ISPCTL_ABORT_CMD, xs)) {
459 printf("%s: isp_watch failed to abort command\n",
460 isp->isp_name);
461 isp_restart(isp);
462 break;
463 }
464 }
465 timeout(isp_watch, isp, WATCH_INTERVAL * hz);
466 isp->isp_dogactive = 1;
467 (void) splx(s);
468 }
469
470 /*
471 * Free any associated resources prior to decommissioning and
472 * set the card to a known state (so it doesn't wake up and kick
473 * us when we aren't expecting it to).
474 *
475 * Locks are held before coming here.
476 */
477 void
478 isp_uninit(isp)
479 struct ispsoftc *isp;
480 {
481 ISP_ILOCKVAL_DECL;
482 ISP_ILOCK(isp);
483 /*
484 * Leave with interrupts disabled.
485 */
486 DISABLE_INTS(isp);
487
488 /*
489 * Turn off the watchdog (if active).
490 */
491 if (isp->isp_dogactive) {
492 untimeout(isp_watch, isp);
493 isp->isp_dogactive = 0;
494 }
495
496 ISP_IUNLOCK(isp);
497 }
498
499 /*
500 * Restart function for a command to be requeued later.
501 */
502 static void
503 isp_command_requeue(arg)
504 void *arg;
505 {
506 struct scsipi_xfer *xs = arg;
507 struct ispsoftc *isp = XS_ISP(xs);
508 int s = splbio();
509 switch (ispcmd_slow(xs)) {
510 case SUCCESSFULLY_QUEUED:
511 printf("%s: isp_command_requeue: requeued for %d.%d\n",
512 isp->isp_name, XS_TGT(xs), XS_LUN(xs));
513 break;
514 case TRY_AGAIN_LATER:
515 printf("%s: EAGAIN for %d.%d\n",
516 isp->isp_name, XS_TGT(xs), XS_LUN(xs));
517 /* FALLTHROUGH */
518 case COMPLETE:
519 /* can only be an error */
520 xs->xs_status |= XS_STS_DONE;
521 if (XS_NOERR(xs)) {
522 XS_SETERR(xs, HBA_BOTCH);
523 }
524 scsipi_done(xs);
525 break;
526 }
527 (void) splx(s);
528 }
529
530 /*
531 * Restart function after a LOOP UP event (e.g.),
532 * done as a timeout for some hysteresis.
533 */
534 static void
535 isp_internal_restart(arg)
536 void *arg;
537 {
538 struct ispsoftc *isp = arg;
539 int result, nrestarted = 0, s;
540
541 s = splbio();
542 if (isp->isp_osinfo.blocked == 0) {
543 struct scsipi_xfer *xs;
544 while ((xs = TAILQ_FIRST(&isp->isp_osinfo.waitq)) != NULL) {
545 TAILQ_REMOVE(&isp->isp_osinfo.waitq, xs, adapter_q);
546 DISABLE_INTS(isp);
547 result = ispscsicmd(xs);
548 ENABLE_INTS(isp);
549 if (result != CMD_QUEUED) {
550 printf("%s: botched command restart (0x%x)\n",
551 isp->isp_name, result);
552 xs->xs_status |= XS_STS_DONE;
553 if (xs->error == XS_NOERROR)
554 xs->error = XS_DRIVER_STUFFUP;
555 scsipi_done(xs);
556 }
557 nrestarted++;
558 }
559 printf("%s: requeued %d commands\n", isp->isp_name, nrestarted);
560 }
561 (void) splx(s);
562 }
563
564 int
565 isp_async(isp, cmd, arg)
566 struct ispsoftc *isp;
567 ispasync_t cmd;
568 void *arg;
569 {
570 int bus, tgt;
571 int s = splbio();
572 switch (cmd) {
573 case ISPASYNC_NEW_TGT_PARAMS:
574 if (IS_SCSI(isp) && isp->isp_dblev) {
575 sdparam *sdp = isp->isp_param;
576 char *wt;
577 int mhz, flags, period;
578
579 tgt = *((int *) arg);
580 bus = (tgt >> 16) & 0xffff;
581 tgt &= 0xffff;
582
583 flags = sdp->isp_devparam[tgt].cur_dflags;
584 period = sdp->isp_devparam[tgt].cur_period;
585 if ((flags & DPARM_SYNC) && period &&
586 (sdp->isp_devparam[tgt].cur_offset) != 0) {
587 if (sdp->isp_lvdmode) {
588 switch (period) {
589 case 0xa:
590 mhz = 40;
591 break;
592 case 0xb:
593 mhz = 33;
594 break;
595 case 0xc:
596 mhz = 25;
597 break;
598 default:
599 mhz = 1000 / (period * 4);
600 break;
601 }
602 } else {
603 mhz = 1000 / (period * 4);
604 }
605 } else {
606 mhz = 0;
607 }
608 switch (flags & (DPARM_WIDE|DPARM_TQING)) {
609 case DPARM_WIDE:
610 wt = ", 16 bit wide\n";
611 break;
612 case DPARM_TQING:
613 wt = ", Tagged Queueing Enabled\n";
614 break;
615 case DPARM_WIDE|DPARM_TQING:
616 wt = ", 16 bit wide, Tagged Queueing Enabled\n";
617 break;
618 default:
619 wt = "\n";
620 break;
621 }
622 if (mhz) {
623 CFGPRINTF("%s: Bus %d Target %d at %dMHz Max "
624 "Offset %d%s", isp->isp_name, bus, tgt, mhz,
625 sdp->isp_devparam[tgt].cur_offset, wt);
626 } else {
627 CFGPRINTF("%s: Bus %d Target %d Async Mode%s",
628 isp->isp_name, bus, tgt, wt);
629 }
630 break;
631 }
632 case ISPASYNC_BUS_RESET:
633 if (arg)
634 bus = *((int *) arg);
635 else
636 bus = 0;
637 printf("%s: SCSI bus %d reset detected\n", isp->isp_name, bus);
638 break;
639 case ISPASYNC_LOOP_DOWN:
640 /*
641 * Hopefully we get here in time to minimize the number
642 * of commands we are firing off that are sure to die.
643 */
644 isp->isp_osinfo.blocked = 1;
645 printf("%s: Loop DOWN\n", isp->isp_name);
646 break;
647 case ISPASYNC_LOOP_UP:
648 isp->isp_osinfo.blocked = 0;
649 timeout(isp_internal_restart, isp, 1);
650 printf("%s: Loop UP\n", isp->isp_name);
651 break;
652 case ISPASYNC_PDB_CHANGED:
653 if (IS_FC(isp) && isp->isp_dblev) {
654 const char *fmt = "%s: Target %d (Loop 0x%x) Port ID 0x%x "
655 "role %s %s\n Port WWN 0x%08x%08x\n Node WWN 0x%08x%08x\n";
656 const static char *roles[4] = {
657 "No", "Target", "Initiator", "Target/Initiator"
658 };
659 char *ptr;
660 fcparam *fcp = isp->isp_param;
661 int tgt = *((int *) arg);
662 struct lportdb *lp = &fcp->portdb[tgt];
663
664 if (lp->valid) {
665 ptr = "arrived";
666 } else {
667 ptr = "disappeared";
668 }
669 printf(fmt, isp->isp_name, tgt, lp->loopid, lp->portid,
670 roles[lp->roles & 0x3], ptr,
671 (u_int32_t) (lp->port_wwn >> 32),
672 (u_int32_t) (lp->port_wwn & 0xffffffffLL),
673 (u_int32_t) (lp->node_wwn >> 32),
674 (u_int32_t) (lp->node_wwn & 0xffffffffLL));
675 break;
676 }
677 #ifdef ISP2100_FABRIC
678 case ISPASYNC_CHANGE_NOTIFY:
679 printf("%s: Name Server Database Changed\n", isp->isp_name);
680 break;
681 case ISPASYNC_FABRIC_DEV:
682 {
683 int target;
684 struct lportdb *lp;
685 sns_scrsp_t *resp = (sns_scrsp_t *) arg;
686 u_int32_t portid;
687 u_int64_t wwn;
688 fcparam *fcp = isp->isp_param;
689
690 portid =
691 (((u_int32_t) resp->snscb_port_id[0]) << 16) |
692 (((u_int32_t) resp->snscb_port_id[1]) << 8) |
693 (((u_int32_t) resp->snscb_port_id[2]));
694 wwn =
695 (((u_int64_t)resp->snscb_portname[0]) << 56) |
696 (((u_int64_t)resp->snscb_portname[1]) << 48) |
697 (((u_int64_t)resp->snscb_portname[2]) << 40) |
698 (((u_int64_t)resp->snscb_portname[3]) << 32) |
699 (((u_int64_t)resp->snscb_portname[4]) << 24) |
700 (((u_int64_t)resp->snscb_portname[5]) << 16) |
701 (((u_int64_t)resp->snscb_portname[6]) << 8) |
702 (((u_int64_t)resp->snscb_portname[7]));
703 printf("%s: Fabric Device (Type 0x%x)@PortID 0x%x WWN "
704 "0x%08x%08x\n", isp->isp_name, resp->snscb_port_type,
705 portid, ((u_int32_t)(wwn >> 32)),
706 ((u_int32_t)(wwn & 0xffffffff)));
707 if (resp->snscb_port_type != 2)
708 break;
709 for (target = FC_SNS_ID+1; target < MAX_FC_TARG; target++) {
710 lp = &fcp->portdb[target];
711 if (lp->port_wwn == wwn)
712 break;
713 }
714 if (target < MAX_FC_TARG) {
715 break;
716 }
717 for (target = FC_SNS_ID+1; target < MAX_FC_TARG; target++) {
718 lp = &fcp->portdb[target];
719 if (lp->port_wwn == 0)
720 break;
721 }
722 if (target == MAX_FC_TARG) {
723 printf("%s: no more space for fabric devices\n",
724 isp->isp_name);
725 return (-1);
726 }
727 lp->port_wwn = lp->node_wwn = wwn;
728 lp->portid = portid;
729 break;
730 }
731 #endif
732 default:
733 break;
734 }
735 (void) splx(s);
736 return (0);
737 }
738