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