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