Home | History | Annotate | Line # | Download | only in ic
isp_netbsd.c revision 1.12.4.2
      1  1.12.4.2  thorpej /* $NetBSD: isp_netbsd.c,v 1.12.4.2 1999/08/02 21:59:05 thorpej Exp $ */
      2  1.12.4.2  thorpej /* release_6_5_99 */
      3       1.1   mjacob /*
      4       1.1   mjacob  * Platform (NetBSD) dependent common attachment code for Qlogic adapters.
      5  1.12.4.2  thorpej  * Matthew Jacob <mjacob (at) nas.nasa.gov>
      6  1.12.4.2  thorpej  */
      7  1.12.4.2  thorpej /*
      8  1.12.4.2  thorpej  * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
      9       1.1   mjacob  * All rights reserved.
     10       1.1   mjacob  *
     11       1.1   mjacob  * Redistribution and use in source and binary forms, with or without
     12       1.1   mjacob  * modification, are permitted provided that the following conditions
     13       1.1   mjacob  * are met:
     14       1.1   mjacob  * 1. Redistributions of source code must retain the above copyright
     15  1.12.4.2  thorpej  *    notice, this list of conditions and the following disclaimer.
     16       1.1   mjacob  * 2. Redistributions in binary form must reproduce the above copyright
     17       1.1   mjacob  *    notice, this list of conditions and the following disclaimer in the
     18       1.1   mjacob  *    documentation and/or other materials provided with the distribution.
     19       1.1   mjacob  * 3. The name of the author may not be used to endorse or promote products
     20  1.12.4.2  thorpej  *    derived from this software without specific prior written permission
     21       1.1   mjacob  *
     22  1.12.4.2  thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  1.12.4.2  thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.12.4.2  thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.12.4.2  thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  1.12.4.2  thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  1.12.4.2  thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  1.12.4.2  thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  1.12.4.2  thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  1.12.4.2  thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  1.12.4.2  thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32       1.1   mjacob  */
     33       1.1   mjacob 
     34       1.1   mjacob #include <dev/ic/isp_netbsd.h>
     35       1.1   mjacob 
     36       1.1   mjacob static void ispminphys __P((struct buf *));
     37       1.1   mjacob static int32_t ispcmd __P((ISP_SCSI_XFER_T *));
     38       1.1   mjacob 
     39       1.1   mjacob static struct scsipi_device isp_dev = { NULL, NULL, NULL, NULL };
     40       1.1   mjacob static int isp_poll __P((struct ispsoftc *, ISP_SCSI_XFER_T *, int));
     41      1.10   mjacob static void isp_watch __P((void *));
     42      1.10   mjacob static void isp_internal_restart __P((void *));
     43      1.10   mjacob 
     44      1.10   mjacob #define	FC_OPENINGS	RQUEST_QUEUE_LEN / (MAX_FC_TARG-1)
     45      1.10   mjacob #define	PI_OPENINGS	RQUEST_QUEUE_LEN / (MAX_TARGETS-1)
     46       1.1   mjacob 
     47       1.1   mjacob /*
     48       1.1   mjacob  * Complete attachment of hardware, include subdevices.
     49       1.1   mjacob  */
     50       1.1   mjacob void
     51       1.1   mjacob isp_attach(isp)
     52       1.1   mjacob 	struct ispsoftc *isp;
     53       1.1   mjacob {
     54       1.6  thorpej 
     55       1.6  thorpej 	isp->isp_osinfo._adapter.scsipi_cmd = ispcmd;
     56       1.6  thorpej 	isp->isp_osinfo._adapter.scsipi_minphys = ispminphys;
     57       1.6  thorpej 
     58       1.1   mjacob 	isp->isp_state = ISP_RUNSTATE;
     59       1.1   mjacob 	isp->isp_osinfo._link.scsipi_scsi.channel = SCSI_CHANNEL_ONLY_ONE;
     60       1.1   mjacob 	isp->isp_osinfo._link.adapter_softc = isp;
     61       1.1   mjacob 	isp->isp_osinfo._link.device = &isp_dev;
     62       1.6  thorpej 	isp->isp_osinfo._link.adapter = &isp->isp_osinfo._adapter;
     63      1.10   mjacob 	TAILQ_INIT(&isp->isp_osinfo.waitq);
     64       1.1   mjacob 
     65  1.12.4.2  thorpej 	if (IS_FC(isp)) {
     66      1.11   mjacob 		/*
     67      1.11   mjacob 		 * Give it another chance here to come alive...
     68      1.11   mjacob 		 */
     69      1.11   mjacob 		fcparam *fcp = isp->isp_param;
     70      1.11   mjacob 		if (fcp->isp_fwstate != FW_READY) {
     71      1.11   mjacob 			(void) isp_control(isp, ISPCTL_FCLINK_TEST, NULL);
     72      1.11   mjacob 		}
     73       1.1   mjacob 		isp->isp_osinfo._link.scsipi_scsi.max_target = MAX_FC_TARG-1;
     74      1.11   mjacob #ifdef	ISP2100_SCCLUN
     75       1.7   mjacob 		/*
     76       1.7   mjacob 		 * 16 bits worth, but let's be reasonable..
     77       1.7   mjacob 		 */
     78       1.7   mjacob 		isp->isp_osinfo._link.scsipi_scsi.max_lun = 255;
     79       1.7   mjacob #else
     80       1.7   mjacob 		isp->isp_osinfo._link.scsipi_scsi.max_lun = 15;
     81       1.7   mjacob #endif
     82      1.10   mjacob 		isp->isp_osinfo._link.openings = FC_OPENINGS;
     83       1.7   mjacob 		isp->isp_osinfo._link.scsipi_scsi.adapter_target =
     84       1.7   mjacob 			((fcparam *)isp->isp_param)->isp_loopid;
     85       1.1   mjacob 	} else {
     86  1.12.4.1  thorpej 		sdparam *sdp = isp->isp_param;
     87      1.10   mjacob 		isp->isp_osinfo._link.openings = PI_OPENINGS;
     88       1.1   mjacob 		isp->isp_osinfo._link.scsipi_scsi.max_target = MAX_TARGETS-1;
     89       1.7   mjacob 		if (isp->isp_bustype == ISP_BT_SBUS) {
     90       1.7   mjacob 			isp->isp_osinfo._link.scsipi_scsi.max_lun = 7;
     91       1.7   mjacob 		} else {
     92       1.7   mjacob 			/*
     93       1.7   mjacob 			 * Too much target breakage at present.
     94       1.7   mjacob 			 */
     95       1.7   mjacob #if	0
     96  1.12.4.1  thorpej 			if (isp->isp_fwrev >= ISP_FW_REV(7,55,0))
     97       1.7   mjacob 				isp->isp_osinfo._link.scsipi_scsi.max_lun = 31;
     98       1.7   mjacob 			else
     99       1.7   mjacob #endif
    100       1.7   mjacob 				isp->isp_osinfo._link.scsipi_scsi.max_lun = 7;
    101       1.7   mjacob 		}
    102       1.1   mjacob 		isp->isp_osinfo._link.scsipi_scsi.adapter_target =
    103  1.12.4.1  thorpej 		    sdp->isp_initiator_id;
    104  1.12.4.1  thorpej 		if (IS_12X0(isp)) {
    105  1.12.4.1  thorpej 			isp->isp_osinfo._link_b = isp->isp_osinfo._link;
    106  1.12.4.1  thorpej 			sdp++;
    107  1.12.4.1  thorpej 			isp->isp_osinfo._link_b.scsipi_scsi.adapter_target =
    108  1.12.4.1  thorpej 			    sdp->isp_initiator_id;
    109  1.12.4.1  thorpej 			isp->isp_osinfo._link_b.scsipi_scsi.channel = 1;
    110  1.12.4.1  thorpej 		}
    111       1.1   mjacob 	}
    112       1.1   mjacob 	if (isp->isp_osinfo._link.openings < 2)
    113       1.1   mjacob 		isp->isp_osinfo._link.openings = 2;
    114       1.1   mjacob 	isp->isp_osinfo._link.type = BUS_SCSI;
    115       1.8   mjacob 
    116       1.8   mjacob 	/*
    117      1.10   mjacob 	 * Send a SCSI Bus Reset (used to be done as part of attach,
    118      1.10   mjacob 	 * but now left to the OS outer layers).
    119      1.10   mjacob 	 */
    120      1.10   mjacob 
    121  1.12.4.1  thorpej 	if (IS_SCSI(isp)) {
    122  1.12.4.1  thorpej 		int bus = 0;
    123  1.12.4.1  thorpej 		(void) isp_control(isp, ISPCTL_RESET_BUS, &bus);
    124  1.12.4.1  thorpej 		if (IS_12X0(isp)) {
    125  1.12.4.1  thorpej 			bus++;
    126  1.12.4.1  thorpej 			(void) isp_control(isp, ISPCTL_RESET_BUS, &bus);
    127  1.12.4.1  thorpej 		}
    128      1.11   mjacob 		SYS_DELAY(2*1000000);
    129      1.11   mjacob 	}
    130      1.10   mjacob 
    131      1.10   mjacob 	/*
    132       1.8   mjacob 	 * Start the watchdog.
    133       1.8   mjacob 	 */
    134       1.8   mjacob 	isp->isp_dogactive = 1;
    135       1.8   mjacob 	timeout(isp_watch, isp, 30 * hz);
    136       1.8   mjacob 
    137       1.8   mjacob 	/*
    138       1.8   mjacob 	 * And attach children (if any).
    139       1.8   mjacob 	 */
    140       1.1   mjacob 	config_found((void *)isp, &isp->isp_osinfo._link, scsiprint);
    141  1.12.4.1  thorpej 	if (IS_12X0(isp)) {
    142  1.12.4.1  thorpej 		config_found((void *)isp, &isp->isp_osinfo._link_b, scsiprint);
    143  1.12.4.1  thorpej 	}
    144       1.1   mjacob }
    145       1.1   mjacob 
    146       1.1   mjacob /*
    147       1.1   mjacob  * minphys our xfers
    148       1.1   mjacob  *
    149       1.1   mjacob  * Unfortunately, the buffer pointer describes the target device- not the
    150       1.1   mjacob  * adapter device, so we can't use the pointer to find out what kind of
    151       1.1   mjacob  * adapter we are and adjust accordingly.
    152       1.1   mjacob  */
    153       1.1   mjacob 
    154       1.1   mjacob static void
    155       1.1   mjacob ispminphys(bp)
    156       1.1   mjacob 	struct buf *bp;
    157       1.1   mjacob {
    158       1.1   mjacob 	/*
    159       1.1   mjacob 	 * XX: Only the 1020 has a 24 bit limit.
    160       1.1   mjacob 	 */
    161       1.1   mjacob 	if (bp->b_bcount >= (1 << 24)) {
    162       1.1   mjacob 		bp->b_bcount = (1 << 24);
    163       1.1   mjacob 	}
    164       1.1   mjacob 	minphys(bp);
    165       1.1   mjacob }
    166       1.1   mjacob 
    167       1.1   mjacob static int
    168       1.1   mjacob ispcmd(xs)
    169       1.1   mjacob 	ISP_SCSI_XFER_T *xs;
    170       1.1   mjacob {
    171       1.1   mjacob 	struct ispsoftc *isp;
    172       1.3   mjacob 	int result;
    173      1.10   mjacob 	int s;
    174       1.1   mjacob 
    175       1.1   mjacob 	isp = XS_ISP(xs);
    176      1.10   mjacob 	s = splbio();
    177       1.3   mjacob 	/*
    178       1.3   mjacob 	 * This is less efficient than I would like in that the
    179       1.3   mjacob 	 * majority of cases will have to do some pointer deferences
    180       1.3   mjacob 	 * to find out that things don't need to be updated.
    181       1.3   mjacob 	 */
    182       1.3   mjacob 	if ((xs->flags & SCSI_AUTOCONF) == 0 && (isp->isp_type & ISP_HA_SCSI)) {
    183       1.3   mjacob 		sdparam *sdp = isp->isp_param;
    184  1.12.4.1  thorpej 		sdp += XS_CHANNEL(xs);
    185       1.3   mjacob 		if (sdp->isp_devparam[XS_TGT(xs)].dev_flags !=
    186       1.3   mjacob 		    sdp->isp_devparam[XS_TGT(xs)].cur_dflags) {
    187       1.3   mjacob 			u_int16_t f = DPARM_WIDE|DPARM_SYNC|DPARM_TQING;
    188       1.3   mjacob 			if (xs->sc_link->quirks & SDEV_NOSYNC)
    189       1.3   mjacob 				f &= ~DPARM_SYNC;
    190       1.3   mjacob 			if (xs->sc_link->quirks & SDEV_NOWIDE)
    191       1.3   mjacob 				f &= ~DPARM_WIDE;
    192       1.3   mjacob 			if (xs->sc_link->quirks & SDEV_NOTAG)
    193       1.3   mjacob 				f &= ~DPARM_TQING;
    194       1.3   mjacob 			sdp->isp_devparam[XS_TGT(xs)].dev_flags &=
    195       1.3   mjacob 				~(DPARM_WIDE|DPARM_SYNC|DPARM_TQING);
    196       1.3   mjacob 			sdp->isp_devparam[XS_TGT(xs)].dev_flags |= f;
    197       1.3   mjacob 			sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
    198  1.12.4.1  thorpej 			isp->isp_update |= (1 << XS_CHANNEL(xs));
    199       1.3   mjacob 		}
    200       1.3   mjacob 	}
    201      1.11   mjacob 
    202      1.11   mjacob 	if (isp->isp_state < ISP_RUNSTATE) {
    203      1.11   mjacob 		DISABLE_INTS(isp);
    204      1.11   mjacob 		isp_init(isp);
    205      1.11   mjacob                 if (isp->isp_state != ISP_INITSTATE) {
    206      1.11   mjacob 			ENABLE_INTS(isp);
    207      1.11   mjacob                         (void) splx(s);
    208      1.11   mjacob                         XS_SETERR(xs, HBA_BOTCH);
    209      1.11   mjacob                         return (CMD_COMPLETE);
    210      1.11   mjacob                 }
    211      1.11   mjacob                 isp->isp_state = ISP_RUNSTATE;
    212      1.11   mjacob 		ENABLE_INTS(isp);
    213      1.11   mjacob         }
    214      1.11   mjacob 
    215      1.10   mjacob 	/*
    216      1.10   mjacob 	 * Check for queue blockage...
    217      1.10   mjacob 	 */
    218      1.10   mjacob 
    219      1.10   mjacob 	if (isp->isp_osinfo.blocked) {
    220      1.10   mjacob 		if (xs->flags & SCSI_POLL) {
    221      1.10   mjacob 			xs->error = XS_DRIVER_STUFFUP;
    222      1.10   mjacob 			splx(s);
    223      1.10   mjacob 			return (TRY_AGAIN_LATER);
    224      1.10   mjacob 		}
    225      1.10   mjacob 		TAILQ_INSERT_TAIL(&isp->isp_osinfo.waitq, xs, adapter_q);
    226      1.10   mjacob 		splx(s);
    227      1.10   mjacob 		return (CMD_QUEUED);
    228      1.10   mjacob 	}
    229      1.10   mjacob 
    230      1.11   mjacob 	DISABLE_INTS(isp);
    231       1.3   mjacob 	result = ispscsicmd(xs);
    232      1.11   mjacob 	ENABLE_INTS(isp);
    233       1.3   mjacob 	if (result != CMD_QUEUED || (xs->flags & SCSI_POLL) == 0) {
    234      1.10   mjacob 		(void) splx(s);
    235       1.3   mjacob 		return (result);
    236       1.1   mjacob 	}
    237       1.1   mjacob 
    238       1.1   mjacob 	/*
    239       1.1   mjacob 	 * If we can't use interrupts, poll on completion.
    240       1.1   mjacob 	 */
    241       1.1   mjacob 	if (isp_poll(isp, xs, XS_TIME(xs))) {
    242       1.1   mjacob 		/*
    243       1.1   mjacob 		 * If no other error occurred but we didn't finish,
    244       1.1   mjacob 		 * something bad happened.
    245       1.1   mjacob 		 */
    246       1.1   mjacob 		if (XS_IS_CMD_DONE(xs) == 0) {
    247       1.1   mjacob 			isp->isp_nactive--;
    248       1.1   mjacob 			if (isp->isp_nactive < 0)
    249       1.1   mjacob 				isp->isp_nactive = 0;
    250       1.1   mjacob 			if (XS_NOERR(xs)) {
    251       1.1   mjacob 				isp_lostcmd(isp, xs);
    252       1.1   mjacob 				XS_SETERR(xs, HBA_BOTCH);
    253       1.1   mjacob 			}
    254       1.1   mjacob 		}
    255       1.1   mjacob 	}
    256      1.10   mjacob 	(void) splx(s);
    257       1.1   mjacob 	return (CMD_COMPLETE);
    258       1.1   mjacob }
    259       1.1   mjacob 
    260       1.1   mjacob static int
    261       1.1   mjacob isp_poll(isp, xs, mswait)
    262       1.1   mjacob 	struct ispsoftc *isp;
    263       1.1   mjacob 	ISP_SCSI_XFER_T *xs;
    264       1.1   mjacob 	int mswait;
    265       1.1   mjacob {
    266       1.1   mjacob 
    267       1.1   mjacob 	while (mswait) {
    268       1.1   mjacob 		/* Try the interrupt handling routine */
    269       1.1   mjacob 		(void)isp_intr((void *)isp);
    270       1.1   mjacob 
    271       1.1   mjacob 		/* See if the xs is now done */
    272       1.1   mjacob 		if (XS_IS_CMD_DONE(xs)) {
    273       1.1   mjacob 			return (0);
    274       1.1   mjacob 		}
    275       1.1   mjacob 		SYS_DELAY(1000);	/* wait one millisecond */
    276       1.1   mjacob 		mswait--;
    277       1.1   mjacob 	}
    278       1.1   mjacob 	return (1);
    279       1.8   mjacob }
    280       1.8   mjacob 
    281       1.8   mjacob static void
    282       1.8   mjacob isp_watch(arg)
    283       1.8   mjacob 	void *arg;
    284       1.8   mjacob {
    285       1.8   mjacob 	int i;
    286       1.8   mjacob 	struct ispsoftc *isp = arg;
    287       1.8   mjacob 	ISP_SCSI_XFER_T *xs;
    288       1.8   mjacob 	ISP_ILOCKVAL_DECL;
    289       1.8   mjacob 
    290       1.8   mjacob 	/*
    291       1.8   mjacob 	 * Look for completely dead commands (but not polled ones).
    292       1.8   mjacob 	 */
    293       1.8   mjacob 	ISP_ILOCK(isp);
    294       1.8   mjacob 	for (i = 0; i < RQUEST_QUEUE_LEN; i++) {
    295       1.8   mjacob 		if ((xs = (ISP_SCSI_XFER_T *) isp->isp_xflist[i]) == NULL) {
    296       1.8   mjacob 			continue;
    297       1.8   mjacob 		}
    298       1.8   mjacob 		if (XS_TIME(xs) == 0) {
    299       1.8   mjacob 			continue;
    300       1.8   mjacob 		}
    301       1.8   mjacob 		XS_TIME(xs) -= (WATCH_INTERVAL * 1000);
    302       1.8   mjacob 		/*
    303       1.8   mjacob 		 * Avoid later thinking that this
    304       1.8   mjacob 		 * transaction is not being timed.
    305       1.8   mjacob 		 * Then give ourselves to watchdog
    306       1.8   mjacob 		 * periods of grace.
    307       1.8   mjacob 		 */
    308       1.8   mjacob 		if (XS_TIME(xs) == 0) {
    309       1.8   mjacob 			XS_TIME(xs) = 1;
    310       1.8   mjacob 		} else if (XS_TIME(xs) > -(2 * WATCH_INTERVAL * 1000)) {
    311       1.8   mjacob 			continue;
    312       1.8   mjacob 		}
    313       1.8   mjacob 		if (isp_control(isp, ISPCTL_ABORT_CMD, xs)) {
    314       1.8   mjacob 			printf("%s: isp_watch failed to abort command\n",
    315       1.8   mjacob 			    isp->isp_name);
    316       1.8   mjacob 			isp_restart(isp);
    317       1.8   mjacob 			break;
    318       1.8   mjacob 		}
    319       1.8   mjacob 	}
    320       1.8   mjacob 	timeout(isp_watch, isp, WATCH_INTERVAL * hz);
    321       1.8   mjacob 	isp->isp_dogactive = 1;
    322       1.8   mjacob 	ISP_IUNLOCK(isp);
    323       1.8   mjacob }
    324       1.8   mjacob 
    325       1.8   mjacob /*
    326       1.8   mjacob  * Free any associated resources prior to decommissioning and
    327       1.8   mjacob  * set the card to a known state (so it doesn't wake up and kick
    328       1.8   mjacob  * us when we aren't expecting it to).
    329       1.8   mjacob  *
    330       1.8   mjacob  * Locks are held before coming here.
    331       1.8   mjacob  */
    332       1.8   mjacob void
    333       1.8   mjacob isp_uninit(isp)
    334       1.8   mjacob 	struct ispsoftc *isp;
    335       1.8   mjacob {
    336       1.8   mjacob 	ISP_ILOCKVAL_DECL;
    337       1.8   mjacob 	ISP_ILOCK(isp);
    338       1.8   mjacob 	/*
    339       1.8   mjacob 	 * Leave with interrupts disabled.
    340       1.8   mjacob 	 */
    341       1.8   mjacob 	DISABLE_INTS(isp);
    342       1.8   mjacob 
    343       1.8   mjacob 	/*
    344       1.8   mjacob 	 * Turn off the watchdog (if active).
    345       1.8   mjacob 	 */
    346       1.8   mjacob 	if (isp->isp_dogactive) {
    347       1.8   mjacob 		untimeout(isp_watch, isp);
    348       1.8   mjacob 		isp->isp_dogactive = 0;
    349       1.8   mjacob 	}
    350       1.8   mjacob 
    351       1.8   mjacob 	ISP_IUNLOCK(isp);
    352       1.9   mjacob }
    353       1.9   mjacob 
    354      1.10   mjacob /*
    355      1.10   mjacob  * Restart function after a LOOP UP event (e.g.),
    356      1.10   mjacob  * done as a timeout for some hysteresis.
    357      1.10   mjacob  */
    358      1.10   mjacob static void
    359      1.10   mjacob isp_internal_restart(arg)
    360      1.10   mjacob 	void *arg;
    361      1.10   mjacob {
    362      1.10   mjacob 	struct ispsoftc *isp = arg;
    363      1.11   mjacob 	int result, nrestarted = 0, s;
    364      1.10   mjacob 
    365      1.11   mjacob 	s = splbio();
    366      1.10   mjacob 	if (isp->isp_osinfo.blocked == 0) {
    367      1.10   mjacob 		struct scsipi_xfer *xs;
    368      1.10   mjacob 		while ((xs = TAILQ_FIRST(&isp->isp_osinfo.waitq)) != NULL) {
    369      1.10   mjacob 			TAILQ_REMOVE(&isp->isp_osinfo.waitq, xs, adapter_q);
    370      1.11   mjacob 			DISABLE_INTS(isp);
    371      1.11   mjacob 			result = ispscsicmd(xs);
    372      1.11   mjacob 			ENABLE_INTS(isp);
    373      1.11   mjacob 			if (result != CMD_QUEUED) {
    374      1.10   mjacob 				printf("%s: botched command restart (0x%x)\n",
    375      1.10   mjacob 				    isp->isp_name, result);
    376      1.10   mjacob 				xs->flags |= ITSDONE;
    377      1.10   mjacob 				if (xs->error == XS_NOERROR)
    378      1.10   mjacob 					xs->error = XS_DRIVER_STUFFUP;
    379      1.10   mjacob 				scsipi_done(xs);
    380      1.10   mjacob 			}
    381      1.10   mjacob 			nrestarted++;
    382      1.10   mjacob 		}
    383      1.10   mjacob 		printf("%s: requeued %d commands\n", isp->isp_name, nrestarted);
    384      1.10   mjacob 	}
    385      1.10   mjacob 	(void) splx(s);
    386      1.10   mjacob }
    387      1.10   mjacob 
    388       1.9   mjacob int
    389       1.9   mjacob isp_async(isp, cmd, arg)
    390       1.9   mjacob 	struct ispsoftc *isp;
    391       1.9   mjacob 	ispasync_t cmd;
    392       1.9   mjacob 	void *arg;
    393       1.9   mjacob {
    394  1.12.4.1  thorpej 	int bus, tgt;
    395      1.10   mjacob 	int s = splbio();
    396       1.9   mjacob 	switch (cmd) {
    397       1.9   mjacob 	case ISPASYNC_NEW_TGT_PARAMS:
    398       1.9   mjacob 		if (isp->isp_type & ISP_HA_SCSI) {
    399       1.9   mjacob 			sdparam *sdp = isp->isp_param;
    400       1.9   mjacob 			char *wt;
    401  1.12.4.1  thorpej 			int mhz, flags, period;
    402       1.9   mjacob 
    403       1.9   mjacob 			tgt = *((int *) arg);
    404  1.12.4.1  thorpej 			bus = (tgt >> 16) & 0xffff;
    405  1.12.4.1  thorpej 			tgt &= 0xffff;
    406      1.12   mjacob 
    407      1.12   mjacob 			flags = sdp->isp_devparam[tgt].cur_dflags;
    408      1.12   mjacob 			period = sdp->isp_devparam[tgt].cur_period;
    409      1.12   mjacob 			if ((flags & DPARM_SYNC) && period &&
    410      1.12   mjacob 			    (sdp->isp_devparam[tgt].cur_offset) != 0) {
    411      1.12   mjacob 				if (sdp->isp_lvdmode) {
    412      1.12   mjacob 					switch (period) {
    413      1.12   mjacob 					case 0xa:
    414      1.12   mjacob 						mhz = 40;
    415      1.12   mjacob 						break;
    416      1.12   mjacob 					case 0xb:
    417      1.12   mjacob 						mhz = 33;
    418      1.12   mjacob 						break;
    419      1.12   mjacob 					case 0xc:
    420      1.12   mjacob 						mhz = 25;
    421      1.12   mjacob 						break;
    422      1.12   mjacob 					default:
    423      1.12   mjacob 						mhz = 1000 / (period * 4);
    424      1.12   mjacob 						break;
    425      1.12   mjacob 					}
    426      1.12   mjacob 				} else {
    427      1.12   mjacob 					mhz = 1000 / (period * 4);
    428      1.12   mjacob 				}
    429       1.9   mjacob 			} else {
    430      1.12   mjacob 				mhz = 0;
    431       1.9   mjacob 			}
    432       1.9   mjacob 			switch (flags & (DPARM_WIDE|DPARM_TQING)) {
    433       1.9   mjacob 			case DPARM_WIDE:
    434       1.9   mjacob 				wt = ", 16 bit wide\n";
    435       1.9   mjacob 				break;
    436       1.9   mjacob 			case DPARM_TQING:
    437       1.9   mjacob 				wt = ", Tagged Queueing Enabled\n";
    438       1.9   mjacob 				break;
    439       1.9   mjacob 			case DPARM_WIDE|DPARM_TQING:
    440       1.9   mjacob 				wt = ", 16 bit wide, Tagged Queueing Enabled\n";
    441       1.9   mjacob 				break;
    442       1.9   mjacob 			default:
    443       1.9   mjacob 				wt = "\n";
    444       1.9   mjacob 				break;
    445       1.9   mjacob 			}
    446      1.12   mjacob 			if (mhz) {
    447  1.12.4.1  thorpej 				printf("%s: Bus %d Target %d at %dMHz Max "
    448  1.12.4.1  thorpej 				    "Offset %d%s", isp->isp_name, bus, tgt, mhz,
    449      1.12   mjacob 				    sdp->isp_devparam[tgt].cur_offset, wt);
    450       1.9   mjacob 			} else {
    451  1.12.4.1  thorpej 				printf("%s: Bus %d Target %d Async Mode%s",
    452  1.12.4.1  thorpej 				    isp->isp_name, bus, tgt, wt);
    453       1.9   mjacob 			}
    454       1.9   mjacob 		}
    455      1.11   mjacob 		break;
    456      1.11   mjacob 	case ISPASYNC_BUS_RESET:
    457  1.12.4.1  thorpej 		if (arg)
    458  1.12.4.1  thorpej 			bus = *((int *) arg);
    459  1.12.4.1  thorpej 		else
    460  1.12.4.1  thorpej 			bus = 0;
    461  1.12.4.1  thorpej 		printf("%s: SCSI bus %d reset detected\n", isp->isp_name, bus);
    462      1.11   mjacob 		break;
    463      1.11   mjacob 	case ISPASYNC_LOOP_DOWN:
    464      1.11   mjacob 		/*
    465      1.11   mjacob 		 * Hopefully we get here in time to minimize the number
    466      1.11   mjacob 		 * of commands we are firing off that are sure to die.
    467      1.11   mjacob 		 */
    468      1.11   mjacob 		isp->isp_osinfo.blocked = 1;
    469      1.11   mjacob 		printf("%s: Loop DOWN\n", isp->isp_name);
    470      1.11   mjacob 		break;
    471      1.11   mjacob         case ISPASYNC_LOOP_UP:
    472      1.11   mjacob 		isp->isp_osinfo.blocked = 0;
    473      1.11   mjacob 		timeout(isp_internal_restart, isp, 1);
    474      1.11   mjacob 		printf("%s: Loop UP\n", isp->isp_name);
    475      1.11   mjacob 		break;
    476  1.12.4.2  thorpej 	case ISPASYNC_PDB_CHANGED:
    477  1.12.4.2  thorpej 	if (IS_FC(isp)) {
    478  1.12.4.2  thorpej 		const char *fmt = "%s: Target %d (Loop 0x%x) Port ID 0x%x "
    479  1.12.4.2  thorpej 		    "role %s %s\n Port WWN 0x%08x%08x\n Node WWN 0x%08x%08x\n";
    480  1.12.4.2  thorpej 		const static char *roles[4] = {
    481      1.11   mjacob 		    "No", "Target", "Initiator", "Target/Initiator"
    482      1.11   mjacob 		};
    483  1.12.4.2  thorpej 		char *ptr;
    484  1.12.4.2  thorpej 		fcparam *fcp = isp->isp_param;
    485  1.12.4.2  thorpej 		int tgt = *((int *) arg);
    486  1.12.4.2  thorpej 		struct lportdb *lp = &fcp->portdb[tgt];
    487  1.12.4.2  thorpej 
    488  1.12.4.2  thorpej 		if (lp->valid) {
    489  1.12.4.2  thorpej 			ptr = "arrived";
    490  1.12.4.2  thorpej 		} else {
    491  1.12.4.2  thorpej 			ptr = "disappeared";
    492      1.11   mjacob 		}
    493  1.12.4.2  thorpej 		printf(fmt, isp->isp_name, tgt, lp->loopid, lp->portid,
    494  1.12.4.2  thorpej 		    roles[lp->roles & 0x3], ptr,
    495  1.12.4.2  thorpej 		    (u_int32_t) (lp->port_wwn >> 32),
    496  1.12.4.2  thorpej 		    (u_int32_t) (lp->port_wwn & 0xffffffffLL),
    497  1.12.4.2  thorpej 		    (u_int32_t) (lp->node_wwn >> 32),
    498  1.12.4.2  thorpej 		    (u_int32_t) (lp->node_wwn & 0xffffffffLL));
    499      1.11   mjacob 		break;
    500      1.11   mjacob 	}
    501  1.12.4.2  thorpej #ifdef	ISP2100_FABRIC
    502      1.11   mjacob 	case ISPASYNC_CHANGE_NOTIFY:
    503      1.11   mjacob 		printf("%s: Name Server Database Changed\n", isp->isp_name);
    504       1.9   mjacob 		break;
    505  1.12.4.2  thorpej 	case ISPASYNC_FABRIC_DEV:
    506  1.12.4.2  thorpej 	{
    507  1.12.4.2  thorpej 		int target;
    508  1.12.4.2  thorpej 		struct lportdb *lp;
    509  1.12.4.2  thorpej 		sns_scrsp_t *resp = (sns_scrsp_t *) arg;
    510  1.12.4.2  thorpej 		u_int32_t portid;
    511  1.12.4.2  thorpej 		u_int64_t wwn;
    512  1.12.4.2  thorpej 		fcparam *fcp = isp->isp_param;
    513  1.12.4.2  thorpej 
    514  1.12.4.2  thorpej 		portid =
    515  1.12.4.2  thorpej 		    (((u_int32_t) resp->snscb_port_id[0]) << 16) |
    516  1.12.4.2  thorpej 		    (((u_int32_t) resp->snscb_port_id[1]) << 8) |
    517  1.12.4.2  thorpej 		    (((u_int32_t) resp->snscb_port_id[2]));
    518  1.12.4.2  thorpej 		wwn =
    519  1.12.4.2  thorpej 		    (((u_int64_t)resp->snscb_portname[0]) << 56) |
    520  1.12.4.2  thorpej 		    (((u_int64_t)resp->snscb_portname[1]) << 48) |
    521  1.12.4.2  thorpej 		    (((u_int64_t)resp->snscb_portname[2]) << 40) |
    522  1.12.4.2  thorpej 		    (((u_int64_t)resp->snscb_portname[3]) << 32) |
    523  1.12.4.2  thorpej 		    (((u_int64_t)resp->snscb_portname[4]) << 24) |
    524  1.12.4.2  thorpej 		    (((u_int64_t)resp->snscb_portname[5]) << 16) |
    525  1.12.4.2  thorpej 		    (((u_int64_t)resp->snscb_portname[6]) <<  8) |
    526  1.12.4.2  thorpej 		    (((u_int64_t)resp->snscb_portname[7]));
    527  1.12.4.2  thorpej 		printf("%s: Fabric Device (Type 0x%x)@PortID 0x%x WWN "
    528  1.12.4.2  thorpej 		    "0x%08x%08x\n", isp->isp_name, resp->snscb_port_type,
    529  1.12.4.2  thorpej 		    portid, ((u_int32_t)(wwn >> 32)),
    530  1.12.4.2  thorpej 		    ((u_int32_t)(wwn & 0xffffffff)));
    531  1.12.4.2  thorpej 		if (resp->snscb_port_type != 2)
    532  1.12.4.2  thorpej 			break;
    533  1.12.4.2  thorpej 		for (target = FC_SNS_ID+1; target < MAX_FC_TARG; target++) {
    534  1.12.4.2  thorpej 			lp = &fcp->portdb[target];
    535  1.12.4.2  thorpej 			if (lp->port_wwn == wwn)
    536  1.12.4.2  thorpej 				break;
    537  1.12.4.2  thorpej 		}
    538  1.12.4.2  thorpej 		if (target < MAX_FC_TARG) {
    539  1.12.4.2  thorpej 			break;
    540  1.12.4.2  thorpej 		}
    541  1.12.4.2  thorpej 		for (target = FC_SNS_ID+1; target < MAX_FC_TARG; target++) {
    542  1.12.4.2  thorpej 			lp = &fcp->portdb[target];
    543  1.12.4.2  thorpej 			if (lp->port_wwn == 0)
    544  1.12.4.2  thorpej 				break;
    545  1.12.4.2  thorpej 		}
    546  1.12.4.2  thorpej 		if (target == MAX_FC_TARG) {
    547  1.12.4.2  thorpej 			printf("%s: no more space for fabric devices\n",
    548  1.12.4.2  thorpej 			    isp->isp_name);
    549  1.12.4.2  thorpej 			return (-1);
    550  1.12.4.2  thorpej 		}
    551  1.12.4.2  thorpej 		lp->port_wwn = lp->node_wwn = wwn;
    552  1.12.4.2  thorpej 		lp->portid = portid;
    553  1.12.4.2  thorpej 		break;
    554  1.12.4.2  thorpej 	}
    555  1.12.4.2  thorpej #endif
    556       1.9   mjacob 	default:
    557       1.9   mjacob 		break;
    558       1.9   mjacob 	}
    559      1.10   mjacob 	(void) splx(s);
    560       1.9   mjacob 	return (0);
    561       1.1   mjacob }
    562