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