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