2 * Machine and OS Independent Target Mode Code for the Qlogic SCSI/FC adapters.
4 * Copyright (c) 1997-2006 by Matthew Jacob
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice immediately at the beginning of the file, without modification,
12 * this list of conditions, and the following disclaimer.
13 * 2. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
34 * Bug fixes gratefully acknowledged from:
35 * Oded Kedem <oded@kashya.com>
38 * Include header file appropriate for platform we're building on.
42 #include <dev/ic/isp_netbsd.h>
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[] =
56 "ATIO returned for lun %d because it was in the middle of Bus Device Reset "
58 static const char atior[] =
59 "ATIO returned on for lun %d on from IID %d because a Bus Reset occurred "
62 static void isp_got_msg(ispsoftc_t *, in_entry_t *);
63 static void isp_got_msg_fc(ispsoftc_t *, in_fcentry_t *);
64 static void isp_handle_atio(ispsoftc_t *, at_entry_t *);
65 static void isp_handle_atio2(ispsoftc_t *, at2_entry_t *);
66 static void isp_handle_ctio(ispsoftc_t *, ct_entry_t *);
67 static void isp_handle_ctio2(ispsoftc_t *, ct2_entry_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, uint16_t *optrp)
118 uint16_t status, seqid;
122 at2e_entry_t *at2eiop;
125 ct2e_entry_t *ct2eiop;
128 in_fcentry_t *inot_fcp;
129 in_fcentry_e_t *inote_fcp;
131 na_fcentry_t *nack_fcp;
132 na_fcentry_e_t *nacke_fcp;
135 #define atiop unp.atiop
136 #define at2iop unp.at2iop
137 #define at2eiop unp.at2eiop
138 #define ctiop unp.ctiop
139 #define ct2iop unp.ct2iop
140 #define ct2eiop unp.ct2eiop
141 #define lunenp unp.lunenp
142 #define inotp unp.inotp
143 #define inot_fcp unp.inot_fcp
144 #define inote_fcp unp.inote_fcp
145 #define nackp unp.nackp
146 #define nack_fcp unp.nack_fcp
147 #define nacke_fcp unp.nacke_fcp
150 uint8_t local[QENTRY_LEN];
151 int bus, type, rval = 1;
153 type = isp_get_response_type(isp, (isphdr_t *)vptr);
156 ISP_TDQE(isp, "isp_target_notify", (int) *optrp, vptr);
160 isp_get_atio(isp, atiop, (at_entry_t *) local);
161 isp_handle_atio(isp, (at_entry_t *) local);
164 isp_get_ctio(isp, ctiop, (ct_entry_t *) local);
165 isp_handle_ctio(isp, (ct_entry_t *) local);
169 isp_get_atio2e(isp, at2eiop, (at2e_entry_t *) local);
171 isp_get_atio2(isp, at2iop, (at2_entry_t *) local);
172 isp_handle_atio2(isp, (at2_entry_t *) local);
177 isp_get_ctio2e(isp, ct2eiop, (ct2e_entry_t *) local);
179 isp_get_ctio2(isp, ct2iop, (ct2_entry_t *) local);
180 isp_handle_ctio2(isp, (ct2_entry_t *) local);
182 case RQSTYPE_ENABLE_LUN:
183 case RQSTYPE_MODIFY_LUN:
184 isp_get_enable_lun(isp, lunenp, (lun_entry_t *) local);
185 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, local);
190 * Either the ISP received a SCSI message it can't
191 * handle, or it's returning an Immed. Notify entry
192 * we sent. We can send Immed. Notify entries to
193 * increment the firmware's resource count for them
194 * (we set this initially in the Enable Lun entry).
199 isp_get_notify_fc_e(isp, inote_fcp, (in_fcentry_e_t *)local);
200 isp_get_notify_fc(isp, inot_fcp, (in_fcentry_t *)local);
201 inot_fcp = (in_fcentry_t *) local;
202 status = inot_fcp->in_status;
203 seqid = inot_fcp->in_seqid;
205 isp_get_notify(isp, inotp, (in_entry_t *)local);
206 inotp = (in_entry_t *) local;
207 status = inotp->in_status & 0xff;
208 seqid = inotp->in_seqid;
209 if (IS_DUALBUS(isp)) {
210 bus = GET_BUS_VAL(inotp->in_iid);
211 SET_BUS_VAL(inotp->in_iid, 0);
214 isp_prt(isp, ISP_LOGTDEBUG0,
215 "Immediate Notify On Bus %d, status=0x%x seqid=0x%x",
219 case IN_MSG_RECEIVED:
220 case IN_IDE_RECEIVED:
222 isp_got_msg_fc(isp, (in_fcentry_t *)local);
224 isp_got_msg(isp, (in_entry_t *)local);
227 case IN_RSRC_UNAVAIL:
228 isp_prt(isp, ISP_LOGWARN, "Firmware out of ATIOs");
229 isp_notify_ack(isp, local);
232 (void) isp_target_async(isp, 0, ASYNC_BUS_RESET);
236 case IN_PORT_CHANGED:
238 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, &local);
241 isp_prt(isp, ISP_LOGERR,
242 "bad status (0x%x) in isp_target_notify", status);
243 isp_notify_ack(isp, local);
248 case RQSTYPE_NOTIFY_ACK:
250 * The ISP is acknowledging our acknowledgement of an
251 * Immediate Notify entry for some asynchronous event.
255 isp_get_notify_ack_fc_e(isp, nacke_fcp,
256 (na_fcentry_e_t *)local);
258 isp_get_notify_ack_fc(isp, nack_fcp,
259 (na_fcentry_t *)local);
260 nack_fcp = (na_fcentry_t *)local;
261 isp_prt(isp, ISP_LOGTDEBUG1,
262 "Notify Ack status=0x%x seqid 0x%x",
263 nack_fcp->na_status, nack_fcp->na_seqid);
265 isp_get_notify_ack(isp, nackp, (na_entry_t *)local);
266 nackp = (na_entry_t *)local;
267 isp_prt(isp, ISP_LOGTDEBUG1,
268 "Notify Ack event 0x%x status=0x%x seqid 0x%x",
269 nackp->na_event, nackp->na_status, nackp->na_seqid);
273 isp_prt(isp, ISP_LOGERR,
274 "Unknown entry type 0x%x in isp_target_notify", type);
297 * Toggle (on/off) target mode for bus/target/lun
299 * The caller has checked for overlap and legality.
301 * Note that not all of bus, target or lun can be paid attention to.
302 * Note also that this action will not be complete until the f/w writes
303 * response entry. The caller is responsible for synchronizing this.
306 isp_lun_cmd(ispsoftc_t *isp, int cmd, int bus, int tgt, int lun,
307 int cmd_cnt, int inot_cnt, uint32_t opaque)
314 MEMZERO(&el, sizeof (el));
315 if (IS_DUALBUS(isp)) {
316 el.le_rsvd = (bus & 0x1) << 7;
318 el.le_cmd_count = cmd_cnt;
319 el.le_in_count = inot_cnt;
320 if (cmd == RQSTYPE_ENABLE_LUN) {
322 el.le_flags = LUN_TQAE|LUN_DISAD;
326 } else if (cmd == -RQSTYPE_ENABLE_LUN) {
327 cmd = RQSTYPE_ENABLE_LUN;
330 } else if (cmd == -RQSTYPE_MODIFY_LUN) {
331 cmd = RQSTYPE_MODIFY_LUN;
332 el.le_ops = LUN_CCDECR | LUN_INDECR;
334 el.le_ops = LUN_CCINCR | LUN_ININCR;
336 el.le_header.rqs_entry_type = cmd;
337 el.le_header.rqs_entry_count = 1;
338 el.le_reserved = opaque;
342 } else if ((FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) == 0) {
346 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
347 isp_prt(isp, ISP_LOGERR,
348 "Request Queue Overflow in isp_lun_cmd");
351 ISP_TDQE(isp, "isp_lun_cmd", (int) optr, &el);
352 isp_put_enable_lun(isp, &el, outp);
353 ISP_ADD_REQUEST(isp, nxti);
359 isp_target_put_entry(ispsoftc_t *isp, void *ap)
363 uint8_t etype = ((isphdr_t *) ap)->rqs_entry_type;
365 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
366 isp_prt(isp, ISP_LOGWARN,
367 "Request Queue Overflow in isp_target_put_entry");
372 isp_put_atio(isp, (at_entry_t *) ap, (at_entry_t *) outp);
375 isp_put_atio2(isp, (at2_entry_t *) ap, (at2_entry_t *) outp);
378 isp_put_ctio(isp, (ct_entry_t *) ap, (ct_entry_t *) outp);
381 isp_put_ctio2(isp, (ct2_entry_t *) ap, (ct2_entry_t *) outp);
384 isp_prt(isp, ISP_LOGERR,
385 "Unknown type 0x%x in isp_put_entry", etype);
389 ISP_TDQE(isp, "isp_target_put_entry", (int) optr, ap);
390 ISP_ADD_REQUEST(isp, nxti);
395 isp_target_put_atio(ispsoftc_t *isp, void *arg)
400 at2e_entry_t _atio2e;
403 MEMZERO(&atun, sizeof atun);
405 at2_entry_t *aep = arg;
406 atun._atio2.at_header.rqs_entry_type = RQSTYPE_ATIO2;
407 atun._atio2.at_header.rqs_entry_count = 1;
408 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
409 atun._atio2.at_scclun = (uint16_t) aep->at_scclun;
411 atun._atio2.at_lun = (uint8_t) aep->at_lun;
413 if (IS_2KLOGIN(isp)) {
414 atun._atio2e.at_iid = ((at2e_entry_t *)aep)->at_iid;
416 atun._atio2.at_iid = aep->at_iid;
418 atun._atio2.at_rxid = aep->at_rxid;
419 atun._atio2.at_status = CT_OK;
421 at_entry_t *aep = arg;
422 atun._atio.at_header.rqs_entry_type = RQSTYPE_ATIO;
423 atun._atio.at_header.rqs_entry_count = 1;
424 atun._atio.at_handle = aep->at_handle;
425 atun._atio.at_iid = aep->at_iid;
426 atun._atio.at_tgt = aep->at_tgt;
427 atun._atio.at_lun = aep->at_lun;
428 atun._atio.at_tag_type = aep->at_tag_type;
429 atun._atio.at_tag_val = aep->at_tag_val;
430 atun._atio.at_status = (aep->at_flags & AT_TQAE);
431 atun._atio.at_status |= CT_OK;
433 return (isp_target_put_entry(isp, &atun));
437 * Command completion- both for handling cases of no resources or
438 * no blackhole driver, or other cases where we have to, inline,
439 * finish the command sanely, or for normal command completion.
441 * The 'completion' code value has the scsi status byte in the low 8 bits.
442 * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have
443 * the sense key and bits 16..23 have the ASCQ and bits 24..31 have the ASC
446 * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't
447 * NB: inline SCSI sense reporting. As such, we lose this information. XXX.
449 * For both parallel && fibre channel, we use the feature that does
450 * an automatic resource autoreplenish so we don't have then later do
451 * put of an atio to replenish the f/w's resource count.
455 isp_endcmd(ispsoftc_t *isp, void *arg, uint32_t code, uint16_t hdl)
461 ct2e_entry_t _ctio2e;
464 MEMZERO(&un, sizeof un);
468 at2_entry_t *aep = arg;
469 ct2_entry_t *cto = &un._ctio2;
471 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
472 cto->ct_header.rqs_entry_count = 1;
473 if ((FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) == 0) {
474 cto->ct_lun = aep->at_lun;
476 if (IS_2KLOGIN(isp)) {
477 un._ctio2e.ct_iid = ((at2e_entry_t *)aep)->at_iid;
479 cto->ct_iid = aep->at_iid;
481 cto->ct_rxid = aep->at_rxid;
482 cto->rsp.m1.ct_scsi_status = sts;
483 cto->ct_flags = CT2_SENDSTATUS | CT2_NO_DATA | CT2_FLAG_MODE1;
485 cto->ct_flags |= CT2_CCINCR;
487 if (aep->at_datalen) {
488 cto->ct_resid = aep->at_datalen;
489 cto->rsp.m1.ct_scsi_status |= CT2_DATA_UNDER;
491 if (sts == SCSI_CHECK && (code & ECMD_SVALID)) {
492 cto->rsp.m1.ct_resp[0] = 0xf0;
493 cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
494 cto->rsp.m1.ct_resp[7] = 8;
495 cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff;
496 cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff;
497 cto->rsp.m1.ct_senselen = 16;
498 cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID;
500 cto->ct_syshandle = hdl;
502 at_entry_t *aep = arg;
503 ct_entry_t *cto = &un._ctio;
505 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
506 cto->ct_header.rqs_entry_count = 1;
507 cto->ct_fwhandle = aep->at_handle;
508 cto->ct_iid = aep->at_iid;
509 cto->ct_tgt = aep->at_tgt;
510 cto->ct_lun = aep->at_lun;
511 cto->ct_tag_type = aep->at_tag_type;
512 cto->ct_tag_val = aep->at_tag_val;
513 if (aep->at_flags & AT_TQAE) {
514 cto->ct_flags |= CT_TQAE;
516 cto->ct_flags = CT_SENDSTATUS | CT_NO_DATA;
518 cto->ct_flags |= CT_CCINCR;
520 cto->ct_scsi_status = sts;
521 cto->ct_syshandle = hdl;
523 return (isp_target_put_entry(isp, &un));
527 * These are either broadcast events or specifically CTIO fast completion
530 isp_target_async(ispsoftc_t *isp, int bus, int event)
534 MEMZERO(¬ify, sizeof (tmd_notify_t));
536 notify.nt_iid = INI_ANY;
537 /* nt_tgt set in outer layers */
538 notify.nt_lun = LUN_ANY;
539 notify.nt_tagval = TAG_ANY;
542 TAG_INSERT_BUS(notify.nt_tagval, bus);
548 notify.nt_ncode = NT_LINK_UP;
549 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
551 case ASYNC_LOOP_DOWN:
552 notify.nt_ncode = NT_LINK_DOWN;
553 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
556 case ASYNC_LIP_OCCURRED:
557 case ASYNC_LOOP_RESET:
558 notify.nt_ncode = NT_LIP_RESET;
559 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
561 case ASYNC_BUS_RESET:
562 case ASYNC_TIMEOUT_RESET: /* XXX: where does this come from ? */
563 notify.nt_ncode = NT_BUS_RESET;
564 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
566 case ASYNC_DEVICE_RESET:
567 notify.nt_ncode = NT_TARGET_RESET;
568 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
570 case ASYNC_CTIO_DONE:
572 uint8_t storage[QENTRY_LEN];
573 memset(storage, 0, QENTRY_LEN);
575 ct2_entry_t *ct = (ct2_entry_t *) storage;
576 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
577 ct->ct_status = CT_OK;
578 ct->ct_syshandle = bus;
579 ct->ct_flags = CT2_SENDSTATUS|CT2_FASTPOST;
581 ct_entry_t *ct = (ct_entry_t *) storage;
582 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO;
583 ct->ct_status = CT_OK;
584 ct->ct_fwhandle = bus;
585 ct->ct_flags = CT_SENDSTATUS;
587 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, storage);
591 isp_prt(isp, ISP_LOGERR,
592 "isp_target_async: unknown event 0x%x", event);
593 if (isp->isp_state == ISP_RUNSTATE) {
594 isp_notify_ack(isp, NULL);
603 * Process a received message.
604 * The ISP firmware can handle most messages, there are only
605 * a few that we need to deal with:
606 * - abort: clean up the current command
607 * - abort tag and clear queue
611 isp_got_msg(ispsoftc_t *isp, in_entry_t *inp)
614 uint8_t status = inp->in_status & ~QLTM_SVALID;
616 MEMZERO(&nt, sizeof (nt));
618 nt.nt_iid = GET_IID_VAL(inp->in_iid);
619 nt.nt_tgt = inp->in_tgt;
620 nt.nt_lun = inp->in_lun;
621 IN_MAKE_TAGID(nt.nt_tagval, 0, inp);
622 nt.nt_lreserved = inp;
624 if (status == IN_IDE_RECEIVED || status == IN_MSG_RECEIVED) {
625 switch (inp->in_msg[0]) {
627 nt.nt_ncode = NT_ABORT_TASK_SET;
629 case MSG_BUS_DEV_RESET:
630 nt.nt_ncode = NT_TARGET_RESET;
633 nt.nt_ncode = NT_ABORT_TASK;
635 case MSG_CLEAR_QUEUE:
636 nt.nt_ncode = NT_CLEAR_TASK_SET;
638 case MSG_REL_RECOVERY:
639 nt.nt_ncode = NT_CLEAR_ACA;
641 case MSG_TERM_IO_PROC:
642 nt.nt_ncode = NT_ABORT_TASK;
645 nt.nt_ncode = NT_LUN_RESET;
648 isp_prt(isp, ISP_LOGERR,
649 "unhandled message 0x%x", inp->in_msg[0]);
650 isp_notify_ack(isp, inp);
653 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt);
655 isp_prt(isp, ISP_LOGERR,
656 "unknown immediate notify status 0x%x", inp->in_status);
657 isp_notify_ack(isp, inp);
662 * Synthesize a message from the task management flags in a FCP_CMND_IU.
665 isp_got_msg_fc(ispsoftc_t *isp, in_fcentry_t *inp)
668 static const char f1[] = "%s from iid 0x%08x%08x lun %d seq 0x%x";
669 static const char f2[] =
670 "unknown %s 0x%x lun %d iid 0x%08x%08x task flags 0x%x seq 0x%x\n";
673 MEMZERO(&nt, sizeof (tmd_notify_t));
675 if (IS_2KLOGIN(isp)) {
676 nt.nt_iid = ((in_fcentry_e_t *)inp)->in_iid;
677 seqid = ((in_fcentry_e_t *)inp)->in_seqid;
679 nt.nt_iid = inp->in_iid;
680 seqid = inp->in_seqid;
682 /* nt_tgt set in outer layers */
683 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
684 nt.nt_lun = inp->in_scclun;
686 nt.nt_lun = inp->in_lun;
688 IN_FC_MAKE_TAGID(nt.nt_tagval, 0, seqid);
689 nt.nt_lreserved = inp;
691 if (inp->in_status != IN_MSG_RECEIVED) {
692 isp_prt(isp, ISP_LOGINFO, f2, "immediate notify status",
693 inp->in_status, nt.nt_lun, (uint32_t) (nt.nt_iid >> 32), (uint32_t) nt.nt_iid,
694 inp->in_task_flags, inp->in_seqid);
695 isp_notify_ack(isp, inp);
699 if (inp->in_task_flags & TASK_FLAGS_ABORT_TASK_SET) {
700 isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET",
701 (uint32_t) (nt.nt_iid >> 32), (uint32_t) nt.nt_iid, nt.nt_lun, inp->in_seqid);
702 nt.nt_ncode = NT_ABORT_TASK_SET;
703 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_TASK_SET) {
704 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET",
705 (uint32_t) (nt.nt_iid >> 32), (uint32_t) nt.nt_iid, nt.nt_lun, inp->in_seqid);
706 nt.nt_ncode = NT_CLEAR_TASK_SET;
707 } else if (inp->in_task_flags & TASK_FLAGS_LUN_RESET) {
708 isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET",
709 (uint32_t) (nt.nt_iid >> 32), (uint32_t) nt.nt_iid, nt.nt_lun, inp->in_seqid);
710 nt.nt_ncode = NT_LUN_RESET;
711 } else if (inp->in_task_flags & TASK_FLAGS_TARGET_RESET) {
712 isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET",
713 (uint32_t) (nt.nt_iid >> 32), (uint32_t) nt.nt_iid, nt.nt_lun, inp->in_seqid);
714 nt.nt_ncode = NT_TARGET_RESET;
715 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_ACA) {
716 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA",
717 (uint32_t) (nt.nt_iid >> 32), (uint32_t) nt.nt_iid, nt.nt_lun, inp->in_seqid);
718 nt.nt_ncode = NT_CLEAR_ACA;
720 isp_prt(isp, ISP_LOGWARN, f2, "task flag",
721 inp->in_status, nt.nt_lun, (uint32_t) (nt.nt_iid >> 32), (uint32_t) nt.nt_iid,
722 inp->in_task_flags, inp->in_seqid);
723 isp_notify_ack(isp, inp);
726 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt);
730 isp_notify_ack(ispsoftc_t *isp, void *arg)
732 char storage[QENTRY_LEN];
736 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
737 isp_prt(isp, ISP_LOGWARN,
738 "Request Queue Overflow For isp_notify_ack");
742 MEMZERO(storage, QENTRY_LEN);
745 na_fcentry_t *na = (na_fcentry_t *) storage;
747 in_fcentry_t *inp = arg;
748 MEMCPY(storage, arg, sizeof (isphdr_t));
749 if (IS_2KLOGIN(isp)) {
750 ((na_fcentry_e_t *)na)->na_iid = ((in_fcentry_e_t *)inp)->in_iid;
752 na->na_iid = inp->in_iid;
754 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
755 na->na_lun = inp->in_scclun;
757 na->na_lun = inp->in_lun;
759 na->na_task_flags = inp->in_task_flags;
760 na->na_seqid = inp->in_seqid;
761 na->na_flags = NAFC_RCOUNT;
762 na->na_status = inp->in_status;
763 if (inp->in_status == IN_RESET) {
764 na->na_flags |= NAFC_RST_CLRD;
767 na->na_flags = NAFC_RST_CLRD;
769 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
770 na->na_header.rqs_entry_count = 1;
771 if (IS_2KLOGIN(isp)) {
772 isp_put_notify_ack_fc_e(isp, (na_fcentry_e_t *) na, (na_fcentry_e_t *)outp);
774 isp_put_notify_ack_fc(isp, na, (na_fcentry_t *)outp);
777 na_entry_t *na = (na_entry_t *) storage;
779 in_entry_t *inp = arg;
780 MEMCPY(storage, arg, sizeof (isphdr_t));
781 na->na_iid = inp->in_iid;
782 na->na_lun = inp->in_lun;
783 na->na_tgt = inp->in_tgt;
784 na->na_seqid = inp->in_seqid;
785 if (inp->in_status == IN_RESET) {
786 na->na_event = NA_RST_CLRD;
789 na->na_event = NA_RST_CLRD;
791 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
792 na->na_header.rqs_entry_count = 1;
793 isp_put_notify_ack(isp, na, (na_entry_t *)outp);
795 ISP_TDQE(isp, "isp_notify_ack", (int) optr, storage);
796 ISP_ADD_REQUEST(isp, nxti);
800 isp_handle_atio(ispsoftc_t *isp, at_entry_t *aep)
805 * The firmware status (except for the QLTM_SVALID bit) indicates
806 * why this ATIO was sent to us.
808 * If QLTM_SVALID is set, the firware has recommended Sense Data.
810 * If the DISCONNECTS DISABLED bit is set in the flags field,
811 * we're still connected on the SCSI bus - i.e. the initiator
812 * did not set DiscPriv in the identify message. We don't care
813 * about this so it's ignored.
816 switch(aep->at_status & ~QLTM_SVALID) {
817 case AT_PATH_INVALID:
819 * ATIO rejected by the firmware due to disabled lun.
821 isp_prt(isp, ISP_LOGERR,
822 "rejected ATIO for disabled lun %d", lun);
826 * Requested Capability not available
827 * We sent an ATIO that overflowed the firmware's
828 * command resource count.
830 isp_prt(isp, ISP_LOGERR,
831 "rejected ATIO for lun %d because of command count"
837 * If we send an ATIO to the firmware to increment
838 * its command resource count, and the firmware is
839 * recovering from a Bus Device Reset, it returns
840 * the ATIO with this status. We set the command
841 * resource count in the Enable Lun entry and do
842 * not increment it. Therefore we should never get
845 isp_prt(isp, ISP_LOGERR, atiocope, lun,
846 GET_BUS_VAL(aep->at_iid));
849 case AT_CDB: /* Got a CDB */
850 case AT_PHASE_ERROR: /* Bus Phase Sequence Error */
852 * Punt to platform specific layer.
854 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
859 * A bus reset came along and blew away this command. Why
860 * they do this in addition the async event code stuff,
863 * Ignore it because the async event will clear things
866 isp_prt(isp, ISP_LOGWARN, atior, lun,
867 GET_IID_VAL(aep->at_iid), GET_BUS_VAL(aep->at_iid));
872 isp_prt(isp, ISP_LOGERR,
873 "Unknown ATIO status 0x%x from initiator %d for lun %d",
874 aep->at_status, aep->at_iid, lun);
875 (void) isp_target_put_atio(isp, aep);
881 isp_handle_atio2(ispsoftc_t *isp, at2_entry_t *aep)
885 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
886 lun = aep->at_scclun;
891 if (IS_2KLOGIN(isp)) {
892 iid = ((at2e_entry_t *)aep)->at_iid;
898 * The firmware status (except for the QLTM_SVALID bit) indicates
899 * why this ATIO was sent to us.
901 * If QLTM_SVALID is set, the firware has recommended Sense Data.
903 * If the DISCONNECTS DISABLED bit is set in the flags field,
904 * we're still connected on the SCSI bus - i.e. the initiator
905 * did not set DiscPriv in the identify message. We don't care
906 * about this so it's ignored.
909 switch(aep->at_status & ~QLTM_SVALID) {
910 case AT_PATH_INVALID:
912 * ATIO rejected by the firmware due to disabled lun.
914 isp_prt(isp, ISP_LOGERR,
915 "rejected ATIO2 for disabled lun %d", lun);
919 * Requested Capability not available
920 * We sent an ATIO that overflowed the firmware's
921 * command resource count.
923 isp_prt(isp, ISP_LOGERR,
924 "rejected ATIO2 for lun %d- command count overflow", lun);
929 * If we send an ATIO to the firmware to increment
930 * its command resource count, and the firmware is
931 * recovering from a Bus Device Reset, it returns
932 * the ATIO with this status. We set the command
933 * resource count in the Enable Lun entry and no
934 * not increment it. Therefore we should never get
937 isp_prt(isp, ISP_LOGERR, atiocope, lun, 0);
940 case AT_CDB: /* Got a CDB */
942 * Punt to platform specific layer.
944 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
949 * A bus reset came along an blew away this command. Why
950 * they do this in addition the async event code stuff,
953 * Ignore it because the async event will clear things
956 isp_prt(isp, ISP_LOGERR, atior, lun, iid, 0);
961 isp_prt(isp, ISP_LOGERR,
962 "Unknown ATIO2 status 0x%x from initiator %d for lun %d",
963 aep->at_status, iid, lun);
964 (void) isp_target_put_atio(isp, aep);
970 isp_handle_ctio(ispsoftc_t *isp, ct_entry_t *ct)
973 int pl = ISP_LOGTDEBUG2;
976 if (ct->ct_syshandle) {
977 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
984 switch(ct->ct_status & ~QLTM_SVALID) {
987 * There are generally 3 possibilities as to why we'd get
989 * We disconnected after receiving a CDB.
990 * We sent or received data.
991 * We sent status & command complete.
994 if (ct->ct_flags & CT_SENDSTATUS) {
996 } else if ((ct->ct_flags & CT_DATAMASK) == CT_NO_DATA) {
998 * Nothing to do in this case.
1000 isp_prt(isp, pl, "CTIO- iid %d disconnected OK",
1008 * Bus Device Reset message received or the SCSI Bus has
1009 * been Reset; the firmware has gone to Bus Free.
1011 * The firmware generates an async mailbox interupt to
1012 * notify us of this and returns outstanding CTIOs with this
1013 * status. These CTIOs are handled in that same way as
1014 * CT_ABORTED ones, so just fall through here.
1016 fmsg = "Bus Device Reset";
1024 * When an Abort message is received the firmware goes to
1025 * Bus Free and returns all outstanding CTIOs with the status
1026 * set, then sends us an Immediate Notify entry.
1029 fmsg = "ABORT TAG message sent by Initiator";
1031 isp_prt(isp, ISP_LOGWARN, "CTIO destroyed by %s", fmsg);
1036 * CTIO rejected by the firmware due to disabled lun.
1039 isp_prt(isp, ISP_LOGERR,
1040 "Firmware rejected CTIO for disabled lun %d",
1046 * CTIO rejected by the firmware due "no path for the
1047 * nondisconnecting nexus specified". This means that
1048 * we tried to access the bus while a non-disconnecting
1049 * command is in process.
1051 isp_prt(isp, ISP_LOGERR,
1052 "Firmware rejected CTIO for bad nexus %d/%d/%d",
1053 ct->ct_iid, ct->ct_tgt, ct->ct_lun);
1057 fmsg = "Reselection";
1062 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
1067 fmsg = "Unrecoverable Error";
1071 fmsg = "Completed with Error";
1073 case CT_PHASE_ERROR:
1075 fmsg = "Phase Sequence Error";
1079 fmsg = "terminated by TERMINATE TRANSFER";
1083 fmsg = "unacknowledged Immediate Notify pending";
1084 isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg);
1087 isp_prt(isp, ISP_LOGERR, "Unknown CTIO status 0x%x",
1088 ct->ct_status & ~QLTM_SVALID);
1094 * There may be more than one CTIO for a data transfer,
1095 * or this may be a status CTIO we're not monitoring.
1097 * The assumption is that they'll all be returned in the
1098 * order we got them.
1100 if (ct->ct_syshandle == 0) {
1101 if ((ct->ct_flags & CT_SENDSTATUS) == 0) {
1103 "intermediate CTIO completed ok");
1106 "unmonitored CTIO completed ok");
1110 "NO xs for CTIO (handle 0x%x) status 0x%x",
1111 ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1115 * Final CTIO completed. Release DMA resources and
1116 * notify platform dependent layers.
1118 if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) {
1119 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1121 isp_prt(isp, pl, "final CTIO complete");
1123 * The platform layer will destroy the handle if appropriate.
1125 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1130 isp_handle_ctio2(ispsoftc_t *isp, ct2_entry_t *ct)
1133 int pl = ISP_LOGTDEBUG2;
1136 if (ct->ct_syshandle) {
1137 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1144 switch(ct->ct_status & ~QLTM_SVALID) {
1146 isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error");
1152 * There are generally 2 possibilities as to why we'd get
1154 * We sent or received data.
1155 * We sent status & command complete.
1162 * Target Reset function received.
1164 * The firmware generates an async mailbox interupt to
1165 * notify us of this and returns outstanding CTIOs with this
1166 * status. These CTIOs are handled in that same way as
1167 * CT_ABORTED ones, so just fall through here.
1169 fmsg = "TARGET RESET Task Management Function Received";
1177 * When an Abort message is received the firmware goes to
1178 * Bus Free and returns all outstanding CTIOs with the status
1179 * set, then sends us an Immediate Notify entry.
1182 fmsg = "ABORT Task Management Function Received";
1184 isp_prt(isp, ISP_LOGERR, "CTIO2 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid);
1189 * CTIO rejected by the firmware - invalid data direction.
1191 isp_prt(isp, ISP_LOGERR, "CTIO2 had wrong data direction");
1195 fmsg = "failure to reconnect to initiator";
1200 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
1204 fmsg = "Completed with Error";
1208 fmsg = "Port Logout";
1210 case CT_PORTNOTAVAIL:
1212 fmsg = "Port not available";
1214 case CT_PORTCHANGED:
1216 fmsg = "Port Changed";
1220 fmsg = "unacknowledged Immediate Notify pending";
1221 isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg);
1226 * CTIO rejected by the firmware because an invalid RX_ID.
1227 * Just print a message.
1229 isp_prt(isp, ISP_LOGERR,
1230 "CTIO2 completed with Invalid RX_ID 0x%x", ct->ct_rxid);
1234 isp_prt(isp, ISP_LOGERR, "Unknown CTIO2 status 0x%x",
1235 ct->ct_status & ~QLTM_SVALID);
1241 * There may be more than one CTIO for a data transfer,
1242 * or this may be a status CTIO we're not monitoring.
1244 * The assumption is that they'll all be returned in the
1245 * order we got them.
1247 if (ct->ct_syshandle == 0) {
1248 if ((ct->ct_flags & CT2_SENDSTATUS) == 0) {
1250 "intermediate CTIO completed ok");
1253 "unmonitored CTIO completed ok");
1257 "NO xs for CTIO (handle 0x%x) status 0x%x",
1258 ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1261 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
1262 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1264 if (ct->ct_flags & CT2_SENDSTATUS) {
1266 * Sent status and command complete.
1268 * We're now really done with this command, so we
1269 * punt to the platform dependent layers because
1270 * only there can we do the appropriate command
1271 * complete thread synchronization.
1273 isp_prt(isp, pl, "status CTIO complete");
1276 * Final CTIO completed. Release DMA resources and
1277 * notify platform dependent layers.
1279 isp_prt(isp, pl, "data CTIO complete");
1281 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1283 * The platform layer will destroy the handle if appropriate.