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