3 * Machine and OS Independent Target Mode Code for the Qlogic SCSI/FC adapters.
5 * Copyright (c) 1999, 2000, 2001 by Matthew Jacob
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice immediately at the beginning of the file, without modification,
14 * this list of conditions, and the following disclaimer.
15 * 2. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * Bug fixes gratefully acknowledged from:
33 * Oded Kedem <oded@kashya.com>
36 * Include header file appropriate for platform we're building on.
40 #include <dev/ic/isp_netbsd.h>
43 #include <dev/isp/isp_freebsd.h>
46 #include <dev/ic/isp_openbsd.h>
49 #include "isp_linux.h"
52 #ifdef ISP_TARGET_MODE
53 static const char atiocope[] =
54 "ATIO returned for lun %d because it was in the middle of Bus Device Reset "
56 static const char atior[] =
57 "ATIO returned on for lun %d on from IID %d because a Bus Reset occurred "
60 static void isp_got_msg(struct ispsoftc *, int, in_entry_t *);
61 static void isp_got_msg_fc(struct ispsoftc *, int, in_fcentry_t *);
62 static void isp_notify_ack(struct ispsoftc *, void *);
63 static void isp_handle_atio(struct ispsoftc *, at_entry_t *);
64 static void isp_handle_atio2(struct ispsoftc *, at2_entry_t *);
65 static void isp_handle_ctio(struct ispsoftc *, ct_entry_t *);
66 static void isp_handle_ctio2(struct ispsoftc *, ct2_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(struct ispsoftc *isp, void *vptr, u_int16_t *optrp)
117 u_int16_t status, seqid;
125 in_fcentry_t *inot_fcp;
127 na_fcentry_t *nack_fcp;
130 #define atiop unp.atiop
131 #define at2iop unp.at2iop
132 #define ctiop unp.ctiop
133 #define ct2iop unp.ct2iop
134 #define lunenp unp.lunenp
135 #define inotp unp.inotp
136 #define inot_fcp unp.inot_fcp
137 #define nackp unp.nackp
138 #define nack_fcp unp.nack_fcp
141 u_int8_t local[QENTRY_LEN];
142 int bus, type, rval = 1;
144 type = isp_get_response_type(isp, (isphdr_t *)vptr);
147 ISP_TDQE(isp, "isp_target_notify", (int) *optrp, vptr);
151 isp_get_atio(isp, atiop, (at_entry_t *) local);
152 isp_handle_atio(isp, (at_entry_t *) local);
155 isp_get_ctio(isp, ctiop, (ct_entry_t *) local);
156 isp_handle_ctio(isp, (ct_entry_t *) local);
159 isp_get_atio2(isp, at2iop, (at2_entry_t *) local);
160 isp_handle_atio2(isp, (at2_entry_t *) local);
163 isp_get_ctio2(isp, ct2iop, (ct2_entry_t *) local);
164 isp_handle_ctio2(isp, (ct2_entry_t *) local);
166 case RQSTYPE_ENABLE_LUN:
167 case RQSTYPE_MODIFY_LUN:
168 isp_get_enable_lun(isp, lunenp, (lun_entry_t *) local);
169 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, local);
174 * Either the ISP received a SCSI message it can't
175 * handle, or it's returning an Immed. Notify entry
176 * we sent. We can send Immed. Notify entries to
177 * increment the firmware's resource count for them
178 * (we set this initially in the Enable Lun entry).
182 isp_get_notify_fc(isp, inot_fcp, (in_fcentry_t *)local);
183 inot_fcp = (in_fcentry_t *) local;
184 status = inot_fcp->in_status;
185 seqid = inot_fcp->in_seqid;
187 isp_get_notify(isp, inotp, (in_entry_t *)local);
188 inotp = (in_entry_t *) local;
189 status = inotp->in_status & 0xff;
190 seqid = inotp->in_seqid;
191 if (IS_DUALBUS(isp)) {
192 bus = GET_BUS_VAL(inotp->in_iid);
193 SET_BUS_VAL(inotp->in_iid, 0);
196 isp_prt(isp, ISP_LOGTDEBUG0,
197 "Immediate Notify On Bus %d, status=0x%x seqid=0x%x",
203 isp_notify_ack(isp, (status == IN_RESET)? NULL : local);
206 (void) isp_async(isp, ISPASYNC_BUS_RESET, &bus);
208 case IN_MSG_RECEIVED:
209 case IN_IDE_RECEIVED:
211 isp_got_msg_fc(isp, bus, (in_fcentry_t *)local);
213 isp_got_msg(isp, bus, (in_entry_t *)local);
216 case IN_RSRC_UNAVAIL:
217 isp_prt(isp, ISP_LOGWARN, "Firmware out of ATIOs");
221 case IN_PORT_CHANGED:
223 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, &local);
226 isp_prt(isp, ISP_LOGERR,
227 "bad status (0x%x) in isp_target_notify", status);
232 case RQSTYPE_NOTIFY_ACK:
234 * The ISP is acknowledging our acknowledgement of an
235 * Immediate Notify entry for some asynchronous event.
238 isp_get_notify_ack_fc(isp, nack_fcp,
239 (na_fcentry_t *)local);
240 nack_fcp = (na_fcentry_t *)local;
241 isp_prt(isp, ISP_LOGTDEBUG1,
242 "Notify Ack status=0x%x seqid 0x%x",
243 nack_fcp->na_status, nack_fcp->na_seqid);
245 isp_get_notify_ack(isp, nackp, (na_entry_t *)local);
246 nackp = (na_entry_t *)local;
247 isp_prt(isp, ISP_LOGTDEBUG1,
248 "Notify Ack event 0x%x status=0x%x seqid 0x%x",
249 nackp->na_event, nackp->na_status, nackp->na_seqid);
253 isp_prt(isp, ISP_LOGERR,
254 "Unknown entry type 0x%x in isp_target_notify", type);
273 * Toggle (on/off) target mode for bus/target/lun
275 * The caller has checked for overlap and legality.
277 * Note that not all of bus, target or lun can be paid attention to.
278 * Note also that this action will not be complete until the f/w writes
279 * response entry. The caller is responsible for synchronizing this.
282 isp_lun_cmd(struct ispsoftc *isp, int cmd, int bus, int tgt, int lun,
283 int cmd_cnt, int inot_cnt, u_int32_t opaque)
286 u_int16_t nxti, optr;
290 MEMZERO(&el, sizeof (el));
291 if (IS_DUALBUS(isp)) {
292 el.le_rsvd = (bus & 0x1) << 7;
294 el.le_cmd_count = cmd_cnt;
295 el.le_in_count = inot_cnt;
296 if (cmd == RQSTYPE_ENABLE_LUN) {
298 el.le_flags = LUN_TQAE|LUN_DISAD;
302 } else if (cmd == -RQSTYPE_ENABLE_LUN) {
303 cmd = RQSTYPE_ENABLE_LUN;
306 } else if (cmd == -RQSTYPE_MODIFY_LUN) {
307 cmd = RQSTYPE_MODIFY_LUN;
308 el.le_ops = LUN_CCDECR | LUN_INDECR;
310 el.le_ops = LUN_CCINCR | LUN_ININCR;
312 el.le_header.rqs_entry_type = cmd;
313 el.le_header.rqs_entry_count = 1;
314 el.le_reserved = opaque;
318 } else if ((FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) == 0) {
323 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
324 isp_prt(isp, ISP_LOGERR,
325 "Request Queue Overflow in isp_lun_cmd");
328 ISP_TDQE(isp, "isp_lun_cmd", (int) optr, &el);
329 isp_put_enable_lun(isp, &el, outp);
330 ISP_ADD_REQUEST(isp, nxti);
336 isp_target_put_entry(struct ispsoftc *isp, void *ap)
339 u_int16_t nxti, optr;
340 u_int8_t etype = ((isphdr_t *) ap)->rqs_entry_type;
342 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
343 isp_prt(isp, ISP_LOGWARN,
344 "Request Queue Overflow in isp_target_put_entry");
349 isp_put_atio(isp, (at_entry_t *) ap, (at_entry_t *) outp);
352 isp_put_atio2(isp, (at2_entry_t *) ap, (at2_entry_t *) outp);
355 isp_put_ctio(isp, (ct_entry_t *) ap, (ct_entry_t *) outp);
358 isp_put_ctio2(isp, (ct2_entry_t *) ap, (ct2_entry_t *) outp);
361 isp_prt(isp, ISP_LOGERR,
362 "Unknown type 0x%x in isp_put_entry", etype);
366 ISP_TDQE(isp, "isp_target_put_entry", (int) optr, ap);;
367 ISP_ADD_REQUEST(isp, nxti);
372 isp_target_put_atio(struct ispsoftc *isp, void *arg)
379 MEMZERO(&atun, sizeof atun);
381 at2_entry_t *aep = arg;
382 atun._atio2.at_header.rqs_entry_type = RQSTYPE_ATIO2;
383 atun._atio2.at_header.rqs_entry_count = 1;
384 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
385 atun._atio2.at_scclun = (u_int16_t) aep->at_scclun;
387 atun._atio2.at_lun = (u_int8_t) aep->at_lun;
389 atun._atio2.at_status = CT_OK;
391 at_entry_t *aep = arg;
392 atun._atio.at_header.rqs_entry_type = RQSTYPE_ATIO;
393 atun._atio.at_header.rqs_entry_count = 1;
394 atun._atio.at_handle = aep->at_handle;
395 atun._atio.at_iid = aep->at_iid;
396 atun._atio.at_tgt = aep->at_tgt;
397 atun._atio.at_lun = aep->at_lun;
398 atun._atio.at_tag_type = aep->at_tag_type;
399 atun._atio.at_tag_val = aep->at_tag_val;
400 atun._atio.at_status = (aep->at_flags & AT_TQAE);
401 atun._atio.at_status |= CT_OK;
403 return (isp_target_put_entry(isp, &atun));
407 * Command completion- both for handling cases of no resources or
408 * no blackhole driver, or other cases where we have to, inline,
409 * finish the command sanely, or for normal command completion.
411 * The 'completion' code value has the scsi status byte in the low 8 bits.
412 * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have
413 * the sense key and bits 16..23 have the ASCQ and bits 24..31 have the ASC
416 * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't
417 * NB: inline SCSI sense reporting. As such, we lose this information. XXX.
419 * For both parallel && fibre channel, we use the feature that does
420 * an automatic resource autoreplenish so we don't have then later do
421 * put of an atio to replenish the f/w's resource count.
425 isp_endcmd(struct ispsoftc *isp, void *arg, u_int32_t code, u_int16_t hdl)
433 MEMZERO(&un, sizeof un);
437 at2_entry_t *aep = arg;
438 ct2_entry_t *cto = &un._ctio2;
440 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
441 cto->ct_header.rqs_entry_count = 1;
442 cto->ct_iid = aep->at_iid;
443 if ((FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) == 0) {
444 cto->ct_lun = aep->at_lun;
446 cto->ct_rxid = aep->at_rxid;
447 cto->rsp.m1.ct_scsi_status = sts & 0xff;
448 cto->ct_flags = CT2_SENDSTATUS | CT2_NO_DATA | CT2_FLAG_MODE1;
450 cto->ct_flags |= CT2_CCINCR;
452 if (aep->at_datalen) {
453 cto->ct_resid = aep->at_datalen;
454 cto->rsp.m1.ct_scsi_status |= CT2_DATA_UNDER;
456 if ((sts & 0xff) == SCSI_CHECK && (sts & ECMD_SVALID)) {
457 cto->rsp.m1.ct_resp[0] = 0xf0;
458 cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
459 cto->rsp.m1.ct_resp[7] = 8;
460 cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff;
461 cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff;
462 cto->rsp.m1.ct_senselen = 16;
463 cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID;
465 cto->ct_syshandle = hdl;
467 at_entry_t *aep = arg;
468 ct_entry_t *cto = &un._ctio;
470 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
471 cto->ct_header.rqs_entry_count = 1;
472 cto->ct_fwhandle = aep->at_handle;
473 cto->ct_iid = aep->at_iid;
474 cto->ct_tgt = aep->at_tgt;
475 cto->ct_lun = aep->at_lun;
476 cto->ct_tag_type = aep->at_tag_type;
477 cto->ct_tag_val = aep->at_tag_val;
478 if (aep->at_flags & AT_TQAE) {
479 cto->ct_flags |= CT_TQAE;
481 cto->ct_flags = CT_SENDSTATUS | CT_NO_DATA;
483 cto->ct_flags |= CT_CCINCR;
485 cto->ct_scsi_status = sts;
486 cto->ct_syshandle = hdl;
488 return (isp_target_put_entry(isp, &un));
492 isp_target_async(struct ispsoftc *isp, int bus, int event)
499 * These three we handle here to propagate an effective bus reset
500 * upstream, but these do not require any immediate notify actions
501 * so we return when done.
504 case ASYNC_LIP_OCCURRED:
506 case ASYNC_LOOP_DOWN:
507 case ASYNC_LOOP_RESET:
510 * These don't require any immediate notify actions. We used
511 * treat them like SCSI Bus Resets, but that was just plain
512 * wrong. Let the normal CTIO completion report what occurred.
516 case ASYNC_BUS_RESET:
517 case ASYNC_TIMEOUT_RESET:
519 return (0); /* we'll be getting an inotify instead */
522 evt.ev_event = event;
523 (void) isp_async(isp, ISPASYNC_TARGET_EVENT, &evt);
525 case ASYNC_DEVICE_RESET:
527 * Bus Device Reset resets a specific target, so
528 * we pass this as a synthesized message.
530 MEMZERO(&msg, sizeof msg);
532 msg.nt_iid = FCPARAM(isp)->isp_loopid;
534 msg.nt_iid = SDPARAM(isp)->isp_initiator_id;
537 msg.nt_msg[0] = MSG_BUS_DEV_RESET;
538 (void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg);
541 isp_prt(isp, ISP_LOGERR,
542 "isp_target_async: unknown event 0x%x", event);
545 if (isp->isp_state == ISP_RUNSTATE)
546 isp_notify_ack(isp, NULL);
552 * Process a received message.
553 * The ISP firmware can handle most messages, there are only
554 * a few that we need to deal with:
555 * - abort: clean up the current command
556 * - abort tag and clear queue
560 isp_got_msg(struct ispsoftc *isp, int bus, in_entry_t *inp)
562 u_int8_t status = inp->in_status & ~QLTM_SVALID;
564 if (status == IN_IDE_RECEIVED || status == IN_MSG_RECEIVED) {
567 MEMZERO(&msg, sizeof (msg));
569 msg.nt_iid = inp->in_iid;
570 msg.nt_tgt = inp->in_tgt;
571 msg.nt_lun = inp->in_lun;
572 msg.nt_tagtype = inp->in_tag_type;
573 msg.nt_tagval = inp->in_tag_val;
574 MEMCPY(msg.nt_msg, inp->in_msg, IN_MSGLEN);
575 (void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg);
577 isp_prt(isp, ISP_LOGERR,
578 "unknown immediate notify status 0x%x", inp->in_status);
583 * Synthesize a message from the task management flags in a FCP_CMND_IU.
586 isp_got_msg_fc(struct ispsoftc *isp, int bus, in_fcentry_t *inp)
589 static const char f1[] = "%s from iid %d lun %d seq 0x%x";
590 static const char f2[] =
591 "unknown %s 0x%x lun %d iid %d task flags 0x%x seq 0x%x\n";
593 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
594 lun = inp->in_scclun;
599 if (inp->in_status != IN_MSG_RECEIVED) {
600 isp_prt(isp, ISP_LOGINFO, f2, "immediate notify status",
601 inp->in_status, lun, inp->in_iid,
602 inp->in_task_flags, inp->in_seqid);
606 MEMZERO(&msg, sizeof (msg));
608 msg.nt_iid = inp->in_iid;
609 msg.nt_tagval = inp->in_seqid;
612 if (inp->in_task_flags & TASK_FLAGS_ABORT_TASK) {
613 isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK",
614 inp->in_iid, msg.nt_lun, inp->in_seqid);
615 msg.nt_msg[0] = MSG_ABORT_TAG;
616 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_TASK_SET) {
617 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET",
618 inp->in_iid, msg.nt_lun, inp->in_seqid);
619 msg.nt_msg[0] = MSG_CLEAR_QUEUE;
620 } else if (inp->in_task_flags & TASK_FLAGS_TARGET_RESET) {
621 isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET",
622 inp->in_iid, msg.nt_lun, inp->in_seqid);
623 msg.nt_msg[0] = MSG_BUS_DEV_RESET;
624 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_ACA) {
625 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA",
626 inp->in_iid, msg.nt_lun, inp->in_seqid);
628 msg.nt_msg[0] = MSG_REL_RECOVERY;
629 } else if (inp->in_task_flags & TASK_FLAGS_TERMINATE_TASK) {
630 isp_prt(isp, ISP_LOGINFO, f1, "TERMINATE TASK",
631 inp->in_iid, msg.nt_lun, inp->in_seqid);
632 msg.nt_msg[0] = MSG_TERM_IO_PROC;
634 isp_prt(isp, ISP_LOGWARN, f2, "task flag",
635 inp->in_status, msg.nt_lun, inp->in_iid,
636 inp->in_task_flags, inp->in_seqid);
639 (void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg);
645 isp_notify_ack(struct ispsoftc *isp, void *arg)
647 char storage[QENTRY_LEN];
648 u_int16_t nxti, optr;
651 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
652 isp_prt(isp, ISP_LOGWARN,
653 "Request Queue Overflow For isp_notify_ack");
657 MEMZERO(storage, QENTRY_LEN);
660 na_fcentry_t *na = (na_fcentry_t *) storage;
662 in_fcentry_t *inp = arg;
663 MEMCPY(storage, arg, sizeof (isphdr_t));
664 na->na_iid = inp->in_iid;
665 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
666 na->na_lun = inp->in_scclun;
668 na->na_lun = inp->in_lun;
670 na->na_task_flags = inp->in_task_flags;
671 na->na_seqid = inp->in_seqid;
672 na->na_flags = NAFC_RCOUNT;
673 na->na_status = inp->in_status;
674 if (inp->in_status == IN_RESET) {
675 na->na_flags |= NAFC_RST_CLRD;
678 na->na_flags = NAFC_RST_CLRD;
680 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
681 na->na_header.rqs_entry_count = 1;
682 isp_put_notify_ack_fc(isp, na, (na_fcentry_t *)outp);
684 na_entry_t *na = (na_entry_t *) storage;
686 in_entry_t *inp = arg;
687 MEMCPY(storage, arg, sizeof (isphdr_t));
688 na->na_iid = inp->in_iid;
689 na->na_lun = inp->in_lun;
690 na->na_tgt = inp->in_tgt;
691 na->na_seqid = inp->in_seqid;
692 if (inp->in_status == IN_RESET) {
693 na->na_event = NA_RST_CLRD;
696 na->na_event = NA_RST_CLRD;
698 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
699 na->na_header.rqs_entry_count = 1;
700 isp_put_notify_ack(isp, na, (na_entry_t *)outp);
702 ISP_TDQE(isp, "isp_notify_ack", (int) optr, storage);
703 ISP_ADD_REQUEST(isp, nxti);
707 isp_handle_atio(struct ispsoftc *isp, at_entry_t *aep)
712 * The firmware status (except for the QLTM_SVALID bit) indicates
713 * why this ATIO was sent to us.
715 * If QLTM_SVALID is set, the firware has recommended Sense Data.
717 * If the DISCONNECTS DISABLED bit is set in the flags field,
718 * we're still connected on the SCSI bus - i.e. the initiator
719 * did not set DiscPriv in the identify message. We don't care
720 * about this so it's ignored.
723 switch(aep->at_status & ~QLTM_SVALID) {
724 case AT_PATH_INVALID:
726 * ATIO rejected by the firmware due to disabled lun.
728 isp_prt(isp, ISP_LOGERR,
729 "rejected ATIO for disabled lun %d", lun);
733 * Requested Capability not available
734 * We sent an ATIO that overflowed the firmware's
735 * command resource count.
737 isp_prt(isp, ISP_LOGERR,
738 "rejected ATIO for lun %d because of command count"
744 * If we send an ATIO to the firmware to increment
745 * its command resource count, and the firmware is
746 * recovering from a Bus Device Reset, it returns
747 * the ATIO with this status. We set the command
748 * resource count in the Enable Lun entry and do
749 * not increment it. Therefore we should never get
752 isp_prt(isp, ISP_LOGERR, atiocope, lun,
753 GET_BUS_VAL(aep->at_iid));
756 case AT_CDB: /* Got a CDB */
757 case AT_PHASE_ERROR: /* Bus Phase Sequence Error */
759 * Punt to platform specific layer.
761 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
766 * A bus reset came along an blew away this command. Why
767 * they do this in addition the async event code stuff,
770 * Ignore it because the async event will clear things
773 isp_prt(isp, ISP_LOGWARN, atior, lun,
774 GET_IID_VAL(aep->at_iid), GET_BUS_VAL(aep->at_iid));
779 isp_prt(isp, ISP_LOGERR,
780 "Unknown ATIO status 0x%x from initiator %d for lun %d",
781 aep->at_status, aep->at_iid, lun);
782 (void) isp_target_put_atio(isp, aep);
788 isp_handle_atio2(struct ispsoftc *isp, at2_entry_t *aep)
792 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
793 lun = aep->at_scclun;
799 * The firmware status (except for the QLTM_SVALID bit) indicates
800 * why this ATIO was sent to us.
802 * If QLTM_SVALID is set, the firware has recommended Sense Data.
804 * If the DISCONNECTS DISABLED bit is set in the flags field,
805 * we're still connected on the SCSI bus - i.e. the initiator
806 * did not set DiscPriv in the identify message. We don't care
807 * about this so it's ignored.
810 switch(aep->at_status & ~QLTM_SVALID) {
811 case AT_PATH_INVALID:
813 * ATIO rejected by the firmware due to disabled lun.
815 isp_prt(isp, ISP_LOGERR,
816 "rejected ATIO2 for disabled lun %d", lun);
820 * Requested Capability not available
821 * We sent an ATIO that overflowed the firmware's
822 * command resource count.
824 isp_prt(isp, ISP_LOGERR,
825 "rejected ATIO2 for lun %d- command count overflow", lun);
830 * If we send an ATIO to the firmware to increment
831 * its command resource count, and the firmware is
832 * recovering from a Bus Device Reset, it returns
833 * the ATIO with this status. We set the command
834 * resource count in the Enable Lun entry and no
835 * not increment it. Therefore we should never get
838 isp_prt(isp, ISP_LOGERR, atiocope, lun, 0);
841 case AT_CDB: /* Got a CDB */
843 * Punt to platform specific layer.
845 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
850 * A bus reset came along an blew away this command. Why
851 * they do this in addition the async event code stuff,
854 * Ignore it because the async event will clear things
857 isp_prt(isp, ISP_LOGERR, atior, lun, aep->at_iid, 0);
862 isp_prt(isp, ISP_LOGERR,
863 "Unknown ATIO2 status 0x%x from initiator %d for lun %d",
864 aep->at_status, aep->at_iid, lun);
865 (void) isp_target_put_atio(isp, aep);
871 isp_handle_ctio(struct ispsoftc *isp, ct_entry_t *ct)
874 int pl = ISP_LOGTDEBUG2;
877 if (ct->ct_syshandle) {
878 xs = isp_find_xs(isp, ct->ct_syshandle);
885 switch(ct->ct_status & ~QLTM_SVALID) {
888 * There are generally 3 possibilities as to why we'd get
890 * We disconnected after receiving a CDB.
891 * We sent or received data.
892 * We sent status & command complete.
895 if (ct->ct_flags & CT_SENDSTATUS) {
897 } else if ((ct->ct_flags & CT_DATAMASK) == CT_NO_DATA) {
899 * Nothing to do in this case.
901 isp_prt(isp, pl, "CTIO- iid %d disconnected OK",
909 * Bus Device Reset message received or the SCSI Bus has
910 * been Reset; the firmware has gone to Bus Free.
912 * The firmware generates an async mailbox interupt to
913 * notify us of this and returns outstanding CTIOs with this
914 * status. These CTIOs are handled in that same way as
915 * CT_ABORTED ones, so just fall through here.
917 fmsg = "Bus Device Reset";
925 * When an Abort message is received the firmware goes to
926 * Bus Free and returns all outstanding CTIOs with the status
927 * set, then sends us an Immediate Notify entry.
930 fmsg = "ABORT TAG message sent by Initiator";
932 isp_prt(isp, ISP_LOGWARN, "CTIO destroyed by %s", fmsg);
937 * CTIO rejected by the firmware due to disabled lun.
940 isp_prt(isp, ISP_LOGERR,
941 "Firmware rejected CTIO for disabled lun %d",
947 * CTIO rejected by the firmware due "no path for the
948 * nondisconnecting nexus specified". This means that
949 * we tried to access the bus while a non-disconnecting
950 * command is in process.
952 isp_prt(isp, ISP_LOGERR,
953 "Firmware rejected CTIO for bad nexus %d/%d/%d",
954 ct->ct_iid, ct->ct_tgt, ct->ct_lun);
958 fmsg = "Reselection";
963 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
968 fmsg = "Unrecoverable Error";
972 fmsg = "Completed with Error";
976 fmsg = "Phase Sequence Error";
980 fmsg = "terminated by TERMINATE TRANSFER";
984 fmsg = "unacknowledged Immediate Notify pending";
985 isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg);
988 isp_prt(isp, ISP_LOGERR, "Unknown CTIO status 0x%x",
989 ct->ct_status & ~QLTM_SVALID);
995 * There may be more than one CTIO for a data transfer,
996 * or this may be a status CTIO we're not monitoring.
998 * The assumption is that they'll all be returned in the
1001 if (ct->ct_syshandle == 0) {
1002 if ((ct->ct_flags & CT_SENDSTATUS) == 0) {
1004 "intermediate CTIO completed ok");
1007 "unmonitored CTIO completed ok");
1011 "NO xs for CTIO (handle 0x%x) status 0x%x",
1012 ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1016 * Final CTIO completed. Release DMA resources and
1017 * notify platform dependent layers.
1019 if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) {
1020 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1022 isp_prt(isp, pl, "final CTIO complete");
1024 * The platform layer will destroy the handle if appropriate.
1026 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1031 isp_handle_ctio2(struct ispsoftc *isp, ct2_entry_t *ct)
1034 int pl = ISP_LOGTDEBUG2;
1037 if (ct->ct_syshandle) {
1038 xs = isp_find_xs(isp, ct->ct_syshandle);
1045 switch(ct->ct_status & ~QLTM_SVALID) {
1047 isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error");
1053 * There are generally 2 possibilities as to why we'd get
1055 * We sent or received data.
1056 * We sent status & command complete.
1063 * Target Reset function received.
1065 * The firmware generates an async mailbox interupt to
1066 * notify us of this and returns outstanding CTIOs with this
1067 * status. These CTIOs are handled in that same way as
1068 * CT_ABORTED ones, so just fall through here.
1070 fmsg = "TARGET RESET Task Management Function Received";
1078 * When an Abort message is received the firmware goes to
1079 * Bus Free and returns all outstanding CTIOs with the status
1080 * set, then sends us an Immediate Notify entry.
1083 fmsg = "ABORT Task Management Function Received";
1085 isp_prt(isp, ISP_LOGERR, "CTIO2 destroyed by %s", fmsg);
1090 * CTIO rejected by the firmware - invalid data direction.
1092 isp_prt(isp, ISP_LOGERR, "CTIO2 had wrong data directiond");
1096 fmsg = "failure to reconnect to initiator";
1101 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
1105 fmsg = "Completed with Error";
1109 fmsg = "Port Logout";
1111 case CT_PORTNOTAVAIL:
1113 fmsg = "Port not available";
1114 case CT_PORTCHANGED:
1116 fmsg = "Port Changed";
1119 fmsg = "unacknowledged Immediate Notify pending";
1120 isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg);
1125 * CTIO rejected by the firmware because an invalid RX_ID.
1126 * Just print a message.
1128 isp_prt(isp, ISP_LOGERR,
1129 "CTIO2 completed with Invalid RX_ID 0x%x", ct->ct_rxid);
1133 isp_prt(isp, ISP_LOGERR, "Unknown CTIO2 status 0x%x",
1134 ct->ct_status & ~QLTM_SVALID);
1140 * There may be more than one CTIO for a data transfer,
1141 * or this may be a status CTIO we're not monitoring.
1143 * The assumption is that they'll all be returned in the
1144 * order we got them.
1146 if (ct->ct_syshandle == 0) {
1147 if ((ct->ct_flags & CT_SENDSTATUS) == 0) {
1149 "intermediate CTIO completed ok");
1152 "unmonitored CTIO completed ok");
1156 "NO xs for CTIO (handle 0x%x) status 0x%x",
1157 ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1160 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
1161 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1163 if (ct->ct_flags & CT_SENDSTATUS) {
1165 * Sent status and command complete.
1167 * We're now really done with this command, so we
1168 * punt to the platform dependent layers because
1169 * only there can we do the appropriate command
1170 * complete thread synchronization.
1172 isp_prt(isp, pl, "status CTIO complete");
1175 * Final CTIO completed. Release DMA resources and
1176 * notify platform dependent layers.
1178 isp_prt(isp, pl, "data CTIO complete");
1180 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1182 * The platform layer will destroy the handle if appropriate.