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 loopid %d because a Bus Reset "
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 *);
69 * The Qlogic driver gets an interrupt to look at response queue entries.
70 * Some of these are status completions for initiatior mode commands, but
71 * if target mode is enabled, we get a whole wad of response queue entries
74 * Basically the split into 3 main groups: Lun Enable/Modification responses,
75 * SCSI Command processing, and Immediate Notification events.
77 * You start by writing a request queue entry to enable target mode (and
78 * establish some resource limitations which you can modify later).
79 * The f/w responds with a LUN ENABLE or LUN MODIFY response with
80 * the status of this action. If the enable was successful, you can expect...
82 * Response queue entries with SCSI commands encapsulate show up in an ATIO
83 * (Accept Target IO) type- sometimes with enough info to stop the command at
84 * this level. Ultimately the driver has to feed back to the f/w's request
85 * queue a sequence of CTIOs (continue target I/O) that describe data to
86 * be moved and/or status to be sent) and finally finishing with sending
87 * to the f/w's response queue an ATIO which then completes the handshake
88 * with the f/w for that command. There's a lot of variations on this theme,
89 * including flags you can set in the CTIO for the Qlogic 2X00 fibre channel
90 * cards that 'auto-replenish' the f/w's ATIO count, but this is the basic
93 * The third group that can show up in the response queue are Immediate
94 * Notification events. These include things like notifications of SCSI bus
95 * resets, or Bus Device Reset messages or other messages received. This
96 * a classic oddbins area. It can get a little weird because you then turn
97 * around and acknowledge the Immediate Notify by writing an entry onto the
98 * request queue and then the f/w turns around and gives you an acknowledgement
99 * to *your* acknowledgement on the response queue (the idea being to let
100 * the f/w tell you when the event is *really* over I guess).
106 * A new response queue entry has arrived. The interrupt service code
107 * has already swizzled it into the platform dependent from canonical form.
109 * Because of the way this driver is designed, unfortunately most of the
110 * actual synchronization work has to be done in the platform specific
111 * code- we have no synchroniation primitives in the common code.
115 isp_target_notify(ispsoftc_t *isp, void *vptr, uint32_t *optrp)
122 at2e_entry_t *at2eiop;
126 ct2e_entry_t *ct2eiop;
130 in_fcentry_t *inot_fcp;
131 in_fcentry_e_t *inote_fcp;
132 in_fcentry_24xx_t *inot_24xx;
134 na_fcentry_t *nack_fcp;
135 na_fcentry_e_t *nacke_fcp;
136 na_fcentry_24xx_t *nack_24xx;
139 abts_rsp_t *abts_rsp;
142 #define atiop unp.atiop
143 #define at2iop unp.at2iop
144 #define at2eiop unp.at2eiop
145 #define at7iop unp.at7iop
146 #define ctiop unp.ctiop
147 #define ct2iop unp.ct2iop
148 #define ct2eiop unp.ct2eiop
149 #define ct7iop unp.ct7iop
150 #define lunenp unp.lunenp
151 #define inotp unp.inotp
152 #define inot_fcp unp.inot_fcp
153 #define inote_fcp unp.inote_fcp
154 #define inot_24xx unp.inot_24xx
155 #define nackp unp.nackp
156 #define nack_fcp unp.nack_fcp
157 #define nacke_fcp unp.nacke_fcp
158 #define nack_24xx unp.nack_24xx
159 #define abts unp.abts
160 #define abts_rsp unp.abts_rsp
164 uint8_t local[QENTRY_LEN];
165 int bus, type, level, rval = 1;
167 type = isp_get_response_type(isp, (isphdr_t *)vptr);
170 ISP_TDQE(isp, "isp_target_notify", (int) *optrp, vptr);
177 isp_get_atio7(isp, at7iop, (at7_entry_t *) local);
178 at7iop = (at7_entry_t *) local;
180 * Check for and do something with commands whose IULEN
181 * extends past a singel queue entry.
183 len = at7iop->at_ta_len & 0xfffff;
184 if (len > (QENTRY_LEN - 8)) {
185 len -= (QENTRY_LEN - 8);
186 isp_prt(isp, ISP_LOGINFO,
187 "long IU length (%d) ignored", len);
189 *optrp = ISP_NXT_QENTRY(*optrp,
190 RESULT_QUEUE_LEN(isp));
195 * Check for a task management function
197 if (at7iop->at_cmnd.fcp_cmnd_task_management) {
198 isp_got_tmf_24xx(isp, at7iop);
202 * Just go straight to outer layer for this one.
204 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, local);
206 isp_get_atio(isp, atiop, (at_entry_t *) local);
207 isp_handle_atio(isp, (at_entry_t *) local);
212 isp_get_ctio(isp, ctiop, (ct_entry_t *) local);
213 isp_handle_ctio(isp, (ct_entry_t *) local);
217 if (FCPARAM(isp)->isp_2klogin) {
218 isp_get_atio2e(isp, at2eiop, (at2e_entry_t *) local);
220 isp_get_atio2(isp, at2iop, (at2_entry_t *) local);
222 isp_handle_atio2(isp, (at2_entry_t *) local);
227 if (FCPARAM(isp)->isp_2klogin) {
228 isp_get_ctio2e(isp, ct2eiop, (ct2e_entry_t *) local);
230 isp_get_ctio2(isp, ct2iop, (ct2_entry_t *) local);
232 isp_handle_ctio2(isp, (ct2_entry_t *) local);
236 isp_get_ctio7(isp, ct7iop, (ct7_entry_t *) local);
237 isp_handle_ctio7(isp, (ct7_entry_t *) local);
240 case RQSTYPE_ENABLE_LUN:
241 case RQSTYPE_MODIFY_LUN:
242 isp_get_enable_lun(isp, lunenp, (lun_entry_t *) local);
243 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, local);
248 * Either the ISP received a SCSI message it can't
249 * handle, or it's returning an Immed. Notify entry
250 * we sent. We can send Immed. Notify entries to
251 * increment the firmware's resource count for them
252 * (we set this initially in the Enable Lun entry).
256 isp_get_notify_24xx(isp, inot_24xx,
257 (in_fcentry_24xx_t *)local);
258 inot_24xx = (in_fcentry_24xx_t *) local;
259 status = inot_24xx->in_status;
260 seqid = inot_24xx->in_rxid;
261 isp_prt(isp, ISP_LOGTDEBUG0,
262 "Immediate Notify status=0x%x seqid=0x%x",
265 case IN24XX_LIP_RESET:
266 case IN24XX_LINK_RESET:
267 case IN24XX_PORT_LOGOUT:
268 case IN24XX_PORT_CHANGED:
269 case IN24XX_LINK_FAILED:
270 case IN24XX_SRR_RCVD:
271 case IN24XX_ELS_RCVD:
272 (void) isp_async(isp, ISPASYNC_TARGET_ACTION,
276 isp_prt(isp, ISP_LOGINFO,
277 "isp_target_notify: unknown status (0x%x)",
279 isp_notify_ack(isp, local);
283 } else if (IS_FC(isp)) {
284 if (FCPARAM(isp)->isp_2klogin) {
285 isp_get_notify_fc_e(isp, inote_fcp,
286 (in_fcentry_e_t *)local);
288 isp_get_notify_fc(isp, inot_fcp,
289 (in_fcentry_t *)local);
291 inot_fcp = (in_fcentry_t *) local;
292 status = inot_fcp->in_status;
293 seqid = inot_fcp->in_seqid;
295 isp_get_notify(isp, inotp, (in_entry_t *)local);
296 inotp = (in_entry_t *) local;
297 status = inotp->in_status & 0xff;
298 seqid = inotp->in_seqid;
299 if (IS_DUALBUS(isp)) {
300 bus = GET_BUS_VAL(inotp->in_iid);
301 SET_BUS_VAL(inotp->in_iid, 0);
305 isp_prt(isp, ISP_LOGTDEBUG0,
306 "Immediate Notify On Bus %d, status=0x%x seqid=0x%x",
310 case IN_MSG_RECEIVED:
311 case IN_IDE_RECEIVED:
313 isp_got_msg_fc(isp, (in_fcentry_t *)local);
315 isp_got_msg(isp, (in_entry_t *)local);
318 case IN_RSRC_UNAVAIL:
319 isp_prt(isp, ISP_LOGINFO, "Firmware out of ATIOs");
320 isp_notify_ack(isp, local);
325 * We form the notify structure here because we need
326 * to mark it as needing a NOTIFY ACK on return.
330 MEMZERO(¬ify, sizeof (tmd_notify_t));
332 notify.nt_iid = INI_ANY;
333 /* nt_tgt set in outer layers */
334 notify.nt_lun = LUN_ANY;
335 notify.nt_tagval = TAG_ANY;
336 notify.nt_ncode = NT_BUS_RESET;
337 notify.nt_need_ack = 1;
338 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
343 case IN_PORT_CHANGED:
345 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, &local);
348 isp_prt(isp, ISP_LOGINFO,
349 "isp_target_notify: unknown status (0x%x)",
351 isp_notify_ack(isp, local);
356 case RQSTYPE_NOTIFY_ACK:
358 * The ISP is acknowledging our acknowledgement of an
359 * Immediate Notify entry for some asynchronous event.
362 isp_get_notify_ack_24xx(isp, nack_24xx,
363 (na_fcentry_24xx_t *) local);
364 nack_24xx = (na_fcentry_24xx_t *) local;
365 if (nack_24xx->na_status != NA_OK) {
368 level = ISP_LOGTDEBUG1;
371 "Notify Ack Status=0x%x; Subcode 0x%x seqid=0x%x",
372 nack_24xx->na_status, nack_24xx->na_status_subcode,
374 } else if (IS_FC(isp)) {
375 if (FCPARAM(isp)->isp_2klogin) {
376 isp_get_notify_ack_fc_e(isp, nacke_fcp,
377 (na_fcentry_e_t *)local);
379 isp_get_notify_ack_fc(isp, nack_fcp,
380 (na_fcentry_t *)local);
382 nack_fcp = (na_fcentry_t *)local;
383 if (nack_fcp->na_status != NA_OK) {
386 level = ISP_LOGTDEBUG1;
389 "Notify Ack Status=0x%x seqid 0x%x",
390 nack_fcp->na_status, nack_fcp->na_seqid);
392 isp_get_notify_ack(isp, nackp, (na_entry_t *)local);
393 nackp = (na_entry_t *)local;
394 if (nackp->na_status != NA_OK) {
397 level = ISP_LOGTDEBUG1;
400 "Notify Ack event 0x%x status=0x%x seqid 0x%x",
401 nackp->na_event, nackp->na_status, nackp->na_seqid);
405 case RQSTYPE_ABTS_RCVD:
406 isp_get_abts(isp, abts, (abts_t *)local);
407 (void) 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;
418 "ABTS RSP response[0x%x]: status=0x%x sub=(0x%x 0x%x)",
419 abts_rsp->abts_rsp_rxid_task, abts_rsp->abts_rsp_status,
420 abts_rsp->abts_rsp_payload.rsp.subcode1,
421 abts_rsp->abts_rsp_payload.rsp.subcode2);
424 isp_prt(isp, ISP_LOGERR,
425 "Unknown entry type 0x%x in isp_target_notify", type);
455 * Toggle (on/off) target mode for bus/target/lun
457 * The caller has checked for overlap and legality.
459 * Note that not all of bus, target or lun can be paid attention to.
460 * Note also that this action will not be complete until the f/w writes
461 * response entry. The caller is responsible for synchronizing this.
464 isp_lun_cmd(ispsoftc_t *isp, int cmd, int bus, int tgt, int lun,
465 int cmd_cnt, int inot_cnt, uint32_t opaque)
472 MEMZERO(&el, sizeof (el));
473 if (IS_DUALBUS(isp)) {
474 el.le_rsvd = (bus & 0x1) << 7;
476 el.le_cmd_count = cmd_cnt;
477 el.le_in_count = inot_cnt;
478 if (cmd == RQSTYPE_ENABLE_LUN) {
480 el.le_flags = LUN_TQAE|LUN_DISAD;
484 } else if (cmd == -RQSTYPE_ENABLE_LUN) {
485 cmd = RQSTYPE_ENABLE_LUN;
488 } else if (cmd == -RQSTYPE_MODIFY_LUN) {
489 cmd = RQSTYPE_MODIFY_LUN;
490 el.le_ops = LUN_CCDECR | LUN_INDECR;
492 el.le_ops = LUN_CCINCR | LUN_ININCR;
494 el.le_header.rqs_entry_type = cmd;
495 el.le_header.rqs_entry_count = 1;
496 el.le_reserved = opaque;
500 } else if (FCPARAM(isp)->isp_sccfw == 0) {
505 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
506 isp_prt(isp, ISP_LOGERR,
507 "Request Queue Overflow in isp_lun_cmd");
510 ISP_TDQE(isp, "isp_lun_cmd", (int) optr, &el);
511 isp_put_enable_lun(isp, &el, outp);
512 ISP_ADD_REQUEST(isp, nxti);
518 isp_target_put_entry(ispsoftc_t *isp, void *ap)
522 uint8_t etype = ((isphdr_t *) ap)->rqs_entry_type;
524 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
525 isp_prt(isp, ISP_LOGWARN,
526 "Request Queue Overflow in isp_target_put_entry");
531 isp_put_atio(isp, (at_entry_t *) ap, (at_entry_t *) outp);
534 if (FCPARAM(isp)->isp_2klogin) {
535 isp_put_atio2e(isp, (at2e_entry_t *) ap,
536 (at2e_entry_t *) outp);
538 isp_put_atio2(isp, (at2_entry_t *) ap,
539 (at2_entry_t *) outp);
543 isp_put_ctio(isp, (ct_entry_t *) ap, (ct_entry_t *) outp);
546 if (FCPARAM(isp)->isp_2klogin) {
547 isp_put_ctio2e(isp, (ct2e_entry_t *) ap,
548 (ct2e_entry_t *) outp);
550 isp_put_ctio2(isp, (ct2_entry_t *) ap,
551 (ct2_entry_t *) outp);
555 isp_put_ctio7(isp, (ct7_entry_t *) ap, (ct7_entry_t *) outp);
558 isp_prt(isp, ISP_LOGERR,
559 "Unknown type 0x%x in isp_put_entry", etype);
562 ISP_TDQE(isp, "isp_target_put_entry", (int) optr, ap);
563 ISP_ADD_REQUEST(isp, nxti);
568 isp_target_put_atio(ispsoftc_t *isp, void *arg)
573 at2e_entry_t _atio2e;
576 MEMZERO(&atun, sizeof atun);
578 at2_entry_t *aep = arg;
579 atun._atio2.at_header.rqs_entry_type = RQSTYPE_ATIO2;
580 atun._atio2.at_header.rqs_entry_count = 1;
581 if (FCPARAM(isp)->isp_sccfw) {
582 atun._atio2.at_scclun = aep->at_scclun;
584 atun._atio2.at_lun = (uint8_t) aep->at_lun;
586 if (FCPARAM(isp)->isp_2klogin) {
587 atun._atio2e.at_iid = ((at2e_entry_t *)aep)->at_iid;
589 atun._atio2.at_iid = aep->at_iid;
591 atun._atio2.at_rxid = aep->at_rxid;
592 atun._atio2.at_status = CT_OK;
594 at_entry_t *aep = arg;
595 atun._atio.at_header.rqs_entry_type = RQSTYPE_ATIO;
596 atun._atio.at_header.rqs_entry_count = 1;
597 atun._atio.at_handle = aep->at_handle;
598 atun._atio.at_iid = aep->at_iid;
599 atun._atio.at_tgt = aep->at_tgt;
600 atun._atio.at_lun = aep->at_lun;
601 atun._atio.at_tag_type = aep->at_tag_type;
602 atun._atio.at_tag_val = aep->at_tag_val;
603 atun._atio.at_status = (aep->at_flags & AT_TQAE);
604 atun._atio.at_status |= CT_OK;
606 return (isp_target_put_entry(isp, &atun));
610 * Command completion- both for handling cases of no resources or
611 * no blackhole driver, or other cases where we have to, inline,
612 * finish the command sanely, or for normal command completion.
614 * The 'completion' code value has the scsi status byte in the low 8 bits.
615 * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have
616 * the sense key and bits 16..23 have the ASCQ and bits 24..31 have the ASC
619 * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't
620 * NB: inline SCSI sense reporting. As such, we lose this information. XXX.
622 * For both parallel && fibre channel, we use the feature that does
623 * an automatic resource autoreplenish so we don't have then later do
624 * put of an atio to replenish the f/w's resource count.
628 isp_endcmd(ispsoftc_t *isp, void *arg, uint32_t code, uint32_t hdl)
634 ct2e_entry_t _ctio2e;
638 MEMZERO(&un, sizeof un);
642 at7_entry_t *aep = arg;
643 ct7_entry_t *cto = &un._ctio7;
645 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
646 cto->ct_header.rqs_entry_count = 1;
647 /* XXXX */ cto->ct_nphdl = aep->at_hdr.seq_id;
648 cto->ct_rxid = aep->at_rxid;
649 cto->ct_iid_lo = (aep->at_hdr.s_id[1] << 8) |
651 cto->ct_iid_hi = aep->at_hdr.s_id[0];
652 cto->ct_oxid = aep->at_hdr.ox_id;
653 cto->ct_scsi_status = sts;
654 cto->ct_flags = CT7_FLAG_MODE1 | CT7_NO_DATA | CT7_SENDSTATUS;
655 if (sts == SCSI_CHECK && (code & ECMD_SVALID)) {
656 cto->rsp.m1.ct_resplen = 16;
657 cto->rsp.m1.ct_resp[0] = 0xf0;
658 cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
659 cto->rsp.m1.ct_resp[7] = 8;
660 cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff;
661 cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff;
663 if (aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl) {
664 cto->ct_resid = aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl;
665 cto->ct_scsi_status |= CT2_DATA_UNDER;
667 cto->ct_syshandle = hdl;
668 } else if (IS_FC(isp)) {
669 at2_entry_t *aep = arg;
670 ct2_entry_t *cto = &un._ctio2;
672 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
673 cto->ct_header.rqs_entry_count = 1;
674 if (FCPARAM(isp)->isp_sccfw == 0) {
675 cto->ct_lun = aep->at_lun;
677 if (FCPARAM(isp)->isp_2klogin) {
678 un._ctio2e.ct_iid = ((at2e_entry_t *)aep)->at_iid;
680 cto->ct_iid = aep->at_iid;
682 cto->ct_rxid = aep->at_rxid;
683 cto->rsp.m1.ct_scsi_status = sts;
684 cto->ct_flags = CT2_SENDSTATUS | CT2_NO_DATA | CT2_FLAG_MODE1;
686 cto->ct_flags |= CT2_CCINCR;
688 if (aep->at_datalen) {
689 cto->ct_resid = aep->at_datalen;
690 cto->rsp.m1.ct_scsi_status |= CT2_DATA_UNDER;
692 if (sts == SCSI_CHECK && (code & ECMD_SVALID)) {
693 cto->rsp.m1.ct_resp[0] = 0xf0;
694 cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
695 cto->rsp.m1.ct_resp[7] = 8;
696 cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff;
697 cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff;
698 cto->rsp.m1.ct_senselen = 16;
699 cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID;
701 cto->ct_syshandle = hdl;
703 at_entry_t *aep = arg;
704 ct_entry_t *cto = &un._ctio;
706 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
707 cto->ct_header.rqs_entry_count = 1;
708 cto->ct_fwhandle = aep->at_handle;
709 cto->ct_iid = aep->at_iid;
710 cto->ct_tgt = aep->at_tgt;
711 cto->ct_lun = aep->at_lun;
712 cto->ct_tag_type = aep->at_tag_type;
713 cto->ct_tag_val = aep->at_tag_val;
714 if (aep->at_flags & AT_TQAE) {
715 cto->ct_flags |= CT_TQAE;
717 cto->ct_flags = CT_SENDSTATUS | CT_NO_DATA;
719 cto->ct_flags |= CT_CCINCR;
721 cto->ct_scsi_status = sts;
722 cto->ct_syshandle = hdl;
724 return (isp_target_put_entry(isp, &un));
728 * These are either broadcast events or specifically CTIO fast completion
731 isp_target_async(ispsoftc_t *isp, int bus, int event)
735 MEMZERO(¬ify, sizeof (tmd_notify_t));
737 notify.nt_iid = INI_ANY;
738 /* nt_tgt set in outer layers */
739 notify.nt_lun = LUN_ANY;
740 notify.nt_tagval = TAG_ANY;
743 TAG_INSERT_BUS(notify.nt_tagval, bus);
749 notify.nt_ncode = NT_LINK_UP;
750 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
752 case ASYNC_LOOP_DOWN:
753 notify.nt_ncode = NT_LINK_DOWN;
754 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
756 case ASYNC_LIP_ERROR:
758 case ASYNC_LIP_OCCURRED:
759 case ASYNC_LOOP_RESET:
760 notify.nt_ncode = NT_LIP_RESET;
761 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
763 case ASYNC_BUS_RESET:
764 case ASYNC_TIMEOUT_RESET: /* XXX: where does this come from ? */
765 notify.nt_ncode = NT_BUS_RESET;
766 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
768 case ASYNC_DEVICE_RESET:
769 notify.nt_ncode = NT_TARGET_RESET;
770 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
772 case ASYNC_CTIO_DONE:
774 uint8_t storage[QENTRY_LEN];
775 memset(storage, 0, QENTRY_LEN);
777 ct7_entry_t *ct = (ct7_entry_t *) storage;
778 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
779 ct->ct_nphdl = CT7_OK;
780 ct->ct_syshandle = bus;
781 ct->ct_flags = CT7_SENDSTATUS|CT7_FASTPOST;
782 } else if (IS_FC(isp)) {
783 /* This should also suffice for 2K login code */
784 ct2_entry_t *ct = (ct2_entry_t *) storage;
785 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
786 ct->ct_status = CT_OK;
787 ct->ct_syshandle = bus;
788 ct->ct_flags = CT2_SENDSTATUS|CT2_FASTPOST;
790 ct_entry_t *ct = (ct_entry_t *) storage;
791 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO;
792 ct->ct_status = CT_OK;
793 ct->ct_fwhandle = bus;
794 ct->ct_flags = CT_SENDSTATUS;
796 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, storage);
800 isp_prt(isp, ISP_LOGERR,
801 "isp_target_async: unknown event 0x%x", event);
802 if (isp->isp_state == ISP_RUNSTATE) {
803 isp_notify_ack(isp, NULL);
812 * Process a received message.
813 * The ISP firmware can handle most messages, there are only
814 * a few that we need to deal with:
815 * - abort: clean up the current command
816 * - abort tag and clear queue
820 isp_got_msg(ispsoftc_t *isp, in_entry_t *inp)
823 uint8_t status = inp->in_status & ~QLTM_SVALID;
825 MEMZERO(&nt, sizeof (nt));
827 nt.nt_iid = GET_IID_VAL(inp->in_iid);
828 nt.nt_tgt = inp->in_tgt;
829 nt.nt_lun = inp->in_lun;
830 IN_MAKE_TAGID(nt.nt_tagval, GET_BUS_VAL(inp->in_iid), 0, inp);
831 nt.nt_lreserved = inp;
833 if (status == IN_IDE_RECEIVED || status == IN_MSG_RECEIVED) {
834 switch (inp->in_msg[0]) {
836 nt.nt_ncode = NT_ABORT_TASK_SET;
838 case MSG_BUS_DEV_RESET:
839 nt.nt_ncode = NT_TARGET_RESET;
842 nt.nt_ncode = NT_ABORT_TASK;
844 case MSG_CLEAR_QUEUE:
845 nt.nt_ncode = NT_CLEAR_TASK_SET;
847 case MSG_REL_RECOVERY:
848 nt.nt_ncode = NT_CLEAR_ACA;
850 case MSG_TERM_IO_PROC:
851 nt.nt_ncode = NT_ABORT_TASK;
854 nt.nt_ncode = NT_LUN_RESET;
857 isp_prt(isp, ISP_LOGERR,
858 "unhandled message 0x%x", inp->in_msg[0]);
859 isp_notify_ack(isp, inp);
862 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt);
864 isp_prt(isp, ISP_LOGERR,
865 "unknown immediate notify status 0x%x", inp->in_status);
866 isp_notify_ack(isp, inp);
871 * Synthesize a message from the task management flags in a FCP_CMND_IU.
874 isp_got_msg_fc(ispsoftc_t *isp, in_fcentry_t *inp)
877 static const char f1[] = "%s from N-port handle 0x%x lun %d seq 0x%x";
878 static const char f2[] = "unknown %s 0x%x lun %d N-Port handle 0x%x "
879 "task flags 0x%x seq 0x%x\n";
880 uint16_t seqid, loopid;
882 MEMZERO(&nt, sizeof (tmd_notify_t));
884 if (FCPARAM(isp)->isp_2klogin) {
885 nt.nt_iid = ((in_fcentry_e_t *)inp)->in_iid;
886 loopid = ((in_fcentry_e_t *)inp)->in_iid;
887 seqid = ((in_fcentry_e_t *)inp)->in_seqid;
889 nt.nt_iid = inp->in_iid;
890 loopid = inp->in_iid;
891 seqid = inp->in_seqid;
893 /* nt_tgt set in outer layers */
894 if (FCPARAM(isp)->isp_sccfw) {
895 nt.nt_lun = inp->in_scclun;
897 nt.nt_lun = inp->in_lun;
899 IN_FC_MAKE_TAGID(nt.nt_tagval, 0, 0, seqid);
901 nt.nt_lreserved = inp;
903 if (inp->in_status != IN_MSG_RECEIVED) {
904 isp_prt(isp, ISP_LOGINFO, f2, "immediate notify status",
905 inp->in_status, nt.nt_lun, loopid, inp->in_task_flags,
907 isp_notify_ack(isp, inp);
911 if (inp->in_task_flags & TASK_FLAGS_ABORT_TASK_SET) {
912 isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET",
913 loopid, nt.nt_lun, inp->in_seqid);
914 nt.nt_ncode = NT_ABORT_TASK_SET;
915 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_TASK_SET) {
916 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET",
917 loopid, nt.nt_lun, inp->in_seqid);
918 nt.nt_ncode = NT_CLEAR_TASK_SET;
919 } else if (inp->in_task_flags & TASK_FLAGS_LUN_RESET) {
920 isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET",
921 loopid, nt.nt_lun, inp->in_seqid);
922 nt.nt_ncode = NT_LUN_RESET;
923 } else if (inp->in_task_flags & TASK_FLAGS_TARGET_RESET) {
924 isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET",
925 loopid, nt.nt_lun, inp->in_seqid);
926 nt.nt_ncode = NT_TARGET_RESET;
927 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_ACA) {
928 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA",
929 loopid, nt.nt_lun, inp->in_seqid);
930 nt.nt_ncode = NT_CLEAR_ACA;
932 isp_prt(isp, ISP_LOGWARN, f2, "task flag", inp->in_status,
933 nt.nt_lun, loopid, inp->in_task_flags, inp->in_seqid);
934 isp_notify_ack(isp, inp);
937 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt);
940 #define HILO(x) (uint32_t) (x >> 32), (uint32_t) x
942 isp_got_tmf_24xx(ispsoftc_t *isp, at7_entry_t *aep)
945 static const char f1[] =
946 "%s from PortID 0x%06x lun %d seq 0x%08x%08x";
947 static const char f2[] =
948 "unknown Task Flag 0x%x lun %d PortID 0x%x tag 0x%08x%08x";
951 MEMZERO(&nt, sizeof (tmd_notify_t));
955 (aep->at_cmnd.fcp_cmnd_lun[0] << 8) |
956 (aep->at_cmnd.fcp_cmnd_lun[1]);
958 * XXX: VPIDX HAS TO BE DERIVED FROM DESTINATION PORT
960 nt.nt_tagval = aep->at_rxid;
961 nt.nt_lreserved = aep;
963 (aep->at_hdr.s_id[0] << 16) |
964 (aep->at_hdr.s_id[1] << 8) |
965 (aep->at_hdr.s_id[2]);
967 if (aep->at_cmnd.fcp_cmnd_task_management &
968 FCP_CMND_TMF_ABORT_TASK_SET) {
969 isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET",
970 sid, nt.nt_lun, HILO(nt.nt_tagval));
971 nt.nt_ncode = NT_ABORT_TASK_SET;
972 } else if (aep->at_cmnd.fcp_cmnd_task_management &
973 FCP_CMND_TMF_CLEAR_TASK_SET) {
974 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET",
975 sid, nt.nt_lun, HILO(nt.nt_tagval));
976 nt.nt_ncode = NT_CLEAR_TASK_SET;
977 } else if (aep->at_cmnd.fcp_cmnd_task_management &
978 FCP_CMND_TMF_LUN_RESET) {
979 isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET",
980 sid, nt.nt_lun, HILO(nt.nt_tagval));
981 nt.nt_ncode = NT_LUN_RESET;
982 } else if (aep->at_cmnd.fcp_cmnd_task_management &
983 FCP_CMND_TMF_TGT_RESET) {
984 isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET",
985 sid, nt.nt_lun, HILO(nt.nt_tagval));
986 nt.nt_ncode = NT_TARGET_RESET;
988 } else if (aep->at_cmnd.fcp_cmnd_task_management &
989 FCP_CMND_TMF_CLEAR_ACA) {
990 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA",
991 sid, nt.nt_lun, HILO(nt.nt_tagval));
992 nt.nt_ncode = NT_CLEAR_ACA;
994 isp_prt(isp, ISP_LOGWARN, f2,
995 aep->at_cmnd.fcp_cmnd_task_management,
996 nt.nt_lun, sid, HILO(nt.nt_tagval));
997 isp_endcmd(isp, aep, 0, 0);
1000 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt);
1004 isp_notify_ack(ispsoftc_t *isp, void *arg)
1006 char storage[QENTRY_LEN];
1007 uint32_t nxti, optr;
1010 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
1011 isp_prt(isp, ISP_LOGWARN,
1012 "Request Queue Overflow For isp_notify_ack");
1016 MEMZERO(storage, QENTRY_LEN);
1018 if (IS_24XX(isp) && arg != NULL && (((isphdr_t *)arg)->rqs_entry_type == RQSTYPE_ATIO)) {
1019 at7_entry_t *aep = arg;
1020 isp_endcmd(isp, aep, 0, 0);
1022 } else if (IS_24XX(isp) && arg != NULL && (((isphdr_t *)arg)->rqs_entry_type == RQSTYPE_ABTS_RSP)) {
1023 abts_rsp_t *abts_rsp = (abts_rsp_t *) storage;
1025 * The caller will have set response values as appropriate
1026 * in the ABTS structure just before calling us.
1028 MEMCPY(abts_rsp, arg, QENTRY_LEN);
1029 isp_put_abts_rsp(isp, abts_rsp, (abts_rsp_t *)outp);
1030 } else if (IS_24XX(isp)) {
1031 na_fcentry_24xx_t *na = (na_fcentry_24xx_t *) storage;
1033 in_fcentry_24xx_t *in = arg;
1034 na->na_nphdl = in->in_nphdl;
1035 na->na_status = in->in_status;
1036 na->na_status_subcode = in->in_status_subcode;
1037 na->na_rxid = in->in_rxid;
1038 na->na_oxid = in->in_oxid;
1039 if (in->in_status == IN24XX_SRR_RCVD) {
1040 na->na_srr_rxid = in->in_srr_rxid;
1041 na->na_srr_reloff_hi = in->in_srr_reloff_hi;
1042 na->na_srr_reloff_lo = in->in_srr_reloff_lo;
1043 na->na_srr_iu = in->in_srr_iu;
1044 na->na_srr_flags = 1;
1045 na->na_srr_reject_vunique = 0;
1046 na->na_srr_reject_explanation = 1;
1047 na->na_srr_reject_code = 1;
1050 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
1051 na->na_header.rqs_entry_count = 1;
1052 isp_put_notify_24xx_ack(isp, na, (na_fcentry_24xx_t *)outp);
1053 } else if (IS_FC(isp)) {
1054 na_fcentry_t *na = (na_fcentry_t *) storage;
1058 in_fcentry_t *inp = arg;
1059 MEMCPY(storage, arg, sizeof (isphdr_t));
1060 if (FCPARAM(isp)->isp_2klogin) {
1061 ((na_fcentry_e_t *)na)->na_iid =
1062 ((in_fcentry_e_t *)inp)->in_iid;
1063 iid = ((na_fcentry_e_t *)na)->na_iid;
1065 na->na_iid = inp->in_iid;
1069 inp->in_task_flags & TASK_FLAGS_RESERVED_MASK;
1070 na->na_seqid = inp->in_seqid;
1071 na->na_flags = NAFC_RCOUNT;
1072 na->na_status = inp->in_status;
1073 if (inp->in_status == IN_RESET) {
1074 na->na_flags |= NAFC_RST_CLRD;
1076 if (inp->in_status == IN_MSG_RECEIVED) {
1077 na->na_flags |= NAFC_TVALID;
1078 na->na_response = 0; /* XXX SUCCEEDED XXX */
1081 na->na_flags = NAFC_RST_CLRD;
1083 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
1084 na->na_header.rqs_entry_count = 1;
1085 if (FCPARAM(isp)->isp_2klogin) {
1086 isp_put_notify_ack_fc_e(isp, (na_fcentry_e_t *) na,
1087 (na_fcentry_e_t *)outp);
1089 isp_put_notify_ack_fc(isp, na, (na_fcentry_t *)outp);
1091 isp_prt(isp, ISP_LOGTDEBUG0, "notify ack loopid %u seqid %x "
1092 "flags %x tflags %x response %x", iid, na->na_seqid,
1093 na->na_flags, na->na_task_flags, na->na_response);
1095 na_entry_t *na = (na_entry_t *) storage;
1097 in_entry_t *inp = arg;
1098 MEMCPY(storage, arg, sizeof (isphdr_t));
1099 na->na_iid = inp->in_iid;
1100 na->na_lun = inp->in_lun;
1101 na->na_tgt = inp->in_tgt;
1102 na->na_seqid = inp->in_seqid;
1103 if (inp->in_status == IN_RESET) {
1104 na->na_event = NA_RST_CLRD;
1107 na->na_event = NA_RST_CLRD;
1109 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
1110 na->na_header.rqs_entry_count = 1;
1111 isp_put_notify_ack(isp, na, (na_entry_t *)outp);
1112 isp_prt(isp, ISP_LOGTDEBUG0, "notify ack loopid %u lun %u tgt "
1113 "%u seqid %x event %x", na->na_iid, na->na_lun, na->na_tgt,
1114 na->na_seqid, na->na_event);
1116 ISP_TDQE(isp, "isp_notify_ack", (int) optr, storage);
1117 ISP_ADD_REQUEST(isp, nxti);
1121 isp_handle_atio(ispsoftc_t *isp, at_entry_t *aep)
1126 * The firmware status (except for the QLTM_SVALID bit) indicates
1127 * why this ATIO was sent to us.
1129 * If QLTM_SVALID is set, the firware has recommended Sense Data.
1131 * If the DISCONNECTS DISABLED bit is set in the flags field,
1132 * we're still connected on the SCSI bus - i.e. the initiator
1133 * did not set DiscPriv in the identify message. We don't care
1134 * about this so it's ignored.
1137 switch(aep->at_status & ~QLTM_SVALID) {
1138 case AT_PATH_INVALID:
1140 * ATIO rejected by the firmware due to disabled lun.
1142 isp_prt(isp, ISP_LOGERR,
1143 "rejected ATIO for disabled lun %d", lun);
1147 * Requested Capability not available
1148 * We sent an ATIO that overflowed the firmware's
1149 * command resource count.
1151 isp_prt(isp, ISP_LOGERR,
1152 "rejected ATIO for lun %d because of command count"
1158 * If we send an ATIO to the firmware to increment
1159 * its command resource count, and the firmware is
1160 * recovering from a Bus Device Reset, it returns
1161 * the ATIO with this status. We set the command
1162 * resource count in the Enable Lun entry and do
1163 * not increment it. Therefore we should never get
1166 isp_prt(isp, ISP_LOGERR, atiocope, lun,
1167 GET_BUS_VAL(aep->at_iid));
1170 case AT_CDB: /* Got a CDB */
1171 case AT_PHASE_ERROR: /* Bus Phase Sequence Error */
1173 * Punt to platform specific layer.
1175 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
1180 * A bus reset came along and blew away this command. Why
1181 * they do this in addition the async event code stuff,
1184 * Ignore it because the async event will clear things
1187 isp_prt(isp, ISP_LOGWARN, atior, lun,
1188 GET_IID_VAL(aep->at_iid), GET_BUS_VAL(aep->at_iid));
1193 isp_prt(isp, ISP_LOGERR,
1194 "Unknown ATIO status 0x%x from loopid %d for lun %d",
1195 aep->at_status, aep->at_iid, lun);
1196 (void) isp_target_put_atio(isp, aep);
1202 isp_handle_atio2(ispsoftc_t *isp, at2_entry_t *aep)
1206 if (FCPARAM(isp)->isp_sccfw) {
1207 lun = aep->at_scclun;
1212 if (FCPARAM(isp)->isp_2klogin) {
1213 iid = ((at2e_entry_t *)aep)->at_iid;
1219 * The firmware status (except for the QLTM_SVALID bit) indicates
1220 * why this ATIO was sent to us.
1222 * If QLTM_SVALID is set, the firware has recommended Sense Data.
1224 * If the DISCONNECTS DISABLED bit is set in the flags field,
1225 * we're still connected on the SCSI bus - i.e. the initiator
1226 * did not set DiscPriv in the identify message. We don't care
1227 * about this so it's ignored.
1230 switch(aep->at_status & ~QLTM_SVALID) {
1231 case AT_PATH_INVALID:
1233 * ATIO rejected by the firmware due to disabled lun.
1235 isp_prt(isp, ISP_LOGERR,
1236 "rejected ATIO2 for disabled lun %d", lun);
1240 * Requested Capability not available
1241 * We sent an ATIO that overflowed the firmware's
1242 * command resource count.
1244 isp_prt(isp, ISP_LOGERR,
1245 "rejected ATIO2 for lun %d- command count overflow", lun);
1250 * If we send an ATIO to the firmware to increment
1251 * its command resource count, and the firmware is
1252 * recovering from a Bus Device Reset, it returns
1253 * the ATIO with this status. We set the command
1254 * resource count in the Enable Lun entry and no
1255 * not increment it. Therefore we should never get
1258 isp_prt(isp, ISP_LOGERR, atiocope, lun, 0);
1261 case AT_CDB: /* Got a CDB */
1263 * Punt to platform specific layer.
1265 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
1270 * A bus reset came along an blew away this command. Why
1271 * they do this in addition the async event code stuff,
1274 * Ignore it because the async event will clear things
1277 isp_prt(isp, ISP_LOGERR, atior, lun, iid, 0);
1282 isp_prt(isp, ISP_LOGERR,
1283 "Unknown ATIO2 status 0x%x from loopid %d for lun %d",
1284 aep->at_status, iid, lun);
1285 (void) isp_target_put_atio(isp, aep);
1291 isp_handle_ctio(ispsoftc_t *isp, ct_entry_t *ct)
1294 int pl = ISP_LOGTDEBUG2;
1297 if (ct->ct_syshandle) {
1298 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1306 switch(ct->ct_status & ~QLTM_SVALID) {
1309 * There are generally 3 possibilities as to why we'd get
1311 * We disconnected after receiving a CDB.
1312 * We sent or received data.
1313 * We sent status & command complete.
1316 if (ct->ct_flags & CT_SENDSTATUS) {
1318 } else if ((ct->ct_flags & CT_DATAMASK) == CT_NO_DATA) {
1320 * Nothing to do in this case.
1322 isp_prt(isp, pl, "CTIO- iid %d disconnected OK",
1330 * Bus Device Reset message received or the SCSI Bus has
1331 * been Reset; the firmware has gone to Bus Free.
1333 * The firmware generates an async mailbox interupt to
1334 * notify us of this and returns outstanding CTIOs with this
1335 * status. These CTIOs are handled in that same way as
1336 * CT_ABORTED ones, so just fall through here.
1338 fmsg = "Bus Device Reset";
1346 * When an Abort message is received the firmware goes to
1347 * Bus Free and returns all outstanding CTIOs with the status
1348 * set, then sends us an Immediate Notify entry.
1351 fmsg = "ABORT TAG message sent by Initiator";
1353 isp_prt(isp, ISP_LOGTDEBUG0, "CTIO destroyed by %s", fmsg);
1358 * CTIO rejected by the firmware due to disabled lun.
1361 isp_prt(isp, ISP_LOGERR,
1362 "Firmware rejected CTIO for disabled lun %d",
1368 * CTIO rejected by the firmware due "no path for the
1369 * nondisconnecting nexus specified". This means that
1370 * we tried to access the bus while a non-disconnecting
1371 * command is in process.
1373 isp_prt(isp, ISP_LOGERR,
1374 "Firmware rejected CTIO for bad nexus %d/%d/%d",
1375 ct->ct_iid, ct->ct_tgt, ct->ct_lun);
1379 fmsg = "Reselection";
1384 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
1389 fmsg = "Unrecoverable Error";
1393 fmsg = "Completed with Error";
1395 case CT_PHASE_ERROR:
1397 fmsg = "Phase Sequence Error";
1401 fmsg = "terminated by TERMINATE TRANSFER";
1405 fmsg = "unacknowledged Immediate Notify pending";
1406 isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg);
1409 isp_prt(isp, ISP_LOGERR, "Unknown CTIO status 0x%x",
1410 ct->ct_status & ~QLTM_SVALID);
1416 * There may be more than one CTIO for a data transfer,
1417 * or this may be a status CTIO we're not monitoring.
1419 * The assumption is that they'll all be returned in the
1420 * order we got them.
1422 if (ct->ct_syshandle == 0) {
1423 if ((ct->ct_flags & CT_SENDSTATUS) == 0) {
1425 "intermediate CTIO completed ok");
1428 "unmonitored CTIO completed ok");
1432 "NO xs for CTIO (handle 0x%x) status 0x%x",
1433 ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1437 * Final CTIO completed. Release DMA resources and
1438 * notify platform dependent layers.
1440 if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) {
1441 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1443 isp_prt(isp, pl, "final CTIO complete");
1445 * The platform layer will destroy the handle if appropriate.
1447 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1452 isp_handle_ctio2(ispsoftc_t *isp, ct2_entry_t *ct)
1455 int pl = ISP_LOGTDEBUG2;
1458 if (ct->ct_syshandle) {
1459 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1467 switch(ct->ct_status & ~QLTM_SVALID) {
1469 isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error");
1475 * There are generally 2 possibilities as to why we'd get
1477 * We sent or received data.
1478 * We sent status & command complete.
1485 * Target Reset function received.
1487 * The firmware generates an async mailbox interupt to
1488 * notify us of this and returns outstanding CTIOs with this
1489 * status. These CTIOs are handled in that same way as
1490 * CT_ABORTED ones, so just fall through here.
1492 fmsg = "TARGET RESET";
1500 * When an Abort message is received the firmware goes to
1501 * Bus Free and returns all outstanding CTIOs with the status
1502 * set, then sends us an Immediate Notify entry.
1508 isp_prt(isp, ISP_LOGTDEBUG0,
1509 "CTIO2 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid);
1514 * CTIO rejected by the firmware - invalid data direction.
1516 isp_prt(isp, ISP_LOGERR, "CTIO2 had wrong data direction");
1520 fmsg = "failure to reconnect to initiator";
1525 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
1529 fmsg = "Completed with Error";
1533 fmsg = "Port Logout";
1535 case CT_PORTUNAVAIL:
1537 fmsg = "Port not available";
1539 case CT_PORTCHANGED:
1541 fmsg = "Port Changed";
1545 fmsg = "unacknowledged Immediate Notify pending";
1546 isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg);
1551 * CTIO rejected by the firmware because an invalid RX_ID.
1552 * Just print a message.
1554 isp_prt(isp, ISP_LOGWARN,
1555 "CTIO2 completed with Invalid RX_ID 0x%x", ct->ct_rxid);
1559 isp_prt(isp, ISP_LOGERR, "Unknown CTIO2 status 0x%x",
1560 ct->ct_status & ~QLTM_SVALID);
1566 * There may be more than one CTIO for a data transfer,
1567 * or this may be a status CTIO we're not monitoring.
1569 * The assumption is that they'll all be returned in the
1570 * order we got them.
1572 if (ct->ct_syshandle == 0) {
1573 if ((ct->ct_flags & CT2_SENDSTATUS) == 0) {
1575 "intermediate CTIO completed ok");
1578 "unmonitored CTIO completed ok");
1582 "NO xs for CTIO (handle 0x%x) status 0x%x",
1583 ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1586 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
1587 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1589 if (ct->ct_flags & CT2_SENDSTATUS) {
1591 * Sent status and command complete.
1593 * We're now really done with this command, so we
1594 * punt to the platform dependent layers because
1595 * only there can we do the appropriate command
1596 * complete thread synchronization.
1598 isp_prt(isp, pl, "status CTIO complete");
1601 * Final CTIO completed. Release DMA resources and
1602 * notify platform dependent layers.
1604 isp_prt(isp, pl, "data CTIO complete");
1606 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1608 * The platform layer will destroy the handle if appropriate.
1614 isp_handle_ctio7(ispsoftc_t *isp, ct7_entry_t *ct)
1617 int pl = ISP_LOGTDEBUG2;
1620 if (ct->ct_syshandle) {
1621 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1629 switch(ct->ct_nphdl) {
1631 isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error");
1634 case CT7_DATA_UNDER:
1637 * There are generally 2 possibilities as to why we'd get
1639 * We sent or received data.
1640 * We sent status & command complete.
1652 * When an Abort message is received the firmware goes to
1653 * Bus Free and returns all outstanding CTIOs with the status
1654 * set, then sends us an Immediate Notify entry.
1659 isp_prt(isp, ISP_LOGTDEBUG0,
1660 "CTIO7 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid);
1667 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
1671 fmsg = "Completed with Error";
1675 fmsg = "Port Logout";
1678 case CT7_PORTUNAVAIL:
1680 fmsg = "Port not available";
1683 case CT7_PORTCHANGED:
1685 fmsg = "Port Changed";
1687 isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg);
1692 * CTIO rejected by the firmware because an invalid RX_ID.
1693 * Just print a message.
1695 isp_prt(isp, ISP_LOGWARN,
1696 "CTIO7 completed with Invalid RX_ID 0x%x", ct->ct_rxid);
1699 case CT7_REASSY_ERR:
1700 isp_prt(isp, ISP_LOGWARN, "reassembly error");
1704 isp_prt(isp, ISP_LOGWARN, "SRR received");
1708 isp_prt(isp, ISP_LOGERR, "Unknown CTIO7 status 0x%x",
1715 * There may be more than one CTIO for a data transfer,
1716 * or this may be a status CTIO we're not monitoring.
1718 * The assumption is that they'll all be returned in the
1719 * order we got them.
1721 if (ct->ct_syshandle == 0) {
1722 if (ct->ct_flags & CT7_TERMINATE) {
1723 isp_prt(isp, ISP_LOGINFO,
1724 "termination of 0x%x complete",
1726 } else if ((ct->ct_flags & CT7_SENDSTATUS) == 0) {
1728 "intermediate CTIO completed ok");
1731 "unmonitored CTIO completed ok");
1735 "NO xs for CTIO (handle 0x%x) status 0x%x",
1736 ct->ct_syshandle, ct->ct_nphdl);
1739 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
1740 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1742 if (ct->ct_flags & CT2_SENDSTATUS) {
1744 * Sent status and command complete.
1746 * We're now really done with this command, so we
1747 * punt to the platform dependent layers because
1748 * only there can we do the appropriate command
1749 * complete thread synchronization.
1751 isp_prt(isp, pl, "status CTIO complete");
1754 * Final CTIO completed. Release DMA resources and
1755 * notify platform dependent layers.
1757 isp_prt(isp, pl, "data CTIO complete");
1759 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1761 * The platform layer will destroy the handle if appropriate.