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