3 * Machine and OS Independent (well, as best as possible)
4 * code for the Qlogic ISP SCSI adapters.
6 * Copyright (c) 1997, 1998, 1999, 2000, 2001 by Matthew Jacob
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice immediately at the beginning of the file, without modification,
15 * this list of conditions, and the following disclaimer.
16 * 2. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
34 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
35 * ideas dredged from the Solaris driver.
39 * Include header file appropriate for platform we're building on.
43 #include <dev/ic/isp_netbsd.h>
46 #include <dev/isp/isp_freebsd.h>
49 #include <dev/ic/isp_openbsd.h>
52 #include "isp_linux.h"
55 #include "isp_solaris.h"
62 #define MBOX_DELAY_COUNT 1000000 / 100
67 static const char portshift[] =
68 "Target %d Loop ID 0x%x (Port 0x%x) => Loop 0x%x (Port 0x%x)";
69 static const char portdup[] =
70 "Target %d duplicates Target %d- killing off both";
71 static const char retained[] =
72 "Retaining Loop ID 0x%x for Target %d (Port 0x%x)";
73 static const char lretained[] =
74 "Retained login of Target %d (Loop ID 0x%x) Port 0x%x";
75 static const char plogout[] =
76 "Logging out Target %d at Loop ID 0x%x (Port 0x%x)";
77 static const char plogierr[] =
78 "Command Error in PLOGI for Port 0x%x (0x%x)";
79 static const char nopdb[] =
80 "Could not get PDB for Device @ Port 0x%x";
81 static const char pdbmfail1[] =
82 "PDB Loop ID info for Device @ Port 0x%x does not match up (0x%x)";
83 static const char pdbmfail2[] =
84 "PDB Port info for Device @ Port 0x%x does not match up (0x%x)";
85 static const char ldumped[] =
86 "Target %d (Loop ID 0x%x) Port 0x%x dumped after login info mismatch";
87 static const char notresp[] =
88 "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
89 static const char xact1[] =
90 "HBA attempted queued transaction with disconnect not set for %d.%d.%d";
91 static const char xact2[] =
92 "HBA attempted queued transaction to target routine %d on target %d bus %d";
93 static const char xact3[] =
94 "HBA attempted queued cmd for %d.%d.%d when queueing disabled";
95 static const char pskip[] =
96 "SCSI phase skipped for target %d.%d.%d";
97 static const char topology[] =
98 "Loop ID %d, AL_PA 0x%x, Port ID 0x%x, Loop State 0x%x, Topology '%s'";
99 static const char swrej[] =
100 "Fabric Nameserver rejected %s (Reason=0x%x Expl=0x%x) for Port ID 0x%x";
101 static const char finmsg[] =
102 "(%d.%d.%d): FIN dl%d resid %d STS 0x%x SKEY %c XS_ERR=0x%x";
103 static const char sc0[] =
104 "%s CHAN %d FTHRSH %d IID %d RESETD %d RETRYC %d RETRYD %d ASD 0x%x";
105 static const char sc1[] =
106 "%s RAAN 0x%x DLAN 0x%x DDMAB 0x%x CDMAB 0x%x SELTIME %d MQD %d";
107 static const char sc2[] = "%s CHAN %d TGT %d FLAGS 0x%x 0x%x/0x%x";
108 static const char sc3[] = "Generated";
109 static const char sc4[] = "NVRAM";
110 static const char bun[] =
111 "bad underrun for %d.%d (count %d, resid %d, status %s)";
114 * Local function prototypes.
116 static int isp_parse_async(struct ispsoftc *, u_int16_t);
117 static int isp_handle_other_response(struct ispsoftc *, int, isphdr_t *,
120 isp_parse_status(struct ispsoftc *, ispstatusreq_t *, XS_T *);
121 static void isp_fastpost_complete(struct ispsoftc *, u_int16_t);
122 static int isp_mbox_continue(struct ispsoftc *);
123 static void isp_scsi_init(struct ispsoftc *);
124 static void isp_scsi_channel_init(struct ispsoftc *, int);
125 static void isp_fibre_init(struct ispsoftc *);
126 static void isp_mark_getpdb_all(struct ispsoftc *);
127 static int isp_getmap(struct ispsoftc *, fcpos_map_t *);
128 static int isp_getpdb(struct ispsoftc *, int, isp_pdb_t *);
129 static u_int64_t isp_get_portname(struct ispsoftc *, int, int);
130 static int isp_fclink_test(struct ispsoftc *, int);
131 static char *isp2100_fw_statename(int);
132 static int isp_pdb_sync(struct ispsoftc *);
133 static int isp_scan_loop(struct ispsoftc *);
134 static int isp_fabric_mbox_cmd(struct ispsoftc *, mbreg_t *);
135 static int isp_scan_fabric(struct ispsoftc *, int);
136 static void isp_register_fc4_type(struct ispsoftc *);
137 static void isp_fw_state(struct ispsoftc *);
138 static void isp_mboxcmd_qnw(struct ispsoftc *, mbreg_t *, int);
139 static void isp_mboxcmd(struct ispsoftc *, mbreg_t *, int);
141 static void isp_update(struct ispsoftc *);
142 static void isp_update_bus(struct ispsoftc *, int);
143 static void isp_setdfltparm(struct ispsoftc *, int);
144 static int isp_read_nvram(struct ispsoftc *);
145 static void isp_rdnvram_word(struct ispsoftc *, int, u_int16_t *);
146 static void isp_parse_nvram_1020(struct ispsoftc *, u_int8_t *);
147 static void isp_parse_nvram_1080(struct ispsoftc *, int, u_int8_t *);
148 static void isp_parse_nvram_12160(struct ispsoftc *, int, u_int8_t *);
149 static void isp_parse_nvram_2100(struct ispsoftc *, u_int8_t *);
154 * Hit the chip over the head, download new f/w if available and set it running.
156 * Locking done elsewhere.
160 isp_reset(struct ispsoftc *isp)
164 int loops, i, dodnld = 1;
165 char *btype = "????";
167 isp->isp_state = ISP_NILSTATE;
170 * Basic types (SCSI, FibreChannel and PCI or SBus)
171 * have been set in the MD code. We figure out more
172 * here. Possibly more refined types based upon PCI
173 * identification. Chip revision has been gathered.
175 * After we've fired this chip up, zero out the conf1 register
176 * for SCSI adapters and do other settings for the 2100.
180 * Get the current running firmware revision out of the
181 * chip before we hit it over the head (if this is our
182 * first time through). Note that we store this as the
183 * 'ROM' firmware revision- which it may not be. In any
184 * case, we don't really use this yet, but we may in
187 if (isp->isp_touched == 0) {
189 * First see whether or not we're sitting in the ISP PROM.
190 * If we've just been reset, we'll have the string "ISP "
191 * spread through outgoing mailbox registers 1-3. We do
192 * this for PCI cards because otherwise we really don't
193 * know what state the card is in and we could hang if
194 * we try this command otherwise.
196 * For SBus cards, we just do this because they almost
197 * certainly will be running firmware by now.
199 if (ISP_READ(isp, OUTMAILBOX1) != 0x4953 ||
200 ISP_READ(isp, OUTMAILBOX2) != 0x5020 ||
201 ISP_READ(isp, OUTMAILBOX3) != 0x2020) {
203 * Just in case it was paused...
205 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
206 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
207 isp_mboxcmd(isp, &mbs, MBLOGNONE);
208 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
209 isp->isp_romfw_rev[0] = mbs.param[1];
210 isp->isp_romfw_rev[1] = mbs.param[2];
211 isp->isp_romfw_rev[2] = mbs.param[3];
214 isp->isp_touched = 1;
220 * Set up default request/response queue in-pointer/out-pointer
224 isp->isp_rqstinrp = BIU_REQINP;
225 isp->isp_rqstoutrp = BIU_REQOUTP;
226 isp->isp_respinrp = BIU_RSPINP;
227 isp->isp_respoutrp = BIU_RSPOUTP;
229 isp->isp_rqstinrp = INMAILBOX4;
230 isp->isp_rqstoutrp = OUTMAILBOX4;
231 isp->isp_respinrp = OUTMAILBOX5;
232 isp->isp_respoutrp = INMAILBOX5;
236 * Put the board into PAUSE mode (so we can read the SXP registers
237 * or write FPM/FBM registers).
239 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
242 switch (isp->isp_type) {
259 * While we're paused, reset the FPM module and FBM fifos.
261 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
262 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
263 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
264 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
265 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
266 } else if (IS_1240(isp)) {
267 sdparam *sdp = isp->isp_param;
270 sdp->isp_ultramode = 1;
272 sdp->isp_ultramode = 1;
274 * XXX: Should probably do some bus sensing.
276 } else if (IS_ULTRA2(isp)) {
277 static const char m[] = "bus %d is in %s Mode";
279 sdparam *sdp = isp->isp_param;
281 isp->isp_clock = 100;
285 else if (IS_1080(isp))
287 else if (IS_10160(isp))
289 else if (IS_12160(isp))
294 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
296 case ISP1080_LVD_MODE:
297 sdp->isp_lvdmode = 1;
298 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
300 case ISP1080_HVD_MODE:
301 sdp->isp_diffmode = 1;
302 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
304 case ISP1080_SE_MODE:
305 sdp->isp_ultramode = 1;
306 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
309 isp_prt(isp, ISP_LOGERR,
310 "unknown mode on bus %d (0x%x)", 0, l);
314 if (IS_DUALBUS(isp)) {
316 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
317 l &= ISP1080_MODE_MASK;
319 case ISP1080_LVD_MODE:
320 sdp->isp_lvdmode = 1;
321 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
323 case ISP1080_HVD_MODE:
324 sdp->isp_diffmode = 1;
325 isp_prt(isp, ISP_LOGCONFIG,
326 m, 1, "Differential");
328 case ISP1080_SE_MODE:
329 sdp->isp_ultramode = 1;
330 isp_prt(isp, ISP_LOGCONFIG,
331 m, 1, "Single-Ended");
334 isp_prt(isp, ISP_LOGERR,
335 "unknown mode on bus %d (0x%x)", 1, l);
340 sdparam *sdp = isp->isp_param;
341 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
344 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
348 isp->isp_type = ISP_HA_SCSI_1020;
353 * Some 1020A chips are Ultra Capable, but don't
354 * run the clock rate up for that unless told to
355 * do so by the Ultra Capable bits being set.
358 isp->isp_type = ISP_HA_SCSI_1020A;
363 isp->isp_type = ISP_HA_SCSI_1040;
368 isp->isp_type = ISP_HA_SCSI_1040A;
373 isp->isp_type = ISP_HA_SCSI_1040B;
378 isp->isp_type = ISP_HA_SCSI_1040C;
383 * Now, while we're at it, gather info about ultra
384 * and/or differential mode.
386 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
387 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
388 sdp->isp_diffmode = 1;
390 sdp->isp_diffmode = 0;
392 i = ISP_READ(isp, RISC_PSR);
393 if (isp->isp_bustype == ISP_BT_SBUS) {
394 i &= RISC_PSR_SBUS_ULTRA;
396 i &= RISC_PSR_PCI_ULTRA;
399 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
400 sdp->isp_ultramode = 1;
402 * If we're in Ultra Mode, we have to be 60MHz clock-
403 * even for the SBus version.
407 sdp->isp_ultramode = 0;
409 * Clock is known. Gronk.
414 * Machine dependent clock (if set) overrides
415 * our generic determinations.
417 if (isp->isp_mdvec->dv_clock) {
418 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
419 isp->isp_clock = isp->isp_mdvec->dv_clock;
426 * Clear instrumentation
428 isp->isp_intcnt = isp->isp_intbogus = 0;
431 * Do MD specific pre initialization
438 * Hit the chip over the head with hammer,
439 * and give the ISP a chance to recover.
443 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
450 * Clear data && control DMA engines.
452 ISP_WRITE(isp, CDMA_CONTROL,
453 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
454 ISP_WRITE(isp, DDMA_CONTROL,
455 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
459 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
466 * Clear data && control DMA engines.
468 ISP_WRITE(isp, CDMA2100_CONTROL,
469 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
470 ISP_WRITE(isp, TDMA2100_CONTROL,
471 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
472 ISP_WRITE(isp, RDMA2100_CONTROL,
473 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
477 * Wait for ISP to be ready to go...
479 loops = MBOX_DELAY_COUNT;
482 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET))
485 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
490 ISP_DUMPREGS(isp, "chip reset timed out");
496 * After we've fired this chip up, zero out the conf1 register
497 * for SCSI adapters and other settings for the 2100.
501 ISP_WRITE(isp, BIU_CONF1, 0);
503 ISP_WRITE(isp, BIU2100_CSR, 0);
507 * Reset RISC Processor
509 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
511 /* Clear semaphore register (just to be sure) */
512 ISP_WRITE(isp, BIU_SEMA, 0);
515 * Establish some initial burst rate stuff.
516 * (only for the 1XX0 boards). This really should
517 * be done later after fetching from NVRAM.
520 u_int16_t tmp = isp->isp_mdvec->dv_conf1;
522 * Busted FIFO. Turn off all but burst enables.
524 if (isp->isp_type == ISP_HA_SCSI_1040A) {
525 tmp &= BIU_BURST_ENABLE;
527 ISP_SETBITS(isp, BIU_CONF1, tmp);
528 if (tmp & BIU_BURST_ENABLE) {
529 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
530 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
533 if (((sdparam *) isp->isp_param)->isp_ultramode) {
534 while (ISP_READ(isp, RISC_MTR) != 0x1313) {
535 ISP_WRITE(isp, RISC_MTR, 0x1313);
536 ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
539 ISP_WRITE(isp, RISC_MTR, 0x1212);
542 * PTI specific register
544 ISP_WRITE(isp, RISC_EMB, DUAL_BANK)
546 ISP_WRITE(isp, RISC_MTR, 0x1212);
549 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
550 if (IS_2200(isp) || IS_23XX(isp)) {
551 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
555 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE); /* release paused processor */
558 * Do MD specific post initialization
563 * Wait for everything to finish firing up.
565 * Avoid doing this on the 2312 because you can generate a PCI
566 * parity error (chip breakage).
571 loops = MBOX_DELAY_COUNT;
572 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
575 isp_prt(isp, ISP_LOGERR,
576 "MBOX_BUSY never cleared on reset");
583 * Up until this point we've done everything by just reading or
584 * setting registers. From this point on we rely on at least *some*
585 * kind of firmware running in the card.
589 * Do some sanity checking.
591 mbs.param[0] = MBOX_NO_OP;
592 isp_mboxcmd(isp, &mbs, MBLOGALL);
593 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
598 mbs.param[0] = MBOX_MAILBOX_REG_TEST;
599 mbs.param[1] = 0xdead;
600 mbs.param[2] = 0xbeef;
601 mbs.param[3] = 0xffff;
602 mbs.param[4] = 0x1111;
603 mbs.param[5] = 0xa5a5;
604 isp_mboxcmd(isp, &mbs, MBLOGALL);
605 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
608 if (mbs.param[1] != 0xdead || mbs.param[2] != 0xbeef ||
609 mbs.param[3] != 0xffff || mbs.param[4] != 0x1111 ||
610 mbs.param[5] != 0xa5a5) {
611 isp_prt(isp, ISP_LOGERR,
612 "Register Test Failed (0x%x 0x%x 0x%x 0x%x 0x%x)",
613 mbs.param[1], mbs.param[2], mbs.param[3],
614 mbs.param[4], mbs.param[5]);
621 * Download new Firmware, unless requested not to do so.
622 * This is made slightly trickier in some cases where the
623 * firmware of the ROM revision is newer than the revision
624 * compiled into the driver. So, where we used to compare
625 * versions of our f/w and the ROM f/w, now we just see
626 * whether we have f/w at all and whether a config flag
627 * has disabled our download.
629 if ((isp->isp_mdvec->dv_ispfw == NULL) ||
630 (isp->isp_confopts & ISP_CFG_NORELOAD)) {
635 code_org = ISP_CODE_ORG_2300;
637 code_org = ISP_CODE_ORG;
640 isp->isp_mbxworkp = (void *) &isp->isp_mdvec->dv_ispfw[1];
641 isp->isp_mbxwrk0 = isp->isp_mdvec->dv_ispfw[3] - 1;
642 isp->isp_mbxwrk1 = code_org + 1;
643 mbs.param[0] = MBOX_WRITE_RAM_WORD;
644 mbs.param[1] = code_org;
645 mbs.param[2] = isp->isp_mdvec->dv_ispfw[0];
646 isp_mboxcmd(isp, &mbs, MBLOGNONE);
647 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
648 isp_prt(isp, ISP_LOGERR,
649 "F/W download failed at word %d",
650 isp->isp_mbxwrk1 - code_org);
655 * Verify that it downloaded correctly.
657 mbs.param[0] = MBOX_VERIFY_CHECKSUM;
658 mbs.param[1] = code_org;
659 isp_mboxcmd(isp, &mbs, MBLOGNONE);
660 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
661 isp_prt(isp, ISP_LOGERR, "Ram Checksum Failure");
664 isp->isp_loaded_fw = 1;
666 isp->isp_loaded_fw = 0;
667 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
671 * Now start it rolling.
673 * If we didn't actually download f/w,
674 * we still need to (re)start it.
678 mbs.param[0] = MBOX_EXEC_FIRMWARE;
679 mbs.param[1] = code_org;
680 isp_mboxcmd(isp, &mbs, MBLOGNONE);
682 * Give it a chance to start.
688 * Set CLOCK RATE, but only if asked to.
690 if (isp->isp_clock) {
691 mbs.param[0] = MBOX_SET_CLOCK_RATE;
692 mbs.param[1] = isp->isp_clock;
693 isp_mboxcmd(isp, &mbs, MBLOGALL);
694 /* we will try not to care if this fails */
698 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
699 isp_mboxcmd(isp, &mbs, MBLOGALL);
700 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
705 * The SBus firmware that we are using apparently does not return
706 * major, minor, micro revisions in the mailbox registers, which
707 * is really, really, annoying.
709 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
711 #ifdef ISP_TARGET_MODE
712 isp->isp_fwrev[0] = 7;
713 isp->isp_fwrev[1] = 55;
715 isp->isp_fwrev[0] = 1;
716 isp->isp_fwrev[1] = 37;
718 isp->isp_fwrev[2] = 0;
721 isp->isp_fwrev[0] = mbs.param[1];
722 isp->isp_fwrev[1] = mbs.param[2];
723 isp->isp_fwrev[2] = mbs.param[3];
725 isp_prt(isp, ISP_LOGCONFIG,
726 "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
727 btype, isp->isp_revision, dodnld? "loaded" : "resident",
728 isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
732 * We do not believe firmware attributes for 2100 code less
733 * than 1.17.0, unless it's the firmware we specifically
736 * Note that all 22XX and 23XX f/w is greater than 1.X.0.
738 if (!(ISP_FW_NEWER_THAN(isp, 1, 17, 0))) {
739 #ifdef USE_SMALLER_2100_FIRMWARE
740 FCPARAM(isp)->isp_fwattr = ISP_FW_ATTR_SCCLUN;
742 FCPARAM(isp)->isp_fwattr = 0;
745 FCPARAM(isp)->isp_fwattr = mbs.param[6];
746 isp_prt(isp, ISP_LOGDEBUG0,
747 "Firmware Attributes = 0x%x", mbs.param[6]);
749 if (ISP_READ(isp, BIU2100_CSR) & BIU2100_PCI64) {
750 isp_prt(isp, ISP_LOGCONFIG,
751 "Installed in 64-Bit PCI slot");
755 if (isp->isp_romfw_rev[0] || isp->isp_romfw_rev[1] ||
756 isp->isp_romfw_rev[2]) {
757 isp_prt(isp, ISP_LOGCONFIG, "Last F/W revision was %d.%d.%d",
758 isp->isp_romfw_rev[0], isp->isp_romfw_rev[1],
759 isp->isp_romfw_rev[2]);
762 mbs.param[0] = MBOX_GET_FIRMWARE_STATUS;
763 isp_mboxcmd(isp, &mbs, MBLOGALL);
764 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
767 isp->isp_maxcmds = mbs.param[2];
768 isp_prt(isp, ISP_LOGINFO,
769 "%d max I/O commands supported", mbs.param[2]);
773 * Set up DMA for the request and result mailboxes.
775 if (ISP_MBOXDMASETUP(isp) != 0) {
776 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
779 isp->isp_state = ISP_RESETSTATE;
782 * Okay- now that we have new firmware running, we now (re)set our
783 * notion of how many luns we support. This is somewhat tricky because
784 * if we haven't loaded firmware, we sometimes do not have an easy way
785 * of knowing how many luns we support.
787 * Expanded lun firmware gives you 32 luns for SCSI cards and
788 * 16384 luns for Fibre Channel cards.
790 * It turns out that even for QLogic 2100s with ROM 1.10 and above
791 * we do get a firmware attributes word returned in mailbox register 6.
793 * Because the lun is in a different position in the Request Queue
794 * Entry structure for Fibre Channel with expanded lun firmware, we
795 * can only support one lun (lun zero) when we don't know what kind
796 * of firmware we're running.
800 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
801 isp->isp_maxluns = 32;
803 isp->isp_maxluns = 8;
806 isp->isp_maxluns = 8;
809 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
810 isp->isp_maxluns = 16384;
812 isp->isp_maxluns = 16;
818 * Initialize Parameters of Hardware to a known state.
820 * Locks are held before coming here.
824 isp_init(struct ispsoftc *isp)
827 * Must do this first to get defaults established.
829 isp_setdfltparm(isp, 0);
830 if (IS_DUALBUS(isp)) {
831 isp_setdfltparm(isp, 1);
841 isp_scsi_init(struct ispsoftc *isp)
843 sdparam *sdp_chan0, *sdp_chan1;
846 sdp_chan0 = isp->isp_param;
847 sdp_chan1 = sdp_chan0;
848 if (IS_DUALBUS(isp)) {
853 * If we have no role (neither target nor initiator), return.
855 if (isp->isp_role == ISP_ROLE_NONE) {
859 /* First do overall per-card settings. */
862 * If we have fast memory timing enabled, turn it on.
864 if (sdp_chan0->isp_fast_mttr) {
865 ISP_WRITE(isp, RISC_MTR, 0x1313);
869 * Set Retry Delay and Count.
870 * You set both channels at the same time.
872 mbs.param[0] = MBOX_SET_RETRY_COUNT;
873 mbs.param[1] = sdp_chan0->isp_retry_count;
874 mbs.param[2] = sdp_chan0->isp_retry_delay;
875 mbs.param[6] = sdp_chan1->isp_retry_count;
876 mbs.param[7] = sdp_chan1->isp_retry_delay;
878 isp_mboxcmd(isp, &mbs, MBLOGALL);
879 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
884 * Set ASYNC DATA SETUP time. This is very important.
886 mbs.param[0] = MBOX_SET_ASYNC_DATA_SETUP_TIME;
887 mbs.param[1] = sdp_chan0->isp_async_data_setup;
888 mbs.param[2] = sdp_chan1->isp_async_data_setup;
889 isp_mboxcmd(isp, &mbs, MBLOGALL);
890 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
895 * Set ACTIVE Negation State.
897 mbs.param[0] = MBOX_SET_ACT_NEG_STATE;
899 (sdp_chan0->isp_req_ack_active_neg << 4) |
900 (sdp_chan0->isp_data_line_active_neg << 5);
902 (sdp_chan1->isp_req_ack_active_neg << 4) |
903 (sdp_chan1->isp_data_line_active_neg << 5);
905 isp_mboxcmd(isp, &mbs, MBLOGNONE);
906 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
907 isp_prt(isp, ISP_LOGERR,
908 "failed to set active negation state (%d,%d), (%d,%d)",
909 sdp_chan0->isp_req_ack_active_neg,
910 sdp_chan0->isp_data_line_active_neg,
911 sdp_chan1->isp_req_ack_active_neg,
912 sdp_chan1->isp_data_line_active_neg);
919 * Set the Tag Aging limit
921 mbs.param[0] = MBOX_SET_TAG_AGE_LIMIT;
922 mbs.param[1] = sdp_chan0->isp_tag_aging;
923 mbs.param[2] = sdp_chan1->isp_tag_aging;
924 isp_mboxcmd(isp, &mbs, MBLOGALL);
925 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
926 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
927 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
932 * Set selection timeout.
934 mbs.param[0] = MBOX_SET_SELECT_TIMEOUT;
935 mbs.param[1] = sdp_chan0->isp_selection_timeout;
936 mbs.param[2] = sdp_chan1->isp_selection_timeout;
937 isp_mboxcmd(isp, &mbs, MBLOGALL);
938 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
942 /* now do per-channel settings */
943 isp_scsi_channel_init(isp, 0);
945 isp_scsi_channel_init(isp, 1);
948 * Now enable request/response queues
951 if (IS_ULTRA2(isp) || IS_1240(isp)) {
952 mbs.param[0] = MBOX_INIT_RES_QUEUE_A64;
953 mbs.param[1] = RESULT_QUEUE_LEN(isp);
954 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
955 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
957 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
958 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
959 isp_mboxcmd(isp, &mbs, MBLOGALL);
960 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
963 isp->isp_residx = mbs.param[5];
965 mbs.param[0] = MBOX_INIT_REQ_QUEUE_A64;
966 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
967 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
968 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
970 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
971 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
972 isp_mboxcmd(isp, &mbs, MBLOGALL);
973 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
976 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
978 mbs.param[0] = MBOX_INIT_RES_QUEUE;
979 mbs.param[1] = RESULT_QUEUE_LEN(isp);
980 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
981 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
983 isp_mboxcmd(isp, &mbs, MBLOGALL);
984 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
987 isp->isp_residx = mbs.param[5];
989 mbs.param[0] = MBOX_INIT_REQ_QUEUE;
990 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
991 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
992 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
994 isp_mboxcmd(isp, &mbs, MBLOGALL);
995 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
998 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1002 * Turn on Fast Posting, LVD transitions
1004 * Ultra2 F/W always has had fast posting (and LVD transitions)
1006 * Ultra and older (i.e., SBus) cards may not. It's just safer
1007 * to assume not for them.
1010 mbs.param[0] = MBOX_SET_FW_FEATURES;
1013 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1015 if (IS_ULTRA2(isp) || IS_1240(isp))
1016 mbs.param[1] |= FW_FEATURE_RIO_16BIT;
1018 #ifndef ISP_NO_FASTPOST
1019 if (IS_ULTRA2(isp) || IS_1240(isp))
1020 mbs.param[1] |= FW_FEATURE_FAST_POST;
1023 if (mbs.param[1] != 0) {
1024 u_int16_t sfeat = mbs.param[1];
1025 isp_mboxcmd(isp, &mbs, MBLOGALL);
1026 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1027 isp_prt(isp, ISP_LOGINFO,
1028 "Enabled FW features (0x%x)", sfeat);
1033 * Let the outer layers decide whether to issue a SCSI bus reset.
1035 isp->isp_state = ISP_INITSTATE;
1039 isp_scsi_channel_init(struct ispsoftc *isp, int channel)
1045 sdp = isp->isp_param;
1049 * Set (possibly new) Initiator ID.
1051 mbs.param[0] = MBOX_SET_INIT_SCSI_ID;
1052 mbs.param[1] = (channel << 7) | sdp->isp_initiator_id;
1053 isp_mboxcmd(isp, &mbs, MBLOGALL);
1054 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1057 isp_prt(isp, ISP_LOGINFO, "Initiator ID is %d on Channel %d",
1058 sdp->isp_initiator_id, channel);
1062 * Set current per-target parameters to an initial safe minimum.
1064 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1068 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1071 #ifndef ISP_TARGET_MODE
1072 sdf = sdp->isp_devparam[tgt].goal_flags;
1073 sdf &= DPARM_SAFE_DFLT;
1075 * It is not quite clear when this changed over so that
1076 * we could force narrow and async for 1000/1020 cards,
1077 * but assume that this is only the case for loaded
1080 if (isp->isp_loaded_fw) {
1081 sdf |= DPARM_NARROW | DPARM_ASYNC;
1085 * The !$*!)$!$)* f/w uses the same index into some
1086 * internal table to decide how to respond to negotiations,
1087 * so if we've said "let's be safe" for ID X, and ID X
1088 * selects *us*, the negotiations will back to 'safe'
1089 * (as in narrow/async). What the f/w *should* do is
1090 * use the initiator id settings to decide how to respond.
1092 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1094 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1095 mbs.param[1] = (channel << 15) | (tgt << 8);
1097 if ((sdf & DPARM_SYNC) == 0) {
1101 (sdp->isp_devparam[tgt].goal_offset << 8) |
1102 (sdp->isp_devparam[tgt].goal_period);
1104 isp_prt(isp, ISP_LOGDEBUG0,
1105 "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1106 channel, tgt, mbs.param[2], mbs.param[3] >> 8,
1107 mbs.param[3] & 0xff);
1108 isp_mboxcmd(isp, &mbs, MBLOGNONE);
1109 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1110 sdf = DPARM_SAFE_DFLT;
1111 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1112 mbs.param[1] = (tgt << 8) | (channel << 15);
1115 isp_mboxcmd(isp, &mbs, MBLOGALL);
1116 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1122 * We don't update any information directly from the f/w
1123 * because we need to run at least one command to cause a
1124 * new state to be latched up. So, we just assume that we
1125 * converge to the values we just had set.
1127 * Ensure that we don't believe tagged queuing is enabled yet.
1128 * It turns out that sometimes the ISP just ignores our
1129 * attempts to set parameters for devices that it hasn't
1132 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1133 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1134 mbs.param[0] = MBOX_SET_DEV_QUEUE_PARAMS;
1135 mbs.param[1] = (channel << 15) | (tgt << 8) | lun;
1136 mbs.param[2] = sdp->isp_max_queue_depth;
1137 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1138 isp_mboxcmd(isp, &mbs, MBLOGALL);
1139 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1144 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1145 if (sdp->isp_devparam[tgt].dev_refresh) {
1146 isp->isp_sendmarker |= (1 << channel);
1147 isp->isp_update |= (1 << channel);
1154 * Fibre Channel specific initialization.
1156 * Locks are held before coming here.
1159 isp_fibre_init(struct ispsoftc *isp)
1162 isp_icb_t local, *icbp = &local;
1165 u_int64_t nwwn, pwwn;
1167 fcp = isp->isp_param;
1170 * Do this *before* initializing the firmware.
1172 isp_mark_getpdb_all(isp);
1173 fcp->isp_fwstate = FW_CONFIG_WAIT;
1174 fcp->isp_loopstate = LOOP_NIL;
1177 * If we have no role (neither target nor initiator), return.
1179 if (isp->isp_role == ISP_ROLE_NONE) {
1183 loopid = fcp->isp_loopid;
1184 MEMZERO(icbp, sizeof (*icbp));
1185 icbp->icb_version = ICB_VERSION1;
1188 * Firmware Options are either retrieved from NVRAM or
1189 * are patched elsewhere. We check them for sanity here
1190 * and make changes based on board revision, but otherwise
1191 * let others decide policy.
1195 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1197 if ((isp->isp_type == ISP_HA_FC_2100) && isp->isp_revision < 5) {
1198 fcp->isp_fwoptions &= ~ICBOPT_FAIRNESS;
1202 * We have to use FULL LOGIN even though it resets the loop too much
1203 * because otherwise port database entries don't get updated after
1204 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1206 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1207 fcp->isp_fwoptions |= ICBOPT_FULL_LOGIN;
1211 * Insist on Port Database Update Async notifications
1213 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
1216 * Make sure that target role reflects into fwoptions.
1218 if (isp->isp_role & ISP_ROLE_TARGET) {
1219 fcp->isp_fwoptions |= ICBOPT_TGT_ENABLE;
1221 fcp->isp_fwoptions &= ~ICBOPT_TGT_ENABLE;
1224 if (isp->isp_role & ISP_ROLE_INITIATOR) {
1225 fcp->isp_fwoptions &= ~ICBOPT_INI_DISABLE;
1227 fcp->isp_fwoptions |= ICBOPT_INI_DISABLE;
1231 * Propagate all of this into the ICB structure.
1233 icbp->icb_fwoptions = fcp->isp_fwoptions;
1234 icbp->icb_maxfrmlen = fcp->isp_maxfrmlen;
1235 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN ||
1236 icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1237 isp_prt(isp, ISP_LOGERR,
1238 "bad frame length (%d) from NVRAM- using %d",
1239 fcp->isp_maxfrmlen, ICB_DFLT_FRMLEN);
1240 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1242 icbp->icb_maxalloc = fcp->isp_maxalloc;
1243 if (icbp->icb_maxalloc < 1) {
1244 isp_prt(isp, ISP_LOGERR,
1245 "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1246 icbp->icb_maxalloc = 16;
1248 icbp->icb_execthrottle = fcp->isp_execthrottle;
1249 if (icbp->icb_execthrottle < 1) {
1250 isp_prt(isp, ISP_LOGERR,
1251 "bad execution throttle of %d- using 16",
1252 fcp->isp_execthrottle);
1253 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1255 icbp->icb_retry_delay = fcp->isp_retry_delay;
1256 icbp->icb_retry_count = fcp->isp_retry_count;
1257 icbp->icb_hardaddr = loopid;
1258 if (icbp->icb_hardaddr >= 125) {
1260 * We end up with a Loop ID of 255 for F-Port topologies
1262 if (icbp->icb_hardaddr != 255) {
1263 isp_prt(isp, ISP_LOGERR,
1264 "bad hard address %u- resetting to zero",
1265 icbp->icb_hardaddr);
1267 icbp->icb_hardaddr = 0;
1270 * Right now we just set extended options to prefer point-to-point
1271 * over loop based upon some soft config options.
1273 * NB: for the 2300, ICBOPT_EXTENDED is required.
1275 if (IS_2200(isp) || IS_23XX(isp)) {
1276 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1278 * Prefer or force Point-To-Point instead Loop?
1280 switch(isp->isp_confopts & ISP_CFG_PORT_PREF) {
1282 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1284 case ISP_CFG_NPORT_ONLY:
1285 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1287 case ISP_CFG_LPORT_ONLY:
1288 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1291 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1296 * QLogic recommends that FAST Posting be turned
1297 * off for 23XX cards and instead allow the HBA
1298 * to write response queue entries and interrupt
1299 * after a delay (ZIO).
1301 * If we set ZIO, it will disable fast posting,
1302 * so we don't need to clear it in fwoptions.
1304 * Depending on the role we're selecting, we
1305 * chose fast posting or not as it still is
1306 * a win for target mode.
1309 if (isp->isp_role == ISP_ROLE_TARGET) {
1310 icbp->icb_fwoptions |= ICBOPT_FAST_POST;
1312 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1315 icbp->icb_fwoptions |= ICBOPT_FAST_POST;
1319 * Values, in 100us increments. The default
1320 * is 2 (200us) if a value 0 (default) is
1323 icbp->icb_idelaytimer = 2;
1326 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1327 icbp->icb_zfwoptions |= ICBZOPT_RATE_ONEGB;
1328 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1329 icbp->icb_zfwoptions |= ICBZOPT_RATE_TWOGB;
1331 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1336 #ifndef ISP_NO_RIO_FC
1338 * RIO seems to be enabled in 2100s for fw >= 1.17.0.
1340 * I've had some questionable problems with RIO on 2200.
1341 * More specifically, on a 2204 I had problems with RIO
1342 * on a Linux system where I was dropping commands right
1343 * and left. It's not clear to me what the actual problem
1346 * 23XX Cards do not support RIO. Instead they support ZIO.
1349 if (!IS_23XX(isp) && ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1350 icbp->icb_xfwoptions |= ICBXOPT_RIO_16BIT;
1351 icbp->icb_racctimer = 4;
1352 icbp->icb_idelaytimer = 8;
1358 * For 22XX > 2.1.26 && 23XX, set someoptions.
1359 * XXX: Probably okay for newer 2100 f/w too.
1361 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1363 * Turn on LIP F8 async event (1)
1364 * Turn on generate AE 8013 on all LIP Resets (2)
1365 * Disable LIP F7 switching (8)
1367 mbs.param[0] = MBOX_SET_FIRMWARE_OPTIONS;
1371 isp_mboxcmd(isp, &mbs, MBLOGALL);
1373 icbp->icb_logintime = 30; /* 30 second login timeout */
1376 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
1377 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
1378 ISP_WRITE(isp, isp->isp_respinrp, 0);
1379 ISP_WRITE(isp, isp->isp_respoutrp, 0);
1382 nwwn = ISP_NODEWWN(isp);
1383 pwwn = ISP_PORTWWN(isp);
1385 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1386 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, nwwn);
1387 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, pwwn);
1388 isp_prt(isp, ISP_LOGDEBUG1,
1389 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1390 ((u_int32_t) (nwwn >> 32)),
1391 ((u_int32_t) (nwwn & 0xffffffff)),
1392 ((u_int32_t) (pwwn >> 32)),
1393 ((u_int32_t) (pwwn & 0xffffffff)));
1395 isp_prt(isp, ISP_LOGDEBUG1, "Not using any WWNs");
1396 icbp->icb_fwoptions &= ~(ICBOPT_BOTH_WWNS|ICBOPT_FULL_LOGIN);
1398 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1399 if (icbp->icb_rqstqlen < 1) {
1400 isp_prt(isp, ISP_LOGERR, "bad request queue length");
1402 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1403 if (icbp->icb_rsltqlen < 1) {
1404 isp_prt(isp, ISP_LOGERR, "bad result queue length");
1406 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1407 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1408 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1409 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1410 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1411 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1412 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1413 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1414 isp_prt(isp, ISP_LOGDEBUG0,
1415 "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1416 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1418 FC_SCRATCH_ACQUIRE(isp);
1419 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1424 mbs.param[0] = MBOX_INIT_FIRMWARE;
1426 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1427 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1430 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1431 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1432 isp_mboxcmd(isp, &mbs, MBLOGALL);
1433 FC_SCRATCH_RELEASE(isp);
1434 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1437 isp->isp_reqidx = isp->isp_reqodx = 0;
1438 isp->isp_residx = 0;
1439 isp->isp_sendmarker = 1;
1442 * Whatever happens, we're now committed to being here.
1444 isp->isp_state = ISP_INITSTATE;
1448 * Fibre Channel Support- get the port database for the id.
1450 * Locks are held before coming here. Return 0 if success,
1455 isp_getmap(struct ispsoftc *isp, fcpos_map_t *map)
1457 fcparam *fcp = (fcparam *) isp->isp_param;
1460 mbs.param[0] = MBOX_GET_FC_AL_POSITION_MAP;
1462 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1463 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1465 * Unneeded. For the 2100, except for initializing f/w, registers
1466 * 4/5 have to not be written to.
1473 FC_SCRATCH_ACQUIRE(isp);
1474 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1475 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1476 MEMCPY(map, fcp->isp_scratch, sizeof (fcpos_map_t));
1477 map->fwmap = mbs.param[1] != 0;
1478 FC_SCRATCH_RELEASE(isp);
1481 FC_SCRATCH_RELEASE(isp);
1486 isp_mark_getpdb_all(struct ispsoftc *isp)
1488 fcparam *fcp = (fcparam *) isp->isp_param;
1490 for (i = 0; i < MAX_FC_TARG; i++) {
1491 fcp->portdb[i].valid = fcp->portdb[i].fabric_dev = 0;
1496 isp_getpdb(struct ispsoftc *isp, int id, isp_pdb_t *pdbp)
1498 fcparam *fcp = (fcparam *) isp->isp_param;
1501 mbs.param[0] = MBOX_GET_PORT_DB;
1502 mbs.param[1] = id << 8;
1503 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1504 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1506 * Unneeded. For the 2100, except for initializing f/w, registers
1507 * 4/5 have to not be written to.
1512 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1513 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1514 FC_SCRATCH_ACQUIRE(isp);
1515 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1516 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1517 isp_get_pdb(isp, (isp_pdb_t *)fcp->isp_scratch, pdbp);
1518 FC_SCRATCH_RELEASE(isp);
1521 FC_SCRATCH_RELEASE(isp);
1526 isp_get_portname(struct ispsoftc *isp, int loopid, int nodename)
1531 mbs.param[0] = MBOX_GET_PORT_NAME;
1532 mbs.param[1] = loopid << 8;
1535 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1536 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1538 (((u_int64_t)(mbs.param[2] & 0xff)) << 56) |
1539 (((u_int64_t)(mbs.param[2] >> 8)) << 48) |
1540 (((u_int64_t)(mbs.param[3] & 0xff)) << 40) |
1541 (((u_int64_t)(mbs.param[3] >> 8)) << 32) |
1542 (((u_int64_t)(mbs.param[6] & 0xff)) << 24) |
1543 (((u_int64_t)(mbs.param[6] >> 8)) << 16) |
1544 (((u_int64_t)(mbs.param[7] & 0xff)) << 8) |
1545 (((u_int64_t)(mbs.param[7] >> 8)));
1551 * Make sure we have good FC link and know our Loop ID.
1555 isp_fclink_test(struct ispsoftc *isp, int usdelay)
1557 static char *toponames[] = {
1562 "F Port (no FLOGI_ACC response)"
1565 int count, check_for_fabric;
1571 fcp = isp->isp_param;
1574 * XXX: Here is where we would start a 'loop dead' timeout
1578 * Wait up to N microseconds for F/W to go to a ready state.
1580 lwfs = FW_CONFIG_WAIT;
1582 while (count < usdelay) {
1585 NANOTIME_T hra, hrb;
1589 if (lwfs != fcp->isp_fwstate) {
1590 isp_prt(isp, ISP_LOGINFO, "Firmware State <%s->%s>",
1591 isp2100_fw_statename((int)lwfs),
1592 isp2100_fw_statename((int)fcp->isp_fwstate));
1593 lwfs = fcp->isp_fwstate;
1595 if (fcp->isp_fwstate == FW_READY) {
1601 * Get the elapsed time in nanoseconds.
1602 * Always guaranteed to be non-zero.
1604 enano = NANOTIME_SUB(&hrb, &hra);
1606 isp_prt(isp, ISP_LOGDEBUG1,
1607 "usec%d: 0x%lx->0x%lx enano 0x%x%08x",
1608 count, (long) GET_NANOSEC(&hra), (long) GET_NANOSEC(&hrb),
1609 (u_int32_t)(enano >> 32), (u_int32_t)(enano & 0xffffffff));
1612 * If the elapsed time is less than 1 millisecond,
1613 * delay a period of time up to that millisecond of
1616 * This peculiar code is an attempt to try and avoid
1617 * invoking u_int64_t math support functions for some
1618 * platforms where linkage is a problem.
1620 if (enano < (1000 * 1000)) {
1622 enano = (1000 * 1000) - enano;
1623 while (enano > (u_int64_t) 4000000000U) {
1624 USEC_SLEEP(isp, 4000000);
1625 enano -= (u_int64_t) 4000000000U;
1629 USEC_SLEEP(isp, wrk);
1631 while (enano > (u_int64_t) 4000000000U) {
1633 enano -= (u_int64_t) 4000000000U;
1636 count += (wrk / 1000);
1641 * If we haven't gone to 'ready' state, return.
1643 if (fcp->isp_fwstate != FW_READY) {
1648 * Get our Loop ID (if possible). We really need to have it.
1650 mbs.param[0] = MBOX_GET_LOOP_ID;
1651 isp_mboxcmd(isp, &mbs, MBLOGALL);
1652 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1655 fcp->isp_loopid = mbs.param[1];
1656 if (IS_2200(isp) || IS_23XX(isp)) {
1657 int topo = (int) mbs.param[6];
1658 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB)
1659 topo = TOPO_PTP_STUB;
1660 fcp->isp_topo = topo;
1662 fcp->isp_topo = TOPO_NL_PORT;
1664 fcp->isp_portid = fcp->isp_alpa = mbs.param[2] & 0xff;
1667 * Check to see if we're on a fabric by trying to see if we
1668 * can talk to the fabric name server. This can be a bit
1669 * tricky because if we're a 2100, we should check always
1670 * (in case we're connected to a server doing aliasing).
1672 fcp->isp_onfabric = 0;
1676 * Don't bother with fabric if we are using really old
1677 * 2100 firmware. It's just not worth it.
1679 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37)) {
1680 check_for_fabric = 1;
1682 check_for_fabric = 0;
1684 } else if (fcp->isp_topo == TOPO_FL_PORT ||
1685 fcp->isp_topo == TOPO_F_PORT) {
1686 check_for_fabric = 1;
1688 check_for_fabric = 0;
1690 if (check_for_fabric && isp_getpdb(isp, FL_PORT_ID, &pdb) == 0) {
1691 int loopid = FL_PORT_ID;
1693 fcp->isp_topo = TOPO_FL_PORT;
1696 if (BITS2WORD(pdb.pdb_portid_bits) == 0) {
1700 fcp->isp_topo = TOPO_NL_PORT;
1703 fcp->isp_portid = mbs.param[2] | ((int) mbs.param[3] << 16);
1706 * Save the Fabric controller's port database entry.
1708 lp = &fcp->portdb[loopid];
1710 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1711 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1712 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1713 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1714 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1715 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1716 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1717 (((u_int64_t)pdb.pdb_nodename[7]));
1719 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1720 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1721 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1722 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1723 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1724 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1725 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1726 (((u_int64_t)pdb.pdb_portname[7]));
1728 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
1729 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
1730 lp->loopid = pdb.pdb_loopid;
1731 lp->loggedin = lp->valid = 1;
1732 fcp->isp_onfabric = 1;
1733 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1734 isp_register_fc4_type(isp);
1737 fcp->isp_onfabric = 0;
1738 fcp->portdb[FL_PORT_ID].valid = 0;
1741 fcp->isp_gbspeed = 1;
1743 mbs.param[0] = MBOX_GET_SET_DATA_RATE;
1744 mbs.param[1] = MBGSD_GET_RATE;
1745 /* mbs.param[2] undefined if we're just getting rate */
1746 isp_mboxcmd(isp, &mbs, MBLOGALL);
1747 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1748 if (mbs.param[1] == MBGSD_TWOGB) {
1749 isp_prt(isp, ISP_LOGINFO, "2Gb link speed/s");
1750 fcp->isp_gbspeed = 2;
1755 isp_prt(isp, ISP_LOGCONFIG, topology, fcp->isp_loopid, fcp->isp_alpa,
1756 fcp->isp_portid, fcp->isp_loopstate, toponames[fcp->isp_topo]);
1759 * Announce ourselves, too. This involves synthesizing an entry.
1761 if (fcp->isp_iid_set == 0) {
1762 fcp->isp_iid_set = 1;
1763 fcp->isp_iid = fcp->isp_loopid;
1764 lp = &fcp->portdb[fcp->isp_iid];
1766 lp = &fcp->portdb[fcp->isp_iid];
1767 if (fcp->isp_portid != lp->portid ||
1768 fcp->isp_loopid != lp->loopid ||
1769 fcp->isp_nodewwn != ISP_NODEWWN(isp) ||
1770 fcp->isp_portwwn != ISP_PORTWWN(isp)) {
1772 count = fcp->isp_iid;
1773 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1776 lp->loopid = fcp->isp_loopid;
1777 lp->portid = fcp->isp_portid;
1778 lp->node_wwn = ISP_NODEWWN(isp);
1779 lp->port_wwn = ISP_PORTWWN(isp);
1780 switch (isp->isp_role) {
1784 case ISP_ROLE_TARGET:
1785 lp->roles = SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT;
1787 case ISP_ROLE_INITIATOR:
1788 lp->roles = SVC3_INI_ROLE >> SVC3_ROLE_SHIFT;
1791 lp->roles = (SVC3_INI_ROLE|SVC3_TGT_ROLE) >> SVC3_ROLE_SHIFT;
1794 lp->loggedin = lp->valid = 1;
1795 count = fcp->isp_iid;
1796 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1801 isp2100_fw_statename(int state)
1804 case FW_CONFIG_WAIT: return "Config Wait";
1805 case FW_WAIT_AL_PA: return "Waiting for AL_PA";
1806 case FW_WAIT_LOGIN: return "Wait Login";
1807 case FW_READY: return "Ready";
1808 case FW_LOSS_OF_SYNC: return "Loss Of Sync";
1809 case FW_ERROR: return "Error";
1810 case FW_REINIT: return "Re-Init";
1811 case FW_NON_PART: return "Nonparticipating";
1812 default: return "?????";
1817 * Synchronize our soft copy of the port database with what the f/w thinks
1818 * (with a view toward possibly for a specific target....)
1822 isp_pdb_sync(struct ispsoftc *isp)
1825 fcparam *fcp = isp->isp_param;
1827 int loopid, base, lim;
1830 * Make sure we're okay for doing this right now.
1832 if (fcp->isp_loopstate != LOOP_PDB_RCVD &&
1833 fcp->isp_loopstate != LOOP_FSCAN_DONE &&
1834 fcp->isp_loopstate != LOOP_LSCAN_DONE) {
1838 if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_NL_PORT ||
1839 fcp->isp_topo == TOPO_N_PORT) {
1840 if (fcp->isp_loopstate < LOOP_LSCAN_DONE) {
1841 if (isp_scan_loop(isp) != 0) {
1846 fcp->isp_loopstate = LOOP_SYNCING_PDB;
1849 * If we get this far, we've settled our differences with the f/w
1850 * (for local loop device) and we can say that the loop state is ready.
1853 if (fcp->isp_topo == TOPO_NL_PORT) {
1854 fcp->loop_seen_once = 1;
1855 fcp->isp_loopstate = LOOP_READY;
1860 * Find all Fabric Entities that didn't make it from one scan to the
1861 * next and let the world know they went away. Scan the whole database.
1863 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[MAX_FC_TARG]; lp++) {
1864 if (lp->was_fabric_dev && lp->fabric_dev == 0) {
1865 loopid = lp - fcp->portdb;
1866 lp->valid = 0; /* should already be set */
1867 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1868 MEMZERO((void *) lp, sizeof (*lp));
1871 lp->was_fabric_dev = lp->fabric_dev;
1874 if (fcp->isp_topo == TOPO_FL_PORT)
1879 if (fcp->isp_topo == TOPO_N_PORT)
1885 * Now log in any fabric devices that the outer layer has
1886 * left for us to see. This seems the most sane policy
1889 for (lp = &fcp->portdb[base]; lp < &fcp->portdb[lim]; lp++) {
1893 loopid = lp - fcp->portdb;
1894 if (loopid >= FL_PORT_ID && loopid <= FC_SNS_ID) {
1901 if (lp->port_wwn == 0) {
1906 * Don't try to log into yourself.
1908 if ((portid = lp->portid) == fcp->isp_portid) {
1914 * If we'd been logged in- see if we still are and we haven't
1915 * changed. If so, no need to log ourselves out, etc..
1917 * Unfortunately, our charming Qlogic f/w has decided to
1918 * return a valid port database entry for a fabric device
1919 * that has, in fact, gone away. And it hangs trying to
1922 if (lp->loggedin && lp->force_logout == 0 &&
1923 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
1925 u_int64_t nwwnn, nwwpn;
1927 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1928 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1929 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1930 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1931 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1932 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1933 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1934 (((u_int64_t)pdb.pdb_nodename[7]));
1936 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1937 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1938 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1939 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1940 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1941 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1942 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1943 (((u_int64_t)pdb.pdb_portname[7]));
1944 nrole = (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >>
1946 if (pdb.pdb_loopid == lp->loopid && lp->portid ==
1947 (u_int32_t) BITS2WORD(pdb.pdb_portid_bits) &&
1948 nwwnn == lp->node_wwn && nwwpn == lp->port_wwn &&
1949 lp->roles == nrole && lp->force_logout == 0) {
1950 lp->loggedin = lp->valid = 1;
1951 isp_prt(isp, ISP_LOGCONFIG, lretained,
1952 (int) (lp - fcp->portdb),
1953 (int) lp->loopid, lp->portid);
1958 if (fcp->isp_fwstate != FW_READY ||
1959 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1964 * Force a logout if we were logged in.
1967 if (lp->force_logout ||
1968 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
1969 mbs.param[0] = MBOX_FABRIC_LOGOUT;
1970 mbs.param[1] = lp->loopid << 8;
1973 isp_mboxcmd(isp, &mbs, MBLOGNONE);
1974 isp_prt(isp, ISP_LOGINFO, plogout,
1975 (int) (lp - fcp->portdb), lp->loopid,
1978 lp->force_logout = lp->loggedin = 0;
1979 if (fcp->isp_fwstate != FW_READY ||
1980 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1988 loopid = lp - fcp->portdb;
1989 lp->loopid = FL_PORT_ID;
1991 mbs.param[0] = MBOX_FABRIC_LOGIN;
1992 mbs.param[1] = loopid << 8;
1993 mbs.param[2] = portid >> 16;
1994 mbs.param[3] = portid & 0xffff;
1995 isp_mboxcmd(isp, &mbs, MBLOGALL & ~(MBOX_LOOP_ID_USED |
1996 MBOX_PORT_ID_USED | MBOX_COMMAND_ERROR));
1997 if (fcp->isp_fwstate != FW_READY ||
1998 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2001 switch (mbs.param[0]) {
2002 case MBOX_LOOP_ID_USED:
2004 * Try the next available loop id.
2008 case MBOX_PORT_ID_USED:
2010 * This port is already logged in.
2011 * Snaffle the loop id it's using if it's
2012 * nonzero, otherwise we're hosed.
2014 if (mbs.param[1] != 0) {
2015 loopid = mbs.param[1];
2016 isp_prt(isp, ISP_LOGINFO, retained,
2017 loopid, (int) (lp - fcp->portdb),
2020 loopid = MAX_FC_TARG;
2024 case MBOX_COMMAND_COMPLETE:
2026 lp->loopid = loopid;
2028 case MBOX_COMMAND_ERROR:
2029 isp_prt(isp, ISP_LOGINFO, plogierr,
2030 portid, mbs.param[1]);
2032 case MBOX_ALL_IDS_USED: /* We're outta IDs */
2034 loopid = MAX_FC_TARG;
2037 } while (lp->loopid == FL_PORT_ID && loopid < MAX_FC_TARG);
2040 * If we get here and we haven't set a Loop ID,
2041 * we failed to log into this device.
2044 if (lp->loopid == FL_PORT_ID) {
2050 * Make sure we can get the approriate port information.
2052 if (isp_getpdb(isp, lp->loopid, &pdb) != 0) {
2053 isp_prt(isp, ISP_LOGWARN, nopdb, lp->portid);
2057 if (fcp->isp_fwstate != FW_READY ||
2058 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2062 if (pdb.pdb_loopid != lp->loopid) {
2063 isp_prt(isp, ISP_LOGWARN, pdbmfail1,
2064 lp->portid, pdb.pdb_loopid);
2068 if (lp->portid != (u_int32_t) BITS2WORD(pdb.pdb_portid_bits)) {
2069 isp_prt(isp, ISP_LOGWARN, pdbmfail2,
2070 lp->portid, BITS2WORD(pdb.pdb_portid_bits));
2075 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2077 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
2078 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
2079 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
2080 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
2081 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
2082 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
2083 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
2084 (((u_int64_t)pdb.pdb_nodename[7]));
2086 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
2087 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
2088 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
2089 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
2090 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
2091 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
2092 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
2093 (((u_int64_t)pdb.pdb_portname[7]));
2095 * Check to make sure this all makes sense.
2097 if (lp->node_wwn && lp->port_wwn) {
2099 loopid = lp - fcp->portdb;
2100 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2105 isp_prt(isp, ISP_LOGINFO,
2106 ldumped, loopid, lp->loopid, lp->portid);
2107 mbs.param[0] = MBOX_FABRIC_LOGOUT;
2108 mbs.param[1] = lp->loopid << 8;
2111 isp_mboxcmd(isp, &mbs, MBLOGNONE);
2112 if (fcp->isp_fwstate != FW_READY ||
2113 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2118 * If we get here, we've for sure seen not only a valid loop
2119 * but know what is or isn't on it, so mark this for usage
2122 fcp->loop_seen_once = 1;
2123 fcp->isp_loopstate = LOOP_READY;
2128 isp_scan_loop(struct ispsoftc *isp)
2131 fcparam *fcp = isp->isp_param;
2133 int loopid, lim, hival;
2135 switch (fcp->isp_topo) {
2146 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2149 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
2152 * make sure the temp port database is clean...
2154 MEMZERO((void *)fcp->tport, sizeof (fcp->tport));
2157 * Run through the local loop ports and get port database info
2160 * There's a somewhat unexplained situation where the f/w passes back
2161 * the wrong database entity- if that happens, just restart (up to
2162 * FL_PORT_ID times).
2164 for (lim = loopid = 0; loopid < hival; loopid++) {
2165 lp = &fcp->tport[loopid];
2168 * Don't even try for ourselves...
2170 if (loopid == fcp->isp_loopid)
2173 lp->node_wwn = isp_get_portname(isp, loopid, 1);
2174 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2176 if (lp->node_wwn == 0)
2178 lp->port_wwn = isp_get_portname(isp, loopid, 0);
2179 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2181 if (lp->port_wwn == 0) {
2189 if (isp_getpdb(isp, loopid, &pdb) != 0) {
2190 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2194 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2199 * If the returned database element doesn't match what we
2200 * asked for, restart the process entirely (up to a point...).
2202 if (pdb.pdb_loopid != loopid) {
2204 if (lim++ < hival) {
2207 isp_prt(isp, ISP_LOGWARN,
2208 "giving up on synchronizing the port database");
2213 * Save the pertinent info locally.
2216 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
2217 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
2218 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
2219 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
2220 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
2221 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
2222 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
2223 (((u_int64_t)pdb.pdb_nodename[7]));
2225 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
2226 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
2227 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
2228 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
2229 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
2230 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
2231 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
2232 (((u_int64_t)pdb.pdb_portname[7]));
2234 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2235 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
2236 lp->loopid = pdb.pdb_loopid;
2240 * Mark all of the permanent local loop database entries as invalid
2241 * (except our own entry).
2243 for (loopid = 0; loopid < hival; loopid++) {
2244 if (loopid == fcp->isp_iid) {
2245 fcp->portdb[loopid].valid = 1;
2246 fcp->portdb[loopid].loopid = fcp->isp_loopid;
2249 fcp->portdb[loopid].valid = 0;
2253 * Now merge our local copy of the port database into our saved copy.
2254 * Notify the outer layers of new devices arriving.
2256 for (loopid = 0; loopid < hival; loopid++) {
2260 * If we don't have a non-zero Port WWN, we're not here.
2262 if (fcp->tport[loopid].port_wwn == 0) {
2269 if (loopid == fcp->isp_iid) {
2274 * For the purposes of deciding whether this is the
2275 * 'same' device or not, we only search for an identical
2276 * Port WWN. Node WWNs may or may not be the same as
2277 * the Port WWN, and there may be multiple different
2278 * Port WWNs with the same Node WWN. It would be chaos
2279 * to have multiple identical Port WWNs, so we don't
2283 for (i = 0; i < hival; i++) {
2285 if (fcp->portdb[i].port_wwn == 0)
2287 if (fcp->portdb[i].port_wwn !=
2288 fcp->tport[loopid].port_wwn)
2291 * We found this WWN elsewhere- it's changed
2292 * loopids then. We don't change it's actual
2293 * position in our cached port database- we
2294 * just change the actual loop ID we'd use.
2296 if (fcp->portdb[i].loopid != loopid) {
2297 isp_prt(isp, ISP_LOGINFO, portshift, i,
2298 fcp->portdb[i].loopid,
2299 fcp->portdb[i].portid, loopid,
2300 fcp->tport[loopid].portid);
2302 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2303 fcp->portdb[i].loopid = loopid;
2304 fcp->portdb[i].valid = 1;
2305 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2308 * Now make sure this Port WWN doesn't exist elsewhere
2309 * in the port database.
2311 for (j = i+1; j < hival; j++) {
2312 if (fcp->portdb[i].port_wwn !=
2313 fcp->portdb[j].port_wwn) {
2316 isp_prt(isp, ISP_LOGWARN, portdup, j, i);
2318 * Invalidate the 'old' *and* 'new' ones.
2319 * This is really harsh and not quite right,
2320 * but if this happens, we really don't know
2321 * who is what at this point.
2323 fcp->portdb[i].valid = 0;
2324 fcp->portdb[j].valid = 0;
2330 * If we didn't traverse the entire port database,
2331 * then we found (and remapped) an existing entry.
2332 * No need to notify anyone- go for the next one.
2335 isp_prt(isp, ISP_LOGINFO, retained,
2336 fcp->portdb[i].loopid, i, fcp->portdb[i].portid);
2341 * We've not found this Port WWN anywhere. It's a new entry.
2342 * See if we can leave it where it is (with target == loopid).
2344 if (fcp->portdb[loopid].port_wwn != 0) {
2345 for (lim = 0; lim < hival; lim++) {
2346 if (fcp->portdb[lim].port_wwn == 0)
2349 /* "Cannot Happen" */
2351 isp_prt(isp, ISP_LOGWARN, "Remap Overflow");
2360 * NB: The actual loopid we use here is loopid- we may
2361 * in fact be at a completely different index (target).
2363 fcp->portdb[i].loopid = loopid;
2364 fcp->portdb[i].port_wwn = fcp->tport[loopid].port_wwn;
2365 fcp->portdb[i].node_wwn = fcp->tport[loopid].node_wwn;
2366 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2367 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2368 fcp->portdb[i].valid = 1;
2371 * Tell the outside world we've arrived.
2373 (void) isp_async(isp, ISPASYNC_PROMENADE, &i);
2377 * Now find all previously used targets that are now invalid and
2378 * notify the outer layers that they're gone.
2380 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[hival]; lp++) {
2381 if (lp->valid || lp->port_wwn == 0) {
2386 * Tell the outside world we've gone
2387 * away and erase our pdb entry.
2390 loopid = lp - fcp->portdb;
2391 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2392 MEMZERO((void *) lp, sizeof (*lp));
2394 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2400 isp_fabric_mbox_cmd(struct ispsoftc *isp, mbreg_t *mbp)
2402 isp_mboxcmd(isp, mbp, MBLOGNONE);
2403 if (mbp->param[0] != MBOX_COMMAND_COMPLETE) {
2404 if (FCPARAM(isp)->isp_loopstate == LOOP_SCANNING_FABRIC) {
2405 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
2407 if (mbp->param[0] == MBOX_COMMAND_ERROR) {
2410 switch (mbp->param[1]) {
2415 m = "Failed to allocate IOCB buffer";
2418 m = "Failed to allocate XCB buffer";
2421 m = "timeout or transmit failed";
2424 m = "no fabric loop";
2427 m = "remote device not a target";
2430 SNPRINTF(tbuf, sizeof tbuf, "%x",
2435 isp_prt(isp, ISP_LOGERR, "SNS Failed- %s", m);
2440 if (FCPARAM(isp)->isp_fwstate != FW_READY ||
2441 FCPARAM(isp)->isp_loopstate < LOOP_SCANNING_FABRIC) {
2447 #ifdef ISP_USE_GA_NXT
2449 isp_scan_fabric(struct ispsoftc *isp, int ftype)
2451 fcparam *fcp = isp->isp_param;
2452 u_int32_t portid, first_portid, last_portid;
2453 int hicap, last_port_same;
2455 if (fcp->isp_onfabric == 0) {
2456 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2460 FC_SCRATCH_ACQUIRE(isp);
2463 * Since Port IDs are 24 bits, we can check against having seen
2464 * anything yet with this value.
2467 last_portid = 0xffffffff; /* not a port */
2468 first_portid = portid = fcp->isp_portid;
2469 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2471 for (hicap = 0; hicap < GA_NXT_MAX; hicap++) {
2474 sns_ga_nxt_rsp_t *rs0, *rs1;
2476 u_int8_t sc[SNS_GA_NXT_RESP_SIZE];
2478 rq = (sns_screq_t *)sc;
2479 MEMZERO((void *) rq, SNS_GA_NXT_REQ_SIZE);
2480 rq->snscb_rblen = SNS_GA_NXT_RESP_SIZE >> 1;
2481 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+0x100);
2482 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+0x100);
2483 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+0x100);
2484 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+0x100);
2485 rq->snscb_sblen = 6;
2486 rq->snscb_data[0] = SNS_GA_NXT;
2487 rq->snscb_data[4] = portid & 0xffff;
2488 rq->snscb_data[5] = (portid >> 16) & 0xff;
2489 isp_put_sns_request(isp, rq, (sns_screq_t *) fcp->isp_scratch);
2490 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GA_NXT_REQ_SIZE);
2491 mbs.param[0] = MBOX_SEND_SNS;
2492 mbs.param[1] = SNS_GA_NXT_REQ_SIZE >> 1;
2493 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2494 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2496 * Leave 4 and 5 alone
2498 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2499 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2500 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2501 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2502 fcp->isp_loopstate = LOOP_PDB_RCVD;
2504 FC_SCRATCH_RELEASE(isp);
2507 MEMORYBARRIER(isp, SYNC_SFORCPU, 0x100, SNS_GA_NXT_RESP_SIZE);
2508 rs1 = (sns_ga_nxt_rsp_t *) sc;
2509 rs0 = (sns_ga_nxt_rsp_t *) ((u_int8_t *)fcp->isp_scratch+0x100);
2510 isp_get_ga_nxt_response(isp, rs0, rs1);
2511 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2513 if (rs1->snscb_cthdr.ct_reason == 9 &&
2514 rs1->snscb_cthdr.ct_explanation == 7)
2515 level = ISP_LOGDEBUG0;
2517 level = ISP_LOGWARN;
2518 isp_prt(isp, level, swrej, "GA_NXT",
2519 rs1->snscb_cthdr.ct_reason,
2520 rs1->snscb_cthdr.ct_explanation, portid);
2521 FC_SCRATCH_RELEASE(isp);
2522 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2526 (((u_int32_t) rs1->snscb_port_id[0]) << 16) |
2527 (((u_int32_t) rs1->snscb_port_id[1]) << 8) |
2528 (((u_int32_t) rs1->snscb_port_id[2]));
2531 * XXX: We should check to make sure that this entry
2532 * XXX: supports the type(s) we are interested in.
2535 * Okay, we now have information about a fabric object.
2536 * If it is the type we're interested in, tell the outer layers
2537 * about it. The outer layer needs to know: Port ID, WWNN,
2538 * WWPN, FC4 type, and port type.
2540 * The lportdb structure is adequate for this.
2542 MEMZERO(&lcl, sizeof (lcl));
2543 lcl.port_type = rs1->snscb_port_type;
2544 lcl.fc4_type = ftype;
2545 lcl.portid = portid;
2547 (((u_int64_t)rs1->snscb_nodename[0]) << 56) |
2548 (((u_int64_t)rs1->snscb_nodename[1]) << 48) |
2549 (((u_int64_t)rs1->snscb_nodename[2]) << 40) |
2550 (((u_int64_t)rs1->snscb_nodename[3]) << 32) |
2551 (((u_int64_t)rs1->snscb_nodename[4]) << 24) |
2552 (((u_int64_t)rs1->snscb_nodename[5]) << 16) |
2553 (((u_int64_t)rs1->snscb_nodename[6]) << 8) |
2554 (((u_int64_t)rs1->snscb_nodename[7]));
2556 (((u_int64_t)rs1->snscb_portname[0]) << 56) |
2557 (((u_int64_t)rs1->snscb_portname[1]) << 48) |
2558 (((u_int64_t)rs1->snscb_portname[2]) << 40) |
2559 (((u_int64_t)rs1->snscb_portname[3]) << 32) |
2560 (((u_int64_t)rs1->snscb_portname[4]) << 24) |
2561 (((u_int64_t)rs1->snscb_portname[5]) << 16) |
2562 (((u_int64_t)rs1->snscb_portname[6]) << 8) |
2563 (((u_int64_t)rs1->snscb_portname[7]));
2566 * Does this fabric object support the type we want?
2569 if (rs1->snscb_fc4_types[ftype >> 5] & (1 << (ftype & 0x1f))) {
2570 if (first_portid == portid) {
2571 lcl.last_fabric_dev = 1;
2573 lcl.last_fabric_dev = 0;
2575 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2577 isp_prt(isp, ISP_LOGDEBUG0,
2578 "PortID 0x%x doesn't support FC4 type 0x%x",
2581 if (first_portid == portid) {
2582 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2583 FC_SCRATCH_RELEASE(isp);
2586 if (portid == last_portid) {
2587 if (last_port_same++ > 20) {
2588 isp_prt(isp, ISP_LOGWARN,
2589 "tangled fabric database detected");
2593 last_port_same = 0 ;
2594 last_portid = portid;
2597 FC_SCRATCH_RELEASE(isp);
2598 if (hicap >= GA_NXT_MAX) {
2599 isp_prt(isp, ISP_LOGWARN, "fabric too big (> %d)", GA_NXT_MAX);
2601 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2605 #define GIDLEN ((ISP2100_SCRLEN >> 1) + 16)
2606 #define NGENT ((GIDLEN - 16) >> 2)
2608 #define IGPOFF (ISP2100_SCRLEN - GIDLEN)
2612 isp_scan_fabric(struct ispsoftc *isp, int ftype)
2614 fcparam *fcp = FCPARAM(isp);
2617 sns_gid_ft_req_t *rq;
2618 sns_gid_ft_rsp_t *rs0, *rs1;
2620 if (fcp->isp_onfabric == 0) {
2621 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2625 FC_SCRATCH_ACQUIRE(isp);
2626 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2628 rq = (sns_gid_ft_req_t *)fcp->tport;
2629 MEMZERO((void *) rq, SNS_GID_FT_REQ_SIZE);
2630 rq->snscb_rblen = GIDLEN >> 1;
2631 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+IGPOFF);
2632 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+IGPOFF);
2633 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+IGPOFF);
2634 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+IGPOFF);
2635 rq->snscb_sblen = 6;
2636 rq->snscb_cmd = SNS_GID_FT;
2637 rq->snscb_mword_div_2 = NGENT;
2638 rq->snscb_fc4_type = ftype;
2639 isp_put_gid_ft_request(isp, rq, (sns_gid_ft_req_t *) fcp->isp_scratch);
2640 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE);
2641 mbs.param[0] = MBOX_SEND_SNS;
2642 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
2643 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2644 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2647 * Leave 4 and 5 alone
2649 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2650 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2651 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2652 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2653 fcp->isp_loopstate = LOOP_PDB_RCVD;
2655 FC_SCRATCH_RELEASE(isp);
2658 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2659 FC_SCRATCH_RELEASE(isp);
2662 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN);
2663 rs1 = (sns_gid_ft_rsp_t *) fcp->tport;
2664 rs0 = (sns_gid_ft_rsp_t *) ((u_int8_t *)fcp->isp_scratch+IGPOFF);
2665 isp_get_gid_ft_response(isp, rs0, rs1, NGENT);
2666 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2668 if (rs1->snscb_cthdr.ct_reason == 9 &&
2669 rs1->snscb_cthdr.ct_explanation == 7)
2670 level = ISP_LOGDEBUG0;
2672 level = ISP_LOGWARN;
2673 isp_prt(isp, level, swrej, "GID_FT",
2674 rs1->snscb_cthdr.ct_reason,
2675 rs1->snscb_cthdr.ct_explanation, 0);
2676 FC_SCRATCH_RELEASE(isp);
2677 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2682 * Okay, we now have a list of Port IDs for this class of device.
2683 * Go through the list and for each one get the WWPN/WWNN for it
2684 * and tell the outer layers about it. The outer layer needs to
2685 * know: Port ID, WWNN, WWPN, FC4 type, and (possibly) port type.
2687 * The lportdb structure is adequate for this.
2691 sns_gxn_id_req_t grqbuf, *gq = &grqbuf;
2692 sns_gxn_id_rsp_t *gs0, grsbuf, *gs1 = &grsbuf;
2695 sns_gff_id_rsp_t *fs0, ffsbuf, *fs1 = &ffsbuf;
2699 MEMZERO(&lcl, sizeof (lcl));
2700 lcl.fc4_type = ftype;
2702 (((u_int32_t) rs1->snscb_ports[i].portid[0]) << 16) |
2703 (((u_int32_t) rs1->snscb_ports[i].portid[1]) << 8) |
2704 (((u_int32_t) rs1->snscb_ports[i].portid[2]));
2706 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2707 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2708 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2709 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2710 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2711 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2712 gq->snscb_sblen = 6;
2713 gq->snscb_cmd = SNS_GPN_ID;
2714 gq->snscb_portid = lcl.portid;
2715 isp_put_gxn_id_request(isp, gq,
2716 (sns_gxn_id_req_t *) fcp->isp_scratch);
2717 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2718 mbs.param[0] = MBOX_SEND_SNS;
2719 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2720 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2721 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2723 * Leave 4 and 5 alone
2725 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2726 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2727 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2728 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2729 fcp->isp_loopstate = LOOP_PDB_RCVD;
2731 FC_SCRATCH_RELEASE(isp);
2734 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2735 FC_SCRATCH_RELEASE(isp);
2738 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2739 gs0 = (sns_gxn_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2740 isp_get_gxn_id_response(isp, gs0, gs1);
2741 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2742 isp_prt(isp, ISP_LOGWARN, swrej, "GPN_ID",
2743 gs1->snscb_cthdr.ct_reason,
2744 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2745 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2746 FC_SCRATCH_RELEASE(isp);
2752 (((u_int64_t)gs1->snscb_wwn[0]) << 56) |
2753 (((u_int64_t)gs1->snscb_wwn[1]) << 48) |
2754 (((u_int64_t)gs1->snscb_wwn[2]) << 40) |
2755 (((u_int64_t)gs1->snscb_wwn[3]) << 32) |
2756 (((u_int64_t)gs1->snscb_wwn[4]) << 24) |
2757 (((u_int64_t)gs1->snscb_wwn[5]) << 16) |
2758 (((u_int64_t)gs1->snscb_wwn[6]) << 8) |
2759 (((u_int64_t)gs1->snscb_wwn[7]));
2761 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2762 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2763 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2764 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2765 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2766 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2767 gq->snscb_sblen = 6;
2768 gq->snscb_cmd = SNS_GNN_ID;
2769 gq->snscb_portid = lcl.portid;
2770 isp_put_gxn_id_request(isp, gq,
2771 (sns_gxn_id_req_t *) fcp->isp_scratch);
2772 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2773 mbs.param[0] = MBOX_SEND_SNS;
2774 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2775 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2776 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2778 * Leave 4 and 5 alone
2780 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2781 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2782 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2783 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2784 fcp->isp_loopstate = LOOP_PDB_RCVD;
2786 FC_SCRATCH_RELEASE(isp);
2789 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2790 FC_SCRATCH_RELEASE(isp);
2793 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2794 gs0 = (sns_gxn_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2795 isp_get_gxn_id_response(isp, gs0, gs1);
2796 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2797 isp_prt(isp, ISP_LOGWARN, swrej, "GNN_ID",
2798 gs1->snscb_cthdr.ct_reason,
2799 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2800 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2801 FC_SCRATCH_RELEASE(isp);
2807 (((u_int64_t)gs1->snscb_wwn[0]) << 56) |
2808 (((u_int64_t)gs1->snscb_wwn[1]) << 48) |
2809 (((u_int64_t)gs1->snscb_wwn[2]) << 40) |
2810 (((u_int64_t)gs1->snscb_wwn[3]) << 32) |
2811 (((u_int64_t)gs1->snscb_wwn[4]) << 24) |
2812 (((u_int64_t)gs1->snscb_wwn[5]) << 16) |
2813 (((u_int64_t)gs1->snscb_wwn[6]) << 8) |
2814 (((u_int64_t)gs1->snscb_wwn[7]));
2817 * The QLogic f/w is bouncing this with a parameter error.
2821 * Try and get FC4 Features (FC-GS-3 only).
2822 * We can use the sns_gxn_id_req_t for this request.
2824 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2825 gq->snscb_rblen = SNS_GFF_ID_RESP_SIZE >> 1;
2826 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2827 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2828 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2829 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2830 gq->snscb_sblen = 6;
2831 gq->snscb_cmd = SNS_GFF_ID;
2832 gq->snscb_portid = lcl.portid;
2833 isp_put_gxn_id_request(isp, gq,
2834 (sns_gxn_id_req_t *) fcp->isp_scratch);
2835 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2836 mbs.param[0] = MBOX_SEND_SNS;
2837 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2838 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2839 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2841 * Leave 4 and 5 alone
2843 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2844 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2845 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2846 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2847 fcp->isp_loopstate = LOOP_PDB_RCVD;
2849 FC_SCRATCH_RELEASE(isp);
2852 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2853 FC_SCRATCH_RELEASE(isp);
2856 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GFF_ID_RESP_SIZE);
2857 fs0 = (sns_gff_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2858 isp_get_gff_id_response(isp, fs0, fs1);
2859 if (fs1->snscb_cthdr.ct_response != FS_ACC) {
2860 isp_prt(isp, /* ISP_LOGDEBUG0 */ ISP_LOGWARN,
2862 fs1->snscb_cthdr.ct_reason,
2863 fs1->snscb_cthdr.ct_explanation, lcl.portid);
2864 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2865 FC_SCRATCH_RELEASE(isp);
2869 int index = (ftype >> 3);
2870 int bshft = (ftype & 0x7) * 4;
2872 (fs1->snscb_fc4_features[index] >> bshft) & 0xf;
2873 if (fc4_fval & 0x1) {
2875 (SVC3_INI_ROLE >> SVC3_ROLE_SHIFT);
2877 if (fc4_fval & 0x2) {
2879 (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT);
2885 * If we really want to know what kind of port type this is,
2886 * we have to run another CT command. Otherwise, we'll leave
2891 if (rs1->snscb_ports[i].control & 0x80) {
2892 lcl.last_fabric_dev = 1;
2894 lcl.last_fabric_dev = 0;
2896 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2898 } while ((rs1->snscb_ports[i].control & 0x80) == 0 && i < NGENT-1);
2901 * If we're not at the last entry, our list isn't big enough.
2903 if ((rs1->snscb_ports[i].control & 0x80) == 0) {
2904 isp_prt(isp, ISP_LOGWARN, "fabric too big for scratch area");
2907 FC_SCRATCH_RELEASE(isp);
2908 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2914 isp_register_fc4_type(struct ispsoftc *isp)
2916 fcparam *fcp = isp->isp_param;
2917 u_int8_t local[SNS_RFT_ID_REQ_SIZE];
2918 sns_screq_t *reqp = (sns_screq_t *) local;
2921 MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
2922 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
2923 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
2924 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
2925 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
2926 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
2927 reqp->snscb_sblen = 22;
2928 reqp->snscb_data[0] = SNS_RFT_ID;
2929 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
2930 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
2931 reqp->snscb_data[6] = (1 << FC4_SCSI);
2933 reqp->snscb_data[6] |= (1 << FC4_IP); /* ISO/IEC 8802-2 LLC/SNAP */
2935 FC_SCRATCH_ACQUIRE(isp);
2936 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
2937 mbs.param[0] = MBOX_SEND_SNS;
2938 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
2939 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2940 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2942 * Leave 4 and 5 alone
2944 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2945 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2946 isp_mboxcmd(isp, &mbs, MBLOGALL);
2947 FC_SCRATCH_RELEASE(isp);
2948 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
2949 isp_prt(isp, ISP_LOGDEBUG0, "Register FC4 types succeeded");
2954 * Start a command. Locking is assumed done in the caller.
2960 struct ispsoftc *isp;
2961 u_int16_t nxti, optr, handle;
2962 u_int8_t local[QENTRY_LEN];
2963 ispreq_t *reqp, *qep;
2970 * Check to make sure we're supporting initiator role.
2972 if ((isp->isp_role & ISP_ROLE_INITIATOR) == 0) {
2973 XS_SETERR(xs, HBA_SELTIMEOUT);
2974 return (CMD_COMPLETE);
2978 * Now make sure we're running.
2981 if (isp->isp_state != ISP_RUNSTATE) {
2982 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
2983 XS_SETERR(xs, HBA_BOTCH);
2984 return (CMD_COMPLETE);
2988 * Check command CDB length, etc.. We really are limited to 16 bytes
2989 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
2990 * but probably only if we're running fairly new firmware (we'll
2991 * let the old f/w choke on an extended command queue entry).
2994 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
2995 isp_prt(isp, ISP_LOGERR,
2996 "unsupported cdb length (%d, CDB[0]=0x%x)",
2997 XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
2998 XS_SETERR(xs, HBA_BOTCH);
2999 return (CMD_COMPLETE);
3003 * Check to see whether we have good firmware state still or
3004 * need to refresh our port database for this target.
3006 target = XS_TGT(xs);
3008 fcparam *fcp = isp->isp_param;
3010 #ifdef HANDLE_LOOPSTATE_IN_OUTER_LAYERS
3011 if (fcp->isp_fwstate != FW_READY ||
3012 fcp->isp_loopstate != LOOP_READY) {
3013 return (CMD_RQLATER);
3017 * If we're not on a Fabric, we can't have a target
3018 * above FL_PORT_ID-1.
3020 * If we're on a fabric and *not* connected as an F-port,
3021 * we can't have a target less than FC_SNS_ID+1. This
3022 * keeps us from having to sort out the difference between
3023 * local public loop devices and those which we might get
3024 * from a switch's database.
3026 if (fcp->isp_onfabric == 0) {
3027 if (target >= FL_PORT_ID) {
3028 XS_SETERR(xs, HBA_SELTIMEOUT);
3029 return (CMD_COMPLETE);
3032 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3033 XS_SETERR(xs, HBA_SELTIMEOUT);
3034 return (CMD_COMPLETE);
3037 * We used to exclude having local loop ports
3038 * at the same time that we have fabric ports.
3039 * That is, we used to exclude having ports
3040 * at < FL_PORT_ID if we're FL-port.
3042 * That's wrong. The only thing that could be
3043 * dicey is if the switch you're connected to
3044 * has these local loop ports appear on the
3045 * fabric and we somehow attach them twice.
3050 * Check for f/w being in ready state. If the f/w
3051 * isn't in ready state, then we don't know our
3052 * loop ID and the f/w hasn't completed logging
3053 * into all targets on the loop. If this is the
3054 * case, then bounce the command. We pretend this is
3055 * a SELECTION TIMEOUT error if we've never gone to
3056 * FW_READY state at all- in this case we may not
3057 * be hooked to a loop at all and we shouldn't hang
3058 * the machine for this. Otherwise, defer this command
3061 if (fcp->isp_fwstate != FW_READY) {
3063 * Give ourselves at most a 250ms delay.
3065 if (isp_fclink_test(isp, 250000)) {
3066 XS_SETERR(xs, HBA_SELTIMEOUT);
3067 if (fcp->loop_seen_once) {
3068 return (CMD_RQLATER);
3070 return (CMD_COMPLETE);
3076 * If we're not on a Fabric, we can't have a target
3077 * above FL_PORT_ID-1.
3079 * If we're on a fabric and *not* connected as an F-port,
3080 * we can't have a target less than FC_SNS_ID+1. This
3081 * keeps us from having to sort out the difference between
3082 * local public loop devices and those which we might get
3083 * from a switch's database.
3085 if (fcp->isp_onfabric == 0) {
3086 if (target >= FL_PORT_ID) {
3087 XS_SETERR(xs, HBA_SELTIMEOUT);
3088 return (CMD_COMPLETE);
3091 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3092 XS_SETERR(xs, HBA_SELTIMEOUT);
3093 return (CMD_COMPLETE);
3095 if (fcp->isp_topo != TOPO_F_PORT &&
3096 target < FL_PORT_ID) {
3097 XS_SETERR(xs, HBA_SELTIMEOUT);
3098 return (CMD_COMPLETE);
3103 * If our loop state is such that we haven't yet received
3104 * a "Port Database Changed" notification (after a LIP or
3105 * a Loop Reset or firmware initialization), then defer
3106 * sending commands for a little while, but only if we've
3107 * seen a valid loop at one point (otherwise we can get
3108 * stuck at initialization time).
3110 if (fcp->isp_loopstate < LOOP_PDB_RCVD) {
3111 XS_SETERR(xs, HBA_SELTIMEOUT);
3112 if (fcp->loop_seen_once) {
3113 return (CMD_RQLATER);
3115 return (CMD_COMPLETE);
3120 * If we're in the middle of loop or fabric scanning
3121 * or merging the port databases, retry this command later.
3123 if (fcp->isp_loopstate == LOOP_SCANNING_FABRIC ||
3124 fcp->isp_loopstate == LOOP_SCANNING_LOOP ||
3125 fcp->isp_loopstate == LOOP_SYNCING_PDB) {
3126 return (CMD_RQLATER);
3130 * If our loop state is now such that we've just now
3131 * received a Port Database Change notification, then
3132 * we have to go off and (re)scan the fabric. We back
3133 * out and try again later if this doesn't work.
3135 if (fcp->isp_loopstate == LOOP_PDB_RCVD && fcp->isp_onfabric) {
3136 if (isp_scan_fabric(isp, FC4_SCSI)) {
3137 return (CMD_RQLATER);
3139 if (fcp->isp_fwstate != FW_READY ||
3140 fcp->isp_loopstate < LOOP_FSCAN_DONE) {
3141 return (CMD_RQLATER);
3146 * If our loop state is now such that we've just now
3147 * received a Port Database Change notification, then
3148 * we have to go off and (re)synchronize our port
3151 if (fcp->isp_loopstate < LOOP_READY) {
3152 if (isp_pdb_sync(isp)) {
3153 return (CMD_RQLATER);
3155 if (fcp->isp_fwstate != FW_READY ||
3156 fcp->isp_loopstate != LOOP_READY) {
3157 return (CMD_RQLATER);
3162 * XXX: Here's were we would cancel any loop_dead flag
3163 * XXX: also cancel in dead_loop timeout that's running
3168 * Now check whether we should even think about pursuing this.
3170 lp = &fcp->portdb[target];
3171 if (lp->valid == 0) {
3172 XS_SETERR(xs, HBA_SELTIMEOUT);
3173 return (CMD_COMPLETE);
3175 if ((lp->roles & (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT)) == 0) {
3176 isp_prt(isp, ISP_LOGDEBUG2,
3177 "Target %d does not have target service", target);
3178 XS_SETERR(xs, HBA_SELTIMEOUT);
3179 return (CMD_COMPLETE);
3182 * Now turn target into what the actual Loop ID is.
3184 target = lp->loopid;
3188 * Next check to see if any HBA or Device
3189 * parameters need to be updated.
3191 if (isp->isp_update != 0) {
3195 if (isp_getrqentry(isp, &nxti, &optr, (void *)&qep)) {
3196 isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow");
3197 XS_SETERR(xs, HBA_BOTCH);
3198 return (CMD_EAGAIN);
3202 * Now see if we need to synchronize the ISP with respect to anything.
3203 * We do dual duty here (cough) for synchronizing for busses other
3204 * than which we got here to send a command to.
3206 reqp = (ispreq_t *) local;
3207 if (isp->isp_sendmarker) {
3208 u_int8_t n = (IS_DUALBUS(isp)? 2: 1);
3210 * Check ports to send markers for...
3212 for (i = 0; i < n; i++) {
3213 if ((isp->isp_sendmarker & (1 << i)) == 0) {
3216 MEMZERO((void *) reqp, QENTRY_LEN);
3217 reqp->req_header.rqs_entry_count = 1;
3218 reqp->req_header.rqs_entry_type = RQSTYPE_MARKER;
3219 reqp->req_modifier = SYNC_ALL;
3220 reqp->req_target = i << 7; /* insert bus number */
3221 isp_put_request(isp, reqp, qep);
3222 ISP_ADD_REQUEST(isp, nxti);
3223 isp->isp_sendmarker &= ~(1 << i);
3224 if (isp_getrqentry(isp, &nxti, &optr, (void *) &qep)) {
3225 isp_prt(isp, ISP_LOGDEBUG0,
3226 "Request Queue Overflow+");
3227 XS_SETERR(xs, HBA_BOTCH);
3228 return (CMD_EAGAIN);
3233 MEMZERO((void *)reqp, QENTRY_LEN);
3234 reqp->req_header.rqs_entry_count = 1;
3236 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
3238 if (XS_CDBLEN(xs) > 12)
3239 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
3241 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
3243 /* reqp->req_header.rqs_flags = 0; */
3244 /* reqp->req_header.rqs_seqno = 0; */
3247 * See comment in isp_intr
3249 /* XS_RESID(xs) = 0; */
3252 * Fibre Channel always requires some kind of tag.
3253 * The Qlogic drivers seem be happy not to use a tag,
3254 * but this breaks for some devices (IBM drives).
3257 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
3260 * If we don't know what tag to use, use HEAD OF QUEUE
3261 * for Request Sense or Simple.
3263 if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
3264 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_HTAG;
3266 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
3269 sdparam *sdp = (sdparam *)isp->isp_param;
3270 sdp += XS_CHANNEL(xs);
3271 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) &&
3273 reqp->req_flags = XS_TAG_TYPE(xs);
3276 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
3278 reqp->req_lun_trn = XS_LUN(xs);
3279 reqp->req_cdblen = XS_CDBLEN(xs);
3281 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN)
3282 ((ispreqt2_t *)reqp)->req_scclun = XS_LUN(xs);
3284 ((ispreqt2_t *)reqp)->req_lun_trn = XS_LUN(xs);
3286 MEMCPY(reqp->req_cdb, XS_CDBP(xs), XS_CDBLEN(xs));
3288 reqp->req_time = XS_TIME(xs) / 1000;
3289 if (reqp->req_time == 0 && XS_TIME(xs)) {
3293 if (isp_save_xs(isp, xs, &handle)) {
3294 isp_prt(isp, ISP_LOGDEBUG0, "out of xflist pointers");
3295 XS_SETERR(xs, HBA_BOTCH);
3296 return (CMD_EAGAIN);
3298 reqp->req_handle = handle;
3301 * Set up DMA and/or do any bus swizzling of the request entry
3302 * so that the Qlogic F/W understands what is being asked of it.
3304 i = ISP_DMASETUP(isp, xs, reqp, &nxti, optr);
3305 if (i != CMD_QUEUED) {
3306 isp_destroy_handle(isp, handle);
3308 * dmasetup sets actual error in packet, and
3309 * return what we were given to return.
3313 XS_SETERR(xs, HBA_NOERROR);
3314 isp_prt(isp, ISP_LOGDEBUG2,
3315 "START cmd for %d.%d.%d cmd 0x%x datalen %ld",
3316 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), XS_CDBP(xs)[0],
3317 (long) XS_XFRLEN(xs));
3318 ISP_ADD_REQUEST(isp, nxti);
3320 return (CMD_QUEUED);
3325 * Locks (ints blocked) assumed held.
3329 isp_control(struct ispsoftc *isp, ispctl_t ctl, void *arg)
3338 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
3341 case ISPCTL_RESET_BUS:
3343 * Issue a bus reset.
3345 mbs.param[0] = MBOX_BUS_RESET;
3349 ((sdparam *) isp->isp_param)->isp_bus_reset_delay;
3350 if (mbs.param[1] < 2)
3352 bus = *((int *) arg);
3353 if (IS_DUALBUS(isp))
3359 isp->isp_sendmarker |= (1 << bus);
3360 isp_mboxcmd(isp, &mbs, MBLOGALL);
3361 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3364 isp_prt(isp, ISP_LOGINFO,
3365 "driver initiated bus reset of bus %d", bus);
3368 case ISPCTL_RESET_DEV:
3369 tgt = (*((int *) arg)) & 0xffff;
3370 bus = (*((int *) arg)) >> 16;
3371 mbs.param[0] = MBOX_ABORT_TARGET;
3372 mbs.param[1] = (tgt << 8) | (bus << 15);
3373 mbs.param[2] = 3; /* 'delay', in seconds */
3374 isp_mboxcmd(isp, &mbs, MBLOGALL);
3375 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3378 isp_prt(isp, ISP_LOGINFO,
3379 "Target %d on Bus %d Reset Succeeded", tgt, bus);
3380 isp->isp_sendmarker |= (1 << bus);
3383 case ISPCTL_ABORT_CMD:
3386 handle = isp_find_handle(isp, xs);
3388 isp_prt(isp, ISP_LOGWARN,
3389 "cannot find handle for command to abort");
3392 bus = XS_CHANNEL(xs);
3393 mbs.param[0] = MBOX_ABORT;
3395 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
3396 mbs.param[1] = tgt << 8;
3399 mbs.param[6] = XS_LUN(xs);
3401 mbs.param[1] = tgt << 8 | XS_LUN(xs);
3405 (bus << 15) | (XS_TGT(xs) << 8) | XS_LUN(xs);
3408 mbs.param[2] = handle;
3409 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_ERROR);
3410 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3414 * XXX: Look for command in the REQUEST QUEUE. That is,
3415 * XXX: It hasen't been picked up by firmware yet.
3419 case ISPCTL_UPDATE_PARAMS:
3424 case ISPCTL_FCLINK_TEST:
3427 int usdelay = (arg)? *((int *) arg) : 250000;
3428 return (isp_fclink_test(isp, usdelay));
3432 case ISPCTL_SCAN_FABRIC:
3435 int ftype = (arg)? *((int *) arg) : FC4_SCSI;
3436 return (isp_scan_fabric(isp, ftype));
3440 case ISPCTL_SCAN_LOOP:
3443 return (isp_scan_loop(isp));
3447 case ISPCTL_PDB_SYNC:
3450 return (isp_pdb_sync(isp));
3454 case ISPCTL_SEND_LIP:
3457 mbs.param[0] = MBOX_INIT_LIP;
3458 isp_mboxcmd(isp, &mbs, MBLOGALL);
3459 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3465 case ISPCTL_GET_POSMAP:
3467 if (IS_FC(isp) && arg) {
3468 return (isp_getmap(isp, arg));
3473 case ISPCTL_GET_PDB:
3474 if (IS_FC(isp) && arg) {
3475 int id = *((int *)arg);
3476 isp_pdb_t *pdb = arg;
3477 return (isp_getpdb(isp, id, pdb));
3481 case ISPCTL_RUN_MBOXCMD:
3483 isp_mboxcmd(isp, arg, MBLOGALL);
3486 #ifdef ISP_TARGET_MODE
3487 case ISPCTL_TOGGLE_TMODE:
3491 * We don't check/set against role here- that's the
3492 * responsibility for the outer layer to coordinate.
3495 int param = *(int *)arg;
3496 mbs.param[0] = MBOX_ENABLE_TARGET_MODE;
3497 mbs.param[1] = param & 0xffff;
3498 mbs.param[2] = param >> 16;
3499 isp_mboxcmd(isp, &mbs, MBLOGALL);
3500 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3512 * Interrupt Service Routine(s).
3514 * External (OS) framework has done the appropriate locking,
3515 * and the locking will be held throughout this function.
3519 * Limit our stack depth by sticking with the max likely number
3520 * of completions on a request queue at any one time.
3522 #ifndef MAX_REQUESTQ_COMPLETIONS
3523 #define MAX_REQUESTQ_COMPLETIONS 64
3527 isp_intr(struct ispsoftc *isp, u_int16_t isr, u_int16_t sema, u_int16_t mbox)
3529 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
3530 u_int16_t iptr, optr, junk;
3531 int i, nlooked = 0, ndone = 0;
3535 * Is this a mailbox related interrupt?
3536 * The mailbox semaphore will be nonzero if so.
3539 if (mbox & 0x4000) {
3540 isp->isp_intmboxc++;
3541 if (isp->isp_mboxbsy) {
3542 int i = 0, obits = isp->isp_obits;
3543 isp->isp_mboxtmp[i++] = mbox;
3544 for (i = 1; i < MAX_MAILBOX; i++) {
3545 if ((obits & (1 << i)) == 0) {
3548 isp->isp_mboxtmp[i] =
3549 ISP_READ(isp, MBOX_OFF(i));
3551 if (isp->isp_mbxwrk0) {
3552 if (isp_mbox_continue(isp) == 0) {
3556 MBOX_NOTIFY_COMPLETE(isp);
3558 isp_prt(isp, ISP_LOGWARN,
3559 "Mbox Command Async (0x%x) with no waiters",
3562 } else if (isp_parse_async(isp, mbox) < 0) {
3565 if ((IS_FC(isp) && mbox != ASYNC_RIO_RESP) ||
3566 isp->isp_state != ISP_RUNSTATE) {
3567 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3568 ISP_WRITE(isp, BIU_SEMA, 0);
3574 * We can't be getting this now.
3576 if (isp->isp_state != ISP_RUNSTATE) {
3577 isp_prt(isp, ISP_LOGWARN,
3578 "interrupt (ISR=%x SEMA=%x) when not ready", isr, sema);
3580 * Thank you very much! *Burrrp*!
3582 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp,
3583 READ_RESPONSE_QUEUE_IN_POINTER(isp));
3585 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3586 ISP_WRITE(isp, BIU_SEMA, 0);
3591 * Get the current Response Queue Out Pointer.
3593 * If we're a 2300, we can ask what hardware what it thinks.
3596 optr = ISP_READ(isp, isp->isp_respoutrp);
3598 * Debug: to be taken out eventually
3600 if (isp->isp_residx != optr) {
3601 isp_prt(isp, ISP_LOGWARN, "optr %x soft optr %x",
3602 optr, isp->isp_residx);
3605 optr = isp->isp_residx;
3609 * You *must* read the Response Queue In Pointer
3610 * prior to clearing the RISC interrupt.
3612 * Debounce the 2300 if revision less than 2.
3614 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
3617 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3618 junk = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3619 } while (junk != iptr && ++i < 1000);
3622 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3623 isp_prt(isp, ISP_LOGWARN,
3624 "Response Queue Out Pointer Unstable (%x, %x)",
3629 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3631 isp->isp_resodx = iptr;
3634 if (optr == iptr && sema == 0) {
3636 * There are a lot of these- reasons unknown- mostly on
3637 * faster Alpha machines.
3639 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
3640 * make sure the old interrupt went away (to avoid 'ringing'
3641 * effects), but that didn't stop this from occurring.
3645 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3646 junk = ISP_READ(isp, BIU_R2HSTSLO);
3648 junk = ISP_READ(isp, BIU_ISR);
3654 sema = ISP_READ(isp, BIU_SEMA);
3655 mbox = ISP_READ(isp, OUTMAILBOX0);
3656 if ((sema & 0x3) && (mbox & 0x8000)) {
3660 isp->isp_intbogus++;
3661 isp_prt(isp, ISP_LOGDEBUG1,
3662 "bogus intr- isr %x (%x) iptr %x optr %x",
3663 isr, junk, iptr, optr);
3666 isp->isp_resodx = iptr;
3667 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3668 ISP_WRITE(isp, BIU_SEMA, 0);
3670 if (isp->isp_rspbsy) {
3673 isp->isp_rspbsy = 1;
3675 while (optr != iptr) {
3676 ispstatusreq_t local, *sp = &local;
3682 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
3684 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
3688 * Synchronize our view of this response queue entry.
3690 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN);
3692 type = isp_get_response_type(isp, hp);
3694 if (type == RQSTYPE_RESPONSE) {
3695 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3696 } else if (type == RQSTYPE_RIO2) {
3698 isp_get_rio2(isp, (isp_rio2_t *) hp, &rio);
3699 for (i = 0; i < rio.req_header.rqs_seqno; i++) {
3700 isp_fastpost_complete(isp, rio.req_handles[i]);
3702 if (isp->isp_fpcchiwater < rio.req_header.rqs_seqno)
3703 isp->isp_fpcchiwater = rio.req_header.rqs_seqno;
3704 MEMZERO(hp, QENTRY_LEN); /* PERF */
3708 * Somebody reachable via isp_handle_other_response
3709 * may have updated the response queue pointers for
3710 * us, so we reload our goal index.
3712 int i = isp_handle_other_response(isp, type, hp, &optr);
3716 iptr = isp->isp_resodx;
3717 MEMZERO(hp, QENTRY_LEN); /* PERF */
3722 * After this point, we'll just look at the header as
3723 * we don't know how to deal with the rest of the
3726 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3729 * It really has to be a bounced request just copied
3730 * from the request queue to the response queue. If
3731 * not, something bad has happened.
3733 if (sp->req_header.rqs_entry_type != RQSTYPE_REQUEST) {
3734 isp_prt(isp, ISP_LOGERR, notresp,
3735 sp->req_header.rqs_entry_type, oop, optr,
3737 if (isp->isp_dblev & ISP_LOGDEBUG0) {
3738 isp_print_bytes(isp, "Queue Entry",
3741 MEMZERO(hp, QENTRY_LEN); /* PERF */
3747 if (sp->req_header.rqs_flags & 0xf) {
3748 #define _RQS_OFLAGS \
3749 ~(RQSFLAG_CONTINUATION|RQSFLAG_FULL|RQSFLAG_BADHEADER|RQSFLAG_BADPACKET)
3750 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
3751 isp_prt(isp, ISP_LOGWARN,
3752 "continuation segment");
3753 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3756 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3757 isp_prt(isp, ISP_LOGDEBUG1,
3758 "internal queues full");
3760 * We'll synthesize a QUEUE FULL message below.
3763 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
3764 isp_prt(isp, ISP_LOGERR, "bad header flag");
3767 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
3768 isp_prt(isp, ISP_LOGERR, "bad request packet");
3771 if (sp->req_header.rqs_flags & _RQS_OFLAGS) {
3772 isp_prt(isp, ISP_LOGERR,
3773 "unknown flags (0x%x) in response",
3774 sp->req_header.rqs_flags);
3779 if (sp->req_handle > isp->isp_maxcmds || sp->req_handle < 1) {
3780 MEMZERO(hp, QENTRY_LEN); /* PERF */
3781 isp_prt(isp, ISP_LOGERR,
3782 "bad request handle %d (type 0x%x, flags 0x%x)",
3783 sp->req_handle, sp->req_header.rqs_entry_type,
3784 sp->req_header.rqs_flags);
3785 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3788 xs = isp_find_xs(isp, sp->req_handle);
3790 u_int8_t ts = sp->req_completion_status & 0xff;
3791 MEMZERO(hp, QENTRY_LEN); /* PERF */
3793 * Only whine if this isn't the expected fallout of
3794 * aborting the command.
3796 if (sp->req_header.rqs_entry_type != RQSTYPE_RESPONSE) {
3797 isp_prt(isp, ISP_LOGERR,
3798 "cannot find handle 0x%x (type 0x%x)",
3800 sp->req_header.rqs_entry_type);
3801 } else if (ts != RQCS_ABORTED) {
3802 isp_prt(isp, ISP_LOGERR,
3803 "cannot find handle 0x%x (status 0x%x)",
3804 sp->req_handle, ts);
3806 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3809 isp_destroy_handle(isp, sp->req_handle);
3810 if (sp->req_status_flags & RQSTF_BUS_RESET) {
3811 XS_SETERR(xs, HBA_BUSRESET);
3812 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
3815 XS_SETERR(xs, HBA_BOTCH);
3818 if (IS_FC(isp) && (sp->req_scsi_status & RQCS_SV)) {
3820 * Fibre Channel F/W doesn't say we got status
3821 * if there's Sense Data instead. I guess they
3822 * think it goes w/o saying.
3824 sp->req_state_flags |= RQSF_GOT_STATUS;
3826 if (sp->req_state_flags & RQSF_GOT_STATUS) {
3827 *XS_STSP(xs) = sp->req_scsi_status & 0xff;
3830 switch (sp->req_header.rqs_entry_type) {
3831 case RQSTYPE_RESPONSE:
3832 XS_SET_STATE_STAT(isp, xs, sp);
3833 isp_parse_status(isp, sp, xs);
3834 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) &&
3835 (*XS_STSP(xs) == SCSI_BUSY)) {
3836 XS_SETERR(xs, HBA_TGTBSY);
3839 XS_RESID(xs) = sp->req_resid;
3840 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3841 (*XS_STSP(xs) == SCSI_CHECK) &&
3842 (sp->req_state_flags & RQSF_GOT_SENSE)) {
3843 XS_SAVE_SENSE(xs, sp);
3846 * A new synchronous rate was negotiated for
3847 * this target. Mark state such that we'll go
3848 * look up that which has changed later.
3850 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
3852 sdparam *sdp = isp->isp_param;
3853 sdp += XS_CHANNEL(xs);
3854 sdp->isp_devparam[t].dev_refresh = 1;
3856 (1 << XS_CHANNEL(xs));
3859 if (sp->req_status_flags & RQSF_XFER_COMPLETE) {
3861 } else if (sp->req_scsi_status & RQCS_RESID) {
3862 XS_RESID(xs) = sp->req_resid;
3866 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3867 (*XS_STSP(xs) == SCSI_CHECK) &&
3868 (sp->req_scsi_status & RQCS_SV)) {
3869 XS_SAVE_SENSE(xs, sp);
3870 /* solely for the benefit of debug */
3871 sp->req_state_flags |= RQSF_GOT_SENSE;
3874 isp_prt(isp, ISP_LOGDEBUG2,
3875 "asked for %ld got resid %ld", (long) XS_XFRLEN(xs),
3876 (long) sp->req_resid);
3878 case RQSTYPE_REQUEST:
3879 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3881 * Force Queue Full status.
3883 *XS_STSP(xs) = SCSI_QFULL;
3884 XS_SETERR(xs, HBA_NOERROR);
3885 } else if (XS_NOERR(xs)) {
3889 isp_prt(isp, ISP_LOGDEBUG0,
3890 "Request Queue Entry bounced back");
3891 XS_SETERR(xs, HBA_BOTCH);
3893 XS_RESID(xs) = XS_XFRLEN(xs);
3896 isp_prt(isp, ISP_LOGWARN,
3897 "unhandled response queue type 0x%x",
3898 sp->req_header.rqs_entry_type);
3900 XS_SETERR(xs, HBA_BOTCH);
3906 * Free any DMA resources. As a side effect, this may
3907 * also do any cache flushing necessary for data coherence. */
3908 if (XS_XFRLEN(xs)) {
3909 ISP_DMAFREE(isp, xs, sp->req_handle);
3912 if (((isp->isp_dblev & (ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
3913 ((isp->isp_dblev & ISP_LOGDEBUG1) && ((!XS_NOERR(xs)) ||
3914 (*XS_STSP(xs) != SCSI_GOOD)))) {
3916 if (sp->req_state_flags & RQSF_GOT_SENSE) {
3917 skey = XS_SNSKEY(xs) & 0xf;
3922 } else if (*XS_STSP(xs) == SCSI_CHECK) {
3927 isp_prt(isp, ISP_LOGALL, finmsg, XS_CHANNEL(xs),
3928 XS_TGT(xs), XS_LUN(xs), XS_XFRLEN(xs), XS_RESID(xs),
3929 *XS_STSP(xs), skey, XS_ERR(xs));
3932 if (isp->isp_nactive > 0)
3934 complist[ndone++] = xs; /* defer completion call until later */
3935 MEMZERO(hp, QENTRY_LEN); /* PERF */
3936 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
3942 * If we looked at any commands, then it's valid to find out
3943 * what the outpointer is. It also is a trigger to update the
3944 * ISP's notion of what we've seen so far.
3947 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3949 * While we're at it, read the requst queue out pointer.
3951 isp->isp_reqodx = READ_REQUEST_QUEUE_OUT_POINTER(isp);
3952 if (isp->isp_rscchiwater < ndone)
3953 isp->isp_rscchiwater = ndone;
3956 isp->isp_residx = optr;
3957 isp->isp_rspbsy = 0;
3958 for (i = 0; i < ndone; i++) {
3961 isp->isp_rsltccmplt++;
3972 isp_parse_async(struct ispsoftc *isp, u_int16_t mbox)
3977 if (IS_DUALBUS(isp)) {
3978 bus = ISP_READ(isp, OUTMAILBOX6);
3982 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
3985 case ASYNC_BUS_RESET:
3986 isp->isp_sendmarker |= (1 << bus);
3987 #ifdef ISP_TARGET_MODE
3988 if (isp_target_async(isp, bus, mbox))
3991 isp_async(isp, ISPASYNC_BUS_RESET, &bus);
3993 case ASYNC_SYSTEM_ERROR:
3994 #ifdef ISP_FW_CRASH_DUMP
3996 * If we have crash dumps enabled, it's up to the handler
3997 * for isp_async to reinit stuff and restart the firmware
3998 * after performing the crash dump. The reason we do things
3999 * this way is that we may need to activate a kernel thread
4000 * to do all the crash dump goop.
4002 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4004 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4006 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4011 case ASYNC_RQS_XFER_ERR:
4012 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
4015 case ASYNC_RSP_XFER_ERR:
4016 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
4021 * We've just been notified that the Queue has woken up.
4022 * We don't need to be chatty about this- just unlatch things
4025 mbox = READ_REQUEST_QUEUE_OUT_POINTER(isp);
4028 case ASYNC_TIMEOUT_RESET:
4029 isp_prt(isp, ISP_LOGWARN,
4030 "timeout initiated SCSI bus reset of bus %d", bus);
4031 isp->isp_sendmarker |= (1 << bus);
4032 #ifdef ISP_TARGET_MODE
4033 if (isp_target_async(isp, bus, mbox))
4038 case ASYNC_DEVICE_RESET:
4039 isp_prt(isp, ISP_LOGINFO, "device reset on bus %d", bus);
4040 isp->isp_sendmarker |= (1 << bus);
4041 #ifdef ISP_TARGET_MODE
4042 if (isp_target_async(isp, bus, mbox))
4047 case ASYNC_EXTMSG_UNDERRUN:
4048 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
4051 case ASYNC_SCAM_INT:
4052 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
4055 case ASYNC_HUNG_SCSI:
4056 isp_prt(isp, ISP_LOGERR,
4057 "stalled SCSI Bus after DATA Overrun");
4058 /* XXX: Need to issue SCSI reset at this point */
4061 case ASYNC_KILLED_BUS:
4062 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
4065 case ASYNC_BUS_TRANSIT:
4066 mbox = ISP_READ(isp, OUTMAILBOX2);
4067 switch (mbox & 0x1c00) {
4068 case SXP_PINS_LVD_MODE:
4069 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
4070 SDPARAM(isp)->isp_diffmode = 0;
4071 SDPARAM(isp)->isp_ultramode = 0;
4072 SDPARAM(isp)->isp_lvdmode = 1;
4074 case SXP_PINS_HVD_MODE:
4075 isp_prt(isp, ISP_LOGINFO,
4076 "Transition to Differential mode");
4077 SDPARAM(isp)->isp_diffmode = 1;
4078 SDPARAM(isp)->isp_ultramode = 0;
4079 SDPARAM(isp)->isp_lvdmode = 0;
4081 case SXP_PINS_SE_MODE:
4082 isp_prt(isp, ISP_LOGINFO,
4083 "Transition to Single Ended mode");
4084 SDPARAM(isp)->isp_diffmode = 0;
4085 SDPARAM(isp)->isp_ultramode = 1;
4086 SDPARAM(isp)->isp_lvdmode = 0;
4089 isp_prt(isp, ISP_LOGWARN,
4090 "Transition to Unknown Mode 0x%x", mbox);
4094 * XXX: Set up to renegotiate again!
4096 /* Can only be for a 1080... */
4097 isp->isp_sendmarker |= (1 << bus);
4101 * We can use bus, which will always be zero for FC cards,
4102 * as a mailbox pattern accumulator to be checked below.
4105 bus = 0x1ce; /* outgoing mailbox regs 1-3, 6-7 */
4109 bus = 0x14e; /* outgoing mailbox regs 1-3, 6 */
4113 bus = 0x10e; /* outgoing mailbox regs 1-3 */
4117 bus = 0x106; /* outgoing mailbox regs 1-2 */
4121 case ASYNC_CMD_CMPLT:
4122 bus = 0x102; /* outgoing mailbox regs 1 */
4125 case ASYNC_RIO_RESP:
4128 case ASYNC_CTIO_DONE:
4130 #ifdef ISP_TARGET_MODE
4132 (ISP_READ(isp, OUTMAILBOX2) << 16) |
4133 (ISP_READ(isp, OUTMAILBOX1));
4134 if (isp_target_async(isp, handle, mbox)) {
4137 /* count it as a fast posting intr */
4138 isp->isp_fphccmplt++;
4141 isp_prt(isp, ISP_LOGINFO, "Fast Posting CTIO done");
4142 isp->isp_fphccmplt++; /* count it as a fast posting intr */
4147 case ASYNC_LIP_OCCURRED:
4148 FCPARAM(isp)->isp_lipseq =
4149 ISP_READ(isp, OUTMAILBOX1);
4150 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4151 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4152 isp->isp_sendmarker = 1;
4153 isp_mark_getpdb_all(isp);
4154 isp_async(isp, ISPASYNC_LIP, NULL);
4155 #ifdef ISP_TARGET_MODE
4156 if (isp_target_async(isp, bus, mbox))
4160 * We've had problems with data corruption occuring on
4161 * commands that complete (with no apparent error) after
4162 * we receive a LIP. This has been observed mostly on
4163 * Local Loop topologies. To be safe, let's just mark
4164 * all active commands as dead.
4166 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4167 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4169 for (i = j = 0; i < isp->isp_maxcmds; i++) {
4171 xs = isp->isp_xflist[i];
4174 XS_SETERR(xs, HBA_BUSRESET);
4178 isp_prt(isp, ISP_LOGERR,
4179 "LIP destroyed %d active commands", j);
4185 isp->isp_sendmarker = 1;
4186 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4187 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4188 isp_mark_getpdb_all(isp);
4189 isp_async(isp, ISPASYNC_LOOP_UP, NULL);
4190 #ifdef ISP_TARGET_MODE
4191 if (isp_target_async(isp, bus, mbox))
4196 case ASYNC_LOOP_DOWN:
4197 isp->isp_sendmarker = 1;
4198 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4199 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4200 isp_mark_getpdb_all(isp);
4201 isp_async(isp, ISPASYNC_LOOP_DOWN, NULL);
4202 #ifdef ISP_TARGET_MODE
4203 if (isp_target_async(isp, bus, mbox))
4208 case ASYNC_LOOP_RESET:
4209 isp->isp_sendmarker = 1;
4210 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4211 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4212 isp_mark_getpdb_all(isp);
4213 isp_async(isp, ISPASYNC_LOOP_RESET, NULL);
4214 #ifdef ISP_TARGET_MODE
4215 if (isp_target_async(isp, bus, mbox))
4220 case ASYNC_PDB_CHANGED:
4221 isp->isp_sendmarker = 1;
4222 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4223 isp_mark_getpdb_all(isp);
4224 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_PDB);
4227 case ASYNC_CHANGE_NOTIFY:
4229 * Not correct, but it will force us to rescan the loop.
4231 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4232 isp_mark_getpdb_all(isp);
4233 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_SNS);
4237 if (FCPARAM(isp)->isp_onfabric)
4238 FCPARAM(isp)->isp_topo = TOPO_F_PORT;
4240 FCPARAM(isp)->isp_topo = TOPO_N_PORT;
4241 isp_mark_getpdb_all(isp);
4242 isp->isp_sendmarker = 1;
4243 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4244 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4245 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4246 #ifdef ISP_TARGET_MODE
4247 if (isp_target_async(isp, bus, mbox))
4250 isp_prt(isp, ISP_LOGINFO, "Point-to-Point mode");
4253 case ASYNC_CONNMODE:
4254 mbox = ISP_READ(isp, OUTMAILBOX1);
4255 isp_mark_getpdb_all(isp);
4258 isp_prt(isp, ISP_LOGINFO,
4259 "Point-to-Point -> Loop mode");
4262 isp_prt(isp, ISP_LOGINFO,
4263 "Loop -> Point-to-Point mode");
4265 case ISP_CONN_BADLIP:
4266 isp_prt(isp, ISP_LOGWARN,
4267 "Point-to-Point -> Loop mode (BAD LIP)");
4269 case ISP_CONN_FATAL:
4270 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
4271 #ifdef ISP_FW_CRASH_DUMP
4272 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4274 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4276 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4279 case ISP_CONN_LOOPBACK:
4280 isp_prt(isp, ISP_LOGWARN,
4281 "Looped Back in Point-to-Point mode");
4284 isp_prt(isp, ISP_LOGWARN,
4285 "Unknown connection mode (0x%x)", mbox);
4288 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4289 isp->isp_sendmarker = 1;
4290 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4291 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4295 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
4301 u_int16_t handles[16];
4303 for (nh = 0, i = 1; i < MAX_MAILBOX; i++) {
4304 if ((bus & (1 << i)) == 0) {
4307 handles[nh++] = ISP_READ(isp, MBOX_OFF(i));
4309 for (i = 0; i < nh; i++) {
4310 isp_fastpost_complete(isp, handles[i]);
4311 isp_prt(isp, ISP_LOGDEBUG3,
4312 "fast post completion of %u", handles[i]);
4314 if (isp->isp_fpcchiwater < nh)
4315 isp->isp_fpcchiwater = nh;
4317 isp->isp_intoasync++;
4323 * Handle other response entries. A pointer to the request queue output
4324 * index is here in case we want to eat several entries at once, although
4325 * this is not used currently.
4329 isp_handle_other_response(struct ispsoftc *isp, int type,
4330 isphdr_t *hp, u_int16_t *optrp)
4333 case RQSTYPE_STATUS_CONT:
4334 isp_prt(isp, ISP_LOGINFO, "Ignored Continuation Response");
4338 case RQSTYPE_ENABLE_LUN:
4339 case RQSTYPE_MODIFY_LUN:
4340 case RQSTYPE_NOTIFY:
4341 case RQSTYPE_NOTIFY_ACK:
4346 isp->isp_rsltccmplt++; /* count as a response completion */
4347 #ifdef ISP_TARGET_MODE
4348 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
4353 case RQSTYPE_REQUEST:
4356 if (type != isp_get_response_type(isp, hp)) {
4358 * This is questionable- we're just papering over
4359 * something we've seen on SMP linux in target
4360 * mode- we don't really know what's happening
4361 * here that causes us to think we've gotten
4362 * an entry, but that either the entry isn't
4363 * filled out yet or our CPU read data is stale.
4365 isp_prt(isp, ISP_LOGINFO,
4366 "unstable type in response queue");
4369 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
4370 isp_get_response_type(isp, hp));
4371 if (isp_async(isp, ISPASYNC_UNHANDLED_RESPONSE, hp)) {
4379 isp_parse_status(struct ispsoftc *isp, ispstatusreq_t *sp, XS_T *xs)
4381 switch (sp->req_completion_status & 0xff) {
4384 XS_SETERR(xs, HBA_NOERROR);
4388 case RQCS_INCOMPLETE:
4389 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
4390 isp_prt(isp, ISP_LOGDEBUG1,
4391 "Selection Timeout for %d.%d.%d",
4392 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4394 XS_SETERR(xs, HBA_SELTIMEOUT);
4398 isp_prt(isp, ISP_LOGERR,
4399 "command incomplete for %d.%d.%d, state 0x%x",
4400 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
4401 sp->req_state_flags);
4404 case RQCS_DMA_ERROR:
4405 isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
4406 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4409 case RQCS_TRANSPORT_ERROR:
4412 SNPRINTF(buf, sizeof (buf), "states=>");
4413 if (sp->req_state_flags & RQSF_GOT_BUS) {
4414 SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
4416 if (sp->req_state_flags & RQSF_GOT_TARGET) {
4417 SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
4419 if (sp->req_state_flags & RQSF_SENT_CDB) {
4420 SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
4422 if (sp->req_state_flags & RQSF_XFRD_DATA) {
4423 SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
4425 if (sp->req_state_flags & RQSF_GOT_STATUS) {
4426 SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
4428 if (sp->req_state_flags & RQSF_GOT_SENSE) {
4429 SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
4431 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
4432 SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
4434 SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
4435 if (sp->req_status_flags & RQSTF_DISCONNECT) {
4436 SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
4438 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
4439 SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
4441 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
4442 SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
4444 if (sp->req_status_flags & RQSTF_BUS_RESET) {
4445 SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
4447 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
4448 SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
4450 if (sp->req_status_flags & RQSTF_ABORTED) {
4451 SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
4453 if (sp->req_status_flags & RQSTF_TIMEOUT) {
4454 SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
4456 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
4457 SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
4459 isp_prt(isp, ISP_LOGERR, "%s", buf);
4460 isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d:\n%s",
4461 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), buf);
4464 case RQCS_RESET_OCCURRED:
4465 isp_prt(isp, ISP_LOGWARN,
4466 "bus reset destroyed command for %d.%d.%d",
4467 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4468 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4470 XS_SETERR(xs, HBA_BUSRESET);
4475 isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
4476 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4477 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4479 XS_SETERR(xs, HBA_ABORTED);
4484 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
4485 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4487 * Check to see if we logged out the device.
4490 if ((sp->req_completion_status & RQSTF_LOGOUT) &&
4491 FCPARAM(isp)->portdb[XS_TGT(xs)].valid &&
4492 FCPARAM(isp)->portdb[XS_TGT(xs)].fabric_dev) {
4493 FCPARAM(isp)->portdb[XS_TGT(xs)].relogin = 1;
4497 XS_SETERR(xs, HBA_CMDTIMEOUT);
4501 case RQCS_DATA_OVERRUN:
4502 XS_RESID(xs) = sp->req_resid;
4503 isp_prt(isp, ISP_LOGERR, "data overrun for command on %d.%d.%d",
4504 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4506 XS_SETERR(xs, HBA_DATAOVR);
4510 case RQCS_COMMAND_OVERRUN:
4511 isp_prt(isp, ISP_LOGERR,
4512 "command overrun for command on %d.%d.%d",
4513 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4516 case RQCS_STATUS_OVERRUN:
4517 isp_prt(isp, ISP_LOGERR,
4518 "status overrun for command on %d.%d.%d",
4519 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4522 case RQCS_BAD_MESSAGE:
4523 isp_prt(isp, ISP_LOGERR,
4524 "msg not COMMAND COMPLETE after status %d.%d.%d",
4525 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4528 case RQCS_NO_MESSAGE_OUT:
4529 isp_prt(isp, ISP_LOGERR,
4530 "No MESSAGE OUT phase after selection on %d.%d.%d",
4531 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4534 case RQCS_EXT_ID_FAILED:
4535 isp_prt(isp, ISP_LOGERR, "EXTENDED IDENTIFY failed %d.%d.%d",
4536 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4539 case RQCS_IDE_MSG_FAILED:
4540 isp_prt(isp, ISP_LOGERR,
4541 "INITIATOR DETECTED ERROR rejected by %d.%d.%d",
4542 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4545 case RQCS_ABORT_MSG_FAILED:
4546 isp_prt(isp, ISP_LOGERR, "ABORT OPERATION rejected by %d.%d.%d",
4547 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4550 case RQCS_REJECT_MSG_FAILED:
4551 isp_prt(isp, ISP_LOGERR, "MESSAGE REJECT rejected by %d.%d.%d",
4552 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4555 case RQCS_NOP_MSG_FAILED:
4556 isp_prt(isp, ISP_LOGERR, "NOP rejected by %d.%d.%d",
4557 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4560 case RQCS_PARITY_ERROR_MSG_FAILED:
4561 isp_prt(isp, ISP_LOGERR,
4562 "MESSAGE PARITY ERROR rejected by %d.%d.%d",
4563 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4566 case RQCS_DEVICE_RESET_MSG_FAILED:
4567 isp_prt(isp, ISP_LOGWARN,
4568 "BUS DEVICE RESET rejected by %d.%d.%d",
4569 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4572 case RQCS_ID_MSG_FAILED:
4573 isp_prt(isp, ISP_LOGERR, "IDENTIFY rejected by %d.%d.%d",
4574 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4577 case RQCS_UNEXP_BUS_FREE:
4578 isp_prt(isp, ISP_LOGERR, "%d.%d.%d had an unexpected bus free",
4579 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4582 case RQCS_DATA_UNDERRUN:
4585 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
4586 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
4587 isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
4588 XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
4589 (ru_marked)? "marked" : "not marked");
4591 XS_SETERR(xs, HBA_BOTCH);
4596 XS_RESID(xs) = sp->req_resid;
4598 XS_SETERR(xs, HBA_NOERROR);
4603 case RQCS_XACT_ERR1:
4604 isp_prt(isp, ISP_LOGERR, xact1, XS_CHANNEL(xs),
4605 XS_TGT(xs), XS_LUN(xs));
4608 case RQCS_XACT_ERR2:
4609 isp_prt(isp, ISP_LOGERR, xact2,
4610 XS_LUN(xs), XS_TGT(xs), XS_CHANNEL(xs));
4613 case RQCS_XACT_ERR3:
4614 isp_prt(isp, ISP_LOGERR, xact3,
4615 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4618 case RQCS_BAD_ENTRY:
4619 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
4622 case RQCS_QUEUE_FULL:
4623 isp_prt(isp, ISP_LOGDEBUG0,
4624 "internal queues full for %d.%d.%d status 0x%x",
4625 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), *XS_STSP(xs));
4628 * If QFULL or some other status byte is set, then this
4629 * isn't an error, per se.
4631 * Unfortunately, some QLogic f/w writers have, in
4632 * some cases, ommitted to *set* status to QFULL.
4635 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
4636 XS_SETERR(xs, HBA_NOERROR);
4644 *XS_STSP(xs) = SCSI_QFULL;
4645 XS_SETERR(xs, HBA_NOERROR);
4648 case RQCS_PHASE_SKIPPED:
4649 isp_prt(isp, ISP_LOGERR, pskip, XS_CHANNEL(xs),
4650 XS_TGT(xs), XS_LUN(xs));
4653 case RQCS_ARQS_FAILED:
4654 isp_prt(isp, ISP_LOGERR,
4655 "Auto Request Sense failed for %d.%d.%d",
4656 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4658 XS_SETERR(xs, HBA_ARQFAIL);
4662 case RQCS_WIDE_FAILED:
4663 isp_prt(isp, ISP_LOGERR,
4664 "Wide Negotiation failed for %d.%d.%d",
4665 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4667 sdparam *sdp = isp->isp_param;
4668 sdp += XS_CHANNEL(xs);
4669 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
4670 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4671 isp->isp_update |= (1 << XS_CHANNEL(xs));
4674 XS_SETERR(xs, HBA_NOERROR);
4678 case RQCS_SYNCXFER_FAILED:
4679 isp_prt(isp, ISP_LOGERR,
4680 "SDTR Message failed for target %d.%d.%d",
4681 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4683 sdparam *sdp = isp->isp_param;
4684 sdp += XS_CHANNEL(xs);
4685 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
4686 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4687 isp->isp_update |= (1 << XS_CHANNEL(xs));
4691 case RQCS_LVD_BUSERR:
4692 isp_prt(isp, ISP_LOGERR,
4693 "Bad LVD condition while talking to %d.%d.%d",
4694 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4697 case RQCS_PORT_UNAVAILABLE:
4699 * No such port on the loop. Moral equivalent of SELTIMEO
4701 case RQCS_PORT_LOGGED_OUT:
4703 * It was there (maybe)- treat as a selection timeout.
4705 if ((sp->req_completion_status & 0xff) == RQCS_PORT_UNAVAILABLE)
4706 isp_prt(isp, ISP_LOGINFO,
4707 "port unavailable for target %d", XS_TGT(xs));
4709 isp_prt(isp, ISP_LOGINFO,
4710 "port logout for target %d", XS_TGT(xs));
4712 * If we're on a local loop, force a LIP (which is overkill)
4713 * to force a re-login of this unit. If we're on fabric,
4714 * then we'll have to relogin as a matter of course.
4716 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4717 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4719 mbs.param[0] = MBOX_INIT_LIP;
4720 isp_mboxcmd_qnw(isp, &mbs, 1);
4724 * Probably overkill.
4726 isp->isp_sendmarker = 1;
4727 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4728 isp_mark_getpdb_all(isp);
4729 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4731 XS_SETERR(xs, HBA_SELTIMEOUT);
4735 case RQCS_PORT_CHANGED:
4736 isp_prt(isp, ISP_LOGWARN,
4737 "port changed for target %d", XS_TGT(xs));
4739 XS_SETERR(xs, HBA_SELTIMEOUT);
4743 case RQCS_PORT_BUSY:
4744 isp_prt(isp, ISP_LOGWARN,
4745 "port busy for target %d", XS_TGT(xs));
4747 XS_SETERR(xs, HBA_TGTBSY);
4752 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x",
4753 sp->req_completion_status);
4757 XS_SETERR(xs, HBA_BOTCH);
4762 isp_fastpost_complete(struct ispsoftc *isp, u_int16_t fph)
4769 xs = isp_find_xs(isp, fph);
4771 isp_prt(isp, ISP_LOGWARN,
4772 "Command for fast post handle 0x%x not found", fph);
4775 isp_destroy_handle(isp, fph);
4778 * Since we don't have a result queue entry item,
4779 * we must believe that SCSI status is zero and
4780 * that all data transferred.
4782 XS_SET_STATE_STAT(isp, xs, NULL);
4784 *XS_STSP(xs) = SCSI_GOOD;
4785 if (XS_XFRLEN(xs)) {
4786 ISP_DMAFREE(isp, xs, fph);
4788 if (isp->isp_nactive)
4790 isp->isp_fphccmplt++;
4795 isp_mbox_continue(struct ispsoftc *isp)
4800 switch (isp->isp_lastmbxcmd) {
4801 case MBOX_WRITE_RAM_WORD:
4802 case MBOX_READ_RAM_WORD:
4803 case MBOX_READ_RAM_WORD_EXTENDED:
4808 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
4809 isp->isp_mbxwrk0 = 0;
4815 * Clear the previous interrupt.
4817 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
4818 ISP_WRITE(isp, BIU_SEMA, 0);
4821 * Continue with next word.
4823 ptr = isp->isp_mbxworkp;
4824 switch (isp->isp_lastmbxcmd) {
4825 case MBOX_WRITE_RAM_WORD:
4826 mbs.param[2] = *ptr++;
4827 mbs.param[1] = isp->isp_mbxwrk1++;
4829 case MBOX_READ_RAM_WORD:
4830 case MBOX_READ_RAM_WORD_EXTENDED:
4831 *ptr++ = isp->isp_mboxtmp[2];
4832 mbs.param[1] = isp->isp_mbxwrk1++;
4835 isp->isp_mbxworkp = ptr;
4836 mbs.param[0] = isp->isp_lastmbxcmd;
4837 isp->isp_mbxwrk0 -= 1;
4838 isp_mboxcmd_qnw(isp, &mbs, 0);
4843 #define HIBYT(x) ((x) >> 0x8)
4844 #define LOBYT(x) ((x) & 0xff)
4845 #define ISPOPMAP(a, b) (((a) << 8) | (b))
4846 static const u_int16_t mbpscsi[] = {
4847 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
4848 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
4849 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
4850 ISPOPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
4851 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
4852 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
4853 ISPOPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
4854 ISPOPMAP(0x03, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
4855 ISPOPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
4856 ISPOPMAP(0x00, 0x00), /* 0x09: */
4857 ISPOPMAP(0x00, 0x00), /* 0x0a: */
4858 ISPOPMAP(0x00, 0x00), /* 0x0b: */
4859 ISPOPMAP(0x00, 0x00), /* 0x0c: */
4860 ISPOPMAP(0x00, 0x00), /* 0x0d: */
4861 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
4862 ISPOPMAP(0x00, 0x00), /* 0x0f: */
4863 ISPOPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
4864 ISPOPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
4865 ISPOPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
4866 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
4867 ISPOPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
4868 ISPOPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
4869 ISPOPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
4870 ISPOPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
4871 ISPOPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
4872 ISPOPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
4873 ISPOPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
4874 ISPOPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
4875 ISPOPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
4876 ISPOPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
4877 ISPOPMAP(0x00, 0x00), /* 0x1e: */
4878 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
4879 ISPOPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
4880 ISPOPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
4881 ISPOPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
4882 ISPOPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
4883 ISPOPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
4884 ISPOPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
4885 ISPOPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
4886 ISPOPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
4887 ISPOPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
4888 ISPOPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
4889 ISPOPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
4890 ISPOPMAP(0x00, 0x00), /* 0x2b: */
4891 ISPOPMAP(0x00, 0x00), /* 0x2c: */
4892 ISPOPMAP(0x00, 0x00), /* 0x2d: */
4893 ISPOPMAP(0x00, 0x00), /* 0x2e: */
4894 ISPOPMAP(0x00, 0x00), /* 0x2f: */
4895 ISPOPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
4896 ISPOPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
4897 ISPOPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
4898 ISPOPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
4899 ISPOPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
4900 ISPOPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
4901 ISPOPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
4902 ISPOPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
4903 ISPOPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
4904 ISPOPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
4905 ISPOPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
4906 ISPOPMAP(0x00, 0x00), /* 0x3b: */
4907 ISPOPMAP(0x00, 0x00), /* 0x3c: */
4908 ISPOPMAP(0x00, 0x00), /* 0x3d: */
4909 ISPOPMAP(0x00, 0x00), /* 0x3e: */
4910 ISPOPMAP(0x00, 0x00), /* 0x3f: */
4911 ISPOPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
4912 ISPOPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
4913 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
4914 ISPOPMAP(0x00, 0x00), /* 0x43: */
4915 ISPOPMAP(0x00, 0x00), /* 0x44: */
4916 ISPOPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
4917 ISPOPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
4918 ISPOPMAP(0x00, 0x00), /* 0x47: */
4919 ISPOPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
4920 ISPOPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
4921 ISPOPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
4922 ISPOPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
4923 ISPOPMAP(0x00, 0x00), /* 0x4c: */
4924 ISPOPMAP(0x00, 0x00), /* 0x4d: */
4925 ISPOPMAP(0x00, 0x00), /* 0x4e: */
4926 ISPOPMAP(0x00, 0x00), /* 0x4f: */
4927 ISPOPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
4928 ISPOPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
4929 ISPOPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
4930 ISPOPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
4931 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
4932 ISPOPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
4933 ISPOPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
4934 ISPOPMAP(0x00, 0x00), /* 0x57: */
4935 ISPOPMAP(0x00, 0x00), /* 0x58: */
4936 ISPOPMAP(0x00, 0x00), /* 0x59: */
4937 ISPOPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
4938 ISPOPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
4939 ISPOPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
4940 ISPOPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
4943 #ifndef ISP_STRIPPED
4944 static char *scsi_mbcmd_names[] = {
4961 "INIT REQUEST QUEUE",
4962 "INIT RESULT QUEUE",
4972 "SINGLE STEP QUEUE",
4974 "GET DEV QUEUE STATUS",
4976 "GET FIRMWARE STATUS",
4978 "GET SELECT TIMEOUT",
4980 "GET TAG AGE LIMIT",
4982 "GET ACT NEG STATE",
4983 "GET ASYNC DATA SETUP TIME",
4985 "GET TARGET PARAMS",
4986 "GET DEV QUEUE PARAMS",
4987 "GET RESET DELAY PARAMS",
4994 "SET SELECT TIMEOUT",
4996 "SET TAG AGE LIMIT",
4998 "SET ACT NEG STATE",
4999 "SET ASYNC DATA SETUP TIME",
5000 "SET PCI CONTROL PARAMS",
5001 "SET TARGET PARAMS",
5002 "SET DEV QUEUE PARAMS",
5003 "SET RESET DELAY PARAMS",
5009 "RETURN BIOS BLOCK ADDR",
5010 "WRITE FOUR RAM WORDS",
5014 "SET SYSTEM PARAMETER",
5015 "GET SYSTEM PARAMETER",
5017 "GET SCAM CONFIGURATION",
5018 "SET SCAM CONFIGURATION",
5019 "SET FIRMWARE FEATURES",
5020 "GET FIRMWARE FEATURES",
5027 "INITIALIZE REQUEST QUEUE A64",
5028 "INITIALIZE RESPONSE QUEUE A64",
5030 "ENABLE TARGET MODE",
5031 "GET TARGET MODE STATE",
5035 "SET DATA OVERRUN RECOVERY MODE",
5036 "GET DATA OVERRUN RECOVERY MODE",
5042 static const u_int16_t mbpfc[] = {
5043 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
5044 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
5045 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
5046 ISPOPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
5047 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
5048 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
5049 ISPOPMAP(0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
5050 ISPOPMAP(0x03, 0x05), /* 0x07: MBOX_VERIFY_CHECKSUM */
5051 ISPOPMAP(0x01, 0x4f), /* 0x08: MBOX_ABOUT_FIRMWARE */
5052 ISPOPMAP(0xdf, 0x01), /* 0x09: LOAD RAM */
5053 ISPOPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
5054 ISPOPMAP(0x00, 0x00), /* 0x0b: */
5055 ISPOPMAP(0x00, 0x00), /* 0x0c: */
5056 ISPOPMAP(0x00, 0x00), /* 0x0d: */
5057 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
5058 ISPOPMAP(0x03, 0x07), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED(1) */
5059 ISPOPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
5060 ISPOPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
5061 ISPOPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
5062 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
5063 ISPOPMAP(0x01, 0xff), /* 0x14: MBOX_STOP_FIRMWARE */
5064 ISPOPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
5065 ISPOPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
5066 ISPOPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
5067 ISPOPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
5068 ISPOPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
5069 ISPOPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
5070 ISPOPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
5071 ISPOPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
5072 ISPOPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
5073 ISPOPMAP(0x00, 0x00), /* 0x1e: */
5074 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
5075 ISPOPMAP(0x01, 0x4f), /* 0x20: MBOX_GET_LOOP_ID */
5076 ISPOPMAP(0x00, 0x00), /* 0x21: */
5077 ISPOPMAP(0x01, 0x07), /* 0x22: MBOX_GET_RETRY_COUNT */
5078 ISPOPMAP(0x00, 0x00), /* 0x23: */
5079 ISPOPMAP(0x00, 0x00), /* 0x24: */
5080 ISPOPMAP(0x00, 0x00), /* 0x25: */
5081 ISPOPMAP(0x00, 0x00), /* 0x26: */
5082 ISPOPMAP(0x00, 0x00), /* 0x27: */
5083 ISPOPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
5084 ISPOPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
5085 ISPOPMAP(0x00, 0x00), /* 0x2a: */
5086 ISPOPMAP(0x00, 0x00), /* 0x2b: */
5087 ISPOPMAP(0x00, 0x00), /* 0x2c: */
5088 ISPOPMAP(0x00, 0x00), /* 0x2d: */
5089 ISPOPMAP(0x00, 0x00), /* 0x2e: */
5090 ISPOPMAP(0x00, 0x00), /* 0x2f: */
5091 ISPOPMAP(0x00, 0x00), /* 0x30: */
5092 ISPOPMAP(0x00, 0x00), /* 0x31: */
5093 ISPOPMAP(0x07, 0x07), /* 0x32: MBOX_SET_RETRY_COUNT */
5094 ISPOPMAP(0x00, 0x00), /* 0x33: */
5095 ISPOPMAP(0x00, 0x00), /* 0x34: */
5096 ISPOPMAP(0x00, 0x00), /* 0x35: */
5097 ISPOPMAP(0x00, 0x00), /* 0x36: */
5098 ISPOPMAP(0x00, 0x00), /* 0x37: */
5099 ISPOPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
5100 ISPOPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
5101 ISPOPMAP(0x00, 0x00), /* 0x3a: */
5102 ISPOPMAP(0x00, 0x00), /* 0x3b: */
5103 ISPOPMAP(0x00, 0x00), /* 0x3c: */
5104 ISPOPMAP(0x00, 0x00), /* 0x3d: */
5105 ISPOPMAP(0x00, 0x00), /* 0x3e: */
5106 ISPOPMAP(0x00, 0x00), /* 0x3f: */
5107 ISPOPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
5108 ISPOPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
5109 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_GET_RESOURCE_COUNTS */
5110 ISPOPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_NON_PARTICIPATING_MODE */
5111 ISPOPMAP(0x00, 0x00), /* 0x44: */
5112 ISPOPMAP(0x00, 0x00), /* 0x45: */
5113 ISPOPMAP(0x00, 0x00), /* 0x46: */
5114 ISPOPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
5115 ISPOPMAP(0x00, 0x00), /* 0x48: */
5116 ISPOPMAP(0x00, 0x00), /* 0x49: */
5117 ISPOPMAP(0x00, 0x00), /* 0x4a: */
5118 ISPOPMAP(0x00, 0x00), /* 0x4b: */
5119 ISPOPMAP(0x00, 0x00), /* 0x4c: */
5120 ISPOPMAP(0x00, 0x00), /* 0x4d: */
5121 ISPOPMAP(0x00, 0x00), /* 0x4e: */
5122 ISPOPMAP(0x00, 0x00), /* 0x4f: */
5123 ISPOPMAP(0x00, 0x00), /* 0x50: */
5124 ISPOPMAP(0x00, 0x00), /* 0x51: */
5125 ISPOPMAP(0x00, 0x00), /* 0x52: */
5126 ISPOPMAP(0x00, 0x00), /* 0x53: */
5127 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
5128 ISPOPMAP(0x00, 0x00), /* 0x55: */
5129 ISPOPMAP(0x00, 0x00), /* 0x56: */
5130 ISPOPMAP(0x00, 0x00), /* 0x57: */
5131 ISPOPMAP(0x00, 0x00), /* 0x58: */
5132 ISPOPMAP(0x00, 0x00), /* 0x59: */
5133 ISPOPMAP(0x00, 0x00), /* 0x5a: */
5134 ISPOPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
5135 ISPOPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
5136 ISPOPMAP(0x07, 0x03), /* 0x5d: MBOX_GET_SET_DATA_RATE */
5137 ISPOPMAP(0x00, 0x00), /* 0x5e: */
5138 ISPOPMAP(0x00, 0x00), /* 0x5f: */
5139 ISPOPMAP(0xfd, 0x31), /* 0x60: MBOX_INIT_FIRMWARE */
5140 ISPOPMAP(0x00, 0x00), /* 0x61: */
5141 ISPOPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
5142 ISPOPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
5143 ISPOPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
5144 ISPOPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
5145 ISPOPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
5146 ISPOPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
5147 ISPOPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
5148 ISPOPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
5149 ISPOPMAP(0x03, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
5150 ISPOPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
5151 ISPOPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
5152 ISPOPMAP(0x00, 0x00), /* 0x6d: */
5153 ISPOPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
5154 ISPOPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
5155 ISPOPMAP(0x03, 0x01), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
5156 ISPOPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
5157 ISPOPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
5158 ISPOPMAP(0x00, 0x00), /* 0x73: */
5159 ISPOPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
5160 ISPOPMAP(0xcf, 0x03), /* 0x75: GET PORT/NODE NAME LIST */
5161 ISPOPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
5162 ISPOPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
5163 ISPOPMAP(0x00, 0x00), /* 0x78: */
5164 ISPOPMAP(0x00, 0x00), /* 0x79: */
5165 ISPOPMAP(0x00, 0x00), /* 0x7a: */
5166 ISPOPMAP(0x00, 0x00), /* 0x7b: */
5167 ISPOPMAP(0x4f, 0x03), /* 0x7c: Get ID List */
5168 ISPOPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
5169 ISPOPMAP(0x0f, 0x01) /* 0x7e: LUN RESET */
5174 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
5175 * do not access at this time in the core driver. The caller is
5176 * responsible for setting this register first (Gross!).
5179 #ifndef ISP_STRIPPED
5180 static char *fc_mbcmd_names[] = {
5194 "READ RAM WORD EXTENDED",
5197 "INIT REQUEST QUEUE",
5198 "INIT RESULT QUEUE",
5208 "SINGLE STEP QUEUE",
5210 "GET DEV QUEUE STATUS",
5212 "GET FIRMWARE STATUS",
5221 "GET FIRMWARE OPTIONS",
5222 "GET PORT QUEUE PARAMS",
5237 "SET FIRMWARE OPTIONS",
5238 "SET PORT QUEUE PARAMS",
5247 "GET RESOURCE COUNTS",
5248 "REQUEST NON PARTICIPATING MODE",
5252 "GET PORT DATABASE,, ENHANCED",
5274 "GET/SET DATA RATE",
5280 "GET FC-AL POSITION MAP",
5281 "GET PORT DATABASE",
5293 "SEND CHANGE REQUEST",
5298 "GET PORT/NODE NAME LIST",
5300 "INITIALIZE IP MAILBOX",
5312 isp_mboxcmd_qnw(struct ispsoftc *isp, mbreg_t *mbp, int nodelay)
5314 unsigned int ibits, obits, box, opcode;
5315 const u_int16_t *mcp;
5322 opcode = mbp->param[0];
5323 ibits = HIBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5324 obits = LOBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5325 for (box = 0; box < MAX_MAILBOX; box++) {
5326 if (ibits & (1 << box)) {
5327 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5330 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5334 isp->isp_lastmbxcmd = opcode;
5335 isp->isp_obits = obits;
5336 isp->isp_mboxbsy = 1;
5338 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5340 * Oddly enough, if we're not delaying for an answer,
5341 * delay a bit to give the f/w a chance to pick up the
5350 isp_mboxcmd(struct ispsoftc *isp, mbreg_t *mbp, int logmask)
5352 char *cname, *xname, tname[16], mname[16];
5353 unsigned int lim, ibits, obits, box, opcode;
5354 const u_int16_t *mcp;
5358 lim = (sizeof (mbpfc) / sizeof (mbpfc[0]));
5361 lim = (sizeof (mbpscsi) / sizeof (mbpscsi[0]));
5364 if ((opcode = mbp->param[0]) >= lim) {
5365 mbp->param[0] = MBOX_INVALID_COMMAND;
5366 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
5370 ibits = HIBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5371 obits = LOBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5373 if (ibits == 0 && obits == 0) {
5374 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
5375 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
5380 * Get exclusive usage of mailbox registers.
5384 for (box = 0; box < MAX_MAILBOX; box++) {
5385 if (ibits & (1 << box)) {
5386 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5388 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5391 isp->isp_lastmbxcmd = opcode;
5394 * We assume that we can't overwrite a previous command.
5396 isp->isp_obits = obits;
5397 isp->isp_mboxbsy = 1;
5400 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
5402 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5405 * While we haven't finished the command, spin our wheels here.
5407 MBOX_WAIT_COMPLETE(isp);
5409 if (isp->isp_mboxbsy) {
5411 * Command timed out.
5413 isp->isp_mboxbsy = 0;
5419 * Copy back output registers.
5421 for (box = 0; box < MAX_MAILBOX; box++) {
5422 if (obits & (1 << box)) {
5423 mbp->param[box] = isp->isp_mboxtmp[box];
5429 if (logmask == 0 || opcode == MBOX_EXEC_FIRMWARE) {
5435 cname = (IS_FC(isp))? fc_mbcmd_names[opcode] : scsi_mbcmd_names[opcode];
5437 if (cname == NULL) {
5439 SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
5443 * Just to be chatty here...
5446 switch (mbp->param[0]) {
5447 case MBOX_COMMAND_COMPLETE:
5449 case MBOX_INVALID_COMMAND:
5450 if (logmask & MBLOGMASK(MBOX_COMMAND_COMPLETE))
5451 xname = "INVALID COMMAND";
5453 case MBOX_HOST_INTERFACE_ERROR:
5454 if (logmask & MBLOGMASK(MBOX_HOST_INTERFACE_ERROR))
5455 xname = "HOST INTERFACE ERROR";
5457 case MBOX_TEST_FAILED:
5458 if (logmask & MBLOGMASK(MBOX_TEST_FAILED))
5459 xname = "TEST FAILED";
5461 case MBOX_COMMAND_ERROR:
5462 if (logmask & MBLOGMASK(MBOX_COMMAND_ERROR))
5463 xname = "COMMAND ERROR";
5465 case MBOX_COMMAND_PARAM_ERROR:
5466 if (logmask & MBLOGMASK(MBOX_COMMAND_PARAM_ERROR))
5467 xname = "COMMAND PARAMETER ERROR";
5469 case MBOX_LOOP_ID_USED:
5470 if (logmask & MBLOGMASK(MBOX_LOOP_ID_USED))
5471 xname = "LOOP ID ALREADY IN USE";
5473 case MBOX_PORT_ID_USED:
5474 if (logmask & MBLOGMASK(MBOX_PORT_ID_USED))
5475 xname = "PORT ID ALREADY IN USE";
5477 case MBOX_ALL_IDS_USED:
5478 if (logmask & MBLOGMASK(MBOX_ALL_IDS_USED))
5479 xname = "ALL LOOP IDS IN USE";
5481 case 0: /* special case */
5485 SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
5490 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s)",
5495 isp_fw_state(struct ispsoftc *isp)
5499 fcparam *fcp = isp->isp_param;
5501 mbs.param[0] = MBOX_GET_FW_STATE;
5502 isp_mboxcmd(isp, &mbs, MBLOGALL);
5503 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
5504 fcp->isp_fwstate = mbs.param[1];
5510 isp_update(struct ispsoftc *isp)
5514 for (bus = 0, upmask = isp->isp_update; upmask != 0; bus++) {
5515 if (upmask & (1 << bus)) {
5516 isp_update_bus(isp, bus);
5518 upmask &= ~(1 << bus);
5523 isp_update_bus(struct ispsoftc *isp, int bus)
5529 isp->isp_update &= ~(1 << bus);
5532 * There are no 'per-bus' settings for Fibre Channel.
5536 sdp = isp->isp_param;
5539 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5540 u_int16_t flags, period, offset;
5543 if (sdp->isp_devparam[tgt].dev_enable == 0) {
5544 sdp->isp_devparam[tgt].dev_update = 0;
5545 sdp->isp_devparam[tgt].dev_refresh = 0;
5546 isp_prt(isp, ISP_LOGDEBUG0,
5547 "skipping target %d bus %d update", tgt, bus);
5551 * If the goal is to update the status of the device,
5552 * take what's in goal_flags and try and set the device
5553 * toward that. Otherwise, if we're just refreshing the
5554 * current device state, get the current parameters.
5558 * Refresh overrides set
5560 if (sdp->isp_devparam[tgt].dev_refresh) {
5561 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
5562 sdp->isp_devparam[tgt].dev_refresh = 0;
5564 } else if (sdp->isp_devparam[tgt].dev_update) {
5565 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
5567 * Make sure goal_flags has "Renegotiate on Error"
5568 * on and "Freeze Queue on Error" off.
5570 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
5571 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
5573 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
5576 * Insist that PARITY must be enabled
5577 * if SYNC or WIDE is enabled.
5579 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
5580 mbs.param[2] |= DPARM_PARITY;
5583 if ((mbs.param[2] & DPARM_SYNC) == 0) {
5587 (sdp->isp_devparam[tgt].goal_offset << 8) |
5588 (sdp->isp_devparam[tgt].goal_period);
5591 * A command completion later that has
5592 * RQSTF_NEGOTIATION set can cause
5593 * the dev_refresh/announce cycle also.
5595 * Note: It is really important to update our current
5596 * flags with at least the state of TAG capabilities-
5597 * otherwise we might try and send a tagged command
5598 * when we have it all turned off. So change it here
5599 * to say that current already matches goal.
5601 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
5602 sdp->isp_devparam[tgt].actv_flags |=
5603 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
5604 isp_prt(isp, ISP_LOGDEBUG0,
5605 "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
5606 bus, tgt, mbs.param[2], mbs.param[3] >> 8,
5607 mbs.param[3] & 0xff);
5608 sdp->isp_devparam[tgt].dev_update = 0;
5609 sdp->isp_devparam[tgt].dev_refresh = 1;
5614 mbs.param[1] = (bus << 15) | (tgt << 8);
5615 isp_mboxcmd(isp, &mbs, MBLOGALL);
5617 isp->isp_sendmarker |= (1 << bus);
5620 flags = mbs.param[2];
5621 period = mbs.param[3] & 0xff;
5622 offset = mbs.param[3] >> 8;
5623 sdp->isp_devparam[tgt].actv_flags = flags;
5624 sdp->isp_devparam[tgt].actv_period = period;
5625 sdp->isp_devparam[tgt].actv_offset = offset;
5626 get = (bus << 16) | tgt;
5627 (void) isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, &get);
5630 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5631 if (sdp->isp_devparam[tgt].dev_update ||
5632 sdp->isp_devparam[tgt].dev_refresh) {
5633 isp->isp_update |= (1 << bus);
5639 #ifndef DEFAULT_FRAMESIZE
5640 #define DEFAULT_FRAMESIZE(isp) ICB_DFLT_FRMLEN
5642 #ifndef DEFAULT_EXEC_THROTTLE
5643 #define DEFAULT_EXEC_THROTTLE(isp) ISP_EXEC_THROTTLE
5647 isp_setdfltparm(struct ispsoftc *isp, int channel)
5654 fcparam *fcp = (fcparam *) isp->isp_param;
5658 if (fcp->isp_gotdparms) {
5661 fcp->isp_gotdparms = 1;
5662 fcp->isp_maxfrmlen = DEFAULT_FRAMESIZE(isp);
5663 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
5664 fcp->isp_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
5665 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
5666 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
5667 /* Platform specific.... */
5668 fcp->isp_loopid = DEFAULT_LOOPID(isp);
5669 fcp->isp_nodewwn = DEFAULT_NODEWWN(isp);
5670 fcp->isp_portwwn = DEFAULT_PORTWWN(isp);
5671 fcp->isp_fwoptions = 0;
5672 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
5673 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
5674 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
5675 #ifndef ISP_NO_FASTPOST_FC
5676 fcp->isp_fwoptions |= ICBOPT_FAST_POST;
5678 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
5679 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
5682 * Make sure this is turned off now until we get
5683 * extended options from NVRAM
5685 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
5688 * Now try and read NVRAM unless told to not do so.
5689 * This will set fcparam's isp_nodewwn && isp_portwwn.
5691 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5692 nvfail = isp_read_nvram(isp);
5694 isp->isp_confopts |= ISP_CFG_NONVRAM;
5699 * Set node && port to override platform set defaults
5700 * unless the nvram read failed (or none was done),
5701 * or the platform code wants to use what had been
5702 * set in the defaults.
5705 isp->isp_confopts |= ISP_CFG_OWNWWPN|ISP_CFG_OWNWWNN;
5707 if (isp->isp_confopts & ISP_CFG_OWNWWNN) {
5708 isp_prt(isp, ISP_LOGCONFIG, "Using Node WWN 0x%08x%08x",
5709 (u_int32_t) (DEFAULT_NODEWWN(isp) >> 32),
5710 (u_int32_t) (DEFAULT_NODEWWN(isp) & 0xffffffff));
5711 ISP_NODEWWN(isp) = DEFAULT_NODEWWN(isp);
5714 * We always start out with values derived
5715 * from NVRAM or our platform default.
5717 ISP_NODEWWN(isp) = fcp->isp_nodewwn;
5719 if (isp->isp_confopts & ISP_CFG_OWNWWPN) {
5720 isp_prt(isp, ISP_LOGCONFIG, "Using Port WWN 0x%08x%08x",
5721 (u_int32_t) (DEFAULT_PORTWWN(isp) >> 32),
5722 (u_int32_t) (DEFAULT_PORTWWN(isp) & 0xffffffff));
5723 ISP_PORTWWN(isp) = DEFAULT_PORTWWN(isp);
5726 * We always start out with values derived
5727 * from NVRAM or our platform default.
5729 ISP_PORTWWN(isp) = fcp->isp_portwwn;
5734 sdp = (sdparam *) isp->isp_param;
5738 * Been there, done that, got the T-shirt...
5740 if (sdp->isp_gotdparms) {
5743 sdp->isp_gotdparms = 1;
5746 * Establish some default parameters.
5748 sdp->isp_cmd_dma_burst_enable = 0;
5749 sdp->isp_data_dma_burst_enabl = 1;
5750 sdp->isp_fifo_threshold = 0;
5751 sdp->isp_initiator_id = DEFAULT_IID(isp);
5752 if (isp->isp_type >= ISP_HA_SCSI_1040) {
5753 sdp->isp_async_data_setup = 9;
5755 sdp->isp_async_data_setup = 6;
5757 sdp->isp_selection_timeout = 250;
5758 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
5759 sdp->isp_tag_aging = 8;
5760 sdp->isp_bus_reset_delay = 5;
5762 * Don't retry selection, busy or queue full automatically- reflect
5765 sdp->isp_retry_count = 0;
5766 sdp->isp_retry_delay = 0;
5768 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5769 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
5770 sdp->isp_devparam[tgt].dev_enable = 1;
5774 * If we've not been told to avoid reading NVRAM, try and read it.
5775 * If we're successful reading it, we can then return because NVRAM
5776 * will tell us what the desired settings are. Otherwise, we establish
5777 * some reasonable 'fake' nvram and goal defaults.
5780 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5781 if (isp_read_nvram(isp) == 0) {
5787 * Now try and see whether we have specific values for them.
5789 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5790 mbs.param[0] = MBOX_GET_ACT_NEG_STATE;
5791 isp_mboxcmd(isp, &mbs, MBLOGNONE);
5792 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
5793 sdp->isp_req_ack_active_neg = 1;
5794 sdp->isp_data_line_active_neg = 1;
5796 sdp->isp_req_ack_active_neg =
5797 (mbs.param[1+channel] >> 4) & 0x1;
5798 sdp->isp_data_line_active_neg =
5799 (mbs.param[1+channel] >> 5) & 0x1;
5803 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc3,
5804 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
5805 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
5806 sdp->isp_retry_delay, sdp->isp_async_data_setup);
5807 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc3,
5808 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
5809 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
5810 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
5813 * The trick here is to establish a default for the default (honk!)
5814 * state (goal_flags). Then try and get the current status from
5815 * the card to fill in the current state. We don't, in fact, set
5816 * the default to the SAFE default state- that's not the goal state.
5818 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5820 sdp->isp_devparam[tgt].actv_offset = 0;
5821 sdp->isp_devparam[tgt].actv_period = 0;
5822 sdp->isp_devparam[tgt].actv_flags = 0;
5824 sdp->isp_devparam[tgt].goal_flags =
5825 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
5828 * We default to Wide/Fast for versions less than a 1040
5829 * (unless it's SBus).
5831 if (IS_ULTRA3(isp)) {
5832 off = ISP_80M_SYNCPARMS >> 8;
5833 per = ISP_80M_SYNCPARMS & 0xff;
5834 } else if (IS_ULTRA2(isp)) {
5835 off = ISP_40M_SYNCPARMS >> 8;
5836 per = ISP_40M_SYNCPARMS & 0xff;
5837 } else if (IS_1240(isp)) {
5838 off = ISP_20M_SYNCPARMS >> 8;
5839 per = ISP_20M_SYNCPARMS & 0xff;
5840 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
5841 isp->isp_type < ISP_HA_SCSI_1020A) ||
5842 (isp->isp_bustype == ISP_BT_PCI &&
5843 isp->isp_type < ISP_HA_SCSI_1040) ||
5844 (isp->isp_clock && isp->isp_clock < 60) ||
5845 (sdp->isp_ultramode == 0)) {
5846 off = ISP_10M_SYNCPARMS >> 8;
5847 per = ISP_10M_SYNCPARMS & 0xff;
5849 off = ISP_20M_SYNCPARMS_1040 >> 8;
5850 per = ISP_20M_SYNCPARMS_1040 & 0xff;
5852 sdp->isp_devparam[tgt].goal_offset =
5853 sdp->isp_devparam[tgt].nvrm_offset = off;
5854 sdp->isp_devparam[tgt].goal_period =
5855 sdp->isp_devparam[tgt].nvrm_period = per;
5857 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc3,
5858 channel, tgt, sdp->isp_devparam[tgt].nvrm_flags,
5859 sdp->isp_devparam[tgt].nvrm_offset,
5860 sdp->isp_devparam[tgt].nvrm_period);
5865 * Re-initialize the ISP and complete all orphaned commands
5866 * with a 'botched' notice. The reset/init routines should
5867 * not disturb an already active list of commands.
5869 * Locks held prior to coming here.
5873 isp_reinit(struct ispsoftc *isp)
5879 isp_mark_getpdb_all(isp);
5882 if (isp->isp_state != ISP_RESETSTATE) {
5883 isp_prt(isp, ISP_LOGERR, "isp_reinit cannot reset card");
5884 } else if (isp->isp_role != ISP_ROLE_NONE) {
5886 if (isp->isp_state == ISP_INITSTATE) {
5887 isp->isp_state = ISP_RUNSTATE;
5889 if (isp->isp_state != ISP_RUNSTATE) {
5890 isp_prt(isp, ISP_LOGERR,
5891 "isp_reinit cannot restart card");
5894 isp->isp_nactive = 0;
5896 for (i = 0; i < isp->isp_maxcmds; i++) {
5898 xs = isp->isp_xflist[i];
5902 handle = isp_index_handle(i);
5903 isp_destroy_handle(isp, handle);
5904 if (XS_XFRLEN(xs)) {
5905 ISP_DMAFREE(isp, xs, handle);
5906 XS_RESID(xs) = XS_XFRLEN(xs);
5910 XS_SETERR(xs, HBA_BUSRESET);
5919 isp_read_nvram(struct ispsoftc *isp)
5922 u_int8_t csum, minversion;
5924 u_int8_t _x[ISP2100_NVRAM_SIZE];
5925 u_int16_t _s[ISP2100_NVRAM_SIZE>>1];
5927 #define nvram_data _n._x
5928 #define nvram_words _n._s
5931 amt = ISP2100_NVRAM_SIZE;
5933 } else if (IS_ULTRA2(isp)) {
5934 amt = ISP1080_NVRAM_SIZE;
5937 amt = ISP_NVRAM_SIZE;
5942 * Just read the first two words first to see if we have a valid
5943 * NVRAM to continue reading the rest with.
5945 for (i = 0; i < 2; i++) {
5946 isp_rdnvram_word(isp, i, &nvram_words[i]);
5948 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
5949 nvram_data[2] != 'P') {
5950 if (isp->isp_bustype != ISP_BT_SBUS) {
5951 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
5952 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x",
5953 nvram_data[0], nvram_data[1], nvram_data[2]);
5957 for (i = 2; i < amt>>1; i++) {
5958 isp_rdnvram_word(isp, i, &nvram_words[i]);
5960 for (csum = 0, i = 0; i < amt; i++) {
5961 csum += nvram_data[i];
5964 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
5967 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
5968 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
5969 ISP_NVRAM_VERSION(nvram_data));
5973 if (IS_ULTRA3(isp)) {
5974 isp_parse_nvram_12160(isp, 0, nvram_data);
5976 isp_parse_nvram_12160(isp, 1, nvram_data);
5977 } else if (IS_1080(isp)) {
5978 isp_parse_nvram_1080(isp, 0, nvram_data);
5979 } else if (IS_1280(isp) || IS_1240(isp)) {
5980 isp_parse_nvram_1080(isp, 0, nvram_data);
5981 isp_parse_nvram_1080(isp, 1, nvram_data);
5982 } else if (IS_SCSI(isp)) {
5983 isp_parse_nvram_1020(isp, nvram_data);
5985 isp_parse_nvram_2100(isp, nvram_data);
5993 isp_rdnvram_word(struct ispsoftc *isp, int wo, u_int16_t *rp)
5996 u_int16_t bit, rqst;
5998 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
6000 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
6004 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
6005 if (IS_2312(isp) && isp->isp_port) {
6008 rqst = (ISP_NVRAM_READ << 8) | wo;
6010 } else if (IS_ULTRA2(isp)) {
6011 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
6012 rqst = (ISP_NVRAM_READ << 8) | wo;
6015 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
6016 rqst = (ISP_NVRAM_READ << 6) | wo;
6021 * Clock the word select request out...
6023 for (i = cbits; i >= 0; i--) {
6024 if ((rqst >> i) & 1) {
6025 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
6027 bit = BIU_NVRAM_SELECT;
6029 ISP_WRITE(isp, BIU_NVRAM, bit);
6031 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
6033 ISP_WRITE(isp, BIU_NVRAM, bit);
6037 * Now read the result back in (bits come back in MSB format).
6040 for (i = 0; i < 16; i++) {
6043 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
6045 rv = ISP_READ(isp, BIU_NVRAM);
6046 if (rv & BIU_NVRAM_DATAIN) {
6050 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
6053 ISP_WRITE(isp, BIU_NVRAM, 0);
6055 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
6059 isp_parse_nvram_1020(struct ispsoftc *isp, u_int8_t *nvram_data)
6061 sdparam *sdp = (sdparam *) isp->isp_param;
6064 sdp->isp_fifo_threshold =
6065 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
6066 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
6068 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6069 sdp->isp_initiator_id =
6070 ISP_NVRAM_INITIATOR_ID(nvram_data);
6072 sdp->isp_bus_reset_delay =
6073 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
6075 sdp->isp_retry_count =
6076 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
6078 sdp->isp_retry_delay =
6079 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
6081 sdp->isp_async_data_setup =
6082 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
6084 if (isp->isp_type >= ISP_HA_SCSI_1040) {
6085 if (sdp->isp_async_data_setup < 9) {
6086 sdp->isp_async_data_setup = 9;
6089 if (sdp->isp_async_data_setup != 6) {
6090 sdp->isp_async_data_setup = 6;
6094 sdp->isp_req_ack_active_neg =
6095 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
6097 sdp->isp_data_line_active_neg =
6098 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
6100 sdp->isp_data_dma_burst_enabl =
6101 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
6103 sdp->isp_cmd_dma_burst_enable =
6104 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
6106 sdp->isp_tag_aging =
6107 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
6109 sdp->isp_selection_timeout =
6110 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
6112 sdp->isp_max_queue_depth =
6113 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
6115 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
6117 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6118 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6119 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6120 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6121 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6122 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6123 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6124 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6126 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6127 sdp->isp_devparam[tgt].dev_enable =
6128 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
6129 sdp->isp_devparam[tgt].exc_throttle =
6130 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
6131 sdp->isp_devparam[tgt].nvrm_offset =
6132 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
6133 sdp->isp_devparam[tgt].nvrm_period =
6134 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
6136 * We probably shouldn't lie about this, but it
6137 * it makes it much safer if we limit NVRAM values
6140 if (isp->isp_type < ISP_HA_SCSI_1040) {
6142 * If we're not ultra, we can't possibly
6143 * be a shorter period than this.
6145 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
6146 sdp->isp_devparam[tgt].nvrm_period = 0x19;
6148 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
6149 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
6152 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
6153 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
6156 sdp->isp_devparam[tgt].nvrm_flags = 0;
6157 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
6158 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6159 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6160 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
6161 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6162 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
6163 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6164 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
6165 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6166 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
6167 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6168 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
6169 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6170 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
6171 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6172 0, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6173 sdp->isp_devparam[tgt].nvrm_offset,
6174 sdp->isp_devparam[tgt].nvrm_period);
6175 sdp->isp_devparam[tgt].goal_offset =
6176 sdp->isp_devparam[tgt].nvrm_offset;
6177 sdp->isp_devparam[tgt].goal_period =
6178 sdp->isp_devparam[tgt].nvrm_period;
6179 sdp->isp_devparam[tgt].goal_flags =
6180 sdp->isp_devparam[tgt].nvrm_flags;
6185 isp_parse_nvram_1080(struct ispsoftc *isp, int bus, u_int8_t *nvram_data)
6187 sdparam *sdp = (sdparam *) isp->isp_param;
6192 sdp->isp_fifo_threshold =
6193 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
6195 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6196 sdp->isp_initiator_id =
6197 ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
6199 sdp->isp_bus_reset_delay =
6200 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6202 sdp->isp_retry_count =
6203 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6205 sdp->isp_retry_delay =
6206 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6208 sdp->isp_async_data_setup =
6209 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6211 sdp->isp_req_ack_active_neg =
6212 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6214 sdp->isp_data_line_active_neg =
6215 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6217 sdp->isp_data_dma_burst_enabl =
6218 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6220 sdp->isp_cmd_dma_burst_enable =
6221 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6223 sdp->isp_selection_timeout =
6224 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6226 sdp->isp_max_queue_depth =
6227 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6229 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6230 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6231 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6232 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6233 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6234 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6235 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6236 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6239 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6240 sdp->isp_devparam[tgt].dev_enable =
6241 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6242 sdp->isp_devparam[tgt].exc_throttle =
6243 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6244 sdp->isp_devparam[tgt].nvrm_offset =
6245 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6246 sdp->isp_devparam[tgt].nvrm_period =
6247 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6248 sdp->isp_devparam[tgt].nvrm_flags = 0;
6249 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6250 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6251 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6252 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6253 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6254 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6255 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6256 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6257 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6258 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6259 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6260 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6261 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6262 sdp->isp_devparam[tgt].actv_flags = 0;
6263 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6264 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6265 sdp->isp_devparam[tgt].nvrm_offset,
6266 sdp->isp_devparam[tgt].nvrm_period);
6267 sdp->isp_devparam[tgt].goal_offset =
6268 sdp->isp_devparam[tgt].nvrm_offset;
6269 sdp->isp_devparam[tgt].goal_period =
6270 sdp->isp_devparam[tgt].nvrm_period;
6271 sdp->isp_devparam[tgt].goal_flags =
6272 sdp->isp_devparam[tgt].nvrm_flags;
6277 isp_parse_nvram_12160(struct ispsoftc *isp, int bus, u_int8_t *nvram_data)
6279 sdparam *sdp = (sdparam *) isp->isp_param;
6284 sdp->isp_fifo_threshold =
6285 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
6287 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6288 sdp->isp_initiator_id =
6289 ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
6291 sdp->isp_bus_reset_delay =
6292 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6294 sdp->isp_retry_count =
6295 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6297 sdp->isp_retry_delay =
6298 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6300 sdp->isp_async_data_setup =
6301 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6303 sdp->isp_req_ack_active_neg =
6304 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6306 sdp->isp_data_line_active_neg =
6307 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6309 sdp->isp_data_dma_burst_enabl =
6310 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6312 sdp->isp_cmd_dma_burst_enable =
6313 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6315 sdp->isp_selection_timeout =
6316 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6318 sdp->isp_max_queue_depth =
6319 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6321 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6322 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6323 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6324 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6325 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6326 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6327 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6328 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6330 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6331 sdp->isp_devparam[tgt].dev_enable =
6332 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6333 sdp->isp_devparam[tgt].exc_throttle =
6334 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6335 sdp->isp_devparam[tgt].nvrm_offset =
6336 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6337 sdp->isp_devparam[tgt].nvrm_period =
6338 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6339 sdp->isp_devparam[tgt].nvrm_flags = 0;
6340 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6341 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6342 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6343 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6344 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6345 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6346 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6347 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6348 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6349 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6350 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6351 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6352 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6353 sdp->isp_devparam[tgt].actv_flags = 0;
6354 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6355 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6356 sdp->isp_devparam[tgt].nvrm_offset,
6357 sdp->isp_devparam[tgt].nvrm_period);
6358 sdp->isp_devparam[tgt].goal_offset =
6359 sdp->isp_devparam[tgt].nvrm_offset;
6360 sdp->isp_devparam[tgt].goal_period =
6361 sdp->isp_devparam[tgt].nvrm_period;
6362 sdp->isp_devparam[tgt].goal_flags =
6363 sdp->isp_devparam[tgt].nvrm_flags;
6368 isp_parse_nvram_2100(struct ispsoftc *isp, u_int8_t *nvram_data)
6370 fcparam *fcp = (fcparam *) isp->isp_param;
6374 * There is NVRAM storage for both Port and Node entities-
6375 * but the Node entity appears to be unused on all the cards
6376 * I can find. However, we should account for this being set
6377 * at some point in the future.
6379 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
6380 * bits 48..60. In the case of the 2202, it appears that they do
6381 * use bit 48 to distinguish between the two instances on the card.
6382 * The 2204, which I've never seen, *probably* extends this method.
6384 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
6386 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
6387 (u_int32_t) (wwn >> 32), (u_int32_t) (wwn & 0xffffffff));
6388 if ((wwn >> 60) == 0) {
6389 wwn |= (((u_int64_t) 2)<< 60);
6392 fcp->isp_portwwn = wwn;
6393 if (IS_2200(isp) || IS_23XX(isp)) {
6394 wwn = ISP2200_NVRAM_NODE_NAME(nvram_data);
6396 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
6397 (u_int32_t) (wwn >> 32),
6398 (u_int32_t) (wwn & 0xffffffff));
6399 if ((wwn >> 60) == 0) {
6400 wwn |= (((u_int64_t) 2)<< 60);
6404 wwn &= ~((u_int64_t) 0xfff << 48);
6406 fcp->isp_nodewwn = wwn;
6409 * Make sure we have both Node and Port as non-zero values.
6411 if (fcp->isp_nodewwn != 0 && fcp->isp_portwwn == 0) {
6412 fcp->isp_portwwn = fcp->isp_nodewwn;
6413 } else if (fcp->isp_nodewwn == 0 && fcp->isp_portwwn != 0) {
6414 fcp->isp_nodewwn = fcp->isp_portwwn;
6418 * Make the Node and Port values sane if they're NAA == 2.
6419 * This means to clear bits 48..56 for the Node WWN and
6420 * make sure that there's some non-zero value in 48..56
6423 if (fcp->isp_nodewwn && fcp->isp_portwwn) {
6424 if ((fcp->isp_nodewwn & (((u_int64_t) 0xfff) << 48)) != 0 &&
6425 (fcp->isp_nodewwn >> 60) == 2) {
6426 fcp->isp_nodewwn &= ~((u_int64_t) 0xfff << 48);
6428 if ((fcp->isp_portwwn & (((u_int64_t) 0xfff) << 48)) == 0 &&
6429 (fcp->isp_portwwn >> 60) == 2) {
6430 fcp->isp_portwwn |= ((u_int64_t) 1 << 56);
6434 isp_prt(isp, ISP_LOGDEBUG0,
6435 "NVRAM: maxfrmlen %d execthrottle %d fwoptions 0x%x loopid %x",
6436 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data),
6437 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
6438 ISP2100_NVRAM_OPTIONS(nvram_data),
6439 ISP2100_NVRAM_HARDLOOPID(nvram_data));
6442 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
6443 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0)
6444 fcp->isp_maxfrmlen =
6445 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
6446 fcp->isp_retry_delay =
6447 ISP2100_NVRAM_RETRY_DELAY(nvram_data);
6448 fcp->isp_retry_count =
6449 ISP2100_NVRAM_RETRY_COUNT(nvram_data);
6450 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6452 ISP2100_NVRAM_HARDLOOPID(nvram_data);
6453 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0)
6454 fcp->isp_execthrottle =
6455 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
6456 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
6459 #ifdef ISP_FW_CRASH_DUMP
6460 static void isp2200_fw_dump(struct ispsoftc *);
6461 static void isp2300_fw_dump(struct ispsoftc *);
6464 isp2200_fw_dump(struct ispsoftc *isp)
6470 ptr = FCPARAM(isp)->isp_dump_data;
6472 isp_prt(isp, ISP_LOGERR,
6473 "No place to dump RISC registers and SRAM");
6477 isp_prt(isp, ISP_LOGERR,
6478 "dump area for RISC registers and SRAM already used");
6481 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6482 for (i = 0; i < 100; i++) {
6484 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6488 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6492 for (i = 0; i < 8; i++) {
6493 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6499 for (i = 0; i < 8; i++) {
6500 *ptr++ = ISP_READ(isp, MBOX_BLOCK + (i << 1));
6506 for (i = 0; i < 48; i++) {
6507 *ptr++ = ISP_READ(isp, DMA_BLOCK + 0x20 + (i << 1));
6511 * RISC H/W Registers
6513 ISP_WRITE(isp, BIU2100_CSR, 0);
6514 for (i = 0; i < 16; i++) {
6515 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6521 for (j = 0; j < 8; j++) {
6522 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 8));
6523 for (i = 0; i < 16; i++) {
6525 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6530 * Frame Buffer Hardware Registers
6532 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6533 for (i = 0; i < 16; i++) {
6534 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6538 * Fibre Protocol Module 0 Hardware Registers
6540 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6541 for (i = 0; i < 64; i++) {
6542 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6546 * Fibre Protocol Module 1 Hardware Registers
6548 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6549 for (i = 0; i < 64; i++) {
6550 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6553 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6556 isp_prt(isp, ISP_LOGALL,
6557 "isp_fw_dump: RISC registers dumped successfully");
6558 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6559 for (i = 0; i < 100; i++) {
6561 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6565 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6566 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6569 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6570 for (i = 0; i < 100; i++) {
6572 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6576 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6577 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause After Reset");
6580 ISP_WRITE(isp, RISC_EMB, 0xf2);
6581 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
6582 for (i = 0; i < 100; i++) {
6584 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6589 mbs.param[0] = MBOX_READ_RAM_WORD;
6590 mbs.param[1] = 0x1000;
6591 isp->isp_mbxworkp = (void *) ptr;
6592 isp->isp_mbxwrk0 = 0xefff; /* continuation count */
6593 isp->isp_mbxwrk1 = 0x1001; /* next SRAM address */
6594 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6595 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6596 isp_prt(isp, ISP_LOGWARN,
6597 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6600 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6601 *ptr++ = isp->isp_mboxtmp[2];
6602 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
6603 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6604 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6608 isp2300_fw_dump(struct ispsoftc *isp)
6614 ptr = FCPARAM(isp)->isp_dump_data;
6616 isp_prt(isp, ISP_LOGERR,
6617 "No place to dump RISC registers and SRAM");
6621 isp_prt(isp, ISP_LOGERR,
6622 "dump area for RISC registers and SRAM already used");
6625 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6626 for (i = 0; i < 100; i++) {
6628 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6632 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6636 for (i = 0; i < 8; i++) {
6637 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6641 * ReqQ-RspQ-Risc2Host Status registers
6643 for (i = 0; i < 8; i++) {
6644 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x10 + (i << 1));
6650 for (i = 0; i < 32; i++) {
6652 ISP_READ(isp, PCI_MBOX_REGS2300_OFF + (i << 1));
6656 * Auto Request Response DMA registers
6658 ISP_WRITE(isp, BIU2100_CSR, 0x40);
6659 for (i = 0; i < 32; i++) {
6660 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6666 ISP_WRITE(isp, BIU2100_CSR, 0x50);
6667 for (i = 0; i < 48; i++) {
6668 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6672 * RISC hardware registers
6674 ISP_WRITE(isp, BIU2100_CSR, 0);
6675 for (i = 0; i < 16; i++) {
6676 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6680 * RISC GP? registers
6682 for (j = 0; j < 8; j++) {
6683 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 9));
6684 for (i = 0; i < 16; i++) {
6686 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6691 * frame buffer hardware registers
6693 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6694 for (i = 0; i < 64; i++) {
6695 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6699 * FPM B0 hardware registers
6701 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6702 for (i = 0; i < 64; i++) {
6703 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6707 * FPM B1 hardware registers
6709 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6710 for (i = 0; i < 64; i++) {
6711 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6714 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6717 isp_prt(isp, ISP_LOGALL,
6718 "isp_fw_dump: RISC registers dumped successfully");
6719 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6720 for (i = 0; i < 100; i++) {
6722 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6726 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6727 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6731 mbs.param[0] = MBOX_READ_RAM_WORD;
6732 mbs.param[1] = 0x800;
6733 isp->isp_mbxworkp = (void *) ptr;
6734 isp->isp_mbxwrk0 = 0xf7ff; /* continuation count */
6735 isp->isp_mbxwrk1 = 0x801; /* next SRAM address */
6736 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6737 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6738 isp_prt(isp, ISP_LOGWARN,
6739 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6742 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6743 *ptr++ = isp->isp_mboxtmp[2];
6746 * We don't have access to mailbox registers 8.. onward
6747 * in our 'common' device model- so we have to set it
6748 * here and hope it stays the same!
6750 ISP_WRITE(isp, PCI_MBOX_REGS2300_OFF + (8 << 1), 0x1);
6752 mbs.param[0] = MBOX_READ_RAM_WORD_EXTENDED;
6754 isp->isp_mbxworkp = (void *) ptr;
6755 isp->isp_mbxwrk0 = 0xffff; /* continuation count */
6756 isp->isp_mbxwrk1 = 0x1; /* next SRAM address */
6757 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6758 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6759 isp_prt(isp, ISP_LOGWARN,
6760 "RAM DUMP FAILED @ WORD %x", 0x10000 + isp->isp_mbxwrk1);
6763 ptr = isp->isp_mbxworkp; /* finish final word */
6764 *ptr++ = mbs.param[2];
6765 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
6766 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6767 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6771 isp_fw_dump(struct ispsoftc *isp)
6774 isp2200_fw_dump(isp);
6775 else if (IS_23XX(isp))
6776 isp2300_fw_dump(isp);