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.
37 * Include header file appropriate for platform we're building on.
41 #include <dev/ic/isp_netbsd.h>
44 #include <sys/cdefs.h>
45 __FBSDID("$FreeBSD$");
46 #include <dev/isp/isp_freebsd.h>
49 #include <dev/ic/isp_openbsd.h>
52 #include "isp_linux.h"
55 #include "isp_solaris.h"
62 #define MBOX_DELAY_COUNT 1000000 / 100
67 static const char portshift[] =
68 "Target %d Loop ID 0x%x (Port 0x%x) => Loop 0x%x (Port 0x%x)";
69 static const char portdup[] =
70 "Target %d duplicates Target %d- killing off both";
71 static const char retained[] =
72 "Retaining Loop ID 0x%x for Target %d (Port 0x%x)";
73 static const char lretained[] =
74 "Retained login of Target %d (Loop ID 0x%x) Port 0x%x";
75 static const char plogout[] =
76 "Logging out Target %d at Loop ID 0x%x (Port 0x%x)";
77 static const char plogierr[] =
78 "Command Error in PLOGI for Port 0x%x (0x%x)";
79 static const char nopdb[] =
80 "Could not get PDB for Device @ Port 0x%x";
81 static const char pdbmfail1[] =
82 "PDB Loop ID info for Device @ Port 0x%x does not match up (0x%x)";
83 static const char pdbmfail2[] =
84 "PDB Port info for Device @ Port 0x%x does not match up (0x%x)";
85 static const char ldumped[] =
86 "Target %d (Loop ID 0x%x) Port 0x%x dumped after login info mismatch";
87 static const char notresp[] =
88 "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
89 static const char xact1[] =
90 "HBA attempted queued transaction with disconnect not set for %d.%d.%d";
91 static const char xact2[] =
92 "HBA attempted queued transaction to target routine %d on target %d bus %d";
93 static const char xact3[] =
94 "HBA attempted queued cmd for %d.%d.%d when queueing disabled";
95 static const char pskip[] =
96 "SCSI phase skipped for target %d.%d.%d";
97 static const char topology[] =
98 "Loop ID %d, Port ID 0x%x, Loop State 0x%x, Topology '%s'";
99 static const char swrej[] =
100 "Fabric Nameserver rejected %s (Reason=0x%x Expl=0x%x) for Port ID 0x%x";
101 static const char finmsg[] =
102 "(%d.%d.%d): FIN dl%d resid %d STS 0x%x SKEY %c XS_ERR=0x%x";
103 static const char sc0[] =
104 "%s CHAN %d FTHRSH %d IID %d RESETD %d RETRYC %d RETRYD %d ASD 0x%x";
105 static const char sc1[] =
106 "%s RAAN 0x%x DLAN 0x%x DDMAB 0x%x CDMAB 0x%x SELTIME %d MQD %d";
107 static const char sc2[] = "%s CHAN %d TGT %d FLAGS 0x%x 0x%x/0x%x";
108 static const char sc3[] = "Generated";
109 static const char sc4[] = "NVRAM";
110 static const char bun[] =
111 "bad underrun for %d.%d (count %d, resid %d, status %s)";
114 * Local function prototypes.
116 static int isp_parse_async(struct ispsoftc *, u_int16_t);
117 static int isp_handle_other_response(struct ispsoftc *, int, isphdr_t *,
120 isp_parse_status(struct ispsoftc *, ispstatusreq_t *, XS_T *);
121 static void isp_fastpost_complete(struct ispsoftc *, u_int16_t);
122 static int isp_mbox_continue(struct ispsoftc *);
123 static void isp_scsi_init(struct ispsoftc *);
124 static void isp_scsi_channel_init(struct ispsoftc *, int);
125 static void isp_fibre_init(struct ispsoftc *);
126 static void isp_mark_getpdb_all(struct ispsoftc *);
127 static int isp_getmap(struct ispsoftc *, fcpos_map_t *);
128 static int isp_getpdb(struct ispsoftc *, int, isp_pdb_t *);
129 static u_int64_t isp_get_portname(struct ispsoftc *, int, int);
130 static int isp_fclink_test(struct ispsoftc *, int);
131 static char *isp2100_fw_statename(int);
132 static int isp_pdb_sync(struct ispsoftc *);
133 static int isp_scan_loop(struct ispsoftc *);
134 static int isp_fabric_mbox_cmd(struct ispsoftc *, mbreg_t *);
135 static int isp_scan_fabric(struct ispsoftc *, int);
136 static void isp_register_fc4_type(struct ispsoftc *);
137 static void isp_fw_state(struct ispsoftc *);
138 static void isp_mboxcmd_qnw(struct ispsoftc *, mbreg_t *, int);
139 static void isp_mboxcmd(struct ispsoftc *, mbreg_t *, int);
141 static void isp_update(struct ispsoftc *);
142 static void isp_update_bus(struct ispsoftc *, int);
143 static void isp_setdfltparm(struct ispsoftc *, int);
144 static int isp_read_nvram(struct ispsoftc *);
145 static void isp_rdnvram_word(struct ispsoftc *, int, u_int16_t *);
146 static void isp_parse_nvram_1020(struct ispsoftc *, u_int8_t *);
147 static void isp_parse_nvram_1080(struct ispsoftc *, int, u_int8_t *);
148 static void isp_parse_nvram_12160(struct ispsoftc *, int, u_int8_t *);
149 static void isp_parse_nvram_2100(struct ispsoftc *, u_int8_t *);
154 * Hit the chip over the head, download new f/w if available and set it running.
156 * Locking done elsewhere.
160 isp_reset(struct ispsoftc *isp)
164 int loops, i, dodnld = 1;
165 char *btype = "????";
167 isp->isp_state = ISP_NILSTATE;
168 MEMZERO(&mbs, sizeof (mbs));
171 * Basic types (SCSI, FibreChannel and PCI or SBus)
172 * have been set in the MD code. We figure out more
173 * here. Possibly more refined types based upon PCI
174 * identification. Chip revision has been gathered.
176 * After we've fired this chip up, zero out the conf1 register
177 * for SCSI adapters and do other settings for the 2100.
181 * Get the current running firmware revision out of the
182 * chip before we hit it over the head (if this is our
183 * first time through). Note that we store this as the
184 * 'ROM' firmware revision- which it may not be. In any
185 * case, we don't really use this yet, but we may in
188 if (isp->isp_touched == 0) {
190 * First see whether or not we're sitting in the ISP PROM.
191 * If we've just been reset, we'll have the string "ISP "
192 * spread through outgoing mailbox registers 1-3. We do
193 * this for PCI cards because otherwise we really don't
194 * know what state the card is in and we could hang if
195 * we try this command otherwise.
197 * For SBus cards, we just do this because they almost
198 * certainly will be running firmware by now.
200 if (ISP_READ(isp, OUTMAILBOX1) != 0x4953 ||
201 ISP_READ(isp, OUTMAILBOX2) != 0x5020 ||
202 ISP_READ(isp, OUTMAILBOX3) != 0x2020) {
204 * Just in case it was paused...
206 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
207 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
208 isp_mboxcmd(isp, &mbs, MBLOGNONE);
209 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
210 isp->isp_romfw_rev[0] = mbs.param[1];
211 isp->isp_romfw_rev[1] = mbs.param[2];
212 isp->isp_romfw_rev[2] = mbs.param[3];
215 isp->isp_touched = 1;
221 * Set up default request/response queue in-pointer/out-pointer
225 isp->isp_rqstinrp = BIU_REQINP;
226 isp->isp_rqstoutrp = BIU_REQOUTP;
227 isp->isp_respinrp = BIU_RSPINP;
228 isp->isp_respoutrp = BIU_RSPOUTP;
230 isp->isp_rqstinrp = INMAILBOX4;
231 isp->isp_rqstoutrp = OUTMAILBOX4;
232 isp->isp_respinrp = OUTMAILBOX5;
233 isp->isp_respoutrp = INMAILBOX5;
237 * Put the board into PAUSE mode (so we can read the SXP registers
238 * or write FPM/FBM registers).
240 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
243 switch (isp->isp_type) {
266 * While we're paused, reset the FPM module and FBM fifos.
268 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
269 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
270 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
271 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
272 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
273 } else if (IS_1240(isp)) {
274 sdparam *sdp = isp->isp_param;
277 sdp->isp_ultramode = 1;
279 sdp->isp_ultramode = 1;
281 * XXX: Should probably do some bus sensing.
283 } else if (IS_ULTRA2(isp)) {
284 static const char m[] = "bus %d is in %s Mode";
286 sdparam *sdp = isp->isp_param;
288 isp->isp_clock = 100;
292 else if (IS_1080(isp))
294 else if (IS_10160(isp))
296 else if (IS_12160(isp))
301 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
303 case ISP1080_LVD_MODE:
304 sdp->isp_lvdmode = 1;
305 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
307 case ISP1080_HVD_MODE:
308 sdp->isp_diffmode = 1;
309 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
311 case ISP1080_SE_MODE:
312 sdp->isp_ultramode = 1;
313 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
316 isp_prt(isp, ISP_LOGERR,
317 "unknown mode on bus %d (0x%x)", 0, l);
321 if (IS_DUALBUS(isp)) {
323 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
324 l &= ISP1080_MODE_MASK;
326 case ISP1080_LVD_MODE:
327 sdp->isp_lvdmode = 1;
328 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
330 case ISP1080_HVD_MODE:
331 sdp->isp_diffmode = 1;
332 isp_prt(isp, ISP_LOGCONFIG,
333 m, 1, "Differential");
335 case ISP1080_SE_MODE:
336 sdp->isp_ultramode = 1;
337 isp_prt(isp, ISP_LOGCONFIG,
338 m, 1, "Single-Ended");
341 isp_prt(isp, ISP_LOGERR,
342 "unknown mode on bus %d (0x%x)", 1, l);
347 sdparam *sdp = isp->isp_param;
348 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
351 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
355 isp->isp_type = ISP_HA_SCSI_1020;
360 * Some 1020A chips are Ultra Capable, but don't
361 * run the clock rate up for that unless told to
362 * do so by the Ultra Capable bits being set.
365 isp->isp_type = ISP_HA_SCSI_1020A;
370 isp->isp_type = ISP_HA_SCSI_1040;
375 isp->isp_type = ISP_HA_SCSI_1040A;
380 isp->isp_type = ISP_HA_SCSI_1040B;
385 isp->isp_type = ISP_HA_SCSI_1040C;
390 * Now, while we're at it, gather info about ultra
391 * and/or differential mode.
393 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
394 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
395 sdp->isp_diffmode = 1;
397 sdp->isp_diffmode = 0;
399 i = ISP_READ(isp, RISC_PSR);
400 if (isp->isp_bustype == ISP_BT_SBUS) {
401 i &= RISC_PSR_SBUS_ULTRA;
403 i &= RISC_PSR_PCI_ULTRA;
406 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
407 sdp->isp_ultramode = 1;
409 * If we're in Ultra Mode, we have to be 60MHz clock-
410 * even for the SBus version.
414 sdp->isp_ultramode = 0;
416 * Clock is known. Gronk.
421 * Machine dependent clock (if set) overrides
422 * our generic determinations.
424 if (isp->isp_mdvec->dv_clock) {
425 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
426 isp->isp_clock = isp->isp_mdvec->dv_clock;
433 * Clear instrumentation
435 isp->isp_intcnt = isp->isp_intbogus = 0;
438 * Do MD specific pre initialization
445 * Hit the chip over the head with hammer,
446 * and give the ISP a chance to recover.
450 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
457 * Clear data && control DMA engines.
459 ISP_WRITE(isp, CDMA_CONTROL,
460 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
461 ISP_WRITE(isp, DDMA_CONTROL,
462 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
466 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
473 * Clear data && control DMA engines.
475 ISP_WRITE(isp, CDMA2100_CONTROL,
476 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
477 ISP_WRITE(isp, TDMA2100_CONTROL,
478 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
479 ISP_WRITE(isp, RDMA2100_CONTROL,
480 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
484 * Wait for ISP to be ready to go...
486 loops = MBOX_DELAY_COUNT;
489 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET))
492 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
497 ISP_DUMPREGS(isp, "chip reset timed out");
503 * After we've fired this chip up, zero out the conf1 register
504 * for SCSI adapters and other settings for the 2100.
508 ISP_WRITE(isp, BIU_CONF1, 0);
510 ISP_WRITE(isp, BIU2100_CSR, 0);
514 * Reset RISC Processor
516 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
518 /* Clear semaphore register (just to be sure) */
519 ISP_WRITE(isp, BIU_SEMA, 0);
522 * Establish some initial burst rate stuff.
523 * (only for the 1XX0 boards). This really should
524 * be done later after fetching from NVRAM.
527 u_int16_t tmp = isp->isp_mdvec->dv_conf1;
529 * Busted FIFO. Turn off all but burst enables.
531 if (isp->isp_type == ISP_HA_SCSI_1040A) {
532 tmp &= BIU_BURST_ENABLE;
534 ISP_SETBITS(isp, BIU_CONF1, tmp);
535 if (tmp & BIU_BURST_ENABLE) {
536 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
537 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
540 if (((sdparam *) isp->isp_param)->isp_ultramode) {
541 while (ISP_READ(isp, RISC_MTR) != 0x1313) {
542 ISP_WRITE(isp, RISC_MTR, 0x1313);
543 ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
546 ISP_WRITE(isp, RISC_MTR, 0x1212);
549 * PTI specific register
551 ISP_WRITE(isp, RISC_EMB, DUAL_BANK)
553 ISP_WRITE(isp, RISC_MTR, 0x1212);
556 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
557 if (IS_2200(isp) || IS_23XX(isp)) {
558 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
562 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE); /* release paused processor */
565 * Do MD specific post initialization
570 * Wait for everything to finish firing up.
572 * Avoid doing this on the 2312 because you can generate a PCI
573 * parity error (chip breakage).
578 loops = MBOX_DELAY_COUNT;
579 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
582 isp_prt(isp, ISP_LOGERR,
583 "MBOX_BUSY never cleared on reset");
590 * Up until this point we've done everything by just reading or
591 * setting registers. From this point on we rely on at least *some*
592 * kind of firmware running in the card.
596 * Do some sanity checking.
598 mbs.param[0] = MBOX_NO_OP;
599 isp_mboxcmd(isp, &mbs, MBLOGALL);
600 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
605 mbs.param[0] = MBOX_MAILBOX_REG_TEST;
606 mbs.param[1] = 0xdead;
607 mbs.param[2] = 0xbeef;
608 mbs.param[3] = 0xffff;
609 mbs.param[4] = 0x1111;
610 mbs.param[5] = 0xa5a5;
611 isp_mboxcmd(isp, &mbs, MBLOGALL);
612 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
615 if (mbs.param[1] != 0xdead || mbs.param[2] != 0xbeef ||
616 mbs.param[3] != 0xffff || mbs.param[4] != 0x1111 ||
617 mbs.param[5] != 0xa5a5) {
618 isp_prt(isp, ISP_LOGERR,
619 "Register Test Failed (0x%x 0x%x 0x%x 0x%x 0x%x)",
620 mbs.param[1], mbs.param[2], mbs.param[3],
621 mbs.param[4], mbs.param[5]);
628 * Download new Firmware, unless requested not to do so.
629 * This is made slightly trickier in some cases where the
630 * firmware of the ROM revision is newer than the revision
631 * compiled into the driver. So, where we used to compare
632 * versions of our f/w and the ROM f/w, now we just see
633 * whether we have f/w at all and whether a config flag
634 * has disabled our download.
636 if ((isp->isp_mdvec->dv_ispfw == NULL) ||
637 (isp->isp_confopts & ISP_CFG_NORELOAD)) {
642 code_org = ISP_CODE_ORG_2300;
644 code_org = ISP_CODE_ORG;
647 isp->isp_mbxworkp = (void *) &isp->isp_mdvec->dv_ispfw[1];
648 isp->isp_mbxwrk0 = isp->isp_mdvec->dv_ispfw[3] - 1;
649 isp->isp_mbxwrk1 = code_org + 1;
650 mbs.param[0] = MBOX_WRITE_RAM_WORD;
651 mbs.param[1] = code_org;
652 mbs.param[2] = isp->isp_mdvec->dv_ispfw[0];
653 isp_mboxcmd(isp, &mbs, MBLOGNONE);
654 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
655 isp_prt(isp, ISP_LOGERR,
656 "F/W download failed at word %d",
657 isp->isp_mbxwrk1 - code_org);
662 * Verify that it downloaded correctly.
664 mbs.param[0] = MBOX_VERIFY_CHECKSUM;
665 mbs.param[1] = code_org;
666 isp_mboxcmd(isp, &mbs, MBLOGNONE);
667 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
668 isp_prt(isp, ISP_LOGERR, "Ram Checksum Failure");
671 isp->isp_loaded_fw = 1;
673 isp->isp_loaded_fw = 0;
674 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
678 * Now start it rolling.
680 * If we didn't actually download f/w,
681 * we still need to (re)start it.
685 mbs.param[0] = MBOX_EXEC_FIRMWARE;
686 mbs.param[1] = code_org;
687 if (IS_2322(isp) || IS_24XX(isp)) {
688 if (isp->isp_loaded_fw) {
696 isp_mboxcmd(isp, &mbs, MBLOGNONE);
698 * Give it a chance to start.
704 * Set CLOCK RATE, but only if asked to.
706 if (isp->isp_clock) {
707 mbs.param[0] = MBOX_SET_CLOCK_RATE;
708 mbs.param[1] = isp->isp_clock;
709 isp_mboxcmd(isp, &mbs, MBLOGALL);
710 /* we will try not to care if this fails */
714 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
715 isp_mboxcmd(isp, &mbs, MBLOGALL);
716 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
721 * The SBus firmware that we are using apparently does not return
722 * major, minor, micro revisions in the mailbox registers, which
723 * is really, really, annoying.
725 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
727 #ifdef ISP_TARGET_MODE
728 isp->isp_fwrev[0] = 7;
729 isp->isp_fwrev[1] = 55;
731 isp->isp_fwrev[0] = 1;
732 isp->isp_fwrev[1] = 37;
734 isp->isp_fwrev[2] = 0;
737 isp->isp_fwrev[0] = mbs.param[1];
738 isp->isp_fwrev[1] = mbs.param[2];
739 isp->isp_fwrev[2] = mbs.param[3];
741 isp_prt(isp, ISP_LOGCONFIG,
742 "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
743 btype, isp->isp_revision, dodnld? "loaded" : "resident",
744 isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
748 * We do not believe firmware attributes for 2100 code less
749 * than 1.17.0, unless it's the firmware we specifically
752 * Note that all 22XX and 23XX f/w is greater than 1.X.0.
754 if (!(ISP_FW_NEWER_THAN(isp, 1, 17, 0))) {
755 #ifdef USE_SMALLER_2100_FIRMWARE
756 FCPARAM(isp)->isp_fwattr = ISP_FW_ATTR_SCCLUN;
758 FCPARAM(isp)->isp_fwattr = 0;
761 FCPARAM(isp)->isp_fwattr = mbs.param[6];
762 isp_prt(isp, ISP_LOGDEBUG0,
763 "Firmware Attributes = 0x%x", mbs.param[6]);
765 if (IS_2KLOGIN(isp)) {
766 isp_prt(isp, ISP_LOGCONFIG, "2K Logins Supported");
770 if (isp->isp_romfw_rev[0] || isp->isp_romfw_rev[1] ||
771 isp->isp_romfw_rev[2]) {
772 isp_prt(isp, ISP_LOGCONFIG, "Last F/W revision was %d.%d.%d",
773 isp->isp_romfw_rev[0], isp->isp_romfw_rev[1],
774 isp->isp_romfw_rev[2]);
777 mbs.param[0] = MBOX_GET_FIRMWARE_STATUS;
778 isp_mboxcmd(isp, &mbs, MBLOGALL);
779 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
782 isp->isp_maxcmds = mbs.param[2];
783 isp_prt(isp, ISP_LOGINFO,
784 "%d max I/O commands supported", mbs.param[2]);
788 * Set up DMA for the request and result mailboxes.
790 if (ISP_MBOXDMASETUP(isp) != 0) {
791 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
794 isp->isp_state = ISP_RESETSTATE;
797 * Okay- now that we have new firmware running, we now (re)set our
798 * notion of how many luns we support. This is somewhat tricky because
799 * if we haven't loaded firmware, we sometimes do not have an easy way
800 * of knowing how many luns we support.
802 * Expanded lun firmware gives you 32 luns for SCSI cards and
803 * 16384 luns for Fibre Channel cards.
805 * It turns out that even for QLogic 2100s with ROM 1.10 and above
806 * we do get a firmware attributes word returned in mailbox register 6.
808 * Because the lun is in a different position in the Request Queue
809 * Entry structure for Fibre Channel with expanded lun firmware, we
810 * can only support one lun (lun zero) when we don't know what kind
811 * of firmware we're running.
815 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
816 isp->isp_maxluns = 32;
818 isp->isp_maxluns = 8;
821 isp->isp_maxluns = 8;
824 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
825 isp->isp_maxluns = 16384;
827 isp->isp_maxluns = 16;
833 * Initialize Parameters of Hardware to a known state.
835 * Locks are held before coming here.
839 isp_init(struct ispsoftc *isp)
842 * Must do this first to get defaults established.
844 isp_setdfltparm(isp, 0);
845 if (IS_DUALBUS(isp)) {
846 isp_setdfltparm(isp, 1);
856 isp_scsi_init(struct ispsoftc *isp)
858 sdparam *sdp_chan0, *sdp_chan1;
861 sdp_chan0 = isp->isp_param;
862 sdp_chan1 = sdp_chan0;
863 if (IS_DUALBUS(isp)) {
868 * If we have no role (neither target nor initiator), return.
870 if (isp->isp_role == ISP_ROLE_NONE) {
874 /* First do overall per-card settings. */
877 * If we have fast memory timing enabled, turn it on.
879 if (sdp_chan0->isp_fast_mttr) {
880 ISP_WRITE(isp, RISC_MTR, 0x1313);
884 * Set Retry Delay and Count.
885 * You set both channels at the same time.
887 MEMZERO(&mbs, sizeof (mbs));
888 mbs.param[0] = MBOX_SET_RETRY_COUNT;
889 mbs.param[1] = sdp_chan0->isp_retry_count;
890 mbs.param[2] = sdp_chan0->isp_retry_delay;
891 mbs.param[6] = sdp_chan1->isp_retry_count;
892 mbs.param[7] = sdp_chan1->isp_retry_delay;
894 isp_mboxcmd(isp, &mbs, MBLOGALL);
895 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
900 * Set ASYNC DATA SETUP time. This is very important.
902 mbs.param[0] = MBOX_SET_ASYNC_DATA_SETUP_TIME;
903 mbs.param[1] = sdp_chan0->isp_async_data_setup;
904 mbs.param[2] = sdp_chan1->isp_async_data_setup;
905 isp_mboxcmd(isp, &mbs, MBLOGALL);
906 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
911 * Set ACTIVE Negation State.
913 mbs.param[0] = MBOX_SET_ACT_NEG_STATE;
915 (sdp_chan0->isp_req_ack_active_neg << 4) |
916 (sdp_chan0->isp_data_line_active_neg << 5);
918 (sdp_chan1->isp_req_ack_active_neg << 4) |
919 (sdp_chan1->isp_data_line_active_neg << 5);
921 isp_mboxcmd(isp, &mbs, MBLOGNONE);
922 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
923 isp_prt(isp, ISP_LOGERR,
924 "failed to set active negation state (%d,%d), (%d,%d)",
925 sdp_chan0->isp_req_ack_active_neg,
926 sdp_chan0->isp_data_line_active_neg,
927 sdp_chan1->isp_req_ack_active_neg,
928 sdp_chan1->isp_data_line_active_neg);
935 * Set the Tag Aging limit
937 mbs.param[0] = MBOX_SET_TAG_AGE_LIMIT;
938 mbs.param[1] = sdp_chan0->isp_tag_aging;
939 mbs.param[2] = sdp_chan1->isp_tag_aging;
940 isp_mboxcmd(isp, &mbs, MBLOGALL);
941 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
942 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
943 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
948 * Set selection timeout.
950 mbs.param[0] = MBOX_SET_SELECT_TIMEOUT;
951 mbs.param[1] = sdp_chan0->isp_selection_timeout;
952 mbs.param[2] = sdp_chan1->isp_selection_timeout;
953 isp_mboxcmd(isp, &mbs, MBLOGALL);
954 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
958 /* now do per-channel settings */
959 isp_scsi_channel_init(isp, 0);
961 isp_scsi_channel_init(isp, 1);
964 * Now enable request/response queues
967 if (IS_ULTRA2(isp) || IS_1240(isp)) {
968 mbs.param[0] = MBOX_INIT_RES_QUEUE_A64;
969 mbs.param[1] = RESULT_QUEUE_LEN(isp);
970 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
971 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
973 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
974 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
975 isp_mboxcmd(isp, &mbs, MBLOGALL);
976 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
979 isp->isp_residx = mbs.param[5];
981 mbs.param[0] = MBOX_INIT_REQ_QUEUE_A64;
982 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
983 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
984 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
986 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
987 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
988 isp_mboxcmd(isp, &mbs, MBLOGALL);
989 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
992 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
994 mbs.param[0] = MBOX_INIT_RES_QUEUE;
995 mbs.param[1] = RESULT_QUEUE_LEN(isp);
996 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
997 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
999 isp_mboxcmd(isp, &mbs, MBLOGALL);
1000 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1003 isp->isp_residx = mbs.param[5];
1005 mbs.param[0] = MBOX_INIT_REQ_QUEUE;
1006 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1007 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1008 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1010 isp_mboxcmd(isp, &mbs, MBLOGALL);
1011 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1014 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1018 * Turn on Fast Posting, LVD transitions
1020 * Ultra2 F/W always has had fast posting (and LVD transitions)
1022 * Ultra and older (i.e., SBus) cards may not. It's just safer
1023 * to assume not for them.
1026 mbs.param[0] = MBOX_SET_FW_FEATURES;
1029 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1031 if (IS_ULTRA2(isp) || IS_1240(isp))
1032 mbs.param[1] |= FW_FEATURE_RIO_16BIT;
1034 #ifndef ISP_NO_FASTPOST
1035 if (IS_ULTRA2(isp) || IS_1240(isp))
1036 mbs.param[1] |= FW_FEATURE_FAST_POST;
1039 if (mbs.param[1] != 0) {
1040 u_int16_t sfeat = mbs.param[1];
1041 isp_mboxcmd(isp, &mbs, MBLOGALL);
1042 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1043 isp_prt(isp, ISP_LOGINFO,
1044 "Enabled FW features (0x%x)", sfeat);
1049 * Let the outer layers decide whether to issue a SCSI bus reset.
1051 isp->isp_state = ISP_INITSTATE;
1055 isp_scsi_channel_init(struct ispsoftc *isp, int channel)
1061 sdp = isp->isp_param;
1065 * Set (possibly new) Initiator ID.
1067 MEMZERO(&mbs, sizeof (mbs));
1068 mbs.param[0] = MBOX_SET_INIT_SCSI_ID;
1069 mbs.param[1] = (channel << 7) | sdp->isp_initiator_id;
1070 isp_mboxcmd(isp, &mbs, MBLOGALL);
1071 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1074 isp_prt(isp, ISP_LOGINFO, "Initiator ID is %d on Channel %d",
1075 sdp->isp_initiator_id, channel);
1079 * Set current per-target parameters to an initial safe minimum.
1081 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1085 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1088 #ifndef ISP_TARGET_MODE
1089 sdf = sdp->isp_devparam[tgt].goal_flags;
1090 sdf &= DPARM_SAFE_DFLT;
1092 * It is not quite clear when this changed over so that
1093 * we could force narrow and async for 1000/1020 cards,
1094 * but assume that this is only the case for loaded
1097 if (isp->isp_loaded_fw) {
1098 sdf |= DPARM_NARROW | DPARM_ASYNC;
1102 * The !$*!)$!$)* f/w uses the same index into some
1103 * internal table to decide how to respond to negotiations,
1104 * so if we've said "let's be safe" for ID X, and ID X
1105 * selects *us*, the negotiations will back to 'safe'
1106 * (as in narrow/async). What the f/w *should* do is
1107 * use the initiator id settings to decide how to respond.
1109 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1111 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1112 mbs.param[1] = (channel << 15) | (tgt << 8);
1114 if ((sdf & DPARM_SYNC) == 0) {
1118 (sdp->isp_devparam[tgt].goal_offset << 8) |
1119 (sdp->isp_devparam[tgt].goal_period);
1121 isp_prt(isp, ISP_LOGDEBUG0,
1122 "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1123 channel, tgt, mbs.param[2], mbs.param[3] >> 8,
1124 mbs.param[3] & 0xff);
1125 isp_mboxcmd(isp, &mbs, MBLOGNONE);
1126 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1127 sdf = DPARM_SAFE_DFLT;
1128 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1129 mbs.param[1] = (tgt << 8) | (channel << 15);
1132 isp_mboxcmd(isp, &mbs, MBLOGALL);
1133 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1139 * We don't update any information directly from the f/w
1140 * because we need to run at least one command to cause a
1141 * new state to be latched up. So, we just assume that we
1142 * converge to the values we just had set.
1144 * Ensure that we don't believe tagged queuing is enabled yet.
1145 * It turns out that sometimes the ISP just ignores our
1146 * attempts to set parameters for devices that it hasn't
1149 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1150 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1151 mbs.param[0] = MBOX_SET_DEV_QUEUE_PARAMS;
1152 mbs.param[1] = (channel << 15) | (tgt << 8) | lun;
1153 mbs.param[2] = sdp->isp_max_queue_depth;
1154 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1155 isp_mboxcmd(isp, &mbs, MBLOGALL);
1156 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1161 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1162 if (sdp->isp_devparam[tgt].dev_refresh) {
1163 isp->isp_sendmarker |= (1 << channel);
1164 isp->isp_update |= (1 << channel);
1171 * Fibre Channel specific initialization.
1173 * Locks are held before coming here.
1176 isp_fibre_init(struct ispsoftc *isp)
1179 isp_icb_t local, *icbp = &local;
1182 u_int64_t nwwn, pwwn;
1184 fcp = isp->isp_param;
1187 * Do this *before* initializing the firmware.
1189 isp_mark_getpdb_all(isp);
1190 fcp->isp_fwstate = FW_CONFIG_WAIT;
1191 fcp->isp_loopstate = LOOP_NIL;
1194 * If we have no role (neither target nor initiator), return.
1196 if (isp->isp_role == ISP_ROLE_NONE) {
1200 loopid = fcp->isp_loopid;
1201 MEMZERO(icbp, sizeof (*icbp));
1202 icbp->icb_version = ICB_VERSION1;
1205 * Firmware Options are either retrieved from NVRAM or
1206 * are patched elsewhere. We check them for sanity here
1207 * and make changes based on board revision, but otherwise
1208 * let others decide policy.
1212 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1214 if ((isp->isp_type == ISP_HA_FC_2100) && isp->isp_revision < 5) {
1215 fcp->isp_fwoptions &= ~ICBOPT_FAIRNESS;
1219 * We have to use FULL LOGIN even though it resets the loop too much
1220 * because otherwise port database entries don't get updated after
1221 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1223 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1224 fcp->isp_fwoptions |= ICBOPT_FULL_LOGIN;
1228 * Insist on Port Database Update Async notifications
1230 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
1233 * Make sure that target role reflects into fwoptions.
1235 if (isp->isp_role & ISP_ROLE_TARGET) {
1236 fcp->isp_fwoptions |= ICBOPT_TGT_ENABLE;
1238 fcp->isp_fwoptions &= ~ICBOPT_TGT_ENABLE;
1241 if (isp->isp_role & ISP_ROLE_INITIATOR) {
1242 fcp->isp_fwoptions &= ~ICBOPT_INI_DISABLE;
1244 fcp->isp_fwoptions |= ICBOPT_INI_DISABLE;
1248 * Propagate all of this into the ICB structure.
1250 icbp->icb_fwoptions = fcp->isp_fwoptions;
1251 icbp->icb_maxfrmlen = fcp->isp_maxfrmlen;
1252 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN ||
1253 icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1254 isp_prt(isp, ISP_LOGERR,
1255 "bad frame length (%d) from NVRAM- using %d",
1256 fcp->isp_maxfrmlen, ICB_DFLT_FRMLEN);
1257 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1259 icbp->icb_maxalloc = fcp->isp_maxalloc;
1260 if (icbp->icb_maxalloc < 1) {
1261 isp_prt(isp, ISP_LOGERR,
1262 "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1263 icbp->icb_maxalloc = 16;
1265 icbp->icb_execthrottle = fcp->isp_execthrottle;
1266 if (icbp->icb_execthrottle < 1) {
1267 isp_prt(isp, ISP_LOGERR,
1268 "bad execution throttle of %d- using 16",
1269 fcp->isp_execthrottle);
1270 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1272 icbp->icb_retry_delay = fcp->isp_retry_delay;
1273 icbp->icb_retry_count = fcp->isp_retry_count;
1274 icbp->icb_hardaddr = loopid;
1275 if (icbp->icb_hardaddr >= 125) {
1277 * We end up with these Loop IDs for F-Port topologies
1279 if (icbp->icb_hardaddr != 0xff || icbp->icb_hardaddr != 0x800) {
1280 isp_prt(isp, ISP_LOGERR,
1281 "bad hard address %u- resetting to zero",
1282 icbp->icb_hardaddr);
1284 icbp->icb_hardaddr = 0;
1287 * Right now we just set extended options to prefer point-to-point
1288 * over loop based upon some soft config options.
1290 * NB: for the 2300, ICBOPT_EXTENDED is required.
1292 if (IS_2200(isp) || IS_23XX(isp)) {
1293 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1295 * Prefer or force Point-To-Point instead Loop?
1297 switch(isp->isp_confopts & ISP_CFG_PORT_PREF) {
1299 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1301 case ISP_CFG_NPORT_ONLY:
1302 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1304 case ISP_CFG_LPORT_ONLY:
1305 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1308 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1313 * QLogic recommends that FAST Posting be turned
1314 * off for 23XX cards and instead allow the HBA
1315 * to write response queue entries and interrupt
1316 * after a delay (ZIO).
1318 * If we set ZIO, it will disable fast posting,
1319 * so we don't need to clear it in fwoptions.
1321 * Depending on the role we're selecting, we
1322 * chose fast posting or not as it still is
1323 * a win for target mode.
1326 if (isp->isp_role == ISP_ROLE_TARGET) {
1327 icbp->icb_fwoptions |= ICBOPT_FAST_POST;
1329 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1332 icbp->icb_fwoptions |= ICBOPT_FAST_POST;
1336 * Values, in 100us increments. The default
1337 * is 2 (200us) if a value 0 (default) is
1340 icbp->icb_idelaytimer = 2;
1343 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1344 icbp->icb_zfwoptions |= ICBZOPT_RATE_ONEGB;
1345 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1346 icbp->icb_zfwoptions |= ICBZOPT_RATE_TWOGB;
1348 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1353 #ifndef ISP_NO_RIO_FC
1355 * RIO seems to be enabled in 2100s for fw >= 1.17.0.
1357 * I've had some questionable problems with RIO on 2200.
1358 * More specifically, on a 2204 I had problems with RIO
1359 * on a Linux system where I was dropping commands right
1360 * and left. It's not clear to me what the actual problem
1363 * 23XX Cards do not support RIO. Instead they support ZIO.
1366 if (!IS_23XX(isp) && ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1367 icbp->icb_xfwoptions |= ICBXOPT_RIO_16BIT;
1368 icbp->icb_racctimer = 4;
1369 icbp->icb_idelaytimer = 8;
1374 MEMZERO(&mbs, sizeof (mbs));
1377 * For 22XX > 2.1.26 && 23XX, set some options.
1378 * XXX: Probably okay for newer 2100 f/w too.
1380 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1382 * Turn on LIP F8 async event (1)
1383 * Turn on generate AE 8013 on all LIP Resets (2)
1384 * Disable LIP F7 switching (8)
1386 mbs.param[0] = MBOX_SET_FIRMWARE_OPTIONS;
1390 isp_mboxcmd(isp, &mbs, MBLOGALL);
1392 icbp->icb_logintime = 30; /* 30 second login timeout */
1395 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
1396 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
1397 ISP_WRITE(isp, isp->isp_respinrp, 0);
1398 ISP_WRITE(isp, isp->isp_respoutrp, 0);
1401 nwwn = ISP_NODEWWN(isp);
1402 pwwn = ISP_PORTWWN(isp);
1404 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1405 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, nwwn);
1406 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, pwwn);
1407 isp_prt(isp, ISP_LOGDEBUG1,
1408 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1409 ((u_int32_t) (nwwn >> 32)),
1410 ((u_int32_t) (nwwn & 0xffffffff)),
1411 ((u_int32_t) (pwwn >> 32)),
1412 ((u_int32_t) (pwwn & 0xffffffff)));
1414 isp_prt(isp, ISP_LOGDEBUG1, "Not using any WWNs");
1415 icbp->icb_fwoptions &= ~(ICBOPT_BOTH_WWNS|ICBOPT_FULL_LOGIN);
1417 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1418 if (icbp->icb_rqstqlen < 1) {
1419 isp_prt(isp, ISP_LOGERR, "bad request queue length");
1421 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1422 if (icbp->icb_rsltqlen < 1) {
1423 isp_prt(isp, ISP_LOGERR, "bad result queue length");
1425 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1426 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1427 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1428 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1429 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1430 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1431 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1432 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1433 isp_prt(isp, ISP_LOGDEBUG0,
1434 "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1435 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1437 FC_SCRATCH_ACQUIRE(isp);
1438 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1443 mbs.param[0] = MBOX_INIT_FIRMWARE;
1445 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1446 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1449 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1450 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1451 isp_mboxcmd(isp, &mbs, MBLOGALL);
1452 FC_SCRATCH_RELEASE(isp);
1453 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1456 isp->isp_reqidx = isp->isp_reqodx = 0;
1457 isp->isp_residx = 0;
1458 isp->isp_sendmarker = 1;
1461 * Whatever happens, we're now committed to being here.
1463 isp->isp_state = ISP_INITSTATE;
1467 * Fibre Channel Support- get the port database for the id.
1469 * Locks are held before coming here. Return 0 if success,
1474 isp_getmap(struct ispsoftc *isp, fcpos_map_t *map)
1476 fcparam *fcp = (fcparam *) isp->isp_param;
1479 MEMZERO(&mbs, sizeof (mbs));
1480 mbs.param[0] = MBOX_GET_FC_AL_POSITION_MAP;
1482 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1483 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1485 * Unneeded. For the 2100, except for initializing f/w, registers
1486 * 4/5 have to not be written to.
1493 FC_SCRATCH_ACQUIRE(isp);
1494 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1495 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1496 MEMCPY(map, fcp->isp_scratch, sizeof (fcpos_map_t));
1497 map->fwmap = mbs.param[1] != 0;
1498 FC_SCRATCH_RELEASE(isp);
1501 FC_SCRATCH_RELEASE(isp);
1506 isp_mark_getpdb_all(struct ispsoftc *isp)
1508 fcparam *fcp = (fcparam *) isp->isp_param;
1510 for (i = 0; i < MAX_FC_TARG; i++) {
1511 fcp->portdb[i].valid = fcp->portdb[i].fabric_dev = 0;
1516 isp_getpdb(struct ispsoftc *isp, int id, isp_pdb_t *pdbp)
1518 fcparam *fcp = (fcparam *) isp->isp_param;
1521 MEMZERO(&mbs, sizeof (mbs));
1522 mbs.param[0] = MBOX_GET_PORT_DB;
1523 if (IS_2KLOGIN(isp)) {
1525 mbs.obits |= (1 << 10);
1527 mbs.param[1] = id << 8;
1529 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1530 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1532 * Unneeded. For the 2100, except for initializing f/w, registers
1533 * 4/5 have to not be written to.
1538 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1539 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1540 FC_SCRATCH_ACQUIRE(isp);
1541 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1542 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1543 isp_get_pdb(isp, (isp_pdb_t *)fcp->isp_scratch, pdbp);
1544 FC_SCRATCH_RELEASE(isp);
1547 FC_SCRATCH_RELEASE(isp);
1552 isp_get_portname(struct ispsoftc *isp, int loopid, int nodename)
1557 MEMZERO(&mbs, sizeof (mbs));
1558 mbs.param[0] = MBOX_GET_PORT_NAME;
1559 if (IS_2KLOGIN(isp)) {
1560 mbs.param[1] = loopid;
1563 mbs.obits |= (1 << 10);
1565 mbs.param[1] = loopid << 8;
1569 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1570 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1572 (((u_int64_t)(mbs.param[2] & 0xff)) << 56) |
1573 (((u_int64_t)(mbs.param[2] >> 8)) << 48) |
1574 (((u_int64_t)(mbs.param[3] & 0xff)) << 40) |
1575 (((u_int64_t)(mbs.param[3] >> 8)) << 32) |
1576 (((u_int64_t)(mbs.param[6] & 0xff)) << 24) |
1577 (((u_int64_t)(mbs.param[6] >> 8)) << 16) |
1578 (((u_int64_t)(mbs.param[7] & 0xff)) << 8) |
1579 (((u_int64_t)(mbs.param[7] >> 8)));
1585 * Make sure we have good FC link and know our Loop ID.
1589 isp_fclink_test(struct ispsoftc *isp, int usdelay)
1591 static char *toponames[] = {
1596 "F Port (no FLOGI_ACC response)"
1599 int count, check_for_fabric;
1605 fcp = isp->isp_param;
1608 * XXX: Here is where we would start a 'loop dead' timeout
1612 * Wait up to N microseconds for F/W to go to a ready state.
1614 lwfs = FW_CONFIG_WAIT;
1616 while (count < usdelay) {
1619 NANOTIME_T hra, hrb;
1623 if (lwfs != fcp->isp_fwstate) {
1624 isp_prt(isp, ISP_LOGINFO, "Firmware State <%s->%s>",
1625 isp2100_fw_statename((int)lwfs),
1626 isp2100_fw_statename((int)fcp->isp_fwstate));
1627 lwfs = fcp->isp_fwstate;
1629 if (fcp->isp_fwstate == FW_READY) {
1635 * Get the elapsed time in nanoseconds.
1636 * Always guaranteed to be non-zero.
1638 enano = NANOTIME_SUB(&hrb, &hra);
1640 isp_prt(isp, ISP_LOGDEBUG1,
1641 "usec%d: 0x%lx->0x%lx enano 0x%x%08x",
1642 count, (long) GET_NANOSEC(&hra), (long) GET_NANOSEC(&hrb),
1643 (u_int32_t)(enano >> 32), (u_int32_t)(enano & 0xffffffff));
1646 * If the elapsed time is less than 1 millisecond,
1647 * delay a period of time up to that millisecond of
1650 * This peculiar code is an attempt to try and avoid
1651 * invoking u_int64_t math support functions for some
1652 * platforms where linkage is a problem.
1654 if (enano < (1000 * 1000)) {
1656 enano = (1000 * 1000) - enano;
1657 while (enano > (u_int64_t) 4000000000U) {
1658 USEC_SLEEP(isp, 4000000);
1659 enano -= (u_int64_t) 4000000000U;
1663 USEC_SLEEP(isp, wrk);
1665 while (enano > (u_int64_t) 4000000000U) {
1667 enano -= (u_int64_t) 4000000000U;
1670 count += (wrk / 1000);
1675 * If we haven't gone to 'ready' state, return.
1677 if (fcp->isp_fwstate != FW_READY) {
1682 * Get our Loop ID (if possible). We really need to have it.
1684 MEMZERO(&mbs, sizeof (mbs));
1685 mbs.param[0] = MBOX_GET_LOOP_ID;
1686 isp_mboxcmd(isp, &mbs, MBLOGALL);
1687 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1690 fcp->isp_loopid = mbs.param[1];
1691 if (fcp->isp_loopid == 0xffff) { /* happens with 2k login f/w */
1692 fcp->isp_loopid = MAX_FC_TARG-1;
1693 } else if (fcp->isp_loopid >= MAX_FC_TARG) {
1694 isp_prt(isp, ISP_LOGWARN, "bad initiator loopid (0x%x)", fcp->isp_loopid);
1695 fcp->isp_loopid = MAX_FC_TARG-1;
1697 if (IS_2200(isp) || IS_23XX(isp)) {
1698 int topo = (int) mbs.param[6];
1699 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB)
1700 topo = TOPO_PTP_STUB;
1701 fcp->isp_topo = topo;
1703 fcp->isp_topo = TOPO_NL_PORT;
1708 fcp->isp_portid = mbs.param[2] | (mbs.param[3] << 16);
1711 * Check to see if we're on a fabric by trying to see if we
1712 * can talk to the fabric name server. This can be a bit
1713 * tricky because if we're a 2100, we should check always
1714 * (in case we're connected to a server doing aliasing).
1716 fcp->isp_onfabric = 0;
1720 * Don't bother with fabric if we are using really old
1721 * 2100 firmware. It's just not worth it.
1723 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37)) {
1724 check_for_fabric = 1;
1726 check_for_fabric = 0;
1728 } else if (fcp->isp_topo == TOPO_FL_PORT ||
1729 fcp->isp_topo == TOPO_F_PORT) {
1730 check_for_fabric = 1;
1732 check_for_fabric = 0;
1734 if (check_for_fabric && isp_getpdb(isp, FL_PORT_ID, &pdb) == 0) {
1735 int loopid = FL_PORT_ID;
1737 fcp->isp_topo = TOPO_FL_PORT;
1740 if (BITS2WORD(pdb.pdb_portid_bits) == 0) {
1744 fcp->isp_topo = TOPO_NL_PORT;
1747 fcp->isp_portid = mbs.param[2] | ((int) mbs.param[3] << 16);
1750 * Save the Fabric controller's port database entry.
1752 lp = &fcp->portdb[loopid];
1754 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1755 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1756 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1757 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1758 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1759 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1760 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1761 (((u_int64_t)pdb.pdb_nodename[7]));
1763 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1764 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1765 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1766 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1767 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1768 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1769 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1770 (((u_int64_t)pdb.pdb_portname[7]));
1772 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
1773 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
1774 lp->loopid = pdb.pdb_loopid;
1775 lp->loggedin = lp->valid = 1;
1776 fcp->isp_onfabric = 1;
1777 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1778 isp_register_fc4_type(isp);
1781 fcp->isp_onfabric = 0;
1782 fcp->portdb[FL_PORT_ID].valid = 0;
1785 fcp->isp_gbspeed = 1;
1787 mbs.param[0] = MBOX_GET_SET_DATA_RATE;
1788 mbs.param[1] = MBGSD_GET_RATE;
1789 /* mbs.param[2] undefined if we're just getting rate */
1790 isp_mboxcmd(isp, &mbs, MBLOGALL);
1791 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1792 if (mbs.param[1] == MBGSD_TWOGB) {
1793 isp_prt(isp, ISP_LOGINFO, "2Gb link speed/s");
1794 fcp->isp_gbspeed = 2;
1799 isp_prt(isp, ISP_LOGCONFIG, topology, fcp->isp_loopid,
1800 fcp->isp_portid, fcp->isp_loopstate, toponames[fcp->isp_topo]);
1803 * Announce ourselves, too. This involves synthesizing an entry.
1805 if (fcp->isp_iid_set == 0) {
1806 fcp->isp_iid_set = 1;
1807 fcp->isp_iid = fcp->isp_loopid;
1808 lp = &fcp->portdb[fcp->isp_iid];
1810 lp = &fcp->portdb[fcp->isp_iid];
1811 if (fcp->isp_portid != lp->portid ||
1812 fcp->isp_loopid != lp->loopid ||
1813 fcp->isp_nodewwn != ISP_NODEWWN(isp) ||
1814 fcp->isp_portwwn != ISP_PORTWWN(isp)) {
1816 count = fcp->isp_iid;
1817 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1820 lp->loopid = fcp->isp_loopid;
1821 lp->portid = fcp->isp_portid;
1822 lp->node_wwn = ISP_NODEWWN(isp);
1823 lp->port_wwn = ISP_PORTWWN(isp);
1824 switch (isp->isp_role) {
1828 case ISP_ROLE_TARGET:
1829 lp->roles = SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT;
1831 case ISP_ROLE_INITIATOR:
1832 lp->roles = SVC3_INI_ROLE >> SVC3_ROLE_SHIFT;
1835 lp->roles = (SVC3_INI_ROLE|SVC3_TGT_ROLE) >> SVC3_ROLE_SHIFT;
1838 lp->loggedin = lp->valid = 1;
1839 count = fcp->isp_iid;
1840 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1845 isp2100_fw_statename(int state)
1848 case FW_CONFIG_WAIT: return "Config Wait";
1849 case FW_WAIT_AL_PA: return "Waiting for AL_PA";
1850 case FW_WAIT_LOGIN: return "Wait Login";
1851 case FW_READY: return "Ready";
1852 case FW_LOSS_OF_SYNC: return "Loss Of Sync";
1853 case FW_ERROR: return "Error";
1854 case FW_REINIT: return "Re-Init";
1855 case FW_NON_PART: return "Nonparticipating";
1856 default: return "?????";
1861 * Synchronize our soft copy of the port database with what the f/w thinks
1862 * (with a view toward possibly for a specific target....)
1866 isp_pdb_sync(struct ispsoftc *isp)
1869 fcparam *fcp = isp->isp_param;
1871 int loopid, base, lim;
1874 * Make sure we're okay for doing this right now.
1876 if (fcp->isp_loopstate != LOOP_PDB_RCVD &&
1877 fcp->isp_loopstate != LOOP_FSCAN_DONE &&
1878 fcp->isp_loopstate != LOOP_LSCAN_DONE) {
1882 if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_NL_PORT ||
1883 fcp->isp_topo == TOPO_N_PORT) {
1884 if (fcp->isp_loopstate < LOOP_LSCAN_DONE) {
1885 if (isp_scan_loop(isp) != 0) {
1890 fcp->isp_loopstate = LOOP_SYNCING_PDB;
1893 * If we get this far, we've settled our differences with the f/w
1894 * (for local loop device) and we can say that the loop state is ready.
1897 if (fcp->isp_topo == TOPO_NL_PORT) {
1898 fcp->loop_seen_once = 1;
1899 fcp->isp_loopstate = LOOP_READY;
1904 * Find all Fabric Entities that didn't make it from one scan to the
1905 * next and let the world know they went away. Scan the whole database.
1907 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[MAX_FC_TARG]; lp++) {
1908 if (lp->was_fabric_dev && lp->fabric_dev == 0) {
1909 loopid = lp - fcp->portdb;
1910 lp->valid = 0; /* should already be set */
1911 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1912 MEMZERO((void *) lp, sizeof (*lp));
1915 lp->was_fabric_dev = lp->fabric_dev;
1918 if (fcp->isp_topo == TOPO_FL_PORT)
1923 if (fcp->isp_topo == TOPO_N_PORT)
1929 * Now log in any fabric devices that the outer layer has
1930 * left for us to see. This seems the most sane policy
1933 for (lp = &fcp->portdb[base]; lp < &fcp->portdb[lim]; lp++) {
1937 loopid = lp - fcp->portdb;
1938 if (loopid >= FL_PORT_ID && loopid <= FC_SNS_ID) {
1945 if (lp->port_wwn == 0) {
1950 * Don't try to log into yourself.
1952 if ((portid = lp->portid) == fcp->isp_portid) {
1958 * If we'd been logged in- see if we still are and we haven't
1959 * changed. If so, no need to log ourselves out, etc..
1961 * Unfortunately, our charming Qlogic f/w has decided to
1962 * return a valid port database entry for a fabric device
1963 * that has, in fact, gone away. And it hangs trying to
1966 if (lp->loggedin && lp->force_logout == 0 &&
1967 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
1969 u_int64_t nwwnn, nwwpn;
1971 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1972 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1973 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1974 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1975 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1976 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1977 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1978 (((u_int64_t)pdb.pdb_nodename[7]));
1980 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1981 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1982 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1983 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1984 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1985 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1986 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1987 (((u_int64_t)pdb.pdb_portname[7]));
1988 nrole = (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >>
1990 if (pdb.pdb_loopid == lp->loopid && lp->portid ==
1991 (u_int32_t) BITS2WORD(pdb.pdb_portid_bits) &&
1992 nwwnn == lp->node_wwn && nwwpn == lp->port_wwn &&
1993 lp->roles == nrole && lp->force_logout == 0) {
1994 lp->loggedin = lp->valid = 1;
1995 isp_prt(isp, ISP_LOGCONFIG, lretained,
1996 (int) (lp - fcp->portdb),
1997 (int) lp->loopid, lp->portid);
2002 if (fcp->isp_fwstate != FW_READY ||
2003 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2008 * Force a logout if we were logged in.
2011 if (lp->force_logout ||
2012 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
2013 MEMZERO(&mbs, sizeof (mbs));
2014 mbs.param[0] = MBOX_FABRIC_LOGOUT;
2015 if (IS_2KLOGIN(isp)) {
2016 mbs.param[1] = lp->loopid;
2017 mbs.obits |= (1 << 10);
2019 mbs.param[1] = lp->loopid << 8;
2023 isp_mboxcmd(isp, &mbs, MBLOGNONE);
2024 isp_prt(isp, ISP_LOGINFO, plogout,
2025 (int) (lp - fcp->portdb), lp->loopid,
2028 lp->force_logout = lp->loggedin = 0;
2029 if (fcp->isp_fwstate != FW_READY ||
2030 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2038 loopid = lp - fcp->portdb;
2039 lp->loopid = FL_PORT_ID;
2041 MEMZERO(&mbs, sizeof (mbs));
2042 mbs.param[0] = MBOX_FABRIC_LOGIN;
2043 if (IS_2KLOGIN(isp)) {
2044 mbs.param[1] = loopid;
2045 mbs.obits |= (1 << 10);
2047 mbs.param[1] = loopid << 8;
2049 mbs.param[2] = portid >> 16;
2050 mbs.param[3] = portid & 0xffff;
2051 isp_mboxcmd(isp, &mbs, MBLOGALL & ~(MBOX_LOOP_ID_USED |
2052 MBOX_PORT_ID_USED | MBOX_COMMAND_ERROR));
2053 if (fcp->isp_fwstate != FW_READY ||
2054 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2057 switch (mbs.param[0]) {
2058 case MBOX_LOOP_ID_USED:
2060 * Try the next available loop id.
2064 case MBOX_PORT_ID_USED:
2066 * This port is already logged in.
2067 * Snaffle the loop id it's using if it's
2068 * nonzero, otherwise we're hosed.
2070 if (mbs.param[1] != 0) {
2071 loopid = mbs.param[1];
2072 if (loopid >= MAX_FC_TARG) {
2073 loopid = MAX_FC_TARG;
2076 isp_prt(isp, ISP_LOGINFO, retained,
2077 loopid, (int) (lp - fcp->portdb),
2080 loopid = MAX_FC_TARG;
2084 case MBOX_COMMAND_COMPLETE:
2086 lp->loopid = loopid;
2088 case MBOX_COMMAND_ERROR:
2089 isp_prt(isp, ISP_LOGINFO, plogierr,
2090 portid, mbs.param[1]);
2092 case MBOX_ALL_IDS_USED: /* We're outta IDs */
2094 loopid = MAX_FC_TARG;
2097 } while (lp->loopid == FL_PORT_ID && loopid < MAX_FC_TARG);
2100 * If we get here and we haven't set a Loop ID,
2101 * we failed to log into this device.
2104 if (lp->loopid == FL_PORT_ID) {
2110 * Make sure we can get the approriate port information.
2112 if (isp_getpdb(isp, lp->loopid, &pdb) != 0) {
2113 isp_prt(isp, ISP_LOGWARN, nopdb, lp->portid);
2117 if (fcp->isp_fwstate != FW_READY ||
2118 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2122 if (pdb.pdb_loopid != lp->loopid) {
2123 isp_prt(isp, ISP_LOGWARN, pdbmfail1,
2124 lp->portid, pdb.pdb_loopid);
2128 if (lp->portid != (u_int32_t) BITS2WORD(pdb.pdb_portid_bits)) {
2129 isp_prt(isp, ISP_LOGWARN, pdbmfail2,
2130 lp->portid, BITS2WORD(pdb.pdb_portid_bits));
2135 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2137 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
2138 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
2139 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
2140 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
2141 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
2142 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
2143 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
2144 (((u_int64_t)pdb.pdb_nodename[7]));
2146 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
2147 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
2148 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
2149 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
2150 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
2151 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
2152 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
2153 (((u_int64_t)pdb.pdb_portname[7]));
2155 * Check to make sure this all makes sense.
2157 if (lp->node_wwn && lp->port_wwn) {
2159 loopid = lp - fcp->portdb;
2160 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2165 isp_prt(isp, ISP_LOGINFO,
2166 ldumped, loopid, lp->loopid, lp->portid);
2167 MEMZERO(&mbs, sizeof (mbs));
2168 mbs.param[0] = MBOX_FABRIC_LOGOUT;
2169 if (IS_2KLOGIN(isp)) {
2170 mbs.param[1] = lp->loopid;
2171 mbs.obits |= (1 << 10);
2173 mbs.param[1] = lp->loopid << 8;
2175 isp_mboxcmd(isp, &mbs, MBLOGNONE);
2176 if (fcp->isp_fwstate != FW_READY ||
2177 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2182 * If we get here, we've for sure seen not only a valid loop
2183 * but know what is or isn't on it, so mark this for usage
2186 fcp->loop_seen_once = 1;
2187 fcp->isp_loopstate = LOOP_READY;
2192 isp_scan_loop(struct ispsoftc *isp)
2195 fcparam *fcp = isp->isp_param;
2197 int loopid, lim, hival;
2199 switch (fcp->isp_topo) {
2210 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2213 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
2216 * make sure the temp port database is clean...
2218 MEMZERO((void *)fcp->tport, sizeof (fcp->tport));
2221 * Run through the local loop ports and get port database info
2224 * There's a somewhat unexplained situation where the f/w passes back
2225 * the wrong database entity- if that happens, just restart (up to
2226 * FL_PORT_ID times).
2228 for (lim = loopid = 0; loopid < hival; loopid++) {
2229 lp = &fcp->tport[loopid];
2232 * Don't even try for ourselves...
2234 if (loopid == fcp->isp_loopid)
2237 lp->node_wwn = isp_get_portname(isp, loopid, 1);
2238 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2240 if (lp->node_wwn == 0)
2242 lp->port_wwn = isp_get_portname(isp, loopid, 0);
2243 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2245 if (lp->port_wwn == 0) {
2253 if (isp_getpdb(isp, loopid, &pdb) != 0) {
2254 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2258 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2263 * If the returned database element doesn't match what we
2264 * asked for, restart the process entirely (up to a point...).
2266 if (pdb.pdb_loopid != loopid) {
2268 if (lim++ < hival) {
2271 isp_prt(isp, ISP_LOGWARN,
2272 "giving up on synchronizing the port database");
2277 * Save the pertinent info locally.
2280 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
2281 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
2282 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
2283 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
2284 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
2285 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
2286 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
2287 (((u_int64_t)pdb.pdb_nodename[7]));
2289 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
2290 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
2291 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
2292 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
2293 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
2294 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
2295 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
2296 (((u_int64_t)pdb.pdb_portname[7]));
2298 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2299 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
2300 lp->loopid = pdb.pdb_loopid;
2304 * Mark all of the permanent local loop database entries as invalid
2305 * (except our own entry).
2307 for (loopid = 0; loopid < hival; loopid++) {
2308 if (loopid == fcp->isp_iid) {
2309 fcp->portdb[loopid].valid = 1;
2310 fcp->portdb[loopid].loopid = fcp->isp_loopid;
2313 fcp->portdb[loopid].valid = 0;
2317 * Now merge our local copy of the port database into our saved copy.
2318 * Notify the outer layers of new devices arriving.
2320 for (loopid = 0; loopid < hival; loopid++) {
2324 * If we don't have a non-zero Port WWN, we're not here.
2326 if (fcp->tport[loopid].port_wwn == 0) {
2333 if (loopid == fcp->isp_iid) {
2338 * For the purposes of deciding whether this is the
2339 * 'same' device or not, we only search for an identical
2340 * Port WWN. Node WWNs may or may not be the same as
2341 * the Port WWN, and there may be multiple different
2342 * Port WWNs with the same Node WWN. It would be chaos
2343 * to have multiple identical Port WWNs, so we don't
2347 for (i = 0; i < hival; i++) {
2349 if (fcp->portdb[i].port_wwn == 0)
2351 if (fcp->portdb[i].port_wwn !=
2352 fcp->tport[loopid].port_wwn)
2355 * We found this WWN elsewhere- it's changed
2356 * loopids then. We don't change it's actual
2357 * position in our cached port database- we
2358 * just change the actual loop ID we'd use.
2360 if (fcp->portdb[i].loopid != loopid) {
2361 isp_prt(isp, ISP_LOGINFO, portshift, i,
2362 fcp->portdb[i].loopid,
2363 fcp->portdb[i].portid, loopid,
2364 fcp->tport[loopid].portid);
2366 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2367 fcp->portdb[i].loopid = loopid;
2368 fcp->portdb[i].valid = 1;
2369 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2372 * Now make sure this Port WWN doesn't exist elsewhere
2373 * in the port database.
2375 for (j = i+1; j < hival; j++) {
2376 if (fcp->portdb[i].port_wwn !=
2377 fcp->portdb[j].port_wwn) {
2380 isp_prt(isp, ISP_LOGWARN, portdup, j, i);
2382 * Invalidate the 'old' *and* 'new' ones.
2383 * This is really harsh and not quite right,
2384 * but if this happens, we really don't know
2385 * who is what at this point.
2387 fcp->portdb[i].valid = 0;
2388 fcp->portdb[j].valid = 0;
2394 * If we didn't traverse the entire port database,
2395 * then we found (and remapped) an existing entry.
2396 * No need to notify anyone- go for the next one.
2399 isp_prt(isp, ISP_LOGINFO, retained,
2400 fcp->portdb[i].loopid, i, fcp->portdb[i].portid);
2405 * We've not found this Port WWN anywhere. It's a new entry.
2406 * See if we can leave it where it is (with target == loopid).
2408 if (fcp->portdb[loopid].port_wwn != 0) {
2409 for (lim = 0; lim < hival; lim++) {
2410 if (fcp->portdb[lim].port_wwn == 0)
2413 /* "Cannot Happen" */
2415 isp_prt(isp, ISP_LOGWARN, "Remap Overflow");
2424 * NB: The actual loopid we use here is loopid- we may
2425 * in fact be at a completely different index (target).
2427 fcp->portdb[i].loopid = loopid;
2428 fcp->portdb[i].port_wwn = fcp->tport[loopid].port_wwn;
2429 fcp->portdb[i].node_wwn = fcp->tport[loopid].node_wwn;
2430 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2431 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2432 fcp->portdb[i].valid = 1;
2435 * Tell the outside world we've arrived.
2437 (void) isp_async(isp, ISPASYNC_PROMENADE, &i);
2441 * Now find all previously used targets that are now invalid and
2442 * notify the outer layers that they're gone.
2444 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[hival]; lp++) {
2445 if (lp->valid || lp->port_wwn == 0) {
2450 * Tell the outside world we've gone
2451 * away and erase our pdb entry.
2454 loopid = lp - fcp->portdb;
2455 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2456 MEMZERO((void *) lp, sizeof (*lp));
2458 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2464 isp_fabric_mbox_cmd(struct ispsoftc *isp, mbreg_t *mbp)
2466 isp_mboxcmd(isp, mbp, MBLOGNONE);
2467 if (mbp->param[0] != MBOX_COMMAND_COMPLETE) {
2468 if (FCPARAM(isp)->isp_loopstate == LOOP_SCANNING_FABRIC) {
2469 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
2471 if (mbp->param[0] == MBOX_COMMAND_ERROR) {
2474 switch (mbp->param[1]) {
2479 m = "Failed to allocate IOCB buffer";
2482 m = "Failed to allocate XCB buffer";
2485 m = "timeout or transmit failed";
2488 m = "no fabric loop";
2491 m = "remote device not a target";
2494 SNPRINTF(tbuf, sizeof tbuf, "%x",
2499 isp_prt(isp, ISP_LOGERR, "SNS Failed- %s", m);
2504 if (FCPARAM(isp)->isp_fwstate != FW_READY ||
2505 FCPARAM(isp)->isp_loopstate < LOOP_SCANNING_FABRIC) {
2511 #ifdef ISP_USE_GA_NXT
2513 isp_scan_fabric(struct ispsoftc *isp, int ftype)
2515 fcparam *fcp = isp->isp_param;
2516 u_int32_t portid, first_portid, last_portid;
2517 int hicap, last_port_same;
2519 if (fcp->isp_onfabric == 0) {
2520 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2524 FC_SCRATCH_ACQUIRE(isp);
2527 * Since Port IDs are 24 bits, we can check against having seen
2528 * anything yet with this value.
2531 last_portid = 0xffffffff; /* not a port */
2532 first_portid = portid = fcp->isp_portid;
2533 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2535 for (hicap = 0; hicap < GA_NXT_MAX; hicap++) {
2538 sns_ga_nxt_rsp_t *rs0, *rs1;
2540 u_int8_t sc[SNS_GA_NXT_RESP_SIZE];
2542 rq = (sns_screq_t *)sc;
2543 MEMZERO((void *) rq, SNS_GA_NXT_REQ_SIZE);
2544 rq->snscb_rblen = SNS_GA_NXT_RESP_SIZE >> 1;
2545 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+0x100);
2546 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+0x100);
2547 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+0x100);
2548 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+0x100);
2549 rq->snscb_sblen = 6;
2550 rq->snscb_data[0] = SNS_GA_NXT;
2551 rq->snscb_data[4] = portid & 0xffff;
2552 rq->snscb_data[5] = (portid >> 16) & 0xff;
2553 isp_put_sns_request(isp, rq, (sns_screq_t *) fcp->isp_scratch);
2554 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GA_NXT_REQ_SIZE);
2555 MEMZERO(&mbs, sizeof (mbs));
2556 mbs.param[0] = MBOX_SEND_SNS;
2557 mbs.param[1] = SNS_GA_NXT_REQ_SIZE >> 1;
2558 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2559 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2561 * Leave 4 and 5 alone
2563 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2564 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2565 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2566 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2567 fcp->isp_loopstate = LOOP_PDB_RCVD;
2569 FC_SCRATCH_RELEASE(isp);
2572 MEMORYBARRIER(isp, SYNC_SFORCPU, 0x100, SNS_GA_NXT_RESP_SIZE);
2573 rs1 = (sns_ga_nxt_rsp_t *) sc;
2574 rs0 = (sns_ga_nxt_rsp_t *) ((u_int8_t *)fcp->isp_scratch+0x100);
2575 isp_get_ga_nxt_response(isp, rs0, rs1);
2576 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2578 if (rs1->snscb_cthdr.ct_reason == 9 &&
2579 rs1->snscb_cthdr.ct_explanation == 7)
2580 level = ISP_LOGDEBUG0;
2582 level = ISP_LOGWARN;
2583 isp_prt(isp, level, swrej, "GA_NXT",
2584 rs1->snscb_cthdr.ct_reason,
2585 rs1->snscb_cthdr.ct_explanation, portid);
2586 FC_SCRATCH_RELEASE(isp);
2587 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2591 (((u_int32_t) rs1->snscb_port_id[0]) << 16) |
2592 (((u_int32_t) rs1->snscb_port_id[1]) << 8) |
2593 (((u_int32_t) rs1->snscb_port_id[2]));
2596 * XXX: We should check to make sure that this entry
2597 * XXX: supports the type(s) we are interested in.
2600 * Okay, we now have information about a fabric object.
2601 * If it is the type we're interested in, tell the outer layers
2602 * about it. The outer layer needs to know: Port ID, WWNN,
2603 * WWPN, FC4 type, and port type.
2605 * The lportdb structure is adequate for this.
2607 MEMZERO(&lcl, sizeof (lcl));
2608 lcl.port_type = rs1->snscb_port_type;
2609 lcl.fc4_type = ftype;
2610 lcl.portid = portid;
2612 (((u_int64_t)rs1->snscb_nodename[0]) << 56) |
2613 (((u_int64_t)rs1->snscb_nodename[1]) << 48) |
2614 (((u_int64_t)rs1->snscb_nodename[2]) << 40) |
2615 (((u_int64_t)rs1->snscb_nodename[3]) << 32) |
2616 (((u_int64_t)rs1->snscb_nodename[4]) << 24) |
2617 (((u_int64_t)rs1->snscb_nodename[5]) << 16) |
2618 (((u_int64_t)rs1->snscb_nodename[6]) << 8) |
2619 (((u_int64_t)rs1->snscb_nodename[7]));
2621 (((u_int64_t)rs1->snscb_portname[0]) << 56) |
2622 (((u_int64_t)rs1->snscb_portname[1]) << 48) |
2623 (((u_int64_t)rs1->snscb_portname[2]) << 40) |
2624 (((u_int64_t)rs1->snscb_portname[3]) << 32) |
2625 (((u_int64_t)rs1->snscb_portname[4]) << 24) |
2626 (((u_int64_t)rs1->snscb_portname[5]) << 16) |
2627 (((u_int64_t)rs1->snscb_portname[6]) << 8) |
2628 (((u_int64_t)rs1->snscb_portname[7]));
2631 * Does this fabric object support the type we want?
2634 if (rs1->snscb_fc4_types[ftype >> 5] & (1 << (ftype & 0x1f))) {
2635 if (first_portid == portid) {
2636 lcl.last_fabric_dev = 1;
2638 lcl.last_fabric_dev = 0;
2640 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2642 isp_prt(isp, ISP_LOGDEBUG0,
2643 "PortID 0x%x doesn't support FC4 type 0x%x",
2646 if (first_portid == portid) {
2647 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2648 FC_SCRATCH_RELEASE(isp);
2651 if (portid == last_portid) {
2652 if (last_port_same++ > 20) {
2653 isp_prt(isp, ISP_LOGWARN,
2654 "tangled fabric database detected");
2658 last_port_same = 0 ;
2659 last_portid = portid;
2662 FC_SCRATCH_RELEASE(isp);
2663 if (hicap >= GA_NXT_MAX) {
2664 isp_prt(isp, ISP_LOGWARN, "fabric too big (> %d)", GA_NXT_MAX);
2666 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2670 #define GIDLEN ((ISP2100_SCRLEN >> 1) + 16)
2671 #define NGENT ((GIDLEN - 16) >> 2)
2673 #define IGPOFF (ISP2100_SCRLEN - GIDLEN)
2677 isp_scan_fabric(struct ispsoftc *isp, int ftype)
2679 fcparam *fcp = FCPARAM(isp);
2682 sns_gid_ft_req_t *rq;
2683 sns_gid_ft_rsp_t *rs0, *rs1;
2685 if (fcp->isp_onfabric == 0) {
2686 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2690 FC_SCRATCH_ACQUIRE(isp);
2691 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2693 rq = (sns_gid_ft_req_t *)fcp->tport;
2694 MEMZERO((void *) rq, SNS_GID_FT_REQ_SIZE);
2695 rq->snscb_rblen = GIDLEN >> 1;
2696 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+IGPOFF);
2697 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+IGPOFF);
2698 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+IGPOFF);
2699 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+IGPOFF);
2700 rq->snscb_sblen = 6;
2701 rq->snscb_cmd = SNS_GID_FT;
2702 rq->snscb_mword_div_2 = NGENT;
2703 rq->snscb_fc4_type = ftype;
2704 isp_put_gid_ft_request(isp, rq, (sns_gid_ft_req_t *) fcp->isp_scratch);
2705 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE);
2706 MEMZERO(&mbs, sizeof (mbs));
2707 mbs.param[0] = MBOX_SEND_SNS;
2708 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
2709 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2710 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2713 * Leave 4 and 5 alone
2715 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2716 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2717 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2718 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2719 fcp->isp_loopstate = LOOP_PDB_RCVD;
2721 FC_SCRATCH_RELEASE(isp);
2724 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2725 FC_SCRATCH_RELEASE(isp);
2728 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN);
2729 rs1 = (sns_gid_ft_rsp_t *) fcp->tport;
2730 rs0 = (sns_gid_ft_rsp_t *) ((u_int8_t *)fcp->isp_scratch+IGPOFF);
2731 isp_get_gid_ft_response(isp, rs0, rs1, NGENT);
2732 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2734 if (rs1->snscb_cthdr.ct_reason == 9 &&
2735 rs1->snscb_cthdr.ct_explanation == 7)
2736 level = ISP_LOGDEBUG0;
2738 level = ISP_LOGWARN;
2739 isp_prt(isp, level, swrej, "GID_FT",
2740 rs1->snscb_cthdr.ct_reason,
2741 rs1->snscb_cthdr.ct_explanation, 0);
2742 FC_SCRATCH_RELEASE(isp);
2743 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2748 * Okay, we now have a list of Port IDs for this class of device.
2749 * Go through the list and for each one get the WWPN/WWNN for it
2750 * and tell the outer layers about it. The outer layer needs to
2751 * know: Port ID, WWNN, WWPN, FC4 type, and (possibly) port type.
2753 * The lportdb structure is adequate for this.
2757 sns_gxn_id_req_t grqbuf, *gq = &grqbuf;
2758 sns_gxn_id_rsp_t *gs0, grsbuf, *gs1 = &grsbuf;
2761 sns_gff_id_rsp_t *fs0, ffsbuf, *fs1 = &ffsbuf;
2765 MEMZERO(&lcl, sizeof (lcl));
2766 lcl.fc4_type = ftype;
2768 (((u_int32_t) rs1->snscb_ports[i].portid[0]) << 16) |
2769 (((u_int32_t) rs1->snscb_ports[i].portid[1]) << 8) |
2770 (((u_int32_t) rs1->snscb_ports[i].portid[2]));
2772 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2773 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2774 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2775 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2776 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2777 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2778 gq->snscb_sblen = 6;
2779 gq->snscb_cmd = SNS_GPN_ID;
2780 gq->snscb_portid = lcl.portid;
2781 isp_put_gxn_id_request(isp, gq,
2782 (sns_gxn_id_req_t *) fcp->isp_scratch);
2783 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2784 MEMZERO(&mbs, sizeof (mbs));
2785 mbs.param[0] = MBOX_SEND_SNS;
2786 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2787 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2788 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2790 * Leave 4 and 5 alone
2792 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2793 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2794 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2795 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2796 fcp->isp_loopstate = LOOP_PDB_RCVD;
2798 FC_SCRATCH_RELEASE(isp);
2801 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2802 FC_SCRATCH_RELEASE(isp);
2805 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2806 gs0 = (sns_gxn_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2807 isp_get_gxn_id_response(isp, gs0, gs1);
2808 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2809 isp_prt(isp, ISP_LOGWARN, swrej, "GPN_ID",
2810 gs1->snscb_cthdr.ct_reason,
2811 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2812 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2813 FC_SCRATCH_RELEASE(isp);
2819 (((u_int64_t)gs1->snscb_wwn[0]) << 56) |
2820 (((u_int64_t)gs1->snscb_wwn[1]) << 48) |
2821 (((u_int64_t)gs1->snscb_wwn[2]) << 40) |
2822 (((u_int64_t)gs1->snscb_wwn[3]) << 32) |
2823 (((u_int64_t)gs1->snscb_wwn[4]) << 24) |
2824 (((u_int64_t)gs1->snscb_wwn[5]) << 16) |
2825 (((u_int64_t)gs1->snscb_wwn[6]) << 8) |
2826 (((u_int64_t)gs1->snscb_wwn[7]));
2828 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2829 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2830 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2831 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2832 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2833 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2834 gq->snscb_sblen = 6;
2835 gq->snscb_cmd = SNS_GNN_ID;
2836 gq->snscb_portid = lcl.portid;
2837 isp_put_gxn_id_request(isp, gq,
2838 (sns_gxn_id_req_t *) fcp->isp_scratch);
2839 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2840 MEMZERO(&mbs, sizeof (mbs));
2841 mbs.param[0] = MBOX_SEND_SNS;
2842 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2843 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2844 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2846 * Leave 4 and 5 alone
2848 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2849 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2850 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2851 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2852 fcp->isp_loopstate = LOOP_PDB_RCVD;
2854 FC_SCRATCH_RELEASE(isp);
2857 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2858 FC_SCRATCH_RELEASE(isp);
2861 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2862 gs0 = (sns_gxn_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2863 isp_get_gxn_id_response(isp, gs0, gs1);
2864 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2865 isp_prt(isp, ISP_LOGWARN, swrej, "GNN_ID",
2866 gs1->snscb_cthdr.ct_reason,
2867 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2868 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2869 FC_SCRATCH_RELEASE(isp);
2875 (((u_int64_t)gs1->snscb_wwn[0]) << 56) |
2876 (((u_int64_t)gs1->snscb_wwn[1]) << 48) |
2877 (((u_int64_t)gs1->snscb_wwn[2]) << 40) |
2878 (((u_int64_t)gs1->snscb_wwn[3]) << 32) |
2879 (((u_int64_t)gs1->snscb_wwn[4]) << 24) |
2880 (((u_int64_t)gs1->snscb_wwn[5]) << 16) |
2881 (((u_int64_t)gs1->snscb_wwn[6]) << 8) |
2882 (((u_int64_t)gs1->snscb_wwn[7]));
2885 * The QLogic f/w is bouncing this with a parameter error.
2889 * Try and get FC4 Features (FC-GS-3 only).
2890 * We can use the sns_gxn_id_req_t for this request.
2892 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2893 gq->snscb_rblen = SNS_GFF_ID_RESP_SIZE >> 1;
2894 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2895 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2896 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2897 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2898 gq->snscb_sblen = 6;
2899 gq->snscb_cmd = SNS_GFF_ID;
2900 gq->snscb_portid = lcl.portid;
2901 isp_put_gxn_id_request(isp, gq,
2902 (sns_gxn_id_req_t *) fcp->isp_scratch);
2903 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2904 MEMZERO(&mbs, sizeof (mbs));
2905 mbs.param[0] = MBOX_SEND_SNS;
2906 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2907 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2908 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2910 * Leave 4 and 5 alone
2912 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2913 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2914 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2915 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2916 fcp->isp_loopstate = LOOP_PDB_RCVD;
2918 FC_SCRATCH_RELEASE(isp);
2921 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2922 FC_SCRATCH_RELEASE(isp);
2925 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GFF_ID_RESP_SIZE);
2926 fs0 = (sns_gff_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2927 isp_get_gff_id_response(isp, fs0, fs1);
2928 if (fs1->snscb_cthdr.ct_response != FS_ACC) {
2929 isp_prt(isp, /* ISP_LOGDEBUG0 */ ISP_LOGWARN,
2931 fs1->snscb_cthdr.ct_reason,
2932 fs1->snscb_cthdr.ct_explanation, lcl.portid);
2933 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2934 FC_SCRATCH_RELEASE(isp);
2938 int index = (ftype >> 3);
2939 int bshft = (ftype & 0x7) * 4;
2941 (fs1->snscb_fc4_features[index] >> bshft) & 0xf;
2942 if (fc4_fval & 0x1) {
2944 (SVC3_INI_ROLE >> SVC3_ROLE_SHIFT);
2946 if (fc4_fval & 0x2) {
2948 (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT);
2954 * If we really want to know what kind of port type this is,
2955 * we have to run another CT command. Otherwise, we'll leave
2960 if (rs1->snscb_ports[i].control & 0x80) {
2961 lcl.last_fabric_dev = 1;
2963 lcl.last_fabric_dev = 0;
2965 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2967 } while ((rs1->snscb_ports[i].control & 0x80) == 0 && i < NGENT-1);
2970 * If we're not at the last entry, our list isn't big enough.
2972 if ((rs1->snscb_ports[i].control & 0x80) == 0) {
2973 isp_prt(isp, ISP_LOGWARN, "fabric too big for scratch area");
2976 FC_SCRATCH_RELEASE(isp);
2977 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2983 isp_register_fc4_type(struct ispsoftc *isp)
2985 fcparam *fcp = isp->isp_param;
2986 u_int8_t local[SNS_RFT_ID_REQ_SIZE];
2987 sns_screq_t *reqp = (sns_screq_t *) local;
2990 MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
2991 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
2992 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
2993 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
2994 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
2995 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
2996 reqp->snscb_sblen = 22;
2997 reqp->snscb_data[0] = SNS_RFT_ID;
2998 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
2999 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
3000 reqp->snscb_data[6] = (1 << FC4_SCSI);
3002 reqp->snscb_data[6] |= (1 << FC4_IP); /* ISO/IEC 8802-2 LLC/SNAP */
3004 FC_SCRATCH_ACQUIRE(isp);
3005 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
3006 MEMZERO(&mbs, sizeof (mbs));
3007 mbs.param[0] = MBOX_SEND_SNS;
3008 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
3009 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
3010 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
3012 * Leave 4 and 5 alone
3014 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
3015 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
3016 isp_mboxcmd(isp, &mbs, MBLOGALL);
3017 FC_SCRATCH_RELEASE(isp);
3018 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3019 isp_prt(isp, ISP_LOGDEBUG0, "Register FC4 types succeeded");
3024 * Start a command. Locking is assumed done in the caller.
3030 struct ispsoftc *isp;
3031 u_int16_t nxti, optr, handle;
3032 u_int8_t local[QENTRY_LEN];
3033 ispreq_t *reqp, *qep;
3040 * Check to make sure we're supporting initiator role.
3042 if ((isp->isp_role & ISP_ROLE_INITIATOR) == 0) {
3043 XS_SETERR(xs, HBA_SELTIMEOUT);
3044 return (CMD_COMPLETE);
3048 * Now make sure we're running.
3051 if (isp->isp_state != ISP_RUNSTATE) {
3052 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
3053 XS_SETERR(xs, HBA_BOTCH);
3054 return (CMD_COMPLETE);
3058 * Check command CDB length, etc.. We really are limited to 16 bytes
3059 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
3060 * but probably only if we're running fairly new firmware (we'll
3061 * let the old f/w choke on an extended command queue entry).
3064 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
3065 isp_prt(isp, ISP_LOGERR,
3066 "unsupported cdb length (%d, CDB[0]=0x%x)",
3067 XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
3068 XS_SETERR(xs, HBA_BOTCH);
3069 return (CMD_COMPLETE);
3073 * Check to see whether we have good firmware state still or
3074 * need to refresh our port database for this target.
3076 target = XS_TGT(xs);
3078 fcparam *fcp = isp->isp_param;
3080 #ifdef HANDLE_LOOPSTATE_IN_OUTER_LAYERS
3081 if (fcp->isp_fwstate != FW_READY ||
3082 fcp->isp_loopstate != LOOP_READY) {
3083 return (CMD_RQLATER);
3087 * If we're not on a Fabric, we can't have a target
3088 * above FL_PORT_ID-1.
3090 * If we're on a fabric and *not* connected as an F-port,
3091 * we can't have a target less than FC_SNS_ID+1. This
3092 * keeps us from having to sort out the difference between
3093 * local public loop devices and those which we might get
3094 * from a switch's database.
3096 if (fcp->isp_onfabric == 0) {
3097 if (target >= FL_PORT_ID) {
3098 XS_SETERR(xs, HBA_SELTIMEOUT);
3099 return (CMD_COMPLETE);
3102 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3103 XS_SETERR(xs, HBA_SELTIMEOUT);
3104 return (CMD_COMPLETE);
3107 * We used to exclude having local loop ports
3108 * at the same time that we have fabric ports.
3109 * That is, we used to exclude having ports
3110 * at < FL_PORT_ID if we're FL-port.
3112 * That's wrong. The only thing that could be
3113 * dicey is if the switch you're connected to
3114 * has these local loop ports appear on the
3115 * fabric and we somehow attach them twice.
3120 * Check for f/w being in ready state. If the f/w
3121 * isn't in ready state, then we don't know our
3122 * loop ID and the f/w hasn't completed logging
3123 * into all targets on the loop. If this is the
3124 * case, then bounce the command. We pretend this is
3125 * a SELECTION TIMEOUT error if we've never gone to
3126 * FW_READY state at all- in this case we may not
3127 * be hooked to a loop at all and we shouldn't hang
3128 * the machine for this. Otherwise, defer this command
3131 if (fcp->isp_fwstate != FW_READY) {
3133 * Give ourselves at most a 250ms delay.
3135 if (isp_fclink_test(isp, 250000)) {
3136 XS_SETERR(xs, HBA_SELTIMEOUT);
3137 if (fcp->loop_seen_once) {
3138 return (CMD_RQLATER);
3140 return (CMD_COMPLETE);
3146 * If we're not on a Fabric, we can't have a target
3147 * above FL_PORT_ID-1.
3149 * If we're on a fabric and *not* connected as an F-port,
3150 * we can't have a target less than FC_SNS_ID+1. This
3151 * keeps us from having to sort out the difference between
3152 * local public loop devices and those which we might get
3153 * from a switch's database.
3155 if (fcp->isp_onfabric == 0) {
3156 if (target >= FL_PORT_ID) {
3157 XS_SETERR(xs, HBA_SELTIMEOUT);
3158 return (CMD_COMPLETE);
3161 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3162 XS_SETERR(xs, HBA_SELTIMEOUT);
3163 return (CMD_COMPLETE);
3165 if (fcp->isp_topo != TOPO_F_PORT &&
3166 target < FL_PORT_ID) {
3167 XS_SETERR(xs, HBA_SELTIMEOUT);
3168 return (CMD_COMPLETE);
3173 * If our loop state is such that we haven't yet received
3174 * a "Port Database Changed" notification (after a LIP or
3175 * a Loop Reset or firmware initialization), then defer
3176 * sending commands for a little while, but only if we've
3177 * seen a valid loop at one point (otherwise we can get
3178 * stuck at initialization time).
3180 if (fcp->isp_loopstate < LOOP_PDB_RCVD) {
3181 XS_SETERR(xs, HBA_SELTIMEOUT);
3182 if (fcp->loop_seen_once) {
3183 return (CMD_RQLATER);
3185 return (CMD_COMPLETE);
3190 * If we're in the middle of loop or fabric scanning
3191 * or merging the port databases, retry this command later.
3193 if (fcp->isp_loopstate == LOOP_SCANNING_FABRIC ||
3194 fcp->isp_loopstate == LOOP_SCANNING_LOOP ||
3195 fcp->isp_loopstate == LOOP_SYNCING_PDB) {
3196 return (CMD_RQLATER);
3200 * If our loop state is now such that we've just now
3201 * received a Port Database Change notification, then
3202 * we have to go off and (re)scan the fabric. We back
3203 * out and try again later if this doesn't work.
3205 if (fcp->isp_loopstate == LOOP_PDB_RCVD && fcp->isp_onfabric) {
3206 if (isp_scan_fabric(isp, FC4_SCSI)) {
3207 return (CMD_RQLATER);
3209 if (fcp->isp_fwstate != FW_READY ||
3210 fcp->isp_loopstate < LOOP_FSCAN_DONE) {
3211 return (CMD_RQLATER);
3216 * If our loop state is now such that we've just now
3217 * received a Port Database Change notification, then
3218 * we have to go off and (re)synchronize our port
3221 if (fcp->isp_loopstate < LOOP_READY) {
3222 if (isp_pdb_sync(isp)) {
3223 return (CMD_RQLATER);
3225 if (fcp->isp_fwstate != FW_READY ||
3226 fcp->isp_loopstate != LOOP_READY) {
3227 return (CMD_RQLATER);
3232 * XXX: Here's were we would cancel any loop_dead flag
3233 * XXX: also cancel in dead_loop timeout that's running
3238 * Now check whether we should even think about pursuing this.
3240 lp = &fcp->portdb[target];
3241 if (lp->valid == 0) {
3242 XS_SETERR(xs, HBA_SELTIMEOUT);
3243 return (CMD_COMPLETE);
3245 if ((lp->roles & (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT)) == 0) {
3246 isp_prt(isp, ISP_LOGDEBUG2,
3247 "Target %d does not have target service", target);
3248 XS_SETERR(xs, HBA_SELTIMEOUT);
3249 return (CMD_COMPLETE);
3252 * Now turn target into what the actual Loop ID is.
3254 target = lp->loopid;
3258 * Next check to see if any HBA or Device
3259 * parameters need to be updated.
3261 if (isp->isp_update != 0) {
3265 if (isp_getrqentry(isp, &nxti, &optr, (void *)&qep)) {
3266 isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow");
3267 XS_SETERR(xs, HBA_BOTCH);
3268 return (CMD_EAGAIN);
3272 * Now see if we need to synchronize the ISP with respect to anything.
3273 * We do dual duty here (cough) for synchronizing for busses other
3274 * than which we got here to send a command to.
3276 reqp = (ispreq_t *) local;
3277 if (isp->isp_sendmarker) {
3278 u_int8_t n = (IS_DUALBUS(isp)? 2: 1);
3280 * Check ports to send markers for...
3282 for (i = 0; i < n; i++) {
3283 if ((isp->isp_sendmarker & (1 << i)) == 0) {
3286 MEMZERO((void *) reqp, QENTRY_LEN);
3287 reqp->req_header.rqs_entry_count = 1;
3288 reqp->req_header.rqs_entry_type = RQSTYPE_MARKER;
3289 reqp->req_modifier = SYNC_ALL;
3290 reqp->req_target = i << 7; /* insert bus number */
3291 isp_put_request(isp, reqp, qep);
3292 ISP_ADD_REQUEST(isp, nxti);
3293 isp->isp_sendmarker &= ~(1 << i);
3294 if (isp_getrqentry(isp, &nxti, &optr, (void *) &qep)) {
3295 isp_prt(isp, ISP_LOGDEBUG0,
3296 "Request Queue Overflow+");
3297 XS_SETERR(xs, HBA_BOTCH);
3298 return (CMD_EAGAIN);
3303 MEMZERO((void *)reqp, QENTRY_LEN);
3304 reqp->req_header.rqs_entry_count = 1;
3306 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
3308 if (XS_CDBLEN(xs) > 12)
3309 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
3311 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
3313 /* reqp->req_header.rqs_flags = 0; */
3314 /* reqp->req_header.rqs_seqno = 0; */
3317 * See comment in isp_intr
3319 /* XS_RESID(xs) = 0; */
3322 * Fibre Channel always requires some kind of tag.
3323 * The Qlogic drivers seem be happy not to use a tag,
3324 * but this breaks for some devices (IBM drives).
3327 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
3330 * If we don't know what tag to use, use HEAD OF QUEUE
3331 * for Request Sense or Simple.
3333 if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
3334 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_HTAG;
3336 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
3339 sdparam *sdp = (sdparam *)isp->isp_param;
3340 sdp += XS_CHANNEL(xs);
3341 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) &&
3343 reqp->req_flags = XS_TAG_TYPE(xs);
3347 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
3348 reqp->req_lun_trn = XS_LUN(xs);
3349 reqp->req_cdblen = XS_CDBLEN(xs);
3350 } else if (IS_2KLOGIN(isp)) {
3351 ((ispreqt2e_t *)reqp)->req_target = target;
3352 ((ispreqt2e_t *)reqp)->req_scclun = XS_LUN(xs);
3353 } else if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
3354 ((ispreqt2_t *)reqp)->req_target = target;
3355 ((ispreqt2_t *)reqp)->req_scclun = XS_LUN(xs);
3357 ((ispreqt2_t *)reqp)->req_target = target;
3358 ((ispreqt2_t *)reqp)->req_lun_trn = XS_LUN(xs);
3360 MEMCPY(reqp->req_cdb, XS_CDBP(xs), XS_CDBLEN(xs));
3362 reqp->req_time = XS_TIME(xs) / 1000;
3363 if (reqp->req_time == 0 && XS_TIME(xs)) {
3367 if (isp_save_xs(isp, xs, &handle)) {
3368 isp_prt(isp, ISP_LOGDEBUG0, "out of xflist pointers");
3369 XS_SETERR(xs, HBA_BOTCH);
3370 return (CMD_EAGAIN);
3372 reqp->req_handle = handle;
3375 * Set up DMA and/or do any bus swizzling of the request entry
3376 * so that the Qlogic F/W understands what is being asked of it.
3378 i = ISP_DMASETUP(isp, xs, reqp, &nxti, optr);
3379 if (i != CMD_QUEUED) {
3380 isp_destroy_handle(isp, handle);
3382 * dmasetup sets actual error in packet, and
3383 * return what we were given to return.
3387 XS_SETERR(xs, HBA_NOERROR);
3388 isp_prt(isp, ISP_LOGDEBUG2,
3389 "START cmd for %d.%d.%d cmd 0x%x datalen %ld",
3390 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), XS_CDBP(xs)[0],
3391 (long) XS_XFRLEN(xs));
3392 ISP_ADD_REQUEST(isp, nxti);
3394 return (CMD_QUEUED);
3399 * Locks (ints blocked) assumed held.
3403 isp_control(struct ispsoftc *isp, ispctl_t ctl, void *arg)
3410 MEMZERO(&mbs, sizeof (mbs));
3414 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
3417 case ISPCTL_RESET_BUS:
3419 * Issue a bus reset.
3421 mbs.param[0] = MBOX_BUS_RESET;
3425 ((sdparam *) isp->isp_param)->isp_bus_reset_delay;
3426 if (mbs.param[1] < 2)
3428 bus = *((int *) arg);
3429 if (IS_DUALBUS(isp))
3435 isp->isp_sendmarker |= (1 << bus);
3436 isp_mboxcmd(isp, &mbs, MBLOGALL);
3437 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3440 isp_prt(isp, ISP_LOGINFO,
3441 "driver initiated bus reset of bus %d", bus);
3444 case ISPCTL_RESET_DEV:
3445 tgt = (*((int *) arg)) & 0xffff;
3446 bus = (*((int *) arg)) >> 16;
3447 mbs.param[0] = MBOX_ABORT_TARGET;
3449 mbs.param[1] = (tgt << 8) | (bus << 15);
3451 if (IS_2KLOGIN(isp)) {
3453 mbs.obits |= (1 << 10);
3455 mbs.param[1] = (tgt << 8);
3458 mbs.param[2] = 3; /* 'delay', in seconds */
3459 isp_mboxcmd(isp, &mbs, MBLOGALL);
3460 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3463 isp_prt(isp, ISP_LOGINFO,
3464 "Target %d on Bus %d Reset Succeeded", tgt, bus);
3465 isp->isp_sendmarker |= (1 << bus);
3468 case ISPCTL_ABORT_CMD:
3471 handle = isp_find_handle(isp, xs);
3473 isp_prt(isp, ISP_LOGWARN,
3474 "cannot find handle for command to abort");
3477 bus = XS_CHANNEL(xs);
3478 mbs.param[0] = MBOX_ABORT;
3480 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
3481 if (IS_2KLOGIN(isp)) {
3484 mbs.param[1] = tgt << 8;
3488 mbs.param[6] = XS_LUN(xs);
3490 mbs.param[1] = tgt << 8 | XS_LUN(xs);
3494 (bus << 15) | (XS_TGT(xs) << 8) | XS_LUN(xs);
3497 mbs.param[2] = handle;
3498 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_ERROR);
3499 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3503 * XXX: Look for command in the REQUEST QUEUE. That is,
3504 * XXX: It hasen't been picked up by firmware yet.
3508 case ISPCTL_UPDATE_PARAMS:
3513 case ISPCTL_FCLINK_TEST:
3516 int usdelay = (arg)? *((int *) arg) : 250000;
3517 return (isp_fclink_test(isp, usdelay));
3521 case ISPCTL_SCAN_FABRIC:
3524 int ftype = (arg)? *((int *) arg) : FC4_SCSI;
3525 return (isp_scan_fabric(isp, ftype));
3529 case ISPCTL_SCAN_LOOP:
3532 return (isp_scan_loop(isp));
3536 case ISPCTL_PDB_SYNC:
3539 return (isp_pdb_sync(isp));
3543 case ISPCTL_SEND_LIP:
3546 mbs.param[0] = MBOX_INIT_LIP;
3547 isp_mboxcmd(isp, &mbs, MBLOGALL);
3548 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3554 case ISPCTL_GET_POSMAP:
3556 if (IS_FC(isp) && arg) {
3557 return (isp_getmap(isp, arg));
3562 case ISPCTL_GET_PDB:
3563 if (IS_FC(isp) && arg) {
3564 int id = *((int *)arg);
3565 isp_pdb_t *pdb = arg;
3566 return (isp_getpdb(isp, id, pdb));
3570 case ISPCTL_RUN_MBOXCMD:
3572 isp_mboxcmd(isp, arg, MBLOGALL);
3575 #ifdef ISP_TARGET_MODE
3576 case ISPCTL_TOGGLE_TMODE:
3580 * We don't check/set against role here- that's the
3581 * responsibility for the outer layer to coordinate.
3584 int param = *(int *)arg;
3585 mbs.param[0] = MBOX_ENABLE_TARGET_MODE;
3586 mbs.param[1] = param & 0xffff;
3587 mbs.param[2] = param >> 16;
3588 isp_mboxcmd(isp, &mbs, MBLOGALL);
3589 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3601 * Interrupt Service Routine(s).
3603 * External (OS) framework has done the appropriate locking,
3604 * and the locking will be held throughout this function.
3608 * Limit our stack depth by sticking with the max likely number
3609 * of completions on a request queue at any one time.
3611 #ifndef MAX_REQUESTQ_COMPLETIONS
3612 #define MAX_REQUESTQ_COMPLETIONS 64
3616 isp_intr(struct ispsoftc *isp, u_int16_t isr, u_int16_t sema, u_int16_t mbox)
3618 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
3619 u_int16_t iptr, optr, junk;
3620 int i, nlooked = 0, ndone = 0;
3624 * Is this a mailbox related interrupt?
3625 * The mailbox semaphore will be nonzero if so.
3628 if (mbox & 0x4000) {
3629 isp->isp_intmboxc++;
3630 if (isp->isp_mboxbsy) {
3631 int i = 0, obits = isp->isp_obits;
3632 isp->isp_mboxtmp[i++] = mbox;
3633 for (i = 1; i < MAX_MAILBOX(isp); i++) {
3634 if ((obits & (1 << i)) == 0) {
3637 isp->isp_mboxtmp[i] =
3638 ISP_READ(isp, MBOX_OFF(i));
3640 if (isp->isp_mbxwrk0) {
3641 if (isp_mbox_continue(isp) == 0) {
3645 MBOX_NOTIFY_COMPLETE(isp);
3647 isp_prt(isp, ISP_LOGWARN,
3648 "Mbox Command Async (0x%x) with no waiters",
3651 } else if (isp_parse_async(isp, mbox) < 0) {
3654 if ((IS_FC(isp) && mbox != ASYNC_RIO_RESP) ||
3655 isp->isp_state != ISP_RUNSTATE) {
3656 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3657 ISP_WRITE(isp, BIU_SEMA, 0);
3663 * We can't be getting this now.
3665 if (isp->isp_state != ISP_RUNSTATE) {
3666 isp_prt(isp, ISP_LOGWARN,
3667 "interrupt (ISR=%x SEMA=%x) when not ready", isr, sema);
3669 * Thank you very much! *Burrrp*!
3671 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp,
3672 READ_RESPONSE_QUEUE_IN_POINTER(isp));
3674 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3675 ISP_WRITE(isp, BIU_SEMA, 0);
3680 * Get the current Response Queue Out Pointer.
3682 * If we're a 2300, we can ask what hardware what it thinks.
3685 optr = ISP_READ(isp, isp->isp_respoutrp);
3687 * Debug: to be taken out eventually
3689 if (isp->isp_residx != optr) {
3690 isp_prt(isp, ISP_LOGWARN, "optr %x soft optr %x",
3691 optr, isp->isp_residx);
3694 optr = isp->isp_residx;
3698 * You *must* read the Response Queue In Pointer
3699 * prior to clearing the RISC interrupt.
3701 * Debounce the 2300 if revision less than 2.
3703 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
3706 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3707 junk = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3708 } while (junk != iptr && ++i < 1000);
3711 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3712 isp_prt(isp, ISP_LOGWARN,
3713 "Response Queue Out Pointer Unstable (%x, %x)",
3718 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3720 isp->isp_resodx = iptr;
3723 if (optr == iptr && sema == 0) {
3725 * There are a lot of these- reasons unknown- mostly on
3726 * faster Alpha machines.
3728 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
3729 * make sure the old interrupt went away (to avoid 'ringing'
3730 * effects), but that didn't stop this from occurring.
3734 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3735 junk = ISP_READ(isp, BIU_R2HSTSLO);
3737 junk = ISP_READ(isp, BIU_ISR);
3743 sema = ISP_READ(isp, BIU_SEMA);
3744 mbox = ISP_READ(isp, OUTMAILBOX0);
3745 if ((sema & 0x3) && (mbox & 0x8000)) {
3749 isp->isp_intbogus++;
3750 isp_prt(isp, ISP_LOGDEBUG1,
3751 "bogus intr- isr %x (%x) iptr %x optr %x",
3752 isr, junk, iptr, optr);
3755 isp->isp_resodx = iptr;
3756 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3757 ISP_WRITE(isp, BIU_SEMA, 0);
3759 if (isp->isp_rspbsy) {
3762 isp->isp_rspbsy = 1;
3764 while (optr != iptr) {
3765 ispstatusreq_t local, *sp = &local;
3771 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
3773 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
3777 * Synchronize our view of this response queue entry.
3779 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN);
3781 type = isp_get_response_type(isp, hp);
3783 if (type == RQSTYPE_RESPONSE) {
3784 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3785 } else if (type == RQSTYPE_RIO2) {
3787 isp_get_rio2(isp, (isp_rio2_t *) hp, &rio);
3788 for (i = 0; i < rio.req_header.rqs_seqno; i++) {
3789 isp_fastpost_complete(isp, rio.req_handles[i]);
3791 if (isp->isp_fpcchiwater < rio.req_header.rqs_seqno)
3792 isp->isp_fpcchiwater = rio.req_header.rqs_seqno;
3793 MEMZERO(hp, QENTRY_LEN); /* PERF */
3797 * Somebody reachable via isp_handle_other_response
3798 * may have updated the response queue pointers for
3799 * us, so we reload our goal index.
3801 int i = isp_handle_other_response(isp, type, hp, &optr);
3805 iptr = isp->isp_resodx;
3806 MEMZERO(hp, QENTRY_LEN); /* PERF */
3811 * After this point, we'll just look at the header as
3812 * we don't know how to deal with the rest of the
3815 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3818 * It really has to be a bounced request just copied
3819 * from the request queue to the response queue. If
3820 * not, something bad has happened.
3822 if (sp->req_header.rqs_entry_type != RQSTYPE_REQUEST) {
3823 isp_prt(isp, ISP_LOGERR, notresp,
3824 sp->req_header.rqs_entry_type, oop, optr,
3826 if (isp->isp_dblev & ISP_LOGDEBUG0) {
3827 isp_print_bytes(isp, "Queue Entry",
3830 MEMZERO(hp, QENTRY_LEN); /* PERF */
3836 if (sp->req_header.rqs_flags & 0xf) {
3837 #define _RQS_OFLAGS \
3838 ~(RQSFLAG_CONTINUATION|RQSFLAG_FULL|RQSFLAG_BADHEADER|RQSFLAG_BADPACKET)
3839 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
3840 isp_prt(isp, ISP_LOGWARN,
3841 "continuation segment");
3842 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3845 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3846 isp_prt(isp, ISP_LOGDEBUG1,
3847 "internal queues full");
3849 * We'll synthesize a QUEUE FULL message below.
3852 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
3853 isp_prt(isp, ISP_LOGERR, "bad header flag");
3856 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
3857 isp_prt(isp, ISP_LOGERR, "bad request packet");
3860 if (sp->req_header.rqs_flags & _RQS_OFLAGS) {
3861 isp_prt(isp, ISP_LOGERR,
3862 "unknown flags (0x%x) in response",
3863 sp->req_header.rqs_flags);
3868 if (sp->req_handle > isp->isp_maxcmds || sp->req_handle < 1) {
3869 MEMZERO(hp, QENTRY_LEN); /* PERF */
3870 isp_prt(isp, ISP_LOGERR,
3871 "bad request handle %d (type 0x%x, flags 0x%x)",
3872 sp->req_handle, sp->req_header.rqs_entry_type,
3873 sp->req_header.rqs_flags);
3874 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3877 xs = isp_find_xs(isp, sp->req_handle);
3879 u_int8_t ts = sp->req_completion_status & 0xff;
3880 MEMZERO(hp, QENTRY_LEN); /* PERF */
3882 * Only whine if this isn't the expected fallout of
3883 * aborting the command.
3885 if (sp->req_header.rqs_entry_type != RQSTYPE_RESPONSE) {
3886 isp_prt(isp, ISP_LOGERR,
3887 "cannot find handle 0x%x (type 0x%x)",
3889 sp->req_header.rqs_entry_type);
3890 } else if (ts != RQCS_ABORTED) {
3891 isp_prt(isp, ISP_LOGERR,
3892 "cannot find handle 0x%x (status 0x%x)",
3893 sp->req_handle, ts);
3895 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3898 isp_destroy_handle(isp, sp->req_handle);
3899 if (sp->req_status_flags & RQSTF_BUS_RESET) {
3900 XS_SETERR(xs, HBA_BUSRESET);
3901 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
3904 XS_SETERR(xs, HBA_BOTCH);
3907 if (IS_FC(isp) && (sp->req_scsi_status & RQCS_SV)) {
3909 * Fibre Channel F/W doesn't say we got status
3910 * if there's Sense Data instead. I guess they
3911 * think it goes w/o saying.
3913 sp->req_state_flags |= RQSF_GOT_STATUS;
3915 if (sp->req_state_flags & RQSF_GOT_STATUS) {
3916 *XS_STSP(xs) = sp->req_scsi_status & 0xff;
3919 switch (sp->req_header.rqs_entry_type) {
3920 case RQSTYPE_RESPONSE:
3921 XS_SET_STATE_STAT(isp, xs, sp);
3922 isp_parse_status(isp, sp, xs);
3923 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) &&
3924 (*XS_STSP(xs) == SCSI_BUSY)) {
3925 XS_SETERR(xs, HBA_TGTBSY);
3928 XS_RESID(xs) = sp->req_resid;
3929 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3930 (*XS_STSP(xs) == SCSI_CHECK) &&
3931 (sp->req_state_flags & RQSF_GOT_SENSE)) {
3932 XS_SAVE_SENSE(xs, sp);
3935 * A new synchronous rate was negotiated for
3936 * this target. Mark state such that we'll go
3937 * look up that which has changed later.
3939 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
3941 sdparam *sdp = isp->isp_param;
3942 sdp += XS_CHANNEL(xs);
3943 sdp->isp_devparam[t].dev_refresh = 1;
3945 (1 << XS_CHANNEL(xs));
3948 if (sp->req_status_flags & RQSF_XFER_COMPLETE) {
3950 } else if (sp->req_scsi_status & RQCS_RESID) {
3951 XS_RESID(xs) = sp->req_resid;
3955 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3956 (*XS_STSP(xs) == SCSI_CHECK) &&
3957 (sp->req_scsi_status & RQCS_SV)) {
3958 XS_SAVE_SENSE(xs, sp);
3959 /* solely for the benefit of debug */
3960 sp->req_state_flags |= RQSF_GOT_SENSE;
3963 isp_prt(isp, ISP_LOGDEBUG2,
3964 "asked for %ld got resid %ld", (long) XS_XFRLEN(xs),
3965 (long) sp->req_resid);
3967 case RQSTYPE_REQUEST:
3968 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3970 * Force Queue Full status.
3972 *XS_STSP(xs) = SCSI_QFULL;
3973 XS_SETERR(xs, HBA_NOERROR);
3974 } else if (XS_NOERR(xs)) {
3978 isp_prt(isp, ISP_LOGDEBUG0,
3979 "Request Queue Entry bounced back");
3980 XS_SETERR(xs, HBA_BOTCH);
3982 XS_RESID(xs) = XS_XFRLEN(xs);
3985 isp_prt(isp, ISP_LOGWARN,
3986 "unhandled response queue type 0x%x",
3987 sp->req_header.rqs_entry_type);
3989 XS_SETERR(xs, HBA_BOTCH);
3995 * Free any DMA resources. As a side effect, this may
3996 * also do any cache flushing necessary for data coherence. */
3997 if (XS_XFRLEN(xs)) {
3998 ISP_DMAFREE(isp, xs, sp->req_handle);
4001 if (((isp->isp_dblev & (ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
4002 ((isp->isp_dblev & ISP_LOGDEBUG1) && ((!XS_NOERR(xs)) ||
4003 (*XS_STSP(xs) != SCSI_GOOD)))) {
4005 if (sp->req_state_flags & RQSF_GOT_SENSE) {
4006 skey = XS_SNSKEY(xs) & 0xf;
4011 } else if (*XS_STSP(xs) == SCSI_CHECK) {
4016 isp_prt(isp, ISP_LOGALL, finmsg, XS_CHANNEL(xs),
4017 XS_TGT(xs), XS_LUN(xs), XS_XFRLEN(xs), XS_RESID(xs),
4018 *XS_STSP(xs), skey, XS_ERR(xs));
4021 if (isp->isp_nactive > 0)
4023 complist[ndone++] = xs; /* defer completion call until later */
4024 MEMZERO(hp, QENTRY_LEN); /* PERF */
4025 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
4031 * If we looked at any commands, then it's valid to find out
4032 * what the outpointer is. It also is a trigger to update the
4033 * ISP's notion of what we've seen so far.
4036 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
4038 * While we're at it, read the requst queue out pointer.
4040 isp->isp_reqodx = READ_REQUEST_QUEUE_OUT_POINTER(isp);
4041 if (isp->isp_rscchiwater < ndone)
4042 isp->isp_rscchiwater = ndone;
4045 isp->isp_residx = optr;
4046 isp->isp_rspbsy = 0;
4047 for (i = 0; i < ndone; i++) {
4050 isp->isp_rsltccmplt++;
4061 isp_parse_async(struct ispsoftc *isp, u_int16_t mbox)
4066 if (IS_DUALBUS(isp)) {
4067 bus = ISP_READ(isp, OUTMAILBOX6);
4071 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
4074 case ASYNC_BUS_RESET:
4075 isp->isp_sendmarker |= (1 << bus);
4076 #ifdef ISP_TARGET_MODE
4077 if (isp_target_async(isp, bus, mbox))
4080 isp_async(isp, ISPASYNC_BUS_RESET, &bus);
4082 case ASYNC_SYSTEM_ERROR:
4083 #ifdef ISP_FW_CRASH_DUMP
4085 * If we have crash dumps enabled, it's up to the handler
4086 * for isp_async to reinit stuff and restart the firmware
4087 * after performing the crash dump. The reason we do things
4088 * this way is that we may need to activate a kernel thread
4089 * to do all the crash dump goop.
4091 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4093 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4095 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4100 case ASYNC_RQS_XFER_ERR:
4101 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
4104 case ASYNC_RSP_XFER_ERR:
4105 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
4110 * We've just been notified that the Queue has woken up.
4111 * We don't need to be chatty about this- just unlatch things
4114 mbox = READ_REQUEST_QUEUE_OUT_POINTER(isp);
4117 case ASYNC_TIMEOUT_RESET:
4118 isp_prt(isp, ISP_LOGWARN,
4119 "timeout initiated SCSI bus reset of bus %d", bus);
4120 isp->isp_sendmarker |= (1 << bus);
4121 #ifdef ISP_TARGET_MODE
4122 if (isp_target_async(isp, bus, mbox))
4127 case ASYNC_DEVICE_RESET:
4128 isp_prt(isp, ISP_LOGINFO, "device reset on bus %d", bus);
4129 isp->isp_sendmarker |= (1 << bus);
4130 #ifdef ISP_TARGET_MODE
4131 if (isp_target_async(isp, bus, mbox))
4136 case ASYNC_EXTMSG_UNDERRUN:
4137 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
4140 case ASYNC_SCAM_INT:
4141 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
4144 case ASYNC_HUNG_SCSI:
4145 isp_prt(isp, ISP_LOGERR,
4146 "stalled SCSI Bus after DATA Overrun");
4147 /* XXX: Need to issue SCSI reset at this point */
4150 case ASYNC_KILLED_BUS:
4151 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
4154 case ASYNC_BUS_TRANSIT:
4155 mbox = ISP_READ(isp, OUTMAILBOX2);
4156 switch (mbox & 0x1c00) {
4157 case SXP_PINS_LVD_MODE:
4158 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
4159 SDPARAM(isp)->isp_diffmode = 0;
4160 SDPARAM(isp)->isp_ultramode = 0;
4161 SDPARAM(isp)->isp_lvdmode = 1;
4163 case SXP_PINS_HVD_MODE:
4164 isp_prt(isp, ISP_LOGINFO,
4165 "Transition to Differential mode");
4166 SDPARAM(isp)->isp_diffmode = 1;
4167 SDPARAM(isp)->isp_ultramode = 0;
4168 SDPARAM(isp)->isp_lvdmode = 0;
4170 case SXP_PINS_SE_MODE:
4171 isp_prt(isp, ISP_LOGINFO,
4172 "Transition to Single Ended mode");
4173 SDPARAM(isp)->isp_diffmode = 0;
4174 SDPARAM(isp)->isp_ultramode = 1;
4175 SDPARAM(isp)->isp_lvdmode = 0;
4178 isp_prt(isp, ISP_LOGWARN,
4179 "Transition to Unknown Mode 0x%x", mbox);
4183 * XXX: Set up to renegotiate again!
4185 /* Can only be for a 1080... */
4186 isp->isp_sendmarker |= (1 << bus);
4190 * We can use bus, which will always be zero for FC cards,
4191 * as a mailbox pattern accumulator to be checked below.
4194 bus = 0x1ce; /* outgoing mailbox regs 1-3, 6-7 */
4198 bus = 0x14e; /* outgoing mailbox regs 1-3, 6 */
4202 bus = 0x10e; /* outgoing mailbox regs 1-3 */
4206 bus = 0x106; /* outgoing mailbox regs 1-2 */
4210 case ASYNC_CMD_CMPLT:
4211 bus = 0x102; /* outgoing mailbox regs 1 */
4214 case ASYNC_RIO_RESP:
4217 case ASYNC_CTIO_DONE:
4219 #ifdef ISP_TARGET_MODE
4221 (ISP_READ(isp, OUTMAILBOX2) << 16) |
4222 (ISP_READ(isp, OUTMAILBOX1));
4223 if (isp_target_async(isp, handle, mbox)) {
4226 /* count it as a fast posting intr */
4227 isp->isp_fphccmplt++;
4230 isp_prt(isp, ISP_LOGINFO, "Fast Posting CTIO done");
4231 isp->isp_fphccmplt++; /* count it as a fast posting intr */
4236 case ASYNC_LIP_OCCURRED:
4237 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4238 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4239 isp->isp_sendmarker = 1;
4240 isp_mark_getpdb_all(isp);
4241 isp_async(isp, ISPASYNC_LIP, NULL);
4242 #ifdef ISP_TARGET_MODE
4243 if (isp_target_async(isp, bus, mbox))
4247 * We've had problems with data corruption occuring on
4248 * commands that complete (with no apparent error) after
4249 * we receive a LIP. This has been observed mostly on
4250 * Local Loop topologies. To be safe, let's just mark
4251 * all active commands as dead.
4253 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4254 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4256 for (i = j = 0; i < isp->isp_maxcmds; i++) {
4258 xs = isp->isp_xflist[i];
4261 XS_SETERR(xs, HBA_BUSRESET);
4265 isp_prt(isp, ISP_LOGERR,
4266 "LIP destroyed %d active commands", j);
4272 isp->isp_sendmarker = 1;
4273 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4274 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4275 isp_mark_getpdb_all(isp);
4276 isp_async(isp, ISPASYNC_LOOP_UP, NULL);
4277 #ifdef ISP_TARGET_MODE
4278 if (isp_target_async(isp, bus, mbox))
4283 case ASYNC_LOOP_DOWN:
4284 isp->isp_sendmarker = 1;
4285 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4286 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4287 isp_mark_getpdb_all(isp);
4288 isp_async(isp, ISPASYNC_LOOP_DOWN, NULL);
4289 #ifdef ISP_TARGET_MODE
4290 if (isp_target_async(isp, bus, mbox))
4295 case ASYNC_LOOP_RESET:
4296 isp->isp_sendmarker = 1;
4297 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4298 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4299 isp_mark_getpdb_all(isp);
4300 isp_async(isp, ISPASYNC_LOOP_RESET, NULL);
4301 #ifdef ISP_TARGET_MODE
4302 if (isp_target_async(isp, bus, mbox))
4307 case ASYNC_PDB_CHANGED:
4308 isp->isp_sendmarker = 1;
4309 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4310 isp_mark_getpdb_all(isp);
4311 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_PDB);
4314 case ASYNC_CHANGE_NOTIFY:
4316 * Not correct, but it will force us to rescan the loop.
4318 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4319 isp_mark_getpdb_all(isp);
4320 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_SNS);
4324 if (FCPARAM(isp)->isp_onfabric)
4325 FCPARAM(isp)->isp_topo = TOPO_F_PORT;
4327 FCPARAM(isp)->isp_topo = TOPO_N_PORT;
4328 isp_mark_getpdb_all(isp);
4329 isp->isp_sendmarker = 1;
4330 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4331 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4332 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4333 #ifdef ISP_TARGET_MODE
4334 if (isp_target_async(isp, bus, mbox))
4337 isp_prt(isp, ISP_LOGINFO, "Point-to-Point mode");
4340 case ASYNC_CONNMODE:
4341 mbox = ISP_READ(isp, OUTMAILBOX1);
4342 isp_mark_getpdb_all(isp);
4345 isp_prt(isp, ISP_LOGINFO,
4346 "Point-to-Point -> Loop mode");
4349 isp_prt(isp, ISP_LOGINFO,
4350 "Loop -> Point-to-Point mode");
4352 case ISP_CONN_BADLIP:
4353 isp_prt(isp, ISP_LOGWARN,
4354 "Point-to-Point -> Loop mode (BAD LIP)");
4356 case ISP_CONN_FATAL:
4357 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
4358 #ifdef ISP_FW_CRASH_DUMP
4359 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4361 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4363 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4366 case ISP_CONN_LOOPBACK:
4367 isp_prt(isp, ISP_LOGWARN,
4368 "Looped Back in Point-to-Point mode");
4371 isp_prt(isp, ISP_LOGWARN,
4372 "Unknown connection mode (0x%x)", mbox);
4375 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4376 isp->isp_sendmarker = 1;
4377 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4378 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4382 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
4388 u_int16_t handles[16];
4390 for (nh = 0, i = 1; i < MAX_MAILBOX(isp); i++) {
4391 if ((bus & (1 << i)) == 0) {
4394 handles[nh++] = ISP_READ(isp, MBOX_OFF(i));
4396 for (i = 0; i < nh; i++) {
4397 isp_fastpost_complete(isp, handles[i]);
4398 isp_prt(isp, ISP_LOGDEBUG3,
4399 "fast post completion of %u", handles[i]);
4401 if (isp->isp_fpcchiwater < nh)
4402 isp->isp_fpcchiwater = nh;
4404 isp->isp_intoasync++;
4410 * Handle other response entries. A pointer to the request queue output
4411 * index is here in case we want to eat several entries at once, although
4412 * this is not used currently.
4416 isp_handle_other_response(struct ispsoftc *isp, int type,
4417 isphdr_t *hp, u_int16_t *optrp)
4420 case RQSTYPE_STATUS_CONT:
4421 isp_prt(isp, ISP_LOGINFO, "Ignored Continuation Response");
4425 case RQSTYPE_ENABLE_LUN:
4426 case RQSTYPE_MODIFY_LUN:
4427 case RQSTYPE_NOTIFY:
4428 case RQSTYPE_NOTIFY_ACK:
4433 isp->isp_rsltccmplt++; /* count as a response completion */
4434 #ifdef ISP_TARGET_MODE
4435 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
4440 case RQSTYPE_REQUEST:
4443 if (type != isp_get_response_type(isp, hp)) {
4445 * This is questionable- we're just papering over
4446 * something we've seen on SMP linux in target
4447 * mode- we don't really know what's happening
4448 * here that causes us to think we've gotten
4449 * an entry, but that either the entry isn't
4450 * filled out yet or our CPU read data is stale.
4452 isp_prt(isp, ISP_LOGINFO,
4453 "unstable type in response queue");
4456 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
4457 isp_get_response_type(isp, hp));
4458 if (isp_async(isp, ISPASYNC_UNHANDLED_RESPONSE, hp)) {
4466 isp_parse_status(struct ispsoftc *isp, ispstatusreq_t *sp, XS_T *xs)
4468 switch (sp->req_completion_status & 0xff) {
4471 XS_SETERR(xs, HBA_NOERROR);
4475 case RQCS_INCOMPLETE:
4476 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
4477 isp_prt(isp, ISP_LOGDEBUG1,
4478 "Selection Timeout for %d.%d.%d",
4479 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4481 XS_SETERR(xs, HBA_SELTIMEOUT);
4485 isp_prt(isp, ISP_LOGERR,
4486 "command incomplete for %d.%d.%d, state 0x%x",
4487 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
4488 sp->req_state_flags);
4491 case RQCS_DMA_ERROR:
4492 isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
4493 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4496 case RQCS_TRANSPORT_ERROR:
4499 SNPRINTF(buf, sizeof (buf), "states=>");
4500 if (sp->req_state_flags & RQSF_GOT_BUS) {
4501 SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
4503 if (sp->req_state_flags & RQSF_GOT_TARGET) {
4504 SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
4506 if (sp->req_state_flags & RQSF_SENT_CDB) {
4507 SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
4509 if (sp->req_state_flags & RQSF_XFRD_DATA) {
4510 SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
4512 if (sp->req_state_flags & RQSF_GOT_STATUS) {
4513 SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
4515 if (sp->req_state_flags & RQSF_GOT_SENSE) {
4516 SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
4518 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
4519 SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
4521 SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
4522 if (sp->req_status_flags & RQSTF_DISCONNECT) {
4523 SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
4525 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
4526 SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
4528 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
4529 SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
4531 if (sp->req_status_flags & RQSTF_BUS_RESET) {
4532 SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
4534 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
4535 SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
4537 if (sp->req_status_flags & RQSTF_ABORTED) {
4538 SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
4540 if (sp->req_status_flags & RQSTF_TIMEOUT) {
4541 SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
4543 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
4544 SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
4546 isp_prt(isp, ISP_LOGERR, "%s", buf);
4547 isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d:\n%s",
4548 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), buf);
4551 case RQCS_RESET_OCCURRED:
4552 isp_prt(isp, ISP_LOGWARN,
4553 "bus reset destroyed command for %d.%d.%d",
4554 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4555 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4557 XS_SETERR(xs, HBA_BUSRESET);
4562 isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
4563 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4564 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4566 XS_SETERR(xs, HBA_ABORTED);
4571 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
4572 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4574 * Check to see if we logged out the device.
4577 if ((sp->req_completion_status & RQSTF_LOGOUT) &&
4578 FCPARAM(isp)->portdb[XS_TGT(xs)].valid &&
4579 FCPARAM(isp)->portdb[XS_TGT(xs)].fabric_dev) {
4580 FCPARAM(isp)->portdb[XS_TGT(xs)].relogin = 1;
4584 XS_SETERR(xs, HBA_CMDTIMEOUT);
4588 case RQCS_DATA_OVERRUN:
4589 XS_RESID(xs) = sp->req_resid;
4590 isp_prt(isp, ISP_LOGERR, "data overrun for command on %d.%d.%d",
4591 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4593 XS_SETERR(xs, HBA_DATAOVR);
4597 case RQCS_COMMAND_OVERRUN:
4598 isp_prt(isp, ISP_LOGERR,
4599 "command overrun for command on %d.%d.%d",
4600 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4603 case RQCS_STATUS_OVERRUN:
4604 isp_prt(isp, ISP_LOGERR,
4605 "status overrun for command on %d.%d.%d",
4606 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4609 case RQCS_BAD_MESSAGE:
4610 isp_prt(isp, ISP_LOGERR,
4611 "msg not COMMAND COMPLETE after status %d.%d.%d",
4612 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4615 case RQCS_NO_MESSAGE_OUT:
4616 isp_prt(isp, ISP_LOGERR,
4617 "No MESSAGE OUT phase after selection on %d.%d.%d",
4618 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4621 case RQCS_EXT_ID_FAILED:
4622 isp_prt(isp, ISP_LOGERR, "EXTENDED IDENTIFY failed %d.%d.%d",
4623 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4626 case RQCS_IDE_MSG_FAILED:
4627 isp_prt(isp, ISP_LOGERR,
4628 "INITIATOR DETECTED ERROR rejected by %d.%d.%d",
4629 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4632 case RQCS_ABORT_MSG_FAILED:
4633 isp_prt(isp, ISP_LOGERR, "ABORT OPERATION rejected by %d.%d.%d",
4634 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4637 case RQCS_REJECT_MSG_FAILED:
4638 isp_prt(isp, ISP_LOGERR, "MESSAGE REJECT rejected by %d.%d.%d",
4639 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4642 case RQCS_NOP_MSG_FAILED:
4643 isp_prt(isp, ISP_LOGERR, "NOP rejected by %d.%d.%d",
4644 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4647 case RQCS_PARITY_ERROR_MSG_FAILED:
4648 isp_prt(isp, ISP_LOGERR,
4649 "MESSAGE PARITY ERROR rejected by %d.%d.%d",
4650 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4653 case RQCS_DEVICE_RESET_MSG_FAILED:
4654 isp_prt(isp, ISP_LOGWARN,
4655 "BUS DEVICE RESET rejected by %d.%d.%d",
4656 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4659 case RQCS_ID_MSG_FAILED:
4660 isp_prt(isp, ISP_LOGERR, "IDENTIFY rejected by %d.%d.%d",
4661 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4664 case RQCS_UNEXP_BUS_FREE:
4665 isp_prt(isp, ISP_LOGERR, "%d.%d.%d had an unexpected bus free",
4666 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4669 case RQCS_DATA_UNDERRUN:
4672 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
4673 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
4674 isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
4675 XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
4676 (ru_marked)? "marked" : "not marked");
4678 XS_SETERR(xs, HBA_BOTCH);
4683 XS_RESID(xs) = sp->req_resid;
4685 XS_SETERR(xs, HBA_NOERROR);
4690 case RQCS_XACT_ERR1:
4691 isp_prt(isp, ISP_LOGERR, xact1, XS_CHANNEL(xs),
4692 XS_TGT(xs), XS_LUN(xs));
4695 case RQCS_XACT_ERR2:
4696 isp_prt(isp, ISP_LOGERR, xact2,
4697 XS_LUN(xs), XS_TGT(xs), XS_CHANNEL(xs));
4700 case RQCS_XACT_ERR3:
4701 isp_prt(isp, ISP_LOGERR, xact3,
4702 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4705 case RQCS_BAD_ENTRY:
4706 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
4709 case RQCS_QUEUE_FULL:
4710 isp_prt(isp, ISP_LOGDEBUG0,
4711 "internal queues full for %d.%d.%d status 0x%x",
4712 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), *XS_STSP(xs));
4715 * If QFULL or some other status byte is set, then this
4716 * isn't an error, per se.
4718 * Unfortunately, some QLogic f/w writers have, in
4719 * some cases, ommitted to *set* status to QFULL.
4722 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
4723 XS_SETERR(xs, HBA_NOERROR);
4731 *XS_STSP(xs) = SCSI_QFULL;
4732 XS_SETERR(xs, HBA_NOERROR);
4735 case RQCS_PHASE_SKIPPED:
4736 isp_prt(isp, ISP_LOGERR, pskip, XS_CHANNEL(xs),
4737 XS_TGT(xs), XS_LUN(xs));
4740 case RQCS_ARQS_FAILED:
4741 isp_prt(isp, ISP_LOGERR,
4742 "Auto Request Sense failed for %d.%d.%d",
4743 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4745 XS_SETERR(xs, HBA_ARQFAIL);
4749 case RQCS_WIDE_FAILED:
4750 isp_prt(isp, ISP_LOGERR,
4751 "Wide Negotiation failed for %d.%d.%d",
4752 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4754 sdparam *sdp = isp->isp_param;
4755 sdp += XS_CHANNEL(xs);
4756 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
4757 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4758 isp->isp_update |= (1 << XS_CHANNEL(xs));
4761 XS_SETERR(xs, HBA_NOERROR);
4765 case RQCS_SYNCXFER_FAILED:
4766 isp_prt(isp, ISP_LOGERR,
4767 "SDTR Message failed for target %d.%d.%d",
4768 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4770 sdparam *sdp = isp->isp_param;
4771 sdp += XS_CHANNEL(xs);
4772 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
4773 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4774 isp->isp_update |= (1 << XS_CHANNEL(xs));
4778 case RQCS_LVD_BUSERR:
4779 isp_prt(isp, ISP_LOGERR,
4780 "Bad LVD condition while talking to %d.%d.%d",
4781 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4784 case RQCS_PORT_UNAVAILABLE:
4786 * No such port on the loop. Moral equivalent of SELTIMEO
4788 case RQCS_PORT_LOGGED_OUT:
4790 * It was there (maybe)- treat as a selection timeout.
4792 if ((sp->req_completion_status & 0xff) == RQCS_PORT_UNAVAILABLE)
4793 isp_prt(isp, ISP_LOGINFO,
4794 "port unavailable for target %d", XS_TGT(xs));
4796 isp_prt(isp, ISP_LOGINFO,
4797 "port logout for target %d", XS_TGT(xs));
4799 * If we're on a local loop, force a LIP (which is overkill)
4800 * to force a re-login of this unit. If we're on fabric,
4801 * then we'll have to relogin as a matter of course.
4803 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4804 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4806 MEMZERO(&mbs, sizeof (mbs));
4807 mbs.param[0] = MBOX_INIT_LIP;
4808 isp_mboxcmd_qnw(isp, &mbs, 1);
4812 * Probably overkill.
4814 isp->isp_sendmarker = 1;
4815 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4816 isp_mark_getpdb_all(isp);
4817 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4819 XS_SETERR(xs, HBA_SELTIMEOUT);
4823 case RQCS_PORT_CHANGED:
4824 isp_prt(isp, ISP_LOGWARN,
4825 "port changed for target %d", XS_TGT(xs));
4827 XS_SETERR(xs, HBA_SELTIMEOUT);
4831 case RQCS_PORT_BUSY:
4832 isp_prt(isp, ISP_LOGWARN,
4833 "port busy for target %d", XS_TGT(xs));
4835 XS_SETERR(xs, HBA_TGTBSY);
4840 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x",
4841 sp->req_completion_status);
4845 XS_SETERR(xs, HBA_BOTCH);
4850 isp_fastpost_complete(struct ispsoftc *isp, u_int16_t fph)
4857 xs = isp_find_xs(isp, fph);
4859 isp_prt(isp, ISP_LOGWARN,
4860 "Command for fast post handle 0x%x not found", fph);
4863 isp_destroy_handle(isp, fph);
4866 * Since we don't have a result queue entry item,
4867 * we must believe that SCSI status is zero and
4868 * that all data transferred.
4870 XS_SET_STATE_STAT(isp, xs, NULL);
4872 *XS_STSP(xs) = SCSI_GOOD;
4873 if (XS_XFRLEN(xs)) {
4874 ISP_DMAFREE(isp, xs, fph);
4876 if (isp->isp_nactive)
4878 isp->isp_fphccmplt++;
4883 isp_mbox_continue(struct ispsoftc *isp)
4888 switch (isp->isp_lastmbxcmd) {
4889 case MBOX_WRITE_RAM_WORD:
4890 case MBOX_READ_RAM_WORD:
4891 case MBOX_READ_RAM_WORD_EXTENDED:
4896 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
4897 isp->isp_mbxwrk0 = 0;
4902 * Clear the previous interrupt.
4904 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
4905 ISP_WRITE(isp, BIU_SEMA, 0);
4908 * Continue with next word.
4910 MEMZERO(&mbs, sizeof (mbs));
4911 ptr = isp->isp_mbxworkp;
4912 switch (isp->isp_lastmbxcmd) {
4913 case MBOX_WRITE_RAM_WORD:
4914 mbs.param[2] = *ptr++;
4915 mbs.param[1] = isp->isp_mbxwrk1++;
4917 case MBOX_READ_RAM_WORD:
4918 case MBOX_READ_RAM_WORD_EXTENDED:
4919 *ptr++ = isp->isp_mboxtmp[2];
4920 mbs.param[1] = isp->isp_mbxwrk1++;
4923 isp->isp_mbxworkp = ptr;
4924 mbs.param[0] = isp->isp_lastmbxcmd;
4925 isp->isp_mbxwrk0 -= 1;
4926 isp_mboxcmd_qnw(isp, &mbs, 0);
4931 #define HIWRD(x) ((x) >> 16)
4932 #define LOWRD(x) ((x) & 0xffff)
4933 #define ISPOPMAP(a, b) (((a) << 16) | (b))
4934 static const u_int32_t mbpscsi[] = {
4935 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
4936 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
4937 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
4938 ISPOPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
4939 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
4940 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
4941 ISPOPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
4942 ISPOPMAP(0x03, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
4943 ISPOPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
4944 ISPOPMAP(0x00, 0x00), /* 0x09: */
4945 ISPOPMAP(0x00, 0x00), /* 0x0a: */
4946 ISPOPMAP(0x00, 0x00), /* 0x0b: */
4947 ISPOPMAP(0x00, 0x00), /* 0x0c: */
4948 ISPOPMAP(0x00, 0x00), /* 0x0d: */
4949 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
4950 ISPOPMAP(0x00, 0x00), /* 0x0f: */
4951 ISPOPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
4952 ISPOPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
4953 ISPOPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
4954 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
4955 ISPOPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
4956 ISPOPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
4957 ISPOPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
4958 ISPOPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
4959 ISPOPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
4960 ISPOPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
4961 ISPOPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
4962 ISPOPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
4963 ISPOPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
4964 ISPOPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
4965 ISPOPMAP(0x00, 0x00), /* 0x1e: */
4966 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
4967 ISPOPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
4968 ISPOPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
4969 ISPOPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
4970 ISPOPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
4971 ISPOPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
4972 ISPOPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
4973 ISPOPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
4974 ISPOPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
4975 ISPOPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
4976 ISPOPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
4977 ISPOPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
4978 ISPOPMAP(0x00, 0x00), /* 0x2b: */
4979 ISPOPMAP(0x00, 0x00), /* 0x2c: */
4980 ISPOPMAP(0x00, 0x00), /* 0x2d: */
4981 ISPOPMAP(0x00, 0x00), /* 0x2e: */
4982 ISPOPMAP(0x00, 0x00), /* 0x2f: */
4983 ISPOPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
4984 ISPOPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
4985 ISPOPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
4986 ISPOPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
4987 ISPOPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
4988 ISPOPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
4989 ISPOPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
4990 ISPOPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
4991 ISPOPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
4992 ISPOPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
4993 ISPOPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
4994 ISPOPMAP(0x00, 0x00), /* 0x3b: */
4995 ISPOPMAP(0x00, 0x00), /* 0x3c: */
4996 ISPOPMAP(0x00, 0x00), /* 0x3d: */
4997 ISPOPMAP(0x00, 0x00), /* 0x3e: */
4998 ISPOPMAP(0x00, 0x00), /* 0x3f: */
4999 ISPOPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
5000 ISPOPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
5001 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
5002 ISPOPMAP(0x00, 0x00), /* 0x43: */
5003 ISPOPMAP(0x00, 0x00), /* 0x44: */
5004 ISPOPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
5005 ISPOPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
5006 ISPOPMAP(0x00, 0x00), /* 0x47: */
5007 ISPOPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
5008 ISPOPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
5009 ISPOPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
5010 ISPOPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
5011 ISPOPMAP(0x00, 0x00), /* 0x4c: */
5012 ISPOPMAP(0x00, 0x00), /* 0x4d: */
5013 ISPOPMAP(0x00, 0x00), /* 0x4e: */
5014 ISPOPMAP(0x00, 0x00), /* 0x4f: */
5015 ISPOPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
5016 ISPOPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
5017 ISPOPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
5018 ISPOPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
5019 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
5020 ISPOPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
5021 ISPOPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
5022 ISPOPMAP(0x00, 0x00), /* 0x57: */
5023 ISPOPMAP(0x00, 0x00), /* 0x58: */
5024 ISPOPMAP(0x00, 0x00), /* 0x59: */
5025 ISPOPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
5026 ISPOPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
5027 ISPOPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
5028 ISPOPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
5031 #ifndef ISP_STRIPPED
5032 static char *scsi_mbcmd_names[] = {
5049 "INIT REQUEST QUEUE",
5050 "INIT RESULT QUEUE",
5060 "SINGLE STEP QUEUE",
5062 "GET DEV QUEUE STATUS",
5064 "GET FIRMWARE STATUS",
5066 "GET SELECT TIMEOUT",
5068 "GET TAG AGE LIMIT",
5070 "GET ACT NEG STATE",
5071 "GET ASYNC DATA SETUP TIME",
5073 "GET TARGET PARAMS",
5074 "GET DEV QUEUE PARAMS",
5075 "GET RESET DELAY PARAMS",
5082 "SET SELECT TIMEOUT",
5084 "SET TAG AGE LIMIT",
5086 "SET ACT NEG STATE",
5087 "SET ASYNC DATA SETUP TIME",
5088 "SET PCI CONTROL PARAMS",
5089 "SET TARGET PARAMS",
5090 "SET DEV QUEUE PARAMS",
5091 "SET RESET DELAY PARAMS",
5097 "RETURN BIOS BLOCK ADDR",
5098 "WRITE FOUR RAM WORDS",
5102 "SET SYSTEM PARAMETER",
5103 "GET SYSTEM PARAMETER",
5105 "GET SCAM CONFIGURATION",
5106 "SET SCAM CONFIGURATION",
5107 "SET FIRMWARE FEATURES",
5108 "GET FIRMWARE FEATURES",
5115 "INITIALIZE REQUEST QUEUE A64",
5116 "INITIALIZE RESPONSE QUEUE A64",
5118 "ENABLE TARGET MODE",
5119 "GET TARGET MODE STATE",
5123 "SET DATA OVERRUN RECOVERY MODE",
5124 "GET DATA OVERRUN RECOVERY MODE",
5130 static const u_int32_t mbpfc[] = {
5131 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
5132 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
5133 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
5134 ISPOPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
5135 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
5136 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
5137 ISPOPMAP(0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
5138 ISPOPMAP(0x03, 0x05), /* 0x07: MBOX_VERIFY_CHECKSUM */
5139 ISPOPMAP(0x01, 0x4f), /* 0x08: MBOX_ABOUT_FIRMWARE */
5140 ISPOPMAP(0xdf, 0x01), /* 0x09: LOAD RAM */
5141 ISPOPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
5142 ISPOPMAP(0x00, 0x00), /* 0x0b: */
5143 ISPOPMAP(0x00, 0x00), /* 0x0c: */
5144 ISPOPMAP(0x00, 0x00), /* 0x0d: */
5145 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
5146 ISPOPMAP(0x03, 0x07), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED(1) */
5147 ISPOPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
5148 ISPOPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
5149 ISPOPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
5150 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
5151 ISPOPMAP(0x01, 0xff), /* 0x14: MBOX_STOP_FIRMWARE */
5152 ISPOPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
5153 ISPOPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
5154 ISPOPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
5155 ISPOPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
5156 ISPOPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
5157 ISPOPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
5158 ISPOPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
5159 ISPOPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
5160 ISPOPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
5161 ISPOPMAP(0x00, 0x00), /* 0x1e: */
5162 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
5163 ISPOPMAP(0x01, 0x4f), /* 0x20: MBOX_GET_LOOP_ID */
5164 ISPOPMAP(0x00, 0x00), /* 0x21: */
5165 ISPOPMAP(0x01, 0x07), /* 0x22: MBOX_GET_RETRY_COUNT */
5166 ISPOPMAP(0x00, 0x00), /* 0x23: */
5167 ISPOPMAP(0x00, 0x00), /* 0x24: */
5168 ISPOPMAP(0x00, 0x00), /* 0x25: */
5169 ISPOPMAP(0x00, 0x00), /* 0x26: */
5170 ISPOPMAP(0x00, 0x00), /* 0x27: */
5171 ISPOPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
5172 ISPOPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
5173 ISPOPMAP(0x00, 0x00), /* 0x2a: */
5174 ISPOPMAP(0x00, 0x00), /* 0x2b: */
5175 ISPOPMAP(0x00, 0x00), /* 0x2c: */
5176 ISPOPMAP(0x00, 0x00), /* 0x2d: */
5177 ISPOPMAP(0x00, 0x00), /* 0x2e: */
5178 ISPOPMAP(0x00, 0x00), /* 0x2f: */
5179 ISPOPMAP(0x00, 0x00), /* 0x30: */
5180 ISPOPMAP(0x00, 0x00), /* 0x31: */
5181 ISPOPMAP(0x07, 0x07), /* 0x32: MBOX_SET_RETRY_COUNT */
5182 ISPOPMAP(0x00, 0x00), /* 0x33: */
5183 ISPOPMAP(0x00, 0x00), /* 0x34: */
5184 ISPOPMAP(0x00, 0x00), /* 0x35: */
5185 ISPOPMAP(0x00, 0x00), /* 0x36: */
5186 ISPOPMAP(0x00, 0x00), /* 0x37: */
5187 ISPOPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
5188 ISPOPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
5189 ISPOPMAP(0x00, 0x00), /* 0x3a: */
5190 ISPOPMAP(0x00, 0x00), /* 0x3b: */
5191 ISPOPMAP(0x00, 0x00), /* 0x3c: */
5192 ISPOPMAP(0x00, 0x00), /* 0x3d: */
5193 ISPOPMAP(0x00, 0x00), /* 0x3e: */
5194 ISPOPMAP(0x00, 0x00), /* 0x3f: */
5195 ISPOPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
5196 ISPOPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
5197 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_GET_RESOURCE_COUNTS */
5198 ISPOPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_NON_PARTICIPATING_MODE */
5199 ISPOPMAP(0x00, 0x00), /* 0x44: */
5200 ISPOPMAP(0x00, 0x00), /* 0x45: */
5201 ISPOPMAP(0x00, 0x00), /* 0x46: */
5202 ISPOPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
5203 ISPOPMAP(0x00, 0x00), /* 0x48: */
5204 ISPOPMAP(0x00, 0x00), /* 0x49: */
5205 ISPOPMAP(0x00, 0x00), /* 0x4a: */
5206 ISPOPMAP(0x00, 0x00), /* 0x4b: */
5207 ISPOPMAP(0x00, 0x00), /* 0x4c: */
5208 ISPOPMAP(0x00, 0x00), /* 0x4d: */
5209 ISPOPMAP(0x00, 0x00), /* 0x4e: */
5210 ISPOPMAP(0x00, 0x00), /* 0x4f: */
5211 ISPOPMAP(0x00, 0x00), /* 0x50: */
5212 ISPOPMAP(0x00, 0x00), /* 0x51: */
5213 ISPOPMAP(0x00, 0x00), /* 0x52: */
5214 ISPOPMAP(0x00, 0x00), /* 0x53: */
5215 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
5216 ISPOPMAP(0x00, 0x00), /* 0x55: */
5217 ISPOPMAP(0x00, 0x00), /* 0x56: */
5218 ISPOPMAP(0x00, 0x00), /* 0x57: */
5219 ISPOPMAP(0x00, 0x00), /* 0x58: */
5220 ISPOPMAP(0x00, 0x00), /* 0x59: */
5221 ISPOPMAP(0x00, 0x00), /* 0x5a: */
5222 ISPOPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
5223 ISPOPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
5224 ISPOPMAP(0x07, 0x03), /* 0x5d: MBOX_GET_SET_DATA_RATE */
5225 ISPOPMAP(0x00, 0x00), /* 0x5e: */
5226 ISPOPMAP(0x00, 0x00), /* 0x5f: */
5227 ISPOPMAP(0xfd, 0x31), /* 0x60: MBOX_INIT_FIRMWARE */
5228 ISPOPMAP(0x00, 0x00), /* 0x61: */
5229 ISPOPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
5230 ISPOPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
5231 ISPOPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
5232 ISPOPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
5233 ISPOPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
5234 ISPOPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
5235 ISPOPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
5236 ISPOPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
5237 ISPOPMAP(0x03, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
5238 ISPOPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
5239 ISPOPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
5240 ISPOPMAP(0x00, 0x00), /* 0x6d: */
5241 ISPOPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
5242 ISPOPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
5243 ISPOPMAP(0x03, 0x01), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
5244 ISPOPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
5245 ISPOPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
5246 ISPOPMAP(0x00, 0x00), /* 0x73: */
5247 ISPOPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
5248 ISPOPMAP(0xcf, 0x03), /* 0x75: GET PORT/NODE NAME LIST */
5249 ISPOPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
5250 ISPOPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
5251 ISPOPMAP(0x00, 0x00), /* 0x78: */
5252 ISPOPMAP(0x00, 0x00), /* 0x79: */
5253 ISPOPMAP(0x00, 0x00), /* 0x7a: */
5254 ISPOPMAP(0x00, 0x00), /* 0x7b: */
5255 ISPOPMAP(0x4f, 0x03), /* 0x7c: Get ID List */
5256 ISPOPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
5257 ISPOPMAP(0x0f, 0x01) /* 0x7e: LUN RESET */
5262 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
5263 * do not access at this time in the core driver. The caller is
5264 * responsible for setting this register first (Gross!).
5267 #ifndef ISP_STRIPPED
5268 static char *fc_mbcmd_names[] = {
5282 "READ RAM WORD EXTENDED",
5285 "INIT REQUEST QUEUE",
5286 "INIT RESULT QUEUE",
5296 "SINGLE STEP QUEUE",
5298 "GET DEV QUEUE STATUS",
5300 "GET FIRMWARE STATUS",
5309 "GET FIRMWARE OPTIONS",
5310 "GET PORT QUEUE PARAMS",
5325 "SET FIRMWARE OPTIONS",
5326 "SET PORT QUEUE PARAMS",
5335 "GET RESOURCE COUNTS",
5336 "REQUEST NON PARTICIPATING MODE",
5340 "GET PORT DATABASE,, ENHANCED",
5362 "GET/SET DATA RATE",
5368 "GET FC-AL POSITION MAP",
5369 "GET PORT DATABASE",
5381 "SEND CHANGE REQUEST",
5386 "GET PORT/NODE NAME LIST",
5388 "INITIALIZE IP MAILBOX",
5400 isp_mboxcmd_qnw(struct ispsoftc *isp, mbreg_t *mbp, int nodelay)
5402 unsigned int ibits, obits, box, opcode;
5403 const u_int32_t *mcp;
5410 opcode = mbp->param[0];
5411 ibits = HIWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5412 obits = LOWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5413 ibits |= mbp->ibits;
5414 obits |= mbp->obits;
5415 for (box = 0; box < MAX_MAILBOX(isp); box++) {
5416 if (ibits & (1 << box)) {
5417 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5420 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5424 isp->isp_lastmbxcmd = opcode;
5425 isp->isp_obits = obits;
5426 isp->isp_mboxbsy = 1;
5428 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5430 * Oddly enough, if we're not delaying for an answer,
5431 * delay a bit to give the f/w a chance to pick up the
5440 isp_mboxcmd(struct ispsoftc *isp, mbreg_t *mbp, int logmask)
5442 char *cname, *xname, tname[16], mname[16];
5443 unsigned int lim, ibits, obits, box, opcode;
5444 const u_int32_t *mcp;
5448 lim = (sizeof (mbpfc) / sizeof (mbpfc[0]));
5451 lim = (sizeof (mbpscsi) / sizeof (mbpscsi[0]));
5454 if ((opcode = mbp->param[0]) >= lim) {
5455 mbp->param[0] = MBOX_INVALID_COMMAND;
5456 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
5460 ibits = HIWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5461 obits = LOWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5463 ibits |= mbp->ibits;
5464 obits |= mbp->obits;
5466 if (ibits == 0 && obits == 0) {
5467 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
5468 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
5473 * Get exclusive usage of mailbox registers.
5477 for (box = 0; box < MAX_MAILBOX(isp); box++) {
5478 if (ibits & (1 << box)) {
5479 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5481 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5484 isp->isp_lastmbxcmd = opcode;
5487 * We assume that we can't overwrite a previous command.
5489 isp->isp_obits = obits;
5490 isp->isp_mboxbsy = 1;
5493 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
5495 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5498 * While we haven't finished the command, spin our wheels here.
5500 MBOX_WAIT_COMPLETE(isp);
5502 if (isp->isp_mboxbsy) {
5504 * Command timed out.
5506 isp->isp_mboxbsy = 0;
5512 * Copy back output registers.
5514 for (box = 0; box < MAX_MAILBOX(isp); box++) {
5515 if (obits & (1 << box)) {
5516 mbp->param[box] = isp->isp_mboxtmp[box];
5522 if (logmask == 0 || opcode == MBOX_EXEC_FIRMWARE) {
5528 cname = (IS_FC(isp))? fc_mbcmd_names[opcode] : scsi_mbcmd_names[opcode];
5530 if (cname == NULL) {
5532 SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
5536 * Just to be chatty here...
5539 switch (mbp->param[0]) {
5540 case MBOX_COMMAND_COMPLETE:
5542 case MBOX_INVALID_COMMAND:
5543 if (logmask & MBLOGMASK(MBOX_COMMAND_COMPLETE))
5544 xname = "INVALID COMMAND";
5546 case MBOX_HOST_INTERFACE_ERROR:
5547 if (logmask & MBLOGMASK(MBOX_HOST_INTERFACE_ERROR))
5548 xname = "HOST INTERFACE ERROR";
5550 case MBOX_TEST_FAILED:
5551 if (logmask & MBLOGMASK(MBOX_TEST_FAILED))
5552 xname = "TEST FAILED";
5554 case MBOX_COMMAND_ERROR:
5555 if (logmask & MBLOGMASK(MBOX_COMMAND_ERROR))
5556 xname = "COMMAND ERROR";
5558 case MBOX_COMMAND_PARAM_ERROR:
5559 if (logmask & MBLOGMASK(MBOX_COMMAND_PARAM_ERROR))
5560 xname = "COMMAND PARAMETER ERROR";
5562 case MBOX_LOOP_ID_USED:
5563 if (logmask & MBLOGMASK(MBOX_LOOP_ID_USED))
5564 xname = "LOOP ID ALREADY IN USE";
5566 case MBOX_PORT_ID_USED:
5567 if (logmask & MBLOGMASK(MBOX_PORT_ID_USED))
5568 xname = "PORT ID ALREADY IN USE";
5570 case MBOX_ALL_IDS_USED:
5571 if (logmask & MBLOGMASK(MBOX_ALL_IDS_USED))
5572 xname = "ALL LOOP IDS IN USE";
5574 case 0: /* special case */
5578 SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
5583 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s)",
5588 isp_fw_state(struct ispsoftc *isp)
5592 fcparam *fcp = isp->isp_param;
5594 MEMZERO(&mbs, sizeof (mbs));
5595 mbs.param[0] = MBOX_GET_FW_STATE;
5596 isp_mboxcmd(isp, &mbs, MBLOGALL);
5597 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
5598 fcp->isp_fwstate = mbs.param[1];
5604 isp_update(struct ispsoftc *isp)
5608 for (bus = 0, upmask = isp->isp_update; upmask != 0; bus++) {
5609 if (upmask & (1 << bus)) {
5610 isp_update_bus(isp, bus);
5612 upmask &= ~(1 << bus);
5617 isp_update_bus(struct ispsoftc *isp, int bus)
5623 isp->isp_update &= ~(1 << bus);
5626 * There are no 'per-bus' settings for Fibre Channel.
5630 sdp = isp->isp_param;
5632 MEMZERO(&mbs, sizeof (mbs));
5634 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5635 u_int16_t flags, period, offset;
5638 if (sdp->isp_devparam[tgt].dev_enable == 0) {
5639 sdp->isp_devparam[tgt].dev_update = 0;
5640 sdp->isp_devparam[tgt].dev_refresh = 0;
5641 isp_prt(isp, ISP_LOGDEBUG0,
5642 "skipping target %d bus %d update", tgt, bus);
5646 * If the goal is to update the status of the device,
5647 * take what's in goal_flags and try and set the device
5648 * toward that. Otherwise, if we're just refreshing the
5649 * current device state, get the current parameters.
5653 * Refresh overrides set
5655 if (sdp->isp_devparam[tgt].dev_refresh) {
5656 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
5657 sdp->isp_devparam[tgt].dev_refresh = 0;
5659 } else if (sdp->isp_devparam[tgt].dev_update) {
5660 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
5662 * Make sure goal_flags has "Renegotiate on Error"
5663 * on and "Freeze Queue on Error" off.
5665 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
5666 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
5668 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
5671 * Insist that PARITY must be enabled
5672 * if SYNC or WIDE is enabled.
5674 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
5675 mbs.param[2] |= DPARM_PARITY;
5678 if ((mbs.param[2] & DPARM_SYNC) == 0) {
5682 (sdp->isp_devparam[tgt].goal_offset << 8) |
5683 (sdp->isp_devparam[tgt].goal_period);
5686 * A command completion later that has
5687 * RQSTF_NEGOTIATION set can cause
5688 * the dev_refresh/announce cycle also.
5690 * Note: It is really important to update our current
5691 * flags with at least the state of TAG capabilities-
5692 * otherwise we might try and send a tagged command
5693 * when we have it all turned off. So change it here
5694 * to say that current already matches goal.
5696 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
5697 sdp->isp_devparam[tgt].actv_flags |=
5698 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
5699 isp_prt(isp, ISP_LOGDEBUG0,
5700 "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
5701 bus, tgt, mbs.param[2], mbs.param[3] >> 8,
5702 mbs.param[3] & 0xff);
5703 sdp->isp_devparam[tgt].dev_update = 0;
5704 sdp->isp_devparam[tgt].dev_refresh = 1;
5709 mbs.param[1] = (bus << 15) | (tgt << 8);
5710 isp_mboxcmd(isp, &mbs, MBLOGALL);
5712 isp->isp_sendmarker |= (1 << bus);
5715 flags = mbs.param[2];
5716 period = mbs.param[3] & 0xff;
5717 offset = mbs.param[3] >> 8;
5718 sdp->isp_devparam[tgt].actv_flags = flags;
5719 sdp->isp_devparam[tgt].actv_period = period;
5720 sdp->isp_devparam[tgt].actv_offset = offset;
5721 get = (bus << 16) | tgt;
5722 (void) isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, &get);
5725 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5726 if (sdp->isp_devparam[tgt].dev_update ||
5727 sdp->isp_devparam[tgt].dev_refresh) {
5728 isp->isp_update |= (1 << bus);
5734 #ifndef DEFAULT_FRAMESIZE
5735 #define DEFAULT_FRAMESIZE(isp) ICB_DFLT_FRMLEN
5737 #ifndef DEFAULT_EXEC_THROTTLE
5738 #define DEFAULT_EXEC_THROTTLE(isp) ISP_EXEC_THROTTLE
5742 isp_setdfltparm(struct ispsoftc *isp, int channel)
5748 MEMZERO(&mbs, sizeof (mbs));
5750 fcparam *fcp = (fcparam *) isp->isp_param;
5754 if (fcp->isp_gotdparms) {
5757 fcp->isp_gotdparms = 1;
5758 fcp->isp_maxfrmlen = DEFAULT_FRAMESIZE(isp);
5759 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
5760 fcp->isp_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
5761 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
5762 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
5763 /* Platform specific.... */
5764 fcp->isp_loopid = DEFAULT_LOOPID(isp);
5765 fcp->isp_nodewwn = DEFAULT_NODEWWN(isp);
5766 fcp->isp_portwwn = DEFAULT_PORTWWN(isp);
5767 fcp->isp_fwoptions = 0;
5768 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
5769 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
5770 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
5771 #ifndef ISP_NO_FASTPOST_FC
5772 fcp->isp_fwoptions |= ICBOPT_FAST_POST;
5774 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
5775 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
5778 * Make sure this is turned off now until we get
5779 * extended options from NVRAM
5781 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
5784 * Now try and read NVRAM unless told to not do so.
5785 * This will set fcparam's isp_nodewwn && isp_portwwn.
5787 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5788 nvfail = isp_read_nvram(isp);
5790 isp->isp_confopts |= ISP_CFG_NONVRAM;
5795 * Set node && port to override platform set defaults
5796 * unless the nvram read failed (or none was done),
5797 * or the platform code wants to use what had been
5798 * set in the defaults.
5801 isp->isp_confopts |= ISP_CFG_OWNWWPN|ISP_CFG_OWNWWNN;
5803 if (isp->isp_confopts & ISP_CFG_OWNWWNN) {
5804 isp_prt(isp, ISP_LOGCONFIG, "Using Node WWN 0x%08x%08x",
5805 (u_int32_t) (DEFAULT_NODEWWN(isp) >> 32),
5806 (u_int32_t) (DEFAULT_NODEWWN(isp) & 0xffffffff));
5807 ISP_NODEWWN(isp) = DEFAULT_NODEWWN(isp);
5810 * We always start out with values derived
5811 * from NVRAM or our platform default.
5813 ISP_NODEWWN(isp) = fcp->isp_nodewwn;
5815 if (isp->isp_confopts & ISP_CFG_OWNWWPN) {
5816 isp_prt(isp, ISP_LOGCONFIG, "Using Port WWN 0x%08x%08x",
5817 (u_int32_t) (DEFAULT_PORTWWN(isp) >> 32),
5818 (u_int32_t) (DEFAULT_PORTWWN(isp) & 0xffffffff));
5819 ISP_PORTWWN(isp) = DEFAULT_PORTWWN(isp);
5822 * We always start out with values derived
5823 * from NVRAM or our platform default.
5825 ISP_PORTWWN(isp) = fcp->isp_portwwn;
5830 sdp = (sdparam *) isp->isp_param;
5834 * Been there, done that, got the T-shirt...
5836 if (sdp->isp_gotdparms) {
5839 sdp->isp_gotdparms = 1;
5842 * Establish some default parameters.
5844 sdp->isp_cmd_dma_burst_enable = 0;
5845 sdp->isp_data_dma_burst_enabl = 1;
5846 sdp->isp_fifo_threshold = 0;
5847 sdp->isp_initiator_id = DEFAULT_IID(isp);
5848 if (isp->isp_type >= ISP_HA_SCSI_1040) {
5849 sdp->isp_async_data_setup = 9;
5851 sdp->isp_async_data_setup = 6;
5853 sdp->isp_selection_timeout = 250;
5854 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
5855 sdp->isp_tag_aging = 8;
5856 sdp->isp_bus_reset_delay = 5;
5858 * Don't retry selection, busy or queue full automatically- reflect
5861 sdp->isp_retry_count = 0;
5862 sdp->isp_retry_delay = 0;
5864 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5865 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
5866 sdp->isp_devparam[tgt].dev_enable = 1;
5870 * If we've not been told to avoid reading NVRAM, try and read it.
5871 * If we're successful reading it, we can then return because NVRAM
5872 * will tell us what the desired settings are. Otherwise, we establish
5873 * some reasonable 'fake' nvram and goal defaults.
5876 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5877 if (isp_read_nvram(isp) == 0) {
5883 * Now try and see whether we have specific values for them.
5885 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5886 mbs.param[0] = MBOX_GET_ACT_NEG_STATE;
5887 isp_mboxcmd(isp, &mbs, MBLOGNONE);
5888 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
5889 sdp->isp_req_ack_active_neg = 1;
5890 sdp->isp_data_line_active_neg = 1;
5892 sdp->isp_req_ack_active_neg =
5893 (mbs.param[1+channel] >> 4) & 0x1;
5894 sdp->isp_data_line_active_neg =
5895 (mbs.param[1+channel] >> 5) & 0x1;
5899 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc3,
5900 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
5901 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
5902 sdp->isp_retry_delay, sdp->isp_async_data_setup);
5903 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc3,
5904 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
5905 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
5906 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
5909 * The trick here is to establish a default for the default (honk!)
5910 * state (goal_flags). Then try and get the current status from
5911 * the card to fill in the current state. We don't, in fact, set
5912 * the default to the SAFE default state- that's not the goal state.
5914 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5916 sdp->isp_devparam[tgt].actv_offset = 0;
5917 sdp->isp_devparam[tgt].actv_period = 0;
5918 sdp->isp_devparam[tgt].actv_flags = 0;
5920 sdp->isp_devparam[tgt].goal_flags =
5921 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
5924 * We default to Wide/Fast for versions less than a 1040
5925 * (unless it's SBus).
5927 if (IS_ULTRA3(isp)) {
5928 off = ISP_80M_SYNCPARMS >> 8;
5929 per = ISP_80M_SYNCPARMS & 0xff;
5930 } else if (IS_ULTRA2(isp)) {
5931 off = ISP_40M_SYNCPARMS >> 8;
5932 per = ISP_40M_SYNCPARMS & 0xff;
5933 } else if (IS_1240(isp)) {
5934 off = ISP_20M_SYNCPARMS >> 8;
5935 per = ISP_20M_SYNCPARMS & 0xff;
5936 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
5937 isp->isp_type < ISP_HA_SCSI_1020A) ||
5938 (isp->isp_bustype == ISP_BT_PCI &&
5939 isp->isp_type < ISP_HA_SCSI_1040) ||
5940 (isp->isp_clock && isp->isp_clock < 60) ||
5941 (sdp->isp_ultramode == 0)) {
5942 off = ISP_10M_SYNCPARMS >> 8;
5943 per = ISP_10M_SYNCPARMS & 0xff;
5945 off = ISP_20M_SYNCPARMS_1040 >> 8;
5946 per = ISP_20M_SYNCPARMS_1040 & 0xff;
5948 sdp->isp_devparam[tgt].goal_offset =
5949 sdp->isp_devparam[tgt].nvrm_offset = off;
5950 sdp->isp_devparam[tgt].goal_period =
5951 sdp->isp_devparam[tgt].nvrm_period = per;
5953 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc3,
5954 channel, tgt, sdp->isp_devparam[tgt].nvrm_flags,
5955 sdp->isp_devparam[tgt].nvrm_offset,
5956 sdp->isp_devparam[tgt].nvrm_period);
5961 * Re-initialize the ISP and complete all orphaned commands
5962 * with a 'botched' notice. The reset/init routines should
5963 * not disturb an already active list of commands.
5965 * Locks held prior to coming here.
5969 isp_reinit(struct ispsoftc *isp)
5975 isp_mark_getpdb_all(isp);
5978 if (isp->isp_state != ISP_RESETSTATE) {
5979 isp_prt(isp, ISP_LOGERR, "isp_reinit cannot reset card");
5980 } else if (isp->isp_role != ISP_ROLE_NONE) {
5982 if (isp->isp_state == ISP_INITSTATE) {
5983 isp->isp_state = ISP_RUNSTATE;
5985 if (isp->isp_state != ISP_RUNSTATE) {
5986 isp_prt(isp, ISP_LOGERR,
5987 "isp_reinit cannot restart card");
5990 isp->isp_nactive = 0;
5992 for (i = 0; i < isp->isp_maxcmds; i++) {
5994 xs = isp->isp_xflist[i];
5998 handle = isp_index_handle(i);
5999 isp_destroy_handle(isp, handle);
6000 if (XS_XFRLEN(xs)) {
6001 ISP_DMAFREE(isp, xs, handle);
6002 XS_RESID(xs) = XS_XFRLEN(xs);
6006 XS_SETERR(xs, HBA_BUSRESET);
6015 isp_read_nvram(struct ispsoftc *isp)
6018 u_int8_t csum, minversion;
6020 u_int8_t _x[ISP2100_NVRAM_SIZE];
6021 u_int16_t _s[ISP2100_NVRAM_SIZE>>1];
6023 #define nvram_data _n._x
6024 #define nvram_words _n._s
6027 amt = ISP2100_NVRAM_SIZE;
6029 } else if (IS_ULTRA2(isp)) {
6030 amt = ISP1080_NVRAM_SIZE;
6033 amt = ISP_NVRAM_SIZE;
6038 * Just read the first two words first to see if we have a valid
6039 * NVRAM to continue reading the rest with.
6041 for (i = 0; i < 2; i++) {
6042 isp_rdnvram_word(isp, i, &nvram_words[i]);
6044 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
6045 nvram_data[2] != 'P') {
6046 if (isp->isp_bustype != ISP_BT_SBUS) {
6047 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
6048 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x",
6049 nvram_data[0], nvram_data[1], nvram_data[2]);
6053 for (i = 2; i < amt>>1; i++) {
6054 isp_rdnvram_word(isp, i, &nvram_words[i]);
6056 for (csum = 0, i = 0; i < amt; i++) {
6057 csum += nvram_data[i];
6060 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
6063 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
6064 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
6065 ISP_NVRAM_VERSION(nvram_data));
6069 if (IS_ULTRA3(isp)) {
6070 isp_parse_nvram_12160(isp, 0, nvram_data);
6072 isp_parse_nvram_12160(isp, 1, nvram_data);
6073 } else if (IS_1080(isp)) {
6074 isp_parse_nvram_1080(isp, 0, nvram_data);
6075 } else if (IS_1280(isp) || IS_1240(isp)) {
6076 isp_parse_nvram_1080(isp, 0, nvram_data);
6077 isp_parse_nvram_1080(isp, 1, nvram_data);
6078 } else if (IS_SCSI(isp)) {
6079 isp_parse_nvram_1020(isp, nvram_data);
6081 isp_parse_nvram_2100(isp, nvram_data);
6089 isp_rdnvram_word(struct ispsoftc *isp, int wo, u_int16_t *rp)
6092 u_int16_t bit, rqst;
6094 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
6096 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
6100 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
6101 if (IS_2312(isp) && isp->isp_port) {
6104 rqst = (ISP_NVRAM_READ << 8) | wo;
6106 } else if (IS_ULTRA2(isp)) {
6107 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
6108 rqst = (ISP_NVRAM_READ << 8) | wo;
6111 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
6112 rqst = (ISP_NVRAM_READ << 6) | wo;
6117 * Clock the word select request out...
6119 for (i = cbits; i >= 0; i--) {
6120 if ((rqst >> i) & 1) {
6121 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
6123 bit = BIU_NVRAM_SELECT;
6125 ISP_WRITE(isp, BIU_NVRAM, bit);
6127 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
6129 ISP_WRITE(isp, BIU_NVRAM, bit);
6133 * Now read the result back in (bits come back in MSB format).
6136 for (i = 0; i < 16; i++) {
6139 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
6141 rv = ISP_READ(isp, BIU_NVRAM);
6142 if (rv & BIU_NVRAM_DATAIN) {
6146 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
6149 ISP_WRITE(isp, BIU_NVRAM, 0);
6151 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
6155 isp_parse_nvram_1020(struct ispsoftc *isp, u_int8_t *nvram_data)
6157 sdparam *sdp = (sdparam *) isp->isp_param;
6160 sdp->isp_fifo_threshold =
6161 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
6162 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
6164 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6165 sdp->isp_initiator_id =
6166 ISP_NVRAM_INITIATOR_ID(nvram_data);
6168 sdp->isp_bus_reset_delay =
6169 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
6171 sdp->isp_retry_count =
6172 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
6174 sdp->isp_retry_delay =
6175 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
6177 sdp->isp_async_data_setup =
6178 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
6180 if (isp->isp_type >= ISP_HA_SCSI_1040) {
6181 if (sdp->isp_async_data_setup < 9) {
6182 sdp->isp_async_data_setup = 9;
6185 if (sdp->isp_async_data_setup != 6) {
6186 sdp->isp_async_data_setup = 6;
6190 sdp->isp_req_ack_active_neg =
6191 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
6193 sdp->isp_data_line_active_neg =
6194 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
6196 sdp->isp_data_dma_burst_enabl =
6197 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
6199 sdp->isp_cmd_dma_burst_enable =
6200 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
6202 sdp->isp_tag_aging =
6203 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
6205 sdp->isp_selection_timeout =
6206 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
6208 sdp->isp_max_queue_depth =
6209 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
6211 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
6213 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6214 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6215 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6216 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6217 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6218 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6219 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6220 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6222 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6223 sdp->isp_devparam[tgt].dev_enable =
6224 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
6225 sdp->isp_devparam[tgt].exc_throttle =
6226 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
6227 sdp->isp_devparam[tgt].nvrm_offset =
6228 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
6229 sdp->isp_devparam[tgt].nvrm_period =
6230 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
6232 * We probably shouldn't lie about this, but it
6233 * it makes it much safer if we limit NVRAM values
6236 if (isp->isp_type < ISP_HA_SCSI_1040) {
6238 * If we're not ultra, we can't possibly
6239 * be a shorter period than this.
6241 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
6242 sdp->isp_devparam[tgt].nvrm_period = 0x19;
6244 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
6245 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
6248 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
6249 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
6252 sdp->isp_devparam[tgt].nvrm_flags = 0;
6253 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
6254 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6255 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6256 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
6257 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6258 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
6259 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6260 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
6261 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6262 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
6263 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6264 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
6265 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6266 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
6267 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6268 0, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6269 sdp->isp_devparam[tgt].nvrm_offset,
6270 sdp->isp_devparam[tgt].nvrm_period);
6271 sdp->isp_devparam[tgt].goal_offset =
6272 sdp->isp_devparam[tgt].nvrm_offset;
6273 sdp->isp_devparam[tgt].goal_period =
6274 sdp->isp_devparam[tgt].nvrm_period;
6275 sdp->isp_devparam[tgt].goal_flags =
6276 sdp->isp_devparam[tgt].nvrm_flags;
6281 isp_parse_nvram_1080(struct ispsoftc *isp, int bus, u_int8_t *nvram_data)
6283 sdparam *sdp = (sdparam *) isp->isp_param;
6288 sdp->isp_fifo_threshold =
6289 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
6291 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6292 sdp->isp_initiator_id =
6293 ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
6295 sdp->isp_bus_reset_delay =
6296 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6298 sdp->isp_retry_count =
6299 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6301 sdp->isp_retry_delay =
6302 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6304 sdp->isp_async_data_setup =
6305 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6307 sdp->isp_req_ack_active_neg =
6308 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6310 sdp->isp_data_line_active_neg =
6311 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6313 sdp->isp_data_dma_burst_enabl =
6314 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6316 sdp->isp_cmd_dma_burst_enable =
6317 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6319 sdp->isp_selection_timeout =
6320 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6322 sdp->isp_max_queue_depth =
6323 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6325 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6326 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6327 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6328 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6329 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6330 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6331 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6332 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6335 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6336 sdp->isp_devparam[tgt].dev_enable =
6337 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6338 sdp->isp_devparam[tgt].exc_throttle =
6339 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6340 sdp->isp_devparam[tgt].nvrm_offset =
6341 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6342 sdp->isp_devparam[tgt].nvrm_period =
6343 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6344 sdp->isp_devparam[tgt].nvrm_flags = 0;
6345 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6346 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6347 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6348 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6349 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6350 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6351 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6352 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6353 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6354 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6355 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6356 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6357 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6358 sdp->isp_devparam[tgt].actv_flags = 0;
6359 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6360 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6361 sdp->isp_devparam[tgt].nvrm_offset,
6362 sdp->isp_devparam[tgt].nvrm_period);
6363 sdp->isp_devparam[tgt].goal_offset =
6364 sdp->isp_devparam[tgt].nvrm_offset;
6365 sdp->isp_devparam[tgt].goal_period =
6366 sdp->isp_devparam[tgt].nvrm_period;
6367 sdp->isp_devparam[tgt].goal_flags =
6368 sdp->isp_devparam[tgt].nvrm_flags;
6373 isp_parse_nvram_12160(struct ispsoftc *isp, int bus, u_int8_t *nvram_data)
6375 sdparam *sdp = (sdparam *) isp->isp_param;
6380 sdp->isp_fifo_threshold =
6381 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
6383 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6384 sdp->isp_initiator_id =
6385 ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
6387 sdp->isp_bus_reset_delay =
6388 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6390 sdp->isp_retry_count =
6391 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6393 sdp->isp_retry_delay =
6394 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6396 sdp->isp_async_data_setup =
6397 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6399 sdp->isp_req_ack_active_neg =
6400 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6402 sdp->isp_data_line_active_neg =
6403 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6405 sdp->isp_data_dma_burst_enabl =
6406 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6408 sdp->isp_cmd_dma_burst_enable =
6409 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6411 sdp->isp_selection_timeout =
6412 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6414 sdp->isp_max_queue_depth =
6415 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6417 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6418 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6419 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6420 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6421 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6422 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6423 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6424 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6426 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6427 sdp->isp_devparam[tgt].dev_enable =
6428 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6429 sdp->isp_devparam[tgt].exc_throttle =
6430 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6431 sdp->isp_devparam[tgt].nvrm_offset =
6432 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6433 sdp->isp_devparam[tgt].nvrm_period =
6434 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6435 sdp->isp_devparam[tgt].nvrm_flags = 0;
6436 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6437 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6438 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6439 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6440 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6441 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6442 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6443 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6444 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6445 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6446 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6447 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6448 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6449 sdp->isp_devparam[tgt].actv_flags = 0;
6450 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6451 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6452 sdp->isp_devparam[tgt].nvrm_offset,
6453 sdp->isp_devparam[tgt].nvrm_period);
6454 sdp->isp_devparam[tgt].goal_offset =
6455 sdp->isp_devparam[tgt].nvrm_offset;
6456 sdp->isp_devparam[tgt].goal_period =
6457 sdp->isp_devparam[tgt].nvrm_period;
6458 sdp->isp_devparam[tgt].goal_flags =
6459 sdp->isp_devparam[tgt].nvrm_flags;
6464 isp_parse_nvram_2100(struct ispsoftc *isp, u_int8_t *nvram_data)
6466 fcparam *fcp = (fcparam *) isp->isp_param;
6470 * There is NVRAM storage for both Port and Node entities-
6471 * but the Node entity appears to be unused on all the cards
6472 * I can find. However, we should account for this being set
6473 * at some point in the future.
6475 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
6476 * bits 48..60. In the case of the 2202, it appears that they do
6477 * use bit 48 to distinguish between the two instances on the card.
6478 * The 2204, which I've never seen, *probably* extends this method.
6480 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
6482 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
6483 (u_int32_t) (wwn >> 32), (u_int32_t) (wwn & 0xffffffff));
6484 if ((wwn >> 60) == 0) {
6485 wwn |= (((u_int64_t) 2)<< 60);
6488 fcp->isp_portwwn = wwn;
6489 if (IS_2200(isp) || IS_23XX(isp)) {
6490 wwn = ISP2200_NVRAM_NODE_NAME(nvram_data);
6492 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
6493 (u_int32_t) (wwn >> 32),
6494 (u_int32_t) (wwn & 0xffffffff));
6495 if ((wwn >> 60) == 0) {
6496 wwn |= (((u_int64_t) 2)<< 60);
6500 wwn &= ~((u_int64_t) 0xfff << 48);
6502 fcp->isp_nodewwn = wwn;
6505 * Make sure we have both Node and Port as non-zero values.
6507 if (fcp->isp_nodewwn != 0 && fcp->isp_portwwn == 0) {
6508 fcp->isp_portwwn = fcp->isp_nodewwn;
6509 } else if (fcp->isp_nodewwn == 0 && fcp->isp_portwwn != 0) {
6510 fcp->isp_nodewwn = fcp->isp_portwwn;
6514 * Make the Node and Port values sane if they're NAA == 2.
6515 * This means to clear bits 48..56 for the Node WWN and
6516 * make sure that there's some non-zero value in 48..56
6519 if (fcp->isp_nodewwn && fcp->isp_portwwn) {
6520 if ((fcp->isp_nodewwn & (((u_int64_t) 0xfff) << 48)) != 0 &&
6521 (fcp->isp_nodewwn >> 60) == 2) {
6522 fcp->isp_nodewwn &= ~((u_int64_t) 0xfff << 48);
6524 if ((fcp->isp_portwwn & (((u_int64_t) 0xfff) << 48)) == 0 &&
6525 (fcp->isp_portwwn >> 60) == 2) {
6526 fcp->isp_portwwn |= ((u_int64_t) 1 << 56);
6530 isp_prt(isp, ISP_LOGDEBUG0,
6531 "NVRAM: maxfrmlen %d execthrottle %d fwoptions 0x%x loopid %x",
6532 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data),
6533 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
6534 ISP2100_NVRAM_OPTIONS(nvram_data),
6535 ISP2100_NVRAM_HARDLOOPID(nvram_data));
6538 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
6539 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0)
6540 fcp->isp_maxfrmlen =
6541 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
6542 fcp->isp_retry_delay =
6543 ISP2100_NVRAM_RETRY_DELAY(nvram_data);
6544 fcp->isp_retry_count =
6545 ISP2100_NVRAM_RETRY_COUNT(nvram_data);
6546 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6548 ISP2100_NVRAM_HARDLOOPID(nvram_data);
6549 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0)
6550 fcp->isp_execthrottle =
6551 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
6552 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
6555 #ifdef ISP_FW_CRASH_DUMP
6556 static void isp2200_fw_dump(struct ispsoftc *);
6557 static void isp2300_fw_dump(struct ispsoftc *);
6560 isp2200_fw_dump(struct ispsoftc *isp)
6566 MEMZERO(&mbs, sizeof (mbs));
6567 ptr = FCPARAM(isp)->isp_dump_data;
6569 isp_prt(isp, ISP_LOGERR,
6570 "No place to dump RISC registers and SRAM");
6574 isp_prt(isp, ISP_LOGERR,
6575 "dump area for RISC registers and SRAM already used");
6578 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6579 for (i = 0; i < 100; i++) {
6581 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6585 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6589 for (i = 0; i < 8; i++) {
6590 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6596 for (i = 0; i < 8; i++) {
6597 *ptr++ = ISP_READ(isp, MBOX_BLOCK + (i << 1));
6603 for (i = 0; i < 48; i++) {
6604 *ptr++ = ISP_READ(isp, DMA_BLOCK + 0x20 + (i << 1));
6608 * RISC H/W Registers
6610 ISP_WRITE(isp, BIU2100_CSR, 0);
6611 for (i = 0; i < 16; i++) {
6612 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6618 for (j = 0; j < 8; j++) {
6619 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 8));
6620 for (i = 0; i < 16; i++) {
6622 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6627 * Frame Buffer Hardware Registers
6629 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6630 for (i = 0; i < 16; i++) {
6631 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6635 * Fibre Protocol Module 0 Hardware Registers
6637 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6638 for (i = 0; i < 64; i++) {
6639 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6643 * Fibre Protocol Module 1 Hardware Registers
6645 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6646 for (i = 0; i < 64; i++) {
6647 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6650 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6653 isp_prt(isp, ISP_LOGALL,
6654 "isp_fw_dump: RISC registers dumped successfully");
6655 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6656 for (i = 0; i < 100; i++) {
6658 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6662 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6663 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6666 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6667 for (i = 0; i < 100; i++) {
6669 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6673 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6674 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause After Reset");
6677 ISP_WRITE(isp, RISC_EMB, 0xf2);
6678 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
6679 for (i = 0; i < 100; i++) {
6681 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6686 mbs.param[0] = MBOX_READ_RAM_WORD;
6687 mbs.param[1] = 0x1000;
6688 isp->isp_mbxworkp = (void *) ptr;
6689 isp->isp_mbxwrk0 = 0xefff; /* continuation count */
6690 isp->isp_mbxwrk1 = 0x1001; /* next SRAM address */
6691 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6692 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6693 isp_prt(isp, ISP_LOGWARN,
6694 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6697 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6698 *ptr++ = isp->isp_mboxtmp[2];
6699 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
6700 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6701 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6705 isp2300_fw_dump(struct ispsoftc *isp)
6711 MEMZERO(&mbs, sizeof (mbs));
6712 ptr = FCPARAM(isp)->isp_dump_data;
6714 isp_prt(isp, ISP_LOGERR,
6715 "No place to dump RISC registers and SRAM");
6719 isp_prt(isp, ISP_LOGERR,
6720 "dump area for RISC registers and SRAM already used");
6723 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6724 for (i = 0; i < 100; i++) {
6726 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6730 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6734 for (i = 0; i < 8; i++) {
6735 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6739 * ReqQ-RspQ-Risc2Host Status registers
6741 for (i = 0; i < 8; i++) {
6742 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x10 + (i << 1));
6748 for (i = 0; i < 32; i++) {
6750 ISP_READ(isp, PCI_MBOX_REGS2300_OFF + (i << 1));
6754 * Auto Request Response DMA registers
6756 ISP_WRITE(isp, BIU2100_CSR, 0x40);
6757 for (i = 0; i < 32; i++) {
6758 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6764 ISP_WRITE(isp, BIU2100_CSR, 0x50);
6765 for (i = 0; i < 48; i++) {
6766 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6770 * RISC hardware registers
6772 ISP_WRITE(isp, BIU2100_CSR, 0);
6773 for (i = 0; i < 16; i++) {
6774 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6778 * RISC GP? registers
6780 for (j = 0; j < 8; j++) {
6781 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 9));
6782 for (i = 0; i < 16; i++) {
6784 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6789 * frame buffer hardware registers
6791 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6792 for (i = 0; i < 64; i++) {
6793 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6797 * FPM B0 hardware registers
6799 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6800 for (i = 0; i < 64; i++) {
6801 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6805 * FPM B1 hardware registers
6807 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6808 for (i = 0; i < 64; i++) {
6809 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6812 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6815 isp_prt(isp, ISP_LOGALL,
6816 "isp_fw_dump: RISC registers dumped successfully");
6817 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6818 for (i = 0; i < 100; i++) {
6820 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6824 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6825 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6829 mbs.param[0] = MBOX_READ_RAM_WORD;
6830 mbs.param[1] = 0x800;
6831 isp->isp_mbxworkp = (void *) ptr;
6832 isp->isp_mbxwrk0 = 0xf7ff; /* continuation count */
6833 isp->isp_mbxwrk1 = 0x801; /* next SRAM address */
6834 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6835 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6836 isp_prt(isp, ISP_LOGWARN,
6837 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6840 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6841 *ptr++ = isp->isp_mboxtmp[2];
6844 * We don't have access to mailbox registers 8.. onward
6845 * in our 'common' device model- so we have to set it
6846 * here and hope it stays the same!
6848 ISP_WRITE(isp, PCI_MBOX_REGS2300_OFF + (8 << 1), 0x1);
6850 mbs.param[0] = MBOX_READ_RAM_WORD_EXTENDED;
6852 isp->isp_mbxworkp = (void *) ptr;
6853 isp->isp_mbxwrk0 = 0xffff; /* continuation count */
6854 isp->isp_mbxwrk1 = 0x1; /* next SRAM address */
6855 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6856 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6857 isp_prt(isp, ISP_LOGWARN,
6858 "RAM DUMP FAILED @ WORD %x", 0x10000 + isp->isp_mbxwrk1);
6861 ptr = isp->isp_mbxworkp; /* finish final word */
6862 *ptr++ = mbs.param[2];
6863 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
6864 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6865 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6869 isp_fw_dump(struct ispsoftc *isp)
6872 isp2200_fw_dump(isp);
6873 else if (IS_23XX(isp))
6874 isp2300_fw_dump(isp);