xref: /freebsd/sys/dev/isp/isp_target.c (revision ac4c858b19f9ebe17fdc3a868aacd140e1918f40)
1 /*-
2  * Machine and OS Independent Target Mode Code for the Qlogic SCSI/FC adapters.
3  *
4  * Copyright (c) 1997-2006 by Matthew Jacob
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice immediately at the beginning of the file, without modification,
12  *    this list of conditions, and the following disclaimer.
13  * 2. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 /*
29  * Bug fixes gratefully acknowledged from:
30  *	Oded Kedem <oded@kashya.com>
31  */
32 /*
33  * Include header file appropriate for platform we're building on.
34  */
35 
36 #ifdef	__NetBSD__
37 #include <dev/ic/isp_netbsd.h>
38 #endif
39 #ifdef	__FreeBSD__
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
42 #include <dev/isp/isp_freebsd.h>
43 #endif
44 #ifdef	__OpenBSD__
45 #include <dev/ic/isp_openbsd.h>
46 #endif
47 #ifdef	__linux__
48 #include "isp_linux.h"
49 #endif
50 
51 #ifdef	ISP_TARGET_MODE
52 static const char atiocope[] =
53     "ATIO returned for lun %d because it was in the middle of Bus Device Reset "
54     "on bus %d";
55 static const char atior[] =
56     "ATIO returned on for lun %d on from loopid %d because a Bus Reset "
57     "occurred on bus %d";
58 
59 static void isp_got_msg(ispsoftc_t *, in_entry_t *);
60 static void isp_got_msg_fc(ispsoftc_t *, in_fcentry_t *);
61 static void isp_got_tmf_24xx(ispsoftc_t *, at7_entry_t *);
62 static void isp_handle_atio(ispsoftc_t *, at_entry_t *);
63 static void isp_handle_atio2(ispsoftc_t *, at2_entry_t *);
64 static void isp_handle_ctio(ispsoftc_t *, ct_entry_t *);
65 static void isp_handle_ctio2(ispsoftc_t *, ct2_entry_t *);
66 static void isp_handle_ctio7(ispsoftc_t *, ct7_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(ispsoftc_t *isp, void *vptr, uint32_t *optrp)
116 {
117 	uint16_t status;
118 	uint32_t seqid;
119 	union {
120 		at_entry_t	*atiop;
121 		at2_entry_t	*at2iop;
122 		at2e_entry_t	*at2eiop;
123 		at7_entry_t	*at7iop;
124 		ct_entry_t	*ctiop;
125 		ct2_entry_t	*ct2iop;
126 		ct2e_entry_t	*ct2eiop;
127 		ct7_entry_t	*ct7iop;
128 		lun_entry_t	*lunenp;
129 		in_entry_t	*inotp;
130 		in_fcentry_t	*inot_fcp;
131 		in_fcentry_e_t	*inote_fcp;
132 		in_fcentry_24xx_t *inot_24xx;
133 		na_entry_t	*nackp;
134 		na_fcentry_t	*nack_fcp;
135 		na_fcentry_e_t	*nacke_fcp;
136 		na_fcentry_24xx_t *nack_24xx;
137 		isphdr_t	*hp;
138 		abts_t		*abts;
139 		abts_rsp_t	*abts_rsp;
140 		els_t		*els;
141 		void *		*vp;
142 #define	atiop		unp.atiop
143 #define	at2iop		unp.at2iop
144 #define	at2eiop		unp.at2eiop
145 #define	at7iop		unp.at7iop
146 #define	ctiop		unp.ctiop
147 #define	ct2iop		unp.ct2iop
148 #define	ct2eiop		unp.ct2eiop
149 #define	ct7iop		unp.ct7iop
150 #define	lunenp		unp.lunenp
151 #define	inotp		unp.inotp
152 #define	inot_fcp	unp.inot_fcp
153 #define	inote_fcp	unp.inote_fcp
154 #define	inot_24xx	unp.inot_24xx
155 #define	nackp		unp.nackp
156 #define	nack_fcp	unp.nack_fcp
157 #define	nacke_fcp	unp.nacke_fcp
158 #define	nack_24xx	unp.nack_24xx
159 #define	abts		unp.abts
160 #define	abts_rsp	unp.abts_rsp
161 #define els		unp.els
162 #define	hdrp		unp.hp
163 	} unp;
164 	uint8_t local[QENTRY_LEN];
165 	int bus, type, level, rval = 1;
166 
167 	type = isp_get_response_type(isp, (isphdr_t *)vptr);
168 	unp.vp = vptr;
169 
170 	ISP_TDQE(isp, "isp_target_notify", (int) *optrp, vptr);
171 
172 	switch(type) {
173 	case RQSTYPE_ATIO:
174 		if (IS_24XX(isp)) {
175 			int len;
176 
177 			isp_get_atio7(isp, at7iop, (at7_entry_t *) local);
178 			at7iop = (at7_entry_t *) local;
179 			/*
180 			 * Check for and do something with commands whose IULEN
181 			 * extends past a singel queue entry.
182 			 */
183 			len = at7iop->at_ta_len & 0xfffff;
184 			if (len > (QENTRY_LEN - 8)) {
185 				len -= (QENTRY_LEN - 8);
186 				isp_prt(isp, ISP_LOGINFO,
187 				    "long IU length (%d) ignored", len);
188 				while (len > 0) {
189 					*optrp =  ISP_NXT_QENTRY(*optrp,
190 					    RESULT_QUEUE_LEN(isp));
191 					len -= QENTRY_LEN;
192 				}
193 			}
194 			/*
195 			 * Check for a task management function
196 			 */
197 			if (at7iop->at_cmnd.fcp_cmnd_task_management) {
198 				isp_got_tmf_24xx(isp, at7iop);
199 				break;
200 			}
201 			/*
202 			 * Just go straight to outer layer for this one.
203 			 */
204 			(void) isp_async(isp, ISPASYNC_TARGET_ACTION, local);
205 		} else {
206 			isp_get_atio(isp, atiop, (at_entry_t *) local);
207 			isp_handle_atio(isp, (at_entry_t *) local);
208 		}
209 		break;
210 
211 	case RQSTYPE_CTIO:
212 		isp_get_ctio(isp, ctiop, (ct_entry_t *) local);
213 		isp_handle_ctio(isp, (ct_entry_t *) local);
214 		break;
215 
216 	case RQSTYPE_ATIO2:
217 		if (FCPARAM(isp)->isp_2klogin) {
218 			isp_get_atio2e(isp, at2eiop, (at2e_entry_t *) local);
219 		} else {
220 			isp_get_atio2(isp, at2iop, (at2_entry_t *) local);
221 		}
222 		isp_handle_atio2(isp, (at2_entry_t *) local);
223 		break;
224 
225 	case RQSTYPE_CTIO3:
226 	case RQSTYPE_CTIO2:
227 		if (FCPARAM(isp)->isp_2klogin) {
228 			isp_get_ctio2e(isp, ct2eiop, (ct2e_entry_t *) local);
229 		} else {
230 			isp_get_ctio2(isp, ct2iop, (ct2_entry_t *) local);
231 		}
232 		isp_handle_ctio2(isp, (ct2_entry_t *) local);
233 		break;
234 
235 	case RQSTYPE_CTIO7:
236 		isp_get_ctio7(isp, ct7iop, (ct7_entry_t *) local);
237 		isp_handle_ctio7(isp, (ct7_entry_t *) local);
238 		break;
239 
240 	case RQSTYPE_ENABLE_LUN:
241 	case RQSTYPE_MODIFY_LUN:
242 		isp_get_enable_lun(isp, lunenp, (lun_entry_t *) local);
243 		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, local);
244 		break;
245 
246 	case RQSTYPE_NOTIFY:
247 		/*
248 		 * Either the ISP received a SCSI message it can't
249 		 * handle, or it's returning an Immed. Notify entry
250 		 * we sent. We can send Immed. Notify entries to
251 		 * increment the firmware's resource count for them
252 		 * (we set this initially in the Enable Lun entry).
253 		 */
254 		bus = 0;
255 		if (IS_24XX(isp)) {
256 			isp_get_notify_24xx(isp, inot_24xx,
257 			    (in_fcentry_24xx_t *)local);
258 			inot_24xx = (in_fcentry_24xx_t *) local;
259 			status = inot_24xx->in_status;
260 			seqid = inot_24xx->in_rxid;
261 			isp_prt(isp, ISP_LOGTDEBUG0,
262 			    "Immediate Notify status=0x%x seqid=0x%x",
263 			    status, seqid);
264 			switch (status) {
265 			case IN24XX_LIP_RESET:
266 			case IN24XX_LINK_RESET:
267 			case IN24XX_PORT_LOGOUT:
268 			case IN24XX_PORT_CHANGED:
269 			case IN24XX_LINK_FAILED:
270 			case IN24XX_SRR_RCVD:
271 			case IN24XX_ELS_RCVD:
272 				(void) isp_async(isp, ISPASYNC_TARGET_ACTION,
273 				    &local);
274 				break;
275 			default:
276 				isp_prt(isp, ISP_LOGINFO,
277 				    "isp_target_notify: unknown status (0x%x)",
278 				    status);
279 				isp_notify_ack(isp, local);
280 				break;
281 			}
282 			break;
283 		} else if (IS_FC(isp)) {
284 			if (FCPARAM(isp)->isp_2klogin) {
285 				isp_get_notify_fc_e(isp, inote_fcp,
286 				    (in_fcentry_e_t *)local);
287 			} else {
288 				isp_get_notify_fc(isp, inot_fcp,
289 				    (in_fcentry_t *)local);
290 			}
291 			inot_fcp = (in_fcentry_t *) local;
292 			status = inot_fcp->in_status;
293 			seqid = inot_fcp->in_seqid;
294 		} else {
295 			isp_get_notify(isp, inotp, (in_entry_t *)local);
296 			inotp = (in_entry_t *) local;
297 			status = inotp->in_status & 0xff;
298 			seqid = inotp->in_seqid;
299 			if (IS_DUALBUS(isp)) {
300 				bus = GET_BUS_VAL(inotp->in_iid);
301 				SET_BUS_VAL(inotp->in_iid, 0);
302 			}
303 		}
304 
305 		isp_prt(isp, ISP_LOGTDEBUG0,
306 		    "Immediate Notify On Bus %d, status=0x%x seqid=0x%x",
307 		    bus, status, seqid);
308 
309 		switch (status) {
310 		case IN_MSG_RECEIVED:
311 		case IN_IDE_RECEIVED:
312 			if (IS_FC(isp)) {
313 				isp_got_msg_fc(isp, (in_fcentry_t *)local);
314 			} else {
315 				isp_got_msg(isp, (in_entry_t *)local);
316 			}
317 			break;
318 		case IN_RSRC_UNAVAIL:
319 			isp_prt(isp, ISP_LOGINFO, "Firmware out of ATIOs");
320 			isp_notify_ack(isp, local);
321 			break;
322 		case IN_RESET:
323 		{
324 			/*
325 			 * We form the notify structure here because we need
326 			 * to mark it as needing a NOTIFY ACK on return.
327 			 */
328 			tmd_notify_t notify;
329 
330 			MEMZERO(&notify, sizeof (tmd_notify_t));
331 			notify.nt_hba = isp;
332 			notify.nt_iid = INI_ANY;
333 			/* nt_tgt set in outer layers */
334 			notify.nt_lun = LUN_ANY;
335 			notify.nt_tagval = TAG_ANY;
336 			notify.nt_ncode = NT_BUS_RESET;
337 			notify.nt_need_ack = 1;
338 			(void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &notify);
339 			break;
340 		}
341 		case IN_PORT_LOGOUT:
342 		case IN_ABORT_TASK:
343 		case IN_PORT_CHANGED:
344 		case IN_GLOBAL_LOGO:
345 			(void) isp_async(isp, ISPASYNC_TARGET_ACTION, &local);
346 			break;
347 		default:
348 			isp_prt(isp, ISP_LOGINFO,
349 			    "isp_target_notify: unknown status (0x%x)",
350 			    status);
351 			isp_notify_ack(isp, local);
352 			break;
353 		}
354 		break;
355 
356 	case RQSTYPE_NOTIFY_ACK:
357 		/*
358 		 * The ISP is acknowledging our acknowledgement of an
359 		 * Immediate Notify entry for some asynchronous event.
360 		 */
361 		if (IS_24XX(isp)) {
362 			isp_get_notify_ack_24xx(isp, nack_24xx,
363 			    (na_fcentry_24xx_t *) local);
364 			nack_24xx = (na_fcentry_24xx_t *) local;
365 			if (nack_24xx->na_status != NA_OK) {
366 				level = ISP_LOGINFO;
367 			} else {
368 				level = ISP_LOGTDEBUG1;
369 			}
370 			isp_prt(isp, level,
371 			    "Notify Ack Status=0x%x; Subcode 0x%x seqid=0x%x",
372 			    nack_24xx->na_status, nack_24xx->na_status_subcode,
373 			    nack_24xx->na_rxid);
374 		} else if (IS_FC(isp)) {
375 			if (FCPARAM(isp)->isp_2klogin) {
376 				isp_get_notify_ack_fc_e(isp, nacke_fcp,
377 				    (na_fcentry_e_t *)local);
378 			} else {
379 				isp_get_notify_ack_fc(isp, nack_fcp,
380 				    (na_fcentry_t *)local);
381 			}
382 			nack_fcp = (na_fcentry_t *)local;
383 			if (nack_fcp->na_status != NA_OK) {
384 				level = ISP_LOGINFO;
385 			} else {
386 				level = ISP_LOGTDEBUG1;
387 			}
388 			isp_prt(isp, level,
389 			    "Notify Ack Status=0x%x seqid 0x%x",
390 			    nack_fcp->na_status, nack_fcp->na_seqid);
391 		} else {
392 			isp_get_notify_ack(isp, nackp, (na_entry_t *)local);
393 			nackp = (na_entry_t *)local;
394 			if (nackp->na_status != NA_OK) {
395 				level = ISP_LOGINFO;
396 			} else {
397 				level = ISP_LOGTDEBUG1;
398 			}
399 			isp_prt(isp, level,
400 			    "Notify Ack event 0x%x status=0x%x seqid 0x%x",
401 			    nackp->na_event, nackp->na_status, nackp->na_seqid);
402 		}
403 		break;
404 
405 	case RQSTYPE_ABTS_RCVD:
406 		isp_get_abts(isp, abts, (abts_t *)local);
407 		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, &local);
408 		break;
409 	case RQSTYPE_ABTS_RSP:
410 		isp_get_abts_rsp(isp, abts_rsp, (abts_rsp_t *)local);
411 		abts_rsp = (abts_rsp_t *) local;
412 		if (abts_rsp->abts_rsp_status) {
413 			level = ISP_LOGINFO;
414 		} else {
415 			level = ISP_LOGTDEBUG0;
416 		}
417 		isp_prt(isp, level,
418 		    "ABTS RSP response[0x%x]: status=0x%x sub=(0x%x 0x%x)",
419 		    abts_rsp->abts_rsp_rxid_task, abts_rsp->abts_rsp_status,
420 		    abts_rsp->abts_rsp_payload.rsp.subcode1,
421 		    abts_rsp->abts_rsp_payload.rsp.subcode2);
422 		break;
423 	default:
424 		isp_prt(isp, ISP_LOGERR,
425 		    "Unknown entry type 0x%x in isp_target_notify", type);
426 		rval = 0;
427 		break;
428 	}
429 #undef	atiop
430 #undef	at2iop
431 #undef	at2eiop
432 #undef	at7iop
433 #undef	ctiop
434 #undef	ct2iop
435 #undef	ct2eiop
436 #undef	ct7iop
437 #undef	lunenp
438 #undef	inotp
439 #undef	inot_fcp
440 #undef	inote_fcp
441 #undef	inot_24xx
442 #undef	nackp
443 #undef	nack_fcp
444 #undef	nacke_fcp
445 #undef	hack_24xx
446 #undef	abts
447 #undef	abts_rsp
448 #undef	els
449 #undef	hdrp
450 	return (rval);
451 }
452 
453 
454 /*
455  * Toggle (on/off) target mode for bus/target/lun
456  *
457  * The caller has checked for overlap and legality.
458  *
459  * Note that not all of bus, target or lun can be paid attention to.
460  * Note also that this action will not be complete until the f/w writes
461  * response entry. The caller is responsible for synchronizing this.
462  */
463 int
464 isp_lun_cmd(ispsoftc_t *isp, int cmd, int bus, int tgt, int lun,
465     int cmd_cnt, int inot_cnt, uint32_t opaque)
466 {
467 	lun_entry_t el;
468 	uint32_t nxti, optr;
469 	void *outp;
470 
471 
472 	MEMZERO(&el, sizeof (el));
473 	if (IS_DUALBUS(isp)) {
474 		el.le_rsvd = (bus & 0x1) << 7;
475 	}
476 	el.le_cmd_count = cmd_cnt;
477 	el.le_in_count = inot_cnt;
478 	if (cmd == RQSTYPE_ENABLE_LUN) {
479 		if (IS_SCSI(isp)) {
480 			el.le_flags = LUN_TQAE|LUN_DISAD;
481 			el.le_cdb6len = 12;
482 			el.le_cdb7len = 12;
483 		}
484 	} else if (cmd == -RQSTYPE_ENABLE_LUN) {
485 		cmd = RQSTYPE_ENABLE_LUN;
486 		el.le_cmd_count = 0;
487 		el.le_in_count = 0;
488 	} else if (cmd == -RQSTYPE_MODIFY_LUN) {
489 		cmd = RQSTYPE_MODIFY_LUN;
490 		el.le_ops = LUN_CCDECR | LUN_INDECR;
491 	} else {
492 		el.le_ops = LUN_CCINCR | LUN_ININCR;
493 	}
494 	el.le_header.rqs_entry_type = cmd;
495 	el.le_header.rqs_entry_count = 1;
496 	el.le_reserved = opaque;
497 	if (IS_SCSI(isp)) {
498 		el.le_tgt = tgt;
499 		el.le_lun = lun;
500 	} else if (FCPARAM(isp)->isp_sccfw == 0) {
501 		el.le_lun = lun;
502 	}
503 	el.le_timeout = 30;
504 
505 	if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
506 		isp_prt(isp, ISP_LOGERR,
507 		    "Request Queue Overflow in isp_lun_cmd");
508 		return (-1);
509 	}
510 	ISP_TDQE(isp, "isp_lun_cmd", (int) optr, &el);
511 	isp_put_enable_lun(isp, &el, outp);
512 	ISP_ADD_REQUEST(isp, nxti);
513 	return (0);
514 }
515 
516 
517 int
518 isp_target_put_entry(ispsoftc_t *isp, void *ap)
519 {
520 	void *outp;
521 	uint32_t nxti, optr;
522 	uint8_t etype = ((isphdr_t *) ap)->rqs_entry_type;
523 
524 	if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
525 		isp_prt(isp, ISP_LOGWARN,
526 		    "Request Queue Overflow in isp_target_put_entry");
527 		return (-1);
528 	}
529 	switch (etype) {
530 	case RQSTYPE_ATIO:
531 		isp_put_atio(isp, (at_entry_t *) ap, (at_entry_t *) outp);
532 		break;
533 	case RQSTYPE_ATIO2:
534 		if (FCPARAM(isp)->isp_2klogin) {
535 			isp_put_atio2e(isp, (at2e_entry_t *) ap,
536 			    (at2e_entry_t *) outp);
537 		} else {
538 			isp_put_atio2(isp, (at2_entry_t *) ap,
539 			    (at2_entry_t *) outp);
540 		}
541 		break;
542 	case RQSTYPE_CTIO:
543 		isp_put_ctio(isp, (ct_entry_t *) ap, (ct_entry_t *) outp);
544 		break;
545 	case RQSTYPE_CTIO2:
546 		if (FCPARAM(isp)->isp_2klogin) {
547 			isp_put_ctio2e(isp, (ct2e_entry_t *) ap,
548 			    (ct2e_entry_t *) outp);
549 		} else {
550 			isp_put_ctio2(isp, (ct2_entry_t *) ap,
551 			    (ct2_entry_t *) outp);
552 		}
553 		break;
554 	case RQSTYPE_CTIO7:
555 		isp_put_ctio7(isp, (ct7_entry_t *) ap, (ct7_entry_t *) outp);
556 		break;
557 	default:
558 		isp_prt(isp, ISP_LOGERR,
559 		    "Unknown type 0x%x in isp_put_entry", etype);
560 		return (-1);
561 	}
562 	ISP_TDQE(isp, "isp_target_put_entry", (int) optr, ap);
563 	ISP_ADD_REQUEST(isp, nxti);
564 	return (0);
565 }
566 
567 int
568 isp_target_put_atio(ispsoftc_t *isp, void *arg)
569 {
570 	union {
571 		at_entry_t _atio;
572 		at2_entry_t _atio2;
573 		at2e_entry_t _atio2e;
574 	} atun;
575 
576 	MEMZERO(&atun, sizeof atun);
577 	if (IS_FC(isp)) {
578 		at2_entry_t *aep = arg;
579 		atun._atio2.at_header.rqs_entry_type = RQSTYPE_ATIO2;
580 		atun._atio2.at_header.rqs_entry_count = 1;
581 		if (FCPARAM(isp)->isp_sccfw) {
582 			atun._atio2.at_scclun = aep->at_scclun;
583 		} else {
584 			atun._atio2.at_lun = (uint8_t) aep->at_lun;
585 		}
586 		if (FCPARAM(isp)->isp_2klogin) {
587 			atun._atio2e.at_iid = ((at2e_entry_t *)aep)->at_iid;
588 		} else {
589 			atun._atio2.at_iid = aep->at_iid;
590 		}
591 		atun._atio2.at_rxid = aep->at_rxid;
592 		atun._atio2.at_status = CT_OK;
593 	} else {
594 		at_entry_t *aep = arg;
595 		atun._atio.at_header.rqs_entry_type = RQSTYPE_ATIO;
596 		atun._atio.at_header.rqs_entry_count = 1;
597 		atun._atio.at_handle = aep->at_handle;
598 		atun._atio.at_iid = aep->at_iid;
599 		atun._atio.at_tgt = aep->at_tgt;
600 		atun._atio.at_lun = aep->at_lun;
601 		atun._atio.at_tag_type = aep->at_tag_type;
602 		atun._atio.at_tag_val = aep->at_tag_val;
603 		atun._atio.at_status = (aep->at_flags & AT_TQAE);
604 		atun._atio.at_status |= CT_OK;
605 	}
606 	return (isp_target_put_entry(isp, &atun));
607 }
608 
609 /*
610  * Command completion- both for handling cases of no resources or
611  * no blackhole driver, or other cases where we have to, inline,
612  * finish the command sanely, or for normal command completion.
613  *
614  * The 'completion' code value has the scsi status byte in the low 8 bits.
615  * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have
616  * the sense key and  bits 16..23 have the ASCQ and bits 24..31 have the ASC
617  * values.
618  *
619  * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't
620  * NB: inline SCSI sense reporting. As such, we lose this information. XXX.
621  *
622  * For both parallel && fibre channel, we use the feature that does
623  * an automatic resource autoreplenish so we don't have then later do
624  * put of an atio to replenish the f/w's resource count.
625  */
626 
627 int
628 isp_endcmd(ispsoftc_t *isp, void *arg, uint32_t code, uint32_t hdl)
629 {
630 	int sts;
631 	union {
632 		ct_entry_t _ctio;
633 		ct2_entry_t _ctio2;
634 		ct2e_entry_t _ctio2e;
635 		ct7_entry_t _ctio7;
636 	} un;
637 
638 	MEMZERO(&un, sizeof un);
639 	sts = code & 0xff;
640 
641 	if (IS_24XX(isp)) {
642 		at7_entry_t *aep = arg;
643 		ct7_entry_t *cto = &un._ctio7;
644 
645 		cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
646 		cto->ct_header.rqs_entry_count = 1;
647 /* XXXX */	cto->ct_nphdl = aep->at_hdr.seq_id;
648 		cto->ct_rxid = aep->at_rxid;
649 		cto->ct_iid_lo = (aep->at_hdr.s_id[1] << 8) |
650 		    aep->at_hdr.s_id[2];
651 		cto->ct_iid_hi = aep->at_hdr.s_id[0];
652 		cto->ct_oxid = aep->at_hdr.ox_id;
653 		cto->ct_scsi_status = sts;
654 		cto->ct_flags = CT7_FLAG_MODE1 | CT7_NO_DATA | CT7_SENDSTATUS;
655 		if (sts == SCSI_CHECK && (code & ECMD_SVALID)) {
656 			cto->rsp.m1.ct_resplen = 16;
657 			cto->rsp.m1.ct_resp[0] = 0xf0;
658 			cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
659 			cto->rsp.m1.ct_resp[7] = 8;
660 			cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff;
661 			cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff;
662 		}
663 		if (aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl) {
664 			cto->ct_resid = aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl;
665 			cto->ct_scsi_status |= CT2_DATA_UNDER;
666 		}
667 		cto->ct_syshandle = hdl;
668 	} else if (IS_FC(isp)) {
669 		at2_entry_t *aep = arg;
670 		ct2_entry_t *cto = &un._ctio2;
671 
672 		cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
673 		cto->ct_header.rqs_entry_count = 1;
674 		if (FCPARAM(isp)->isp_sccfw == 0) {
675 			cto->ct_lun = aep->at_lun;
676 		}
677 		if (FCPARAM(isp)->isp_2klogin) {
678 			un._ctio2e.ct_iid = ((at2e_entry_t *)aep)->at_iid;
679 		} else {
680 			cto->ct_iid = aep->at_iid;
681 		}
682 		cto->ct_rxid = aep->at_rxid;
683 		cto->rsp.m1.ct_scsi_status = sts;
684 		cto->ct_flags = CT2_SENDSTATUS | CT2_NO_DATA | CT2_FLAG_MODE1;
685 		if (hdl == 0) {
686 			cto->ct_flags |= CT2_CCINCR;
687 		}
688 		if (aep->at_datalen) {
689 			cto->ct_resid = aep->at_datalen;
690 			cto->rsp.m1.ct_scsi_status |= CT2_DATA_UNDER;
691 		}
692 		if (sts == SCSI_CHECK && (code & ECMD_SVALID)) {
693 			cto->rsp.m1.ct_resp[0] = 0xf0;
694 			cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
695 			cto->rsp.m1.ct_resp[7] = 8;
696 			cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff;
697 			cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff;
698 			cto->rsp.m1.ct_senselen = 16;
699 			cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID;
700 		}
701 		cto->ct_syshandle = hdl;
702 	} else {
703 		at_entry_t *aep = arg;
704 		ct_entry_t *cto = &un._ctio;
705 
706 		cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
707 		cto->ct_header.rqs_entry_count = 1;
708 		cto->ct_fwhandle = aep->at_handle;
709 		cto->ct_iid = aep->at_iid;
710 		cto->ct_tgt = aep->at_tgt;
711 		cto->ct_lun = aep->at_lun;
712 		cto->ct_tag_type = aep->at_tag_type;
713 		cto->ct_tag_val = aep->at_tag_val;
714 		if (aep->at_flags & AT_TQAE) {
715 			cto->ct_flags |= CT_TQAE;
716 		}
717 		cto->ct_flags = CT_SENDSTATUS | CT_NO_DATA;
718 		if (hdl == 0) {
719 			cto->ct_flags |= CT_CCINCR;
720 		}
721 		cto->ct_scsi_status = sts;
722 		cto->ct_syshandle = hdl;
723 	}
724 	return (isp_target_put_entry(isp, &un));
725 }
726 
727 /*
728  * These are either broadcast events or specifically CTIO fast completion
729  */
730 int
731 isp_target_async(ispsoftc_t *isp, int bus, int event)
732 {
733 	tmd_notify_t notify;
734 
735 	MEMZERO(&notify, sizeof (tmd_notify_t));
736 	notify.nt_hba = isp;
737 	notify.nt_iid = INI_ANY;
738 	/* nt_tgt set in outer layers */
739 	notify.nt_lun = LUN_ANY;
740 	notify.nt_tagval = TAG_ANY;
741 
742 	if (IS_SCSI(isp)) {
743 		TAG_INSERT_BUS(notify.nt_tagval, bus);
744 	}
745 
746 	switch (event) {
747 	case ASYNC_LOOP_UP:
748 	case ASYNC_PTPMODE:
749 		notify.nt_ncode = NT_LINK_UP;
750 		(void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &notify);
751 		break;
752 	case ASYNC_LOOP_DOWN:
753 		notify.nt_ncode = NT_LINK_DOWN;
754 		(void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &notify);
755 		break;
756 	case ASYNC_LIP_ERROR:
757 	case ASYNC_LIP_F8:
758 	case ASYNC_LIP_OCCURRED:
759 	case ASYNC_LOOP_RESET:
760 		notify.nt_ncode = NT_LIP_RESET;
761 		(void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &notify);
762 		break;
763 	case ASYNC_BUS_RESET:
764 	case ASYNC_TIMEOUT_RESET:	/* XXX: where does this come from ? */
765 		notify.nt_ncode = NT_BUS_RESET;
766 		(void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &notify);
767 		break;
768 	case ASYNC_DEVICE_RESET:
769 		notify.nt_ncode = NT_TARGET_RESET;
770 		(void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &notify);
771 		break;
772 	case ASYNC_CTIO_DONE:
773 	{
774 		uint8_t storage[QENTRY_LEN];
775 		memset(storage, 0, QENTRY_LEN);
776 		if (IS_24XX(isp)) {
777 			ct7_entry_t *ct = (ct7_entry_t *) storage;
778 			ct->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
779 			ct->ct_nphdl = CT7_OK;
780 			ct->ct_syshandle = bus;
781 			ct->ct_flags = CT7_SENDSTATUS|CT7_FASTPOST;
782 		} else if (IS_FC(isp)) {
783             		/* This should also suffice for 2K login code */
784 			ct2_entry_t *ct = (ct2_entry_t *) storage;
785 			ct->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
786 			ct->ct_status = CT_OK;
787 			ct->ct_syshandle = bus;
788 			ct->ct_flags = CT2_SENDSTATUS|CT2_FASTPOST;
789 		} else {
790 			ct_entry_t *ct = (ct_entry_t *) storage;
791 			ct->ct_header.rqs_entry_type = RQSTYPE_CTIO;
792 			ct->ct_status = CT_OK;
793 			ct->ct_fwhandle = bus;
794 			ct->ct_flags = CT_SENDSTATUS;
795 		}
796 		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, storage);
797 		break;
798 	}
799 	default:
800 		isp_prt(isp, ISP_LOGERR,
801 		    "isp_target_async: unknown event 0x%x", event);
802 		if (isp->isp_state == ISP_RUNSTATE) {
803 			isp_notify_ack(isp, NULL);
804 		}
805 		break;
806 	}
807 	return (0);
808 }
809 
810 
811 /*
812  * Process a received message.
813  * The ISP firmware can handle most messages, there are only
814  * a few that we need to deal with:
815  * - abort: clean up the current command
816  * - abort tag and clear queue
817  */
818 
819 static void
820 isp_got_msg(ispsoftc_t *isp, in_entry_t *inp)
821 {
822 	tmd_notify_t nt;
823 	uint8_t status = inp->in_status & ~QLTM_SVALID;
824 
825 	MEMZERO(&nt, sizeof (nt));
826 	nt.nt_hba = isp;
827 	nt.nt_iid = GET_IID_VAL(inp->in_iid);
828 	nt.nt_tgt = inp->in_tgt;
829 	nt.nt_lun = inp->in_lun;
830 	IN_MAKE_TAGID(nt.nt_tagval, GET_BUS_VAL(inp->in_iid), 0, inp);
831 	nt.nt_lreserved = inp;
832 
833 	if (status == IN_IDE_RECEIVED || status == IN_MSG_RECEIVED) {
834 		switch (inp->in_msg[0]) {
835 		case MSG_ABORT:
836 			nt.nt_ncode = NT_ABORT_TASK_SET;
837 			break;
838 		case MSG_BUS_DEV_RESET:
839 			nt.nt_ncode = NT_TARGET_RESET;
840 			break;
841 		case MSG_ABORT_TAG:
842 			nt.nt_ncode = NT_ABORT_TASK;
843 			break;
844 		case MSG_CLEAR_QUEUE:
845 			nt.nt_ncode = NT_CLEAR_TASK_SET;
846 			break;
847 		case MSG_REL_RECOVERY:
848 			nt.nt_ncode = NT_CLEAR_ACA;
849 			break;
850 		case MSG_TERM_IO_PROC:
851 			nt.nt_ncode = NT_ABORT_TASK;
852 			break;
853 		case MSG_LUN_RESET:
854 			nt.nt_ncode = NT_LUN_RESET;
855 			break;
856 		default:
857 			isp_prt(isp, ISP_LOGERR,
858 			    "unhandled message 0x%x", inp->in_msg[0]);
859 			isp_notify_ack(isp, inp);
860 			return;
861 		}
862 		(void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt);
863 	} else {
864 		isp_prt(isp, ISP_LOGERR,
865 		    "unknown immediate notify status 0x%x", inp->in_status);
866 		isp_notify_ack(isp, inp);
867 	}
868 }
869 
870 /*
871  * Synthesize a message from the task management flags in a FCP_CMND_IU.
872  */
873 static void
874 isp_got_msg_fc(ispsoftc_t *isp, in_fcentry_t *inp)
875 {
876 	tmd_notify_t nt;
877 	static const char f1[] = "%s from N-port handle 0x%x lun %d seq 0x%x";
878 	static const char f2[] = "unknown %s 0x%x lun %d N-Port handle 0x%x "
879 	    "task flags 0x%x seq 0x%x\n";
880 	uint16_t seqid, loopid;
881 
882 	MEMZERO(&nt, sizeof (tmd_notify_t));
883 	nt.nt_hba = isp;
884 	if (FCPARAM(isp)->isp_2klogin) {
885 		nt.nt_iid = ((in_fcentry_e_t *)inp)->in_iid;
886 		loopid = ((in_fcentry_e_t *)inp)->in_iid;
887 		seqid = ((in_fcentry_e_t *)inp)->in_seqid;
888 	} else {
889 		nt.nt_iid = inp->in_iid;
890 		loopid = inp->in_iid;
891 		seqid = inp->in_seqid;
892 	}
893 	/* nt_tgt set in outer layers */
894 	if (FCPARAM(isp)->isp_sccfw) {
895 		nt.nt_lun = inp->in_scclun;
896 	} else {
897 		nt.nt_lun = inp->in_lun;
898 	}
899 	IN_FC_MAKE_TAGID(nt.nt_tagval, 0, 0, seqid);
900 	nt.nt_need_ack = 1;
901 	nt.nt_lreserved = inp;
902 
903 	if (inp->in_status != IN_MSG_RECEIVED) {
904 		isp_prt(isp, ISP_LOGINFO, f2, "immediate notify status",
905 		    inp->in_status, nt.nt_lun, loopid, inp->in_task_flags,
906 		    inp->in_seqid);
907 		isp_notify_ack(isp, inp);
908 		return;
909 	}
910 
911 	if (inp->in_task_flags & TASK_FLAGS_ABORT_TASK_SET) {
912 		isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET",
913 		    loopid, nt.nt_lun, inp->in_seqid);
914 		nt.nt_ncode = NT_ABORT_TASK_SET;
915 	} else if (inp->in_task_flags & TASK_FLAGS_CLEAR_TASK_SET) {
916 		isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET",
917 		    loopid, nt.nt_lun, inp->in_seqid);
918 		nt.nt_ncode = NT_CLEAR_TASK_SET;
919 	} else if (inp->in_task_flags & TASK_FLAGS_LUN_RESET) {
920 		isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET",
921 		    loopid, nt.nt_lun, inp->in_seqid);
922 		nt.nt_ncode = NT_LUN_RESET;
923 	} else if (inp->in_task_flags & TASK_FLAGS_TARGET_RESET) {
924 		isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET",
925 		    loopid, nt.nt_lun, inp->in_seqid);
926 		nt.nt_ncode = NT_TARGET_RESET;
927 	} else if (inp->in_task_flags & TASK_FLAGS_CLEAR_ACA) {
928 		isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA",
929 		    loopid, nt.nt_lun, inp->in_seqid);
930 		nt.nt_ncode = NT_CLEAR_ACA;
931 	} else {
932 		isp_prt(isp, ISP_LOGWARN, f2, "task flag", inp->in_status,
933 		    nt.nt_lun, loopid, inp->in_task_flags,  inp->in_seqid);
934 		isp_notify_ack(isp, inp);
935 		return;
936 	}
937 	(void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt);
938 }
939 
940 #define	HILO(x)	(uint32_t) (x >> 32),  (uint32_t) x
941 static void
942 isp_got_tmf_24xx(ispsoftc_t *isp, at7_entry_t *aep)
943 {
944 	tmd_notify_t nt;
945 	static const char f1[] =
946 	    "%s from PortID 0x%06x lun %d seq 0x%08x%08x";
947 	static const char f2[] =
948 	    "unknown Task Flag 0x%x lun %d PortID 0x%x tag 0x%08x%08x";
949 	uint32_t sid;
950 
951 	MEMZERO(&nt, sizeof (tmd_notify_t));
952 	nt.nt_hba = isp;
953 	nt.nt_iid = INI_ANY;
954 	nt.nt_lun =
955 	    (aep->at_cmnd.fcp_cmnd_lun[0] << 8) |
956 	    (aep->at_cmnd.fcp_cmnd_lun[1]);
957 	/*
958 	 * XXX: VPIDX HAS TO BE DERIVED FROM DESTINATION PORT
959 	 */
960 	nt.nt_tagval = aep->at_rxid;
961 	nt.nt_lreserved = aep;
962 	sid =
963 	    (aep->at_hdr.s_id[0] << 16) |
964 	    (aep->at_hdr.s_id[1] <<  8) |
965 	    (aep->at_hdr.s_id[2]);
966 
967 	if (aep->at_cmnd.fcp_cmnd_task_management &
968 	    FCP_CMND_TMF_ABORT_TASK_SET) {
969 		isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET",
970 		    sid, nt.nt_lun, HILO(nt.nt_tagval));
971 		nt.nt_ncode = NT_ABORT_TASK_SET;
972 	} else if (aep->at_cmnd.fcp_cmnd_task_management &
973 	    FCP_CMND_TMF_CLEAR_TASK_SET) {
974 		isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET",
975 		    sid, nt.nt_lun, HILO(nt.nt_tagval));
976 		nt.nt_ncode = NT_CLEAR_TASK_SET;
977 	} else if (aep->at_cmnd.fcp_cmnd_task_management &
978 	    FCP_CMND_TMF_LUN_RESET) {
979 		isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET",
980 		    sid, nt.nt_lun, HILO(nt.nt_tagval));
981 		nt.nt_ncode = NT_LUN_RESET;
982 	} else if (aep->at_cmnd.fcp_cmnd_task_management &
983 	    FCP_CMND_TMF_TGT_RESET) {
984 		isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET",
985 		    sid, nt.nt_lun, HILO(nt.nt_tagval));
986 		nt.nt_ncode = NT_TARGET_RESET;
987 		nt.nt_lun = LUN_ANY;
988 	} else if (aep->at_cmnd.fcp_cmnd_task_management &
989 	    FCP_CMND_TMF_CLEAR_ACA) {
990 		isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA",
991 		    sid, nt.nt_lun, HILO(nt.nt_tagval));
992 		nt.nt_ncode = NT_CLEAR_ACA;
993 	} else {
994 		isp_prt(isp, ISP_LOGWARN, f2,
995 		    aep->at_cmnd.fcp_cmnd_task_management,
996 		    nt.nt_lun, sid, HILO(nt.nt_tagval));
997 		isp_endcmd(isp, aep, 0, 0);
998 		return;
999 	}
1000 	(void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt);
1001 }
1002 
1003 void
1004 isp_notify_ack(ispsoftc_t *isp, void *arg)
1005 {
1006 	char storage[QENTRY_LEN];
1007 	uint32_t nxti, optr;
1008 	void *outp;
1009 
1010 	if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
1011 		isp_prt(isp, ISP_LOGWARN,
1012 		    "Request Queue Overflow For isp_notify_ack");
1013 		return;
1014 	}
1015 
1016 	MEMZERO(storage, QENTRY_LEN);
1017 
1018 	if (IS_24XX(isp) && arg != NULL && (((isphdr_t *)arg)->rqs_entry_type == RQSTYPE_ATIO)) {
1019 		at7_entry_t *aep = arg;
1020 		isp_endcmd(isp, aep, 0, 0);
1021 		return;
1022 	} else if (IS_24XX(isp) && arg != NULL && (((isphdr_t *)arg)->rqs_entry_type == RQSTYPE_ABTS_RSP)) {
1023 		abts_rsp_t *abts_rsp = (abts_rsp_t *) storage;
1024 		/*
1025 		 * The caller will have set response values as appropriate
1026 		 * in the ABTS structure just before calling us.
1027 		 */
1028 		MEMCPY(abts_rsp, arg, QENTRY_LEN);
1029 		isp_put_abts_rsp(isp, abts_rsp, (abts_rsp_t *)outp);
1030 	} else if (IS_24XX(isp)) {
1031 		na_fcentry_24xx_t *na = (na_fcentry_24xx_t *) storage;
1032 		if (arg) {
1033 			in_fcentry_24xx_t *in = arg;
1034 			na->na_nphdl = in->in_nphdl;
1035 			na->na_status = in->in_status;
1036 			na->na_status_subcode = in->in_status_subcode;
1037 			na->na_rxid = in->in_rxid;
1038 			na->na_oxid = in->in_oxid;
1039 			if (in->in_status == IN24XX_SRR_RCVD) {
1040 				na->na_srr_rxid = in->in_srr_rxid;
1041 				na->na_srr_reloff_hi = in->in_srr_reloff_hi;
1042 				na->na_srr_reloff_lo = in->in_srr_reloff_lo;
1043 				na->na_srr_iu = in->in_srr_iu;
1044 				na->na_srr_flags = 1;
1045 				na->na_srr_reject_vunique = 0;
1046 				na->na_srr_reject_explanation = 1;
1047 				na->na_srr_reject_code = 1;
1048 			}
1049 		}
1050 		na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
1051 		na->na_header.rqs_entry_count = 1;
1052 		isp_put_notify_24xx_ack(isp, na, (na_fcentry_24xx_t *)outp);
1053 	} else if (IS_FC(isp)) {
1054 		na_fcentry_t *na = (na_fcentry_t *) storage;
1055 		int iid = 0;
1056 
1057 		if (arg) {
1058 			in_fcentry_t *inp = arg;
1059 			MEMCPY(storage, arg, sizeof (isphdr_t));
1060 			if (FCPARAM(isp)->isp_2klogin) {
1061 				((na_fcentry_e_t *)na)->na_iid =
1062 				    ((in_fcentry_e_t *)inp)->in_iid;
1063 				iid = ((na_fcentry_e_t *)na)->na_iid;
1064 			} else {
1065 				na->na_iid = inp->in_iid;
1066 				iid = na->na_iid;
1067 			}
1068 			na->na_task_flags =
1069 			    inp->in_task_flags & TASK_FLAGS_RESERVED_MASK;
1070 			na->na_seqid = inp->in_seqid;
1071 			na->na_flags = NAFC_RCOUNT;
1072 			na->na_status = inp->in_status;
1073 			if (inp->in_status == IN_RESET) {
1074 				na->na_flags |= NAFC_RST_CLRD;
1075 			}
1076 			if (inp->in_status == IN_MSG_RECEIVED) {
1077 				na->na_flags |= NAFC_TVALID;
1078 				na->na_response = 0;	/* XXX SUCCEEDED XXX */
1079 			}
1080 		} else {
1081 			na->na_flags = NAFC_RST_CLRD;
1082 		}
1083 		na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
1084 		na->na_header.rqs_entry_count = 1;
1085 		if (FCPARAM(isp)->isp_2klogin) {
1086 			isp_put_notify_ack_fc_e(isp, (na_fcentry_e_t *) na,
1087 			    (na_fcentry_e_t *)outp);
1088 		} else {
1089 			isp_put_notify_ack_fc(isp, na, (na_fcentry_t *)outp);
1090 		}
1091 		isp_prt(isp, ISP_LOGTDEBUG0, "notify ack loopid %u seqid %x "
1092 		    "flags %x tflags %x response %x", iid, na->na_seqid,
1093 		    na->na_flags, na->na_task_flags, na->na_response);
1094 	} else {
1095 		na_entry_t *na = (na_entry_t *) storage;
1096 		if (arg) {
1097 			in_entry_t *inp = arg;
1098 			MEMCPY(storage, arg, sizeof (isphdr_t));
1099 			na->na_iid = inp->in_iid;
1100 			na->na_lun = inp->in_lun;
1101 			na->na_tgt = inp->in_tgt;
1102 			na->na_seqid = inp->in_seqid;
1103 			if (inp->in_status == IN_RESET) {
1104 				na->na_event = NA_RST_CLRD;
1105 			}
1106 		} else {
1107 			na->na_event = NA_RST_CLRD;
1108 		}
1109 		na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
1110 		na->na_header.rqs_entry_count = 1;
1111 		isp_put_notify_ack(isp, na, (na_entry_t *)outp);
1112 		isp_prt(isp, ISP_LOGTDEBUG0, "notify ack loopid %u lun %u tgt "
1113 		    "%u seqid %x event %x", na->na_iid, na->na_lun, na->na_tgt,
1114 		    na->na_seqid, na->na_event);
1115 	}
1116 	ISP_TDQE(isp, "isp_notify_ack", (int) optr, storage);
1117 	ISP_ADD_REQUEST(isp, nxti);
1118 }
1119 
1120 static void
1121 isp_handle_atio(ispsoftc_t *isp, at_entry_t *aep)
1122 {
1123 	int lun;
1124 	lun = aep->at_lun;
1125 	/*
1126 	 * The firmware status (except for the QLTM_SVALID bit) indicates
1127 	 * why this ATIO was sent to us.
1128 	 *
1129 	 * If QLTM_SVALID is set, the firware has recommended Sense Data.
1130 	 *
1131 	 * If the DISCONNECTS DISABLED bit is set in the flags field,
1132 	 * we're still connected on the SCSI bus - i.e. the initiator
1133 	 * did not set DiscPriv in the identify message. We don't care
1134 	 * about this so it's ignored.
1135 	 */
1136 
1137 	switch(aep->at_status & ~QLTM_SVALID) {
1138 	case AT_PATH_INVALID:
1139 		/*
1140 		 * ATIO rejected by the firmware due to disabled lun.
1141 		 */
1142 		isp_prt(isp, ISP_LOGERR,
1143 		    "rejected ATIO for disabled lun %d", lun);
1144 		break;
1145 	case AT_NOCAP:
1146 		/*
1147 		 * Requested Capability not available
1148 		 * We sent an ATIO that overflowed the firmware's
1149 		 * command resource count.
1150 		 */
1151 		isp_prt(isp, ISP_LOGERR,
1152 		    "rejected ATIO for lun %d because of command count"
1153 		    " overflow", lun);
1154 		break;
1155 
1156 	case AT_BDR_MSG:
1157 		/*
1158 		 * If we send an ATIO to the firmware to increment
1159 		 * its command resource count, and the firmware is
1160 		 * recovering from a Bus Device Reset, it returns
1161 		 * the ATIO with this status. We set the command
1162 		 * resource count in the Enable Lun entry and do
1163 		 * not increment it. Therefore we should never get
1164 		 * this status here.
1165 		 */
1166 		isp_prt(isp, ISP_LOGERR, atiocope, lun,
1167 		    GET_BUS_VAL(aep->at_iid));
1168 		break;
1169 
1170 	case AT_CDB:		/* Got a CDB */
1171 	case AT_PHASE_ERROR:	/* Bus Phase Sequence Error */
1172 		/*
1173 		 * Punt to platform specific layer.
1174 		 */
1175 		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
1176 		break;
1177 
1178 	case AT_RESET:
1179 		/*
1180 		 * A bus reset came along and blew away this command. Why
1181 		 * they do this in addition the async event code stuff,
1182 		 * I dunno.
1183 		 *
1184 		 * Ignore it because the async event will clear things
1185 		 * up for us.
1186 		 */
1187 		isp_prt(isp, ISP_LOGWARN, atior, lun,
1188 		    GET_IID_VAL(aep->at_iid), GET_BUS_VAL(aep->at_iid));
1189 		break;
1190 
1191 
1192 	default:
1193 		isp_prt(isp, ISP_LOGERR,
1194 		    "Unknown ATIO status 0x%x from loopid %d for lun %d",
1195 		    aep->at_status, aep->at_iid, lun);
1196 		(void) isp_target_put_atio(isp, aep);
1197 		break;
1198 	}
1199 }
1200 
1201 static void
1202 isp_handle_atio2(ispsoftc_t *isp, at2_entry_t *aep)
1203 {
1204 	int lun, iid;
1205 
1206 	if (FCPARAM(isp)->isp_sccfw) {
1207 		lun = aep->at_scclun;
1208 	} else {
1209 		lun = aep->at_lun;
1210 	}
1211 
1212 	if (FCPARAM(isp)->isp_2klogin) {
1213 		iid = ((at2e_entry_t *)aep)->at_iid;
1214 	} else {
1215 		iid = aep->at_iid;
1216 	}
1217 
1218 	/*
1219 	 * The firmware status (except for the QLTM_SVALID bit) indicates
1220 	 * why this ATIO was sent to us.
1221 	 *
1222 	 * If QLTM_SVALID is set, the firware has recommended Sense Data.
1223 	 *
1224 	 * If the DISCONNECTS DISABLED bit is set in the flags field,
1225 	 * we're still connected on the SCSI bus - i.e. the initiator
1226 	 * did not set DiscPriv in the identify message. We don't care
1227 	 * about this so it's ignored.
1228 	 */
1229 
1230 	switch(aep->at_status & ~QLTM_SVALID) {
1231 	case AT_PATH_INVALID:
1232 		/*
1233 		 * ATIO rejected by the firmware due to disabled lun.
1234 		 */
1235 		isp_prt(isp, ISP_LOGERR,
1236 		    "rejected ATIO2 for disabled lun %d", lun);
1237 		break;
1238 	case AT_NOCAP:
1239 		/*
1240 		 * Requested Capability not available
1241 		 * We sent an ATIO that overflowed the firmware's
1242 		 * command resource count.
1243 		 */
1244 		isp_prt(isp, ISP_LOGERR,
1245 		    "rejected ATIO2 for lun %d- command count overflow", lun);
1246 		break;
1247 
1248 	case AT_BDR_MSG:
1249 		/*
1250 		 * If we send an ATIO to the firmware to increment
1251 		 * its command resource count, and the firmware is
1252 		 * recovering from a Bus Device Reset, it returns
1253 		 * the ATIO with this status. We set the command
1254 		 * resource count in the Enable Lun entry and no
1255 		 * not increment it. Therefore we should never get
1256 		 * this status here.
1257 		 */
1258 		isp_prt(isp, ISP_LOGERR, atiocope, lun, 0);
1259 		break;
1260 
1261 	case AT_CDB:		/* Got a CDB */
1262 		/*
1263 		 * Punt to platform specific layer.
1264 		 */
1265 		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
1266 		break;
1267 
1268 	case AT_RESET:
1269 		/*
1270 		 * A bus reset came along an blew away this command. Why
1271 		 * they do this in addition the async event code stuff,
1272 		 * I dunno.
1273 		 *
1274 		 * Ignore it because the async event will clear things
1275 		 * up for us.
1276 		 */
1277 		isp_prt(isp, ISP_LOGERR, atior, lun, iid, 0);
1278 		break;
1279 
1280 
1281 	default:
1282 		isp_prt(isp, ISP_LOGERR,
1283 		    "Unknown ATIO2 status 0x%x from loopid %d for lun %d",
1284 		    aep->at_status, iid, lun);
1285 		(void) isp_target_put_atio(isp, aep);
1286 		break;
1287 	}
1288 }
1289 
1290 static void
1291 isp_handle_ctio(ispsoftc_t *isp, ct_entry_t *ct)
1292 {
1293 	void *xs;
1294 	int pl = ISP_LOGTDEBUG2;
1295 	char *fmsg = NULL;
1296 
1297 	if (ct->ct_syshandle) {
1298 		xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1299 		if (xs == NULL) {
1300 			pl = ISP_LOGALL;
1301 		}
1302 	} else {
1303 		xs = NULL;
1304 	}
1305 
1306 	switch(ct->ct_status & ~QLTM_SVALID) {
1307 	case CT_OK:
1308 		/*
1309 		 * There are generally 3 possibilities as to why we'd get
1310 		 * this condition:
1311 		 * 	We disconnected after receiving a CDB.
1312 		 * 	We sent or received data.
1313 		 * 	We sent status & command complete.
1314 		 */
1315 
1316 		if (ct->ct_flags & CT_SENDSTATUS) {
1317 			break;
1318 		} else if ((ct->ct_flags & CT_DATAMASK) == CT_NO_DATA) {
1319 			/*
1320 			 * Nothing to do in this case.
1321 			 */
1322 			isp_prt(isp, pl, "CTIO- iid %d disconnected OK",
1323 			    ct->ct_iid);
1324 			return;
1325 		}
1326 		break;
1327 
1328 	case CT_BDR_MSG:
1329 		/*
1330 		 * Bus Device Reset message received or the SCSI Bus has
1331 		 * been Reset; the firmware has gone to Bus Free.
1332 		 *
1333 		 * The firmware generates an async mailbox interupt to
1334 		 * notify us of this and returns outstanding CTIOs with this
1335 		 * status. These CTIOs are handled in that same way as
1336 		 * CT_ABORTED ones, so just fall through here.
1337 		 */
1338 		fmsg = "Bus Device Reset";
1339 		/*FALLTHROUGH*/
1340 	case CT_RESET:
1341 		if (fmsg == NULL)
1342 			fmsg = "Bus Reset";
1343 		/*FALLTHROUGH*/
1344 	case CT_ABORTED:
1345 		/*
1346 		 * When an Abort message is received the firmware goes to
1347 		 * Bus Free and returns all outstanding CTIOs with the status
1348 		 * set, then sends us an Immediate Notify entry.
1349 		 */
1350 		if (fmsg == NULL)
1351 			fmsg = "ABORT TAG message sent by Initiator";
1352 
1353 		isp_prt(isp, ISP_LOGTDEBUG0, "CTIO destroyed by %s", fmsg);
1354 		break;
1355 
1356 	case CT_INVAL:
1357 		/*
1358 		 * CTIO rejected by the firmware due to disabled lun.
1359 		 * "Cannot Happen".
1360 		 */
1361 		isp_prt(isp, ISP_LOGERR,
1362 		    "Firmware rejected CTIO for disabled lun %d",
1363 		    ct->ct_lun);
1364 		break;
1365 
1366 	case CT_NOPATH:
1367 		/*
1368 		 * CTIO rejected by the firmware due "no path for the
1369 		 * nondisconnecting nexus specified". This means that
1370 		 * we tried to access the bus while a non-disconnecting
1371 		 * command is in process.
1372 		 */
1373 		isp_prt(isp, ISP_LOGERR,
1374 		    "Firmware rejected CTIO for bad nexus %d/%d/%d",
1375 		    ct->ct_iid, ct->ct_tgt, ct->ct_lun);
1376 		break;
1377 
1378 	case CT_RSELTMO:
1379 		fmsg = "Reselection";
1380 		/*FALLTHROUGH*/
1381 	case CT_TIMEOUT:
1382 		if (fmsg == NULL)
1383 			fmsg = "Command";
1384 		isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
1385 		break;
1386 
1387 	case	CT_PANIC:
1388 		if (fmsg == NULL)
1389 			fmsg = "Unrecoverable Error";
1390 		/*FALLTHROUGH*/
1391 	case CT_ERR:
1392 		if (fmsg == NULL)
1393 			fmsg = "Completed with Error";
1394 		/*FALLTHROUGH*/
1395 	case CT_PHASE_ERROR:
1396 		if (fmsg == NULL)
1397 			fmsg = "Phase Sequence Error";
1398 		/*FALLTHROUGH*/
1399 	case CT_TERMINATED:
1400 		if (fmsg == NULL)
1401 			fmsg = "terminated by TERMINATE TRANSFER";
1402 		/*FALLTHROUGH*/
1403 	case CT_NOACK:
1404 		if (fmsg == NULL)
1405 			fmsg = "unacknowledged Immediate Notify pending";
1406 		isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg);
1407 		break;
1408 	default:
1409 		isp_prt(isp, ISP_LOGERR, "Unknown CTIO status 0x%x",
1410 		    ct->ct_status & ~QLTM_SVALID);
1411 		break;
1412 	}
1413 
1414 	if (xs == NULL) {
1415 		/*
1416 		 * There may be more than one CTIO for a data transfer,
1417 		 * or this may be a status CTIO we're not monitoring.
1418 		 *
1419 		 * The assumption is that they'll all be returned in the
1420 		 * order we got them.
1421 		 */
1422 		if (ct->ct_syshandle == 0) {
1423 			if ((ct->ct_flags & CT_SENDSTATUS) == 0) {
1424 				isp_prt(isp, pl,
1425 				    "intermediate CTIO completed ok");
1426 			} else {
1427 				isp_prt(isp, pl,
1428 				    "unmonitored CTIO completed ok");
1429 			}
1430 		} else {
1431 			isp_prt(isp, pl,
1432 			    "NO xs for CTIO (handle 0x%x) status 0x%x",
1433 			    ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1434 		}
1435 	} else {
1436 		/*
1437 		 * Final CTIO completed. Release DMA resources and
1438 		 * notify platform dependent layers.
1439 		 */
1440 		if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) {
1441 			ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1442 		}
1443 		isp_prt(isp, pl, "final CTIO complete");
1444 		/*
1445 		 * The platform layer will destroy the handle if appropriate.
1446 		 */
1447 		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1448 	}
1449 }
1450 
1451 static void
1452 isp_handle_ctio2(ispsoftc_t *isp, ct2_entry_t *ct)
1453 {
1454 	void *xs;
1455 	int pl = ISP_LOGTDEBUG2;
1456 	char *fmsg = NULL;
1457 
1458 	if (ct->ct_syshandle) {
1459 		xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1460 		if (xs == NULL) {
1461 			pl = ISP_LOGALL;
1462 		}
1463 	} else {
1464 		xs = NULL;
1465 	}
1466 
1467 	switch(ct->ct_status & ~QLTM_SVALID) {
1468 	case CT_BUS_ERROR:
1469 		isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error");
1470 		/* FALL Through */
1471 	case CT_DATA_OVER:
1472 	case CT_DATA_UNDER:
1473 	case CT_OK:
1474 		/*
1475 		 * There are generally 2 possibilities as to why we'd get
1476 		 * this condition:
1477 		 * 	We sent or received data.
1478 		 * 	We sent status & command complete.
1479 		 */
1480 
1481 		break;
1482 
1483 	case CT_BDR_MSG:
1484 		/*
1485 		 * Target Reset function received.
1486 		 *
1487 		 * The firmware generates an async mailbox interupt to
1488 		 * notify us of this and returns outstanding CTIOs with this
1489 		 * status. These CTIOs are handled in that same way as
1490 		 * CT_ABORTED ones, so just fall through here.
1491 		 */
1492 		fmsg = "TARGET RESET";
1493 		/*FALLTHROUGH*/
1494 	case CT_RESET:
1495 		if (fmsg == NULL)
1496 			fmsg = "LIP Reset";
1497 		/*FALLTHROUGH*/
1498 	case CT_ABORTED:
1499 		/*
1500 		 * When an Abort message is received the firmware goes to
1501 		 * Bus Free and returns all outstanding CTIOs with the status
1502 		 * set, then sends us an Immediate Notify entry.
1503 		 */
1504 		if (fmsg == NULL) {
1505 			fmsg = "ABORT";
1506 		}
1507 
1508 		isp_prt(isp, ISP_LOGTDEBUG0,
1509 		    "CTIO2 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid);
1510 		break;
1511 
1512 	case CT_INVAL:
1513 		/*
1514 		 * CTIO rejected by the firmware - invalid data direction.
1515 		 */
1516 		isp_prt(isp, ISP_LOGERR, "CTIO2 had wrong data direction");
1517 		break;
1518 
1519 	case CT_RSELTMO:
1520 		fmsg = "failure to reconnect to initiator";
1521 		/*FALLTHROUGH*/
1522 	case CT_TIMEOUT:
1523 		if (fmsg == NULL)
1524 			fmsg = "command";
1525 		isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
1526 		break;
1527 
1528 	case CT_ERR:
1529 		fmsg = "Completed with Error";
1530 		/*FALLTHROUGH*/
1531 	case CT_LOGOUT:
1532 		if (fmsg == NULL)
1533 			fmsg = "Port Logout";
1534 		/*FALLTHROUGH*/
1535 	case CT_PORTUNAVAIL:
1536 		if (fmsg == NULL)
1537 			fmsg = "Port not available";
1538 		/*FALLTHROUGH*/
1539 	case CT_PORTCHANGED:
1540 		if (fmsg == NULL)
1541 			fmsg = "Port Changed";
1542 		/*FALLTHROUGH*/
1543 	case CT_NOACK:
1544 		if (fmsg == NULL)
1545 			fmsg = "unacknowledged Immediate Notify pending";
1546 		isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg);
1547 		break;
1548 
1549 	case CT_INVRXID:
1550 		/*
1551 		 * CTIO rejected by the firmware because an invalid RX_ID.
1552 		 * Just print a message.
1553 		 */
1554 		isp_prt(isp, ISP_LOGWARN,
1555 		    "CTIO2 completed with Invalid RX_ID 0x%x", ct->ct_rxid);
1556 		break;
1557 
1558 	default:
1559 		isp_prt(isp, ISP_LOGERR, "Unknown CTIO2 status 0x%x",
1560 		    ct->ct_status & ~QLTM_SVALID);
1561 		break;
1562 	}
1563 
1564 	if (xs == NULL) {
1565 		/*
1566 		 * There may be more than one CTIO for a data transfer,
1567 		 * or this may be a status CTIO we're not monitoring.
1568 		 *
1569 		 * The assumption is that they'll all be returned in the
1570 		 * order we got them.
1571 		 */
1572 		if (ct->ct_syshandle == 0) {
1573 			if ((ct->ct_flags & CT2_SENDSTATUS) == 0) {
1574 				isp_prt(isp, pl,
1575 				    "intermediate CTIO completed ok");
1576 			} else {
1577 				isp_prt(isp, pl,
1578 				    "unmonitored CTIO completed ok");
1579 			}
1580 		} else {
1581 			isp_prt(isp, pl,
1582 			    "NO xs for CTIO (handle 0x%x) status 0x%x",
1583 			    ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1584 		}
1585 	} else {
1586 		if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
1587 			ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1588 		}
1589 		if (ct->ct_flags & CT2_SENDSTATUS) {
1590 			/*
1591 			 * Sent status and command complete.
1592 			 *
1593 			 * We're now really done with this command, so we
1594 			 * punt to the platform dependent layers because
1595 			 * only there can we do the appropriate command
1596 			 * complete thread synchronization.
1597 			 */
1598 			isp_prt(isp, pl, "status CTIO complete");
1599 		} else {
1600 			/*
1601 			 * Final CTIO completed. Release DMA resources and
1602 			 * notify platform dependent layers.
1603 			 */
1604 			isp_prt(isp, pl, "data CTIO complete");
1605 		}
1606 		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1607 		/*
1608 		 * The platform layer will destroy the handle if appropriate.
1609 		 */
1610 	}
1611 }
1612 
1613 static void
1614 isp_handle_ctio7(ispsoftc_t *isp, ct7_entry_t *ct)
1615 {
1616 	void *xs;
1617 	int pl = ISP_LOGTDEBUG2;
1618 	char *fmsg = NULL;
1619 
1620 	if (ct->ct_syshandle) {
1621 		xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1622 		if (xs == NULL) {
1623 			pl = ISP_LOGALL;
1624 		}
1625 	} else {
1626 		xs = NULL;
1627 	}
1628 
1629 	switch(ct->ct_nphdl) {
1630 	case CT7_BUS_ERROR:
1631 		isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error");
1632 		/* FALL Through */
1633 	case CT7_DATA_OVER:
1634 	case CT7_DATA_UNDER:
1635 	case CT7_OK:
1636 		/*
1637 		 * There are generally 2 possibilities as to why we'd get
1638 		 * this condition:
1639 		 * 	We sent or received data.
1640 		 * 	We sent status & command complete.
1641 		 */
1642 
1643 		break;
1644 
1645 	case CT7_RESET:
1646 		if (fmsg == NULL) {
1647 			fmsg = "LIP Reset";
1648 		}
1649 		/*FALLTHROUGH*/
1650 	case CT7_ABORTED:
1651 		/*
1652 		 * When an Abort message is received the firmware goes to
1653 		 * Bus Free and returns all outstanding CTIOs with the status
1654 		 * set, then sends us an Immediate Notify entry.
1655 		 */
1656 		if (fmsg == NULL) {
1657 			fmsg = "ABORT";
1658 		}
1659 		isp_prt(isp, ISP_LOGTDEBUG0,
1660 		    "CTIO7 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid);
1661 		break;
1662 
1663 	case CT7_TIMEOUT:
1664 		if (fmsg == NULL) {
1665 			fmsg = "command";
1666 		}
1667 		isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
1668 		break;
1669 
1670 	case CT7_ERR:
1671 		fmsg = "Completed with Error";
1672 		/*FALLTHROUGH*/
1673 	case CT7_LOGOUT:
1674 		if (fmsg == NULL) {
1675 			fmsg = "Port Logout";
1676 		}
1677 		/*FALLTHROUGH*/
1678 	case CT7_PORTUNAVAIL:
1679 		if (fmsg == NULL) {
1680 			fmsg = "Port not available";
1681 		}
1682 		/*FALLTHROUGH*/
1683 	case CT7_PORTCHANGED:
1684 		if (fmsg == NULL) {
1685 			fmsg = "Port Changed";
1686 		}
1687 		isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg);
1688 		break;
1689 
1690 	case CT7_INVRXID:
1691 		/*
1692 		 * CTIO rejected by the firmware because an invalid RX_ID.
1693 		 * Just print a message.
1694 		 */
1695 		isp_prt(isp, ISP_LOGWARN,
1696 		    "CTIO7 completed with Invalid RX_ID 0x%x", ct->ct_rxid);
1697 		break;
1698 
1699 	case CT7_REASSY_ERR:
1700 		isp_prt(isp, ISP_LOGWARN, "reassembly error");
1701 		break;
1702 
1703 	case CT7_SRR:
1704 		isp_prt(isp, ISP_LOGWARN, "SRR received");
1705 		break;
1706 
1707 	default:
1708 		isp_prt(isp, ISP_LOGERR, "Unknown CTIO7 status 0x%x",
1709 		    ct->ct_nphdl);
1710 		break;
1711 	}
1712 
1713 	if (xs == NULL) {
1714 		/*
1715 		 * There may be more than one CTIO for a data transfer,
1716 		 * or this may be a status CTIO we're not monitoring.
1717 		 *
1718 		 * The assumption is that they'll all be returned in the
1719 		 * order we got them.
1720 		 */
1721 		if (ct->ct_syshandle == 0) {
1722 			if (ct->ct_flags & CT7_TERMINATE) {
1723 				isp_prt(isp, ISP_LOGINFO,
1724 				    "termination of 0x%x complete",
1725 				    ct->ct_rxid);
1726 			} else if ((ct->ct_flags & CT7_SENDSTATUS) == 0) {
1727 				isp_prt(isp, pl,
1728 				    "intermediate CTIO completed ok");
1729 			} else {
1730 				isp_prt(isp, pl,
1731 				    "unmonitored CTIO completed ok");
1732 			}
1733 		} else {
1734 			isp_prt(isp, pl,
1735 			    "NO xs for CTIO (handle 0x%x) status 0x%x",
1736 			    ct->ct_syshandle, ct->ct_nphdl);
1737 		}
1738 	} else {
1739 		if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
1740 			ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1741 		}
1742 		if (ct->ct_flags & CT2_SENDSTATUS) {
1743 			/*
1744 			 * Sent status and command complete.
1745 			 *
1746 			 * We're now really done with this command, so we
1747 			 * punt to the platform dependent layers because
1748 			 * only there can we do the appropriate command
1749 			 * complete thread synchronization.
1750 			 */
1751 			isp_prt(isp, pl, "status CTIO complete");
1752 		} else {
1753 			/*
1754 			 * Final CTIO completed. Release DMA resources and
1755 			 * notify platform dependent layers.
1756 			 */
1757 			isp_prt(isp, pl, "data CTIO complete");
1758 		}
1759 		(void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1760 		/*
1761 		 * The platform layer will destroy the handle if appropriate.
1762 		 */
1763 	}
1764 }
1765 #endif
1766