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