1098ca2bdSWarner Losh /*-
2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3718cf2ccSPedro F. Giffuni *
41b760be4SAlexander Motin * Copyright (c) 2009-2020 Alexander Motin <mav@FreeBSD.org>
52df76c16SMatt Jacob * Copyright (c) 1997-2009 by Matthew Jacob
6ea49c6e4SMatt Jacob * All rights reserved.
7ea49c6e4SMatt Jacob *
8ea49c6e4SMatt Jacob * Redistribution and use in source and binary forms, with or without
9ea49c6e4SMatt Jacob * modification, are permitted provided that the following conditions
10ea49c6e4SMatt Jacob * are met:
11ea49c6e4SMatt Jacob *
12e48b2487SMatt Jacob * 1. Redistributions of source code must retain the above copyright
13e48b2487SMatt Jacob * notice, this list of conditions and the following disclaimer.
14e48b2487SMatt Jacob * 2. Redistributions in binary form must reproduce the above copyright
15e48b2487SMatt Jacob * notice, this list of conditions and the following disclaimer in the
16e48b2487SMatt Jacob * documentation and/or other materials provided with the distribution.
17e48b2487SMatt Jacob *
18e48b2487SMatt Jacob * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19ea49c6e4SMatt Jacob * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20ea49c6e4SMatt Jacob * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21e48b2487SMatt Jacob * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
22e48b2487SMatt Jacob * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23ea49c6e4SMatt Jacob * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24ea49c6e4SMatt Jacob * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25ea49c6e4SMatt Jacob * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26ea49c6e4SMatt Jacob * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27ea49c6e4SMatt Jacob * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28ea49c6e4SMatt Jacob * SUCH DAMAGE.
292df76c16SMatt Jacob *
30ea49c6e4SMatt Jacob */
31ea49c6e4SMatt Jacob /*
321b760be4SAlexander Motin * Machine and OS Independent Target Mode Code for the Qlogic FC adapters.
33e48b2487SMatt Jacob */
34e48b2487SMatt Jacob /*
3575c1e828SMatt Jacob * Bug fixes gratefully acknowledged from:
3675c1e828SMatt Jacob * Oded Kedem <oded@kashya.com>
3775c1e828SMatt Jacob */
3875c1e828SMatt Jacob /*
39ea49c6e4SMatt Jacob * Include header file appropriate for platform we're building on.
40ea49c6e4SMatt Jacob */
41ea49c6e4SMatt Jacob
42ea49c6e4SMatt Jacob #ifdef __NetBSD__
43ea49c6e4SMatt Jacob #include <dev/ic/isp_netbsd.h>
44ea49c6e4SMatt Jacob #endif
45ea49c6e4SMatt Jacob #ifdef __FreeBSD__
46799881e0SMatt Jacob #include <sys/cdefs.h>
47ea49c6e4SMatt Jacob #include <dev/isp/isp_freebsd.h>
48ea49c6e4SMatt Jacob #endif
49ea49c6e4SMatt Jacob #ifdef __OpenBSD__
50ea49c6e4SMatt Jacob #include <dev/ic/isp_openbsd.h>
51ea49c6e4SMatt Jacob #endif
52ea49c6e4SMatt Jacob #ifdef __linux__
53ea49c6e4SMatt Jacob #include "isp_linux.h"
54ea49c6e4SMatt Jacob #endif
55ea49c6e4SMatt Jacob
56ea49c6e4SMatt Jacob #ifdef ISP_TARGET_MODE
5710365e5aSMatt Jacob static void isp_got_tmf_24xx(ispsoftc_t *, at7_entry_t *);
58981ffc4eSAlexander Motin static void isp_handle_abts(ispsoftc_t *, abts_t *);
5910365e5aSMatt Jacob static void isp_handle_ctio7(ispsoftc_t *, ct7_entry_t *);
6087b04de6SAlexander Motin static void isp_handle_notify_24xx(ispsoftc_t *, in_fcentry_24xx_t *);
61ea49c6e4SMatt Jacob
62ea49c6e4SMatt Jacob /*
63ea49c6e4SMatt Jacob * The Qlogic driver gets an interrupt to look at response queue entries.
64ea49c6e4SMatt Jacob * Some of these are status completions for initiatior mode commands, but
65ea49c6e4SMatt Jacob * if target mode is enabled, we get a whole wad of response queue entries
66ea49c6e4SMatt Jacob * to be handled here.
67ea49c6e4SMatt Jacob *
68ea49c6e4SMatt Jacob * Basically the split into 3 main groups: Lun Enable/Modification responses,
69ea49c6e4SMatt Jacob * SCSI Command processing, and Immediate Notification events.
70ea49c6e4SMatt Jacob *
71ea49c6e4SMatt Jacob * You start by writing a request queue entry to enable target mode (and
72ea49c6e4SMatt Jacob * establish some resource limitations which you can modify later).
73ea49c6e4SMatt Jacob * The f/w responds with a LUN ENABLE or LUN MODIFY response with
74ea49c6e4SMatt Jacob * the status of this action. If the enable was successful, you can expect...
75ea49c6e4SMatt Jacob *
76ea49c6e4SMatt Jacob * Response queue entries with SCSI commands encapsulate show up in an ATIO
77ea49c6e4SMatt Jacob * (Accept Target IO) type- sometimes with enough info to stop the command at
78ea49c6e4SMatt Jacob * this level. Ultimately the driver has to feed back to the f/w's request
79ea49c6e4SMatt Jacob * queue a sequence of CTIOs (continue target I/O) that describe data to
80ea49c6e4SMatt Jacob * be moved and/or status to be sent) and finally finishing with sending
81ea49c6e4SMatt Jacob * to the f/w's response queue an ATIO which then completes the handshake
82ea49c6e4SMatt Jacob * with the f/w for that command. There's a lot of variations on this theme,
83ea49c6e4SMatt Jacob * including flags you can set in the CTIO for the Qlogic 2X00 fibre channel
84ea49c6e4SMatt Jacob * cards that 'auto-replenish' the f/w's ATIO count, but this is the basic
85ea49c6e4SMatt Jacob * gist of it.
86ea49c6e4SMatt Jacob *
87ea49c6e4SMatt Jacob * The third group that can show up in the response queue are Immediate
88ea49c6e4SMatt Jacob * Notification events. These include things like notifications of SCSI bus
89ea49c6e4SMatt Jacob * resets, or Bus Device Reset messages or other messages received. This
90f09deb69SJeroen Ruigrok van der Werven * a classic oddbins area. It can get a little weird because you then turn
91ea49c6e4SMatt Jacob * around and acknowledge the Immediate Notify by writing an entry onto the
92ea49c6e4SMatt Jacob * request queue and then the f/w turns around and gives you an acknowledgement
93ea49c6e4SMatt Jacob * to *your* acknowledgement on the response queue (the idea being to let
94ea49c6e4SMatt Jacob * the f/w tell you when the event is *really* over I guess).
95ea49c6e4SMatt Jacob *
96ea49c6e4SMatt Jacob */
97ea49c6e4SMatt Jacob
98ea49c6e4SMatt Jacob
99ea49c6e4SMatt Jacob /*
100ea49c6e4SMatt Jacob * A new response queue entry has arrived. The interrupt service code
101ea49c6e4SMatt Jacob * has already swizzled it into the platform dependent from canonical form.
102ea49c6e4SMatt Jacob *
103ea49c6e4SMatt Jacob * Because of the way this driver is designed, unfortunately most of the
104ea49c6e4SMatt Jacob * actual synchronization work has to be done in the platform specific
105ea49c6e4SMatt Jacob * code- we have no synchroniation primitives in the common code.
106ea49c6e4SMatt Jacob */
107ea49c6e4SMatt Jacob
108ea49c6e4SMatt Jacob int
isp_target_notify(ispsoftc_t * isp,void * vptr,uint32_t * optrp,uint16_t ql)109b8e2395eSAlexander Motin isp_target_notify(ispsoftc_t *isp, void *vptr, uint32_t *optrp, uint16_t ql)
110ea49c6e4SMatt Jacob {
111ea49c6e4SMatt Jacob union {
11210365e5aSMatt Jacob at7_entry_t *at7iop;
11310365e5aSMatt Jacob ct7_entry_t *ct7iop;
11410365e5aSMatt Jacob in_fcentry_24xx_t *inot_24xx;
11510365e5aSMatt Jacob na_fcentry_24xx_t *nack_24xx;
116ea49c6e4SMatt Jacob isphdr_t *hp;
11710365e5aSMatt Jacob abts_t *abts;
11810365e5aSMatt Jacob abts_rsp_t *abts_rsp;
119ea49c6e4SMatt Jacob void * *vp;
12010365e5aSMatt Jacob #define at7iop unp.at7iop
12110365e5aSMatt Jacob #define ct7iop unp.ct7iop
12210365e5aSMatt Jacob #define inot_24xx unp.inot_24xx
12310365e5aSMatt Jacob #define nack_24xx unp.nack_24xx
12410365e5aSMatt Jacob #define abts unp.abts
12510365e5aSMatt Jacob #define abts_rsp unp.abts_rsp
126ea49c6e4SMatt Jacob #define hdrp unp.hp
127ea49c6e4SMatt Jacob } unp;
1281dae40ebSMatt Jacob uint8_t local[QENTRY_LEN];
1295a5632c2SAlexander Motin int type, len, level, rval = 1;
130ea49c6e4SMatt Jacob
1314fd13c1bSMatt Jacob type = isp_get_response_type(isp, (isphdr_t *)vptr);
132ea49c6e4SMatt Jacob unp.vp = vptr;
133ea49c6e4SMatt Jacob
134156c1ebeSAlexander Motin if (isp->isp_dblev & ISP_LOGTDEBUG2)
135156c1ebeSAlexander Motin isp_print_qentry(isp, __func__, *optrp, vptr);
136ea49c6e4SMatt Jacob
1374fd13c1bSMatt Jacob switch (type) {
138ea49c6e4SMatt Jacob case RQSTYPE_ATIO:
13910365e5aSMatt Jacob isp_get_atio7(isp, at7iop, (at7_entry_t *) local);
14010365e5aSMatt Jacob at7iop = (at7_entry_t *) local;
14110365e5aSMatt Jacob /*
1422df76c16SMatt Jacob * Check for and do something with commands whose
1432df76c16SMatt Jacob * IULEN extends past a single queue entry.
14410365e5aSMatt Jacob */
145d2a2ccbcSAlexander Motin len = at7iop->at_ta_len & 0x0fff;
14610365e5aSMatt Jacob if (len > (QENTRY_LEN - 8)) {
14710365e5aSMatt Jacob len -= (QENTRY_LEN - 8);
1482df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, "long IU length (%d) ignored", len);
14910365e5aSMatt Jacob while (len > 0) {
150b8e2395eSAlexander Motin *optrp = ISP_NXT_QENTRY(*optrp, ql);
15110365e5aSMatt Jacob len -= QENTRY_LEN;
15210365e5aSMatt Jacob }
15310365e5aSMatt Jacob }
15410365e5aSMatt Jacob /*
15510365e5aSMatt Jacob * Check for a task management function
15610365e5aSMatt Jacob */
15710365e5aSMatt Jacob if (at7iop->at_cmnd.fcp_cmnd_task_management) {
15810365e5aSMatt Jacob isp_got_tmf_24xx(isp, at7iop);
15910365e5aSMatt Jacob break;
16010365e5aSMatt Jacob }
16110365e5aSMatt Jacob /*
16210365e5aSMatt Jacob * Just go straight to outer layer for this one.
16310365e5aSMatt Jacob */
1642df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_ACTION, local);
165ea49c6e4SMatt Jacob break;
16610365e5aSMatt Jacob
16710365e5aSMatt Jacob case RQSTYPE_CTIO7:
16810365e5aSMatt Jacob isp_get_ctio7(isp, ct7iop, (ct7_entry_t *) local);
16910365e5aSMatt Jacob isp_handle_ctio7(isp, (ct7_entry_t *) local);
17010365e5aSMatt Jacob break;
17110365e5aSMatt Jacob
172ea49c6e4SMatt Jacob case RQSTYPE_NOTIFY:
1732df76c16SMatt Jacob isp_get_notify_24xx(isp, inot_24xx, (in_fcentry_24xx_t *)local);
1745a5632c2SAlexander Motin isp_handle_notify_24xx(isp, (in_fcentry_24xx_t *)local);
175df9c69d2SAlexander Motin break;
176ea49c6e4SMatt Jacob
177ea49c6e4SMatt Jacob case RQSTYPE_NOTIFY_ACK:
178ea49c6e4SMatt Jacob /*
179ea49c6e4SMatt Jacob * The ISP is acknowledging our acknowledgement of an
180ea49c6e4SMatt Jacob * Immediate Notify entry for some asynchronous event.
181ea49c6e4SMatt Jacob */
1822df76c16SMatt Jacob isp_get_notify_ack_24xx(isp, nack_24xx, (na_fcentry_24xx_t *) local);
18310365e5aSMatt Jacob nack_24xx = (na_fcentry_24xx_t *) local;
1841b760be4SAlexander Motin if (nack_24xx->na_status != NA_OK)
18510365e5aSMatt Jacob level = ISP_LOGINFO;
1861b760be4SAlexander Motin else
18710365e5aSMatt Jacob level = ISP_LOGTDEBUG1;
1882df76c16SMatt 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);
189ea49c6e4SMatt Jacob break;
19010365e5aSMatt Jacob
19110365e5aSMatt Jacob case RQSTYPE_ABTS_RCVD:
19210365e5aSMatt Jacob isp_get_abts(isp, abts, (abts_t *)local);
193981ffc4eSAlexander Motin isp_handle_abts(isp, (abts_t *)local);
19410365e5aSMatt Jacob break;
19510365e5aSMatt Jacob case RQSTYPE_ABTS_RSP:
19610365e5aSMatt Jacob isp_get_abts_rsp(isp, abts_rsp, (abts_rsp_t *)local);
19710365e5aSMatt Jacob abts_rsp = (abts_rsp_t *) local;
1981b760be4SAlexander Motin if (abts_rsp->abts_rsp_status)
19910365e5aSMatt Jacob level = ISP_LOGINFO;
2001b760be4SAlexander Motin else
20110365e5aSMatt Jacob level = ISP_LOGTDEBUG0;
2022df76c16SMatt 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,
2032df76c16SMatt Jacob abts_rsp->abts_rsp_payload.rsp.subcode1, abts_rsp->abts_rsp_payload.rsp.subcode2);
20410365e5aSMatt Jacob break;
205ea49c6e4SMatt Jacob default:
2062df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "%s: unknown entry type 0x%x", __func__, type);
207e63442b6SMatt Jacob rval = 0;
208ea49c6e4SMatt Jacob break;
209ea49c6e4SMatt Jacob }
21010365e5aSMatt Jacob #undef at7iop
21110365e5aSMatt Jacob #undef ct7iop
21210365e5aSMatt Jacob #undef inot_24xx
21310365e5aSMatt Jacob #undef hack_24xx
21410365e5aSMatt Jacob #undef abts
21510365e5aSMatt Jacob #undef abts_rsp
216ea49c6e4SMatt Jacob #undef hdrp
217ea49c6e4SMatt Jacob return (rval);
218ea49c6e4SMatt Jacob }
219ea49c6e4SMatt Jacob
220ea49c6e4SMatt Jacob /*
221ea49c6e4SMatt Jacob * Command completion- both for handling cases of no resources or
222ea49c6e4SMatt Jacob * no blackhole driver, or other cases where we have to, inline,
223ea49c6e4SMatt Jacob * finish the command sanely, or for normal command completion.
224ea49c6e4SMatt Jacob *
225ea49c6e4SMatt Jacob * The 'completion' code value has the scsi status byte in the low 8 bits.
226ea49c6e4SMatt Jacob * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have
227ea49c6e4SMatt Jacob * the sense key and bits 16..23 have the ASCQ and bits 24..31 have the ASC
228ea49c6e4SMatt Jacob * values.
229ea49c6e4SMatt Jacob *
230ea49c6e4SMatt Jacob * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't
231b25bcef8SMatt Jacob * NB: inline SCSI sense reporting. As such, we lose this information. XXX.
232ea49c6e4SMatt Jacob *
233ea49c6e4SMatt Jacob * For both parallel && fibre channel, we use the feature that does
234ea49c6e4SMatt Jacob * an automatic resource autoreplenish so we don't have then later do
235ea49c6e4SMatt Jacob * put of an atio to replenish the f/w's resource count.
236ea49c6e4SMatt Jacob */
237ea49c6e4SMatt Jacob
238ea49c6e4SMatt Jacob int
isp_endcmd(ispsoftc_t * isp,...)2392df76c16SMatt Jacob isp_endcmd(ispsoftc_t *isp, ...)
240ea49c6e4SMatt Jacob {
2412df76c16SMatt Jacob uint32_t code, hdl;
2422df76c16SMatt Jacob uint8_t sts;
2431b760be4SAlexander Motin at7_entry_t *aep;
2441b760be4SAlexander Motin ct7_entry_t _ctio7, *cto = &_ctio7;
2452df76c16SMatt Jacob va_list ap;
2468290ea90SAlexander Motin int vpidx, nphdl;
247ea49c6e4SMatt Jacob
2482df76c16SMatt Jacob va_start(ap, isp);
2492df76c16SMatt Jacob aep = va_arg(ap, at7_entry_t *);
2502df76c16SMatt Jacob nphdl = va_arg(ap, int);
2512df76c16SMatt Jacob /*
2522df76c16SMatt Jacob * Note that vpidx may equal 0xff (unknown) here
2532df76c16SMatt Jacob */
2542df76c16SMatt Jacob vpidx = va_arg(ap, int);
2552df76c16SMatt Jacob code = va_arg(ap, uint32_t);
2562df76c16SMatt Jacob hdl = va_arg(ap, uint32_t);
2572df76c16SMatt Jacob va_end(ap);
2582df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "%s: [RX_ID 0x%x] chan %d code %x", __func__, aep->at_rxid, vpidx, code);
2592df76c16SMatt Jacob
2602df76c16SMatt Jacob sts = code & 0xff;
2611b760be4SAlexander Motin ISP_MEMZERO(cto, sizeof(*cto));
26210365e5aSMatt Jacob cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
26310365e5aSMatt Jacob cto->ct_header.rqs_entry_count = 1;
2642df76c16SMatt Jacob cto->ct_nphdl = nphdl;
26510365e5aSMatt Jacob cto->ct_rxid = aep->at_rxid;
2662df76c16SMatt Jacob cto->ct_iid_lo = (aep->at_hdr.s_id[1] << 8) | aep->at_hdr.s_id[2];
26710365e5aSMatt Jacob cto->ct_iid_hi = aep->at_hdr.s_id[0];
26810365e5aSMatt Jacob cto->ct_oxid = aep->at_hdr.ox_id;
26910365e5aSMatt Jacob cto->ct_scsi_status = sts;
2702df76c16SMatt Jacob cto->ct_vpidx = vpidx;
2712df76c16SMatt Jacob cto->ct_flags = CT7_NOACK;
2722df76c16SMatt Jacob if (code & ECMD_TERMINATE) {
2732df76c16SMatt Jacob cto->ct_flags |= CT7_TERMINATE;
2742df76c16SMatt Jacob } else if (code & ECMD_SVALID) {
2752df76c16SMatt Jacob cto->ct_flags |= CT7_FLAG_MODE1 | CT7_SENDSTATUS;
2762df76c16SMatt Jacob cto->ct_scsi_status |= (FCP_SNSLEN_VALID << 8);
277352427b3SAlexander Motin cto->ct_senselen = min(16, MAXRESPLEN_24XX);
2782df76c16SMatt Jacob ISP_MEMZERO(cto->rsp.m1.ct_resp, sizeof (cto->rsp.m1.ct_resp));
27910365e5aSMatt Jacob cto->rsp.m1.ct_resp[0] = 0xf0;
28010365e5aSMatt Jacob cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
28110365e5aSMatt Jacob cto->rsp.m1.ct_resp[7] = 8;
282387d8239SMatt Jacob cto->rsp.m1.ct_resp[12] = (code >> 16) & 0xff;
283387d8239SMatt Jacob cto->rsp.m1.ct_resp[13] = (code >> 24) & 0xff;
284352427b3SAlexander Motin } else if (code & ECMD_RVALID) {
285352427b3SAlexander Motin cto->ct_flags |= CT7_FLAG_MODE1 | CT7_SENDSTATUS;
286352427b3SAlexander Motin cto->ct_scsi_status |= (FCP_RSPLEN_VALID << 8);
287352427b3SAlexander Motin cto->rsp.m1.ct_resplen = 4;
288352427b3SAlexander Motin ISP_MEMZERO(cto->rsp.m1.ct_resp, sizeof (cto->rsp.m1.ct_resp));
289352427b3SAlexander Motin cto->rsp.m1.ct_resp[0] = (code >> 12) & 0xf;
290352427b3SAlexander Motin cto->rsp.m1.ct_resp[1] = (code >> 16) & 0xff;
291352427b3SAlexander Motin cto->rsp.m1.ct_resp[2] = (code >> 24) & 0xff;
292352427b3SAlexander Motin cto->rsp.m1.ct_resp[3] = 0;
2932df76c16SMatt Jacob } else {
2942df76c16SMatt Jacob cto->ct_flags |= CT7_FLAG_MODE1 | CT7_SENDSTATUS;
29510365e5aSMatt Jacob }
296a6036a44SAlexander Motin if (aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl != 0) {
29710365e5aSMatt Jacob cto->ct_resid = aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl;
2982df76c16SMatt Jacob cto->ct_scsi_status |= (FCP_RESID_UNDERFLOW << 8);
2992df76c16SMatt Jacob }
30010365e5aSMatt Jacob cto->ct_syshandle = hdl;
301156c1ebeSAlexander Motin return (isp_send_entry(isp, cto));
302ea49c6e4SMatt Jacob }
303ea49c6e4SMatt Jacob
3049cd7268eSMatt Jacob /*
3059cd7268eSMatt Jacob * These are either broadcast events or specifically CTIO fast completion
3069cd7268eSMatt Jacob */
3072df76c16SMatt Jacob
3089c2e9bcfSAlexander Motin void
isp_target_async(ispsoftc_t * isp,int bus,int event)3099cd7268eSMatt Jacob isp_target_async(ispsoftc_t *isp, int bus, int event)
310ea49c6e4SMatt Jacob {
3112df76c16SMatt Jacob isp_notify_t notify;
312e5265237SMatt Jacob
3132df76c16SMatt Jacob ISP_MEMZERO(¬ify, sizeof (isp_notify_t));
314e5265237SMatt Jacob notify.nt_hba = isp;
3152df76c16SMatt Jacob notify.nt_wwn = INI_ANY;
3162df76c16SMatt Jacob notify.nt_nphdl = NIL_HANDLE;
3172df76c16SMatt Jacob notify.nt_sid = PORT_ANY;
3182df76c16SMatt Jacob notify.nt_did = PORT_ANY;
3192df76c16SMatt Jacob notify.nt_tgt = TGT_ANY;
3202df76c16SMatt Jacob notify.nt_channel = bus;
321e5265237SMatt Jacob notify.nt_lun = LUN_ANY;
322e5265237SMatt Jacob notify.nt_tagval = TAG_ANY;
3232df76c16SMatt Jacob notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32);
324ea49c6e4SMatt Jacob
325ea49c6e4SMatt Jacob switch (event) {
326e5265237SMatt Jacob case ASYNC_LOOP_UP:
327e5265237SMatt Jacob case ASYNC_PTPMODE:
3282df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "%s: LOOP UP", __func__);
329e5265237SMatt Jacob notify.nt_ncode = NT_LINK_UP;
3302df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
331e5265237SMatt Jacob break;
332e5265237SMatt Jacob case ASYNC_LOOP_DOWN:
3332df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "%s: LOOP DOWN", __func__);
334e5265237SMatt Jacob notify.nt_ncode = NT_LINK_DOWN;
3352df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
336e5265237SMatt Jacob break;
33710365e5aSMatt Jacob case ASYNC_LIP_ERROR:
338e2929f5fSAlexander Motin case ASYNC_LIP_NOS_OLS_RECV:
339ea49c6e4SMatt Jacob case ASYNC_LIP_OCCURRED:
34023ac1fceSMatt Jacob case ASYNC_LOOP_RESET:
3412df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "%s: LIP RESET", __func__);
342e5265237SMatt Jacob notify.nt_ncode = NT_LIP_RESET;
3432df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
344e5265237SMatt Jacob break;
345ea49c6e4SMatt Jacob default:
3462df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "%s: unknown event 0x%x", __func__, event);
347ea49c6e4SMatt Jacob break;
348ea49c6e4SMatt Jacob }
349ea49c6e4SMatt Jacob }
350ea49c6e4SMatt Jacob
35110365e5aSMatt Jacob static void
isp_got_tmf_24xx(ispsoftc_t * isp,at7_entry_t * aep)35210365e5aSMatt Jacob isp_got_tmf_24xx(ispsoftc_t *isp, at7_entry_t *aep)
35310365e5aSMatt Jacob {
3542df76c16SMatt Jacob isp_notify_t notify;
35515c62456SAlexander Motin static const char f1[] = "%s from PortID 0x%06x lun %jx seq 0x%08x";
35615c62456SAlexander Motin static const char f2[] = "unknown Task Flag 0x%x lun %jx PortID 0x%x tag 0x%08x";
357352427b3SAlexander Motin fcportdb_t *lp;
3582df76c16SMatt Jacob uint16_t chan;
3592df76c16SMatt Jacob uint32_t sid, did;
36010365e5aSMatt Jacob
3612df76c16SMatt Jacob ISP_MEMZERO(¬ify, sizeof (isp_notify_t));
3622df76c16SMatt Jacob notify.nt_hba = isp;
3632df76c16SMatt Jacob notify.nt_wwn = INI_ANY;
36415c62456SAlexander Motin notify.nt_lun = CAM_EXTLUN_BYTE_SWIZZLE(be64dec(aep->at_cmnd.fcp_cmnd_lun));
3652df76c16SMatt Jacob notify.nt_tagval = aep->at_rxid;
3662df76c16SMatt Jacob notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32);
3672df76c16SMatt Jacob notify.nt_lreserved = aep;
368352427b3SAlexander Motin sid = (aep->at_hdr.s_id[0] << 16) | (aep->at_hdr.s_id[1] << 8) | aep->at_hdr.s_id[2];
3692df76c16SMatt Jacob did = (aep->at_hdr.d_id[0] << 16) | (aep->at_hdr.d_id[1] << 8) | aep->at_hdr.d_id[2];
37093d07b9aSAlexander Motin if (ISP_CAP_MULTI_ID(isp) && isp->isp_nchan > 1) {
37193d07b9aSAlexander Motin /* Channel has to be derived from D_ID */
37293d07b9aSAlexander Motin isp_find_chan_by_did(isp, did, &chan);
37393d07b9aSAlexander Motin if (chan == ISP_NOCHAN) {
3749c81a61eSAlexander Motin isp_prt(isp, ISP_LOGWARN,
3759c81a61eSAlexander Motin "%s: D_ID 0x%x not found on any channel",
3769c81a61eSAlexander Motin __func__, did);
3779c81a61eSAlexander Motin isp_endcmd(isp, aep, NIL_HANDLE, ISP_NOCHAN,
3789c81a61eSAlexander Motin ECMD_TERMINATE, 0);
37910365e5aSMatt Jacob return;
38010365e5aSMatt Jacob }
38193d07b9aSAlexander Motin } else {
38293d07b9aSAlexander Motin chan = 0;
38393d07b9aSAlexander Motin }
384352427b3SAlexander Motin if (isp_find_pdb_by_portid(isp, chan, sid, &lp))
385352427b3SAlexander Motin notify.nt_nphdl = lp->handle;
386352427b3SAlexander Motin else
387352427b3SAlexander Motin notify.nt_nphdl = NIL_HANDLE;
3882df76c16SMatt Jacob notify.nt_sid = sid;
3892df76c16SMatt Jacob notify.nt_did = did;
3902df76c16SMatt Jacob notify.nt_channel = chan;
391c98d2b1fSAlexander Motin if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_QUERY_TASK_SET) {
392c98d2b1fSAlexander Motin isp_prt(isp, ISP_LOGINFO, f1, "QUERY TASK SET", sid, notify.nt_lun, aep->at_rxid);
393c98d2b1fSAlexander Motin notify.nt_ncode = NT_QUERY_TASK_SET;
394c98d2b1fSAlexander Motin } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_ABORT_TASK_SET) {
3952df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET", sid, notify.nt_lun, aep->at_rxid);
3962df76c16SMatt Jacob notify.nt_ncode = NT_ABORT_TASK_SET;
3972df76c16SMatt Jacob } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_CLEAR_TASK_SET) {
3982df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET", sid, notify.nt_lun, aep->at_rxid);
3992df76c16SMatt Jacob notify.nt_ncode = NT_CLEAR_TASK_SET;
400c98d2b1fSAlexander Motin } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_QUERY_ASYNC_EVENT) {
401c98d2b1fSAlexander Motin isp_prt(isp, ISP_LOGINFO, f1, "QUERY ASYNC EVENT", sid, notify.nt_lun, aep->at_rxid);
402c98d2b1fSAlexander Motin notify.nt_ncode = NT_QUERY_ASYNC_EVENT;
4032df76c16SMatt Jacob } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_LUN_RESET) {
4042df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET", sid, notify.nt_lun, aep->at_rxid);
4052df76c16SMatt Jacob notify.nt_ncode = NT_LUN_RESET;
4062df76c16SMatt Jacob } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_TGT_RESET) {
4072df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET", sid, notify.nt_lun, aep->at_rxid);
4082df76c16SMatt Jacob notify.nt_ncode = NT_TARGET_RESET;
4092df76c16SMatt Jacob } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_CLEAR_ACA) {
4102df76c16SMatt Jacob isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA", sid, notify.nt_lun, aep->at_rxid);
4112df76c16SMatt Jacob notify.nt_ncode = NT_CLEAR_ACA;
4122df76c16SMatt Jacob } else {
4132df76c16SMatt Jacob isp_prt(isp, ISP_LOGWARN, f2, aep->at_cmnd.fcp_cmnd_task_management, notify.nt_lun, sid, aep->at_rxid);
4142df76c16SMatt Jacob notify.nt_ncode = NT_UNKNOWN;
415352427b3SAlexander Motin isp_endcmd(isp, aep, notify.nt_nphdl, chan, ECMD_RVALID | (0x4 << 12), 0);
4162df76c16SMatt Jacob return;
4172df76c16SMatt Jacob }
4182df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
41910365e5aSMatt Jacob }
42010365e5aSMatt Jacob
4212df76c16SMatt Jacob int
isp_notify_ack(ispsoftc_t * isp,void * arg)4229cd7268eSMatt Jacob isp_notify_ack(ispsoftc_t *isp, void *arg)
423ea49c6e4SMatt Jacob {
4241b760be4SAlexander Motin na_fcentry_24xx_t _na, *na = &_na;
425ea49c6e4SMatt Jacob
4262df76c16SMatt Jacob /*
4272df76c16SMatt Jacob * This is in case a Task Management Function ends up here.
4282df76c16SMatt Jacob */
4291b760be4SAlexander Motin if (((isphdr_t *)arg)->rqs_entry_type == RQSTYPE_ATIO)
4301b760be4SAlexander Motin return (isp_endcmd(isp, arg, NIL_HANDLE, 0, 0, 0));
4312df76c16SMatt Jacob
43244a2a27aSAlexander Motin in_fcentry_24xx_t *in = arg;
43344a2a27aSAlexander Motin
4341b760be4SAlexander Motin ISP_MEMZERO(na, sizeof(*na));
435387d8239SMatt Jacob na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
436387d8239SMatt Jacob na->na_header.rqs_entry_count = 1;
43710365e5aSMatt Jacob na->na_nphdl = in->in_nphdl;
438387d8239SMatt Jacob na->na_flags = in->in_flags;
43910365e5aSMatt Jacob na->na_status = in->in_status;
44010365e5aSMatt Jacob na->na_status_subcode = in->in_status_subcode;
44137a7daacSAlexander Motin na->na_fwhandle = in->in_fwhandle;
44210365e5aSMatt Jacob na->na_rxid = in->in_rxid;
44310365e5aSMatt Jacob na->na_oxid = in->in_oxid;
4442df76c16SMatt Jacob na->na_vpidx = in->in_vpidx;
44510365e5aSMatt Jacob if (in->in_status == IN24XX_SRR_RCVD) {
44610365e5aSMatt Jacob na->na_srr_rxid = in->in_srr_rxid;
44710365e5aSMatt Jacob na->na_srr_reloff_hi = in->in_srr_reloff_hi;
44810365e5aSMatt Jacob na->na_srr_reloff_lo = in->in_srr_reloff_lo;
44910365e5aSMatt Jacob na->na_srr_iu = in->in_srr_iu;
450387d8239SMatt Jacob /*
451387d8239SMatt Jacob * Whether we're accepting the SRR or rejecting
452387d8239SMatt Jacob * it is determined by looking at the in_reserved
453387d8239SMatt Jacob * field in the original notify structure.
454387d8239SMatt Jacob */
455387d8239SMatt Jacob if (in->in_reserved) {
45610365e5aSMatt Jacob na->na_srr_flags = 1;
45710365e5aSMatt Jacob na->na_srr_reject_vunique = 0;
45844a2a27aSAlexander Motin /* Unable to perform this command at this time. */
45944a2a27aSAlexander Motin na->na_srr_reject_code = 9;
46044a2a27aSAlexander Motin /* Unable to supply the requested data. */
46144a2a27aSAlexander Motin na->na_srr_reject_explanation = 0x2a;
46210365e5aSMatt Jacob }
463387d8239SMatt Jacob }
464156c1ebeSAlexander Motin return (isp_send_entry(isp, na));
4652df76c16SMatt Jacob }
4662df76c16SMatt Jacob
4672df76c16SMatt Jacob int
isp_acknak_abts(ispsoftc_t * isp,void * arg,int errno)4682df76c16SMatt Jacob isp_acknak_abts(ispsoftc_t *isp, void *arg, int errno)
4692df76c16SMatt Jacob {
4702df76c16SMatt Jacob char storage[QENTRY_LEN];
4712df76c16SMatt Jacob uint16_t tmpw;
4722df76c16SMatt Jacob uint8_t tmpb;
4732df76c16SMatt Jacob abts_t *abts = arg;
4742df76c16SMatt Jacob abts_rsp_t *rsp = (abts_rsp_t *) storage;
4752df76c16SMatt Jacob
4762df76c16SMatt Jacob if (abts->abts_header.rqs_entry_type != RQSTYPE_ABTS_RCVD) {
4772df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "%s: called for non-ABTS entry (0x%x)", __func__, abts->abts_header.rqs_entry_type);
4782df76c16SMatt Jacob return (0);
4792df76c16SMatt Jacob }
4802df76c16SMatt Jacob
4812df76c16SMatt Jacob ISP_MEMCPY(rsp, abts, QENTRY_LEN);
4822df76c16SMatt Jacob rsp->abts_rsp_header.rqs_entry_type = RQSTYPE_ABTS_RSP;
4832df76c16SMatt Jacob
4842df76c16SMatt Jacob /*
4852df76c16SMatt Jacob * Swap destination and source for response.
4862df76c16SMatt Jacob */
4872df76c16SMatt Jacob rsp->abts_rsp_r_ctl = BA_ACC;
4882df76c16SMatt Jacob tmpw = rsp->abts_rsp_did_lo;
4892df76c16SMatt Jacob tmpb = rsp->abts_rsp_did_hi;
4902df76c16SMatt Jacob rsp->abts_rsp_did_lo = rsp->abts_rsp_sid_lo;
4912df76c16SMatt Jacob rsp->abts_rsp_did_hi = rsp->abts_rsp_sid_hi;
4922df76c16SMatt Jacob rsp->abts_rsp_sid_lo = tmpw;
4932df76c16SMatt Jacob rsp->abts_rsp_sid_hi = tmpb;
4942df76c16SMatt Jacob
4952df76c16SMatt Jacob rsp->abts_rsp_f_ctl_hi ^= 0x80; /* invert Exchange Context */
4962df76c16SMatt Jacob rsp->abts_rsp_f_ctl_hi &= ~0x7f; /* clear Sequence Initiator and other bits */
4972df76c16SMatt Jacob rsp->abts_rsp_f_ctl_hi |= 0x10; /* abort the whole exchange */
4982df76c16SMatt Jacob rsp->abts_rsp_f_ctl_hi |= 0x8; /* last data frame of sequence */
4992df76c16SMatt Jacob rsp->abts_rsp_f_ctl_hi |= 0x1; /* transfer Sequence Initiative */
5002df76c16SMatt Jacob rsp->abts_rsp_f_ctl_lo = 0;
5012df76c16SMatt Jacob
5022df76c16SMatt Jacob if (errno == 0) {
5032df76c16SMatt Jacob uint16_t rx_id, ox_id;
5042df76c16SMatt Jacob
5052df76c16SMatt Jacob rx_id = rsp->abts_rsp_rx_id;
5062df76c16SMatt Jacob ox_id = rsp->abts_rsp_ox_id;
5072df76c16SMatt Jacob ISP_MEMZERO(&rsp->abts_rsp_payload.ba_acc, sizeof (rsp->abts_rsp_payload.ba_acc));
5082df76c16SMatt 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);
5092df76c16SMatt Jacob rsp->abts_rsp_payload.ba_acc.aborted_rx_id = rx_id;
5102df76c16SMatt Jacob rsp->abts_rsp_payload.ba_acc.aborted_ox_id = ox_id;
5112df76c16SMatt Jacob rsp->abts_rsp_payload.ba_acc.high_seq_cnt = 0xffff;
5122df76c16SMatt Jacob } else {
5132df76c16SMatt Jacob ISP_MEMZERO(&rsp->abts_rsp_payload.ba_rjt, sizeof (rsp->abts_rsp_payload.ba_acc));
5142df76c16SMatt Jacob switch (errno) {
5152df76c16SMatt Jacob case ENOMEM:
516387d8239SMatt Jacob rsp->abts_rsp_payload.ba_rjt.reason = 5; /* Logical Unit Busy */
5172df76c16SMatt Jacob break;
5182df76c16SMatt Jacob default:
5192df76c16SMatt Jacob rsp->abts_rsp_payload.ba_rjt.reason = 9; /* Unable to perform command request */
5202df76c16SMatt Jacob break;
5212df76c16SMatt Jacob }
5222df76c16SMatt Jacob }
523156c1ebeSAlexander Motin return (isp_send_entry(isp, rsp));
524ea49c6e4SMatt Jacob }
525ea49c6e4SMatt Jacob
526ea49c6e4SMatt Jacob static void
isp_handle_abts(ispsoftc_t * isp,abts_t * abts)527981ffc4eSAlexander Motin isp_handle_abts(ispsoftc_t *isp, abts_t *abts)
528981ffc4eSAlexander Motin {
529981ffc4eSAlexander Motin isp_notify_t notify, *nt = ¬ify;
530981ffc4eSAlexander Motin fcportdb_t *lp;
531981ffc4eSAlexander Motin uint16_t chan;
532981ffc4eSAlexander Motin uint32_t sid, did;
533981ffc4eSAlexander Motin
534981ffc4eSAlexander Motin did = (abts->abts_did_hi << 16) | abts->abts_did_lo;
535981ffc4eSAlexander Motin sid = (abts->abts_sid_hi << 16) | abts->abts_sid_lo;
536981ffc4eSAlexander Motin ISP_MEMZERO(nt, sizeof (isp_notify_t));
537981ffc4eSAlexander Motin
538981ffc4eSAlexander Motin nt->nt_hba = isp;
539981ffc4eSAlexander Motin nt->nt_did = did;
540981ffc4eSAlexander Motin nt->nt_nphdl = abts->abts_nphdl;
541981ffc4eSAlexander Motin nt->nt_sid = sid;
5429c81a61eSAlexander Motin if (ISP_CAP_MULTI_ID(isp) && isp->isp_nchan > 1) {
5439c81a61eSAlexander Motin /* Channel has to be derived from D_ID */
544981ffc4eSAlexander Motin isp_find_chan_by_did(isp, did, &chan);
545981ffc4eSAlexander Motin if (chan == ISP_NOCHAN) {
5469c81a61eSAlexander Motin isp_prt(isp, ISP_LOGWARN,
5479c81a61eSAlexander Motin "%s: D_ID 0x%x not found on any channel",
5489c81a61eSAlexander Motin __func__, did);
5499c81a61eSAlexander Motin isp_acknak_abts(isp, abts, ENXIO);
5509c81a61eSAlexander Motin return;
5519c81a61eSAlexander Motin }
5529c81a61eSAlexander Motin } else
5539c81a61eSAlexander Motin chan = 0;
554981ffc4eSAlexander Motin nt->nt_tgt = FCPARAM(isp, chan)->isp_wwpn;
5559c81a61eSAlexander Motin if (isp_find_pdb_by_handle(isp, chan, abts->abts_nphdl, &lp))
556981ffc4eSAlexander Motin nt->nt_wwn = lp->port_wwn;
5579c81a61eSAlexander Motin else
558981ffc4eSAlexander Motin nt->nt_wwn = INI_ANY;
559981ffc4eSAlexander Motin nt->nt_lun = LUN_ANY;
560981ffc4eSAlexander Motin nt->nt_need_ack = 1;
561981ffc4eSAlexander Motin nt->nt_tagval = abts->abts_rxid_task;
562981ffc4eSAlexander Motin nt->nt_tagval |= (((uint64_t) abts->abts_rxid_abts) << 32);
563981ffc4eSAlexander Motin isp_prt(isp, ISP_LOGTINFO, "[0x%x] ABTS from N-Port handle 0x%x"
564981ffc4eSAlexander Motin " Port 0x%06x for task 0x%x (rx_id 0x%04x ox_id 0x%04x)",
565981ffc4eSAlexander Motin abts->abts_rxid_abts, abts->abts_nphdl, sid, abts->abts_rxid_task,
566981ffc4eSAlexander Motin abts->abts_rx_id, abts->abts_ox_id);
567981ffc4eSAlexander Motin nt->nt_channel = chan;
568981ffc4eSAlexander Motin nt->nt_ncode = NT_ABORT_TASK;
569981ffc4eSAlexander Motin nt->nt_lreserved = abts;
570981ffc4eSAlexander Motin isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
571981ffc4eSAlexander Motin }
572981ffc4eSAlexander Motin
573981ffc4eSAlexander Motin static void
isp_handle_ctio7(ispsoftc_t * isp,ct7_entry_t * ct)57410365e5aSMatt Jacob isp_handle_ctio7(ispsoftc_t *isp, ct7_entry_t *ct)
57510365e5aSMatt Jacob {
57610365e5aSMatt Jacob void *xs;
57710365e5aSMatt Jacob int pl = ISP_LOGTDEBUG2;
57810365e5aSMatt Jacob char *fmsg = NULL;
57910365e5aSMatt Jacob
58010365e5aSMatt Jacob if (ct->ct_syshandle) {
581970ceb2fSAlexander Motin xs = isp_find_xs(isp, ct->ct_syshandle);
58210365e5aSMatt Jacob if (xs == NULL) {
58310365e5aSMatt Jacob pl = ISP_LOGALL;
58410365e5aSMatt Jacob }
58510365e5aSMatt Jacob } else {
58610365e5aSMatt Jacob xs = NULL;
58710365e5aSMatt Jacob }
58810365e5aSMatt Jacob
58910365e5aSMatt Jacob switch (ct->ct_nphdl) {
59010365e5aSMatt Jacob case CT7_BUS_ERROR:
59110365e5aSMatt Jacob isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error");
59210365e5aSMatt Jacob /* FALL Through */
59310365e5aSMatt Jacob case CT7_DATA_OVER:
59410365e5aSMatt Jacob case CT7_DATA_UNDER:
59510365e5aSMatt Jacob case CT7_OK:
59610365e5aSMatt Jacob /*
59710365e5aSMatt Jacob * There are generally 2 possibilities as to why we'd get
59810365e5aSMatt Jacob * this condition:
59910365e5aSMatt Jacob * We sent or received data.
60010365e5aSMatt Jacob * We sent status & command complete.
60110365e5aSMatt Jacob */
60210365e5aSMatt Jacob
60310365e5aSMatt Jacob break;
60410365e5aSMatt Jacob
60510365e5aSMatt Jacob case CT7_RESET:
60610365e5aSMatt Jacob if (fmsg == NULL) {
60710365e5aSMatt Jacob fmsg = "LIP Reset";
60810365e5aSMatt Jacob }
60910365e5aSMatt Jacob /*FALLTHROUGH*/
61010365e5aSMatt Jacob case CT7_ABORTED:
61110365e5aSMatt Jacob /*
61210365e5aSMatt Jacob * When an Abort message is received the firmware goes to
61310365e5aSMatt Jacob * Bus Free and returns all outstanding CTIOs with the status
61410365e5aSMatt Jacob * set, then sends us an Immediate Notify entry.
61510365e5aSMatt Jacob */
61610365e5aSMatt Jacob if (fmsg == NULL) {
61710365e5aSMatt Jacob fmsg = "ABORT";
61810365e5aSMatt Jacob }
6192df76c16SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "CTIO7 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid);
62010365e5aSMatt Jacob break;
62110365e5aSMatt Jacob
62210365e5aSMatt Jacob case CT7_TIMEOUT:
62310365e5aSMatt Jacob if (fmsg == NULL) {
62410365e5aSMatt Jacob fmsg = "command";
62510365e5aSMatt Jacob }
6262df76c16SMatt Jacob isp_prt(isp, ISP_LOGWARN, "Firmware timed out on %s", fmsg);
62710365e5aSMatt Jacob break;
62810365e5aSMatt Jacob
62910365e5aSMatt Jacob case CT7_ERR:
63010365e5aSMatt Jacob fmsg = "Completed with Error";
63110365e5aSMatt Jacob /*FALLTHROUGH*/
63210365e5aSMatt Jacob case CT7_LOGOUT:
63310365e5aSMatt Jacob if (fmsg == NULL) {
63410365e5aSMatt Jacob fmsg = "Port Logout";
63510365e5aSMatt Jacob }
63610365e5aSMatt Jacob /*FALLTHROUGH*/
63710365e5aSMatt Jacob case CT7_PORTUNAVAIL:
63810365e5aSMatt Jacob if (fmsg == NULL) {
63910365e5aSMatt Jacob fmsg = "Port not available";
64010365e5aSMatt Jacob }
64110365e5aSMatt Jacob /*FALLTHROUGH*/
64210365e5aSMatt Jacob case CT7_PORTCHANGED:
64310365e5aSMatt Jacob if (fmsg == NULL) {
64410365e5aSMatt Jacob fmsg = "Port Changed";
64510365e5aSMatt Jacob }
64610365e5aSMatt Jacob isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg);
64710365e5aSMatt Jacob break;
64810365e5aSMatt Jacob
64910365e5aSMatt Jacob case CT7_INVRXID:
65010365e5aSMatt Jacob /*
65110365e5aSMatt Jacob * CTIO rejected by the firmware because an invalid RX_ID.
65210365e5aSMatt Jacob * Just print a message.
65310365e5aSMatt Jacob */
6542df76c16SMatt Jacob isp_prt(isp, ISP_LOGWARN, "CTIO7 completed with Invalid RX_ID 0x%x", ct->ct_rxid);
65510365e5aSMatt Jacob break;
65610365e5aSMatt Jacob
65710365e5aSMatt Jacob case CT7_REASSY_ERR:
65810365e5aSMatt Jacob isp_prt(isp, ISP_LOGWARN, "reassembly error");
65910365e5aSMatt Jacob break;
66010365e5aSMatt Jacob
66110365e5aSMatt Jacob case CT7_SRR:
662387d8239SMatt Jacob isp_prt(isp, ISP_LOGTDEBUG0, "SRR received");
66310365e5aSMatt Jacob break;
66410365e5aSMatt Jacob
66510365e5aSMatt Jacob default:
6662df76c16SMatt Jacob isp_prt(isp, ISP_LOGERR, "Unknown CTIO7 status 0x%x", ct->ct_nphdl);
66710365e5aSMatt Jacob break;
66810365e5aSMatt Jacob }
66910365e5aSMatt Jacob
67010365e5aSMatt Jacob if (xs == NULL) {
67110365e5aSMatt Jacob /*
67210365e5aSMatt Jacob * There may be more than one CTIO for a data transfer,
67310365e5aSMatt Jacob * or this may be a status CTIO we're not monitoring.
67410365e5aSMatt Jacob *
67510365e5aSMatt Jacob * The assumption is that they'll all be returned in the
67610365e5aSMatt Jacob * order we got them.
67710365e5aSMatt Jacob */
67810365e5aSMatt Jacob if (ct->ct_syshandle == 0) {
67910365e5aSMatt Jacob if (ct->ct_flags & CT7_TERMINATE) {
680387d8239SMatt Jacob isp_prt(isp, ISP_LOGINFO, "termination of [RX_ID 0x%x] complete", ct->ct_rxid);
68110365e5aSMatt Jacob } else if ((ct->ct_flags & CT7_SENDSTATUS) == 0) {
6822df76c16SMatt Jacob isp_prt(isp, pl, "intermediate CTIO completed ok");
68310365e5aSMatt Jacob } else {
6842df76c16SMatt Jacob isp_prt(isp, pl, "unmonitored CTIO completed ok");
68510365e5aSMatt Jacob }
68610365e5aSMatt Jacob } else {
6872df76c16SMatt Jacob isp_prt(isp, pl, "NO xs for CTIO (handle 0x%x) status 0x%x", ct->ct_syshandle, ct->ct_nphdl);
68810365e5aSMatt Jacob }
68910365e5aSMatt Jacob } else {
690f6854a0cSAlexander Motin ISP_DMAFREE(isp, xs);
6912df76c16SMatt Jacob if (ct->ct_flags & CT7_SENDSTATUS) {
69210365e5aSMatt Jacob /*
69310365e5aSMatt Jacob * Sent status and command complete.
69410365e5aSMatt Jacob *
69510365e5aSMatt Jacob * We're now really done with this command, so we
69610365e5aSMatt Jacob * punt to the platform dependent layers because
69710365e5aSMatt Jacob * only there can we do the appropriate command
69810365e5aSMatt Jacob * complete thread synchronization.
69910365e5aSMatt Jacob */
70010365e5aSMatt Jacob isp_prt(isp, pl, "status CTIO complete");
70110365e5aSMatt Jacob } else {
70210365e5aSMatt Jacob /*
70310365e5aSMatt Jacob * Final CTIO completed. Release DMA resources and
70410365e5aSMatt Jacob * notify platform dependent layers.
70510365e5aSMatt Jacob */
70610365e5aSMatt Jacob isp_prt(isp, pl, "data CTIO complete");
70710365e5aSMatt Jacob }
7082df76c16SMatt Jacob isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
70910365e5aSMatt Jacob /*
71010365e5aSMatt Jacob * The platform layer will destroy the handle if appropriate.
71110365e5aSMatt Jacob */
71210365e5aSMatt Jacob }
71310365e5aSMatt Jacob }
7142df76c16SMatt Jacob
7152df76c16SMatt Jacob static void
isp_handle_notify_24xx(ispsoftc_t * isp,in_fcentry_24xx_t * inot)7165a5632c2SAlexander Motin isp_handle_notify_24xx(ispsoftc_t *isp, in_fcentry_24xx_t *inot)
7172df76c16SMatt Jacob {
7185a5632c2SAlexander Motin uint8_t chan;
7195a5632c2SAlexander Motin uint16_t nphdl, prli_options = 0;
7205a5632c2SAlexander Motin uint32_t portid;
7215a5632c2SAlexander Motin fcportdb_t *lp;
7225a5632c2SAlexander Motin char *msg = NULL;
7235a5632c2SAlexander Motin uint8_t *ptr = (uint8_t *)inot;
7245a5632c2SAlexander Motin uint64_t wwpn = INI_NONE, wwnn = INI_NONE;
7255a5632c2SAlexander Motin isp_notify_t notify;
7265a5632c2SAlexander Motin char buf[16];
7272df76c16SMatt Jacob
7285a5632c2SAlexander Motin nphdl = inot->in_nphdl;
7295a5632c2SAlexander Motin if (nphdl != NIL_HANDLE) {
7305a5632c2SAlexander Motin portid = inot->in_portid_hi << 16 | inot->in_portid_lo;
7312df76c16SMatt Jacob } else {
7325a5632c2SAlexander Motin portid = PORT_ANY;
7335a5632c2SAlexander Motin }
7345a5632c2SAlexander Motin
7355a5632c2SAlexander Motin chan = ISP_GET_VPIDX(isp, inot->in_vpidx);
7365a5632c2SAlexander Motin if (chan >= isp->isp_nchan &&
7375a5632c2SAlexander Motin inot->in_status != IN24XX_LIP_RESET &&
7385a5632c2SAlexander Motin inot->in_status != IN24XX_LINK_RESET &&
7395a5632c2SAlexander Motin inot->in_status != IN24XX_LINK_FAILED) {
7405a5632c2SAlexander Motin isp_prt(isp, ISP_LOGWARN, "%s: Received INOT with status %x on VP %x",
7415a5632c2SAlexander Motin __func__, inot->in_status, chan);
7425a5632c2SAlexander Motin isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
7432df76c16SMatt Jacob return;
7442df76c16SMatt Jacob }
7455a5632c2SAlexander Motin
7465a5632c2SAlexander Motin switch (inot->in_status) {
7472df76c16SMatt Jacob case IN24XX_ELS_RCVD:
7485a5632c2SAlexander Motin {
7495a5632c2SAlexander Motin /*
7505a5632c2SAlexander Motin * Note that we're just getting notification that an ELS was
7515a5632c2SAlexander Motin * received (possibly with some associated information sent
7525a5632c2SAlexander Motin * upstream). This is *not* the same as being given the ELS
7535a5632c2SAlexander Motin * frame to accept or reject.
7545a5632c2SAlexander Motin */
7555a5632c2SAlexander Motin switch (inot->in_status_subcode) {
7565a5632c2SAlexander Motin case LOGO:
7575a5632c2SAlexander Motin msg = "LOGO";
7585a5632c2SAlexander Motin wwpn = be64dec(&ptr[IN24XX_PLOGI_WWPN_OFF]);
7595a5632c2SAlexander Motin isp_del_wwn_entry(isp, chan, wwpn, nphdl, portid);
7605a5632c2SAlexander Motin break;
7615a5632c2SAlexander Motin case PRLO:
7625a5632c2SAlexander Motin msg = "PRLO";
7635a5632c2SAlexander Motin break;
7645a5632c2SAlexander Motin case PLOGI:
7655a5632c2SAlexander Motin msg = "PLOGI";
7665a5632c2SAlexander Motin wwnn = be64dec(&ptr[IN24XX_PLOGI_WWNN_OFF]);
7675a5632c2SAlexander Motin wwpn = be64dec(&ptr[IN24XX_PLOGI_WWPN_OFF]);
7685a5632c2SAlexander Motin isp_add_wwn_entry(isp, chan, wwpn, wwnn,
7695a5632c2SAlexander Motin nphdl, portid, prli_options);
7705a5632c2SAlexander Motin break;
7715a5632c2SAlexander Motin case PRLI:
7725a5632c2SAlexander Motin msg = "PRLI";
7735a5632c2SAlexander Motin prli_options = inot->in_prli_options;
7745a5632c2SAlexander Motin if (inot->in_flags & IN24XX_FLAG_PN_NN_VALID)
7755a5632c2SAlexander Motin wwnn = be64dec(&ptr[IN24XX_PRLI_WWNN_OFF]);
7765a5632c2SAlexander Motin wwpn = be64dec(&ptr[IN24XX_PRLI_WWPN_OFF]);
7775a5632c2SAlexander Motin isp_add_wwn_entry(isp, chan, wwpn, wwnn,
7785a5632c2SAlexander Motin nphdl, portid, prli_options);
7795a5632c2SAlexander Motin break;
7808cb0d414SAlexander Motin case TPRLO:
7818cb0d414SAlexander Motin msg = "TPRLO";
7828cb0d414SAlexander Motin break;
7835a5632c2SAlexander Motin case PDISC:
7845a5632c2SAlexander Motin msg = "PDISC";
7855a5632c2SAlexander Motin break;
7865a5632c2SAlexander Motin case ADISC:
7875a5632c2SAlexander Motin msg = "ADISC";
7882df76c16SMatt Jacob break;
7892df76c16SMatt Jacob default:
7905a5632c2SAlexander Motin ISP_SNPRINTF(buf, sizeof (buf), "ELS 0x%x",
7915a5632c2SAlexander Motin inot->in_status_subcode);
7925a5632c2SAlexander Motin msg = buf;
7935a5632c2SAlexander Motin break;
7945a5632c2SAlexander Motin }
7955a5632c2SAlexander Motin if (inot->in_flags & IN24XX_FLAG_PUREX_IOCB) {
7965a5632c2SAlexander Motin isp_prt(isp, ISP_LOGERR, "%s Chan %d ELS N-port handle %x"
7975a5632c2SAlexander Motin " PortID 0x%06x marked as needing a PUREX response",
7985a5632c2SAlexander Motin msg, chan, nphdl, portid);
7995a5632c2SAlexander Motin break;
8005a5632c2SAlexander Motin }
8015a5632c2SAlexander Motin isp_prt(isp, ISP_LOGTDEBUG0, "%s Chan %d ELS N-port handle %x"
8025a5632c2SAlexander Motin " PortID 0x%06x RX_ID 0x%x OX_ID 0x%x", msg, chan, nphdl,
8035a5632c2SAlexander Motin portid, inot->in_rxid, inot->in_oxid);
8045a5632c2SAlexander Motin isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
8055a5632c2SAlexander Motin break;
8065a5632c2SAlexander Motin }
8075a5632c2SAlexander Motin
8085a5632c2SAlexander Motin case IN24XX_PORT_LOGOUT:
8095a5632c2SAlexander Motin msg = "PORT LOGOUT";
8105a5632c2SAlexander Motin if (isp_find_pdb_by_handle(isp, chan, nphdl, &lp))
8115a5632c2SAlexander Motin isp_del_wwn_entry(isp, chan, lp->port_wwn, nphdl, lp->portid);
8125a5632c2SAlexander Motin /* FALLTHROUGH */
8135a5632c2SAlexander Motin case IN24XX_PORT_CHANGED:
8145a5632c2SAlexander Motin if (msg == NULL)
8155a5632c2SAlexander Motin msg = "PORT CHANGED";
8165a5632c2SAlexander Motin /* FALLTHROUGH */
8175a5632c2SAlexander Motin case IN24XX_LIP_RESET:
8185a5632c2SAlexander Motin if (msg == NULL)
8195a5632c2SAlexander Motin msg = "LIP RESET";
8205a5632c2SAlexander Motin isp_prt(isp, ISP_LOGINFO, "Chan %d %s (sub-status 0x%x) for "
8215a5632c2SAlexander Motin "N-port handle 0x%x",
8225a5632c2SAlexander Motin chan, msg, inot->in_status_subcode, nphdl);
8235a5632c2SAlexander Motin
8245a5632c2SAlexander Motin /*
8255a5632c2SAlexander Motin * All subcodes here are irrelevant. What is relevant
8265a5632c2SAlexander Motin * is that we need to terminate all active commands from
8275a5632c2SAlexander Motin * this initiator (known by N-port handle).
8285a5632c2SAlexander Motin */
8295a5632c2SAlexander Motin /* XXX IMPLEMENT XXX */
8305a5632c2SAlexander Motin isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
8315a5632c2SAlexander Motin break;
8325a5632c2SAlexander Motin
8335a5632c2SAlexander Motin case IN24XX_SRR_RCVD:
8345a5632c2SAlexander Motin #ifdef ISP_TARGET_MODE
8355a5632c2SAlexander Motin ISP_MEMZERO(¬ify, sizeof (isp_notify_t));
8365a5632c2SAlexander Motin notify.nt_hba = isp;
8375a5632c2SAlexander Motin notify.nt_wwn = INI_ANY;
8385a5632c2SAlexander Motin notify.nt_tgt = FCPARAM(isp, chan)->isp_wwpn;
8395a5632c2SAlexander Motin notify.nt_nphdl = nphdl;
8405a5632c2SAlexander Motin notify.nt_sid = portid;
8415a5632c2SAlexander Motin notify.nt_did = PORT_ANY;
8425a5632c2SAlexander Motin notify.nt_lun = LUN_ANY;
8435a5632c2SAlexander Motin notify.nt_tagval = inot->in_rxid;
8445a5632c2SAlexander Motin notify.nt_tagval |= ((uint64_t)inot->in_srr_rxid << 32);
8455a5632c2SAlexander Motin notify.nt_need_ack = 1;
8465a5632c2SAlexander Motin notify.nt_channel = chan;
8475a5632c2SAlexander Motin notify.nt_lreserved = inot;
8485a5632c2SAlexander Motin notify.nt_ncode = NT_SRR;
8495a5632c2SAlexander Motin isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
8505a5632c2SAlexander Motin break;
8515a5632c2SAlexander Motin #else
8525a5632c2SAlexander Motin if (msg == NULL)
8535a5632c2SAlexander Motin msg = "SRR RCVD";
8545a5632c2SAlexander Motin /* FALLTHROUGH */
8555a5632c2SAlexander Motin #endif
8565a5632c2SAlexander Motin case IN24XX_LINK_RESET:
8575a5632c2SAlexander Motin if (msg == NULL)
8585a5632c2SAlexander Motin msg = "LINK RESET";
8595a5632c2SAlexander Motin case IN24XX_LINK_FAILED:
8605a5632c2SAlexander Motin if (msg == NULL)
8615a5632c2SAlexander Motin msg = "LINK FAILED";
8625a5632c2SAlexander Motin default:
8635a5632c2SAlexander Motin isp_prt(isp, ISP_LOGWARN, "Chan %d %s", chan, msg);
8645a5632c2SAlexander Motin isp_async(isp, ISPASYNC_TARGET_NOTIFY_ACK, inot);
8652df76c16SMatt Jacob break;
8662df76c16SMatt Jacob }
8672df76c16SMatt Jacob }
868ea49c6e4SMatt Jacob #endif
869