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