2 * Copyright (c) 1997-2009 by Matthew Jacob
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Machine and OS Independent Target Mode Code for the Qlogic SCSI/FC adapters.
32 * Bug fixes gratefully acknowledged from:
33 * Oded Kedem <oded@kashya.com>
36 * Include header file appropriate for platform we're building on.
40 #include <dev/ic/isp_netbsd.h>
43 #include <sys/cdefs.h>
44 __FBSDID("$FreeBSD$");
45 #include <dev/isp/isp_freebsd.h>
48 #include <dev/ic/isp_openbsd.h>
51 #include "isp_linux.h"
54 #ifdef ISP_TARGET_MODE
55 static const char atiocope[] = "ATIO returned for lun %d because it was in the middle of Bus Device Reset on bus %d";
56 static const char atior[] = "ATIO returned on for lun %d on from loopid %d because a Bus Reset occurred on bus %d";
57 static const char rqo[] = "%s: Request Queue Overflow";
59 static void isp_got_msg(ispsoftc_t *, in_entry_t *);
60 static void isp_got_msg_fc(ispsoftc_t *, in_fcentry_t *);
61 static void isp_got_tmf_24xx(ispsoftc_t *, at7_entry_t *);
62 static void isp_handle_atio(ispsoftc_t *, at_entry_t *);
63 static void isp_handle_atio2(ispsoftc_t *, at2_entry_t *);
64 static void isp_handle_ctio(ispsoftc_t *, ct_entry_t *);
65 static void isp_handle_ctio2(ispsoftc_t *, ct2_entry_t *);
66 static void isp_handle_ctio7(ispsoftc_t *, ct7_entry_t *);
67 static void isp_handle_24xx_inotify(ispsoftc_t *, in_fcentry_24xx_t *);
70 * The Qlogic driver gets an interrupt to look at response queue entries.
71 * Some of these are status completions for initiatior mode commands, but
72 * if target mode is enabled, we get a whole wad of response queue entries
75 * Basically the split into 3 main groups: Lun Enable/Modification responses,
76 * SCSI Command processing, and Immediate Notification events.
78 * You start by writing a request queue entry to enable target mode (and
79 * establish some resource limitations which you can modify later).
80 * The f/w responds with a LUN ENABLE or LUN MODIFY response with
81 * the status of this action. If the enable was successful, you can expect...
83 * Response queue entries with SCSI commands encapsulate show up in an ATIO
84 * (Accept Target IO) type- sometimes with enough info to stop the command at
85 * this level. Ultimately the driver has to feed back to the f/w's request
86 * queue a sequence of CTIOs (continue target I/O) that describe data to
87 * be moved and/or status to be sent) and finally finishing with sending
88 * to the f/w's response queue an ATIO which then completes the handshake
89 * with the f/w for that command. There's a lot of variations on this theme,
90 * including flags you can set in the CTIO for the Qlogic 2X00 fibre channel
91 * cards that 'auto-replenish' the f/w's ATIO count, but this is the basic
94 * The third group that can show up in the response queue are Immediate
95 * Notification events. These include things like notifications of SCSI bus
96 * resets, or Bus Device Reset messages or other messages received. This
97 * a classic oddbins area. It can get a little weird because you then turn
98 * around and acknowledge the Immediate Notify by writing an entry onto the
99 * request queue and then the f/w turns around and gives you an acknowledgement
100 * to *your* acknowledgement on the response queue (the idea being to let
101 * the f/w tell you when the event is *really* over I guess).
107 * A new response queue entry has arrived. The interrupt service code
108 * has already swizzled it into the platform dependent from canonical form.
110 * Because of the way this driver is designed, unfortunately most of the
111 * actual synchronization work has to be done in the platform specific
112 * code- we have no synchroniation primitives in the common code.
116 isp_target_notify(ispsoftc_t *isp, void *vptr, uint32_t *optrp)
123 at2e_entry_t *at2eiop;
127 ct2e_entry_t *ct2eiop;
131 in_fcentry_t *inot_fcp;
132 in_fcentry_e_t *inote_fcp;
133 in_fcentry_24xx_t *inot_24xx;
135 na_fcentry_t *nack_fcp;
136 na_fcentry_e_t *nacke_fcp;
137 na_fcentry_24xx_t *nack_24xx;
140 abts_rsp_t *abts_rsp;
143 #define atiop unp.atiop
144 #define at2iop unp.at2iop
145 #define at2eiop unp.at2eiop
146 #define at7iop unp.at7iop
147 #define ctiop unp.ctiop
148 #define ct2iop unp.ct2iop
149 #define ct2eiop unp.ct2eiop
150 #define ct7iop unp.ct7iop
151 #define lunenp unp.lunenp
152 #define inotp unp.inotp
153 #define inot_fcp unp.inot_fcp
154 #define inote_fcp unp.inote_fcp
155 #define inot_24xx unp.inot_24xx
156 #define nackp unp.nackp
157 #define nack_fcp unp.nack_fcp
158 #define nacke_fcp unp.nacke_fcp
159 #define nack_24xx unp.nack_24xx
160 #define abts unp.abts
161 #define abts_rsp unp.abts_rsp
165 uint8_t local[QENTRY_LEN];
167 int bus, type, level, rval = 1;
170 type = isp_get_response_type(isp, (isphdr_t *)vptr);
173 ISP_TDQE(isp, "isp_target_notify", (int) *optrp, vptr);
180 isp_get_atio7(isp, at7iop, (at7_entry_t *) local);
181 at7iop = (at7_entry_t *) local;
183 * Check for and do something with commands whose
184 * IULEN extends past a single queue entry.
186 len = at7iop->at_ta_len & 0xfffff;
187 if (len > (QENTRY_LEN - 8)) {
188 len -= (QENTRY_LEN - 8);
189 isp_prt(isp, ISP_LOGINFO, "long IU length (%d) ignored", len);
191 *optrp = ISP_NXT_QENTRY(*optrp, RESULT_QUEUE_LEN(isp));
196 * Check for a task management function
198 if (at7iop->at_cmnd.fcp_cmnd_task_management) {
199 isp_got_tmf_24xx(isp, at7iop);
203 * Just go straight to outer layer for this one.
205 isp_async(isp, ISPASYNC_TARGET_ACTION, local);
207 isp_get_atio(isp, atiop, (at_entry_t *) local);
208 isp_handle_atio(isp, (at_entry_t *) local);
213 isp_get_ctio(isp, ctiop, (ct_entry_t *) local);
214 isp_handle_ctio(isp, (ct_entry_t *) local);
218 if (ISP_CAP_2KLOGIN(isp)) {
219 isp_get_atio2e(isp, at2eiop, (at2e_entry_t *) local);
221 isp_get_atio2(isp, at2iop, (at2_entry_t *) local);
223 isp_handle_atio2(isp, (at2_entry_t *) local);
228 if (ISP_CAP_2KLOGIN(isp)) {
229 isp_get_ctio2e(isp, ct2eiop, (ct2e_entry_t *) local);
231 isp_get_ctio2(isp, ct2iop, (ct2_entry_t *) local);
233 isp_handle_ctio2(isp, (ct2_entry_t *) local);
237 isp_get_ctio7(isp, ct7iop, (ct7_entry_t *) local);
238 isp_handle_ctio7(isp, (ct7_entry_t *) local);
241 case RQSTYPE_ENABLE_LUN:
242 case RQSTYPE_MODIFY_LUN:
243 isp_get_enable_lun(isp, lunenp, (lun_entry_t *) local);
244 isp_async(isp, ISPASYNC_TARGET_ACTION, local);
250 isp_get_notify_24xx(isp, inot_24xx, (in_fcentry_24xx_t *)local);
251 inot_24xx = (in_fcentry_24xx_t *) local;
252 isp_handle_24xx_inotify(isp, inot_24xx);
256 if (ISP_CAP_2KLOGIN(isp)) {
257 in_fcentry_e_t *ecp = (in_fcentry_e_t *)local;
258 isp_get_notify_fc_e(isp, inote_fcp, ecp);
260 status = ecp->in_status;
261 seqid = ecp->in_seqid;
263 in_fcentry_t *fcp = (in_fcentry_t *)local;
264 isp_get_notify_fc(isp, inot_fcp, fcp);
266 status = fcp->in_status;
267 seqid = fcp->in_seqid;
270 in_entry_t *inp = (in_entry_t *)local;
271 isp_get_notify(isp, inotp, inp);
272 status = inp->in_status & 0xff;
273 seqid = inp->in_seqid;
275 if (IS_DUALBUS(isp)) {
276 bus = GET_BUS_VAL(inp->in_iid);
277 SET_BUS_VAL(inp->in_iid, 0);
281 isp_prt(isp, ISP_LOGTDEBUG0, "Immediate Notify On Bus %d, status=0x%x seqid=0x%x", bus, status, seqid);
284 case IN_MSG_RECEIVED:
285 case IN_IDE_RECEIVED:
287 isp_got_msg_fc(isp, (in_fcentry_t *)local);
289 isp_got_msg(isp, (in_entry_t *)local);
292 case IN_RSRC_UNAVAIL:
293 isp_prt(isp, ISP_LOGINFO, "Firmware out of ATIOs");
294 (void) isp_notify_ack(isp, local);
298 ISP_MEMZERO(¬ify, sizeof (isp_notify_t));
300 notify.nt_wwn = INI_ANY;
301 notify.nt_tgt = TGT_ANY;
302 notify.nt_nphdl = iid;
303 notify.nt_sid = PORT_ANY;
304 notify.nt_did = PORT_ANY;
305 notify.nt_lun = LUN_ANY;
306 notify.nt_tagval = TAG_ANY;
307 notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32);
308 notify.nt_ncode = NT_BUS_RESET;
309 notify.nt_need_ack = 1;
310 notify.nt_lreserved = local;
311 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
315 ISP_MEMZERO(¬ify, sizeof (isp_notify_t));
317 notify.nt_wwn = INI_ANY;
318 notify.nt_nphdl = iid;
319 notify.nt_sid = PORT_ANY;
320 notify.nt_did = PORT_ANY;
321 notify.nt_ncode = NT_LOGOUT;
322 notify.nt_need_ack = 1;
323 notify.nt_lreserved = local;
324 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
328 ISP_MEMZERO(¬ify, sizeof (isp_notify_t));
330 notify.nt_wwn = INI_ANY;
331 notify.nt_nphdl = iid;
332 notify.nt_sid = PORT_ANY;
333 notify.nt_did = PORT_ANY;
334 notify.nt_ncode = NT_ABORT_TASK;
335 notify.nt_need_ack = 1;
336 notify.nt_lreserved = local;
337 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
341 isp_prt(isp, ISP_LOGTINFO, "%s: all ports logged out", __func__);
342 ISP_MEMZERO(¬ify, sizeof (isp_notify_t));
344 notify.nt_wwn = INI_ANY;
345 notify.nt_nphdl = NIL_HANDLE;
346 notify.nt_sid = PORT_ANY;
347 notify.nt_did = PORT_ANY;
348 notify.nt_ncode = NT_GLOBAL_LOGOUT;
349 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
350 (void) isp_notify_ack(isp, local);
353 case IN_PORT_CHANGED:
354 isp_prt(isp, ISP_LOGTINFO, "%s: port changed", __func__);
355 (void) isp_notify_ack(isp, local);
359 ISP_SNPRINTF(local, sizeof local, "%s: unknown status to RQSTYPE_NOTIFY (0x%x)", __func__, status);
360 isp_print_bytes(isp, local, QENTRY_LEN, vptr);
361 (void) isp_notify_ack(isp, local);
366 case RQSTYPE_NOTIFY_ACK:
368 * The ISP is acknowledging our acknowledgement of an
369 * Immediate Notify entry for some asynchronous event.
372 isp_get_notify_ack_24xx(isp, nack_24xx, (na_fcentry_24xx_t *) local);
373 nack_24xx = (na_fcentry_24xx_t *) local;
374 if (nack_24xx->na_status != NA_OK) {
377 level = ISP_LOGTDEBUG1;
379 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);
380 } else if (IS_FC(isp)) {
381 if (ISP_CAP_2KLOGIN(isp)) {
382 isp_get_notify_ack_fc_e(isp, nacke_fcp, (na_fcentry_e_t *)local);
384 isp_get_notify_ack_fc(isp, nack_fcp, (na_fcentry_t *)local);
386 nack_fcp = (na_fcentry_t *)local;
387 if (nack_fcp->na_status != NA_OK) {
390 level = ISP_LOGTDEBUG1;
392 isp_prt(isp, level, "Notify Ack Status=0x%x seqid 0x%x", nack_fcp->na_status, nack_fcp->na_seqid);
394 isp_get_notify_ack(isp, nackp, (na_entry_t *)local);
395 nackp = (na_entry_t *)local;
396 if (nackp->na_status != NA_OK) {
399 level = ISP_LOGTDEBUG1;
401 isp_prt(isp, level, "Notify Ack event 0x%x status=0x%x seqid 0x%x", nackp->na_event, nackp->na_status, nackp->na_seqid);
405 case RQSTYPE_ABTS_RCVD:
406 isp_get_abts(isp, abts, (abts_t *)local);
407 isp_async(isp, ISPASYNC_TARGET_ACTION, &local);
409 case RQSTYPE_ABTS_RSP:
410 isp_get_abts_rsp(isp, abts_rsp, (abts_rsp_t *)local);
411 abts_rsp = (abts_rsp_t *) local;
412 if (abts_rsp->abts_rsp_status) {
415 level = ISP_LOGTDEBUG0;
417 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,
418 abts_rsp->abts_rsp_payload.rsp.subcode1, abts_rsp->abts_rsp_payload.rsp.subcode2);
421 isp_prt(isp, ISP_LOGERR, "%s: unknown entry type 0x%x", __func__, type);
451 * Toggle (on/off) target mode for bus/target/lun.
453 * The caller has checked for overlap and legality.
455 * Note that not all of bus, target or lun can be paid attention to.
456 * Note also that this action will not be complete until the f/w writes
457 * a response entry. The caller is responsible for synchronizing with this.
460 isp_lun_cmd(ispsoftc_t *isp, int cmd, int bus, int lun, int cmd_cnt, int inot_cnt)
465 ISP_MEMZERO(&el, sizeof (el));
466 if (IS_DUALBUS(isp)) {
467 el.le_rsvd = (bus & 0x1) << 7;
469 el.le_cmd_count = cmd_cnt;
470 el.le_in_count = inot_cnt;
471 if (cmd == RQSTYPE_ENABLE_LUN) {
473 el.le_flags = LUN_TQAE|LUN_DISAD;
477 } else if (cmd == -RQSTYPE_ENABLE_LUN) {
478 cmd = RQSTYPE_ENABLE_LUN;
481 } else if (cmd == -RQSTYPE_MODIFY_LUN) {
482 cmd = RQSTYPE_MODIFY_LUN;
483 el.le_ops = LUN_CCDECR | LUN_INDECR;
485 el.le_ops = LUN_CCINCR | LUN_ININCR;
487 el.le_header.rqs_entry_type = cmd;
488 el.le_header.rqs_entry_count = 1;
490 el.le_tgt = SDPARAM(isp, bus)->isp_initiator_id;
492 } else if (ISP_CAP_SCCFW(isp) == 0) {
497 outp = isp_getrqentry(isp);
499 isp_prt(isp, ISP_LOGERR, rqo, __func__);
502 isp_put_enable_lun(isp, &el, outp);
503 ISP_TDQE(isp, "isp_lun_cmd", isp->isp_reqidx, &el);
504 ISP_SYNC_REQUEST(isp);
509 isp_target_put_entry(ispsoftc_t *isp, void *ap)
512 uint8_t etype = ((isphdr_t *) ap)->rqs_entry_type;
514 outp = isp_getrqentry(isp);
516 isp_prt(isp, ISP_LOGWARN, rqo, __func__);
521 isp_put_atio(isp, (at_entry_t *) ap, (at_entry_t *) outp);
524 if (ISP_CAP_2KLOGIN(isp)) {
525 isp_put_atio2e(isp, (at2e_entry_t *) ap, (at2e_entry_t *) outp);
527 isp_put_atio2(isp, (at2_entry_t *) ap, (at2_entry_t *) outp);
531 isp_put_ctio(isp, (ct_entry_t *) ap, (ct_entry_t *) outp);
534 if (ISP_CAP_2KLOGIN(isp)) {
535 isp_put_ctio2e(isp, (ct2e_entry_t *) ap, (ct2e_entry_t *) outp);
537 isp_put_ctio2(isp, (ct2_entry_t *) ap, (ct2_entry_t *) outp);
541 isp_put_ctio7(isp, (ct7_entry_t *) ap, (ct7_entry_t *) outp);
544 isp_prt(isp, ISP_LOGERR, "%s: Unknown type 0x%x", __func__, etype);
547 ISP_TDQE(isp, __func__, isp->isp_reqidx, ap);
548 ISP_SYNC_REQUEST(isp);
553 isp_target_put_atio(ispsoftc_t *isp, void *arg)
558 at2e_entry_t _atio2e;
561 ISP_MEMZERO(&atun, sizeof atun);
563 at2_entry_t *aep = arg;
564 atun._atio2.at_header.rqs_entry_type = RQSTYPE_ATIO2;
565 atun._atio2.at_header.rqs_entry_count = 1;
566 if (ISP_CAP_SCCFW(isp)) {
567 atun._atio2.at_scclun = aep->at_scclun;
569 atun._atio2.at_lun = (uint8_t) aep->at_lun;
571 if (ISP_CAP_2KLOGIN(isp)) {
572 atun._atio2e.at_iid = ((at2e_entry_t *)aep)->at_iid;
574 atun._atio2.at_iid = aep->at_iid;
576 atun._atio2.at_rxid = aep->at_rxid;
577 atun._atio2.at_status = CT_OK;
579 at_entry_t *aep = arg;
580 atun._atio.at_header.rqs_entry_type = RQSTYPE_ATIO;
581 atun._atio.at_header.rqs_entry_count = 1;
582 atun._atio.at_handle = aep->at_handle;
583 atun._atio.at_iid = aep->at_iid;
584 atun._atio.at_tgt = aep->at_tgt;
585 atun._atio.at_lun = aep->at_lun;
586 atun._atio.at_tag_type = aep->at_tag_type;
587 atun._atio.at_tag_val = aep->at_tag_val;
588 atun._atio.at_status = (aep->at_flags & AT_TQAE);
589 atun._atio.at_status |= CT_OK;
591 return (isp_target_put_entry(isp, &atun));
595 * Command completion- both for handling cases of no resources or
596 * no blackhole driver, or other cases where we have to, inline,
597 * finish the command sanely, or for normal command completion.
599 * The 'completion' code value has the scsi status byte in the low 8 bits.
600 * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have
601 * the sense key and bits 16..23 have the ASCQ and bits 24..31 have the ASC
604 * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't
605 * NB: inline SCSI sense reporting. As such, we lose this information. XXX.
607 * For both parallel && fibre channel, we use the feature that does
608 * an automatic resource autoreplenish so we don't have then later do
609 * put of an atio to replenish the f/w's resource count.
613 isp_endcmd(ispsoftc_t *isp, ...)
620 ct2e_entry_t _ctio2e;
625 ISP_MEMZERO(&un, sizeof un);
630 ct7_entry_t *cto = &un._ctio7;
633 aep = va_arg(ap, at7_entry_t *);
634 nphdl = va_arg(ap, int);
636 * Note that vpidx may equal 0xff (unknown) here
638 vpidx = va_arg(ap, int);
639 code = va_arg(ap, uint32_t);
640 hdl = va_arg(ap, uint32_t);
642 isp_prt(isp, ISP_LOGTDEBUG0, "%s: [RX_ID 0x%x] chan %d code %x", __func__, aep->at_rxid, vpidx, code);
645 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
646 cto->ct_header.rqs_entry_count = 1;
647 cto->ct_nphdl = nphdl;
648 cto->ct_rxid = aep->at_rxid;
649 cto->ct_iid_lo = (aep->at_hdr.s_id[1] << 8) | aep->at_hdr.s_id[2];
650 cto->ct_iid_hi = aep->at_hdr.s_id[0];
651 cto->ct_oxid = aep->at_hdr.ox_id;
652 cto->ct_scsi_status = sts;
653 cto->ct_vpidx = vpidx;
654 cto->ct_flags = CT7_NOACK;
655 if (code & ECMD_TERMINATE) {
656 cto->ct_flags |= CT7_TERMINATE;
657 } else if (code & ECMD_SVALID) {
658 cto->ct_flags |= CT7_FLAG_MODE1 | CT7_SENDSTATUS;
659 cto->ct_scsi_status |= (FCP_SNSLEN_VALID << 8);
660 cto->rsp.m1.ct_resplen = cto->ct_senselen = min(16, MAXRESPLEN_24XX);
661 ISP_MEMZERO(cto->rsp.m1.ct_resp, sizeof (cto->rsp.m1.ct_resp));
662 cto->rsp.m1.ct_resp[0] = 0xf0;
663 cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
664 cto->rsp.m1.ct_resp[7] = 8;
665 cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff;
666 cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff;
668 cto->ct_flags |= CT7_FLAG_MODE1 | CT7_SENDSTATUS;
670 if (aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl) {
671 cto->ct_resid = aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl;
672 if (cto->ct_resid < 0) {
673 cto->ct_scsi_status |= (FCP_RESID_OVERFLOW << 8);
674 } else if (cto->ct_resid > 0) {
675 cto->ct_scsi_status |= (FCP_RESID_UNDERFLOW << 8);
678 cto->ct_syshandle = hdl;
679 } else if (IS_FC(isp)) {
681 ct2_entry_t *cto = &un._ctio2;
684 aep = va_arg(ap, at2_entry_t *);
685 code = va_arg(ap, uint32_t);
686 hdl = va_arg(ap, uint32_t);
689 isp_prt(isp, ISP_LOGTDEBUG0, "%s: [RX_ID 0x%x] code %x", __func__, aep->at_rxid, code);
692 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
693 cto->ct_header.rqs_entry_count = 1;
694 if (ISP_CAP_SCCFW(isp) == 0) {
695 cto->ct_lun = aep->at_lun;
697 if (ISP_CAP_2KLOGIN(isp)) {
698 un._ctio2e.ct_iid = ((at2e_entry_t *)aep)->at_iid;
700 cto->ct_iid = aep->at_iid;
702 cto->ct_rxid = aep->at_rxid;
703 cto->rsp.m1.ct_scsi_status = sts;
704 cto->ct_flags = CT2_SENDSTATUS | CT2_NO_DATA | CT2_FLAG_MODE1;
706 cto->ct_flags |= CT2_CCINCR;
708 if (aep->at_datalen) {
709 cto->ct_resid = aep->at_datalen;
710 cto->rsp.m1.ct_scsi_status |= CT2_DATA_UNDER;
712 if (sts == SCSI_CHECK && (code & ECMD_SVALID)) {
713 cto->rsp.m1.ct_resp[0] = 0xf0;
714 cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
715 cto->rsp.m1.ct_resp[7] = 8;
716 cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff;
717 cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff;
718 cto->rsp.m1.ct_senselen = 16;
719 cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID;
721 cto->ct_syshandle = hdl;
724 ct_entry_t *cto = &un._ctio;
727 aep = va_arg(ap, at_entry_t *);
728 code = va_arg(ap, uint32_t);
729 hdl = va_arg(ap, uint32_t);
731 isp_prt(isp, ISP_LOGTDEBUG0, "%s: [IID %d] code %x", __func__, aep->at_iid, code);
734 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
735 cto->ct_header.rqs_entry_count = 1;
736 cto->ct_fwhandle = aep->at_handle;
737 cto->ct_iid = aep->at_iid;
738 cto->ct_tgt = aep->at_tgt;
739 cto->ct_lun = aep->at_lun;
740 cto->ct_tag_type = aep->at_tag_type;
741 cto->ct_tag_val = aep->at_tag_val;
742 if (aep->at_flags & AT_TQAE) {
743 cto->ct_flags |= CT_TQAE;
745 cto->ct_flags = CT_SENDSTATUS | CT_NO_DATA;
747 cto->ct_flags |= CT_CCINCR;
749 cto->ct_scsi_status = sts;
750 cto->ct_syshandle = hdl;
752 return (isp_target_put_entry(isp, &un));
756 * These are either broadcast events or specifically CTIO fast completion
760 isp_target_async(ispsoftc_t *isp, int bus, int event)
764 ISP_MEMZERO(¬ify, sizeof (isp_notify_t));
766 notify.nt_wwn = INI_ANY;
767 notify.nt_nphdl = NIL_HANDLE;
768 notify.nt_sid = PORT_ANY;
769 notify.nt_did = PORT_ANY;
770 notify.nt_tgt = TGT_ANY;
771 notify.nt_channel = bus;
772 notify.nt_lun = LUN_ANY;
773 notify.nt_tagval = TAG_ANY;
774 notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32);
779 isp_prt(isp, ISP_LOGTDEBUG0, "%s: LOOP UP", __func__);
780 notify.nt_ncode = NT_LINK_UP;
781 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
783 case ASYNC_LOOP_DOWN:
784 isp_prt(isp, ISP_LOGTDEBUG0, "%s: LOOP DOWN", __func__);
785 notify.nt_ncode = NT_LINK_DOWN;
786 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
788 case ASYNC_LIP_ERROR:
790 case ASYNC_LIP_OCCURRED:
791 case ASYNC_LOOP_RESET:
792 isp_prt(isp, ISP_LOGTDEBUG0, "%s: LIP RESET", __func__);
793 notify.nt_ncode = NT_LIP_RESET;
794 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
796 case ASYNC_BUS_RESET:
797 case ASYNC_TIMEOUT_RESET: /* XXX: where does this come from ? */
798 isp_prt(isp, ISP_LOGTDEBUG0, "%s: BUS RESET", __func__);
799 notify.nt_ncode = NT_BUS_RESET;
800 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
802 case ASYNC_DEVICE_RESET:
803 isp_prt(isp, ISP_LOGTDEBUG0, "%s: DEVICE RESET", __func__);
804 notify.nt_ncode = NT_TARGET_RESET;
805 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
807 case ASYNC_CTIO_DONE:
809 uint8_t storage[QENTRY_LEN];
810 isp_prt(isp, ISP_LOGTDEBUG0, "%s: CTIO DONE", __func__);
811 memset(storage, 0, QENTRY_LEN);
813 ct7_entry_t *ct = (ct7_entry_t *) storage;
814 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
815 ct->ct_nphdl = CT7_OK;
816 ct->ct_syshandle = bus;
817 ct->ct_flags = CT7_SENDSTATUS;
818 } else if (IS_FC(isp)) {
819 /* This should also suffice for 2K login code */
820 ct2_entry_t *ct = (ct2_entry_t *) storage;
821 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
822 ct->ct_status = CT_OK;
823 ct->ct_syshandle = bus;
824 ct->ct_flags = CT2_SENDSTATUS|CT2_FASTPOST;
826 ct_entry_t *ct = (ct_entry_t *) storage;
827 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO;
828 ct->ct_status = CT_OK;
829 ct->ct_fwhandle = bus;
830 ct->ct_flags = CT_SENDSTATUS;
832 isp_async(isp, ISPASYNC_TARGET_ACTION, storage);
836 isp_prt(isp, ISP_LOGERR, "%s: unknown event 0x%x", __func__, event);
837 if (isp->isp_state == ISP_RUNSTATE) {
838 (void) isp_notify_ack(isp, NULL);
847 * Process a received message.
848 * The ISP firmware can handle most messages, there are only
849 * a few that we need to deal with:
850 * - abort: clean up the current command
851 * - abort tag and clear queue
855 isp_got_msg(ispsoftc_t *isp, in_entry_t *inp)
858 uint8_t status = inp->in_status & ~QLTM_SVALID;
860 ISP_MEMZERO(¬ify, sizeof (notify));
862 notify.nt_wwn = INI_ANY;
863 notify.nt_nphdl = GET_IID_VAL(inp->in_iid);
864 notify.nt_sid = PORT_ANY;
865 notify.nt_did = PORT_ANY;
866 notify.nt_channel = GET_BUS_VAL(inp->in_iid);
867 notify.nt_tgt = inp->in_tgt;
868 notify.nt_lun = inp->in_lun;
869 IN_MAKE_TAGID(notify.nt_tagval, inp);
870 notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32);
871 notify.nt_lreserved = inp;
873 if (status == IN_IDE_RECEIVED || status == IN_MSG_RECEIVED) {
874 switch (inp->in_msg[0]) {
876 notify.nt_ncode = NT_ABORT_TASK_SET;
878 case MSG_BUS_DEV_RESET:
879 notify.nt_ncode = NT_TARGET_RESET;
882 notify.nt_ncode = NT_ABORT_TASK;
884 case MSG_CLEAR_QUEUE:
885 notify.nt_ncode = NT_CLEAR_TASK_SET;
887 case MSG_REL_RECOVERY:
888 notify.nt_ncode = NT_CLEAR_ACA;
890 case MSG_TERM_IO_PROC:
891 notify.nt_ncode = NT_ABORT_TASK;
894 notify.nt_ncode = NT_LUN_RESET;
897 isp_prt(isp, ISP_LOGERR, "%s: unhandled message 0x%x", __func__, inp->in_msg[0]);
898 (void) isp_notify_ack(isp, inp);
901 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
903 isp_prt(isp, ISP_LOGERR, "%s: unknown immediate notify status 0x%x", __func__, inp->in_status);
904 (void) isp_notify_ack(isp, inp);
909 * Synthesize a message from the task management flags in a FCP_CMND_IU.
912 isp_got_msg_fc(ispsoftc_t *isp, in_fcentry_t *inp)
915 static const char f1[] = "%s from N-port handle 0x%x lun %d seq 0x%x";
916 static const char f2[] = "unknown %s 0x%x lun %d N-Port handle 0x%x task flags 0x%x seq 0x%x\n";
917 uint16_t seqid, loopid;
919 ISP_MEMZERO(¬ify, sizeof (isp_notify_t));
921 notify.nt_wwn = INI_ANY;
922 if (ISP_CAP_2KLOGIN(isp)) {
923 notify.nt_nphdl = ((in_fcentry_e_t *)inp)->in_iid;
924 loopid = ((in_fcentry_e_t *)inp)->in_iid;
925 seqid = ((in_fcentry_e_t *)inp)->in_seqid;
927 notify.nt_nphdl = inp->in_iid;
928 loopid = inp->in_iid;
929 seqid = inp->in_seqid;
931 notify.nt_sid = PORT_ANY;
932 notify.nt_did = PORT_ANY;
934 /* nt_tgt set in outer layers */
935 if (ISP_CAP_SCCFW(isp)) {
936 notify.nt_lun = inp->in_scclun;
938 notify.nt_lun = inp->in_lun;
940 notify.nt_tagval = seqid;
941 notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32);
942 notify.nt_need_ack = 1;
943 notify.nt_lreserved = inp;
945 if (inp->in_status != IN_MSG_RECEIVED) {
946 isp_prt(isp, ISP_LOGINFO, f2, "immediate notify status", inp->in_status, notify.nt_lun, loopid, inp->in_task_flags, inp->in_seqid);
947 (void) isp_notify_ack(isp, inp);
951 if (inp->in_task_flags & TASK_FLAGS_ABORT_TASK_SET) {
952 isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET", loopid, notify.nt_lun, inp->in_seqid);
953 notify.nt_ncode = NT_ABORT_TASK_SET;
954 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_TASK_SET) {
955 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET", loopid, notify.nt_lun, inp->in_seqid);
956 notify.nt_ncode = NT_CLEAR_TASK_SET;
957 } else if (inp->in_task_flags & TASK_FLAGS_LUN_RESET) {
958 isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET", loopid, notify.nt_lun, inp->in_seqid);
959 notify.nt_ncode = NT_LUN_RESET;
960 } else if (inp->in_task_flags & TASK_FLAGS_TARGET_RESET) {
961 isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET", loopid, notify.nt_lun, inp->in_seqid);
962 notify.nt_ncode = NT_TARGET_RESET;
963 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_ACA) {
964 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA", loopid, notify.nt_lun, inp->in_seqid);
965 notify.nt_ncode = NT_CLEAR_ACA;
967 isp_prt(isp, ISP_LOGWARN, f2, "task flag", inp->in_status, notify.nt_lun, loopid, inp->in_task_flags, inp->in_seqid);
968 (void) isp_notify_ack(isp, inp);
971 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
975 isp_got_tmf_24xx(ispsoftc_t *isp, at7_entry_t *aep)
978 static const char f1[] = "%s from PortID 0x%06x lun %d seq 0x%08x";
979 static const char f2[] = "unknown Task Flag 0x%x lun %d PortID 0x%x tag 0x%08x";
983 ISP_MEMZERO(¬ify, sizeof (isp_notify_t));
985 notify.nt_wwn = INI_ANY;
986 notify.nt_lun = (aep->at_cmnd.fcp_cmnd_lun[0] << 8) | (aep->at_cmnd.fcp_cmnd_lun[1]);
987 notify.nt_tagval = aep->at_rxid;
988 notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32);
989 notify.nt_lreserved = aep;
990 sid = (aep->at_hdr.s_id[0] << 16) | (aep->at_hdr.s_id[1] << 8) | (aep->at_hdr.s_id[2]);
992 /* Channel has to derived from D_ID */
993 did = (aep->at_hdr.d_id[0] << 16) | (aep->at_hdr.d_id[1] << 8) | aep->at_hdr.d_id[2];
994 for (chan = 0; chan < isp->isp_nchan; chan++) {
995 if (FCPARAM(isp, chan)->isp_portid == did) {
999 if (chan == isp->isp_nchan) {
1000 isp_prt(isp, ISP_LOGWARN, "%s: D_ID 0x%x not found on any channel", __func__, did);
1001 /* just drop on the floor */
1004 notify.nt_nphdl = NIL_HANDLE; /* unknown here */
1005 notify.nt_sid = sid;
1006 notify.nt_did = did;
1007 notify.nt_channel = chan;
1008 if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_ABORT_TASK_SET) {
1009 isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET", sid, notify.nt_lun, aep->at_rxid);
1010 notify.nt_ncode = NT_ABORT_TASK_SET;
1011 } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_CLEAR_TASK_SET) {
1012 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET", sid, notify.nt_lun, aep->at_rxid);
1013 notify.nt_ncode = NT_CLEAR_TASK_SET;
1014 } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_LUN_RESET) {
1015 isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET", sid, notify.nt_lun, aep->at_rxid);
1016 notify.nt_ncode = NT_LUN_RESET;
1017 } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_TGT_RESET) {
1018 isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET", sid, notify.nt_lun, aep->at_rxid);
1019 notify.nt_ncode = NT_TARGET_RESET;
1020 } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_CLEAR_ACA) {
1021 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA", sid, notify.nt_lun, aep->at_rxid);
1022 notify.nt_ncode = NT_CLEAR_ACA;
1024 isp_prt(isp, ISP_LOGWARN, f2, aep->at_cmnd.fcp_cmnd_task_management, notify.nt_lun, sid, aep->at_rxid);
1025 notify.nt_ncode = NT_UNKNOWN;
1028 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
1032 isp_notify_ack(ispsoftc_t *isp, void *arg)
1034 char storage[QENTRY_LEN];
1038 * This is in case a Task Management Function ends up here.
1040 if (IS_24XX(isp) && arg != NULL && (((isphdr_t *)arg)->rqs_entry_type == RQSTYPE_ATIO)) {
1041 at7_entry_t *aep = arg;
1042 return (isp_endcmd(isp, aep, NIL_HANDLE, 0, 0, 0));
1045 outp = isp_getrqentry(isp);
1047 isp_prt(isp, ISP_LOGWARN, rqo, __func__);
1051 ISP_MEMZERO(storage, QENTRY_LEN);
1054 na_fcentry_24xx_t *na = (na_fcentry_24xx_t *) storage;
1056 in_fcentry_24xx_t *in = arg;
1057 na->na_nphdl = in->in_nphdl;
1058 na->na_flags = in->in_flags & IN24XX_FLAG_PUREX_IOCB;
1059 na->na_status = in->in_status;
1060 na->na_status_subcode = in->in_status_subcode;
1061 na->na_rxid = in->in_rxid;
1062 na->na_oxid = in->in_oxid;
1063 na->na_vpidx = in->in_vpidx;
1064 if (in->in_status == IN24XX_SRR_RCVD) {
1065 na->na_srr_rxid = in->in_srr_rxid;
1066 na->na_srr_reloff_hi = in->in_srr_reloff_hi;
1067 na->na_srr_reloff_lo = in->in_srr_reloff_lo;
1068 na->na_srr_iu = in->in_srr_iu;
1069 na->na_srr_flags = 1;
1070 na->na_srr_reject_vunique = 0;
1071 na->na_srr_reject_explanation = 1;
1072 na->na_srr_reject_code = 1;
1075 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
1076 na->na_header.rqs_entry_count = 1;
1077 isp_put_notify_24xx_ack(isp, na, (na_fcentry_24xx_t *)outp);
1078 } else if (IS_FC(isp)) {
1079 na_fcentry_t *na = (na_fcentry_t *) storage;
1083 in_fcentry_t *inp = arg;
1084 ISP_MEMCPY(storage, arg, sizeof (isphdr_t));
1085 if (ISP_CAP_2KLOGIN(isp)) {
1086 ((na_fcentry_e_t *)na)->na_iid = ((in_fcentry_e_t *)inp)->in_iid;
1087 iid = ((na_fcentry_e_t *)na)->na_iid;
1089 na->na_iid = inp->in_iid;
1092 na->na_task_flags = inp->in_task_flags & TASK_FLAGS_RESERVED_MASK;
1093 na->na_seqid = inp->in_seqid;
1094 na->na_flags = NAFC_RCOUNT;
1095 na->na_status = inp->in_status;
1096 if (inp->in_status == IN_RESET) {
1097 na->na_flags |= NAFC_RST_CLRD;
1099 if (inp->in_status == IN_MSG_RECEIVED) {
1100 na->na_flags |= NAFC_TVALID;
1101 na->na_response = 0; /* XXX SUCCEEDED XXX */
1104 na->na_flags = NAFC_RST_CLRD;
1106 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
1107 na->na_header.rqs_entry_count = 1;
1108 if (ISP_CAP_2KLOGIN(isp)) {
1109 isp_put_notify_ack_fc_e(isp, (na_fcentry_e_t *) na, (na_fcentry_e_t *)outp);
1111 isp_put_notify_ack_fc(isp, na, (na_fcentry_t *)outp);
1113 isp_prt(isp, ISP_LOGTDEBUG0, "notify ack loopid %u seqid %x flags %x tflags %x response %x", iid, na->na_seqid,
1114 na->na_flags, na->na_task_flags, na->na_response);
1116 na_entry_t *na = (na_entry_t *) storage;
1118 in_entry_t *inp = arg;
1119 ISP_MEMCPY(storage, arg, sizeof (isphdr_t));
1120 na->na_iid = inp->in_iid;
1121 na->na_lun = inp->in_lun;
1122 na->na_tgt = inp->in_tgt;
1123 na->na_seqid = inp->in_seqid;
1124 if (inp->in_status == IN_RESET) {
1125 na->na_event = NA_RST_CLRD;
1128 na->na_event = NA_RST_CLRD;
1130 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
1131 na->na_header.rqs_entry_count = 1;
1132 isp_put_notify_ack(isp, na, (na_entry_t *)outp);
1133 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);
1135 ISP_TDQE(isp, "isp_notify_ack", isp->isp_reqidx, storage);
1136 ISP_SYNC_REQUEST(isp);
1141 isp_acknak_abts(ispsoftc_t *isp, void *arg, int errno)
1143 char storage[QENTRY_LEN];
1147 abts_rsp_t *rsp = (abts_rsp_t *) storage;
1150 if (!IS_24XX(isp)) {
1151 isp_prt(isp, ISP_LOGERR, "%s: called for non-24XX card", __func__);
1155 if (abts->abts_header.rqs_entry_type != RQSTYPE_ABTS_RCVD) {
1156 isp_prt(isp, ISP_LOGERR, "%s: called for non-ABTS entry (0x%x)", __func__, abts->abts_header.rqs_entry_type);
1160 outp = isp_getrqentry(isp);
1162 isp_prt(isp, ISP_LOGWARN, rqo, __func__);
1166 ISP_MEMCPY(rsp, abts, QENTRY_LEN);
1167 rsp->abts_rsp_header.rqs_entry_type = RQSTYPE_ABTS_RSP;
1170 * Swap destination and source for response.
1172 rsp->abts_rsp_r_ctl = BA_ACC;
1173 tmpw = rsp->abts_rsp_did_lo;
1174 tmpb = rsp->abts_rsp_did_hi;
1175 rsp->abts_rsp_did_lo = rsp->abts_rsp_sid_lo;
1176 rsp->abts_rsp_did_hi = rsp->abts_rsp_sid_hi;
1177 rsp->abts_rsp_sid_lo = tmpw;
1178 rsp->abts_rsp_sid_hi = tmpb;
1180 rsp->abts_rsp_f_ctl_hi ^= 0x80; /* invert Exchange Context */
1181 rsp->abts_rsp_f_ctl_hi &= ~0x7f; /* clear Sequence Initiator and other bits */
1182 rsp->abts_rsp_f_ctl_hi |= 0x10; /* abort the whole exchange */
1183 rsp->abts_rsp_f_ctl_hi |= 0x8; /* last data frame of sequence */
1184 rsp->abts_rsp_f_ctl_hi |= 0x1; /* transfer Sequence Initiative */
1185 rsp->abts_rsp_f_ctl_lo = 0;
1188 uint16_t rx_id, ox_id;
1190 rx_id = rsp->abts_rsp_rx_id;
1191 ox_id = rsp->abts_rsp_ox_id;
1192 ISP_MEMZERO(&rsp->abts_rsp_payload.ba_acc, sizeof (rsp->abts_rsp_payload.ba_acc));
1193 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);
1194 rsp->abts_rsp_payload.ba_acc.aborted_rx_id = rx_id;
1195 rsp->abts_rsp_payload.ba_acc.aborted_ox_id = ox_id;
1196 rsp->abts_rsp_payload.ba_acc.high_seq_cnt = 0xffff;
1198 ISP_MEMZERO(&rsp->abts_rsp_payload.ba_rjt, sizeof (rsp->abts_rsp_payload.ba_acc));
1201 rsp->abts_rsp_payload.ba_rjt.reason = 5; /* Logical Busy */
1204 rsp->abts_rsp_payload.ba_rjt.reason = 9; /* Unable to perform command request */
1210 * The caller will have set response values as appropriate
1211 * in the ABTS structure just before calling us.
1213 isp_put_abts_rsp(isp, rsp, (abts_rsp_t *)outp);
1214 ISP_TDQE(isp, "isp_acknak_abts", isp->isp_reqidx, storage);
1215 ISP_SYNC_REQUEST(isp);
1220 isp_handle_atio(ispsoftc_t *isp, at_entry_t *aep)
1225 * The firmware status (except for the QLTM_SVALID bit) indicates
1226 * why this ATIO was sent to us.
1228 * If QLTM_SVALID is set, the firware has recommended Sense Data.
1230 * If the DISCONNECTS DISABLED bit is set in the flags field,
1231 * we're still connected on the SCSI bus - i.e. the initiator
1232 * did not set DiscPriv in the identify message. We don't care
1233 * about this so it's ignored.
1236 switch (aep->at_status & ~QLTM_SVALID) {
1237 case AT_PATH_INVALID:
1239 * ATIO rejected by the firmware due to disabled lun.
1241 isp_prt(isp, ISP_LOGERR, "rejected ATIO for disabled lun %d", lun);
1245 * Requested Capability not available
1246 * We sent an ATIO that overflowed the firmware's
1247 * command resource count.
1249 isp_prt(isp, ISP_LOGERR, "rejected ATIO for lun %d because of command count overflow", lun);
1254 * If we send an ATIO to the firmware to increment
1255 * its command resource count, and the firmware is
1256 * recovering from a Bus Device Reset, it returns
1257 * the ATIO with this status. We set the command
1258 * resource count in the Enable Lun entry and do
1259 * not increment it. Therefore we should never get
1262 isp_prt(isp, ISP_LOGERR, atiocope, lun, GET_BUS_VAL(aep->at_iid));
1265 case AT_CDB: /* Got a CDB */
1266 case AT_PHASE_ERROR: /* Bus Phase Sequence Error */
1268 * Punt to platform specific layer.
1270 isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
1275 * A bus reset came along and blew away this command. Why
1276 * they do this in addition the async event code stuff,
1279 * Ignore it because the async event will clear things
1282 isp_prt(isp, ISP_LOGWARN, atior, lun, GET_IID_VAL(aep->at_iid), GET_BUS_VAL(aep->at_iid));
1287 isp_prt(isp, ISP_LOGERR, "Unknown ATIO status 0x%x from loopid %d for lun %d", aep->at_status, aep->at_iid, lun);
1288 (void) isp_target_put_atio(isp, aep);
1294 isp_handle_atio2(ispsoftc_t *isp, at2_entry_t *aep)
1298 if (ISP_CAP_SCCFW(isp)) {
1299 lun = aep->at_scclun;
1304 if (ISP_CAP_2KLOGIN(isp)) {
1305 iid = ((at2e_entry_t *)aep)->at_iid;
1311 * The firmware status (except for the QLTM_SVALID bit) indicates
1312 * why this ATIO was sent to us.
1314 * If QLTM_SVALID is set, the firware has recommended Sense Data.
1316 * If the DISCONNECTS DISABLED bit is set in the flags field,
1317 * we're still connected on the SCSI bus - i.e. the initiator
1318 * did not set DiscPriv in the identify message. We don't care
1319 * about this so it's ignored.
1322 switch (aep->at_status & ~QLTM_SVALID) {
1323 case AT_PATH_INVALID:
1325 * ATIO rejected by the firmware due to disabled lun.
1327 isp_prt(isp, ISP_LOGERR, "rejected ATIO2 for disabled lun %d", lun);
1331 * Requested Capability not available
1332 * We sent an ATIO that overflowed the firmware's
1333 * command resource count.
1335 isp_prt(isp, ISP_LOGERR, "rejected ATIO2 for lun %d- command count overflow", lun);
1340 * If we send an ATIO to the firmware to increment
1341 * its command resource count, and the firmware is
1342 * recovering from a Bus Device Reset, it returns
1343 * the ATIO with this status. We set the command
1344 * resource count in the Enable Lun entry and no
1345 * not increment it. Therefore we should never get
1348 isp_prt(isp, ISP_LOGERR, atiocope, lun, 0);
1351 case AT_CDB: /* Got a CDB */
1353 * Punt to platform specific layer.
1355 isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
1360 * A bus reset came along an blew away this command. Why
1361 * they do this in addition the async event code stuff,
1364 * Ignore it because the async event will clear things
1367 isp_prt(isp, ISP_LOGERR, atior, lun, iid, 0);
1372 isp_prt(isp, ISP_LOGERR, "Unknown ATIO2 status 0x%x from loopid %d for lun %d", aep->at_status, iid, lun);
1373 (void) isp_target_put_atio(isp, aep);
1379 isp_handle_ctio(ispsoftc_t *isp, ct_entry_t *ct)
1382 int pl = ISP_LOGTDEBUG2;
1385 if (ct->ct_syshandle) {
1386 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1394 switch (ct->ct_status & ~QLTM_SVALID) {
1397 * There are generally 3 possibilities as to why we'd get
1399 * We disconnected after receiving a CDB.
1400 * We sent or received data.
1401 * We sent status & command complete.
1404 if (ct->ct_flags & CT_SENDSTATUS) {
1406 } else if ((ct->ct_flags & CT_DATAMASK) == CT_NO_DATA) {
1408 * Nothing to do in this case.
1410 isp_prt(isp, pl, "CTIO- iid %d disconnected OK", ct->ct_iid);
1417 * Bus Device Reset message received or the SCSI Bus has
1418 * been Reset; the firmware has gone to Bus Free.
1420 * The firmware generates an async mailbox interrupt to
1421 * notify us of this and returns outstanding CTIOs with this
1422 * status. These CTIOs are handled in that same way as
1423 * CT_ABORTED ones, so just fall through here.
1425 fmsg = "Bus Device Reset";
1433 * When an Abort message is received the firmware goes to
1434 * Bus Free and returns all outstanding CTIOs with the status
1435 * set, then sends us an Immediate Notify entry.
1438 fmsg = "ABORT TAG message sent by Initiator";
1439 isp_prt(isp, ISP_LOGTDEBUG0, "CTIO destroyed by %s", fmsg);
1444 * CTIO rejected by the firmware due to disabled lun.
1447 isp_prt(isp, ISP_LOGERR, "Firmware rejected CTIO for disabled lun %d", ct->ct_lun);
1452 * CTIO rejected by the firmware due "no path for the
1453 * nondisconnecting nexus specified". This means that
1454 * we tried to access the bus while a non-disconnecting
1455 * command is in process.
1457 isp_prt(isp, ISP_LOGERR, "Firmware rejected CTIO for bad nexus %d/%d/%d", ct->ct_iid, ct->ct_tgt, ct->ct_lun);
1461 fmsg = "Reselection";
1466 isp_prt(isp, ISP_LOGWARN, "Firmware timed out on %s", fmsg);
1471 fmsg = "Unrecoverable Error";
1475 fmsg = "Completed with Error";
1477 case CT_PHASE_ERROR:
1479 fmsg = "Phase Sequence Error";
1483 fmsg = "terminated by TERMINATE TRANSFER";
1487 fmsg = "unacknowledged Immediate Notify pending";
1488 isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg);
1491 isp_prt(isp, ISP_LOGERR, "Unknown CTIO status 0x%x", ct->ct_status & ~QLTM_SVALID);
1497 * There may be more than one CTIO for a data transfer,
1498 * or this may be a status CTIO we're not monitoring.
1500 * The assumption is that they'll all be returned in the
1501 * order we got them.
1503 if (ct->ct_syshandle == 0) {
1504 if ((ct->ct_flags & CT_SENDSTATUS) == 0) {
1505 isp_prt(isp, pl, "intermediate CTIO completed ok");
1507 isp_prt(isp, pl, "unmonitored CTIO completed ok");
1510 isp_prt(isp, pl, "NO xs for CTIO (handle 0x%x) status 0x%x", ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1514 * Final CTIO completed. Release DMA resources and
1515 * notify platform dependent layers.
1517 if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) {
1518 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1520 isp_prt(isp, pl, "final CTIO complete");
1522 * The platform layer will destroy the handle if appropriate.
1524 isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1529 isp_handle_ctio2(ispsoftc_t *isp, ct2_entry_t *ct)
1532 int pl = ISP_LOGTDEBUG2;
1535 if (ct->ct_syshandle) {
1536 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1544 switch (ct->ct_status & ~QLTM_SVALID) {
1546 isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error");
1552 * There are generally 2 possibilities as to why we'd get
1554 * We sent or received data.
1555 * We sent status & command complete.
1562 * Target Reset function received.
1564 * The firmware generates an async mailbox interrupt to
1565 * notify us of this and returns outstanding CTIOs with this
1566 * status. These CTIOs are handled in that same way as
1567 * CT_ABORTED ones, so just fall through here.
1569 fmsg = "TARGET RESET";
1577 * When an Abort message is received the firmware goes to
1578 * Bus Free and returns all outstanding CTIOs with the status
1579 * set, then sends us an Immediate Notify entry.
1585 isp_prt(isp, ISP_LOGTDEBUG0, "CTIO2 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid);
1590 * CTIO rejected by the firmware - invalid data direction.
1592 isp_prt(isp, ISP_LOGERR, "CTIO2 had wrong data direction");
1596 fmsg = "failure to reconnect to initiator";
1601 isp_prt(isp, ISP_LOGWARN, "Firmware timed out on %s", fmsg);
1605 fmsg = "Completed with Error";
1609 fmsg = "Port Logout";
1611 case CT_PORTUNAVAIL:
1613 fmsg = "Port not available";
1615 case CT_PORTCHANGED:
1617 fmsg = "Port Changed";
1621 fmsg = "unacknowledged Immediate Notify pending";
1622 isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg);
1627 * CTIO rejected by the firmware because an invalid RX_ID.
1628 * Just print a message.
1630 isp_prt(isp, ISP_LOGWARN, "CTIO2 completed with Invalid RX_ID 0x%x", ct->ct_rxid);
1634 isp_prt(isp, ISP_LOGERR, "Unknown CTIO2 status 0x%x", ct->ct_status & ~QLTM_SVALID);
1640 * There may be more than one CTIO for a data transfer,
1641 * or this may be a status CTIO we're not monitoring.
1643 * The assumption is that they'll all be returned in the
1644 * order we got them.
1646 if (ct->ct_syshandle == 0) {
1647 if ((ct->ct_flags & CT2_SENDSTATUS) == 0) {
1648 isp_prt(isp, pl, "intermediate CTIO completed ok");
1650 isp_prt(isp, pl, "unmonitored CTIO completed ok");
1653 isp_prt(isp, pl, "NO xs for CTIO (handle 0x%x) status 0x%x", ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1656 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
1657 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1659 if (ct->ct_flags & CT2_SENDSTATUS) {
1661 * Sent status and command complete.
1663 * We're now really done with this command, so we
1664 * punt to the platform dependent layers because
1665 * only there can we do the appropriate command
1666 * complete thread synchronization.
1668 isp_prt(isp, pl, "status CTIO complete");
1671 * Final CTIO completed. Release DMA resources and
1672 * notify platform dependent layers.
1674 isp_prt(isp, pl, "data CTIO complete");
1676 isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1678 * The platform layer will destroy the handle if appropriate.
1684 isp_handle_ctio7(ispsoftc_t *isp, ct7_entry_t *ct)
1687 int pl = ISP_LOGTDEBUG2;
1690 if (ct->ct_syshandle) {
1691 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1699 switch (ct->ct_nphdl) {
1701 isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error");
1704 case CT7_DATA_UNDER:
1707 * There are generally 2 possibilities as to why we'd get
1709 * We sent or received data.
1710 * We sent status & command complete.
1722 * When an Abort message is received the firmware goes to
1723 * Bus Free and returns all outstanding CTIOs with the status
1724 * set, then sends us an Immediate Notify entry.
1729 isp_prt(isp, ISP_LOGTDEBUG0, "CTIO7 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid);
1736 isp_prt(isp, ISP_LOGWARN, "Firmware timed out on %s", fmsg);
1740 fmsg = "Completed with Error";
1744 fmsg = "Port Logout";
1747 case CT7_PORTUNAVAIL:
1749 fmsg = "Port not available";
1752 case CT7_PORTCHANGED:
1754 fmsg = "Port Changed";
1756 isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg);
1761 * CTIO rejected by the firmware because an invalid RX_ID.
1762 * Just print a message.
1764 isp_prt(isp, ISP_LOGWARN, "CTIO7 completed with Invalid RX_ID 0x%x", ct->ct_rxid);
1767 case CT7_REASSY_ERR:
1768 isp_prt(isp, ISP_LOGWARN, "reassembly error");
1772 isp_prt(isp, ISP_LOGWARN, "SRR received");
1776 isp_prt(isp, ISP_LOGERR, "Unknown CTIO7 status 0x%x", ct->ct_nphdl);
1782 * There may be more than one CTIO for a data transfer,
1783 * or this may be a status CTIO we're not monitoring.
1785 * The assumption is that they'll all be returned in the
1786 * order we got them.
1788 if (ct->ct_syshandle == 0) {
1789 if (ct->ct_flags & CT7_TERMINATE) {
1790 isp_prt(isp, ISP_LOGINFO, "termination of 0x%x complete", ct->ct_rxid);
1791 } else if ((ct->ct_flags & CT7_SENDSTATUS) == 0) {
1792 isp_prt(isp, pl, "intermediate CTIO completed ok");
1794 isp_prt(isp, pl, "unmonitored CTIO completed ok");
1797 isp_prt(isp, pl, "NO xs for CTIO (handle 0x%x) status 0x%x", ct->ct_syshandle, ct->ct_nphdl);
1800 if ((ct->ct_flags & CT7_DATAMASK) != CT7_NO_DATA) {
1801 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1803 if (ct->ct_flags & CT7_SENDSTATUS) {
1805 * Sent status and command complete.
1807 * We're now really done with this command, so we
1808 * punt to the platform dependent layers because
1809 * only there can we do the appropriate command
1810 * complete thread synchronization.
1812 isp_prt(isp, pl, "status CTIO complete");
1815 * Final CTIO completed. Release DMA resources and
1816 * notify platform dependent layers.
1818 isp_prt(isp, pl, "data CTIO complete");
1820 isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1822 * The platform layer will destroy the handle if appropriate.
1828 isp_handle_24xx_inotify(ispsoftc_t *isp, in_fcentry_24xx_t *inot_24xx)
1830 uint8_t ochan, chan, lochan, hichan;
1833 * Check to see whether we got a wildcard channel.
1834 * If so, we have to iterate over all channels.
1836 ochan = chan = ISP_GET_VPIDX(isp, inot_24xx->in_vpidx);
1839 hichan = isp->isp_nchan;
1841 if (chan >= isp->isp_nchan) {
1843 ISP_SNPRINTF(buf, sizeof buf, "%s: bad channel %d for status 0x%x", __func__, chan, inot_24xx->in_status);
1844 isp_print_bytes(isp, buf, QENTRY_LEN, inot_24xx);
1845 (void) isp_notify_ack(isp, inot_24xx);
1851 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);
1852 for (chan = lochan; chan < hichan; chan++) {
1853 switch (inot_24xx->in_status) {
1854 case IN24XX_LIP_RESET:
1855 case IN24XX_LINK_RESET:
1856 case IN24XX_PORT_LOGOUT:
1857 case IN24XX_PORT_CHANGED:
1858 case IN24XX_LINK_FAILED:
1859 case IN24XX_SRR_RCVD:
1860 case IN24XX_ELS_RCVD:
1861 inot_24xx->in_vpidx = chan;
1862 isp_async(isp, ISPASYNC_TARGET_ACTION, inot_24xx);
1865 isp_prt(isp, ISP_LOGINFO, "%s: unhandled status (0x%x) for chan %d", __func__, inot_24xx->in_status, chan);
1866 (void) isp_notify_ack(isp, inot_24xx);
1870 inot_24xx->in_vpidx = ochan;