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 * Bug fixes gratefully acknowledged from:
30 * Oded Kedem <oded@kashya.com>
33 * Include header file appropriate for platform we're building on.
37 #include <dev/ic/isp_netbsd.h>
40 #include <sys/cdefs.h>
41 __FBSDID("$FreeBSD$");
42 #include <dev/isp/isp_freebsd.h>
45 #include <dev/ic/isp_openbsd.h>
48 #include "isp_linux.h"
51 #ifdef ISP_TARGET_MODE
52 static const char atiocope[] =
53 "ATIO returned for lun %d because it was in the middle of Bus Device Reset "
55 static const char atior[] =
56 "ATIO returned on for lun %d on from IID %d because a Bus Reset occurred "
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_handle_atio(ispsoftc_t *, at_entry_t *);
62 static void isp_handle_atio2(ispsoftc_t *, at2_entry_t *);
63 static void isp_handle_ctio(ispsoftc_t *, ct_entry_t *);
64 static void isp_handle_ctio2(ispsoftc_t *, ct2_entry_t *);
67 * The Qlogic driver gets an interrupt to look at response queue entries.
68 * Some of these are status completions for initiatior mode commands, but
69 * if target mode is enabled, we get a whole wad of response queue entries
72 * Basically the split into 3 main groups: Lun Enable/Modification responses,
73 * SCSI Command processing, and Immediate Notification events.
75 * You start by writing a request queue entry to enable target mode (and
76 * establish some resource limitations which you can modify later).
77 * The f/w responds with a LUN ENABLE or LUN MODIFY response with
78 * the status of this action. If the enable was successful, you can expect...
80 * Response queue entries with SCSI commands encapsulate show up in an ATIO
81 * (Accept Target IO) type- sometimes with enough info to stop the command at
82 * this level. Ultimately the driver has to feed back to the f/w's request
83 * queue a sequence of CTIOs (continue target I/O) that describe data to
84 * be moved and/or status to be sent) and finally finishing with sending
85 * to the f/w's response queue an ATIO which then completes the handshake
86 * with the f/w for that command. There's a lot of variations on this theme,
87 * including flags you can set in the CTIO for the Qlogic 2X00 fibre channel
88 * cards that 'auto-replenish' the f/w's ATIO count, but this is the basic
91 * The third group that can show up in the response queue are Immediate
92 * Notification events. These include things like notifications of SCSI bus
93 * resets, or Bus Device Reset messages or other messages received. This
94 * a classic oddbins area. It can get a little weird because you then turn
95 * around and acknowledge the Immediate Notify by writing an entry onto the
96 * request queue and then the f/w turns around and gives you an acknowledgement
97 * to *your* acknowledgement on the response queue (the idea being to let
98 * the f/w tell you when the event is *really* over I guess).
104 * A new response queue entry has arrived. The interrupt service code
105 * has already swizzled it into the platform dependent from canonical form.
107 * Because of the way this driver is designed, unfortunately most of the
108 * actual synchronization work has to be done in the platform specific
109 * code- we have no synchroniation primitives in the common code.
113 isp_target_notify(ispsoftc_t *isp, void *vptr, uint16_t *optrp)
115 uint16_t status, seqid;
119 at2e_entry_t *at2eiop;
122 ct2e_entry_t *ct2eiop;
125 in_fcentry_t *inot_fcp;
126 in_fcentry_e_t *inote_fcp;
128 na_fcentry_t *nack_fcp;
129 na_fcentry_e_t *nacke_fcp;
132 #define atiop unp.atiop
133 #define at2iop unp.at2iop
134 #define at2eiop unp.at2eiop
135 #define ctiop unp.ctiop
136 #define ct2iop unp.ct2iop
137 #define ct2eiop unp.ct2eiop
138 #define lunenp unp.lunenp
139 #define inotp unp.inotp
140 #define inot_fcp unp.inot_fcp
141 #define inote_fcp unp.inote_fcp
142 #define nackp unp.nackp
143 #define nack_fcp unp.nack_fcp
144 #define nacke_fcp unp.nacke_fcp
147 uint8_t local[QENTRY_LEN];
148 int bus, type, rval = 1;
150 type = isp_get_response_type(isp, (isphdr_t *)vptr);
153 ISP_TDQE(isp, "isp_target_notify", (int) *optrp, vptr);
157 isp_get_atio(isp, atiop, (at_entry_t *) local);
158 isp_handle_atio(isp, (at_entry_t *) local);
161 isp_get_ctio(isp, ctiop, (ct_entry_t *) local);
162 isp_handle_ctio(isp, (ct_entry_t *) local);
165 if (IS_2KLOGIN(isp)) {
166 isp_get_atio2e(isp, at2eiop, (at2e_entry_t *) local);
168 isp_get_atio2(isp, at2iop, (at2_entry_t *) local);
170 isp_handle_atio2(isp, (at2_entry_t *) local);
174 if (IS_2KLOGIN(isp)) {
175 isp_get_ctio2e(isp, ct2eiop, (ct2e_entry_t *) local);
177 isp_get_ctio2(isp, ct2iop, (ct2_entry_t *) local);
179 isp_handle_ctio2(isp, (ct2_entry_t *) local);
181 case RQSTYPE_ENABLE_LUN:
182 case RQSTYPE_MODIFY_LUN:
183 isp_get_enable_lun(isp, lunenp, (lun_entry_t *) local);
184 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, local);
189 * Either the ISP received a SCSI message it can't
190 * handle, or it's returning an Immed. Notify entry
191 * we sent. We can send Immed. Notify entries to
192 * increment the firmware's resource count for them
193 * (we set this initially in the Enable Lun entry).
197 if (IS_2KLOGIN(isp)) {
198 isp_get_notify_fc_e(isp, inote_fcp,
199 (in_fcentry_e_t *)local);
201 isp_get_notify_fc(isp, inot_fcp,
202 (in_fcentry_t *)local);
204 inot_fcp = (in_fcentry_t *) local;
205 status = inot_fcp->in_status;
206 seqid = inot_fcp->in_seqid;
208 isp_get_notify(isp, inotp, (in_entry_t *)local);
209 inotp = (in_entry_t *) local;
210 status = inotp->in_status & 0xff;
211 seqid = inotp->in_seqid;
212 if (IS_DUALBUS(isp)) {
213 bus = GET_BUS_VAL(inotp->in_iid);
214 SET_BUS_VAL(inotp->in_iid, 0);
218 isp_prt(isp, ISP_LOGTDEBUG0,
219 "Immediate Notify On Bus %d, status=0x%x seqid=0x%x",
223 case IN_MSG_RECEIVED:
224 case IN_IDE_RECEIVED:
226 isp_got_msg_fc(isp, (in_fcentry_t *)local);
228 isp_got_msg(isp, (in_entry_t *)local);
231 case IN_RSRC_UNAVAIL:
232 isp_prt(isp, ISP_LOGWARN, "Firmware out of ATIOs");
233 isp_notify_ack(isp, local);
236 (void) isp_target_async(isp, 0, ASYNC_BUS_RESET);
240 case IN_PORT_CHANGED:
242 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, &local);
245 isp_prt(isp, ISP_LOGERR,
246 "bad status (0x%x) in isp_target_notify", status);
247 isp_notify_ack(isp, local);
252 case RQSTYPE_NOTIFY_ACK:
254 * The ISP is acknowledging our acknowledgement of an
255 * Immediate Notify entry for some asynchronous event.
258 if (IS_2KLOGIN(isp)) {
259 isp_get_notify_ack_fc_e(isp, nacke_fcp,
260 (na_fcentry_e_t *)local);
262 isp_get_notify_ack_fc(isp, nack_fcp,
263 (na_fcentry_t *)local);
265 nack_fcp = (na_fcentry_t *)local;
266 isp_prt(isp, ISP_LOGTDEBUG1,
267 "Notify Ack status=0x%x seqid 0x%x",
268 nack_fcp->na_status, nack_fcp->na_seqid);
270 isp_get_notify_ack(isp, nackp, (na_entry_t *)local);
271 nackp = (na_entry_t *)local;
272 isp_prt(isp, ISP_LOGTDEBUG1,
273 "Notify Ack event 0x%x status=0x%x seqid 0x%x",
274 nackp->na_event, nackp->na_status, nackp->na_seqid);
278 isp_prt(isp, ISP_LOGERR,
279 "Unknown entry type 0x%x in isp_target_notify", type);
302 * Toggle (on/off) target mode for bus/target/lun
304 * The caller has checked for overlap and legality.
306 * Note that not all of bus, target or lun can be paid attention to.
307 * Note also that this action will not be complete until the f/w writes
308 * response entry. The caller is responsible for synchronizing this.
311 isp_lun_cmd(ispsoftc_t *isp, int cmd, int bus, int tgt, int lun,
312 int cmd_cnt, int inot_cnt, uint32_t opaque)
319 MEMZERO(&el, sizeof (el));
320 if (IS_DUALBUS(isp)) {
321 el.le_rsvd = (bus & 0x1) << 7;
323 el.le_cmd_count = cmd_cnt;
324 el.le_in_count = inot_cnt;
325 if (cmd == RQSTYPE_ENABLE_LUN) {
327 el.le_flags = LUN_TQAE|LUN_DISAD;
331 } else if (cmd == -RQSTYPE_ENABLE_LUN) {
332 cmd = RQSTYPE_ENABLE_LUN;
335 } else if (cmd == -RQSTYPE_MODIFY_LUN) {
336 cmd = RQSTYPE_MODIFY_LUN;
337 el.le_ops = LUN_CCDECR | LUN_INDECR;
339 el.le_ops = LUN_CCINCR | LUN_ININCR;
341 el.le_header.rqs_entry_type = cmd;
342 el.le_header.rqs_entry_count = 1;
343 el.le_reserved = opaque;
347 } else if ((FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) == 0) {
351 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
352 isp_prt(isp, ISP_LOGERR,
353 "Request Queue Overflow in isp_lun_cmd");
356 ISP_TDQE(isp, "isp_lun_cmd", (int) optr, &el);
357 isp_put_enable_lun(isp, &el, outp);
358 ISP_ADD_REQUEST(isp, nxti);
364 isp_target_put_entry(ispsoftc_t *isp, void *ap)
368 uint8_t etype = ((isphdr_t *) ap)->rqs_entry_type;
370 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
371 isp_prt(isp, ISP_LOGWARN,
372 "Request Queue Overflow in isp_target_put_entry");
377 isp_put_atio(isp, (at_entry_t *) ap, (at_entry_t *) outp);
380 if (IS_2KLOGIN(isp)) {
381 isp_put_atio2e(isp, (at2e_entry_t *) ap, (at2e_entry_t *) outp);
383 isp_put_atio2(isp, (at2_entry_t *) ap, (at2_entry_t *) outp);
387 isp_put_ctio(isp, (ct_entry_t *) ap, (ct_entry_t *) outp);
390 if (IS_2KLOGIN(isp)) {
391 isp_put_ctio2e(isp, (ct2e_entry_t *) ap, (ct2e_entry_t *) outp);
393 isp_put_ctio2(isp, (ct2_entry_t *) ap, (ct2_entry_t *) outp);
397 isp_prt(isp, ISP_LOGERR,
398 "Unknown type 0x%x in isp_put_entry", etype);
402 ISP_TDQE(isp, "isp_target_put_entry", (int) optr, ap);
403 ISP_ADD_REQUEST(isp, nxti);
408 isp_target_put_atio(ispsoftc_t *isp, void *arg)
413 at2e_entry_t _atio2e;
416 MEMZERO(&atun, sizeof atun);
418 at2_entry_t *aep = arg;
419 atun._atio2.at_header.rqs_entry_type = RQSTYPE_ATIO2;
420 atun._atio2.at_header.rqs_entry_count = 1;
421 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
422 atun._atio2.at_scclun = (uint16_t) aep->at_scclun;
424 atun._atio2.at_lun = (uint8_t) aep->at_lun;
426 if (IS_2KLOGIN(isp)) {
427 atun._atio2e.at_iid = ((at2e_entry_t *)aep)->at_iid;
429 atun._atio2.at_iid = aep->at_iid;
431 atun._atio2.at_rxid = aep->at_rxid;
432 atun._atio2.at_status = CT_OK;
434 at_entry_t *aep = arg;
435 atun._atio.at_header.rqs_entry_type = RQSTYPE_ATIO;
436 atun._atio.at_header.rqs_entry_count = 1;
437 atun._atio.at_handle = aep->at_handle;
438 atun._atio.at_iid = aep->at_iid;
439 atun._atio.at_tgt = aep->at_tgt;
440 atun._atio.at_lun = aep->at_lun;
441 atun._atio.at_tag_type = aep->at_tag_type;
442 atun._atio.at_tag_val = aep->at_tag_val;
443 atun._atio.at_status = (aep->at_flags & AT_TQAE);
444 atun._atio.at_status |= CT_OK;
446 return (isp_target_put_entry(isp, &atun));
450 * Command completion- both for handling cases of no resources or
451 * no blackhole driver, or other cases where we have to, inline,
452 * finish the command sanely, or for normal command completion.
454 * The 'completion' code value has the scsi status byte in the low 8 bits.
455 * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have
456 * the sense key and bits 16..23 have the ASCQ and bits 24..31 have the ASC
459 * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't
460 * NB: inline SCSI sense reporting. As such, we lose this information. XXX.
462 * For both parallel && fibre channel, we use the feature that does
463 * an automatic resource autoreplenish so we don't have then later do
464 * put of an atio to replenish the f/w's resource count.
468 isp_endcmd(ispsoftc_t *isp, void *arg, uint32_t code, uint16_t hdl)
474 ct2e_entry_t _ctio2e;
477 MEMZERO(&un, sizeof un);
481 at2_entry_t *aep = arg;
482 ct2_entry_t *cto = &un._ctio2;
484 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
485 cto->ct_header.rqs_entry_count = 1;
486 if ((FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) == 0) {
487 cto->ct_lun = aep->at_lun;
489 if (IS_2KLOGIN(isp)) {
490 un._ctio2e.ct_iid = ((at2e_entry_t *)aep)->at_iid;
492 cto->ct_iid = aep->at_iid;
494 cto->ct_rxid = aep->at_rxid;
495 cto->rsp.m1.ct_scsi_status = sts;
496 cto->ct_flags = CT2_SENDSTATUS | CT2_NO_DATA | CT2_FLAG_MODE1;
498 cto->ct_flags |= CT2_CCINCR;
500 if (aep->at_datalen) {
501 cto->ct_resid = aep->at_datalen;
502 cto->rsp.m1.ct_scsi_status |= CT2_DATA_UNDER;
504 if (sts == SCSI_CHECK && (code & ECMD_SVALID)) {
505 cto->rsp.m1.ct_resp[0] = 0xf0;
506 cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
507 cto->rsp.m1.ct_resp[7] = 8;
508 cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff;
509 cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff;
510 cto->rsp.m1.ct_senselen = 16;
511 cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID;
513 cto->ct_syshandle = hdl;
515 at_entry_t *aep = arg;
516 ct_entry_t *cto = &un._ctio;
518 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
519 cto->ct_header.rqs_entry_count = 1;
520 cto->ct_fwhandle = aep->at_handle;
521 cto->ct_iid = aep->at_iid;
522 cto->ct_tgt = aep->at_tgt;
523 cto->ct_lun = aep->at_lun;
524 cto->ct_tag_type = aep->at_tag_type;
525 cto->ct_tag_val = aep->at_tag_val;
526 if (aep->at_flags & AT_TQAE) {
527 cto->ct_flags |= CT_TQAE;
529 cto->ct_flags = CT_SENDSTATUS | CT_NO_DATA;
531 cto->ct_flags |= CT_CCINCR;
533 cto->ct_scsi_status = sts;
534 cto->ct_syshandle = hdl;
536 return (isp_target_put_entry(isp, &un));
540 * These are either broadcast events or specifically CTIO fast completion
543 isp_target_async(ispsoftc_t *isp, int bus, int event)
547 MEMZERO(¬ify, sizeof (tmd_notify_t));
549 notify.nt_iid = INI_ANY;
550 /* nt_tgt set in outer layers */
551 notify.nt_lun = LUN_ANY;
552 notify.nt_tagval = TAG_ANY;
555 TAG_INSERT_BUS(notify.nt_tagval, bus);
561 notify.nt_ncode = NT_LINK_UP;
562 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
564 case ASYNC_LOOP_DOWN:
565 notify.nt_ncode = NT_LINK_DOWN;
566 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
569 case ASYNC_LIP_OCCURRED:
570 case ASYNC_LOOP_RESET:
571 notify.nt_ncode = NT_LIP_RESET;
572 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
574 case ASYNC_BUS_RESET:
575 case ASYNC_TIMEOUT_RESET: /* XXX: where does this come from ? */
576 notify.nt_ncode = NT_BUS_RESET;
577 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
579 case ASYNC_DEVICE_RESET:
580 notify.nt_ncode = NT_TARGET_RESET;
581 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
583 case ASYNC_CTIO_DONE:
585 uint8_t storage[QENTRY_LEN];
586 memset(storage, 0, QENTRY_LEN);
588 /* This should also suffice for 2K login code */
589 ct2_entry_t *ct = (ct2_entry_t *) storage;
590 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
591 ct->ct_status = CT_OK;
592 ct->ct_syshandle = bus;
593 ct->ct_flags = CT2_SENDSTATUS|CT2_FASTPOST;
595 ct_entry_t *ct = (ct_entry_t *) storage;
596 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO;
597 ct->ct_status = CT_OK;
598 ct->ct_fwhandle = bus;
599 ct->ct_flags = CT_SENDSTATUS;
601 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, storage);
605 isp_prt(isp, ISP_LOGERR,
606 "isp_target_async: unknown event 0x%x", event);
607 if (isp->isp_state == ISP_RUNSTATE) {
608 isp_notify_ack(isp, NULL);
617 * Process a received message.
618 * The ISP firmware can handle most messages, there are only
619 * a few that we need to deal with:
620 * - abort: clean up the current command
621 * - abort tag and clear queue
625 isp_got_msg(ispsoftc_t *isp, in_entry_t *inp)
628 uint8_t status = inp->in_status & ~QLTM_SVALID;
630 MEMZERO(&nt, sizeof (nt));
632 nt.nt_iid = GET_IID_VAL(inp->in_iid);
633 nt.nt_tgt = inp->in_tgt;
634 nt.nt_lun = inp->in_lun;
635 IN_MAKE_TAGID(nt.nt_tagval, 0, inp);
636 nt.nt_lreserved = inp;
638 if (status == IN_IDE_RECEIVED || status == IN_MSG_RECEIVED) {
639 switch (inp->in_msg[0]) {
641 nt.nt_ncode = NT_ABORT_TASK_SET;
643 case MSG_BUS_DEV_RESET:
644 nt.nt_ncode = NT_TARGET_RESET;
647 nt.nt_ncode = NT_ABORT_TASK;
649 case MSG_CLEAR_QUEUE:
650 nt.nt_ncode = NT_CLEAR_TASK_SET;
652 case MSG_REL_RECOVERY:
653 nt.nt_ncode = NT_CLEAR_ACA;
655 case MSG_TERM_IO_PROC:
656 nt.nt_ncode = NT_ABORT_TASK;
659 nt.nt_ncode = NT_LUN_RESET;
662 isp_prt(isp, ISP_LOGERR,
663 "unhandled message 0x%x", inp->in_msg[0]);
664 isp_notify_ack(isp, inp);
667 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt);
669 isp_prt(isp, ISP_LOGERR,
670 "unknown immediate notify status 0x%x", inp->in_status);
671 isp_notify_ack(isp, inp);
676 * Synthesize a message from the task management flags in a FCP_CMND_IU.
679 isp_got_msg_fc(ispsoftc_t *isp, in_fcentry_t *inp)
682 static const char f1[] = "%s from loop id %d lun %d seq 0x%x";
683 static const char f2[] =
684 "unknown %s 0x%x lun %d loop id %d task flags 0x%x seq 0x%x\n";
685 uint16_t seqid, loopid;
687 MEMZERO(&nt, sizeof (tmd_notify_t));
689 if (IS_2KLOGIN(isp)) {
690 nt.nt_iid = ((in_fcentry_e_t *)inp)->in_iid;
691 loopid = ((in_fcentry_e_t *)inp)->in_iid;
692 seqid = ((in_fcentry_e_t *)inp)->in_seqid;
694 nt.nt_iid = inp->in_iid;
695 loopid = inp->in_iid;
696 seqid = inp->in_seqid;
698 /* nt_tgt set in outer layers */
699 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
700 nt.nt_lun = inp->in_scclun;
702 nt.nt_lun = inp->in_lun;
704 IN_FC_MAKE_TAGID(nt.nt_tagval, 0, seqid);
705 nt.nt_lreserved = inp;
707 if (inp->in_status != IN_MSG_RECEIVED) {
708 isp_prt(isp, ISP_LOGINFO, f2, "immediate notify status",
709 inp->in_status, nt.nt_lun, loopid, inp->in_task_flags,
711 isp_notify_ack(isp, inp);
715 if (inp->in_task_flags & TASK_FLAGS_ABORT_TASK_SET) {
716 isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET",
717 loopid, nt.nt_lun, inp->in_seqid);
718 nt.nt_ncode = NT_ABORT_TASK_SET;
719 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_TASK_SET) {
720 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET",
721 loopid, nt.nt_lun, inp->in_seqid);
722 nt.nt_ncode = NT_CLEAR_TASK_SET;
723 } else if (inp->in_task_flags & TASK_FLAGS_LUN_RESET) {
724 isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET",
725 loopid, nt.nt_lun, inp->in_seqid);
726 nt.nt_ncode = NT_LUN_RESET;
727 } else if (inp->in_task_flags & TASK_FLAGS_TARGET_RESET) {
728 isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET",
729 loopid, nt.nt_lun, inp->in_seqid);
730 nt.nt_ncode = NT_TARGET_RESET;
731 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_ACA) {
732 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA",
733 loopid, nt.nt_lun, inp->in_seqid);
734 nt.nt_ncode = NT_CLEAR_ACA;
736 isp_prt(isp, ISP_LOGWARN, f2, "task flag", inp->in_status,
737 nt.nt_lun, loopid, inp->in_task_flags, inp->in_seqid);
738 isp_notify_ack(isp, inp);
741 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt);
745 isp_notify_ack(ispsoftc_t *isp, void *arg)
747 char storage[QENTRY_LEN];
751 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
752 isp_prt(isp, ISP_LOGWARN,
753 "Request Queue Overflow For isp_notify_ack");
757 MEMZERO(storage, QENTRY_LEN);
760 na_fcentry_t *na = (na_fcentry_t *) storage;
764 in_fcentry_t *inp = arg;
765 MEMCPY(storage, arg, sizeof (isphdr_t));
766 if (IS_2KLOGIN(isp)) {
767 ((na_fcentry_e_t *)na)->na_iid =
768 ((in_fcentry_e_t *)inp)->in_iid;
769 iid = ((na_fcentry_e_t *)na)->na_iid;
771 na->na_iid = inp->in_iid;
775 inp->in_task_flags & TASK_FLAGS_RESERVED_MASK;
776 na->na_seqid = inp->in_seqid;
777 na->na_flags = NAFC_RCOUNT;
778 na->na_status = inp->in_status;
779 if (inp->in_status == IN_RESET) {
780 na->na_flags |= NAFC_RST_CLRD;
782 if (inp->in_status == IN_MSG_RECEIVED) {
783 na->na_flags |= NAFC_TVALID;
784 na->na_response = 0; /* XXX SUCCEEDED XXX */
787 na->na_flags = NAFC_RST_CLRD;
789 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
790 na->na_header.rqs_entry_count = 1;
791 if (IS_2KLOGIN(isp)) {
792 isp_put_notify_ack_fc_e(isp, (na_fcentry_e_t *) na,
793 (na_fcentry_e_t *)outp);
795 isp_put_notify_ack_fc(isp, na, (na_fcentry_t *)outp);
797 isp_prt(isp, ISP_LOGTDEBUG0, "notify ack iid %u seqid %x flags "
798 "%x tflags %x response %x", iid, na->na_seqid,
799 na->na_flags, na->na_task_flags, na->na_response);
801 na_entry_t *na = (na_entry_t *) storage;
803 in_entry_t *inp = arg;
804 MEMCPY(storage, arg, sizeof (isphdr_t));
805 na->na_iid = inp->in_iid;
806 na->na_lun = inp->in_lun;
807 na->na_tgt = inp->in_tgt;
808 na->na_seqid = inp->in_seqid;
809 if (inp->in_status == IN_RESET) {
810 na->na_event = NA_RST_CLRD;
813 na->na_event = NA_RST_CLRD;
815 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
816 na->na_header.rqs_entry_count = 1;
817 isp_put_notify_ack(isp, na, (na_entry_t *)outp);
818 isp_prt(isp, ISP_LOGTDEBUG0, "notify ack iid %u lun %u tgt %u "
819 "seqid %x event %x", na->na_iid, na->na_lun, na->na_tgt,
820 na->na_seqid, na->na_event);
822 ISP_TDQE(isp, "isp_notify_ack", (int) optr, storage);
823 ISP_ADD_REQUEST(isp, nxti);
827 isp_handle_atio(ispsoftc_t *isp, at_entry_t *aep)
832 * The firmware status (except for the QLTM_SVALID bit) indicates
833 * why this ATIO was sent to us.
835 * If QLTM_SVALID is set, the firware has recommended Sense Data.
837 * If the DISCONNECTS DISABLED bit is set in the flags field,
838 * we're still connected on the SCSI bus - i.e. the initiator
839 * did not set DiscPriv in the identify message. We don't care
840 * about this so it's ignored.
843 switch(aep->at_status & ~QLTM_SVALID) {
844 case AT_PATH_INVALID:
846 * ATIO rejected by the firmware due to disabled lun.
848 isp_prt(isp, ISP_LOGERR,
849 "rejected ATIO for disabled lun %d", lun);
853 * Requested Capability not available
854 * We sent an ATIO that overflowed the firmware's
855 * command resource count.
857 isp_prt(isp, ISP_LOGERR,
858 "rejected ATIO for lun %d because of command count"
864 * If we send an ATIO to the firmware to increment
865 * its command resource count, and the firmware is
866 * recovering from a Bus Device Reset, it returns
867 * the ATIO with this status. We set the command
868 * resource count in the Enable Lun entry and do
869 * not increment it. Therefore we should never get
872 isp_prt(isp, ISP_LOGERR, atiocope, lun,
873 GET_BUS_VAL(aep->at_iid));
876 case AT_CDB: /* Got a CDB */
877 case AT_PHASE_ERROR: /* Bus Phase Sequence Error */
879 * Punt to platform specific layer.
881 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
886 * A bus reset came along and blew away this command. Why
887 * they do this in addition the async event code stuff,
890 * Ignore it because the async event will clear things
893 isp_prt(isp, ISP_LOGWARN, atior, lun,
894 GET_IID_VAL(aep->at_iid), GET_BUS_VAL(aep->at_iid));
899 isp_prt(isp, ISP_LOGERR,
900 "Unknown ATIO status 0x%x from initiator %d for lun %d",
901 aep->at_status, aep->at_iid, lun);
902 (void) isp_target_put_atio(isp, aep);
908 isp_handle_atio2(ispsoftc_t *isp, at2_entry_t *aep)
912 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
913 lun = aep->at_scclun;
918 if (IS_2KLOGIN(isp)) {
919 iid = ((at2e_entry_t *)aep)->at_iid;
925 * The firmware status (except for the QLTM_SVALID bit) indicates
926 * why this ATIO was sent to us.
928 * If QLTM_SVALID is set, the firware has recommended Sense Data.
930 * If the DISCONNECTS DISABLED bit is set in the flags field,
931 * we're still connected on the SCSI bus - i.e. the initiator
932 * did not set DiscPriv in the identify message. We don't care
933 * about this so it's ignored.
936 switch(aep->at_status & ~QLTM_SVALID) {
937 case AT_PATH_INVALID:
939 * ATIO rejected by the firmware due to disabled lun.
941 isp_prt(isp, ISP_LOGERR,
942 "rejected ATIO2 for disabled lun %d", lun);
946 * Requested Capability not available
947 * We sent an ATIO that overflowed the firmware's
948 * command resource count.
950 isp_prt(isp, ISP_LOGERR,
951 "rejected ATIO2 for lun %d- command count overflow", lun);
956 * If we send an ATIO to the firmware to increment
957 * its command resource count, and the firmware is
958 * recovering from a Bus Device Reset, it returns
959 * the ATIO with this status. We set the command
960 * resource count in the Enable Lun entry and no
961 * not increment it. Therefore we should never get
964 isp_prt(isp, ISP_LOGERR, atiocope, lun, 0);
967 case AT_CDB: /* Got a CDB */
969 * Punt to platform specific layer.
971 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
976 * A bus reset came along an blew away this command. Why
977 * they do this in addition the async event code stuff,
980 * Ignore it because the async event will clear things
983 isp_prt(isp, ISP_LOGERR, atior, lun, iid, 0);
988 isp_prt(isp, ISP_LOGERR,
989 "Unknown ATIO2 status 0x%x from initiator %d for lun %d",
990 aep->at_status, iid, lun);
991 (void) isp_target_put_atio(isp, aep);
997 isp_handle_ctio(ispsoftc_t *isp, ct_entry_t *ct)
1000 int pl = ISP_LOGTDEBUG2;
1003 if (ct->ct_syshandle) {
1004 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1011 switch(ct->ct_status & ~QLTM_SVALID) {
1014 * There are generally 3 possibilities as to why we'd get
1016 * We disconnected after receiving a CDB.
1017 * We sent or received data.
1018 * We sent status & command complete.
1021 if (ct->ct_flags & CT_SENDSTATUS) {
1023 } else if ((ct->ct_flags & CT_DATAMASK) == CT_NO_DATA) {
1025 * Nothing to do in this case.
1027 isp_prt(isp, pl, "CTIO- iid %d disconnected OK",
1035 * Bus Device Reset message received or the SCSI Bus has
1036 * been Reset; the firmware has gone to Bus Free.
1038 * The firmware generates an async mailbox interupt to
1039 * notify us of this and returns outstanding CTIOs with this
1040 * status. These CTIOs are handled in that same way as
1041 * CT_ABORTED ones, so just fall through here.
1043 fmsg = "Bus Device Reset";
1051 * When an Abort message is received the firmware goes to
1052 * Bus Free and returns all outstanding CTIOs with the status
1053 * set, then sends us an Immediate Notify entry.
1056 fmsg = "ABORT TAG message sent by Initiator";
1058 isp_prt(isp, ISP_LOGWARN, "CTIO destroyed by %s", fmsg);
1063 * CTIO rejected by the firmware due to disabled lun.
1066 isp_prt(isp, ISP_LOGERR,
1067 "Firmware rejected CTIO for disabled lun %d",
1073 * CTIO rejected by the firmware due "no path for the
1074 * nondisconnecting nexus specified". This means that
1075 * we tried to access the bus while a non-disconnecting
1076 * command is in process.
1078 isp_prt(isp, ISP_LOGERR,
1079 "Firmware rejected CTIO for bad nexus %d/%d/%d",
1080 ct->ct_iid, ct->ct_tgt, ct->ct_lun);
1084 fmsg = "Reselection";
1089 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
1094 fmsg = "Unrecoverable Error";
1098 fmsg = "Completed with Error";
1100 case CT_PHASE_ERROR:
1102 fmsg = "Phase Sequence Error";
1106 fmsg = "terminated by TERMINATE TRANSFER";
1110 fmsg = "unacknowledged Immediate Notify pending";
1111 isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg);
1114 isp_prt(isp, ISP_LOGERR, "Unknown CTIO status 0x%x",
1115 ct->ct_status & ~QLTM_SVALID);
1121 * There may be more than one CTIO for a data transfer,
1122 * or this may be a status CTIO we're not monitoring.
1124 * The assumption is that they'll all be returned in the
1125 * order we got them.
1127 if (ct->ct_syshandle == 0) {
1128 if ((ct->ct_flags & CT_SENDSTATUS) == 0) {
1130 "intermediate CTIO completed ok");
1133 "unmonitored CTIO completed ok");
1137 "NO xs for CTIO (handle 0x%x) status 0x%x",
1138 ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1142 * Final CTIO completed. Release DMA resources and
1143 * notify platform dependent layers.
1145 if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) {
1146 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1148 isp_prt(isp, pl, "final CTIO complete");
1150 * The platform layer will destroy the handle if appropriate.
1152 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1157 isp_handle_ctio2(ispsoftc_t *isp, ct2_entry_t *ct)
1160 int pl = ISP_LOGTDEBUG2;
1163 if (ct->ct_syshandle) {
1164 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1171 switch(ct->ct_status & ~QLTM_SVALID) {
1173 isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error");
1179 * There are generally 2 possibilities as to why we'd get
1181 * We sent or received data.
1182 * We sent status & command complete.
1189 * Target Reset function received.
1191 * The firmware generates an async mailbox interupt to
1192 * notify us of this and returns outstanding CTIOs with this
1193 * status. These CTIOs are handled in that same way as
1194 * CT_ABORTED ones, so just fall through here.
1196 fmsg = "TARGET RESET Task Management Function Received";
1204 * When an Abort message is received the firmware goes to
1205 * Bus Free and returns all outstanding CTIOs with the status
1206 * set, then sends us an Immediate Notify entry.
1209 fmsg = "ABORT Task Management Function Received";
1211 isp_prt(isp, ISP_LOGERR, "CTIO2 destroyed by %s: RX_ID=0x%x",
1217 * CTIO rejected by the firmware - invalid data direction.
1219 isp_prt(isp, ISP_LOGERR, "CTIO2 had wrong data direction");
1223 fmsg = "failure to reconnect to initiator";
1228 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
1232 fmsg = "Completed with Error";
1236 fmsg = "Port Logout";
1238 case CT_PORTNOTAVAIL:
1240 fmsg = "Port not available";
1242 case CT_PORTCHANGED:
1244 fmsg = "Port Changed";
1248 fmsg = "unacknowledged Immediate Notify pending";
1249 isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg);
1254 * CTIO rejected by the firmware because an invalid RX_ID.
1255 * Just print a message.
1257 isp_prt(isp, ISP_LOGERR,
1258 "CTIO2 completed with Invalid RX_ID 0x%x", ct->ct_rxid);
1262 isp_prt(isp, ISP_LOGERR, "Unknown CTIO2 status 0x%x",
1263 ct->ct_status & ~QLTM_SVALID);
1269 * There may be more than one CTIO for a data transfer,
1270 * or this may be a status CTIO we're not monitoring.
1272 * The assumption is that they'll all be returned in the
1273 * order we got them.
1275 if (ct->ct_syshandle == 0) {
1276 if ((ct->ct_flags & CT2_SENDSTATUS) == 0) {
1278 "intermediate CTIO completed ok");
1281 "unmonitored CTIO completed ok");
1285 "NO xs for CTIO (handle 0x%x) status 0x%x",
1286 ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1289 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
1290 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1292 if (ct->ct_flags & CT2_SENDSTATUS) {
1294 * Sent status and command complete.
1296 * We're now really done with this command, so we
1297 * punt to the platform dependent layers because
1298 * only there can we do the appropriate command
1299 * complete thread synchronization.
1301 isp_prt(isp, pl, "status CTIO complete");
1304 * Final CTIO completed. Release DMA resources and
1305 * notify platform dependent layers.
1307 isp_prt(isp, pl, "data CTIO complete");
1309 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1311 * The platform layer will destroy the handle if appropriate.