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