Deleted Added
sdiff udiff text old ( 64095 ) new ( 65140 )
full compact
1/* $FreeBSD: head/sys/dev/isp/isp.c 64095 2000-08-01 06:51:05Z mjacob $ */
2/*
3 * Machine and OS Independent (well, as best as possible)
4 * code for the Qlogic ISP SCSI adapters.
5 *
6 * Copyright (c) 1997, 1998, 1999 by Matthew Jacob
7 * NASA/Ames Research Center
8 * All rights reserved.
9 *

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

590 */
591 mbs.param[0] = MBOX_VERIFY_CHECKSUM;
592 mbs.param[1] = ISP_CODE_ORG;
593 isp_mboxcmd(isp, &mbs, MBLOGNONE);
594 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
595 isp_prt(isp, ISP_LOGERR, "Ram Checksum Failure");
596 return;
597 }
598 } else {
599 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
600 }
601
602 /*
603 * Now start it rolling.
604 *
605 * If we didn't actually download f/w,
606 * we still need to (re)start it.

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

745 sdp_chan1++;
746 }
747
748 /* First do overall per-card settings. */
749
750 /*
751 * If we have fast memory timing enabled, turn it on.
752 */
753 if (isp->isp_fast_mttr) {
754 ISP_WRITE(isp, RISC_MTR, 0x1313);
755 }
756
757 /*
758 * Set Retry Delay and Count.
759 * You set both channels at the same time.
760 */
761 mbs.param[0] = MBOX_SET_RETRY_COUNT;

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

918 */
919 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
920 int lun;
921 u_int16_t sdf;
922
923 if (sdp->isp_devparam[tgt].dev_enable == 0) {
924 continue;
925 }
926
927 /*
928 * If we're in LVD mode, then we pretty much should
929 * only disable tagged queuing.
930 */
931 if (IS_ULTRA2(isp) && sdp->isp_lvdmode) {
932 sdf = DPARM_DEFAULT & ~DPARM_TQING;
933 } else {
934 int rvf = ISP_FW_REVX(isp->isp_fwrev);
935 sdf = DPARM_SAFE_DFLT;
936
937 /*
938 * It is not quite clear when this changed over so that
939 * we could force narrow and async, so assume >= 7.55
940 * for i/t F/W and = 4.55 for initiator f/w.
941 */
942 if ((ISP_FW_REV(4, 55, 0) <= rvf &&
943 (ISP_FW_REV(5, 0, 0) > rvf)) ||
944 (ISP_FW_REV(7, 55, 0) <= rvf)) {
945 sdf |= DPARM_NARROW | DPARM_ASYNC;
946 }
947 }
948 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
949 mbs.param[1] = (tgt << 8) | (channel << 15);
950 mbs.param[2] = sdf;
951 mbs.param[3] =
952 (sdp->isp_devparam[tgt].sync_offset << 8) |
953 (sdp->isp_devparam[tgt].sync_period);
954 isp_mboxcmd(isp, &mbs, MBLOGALL);
955 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
956 sdf = DPARM_SAFE_DFLT;
957 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
958 mbs.param[1] = (tgt << 8) | (channel << 15);
959 mbs.param[2] = sdf;
960 mbs.param[3] =
961 (sdp->isp_devparam[tgt].sync_offset << 8) |
962 (sdp->isp_devparam[tgt].sync_period);
963 isp_mboxcmd(isp, &mbs, MBLOGALL);
964 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
965 continue;
966 }
967 }
968#if 0
969 /*
970 * We don't update dev_flags with what we've set
971 * because that's not the ultimate goal setting.
972 * If we succeed with the command, we *do* update
973 * cur_dflags by getting target parameters.
974 */
975 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
976 mbs.param[1] = (tgt << 8) | (channel << 15);
977 isp_mboxcmd(isp, &mbs, MBLOGALL);
978 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
979 /*
980 * Urrr.... We'll set cur_dflags to DPARM_SAFE_DFLT so
981 * we don't try and do tags if tags aren't enabled.
982 */
983 sdp->isp_devparam[tgt].cur_dflags = DPARM_SAFE_DFLT;
984 } else {
985 sdp->isp_devparam[tgt].cur_dflags = mbs.param[2];
986 sdp->isp_devparam[tgt].cur_offset = mbs.param[3] >> 8;
987 sdp->isp_devparam[tgt].cur_period = mbs.param[3] & 0xff;
988 }
989 isp_prt(isp, ISP_LOGTDEBUG0,
990 "set flags 0x%x got 0x%x back for target %d",
991 sdf, mbs.param[2], tgt);
992
993#else
994 /*
995 * We don't update any information because we need to run
996 * at least one command per target to cause a new state
997 * to be latched.
998 */
999#endif
1000 /*
1001 * Ensure that we don't believe tagged queuing is enabled yet.
1002 * It turns out that sometimes the ISP just ignores our
1003 * attempts to set parameters for devices that it hasn't
1004 * seen yet.
1005 */
1006 sdp->isp_devparam[tgt].cur_dflags &= ~DPARM_TQING;
1007 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1008 mbs.param[0] = MBOX_SET_DEV_QUEUE_PARAMS;
1009 mbs.param[1] = (channel << 15) | (tgt << 8) | lun;
1010 mbs.param[2] = sdp->isp_max_queue_depth;
1011 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1012 isp_mboxcmd(isp, &mbs, MBLOGALL);
1013 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1014 break;
1015 }
1016 }
1017 }
1018}
1019
1020/*
1021 * Fibre Channel specific initialization.
1022 *
1023 * Locks are held before coming here.
1024 */
1025static void

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

