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