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);
164 isp_get_ctio2(isp, ct2iop, (ct2_entry_t *) local);
165 isp_handle_ctio2(isp, (ct2_entry_t *) local);
167 case RQSTYPE_ENABLE_LUN:
168 case RQSTYPE_MODIFY_LUN:
169 isp_get_enable_lun(isp, lunenp, (lun_entry_t *) local);
170 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, local);
175 * Either the ISP received a SCSI message it can't
176 * handle, or it's returning an Immed. Notify entry
177 * we sent. We can send Immed. Notify entries to
178 * increment the firmware's resource count for them
179 * (we set this initially in the Enable Lun entry).
183 isp_get_notify_fc(isp, inot_fcp, (in_fcentry_t *)local);
184 inot_fcp = (in_fcentry_t *) local;
185 status = inot_fcp->in_status;
186 seqid = inot_fcp->in_seqid;
188 isp_get_notify(isp, inotp, (in_entry_t *)local);
189 inotp = (in_entry_t *) local;
190 status = inotp->in_status & 0xff;
191 seqid = inotp->in_seqid;
192 if (IS_DUALBUS(isp)) {
193 bus = GET_BUS_VAL(inotp->in_iid);
194 SET_BUS_VAL(inotp->in_iid, 0);
197 isp_prt(isp, ISP_LOGTDEBUG0,
198 "Immediate Notify On Bus %d, status=0x%x seqid=0x%x",
204 isp_notify_ack(isp, (status == IN_RESET)? NULL : local);
207 (void) isp_async(isp, ISPASYNC_BUS_RESET, &bus);
209 case IN_MSG_RECEIVED:
210 case IN_IDE_RECEIVED:
212 isp_got_msg_fc(isp, bus, (in_fcentry_t *)local);
214 isp_got_msg(isp, bus, (in_entry_t *)local);
217 case IN_RSRC_UNAVAIL:
218 isp_prt(isp, ISP_LOGWARN, "Firmware out of ATIOs");
222 case IN_PORT_CHANGED:
224 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, &local);
227 isp_prt(isp, ISP_LOGERR,
228 "bad status (0x%x) in isp_target_notify", status);
233 case RQSTYPE_NOTIFY_ACK:
235 * The ISP is acknowledging our acknowledgement of an
236 * Immediate Notify entry for some asynchronous event.
239 isp_get_notify_ack_fc(isp, nack_fcp,
240 (na_fcentry_t *)local);
241 nack_fcp = (na_fcentry_t *)local;
242 isp_prt(isp, ISP_LOGTDEBUG1,
243 "Notify Ack status=0x%x seqid 0x%x",
244 nack_fcp->na_status, nack_fcp->na_seqid);
246 isp_get_notify_ack(isp, nackp, (na_entry_t *)local);
247 nackp = (na_entry_t *)local;
248 isp_prt(isp, ISP_LOGTDEBUG1,
249 "Notify Ack event 0x%x status=0x%x seqid 0x%x",
250 nackp->na_event, nackp->na_status, nackp->na_seqid);
254 isp_prt(isp, ISP_LOGERR,
255 "Unknown entry type 0x%x in isp_target_notify", type);
274 * Toggle (on/off) target mode for bus/target/lun
276 * The caller has checked for overlap and legality.
278 * Note that not all of bus, target or lun can be paid attention to.
279 * Note also that this action will not be complete until the f/w writes
280 * response entry. The caller is responsible for synchronizing this.
283 isp_lun_cmd(struct ispsoftc *isp, int cmd, int bus, int tgt, int lun,
284 int cmd_cnt, int inot_cnt, u_int32_t opaque)
287 u_int16_t nxti, optr;
291 MEMZERO(&el, sizeof (el));
292 if (IS_DUALBUS(isp)) {
293 el.le_rsvd = (bus & 0x1) << 7;
295 el.le_cmd_count = cmd_cnt;
296 el.le_in_count = inot_cnt;
297 if (cmd == RQSTYPE_ENABLE_LUN) {
299 el.le_flags = LUN_TQAE|LUN_DISAD;
303 } else if (cmd == -RQSTYPE_ENABLE_LUN) {
304 cmd = RQSTYPE_ENABLE_LUN;
307 } else if (cmd == -RQSTYPE_MODIFY_LUN) {
308 cmd = RQSTYPE_MODIFY_LUN;
309 el.le_ops = LUN_CCDECR | LUN_INDECR;
311 el.le_ops = LUN_CCINCR | LUN_ININCR;
313 el.le_header.rqs_entry_type = cmd;
314 el.le_header.rqs_entry_count = 1;
315 el.le_reserved = opaque;
319 } else if ((FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) == 0) {
324 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
325 isp_prt(isp, ISP_LOGERR,
326 "Request Queue Overflow in isp_lun_cmd");
329 ISP_TDQE(isp, "isp_lun_cmd", (int) optr, &el);
330 isp_put_enable_lun(isp, &el, outp);
331 ISP_ADD_REQUEST(isp, nxti);
337 isp_target_put_entry(struct ispsoftc *isp, void *ap)
340 u_int16_t nxti, optr;
341 u_int8_t etype = ((isphdr_t *) ap)->rqs_entry_type;
343 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
344 isp_prt(isp, ISP_LOGWARN,
345 "Request Queue Overflow in isp_target_put_entry");
350 isp_put_atio(isp, (at_entry_t *) ap, (at_entry_t *) outp);
353 isp_put_atio2(isp, (at2_entry_t *) ap, (at2_entry_t *) outp);
356 isp_put_ctio(isp, (ct_entry_t *) ap, (ct_entry_t *) outp);
359 isp_put_ctio2(isp, (ct2_entry_t *) ap, (ct2_entry_t *) outp);
362 isp_prt(isp, ISP_LOGERR,
363 "Unknown type 0x%x in isp_put_entry", etype);
367 ISP_TDQE(isp, "isp_target_put_entry", (int) optr, ap);
368 ISP_ADD_REQUEST(isp, nxti);
373 isp_target_put_atio(struct ispsoftc *isp, void *arg)
380 MEMZERO(&atun, sizeof atun);
382 at2_entry_t *aep = arg;
383 atun._atio2.at_header.rqs_entry_type = RQSTYPE_ATIO2;
384 atun._atio2.at_header.rqs_entry_count = 1;
385 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
386 atun._atio2.at_scclun = (u_int16_t) aep->at_scclun;
388 atun._atio2.at_lun = (u_int8_t) aep->at_lun;
390 atun._atio2.at_iid = aep->at_iid;
391 atun._atio2.at_rxid = aep->at_rxid;
392 atun._atio2.at_status = CT_OK;
394 at_entry_t *aep = arg;
395 atun._atio.at_header.rqs_entry_type = RQSTYPE_ATIO;
396 atun._atio.at_header.rqs_entry_count = 1;
397 atun._atio.at_handle = aep->at_handle;
398 atun._atio.at_iid = aep->at_iid;
399 atun._atio.at_tgt = aep->at_tgt;
400 atun._atio.at_lun = aep->at_lun;
401 atun._atio.at_tag_type = aep->at_tag_type;
402 atun._atio.at_tag_val = aep->at_tag_val;
403 atun._atio.at_status = (aep->at_flags & AT_TQAE);
404 atun._atio.at_status |= CT_OK;
406 return (isp_target_put_entry(isp, &atun));
410 * Command completion- both for handling cases of no resources or
411 * no blackhole driver, or other cases where we have to, inline,
412 * finish the command sanely, or for normal command completion.
414 * The 'completion' code value has the scsi status byte in the low 8 bits.
415 * If status is a CHECK CONDITION and bit 8 is nonzero, then bits 12..15 have
416 * the sense key and bits 16..23 have the ASCQ and bits 24..31 have the ASC
419 * NB: the key, asc, ascq, cannot be used for parallel SCSI as it doesn't
420 * NB: inline SCSI sense reporting. As such, we lose this information. XXX.
422 * For both parallel && fibre channel, we use the feature that does
423 * an automatic resource autoreplenish so we don't have then later do
424 * put of an atio to replenish the f/w's resource count.
428 isp_endcmd(struct ispsoftc *isp, void *arg, u_int32_t code, u_int16_t hdl)
436 MEMZERO(&un, sizeof un);
440 at2_entry_t *aep = arg;
441 ct2_entry_t *cto = &un._ctio2;
443 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO2;
444 cto->ct_header.rqs_entry_count = 1;
445 cto->ct_iid = aep->at_iid;
446 if ((FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) == 0) {
447 cto->ct_lun = aep->at_lun;
449 cto->ct_rxid = aep->at_rxid;
450 cto->rsp.m1.ct_scsi_status = sts;
451 cto->ct_flags = CT2_SENDSTATUS | CT2_NO_DATA | CT2_FLAG_MODE1;
453 cto->ct_flags |= CT2_CCINCR;
455 if (aep->at_datalen) {
456 cto->ct_resid = aep->at_datalen;
457 cto->rsp.m1.ct_scsi_status |= CT2_DATA_UNDER;
459 if (sts == SCSI_CHECK && (code & ECMD_SVALID)) {
460 cto->rsp.m1.ct_resp[0] = 0xf0;
461 cto->rsp.m1.ct_resp[2] = (code >> 12) & 0xf;
462 cto->rsp.m1.ct_resp[7] = 8;
463 cto->rsp.m1.ct_resp[12] = (code >> 24) & 0xff;
464 cto->rsp.m1.ct_resp[13] = (code >> 16) & 0xff;
465 cto->rsp.m1.ct_senselen = 16;
466 cto->rsp.m1.ct_scsi_status |= CT2_SNSLEN_VALID;
468 cto->ct_syshandle = hdl;
470 at_entry_t *aep = arg;
471 ct_entry_t *cto = &un._ctio;
473 cto->ct_header.rqs_entry_type = RQSTYPE_CTIO;
474 cto->ct_header.rqs_entry_count = 1;
475 cto->ct_fwhandle = aep->at_handle;
476 cto->ct_iid = aep->at_iid;
477 cto->ct_tgt = aep->at_tgt;
478 cto->ct_lun = aep->at_lun;
479 cto->ct_tag_type = aep->at_tag_type;
480 cto->ct_tag_val = aep->at_tag_val;
481 if (aep->at_flags & AT_TQAE) {
482 cto->ct_flags |= CT_TQAE;
484 cto->ct_flags = CT_SENDSTATUS | CT_NO_DATA;
486 cto->ct_flags |= CT_CCINCR;
488 cto->ct_scsi_status = sts;
489 cto->ct_syshandle = hdl;
491 return (isp_target_put_entry(isp, &un));
495 isp_target_async(struct ispsoftc *isp, int bus, int event)
502 * These three we handle here to propagate an effective bus reset
503 * upstream, but these do not require any immediate notify actions
504 * so we return when done.
507 case ASYNC_LIP_OCCURRED:
509 case ASYNC_LOOP_DOWN:
510 case ASYNC_LOOP_RESET:
513 * These don't require any immediate notify actions. We used
514 * treat them like SCSI Bus Resets, but that was just plain
515 * wrong. Let the normal CTIO completion report what occurred.
519 case ASYNC_BUS_RESET:
520 case ASYNC_TIMEOUT_RESET:
522 return (0); /* we'll be getting an inotify instead */
525 evt.ev_event = event;
526 (void) isp_async(isp, ISPASYNC_TARGET_EVENT, &evt);
528 case ASYNC_DEVICE_RESET:
530 * Bus Device Reset resets a specific target, so
531 * we pass this as a synthesized message.
533 MEMZERO(&msg, sizeof msg);
535 msg.nt_iid = FCPARAM(isp)->isp_loopid;
537 msg.nt_iid = SDPARAM(isp)->isp_initiator_id;
540 msg.nt_msg[0] = MSG_BUS_DEV_RESET;
541 (void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg);
543 case ASYNC_CTIO_DONE:
545 evt.ev_event = event;
546 (void) isp_async(isp, ISPASYNC_TARGET_EVENT, &evt);
549 isp_prt(isp, ISP_LOGERR,
550 "isp_target_async: unknown event 0x%x", event);
553 if (isp->isp_state == ISP_RUNSTATE)
554 isp_notify_ack(isp, NULL);
560 * Process a received message.
561 * The ISP firmware can handle most messages, there are only
562 * a few that we need to deal with:
563 * - abort: clean up the current command
564 * - abort tag and clear queue
568 isp_got_msg(struct ispsoftc *isp, int bus, in_entry_t *inp)
570 u_int8_t status = inp->in_status & ~QLTM_SVALID;
572 if (status == IN_IDE_RECEIVED || status == IN_MSG_RECEIVED) {
575 MEMZERO(&msg, sizeof (msg));
577 msg.nt_iid = inp->in_iid;
578 msg.nt_tgt = inp->in_tgt;
579 msg.nt_lun = inp->in_lun;
580 msg.nt_tagtype = inp->in_tag_type;
581 IN_MAKE_TAGID(msg.nt_tagval, 0, inp);
582 MEMCPY(msg.nt_msg, inp->in_msg, IN_MSGLEN);
583 (void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg);
585 isp_prt(isp, ISP_LOGERR,
586 "unknown immediate notify status 0x%x", inp->in_status);
591 * Synthesize a message from the task management flags in a FCP_CMND_IU.
594 isp_got_msg_fc(struct ispsoftc *isp, int bus, in_fcentry_t *inp)
597 static const char f1[] = "%s from iid %d lun %d seq 0x%x";
598 static const char f2[] =
599 "unknown %s 0x%x lun %d iid %d task flags 0x%x seq 0x%x\n";
601 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
602 lun = inp->in_scclun;
607 if (inp->in_status != IN_MSG_RECEIVED) {
608 isp_prt(isp, ISP_LOGINFO, f2, "immediate notify status",
609 inp->in_status, lun, inp->in_iid,
610 inp->in_task_flags, inp->in_seqid);
614 MEMZERO(&msg, sizeof (msg));
616 msg.nt_iid = inp->in_iid;
617 IN_FC_MAKE_TAGID(msg.nt_tagval, 0, inp);
620 if (inp->in_task_flags & TASK_FLAGS_ABORT_TASK_SET) {
621 isp_prt(isp, ISP_LOGINFO, f1, "ABORT TASK SET",
622 inp->in_iid, lun, inp->in_seqid);
623 msg.nt_msg[0] = MSG_ABORT;
624 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_TASK_SET) {
625 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR TASK SET",
626 inp->in_iid, lun, inp->in_seqid);
627 msg.nt_msg[0] = MSG_CLEAR_QUEUE;
628 } else if (inp->in_task_flags & TASK_FLAGS_LUN_RESET) {
629 isp_prt(isp, ISP_LOGINFO, f1, "LUN RESET",
630 inp->in_iid, lun, inp->in_seqid);
631 msg.nt_msg[0] = MSG_LUN_RESET;
632 } else if (inp->in_task_flags & TASK_FLAGS_TARGET_RESET) {
633 isp_prt(isp, ISP_LOGINFO, f1, "TARGET RESET",
634 inp->in_iid, lun, inp->in_seqid);
635 msg.nt_msg[0] = MSG_BUS_DEV_RESET;
636 } else if (inp->in_task_flags & TASK_FLAGS_CLEAR_ACA) {
637 isp_prt(isp, ISP_LOGINFO, f1, "CLEAR ACA",
638 inp->in_iid, lun, inp->in_seqid);
639 msg.nt_msg[0] = MSG_REL_RECOVERY;
641 isp_prt(isp, ISP_LOGWARN, f2, "task flag",
642 inp->in_status, lun, inp->in_iid,
643 inp->in_task_flags, inp->in_seqid);
646 (void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg);
652 isp_notify_ack(struct ispsoftc *isp, void *arg)
654 char storage[QENTRY_LEN];
655 u_int16_t nxti, optr;
658 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
659 isp_prt(isp, ISP_LOGWARN,
660 "Request Queue Overflow For isp_notify_ack");
664 MEMZERO(storage, QENTRY_LEN);
667 na_fcentry_t *na = (na_fcentry_t *) storage;
669 in_fcentry_t *inp = arg;
670 MEMCPY(storage, arg, sizeof (isphdr_t));
671 na->na_iid = inp->in_iid;
672 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
673 na->na_lun = inp->in_scclun;
675 na->na_lun = inp->in_lun;
677 na->na_task_flags = inp->in_task_flags;
678 na->na_seqid = inp->in_seqid;
679 na->na_flags = NAFC_RCOUNT;
680 na->na_status = inp->in_status;
681 if (inp->in_status == IN_RESET) {
682 na->na_flags |= NAFC_RST_CLRD;
685 na->na_flags = NAFC_RST_CLRD;
687 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
688 na->na_header.rqs_entry_count = 1;
689 isp_put_notify_ack_fc(isp, na, (na_fcentry_t *)outp);
691 na_entry_t *na = (na_entry_t *) storage;
693 in_entry_t *inp = arg;
694 MEMCPY(storage, arg, sizeof (isphdr_t));
695 na->na_iid = inp->in_iid;
696 na->na_lun = inp->in_lun;
697 na->na_tgt = inp->in_tgt;
698 na->na_seqid = inp->in_seqid;
699 if (inp->in_status == IN_RESET) {
700 na->na_event = NA_RST_CLRD;
703 na->na_event = NA_RST_CLRD;
705 na->na_header.rqs_entry_type = RQSTYPE_NOTIFY_ACK;
706 na->na_header.rqs_entry_count = 1;
707 isp_put_notify_ack(isp, na, (na_entry_t *)outp);
709 ISP_TDQE(isp, "isp_notify_ack", (int) optr, storage);
710 ISP_ADD_REQUEST(isp, nxti);
714 isp_handle_atio(struct ispsoftc *isp, at_entry_t *aep)
719 * The firmware status (except for the QLTM_SVALID bit) indicates
720 * why this ATIO was sent to us.
722 * If QLTM_SVALID is set, the firware has recommended Sense Data.
724 * If the DISCONNECTS DISABLED bit is set in the flags field,
725 * we're still connected on the SCSI bus - i.e. the initiator
726 * did not set DiscPriv in the identify message. We don't care
727 * about this so it's ignored.
730 switch(aep->at_status & ~QLTM_SVALID) {
731 case AT_PATH_INVALID:
733 * ATIO rejected by the firmware due to disabled lun.
735 isp_prt(isp, ISP_LOGERR,
736 "rejected ATIO for disabled lun %d", lun);
740 * Requested Capability not available
741 * We sent an ATIO that overflowed the firmware's
742 * command resource count.
744 isp_prt(isp, ISP_LOGERR,
745 "rejected ATIO for lun %d because of command count"
751 * If we send an ATIO to the firmware to increment
752 * its command resource count, and the firmware is
753 * recovering from a Bus Device Reset, it returns
754 * the ATIO with this status. We set the command
755 * resource count in the Enable Lun entry and do
756 * not increment it. Therefore we should never get
759 isp_prt(isp, ISP_LOGERR, atiocope, lun,
760 GET_BUS_VAL(aep->at_iid));
763 case AT_CDB: /* Got a CDB */
764 case AT_PHASE_ERROR: /* Bus Phase Sequence Error */
766 * Punt to platform specific layer.
768 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
773 * A bus reset came along and blew away this command. Why
774 * they do this in addition the async event code stuff,
777 * Ignore it because the async event will clear things
780 isp_prt(isp, ISP_LOGWARN, atior, lun,
781 GET_IID_VAL(aep->at_iid), GET_BUS_VAL(aep->at_iid));
786 isp_prt(isp, ISP_LOGERR,
787 "Unknown ATIO status 0x%x from initiator %d for lun %d",
788 aep->at_status, aep->at_iid, lun);
789 (void) isp_target_put_atio(isp, aep);
795 isp_handle_atio2(struct ispsoftc *isp, at2_entry_t *aep)
799 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
800 lun = aep->at_scclun;
806 * The firmware status (except for the QLTM_SVALID bit) indicates
807 * why this ATIO was sent to us.
809 * If QLTM_SVALID is set, the firware has recommended Sense Data.
811 * If the DISCONNECTS DISABLED bit is set in the flags field,
812 * we're still connected on the SCSI bus - i.e. the initiator
813 * did not set DiscPriv in the identify message. We don't care
814 * about this so it's ignored.
817 switch(aep->at_status & ~QLTM_SVALID) {
818 case AT_PATH_INVALID:
820 * ATIO rejected by the firmware due to disabled lun.
822 isp_prt(isp, ISP_LOGERR,
823 "rejected ATIO2 for disabled lun %d", lun);
827 * Requested Capability not available
828 * We sent an ATIO that overflowed the firmware's
829 * command resource count.
831 isp_prt(isp, ISP_LOGERR,
832 "rejected ATIO2 for lun %d- command count overflow", lun);
837 * If we send an ATIO to the firmware to increment
838 * its command resource count, and the firmware is
839 * recovering from a Bus Device Reset, it returns
840 * the ATIO with this status. We set the command
841 * resource count in the Enable Lun entry and no
842 * not increment it. Therefore we should never get
845 isp_prt(isp, ISP_LOGERR, atiocope, lun, 0);
848 case AT_CDB: /* Got a CDB */
850 * Punt to platform specific layer.
852 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, aep);
857 * A bus reset came along an blew away this command. Why
858 * they do this in addition the async event code stuff,
861 * Ignore it because the async event will clear things
864 isp_prt(isp, ISP_LOGERR, atior, lun, aep->at_iid, 0);
869 isp_prt(isp, ISP_LOGERR,
870 "Unknown ATIO2 status 0x%x from initiator %d for lun %d",
871 aep->at_status, aep->at_iid, lun);
872 (void) isp_target_put_atio(isp, aep);
878 isp_handle_ctio(struct ispsoftc *isp, ct_entry_t *ct)
881 int pl = ISP_LOGTDEBUG2;
884 if (ct->ct_syshandle) {
885 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
892 switch(ct->ct_status & ~QLTM_SVALID) {
895 * There are generally 3 possibilities as to why we'd get
897 * We disconnected after receiving a CDB.
898 * We sent or received data.
899 * We sent status & command complete.
902 if (ct->ct_flags & CT_SENDSTATUS) {
904 } else if ((ct->ct_flags & CT_DATAMASK) == CT_NO_DATA) {
906 * Nothing to do in this case.
908 isp_prt(isp, pl, "CTIO- iid %d disconnected OK",
916 * Bus Device Reset message received or the SCSI Bus has
917 * been Reset; the firmware has gone to Bus Free.
919 * The firmware generates an async mailbox interupt to
920 * notify us of this and returns outstanding CTIOs with this
921 * status. These CTIOs are handled in that same way as
922 * CT_ABORTED ones, so just fall through here.
924 fmsg = "Bus Device Reset";
932 * When an Abort message is received the firmware goes to
933 * Bus Free and returns all outstanding CTIOs with the status
934 * set, then sends us an Immediate Notify entry.
937 fmsg = "ABORT TAG message sent by Initiator";
939 isp_prt(isp, ISP_LOGWARN, "CTIO destroyed by %s", fmsg);
944 * CTIO rejected by the firmware due to disabled lun.
947 isp_prt(isp, ISP_LOGERR,
948 "Firmware rejected CTIO for disabled lun %d",
954 * CTIO rejected by the firmware due "no path for the
955 * nondisconnecting nexus specified". This means that
956 * we tried to access the bus while a non-disconnecting
957 * command is in process.
959 isp_prt(isp, ISP_LOGERR,
960 "Firmware rejected CTIO for bad nexus %d/%d/%d",
961 ct->ct_iid, ct->ct_tgt, ct->ct_lun);
965 fmsg = "Reselection";
970 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
975 fmsg = "Unrecoverable Error";
979 fmsg = "Completed with Error";
983 fmsg = "Phase Sequence Error";
987 fmsg = "terminated by TERMINATE TRANSFER";
991 fmsg = "unacknowledged Immediate Notify pending";
992 isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg);
995 isp_prt(isp, ISP_LOGERR, "Unknown CTIO status 0x%x",
996 ct->ct_status & ~QLTM_SVALID);
1002 * There may be more than one CTIO for a data transfer,
1003 * or this may be a status CTIO we're not monitoring.
1005 * The assumption is that they'll all be returned in the
1006 * order we got them.
1008 if (ct->ct_syshandle == 0) {
1009 if ((ct->ct_flags & CT_SENDSTATUS) == 0) {
1011 "intermediate CTIO completed ok");
1014 "unmonitored CTIO completed ok");
1018 "NO xs for CTIO (handle 0x%x) status 0x%x",
1019 ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1023 * Final CTIO completed. Release DMA resources and
1024 * notify platform dependent layers.
1026 if ((ct->ct_flags & CT_DATAMASK) != CT_NO_DATA) {
1027 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1029 isp_prt(isp, pl, "final CTIO complete");
1031 * The platform layer will destroy the handle if appropriate.
1033 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1038 isp_handle_ctio2(struct ispsoftc *isp, ct2_entry_t *ct)
1041 int pl = ISP_LOGTDEBUG2;
1044 if (ct->ct_syshandle) {
1045 xs = isp_find_xs_tgt(isp, ct->ct_syshandle);
1052 switch(ct->ct_status & ~QLTM_SVALID) {
1054 isp_prt(isp, ISP_LOGERR, "PCI DMA Bus Error");
1060 * There are generally 2 possibilities as to why we'd get
1062 * We sent or received data.
1063 * We sent status & command complete.
1070 * Target Reset function received.
1072 * The firmware generates an async mailbox interupt to
1073 * notify us of this and returns outstanding CTIOs with this
1074 * status. These CTIOs are handled in that same way as
1075 * CT_ABORTED ones, so just fall through here.
1077 fmsg = "TARGET RESET Task Management Function Received";
1085 * When an Abort message is received the firmware goes to
1086 * Bus Free and returns all outstanding CTIOs with the status
1087 * set, then sends us an Immediate Notify entry.
1090 fmsg = "ABORT Task Management Function Received";
1092 isp_prt(isp, ISP_LOGERR, "CTIO2 destroyed by %s", fmsg);
1097 * CTIO rejected by the firmware - invalid data direction.
1099 isp_prt(isp, ISP_LOGERR, "CTIO2 had wrong data direction");
1103 fmsg = "failure to reconnect to initiator";
1108 isp_prt(isp, ISP_LOGERR, "Firmware timed out on %s", fmsg);
1112 fmsg = "Completed with Error";
1116 fmsg = "Port Logout";
1118 case CT_PORTNOTAVAIL:
1120 fmsg = "Port not available";
1122 case CT_PORTCHANGED:
1124 fmsg = "Port Changed";
1128 fmsg = "unacknowledged Immediate Notify pending";
1129 isp_prt(isp, ISP_LOGERR, "CTIO returned by f/w- %s", fmsg);
1134 * CTIO rejected by the firmware because an invalid RX_ID.
1135 * Just print a message.
1137 isp_prt(isp, ISP_LOGERR,
1138 "CTIO2 completed with Invalid RX_ID 0x%x", ct->ct_rxid);
1142 isp_prt(isp, ISP_LOGERR, "Unknown CTIO2 status 0x%x",
1143 ct->ct_status & ~QLTM_SVALID);
1149 * There may be more than one CTIO for a data transfer,
1150 * or this may be a status CTIO we're not monitoring.
1152 * The assumption is that they'll all be returned in the
1153 * order we got them.
1155 if (ct->ct_syshandle == 0) {
1156 if ((ct->ct_flags & CT2_SENDSTATUS) == 0) {
1158 "intermediate CTIO completed ok");
1161 "unmonitored CTIO completed ok");
1165 "NO xs for CTIO (handle 0x%x) status 0x%x",
1166 ct->ct_syshandle, ct->ct_status & ~QLTM_SVALID);
1169 if ((ct->ct_flags & CT2_DATAMASK) != CT2_NO_DATA) {
1170 ISP_DMAFREE(isp, xs, ct->ct_syshandle);
1172 if (ct->ct_flags & CT2_SENDSTATUS) {
1174 * Sent status and command complete.
1176 * We're now really done with this command, so we
1177 * punt to the platform dependent layers because
1178 * only there can we do the appropriate command
1179 * complete thread synchronization.
1181 isp_prt(isp, pl, "status CTIO complete");
1184 * Final CTIO completed. Release DMA resources and
1185 * notify platform dependent layers.
1187 isp_prt(isp, pl, "data CTIO complete");
1189 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, ct);
1191 * The platform layer will destroy the handle if appropriate.