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