2 * Copyright (c) 1997-2007 by Matthew Jacob
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * Machine and OS Independent Target Mode Code for the Qlogic SCSI/FC adapters.
31 * Bug fixes gratefully acknowledged from:
32 * Oded Kedem <oded@kashya.com>
35 * Include header file appropriate for platform we're building on.
39 #include <dev/ic/isp_netbsd.h>
42 #include <sys/cdefs.h>
43 __FBSDID("$FreeBSD$");
44 #include <dev/isp/isp_freebsd.h>
47 #include <dev/ic/isp_openbsd.h>
50 #include "isp_linux.h"
53 #ifdef ISP_TARGET_MODE
54 static const char atiocope[] =
55 "ATIO returned for lun %d because it was in the middle of Bus Device Reset "
57 static const char atior[] =
58 "ATIO returned on for lun %d on from loopid %d because a Bus Reset "
61 static void isp_got_msg(ispsoftc_t *, in_entry_t *);
62 static void isp_got_msg_fc(ispsoftc_t *, in_fcentry_t *);
63 static void isp_got_tmf_24xx(ispsoftc_t *, at7_entry_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 *);
68 static void isp_handle_ctio7(ispsoftc_t *, ct7_entry_t *);
71 * The Qlogic driver gets an interrupt to look at response queue entries.
72 * Some of these are status completions for initiatior mode commands, but
73 * if target mode is enabled, we get a whole wad of response queue entries
76 * Basically the split into 3 main groups: Lun Enable/Modification responses,
77 * SCSI Command processing, and Immediate Notification events.
79 * You start by writing a request queue entry to enable target mode (and
80 * establish some resource limitations which you can modify later).
81 * The f/w responds with a LUN ENABLE or LUN MODIFY response with
82 * the status of this action. If the enable was successful, you can expect...
84 * Response queue entries with SCSI commands encapsulate show up in an ATIO
85 * (Accept Target IO) type- sometimes with enough info to stop the command at
86 * this level. Ultimately the driver has to feed back to the f/w's request
87 * queue a sequence of CTIOs (continue target I/O) that describe data to
88 * be moved and/or status to be sent) and finally finishing with sending
89 * to the f/w's response queue an ATIO which then completes the handshake
90 * with the f/w for that command. There's a lot of variations on this theme,
91 * including flags you can set in the CTIO for the Qlogic 2X00 fibre channel
92 * cards that 'auto-replenish' the f/w's ATIO count, but this is the basic
95 * The third group that can show up in the response queue are Immediate
96 * Notification events. These include things like notifications of SCSI bus
97 * resets, or Bus Device Reset messages or other messages received. This
98 * a classic oddbins area. It can get a little weird because you then turn
99 * around and acknowledge the Immediate Notify by writing an entry onto the
100 * request queue and then the f/w turns around and gives you an acknowledgement
101 * to *your* acknowledgement on the response queue (the idea being to let
102 * the f/w tell you when the event is *really* over I guess).
108 * A new response queue entry has arrived. The interrupt service code
109 * has already swizzled it into the platform dependent from canonical form.
111 * Because of the way this driver is designed, unfortunately most of the
112 * actual synchronization work has to be done in the platform specific
113 * code- we have no synchroniation primitives in the common code.
117 isp_target_notify(ispsoftc_t *isp, void *vptr, uint32_t *optrp)
124 at2e_entry_t *at2eiop;
128 ct2e_entry_t *ct2eiop;
132 in_fcentry_t *inot_fcp;
133 in_fcentry_e_t *inote_fcp;
134 in_fcentry_24xx_t *inot_24xx;
136 na_fcentry_t *nack_fcp;
137 na_fcentry_e_t *nacke_fcp;
138 na_fcentry_24xx_t *nack_24xx;
141 abts_rsp_t *abts_rsp;
144 #define atiop unp.atiop
145 #define at2iop unp.at2iop
146 #define at2eiop unp.at2eiop
147 #define at7iop unp.at7iop
148 #define ctiop unp.ctiop
149 #define ct2iop unp.ct2iop
150 #define ct2eiop unp.ct2eiop
151 #define ct7iop unp.ct7iop
152 #define lunenp unp.lunenp
153 #define inotp unp.inotp
154 #define inot_fcp unp.inot_fcp
155 #define inote_fcp unp.inote_fcp
156 #define inot_24xx unp.inot_24xx
157 #define nackp unp.nackp
158 #define nack_fcp unp.nack_fcp
159 #define nacke_fcp unp.nacke_fcp
160 #define nack_24xx unp.nack_24xx
161 #define abts unp.abts
162 #define abts_rsp unp.abts_rsp
166 uint8_t local[QENTRY_LEN];
167 int bus, type, level, rval = 1;
169 type = isp_get_response_type(isp, (isphdr_t *)vptr);
172 ISP_TDQE(isp, "isp_target_notify", (int) *optrp, vptr);
179 isp_get_atio7(isp, at7iop, (at7_entry_t *) local);
180 at7iop = (at7_entry_t *) local;
182 * Check for and do something with commands whose IULEN
183 * extends past a singel queue entry.
185 len = at7iop->at_ta_len & 0xfffff;
186 if (len > (QENTRY_LEN - 8)) {
187 len -= (QENTRY_LEN - 8);
188 isp_prt(isp, ISP_LOGINFO,
189 "long IU length (%d) ignored", len);
191 *optrp = ISP_NXT_QENTRY(*optrp,
192 RESULT_QUEUE_LEN(isp));
197 * Check for a task management function
199 if (at7iop->at_cmnd.fcp_cmnd_task_management) {
200 isp_got_tmf_24xx(isp, at7iop);
204 * Just go straight to outer layer for this one.
206 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, local);
208 isp_get_atio(isp, atiop, (at_entry_t *) local);
209 isp_handle_atio(isp, (at_entry_t *) local);
214 isp_get_ctio(isp, ctiop, (ct_entry_t *) local);
215 isp_handle_ctio(isp, (ct_entry_t *) local);
219 if (FCPARAM(isp)->isp_2klogin) {
220 isp_get_atio2e(isp, at2eiop, (at2e_entry_t *) local);
222 isp_get_atio2(isp, at2iop, (at2_entry_t *) local);
224 isp_handle_atio2(isp, (at2_entry_t *) local);
229 if (FCPARAM(isp)->isp_2klogin) {
230 isp_get_ctio2e(isp, ct2eiop, (ct2e_entry_t *) local);
232 isp_get_ctio2(isp, ct2iop, (ct2_entry_t *) local);
234 isp_handle_ctio2(isp, (ct2_entry_t *) local);
238 isp_get_ctio7(isp, ct7iop, (ct7_entry_t *) local);
239 isp_handle_ctio7(isp, (ct7_entry_t *) local);
242 case RQSTYPE_ENABLE_LUN:
243 case RQSTYPE_MODIFY_LUN:
244 isp_get_enable_lun(isp, lunenp, (lun_entry_t *) local);
245 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, local);
250 * Either the ISP received a SCSI message it can't
251 * handle, or it's returning an Immed. Notify entry
252 * we sent. We can send Immed. Notify entries to
253 * increment the firmware's resource count for them
254 * (we set this initially in the Enable Lun entry).
258 isp_get_notify_24xx(isp, inot_24xx,
259 (in_fcentry_24xx_t *)local);
260 inot_24xx = (in_fcentry_24xx_t *) local;
261 status = inot_24xx->in_status;
262 seqid = inot_24xx->in_rxid;
263 isp_prt(isp, ISP_LOGTDEBUG0,
264 "Immediate Notify status=0x%x seqid=0x%x",
267 case IN24XX_LIP_RESET:
268 case IN24XX_LINK_RESET:
269 case IN24XX_PORT_LOGOUT:
270 case IN24XX_PORT_CHANGED:
271 case IN24XX_LINK_FAILED:
272 case IN24XX_SRR_RCVD:
273 case IN24XX_ELS_RCVD:
274 (void) isp_async(isp, ISPASYNC_TARGET_ACTION,
278 isp_prt(isp, ISP_LOGINFO,
279 "isp_target_notify: unknown status (0x%x)",
281 isp_notify_ack(isp, local);
285 } else if (IS_FC(isp)) {
286 if (FCPARAM(isp)->isp_2klogin) {
287 isp_get_notify_fc_e(isp, inote_fcp,
288 (in_fcentry_e_t *)local);
290 isp_get_notify_fc(isp, inot_fcp,
291 (in_fcentry_t *)local);
293 inot_fcp = (in_fcentry_t *) local;
294 status = inot_fcp->in_status;
295 seqid = inot_fcp->in_seqid;
297 isp_get_notify(isp, inotp, (in_entry_t *)local);
298 inotp = (in_entry_t *) local;
299 status = inotp->in_status & 0xff;
300 seqid = inotp->in_seqid;
301 if (IS_DUALBUS(isp)) {
302 bus = GET_BUS_VAL(inotp->in_iid);
303 SET_BUS_VAL(inotp->in_iid, 0);
307 isp_prt(isp, ISP_LOGTDEBUG0,
308 "Immediate Notify On Bus %d, status=0x%x seqid=0x%x",
312 case IN_MSG_RECEIVED:
313 case IN_IDE_RECEIVED:
315 isp_got_msg_fc(isp, (in_fcentry_t *)local);
317 isp_got_msg(isp, (in_entry_t *)local);
320 case IN_RSRC_UNAVAIL:
321 isp_prt(isp, ISP_LOGINFO, "Firmware out of ATIOs");
322 isp_notify_ack(isp, local);
327 * We form the notify structure here because we need
328 * to mark it as needing a NOTIFY ACK on return.
332 MEMZERO(¬ify, sizeof (tmd_notify_t));
334 notify.nt_iid = INI_ANY;
335 /* nt_tgt set in outer layers */
336 notify.nt_lun = LUN_ANY;
337 notify.nt_tagval = TAG_ANY;
338 notify.nt_ncode = NT_BUS_RESET;
339 notify.nt_need_ack = 1;
340 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
345 case IN_PORT_CHANGED:
347 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, &local);
350 isp_prt(isp, ISP_LOGINFO,
351 "isp_target_notify: unknown status (0x%x)",
353 isp_notify_ack(isp, local);
358 case RQSTYPE_NOTIFY_ACK:
360 * The ISP is acknowledging our acknowledgement of an
361 * Immediate Notify entry for some asynchronous event.
364 isp_get_notify_ack_24xx(isp, nack_24xx,
365 (na_fcentry_24xx_t *) local);
366 nack_24xx = (na_fcentry_24xx_t *) local;
367 if (nack_24xx->na_status != NA_OK) {
370 level = ISP_LOGTDEBUG1;
373 "Notify Ack Status=0x%x; Subcode 0x%x seqid=0x%x",
374 nack_24xx->na_status, nack_24xx->na_status_subcode,
376 } else if (IS_FC(isp)) {
377 if (FCPARAM(isp)->isp_2klogin) {
378 isp_get_notify_ack_fc_e(isp, nacke_fcp,
379 (na_fcentry_e_t *)local);
381 isp_get_notify_ack_fc(isp, nack_fcp,
382 (na_fcentry_t *)local);
384 nack_fcp = (na_fcentry_t *)local;
385 if (nack_fcp->na_status != NA_OK) {
388 level = ISP_LOGTDEBUG1;
391 "Notify Ack Status=0x%x seqid 0x%x",
392 nack_fcp->na_status, nack_fcp->na_seqid);
394 isp_get_notify_ack(isp, nackp, (na_entry_t *)local);
395 nackp = (na_entry_t *)local;
396 if (nackp->na_status != NA_OK) {
399 level = ISP_LOGTDEBUG1;
402 "Notify Ack event 0x%x status=0x%x seqid 0x%x",
403 nackp->na_event, nackp->na_status, nackp->na_seqid);
407 case RQSTYPE_ABTS_RCVD:
408 isp_get_abts(isp, abts, (abts_t *)local);
409 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, &local);
411 case RQSTYPE_ABTS_RSP:
412 isp_get_abts_rsp(isp, abts_rsp, (abts_rsp_t *)local);
413 abts_rsp = (abts_rsp_t *) local;
414 if (abts_rsp->abts_rsp_status) {
417 level = ISP_LOGTDEBUG0;
420 "ABTS RSP response[0x%x]: status=0x%x sub=(0x%x 0x%x)",
421 abts_rsp->abts_rsp_rxid_task, abts_rsp->abts_rsp_status,
422 abts_rsp->abts_rsp_payload.rsp.subcode1,
423 abts_rsp->abts_rsp_payload.rsp.subcode2);
426 isp_prt(isp, ISP_LOGERR,
427 "Unknown entry type 0x%x in isp_target_notify", type);
457 * Toggle (on/off) target mode for bus/target/lun
459 * The caller has checked for overlap and legality.
461 * Note that not all of bus, target or lun can be paid attention to.
462 * Note also that this action will not be complete until the f/w writes
463 * response entry. The caller is responsible for synchronizing this.
466 isp_lun_cmd(ispsoftc_t *isp, int cmd, int bus, int tgt, int lun,
467 int cmd_cnt, int inot_cnt, uint32_t opaque)
474 MEMZERO(&el, sizeof (el));
475 if (IS_DUALBUS(isp)) {
476 el.le_rsvd = (bus & 0x1) << 7;
478 el.le_cmd_count = cmd_cnt;
479 el.le_in_count = inot_cnt;
480 if (cmd == RQSTYPE_ENABLE_LUN) {
482 el.le_flags = LUN_TQAE|LUN_DISAD;
486 } else if (cmd == -RQSTYPE_ENABLE_LUN) {
487 cmd = RQSTYPE_ENABLE_LUN;
490 } else if (cmd == -RQSTYPE_MODIFY_LUN) {
491 cmd = RQSTYPE_MODIFY_LUN;
492 el.le_ops = LUN_CCDECR | LUN_INDECR;
494 el.le_ops = LUN_CCINCR | LUN_ININCR;
496 el.le_header.rqs_entry_type = cmd;
497 el.le_header.rqs_entry_count = 1;
498 el.le_reserved = opaque;
502 } else if (FCPARAM(isp)->isp_sccfw == 0) {
507 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
508 isp_prt(isp, ISP_LOGERR,
509 "Request Queue Overflow in isp_lun_cmd");
512 ISP_TDQE(isp, "isp_lun_cmd", (int) optr, &el);
513 isp_put_enable_lun(isp, &el, outp);
514 ISP_ADD_REQUEST(isp, nxti);
520 isp_target_put_entry(ispsoftc_t *isp, void *ap)
524 uint8_t etype = ((isphdr_t *) ap)->rqs_entry_type;
526 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
527 isp_prt(isp, ISP_LOGWARN,
528 "Request Queue Overflow in isp_target_put_entry");
533 isp_put_atio(isp, (at_entry_t *) ap, (at_entry_t *) outp);
536 if (FCPARAM(isp)->isp_2klogin) {
537 isp_put_atio2e(isp, (at2e_entry_t *) ap,
538 (at2e_entry_t *) outp);
540 isp_put_atio2(isp, (at2_entry_t *) ap,
541 (at2_entry_t *) outp);
545 isp_put_ctio(isp, (ct_entry_t *) ap, (ct_entry_t *) outp);
548 if (FCPARAM(isp)->isp_2klogin) {
549 isp_put_ctio2e(isp, (ct2e_entry_t *) ap,
550 (ct2e_entry_t *) outp);
552 isp_put_ctio2(isp, (ct2_entry_t *) ap,
553 (ct2_entry_t *) outp);
557 isp_put_ctio7(isp, (ct7_entry_t *) ap, (ct7_entry_t *) outp);
560 isp_prt(isp, ISP_LOGERR,
561 "Unknown type 0x%x in isp_put_entry", etype);
564 ISP_TDQE(isp, "isp_target_put_entry", (int) optr, ap);
565 ISP_ADD_REQUEST(isp, nxti);
570 isp_target_put_atio(ispsoftc_t *isp, void *arg)
575 at2e_entry_t _atio2e;
578 MEMZERO(&atun, sizeof atun);
580 at2_entry_t *aep = arg;
581 atun._atio2.at_header.rqs_entry_type = RQSTYPE_ATIO2;
582 atun._atio2.at_header.rqs_entry_count = 1;
583 if (FCPARAM(isp)->isp_sccfw) {
584 atun._atio2.at_scclun = aep->at_scclun;
586 atun._atio2.at_lun = (uint8_t) aep->at_lun;
588 if (FCPARAM(isp)->isp_2klogin) {
589 atun._atio2e.at_iid = ((at2e_entry_t *)aep)->at_iid;
591 atun._atio2.at_iid = aep->at_iid;
593 atun._atio2.at_rxid = aep->at_rxid;
594 atun._atio2.at_status = CT_OK;
596 at_entry_t *aep = arg;
597 atun._atio.at_header.rqs_entry_type = RQSTYPE_ATIO;
598 atun._atio.at_header.rqs_entry_count = 1;
599 atun._atio.at_handle = aep->at_handle;
600 atun._atio.at_iid = aep->at_iid;
601 atun._atio.at_tgt = aep->at_tgt;
602 atun._atio.at_lun = aep->at_lun;
603 atun._atio.at_tag_type = aep->at_tag_type;
604 atun._atio.at_tag_val = aep->at_tag_val;
605 atun._atio.at_status = (aep->at_flags & AT_TQAE);
606 atun._atio.at_status |= CT_OK;
608 return (isp_target_put_entry(isp, &atun));
612 * Command completion- both for handling cases of no resources or
613 * no blackhole driver, or other cases where we have to, inline,
614 * finish the command sanely, or for normal command completion.
616 * The 'completion' code value has the scsi status byte in the low 8 bits.
617 * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have
618 * the sense key and bits 16..23 have the ASCQ and bits 24..31 have the ASC
621 * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't
622 * NB: inline SCSI sense reporting. As such, we lose this information. XXX.
624 * For both parallel && fibre channel, we use the feature that does
625 * an automatic resource autoreplenish so we don't have then later do
626 * put of an atio to replenish the f/w's resource count.
630 isp_endcmd(ispsoftc_t *isp, void *arg, uint32_t code, uint32_t hdl)
636 ct2e_entry_t _ctio2e;
640 MEMZERO(&un, sizeof un);
644 at7_entry_t *aep = arg;
645 ct7_entry_t *cto = &un._ctio7;
647 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
648 cto->ct_header.rqs_entry_count = 1;
649 /* XXXX */ cto->ct_nphdl = aep->at_hdr.seq_id;
650 cto->ct_rxid = aep->at_rxid;
651 cto->ct_iid_lo = (aep->at_hdr.s_id[1] << 8) |
653 cto->ct_iid_hi = aep->at_hdr.s_id[0];
654 cto->ct_oxid = aep->at_hdr.ox_id;
655 cto->ct_scsi_status = sts;
656 cto->ct_flags = CT7_FLAG_MODE1 | CT7_NO_DATA | CT7_SENDSTATUS;
657 if (sts == SCSI_CHECK && (code & ECMD_SVALID)) {
658 cto->rsp.m1.ct_resplen = 16;
659 cto->rsp.m1.ct_resp[0] = 0xf0;
660 cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
661 cto->rsp.m1.ct_resp[7] = 8;
662 cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff;
663 cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff;
665 if (aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl) {
666 cto->ct_resid = aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl;
667 cto->ct_scsi_status |= CT2_DATA_UNDER;
669 cto->ct_syshandle = hdl;
670 } else if (IS_FC(isp)) {
671 at2_entry_t *aep = arg;
672 ct2_entry_t *cto = &un._ctio2;
674 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
675 cto->ct_header.rqs_entry_count = 1;
676 if (FCPARAM(isp)->isp_sccfw == 0) {
677 cto->ct_lun = aep->at_lun;
679 if (FCPARAM(isp)->isp_2klogin) {
680 un._ctio2e.ct_iid = ((at2e_entry_t *)aep)->at_iid;
682 cto->ct_iid = aep->at_iid;
684 cto->ct_rxid = aep->at_rxid;
685 cto->rsp.m1.ct_scsi_status = sts;
686 cto->ct_flags = CT2_SENDSTATUS | CT2_NO_DATA | CT2_FLAG_MODE1;
688 cto->ct_flags |= CT2_CCINCR;
690 if (aep->at_datalen) {
691 cto->ct_resid = aep->at_datalen;
692 cto->rsp.m1.ct_scsi_status |= CT2_DATA_UNDER;
694 if (sts == SCSI_CHECK && (code & ECMD_SVALID)) {
695 cto->rsp.m1.ct_resp[0] = 0xf0;
696 cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
697 cto->rsp.m1.ct_resp[7] = 8;
698 cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff;
699 cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff;
700 cto->rsp.m1.ct_senselen = 16;
701 cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID;
703 cto->ct_syshandle = hdl;
705 at_entry_t *aep = arg;
706 ct_entry_t *cto = &un._ctio;
708 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
709 cto->ct_header.rqs_entry_count = 1;
710 cto->ct_fwhandle = aep->at_handle;
711 cto->ct_iid = aep->at_iid;
712 cto->ct_tgt = aep->at_tgt;
713 cto->ct_lun = aep->at_lun;
714 cto->ct_tag_type = aep->at_tag_type;
715 cto->ct_tag_val = aep->at_tag_val;
716 if (aep->at_flags & AT_TQAE) {
717 cto->ct_flags |= CT_TQAE;
719 cto->ct_flags = CT_SENDSTATUS | CT_NO_DATA;
721 cto->ct_flags |= CT_CCINCR;
723 cto->ct_scsi_status = sts;
724 cto->ct_syshandle = hdl;
726 return (isp_target_put_entry(isp, &un));
730 * These are either broadcast events or specifically CTIO fast completion
733 isp_target_async(ispsoftc_t *isp, int bus, int event)
737 MEMZERO(¬ify, sizeof (tmd_notify_t));
739 notify.nt_iid = INI_ANY;
740 /* nt_tgt set in outer layers */
741 notify.nt_lun = LUN_ANY;
742 notify.nt_tagval = TAG_ANY;
745 TAG_INSERT_BUS(notify.nt_tagval, bus);
751 notify.nt_ncode = NT_LINK_UP;
752 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
754 case ASYNC_LOOP_DOWN:
755 notify.nt_ncode = NT_LINK_DOWN;
756 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
758 case ASYNC_LIP_ERROR:
760 case ASYNC_LIP_OCCURRED:
761 case ASYNC_LOOP_RESET:
762 notify.nt_ncode = NT_LIP_RESET;
763 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
765 case ASYNC_BUS_RESET:
766 case ASYNC_TIMEOUT_RESET: /* XXX: where does this come from ? */
767 notify.nt_ncode = NT_BUS_RESET;
768 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
770 case ASYNC_DEVICE_RESET:
771 notify.nt_ncode = NT_TARGET_RESET;
772 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
774 case ASYNC_CTIO_DONE:
776 uint8_t storage[QENTRY_LEN];
777 memset(storage, 0, QENTRY_LEN);
779 ct7_entry_t *ct = (ct7_entry_t *) storage;
780 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
781 ct->ct_nphdl = CT7_OK;
782 ct->ct_syshandle = bus;
783 ct->ct_flags = CT7_SENDSTATUS|CT7_FASTPOST;
784 } else if (IS_FC(isp)) {
785 /* This should also suffice for 2K login code */
786 ct2_entry_t *ct = (ct2_entry_t *) storage;
787 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
788 ct->ct_status = CT_OK;
789 ct->ct_syshandle = bus;
790 ct->ct_flags = CT2_SENDSTATUS|CT2_FASTPOST;
792 ct_entry_t *ct = (ct_entry_t *) storage;
793 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO;
794 ct->ct_status = CT_OK;
795 ct->ct_fwhandle = bus;
796 ct->ct_flags = CT_SENDSTATUS;
798 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, storage);
802 isp_prt(isp, ISP_LOGERR,
803 "isp_target_async: unknown event 0x%x", event);
804 if (isp->isp_state == ISP_RUNSTATE) {
805 isp_notify_ack(isp, NULL);
814 * Process a received message.
815 * The ISP firmware can handle most messages, there are only
816 * a few that we need to deal with:
817 * - abort: clean up the current command
818 * - abort tag and clear queue
822 isp_got_msg(ispsoftc_t *isp, in_entry_t *inp)
825 uint8_t status = inp->in_status & ~QLTM_SVALID;
827 MEMZERO(&nt, sizeof (nt));
829 nt.nt_iid = GET_IID_VAL(inp->in_iid);
830 nt.nt_tgt = inp->in_tgt;
831 nt.nt_lun = inp->in_lun;
832 IN_MAKE_TAGID(nt.nt_tagval, GET_BUS_VAL(inp->in_iid), 0, inp);
833 nt.nt_lreserved = inp;
835 if (status == IN_IDE_RECEIVED || status == IN_MSG_RECEIVED) {
836 switch (inp->in_msg[0]) {
838 nt.nt_ncode = NT_ABORT_TASK_SET;
840 case MSG_BUS_DEV_RESET:
841 nt.nt_ncode = NT_TARGET_RESET;
844 nt.nt_ncode = NT_ABORT_TASK;
846 case MSG_CLEAR_QUEUE:
847 nt.nt_ncode = NT_CLEAR_TASK_SET;
849 case MSG_REL_RECOVERY:
850 nt.nt_ncode = NT_CLEAR_ACA;
852 case MSG_TERM_IO_PROC:
853 nt.nt_ncode = NT_ABORT_TASK;
856 nt.nt_ncode = NT_LUN_RESET;
859 isp_prt(isp, ISP_LOGERR,
860 "unhandled message 0x%x", inp->in_msg[0]);
861 isp_notify_ack(isp, inp);
864 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt);
866 isp_prt(isp, ISP_LOGERR,
867 "unknown immediate notify status 0x%x", inp->in_status);
868 isp_notify_ack(isp, inp);
873 * Synthesize a message from the task management flags in a FCP_CMND_IU.
876 isp_got_msg_fc(ispsoftc_t *isp, in_fcentry_t *inp)
879 static const char f1[] = "%s from N-port handle 0x%x lun %d seq 0x%x";
880 static const char f2[] = "unknown %s 0x%x lun %d N-Port handle 0x%x "
881 "task flags 0x%x seq 0x%x\n";
882 uint16_t seqid, loopid;
884 MEMZERO(&nt, sizeof (tmd_notify_t));
886 if (FCPARAM(isp)->isp_2klogin) {
887 nt.nt_iid = ((in_fcentry_e_t *)inp)->in_iid;
888 loopid = ((in_fcentry_e_t *)inp)->in_iid;
889 seqid = ((in_fcentry_e_t *)inp)->in_seqid;
891 nt.nt_iid = inp->in_iid;
892 loopid = inp->in_iid;
893 seqid = inp->in_seqid;
895 /* nt_tgt set in outer layers */
896 if (FCPARAM(isp)->isp_sccfw) {
897 nt.nt_lun = inp->in_scclun;
899 nt.nt_lun = inp->in_lun;
901 IN_FC_MAKE_TAGID(nt.nt_tagval, 0, 0, seqid);
903 nt.nt_lreserved = inp;
905 if (inp->in_status != IN_MSG_RECEIVED) {
906 isp_prt(isp, ISP_LOGINFO, f2, "immediate notify status",
907 inp->in_status, nt.nt_lun, loopid, inp->in_task_flags,
909 isp_notify_ack(isp, inp);
913 if (inp->in_task_flags & TASK_FLAGS_ABORT_TASK_SET) {
914 isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET",
915 loopid, nt.nt_lun, inp->in_seqid);
916 nt.nt_ncode = NT_ABORT_TASK_SET;
917 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_TASK_SET) {
918 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET",
919 loopid, nt.nt_lun, inp->in_seqid);
920 nt.nt_ncode = NT_CLEAR_TASK_SET;
921 } else if (inp->in_task_flags & TASK_FLAGS_LUN_RESET) {
922 isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET",
923 loopid, nt.nt_lun, inp->in_seqid);
924 nt.nt_ncode = NT_LUN_RESET;
925 } else if (inp->in_task_flags & TASK_FLAGS_TARGET_RESET) {
926 isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET",
927 loopid, nt.nt_lun, inp->in_seqid);
928 nt.nt_ncode = NT_TARGET_RESET;
929 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_ACA) {
930 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA",
931 loopid, nt.nt_lun, inp->in_seqid);
932 nt.nt_ncode = NT_CLEAR_ACA;
934 isp_prt(isp, ISP_LOGWARN, f2, "task flag", inp->in_status,
935 nt.nt_lun, loopid, inp->in_task_flags, inp->in_seqid);
936 isp_notify_ack(isp, inp);
939 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt);
942 #define HILO(x) (uint32_t) (x >> 32), (uint32_t) x
944 isp_got_tmf_24xx(ispsoftc_t *isp, at7_entry_t *aep)
947 static const char f1[] =
948 "%s from PortID 0x%06x lun %d seq 0x%08x%08x";
949 static const char f2[] =
950 "unknown Task Flag 0x%x lun %d PortID 0x%x tag 0x%08x%08x";
953 MEMZERO(&nt, sizeof (tmd_notify_t));
957 (aep->at_cmnd.fcp_cmnd_lun[0] << 8) |
958 (aep->at_cmnd.fcp_cmnd_lun[1]);
960 * XXX: VPIDX HAS TO BE DERIVED FROM DESTINATION PORT
962 nt.nt_tagval = aep->at_rxid;
963 nt.nt_lreserved = aep;
965 (aep->at_hdr.s_id[0] << 16) |
966 (aep->at_hdr.s_id[1] << 8) |
967 (aep->at_hdr.s_id[2]);
969 if (aep->at_cmnd.fcp_cmnd_task_management &
970 FCP_CMND_TMF_ABORT_TASK_SET) {
971 isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET",
972 sid, nt.nt_lun, HILO(nt.nt_tagval));
973 nt.nt_ncode = NT_ABORT_TASK_SET;
974 } else if (aep->at_cmnd.fcp_cmnd_task_management &
975 FCP_CMND_TMF_CLEAR_TASK_SET) {
976 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET",
977 sid, nt.nt_lun, HILO(nt.nt_tagval));
978 nt.nt_ncode = NT_CLEAR_TASK_SET;
979 } else if (aep->at_cmnd.fcp_cmnd_task_management &
980 FCP_CMND_TMF_LUN_RESET) {
981 isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET",
982 sid, nt.nt_lun, HILO(nt.nt_tagval));
983 nt.nt_ncode = NT_LUN_RESET;
984 } else if (aep->at_cmnd.fcp_cmnd_task_management &
985 FCP_CMND_TMF_TGT_RESET) {
986 isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET",
987 sid, nt.nt_lun, HILO(nt.nt_tagval));
988 nt.nt_ncode = NT_TARGET_RESET;
990 } else if (aep->at_cmnd.fcp_cmnd_task_management &
991 FCP_CMND_TMF_CLEAR_ACA) {
992 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA",
993 sid, nt.nt_lun, HILO(nt.nt_tagval));
994 nt.nt_ncode = NT_CLEAR_ACA;
996 isp_prt(isp, ISP_LOGWARN, f2,
997 aep->at_cmnd.fcp_cmnd_task_management,
998 nt.nt_lun, sid, HILO(nt.nt_tagval));
999 isp_endcmd(isp, aep, 0, 0);
1002 (void) isp_async(isp, ISPASYNC_TARGET_NOTIFY, &nt);
1006 isp_notify_ack(ispsoftc_t *isp, void *arg)
1008 char storage[QENTRY_LEN];
1009 uint32_t nxti, optr;
1012 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
1013 isp_prt(isp, ISP_LOGWARN,
1014 "Request Queue Overflow For isp_notify_ack");
1018 MEMZERO(storage, QENTRY_LEN);
1020 if (IS_24XX(isp) && arg != NULL && (((isphdr_t *)arg)->rqs_entry_type == RQSTYPE_ATIO)) {
1021 at7_entry_t *aep = arg;
1022 isp_endcmd(isp, aep, 0, 0);
1024 } else if (IS_24XX(isp) && arg != NULL && (((isphdr_t *)arg)->rqs_entry_type == RQSTYPE_ABTS_RSP)) {
1025 abts_rsp_t *abts_rsp = (abts_rsp_t *) storage;
1027 * The caller will have set response values as appropriate
1028 * in the ABTS structure just before calling us.
1030 MEMCPY(abts_rsp, arg, QENTRY_LEN);
1031 isp_put_abts_rsp(isp, abts_rsp, (abts_rsp_t *)outp);
1032 } else if (IS_24XX(isp)) {
1033 na_fcentry_24xx_t *na = (na_fcentry_24xx_t *) storage;
1035 in_fcentry_24xx_t *in = arg;
1036 na->na_nphdl = in->in_nphdl;
1037 na->na_status = in->in_status;
1038 na->na_status_subcode = in->in_status_subcode;
1039 na->na_rxid = in->in_rxid;
1040 na->na_oxid = in->in_oxid;
1041 if (in->in_status == IN24XX_SRR_RCVD) {
1042 na->na_srr_rxid = in->in_srr_rxid;
1043 na->na_srr_reloff_hi = in->in_srr_reloff_hi;
1044 na->na_srr_reloff_lo = in->in_srr_reloff_lo;
1045 na->na_srr_iu = in->in_srr_iu;
1046 na->na_srr_flags = 1;
1047 na->na_srr_reject_vunique = 0;
1048 na->na_srr_reject_explanation = 1;
1049 na->na_srr_reject_code = 1;
1052 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
1053 na->na_header.rqs_entry_count = 1;
1054 isp_put_notify_24xx_ack(isp, na, (na_fcentry_24xx_t *)outp);
1055 } else if (IS_FC(isp)) {
1056 na_fcentry_t *na = (na_fcentry_t *) storage;
1060 in_fcentry_t *inp = arg;
1061 MEMCPY(storage, arg, sizeof (isphdr_t));
1062 if (FCPARAM(isp)->isp_2klogin) {
1063 ((na_fcentry_e_t *)na)->na_iid =
1064 ((in_fcentry_e_t *)inp)->in_iid;
1065 iid = ((na_fcentry_e_t *)na)->na_iid;
1067 na->na_iid = inp->in_iid;
1071 inp->in_task_flags & TASK_FLAGS_RESERVED_MASK;
1072 na->na_seqid = inp->in_seqid;
1073 na->na_flags = NAFC_RCOUNT;
1074 na->na_status = inp->in_status;
1075 if (inp->in_status == IN_RESET) {
1076 na->na_flags |= NAFC_RST_CLRD;
1078 if (inp->in_status == IN_MSG_RECEIVED) {
1079 na->na_flags |= NAFC_TVALID;
1080 na->na_response = 0; /* XXX SUCCEEDED XXX */
1083 na->na_flags = NAFC_RST_CLRD;
1085 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
1086 na->na_header.rqs_entry_count = 1;
1087 if (FCPARAM(isp)->isp_2klogin) {
1088 isp_put_notify_ack_fc_e(isp, (na_fcentry_e_t *) na,
1089 (na_fcentry_e_t *)outp);
1091 isp_put_notify_ack_fc(isp, na, (na_fcentry_t *)outp);
1093 isp_prt(isp, ISP_LOGTDEBUG0, "notify ack loopid %u seqid %x "
1094 "flags %x tflags %x response %x", iid, na->na_seqid,
1095 na->na_flags, na->na_task_flags, na->na_response);
1097 na_entry_t *na = (na_entry_t *) storage;
1099 in_entry_t *inp = arg;
1100 MEMCPY(storage, arg, sizeof (isphdr_t));
1101 na->na_iid = inp->in_iid;
1102 na->na_lun = inp->in_lun;
1103 na->na_tgt = inp->in_tgt;
1104 na->na_seqid = inp->in_seqid;
1105 if (inp->in_status == IN_RESET) {
1106 na->na_event = NA_RST_CLRD;
1109 na->na_event = NA_RST_CLRD;
1111 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
1112 na->na_header.rqs_entry_count = 1;
1113 isp_put_notify_ack(isp, na, (na_entry_t *)outp);
1114 isp_prt(isp, ISP_LOGTDEBUG0, "notify ack loopid %u lun %u tgt "
1115 "%u seqid %x event %x", na->na_iid, na->na_lun, na->na_tgt,
1116 na->na_seqid, na->na_event);
1118 ISP_TDQE(isp, "isp_notify_ack", (int) optr, storage);
1119 ISP_ADD_REQUEST(isp, nxti);
1123 isp_handle_atio(ispsoftc_t *isp, at_entry_t *aep)
1128 * The firmware status (except for the QLTM_SVALID bit) indicates
1129 * why this ATIO was sent to us.
1131 * If QLTM_SVALID is set, the firware has recommended Sense Data.
1133 * If the DISCONNECTS DISABLED bit is set in the flags field,
1134 * we're still connected on the SCSI bus - i.e. the initiator
1135 * did not set DiscPriv in the identify message. We don't care
1136 * about this so it's ignored.
1139 switch(aep->at_status & ~QLTM_SVALID) {
1140 case AT_PATH_INVALID:
1142 * ATIO rejected by the firmware due to disabled lun.
1144 isp_prt(isp, ISP_LOGERR,
1145 "rejected ATIO for disabled lun %d", lun);
1149 * Requested Capability not available
1150 * We sent an ATIO that overflowed the firmware's
1151 * command resource count.
1153 isp_prt(isp, ISP_LOGERR,
1154 "rejected ATIO for lun %d because of command count"
1160 * If we send an ATIO to the firmware to increment
1161 * its command resource count, and the firmware is
1162 * recovering from a Bus Device Reset, it returns
1163 * the ATIO with this status. We set the command
1164 * resource count in the Enable Lun entry and do
1165 * not increment it. Therefore we should never get
1168 isp_prt(isp, ISP_LOGERR, atiocope, lun,
1169 GET_BUS_VAL(aep->at_iid));
1172 case AT_CDB: /* Got a CDB */
1173 case AT_PHASE_ERROR: /* Bus Phase Sequence Error */
1175 * Punt to platform specific layer.
1177 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
1182 * A bus reset came along and blew away this command. Why
1183 * they do this in addition the async event code stuff,
1186 * Ignore it because the async event will clear things
1189 isp_prt(isp, ISP_LOGWARN, atior, lun,
1190 GET_IID_VAL(aep->at_iid), GET_BUS_VAL(aep->at_iid));
1195 isp_prt(isp, ISP_LOGERR,
1196 "Unknown ATIO status 0x%x from loopid %d for lun %d",
1197 aep->at_status, aep->at_iid, lun);
1198 (void) isp_target_put_atio(isp, aep);
1204 isp_handle_atio2(ispsoftc_t *isp, at2_entry_t *aep)
1208 if (FCPARAM(isp)->isp_sccfw) {
1209 lun = aep->at_scclun;
1214 if (FCPARAM(isp)->isp_2klogin) {
1215 iid = ((at2e_entry_t *)aep)->at_iid;
1221 * The firmware status (except for the QLTM_SVALID bit) indicates
1222 * why this ATIO was sent to us.
1224 * If QLTM_SVALID is set, the firware has recommended Sense Data.
1226 * If the DISCONNECTS DISABLED bit is set in the flags field,
1227 * we're still connected on the SCSI bus - i.e. the initiator
1228 * did not set DiscPriv in the identify message. We don't care
1229 * about this so it's ignored.
1232 switch(aep->at_status & ~QLTM_SVALID) {
1233 case AT_PATH_INVALID:
1235 * ATIO rejected by the firmware due to disabled lun.
1237 isp_prt(isp, ISP_LOGERR,
1238 "rejected ATIO2 for disabled lun %d", lun);
1242 * Requested Capability not available
1243 * We sent an ATIO that overflowed the firmware's
1244 * command resource count.
1246 isp_prt(isp, ISP_LOGERR,
1247 "rejected ATIO2 for lun %d- command count overflow", lun);
1252 * If we send an ATIO to the firmware to increment
1253 * its command resource count, and the firmware is
1254 * recovering from a Bus Device Reset, it returns
1255 * the ATIO with this status. We set the command
1256 * resource count in the Enable Lun entry and no
1257 * not increment it. Therefore we should never get
1260 isp_prt(isp, ISP_LOGERR, atiocope, lun, 0);
1263 case AT_CDB: /* Got a CDB */
1265 * Punt to platform specific layer.
1267 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
1272 * A bus reset came along an blew away this command. Why
1273 * they do this in addition the async event code stuff,
1276 * Ignore it because the async event will clear things
1279 isp_prt(isp, ISP_LOGERR, atior, lun, iid, 0);
1284 isp_prt(isp, ISP_LOGERR,
1285 "Unknown ATIO2 status 0x%x from loopid %d for lun %d",
1286 aep->at_status, iid, lun);
1287 (void) isp_target_put_atio(isp, aep);
1293 isp_handle_ctio(ispsoftc_t *isp, ct_entry_t *ct)
1296 int pl = ISP_LOGTDEBUG2;
1299 if (ct->ct_syshandle) {
1300 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1308 switch(ct->ct_status & ~QLTM_SVALID) {
1311 * There are generally 3 possibilities as to why we'd get
1313 * We disconnected after receiving a CDB.
1314 * We sent or received data.
1315 * We sent status & command complete.
1318 if (ct->ct_flags & CT_SENDSTATUS) {
1320 } else if ((ct->ct_flags & CT_DATAMASK) == CT_NO_DATA) {
1322 * Nothing to do in this case.
1324 isp_prt(isp, pl, "CTIO- iid %d disconnected OK",
1332 * Bus Device Reset message received or the SCSI Bus has
1333 * been Reset; the firmware has gone to Bus Free.
1335 * The firmware generates an async mailbox interrupt to
1336 * notify us of this and returns outstanding CTIOs with this
1337 * status. These CTIOs are handled in that same way as
1338 * CT_ABORTED ones, so just fall through here.
1340 fmsg = "Bus Device Reset";
1348 * When an Abort message is received the firmware goes to
1349 * Bus Free and returns all outstanding CTIOs with the status
1350 * set, then sends us an Immediate Notify entry.
1353 fmsg = "ABORT TAG message sent by Initiator";
1355 isp_prt(isp, ISP_LOGTDEBUG0, "CTIO destroyed by %s", fmsg);
1360 * CTIO rejected by the firmware due to disabled lun.
1363 isp_prt(isp, ISP_LOGERR,
1364 "Firmware rejected CTIO for disabled lun %d",
1370 * CTIO rejected by the firmware due "no path for the
1371 * nondisconnecting nexus specified". This means that
1372 * we tried to access the bus while a non-disconnecting
1373 * command is in process.
1375 isp_prt(isp, ISP_LOGERR,
1376 "Firmware rejected CTIO for bad nexus %d/%d/%d",
1377 ct->ct_iid, ct->ct_tgt, ct->ct_lun);
1381 fmsg = "Reselection";
1386 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
1391 fmsg = "Unrecoverable Error";
1395 fmsg = "Completed with Error";
1397 case CT_PHASE_ERROR:
1399 fmsg = "Phase Sequence Error";
1403 fmsg = "terminated by TERMINATE TRANSFER";
1407 fmsg = "unacknowledged Immediate Notify pending";
1408 isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg);
1411 isp_prt(isp, ISP_LOGERR, "Unknown CTIO status 0x%x",
1412 ct->ct_status & ~QLTM_SVALID);
1418 * There may be more than one CTIO for a data transfer,
1419 * or this may be a status CTIO we're not monitoring.
1421 * The assumption is that they'll all be returned in the
1422 * order we got them.
1424 if (ct->ct_syshandle == 0) {
1425 if ((ct->ct_flags & CT_SENDSTATUS) == 0) {
1427 "intermediate CTIO completed ok");
1430 "unmonitored CTIO completed ok");
1434 "NO xs for CTIO (handle 0x%x) status 0x%x",
1435 ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1439 * Final CTIO completed. Release DMA resources and
1440 * notify platform dependent layers.
1442 if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) {
1443 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1445 isp_prt(isp, pl, "final CTIO complete");
1447 * The platform layer will destroy the handle if appropriate.
1449 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1454 isp_handle_ctio2(ispsoftc_t *isp, ct2_entry_t *ct)
1457 int pl = ISP_LOGTDEBUG2;
1460 if (ct->ct_syshandle) {
1461 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1469 switch(ct->ct_status & ~QLTM_SVALID) {
1471 isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error");
1477 * There are generally 2 possibilities as to why we'd get
1479 * We sent or received data.
1480 * We sent status & command complete.
1487 * Target Reset function received.
1489 * The firmware generates an async mailbox interrupt to
1490 * notify us of this and returns outstanding CTIOs with this
1491 * status. These CTIOs are handled in that same way as
1492 * CT_ABORTED ones, so just fall through here.
1494 fmsg = "TARGET RESET";
1502 * When an Abort message is received the firmware goes to
1503 * Bus Free and returns all outstanding CTIOs with the status
1504 * set, then sends us an Immediate Notify entry.
1510 isp_prt(isp, ISP_LOGTDEBUG0,
1511 "CTIO2 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid);
1516 * CTIO rejected by the firmware - invalid data direction.
1518 isp_prt(isp, ISP_LOGERR, "CTIO2 had wrong data direction");
1522 fmsg = "failure to reconnect to initiator";
1527 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
1531 fmsg = "Completed with Error";
1535 fmsg = "Port Logout";
1537 case CT_PORTUNAVAIL:
1539 fmsg = "Port not available";
1541 case CT_PORTCHANGED:
1543 fmsg = "Port Changed";
1547 fmsg = "unacknowledged Immediate Notify pending";
1548 isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg);
1553 * CTIO rejected by the firmware because an invalid RX_ID.
1554 * Just print a message.
1556 isp_prt(isp, ISP_LOGWARN,
1557 "CTIO2 completed with Invalid RX_ID 0x%x", ct->ct_rxid);
1561 isp_prt(isp, ISP_LOGERR, "Unknown CTIO2 status 0x%x",
1562 ct->ct_status & ~QLTM_SVALID);
1568 * There may be more than one CTIO for a data transfer,
1569 * or this may be a status CTIO we're not monitoring.
1571 * The assumption is that they'll all be returned in the
1572 * order we got them.
1574 if (ct->ct_syshandle == 0) {
1575 if ((ct->ct_flags & CT2_SENDSTATUS) == 0) {
1577 "intermediate CTIO completed ok");
1580 "unmonitored CTIO completed ok");
1584 "NO xs for CTIO (handle 0x%x) status 0x%x",
1585 ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1588 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
1589 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1591 if (ct->ct_flags & CT2_SENDSTATUS) {
1593 * Sent status and command complete.
1595 * We're now really done with this command, so we
1596 * punt to the platform dependent layers because
1597 * only there can we do the appropriate command
1598 * complete thread synchronization.
1600 isp_prt(isp, pl, "status CTIO complete");
1603 * Final CTIO completed. Release DMA resources and
1604 * notify platform dependent layers.
1606 isp_prt(isp, pl, "data CTIO complete");
1608 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1610 * The platform layer will destroy the handle if appropriate.
1616 isp_handle_ctio7(ispsoftc_t *isp, ct7_entry_t *ct)
1619 int pl = ISP_LOGTDEBUG2;
1622 if (ct->ct_syshandle) {
1623 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1631 switch(ct->ct_nphdl) {
1633 isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error");
1636 case CT7_DATA_UNDER:
1639 * There are generally 2 possibilities as to why we'd get
1641 * We sent or received data.
1642 * We sent status & command complete.
1654 * When an Abort message is received the firmware goes to
1655 * Bus Free and returns all outstanding CTIOs with the status
1656 * set, then sends us an Immediate Notify entry.
1661 isp_prt(isp, ISP_LOGTDEBUG0,
1662 "CTIO7 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid);
1669 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
1673 fmsg = "Completed with Error";
1677 fmsg = "Port Logout";
1680 case CT7_PORTUNAVAIL:
1682 fmsg = "Port not available";
1685 case CT7_PORTCHANGED:
1687 fmsg = "Port Changed";
1689 isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg);
1694 * CTIO rejected by the firmware because an invalid RX_ID.
1695 * Just print a message.
1697 isp_prt(isp, ISP_LOGWARN,
1698 "CTIO7 completed with Invalid RX_ID 0x%x", ct->ct_rxid);
1701 case CT7_REASSY_ERR:
1702 isp_prt(isp, ISP_LOGWARN, "reassembly error");
1706 isp_prt(isp, ISP_LOGWARN, "SRR received");
1710 isp_prt(isp, ISP_LOGERR, "Unknown CTIO7 status 0x%x",
1717 * There may be more than one CTIO for a data transfer,
1718 * or this may be a status CTIO we're not monitoring.
1720 * The assumption is that they'll all be returned in the
1721 * order we got them.
1723 if (ct->ct_syshandle == 0) {
1724 if (ct->ct_flags & CT7_TERMINATE) {
1725 isp_prt(isp, ISP_LOGINFO,
1726 "termination of 0x%x complete",
1728 } else if ((ct->ct_flags & CT7_SENDSTATUS) == 0) {
1730 "intermediate CTIO completed ok");
1733 "unmonitored CTIO completed ok");
1737 "NO xs for CTIO (handle 0x%x) status 0x%x",
1738 ct->ct_syshandle, ct->ct_nphdl);
1741 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
1742 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1744 if (ct->ct_flags & CT2_SENDSTATUS) {
1746 * Sent status and command complete.
1748 * We're now really done with this command, so we
1749 * punt to the platform dependent layers because
1750 * only there can we do the appropriate command
1751 * complete thread synchronization.
1753 isp_prt(isp, pl, "status CTIO complete");
1756 * Final CTIO completed. Release DMA resources and
1757 * notify platform dependent layers.
1759 isp_prt(isp, pl, "data CTIO complete");
1761 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1763 * The platform layer will destroy the handle if appropriate.