Home | History | Annotate | Line # | Download | only in ic
isp_netbsd.c revision 1.20
      1 /* $NetBSD: isp_netbsd.c,v 1.20 1999/12/05 18:20:53 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, s;
    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 	tgt = XS_TGT(xs);
    206 	chan = XS_CHANNEL(xs);
    207 	sdp = isp->isp_param;
    208 	sdp += chan;
    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 	s = splbio();
    244 	sdp->isp_devparam[tgt].dev_flags = f;
    245 	sdp->isp_devparam[tgt].dev_update = 1;
    246 	isp->isp_update |= (1 << chan);
    247 
    248 	/*
    249 	 * Now check to see whether we can get out of this checking mode now.
    250 	 * XXX: WE CANNOT AS YET BECAUSE THERE IS NO MECHANISM TO TELL US
    251 	 * XXX: WHEN WE'RE DONE DISCOVERY BECAUSE WE NEED ONE COMMAND AFTER
    252 	 * XXX: DISCOVERY IS DONE FOR EACH TARGET TO TELL US THAT WE'RE DONE
    253 	 * XXX: AND THAT DOESN'T HAPPEN HERE. AT BEST WE CAN MARK OURSELVES
    254 	 * XXX: DONE WITH DISCOVERY FOR THIS TARGET AND SO SAVE MAYBE 20
    255 	 * XXX: LINES OF C CODE.
    256 	 */
    257 	isp->isp_osinfo.discovered[chan] |= (1 << tgt);
    258 	/* do not bother with these lines- they'll never execute correctly */
    259 #if	0
    260 	sdp = isp->isp_param;
    261 	for (chan = 0; chan < (IS_12X0(isp)? 2 : 1); chan++, sdp++) {
    262 		f = 0xffff & ~(1 << sdp->isp_initiator_id);
    263 		if (isp->isp_osinfo.discovered[chan] != f) {
    264 			break;
    265 		}
    266 	}
    267 	if (chan == (IS_12X0(isp)? 2 : 1)) {
    268 		CFGPRINTF("%s: allowing sync/wide negotiation and "
    269 		    "tag usage\n", isp->isp_name);
    270 		isp->isp_osinfo._adapter.scsipi_cmd = ispcmd;
    271 		if (IS_12X0(isp))
    272 			isp->isp_update |= 2;
    273 	}
    274 #endif
    275 	splx(s);
    276 	return (ispcmd(xs));
    277 }
    278 
    279 static int
    280 ispioctl(sc_link, cmd, addr, flag, p)
    281 	struct scsipi_link *sc_link;
    282 	u_long cmd;
    283 	caddr_t addr;
    284 	int flag;
    285 	struct proc *p;
    286 {
    287 	struct ispsoftc *isp = sc_link->adapter_softc;
    288 	int s, chan, retval = ENOTTY;
    289 
    290 	switch (cmd) {
    291 	case SCBUSIORESET:
    292 		chan = sc_link->scsipi_scsi.channel;
    293 		s = splbio();
    294 		if (isp_control(isp, ISPCTL_RESET_BUS, &chan))
    295 			retval = EIO;
    296 		else
    297 			retval = 0;
    298 		(void) splx(s);
    299 		break;
    300 	default:
    301 		break;
    302 	}
    303 	return (retval);
    304 }
    305 
    306 
    307 static int32_t
    308 ispcmd(xs)
    309 	ISP_SCSI_XFER_T *xs;
    310 {
    311 	struct ispsoftc *isp;
    312 	int result, s;
    313 
    314 	isp = XS_ISP(xs);
    315 	s = splbio();
    316 	if (isp->isp_state < ISP_RUNSTATE) {
    317 		DISABLE_INTS(isp);
    318 		isp_init(isp);
    319                 if (isp->isp_state != ISP_INITSTATE) {
    320 			ENABLE_INTS(isp);
    321                         (void) splx(s);
    322                         XS_SETERR(xs, HBA_BOTCH);
    323                         return (COMPLETE);
    324                 }
    325                 isp->isp_state = ISP_RUNSTATE;
    326 		ENABLE_INTS(isp);
    327         }
    328 
    329 	/*
    330 	 * Check for queue blockage...
    331 	 */
    332 	if (isp->isp_osinfo.blocked) {
    333 		if (xs->xs_control & XS_CTL_POLL) {
    334 			xs->error = XS_DRIVER_STUFFUP;
    335 			splx(s);
    336 			return (TRY_AGAIN_LATER);
    337 		}
    338 		TAILQ_INSERT_TAIL(&isp->isp_osinfo.waitq, xs, adapter_q);
    339 		splx(s);
    340 		return (SUCCESSFULLY_QUEUED);
    341 	}
    342 	DISABLE_INTS(isp);
    343 	result = ispscsicmd(xs);
    344 	ENABLE_INTS(isp);
    345 
    346 	if ((xs->xs_control & XS_CTL_POLL) == 0) {
    347 		switch (result) {
    348 		case CMD_QUEUED:
    349 			result = SUCCESSFULLY_QUEUED;
    350 			break;
    351 		case CMD_EAGAIN:
    352 			result = TRY_AGAIN_LATER;
    353 			break;
    354 		case CMD_RQLATER:
    355 			result = SUCCESSFULLY_QUEUED;
    356 			timeout(isp_command_requeue, xs, hz);
    357 			break;
    358 		case CMD_COMPLETE:
    359 			result = COMPLETE;
    360 			break;
    361 		}
    362 		(void) splx(s);
    363 		return (result);
    364 	}
    365 
    366 	switch (result) {
    367 	case CMD_QUEUED:
    368 		result = SUCCESSFULLY_QUEUED;
    369 		break;
    370 	case CMD_RQLATER:
    371 	case CMD_EAGAIN:
    372 		if (XS_NOERR(xs)) {
    373 			xs->error = XS_DRIVER_STUFFUP;
    374 		}
    375 		result = TRY_AGAIN_LATER;
    376 		break;
    377 	case CMD_COMPLETE:
    378 		result = COMPLETE;
    379 		break;
    380 
    381 	}
    382 	/*
    383 	 * If we can't use interrupts, poll on completion.
    384 	 */
    385 	if (result == SUCCESSFULLY_QUEUED) {
    386 		if (isp_poll(isp, xs, XS_TIME(xs))) {
    387 			/*
    388 			 * If no other error occurred but we didn't finish,
    389 			 * something bad happened.
    390 			 */
    391 			if (XS_IS_CMD_DONE(xs) == 0) {
    392 				if (isp_control(isp, ISPCTL_ABORT_CMD, xs)) {
    393 					isp_restart(isp);
    394 				}
    395 				if (XS_NOERR(xs)) {
    396 					XS_SETERR(xs, HBA_BOTCH);
    397 				}
    398 			}
    399 		}
    400 		result = COMPLETE;
    401 	}
    402 	(void) splx(s);
    403 	return (result);
    404 }
    405 
    406 static int
    407 isp_poll(isp, xs, mswait)
    408 	struct ispsoftc *isp;
    409 	ISP_SCSI_XFER_T *xs;
    410 	int mswait;
    411 {
    412 
    413 	while (mswait) {
    414 		/* Try the interrupt handling routine */
    415 		(void)isp_intr((void *)isp);
    416 
    417 		/* See if the xs is now done */
    418 		if (XS_IS_CMD_DONE(xs)) {
    419 			return (0);
    420 		}
    421 		SYS_DELAY(1000);	/* wait one millisecond */
    422 		mswait--;
    423 	}
    424 	return (1);
    425 }
    426 
    427 static void
    428 isp_watch(arg)
    429 	void *arg;
    430 {
    431 	int i;
    432 	struct ispsoftc *isp = arg;
    433 	struct scsipi_xfer *xs;
    434 	int s;
    435 
    436 	/*
    437 	 * Look for completely dead commands (but not polled ones).
    438 	 */
    439 	s = splbio();
    440 	for (i = 0; i < isp->isp_maxcmds; i++) {
    441 		xs = isp->isp_xflist[i];
    442 		if (xs == NULL) {
    443 			continue;
    444 		}
    445 		if (xs->timeout == 0 || (xs->xs_control & XS_CTL_POLL)) {
    446 			continue;
    447 		}
    448 		xs->timeout -= (WATCH_INTERVAL * 1000);
    449 		/*
    450 		 * Avoid later thinking that this
    451 		 * transaction is not being timed.
    452 		 * Then give ourselves to watchdog
    453 		 * periods of grace.
    454 		 */
    455 		if (xs->timeout == 0) {
    456 			xs->timeout = 1;
    457 		} else if (xs->timeout > -(2 * WATCH_INTERVAL * 1000)) {
    458 			continue;
    459 		}
    460 		if (isp_control(isp, ISPCTL_ABORT_CMD, xs)) {
    461 			printf("%s: isp_watch failed to abort command\n",
    462 			    isp->isp_name);
    463 			isp_restart(isp);
    464 			break;
    465 		}
    466 	}
    467 	timeout(isp_watch, isp, WATCH_INTERVAL * hz);
    468 	isp->isp_dogactive = 1;
    469 	(void) splx(s);
    470 }
    471 
    472 /*
    473  * Free any associated resources prior to decommissioning and
    474  * set the card to a known state (so it doesn't wake up and kick
    475  * us when we aren't expecting it to).
    476  *
    477  * Locks are held before coming here.
    478  */
    479 void
    480 isp_uninit(isp)
    481 	struct ispsoftc *isp;
    482 {
    483 	ISP_ILOCKVAL_DECL;
    484 	ISP_ILOCK(isp);
    485 	/*
    486 	 * Leave with interrupts disabled.
    487 	 */
    488 	DISABLE_INTS(isp);
    489 
    490 	/*
    491 	 * Turn off the watchdog (if active).
    492 	 */
    493 	if (isp->isp_dogactive) {
    494 		untimeout(isp_watch, isp);
    495 		isp->isp_dogactive = 0;
    496 	}
    497 
    498 	ISP_IUNLOCK(isp);
    499 }
    500 
    501 /*
    502  * Restart function for a command to be requeued later.
    503  */
    504 static void
    505 isp_command_requeue(arg)
    506 	void *arg;
    507 {
    508 	struct scsipi_xfer *xs = arg;
    509 	struct ispsoftc *isp = XS_ISP(xs);
    510 	int s = splbio();
    511 	switch (ispcmd_slow(xs)) {
    512 	case SUCCESSFULLY_QUEUED:
    513 		printf("%s: isp_command_requeue: requeued for %d.%d\n",
    514 		    isp->isp_name, XS_TGT(xs), XS_LUN(xs));
    515 		break;
    516 	case TRY_AGAIN_LATER:
    517 		printf("%s: EAGAIN for %d.%d\n",
    518 		    isp->isp_name, XS_TGT(xs), XS_LUN(xs));
    519 		/* FALLTHROUGH */
    520 	case COMPLETE:
    521 		/* can only be an error */
    522 		xs->xs_status |= XS_STS_DONE;
    523 		if (XS_NOERR(xs)) {
    524 			XS_SETERR(xs, HBA_BOTCH);
    525 		}
    526 		scsipi_done(xs);
    527 		break;
    528 	}
    529 	(void) splx(s);
    530 }
    531 
    532 /*
    533  * Restart function after a LOOP UP event (e.g.),
    534  * done as a timeout for some hysteresis.
    535  */
    536 static void
    537 isp_internal_restart(arg)
    538 	void *arg;
    539 {
    540 	struct ispsoftc *isp = arg;
    541 	int result, nrestarted = 0, s;
    542 
    543 	s = splbio();
    544 	if (isp->isp_osinfo.blocked == 0) {
    545 		struct scsipi_xfer *xs;
    546 		while ((xs = TAILQ_FIRST(&isp->isp_osinfo.waitq)) != NULL) {
    547 			TAILQ_REMOVE(&isp->isp_osinfo.waitq, xs, adapter_q);
    548 			DISABLE_INTS(isp);
    549 			result = ispscsicmd(xs);
    550 			ENABLE_INTS(isp);
    551 			if (result != CMD_QUEUED) {
    552 				printf("%s: botched command restart (0x%x)\n",
    553 				    isp->isp_name, result);
    554 				xs->xs_status |= XS_STS_DONE;
    555 				if (xs->error == XS_NOERROR)
    556 					xs->error = XS_DRIVER_STUFFUP;
    557 				scsipi_done(xs);
    558 			}
    559 			nrestarted++;
    560 		}
    561 		printf("%s: requeued %d commands\n", isp->isp_name, nrestarted);
    562 	}
    563 	(void) splx(s);
    564 }
    565 
    566 int
    567 isp_async(isp, cmd, arg)
    568 	struct ispsoftc *isp;
    569 	ispasync_t cmd;
    570 	void *arg;
    571 {
    572 	int bus, tgt;
    573 	int s = splbio();
    574 	switch (cmd) {
    575 	case ISPASYNC_NEW_TGT_PARAMS:
    576 	if (IS_SCSI(isp) && isp->isp_dblev) {
    577 		sdparam *sdp = isp->isp_param;
    578 		char *wt;
    579 		int mhz, flags, period;
    580 
    581 		tgt = *((int *) arg);
    582 		bus = (tgt >> 16) & 0xffff;
    583 		tgt &= 0xffff;
    584 
    585 		flags = sdp->isp_devparam[tgt].cur_dflags;
    586 		period = sdp->isp_devparam[tgt].cur_period;
    587 		if ((flags & DPARM_SYNC) && period &&
    588 		    (sdp->isp_devparam[tgt].cur_offset) != 0) {
    589 			if (sdp->isp_lvdmode) {
    590 				switch (period) {
    591 				case 0xa:
    592 					mhz = 40;
    593 					break;
    594 				case 0xb:
    595 					mhz = 33;
    596 					break;
    597 				case 0xc:
    598 					mhz = 25;
    599 					break;
    600 				default:
    601 					mhz = 1000 / (period * 4);
    602 					break;
    603 				}
    604 			} else {
    605 				mhz = 1000 / (period * 4);
    606 			}
    607 		} else {
    608 			mhz = 0;
    609 		}
    610 		switch (flags & (DPARM_WIDE|DPARM_TQING)) {
    611 		case DPARM_WIDE:
    612 			wt = ", 16 bit wide\n";
    613 			break;
    614 		case DPARM_TQING:
    615 			wt = ", Tagged Queueing Enabled\n";
    616 			break;
    617 		case DPARM_WIDE|DPARM_TQING:
    618 			wt = ", 16 bit wide, Tagged Queueing Enabled\n";
    619 			break;
    620 		default:
    621 			wt = "\n";
    622 			break;
    623 		}
    624 		if (mhz) {
    625 			CFGPRINTF("%s: Bus %d Target %d at %dMHz Max "
    626 			    "Offset %d%s", isp->isp_name, bus, tgt, mhz,
    627 			    sdp->isp_devparam[tgt].cur_offset, wt);
    628 		} else {
    629 			CFGPRINTF("%s: Bus %d Target %d Async Mode%s",
    630 			    isp->isp_name, bus, tgt, wt);
    631 		}
    632 		break;
    633 	}
    634 	case ISPASYNC_BUS_RESET:
    635 		if (arg)
    636 			bus = *((int *) arg);
    637 		else
    638 			bus = 0;
    639 		printf("%s: SCSI bus %d reset detected\n", isp->isp_name, bus);
    640 		break;
    641 	case ISPASYNC_LOOP_DOWN:
    642 		/*
    643 		 * Hopefully we get here in time to minimize the number
    644 		 * of commands we are firing off that are sure to die.
    645 		 */
    646 		isp->isp_osinfo.blocked = 1;
    647 		printf("%s: Loop DOWN\n", isp->isp_name);
    648 		break;
    649         case ISPASYNC_LOOP_UP:
    650 		isp->isp_osinfo.blocked = 0;
    651 		timeout(isp_internal_restart, isp, 1);
    652 		printf("%s: Loop UP\n", isp->isp_name);
    653 		break;
    654 	case ISPASYNC_PDB_CHANGED:
    655 	if (IS_FC(isp) && isp->isp_dblev) {
    656 		const char *fmt = "%s: Target %d (Loop 0x%x) Port ID 0x%x "
    657 		    "role %s %s\n Port WWN 0x%08x%08x\n Node WWN 0x%08x%08x\n";
    658 		const static char *roles[4] = {
    659 		    "No", "Target", "Initiator", "Target/Initiator"
    660 		};
    661 		char *ptr;
    662 		fcparam *fcp = isp->isp_param;
    663 		int tgt = *((int *) arg);
    664 		struct lportdb *lp = &fcp->portdb[tgt];
    665 
    666 		if (lp->valid) {
    667 			ptr = "arrived";
    668 		} else {
    669 			ptr = "disappeared";
    670 		}
    671 		printf(fmt, isp->isp_name, tgt, lp->loopid, lp->portid,
    672 		    roles[lp->roles & 0x3], ptr,
    673 		    (u_int32_t) (lp->port_wwn >> 32),
    674 		    (u_int32_t) (lp->port_wwn & 0xffffffffLL),
    675 		    (u_int32_t) (lp->node_wwn >> 32),
    676 		    (u_int32_t) (lp->node_wwn & 0xffffffffLL));
    677 		break;
    678 	}
    679 #ifdef	ISP2100_FABRIC
    680 	case ISPASYNC_CHANGE_NOTIFY:
    681 		printf("%s: Name Server Database Changed\n", isp->isp_name);
    682 		break;
    683 	case ISPASYNC_FABRIC_DEV:
    684 	{
    685 		int target;
    686 		struct lportdb *lp;
    687 		sns_scrsp_t *resp = (sns_scrsp_t *) arg;
    688 		u_int32_t portid;
    689 		u_int64_t wwn;
    690 		fcparam *fcp = isp->isp_param;
    691 
    692 		portid =
    693 		    (((u_int32_t) resp->snscb_port_id[0]) << 16) |
    694 		    (((u_int32_t) resp->snscb_port_id[1]) << 8) |
    695 		    (((u_int32_t) resp->snscb_port_id[2]));
    696 		wwn =
    697 		    (((u_int64_t)resp->snscb_portname[0]) << 56) |
    698 		    (((u_int64_t)resp->snscb_portname[1]) << 48) |
    699 		    (((u_int64_t)resp->snscb_portname[2]) << 40) |
    700 		    (((u_int64_t)resp->snscb_portname[3]) << 32) |
    701 		    (((u_int64_t)resp->snscb_portname[4]) << 24) |
    702 		    (((u_int64_t)resp->snscb_portname[5]) << 16) |
    703 		    (((u_int64_t)resp->snscb_portname[6]) <<  8) |
    704 		    (((u_int64_t)resp->snscb_portname[7]));
    705 		printf("%s: Fabric Device (Type 0x%x)@PortID 0x%x WWN "
    706 		    "0x%08x%08x\n", isp->isp_name, resp->snscb_port_type,
    707 		    portid, ((u_int32_t)(wwn >> 32)),
    708 		    ((u_int32_t)(wwn & 0xffffffff)));
    709 		if (resp->snscb_port_type != 2)
    710 			break;
    711 		for (target = FC_SNS_ID+1; target < MAX_FC_TARG; target++) {
    712 			lp = &fcp->portdb[target];
    713 			if (lp->port_wwn == wwn)
    714 				break;
    715 		}
    716 		if (target < MAX_FC_TARG) {
    717 			break;
    718 		}
    719 		for (target = FC_SNS_ID+1; target < MAX_FC_TARG; target++) {
    720 			lp = &fcp->portdb[target];
    721 			if (lp->port_wwn == 0)
    722 				break;
    723 		}
    724 		if (target == MAX_FC_TARG) {
    725 			printf("%s: no more space for fabric devices\n",
    726 			    isp->isp_name);
    727 			return (-1);
    728 		}
    729 		lp->port_wwn = lp->node_wwn = wwn;
    730 		lp->portid = portid;
    731 		break;
    732 	}
    733 #endif
    734 	default:
    735 		break;
    736 	}
    737 	(void) splx(s);
    738 	return (0);
    739 }
    740