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 = (arg)? *((int *) arg) : 250000;
3519 return (isp_fclink_test(isp, usdelay));
3523 case ISPCTL_SCAN_FABRIC:
3526 int ftype = (arg)? *((int *) arg) : FC4_SCSI;
3527 return (isp_scan_fabric(isp, ftype));
3531 case ISPCTL_SCAN_LOOP:
3534 return (isp_scan_loop(isp));
3538 case ISPCTL_PDB_SYNC:
3541 return (isp_pdb_sync(isp));
3545 case ISPCTL_SEND_LIP:
3548 mbs.param[0] = MBOX_INIT_LIP;
3549 isp_mboxcmd(isp, &mbs, MBLOGALL);
3550 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3556 case ISPCTL_GET_POSMAP:
3558 if (IS_FC(isp) && arg) {
3559 return (isp_getmap(isp, arg));
3564 case ISPCTL_GET_PDB:
3565 if (IS_FC(isp) && arg) {
3566 int id = *((int *)arg);
3567 isp_pdb_t *pdb = arg;
3568 return (isp_getpdb(isp, id, pdb));
3572 case ISPCTL_RUN_MBOXCMD:
3574 isp_mboxcmd(isp, arg, MBLOGALL);
3577 #ifdef ISP_TARGET_MODE
3578 case ISPCTL_TOGGLE_TMODE:
3582 * We don't check/set against role here- that's the
3583 * responsibility for the outer layer to coordinate.
3586 int param = *(int *)arg;
3587 mbs.param[0] = MBOX_ENABLE_TARGET_MODE;
3588 mbs.param[1] = param & 0xffff;
3589 mbs.param[2] = param >> 16;
3590 isp_mboxcmd(isp, &mbs, MBLOGALL);
3591 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3603 * Interrupt Service Routine(s).
3605 * External (OS) framework has done the appropriate locking,
3606 * and the locking will be held throughout this function.
3610 * Limit our stack depth by sticking with the max likely number
3611 * of completions on a request queue at any one time.
3613 #ifndef MAX_REQUESTQ_COMPLETIONS
3614 #define MAX_REQUESTQ_COMPLETIONS 64
3618 isp_intr(ispsoftc_t *isp, uint16_t isr, uint16_t sema, uint16_t mbox)
3620 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
3621 uint16_t iptr, optr, junk;
3622 int i, nlooked = 0, ndone = 0;
3626 * Is this a mailbox related interrupt?
3627 * The mailbox semaphore will be nonzero if so.
3630 if (mbox & 0x4000) {
3631 isp->isp_intmboxc++;
3632 if (isp->isp_mboxbsy) {
3633 int i = 0, obits = isp->isp_obits;
3634 isp->isp_mboxtmp[i++] = mbox;
3635 for (i = 1; i < MAX_MAILBOX(isp); i++) {
3636 if ((obits & (1 << i)) == 0) {
3639 isp->isp_mboxtmp[i] =
3640 ISP_READ(isp, MBOX_OFF(i));
3642 if (isp->isp_mbxwrk0) {
3643 if (isp_mbox_continue(isp) == 0) {
3647 MBOX_NOTIFY_COMPLETE(isp);
3649 isp_prt(isp, ISP_LOGWARN,
3650 "Mbox Command Async (0x%x) with no waiters",
3653 } else if (isp_parse_async(isp, mbox) < 0) {
3656 if ((IS_FC(isp) && mbox != ASYNC_RIO_RESP) ||
3657 isp->isp_state != ISP_RUNSTATE) {
3658 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3659 ISP_WRITE(isp, BIU_SEMA, 0);
3665 * We can't be getting this now.
3667 if (isp->isp_state != ISP_RUNSTATE) {
3668 isp_prt(isp, ISP_LOGWARN,
3669 "interrupt (ISR=%x SEMA=%x) when not ready", isr, sema);
3671 * Thank you very much! *Burrrp*!
3673 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp,
3674 READ_RESPONSE_QUEUE_IN_POINTER(isp));
3676 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3677 ISP_WRITE(isp, BIU_SEMA, 0);
3682 * Get the current Response Queue Out Pointer.
3684 * If we're a 2300, we can ask what hardware what it thinks.
3687 optr = ISP_READ(isp, isp->isp_respoutrp);
3689 * Debug: to be taken out eventually
3691 if (isp->isp_residx != optr) {
3692 isp_prt(isp, ISP_LOGWARN, "optr %x soft optr %x",
3693 optr, isp->isp_residx);
3696 optr = isp->isp_residx;
3700 * You *must* read the Response Queue In Pointer
3701 * prior to clearing the RISC interrupt.
3703 * Debounce the 2300 if revision less than 2.
3705 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
3708 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3709 junk = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3710 } while (junk != iptr && ++i < 1000);
3713 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3714 isp_prt(isp, ISP_LOGWARN,
3715 "Response Queue Out Pointer Unstable (%x, %x)",
3720 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3722 isp->isp_resodx = iptr;
3725 if (optr == iptr && sema == 0) {
3727 * There are a lot of these- reasons unknown- mostly on
3728 * faster Alpha machines.
3730 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
3731 * make sure the old interrupt went away (to avoid 'ringing'
3732 * effects), but that didn't stop this from occurring.
3736 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3737 junk = ISP_READ(isp, BIU_R2HSTSLO);
3739 junk = ISP_READ(isp, BIU_ISR);
3745 sema = ISP_READ(isp, BIU_SEMA);
3746 mbox = ISP_READ(isp, OUTMAILBOX0);
3747 if ((sema & 0x3) && (mbox & 0x8000)) {
3751 isp->isp_intbogus++;
3752 isp_prt(isp, ISP_LOGDEBUG1,
3753 "bogus intr- isr %x (%x) iptr %x optr %x",
3754 isr, junk, iptr, optr);
3757 isp->isp_resodx = iptr;
3758 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3759 ISP_WRITE(isp, BIU_SEMA, 0);
3761 if (isp->isp_rspbsy) {
3764 isp->isp_rspbsy = 1;
3766 while (optr != iptr) {
3767 ispstatusreq_t local, *sp = &local;
3773 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
3775 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
3779 * Synchronize our view of this response queue entry.
3781 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN);
3783 type = isp_get_response_type(isp, hp);
3785 if (type == RQSTYPE_RESPONSE) {
3786 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3787 } else if (type == RQSTYPE_RIO2) {
3789 isp_get_rio2(isp, (isp_rio2_t *) hp, &rio);
3790 for (i = 0; i < rio.req_header.rqs_seqno; i++) {
3791 isp_fastpost_complete(isp, rio.req_handles[i]);
3793 if (isp->isp_fpcchiwater < rio.req_header.rqs_seqno)
3794 isp->isp_fpcchiwater = rio.req_header.rqs_seqno;
3795 MEMZERO(hp, QENTRY_LEN); /* PERF */
3799 * Somebody reachable via isp_handle_other_response
3800 * may have updated the response queue pointers for
3801 * us, so we reload our goal index.
3803 int i = isp_handle_other_response(isp, type, hp, &optr);
3807 iptr = isp->isp_resodx;
3808 MEMZERO(hp, QENTRY_LEN); /* PERF */
3813 * After this point, we'll just look at the header as
3814 * we don't know how to deal with the rest of the
3817 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3820 * It really has to be a bounced request just copied
3821 * from the request queue to the response queue. If
3822 * not, something bad has happened.
3824 if (sp->req_header.rqs_entry_type != RQSTYPE_REQUEST) {
3825 isp_prt(isp, ISP_LOGERR, notresp,
3826 sp->req_header.rqs_entry_type, oop, optr,
3828 if (isp->isp_dblev & ISP_LOGDEBUG0) {
3829 isp_print_bytes(isp, "Queue Entry",
3832 MEMZERO(hp, QENTRY_LEN); /* PERF */
3838 if (sp->req_header.rqs_flags & 0xf) {
3839 #define _RQS_OFLAGS \
3840 ~(RQSFLAG_CONTINUATION|RQSFLAG_FULL|RQSFLAG_BADHEADER|RQSFLAG_BADPACKET)
3841 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
3842 isp_prt(isp, ISP_LOGWARN,
3843 "continuation segment");
3844 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3847 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3848 isp_prt(isp, ISP_LOGDEBUG1,
3849 "internal queues full");
3851 * We'll synthesize a QUEUE FULL message below.
3854 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
3855 isp_prt(isp, ISP_LOGERR, "bad header flag");
3858 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
3859 isp_prt(isp, ISP_LOGERR, "bad request packet");
3862 if (sp->req_header.rqs_flags & _RQS_OFLAGS) {
3863 isp_prt(isp, ISP_LOGERR,
3864 "unknown flags (0x%x) in response",
3865 sp->req_header.rqs_flags);
3870 if (sp->req_handle > isp->isp_maxcmds || sp->req_handle < 1) {
3871 MEMZERO(hp, QENTRY_LEN); /* PERF */
3872 isp_prt(isp, ISP_LOGERR,
3873 "bad request handle %d (type 0x%x, flags 0x%x)",
3874 sp->req_handle, sp->req_header.rqs_entry_type,
3875 sp->req_header.rqs_flags);
3876 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3879 xs = isp_find_xs(isp, sp->req_handle);
3881 uint8_t ts = sp->req_completion_status & 0xff;
3882 MEMZERO(hp, QENTRY_LEN); /* PERF */
3884 * Only whine if this isn't the expected fallout of
3885 * aborting the command.
3887 if (sp->req_header.rqs_entry_type != RQSTYPE_RESPONSE) {
3888 isp_prt(isp, ISP_LOGERR,
3889 "cannot find handle 0x%x (type 0x%x)",
3891 sp->req_header.rqs_entry_type);
3892 } else if (ts != RQCS_ABORTED) {
3893 isp_prt(isp, ISP_LOGERR,
3894 "cannot find handle 0x%x (status 0x%x)",
3895 sp->req_handle, ts);
3897 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3900 isp_destroy_handle(isp, sp->req_handle);
3901 if (sp->req_status_flags & RQSTF_BUS_RESET) {
3902 XS_SETERR(xs, HBA_BUSRESET);
3903 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
3906 XS_SETERR(xs, HBA_BOTCH);
3909 if (IS_FC(isp) && (sp->req_scsi_status & RQCS_SV)) {
3911 * Fibre Channel F/W doesn't say we got status
3912 * if there's Sense Data instead. I guess they
3913 * think it goes w/o saying.
3915 sp->req_state_flags |= RQSF_GOT_STATUS;
3917 if (sp->req_state_flags & RQSF_GOT_STATUS) {
3918 *XS_STSP(xs) = sp->req_scsi_status & 0xff;
3921 switch (sp->req_header.rqs_entry_type) {
3922 case RQSTYPE_RESPONSE:
3923 XS_SET_STATE_STAT(isp, xs, sp);
3924 isp_parse_status(isp, sp, xs);
3925 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) &&
3926 (*XS_STSP(xs) == SCSI_BUSY)) {
3927 XS_SETERR(xs, HBA_TGTBSY);
3930 XS_RESID(xs) = sp->req_resid;
3931 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3932 (*XS_STSP(xs) == SCSI_CHECK) &&
3933 (sp->req_state_flags & RQSF_GOT_SENSE)) {
3934 XS_SAVE_SENSE(xs, sp);
3937 * A new synchronous rate was negotiated for
3938 * this target. Mark state such that we'll go
3939 * look up that which has changed later.
3941 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
3943 sdparam *sdp = isp->isp_param;
3944 sdp += XS_CHANNEL(xs);
3945 sdp->isp_devparam[t].dev_refresh = 1;
3947 (1 << XS_CHANNEL(xs));
3950 if (sp->req_status_flags & RQSF_XFER_COMPLETE) {
3952 } else if (sp->req_scsi_status & RQCS_RESID) {
3953 XS_RESID(xs) = sp->req_resid;
3957 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3958 (*XS_STSP(xs) == SCSI_CHECK) &&
3959 (sp->req_scsi_status & RQCS_SV)) {
3960 XS_SAVE_SENSE(xs, sp);
3961 /* solely for the benefit of debug */
3962 sp->req_state_flags |= RQSF_GOT_SENSE;
3965 isp_prt(isp, ISP_LOGDEBUG2,
3966 "asked for %ld got resid %ld", (long) XS_XFRLEN(xs),
3967 (long) sp->req_resid);
3969 case RQSTYPE_REQUEST:
3970 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3972 * Force Queue Full status.
3974 *XS_STSP(xs) = SCSI_QFULL;
3975 XS_SETERR(xs, HBA_NOERROR);
3976 } else if (XS_NOERR(xs)) {
3980 isp_prt(isp, ISP_LOGDEBUG0,
3981 "Request Queue Entry bounced back");
3982 XS_SETERR(xs, HBA_BOTCH);
3984 XS_RESID(xs) = XS_XFRLEN(xs);
3987 isp_prt(isp, ISP_LOGWARN,
3988 "unhandled response queue type 0x%x",
3989 sp->req_header.rqs_entry_type);
3991 XS_SETERR(xs, HBA_BOTCH);
3997 * Free any DMA resources. As a side effect, this may
3998 * also do any cache flushing necessary for data coherence. */
3999 if (XS_XFRLEN(xs)) {
4000 ISP_DMAFREE(isp, xs, sp->req_handle);
4003 if (((isp->isp_dblev & (ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
4004 ((isp->isp_dblev & ISP_LOGDEBUG1) && ((!XS_NOERR(xs)) ||
4005 (*XS_STSP(xs) != SCSI_GOOD)))) {
4007 if (sp->req_state_flags & RQSF_GOT_SENSE) {
4008 skey = XS_SNSKEY(xs) & 0xf;
4013 } else if (*XS_STSP(xs) == SCSI_CHECK) {
4018 isp_prt(isp, ISP_LOGALL, finmsg, XS_CHANNEL(xs),
4019 XS_TGT(xs), XS_LUN(xs), XS_XFRLEN(xs), XS_RESID(xs),
4020 *XS_STSP(xs), skey, XS_ERR(xs));
4023 if (isp->isp_nactive > 0)
4025 complist[ndone++] = xs; /* defer completion call until later */
4026 MEMZERO(hp, QENTRY_LEN); /* PERF */
4027 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
4033 * If we looked at any commands, then it's valid to find out
4034 * what the outpointer is. It also is a trigger to update the
4035 * ISP's notion of what we've seen so far.
4038 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
4040 * While we're at it, read the requst queue out pointer.
4042 isp->isp_reqodx = READ_REQUEST_QUEUE_OUT_POINTER(isp);
4043 if (isp->isp_rscchiwater < ndone)
4044 isp->isp_rscchiwater = ndone;
4047 isp->isp_residx = optr;
4048 isp->isp_rspbsy = 0;
4049 for (i = 0; i < ndone; i++) {
4052 isp->isp_rsltccmplt++;
4063 isp_parse_async(ispsoftc_t *isp, uint16_t mbox)
4068 if (IS_DUALBUS(isp)) {
4069 bus = ISP_READ(isp, OUTMAILBOX6);
4073 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
4076 case ASYNC_BUS_RESET:
4077 isp->isp_sendmarker |= (1 << bus);
4078 #ifdef ISP_TARGET_MODE
4079 if (isp_target_async(isp, bus, mbox))
4082 isp_async(isp, ISPASYNC_BUS_RESET, &bus);
4084 case ASYNC_SYSTEM_ERROR:
4085 #ifdef ISP_FW_CRASH_DUMP
4087 * If we have crash dumps enabled, it's up to the handler
4088 * for isp_async to reinit stuff and restart the firmware
4089 * after performing the crash dump. The reason we do things
4090 * this way is that we may need to activate a kernel thread
4091 * to do all the crash dump goop.
4093 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4095 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4097 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4102 case ASYNC_RQS_XFER_ERR:
4103 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
4106 case ASYNC_RSP_XFER_ERR:
4107 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
4112 * We've just been notified that the Queue has woken up.
4113 * We don't need to be chatty about this- just unlatch things
4116 mbox = READ_REQUEST_QUEUE_OUT_POINTER(isp);
4119 case ASYNC_TIMEOUT_RESET:
4120 isp_prt(isp, ISP_LOGWARN,
4121 "timeout initiated SCSI bus reset of bus %d", bus);
4122 isp->isp_sendmarker |= (1 << bus);
4123 #ifdef ISP_TARGET_MODE
4124 if (isp_target_async(isp, bus, mbox))
4129 case ASYNC_DEVICE_RESET:
4130 isp_prt(isp, ISP_LOGINFO, "device reset on bus %d", bus);
4131 isp->isp_sendmarker |= (1 << bus);
4132 #ifdef ISP_TARGET_MODE
4133 if (isp_target_async(isp, bus, mbox))
4138 case ASYNC_EXTMSG_UNDERRUN:
4139 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
4142 case ASYNC_SCAM_INT:
4143 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
4146 case ASYNC_HUNG_SCSI:
4147 isp_prt(isp, ISP_LOGERR,
4148 "stalled SCSI Bus after DATA Overrun");
4149 /* XXX: Need to issue SCSI reset at this point */
4152 case ASYNC_KILLED_BUS:
4153 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
4156 case ASYNC_BUS_TRANSIT:
4157 mbox = ISP_READ(isp, OUTMAILBOX2);
4158 switch (mbox & 0x1c00) {
4159 case SXP_PINS_LVD_MODE:
4160 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
4161 SDPARAM(isp)->isp_diffmode = 0;
4162 SDPARAM(isp)->isp_ultramode = 0;
4163 SDPARAM(isp)->isp_lvdmode = 1;
4165 case SXP_PINS_HVD_MODE:
4166 isp_prt(isp, ISP_LOGINFO,
4167 "Transition to Differential mode");
4168 SDPARAM(isp)->isp_diffmode = 1;
4169 SDPARAM(isp)->isp_ultramode = 0;
4170 SDPARAM(isp)->isp_lvdmode = 0;
4172 case SXP_PINS_SE_MODE:
4173 isp_prt(isp, ISP_LOGINFO,
4174 "Transition to Single Ended mode");
4175 SDPARAM(isp)->isp_diffmode = 0;
4176 SDPARAM(isp)->isp_ultramode = 1;
4177 SDPARAM(isp)->isp_lvdmode = 0;
4180 isp_prt(isp, ISP_LOGWARN,
4181 "Transition to Unknown Mode 0x%x", mbox);
4185 * XXX: Set up to renegotiate again!
4187 /* Can only be for a 1080... */
4188 isp->isp_sendmarker |= (1 << bus);
4192 * We can use bus, which will always be zero for FC cards,
4193 * as a mailbox pattern accumulator to be checked below.
4196 bus = 0x1ce; /* outgoing mailbox regs 1-3, 6-7 */
4200 bus = 0x14e; /* outgoing mailbox regs 1-3, 6 */
4204 bus = 0x10e; /* outgoing mailbox regs 1-3 */
4208 bus = 0x106; /* outgoing mailbox regs 1-2 */
4212 case ASYNC_CMD_CMPLT:
4213 bus = 0x102; /* outgoing mailbox regs 1 */
4216 case ASYNC_RIO_RESP:
4219 case ASYNC_CTIO_DONE:
4221 #ifdef ISP_TARGET_MODE
4223 (ISP_READ(isp, OUTMAILBOX2) << 16) |
4224 (ISP_READ(isp, OUTMAILBOX1));
4225 if (isp_target_async(isp, handle, mbox)) {
4228 /* count it as a fast posting intr */
4229 isp->isp_fphccmplt++;
4232 isp_prt(isp, ISP_LOGINFO, "Fast Posting CTIO done");
4233 isp->isp_fphccmplt++; /* count it as a fast posting intr */
4238 case ASYNC_LIP_OCCURRED:
4239 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4240 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4241 isp->isp_sendmarker = 1;
4242 isp_mark_getpdb_all(isp);
4243 isp_async(isp, ISPASYNC_LIP, NULL);
4244 #ifdef ISP_TARGET_MODE
4245 if (isp_target_async(isp, bus, mbox))
4249 * We've had problems with data corruption occuring on
4250 * commands that complete (with no apparent error) after
4251 * we receive a LIP. This has been observed mostly on
4252 * Local Loop topologies. To be safe, let's just mark
4253 * all active commands as dead.
4255 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4256 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4258 for (i = j = 0; i < isp->isp_maxcmds; i++) {
4260 xs = isp->isp_xflist[i];
4263 XS_SETERR(xs, HBA_BUSRESET);
4267 isp_prt(isp, ISP_LOGERR,
4268 "LIP destroyed %d active commands", j);
4274 isp->isp_sendmarker = 1;
4275 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4276 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4277 isp_mark_getpdb_all(isp);
4278 isp_async(isp, ISPASYNC_LOOP_UP, NULL);
4279 #ifdef ISP_TARGET_MODE
4280 if (isp_target_async(isp, bus, mbox))
4285 case ASYNC_LOOP_DOWN:
4286 isp->isp_sendmarker = 1;
4287 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4288 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4289 isp_mark_getpdb_all(isp);
4290 isp_async(isp, ISPASYNC_LOOP_DOWN, NULL);
4291 #ifdef ISP_TARGET_MODE
4292 if (isp_target_async(isp, bus, mbox))
4297 case ASYNC_LOOP_RESET:
4298 isp->isp_sendmarker = 1;
4299 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4300 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4301 isp_mark_getpdb_all(isp);
4302 isp_async(isp, ISPASYNC_LOOP_RESET, NULL);
4303 #ifdef ISP_TARGET_MODE
4304 if (isp_target_async(isp, bus, mbox))
4309 case ASYNC_PDB_CHANGED:
4310 isp->isp_sendmarker = 1;
4311 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4312 isp_mark_getpdb_all(isp);
4313 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_PDB);
4316 case ASYNC_CHANGE_NOTIFY:
4318 * Not correct, but it will force us to rescan the loop.
4320 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4321 isp_mark_getpdb_all(isp);
4322 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_SNS);
4326 if (FCPARAM(isp)->isp_onfabric)
4327 FCPARAM(isp)->isp_topo = TOPO_F_PORT;
4329 FCPARAM(isp)->isp_topo = TOPO_N_PORT;
4330 isp_mark_getpdb_all(isp);
4331 isp->isp_sendmarker = 1;
4332 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4333 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4334 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4335 #ifdef ISP_TARGET_MODE
4336 if (isp_target_async(isp, bus, mbox))
4339 isp_prt(isp, ISP_LOGINFO, "Point-to-Point mode");
4342 case ASYNC_CONNMODE:
4343 mbox = ISP_READ(isp, OUTMAILBOX1);
4344 isp_mark_getpdb_all(isp);
4347 isp_prt(isp, ISP_LOGINFO,
4348 "Point-to-Point -> Loop mode");
4351 isp_prt(isp, ISP_LOGINFO,
4352 "Loop -> Point-to-Point mode");
4354 case ISP_CONN_BADLIP:
4355 isp_prt(isp, ISP_LOGWARN,
4356 "Point-to-Point -> Loop mode (BAD LIP)");
4358 case ISP_CONN_FATAL:
4359 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
4360 #ifdef ISP_FW_CRASH_DUMP
4361 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4363 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4365 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4368 case ISP_CONN_LOOPBACK:
4369 isp_prt(isp, ISP_LOGWARN,
4370 "Looped Back in Point-to-Point mode");
4373 isp_prt(isp, ISP_LOGWARN,
4374 "Unknown connection mode (0x%x)", mbox);
4377 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4378 isp->isp_sendmarker = 1;
4379 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4380 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4384 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
4390 uint16_t handles[16];
4392 for (nh = 0, i = 1; i < MAX_MAILBOX(isp); i++) {
4393 if ((bus & (1 << i)) == 0) {
4396 handles[nh++] = ISP_READ(isp, MBOX_OFF(i));
4398 for (i = 0; i < nh; i++) {
4399 isp_fastpost_complete(isp, handles[i]);
4400 isp_prt(isp, ISP_LOGDEBUG3,
4401 "fast post completion of %u", handles[i]);
4403 if (isp->isp_fpcchiwater < nh)
4404 isp->isp_fpcchiwater = nh;
4406 isp->isp_intoasync++;
4412 * Handle other response entries. A pointer to the request queue output
4413 * index is here in case we want to eat several entries at once, although
4414 * this is not used currently.
4418 isp_handle_other_response(ispsoftc_t *isp, int type,
4419 isphdr_t *hp, uint16_t *optrp)
4422 case RQSTYPE_STATUS_CONT:
4423 isp_prt(isp, ISP_LOGINFO, "Ignored Continuation Response");
4427 case RQSTYPE_ENABLE_LUN:
4428 case RQSTYPE_MODIFY_LUN:
4429 case RQSTYPE_NOTIFY:
4430 case RQSTYPE_NOTIFY_ACK:
4435 isp->isp_rsltccmplt++; /* count as a response completion */
4436 #ifdef ISP_TARGET_MODE
4437 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
4442 case RQSTYPE_REQUEST:
4445 if (type != isp_get_response_type(isp, hp)) {
4447 * This is questionable- we're just papering over
4448 * something we've seen on SMP linux in target
4449 * mode- we don't really know what's happening
4450 * here that causes us to think we've gotten
4451 * an entry, but that either the entry isn't
4452 * filled out yet or our CPU read data is stale.
4454 isp_prt(isp, ISP_LOGINFO,
4455 "unstable type in response queue");
4458 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
4459 isp_get_response_type(isp, hp));
4460 if (isp_async(isp, ISPASYNC_UNHANDLED_RESPONSE, hp)) {
4468 isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs)
4470 switch (sp->req_completion_status & 0xff) {
4473 XS_SETERR(xs, HBA_NOERROR);
4477 case RQCS_INCOMPLETE:
4478 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
4479 isp_prt(isp, ISP_LOGDEBUG1,
4480 "Selection Timeout for %d.%d.%d",
4481 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4483 XS_SETERR(xs, HBA_SELTIMEOUT);
4487 isp_prt(isp, ISP_LOGERR,
4488 "command incomplete for %d.%d.%d, state 0x%x",
4489 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
4490 sp->req_state_flags);
4493 case RQCS_DMA_ERROR:
4494 isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
4495 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4498 case RQCS_TRANSPORT_ERROR:
4501 SNPRINTF(buf, sizeof (buf), "states=>");
4502 if (sp->req_state_flags & RQSF_GOT_BUS) {
4503 SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
4505 if (sp->req_state_flags & RQSF_GOT_TARGET) {
4506 SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
4508 if (sp->req_state_flags & RQSF_SENT_CDB) {
4509 SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
4511 if (sp->req_state_flags & RQSF_XFRD_DATA) {
4512 SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
4514 if (sp->req_state_flags & RQSF_GOT_STATUS) {
4515 SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
4517 if (sp->req_state_flags & RQSF_GOT_SENSE) {
4518 SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
4520 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
4521 SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
4523 SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
4524 if (sp->req_status_flags & RQSTF_DISCONNECT) {
4525 SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
4527 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
4528 SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
4530 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
4531 SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
4533 if (sp->req_status_flags & RQSTF_BUS_RESET) {
4534 SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
4536 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
4537 SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
4539 if (sp->req_status_flags & RQSTF_ABORTED) {
4540 SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
4542 if (sp->req_status_flags & RQSTF_TIMEOUT) {
4543 SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
4545 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
4546 SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
4548 isp_prt(isp, ISP_LOGERR, "%s", buf);
4549 isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d:\n%s",
4550 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), buf);
4553 case RQCS_RESET_OCCURRED:
4554 isp_prt(isp, ISP_LOGWARN,
4555 "bus reset destroyed command for %d.%d.%d",
4556 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4557 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4559 XS_SETERR(xs, HBA_BUSRESET);
4564 isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
4565 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4566 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4568 XS_SETERR(xs, HBA_ABORTED);
4573 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
4574 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4576 * Check to see if we logged out the device.
4579 if ((sp->req_completion_status & RQSTF_LOGOUT) &&
4580 FCPARAM(isp)->portdb[XS_TGT(xs)].valid &&
4581 FCPARAM(isp)->portdb[XS_TGT(xs)].fabric_dev) {
4582 FCPARAM(isp)->portdb[XS_TGT(xs)].relogin = 1;
4586 XS_SETERR(xs, HBA_CMDTIMEOUT);
4590 case RQCS_DATA_OVERRUN:
4591 XS_RESID(xs) = sp->req_resid;
4592 isp_prt(isp, ISP_LOGERR, "data overrun for command on %d.%d.%d",
4593 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4595 XS_SETERR(xs, HBA_DATAOVR);
4599 case RQCS_COMMAND_OVERRUN:
4600 isp_prt(isp, ISP_LOGERR,
4601 "command overrun for command on %d.%d.%d",
4602 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4605 case RQCS_STATUS_OVERRUN:
4606 isp_prt(isp, ISP_LOGERR,
4607 "status overrun for command on %d.%d.%d",
4608 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4611 case RQCS_BAD_MESSAGE:
4612 isp_prt(isp, ISP_LOGERR,
4613 "msg not COMMAND COMPLETE after status %d.%d.%d",
4614 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4617 case RQCS_NO_MESSAGE_OUT:
4618 isp_prt(isp, ISP_LOGERR,
4619 "No MESSAGE OUT phase after selection on %d.%d.%d",
4620 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4623 case RQCS_EXT_ID_FAILED:
4624 isp_prt(isp, ISP_LOGERR, "EXTENDED IDENTIFY failed %d.%d.%d",
4625 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4628 case RQCS_IDE_MSG_FAILED:
4629 isp_prt(isp, ISP_LOGERR,
4630 "INITIATOR DETECTED ERROR rejected by %d.%d.%d",
4631 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4634 case RQCS_ABORT_MSG_FAILED:
4635 isp_prt(isp, ISP_LOGERR, "ABORT OPERATION rejected by %d.%d.%d",
4636 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4639 case RQCS_REJECT_MSG_FAILED:
4640 isp_prt(isp, ISP_LOGERR, "MESSAGE REJECT rejected by %d.%d.%d",
4641 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4644 case RQCS_NOP_MSG_FAILED:
4645 isp_prt(isp, ISP_LOGERR, "NOP rejected by %d.%d.%d",
4646 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4649 case RQCS_PARITY_ERROR_MSG_FAILED:
4650 isp_prt(isp, ISP_LOGERR,
4651 "MESSAGE PARITY ERROR rejected by %d.%d.%d",
4652 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4655 case RQCS_DEVICE_RESET_MSG_FAILED:
4656 isp_prt(isp, ISP_LOGWARN,
4657 "BUS DEVICE RESET rejected by %d.%d.%d",
4658 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4661 case RQCS_ID_MSG_FAILED:
4662 isp_prt(isp, ISP_LOGERR, "IDENTIFY rejected by %d.%d.%d",
4663 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4666 case RQCS_UNEXP_BUS_FREE:
4667 isp_prt(isp, ISP_LOGERR, "%d.%d.%d had an unexpected bus free",
4668 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4671 case RQCS_DATA_UNDERRUN:
4674 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
4675 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
4676 isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
4677 XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
4678 (ru_marked)? "marked" : "not marked");
4680 XS_SETERR(xs, HBA_BOTCH);
4685 XS_RESID(xs) = sp->req_resid;
4687 XS_SETERR(xs, HBA_NOERROR);
4692 case RQCS_XACT_ERR1:
4693 isp_prt(isp, ISP_LOGERR, xact1, XS_CHANNEL(xs),
4694 XS_TGT(xs), XS_LUN(xs));
4697 case RQCS_XACT_ERR2:
4698 isp_prt(isp, ISP_LOGERR, xact2,
4699 XS_LUN(xs), XS_TGT(xs), XS_CHANNEL(xs));
4702 case RQCS_XACT_ERR3:
4703 isp_prt(isp, ISP_LOGERR, xact3,
4704 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4707 case RQCS_BAD_ENTRY:
4708 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
4711 case RQCS_QUEUE_FULL:
4712 isp_prt(isp, ISP_LOGDEBUG0,
4713 "internal queues full for %d.%d.%d status 0x%x",
4714 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), *XS_STSP(xs));
4717 * If QFULL or some other status byte is set, then this
4718 * isn't an error, per se.
4720 * Unfortunately, some QLogic f/w writers have, in
4721 * some cases, ommitted to *set* status to QFULL.
4724 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
4725 XS_SETERR(xs, HBA_NOERROR);
4733 *XS_STSP(xs) = SCSI_QFULL;
4734 XS_SETERR(xs, HBA_NOERROR);
4737 case RQCS_PHASE_SKIPPED:
4738 isp_prt(isp, ISP_LOGERR, pskip, XS_CHANNEL(xs),
4739 XS_TGT(xs), XS_LUN(xs));
4742 case RQCS_ARQS_FAILED:
4743 isp_prt(isp, ISP_LOGERR,
4744 "Auto Request Sense failed for %d.%d.%d",
4745 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4747 XS_SETERR(xs, HBA_ARQFAIL);
4751 case RQCS_WIDE_FAILED:
4752 isp_prt(isp, ISP_LOGERR,
4753 "Wide Negotiation failed for %d.%d.%d",
4754 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4756 sdparam *sdp = isp->isp_param;
4757 sdp += XS_CHANNEL(xs);
4758 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
4759 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4760 isp->isp_update |= (1 << XS_CHANNEL(xs));
4763 XS_SETERR(xs, HBA_NOERROR);
4767 case RQCS_SYNCXFER_FAILED:
4768 isp_prt(isp, ISP_LOGERR,
4769 "SDTR Message failed for target %d.%d.%d",
4770 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4772 sdparam *sdp = isp->isp_param;
4773 sdp += XS_CHANNEL(xs);
4774 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
4775 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4776 isp->isp_update |= (1 << XS_CHANNEL(xs));
4780 case RQCS_LVD_BUSERR:
4781 isp_prt(isp, ISP_LOGERR,
4782 "Bad LVD condition while talking to %d.%d.%d",
4783 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4786 case RQCS_PORT_UNAVAILABLE:
4788 * No such port on the loop. Moral equivalent of SELTIMEO
4790 case RQCS_PORT_LOGGED_OUT:
4792 * It was there (maybe)- treat as a selection timeout.
4794 if ((sp->req_completion_status & 0xff) == RQCS_PORT_UNAVAILABLE)
4795 isp_prt(isp, ISP_LOGINFO,
4796 "port unavailable for target %d", XS_TGT(xs));
4798 isp_prt(isp, ISP_LOGINFO,
4799 "port logout for target %d", XS_TGT(xs));
4801 * If we're on a local loop, force a LIP (which is overkill)
4802 * to force a re-login of this unit. If we're on fabric,
4803 * then we'll have to relogin as a matter of course.
4805 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4806 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4808 MEMZERO(&mbs, sizeof (mbs));
4809 mbs.param[0] = MBOX_INIT_LIP;
4810 isp_mboxcmd_qnw(isp, &mbs, 1);
4814 * Probably overkill.
4816 isp->isp_sendmarker = 1;
4817 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4818 isp_mark_getpdb_all(isp);
4819 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4821 XS_SETERR(xs, HBA_SELTIMEOUT);
4825 case RQCS_PORT_CHANGED:
4826 isp_prt(isp, ISP_LOGWARN,
4827 "port changed for target %d", XS_TGT(xs));
4829 XS_SETERR(xs, HBA_SELTIMEOUT);
4833 case RQCS_PORT_BUSY:
4834 isp_prt(isp, ISP_LOGWARN,
4835 "port busy for target %d", XS_TGT(xs));
4837 XS_SETERR(xs, HBA_TGTBSY);
4842 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x",
4843 sp->req_completion_status);
4847 XS_SETERR(xs, HBA_BOTCH);
4852 isp_fastpost_complete(ispsoftc_t *isp, uint16_t fph)
4859 xs = isp_find_xs(isp, fph);
4861 isp_prt(isp, ISP_LOGWARN,
4862 "Command for fast post handle 0x%x not found", fph);
4865 isp_destroy_handle(isp, fph);
4868 * Since we don't have a result queue entry item,
4869 * we must believe that SCSI status is zero and
4870 * that all data transferred.
4872 XS_SET_STATE_STAT(isp, xs, NULL);
4874 *XS_STSP(xs) = SCSI_GOOD;
4875 if (XS_XFRLEN(xs)) {
4876 ISP_DMAFREE(isp, xs, fph);
4878 if (isp->isp_nactive)
4880 isp->isp_fphccmplt++;
4885 isp_mbox_continue(ispsoftc_t *isp)
4890 switch (isp->isp_lastmbxcmd) {
4891 case MBOX_WRITE_RAM_WORD:
4892 case MBOX_READ_RAM_WORD:
4893 case MBOX_READ_RAM_WORD_EXTENDED:
4898 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
4899 isp->isp_mbxwrk0 = 0;
4904 * Clear the previous interrupt.
4906 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
4907 ISP_WRITE(isp, BIU_SEMA, 0);
4910 * Continue with next word.
4912 MEMZERO(&mbs, sizeof (mbs));
4913 ptr = isp->isp_mbxworkp;
4914 switch (isp->isp_lastmbxcmd) {
4915 case MBOX_WRITE_RAM_WORD:
4916 mbs.param[2] = *ptr++;
4917 mbs.param[1] = isp->isp_mbxwrk1++;
4919 case MBOX_READ_RAM_WORD:
4920 case MBOX_READ_RAM_WORD_EXTENDED:
4921 *ptr++ = isp->isp_mboxtmp[2];
4922 mbs.param[1] = isp->isp_mbxwrk1++;
4925 isp->isp_mbxworkp = ptr;
4926 mbs.param[0] = isp->isp_lastmbxcmd;
4927 isp->isp_mbxwrk0 -= 1;
4928 isp_mboxcmd_qnw(isp, &mbs, 0);
4933 #define HIWRD(x) ((x) >> 16)
4934 #define LOWRD(x) ((x) & 0xffff)
4935 #define ISPOPMAP(a, b) (((a) << 16) | (b))
4936 static const uint32_t mbpscsi[] = {
4937 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
4938 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
4939 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
4940 ISPOPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
4941 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
4942 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
4943 ISPOPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
4944 ISPOPMAP(0x03, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
4945 ISPOPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
4946 ISPOPMAP(0x00, 0x00), /* 0x09: */
4947 ISPOPMAP(0x00, 0x00), /* 0x0a: */
4948 ISPOPMAP(0x00, 0x00), /* 0x0b: */
4949 ISPOPMAP(0x00, 0x00), /* 0x0c: */
4950 ISPOPMAP(0x00, 0x00), /* 0x0d: */
4951 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
4952 ISPOPMAP(0x00, 0x00), /* 0x0f: */
4953 ISPOPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
4954 ISPOPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
4955 ISPOPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
4956 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
4957 ISPOPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
4958 ISPOPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
4959 ISPOPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
4960 ISPOPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
4961 ISPOPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
4962 ISPOPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
4963 ISPOPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
4964 ISPOPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
4965 ISPOPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
4966 ISPOPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
4967 ISPOPMAP(0x00, 0x00), /* 0x1e: */
4968 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
4969 ISPOPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
4970 ISPOPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
4971 ISPOPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
4972 ISPOPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
4973 ISPOPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
4974 ISPOPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
4975 ISPOPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
4976 ISPOPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
4977 ISPOPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
4978 ISPOPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
4979 ISPOPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
4980 ISPOPMAP(0x00, 0x00), /* 0x2b: */
4981 ISPOPMAP(0x00, 0x00), /* 0x2c: */
4982 ISPOPMAP(0x00, 0x00), /* 0x2d: */
4983 ISPOPMAP(0x00, 0x00), /* 0x2e: */
4984 ISPOPMAP(0x00, 0x00), /* 0x2f: */
4985 ISPOPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
4986 ISPOPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
4987 ISPOPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
4988 ISPOPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
4989 ISPOPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
4990 ISPOPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
4991 ISPOPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
4992 ISPOPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
4993 ISPOPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
4994 ISPOPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
4995 ISPOPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
4996 ISPOPMAP(0x00, 0x00), /* 0x3b: */
4997 ISPOPMAP(0x00, 0x00), /* 0x3c: */
4998 ISPOPMAP(0x00, 0x00), /* 0x3d: */
4999 ISPOPMAP(0x00, 0x00), /* 0x3e: */
5000 ISPOPMAP(0x00, 0x00), /* 0x3f: */
5001 ISPOPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
5002 ISPOPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
5003 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
5004 ISPOPMAP(0x00, 0x00), /* 0x43: */
5005 ISPOPMAP(0x00, 0x00), /* 0x44: */
5006 ISPOPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
5007 ISPOPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
5008 ISPOPMAP(0x00, 0x00), /* 0x47: */
5009 ISPOPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
5010 ISPOPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
5011 ISPOPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
5012 ISPOPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
5013 ISPOPMAP(0x00, 0x00), /* 0x4c: */
5014 ISPOPMAP(0x00, 0x00), /* 0x4d: */
5015 ISPOPMAP(0x00, 0x00), /* 0x4e: */
5016 ISPOPMAP(0x00, 0x00), /* 0x4f: */
5017 ISPOPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
5018 ISPOPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
5019 ISPOPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
5020 ISPOPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
5021 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
5022 ISPOPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
5023 ISPOPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
5024 ISPOPMAP(0x00, 0x00), /* 0x57: */
5025 ISPOPMAP(0x00, 0x00), /* 0x58: */
5026 ISPOPMAP(0x00, 0x00), /* 0x59: */
5027 ISPOPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
5028 ISPOPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
5029 ISPOPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
5030 ISPOPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
5033 #ifndef ISP_STRIPPED
5034 static char *scsi_mbcmd_names[] = {
5051 "INIT REQUEST QUEUE",
5052 "INIT RESULT QUEUE",
5062 "SINGLE STEP QUEUE",
5064 "GET DEV QUEUE STATUS",
5066 "GET FIRMWARE STATUS",
5068 "GET SELECT TIMEOUT",
5070 "GET TAG AGE LIMIT",
5072 "GET ACT NEG STATE",
5073 "GET ASYNC DATA SETUP TIME",
5075 "GET TARGET PARAMS",
5076 "GET DEV QUEUE PARAMS",
5077 "GET RESET DELAY PARAMS",
5084 "SET SELECT TIMEOUT",
5086 "SET TAG AGE LIMIT",
5088 "SET ACT NEG STATE",
5089 "SET ASYNC DATA SETUP TIME",
5090 "SET PCI CONTROL PARAMS",
5091 "SET TARGET PARAMS",
5092 "SET DEV QUEUE PARAMS",
5093 "SET RESET DELAY PARAMS",
5099 "RETURN BIOS BLOCK ADDR",
5100 "WRITE FOUR RAM WORDS",
5104 "SET SYSTEM PARAMETER",
5105 "GET SYSTEM PARAMETER",
5107 "GET SCAM CONFIGURATION",
5108 "SET SCAM CONFIGURATION",
5109 "SET FIRMWARE FEATURES",
5110 "GET FIRMWARE FEATURES",
5117 "INITIALIZE REQUEST QUEUE A64",
5118 "INITIALIZE RESPONSE QUEUE A64",
5120 "ENABLE TARGET MODE",
5121 "GET TARGET MODE STATE",
5125 "SET DATA OVERRUN RECOVERY MODE",
5126 "GET DATA OVERRUN RECOVERY MODE",
5132 static const uint32_t mbpfc[] = {
5133 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
5134 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
5135 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
5136 ISPOPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
5137 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
5138 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
5139 ISPOPMAP(0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
5140 ISPOPMAP(0x03, 0x05), /* 0x07: MBOX_VERIFY_CHECKSUM */
5141 ISPOPMAP(0x01, 0x4f), /* 0x08: MBOX_ABOUT_FIRMWARE */
5142 ISPOPMAP(0xdf, 0x01), /* 0x09: LOAD RAM */
5143 ISPOPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
5144 ISPOPMAP(0x00, 0x00), /* 0x0b: */
5145 ISPOPMAP(0x00, 0x00), /* 0x0c: */
5146 ISPOPMAP(0x00, 0x00), /* 0x0d: */
5147 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
5148 ISPOPMAP(0x03, 0x07), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED(1) */
5149 ISPOPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
5150 ISPOPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
5151 ISPOPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
5152 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
5153 ISPOPMAP(0x01, 0xff), /* 0x14: MBOX_STOP_FIRMWARE */
5154 ISPOPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
5155 ISPOPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
5156 ISPOPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
5157 ISPOPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
5158 ISPOPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
5159 ISPOPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
5160 ISPOPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
5161 ISPOPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
5162 ISPOPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
5163 ISPOPMAP(0x00, 0x00), /* 0x1e: */
5164 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
5165 ISPOPMAP(0x01, 0x4f), /* 0x20: MBOX_GET_LOOP_ID */
5166 ISPOPMAP(0x00, 0x00), /* 0x21: */
5167 ISPOPMAP(0x01, 0x07), /* 0x22: MBOX_GET_RETRY_COUNT */
5168 ISPOPMAP(0x00, 0x00), /* 0x23: */
5169 ISPOPMAP(0x00, 0x00), /* 0x24: */
5170 ISPOPMAP(0x00, 0x00), /* 0x25: */
5171 ISPOPMAP(0x00, 0x00), /* 0x26: */
5172 ISPOPMAP(0x00, 0x00), /* 0x27: */
5173 ISPOPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
5174 ISPOPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
5175 ISPOPMAP(0x00, 0x00), /* 0x2a: */
5176 ISPOPMAP(0x00, 0x00), /* 0x2b: */
5177 ISPOPMAP(0x00, 0x00), /* 0x2c: */
5178 ISPOPMAP(0x00, 0x00), /* 0x2d: */
5179 ISPOPMAP(0x00, 0x00), /* 0x2e: */
5180 ISPOPMAP(0x00, 0x00), /* 0x2f: */
5181 ISPOPMAP(0x00, 0x00), /* 0x30: */
5182 ISPOPMAP(0x00, 0x00), /* 0x31: */
5183 ISPOPMAP(0x07, 0x07), /* 0x32: MBOX_SET_RETRY_COUNT */
5184 ISPOPMAP(0x00, 0x00), /* 0x33: */
5185 ISPOPMAP(0x00, 0x00), /* 0x34: */
5186 ISPOPMAP(0x00, 0x00), /* 0x35: */
5187 ISPOPMAP(0x00, 0x00), /* 0x36: */
5188 ISPOPMAP(0x00, 0x00), /* 0x37: */
5189 ISPOPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
5190 ISPOPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
5191 ISPOPMAP(0x00, 0x00), /* 0x3a: */
5192 ISPOPMAP(0x00, 0x00), /* 0x3b: */
5193 ISPOPMAP(0x00, 0x00), /* 0x3c: */
5194 ISPOPMAP(0x00, 0x00), /* 0x3d: */
5195 ISPOPMAP(0x00, 0x00), /* 0x3e: */
5196 ISPOPMAP(0x00, 0x00), /* 0x3f: */
5197 ISPOPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
5198 ISPOPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
5199 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_GET_RESOURCE_COUNTS */
5200 ISPOPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_NON_PARTICIPATING_MODE */
5201 ISPOPMAP(0x00, 0x00), /* 0x44: */
5202 ISPOPMAP(0x00, 0x00), /* 0x45: */
5203 ISPOPMAP(0x00, 0x00), /* 0x46: */
5204 ISPOPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
5205 ISPOPMAP(0x00, 0x00), /* 0x48: */
5206 ISPOPMAP(0x00, 0x00), /* 0x49: */
5207 ISPOPMAP(0x00, 0x00), /* 0x4a: */
5208 ISPOPMAP(0x00, 0x00), /* 0x4b: */
5209 ISPOPMAP(0x00, 0x00), /* 0x4c: */
5210 ISPOPMAP(0x00, 0x00), /* 0x4d: */
5211 ISPOPMAP(0x00, 0x00), /* 0x4e: */
5212 ISPOPMAP(0x00, 0x00), /* 0x4f: */
5213 ISPOPMAP(0x00, 0x00), /* 0x50: */
5214 ISPOPMAP(0x00, 0x00), /* 0x51: */
5215 ISPOPMAP(0x00, 0x00), /* 0x52: */
5216 ISPOPMAP(0x00, 0x00), /* 0x53: */
5217 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
5218 ISPOPMAP(0x00, 0x00), /* 0x55: */
5219 ISPOPMAP(0x00, 0x00), /* 0x56: */
5220 ISPOPMAP(0x00, 0x00), /* 0x57: */
5221 ISPOPMAP(0x00, 0x00), /* 0x58: */
5222 ISPOPMAP(0x00, 0x00), /* 0x59: */
5223 ISPOPMAP(0x00, 0x00), /* 0x5a: */
5224 ISPOPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
5225 ISPOPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
5226 ISPOPMAP(0x07, 0x03), /* 0x5d: MBOX_GET_SET_DATA_RATE */
5227 ISPOPMAP(0x00, 0x00), /* 0x5e: */
5228 ISPOPMAP(0x00, 0x00), /* 0x5f: */
5229 ISPOPMAP(0xfd, 0x31), /* 0x60: MBOX_INIT_FIRMWARE */
5230 ISPOPMAP(0x00, 0x00), /* 0x61: */
5231 ISPOPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
5232 ISPOPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
5233 ISPOPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
5234 ISPOPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
5235 ISPOPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
5236 ISPOPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
5237 ISPOPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
5238 ISPOPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
5239 ISPOPMAP(0x03, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
5240 ISPOPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
5241 ISPOPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
5242 ISPOPMAP(0x00, 0x00), /* 0x6d: */
5243 ISPOPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
5244 ISPOPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
5245 ISPOPMAP(0x03, 0x01), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
5246 ISPOPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
5247 ISPOPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
5248 ISPOPMAP(0x00, 0x00), /* 0x73: */
5249 ISPOPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
5250 ISPOPMAP(0xcf, 0x03), /* 0x75: GET PORT/NODE NAME LIST */
5251 ISPOPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
5252 ISPOPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
5253 ISPOPMAP(0x00, 0x00), /* 0x78: */
5254 ISPOPMAP(0x00, 0x00), /* 0x79: */
5255 ISPOPMAP(0x00, 0x00), /* 0x7a: */
5256 ISPOPMAP(0x00, 0x00), /* 0x7b: */
5257 ISPOPMAP(0x4f, 0x03), /* 0x7c: Get ID List */
5258 ISPOPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
5259 ISPOPMAP(0x0f, 0x01) /* 0x7e: LUN RESET */
5264 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
5265 * do not access at this time in the core driver. The caller is
5266 * responsible for setting this register first (Gross!).
5269 #ifndef ISP_STRIPPED
5270 static char *fc_mbcmd_names[] = {
5284 "READ RAM WORD EXTENDED",
5287 "INIT REQUEST QUEUE",
5288 "INIT RESULT QUEUE",
5298 "SINGLE STEP QUEUE",
5300 "GET DEV QUEUE STATUS",
5302 "GET FIRMWARE STATUS",
5311 "GET FIRMWARE OPTIONS",
5312 "GET PORT QUEUE PARAMS",
5327 "SET FIRMWARE OPTIONS",
5328 "SET PORT QUEUE PARAMS",
5337 "GET RESOURCE COUNTS",
5338 "REQUEST NON PARTICIPATING MODE",
5342 "GET PORT DATABASE,, ENHANCED",
5364 "GET/SET DATA RATE",
5370 "GET FC-AL POSITION MAP",
5371 "GET PORT DATABASE",
5383 "SEND CHANGE REQUEST",
5388 "GET PORT/NODE NAME LIST",
5390 "INITIALIZE IP MAILBOX",
5402 isp_mboxcmd_qnw(ispsoftc_t *isp, mbreg_t *mbp, int nodelay)
5404 unsigned int ibits, obits, box, opcode;
5405 const uint32_t *mcp;
5412 opcode = mbp->param[0];
5413 ibits = HIWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5414 obits = LOWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5415 ibits |= mbp->ibits;
5416 obits |= mbp->obits;
5417 for (box = 0; box < MAX_MAILBOX(isp); box++) {
5418 if (ibits & (1 << box)) {
5419 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5422 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5426 isp->isp_lastmbxcmd = opcode;
5427 isp->isp_obits = obits;
5428 isp->isp_mboxbsy = 1;
5430 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5432 * Oddly enough, if we're not delaying for an answer,
5433 * delay a bit to give the f/w a chance to pick up the
5442 isp_mboxcmd(ispsoftc_t *isp, mbreg_t *mbp, int logmask)
5444 char *cname, *xname, tname[16], mname[16];
5445 unsigned int lim, ibits, obits, box, opcode;
5446 const uint32_t *mcp;
5450 lim = (sizeof (mbpfc) / sizeof (mbpfc[0]));
5453 lim = (sizeof (mbpscsi) / sizeof (mbpscsi[0]));
5456 if ((opcode = mbp->param[0]) >= lim) {
5457 mbp->param[0] = MBOX_INVALID_COMMAND;
5458 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
5462 ibits = HIWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5463 obits = LOWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5465 ibits |= mbp->ibits;
5466 obits |= mbp->obits;
5468 if (ibits == 0 && obits == 0) {
5469 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
5470 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
5475 * Get exclusive usage of mailbox registers.
5479 for (box = 0; box < MAX_MAILBOX(isp); box++) {
5480 if (ibits & (1 << box)) {
5481 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5483 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5486 isp->isp_lastmbxcmd = opcode;
5489 * We assume that we can't overwrite a previous command.
5491 isp->isp_obits = obits;
5492 isp->isp_mboxbsy = 1;
5495 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
5497 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5500 * While we haven't finished the command, spin our wheels here.
5502 MBOX_WAIT_COMPLETE(isp);
5504 if (isp->isp_mboxbsy) {
5506 * Command timed out.
5508 isp->isp_mboxbsy = 0;
5514 * Copy back output registers.
5516 for (box = 0; box < MAX_MAILBOX(isp); box++) {
5517 if (obits & (1 << box)) {
5518 mbp->param[box] = isp->isp_mboxtmp[box];
5524 if (logmask == 0 || opcode == MBOX_EXEC_FIRMWARE) {
5530 cname = (IS_FC(isp))? fc_mbcmd_names[opcode] : scsi_mbcmd_names[opcode];
5532 if (cname == NULL) {
5534 SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
5538 * Just to be chatty here...
5541 switch (mbp->param[0]) {
5542 case MBOX_COMMAND_COMPLETE:
5544 case MBOX_INVALID_COMMAND:
5545 if (logmask & MBLOGMASK(MBOX_COMMAND_COMPLETE))
5546 xname = "INVALID COMMAND";
5548 case MBOX_HOST_INTERFACE_ERROR:
5549 if (logmask & MBLOGMASK(MBOX_HOST_INTERFACE_ERROR))
5550 xname = "HOST INTERFACE ERROR";
5552 case MBOX_TEST_FAILED:
5553 if (logmask & MBLOGMASK(MBOX_TEST_FAILED))
5554 xname = "TEST FAILED";
5556 case MBOX_COMMAND_ERROR:
5557 if (logmask & MBLOGMASK(MBOX_COMMAND_ERROR))
5558 xname = "COMMAND ERROR";
5560 case MBOX_COMMAND_PARAM_ERROR:
5561 if (logmask & MBLOGMASK(MBOX_COMMAND_PARAM_ERROR))
5562 xname = "COMMAND PARAMETER ERROR";
5564 case MBOX_LOOP_ID_USED:
5565 if (logmask & MBLOGMASK(MBOX_LOOP_ID_USED))
5566 xname = "LOOP ID ALREADY IN USE";
5568 case MBOX_PORT_ID_USED:
5569 if (logmask & MBLOGMASK(MBOX_PORT_ID_USED))
5570 xname = "PORT ID ALREADY IN USE";
5572 case MBOX_ALL_IDS_USED:
5573 if (logmask & MBLOGMASK(MBOX_ALL_IDS_USED))
5574 xname = "ALL LOOP IDS IN USE";
5576 case 0: /* special case */
5580 SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
5585 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s)",
5590 isp_fw_state(ispsoftc_t *isp)
5594 fcparam *fcp = isp->isp_param;
5596 MEMZERO(&mbs, sizeof (mbs));
5597 mbs.param[0] = MBOX_GET_FW_STATE;
5598 isp_mboxcmd(isp, &mbs, MBLOGALL);
5599 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
5600 fcp->isp_fwstate = mbs.param[1];
5606 isp_update(ispsoftc_t *isp)
5610 for (bus = 0, upmask = isp->isp_update; upmask != 0; bus++) {
5611 if (upmask & (1 << bus)) {
5612 isp_update_bus(isp, bus);
5614 upmask &= ~(1 << bus);
5619 isp_update_bus(ispsoftc_t *isp, int bus)
5625 isp->isp_update &= ~(1 << bus);
5628 * There are no 'per-bus' settings for Fibre Channel.
5632 sdp = isp->isp_param;
5634 MEMZERO(&mbs, sizeof (mbs));
5636 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5637 uint16_t flags, period, offset;
5640 if (sdp->isp_devparam[tgt].dev_enable == 0) {
5641 sdp->isp_devparam[tgt].dev_update = 0;
5642 sdp->isp_devparam[tgt].dev_refresh = 0;
5643 isp_prt(isp, ISP_LOGDEBUG0,
5644 "skipping target %d bus %d update", tgt, bus);
5648 * If the goal is to update the status of the device,
5649 * take what's in goal_flags and try and set the device
5650 * toward that. Otherwise, if we're just refreshing the
5651 * current device state, get the current parameters.
5655 * Refresh overrides set
5657 if (sdp->isp_devparam[tgt].dev_refresh) {
5658 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
5659 sdp->isp_devparam[tgt].dev_refresh = 0;
5661 } else if (sdp->isp_devparam[tgt].dev_update) {
5662 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
5664 * Make sure goal_flags has "Renegotiate on Error"
5665 * on and "Freeze Queue on Error" off.
5667 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
5668 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
5670 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
5673 * Insist that PARITY must be enabled
5674 * if SYNC or WIDE is enabled.
5676 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
5677 mbs.param[2] |= DPARM_PARITY;
5680 if ((mbs.param[2] & DPARM_SYNC) == 0) {
5684 (sdp->isp_devparam[tgt].goal_offset << 8) |
5685 (sdp->isp_devparam[tgt].goal_period);
5688 * A command completion later that has
5689 * RQSTF_NEGOTIATION set can cause
5690 * the dev_refresh/announce cycle also.
5692 * Note: It is really important to update our current
5693 * flags with at least the state of TAG capabilities-
5694 * otherwise we might try and send a tagged command
5695 * when we have it all turned off. So change it here
5696 * to say that current already matches goal.
5698 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
5699 sdp->isp_devparam[tgt].actv_flags |=
5700 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
5701 isp_prt(isp, ISP_LOGDEBUG0,
5702 "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
5703 bus, tgt, mbs.param[2], mbs.param[3] >> 8,
5704 mbs.param[3] & 0xff);
5705 sdp->isp_devparam[tgt].dev_update = 0;
5706 sdp->isp_devparam[tgt].dev_refresh = 1;
5711 mbs.param[1] = (bus << 15) | (tgt << 8);
5712 isp_mboxcmd(isp, &mbs, MBLOGALL);
5714 isp->isp_sendmarker |= (1 << bus);
5717 flags = mbs.param[2];
5718 period = mbs.param[3] & 0xff;
5719 offset = mbs.param[3] >> 8;
5720 sdp->isp_devparam[tgt].actv_flags = flags;
5721 sdp->isp_devparam[tgt].actv_period = period;
5722 sdp->isp_devparam[tgt].actv_offset = offset;
5723 get = (bus << 16) | tgt;
5724 (void) isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, &get);
5727 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5728 if (sdp->isp_devparam[tgt].dev_update ||
5729 sdp->isp_devparam[tgt].dev_refresh) {
5730 isp->isp_update |= (1 << bus);
5736 #ifndef DEFAULT_FRAMESIZE
5737 #define DEFAULT_FRAMESIZE(isp) ICB_DFLT_FRMLEN
5739 #ifndef DEFAULT_EXEC_THROTTLE
5740 #define DEFAULT_EXEC_THROTTLE(isp) ISP_EXEC_THROTTLE
5744 isp_setdfltparm(ispsoftc_t *isp, int channel)
5750 MEMZERO(&mbs, sizeof (mbs));
5752 fcparam *fcp = (fcparam *) isp->isp_param;
5756 if (fcp->isp_gotdparms) {
5759 fcp->isp_gotdparms = 1;
5760 fcp->isp_maxfrmlen = DEFAULT_FRAMESIZE(isp);
5761 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
5762 fcp->isp_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
5763 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
5764 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
5765 /* Platform specific.... */
5766 fcp->isp_loopid = DEFAULT_LOOPID(isp);
5767 fcp->isp_nodewwn = DEFAULT_NODEWWN(isp);
5768 fcp->isp_portwwn = DEFAULT_PORTWWN(isp);
5769 fcp->isp_fwoptions = 0;
5770 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
5771 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
5772 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
5773 #ifndef ISP_NO_FASTPOST_FC
5774 fcp->isp_fwoptions |= ICBOPT_FAST_POST;
5776 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
5777 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
5780 * Make sure this is turned off now until we get
5781 * extended options from NVRAM
5783 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
5786 * Now try and read NVRAM unless told to not do so.
5787 * This will set fcparam's isp_nodewwn && isp_portwwn.
5789 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5790 nvfail = isp_read_nvram(isp);
5792 isp->isp_confopts |= ISP_CFG_NONVRAM;
5797 * Set node && port to override platform set defaults
5798 * unless the nvram read failed (or none was done),
5799 * or the platform code wants to use what had been
5800 * set in the defaults.
5803 isp->isp_confopts |= ISP_CFG_OWNWWPN|ISP_CFG_OWNWWNN;
5805 if (isp->isp_confopts & ISP_CFG_OWNWWNN) {
5806 isp_prt(isp, ISP_LOGCONFIG, "Using Node WWN 0x%08x%08x",
5807 (uint32_t) (DEFAULT_NODEWWN(isp) >> 32),
5808 (uint32_t) (DEFAULT_NODEWWN(isp) & 0xffffffff));
5809 ISP_NODEWWN(isp) = DEFAULT_NODEWWN(isp);
5812 * We always start out with values derived
5813 * from NVRAM or our platform default.
5815 ISP_NODEWWN(isp) = fcp->isp_nodewwn;
5817 if (isp->isp_confopts & ISP_CFG_OWNWWPN) {
5818 isp_prt(isp, ISP_LOGCONFIG, "Using Port WWN 0x%08x%08x",
5819 (uint32_t) (DEFAULT_PORTWWN(isp) >> 32),
5820 (uint32_t) (DEFAULT_PORTWWN(isp) & 0xffffffff));
5821 ISP_PORTWWN(isp) = DEFAULT_PORTWWN(isp);
5824 * We always start out with values derived
5825 * from NVRAM or our platform default.
5827 ISP_PORTWWN(isp) = fcp->isp_portwwn;
5832 sdp = (sdparam *) isp->isp_param;
5836 * Been there, done that, got the T-shirt...
5838 if (sdp->isp_gotdparms) {
5841 sdp->isp_gotdparms = 1;
5844 * Establish some default parameters.
5846 sdp->isp_cmd_dma_burst_enable = 0;
5847 sdp->isp_data_dma_burst_enabl = 1;
5848 sdp->isp_fifo_threshold = 0;
5849 sdp->isp_initiator_id = DEFAULT_IID(isp);
5850 if (isp->isp_type >= ISP_HA_SCSI_1040) {
5851 sdp->isp_async_data_setup = 9;
5853 sdp->isp_async_data_setup = 6;
5855 sdp->isp_selection_timeout = 250;
5856 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
5857 sdp->isp_tag_aging = 8;
5858 sdp->isp_bus_reset_delay = 5;
5860 * Don't retry selection, busy or queue full automatically- reflect
5863 sdp->isp_retry_count = 0;
5864 sdp->isp_retry_delay = 0;
5866 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5867 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
5868 sdp->isp_devparam[tgt].dev_enable = 1;
5872 * If we've not been told to avoid reading NVRAM, try and read it.
5873 * If we're successful reading it, we can then return because NVRAM
5874 * will tell us what the desired settings are. Otherwise, we establish
5875 * some reasonable 'fake' nvram and goal defaults.
5878 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5879 if (isp_read_nvram(isp) == 0) {
5885 * Now try and see whether we have specific values for them.
5887 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5888 mbs.param[0] = MBOX_GET_ACT_NEG_STATE;
5889 isp_mboxcmd(isp, &mbs, MBLOGNONE);
5890 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
5891 sdp->isp_req_ack_active_neg = 1;
5892 sdp->isp_data_line_active_neg = 1;
5894 sdp->isp_req_ack_active_neg =
5895 (mbs.param[1+channel] >> 4) & 0x1;
5896 sdp->isp_data_line_active_neg =
5897 (mbs.param[1+channel] >> 5) & 0x1;
5901 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc3,
5902 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
5903 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
5904 sdp->isp_retry_delay, sdp->isp_async_data_setup);
5905 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc3,
5906 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
5907 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
5908 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
5911 * The trick here is to establish a default for the default (honk!)
5912 * state (goal_flags). Then try and get the current status from
5913 * the card to fill in the current state. We don't, in fact, set
5914 * the default to the SAFE default state- that's not the goal state.
5916 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5918 sdp->isp_devparam[tgt].actv_offset = 0;
5919 sdp->isp_devparam[tgt].actv_period = 0;
5920 sdp->isp_devparam[tgt].actv_flags = 0;
5922 sdp->isp_devparam[tgt].goal_flags =
5923 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
5926 * We default to Wide/Fast for versions less than a 1040
5927 * (unless it's SBus).
5929 if (IS_ULTRA3(isp)) {
5930 off = ISP_80M_SYNCPARMS >> 8;
5931 per = ISP_80M_SYNCPARMS & 0xff;
5932 } else if (IS_ULTRA2(isp)) {
5933 off = ISP_40M_SYNCPARMS >> 8;
5934 per = ISP_40M_SYNCPARMS & 0xff;
5935 } else if (IS_1240(isp)) {
5936 off = ISP_20M_SYNCPARMS >> 8;
5937 per = ISP_20M_SYNCPARMS & 0xff;
5938 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
5939 isp->isp_type < ISP_HA_SCSI_1020A) ||
5940 (isp->isp_bustype == ISP_BT_PCI &&
5941 isp->isp_type < ISP_HA_SCSI_1040) ||
5942 (isp->isp_clock && isp->isp_clock < 60) ||
5943 (sdp->isp_ultramode == 0)) {
5944 off = ISP_10M_SYNCPARMS >> 8;
5945 per = ISP_10M_SYNCPARMS & 0xff;
5947 off = ISP_20M_SYNCPARMS_1040 >> 8;
5948 per = ISP_20M_SYNCPARMS_1040 & 0xff;
5950 sdp->isp_devparam[tgt].goal_offset =
5951 sdp->isp_devparam[tgt].nvrm_offset = off;
5952 sdp->isp_devparam[tgt].goal_period =
5953 sdp->isp_devparam[tgt].nvrm_period = per;
5955 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc3,
5956 channel, tgt, sdp->isp_devparam[tgt].nvrm_flags,
5957 sdp->isp_devparam[tgt].nvrm_offset,
5958 sdp->isp_devparam[tgt].nvrm_period);
5963 * Re-initialize the ISP and complete all orphaned commands
5964 * with a 'botched' notice. The reset/init routines should
5965 * not disturb an already active list of commands.
5967 * Locks held prior to coming here.
5971 isp_reinit(ispsoftc_t *isp)
5977 isp_mark_getpdb_all(isp);
5980 if (isp->isp_state != ISP_RESETSTATE) {
5981 isp_prt(isp, ISP_LOGERR, "isp_reinit cannot reset card");
5982 } else if (isp->isp_role != ISP_ROLE_NONE) {
5984 if (isp->isp_state == ISP_INITSTATE) {
5985 isp->isp_state = ISP_RUNSTATE;
5987 if (isp->isp_state != ISP_RUNSTATE) {
5988 isp_prt(isp, ISP_LOGERR,
5989 "isp_reinit cannot restart card");
5992 isp->isp_nactive = 0;
5994 for (i = 0; i < isp->isp_maxcmds; i++) {
5996 xs = isp->isp_xflist[i];
6000 handle = isp_index_handle(i);
6001 isp_destroy_handle(isp, handle);
6002 if (XS_XFRLEN(xs)) {
6003 ISP_DMAFREE(isp, xs, handle);
6004 XS_RESID(xs) = XS_XFRLEN(xs);
6008 XS_SETERR(xs, HBA_BUSRESET);
6017 isp_read_nvram(ispsoftc_t *isp)
6020 uint8_t csum, minversion;
6022 uint8_t _x[ISP2100_NVRAM_SIZE];
6023 uint16_t _s[ISP2100_NVRAM_SIZE>>1];
6025 #define nvram_data _n._x
6026 #define nvram_words _n._s
6029 amt = ISP2100_NVRAM_SIZE;
6031 } else if (IS_ULTRA2(isp)) {
6032 amt = ISP1080_NVRAM_SIZE;
6035 amt = ISP_NVRAM_SIZE;
6040 * Just read the first two words first to see if we have a valid
6041 * NVRAM to continue reading the rest with.
6043 for (i = 0; i < 2; i++) {
6044 isp_rdnvram_word(isp, i, &nvram_words[i]);
6046 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
6047 nvram_data[2] != 'P') {
6048 if (isp->isp_bustype != ISP_BT_SBUS) {
6049 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
6050 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x",
6051 nvram_data[0], nvram_data[1], nvram_data[2]);
6055 for (i = 2; i < amt>>1; i++) {
6056 isp_rdnvram_word(isp, i, &nvram_words[i]);
6058 for (csum = 0, i = 0; i < amt; i++) {
6059 csum += nvram_data[i];
6062 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
6065 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
6066 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
6067 ISP_NVRAM_VERSION(nvram_data));
6071 if (IS_ULTRA3(isp)) {
6072 isp_parse_nvram_12160(isp, 0, nvram_data);
6074 isp_parse_nvram_12160(isp, 1, nvram_data);
6075 } else if (IS_1080(isp)) {
6076 isp_parse_nvram_1080(isp, 0, nvram_data);
6077 } else if (IS_1280(isp) || IS_1240(isp)) {
6078 isp_parse_nvram_1080(isp, 0, nvram_data);
6079 isp_parse_nvram_1080(isp, 1, nvram_data);
6080 } else if (IS_SCSI(isp)) {
6081 isp_parse_nvram_1020(isp, nvram_data);
6083 isp_parse_nvram_2100(isp, nvram_data);
6091 isp_rdnvram_word(ispsoftc_t *isp, int wo, uint16_t *rp)
6096 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
6098 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
6102 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
6103 if (IS_2312(isp) && isp->isp_port) {
6106 rqst = (ISP_NVRAM_READ << 8) | wo;
6108 } else if (IS_ULTRA2(isp)) {
6109 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
6110 rqst = (ISP_NVRAM_READ << 8) | wo;
6113 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
6114 rqst = (ISP_NVRAM_READ << 6) | wo;
6119 * Clock the word select request out...
6121 for (i = cbits; i >= 0; i--) {
6122 if ((rqst >> i) & 1) {
6123 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
6125 bit = BIU_NVRAM_SELECT;
6127 ISP_WRITE(isp, BIU_NVRAM, bit);
6129 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
6131 ISP_WRITE(isp, BIU_NVRAM, bit);
6135 * Now read the result back in (bits come back in MSB format).
6138 for (i = 0; i < 16; i++) {
6141 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
6143 rv = ISP_READ(isp, BIU_NVRAM);
6144 if (rv & BIU_NVRAM_DATAIN) {
6148 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
6151 ISP_WRITE(isp, BIU_NVRAM, 0);
6153 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
6157 isp_parse_nvram_1020(ispsoftc_t *isp, uint8_t *nvram_data)
6159 sdparam *sdp = (sdparam *) isp->isp_param;
6162 sdp->isp_fifo_threshold =
6163 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
6164 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
6166 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6167 sdp->isp_initiator_id =
6168 ISP_NVRAM_INITIATOR_ID(nvram_data);
6170 sdp->isp_bus_reset_delay =
6171 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
6173 sdp->isp_retry_count =
6174 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
6176 sdp->isp_retry_delay =
6177 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
6179 sdp->isp_async_data_setup =
6180 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
6182 if (isp->isp_type >= ISP_HA_SCSI_1040) {
6183 if (sdp->isp_async_data_setup < 9) {
6184 sdp->isp_async_data_setup = 9;
6187 if (sdp->isp_async_data_setup != 6) {
6188 sdp->isp_async_data_setup = 6;
6192 sdp->isp_req_ack_active_neg =
6193 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
6195 sdp->isp_data_line_active_neg =
6196 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
6198 sdp->isp_data_dma_burst_enabl =
6199 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
6201 sdp->isp_cmd_dma_burst_enable =
6202 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
6204 sdp->isp_tag_aging =
6205 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
6207 sdp->isp_selection_timeout =
6208 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
6210 sdp->isp_max_queue_depth =
6211 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
6213 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
6215 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6216 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6217 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6218 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6219 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6220 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6221 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6222 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6224 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6225 sdp->isp_devparam[tgt].dev_enable =
6226 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
6227 sdp->isp_devparam[tgt].exc_throttle =
6228 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
6229 sdp->isp_devparam[tgt].nvrm_offset =
6230 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
6231 sdp->isp_devparam[tgt].nvrm_period =
6232 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
6234 * We probably shouldn't lie about this, but it
6235 * it makes it much safer if we limit NVRAM values
6238 if (isp->isp_type < ISP_HA_SCSI_1040) {
6240 * If we're not ultra, we can't possibly
6241 * be a shorter period than this.
6243 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
6244 sdp->isp_devparam[tgt].nvrm_period = 0x19;
6246 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
6247 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
6250 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
6251 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
6254 sdp->isp_devparam[tgt].nvrm_flags = 0;
6255 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
6256 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6257 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6258 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
6259 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6260 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
6261 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6262 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
6263 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6264 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
6265 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6266 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
6267 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6268 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
6269 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6270 0, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6271 sdp->isp_devparam[tgt].nvrm_offset,
6272 sdp->isp_devparam[tgt].nvrm_period);
6273 sdp->isp_devparam[tgt].goal_offset =
6274 sdp->isp_devparam[tgt].nvrm_offset;
6275 sdp->isp_devparam[tgt].goal_period =
6276 sdp->isp_devparam[tgt].nvrm_period;
6277 sdp->isp_devparam[tgt].goal_flags =
6278 sdp->isp_devparam[tgt].nvrm_flags;
6283 isp_parse_nvram_1080(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
6285 sdparam *sdp = (sdparam *) isp->isp_param;
6290 sdp->isp_fifo_threshold =
6291 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
6293 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6294 sdp->isp_initiator_id =
6295 ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
6297 sdp->isp_bus_reset_delay =
6298 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6300 sdp->isp_retry_count =
6301 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6303 sdp->isp_retry_delay =
6304 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6306 sdp->isp_async_data_setup =
6307 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6309 sdp->isp_req_ack_active_neg =
6310 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6312 sdp->isp_data_line_active_neg =
6313 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6315 sdp->isp_data_dma_burst_enabl =
6316 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6318 sdp->isp_cmd_dma_burst_enable =
6319 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6321 sdp->isp_selection_timeout =
6322 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6324 sdp->isp_max_queue_depth =
6325 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6327 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6328 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6329 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6330 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6331 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6332 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6333 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6334 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6337 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6338 sdp->isp_devparam[tgt].dev_enable =
6339 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6340 sdp->isp_devparam[tgt].exc_throttle =
6341 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6342 sdp->isp_devparam[tgt].nvrm_offset =
6343 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6344 sdp->isp_devparam[tgt].nvrm_period =
6345 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6346 sdp->isp_devparam[tgt].nvrm_flags = 0;
6347 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6348 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6349 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6350 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6351 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6352 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6353 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6354 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6355 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6356 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6357 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6358 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6359 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6360 sdp->isp_devparam[tgt].actv_flags = 0;
6361 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6362 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6363 sdp->isp_devparam[tgt].nvrm_offset,
6364 sdp->isp_devparam[tgt].nvrm_period);
6365 sdp->isp_devparam[tgt].goal_offset =
6366 sdp->isp_devparam[tgt].nvrm_offset;
6367 sdp->isp_devparam[tgt].goal_period =
6368 sdp->isp_devparam[tgt].nvrm_period;
6369 sdp->isp_devparam[tgt].goal_flags =
6370 sdp->isp_devparam[tgt].nvrm_flags;
6375 isp_parse_nvram_12160(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
6377 sdparam *sdp = (sdparam *) isp->isp_param;
6382 sdp->isp_fifo_threshold =
6383 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
6385 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6386 sdp->isp_initiator_id =
6387 ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
6389 sdp->isp_bus_reset_delay =
6390 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6392 sdp->isp_retry_count =
6393 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6395 sdp->isp_retry_delay =
6396 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6398 sdp->isp_async_data_setup =
6399 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6401 sdp->isp_req_ack_active_neg =
6402 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6404 sdp->isp_data_line_active_neg =
6405 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6407 sdp->isp_data_dma_burst_enabl =
6408 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6410 sdp->isp_cmd_dma_burst_enable =
6411 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6413 sdp->isp_selection_timeout =
6414 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6416 sdp->isp_max_queue_depth =
6417 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6419 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6420 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6421 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6422 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6423 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6424 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6425 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6426 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6428 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6429 sdp->isp_devparam[tgt].dev_enable =
6430 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6431 sdp->isp_devparam[tgt].exc_throttle =
6432 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6433 sdp->isp_devparam[tgt].nvrm_offset =
6434 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6435 sdp->isp_devparam[tgt].nvrm_period =
6436 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6437 sdp->isp_devparam[tgt].nvrm_flags = 0;
6438 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6439 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6440 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6441 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6442 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6443 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6444 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6445 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6446 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6447 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6448 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6449 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6450 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6451 sdp->isp_devparam[tgt].actv_flags = 0;
6452 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6453 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6454 sdp->isp_devparam[tgt].nvrm_offset,
6455 sdp->isp_devparam[tgt].nvrm_period);
6456 sdp->isp_devparam[tgt].goal_offset =
6457 sdp->isp_devparam[tgt].nvrm_offset;
6458 sdp->isp_devparam[tgt].goal_period =
6459 sdp->isp_devparam[tgt].nvrm_period;
6460 sdp->isp_devparam[tgt].goal_flags =
6461 sdp->isp_devparam[tgt].nvrm_flags;
6466 isp_parse_nvram_2100(ispsoftc_t *isp, uint8_t *nvram_data)
6468 fcparam *fcp = (fcparam *) isp->isp_param;
6472 * There is NVRAM storage for both Port and Node entities-
6473 * but the Node entity appears to be unused on all the cards
6474 * I can find. However, we should account for this being set
6475 * at some point in the future.
6477 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
6478 * bits 48..60. In the case of the 2202, it appears that they do
6479 * use bit 48 to distinguish between the two instances on the card.
6480 * The 2204, which I've never seen, *probably* extends this method.
6482 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
6484 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
6485 (uint32_t) (wwn >> 32), (uint32_t) (wwn & 0xffffffff));
6486 if ((wwn >> 60) == 0) {
6487 wwn |= (((uint64_t) 2)<< 60);
6490 fcp->isp_portwwn = wwn;
6491 if (IS_2200(isp) || IS_23XX(isp)) {
6492 wwn = ISP2200_NVRAM_NODE_NAME(nvram_data);
6494 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
6495 (uint32_t) (wwn >> 32),
6496 (uint32_t) (wwn & 0xffffffff));
6497 if ((wwn >> 60) == 0) {
6498 wwn |= (((uint64_t) 2)<< 60);
6502 wwn &= ~((uint64_t) 0xfff << 48);
6504 fcp->isp_nodewwn = wwn;
6507 * Make sure we have both Node and Port as non-zero values.
6509 if (fcp->isp_nodewwn != 0 && fcp->isp_portwwn == 0) {
6510 fcp->isp_portwwn = fcp->isp_nodewwn;
6511 } else if (fcp->isp_nodewwn == 0 && fcp->isp_portwwn != 0) {
6512 fcp->isp_nodewwn = fcp->isp_portwwn;
6516 * Make the Node and Port values sane if they're NAA == 2.
6517 * This means to clear bits 48..56 for the Node WWN and
6518 * make sure that there's some non-zero value in 48..56
6521 if (fcp->isp_nodewwn && fcp->isp_portwwn) {
6522 if ((fcp->isp_nodewwn & (((uint64_t) 0xfff) << 48)) != 0 &&
6523 (fcp->isp_nodewwn >> 60) == 2) {
6524 fcp->isp_nodewwn &= ~((uint64_t) 0xfff << 48);
6526 if ((fcp->isp_portwwn & (((uint64_t) 0xfff) << 48)) == 0 &&
6527 (fcp->isp_portwwn >> 60) == 2) {
6528 fcp->isp_portwwn |= ((uint64_t) 1 << 56);
6532 isp_prt(isp, ISP_LOGDEBUG0,
6533 "NVRAM: maxfrmlen %d execthrottle %d fwoptions 0x%x loopid %x",
6534 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data),
6535 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
6536 ISP2100_NVRAM_OPTIONS(nvram_data),
6537 ISP2100_NVRAM_HARDLOOPID(nvram_data));
6540 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
6541 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0)
6542 fcp->isp_maxfrmlen =
6543 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
6544 fcp->isp_retry_delay =
6545 ISP2100_NVRAM_RETRY_DELAY(nvram_data);
6546 fcp->isp_retry_count =
6547 ISP2100_NVRAM_RETRY_COUNT(nvram_data);
6548 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6550 ISP2100_NVRAM_HARDLOOPID(nvram_data);
6551 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0)
6552 fcp->isp_execthrottle =
6553 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
6554 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
6557 #ifdef ISP_FW_CRASH_DUMP
6558 static void isp2200_fw_dump(ispsoftc_t *);
6559 static void isp2300_fw_dump(ispsoftc_t *);
6562 isp2200_fw_dump(ispsoftc_t *isp)
6568 MEMZERO(&mbs, sizeof (mbs));
6569 ptr = FCPARAM(isp)->isp_dump_data;
6571 isp_prt(isp, ISP_LOGERR,
6572 "No place to dump RISC registers and SRAM");
6576 isp_prt(isp, ISP_LOGERR,
6577 "dump area for RISC registers and SRAM already used");
6580 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6581 for (i = 0; i < 100; i++) {
6583 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6587 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6591 for (i = 0; i < 8; i++) {
6592 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6598 for (i = 0; i < 8; i++) {
6599 *ptr++ = ISP_READ(isp, MBOX_BLOCK + (i << 1));
6605 for (i = 0; i < 48; i++) {
6606 *ptr++ = ISP_READ(isp, DMA_BLOCK + 0x20 + (i << 1));
6610 * RISC H/W Registers
6612 ISP_WRITE(isp, BIU2100_CSR, 0);
6613 for (i = 0; i < 16; i++) {
6614 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6620 for (j = 0; j < 8; j++) {
6621 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 8));
6622 for (i = 0; i < 16; i++) {
6624 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6629 * Frame Buffer Hardware Registers
6631 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6632 for (i = 0; i < 16; i++) {
6633 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6637 * Fibre Protocol Module 0 Hardware Registers
6639 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6640 for (i = 0; i < 64; i++) {
6641 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6645 * Fibre Protocol Module 1 Hardware Registers
6647 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6648 for (i = 0; i < 64; i++) {
6649 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6652 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6655 isp_prt(isp, ISP_LOGALL,
6656 "isp_fw_dump: RISC registers dumped successfully");
6657 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6658 for (i = 0; i < 100; i++) {
6660 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6664 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6665 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6668 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6669 for (i = 0; i < 100; i++) {
6671 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6675 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6676 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause After Reset");
6679 ISP_WRITE(isp, RISC_EMB, 0xf2);
6680 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
6681 for (i = 0; i < 100; i++) {
6683 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6688 mbs.param[0] = MBOX_READ_RAM_WORD;
6689 mbs.param[1] = 0x1000;
6690 isp->isp_mbxworkp = (void *) ptr;
6691 isp->isp_mbxwrk0 = 0xefff; /* continuation count */
6692 isp->isp_mbxwrk1 = 0x1001; /* next SRAM address */
6693 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6694 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6695 isp_prt(isp, ISP_LOGWARN,
6696 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6699 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6700 *ptr++ = isp->isp_mboxtmp[2];
6701 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
6702 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6703 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6707 isp2300_fw_dump(ispsoftc_t *isp)
6713 MEMZERO(&mbs, sizeof (mbs));
6714 ptr = FCPARAM(isp)->isp_dump_data;
6716 isp_prt(isp, ISP_LOGERR,
6717 "No place to dump RISC registers and SRAM");
6721 isp_prt(isp, ISP_LOGERR,
6722 "dump area for RISC registers and SRAM already used");
6725 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6726 for (i = 0; i < 100; i++) {
6728 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6732 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6736 for (i = 0; i < 8; i++) {
6737 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6741 * ReqQ-RspQ-Risc2Host Status registers
6743 for (i = 0; i < 8; i++) {
6744 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x10 + (i << 1));
6750 for (i = 0; i < 32; i++) {
6752 ISP_READ(isp, PCI_MBOX_REGS2300_OFF + (i << 1));
6756 * Auto Request Response DMA registers
6758 ISP_WRITE(isp, BIU2100_CSR, 0x40);
6759 for (i = 0; i < 32; i++) {
6760 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6766 ISP_WRITE(isp, BIU2100_CSR, 0x50);
6767 for (i = 0; i < 48; i++) {
6768 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6772 * RISC hardware registers
6774 ISP_WRITE(isp, BIU2100_CSR, 0);
6775 for (i = 0; i < 16; i++) {
6776 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6780 * RISC GP? registers
6782 for (j = 0; j < 8; j++) {
6783 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 9));
6784 for (i = 0; i < 16; i++) {
6786 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6791 * frame buffer hardware registers
6793 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6794 for (i = 0; i < 64; i++) {
6795 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6799 * FPM B0 hardware registers
6801 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6802 for (i = 0; i < 64; i++) {
6803 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6807 * FPM B1 hardware registers
6809 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6810 for (i = 0; i < 64; i++) {
6811 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6814 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6817 isp_prt(isp, ISP_LOGALL,
6818 "isp_fw_dump: RISC registers dumped successfully");
6819 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6820 for (i = 0; i < 100; i++) {
6822 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6826 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6827 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6831 mbs.param[0] = MBOX_READ_RAM_WORD;
6832 mbs.param[1] = 0x800;
6833 isp->isp_mbxworkp = (void *) ptr;
6834 isp->isp_mbxwrk0 = 0xf7ff; /* continuation count */
6835 isp->isp_mbxwrk1 = 0x801; /* next SRAM address */
6836 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6837 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6838 isp_prt(isp, ISP_LOGWARN,
6839 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6842 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6843 *ptr++ = isp->isp_mboxtmp[2];
6846 * We don't have access to mailbox registers 8.. onward
6847 * in our 'common' device model- so we have to set it
6848 * here and hope it stays the same!
6850 ISP_WRITE(isp, PCI_MBOX_REGS2300_OFF + (8 << 1), 0x1);
6852 mbs.param[0] = MBOX_READ_RAM_WORD_EXTENDED;
6854 isp->isp_mbxworkp = (void *) ptr;
6855 isp->isp_mbxwrk0 = 0xffff; /* continuation count */
6856 isp->isp_mbxwrk1 = 0x1; /* next SRAM address */
6857 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6858 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6859 isp_prt(isp, ISP_LOGWARN,
6860 "RAM DUMP FAILED @ WORD %x", 0x10000 + isp->isp_mbxwrk1);
6863 ptr = isp->isp_mbxworkp; /* finish final word */
6864 *ptr++ = mbs.param[2];
6865 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
6866 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6867 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6871 isp_fw_dump(ispsoftc_t *isp)
6874 isp2200_fw_dump(isp);
6875 else if (IS_23XX(isp))
6876 isp2300_fw_dump(isp);