1033
1034 fcp = isp->isp_param;
1035
1036 loopid = DEFAULT_LOOPID(isp);
1037 icbp = (isp_icb_t *) fcp->isp_scratch;
1038 MEMZERO(icbp, sizeof (*icbp));
1039
1040 icbp->icb_version = ICB_VERSION1;
1041#ifdef ISP_TARGET_MODE
1042 fcp->isp_fwoptions = ICBOPT_TGT_ENABLE;
1043#else
1044 fcp->isp_fwoptions = 0;
1045#endif
1046 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
1047 /*
1048 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1049 */
1050 if ((isp->isp_type == ISP_HA_FC_2100) && isp->isp_revision < 5) {
1051 fcp->isp_fwoptions &= ~ICBOPT_FAIRNESS;
1052 }
1053 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
1054 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
1055 /*
1056 * We have to use FULL LOGIN even though it resets the loop too much
1057 * because otherwise port database entries don't get updated after
1058 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1059 */
1060 if (ISP_FW_REVX(isp->isp_fwrev) < ISP_FW_REV(1, 17, 0)) {
1061 fcp->isp_fwoptions |= ICBOPT_FULL_LOGIN;
1062 }
1063#ifndef ISP_NO_FASTPOST_FC
1064 fcp->isp_fwoptions |= ICBOPT_FAST_POST;
1065#endif
1066 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
1067 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
1068
1069 /*
1070 * We don't set ICBOPT_PORTNAME because we want our
1071 * Node Name && Port Names to be distinct.
1072 */
1073
1074 icbp->icb_fwoptions = fcp->isp_fwoptions;
1075 icbp->icb_maxfrmlen = fcp->isp_maxfrmlen;
1076 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN ||
1077 icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {

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

1091 isp_prt(isp, ISP_LOGERR,
1092 "bad execution throttle of %d- using 16",
1093 fcp->isp_execthrottle);
1094 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1095 }
1096 icbp->icb_retry_delay = fcp->isp_retry_delay;
1097 icbp->icb_retry_count = fcp->isp_retry_count;
1098 icbp->icb_hardaddr = loopid;
1099#ifdef PRET_A_PORTE
1100 if (IS_2200(isp)) {
1101 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1102 /*
1103 * Prefer or force Point-To-Point instead Loop?
1104 */
1105 if (isp->isp_confopts & ISP_CFG_NPORT)
1106 icbp->icb_xfwoptions = ICBXOPT_PTP_2_LOOP;
1107 else
1108 icbp->icb_xfwoptions = ICBXOPT_LOOP_2_PTP;
1109 }
1110#endif
1111 icbp->icb_logintime = 60; /* 60 second login timeout */
1112
1113 if (fcp->isp_nodewwn) {
1114 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, fcp->isp_nodewwn);
1115 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_portwwn);
1116 } else {
1117 fcp->isp_fwoptions &= ~(ICBOPT_USE_PORTNAME|ICBOPT_FULL_LOGIN);
1118 }
1119 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1120 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1121 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_LSW(isp->isp_rquest_dma);
1122 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_MSW(isp->isp_rquest_dma);
1123 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_LSW(isp->isp_result_dma);
1124 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_MSW(isp->isp_result_dma);
1125 ISP_SWIZZLE_ICB(isp, icbp);
1126
1127 /*
1128 * Do this *before* initializing the firmware.
1129 */
1130 isp_mark_getpdb_all(isp);
1131 fcp->isp_fwstate = FW_CONFIG_WAIT;
1132 fcp->isp_loopstate = LOOP_NIL;

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

