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