1098ca2bdSWarner Losh /*- 22df76c16SMatt Jacob * Copyright (c) 1997-2009 by Matthew Jacob 3ea49c6e4SMatt Jacob * All rights reserved. 4ea49c6e4SMatt Jacob * 5ea49c6e4SMatt Jacob * Redistribution and use in source and binary forms, with or without 6ea49c6e4SMatt Jacob * modification, are permitted provided that the following conditions 7ea49c6e4SMatt Jacob * are met: 8ea49c6e4SMatt Jacob * 9e48b2487SMatt Jacob * 1. Redistributions of source code must retain the above copyright 10e48b2487SMatt Jacob * notice, this list of conditions and the following disclaimer. 11e48b2487SMatt Jacob * 2. Redistributions in binary form must reproduce the above copyright 12e48b2487SMatt Jacob * notice, this list of conditions and the following disclaimer in the 13e48b2487SMatt Jacob * documentation and/or other materials provided with the distribution. 14e48b2487SMatt Jacob * 15e48b2487SMatt Jacob * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16ea49c6e4SMatt Jacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17ea49c6e4SMatt Jacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18e48b2487SMatt Jacob * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 19e48b2487SMatt Jacob * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20ea49c6e4SMatt Jacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21ea49c6e4SMatt Jacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22ea49c6e4SMatt Jacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23ea49c6e4SMatt Jacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24ea49c6e4SMatt Jacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25ea49c6e4SMatt Jacob * SUCH DAMAGE. 262df76c16SMatt Jacob * 27ea49c6e4SMatt Jacob */ 28ea49c6e4SMatt Jacob /* 29e48b2487SMatt Jacob * Machine and OS Independent Target Mode Code for the Qlogic SCSI/FC adapters. 30e48b2487SMatt Jacob */ 31e48b2487SMatt Jacob /* 3275c1e828SMatt Jacob * Bug fixes gratefully acknowledged from: 3375c1e828SMatt Jacob * Oded Kedem <oded@kashya.com> 3475c1e828SMatt Jacob */ 3575c1e828SMatt Jacob /* 36ea49c6e4SMatt Jacob * Include header file appropriate for platform we're building on. 37ea49c6e4SMatt Jacob */ 38ea49c6e4SMatt Jacob 39ea49c6e4SMatt Jacob #ifdef __NetBSD__ 40ea49c6e4SMatt Jacob #include <dev/ic/isp_netbsd.h> 41ea49c6e4SMatt Jacob #endif 42ea49c6e4SMatt Jacob #ifdef __FreeBSD__ 43799881e0SMatt Jacob #include <sys/cdefs.h> 44799881e0SMatt Jacob __FBSDID("$FreeBSD$"); 45ea49c6e4SMatt Jacob #include <dev/isp/isp_freebsd.h> 46ea49c6e4SMatt Jacob #endif 47ea49c6e4SMatt Jacob #ifdef __OpenBSD__ 48ea49c6e4SMatt Jacob #include <dev/ic/isp_openbsd.h> 49ea49c6e4SMatt Jacob #endif 50ea49c6e4SMatt Jacob #ifdef __linux__ 51ea49c6e4SMatt Jacob #include "isp_linux.h" 52ea49c6e4SMatt Jacob #endif 53ea49c6e4SMatt Jacob 54ea49c6e4SMatt Jacob #ifdef ISP_TARGET_MODE 552df76c16SMatt Jacob static const char atiocope[] = "ATIO returned for lun %d because it was in the middle of Bus Device Reset on bus %d"; 562df76c16SMatt Jacob static const char atior[] = "ATIO returned on for lun %d on from loopid %d because a Bus Reset occurred on bus %d"; 572df76c16SMatt Jacob static const char rqo[] = "%s: Request Queue Overflow"; 58ea49c6e4SMatt Jacob 599cd7268eSMatt Jacob static void isp_got_msg(ispsoftc_t *, in_entry_t *); 609cd7268eSMatt Jacob static void isp_got_msg_fc(ispsoftc_t *, in_fcentry_t *); 6110365e5aSMatt Jacob static void isp_got_tmf_24xx(ispsoftc_t *, at7_entry_t *); 629cd7268eSMatt Jacob static void isp_handle_atio(ispsoftc_t *, at_entry_t *); 639cd7268eSMatt Jacob static void isp_handle_atio2(ispsoftc_t *, at2_entry_t *); 649cd7268eSMatt Jacob static void isp_handle_ctio(ispsoftc_t *, ct_entry_t *); 659cd7268eSMatt Jacob static void isp_handle_ctio2(ispsoftc_t *, ct2_entry_t *); 6610365e5aSMatt Jacob static void isp_handle_ctio7(ispsoftc_t *, ct7_entry_t *); 672df76c16SMatt Jacob static void isp_handle_24xx_inotify(ispsoftc_t *, in_fcentry_24xx_t *); 68ea49c6e4SMatt Jacob 69ea49c6e4SMatt Jacob /* 70ea49c6e4SMatt Jacob * The Qlogic driver gets an interrupt to look at response queue entries. 71ea49c6e4SMatt Jacob * Some of these are status completions for initiatior mode commands, but 72ea49c6e4SMatt Jacob * if target mode is enabled, we get a whole wad of response queue entries 73ea49c6e4SMatt Jacob * to be handled here. 74ea49c6e4SMatt Jacob * 75ea49c6e4SMatt Jacob * Basically the split into 3 main groups: Lun Enable/Modification responses, 76ea49c6e4SMatt Jacob * SCSI Command processing, and Immediate Notification events. 77ea49c6e4SMatt Jacob * 78ea49c6e4SMatt Jacob * You start by writing a request queue entry to enable target mode (and 79ea49c6e4SMatt Jacob * establish some resource limitations which you can modify later). 80ea49c6e4SMatt Jacob * The f/w responds with a LUN ENABLE or LUN MODIFY response with 81ea49c6e4SMatt Jacob * the status of this action. If the enable was successful, you can expect... 82ea49c6e4SMatt Jacob * 83ea49c6e4SMatt Jacob * Response queue entries with SCSI commands encapsulate show up in an ATIO 84ea49c6e4SMatt Jacob * (Accept Target IO) type- sometimes with enough info to stop the command at 85ea49c6e4SMatt Jacob * this level. Ultimately the driver has to feed back to the f/w's request 86ea49c6e4SMatt Jacob * queue a sequence of CTIOs (continue target I/O) that describe data to 87ea49c6e4SMatt Jacob * be moved and/or status to be sent) and finally finishing with sending 88ea49c6e4SMatt Jacob * to the f/w's response queue an ATIO which then completes the handshake 89ea49c6e4SMatt Jacob * with the f/w for that command. There's a lot of variations on this theme, 90ea49c6e4SMatt Jacob * including flags you can set in the CTIO for the Qlogic 2X00 fibre channel 91ea49c6e4SMatt Jacob * cards that 'auto-replenish' the f/w's ATIO count, but this is the basic 92ea49c6e4SMatt Jacob * gist of it. 93ea49c6e4SMatt Jacob * 94ea49c6e4SMatt Jacob * The third group that can show up in the response queue are Immediate 95ea49c6e4SMatt Jacob * Notification events. These include things like notifications of SCSI bus 96ea49c6e4SMatt Jacob * resets, or Bus Device Reset messages or other messages received. This 97f09deb69SJeroen Ruigrok van der Werven * a classic oddbins area. It can get a little weird because you then turn 98ea49c6e4SMatt Jacob * around and acknowledge the Immediate Notify by writing an entry onto the 99ea49c6e4SMatt Jacob * request queue and then the f/w turns around and gives you an acknowledgement 100ea49c6e4SMatt Jacob * to *your* acknowledgement on the response queue (the idea being to let 101ea49c6e4SMatt Jacob * the f/w tell you when the event is *really* over I guess). 102ea49c6e4SMatt Jacob * 103ea49c6e4SMatt Jacob */ 104ea49c6e4SMatt Jacob 105ea49c6e4SMatt Jacob 106ea49c6e4SMatt Jacob /* 107ea49c6e4SMatt Jacob * A new response queue entry has arrived. The interrupt service code 108ea49c6e4SMatt Jacob * has already swizzled it into the platform dependent from canonical form. 109ea49c6e4SMatt Jacob * 110ea49c6e4SMatt Jacob * Because of the way this driver is designed, unfortunately most of the 111ea49c6e4SMatt Jacob * actual synchronization work has to be done in the platform specific 112ea49c6e4SMatt Jacob * code- we have no synchroniation primitives in the common code. 113ea49c6e4SMatt Jacob */ 114ea49c6e4SMatt Jacob 115ea49c6e4SMatt Jacob int 11610365e5aSMatt Jacob isp_target_notify(ispsoftc_t *isp, void *vptr, uint32_t *optrp) 117ea49c6e4SMatt Jacob { 11810365e5aSMatt Jacob uint16_t status; 11910365e5aSMatt Jacob uint32_t seqid; 120ea49c6e4SMatt Jacob union { 121ea49c6e4SMatt Jacob at_entry_t *atiop; 122ea49c6e4SMatt Jacob at2_entry_t *at2iop; 123e5265237SMatt Jacob at2e_entry_t *at2eiop; 12410365e5aSMatt Jacob at7_entry_t *at7iop; 125ea49c6e4SMatt Jacob ct_entry_t *ctiop; 126ea49c6e4SMatt Jacob ct2_entry_t *ct2iop; 127e5265237SMatt Jacob ct2e_entry_t *ct2eiop; 12810365e5aSMatt Jacob ct7_entry_t *ct7iop; 129ea49c6e4SMatt Jacob lun_entry_t *lunenp; 130ea49c6e4SMatt Jacob in_entry_t *inotp; 131ea49c6e4SMatt Jacob in_fcentry_t *inot_fcp; 132e5265237SMatt Jacob in_fcentry_e_t *inote_fcp; 13310365e5aSMatt Jacob in_fcentry_24xx_t *inot_24xx; 134ea49c6e4SMatt Jacob na_entry_t *nackp; 135ea49c6e4SMatt Jacob na_fcentry_t *nack_fcp; 136e5265237SMatt Jacob na_fcentry_e_t *nacke_fcp; 13710365e5aSMatt Jacob na_fcentry_24xx_t *nack_24xx; 138ea49c6e4SMatt Jacob isphdr_t *hp; 13910365e5aSMatt Jacob abts_t *abts; 14010365e5aSMatt Jacob abts_rsp_t *abts_rsp; 14110365e5aSMatt Jacob els_t *els; 142ea49c6e4SMatt Jacob void * *vp; 143ea49c6e4SMatt Jacob #define atiop unp.atiop 144ea49c6e4SMatt Jacob #define at2iop unp.at2iop 145e5265237SMatt Jacob #define at2eiop unp.at2eiop 14610365e5aSMatt Jacob #define at7iop unp.at7iop 147ea49c6e4SMatt Jacob #define ctiop unp.ctiop 148ea49c6e4SMatt Jacob #define ct2iop unp.ct2iop 149e5265237SMatt Jacob #define ct2eiop unp.ct2eiop 15010365e5aSMatt Jacob #define ct7iop unp.ct7iop 151ea49c6e4SMatt Jacob #define lunenp unp.lunenp 152ea49c6e4SMatt Jacob #define inotp unp.inotp 153ea49c6e4SMatt Jacob #define inot_fcp unp.inot_fcp 154e5265237SMatt Jacob #define inote_fcp unp.inote_fcp 15510365e5aSMatt Jacob #define inot_24xx unp.inot_24xx 156ea49c6e4SMatt Jacob #define nackp unp.nackp 157ea49c6e4SMatt Jacob #define nack_fcp unp.nack_fcp 158e5265237SMatt Jacob #define nacke_fcp unp.nacke_fcp 15910365e5aSMatt Jacob #define nack_24xx unp.nack_24xx 16010365e5aSMatt Jacob #define abts unp.abts 16110365e5aSMatt Jacob #define abts_rsp unp.abts_rsp 16210365e5aSMatt Jacob #define els unp.els 163ea49c6e4SMatt Jacob #define hdrp unp.hp 164ea49c6e4SMatt Jacob } unp; 1651dae40ebSMatt Jacob uint8_t local[QENTRY_LEN]; 1662df76c16SMatt Jacob uint16_t iid; 16710365e5aSMatt Jacob int bus, type, level, rval = 1; 1682df76c16SMatt Jacob isp_notify_t notify; 169ea49c6e4SMatt Jacob 1704fd13c1bSMatt Jacob type = isp_get_response_type(isp, (isphdr_t *)vptr); 171ea49c6e4SMatt Jacob unp.vp = vptr; 172ea49c6e4SMatt Jacob 173ea49c6e4SMatt Jacob ISP_TDQE(isp, "isp_target_notify", (int) *optrp, vptr); 174ea49c6e4SMatt Jacob 1754fd13c1bSMatt Jacob switch (type) { 176ea49c6e4SMatt Jacob case RQSTYPE_ATIO: 17710365e5aSMatt Jacob if (IS_24XX(isp)) { 17810365e5aSMatt Jacob int len; 17910365e5aSMatt Jacob 18010365e5aSMatt Jacob isp_get_atio7(isp, at7iop, (at7_entry_t *) local); 18110365e5aSMatt Jacob at7iop = (at7_entry_t *) local; 18210365e5aSMatt Jacob /* 1832df76c16SMatt Jacob * Check for and do something with commands whose 1842df76c16SMatt Jacob * IULEN extends past a single queue entry. 18510365e5aSMatt Jacob */ 18610365e5aSMatt Jacob len = at7iop->at_ta_len & 0xfffff; 18710365e5aSMatt Jacob if (len > (QENTRY_LEN - 8)) { 18810365e5aSMatt Jacob len -= (QENTRY_LEN - 8); 1892df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, "long IU length (%d) ignored", len); 19010365e5aSMatt Jacob while (len > 0) { 1912df76c16SMatt Jacob *optrp = ISP_NXT_QENTRY(*optrp, RESULT_QUEUE_LEN(isp)); 19210365e5aSMatt Jacob len -= QENTRY_LEN; 19310365e5aSMatt Jacob } 19410365e5aSMatt Jacob } 19510365e5aSMatt Jacob /* 19610365e5aSMatt Jacob * Check for a task management function 19710365e5aSMatt Jacob */ 19810365e5aSMatt Jacob if (at7iop->at_cmnd.fcp_cmnd_task_management) { 19910365e5aSMatt Jacob isp_got_tmf_24xx(isp, at7iop); 20010365e5aSMatt Jacob break; 20110365e5aSMatt Jacob } 20210365e5aSMatt Jacob /* 20310365e5aSMatt Jacob * Just go straight to outer layer for this one. 20410365e5aSMatt Jacob */ 2052df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_ACTION, local); 20610365e5aSMatt Jacob } else { 2074fd13c1bSMatt Jacob isp_get_atio(isp, atiop, (at_entry_t *) local); 2084fd13c1bSMatt Jacob isp_handle_atio(isp, (at_entry_t *) local); 20910365e5aSMatt Jacob } 210ea49c6e4SMatt Jacob break; 21110365e5aSMatt Jacob 212ea49c6e4SMatt Jacob case RQSTYPE_CTIO: 2134fd13c1bSMatt Jacob isp_get_ctio(isp, ctiop, (ct_entry_t *) local); 2144fd13c1bSMatt Jacob isp_handle_ctio(isp, (ct_entry_t *) local); 215ea49c6e4SMatt Jacob break; 21610365e5aSMatt Jacob 217ea49c6e4SMatt Jacob case RQSTYPE_ATIO2: 2182df76c16SMatt Jacob if (ISP_CAP_2KLOGIN(isp)) { 219e5265237SMatt Jacob isp_get_atio2e(isp, at2eiop, (at2e_entry_t *) local); 22099ece8d6SMatt Jacob } else { 2214fd13c1bSMatt Jacob isp_get_atio2(isp, at2iop, (at2_entry_t *) local); 22299ece8d6SMatt Jacob } 2234fd13c1bSMatt Jacob isp_handle_atio2(isp, (at2_entry_t *) local); 224ea49c6e4SMatt Jacob break; 22510365e5aSMatt Jacob 226ac9d0a02SMatt Jacob case RQSTYPE_CTIO3: 227ea49c6e4SMatt Jacob case RQSTYPE_CTIO2: 2282df76c16SMatt Jacob if (ISP_CAP_2KLOGIN(isp)) { 229e5265237SMatt Jacob isp_get_ctio2e(isp, ct2eiop, (ct2e_entry_t *) local); 23099ece8d6SMatt Jacob } else { 2314fd13c1bSMatt Jacob isp_get_ctio2(isp, ct2iop, (ct2_entry_t *) local); 23299ece8d6SMatt Jacob } 2334fd13c1bSMatt Jacob isp_handle_ctio2(isp, (ct2_entry_t *) local); 234ea49c6e4SMatt Jacob break; 23510365e5aSMatt Jacob 23610365e5aSMatt Jacob case RQSTYPE_CTIO7: 23710365e5aSMatt Jacob isp_get_ctio7(isp, ct7iop, (ct7_entry_t *) local); 23810365e5aSMatt Jacob isp_handle_ctio7(isp, (ct7_entry_t *) local); 23910365e5aSMatt Jacob break; 24010365e5aSMatt Jacob 241ea49c6e4SMatt Jacob case RQSTYPE_ENABLE_LUN: 242ea49c6e4SMatt Jacob case RQSTYPE_MODIFY_LUN: 2434fd13c1bSMatt Jacob isp_get_enable_lun(isp, lunenp, (lun_entry_t *) local); 2442df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_ACTION, local); 245ea49c6e4SMatt Jacob break; 246ea49c6e4SMatt Jacob 247ea49c6e4SMatt Jacob case RQSTYPE_NOTIFY: 24814a37293SMatt Jacob bus = 0; 24910365e5aSMatt Jacob if (IS_24XX(isp)) { 2502df76c16SMatt Jacob isp_get_notify_24xx(isp, inot_24xx, (in_fcentry_24xx_t *)local); 25110365e5aSMatt Jacob inot_24xx = (in_fcentry_24xx_t *) local; 2522df76c16SMatt Jacob isp_handle_24xx_inotify(isp, inot_24xx); 25310365e5aSMatt Jacob break; 25410365e5aSMatt Jacob } 2552df76c16SMatt Jacob if (IS_FC(isp)) { 2562df76c16SMatt Jacob if (ISP_CAP_2KLOGIN(isp)) { 2572df76c16SMatt Jacob in_fcentry_e_t *ecp = (in_fcentry_e_t *)local; 2582df76c16SMatt Jacob isp_get_notify_fc_e(isp, inote_fcp, ecp); 2592df76c16SMatt Jacob iid = ecp->in_iid; 2602df76c16SMatt Jacob status = ecp->in_status; 2612df76c16SMatt Jacob seqid = ecp->in_seqid; 26299ece8d6SMatt Jacob } else { 2632df76c16SMatt Jacob in_fcentry_t *fcp = (in_fcentry_t *)local; 2642df76c16SMatt Jacob isp_get_notify_fc(isp, inot_fcp, fcp); 2652df76c16SMatt Jacob iid = fcp->in_iid; 2662df76c16SMatt Jacob status = fcp->in_status; 2672df76c16SMatt Jacob seqid = fcp->in_seqid; 26899ece8d6SMatt Jacob } 269ea49c6e4SMatt Jacob } else { 2702df76c16SMatt Jacob in_entry_t *inp = (in_entry_t *)local; 2712df76c16SMatt Jacob isp_get_notify(isp, inotp, inp); 2722df76c16SMatt Jacob status = inp->in_status & 0xff; 2732df76c16SMatt Jacob seqid = inp->in_seqid; 2742df76c16SMatt Jacob iid = inp->in_iid; 27514a37293SMatt Jacob if (IS_DUALBUS(isp)) { 2762df76c16SMatt Jacob bus = GET_BUS_VAL(inp->in_iid); 2772df76c16SMatt Jacob SET_BUS_VAL(inp->in_iid, 0); 278ea49c6e4SMatt Jacob } 27914a37293SMatt Jacob } 280b4110d46SMatt Jacob 2812df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "Immediate Notify On Bus %d, status=0x%x seqid=0x%x", bus, status, seqid); 28223ac1fceSMatt Jacob 283ea49c6e4SMatt Jacob switch (status) { 284ea49c6e4SMatt Jacob case IN_MSG_RECEIVED: 285ea49c6e4SMatt Jacob case IN_IDE_RECEIVED: 286ea49c6e4SMatt Jacob if (IS_FC(isp)) { 287e5265237SMatt Jacob isp_got_msg_fc(isp, (in_fcentry_t *)local); 288ea49c6e4SMatt Jacob } else { 289e5265237SMatt Jacob isp_got_msg(isp, (in_entry_t *)local); 290ea49c6e4SMatt Jacob } 291ea49c6e4SMatt Jacob break; 292ea49c6e4SMatt Jacob case IN_RSRC_UNAVAIL: 29310365e5aSMatt Jacob isp_prt(isp, ISP_LOGINFO, "Firmware out of ATIOs"); 294387d8239SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, local); 295e5265237SMatt Jacob break; 29610365e5aSMatt Jacob 2972df76c16SMatt Jacob case IN_RESET: 2982df76c16SMatt Jacob ISP_MEMZERO(¬ify, sizeof (isp_notify_t)); 29910365e5aSMatt Jacob notify.nt_hba = isp; 3002df76c16SMatt Jacob notify.nt_wwn = INI_ANY; 3012df76c16SMatt Jacob notify.nt_tgt = TGT_ANY; 3022df76c16SMatt Jacob notify.nt_nphdl = iid; 3032df76c16SMatt Jacob notify.nt_sid = PORT_ANY; 3042df76c16SMatt Jacob notify.nt_did = PORT_ANY; 30510365e5aSMatt Jacob notify.nt_lun = LUN_ANY; 30610365e5aSMatt Jacob notify.nt_tagval = TAG_ANY; 3072df76c16SMatt Jacob notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32); 30810365e5aSMatt Jacob notify.nt_ncode = NT_BUS_RESET; 30910365e5aSMatt Jacob notify.nt_need_ack = 1; 3102df76c16SMatt Jacob notify.nt_lreserved = local; 3112df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 312ea49c6e4SMatt Jacob break; 3132df76c16SMatt Jacob 314ea49c6e4SMatt Jacob case IN_PORT_LOGOUT: 3152df76c16SMatt Jacob ISP_MEMZERO(¬ify, sizeof (isp_notify_t)); 3162df76c16SMatt Jacob notify.nt_hba = isp; 3172df76c16SMatt Jacob notify.nt_wwn = INI_ANY; 3182df76c16SMatt Jacob notify.nt_nphdl = iid; 3192df76c16SMatt Jacob notify.nt_sid = PORT_ANY; 3202df76c16SMatt Jacob notify.nt_did = PORT_ANY; 3212df76c16SMatt Jacob notify.nt_ncode = NT_LOGOUT; 3222df76c16SMatt Jacob notify.nt_need_ack = 1; 3232df76c16SMatt Jacob notify.nt_lreserved = local; 3242df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 325ea49c6e4SMatt Jacob break; 3262df76c16SMatt Jacob 3272df76c16SMatt Jacob case IN_ABORT_TASK: 3282df76c16SMatt Jacob ISP_MEMZERO(¬ify, sizeof (isp_notify_t)); 3292df76c16SMatt Jacob notify.nt_hba = isp; 3302df76c16SMatt Jacob notify.nt_wwn = INI_ANY; 3312df76c16SMatt Jacob notify.nt_nphdl = iid; 3322df76c16SMatt Jacob notify.nt_sid = PORT_ANY; 3332df76c16SMatt Jacob notify.nt_did = PORT_ANY; 3342df76c16SMatt Jacob notify.nt_ncode = NT_ABORT_TASK; 3352df76c16SMatt Jacob notify.nt_need_ack = 1; 3362df76c16SMatt Jacob notify.nt_lreserved = local; 3372df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 3382df76c16SMatt Jacob break; 3392df76c16SMatt Jacob 3402df76c16SMatt Jacob case IN_GLOBAL_LOGO: 3412df76c16SMatt Jacob isp_prt(isp, ISP_LOGTINFO, "%s: all ports logged out", __func__); 3422df76c16SMatt Jacob ISP_MEMZERO(¬ify, sizeof (isp_notify_t)); 3432df76c16SMatt Jacob notify.nt_hba = isp; 3442df76c16SMatt Jacob notify.nt_wwn = INI_ANY; 3452df76c16SMatt Jacob notify.nt_nphdl = NIL_HANDLE; 3462df76c16SMatt Jacob notify.nt_sid = PORT_ANY; 3472df76c16SMatt Jacob notify.nt_did = PORT_ANY; 3482df76c16SMatt Jacob notify.nt_ncode = NT_GLOBAL_LOGOUT; 349387d8239SMatt Jacob notify.nt_need_ack = 1; 350387d8239SMatt Jacob notify.nt_lreserved = local; 3512df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 3522df76c16SMatt Jacob break; 3532df76c16SMatt Jacob 3542df76c16SMatt Jacob case IN_PORT_CHANGED: 3552df76c16SMatt Jacob isp_prt(isp, ISP_LOGTINFO, "%s: port changed", __func__); 356387d8239SMatt Jacob ISP_MEMZERO(¬ify, sizeof (isp_notify_t)); 357387d8239SMatt Jacob notify.nt_hba = isp; 358387d8239SMatt Jacob notify.nt_wwn = INI_ANY; 359387d8239SMatt Jacob notify.nt_nphdl = NIL_HANDLE; 360387d8239SMatt Jacob notify.nt_sid = PORT_ANY; 361387d8239SMatt Jacob notify.nt_did = PORT_ANY; 362387d8239SMatt Jacob notify.nt_ncode = NT_CHANGED; 363387d8239SMatt Jacob notify.nt_need_ack = 1; 364387d8239SMatt Jacob notify.nt_lreserved = local; 365387d8239SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 3662df76c16SMatt Jacob break; 3672df76c16SMatt Jacob 368ea49c6e4SMatt Jacob default: 3692df76c16SMatt Jacob ISP_SNPRINTF(local, sizeof local, "%s: unknown status to RQSTYPE_NOTIFY (0x%x)", __func__, status); 3702df76c16SMatt Jacob isp_print_bytes(isp, local, QENTRY_LEN, vptr); 371387d8239SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, local); 372ea49c6e4SMatt Jacob break; 373ea49c6e4SMatt Jacob } 374ea49c6e4SMatt Jacob break; 375ea49c6e4SMatt Jacob 376ea49c6e4SMatt Jacob case RQSTYPE_NOTIFY_ACK: 377ea49c6e4SMatt Jacob /* 378ea49c6e4SMatt Jacob * The ISP is acknowledging our acknowledgement of an 379ea49c6e4SMatt Jacob * Immediate Notify entry for some asynchronous event. 380ea49c6e4SMatt Jacob */ 38110365e5aSMatt Jacob if (IS_24XX(isp)) { 3822df76c16SMatt Jacob isp_get_notify_ack_24xx(isp, nack_24xx, (na_fcentry_24xx_t *) local); 38310365e5aSMatt Jacob nack_24xx = (na_fcentry_24xx_t *) local; 38410365e5aSMatt Jacob if (nack_24xx->na_status != NA_OK) { 38510365e5aSMatt Jacob level = ISP_LOGINFO; 38610365e5aSMatt Jacob } else { 38710365e5aSMatt Jacob level = ISP_LOGTDEBUG1; 38810365e5aSMatt Jacob } 3892df76c16SMatt Jacob isp_prt(isp, level, "Notify Ack Status=0x%x; Subcode 0x%x seqid=0x%x", nack_24xx->na_status, nack_24xx->na_status_subcode, nack_24xx->na_rxid); 39010365e5aSMatt Jacob } else if (IS_FC(isp)) { 3912df76c16SMatt Jacob if (ISP_CAP_2KLOGIN(isp)) { 3922df76c16SMatt Jacob isp_get_notify_ack_fc_e(isp, nacke_fcp, (na_fcentry_e_t *)local); 39399ece8d6SMatt Jacob } else { 3942df76c16SMatt Jacob isp_get_notify_ack_fc(isp, nack_fcp, (na_fcentry_t *)local); 39599ece8d6SMatt Jacob } 3964fd13c1bSMatt Jacob nack_fcp = (na_fcentry_t *)local; 39710365e5aSMatt Jacob if (nack_fcp->na_status != NA_OK) { 39810365e5aSMatt Jacob level = ISP_LOGINFO; 39910365e5aSMatt Jacob } else { 40010365e5aSMatt Jacob level = ISP_LOGTDEBUG1; 40110365e5aSMatt Jacob } 4022df76c16SMatt Jacob isp_prt(isp, level, "Notify Ack Status=0x%x seqid 0x%x", nack_fcp->na_status, nack_fcp->na_seqid); 403ea49c6e4SMatt Jacob } else { 4044fd13c1bSMatt Jacob isp_get_notify_ack(isp, nackp, (na_entry_t *)local); 4054fd13c1bSMatt Jacob nackp = (na_entry_t *)local; 40610365e5aSMatt Jacob if (nackp->na_status != NA_OK) { 40710365e5aSMatt Jacob level = ISP_LOGINFO; 40810365e5aSMatt Jacob } else { 40910365e5aSMatt Jacob level = ISP_LOGTDEBUG1; 41010365e5aSMatt Jacob } 4112df76c16SMatt Jacob isp_prt(isp, level, "Notify Ack event 0x%x status=0x%x seqid 0x%x", nackp->na_event, nackp->na_status, nackp->na_seqid); 412ea49c6e4SMatt Jacob } 413ea49c6e4SMatt Jacob break; 41410365e5aSMatt Jacob 41510365e5aSMatt Jacob case RQSTYPE_ABTS_RCVD: 41610365e5aSMatt Jacob isp_get_abts(isp, abts, (abts_t *)local); 4172df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_ACTION, &local); 41810365e5aSMatt Jacob break; 41910365e5aSMatt Jacob case RQSTYPE_ABTS_RSP: 42010365e5aSMatt Jacob isp_get_abts_rsp(isp, abts_rsp, (abts_rsp_t *)local); 42110365e5aSMatt Jacob abts_rsp = (abts_rsp_t *) local; 42210365e5aSMatt Jacob if (abts_rsp->abts_rsp_status) { 42310365e5aSMatt Jacob level = ISP_LOGINFO; 42410365e5aSMatt Jacob } else { 42510365e5aSMatt Jacob level = ISP_LOGTDEBUG0; 42610365e5aSMatt Jacob } 4272df76c16SMatt Jacob isp_prt(isp, level, "ABTS RSP response[0x%x]: status=0x%x sub=(0x%x 0x%x)", abts_rsp->abts_rsp_rxid_task, abts_rsp->abts_rsp_status, 4282df76c16SMatt Jacob abts_rsp->abts_rsp_payload.rsp.subcode1, abts_rsp->abts_rsp_payload.rsp.subcode2); 42910365e5aSMatt Jacob break; 430ea49c6e4SMatt Jacob default: 4312df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "%s: unknown entry type 0x%x", __func__, type); 432e63442b6SMatt Jacob rval = 0; 433ea49c6e4SMatt Jacob break; 434ea49c6e4SMatt Jacob } 435ea49c6e4SMatt Jacob #undef atiop 436ea49c6e4SMatt Jacob #undef at2iop 437e5265237SMatt Jacob #undef at2eiop 43810365e5aSMatt Jacob #undef at7iop 439ea49c6e4SMatt Jacob #undef ctiop 440ea49c6e4SMatt Jacob #undef ct2iop 441e5265237SMatt Jacob #undef ct2eiop 44210365e5aSMatt Jacob #undef ct7iop 443ea49c6e4SMatt Jacob #undef lunenp 444ea49c6e4SMatt Jacob #undef inotp 445ea49c6e4SMatt Jacob #undef inot_fcp 446e5265237SMatt Jacob #undef inote_fcp 44710365e5aSMatt Jacob #undef inot_24xx 448ea49c6e4SMatt Jacob #undef nackp 449ea49c6e4SMatt Jacob #undef nack_fcp 450e5265237SMatt Jacob #undef nacke_fcp 45110365e5aSMatt Jacob #undef hack_24xx 45210365e5aSMatt Jacob #undef abts 45310365e5aSMatt Jacob #undef abts_rsp 45410365e5aSMatt Jacob #undef els 455ea49c6e4SMatt Jacob #undef hdrp 456ea49c6e4SMatt Jacob return (rval); 457ea49c6e4SMatt Jacob } 458ea49c6e4SMatt Jacob 459ea49c6e4SMatt Jacob 460ea49c6e4SMatt Jacob /* 4612df76c16SMatt Jacob * Toggle (on/off) target mode for bus/target/lun. 462ea49c6e4SMatt Jacob * 463ea49c6e4SMatt Jacob * The caller has checked for overlap and legality. 464ea49c6e4SMatt Jacob * 465ea49c6e4SMatt Jacob * Note that not all of bus, target or lun can be paid attention to. 466ea49c6e4SMatt Jacob * Note also that this action will not be complete until the f/w writes 4672df76c16SMatt Jacob * a response entry. The caller is responsible for synchronizing with this. 468ea49c6e4SMatt Jacob */ 469ea49c6e4SMatt Jacob int 4702df76c16SMatt Jacob isp_lun_cmd(ispsoftc_t *isp, int cmd, int bus, int lun, int cmd_cnt, int inot_cnt) 471ea49c6e4SMatt Jacob { 472ea49c6e4SMatt Jacob lun_entry_t el; 473ea49c6e4SMatt Jacob void *outp; 474ea49c6e4SMatt Jacob 4752df76c16SMatt Jacob ISP_MEMZERO(&el, sizeof (el)); 47614a37293SMatt Jacob if (IS_DUALBUS(isp)) { 47714a37293SMatt Jacob el.le_rsvd = (bus & 0x1) << 7; 47814a37293SMatt Jacob } 479387d8239SMatt Jacob el.le_cmd_count = (cmd_cnt < 0)? -cmd_cnt : cmd_cnt; 480387d8239SMatt Jacob el.le_in_count = (inot_cnt < 0)? -inot_cnt : inot_cnt; 481ea49c6e4SMatt Jacob if (cmd == RQSTYPE_ENABLE_LUN) { 482ea49c6e4SMatt Jacob if (IS_SCSI(isp)) { 4832133e16fSMatt Jacob el.le_flags = LUN_TQAE|LUN_DISAD; 484ea49c6e4SMatt Jacob el.le_cdb6len = 12; 485ea49c6e4SMatt Jacob el.le_cdb7len = 12; 486ea49c6e4SMatt Jacob } 487387d8239SMatt Jacob } else if (cmd == RQSTYPE_MODIFY_LUN) { 488387d8239SMatt Jacob if (cmd_cnt == 0 && inot_cnt == 0) { 489387d8239SMatt Jacob isp_prt(isp, ISP_LOGWARN, "makes no sense to modify a lun with both command and immediate notify counts as zero"); 490387d8239SMatt Jacob return (0); 491387d8239SMatt Jacob } 492387d8239SMatt Jacob if (cmd_cnt < 0) 493387d8239SMatt Jacob el.le_ops |= LUN_CCDECR; 494387d8239SMatt Jacob else 495387d8239SMatt Jacob el.le_ops |= LUN_CCINCR; 496387d8239SMatt Jacob if (inot_cnt < 0) 497387d8239SMatt Jacob el.le_ops |= LUN_INDECR; 498387d8239SMatt Jacob else 499387d8239SMatt Jacob el.le_ops |= LUN_ININCR; 500ea49c6e4SMatt Jacob } else { 501387d8239SMatt Jacob isp_prt(isp, ISP_LOGWARN, "unknown cmd (0x%x) in %s", cmd, __func__); 502387d8239SMatt Jacob return (-1); 503ea49c6e4SMatt Jacob } 504ea49c6e4SMatt Jacob el.le_header.rqs_entry_type = cmd; 505ea49c6e4SMatt Jacob el.le_header.rqs_entry_count = 1; 506ea49c6e4SMatt Jacob if (IS_SCSI(isp)) { 5072df76c16SMatt Jacob el.le_tgt = SDPARAM(isp, bus)->isp_initiator_id; 508ea49c6e4SMatt Jacob el.le_lun = lun; 5092df76c16SMatt Jacob } else if (ISP_CAP_SCCFW(isp) == 0) { 510ea49c6e4SMatt Jacob el.le_lun = lun; 511ea49c6e4SMatt Jacob } 512351c7054SMatt Jacob el.le_timeout = 30; 513ea49c6e4SMatt Jacob 5142df76c16SMatt Jacob outp = isp_getrqentry(isp); 5152df76c16SMatt Jacob if (outp == NULL) { 5162df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, rqo, __func__); 517ea49c6e4SMatt Jacob return (-1); 518ea49c6e4SMatt Jacob } 5194fd13c1bSMatt Jacob isp_put_enable_lun(isp, &el, outp); 5202df76c16SMatt Jacob ISP_TDQE(isp, "isp_lun_cmd", isp->isp_reqidx, &el); 5212df76c16SMatt Jacob ISP_SYNC_REQUEST(isp); 522ea49c6e4SMatt Jacob return (0); 523ea49c6e4SMatt Jacob } 524ea49c6e4SMatt Jacob 525ea49c6e4SMatt Jacob int 5269cd7268eSMatt Jacob isp_target_put_entry(ispsoftc_t *isp, void *ap) 527ea49c6e4SMatt Jacob { 528ea49c6e4SMatt Jacob void *outp; 5291dae40ebSMatt Jacob uint8_t etype = ((isphdr_t *) ap)->rqs_entry_type; 530ea49c6e4SMatt Jacob 5312df76c16SMatt Jacob outp = isp_getrqentry(isp); 5322df76c16SMatt Jacob if (outp == NULL) { 5332df76c16SMatt Jacob isp_prt(isp, ISP_LOGWARN, rqo, __func__); 534ea49c6e4SMatt Jacob return (-1); 535ea49c6e4SMatt Jacob } 536ea49c6e4SMatt Jacob switch (etype) { 537ea49c6e4SMatt Jacob case RQSTYPE_ATIO: 5384fd13c1bSMatt Jacob isp_put_atio(isp, (at_entry_t *) ap, (at_entry_t *) outp); 539ea49c6e4SMatt Jacob break; 540ea49c6e4SMatt Jacob case RQSTYPE_ATIO2: 5412df76c16SMatt Jacob if (ISP_CAP_2KLOGIN(isp)) { 5422df76c16SMatt Jacob isp_put_atio2e(isp, (at2e_entry_t *) ap, (at2e_entry_t *) outp); 54399ece8d6SMatt Jacob } else { 5442df76c16SMatt Jacob isp_put_atio2(isp, (at2_entry_t *) ap, (at2_entry_t *) outp); 54599ece8d6SMatt Jacob } 546ea49c6e4SMatt Jacob break; 547ea49c6e4SMatt Jacob case RQSTYPE_CTIO: 5484fd13c1bSMatt Jacob isp_put_ctio(isp, (ct_entry_t *) ap, (ct_entry_t *) outp); 549ea49c6e4SMatt Jacob break; 550ea49c6e4SMatt Jacob case RQSTYPE_CTIO2: 5512df76c16SMatt Jacob if (ISP_CAP_2KLOGIN(isp)) { 5522df76c16SMatt Jacob isp_put_ctio2e(isp, (ct2e_entry_t *) ap, (ct2e_entry_t *) outp); 55399ece8d6SMatt Jacob } else { 5542df76c16SMatt Jacob isp_put_ctio2(isp, (ct2_entry_t *) ap, (ct2_entry_t *) outp); 55599ece8d6SMatt Jacob } 556ea49c6e4SMatt Jacob break; 55710365e5aSMatt Jacob case RQSTYPE_CTIO7: 55810365e5aSMatt Jacob isp_put_ctio7(isp, (ct7_entry_t *) ap, (ct7_entry_t *) outp); 55910365e5aSMatt Jacob break; 560ea49c6e4SMatt Jacob default: 5612df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "%s: Unknown type 0x%x", __func__, etype); 562ea49c6e4SMatt Jacob return (-1); 563ea49c6e4SMatt Jacob } 5642df76c16SMatt Jacob ISP_TDQE(isp, __func__, isp->isp_reqidx, ap); 5652df76c16SMatt Jacob ISP_SYNC_REQUEST(isp); 566ea49c6e4SMatt Jacob return (0); 567ea49c6e4SMatt Jacob } 568ea49c6e4SMatt Jacob 569ea49c6e4SMatt Jacob int 5709cd7268eSMatt Jacob isp_target_put_atio(ispsoftc_t *isp, void *arg) 571ea49c6e4SMatt Jacob { 572ea49c6e4SMatt Jacob union { 573ea49c6e4SMatt Jacob at_entry_t _atio; 574ea49c6e4SMatt Jacob at2_entry_t _atio2; 575e5265237SMatt Jacob at2e_entry_t _atio2e; 576ea49c6e4SMatt Jacob } atun; 577ea49c6e4SMatt Jacob 5782df76c16SMatt Jacob ISP_MEMZERO(&atun, sizeof atun); 579ea49c6e4SMatt Jacob if (IS_FC(isp)) { 580b25bcef8SMatt Jacob at2_entry_t *aep = arg; 581ea49c6e4SMatt Jacob atun._atio2.at_header.rqs_entry_type = RQSTYPE_ATIO2; 582ea49c6e4SMatt Jacob atun._atio2.at_header.rqs_entry_count = 1; 5832df76c16SMatt Jacob if (ISP_CAP_SCCFW(isp)) { 58410365e5aSMatt Jacob atun._atio2.at_scclun = aep->at_scclun; 5852133e16fSMatt Jacob } else { 5861dae40ebSMatt Jacob atun._atio2.at_lun = (uint8_t) aep->at_lun; 5872133e16fSMatt Jacob } 5882df76c16SMatt Jacob if (ISP_CAP_2KLOGIN(isp)) { 589e5265237SMatt Jacob atun._atio2e.at_iid = ((at2e_entry_t *)aep)->at_iid; 590e5265237SMatt Jacob } else { 59103cf2fbaSMatt Jacob atun._atio2.at_iid = aep->at_iid; 592e5265237SMatt Jacob } 593e5824c5dSMatt Jacob atun._atio2.at_rxid = aep->at_rxid; 594ea49c6e4SMatt Jacob atun._atio2.at_status = CT_OK; 595ea49c6e4SMatt Jacob } else { 596b25bcef8SMatt Jacob at_entry_t *aep = arg; 597ea49c6e4SMatt Jacob atun._atio.at_header.rqs_entry_type = RQSTYPE_ATIO; 598ea49c6e4SMatt Jacob atun._atio.at_header.rqs_entry_count = 1; 599b25bcef8SMatt Jacob atun._atio.at_handle = aep->at_handle; 600b25bcef8SMatt Jacob atun._atio.at_iid = aep->at_iid; 601b25bcef8SMatt Jacob atun._atio.at_tgt = aep->at_tgt; 602b25bcef8SMatt Jacob atun._atio.at_lun = aep->at_lun; 603b25bcef8SMatt Jacob atun._atio.at_tag_type = aep->at_tag_type; 604b25bcef8SMatt Jacob atun._atio.at_tag_val = aep->at_tag_val; 605b25bcef8SMatt Jacob atun._atio.at_status = (aep->at_flags & AT_TQAE); 606b25bcef8SMatt Jacob atun._atio.at_status |= CT_OK; 607ea49c6e4SMatt Jacob } 608ea49c6e4SMatt Jacob return (isp_target_put_entry(isp, &atun)); 609ea49c6e4SMatt Jacob } 610ea49c6e4SMatt Jacob 611ea49c6e4SMatt Jacob /* 612ea49c6e4SMatt Jacob * Command completion- both for handling cases of no resources or 613ea49c6e4SMatt Jacob * no blackhole driver, or other cases where we have to, inline, 614ea49c6e4SMatt Jacob * finish the command sanely, or for normal command completion. 615ea49c6e4SMatt Jacob * 616ea49c6e4SMatt Jacob * The 'completion' code value has the scsi status byte in the low 8 bits. 617ea49c6e4SMatt Jacob * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have 618ea49c6e4SMatt Jacob * the sense key and bits 16..23 have the ASCQ and bits 24..31 have the ASC 619ea49c6e4SMatt Jacob * values. 620ea49c6e4SMatt Jacob * 621ea49c6e4SMatt Jacob * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't 622b25bcef8SMatt Jacob * NB: inline SCSI sense reporting. As such, we lose this information. XXX. 623ea49c6e4SMatt Jacob * 624ea49c6e4SMatt Jacob * For both parallel && fibre channel, we use the feature that does 625ea49c6e4SMatt Jacob * an automatic resource autoreplenish so we don't have then later do 626ea49c6e4SMatt Jacob * put of an atio to replenish the f/w's resource count. 627ea49c6e4SMatt Jacob */ 628ea49c6e4SMatt Jacob 629ea49c6e4SMatt Jacob int 6302df76c16SMatt Jacob isp_endcmd(ispsoftc_t *isp, ...) 631ea49c6e4SMatt Jacob { 6322df76c16SMatt Jacob uint32_t code, hdl; 6332df76c16SMatt Jacob uint8_t sts; 634ea49c6e4SMatt Jacob union { 635ea49c6e4SMatt Jacob ct_entry_t _ctio; 636ea49c6e4SMatt Jacob ct2_entry_t _ctio2; 637e5265237SMatt Jacob ct2e_entry_t _ctio2e; 63810365e5aSMatt Jacob ct7_entry_t _ctio7; 639ea49c6e4SMatt Jacob } un; 6402df76c16SMatt Jacob va_list ap; 641ea49c6e4SMatt Jacob 6422df76c16SMatt Jacob ISP_MEMZERO(&un, sizeof un); 643ea49c6e4SMatt Jacob 64410365e5aSMatt Jacob if (IS_24XX(isp)) { 6452df76c16SMatt Jacob int vpidx, nphdl; 6462df76c16SMatt Jacob at7_entry_t *aep; 64710365e5aSMatt Jacob ct7_entry_t *cto = &un._ctio7; 64810365e5aSMatt Jacob 6492df76c16SMatt Jacob va_start(ap, isp); 6502df76c16SMatt Jacob aep = va_arg(ap, at7_entry_t *); 6512df76c16SMatt Jacob nphdl = va_arg(ap, int); 6522df76c16SMatt Jacob /* 6532df76c16SMatt Jacob * Note that vpidx may equal 0xff (unknown) here 6542df76c16SMatt Jacob */ 6552df76c16SMatt Jacob vpidx = va_arg(ap, int); 6562df76c16SMatt Jacob code = va_arg(ap, uint32_t); 6572df76c16SMatt Jacob hdl = va_arg(ap, uint32_t); 6582df76c16SMatt Jacob va_end(ap); 6592df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "%s: [RX_ID 0x%x] chan %d code %x", __func__, aep->at_rxid, vpidx, code); 6602df76c16SMatt Jacob 6612df76c16SMatt Jacob sts = code & 0xff; 66210365e5aSMatt Jacob cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7; 66310365e5aSMatt Jacob cto->ct_header.rqs_entry_count = 1; 6642df76c16SMatt Jacob cto->ct_nphdl = nphdl; 66510365e5aSMatt Jacob cto->ct_rxid = aep->at_rxid; 6662df76c16SMatt Jacob cto->ct_iid_lo = (aep->at_hdr.s_id[1] << 8) | aep->at_hdr.s_id[2]; 66710365e5aSMatt Jacob cto->ct_iid_hi = aep->at_hdr.s_id[0]; 66810365e5aSMatt Jacob cto->ct_oxid = aep->at_hdr.ox_id; 66910365e5aSMatt Jacob cto->ct_scsi_status = sts; 6702df76c16SMatt Jacob cto->ct_vpidx = vpidx; 6712df76c16SMatt Jacob cto->ct_flags = CT7_NOACK; 6722df76c16SMatt Jacob if (code & ECMD_TERMINATE) { 6732df76c16SMatt Jacob cto->ct_flags |= CT7_TERMINATE; 6742df76c16SMatt Jacob } else if (code & ECMD_SVALID) { 6752df76c16SMatt Jacob cto->ct_flags |= CT7_FLAG_MODE1 | CT7_SENDSTATUS; 6762df76c16SMatt Jacob cto->ct_scsi_status |= (FCP_SNSLEN_VALID << 8); 6772df76c16SMatt Jacob cto->rsp.m1.ct_resplen = cto->ct_senselen = min(16, MAXRESPLEN_24XX); 6782df76c16SMatt Jacob ISP_MEMZERO(cto->rsp.m1.ct_resp, sizeof (cto->rsp.m1.ct_resp)); 67910365e5aSMatt Jacob cto->rsp.m1.ct_resp[0] = 0xf0; 68010365e5aSMatt Jacob cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf; 68110365e5aSMatt Jacob cto->rsp.m1.ct_resp[7] = 8; 682387d8239SMatt Jacob cto->rsp.m1.ct_resp[12] = (code >> 16) & 0xff; 683387d8239SMatt Jacob cto->rsp.m1.ct_resp[13] = (code >> 24) & 0xff; 6842df76c16SMatt Jacob } else { 6852df76c16SMatt Jacob cto->ct_flags |= CT7_FLAG_MODE1 | CT7_SENDSTATUS; 68610365e5aSMatt Jacob } 68710365e5aSMatt Jacob if (aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl) { 68810365e5aSMatt Jacob cto->ct_resid = aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl; 6892df76c16SMatt Jacob if (cto->ct_resid < 0) { 6902df76c16SMatt Jacob cto->ct_scsi_status |= (FCP_RESID_OVERFLOW << 8); 6912df76c16SMatt Jacob } else if (cto->ct_resid > 0) { 6922df76c16SMatt Jacob cto->ct_scsi_status |= (FCP_RESID_UNDERFLOW << 8); 6932df76c16SMatt Jacob } 69410365e5aSMatt Jacob } 69510365e5aSMatt Jacob cto->ct_syshandle = hdl; 69610365e5aSMatt Jacob } else if (IS_FC(isp)) { 6972df76c16SMatt Jacob at2_entry_t *aep; 698ea49c6e4SMatt Jacob ct2_entry_t *cto = &un._ctio2; 699ea49c6e4SMatt Jacob 7002df76c16SMatt Jacob va_start(ap, isp); 7012df76c16SMatt Jacob aep = va_arg(ap, at2_entry_t *); 7022df76c16SMatt Jacob code = va_arg(ap, uint32_t); 7032df76c16SMatt Jacob hdl = va_arg(ap, uint32_t); 7042df76c16SMatt Jacob va_end(ap); 7052df76c16SMatt Jacob 7062df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "%s: [RX_ID 0x%x] code %x", __func__, aep->at_rxid, code); 7072df76c16SMatt Jacob 7082df76c16SMatt Jacob sts = code & 0xff; 709ea49c6e4SMatt Jacob cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2; 710ea49c6e4SMatt Jacob cto->ct_header.rqs_entry_count = 1; 7112df76c16SMatt Jacob if (ISP_CAP_SCCFW(isp) == 0) { 712ea49c6e4SMatt Jacob cto->ct_lun = aep->at_lun; 7132133e16fSMatt Jacob } 7142df76c16SMatt Jacob if (ISP_CAP_2KLOGIN(isp)) { 715e5265237SMatt Jacob un._ctio2e.ct_iid = ((at2e_entry_t *)aep)->at_iid; 716e5265237SMatt Jacob } else { 717e5265237SMatt Jacob cto->ct_iid = aep->at_iid; 718e5265237SMatt Jacob } 719ea49c6e4SMatt Jacob cto->ct_rxid = aep->at_rxid; 720eedb2dfeSMatt Jacob cto->rsp.m1.ct_scsi_status = sts; 721ea49c6e4SMatt Jacob cto->ct_flags = CT2_SENDSTATUS | CT2_NO_DATA | CT2_FLAG_MODE1; 722ea49c6e4SMatt Jacob if (hdl == 0) { 723ea49c6e4SMatt Jacob cto->ct_flags |= CT2_CCINCR; 724ea49c6e4SMatt Jacob } 725ea49c6e4SMatt Jacob if (aep->at_datalen) { 726ea49c6e4SMatt Jacob cto->ct_resid = aep->at_datalen; 7275d571944SMatt Jacob cto->rsp.m1.ct_scsi_status |= CT2_DATA_UNDER; 728ea49c6e4SMatt Jacob } 729eedb2dfeSMatt Jacob if (sts == SCSI_CHECK && (code & ECMD_SVALID)) { 730ea49c6e4SMatt Jacob cto->rsp.m1.ct_resp[0] = 0xf0; 731ea49c6e4SMatt Jacob cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf; 732ea49c6e4SMatt Jacob cto->rsp.m1.ct_resp[7] = 8; 733ea49c6e4SMatt Jacob cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff; 734ea49c6e4SMatt Jacob cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff; 735ea49c6e4SMatt Jacob cto->rsp.m1.ct_senselen = 16; 7365d571944SMatt Jacob cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID; 737ea49c6e4SMatt Jacob } 738b0bd9b71SMatt Jacob cto->ct_syshandle = hdl; 739ea49c6e4SMatt Jacob } else { 7402df76c16SMatt Jacob at_entry_t *aep; 741ea49c6e4SMatt Jacob ct_entry_t *cto = &un._ctio; 742ea49c6e4SMatt Jacob 7432df76c16SMatt Jacob va_start(ap, isp); 7442df76c16SMatt Jacob aep = va_arg(ap, at_entry_t *); 7452df76c16SMatt Jacob code = va_arg(ap, uint32_t); 7462df76c16SMatt Jacob hdl = va_arg(ap, uint32_t); 7472df76c16SMatt Jacob va_end(ap); 7482df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "%s: [IID %d] code %x", __func__, aep->at_iid, code); 7492df76c16SMatt Jacob sts = code; 7502df76c16SMatt Jacob 751ea49c6e4SMatt Jacob cto->ct_header.rqs_entry_type = RQSTYPE_CTIO; 752ea49c6e4SMatt Jacob cto->ct_header.rqs_entry_count = 1; 7535f5aafe1SMatt Jacob cto->ct_fwhandle = aep->at_handle; 754ea49c6e4SMatt Jacob cto->ct_iid = aep->at_iid; 755ea49c6e4SMatt Jacob cto->ct_tgt = aep->at_tgt; 756ea49c6e4SMatt Jacob cto->ct_lun = aep->at_lun; 757ea49c6e4SMatt Jacob cto->ct_tag_type = aep->at_tag_type; 758ea49c6e4SMatt Jacob cto->ct_tag_val = aep->at_tag_val; 759b25bcef8SMatt Jacob if (aep->at_flags & AT_TQAE) { 760b25bcef8SMatt Jacob cto->ct_flags |= CT_TQAE; 761b25bcef8SMatt Jacob } 762ea49c6e4SMatt Jacob cto->ct_flags = CT_SENDSTATUS | CT_NO_DATA; 763ea49c6e4SMatt Jacob if (hdl == 0) { 764ea49c6e4SMatt Jacob cto->ct_flags |= CT_CCINCR; 765ea49c6e4SMatt Jacob } 766ea49c6e4SMatt Jacob cto->ct_scsi_status = sts; 767b0bd9b71SMatt Jacob cto->ct_syshandle = hdl; 768ea49c6e4SMatt Jacob } 769ea49c6e4SMatt Jacob return (isp_target_put_entry(isp, &un)); 770ea49c6e4SMatt Jacob } 771ea49c6e4SMatt Jacob 7729cd7268eSMatt Jacob /* 7739cd7268eSMatt Jacob * These are either broadcast events or specifically CTIO fast completion 7749cd7268eSMatt Jacob */ 7752df76c16SMatt Jacob 776e63442b6SMatt Jacob int 7779cd7268eSMatt Jacob isp_target_async(ispsoftc_t *isp, int bus, int event) 778ea49c6e4SMatt Jacob { 7792df76c16SMatt Jacob isp_notify_t notify; 780e5265237SMatt Jacob 7812df76c16SMatt Jacob ISP_MEMZERO(¬ify, sizeof (isp_notify_t)); 782e5265237SMatt Jacob notify.nt_hba = isp; 7832df76c16SMatt Jacob notify.nt_wwn = INI_ANY; 7842df76c16SMatt Jacob notify.nt_nphdl = NIL_HANDLE; 7852df76c16SMatt Jacob notify.nt_sid = PORT_ANY; 7862df76c16SMatt Jacob notify.nt_did = PORT_ANY; 7872df76c16SMatt Jacob notify.nt_tgt = TGT_ANY; 7882df76c16SMatt Jacob notify.nt_channel = bus; 789e5265237SMatt Jacob notify.nt_lun = LUN_ANY; 790e5265237SMatt Jacob notify.nt_tagval = TAG_ANY; 7912df76c16SMatt Jacob notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32); 792ea49c6e4SMatt Jacob 793ea49c6e4SMatt Jacob switch (event) { 794e5265237SMatt Jacob case ASYNC_LOOP_UP: 795e5265237SMatt Jacob case ASYNC_PTPMODE: 7962df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "%s: LOOP UP", __func__); 797e5265237SMatt Jacob notify.nt_ncode = NT_LINK_UP; 7982df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 799e5265237SMatt Jacob break; 800e5265237SMatt Jacob case ASYNC_LOOP_DOWN: 8012df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "%s: LOOP DOWN", __func__); 802e5265237SMatt Jacob notify.nt_ncode = NT_LINK_DOWN; 8032df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 804e5265237SMatt Jacob break; 80510365e5aSMatt Jacob case ASYNC_LIP_ERROR: 80623ac1fceSMatt Jacob case ASYNC_LIP_F8: 807ea49c6e4SMatt Jacob case ASYNC_LIP_OCCURRED: 80823ac1fceSMatt Jacob case ASYNC_LOOP_RESET: 8092df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "%s: LIP RESET", __func__); 810e5265237SMatt Jacob notify.nt_ncode = NT_LIP_RESET; 8112df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 812e5265237SMatt Jacob break; 813ea49c6e4SMatt Jacob case ASYNC_BUS_RESET: 814e5265237SMatt Jacob case ASYNC_TIMEOUT_RESET: /* XXX: where does this come from ? */ 8152df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "%s: BUS RESET", __func__); 816e5265237SMatt Jacob notify.nt_ncode = NT_BUS_RESET; 8172df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 818ea49c6e4SMatt Jacob break; 819ea49c6e4SMatt Jacob case ASYNC_DEVICE_RESET: 8202df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "%s: DEVICE RESET", __func__); 821e5265237SMatt Jacob notify.nt_ncode = NT_TARGET_RESET; 8222df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 823ea49c6e4SMatt Jacob break; 8242f9e7606SMatt Jacob case ASYNC_CTIO_DONE: 825e5265237SMatt Jacob { 826e5265237SMatt Jacob uint8_t storage[QENTRY_LEN]; 8272df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "%s: CTIO DONE", __func__); 828e5265237SMatt Jacob memset(storage, 0, QENTRY_LEN); 82910365e5aSMatt Jacob if (IS_24XX(isp)) { 83010365e5aSMatt Jacob ct7_entry_t *ct = (ct7_entry_t *) storage; 83110365e5aSMatt Jacob ct->ct_header.rqs_entry_type = RQSTYPE_CTIO7; 83210365e5aSMatt Jacob ct->ct_nphdl = CT7_OK; 83310365e5aSMatt Jacob ct->ct_syshandle = bus; 8342df76c16SMatt Jacob ct->ct_flags = CT7_SENDSTATUS; 83510365e5aSMatt Jacob } else if (IS_FC(isp)) { 83699ece8d6SMatt Jacob /* This should also suffice for 2K login code */ 837e5265237SMatt Jacob ct2_entry_t *ct = (ct2_entry_t *) storage; 838e5265237SMatt Jacob ct->ct_header.rqs_entry_type = RQSTYPE_CTIO2; 839e5265237SMatt Jacob ct->ct_status = CT_OK; 840e5265237SMatt Jacob ct->ct_syshandle = bus; 841e5265237SMatt Jacob ct->ct_flags = CT2_SENDSTATUS|CT2_FASTPOST; 842e5265237SMatt Jacob } else { 843e5265237SMatt Jacob ct_entry_t *ct = (ct_entry_t *) storage; 844e5265237SMatt Jacob ct->ct_header.rqs_entry_type = RQSTYPE_CTIO; 845e5265237SMatt Jacob ct->ct_status = CT_OK; 846443e752dSMatt Jacob ct->ct_syshandle = bus; 847443e752dSMatt Jacob /* we skip fwhandle here */ 848443e752dSMatt Jacob ct->ct_fwhandle = 0; 849e5265237SMatt Jacob ct->ct_flags = CT_SENDSTATUS; 850e5265237SMatt Jacob } 8512df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_ACTION, storage); 85210365e5aSMatt Jacob break; 853e5265237SMatt Jacob } 854ea49c6e4SMatt Jacob default: 8552df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "%s: unknown event 0x%x", __func__, event); 856e5265237SMatt Jacob if (isp->isp_state == ISP_RUNSTATE) { 857387d8239SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, NULL); 858e5265237SMatt Jacob } 859ea49c6e4SMatt Jacob break; 860ea49c6e4SMatt Jacob } 861e63442b6SMatt Jacob return (0); 862ea49c6e4SMatt Jacob } 863ea49c6e4SMatt Jacob 864ea49c6e4SMatt Jacob 865ea49c6e4SMatt Jacob /* 866ea49c6e4SMatt Jacob * Process a received message. 867ea49c6e4SMatt Jacob * The ISP firmware can handle most messages, there are only 868ea49c6e4SMatt Jacob * a few that we need to deal with: 869ea49c6e4SMatt Jacob * - abort: clean up the current command 870ea49c6e4SMatt Jacob * - abort tag and clear queue 871ea49c6e4SMatt Jacob */ 872ea49c6e4SMatt Jacob 873ea49c6e4SMatt Jacob static void 8749cd7268eSMatt Jacob isp_got_msg(ispsoftc_t *isp, in_entry_t *inp) 875ea49c6e4SMatt Jacob { 8762df76c16SMatt Jacob isp_notify_t notify; 8771dae40ebSMatt Jacob uint8_t status = inp->in_status & ~QLTM_SVALID; 878ea49c6e4SMatt Jacob 8792df76c16SMatt Jacob ISP_MEMZERO(¬ify, sizeof (notify)); 8802df76c16SMatt Jacob notify.nt_hba = isp; 8812df76c16SMatt Jacob notify.nt_wwn = INI_ANY; 8822df76c16SMatt Jacob notify.nt_nphdl = GET_IID_VAL(inp->in_iid); 8832df76c16SMatt Jacob notify.nt_sid = PORT_ANY; 8842df76c16SMatt Jacob notify.nt_did = PORT_ANY; 8852df76c16SMatt Jacob notify.nt_channel = GET_BUS_VAL(inp->in_iid); 8862df76c16SMatt Jacob notify.nt_tgt = inp->in_tgt; 8872df76c16SMatt Jacob notify.nt_lun = inp->in_lun; 8882df76c16SMatt Jacob IN_MAKE_TAGID(notify.nt_tagval, inp); 8892df76c16SMatt Jacob notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32); 8902df76c16SMatt Jacob notify.nt_lreserved = inp; 891ea49c6e4SMatt Jacob 892e5265237SMatt Jacob if (status == IN_IDE_RECEIVED || status == IN_MSG_RECEIVED) { 893e5265237SMatt Jacob switch (inp->in_msg[0]) { 894e5265237SMatt Jacob case MSG_ABORT: 8952df76c16SMatt Jacob notify.nt_ncode = NT_ABORT_TASK_SET; 896e5265237SMatt Jacob break; 897e5265237SMatt Jacob case MSG_BUS_DEV_RESET: 8982df76c16SMatt Jacob notify.nt_ncode = NT_TARGET_RESET; 899e5265237SMatt Jacob break; 900e5265237SMatt Jacob case MSG_ABORT_TAG: 9012df76c16SMatt Jacob notify.nt_ncode = NT_ABORT_TASK; 902e5265237SMatt Jacob break; 903e5265237SMatt Jacob case MSG_CLEAR_QUEUE: 9042df76c16SMatt Jacob notify.nt_ncode = NT_CLEAR_TASK_SET; 905e5265237SMatt Jacob break; 906e5265237SMatt Jacob case MSG_REL_RECOVERY: 9072df76c16SMatt Jacob notify.nt_ncode = NT_CLEAR_ACA; 908e5265237SMatt Jacob break; 909e5265237SMatt Jacob case MSG_TERM_IO_PROC: 9102df76c16SMatt Jacob notify.nt_ncode = NT_ABORT_TASK; 911e5265237SMatt Jacob break; 912e5265237SMatt Jacob case MSG_LUN_RESET: 9132df76c16SMatt Jacob notify.nt_ncode = NT_LUN_RESET; 914e5265237SMatt Jacob break; 915e5265237SMatt Jacob default: 9162df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "%s: unhandled message 0x%x", __func__, inp->in_msg[0]); 917387d8239SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inp); 918e5265237SMatt Jacob return; 919e5265237SMatt Jacob } 9202df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 921ea49c6e4SMatt Jacob } else { 9222df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "%s: unknown immediate notify status 0x%x", __func__, inp->in_status); 923387d8239SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inp); 924ea49c6e4SMatt Jacob } 925ea49c6e4SMatt Jacob } 926ea49c6e4SMatt Jacob 927ea49c6e4SMatt Jacob /* 928ea49c6e4SMatt Jacob * Synthesize a message from the task management flags in a FCP_CMND_IU. 929ea49c6e4SMatt Jacob */ 930ea49c6e4SMatt Jacob static void 9319cd7268eSMatt Jacob isp_got_msg_fc(ispsoftc_t *isp, in_fcentry_t *inp) 932ea49c6e4SMatt Jacob { 9332df76c16SMatt Jacob isp_notify_t notify; 93410365e5aSMatt Jacob static const char f1[] = "%s from N-port handle 0x%x lun %d seq 0x%x"; 9352df76c16SMatt Jacob static const char f2[] = "unknown %s 0x%x lun %d N-Port handle 0x%x task flags 0x%x seq 0x%x\n"; 936b4110d46SMatt Jacob uint16_t seqid, loopid; 937ea49c6e4SMatt Jacob 9382df76c16SMatt Jacob ISP_MEMZERO(¬ify, sizeof (isp_notify_t)); 9392df76c16SMatt Jacob notify.nt_hba = isp; 9402df76c16SMatt Jacob notify.nt_wwn = INI_ANY; 9412df76c16SMatt Jacob if (ISP_CAP_2KLOGIN(isp)) { 9422df76c16SMatt Jacob notify.nt_nphdl = ((in_fcentry_e_t *)inp)->in_iid; 943b4110d46SMatt Jacob loopid = ((in_fcentry_e_t *)inp)->in_iid; 9449cd7268eSMatt Jacob seqid = ((in_fcentry_e_t *)inp)->in_seqid; 945d82b6503SMatt Jacob } else { 9462df76c16SMatt Jacob notify.nt_nphdl = inp->in_iid; 947b4110d46SMatt Jacob loopid = inp->in_iid; 9489cd7268eSMatt Jacob seqid = inp->in_seqid; 949d82b6503SMatt Jacob } 9502df76c16SMatt Jacob notify.nt_sid = PORT_ANY; 9512df76c16SMatt Jacob notify.nt_did = PORT_ANY; 9522df76c16SMatt Jacob 953e5265237SMatt Jacob /* nt_tgt set in outer layers */ 9542df76c16SMatt Jacob if (ISP_CAP_SCCFW(isp)) { 9552df76c16SMatt Jacob notify.nt_lun = inp->in_scclun; 956e5265237SMatt Jacob } else { 9572df76c16SMatt Jacob notify.nt_lun = inp->in_lun; 958e5265237SMatt Jacob } 9592df76c16SMatt Jacob notify.nt_tagval = seqid; 9602df76c16SMatt Jacob notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32); 9612df76c16SMatt Jacob notify.nt_need_ack = 1; 9622df76c16SMatt Jacob notify.nt_lreserved = inp; 963d82b6503SMatt Jacob 964ea49c6e4SMatt Jacob if (inp->in_status != IN_MSG_RECEIVED) { 9652df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, f2, "immediate notify status", inp->in_status, notify.nt_lun, loopid, inp->in_task_flags, inp->in_seqid); 966387d8239SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inp); 967e5265237SMatt Jacob return; 968e5265237SMatt Jacob } 969ea49c6e4SMatt Jacob 9702f9e7606SMatt Jacob if (inp->in_task_flags & TASK_FLAGS_ABORT_TASK_SET) { 9712df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET", loopid, notify.nt_lun, inp->in_seqid); 9722df76c16SMatt Jacob notify.nt_ncode = NT_ABORT_TASK_SET; 973ea49c6e4SMatt Jacob } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_TASK_SET) { 9742df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET", loopid, notify.nt_lun, inp->in_seqid); 9752df76c16SMatt Jacob notify.nt_ncode = NT_CLEAR_TASK_SET; 9762f9e7606SMatt Jacob } else if (inp->in_task_flags & TASK_FLAGS_LUN_RESET) { 9772df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET", loopid, notify.nt_lun, inp->in_seqid); 9782df76c16SMatt Jacob notify.nt_ncode = NT_LUN_RESET; 979ea49c6e4SMatt Jacob } else if (inp->in_task_flags & TASK_FLAGS_TARGET_RESET) { 9802df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET", loopid, notify.nt_lun, inp->in_seqid); 9812df76c16SMatt Jacob notify.nt_ncode = NT_TARGET_RESET; 982ea49c6e4SMatt Jacob } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_ACA) { 9832df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA", loopid, notify.nt_lun, inp->in_seqid); 9842df76c16SMatt Jacob notify.nt_ncode = NT_CLEAR_ACA; 985ea49c6e4SMatt Jacob } else { 9862df76c16SMatt Jacob isp_prt(isp, ISP_LOGWARN, f2, "task flag", inp->in_status, notify.nt_lun, loopid, inp->in_task_flags, inp->in_seqid); 987387d8239SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inp); 988e5265237SMatt Jacob return; 989ea49c6e4SMatt Jacob } 9902df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 991ea49c6e4SMatt Jacob } 992ea49c6e4SMatt Jacob 99310365e5aSMatt Jacob static void 99410365e5aSMatt Jacob isp_got_tmf_24xx(ispsoftc_t *isp, at7_entry_t *aep) 99510365e5aSMatt Jacob { 9962df76c16SMatt Jacob isp_notify_t notify; 9972df76c16SMatt Jacob static const char f1[] = "%s from PortID 0x%06x lun %d seq 0x%08x"; 9982df76c16SMatt Jacob static const char f2[] = "unknown Task Flag 0x%x lun %d PortID 0x%x tag 0x%08x"; 9992df76c16SMatt Jacob uint16_t chan; 10002df76c16SMatt Jacob uint32_t sid, did; 100110365e5aSMatt Jacob 10022df76c16SMatt Jacob ISP_MEMZERO(¬ify, sizeof (isp_notify_t)); 10032df76c16SMatt Jacob notify.nt_hba = isp; 10042df76c16SMatt Jacob notify.nt_wwn = INI_ANY; 10052df76c16SMatt Jacob notify.nt_lun = (aep->at_cmnd.fcp_cmnd_lun[0] << 8) | (aep->at_cmnd.fcp_cmnd_lun[1]); 10062df76c16SMatt Jacob notify.nt_tagval = aep->at_rxid; 10072df76c16SMatt Jacob notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32); 10082df76c16SMatt Jacob notify.nt_lreserved = aep; 10092df76c16SMatt Jacob sid = (aep->at_hdr.s_id[0] << 16) | (aep->at_hdr.s_id[1] << 8) | (aep->at_hdr.s_id[2]); 101010365e5aSMatt Jacob 10112df76c16SMatt Jacob /* Channel has to derived from D_ID */ 10122df76c16SMatt Jacob did = (aep->at_hdr.d_id[0] << 16) | (aep->at_hdr.d_id[1] << 8) | aep->at_hdr.d_id[2]; 10132df76c16SMatt Jacob for (chan = 0; chan < isp->isp_nchan; chan++) { 10142df76c16SMatt Jacob if (FCPARAM(isp, chan)->isp_portid == did) { 10152df76c16SMatt Jacob break; 10162df76c16SMatt Jacob } 10172df76c16SMatt Jacob } 10182df76c16SMatt Jacob if (chan == isp->isp_nchan) { 10192df76c16SMatt Jacob isp_prt(isp, ISP_LOGWARN, "%s: D_ID 0x%x not found on any channel", __func__, did); 10202df76c16SMatt Jacob /* just drop on the floor */ 102110365e5aSMatt Jacob return; 102210365e5aSMatt Jacob } 10232df76c16SMatt Jacob notify.nt_nphdl = NIL_HANDLE; /* unknown here */ 10242df76c16SMatt Jacob notify.nt_sid = sid; 10252df76c16SMatt Jacob notify.nt_did = did; 10262df76c16SMatt Jacob notify.nt_channel = chan; 10272df76c16SMatt Jacob if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_ABORT_TASK_SET) { 10282df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET", sid, notify.nt_lun, aep->at_rxid); 10292df76c16SMatt Jacob notify.nt_ncode = NT_ABORT_TASK_SET; 10302df76c16SMatt Jacob } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_CLEAR_TASK_SET) { 10312df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET", sid, notify.nt_lun, aep->at_rxid); 10322df76c16SMatt Jacob notify.nt_ncode = NT_CLEAR_TASK_SET; 10332df76c16SMatt Jacob } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_LUN_RESET) { 10342df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET", sid, notify.nt_lun, aep->at_rxid); 10352df76c16SMatt Jacob notify.nt_ncode = NT_LUN_RESET; 10362df76c16SMatt Jacob } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_TGT_RESET) { 10372df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET", sid, notify.nt_lun, aep->at_rxid); 10382df76c16SMatt Jacob notify.nt_ncode = NT_TARGET_RESET; 10392df76c16SMatt Jacob } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_CLEAR_ACA) { 10402df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA", sid, notify.nt_lun, aep->at_rxid); 10412df76c16SMatt Jacob notify.nt_ncode = NT_CLEAR_ACA; 10422df76c16SMatt Jacob } else { 10432df76c16SMatt Jacob isp_prt(isp, ISP_LOGWARN, f2, aep->at_cmnd.fcp_cmnd_task_management, notify.nt_lun, sid, aep->at_rxid); 10442df76c16SMatt Jacob notify.nt_ncode = NT_UNKNOWN; 10452df76c16SMatt Jacob return; 10462df76c16SMatt Jacob } 10472df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify); 104810365e5aSMatt Jacob } 104910365e5aSMatt Jacob 10502df76c16SMatt Jacob int 10519cd7268eSMatt Jacob isp_notify_ack(ispsoftc_t *isp, void *arg) 1052ea49c6e4SMatt Jacob { 1053ea49c6e4SMatt Jacob char storage[QENTRY_LEN]; 1054ea49c6e4SMatt Jacob void *outp; 1055ea49c6e4SMatt Jacob 10562df76c16SMatt Jacob /* 10572df76c16SMatt Jacob * This is in case a Task Management Function ends up here. 10582df76c16SMatt Jacob */ 105910365e5aSMatt Jacob if (IS_24XX(isp) && arg != NULL && (((isphdr_t *)arg)->rqs_entry_type == RQSTYPE_ATIO)) { 106010365e5aSMatt Jacob at7_entry_t *aep = arg; 10612df76c16SMatt Jacob return (isp_endcmd(isp, aep, NIL_HANDLE, 0, 0, 0)); 10622df76c16SMatt Jacob } 10632df76c16SMatt Jacob 10642df76c16SMatt Jacob outp = isp_getrqentry(isp); 10652df76c16SMatt Jacob if (outp == NULL) { 10662df76c16SMatt Jacob isp_prt(isp, ISP_LOGWARN, rqo, __func__); 10672df76c16SMatt Jacob return (1); 10682df76c16SMatt Jacob } 10692df76c16SMatt Jacob 10702df76c16SMatt Jacob ISP_MEMZERO(storage, QENTRY_LEN); 10712df76c16SMatt Jacob 10722df76c16SMatt Jacob if (IS_24XX(isp)) { 107310365e5aSMatt Jacob na_fcentry_24xx_t *na = (na_fcentry_24xx_t *) storage; 1074387d8239SMatt Jacob na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK; 1075387d8239SMatt Jacob na->na_header.rqs_entry_count = 1; 107610365e5aSMatt Jacob if (arg) { 107710365e5aSMatt Jacob in_fcentry_24xx_t *in = arg; 107810365e5aSMatt Jacob na->na_nphdl = in->in_nphdl; 1079387d8239SMatt Jacob na->na_flags = in->in_flags; 108010365e5aSMatt Jacob na->na_status = in->in_status; 108110365e5aSMatt Jacob na->na_status_subcode = in->in_status_subcode; 1082*37a7daacSAlexander Motin na->na_fwhandle = in->in_fwhandle; 108310365e5aSMatt Jacob na->na_rxid = in->in_rxid; 108410365e5aSMatt Jacob na->na_oxid = in->in_oxid; 10852df76c16SMatt Jacob na->na_vpidx = in->in_vpidx; 108610365e5aSMatt Jacob if (in->in_status == IN24XX_SRR_RCVD) { 108710365e5aSMatt Jacob na->na_srr_rxid = in->in_srr_rxid; 108810365e5aSMatt Jacob na->na_srr_reloff_hi = in->in_srr_reloff_hi; 108910365e5aSMatt Jacob na->na_srr_reloff_lo = in->in_srr_reloff_lo; 109010365e5aSMatt Jacob na->na_srr_iu = in->in_srr_iu; 1091387d8239SMatt Jacob /* 1092387d8239SMatt Jacob * Whether we're accepting the SRR or rejecting 1093387d8239SMatt Jacob * it is determined by looking at the in_reserved 1094387d8239SMatt Jacob * field in the original notify structure. 1095387d8239SMatt Jacob */ 1096387d8239SMatt Jacob if (in->in_reserved) { 109710365e5aSMatt Jacob na->na_srr_flags = 1; 109810365e5aSMatt Jacob na->na_srr_reject_vunique = 0; 1099387d8239SMatt Jacob na->na_srr_reject_code = 9; /* unable to perform this command at this time */ 1100387d8239SMatt Jacob na->na_srr_reject_explanation = 0x2a; /* unable to supply the requested data */ 110110365e5aSMatt Jacob } 110210365e5aSMatt Jacob } 1103387d8239SMatt Jacob } 110410365e5aSMatt Jacob isp_put_notify_24xx_ack(isp, na, (na_fcentry_24xx_t *)outp); 110510365e5aSMatt Jacob } else if (IS_FC(isp)) { 1106ea49c6e4SMatt Jacob na_fcentry_t *na = (na_fcentry_t *) storage; 1107b4110d46SMatt Jacob int iid = 0; 1108b4110d46SMatt Jacob 1109ea49c6e4SMatt Jacob if (arg) { 1110ea49c6e4SMatt Jacob in_fcentry_t *inp = arg; 11112df76c16SMatt Jacob ISP_MEMCPY(storage, arg, sizeof (isphdr_t)); 11122df76c16SMatt Jacob if (ISP_CAP_2KLOGIN(isp)) { 11132df76c16SMatt Jacob ((na_fcentry_e_t *)na)->na_iid = ((in_fcentry_e_t *)inp)->in_iid; 1114b4110d46SMatt Jacob iid = ((na_fcentry_e_t *)na)->na_iid; 1115e5265237SMatt Jacob } else { 1116ea49c6e4SMatt Jacob na->na_iid = inp->in_iid; 1117b4110d46SMatt Jacob iid = na->na_iid; 1118e5265237SMatt Jacob } 11192df76c16SMatt Jacob na->na_task_flags = inp->in_task_flags & TASK_FLAGS_RESERVED_MASK; 1120ea49c6e4SMatt Jacob na->na_seqid = inp->in_seqid; 112175c1e828SMatt Jacob na->na_status = inp->in_status; 1122387d8239SMatt Jacob na->na_flags = NAFC_RCOUNT; 1123ea49c6e4SMatt Jacob if (inp->in_status == IN_RESET) { 1124387d8239SMatt Jacob na->na_flags = NAFC_RST_CLRD; /* We do not modify resource counts for LIP resets */ 1125ea49c6e4SMatt Jacob } 1126b4110d46SMatt Jacob if (inp->in_status == IN_MSG_RECEIVED) { 1127b4110d46SMatt Jacob na->na_flags |= NAFC_TVALID; 1128b4110d46SMatt Jacob na->na_response = 0; /* XXX SUCCEEDED XXX */ 1129b4110d46SMatt Jacob } 1130ea49c6e4SMatt Jacob } else { 1131ea49c6e4SMatt Jacob na->na_flags = NAFC_RST_CLRD; 1132ea49c6e4SMatt Jacob } 11339dae8807SMatt Jacob na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK; 11349dae8807SMatt Jacob na->na_header.rqs_entry_count = 1; 11352df76c16SMatt Jacob if (ISP_CAP_2KLOGIN(isp)) { 11362df76c16SMatt Jacob isp_put_notify_ack_fc_e(isp, (na_fcentry_e_t *) na, (na_fcentry_e_t *)outp); 1137e5265237SMatt Jacob } else { 11384fd13c1bSMatt Jacob isp_put_notify_ack_fc(isp, na, (na_fcentry_t *)outp); 1139e5265237SMatt Jacob } 11402df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "notify ack loopid %u seqid %x flags %x tflags %x response %x", iid, na->na_seqid, 1141b4110d46SMatt Jacob na->na_flags, na->na_task_flags, na->na_response); 1142ea49c6e4SMatt Jacob } else { 1143ea49c6e4SMatt Jacob na_entry_t *na = (na_entry_t *) storage; 1144ea49c6e4SMatt Jacob if (arg) { 1145ea49c6e4SMatt Jacob in_entry_t *inp = arg; 11462df76c16SMatt Jacob ISP_MEMCPY(storage, arg, sizeof (isphdr_t)); 1147ea49c6e4SMatt Jacob na->na_iid = inp->in_iid; 1148ea49c6e4SMatt Jacob na->na_lun = inp->in_lun; 1149ea49c6e4SMatt Jacob na->na_tgt = inp->in_tgt; 1150ea49c6e4SMatt Jacob na->na_seqid = inp->in_seqid; 1151ea49c6e4SMatt Jacob if (inp->in_status == IN_RESET) { 11529dae8807SMatt Jacob na->na_event = NA_RST_CLRD; 1153ea49c6e4SMatt Jacob } 1154ea49c6e4SMatt Jacob } else { 11559dae8807SMatt Jacob na->na_event = NA_RST_CLRD; 1156ea49c6e4SMatt Jacob } 11579dae8807SMatt Jacob na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK; 11589dae8807SMatt Jacob na->na_header.rqs_entry_count = 1; 11594fd13c1bSMatt Jacob isp_put_notify_ack(isp, na, (na_entry_t *)outp); 11602df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "notify ack loopid %u lun %u tgt %u seqid %x event %x", na->na_iid, na->na_lun, na->na_tgt, na->na_seqid, na->na_event); 1161ea49c6e4SMatt Jacob } 11622df76c16SMatt Jacob ISP_TDQE(isp, "isp_notify_ack", isp->isp_reqidx, storage); 11632df76c16SMatt Jacob ISP_SYNC_REQUEST(isp); 11642df76c16SMatt Jacob return (0); 11652df76c16SMatt Jacob } 11662df76c16SMatt Jacob 11672df76c16SMatt Jacob int 11682df76c16SMatt Jacob isp_acknak_abts(ispsoftc_t *isp, void *arg, int errno) 11692df76c16SMatt Jacob { 11702df76c16SMatt Jacob char storage[QENTRY_LEN]; 11712df76c16SMatt Jacob uint16_t tmpw; 11722df76c16SMatt Jacob uint8_t tmpb; 11732df76c16SMatt Jacob abts_t *abts = arg; 11742df76c16SMatt Jacob abts_rsp_t *rsp = (abts_rsp_t *) storage; 11752df76c16SMatt Jacob void *outp; 11762df76c16SMatt Jacob 11772df76c16SMatt Jacob if (!IS_24XX(isp)) { 11782df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "%s: called for non-24XX card", __func__); 11792df76c16SMatt Jacob return (0); 11802df76c16SMatt Jacob } 11812df76c16SMatt Jacob 11822df76c16SMatt Jacob if (abts->abts_header.rqs_entry_type != RQSTYPE_ABTS_RCVD) { 11832df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "%s: called for non-ABTS entry (0x%x)", __func__, abts->abts_header.rqs_entry_type); 11842df76c16SMatt Jacob return (0); 11852df76c16SMatt Jacob } 11862df76c16SMatt Jacob 11872df76c16SMatt Jacob outp = isp_getrqentry(isp); 11882df76c16SMatt Jacob if (outp == NULL) { 11892df76c16SMatt Jacob isp_prt(isp, ISP_LOGWARN, rqo, __func__); 11902df76c16SMatt Jacob return (1); 11912df76c16SMatt Jacob } 11922df76c16SMatt Jacob 11932df76c16SMatt Jacob ISP_MEMCPY(rsp, abts, QENTRY_LEN); 11942df76c16SMatt Jacob rsp->abts_rsp_header.rqs_entry_type = RQSTYPE_ABTS_RSP; 11952df76c16SMatt Jacob 11962df76c16SMatt Jacob /* 11972df76c16SMatt Jacob * Swap destination and source for response. 11982df76c16SMatt Jacob */ 11992df76c16SMatt Jacob rsp->abts_rsp_r_ctl = BA_ACC; 12002df76c16SMatt Jacob tmpw = rsp->abts_rsp_did_lo; 12012df76c16SMatt Jacob tmpb = rsp->abts_rsp_did_hi; 12022df76c16SMatt Jacob rsp->abts_rsp_did_lo = rsp->abts_rsp_sid_lo; 12032df76c16SMatt Jacob rsp->abts_rsp_did_hi = rsp->abts_rsp_sid_hi; 12042df76c16SMatt Jacob rsp->abts_rsp_sid_lo = tmpw; 12052df76c16SMatt Jacob rsp->abts_rsp_sid_hi = tmpb; 12062df76c16SMatt Jacob 12072df76c16SMatt Jacob rsp->abts_rsp_f_ctl_hi ^= 0x80; /* invert Exchange Context */ 12082df76c16SMatt Jacob rsp->abts_rsp_f_ctl_hi &= ~0x7f; /* clear Sequence Initiator and other bits */ 12092df76c16SMatt Jacob rsp->abts_rsp_f_ctl_hi |= 0x10; /* abort the whole exchange */ 12102df76c16SMatt Jacob rsp->abts_rsp_f_ctl_hi |= 0x8; /* last data frame of sequence */ 12112df76c16SMatt Jacob rsp->abts_rsp_f_ctl_hi |= 0x1; /* transfer Sequence Initiative */ 12122df76c16SMatt Jacob rsp->abts_rsp_f_ctl_lo = 0; 12132df76c16SMatt Jacob 12142df76c16SMatt Jacob if (errno == 0) { 12152df76c16SMatt Jacob uint16_t rx_id, ox_id; 12162df76c16SMatt Jacob 12172df76c16SMatt Jacob rx_id = rsp->abts_rsp_rx_id; 12182df76c16SMatt Jacob ox_id = rsp->abts_rsp_ox_id; 12192df76c16SMatt Jacob ISP_MEMZERO(&rsp->abts_rsp_payload.ba_acc, sizeof (rsp->abts_rsp_payload.ba_acc)); 12202df76c16SMatt Jacob isp_prt(isp, ISP_LOGTINFO, "[0x%x] ABTS of 0x%x being BA_ACC'd", rsp->abts_rsp_rxid_abts, rsp->abts_rsp_rxid_task); 12212df76c16SMatt Jacob rsp->abts_rsp_payload.ba_acc.aborted_rx_id = rx_id; 12222df76c16SMatt Jacob rsp->abts_rsp_payload.ba_acc.aborted_ox_id = ox_id; 12232df76c16SMatt Jacob rsp->abts_rsp_payload.ba_acc.high_seq_cnt = 0xffff; 12242df76c16SMatt Jacob } else { 12252df76c16SMatt Jacob ISP_MEMZERO(&rsp->abts_rsp_payload.ba_rjt, sizeof (rsp->abts_rsp_payload.ba_acc)); 12262df76c16SMatt Jacob switch (errno) { 12272df76c16SMatt Jacob case ENOMEM: 1228387d8239SMatt Jacob rsp->abts_rsp_payload.ba_rjt.reason = 5; /* Logical Unit Busy */ 12292df76c16SMatt Jacob break; 12302df76c16SMatt Jacob default: 12312df76c16SMatt Jacob rsp->abts_rsp_payload.ba_rjt.reason = 9; /* Unable to perform command request */ 12322df76c16SMatt Jacob break; 12332df76c16SMatt Jacob } 12342df76c16SMatt Jacob } 12352df76c16SMatt Jacob 12362df76c16SMatt Jacob /* 12372df76c16SMatt Jacob * The caller will have set response values as appropriate 12382df76c16SMatt Jacob * in the ABTS structure just before calling us. 12392df76c16SMatt Jacob */ 12402df76c16SMatt Jacob isp_put_abts_rsp(isp, rsp, (abts_rsp_t *)outp); 12412df76c16SMatt Jacob ISP_TDQE(isp, "isp_acknak_abts", isp->isp_reqidx, storage); 12422df76c16SMatt Jacob ISP_SYNC_REQUEST(isp); 12432df76c16SMatt Jacob return (0); 1244ea49c6e4SMatt Jacob } 1245ea49c6e4SMatt Jacob 1246ea49c6e4SMatt Jacob static void 12479cd7268eSMatt Jacob isp_handle_atio(ispsoftc_t *isp, at_entry_t *aep) 1248ea49c6e4SMatt Jacob { 1249ea49c6e4SMatt Jacob int lun; 1250ea49c6e4SMatt Jacob lun = aep->at_lun; 1251ea49c6e4SMatt Jacob /* 1252ea49c6e4SMatt Jacob * The firmware status (except for the QLTM_SVALID bit) indicates 1253ea49c6e4SMatt Jacob * why this ATIO was sent to us. 1254ea49c6e4SMatt Jacob * 1255ea49c6e4SMatt Jacob * If QLTM_SVALID is set, the firware has recommended Sense Data. 1256ea49c6e4SMatt Jacob * 1257ea49c6e4SMatt Jacob * If the DISCONNECTS DISABLED bit is set in the flags field, 1258ea49c6e4SMatt Jacob * we're still connected on the SCSI bus - i.e. the initiator 1259ea49c6e4SMatt Jacob * did not set DiscPriv in the identify message. We don't care 1260ea49c6e4SMatt Jacob * about this so it's ignored. 1261ea49c6e4SMatt Jacob */ 1262ea49c6e4SMatt Jacob 1263ea49c6e4SMatt Jacob switch (aep->at_status & ~QLTM_SVALID) { 1264ea49c6e4SMatt Jacob case AT_PATH_INVALID: 1265ea49c6e4SMatt Jacob /* 1266ea49c6e4SMatt Jacob * ATIO rejected by the firmware due to disabled lun. 1267ea49c6e4SMatt Jacob */ 12682df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "rejected ATIO for disabled lun %d", lun); 1269ea49c6e4SMatt Jacob break; 1270ea49c6e4SMatt Jacob case AT_NOCAP: 1271ea49c6e4SMatt Jacob /* 1272ea49c6e4SMatt Jacob * Requested Capability not available 1273ea49c6e4SMatt Jacob * We sent an ATIO that overflowed the firmware's 1274ea49c6e4SMatt Jacob * command resource count. 1275ea49c6e4SMatt Jacob */ 12762df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "rejected ATIO for lun %d because of command count overflow", lun); 1277ea49c6e4SMatt Jacob break; 1278ea49c6e4SMatt Jacob 1279ea49c6e4SMatt Jacob case AT_BDR_MSG: 1280ea49c6e4SMatt Jacob /* 1281ea49c6e4SMatt Jacob * If we send an ATIO to the firmware to increment 1282ea49c6e4SMatt Jacob * its command resource count, and the firmware is 1283ea49c6e4SMatt Jacob * recovering from a Bus Device Reset, it returns 1284ea49c6e4SMatt Jacob * the ATIO with this status. We set the command 12854fd13c1bSMatt Jacob * resource count in the Enable Lun entry and do 1286ea49c6e4SMatt Jacob * not increment it. Therefore we should never get 1287ea49c6e4SMatt Jacob * this status here. 1288ea49c6e4SMatt Jacob */ 12892df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, atiocope, lun, GET_BUS_VAL(aep->at_iid)); 1290ea49c6e4SMatt Jacob break; 1291ea49c6e4SMatt Jacob 1292ea49c6e4SMatt Jacob case AT_CDB: /* Got a CDB */ 1293ea49c6e4SMatt Jacob case AT_PHASE_ERROR: /* Bus Phase Sequence Error */ 1294ea49c6e4SMatt Jacob /* 1295ea49c6e4SMatt Jacob * Punt to platform specific layer. 1296ea49c6e4SMatt Jacob */ 12972df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_ACTION, aep); 1298ea49c6e4SMatt Jacob break; 1299ea49c6e4SMatt Jacob 1300ea49c6e4SMatt Jacob case AT_RESET: 1301ea49c6e4SMatt Jacob /* 1302d64ada50SJens Schweikhardt * A bus reset came along and blew away this command. Why 1303ea49c6e4SMatt Jacob * they do this in addition the async event code stuff, 1304ea49c6e4SMatt Jacob * I dunno. 1305ea49c6e4SMatt Jacob * 1306ea49c6e4SMatt Jacob * Ignore it because the async event will clear things 1307ea49c6e4SMatt Jacob * up for us. 1308ea49c6e4SMatt Jacob */ 13092df76c16SMatt Jacob isp_prt(isp, ISP_LOGWARN, atior, lun, GET_IID_VAL(aep->at_iid), GET_BUS_VAL(aep->at_iid)); 1310ea49c6e4SMatt Jacob break; 1311ea49c6e4SMatt Jacob 1312ea49c6e4SMatt Jacob 1313ea49c6e4SMatt Jacob default: 13142df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "Unknown ATIO status 0x%x from loopid %d for lun %d", aep->at_status, aep->at_iid, lun); 1315b25bcef8SMatt Jacob (void) isp_target_put_atio(isp, aep); 1316ea49c6e4SMatt Jacob break; 1317ea49c6e4SMatt Jacob } 1318ea49c6e4SMatt Jacob } 1319ea49c6e4SMatt Jacob 1320ea49c6e4SMatt Jacob static void 13219cd7268eSMatt Jacob isp_handle_atio2(ispsoftc_t *isp, at2_entry_t *aep) 1322ea49c6e4SMatt Jacob { 1323e5265237SMatt Jacob int lun, iid; 13242133e16fSMatt Jacob 13252df76c16SMatt Jacob if (ISP_CAP_SCCFW(isp)) { 1326ea49c6e4SMatt Jacob lun = aep->at_scclun; 13272133e16fSMatt Jacob } else { 1328ea49c6e4SMatt Jacob lun = aep->at_lun; 13292133e16fSMatt Jacob } 13302133e16fSMatt Jacob 13312df76c16SMatt Jacob if (ISP_CAP_2KLOGIN(isp)) { 1332e5265237SMatt Jacob iid = ((at2e_entry_t *)aep)->at_iid; 1333e5265237SMatt Jacob } else { 1334e5265237SMatt Jacob iid = aep->at_iid; 1335e5265237SMatt Jacob } 1336e5265237SMatt Jacob 1337ea49c6e4SMatt Jacob /* 1338ea49c6e4SMatt Jacob * The firmware status (except for the QLTM_SVALID bit) indicates 1339ea49c6e4SMatt Jacob * why this ATIO was sent to us. 1340ea49c6e4SMatt Jacob * 1341ea49c6e4SMatt Jacob * If QLTM_SVALID is set, the firware has recommended Sense Data. 1342ea49c6e4SMatt Jacob * 1343ea49c6e4SMatt Jacob * If the DISCONNECTS DISABLED bit is set in the flags field, 1344ea49c6e4SMatt Jacob * we're still connected on the SCSI bus - i.e. the initiator 1345ea49c6e4SMatt Jacob * did not set DiscPriv in the identify message. We don't care 1346ea49c6e4SMatt Jacob * about this so it's ignored. 1347ea49c6e4SMatt Jacob */ 1348ea49c6e4SMatt Jacob 1349ea49c6e4SMatt Jacob switch (aep->at_status & ~QLTM_SVALID) { 1350ea49c6e4SMatt Jacob case AT_PATH_INVALID: 1351ea49c6e4SMatt Jacob /* 1352ea49c6e4SMatt Jacob * ATIO rejected by the firmware due to disabled lun. 1353ea49c6e4SMatt Jacob */ 13542df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "rejected ATIO2 for disabled lun %d", lun); 1355ea49c6e4SMatt Jacob break; 1356ea49c6e4SMatt Jacob case AT_NOCAP: 1357ea49c6e4SMatt Jacob /* 1358ea49c6e4SMatt Jacob * Requested Capability not available 1359ea49c6e4SMatt Jacob * We sent an ATIO that overflowed the firmware's 1360ea49c6e4SMatt Jacob * command resource count. 1361ea49c6e4SMatt Jacob */ 13622df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "rejected ATIO2 for lun %d- command count overflow", lun); 1363ea49c6e4SMatt Jacob break; 1364ea49c6e4SMatt Jacob 1365ea49c6e4SMatt Jacob case AT_BDR_MSG: 1366ea49c6e4SMatt Jacob /* 1367ea49c6e4SMatt Jacob * If we send an ATIO to the firmware to increment 1368ea49c6e4SMatt Jacob * its command resource count, and the firmware is 1369ea49c6e4SMatt Jacob * recovering from a Bus Device Reset, it returns 1370ea49c6e4SMatt Jacob * the ATIO with this status. We set the command 1371ea49c6e4SMatt Jacob * resource count in the Enable Lun entry and no 1372ea49c6e4SMatt Jacob * not increment it. Therefore we should never get 1373ea49c6e4SMatt Jacob * this status here. 1374ea49c6e4SMatt Jacob */ 137523ac1fceSMatt Jacob isp_prt(isp, ISP_LOGERR, atiocope, lun, 0); 1376ea49c6e4SMatt Jacob break; 1377ea49c6e4SMatt Jacob 1378ea49c6e4SMatt Jacob case AT_CDB: /* Got a CDB */ 1379ea49c6e4SMatt Jacob /* 1380ea49c6e4SMatt Jacob * Punt to platform specific layer. 1381ea49c6e4SMatt Jacob */ 13822df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_ACTION, aep); 1383ea49c6e4SMatt Jacob break; 1384ea49c6e4SMatt Jacob 1385ea49c6e4SMatt Jacob case AT_RESET: 1386ea49c6e4SMatt Jacob /* 1387ea49c6e4SMatt Jacob * A bus reset came along an blew away this command. Why 1388ea49c6e4SMatt Jacob * they do this in addition the async event code stuff, 1389ea49c6e4SMatt Jacob * I dunno. 1390ea49c6e4SMatt Jacob * 1391ea49c6e4SMatt Jacob * Ignore it because the async event will clear things 1392ea49c6e4SMatt Jacob * up for us. 1393ea49c6e4SMatt Jacob */ 1394e5265237SMatt Jacob isp_prt(isp, ISP_LOGERR, atior, lun, iid, 0); 1395ea49c6e4SMatt Jacob break; 1396ea49c6e4SMatt Jacob 1397ea49c6e4SMatt Jacob 1398ea49c6e4SMatt Jacob default: 13992df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "Unknown ATIO2 status 0x%x from loopid %d for lun %d", aep->at_status, iid, lun); 1400b25bcef8SMatt Jacob (void) isp_target_put_atio(isp, aep); 1401ea49c6e4SMatt Jacob break; 1402ea49c6e4SMatt Jacob } 1403ea49c6e4SMatt Jacob } 1404ea49c6e4SMatt Jacob 1405ea49c6e4SMatt Jacob static void 14069cd7268eSMatt Jacob isp_handle_ctio(ispsoftc_t *isp, ct_entry_t *ct) 1407ea49c6e4SMatt Jacob { 1408b0bd9b71SMatt Jacob void *xs; 140910549c05SMatt Jacob int pl = ISP_LOGTDEBUG2; 1410ea49c6e4SMatt Jacob char *fmsg = NULL; 1411ea49c6e4SMatt Jacob 1412b0bd9b71SMatt Jacob if (ct->ct_syshandle) { 141351e23558SNate Lawson xs = isp_find_xs_tgt(isp, ct->ct_syshandle); 141410365e5aSMatt Jacob if (xs == NULL) { 141510549c05SMatt Jacob pl = ISP_LOGALL; 141610365e5aSMatt Jacob } 1417ea49c6e4SMatt Jacob } else { 1418ea49c6e4SMatt Jacob xs = NULL; 1419ea49c6e4SMatt Jacob } 1420ea49c6e4SMatt Jacob 1421ea49c6e4SMatt Jacob switch (ct->ct_status & ~QLTM_SVALID) { 1422ea49c6e4SMatt Jacob case CT_OK: 1423ea49c6e4SMatt Jacob /* 1424ea49c6e4SMatt Jacob * There are generally 3 possibilities as to why we'd get 1425ea49c6e4SMatt Jacob * this condition: 1426ea49c6e4SMatt Jacob * We disconnected after receiving a CDB. 1427ea49c6e4SMatt Jacob * We sent or received data. 1428ea49c6e4SMatt Jacob * We sent status & command complete. 1429ea49c6e4SMatt Jacob */ 1430ea49c6e4SMatt Jacob 14319dae8807SMatt Jacob if (ct->ct_flags & CT_SENDSTATUS) { 14329dae8807SMatt Jacob break; 14339dae8807SMatt Jacob } else if ((ct->ct_flags & CT_DATAMASK) == CT_NO_DATA) { 1434ea49c6e4SMatt Jacob /* 1435ea49c6e4SMatt Jacob * Nothing to do in this case. 1436ea49c6e4SMatt Jacob */ 14372df76c16SMatt Jacob isp_prt(isp, pl, "CTIO- iid %d disconnected OK", ct->ct_iid); 1438ea49c6e4SMatt Jacob return; 1439ea49c6e4SMatt Jacob } 1440ea49c6e4SMatt Jacob break; 1441ea49c6e4SMatt Jacob 1442ea49c6e4SMatt Jacob case CT_BDR_MSG: 1443ea49c6e4SMatt Jacob /* 1444ea49c6e4SMatt Jacob * Bus Device Reset message received or the SCSI Bus has 1445ea49c6e4SMatt Jacob * been Reset; the firmware has gone to Bus Free. 1446ea49c6e4SMatt Jacob * 1447976b0106SKevin Lo * The firmware generates an async mailbox interrupt to 1448ea49c6e4SMatt Jacob * notify us of this and returns outstanding CTIOs with this 1449ea49c6e4SMatt Jacob * status. These CTIOs are handled in that same way as 1450ea49c6e4SMatt Jacob * CT_ABORTED ones, so just fall through here. 1451ea49c6e4SMatt Jacob */ 1452ea49c6e4SMatt Jacob fmsg = "Bus Device Reset"; 1453ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 1454ea49c6e4SMatt Jacob case CT_RESET: 1455ea49c6e4SMatt Jacob if (fmsg == NULL) 1456ea49c6e4SMatt Jacob fmsg = "Bus Reset"; 1457ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 1458ea49c6e4SMatt Jacob case CT_ABORTED: 1459ea49c6e4SMatt Jacob /* 1460ea49c6e4SMatt Jacob * When an Abort message is received the firmware goes to 1461ea49c6e4SMatt Jacob * Bus Free and returns all outstanding CTIOs with the status 1462ea49c6e4SMatt Jacob * set, then sends us an Immediate Notify entry. 1463ea49c6e4SMatt Jacob */ 1464ea49c6e4SMatt Jacob if (fmsg == NULL) 146523ac1fceSMatt Jacob fmsg = "ABORT TAG message sent by Initiator"; 146610365e5aSMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "CTIO destroyed by %s", fmsg); 1467ea49c6e4SMatt Jacob break; 1468ea49c6e4SMatt Jacob 1469ea49c6e4SMatt Jacob case CT_INVAL: 1470ea49c6e4SMatt Jacob /* 1471ea49c6e4SMatt Jacob * CTIO rejected by the firmware due to disabled lun. 1472ea49c6e4SMatt Jacob * "Cannot Happen". 1473ea49c6e4SMatt Jacob */ 14742df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "Firmware rejected CTIO for disabled lun %d", ct->ct_lun); 1475ea49c6e4SMatt Jacob break; 1476ea49c6e4SMatt Jacob 1477ea49c6e4SMatt Jacob case CT_NOPATH: 1478ea49c6e4SMatt Jacob /* 1479ea49c6e4SMatt Jacob * CTIO rejected by the firmware due "no path for the 1480ea49c6e4SMatt Jacob * nondisconnecting nexus specified". This means that 1481ea49c6e4SMatt Jacob * we tried to access the bus while a non-disconnecting 1482ea49c6e4SMatt Jacob * command is in process. 1483ea49c6e4SMatt Jacob */ 14842df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "Firmware rejected CTIO for bad nexus %d/%d/%d", ct->ct_iid, ct->ct_tgt, ct->ct_lun); 1485ea49c6e4SMatt Jacob break; 1486ea49c6e4SMatt Jacob 1487ea49c6e4SMatt Jacob case CT_RSELTMO: 1488ea49c6e4SMatt Jacob fmsg = "Reselection"; 1489ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 1490ea49c6e4SMatt Jacob case CT_TIMEOUT: 1491ea49c6e4SMatt Jacob if (fmsg == NULL) 1492ea49c6e4SMatt Jacob fmsg = "Command"; 14932df76c16SMatt Jacob isp_prt(isp, ISP_LOGWARN, "Firmware timed out on %s", fmsg); 1494ea49c6e4SMatt Jacob break; 1495ea49c6e4SMatt Jacob 1496b25bcef8SMatt Jacob case CT_PANIC: 1497b25bcef8SMatt Jacob if (fmsg == NULL) 1498b25bcef8SMatt Jacob fmsg = "Unrecoverable Error"; 1499b25bcef8SMatt Jacob /*FALLTHROUGH*/ 1500ea49c6e4SMatt Jacob case CT_ERR: 1501b25bcef8SMatt Jacob if (fmsg == NULL) 1502ea49c6e4SMatt Jacob fmsg = "Completed with Error"; 1503ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 1504ea49c6e4SMatt Jacob case CT_PHASE_ERROR: 1505ea49c6e4SMatt Jacob if (fmsg == NULL) 1506ea49c6e4SMatt Jacob fmsg = "Phase Sequence Error"; 1507ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 1508ea49c6e4SMatt Jacob case CT_TERMINATED: 1509ea49c6e4SMatt Jacob if (fmsg == NULL) 1510ea49c6e4SMatt Jacob fmsg = "terminated by TERMINATE TRANSFER"; 1511ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 1512ea49c6e4SMatt Jacob case CT_NOACK: 1513ea49c6e4SMatt Jacob if (fmsg == NULL) 1514ea49c6e4SMatt Jacob fmsg = "unacknowledged Immediate Notify pending"; 151510549c05SMatt Jacob isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg); 1516ea49c6e4SMatt Jacob break; 1517ea49c6e4SMatt Jacob default: 15182df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "Unknown CTIO status 0x%x", ct->ct_status & ~QLTM_SVALID); 1519ea49c6e4SMatt Jacob break; 1520ea49c6e4SMatt Jacob } 1521ea49c6e4SMatt Jacob 1522ea49c6e4SMatt Jacob if (xs == NULL) { 1523ea49c6e4SMatt Jacob /* 1524ea49c6e4SMatt Jacob * There may be more than one CTIO for a data transfer, 1525ea49c6e4SMatt Jacob * or this may be a status CTIO we're not monitoring. 1526ea49c6e4SMatt Jacob * 1527ea49c6e4SMatt Jacob * The assumption is that they'll all be returned in the 1528ea49c6e4SMatt Jacob * order we got them. 1529ea49c6e4SMatt Jacob */ 1530b0bd9b71SMatt Jacob if (ct->ct_syshandle == 0) { 1531ea49c6e4SMatt Jacob if ((ct->ct_flags & CT_SENDSTATUS) == 0) { 15322df76c16SMatt Jacob isp_prt(isp, pl, "intermediate CTIO completed ok"); 1533ea49c6e4SMatt Jacob } else { 15342df76c16SMatt Jacob isp_prt(isp, pl, "unmonitored CTIO completed ok"); 1535ea49c6e4SMatt Jacob } 1536ea49c6e4SMatt Jacob } else { 15372df76c16SMatt Jacob isp_prt(isp, pl, "NO xs for CTIO (handle 0x%x) status 0x%x", ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID); 1538ea49c6e4SMatt Jacob } 1539ea49c6e4SMatt Jacob } else { 1540ea49c6e4SMatt Jacob /* 1541ea49c6e4SMatt Jacob * Final CTIO completed. Release DMA resources and 1542ea49c6e4SMatt Jacob * notify platform dependent layers. 1543ea49c6e4SMatt Jacob */ 15445d571944SMatt Jacob if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) { 1545b0bd9b71SMatt Jacob ISP_DMAFREE(isp, xs, ct->ct_syshandle); 1546ea49c6e4SMatt Jacob } 1547b25bcef8SMatt Jacob isp_prt(isp, pl, "final CTIO complete"); 1548ea49c6e4SMatt Jacob /* 1549ea49c6e4SMatt Jacob * The platform layer will destroy the handle if appropriate. 1550ea49c6e4SMatt Jacob */ 15512df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_ACTION, ct); 1552ea49c6e4SMatt Jacob } 1553ea49c6e4SMatt Jacob } 1554ea49c6e4SMatt Jacob 1555ea49c6e4SMatt Jacob static void 15569cd7268eSMatt Jacob isp_handle_ctio2(ispsoftc_t *isp, ct2_entry_t *ct) 1557ea49c6e4SMatt Jacob { 155810365e5aSMatt Jacob void *xs; 155910549c05SMatt Jacob int pl = ISP_LOGTDEBUG2; 1560ea49c6e4SMatt Jacob char *fmsg = NULL; 1561ea49c6e4SMatt Jacob 1562b0bd9b71SMatt Jacob if (ct->ct_syshandle) { 156351e23558SNate Lawson xs = isp_find_xs_tgt(isp, ct->ct_syshandle); 156410365e5aSMatt Jacob if (xs == NULL) { 156510549c05SMatt Jacob pl = ISP_LOGALL; 156610365e5aSMatt Jacob } 1567ea49c6e4SMatt Jacob } else { 1568ea49c6e4SMatt Jacob xs = NULL; 1569ea49c6e4SMatt Jacob } 1570ea49c6e4SMatt Jacob 1571ea49c6e4SMatt Jacob switch (ct->ct_status & ~QLTM_SVALID) { 15725d571944SMatt Jacob case CT_BUS_ERROR: 15735d571944SMatt Jacob isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error"); 15745d571944SMatt Jacob /* FALL Through */ 15755d571944SMatt Jacob case CT_DATA_OVER: 15765d571944SMatt Jacob case CT_DATA_UNDER: 1577ea49c6e4SMatt Jacob case CT_OK: 1578ea49c6e4SMatt Jacob /* 1579ea49c6e4SMatt Jacob * There are generally 2 possibilities as to why we'd get 1580ea49c6e4SMatt Jacob * this condition: 1581ea49c6e4SMatt Jacob * We sent or received data. 1582ea49c6e4SMatt Jacob * We sent status & command complete. 1583ea49c6e4SMatt Jacob */ 1584ea49c6e4SMatt Jacob 1585ea49c6e4SMatt Jacob break; 1586ea49c6e4SMatt Jacob 1587ea49c6e4SMatt Jacob case CT_BDR_MSG: 1588ea49c6e4SMatt Jacob /* 15895d571944SMatt Jacob * Target Reset function received. 1590ea49c6e4SMatt Jacob * 1591976b0106SKevin Lo * The firmware generates an async mailbox interrupt to 1592ea49c6e4SMatt Jacob * notify us of this and returns outstanding CTIOs with this 1593ea49c6e4SMatt Jacob * status. These CTIOs are handled in that same way as 1594ea49c6e4SMatt Jacob * CT_ABORTED ones, so just fall through here. 1595ea49c6e4SMatt Jacob */ 159610365e5aSMatt Jacob fmsg = "TARGET RESET"; 1597ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 1598ea49c6e4SMatt Jacob case CT_RESET: 1599ea49c6e4SMatt Jacob if (fmsg == NULL) 16005d571944SMatt Jacob fmsg = "LIP Reset"; 1601ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 1602ea49c6e4SMatt Jacob case CT_ABORTED: 1603ea49c6e4SMatt Jacob /* 1604ea49c6e4SMatt Jacob * When an Abort message is received the firmware goes to 1605ea49c6e4SMatt Jacob * Bus Free and returns all outstanding CTIOs with the status 1606ea49c6e4SMatt Jacob * set, then sends us an Immediate Notify entry. 1607ea49c6e4SMatt Jacob */ 160810365e5aSMatt Jacob if (fmsg == NULL) { 160910365e5aSMatt Jacob fmsg = "ABORT"; 161010365e5aSMatt Jacob } 1611ea49c6e4SMatt Jacob 16122df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "CTIO2 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid); 1613ea49c6e4SMatt Jacob break; 1614ea49c6e4SMatt Jacob 1615ea49c6e4SMatt Jacob case CT_INVAL: 1616ea49c6e4SMatt Jacob /* 16170c02c31bSMatt Jacob * CTIO rejected by the firmware - invalid data direction. 1618ea49c6e4SMatt Jacob */ 16192f9e7606SMatt Jacob isp_prt(isp, ISP_LOGERR, "CTIO2 had wrong data direction"); 1620ea49c6e4SMatt Jacob break; 1621ea49c6e4SMatt Jacob 1622ea49c6e4SMatt Jacob case CT_RSELTMO: 16235d571944SMatt Jacob fmsg = "failure to reconnect to initiator"; 1624ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 1625ea49c6e4SMatt Jacob case CT_TIMEOUT: 1626ea49c6e4SMatt Jacob if (fmsg == NULL) 16275d571944SMatt Jacob fmsg = "command"; 16282df76c16SMatt Jacob isp_prt(isp, ISP_LOGWARN, "Firmware timed out on %s", fmsg); 1629ea49c6e4SMatt Jacob break; 1630ea49c6e4SMatt Jacob 1631ea49c6e4SMatt Jacob case CT_ERR: 1632ea49c6e4SMatt Jacob fmsg = "Completed with Error"; 1633ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 1634ea49c6e4SMatt Jacob case CT_LOGOUT: 1635ea49c6e4SMatt Jacob if (fmsg == NULL) 1636ea49c6e4SMatt Jacob fmsg = "Port Logout"; 1637ea49c6e4SMatt Jacob /*FALLTHROUGH*/ 163810365e5aSMatt Jacob case CT_PORTUNAVAIL: 1639ea49c6e4SMatt Jacob if (fmsg == NULL) 1640ea49c6e4SMatt Jacob fmsg = "Port not available"; 1641a0fb4cf1SPoul-Henning Kamp /*FALLTHROUGH*/ 16425d571944SMatt Jacob case CT_PORTCHANGED: 16435d571944SMatt Jacob if (fmsg == NULL) 16445d571944SMatt Jacob fmsg = "Port Changed"; 1645a0fb4cf1SPoul-Henning Kamp /*FALLTHROUGH*/ 1646ea49c6e4SMatt Jacob case CT_NOACK: 1647ea49c6e4SMatt Jacob if (fmsg == NULL) 1648ea49c6e4SMatt Jacob fmsg = "unacknowledged Immediate Notify pending"; 164910365e5aSMatt Jacob isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg); 1650ea49c6e4SMatt Jacob break; 1651ea49c6e4SMatt Jacob 1652ea49c6e4SMatt Jacob case CT_INVRXID: 1653ea49c6e4SMatt Jacob /* 1654ea49c6e4SMatt Jacob * CTIO rejected by the firmware because an invalid RX_ID. 1655ea49c6e4SMatt Jacob * Just print a message. 1656ea49c6e4SMatt Jacob */ 16572df76c16SMatt Jacob isp_prt(isp, ISP_LOGWARN, "CTIO2 completed with Invalid RX_ID 0x%x", ct->ct_rxid); 1658ea49c6e4SMatt Jacob break; 1659ea49c6e4SMatt Jacob 1660ea49c6e4SMatt Jacob default: 16612df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "Unknown CTIO2 status 0x%x", ct->ct_status & ~QLTM_SVALID); 1662ea49c6e4SMatt Jacob break; 1663ea49c6e4SMatt Jacob } 1664ea49c6e4SMatt Jacob 1665ea49c6e4SMatt Jacob if (xs == NULL) { 1666ea49c6e4SMatt Jacob /* 1667ea49c6e4SMatt Jacob * There may be more than one CTIO for a data transfer, 1668ea49c6e4SMatt Jacob * or this may be a status CTIO we're not monitoring. 1669ea49c6e4SMatt Jacob * 1670ea49c6e4SMatt Jacob * The assumption is that they'll all be returned in the 1671ea49c6e4SMatt Jacob * order we got them. 1672ea49c6e4SMatt Jacob */ 1673b0bd9b71SMatt Jacob if (ct->ct_syshandle == 0) { 1674ac9d0a02SMatt Jacob if ((ct->ct_flags & CT2_SENDSTATUS) == 0) { 16752df76c16SMatt Jacob isp_prt(isp, pl, "intermediate CTIO completed ok"); 1676ea49c6e4SMatt Jacob } else { 16772df76c16SMatt Jacob isp_prt(isp, pl, "unmonitored CTIO completed ok"); 1678ea49c6e4SMatt Jacob } 1679ea49c6e4SMatt Jacob } else { 16802df76c16SMatt Jacob isp_prt(isp, pl, "NO xs for CTIO (handle 0x%x) status 0x%x", ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID); 1681ea49c6e4SMatt Jacob } 1682ea49c6e4SMatt Jacob } else { 16835d571944SMatt Jacob if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) { 16845d571944SMatt Jacob ISP_DMAFREE(isp, xs, ct->ct_syshandle); 16855d571944SMatt Jacob } 1686ac9d0a02SMatt Jacob if (ct->ct_flags & CT2_SENDSTATUS) { 1687ea49c6e4SMatt Jacob /* 1688ea49c6e4SMatt Jacob * Sent status and command complete. 1689ea49c6e4SMatt Jacob * 1690ea49c6e4SMatt Jacob * We're now really done with this command, so we 1691ea49c6e4SMatt Jacob * punt to the platform dependent layers because 1692ea49c6e4SMatt Jacob * only there can we do the appropriate command 1693ea49c6e4SMatt Jacob * complete thread synchronization. 1694ea49c6e4SMatt Jacob */ 169510549c05SMatt Jacob isp_prt(isp, pl, "status CTIO complete"); 1696ea49c6e4SMatt Jacob } else { 1697ea49c6e4SMatt Jacob /* 1698ea49c6e4SMatt Jacob * Final CTIO completed. Release DMA resources and 1699ea49c6e4SMatt Jacob * notify platform dependent layers. 1700ea49c6e4SMatt Jacob */ 170110549c05SMatt Jacob isp_prt(isp, pl, "data CTIO complete"); 1702ea49c6e4SMatt Jacob } 17032df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_ACTION, ct); 1704ea49c6e4SMatt Jacob /* 1705ea49c6e4SMatt Jacob * The platform layer will destroy the handle if appropriate. 1706ea49c6e4SMatt Jacob */ 1707ea49c6e4SMatt Jacob } 1708ea49c6e4SMatt Jacob } 170910365e5aSMatt Jacob 171010365e5aSMatt Jacob static void 171110365e5aSMatt Jacob isp_handle_ctio7(ispsoftc_t *isp, ct7_entry_t *ct) 171210365e5aSMatt Jacob { 171310365e5aSMatt Jacob void *xs; 171410365e5aSMatt Jacob int pl = ISP_LOGTDEBUG2; 171510365e5aSMatt Jacob char *fmsg = NULL; 171610365e5aSMatt Jacob 171710365e5aSMatt Jacob if (ct->ct_syshandle) { 171810365e5aSMatt Jacob xs = isp_find_xs_tgt(isp, ct->ct_syshandle); 171910365e5aSMatt Jacob if (xs == NULL) { 172010365e5aSMatt Jacob pl = ISP_LOGALL; 172110365e5aSMatt Jacob } 172210365e5aSMatt Jacob } else { 172310365e5aSMatt Jacob xs = NULL; 172410365e5aSMatt Jacob } 172510365e5aSMatt Jacob 172610365e5aSMatt Jacob switch (ct->ct_nphdl) { 172710365e5aSMatt Jacob case CT7_BUS_ERROR: 172810365e5aSMatt Jacob isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error"); 172910365e5aSMatt Jacob /* FALL Through */ 173010365e5aSMatt Jacob case CT7_DATA_OVER: 173110365e5aSMatt Jacob case CT7_DATA_UNDER: 173210365e5aSMatt Jacob case CT7_OK: 173310365e5aSMatt Jacob /* 173410365e5aSMatt Jacob * There are generally 2 possibilities as to why we'd get 173510365e5aSMatt Jacob * this condition: 173610365e5aSMatt Jacob * We sent or received data. 173710365e5aSMatt Jacob * We sent status & command complete. 173810365e5aSMatt Jacob */ 173910365e5aSMatt Jacob 174010365e5aSMatt Jacob break; 174110365e5aSMatt Jacob 174210365e5aSMatt Jacob case CT7_RESET: 174310365e5aSMatt Jacob if (fmsg == NULL) { 174410365e5aSMatt Jacob fmsg = "LIP Reset"; 174510365e5aSMatt Jacob } 174610365e5aSMatt Jacob /*FALLTHROUGH*/ 174710365e5aSMatt Jacob case CT7_ABORTED: 174810365e5aSMatt Jacob /* 174910365e5aSMatt Jacob * When an Abort message is received the firmware goes to 175010365e5aSMatt Jacob * Bus Free and returns all outstanding CTIOs with the status 175110365e5aSMatt Jacob * set, then sends us an Immediate Notify entry. 175210365e5aSMatt Jacob */ 175310365e5aSMatt Jacob if (fmsg == NULL) { 175410365e5aSMatt Jacob fmsg = "ABORT"; 175510365e5aSMatt Jacob } 17562df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "CTIO7 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid); 175710365e5aSMatt Jacob break; 175810365e5aSMatt Jacob 175910365e5aSMatt Jacob case CT7_TIMEOUT: 176010365e5aSMatt Jacob if (fmsg == NULL) { 176110365e5aSMatt Jacob fmsg = "command"; 176210365e5aSMatt Jacob } 17632df76c16SMatt Jacob isp_prt(isp, ISP_LOGWARN, "Firmware timed out on %s", fmsg); 176410365e5aSMatt Jacob break; 176510365e5aSMatt Jacob 176610365e5aSMatt Jacob case CT7_ERR: 176710365e5aSMatt Jacob fmsg = "Completed with Error"; 176810365e5aSMatt Jacob /*FALLTHROUGH*/ 176910365e5aSMatt Jacob case CT7_LOGOUT: 177010365e5aSMatt Jacob if (fmsg == NULL) { 177110365e5aSMatt Jacob fmsg = "Port Logout"; 177210365e5aSMatt Jacob } 177310365e5aSMatt Jacob /*FALLTHROUGH*/ 177410365e5aSMatt Jacob case CT7_PORTUNAVAIL: 177510365e5aSMatt Jacob if (fmsg == NULL) { 177610365e5aSMatt Jacob fmsg = "Port not available"; 177710365e5aSMatt Jacob } 177810365e5aSMatt Jacob /*FALLTHROUGH*/ 177910365e5aSMatt Jacob case CT7_PORTCHANGED: 178010365e5aSMatt Jacob if (fmsg == NULL) { 178110365e5aSMatt Jacob fmsg = "Port Changed"; 178210365e5aSMatt Jacob } 178310365e5aSMatt Jacob isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg); 178410365e5aSMatt Jacob break; 178510365e5aSMatt Jacob 178610365e5aSMatt Jacob case CT7_INVRXID: 178710365e5aSMatt Jacob /* 178810365e5aSMatt Jacob * CTIO rejected by the firmware because an invalid RX_ID. 178910365e5aSMatt Jacob * Just print a message. 179010365e5aSMatt Jacob */ 17912df76c16SMatt Jacob isp_prt(isp, ISP_LOGWARN, "CTIO7 completed with Invalid RX_ID 0x%x", ct->ct_rxid); 179210365e5aSMatt Jacob break; 179310365e5aSMatt Jacob 179410365e5aSMatt Jacob case CT7_REASSY_ERR: 179510365e5aSMatt Jacob isp_prt(isp, ISP_LOGWARN, "reassembly error"); 179610365e5aSMatt Jacob break; 179710365e5aSMatt Jacob 179810365e5aSMatt Jacob case CT7_SRR: 1799387d8239SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "SRR received"); 180010365e5aSMatt Jacob break; 180110365e5aSMatt Jacob 180210365e5aSMatt Jacob default: 18032df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "Unknown CTIO7 status 0x%x", ct->ct_nphdl); 180410365e5aSMatt Jacob break; 180510365e5aSMatt Jacob } 180610365e5aSMatt Jacob 180710365e5aSMatt Jacob if (xs == NULL) { 180810365e5aSMatt Jacob /* 180910365e5aSMatt Jacob * There may be more than one CTIO for a data transfer, 181010365e5aSMatt Jacob * or this may be a status CTIO we're not monitoring. 181110365e5aSMatt Jacob * 181210365e5aSMatt Jacob * The assumption is that they'll all be returned in the 181310365e5aSMatt Jacob * order we got them. 181410365e5aSMatt Jacob */ 181510365e5aSMatt Jacob if (ct->ct_syshandle == 0) { 181610365e5aSMatt Jacob if (ct->ct_flags & CT7_TERMINATE) { 1817387d8239SMatt Jacob isp_prt(isp, ISP_LOGINFO, "termination of [RX_ID 0x%x] complete", ct->ct_rxid); 181810365e5aSMatt Jacob } else if ((ct->ct_flags & CT7_SENDSTATUS) == 0) { 18192df76c16SMatt Jacob isp_prt(isp, pl, "intermediate CTIO completed ok"); 182010365e5aSMatt Jacob } else { 18212df76c16SMatt Jacob isp_prt(isp, pl, "unmonitored CTIO completed ok"); 182210365e5aSMatt Jacob } 182310365e5aSMatt Jacob } else { 18242df76c16SMatt Jacob isp_prt(isp, pl, "NO xs for CTIO (handle 0x%x) status 0x%x", ct->ct_syshandle, ct->ct_nphdl); 182510365e5aSMatt Jacob } 182610365e5aSMatt Jacob } else { 18272df76c16SMatt Jacob if ((ct->ct_flags & CT7_DATAMASK) != CT7_NO_DATA) { 182810365e5aSMatt Jacob ISP_DMAFREE(isp, xs, ct->ct_syshandle); 182910365e5aSMatt Jacob } 18302df76c16SMatt Jacob if (ct->ct_flags & CT7_SENDSTATUS) { 183110365e5aSMatt Jacob /* 183210365e5aSMatt Jacob * Sent status and command complete. 183310365e5aSMatt Jacob * 183410365e5aSMatt Jacob * We're now really done with this command, so we 183510365e5aSMatt Jacob * punt to the platform dependent layers because 183610365e5aSMatt Jacob * only there can we do the appropriate command 183710365e5aSMatt Jacob * complete thread synchronization. 183810365e5aSMatt Jacob */ 183910365e5aSMatt Jacob isp_prt(isp, pl, "status CTIO complete"); 184010365e5aSMatt Jacob } else { 184110365e5aSMatt Jacob /* 184210365e5aSMatt Jacob * Final CTIO completed. Release DMA resources and 184310365e5aSMatt Jacob * notify platform dependent layers. 184410365e5aSMatt Jacob */ 184510365e5aSMatt Jacob isp_prt(isp, pl, "data CTIO complete"); 184610365e5aSMatt Jacob } 18472df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_ACTION, ct); 184810365e5aSMatt Jacob /* 184910365e5aSMatt Jacob * The platform layer will destroy the handle if appropriate. 185010365e5aSMatt Jacob */ 185110365e5aSMatt Jacob } 185210365e5aSMatt Jacob } 18532df76c16SMatt Jacob 18542df76c16SMatt Jacob static void 18552df76c16SMatt Jacob isp_handle_24xx_inotify(ispsoftc_t *isp, in_fcentry_24xx_t *inot_24xx) 18562df76c16SMatt Jacob { 18572df76c16SMatt Jacob uint8_t ochan, chan, lochan, hichan; 18582df76c16SMatt Jacob 18592df76c16SMatt Jacob /* 18602df76c16SMatt Jacob * Check to see whether we got a wildcard channel. 18612df76c16SMatt Jacob * If so, we have to iterate over all channels. 18622df76c16SMatt Jacob */ 18632df76c16SMatt Jacob ochan = chan = ISP_GET_VPIDX(isp, inot_24xx->in_vpidx); 18642df76c16SMatt Jacob if (chan == 0xff) { 18652df76c16SMatt Jacob lochan = 0; 18662df76c16SMatt Jacob hichan = isp->isp_nchan; 18672df76c16SMatt Jacob } else { 18682df76c16SMatt Jacob if (chan >= isp->isp_nchan) { 18692df76c16SMatt Jacob char buf[64]; 18702df76c16SMatt Jacob ISP_SNPRINTF(buf, sizeof buf, "%s: bad channel %d for status 0x%x", __func__, chan, inot_24xx->in_status); 18712df76c16SMatt Jacob isp_print_bytes(isp, buf, QENTRY_LEN, inot_24xx); 1872387d8239SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot_24xx); 18732df76c16SMatt Jacob return; 18742df76c16SMatt Jacob } 18752df76c16SMatt Jacob lochan = chan; 18762df76c16SMatt Jacob hichan = chan + 1; 18772df76c16SMatt Jacob } 18782df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG1, "%s: Immediate Notify Channels %d..%d status=0x%x seqid=0x%x", __func__, lochan, hichan-1, inot_24xx->in_status, inot_24xx->in_rxid); 18792df76c16SMatt Jacob for (chan = lochan; chan < hichan; chan++) { 18802df76c16SMatt Jacob switch (inot_24xx->in_status) { 18812df76c16SMatt Jacob case IN24XX_LIP_RESET: 18822df76c16SMatt Jacob case IN24XX_LINK_RESET: 18832df76c16SMatt Jacob case IN24XX_PORT_LOGOUT: 18842df76c16SMatt Jacob case IN24XX_PORT_CHANGED: 18852df76c16SMatt Jacob case IN24XX_LINK_FAILED: 18862df76c16SMatt Jacob case IN24XX_SRR_RCVD: 18872df76c16SMatt Jacob case IN24XX_ELS_RCVD: 1888387d8239SMatt Jacob inot_24xx->in_reserved = 0; /* clear this for later usage */ 18892df76c16SMatt Jacob inot_24xx->in_vpidx = chan; 18902df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_ACTION, inot_24xx); 18912df76c16SMatt Jacob break; 18922df76c16SMatt Jacob default: 18932df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, "%s: unhandled status (0x%x) for chan %d", __func__, inot_24xx->in_status, chan); 1894387d8239SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot_24xx); 18952df76c16SMatt Jacob break; 18962df76c16SMatt Jacob } 18972df76c16SMatt Jacob } 18982df76c16SMatt Jacob inot_24xx->in_vpidx = ochan; 18992df76c16SMatt Jacob } 1900ea49c6e4SMatt Jacob #endif 1901