Home | History | Annotate | Line # | Download | only in ic
isp_netbsd.c revision 1.18.2.7
      1  1.18.2.7   bouyer /* $NetBSD: isp_netbsd.c,v 1.18.2.7 2000/12/08 09:12:22 bouyer Exp $ */
      2  1.18.2.6   bouyer /*
      3  1.18.2.6   bouyer  * This driver, which is contained in NetBSD in the files:
      4  1.18.2.6   bouyer  *
      5  1.18.2.6   bouyer  *	sys/dev/ic/isp.c
      6  1.18.2.6   bouyer  *	sys/dev/ic/ic/isp.c
      7  1.18.2.6   bouyer  *	sys/dev/ic/ic/isp_inline.h
      8  1.18.2.6   bouyer  *	sys/dev/ic/ic/isp_netbsd.c
      9  1.18.2.6   bouyer  *	sys/dev/ic/ic/isp_netbsd.h
     10  1.18.2.6   bouyer  *	sys/dev/ic/ic/isp_target.c
     11  1.18.2.6   bouyer  *	sys/dev/ic/ic/isp_target.h
     12  1.18.2.6   bouyer  *	sys/dev/ic/ic/isp_tpublic.h
     13  1.18.2.6   bouyer  *	sys/dev/ic/ic/ispmbox.h
     14  1.18.2.6   bouyer  *	sys/dev/ic/ic/ispreg.h
     15  1.18.2.6   bouyer  *	sys/dev/ic/ic/ispvar.h
     16  1.18.2.6   bouyer  *	sys/microcode/isp/asm_sbus.h
     17  1.18.2.6   bouyer  *	sys/microcode/isp/asm_1040.h
     18  1.18.2.6   bouyer  *	sys/microcode/isp/asm_1080.h
     19  1.18.2.6   bouyer  *	sys/microcode/isp/asm_12160.h
     20  1.18.2.6   bouyer  *	sys/microcode/isp/asm_2100.h
     21  1.18.2.6   bouyer  *	sys/microcode/isp/asm_2200.h
     22  1.18.2.6   bouyer  *	sys/pci/isp_pci.c
     23  1.18.2.6   bouyer  *	sys/sbus/isp_sbus.c
     24  1.18.2.6   bouyer  *
     25  1.18.2.6   bouyer  * Is being actively maintained by Matthew Jacob (mjacob (at) netbsd.org).
     26  1.18.2.6   bouyer  * This driver also is shared source with FreeBSD, OpenBSD, Linux, Solaris,
     27  1.18.2.6   bouyer  * Linux versions. This tends to be an interesting maintenance problem.
     28  1.18.2.6   bouyer  *
     29  1.18.2.6   bouyer  * Please coordinate with Matthew Jacob on changes you wish to make here.
     30  1.18.2.6   bouyer  */
     31       1.1   mjacob /*
     32       1.1   mjacob  * Platform (NetBSD) dependent common attachment code for Qlogic adapters.
     33      1.15   mjacob  * Matthew Jacob <mjacob (at) nas.nasa.gov>
     34      1.15   mjacob  */
     35      1.15   mjacob /*
     36      1.15   mjacob  * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
     37       1.1   mjacob  * All rights reserved.
     38       1.1   mjacob  *
     39       1.1   mjacob  * Redistribution and use in source and binary forms, with or without
     40       1.1   mjacob  * modification, are permitted provided that the following conditions
     41       1.1   mjacob  * are met:
     42       1.1   mjacob  * 1. Redistributions of source code must retain the above copyright
     43      1.15   mjacob  *    notice, this list of conditions and the following disclaimer.
     44       1.1   mjacob  * 2. Redistributions in binary form must reproduce the above copyright
     45       1.1   mjacob  *    notice, this list of conditions and the following disclaimer in the
     46       1.1   mjacob  *    documentation and/or other materials provided with the distribution.
     47       1.1   mjacob  * 3. The name of the author may not be used to endorse or promote products
     48      1.15   mjacob  *    derived from this software without specific prior written permission
     49       1.1   mjacob  *
     50      1.15   mjacob  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     51      1.15   mjacob  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     52      1.15   mjacob  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     53      1.15   mjacob  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     54      1.15   mjacob  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     55      1.15   mjacob  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     56      1.15   mjacob  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     57      1.15   mjacob  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     58      1.15   mjacob  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     59      1.15   mjacob  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     60       1.1   mjacob  */
     61       1.1   mjacob 
     62       1.1   mjacob #include <dev/ic/isp_netbsd.h>
     63      1.17   mjacob #include <sys/scsiio.h>
     64       1.1   mjacob 
     65  1.18.2.6   bouyer 
     66  1.18.2.6   bouyer /*
     67  1.18.2.6   bouyer  * Set a timeout for the watchdogging of a command.
     68  1.18.2.6   bouyer  *
     69  1.18.2.6   bouyer  * The dimensional analysis is
     70  1.18.2.6   bouyer  *
     71  1.18.2.6   bouyer  *	milliseconds * (seconds/millisecond) * (ticks/second) = ticks
     72  1.18.2.6   bouyer  *
     73  1.18.2.6   bouyer  *			=
     74  1.18.2.6   bouyer  *
     75  1.18.2.6   bouyer  *	(milliseconds / 1000) * hz = ticks
     76  1.18.2.6   bouyer  *
     77  1.18.2.6   bouyer  *
     78  1.18.2.6   bouyer  * For timeouts less than 1 second, we'll get zero. Because of this, and
     79  1.18.2.6   bouyer  * because we want to establish *our* timeout to be longer than what the
     80  1.18.2.6   bouyer  * firmware might do, we just add 3 seconds at the back end.
     81  1.18.2.6   bouyer  */
     82  1.18.2.6   bouyer #define	_XT(xs)	((((xs)->timeout/1000) * hz) + (3 * hz))
     83  1.18.2.6   bouyer 
     84       1.1   mjacob static void ispminphys __P((struct buf *));
     85  1.18.2.6   bouyer static int32_t ispcmd __P((XS_T *));
     86      1.17   mjacob static int
     87  1.18.2.6   bouyer ispioctl __P((struct scsipi_link *, u_long, caddr_t, int, struct proc *));
     88       1.1   mjacob 
     89  1.18.2.6   bouyer static struct scsipi_device isp_dev = { NULL, NULL, NULL, NULL };
     90  1.18.2.6   bouyer static int isp_polled_cmd __P((struct ispsoftc *, XS_T *));
     91  1.18.2.6   bouyer static void isp_dog __P((void *));
     92      1.17   mjacob static void isp_command_requeue __P((void *));
     93  1.18.2.6   bouyer static void isp_internal_restart __P((void *));
     94      1.10   mjacob 
     95       1.1   mjacob /*
     96       1.1   mjacob  * Complete attachment of hardware, include subdevices.
     97       1.1   mjacob  */
     98       1.1   mjacob void
     99       1.1   mjacob isp_attach(isp)
    100       1.1   mjacob 	struct ispsoftc *isp;
    101       1.1   mjacob {
    102  1.18.2.6   bouyer 	isp->isp_osinfo._adapter.scsipi_minphys = ispminphys;
    103  1.18.2.6   bouyer 	isp->isp_osinfo._adapter.scsipi_ioctl = ispioctl;
    104  1.18.2.6   bouyer 	isp->isp_osinfo._adapter.scsipi_cmd = ispcmd;
    105       1.6  thorpej 
    106       1.1   mjacob 	isp->isp_state = ISP_RUNSTATE;
    107  1.18.2.6   bouyer 	isp->isp_osinfo._link.scsipi_scsi.channel =
    108  1.18.2.6   bouyer 	    (IS_DUALBUS(isp))? 0 : SCSI_CHANNEL_ONLY_ONE;
    109  1.18.2.6   bouyer 	isp->isp_osinfo._link.adapter_softc = isp;
    110  1.18.2.6   bouyer 	isp->isp_osinfo._link.device = &isp_dev;
    111  1.18.2.6   bouyer 	isp->isp_osinfo._link.adapter = &isp->isp_osinfo._adapter;
    112  1.18.2.6   bouyer 	isp->isp_osinfo._link.openings = isp->isp_maxcmds;
    113  1.18.2.1  thorpej 	/*
    114  1.18.2.6   bouyer 	 * Until the midlayer is fixed to use REPORT LUNS, limit to 8 luns.
    115  1.18.2.1  thorpej 	 */
    116  1.18.2.6   bouyer 	isp->isp_osinfo._link.scsipi_scsi.max_lun =
    117  1.18.2.6   bouyer 	   (isp->isp_maxluns < 7)? isp->isp_maxluns - 1 : 7;
    118  1.18.2.6   bouyer 	TAILQ_INIT(&isp->isp_osinfo.waitq);	/* The 2nd bus will share.. */
    119  1.18.2.6   bouyer 
    120  1.18.2.6   bouyer 	if (IS_FC(isp)) {
    121  1.18.2.6   bouyer 		isp->isp_osinfo._link.scsipi_scsi.max_target = MAX_FC_TARG-1;
    122  1.18.2.6   bouyer 	} else {
    123  1.18.2.6   bouyer 		sdparam *sdp = isp->isp_param;
    124  1.18.2.6   bouyer 		isp->isp_osinfo._link.scsipi_scsi.max_target = MAX_TARGETS-1;
    125  1.18.2.6   bouyer 		isp->isp_osinfo._link.scsipi_scsi.adapter_target =
    126  1.18.2.6   bouyer 		    sdp->isp_initiator_id;
    127  1.18.2.6   bouyer 		isp->isp_osinfo.discovered[0] = 1 << sdp->isp_initiator_id;
    128  1.18.2.6   bouyer 		if (IS_DUALBUS(isp)) {
    129  1.18.2.6   bouyer 			isp->isp_osinfo._link_b = isp->isp_osinfo._link;
    130  1.18.2.6   bouyer 			sdp++;
    131  1.18.2.6   bouyer 			isp->isp_osinfo.discovered[1] =
    132  1.18.2.6   bouyer 			    1 << sdp->isp_initiator_id;
    133  1.18.2.6   bouyer 			isp->isp_osinfo._link_b.scsipi_scsi.adapter_target =
    134  1.18.2.6   bouyer 			    sdp->isp_initiator_id;
    135  1.18.2.6   bouyer 			isp->isp_osinfo._link_b.scsipi_scsi.channel = 1;
    136  1.18.2.6   bouyer 			isp->isp_osinfo._link_b.scsipi_scsi.max_lun =
    137  1.18.2.6   bouyer 			    isp->isp_osinfo._link.scsipi_scsi.max_lun;
    138      1.14   mjacob 		}
    139       1.1   mjacob 	}
    140  1.18.2.6   bouyer 	isp->isp_osinfo._link.type = BUS_SCSI;
    141       1.8   mjacob 
    142       1.8   mjacob 	/*
    143  1.18.2.6   bouyer 	 * Send a SCSI Bus Reset.
    144      1.10   mjacob 	 */
    145      1.14   mjacob 	if (IS_SCSI(isp)) {
    146  1.18.2.6   bouyer 		int bus = 0;
    147  1.18.2.6   bouyer 		ISP_LOCK(isp);
    148  1.18.2.6   bouyer 		(void) isp_control(isp, ISPCTL_RESET_BUS, &bus);
    149  1.18.2.6   bouyer 		if (IS_DUALBUS(isp)) {
    150  1.18.2.6   bouyer 			bus++;
    151  1.18.2.6   bouyer 			(void) isp_control(isp, ISPCTL_RESET_BUS, &bus);
    152  1.18.2.6   bouyer 		}
    153  1.18.2.6   bouyer 		ISP_UNLOCK(isp);
    154  1.18.2.6   bouyer 	} else {
    155  1.18.2.6   bouyer 		int defid;
    156  1.18.2.6   bouyer 		fcparam *fcp = isp->isp_param;
    157  1.18.2.6   bouyer 		delay(2 * 1000000);
    158  1.18.2.6   bouyer 		defid = MAX_FC_TARG;
    159  1.18.2.6   bouyer 		ISP_LOCK(isp);
    160  1.18.2.6   bouyer 		/*
    161  1.18.2.6   bouyer 		 * We probably won't have clock interrupts running,
    162  1.18.2.6   bouyer 		 * so we'll be really short (smoke test, really)
    163  1.18.2.6   bouyer 		 * at this time.
    164  1.18.2.6   bouyer 		 */
    165  1.18.2.6   bouyer 		if (isp_control(isp, ISPCTL_FCLINK_TEST, NULL)) {
    166  1.18.2.6   bouyer 			(void) isp_control(isp, ISPCTL_PDB_SYNC, NULL);
    167  1.18.2.6   bouyer 			if (fcp->isp_fwstate == FW_READY &&
    168  1.18.2.6   bouyer 			    fcp->isp_loopstate >= LOOP_PDB_RCVD) {
    169  1.18.2.6   bouyer 				defid = fcp->isp_loopid;
    170  1.18.2.6   bouyer 			}
    171  1.18.2.6   bouyer 		}
    172  1.18.2.6   bouyer 		ISP_UNLOCK(isp);
    173  1.18.2.6   bouyer 		isp->isp_osinfo._link.scsipi_scsi.adapter_target = defid;
    174      1.11   mjacob 	}
    175      1.10   mjacob 
    176      1.10   mjacob 	/*
    177  1.18.2.6   bouyer 	 * After this point, we'll be doing the new configuration
    178  1.18.2.6   bouyer 	 * schema which allows interrups, so we can do tsleep/wakeup
    179  1.18.2.6   bouyer 	 * for mailbox stuff at that point.
    180       1.8   mjacob 	 */
    181  1.18.2.6   bouyer 	isp->isp_osinfo.no_mbox_ints = 0;
    182       1.8   mjacob 
    183       1.8   mjacob 	/*
    184       1.8   mjacob 	 * And attach children (if any).
    185       1.8   mjacob 	 */
    186  1.18.2.6   bouyer 	config_found((void *)isp, &isp->isp_osinfo._link, scsiprint);
    187  1.18.2.6   bouyer 	if (IS_DUALBUS(isp)) {
    188  1.18.2.6   bouyer 		config_found((void *)isp, &isp->isp_osinfo._link_b, scsiprint);
    189  1.18.2.6   bouyer 	}
    190       1.1   mjacob }
    191       1.1   mjacob 
    192       1.1   mjacob /*
    193       1.1   mjacob  * minphys our xfers
    194       1.1   mjacob  *
    195       1.1   mjacob  * Unfortunately, the buffer pointer describes the target device- not the
    196       1.1   mjacob  * adapter device, so we can't use the pointer to find out what kind of
    197       1.1   mjacob  * adapter we are and adjust accordingly.
    198       1.1   mjacob  */
    199       1.1   mjacob 
    200       1.1   mjacob static void
    201       1.1   mjacob ispminphys(bp)
    202       1.1   mjacob 	struct buf *bp;
    203       1.1   mjacob {
    204       1.1   mjacob 	/*
    205       1.1   mjacob 	 * XX: Only the 1020 has a 24 bit limit.
    206       1.1   mjacob 	 */
    207       1.1   mjacob 	if (bp->b_bcount >= (1 << 24)) {
    208       1.1   mjacob 		bp->b_bcount = (1 << 24);
    209       1.1   mjacob 	}
    210       1.1   mjacob 	minphys(bp);
    211       1.1   mjacob }
    212       1.1   mjacob 
    213      1.17   mjacob static int
    214  1.18.2.6   bouyer ispioctl(sc_link, cmd, addr, flag, p)
    215  1.18.2.6   bouyer 	struct scsipi_link *sc_link;
    216      1.17   mjacob 	u_long cmd;
    217      1.17   mjacob 	caddr_t addr;
    218      1.17   mjacob 	int flag;
    219      1.17   mjacob 	struct proc *p;
    220      1.17   mjacob {
    221  1.18.2.6   bouyer 	struct ispsoftc *isp = sc_link->adapter_softc;
    222  1.18.2.6   bouyer 	int s, chan, retval = ENOTTY;
    223      1.17   mjacob 
    224  1.18.2.6   bouyer 	chan = (sc_link->scsipi_scsi.channel == SCSI_CHANNEL_ONLY_ONE)? 0 :
    225  1.18.2.6   bouyer 	    sc_link->scsipi_scsi.channel;
    226  1.18.2.6   bouyer 
    227      1.17   mjacob 	switch (cmd) {
    228  1.18.2.6   bouyer 	case SCBUSACCEL:
    229  1.18.2.6   bouyer 	{
    230  1.18.2.6   bouyer 		struct scbusaccel_args *sp = (struct scbusaccel_args *)addr;
    231  1.18.2.6   bouyer 		if (IS_SCSI(isp) && sp->sa_lun == 0) {
    232  1.18.2.6   bouyer 			int dflags = 0;
    233  1.18.2.6   bouyer 			sdparam *sdp = SDPARAM(isp);
    234  1.18.2.6   bouyer 
    235  1.18.2.6   bouyer 			sdp += chan;
    236  1.18.2.6   bouyer 			if (sp->sa_flags & SC_ACCEL_TAGS)
    237  1.18.2.6   bouyer 				dflags |= DPARM_TQING;
    238  1.18.2.6   bouyer 			if (sp->sa_flags & SC_ACCEL_WIDE)
    239  1.18.2.6   bouyer 				dflags |= DPARM_WIDE;
    240  1.18.2.6   bouyer 			if (sp->sa_flags & SC_ACCEL_SYNC)
    241  1.18.2.6   bouyer 				dflags |= DPARM_SYNC;
    242  1.18.2.6   bouyer 			s = splbio();
    243  1.18.2.6   bouyer 			sdp->isp_devparam[sp->sa_target].dev_flags |= dflags;
    244  1.18.2.6   bouyer 			dflags = sdp->isp_devparam[sp->sa_target].dev_flags;
    245  1.18.2.6   bouyer 			sdp->isp_devparam[sp->sa_target].dev_update = 1;
    246  1.18.2.6   bouyer 			isp->isp_update |= (1 << chan);
    247  1.18.2.6   bouyer 			splx(s);
    248  1.18.2.6   bouyer 			isp_prt(isp, ISP_LOGDEBUG1,
    249  1.18.2.6   bouyer 			    "ispioctl: device flags 0x%x for %d.%d.X",
    250  1.18.2.6   bouyer 			    dflags, chan, sp->sa_target);
    251  1.18.2.6   bouyer 		}
    252  1.18.2.6   bouyer 		retval = 0;
    253  1.18.2.6   bouyer 		break;
    254  1.18.2.6   bouyer 	}
    255      1.17   mjacob 	case SCBUSIORESET:
    256      1.17   mjacob 		s = splbio();
    257  1.18.2.6   bouyer 		if (isp_control(isp, ISPCTL_RESET_BUS, &chan))
    258      1.17   mjacob 			retval = EIO;
    259      1.17   mjacob 		else
    260      1.17   mjacob 			retval = 0;
    261      1.17   mjacob 		(void) splx(s);
    262      1.17   mjacob 		break;
    263      1.17   mjacob 	default:
    264      1.17   mjacob 		break;
    265       1.3   mjacob 	}
    266      1.17   mjacob 	return (retval);
    267      1.17   mjacob }
    268      1.17   mjacob 
    269  1.18.2.6   bouyer 
    270  1.18.2.6   bouyer static int32_t
    271  1.18.2.6   bouyer ispcmd(xs)
    272  1.18.2.6   bouyer 	XS_T *xs;
    273      1.17   mjacob {
    274  1.18.2.6   bouyer 	struct ispsoftc *isp;
    275      1.17   mjacob 	int result, s;
    276      1.11   mjacob 
    277  1.18.2.6   bouyer 	isp = XS_ISP(xs);
    278  1.18.2.6   bouyer 	s = splbio();
    279  1.18.2.6   bouyer 	if (isp->isp_state < ISP_RUNSTATE) {
    280  1.18.2.1  thorpej 		DISABLE_INTS(isp);
    281  1.18.2.6   bouyer 		isp_init(isp);
    282  1.18.2.6   bouyer                 if (isp->isp_state != ISP_INITSTATE) {
    283  1.18.2.6   bouyer 			ENABLE_INTS(isp);
    284  1.18.2.6   bouyer                         (void) splx(s);
    285  1.18.2.6   bouyer                         XS_SETERR(xs, HBA_BOTCH);
    286  1.18.2.6   bouyer                         return (COMPLETE);
    287  1.18.2.6   bouyer                 }
    288  1.18.2.6   bouyer                 isp->isp_state = ISP_RUNSTATE;
    289  1.18.2.1  thorpej 		ENABLE_INTS(isp);
    290  1.18.2.6   bouyer         }
    291  1.18.2.1  thorpej 
    292  1.18.2.6   bouyer 	/*
    293  1.18.2.6   bouyer 	 * Check for queue blockage...
    294  1.18.2.6   bouyer 	 */
    295  1.18.2.6   bouyer 	if (isp->isp_osinfo.blocked) {
    296  1.18.2.6   bouyer 		if (xs->xs_control & XS_CTL_POLL) {
    297  1.18.2.6   bouyer 			xs->error = XS_DRIVER_STUFFUP;
    298  1.18.2.6   bouyer 			splx(s);
    299  1.18.2.6   bouyer 			return (TRY_AGAIN_LATER);
    300  1.18.2.6   bouyer 		}
    301  1.18.2.6   bouyer 		TAILQ_INSERT_TAIL(&isp->isp_osinfo.waitq, xs, adapter_q);
    302  1.18.2.6   bouyer 		splx(s);
    303  1.18.2.6   bouyer 		return (SUCCESSFULLY_QUEUED);
    304  1.18.2.6   bouyer 	}
    305  1.18.2.6   bouyer 
    306  1.18.2.6   bouyer 	if (xs->xs_control & XS_CTL_POLL) {
    307  1.18.2.6   bouyer 		volatile u_int8_t ombi = isp->isp_osinfo.no_mbox_ints;
    308  1.18.2.6   bouyer 		isp->isp_osinfo.no_mbox_ints = 1;
    309  1.18.2.6   bouyer 		result = isp_polled_cmd(isp, xs);
    310  1.18.2.6   bouyer 		isp->isp_osinfo.no_mbox_ints = ombi;
    311  1.18.2.6   bouyer 		(void) splx(s);
    312  1.18.2.6   bouyer 		return (result);
    313  1.18.2.6   bouyer 	}
    314  1.18.2.1  thorpej 
    315  1.18.2.6   bouyer 	result = isp_start(xs);
    316  1.18.2.6   bouyer #if	0
    317  1.18.2.6   bouyer {
    318  1.18.2.6   bouyer 	static int na[16] = { 0 };
    319  1.18.2.6   bouyer 	if (na[isp->isp_unit] < isp->isp_nactive) {
    320  1.18.2.6   bouyer 		isp_prt(isp, ISP_LOGALL, "active hiwater %d", isp->isp_nactive);
    321  1.18.2.6   bouyer 		na[isp->isp_unit] = isp->isp_nactive;
    322  1.18.2.6   bouyer 	}
    323  1.18.2.6   bouyer }
    324  1.18.2.6   bouyer #endif
    325  1.18.2.6   bouyer 	switch (result) {
    326  1.18.2.6   bouyer 	case CMD_QUEUED:
    327  1.18.2.6   bouyer 		result = SUCCESSFULLY_QUEUED;
    328  1.18.2.6   bouyer 		if (xs->timeout) {
    329  1.18.2.6   bouyer 			callout_reset(&xs->xs_callout, _XT(xs), isp_dog, xs);
    330  1.18.2.6   bouyer 		}
    331  1.18.2.6   bouyer 		break;
    332  1.18.2.6   bouyer 	case CMD_EAGAIN:
    333  1.18.2.6   bouyer 		result = TRY_AGAIN_LATER;
    334  1.18.2.6   bouyer 		break;
    335  1.18.2.6   bouyer 	case CMD_RQLATER:
    336  1.18.2.6   bouyer 		result = SUCCESSFULLY_QUEUED;
    337  1.18.2.6   bouyer 		callout_reset(&xs->xs_callout, hz, isp_command_requeue, xs);
    338  1.18.2.6   bouyer 		break;
    339  1.18.2.6   bouyer 	case CMD_COMPLETE:
    340  1.18.2.6   bouyer 		result = COMPLETE;
    341  1.18.2.6   bouyer 		break;
    342  1.18.2.6   bouyer 	}
    343  1.18.2.6   bouyer 	(void) splx(s);
    344  1.18.2.6   bouyer 	return (result);
    345  1.18.2.6   bouyer }
    346  1.18.2.1  thorpej 
    347  1.18.2.6   bouyer static int
    348  1.18.2.6   bouyer isp_polled_cmd(isp, xs)
    349  1.18.2.6   bouyer 	struct ispsoftc *isp;
    350  1.18.2.6   bouyer 	XS_T *xs;
    351  1.18.2.6   bouyer {
    352  1.18.2.6   bouyer 	int result;
    353  1.18.2.6   bouyer 	int infinite = 0, mswait;
    354  1.18.2.1  thorpej 
    355  1.18.2.6   bouyer 	result = isp_start(xs);
    356  1.18.2.6   bouyer 
    357  1.18.2.6   bouyer 	switch (result) {
    358  1.18.2.6   bouyer 	case CMD_QUEUED:
    359  1.18.2.6   bouyer 		result = SUCCESSFULLY_QUEUED;
    360  1.18.2.6   bouyer 		break;
    361  1.18.2.6   bouyer 	case CMD_RQLATER:
    362  1.18.2.6   bouyer 	case CMD_EAGAIN:
    363  1.18.2.6   bouyer 		if (XS_NOERR(xs)) {
    364  1.18.2.6   bouyer 			xs->error = XS_DRIVER_STUFFUP;
    365      1.17   mjacob 		}
    366  1.18.2.6   bouyer 		result = TRY_AGAIN_LATER;
    367  1.18.2.6   bouyer 		break;
    368  1.18.2.6   bouyer 	case CMD_COMPLETE:
    369  1.18.2.6   bouyer 		result = COMPLETE;
    370  1.18.2.6   bouyer 		break;
    371  1.18.2.6   bouyer 
    372  1.18.2.6   bouyer 	}
    373       1.1   mjacob 
    374  1.18.2.6   bouyer 	if (result != SUCCESSFULLY_QUEUED) {
    375  1.18.2.6   bouyer 		return (result);
    376  1.18.2.6   bouyer 	}
    377  1.18.2.6   bouyer 
    378  1.18.2.6   bouyer 	/*
    379  1.18.2.6   bouyer 	 * If we can't use interrupts, poll on completion.
    380  1.18.2.6   bouyer 	 */
    381  1.18.2.6   bouyer 	if ((mswait = XS_TIME(xs)) == 0)
    382  1.18.2.6   bouyer 		infinite = 1;
    383  1.18.2.6   bouyer 
    384  1.18.2.6   bouyer 	while (mswait || infinite) {
    385  1.18.2.6   bouyer 		if (isp_intr((void *)isp)) {
    386  1.18.2.6   bouyer 			if (XS_CMD_DONE_P(xs)) {
    387  1.18.2.6   bouyer 				break;
    388       1.1   mjacob 			}
    389       1.1   mjacob 		}
    390  1.18.2.6   bouyer 		USEC_DELAY(1000);
    391  1.18.2.6   bouyer 		mswait -= 1;
    392  1.18.2.6   bouyer 	}
    393  1.18.2.1  thorpej 
    394  1.18.2.6   bouyer 	/*
    395  1.18.2.6   bouyer 	 * If no other error occurred but we didn't finish,
    396  1.18.2.6   bouyer 	 * something bad happened.
    397  1.18.2.6   bouyer 	 */
    398  1.18.2.6   bouyer 	if (XS_CMD_DONE_P(xs) == 0) {
    399  1.18.2.6   bouyer 		if (isp_control(isp, ISPCTL_ABORT_CMD, xs)) {
    400  1.18.2.6   bouyer 			isp_reinit(isp);
    401  1.18.2.6   bouyer 		}
    402  1.18.2.6   bouyer 		if (XS_NOERR(xs)) {
    403  1.18.2.6   bouyer 			XS_SETERR(xs, HBA_BOTCH);
    404  1.18.2.1  thorpej 		}
    405       1.1   mjacob 	}
    406  1.18.2.6   bouyer 	result = COMPLETE;
    407  1.18.2.6   bouyer 	return (result);
    408       1.1   mjacob }
    409       1.1   mjacob 
    410  1.18.2.6   bouyer void
    411  1.18.2.6   bouyer isp_done(xs)
    412  1.18.2.6   bouyer 	XS_T *xs;
    413       1.1   mjacob {
    414  1.18.2.6   bouyer 	XS_CMD_S_DONE(xs);
    415  1.18.2.6   bouyer 	if (XS_CMD_WDOG_P(xs) == 0) {
    416  1.18.2.6   bouyer 		struct ispsoftc *isp = XS_ISP(xs);
    417  1.18.2.6   bouyer 		callout_stop(&xs->xs_callout);
    418  1.18.2.6   bouyer 		if (XS_CMD_GRACE_P(xs)) {
    419  1.18.2.6   bouyer 			isp_prt(isp, ISP_LOGDEBUG1,
    420  1.18.2.6   bouyer 			    "finished command on borrowed time");
    421       1.1   mjacob 		}
    422  1.18.2.6   bouyer 		XS_CMD_S_CLEAR(xs);
    423  1.18.2.6   bouyer 		scsipi_done(xs);
    424       1.1   mjacob 	}
    425       1.8   mjacob }
    426       1.8   mjacob 
    427       1.8   mjacob static void
    428  1.18.2.6   bouyer isp_dog(arg)
    429       1.8   mjacob 	void *arg;
    430       1.8   mjacob {
    431  1.18.2.6   bouyer 	XS_T *xs = arg;
    432  1.18.2.6   bouyer 	struct ispsoftc *isp = XS_ISP(xs);
    433  1.18.2.6   bouyer 	u_int32_t handle;
    434       1.8   mjacob 
    435  1.18.2.6   bouyer 	ISP_ILOCK(isp);
    436       1.8   mjacob 	/*
    437  1.18.2.6   bouyer 	 * We've decided this command is dead. Make sure we're not trying
    438  1.18.2.6   bouyer 	 * to kill a command that's already dead by getting it's handle and
    439  1.18.2.6   bouyer 	 * and seeing whether it's still alive.
    440       1.8   mjacob 	 */
    441  1.18.2.6   bouyer 	handle = isp_find_handle(isp, xs);
    442  1.18.2.6   bouyer 	if (handle) {
    443  1.18.2.6   bouyer 		u_int16_t r, r1, i;
    444  1.18.2.6   bouyer 
    445  1.18.2.6   bouyer 		if (XS_CMD_DONE_P(xs)) {
    446  1.18.2.6   bouyer 			isp_prt(isp, ISP_LOGDEBUG1,
    447  1.18.2.6   bouyer 			    "watchdog found done cmd (handle 0x%x)", handle);
    448  1.18.2.6   bouyer 			ISP_IUNLOCK(isp);
    449  1.18.2.6   bouyer 			return;
    450       1.8   mjacob 		}
    451  1.18.2.6   bouyer 
    452  1.18.2.6   bouyer 		if (XS_CMD_WDOG_P(xs)) {
    453  1.18.2.6   bouyer 			isp_prt(isp, ISP_LOGDEBUG1,
    454  1.18.2.6   bouyer 			    "recursive watchdog (handle 0x%x)", handle);
    455  1.18.2.6   bouyer 			ISP_IUNLOCK(isp);
    456  1.18.2.6   bouyer 			return;
    457       1.8   mjacob 		}
    458  1.18.2.6   bouyer 
    459  1.18.2.6   bouyer 		XS_CMD_S_WDOG(xs);
    460  1.18.2.6   bouyer 
    461  1.18.2.6   bouyer 		i = 0;
    462  1.18.2.6   bouyer 		do {
    463  1.18.2.6   bouyer 			r = ISP_READ(isp, BIU_ISR);
    464  1.18.2.6   bouyer 			USEC_DELAY(1);
    465  1.18.2.6   bouyer 			r1 = ISP_READ(isp, BIU_ISR);
    466  1.18.2.6   bouyer 		} while (r != r1 && ++i < 1000);
    467  1.18.2.6   bouyer 
    468  1.18.2.6   bouyer 		if (INT_PENDING(isp, r) && isp_intr(isp) && XS_CMD_DONE_P(xs)) {
    469  1.18.2.6   bouyer 			isp_prt(isp, ISP_LOGDEBUG1, "watchdog cleanup (%x, %x)",
    470  1.18.2.6   bouyer 			    handle, r);
    471  1.18.2.6   bouyer 			XS_CMD_C_WDOG(xs);
    472  1.18.2.6   bouyer 			isp_done(xs);
    473  1.18.2.6   bouyer 		} else if (XS_CMD_GRACE_P(xs)) {
    474  1.18.2.6   bouyer 			isp_prt(isp, ISP_LOGDEBUG1, "watchdog timeout (%x, %x)",
    475  1.18.2.6   bouyer 			    handle, r);
    476  1.18.2.6   bouyer 			/*
    477  1.18.2.6   bouyer 			 * Make sure the command is *really* dead before we
    478  1.18.2.6   bouyer 			 * release the handle (and DMA resources) for reuse.
    479  1.18.2.6   bouyer 			 */
    480  1.18.2.6   bouyer 			(void) isp_control(isp, ISPCTL_ABORT_CMD, arg);
    481  1.18.2.6   bouyer 
    482  1.18.2.6   bouyer 			/*
    483  1.18.2.6   bouyer 			 * After this point, the comamnd is really dead.
    484  1.18.2.6   bouyer 			 */
    485  1.18.2.6   bouyer 			if (XS_XFRLEN(xs)) {
    486  1.18.2.6   bouyer 				ISP_DMAFREE(isp, xs, handle);
    487  1.18.2.6   bouyer 			}
    488  1.18.2.6   bouyer 			isp_destroy_handle(isp, handle);
    489  1.18.2.6   bouyer 			XS_SETERR(xs, XS_TIMEOUT);
    490  1.18.2.6   bouyer 			XS_CMD_S_CLEAR(xs);
    491  1.18.2.6   bouyer 			isp_done(xs);
    492  1.18.2.6   bouyer 		} else {
    493  1.18.2.6   bouyer 			u_int16_t iptr, optr;
    494  1.18.2.6   bouyer 			ispreq_t *mp;
    495  1.18.2.6   bouyer 			isp_prt(isp, ISP_LOGDEBUG2,
    496  1.18.2.6   bouyer 			    "possible command timeout (%x, %x)", handle, r);
    497  1.18.2.6   bouyer 			XS_CMD_C_WDOG(xs);
    498  1.18.2.6   bouyer 			callout_reset(&xs->xs_callout, hz, isp_dog, xs);
    499  1.18.2.6   bouyer 			if (isp_getrqentry(isp, &iptr, &optr, (void **) &mp)) {
    500  1.18.2.6   bouyer 				ISP_IUNLOCK(isp);
    501  1.18.2.6   bouyer 				return;
    502  1.18.2.6   bouyer 			}
    503  1.18.2.6   bouyer 			XS_CMD_S_GRACE(xs);
    504  1.18.2.6   bouyer 			MEMZERO((void *) mp, sizeof (*mp));
    505  1.18.2.6   bouyer 			mp->req_header.rqs_entry_count = 1;
    506  1.18.2.6   bouyer 			mp->req_header.rqs_entry_type = RQSTYPE_MARKER;
    507  1.18.2.6   bouyer 			mp->req_modifier = SYNC_ALL;
    508  1.18.2.6   bouyer 			mp->req_target = XS_CHANNEL(xs) << 7;
    509  1.18.2.6   bouyer 			ISP_SWIZZLE_REQUEST(isp, mp);
    510  1.18.2.6   bouyer 			ISP_ADD_REQUEST(isp, iptr);
    511       1.8   mjacob 		}
    512  1.18.2.6   bouyer 	} else {
    513  1.18.2.6   bouyer 		isp_prt(isp, ISP_LOGDEBUG0, "watchdog with no command");
    514       1.8   mjacob 	}
    515  1.18.2.6   bouyer 	ISP_IUNLOCK(isp);
    516       1.8   mjacob }
    517       1.8   mjacob 
    518       1.8   mjacob /*
    519       1.8   mjacob  * Free any associated resources prior to decommissioning and
    520       1.8   mjacob  * set the card to a known state (so it doesn't wake up and kick
    521       1.8   mjacob  * us when we aren't expecting it to).
    522       1.8   mjacob  *
    523       1.8   mjacob  * Locks are held before coming here.
    524       1.8   mjacob  */
    525       1.8   mjacob void
    526       1.8   mjacob isp_uninit(isp)
    527       1.8   mjacob 	struct ispsoftc *isp;
    528       1.8   mjacob {
    529  1.18.2.6   bouyer 	isp_lock(isp);
    530       1.8   mjacob 	/*
    531       1.8   mjacob 	 * Leave with interrupts disabled.
    532       1.8   mjacob 	 */
    533       1.8   mjacob 	DISABLE_INTS(isp);
    534  1.18.2.6   bouyer 	isp_unlock(isp);
    535       1.9   mjacob }
    536       1.9   mjacob 
    537      1.10   mjacob /*
    538      1.17   mjacob  * Restart function for a command to be requeued later.
    539      1.17   mjacob  */
    540      1.17   mjacob static void
    541      1.17   mjacob isp_command_requeue(arg)
    542      1.17   mjacob 	void *arg;
    543      1.17   mjacob {
    544      1.17   mjacob 	struct scsipi_xfer *xs = arg;
    545  1.18.2.6   bouyer 	struct ispsoftc *isp = XS_ISP(xs);
    546  1.18.2.6   bouyer 	ISP_ILOCK(isp);
    547  1.18.2.6   bouyer 	switch (ispcmd(xs)) {
    548  1.18.2.6   bouyer 	case SUCCESSFULLY_QUEUED:
    549  1.18.2.6   bouyer 		isp_prt(isp, ISP_LOGINFO,
    550  1.18.2.6   bouyer 		    "requeued commands for %d.%d", XS_TGT(xs), XS_LUN(xs));
    551  1.18.2.6   bouyer 		if (xs->timeout) {
    552  1.18.2.6   bouyer 			callout_reset(&xs->xs_callout, _XT(xs), isp_dog, xs);
    553  1.18.2.6   bouyer 		}
    554  1.18.2.6   bouyer 		break;
    555  1.18.2.6   bouyer 	case TRY_AGAIN_LATER:
    556  1.18.2.6   bouyer 		isp_prt(isp, ISP_LOGINFO,
    557  1.18.2.6   bouyer 		    "EAGAIN on requeue for %d.%d", XS_TGT(xs), XS_LUN(xs));
    558  1.18.2.6   bouyer 		callout_reset(&xs->xs_callout, hz, isp_command_requeue, xs);
    559  1.18.2.6   bouyer 		break;
    560  1.18.2.6   bouyer 	case COMPLETE:
    561  1.18.2.6   bouyer 		/* can only be an error */
    562  1.18.2.6   bouyer 		XS_CMD_S_DONE(xs);
    563  1.18.2.6   bouyer 		callout_stop(&xs->xs_callout);
    564  1.18.2.6   bouyer 		if (XS_NOERR(xs)) {
    565  1.18.2.6   bouyer 			XS_SETERR(xs, HBA_BOTCH);
    566  1.18.2.6   bouyer 		}
    567  1.18.2.6   bouyer 		scsipi_done(xs);
    568  1.18.2.6   bouyer 		break;
    569  1.18.2.6   bouyer 	}
    570  1.18.2.6   bouyer 	ISP_IUNLOCK(isp);
    571  1.18.2.6   bouyer }
    572  1.18.2.1  thorpej 
    573  1.18.2.6   bouyer /*
    574  1.18.2.6   bouyer  * Restart function after a LOOP UP event (e.g.),
    575  1.18.2.6   bouyer  * done as a timeout for some hysteresis.
    576  1.18.2.6   bouyer  */
    577  1.18.2.6   bouyer static void
    578  1.18.2.6   bouyer isp_internal_restart(arg)
    579  1.18.2.6   bouyer 	void *arg;
    580  1.18.2.6   bouyer {
    581  1.18.2.6   bouyer 	struct ispsoftc *isp = arg;
    582  1.18.2.6   bouyer 	int result, nrestarted = 0;
    583  1.18.2.6   bouyer 
    584  1.18.2.6   bouyer 	ISP_ILOCK(isp);
    585  1.18.2.6   bouyer 	if (isp->isp_osinfo.blocked == 0) {
    586  1.18.2.6   bouyer 		struct scsipi_xfer *xs;
    587  1.18.2.6   bouyer 		while ((xs = TAILQ_FIRST(&isp->isp_osinfo.waitq)) != NULL) {
    588  1.18.2.6   bouyer 			TAILQ_REMOVE(&isp->isp_osinfo.waitq, xs, adapter_q);
    589  1.18.2.6   bouyer 			result = isp_start(xs);
    590  1.18.2.6   bouyer 			if (result != CMD_QUEUED) {
    591  1.18.2.6   bouyer 				isp_prt(isp, ISP_LOGERR,
    592  1.18.2.6   bouyer 				    "botched command restart (err=%d)", result);
    593  1.18.2.6   bouyer 				XS_CMD_S_DONE(xs);
    594  1.18.2.6   bouyer 				if (xs->error == XS_NOERROR)
    595  1.18.2.6   bouyer 					xs->error = XS_DRIVER_STUFFUP;
    596  1.18.2.6   bouyer 				callout_stop(&xs->xs_callout);
    597  1.18.2.6   bouyer 				scsipi_done(xs);
    598  1.18.2.6   bouyer 			} else if (xs->timeout) {
    599  1.18.2.6   bouyer 				callout_reset(&xs->xs_callout,
    600  1.18.2.6   bouyer 				    _XT(xs), isp_dog, xs);
    601  1.18.2.6   bouyer 			}
    602  1.18.2.6   bouyer 			nrestarted++;
    603  1.18.2.6   bouyer 		}
    604  1.18.2.6   bouyer 		isp_prt(isp, ISP_LOGINFO,
    605  1.18.2.6   bouyer 		    "isp_restart requeued %d commands", nrestarted);
    606  1.18.2.6   bouyer 	}
    607  1.18.2.6   bouyer 	ISP_IUNLOCK(isp);
    608      1.17   mjacob }
    609      1.18   mjacob 
    610       1.9   mjacob int
    611       1.9   mjacob isp_async(isp, cmd, arg)
    612       1.9   mjacob 	struct ispsoftc *isp;
    613       1.9   mjacob 	ispasync_t cmd;
    614       1.9   mjacob 	void *arg;
    615       1.9   mjacob {
    616  1.18.2.3  thorpej 	int bus, tgt;
    617      1.10   mjacob 	int s = splbio();
    618       1.9   mjacob 	switch (cmd) {
    619  1.18.2.5  thorpej 	case ISPASYNC_NEW_TGT_PARAMS:
    620  1.18.2.6   bouyer 	if (IS_SCSI(isp) && isp->isp_dblev) {
    621  1.18.2.5  thorpej 		sdparam *sdp = isp->isp_param;
    622  1.18.2.6   bouyer 		char *wt;
    623  1.18.2.6   bouyer 		int mhz, flags, period;
    624  1.18.2.3  thorpej 
    625  1.18.2.3  thorpej 		tgt = *((int *) arg);
    626  1.18.2.3  thorpej 		bus = (tgt >> 16) & 0xffff;
    627  1.18.2.3  thorpej 		tgt &= 0xffff;
    628  1.18.2.6   bouyer 		sdp += bus;
    629  1.18.2.5  thorpej 		flags = sdp->isp_devparam[tgt].cur_dflags;
    630  1.18.2.6   bouyer 		period = sdp->isp_devparam[tgt].cur_period;
    631  1.18.2.5  thorpej 
    632  1.18.2.6   bouyer 		if ((flags & DPARM_SYNC) && period &&
    633  1.18.2.6   bouyer 		    (sdp->isp_devparam[tgt].cur_offset) != 0) {
    634  1.18.2.6   bouyer 			/*
    635  1.18.2.6   bouyer 			 * There's some ambiguity about our negotiated speed
    636  1.18.2.6   bouyer 			 * if we haven't detected LVD mode correctly (which
    637  1.18.2.6   bouyer 			 * seems to happen, unfortunately). If we're in LVD
    638  1.18.2.6   bouyer 			 * mode, then different rules apply about speed.
    639  1.18.2.6   bouyer 			 */
    640  1.18.2.6   bouyer 			if (sdp->isp_lvdmode || period < 0xc) {
    641  1.18.2.6   bouyer 				switch (period) {
    642  1.18.2.6   bouyer 				case 0x9:
    643  1.18.2.6   bouyer 					mhz = 80;
    644  1.18.2.6   bouyer 					break;
    645  1.18.2.6   bouyer 				case 0xa:
    646  1.18.2.6   bouyer 					mhz = 40;
    647  1.18.2.6   bouyer 					break;
    648  1.18.2.6   bouyer 				case 0xb:
    649  1.18.2.6   bouyer 					mhz = 33;
    650  1.18.2.6   bouyer 					break;
    651  1.18.2.6   bouyer 				case 0xc:
    652  1.18.2.6   bouyer 					mhz = 25;
    653  1.18.2.6   bouyer 					break;
    654  1.18.2.6   bouyer 				default:
    655  1.18.2.6   bouyer 					mhz = 1000 / (period * 4);
    656  1.18.2.6   bouyer 					break;
    657  1.18.2.6   bouyer 				}
    658  1.18.2.6   bouyer 			} else {
    659  1.18.2.6   bouyer 				mhz = 1000 / (period * 4);
    660  1.18.2.6   bouyer 			}
    661  1.18.2.6   bouyer 		} else {
    662  1.18.2.6   bouyer 			mhz = 0;
    663  1.18.2.6   bouyer 		}
    664  1.18.2.6   bouyer 		switch (flags & (DPARM_WIDE|DPARM_TQING)) {
    665  1.18.2.6   bouyer 		case DPARM_WIDE:
    666  1.18.2.6   bouyer 			wt = ", 16 bit wide";
    667  1.18.2.6   bouyer 			break;
    668  1.18.2.6   bouyer 		case DPARM_TQING:
    669  1.18.2.6   bouyer 			wt = ", Tagged Queueing Enabled";
    670  1.18.2.6   bouyer 			break;
    671  1.18.2.6   bouyer 		case DPARM_WIDE|DPARM_TQING:
    672  1.18.2.6   bouyer 			wt = ", 16 bit wide, Tagged Queueing Enabled";
    673  1.18.2.6   bouyer 			break;
    674  1.18.2.6   bouyer 		default:
    675  1.18.2.6   bouyer 			wt = " ";
    676  1.18.2.6   bouyer 			break;
    677  1.18.2.6   bouyer 		}
    678  1.18.2.6   bouyer 		if (mhz) {
    679  1.18.2.6   bouyer 			isp_prt(isp, ISP_LOGINFO,
    680  1.18.2.6   bouyer 			    "Bus %d Target %d at %dMHz Max Offset %d%s",
    681  1.18.2.6   bouyer 			    bus, tgt, mhz, sdp->isp_devparam[tgt].cur_offset,
    682  1.18.2.6   bouyer 			    wt);
    683  1.18.2.6   bouyer 		} else {
    684  1.18.2.6   bouyer 			isp_prt(isp, ISP_LOGINFO,
    685  1.18.2.6   bouyer 			    "Bus %d Target %d Async Mode%s", bus, tgt, wt);
    686  1.18.2.6   bouyer 		}
    687      1.11   mjacob 		break;
    688  1.18.2.3  thorpej 	}
    689      1.11   mjacob 	case ISPASYNC_BUS_RESET:
    690      1.14   mjacob 		if (arg)
    691      1.14   mjacob 			bus = *((int *) arg);
    692      1.14   mjacob 		else
    693      1.14   mjacob 			bus = 0;
    694  1.18.2.6   bouyer 		isp_prt(isp, ISP_LOGINFO, "SCSI bus %d reset detected", bus);
    695      1.11   mjacob 		break;
    696      1.11   mjacob 	case ISPASYNC_LOOP_DOWN:
    697      1.11   mjacob 		/*
    698      1.11   mjacob 		 * Hopefully we get here in time to minimize the number
    699      1.11   mjacob 		 * of commands we are firing off that are sure to die.
    700      1.11   mjacob 		 */
    701  1.18.2.6   bouyer 		isp->isp_osinfo.blocked = 1;
    702  1.18.2.6   bouyer 		isp_prt(isp, ISP_LOGINFO, "Loop DOWN");
    703      1.11   mjacob 		break;
    704      1.11   mjacob         case ISPASYNC_LOOP_UP:
    705  1.18.2.6   bouyer 		isp->isp_osinfo.blocked = 0;
    706  1.18.2.6   bouyer 		callout_reset(&isp->isp_osinfo._restart, 1,
    707  1.18.2.6   bouyer 		    isp_internal_restart, isp);
    708  1.18.2.6   bouyer 		isp_prt(isp, ISP_LOGINFO, "Loop UP");
    709      1.11   mjacob 		break;
    710      1.15   mjacob 	case ISPASYNC_PDB_CHANGED:
    711      1.17   mjacob 	if (IS_FC(isp) && isp->isp_dblev) {
    712  1.18.2.6   bouyer 		const char *fmt = "Target %d (Loop 0x%x) Port ID 0x%x "
    713  1.18.2.6   bouyer 		    "role %s %s\n Port WWN 0x%08x%08x\n Node WWN 0x%08x%08x";
    714      1.15   mjacob 		const static char *roles[4] = {
    715      1.11   mjacob 		    "No", "Target", "Initiator", "Target/Initiator"
    716      1.11   mjacob 		};
    717      1.15   mjacob 		char *ptr;
    718      1.15   mjacob 		fcparam *fcp = isp->isp_param;
    719      1.15   mjacob 		int tgt = *((int *) arg);
    720      1.15   mjacob 		struct lportdb *lp = &fcp->portdb[tgt];
    721      1.15   mjacob 
    722      1.15   mjacob 		if (lp->valid) {
    723      1.15   mjacob 			ptr = "arrived";
    724      1.15   mjacob 		} else {
    725      1.15   mjacob 			ptr = "disappeared";
    726      1.11   mjacob 		}
    727  1.18.2.6   bouyer 		isp_prt(isp, ISP_LOGINFO, fmt, tgt, lp->loopid, lp->portid,
    728      1.15   mjacob 		    roles[lp->roles & 0x3], ptr,
    729      1.15   mjacob 		    (u_int32_t) (lp->port_wwn >> 32),
    730      1.15   mjacob 		    (u_int32_t) (lp->port_wwn & 0xffffffffLL),
    731      1.15   mjacob 		    (u_int32_t) (lp->node_wwn >> 32),
    732      1.15   mjacob 		    (u_int32_t) (lp->node_wwn & 0xffffffffLL));
    733      1.11   mjacob 		break;
    734      1.11   mjacob 	}
    735      1.15   mjacob #ifdef	ISP2100_FABRIC
    736      1.11   mjacob 	case ISPASYNC_CHANGE_NOTIFY:
    737  1.18.2.6   bouyer 		isp_prt(isp, ISP_LOGINFO, "Name Server Database Changed");
    738       1.9   mjacob 		break;
    739      1.15   mjacob 	case ISPASYNC_FABRIC_DEV:
    740      1.15   mjacob 	{
    741      1.15   mjacob 		int target;
    742      1.15   mjacob 		struct lportdb *lp;
    743      1.15   mjacob 		sns_scrsp_t *resp = (sns_scrsp_t *) arg;
    744      1.15   mjacob 		u_int32_t portid;
    745      1.15   mjacob 		u_int64_t wwn;
    746      1.15   mjacob 		fcparam *fcp = isp->isp_param;
    747      1.15   mjacob 
    748      1.15   mjacob 		portid =
    749      1.15   mjacob 		    (((u_int32_t) resp->snscb_port_id[0]) << 16) |
    750      1.15   mjacob 		    (((u_int32_t) resp->snscb_port_id[1]) << 8) |
    751      1.15   mjacob 		    (((u_int32_t) resp->snscb_port_id[2]));
    752      1.15   mjacob 		wwn =
    753      1.15   mjacob 		    (((u_int64_t)resp->snscb_portname[0]) << 56) |
    754      1.15   mjacob 		    (((u_int64_t)resp->snscb_portname[1]) << 48) |
    755      1.15   mjacob 		    (((u_int64_t)resp->snscb_portname[2]) << 40) |
    756      1.15   mjacob 		    (((u_int64_t)resp->snscb_portname[3]) << 32) |
    757      1.15   mjacob 		    (((u_int64_t)resp->snscb_portname[4]) << 24) |
    758      1.15   mjacob 		    (((u_int64_t)resp->snscb_portname[5]) << 16) |
    759      1.15   mjacob 		    (((u_int64_t)resp->snscb_portname[6]) <<  8) |
    760      1.15   mjacob 		    (((u_int64_t)resp->snscb_portname[7]));
    761  1.18.2.6   bouyer 
    762  1.18.2.6   bouyer 		isp_prt(isp, ISP_LOGINFO,
    763  1.18.2.6   bouyer 		    "Fabric Device (Type 0x%x)@PortID 0x%x WWN 0x%08x%08x",
    764  1.18.2.6   bouyer 		    resp->snscb_port_type, portid, ((u_int32_t)(wwn >> 32)),
    765      1.15   mjacob 		    ((u_int32_t)(wwn & 0xffffffff)));
    766  1.18.2.6   bouyer 
    767      1.15   mjacob 		for (target = FC_SNS_ID+1; target < MAX_FC_TARG; target++) {
    768      1.15   mjacob 			lp = &fcp->portdb[target];
    769      1.15   mjacob 			if (lp->port_wwn == wwn)
    770      1.15   mjacob 				break;
    771      1.15   mjacob 		}
    772      1.15   mjacob 		if (target < MAX_FC_TARG) {
    773      1.15   mjacob 			break;
    774      1.15   mjacob 		}
    775      1.15   mjacob 		for (target = FC_SNS_ID+1; target < MAX_FC_TARG; target++) {
    776      1.15   mjacob 			lp = &fcp->portdb[target];
    777      1.15   mjacob 			if (lp->port_wwn == 0)
    778      1.15   mjacob 				break;
    779      1.15   mjacob 		}
    780      1.15   mjacob 		if (target == MAX_FC_TARG) {
    781  1.18.2.6   bouyer 			isp_prt(isp, ISP_LOGWARN,
    782  1.18.2.6   bouyer 			    "no more space for fabric devices");
    783      1.15   mjacob 			return (-1);
    784      1.15   mjacob 		}
    785      1.15   mjacob 		lp->port_wwn = lp->node_wwn = wwn;
    786      1.15   mjacob 		lp->portid = portid;
    787      1.15   mjacob 		break;
    788      1.15   mjacob 	}
    789      1.15   mjacob #endif
    790       1.9   mjacob 	default:
    791       1.9   mjacob 		break;
    792       1.9   mjacob 	}
    793      1.10   mjacob 	(void) splx(s);
    794       1.9   mjacob 	return (0);
    795  1.18.2.6   bouyer }
    796  1.18.2.6   bouyer 
    797  1.18.2.6   bouyer #include <machine/stdarg.h>
    798  1.18.2.6   bouyer void
    799  1.18.2.6   bouyer #ifdef	__STDC__
    800  1.18.2.6   bouyer isp_prt(struct ispsoftc *isp, int level, const char *fmt, ...)
    801  1.18.2.6   bouyer #else
    802  1.18.2.6   bouyer isp_prt(isp, fmt, va_alist)
    803  1.18.2.6   bouyer 	struct ispsoftc *isp;
    804  1.18.2.6   bouyer 	char *fmt;
    805  1.18.2.6   bouyer 	va_dcl;
    806  1.18.2.6   bouyer #endif
    807  1.18.2.6   bouyer {
    808  1.18.2.6   bouyer 	va_list ap;
    809  1.18.2.6   bouyer 	if (level != ISP_LOGALL && (level & isp->isp_dblev) == 0) {
    810  1.18.2.6   bouyer 		return;
    811  1.18.2.6   bouyer 	}
    812  1.18.2.6   bouyer 	printf("%s: ", isp->isp_name);
    813  1.18.2.6   bouyer 	va_start(ap, fmt);
    814  1.18.2.6   bouyer 	vprintf(fmt, ap);
    815  1.18.2.6   bouyer 	va_end(ap);
    816  1.18.2.6   bouyer 	printf("\n");
    817       1.1   mjacob }
    818