2 * Copyright (c) 1997-2009 by Matthew Jacob
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $FreeBSD: src/sys/dev/isp/isp_target.c,v 1.47 2010/02/27 05:41:23 mjacob Exp $
30 * Machine and OS Independent Target Mode Code for the Qlogic SCSI/FC adapters.
33 * Bug fixes gratefully acknowledged from:
34 * Oded Kedem <oded@kashya.com>
37 * Include header file appropriate for platform we're building on.
40 #include <dev/disk/isp/isp_freebsd.h>
42 #ifdef ISP_TARGET_MODE
43 static const char atiocope[] = "ATIO returned for lun %d because it was in the middle of Bus Device Reset on bus %d";
44 static const char atior[] = "ATIO returned on for lun %d on from loopid %d because a Bus Reset occurred on bus %d";
45 static const char rqo[] = "%s: Request Queue Overflow";
47 static void isp_got_msg(ispsoftc_t *, in_entry_t *);
48 static void isp_got_msg_fc(ispsoftc_t *, in_fcentry_t *);
49 static void isp_got_tmf_24xx(ispsoftc_t *, at7_entry_t *);
50 static void isp_handle_atio(ispsoftc_t *, at_entry_t *);
51 static void isp_handle_atio2(ispsoftc_t *, at2_entry_t *);
52 static void isp_handle_ctio(ispsoftc_t *, ct_entry_t *);
53 static void isp_handle_ctio2(ispsoftc_t *, ct2_entry_t *);
54 static void isp_handle_ctio7(ispsoftc_t *, ct7_entry_t *);
55 static void isp_handle_24xx_inotify(ispsoftc_t *, in_fcentry_24xx_t *);
58 * The Qlogic driver gets an interrupt to look at response queue entries.
59 * Some of these are status completions for initiatior mode commands, but
60 * if target mode is enabled, we get a whole wad of response queue entries
63 * Basically the split into 3 main groups: Lun Enable/Modification responses,
64 * SCSI Command processing, and Immediate Notification events.
66 * You start by writing a request queue entry to enable target mode (and
67 * establish some resource limitations which you can modify later).
68 * The f/w responds with a LUN ENABLE or LUN MODIFY response with
69 * the status of this action. If the enable was successful, you can expect...
71 * Response queue entries with SCSI commands encapsulate show up in an ATIO
72 * (Accept Target IO) type- sometimes with enough info to stop the command at
73 * this level. Ultimately the driver has to feed back to the f/w's request
74 * queue a sequence of CTIOs (continue target I/O) that describe data to
75 * be moved and/or status to be sent) and finally finishing with sending
76 * to the f/w's response queue an ATIO which then completes the handshake
77 * with the f/w for that command. There's a lot of variations on this theme,
78 * including flags you can set in the CTIO for the Qlogic 2X00 fibre channel
79 * cards that 'auto-replenish' the f/w's ATIO count, but this is the basic
82 * The third group that can show up in the response queue are Immediate
83 * Notification events. These include things like notifications of SCSI bus
84 * resets, or Bus Device Reset messages or other messages received. This
85 * a classic oddbins area. It can get a little weird because you then turn
86 * around and acknowledge the Immediate Notify by writing an entry onto the
87 * request queue and then the f/w turns around and gives you an acknowledgement
88 * to *your* acknowledgement on the response queue (the idea being to let
89 * the f/w tell you when the event is *really* over I guess).
95 * A new response queue entry has arrived. The interrupt service code
96 * has already swizzled it into the platform dependent from canonical form.
98 * Because of the way this driver is designed, unfortunately most of the
99 * actual synchronization work has to be done in the platform specific
100 * code- we have no synchroniation primitives in the common code.
104 isp_target_notify(ispsoftc_t *isp, void *vptr, uint32_t *optrp)
111 at2e_entry_t *at2eiop;
115 ct2e_entry_t *ct2eiop;
119 in_fcentry_t *inot_fcp;
120 in_fcentry_e_t *inote_fcp;
121 in_fcentry_24xx_t *inot_24xx;
123 na_fcentry_t *nack_fcp;
124 na_fcentry_e_t *nacke_fcp;
125 na_fcentry_24xx_t *nack_24xx;
128 abts_rsp_t *abts_rsp;
131 #define atiop unp.atiop
132 #define at2iop unp.at2iop
133 #define at2eiop unp.at2eiop
134 #define at7iop unp.at7iop
135 #define ctiop unp.ctiop
136 #define ct2iop unp.ct2iop
137 #define ct2eiop unp.ct2eiop
138 #define ct7iop unp.ct7iop
139 #define lunenp unp.lunenp
140 #define inotp unp.inotp
141 #define inot_fcp unp.inot_fcp
142 #define inote_fcp unp.inote_fcp
143 #define inot_24xx unp.inot_24xx
144 #define nackp unp.nackp
145 #define nack_fcp unp.nack_fcp
146 #define nacke_fcp unp.nacke_fcp
147 #define nack_24xx unp.nack_24xx
148 #define abts unp.abts
149 #define abts_rsp unp.abts_rsp
153 uint8_t local[QENTRY_LEN];
155 int bus, type, level, rval = 1;
158 type = isp_get_response_type(isp, (isphdr_t *)vptr);
161 ISP_TDQE(isp, "isp_target_notify", (int) *optrp, vptr);
168 isp_get_atio7(isp, at7iop, (at7_entry_t *) local);
169 at7iop = (at7_entry_t *) local;
171 * Check for and do something with commands whose
172 * IULEN extends past a single queue entry.
174 len = at7iop->at_ta_len & 0xfffff;
175 if (len > (QENTRY_LEN - 8)) {
176 len -= (QENTRY_LEN - 8);
177 isp_prt(isp, ISP_LOGINFO, "long IU length (%d) ignored", len);
179 *optrp = ISP_NXT_QENTRY(*optrp, RESULT_QUEUE_LEN(isp));
184 * Check for a task management function
186 if (at7iop->at_cmnd.fcp_cmnd_task_management) {
187 isp_got_tmf_24xx(isp, at7iop);
191 * Just go straight to outer layer for this one.
193 isp_async(isp, ISPASYNC_TARGET_ACTION, local);
195 isp_get_atio(isp, atiop, (at_entry_t *) local);
196 isp_handle_atio(isp, (at_entry_t *) local);
201 isp_get_ctio(isp, ctiop, (ct_entry_t *) local);
202 isp_handle_ctio(isp, (ct_entry_t *) local);
206 if (ISP_CAP_2KLOGIN(isp)) {
207 isp_get_atio2e(isp, at2eiop, (at2e_entry_t *) local);
209 isp_get_atio2(isp, at2iop, (at2_entry_t *) local);
211 isp_handle_atio2(isp, (at2_entry_t *) local);
216 if (ISP_CAP_2KLOGIN(isp)) {
217 isp_get_ctio2e(isp, ct2eiop, (ct2e_entry_t *) local);
219 isp_get_ctio2(isp, ct2iop, (ct2_entry_t *) local);
221 isp_handle_ctio2(isp, (ct2_entry_t *) local);
225 isp_get_ctio7(isp, ct7iop, (ct7_entry_t *) local);
226 isp_handle_ctio7(isp, (ct7_entry_t *) local);
229 case RQSTYPE_ENABLE_LUN:
230 case RQSTYPE_MODIFY_LUN:
231 isp_get_enable_lun(isp, lunenp, (lun_entry_t *) local);
232 isp_async(isp, ISPASYNC_TARGET_ACTION, local);
238 isp_get_notify_24xx(isp, inot_24xx, (in_fcentry_24xx_t *)local);
239 inot_24xx = (in_fcentry_24xx_t *) local;
240 isp_handle_24xx_inotify(isp, inot_24xx);
244 if (ISP_CAP_2KLOGIN(isp)) {
245 in_fcentry_e_t *ecp = (in_fcentry_e_t *)local;
246 isp_get_notify_fc_e(isp, inote_fcp, ecp);
248 status = ecp->in_status;
249 seqid = ecp->in_seqid;
251 in_fcentry_t *fcp = (in_fcentry_t *)local;
252 isp_get_notify_fc(isp, inot_fcp, fcp);
254 status = fcp->in_status;
255 seqid = fcp->in_seqid;
258 in_entry_t *inp = (in_entry_t *)local;
259 isp_get_notify(isp, inotp, inp);
260 status = inp->in_status & 0xff;
261 seqid = inp->in_seqid;
263 if (IS_DUALBUS(isp)) {
264 bus = GET_BUS_VAL(inp->in_iid);
265 SET_BUS_VAL(inp->in_iid, 0);
269 isp_prt(isp, ISP_LOGTDEBUG0, "Immediate Notify On Bus %d, status=0x%x seqid=0x%x", bus, status, seqid);
272 case IN_MSG_RECEIVED:
273 case IN_IDE_RECEIVED:
275 isp_got_msg_fc(isp, (in_fcentry_t *)local);
277 isp_got_msg(isp, (in_entry_t *)local);
280 case IN_RSRC_UNAVAIL:
281 isp_prt(isp, ISP_LOGINFO, "Firmware out of ATIOs");
282 (void) isp_notify_ack(isp, local);
286 ISP_MEMZERO(¬ify, sizeof (isp_notify_t));
288 notify.nt_wwn = INI_ANY;
289 notify.nt_tgt = TGT_ANY;
290 notify.nt_nphdl = iid;
291 notify.nt_sid = PORT_ANY;
292 notify.nt_did = PORT_ANY;
293 notify.nt_lun = LUN_ANY;
294 notify.nt_tagval = TAG_ANY;
295 notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32);
296 notify.nt_ncode = NT_BUS_RESET;
297 notify.nt_need_ack = 1;
298 notify.nt_lreserved = local;
299 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
303 ISP_MEMZERO(¬ify, sizeof (isp_notify_t));
305 notify.nt_wwn = INI_ANY;
306 notify.nt_nphdl = iid;
307 notify.nt_sid = PORT_ANY;
308 notify.nt_did = PORT_ANY;
309 notify.nt_ncode = NT_LOGOUT;
310 notify.nt_need_ack = 1;
311 notify.nt_lreserved = local;
312 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
316 ISP_MEMZERO(¬ify, sizeof (isp_notify_t));
318 notify.nt_wwn = INI_ANY;
319 notify.nt_nphdl = iid;
320 notify.nt_sid = PORT_ANY;
321 notify.nt_did = PORT_ANY;
322 notify.nt_ncode = NT_ABORT_TASK;
323 notify.nt_need_ack = 1;
324 notify.nt_lreserved = local;
325 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
329 isp_prt(isp, ISP_LOGTINFO, "%s: all ports logged out", __func__);
330 ISP_MEMZERO(¬ify, sizeof (isp_notify_t));
332 notify.nt_wwn = INI_ANY;
333 notify.nt_nphdl = NIL_HANDLE;
334 notify.nt_sid = PORT_ANY;
335 notify.nt_did = PORT_ANY;
336 notify.nt_ncode = NT_GLOBAL_LOGOUT;
337 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
338 (void) isp_notify_ack(isp, local);
341 case IN_PORT_CHANGED:
342 isp_prt(isp, ISP_LOGTINFO, "%s: port changed", __func__);
343 (void) isp_notify_ack(isp, local);
347 ISP_SNPRINTF(local, sizeof local, "%s: unknown status to RQSTYPE_NOTIFY (0x%x)", __func__, status);
348 isp_print_bytes(isp, local, QENTRY_LEN, vptr);
349 (void) isp_notify_ack(isp, local);
354 case RQSTYPE_NOTIFY_ACK:
356 * The ISP is acknowledging our acknowledgement of an
357 * Immediate Notify entry for some asynchronous event.
360 isp_get_notify_ack_24xx(isp, nack_24xx, (na_fcentry_24xx_t *) local);
361 nack_24xx = (na_fcentry_24xx_t *) local;
362 if (nack_24xx->na_status != NA_OK) {
365 level = ISP_LOGTDEBUG1;
367 isp_prt(isp, level, "Notify Ack Status=0x%x; Subcode 0x%x seqid=0x%x", nack_24xx->na_status, nack_24xx->na_status_subcode, nack_24xx->na_rxid);
368 } else if (IS_FC(isp)) {
369 if (ISP_CAP_2KLOGIN(isp)) {
370 isp_get_notify_ack_fc_e(isp, nacke_fcp, (na_fcentry_e_t *)local);
372 isp_get_notify_ack_fc(isp, nack_fcp, (na_fcentry_t *)local);
374 nack_fcp = (na_fcentry_t *)local;
375 if (nack_fcp->na_status != NA_OK) {
378 level = ISP_LOGTDEBUG1;
380 isp_prt(isp, level, "Notify Ack Status=0x%x seqid 0x%x", nack_fcp->na_status, nack_fcp->na_seqid);
382 isp_get_notify_ack(isp, nackp, (na_entry_t *)local);
383 nackp = (na_entry_t *)local;
384 if (nackp->na_status != NA_OK) {
387 level = ISP_LOGTDEBUG1;
389 isp_prt(isp, level, "Notify Ack event 0x%x status=0x%x seqid 0x%x", nackp->na_event, nackp->na_status, nackp->na_seqid);
393 case RQSTYPE_ABTS_RCVD:
394 isp_get_abts(isp, abts, (abts_t *)local);
395 isp_async(isp, ISPASYNC_TARGET_ACTION, &local);
397 case RQSTYPE_ABTS_RSP:
398 isp_get_abts_rsp(isp, abts_rsp, (abts_rsp_t *)local);
399 abts_rsp = (abts_rsp_t *) local;
400 if (abts_rsp->abts_rsp_status) {
403 level = ISP_LOGTDEBUG0;
405 isp_prt(isp, level, "ABTS RSP response[0x%x]: status=0x%x sub=(0x%x 0x%x)", abts_rsp->abts_rsp_rxid_task, abts_rsp->abts_rsp_status,
406 abts_rsp->abts_rsp_payload.rsp.subcode1, abts_rsp->abts_rsp_payload.rsp.subcode2);
409 isp_prt(isp, ISP_LOGERR, "%s: unknown entry type 0x%x", __func__, type);
439 * Toggle (on/off) target mode for bus/target/lun.
441 * The caller has checked for overlap and legality.
443 * Note that not all of bus, target or lun can be paid attention to.
444 * Note also that this action will not be complete until the f/w writes
445 * a response entry. The caller is responsible for synchronizing with this.
448 isp_lun_cmd(ispsoftc_t *isp, int cmd, int bus, int lun, int cmd_cnt, int inot_cnt)
453 ISP_MEMZERO(&el, sizeof (el));
454 if (IS_DUALBUS(isp)) {
455 el.le_rsvd = (bus & 0x1) << 7;
457 el.le_cmd_count = cmd_cnt;
458 el.le_in_count = inot_cnt;
459 if (cmd == RQSTYPE_ENABLE_LUN) {
461 el.le_flags = LUN_TQAE|LUN_DISAD;
465 } else if (cmd == -RQSTYPE_ENABLE_LUN) {
466 cmd = RQSTYPE_ENABLE_LUN;
469 } else if (cmd == -RQSTYPE_MODIFY_LUN) {
470 cmd = RQSTYPE_MODIFY_LUN;
471 el.le_ops = LUN_CCDECR | LUN_INDECR;
473 el.le_ops = LUN_CCINCR | LUN_ININCR;
475 el.le_header.rqs_entry_type = cmd;
476 el.le_header.rqs_entry_count = 1;
478 el.le_tgt = SDPARAM(isp, bus)->isp_initiator_id;
480 } else if (ISP_CAP_SCCFW(isp) == 0) {
485 outp = isp_getrqentry(isp);
487 isp_prt(isp, ISP_LOGERR, rqo, __func__);
490 isp_put_enable_lun(isp, &el, outp);
491 ISP_TDQE(isp, "isp_lun_cmd", isp->isp_reqidx, &el);
492 ISP_SYNC_REQUEST(isp);
497 isp_target_put_entry(ispsoftc_t *isp, void *ap)
500 uint8_t etype = ((isphdr_t *) ap)->rqs_entry_type;
502 outp = isp_getrqentry(isp);
504 isp_prt(isp, ISP_LOGWARN, rqo, __func__);
509 isp_put_atio(isp, (at_entry_t *) ap, (at_entry_t *) outp);
512 if (ISP_CAP_2KLOGIN(isp)) {
513 isp_put_atio2e(isp, (at2e_entry_t *) ap, (at2e_entry_t *) outp);
515 isp_put_atio2(isp, (at2_entry_t *) ap, (at2_entry_t *) outp);
519 isp_put_ctio(isp, (ct_entry_t *) ap, (ct_entry_t *) outp);
522 if (ISP_CAP_2KLOGIN(isp)) {
523 isp_put_ctio2e(isp, (ct2e_entry_t *) ap, (ct2e_entry_t *) outp);
525 isp_put_ctio2(isp, (ct2_entry_t *) ap, (ct2_entry_t *) outp);
529 isp_put_ctio7(isp, (ct7_entry_t *) ap, (ct7_entry_t *) outp);
532 isp_prt(isp, ISP_LOGERR, "%s: Unknown type 0x%x", __func__, etype);
535 ISP_TDQE(isp, __func__, isp->isp_reqidx, ap);
536 ISP_SYNC_REQUEST(isp);
541 isp_target_put_atio(ispsoftc_t *isp, void *arg)
546 at2e_entry_t _atio2e;
549 ISP_MEMZERO(&atun, sizeof atun);
551 at2_entry_t *aep = arg;
552 atun._atio2.at_header.rqs_entry_type = RQSTYPE_ATIO2;
553 atun._atio2.at_header.rqs_entry_count = 1;
554 if (ISP_CAP_SCCFW(isp)) {
555 atun._atio2.at_scclun = aep->at_scclun;
557 atun._atio2.at_lun = (uint8_t) aep->at_lun;
559 if (ISP_CAP_2KLOGIN(isp)) {
560 atun._atio2e.at_iid = ((at2e_entry_t *)aep)->at_iid;
562 atun._atio2.at_iid = aep->at_iid;
564 atun._atio2.at_rxid = aep->at_rxid;
565 atun._atio2.at_status = CT_OK;
567 at_entry_t *aep = arg;
568 atun._atio.at_header.rqs_entry_type = RQSTYPE_ATIO;
569 atun._atio.at_header.rqs_entry_count = 1;
570 atun._atio.at_handle = aep->at_handle;
571 atun._atio.at_iid = aep->at_iid;
572 atun._atio.at_tgt = aep->at_tgt;
573 atun._atio.at_lun = aep->at_lun;
574 atun._atio.at_tag_type = aep->at_tag_type;
575 atun._atio.at_tag_val = aep->at_tag_val;
576 atun._atio.at_status = (aep->at_flags & AT_TQAE);
577 atun._atio.at_status |= CT_OK;
579 return (isp_target_put_entry(isp, &atun));
583 * Command completion- both for handling cases of no resources or
584 * no blackhole driver, or other cases where we have to, inline,
585 * finish the command sanely, or for normal command completion.
587 * The 'completion' code value has the scsi status byte in the low 8 bits.
588 * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have
589 * the sense key and bits 16..23 have the ASCQ and bits 24..31 have the ASC
592 * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't
593 * NB: inline SCSI sense reporting. As such, we lose this information. XXX.
595 * For both parallel && fibre channel, we use the feature that does
596 * an automatic resource autoreplenish so we don't have then later do
597 * put of an atio to replenish the f/w's resource count.
601 isp_endcmd(ispsoftc_t *isp, ...)
608 ct2e_entry_t _ctio2e;
613 ISP_MEMZERO(&un, sizeof un);
618 ct7_entry_t *cto = &un._ctio7;
621 aep = va_arg(ap, at7_entry_t *);
622 nphdl = va_arg(ap, int);
624 * Note that vpidx may equal 0xff (unknown) here
626 vpidx = va_arg(ap, int);
627 code = va_arg(ap, uint32_t);
628 hdl = va_arg(ap, uint32_t);
630 isp_prt(isp, ISP_LOGTDEBUG0, "%s: [RX_ID 0x%x] chan %d code %x", __func__, aep->at_rxid, vpidx, code);
633 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
634 cto->ct_header.rqs_entry_count = 1;
635 cto->ct_nphdl = nphdl;
636 cto->ct_rxid = aep->at_rxid;
637 cto->ct_iid_lo = (aep->at_hdr.s_id[1] << 8) | aep->at_hdr.s_id[2];
638 cto->ct_iid_hi = aep->at_hdr.s_id[0];
639 cto->ct_oxid = aep->at_hdr.ox_id;
640 cto->ct_scsi_status = sts;
641 cto->ct_vpidx = vpidx;
642 cto->ct_flags = CT7_NOACK;
643 if (code & ECMD_TERMINATE) {
644 cto->ct_flags |= CT7_TERMINATE;
645 } else if (code & ECMD_SVALID) {
646 cto->ct_flags |= CT7_FLAG_MODE1 | CT7_SENDSTATUS;
647 cto->ct_scsi_status |= (FCP_SNSLEN_VALID << 8);
648 cto->rsp.m1.ct_resplen = cto->ct_senselen = min(16, MAXRESPLEN_24XX);
649 ISP_MEMZERO(cto->rsp.m1.ct_resp, sizeof (cto->rsp.m1.ct_resp));
650 cto->rsp.m1.ct_resp[0] = 0xf0;
651 cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
652 cto->rsp.m1.ct_resp[7] = 8;
653 cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff;
654 cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff;
656 cto->ct_flags |= CT7_FLAG_MODE1 | CT7_SENDSTATUS;
658 if (aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl) {
659 cto->ct_resid = aep->at_cmnd.cdb_dl.sf.fcp_cmnd_dl;
660 if (cto->ct_resid < 0) {
661 cto->ct_scsi_status |= (FCP_RESID_OVERFLOW << 8);
662 } else if (cto->ct_resid > 0) {
663 cto->ct_scsi_status |= (FCP_RESID_UNDERFLOW << 8);
666 cto->ct_syshandle = hdl;
667 } else if (IS_FC(isp)) {
669 ct2_entry_t *cto = &un._ctio2;
672 aep = va_arg(ap, at2_entry_t *);
673 code = va_arg(ap, uint32_t);
674 hdl = va_arg(ap, uint32_t);
677 isp_prt(isp, ISP_LOGTDEBUG0, "%s: [RX_ID 0x%x] code %x", __func__, aep->at_rxid, code);
680 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
681 cto->ct_header.rqs_entry_count = 1;
682 if (ISP_CAP_SCCFW(isp) == 0) {
683 cto->ct_lun = aep->at_lun;
685 if (ISP_CAP_2KLOGIN(isp)) {
686 un._ctio2e.ct_iid = ((at2e_entry_t *)aep)->at_iid;
688 cto->ct_iid = aep->at_iid;
690 cto->ct_rxid = aep->at_rxid;
691 cto->rsp.m1.ct_scsi_status = sts;
692 cto->ct_flags = CT2_SENDSTATUS | CT2_NO_DATA | CT2_FLAG_MODE1;
694 cto->ct_flags |= CT2_CCINCR;
696 if (aep->at_datalen) {
697 cto->ct_resid = aep->at_datalen;
698 cto->rsp.m1.ct_scsi_status |= CT2_DATA_UNDER;
700 if (sts == SCSI_CHECK && (code & ECMD_SVALID)) {
701 cto->rsp.m1.ct_resp[0] = 0xf0;
702 cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
703 cto->rsp.m1.ct_resp[7] = 8;
704 cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff;
705 cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff;
706 cto->rsp.m1.ct_senselen = 16;
707 cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID;
709 cto->ct_syshandle = hdl;
712 ct_entry_t *cto = &un._ctio;
715 aep = va_arg(ap, at_entry_t *);
716 code = va_arg(ap, uint32_t);
717 hdl = va_arg(ap, uint32_t);
719 isp_prt(isp, ISP_LOGTDEBUG0, "%s: [IID %d] code %x", __func__, aep->at_iid, code);
722 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
723 cto->ct_header.rqs_entry_count = 1;
724 cto->ct_fwhandle = aep->at_handle;
725 cto->ct_iid = aep->at_iid;
726 cto->ct_tgt = aep->at_tgt;
727 cto->ct_lun = aep->at_lun;
728 cto->ct_tag_type = aep->at_tag_type;
729 cto->ct_tag_val = aep->at_tag_val;
730 if (aep->at_flags & AT_TQAE) {
731 cto->ct_flags |= CT_TQAE;
733 cto->ct_flags = CT_SENDSTATUS | CT_NO_DATA;
735 cto->ct_flags |= CT_CCINCR;
737 cto->ct_scsi_status = sts;
738 cto->ct_syshandle = hdl;
740 return (isp_target_put_entry(isp, &un));
744 * These are either broadcast events or specifically CTIO fast completion
748 isp_target_async(ispsoftc_t *isp, int bus, int event)
752 ISP_MEMZERO(¬ify, sizeof (isp_notify_t));
754 notify.nt_wwn = INI_ANY;
755 notify.nt_nphdl = NIL_HANDLE;
756 notify.nt_sid = PORT_ANY;
757 notify.nt_did = PORT_ANY;
758 notify.nt_tgt = TGT_ANY;
759 notify.nt_channel = bus;
760 notify.nt_lun = LUN_ANY;
761 notify.nt_tagval = TAG_ANY;
762 notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32);
767 isp_prt(isp, ISP_LOGTDEBUG0, "%s: LOOP UP", __func__);
768 notify.nt_ncode = NT_LINK_UP;
769 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
771 case ASYNC_LOOP_DOWN:
772 isp_prt(isp, ISP_LOGTDEBUG0, "%s: LOOP DOWN", __func__);
773 notify.nt_ncode = NT_LINK_DOWN;
774 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
776 case ASYNC_LIP_ERROR:
778 case ASYNC_LIP_OCCURRED:
779 case ASYNC_LOOP_RESET:
780 isp_prt(isp, ISP_LOGTDEBUG0, "%s: LIP RESET", __func__);
781 notify.nt_ncode = NT_LIP_RESET;
782 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
784 case ASYNC_BUS_RESET:
785 case ASYNC_TIMEOUT_RESET: /* XXX: where does this come from ? */
786 isp_prt(isp, ISP_LOGTDEBUG0, "%s: BUS RESET", __func__);
787 notify.nt_ncode = NT_BUS_RESET;
788 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
790 case ASYNC_DEVICE_RESET:
791 isp_prt(isp, ISP_LOGTDEBUG0, "%s: DEVICE RESET", __func__);
792 notify.nt_ncode = NT_TARGET_RESET;
793 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
795 case ASYNC_CTIO_DONE:
797 uint8_t storage[QENTRY_LEN];
798 isp_prt(isp, ISP_LOGTDEBUG0, "%s: CTIO DONE", __func__);
799 memset(storage, 0, QENTRY_LEN);
801 ct7_entry_t *ct = (ct7_entry_t *) storage;
802 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO7;
803 ct->ct_nphdl = CT7_OK;
804 ct->ct_syshandle = bus;
805 ct->ct_flags = CT7_SENDSTATUS;
806 } else if (IS_FC(isp)) {
807 /* This should also suffice for 2K login code */
808 ct2_entry_t *ct = (ct2_entry_t *) storage;
809 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
810 ct->ct_status = CT_OK;
811 ct->ct_syshandle = bus;
812 ct->ct_flags = CT2_SENDSTATUS|CT2_FASTPOST;
814 ct_entry_t *ct = (ct_entry_t *) storage;
815 ct->ct_header.rqs_entry_type = RQSTYPE_CTIO;
816 ct->ct_status = CT_OK;
817 ct->ct_syshandle = bus;
818 /* we skip fwhandle here */
820 ct->ct_flags = CT_SENDSTATUS;
822 isp_async(isp, ISPASYNC_TARGET_ACTION, storage);
826 isp_prt(isp, ISP_LOGERR, "%s: unknown event 0x%x", __func__, event);
827 if (isp->isp_state == ISP_RUNSTATE) {
828 (void) isp_notify_ack(isp, NULL);
837 * Process a received message.
838 * The ISP firmware can handle most messages, there are only
839 * a few that we need to deal with:
840 * - abort: clean up the current command
841 * - abort tag and clear queue
845 isp_got_msg(ispsoftc_t *isp, in_entry_t *inp)
848 uint8_t status = inp->in_status & ~QLTM_SVALID;
850 ISP_MEMZERO(¬ify, sizeof (notify));
852 notify.nt_wwn = INI_ANY;
853 notify.nt_nphdl = GET_IID_VAL(inp->in_iid);
854 notify.nt_sid = PORT_ANY;
855 notify.nt_did = PORT_ANY;
856 notify.nt_channel = GET_BUS_VAL(inp->in_iid);
857 notify.nt_tgt = inp->in_tgt;
858 notify.nt_lun = inp->in_lun;
859 IN_MAKE_TAGID(notify.nt_tagval, inp);
860 notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32);
861 notify.nt_lreserved = inp;
863 if (status == IN_IDE_RECEIVED || status == IN_MSG_RECEIVED) {
864 switch (inp->in_msg[0]) {
866 notify.nt_ncode = NT_ABORT_TASK_SET;
868 case MSG_BUS_DEV_RESET:
869 notify.nt_ncode = NT_TARGET_RESET;
872 notify.nt_ncode = NT_ABORT_TASK;
874 case MSG_CLEAR_QUEUE:
875 notify.nt_ncode = NT_CLEAR_TASK_SET;
877 case MSG_REL_RECOVERY:
878 notify.nt_ncode = NT_CLEAR_ACA;
880 case MSG_TERM_IO_PROC:
881 notify.nt_ncode = NT_ABORT_TASK;
884 notify.nt_ncode = NT_LUN_RESET;
887 isp_prt(isp, ISP_LOGERR, "%s: unhandled message 0x%x", __func__, inp->in_msg[0]);
888 (void) isp_notify_ack(isp, inp);
891 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
893 isp_prt(isp, ISP_LOGERR, "%s: unknown immediate notify status 0x%x", __func__, inp->in_status);
894 (void) isp_notify_ack(isp, inp);
899 * Synthesize a message from the task management flags in a FCP_CMND_IU.
902 isp_got_msg_fc(ispsoftc_t *isp, in_fcentry_t *inp)
905 static const char f1[] = "%s from N-port handle 0x%x lun %d seq 0x%x";
906 static const char f2[] = "unknown %s 0x%x lun %d N-Port handle 0x%x task flags 0x%x seq 0x%x\n";
907 uint16_t seqid, loopid;
909 ISP_MEMZERO(¬ify, sizeof (isp_notify_t));
911 notify.nt_wwn = INI_ANY;
912 if (ISP_CAP_2KLOGIN(isp)) {
913 notify.nt_nphdl = ((in_fcentry_e_t *)inp)->in_iid;
914 loopid = ((in_fcentry_e_t *)inp)->in_iid;
915 seqid = ((in_fcentry_e_t *)inp)->in_seqid;
917 notify.nt_nphdl = inp->in_iid;
918 loopid = inp->in_iid;
919 seqid = inp->in_seqid;
921 notify.nt_sid = PORT_ANY;
922 notify.nt_did = PORT_ANY;
924 /* nt_tgt set in outer layers */
925 if (ISP_CAP_SCCFW(isp)) {
926 notify.nt_lun = inp->in_scclun;
928 notify.nt_lun = inp->in_lun;
930 notify.nt_tagval = seqid;
931 notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32);
932 notify.nt_need_ack = 1;
933 notify.nt_lreserved = inp;
935 if (inp->in_status != IN_MSG_RECEIVED) {
936 isp_prt(isp, ISP_LOGINFO, f2, "immediate notify status", inp->in_status, notify.nt_lun, loopid, inp->in_task_flags, inp->in_seqid);
937 (void) isp_notify_ack(isp, inp);
941 if (inp->in_task_flags & TASK_FLAGS_ABORT_TASK_SET) {
942 isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET", loopid, notify.nt_lun, inp->in_seqid);
943 notify.nt_ncode = NT_ABORT_TASK_SET;
944 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_TASK_SET) {
945 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET", loopid, notify.nt_lun, inp->in_seqid);
946 notify.nt_ncode = NT_CLEAR_TASK_SET;
947 } else if (inp->in_task_flags & TASK_FLAGS_LUN_RESET) {
948 isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET", loopid, notify.nt_lun, inp->in_seqid);
949 notify.nt_ncode = NT_LUN_RESET;
950 } else if (inp->in_task_flags & TASK_FLAGS_TARGET_RESET) {
951 isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET", loopid, notify.nt_lun, inp->in_seqid);
952 notify.nt_ncode = NT_TARGET_RESET;
953 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_ACA) {
954 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA", loopid, notify.nt_lun, inp->in_seqid);
955 notify.nt_ncode = NT_CLEAR_ACA;
957 isp_prt(isp, ISP_LOGWARN, f2, "task flag", inp->in_status, notify.nt_lun, loopid, inp->in_task_flags, inp->in_seqid);
958 (void) isp_notify_ack(isp, inp);
961 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
965 isp_got_tmf_24xx(ispsoftc_t *isp, at7_entry_t *aep)
968 static const char f1[] = "%s from PortID 0x%06x lun %d seq 0x%08x";
969 static const char f2[] = "unknown Task Flag 0x%x lun %d PortID 0x%x tag 0x%08x";
973 ISP_MEMZERO(¬ify, sizeof (isp_notify_t));
975 notify.nt_wwn = INI_ANY;
976 notify.nt_lun = (aep->at_cmnd.fcp_cmnd_lun[0] << 8) | (aep->at_cmnd.fcp_cmnd_lun[1]);
977 notify.nt_tagval = aep->at_rxid;
978 notify.nt_tagval |= (((uint64_t)(isp->isp_serno++)) << 32);
979 notify.nt_lreserved = aep;
980 sid = (aep->at_hdr.s_id[0] << 16) | (aep->at_hdr.s_id[1] << 8) | (aep->at_hdr.s_id[2]);
982 /* Channel has to derived from D_ID */
983 did = (aep->at_hdr.d_id[0] << 16) | (aep->at_hdr.d_id[1] << 8) | aep->at_hdr.d_id[2];
984 for (chan = 0; chan < isp->isp_nchan; chan++) {
985 if (FCPARAM(isp, chan)->isp_portid == did) {
989 if (chan == isp->isp_nchan) {
990 isp_prt(isp, ISP_LOGWARN, "%s: D_ID 0x%x not found on any channel", __func__, did);
991 /* just drop on the floor */
994 notify.nt_nphdl = NIL_HANDLE; /* unknown here */
997 notify.nt_channel = chan;
998 if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_ABORT_TASK_SET) {
999 isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET", sid, notify.nt_lun, aep->at_rxid);
1000 notify.nt_ncode = NT_ABORT_TASK_SET;
1001 } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_CLEAR_TASK_SET) {
1002 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET", sid, notify.nt_lun, aep->at_rxid);
1003 notify.nt_ncode = NT_CLEAR_TASK_SET;
1004 } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_LUN_RESET) {
1005 isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET", sid, notify.nt_lun, aep->at_rxid);
1006 notify.nt_ncode = NT_LUN_RESET;
1007 } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_TGT_RESET) {
1008 isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET", sid, notify.nt_lun, aep->at_rxid);
1009 notify.nt_ncode = NT_TARGET_RESET;
1010 } else if (aep->at_cmnd.fcp_cmnd_task_management & FCP_CMND_TMF_CLEAR_ACA) {
1011 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA", sid, notify.nt_lun, aep->at_rxid);
1012 notify.nt_ncode = NT_CLEAR_ACA;
1014 isp_prt(isp, ISP_LOGWARN, f2, aep->at_cmnd.fcp_cmnd_task_management, notify.nt_lun, sid, aep->at_rxid);
1015 notify.nt_ncode = NT_UNKNOWN;
1018 isp_async(isp, ISPASYNC_TARGET_NOTIFY, ¬ify);
1022 isp_notify_ack(ispsoftc_t *isp, void *arg)
1024 char storage[QENTRY_LEN];
1028 * This is in case a Task Management Function ends up here.
1030 if (IS_24XX(isp) && arg != NULL && (((isphdr_t *)arg)->rqs_entry_type == RQSTYPE_ATIO)) {
1031 at7_entry_t *aep = arg;
1032 return (isp_endcmd(isp, aep, NIL_HANDLE, 0, 0, 0));
1035 outp = isp_getrqentry(isp);
1037 isp_prt(isp, ISP_LOGWARN, rqo, __func__);
1041 ISP_MEMZERO(storage, QENTRY_LEN);
1044 na_fcentry_24xx_t *na = (na_fcentry_24xx_t *) storage;
1046 in_fcentry_24xx_t *in = arg;
1047 na->na_nphdl = in->in_nphdl;
1048 na->na_flags = in->in_flags & IN24XX_FLAG_PUREX_IOCB;
1049 na->na_status = in->in_status;
1050 na->na_status_subcode = in->in_status_subcode;
1051 na->na_rxid = in->in_rxid;
1052 na->na_oxid = in->in_oxid;
1053 na->na_vpidx = in->in_vpidx;
1054 if (in->in_status == IN24XX_SRR_RCVD) {
1055 na->na_srr_rxid = in->in_srr_rxid;
1056 na->na_srr_reloff_hi = in->in_srr_reloff_hi;
1057 na->na_srr_reloff_lo = in->in_srr_reloff_lo;
1058 na->na_srr_iu = in->in_srr_iu;
1059 na->na_srr_flags = 1;
1060 na->na_srr_reject_vunique = 0;
1061 na->na_srr_reject_explanation = 1;
1062 na->na_srr_reject_code = 1;
1065 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
1066 na->na_header.rqs_entry_count = 1;
1067 isp_put_notify_24xx_ack(isp, na, (na_fcentry_24xx_t *)outp);
1068 } else if (IS_FC(isp)) {
1069 na_fcentry_t *na = (na_fcentry_t *) storage;
1073 in_fcentry_t *inp = arg;
1074 ISP_MEMCPY(storage, arg, sizeof (isphdr_t));
1075 if (ISP_CAP_2KLOGIN(isp)) {
1076 ((na_fcentry_e_t *)na)->na_iid = ((in_fcentry_e_t *)inp)->in_iid;
1077 iid = ((na_fcentry_e_t *)na)->na_iid;
1079 na->na_iid = inp->in_iid;
1082 na->na_task_flags = inp->in_task_flags & TASK_FLAGS_RESERVED_MASK;
1083 na->na_seqid = inp->in_seqid;
1084 na->na_flags = NAFC_RCOUNT;
1085 na->na_status = inp->in_status;
1086 if (inp->in_status == IN_RESET) {
1087 na->na_flags |= NAFC_RST_CLRD;
1089 if (inp->in_status == IN_MSG_RECEIVED) {
1090 na->na_flags |= NAFC_TVALID;
1091 na->na_response = 0; /* XXX SUCCEEDED XXX */
1094 na->na_flags = NAFC_RST_CLRD;
1096 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
1097 na->na_header.rqs_entry_count = 1;
1098 if (ISP_CAP_2KLOGIN(isp)) {
1099 isp_put_notify_ack_fc_e(isp, (na_fcentry_e_t *) na, (na_fcentry_e_t *)outp);
1101 isp_put_notify_ack_fc(isp, na, (na_fcentry_t *)outp);
1103 isp_prt(isp, ISP_LOGTDEBUG0, "notify ack loopid %u seqid %x flags %x tflags %x response %x", iid, na->na_seqid,
1104 na->na_flags, na->na_task_flags, na->na_response);
1106 na_entry_t *na = (na_entry_t *) storage;
1108 in_entry_t *inp = arg;
1109 ISP_MEMCPY(storage, arg, sizeof (isphdr_t));
1110 na->na_iid = inp->in_iid;
1111 na->na_lun = inp->in_lun;
1112 na->na_tgt = inp->in_tgt;
1113 na->na_seqid = inp->in_seqid;
1114 if (inp->in_status == IN_RESET) {
1115 na->na_event = NA_RST_CLRD;
1118 na->na_event = NA_RST_CLRD;
1120 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
1121 na->na_header.rqs_entry_count = 1;
1122 isp_put_notify_ack(isp, na, (na_entry_t *)outp);
1123 isp_prt(isp, ISP_LOGTDEBUG0, "notify ack loopid %u lun %u tgt %u seqid %x event %x", na->na_iid, na->na_lun, na->na_tgt, na->na_seqid, na->na_event);
1125 ISP_TDQE(isp, "isp_notify_ack", isp->isp_reqidx, storage);
1126 ISP_SYNC_REQUEST(isp);
1131 isp_acknak_abts(ispsoftc_t *isp, void *arg, int errno)
1133 char storage[QENTRY_LEN];
1137 abts_rsp_t *rsp = (abts_rsp_t *) storage;
1140 if (!IS_24XX(isp)) {
1141 isp_prt(isp, ISP_LOGERR, "%s: called for non-24XX card", __func__);
1145 if (abts->abts_header.rqs_entry_type != RQSTYPE_ABTS_RCVD) {
1146 isp_prt(isp, ISP_LOGERR, "%s: called for non-ABTS entry (0x%x)", __func__, abts->abts_header.rqs_entry_type);
1150 outp = isp_getrqentry(isp);
1152 isp_prt(isp, ISP_LOGWARN, rqo, __func__);
1156 ISP_MEMCPY(rsp, abts, QENTRY_LEN);
1157 rsp->abts_rsp_header.rqs_entry_type = RQSTYPE_ABTS_RSP;
1160 * Swap destination and source for response.
1162 rsp->abts_rsp_r_ctl = BA_ACC;
1163 tmpw = rsp->abts_rsp_did_lo;
1164 tmpb = rsp->abts_rsp_did_hi;
1165 rsp->abts_rsp_did_lo = rsp->abts_rsp_sid_lo;
1166 rsp->abts_rsp_did_hi = rsp->abts_rsp_sid_hi;
1167 rsp->abts_rsp_sid_lo = tmpw;
1168 rsp->abts_rsp_sid_hi = tmpb;
1170 rsp->abts_rsp_f_ctl_hi ^= 0x80; /* invert Exchange Context */
1171 rsp->abts_rsp_f_ctl_hi &= ~0x7f; /* clear Sequence Initiator and other bits */
1172 rsp->abts_rsp_f_ctl_hi |= 0x10; /* abort the whole exchange */
1173 rsp->abts_rsp_f_ctl_hi |= 0x8; /* last data frame of sequence */
1174 rsp->abts_rsp_f_ctl_hi |= 0x1; /* transfer Sequence Initiative */
1175 rsp->abts_rsp_f_ctl_lo = 0;
1178 uint16_t rx_id, ox_id;
1180 rx_id = rsp->abts_rsp_rx_id;
1181 ox_id = rsp->abts_rsp_ox_id;
1182 ISP_MEMZERO(&rsp->abts_rsp_payload.ba_acc, sizeof (rsp->abts_rsp_payload.ba_acc));
1183 isp_prt(isp, ISP_LOGTINFO, "[0x%x] ABTS of 0x%x being BA_ACC'd", rsp->abts_rsp_rxid_abts, rsp->abts_rsp_rxid_task);
1184 rsp->abts_rsp_payload.ba_acc.aborted_rx_id = rx_id;
1185 rsp->abts_rsp_payload.ba_acc.aborted_ox_id = ox_id;
1186 rsp->abts_rsp_payload.ba_acc.high_seq_cnt = 0xffff;
1188 ISP_MEMZERO(&rsp->abts_rsp_payload.ba_rjt, sizeof (rsp->abts_rsp_payload.ba_acc));
1191 rsp->abts_rsp_payload.ba_rjt.reason = 5; /* Logical Busy */
1194 rsp->abts_rsp_payload.ba_rjt.reason = 9; /* Unable to perform command request */
1200 * The caller will have set response values as appropriate
1201 * in the ABTS structure just before calling us.
1203 isp_put_abts_rsp(isp, rsp, (abts_rsp_t *)outp);
1204 ISP_TDQE(isp, "isp_acknak_abts", isp->isp_reqidx, storage);
1205 ISP_SYNC_REQUEST(isp);
1210 isp_handle_atio(ispsoftc_t *isp, at_entry_t *aep)
1215 * The firmware status (except for the QLTM_SVALID bit) indicates
1216 * why this ATIO was sent to us.
1218 * If QLTM_SVALID is set, the firware has recommended Sense Data.
1220 * If the DISCONNECTS DISABLED bit is set in the flags field,
1221 * we're still connected on the SCSI bus - i.e. the initiator
1222 * did not set DiscPriv in the identify message. We don't care
1223 * about this so it's ignored.
1226 switch (aep->at_status & ~QLTM_SVALID) {
1227 case AT_PATH_INVALID:
1229 * ATIO rejected by the firmware due to disabled lun.
1231 isp_prt(isp, ISP_LOGERR, "rejected ATIO for disabled lun %d", lun);
1235 * Requested Capability not available
1236 * We sent an ATIO that overflowed the firmware's
1237 * command resource count.
1239 isp_prt(isp, ISP_LOGERR, "rejected ATIO for lun %d because of command count overflow", lun);
1244 * If we send an ATIO to the firmware to increment
1245 * its command resource count, and the firmware is
1246 * recovering from a Bus Device Reset, it returns
1247 * the ATIO with this status. We set the command
1248 * resource count in the Enable Lun entry and do
1249 * not increment it. Therefore we should never get
1252 isp_prt(isp, ISP_LOGERR, atiocope, lun, GET_BUS_VAL(aep->at_iid));
1255 case AT_CDB: /* Got a CDB */
1256 case AT_PHASE_ERROR: /* Bus Phase Sequence Error */
1258 * Punt to platform specific layer.
1260 isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
1265 * A bus reset came along and blew away this command. Why
1266 * they do this in addition the async event code stuff,
1269 * Ignore it because the async event will clear things
1272 isp_prt(isp, ISP_LOGWARN, atior, lun, GET_IID_VAL(aep->at_iid), GET_BUS_VAL(aep->at_iid));
1277 isp_prt(isp, ISP_LOGERR, "Unknown ATIO status 0x%x from loopid %d for lun %d", aep->at_status, aep->at_iid, lun);
1278 (void) isp_target_put_atio(isp, aep);
1284 isp_handle_atio2(ispsoftc_t *isp, at2_entry_t *aep)
1288 if (ISP_CAP_SCCFW(isp)) {
1289 lun = aep->at_scclun;
1294 if (ISP_CAP_2KLOGIN(isp)) {
1295 iid = ((at2e_entry_t *)aep)->at_iid;
1301 * The firmware status (except for the QLTM_SVALID bit) indicates
1302 * why this ATIO was sent to us.
1304 * If QLTM_SVALID is set, the firware has recommended Sense Data.
1306 * If the DISCONNECTS DISABLED bit is set in the flags field,
1307 * we're still connected on the SCSI bus - i.e. the initiator
1308 * did not set DiscPriv in the identify message. We don't care
1309 * about this so it's ignored.
1312 switch (aep->at_status & ~QLTM_SVALID) {
1313 case AT_PATH_INVALID:
1315 * ATIO rejected by the firmware due to disabled lun.
1317 isp_prt(isp, ISP_LOGERR, "rejected ATIO2 for disabled lun %d", lun);
1321 * Requested Capability not available
1322 * We sent an ATIO that overflowed the firmware's
1323 * command resource count.
1325 isp_prt(isp, ISP_LOGERR, "rejected ATIO2 for lun %d- command count overflow", lun);
1330 * If we send an ATIO to the firmware to increment
1331 * its command resource count, and the firmware is
1332 * recovering from a Bus Device Reset, it returns
1333 * the ATIO with this status. We set the command
1334 * resource count in the Enable Lun entry and no
1335 * not increment it. Therefore we should never get
1338 isp_prt(isp, ISP_LOGERR, atiocope, lun, 0);
1341 case AT_CDB: /* Got a CDB */
1343 * Punt to platform specific layer.
1345 isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
1350 * A bus reset came along an blew away this command. Why
1351 * they do this in addition the async event code stuff,
1354 * Ignore it because the async event will clear things
1357 isp_prt(isp, ISP_LOGERR, atior, lun, iid, 0);
1362 isp_prt(isp, ISP_LOGERR, "Unknown ATIO2 status 0x%x from loopid %d for lun %d", aep->at_status, iid, lun);
1363 (void) isp_target_put_atio(isp, aep);
1369 isp_handle_ctio(ispsoftc_t *isp, ct_entry_t *ct)
1372 int pl = ISP_LOGTDEBUG2;
1375 if (ct->ct_syshandle) {
1376 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1384 switch (ct->ct_status & ~QLTM_SVALID) {
1387 * There are generally 3 possibilities as to why we'd get
1389 * We disconnected after receiving a CDB.
1390 * We sent or received data.
1391 * We sent status & command complete.
1394 if (ct->ct_flags & CT_SENDSTATUS) {
1396 } else if ((ct->ct_flags & CT_DATAMASK) == CT_NO_DATA) {
1398 * Nothing to do in this case.
1400 isp_prt(isp, pl, "CTIO- iid %d disconnected OK", ct->ct_iid);
1407 * Bus Device Reset message received or the SCSI Bus has
1408 * been Reset; the firmware has gone to Bus Free.
1410 * The firmware generates an async mailbox interrupt to
1411 * notify us of this and returns outstanding CTIOs with this
1412 * status. These CTIOs are handled in that same way as
1413 * CT_ABORTED ones, so just fall through here.
1415 fmsg = "Bus Device Reset";
1423 * When an Abort message is received the firmware goes to
1424 * Bus Free and returns all outstanding CTIOs with the status
1425 * set, then sends us an Immediate Notify entry.
1428 fmsg = "ABORT TAG message sent by Initiator";
1429 isp_prt(isp, ISP_LOGTDEBUG0, "CTIO destroyed by %s", fmsg);
1434 * CTIO rejected by the firmware due to disabled lun.
1437 isp_prt(isp, ISP_LOGERR, "Firmware rejected CTIO for disabled lun %d", ct->ct_lun);
1442 * CTIO rejected by the firmware due "no path for the
1443 * nondisconnecting nexus specified". This means that
1444 * we tried to access the bus while a non-disconnecting
1445 * command is in process.
1447 isp_prt(isp, ISP_LOGERR, "Firmware rejected CTIO for bad nexus %d/%d/%d", ct->ct_iid, ct->ct_tgt, ct->ct_lun);
1451 fmsg = "Reselection";
1456 isp_prt(isp, ISP_LOGWARN, "Firmware timed out on %s", fmsg);
1461 fmsg = "Unrecoverable Error";
1465 fmsg = "Completed with Error";
1467 case CT_PHASE_ERROR:
1469 fmsg = "Phase Sequence Error";
1473 fmsg = "terminated by TERMINATE TRANSFER";
1477 fmsg = "unacknowledged Immediate Notify pending";
1478 isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg);
1481 isp_prt(isp, ISP_LOGERR, "Unknown CTIO status 0x%x", ct->ct_status & ~QLTM_SVALID);
1487 * There may be more than one CTIO for a data transfer,
1488 * or this may be a status CTIO we're not monitoring.
1490 * The assumption is that they'll all be returned in the
1491 * order we got them.
1493 if (ct->ct_syshandle == 0) {
1494 if ((ct->ct_flags & CT_SENDSTATUS) == 0) {
1495 isp_prt(isp, pl, "intermediate CTIO completed ok");
1497 isp_prt(isp, pl, "unmonitored CTIO completed ok");
1500 isp_prt(isp, pl, "NO xs for CTIO (handle 0x%x) status 0x%x", ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1504 * Final CTIO completed. Release DMA resources and
1505 * notify platform dependent layers.
1507 if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) {
1508 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1510 isp_prt(isp, pl, "final CTIO complete");
1512 * The platform layer will destroy the handle if appropriate.
1514 isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1519 isp_handle_ctio2(ispsoftc_t *isp, ct2_entry_t *ct)
1522 int pl = ISP_LOGTDEBUG2;
1525 if (ct->ct_syshandle) {
1526 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1534 switch (ct->ct_status & ~QLTM_SVALID) {
1536 isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error");
1542 * There are generally 2 possibilities as to why we'd get
1544 * We sent or received data.
1545 * We sent status & command complete.
1552 * Target Reset function received.
1554 * The firmware generates an async mailbox interrupt to
1555 * notify us of this and returns outstanding CTIOs with this
1556 * status. These CTIOs are handled in that same way as
1557 * CT_ABORTED ones, so just fall through here.
1559 fmsg = "TARGET RESET";
1567 * When an Abort message is received the firmware goes to
1568 * Bus Free and returns all outstanding CTIOs with the status
1569 * set, then sends us an Immediate Notify entry.
1575 isp_prt(isp, ISP_LOGTDEBUG0, "CTIO2 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid);
1580 * CTIO rejected by the firmware - invalid data direction.
1582 isp_prt(isp, ISP_LOGERR, "CTIO2 had wrong data direction");
1586 fmsg = "failure to reconnect to initiator";
1591 isp_prt(isp, ISP_LOGWARN, "Firmware timed out on %s", fmsg);
1595 fmsg = "Completed with Error";
1599 fmsg = "Port Logout";
1601 case CT_PORTUNAVAIL:
1603 fmsg = "Port not available";
1605 case CT_PORTCHANGED:
1607 fmsg = "Port Changed";
1611 fmsg = "unacknowledged Immediate Notify pending";
1612 isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg);
1617 * CTIO rejected by the firmware because an invalid RX_ID.
1618 * Just print a message.
1620 isp_prt(isp, ISP_LOGWARN, "CTIO2 completed with Invalid RX_ID 0x%x", ct->ct_rxid);
1624 isp_prt(isp, ISP_LOGERR, "Unknown CTIO2 status 0x%x", ct->ct_status & ~QLTM_SVALID);
1630 * There may be more than one CTIO for a data transfer,
1631 * or this may be a status CTIO we're not monitoring.
1633 * The assumption is that they'll all be returned in the
1634 * order we got them.
1636 if (ct->ct_syshandle == 0) {
1637 if ((ct->ct_flags & CT2_SENDSTATUS) == 0) {
1638 isp_prt(isp, pl, "intermediate CTIO completed ok");
1640 isp_prt(isp, pl, "unmonitored CTIO completed ok");
1643 isp_prt(isp, pl, "NO xs for CTIO (handle 0x%x) status 0x%x", ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1646 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
1647 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1649 if (ct->ct_flags & CT2_SENDSTATUS) {
1651 * Sent status and command complete.
1653 * We're now really done with this command, so we
1654 * punt to the platform dependent layers because
1655 * only there can we do the appropriate command
1656 * complete thread synchronization.
1658 isp_prt(isp, pl, "status CTIO complete");
1661 * Final CTIO completed. Release DMA resources and
1662 * notify platform dependent layers.
1664 isp_prt(isp, pl, "data CTIO complete");
1666 isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1668 * The platform layer will destroy the handle if appropriate.
1674 isp_handle_ctio7(ispsoftc_t *isp, ct7_entry_t *ct)
1677 int pl = ISP_LOGTDEBUG2;
1680 if (ct->ct_syshandle) {
1681 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1689 switch (ct->ct_nphdl) {
1691 isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error");
1694 case CT7_DATA_UNDER:
1697 * There are generally 2 possibilities as to why we'd get
1699 * We sent or received data.
1700 * We sent status & command complete.
1712 * When an Abort message is received the firmware goes to
1713 * Bus Free and returns all outstanding CTIOs with the status
1714 * set, then sends us an Immediate Notify entry.
1719 isp_prt(isp, ISP_LOGTDEBUG0, "CTIO7 destroyed by %s: RX_ID=0x%x", fmsg, ct->ct_rxid);
1726 isp_prt(isp, ISP_LOGWARN, "Firmware timed out on %s", fmsg);
1730 fmsg = "Completed with Error";
1734 fmsg = "Port Logout";
1737 case CT7_PORTUNAVAIL:
1739 fmsg = "Port not available";
1742 case CT7_PORTCHANGED:
1744 fmsg = "Port Changed";
1746 isp_prt(isp, ISP_LOGWARN, "CTIO returned by f/w- %s", fmsg);
1751 * CTIO rejected by the firmware because an invalid RX_ID.
1752 * Just print a message.
1754 isp_prt(isp, ISP_LOGWARN, "CTIO7 completed with Invalid RX_ID 0x%x", ct->ct_rxid);
1757 case CT7_REASSY_ERR:
1758 isp_prt(isp, ISP_LOGWARN, "reassembly error");
1762 isp_prt(isp, ISP_LOGWARN, "SRR received");
1766 isp_prt(isp, ISP_LOGERR, "Unknown CTIO7 status 0x%x", ct->ct_nphdl);
1772 * There may be more than one CTIO for a data transfer,
1773 * or this may be a status CTIO we're not monitoring.
1775 * The assumption is that they'll all be returned in the
1776 * order we got them.
1778 if (ct->ct_syshandle == 0) {
1779 if (ct->ct_flags & CT7_TERMINATE) {
1780 isp_prt(isp, ISP_LOGINFO, "termination of 0x%x complete", ct->ct_rxid);
1781 } else if ((ct->ct_flags & CT7_SENDSTATUS) == 0) {
1782 isp_prt(isp, pl, "intermediate CTIO completed ok");
1784 isp_prt(isp, pl, "unmonitored CTIO completed ok");
1787 isp_prt(isp, pl, "NO xs for CTIO (handle 0x%x) status 0x%x", ct->ct_syshandle, ct->ct_nphdl);
1790 if ((ct->ct_flags & CT7_DATAMASK) != CT7_NO_DATA) {
1791 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1793 if (ct->ct_flags & CT7_SENDSTATUS) {
1795 * Sent status and command complete.
1797 * We're now really done with this command, so we
1798 * punt to the platform dependent layers because
1799 * only there can we do the appropriate command
1800 * complete thread synchronization.
1802 isp_prt(isp, pl, "status CTIO complete");
1805 * Final CTIO completed. Release DMA resources and
1806 * notify platform dependent layers.
1808 isp_prt(isp, pl, "data CTIO complete");
1810 isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1812 * The platform layer will destroy the handle if appropriate.
1818 isp_handle_24xx_inotify(ispsoftc_t *isp, in_fcentry_24xx_t *inot_24xx)
1820 uint8_t ochan, chan, lochan, hichan;
1823 * Check to see whether we got a wildcard channel.
1824 * If so, we have to iterate over all channels.
1826 ochan = chan = ISP_GET_VPIDX(isp, inot_24xx->in_vpidx);
1829 hichan = isp->isp_nchan;
1831 if (chan >= isp->isp_nchan) {
1833 ISP_SNPRINTF(buf, sizeof buf, "%s: bad channel %d for status 0x%x", __func__, chan, inot_24xx->in_status);
1834 isp_print_bytes(isp, buf, QENTRY_LEN, inot_24xx);
1835 (void) isp_notify_ack(isp, inot_24xx);
1841 isp_prt(isp, ISP_LOGTDEBUG1, "%s: Immediate Notify Channels %d..%d status=0x%x seqid=0x%x", __func__, lochan, hichan-1, inot_24xx->in_status, inot_24xx->in_rxid);
1842 for (chan = lochan; chan < hichan; chan++) {
1843 switch (inot_24xx->in_status) {
1844 case IN24XX_LIP_RESET:
1845 case IN24XX_LINK_RESET:
1846 case IN24XX_PORT_LOGOUT:
1847 case IN24XX_PORT_CHANGED:
1848 case IN24XX_LINK_FAILED:
1849 case IN24XX_SRR_RCVD:
1850 case IN24XX_ELS_RCVD:
1851 inot_24xx->in_vpidx = chan;
1852 isp_async(isp, ISPASYNC_TARGET_ACTION, inot_24xx);
1855 isp_prt(isp, ISP_LOGINFO, "%s: unhandled status (0x%x) for chan %d", __func__, inot_24xx->in_status, chan);
1856 (void) isp_notify_ack(isp, inot_24xx);
1860 inot_24xx->in_vpidx = ochan;