Deleted Added
sdiff udiff text old ( 140651 ) new ( 154704 )
full compact
1/* $FreeBSD: head/sys/dev/isp/isp_target.c 140651 2005-01-23 06:28:08Z mjacob $ */
2/*-
3 * Machine and OS Independent Target Mode Code for the Qlogic SCSI/FC adapters.
4 *
5 * Copyright (c) 1999, 2000, 2001 by Matthew Jacob
6 * All rights reserved.
7 * mjacob@feral.com
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
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

--- 19 unchanged lines hidden (view full) ---

35/*
36 * Include header file appropriate for platform we're building on.
37 */
38
39#ifdef __NetBSD__
40#include <dev/ic/isp_netbsd.h>
41#endif
42#ifdef __FreeBSD__
43#include <dev/isp/isp_freebsd.h>
44#endif
45#ifdef __OpenBSD__
46#include <dev/ic/isp_openbsd.h>
47#endif
48#ifdef __linux__
49#include "isp_linux.h"
50#endif
51
52#ifdef ISP_TARGET_MODE
53static const char atiocope[] =
54 "ATIO returned for lun %d because it was in the middle of Bus Device Reset "
55 "on bus %d";
56static const char atior[] =
57 "ATIO returned on for lun %d on from IID %d because a Bus Reset occurred "
58 "on bus %d";
59
60static void isp_got_msg(struct ispsoftc *, int, in_entry_t *);
61static void isp_got_msg_fc(struct ispsoftc *, int, in_fcentry_t *);
62static void isp_notify_ack(struct ispsoftc *, void *);
63static void isp_handle_atio(struct ispsoftc *, at_entry_t *);
64static void isp_handle_atio2(struct ispsoftc *, at2_entry_t *);
65static void isp_handle_ctio(struct ispsoftc *, ct_entry_t *);
66static void isp_handle_ctio2(struct ispsoftc *, ct2_entry_t *);
67
68/*
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

--- 42 unchanged lines hidden (view full) ---

113
114int
115isp_target_notify(struct ispsoftc *isp, void *vptr, u_int16_t *optrp)
116{
117 u_int16_t status, seqid;
118 union {
119 at_entry_t *atiop;
120 at2_entry_t *at2iop;
121 ct_entry_t *ctiop;
122 ct2_entry_t *ct2iop;
123 lun_entry_t *lunenp;
124 in_entry_t *inotp;
125 in_fcentry_t *inot_fcp;
126 na_entry_t *nackp;
127 na_fcentry_t *nack_fcp;
128 isphdr_t *hp;
129 void * *vp;
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
139#define hdrp unp.hp
140 } unp;
141 u_int8_t local[QENTRY_LEN];
142 int bus, type, rval = 1;
143
144 type = isp_get_response_type(isp, (isphdr_t *)vptr);
145 unp.vp = vptr;
146

--- 4 unchanged lines hidden (view full) ---

151 isp_get_atio(isp, atiop, (at_entry_t *) local);
152 isp_handle_atio(isp, (at_entry_t *) local);
153 break;
154 case RQSTYPE_CTIO:
155 isp_get_ctio(isp, ctiop, (ct_entry_t *) local);
156 isp_handle_ctio(isp, (ct_entry_t *) local);
157 break;
158 case RQSTYPE_ATIO2:
159 isp_get_atio2(isp, at2iop, (at2_entry_t *) local);
160 isp_handle_atio2(isp, (at2_entry_t *) local);
161 break;
162 case RQSTYPE_CTIO3:
163 case RQSTYPE_CTIO2:
164 isp_get_ctio2(isp, ct2iop, (ct2_entry_t *) local);
165 isp_handle_ctio2(isp, (ct2_entry_t *) local);
166 break;
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);
171 break;
172
173 case RQSTYPE_NOTIFY:
174 /*
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).
180 */
181 bus = 0;
182 if (IS_FC(isp)) {
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;
187 } else {
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);
195 }
196 }
197 isp_prt(isp, ISP_LOGTDEBUG0,
198 "Immediate Notify On Bus %d, status=0x%x seqid=0x%x",
199 bus, status, seqid);
200
201 /*
202 * ACK it right away.
203 */
204 isp_notify_ack(isp, (status == IN_RESET)? NULL : local);
205 switch (status) {
206 case IN_RESET:
207 (void) isp_async(isp, ISPASYNC_BUS_RESET, &bus);
208 break;
209 case IN_MSG_RECEIVED:
210 case IN_IDE_RECEIVED:
211 if (IS_FC(isp)) {
212 isp_got_msg_fc(isp, bus, (in_fcentry_t *)local);
213 } else {
214 isp_got_msg(isp, bus, (in_entry_t *)local);
215 }
216 break;
217 case IN_RSRC_UNAVAIL:
218 isp_prt(isp, ISP_LOGWARN, "Firmware out of ATIOs");
219 break;
220 case IN_PORT_LOGOUT:
221 case IN_ABORT_TASK:
222 case IN_PORT_CHANGED:
223 case IN_GLOBAL_LOGO:
224 (void) isp_async(isp, ISPASYNC_TARGET_ACTION, &local);
225 break;
226 default:
227 isp_prt(isp, ISP_LOGERR,
228 "bad status (0x%x) in isp_target_notify", status);
229 break;
230 }
231 break;
232
233 case RQSTYPE_NOTIFY_ACK:
234 /*
235 * The ISP is acknowledging our acknowledgement of an
236 * Immediate Notify entry for some asynchronous event.
237 */
238 if (IS_FC(isp)) {
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);
245 } else {
246 isp_get_notify_ack(isp, nackp, (na_entry_t *)local);
247 nackp = (na_entry_t *)local;
248 isp_prt(isp, ISP_LOGTDEBUG1,

--- 4 unchanged lines hidden (view full) ---

253 default:
254 isp_prt(isp, ISP_LOGERR,
255 "Unknown entry type 0x%x in isp_target_notify", type);
256 rval = 0;
257 break;
258 }
259#undef atiop
260#undef at2iop
261#undef ctiop
262#undef ct2iop
263#undef lunenp
264#undef inotp
265#undef inot_fcp
266#undef nackp
267#undef nack_fcp
268#undef hdrp
269 return (rval);
270}
271
272
273/*
274 * Toggle (on/off) target mode for bus/target/lun
275 *

--- 94 unchanged lines hidden (view full) ---

370}
371
372int
373isp_target_put_atio(struct ispsoftc *isp, void *arg)
374{
375 union {
376 at_entry_t _atio;
377 at2_entry_t _atio2;
378 } atun;
379
380 MEMZERO(&atun, sizeof atun);
381 if (IS_FC(isp)) {
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;
387 } else {
388 atun._atio2.at_lun = (u_int8_t) aep->at_lun;
389 }
390 atun._atio2.at_iid = aep->at_iid;
391 atun._atio2.at_rxid = aep->at_rxid;
392 atun._atio2.at_status = CT_OK;
393 } else {
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;

--- 27 unchanged lines hidden (view full) ---

426
427int
428isp_endcmd(struct ispsoftc *isp, void *arg, u_int32_t code, u_int16_t hdl)
429{
430 int sts;
431 union {
432 ct_entry_t _ctio;
433 ct2_entry_t _ctio2;
434 } un;
435
436 MEMZERO(&un, sizeof un);
437 sts = code & 0xff;
438
439 if (IS_FC(isp)) {
440 at2_entry_t *aep = arg;
441 ct2_entry_t *cto = &un._ctio2;
442
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;
448 }
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;
452 if (hdl == 0) {
453 cto->ct_flags |= CT2_CCINCR;
454 }
455 if (aep->at_datalen) {
456 cto->ct_resid = aep->at_datalen;

--- 32 unchanged lines hidden (view full) ---

489 cto->ct_syshandle = hdl;
490 }
491 return (isp_target_put_entry(isp, &un));
492}
493
494int
495isp_target_async(struct ispsoftc *isp, int bus, int event)
496{
497 tmd_event_t evt;
498 tmd_msg_t msg;
499
500 switch (event) {
501 /*
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.
505 */
506 case ASYNC_LIP_F8:
507 case ASYNC_LIP_OCCURRED:
508 case ASYNC_LOOP_UP:
509 case ASYNC_LOOP_DOWN:
510 case ASYNC_LOOP_RESET:
511 case ASYNC_PTPMODE:
512 /*
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.
516 */
517 return (0);
518
519 case ASYNC_BUS_RESET:
520 case ASYNC_TIMEOUT_RESET:
521 if (IS_FC(isp)) {
522 return (0); /* we'll be getting an inotify instead */
523 }
524 evt.ev_bus = bus;
525 evt.ev_event = event;
526 (void) isp_async(isp, ISPASYNC_TARGET_EVENT, &evt);
527 break;
528 case ASYNC_DEVICE_RESET:
529 /*
530 * Bus Device Reset resets a specific target, so
531 * we pass this as a synthesized message.
532 */
533 MEMZERO(&msg, sizeof msg);
534 if (IS_FC(isp)) {
535 msg.nt_iid = FCPARAM(isp)->isp_loopid;
536 } else {
537 msg.nt_iid = SDPARAM(isp)->isp_initiator_id;
538 }
539 msg.nt_bus = bus;
540 msg.nt_msg[0] = MSG_BUS_DEV_RESET;
541 (void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg);
542 break;
543 case ASYNC_CTIO_DONE:
544 evt.ev_bus = bus;
545 evt.ev_event = event;
546 (void) isp_async(isp, ISPASYNC_TARGET_EVENT, &evt);
547 return (0);
548 default:
549 isp_prt(isp, ISP_LOGERR,
550 "isp_target_async: unknown event 0x%x", event);
551 break;
552 }
553 if (isp->isp_state == ISP_RUNSTATE)
554 isp_notify_ack(isp, NULL);
555 return(0);
556}
557
558
559/*
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
565 */
566
567static void
568isp_got_msg(struct ispsoftc *isp, int bus, in_entry_t *inp)
569{
570 u_int8_t status = inp->in_status & ~QLTM_SVALID;
571
572 if (status == IN_IDE_RECEIVED || status == IN_MSG_RECEIVED) {
573 tmd_msg_t msg;
574
575 MEMZERO(&msg, sizeof (msg));
576 msg.nt_bus = bus;
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);
584 } else {
585 isp_prt(isp, ISP_LOGERR,
586 "unknown immediate notify status 0x%x", inp->in_status);
587 }
588}
589
590/*
591 * Synthesize a message from the task management flags in a FCP_CMND_IU.
592 */
593static void
594isp_got_msg_fc(struct ispsoftc *isp, int bus, in_fcentry_t *inp)
595{
596 int lun;
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";
600
601 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
602 lun = inp->in_scclun;
603 } else {
604 lun = inp->in_lun;
605 }
606
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);
611 } else {
612 tmd_msg_t msg;
613
614 MEMZERO(&msg, sizeof (msg));
615 msg.nt_bus = bus;
616 msg.nt_iid = inp->in_iid;
617 IN_FC_MAKE_TAGID(msg.nt_tagval, 0, inp);
618 msg.nt_lun = lun;
619
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;
640 } else {
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);
644 }
645 if (msg.nt_msg[0]) {
646 (void) isp_async(isp, ISPASYNC_TARGET_MESSAGE, &msg);
647 }
648 }
649}
650
651static void
652isp_notify_ack(struct ispsoftc *isp, void *arg)
653{
654 char storage[QENTRY_LEN];
655 u_int16_t nxti, optr;
656 void *outp;
657
658 if (isp_getrqentry(isp, &nxti, &optr, &outp)) {
659 isp_prt(isp, ISP_LOGWARN,
660 "Request Queue Overflow For isp_notify_ack");
661 return;
662 }
663
664 MEMZERO(storage, QENTRY_LEN);
665
666 if (IS_FC(isp)) {
667 na_fcentry_t *na = (na_fcentry_t *) storage;
668 if (arg) {
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;
674 } else {
675 na->na_lun = inp->in_lun;
676 }
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;
683 }
684 } else {
685 na->na_flags = NAFC_RST_CLRD;
686 }
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);
690 } else {
691 na_entry_t *na = (na_entry_t *) storage;
692 if (arg) {
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;

--- 91 unchanged lines hidden (view full) ---

789 (void) isp_target_put_atio(isp, aep);
790 break;
791 }
792}
793
794static void
795isp_handle_atio2(struct ispsoftc *isp, at2_entry_t *aep)
796{
797 int lun;
798
799 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
800 lun = aep->at_scclun;
801 } else {
802 lun = aep->at_lun;
803 }
804
805 /*
806 * The firmware status (except for the QLTM_SVALID bit) indicates
807 * why this ATIO was sent to us.
808 *
809 * If QLTM_SVALID is set, the firware has recommended Sense Data.
810 *
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

--- 43 unchanged lines hidden (view full) ---

856 /*
857 * A bus reset came along an blew away this command. Why
858 * they do this in addition the async event code stuff,
859 * I dunno.
860 *
861 * Ignore it because the async event will clear things
862 * up for us.
863 */
864 isp_prt(isp, ISP_LOGERR, atior, lun, aep->at_iid, 0);
865 break;
866
867
868 default:
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);
873 break;
874 }
875}
876
877static void
878isp_handle_ctio(struct ispsoftc *isp, ct_entry_t *ct)
879{

--- 316 unchanged lines hidden ---