1288 enano = NANOTIME_SUB(&hrb, &hra);
1289
1290 /*
1291 * If the elapsed time is less than 1 millisecond,
1292 * delay a period of time up to that millisecond of
1293 * waiting.
1294 */
1295 isp_prt(isp, ISP_LOGDEBUG3, "usec%d: 0x%lx->0x%lx enano %u",
1296 count, GET_NANOSEC(&hra), GET_NANOSEC(&hrb), enano);
1297
1298 /*
1299 * This peculiar code is an attempt to try and avoid
1300 * invoking u_int64_t math support functions for some
1301 * platforms where linkage is a problem.
1302 */
1303 if (enano < (1000 * 1000)) {
1304 count += 1000;

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

2217 /*
2218 * Fibre Channel always requires some kind of tag.
2219 * The Qlogic drivers seem be happy not to use a tag,
2220 * but this breaks for some devices (IBM drives).
2221 */
2222 if (XS_TAG_P(xs)) {
2223 t2reqp->req_flags = XS_TAG_TYPE(xs);
2224 } else {
2225 if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
2226 t2reqp->req_flags = REQFLAG_HTAG;
2227 else
2228 t2reqp->req_flags = REQFLAG_OTAG;
2229 }
2230 } else {
2231 sdparam *sdp = (sdparam *)isp->isp_param;
2232 if ((sdp->isp_devparam[target].cur_dflags & DPARM_TQING) &&

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

2376 (bus << 15) | (XS_TGT(xs) << 8) | XS_LUN(xs);
2377 }
2378 mbs.param[3] = handle >> 16;
2379 mbs.param[2] = handle & 0xffff;
2380 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_ERROR);
2381 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
2382 return (0);
2383 }
2384 break;
2385
2386 case ISPCTL_UPDATE_PARAMS:
2387 isp_update(isp);
2388 return (0);
2389
2390 case ISPCTL_FCLINK_TEST:
2391 if (IS_FC(isp)) {
2392 int usdelay = (arg)? *((int *) arg) : 250000;
2393 return (isp_fclink_test(isp, usdelay));
2394 }
2395 break;
2396
2397 case ISPCTL_PDB_SYNC:
2398 if (IS_FC(isp)) {
2399 return (isp_pdb_sync(isp, -1));
2400 }
2401 break;
2402
2403#ifdef ISP_TARGET_MODE
2404 case ISPCTL_TOGGLE_TMODE:
2405 if (IS_SCSI(isp)) {
2406 int ena = *(int *)arg;
2407 mbs.param[0] = MBOX_ENABLE_TARGET_MODE;
2408 mbs.param[1] = (ena)? ENABLE_TARGET_FLAG : 0;
2409 isp_mboxcmd(isp, &mbs, MBLOGALL);
2410 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2411 break;
2412 }
2413 }
2414 return (0);
2415#endif
2416 }
2417 return (-1);
2418}
2419
2420/*
2421 * Interrupt Service Routine(s).
2422 *

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

2585 /*
2586 * Do any appropriate unswizzling of what the Qlogic f/w has
2587 * written into memory so it makes sense to us. This is a
2588 * per-platform thing. Also includes any memory barriers.
2589 */
2590 ISP_UNSWIZZLE_RESPONSE(isp, sp, oop);
2591 if (sp->req_header.rqs_entry_type != RQSTYPE_RESPONSE) {
2592 if (isp_handle_other_response(isp, sp, &optr) == 0) {
2593 continue;
2594 }
2595 /*
2596 * It really has to be a bounced request just copied
2597 * from the request queue to the response queue. If
2598 * not, something bad has happened.
2599 */
2600 if (sp->req_header.rqs_entry_type != RQSTYPE_REQUEST) {
2601 isp_prt(isp, ISP_LOGERR, notresp,
2602 sp->req_header.rqs_entry_type, oop, optr);
2603 continue;
2604 }
2605 buddaboom = 1;
2606 }
2607
2608 if (sp->req_header.rqs_flags & 0xf) {
2609#define _RQS_OFLAGS \
2610 ~(RQSFLAG_CONTINUATION|RQSFLAG_FULL|RQSFLAG_BADHEADER|RQSFLAG_BADPACKET)

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

2633 isp_prt(isp, ISP_LOGERR,
2634 "unknown flags (0x%x) in response",
2635 sp->req_header.rqs_flags);
2636 buddaboom++;
2637 }
2638#undef _RQS_OFLAGS
2639 }
2640 if (sp->req_handle > isp->isp_maxcmds || sp->req_handle < 1) {
2641 isp_prt(isp, ISP_LOGERR,
2642 "bad request handle %d", sp->req_handle);
2643 ISP_WRITE(isp, INMAILBOX5, optr);
2644 continue;
2645 }
2646 xs = isp_find_xs(isp, sp->req_handle);
2647 if (xs == NULL) {
2648 isp_prt(isp, ISP_LOGERR,
2649 "cannot find handle 0x%x in xflist",
2650 sp->req_handle);
2651 ISP_WRITE(isp, INMAILBOX5, optr);
2652 continue;
2653 }
2654 isp_destroy_handle(isp, sp->req_handle);
2655 if (sp->req_status_flags & RQSTF_BUS_RESET) {
2656 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
2657 }
2658 if (buddaboom) {
2659 XS_SETERR(xs, HBA_BOTCH);
2660 }
2661 *XS_STSP(xs) = sp->req_scsi_status & 0xff;
2662 if (IS_SCSI(isp)) {
2663 if (sp->req_state_flags & RQSF_GOT_SENSE) {
2664 XS_SAVE_SENSE(xs, sp);
2665 }
2666 /*
2667 * A new synchronous rate was negotiated for this
2668 * target. Mark state such that we'll go look up
2669 * that which has changed later.
2670 */
2671 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
2672 sdparam *sdp = isp->isp_param;
2673 sdp += XS_CHANNEL(xs);
2674 sdp->isp_devparam[XS_TGT(xs)].dev_refresh = 1;
2675 isp->isp_update |= (1 << XS_CHANNEL(xs));
2676 }
2677 } else {
2678 if (sp->req_scsi_status & RQCS_SV) {
2679 XS_SAVE_SENSE(xs, sp);
2680 /* force that we 'got' sense */
2681 sp->req_state_flags |= RQSF_GOT_SENSE;
2682 }
2683 }
2684
2685 if (sp->req_header.rqs_entry_type == RQSTYPE_RESPONSE) {
2686 XS_SET_STATE_STAT(isp, xs, sp);
2687 isp_parse_status(isp, sp, xs);
2688 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) &&
2689 (*XS_STSP(xs) == SCSI_BUSY)) {
2690 XS_SETERR(xs, HBA_TGTBSY);
2691 }
2692 } else if (sp->req_header.rqs_entry_type == RQSTYPE_REQUEST) {
2693 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
2694 /*
2695 * Force Queue Full status.
2696 */
2697 *XS_STSP(xs) = SCSI_QFULL;
2698 XS_SETERR(xs, HBA_NOERROR);
2699 } else if (XS_NOERR(xs)) {
2700 XS_SETERR(xs, HBA_BOTCH);
2701 }
2702 } else {
2703 isp_prt(isp, ISP_LOGWARN,
2704 "unhandled respose queue type 0x%x",
2705 sp->req_header.rqs_entry_type);
2706 if (XS_NOERR(xs)) {
2707 XS_SETERR(xs, HBA_BOTCH);
2708 }
2709 }
2710 if (IS_SCSI(isp)) {
2711 XS_RESID(xs) = sp->req_resid;
2712 } else if (sp->req_scsi_status & RQCS_RV) {
2713 XS_RESID(xs) = sp->req_resid;
2714 isp_prt(isp, ISP_LOGDEBUG2, "cnt %d rsd %d",
2715 XS_XFRLEN(xs), sp->req_resid);
2716 }
2717 if (XS_XFRLEN(xs)) {
2718 ISP_DMAFREE(isp, xs, sp->req_handle);
2719 }
2720 if (((isp->isp_dblev & (ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
2721 ((isp->isp_dblev & ISP_LOGDEBUG1) && !XS_NOERR(xs))) {
2722 char skey;
2723 if (sp->req_state_flags & RQSF_GOT_SENSE) {
2724 skey = XS_SNSKEY(xs) & 0xf;
2725 if (skey < 10)
2726 skey += '0';
2727 else

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

2734 isp_prt(isp, ISP_LOGALL, finmsg, XS_CHANNEL(xs),
2735 XS_TGT(xs), XS_LUN(xs), XS_XFRLEN(xs), XS_RESID(xs),
2736 *XS_STSP(xs), skey, XS_ERR(xs));
2737 }
2738
2739 if (isp->isp_nactive > 0)
2740 isp->isp_nactive--;
2741 complist[ndone++] = xs; /* defer completion call until later */
2742 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
2743 break;
2744 }
2745 }
2746
2747 /*
2748 * If we looked at any commands, then it's valid to find out
2749 * what the outpointer is. It also is a trigger to update the

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

2778
2779 if (IS_DUALBUS(isp)) {
2780 bus = ISP_READ(isp, OUTMAILBOX6);
2781 } else {
2782 bus = 0;
2783 }
2784
2785 switch (mbox) {
2786 case MBOX_COMMAND_COMPLETE: /* sometimes these show up */
2787 break;
2788 case ASYNC_BUS_RESET:
2789 isp->isp_sendmarker |= (1 << bus);
2790#ifdef ISP_TARGET_MODE
2791 isp_target_async(isp, bus, mbox);
2792#endif
2793 isp_async(isp, ISPASYNC_BUS_RESET, &bus);
2794 break;
2795 case ASYNC_SYSTEM_ERROR:

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

2852 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
2853 break;
2854
2855 case ASYNC_BUS_TRANSIT:
2856 mbox = ISP_READ(isp, OUTMAILBOX2);
2857 switch (mbox & 0x1c00) {
2858 case SXP_PINS_LVD_MODE:
2859 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
2860 ((sdparam *)isp->isp_param)->isp_diffmode = 0;
2861 ((sdparam *)isp->isp_param)->isp_ultramode = 0;
2862 ((sdparam *)isp->isp_param)->isp_lvdmode = 1;
2863 break;
2864 case SXP_PINS_HVD_MODE:
2865 isp_prt(isp, ISP_LOGINFO,
2866 "Transition to Differential mode");
2867 ((sdparam *)isp->isp_param)->isp_diffmode = 1;
2868 ((sdparam *)isp->isp_param)->isp_ultramode = 0;
2869 ((sdparam *)isp->isp_param)->isp_lvdmode = 0;
2870 break;
2871 case SXP_PINS_SE_MODE:
2872 isp_prt(isp, ISP_LOGINFO,
2873 "Transition to Single Ended mode");
2874 ((sdparam *)isp->isp_param)->isp_diffmode = 0;
2875 ((sdparam *)isp->isp_param)->isp_ultramode = 1;
2876 ((sdparam *)isp->isp_param)->isp_lvdmode = 0;
2877 break;
2878 default:
2879 isp_prt(isp, ISP_LOGWARN,
2880 "Transition to Unknown Mode 0x%x", mbox);
2881 break;
2882 }
2883 /*
2884 * XXX: Set up to renegotiate again!

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

2890 case ASYNC_CMD_CMPLT:
2891 fast_post_handle = (ISP_READ(isp, OUTMAILBOX2) << 16) |
2892 ISP_READ(isp, OUTMAILBOX1);
2893 isp_prt(isp, ISP_LOGDEBUG3, "fast post completion of %u",
2894 fast_post_handle);
2895 break;
2896
2897 case ASYNC_CTIO_DONE:
2898 /* Should only occur when Fast Posting Set for 2100s */
2899 isp_prt(isp, ISP_LOGDEBUG3, "Fast Posting CTIO done");
2900 break;
2901
2902 case ASYNC_LIP_OCCURRED:
2903 ((fcparam *) isp->isp_param)->isp_lipseq =
2904 ISP_READ(isp, OUTMAILBOX1);
2905 ((fcparam *) isp->isp_param)->isp_fwstate = FW_CONFIG_WAIT;
2906 ((fcparam *) isp->isp_param)->isp_loopstate = LOOP_LIP_RCVD;
2907 isp->isp_sendmarker = 1;
2908 isp_mark_getpdb_all(isp);
2909 isp_prt(isp, ISP_LOGINFO, "LIP occurred");
2910#ifdef ISP_TARGET_MODE
2911 isp_target_async(isp, bus, mbox);
2912#endif
2913 break;
2914
2915 case ASYNC_LOOP_UP:
2916 isp->isp_sendmarker = 1;
2917 ((fcparam *) isp->isp_param)->isp_fwstate = FW_CONFIG_WAIT;
2918 ((fcparam *) isp->isp_param)->isp_loopstate = LOOP_LIP_RCVD;
2919 isp_mark_getpdb_all(isp);
2920 isp_async(isp, ISPASYNC_LOOP_UP, NULL);
2921#ifdef ISP_TARGET_MODE
2922 isp_target_async(isp, bus, mbox);
2923#endif
2924 break;
2925
2926 case ASYNC_LOOP_DOWN:
2927 isp->isp_sendmarker = 1;
2928 ((fcparam *) isp->isp_param)->isp_fwstate = FW_CONFIG_WAIT;
2929 ((fcparam *) isp->isp_param)->isp_loopstate = LOOP_NIL;
2930 isp_mark_getpdb_all(isp);
2931 isp_async(isp, ISPASYNC_LOOP_DOWN, NULL);
2932#ifdef ISP_TARGET_MODE
2933 isp_target_async(isp, bus, mbox);
2934#endif
2935 break;
2936
2937 case ASYNC_LOOP_RESET:
2938 isp->isp_sendmarker = 1;
2939 ((fcparam *) isp->isp_param)->isp_fwstate = FW_CONFIG_WAIT;
2940 ((fcparam *) isp->isp_param)->isp_loopstate = LOOP_NIL;
2941 isp_mark_getpdb_all(isp);
2942 isp_prt(isp, ISP_LOGINFO, "Loop RESET");
2943#ifdef ISP_TARGET_MODE
2944 isp_target_async(isp, bus, mbox);
2945#endif
2946 break;
2947
2948 case ASYNC_PDB_CHANGED:
2949 isp->isp_sendmarker = 1;
2950 ((fcparam *) isp->isp_param)->isp_loopstate = LOOP_PDB_RCVD;
2951 isp_mark_getpdb_all(isp);
2952 isp_prt(isp, ISP_LOGINFO, "Port Database Changed");
2953 break;
2954
2955 case ASYNC_CHANGE_NOTIFY:
2956 isp_mark_getpdb_all(isp);
2957 /*
2958 * Not correct, but it will force us to rescan the loop.
2959 */
2960 ((fcparam *) isp->isp_param)->isp_loopstate = LOOP_PDB_RCVD;
2961 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, NULL);
2962 break;
2963
2964 case ASYNC_PTPMODE:
2965 if (((fcparam *) isp->isp_param)->isp_onfabric)
2966 ((fcparam *) isp->isp_param)->isp_topo = TOPO_N_PORT;
2967 else
2968 ((fcparam *) isp->isp_param)->isp_topo = TOPO_F_PORT;
2969 isp_mark_getpdb_all(isp);
2970 isp->isp_sendmarker = 1;
2971 ((fcparam *) isp->isp_param)->isp_fwstate = FW_CONFIG_WAIT;
2972 ((fcparam *) isp->isp_param)->isp_loopstate = LOOP_LIP_RCVD;
2973#ifdef ISP_TARGET_MODE
2974 isp_target_async(isp, bus, mbox);
2975#endif
2976 isp_prt(isp, ISP_LOGINFO, "Point-to-Point mode");
2977 break;
2978
2979 case ASYNC_CONNMODE:
2980 mbox = ISP_READ(isp, OUTMAILBOX1);

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

3016
3017static int
3018isp_handle_other_response(isp, sp, optrp)
3019 struct ispsoftc *isp;
3020 ispstatusreq_t *sp;
3021 u_int16_t *optrp;
3022{
3023 switch (sp->req_header.rqs_entry_type) {
3024 case RQSTYPE_ATIO:
3025 case RQSTYPE_CTIO:
3026 case RQSTYPE_ENABLE_LUN:
3027 case RQSTYPE_MODIFY_LUN:
3028 case RQSTYPE_NOTIFY:
3029 case RQSTYPE_NOTIFY_ACK:
3030 case RQSTYPE_CTIO1:
3031 case RQSTYPE_ATIO2:

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

3055 case RQCS_COMPLETE:
3056 if (XS_NOERR(xs)) {
3057 XS_SETERR(xs, HBA_NOERROR);
3058 }
3059 return;
3060
3061 case RQCS_INCOMPLETE:
3062 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
3063 isp_prt(isp, ISP_LOGDEBUG0,
3064 "Selection Timeout for %d.%d.%d",
3065 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
3066 if (XS_NOERR(xs)) {
3067 XS_SETERR(xs, HBA_SELTIMEOUT);
3068 }
3069 return;
3070 }
3071 isp_prt(isp, ISP_LOGERR,

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

3158 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
3159 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3160 if (XS_NOERR(xs)) {
3161 XS_SETERR(xs, HBA_CMDTIMEOUT);
3162 }
3163 return;
3164
3165 case RQCS_DATA_OVERRUN:
3166 if (IS_FC(isp)) {
3167 XS_RESID(xs) = sp->req_resid;
3168 break;
3169 }
3170 isp_prt(isp, ISP_LOGERR, "data overrun for command on %d.%d.%d",
3171 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3172 if (XS_NOERR(xs)) {
3173 XS_SETERR(xs, HBA_DATAOVR);
3174 }
3175 return;
3176
3177 case RQCS_COMMAND_OVERRUN:

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

3242 break;
3243
3244 case RQCS_UNEXP_BUS_FREE:
3245 isp_prt(isp, ISP_LOGERR, "%d.%d.%d had an unexpected bus free",
3246 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
3247 break;
3248
3249 case RQCS_DATA_UNDERRUN:
3250 if (IS_FC(isp)) {
3251 XS_RESID(xs) = sp->req_resid;
3252 }
3253 if (XS_NOERR(xs)) {
3254 XS_SETERR(xs, HBA_NOERROR);
3255 }
3256 return;
3257
3258 case RQCS_XACT_ERR1:
3259 isp_prt(isp, ISP_LOGERR, xact1, XS_CHANNEL(xs),
3260 XS_TGT(xs), XS_LUN(xs));

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

3409 * that all data transferred.
3410 */
3411 XS_SET_STATE_STAT(isp, xs, NULL);
3412 XS_RESID(xs) = 0;
3413 *XS_STSP(xs) = SCSI_GOOD;
3414 if (XS_XFRLEN(xs)) {
3415 ISP_DMAFREE(isp, xs, fph);
3416 }
3417 isp_done(xs);
3418 if (isp->isp_nactive)
3419 isp->isp_nactive--;
3420}
3421
3422#define HIBYT(x) ((x) >> 0x8)
3423#define LOBYT(x) ((x) & 0xff)
3424#define ISPOPMAP(a, b) (((a) << 8) | (b))
3425static u_int16_t mbpscsi[] = {
3426 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
3427 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */

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

4035 fcp->isp_fwstate = mbs.param[1];
4036 }
4037}
4038
4039static void
4040isp_update(isp)
4041 struct ispsoftc *isp;
4042{
4043 int bus;
4044
4045 for (bus = 0; isp->isp_update != 0; bus++) {
4046 if (isp->isp_update & (1 << bus)) {
4047 isp_update_bus(isp, bus);
4048 isp->isp_update ^= (1 << bus);
4049 }
4050 }
4051}
4052
4053static void
4054isp_update_bus(isp, bus)
4055 struct ispsoftc *isp;
4056 int bus;
4057{
4058 int tgt;
4059 mbreg_t mbs;
4060 sdparam *sdp;
4061
4062 if (IS_FC(isp)) {
4063 return;
4064 }
4065
4066 sdp = isp->isp_param;
4067 sdp += bus;
4068
4069 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
4070 u_int16_t flags, period, offset;
4071 int get;
4072
4073 if (sdp->isp_devparam[tgt].dev_enable == 0) {
4074 isp_prt(isp, ISP_LOGDEBUG1,
4075 "skipping target %d bus %d update", tgt, bus);
4076 continue;
4077 }
4078
4079 /*
4080 * If the goal is to update the status of the device,
4081 * take what's in dev_flags and try and set the device
4082 * toward that. Otherwise, if we're just refreshing the
4083 * current device state, get the current parameters.
4084 */
4085 if (sdp->isp_devparam[tgt].dev_update) {
4086 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
4087 mbs.param[2] = sdp->isp_devparam[tgt].dev_flags;
4088 /*
4089 * Insist that PARITY must be enabled if SYNC
4090 * is enabled.
4091 */
4092 if (mbs.param[2] & DPARM_SYNC) {
4093 mbs.param[2] |= DPARM_PARITY;
4094 }
4095 mbs.param[3] =
4096 (sdp->isp_devparam[tgt].sync_offset << 8) |
4097 (sdp->isp_devparam[tgt].sync_period);
4098 sdp->isp_devparam[tgt].dev_update = 0;
4099 /*
4100 * A command completion later that has
4101 * RQSTF_NEGOTIATION set will cause
4102 * the dev_refresh/announce cycle.
4103 *
4104 * Note: It is really important to update our current
4105 * flags with at least the state of TAG capabilities-
4106 * otherwise we might try and send a tagged command
4107 * when we have it all turned off. So change it here
4108 * to say that current already matches goal.
4109 */
4110 sdp->isp_devparam[tgt].cur_dflags &= ~DPARM_TQING;
4111 sdp->isp_devparam[tgt].cur_dflags |=
4112 (sdp->isp_devparam[tgt].dev_flags & DPARM_TQING);
4113 sdp->isp_devparam[tgt].dev_refresh = 1;
4114 isp_prt(isp, ISP_LOGDEBUG2,
4115 "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
4116 bus, tgt, mbs.param[2], mbs.param[3] >> 8,
4117 mbs.param[3] & 0xff);
4118 get = 0;
4119 } else if (sdp->isp_devparam[tgt].dev_refresh) {
4120 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
4121 sdp->isp_devparam[tgt].dev_refresh = 0;
4122 get = 1;
4123 } else {
4124 continue;
4125 }
4126 mbs.param[1] = (bus << 15) | (tgt << 8) ;
4127 isp_mboxcmd(isp, &mbs, MBLOGALL);
4128 if (get == 0) {
4129 isp->isp_sendmarker |= (1 << bus);
4130 continue;
4131 }
4132 flags = mbs.param[2];
4133 period = mbs.param[3] & 0xff;
4134 offset = mbs.param[3] >> 8;
4135 sdp->isp_devparam[tgt].cur_dflags = flags;
4136 sdp->isp_devparam[tgt].cur_period = period;
4137 sdp->isp_devparam[tgt].cur_offset = offset;
4138 get = (bus << 16) | tgt;
4139 (void) isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, &get);
4140 }
4141}
4142
4143static void
4144isp_setdfltparm(isp, channel)
4145 struct ispsoftc *isp;
4146 int channel;
4147{
4148 int tgt;

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

4153 fcparam *fcp = (fcparam *) isp->isp_param;
4154 fcp += channel;
4155 if (fcp->isp_gotdparms) {
4156 return;
4157 }
4158 fcp->isp_gotdparms = 1;
4159 fcp->isp_maxfrmlen = ICB_DFLT_FRMLEN;
4160 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
4161 fcp->isp_execthrottle = ICB_DFLT_THROTTLE;
4162 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
4163 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
4164 /* Platform specific.... */
4165 fcp->isp_loopid = DEFAULT_LOOPID(isp);
4166 fcp->isp_nodewwn = DEFAULT_NODEWWN(isp);
4167 fcp->isp_portwwn = DEFAULT_PORTWWN(isp);
4168
4169 /*
4170 * Now try and read NVRAM
4171 */
4172 if ((isp->isp_confopts & (ISP_CFG_NONVRAM|ISP_CFG_OWNWWN)) ||
4173 (isp_read_nvram(isp))) {
4174 isp_prt(isp, ISP_LOGINFO,
4175 "Node WWN 0x%08x%08x, Port WWN 0x%08x%08x",
4176 (u_int32_t) (fcp->isp_nodewwn >> 32),
4177 (u_int32_t) (fcp->isp_nodewwn & 0xffffffff),

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

4251 (isp->isp_bustype == ISP_BT_PCI &&
4252 isp->isp_type < ISP_HA_SCSI_1040) ||
4253 (isp->isp_clock && isp->isp_clock < 60) ||
4254 (sdp->isp_ultramode == 0)) {
4255 sdp->isp_devparam[tgt].sync_offset =
4256 ISP_10M_SYNCPARMS >> 8;
4257 sdp->isp_devparam[tgt].sync_period =
4258 ISP_10M_SYNCPARMS & 0xff;
4259 } else if (IS_ULTRA2(isp)) {
4260 sdp->isp_devparam[tgt].sync_offset =
4261 ISP_40M_SYNCPARMS >> 8;
4262 sdp->isp_devparam[tgt].sync_period =
4263 ISP_40M_SYNCPARMS & 0xff;
4264 } else {
4265 sdp->isp_devparam[tgt].sync_offset =
4266 ISP_20M_SYNCPARMS >> 8;
4267 sdp->isp_devparam[tgt].sync_period =
4268 ISP_20M_SYNCPARMS & 0xff;
4269 }
4270
4271 /*
4272 * Don't get current target parameters if we've been
4273 * told not to use NVRAM- it's really the same thing.
4274 */
4275 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
4276

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

4308 (ISP_20M_SYNCPARMS & 0xff))) {
4309 sdp->isp_devparam[tgt].sync_offset =
4310 ISP_10M_SYNCPARMS >> 8;
4311 sdp->isp_devparam[tgt].sync_period =
4312 ISP_10M_SYNCPARMS & 0xff;
4313 }
4314 }
4315 isp_prt(isp, ISP_LOGDEBUG1,
4316 "bus %d tgt %d flags %x offset %x period %x",
4317 channel, tgt, sdp->isp_devparam[tgt].dev_flags,
4318 sdp->isp_devparam[tgt].sync_offset,
4319 sdp->isp_devparam[tgt].sync_period);
4320 }
4321
4322 /*
4323 * Establish default some more default parameters.
4324 */

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

4334 sdp->isp_selection_timeout = 250;
4335 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
4336 sdp->isp_tag_aging = 8;
4337 sdp->isp_bus_reset_delay = 3;
4338 sdp->isp_retry_count = 2;
4339 sdp->isp_retry_delay = 2;
4340
4341 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
4342 sdp->isp_devparam[tgt].exc_throttle = 16;
4343 sdp->isp_devparam[tgt].dev_enable = 1;
4344 }
4345}
4346
4347/*
4348 * Re-initialize the ISP and complete all orphaned commands
4349 * with a 'botched' notice. The reset/init routines should
4350 * not disturb an already active list of commands.

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

4584 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
4585
4586 sdp->isp_selection_timeout =
4587 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
4588
4589 sdp->isp_max_queue_depth =
4590 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
4591
4592 isp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
4593 for (i = 0; i < MAX_TARGETS; i++) {
4594 sdp->isp_devparam[i].dev_enable =
4595 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, i);
4596 sdp->isp_devparam[i].exc_throttle =
4597 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, i);
4598 sdp->isp_devparam[i].sync_offset =
4599 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, i);
4600 sdp->isp_devparam[i].sync_period =

--- 242 unchanged lines hidden ---