Home | History | Annotate | Line # | Download | only in ic
isp_netbsd.c revision 1.39.2.10
      1  1.39.2.10  nathanw /* $NetBSD: isp_netbsd.c,v 1.39.2.10 2002/06/20 03:44:49 nathanw Exp $ */
      2       1.30   mjacob /*
      3       1.30   mjacob  * This driver, which is contained in NetBSD in the files:
      4       1.30   mjacob  *
      5       1.30   mjacob  *	sys/dev/ic/isp.c
      6       1.34      wiz  *	sys/dev/ic/isp_inline.h
      7       1.34      wiz  *	sys/dev/ic/isp_netbsd.c
      8       1.34      wiz  *	sys/dev/ic/isp_netbsd.h
      9       1.34      wiz  *	sys/dev/ic/isp_target.c
     10       1.34      wiz  *	sys/dev/ic/isp_target.h
     11       1.34      wiz  *	sys/dev/ic/isp_tpublic.h
     12       1.34      wiz  *	sys/dev/ic/ispmbox.h
     13       1.34      wiz  *	sys/dev/ic/ispreg.h
     14       1.34      wiz  *	sys/dev/ic/ispvar.h
     15       1.30   mjacob  *	sys/microcode/isp/asm_sbus.h
     16       1.30   mjacob  *	sys/microcode/isp/asm_1040.h
     17       1.30   mjacob  *	sys/microcode/isp/asm_1080.h
     18       1.30   mjacob  *	sys/microcode/isp/asm_12160.h
     19       1.30   mjacob  *	sys/microcode/isp/asm_2100.h
     20       1.30   mjacob  *	sys/microcode/isp/asm_2200.h
     21       1.30   mjacob  *	sys/pci/isp_pci.c
     22       1.30   mjacob  *	sys/sbus/isp_sbus.c
     23       1.30   mjacob  *
     24       1.30   mjacob  * Is being actively maintained by Matthew Jacob (mjacob (at) netbsd.org).
     25       1.30   mjacob  * This driver also is shared source with FreeBSD, OpenBSD, Linux, Solaris,
     26       1.30   mjacob  * Linux versions. This tends to be an interesting maintenance problem.
     27       1.30   mjacob  *
     28       1.30   mjacob  * Please coordinate with Matthew Jacob on changes you wish to make here.
     29       1.30   mjacob  */
     30        1.1   mjacob /*
     31        1.1   mjacob  * Platform (NetBSD) dependent common attachment code for Qlogic adapters.
     32       1.15   mjacob  * Matthew Jacob <mjacob (at) nas.nasa.gov>
     33       1.15   mjacob  */
     34       1.15   mjacob /*
     35       1.15   mjacob  * Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
     36        1.1   mjacob  * All rights reserved.
     37        1.1   mjacob  *
     38        1.1   mjacob  * Redistribution and use in source and binary forms, with or without
     39        1.1   mjacob  * modification, are permitted provided that the following conditions
     40        1.1   mjacob  * are met:
     41        1.1   mjacob  * 1. Redistributions of source code must retain the above copyright
     42       1.15   mjacob  *    notice, this list of conditions and the following disclaimer.
     43        1.1   mjacob  * 2. Redistributions in binary form must reproduce the above copyright
     44        1.1   mjacob  *    notice, this list of conditions and the following disclaimer in the
     45        1.1   mjacob  *    documentation and/or other materials provided with the distribution.
     46        1.1   mjacob  * 3. The name of the author may not be used to endorse or promote products
     47       1.15   mjacob  *    derived from this software without specific prior written permission
     48        1.1   mjacob  *
     49       1.15   mjacob  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     50       1.15   mjacob  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     51       1.15   mjacob  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     52       1.15   mjacob  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     53       1.15   mjacob  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     54       1.15   mjacob  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     55       1.15   mjacob  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     56       1.15   mjacob  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     57       1.15   mjacob  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     58       1.15   mjacob  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     59        1.1   mjacob  */
     60   1.39.2.6  nathanw 
     61   1.39.2.6  nathanw #include <sys/cdefs.h>
     62  1.39.2.10  nathanw __KERNEL_RCSID(0, "$NetBSD: isp_netbsd.c,v 1.39.2.10 2002/06/20 03:44:49 nathanw Exp $");
     63        1.1   mjacob 
     64        1.1   mjacob #include <dev/ic/isp_netbsd.h>
     65       1.17   mjacob #include <sys/scsiio.h>
     66        1.1   mjacob 
     67       1.27   mjacob 
     68       1.27   mjacob /*
     69       1.27   mjacob  * Set a timeout for the watchdogging of a command.
     70       1.27   mjacob  *
     71       1.27   mjacob  * The dimensional analysis is
     72       1.27   mjacob  *
     73       1.27   mjacob  *	milliseconds * (seconds/millisecond) * (ticks/second) = ticks
     74       1.27   mjacob  *
     75       1.27   mjacob  *			=
     76       1.27   mjacob  *
     77       1.27   mjacob  *	(milliseconds / 1000) * hz = ticks
     78       1.27   mjacob  *
     79       1.27   mjacob  *
     80       1.27   mjacob  * For timeouts less than 1 second, we'll get zero. Because of this, and
     81       1.27   mjacob  * because we want to establish *our* timeout to be longer than what the
     82       1.27   mjacob  * firmware might do, we just add 3 seconds at the back end.
     83       1.27   mjacob  */
     84       1.27   mjacob #define	_XT(xs)	((((xs)->timeout/1000) * hz) + (3 * hz))
     85       1.26   mjacob 
     86   1.39.2.3  nathanw static void isp_config_interrupts(struct device *);
     87   1.39.2.2  nathanw static void ispminphys_1020(struct buf *);
     88   1.39.2.1  nathanw static void ispminphys(struct buf *);
     89   1.39.2.2  nathanw static INLINE void ispcmd(struct ispsoftc *, XS_T *);
     90   1.39.2.2  nathanw static void isprequest(struct scsipi_channel *, scsipi_adapter_req_t, void *);
     91   1.39.2.2  nathanw static int
     92   1.39.2.2  nathanw ispioctl(struct scsipi_channel *, u_long, caddr_t, int, struct proc *);
     93        1.1   mjacob 
     94   1.39.2.2  nathanw static void isp_polled_cmd(struct ispsoftc *, XS_T *);
     95   1.39.2.1  nathanw static void isp_dog(void *);
     96   1.39.2.2  nathanw static void isp_create_fc_worker(void *);
     97   1.39.2.2  nathanw static void isp_fc_worker(void *);
     98       1.10   mjacob 
     99        1.1   mjacob /*
    100        1.1   mjacob  * Complete attachment of hardware, include subdevices.
    101        1.1   mjacob  */
    102        1.1   mjacob void
    103   1.39.2.1  nathanw isp_attach(struct ispsoftc *isp)
    104        1.1   mjacob {
    105        1.1   mjacob 	isp->isp_state = ISP_RUNSTATE;
    106   1.39.2.2  nathanw 
    107   1.39.2.2  nathanw 	isp->isp_osinfo._adapter.adapt_dev = &isp->isp_osinfo._dev;
    108   1.39.2.2  nathanw 	isp->isp_osinfo._adapter.adapt_nchannels = IS_DUALBUS(isp) ? 2 : 1;
    109   1.39.2.2  nathanw 	isp->isp_osinfo._adapter.adapt_openings = isp->isp_maxcmds;
    110   1.39.2.2  nathanw 	/*
    111   1.39.2.2  nathanw 	 * It's not stated whether max_periph is limited by SPI
    112   1.39.2.2  nathanw 	 * tag uage, but let's assume that it is.
    113   1.39.2.2  nathanw 	 */
    114   1.39.2.2  nathanw 	isp->isp_osinfo._adapter.adapt_max_periph = min(isp->isp_maxcmds, 255);
    115   1.39.2.2  nathanw 	isp->isp_osinfo._adapter.adapt_ioctl = ispioctl;
    116   1.39.2.2  nathanw 	isp->isp_osinfo._adapter.adapt_request = isprequest;
    117   1.39.2.2  nathanw 	if (isp->isp_type <= ISP_HA_SCSI_1020A) {
    118   1.39.2.2  nathanw 		isp->isp_osinfo._adapter.adapt_minphys = ispminphys_1020;
    119   1.39.2.2  nathanw 	} else {
    120   1.39.2.2  nathanw 		isp->isp_osinfo._adapter.adapt_minphys = ispminphys;
    121   1.39.2.2  nathanw 	}
    122   1.39.2.2  nathanw 
    123   1.39.2.2  nathanw 	isp->isp_osinfo._chan.chan_adapter = &isp->isp_osinfo._adapter;
    124   1.39.2.2  nathanw 	isp->isp_osinfo._chan.chan_bustype = &scsi_bustype;
    125   1.39.2.2  nathanw 	isp->isp_osinfo._chan.chan_channel = 0;
    126   1.39.2.2  nathanw 
    127       1.28   mjacob 	/*
    128       1.28   mjacob 	 * Until the midlayer is fixed to use REPORT LUNS, limit to 8 luns.
    129       1.28   mjacob 	 */
    130   1.39.2.2  nathanw 	isp->isp_osinfo._chan.chan_nluns = min(isp->isp_maxluns, 8);
    131        1.1   mjacob 
    132       1.15   mjacob 	if (IS_FC(isp)) {
    133   1.39.2.2  nathanw 		isp->isp_osinfo._chan.chan_ntargets = MAX_FC_TARG;
    134   1.39.2.2  nathanw 		isp->isp_osinfo._chan.chan_id = MAX_FC_TARG;
    135   1.39.2.2  nathanw 		isp->isp_osinfo.threadwork = 1;
    136   1.39.2.2  nathanw 		/*
    137   1.39.2.2  nathanw 		 * Note that isp_create_fc_worker won't get called
    138   1.39.2.2  nathanw 		 * until much much later (after proc0 is created).
    139   1.39.2.2  nathanw 		 */
    140   1.39.2.2  nathanw 		kthread_create(isp_create_fc_worker, isp);
    141   1.39.2.8  nathanw #ifdef	ISP_FW_CRASH_DUMP
    142   1.39.2.8  nathanw 		if (IS_2200(isp)) {
    143   1.39.2.8  nathanw 			FCPARAM(isp)->isp_dump_data =
    144   1.39.2.8  nathanw 			    malloc(QLA2200_RISC_IMAGE_DUMP_SIZE, M_DEVBUF,
    145   1.39.2.8  nathanw 				M_NOWAIT);
    146   1.39.2.8  nathanw 		} else if (IS_23XX(isp)) {
    147   1.39.2.8  nathanw 			FCPARAM(isp)->isp_dump_data =
    148   1.39.2.8  nathanw 			    malloc(QLA2300_RISC_IMAGE_DUMP_SIZE, M_DEVBUF,
    149   1.39.2.8  nathanw 				M_NOWAIT);
    150   1.39.2.8  nathanw 		}
    151   1.39.2.8  nathanw 		if (FCPARAM(isp)->isp_dump_data)
    152   1.39.2.8  nathanw 			FCPARAM(isp)->isp_dump_data[0] = 0;
    153   1.39.2.8  nathanw #endif
    154        1.1   mjacob 	} else {
    155   1.39.2.2  nathanw 		int bus = 0;
    156       1.14   mjacob 		sdparam *sdp = isp->isp_param;
    157   1.39.2.2  nathanw 
    158   1.39.2.2  nathanw 		isp->isp_osinfo._chan.chan_ntargets = MAX_TARGETS;
    159   1.39.2.2  nathanw 		isp->isp_osinfo._chan.chan_id = sdp->isp_initiator_id;
    160       1.17   mjacob 		isp->isp_osinfo.discovered[0] = 1 << sdp->isp_initiator_id;
    161       1.21   mjacob 		if (IS_DUALBUS(isp)) {
    162   1.39.2.2  nathanw 			isp->isp_osinfo._chan_b = isp->isp_osinfo._chan;
    163       1.14   mjacob 			sdp++;
    164       1.18   mjacob 			isp->isp_osinfo.discovered[1] =
    165       1.18   mjacob 			    1 << sdp->isp_initiator_id;
    166   1.39.2.2  nathanw 			isp->isp_osinfo._chan_b.chan_id = sdp->isp_initiator_id;
    167   1.39.2.2  nathanw 			isp->isp_osinfo._chan_b.chan_channel = 1;
    168       1.14   mjacob 		}
    169       1.28   mjacob 		ISP_LOCK(isp);
    170       1.14   mjacob 		(void) isp_control(isp, ISPCTL_RESET_BUS, &bus);
    171       1.21   mjacob 		if (IS_DUALBUS(isp)) {
    172       1.14   mjacob 			bus++;
    173       1.14   mjacob 			(void) isp_control(isp, ISPCTL_RESET_BUS, &bus);
    174       1.14   mjacob 		}
    175       1.29   mjacob 		ISP_UNLOCK(isp);
    176       1.11   mjacob 	}
    177       1.10   mjacob 
    178   1.39.2.3  nathanw 
    179       1.10   mjacob 	/*
    180   1.39.2.3  nathanw          * Defer enabling mailbox interrupts until later.
    181   1.39.2.3  nathanw          */
    182   1.39.2.3  nathanw         config_interrupts((struct device *) isp, isp_config_interrupts);
    183       1.28   mjacob 
    184       1.28   mjacob 	/*
    185        1.8   mjacob 	 * And attach children (if any).
    186        1.8   mjacob 	 */
    187   1.39.2.2  nathanw 	config_found((void *)isp, &isp->isp_chanA, scsiprint);
    188       1.21   mjacob 	if (IS_DUALBUS(isp)) {
    189   1.39.2.2  nathanw 		config_found((void *)isp, &isp->isp_chanB, scsiprint);
    190       1.14   mjacob 	}
    191        1.1   mjacob }
    192        1.1   mjacob 
    193   1.39.2.3  nathanw 
    194   1.39.2.3  nathanw static void
    195   1.39.2.3  nathanw isp_config_interrupts(struct device *self)
    196   1.39.2.3  nathanw {
    197   1.39.2.3  nathanw         struct ispsoftc *isp = (struct ispsoftc *) self;
    198   1.39.2.3  nathanw 
    199   1.39.2.3  nathanw 	/*
    200   1.39.2.3  nathanw 	 * After this point, we'll be doing the new configuration
    201   1.39.2.5  nathanw 	 * schema which allows interrups, so we can do tsleep/wakeup
    202   1.39.2.3  nathanw 	 * for mailbox stuff at that point.
    203   1.39.2.3  nathanw 	 */
    204   1.39.2.3  nathanw 	isp->isp_osinfo.no_mbox_ints = 0;
    205   1.39.2.3  nathanw }
    206   1.39.2.3  nathanw 
    207   1.39.2.3  nathanw 
    208        1.1   mjacob /*
    209        1.1   mjacob  * minphys our xfers
    210        1.1   mjacob  */
    211        1.1   mjacob 
    212        1.1   mjacob static void
    213   1.39.2.2  nathanw ispminphys_1020(struct buf *bp)
    214        1.1   mjacob {
    215        1.1   mjacob 	if (bp->b_bcount >= (1 << 24)) {
    216        1.1   mjacob 		bp->b_bcount = (1 << 24);
    217        1.1   mjacob 	}
    218        1.1   mjacob 	minphys(bp);
    219        1.1   mjacob }
    220        1.1   mjacob 
    221   1.39.2.2  nathanw static void
    222   1.39.2.2  nathanw ispminphys(struct buf *bp)
    223   1.39.2.2  nathanw {
    224   1.39.2.2  nathanw 	if (bp->b_bcount >= (1 << 30)) {
    225   1.39.2.2  nathanw 		bp->b_bcount = (1 << 30);
    226   1.39.2.2  nathanw 	}
    227   1.39.2.2  nathanw 	minphys(bp);
    228   1.39.2.2  nathanw }
    229   1.39.2.2  nathanw 
    230       1.17   mjacob static int
    231   1.39.2.2  nathanw ispioctl(struct scsipi_channel *chan, u_long cmd, caddr_t addr, int flag,
    232   1.39.2.2  nathanw 	struct proc *p)
    233       1.17   mjacob {
    234   1.39.2.2  nathanw 	struct ispsoftc *isp = (void *)chan->chan_adapter->adapt_dev;
    235   1.39.2.2  nathanw 	int retval = ENOTTY;
    236       1.17   mjacob 
    237       1.17   mjacob 	switch (cmd) {
    238   1.39.2.8  nathanw #ifdef	ISP_FW_CRASH_DUMP
    239   1.39.2.8  nathanw 	case ISP_GET_FW_CRASH_DUMP:
    240   1.39.2.8  nathanw 	{
    241   1.39.2.8  nathanw 		u_int16_t *ptr = FCPARAM(isp)->isp_dump_data;
    242   1.39.2.8  nathanw 		size_t sz;
    243   1.39.2.8  nathanw 
    244   1.39.2.8  nathanw 		retval = 0;
    245   1.39.2.8  nathanw 		if (IS_2200(isp))
    246   1.39.2.8  nathanw 			sz = QLA2200_RISC_IMAGE_DUMP_SIZE;
    247   1.39.2.2  nathanw 		else
    248   1.39.2.8  nathanw 			sz = QLA2300_RISC_IMAGE_DUMP_SIZE;
    249   1.39.2.8  nathanw 		ISP_LOCK(isp);
    250   1.39.2.8  nathanw 		if (ptr && *ptr) {
    251   1.39.2.8  nathanw 			void *uaddr = *((void **) addr);
    252   1.39.2.8  nathanw 			if (copyout(ptr, uaddr, sz)) {
    253   1.39.2.8  nathanw 				retval = EFAULT;
    254   1.39.2.8  nathanw 			} else {
    255   1.39.2.8  nathanw 				*ptr = 0;
    256   1.39.2.8  nathanw 			}
    257   1.39.2.8  nathanw 		} else {
    258   1.39.2.8  nathanw 			retval = ENXIO;
    259   1.39.2.8  nathanw 		}
    260   1.39.2.8  nathanw 		ISP_UNLOCK(isp);
    261   1.39.2.8  nathanw 		break;
    262   1.39.2.8  nathanw 	}
    263   1.39.2.8  nathanw 
    264   1.39.2.8  nathanw 	case ISP_FORCE_CRASH_DUMP:
    265   1.39.2.8  nathanw 		ISP_LOCK(isp);
    266   1.39.2.8  nathanw 		if (isp->isp_osinfo.blocked == 0) {
    267   1.39.2.8  nathanw                         isp->isp_osinfo.blocked = 1;
    268   1.39.2.8  nathanw                         scsipi_channel_freeze(&isp->isp_chanA, 1);
    269   1.39.2.8  nathanw                 }
    270   1.39.2.8  nathanw 		isp_fw_dump(isp);
    271   1.39.2.8  nathanw 		isp_reinit(isp);
    272   1.39.2.2  nathanw 		ISP_UNLOCK(isp);
    273   1.39.2.8  nathanw 		retval = 0;
    274   1.39.2.8  nathanw 		break;
    275   1.39.2.8  nathanw #endif
    276   1.39.2.2  nathanw 	case ISP_SDBLEV:
    277       1.29   mjacob 	{
    278   1.39.2.2  nathanw 		int olddblev = isp->isp_dblev;
    279   1.39.2.2  nathanw 		isp->isp_dblev = *(int *)addr;
    280   1.39.2.2  nathanw 		*(int *)addr = olddblev;
    281       1.29   mjacob 		retval = 0;
    282       1.29   mjacob 		break;
    283       1.29   mjacob 	}
    284   1.39.2.2  nathanw 	case ISP_RESETHBA:
    285   1.39.2.2  nathanw 		ISP_LOCK(isp);
    286   1.39.2.2  nathanw 		isp_reinit(isp);
    287   1.39.2.2  nathanw 		ISP_UNLOCK(isp);
    288   1.39.2.2  nathanw 		retval = 0;
    289   1.39.2.2  nathanw 		break;
    290   1.39.2.8  nathanw 	case ISP_RESCAN:
    291   1.39.2.2  nathanw 		if (IS_FC(isp)) {
    292   1.39.2.2  nathanw 			ISP_LOCK(isp);
    293   1.39.2.2  nathanw 			if (isp_fc_runstate(isp, 5 * 1000000)) {
    294   1.39.2.2  nathanw 				retval = EIO;
    295   1.39.2.2  nathanw 			} else {
    296   1.39.2.2  nathanw 				retval = 0;
    297   1.39.2.2  nathanw 			}
    298   1.39.2.2  nathanw 			ISP_UNLOCK(isp);
    299   1.39.2.2  nathanw 		}
    300   1.39.2.2  nathanw 		break;
    301   1.39.2.2  nathanw 	case ISP_FC_LIP:
    302   1.39.2.2  nathanw 		if (IS_FC(isp)) {
    303   1.39.2.2  nathanw 			ISP_LOCK(isp);
    304   1.39.2.2  nathanw 			if (isp_control(isp, ISPCTL_SEND_LIP, 0)) {
    305   1.39.2.2  nathanw 				retval = EIO;
    306   1.39.2.2  nathanw 			} else {
    307   1.39.2.2  nathanw 				retval = 0;
    308   1.39.2.2  nathanw 			}
    309   1.39.2.2  nathanw 			ISP_UNLOCK(isp);
    310   1.39.2.2  nathanw 		}
    311   1.39.2.2  nathanw 		break;
    312   1.39.2.2  nathanw 	case ISP_FC_GETDINFO:
    313   1.39.2.2  nathanw 	{
    314   1.39.2.2  nathanw 		struct isp_fc_device *ifc = (struct isp_fc_device *) addr;
    315   1.39.2.2  nathanw 		struct lportdb *lp;
    316   1.39.2.2  nathanw 
    317   1.39.2.2  nathanw 		if (ifc->loopid < 0 || ifc->loopid >= MAX_FC_TARG) {
    318   1.39.2.2  nathanw 			retval = EINVAL;
    319   1.39.2.2  nathanw 			break;
    320   1.39.2.2  nathanw 		}
    321   1.39.2.2  nathanw 		ISP_LOCK(isp);
    322   1.39.2.2  nathanw 		lp = &FCPARAM(isp)->portdb[ifc->loopid];
    323   1.39.2.2  nathanw 		if (lp->valid) {
    324   1.39.2.2  nathanw 			ifc->loopid = lp->loopid;
    325   1.39.2.2  nathanw 			ifc->portid = lp->portid;
    326   1.39.2.2  nathanw 			ifc->node_wwn = lp->node_wwn;
    327   1.39.2.2  nathanw 			ifc->port_wwn = lp->port_wwn;
    328       1.17   mjacob 			retval = 0;
    329   1.39.2.2  nathanw 		} else {
    330   1.39.2.2  nathanw 			retval = ENODEV;
    331   1.39.2.2  nathanw 		}
    332   1.39.2.2  nathanw 		ISP_UNLOCK(isp);
    333       1.17   mjacob 		break;
    334   1.39.2.2  nathanw 	}
    335  1.39.2.10  nathanw 	case ISP_GET_STATS:
    336  1.39.2.10  nathanw 	{
    337  1.39.2.10  nathanw 		isp_stats_t *sp = (isp_stats_t *) addr;
    338  1.39.2.10  nathanw 
    339  1.39.2.10  nathanw 		MEMZERO(sp, sizeof (*sp));
    340  1.39.2.10  nathanw 		sp->isp_stat_version = ISP_STATS_VERSION;
    341  1.39.2.10  nathanw 		sp->isp_type = isp->isp_type;
    342  1.39.2.10  nathanw 		sp->isp_revision = isp->isp_revision;
    343  1.39.2.10  nathanw 		ISP_LOCK(isp);
    344  1.39.2.10  nathanw 		sp->isp_stats[ISP_INTCNT] = isp->isp_intcnt;
    345  1.39.2.10  nathanw 		sp->isp_stats[ISP_INTBOGUS] = isp->isp_intbogus;
    346  1.39.2.10  nathanw 		sp->isp_stats[ISP_INTMBOXC] = isp->isp_intmboxc;
    347  1.39.2.10  nathanw 		sp->isp_stats[ISP_INGOASYNC] = isp->isp_intoasync;
    348  1.39.2.10  nathanw 		sp->isp_stats[ISP_RSLTCCMPLT] = isp->isp_rsltccmplt;
    349  1.39.2.10  nathanw 		sp->isp_stats[ISP_FPHCCMCPLT] = isp->isp_fphccmplt;
    350  1.39.2.10  nathanw 		sp->isp_stats[ISP_RSCCHIWAT] = isp->isp_rscchiwater;
    351  1.39.2.10  nathanw 		sp->isp_stats[ISP_FPCCHIWAT] = isp->isp_fpcchiwater;
    352  1.39.2.10  nathanw 		ISP_UNLOCK(isp);
    353  1.39.2.10  nathanw 		retval = 0;
    354  1.39.2.10  nathanw 		break;
    355  1.39.2.10  nathanw 	}
    356  1.39.2.10  nathanw 	case ISP_CLR_STATS:
    357  1.39.2.10  nathanw 		ISP_LOCK(isp);
    358  1.39.2.10  nathanw 		isp->isp_intcnt = 0;
    359  1.39.2.10  nathanw 		isp->isp_intbogus = 0;
    360  1.39.2.10  nathanw 		isp->isp_intmboxc = 0;
    361  1.39.2.10  nathanw 		isp->isp_intoasync = 0;
    362  1.39.2.10  nathanw 		isp->isp_rsltccmplt = 0;
    363  1.39.2.10  nathanw 		isp->isp_fphccmplt = 0;
    364  1.39.2.10  nathanw 		isp->isp_rscchiwater = 0;
    365  1.39.2.10  nathanw 		isp->isp_fpcchiwater = 0;
    366  1.39.2.10  nathanw 		ISP_UNLOCK(isp);
    367  1.39.2.10  nathanw 		retval = 0;
    368  1.39.2.10  nathanw 		break;
    369  1.39.2.10  nathanw 	case ISP_FC_GETHINFO:
    370  1.39.2.10  nathanw 	{
    371  1.39.2.10  nathanw 		struct isp_hba_device *hba = (struct isp_hba_device *) addr;
    372  1.39.2.10  nathanw 		MEMZERO(hba, sizeof (*hba));
    373  1.39.2.10  nathanw 		ISP_LOCK(isp);
    374  1.39.2.10  nathanw 		hba->fc_speed = FCPARAM(isp)->isp_gbspeed;
    375  1.39.2.10  nathanw 		hba->fc_scsi_supported = 1;
    376  1.39.2.10  nathanw 		hba->fc_topology = FCPARAM(isp)->isp_topo + 1;
    377  1.39.2.10  nathanw 		hba->fc_loopid = FCPARAM(isp)->isp_loopid;
    378  1.39.2.10  nathanw 		hba->active_node_wwn = FCPARAM(isp)->isp_nodewwn;
    379  1.39.2.10  nathanw 		hba->active_port_wwn = FCPARAM(isp)->isp_portwwn;
    380  1.39.2.10  nathanw 		ISP_UNLOCK(isp);
    381  1.39.2.10  nathanw 		break;
    382  1.39.2.10  nathanw 	}
    383   1.39.2.8  nathanw 	case SCBUSIORESET:
    384   1.39.2.8  nathanw 		ISP_LOCK(isp);
    385   1.39.2.8  nathanw 		if (isp_control(isp, ISPCTL_RESET_BUS, &chan->chan_channel))
    386   1.39.2.8  nathanw 			retval = EIO;
    387   1.39.2.8  nathanw 		else
    388   1.39.2.8  nathanw 			retval = 0;
    389   1.39.2.8  nathanw 		ISP_UNLOCK(isp);
    390   1.39.2.8  nathanw 		break;
    391       1.17   mjacob 	default:
    392       1.17   mjacob 		break;
    393        1.3   mjacob 	}
    394       1.17   mjacob 	return (retval);
    395       1.17   mjacob }
    396       1.17   mjacob 
    397   1.39.2.2  nathanw static INLINE void
    398   1.39.2.2  nathanw ispcmd(struct ispsoftc *isp, XS_T *xs)
    399       1.17   mjacob {
    400   1.39.2.2  nathanw 	ISP_LOCK(isp);
    401       1.11   mjacob 	if (isp->isp_state < ISP_RUNSTATE) {
    402       1.11   mjacob 		DISABLE_INTS(isp);
    403       1.11   mjacob 		isp_init(isp);
    404   1.39.2.2  nathanw 		if (isp->isp_state != ISP_INITSTATE) {
    405       1.11   mjacob 			ENABLE_INTS(isp);
    406   1.39.2.2  nathanw 			ISP_UNLOCK(isp);
    407   1.39.2.2  nathanw 			XS_SETERR(xs, HBA_BOTCH);
    408   1.39.2.2  nathanw 			scsipi_done(xs);
    409   1.39.2.2  nathanw 			return;
    410   1.39.2.2  nathanw 		}
    411   1.39.2.2  nathanw 		isp->isp_state = ISP_RUNSTATE;
    412       1.11   mjacob 		ENABLE_INTS(isp);
    413   1.39.2.2  nathanw 	}
    414       1.10   mjacob 	/*
    415   1.39.2.2  nathanw 	 * Handle the case of a FC card where the FC thread hasn't
    416   1.39.2.2  nathanw 	 * fired up yet and we have loop state to clean up. If we
    417   1.39.2.2  nathanw 	 * can't clear things up and we've never seen loop up, bounce
    418   1.39.2.2  nathanw 	 * the command.
    419       1.10   mjacob 	 */
    420   1.39.2.2  nathanw 	if (IS_FC(isp) && isp->isp_osinfo.threadwork &&
    421   1.39.2.2  nathanw 	    isp->isp_osinfo.thread == 0) {
    422   1.39.2.2  nathanw 		volatile u_int8_t ombi = isp->isp_osinfo.no_mbox_ints;
    423   1.39.2.2  nathanw 		int delay_time;
    424   1.39.2.2  nathanw 
    425       1.16  thorpej 		if (xs->xs_control & XS_CTL_POLL) {
    426   1.39.2.2  nathanw 			isp->isp_osinfo.no_mbox_ints = 1;
    427       1.10   mjacob 		}
    428   1.39.2.2  nathanw 
    429   1.39.2.2  nathanw 		if (isp->isp_osinfo.loop_checked == 0) {
    430   1.39.2.2  nathanw 			delay_time = 10 * 1000000;
    431   1.39.2.2  nathanw 			isp->isp_osinfo.loop_checked = 1;
    432   1.39.2.2  nathanw 		} else {
    433   1.39.2.2  nathanw 			delay_time = 250000;
    434   1.39.2.2  nathanw 		}
    435   1.39.2.2  nathanw 
    436   1.39.2.2  nathanw 		if (isp_fc_runstate(isp, delay_time) != 0) {
    437   1.39.2.2  nathanw 			if (xs->xs_control & XS_CTL_POLL) {
    438   1.39.2.2  nathanw 				isp->isp_osinfo.no_mbox_ints = ombi;
    439   1.39.2.2  nathanw 			}
    440   1.39.2.2  nathanw 			if (FCPARAM(isp)->loop_seen_once == 0) {
    441   1.39.2.2  nathanw 				XS_SETERR(xs, HBA_SELTIMEOUT);
    442   1.39.2.2  nathanw 				scsipi_done(xs);
    443   1.39.2.2  nathanw 				ISP_UNLOCK(isp);
    444   1.39.2.2  nathanw 				return;
    445   1.39.2.2  nathanw 			}
    446   1.39.2.2  nathanw 			/*
    447   1.39.2.2  nathanw 			 * Otherwise, fall thru to be queued up for later.
    448   1.39.2.2  nathanw 			 */
    449   1.39.2.2  nathanw 		} else {
    450   1.39.2.2  nathanw 			int wasblocked =
    451   1.39.2.2  nathanw 			    (isp->isp_osinfo.blocked || isp->isp_osinfo.paused);
    452   1.39.2.2  nathanw 			isp->isp_osinfo.threadwork = 0;
    453   1.39.2.2  nathanw 			isp->isp_osinfo.blocked =
    454   1.39.2.2  nathanw 			    isp->isp_osinfo.paused = 0;
    455   1.39.2.2  nathanw 			if (wasblocked) {
    456   1.39.2.2  nathanw 				scsipi_channel_thaw(&isp->isp_chanA, 1);
    457   1.39.2.2  nathanw 			}
    458   1.39.2.2  nathanw 		}
    459   1.39.2.2  nathanw 		if (xs->xs_control & XS_CTL_POLL) {
    460   1.39.2.2  nathanw 			isp->isp_osinfo.no_mbox_ints = ombi;
    461   1.39.2.2  nathanw 		}
    462   1.39.2.2  nathanw 	}
    463   1.39.2.2  nathanw 
    464   1.39.2.2  nathanw 	if (isp->isp_osinfo.paused) {
    465   1.39.2.2  nathanw 		isp_prt(isp, ISP_LOGWARN, "I/O while paused");
    466   1.39.2.2  nathanw 		xs->error = XS_RESOURCE_SHORTAGE;
    467   1.39.2.2  nathanw 		scsipi_done(xs);
    468   1.39.2.2  nathanw 		ISP_UNLOCK(isp);
    469   1.39.2.2  nathanw 		return;
    470   1.39.2.2  nathanw 	}
    471   1.39.2.2  nathanw 	if (isp->isp_osinfo.blocked) {
    472   1.39.2.2  nathanw 		isp_prt(isp, ISP_LOGWARN, "I/O while blocked");
    473   1.39.2.2  nathanw 		xs->error = XS_REQUEUE;
    474   1.39.2.2  nathanw 		scsipi_done(xs);
    475   1.39.2.2  nathanw 		ISP_UNLOCK(isp);
    476   1.39.2.2  nathanw 		return;
    477       1.10   mjacob 	}
    478       1.17   mjacob 
    479       1.26   mjacob 	if (xs->xs_control & XS_CTL_POLL) {
    480       1.28   mjacob 		volatile u_int8_t ombi = isp->isp_osinfo.no_mbox_ints;
    481       1.28   mjacob 		isp->isp_osinfo.no_mbox_ints = 1;
    482   1.39.2.2  nathanw 		isp_polled_cmd(isp, xs);
    483       1.28   mjacob 		isp->isp_osinfo.no_mbox_ints = ombi;
    484   1.39.2.2  nathanw 		ISP_UNLOCK(isp);
    485   1.39.2.2  nathanw 		return;
    486        1.1   mjacob 	}
    487        1.1   mjacob 
    488   1.39.2.2  nathanw 	switch (isp_start(xs)) {
    489       1.26   mjacob 	case CMD_QUEUED:
    490       1.26   mjacob 		if (xs->timeout) {
    491       1.26   mjacob 			callout_reset(&xs->xs_callout, _XT(xs), isp_dog, xs);
    492       1.26   mjacob 		}
    493       1.26   mjacob 		break;
    494       1.26   mjacob 	case CMD_EAGAIN:
    495   1.39.2.2  nathanw 		isp->isp_osinfo.paused = 1;
    496   1.39.2.2  nathanw 		xs->error = XS_RESOURCE_SHORTAGE;
    497   1.39.2.2  nathanw 		scsipi_channel_freeze(&isp->isp_chanA, 1);
    498   1.39.2.2  nathanw 		if (IS_DUALBUS(isp)) {
    499   1.39.2.2  nathanw 			scsipi_channel_freeze(&isp->isp_chanB, 1);
    500   1.39.2.2  nathanw 		}
    501   1.39.2.2  nathanw 		scsipi_done(xs);
    502       1.26   mjacob 		break;
    503       1.26   mjacob 	case CMD_RQLATER:
    504   1.39.2.2  nathanw 		/*
    505   1.39.2.2  nathanw 		 * We can only get RQLATER from FC devices (1 channel only)
    506   1.39.2.2  nathanw 		 *
    507   1.39.2.2  nathanw 		 * Also, if we've never seen loop up, bounce the command
    508   1.39.2.2  nathanw 		 * (somebody has booted with no FC cable connected)
    509   1.39.2.2  nathanw 		 */
    510   1.39.2.2  nathanw 		if (FCPARAM(isp)->loop_seen_once == 0) {
    511   1.39.2.2  nathanw 			XS_SETERR(xs, HBA_SELTIMEOUT);
    512   1.39.2.2  nathanw 			scsipi_done(xs);
    513   1.39.2.2  nathanw 			break;
    514   1.39.2.2  nathanw 		}
    515   1.39.2.2  nathanw 		if (isp->isp_osinfo.blocked == 0) {
    516   1.39.2.2  nathanw 			isp->isp_osinfo.blocked = 1;
    517   1.39.2.2  nathanw 			scsipi_channel_freeze(&isp->isp_chanA, 1);
    518   1.39.2.2  nathanw 		}
    519   1.39.2.2  nathanw 		xs->error = XS_REQUEUE;
    520   1.39.2.2  nathanw 		scsipi_done(xs);
    521       1.26   mjacob 		break;
    522       1.26   mjacob 	case CMD_COMPLETE:
    523   1.39.2.2  nathanw 		scsipi_done(xs);
    524       1.26   mjacob 		break;
    525       1.26   mjacob 	}
    526   1.39.2.2  nathanw 	ISP_UNLOCK(isp);
    527       1.26   mjacob }
    528       1.26   mjacob 
    529   1.39.2.2  nathanw static void
    530   1.39.2.2  nathanw isprequest(struct scsipi_channel *chan, scsipi_adapter_req_t req, void *arg)
    531   1.39.2.2  nathanw {
    532   1.39.2.2  nathanw 	struct ispsoftc *isp = (void *)chan->chan_adapter->adapt_dev;
    533   1.39.2.2  nathanw 
    534   1.39.2.2  nathanw 	switch (req) {
    535   1.39.2.2  nathanw 	case ADAPTER_REQ_RUN_XFER:
    536   1.39.2.2  nathanw 		ispcmd(isp, (XS_T *) arg);
    537   1.39.2.2  nathanw 		break;
    538   1.39.2.2  nathanw 
    539   1.39.2.2  nathanw 	case ADAPTER_REQ_GROW_RESOURCES:
    540   1.39.2.2  nathanw 		/* Not supported. */
    541   1.39.2.2  nathanw 		break;
    542   1.39.2.2  nathanw 
    543   1.39.2.2  nathanw 	case ADAPTER_REQ_SET_XFER_MODE:
    544   1.39.2.2  nathanw 	if (IS_SCSI(isp)) {
    545   1.39.2.2  nathanw 		struct scsipi_xfer_mode *xm = arg;
    546   1.39.2.2  nathanw 		int dflags = 0;
    547   1.39.2.2  nathanw 		sdparam *sdp = SDPARAM(isp);
    548   1.39.2.2  nathanw 
    549   1.39.2.2  nathanw 		sdp += chan->chan_channel;
    550   1.39.2.2  nathanw 		if (xm->xm_mode & PERIPH_CAP_TQING)
    551   1.39.2.2  nathanw 			dflags |= DPARM_TQING;
    552   1.39.2.2  nathanw 		if (xm->xm_mode & PERIPH_CAP_WIDE16)
    553   1.39.2.2  nathanw 			dflags |= DPARM_WIDE;
    554   1.39.2.2  nathanw 		if (xm->xm_mode & PERIPH_CAP_SYNC)
    555   1.39.2.2  nathanw 			dflags |= DPARM_SYNC;
    556   1.39.2.2  nathanw 		ISP_LOCK(isp);
    557   1.39.2.4  nathanw 		sdp->isp_devparam[xm->xm_target].goal_flags |= dflags;
    558   1.39.2.4  nathanw 		dflags = sdp->isp_devparam[xm->xm_target].goal_flags;
    559   1.39.2.2  nathanw 		sdp->isp_devparam[xm->xm_target].dev_update = 1;
    560   1.39.2.2  nathanw 		isp->isp_update |= (1 << chan->chan_channel);
    561   1.39.2.2  nathanw 		ISP_UNLOCK(isp);
    562   1.39.2.2  nathanw 		isp_prt(isp, ISP_LOGDEBUG1,
    563   1.39.2.2  nathanw 		    "ispioctl: device flags 0x%x for %d.%d.X",
    564   1.39.2.2  nathanw 		    dflags, chan->chan_channel, xm->xm_target);
    565   1.39.2.2  nathanw 		break;
    566   1.39.2.2  nathanw 	}
    567   1.39.2.2  nathanw 	default:
    568   1.39.2.2  nathanw 		break;
    569   1.39.2.2  nathanw 	}
    570   1.39.2.2  nathanw }
    571   1.39.2.2  nathanw 
    572   1.39.2.2  nathanw static void
    573   1.39.2.1  nathanw isp_polled_cmd(struct ispsoftc *isp, XS_T *xs)
    574       1.26   mjacob {
    575       1.26   mjacob 	int result;
    576       1.26   mjacob 	int infinite = 0, mswait;
    577       1.26   mjacob 
    578       1.28   mjacob 	result = isp_start(xs);
    579       1.26   mjacob 
    580       1.17   mjacob 	switch (result) {
    581       1.17   mjacob 	case CMD_QUEUED:
    582       1.17   mjacob 		break;
    583       1.17   mjacob 	case CMD_RQLATER:
    584   1.39.2.2  nathanw 		if (XS_NOERR(xs)) {
    585   1.39.2.2  nathanw 			xs->error = XS_REQUEUE;
    586   1.39.2.2  nathanw 		}
    587       1.17   mjacob 	case CMD_EAGAIN:
    588       1.17   mjacob 		if (XS_NOERR(xs)) {
    589   1.39.2.2  nathanw 			xs->error = XS_RESOURCE_SHORTAGE;
    590       1.17   mjacob 		}
    591   1.39.2.2  nathanw 		/* FALLTHROUGH */
    592       1.17   mjacob 	case CMD_COMPLETE:
    593   1.39.2.2  nathanw 		scsipi_done(xs);
    594   1.39.2.2  nathanw 		return;
    595       1.17   mjacob 
    596       1.17   mjacob 	}
    597       1.26   mjacob 
    598        1.1   mjacob 	/*
    599        1.1   mjacob 	 * If we can't use interrupts, poll on completion.
    600        1.1   mjacob 	 */
    601       1.26   mjacob 	if ((mswait = XS_TIME(xs)) == 0)
    602       1.26   mjacob 		infinite = 1;
    603       1.26   mjacob 
    604       1.26   mjacob 	while (mswait || infinite) {
    605   1.39.2.4  nathanw 		u_int16_t isr, sema, mbox;
    606   1.39.2.4  nathanw 		if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
    607   1.39.2.4  nathanw 			isp_intr(isp, isr, sema, mbox);
    608       1.26   mjacob 			if (XS_CMD_DONE_P(xs)) {
    609       1.26   mjacob 				break;
    610        1.1   mjacob 			}
    611        1.1   mjacob 		}
    612       1.28   mjacob 		USEC_DELAY(1000);
    613       1.26   mjacob 		mswait -= 1;
    614       1.26   mjacob 	}
    615       1.26   mjacob 
    616       1.26   mjacob 	/*
    617       1.26   mjacob 	 * If no other error occurred but we didn't finish,
    618       1.26   mjacob 	 * something bad happened.
    619       1.26   mjacob 	 */
    620       1.26   mjacob 	if (XS_CMD_DONE_P(xs) == 0) {
    621       1.26   mjacob 		if (isp_control(isp, ISPCTL_ABORT_CMD, xs)) {
    622       1.28   mjacob 			isp_reinit(isp);
    623       1.26   mjacob 		}
    624       1.26   mjacob 		if (XS_NOERR(xs)) {
    625       1.26   mjacob 			XS_SETERR(xs, HBA_BOTCH);
    626       1.26   mjacob 		}
    627        1.1   mjacob 	}
    628   1.39.2.2  nathanw 	scsipi_done(xs);
    629        1.1   mjacob }
    630        1.1   mjacob 
    631       1.26   mjacob void
    632   1.39.2.1  nathanw isp_done(XS_T *xs)
    633        1.1   mjacob {
    634       1.26   mjacob 	XS_CMD_S_DONE(xs);
    635       1.26   mjacob 	if (XS_CMD_WDOG_P(xs) == 0) {
    636       1.26   mjacob 		struct ispsoftc *isp = XS_ISP(xs);
    637       1.26   mjacob 		callout_stop(&xs->xs_callout);
    638       1.26   mjacob 		if (XS_CMD_GRACE_P(xs)) {
    639       1.28   mjacob 			isp_prt(isp, ISP_LOGDEBUG1,
    640       1.28   mjacob 			    "finished command on borrowed time");
    641        1.1   mjacob 		}
    642       1.26   mjacob 		XS_CMD_S_CLEAR(xs);
    643   1.39.2.2  nathanw 		/*
    644   1.39.2.2  nathanw 		 * Fixup- if we get a QFULL, we need
    645   1.39.2.2  nathanw 		 * to set XS_BUSY as the error.
    646   1.39.2.2  nathanw 		 */
    647   1.39.2.2  nathanw 		if (xs->status == SCSI_QUEUE_FULL) {
    648   1.39.2.2  nathanw 			xs->error = XS_BUSY;
    649   1.39.2.2  nathanw 		}
    650   1.39.2.2  nathanw 		if (isp->isp_osinfo.paused) {
    651   1.39.2.2  nathanw 			isp->isp_osinfo.paused = 0;
    652   1.39.2.2  nathanw 			scsipi_channel_timed_thaw(&isp->isp_chanA);
    653   1.39.2.2  nathanw 			if (IS_DUALBUS(isp)) {
    654   1.39.2.2  nathanw 				scsipi_channel_timed_thaw(&isp->isp_chanB);
    655   1.39.2.2  nathanw 			}
    656   1.39.2.2  nathanw 		}
    657       1.26   mjacob 		scsipi_done(xs);
    658        1.1   mjacob 	}
    659        1.8   mjacob }
    660        1.8   mjacob 
    661        1.8   mjacob static void
    662   1.39.2.1  nathanw isp_dog(void *arg)
    663        1.8   mjacob {
    664       1.28   mjacob 	XS_T *xs = arg;
    665       1.26   mjacob 	struct ispsoftc *isp = XS_ISP(xs);
    666   1.39.2.1  nathanw 	u_int16_t handle;
    667        1.8   mjacob 
    668       1.30   mjacob 	ISP_ILOCK(isp);
    669        1.8   mjacob 	/*
    670       1.26   mjacob 	 * We've decided this command is dead. Make sure we're not trying
    671       1.26   mjacob 	 * to kill a command that's already dead by getting it's handle and
    672       1.26   mjacob 	 * and seeing whether it's still alive.
    673       1.26   mjacob 	 */
    674       1.26   mjacob 	handle = isp_find_handle(isp, xs);
    675       1.26   mjacob 	if (handle) {
    676   1.39.2.4  nathanw 		u_int16_t isr, mbox, sema;
    677       1.26   mjacob 
    678       1.26   mjacob 		if (XS_CMD_DONE_P(xs)) {
    679       1.28   mjacob 			isp_prt(isp, ISP_LOGDEBUG1,
    680       1.28   mjacob 			    "watchdog found done cmd (handle 0x%x)", handle);
    681       1.30   mjacob 			ISP_IUNLOCK(isp);
    682       1.26   mjacob 			return;
    683       1.26   mjacob 		}
    684       1.26   mjacob 
    685       1.26   mjacob 		if (XS_CMD_WDOG_P(xs)) {
    686       1.28   mjacob 			isp_prt(isp, ISP_LOGDEBUG1,
    687       1.28   mjacob 			    "recursive watchdog (handle 0x%x)", handle);
    688       1.30   mjacob 			ISP_IUNLOCK(isp);
    689       1.26   mjacob 			return;
    690       1.26   mjacob 		}
    691       1.26   mjacob 
    692       1.26   mjacob 		XS_CMD_S_WDOG(xs);
    693       1.26   mjacob 
    694   1.39.2.4  nathanw 		if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
    695   1.39.2.4  nathanw 			isp_intr(isp, isr, sema, mbox);
    696   1.39.2.4  nathanw 
    697   1.39.2.4  nathanw 		}
    698   1.39.2.4  nathanw 		if (XS_CMD_DONE_P(xs)) {
    699   1.39.2.4  nathanw 			isp_prt(isp, ISP_LOGDEBUG1,
    700   1.39.2.4  nathanw 			    "watchdog cleanup for handle 0x%x", handle);
    701       1.26   mjacob 			XS_CMD_C_WDOG(xs);
    702       1.26   mjacob 			isp_done(xs);
    703       1.26   mjacob 		} else if (XS_CMD_GRACE_P(xs)) {
    704   1.39.2.4  nathanw 			isp_prt(isp, ISP_LOGDEBUG1,
    705   1.39.2.4  nathanw 			    "watchdog timeout for handle 0x%x", handle);
    706       1.26   mjacob 			/*
    707       1.26   mjacob 			 * Make sure the command is *really* dead before we
    708       1.26   mjacob 			 * release the handle (and DMA resources) for reuse.
    709       1.26   mjacob 			 */
    710       1.26   mjacob 			(void) isp_control(isp, ISPCTL_ABORT_CMD, arg);
    711       1.26   mjacob 
    712       1.26   mjacob 			/*
    713       1.26   mjacob 			 * After this point, the comamnd is really dead.
    714       1.26   mjacob 			 */
    715       1.26   mjacob 			if (XS_XFRLEN(xs)) {
    716       1.26   mjacob 				ISP_DMAFREE(isp, xs, handle);
    717       1.26   mjacob 			}
    718       1.26   mjacob 			isp_destroy_handle(isp, handle);
    719       1.26   mjacob 			XS_SETERR(xs, XS_TIMEOUT);
    720       1.26   mjacob 			XS_CMD_S_CLEAR(xs);
    721       1.26   mjacob 			isp_done(xs);
    722       1.26   mjacob 		} else {
    723   1.39.2.7  nathanw 			u_int16_t nxti, optr;
    724   1.39.2.7  nathanw 			ispreq_t local, *mp = &local, *qe;
    725       1.28   mjacob 			isp_prt(isp, ISP_LOGDEBUG2,
    726   1.39.2.4  nathanw 			    "possible command timeout on handle %x", handle);
    727       1.26   mjacob 			XS_CMD_C_WDOG(xs);
    728       1.26   mjacob 			callout_reset(&xs->xs_callout, hz, isp_dog, xs);
    729   1.39.2.7  nathanw 			if (isp_getrqentry(isp, &nxti, &optr, (void **) &qe)) {
    730       1.33   mjacob 				ISP_UNLOCK(isp);
    731       1.26   mjacob 				return;
    732       1.26   mjacob 			}
    733       1.26   mjacob 			XS_CMD_S_GRACE(xs);
    734       1.26   mjacob 			MEMZERO((void *) mp, sizeof (*mp));
    735       1.26   mjacob 			mp->req_header.rqs_entry_count = 1;
    736       1.26   mjacob 			mp->req_header.rqs_entry_type = RQSTYPE_MARKER;
    737       1.26   mjacob 			mp->req_modifier = SYNC_ALL;
    738       1.26   mjacob 			mp->req_target = XS_CHANNEL(xs) << 7;
    739   1.39.2.7  nathanw 			isp_put_request(isp, mp, qe);
    740   1.39.2.7  nathanw 			ISP_ADD_REQUEST(isp, nxti);
    741        1.8   mjacob 		}
    742       1.30   mjacob 	} else {
    743       1.30   mjacob 		isp_prt(isp, ISP_LOGDEBUG0, "watchdog with no command");
    744        1.8   mjacob 	}
    745       1.30   mjacob 	ISP_IUNLOCK(isp);
    746        1.8   mjacob }
    747        1.8   mjacob 
    748        1.8   mjacob /*
    749   1.39.2.2  nathanw  * Fibre Channel state cleanup thread
    750   1.39.2.2  nathanw  */
    751   1.39.2.2  nathanw static void
    752   1.39.2.2  nathanw isp_create_fc_worker(void *arg)
    753   1.39.2.2  nathanw {
    754   1.39.2.2  nathanw 	struct ispsoftc *isp = arg;
    755   1.39.2.2  nathanw 
    756   1.39.2.2  nathanw 	if (kthread_create1(isp_fc_worker, isp, &isp->isp_osinfo.thread,
    757   1.39.2.2  nathanw 	    "%s:fc_thrd", isp->isp_name)) {
    758   1.39.2.2  nathanw 		isp_prt(isp, ISP_LOGERR, "unable to create FC worker thread");
    759   1.39.2.2  nathanw 		panic("isp_create_fc_worker");
    760   1.39.2.2  nathanw 	}
    761   1.39.2.2  nathanw 
    762   1.39.2.2  nathanw }
    763   1.39.2.2  nathanw 
    764   1.39.2.2  nathanw static void
    765   1.39.2.2  nathanw isp_fc_worker(void *arg)
    766   1.39.2.2  nathanw {
    767   1.39.2.2  nathanw 	void scsipi_run_queue(struct scsipi_channel *);
    768   1.39.2.2  nathanw 	struct ispsoftc *isp = arg;
    769   1.39.2.2  nathanw 
    770   1.39.2.2  nathanw 	for (;;) {
    771   1.39.2.2  nathanw 		int s;
    772   1.39.2.2  nathanw 
    773   1.39.2.2  nathanw 		/*
    774   1.39.2.2  nathanw 		 * Note we do *not* use the ISP_LOCK/ISP_UNLOCK macros here.
    775   1.39.2.2  nathanw 		 */
    776   1.39.2.2  nathanw 		s = splbio();
    777   1.39.2.2  nathanw 		while (isp->isp_osinfo.threadwork) {
    778   1.39.2.2  nathanw 			isp->isp_osinfo.threadwork = 0;
    779   1.39.2.5  nathanw 			if (isp_fc_runstate(isp, 10 * 1000000) == 0) {
    780   1.39.2.2  nathanw 				break;
    781   1.39.2.2  nathanw 			}
    782   1.39.2.4  nathanw 			if  (isp->isp_osinfo.loop_checked &&
    783   1.39.2.4  nathanw 			     FCPARAM(isp)->loop_seen_once == 0) {
    784   1.39.2.4  nathanw 				splx(s);
    785   1.39.2.4  nathanw 				goto skip;
    786   1.39.2.4  nathanw 			}
    787   1.39.2.2  nathanw 			isp->isp_osinfo.threadwork = 1;
    788   1.39.2.2  nathanw 			splx(s);
    789   1.39.2.2  nathanw 			delay(500 * 1000);
    790   1.39.2.2  nathanw 			s = splbio();
    791   1.39.2.2  nathanw 		}
    792   1.39.2.2  nathanw 		if (FCPARAM(isp)->isp_fwstate != FW_READY ||
    793   1.39.2.2  nathanw 		    FCPARAM(isp)->isp_loopstate != LOOP_READY) {
    794   1.39.2.2  nathanw 			isp_prt(isp, ISP_LOGINFO, "isp_fc_runstate in vain");
    795   1.39.2.2  nathanw 			isp->isp_osinfo.threadwork = 1;
    796   1.39.2.2  nathanw 			splx(s);
    797   1.39.2.2  nathanw 			continue;
    798   1.39.2.2  nathanw 		}
    799   1.39.2.2  nathanw 
    800   1.39.2.2  nathanw 		if (isp->isp_osinfo.blocked) {
    801   1.39.2.2  nathanw 			isp->isp_osinfo.blocked = 0;
    802   1.39.2.4  nathanw 			isp_prt(isp, ISP_LOGDEBUG0,
    803   1.39.2.4  nathanw 			    "restarting queues (freeze count %d)",
    804   1.39.2.4  nathanw 			    isp->isp_chanA.chan_qfreeze);
    805   1.39.2.2  nathanw 			scsipi_channel_thaw(&isp->isp_chanA, 1);
    806   1.39.2.2  nathanw 		}
    807   1.39.2.2  nathanw 
    808   1.39.2.2  nathanw 		if (isp->isp_osinfo.thread == NULL)
    809   1.39.2.2  nathanw 			break;
    810   1.39.2.2  nathanw 
    811   1.39.2.4  nathanw skip:
    812   1.39.2.2  nathanw 		(void) tsleep(&isp->isp_osinfo.thread, PRIBIO, "fcclnup", 0);
    813   1.39.2.2  nathanw 
    814   1.39.2.2  nathanw 		splx(s);
    815   1.39.2.2  nathanw 	}
    816   1.39.2.2  nathanw 
    817   1.39.2.2  nathanw 	/* In case parent is waiting for us to exit. */
    818   1.39.2.2  nathanw 	wakeup(&isp->isp_osinfo.thread);
    819   1.39.2.2  nathanw 
    820   1.39.2.2  nathanw 	kthread_exit(0);
    821   1.39.2.2  nathanw }
    822   1.39.2.2  nathanw 
    823   1.39.2.2  nathanw /*
    824        1.8   mjacob  * Free any associated resources prior to decommissioning and
    825        1.8   mjacob  * set the card to a known state (so it doesn't wake up and kick
    826        1.8   mjacob  * us when we aren't expecting it to).
    827        1.8   mjacob  *
    828        1.8   mjacob  * Locks are held before coming here.
    829        1.8   mjacob  */
    830        1.8   mjacob void
    831   1.39.2.1  nathanw isp_uninit(struct ispsoftc *isp)
    832        1.8   mjacob {
    833       1.28   mjacob 	isp_lock(isp);
    834        1.8   mjacob 	/*
    835        1.8   mjacob 	 * Leave with interrupts disabled.
    836        1.8   mjacob 	 */
    837        1.8   mjacob 	DISABLE_INTS(isp);
    838       1.28   mjacob 	isp_unlock(isp);
    839        1.9   mjacob }
    840        1.9   mjacob 
    841        1.9   mjacob int
    842   1.39.2.1  nathanw isp_async(struct ispsoftc *isp, ispasync_t cmd, void *arg)
    843        1.9   mjacob {
    844       1.14   mjacob 	int bus, tgt;
    845   1.39.2.2  nathanw 
    846        1.9   mjacob 	switch (cmd) {
    847        1.9   mjacob 	case ISPASYNC_NEW_TGT_PARAMS:
    848       1.17   mjacob 	if (IS_SCSI(isp) && isp->isp_dblev) {
    849       1.17   mjacob 		sdparam *sdp = isp->isp_param;
    850   1.39.2.2  nathanw 		int flags;
    851   1.39.2.2  nathanw 		struct scsipi_xfer_mode xm;
    852       1.17   mjacob 
    853       1.17   mjacob 		tgt = *((int *) arg);
    854       1.17   mjacob 		bus = (tgt >> 16) & 0xffff;
    855       1.17   mjacob 		tgt &= 0xffff;
    856       1.21   mjacob 		sdp += bus;
    857   1.39.2.4  nathanw 		flags = sdp->isp_devparam[tgt].actv_flags;
    858       1.21   mjacob 
    859   1.39.2.2  nathanw 		xm.xm_mode = 0;
    860   1.39.2.4  nathanw 		xm.xm_period = sdp->isp_devparam[tgt].actv_period;
    861   1.39.2.4  nathanw 		xm.xm_offset = sdp->isp_devparam[tgt].actv_offset;
    862   1.39.2.2  nathanw 		xm.xm_target = tgt;
    863   1.39.2.2  nathanw 
    864   1.39.2.2  nathanw 		if ((flags & DPARM_SYNC) && xm.xm_period && xm.xm_offset)
    865   1.39.2.2  nathanw 			xm.xm_mode |= PERIPH_CAP_SYNC;
    866   1.39.2.2  nathanw 		if (flags & DPARM_WIDE)
    867   1.39.2.2  nathanw 			xm.xm_mode |= PERIPH_CAP_WIDE16;
    868   1.39.2.2  nathanw 		if (flags & DPARM_TQING)
    869   1.39.2.2  nathanw 			xm.xm_mode |= PERIPH_CAP_TQING;
    870   1.39.2.2  nathanw 		scsipi_async_event(bus? &isp->isp_chanB : &isp->isp_chanA,
    871   1.39.2.2  nathanw 		    ASYNC_EVENT_XFER_MODE, &xm);
    872       1.11   mjacob 		break;
    873       1.17   mjacob 	}
    874       1.11   mjacob 	case ISPASYNC_BUS_RESET:
    875   1.39.2.2  nathanw 		bus = *((int *) arg);
    876   1.39.2.2  nathanw 		scsipi_async_event(bus? &isp->isp_chanB : &isp->isp_chanA,
    877   1.39.2.2  nathanw 		    ASYNC_EVENT_RESET, NULL);
    878       1.28   mjacob 		isp_prt(isp, ISP_LOGINFO, "SCSI bus %d reset detected", bus);
    879       1.11   mjacob 		break;
    880   1.39.2.2  nathanw 	case ISPASYNC_LIP:
    881   1.39.2.2  nathanw 		/*
    882   1.39.2.2  nathanw 		 * Don't do queue freezes or blockage until we have the
    883   1.39.2.2  nathanw 		 * thread running that can unfreeze/unblock us.
    884   1.39.2.2  nathanw 		 */
    885   1.39.2.2  nathanw 		if (isp->isp_osinfo.blocked == 0)  {
    886   1.39.2.2  nathanw 			if (isp->isp_osinfo.thread) {
    887   1.39.2.2  nathanw 				isp->isp_osinfo.blocked = 1;
    888   1.39.2.2  nathanw 				scsipi_channel_freeze(&isp->isp_chanA, 1);
    889   1.39.2.2  nathanw 			}
    890   1.39.2.2  nathanw 		}
    891   1.39.2.2  nathanw 		isp_prt(isp, ISP_LOGINFO, "LIP Received");
    892   1.39.2.2  nathanw 		break;
    893   1.39.2.2  nathanw 	case ISPASYNC_LOOP_RESET:
    894   1.39.2.2  nathanw 		/*
    895   1.39.2.2  nathanw 		 * Don't do queue freezes or blockage until we have the
    896   1.39.2.2  nathanw 		 * thread running that can unfreeze/unblock us.
    897   1.39.2.2  nathanw 		 */
    898   1.39.2.2  nathanw 		if (isp->isp_osinfo.blocked == 0) {
    899   1.39.2.2  nathanw 			if (isp->isp_osinfo.thread) {
    900   1.39.2.2  nathanw 				isp->isp_osinfo.blocked = 1;
    901   1.39.2.2  nathanw 				scsipi_channel_freeze(&isp->isp_chanA, 1);
    902   1.39.2.2  nathanw 			}
    903   1.39.2.2  nathanw 		}
    904   1.39.2.2  nathanw 		isp_prt(isp, ISP_LOGINFO, "Loop Reset Received");
    905   1.39.2.2  nathanw 		break;
    906       1.11   mjacob 	case ISPASYNC_LOOP_DOWN:
    907       1.11   mjacob 		/*
    908   1.39.2.2  nathanw 		 * Don't do queue freezes or blockage until we have the
    909   1.39.2.2  nathanw 		 * thread running that can unfreeze/unblock us.
    910       1.11   mjacob 		 */
    911   1.39.2.2  nathanw 		if (isp->isp_osinfo.blocked == 0) {
    912   1.39.2.2  nathanw 			if (isp->isp_osinfo.thread) {
    913   1.39.2.2  nathanw 				isp->isp_osinfo.blocked = 1;
    914   1.39.2.2  nathanw 				scsipi_channel_freeze(&isp->isp_chanA, 1);
    915   1.39.2.2  nathanw 			}
    916   1.39.2.2  nathanw 		}
    917       1.28   mjacob 		isp_prt(isp, ISP_LOGINFO, "Loop DOWN");
    918       1.11   mjacob 		break;
    919       1.11   mjacob         case ISPASYNC_LOOP_UP:
    920   1.39.2.2  nathanw 		/*
    921   1.39.2.2  nathanw 		 * Let the subsequent ISPASYNC_CHANGE_NOTIFY invoke
    922   1.39.2.2  nathanw 		 * the FC worker thread. When the FC worker thread
    923   1.39.2.2  nathanw 		 * is done, let *it* call scsipi_channel_thaw...
    924   1.39.2.2  nathanw 		 */
    925       1.28   mjacob 		isp_prt(isp, ISP_LOGINFO, "Loop UP");
    926       1.11   mjacob 		break;
    927       1.39   mjacob 	case ISPASYNC_PROMENADE:
    928       1.17   mjacob 	if (IS_FC(isp) && isp->isp_dblev) {
    929  1.39.2.10  nathanw 		static const char fmt[] = "Target %d (Loop 0x%x) Port ID 0x%x "
    930       1.39   mjacob 		    "(role %s) %s\n Port WWN 0x%08x%08x\n Node WWN 0x%08x%08x";
    931  1.39.2.10  nathanw 		const static char *const roles[4] = {
    932   1.39.2.2  nathanw 		    "None", "Target", "Initiator", "Target/Initiator"
    933       1.11   mjacob 		};
    934       1.15   mjacob 		fcparam *fcp = isp->isp_param;
    935       1.15   mjacob 		int tgt = *((int *) arg);
    936       1.15   mjacob 		struct lportdb *lp = &fcp->portdb[tgt];
    937       1.15   mjacob 
    938       1.28   mjacob 		isp_prt(isp, ISP_LOGINFO, fmt, tgt, lp->loopid, lp->portid,
    939       1.39   mjacob 		    roles[lp->roles & 0x3],
    940       1.39   mjacob 		    (lp->valid)? "Arrived" : "Departed",
    941       1.15   mjacob 		    (u_int32_t) (lp->port_wwn >> 32),
    942       1.15   mjacob 		    (u_int32_t) (lp->port_wwn & 0xffffffffLL),
    943       1.15   mjacob 		    (u_int32_t) (lp->node_wwn >> 32),
    944       1.15   mjacob 		    (u_int32_t) (lp->node_wwn & 0xffffffffLL));
    945       1.11   mjacob 		break;
    946       1.11   mjacob 	}
    947       1.11   mjacob 	case ISPASYNC_CHANGE_NOTIFY:
    948   1.39.2.2  nathanw 		if (arg == ISPASYNC_CHANGE_PDB) {
    949   1.39.2.2  nathanw 			isp_prt(isp, ISP_LOGINFO, "Port Database Changed");
    950   1.39.2.2  nathanw 		} else if (arg == ISPASYNC_CHANGE_SNS) {
    951       1.38   mjacob 			isp_prt(isp, ISP_LOGINFO,
    952       1.38   mjacob 			    "Name Server Database Changed");
    953   1.39.2.2  nathanw 		}
    954   1.39.2.2  nathanw 
    955   1.39.2.2  nathanw 		/*
    956   1.39.2.2  nathanw 		 * We can set blocked here because we know it's now okay
    957   1.39.2.2  nathanw 		 * to try and run isp_fc_runstate (in order to build loop
    958   1.39.2.2  nathanw 		 * state). But we don't try and freeze the midlayer's queue
    959   1.39.2.2  nathanw 		 * if we have no thread that we can wake to later unfreeze
    960   1.39.2.2  nathanw 		 * it.
    961   1.39.2.2  nathanw 		 */
    962   1.39.2.2  nathanw 		if (isp->isp_osinfo.blocked == 0) {
    963   1.39.2.2  nathanw 			isp->isp_osinfo.blocked = 1;
    964   1.39.2.2  nathanw 			if (isp->isp_osinfo.thread) {
    965   1.39.2.2  nathanw 				scsipi_channel_freeze(&isp->isp_chanA, 1);
    966   1.39.2.2  nathanw 			}
    967   1.39.2.2  nathanw 		}
    968   1.39.2.2  nathanw 		/*
    969   1.39.2.2  nathanw 		 * Note that we have work for the thread to do, and
    970   1.39.2.2  nathanw 		 * if the thread is here already, wake it up.
    971   1.39.2.2  nathanw 		 */
    972   1.39.2.2  nathanw 		isp->isp_osinfo.threadwork++;
    973   1.39.2.2  nathanw 		if (isp->isp_osinfo.thread) {
    974   1.39.2.2  nathanw 			wakeup(&isp->isp_osinfo.thread);
    975       1.38   mjacob 		} else {
    976   1.39.2.2  nathanw 			isp_prt(isp, ISP_LOGDEBUG1, "no FC thread yet");
    977       1.38   mjacob 		}
    978        1.9   mjacob 		break;
    979       1.15   mjacob 	case ISPASYNC_FABRIC_DEV:
    980       1.15   mjacob 	{
    981   1.39.2.9  nathanw 		int target, base, lim;
    982   1.39.2.9  nathanw 		fcparam *fcp = isp->isp_param;
    983       1.39   mjacob 		struct lportdb *lp = NULL;
    984   1.39.2.9  nathanw 		struct lportdb *clp = (struct lportdb *) arg;
    985       1.39   mjacob 		char *pt;
    986       1.39   mjacob 
    987   1.39.2.9  nathanw 		switch (clp->port_type) {
    988       1.39   mjacob 		case 1:
    989       1.39   mjacob 			pt = "   N_Port";
    990       1.39   mjacob 			break;
    991       1.39   mjacob 		case 2:
    992       1.39   mjacob 			pt = "  NL_Port";
    993       1.39   mjacob 			break;
    994       1.39   mjacob 		case 3:
    995       1.39   mjacob 			pt = "F/NL_Port";
    996       1.39   mjacob 			break;
    997       1.39   mjacob 		case 0x7f:
    998       1.39   mjacob 			pt = "  Nx_Port";
    999       1.39   mjacob 			break;
   1000       1.39   mjacob 		case 0x81:
   1001       1.39   mjacob 			pt = "  F_port";
   1002       1.39   mjacob 			break;
   1003       1.39   mjacob 		case 0x82:
   1004       1.39   mjacob 			pt = "  FL_Port";
   1005       1.39   mjacob 			break;
   1006       1.39   mjacob 		case 0x84:
   1007       1.39   mjacob 			pt = "   E_port";
   1008       1.39   mjacob 			break;
   1009       1.39   mjacob 		default:
   1010   1.39.2.9  nathanw 			pt = " ";
   1011       1.39   mjacob 			break;
   1012       1.39   mjacob 		}
   1013   1.39.2.9  nathanw 
   1014       1.28   mjacob 		isp_prt(isp, ISP_LOGINFO,
   1015   1.39.2.9  nathanw 		    "%s Fabric Device @ PortID 0x%x", pt, clp->portid);
   1016   1.39.2.9  nathanw 
   1017   1.39.2.9  nathanw 		/*
   1018   1.39.2.9  nathanw 		 * If we don't have an initiator role we bail.
   1019   1.39.2.9  nathanw 		 *
   1020   1.39.2.9  nathanw 		 * We just use ISPASYNC_FABRIC_DEV for announcement purposes.
   1021   1.39.2.9  nathanw 		 */
   1022   1.39.2.9  nathanw 
   1023   1.39.2.9  nathanw 		if ((isp->isp_role & ISP_ROLE_INITIATOR) == 0) {
   1024   1.39.2.9  nathanw 			break;
   1025   1.39.2.9  nathanw 		}
   1026   1.39.2.9  nathanw 
   1027       1.39   mjacob 		/*
   1028   1.39.2.9  nathanw 		 * Is this entry for us? If so, we bail.
   1029       1.39   mjacob 		 */
   1030   1.39.2.9  nathanw 
   1031   1.39.2.9  nathanw 		if (fcp->isp_portid == clp->portid) {
   1032       1.39   mjacob 			break;
   1033       1.39   mjacob 		}
   1034   1.39.2.9  nathanw 
   1035   1.39.2.9  nathanw 		/*
   1036   1.39.2.9  nathanw 		 * Else, the default policy is to find room for it in
   1037   1.39.2.9  nathanw 		 * our local port database. Later, when we execute
   1038   1.39.2.9  nathanw 		 * the call to isp_pdb_sync either this newly arrived
   1039   1.39.2.9  nathanw 		 * or already logged in device will be (re)announced.
   1040   1.39.2.9  nathanw 		 */
   1041   1.39.2.9  nathanw 
   1042   1.39.2.9  nathanw 		if (fcp->isp_topo == TOPO_FL_PORT)
   1043   1.39.2.9  nathanw 			base = FC_SNS_ID+1;
   1044       1.39   mjacob 		else
   1045   1.39.2.9  nathanw 			base = 0;
   1046   1.39.2.9  nathanw 
   1047   1.39.2.9  nathanw 		if (fcp->isp_topo == TOPO_N_PORT)
   1048   1.39.2.9  nathanw 			lim = 1;
   1049   1.39.2.9  nathanw 		else
   1050   1.39.2.9  nathanw 			lim = MAX_FC_TARG;
   1051   1.39.2.9  nathanw 
   1052       1.39   mjacob 		/*
   1053       1.39   mjacob 		 * Is it already in our list?
   1054       1.39   mjacob 		 */
   1055   1.39.2.9  nathanw 		for (target = base; target < lim; target++) {
   1056       1.39   mjacob 			if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
   1057       1.39   mjacob 				continue;
   1058       1.39   mjacob 			}
   1059       1.15   mjacob 			lp = &fcp->portdb[target];
   1060   1.39.2.9  nathanw 			if (lp->port_wwn == clp->port_wwn &&
   1061   1.39.2.9  nathanw 			    lp->node_wwn == clp->node_wwn) {
   1062       1.39   mjacob 				lp->fabric_dev = 1;
   1063       1.15   mjacob 				break;
   1064       1.39   mjacob 			}
   1065       1.15   mjacob 		}
   1066   1.39.2.9  nathanw 		if (target < lim) {
   1067       1.15   mjacob 			break;
   1068       1.15   mjacob 		}
   1069   1.39.2.9  nathanw 		for (target = base; target < lim; target++) {
   1070       1.39   mjacob 			if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
   1071       1.39   mjacob 				continue;
   1072       1.39   mjacob 			}
   1073       1.15   mjacob 			lp = &fcp->portdb[target];
   1074       1.39   mjacob 			if (lp->port_wwn == 0) {
   1075       1.15   mjacob 				break;
   1076       1.39   mjacob 			}
   1077       1.15   mjacob 		}
   1078   1.39.2.9  nathanw 		if (target == lim) {
   1079       1.28   mjacob 			isp_prt(isp, ISP_LOGWARN,
   1080   1.39.2.9  nathanw 			    "out of space for fabric devices");
   1081       1.39   mjacob 			break;
   1082       1.15   mjacob 		}
   1083   1.39.2.9  nathanw 		lp->port_type = clp->port_type;
   1084   1.39.2.9  nathanw 		lp->fc4_type = clp->fc4_type;
   1085   1.39.2.9  nathanw 		lp->node_wwn = clp->node_wwn;
   1086   1.39.2.9  nathanw 		lp->port_wwn = clp->port_wwn;
   1087   1.39.2.9  nathanw 		lp->portid = clp->portid;
   1088       1.39   mjacob 		lp->fabric_dev = 1;
   1089   1.39.2.3  nathanw 		break;
   1090   1.39.2.3  nathanw 	}
   1091   1.39.2.3  nathanw 	case ISPASYNC_FW_CRASH:
   1092   1.39.2.3  nathanw 	{
   1093   1.39.2.3  nathanw 		u_int16_t mbox1, mbox6;
   1094   1.39.2.3  nathanw 		mbox1 = ISP_READ(isp, OUTMAILBOX1);
   1095   1.39.2.3  nathanw 		if (IS_DUALBUS(isp)) {
   1096   1.39.2.3  nathanw 			mbox6 = ISP_READ(isp, OUTMAILBOX6);
   1097   1.39.2.3  nathanw 		} else {
   1098   1.39.2.3  nathanw 			mbox6 = 0;
   1099   1.39.2.3  nathanw 		}
   1100   1.39.2.3  nathanw                 isp_prt(isp, ISP_LOGERR,
   1101   1.39.2.4  nathanw                     "Internal Firmware Error on bus %d @ RISC Address 0x%x",
   1102   1.39.2.3  nathanw                     mbox6, mbox1);
   1103   1.39.2.3  nathanw 		isp_reinit(isp);
   1104       1.15   mjacob 		break;
   1105       1.15   mjacob 	}
   1106        1.9   mjacob 	default:
   1107        1.9   mjacob 		break;
   1108        1.9   mjacob 	}
   1109        1.9   mjacob 	return (0);
   1110       1.28   mjacob }
   1111       1.28   mjacob 
   1112       1.28   mjacob #include <machine/stdarg.h>
   1113       1.28   mjacob void
   1114       1.28   mjacob isp_prt(struct ispsoftc *isp, int level, const char *fmt, ...)
   1115       1.28   mjacob {
   1116       1.28   mjacob 	va_list ap;
   1117       1.28   mjacob 	if (level != ISP_LOGALL && (level & isp->isp_dblev) == 0) {
   1118       1.28   mjacob 		return;
   1119       1.28   mjacob 	}
   1120       1.28   mjacob 	printf("%s: ", isp->isp_name);
   1121       1.28   mjacob 	va_start(ap, fmt);
   1122       1.28   mjacob 	vprintf(fmt, ap);
   1123       1.28   mjacob 	va_end(ap);
   1124       1.28   mjacob 	printf("\n");
   1125        1.1   mjacob }
   1126