2 * Machine and OS Independent (well, as best as possible)
3 * code for the Qlogic ISP SCSI adapters.
5 * Copyright (c) 1997-2006 by Matthew Jacob
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice immediately at the beginning of the file, without modification,
13 * this list of conditions, and the following disclaimer.
14 * 2. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
32 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
33 * ideas dredged from the Solaris driver.
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
41 * Include header file appropriate for platform we're building on.
44 #include <dev/ic/isp_netbsd.h>
47 #include <dev/isp/isp_freebsd.h>
50 #include <dev/ic/isp_openbsd.h>
53 #include "isp_linux.h"
56 #include "isp_solaris.h"
63 #define MBOX_DELAY_COUNT 1000000 / 100
68 static const char portshift[] =
69 "Target %d Loop ID 0x%x (Port 0x%x) => Loop 0x%x (Port 0x%x)";
70 static const char portdup[] =
71 "Target %d duplicates Target %d- killing off both";
72 static const char retained[] =
73 "Retaining Loop ID 0x%x for Target %d (Port 0x%x)";
74 static const char lretained[] =
75 "Retained login of Target %d (Loop ID 0x%x) Port 0x%x";
76 static const char plogout[] =
77 "Logging out Target %d at Loop ID 0x%x (Port 0x%x)";
78 static const char plogierr[] =
79 "Command Error in PLOGI for Port 0x%x (0x%x)";
80 static const char nopdb[] =
81 "Could not get PDB for Device @ Port 0x%x";
82 static const char pdbmfail1[] =
83 "PDB Loop ID info for Device @ Port 0x%x does not match up (0x%x)";
84 static const char pdbmfail2[] =
85 "PDB Port info for Device @ Port 0x%x does not match up (0x%x)";
86 static const char ldumped[] =
87 "Target %d (Loop ID 0x%x) Port 0x%x dumped after login info mismatch";
88 static const char notresp[] =
89 "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
90 static const char xact1[] =
91 "HBA attempted queued transaction with disconnect not set for %d.%d.%d";
92 static const char xact2[] =
93 "HBA attempted queued transaction to target routine %d on target %d bus %d";
94 static const char xact3[] =
95 "HBA attempted queued cmd for %d.%d.%d when queueing disabled";
96 static const char pskip[] =
97 "SCSI phase skipped for target %d.%d.%d";
98 static const char topology[] =
99 "Loop ID %d, Port ID 0x%x, Loop State 0x%x, Topology '%s'";
100 static const char swrej[] =
101 "Fabric Nameserver rejected %s (Reason=0x%x Expl=0x%x) for Port ID 0x%x";
102 static const char finmsg[] =
103 "(%d.%d.%d): FIN dl%d resid %d STS 0x%x SKEY %c XS_ERR=0x%x";
104 static const char sc0[] =
105 "%s CHAN %d FTHRSH %d IID %d RESETD %d RETRYC %d RETRYD %d ASD 0x%x";
106 static const char sc1[] =
107 "%s RAAN 0x%x DLAN 0x%x DDMAB 0x%x CDMAB 0x%x SELTIME %d MQD %d";
108 static const char sc2[] = "%s CHAN %d TGT %d FLAGS 0x%x 0x%x/0x%x";
109 static const char sc3[] = "Generated";
110 static const char sc4[] = "NVRAM";
111 static const char bun[] =
112 "bad underrun for %d.%d (count %d, resid %d, status %s)";
115 * Local function prototypes.
117 static int isp_parse_async(ispsoftc_t *, uint16_t);
118 static int isp_handle_other_response(ispsoftc_t *, int, isphdr_t *,
121 isp_parse_status(ispsoftc_t *, ispstatusreq_t *, XS_T *);
122 static void isp_fastpost_complete(ispsoftc_t *, uint16_t);
123 static int isp_mbox_continue(ispsoftc_t *);
124 static void isp_scsi_init(ispsoftc_t *);
125 static void isp_scsi_channel_init(ispsoftc_t *, int);
126 static void isp_fibre_init(ispsoftc_t *);
127 static void isp_mark_getpdb_all(ispsoftc_t *);
128 static int isp_getmap(ispsoftc_t *, fcpos_map_t *);
129 static int isp_getpdb(ispsoftc_t *, int, isp_pdb_t *);
130 static uint64_t isp_get_portname(ispsoftc_t *, int, int);
131 static int isp_fclink_test(ispsoftc_t *, int);
132 static char *isp2100_fw_statename(int);
133 static int isp_pdb_sync(ispsoftc_t *);
134 static int isp_scan_loop(ispsoftc_t *);
135 static int isp_fabric_mbox_cmd(ispsoftc_t *, mbreg_t *);
136 static int isp_scan_fabric(ispsoftc_t *, int);
137 static void isp_register_fc4_type(ispsoftc_t *);
138 static void isp_fw_state(ispsoftc_t *);
139 static void isp_mboxcmd_qnw(ispsoftc_t *, mbreg_t *, int);
140 static void isp_mboxcmd(ispsoftc_t *, mbreg_t *, int);
142 static void isp_update(ispsoftc_t *);
143 static void isp_update_bus(ispsoftc_t *, int);
144 static void isp_setdfltparm(ispsoftc_t *, int);
145 static int isp_read_nvram(ispsoftc_t *);
146 static void isp_rdnvram_word(ispsoftc_t *, int, uint16_t *);
147 static void isp_parse_nvram_1020(ispsoftc_t *, uint8_t *);
148 static void isp_parse_nvram_1080(ispsoftc_t *, int, uint8_t *);
149 static void isp_parse_nvram_12160(ispsoftc_t *, int, uint8_t *);
150 static void isp_parse_nvram_2100(ispsoftc_t *, uint8_t *);
155 * Hit the chip over the head, download new f/w if available and set it running.
157 * Locking done elsewhere.
161 isp_reset(ispsoftc_t *isp)
165 int loops, i, dodnld = 1;
166 char *btype = "????";
168 isp->isp_state = ISP_NILSTATE;
169 MEMZERO(&mbs, sizeof (mbs));
172 * Basic types (SCSI, FibreChannel and PCI or SBus)
173 * have been set in the MD code. We figure out more
174 * here. Possibly more refined types based upon PCI
175 * identification. Chip revision has been gathered.
177 * After we've fired this chip up, zero out the conf1 register
178 * for SCSI adapters and do other settings for the 2100.
182 * Get the current running firmware revision out of the
183 * chip before we hit it over the head (if this is our
184 * first time through). Note that we store this as the
185 * 'ROM' firmware revision- which it may not be. In any
186 * case, we don't really use this yet, but we may in
189 if (isp->isp_touched == 0) {
191 * First see whether or not we're sitting in the ISP PROM.
192 * If we've just been reset, we'll have the string "ISP "
193 * spread through outgoing mailbox registers 1-3. We do
194 * this for PCI cards because otherwise we really don't
195 * know what state the card is in and we could hang if
196 * we try this command otherwise.
198 * For SBus cards, we just do this because they almost
199 * certainly will be running firmware by now.
201 if (ISP_READ(isp, OUTMAILBOX1) != 0x4953 ||
202 ISP_READ(isp, OUTMAILBOX2) != 0x5020 ||
203 ISP_READ(isp, OUTMAILBOX3) != 0x2020) {
205 * Just in case it was paused...
207 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
208 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
209 isp_mboxcmd(isp, &mbs, MBLOGNONE);
210 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
211 isp->isp_romfw_rev[0] = mbs.param[1];
212 isp->isp_romfw_rev[1] = mbs.param[2];
213 isp->isp_romfw_rev[2] = mbs.param[3];
216 isp->isp_touched = 1;
222 * Set up default request/response queue in-pointer/out-pointer
226 isp->isp_rqstinrp = BIU_REQINP;
227 isp->isp_rqstoutrp = BIU_REQOUTP;
228 isp->isp_respinrp = BIU_RSPINP;
229 isp->isp_respoutrp = BIU_RSPOUTP;
231 isp->isp_rqstinrp = INMAILBOX4;
232 isp->isp_rqstoutrp = OUTMAILBOX4;
233 isp->isp_respinrp = OUTMAILBOX5;
234 isp->isp_respoutrp = INMAILBOX5;
238 * Put the board into PAUSE mode (so we can read the SXP registers
239 * or write FPM/FBM registers).
241 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
244 switch (isp->isp_type) {
267 * While we're paused, reset the FPM module and FBM fifos.
269 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
270 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
271 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
272 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
273 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
274 } else if (IS_1240(isp)) {
275 sdparam *sdp = isp->isp_param;
278 sdp->isp_ultramode = 1;
280 sdp->isp_ultramode = 1;
282 * XXX: Should probably do some bus sensing.
284 } else if (IS_ULTRA2(isp)) {
285 static const char m[] = "bus %d is in %s Mode";
287 sdparam *sdp = isp->isp_param;
289 isp->isp_clock = 100;
293 else if (IS_1080(isp))
295 else if (IS_10160(isp))
297 else if (IS_12160(isp))
302 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
304 case ISP1080_LVD_MODE:
305 sdp->isp_lvdmode = 1;
306 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
308 case ISP1080_HVD_MODE:
309 sdp->isp_diffmode = 1;
310 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
312 case ISP1080_SE_MODE:
313 sdp->isp_ultramode = 1;
314 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
317 isp_prt(isp, ISP_LOGERR,
318 "unknown mode on bus %d (0x%x)", 0, l);
322 if (IS_DUALBUS(isp)) {
324 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
325 l &= ISP1080_MODE_MASK;
327 case ISP1080_LVD_MODE:
328 sdp->isp_lvdmode = 1;
329 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
331 case ISP1080_HVD_MODE:
332 sdp->isp_diffmode = 1;
333 isp_prt(isp, ISP_LOGCONFIG,
334 m, 1, "Differential");
336 case ISP1080_SE_MODE:
337 sdp->isp_ultramode = 1;
338 isp_prt(isp, ISP_LOGCONFIG,
339 m, 1, "Single-Ended");
342 isp_prt(isp, ISP_LOGERR,
343 "unknown mode on bus %d (0x%x)", 1, l);
348 sdparam *sdp = isp->isp_param;
349 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
352 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
356 isp->isp_type = ISP_HA_SCSI_1020;
361 * Some 1020A chips are Ultra Capable, but don't
362 * run the clock rate up for that unless told to
363 * do so by the Ultra Capable bits being set.
366 isp->isp_type = ISP_HA_SCSI_1020A;
371 isp->isp_type = ISP_HA_SCSI_1040;
376 isp->isp_type = ISP_HA_SCSI_1040A;
381 isp->isp_type = ISP_HA_SCSI_1040B;
386 isp->isp_type = ISP_HA_SCSI_1040C;
391 * Now, while we're at it, gather info about ultra
392 * and/or differential mode.
394 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
395 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
396 sdp->isp_diffmode = 1;
398 sdp->isp_diffmode = 0;
400 i = ISP_READ(isp, RISC_PSR);
401 if (isp->isp_bustype == ISP_BT_SBUS) {
402 i &= RISC_PSR_SBUS_ULTRA;
404 i &= RISC_PSR_PCI_ULTRA;
407 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
408 sdp->isp_ultramode = 1;
410 * If we're in Ultra Mode, we have to be 60MHz clock-
411 * even for the SBus version.
415 sdp->isp_ultramode = 0;
417 * Clock is known. Gronk.
422 * Machine dependent clock (if set) overrides
423 * our generic determinations.
425 if (isp->isp_mdvec->dv_clock) {
426 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
427 isp->isp_clock = isp->isp_mdvec->dv_clock;
434 * Clear instrumentation
436 isp->isp_intcnt = isp->isp_intbogus = 0;
439 * Do MD specific pre initialization
446 * Hit the chip over the head with hammer,
447 * and give the ISP a chance to recover.
451 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
458 * Clear data && control DMA engines.
460 ISP_WRITE(isp, CDMA_CONTROL,
461 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
462 ISP_WRITE(isp, DDMA_CONTROL,
463 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
467 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
474 * Clear data && control DMA engines.
476 ISP_WRITE(isp, CDMA2100_CONTROL,
477 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
478 ISP_WRITE(isp, TDMA2100_CONTROL,
479 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
480 ISP_WRITE(isp, RDMA2100_CONTROL,
481 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
485 * Wait for ISP to be ready to go...
487 loops = MBOX_DELAY_COUNT;
490 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET))
493 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
498 ISP_DUMPREGS(isp, "chip reset timed out");
504 * After we've fired this chip up, zero out the conf1 register
505 * for SCSI adapters and other settings for the 2100.
509 ISP_WRITE(isp, BIU_CONF1, 0);
511 ISP_WRITE(isp, BIU2100_CSR, 0);
515 * Reset RISC Processor
517 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
519 /* Clear semaphore register (just to be sure) */
520 ISP_WRITE(isp, BIU_SEMA, 0);
523 * Establish some initial burst rate stuff.
524 * (only for the 1XX0 boards). This really should
525 * be done later after fetching from NVRAM.
528 uint16_t tmp = isp->isp_mdvec->dv_conf1;
530 * Busted FIFO. Turn off all but burst enables.
532 if (isp->isp_type == ISP_HA_SCSI_1040A) {
533 tmp &= BIU_BURST_ENABLE;
535 ISP_SETBITS(isp, BIU_CONF1, tmp);
536 if (tmp & BIU_BURST_ENABLE) {
537 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
538 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
541 if (((sdparam *) isp->isp_param)->isp_ultramode) {
542 while (ISP_READ(isp, RISC_MTR) != 0x1313) {
543 ISP_WRITE(isp, RISC_MTR, 0x1313);
544 ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
547 ISP_WRITE(isp, RISC_MTR, 0x1212);
550 * PTI specific register
552 ISP_WRITE(isp, RISC_EMB, DUAL_BANK)
554 ISP_WRITE(isp, RISC_MTR, 0x1212);
557 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
558 if (IS_2200(isp) || IS_23XX(isp)) {
559 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
563 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE); /* release paused processor */
566 * Do MD specific post initialization
571 * Wait for everything to finish firing up.
573 * Avoid doing this on the 2312 because you can generate a PCI
574 * parity error (chip breakage).
579 loops = MBOX_DELAY_COUNT;
580 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
583 isp_prt(isp, ISP_LOGERR,
584 "MBOX_BUSY never cleared on reset");
591 * Up until this point we've done everything by just reading or
592 * setting registers. From this point on we rely on at least *some*
593 * kind of firmware running in the card.
597 * Do some sanity checking.
599 mbs.param[0] = MBOX_NO_OP;
600 isp_mboxcmd(isp, &mbs, MBLOGALL);
601 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
606 mbs.param[0] = MBOX_MAILBOX_REG_TEST;
607 mbs.param[1] = 0xdead;
608 mbs.param[2] = 0xbeef;
609 mbs.param[3] = 0xffff;
610 mbs.param[4] = 0x1111;
611 mbs.param[5] = 0xa5a5;
612 isp_mboxcmd(isp, &mbs, MBLOGALL);
613 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
616 if (mbs.param[1] != 0xdead || mbs.param[2] != 0xbeef ||
617 mbs.param[3] != 0xffff || mbs.param[4] != 0x1111 ||
618 mbs.param[5] != 0xa5a5) {
619 isp_prt(isp, ISP_LOGERR,
620 "Register Test Failed (0x%x 0x%x 0x%x 0x%x 0x%x)",
621 mbs.param[1], mbs.param[2], mbs.param[3],
622 mbs.param[4], mbs.param[5]);
629 * Download new Firmware, unless requested not to do so.
630 * This is made slightly trickier in some cases where the
631 * firmware of the ROM revision is newer than the revision
632 * compiled into the driver. So, where we used to compare
633 * versions of our f/w and the ROM f/w, now we just see
634 * whether we have f/w at all and whether a config flag
635 * has disabled our download.
637 if ((isp->isp_mdvec->dv_ispfw == NULL) ||
638 (isp->isp_confopts & ISP_CFG_NORELOAD)) {
643 code_org = ISP_CODE_ORG_2300;
645 code_org = ISP_CODE_ORG;
648 isp->isp_mbxworkp = (void *) &isp->isp_mdvec->dv_ispfw[1];
649 isp->isp_mbxwrk0 = isp->isp_mdvec->dv_ispfw[3] - 1;
650 isp->isp_mbxwrk1 = code_org + 1;
651 mbs.param[0] = MBOX_WRITE_RAM_WORD;
652 mbs.param[1] = code_org;
653 mbs.param[2] = isp->isp_mdvec->dv_ispfw[0];
654 isp_mboxcmd(isp, &mbs, MBLOGNONE);
655 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
656 isp_prt(isp, ISP_LOGERR,
657 "F/W download failed at word %d",
658 isp->isp_mbxwrk1 - code_org);
663 * Verify that it downloaded correctly.
665 mbs.param[0] = MBOX_VERIFY_CHECKSUM;
666 mbs.param[1] = code_org;
667 isp_mboxcmd(isp, &mbs, MBLOGNONE);
668 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
669 isp_prt(isp, ISP_LOGERR, "Ram Checksum Failure");
672 isp->isp_loaded_fw = 1;
674 isp->isp_loaded_fw = 0;
675 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
679 * Now start it rolling.
681 * If we didn't actually download f/w,
682 * we still need to (re)start it.
686 mbs.param[0] = MBOX_EXEC_FIRMWARE;
687 mbs.param[1] = code_org;
688 if (IS_2322(isp) || IS_24XX(isp)) {
689 if (isp->isp_loaded_fw) {
697 isp_mboxcmd(isp, &mbs, MBLOGNONE);
699 * Give it a chance to start.
705 * Set CLOCK RATE, but only if asked to.
707 if (isp->isp_clock) {
708 mbs.param[0] = MBOX_SET_CLOCK_RATE;
709 mbs.param[1] = isp->isp_clock;
710 isp_mboxcmd(isp, &mbs, MBLOGALL);
711 /* we will try not to care if this fails */
715 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
716 isp_mboxcmd(isp, &mbs, MBLOGALL);
717 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
722 * The SBus firmware that we are using apparently does not return
723 * major, minor, micro revisions in the mailbox registers, which
724 * is really, really, annoying.
726 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
728 #ifdef ISP_TARGET_MODE
729 isp->isp_fwrev[0] = 7;
730 isp->isp_fwrev[1] = 55;
732 isp->isp_fwrev[0] = 1;
733 isp->isp_fwrev[1] = 37;
735 isp->isp_fwrev[2] = 0;
738 isp->isp_fwrev[0] = mbs.param[1];
739 isp->isp_fwrev[1] = mbs.param[2];
740 isp->isp_fwrev[2] = mbs.param[3];
742 isp_prt(isp, ISP_LOGCONFIG,
743 "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
744 btype, isp->isp_revision, dodnld? "loaded" : "resident",
745 isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
749 * We do not believe firmware attributes for 2100 code less
750 * than 1.17.0, unless it's the firmware we specifically
753 * Note that all 22XX and 23XX f/w is greater than 1.X.0.
755 if (!(ISP_FW_NEWER_THAN(isp, 1, 17, 0))) {
756 #ifdef USE_SMALLER_2100_FIRMWARE
757 FCPARAM(isp)->isp_fwattr = ISP_FW_ATTR_SCCLUN;
759 FCPARAM(isp)->isp_fwattr = 0;
762 FCPARAM(isp)->isp_fwattr = mbs.param[6];
763 isp_prt(isp, ISP_LOGDEBUG0,
764 "Firmware Attributes = 0x%x", mbs.param[6]);
766 if (IS_2KLOGIN(isp)) {
767 isp_prt(isp, ISP_LOGCONFIG, "2K Logins Supported");
771 if (isp->isp_romfw_rev[0] || isp->isp_romfw_rev[1] ||
772 isp->isp_romfw_rev[2]) {
773 isp_prt(isp, ISP_LOGCONFIG, "Last F/W revision was %d.%d.%d",
774 isp->isp_romfw_rev[0], isp->isp_romfw_rev[1],
775 isp->isp_romfw_rev[2]);
778 mbs.param[0] = MBOX_GET_FIRMWARE_STATUS;
779 isp_mboxcmd(isp, &mbs, MBLOGALL);
780 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
783 isp->isp_maxcmds = mbs.param[2];
784 isp_prt(isp, ISP_LOGINFO,
785 "%d max I/O commands supported", mbs.param[2]);
789 * Set up DMA for the request and result mailboxes.
791 if (ISP_MBOXDMASETUP(isp) != 0) {
792 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
795 isp->isp_state = ISP_RESETSTATE;
798 * Okay- now that we have new firmware running, we now (re)set our
799 * notion of how many luns we support. This is somewhat tricky because
800 * if we haven't loaded firmware, we sometimes do not have an easy way
801 * of knowing how many luns we support.
803 * Expanded lun firmware gives you 32 luns for SCSI cards and
804 * 16384 luns for Fibre Channel cards.
806 * It turns out that even for QLogic 2100s with ROM 1.10 and above
807 * we do get a firmware attributes word returned in mailbox register 6.
809 * Because the lun is in a different position in the Request Queue
810 * Entry structure for Fibre Channel with expanded lun firmware, we
811 * can only support one lun (lun zero) when we don't know what kind
812 * of firmware we're running.
816 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
817 isp->isp_maxluns = 32;
819 isp->isp_maxluns = 8;
822 isp->isp_maxluns = 8;
825 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
826 isp->isp_maxluns = 16384;
828 isp->isp_maxluns = 16;
834 * Initialize Parameters of Hardware to a known state.
836 * Locks are held before coming here.
840 isp_init(ispsoftc_t *isp)
843 * Must do this first to get defaults established.
845 isp_setdfltparm(isp, 0);
846 if (IS_DUALBUS(isp)) {
847 isp_setdfltparm(isp, 1);
857 isp_scsi_init(ispsoftc_t *isp)
859 sdparam *sdp_chan0, *sdp_chan1;
862 sdp_chan0 = isp->isp_param;
863 sdp_chan1 = sdp_chan0;
864 if (IS_DUALBUS(isp)) {
869 * If we have no role (neither target nor initiator), return.
871 if (isp->isp_role == ISP_ROLE_NONE) {
875 /* First do overall per-card settings. */
878 * If we have fast memory timing enabled, turn it on.
880 if (sdp_chan0->isp_fast_mttr) {
881 ISP_WRITE(isp, RISC_MTR, 0x1313);
885 * Set Retry Delay and Count.
886 * You set both channels at the same time.
888 MEMZERO(&mbs, sizeof (mbs));
889 mbs.param[0] = MBOX_SET_RETRY_COUNT;
890 mbs.param[1] = sdp_chan0->isp_retry_count;
891 mbs.param[2] = sdp_chan0->isp_retry_delay;
892 mbs.param[6] = sdp_chan1->isp_retry_count;
893 mbs.param[7] = sdp_chan1->isp_retry_delay;
895 isp_mboxcmd(isp, &mbs, MBLOGALL);
896 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
901 * Set ASYNC DATA SETUP time. This is very important.
903 mbs.param[0] = MBOX_SET_ASYNC_DATA_SETUP_TIME;
904 mbs.param[1] = sdp_chan0->isp_async_data_setup;
905 mbs.param[2] = sdp_chan1->isp_async_data_setup;
906 isp_mboxcmd(isp, &mbs, MBLOGALL);
907 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
912 * Set ACTIVE Negation State.
914 mbs.param[0] = MBOX_SET_ACT_NEG_STATE;
916 (sdp_chan0->isp_req_ack_active_neg << 4) |
917 (sdp_chan0->isp_data_line_active_neg << 5);
919 (sdp_chan1->isp_req_ack_active_neg << 4) |
920 (sdp_chan1->isp_data_line_active_neg << 5);
922 isp_mboxcmd(isp, &mbs, MBLOGNONE);
923 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
924 isp_prt(isp, ISP_LOGERR,
925 "failed to set active negation state (%d,%d), (%d,%d)",
926 sdp_chan0->isp_req_ack_active_neg,
927 sdp_chan0->isp_data_line_active_neg,
928 sdp_chan1->isp_req_ack_active_neg,
929 sdp_chan1->isp_data_line_active_neg);
936 * Set the Tag Aging limit
938 mbs.param[0] = MBOX_SET_TAG_AGE_LIMIT;
939 mbs.param[1] = sdp_chan0->isp_tag_aging;
940 mbs.param[2] = sdp_chan1->isp_tag_aging;
941 isp_mboxcmd(isp, &mbs, MBLOGALL);
942 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
943 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
944 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
949 * Set selection timeout.
951 mbs.param[0] = MBOX_SET_SELECT_TIMEOUT;
952 mbs.param[1] = sdp_chan0->isp_selection_timeout;
953 mbs.param[2] = sdp_chan1->isp_selection_timeout;
954 isp_mboxcmd(isp, &mbs, MBLOGALL);
955 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
959 /* now do per-channel settings */
960 isp_scsi_channel_init(isp, 0);
962 isp_scsi_channel_init(isp, 1);
965 * Now enable request/response queues
968 if (IS_ULTRA2(isp) || IS_1240(isp)) {
969 mbs.param[0] = MBOX_INIT_RES_QUEUE_A64;
970 mbs.param[1] = RESULT_QUEUE_LEN(isp);
971 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
972 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
974 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
975 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
976 isp_mboxcmd(isp, &mbs, MBLOGALL);
977 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
980 isp->isp_residx = mbs.param[5];
982 mbs.param[0] = MBOX_INIT_REQ_QUEUE_A64;
983 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
984 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
985 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
987 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
988 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
989 isp_mboxcmd(isp, &mbs, MBLOGALL);
990 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
993 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
995 mbs.param[0] = MBOX_INIT_RES_QUEUE;
996 mbs.param[1] = RESULT_QUEUE_LEN(isp);
997 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
998 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1000 isp_mboxcmd(isp, &mbs, MBLOGALL);
1001 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1004 isp->isp_residx = mbs.param[5];
1006 mbs.param[0] = MBOX_INIT_REQ_QUEUE;
1007 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1008 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1009 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1011 isp_mboxcmd(isp, &mbs, MBLOGALL);
1012 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1015 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1019 * Turn on Fast Posting, LVD transitions
1021 * Ultra2 F/W always has had fast posting (and LVD transitions)
1023 * Ultra and older (i.e., SBus) cards may not. It's just safer
1024 * to assume not for them.
1027 mbs.param[0] = MBOX_SET_FW_FEATURES;
1030 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1032 if (IS_ULTRA2(isp) || IS_1240(isp))
1033 mbs.param[1] |= FW_FEATURE_RIO_16BIT;
1035 #ifndef ISP_NO_FASTPOST
1036 if (IS_ULTRA2(isp) || IS_1240(isp))
1037 mbs.param[1] |= FW_FEATURE_FAST_POST;
1040 if (mbs.param[1] != 0) {
1041 uint16_t sfeat = mbs.param[1];
1042 isp_mboxcmd(isp, &mbs, MBLOGALL);
1043 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1044 isp_prt(isp, ISP_LOGINFO,
1045 "Enabled FW features (0x%x)", sfeat);
1050 * Let the outer layers decide whether to issue a SCSI bus reset.
1052 isp->isp_state = ISP_INITSTATE;
1056 isp_scsi_channel_init(ispsoftc_t *isp, int channel)
1062 sdp = isp->isp_param;
1066 * Set (possibly new) Initiator ID.
1068 MEMZERO(&mbs, sizeof (mbs));
1069 mbs.param[0] = MBOX_SET_INIT_SCSI_ID;
1070 mbs.param[1] = (channel << 7) | sdp->isp_initiator_id;
1071 isp_mboxcmd(isp, &mbs, MBLOGALL);
1072 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1075 isp_prt(isp, ISP_LOGINFO, "Initiator ID is %d on Channel %d",
1076 sdp->isp_initiator_id, channel);
1080 * Set current per-target parameters to an initial safe minimum.
1082 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1086 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1089 #ifndef ISP_TARGET_MODE
1090 sdf = sdp->isp_devparam[tgt].goal_flags;
1091 sdf &= DPARM_SAFE_DFLT;
1093 * It is not quite clear when this changed over so that
1094 * we could force narrow and async for 1000/1020 cards,
1095 * but assume that this is only the case for loaded
1098 if (isp->isp_loaded_fw) {
1099 sdf |= DPARM_NARROW | DPARM_ASYNC;
1103 * The !$*!)$!$)* f/w uses the same index into some
1104 * internal table to decide how to respond to negotiations,
1105 * so if we've said "let's be safe" for ID X, and ID X
1106 * selects *us*, the negotiations will back to 'safe'
1107 * (as in narrow/async). What the f/w *should* do is
1108 * use the initiator id settings to decide how to respond.
1110 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1112 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1113 mbs.param[1] = (channel << 15) | (tgt << 8);
1115 if ((sdf & DPARM_SYNC) == 0) {
1119 (sdp->isp_devparam[tgt].goal_offset << 8) |
1120 (sdp->isp_devparam[tgt].goal_period);
1122 isp_prt(isp, ISP_LOGDEBUG0,
1123 "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1124 channel, tgt, mbs.param[2], mbs.param[3] >> 8,
1125 mbs.param[3] & 0xff);
1126 isp_mboxcmd(isp, &mbs, MBLOGNONE);
1127 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1128 sdf = DPARM_SAFE_DFLT;
1129 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1130 mbs.param[1] = (tgt << 8) | (channel << 15);
1133 isp_mboxcmd(isp, &mbs, MBLOGALL);
1134 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1140 * We don't update any information directly from the f/w
1141 * because we need to run at least one command to cause a
1142 * new state to be latched up. So, we just assume that we
1143 * converge to the values we just had set.
1145 * Ensure that we don't believe tagged queuing is enabled yet.
1146 * It turns out that sometimes the ISP just ignores our
1147 * attempts to set parameters for devices that it hasn't
1150 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1151 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1152 mbs.param[0] = MBOX_SET_DEV_QUEUE_PARAMS;
1153 mbs.param[1] = (channel << 15) | (tgt << 8) | lun;
1154 mbs.param[2] = sdp->isp_max_queue_depth;
1155 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1156 isp_mboxcmd(isp, &mbs, MBLOGALL);
1157 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1162 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1163 if (sdp->isp_devparam[tgt].dev_refresh) {
1164 isp->isp_sendmarker |= (1 << channel);
1165 isp->isp_update |= (1 << channel);
1172 * Fibre Channel specific initialization.
1174 * Locks are held before coming here.
1177 isp_fibre_init(ispsoftc_t *isp)
1180 isp_icb_t local, *icbp = &local;
1183 uint64_t nwwn, pwwn;
1185 fcp = isp->isp_param;
1188 * Do this *before* initializing the firmware.
1190 isp_mark_getpdb_all(isp);
1191 fcp->isp_fwstate = FW_CONFIG_WAIT;
1192 fcp->isp_loopstate = LOOP_NIL;
1195 * If we have no role (neither target nor initiator), return.
1197 if (isp->isp_role == ISP_ROLE_NONE) {
1201 loopid = fcp->isp_loopid;
1202 MEMZERO(icbp, sizeof (*icbp));
1203 icbp->icb_version = ICB_VERSION1;
1206 * Firmware Options are either retrieved from NVRAM or
1207 * are patched elsewhere. We check them for sanity here
1208 * and make changes based on board revision, but otherwise
1209 * let others decide policy.
1213 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1215 if ((isp->isp_type == ISP_HA_FC_2100) && isp->isp_revision < 5) {
1216 fcp->isp_fwoptions &= ~ICBOPT_FAIRNESS;
1220 * We have to use FULL LOGIN even though it resets the loop too much
1221 * because otherwise port database entries don't get updated after
1222 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1224 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1225 fcp->isp_fwoptions |= ICBOPT_FULL_LOGIN;
1229 * Insist on Port Database Update Async notifications
1231 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
1234 * Make sure that target role reflects into fwoptions.
1236 if (isp->isp_role & ISP_ROLE_TARGET) {
1237 fcp->isp_fwoptions |= ICBOPT_TGT_ENABLE;
1239 fcp->isp_fwoptions &= ~ICBOPT_TGT_ENABLE;
1242 if (isp->isp_role & ISP_ROLE_INITIATOR) {
1243 fcp->isp_fwoptions &= ~ICBOPT_INI_DISABLE;
1245 fcp->isp_fwoptions |= ICBOPT_INI_DISABLE;
1249 * Propagate all of this into the ICB structure.
1251 icbp->icb_fwoptions = fcp->isp_fwoptions;
1252 icbp->icb_maxfrmlen = fcp->isp_maxfrmlen;
1253 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN ||
1254 icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1255 isp_prt(isp, ISP_LOGERR,
1256 "bad frame length (%d) from NVRAM- using %d",
1257 fcp->isp_maxfrmlen, ICB_DFLT_FRMLEN);
1258 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1260 icbp->icb_maxalloc = fcp->isp_maxalloc;
1261 if (icbp->icb_maxalloc < 1) {
1262 isp_prt(isp, ISP_LOGERR,
1263 "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1264 icbp->icb_maxalloc = 16;
1266 icbp->icb_execthrottle = fcp->isp_execthrottle;
1267 if (icbp->icb_execthrottle < 1) {
1268 isp_prt(isp, ISP_LOGERR,
1269 "bad execution throttle of %d- using 16",
1270 fcp->isp_execthrottle);
1271 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1273 icbp->icb_retry_delay = fcp->isp_retry_delay;
1274 icbp->icb_retry_count = fcp->isp_retry_count;
1275 icbp->icb_hardaddr = loopid;
1276 if (icbp->icb_hardaddr >= 125) {
1278 * We end up with these Loop IDs for F-Port topologies
1280 if (icbp->icb_hardaddr != 0xff && icbp->icb_hardaddr != 0x800) {
1281 isp_prt(isp, ISP_LOGERR,
1282 "bad hard address %u- resetting to zero",
1283 icbp->icb_hardaddr);
1285 icbp->icb_hardaddr = 0;
1288 * Right now we just set extended options to prefer point-to-point
1289 * over loop based upon some soft config options.
1291 * NB: for the 2300, ICBOPT_EXTENDED is required.
1293 if (IS_2200(isp) || IS_23XX(isp)) {
1294 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1296 * Prefer or force Point-To-Point instead Loop?
1298 switch(isp->isp_confopts & ISP_CFG_PORT_PREF) {
1300 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1302 case ISP_CFG_NPORT_ONLY:
1303 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1305 case ISP_CFG_LPORT_ONLY:
1306 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1309 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1314 * QLogic recommends that FAST Posting be turned
1315 * off for 23XX cards and instead allow the HBA
1316 * to write response queue entries and interrupt
1317 * after a delay (ZIO).
1319 * If we set ZIO, it will disable fast posting,
1320 * so we don't need to clear it in fwoptions.
1322 * Depending on the role we're selecting, we
1323 * chose fast posting or not as it still is
1324 * a win for target mode.
1327 if (isp->isp_role == ISP_ROLE_TARGET) {
1328 icbp->icb_fwoptions |= ICBOPT_FAST_POST;
1330 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1333 icbp->icb_fwoptions |= ICBOPT_FAST_POST;
1337 * Values, in 100us increments. The default
1338 * is 2 (200us) if a value 0 (default) is
1341 icbp->icb_idelaytimer = 2;
1344 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1345 icbp->icb_zfwoptions |= ICBZOPT_RATE_ONEGB;
1346 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1347 icbp->icb_zfwoptions |= ICBZOPT_RATE_TWOGB;
1349 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1354 #ifndef ISP_NO_RIO_FC
1356 * RIO seems to be enabled in 2100s for fw >= 1.17.0.
1358 * I've had some questionable problems with RIO on 2200.
1359 * More specifically, on a 2204 I had problems with RIO
1360 * on a Linux system where I was dropping commands right
1361 * and left. It's not clear to me what the actual problem
1364 * 23XX Cards do not support RIO. Instead they support ZIO.
1367 if (!IS_23XX(isp) && ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1368 icbp->icb_xfwoptions |= ICBXOPT_RIO_16BIT;
1369 icbp->icb_racctimer = 4;
1370 icbp->icb_idelaytimer = 8;
1375 MEMZERO(&mbs, sizeof (mbs));
1378 * For 22XX > 2.1.26 && 23XX, set some options.
1379 * XXX: Probably okay for newer 2100 f/w too.
1381 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1383 * Turn on LIP F8 async event (1)
1384 * Turn on generate AE 8013 on all LIP Resets (2)
1385 * Disable LIP F7 switching (8)
1387 mbs.param[0] = MBOX_SET_FIRMWARE_OPTIONS;
1391 isp_mboxcmd(isp, &mbs, MBLOGALL);
1393 icbp->icb_logintime = ICB_LOGIN_TOV;
1394 icbp->icb_lunetimeout = ICB_LUN_ENABLE_TOV;
1397 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
1398 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
1399 ISP_WRITE(isp, isp->isp_respinrp, 0);
1400 ISP_WRITE(isp, isp->isp_respoutrp, 0);
1403 nwwn = ISP_NODEWWN(isp);
1404 pwwn = ISP_PORTWWN(isp);
1406 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1407 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, nwwn);
1408 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, pwwn);
1409 isp_prt(isp, ISP_LOGDEBUG1,
1410 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1411 ((uint32_t) (nwwn >> 32)),
1412 ((uint32_t) (nwwn & 0xffffffff)),
1413 ((uint32_t) (pwwn >> 32)),
1414 ((uint32_t) (pwwn & 0xffffffff)));
1416 isp_prt(isp, ISP_LOGDEBUG1, "Not using any WWNs");
1417 icbp->icb_fwoptions &= ~(ICBOPT_BOTH_WWNS|ICBOPT_FULL_LOGIN);
1419 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1420 if (icbp->icb_rqstqlen < 1) {
1421 isp_prt(isp, ISP_LOGERR, "bad request queue length");
1423 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1424 if (icbp->icb_rsltqlen < 1) {
1425 isp_prt(isp, ISP_LOGERR, "bad result queue length");
1427 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1428 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1429 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1430 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1431 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1432 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1433 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1434 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1435 isp_prt(isp, ISP_LOGDEBUG0,
1436 "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1437 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1439 FC_SCRATCH_ACQUIRE(isp);
1440 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1445 mbs.param[0] = MBOX_INIT_FIRMWARE;
1447 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1448 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1451 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1452 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1453 isp_mboxcmd(isp, &mbs, MBLOGALL);
1454 FC_SCRATCH_RELEASE(isp);
1455 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1458 isp->isp_reqidx = isp->isp_reqodx = 0;
1459 isp->isp_residx = 0;
1460 isp->isp_sendmarker = 1;
1463 * Whatever happens, we're now committed to being here.
1465 isp->isp_state = ISP_INITSTATE;
1469 * Fibre Channel Support- get the port database for the id.
1471 * Locks are held before coming here. Return 0 if success,
1476 isp_getmap(ispsoftc_t *isp, fcpos_map_t *map)
1478 fcparam *fcp = (fcparam *) isp->isp_param;
1481 MEMZERO(&mbs, sizeof (mbs));
1482 mbs.param[0] = MBOX_GET_FC_AL_POSITION_MAP;
1484 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1485 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1487 * Unneeded. For the 2100, except for initializing f/w, registers
1488 * 4/5 have to not be written to.
1495 FC_SCRATCH_ACQUIRE(isp);
1496 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1497 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1498 MEMCPY(map, fcp->isp_scratch, sizeof (fcpos_map_t));
1499 map->fwmap = mbs.param[1] != 0;
1500 FC_SCRATCH_RELEASE(isp);
1503 FC_SCRATCH_RELEASE(isp);
1508 isp_mark_getpdb_all(ispsoftc_t *isp)
1510 fcparam *fcp = (fcparam *) isp->isp_param;
1512 for (i = 0; i < MAX_FC_TARG; i++) {
1513 fcp->portdb[i].valid = fcp->portdb[i].fabric_dev = 0;
1518 isp_getpdb(ispsoftc_t *isp, int id, isp_pdb_t *pdbp)
1520 fcparam *fcp = (fcparam *) isp->isp_param;
1523 MEMZERO(&mbs, sizeof (mbs));
1524 mbs.param[0] = MBOX_GET_PORT_DB;
1525 if (IS_2KLOGIN(isp)) {
1527 mbs.obits |= (1 << 10);
1529 mbs.param[1] = id << 8;
1531 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1532 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1534 * Unneeded. For the 2100, except for initializing f/w, registers
1535 * 4/5 have to not be written to.
1540 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1541 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1542 FC_SCRATCH_ACQUIRE(isp);
1543 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1544 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1545 isp_get_pdb(isp, (isp_pdb_t *)fcp->isp_scratch, pdbp);
1546 FC_SCRATCH_RELEASE(isp);
1549 FC_SCRATCH_RELEASE(isp);
1554 isp_get_portname(ispsoftc_t *isp, int loopid, int nodename)
1559 MEMZERO(&mbs, sizeof (mbs));
1560 mbs.param[0] = MBOX_GET_PORT_NAME;
1561 if (IS_2KLOGIN(isp)) {
1562 mbs.param[1] = loopid;
1565 mbs.obits |= (1 << 10);
1567 mbs.param[1] = loopid << 8;
1571 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1572 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1574 (((uint64_t)(mbs.param[2] & 0xff)) << 56) |
1575 (((uint64_t)(mbs.param[2] >> 8)) << 48) |
1576 (((uint64_t)(mbs.param[3] & 0xff)) << 40) |
1577 (((uint64_t)(mbs.param[3] >> 8)) << 32) |
1578 (((uint64_t)(mbs.param[6] & 0xff)) << 24) |
1579 (((uint64_t)(mbs.param[6] >> 8)) << 16) |
1580 (((uint64_t)(mbs.param[7] & 0xff)) << 8) |
1581 (((uint64_t)(mbs.param[7] >> 8)));
1587 * Make sure we have good FC link and know our Loop ID.
1591 isp_fclink_test(ispsoftc_t *isp, int usdelay)
1593 static char *toponames[] = {
1598 "F Port (no FLOGI_ACC response)"
1601 int count, check_for_fabric;
1607 fcp = isp->isp_param;
1610 * XXX: Here is where we would start a 'loop dead' timeout
1614 * Wait up to N microseconds for F/W to go to a ready state.
1616 lwfs = FW_CONFIG_WAIT;
1618 while (count < usdelay) {
1621 NANOTIME_T hra, hrb;
1625 if (lwfs != fcp->isp_fwstate) {
1626 isp_prt(isp, ISP_LOGINFO, "Firmware State <%s->%s>",
1627 isp2100_fw_statename((int)lwfs),
1628 isp2100_fw_statename((int)fcp->isp_fwstate));
1629 lwfs = fcp->isp_fwstate;
1631 if (fcp->isp_fwstate == FW_READY) {
1637 * Get the elapsed time in nanoseconds.
1638 * Always guaranteed to be non-zero.
1640 enano = NANOTIME_SUB(&hrb, &hra);
1642 isp_prt(isp, ISP_LOGDEBUG1,
1643 "usec%d: 0x%lx->0x%lx enano 0x%x%08x",
1644 count, (long) GET_NANOSEC(&hra), (long) GET_NANOSEC(&hrb),
1645 (uint32_t)(enano >> 32), (uint32_t)(enano & 0xffffffff));
1648 * If the elapsed time is less than 1 millisecond,
1649 * delay a period of time up to that millisecond of
1652 * This peculiar code is an attempt to try and avoid
1653 * invoking uint64_t math support functions for some
1654 * platforms where linkage is a problem.
1656 if (enano < (1000 * 1000)) {
1658 enano = (1000 * 1000) - enano;
1659 while (enano > (uint64_t) 4000000000U) {
1660 USEC_SLEEP(isp, 4000000);
1661 enano -= (uint64_t) 4000000000U;
1665 USEC_SLEEP(isp, wrk);
1667 while (enano > (uint64_t) 4000000000U) {
1669 enano -= (uint64_t) 4000000000U;
1672 count += (wrk / 1000);
1677 * If we haven't gone to 'ready' state, return.
1679 if (fcp->isp_fwstate != FW_READY) {
1684 * Get our Loop ID (if possible). We really need to have it.
1686 MEMZERO(&mbs, sizeof (mbs));
1687 mbs.param[0] = MBOX_GET_LOOP_ID;
1688 isp_mboxcmd(isp, &mbs, MBLOGALL);
1689 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1692 fcp->isp_loopid = mbs.param[1];
1693 if (fcp->isp_loopid == 0xffff) { /* happens with 2k login f/w */
1694 fcp->isp_loopid = MAX_FC_TARG-1;
1695 } else if (fcp->isp_loopid >= MAX_FC_TARG) {
1696 isp_prt(isp, ISP_LOGWARN, "bad initiator loopid (0x%x)", fcp->isp_loopid);
1697 fcp->isp_loopid = MAX_FC_TARG-1;
1699 if (IS_2200(isp) || IS_23XX(isp)) {
1700 int topo = (int) mbs.param[6];
1701 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB)
1702 topo = TOPO_PTP_STUB;
1703 fcp->isp_topo = topo;
1705 fcp->isp_topo = TOPO_NL_PORT;
1710 fcp->isp_portid = mbs.param[2] | (mbs.param[3] << 16);
1713 * Check to see if we're on a fabric by trying to see if we
1714 * can talk to the fabric name server. This can be a bit
1715 * tricky because if we're a 2100, we should check always
1716 * (in case we're connected to a server doing aliasing).
1718 fcp->isp_onfabric = 0;
1722 * Don't bother with fabric if we are using really old
1723 * 2100 firmware. It's just not worth it.
1725 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37)) {
1726 check_for_fabric = 1;
1728 check_for_fabric = 0;
1730 } else if (fcp->isp_topo == TOPO_FL_PORT ||
1731 fcp->isp_topo == TOPO_F_PORT) {
1732 check_for_fabric = 1;
1734 check_for_fabric = 0;
1736 if (check_for_fabric && isp_getpdb(isp, FL_PORT_ID, &pdb) == 0) {
1737 int loopid = FL_PORT_ID;
1739 fcp->isp_topo = TOPO_FL_PORT;
1742 if (BITS2WORD(pdb.pdb_portid_bits) == 0) {
1746 fcp->isp_topo = TOPO_NL_PORT;
1749 fcp->isp_portid = mbs.param[2] | ((int) mbs.param[3] << 16);
1752 * Save the Fabric controller's port database entry.
1754 lp = &fcp->portdb[loopid];
1756 (((uint64_t)pdb.pdb_nodename[0]) << 56) |
1757 (((uint64_t)pdb.pdb_nodename[1]) << 48) |
1758 (((uint64_t)pdb.pdb_nodename[2]) << 40) |
1759 (((uint64_t)pdb.pdb_nodename[3]) << 32) |
1760 (((uint64_t)pdb.pdb_nodename[4]) << 24) |
1761 (((uint64_t)pdb.pdb_nodename[5]) << 16) |
1762 (((uint64_t)pdb.pdb_nodename[6]) << 8) |
1763 (((uint64_t)pdb.pdb_nodename[7]));
1765 (((uint64_t)pdb.pdb_portname[0]) << 56) |
1766 (((uint64_t)pdb.pdb_portname[1]) << 48) |
1767 (((uint64_t)pdb.pdb_portname[2]) << 40) |
1768 (((uint64_t)pdb.pdb_portname[3]) << 32) |
1769 (((uint64_t)pdb.pdb_portname[4]) << 24) |
1770 (((uint64_t)pdb.pdb_portname[5]) << 16) |
1771 (((uint64_t)pdb.pdb_portname[6]) << 8) |
1772 (((uint64_t)pdb.pdb_portname[7]));
1774 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
1775 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
1776 lp->loopid = pdb.pdb_loopid;
1777 lp->loggedin = lp->valid = 1;
1778 fcp->isp_onfabric = 1;
1779 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1780 isp_register_fc4_type(isp);
1783 fcp->isp_onfabric = 0;
1784 fcp->portdb[FL_PORT_ID].valid = 0;
1787 fcp->isp_gbspeed = 1;
1789 mbs.param[0] = MBOX_GET_SET_DATA_RATE;
1790 mbs.param[1] = MBGSD_GET_RATE;
1791 /* mbs.param[2] undefined if we're just getting rate */
1792 isp_mboxcmd(isp, &mbs, MBLOGALL);
1793 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1794 if (mbs.param[1] == MBGSD_TWOGB) {
1795 isp_prt(isp, ISP_LOGINFO, "2Gb link speed/s");
1796 fcp->isp_gbspeed = 2;
1801 isp_prt(isp, ISP_LOGCONFIG, topology, fcp->isp_loopid,
1802 fcp->isp_portid, fcp->isp_loopstate, toponames[fcp->isp_topo]);
1805 * Announce ourselves, too. This involves synthesizing an entry.
1807 if (fcp->isp_iid_set == 0) {
1808 fcp->isp_iid_set = 1;
1809 fcp->isp_iid = fcp->isp_loopid;
1810 lp = &fcp->portdb[fcp->isp_iid];
1812 lp = &fcp->portdb[fcp->isp_iid];
1813 if (fcp->isp_portid != lp->portid ||
1814 fcp->isp_loopid != lp->loopid ||
1815 fcp->isp_nodewwn != ISP_NODEWWN(isp) ||
1816 fcp->isp_portwwn != ISP_PORTWWN(isp)) {
1818 count = fcp->isp_iid;
1819 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1822 lp->loopid = fcp->isp_loopid;
1823 lp->portid = fcp->isp_portid;
1824 lp->node_wwn = ISP_NODEWWN(isp);
1825 lp->port_wwn = ISP_PORTWWN(isp);
1826 switch (isp->isp_role) {
1830 case ISP_ROLE_TARGET:
1831 lp->roles = SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT;
1833 case ISP_ROLE_INITIATOR:
1834 lp->roles = SVC3_INI_ROLE >> SVC3_ROLE_SHIFT;
1837 lp->roles = (SVC3_INI_ROLE|SVC3_TGT_ROLE) >> SVC3_ROLE_SHIFT;
1840 lp->loggedin = lp->valid = 1;
1841 count = fcp->isp_iid;
1842 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1847 isp2100_fw_statename(int state)
1850 case FW_CONFIG_WAIT: return "Config Wait";
1851 case FW_WAIT_AL_PA: return "Waiting for AL_PA";
1852 case FW_WAIT_LOGIN: return "Wait Login";
1853 case FW_READY: return "Ready";
1854 case FW_LOSS_OF_SYNC: return "Loss Of Sync";
1855 case FW_ERROR: return "Error";
1856 case FW_REINIT: return "Re-Init";
1857 case FW_NON_PART: return "Nonparticipating";
1858 default: return "?????";
1863 * Synchronize our soft copy of the port database with what the f/w thinks
1864 * (with a view toward possibly for a specific target....)
1868 isp_pdb_sync(ispsoftc_t *isp)
1871 fcparam *fcp = isp->isp_param;
1873 int loopid, base, lim;
1876 * Make sure we're okay for doing this right now.
1878 if (fcp->isp_loopstate != LOOP_PDB_RCVD &&
1879 fcp->isp_loopstate != LOOP_FSCAN_DONE &&
1880 fcp->isp_loopstate != LOOP_LSCAN_DONE) {
1884 if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_NL_PORT ||
1885 fcp->isp_topo == TOPO_N_PORT) {
1886 if (fcp->isp_loopstate < LOOP_LSCAN_DONE) {
1887 if (isp_scan_loop(isp) != 0) {
1892 fcp->isp_loopstate = LOOP_SYNCING_PDB;
1895 * If we get this far, we've settled our differences with the f/w
1896 * (for local loop device) and we can say that the loop state is ready.
1899 if (fcp->isp_topo == TOPO_NL_PORT) {
1900 fcp->loop_seen_once = 1;
1901 fcp->isp_loopstate = LOOP_READY;
1906 * Find all Fabric Entities that didn't make it from one scan to the
1907 * next and let the world know they went away. Scan the whole database.
1909 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[MAX_FC_TARG]; lp++) {
1910 if (lp->was_fabric_dev && lp->fabric_dev == 0) {
1911 loopid = lp - fcp->portdb;
1912 lp->valid = 0; /* should already be set */
1913 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1914 MEMZERO((void *) lp, sizeof (*lp));
1917 lp->was_fabric_dev = lp->fabric_dev;
1920 if (fcp->isp_topo == TOPO_FL_PORT)
1925 if (fcp->isp_topo == TOPO_N_PORT)
1931 * Now log in any fabric devices that the outer layer has
1932 * left for us to see. This seems the most sane policy
1935 for (lp = &fcp->portdb[base]; lp < &fcp->portdb[lim]; lp++) {
1939 loopid = lp - fcp->portdb;
1940 if (loopid >= FL_PORT_ID && loopid <= FC_SNS_ID) {
1947 if (lp->port_wwn == 0) {
1952 * Don't try to log into yourself.
1954 if ((portid = lp->portid) == fcp->isp_portid) {
1960 * If we'd been logged in- see if we still are and we haven't
1961 * changed. If so, no need to log ourselves out, etc..
1963 * Unfortunately, our charming Qlogic f/w has decided to
1964 * return a valid port database entry for a fabric device
1965 * that has, in fact, gone away. And it hangs trying to
1968 if (lp->loggedin && lp->force_logout == 0 &&
1969 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
1971 uint64_t nwwnn, nwwpn;
1973 (((uint64_t)pdb.pdb_nodename[0]) << 56) |
1974 (((uint64_t)pdb.pdb_nodename[1]) << 48) |
1975 (((uint64_t)pdb.pdb_nodename[2]) << 40) |
1976 (((uint64_t)pdb.pdb_nodename[3]) << 32) |
1977 (((uint64_t)pdb.pdb_nodename[4]) << 24) |
1978 (((uint64_t)pdb.pdb_nodename[5]) << 16) |
1979 (((uint64_t)pdb.pdb_nodename[6]) << 8) |
1980 (((uint64_t)pdb.pdb_nodename[7]));
1982 (((uint64_t)pdb.pdb_portname[0]) << 56) |
1983 (((uint64_t)pdb.pdb_portname[1]) << 48) |
1984 (((uint64_t)pdb.pdb_portname[2]) << 40) |
1985 (((uint64_t)pdb.pdb_portname[3]) << 32) |
1986 (((uint64_t)pdb.pdb_portname[4]) << 24) |
1987 (((uint64_t)pdb.pdb_portname[5]) << 16) |
1988 (((uint64_t)pdb.pdb_portname[6]) << 8) |
1989 (((uint64_t)pdb.pdb_portname[7]));
1990 nrole = (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >>
1992 if (pdb.pdb_loopid == lp->loopid && lp->portid ==
1993 (uint32_t) BITS2WORD(pdb.pdb_portid_bits) &&
1994 nwwnn == lp->node_wwn && nwwpn == lp->port_wwn &&
1995 lp->roles == nrole && lp->force_logout == 0) {
1996 lp->loggedin = lp->valid = 1;
1997 isp_prt(isp, ISP_LOGCONFIG, lretained,
1998 (int) (lp - fcp->portdb),
1999 (int) lp->loopid, lp->portid);
2004 if (fcp->isp_fwstate != FW_READY ||
2005 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2010 * Force a logout if we were logged in.
2013 if (lp->force_logout ||
2014 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
2015 MEMZERO(&mbs, sizeof (mbs));
2016 mbs.param[0] = MBOX_FABRIC_LOGOUT;
2017 if (IS_2KLOGIN(isp)) {
2018 mbs.param[1] = lp->loopid;
2019 mbs.obits |= (1 << 10);
2021 mbs.param[1] = lp->loopid << 8;
2025 isp_mboxcmd(isp, &mbs, MBLOGNONE);
2026 isp_prt(isp, ISP_LOGINFO, plogout,
2027 (int) (lp - fcp->portdb), lp->loopid,
2030 lp->force_logout = lp->loggedin = 0;
2031 if (fcp->isp_fwstate != FW_READY ||
2032 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2040 loopid = lp - fcp->portdb;
2041 lp->loopid = FL_PORT_ID;
2043 MEMZERO(&mbs, sizeof (mbs));
2044 mbs.param[0] = MBOX_FABRIC_LOGIN;
2045 if (IS_2KLOGIN(isp)) {
2046 mbs.param[1] = loopid;
2047 mbs.obits |= (1 << 10);
2049 mbs.param[1] = loopid << 8;
2051 mbs.param[2] = portid >> 16;
2052 mbs.param[3] = portid & 0xffff;
2053 isp_mboxcmd(isp, &mbs, MBLOGALL & ~(MBOX_LOOP_ID_USED |
2054 MBOX_PORT_ID_USED | MBOX_COMMAND_ERROR));
2055 if (fcp->isp_fwstate != FW_READY ||
2056 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2059 switch (mbs.param[0]) {
2060 case MBOX_LOOP_ID_USED:
2062 * Try the next available loop id.
2066 case MBOX_PORT_ID_USED:
2068 * This port is already logged in.
2069 * Snaffle the loop id it's using if it's
2070 * nonzero, otherwise we're hosed.
2072 if (mbs.param[1] != 0) {
2073 loopid = mbs.param[1];
2074 if (loopid >= MAX_FC_TARG) {
2075 loopid = MAX_FC_TARG;
2078 isp_prt(isp, ISP_LOGINFO, retained,
2079 loopid, (int) (lp - fcp->portdb),
2082 loopid = MAX_FC_TARG;
2086 case MBOX_COMMAND_COMPLETE:
2088 lp->loopid = loopid;
2090 case MBOX_COMMAND_ERROR:
2091 isp_prt(isp, ISP_LOGINFO, plogierr,
2092 portid, mbs.param[1]);
2094 case MBOX_ALL_IDS_USED: /* We're outta IDs */
2096 loopid = MAX_FC_TARG;
2099 } while (lp->loopid == FL_PORT_ID && loopid < MAX_FC_TARG);
2102 * If we get here and we haven't set a Loop ID,
2103 * we failed to log into this device.
2106 if (lp->loopid == FL_PORT_ID) {
2112 * Make sure we can get the approriate port information.
2114 if (isp_getpdb(isp, lp->loopid, &pdb) != 0) {
2115 isp_prt(isp, ISP_LOGWARN, nopdb, lp->portid);
2119 if (fcp->isp_fwstate != FW_READY ||
2120 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2124 if (pdb.pdb_loopid != lp->loopid) {
2125 isp_prt(isp, ISP_LOGWARN, pdbmfail1,
2126 lp->portid, pdb.pdb_loopid);
2130 if (lp->portid != (uint32_t) BITS2WORD(pdb.pdb_portid_bits)) {
2131 isp_prt(isp, ISP_LOGWARN, pdbmfail2,
2132 lp->portid, BITS2WORD(pdb.pdb_portid_bits));
2137 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2139 (((uint64_t)pdb.pdb_nodename[0]) << 56) |
2140 (((uint64_t)pdb.pdb_nodename[1]) << 48) |
2141 (((uint64_t)pdb.pdb_nodename[2]) << 40) |
2142 (((uint64_t)pdb.pdb_nodename[3]) << 32) |
2143 (((uint64_t)pdb.pdb_nodename[4]) << 24) |
2144 (((uint64_t)pdb.pdb_nodename[5]) << 16) |
2145 (((uint64_t)pdb.pdb_nodename[6]) << 8) |
2146 (((uint64_t)pdb.pdb_nodename[7]));
2148 (((uint64_t)pdb.pdb_portname[0]) << 56) |
2149 (((uint64_t)pdb.pdb_portname[1]) << 48) |
2150 (((uint64_t)pdb.pdb_portname[2]) << 40) |
2151 (((uint64_t)pdb.pdb_portname[3]) << 32) |
2152 (((uint64_t)pdb.pdb_portname[4]) << 24) |
2153 (((uint64_t)pdb.pdb_portname[5]) << 16) |
2154 (((uint64_t)pdb.pdb_portname[6]) << 8) |
2155 (((uint64_t)pdb.pdb_portname[7]));
2157 * Check to make sure this all makes sense.
2159 if (lp->node_wwn && lp->port_wwn) {
2161 loopid = lp - fcp->portdb;
2162 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2167 isp_prt(isp, ISP_LOGINFO,
2168 ldumped, loopid, lp->loopid, lp->portid);
2169 MEMZERO(&mbs, sizeof (mbs));
2170 mbs.param[0] = MBOX_FABRIC_LOGOUT;
2171 if (IS_2KLOGIN(isp)) {
2172 mbs.param[1] = lp->loopid;
2173 mbs.obits |= (1 << 10);
2175 mbs.param[1] = lp->loopid << 8;
2177 isp_mboxcmd(isp, &mbs, MBLOGNONE);
2178 if (fcp->isp_fwstate != FW_READY ||
2179 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2184 * If we get here, we've for sure seen not only a valid loop
2185 * but know what is or isn't on it, so mark this for usage
2188 fcp->loop_seen_once = 1;
2189 fcp->isp_loopstate = LOOP_READY;
2194 isp_scan_loop(ispsoftc_t *isp)
2197 fcparam *fcp = isp->isp_param;
2199 int loopid, lim, hival;
2201 switch (fcp->isp_topo) {
2212 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2215 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
2218 * make sure the temp port database is clean...
2220 MEMZERO((void *)fcp->tport, sizeof (fcp->tport));
2223 * Run through the local loop ports and get port database info
2226 * There's a somewhat unexplained situation where the f/w passes back
2227 * the wrong database entity- if that happens, just restart (up to
2228 * FL_PORT_ID times).
2230 for (lim = loopid = 0; loopid < hival; loopid++) {
2231 lp = &fcp->tport[loopid];
2234 * Don't even try for ourselves...
2236 if (loopid == fcp->isp_loopid)
2239 lp->node_wwn = isp_get_portname(isp, loopid, 1);
2240 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2242 if (lp->node_wwn == 0)
2244 lp->port_wwn = isp_get_portname(isp, loopid, 0);
2245 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2247 if (lp->port_wwn == 0) {
2255 if (isp_getpdb(isp, loopid, &pdb) != 0) {
2256 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2260 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2265 * If the returned database element doesn't match what we
2266 * asked for, restart the process entirely (up to a point...).
2268 if (pdb.pdb_loopid != loopid) {
2270 if (lim++ < hival) {
2273 isp_prt(isp, ISP_LOGWARN,
2274 "giving up on synchronizing the port database");
2279 * Save the pertinent info locally.
2282 (((uint64_t)pdb.pdb_nodename[0]) << 56) |
2283 (((uint64_t)pdb.pdb_nodename[1]) << 48) |
2284 (((uint64_t)pdb.pdb_nodename[2]) << 40) |
2285 (((uint64_t)pdb.pdb_nodename[3]) << 32) |
2286 (((uint64_t)pdb.pdb_nodename[4]) << 24) |
2287 (((uint64_t)pdb.pdb_nodename[5]) << 16) |
2288 (((uint64_t)pdb.pdb_nodename[6]) << 8) |
2289 (((uint64_t)pdb.pdb_nodename[7]));
2291 (((uint64_t)pdb.pdb_portname[0]) << 56) |
2292 (((uint64_t)pdb.pdb_portname[1]) << 48) |
2293 (((uint64_t)pdb.pdb_portname[2]) << 40) |
2294 (((uint64_t)pdb.pdb_portname[3]) << 32) |
2295 (((uint64_t)pdb.pdb_portname[4]) << 24) |
2296 (((uint64_t)pdb.pdb_portname[5]) << 16) |
2297 (((uint64_t)pdb.pdb_portname[6]) << 8) |
2298 (((uint64_t)pdb.pdb_portname[7]));
2300 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2301 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
2302 lp->loopid = pdb.pdb_loopid;
2306 * Mark all of the permanent local loop database entries as invalid
2307 * (except our own entry).
2309 for (loopid = 0; loopid < hival; loopid++) {
2310 if (loopid == fcp->isp_iid) {
2311 fcp->portdb[loopid].valid = 1;
2312 fcp->portdb[loopid].loopid = fcp->isp_loopid;
2315 fcp->portdb[loopid].valid = 0;
2319 * Now merge our local copy of the port database into our saved copy.
2320 * Notify the outer layers of new devices arriving.
2322 for (loopid = 0; loopid < hival; loopid++) {
2326 * If we don't have a non-zero Port WWN, we're not here.
2328 if (fcp->tport[loopid].port_wwn == 0) {
2335 if (loopid == fcp->isp_iid) {
2340 * For the purposes of deciding whether this is the
2341 * 'same' device or not, we only search for an identical
2342 * Port WWN. Node WWNs may or may not be the same as
2343 * the Port WWN, and there may be multiple different
2344 * Port WWNs with the same Node WWN. It would be chaos
2345 * to have multiple identical Port WWNs, so we don't
2349 for (i = 0; i < hival; i++) {
2351 if (fcp->portdb[i].port_wwn == 0)
2353 if (fcp->portdb[i].port_wwn !=
2354 fcp->tport[loopid].port_wwn)
2357 * We found this WWN elsewhere- it's changed
2358 * loopids then. We don't change it's actual
2359 * position in our cached port database- we
2360 * just change the actual loop ID we'd use.
2362 if (fcp->portdb[i].loopid != loopid) {
2363 isp_prt(isp, ISP_LOGINFO, portshift, i,
2364 fcp->portdb[i].loopid,
2365 fcp->portdb[i].portid, loopid,
2366 fcp->tport[loopid].portid);
2368 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2369 fcp->portdb[i].loopid = loopid;
2370 fcp->portdb[i].valid = 1;
2371 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2374 * Now make sure this Port WWN doesn't exist elsewhere
2375 * in the port database.
2377 for (j = i+1; j < hival; j++) {
2378 if (fcp->portdb[i].port_wwn !=
2379 fcp->portdb[j].port_wwn) {
2382 isp_prt(isp, ISP_LOGWARN, portdup, j, i);
2384 * Invalidate the 'old' *and* 'new' ones.
2385 * This is really harsh and not quite right,
2386 * but if this happens, we really don't know
2387 * who is what at this point.
2389 fcp->portdb[i].valid = 0;
2390 fcp->portdb[j].valid = 0;
2396 * If we didn't traverse the entire port database,
2397 * then we found (and remapped) an existing entry.
2398 * No need to notify anyone- go for the next one.
2401 isp_prt(isp, ISP_LOGINFO, retained,
2402 fcp->portdb[i].loopid, i, fcp->portdb[i].portid);
2407 * We've not found this Port WWN anywhere. It's a new entry.
2408 * See if we can leave it where it is (with target == loopid).
2410 if (fcp->portdb[loopid].port_wwn != 0) {
2411 for (lim = 0; lim < hival; lim++) {
2412 if (fcp->portdb[lim].port_wwn == 0)
2415 /* "Cannot Happen" */
2417 isp_prt(isp, ISP_LOGWARN, "Remap Overflow");
2426 * NB: The actual loopid we use here is loopid- we may
2427 * in fact be at a completely different index (target).
2429 fcp->portdb[i].loopid = loopid;
2430 fcp->portdb[i].port_wwn = fcp->tport[loopid].port_wwn;
2431 fcp->portdb[i].node_wwn = fcp->tport[loopid].node_wwn;
2432 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2433 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2434 fcp->portdb[i].valid = 1;
2437 * Tell the outside world we've arrived.
2439 (void) isp_async(isp, ISPASYNC_PROMENADE, &i);
2443 * Now find all previously used targets that are now invalid and
2444 * notify the outer layers that they're gone.
2446 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[hival]; lp++) {
2447 if (lp->valid || lp->port_wwn == 0) {
2452 * Tell the outside world we've gone
2453 * away and erase our pdb entry.
2456 loopid = lp - fcp->portdb;
2457 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2458 MEMZERO((void *) lp, sizeof (*lp));
2460 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2466 isp_fabric_mbox_cmd(ispsoftc_t *isp, mbreg_t *mbp)
2468 isp_mboxcmd(isp, mbp, MBLOGNONE);
2469 if (mbp->param[0] != MBOX_COMMAND_COMPLETE) {
2470 if (FCPARAM(isp)->isp_loopstate == LOOP_SCANNING_FABRIC) {
2471 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
2473 if (mbp->param[0] == MBOX_COMMAND_ERROR) {
2476 switch (mbp->param[1]) {
2481 m = "Failed to allocate IOCB buffer";
2484 m = "Failed to allocate XCB buffer";
2487 m = "timeout or transmit failed";
2490 m = "no fabric loop";
2493 m = "remote device not a target";
2496 SNPRINTF(tbuf, sizeof tbuf, "%x",
2501 isp_prt(isp, ISP_LOGERR, "SNS Failed- %s", m);
2506 if (FCPARAM(isp)->isp_fwstate != FW_READY ||
2507 FCPARAM(isp)->isp_loopstate < LOOP_SCANNING_FABRIC) {
2513 #ifdef ISP_USE_GA_NXT
2515 isp_scan_fabric(ispsoftc_t *isp, int ftype)
2517 fcparam *fcp = isp->isp_param;
2518 uint32_t portid, first_portid, last_portid;
2519 int hicap, last_port_same;
2521 if (fcp->isp_onfabric == 0) {
2522 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2526 FC_SCRATCH_ACQUIRE(isp);
2529 * Since Port IDs are 24 bits, we can check against having seen
2530 * anything yet with this value.
2533 last_portid = 0xffffffff; /* not a port */
2534 first_portid = portid = fcp->isp_portid;
2535 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2537 for (hicap = 0; hicap < GA_NXT_MAX; hicap++) {
2540 sns_ga_nxt_rsp_t *rs0, *rs1;
2542 uint8_t sc[SNS_GA_NXT_RESP_SIZE];
2544 rq = (sns_screq_t *)sc;
2545 MEMZERO((void *) rq, SNS_GA_NXT_REQ_SIZE);
2546 rq->snscb_rblen = SNS_GA_NXT_RESP_SIZE >> 1;
2547 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+0x100);
2548 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+0x100);
2549 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+0x100);
2550 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+0x100);
2551 rq->snscb_sblen = 6;
2552 rq->snscb_data[0] = SNS_GA_NXT;
2553 rq->snscb_data[4] = portid & 0xffff;
2554 rq->snscb_data[5] = (portid >> 16) & 0xff;
2555 isp_put_sns_request(isp, rq, (sns_screq_t *) fcp->isp_scratch);
2556 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GA_NXT_REQ_SIZE);
2557 MEMZERO(&mbs, sizeof (mbs));
2558 mbs.param[0] = MBOX_SEND_SNS;
2559 mbs.param[1] = SNS_GA_NXT_REQ_SIZE >> 1;
2560 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2561 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2563 * Leave 4 and 5 alone
2565 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2566 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2567 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2568 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2569 fcp->isp_loopstate = LOOP_PDB_RCVD;
2571 FC_SCRATCH_RELEASE(isp);
2574 MEMORYBARRIER(isp, SYNC_SFORCPU, 0x100, SNS_GA_NXT_RESP_SIZE);
2575 rs1 = (sns_ga_nxt_rsp_t *) sc;
2576 rs0 = (sns_ga_nxt_rsp_t *) ((uint8_t *)fcp->isp_scratch+0x100);
2577 isp_get_ga_nxt_response(isp, rs0, rs1);
2578 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2580 if (rs1->snscb_cthdr.ct_reason == 9 &&
2581 rs1->snscb_cthdr.ct_explanation == 7)
2582 level = ISP_LOGDEBUG0;
2584 level = ISP_LOGWARN;
2585 isp_prt(isp, level, swrej, "GA_NXT",
2586 rs1->snscb_cthdr.ct_reason,
2587 rs1->snscb_cthdr.ct_explanation, portid);
2588 FC_SCRATCH_RELEASE(isp);
2589 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2593 (((uint32_t) rs1->snscb_port_id[0]) << 16) |
2594 (((uint32_t) rs1->snscb_port_id[1]) << 8) |
2595 (((uint32_t) rs1->snscb_port_id[2]));
2598 * XXX: We should check to make sure that this entry
2599 * XXX: supports the type(s) we are interested in.
2602 * Okay, we now have information about a fabric object.
2603 * If it is the type we're interested in, tell the outer layers
2604 * about it. The outer layer needs to know: Port ID, WWNN,
2605 * WWPN, FC4 type, and port type.
2607 * The lportdb structure is adequate for this.
2609 MEMZERO(&lcl, sizeof (lcl));
2610 lcl.port_type = rs1->snscb_port_type;
2611 lcl.fc4_type = ftype;
2612 lcl.portid = portid;
2614 (((uint64_t)rs1->snscb_nodename[0]) << 56) |
2615 (((uint64_t)rs1->snscb_nodename[1]) << 48) |
2616 (((uint64_t)rs1->snscb_nodename[2]) << 40) |
2617 (((uint64_t)rs1->snscb_nodename[3]) << 32) |
2618 (((uint64_t)rs1->snscb_nodename[4]) << 24) |
2619 (((uint64_t)rs1->snscb_nodename[5]) << 16) |
2620 (((uint64_t)rs1->snscb_nodename[6]) << 8) |
2621 (((uint64_t)rs1->snscb_nodename[7]));
2623 (((uint64_t)rs1->snscb_portname[0]) << 56) |
2624 (((uint64_t)rs1->snscb_portname[1]) << 48) |
2625 (((uint64_t)rs1->snscb_portname[2]) << 40) |
2626 (((uint64_t)rs1->snscb_portname[3]) << 32) |
2627 (((uint64_t)rs1->snscb_portname[4]) << 24) |
2628 (((uint64_t)rs1->snscb_portname[5]) << 16) |
2629 (((uint64_t)rs1->snscb_portname[6]) << 8) |
2630 (((uint64_t)rs1->snscb_portname[7]));
2633 * Does this fabric object support the type we want?
2636 if (rs1->snscb_fc4_types[ftype >> 5] & (1 << (ftype & 0x1f))) {
2637 if (first_portid == portid) {
2638 lcl.last_fabric_dev = 1;
2640 lcl.last_fabric_dev = 0;
2642 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2644 isp_prt(isp, ISP_LOGDEBUG0,
2645 "PortID 0x%x doesn't support FC4 type 0x%x",
2648 if (first_portid == portid) {
2649 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2650 FC_SCRATCH_RELEASE(isp);
2653 if (portid == last_portid) {
2654 if (last_port_same++ > 20) {
2655 isp_prt(isp, ISP_LOGWARN,
2656 "tangled fabric database detected");
2660 last_port_same = 0 ;
2661 last_portid = portid;
2664 FC_SCRATCH_RELEASE(isp);
2665 if (hicap >= GA_NXT_MAX) {
2666 isp_prt(isp, ISP_LOGWARN, "fabric too big (> %d)", GA_NXT_MAX);
2668 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2672 #define GIDLEN ((ISP2100_SCRLEN >> 1) + 16)
2673 #define NGENT ((GIDLEN - 16) >> 2)
2675 #define IGPOFF (ISP2100_SCRLEN - GIDLEN)
2679 isp_scan_fabric(ispsoftc_t *isp, int ftype)
2681 fcparam *fcp = FCPARAM(isp);
2684 sns_gid_ft_req_t *rq;
2685 sns_gid_ft_rsp_t *rs0, *rs1;
2687 if (fcp->isp_onfabric == 0) {
2688 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2692 FC_SCRATCH_ACQUIRE(isp);
2693 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2695 rq = (sns_gid_ft_req_t *)fcp->tport;
2696 MEMZERO((void *) rq, SNS_GID_FT_REQ_SIZE);
2697 rq->snscb_rblen = GIDLEN >> 1;
2698 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+IGPOFF);
2699 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+IGPOFF);
2700 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+IGPOFF);
2701 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+IGPOFF);
2702 rq->snscb_sblen = 6;
2703 rq->snscb_cmd = SNS_GID_FT;
2704 rq->snscb_mword_div_2 = NGENT;
2705 rq->snscb_fc4_type = ftype;
2706 isp_put_gid_ft_request(isp, rq, (sns_gid_ft_req_t *) fcp->isp_scratch);
2707 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE);
2708 MEMZERO(&mbs, sizeof (mbs));
2709 mbs.param[0] = MBOX_SEND_SNS;
2710 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
2711 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2712 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2715 * Leave 4 and 5 alone
2717 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2718 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2719 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2720 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2721 fcp->isp_loopstate = LOOP_PDB_RCVD;
2723 FC_SCRATCH_RELEASE(isp);
2726 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2727 FC_SCRATCH_RELEASE(isp);
2730 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN);
2731 rs1 = (sns_gid_ft_rsp_t *) fcp->tport;
2732 rs0 = (sns_gid_ft_rsp_t *) ((uint8_t *)fcp->isp_scratch+IGPOFF);
2733 isp_get_gid_ft_response(isp, rs0, rs1, NGENT);
2734 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2736 if (rs1->snscb_cthdr.ct_reason == 9 &&
2737 rs1->snscb_cthdr.ct_explanation == 7)
2738 level = ISP_LOGDEBUG0;
2740 level = ISP_LOGWARN;
2741 isp_prt(isp, level, swrej, "GID_FT",
2742 rs1->snscb_cthdr.ct_reason,
2743 rs1->snscb_cthdr.ct_explanation, 0);
2744 FC_SCRATCH_RELEASE(isp);
2745 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2750 * Okay, we now have a list of Port IDs for this class of device.
2751 * Go through the list and for each one get the WWPN/WWNN for it
2752 * and tell the outer layers about it. The outer layer needs to
2753 * know: Port ID, WWNN, WWPN, FC4 type, and (possibly) port type.
2755 * The lportdb structure is adequate for this.
2759 sns_gxn_id_req_t grqbuf, *gq = &grqbuf;
2760 sns_gxn_id_rsp_t *gs0, grsbuf, *gs1 = &grsbuf;
2763 sns_gff_id_rsp_t *fs0, ffsbuf, *fs1 = &ffsbuf;
2767 MEMZERO(&lcl, sizeof (lcl));
2768 lcl.fc4_type = ftype;
2770 (((uint32_t) rs1->snscb_ports[i].portid[0]) << 16) |
2771 (((uint32_t) rs1->snscb_ports[i].portid[1]) << 8) |
2772 (((uint32_t) rs1->snscb_ports[i].portid[2]));
2774 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2775 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2776 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2777 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2778 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2779 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2780 gq->snscb_sblen = 6;
2781 gq->snscb_cmd = SNS_GPN_ID;
2782 gq->snscb_portid = lcl.portid;
2783 isp_put_gxn_id_request(isp, gq,
2784 (sns_gxn_id_req_t *) fcp->isp_scratch);
2785 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2786 MEMZERO(&mbs, sizeof (mbs));
2787 mbs.param[0] = MBOX_SEND_SNS;
2788 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2789 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2790 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2792 * Leave 4 and 5 alone
2794 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2795 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2796 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2797 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2798 fcp->isp_loopstate = LOOP_PDB_RCVD;
2800 FC_SCRATCH_RELEASE(isp);
2803 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2804 FC_SCRATCH_RELEASE(isp);
2807 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2808 gs0 = (sns_gxn_id_rsp_t *) ((uint8_t *)fcp->isp_scratch+GXOFF);
2809 isp_get_gxn_id_response(isp, gs0, gs1);
2810 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2811 isp_prt(isp, ISP_LOGWARN, swrej, "GPN_ID",
2812 gs1->snscb_cthdr.ct_reason,
2813 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2814 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2815 FC_SCRATCH_RELEASE(isp);
2821 (((uint64_t)gs1->snscb_wwn[0]) << 56) |
2822 (((uint64_t)gs1->snscb_wwn[1]) << 48) |
2823 (((uint64_t)gs1->snscb_wwn[2]) << 40) |
2824 (((uint64_t)gs1->snscb_wwn[3]) << 32) |
2825 (((uint64_t)gs1->snscb_wwn[4]) << 24) |
2826 (((uint64_t)gs1->snscb_wwn[5]) << 16) |
2827 (((uint64_t)gs1->snscb_wwn[6]) << 8) |
2828 (((uint64_t)gs1->snscb_wwn[7]));
2830 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2831 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2832 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2833 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2834 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2835 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2836 gq->snscb_sblen = 6;
2837 gq->snscb_cmd = SNS_GNN_ID;
2838 gq->snscb_portid = lcl.portid;
2839 isp_put_gxn_id_request(isp, gq,
2840 (sns_gxn_id_req_t *) fcp->isp_scratch);
2841 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2842 MEMZERO(&mbs, sizeof (mbs));
2843 mbs.param[0] = MBOX_SEND_SNS;
2844 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2845 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2846 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2848 * Leave 4 and 5 alone
2850 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2851 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2852 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2853 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2854 fcp->isp_loopstate = LOOP_PDB_RCVD;
2856 FC_SCRATCH_RELEASE(isp);
2859 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2860 FC_SCRATCH_RELEASE(isp);
2863 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2864 gs0 = (sns_gxn_id_rsp_t *) ((uint8_t *)fcp->isp_scratch+GXOFF);
2865 isp_get_gxn_id_response(isp, gs0, gs1);
2866 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2867 isp_prt(isp, ISP_LOGWARN, swrej, "GNN_ID",
2868 gs1->snscb_cthdr.ct_reason,
2869 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2870 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2871 FC_SCRATCH_RELEASE(isp);
2877 (((uint64_t)gs1->snscb_wwn[0]) << 56) |
2878 (((uint64_t)gs1->snscb_wwn[1]) << 48) |
2879 (((uint64_t)gs1->snscb_wwn[2]) << 40) |
2880 (((uint64_t)gs1->snscb_wwn[3]) << 32) |
2881 (((uint64_t)gs1->snscb_wwn[4]) << 24) |
2882 (((uint64_t)gs1->snscb_wwn[5]) << 16) |
2883 (((uint64_t)gs1->snscb_wwn[6]) << 8) |
2884 (((uint64_t)gs1->snscb_wwn[7]));
2887 * The QLogic f/w is bouncing this with a parameter error.
2891 * Try and get FC4 Features (FC-GS-3 only).
2892 * We can use the sns_gxn_id_req_t for this request.
2894 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2895 gq->snscb_rblen = SNS_GFF_ID_RESP_SIZE >> 1;
2896 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2897 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2898 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2899 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2900 gq->snscb_sblen = 6;
2901 gq->snscb_cmd = SNS_GFF_ID;
2902 gq->snscb_portid = lcl.portid;
2903 isp_put_gxn_id_request(isp, gq,
2904 (sns_gxn_id_req_t *) fcp->isp_scratch);
2905 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2906 MEMZERO(&mbs, sizeof (mbs));
2907 mbs.param[0] = MBOX_SEND_SNS;
2908 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2909 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2910 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2912 * Leave 4 and 5 alone
2914 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2915 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2916 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2917 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2918 fcp->isp_loopstate = LOOP_PDB_RCVD;
2920 FC_SCRATCH_RELEASE(isp);
2923 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2924 FC_SCRATCH_RELEASE(isp);
2927 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GFF_ID_RESP_SIZE);
2928 fs0 = (sns_gff_id_rsp_t *) ((uint8_t *)fcp->isp_scratch+GXOFF);
2929 isp_get_gff_id_response(isp, fs0, fs1);
2930 if (fs1->snscb_cthdr.ct_response != FS_ACC) {
2931 isp_prt(isp, /* ISP_LOGDEBUG0 */ ISP_LOGWARN,
2933 fs1->snscb_cthdr.ct_reason,
2934 fs1->snscb_cthdr.ct_explanation, lcl.portid);
2935 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2936 FC_SCRATCH_RELEASE(isp);
2940 int index = (ftype >> 3);
2941 int bshft = (ftype & 0x7) * 4;
2943 (fs1->snscb_fc4_features[index] >> bshft) & 0xf;
2944 if (fc4_fval & 0x1) {
2946 (SVC3_INI_ROLE >> SVC3_ROLE_SHIFT);
2948 if (fc4_fval & 0x2) {
2950 (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT);
2956 * If we really want to know what kind of port type this is,
2957 * we have to run another CT command. Otherwise, we'll leave
2962 if (rs1->snscb_ports[i].control & 0x80) {
2963 lcl.last_fabric_dev = 1;
2965 lcl.last_fabric_dev = 0;
2967 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2969 } while ((rs1->snscb_ports[i].control & 0x80) == 0 && i < NGENT-1);
2972 * If we're not at the last entry, our list isn't big enough.
2974 if ((rs1->snscb_ports[i].control & 0x80) == 0) {
2975 isp_prt(isp, ISP_LOGWARN, "fabric too big for scratch area");
2978 FC_SCRATCH_RELEASE(isp);
2979 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2985 isp_register_fc4_type(ispsoftc_t *isp)
2987 fcparam *fcp = isp->isp_param;
2988 uint8_t local[SNS_RFT_ID_REQ_SIZE];
2989 sns_screq_t *reqp = (sns_screq_t *) local;
2992 MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
2993 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
2994 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
2995 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
2996 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
2997 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
2998 reqp->snscb_sblen = 22;
2999 reqp->snscb_data[0] = SNS_RFT_ID;
3000 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
3001 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
3002 reqp->snscb_data[6] = (1 << FC4_SCSI);
3004 reqp->snscb_data[6] |= (1 << FC4_IP); /* ISO/IEC 8802-2 LLC/SNAP */
3006 FC_SCRATCH_ACQUIRE(isp);
3007 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
3008 MEMZERO(&mbs, sizeof (mbs));
3009 mbs.param[0] = MBOX_SEND_SNS;
3010 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
3011 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
3012 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
3014 * Leave 4 and 5 alone
3016 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
3017 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
3018 isp_mboxcmd(isp, &mbs, MBLOGALL);
3019 FC_SCRATCH_RELEASE(isp);
3020 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3021 isp_prt(isp, ISP_LOGDEBUG0, "Register FC4 types succeeded");
3026 * Start a command. Locking is assumed done in the caller.
3033 uint16_t nxti, optr, handle;
3034 uint8_t local[QENTRY_LEN];
3035 ispreq_t *reqp, *qep;
3042 * Check to make sure we're supporting initiator role.
3044 if ((isp->isp_role & ISP_ROLE_INITIATOR) == 0) {
3045 XS_SETERR(xs, HBA_SELTIMEOUT);
3046 return (CMD_COMPLETE);
3050 * Now make sure we're running.
3053 if (isp->isp_state != ISP_RUNSTATE) {
3054 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
3055 XS_SETERR(xs, HBA_BOTCH);
3056 return (CMD_COMPLETE);
3060 * Check command CDB length, etc.. We really are limited to 16 bytes
3061 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
3062 * but probably only if we're running fairly new firmware (we'll
3063 * let the old f/w choke on an extended command queue entry).
3066 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
3067 isp_prt(isp, ISP_LOGERR,
3068 "unsupported cdb length (%d, CDB[0]=0x%x)",
3069 XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
3070 XS_SETERR(xs, HBA_BOTCH);
3071 return (CMD_COMPLETE);
3075 * Check to see whether we have good firmware state still or
3076 * need to refresh our port database for this target.
3078 target = XS_TGT(xs);
3080 fcparam *fcp = isp->isp_param;
3082 #ifdef HANDLE_LOOPSTATE_IN_OUTER_LAYERS
3083 if (fcp->isp_fwstate != FW_READY ||
3084 fcp->isp_loopstate != LOOP_READY) {
3085 return (CMD_RQLATER);
3089 * If we're not on a Fabric, we can't have a target
3090 * above FL_PORT_ID-1.
3092 * If we're on a fabric and *not* connected as an F-port,
3093 * we can't have a target less than FC_SNS_ID+1. This
3094 * keeps us from having to sort out the difference between
3095 * local public loop devices and those which we might get
3096 * from a switch's database.
3098 if (fcp->isp_onfabric == 0) {
3099 if (target >= FL_PORT_ID) {
3100 XS_SETERR(xs, HBA_SELTIMEOUT);
3101 return (CMD_COMPLETE);
3104 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3105 XS_SETERR(xs, HBA_SELTIMEOUT);
3106 return (CMD_COMPLETE);
3109 * We used to exclude having local loop ports
3110 * at the same time that we have fabric ports.
3111 * That is, we used to exclude having ports
3112 * at < FL_PORT_ID if we're FL-port.
3114 * That's wrong. The only thing that could be
3115 * dicey is if the switch you're connected to
3116 * has these local loop ports appear on the
3117 * fabric and we somehow attach them twice.
3122 * Check for f/w being in ready state. If the f/w
3123 * isn't in ready state, then we don't know our
3124 * loop ID and the f/w hasn't completed logging
3125 * into all targets on the loop. If this is the
3126 * case, then bounce the command. We pretend this is
3127 * a SELECTION TIMEOUT error if we've never gone to
3128 * FW_READY state at all- in this case we may not
3129 * be hooked to a loop at all and we shouldn't hang
3130 * the machine for this. Otherwise, defer this command
3133 if (fcp->isp_fwstate != FW_READY) {
3135 * Give ourselves at most a 250ms delay.
3137 if (isp_fclink_test(isp, 250000)) {
3138 XS_SETERR(xs, HBA_SELTIMEOUT);
3139 if (fcp->loop_seen_once) {
3140 return (CMD_RQLATER);
3142 return (CMD_COMPLETE);
3148 * If we're not on a Fabric, we can't have a target
3149 * above FL_PORT_ID-1.
3151 * If we're on a fabric and *not* connected as an F-port,
3152 * we can't have a target less than FC_SNS_ID+1. This
3153 * keeps us from having to sort out the difference between
3154 * local public loop devices and those which we might get
3155 * from a switch's database.
3157 if (fcp->isp_onfabric == 0) {
3158 if (target >= FL_PORT_ID) {
3159 XS_SETERR(xs, HBA_SELTIMEOUT);
3160 return (CMD_COMPLETE);
3163 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3164 XS_SETERR(xs, HBA_SELTIMEOUT);
3165 return (CMD_COMPLETE);
3167 if (fcp->isp_topo != TOPO_F_PORT &&
3168 target < FL_PORT_ID) {
3169 XS_SETERR(xs, HBA_SELTIMEOUT);
3170 return (CMD_COMPLETE);
3175 * If our loop state is such that we haven't yet received
3176 * a "Port Database Changed" notification (after a LIP or
3177 * a Loop Reset or firmware initialization), then defer
3178 * sending commands for a little while, but only if we've
3179 * seen a valid loop at one point (otherwise we can get
3180 * stuck at initialization time).
3182 if (fcp->isp_loopstate < LOOP_PDB_RCVD) {
3183 XS_SETERR(xs, HBA_SELTIMEOUT);
3184 if (fcp->loop_seen_once) {
3185 return (CMD_RQLATER);
3187 return (CMD_COMPLETE);
3192 * If we're in the middle of loop or fabric scanning
3193 * or merging the port databases, retry this command later.
3195 if (fcp->isp_loopstate == LOOP_SCANNING_FABRIC ||
3196 fcp->isp_loopstate == LOOP_SCANNING_LOOP ||
3197 fcp->isp_loopstate == LOOP_SYNCING_PDB) {
3198 return (CMD_RQLATER);
3202 * If our loop state is now such that we've just now
3203 * received a Port Database Change notification, then
3204 * we have to go off and (re)scan the fabric. We back
3205 * out and try again later if this doesn't work.
3207 if (fcp->isp_loopstate == LOOP_PDB_RCVD && fcp->isp_onfabric) {
3208 if (isp_scan_fabric(isp, FC4_SCSI)) {
3209 return (CMD_RQLATER);
3211 if (fcp->isp_fwstate != FW_READY ||
3212 fcp->isp_loopstate < LOOP_FSCAN_DONE) {
3213 return (CMD_RQLATER);
3218 * If our loop state is now such that we've just now
3219 * received a Port Database Change notification, then
3220 * we have to go off and (re)synchronize our port
3223 if (fcp->isp_loopstate < LOOP_READY) {
3224 if (isp_pdb_sync(isp)) {
3225 return (CMD_RQLATER);
3227 if (fcp->isp_fwstate != FW_READY ||
3228 fcp->isp_loopstate != LOOP_READY) {
3229 return (CMD_RQLATER);
3234 * XXX: Here's were we would cancel any loop_dead flag
3235 * XXX: also cancel in dead_loop timeout that's running
3240 * Now check whether we should even think about pursuing this.
3242 lp = &fcp->portdb[target];
3243 if (lp->valid == 0) {
3244 XS_SETERR(xs, HBA_SELTIMEOUT);
3245 return (CMD_COMPLETE);
3247 if ((lp->roles & (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT)) == 0) {
3248 isp_prt(isp, ISP_LOGDEBUG2,
3249 "Target %d does not have target service", target);
3250 XS_SETERR(xs, HBA_SELTIMEOUT);
3251 return (CMD_COMPLETE);
3254 * Now turn target into what the actual Loop ID is.
3256 target = lp->loopid;
3260 * Next check to see if any HBA or Device
3261 * parameters need to be updated.
3263 if (isp->isp_update != 0) {
3267 if (isp_getrqentry(isp, &nxti, &optr, (void *)&qep)) {
3268 isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow");
3269 XS_SETERR(xs, HBA_BOTCH);
3270 return (CMD_EAGAIN);
3274 * Now see if we need to synchronize the ISP with respect to anything.
3275 * We do dual duty here (cough) for synchronizing for busses other
3276 * than which we got here to send a command to.
3278 reqp = (ispreq_t *) local;
3279 if (isp->isp_sendmarker) {
3280 uint8_t n = (IS_DUALBUS(isp)? 2: 1);
3282 * Check ports to send markers for...
3284 for (i = 0; i < n; i++) {
3285 if ((isp->isp_sendmarker & (1 << i)) == 0) {
3288 MEMZERO((void *) reqp, QENTRY_LEN);
3289 reqp->req_header.rqs_entry_count = 1;
3290 reqp->req_header.rqs_entry_type = RQSTYPE_MARKER;
3291 reqp->req_modifier = SYNC_ALL;
3292 reqp->req_target = i << 7; /* insert bus number */
3293 isp_put_request(isp, reqp, qep);
3294 ISP_ADD_REQUEST(isp, nxti);
3295 isp->isp_sendmarker &= ~(1 << i);
3296 if (isp_getrqentry(isp, &nxti, &optr, (void *) &qep)) {
3297 isp_prt(isp, ISP_LOGDEBUG0,
3298 "Request Queue Overflow+");
3299 XS_SETERR(xs, HBA_BOTCH);
3300 return (CMD_EAGAIN);
3305 MEMZERO((void *)reqp, QENTRY_LEN);
3306 reqp->req_header.rqs_entry_count = 1;
3308 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
3310 if (XS_CDBLEN(xs) > 12)
3311 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
3313 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
3315 /* reqp->req_header.rqs_flags = 0; */
3316 /* reqp->req_header.rqs_seqno = 0; */
3319 * See comment in isp_intr
3321 /* XS_RESID(xs) = 0; */
3324 * Fibre Channel always requires some kind of tag.
3325 * The Qlogic drivers seem be happy not to use a tag,
3326 * but this breaks for some devices (IBM drives).
3329 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
3332 * If we don't know what tag to use, use HEAD OF QUEUE
3333 * for Request Sense or Simple.
3335 if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
3336 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_HTAG;
3338 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
3341 sdparam *sdp = (sdparam *)isp->isp_param;
3342 sdp += XS_CHANNEL(xs);
3343 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) &&
3345 reqp->req_flags = XS_TAG_TYPE(xs);
3349 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
3350 reqp->req_lun_trn = XS_LUN(xs);
3351 reqp->req_cdblen = XS_CDBLEN(xs);
3352 } else if (IS_2KLOGIN(isp)) {
3353 ((ispreqt2e_t *)reqp)->req_target = target;
3354 ((ispreqt2e_t *)reqp)->req_scclun = XS_LUN(xs);
3355 } else if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
3356 ((ispreqt2_t *)reqp)->req_target = target;
3357 ((ispreqt2_t *)reqp)->req_scclun = XS_LUN(xs);
3359 ((ispreqt2_t *)reqp)->req_target = target;
3360 ((ispreqt2_t *)reqp)->req_lun_trn = XS_LUN(xs);
3362 MEMCPY(reqp->req_cdb, XS_CDBP(xs), XS_CDBLEN(xs));
3364 reqp->req_time = XS_TIME(xs) / 1000;
3365 if (reqp->req_time == 0 && XS_TIME(xs)) {
3369 if (isp_save_xs(isp, xs, &handle)) {
3370 isp_prt(isp, ISP_LOGDEBUG0, "out of xflist pointers");
3371 XS_SETERR(xs, HBA_BOTCH);
3372 return (CMD_EAGAIN);
3374 reqp->req_handle = handle;
3377 * Set up DMA and/or do any bus swizzling of the request entry
3378 * so that the Qlogic F/W understands what is being asked of it.
3380 i = ISP_DMASETUP(isp, xs, reqp, &nxti, optr);
3381 if (i != CMD_QUEUED) {
3382 isp_destroy_handle(isp, handle);
3384 * dmasetup sets actual error in packet, and
3385 * return what we were given to return.
3389 XS_SETERR(xs, HBA_NOERROR);
3390 isp_prt(isp, ISP_LOGDEBUG2,
3391 "START cmd for %d.%d.%d cmd 0x%x datalen %ld",
3392 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), XS_CDBP(xs)[0],
3393 (long) XS_XFRLEN(xs));
3394 ISP_ADD_REQUEST(isp, nxti);
3396 return (CMD_QUEUED);
3401 * Locks (ints blocked) assumed held.
3405 isp_control(ispsoftc_t *isp, ispctl_t ctl, void *arg)
3412 MEMZERO(&mbs, sizeof (mbs));
3416 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
3419 case ISPCTL_RESET_BUS:
3421 * Issue a bus reset.
3423 mbs.param[0] = MBOX_BUS_RESET;
3427 ((sdparam *) isp->isp_param)->isp_bus_reset_delay;
3428 if (mbs.param[1] < 2)
3430 bus = *((int *) arg);
3431 if (IS_DUALBUS(isp))
3437 isp->isp_sendmarker |= (1 << bus);
3438 isp_mboxcmd(isp, &mbs, MBLOGALL);
3439 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3442 isp_prt(isp, ISP_LOGINFO,
3443 "driver initiated bus reset of bus %d", bus);
3446 case ISPCTL_RESET_DEV:
3447 tgt = (*((int *) arg)) & 0xffff;
3448 bus = (*((int *) arg)) >> 16;
3449 mbs.param[0] = MBOX_ABORT_TARGET;
3451 mbs.param[1] = (tgt << 8) | (bus << 15);
3453 if (IS_2KLOGIN(isp)) {
3455 mbs.obits |= (1 << 10);
3457 mbs.param[1] = (tgt << 8);
3460 mbs.param[2] = 3; /* 'delay', in seconds */
3461 isp_mboxcmd(isp, &mbs, MBLOGALL);
3462 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3465 isp_prt(isp, ISP_LOGINFO,
3466 "Target %d on Bus %d Reset Succeeded", tgt, bus);
3467 isp->isp_sendmarker |= (1 << bus);
3470 case ISPCTL_ABORT_CMD:
3473 handle = isp_find_handle(isp, xs);
3475 isp_prt(isp, ISP_LOGWARN,
3476 "cannot find handle for command to abort");
3479 bus = XS_CHANNEL(xs);
3480 mbs.param[0] = MBOX_ABORT;
3482 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
3483 if (IS_2KLOGIN(isp)) {
3486 mbs.param[1] = tgt << 8;
3490 mbs.param[6] = XS_LUN(xs);
3492 mbs.param[1] = tgt << 8 | XS_LUN(xs);
3496 (bus << 15) | (XS_TGT(xs) << 8) | XS_LUN(xs);
3499 mbs.param[2] = handle;
3500 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_ERROR);
3501 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3505 * XXX: Look for command in the REQUEST QUEUE. That is,
3506 * XXX: It hasen't been picked up by firmware yet.
3510 case ISPCTL_UPDATE_PARAMS:
3515 case ISPCTL_FCLINK_TEST:
3518 int usdelay = *((int *) arg);
3522 return (isp_fclink_test(isp, usdelay));
3526 case ISPCTL_SCAN_FABRIC:
3529 int ftype = (arg)? *((int *) arg) : FC4_SCSI;
3530 return (isp_scan_fabric(isp, ftype));
3534 case ISPCTL_SCAN_LOOP:
3537 return (isp_scan_loop(isp));
3541 case ISPCTL_PDB_SYNC:
3544 return (isp_pdb_sync(isp));
3548 case ISPCTL_SEND_LIP:
3551 mbs.param[0] = MBOX_INIT_LIP;
3552 isp_mboxcmd(isp, &mbs, MBLOGALL);
3553 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3559 case ISPCTL_GET_POSMAP:
3561 if (IS_FC(isp) && arg) {
3562 return (isp_getmap(isp, arg));
3567 case ISPCTL_GET_PDB:
3568 if (IS_FC(isp) && arg) {
3569 int id = *((int *)arg);
3570 isp_pdb_t *pdb = arg;
3571 return (isp_getpdb(isp, id, pdb));
3575 case ISPCTL_RUN_MBOXCMD:
3577 isp_mboxcmd(isp, arg, MBLOGALL);
3580 #ifdef ISP_TARGET_MODE
3581 case ISPCTL_TOGGLE_TMODE:
3585 * We don't check/set against role here- that's the
3586 * responsibility for the outer layer to coordinate.
3589 int param = *(int *)arg;
3590 mbs.param[0] = MBOX_ENABLE_TARGET_MODE;
3591 mbs.param[1] = param & 0xffff;
3592 mbs.param[2] = param >> 16;
3593 isp_mboxcmd(isp, &mbs, MBLOGALL);
3594 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3606 * Interrupt Service Routine(s).
3608 * External (OS) framework has done the appropriate locking,
3609 * and the locking will be held throughout this function.
3613 * Limit our stack depth by sticking with the max likely number
3614 * of completions on a request queue at any one time.
3616 #ifndef MAX_REQUESTQ_COMPLETIONS
3617 #define MAX_REQUESTQ_COMPLETIONS 64
3621 isp_intr(ispsoftc_t *isp, uint16_t isr, uint16_t sema, uint16_t mbox)
3623 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
3624 uint16_t iptr, optr, junk;
3625 int i, nlooked = 0, ndone = 0;
3629 * Is this a mailbox related interrupt?
3630 * The mailbox semaphore will be nonzero if so.
3633 if (mbox & 0x4000) {
3634 isp->isp_intmboxc++;
3635 if (isp->isp_mboxbsy) {
3636 int i = 0, obits = isp->isp_obits;
3637 isp->isp_mboxtmp[i++] = mbox;
3638 for (i = 1; i < MAX_MAILBOX(isp); i++) {
3639 if ((obits & (1 << i)) == 0) {
3642 isp->isp_mboxtmp[i] =
3643 ISP_READ(isp, MBOX_OFF(i));
3645 if (isp->isp_mbxwrk0) {
3646 if (isp_mbox_continue(isp) == 0) {
3650 MBOX_NOTIFY_COMPLETE(isp);
3652 isp_prt(isp, ISP_LOGWARN,
3653 "Mbox Command Async (0x%x) with no waiters",
3656 } else if (isp_parse_async(isp, mbox) < 0) {
3659 if ((IS_FC(isp) && mbox != ASYNC_RIO_RESP) ||
3660 isp->isp_state != ISP_RUNSTATE) {
3661 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3662 ISP_WRITE(isp, BIU_SEMA, 0);
3668 * We can't be getting this now.
3670 if (isp->isp_state != ISP_RUNSTATE) {
3671 isp_prt(isp, ISP_LOGWARN,
3672 "interrupt (ISR=%x SEMA=%x) when not ready", isr, sema);
3674 * Thank you very much! *Burrrp*!
3676 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp,
3677 READ_RESPONSE_QUEUE_IN_POINTER(isp));
3679 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3680 ISP_WRITE(isp, BIU_SEMA, 0);
3685 * Get the current Response Queue Out Pointer.
3687 * If we're a 2300, we can ask what hardware what it thinks.
3690 optr = ISP_READ(isp, isp->isp_respoutrp);
3692 * Debug: to be taken out eventually
3694 if (isp->isp_residx != optr) {
3695 isp_prt(isp, ISP_LOGWARN, "optr %x soft optr %x",
3696 optr, isp->isp_residx);
3699 optr = isp->isp_residx;
3703 * You *must* read the Response Queue In Pointer
3704 * prior to clearing the RISC interrupt.
3706 * Debounce the 2300 if revision less than 2.
3708 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
3711 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3712 junk = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3713 } while (junk != iptr && ++i < 1000);
3716 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3717 isp_prt(isp, ISP_LOGWARN,
3718 "Response Queue Out Pointer Unstable (%x, %x)",
3723 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3725 isp->isp_resodx = iptr;
3728 if (optr == iptr && sema == 0) {
3730 * There are a lot of these- reasons unknown- mostly on
3731 * faster Alpha machines.
3733 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
3734 * make sure the old interrupt went away (to avoid 'ringing'
3735 * effects), but that didn't stop this from occurring.
3739 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3740 junk = ISP_READ(isp, BIU_R2HSTSLO);
3742 junk = ISP_READ(isp, BIU_ISR);
3748 sema = ISP_READ(isp, BIU_SEMA);
3749 mbox = ISP_READ(isp, OUTMAILBOX0);
3750 if ((sema & 0x3) && (mbox & 0x8000)) {
3754 isp->isp_intbogus++;
3755 isp_prt(isp, ISP_LOGDEBUG1,
3756 "bogus intr- isr %x (%x) iptr %x optr %x",
3757 isr, junk, iptr, optr);
3760 isp->isp_resodx = iptr;
3761 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3762 ISP_WRITE(isp, BIU_SEMA, 0);
3764 if (isp->isp_rspbsy) {
3767 isp->isp_rspbsy = 1;
3769 while (optr != iptr) {
3770 ispstatusreq_t local, *sp = &local;
3776 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
3778 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
3782 * Synchronize our view of this response queue entry.
3784 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN);
3786 type = isp_get_response_type(isp, hp);
3788 if (type == RQSTYPE_RESPONSE) {
3789 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3790 } else if (type == RQSTYPE_RIO2) {
3792 isp_get_rio2(isp, (isp_rio2_t *) hp, &rio);
3793 for (i = 0; i < rio.req_header.rqs_seqno; i++) {
3794 isp_fastpost_complete(isp, rio.req_handles[i]);
3796 if (isp->isp_fpcchiwater < rio.req_header.rqs_seqno)
3797 isp->isp_fpcchiwater = rio.req_header.rqs_seqno;
3798 MEMZERO(hp, QENTRY_LEN); /* PERF */
3802 * Somebody reachable via isp_handle_other_response
3803 * may have updated the response queue pointers for
3804 * us, so we reload our goal index.
3806 int i = isp_handle_other_response(isp, type, hp, &optr);
3810 iptr = isp->isp_resodx;
3811 MEMZERO(hp, QENTRY_LEN); /* PERF */
3816 * After this point, we'll just look at the header as
3817 * we don't know how to deal with the rest of the
3820 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3823 * It really has to be a bounced request just copied
3824 * from the request queue to the response queue. If
3825 * not, something bad has happened.
3827 if (sp->req_header.rqs_entry_type != RQSTYPE_REQUEST) {
3828 isp_prt(isp, ISP_LOGERR, notresp,
3829 sp->req_header.rqs_entry_type, oop, optr,
3831 if (isp->isp_dblev & ISP_LOGDEBUG0) {
3832 isp_print_bytes(isp, "Queue Entry",
3835 MEMZERO(hp, QENTRY_LEN); /* PERF */
3841 if (sp->req_header.rqs_flags & 0xf) {
3842 #define _RQS_OFLAGS \
3843 ~(RQSFLAG_CONTINUATION|RQSFLAG_FULL|RQSFLAG_BADHEADER|RQSFLAG_BADPACKET)
3844 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
3845 isp_prt(isp, ISP_LOGWARN,
3846 "continuation segment");
3847 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3850 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3851 isp_prt(isp, ISP_LOGDEBUG1,
3852 "internal queues full");
3854 * We'll synthesize a QUEUE FULL message below.
3857 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
3858 isp_prt(isp, ISP_LOGERR, "bad header flag");
3861 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
3862 isp_prt(isp, ISP_LOGERR, "bad request packet");
3865 if (sp->req_header.rqs_flags & _RQS_OFLAGS) {
3866 isp_prt(isp, ISP_LOGERR,
3867 "unknown flags (0x%x) in response",
3868 sp->req_header.rqs_flags);
3873 if (sp->req_handle > isp->isp_maxcmds || sp->req_handle < 1) {
3874 MEMZERO(hp, QENTRY_LEN); /* PERF */
3875 isp_prt(isp, ISP_LOGERR,
3876 "bad request handle %d (type 0x%x, flags 0x%x)",
3877 sp->req_handle, sp->req_header.rqs_entry_type,
3878 sp->req_header.rqs_flags);
3879 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3882 xs = isp_find_xs(isp, sp->req_handle);
3884 uint8_t ts = sp->req_completion_status & 0xff;
3885 MEMZERO(hp, QENTRY_LEN); /* PERF */
3887 * Only whine if this isn't the expected fallout of
3888 * aborting the command.
3890 if (sp->req_header.rqs_entry_type != RQSTYPE_RESPONSE) {
3891 isp_prt(isp, ISP_LOGERR,
3892 "cannot find handle 0x%x (type 0x%x)",
3894 sp->req_header.rqs_entry_type);
3895 } else if (ts != RQCS_ABORTED) {
3896 isp_prt(isp, ISP_LOGERR,
3897 "cannot find handle 0x%x (status 0x%x)",
3898 sp->req_handle, ts);
3900 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3903 isp_destroy_handle(isp, sp->req_handle);
3904 if (sp->req_status_flags & RQSTF_BUS_RESET) {
3905 XS_SETERR(xs, HBA_BUSRESET);
3906 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
3909 XS_SETERR(xs, HBA_BOTCH);
3912 if (IS_FC(isp) && (sp->req_scsi_status & RQCS_SV)) {
3914 * Fibre Channel F/W doesn't say we got status
3915 * if there's Sense Data instead. I guess they
3916 * think it goes w/o saying.
3918 sp->req_state_flags |= RQSF_GOT_STATUS;
3920 if (sp->req_state_flags & RQSF_GOT_STATUS) {
3921 *XS_STSP(xs) = sp->req_scsi_status & 0xff;
3924 switch (sp->req_header.rqs_entry_type) {
3925 case RQSTYPE_RESPONSE:
3926 XS_SET_STATE_STAT(isp, xs, sp);
3927 isp_parse_status(isp, sp, xs);
3928 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) &&
3929 (*XS_STSP(xs) == SCSI_BUSY)) {
3930 XS_SETERR(xs, HBA_TGTBSY);
3933 XS_RESID(xs) = sp->req_resid;
3934 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3935 (*XS_STSP(xs) == SCSI_CHECK) &&
3936 (sp->req_state_flags & RQSF_GOT_SENSE)) {
3937 XS_SAVE_SENSE(xs, sp);
3940 * A new synchronous rate was negotiated for
3941 * this target. Mark state such that we'll go
3942 * look up that which has changed later.
3944 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
3946 sdparam *sdp = isp->isp_param;
3947 sdp += XS_CHANNEL(xs);
3948 sdp->isp_devparam[t].dev_refresh = 1;
3950 (1 << XS_CHANNEL(xs));
3953 if (sp->req_status_flags & RQSF_XFER_COMPLETE) {
3955 } else if (sp->req_scsi_status & RQCS_RESID) {
3956 XS_RESID(xs) = sp->req_resid;
3960 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3961 (*XS_STSP(xs) == SCSI_CHECK) &&
3962 (sp->req_scsi_status & RQCS_SV)) {
3963 XS_SAVE_SENSE(xs, sp);
3964 /* solely for the benefit of debug */
3965 sp->req_state_flags |= RQSF_GOT_SENSE;
3968 isp_prt(isp, ISP_LOGDEBUG2,
3969 "asked for %ld got resid %ld", (long) XS_XFRLEN(xs),
3970 (long) sp->req_resid);
3972 case RQSTYPE_REQUEST:
3973 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3975 * Force Queue Full status.
3977 *XS_STSP(xs) = SCSI_QFULL;
3978 XS_SETERR(xs, HBA_NOERROR);
3979 } else if (XS_NOERR(xs)) {
3983 isp_prt(isp, ISP_LOGDEBUG0,
3984 "Request Queue Entry bounced back");
3985 XS_SETERR(xs, HBA_BOTCH);
3987 XS_RESID(xs) = XS_XFRLEN(xs);
3990 isp_prt(isp, ISP_LOGWARN,
3991 "unhandled response queue type 0x%x",
3992 sp->req_header.rqs_entry_type);
3994 XS_SETERR(xs, HBA_BOTCH);
4000 * Free any DMA resources. As a side effect, this may
4001 * also do any cache flushing necessary for data coherence. */
4002 if (XS_XFRLEN(xs)) {
4003 ISP_DMAFREE(isp, xs, sp->req_handle);
4006 if (((isp->isp_dblev & (ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
4007 ((isp->isp_dblev & ISP_LOGDEBUG1) && ((!XS_NOERR(xs)) ||
4008 (*XS_STSP(xs) != SCSI_GOOD)))) {
4010 if (sp->req_state_flags & RQSF_GOT_SENSE) {
4011 skey = XS_SNSKEY(xs) & 0xf;
4016 } else if (*XS_STSP(xs) == SCSI_CHECK) {
4021 isp_prt(isp, ISP_LOGALL, finmsg, XS_CHANNEL(xs),
4022 XS_TGT(xs), XS_LUN(xs), XS_XFRLEN(xs), XS_RESID(xs),
4023 *XS_STSP(xs), skey, XS_ERR(xs));
4026 if (isp->isp_nactive > 0)
4028 complist[ndone++] = xs; /* defer completion call until later */
4029 MEMZERO(hp, QENTRY_LEN); /* PERF */
4030 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
4036 * If we looked at any commands, then it's valid to find out
4037 * what the outpointer is. It also is a trigger to update the
4038 * ISP's notion of what we've seen so far.
4041 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
4043 * While we're at it, read the requst queue out pointer.
4045 isp->isp_reqodx = READ_REQUEST_QUEUE_OUT_POINTER(isp);
4046 if (isp->isp_rscchiwater < ndone)
4047 isp->isp_rscchiwater = ndone;
4050 isp->isp_residx = optr;
4051 isp->isp_rspbsy = 0;
4052 for (i = 0; i < ndone; i++) {
4055 isp->isp_rsltccmplt++;
4066 isp_parse_async(ispsoftc_t *isp, uint16_t mbox)
4071 if (IS_DUALBUS(isp)) {
4072 bus = ISP_READ(isp, OUTMAILBOX6);
4076 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
4079 case ASYNC_BUS_RESET:
4080 isp->isp_sendmarker |= (1 << bus);
4081 #ifdef ISP_TARGET_MODE
4082 if (isp_target_async(isp, bus, mbox))
4085 isp_async(isp, ISPASYNC_BUS_RESET, &bus);
4087 case ASYNC_SYSTEM_ERROR:
4088 #ifdef ISP_FW_CRASH_DUMP
4090 * If we have crash dumps enabled, it's up to the handler
4091 * for isp_async to reinit stuff and restart the firmware
4092 * after performing the crash dump. The reason we do things
4093 * this way is that we may need to activate a kernel thread
4094 * to do all the crash dump goop.
4096 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4098 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4100 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4105 case ASYNC_RQS_XFER_ERR:
4106 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
4109 case ASYNC_RSP_XFER_ERR:
4110 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
4115 * We've just been notified that the Queue has woken up.
4116 * We don't need to be chatty about this- just unlatch things
4119 mbox = READ_REQUEST_QUEUE_OUT_POINTER(isp);
4122 case ASYNC_TIMEOUT_RESET:
4123 isp_prt(isp, ISP_LOGWARN,
4124 "timeout initiated SCSI bus reset of bus %d", bus);
4125 isp->isp_sendmarker |= (1 << bus);
4126 #ifdef ISP_TARGET_MODE
4127 if (isp_target_async(isp, bus, mbox))
4132 case ASYNC_DEVICE_RESET:
4133 isp_prt(isp, ISP_LOGINFO, "device reset on bus %d", bus);
4134 isp->isp_sendmarker |= (1 << bus);
4135 #ifdef ISP_TARGET_MODE
4136 if (isp_target_async(isp, bus, mbox))
4141 case ASYNC_EXTMSG_UNDERRUN:
4142 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
4145 case ASYNC_SCAM_INT:
4146 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
4149 case ASYNC_HUNG_SCSI:
4150 isp_prt(isp, ISP_LOGERR,
4151 "stalled SCSI Bus after DATA Overrun");
4152 /* XXX: Need to issue SCSI reset at this point */
4155 case ASYNC_KILLED_BUS:
4156 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
4159 case ASYNC_BUS_TRANSIT:
4160 mbox = ISP_READ(isp, OUTMAILBOX2);
4161 switch (mbox & 0x1c00) {
4162 case SXP_PINS_LVD_MODE:
4163 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
4164 SDPARAM(isp)->isp_diffmode = 0;
4165 SDPARAM(isp)->isp_ultramode = 0;
4166 SDPARAM(isp)->isp_lvdmode = 1;
4168 case SXP_PINS_HVD_MODE:
4169 isp_prt(isp, ISP_LOGINFO,
4170 "Transition to Differential mode");
4171 SDPARAM(isp)->isp_diffmode = 1;
4172 SDPARAM(isp)->isp_ultramode = 0;
4173 SDPARAM(isp)->isp_lvdmode = 0;
4175 case SXP_PINS_SE_MODE:
4176 isp_prt(isp, ISP_LOGINFO,
4177 "Transition to Single Ended mode");
4178 SDPARAM(isp)->isp_diffmode = 0;
4179 SDPARAM(isp)->isp_ultramode = 1;
4180 SDPARAM(isp)->isp_lvdmode = 0;
4183 isp_prt(isp, ISP_LOGWARN,
4184 "Transition to Unknown Mode 0x%x", mbox);
4188 * XXX: Set up to renegotiate again!
4190 /* Can only be for a 1080... */
4191 isp->isp_sendmarker |= (1 << bus);
4195 * We can use bus, which will always be zero for FC cards,
4196 * as a mailbox pattern accumulator to be checked below.
4199 bus = 0x1ce; /* outgoing mailbox regs 1-3, 6-7 */
4203 bus = 0x14e; /* outgoing mailbox regs 1-3, 6 */
4207 bus = 0x10e; /* outgoing mailbox regs 1-3 */
4211 bus = 0x106; /* outgoing mailbox regs 1-2 */
4215 case ASYNC_CMD_CMPLT:
4216 bus = 0x102; /* outgoing mailbox regs 1 */
4219 case ASYNC_RIO_RESP:
4222 case ASYNC_CTIO_DONE:
4224 #ifdef ISP_TARGET_MODE
4226 (ISP_READ(isp, OUTMAILBOX2) << 16) |
4227 (ISP_READ(isp, OUTMAILBOX1));
4228 if (isp_target_async(isp, handle, mbox)) {
4231 /* count it as a fast posting intr */
4232 isp->isp_fphccmplt++;
4235 isp_prt(isp, ISP_LOGINFO, "Fast Posting CTIO done");
4236 isp->isp_fphccmplt++; /* count it as a fast posting intr */
4241 case ASYNC_LIP_OCCURRED:
4242 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4243 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4244 isp->isp_sendmarker = 1;
4245 isp_mark_getpdb_all(isp);
4246 isp_async(isp, ISPASYNC_LIP, NULL);
4247 #ifdef ISP_TARGET_MODE
4248 if (isp_target_async(isp, bus, mbox))
4252 * We've had problems with data corruption occuring on
4253 * commands that complete (with no apparent error) after
4254 * we receive a LIP. This has been observed mostly on
4255 * Local Loop topologies. To be safe, let's just mark
4256 * all active commands as dead.
4258 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4259 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4261 for (i = j = 0; i < isp->isp_maxcmds; i++) {
4263 xs = isp->isp_xflist[i];
4266 XS_SETERR(xs, HBA_BUSRESET);
4270 isp_prt(isp, ISP_LOGERR,
4271 "LIP destroyed %d active commands", j);
4277 isp->isp_sendmarker = 1;
4278 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4279 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4280 isp_mark_getpdb_all(isp);
4281 isp_async(isp, ISPASYNC_LOOP_UP, NULL);
4282 #ifdef ISP_TARGET_MODE
4283 if (isp_target_async(isp, bus, mbox))
4288 case ASYNC_LOOP_DOWN:
4289 isp->isp_sendmarker = 1;
4290 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4291 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4292 isp_mark_getpdb_all(isp);
4293 isp_async(isp, ISPASYNC_LOOP_DOWN, NULL);
4294 #ifdef ISP_TARGET_MODE
4295 if (isp_target_async(isp, bus, mbox))
4300 case ASYNC_LOOP_RESET:
4301 isp->isp_sendmarker = 1;
4302 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4303 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4304 isp_mark_getpdb_all(isp);
4305 isp_async(isp, ISPASYNC_LOOP_RESET, NULL);
4306 #ifdef ISP_TARGET_MODE
4307 if (isp_target_async(isp, bus, mbox))
4312 case ASYNC_PDB_CHANGED:
4313 isp->isp_sendmarker = 1;
4314 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4315 isp_mark_getpdb_all(isp);
4316 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_PDB);
4319 case ASYNC_CHANGE_NOTIFY:
4321 * Not correct, but it will force us to rescan the loop.
4323 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4324 isp_mark_getpdb_all(isp);
4325 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_SNS);
4329 if (FCPARAM(isp)->isp_onfabric)
4330 FCPARAM(isp)->isp_topo = TOPO_F_PORT;
4332 FCPARAM(isp)->isp_topo = TOPO_N_PORT;
4333 isp_mark_getpdb_all(isp);
4334 isp->isp_sendmarker = 1;
4335 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4336 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4337 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4338 #ifdef ISP_TARGET_MODE
4339 if (isp_target_async(isp, bus, mbox))
4342 isp_prt(isp, ISP_LOGINFO, "Point-to-Point mode");
4345 case ASYNC_CONNMODE:
4346 mbox = ISP_READ(isp, OUTMAILBOX1);
4347 isp_mark_getpdb_all(isp);
4350 isp_prt(isp, ISP_LOGINFO,
4351 "Point-to-Point -> Loop mode");
4354 isp_prt(isp, ISP_LOGINFO,
4355 "Loop -> Point-to-Point mode");
4357 case ISP_CONN_BADLIP:
4358 isp_prt(isp, ISP_LOGWARN,
4359 "Point-to-Point -> Loop mode (BAD LIP)");
4361 case ISP_CONN_FATAL:
4362 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
4363 #ifdef ISP_FW_CRASH_DUMP
4364 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4366 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4368 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4371 case ISP_CONN_LOOPBACK:
4372 isp_prt(isp, ISP_LOGWARN,
4373 "Looped Back in Point-to-Point mode");
4376 isp_prt(isp, ISP_LOGWARN,
4377 "Unknown connection mode (0x%x)", mbox);
4380 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4381 isp->isp_sendmarker = 1;
4382 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4383 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4387 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
4393 uint16_t handles[16];
4395 for (nh = 0, i = 1; i < MAX_MAILBOX(isp); i++) {
4396 if ((bus & (1 << i)) == 0) {
4399 handles[nh++] = ISP_READ(isp, MBOX_OFF(i));
4401 for (i = 0; i < nh; i++) {
4402 isp_fastpost_complete(isp, handles[i]);
4403 isp_prt(isp, ISP_LOGDEBUG3,
4404 "fast post completion of %u", handles[i]);
4406 if (isp->isp_fpcchiwater < nh)
4407 isp->isp_fpcchiwater = nh;
4409 isp->isp_intoasync++;
4415 * Handle other response entries. A pointer to the request queue output
4416 * index is here in case we want to eat several entries at once, although
4417 * this is not used currently.
4421 isp_handle_other_response(ispsoftc_t *isp, int type,
4422 isphdr_t *hp, uint16_t *optrp)
4425 case RQSTYPE_STATUS_CONT:
4426 isp_prt(isp, ISP_LOGINFO, "Ignored Continuation Response");
4430 case RQSTYPE_ENABLE_LUN:
4431 case RQSTYPE_MODIFY_LUN:
4432 case RQSTYPE_NOTIFY:
4433 case RQSTYPE_NOTIFY_ACK:
4438 isp->isp_rsltccmplt++; /* count as a response completion */
4439 #ifdef ISP_TARGET_MODE
4440 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
4445 case RQSTYPE_REQUEST:
4448 if (type != isp_get_response_type(isp, hp)) {
4450 * This is questionable- we're just papering over
4451 * something we've seen on SMP linux in target
4452 * mode- we don't really know what's happening
4453 * here that causes us to think we've gotten
4454 * an entry, but that either the entry isn't
4455 * filled out yet or our CPU read data is stale.
4457 isp_prt(isp, ISP_LOGINFO,
4458 "unstable type in response queue");
4461 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
4462 isp_get_response_type(isp, hp));
4463 if (isp_async(isp, ISPASYNC_UNHANDLED_RESPONSE, hp)) {
4471 isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs)
4473 switch (sp->req_completion_status & 0xff) {
4476 XS_SETERR(xs, HBA_NOERROR);
4480 case RQCS_INCOMPLETE:
4481 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
4482 isp_prt(isp, ISP_LOGDEBUG1,
4483 "Selection Timeout for %d.%d.%d",
4484 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4486 XS_SETERR(xs, HBA_SELTIMEOUT);
4490 isp_prt(isp, ISP_LOGERR,
4491 "command incomplete for %d.%d.%d, state 0x%x",
4492 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
4493 sp->req_state_flags);
4496 case RQCS_DMA_ERROR:
4497 isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
4498 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4501 case RQCS_TRANSPORT_ERROR:
4504 SNPRINTF(buf, sizeof (buf), "states=>");
4505 if (sp->req_state_flags & RQSF_GOT_BUS) {
4506 SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
4508 if (sp->req_state_flags & RQSF_GOT_TARGET) {
4509 SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
4511 if (sp->req_state_flags & RQSF_SENT_CDB) {
4512 SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
4514 if (sp->req_state_flags & RQSF_XFRD_DATA) {
4515 SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
4517 if (sp->req_state_flags & RQSF_GOT_STATUS) {
4518 SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
4520 if (sp->req_state_flags & RQSF_GOT_SENSE) {
4521 SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
4523 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
4524 SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
4526 SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
4527 if (sp->req_status_flags & RQSTF_DISCONNECT) {
4528 SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
4530 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
4531 SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
4533 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
4534 SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
4536 if (sp->req_status_flags & RQSTF_BUS_RESET) {
4537 SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
4539 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
4540 SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
4542 if (sp->req_status_flags & RQSTF_ABORTED) {
4543 SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
4545 if (sp->req_status_flags & RQSTF_TIMEOUT) {
4546 SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
4548 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
4549 SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
4551 isp_prt(isp, ISP_LOGERR, "%s", buf);
4552 isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d:\n%s",
4553 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), buf);
4556 case RQCS_RESET_OCCURRED:
4557 isp_prt(isp, ISP_LOGWARN,
4558 "bus reset destroyed command for %d.%d.%d",
4559 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4560 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4562 XS_SETERR(xs, HBA_BUSRESET);
4567 isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
4568 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4569 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4571 XS_SETERR(xs, HBA_ABORTED);
4576 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
4577 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4579 * Check to see if we logged out the device.
4582 if ((sp->req_completion_status & RQSTF_LOGOUT) &&
4583 FCPARAM(isp)->portdb[XS_TGT(xs)].valid &&
4584 FCPARAM(isp)->portdb[XS_TGT(xs)].fabric_dev) {
4585 FCPARAM(isp)->portdb[XS_TGT(xs)].relogin = 1;
4589 XS_SETERR(xs, HBA_CMDTIMEOUT);
4593 case RQCS_DATA_OVERRUN:
4594 XS_RESID(xs) = sp->req_resid;
4595 isp_prt(isp, ISP_LOGERR, "data overrun for command on %d.%d.%d",
4596 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4598 XS_SETERR(xs, HBA_DATAOVR);
4602 case RQCS_COMMAND_OVERRUN:
4603 isp_prt(isp, ISP_LOGERR,
4604 "command overrun for command on %d.%d.%d",
4605 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4608 case RQCS_STATUS_OVERRUN:
4609 isp_prt(isp, ISP_LOGERR,
4610 "status overrun for command on %d.%d.%d",
4611 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4614 case RQCS_BAD_MESSAGE:
4615 isp_prt(isp, ISP_LOGERR,
4616 "msg not COMMAND COMPLETE after status %d.%d.%d",
4617 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4620 case RQCS_NO_MESSAGE_OUT:
4621 isp_prt(isp, ISP_LOGERR,
4622 "No MESSAGE OUT phase after selection on %d.%d.%d",
4623 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4626 case RQCS_EXT_ID_FAILED:
4627 isp_prt(isp, ISP_LOGERR, "EXTENDED IDENTIFY failed %d.%d.%d",
4628 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4631 case RQCS_IDE_MSG_FAILED:
4632 isp_prt(isp, ISP_LOGERR,
4633 "INITIATOR DETECTED ERROR rejected by %d.%d.%d",
4634 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4637 case RQCS_ABORT_MSG_FAILED:
4638 isp_prt(isp, ISP_LOGERR, "ABORT OPERATION rejected by %d.%d.%d",
4639 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4642 case RQCS_REJECT_MSG_FAILED:
4643 isp_prt(isp, ISP_LOGERR, "MESSAGE REJECT rejected by %d.%d.%d",
4644 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4647 case RQCS_NOP_MSG_FAILED:
4648 isp_prt(isp, ISP_LOGERR, "NOP rejected by %d.%d.%d",
4649 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4652 case RQCS_PARITY_ERROR_MSG_FAILED:
4653 isp_prt(isp, ISP_LOGERR,
4654 "MESSAGE PARITY ERROR rejected by %d.%d.%d",
4655 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4658 case RQCS_DEVICE_RESET_MSG_FAILED:
4659 isp_prt(isp, ISP_LOGWARN,
4660 "BUS DEVICE RESET rejected by %d.%d.%d",
4661 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4664 case RQCS_ID_MSG_FAILED:
4665 isp_prt(isp, ISP_LOGERR, "IDENTIFY rejected by %d.%d.%d",
4666 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4669 case RQCS_UNEXP_BUS_FREE:
4670 isp_prt(isp, ISP_LOGERR, "%d.%d.%d had an unexpected bus free",
4671 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4674 case RQCS_DATA_UNDERRUN:
4677 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
4678 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
4679 isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
4680 XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
4681 (ru_marked)? "marked" : "not marked");
4683 XS_SETERR(xs, HBA_BOTCH);
4688 XS_RESID(xs) = sp->req_resid;
4690 XS_SETERR(xs, HBA_NOERROR);
4695 case RQCS_XACT_ERR1:
4696 isp_prt(isp, ISP_LOGERR, xact1, XS_CHANNEL(xs),
4697 XS_TGT(xs), XS_LUN(xs));
4700 case RQCS_XACT_ERR2:
4701 isp_prt(isp, ISP_LOGERR, xact2,
4702 XS_LUN(xs), XS_TGT(xs), XS_CHANNEL(xs));
4705 case RQCS_XACT_ERR3:
4706 isp_prt(isp, ISP_LOGERR, xact3,
4707 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4710 case RQCS_BAD_ENTRY:
4711 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
4714 case RQCS_QUEUE_FULL:
4715 isp_prt(isp, ISP_LOGDEBUG0,
4716 "internal queues full for %d.%d.%d status 0x%x",
4717 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), *XS_STSP(xs));
4720 * If QFULL or some other status byte is set, then this
4721 * isn't an error, per se.
4723 * Unfortunately, some QLogic f/w writers have, in
4724 * some cases, ommitted to *set* status to QFULL.
4727 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
4728 XS_SETERR(xs, HBA_NOERROR);
4736 *XS_STSP(xs) = SCSI_QFULL;
4737 XS_SETERR(xs, HBA_NOERROR);
4740 case RQCS_PHASE_SKIPPED:
4741 isp_prt(isp, ISP_LOGERR, pskip, XS_CHANNEL(xs),
4742 XS_TGT(xs), XS_LUN(xs));
4745 case RQCS_ARQS_FAILED:
4746 isp_prt(isp, ISP_LOGERR,
4747 "Auto Request Sense failed for %d.%d.%d",
4748 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4750 XS_SETERR(xs, HBA_ARQFAIL);
4754 case RQCS_WIDE_FAILED:
4755 isp_prt(isp, ISP_LOGERR,
4756 "Wide Negotiation failed for %d.%d.%d",
4757 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4759 sdparam *sdp = isp->isp_param;
4760 sdp += XS_CHANNEL(xs);
4761 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
4762 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4763 isp->isp_update |= (1 << XS_CHANNEL(xs));
4766 XS_SETERR(xs, HBA_NOERROR);
4770 case RQCS_SYNCXFER_FAILED:
4771 isp_prt(isp, ISP_LOGERR,
4772 "SDTR Message failed for target %d.%d.%d",
4773 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4775 sdparam *sdp = isp->isp_param;
4776 sdp += XS_CHANNEL(xs);
4777 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
4778 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4779 isp->isp_update |= (1 << XS_CHANNEL(xs));
4783 case RQCS_LVD_BUSERR:
4784 isp_prt(isp, ISP_LOGERR,
4785 "Bad LVD condition while talking to %d.%d.%d",
4786 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4789 case RQCS_PORT_UNAVAILABLE:
4791 * No such port on the loop. Moral equivalent of SELTIMEO
4793 case RQCS_PORT_LOGGED_OUT:
4795 * It was there (maybe)- treat as a selection timeout.
4797 if ((sp->req_completion_status & 0xff) == RQCS_PORT_UNAVAILABLE)
4798 isp_prt(isp, ISP_LOGINFO,
4799 "port unavailable for target %d", XS_TGT(xs));
4801 isp_prt(isp, ISP_LOGINFO,
4802 "port logout for target %d", XS_TGT(xs));
4804 * If we're on a local loop, force a LIP (which is overkill)
4805 * to force a re-login of this unit. If we're on fabric,
4806 * then we'll have to relogin as a matter of course.
4808 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4809 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4811 MEMZERO(&mbs, sizeof (mbs));
4812 mbs.param[0] = MBOX_INIT_LIP;
4813 isp_mboxcmd_qnw(isp, &mbs, 1);
4817 * Probably overkill.
4819 isp->isp_sendmarker = 1;
4820 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4821 isp_mark_getpdb_all(isp);
4822 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4824 XS_SETERR(xs, HBA_SELTIMEOUT);
4828 case RQCS_PORT_CHANGED:
4829 isp_prt(isp, ISP_LOGWARN,
4830 "port changed for target %d", XS_TGT(xs));
4832 XS_SETERR(xs, HBA_SELTIMEOUT);
4836 case RQCS_PORT_BUSY:
4837 isp_prt(isp, ISP_LOGWARN,
4838 "port busy for target %d", XS_TGT(xs));
4840 XS_SETERR(xs, HBA_TGTBSY);
4845 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x",
4846 sp->req_completion_status);
4850 XS_SETERR(xs, HBA_BOTCH);
4855 isp_fastpost_complete(ispsoftc_t *isp, uint16_t fph)
4862 xs = isp_find_xs(isp, fph);
4864 isp_prt(isp, ISP_LOGWARN,
4865 "Command for fast post handle 0x%x not found", fph);
4868 isp_destroy_handle(isp, fph);
4871 * Since we don't have a result queue entry item,
4872 * we must believe that SCSI status is zero and
4873 * that all data transferred.
4875 XS_SET_STATE_STAT(isp, xs, NULL);
4877 *XS_STSP(xs) = SCSI_GOOD;
4878 if (XS_XFRLEN(xs)) {
4879 ISP_DMAFREE(isp, xs, fph);
4881 if (isp->isp_nactive)
4883 isp->isp_fphccmplt++;
4888 isp_mbox_continue(ispsoftc_t *isp)
4893 switch (isp->isp_lastmbxcmd) {
4894 case MBOX_WRITE_RAM_WORD:
4895 case MBOX_READ_RAM_WORD:
4896 case MBOX_READ_RAM_WORD_EXTENDED:
4901 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
4902 isp->isp_mbxwrk0 = 0;
4907 * Clear the previous interrupt.
4909 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
4910 ISP_WRITE(isp, BIU_SEMA, 0);
4913 * Continue with next word.
4915 MEMZERO(&mbs, sizeof (mbs));
4916 ptr = isp->isp_mbxworkp;
4917 switch (isp->isp_lastmbxcmd) {
4918 case MBOX_WRITE_RAM_WORD:
4919 mbs.param[2] = *ptr++;
4920 mbs.param[1] = isp->isp_mbxwrk1++;
4922 case MBOX_READ_RAM_WORD:
4923 case MBOX_READ_RAM_WORD_EXTENDED:
4924 *ptr++ = isp->isp_mboxtmp[2];
4925 mbs.param[1] = isp->isp_mbxwrk1++;
4928 isp->isp_mbxworkp = ptr;
4929 mbs.param[0] = isp->isp_lastmbxcmd;
4930 isp->isp_mbxwrk0 -= 1;
4931 isp_mboxcmd_qnw(isp, &mbs, 0);
4936 #define HIWRD(x) ((x) >> 16)
4937 #define LOWRD(x) ((x) & 0xffff)
4938 #define ISPOPMAP(a, b) (((a) << 16) | (b))
4939 static const uint32_t mbpscsi[] = {
4940 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
4941 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
4942 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
4943 ISPOPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
4944 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
4945 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
4946 ISPOPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
4947 ISPOPMAP(0x03, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
4948 ISPOPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
4949 ISPOPMAP(0x00, 0x00), /* 0x09: */
4950 ISPOPMAP(0x00, 0x00), /* 0x0a: */
4951 ISPOPMAP(0x00, 0x00), /* 0x0b: */
4952 ISPOPMAP(0x00, 0x00), /* 0x0c: */
4953 ISPOPMAP(0x00, 0x00), /* 0x0d: */
4954 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
4955 ISPOPMAP(0x00, 0x00), /* 0x0f: */
4956 ISPOPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
4957 ISPOPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
4958 ISPOPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
4959 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
4960 ISPOPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
4961 ISPOPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
4962 ISPOPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
4963 ISPOPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
4964 ISPOPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
4965 ISPOPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
4966 ISPOPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
4967 ISPOPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
4968 ISPOPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
4969 ISPOPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
4970 ISPOPMAP(0x00, 0x00), /* 0x1e: */
4971 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
4972 ISPOPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
4973 ISPOPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
4974 ISPOPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
4975 ISPOPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
4976 ISPOPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
4977 ISPOPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
4978 ISPOPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
4979 ISPOPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
4980 ISPOPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
4981 ISPOPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
4982 ISPOPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
4983 ISPOPMAP(0x00, 0x00), /* 0x2b: */
4984 ISPOPMAP(0x00, 0x00), /* 0x2c: */
4985 ISPOPMAP(0x00, 0x00), /* 0x2d: */
4986 ISPOPMAP(0x00, 0x00), /* 0x2e: */
4987 ISPOPMAP(0x00, 0x00), /* 0x2f: */
4988 ISPOPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
4989 ISPOPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
4990 ISPOPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
4991 ISPOPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
4992 ISPOPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
4993 ISPOPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
4994 ISPOPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
4995 ISPOPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
4996 ISPOPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
4997 ISPOPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
4998 ISPOPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
4999 ISPOPMAP(0x00, 0x00), /* 0x3b: */
5000 ISPOPMAP(0x00, 0x00), /* 0x3c: */
5001 ISPOPMAP(0x00, 0x00), /* 0x3d: */
5002 ISPOPMAP(0x00, 0x00), /* 0x3e: */
5003 ISPOPMAP(0x00, 0x00), /* 0x3f: */
5004 ISPOPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
5005 ISPOPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
5006 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
5007 ISPOPMAP(0x00, 0x00), /* 0x43: */
5008 ISPOPMAP(0x00, 0x00), /* 0x44: */
5009 ISPOPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
5010 ISPOPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
5011 ISPOPMAP(0x00, 0x00), /* 0x47: */
5012 ISPOPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
5013 ISPOPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
5014 ISPOPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
5015 ISPOPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
5016 ISPOPMAP(0x00, 0x00), /* 0x4c: */
5017 ISPOPMAP(0x00, 0x00), /* 0x4d: */
5018 ISPOPMAP(0x00, 0x00), /* 0x4e: */
5019 ISPOPMAP(0x00, 0x00), /* 0x4f: */
5020 ISPOPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
5021 ISPOPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
5022 ISPOPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
5023 ISPOPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
5024 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
5025 ISPOPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
5026 ISPOPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
5027 ISPOPMAP(0x00, 0x00), /* 0x57: */
5028 ISPOPMAP(0x00, 0x00), /* 0x58: */
5029 ISPOPMAP(0x00, 0x00), /* 0x59: */
5030 ISPOPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
5031 ISPOPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
5032 ISPOPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
5033 ISPOPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
5036 #ifndef ISP_STRIPPED
5037 static char *scsi_mbcmd_names[] = {
5054 "INIT REQUEST QUEUE",
5055 "INIT RESULT QUEUE",
5065 "SINGLE STEP QUEUE",
5067 "GET DEV QUEUE STATUS",
5069 "GET FIRMWARE STATUS",
5071 "GET SELECT TIMEOUT",
5073 "GET TAG AGE LIMIT",
5075 "GET ACT NEG STATE",
5076 "GET ASYNC DATA SETUP TIME",
5078 "GET TARGET PARAMS",
5079 "GET DEV QUEUE PARAMS",
5080 "GET RESET DELAY PARAMS",
5087 "SET SELECT TIMEOUT",
5089 "SET TAG AGE LIMIT",
5091 "SET ACT NEG STATE",
5092 "SET ASYNC DATA SETUP TIME",
5093 "SET PCI CONTROL PARAMS",
5094 "SET TARGET PARAMS",
5095 "SET DEV QUEUE PARAMS",
5096 "SET RESET DELAY PARAMS",
5102 "RETURN BIOS BLOCK ADDR",
5103 "WRITE FOUR RAM WORDS",
5107 "SET SYSTEM PARAMETER",
5108 "GET SYSTEM PARAMETER",
5110 "GET SCAM CONFIGURATION",
5111 "SET SCAM CONFIGURATION",
5112 "SET FIRMWARE FEATURES",
5113 "GET FIRMWARE FEATURES",
5120 "INITIALIZE REQUEST QUEUE A64",
5121 "INITIALIZE RESPONSE QUEUE A64",
5123 "ENABLE TARGET MODE",
5124 "GET TARGET MODE STATE",
5128 "SET DATA OVERRUN RECOVERY MODE",
5129 "GET DATA OVERRUN RECOVERY MODE",
5135 static const uint32_t mbpfc[] = {
5136 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
5137 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
5138 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
5139 ISPOPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
5140 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
5141 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
5142 ISPOPMAP(0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
5143 ISPOPMAP(0x03, 0x05), /* 0x07: MBOX_VERIFY_CHECKSUM */
5144 ISPOPMAP(0x01, 0x4f), /* 0x08: MBOX_ABOUT_FIRMWARE */
5145 ISPOPMAP(0xdf, 0x01), /* 0x09: LOAD RAM */
5146 ISPOPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
5147 ISPOPMAP(0x00, 0x00), /* 0x0b: */
5148 ISPOPMAP(0x00, 0x00), /* 0x0c: */
5149 ISPOPMAP(0x00, 0x00), /* 0x0d: */
5150 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
5151 ISPOPMAP(0x03, 0x07), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED(1) */
5152 ISPOPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
5153 ISPOPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
5154 ISPOPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
5155 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
5156 ISPOPMAP(0x01, 0xff), /* 0x14: MBOX_STOP_FIRMWARE */
5157 ISPOPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
5158 ISPOPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
5159 ISPOPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
5160 ISPOPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
5161 ISPOPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
5162 ISPOPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
5163 ISPOPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
5164 ISPOPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
5165 ISPOPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
5166 ISPOPMAP(0x00, 0x00), /* 0x1e: */
5167 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
5168 ISPOPMAP(0x01, 0x4f), /* 0x20: MBOX_GET_LOOP_ID */
5169 ISPOPMAP(0x00, 0x00), /* 0x21: */
5170 ISPOPMAP(0x01, 0x07), /* 0x22: MBOX_GET_RETRY_COUNT */
5171 ISPOPMAP(0x00, 0x00), /* 0x23: */
5172 ISPOPMAP(0x00, 0x00), /* 0x24: */
5173 ISPOPMAP(0x00, 0x00), /* 0x25: */
5174 ISPOPMAP(0x00, 0x00), /* 0x26: */
5175 ISPOPMAP(0x00, 0x00), /* 0x27: */
5176 ISPOPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
5177 ISPOPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
5178 ISPOPMAP(0x00, 0x00), /* 0x2a: */
5179 ISPOPMAP(0x00, 0x00), /* 0x2b: */
5180 ISPOPMAP(0x00, 0x00), /* 0x2c: */
5181 ISPOPMAP(0x00, 0x00), /* 0x2d: */
5182 ISPOPMAP(0x00, 0x00), /* 0x2e: */
5183 ISPOPMAP(0x00, 0x00), /* 0x2f: */
5184 ISPOPMAP(0x00, 0x00), /* 0x30: */
5185 ISPOPMAP(0x00, 0x00), /* 0x31: */
5186 ISPOPMAP(0x07, 0x07), /* 0x32: MBOX_SET_RETRY_COUNT */
5187 ISPOPMAP(0x00, 0x00), /* 0x33: */
5188 ISPOPMAP(0x00, 0x00), /* 0x34: */
5189 ISPOPMAP(0x00, 0x00), /* 0x35: */
5190 ISPOPMAP(0x00, 0x00), /* 0x36: */
5191 ISPOPMAP(0x00, 0x00), /* 0x37: */
5192 ISPOPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
5193 ISPOPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
5194 ISPOPMAP(0x00, 0x00), /* 0x3a: */
5195 ISPOPMAP(0x00, 0x00), /* 0x3b: */
5196 ISPOPMAP(0x00, 0x00), /* 0x3c: */
5197 ISPOPMAP(0x00, 0x00), /* 0x3d: */
5198 ISPOPMAP(0x00, 0x00), /* 0x3e: */
5199 ISPOPMAP(0x00, 0x00), /* 0x3f: */
5200 ISPOPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
5201 ISPOPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
5202 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_GET_RESOURCE_COUNTS */
5203 ISPOPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_NON_PARTICIPATING_MODE */
5204 ISPOPMAP(0x00, 0x00), /* 0x44: */
5205 ISPOPMAP(0x00, 0x00), /* 0x45: */
5206 ISPOPMAP(0x00, 0x00), /* 0x46: */
5207 ISPOPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
5208 ISPOPMAP(0x00, 0x00), /* 0x48: */
5209 ISPOPMAP(0x00, 0x00), /* 0x49: */
5210 ISPOPMAP(0x00, 0x00), /* 0x4a: */
5211 ISPOPMAP(0x00, 0x00), /* 0x4b: */
5212 ISPOPMAP(0x00, 0x00), /* 0x4c: */
5213 ISPOPMAP(0x00, 0x00), /* 0x4d: */
5214 ISPOPMAP(0x00, 0x00), /* 0x4e: */
5215 ISPOPMAP(0x00, 0x00), /* 0x4f: */
5216 ISPOPMAP(0x00, 0x00), /* 0x50: */
5217 ISPOPMAP(0x00, 0x00), /* 0x51: */
5218 ISPOPMAP(0x00, 0x00), /* 0x52: */
5219 ISPOPMAP(0x00, 0x00), /* 0x53: */
5220 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
5221 ISPOPMAP(0x00, 0x00), /* 0x55: */
5222 ISPOPMAP(0x00, 0x00), /* 0x56: */
5223 ISPOPMAP(0x00, 0x00), /* 0x57: */
5224 ISPOPMAP(0x00, 0x00), /* 0x58: */
5225 ISPOPMAP(0x00, 0x00), /* 0x59: */
5226 ISPOPMAP(0x00, 0x00), /* 0x5a: */
5227 ISPOPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
5228 ISPOPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
5229 ISPOPMAP(0x07, 0x03), /* 0x5d: MBOX_GET_SET_DATA_RATE */
5230 ISPOPMAP(0x00, 0x00), /* 0x5e: */
5231 ISPOPMAP(0x00, 0x00), /* 0x5f: */
5232 ISPOPMAP(0xfd, 0x31), /* 0x60: MBOX_INIT_FIRMWARE */
5233 ISPOPMAP(0x00, 0x00), /* 0x61: */
5234 ISPOPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
5235 ISPOPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
5236 ISPOPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
5237 ISPOPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
5238 ISPOPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
5239 ISPOPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
5240 ISPOPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
5241 ISPOPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
5242 ISPOPMAP(0x03, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
5243 ISPOPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
5244 ISPOPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
5245 ISPOPMAP(0x00, 0x00), /* 0x6d: */
5246 ISPOPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
5247 ISPOPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
5248 ISPOPMAP(0x03, 0x01), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
5249 ISPOPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
5250 ISPOPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
5251 ISPOPMAP(0x00, 0x00), /* 0x73: */
5252 ISPOPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
5253 ISPOPMAP(0xcf, 0x03), /* 0x75: GET PORT/NODE NAME LIST */
5254 ISPOPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
5255 ISPOPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
5256 ISPOPMAP(0x00, 0x00), /* 0x78: */
5257 ISPOPMAP(0x00, 0x00), /* 0x79: */
5258 ISPOPMAP(0x00, 0x00), /* 0x7a: */
5259 ISPOPMAP(0x00, 0x00), /* 0x7b: */
5260 ISPOPMAP(0x4f, 0x03), /* 0x7c: Get ID List */
5261 ISPOPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
5262 ISPOPMAP(0x0f, 0x01) /* 0x7e: LUN RESET */
5267 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
5268 * do not access at this time in the core driver. The caller is
5269 * responsible for setting this register first (Gross!).
5272 #ifndef ISP_STRIPPED
5273 static char *fc_mbcmd_names[] = {
5287 "READ RAM WORD EXTENDED",
5290 "INIT REQUEST QUEUE",
5291 "INIT RESULT QUEUE",
5301 "SINGLE STEP QUEUE",
5303 "GET DEV QUEUE STATUS",
5305 "GET FIRMWARE STATUS",
5314 "GET FIRMWARE OPTIONS",
5315 "GET PORT QUEUE PARAMS",
5330 "SET FIRMWARE OPTIONS",
5331 "SET PORT QUEUE PARAMS",
5340 "GET RESOURCE COUNTS",
5341 "REQUEST NON PARTICIPATING MODE",
5345 "GET PORT DATABASE,, ENHANCED",
5367 "GET/SET DATA RATE",
5373 "GET FC-AL POSITION MAP",
5374 "GET PORT DATABASE",
5386 "SEND CHANGE REQUEST",
5391 "GET PORT/NODE NAME LIST",
5393 "INITIALIZE IP MAILBOX",
5405 isp_mboxcmd_qnw(ispsoftc_t *isp, mbreg_t *mbp, int nodelay)
5407 unsigned int ibits, obits, box, opcode;
5408 const uint32_t *mcp;
5415 opcode = mbp->param[0];
5416 ibits = HIWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5417 obits = LOWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5418 ibits |= mbp->ibits;
5419 obits |= mbp->obits;
5420 for (box = 0; box < MAX_MAILBOX(isp); box++) {
5421 if (ibits & (1 << box)) {
5422 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5425 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5429 isp->isp_lastmbxcmd = opcode;
5430 isp->isp_obits = obits;
5431 isp->isp_mboxbsy = 1;
5433 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5435 * Oddly enough, if we're not delaying for an answer,
5436 * delay a bit to give the f/w a chance to pick up the
5445 isp_mboxcmd(ispsoftc_t *isp, mbreg_t *mbp, int logmask)
5447 char *cname, *xname, tname[16], mname[16];
5448 unsigned int lim, ibits, obits, box, opcode;
5449 const uint32_t *mcp;
5453 lim = (sizeof (mbpfc) / sizeof (mbpfc[0]));
5456 lim = (sizeof (mbpscsi) / sizeof (mbpscsi[0]));
5459 if ((opcode = mbp->param[0]) >= lim) {
5460 mbp->param[0] = MBOX_INVALID_COMMAND;
5461 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
5465 ibits = HIWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5466 obits = LOWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5468 ibits |= mbp->ibits;
5469 obits |= mbp->obits;
5471 if (ibits == 0 && obits == 0) {
5472 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
5473 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
5478 * Get exclusive usage of mailbox registers.
5482 for (box = 0; box < MAX_MAILBOX(isp); box++) {
5483 if (ibits & (1 << box)) {
5484 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5486 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5489 isp->isp_lastmbxcmd = opcode;
5492 * We assume that we can't overwrite a previous command.
5494 isp->isp_obits = obits;
5495 isp->isp_mboxbsy = 1;
5498 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
5500 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5503 * While we haven't finished the command, spin our wheels here.
5505 MBOX_WAIT_COMPLETE(isp);
5507 if (isp->isp_mboxbsy) {
5509 * Command timed out.
5511 isp->isp_mboxbsy = 0;
5517 * Copy back output registers.
5519 for (box = 0; box < MAX_MAILBOX(isp); box++) {
5520 if (obits & (1 << box)) {
5521 mbp->param[box] = isp->isp_mboxtmp[box];
5527 if (logmask == 0 || opcode == MBOX_EXEC_FIRMWARE) {
5533 cname = (IS_FC(isp))? fc_mbcmd_names[opcode] : scsi_mbcmd_names[opcode];
5535 if (cname == NULL) {
5537 SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
5541 * Just to be chatty here...
5544 switch (mbp->param[0]) {
5545 case MBOX_COMMAND_COMPLETE:
5547 case MBOX_INVALID_COMMAND:
5548 if (logmask & MBLOGMASK(MBOX_COMMAND_COMPLETE))
5549 xname = "INVALID COMMAND";
5551 case MBOX_HOST_INTERFACE_ERROR:
5552 if (logmask & MBLOGMASK(MBOX_HOST_INTERFACE_ERROR))
5553 xname = "HOST INTERFACE ERROR";
5555 case MBOX_TEST_FAILED:
5556 if (logmask & MBLOGMASK(MBOX_TEST_FAILED))
5557 xname = "TEST FAILED";
5559 case MBOX_COMMAND_ERROR:
5560 if (logmask & MBLOGMASK(MBOX_COMMAND_ERROR))
5561 xname = "COMMAND ERROR";
5563 case MBOX_COMMAND_PARAM_ERROR:
5564 if (logmask & MBLOGMASK(MBOX_COMMAND_PARAM_ERROR))
5565 xname = "COMMAND PARAMETER ERROR";
5567 case MBOX_LOOP_ID_USED:
5568 if (logmask & MBLOGMASK(MBOX_LOOP_ID_USED))
5569 xname = "LOOP ID ALREADY IN USE";
5571 case MBOX_PORT_ID_USED:
5572 if (logmask & MBLOGMASK(MBOX_PORT_ID_USED))
5573 xname = "PORT ID ALREADY IN USE";
5575 case MBOX_ALL_IDS_USED:
5576 if (logmask & MBLOGMASK(MBOX_ALL_IDS_USED))
5577 xname = "ALL LOOP IDS IN USE";
5579 case 0: /* special case */
5583 SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
5588 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s)",
5593 isp_fw_state(ispsoftc_t *isp)
5597 fcparam *fcp = isp->isp_param;
5599 MEMZERO(&mbs, sizeof (mbs));
5600 mbs.param[0] = MBOX_GET_FW_STATE;
5601 isp_mboxcmd(isp, &mbs, MBLOGALL);
5602 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
5603 fcp->isp_fwstate = mbs.param[1];
5609 isp_update(ispsoftc_t *isp)
5613 for (bus = 0, upmask = isp->isp_update; upmask != 0; bus++) {
5614 if (upmask & (1 << bus)) {
5615 isp_update_bus(isp, bus);
5617 upmask &= ~(1 << bus);
5622 isp_update_bus(ispsoftc_t *isp, int bus)
5628 isp->isp_update &= ~(1 << bus);
5631 * There are no 'per-bus' settings for Fibre Channel.
5635 sdp = isp->isp_param;
5637 MEMZERO(&mbs, sizeof (mbs));
5639 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5640 uint16_t flags, period, offset;
5643 if (sdp->isp_devparam[tgt].dev_enable == 0) {
5644 sdp->isp_devparam[tgt].dev_update = 0;
5645 sdp->isp_devparam[tgt].dev_refresh = 0;
5646 isp_prt(isp, ISP_LOGDEBUG0,
5647 "skipping target %d bus %d update", tgt, bus);
5651 * If the goal is to update the status of the device,
5652 * take what's in goal_flags and try and set the device
5653 * toward that. Otherwise, if we're just refreshing the
5654 * current device state, get the current parameters.
5658 * Refresh overrides set
5660 if (sdp->isp_devparam[tgt].dev_refresh) {
5661 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
5662 sdp->isp_devparam[tgt].dev_refresh = 0;
5664 } else if (sdp->isp_devparam[tgt].dev_update) {
5665 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
5667 * Make sure goal_flags has "Renegotiate on Error"
5668 * on and "Freeze Queue on Error" off.
5670 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
5671 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
5673 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
5676 * Insist that PARITY must be enabled
5677 * if SYNC or WIDE is enabled.
5679 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
5680 mbs.param[2] |= DPARM_PARITY;
5683 if ((mbs.param[2] & DPARM_SYNC) == 0) {
5687 (sdp->isp_devparam[tgt].goal_offset << 8) |
5688 (sdp->isp_devparam[tgt].goal_period);
5691 * A command completion later that has
5692 * RQSTF_NEGOTIATION set can cause
5693 * the dev_refresh/announce cycle also.
5695 * Note: It is really important to update our current
5696 * flags with at least the state of TAG capabilities-
5697 * otherwise we might try and send a tagged command
5698 * when we have it all turned off. So change it here
5699 * to say that current already matches goal.
5701 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
5702 sdp->isp_devparam[tgt].actv_flags |=
5703 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
5704 isp_prt(isp, ISP_LOGDEBUG0,
5705 "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
5706 bus, tgt, mbs.param[2], mbs.param[3] >> 8,
5707 mbs.param[3] & 0xff);
5708 sdp->isp_devparam[tgt].dev_update = 0;
5709 sdp->isp_devparam[tgt].dev_refresh = 1;
5714 mbs.param[1] = (bus << 15) | (tgt << 8);
5715 isp_mboxcmd(isp, &mbs, MBLOGALL);
5717 isp->isp_sendmarker |= (1 << bus);
5720 flags = mbs.param[2];
5721 period = mbs.param[3] & 0xff;
5722 offset = mbs.param[3] >> 8;
5723 sdp->isp_devparam[tgt].actv_flags = flags;
5724 sdp->isp_devparam[tgt].actv_period = period;
5725 sdp->isp_devparam[tgt].actv_offset = offset;
5726 get = (bus << 16) | tgt;
5727 (void) isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, &get);
5730 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5731 if (sdp->isp_devparam[tgt].dev_update ||
5732 sdp->isp_devparam[tgt].dev_refresh) {
5733 isp->isp_update |= (1 << bus);
5739 #ifndef DEFAULT_FRAMESIZE
5740 #define DEFAULT_FRAMESIZE(isp) ICB_DFLT_FRMLEN
5742 #ifndef DEFAULT_EXEC_THROTTLE
5743 #define DEFAULT_EXEC_THROTTLE(isp) ISP_EXEC_THROTTLE
5747 isp_setdfltparm(ispsoftc_t *isp, int channel)
5753 MEMZERO(&mbs, sizeof (mbs));
5755 fcparam *fcp = (fcparam *) isp->isp_param;
5759 if (fcp->isp_gotdparms) {
5762 fcp->isp_gotdparms = 1;
5763 fcp->isp_maxfrmlen = DEFAULT_FRAMESIZE(isp);
5764 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
5765 fcp->isp_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
5766 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
5767 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
5768 /* Platform specific.... */
5769 fcp->isp_loopid = DEFAULT_LOOPID(isp);
5770 fcp->isp_nodewwn = DEFAULT_NODEWWN(isp);
5771 fcp->isp_portwwn = DEFAULT_PORTWWN(isp);
5772 fcp->isp_fwoptions = 0;
5773 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
5774 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
5775 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
5776 #ifndef ISP_NO_FASTPOST_FC
5777 fcp->isp_fwoptions |= ICBOPT_FAST_POST;
5779 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
5780 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
5783 * Make sure this is turned off now until we get
5784 * extended options from NVRAM
5786 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
5789 * Now try and read NVRAM unless told to not do so.
5790 * This will set fcparam's isp_nodewwn && isp_portwwn.
5792 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5793 nvfail = isp_read_nvram(isp);
5795 isp->isp_confopts |= ISP_CFG_NONVRAM;
5800 * Set node && port to override platform set defaults
5801 * unless the nvram read failed (or none was done),
5802 * or the platform code wants to use what had been
5803 * set in the defaults.
5806 isp->isp_confopts |= ISP_CFG_OWNWWPN|ISP_CFG_OWNWWNN;
5808 if (isp->isp_confopts & ISP_CFG_OWNWWNN) {
5809 isp_prt(isp, ISP_LOGCONFIG, "Using Node WWN 0x%08x%08x",
5810 (uint32_t) (DEFAULT_NODEWWN(isp) >> 32),
5811 (uint32_t) (DEFAULT_NODEWWN(isp) & 0xffffffff));
5812 ISP_NODEWWN(isp) = DEFAULT_NODEWWN(isp);
5815 * We always start out with values derived
5816 * from NVRAM or our platform default.
5818 ISP_NODEWWN(isp) = fcp->isp_nodewwn;
5820 if (isp->isp_confopts & ISP_CFG_OWNWWPN) {
5821 isp_prt(isp, ISP_LOGCONFIG, "Using Port WWN 0x%08x%08x",
5822 (uint32_t) (DEFAULT_PORTWWN(isp) >> 32),
5823 (uint32_t) (DEFAULT_PORTWWN(isp) & 0xffffffff));
5824 ISP_PORTWWN(isp) = DEFAULT_PORTWWN(isp);
5827 * We always start out with values derived
5828 * from NVRAM or our platform default.
5830 ISP_PORTWWN(isp) = fcp->isp_portwwn;
5835 sdp = (sdparam *) isp->isp_param;
5839 * Been there, done that, got the T-shirt...
5841 if (sdp->isp_gotdparms) {
5844 sdp->isp_gotdparms = 1;
5847 * Establish some default parameters.
5849 sdp->isp_cmd_dma_burst_enable = 0;
5850 sdp->isp_data_dma_burst_enabl = 1;
5851 sdp->isp_fifo_threshold = 0;
5852 sdp->isp_initiator_id = DEFAULT_IID(isp);
5853 if (isp->isp_type >= ISP_HA_SCSI_1040) {
5854 sdp->isp_async_data_setup = 9;
5856 sdp->isp_async_data_setup = 6;
5858 sdp->isp_selection_timeout = 250;
5859 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
5860 sdp->isp_tag_aging = 8;
5861 sdp->isp_bus_reset_delay = 5;
5863 * Don't retry selection, busy or queue full automatically- reflect
5866 sdp->isp_retry_count = 0;
5867 sdp->isp_retry_delay = 0;
5869 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5870 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
5871 sdp->isp_devparam[tgt].dev_enable = 1;
5875 * If we've not been told to avoid reading NVRAM, try and read it.
5876 * If we're successful reading it, we can then return because NVRAM
5877 * will tell us what the desired settings are. Otherwise, we establish
5878 * some reasonable 'fake' nvram and goal defaults.
5881 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5882 if (isp_read_nvram(isp) == 0) {
5888 * Now try and see whether we have specific values for them.
5890 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5891 mbs.param[0] = MBOX_GET_ACT_NEG_STATE;
5892 isp_mboxcmd(isp, &mbs, MBLOGNONE);
5893 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
5894 sdp->isp_req_ack_active_neg = 1;
5895 sdp->isp_data_line_active_neg = 1;
5897 sdp->isp_req_ack_active_neg =
5898 (mbs.param[1+channel] >> 4) & 0x1;
5899 sdp->isp_data_line_active_neg =
5900 (mbs.param[1+channel] >> 5) & 0x1;
5904 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc3,
5905 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
5906 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
5907 sdp->isp_retry_delay, sdp->isp_async_data_setup);
5908 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc3,
5909 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
5910 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
5911 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
5914 * The trick here is to establish a default for the default (honk!)
5915 * state (goal_flags). Then try and get the current status from
5916 * the card to fill in the current state. We don't, in fact, set
5917 * the default to the SAFE default state- that's not the goal state.
5919 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5921 sdp->isp_devparam[tgt].actv_offset = 0;
5922 sdp->isp_devparam[tgt].actv_period = 0;
5923 sdp->isp_devparam[tgt].actv_flags = 0;
5925 sdp->isp_devparam[tgt].goal_flags =
5926 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
5929 * We default to Wide/Fast for versions less than a 1040
5930 * (unless it's SBus).
5932 if (IS_ULTRA3(isp)) {
5933 off = ISP_80M_SYNCPARMS >> 8;
5934 per = ISP_80M_SYNCPARMS & 0xff;
5935 } else if (IS_ULTRA2(isp)) {
5936 off = ISP_40M_SYNCPARMS >> 8;
5937 per = ISP_40M_SYNCPARMS & 0xff;
5938 } else if (IS_1240(isp)) {
5939 off = ISP_20M_SYNCPARMS >> 8;
5940 per = ISP_20M_SYNCPARMS & 0xff;
5941 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
5942 isp->isp_type < ISP_HA_SCSI_1020A) ||
5943 (isp->isp_bustype == ISP_BT_PCI &&
5944 isp->isp_type < ISP_HA_SCSI_1040) ||
5945 (isp->isp_clock && isp->isp_clock < 60) ||
5946 (sdp->isp_ultramode == 0)) {
5947 off = ISP_10M_SYNCPARMS >> 8;
5948 per = ISP_10M_SYNCPARMS & 0xff;
5950 off = ISP_20M_SYNCPARMS_1040 >> 8;
5951 per = ISP_20M_SYNCPARMS_1040 & 0xff;
5953 sdp->isp_devparam[tgt].goal_offset =
5954 sdp->isp_devparam[tgt].nvrm_offset = off;
5955 sdp->isp_devparam[tgt].goal_period =
5956 sdp->isp_devparam[tgt].nvrm_period = per;
5958 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc3,
5959 channel, tgt, sdp->isp_devparam[tgt].nvrm_flags,
5960 sdp->isp_devparam[tgt].nvrm_offset,
5961 sdp->isp_devparam[tgt].nvrm_period);
5966 * Re-initialize the ISP and complete all orphaned commands
5967 * with a 'botched' notice. The reset/init routines should
5968 * not disturb an already active list of commands.
5970 * Locks held prior to coming here.
5974 isp_reinit(ispsoftc_t *isp)
5980 isp_mark_getpdb_all(isp);
5983 if (isp->isp_state != ISP_RESETSTATE) {
5984 isp_prt(isp, ISP_LOGERR, "isp_reinit cannot reset card");
5985 } else if (isp->isp_role != ISP_ROLE_NONE) {
5987 if (isp->isp_state == ISP_INITSTATE) {
5988 isp->isp_state = ISP_RUNSTATE;
5990 if (isp->isp_state != ISP_RUNSTATE) {
5991 isp_prt(isp, ISP_LOGERR,
5992 "isp_reinit cannot restart card");
5995 isp->isp_nactive = 0;
5997 for (i = 0; i < isp->isp_maxcmds; i++) {
5999 xs = isp->isp_xflist[i];
6003 handle = isp_index_handle(i);
6004 isp_destroy_handle(isp, handle);
6005 if (XS_XFRLEN(xs)) {
6006 ISP_DMAFREE(isp, xs, handle);
6007 XS_RESID(xs) = XS_XFRLEN(xs);
6011 XS_SETERR(xs, HBA_BUSRESET);
6020 isp_read_nvram(ispsoftc_t *isp)
6023 uint8_t csum, minversion;
6025 uint8_t _x[ISP2100_NVRAM_SIZE];
6026 uint16_t _s[ISP2100_NVRAM_SIZE>>1];
6028 #define nvram_data _n._x
6029 #define nvram_words _n._s
6032 amt = ISP2100_NVRAM_SIZE;
6034 } else if (IS_ULTRA2(isp)) {
6035 amt = ISP1080_NVRAM_SIZE;
6038 amt = ISP_NVRAM_SIZE;
6043 * Just read the first two words first to see if we have a valid
6044 * NVRAM to continue reading the rest with.
6046 for (i = 0; i < 2; i++) {
6047 isp_rdnvram_word(isp, i, &nvram_words[i]);
6049 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
6050 nvram_data[2] != 'P') {
6051 if (isp->isp_bustype != ISP_BT_SBUS) {
6052 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
6053 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x",
6054 nvram_data[0], nvram_data[1], nvram_data[2]);
6058 for (i = 2; i < amt>>1; i++) {
6059 isp_rdnvram_word(isp, i, &nvram_words[i]);
6061 for (csum = 0, i = 0; i < amt; i++) {
6062 csum += nvram_data[i];
6065 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
6068 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
6069 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
6070 ISP_NVRAM_VERSION(nvram_data));
6074 if (IS_ULTRA3(isp)) {
6075 isp_parse_nvram_12160(isp, 0, nvram_data);
6077 isp_parse_nvram_12160(isp, 1, nvram_data);
6078 } else if (IS_1080(isp)) {
6079 isp_parse_nvram_1080(isp, 0, nvram_data);
6080 } else if (IS_1280(isp) || IS_1240(isp)) {
6081 isp_parse_nvram_1080(isp, 0, nvram_data);
6082 isp_parse_nvram_1080(isp, 1, nvram_data);
6083 } else if (IS_SCSI(isp)) {
6084 isp_parse_nvram_1020(isp, nvram_data);
6086 isp_parse_nvram_2100(isp, nvram_data);
6094 isp_rdnvram_word(ispsoftc_t *isp, int wo, uint16_t *rp)
6099 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
6101 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
6105 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
6106 if (IS_2312(isp) && isp->isp_port) {
6109 rqst = (ISP_NVRAM_READ << 8) | wo;
6111 } else if (IS_ULTRA2(isp)) {
6112 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
6113 rqst = (ISP_NVRAM_READ << 8) | wo;
6116 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
6117 rqst = (ISP_NVRAM_READ << 6) | wo;
6122 * Clock the word select request out...
6124 for (i = cbits; i >= 0; i--) {
6125 if ((rqst >> i) & 1) {
6126 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
6128 bit = BIU_NVRAM_SELECT;
6130 ISP_WRITE(isp, BIU_NVRAM, bit);
6132 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
6134 ISP_WRITE(isp, BIU_NVRAM, bit);
6138 * Now read the result back in (bits come back in MSB format).
6141 for (i = 0; i < 16; i++) {
6144 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
6146 rv = ISP_READ(isp, BIU_NVRAM);
6147 if (rv & BIU_NVRAM_DATAIN) {
6151 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
6154 ISP_WRITE(isp, BIU_NVRAM, 0);
6156 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
6160 isp_parse_nvram_1020(ispsoftc_t *isp, uint8_t *nvram_data)
6162 sdparam *sdp = (sdparam *) isp->isp_param;
6165 sdp->isp_fifo_threshold =
6166 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
6167 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
6169 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6170 sdp->isp_initiator_id =
6171 ISP_NVRAM_INITIATOR_ID(nvram_data);
6173 sdp->isp_bus_reset_delay =
6174 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
6176 sdp->isp_retry_count =
6177 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
6179 sdp->isp_retry_delay =
6180 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
6182 sdp->isp_async_data_setup =
6183 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
6185 if (isp->isp_type >= ISP_HA_SCSI_1040) {
6186 if (sdp->isp_async_data_setup < 9) {
6187 sdp->isp_async_data_setup = 9;
6190 if (sdp->isp_async_data_setup != 6) {
6191 sdp->isp_async_data_setup = 6;
6195 sdp->isp_req_ack_active_neg =
6196 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
6198 sdp->isp_data_line_active_neg =
6199 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
6201 sdp->isp_data_dma_burst_enabl =
6202 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
6204 sdp->isp_cmd_dma_burst_enable =
6205 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
6207 sdp->isp_tag_aging =
6208 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
6210 sdp->isp_selection_timeout =
6211 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
6213 sdp->isp_max_queue_depth =
6214 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
6216 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
6218 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6219 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6220 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6221 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6222 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6223 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6224 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6225 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6227 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6228 sdp->isp_devparam[tgt].dev_enable =
6229 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
6230 sdp->isp_devparam[tgt].exc_throttle =
6231 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
6232 sdp->isp_devparam[tgt].nvrm_offset =
6233 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
6234 sdp->isp_devparam[tgt].nvrm_period =
6235 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
6237 * We probably shouldn't lie about this, but it
6238 * it makes it much safer if we limit NVRAM values
6241 if (isp->isp_type < ISP_HA_SCSI_1040) {
6243 * If we're not ultra, we can't possibly
6244 * be a shorter period than this.
6246 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
6247 sdp->isp_devparam[tgt].nvrm_period = 0x19;
6249 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
6250 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
6253 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
6254 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
6257 sdp->isp_devparam[tgt].nvrm_flags = 0;
6258 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
6259 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6260 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6261 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
6262 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6263 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
6264 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6265 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
6266 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6267 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
6268 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6269 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
6270 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6271 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
6272 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6273 0, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6274 sdp->isp_devparam[tgt].nvrm_offset,
6275 sdp->isp_devparam[tgt].nvrm_period);
6276 sdp->isp_devparam[tgt].goal_offset =
6277 sdp->isp_devparam[tgt].nvrm_offset;
6278 sdp->isp_devparam[tgt].goal_period =
6279 sdp->isp_devparam[tgt].nvrm_period;
6280 sdp->isp_devparam[tgt].goal_flags =
6281 sdp->isp_devparam[tgt].nvrm_flags;
6286 isp_parse_nvram_1080(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
6288 sdparam *sdp = (sdparam *) isp->isp_param;
6293 sdp->isp_fifo_threshold =
6294 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
6296 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6297 sdp->isp_initiator_id =
6298 ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
6300 sdp->isp_bus_reset_delay =
6301 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6303 sdp->isp_retry_count =
6304 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6306 sdp->isp_retry_delay =
6307 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6309 sdp->isp_async_data_setup =
6310 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6312 sdp->isp_req_ack_active_neg =
6313 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6315 sdp->isp_data_line_active_neg =
6316 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6318 sdp->isp_data_dma_burst_enabl =
6319 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6321 sdp->isp_cmd_dma_burst_enable =
6322 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6324 sdp->isp_selection_timeout =
6325 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6327 sdp->isp_max_queue_depth =
6328 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6330 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6331 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6332 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6333 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6334 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6335 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6336 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6337 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6340 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6341 sdp->isp_devparam[tgt].dev_enable =
6342 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6343 sdp->isp_devparam[tgt].exc_throttle =
6344 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6345 sdp->isp_devparam[tgt].nvrm_offset =
6346 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6347 sdp->isp_devparam[tgt].nvrm_period =
6348 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6349 sdp->isp_devparam[tgt].nvrm_flags = 0;
6350 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6351 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6352 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6353 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6354 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6355 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6356 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6357 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6358 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6359 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6360 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6361 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6362 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6363 sdp->isp_devparam[tgt].actv_flags = 0;
6364 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6365 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6366 sdp->isp_devparam[tgt].nvrm_offset,
6367 sdp->isp_devparam[tgt].nvrm_period);
6368 sdp->isp_devparam[tgt].goal_offset =
6369 sdp->isp_devparam[tgt].nvrm_offset;
6370 sdp->isp_devparam[tgt].goal_period =
6371 sdp->isp_devparam[tgt].nvrm_period;
6372 sdp->isp_devparam[tgt].goal_flags =
6373 sdp->isp_devparam[tgt].nvrm_flags;
6378 isp_parse_nvram_12160(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
6380 sdparam *sdp = (sdparam *) isp->isp_param;
6385 sdp->isp_fifo_threshold =
6386 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
6388 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6389 sdp->isp_initiator_id =
6390 ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
6392 sdp->isp_bus_reset_delay =
6393 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6395 sdp->isp_retry_count =
6396 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6398 sdp->isp_retry_delay =
6399 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6401 sdp->isp_async_data_setup =
6402 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6404 sdp->isp_req_ack_active_neg =
6405 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6407 sdp->isp_data_line_active_neg =
6408 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6410 sdp->isp_data_dma_burst_enabl =
6411 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6413 sdp->isp_cmd_dma_burst_enable =
6414 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6416 sdp->isp_selection_timeout =
6417 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6419 sdp->isp_max_queue_depth =
6420 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6422 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6423 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6424 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6425 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6426 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6427 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6428 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6429 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6431 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6432 sdp->isp_devparam[tgt].dev_enable =
6433 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6434 sdp->isp_devparam[tgt].exc_throttle =
6435 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6436 sdp->isp_devparam[tgt].nvrm_offset =
6437 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6438 sdp->isp_devparam[tgt].nvrm_period =
6439 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6440 sdp->isp_devparam[tgt].nvrm_flags = 0;
6441 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6442 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6443 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6444 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6445 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6446 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6447 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6448 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6449 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6450 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6451 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6452 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6453 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6454 sdp->isp_devparam[tgt].actv_flags = 0;
6455 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6456 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6457 sdp->isp_devparam[tgt].nvrm_offset,
6458 sdp->isp_devparam[tgt].nvrm_period);
6459 sdp->isp_devparam[tgt].goal_offset =
6460 sdp->isp_devparam[tgt].nvrm_offset;
6461 sdp->isp_devparam[tgt].goal_period =
6462 sdp->isp_devparam[tgt].nvrm_period;
6463 sdp->isp_devparam[tgt].goal_flags =
6464 sdp->isp_devparam[tgt].nvrm_flags;
6469 isp_parse_nvram_2100(ispsoftc_t *isp, uint8_t *nvram_data)
6471 fcparam *fcp = (fcparam *) isp->isp_param;
6475 * There is NVRAM storage for both Port and Node entities-
6476 * but the Node entity appears to be unused on all the cards
6477 * I can find. However, we should account for this being set
6478 * at some point in the future.
6480 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
6481 * bits 48..60. In the case of the 2202, it appears that they do
6482 * use bit 48 to distinguish between the two instances on the card.
6483 * The 2204, which I've never seen, *probably* extends this method.
6485 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
6487 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
6488 (uint32_t) (wwn >> 32), (uint32_t) (wwn & 0xffffffff));
6489 if ((wwn >> 60) == 0) {
6490 wwn |= (((uint64_t) 2)<< 60);
6493 fcp->isp_portwwn = wwn;
6494 if (IS_2200(isp) || IS_23XX(isp)) {
6495 wwn = ISP2200_NVRAM_NODE_NAME(nvram_data);
6497 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
6498 (uint32_t) (wwn >> 32),
6499 (uint32_t) (wwn & 0xffffffff));
6500 if ((wwn >> 60) == 0) {
6501 wwn |= (((uint64_t) 2)<< 60);
6505 wwn &= ~((uint64_t) 0xfff << 48);
6507 fcp->isp_nodewwn = wwn;
6510 * Make sure we have both Node and Port as non-zero values.
6512 if (fcp->isp_nodewwn != 0 && fcp->isp_portwwn == 0) {
6513 fcp->isp_portwwn = fcp->isp_nodewwn;
6514 } else if (fcp->isp_nodewwn == 0 && fcp->isp_portwwn != 0) {
6515 fcp->isp_nodewwn = fcp->isp_portwwn;
6519 * Make the Node and Port values sane if they're NAA == 2.
6520 * This means to clear bits 48..56 for the Node WWN and
6521 * make sure that there's some non-zero value in 48..56
6524 if (fcp->isp_nodewwn && fcp->isp_portwwn) {
6525 if ((fcp->isp_nodewwn & (((uint64_t) 0xfff) << 48)) != 0 &&
6526 (fcp->isp_nodewwn >> 60) == 2) {
6527 fcp->isp_nodewwn &= ~((uint64_t) 0xfff << 48);
6529 if ((fcp->isp_portwwn & (((uint64_t) 0xfff) << 48)) == 0 &&
6530 (fcp->isp_portwwn >> 60) == 2) {
6531 fcp->isp_portwwn |= ((uint64_t) 1 << 56);
6535 isp_prt(isp, ISP_LOGDEBUG0,
6536 "NVRAM: maxfrmlen %d execthrottle %d fwoptions 0x%x loopid %x",
6537 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data),
6538 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
6539 ISP2100_NVRAM_OPTIONS(nvram_data),
6540 ISP2100_NVRAM_HARDLOOPID(nvram_data));
6543 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
6544 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0)
6545 fcp->isp_maxfrmlen =
6546 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
6547 fcp->isp_retry_delay =
6548 ISP2100_NVRAM_RETRY_DELAY(nvram_data);
6549 fcp->isp_retry_count =
6550 ISP2100_NVRAM_RETRY_COUNT(nvram_data);
6551 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6553 ISP2100_NVRAM_HARDLOOPID(nvram_data);
6554 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0)
6555 fcp->isp_execthrottle =
6556 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
6557 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
6560 #ifdef ISP_FW_CRASH_DUMP
6561 static void isp2200_fw_dump(ispsoftc_t *);
6562 static void isp2300_fw_dump(ispsoftc_t *);
6565 isp2200_fw_dump(ispsoftc_t *isp)
6571 MEMZERO(&mbs, sizeof (mbs));
6572 ptr = FCPARAM(isp)->isp_dump_data;
6574 isp_prt(isp, ISP_LOGERR,
6575 "No place to dump RISC registers and SRAM");
6579 isp_prt(isp, ISP_LOGERR,
6580 "dump area for RISC registers and SRAM already used");
6583 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6584 for (i = 0; i < 100; i++) {
6586 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6590 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6594 for (i = 0; i < 8; i++) {
6595 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6601 for (i = 0; i < 8; i++) {
6602 *ptr++ = ISP_READ(isp, MBOX_BLOCK + (i << 1));
6608 for (i = 0; i < 48; i++) {
6609 *ptr++ = ISP_READ(isp, DMA_BLOCK + 0x20 + (i << 1));
6613 * RISC H/W Registers
6615 ISP_WRITE(isp, BIU2100_CSR, 0);
6616 for (i = 0; i < 16; i++) {
6617 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6623 for (j = 0; j < 8; j++) {
6624 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 8));
6625 for (i = 0; i < 16; i++) {
6627 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6632 * Frame Buffer Hardware Registers
6634 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6635 for (i = 0; i < 16; i++) {
6636 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6640 * Fibre Protocol Module 0 Hardware Registers
6642 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6643 for (i = 0; i < 64; i++) {
6644 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6648 * Fibre Protocol Module 1 Hardware Registers
6650 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6651 for (i = 0; i < 64; i++) {
6652 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6655 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6658 isp_prt(isp, ISP_LOGALL,
6659 "isp_fw_dump: RISC registers dumped successfully");
6660 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6661 for (i = 0; i < 100; i++) {
6663 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6667 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6668 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6671 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6672 for (i = 0; i < 100; i++) {
6674 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6678 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6679 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause After Reset");
6682 ISP_WRITE(isp, RISC_EMB, 0xf2);
6683 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
6684 for (i = 0; i < 100; i++) {
6686 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6691 mbs.param[0] = MBOX_READ_RAM_WORD;
6692 mbs.param[1] = 0x1000;
6693 isp->isp_mbxworkp = (void *) ptr;
6694 isp->isp_mbxwrk0 = 0xefff; /* continuation count */
6695 isp->isp_mbxwrk1 = 0x1001; /* next SRAM address */
6696 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6697 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6698 isp_prt(isp, ISP_LOGWARN,
6699 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6702 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6703 *ptr++ = isp->isp_mboxtmp[2];
6704 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
6705 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6706 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6710 isp2300_fw_dump(ispsoftc_t *isp)
6716 MEMZERO(&mbs, sizeof (mbs));
6717 ptr = FCPARAM(isp)->isp_dump_data;
6719 isp_prt(isp, ISP_LOGERR,
6720 "No place to dump RISC registers and SRAM");
6724 isp_prt(isp, ISP_LOGERR,
6725 "dump area for RISC registers and SRAM already used");
6728 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6729 for (i = 0; i < 100; i++) {
6731 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6735 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6739 for (i = 0; i < 8; i++) {
6740 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6744 * ReqQ-RspQ-Risc2Host Status registers
6746 for (i = 0; i < 8; i++) {
6747 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x10 + (i << 1));
6753 for (i = 0; i < 32; i++) {
6755 ISP_READ(isp, PCI_MBOX_REGS2300_OFF + (i << 1));
6759 * Auto Request Response DMA registers
6761 ISP_WRITE(isp, BIU2100_CSR, 0x40);
6762 for (i = 0; i < 32; i++) {
6763 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6769 ISP_WRITE(isp, BIU2100_CSR, 0x50);
6770 for (i = 0; i < 48; i++) {
6771 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6775 * RISC hardware registers
6777 ISP_WRITE(isp, BIU2100_CSR, 0);
6778 for (i = 0; i < 16; i++) {
6779 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6783 * RISC GP? registers
6785 for (j = 0; j < 8; j++) {
6786 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 9));
6787 for (i = 0; i < 16; i++) {
6789 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6794 * frame buffer hardware registers
6796 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6797 for (i = 0; i < 64; i++) {
6798 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6802 * FPM B0 hardware registers
6804 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6805 for (i = 0; i < 64; i++) {
6806 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6810 * FPM B1 hardware registers
6812 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6813 for (i = 0; i < 64; i++) {
6814 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6817 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6820 isp_prt(isp, ISP_LOGALL,
6821 "isp_fw_dump: RISC registers dumped successfully");
6822 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6823 for (i = 0; i < 100; i++) {
6825 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6829 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6830 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6834 mbs.param[0] = MBOX_READ_RAM_WORD;
6835 mbs.param[1] = 0x800;
6836 isp->isp_mbxworkp = (void *) ptr;
6837 isp->isp_mbxwrk0 = 0xf7ff; /* continuation count */
6838 isp->isp_mbxwrk1 = 0x801; /* next SRAM address */
6839 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6840 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6841 isp_prt(isp, ISP_LOGWARN,
6842 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6845 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6846 *ptr++ = isp->isp_mboxtmp[2];
6849 * We don't have access to mailbox registers 8.. onward
6850 * in our 'common' device model- so we have to set it
6851 * here and hope it stays the same!
6853 ISP_WRITE(isp, PCI_MBOX_REGS2300_OFF + (8 << 1), 0x1);
6855 mbs.param[0] = MBOX_READ_RAM_WORD_EXTENDED;
6857 isp->isp_mbxworkp = (void *) ptr;
6858 isp->isp_mbxwrk0 = 0xffff; /* continuation count */
6859 isp->isp_mbxwrk1 = 0x1; /* next SRAM address */
6860 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6861 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6862 isp_prt(isp, ISP_LOGWARN,
6863 "RAM DUMP FAILED @ WORD %x", 0x10000 + isp->isp_mbxwrk1);
6866 ptr = isp->isp_mbxworkp; /* finish final word */
6867 *ptr++ = mbs.param[2];
6868 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
6869 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6870 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6874 isp_fw_dump(ispsoftc_t *isp)
6877 isp2200_fw_dump(isp);
6878 else if (IS_23XX(isp))
6879 isp2300_fw_dump(isp);