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