Home | History | Annotate | Line # | Download | only in ic
isp_target.c revision 1.9.2.3
      1  1.9.2.3  bouyer /* $NetBSD: isp_target.c,v 1.9.2.3 2001/01/05 17:35:41 bouyer Exp $ */
      2  1.9.2.2  bouyer /*
      3  1.9.2.2  bouyer  * This driver, which is contained in NetBSD in the files:
      4  1.9.2.2  bouyer  *
      5  1.9.2.2  bouyer  *	sys/dev/ic/isp.c
      6  1.9.2.3  bouyer  *	sys/dev/ic/isp_inline.h
      7  1.9.2.3  bouyer  *	sys/dev/ic/isp_netbsd.c
      8  1.9.2.3  bouyer  *	sys/dev/ic/isp_netbsd.h
      9  1.9.2.3  bouyer  *	sys/dev/ic/isp_target.c
     10  1.9.2.3  bouyer  *	sys/dev/ic/isp_target.h
     11  1.9.2.3  bouyer  *	sys/dev/ic/isp_tpublic.h
     12  1.9.2.3  bouyer  *	sys/dev/ic/ispmbox.h
     13  1.9.2.3  bouyer  *	sys/dev/ic/ispreg.h
     14  1.9.2.3  bouyer  *	sys/dev/ic/ispvar.h
     15  1.9.2.2  bouyer  *	sys/microcode/isp/asm_sbus.h
     16  1.9.2.2  bouyer  *	sys/microcode/isp/asm_1040.h
     17  1.9.2.2  bouyer  *	sys/microcode/isp/asm_1080.h
     18  1.9.2.2  bouyer  *	sys/microcode/isp/asm_12160.h
     19  1.9.2.2  bouyer  *	sys/microcode/isp/asm_2100.h
     20  1.9.2.2  bouyer  *	sys/microcode/isp/asm_2200.h
     21  1.9.2.2  bouyer  *	sys/pci/isp_pci.c
     22  1.9.2.2  bouyer  *	sys/sbus/isp_sbus.c
     23  1.9.2.2  bouyer  *
     24  1.9.2.2  bouyer  * Is being actively maintained by Matthew Jacob (mjacob (at) netbsd.org).
     25  1.9.2.2  bouyer  * This driver also is shared source with FreeBSD, OpenBSD, Linux, Solaris,
     26  1.9.2.2  bouyer  * Linux versions. This tends to be an interesting maintenance problem.
     27  1.9.2.2  bouyer  *
     28  1.9.2.2  bouyer  * Please coordinate with Matthew Jacob on changes you wish to make here.
     29  1.9.2.2  bouyer  */
     30  1.9.2.2  bouyer /*
     31  1.9.2.2  bouyer  * Machine and OS Independent Target Mode Code for the Qlogic SCSI/FC adapters.
     32  1.9.2.2  bouyer  *
     33  1.9.2.2  bouyer  * Copyright (c) 1999 by Matthew Jacob
     34  1.9.2.2  bouyer  * All rights reserved.
     35  1.9.2.2  bouyer  * mjacob (at) feral.com
     36  1.9.2.2  bouyer  *
     37  1.9.2.2  bouyer  * Redistribution and use in source and binary forms, with or without
     38  1.9.2.2  bouyer  * modification, are permitted provided that the following conditions
     39  1.9.2.2  bouyer  * are met:
     40  1.9.2.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     41  1.9.2.2  bouyer  *    notice immediately at the beginning of the file, without modification,
     42  1.9.2.2  bouyer  *    this list of conditions, and the following disclaimer.
     43  1.9.2.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     44  1.9.2.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     45  1.9.2.2  bouyer  *    documentation and/or other materials provided with the distribution.
     46  1.9.2.2  bouyer  * 3. The name of the author may not be used to endorse or promote products
     47  1.9.2.2  bouyer  *    derived from this software without specific prior written permission.
     48  1.9.2.2  bouyer  *
     49  1.9.2.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     50  1.9.2.2  bouyer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     51  1.9.2.2  bouyer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     52  1.9.2.2  bouyer  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
     53  1.9.2.2  bouyer  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     54  1.9.2.2  bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     55  1.9.2.2  bouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     56  1.9.2.2  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     57  1.9.2.2  bouyer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     58  1.9.2.2  bouyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     59  1.9.2.2  bouyer  * SUCH DAMAGE.
     60  1.9.2.2  bouyer  */
     61  1.9.2.2  bouyer 
     62  1.9.2.2  bouyer /*
     63  1.9.2.2  bouyer  * Include header file appropriate for platform we're building on.
     64  1.9.2.2  bouyer  */
     65  1.9.2.2  bouyer 
     66  1.9.2.2  bouyer #ifdef	__NetBSD__
     67  1.9.2.2  bouyer #include <dev/ic/isp_netbsd.h>
     68  1.9.2.2  bouyer #endif
     69  1.9.2.2  bouyer #ifdef	__FreeBSD__
     70  1.9.2.2  bouyer #include <dev/isp/isp_freebsd.h>
     71  1.9.2.2  bouyer #endif
     72  1.9.2.2  bouyer #ifdef	__OpenBSD__
     73  1.9.2.2  bouyer #include <dev/ic/isp_openbsd.h>
     74  1.9.2.2  bouyer #endif
     75  1.9.2.2  bouyer #ifdef	__linux__
     76  1.9.2.2  bouyer #include "isp_linux.h"
     77  1.9.2.2  bouyer #endif
     78  1.9.2.2  bouyer 
     79  1.9.2.2  bouyer #ifdef	ISP_TARGET_MODE
     80  1.9.2.2  bouyer static char *atiocope =
     81  1.9.2.2  bouyer     "ATIO returned for lun %d because it was in the middle of Bus Device Reset";
     82  1.9.2.2  bouyer static char *atior =
     83  1.9.2.2  bouyer     "ATIO returned for lun %d from initiator %d because a Bus Reset occurred";
     84  1.9.2.2  bouyer 
     85  1.9.2.2  bouyer static void isp_got_msg __P((struct ispsoftc *, int, in_entry_t *));
     86  1.9.2.2  bouyer static void isp_got_msg_fc __P((struct ispsoftc *, int, in_fcentry_t *));
     87  1.9.2.2  bouyer static void isp_notify_ack __P((struct ispsoftc *, void *));
     88  1.9.2.2  bouyer static void isp_handle_atio(struct ispsoftc *, at_entry_t *);
     89  1.9.2.2  bouyer static void isp_handle_atio2(struct ispsoftc *, at2_entry_t *);
     90  1.9.2.2  bouyer static void isp_handle_ctio(struct ispsoftc *, ct_entry_t *);
     91  1.9.2.2  bouyer static void isp_handle_ctio2(struct ispsoftc *, ct2_entry_t *);
     92  1.9.2.2  bouyer 
     93  1.9.2.2  bouyer /*
     94  1.9.2.2  bouyer  * The Qlogic driver gets an interrupt to look at response queue entries.
     95  1.9.2.2  bouyer  * Some of these are status completions for initiatior mode commands, but
     96  1.9.2.2  bouyer  * if target mode is enabled, we get a whole wad of response queue entries
     97  1.9.2.2  bouyer  * to be handled here.
     98  1.9.2.2  bouyer  *
     99  1.9.2.2  bouyer  * Basically the split into 3 main groups: Lun Enable/Modification responses,
    100  1.9.2.2  bouyer  * SCSI Command processing, and Immediate Notification events.
    101  1.9.2.2  bouyer  *
    102  1.9.2.2  bouyer  * You start by writing a request queue entry to enable target mode (and
    103  1.9.2.2  bouyer  * establish some resource limitations which you can modify later).
    104  1.9.2.2  bouyer  * The f/w responds with a LUN ENABLE or LUN MODIFY response with
    105  1.9.2.2  bouyer  * the status of this action. If the enable was successful, you can expect...
    106  1.9.2.2  bouyer  *
    107  1.9.2.2  bouyer  * Response queue entries with SCSI commands encapsulate show up in an ATIO
    108  1.9.2.2  bouyer  * (Accept Target IO) type- sometimes with enough info to stop the command at
    109  1.9.2.2  bouyer  * this level. Ultimately the driver has to feed back to the f/w's request
    110  1.9.2.2  bouyer  * queue a sequence of CTIOs (continue target I/O) that describe data to
    111  1.9.2.2  bouyer  * be moved and/or status to be sent) and finally finishing with sending
    112  1.9.2.2  bouyer  * to the f/w's response queue an ATIO which then completes the handshake
    113  1.9.2.2  bouyer  * with the f/w for that command. There's a lot of variations on this theme,
    114  1.9.2.2  bouyer  * including flags you can set in the CTIO for the Qlogic 2X00 fibre channel
    115  1.9.2.2  bouyer  * cards that 'auto-replenish' the f/w's ATIO count, but this is the basic
    116  1.9.2.2  bouyer  * gist of it.
    117  1.9.2.2  bouyer  *
    118  1.9.2.2  bouyer  * The third group that can show up in the response queue are Immediate
    119  1.9.2.2  bouyer  * Notification events. These include things like notifications of SCSI bus
    120  1.9.2.2  bouyer  * resets, or Bus Device Reset messages or other messages received. This
    121  1.9.2.2  bouyer  * a classic oddbins area. It can get  a little wierd because you then turn
    122  1.9.2.2  bouyer  * around and acknowledge the Immediate Notify by writing an entry onto the
    123  1.9.2.2  bouyer  * request queue and then the f/w turns around and gives you an acknowledgement
    124  1.9.2.2  bouyer  * to *your* acknowledgement on the response queue (the idea being to let
    125  1.9.2.2  bouyer  * the f/w tell you when the event is *really* over I guess).
    126  1.9.2.2  bouyer  *
    127  1.9.2.2  bouyer  */
    128  1.9.2.2  bouyer 
    129  1.9.2.2  bouyer 
    130  1.9.2.2  bouyer /*
    131  1.9.2.2  bouyer  * A new response queue entry has arrived. The interrupt service code
    132  1.9.2.2  bouyer  * has already swizzled it into the platform dependent from canonical form.
    133  1.9.2.2  bouyer  *
    134  1.9.2.2  bouyer  * Because of the way this driver is designed, unfortunately most of the
    135  1.9.2.2  bouyer  * actual synchronization work has to be done in the platform specific
    136  1.9.2.2  bouyer  * code- we have no synchroniation primitives in the common code.
    137  1.9.2.2  bouyer  */
    138  1.9.2.2  bouyer 
    139  1.9.2.2  bouyer int
    140  1.9.2.2  bouyer isp_target_notify(isp, vptr, optrp)
    141  1.9.2.2  bouyer 	struct ispsoftc *isp;
    142  1.9.2.2  bouyer 	void *vptr;
    143  1.9.2.2  bouyer 	u_int16_t *optrp;
    144  1.9.2.2  bouyer {
    145  1.9.2.2  bouyer 	u_int16_t status, seqid;
    146  1.9.2.2  bouyer 	union {
    147  1.9.2.2  bouyer 		at_entry_t	*atiop;
    148  1.9.2.2  bouyer 		at2_entry_t	*at2iop;
    149  1.9.2.2  bouyer 		ct_entry_t	*ctiop;
    150  1.9.2.2  bouyer 		ct2_entry_t	*ct2iop;
    151  1.9.2.2  bouyer 		lun_entry_t	*lunenp;
    152  1.9.2.2  bouyer 		in_entry_t	*inotp;
    153  1.9.2.2  bouyer 		in_fcentry_t	*inot_fcp;
    154  1.9.2.2  bouyer 		na_entry_t	*nackp;
    155  1.9.2.2  bouyer 		na_fcentry_t	*nack_fcp;
    156  1.9.2.2  bouyer 		isphdr_t	*hp;
    157  1.9.2.2  bouyer 		void *		*vp;
    158  1.9.2.2  bouyer #define	atiop		unp.atiop
    159  1.9.2.2  bouyer #define	at2iop		unp.at2iop
    160  1.9.2.2  bouyer #define	ctiop		unp.ctiop
    161  1.9.2.2  bouyer #define	ct2iop		unp.ct2iop
    162  1.9.2.2  bouyer #define	lunenp		unp.lunenp
    163  1.9.2.2  bouyer #define	inotp		unp.inotp
    164  1.9.2.2  bouyer #define	inot_fcp	unp.inot_fcp
    165  1.9.2.2  bouyer #define	nackp		unp.nackp
    166  1.9.2.2  bouyer #define	nack_fcp	unp.nack_fcp
    167  1.9.2.2  bouyer #define	hdrp		unp.hp
    168  1.9.2.2  bouyer 	} unp;
    169  1.9.2.2  bouyer 	int bus, rval = 0;
    170  1.9.2.2  bouyer 
    171  1.9.2.2  bouyer 	unp.vp = vptr;
    172  1.9.2.2  bouyer 
    173  1.9.2.2  bouyer 	ISP_TDQE(isp, "isp_target_notify", (int) *optrp, vptr);
    174  1.9.2.2  bouyer 
    175  1.9.2.2  bouyer 	switch(hdrp->rqs_entry_type) {
    176  1.9.2.2  bouyer 	case RQSTYPE_ATIO:
    177  1.9.2.2  bouyer 		isp_handle_atio(isp, atiop);
    178  1.9.2.2  bouyer 		break;
    179  1.9.2.2  bouyer 	case RQSTYPE_CTIO:
    180  1.9.2.2  bouyer 		isp_handle_ctio(isp, ctiop);
    181  1.9.2.2  bouyer 		break;
    182  1.9.2.2  bouyer 	case RQSTYPE_ATIO2:
    183  1.9.2.2  bouyer 		isp_handle_atio2(isp, at2iop);
    184  1.9.2.2  bouyer 		break;
    185  1.9.2.2  bouyer 	case RQSTYPE_CTIO2:
    186  1.9.2.2  bouyer 		isp_handle_ctio2(isp, ct2iop);
    187  1.9.2.2  bouyer 		break;
    188  1.9.2.2  bouyer 	case RQSTYPE_ENABLE_LUN:
    189  1.9.2.2  bouyer 	case RQSTYPE_MODIFY_LUN:
    190  1.9.2.2  bouyer 		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, vptr);
    191  1.9.2.2  bouyer 		break;
    192  1.9.2.2  bouyer 
    193  1.9.2.2  bouyer 	case RQSTYPE_NOTIFY:
    194  1.9.2.2  bouyer 		/*
    195  1.9.2.2  bouyer 		 * Either the ISP received a SCSI message it can't
    196  1.9.2.2  bouyer 		 * handle, or it's returning an Immed. Notify entry
    197  1.9.2.2  bouyer 		 * we sent. We can send Immed. Notify entries to
    198  1.9.2.2  bouyer 		 * increment the firmware's resource count for them
    199  1.9.2.2  bouyer 		 * (we set this initially in the Enable Lun entry).
    200  1.9.2.2  bouyer 		 */
    201  1.9.2.2  bouyer 		bus = 0;
    202  1.9.2.2  bouyer 		if (IS_FC(isp)) {
    203  1.9.2.2  bouyer 			status = inot_fcp->in_status;
    204  1.9.2.2  bouyer 			seqid = inot_fcp->in_seqid;
    205  1.9.2.2  bouyer 		} else {
    206  1.9.2.2  bouyer 			status = inotp->in_status & 0xff;
    207  1.9.2.2  bouyer 			seqid = inotp->in_seqid;
    208  1.9.2.2  bouyer 			if (IS_DUALBUS(isp)) {
    209  1.9.2.2  bouyer 				bus = (inotp->in_iid & 0x80) >> 7;
    210  1.9.2.2  bouyer 				inotp->in_iid &= ~0x80;
    211  1.9.2.2  bouyer 			}
    212  1.9.2.2  bouyer 		}
    213  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGTDEBUG1,
    214  1.9.2.2  bouyer 		    "Immediate Notify, status=0x%x seqid=0x%x", status, seqid);
    215  1.9.2.2  bouyer 		switch (status) {
    216  1.9.2.2  bouyer 		case IN_RESET:
    217  1.9.2.2  bouyer 			(void) isp_async(isp, ISPASYNC_BUS_RESET, &bus);
    218  1.9.2.2  bouyer 			break;
    219  1.9.2.2  bouyer 		case IN_MSG_RECEIVED:
    220  1.9.2.2  bouyer 		case IN_IDE_RECEIVED:
    221  1.9.2.2  bouyer 			if (IS_FC(isp)) {
    222  1.9.2.2  bouyer 				isp_got_msg_fc(isp, bus, vptr);
    223  1.9.2.2  bouyer 			} else {
    224  1.9.2.2  bouyer 				isp_got_msg(isp, bus, vptr);
    225  1.9.2.2  bouyer 			}
    226  1.9.2.2  bouyer 			break;
    227  1.9.2.2  bouyer 		case IN_RSRC_UNAVAIL:
    228  1.9.2.2  bouyer 			isp_prt(isp, ISP_LOGWARN, "Firmware out of ATIOs");
    229  1.9.2.2  bouyer 			break;
    230  1.9.2.2  bouyer 		case IN_ABORT_TASK:
    231  1.9.2.2  bouyer 			isp_prt(isp, ISP_LOGWARN,
    232  1.9.2.2  bouyer 			    "Abort Task for Initiator %d RX_ID 0x%x",
    233  1.9.2.2  bouyer 			    inot_fcp->in_iid, seqid);
    234  1.9.2.2  bouyer 			break;
    235  1.9.2.2  bouyer 		case IN_PORT_LOGOUT:
    236  1.9.2.2  bouyer 			isp_prt(isp, ISP_LOGWARN,
    237  1.9.2.2  bouyer 			    "Port Logout for Initiator %d RX_ID 0x%x",
    238  1.9.2.2  bouyer 			    inot_fcp->in_iid, seqid);
    239  1.9.2.2  bouyer 			break;
    240  1.9.2.2  bouyer 		case IN_PORT_CHANGED:
    241  1.9.2.2  bouyer 			isp_prt(isp, ISP_LOGWARN,
    242  1.9.2.2  bouyer 			    "Port Changed for Initiator %d RX_ID 0x%x",
    243  1.9.2.2  bouyer 			    inot_fcp->in_iid, seqid);
    244  1.9.2.2  bouyer 			break;
    245  1.9.2.2  bouyer 		case IN_GLOBAL_LOGO:
    246  1.9.2.2  bouyer 			isp_prt(isp, ISP_LOGWARN, "All ports logged out");
    247  1.9.2.2  bouyer 			break;
    248  1.9.2.2  bouyer 		default:
    249  1.9.2.2  bouyer 			isp_prt(isp, ISP_LOGERR,
    250  1.9.2.2  bouyer 			    "bad status (0x%x) in isp_target_notify", status);
    251  1.9.2.2  bouyer 			break;
    252  1.9.2.2  bouyer 		}
    253  1.9.2.2  bouyer 		isp_notify_ack(isp, vptr);
    254  1.9.2.2  bouyer 		break;
    255  1.9.2.2  bouyer 
    256  1.9.2.2  bouyer 	case RQSTYPE_NOTIFY_ACK:
    257  1.9.2.2  bouyer 		/*
    258  1.9.2.2  bouyer 		 * The ISP is acknowledging our acknowledgement of an
    259  1.9.2.2  bouyer 		 * Immediate Notify entry for some asynchronous event.
    260  1.9.2.2  bouyer 		 */
    261  1.9.2.2  bouyer 		if (IS_FC(isp)) {
    262  1.9.2.2  bouyer 			isp_prt(isp, ISP_LOGTDEBUG1,
    263  1.9.2.2  bouyer 			    "Notify Ack status=0x%x seqid 0x%x",
    264  1.9.2.2  bouyer 			    nack_fcp->na_status, nack_fcp->na_seqid);
    265  1.9.2.2  bouyer 		} else {
    266  1.9.2.2  bouyer 			isp_prt(isp, ISP_LOGTDEBUG1,
    267  1.9.2.2  bouyer 			    "Notify Ack event 0x%x status=0x%x seqid 0x%x",
    268  1.9.2.2  bouyer 			    nackp->na_event, nackp->na_status, nackp->na_seqid);
    269  1.9.2.2  bouyer 		}
    270  1.9.2.2  bouyer 		break;
    271  1.9.2.2  bouyer 	default:
    272  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR,
    273  1.9.2.2  bouyer 		    "Unknown entry type 0x%x in isp_target_notify",
    274  1.9.2.2  bouyer 		    hdrp->rqs_entry_type);
    275  1.9.2.2  bouyer 		rval = -1;
    276  1.9.2.2  bouyer 		break;
    277  1.9.2.2  bouyer 	}
    278  1.9.2.2  bouyer #undef	atiop
    279  1.9.2.2  bouyer #undef	at2iop
    280  1.9.2.2  bouyer #undef	ctiop
    281  1.9.2.2  bouyer #undef	ct2iop
    282  1.9.2.2  bouyer #undef	lunenp
    283  1.9.2.2  bouyer #undef	inotp
    284  1.9.2.2  bouyer #undef	inot_fcp
    285  1.9.2.2  bouyer #undef	nackp
    286  1.9.2.2  bouyer #undef	nack_fcp
    287  1.9.2.2  bouyer #undef	hdrp
    288  1.9.2.2  bouyer 	return (rval);
    289  1.9.2.2  bouyer }
    290  1.9.2.2  bouyer 
    291  1.9.2.2  bouyer 
    292  1.9.2.2  bouyer /*
    293  1.9.2.2  bouyer  * Toggle (on/off) target mode for bus/target/lun
    294  1.9.2.2  bouyer  *
    295  1.9.2.2  bouyer  * The caller has checked for overlap and legality.
    296  1.9.2.2  bouyer  *
    297  1.9.2.2  bouyer  * Note that not all of bus, target or lun can be paid attention to.
    298  1.9.2.2  bouyer  * Note also that this action will not be complete until the f/w writes
    299  1.9.2.2  bouyer  * response entry. The caller is responsible for synchronizing this.
    300  1.9.2.2  bouyer  */
    301  1.9.2.2  bouyer int
    302  1.9.2.2  bouyer isp_lun_cmd(isp, cmd, bus, tgt, lun, opaque)
    303  1.9.2.2  bouyer 	struct ispsoftc *isp;
    304  1.9.2.2  bouyer 	int cmd;
    305  1.9.2.2  bouyer 	int bus;
    306  1.9.2.2  bouyer 	int tgt;
    307  1.9.2.2  bouyer 	int lun;
    308  1.9.2.2  bouyer 	u_int32_t opaque;
    309  1.9.2.2  bouyer {
    310  1.9.2.2  bouyer 	lun_entry_t el;
    311  1.9.2.2  bouyer 	u_int16_t iptr, optr;
    312  1.9.2.2  bouyer 	void *outp;
    313  1.9.2.2  bouyer 
    314  1.9.2.2  bouyer 
    315  1.9.2.2  bouyer 	MEMZERO(&el, sizeof (el));
    316  1.9.2.2  bouyer 	if (IS_DUALBUS(isp)) {
    317  1.9.2.2  bouyer 		el.le_rsvd = (bus & 0x1) << 7;
    318  1.9.2.2  bouyer 	}
    319  1.9.2.2  bouyer 	el.le_cmd_count = DFLT_CMD_CNT;
    320  1.9.2.2  bouyer 	el.le_in_count = DFLT_INOTIFY;
    321  1.9.2.2  bouyer 	if (cmd == RQSTYPE_ENABLE_LUN) {
    322  1.9.2.2  bouyer 		if (IS_SCSI(isp)) {
    323  1.9.2.2  bouyer 			el.le_flags = LUN_TQAE|LUN_DISAD;
    324  1.9.2.2  bouyer 			el.le_cdb6len = 12;
    325  1.9.2.2  bouyer 			el.le_cdb7len = 12;
    326  1.9.2.2  bouyer 		}
    327  1.9.2.2  bouyer 	} else if (cmd == -RQSTYPE_ENABLE_LUN) {
    328  1.9.2.2  bouyer 		cmd = RQSTYPE_ENABLE_LUN;
    329  1.9.2.2  bouyer 		el.le_cmd_count = 0;
    330  1.9.2.2  bouyer 		el.le_in_count = 0;
    331  1.9.2.2  bouyer 	} else if (cmd == -RQSTYPE_MODIFY_LUN) {
    332  1.9.2.2  bouyer 		cmd = RQSTYPE_MODIFY_LUN;
    333  1.9.2.2  bouyer 		el.le_ops = LUN_CCDECR | LUN_INDECR;
    334  1.9.2.2  bouyer 	} else {
    335  1.9.2.2  bouyer 		el.le_ops = LUN_CCINCR | LUN_ININCR;
    336  1.9.2.2  bouyer 	}
    337  1.9.2.2  bouyer 	el.le_header.rqs_entry_type = cmd;
    338  1.9.2.2  bouyer 	el.le_header.rqs_entry_count = 1;
    339  1.9.2.2  bouyer 	el.le_reserved = opaque;
    340  1.9.2.2  bouyer 	if (IS_SCSI(isp)) {
    341  1.9.2.2  bouyer 		el.le_tgt = tgt;
    342  1.9.2.2  bouyer 		el.le_lun = lun;
    343  1.9.2.2  bouyer 	} else if (isp->isp_maxluns <= 16) {
    344  1.9.2.2  bouyer 		el.le_lun = lun;
    345  1.9.2.2  bouyer 	}
    346  1.9.2.2  bouyer 
    347  1.9.2.2  bouyer 	if (isp_getrqentry(isp, &iptr, &optr, &outp)) {
    348  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGWARN,
    349  1.9.2.2  bouyer 		    "Request Queue Overflow in isp_lun_cmd");
    350  1.9.2.2  bouyer 		return (-1);
    351  1.9.2.2  bouyer 	}
    352  1.9.2.2  bouyer 	ISP_SWIZ_ENABLE_LUN(isp, outp, &el);
    353  1.9.2.2  bouyer 	ISP_TDQE(isp, "isp_lun_cmd", (int) optr, &el);
    354  1.9.2.2  bouyer 	ISP_ADD_REQUEST(isp, iptr);
    355  1.9.2.2  bouyer 	return (0);
    356  1.9.2.2  bouyer }
    357  1.9.2.2  bouyer 
    358  1.9.2.2  bouyer 
    359  1.9.2.2  bouyer int
    360  1.9.2.2  bouyer isp_target_put_entry(isp, ap)
    361  1.9.2.2  bouyer 	struct ispsoftc *isp;
    362  1.9.2.2  bouyer 	void *ap;
    363  1.9.2.2  bouyer {
    364  1.9.2.2  bouyer 	void *outp;
    365  1.9.2.2  bouyer 	u_int16_t iptr, optr;
    366  1.9.2.2  bouyer 	u_int8_t etype = ((isphdr_t *) ap)->rqs_entry_type;
    367  1.9.2.2  bouyer 
    368  1.9.2.2  bouyer 	if (isp_getrqentry(isp, &iptr, &optr, &outp)) {
    369  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGWARN,
    370  1.9.2.2  bouyer 		    "Request Queue Overflow in isp_target_put_entry");
    371  1.9.2.2  bouyer 		return (-1);
    372  1.9.2.2  bouyer 	}
    373  1.9.2.2  bouyer 	switch (etype) {
    374  1.9.2.2  bouyer 	case RQSTYPE_ATIO:
    375  1.9.2.2  bouyer 		ISP_SWIZ_ATIO(isp, outp, ap);
    376  1.9.2.2  bouyer 		break;
    377  1.9.2.2  bouyer 	case RQSTYPE_ATIO2:
    378  1.9.2.2  bouyer 		ISP_SWIZ_ATIO2(isp, outp, ap);
    379  1.9.2.2  bouyer 		break;
    380  1.9.2.2  bouyer 	case RQSTYPE_CTIO:
    381  1.9.2.2  bouyer 		ISP_SWIZ_CTIO(isp, outp, ap);
    382  1.9.2.2  bouyer 		break;
    383  1.9.2.2  bouyer 	case RQSTYPE_CTIO2:
    384  1.9.2.2  bouyer 		ISP_SWIZ_CTIO2(isp, outp, ap);
    385  1.9.2.2  bouyer 		break;
    386  1.9.2.2  bouyer 	default:
    387  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR,
    388  1.9.2.2  bouyer 		    "Unknown type 0x%x in isp_put_entry", etype);
    389  1.9.2.2  bouyer 		return (-1);
    390  1.9.2.2  bouyer 	}
    391  1.9.2.2  bouyer 
    392  1.9.2.2  bouyer 	ISP_TDQE(isp, "isp_target_put_entry", (int) optr, ap);;
    393  1.9.2.2  bouyer 
    394  1.9.2.2  bouyer 	ISP_ADD_REQUEST(isp, iptr);
    395  1.9.2.2  bouyer 	return (0);
    396  1.9.2.2  bouyer }
    397  1.9.2.2  bouyer 
    398  1.9.2.2  bouyer int
    399  1.9.2.2  bouyer isp_target_put_atio(isp, iid, tgt, lun, ttype, tval)
    400  1.9.2.2  bouyer 	struct ispsoftc *isp;
    401  1.9.2.2  bouyer 	int iid;
    402  1.9.2.2  bouyer 	int tgt;
    403  1.9.2.2  bouyer 	int lun;
    404  1.9.2.2  bouyer 	int ttype;
    405  1.9.2.2  bouyer 	int tval;
    406  1.9.2.2  bouyer {
    407  1.9.2.2  bouyer 	union {
    408  1.9.2.2  bouyer 		at_entry_t _atio;
    409  1.9.2.2  bouyer 		at2_entry_t _atio2;
    410  1.9.2.2  bouyer 	} atun;
    411  1.9.2.2  bouyer 
    412  1.9.2.2  bouyer 	MEMZERO(&atun, sizeof atun);
    413  1.9.2.2  bouyer 	if (IS_FC(isp)) {
    414  1.9.2.2  bouyer 		atun._atio2.at_header.rqs_entry_type = RQSTYPE_ATIO2;
    415  1.9.2.2  bouyer 		atun._atio2.at_header.rqs_entry_count = 1;
    416  1.9.2.2  bouyer 		if (isp->isp_maxluns > 16) {
    417  1.9.2.2  bouyer 			atun._atio2.at_scclun = (u_int16_t) lun;
    418  1.9.2.2  bouyer 		} else {
    419  1.9.2.2  bouyer 			atun._atio2.at_lun = (u_int8_t) lun;
    420  1.9.2.2  bouyer 		}
    421  1.9.2.2  bouyer 		atun._atio2.at_status = CT_OK;
    422  1.9.2.2  bouyer 	} else {
    423  1.9.2.2  bouyer 		atun._atio.at_header.rqs_entry_type = RQSTYPE_ATIO;
    424  1.9.2.2  bouyer 		atun._atio.at_header.rqs_entry_count = 1;
    425  1.9.2.2  bouyer 		atun._atio.at_iid = iid;
    426  1.9.2.2  bouyer 		atun._atio.at_tgt = tgt;
    427  1.9.2.2  bouyer 		atun._atio.at_lun = lun;
    428  1.9.2.2  bouyer 		atun._atio.at_tag_type = ttype;
    429  1.9.2.2  bouyer 		atun._atio.at_tag_val = tval;
    430  1.9.2.2  bouyer 		atun._atio.at_status = CT_OK;
    431  1.9.2.2  bouyer 	}
    432  1.9.2.2  bouyer 	return (isp_target_put_entry(isp, &atun));
    433  1.9.2.2  bouyer }
    434  1.9.2.2  bouyer 
    435  1.9.2.2  bouyer /*
    436  1.9.2.2  bouyer  * Command completion- both for handling cases of no resources or
    437  1.9.2.2  bouyer  * no blackhole driver, or other cases where we have to, inline,
    438  1.9.2.2  bouyer  * finish the command sanely, or for normal command completion.
    439  1.9.2.2  bouyer  *
    440  1.9.2.2  bouyer  * The 'completion' code value has the scsi status byte in the low 8 bits.
    441  1.9.2.2  bouyer  * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have
    442  1.9.2.2  bouyer  * the sense key and  bits 16..23 have the ASCQ and bits 24..31 have the ASC
    443  1.9.2.2  bouyer  * values.
    444  1.9.2.2  bouyer  *
    445  1.9.2.2  bouyer  * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't
    446  1.9.2.2  bouyer  * NB: inline SCSI sense reporting.
    447  1.9.2.2  bouyer  *
    448  1.9.2.2  bouyer  * For both parallel && fibre channel, we use the feature that does
    449  1.9.2.2  bouyer  * an automatic resource autoreplenish so we don't have then later do
    450  1.9.2.2  bouyer  * put of an atio to replenish the f/w's resource count.
    451  1.9.2.2  bouyer  */
    452  1.9.2.2  bouyer 
    453  1.9.2.2  bouyer int
    454  1.9.2.2  bouyer isp_endcmd(struct ispsoftc *isp, void *arg, u_int32_t code, u_int32_t hdl)
    455  1.9.2.2  bouyer {
    456  1.9.2.2  bouyer 	int sts;
    457  1.9.2.2  bouyer 	union {
    458  1.9.2.2  bouyer 		ct_entry_t _ctio;
    459  1.9.2.2  bouyer 		ct2_entry_t _ctio2;
    460  1.9.2.2  bouyer 	} un;
    461  1.9.2.2  bouyer 
    462  1.9.2.2  bouyer 	MEMZERO(&un, sizeof un);
    463  1.9.2.2  bouyer 	sts = code & 0xff;
    464  1.9.2.2  bouyer 
    465  1.9.2.2  bouyer 	if (IS_FC(isp)) {
    466  1.9.2.2  bouyer 		at2_entry_t *aep = arg;
    467  1.9.2.2  bouyer 		ct2_entry_t *cto = &un._ctio2;
    468  1.9.2.2  bouyer 
    469  1.9.2.2  bouyer 		cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
    470  1.9.2.2  bouyer 		cto->ct_header.rqs_entry_count = 1;
    471  1.9.2.2  bouyer 		cto->ct_iid = aep->at_iid;
    472  1.9.2.2  bouyer 		if (isp->isp_maxluns <= 16) {
    473  1.9.2.2  bouyer 			cto->ct_lun = aep->at_lun;
    474  1.9.2.2  bouyer 		}
    475  1.9.2.2  bouyer 		cto->ct_rxid = aep->at_rxid;
    476  1.9.2.2  bouyer 		cto->rsp.m1.ct_scsi_status = sts & 0xff;
    477  1.9.2.2  bouyer 		cto->ct_flags = CT2_SENDSTATUS | CT2_NO_DATA | CT2_FLAG_MODE1;
    478  1.9.2.2  bouyer 		if (hdl == 0) {
    479  1.9.2.2  bouyer 			cto->ct_flags |= CT2_CCINCR;
    480  1.9.2.2  bouyer 		}
    481  1.9.2.2  bouyer 		if (aep->at_datalen) {
    482  1.9.2.2  bouyer 			cto->ct_resid = aep->at_datalen;
    483  1.9.2.2  bouyer 			cto->ct_flags |= CT2_DATA_UNDER;
    484  1.9.2.2  bouyer 		}
    485  1.9.2.2  bouyer 		if ((sts & 0xff) == SCSI_CHECK && (sts & ECMD_SVALID)) {
    486  1.9.2.2  bouyer 			cto->rsp.m1.ct_resp[0] = 0xf0;
    487  1.9.2.2  bouyer 			cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
    488  1.9.2.2  bouyer 			cto->rsp.m1.ct_resp[7] = 8;
    489  1.9.2.2  bouyer 			cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff;
    490  1.9.2.2  bouyer 			cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff;
    491  1.9.2.2  bouyer 			cto->rsp.m1.ct_senselen = 16;
    492  1.9.2.2  bouyer 			cto->ct_flags |= CT2_SNSLEN_VALID;
    493  1.9.2.2  bouyer 		}
    494  1.9.2.2  bouyer 		cto->ct_reserved = hdl;
    495  1.9.2.2  bouyer 	} else {
    496  1.9.2.2  bouyer 		at_entry_t *aep = arg;
    497  1.9.2.2  bouyer 		ct_entry_t *cto = &un._ctio;
    498  1.9.2.2  bouyer 
    499  1.9.2.2  bouyer 		cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
    500  1.9.2.2  bouyer 		cto->ct_header.rqs_entry_count = 1;
    501  1.9.2.2  bouyer 		cto->ct_iid = aep->at_iid;
    502  1.9.2.2  bouyer 		cto->ct_tgt = aep->at_tgt;
    503  1.9.2.2  bouyer 		cto->ct_lun = aep->at_lun;
    504  1.9.2.2  bouyer 		cto->ct_tag_type = aep->at_tag_type;
    505  1.9.2.2  bouyer 		cto->ct_tag_val = aep->at_tag_val;
    506  1.9.2.2  bouyer 		cto->ct_flags = CT_SENDSTATUS | CT_NO_DATA;
    507  1.9.2.2  bouyer 		if (hdl == 0) {
    508  1.9.2.2  bouyer 			cto->ct_flags |= CT_CCINCR;
    509  1.9.2.2  bouyer 		}
    510  1.9.2.2  bouyer 		cto->ct_scsi_status = sts;
    511  1.9.2.2  bouyer 		cto->ct_reserved = hdl;
    512  1.9.2.2  bouyer 	}
    513  1.9.2.2  bouyer 	return (isp_target_put_entry(isp, &un));
    514  1.9.2.2  bouyer }
    515  1.9.2.2  bouyer 
    516  1.9.2.2  bouyer void
    517  1.9.2.2  bouyer isp_target_async(isp, bus, event)
    518  1.9.2.2  bouyer 	struct ispsoftc *isp;
    519  1.9.2.2  bouyer 	int bus;
    520  1.9.2.2  bouyer 	int event;
    521  1.9.2.2  bouyer {
    522  1.9.2.2  bouyer 	tmd_event_t evt;
    523  1.9.2.2  bouyer 	tmd_msg_t msg;
    524  1.9.2.2  bouyer 
    525  1.9.2.2  bouyer 	switch (event) {
    526  1.9.2.2  bouyer 	/*
    527  1.9.2.2  bouyer 	 * These three we handle here to propagate an effective bus reset
    528  1.9.2.2  bouyer 	 * upstream, but these do not require any immediate notify actions
    529  1.9.2.2  bouyer 	 * so we return when done.
    530  1.9.2.2  bouyer 	 */
    531  1.9.2.2  bouyer 	case ASYNC_LIP_OCCURRED:
    532  1.9.2.2  bouyer 	case ASYNC_LOOP_UP:
    533  1.9.2.2  bouyer 	case ASYNC_LOOP_DOWN:
    534  1.9.2.2  bouyer 		evt.ev_bus = bus;
    535  1.9.2.2  bouyer 		evt.ev_event = event;
    536  1.9.2.2  bouyer 		(void) isp_async(isp, ISPASYNC_TARGET_EVENT, &evt);
    537  1.9.2.2  bouyer 		return;
    538  1.9.2.2  bouyer 
    539  1.9.2.2  bouyer 	case ASYNC_LOOP_RESET:
    540  1.9.2.2  bouyer 	case ASYNC_BUS_RESET:
    541  1.9.2.2  bouyer 	case ASYNC_TIMEOUT_RESET:
    542  1.9.2.2  bouyer 		if (IS_FC(isp)) {
    543  1.9.2.2  bouyer 			return;	/* we'll be getting an inotify instead */
    544  1.9.2.2  bouyer 		}
    545  1.9.2.2  bouyer 		evt.ev_bus = bus;
    546  1.9.2.2  bouyer 		evt.ev_event = event;
    547  1.9.2.2  bouyer 		(void) isp_async(isp, ISPASYNC_TARGET_EVENT, &evt);
    548  1.9.2.2  bouyer 		break;
    549  1.9.2.2  bouyer 	case ASYNC_DEVICE_RESET:
    550  1.9.2.2  bouyer 		/*
    551  1.9.2.2  bouyer 		 * Bus Device Reset resets a specific target, so
    552  1.9.2.2  bouyer 		 * we pass this as a synthesized message.
    553  1.9.2.2  bouyer 		 */
    554  1.9.2.2  bouyer 		MEMZERO(&msg, sizeof msg);
    555  1.9.2.2  bouyer 		if (IS_FC(isp)) {
    556  1.9.2.2  bouyer 			msg.nt_iid = FCPARAM(isp)->isp_loopid;
    557  1.9.2.2  bouyer 		} else {
    558  1.9.2.2  bouyer 			msg.nt_iid = SDPARAM(isp)->isp_initiator_id;
    559  1.9.2.2  bouyer 		}
    560  1.9.2.2  bouyer 		msg.nt_bus = bus;
    561  1.9.2.2  bouyer 		msg.nt_msg[0] = MSG_BUS_DEV_RESET;
    562  1.9.2.2  bouyer 		(void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg);
    563  1.9.2.2  bouyer 		break;
    564  1.9.2.2  bouyer 	default:
    565  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR,
    566  1.9.2.2  bouyer 		    "isp_target_async: unknown event 0x%x", event);
    567  1.9.2.2  bouyer 		break;
    568  1.9.2.2  bouyer 	}
    569  1.9.2.2  bouyer 	if (isp->isp_state == ISP_RUNSTATE)
    570  1.9.2.2  bouyer 		isp_notify_ack(isp, NULL);
    571  1.9.2.2  bouyer }
    572  1.9.2.2  bouyer 
    573  1.9.2.2  bouyer 
    574  1.9.2.2  bouyer /*
    575  1.9.2.2  bouyer  * Process a received message.
    576  1.9.2.2  bouyer  * The ISP firmware can handle most messages, there are only
    577  1.9.2.2  bouyer  * a few that we need to deal with:
    578  1.9.2.2  bouyer  * - abort: clean up the current command
    579  1.9.2.2  bouyer  * - abort tag and clear queue
    580  1.9.2.2  bouyer  */
    581  1.9.2.2  bouyer 
    582  1.9.2.2  bouyer static void
    583  1.9.2.2  bouyer isp_got_msg(isp, bus, inp)
    584  1.9.2.2  bouyer 	struct ispsoftc *isp;
    585  1.9.2.2  bouyer 	int bus;
    586  1.9.2.2  bouyer 	in_entry_t *inp;
    587  1.9.2.2  bouyer {
    588  1.9.2.2  bouyer 	u_int8_t status = inp->in_status & ~QLTM_SVALID;
    589  1.9.2.2  bouyer 
    590  1.9.2.2  bouyer 	if (status == IN_IDE_RECEIVED || status == IN_MSG_RECEIVED) {
    591  1.9.2.2  bouyer 		tmd_msg_t msg;
    592  1.9.2.2  bouyer 
    593  1.9.2.2  bouyer 		MEMZERO(&msg, sizeof (msg));
    594  1.9.2.2  bouyer 		msg.nt_bus = bus;
    595  1.9.2.2  bouyer 		msg.nt_iid = inp->in_iid;
    596  1.9.2.2  bouyer 		msg.nt_tgt = inp->in_tgt;
    597  1.9.2.2  bouyer 		msg.nt_lun = inp->in_lun;
    598  1.9.2.2  bouyer 		msg.nt_tagtype = inp->in_tag_type;
    599  1.9.2.2  bouyer 		msg.nt_tagval = inp->in_tag_val;
    600  1.9.2.2  bouyer 		MEMCPY(msg.nt_msg, inp->in_msg, IN_MSGLEN);
    601  1.9.2.2  bouyer 		(void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg);
    602  1.9.2.2  bouyer 	} else {
    603  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR,
    604  1.9.2.2  bouyer 		    "unknown immediate notify status 0x%x", inp->in_status);
    605  1.9.2.2  bouyer 	}
    606  1.9.2.2  bouyer }
    607  1.9.2.2  bouyer 
    608  1.9.2.2  bouyer /*
    609  1.9.2.2  bouyer  * Synthesize a message from the task management flags in a FCP_CMND_IU.
    610  1.9.2.2  bouyer  */
    611  1.9.2.2  bouyer static void
    612  1.9.2.2  bouyer isp_got_msg_fc(isp, bus, inp)
    613  1.9.2.2  bouyer 	struct ispsoftc *isp;
    614  1.9.2.2  bouyer 	int bus;
    615  1.9.2.2  bouyer 	in_fcentry_t *inp;
    616  1.9.2.2  bouyer {
    617  1.9.2.2  bouyer 	static char *f1 = "%s from iid %d lun %d seq 0x%x";
    618  1.9.2.2  bouyer 	static char *f2 =
    619  1.9.2.2  bouyer 	    "unknown %s 0x%x lun %d iid %d task flags 0x%x seq 0x%x\n";
    620  1.9.2.2  bouyer 
    621  1.9.2.2  bouyer 	if (inp->in_status != IN_MSG_RECEIVED) {
    622  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGINFO, f2, "immediate notify status",
    623  1.9.2.2  bouyer 		    inp->in_status, inp->in_lun, inp->in_iid,
    624  1.9.2.2  bouyer 		    inp->in_task_flags,  inp->in_seqid);
    625  1.9.2.2  bouyer 	} else {
    626  1.9.2.2  bouyer 		tmd_msg_t msg;
    627  1.9.2.2  bouyer 
    628  1.9.2.2  bouyer 		MEMZERO(&msg, sizeof (msg));
    629  1.9.2.2  bouyer 		msg.nt_bus = bus;
    630  1.9.2.2  bouyer 		msg.nt_iid = inp->in_iid;
    631  1.9.2.2  bouyer 		if (isp->isp_maxluns > 16) {
    632  1.9.2.2  bouyer 			msg.nt_lun = inp->in_scclun;
    633  1.9.2.2  bouyer 		} else {
    634  1.9.2.2  bouyer 			msg.nt_lun = inp->in_lun;
    635  1.9.2.2  bouyer 		}
    636  1.9.2.2  bouyer 		msg.nt_tagval = inp->in_seqid;
    637  1.9.2.2  bouyer 
    638  1.9.2.2  bouyer 		if (inp->in_task_flags & TASK_FLAGS_ABORT_TASK) {
    639  1.9.2.2  bouyer 			isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK",
    640  1.9.2.2  bouyer 			    inp->in_iid, inp->in_lun, inp->in_seqid);
    641  1.9.2.2  bouyer 			msg.nt_msg[0] = MSG_ABORT_TAG;
    642  1.9.2.2  bouyer 		} else if (inp->in_task_flags & TASK_FLAGS_CLEAR_TASK_SET) {
    643  1.9.2.2  bouyer 			isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET",
    644  1.9.2.2  bouyer 			    inp->in_iid, inp->in_lun, inp->in_seqid);
    645  1.9.2.2  bouyer 			msg.nt_msg[0] = MSG_CLEAR_QUEUE;
    646  1.9.2.2  bouyer 		} else if (inp->in_task_flags & TASK_FLAGS_TARGET_RESET) {
    647  1.9.2.2  bouyer 			isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET",
    648  1.9.2.2  bouyer 			    inp->in_iid, inp->in_lun, inp->in_seqid);
    649  1.9.2.2  bouyer 			msg.nt_msg[0] = MSG_BUS_DEV_RESET;
    650  1.9.2.2  bouyer 		} else if (inp->in_task_flags & TASK_FLAGS_CLEAR_ACA) {
    651  1.9.2.2  bouyer 			isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA",
    652  1.9.2.2  bouyer 			    inp->in_iid, inp->in_lun, inp->in_seqid);
    653  1.9.2.2  bouyer 			/* ???? */
    654  1.9.2.2  bouyer 			msg.nt_msg[0] = MSG_REL_RECOVERY;
    655  1.9.2.2  bouyer 		} else if (inp->in_task_flags & TASK_FLAGS_TERMINATE_TASK) {
    656  1.9.2.2  bouyer 			isp_prt(isp, ISP_LOGINFO, f1, "TERMINATE TASK",
    657  1.9.2.2  bouyer 			    inp->in_iid, inp->in_lun, inp->in_seqid);
    658  1.9.2.2  bouyer 			msg.nt_msg[0] = MSG_TERM_IO_PROC;
    659  1.9.2.2  bouyer 		} else {
    660  1.9.2.2  bouyer 			isp_prt(isp, ISP_LOGWARN, f2, "task flag",
    661  1.9.2.2  bouyer 			    inp->in_status, inp->in_lun, inp->in_iid,
    662  1.9.2.2  bouyer 			    inp->in_task_flags,  inp->in_seqid);
    663  1.9.2.2  bouyer 		}
    664  1.9.2.2  bouyer 		if (msg.nt_msg[0]) {
    665  1.9.2.2  bouyer 			(void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg);
    666  1.9.2.2  bouyer 		}
    667  1.9.2.2  bouyer 	}
    668  1.9.2.2  bouyer }
    669  1.9.2.2  bouyer 
    670  1.9.2.2  bouyer static void
    671  1.9.2.2  bouyer isp_notify_ack(isp, arg)
    672  1.9.2.2  bouyer 	struct ispsoftc *isp;
    673  1.9.2.2  bouyer 	void *arg;
    674  1.9.2.2  bouyer {
    675  1.9.2.2  bouyer 	char storage[QENTRY_LEN];
    676  1.9.2.2  bouyer 	u_int16_t iptr, optr;
    677  1.9.2.2  bouyer 	void *outp;
    678  1.9.2.2  bouyer 
    679  1.9.2.2  bouyer 	if (isp_getrqentry(isp, &iptr, &optr, &outp)) {
    680  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGWARN,
    681  1.9.2.2  bouyer 		    "Request Queue Overflow For isp_notify_ack");
    682  1.9.2.2  bouyer 		return;
    683  1.9.2.2  bouyer 	}
    684  1.9.2.2  bouyer 
    685  1.9.2.2  bouyer 	MEMZERO(storage, QENTRY_LEN);
    686  1.9.2.2  bouyer 
    687  1.9.2.2  bouyer 	if (IS_FC(isp)) {
    688  1.9.2.2  bouyer 		na_fcentry_t *na = (na_fcentry_t *) storage;
    689  1.9.2.2  bouyer 		if (arg) {
    690  1.9.2.2  bouyer 			in_fcentry_t *inp = arg;
    691  1.9.2.2  bouyer 			MEMCPY(storage, arg, sizeof (isphdr_t));
    692  1.9.2.2  bouyer 			na->na_iid = inp->in_iid;
    693  1.9.2.2  bouyer 			if (isp->isp_maxluns > 16) {
    694  1.9.2.2  bouyer 				na->na_lun = inp->in_scclun;
    695  1.9.2.2  bouyer 			} else {
    696  1.9.2.2  bouyer 				na->na_lun = inp->in_lun;
    697  1.9.2.2  bouyer 			}
    698  1.9.2.2  bouyer 			na->na_task_flags = inp->in_task_flags;
    699  1.9.2.2  bouyer 			na->na_seqid = inp->in_seqid;
    700  1.9.2.2  bouyer 			na->na_flags = NAFC_RCOUNT;
    701  1.9.2.2  bouyer 			if (inp->in_status == IN_RESET) {
    702  1.9.2.2  bouyer 				na->na_flags |= NAFC_RST_CLRD;
    703  1.9.2.2  bouyer 			}
    704  1.9.2.2  bouyer 		} else {
    705  1.9.2.2  bouyer 			na->na_flags = NAFC_RST_CLRD;
    706  1.9.2.2  bouyer 		}
    707  1.9.2.2  bouyer 		na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
    708  1.9.2.2  bouyer 		na->na_header.rqs_entry_count = 1;
    709  1.9.2.2  bouyer 		ISP_SWIZ_NOT_ACK_FC(isp, outp, na);
    710  1.9.2.2  bouyer 	} else {
    711  1.9.2.2  bouyer 		na_entry_t *na = (na_entry_t *) storage;
    712  1.9.2.2  bouyer 		if (arg) {
    713  1.9.2.2  bouyer 			in_entry_t *inp = arg;
    714  1.9.2.2  bouyer 			MEMCPY(storage, arg, sizeof (isphdr_t));
    715  1.9.2.2  bouyer 			na->na_iid = inp->in_iid;
    716  1.9.2.2  bouyer 			na->na_lun = inp->in_lun;
    717  1.9.2.2  bouyer 			na->na_tgt = inp->in_tgt;
    718  1.9.2.2  bouyer 			na->na_seqid = inp->in_seqid;
    719  1.9.2.2  bouyer 			if (inp->in_status == IN_RESET) {
    720  1.9.2.2  bouyer 				na->na_event = NA_RST_CLRD;
    721  1.9.2.2  bouyer 			}
    722  1.9.2.2  bouyer 		} else {
    723  1.9.2.2  bouyer 			na->na_event = NA_RST_CLRD;
    724  1.9.2.2  bouyer 		}
    725  1.9.2.2  bouyer 		na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
    726  1.9.2.2  bouyer 		na->na_header.rqs_entry_count = 1;
    727  1.9.2.2  bouyer 		ISP_SWIZ_NOT_ACK(isp, outp, na);
    728  1.9.2.2  bouyer 	}
    729  1.9.2.2  bouyer 	ISP_TDQE(isp, "isp_notify_ack", (int) optr, storage);
    730  1.9.2.2  bouyer 	ISP_ADD_REQUEST(isp, iptr);
    731  1.9.2.2  bouyer }
    732  1.9.2.2  bouyer 
    733  1.9.2.2  bouyer static void
    734  1.9.2.2  bouyer isp_handle_atio(isp, aep)
    735  1.9.2.2  bouyer 	struct ispsoftc *isp;
    736  1.9.2.2  bouyer 	at_entry_t *aep;
    737  1.9.2.2  bouyer {
    738  1.9.2.2  bouyer 	int lun;
    739  1.9.2.2  bouyer 	lun = aep->at_lun;
    740  1.9.2.2  bouyer 	/*
    741  1.9.2.2  bouyer 	 * The firmware status (except for the QLTM_SVALID bit) indicates
    742  1.9.2.2  bouyer 	 * why this ATIO was sent to us.
    743  1.9.2.2  bouyer 	 *
    744  1.9.2.2  bouyer 	 * If QLTM_SVALID is set, the firware has recommended Sense Data.
    745  1.9.2.2  bouyer 	 *
    746  1.9.2.2  bouyer 	 * If the DISCONNECTS DISABLED bit is set in the flags field,
    747  1.9.2.2  bouyer 	 * we're still connected on the SCSI bus - i.e. the initiator
    748  1.9.2.2  bouyer 	 * did not set DiscPriv in the identify message. We don't care
    749  1.9.2.2  bouyer 	 * about this so it's ignored.
    750  1.9.2.2  bouyer 	 */
    751  1.9.2.2  bouyer 
    752  1.9.2.2  bouyer 	switch(aep->at_status & ~QLTM_SVALID) {
    753  1.9.2.2  bouyer 	case AT_PATH_INVALID:
    754  1.9.2.2  bouyer 		/*
    755  1.9.2.2  bouyer 		 * ATIO rejected by the firmware due to disabled lun.
    756  1.9.2.2  bouyer 		 */
    757  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR,
    758  1.9.2.2  bouyer 		    "rejected ATIO for disabled lun %d", lun);
    759  1.9.2.2  bouyer 		break;
    760  1.9.2.2  bouyer 	case AT_NOCAP:
    761  1.9.2.2  bouyer 		/*
    762  1.9.2.2  bouyer 		 * Requested Capability not available
    763  1.9.2.2  bouyer 		 * We sent an ATIO that overflowed the firmware's
    764  1.9.2.2  bouyer 		 * command resource count.
    765  1.9.2.2  bouyer 		 */
    766  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR,
    767  1.9.2.2  bouyer 		    "rejected ATIO for lun %d because of command count"
    768  1.9.2.2  bouyer 		    " overflow", lun);
    769  1.9.2.2  bouyer 		break;
    770  1.9.2.2  bouyer 
    771  1.9.2.2  bouyer 	case AT_BDR_MSG:
    772  1.9.2.2  bouyer 		/*
    773  1.9.2.2  bouyer 		 * If we send an ATIO to the firmware to increment
    774  1.9.2.2  bouyer 		 * its command resource count, and the firmware is
    775  1.9.2.2  bouyer 		 * recovering from a Bus Device Reset, it returns
    776  1.9.2.2  bouyer 		 * the ATIO with this status. We set the command
    777  1.9.2.2  bouyer 		 * resource count in the Enable Lun entry and no
    778  1.9.2.2  bouyer 		 * not increment it. Therefore we should never get
    779  1.9.2.2  bouyer 		 * this status here.
    780  1.9.2.2  bouyer 		 */
    781  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR, atiocope, lun);
    782  1.9.2.2  bouyer 		break;
    783  1.9.2.2  bouyer 
    784  1.9.2.2  bouyer 	case AT_CDB:		/* Got a CDB */
    785  1.9.2.2  bouyer 	case AT_PHASE_ERROR:	/* Bus Phase Sequence Error */
    786  1.9.2.2  bouyer 		/*
    787  1.9.2.2  bouyer 		 * Punt to platform specific layer.
    788  1.9.2.2  bouyer 		 */
    789  1.9.2.2  bouyer 		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
    790  1.9.2.2  bouyer 		break;
    791  1.9.2.2  bouyer 
    792  1.9.2.2  bouyer 	case AT_RESET:
    793  1.9.2.2  bouyer 		/*
    794  1.9.2.2  bouyer 		 * A bus reset came along an blew away this command. Why
    795  1.9.2.2  bouyer 		 * they do this in addition the async event code stuff,
    796  1.9.2.2  bouyer 		 * I dunno.
    797  1.9.2.2  bouyer 		 *
    798  1.9.2.2  bouyer 		 * Ignore it because the async event will clear things
    799  1.9.2.2  bouyer 		 * up for us.
    800  1.9.2.2  bouyer 		 */
    801  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGWARN, atior, lun, aep->at_iid);
    802  1.9.2.2  bouyer 		break;
    803  1.9.2.2  bouyer 
    804  1.9.2.2  bouyer 
    805  1.9.2.2  bouyer 	default:
    806  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR,
    807  1.9.2.2  bouyer 		    "Unknown ATIO status 0x%x from initiator %d for lun %d",
    808  1.9.2.2  bouyer 		    aep->at_status, aep->at_iid, lun);
    809  1.9.2.2  bouyer 		(void) isp_target_put_atio(isp, aep->at_iid, aep->at_tgt,
    810  1.9.2.2  bouyer 		    lun, aep->at_tag_type, aep->at_tag_val);
    811  1.9.2.2  bouyer 		break;
    812  1.9.2.2  bouyer 	}
    813  1.9.2.2  bouyer }
    814  1.9.2.2  bouyer 
    815  1.9.2.2  bouyer static void
    816  1.9.2.2  bouyer isp_handle_atio2(isp, aep)
    817  1.9.2.2  bouyer 	struct ispsoftc *isp;
    818  1.9.2.2  bouyer 	at2_entry_t *aep;
    819  1.9.2.2  bouyer {
    820  1.9.2.2  bouyer 	int lun;
    821  1.9.2.2  bouyer 
    822  1.9.2.2  bouyer 	if (isp->isp_maxluns > 16) {
    823  1.9.2.2  bouyer 		lun = aep->at_scclun;
    824  1.9.2.2  bouyer 	} else {
    825  1.9.2.2  bouyer 		lun = aep->at_lun;
    826  1.9.2.2  bouyer 	}
    827  1.9.2.2  bouyer 
    828  1.9.2.2  bouyer 	/*
    829  1.9.2.2  bouyer 	 * The firmware status (except for the QLTM_SVALID bit) indicates
    830  1.9.2.2  bouyer 	 * why this ATIO was sent to us.
    831  1.9.2.2  bouyer 	 *
    832  1.9.2.2  bouyer 	 * If QLTM_SVALID is set, the firware has recommended Sense Data.
    833  1.9.2.2  bouyer 	 *
    834  1.9.2.2  bouyer 	 * If the DISCONNECTS DISABLED bit is set in the flags field,
    835  1.9.2.2  bouyer 	 * we're still connected on the SCSI bus - i.e. the initiator
    836  1.9.2.2  bouyer 	 * did not set DiscPriv in the identify message. We don't care
    837  1.9.2.2  bouyer 	 * about this so it's ignored.
    838  1.9.2.2  bouyer 	 */
    839  1.9.2.2  bouyer 
    840  1.9.2.2  bouyer 	switch(aep->at_status & ~QLTM_SVALID) {
    841  1.9.2.2  bouyer 	case AT_PATH_INVALID:
    842  1.9.2.2  bouyer 		/*
    843  1.9.2.2  bouyer 		 * ATIO rejected by the firmware due to disabled lun.
    844  1.9.2.2  bouyer 		 */
    845  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR,
    846  1.9.2.2  bouyer 		    "rejected ATIO2 for disabled lun %d", lun);
    847  1.9.2.2  bouyer 		break;
    848  1.9.2.2  bouyer 	case AT_NOCAP:
    849  1.9.2.2  bouyer 		/*
    850  1.9.2.2  bouyer 		 * Requested Capability not available
    851  1.9.2.2  bouyer 		 * We sent an ATIO that overflowed the firmware's
    852  1.9.2.2  bouyer 		 * command resource count.
    853  1.9.2.2  bouyer 		 */
    854  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR,
    855  1.9.2.2  bouyer 		    "rejected ATIO2 for lun %d- command count overflow", lun);
    856  1.9.2.2  bouyer 		break;
    857  1.9.2.2  bouyer 
    858  1.9.2.2  bouyer 	case AT_BDR_MSG:
    859  1.9.2.2  bouyer 		/*
    860  1.9.2.2  bouyer 		 * If we send an ATIO to the firmware to increment
    861  1.9.2.2  bouyer 		 * its command resource count, and the firmware is
    862  1.9.2.2  bouyer 		 * recovering from a Bus Device Reset, it returns
    863  1.9.2.2  bouyer 		 * the ATIO with this status. We set the command
    864  1.9.2.2  bouyer 		 * resource count in the Enable Lun entry and no
    865  1.9.2.2  bouyer 		 * not increment it. Therefore we should never get
    866  1.9.2.2  bouyer 		 * this status here.
    867  1.9.2.2  bouyer 		 */
    868  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR, atiocope, lun);
    869  1.9.2.2  bouyer 		break;
    870  1.9.2.2  bouyer 
    871  1.9.2.2  bouyer 	case AT_CDB:		/* Got a CDB */
    872  1.9.2.2  bouyer 		/*
    873  1.9.2.2  bouyer 		 * Punt to platform specific layer.
    874  1.9.2.2  bouyer 		 */
    875  1.9.2.2  bouyer 		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
    876  1.9.2.2  bouyer 		break;
    877  1.9.2.2  bouyer 
    878  1.9.2.2  bouyer 	case AT_RESET:
    879  1.9.2.2  bouyer 		/*
    880  1.9.2.2  bouyer 		 * A bus reset came along an blew away this command. Why
    881  1.9.2.2  bouyer 		 * they do this in addition the async event code stuff,
    882  1.9.2.2  bouyer 		 * I dunno.
    883  1.9.2.2  bouyer 		 *
    884  1.9.2.2  bouyer 		 * Ignore it because the async event will clear things
    885  1.9.2.2  bouyer 		 * up for us.
    886  1.9.2.2  bouyer 		 */
    887  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR, atior, lun, aep->at_iid);
    888  1.9.2.2  bouyer 		break;
    889  1.9.2.2  bouyer 
    890  1.9.2.2  bouyer 
    891  1.9.2.2  bouyer 	default:
    892  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR,
    893  1.9.2.2  bouyer 		    "Unknown ATIO2 status 0x%x from initiator %d for lun %d",
    894  1.9.2.2  bouyer 		    aep->at_status, aep->at_iid, lun);
    895  1.9.2.2  bouyer 		(void) isp_target_put_atio(isp, aep->at_iid, 0, lun, 0, 0);
    896  1.9.2.2  bouyer 		break;
    897  1.9.2.2  bouyer 	}
    898  1.9.2.2  bouyer }
    899  1.9.2.2  bouyer 
    900  1.9.2.2  bouyer static void
    901  1.9.2.2  bouyer isp_handle_ctio(isp, ct)
    902  1.9.2.2  bouyer 	struct ispsoftc *isp;
    903  1.9.2.2  bouyer 	ct_entry_t *ct;
    904  1.9.2.2  bouyer {
    905  1.9.2.2  bouyer 	XS_T *xs;
    906  1.9.2.2  bouyer 	int pl = ISP_LOGTDEBUG2;
    907  1.9.2.2  bouyer 	char *fmsg = NULL;
    908  1.9.2.2  bouyer 
    909  1.9.2.2  bouyer 	if (ct->ct_reserved) {
    910  1.9.2.2  bouyer 		xs = isp_find_xs(isp, ct->ct_reserved);
    911  1.9.2.2  bouyer 		if (xs == NULL)
    912  1.9.2.2  bouyer 			pl = ISP_LOGALL;
    913  1.9.2.2  bouyer 	} else {
    914  1.9.2.2  bouyer 		pl = ISP_LOGTDEBUG1;
    915  1.9.2.2  bouyer 		xs = NULL;
    916  1.9.2.2  bouyer 	}
    917  1.9.2.2  bouyer 
    918  1.9.2.2  bouyer 	switch(ct->ct_status & ~QLTM_SVALID) {
    919  1.9.2.2  bouyer 	case CT_OK:
    920  1.9.2.2  bouyer 		/*
    921  1.9.2.2  bouyer 		 * There are generally 3 possibilities as to why we'd get
    922  1.9.2.2  bouyer 		 * this condition:
    923  1.9.2.2  bouyer 		 * 	We disconnected after receiving a CDB.
    924  1.9.2.2  bouyer 		 * 	We sent or received data.
    925  1.9.2.2  bouyer 		 * 	We sent status & command complete.
    926  1.9.2.2  bouyer 		 */
    927  1.9.2.2  bouyer 
    928  1.9.2.2  bouyer 		if (ct->ct_flags & CT_SENDSTATUS) {
    929  1.9.2.2  bouyer 			break;
    930  1.9.2.2  bouyer 		} else if ((ct->ct_flags & CT_DATAMASK) == CT_NO_DATA) {
    931  1.9.2.2  bouyer 			/*
    932  1.9.2.2  bouyer 			 * Nothing to do in this case.
    933  1.9.2.2  bouyer 			 */
    934  1.9.2.2  bouyer 			isp_prt(isp, pl, "CTIO- iid %d disconnected OK",
    935  1.9.2.2  bouyer 			    ct->ct_iid);
    936  1.9.2.2  bouyer 			return;
    937  1.9.2.2  bouyer 		}
    938  1.9.2.2  bouyer 		break;
    939  1.9.2.2  bouyer 
    940  1.9.2.2  bouyer 	case CT_BDR_MSG:
    941  1.9.2.2  bouyer 		/*
    942  1.9.2.2  bouyer 		 * Bus Device Reset message received or the SCSI Bus has
    943  1.9.2.2  bouyer 		 * been Reset; the firmware has gone to Bus Free.
    944  1.9.2.2  bouyer 		 *
    945  1.9.2.2  bouyer 		 * The firmware generates an async mailbox interupt to
    946  1.9.2.2  bouyer 		 * notify us of this and returns outstanding CTIOs with this
    947  1.9.2.2  bouyer 		 * status. These CTIOs are handled in that same way as
    948  1.9.2.2  bouyer 		 * CT_ABORTED ones, so just fall through here.
    949  1.9.2.2  bouyer 		 */
    950  1.9.2.2  bouyer 		fmsg = "Bus Device Reset";
    951  1.9.2.2  bouyer 		/*FALLTHROUGH*/
    952  1.9.2.2  bouyer 	case CT_RESET:
    953  1.9.2.2  bouyer 		if (fmsg == NULL)
    954  1.9.2.2  bouyer 			fmsg = "Bus Reset";
    955  1.9.2.2  bouyer 		/*FALLTHROUGH*/
    956  1.9.2.2  bouyer 	case CT_ABORTED:
    957  1.9.2.2  bouyer 		/*
    958  1.9.2.2  bouyer 		 * When an Abort message is received the firmware goes to
    959  1.9.2.2  bouyer 		 * Bus Free and returns all outstanding CTIOs with the status
    960  1.9.2.2  bouyer 		 * set, then sends us an Immediate Notify entry.
    961  1.9.2.2  bouyer 		 */
    962  1.9.2.2  bouyer 		if (fmsg == NULL)
    963  1.9.2.2  bouyer 			fmsg = "ABORT TASK sent by Initiator";
    964  1.9.2.2  bouyer 
    965  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGWARN, "CTIO destroyed by %s", fmsg);
    966  1.9.2.2  bouyer 		break;
    967  1.9.2.2  bouyer 
    968  1.9.2.2  bouyer 	case CT_INVAL:
    969  1.9.2.2  bouyer 		/*
    970  1.9.2.2  bouyer 		 * CTIO rejected by the firmware due to disabled lun.
    971  1.9.2.2  bouyer 		 * "Cannot Happen".
    972  1.9.2.2  bouyer 		 */
    973  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR,
    974  1.9.2.2  bouyer 		    "Firmware rejected CTIO for disabled lun %d",
    975  1.9.2.2  bouyer 		    ct->ct_lun);
    976  1.9.2.2  bouyer 		break;
    977  1.9.2.2  bouyer 
    978  1.9.2.2  bouyer 	case CT_NOPATH:
    979  1.9.2.2  bouyer 		/*
    980  1.9.2.2  bouyer 		 * CTIO rejected by the firmware due "no path for the
    981  1.9.2.2  bouyer 		 * nondisconnecting nexus specified". This means that
    982  1.9.2.2  bouyer 		 * we tried to access the bus while a non-disconnecting
    983  1.9.2.2  bouyer 		 * command is in process.
    984  1.9.2.2  bouyer 		 */
    985  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR,
    986  1.9.2.2  bouyer 		    "Firmware rejected CTIO for bad nexus %d/%d/%d",
    987  1.9.2.2  bouyer 		    ct->ct_iid, ct->ct_tgt, ct->ct_lun);
    988  1.9.2.2  bouyer 		break;
    989  1.9.2.2  bouyer 
    990  1.9.2.2  bouyer 	case CT_RSELTMO:
    991  1.9.2.2  bouyer 		fmsg = "Reselection";
    992  1.9.2.2  bouyer 		/*FALLTHROUGH*/
    993  1.9.2.2  bouyer 	case CT_TIMEOUT:
    994  1.9.2.2  bouyer 		if (fmsg == NULL)
    995  1.9.2.2  bouyer 			fmsg = "Command";
    996  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
    997  1.9.2.2  bouyer 		break;
    998  1.9.2.2  bouyer 
    999  1.9.2.2  bouyer 	case CT_ERR:
   1000  1.9.2.2  bouyer 		fmsg = "Completed with Error";
   1001  1.9.2.2  bouyer 		/*FALLTHROUGH*/
   1002  1.9.2.2  bouyer 	case CT_PHASE_ERROR:
   1003  1.9.2.2  bouyer 		if (fmsg == NULL)
   1004  1.9.2.2  bouyer 			fmsg = "Phase Sequence Error";
   1005  1.9.2.2  bouyer 		/*FALLTHROUGH*/
   1006  1.9.2.2  bouyer 	case CT_TERMINATED:
   1007  1.9.2.2  bouyer 		if (fmsg == NULL)
   1008  1.9.2.2  bouyer 			fmsg = "terminated by TERMINATE TRANSFER";
   1009  1.9.2.2  bouyer 		/*FALLTHROUGH*/
   1010  1.9.2.2  bouyer 	case CT_NOACK:
   1011  1.9.2.2  bouyer 		if (fmsg == NULL)
   1012  1.9.2.2  bouyer 			fmsg = "unacknowledged Immediate Notify pending";
   1013  1.9.2.2  bouyer 
   1014  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg);
   1015  1.9.2.2  bouyer #if	0
   1016  1.9.2.2  bouyer 			if (status & SENSEVALID) {
   1017  1.9.2.2  bouyer 				bcopy((caddr_t) (cep + CTIO_SENSE_OFFSET),
   1018  1.9.2.2  bouyer 				    (caddr_t) &cdp->cd_sensedata,
   1019  1.9.2.2  bouyer 				    sizeof(scsi_sense_t));
   1020  1.9.2.2  bouyer 				cdp->cd_flags |= CDF_SENSEVALID;
   1021  1.9.2.2  bouyer 			}
   1022  1.9.2.2  bouyer #endif
   1023  1.9.2.2  bouyer 		break;
   1024  1.9.2.2  bouyer 	default:
   1025  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR, "Unknown CTIO status 0x%x",
   1026  1.9.2.2  bouyer 		    ct->ct_status & ~QLTM_SVALID);
   1027  1.9.2.2  bouyer 		break;
   1028  1.9.2.2  bouyer 	}
   1029  1.9.2.2  bouyer 
   1030  1.9.2.2  bouyer 	if (xs == NULL) {
   1031  1.9.2.2  bouyer 		/*
   1032  1.9.2.2  bouyer 		 * There may be more than one CTIO for a data transfer,
   1033  1.9.2.2  bouyer 		 * or this may be a status CTIO we're not monitoring.
   1034  1.9.2.2  bouyer 		 *
   1035  1.9.2.2  bouyer 		 * The assumption is that they'll all be returned in the
   1036  1.9.2.2  bouyer 		 * order we got them.
   1037  1.9.2.2  bouyer 		 */
   1038  1.9.2.2  bouyer 		if (ct->ct_reserved == 0) {
   1039  1.9.2.2  bouyer 			if ((ct->ct_flags & CT_SENDSTATUS) == 0) {
   1040  1.9.2.2  bouyer 				isp_prt(isp, pl,
   1041  1.9.2.2  bouyer 				    "intermediate CTIO completed ok");
   1042  1.9.2.2  bouyer 			} else {
   1043  1.9.2.2  bouyer 				isp_prt(isp, pl,
   1044  1.9.2.2  bouyer 				    "unmonitored CTIO completed ok");
   1045  1.9.2.2  bouyer 			}
   1046  1.9.2.2  bouyer 		} else {
   1047  1.9.2.2  bouyer 			isp_prt(isp, pl,
   1048  1.9.2.2  bouyer 			    "NO xs for CTIO (handle 0x%x) status 0x%x",
   1049  1.9.2.2  bouyer 			    ct->ct_reserved, ct->ct_status & ~QLTM_SVALID);
   1050  1.9.2.2  bouyer 		}
   1051  1.9.2.2  bouyer 	} else {
   1052  1.9.2.2  bouyer 		if (ct->ct_flags & CT_SENDSTATUS) {
   1053  1.9.2.2  bouyer 			/*
   1054  1.9.2.2  bouyer 			 * Sent status and command complete.
   1055  1.9.2.2  bouyer 			 *
   1056  1.9.2.2  bouyer 			 * We're now really done with this command, so we
   1057  1.9.2.2  bouyer 			 * punt to the platform dependent layers because
   1058  1.9.2.2  bouyer 			 * only there can we do the appropriate command
   1059  1.9.2.2  bouyer 			 * complete thread synchronization.
   1060  1.9.2.2  bouyer 			 */
   1061  1.9.2.2  bouyer 			isp_prt(isp, pl, "status CTIO complete");
   1062  1.9.2.2  bouyer 		} else {
   1063  1.9.2.2  bouyer 			/*
   1064  1.9.2.2  bouyer 			 * Final CTIO completed. Release DMA resources and
   1065  1.9.2.2  bouyer 			 * notify platform dependent layers.
   1066  1.9.2.2  bouyer 			 */
   1067  1.9.2.2  bouyer 			isp_prt(isp, pl, "data CTIO complete");
   1068  1.9.2.2  bouyer 			ISP_DMAFREE(isp, xs, ct->ct_reserved);
   1069  1.9.2.2  bouyer 		}
   1070  1.9.2.2  bouyer 		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
   1071  1.9.2.2  bouyer 		/*
   1072  1.9.2.2  bouyer 		 * The platform layer will destroy the handle if appropriate.
   1073  1.9.2.2  bouyer 		 */
   1074  1.9.2.2  bouyer 	}
   1075  1.9.2.2  bouyer }
   1076  1.9.2.2  bouyer 
   1077  1.9.2.2  bouyer static void
   1078  1.9.2.2  bouyer isp_handle_ctio2(isp, ct)
   1079  1.9.2.2  bouyer 	struct ispsoftc *isp;
   1080  1.9.2.2  bouyer 	ct2_entry_t *ct;
   1081  1.9.2.2  bouyer {
   1082  1.9.2.2  bouyer 	XS_T *xs;
   1083  1.9.2.2  bouyer 	int pl = ISP_LOGTDEBUG2;
   1084  1.9.2.2  bouyer 	char *fmsg = NULL;
   1085  1.9.2.2  bouyer 
   1086  1.9.2.2  bouyer 	if (ct->ct_reserved) {
   1087  1.9.2.2  bouyer 		xs = isp_find_xs(isp, ct->ct_reserved);
   1088  1.9.2.2  bouyer 		if (xs == NULL)
   1089  1.9.2.2  bouyer 			pl = ISP_LOGALL;
   1090  1.9.2.2  bouyer 	} else {
   1091  1.9.2.2  bouyer 		pl = ISP_LOGTDEBUG1;
   1092  1.9.2.2  bouyer 		xs = NULL;
   1093  1.9.2.2  bouyer 	}
   1094  1.9.2.2  bouyer 
   1095  1.9.2.2  bouyer 	switch(ct->ct_status & ~QLTM_SVALID) {
   1096  1.9.2.2  bouyer 	case CT_OK:
   1097  1.9.2.2  bouyer 		/*
   1098  1.9.2.2  bouyer 		 * There are generally 2 possibilities as to why we'd get
   1099  1.9.2.2  bouyer 		 * this condition:
   1100  1.9.2.2  bouyer 		 * 	We sent or received data.
   1101  1.9.2.2  bouyer 		 * 	We sent status & command complete.
   1102  1.9.2.2  bouyer 		 */
   1103  1.9.2.2  bouyer 
   1104  1.9.2.2  bouyer 		break;
   1105  1.9.2.2  bouyer 
   1106  1.9.2.2  bouyer 	case CT_BDR_MSG:
   1107  1.9.2.2  bouyer 		/*
   1108  1.9.2.2  bouyer 		 * Bus Device Reset message received or the SCSI Bus has
   1109  1.9.2.2  bouyer 		 * been Reset; the firmware has gone to Bus Free.
   1110  1.9.2.2  bouyer 		 *
   1111  1.9.2.2  bouyer 		 * The firmware generates an async mailbox interupt to
   1112  1.9.2.2  bouyer 		 * notify us of this and returns outstanding CTIOs with this
   1113  1.9.2.2  bouyer 		 * status. These CTIOs are handled in that same way as
   1114  1.9.2.2  bouyer 		 * CT_ABORTED ones, so just fall through here.
   1115  1.9.2.2  bouyer 		 */
   1116  1.9.2.2  bouyer 		fmsg = "Bus Device Reset";
   1117  1.9.2.2  bouyer 		/*FALLTHROUGH*/
   1118  1.9.2.2  bouyer 	case CT_RESET:
   1119  1.9.2.2  bouyer 		if (fmsg == NULL)
   1120  1.9.2.2  bouyer 			fmsg = "Bus Reset";
   1121  1.9.2.2  bouyer 		/*FALLTHROUGH*/
   1122  1.9.2.2  bouyer 	case CT_ABORTED:
   1123  1.9.2.2  bouyer 		/*
   1124  1.9.2.2  bouyer 		 * When an Abort message is received the firmware goes to
   1125  1.9.2.2  bouyer 		 * Bus Free and returns all outstanding CTIOs with the status
   1126  1.9.2.2  bouyer 		 * set, then sends us an Immediate Notify entry.
   1127  1.9.2.2  bouyer 		 */
   1128  1.9.2.2  bouyer 		if (fmsg == NULL)
   1129  1.9.2.2  bouyer 			fmsg = "ABORT TASK sent by Initiator";
   1130  1.9.2.2  bouyer 
   1131  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR, "CTIO2 destroyed by %s", fmsg);
   1132  1.9.2.2  bouyer 		break;
   1133  1.9.2.2  bouyer 
   1134  1.9.2.2  bouyer 	case CT_INVAL:
   1135  1.9.2.2  bouyer 		/*
   1136  1.9.2.2  bouyer 		 * CTIO rejected by the firmware - invalid data direction.
   1137  1.9.2.2  bouyer 		 */
   1138  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR, "CTIO2 had wrong data directiond");
   1139  1.9.2.2  bouyer 		break;
   1140  1.9.2.2  bouyer 
   1141  1.9.2.2  bouyer 	case CT_NOPATH:
   1142  1.9.2.2  bouyer 		/*
   1143  1.9.2.2  bouyer 		 * CTIO rejected by the firmware due "no path for the
   1144  1.9.2.2  bouyer 		 * nondisconnecting nexus specified". This means that
   1145  1.9.2.2  bouyer 		 * we tried to access the bus while a non-disconnecting
   1146  1.9.2.2  bouyer 		 * command is in process.
   1147  1.9.2.2  bouyer 		 */
   1148  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR,
   1149  1.9.2.2  bouyer 		    "Firmware rejected CTIO2 for bad nexus %d->%d",
   1150  1.9.2.2  bouyer 		    ct->ct_iid, ct->ct_lun);
   1151  1.9.2.2  bouyer 		break;
   1152  1.9.2.2  bouyer 
   1153  1.9.2.2  bouyer 	case CT_RSELTMO:
   1154  1.9.2.2  bouyer 		fmsg = "Reselection";
   1155  1.9.2.2  bouyer 		/*FALLTHROUGH*/
   1156  1.9.2.2  bouyer 	case CT_TIMEOUT:
   1157  1.9.2.2  bouyer 		if (fmsg == NULL)
   1158  1.9.2.2  bouyer 			fmsg = "Command";
   1159  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
   1160  1.9.2.2  bouyer 		break;
   1161  1.9.2.2  bouyer 
   1162  1.9.2.2  bouyer 	case CT_ERR:
   1163  1.9.2.2  bouyer 		fmsg = "Completed with Error";
   1164  1.9.2.2  bouyer 		/*FALLTHROUGH*/
   1165  1.9.2.2  bouyer 	case CT_PHASE_ERROR:	/* Bus phase sequence error */
   1166  1.9.2.2  bouyer 		if (fmsg == NULL)
   1167  1.9.2.2  bouyer 			fmsg = "Phase Sequence Error";
   1168  1.9.2.2  bouyer 		/*FALLTHROUGH*/
   1169  1.9.2.2  bouyer 	case CT_TERMINATED:
   1170  1.9.2.2  bouyer 		if (fmsg == NULL)
   1171  1.9.2.2  bouyer 			fmsg = "terminated by TERMINATE TRANSFER";
   1172  1.9.2.2  bouyer 		/*FALLTHROUGH*/
   1173  1.9.2.2  bouyer 	case CT_LOGOUT:
   1174  1.9.2.2  bouyer 		if (fmsg == NULL)
   1175  1.9.2.2  bouyer 			fmsg = "Port Logout";
   1176  1.9.2.2  bouyer 		/*FALLTHROUGH*/
   1177  1.9.2.2  bouyer 	case CT_PORTNOTAVAIL:
   1178  1.9.2.2  bouyer 		if (fmsg == NULL)
   1179  1.9.2.2  bouyer 			fmsg = "Port not available";
   1180  1.9.2.2  bouyer 	case CT_NOACK:
   1181  1.9.2.2  bouyer 		if (fmsg == NULL)
   1182  1.9.2.2  bouyer 			fmsg = "unacknowledged Immediate Notify pending";
   1183  1.9.2.2  bouyer 
   1184  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg);
   1185  1.9.2.2  bouyer #if	0
   1186  1.9.2.2  bouyer 			if (status & SENSEVALID) {
   1187  1.9.2.2  bouyer 				bcopy((caddr_t) (cep + CTIO_SENSE_OFFSET),
   1188  1.9.2.2  bouyer 				    (caddr_t) &cdp->cd_sensedata,
   1189  1.9.2.2  bouyer 				    sizeof(scsi_sense_t));
   1190  1.9.2.2  bouyer 				cdp->cd_flags |= CDF_SENSEVALID;
   1191  1.9.2.2  bouyer 			}
   1192  1.9.2.2  bouyer #endif
   1193  1.9.2.2  bouyer 		break;
   1194  1.9.2.2  bouyer 
   1195  1.9.2.2  bouyer 	case CT_INVRXID:
   1196  1.9.2.2  bouyer 		/*
   1197  1.9.2.2  bouyer 		 * CTIO rejected by the firmware because an invalid RX_ID.
   1198  1.9.2.2  bouyer 		 * Just print a message.
   1199  1.9.2.2  bouyer 		 */
   1200  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR,
   1201  1.9.2.2  bouyer 		    "CTIO2 completed with Invalid RX_ID 0x%x", ct->ct_rxid);
   1202  1.9.2.2  bouyer 		break;
   1203  1.9.2.2  bouyer 
   1204  1.9.2.2  bouyer 	default:
   1205  1.9.2.2  bouyer 		isp_prt(isp, ISP_LOGERR, "Unknown CTIO status 0x%x",
   1206  1.9.2.2  bouyer 		    ct->ct_status & ~QLTM_SVALID);
   1207  1.9.2.2  bouyer 		break;
   1208  1.9.2.2  bouyer 	}
   1209  1.9.2.2  bouyer 
   1210  1.9.2.2  bouyer 	if (xs == NULL) {
   1211  1.9.2.2  bouyer 		/*
   1212  1.9.2.2  bouyer 		 * There may be more than one CTIO for a data transfer,
   1213  1.9.2.2  bouyer 		 * or this may be a status CTIO we're not monitoring.
   1214  1.9.2.2  bouyer 		 *
   1215  1.9.2.2  bouyer 		 * The assumption is that they'll all be returned in the
   1216  1.9.2.2  bouyer 		 * order we got them.
   1217  1.9.2.2  bouyer 		 */
   1218  1.9.2.2  bouyer 		if (ct->ct_reserved == 0) {
   1219  1.9.2.2  bouyer 			if ((ct->ct_flags & CT_SENDSTATUS) == 0) {
   1220  1.9.2.2  bouyer 				isp_prt(isp, pl,
   1221  1.9.2.2  bouyer 				    "intermediate CTIO completed ok");
   1222  1.9.2.2  bouyer 			} else {
   1223  1.9.2.2  bouyer 				isp_prt(isp, pl,
   1224  1.9.2.2  bouyer 				    "unmonitored CTIO completed ok");
   1225  1.9.2.2  bouyer 			}
   1226  1.9.2.2  bouyer 		} else {
   1227  1.9.2.2  bouyer 			isp_prt(isp, pl,
   1228  1.9.2.2  bouyer 			    "NO xs for CTIO (handle 0x%x) status 0x%x",
   1229  1.9.2.2  bouyer 			    ct->ct_reserved, ct->ct_status & ~QLTM_SVALID);
   1230  1.9.2.2  bouyer 		}
   1231  1.9.2.2  bouyer 	} else {
   1232  1.9.2.2  bouyer 		if (ct->ct_flags & CT_SENDSTATUS) {
   1233  1.9.2.2  bouyer 			/*
   1234  1.9.2.2  bouyer 			 * Sent status and command complete.
   1235  1.9.2.2  bouyer 			 *
   1236  1.9.2.2  bouyer 			 * We're now really done with this command, so we
   1237  1.9.2.2  bouyer 			 * punt to the platform dependent layers because
   1238  1.9.2.2  bouyer 			 * only there can we do the appropriate command
   1239  1.9.2.2  bouyer 			 * complete thread synchronization.
   1240  1.9.2.2  bouyer 			 */
   1241  1.9.2.2  bouyer 			isp_prt(isp, pl, "status CTIO complete");
   1242  1.9.2.2  bouyer 		} else {
   1243  1.9.2.2  bouyer 			/*
   1244  1.9.2.2  bouyer 			 * Final CTIO completed. Release DMA resources and
   1245  1.9.2.2  bouyer 			 * notify platform dependent layers.
   1246  1.9.2.2  bouyer 			 */
   1247  1.9.2.2  bouyer 			isp_prt(isp, pl, "data CTIO complete");
   1248  1.9.2.2  bouyer 			ISP_DMAFREE(isp, xs, ct->ct_reserved);
   1249  1.9.2.2  bouyer 		}
   1250  1.9.2.2  bouyer 		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
   1251  1.9.2.2  bouyer 		/*
   1252  1.9.2.2  bouyer 		 * The platform layer will destroy the handle if appropriate.
   1253  1.9.2.2  bouyer 		 */
   1254  1.9.2.2  bouyer 	}
   1255  1.9.2.2  bouyer }
   1256  1.9.2.2  bouyer #endif
   1257