1 /* $FreeBSD: src/sys/dev/isp/isp.c,v 1.41.2.23 2002/10/11 17:34:28 mjacob Exp $ */
3 * Machine and OS Independent (well, as best as possible)
4 * code for the Qlogic ISP SCSI adapters.
6 * Copyright (c) 1997, 1998, 1999, 2000, 2001 by Matthew Jacob
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice immediately at the beginning of the file, without modification,
15 * this list of conditions, and the following disclaimer.
16 * 2. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
34 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
35 * ideas dredged from the Solaris driver.
39 * Include header file appropriate for platform we're building on.
43 #include <dev/ic/isp_netbsd.h>
45 #if defined(__DragonFly__) || defined(__FreeBSD__)
46 #include "isp_freebsd.h"
49 #include <dev/ic/isp_openbsd.h>
52 #include "isp_linux.h"
55 #include "isp_solaris.h"
62 #define MBOX_DELAY_COUNT 1000000 / 100
67 static const char portshift[] =
68 "Target %d Loop ID 0x%x (Port 0x%x) => Loop 0x%x (Port 0x%x)";
69 static const char portdup[] =
70 "Target %d duplicates Target %d- killing off both";
71 static const char retained[] =
72 "Retaining Loop ID 0x%x for Target %d (Port 0x%x)";
73 static const char lretained[] =
74 "Retained login of Target %d (Loop ID 0x%x) Port 0x%x";
75 static const char plogout[] =
76 "Logging out Target %d at Loop ID 0x%x (Port 0x%x)";
77 static const char plogierr[] =
78 "Command Error in PLOGI for Port 0x%x (0x%x)";
79 static const char nopdb[] =
80 "Could not get PDB for Device @ Port 0x%x";
81 static const char pdbmfail1[] =
82 "PDB Loop ID info for Device @ Port 0x%x does not match up (0x%x)";
83 static const char pdbmfail2[] =
84 "PDB Port info for Device @ Port 0x%x does not match up (0x%x)";
85 static const char ldumped[] =
86 "Target %d (Loop ID 0x%x) Port 0x%x dumped after login info mismatch";
87 static const char notresp[] =
88 "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
89 static const char xact1[] =
90 "HBA attempted queued transaction with disconnect not set for %d.%d.%d";
91 static const char xact2[] =
92 "HBA attempted queued transaction to target routine %d on target %d bus %d";
93 static const char xact3[] =
94 "HBA attempted queued cmd for %d.%d.%d when queueing disabled";
95 static const char pskip[] =
96 "SCSI phase skipped for target %d.%d.%d";
97 static const char topology[] =
98 "Loop ID %d, AL_PA 0x%x, Port ID 0x%x, Loop State 0x%x, Topology '%s'";
99 static const char swrej[] =
100 "Fabric Nameserver rejected %s (Reason=0x%x Expl=0x%x) for Port ID 0x%x";
101 static const char finmsg[] =
102 "(%d.%d.%d): FIN dl%d resid %d STS 0x%x SKEY %c XS_ERR=0x%x";
103 static const char sc0[] =
104 "%s CHAN %d FTHRSH %d IID %d RESETD %d RETRYC %d RETRYD %d ASD 0x%x";
105 static const char sc1[] =
106 "%s RAAN 0x%x DLAN 0x%x DDMAB 0x%x CDMAB 0x%x SELTIME %d MQD %d";
107 static const char sc2[] = "%s CHAN %d TGT %d FLAGS 0x%x 0x%x/0x%x";
108 static const char sc3[] = "Generated";
109 static const char sc4[] = "NVRAM";
110 static const char bun[] =
111 "bad underrun for %d.%d (count %d, resid %d, status %s)";
114 * Local function prototypes.
116 static int isp_parse_async(struct ispsoftc *, u_int16_t);
117 static int isp_handle_other_response(struct ispsoftc *, int, isphdr_t *,
120 isp_parse_status(struct ispsoftc *, ispstatusreq_t *, XS_T *);
121 static void isp_fastpost_complete(struct ispsoftc *, u_int16_t);
122 static int isp_mbox_continue(struct ispsoftc *);
123 static void isp_scsi_init(struct ispsoftc *);
124 static void isp_scsi_channel_init(struct ispsoftc *, int);
125 static void isp_fibre_init(struct ispsoftc *);
126 static void isp_mark_getpdb_all(struct ispsoftc *);
127 static int isp_getmap(struct ispsoftc *, fcpos_map_t *);
128 static int isp_getpdb(struct ispsoftc *, int, isp_pdb_t *);
129 static u_int64_t isp_get_portname(struct ispsoftc *, int, int);
130 static int isp_fclink_test(struct ispsoftc *, int);
131 static char *isp2100_fw_statename(int);
132 static int isp_pdb_sync(struct ispsoftc *);
133 static int isp_scan_loop(struct ispsoftc *);
134 static int isp_fabric_mbox_cmd(struct ispsoftc *, mbreg_t *);
135 static int isp_scan_fabric(struct ispsoftc *, int);
136 static void isp_register_fc4_type(struct ispsoftc *);
137 static void isp_fw_state(struct ispsoftc *);
138 static void isp_mboxcmd_qnw(struct ispsoftc *, mbreg_t *, int);
139 static void isp_mboxcmd(struct ispsoftc *, mbreg_t *, int);
141 static void isp_update(struct ispsoftc *);
142 static void isp_update_bus(struct ispsoftc *, int);
143 static void isp_setdfltparm(struct ispsoftc *, int);
144 static int isp_read_nvram(struct ispsoftc *);
145 static void isp_rdnvram_word(struct ispsoftc *, int, u_int16_t *);
146 static void isp_parse_nvram_1020(struct ispsoftc *, u_int8_t *);
147 static void isp_parse_nvram_1080(struct ispsoftc *, int, u_int8_t *);
148 static void isp_parse_nvram_12160(struct ispsoftc *, int, u_int8_t *);
149 static void isp_parse_nvram_2100(struct ispsoftc *, u_int8_t *);
154 * Hit the chip over the head, download new f/w if available and set it running.
156 * Locking done elsewhere.
160 isp_reset(struct ispsoftc *isp)
164 int loops, i, dodnld = 1;
165 char *btype = "????";
167 isp->isp_state = ISP_NILSTATE;
170 * Basic types (SCSI, FibreChannel and PCI or SBus)
171 * have been set in the MD code. We figure out more
172 * here. Possibly more refined types based upon PCI
173 * identification. Chip revision has been gathered.
175 * After we've fired this chip up, zero out the conf1 register
176 * for SCSI adapters and do other settings for the 2100.
180 * Get the current running firmware revision out of the
181 * chip before we hit it over the head (if this is our
182 * first time through). Note that we store this as the
183 * 'ROM' firmware revision- which it may not be. In any
184 * case, we don't really use this yet, but we may in
187 if (isp->isp_touched == 0) {
189 * First see whether or not we're sitting in the ISP PROM.
190 * If we've just been reset, we'll have the string "ISP "
191 * spread through outgoing mailbox registers 1-3. We do
192 * this for PCI cards because otherwise we really don't
193 * know what state the card is in and we could hang if
194 * we try this command otherwise.
196 * For SBus cards, we just do this because they almost
197 * certainly will be running firmware by now.
199 if (ISP_READ(isp, OUTMAILBOX1) != 0x4953 ||
200 ISP_READ(isp, OUTMAILBOX2) != 0x5020 ||
201 ISP_READ(isp, OUTMAILBOX3) != 0x2020) {
203 * Just in case it was paused...
205 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
206 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
207 isp_mboxcmd(isp, &mbs, MBLOGNONE);
208 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
209 isp->isp_romfw_rev[0] = mbs.param[1];
210 isp->isp_romfw_rev[1] = mbs.param[2];
211 isp->isp_romfw_rev[2] = mbs.param[3];
214 isp->isp_touched = 1;
220 * Set up default request/response queue in-pointer/out-pointer
224 isp->isp_rqstinrp = BIU_REQINP;
225 isp->isp_rqstoutrp = BIU_REQOUTP;
226 isp->isp_respinrp = BIU_RSPINP;
227 isp->isp_respoutrp = BIU_RSPOUTP;
229 isp->isp_rqstinrp = INMAILBOX4;
230 isp->isp_rqstoutrp = OUTMAILBOX4;
231 isp->isp_respinrp = OUTMAILBOX5;
232 isp->isp_respoutrp = INMAILBOX5;
236 * Put the board into PAUSE mode (so we can read the SXP registers
237 * or write FPM/FBM registers).
239 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
242 switch (isp->isp_type) {
259 * While we're paused, reset the FPM module and FBM fifos.
261 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
262 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
263 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
264 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
265 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
266 } else if (IS_1240(isp)) {
267 sdparam *sdp = isp->isp_param;
270 sdp->isp_ultramode = 1;
272 sdp->isp_ultramode = 1;
274 * XXX: Should probably do some bus sensing.
276 } else if (IS_ULTRA2(isp)) {
277 static const char m[] = "bus %d is in %s Mode";
279 sdparam *sdp = isp->isp_param;
281 isp->isp_clock = 100;
285 else if (IS_1080(isp))
287 else if (IS_10160(isp))
289 else if (IS_12160(isp))
294 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
296 case ISP1080_LVD_MODE:
297 sdp->isp_lvdmode = 1;
298 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
300 case ISP1080_HVD_MODE:
301 sdp->isp_diffmode = 1;
302 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
304 case ISP1080_SE_MODE:
305 sdp->isp_ultramode = 1;
306 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
309 isp_prt(isp, ISP_LOGERR,
310 "unknown mode on bus %d (0x%x)", 0, l);
314 if (IS_DUALBUS(isp)) {
316 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
317 l &= ISP1080_MODE_MASK;
319 case ISP1080_LVD_MODE:
320 sdp->isp_lvdmode = 1;
321 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
323 case ISP1080_HVD_MODE:
324 sdp->isp_diffmode = 1;
325 isp_prt(isp, ISP_LOGCONFIG,
326 m, 1, "Differential");
328 case ISP1080_SE_MODE:
329 sdp->isp_ultramode = 1;
330 isp_prt(isp, ISP_LOGCONFIG,
331 m, 1, "Single-Ended");
334 isp_prt(isp, ISP_LOGERR,
335 "unknown mode on bus %d (0x%x)", 1, l);
340 sdparam *sdp = isp->isp_param;
341 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
344 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
348 isp->isp_type = ISP_HA_SCSI_1020;
353 * Some 1020A chips are Ultra Capable, but don't
354 * run the clock rate up for that unless told to
355 * do so by the Ultra Capable bits being set.
358 isp->isp_type = ISP_HA_SCSI_1020A;
363 isp->isp_type = ISP_HA_SCSI_1040;
368 isp->isp_type = ISP_HA_SCSI_1040A;
373 isp->isp_type = ISP_HA_SCSI_1040B;
378 isp->isp_type = ISP_HA_SCSI_1040C;
383 * Now, while we're at it, gather info about ultra
384 * and/or differential mode.
386 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
387 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
388 sdp->isp_diffmode = 1;
390 sdp->isp_diffmode = 0;
392 i = ISP_READ(isp, RISC_PSR);
393 if (isp->isp_bustype == ISP_BT_SBUS) {
394 i &= RISC_PSR_SBUS_ULTRA;
396 i &= RISC_PSR_PCI_ULTRA;
399 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
400 sdp->isp_ultramode = 1;
402 * If we're in Ultra Mode, we have to be 60Mhz clock-
403 * even for the SBus version.
407 sdp->isp_ultramode = 0;
409 * Clock is known. Gronk.
414 * Machine dependent clock (if set) overrides
415 * our generic determinations.
417 if (isp->isp_mdvec->dv_clock) {
418 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
419 isp->isp_clock = isp->isp_mdvec->dv_clock;
426 * Clear instrumentation
428 isp->isp_intcnt = isp->isp_intbogus = 0;
431 * Do MD specific pre initialization
438 * Hit the chip over the head with hammer,
439 * and give the ISP a chance to recover.
443 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
450 * Clear data && control DMA engines.
452 ISP_WRITE(isp, CDMA_CONTROL,
453 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
454 ISP_WRITE(isp, DDMA_CONTROL,
455 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
459 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
466 * Clear data && control DMA engines.
468 ISP_WRITE(isp, CDMA2100_CONTROL,
469 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
470 ISP_WRITE(isp, TDMA2100_CONTROL,
471 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
472 ISP_WRITE(isp, RDMA2100_CONTROL,
473 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
477 * Wait for ISP to be ready to go...
479 loops = MBOX_DELAY_COUNT;
482 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET))
485 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
490 ISP_DUMPREGS(isp, "chip reset timed out");
496 * After we've fired this chip up, zero out the conf1 register
497 * for SCSI adapters and other settings for the 2100.
501 ISP_WRITE(isp, BIU_CONF1, 0);
503 ISP_WRITE(isp, BIU2100_CSR, 0);
507 * Reset RISC Processor
509 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
511 /* Clear semaphore register (just to be sure) */
512 ISP_WRITE(isp, BIU_SEMA, 0);
515 * Establish some initial burst rate stuff.
516 * (only for the 1XX0 boards). This really should
517 * be done later after fetching from NVRAM.
520 u_int16_t tmp = isp->isp_mdvec->dv_conf1;
522 * Busted FIFO. Turn off all but burst enables.
524 if (isp->isp_type == ISP_HA_SCSI_1040A) {
525 tmp &= BIU_BURST_ENABLE;
527 ISP_SETBITS(isp, BIU_CONF1, tmp);
528 if (tmp & BIU_BURST_ENABLE) {
529 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
530 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
533 if (((sdparam *) isp->isp_param)->isp_ultramode) {
534 while (ISP_READ(isp, RISC_MTR) != 0x1313) {
535 ISP_WRITE(isp, RISC_MTR, 0x1313);
536 ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
539 ISP_WRITE(isp, RISC_MTR, 0x1212);
542 * PTI specific register
544 ISP_WRITE(isp, RISC_EMB, DUAL_BANK)
546 ISP_WRITE(isp, RISC_MTR, 0x1212);
549 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
550 if (IS_2200(isp) || IS_23XX(isp)) {
551 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
555 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE); /* release paused processor */
558 * Do MD specific post initialization
563 * Wait for everything to finish firing up.
565 * Avoid doing this on the 2312 because you can generate a PCI
566 * parity error (chip breakage).
571 loops = MBOX_DELAY_COUNT;
572 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
575 isp_prt(isp, ISP_LOGERR,
576 "MBOX_BUSY never cleared on reset");
583 * Up until this point we've done everything by just reading or
584 * setting registers. From this point on we rely on at least *some*
585 * kind of firmware running in the card.
589 * Do some sanity checking.
591 mbs.param[0] = MBOX_NO_OP;
592 isp_mboxcmd(isp, &mbs, MBLOGALL);
593 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
598 mbs.param[0] = MBOX_MAILBOX_REG_TEST;
599 mbs.param[1] = 0xdead;
600 mbs.param[2] = 0xbeef;
601 mbs.param[3] = 0xffff;
602 mbs.param[4] = 0x1111;
603 mbs.param[5] = 0xa5a5;
604 isp_mboxcmd(isp, &mbs, MBLOGALL);
605 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
608 if (mbs.param[1] != 0xdead || mbs.param[2] != 0xbeef ||
609 mbs.param[3] != 0xffff || mbs.param[4] != 0x1111 ||
610 mbs.param[5] != 0xa5a5) {
611 isp_prt(isp, ISP_LOGERR,
612 "Register Test Failed (0x%x 0x%x 0x%x 0x%x 0x%x)",
613 mbs.param[1], mbs.param[2], mbs.param[3],
614 mbs.param[4], mbs.param[5]);
621 * Download new Firmware, unless requested not to do so.
622 * This is made slightly trickier in some cases where the
623 * firmware of the ROM revision is newer than the revision
624 * compiled into the driver. So, where we used to compare
625 * versions of our f/w and the ROM f/w, now we just see
626 * whether we have f/w at all and whether a config flag
627 * has disabled our download.
629 if ((isp->isp_mdvec->dv_ispfw == NULL) ||
630 (isp->isp_confopts & ISP_CFG_NORELOAD)) {
635 code_org = ISP_CODE_ORG_2300;
637 code_org = ISP_CODE_ORG;
640 isp->isp_mbxworkp = (void *) &isp->isp_mdvec->dv_ispfw[1];
641 isp->isp_mbxwrk0 = isp->isp_mdvec->dv_ispfw[3] - 1;
642 isp->isp_mbxwrk1 = code_org + 1;
643 mbs.param[0] = MBOX_WRITE_RAM_WORD;
644 mbs.param[1] = code_org;
645 mbs.param[2] = isp->isp_mdvec->dv_ispfw[0];
646 isp_mboxcmd(isp, &mbs, MBLOGNONE);
647 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
648 isp_prt(isp, ISP_LOGERR,
649 "F/W download failed at word %d",
650 isp->isp_mbxwrk1 - code_org);
655 * Verify that it downloaded correctly.
657 mbs.param[0] = MBOX_VERIFY_CHECKSUM;
658 mbs.param[1] = code_org;
659 isp_mboxcmd(isp, &mbs, MBLOGNONE);
660 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
661 isp_prt(isp, ISP_LOGERR, "Ram Checksum Failure");
664 isp->isp_loaded_fw = 1;
666 isp->isp_loaded_fw = 0;
667 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
671 * Now start it rolling.
673 * If we didn't actually download f/w,
674 * we still need to (re)start it.
678 mbs.param[0] = MBOX_EXEC_FIRMWARE;
679 mbs.param[1] = code_org;
680 isp_mboxcmd(isp, &mbs, MBLOGNONE);
682 * Give it a chance to start.
688 * Set CLOCK RATE, but only if asked to.
690 if (isp->isp_clock) {
691 mbs.param[0] = MBOX_SET_CLOCK_RATE;
692 mbs.param[1] = isp->isp_clock;
693 isp_mboxcmd(isp, &mbs, MBLOGALL);
694 /* we will try not to care if this fails */
698 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
699 isp_mboxcmd(isp, &mbs, MBLOGALL);
700 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
705 * The SBus firmware that we are using apparently does not return
706 * major, minor, micro revisions in the mailbox registers, which
707 * is really, really, annoying.
709 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
711 #ifdef ISP_TARGET_MODE
712 isp->isp_fwrev[0] = 7;
713 isp->isp_fwrev[1] = 55;
715 isp->isp_fwrev[0] = 1;
716 isp->isp_fwrev[1] = 37;
718 isp->isp_fwrev[2] = 0;
721 isp->isp_fwrev[0] = mbs.param[1];
722 isp->isp_fwrev[1] = mbs.param[2];
723 isp->isp_fwrev[2] = mbs.param[3];
725 isp_prt(isp, ISP_LOGCONFIG,
726 "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
727 btype, isp->isp_revision, dodnld? "loaded" : "resident",
728 isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
732 * We do not believe firmware attributes for 2100 code less
733 * than 1.17.0, unless it's the firmware we specifically
736 * Note that all 22XX and 23XX f/w is greater than 1.X.0.
738 if (!(ISP_FW_NEWER_THAN(isp, 1, 17, 0))) {
739 #ifdef USE_SMALLER_2100_FIRMWARE
740 FCPARAM(isp)->isp_fwattr = ISP_FW_ATTR_SCCLUN;
742 FCPARAM(isp)->isp_fwattr = 0;
745 FCPARAM(isp)->isp_fwattr = mbs.param[6];
746 isp_prt(isp, ISP_LOGDEBUG0,
747 "Firmware Attributes = 0x%x", mbs.param[6]);
749 if (ISP_READ(isp, BIU2100_CSR) & BIU2100_PCI64) {
750 isp_prt(isp, ISP_LOGCONFIG,
751 "Installed in 64-Bit PCI slot");
755 if (isp->isp_romfw_rev[0] || isp->isp_romfw_rev[1] ||
756 isp->isp_romfw_rev[2]) {
757 isp_prt(isp, ISP_LOGCONFIG, "Last F/W revision was %d.%d.%d",
758 isp->isp_romfw_rev[0], isp->isp_romfw_rev[1],
759 isp->isp_romfw_rev[2]);
762 mbs.param[0] = MBOX_GET_FIRMWARE_STATUS;
763 isp_mboxcmd(isp, &mbs, MBLOGALL);
764 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
767 isp->isp_maxcmds = mbs.param[2];
768 isp_prt(isp, ISP_LOGINFO,
769 "%d max I/O commands supported", mbs.param[2]);
773 * Set up DMA for the request and result mailboxes.
775 if (ISP_MBOXDMASETUP(isp) != 0) {
776 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
779 isp->isp_state = ISP_RESETSTATE;
782 * Okay- now that we have new firmware running, we now (re)set our
783 * notion of how many luns we support. This is somewhat tricky because
784 * if we haven't loaded firmware, we sometimes do not have an easy way
785 * of knowing how many luns we support.
787 * Expanded lun firmware gives you 32 luns for SCSI cards and
788 * 16384 luns for Fibre Channel cards.
790 * It turns out that even for QLogic 2100s with ROM 1.10 and above
791 * we do get a firmware attributes word returned in mailbox register 6.
793 * Because the lun is in a a different position in the Request Queue
794 * Entry structure for Fibre Channel with expanded lun firmware, we
795 * can only support one lun (lun zero) when we don't know what kind
796 * of firmware we're running.
798 * Note that we only do this once (the first time thru isp_reset)
799 * because we may be called again after firmware has been loaded once
804 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
805 isp->isp_maxluns = 32;
807 isp->isp_maxluns = 8;
810 isp->isp_maxluns = 8;
813 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
814 isp->isp_maxluns = 16384;
816 isp->isp_maxluns = 16;
822 * Initialize Parameters of Hardware to a known state.
824 * Locks are held before coming here.
828 isp_init(struct ispsoftc *isp)
831 * Must do this first to get defaults established.
833 isp_setdfltparm(isp, 0);
834 if (IS_DUALBUS(isp)) {
835 isp_setdfltparm(isp, 1);
845 isp_scsi_init(struct ispsoftc *isp)
847 sdparam *sdp_chan0, *sdp_chan1;
850 sdp_chan0 = isp->isp_param;
851 sdp_chan1 = sdp_chan0;
852 if (IS_DUALBUS(isp)) {
857 * If we have no role (neither target nor initiator), return.
859 if (isp->isp_role == ISP_ROLE_NONE) {
863 /* First do overall per-card settings. */
866 * If we have fast memory timing enabled, turn it on.
868 if (sdp_chan0->isp_fast_mttr) {
869 ISP_WRITE(isp, RISC_MTR, 0x1313);
873 * Set Retry Delay and Count.
874 * You set both channels at the same time.
876 mbs.param[0] = MBOX_SET_RETRY_COUNT;
877 mbs.param[1] = sdp_chan0->isp_retry_count;
878 mbs.param[2] = sdp_chan0->isp_retry_delay;
879 mbs.param[6] = sdp_chan1->isp_retry_count;
880 mbs.param[7] = sdp_chan1->isp_retry_delay;
882 isp_mboxcmd(isp, &mbs, MBLOGALL);
883 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
888 * Set ASYNC DATA SETUP time. This is very important.
890 mbs.param[0] = MBOX_SET_ASYNC_DATA_SETUP_TIME;
891 mbs.param[1] = sdp_chan0->isp_async_data_setup;
892 mbs.param[2] = sdp_chan1->isp_async_data_setup;
893 isp_mboxcmd(isp, &mbs, MBLOGALL);
894 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
899 * Set ACTIVE Negation State.
901 mbs.param[0] = MBOX_SET_ACT_NEG_STATE;
903 (sdp_chan0->isp_req_ack_active_neg << 4) |
904 (sdp_chan0->isp_data_line_active_neg << 5);
906 (sdp_chan1->isp_req_ack_active_neg << 4) |
907 (sdp_chan1->isp_data_line_active_neg << 5);
909 isp_mboxcmd(isp, &mbs, MBLOGNONE);
910 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
911 isp_prt(isp, ISP_LOGERR,
912 "failed to set active negation state (%d,%d), (%d,%d)",
913 sdp_chan0->isp_req_ack_active_neg,
914 sdp_chan0->isp_data_line_active_neg,
915 sdp_chan1->isp_req_ack_active_neg,
916 sdp_chan1->isp_data_line_active_neg);
923 * Set the Tag Aging limit
925 mbs.param[0] = MBOX_SET_TAG_AGE_LIMIT;
926 mbs.param[1] = sdp_chan0->isp_tag_aging;
927 mbs.param[2] = sdp_chan1->isp_tag_aging;
928 isp_mboxcmd(isp, &mbs, MBLOGALL);
929 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
930 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
931 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
936 * Set selection timeout.
938 mbs.param[0] = MBOX_SET_SELECT_TIMEOUT;
939 mbs.param[1] = sdp_chan0->isp_selection_timeout;
940 mbs.param[2] = sdp_chan1->isp_selection_timeout;
941 isp_mboxcmd(isp, &mbs, MBLOGALL);
942 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
946 /* now do per-channel settings */
947 isp_scsi_channel_init(isp, 0);
949 isp_scsi_channel_init(isp, 1);
952 * Now enable request/response queues
955 if (IS_ULTRA2(isp) || IS_1240(isp)) {
956 mbs.param[0] = MBOX_INIT_RES_QUEUE_A64;
957 mbs.param[1] = RESULT_QUEUE_LEN(isp);
958 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
959 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
961 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
962 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
963 isp_mboxcmd(isp, &mbs, MBLOGALL);
964 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
967 isp->isp_residx = mbs.param[5];
969 mbs.param[0] = MBOX_INIT_REQ_QUEUE_A64;
970 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
971 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
972 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
974 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
975 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
976 isp_mboxcmd(isp, &mbs, MBLOGALL);
977 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
980 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
982 mbs.param[0] = MBOX_INIT_RES_QUEUE;
983 mbs.param[1] = RESULT_QUEUE_LEN(isp);
984 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
985 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
987 isp_mboxcmd(isp, &mbs, MBLOGALL);
988 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
991 isp->isp_residx = mbs.param[5];
993 mbs.param[0] = MBOX_INIT_REQ_QUEUE;
994 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
995 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
996 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
998 isp_mboxcmd(isp, &mbs, MBLOGALL);
999 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1002 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1006 * Turn on Fast Posting, LVD transitions
1008 * Ultra2 F/W always has had fast posting (and LVD transitions)
1010 * Ultra and older (i.e., SBus) cards may not. It's just safer
1011 * to assume not for them.
1014 mbs.param[0] = MBOX_SET_FW_FEATURES;
1017 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1019 if (IS_ULTRA2(isp) || IS_1240(isp))
1020 mbs.param[1] |= FW_FEATURE_RIO_16BIT;
1022 #ifndef ISP_NO_FASTPOST
1023 if (IS_ULTRA2(isp) || IS_1240(isp))
1024 mbs.param[1] |= FW_FEATURE_FAST_POST;
1027 if (mbs.param[1] != 0) {
1028 u_int16_t sfeat = mbs.param[1];
1029 isp_mboxcmd(isp, &mbs, MBLOGALL);
1030 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1031 isp_prt(isp, ISP_LOGINFO,
1032 "Enabled FW features (0x%x)", sfeat);
1037 * Let the outer layers decide whether to issue a SCSI bus reset.
1039 isp->isp_state = ISP_INITSTATE;
1043 isp_scsi_channel_init(struct ispsoftc *isp, int channel)
1049 sdp = isp->isp_param;
1053 * Set (possibly new) Initiator ID.
1055 mbs.param[0] = MBOX_SET_INIT_SCSI_ID;
1056 mbs.param[1] = (channel << 7) | sdp->isp_initiator_id;
1057 isp_mboxcmd(isp, &mbs, MBLOGALL);
1058 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1061 isp_prt(isp, ISP_LOGINFO, "Initiator ID is %d on Channel %d",
1062 sdp->isp_initiator_id, channel);
1066 * Set current per-target parameters to an initial safe minimum.
1068 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1072 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1075 #ifndef ISP_TARGET_MODE
1076 sdf = sdp->isp_devparam[tgt].goal_flags;
1077 sdf &= DPARM_SAFE_DFLT;
1079 * It is not quite clear when this changed over so that
1080 * we could force narrow and async for 1000/1020 cards,
1081 * but assume that this is only the case for loaded
1084 if (isp->isp_loaded_fw) {
1085 sdf |= DPARM_NARROW | DPARM_ASYNC;
1089 * The !$*!)$!$)* f/w uses the same index into some
1090 * internal table to decide how to respond to negotiations,
1091 * so if we've said "let's be safe" for ID X, and ID X
1092 * selects *us*, the negotiations will back to 'safe'
1093 * (as in narrow/async). What the f/w *should* do is
1094 * use the initiator id settings to decide how to respond.
1096 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1098 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1099 mbs.param[1] = (channel << 15) | (tgt << 8);
1101 if ((sdf & DPARM_SYNC) == 0) {
1105 (sdp->isp_devparam[tgt].goal_offset << 8) |
1106 (sdp->isp_devparam[tgt].goal_period);
1108 isp_prt(isp, ISP_LOGDEBUG0,
1109 "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1110 channel, tgt, mbs.param[2], mbs.param[3] >> 8,
1111 mbs.param[3] & 0xff);
1112 isp_mboxcmd(isp, &mbs, MBLOGNONE);
1113 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1114 sdf = DPARM_SAFE_DFLT;
1115 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1116 mbs.param[1] = (tgt << 8) | (channel << 15);
1119 isp_mboxcmd(isp, &mbs, MBLOGALL);
1120 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1126 * We don't update any information directly from the f/w
1127 * because we need to run at least one command to cause a
1128 * new state to be latched up. So, we just assume that we
1129 * converge to the values we just had set.
1131 * Ensure that we don't believe tagged queuing is enabled yet.
1132 * It turns out that sometimes the ISP just ignores our
1133 * attempts to set parameters for devices that it hasn't
1136 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1137 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1138 mbs.param[0] = MBOX_SET_DEV_QUEUE_PARAMS;
1139 mbs.param[1] = (channel << 15) | (tgt << 8) | lun;
1140 mbs.param[2] = sdp->isp_max_queue_depth;
1141 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1142 isp_mboxcmd(isp, &mbs, MBLOGALL);
1143 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1148 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1149 if (sdp->isp_devparam[tgt].dev_refresh) {
1150 isp->isp_sendmarker |= (1 << channel);
1151 isp->isp_update |= (1 << channel);
1158 * Fibre Channel specific initialization.
1160 * Locks are held before coming here.
1163 isp_fibre_init(struct ispsoftc *isp)
1166 isp_icb_t local, *icbp = &local;
1169 u_int64_t nwwn, pwwn;
1171 fcp = isp->isp_param;
1174 * Do this *before* initializing the firmware.
1176 isp_mark_getpdb_all(isp);
1177 fcp->isp_fwstate = FW_CONFIG_WAIT;
1178 fcp->isp_loopstate = LOOP_NIL;
1181 * If we have no role (neither target nor initiator), return.
1183 if (isp->isp_role == ISP_ROLE_NONE) {
1187 loopid = fcp->isp_loopid;
1188 MEMZERO(icbp, sizeof (*icbp));
1189 icbp->icb_version = ICB_VERSION1;
1192 * Firmware Options are either retrieved from NVRAM or
1193 * are patched elsewhere. We check them for sanity here
1194 * and make changes based on board revision, but otherwise
1195 * let others decide policy.
1199 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1201 if ((isp->isp_type == ISP_HA_FC_2100) && isp->isp_revision < 5) {
1202 fcp->isp_fwoptions &= ~ICBOPT_FAIRNESS;
1206 * We have to use FULL LOGIN even though it resets the loop too much
1207 * because otherwise port database entries don't get updated after
1208 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1210 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1211 fcp->isp_fwoptions |= ICBOPT_FULL_LOGIN;
1215 * Insist on Port Database Update Async notifications
1217 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
1220 * Make sure that target role reflects into fwoptions.
1222 if (isp->isp_role & ISP_ROLE_TARGET) {
1223 fcp->isp_fwoptions |= ICBOPT_TGT_ENABLE;
1225 fcp->isp_fwoptions &= ~ICBOPT_TGT_ENABLE;
1229 * Propagate all of this into the ICB structure.
1231 icbp->icb_fwoptions = fcp->isp_fwoptions;
1232 icbp->icb_maxfrmlen = fcp->isp_maxfrmlen;
1233 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN ||
1234 icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1235 isp_prt(isp, ISP_LOGERR,
1236 "bad frame length (%d) from NVRAM- using %d",
1237 fcp->isp_maxfrmlen, ICB_DFLT_FRMLEN);
1238 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1240 icbp->icb_maxalloc = fcp->isp_maxalloc;
1241 if (icbp->icb_maxalloc < 1) {
1242 isp_prt(isp, ISP_LOGERR,
1243 "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1244 icbp->icb_maxalloc = 16;
1246 icbp->icb_execthrottle = fcp->isp_execthrottle;
1247 if (icbp->icb_execthrottle < 1) {
1248 isp_prt(isp, ISP_LOGERR,
1249 "bad execution throttle of %d- using 16",
1250 fcp->isp_execthrottle);
1251 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1253 icbp->icb_retry_delay = fcp->isp_retry_delay;
1254 icbp->icb_retry_count = fcp->isp_retry_count;
1255 icbp->icb_hardaddr = loopid;
1257 * Right now we just set extended options to prefer point-to-point
1258 * over loop based upon some soft config options.
1260 * NB: for the 2300, ICBOPT_EXTENDED is required.
1262 if (IS_2200(isp) || IS_23XX(isp)) {
1263 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1265 * Prefer or force Point-To-Point instead Loop?
1267 switch(isp->isp_confopts & ISP_CFG_PORT_PREF) {
1269 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1271 case ISP_CFG_NPORT_ONLY:
1272 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1274 case ISP_CFG_LPORT_ONLY:
1275 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1278 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1283 * QLogic recommends that FAST Posting be turned
1284 * off for 23XX cards and instead allow the HBA
1285 * to write response queue entries and interrupt
1286 * after a delay (ZIO).
1288 * If we set ZIO, it will disable fast posting,
1289 * so we don't need to clear it in fwoptions.
1291 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1293 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1294 icbp->icb_zfwoptions |= ICBZOPT_RATE_ONEGB;
1295 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1296 icbp->icb_zfwoptions |= ICBZOPT_RATE_TWOGB;
1298 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1303 #ifndef ISP_NO_RIO_FC
1305 * RIO seems to be enabled in 2100s for fw >= 1.17.0.
1307 * I've had some questionable problems with RIO on 2200.
1308 * More specifically, on a 2204 I had problems with RIO
1309 * on a Linux system where I was dropping commands right
1310 * and left. It's not clear to me what the actual problem
1313 * 23XX Cards do not support RIO. Instead they support ZIO.
1316 if (!IS_23XX(isp) && ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1317 icbp->icb_xfwoptions |= ICBXOPT_RIO_16BIT;
1318 icbp->icb_racctimer = 4;
1319 icbp->icb_idelaytimer = 8;
1325 * For 22XX > 2.1.26 && 23XX, set someoptions.
1326 * XXX: Probably okay for newer 2100 f/w too.
1328 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1330 * Turn on LIP F8 async event (1)
1331 * Turn on generate AE 8013 on all LIP Resets (2)
1332 * Disable LIP F7 switching (8)
1334 mbs.param[0] = MBOX_SET_FIRMWARE_OPTIONS;
1338 isp_mboxcmd(isp, &mbs, MBLOGALL);
1340 icbp->icb_logintime = 30; /* 30 second login timeout */
1343 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
1344 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
1345 ISP_WRITE(isp, isp->isp_respinrp, 0);
1346 ISP_WRITE(isp, isp->isp_respoutrp, 0);
1349 nwwn = ISP_NODEWWN(isp);
1350 pwwn = ISP_PORTWWN(isp);
1352 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1353 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, nwwn);
1354 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, pwwn);
1355 isp_prt(isp, ISP_LOGDEBUG1,
1356 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1357 ((u_int32_t) (nwwn >> 32)),
1358 ((u_int32_t) (nwwn & 0xffffffff)),
1359 ((u_int32_t) (pwwn >> 32)),
1360 ((u_int32_t) (pwwn & 0xffffffff)));
1362 isp_prt(isp, ISP_LOGDEBUG1, "Not using any WWNs");
1363 icbp->icb_fwoptions &= ~(ICBOPT_BOTH_WWNS|ICBOPT_FULL_LOGIN);
1365 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1366 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1367 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1368 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1369 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1370 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1371 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1372 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1373 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1374 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1375 isp_prt(isp, ISP_LOGDEBUG0,
1376 "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1377 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1379 FC_SCRATCH_ACQUIRE(isp);
1380 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1385 mbs.param[0] = MBOX_INIT_FIRMWARE;
1387 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1388 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1391 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1392 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1393 isp_mboxcmd(isp, &mbs, MBLOGALL);
1394 FC_SCRATCH_RELEASE(isp);
1395 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1398 isp->isp_reqidx = isp->isp_reqodx = 0;
1399 isp->isp_residx = 0;
1400 isp->isp_sendmarker = 1;
1403 * Whatever happens, we're now committed to being here.
1405 isp->isp_state = ISP_INITSTATE;
1409 * Fibre Channel Support- get the port database for the id.
1411 * Locks are held before coming here. Return 0 if success,
1416 isp_getmap(struct ispsoftc *isp, fcpos_map_t *map)
1418 fcparam *fcp = (fcparam *) isp->isp_param;
1421 mbs.param[0] = MBOX_GET_FC_AL_POSITION_MAP;
1423 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1424 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1426 * Unneeded. For the 2100, except for initializing f/w, registers
1427 * 4/5 have to not be written to.
1434 FC_SCRATCH_ACQUIRE(isp);
1435 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1436 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1437 MEMCPY(map, fcp->isp_scratch, sizeof (fcpos_map_t));
1438 map->fwmap = mbs.param[1] != 0;
1439 FC_SCRATCH_RELEASE(isp);
1442 FC_SCRATCH_RELEASE(isp);
1447 isp_mark_getpdb_all(struct ispsoftc *isp)
1449 fcparam *fcp = (fcparam *) isp->isp_param;
1451 for (i = 0; i < MAX_FC_TARG; i++) {
1452 fcp->portdb[i].valid = fcp->portdb[i].fabric_dev = 0;
1457 isp_getpdb(struct ispsoftc *isp, int id, isp_pdb_t *pdbp)
1459 fcparam *fcp = (fcparam *) isp->isp_param;
1462 mbs.param[0] = MBOX_GET_PORT_DB;
1463 mbs.param[1] = id << 8;
1464 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1465 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1467 * Unneeded. For the 2100, except for initializing f/w, registers
1468 * 4/5 have to not be written to.
1473 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1474 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1475 FC_SCRATCH_ACQUIRE(isp);
1476 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1477 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1478 isp_get_pdb(isp, (isp_pdb_t *)fcp->isp_scratch, pdbp);
1479 FC_SCRATCH_RELEASE(isp);
1482 FC_SCRATCH_RELEASE(isp);
1487 isp_get_portname(struct ispsoftc *isp, int loopid, int nodename)
1492 mbs.param[0] = MBOX_GET_PORT_NAME;
1493 mbs.param[1] = loopid << 8;
1496 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1497 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1499 (((u_int64_t)(mbs.param[2] & 0xff)) << 56) |
1500 (((u_int64_t)(mbs.param[2] >> 8)) << 48) |
1501 (((u_int64_t)(mbs.param[3] & 0xff)) << 40) |
1502 (((u_int64_t)(mbs.param[3] >> 8)) << 32) |
1503 (((u_int64_t)(mbs.param[6] & 0xff)) << 24) |
1504 (((u_int64_t)(mbs.param[6] >> 8)) << 16) |
1505 (((u_int64_t)(mbs.param[7] & 0xff)) << 8) |
1506 (((u_int64_t)(mbs.param[7] >> 8)));
1512 * Make sure we have good FC link and know our Loop ID.
1516 isp_fclink_test(struct ispsoftc *isp, int usdelay)
1518 static char *toponames[] = {
1523 "F Port (no FLOGI_ACC response)"
1526 int count, check_for_fabric;
1532 fcp = isp->isp_param;
1535 * XXX: Here is where we would start a 'loop dead' timeout
1539 * Wait up to N microseconds for F/W to go to a ready state.
1541 lwfs = FW_CONFIG_WAIT;
1543 while (count < usdelay) {
1546 NANOTIME_T hra, hrb;
1550 if (lwfs != fcp->isp_fwstate) {
1551 isp_prt(isp, ISP_LOGINFO, "Firmware State <%s->%s>",
1552 isp2100_fw_statename((int)lwfs),
1553 isp2100_fw_statename((int)fcp->isp_fwstate));
1554 lwfs = fcp->isp_fwstate;
1556 if (fcp->isp_fwstate == FW_READY) {
1562 * Get the elapsed time in nanoseconds.
1563 * Always guaranteed to be non-zero.
1565 enano = NANOTIME_SUB(&hrb, &hra);
1567 isp_prt(isp, ISP_LOGDEBUG1,
1568 "usec%d: 0x%lx->0x%lx enano 0x%x%08x",
1569 count, (long) GET_NANOSEC(&hra), (long) GET_NANOSEC(&hrb),
1570 (u_int32_t)(enano >> 32), (u_int32_t)(enano & 0xffffffff));
1573 * If the elapsed time is less than 1 millisecond,
1574 * delay a period of time up to that millisecond of
1577 * This peculiar code is an attempt to try and avoid
1578 * invoking u_int64_t math support functions for some
1579 * platforms where linkage is a problem.
1581 if (enano < (1000 * 1000)) {
1583 enano = (1000 * 1000) - enano;
1584 while (enano > (u_int64_t) 4000000000U) {
1585 USEC_SLEEP(isp, 4000000);
1586 enano -= (u_int64_t) 4000000000U;
1590 USEC_SLEEP(isp, wrk);
1592 while (enano > (u_int64_t) 4000000000U) {
1594 enano -= (u_int64_t) 4000000000U;
1597 count += (wrk / 1000);
1602 * If we haven't gone to 'ready' state, return.
1604 if (fcp->isp_fwstate != FW_READY) {
1609 * Get our Loop ID (if possible). We really need to have it.
1611 mbs.param[0] = MBOX_GET_LOOP_ID;
1612 isp_mboxcmd(isp, &mbs, MBLOGALL);
1613 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1616 fcp->isp_loopid = mbs.param[1];
1617 if (IS_2200(isp) || IS_23XX(isp)) {
1618 int topo = (int) mbs.param[6];
1619 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB)
1620 topo = TOPO_PTP_STUB;
1621 fcp->isp_topo = topo;
1623 fcp->isp_topo = TOPO_NL_PORT;
1625 fcp->isp_portid = fcp->isp_alpa = mbs.param[2] & 0xff;
1628 * Check to see if we're on a fabric by trying to see if we
1629 * can talk to the fabric name server. This can be a bit
1630 * tricky because if we're a 2100, we should check always
1631 * (in case we're connected to an server doing aliasing).
1633 fcp->isp_onfabric = 0;
1637 * Don't bother with fabric if we are using really old
1638 * 2100 firmware. It's just not worth it.
1640 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37)) {
1641 check_for_fabric = 1;
1643 check_for_fabric = 0;
1645 } else if (fcp->isp_topo == TOPO_FL_PORT ||
1646 fcp->isp_topo == TOPO_F_PORT) {
1647 check_for_fabric = 1;
1649 check_for_fabric = 0;
1651 if (check_for_fabric && isp_getpdb(isp, FL_PORT_ID, &pdb) == 0) {
1652 int loopid = FL_PORT_ID;
1654 fcp->isp_topo = TOPO_FL_PORT;
1657 if (BITS2WORD(pdb.pdb_portid_bits) == 0) {
1661 fcp->isp_topo = TOPO_NL_PORT;
1664 fcp->isp_portid = mbs.param[2] | ((int) mbs.param[3] << 16);
1667 * Save the Fabric controller's port database entry.
1669 lp = &fcp->portdb[loopid];
1671 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1672 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1673 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1674 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1675 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1676 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1677 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1678 (((u_int64_t)pdb.pdb_nodename[7]));
1680 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1681 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1682 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1683 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1684 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1685 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1686 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1687 (((u_int64_t)pdb.pdb_portname[7]));
1689 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
1690 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
1691 lp->loopid = pdb.pdb_loopid;
1692 lp->loggedin = lp->valid = 1;
1693 fcp->isp_onfabric = 1;
1694 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1695 isp_register_fc4_type(isp);
1698 fcp->isp_onfabric = 0;
1699 fcp->portdb[FL_PORT_ID].valid = 0;
1702 fcp->isp_gbspeed = 1;
1704 mbs.param[0] = MBOX_GET_SET_DATA_RATE;
1705 mbs.param[1] = MBGSD_GET_RATE;
1706 /* mbs.param[2] undefined if we're just getting rate */
1707 isp_mboxcmd(isp, &mbs, MBLOGALL);
1708 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1709 if (mbs.param[1] == MBGSD_TWOGB) {
1710 isp_prt(isp, ISP_LOGINFO, "2Gb link speed/s");
1711 fcp->isp_gbspeed = 2;
1716 isp_prt(isp, ISP_LOGCONFIG, topology, fcp->isp_loopid, fcp->isp_alpa,
1717 fcp->isp_portid, fcp->isp_loopstate, toponames[fcp->isp_topo]);
1720 * Announce ourselves, too. This involves synthesizing an entry.
1722 if (fcp->isp_iid_set == 0) {
1723 fcp->isp_iid_set = 1;
1724 fcp->isp_iid = fcp->isp_loopid;
1725 lp = &fcp->portdb[fcp->isp_iid];
1727 lp = &fcp->portdb[fcp->isp_iid];
1728 if (fcp->isp_portid != lp->portid ||
1729 fcp->isp_loopid != lp->loopid ||
1730 fcp->isp_nodewwn != ISP_NODEWWN(isp) ||
1731 fcp->isp_portwwn != ISP_PORTWWN(isp)) {
1733 count = fcp->isp_iid;
1734 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1737 lp->loopid = fcp->isp_loopid;
1738 lp->portid = fcp->isp_portid;
1739 lp->node_wwn = ISP_NODEWWN(isp);
1740 lp->port_wwn = ISP_PORTWWN(isp);
1741 switch (isp->isp_role) {
1745 case ISP_ROLE_TARGET:
1746 lp->roles = SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT;
1748 case ISP_ROLE_INITIATOR:
1749 lp->roles = SVC3_INI_ROLE >> SVC3_ROLE_SHIFT;
1752 lp->roles = (SVC3_INI_ROLE|SVC3_TGT_ROLE) >> SVC3_ROLE_SHIFT;
1755 lp->loggedin = lp->valid = 1;
1756 count = fcp->isp_iid;
1757 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1762 isp2100_fw_statename(int state)
1765 case FW_CONFIG_WAIT: return "Config Wait";
1766 case FW_WAIT_AL_PA: return "Waiting for AL_PA";
1767 case FW_WAIT_LOGIN: return "Wait Login";
1768 case FW_READY: return "Ready";
1769 case FW_LOSS_OF_SYNC: return "Loss Of Sync";
1770 case FW_ERROR: return "Error";
1771 case FW_REINIT: return "Re-Init";
1772 case FW_NON_PART: return "Nonparticipating";
1773 default: return "?????";
1778 * Synchronize our soft copy of the port database with what the f/w thinks
1779 * (with a view toward possibly for a specific target....)
1783 isp_pdb_sync(struct ispsoftc *isp)
1786 fcparam *fcp = isp->isp_param;
1788 int loopid, base, lim;
1791 * Make sure we're okay for doing this right now.
1793 if (fcp->isp_loopstate != LOOP_PDB_RCVD &&
1794 fcp->isp_loopstate != LOOP_FSCAN_DONE &&
1795 fcp->isp_loopstate != LOOP_LSCAN_DONE) {
1799 if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_NL_PORT ||
1800 fcp->isp_topo == TOPO_N_PORT) {
1801 if (fcp->isp_loopstate < LOOP_LSCAN_DONE) {
1802 if (isp_scan_loop(isp) != 0) {
1807 fcp->isp_loopstate = LOOP_SYNCING_PDB;
1810 * If we get this far, we've settled our differences with the f/w
1811 * (for local loop device) and we can say that the loop state is ready.
1814 if (fcp->isp_topo == TOPO_NL_PORT) {
1815 fcp->loop_seen_once = 1;
1816 fcp->isp_loopstate = LOOP_READY;
1821 * Find all Fabric Entities that didn't make it from one scan to the
1822 * next and let the world know they went away. Scan the whole database.
1824 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[MAX_FC_TARG]; lp++) {
1825 if (lp->was_fabric_dev && lp->fabric_dev == 0) {
1826 loopid = lp - fcp->portdb;
1827 lp->valid = 0; /* should already be set */
1828 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1829 MEMZERO((void *) lp, sizeof (*lp));
1832 lp->was_fabric_dev = lp->fabric_dev;
1835 if (fcp->isp_topo == TOPO_FL_PORT)
1840 if (fcp->isp_topo == TOPO_N_PORT)
1846 * Now log in any fabric devices that the outer layer has
1847 * left for us to see. This seems the most sane policy
1850 for (lp = &fcp->portdb[base]; lp < &fcp->portdb[lim]; lp++) {
1854 loopid = lp - fcp->portdb;
1855 if (loopid >= FL_PORT_ID && loopid <= FC_SNS_ID) {
1862 if (lp->port_wwn == 0) {
1867 * Don't try to log into yourself.
1869 if ((portid = lp->portid) == fcp->isp_portid) {
1875 * If we'd been logged in- see if we still are and we haven't
1876 * changed. If so, no need to log ourselves out, etc..
1878 * Unfortunately, our charming Qlogic f/w has decided to
1879 * return a valid port database entry for a fabric device
1880 * that has, in fact, gone away. And it hangs trying to
1883 if (lp->loggedin && lp->force_logout == 0 &&
1884 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
1886 u_int64_t nwwnn, nwwpn;
1888 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1889 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1890 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1891 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1892 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1893 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1894 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1895 (((u_int64_t)pdb.pdb_nodename[7]));
1897 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1898 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1899 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1900 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1901 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1902 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1903 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1904 (((u_int64_t)pdb.pdb_portname[7]));
1905 nrole = (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >>
1907 if (pdb.pdb_loopid == lp->loopid && lp->portid ==
1908 (u_int32_t) BITS2WORD(pdb.pdb_portid_bits) &&
1909 nwwnn == lp->node_wwn && nwwpn == lp->port_wwn &&
1910 lp->roles == nrole && lp->force_logout == 0) {
1911 lp->loggedin = lp->valid = 1;
1912 isp_prt(isp, ISP_LOGCONFIG, lretained,
1913 (int) (lp - fcp->portdb),
1914 (int) lp->loopid, lp->portid);
1919 if (fcp->isp_fwstate != FW_READY ||
1920 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1925 * Force a logout if we were logged in.
1928 if (lp->force_logout ||
1929 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
1930 mbs.param[0] = MBOX_FABRIC_LOGOUT;
1931 mbs.param[1] = lp->loopid << 8;
1934 isp_mboxcmd(isp, &mbs, MBLOGNONE);
1935 isp_prt(isp, ISP_LOGINFO, plogout,
1936 (int) (lp - fcp->portdb), lp->loopid,
1939 lp->force_logout = lp->loggedin = 0;
1940 if (fcp->isp_fwstate != FW_READY ||
1941 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1949 loopid = lp - fcp->portdb;
1950 lp->loopid = FL_PORT_ID;
1952 mbs.param[0] = MBOX_FABRIC_LOGIN;
1953 mbs.param[1] = loopid << 8;
1954 mbs.param[2] = portid >> 16;
1955 mbs.param[3] = portid & 0xffff;
1956 isp_mboxcmd(isp, &mbs, MBLOGALL & ~(MBOX_LOOP_ID_USED |
1957 MBOX_PORT_ID_USED | MBOX_COMMAND_ERROR));
1958 if (fcp->isp_fwstate != FW_READY ||
1959 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1962 switch (mbs.param[0]) {
1963 case MBOX_LOOP_ID_USED:
1965 * Try the next available loop id.
1969 case MBOX_PORT_ID_USED:
1971 * This port is already logged in.
1972 * Snaffle the loop id it's using if it's
1973 * nonzero, otherwise we're hosed.
1975 if (mbs.param[1] != 0) {
1976 loopid = mbs.param[1];
1977 isp_prt(isp, ISP_LOGINFO, retained,
1978 loopid, (int) (lp - fcp->portdb),
1981 loopid = MAX_FC_TARG;
1985 case MBOX_COMMAND_COMPLETE:
1987 lp->loopid = loopid;
1989 case MBOX_COMMAND_ERROR:
1990 isp_prt(isp, ISP_LOGINFO, plogierr,
1991 portid, mbs.param[1]);
1993 case MBOX_ALL_IDS_USED: /* We're outta IDs */
1995 loopid = MAX_FC_TARG;
1998 } while (lp->loopid == FL_PORT_ID && loopid < MAX_FC_TARG);
2001 * If we get here and we haven't set a Loop ID,
2002 * we failed to log into this device.
2005 if (lp->loopid == FL_PORT_ID) {
2011 * Make sure we can get the approriate port information.
2013 if (isp_getpdb(isp, lp->loopid, &pdb) != 0) {
2014 isp_prt(isp, ISP_LOGWARN, nopdb, lp->portid);
2018 if (fcp->isp_fwstate != FW_READY ||
2019 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2023 if (pdb.pdb_loopid != lp->loopid) {
2024 isp_prt(isp, ISP_LOGWARN, pdbmfail1,
2025 lp->portid, pdb.pdb_loopid);
2029 if (lp->portid != (u_int32_t) BITS2WORD(pdb.pdb_portid_bits)) {
2030 isp_prt(isp, ISP_LOGWARN, pdbmfail2,
2031 lp->portid, BITS2WORD(pdb.pdb_portid_bits));
2036 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2038 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
2039 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
2040 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
2041 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
2042 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
2043 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
2044 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
2045 (((u_int64_t)pdb.pdb_nodename[7]));
2047 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
2048 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
2049 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
2050 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
2051 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
2052 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
2053 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
2054 (((u_int64_t)pdb.pdb_portname[7]));
2056 * Check to make sure this all makes sense.
2058 if (lp->node_wwn && lp->port_wwn) {
2060 loopid = lp - fcp->portdb;
2061 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2066 isp_prt(isp, ISP_LOGINFO,
2067 ldumped, loopid, lp->loopid, lp->portid);
2068 mbs.param[0] = MBOX_FABRIC_LOGOUT;
2069 mbs.param[1] = lp->loopid << 8;
2072 isp_mboxcmd(isp, &mbs, MBLOGNONE);
2073 if (fcp->isp_fwstate != FW_READY ||
2074 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2079 * If we get here, we've for sure seen not only a valid loop
2080 * but know what is or isn't on it, so mark this for usage
2083 fcp->loop_seen_once = 1;
2084 fcp->isp_loopstate = LOOP_READY;
2089 isp_scan_loop(struct ispsoftc *isp)
2092 fcparam *fcp = isp->isp_param;
2094 int loopid, lim, hival;
2096 switch (fcp->isp_topo) {
2107 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2110 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
2113 * make sure the temp port database is clean...
2115 MEMZERO((void *)fcp->tport, sizeof (fcp->tport));
2118 * Run through the local loop ports and get port database info
2121 * There's a somewhat unexplained situation where the f/w passes back
2122 * the wrong database entity- if that happens, just restart (up to
2123 * FL_PORT_ID times).
2125 for (lim = loopid = 0; loopid < hival; loopid++) {
2126 lp = &fcp->tport[loopid];
2129 * Don't even try for ourselves...
2131 if (loopid == fcp->isp_loopid)
2134 lp->node_wwn = isp_get_portname(isp, loopid, 1);
2135 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2137 if (lp->node_wwn == 0)
2139 lp->port_wwn = isp_get_portname(isp, loopid, 0);
2140 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2142 if (lp->port_wwn == 0) {
2150 if (isp_getpdb(isp, loopid, &pdb) != 0) {
2151 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2155 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2160 * If the returned database element doesn't match what we
2161 * asked for, restart the process entirely (up to a point...).
2163 if (pdb.pdb_loopid != loopid) {
2165 if (lim++ < hival) {
2168 isp_prt(isp, ISP_LOGWARN,
2169 "giving up on synchronizing the port database");
2174 * Save the pertinent info locally.
2177 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
2178 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
2179 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
2180 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
2181 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
2182 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
2183 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
2184 (((u_int64_t)pdb.pdb_nodename[7]));
2186 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
2187 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
2188 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
2189 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
2190 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
2191 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
2192 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
2193 (((u_int64_t)pdb.pdb_portname[7]));
2195 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2196 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
2197 lp->loopid = pdb.pdb_loopid;
2201 * Mark all of the permanent local loop database entries as invalid
2202 * (except our own entry).
2204 for (loopid = 0; loopid < hival; loopid++) {
2205 if (loopid == fcp->isp_iid) {
2206 fcp->portdb[loopid].valid = 1;
2207 fcp->portdb[loopid].loopid = fcp->isp_loopid;
2210 fcp->portdb[loopid].valid = 0;
2214 * Now merge our local copy of the port database into our saved copy.
2215 * Notify the outer layers of new devices arriving.
2217 for (loopid = 0; loopid < hival; loopid++) {
2221 * If we don't have a non-zero Port WWN, we're not here.
2223 if (fcp->tport[loopid].port_wwn == 0) {
2230 if (loopid == fcp->isp_iid) {
2235 * For the purposes of deciding whether this is the
2236 * 'same' device or not, we only search for an identical
2237 * Port WWN. Node WWNs may or may not be the same as
2238 * the Port WWN, and there may be multiple different
2239 * Port WWNs with the same Node WWN. It would be chaos
2240 * to have multiple identical Port WWNs, so we don't
2244 for (i = 0; i < hival; i++) {
2246 if (fcp->portdb[i].port_wwn == 0)
2248 if (fcp->portdb[i].port_wwn !=
2249 fcp->tport[loopid].port_wwn)
2252 * We found this WWN elsewhere- it's changed
2253 * loopids then. We don't change it's actual
2254 * position in our cached port database- we
2255 * just change the actual loop ID we'd use.
2257 if (fcp->portdb[i].loopid != loopid) {
2258 isp_prt(isp, ISP_LOGINFO, portshift, i,
2259 fcp->portdb[i].loopid,
2260 fcp->portdb[i].portid, loopid,
2261 fcp->tport[loopid].portid);
2263 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2264 fcp->portdb[i].loopid = loopid;
2265 fcp->portdb[i].valid = 1;
2266 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2269 * Now make sure this Port WWN doesn't exist elsewhere
2270 * in the port database.
2272 for (j = i+1; j < hival; j++) {
2273 if (fcp->portdb[i].port_wwn !=
2274 fcp->portdb[j].port_wwn) {
2277 isp_prt(isp, ISP_LOGWARN, portdup, j, i);
2279 * Invalidate the 'old' *and* 'new' ones.
2280 * This is really harsh and not quite right,
2281 * but if this happens, we really don't know
2282 * who is what at this point.
2284 fcp->portdb[i].valid = 0;
2285 fcp->portdb[j].valid = 0;
2291 * If we didn't traverse the entire port database,
2292 * then we found (and remapped) an existing entry.
2293 * No need to notify anyone- go for the next one.
2296 isp_prt(isp, ISP_LOGINFO, retained,
2297 fcp->portdb[i].loopid, i, fcp->portdb[i].portid);
2302 * We've not found this Port WWN anywhere. It's a new entry.
2303 * See if we can leave it where it is (with target == loopid).
2305 if (fcp->portdb[loopid].port_wwn != 0) {
2306 for (lim = 0; lim < hival; lim++) {
2307 if (fcp->portdb[lim].port_wwn == 0)
2310 /* "Cannot Happen" */
2312 isp_prt(isp, ISP_LOGWARN, "Remap Overflow");
2321 * NB: The actual loopid we use here is loopid- we may
2322 * in fact be at a completely different index (target).
2324 fcp->portdb[i].loopid = loopid;
2325 fcp->portdb[i].port_wwn = fcp->tport[loopid].port_wwn;
2326 fcp->portdb[i].node_wwn = fcp->tport[loopid].node_wwn;
2327 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2328 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2329 fcp->portdb[i].valid = 1;
2332 * Tell the outside world we've arrived.
2334 (void) isp_async(isp, ISPASYNC_PROMENADE, &i);
2338 * Now find all previously used targets that are now invalid and
2339 * notify the outer layers that they're gone.
2341 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[hival]; lp++) {
2342 if (lp->valid || lp->port_wwn == 0) {
2347 * Tell the outside world we've gone
2348 * away and erase our pdb entry.
2351 loopid = lp - fcp->portdb;
2352 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2353 MEMZERO((void *) lp, sizeof (*lp));
2355 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2361 isp_fabric_mbox_cmd(struct ispsoftc *isp, mbreg_t *mbp)
2363 isp_mboxcmd(isp, mbp, MBLOGNONE);
2364 if (mbp->param[0] != MBOX_COMMAND_COMPLETE) {
2365 if (FCPARAM(isp)->isp_loopstate == LOOP_SCANNING_FABRIC) {
2366 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
2368 if (mbp->param[0] == MBOX_COMMAND_ERROR) {
2371 switch (mbp->param[1]) {
2376 m = "Failed to allocate IOCB buffer";
2379 m = "Failed to allocate XCB buffer";
2382 m = "timeout or transmit failed";
2385 m = "no fabric loop";
2388 m = "remote device not a target";
2391 SNPRINTF(tbuf, sizeof tbuf, "%x",
2396 isp_prt(isp, ISP_LOGERR, "SNS Failed- %s", m);
2401 if (FCPARAM(isp)->isp_fwstate != FW_READY ||
2402 FCPARAM(isp)->isp_loopstate < LOOP_SCANNING_FABRIC) {
2408 #ifdef ISP_USE_GA_NXT
2410 isp_scan_fabric(struct ispsoftc *isp, int ftype)
2412 fcparam *fcp = isp->isp_param;
2413 u_int32_t portid, first_portid, last_portid;
2414 int hicap, last_port_same;
2416 if (fcp->isp_onfabric == 0) {
2417 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2421 FC_SCRATCH_ACQUIRE(isp);
2424 * Since Port IDs are 24 bits, we can check against having seen
2425 * anything yet with this value.
2428 last_portid = 0xffffffff; /* not a port */
2429 first_portid = portid = fcp->isp_portid;
2430 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2432 for (hicap = 0; hicap < GA_NXT_MAX; hicap++) {
2435 sns_ga_nxt_rsp_t *rs0, *rs1;
2437 u_int8_t sc[SNS_GA_NXT_RESP_SIZE];
2439 rq = (sns_screq_t *)sc;
2440 MEMZERO((void *) rq, SNS_GA_NXT_REQ_SIZE);
2441 rq->snscb_rblen = SNS_GA_NXT_RESP_SIZE >> 1;
2442 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+0x100);
2443 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+0x100);
2444 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+0x100);
2445 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+0x100);
2446 rq->snscb_sblen = 6;
2447 rq->snscb_data[0] = SNS_GA_NXT;
2448 rq->snscb_data[4] = portid & 0xffff;
2449 rq->snscb_data[5] = (portid >> 16) & 0xff;
2450 isp_put_sns_request(isp, rq, (sns_screq_t *) fcp->isp_scratch);
2451 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GA_NXT_REQ_SIZE);
2452 mbs.param[0] = MBOX_SEND_SNS;
2453 mbs.param[1] = SNS_GA_NXT_REQ_SIZE >> 1;
2454 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2455 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2457 * Leave 4 and 5 alone
2459 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2460 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2461 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2462 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2463 fcp->isp_loopstate = LOOP_PDB_RCVD;
2465 FC_SCRATCH_RELEASE(isp);
2468 MEMORYBARRIER(isp, SYNC_SFORCPU, 0x100, SNS_GA_NXT_RESP_SIZE);
2469 rs1 = (sns_ga_nxt_rsp_t *) sc;
2470 rs0 = (sns_ga_nxt_rsp_t *) ((u_int8_t *)fcp->isp_scratch+0x100);
2471 isp_get_ga_nxt_response(isp, rs0, rs1);
2472 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2474 if (rs1->snscb_cthdr.ct_reason == 9 &&
2475 rs1->snscb_cthdr.ct_explanation == 7)
2476 level = ISP_LOGDEBUG0;
2478 level = ISP_LOGWARN;
2479 isp_prt(isp, level, swrej, "GA_NXT",
2480 rs1->snscb_cthdr.ct_reason,
2481 rs1->snscb_cthdr.ct_explanation, portid);
2482 FC_SCRATCH_RELEASE(isp);
2483 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2487 (((u_int32_t) rs1->snscb_port_id[0]) << 16) |
2488 (((u_int32_t) rs1->snscb_port_id[1]) << 8) |
2489 (((u_int32_t) rs1->snscb_port_id[2]));
2492 * XXX: We should check to make sure that this entry
2493 * XXX: supports the type(s) we are interested in.
2496 * Okay, we now have information about a fabric object.
2497 * If it is the type we're interested in, tell the outer layers
2498 * about it. The outer layer needs to know: Port ID, WWNN,
2499 * WWPN, FC4 type, and port type.
2501 * The lportdb structure is adequate for this.
2503 MEMZERO(&lcl, sizeof (lcl));
2504 lcl.port_type = rs1->snscb_port_type;
2505 lcl.fc4_type = ftype;
2506 lcl.portid = portid;
2508 (((u_int64_t)rs1->snscb_nodename[0]) << 56) |
2509 (((u_int64_t)rs1->snscb_nodename[1]) << 48) |
2510 (((u_int64_t)rs1->snscb_nodename[2]) << 40) |
2511 (((u_int64_t)rs1->snscb_nodename[3]) << 32) |
2512 (((u_int64_t)rs1->snscb_nodename[4]) << 24) |
2513 (((u_int64_t)rs1->snscb_nodename[5]) << 16) |
2514 (((u_int64_t)rs1->snscb_nodename[6]) << 8) |
2515 (((u_int64_t)rs1->snscb_nodename[7]));
2517 (((u_int64_t)rs1->snscb_portname[0]) << 56) |
2518 (((u_int64_t)rs1->snscb_portname[1]) << 48) |
2519 (((u_int64_t)rs1->snscb_portname[2]) << 40) |
2520 (((u_int64_t)rs1->snscb_portname[3]) << 32) |
2521 (((u_int64_t)rs1->snscb_portname[4]) << 24) |
2522 (((u_int64_t)rs1->snscb_portname[5]) << 16) |
2523 (((u_int64_t)rs1->snscb_portname[6]) << 8) |
2524 (((u_int64_t)rs1->snscb_portname[7]));
2527 * Does this fabric object support the type we want?
2530 if (rs1->snscb_fc4_types[ftype >> 5] & (1 << (ftype & 0x1f))) {
2531 if (first_portid == portid) {
2532 lcl.last_fabric_dev = 1;
2534 lcl.last_fabric_dev = 0;
2536 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2538 isp_prt(isp, ISP_LOGDEBUG0,
2539 "PortID 0x%x doesn't support FC4 type 0x%x",
2542 if (first_portid == portid) {
2543 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2544 FC_SCRATCH_RELEASE(isp);
2547 if (portid == last_portid) {
2548 if (last_port_same++ > 20) {
2549 isp_prt(isp, ISP_LOGWARN,
2550 "tangled fabric database detected");
2554 last_port_same = 0 ;
2555 last_portid = portid;
2558 FC_SCRATCH_RELEASE(isp);
2559 if (hicap >= GA_NXT_MAX) {
2560 isp_prt(isp, ISP_LOGWARN, "fabric too big (> %d)", GA_NXT_MAX);
2562 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2566 #define GIDLEN ((ISP2100_SCRLEN >> 1) + 16)
2567 #define NGENT ((GIDLEN - 16) >> 2)
2569 #define IGPOFF (ISP2100_SCRLEN - GIDLEN)
2573 isp_scan_fabric(struct ispsoftc *isp, int ftype)
2575 fcparam *fcp = FCPARAM(isp);
2578 sns_gid_ft_req_t *rq;
2579 sns_gid_ft_rsp_t *rs0, *rs1;
2581 if (fcp->isp_onfabric == 0) {
2582 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2586 FC_SCRATCH_ACQUIRE(isp);
2587 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2589 rq = (sns_gid_ft_req_t *)fcp->tport;
2590 MEMZERO((void *) rq, SNS_GID_FT_REQ_SIZE);
2591 rq->snscb_rblen = GIDLEN >> 1;
2592 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+IGPOFF);
2593 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+IGPOFF);
2594 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+IGPOFF);
2595 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+IGPOFF);
2596 rq->snscb_sblen = 6;
2597 rq->snscb_cmd = SNS_GID_FT;
2598 rq->snscb_mword_div_2 = NGENT;
2599 rq->snscb_fc4_type = ftype;
2600 isp_put_gid_ft_request(isp, rq, (sns_gid_ft_req_t *) fcp->isp_scratch);
2601 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE);
2602 mbs.param[0] = MBOX_SEND_SNS;
2603 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
2604 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2605 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2608 * Leave 4 and 5 alone
2610 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2611 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2612 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2613 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2614 fcp->isp_loopstate = LOOP_PDB_RCVD;
2616 FC_SCRATCH_RELEASE(isp);
2619 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2620 FC_SCRATCH_RELEASE(isp);
2623 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN);
2624 rs1 = (sns_gid_ft_rsp_t *) fcp->tport;
2625 rs0 = (sns_gid_ft_rsp_t *) ((u_int8_t *)fcp->isp_scratch+IGPOFF);
2626 isp_get_gid_ft_response(isp, rs0, rs1, NGENT);
2627 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2629 if (rs1->snscb_cthdr.ct_reason == 9 &&
2630 rs1->snscb_cthdr.ct_explanation == 7)
2631 level = ISP_LOGDEBUG0;
2633 level = ISP_LOGWARN;
2634 isp_prt(isp, level, swrej, "GID_FT",
2635 rs1->snscb_cthdr.ct_reason,
2636 rs1->snscb_cthdr.ct_explanation, 0);
2637 FC_SCRATCH_RELEASE(isp);
2638 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2643 * Okay, we now have a list of Port IDs for this class of device.
2644 * Go through the list and for each one get the WWPN/WWNN for it
2645 * and tell the outer layers about it. The outer layer needs to
2646 * know: Port ID, WWNN, WWPN, FC4 type, and (possibly) port type.
2648 * The lportdb structure is adequate for this.
2652 sns_gxn_id_req_t grqbuf, *gq = &grqbuf;
2653 sns_gxn_id_rsp_t *gs0, grsbuf, *gs1 = &grsbuf;
2656 sns_gff_id_rsp_t *fs0, ffsbuf, *fs1 = &ffsbuf;
2660 MEMZERO(&lcl, sizeof (lcl));
2661 lcl.fc4_type = ftype;
2663 (((u_int32_t) rs1->snscb_ports[i].portid[0]) << 16) |
2664 (((u_int32_t) rs1->snscb_ports[i].portid[1]) << 8) |
2665 (((u_int32_t) rs1->snscb_ports[i].portid[2]));
2667 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2668 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2669 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2670 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2671 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2672 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2673 gq->snscb_sblen = 6;
2674 gq->snscb_cmd = SNS_GPN_ID;
2675 gq->snscb_portid = lcl.portid;
2676 isp_put_gxn_id_request(isp, gq,
2677 (sns_gxn_id_req_t *) fcp->isp_scratch);
2678 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2679 mbs.param[0] = MBOX_SEND_SNS;
2680 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2681 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2682 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2684 * Leave 4 and 5 alone
2686 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2687 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2688 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2689 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2690 fcp->isp_loopstate = LOOP_PDB_RCVD;
2692 FC_SCRATCH_RELEASE(isp);
2695 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2696 FC_SCRATCH_RELEASE(isp);
2699 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2700 gs0 = (sns_gxn_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2701 isp_get_gxn_id_response(isp, gs0, gs1);
2702 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2703 isp_prt(isp, ISP_LOGWARN, swrej, "GPN_ID",
2704 gs1->snscb_cthdr.ct_reason,
2705 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2706 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2707 FC_SCRATCH_RELEASE(isp);
2713 (((u_int64_t)gs1->snscb_wwn[0]) << 56) |
2714 (((u_int64_t)gs1->snscb_wwn[1]) << 48) |
2715 (((u_int64_t)gs1->snscb_wwn[2]) << 40) |
2716 (((u_int64_t)gs1->snscb_wwn[3]) << 32) |
2717 (((u_int64_t)gs1->snscb_wwn[4]) << 24) |
2718 (((u_int64_t)gs1->snscb_wwn[5]) << 16) |
2719 (((u_int64_t)gs1->snscb_wwn[6]) << 8) |
2720 (((u_int64_t)gs1->snscb_wwn[7]));
2722 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2723 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2724 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2725 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2726 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2727 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2728 gq->snscb_sblen = 6;
2729 gq->snscb_cmd = SNS_GNN_ID;
2730 gq->snscb_portid = lcl.portid;
2731 isp_put_gxn_id_request(isp, gq,
2732 (sns_gxn_id_req_t *) fcp->isp_scratch);
2733 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2734 mbs.param[0] = MBOX_SEND_SNS;
2735 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2736 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2737 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2739 * Leave 4 and 5 alone
2741 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2742 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2743 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2744 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2745 fcp->isp_loopstate = LOOP_PDB_RCVD;
2747 FC_SCRATCH_RELEASE(isp);
2750 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2751 FC_SCRATCH_RELEASE(isp);
2754 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2755 gs0 = (sns_gxn_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2756 isp_get_gxn_id_response(isp, gs0, gs1);
2757 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2758 isp_prt(isp, ISP_LOGWARN, swrej, "GNN_ID",
2759 gs1->snscb_cthdr.ct_reason,
2760 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2761 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2762 FC_SCRATCH_RELEASE(isp);
2768 (((u_int64_t)gs1->snscb_wwn[0]) << 56) |
2769 (((u_int64_t)gs1->snscb_wwn[1]) << 48) |
2770 (((u_int64_t)gs1->snscb_wwn[2]) << 40) |
2771 (((u_int64_t)gs1->snscb_wwn[3]) << 32) |
2772 (((u_int64_t)gs1->snscb_wwn[4]) << 24) |
2773 (((u_int64_t)gs1->snscb_wwn[5]) << 16) |
2774 (((u_int64_t)gs1->snscb_wwn[6]) << 8) |
2775 (((u_int64_t)gs1->snscb_wwn[7]));
2778 * The QLogic f/w is bouncing this with a parameter error.
2782 * Try and get FC4 Features (FC-GS-3 only).
2783 * We can use the sns_gxn_id_req_t for this request.
2785 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2786 gq->snscb_rblen = SNS_GFF_ID_RESP_SIZE >> 1;
2787 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2788 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2789 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2790 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2791 gq->snscb_sblen = 6;
2792 gq->snscb_cmd = SNS_GFF_ID;
2793 gq->snscb_portid = lcl.portid;
2794 isp_put_gxn_id_request(isp, gq,
2795 (sns_gxn_id_req_t *) fcp->isp_scratch);
2796 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2797 mbs.param[0] = MBOX_SEND_SNS;
2798 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2799 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2800 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2802 * Leave 4 and 5 alone
2804 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2805 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2806 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2807 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2808 fcp->isp_loopstate = LOOP_PDB_RCVD;
2810 FC_SCRATCH_RELEASE(isp);
2813 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2814 FC_SCRATCH_RELEASE(isp);
2817 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GFF_ID_RESP_SIZE);
2818 fs0 = (sns_gff_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2819 isp_get_gff_id_response(isp, fs0, fs1);
2820 if (fs1->snscb_cthdr.ct_response != FS_ACC) {
2821 isp_prt(isp, /* ISP_LOGDEBUG0 */ ISP_LOGWARN,
2823 fs1->snscb_cthdr.ct_reason,
2824 fs1->snscb_cthdr.ct_explanation, lcl.portid);
2825 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2826 FC_SCRATCH_RELEASE(isp);
2830 int index = (ftype >> 3);
2831 int bshft = (ftype & 0x7) * 4;
2833 (fs1->snscb_fc4_features[index] >> bshft) & 0xf;
2834 if (fc4_fval & 0x1) {
2836 (SVC3_INI_ROLE >> SVC3_ROLE_SHIFT);
2838 if (fc4_fval & 0x2) {
2840 (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT);
2846 * If we really want to know what kind of port type this is,
2847 * we have to run another CT command. Otherwise, we'll leave
2852 if (rs1->snscb_ports[i].control & 0x80) {
2853 lcl.last_fabric_dev = 1;
2855 lcl.last_fabric_dev = 0;
2857 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2859 } while ((rs1->snscb_ports[i].control & 0x80) == 0 && i < NGENT-1);
2862 * If we're not at the last entry, our list isn't big enough.
2864 if ((rs1->snscb_ports[i].control & 0x80) == 0) {
2865 isp_prt(isp, ISP_LOGWARN, "fabric too big for scratch area");
2868 FC_SCRATCH_RELEASE(isp);
2869 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2875 isp_register_fc4_type(struct ispsoftc *isp)
2877 fcparam *fcp = isp->isp_param;
2878 u_int8_t local[SNS_RFT_ID_REQ_SIZE];
2879 sns_screq_t *reqp = (sns_screq_t *) local;
2882 MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
2883 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
2884 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
2885 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
2886 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
2887 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
2888 reqp->snscb_sblen = 22;
2889 reqp->snscb_data[0] = SNS_RFT_ID;
2890 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
2891 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
2892 reqp->snscb_data[6] = (1 << FC4_SCSI);
2894 reqp->snscb_data[6] |= (1 << FC4_IP); /* ISO/IEC 8802-2 LLC/SNAP */
2896 FC_SCRATCH_ACQUIRE(isp);
2897 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
2898 mbs.param[0] = MBOX_SEND_SNS;
2899 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
2900 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2901 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2903 * Leave 4 and 5 alone
2905 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2906 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2907 isp_mboxcmd(isp, &mbs, MBLOGALL);
2908 FC_SCRATCH_RELEASE(isp);
2909 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
2910 isp_prt(isp, ISP_LOGDEBUG0, "Register FC4 types succeeded");
2915 * Start a command. Locking is assumed done in the caller.
2921 struct ispsoftc *isp;
2922 u_int16_t nxti, optr, handle;
2923 u_int8_t local[QENTRY_LEN];
2924 ispreq_t *reqp, *qep;
2931 * Check to make sure we're supporting initiator role.
2933 if ((isp->isp_role & ISP_ROLE_INITIATOR) == 0) {
2934 XS_SETERR(xs, HBA_SELTIMEOUT);
2935 return (CMD_COMPLETE);
2939 * Now make sure we're running.
2942 if (isp->isp_state != ISP_RUNSTATE) {
2943 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
2944 XS_SETERR(xs, HBA_BOTCH);
2945 return (CMD_COMPLETE);
2949 * Check command CDB length, etc.. We really are limited to 16 bytes
2950 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
2951 * but probably only if we're running fairly new firmware (we'll
2952 * let the old f/w choke on an extended command queue entry).
2955 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
2956 isp_prt(isp, ISP_LOGERR,
2957 "unsupported cdb length (%d, CDB[0]=0x%x)",
2958 XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
2959 XS_SETERR(xs, HBA_BOTCH);
2960 return (CMD_COMPLETE);
2964 * Check to see whether we have good firmware state still or
2965 * need to refresh our port database for this target.
2967 target = XS_TGT(xs);
2969 fcparam *fcp = isp->isp_param;
2971 #ifdef HANDLE_LOOPSTATE_IN_OUTER_LAYERS
2972 if (fcp->isp_fwstate != FW_READY ||
2973 fcp->isp_loopstate != LOOP_READY) {
2974 return (CMD_RQLATER);
2978 * If we're not on a Fabric, we can't have a target
2979 * above FL_PORT_ID-1.
2981 * If we're on a fabric and *not* connected as an F-port,
2982 * we can't have a target less than FC_SNS_ID+1. This
2983 * keeps us from having to sort out the difference between
2984 * local public loop devices and those which we might get
2985 * from a switch's database.
2987 if (fcp->isp_onfabric == 0) {
2988 if (target >= FL_PORT_ID) {
2989 XS_SETERR(xs, HBA_SELTIMEOUT);
2990 return (CMD_COMPLETE);
2993 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
2994 XS_SETERR(xs, HBA_SELTIMEOUT);
2995 return (CMD_COMPLETE);
2998 * We used to exclude having local loop ports
2999 * at the same time that we have fabric ports.
3000 * That is, we used to exclude having ports
3001 * at < FL_PORT_ID if we're FL-port.
3003 * That's wrong. The only thing that could be
3004 * dicey is if the switch you're connected to
3005 * has these local loop ports appear on the
3006 * fabric and we somehow attach them twice.
3011 * Check for f/w being in ready state. If the f/w
3012 * isn't in ready state, then we don't know our
3013 * loop ID and the f/w hasn't completed logging
3014 * into all targets on the loop. If this is the
3015 * case, then bounce the command. We pretend this is
3016 * a SELECTION TIMEOUT error if we've never gone to
3017 * FW_READY state at all- in this case we may not
3018 * be hooked to a loop at all and we shouldn't hang
3019 * the machine for this. Otherwise, defer this command
3022 if (fcp->isp_fwstate != FW_READY) {
3024 * Give ourselves at most a 250ms delay.
3026 if (isp_fclink_test(isp, 250000)) {
3027 XS_SETERR(xs, HBA_SELTIMEOUT);
3028 if (fcp->loop_seen_once) {
3029 return (CMD_RQLATER);
3031 return (CMD_COMPLETE);
3037 * If we're not on a Fabric, we can't have a target
3038 * above FL_PORT_ID-1.
3040 * If we're on a fabric and *not* connected as an F-port,
3041 * we can't have a target less than FC_SNS_ID+1. This
3042 * keeps us from having to sort out the difference between
3043 * local public loop devices and those which we might get
3044 * from a switch's database.
3046 if (fcp->isp_onfabric == 0) {
3047 if (target >= FL_PORT_ID) {
3048 XS_SETERR(xs, HBA_SELTIMEOUT);
3049 return (CMD_COMPLETE);
3052 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3053 XS_SETERR(xs, HBA_SELTIMEOUT);
3054 return (CMD_COMPLETE);
3056 if (fcp->isp_topo != TOPO_F_PORT &&
3057 target < FL_PORT_ID) {
3058 XS_SETERR(xs, HBA_SELTIMEOUT);
3059 return (CMD_COMPLETE);
3064 * If our loop state is such that we haven't yet received
3065 * a "Port Database Changed" notification (after a LIP or
3066 * a Loop Reset or firmware initialization), then defer
3067 * sending commands for a little while, but only if we've
3068 * seen a valid loop at one point (otherwise we can get
3069 * stuck at initialization time).
3071 if (fcp->isp_loopstate < LOOP_PDB_RCVD) {
3072 XS_SETERR(xs, HBA_SELTIMEOUT);
3073 if (fcp->loop_seen_once) {
3074 return (CMD_RQLATER);
3076 return (CMD_COMPLETE);
3081 * If we're in the middle of loop or fabric scanning
3082 * or merging the port databases, retry this command later.
3084 if (fcp->isp_loopstate == LOOP_SCANNING_FABRIC ||
3085 fcp->isp_loopstate == LOOP_SCANNING_LOOP ||
3086 fcp->isp_loopstate == LOOP_SYNCING_PDB) {
3087 return (CMD_RQLATER);
3091 * If our loop state is now such that we've just now
3092 * received a Port Database Change notification, then
3093 * we have to go off and (re)scan the fabric. We back
3094 * out and try again later if this doesn't work.
3096 if (fcp->isp_loopstate == LOOP_PDB_RCVD && fcp->isp_onfabric) {
3097 if (isp_scan_fabric(isp, FC4_SCSI)) {
3098 return (CMD_RQLATER);
3100 if (fcp->isp_fwstate != FW_READY ||
3101 fcp->isp_loopstate < LOOP_FSCAN_DONE) {
3102 return (CMD_RQLATER);
3107 * If our loop state is now such that we've just now
3108 * received a Port Database Change notification, then
3109 * we have to go off and (re)synchronize our port
3112 if (fcp->isp_loopstate < LOOP_READY) {
3113 if (isp_pdb_sync(isp)) {
3114 return (CMD_RQLATER);
3116 if (fcp->isp_fwstate != FW_READY ||
3117 fcp->isp_loopstate != LOOP_READY) {
3118 return (CMD_RQLATER);
3123 * XXX: Here's were we would cancel any loop_dead flag
3124 * XXX: also cancel in dead_loop timeout that's running
3129 * Now check whether we should even think about pursuing this.
3131 lp = &fcp->portdb[target];
3132 if (lp->valid == 0) {
3133 XS_SETERR(xs, HBA_SELTIMEOUT);
3134 return (CMD_COMPLETE);
3136 if ((lp->roles & (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT)) == 0) {
3137 isp_prt(isp, ISP_LOGDEBUG2,
3138 "Target %d does not have target service", target);
3139 XS_SETERR(xs, HBA_SELTIMEOUT);
3140 return (CMD_COMPLETE);
3143 * Now turn target into what the actual Loop ID is.
3145 target = lp->loopid;
3149 * Next check to see if any HBA or Device
3150 * parameters need to be updated.
3152 if (isp->isp_update != 0) {
3156 if (isp_getrqentry(isp, &nxti, &optr, (void *)&qep)) {
3157 isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow");
3158 XS_SETERR(xs, HBA_BOTCH);
3159 return (CMD_EAGAIN);
3163 * Now see if we need to synchronize the ISP with respect to anything.
3164 * We do dual duty here (cough) for synchronizing for busses other
3165 * than which we got here to send a command to.
3167 reqp = (ispreq_t *) local;
3168 if (isp->isp_sendmarker) {
3169 u_int8_t n = (IS_DUALBUS(isp)? 2: 1);
3171 * Check ports to send markers for...
3173 for (i = 0; i < n; i++) {
3174 if ((isp->isp_sendmarker & (1 << i)) == 0) {
3177 MEMZERO((void *) reqp, QENTRY_LEN);
3178 reqp->req_header.rqs_entry_count = 1;
3179 reqp->req_header.rqs_entry_type = RQSTYPE_MARKER;
3180 reqp->req_modifier = SYNC_ALL;
3181 reqp->req_target = i << 7; /* insert bus number */
3182 isp_put_request(isp, reqp, qep);
3183 ISP_ADD_REQUEST(isp, nxti);
3184 isp->isp_sendmarker &= ~(1 << i);
3185 if (isp_getrqentry(isp, &nxti, &optr, (void *) &qep)) {
3186 isp_prt(isp, ISP_LOGDEBUG0,
3187 "Request Queue Overflow+");
3188 XS_SETERR(xs, HBA_BOTCH);
3189 return (CMD_EAGAIN);
3194 MEMZERO((void *)reqp, QENTRY_LEN);
3195 reqp->req_header.rqs_entry_count = 1;
3197 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
3199 if (XS_CDBLEN(xs) > 12)
3200 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
3202 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
3204 /* reqp->req_header.rqs_flags = 0; */
3205 /* reqp->req_header.rqs_seqno = 0; */
3208 * See comment in isp_intr
3210 /* XS_RESID(xs) = 0; */
3213 * Fibre Channel always requires some kind of tag.
3214 * The Qlogic drivers seem be happy not to use a tag,
3215 * but this breaks for some devices (IBM drives).
3218 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
3221 * If we don't know what tag to use, use HEAD OF QUEUE
3222 * for Request Sense or Simple.
3224 if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
3225 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_HTAG;
3227 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
3230 sdparam *sdp = (sdparam *)isp->isp_param;
3231 sdp += XS_CHANNEL(xs);
3232 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) &&
3234 reqp->req_flags = XS_TAG_TYPE(xs);
3237 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
3239 reqp->req_lun_trn = XS_LUN(xs);
3240 reqp->req_cdblen = XS_CDBLEN(xs);
3242 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN)
3243 ((ispreqt2_t *)reqp)->req_scclun = XS_LUN(xs);
3245 ((ispreqt2_t *)reqp)->req_lun_trn = XS_LUN(xs);
3247 MEMCPY(reqp->req_cdb, XS_CDBP(xs), XS_CDBLEN(xs));
3249 reqp->req_time = XS_TIME(xs) / 1000;
3250 if (reqp->req_time == 0 && XS_TIME(xs)) {
3254 if (isp_save_xs(isp, xs, &handle)) {
3255 isp_prt(isp, ISP_LOGDEBUG0, "out of xflist pointers");
3256 XS_SETERR(xs, HBA_BOTCH);
3257 return (CMD_EAGAIN);
3259 reqp->req_handle = handle;
3262 * Set up DMA and/or do any bus swizzling of the request entry
3263 * so that the Qlogic F/W understands what is being asked of it.
3265 i = ISP_DMASETUP(isp, xs, reqp, &nxti, optr);
3266 if (i != CMD_QUEUED) {
3267 isp_destroy_handle(isp, handle);
3269 * dmasetup sets actual error in packet, and
3270 * return what we were given to return.
3274 XS_SETERR(xs, HBA_NOERROR);
3275 isp_prt(isp, ISP_LOGDEBUG2,
3276 "START cmd for %d.%d.%d cmd 0x%x datalen %ld",
3277 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), XS_CDBP(xs)[0],
3278 (long) XS_XFRLEN(xs));
3279 ISP_ADD_REQUEST(isp, nxti);
3281 return (CMD_QUEUED);
3286 * Locks (ints blocked) assumed held.
3290 isp_control(struct ispsoftc *isp, ispctl_t ctl, void *arg)
3299 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
3302 case ISPCTL_RESET_BUS:
3304 * Issue a bus reset.
3306 mbs.param[0] = MBOX_BUS_RESET;
3310 ((sdparam *) isp->isp_param)->isp_bus_reset_delay;
3311 if (mbs.param[1] < 2)
3313 bus = *((int *) arg);
3314 if (IS_DUALBUS(isp))
3320 isp->isp_sendmarker |= (1 << bus);
3321 isp_mboxcmd(isp, &mbs, MBLOGALL);
3322 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3325 isp_prt(isp, ISP_LOGINFO,
3326 "driver initiated bus reset of bus %d", bus);
3329 case ISPCTL_RESET_DEV:
3330 tgt = (*((int *) arg)) & 0xffff;
3331 bus = (*((int *) arg)) >> 16;
3332 mbs.param[0] = MBOX_ABORT_TARGET;
3333 mbs.param[1] = (tgt << 8) | (bus << 15);
3334 mbs.param[2] = 3; /* 'delay', in seconds */
3335 isp_mboxcmd(isp, &mbs, MBLOGALL);
3336 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3339 isp_prt(isp, ISP_LOGINFO,
3340 "Target %d on Bus %d Reset Succeeded", tgt, bus);
3341 isp->isp_sendmarker |= (1 << bus);
3344 case ISPCTL_ABORT_CMD:
3347 handle = isp_find_handle(isp, xs);
3349 isp_prt(isp, ISP_LOGWARN,
3350 "cannot find handle for command to abort");
3353 bus = XS_CHANNEL(xs);
3354 mbs.param[0] = MBOX_ABORT;
3356 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
3357 mbs.param[1] = tgt << 8;
3360 mbs.param[6] = XS_LUN(xs);
3362 mbs.param[1] = tgt << 8 | XS_LUN(xs);
3366 (bus << 15) | (XS_TGT(xs) << 8) | XS_LUN(xs);
3369 mbs.param[2] = handle;
3370 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_ERROR);
3371 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3375 * XXX: Look for command in the REQUEST QUEUE. That is,
3376 * XXX: It hasen't been picked up by firmware yet.
3380 case ISPCTL_UPDATE_PARAMS:
3385 case ISPCTL_FCLINK_TEST:
3388 int usdelay = (arg)? *((int *) arg) : 250000;
3389 return (isp_fclink_test(isp, usdelay));
3393 case ISPCTL_SCAN_FABRIC:
3396 int ftype = (arg)? *((int *) arg) : FC4_SCSI;
3397 return (isp_scan_fabric(isp, ftype));
3401 case ISPCTL_SCAN_LOOP:
3404 return (isp_scan_loop(isp));
3408 case ISPCTL_PDB_SYNC:
3411 return (isp_pdb_sync(isp));
3415 case ISPCTL_SEND_LIP:
3418 mbs.param[0] = MBOX_INIT_LIP;
3419 isp_mboxcmd(isp, &mbs, MBLOGALL);
3420 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3426 case ISPCTL_GET_POSMAP:
3428 if (IS_FC(isp) && arg) {
3429 return (isp_getmap(isp, arg));
3433 case ISPCTL_RUN_MBOXCMD:
3435 isp_mboxcmd(isp, arg, MBLOGALL);
3438 #ifdef ISP_TARGET_MODE
3439 case ISPCTL_TOGGLE_TMODE:
3443 * We don't check/set against role here- that's the
3444 * responsibility for the outer layer to coordinate.
3447 int param = *(int *)arg;
3448 mbs.param[0] = MBOX_ENABLE_TARGET_MODE;
3449 mbs.param[1] = param & 0xffff;
3450 mbs.param[2] = param >> 16;
3451 isp_mboxcmd(isp, &mbs, MBLOGALL);
3452 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3464 * Interrupt Service Routine(s).
3466 * External (OS) framework has done the appropriate locking,
3467 * and the locking will be held throughout this function.
3471 * Limit our stack depth by sticking with the max likely number
3472 * of completions on a request queue at any one time.
3474 #ifndef MAX_REQUESTQ_COMPLETIONS
3475 #define MAX_REQUESTQ_COMPLETIONS 64
3479 isp_intr(struct ispsoftc *isp, u_int16_t isr, u_int16_t sema, u_int16_t mbox)
3481 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
3482 u_int16_t iptr, optr, junk;
3483 int i, nlooked = 0, ndone = 0;
3487 * Is this a mailbox related interrupt?
3488 * The mailbox semaphore will be nonzero if so.
3491 if (mbox & 0x4000) {
3492 isp->isp_intmboxc++;
3493 if (isp->isp_mboxbsy) {
3494 int i = 0, obits = isp->isp_obits;
3495 isp->isp_mboxtmp[i++] = mbox;
3496 for (i = 1; i < MAX_MAILBOX; i++) {
3497 if ((obits & (1 << i)) == 0) {
3500 isp->isp_mboxtmp[i] =
3501 ISP_READ(isp, MBOX_OFF(i));
3503 if (isp->isp_mbxwrk0) {
3504 if (isp_mbox_continue(isp) == 0) {
3508 MBOX_NOTIFY_COMPLETE(isp);
3510 isp_prt(isp, ISP_LOGWARN,
3511 "Mbox Command Async (0x%x) with no waiters",
3514 } else if (isp_parse_async(isp, mbox) < 0) {
3517 if ((IS_FC(isp) && mbox != ASYNC_RIO_RESP) ||
3518 isp->isp_state != ISP_RUNSTATE) {
3519 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3520 ISP_WRITE(isp, BIU_SEMA, 0);
3526 * We can't be getting this now.
3528 if (isp->isp_state != ISP_RUNSTATE) {
3529 isp_prt(isp, ISP_LOGWARN,
3530 "interrupt (ISR=%x SEMA=%x) when not ready", isr, sema);
3532 * Thank you very much! *Burrrp*!
3534 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp,
3535 READ_RESPONSE_QUEUE_IN_POINTER(isp));
3537 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3538 ISP_WRITE(isp, BIU_SEMA, 0);
3543 * Get the current Response Queue Out Pointer.
3545 * If we're a 2300, we can ask what hardware what it thinks.
3548 optr = ISP_READ(isp, isp->isp_respoutrp);
3550 * Debug: to be taken out eventually
3552 if (isp->isp_residx != optr) {
3553 isp_prt(isp, ISP_LOGWARN, "optr %x soft optr %x",
3554 optr, isp->isp_residx);
3557 optr = isp->isp_residx;
3561 * You *must* read the Response Queue In Pointer
3562 * prior to clearing the RISC interrupt.
3564 * Debounce the 2300 if revision less than 2.
3566 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
3569 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3570 junk = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3571 } while (junk != iptr && ++i < 1000);
3574 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3575 isp_prt(isp, ISP_LOGWARN,
3576 "Response Queue Out Pointer Unstable (%x, %x)",
3581 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3583 isp->isp_resodx = iptr;
3586 if (optr == iptr && sema == 0) {
3588 * There are a lot of these- reasons unknown- mostly on
3589 * faster Alpha machines.
3591 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
3592 * make sure the old interrupt went away (to avoid 'ringing'
3593 * effects), but that didn't stop this from occurring.
3597 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3598 junk = ISP_READ(isp, BIU_R2HSTSLO);
3600 junk = ISP_READ(isp, BIU_ISR);
3606 sema = ISP_READ(isp, BIU_SEMA);
3607 mbox = ISP_READ(isp, OUTMAILBOX0);
3608 if ((sema & 0x3) && (mbox & 0x8000)) {
3612 isp->isp_intbogus++;
3613 isp_prt(isp, ISP_LOGDEBUG1,
3614 "bogus intr- isr %x (%x) iptr %x optr %x",
3615 isr, junk, iptr, optr);
3618 isp->isp_resodx = iptr;
3619 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3620 ISP_WRITE(isp, BIU_SEMA, 0);
3622 if (isp->isp_rspbsy) {
3625 isp->isp_rspbsy = 1;
3627 while (optr != iptr) {
3628 ispstatusreq_t local, *sp = &local;
3634 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
3636 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
3639 * Synchronize our view of this response queue entry.
3641 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN);
3643 type = isp_get_response_type(isp, hp);
3645 if (type == RQSTYPE_RESPONSE) {
3646 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3647 } else if (type == RQSTYPE_RIO2) {
3649 isp_get_rio2(isp, (isp_rio2_t *) hp, &rio);
3650 for (i = 0; i < rio.req_header.rqs_seqno; i++) {
3651 isp_fastpost_complete(isp, rio.req_handles[i]);
3653 if (isp->isp_fpcchiwater < rio.req_header.rqs_seqno)
3654 isp->isp_fpcchiwater = rio.req_header.rqs_seqno;
3655 MEMZERO(hp, QENTRY_LEN); /* PERF */
3659 * Somebody reachable via isp_handle_other_response
3660 * may have updated the response queue pointers for
3661 * us, so we reload our goal index.
3663 if (isp_handle_other_response(isp, type, hp, &optr)) {
3664 iptr = isp->isp_resodx;
3665 MEMZERO(hp, QENTRY_LEN); /* PERF */
3670 * After this point, we'll just look at the header as
3671 * we don't know how to deal with the rest of the
3674 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3677 * It really has to be a bounced request just copied
3678 * from the request queue to the response queue. If
3679 * not, something bad has happened.
3681 if (sp->req_header.rqs_entry_type != RQSTYPE_REQUEST) {
3682 isp_prt(isp, ISP_LOGERR, notresp,
3683 sp->req_header.rqs_entry_type, oop, optr,
3685 if (isp->isp_dblev & ISP_LOGDEBUG0) {
3686 isp_print_bytes(isp, "Queue Entry",
3689 MEMZERO(hp, QENTRY_LEN); /* PERF */
3695 if (sp->req_header.rqs_flags & 0xf) {
3696 #define _RQS_OFLAGS \
3697 ~(RQSFLAG_CONTINUATION|RQSFLAG_FULL|RQSFLAG_BADHEADER|RQSFLAG_BADPACKET)
3698 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
3699 isp_prt(isp, ISP_LOGWARN,
3700 "continuation segment");
3701 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3704 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3705 isp_prt(isp, ISP_LOGDEBUG1,
3706 "internal queues full");
3708 * We'll synthesize a QUEUE FULL message below.
3711 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
3712 isp_prt(isp, ISP_LOGERR, "bad header flag");
3715 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
3716 isp_prt(isp, ISP_LOGERR, "bad request packet");
3719 if (sp->req_header.rqs_flags & _RQS_OFLAGS) {
3720 isp_prt(isp, ISP_LOGERR,
3721 "unknown flags (0x%x) in response",
3722 sp->req_header.rqs_flags);
3727 if (sp->req_handle > isp->isp_maxcmds || sp->req_handle < 1) {
3728 MEMZERO(hp, QENTRY_LEN); /* PERF */
3729 isp_prt(isp, ISP_LOGERR,
3730 "bad request handle %d (type 0x%x, flags 0x%x)",
3731 sp->req_handle, sp->req_header.rqs_entry_type,
3732 sp->req_header.rqs_flags);
3733 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3736 xs = isp_find_xs(isp, sp->req_handle);
3738 u_int8_t ts = sp->req_completion_status & 0xff;
3739 MEMZERO(hp, QENTRY_LEN); /* PERF */
3741 * Only whine if this isn't the expected fallout of
3742 * aborting the command.
3744 if (sp->req_header.rqs_entry_type != RQSTYPE_RESPONSE) {
3745 isp_prt(isp, ISP_LOGERR,
3746 "cannot find handle 0x%x (type 0x%x)",
3748 sp->req_header.rqs_entry_type);
3749 } else if (ts != RQCS_ABORTED) {
3750 isp_prt(isp, ISP_LOGERR,
3751 "cannot find handle 0x%x (status 0x%x)",
3752 sp->req_handle, ts);
3754 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3757 isp_destroy_handle(isp, sp->req_handle);
3758 if (sp->req_status_flags & RQSTF_BUS_RESET) {
3759 XS_SETERR(xs, HBA_BUSRESET);
3760 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
3763 XS_SETERR(xs, HBA_BOTCH);
3766 if (IS_FC(isp) && (sp->req_scsi_status & RQCS_SV)) {
3768 * Fibre Channel F/W doesn't say we got status
3769 * if there's Sense Data instead. I guess they
3770 * think it goes w/o saying.
3772 sp->req_state_flags |= RQSF_GOT_STATUS;
3774 if (sp->req_state_flags & RQSF_GOT_STATUS) {
3775 *XS_STSP(xs) = sp->req_scsi_status & 0xff;
3778 switch (sp->req_header.rqs_entry_type) {
3779 case RQSTYPE_RESPONSE:
3780 XS_SET_STATE_STAT(isp, xs, sp);
3781 isp_parse_status(isp, sp, xs);
3782 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) &&
3783 (*XS_STSP(xs) == SCSI_BUSY)) {
3784 XS_SETERR(xs, HBA_TGTBSY);
3787 XS_RESID(xs) = sp->req_resid;
3788 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3789 (*XS_STSP(xs) == SCSI_CHECK) &&
3790 (sp->req_state_flags & RQSF_GOT_SENSE)) {
3791 XS_SAVE_SENSE(xs, sp);
3794 * A new synchronous rate was negotiated for
3795 * this target. Mark state such that we'll go
3796 * look up that which has changed later.
3798 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
3800 sdparam *sdp = isp->isp_param;
3801 sdp += XS_CHANNEL(xs);
3802 sdp->isp_devparam[t].dev_refresh = 1;
3804 (1 << XS_CHANNEL(xs));
3807 if (sp->req_status_flags & RQSF_XFER_COMPLETE) {
3809 } else if (sp->req_scsi_status & RQCS_RESID) {
3810 XS_RESID(xs) = sp->req_resid;
3814 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3815 (*XS_STSP(xs) == SCSI_CHECK) &&
3816 (sp->req_scsi_status & RQCS_SV)) {
3817 XS_SAVE_SENSE(xs, sp);
3818 /* solely for the benefit of debug */
3819 sp->req_state_flags |= RQSF_GOT_SENSE;
3822 isp_prt(isp, ISP_LOGDEBUG2,
3823 "asked for %ld got resid %ld", (long) XS_XFRLEN(xs),
3824 (long) sp->req_resid);
3826 case RQSTYPE_REQUEST:
3827 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3829 * Force Queue Full status.
3831 *XS_STSP(xs) = SCSI_QFULL;
3832 XS_SETERR(xs, HBA_NOERROR);
3833 } else if (XS_NOERR(xs)) {
3837 isp_prt(isp, ISP_LOGDEBUG0,
3838 "Request Queue Entry bounced back");
3839 XS_SETERR(xs, HBA_BOTCH);
3841 XS_RESID(xs) = XS_XFRLEN(xs);
3844 isp_prt(isp, ISP_LOGWARN,
3845 "unhandled response queue type 0x%x",
3846 sp->req_header.rqs_entry_type);
3848 XS_SETERR(xs, HBA_BOTCH);
3854 * Free any dma resources. As a side effect, this may
3855 * also do any cache flushing necessary for data coherence. */
3856 if (XS_XFRLEN(xs)) {
3857 ISP_DMAFREE(isp, xs, sp->req_handle);
3860 if (((isp->isp_dblev & (ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
3861 ((isp->isp_dblev & ISP_LOGDEBUG1) && ((!XS_NOERR(xs)) ||
3862 (*XS_STSP(xs) != SCSI_GOOD)))) {
3864 if (sp->req_state_flags & RQSF_GOT_SENSE) {
3865 skey = XS_SNSKEY(xs) & 0xf;
3870 } else if (*XS_STSP(xs) == SCSI_CHECK) {
3875 isp_prt(isp, ISP_LOGALL, finmsg, XS_CHANNEL(xs),
3876 XS_TGT(xs), XS_LUN(xs), XS_XFRLEN(xs), XS_RESID(xs),
3877 *XS_STSP(xs), skey, XS_ERR(xs));
3880 if (isp->isp_nactive > 0)
3882 complist[ndone++] = xs; /* defer completion call until later */
3883 MEMZERO(hp, QENTRY_LEN); /* PERF */
3884 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
3890 * If we looked at any commands, then it's valid to find out
3891 * what the outpointer is. It also is a trigger to update the
3892 * ISP's notion of what we've seen so far.
3895 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3897 * While we're at it, read the requst queue out pointer.
3899 isp->isp_reqodx = READ_REQUEST_QUEUE_OUT_POINTER(isp);
3900 if (isp->isp_rscchiwater < ndone)
3901 isp->isp_rscchiwater = ndone;
3904 isp->isp_residx = optr;
3905 isp->isp_rspbsy = 0;
3906 for (i = 0; i < ndone; i++) {
3909 isp->isp_rsltccmplt++;
3920 isp_parse_async(struct ispsoftc *isp, u_int16_t mbox)
3925 if (IS_DUALBUS(isp)) {
3926 bus = ISP_READ(isp, OUTMAILBOX6);
3930 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
3933 case ASYNC_BUS_RESET:
3934 isp->isp_sendmarker |= (1 << bus);
3935 #ifdef ISP_TARGET_MODE
3936 if (isp_target_async(isp, bus, mbox))
3939 isp_async(isp, ISPASYNC_BUS_RESET, &bus);
3941 case ASYNC_SYSTEM_ERROR:
3942 #ifdef ISP_FW_CRASH_DUMP
3944 * If we have crash dumps enabled, it's up to the handler
3945 * for isp_async to reinit stuff and restart the firmware
3946 * after performing the crash dump. The reason we do things
3947 * this way is that we may need to activate a kernel thread
3948 * to do all the crash dump goop.
3950 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
3952 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
3954 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
3959 case ASYNC_RQS_XFER_ERR:
3960 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
3963 case ASYNC_RSP_XFER_ERR:
3964 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
3969 * We've just been notified that the Queue has woken up.
3970 * We don't need to be chatty about this- just unlatch things
3973 mbox = READ_REQUEST_QUEUE_OUT_POINTER(isp);
3976 case ASYNC_TIMEOUT_RESET:
3977 isp_prt(isp, ISP_LOGWARN,
3978 "timeout initiated SCSI bus reset of bus %d", bus);
3979 isp->isp_sendmarker |= (1 << bus);
3980 #ifdef ISP_TARGET_MODE
3981 if (isp_target_async(isp, bus, mbox))
3986 case ASYNC_DEVICE_RESET:
3987 isp_prt(isp, ISP_LOGINFO, "device reset on bus %d", bus);
3988 isp->isp_sendmarker |= (1 << bus);
3989 #ifdef ISP_TARGET_MODE
3990 if (isp_target_async(isp, bus, mbox))
3995 case ASYNC_EXTMSG_UNDERRUN:
3996 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
3999 case ASYNC_SCAM_INT:
4000 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
4003 case ASYNC_HUNG_SCSI:
4004 isp_prt(isp, ISP_LOGERR,
4005 "stalled SCSI Bus after DATA Overrun");
4006 /* XXX: Need to issue SCSI reset at this point */
4009 case ASYNC_KILLED_BUS:
4010 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
4013 case ASYNC_BUS_TRANSIT:
4014 mbox = ISP_READ(isp, OUTMAILBOX2);
4015 switch (mbox & 0x1c00) {
4016 case SXP_PINS_LVD_MODE:
4017 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
4018 SDPARAM(isp)->isp_diffmode = 0;
4019 SDPARAM(isp)->isp_ultramode = 0;
4020 SDPARAM(isp)->isp_lvdmode = 1;
4022 case SXP_PINS_HVD_MODE:
4023 isp_prt(isp, ISP_LOGINFO,
4024 "Transition to Differential mode");
4025 SDPARAM(isp)->isp_diffmode = 1;
4026 SDPARAM(isp)->isp_ultramode = 0;
4027 SDPARAM(isp)->isp_lvdmode = 0;
4029 case SXP_PINS_SE_MODE:
4030 isp_prt(isp, ISP_LOGINFO,
4031 "Transition to Single Ended mode");
4032 SDPARAM(isp)->isp_diffmode = 0;
4033 SDPARAM(isp)->isp_ultramode = 1;
4034 SDPARAM(isp)->isp_lvdmode = 0;
4037 isp_prt(isp, ISP_LOGWARN,
4038 "Transition to Unknown Mode 0x%x", mbox);
4042 * XXX: Set up to renegotiate again!
4044 /* Can only be for a 1080... */
4045 isp->isp_sendmarker |= (1 << bus);
4049 * We can use bus, which will always be zero for FC cards,
4050 * as a mailbox pattern accumulator to be checked below.
4053 bus = 0x1ce; /* outgoing mailbox regs 1-3, 6-7 */
4057 bus = 0x14e; /* outgoing mailbox regs 1-3, 6 */
4061 bus = 0x10e; /* outgoing mailbox regs 1-3 */
4065 bus = 0x106; /* outgoing mailbox regs 1-2 */
4069 case ASYNC_CMD_CMPLT:
4070 bus = 0x102; /* outgoing mailbox regs 1 */
4073 case ASYNC_RIO_RESP:
4076 case ASYNC_CTIO_DONE:
4078 #ifdef ISP_TARGET_MODE
4080 (ISP_READ(isp, OUTMAILBOX2) << 16) |
4081 (ISP_READ(isp, OUTMAILBOX1));
4082 if (isp_target_async(isp, handle, mbox))
4085 isp_prt(isp, ISP_LOGINFO, "Fast Posting CTIO done");
4087 isp->isp_fphccmplt++; /* count it as a fast posting intr */
4091 case ASYNC_LIP_OCCURRED:
4092 FCPARAM(isp)->isp_lipseq =
4093 ISP_READ(isp, OUTMAILBOX1);
4094 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4095 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4096 isp->isp_sendmarker = 1;
4097 isp_mark_getpdb_all(isp);
4098 isp_async(isp, ISPASYNC_LIP, NULL);
4099 #ifdef ISP_TARGET_MODE
4100 if (isp_target_async(isp, bus, mbox))
4104 * We've had problems with data corruption occuring on
4105 * commands that complete (with no apparent error) after
4106 * we receive a LIP. This has been observed mostly on
4107 * Local Loop topologies. To be safe, let's just mark
4108 * all active commands as dead.
4110 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4111 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4113 for (i = j = 0; i < isp->isp_maxcmds; i++) {
4115 xs = isp->isp_xflist[i];
4118 XS_SETERR(xs, HBA_BUSRESET);
4122 isp_prt(isp, ISP_LOGERR,
4123 "LIP destroyed %d active commands", j);
4129 isp->isp_sendmarker = 1;
4130 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4131 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4132 isp_mark_getpdb_all(isp);
4133 isp_async(isp, ISPASYNC_LOOP_UP, NULL);
4134 #ifdef ISP_TARGET_MODE
4135 if (isp_target_async(isp, bus, mbox))
4140 case ASYNC_LOOP_DOWN:
4141 isp->isp_sendmarker = 1;
4142 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4143 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4144 isp_mark_getpdb_all(isp);
4145 isp_async(isp, ISPASYNC_LOOP_DOWN, NULL);
4146 #ifdef ISP_TARGET_MODE
4147 if (isp_target_async(isp, bus, mbox))
4152 case ASYNC_LOOP_RESET:
4153 isp->isp_sendmarker = 1;
4154 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4155 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4156 isp_mark_getpdb_all(isp);
4157 isp_async(isp, ISPASYNC_LOOP_RESET, NULL);
4158 #ifdef ISP_TARGET_MODE
4159 if (isp_target_async(isp, bus, mbox))
4164 case ASYNC_PDB_CHANGED:
4165 isp->isp_sendmarker = 1;
4166 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4167 isp_mark_getpdb_all(isp);
4168 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_PDB);
4171 case ASYNC_CHANGE_NOTIFY:
4173 * Not correct, but it will force us to rescan the loop.
4175 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4176 isp_mark_getpdb_all(isp);
4177 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_SNS);
4181 if (FCPARAM(isp)->isp_onfabric)
4182 FCPARAM(isp)->isp_topo = TOPO_F_PORT;
4184 FCPARAM(isp)->isp_topo = TOPO_N_PORT;
4185 isp_mark_getpdb_all(isp);
4186 isp->isp_sendmarker = 1;
4187 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4188 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4189 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4190 #ifdef ISP_TARGET_MODE
4191 if (isp_target_async(isp, bus, mbox))
4194 isp_prt(isp, ISP_LOGINFO, "Point-to-Point mode");
4197 case ASYNC_CONNMODE:
4198 mbox = ISP_READ(isp, OUTMAILBOX1);
4199 isp_mark_getpdb_all(isp);
4202 isp_prt(isp, ISP_LOGINFO,
4203 "Point-to-Point -> Loop mode");
4206 isp_prt(isp, ISP_LOGINFO,
4207 "Loop -> Point-to-Point mode");
4209 case ISP_CONN_BADLIP:
4210 isp_prt(isp, ISP_LOGWARN,
4211 "Point-to-Point -> Loop mode (BAD LIP)");
4213 case ISP_CONN_FATAL:
4214 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
4215 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4217 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4219 case ISP_CONN_LOOPBACK:
4220 isp_prt(isp, ISP_LOGWARN,
4221 "Looped Back in Point-to-Point mode");
4224 isp_prt(isp, ISP_LOGWARN,
4225 "Unknown connection mode (0x%x)", mbox);
4228 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4229 isp->isp_sendmarker = 1;
4230 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4231 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4235 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
4241 u_int16_t handles[5];
4243 for (nh = 0, i = 1; i < MAX_MAILBOX; i++) {
4244 if ((bus & (1 << i)) == 0) {
4247 handles[nh++] = ISP_READ(isp, MBOX_OFF(i));
4249 for (i = 0; i < nh; i++) {
4250 isp_fastpost_complete(isp, handles[i]);
4251 isp_prt(isp, ISP_LOGDEBUG3,
4252 "fast post completion of %u", handles[i]);
4254 if (isp->isp_fpcchiwater < nh)
4255 isp->isp_fpcchiwater = nh;
4257 isp->isp_intoasync++;
4263 * Handle other response entries. A pointer to the request queue output
4264 * index is here in case we want to eat several entries at once, although
4265 * this is not used currently.
4269 isp_handle_other_response(struct ispsoftc *isp, int type,
4270 isphdr_t *hp, u_int16_t *optrp)
4273 case RQSTYPE_STATUS_CONT:
4274 isp_prt(isp, ISP_LOGINFO, "Ignored Continuation Response");
4278 case RQSTYPE_ENABLE_LUN:
4279 case RQSTYPE_MODIFY_LUN:
4280 case RQSTYPE_NOTIFY:
4281 case RQSTYPE_NOTIFY_ACK:
4286 isp->isp_rsltccmplt++; /* count as a response completion */
4287 #ifdef ISP_TARGET_MODE
4288 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
4295 case RQSTYPE_REQUEST:
4297 if (isp_async(isp, ISPASYNC_UNHANDLED_RESPONSE, hp)) {
4300 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
4301 isp_get_response_type(isp, hp));
4307 isp_parse_status(struct ispsoftc *isp, ispstatusreq_t *sp, XS_T *xs)
4309 switch (sp->req_completion_status & 0xff) {
4312 XS_SETERR(xs, HBA_NOERROR);
4316 case RQCS_INCOMPLETE:
4317 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
4318 isp_prt(isp, ISP_LOGDEBUG1,
4319 "Selection Timeout for %d.%d.%d",
4320 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4322 XS_SETERR(xs, HBA_SELTIMEOUT);
4326 isp_prt(isp, ISP_LOGERR,
4327 "command incomplete for %d.%d.%d, state 0x%x",
4328 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
4329 sp->req_state_flags);
4332 case RQCS_DMA_ERROR:
4333 isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
4334 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4337 case RQCS_TRANSPORT_ERROR:
4340 SNPRINTF(buf, sizeof (buf), "states=>");
4341 if (sp->req_state_flags & RQSF_GOT_BUS) {
4342 SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
4344 if (sp->req_state_flags & RQSF_GOT_TARGET) {
4345 SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
4347 if (sp->req_state_flags & RQSF_SENT_CDB) {
4348 SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
4350 if (sp->req_state_flags & RQSF_XFRD_DATA) {
4351 SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
4353 if (sp->req_state_flags & RQSF_GOT_STATUS) {
4354 SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
4356 if (sp->req_state_flags & RQSF_GOT_SENSE) {
4357 SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
4359 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
4360 SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
4362 SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
4363 if (sp->req_status_flags & RQSTF_DISCONNECT) {
4364 SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
4366 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
4367 SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
4369 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
4370 SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
4372 if (sp->req_status_flags & RQSTF_BUS_RESET) {
4373 SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
4375 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
4376 SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
4378 if (sp->req_status_flags & RQSTF_ABORTED) {
4379 SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
4381 if (sp->req_status_flags & RQSTF_TIMEOUT) {
4382 SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
4384 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
4385 SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
4387 isp_prt(isp, ISP_LOGERR, "%s", buf);
4388 isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d:\n%s",
4389 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), buf);
4392 case RQCS_RESET_OCCURRED:
4393 isp_prt(isp, ISP_LOGWARN,
4394 "bus reset destroyed command for %d.%d.%d",
4395 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4396 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4398 XS_SETERR(xs, HBA_BUSRESET);
4403 isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
4404 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4405 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4407 XS_SETERR(xs, HBA_ABORTED);
4412 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
4413 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4415 * Check to see if we logged out the device.
4418 if ((sp->req_completion_status & RQSTF_LOGOUT) &&
4419 FCPARAM(isp)->portdb[XS_TGT(xs)].valid &&
4420 FCPARAM(isp)->portdb[XS_TGT(xs)].fabric_dev) {
4421 FCPARAM(isp)->portdb[XS_TGT(xs)].relogin = 1;
4425 XS_SETERR(xs, HBA_CMDTIMEOUT);
4429 case RQCS_DATA_OVERRUN:
4430 XS_RESID(xs) = sp->req_resid;
4431 isp_prt(isp, ISP_LOGERR, "data overrun for command on %d.%d.%d",
4432 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4434 XS_SETERR(xs, HBA_DATAOVR);
4438 case RQCS_COMMAND_OVERRUN:
4439 isp_prt(isp, ISP_LOGERR,
4440 "command overrun for command on %d.%d.%d",
4441 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4444 case RQCS_STATUS_OVERRUN:
4445 isp_prt(isp, ISP_LOGERR,
4446 "status overrun for command on %d.%d.%d",
4447 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4450 case RQCS_BAD_MESSAGE:
4451 isp_prt(isp, ISP_LOGERR,
4452 "msg not COMMAND COMPLETE after status %d.%d.%d",
4453 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4456 case RQCS_NO_MESSAGE_OUT:
4457 isp_prt(isp, ISP_LOGERR,
4458 "No MESSAGE OUT phase after selection on %d.%d.%d",
4459 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4462 case RQCS_EXT_ID_FAILED:
4463 isp_prt(isp, ISP_LOGERR, "EXTENDED IDENTIFY failed %d.%d.%d",
4464 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4467 case RQCS_IDE_MSG_FAILED:
4468 isp_prt(isp, ISP_LOGERR,
4469 "INITIATOR DETECTED ERROR rejected by %d.%d.%d",
4470 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4473 case RQCS_ABORT_MSG_FAILED:
4474 isp_prt(isp, ISP_LOGERR, "ABORT OPERATION rejected by %d.%d.%d",
4475 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4478 case RQCS_REJECT_MSG_FAILED:
4479 isp_prt(isp, ISP_LOGERR, "MESSAGE REJECT rejected by %d.%d.%d",
4480 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4483 case RQCS_NOP_MSG_FAILED:
4484 isp_prt(isp, ISP_LOGERR, "NOP rejected by %d.%d.%d",
4485 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4488 case RQCS_PARITY_ERROR_MSG_FAILED:
4489 isp_prt(isp, ISP_LOGERR,
4490 "MESSAGE PARITY ERROR rejected by %d.%d.%d",
4491 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4494 case RQCS_DEVICE_RESET_MSG_FAILED:
4495 isp_prt(isp, ISP_LOGWARN,
4496 "BUS DEVICE RESET rejected by %d.%d.%d",
4497 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4500 case RQCS_ID_MSG_FAILED:
4501 isp_prt(isp, ISP_LOGERR, "IDENTIFY rejected by %d.%d.%d",
4502 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4505 case RQCS_UNEXP_BUS_FREE:
4506 isp_prt(isp, ISP_LOGERR, "%d.%d.%d had an unexpected bus free",
4507 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4510 case RQCS_DATA_UNDERRUN:
4513 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
4514 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
4515 isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
4516 XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
4517 (ru_marked)? "marked" : "not marked");
4519 XS_SETERR(xs, HBA_BOTCH);
4524 XS_RESID(xs) = sp->req_resid;
4526 XS_SETERR(xs, HBA_NOERROR);
4531 case RQCS_XACT_ERR1:
4532 isp_prt(isp, ISP_LOGERR, xact1, XS_CHANNEL(xs),
4533 XS_TGT(xs), XS_LUN(xs));
4536 case RQCS_XACT_ERR2:
4537 isp_prt(isp, ISP_LOGERR, xact2,
4538 XS_LUN(xs), XS_TGT(xs), XS_CHANNEL(xs));
4541 case RQCS_XACT_ERR3:
4542 isp_prt(isp, ISP_LOGERR, xact3,
4543 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4546 case RQCS_BAD_ENTRY:
4547 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
4550 case RQCS_QUEUE_FULL:
4551 isp_prt(isp, ISP_LOGDEBUG0,
4552 "internal queues full for %d.%d.%d status 0x%x",
4553 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), *XS_STSP(xs));
4556 * If QFULL or some other status byte is set, then this
4557 * isn't an error, per se.
4559 * Unfortunately, some QLogic f/w writers have, in
4560 * some cases, ommitted to *set* status to QFULL.
4563 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
4564 XS_SETERR(xs, HBA_NOERROR);
4572 *XS_STSP(xs) = SCSI_QFULL;
4573 XS_SETERR(xs, HBA_NOERROR);
4576 case RQCS_PHASE_SKIPPED:
4577 isp_prt(isp, ISP_LOGERR, pskip, XS_CHANNEL(xs),
4578 XS_TGT(xs), XS_LUN(xs));
4581 case RQCS_ARQS_FAILED:
4582 isp_prt(isp, ISP_LOGERR,
4583 "Auto Request Sense failed for %d.%d.%d",
4584 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4586 XS_SETERR(xs, HBA_ARQFAIL);
4590 case RQCS_WIDE_FAILED:
4591 isp_prt(isp, ISP_LOGERR,
4592 "Wide Negotiation failed for %d.%d.%d",
4593 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4595 sdparam *sdp = isp->isp_param;
4596 sdp += XS_CHANNEL(xs);
4597 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
4598 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4599 isp->isp_update |= (1 << XS_CHANNEL(xs));
4602 XS_SETERR(xs, HBA_NOERROR);
4606 case RQCS_SYNCXFER_FAILED:
4607 isp_prt(isp, ISP_LOGERR,
4608 "SDTR Message failed for target %d.%d.%d",
4609 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4611 sdparam *sdp = isp->isp_param;
4612 sdp += XS_CHANNEL(xs);
4613 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
4614 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4615 isp->isp_update |= (1 << XS_CHANNEL(xs));
4619 case RQCS_LVD_BUSERR:
4620 isp_prt(isp, ISP_LOGERR,
4621 "Bad LVD condition while talking to %d.%d.%d",
4622 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4625 case RQCS_PORT_UNAVAILABLE:
4627 * No such port on the loop. Moral equivalent of SELTIMEO
4629 case RQCS_PORT_LOGGED_OUT:
4631 * It was there (maybe)- treat as a selection timeout.
4633 if ((sp->req_completion_status & 0xff) == RQCS_PORT_UNAVAILABLE)
4634 isp_prt(isp, ISP_LOGINFO,
4635 "port unavailable for target %d", XS_TGT(xs));
4637 isp_prt(isp, ISP_LOGINFO,
4638 "port logout for target %d", XS_TGT(xs));
4640 * If we're on a local loop, force a LIP (which is overkill)
4641 * to force a re-login of this unit. If we're on fabric,
4642 * then we'll have to relogin as a matter of course.
4644 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4645 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4647 mbs.param[0] = MBOX_INIT_LIP;
4648 isp_mboxcmd_qnw(isp, &mbs, 1);
4652 * Probably overkill.
4654 isp->isp_sendmarker = 1;
4655 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4656 isp_mark_getpdb_all(isp);
4657 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4659 XS_SETERR(xs, HBA_SELTIMEOUT);
4663 case RQCS_PORT_CHANGED:
4664 isp_prt(isp, ISP_LOGWARN,
4665 "port changed for target %d", XS_TGT(xs));
4667 XS_SETERR(xs, HBA_SELTIMEOUT);
4671 case RQCS_PORT_BUSY:
4672 isp_prt(isp, ISP_LOGWARN,
4673 "port busy for target %d", XS_TGT(xs));
4675 XS_SETERR(xs, HBA_TGTBSY);
4680 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x",
4681 sp->req_completion_status);
4685 XS_SETERR(xs, HBA_BOTCH);
4690 isp_fastpost_complete(struct ispsoftc *isp, u_int16_t fph)
4697 xs = isp_find_xs(isp, fph);
4699 isp_prt(isp, ISP_LOGWARN,
4700 "Command for fast post handle 0x%x not found", fph);
4703 isp_destroy_handle(isp, fph);
4706 * Since we don't have a result queue entry item,
4707 * we must believe that SCSI status is zero and
4708 * that all data transferred.
4710 XS_SET_STATE_STAT(isp, xs, NULL);
4712 *XS_STSP(xs) = SCSI_GOOD;
4713 if (XS_XFRLEN(xs)) {
4714 ISP_DMAFREE(isp, xs, fph);
4716 if (isp->isp_nactive)
4718 isp->isp_fphccmplt++;
4723 isp_mbox_continue(struct ispsoftc *isp)
4728 switch (isp->isp_lastmbxcmd) {
4729 case MBOX_WRITE_RAM_WORD:
4730 case MBOX_READ_RAM_WORD:
4731 case MBOX_READ_RAM_WORD_EXTENDED:
4736 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
4737 isp->isp_mbxwrk0 = 0;
4743 * Clear the previous interrupt.
4745 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
4746 ISP_WRITE(isp, BIU_SEMA, 0);
4749 * Continue with next word.
4751 ptr = isp->isp_mbxworkp;
4752 switch (isp->isp_lastmbxcmd) {
4753 case MBOX_WRITE_RAM_WORD:
4754 mbs.param[2] = *ptr++;
4755 mbs.param[1] = isp->isp_mbxwrk1++;
4757 case MBOX_READ_RAM_WORD:
4758 case MBOX_READ_RAM_WORD_EXTENDED:
4759 *ptr++ = isp->isp_mboxtmp[2];
4760 mbs.param[1] = isp->isp_mbxwrk1++;
4763 isp->isp_mbxworkp = ptr;
4764 mbs.param[0] = isp->isp_lastmbxcmd;
4765 isp->isp_mbxwrk0 -= 1;
4766 isp_mboxcmd_qnw(isp, &mbs, 0);
4771 #define HIBYT(x) ((x) >> 0x8)
4772 #define LOBYT(x) ((x) & 0xff)
4773 #define ISPOPMAP(a, b) (((a) << 8) | (b))
4774 static u_int16_t mbpscsi[] = {
4775 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
4776 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
4777 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
4778 ISPOPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
4779 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
4780 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
4781 ISPOPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
4782 ISPOPMAP(0x03, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
4783 ISPOPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
4784 ISPOPMAP(0x00, 0x00), /* 0x09: */
4785 ISPOPMAP(0x00, 0x00), /* 0x0a: */
4786 ISPOPMAP(0x00, 0x00), /* 0x0b: */
4787 ISPOPMAP(0x00, 0x00), /* 0x0c: */
4788 ISPOPMAP(0x00, 0x00), /* 0x0d: */
4789 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
4790 ISPOPMAP(0x00, 0x00), /* 0x0f: */
4791 ISPOPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
4792 ISPOPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
4793 ISPOPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
4794 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
4795 ISPOPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
4796 ISPOPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
4797 ISPOPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
4798 ISPOPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
4799 ISPOPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
4800 ISPOPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
4801 ISPOPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
4802 ISPOPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
4803 ISPOPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
4804 ISPOPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
4805 ISPOPMAP(0x00, 0x00), /* 0x1e: */
4806 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
4807 ISPOPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
4808 ISPOPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
4809 ISPOPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
4810 ISPOPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
4811 ISPOPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
4812 ISPOPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
4813 ISPOPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
4814 ISPOPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
4815 ISPOPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
4816 ISPOPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
4817 ISPOPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
4818 ISPOPMAP(0x00, 0x00), /* 0x2b: */
4819 ISPOPMAP(0x00, 0x00), /* 0x2c: */
4820 ISPOPMAP(0x00, 0x00), /* 0x2d: */
4821 ISPOPMAP(0x00, 0x00), /* 0x2e: */
4822 ISPOPMAP(0x00, 0x00), /* 0x2f: */
4823 ISPOPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
4824 ISPOPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
4825 ISPOPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
4826 ISPOPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
4827 ISPOPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
4828 ISPOPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
4829 ISPOPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
4830 ISPOPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
4831 ISPOPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
4832 ISPOPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
4833 ISPOPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
4834 ISPOPMAP(0x00, 0x00), /* 0x3b: */
4835 ISPOPMAP(0x00, 0x00), /* 0x3c: */
4836 ISPOPMAP(0x00, 0x00), /* 0x3d: */
4837 ISPOPMAP(0x00, 0x00), /* 0x3e: */
4838 ISPOPMAP(0x00, 0x00), /* 0x3f: */
4839 ISPOPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
4840 ISPOPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
4841 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
4842 ISPOPMAP(0x00, 0x00), /* 0x43: */
4843 ISPOPMAP(0x00, 0x00), /* 0x44: */
4844 ISPOPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
4845 ISPOPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
4846 ISPOPMAP(0x00, 0x00), /* 0x47: */
4847 ISPOPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
4848 ISPOPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
4849 ISPOPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
4850 ISPOPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
4851 ISPOPMAP(0x00, 0x00), /* 0x4c: */
4852 ISPOPMAP(0x00, 0x00), /* 0x4d: */
4853 ISPOPMAP(0x00, 0x00), /* 0x4e: */
4854 ISPOPMAP(0x00, 0x00), /* 0x4f: */
4855 ISPOPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
4856 ISPOPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
4857 ISPOPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
4858 ISPOPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
4859 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
4860 ISPOPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
4861 ISPOPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
4862 ISPOPMAP(0x00, 0x00), /* 0x57: */
4863 ISPOPMAP(0x00, 0x00), /* 0x58: */
4864 ISPOPMAP(0x00, 0x00), /* 0x59: */
4865 ISPOPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
4866 ISPOPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
4867 ISPOPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
4868 ISPOPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
4871 #ifndef ISP_STRIPPED
4872 static char *scsi_mbcmd_names[] = {
4889 "INIT REQUEST QUEUE",
4890 "INIT RESULT QUEUE",
4900 "SINGLE STEP QUEUE",
4902 "GET DEV QUEUE STATUS",
4904 "GET FIRMWARE STATUS",
4906 "GET SELECT TIMEOUT",
4908 "GET TAG AGE LIMIT",
4910 "GET ACT NEG STATE",
4911 "GET ASYNC DATA SETUP TIME",
4913 "GET TARGET PARAMS",
4914 "GET DEV QUEUE PARAMS",
4915 "GET RESET DELAY PARAMS",
4922 "SET SELECT TIMEOUT",
4924 "SET TAG AGE LIMIT",
4926 "SET ACT NEG STATE",
4927 "SET ASYNC DATA SETUP TIME",
4928 "SET PCI CONTROL PARAMS",
4929 "SET TARGET PARAMS",
4930 "SET DEV QUEUE PARAMS",
4931 "SET RESET DELAY PARAMS",
4937 "RETURN BIOS BLOCK ADDR",
4938 "WRITE FOUR RAM WORDS",
4942 "SET SYSTEM PARAMETER",
4943 "GET SYSTEM PARAMETER",
4945 "GET SCAM CONFIGURATION",
4946 "SET SCAM CONFIGURATION",
4947 "SET FIRMWARE FEATURES",
4948 "GET FIRMWARE FEATURES",
4955 "INITIALIZE REQUEST QUEUE A64",
4956 "INITIALIZE RESPONSE QUEUE A64",
4958 "ENABLE TARGET MODE",
4959 "GET TARGET MODE STATE",
4963 "SET DATA OVERRUN RECOVERY MODE",
4964 "GET DATA OVERRUN RECOVERY MODE",
4970 static u_int16_t mbpfc[] = {
4971 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
4972 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
4973 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
4974 ISPOPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
4975 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
4976 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
4977 ISPOPMAP(0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
4978 ISPOPMAP(0x03, 0x05), /* 0x07: MBOX_VERIFY_CHECKSUM */
4979 ISPOPMAP(0x01, 0x4f), /* 0x08: MBOX_ABOUT_FIRMWARE */
4980 ISPOPMAP(0xdf, 0x01), /* 0x09: LOAD RAM */
4981 ISPOPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
4982 ISPOPMAP(0x00, 0x00), /* 0x0b: */
4983 ISPOPMAP(0x00, 0x00), /* 0x0c: */
4984 ISPOPMAP(0x00, 0x00), /* 0x0d: */
4985 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
4986 ISPOPMAP(0x03, 0x07), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED(1) */
4987 ISPOPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
4988 ISPOPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
4989 ISPOPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
4990 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
4991 ISPOPMAP(0x01, 0xff), /* 0x14: MBOX_STOP_FIRMWARE */
4992 ISPOPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
4993 ISPOPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
4994 ISPOPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
4995 ISPOPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
4996 ISPOPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
4997 ISPOPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
4998 ISPOPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
4999 ISPOPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
5000 ISPOPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
5001 ISPOPMAP(0x00, 0x00), /* 0x1e: */
5002 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
5003 ISPOPMAP(0x01, 0x4f), /* 0x20: MBOX_GET_LOOP_ID */
5004 ISPOPMAP(0x00, 0x00), /* 0x21: */
5005 ISPOPMAP(0x01, 0x07), /* 0x22: MBOX_GET_RETRY_COUNT */
5006 ISPOPMAP(0x00, 0x00), /* 0x23: */
5007 ISPOPMAP(0x00, 0x00), /* 0x24: */
5008 ISPOPMAP(0x00, 0x00), /* 0x25: */
5009 ISPOPMAP(0x00, 0x00), /* 0x26: */
5010 ISPOPMAP(0x00, 0x00), /* 0x27: */
5011 ISPOPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
5012 ISPOPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
5013 ISPOPMAP(0x00, 0x00), /* 0x2a: */
5014 ISPOPMAP(0x00, 0x00), /* 0x2b: */
5015 ISPOPMAP(0x00, 0x00), /* 0x2c: */
5016 ISPOPMAP(0x00, 0x00), /* 0x2d: */
5017 ISPOPMAP(0x00, 0x00), /* 0x2e: */
5018 ISPOPMAP(0x00, 0x00), /* 0x2f: */
5019 ISPOPMAP(0x00, 0x00), /* 0x30: */
5020 ISPOPMAP(0x00, 0x00), /* 0x31: */
5021 ISPOPMAP(0x07, 0x07), /* 0x32: MBOX_SET_RETRY_COUNT */
5022 ISPOPMAP(0x00, 0x00), /* 0x33: */
5023 ISPOPMAP(0x00, 0x00), /* 0x34: */
5024 ISPOPMAP(0x00, 0x00), /* 0x35: */
5025 ISPOPMAP(0x00, 0x00), /* 0x36: */
5026 ISPOPMAP(0x00, 0x00), /* 0x37: */
5027 ISPOPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
5028 ISPOPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
5029 ISPOPMAP(0x00, 0x00), /* 0x3a: */
5030 ISPOPMAP(0x00, 0x00), /* 0x3b: */
5031 ISPOPMAP(0x00, 0x00), /* 0x3c: */
5032 ISPOPMAP(0x00, 0x00), /* 0x3d: */
5033 ISPOPMAP(0x00, 0x00), /* 0x3e: */
5034 ISPOPMAP(0x00, 0x00), /* 0x3f: */
5035 ISPOPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
5036 ISPOPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
5037 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_GET_RESOURCE_COUNTS */
5038 ISPOPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_NON_PARTICIPATING_MODE */
5039 ISPOPMAP(0x00, 0x00), /* 0x44: */
5040 ISPOPMAP(0x00, 0x00), /* 0x45: */
5041 ISPOPMAP(0x00, 0x00), /* 0x46: */
5042 ISPOPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
5043 ISPOPMAP(0x00, 0x00), /* 0x48: */
5044 ISPOPMAP(0x00, 0x00), /* 0x49: */
5045 ISPOPMAP(0x00, 0x00), /* 0x4a: */
5046 ISPOPMAP(0x00, 0x00), /* 0x4b: */
5047 ISPOPMAP(0x00, 0x00), /* 0x4c: */
5048 ISPOPMAP(0x00, 0x00), /* 0x4d: */
5049 ISPOPMAP(0x00, 0x00), /* 0x4e: */
5050 ISPOPMAP(0x00, 0x00), /* 0x4f: */
5051 ISPOPMAP(0x00, 0x00), /* 0x50: */
5052 ISPOPMAP(0x00, 0x00), /* 0x51: */
5053 ISPOPMAP(0x00, 0x00), /* 0x52: */
5054 ISPOPMAP(0x00, 0x00), /* 0x53: */
5055 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
5056 ISPOPMAP(0x00, 0x00), /* 0x55: */
5057 ISPOPMAP(0x00, 0x00), /* 0x56: */
5058 ISPOPMAP(0x00, 0x00), /* 0x57: */
5059 ISPOPMAP(0x00, 0x00), /* 0x58: */
5060 ISPOPMAP(0x00, 0x00), /* 0x59: */
5061 ISPOPMAP(0x00, 0x00), /* 0x5a: */
5062 ISPOPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
5063 ISPOPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
5064 ISPOPMAP(0x07, 0x03), /* 0x5d: MBOX_GET_SET_DATA_RATE */
5065 ISPOPMAP(0x00, 0x00), /* 0x5e: */
5066 ISPOPMAP(0x00, 0x00), /* 0x5f: */
5067 ISPOPMAP(0xfd, 0x31), /* 0x60: MBOX_INIT_FIRMWARE */
5068 ISPOPMAP(0x00, 0x00), /* 0x61: */
5069 ISPOPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
5070 ISPOPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
5071 ISPOPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
5072 ISPOPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
5073 ISPOPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
5074 ISPOPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
5075 ISPOPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
5076 ISPOPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
5077 ISPOPMAP(0x03, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
5078 ISPOPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
5079 ISPOPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
5080 ISPOPMAP(0x00, 0x00), /* 0x6d: */
5081 ISPOPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
5082 ISPOPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
5083 ISPOPMAP(0x03, 0x01), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
5084 ISPOPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
5085 ISPOPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
5086 ISPOPMAP(0x00, 0x00), /* 0x73: */
5087 ISPOPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
5088 ISPOPMAP(0xcf, 0x03), /* 0x75: GET PORT/NODE NAME LIST */
5089 ISPOPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
5090 ISPOPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
5091 ISPOPMAP(0x00, 0x00), /* 0x78: */
5092 ISPOPMAP(0x00, 0x00), /* 0x79: */
5093 ISPOPMAP(0x00, 0x00), /* 0x7a: */
5094 ISPOPMAP(0x00, 0x00), /* 0x7b: */
5095 ISPOPMAP(0x4f, 0x03), /* 0x7c: Get ID List */
5096 ISPOPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
5097 ISPOPMAP(0x07, 0x01) /* 0x7e: Lun RESET */
5102 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
5103 * do not access at this time in the core driver. The caller is
5104 * responsible for setting this register first (Gross!).
5107 #ifndef ISP_STRIPPED
5108 static char *fc_mbcmd_names[] = {
5122 "READ RAM WORD EXTENDED",
5125 "INIT REQUEST QUEUE",
5126 "INIT RESULT QUEUE",
5136 "SINGLE STEP QUEUE",
5138 "GET DEV QUEUE STATUS",
5140 "GET FIRMWARE STATUS",
5149 "GET FIRMWARE OPTIONS",
5150 "GET PORT QUEUE PARAMS",
5165 "SET FIRMWARE OPTIONS",
5166 "SET PORT QUEUE PARAMS",
5175 "GET RESOURCE COUNTS",
5176 "REQUEST NON PARTICIPATING MODE",
5180 "GET PORT DATABASE,, ENHANCED",
5202 "GET/SET DATA RATE",
5208 "GET FC-AL POSITION MAP",
5209 "GET PORT DATABASE",
5221 "SEND CHANGE REQUEST",
5226 "GET PORT/NODE NAME LIST",
5228 "INITIALIZE IP MAILBOX",
5240 isp_mboxcmd_qnw(struct ispsoftc *isp, mbreg_t *mbp, int nodelay)
5242 unsigned int lim, ibits, obits, box, opcode;
5250 lim = NELEM(mbpscsi);
5252 opcode = mbp->param[0];
5253 ibits = HIBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5254 obits = LOBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5255 for (box = 0; box < MAX_MAILBOX; box++) {
5256 if (ibits & (1 << box)) {
5257 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5260 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5264 isp->isp_lastmbxcmd = opcode;
5265 isp->isp_obits = obits;
5266 isp->isp_mboxbsy = 1;
5268 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5270 * Oddly enough, if we're not delaying for an answer,
5271 * delay a bit to give the f/w a chance to pick up the
5280 isp_mboxcmd(struct ispsoftc *isp, mbreg_t *mbp, int logmask)
5282 char *cname, *xname, tname[16], mname[16];
5283 unsigned int lim, ibits, obits, box, opcode;
5291 lim = NELEM(mbpscsi);
5294 if ((opcode = mbp->param[0]) >= lim) {
5295 mbp->param[0] = MBOX_INVALID_COMMAND;
5296 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
5300 ibits = HIBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5301 obits = LOBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5303 if (ibits == 0 && obits == 0) {
5304 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
5305 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
5310 * Get exclusive usage of mailbox registers.
5314 for (box = 0; box < MAX_MAILBOX; box++) {
5315 if (ibits & (1 << box)) {
5316 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5318 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5321 isp->isp_lastmbxcmd = opcode;
5324 * We assume that we can't overwrite a previous command.
5326 isp->isp_obits = obits;
5327 isp->isp_mboxbsy = 1;
5330 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
5332 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5335 * While we haven't finished the command, spin our wheels here.
5337 MBOX_WAIT_COMPLETE(isp);
5339 if (isp->isp_mboxbsy) {
5341 * Command timed out.
5343 isp->isp_mboxbsy = 0;
5349 * Copy back output registers.
5351 for (box = 0; box < MAX_MAILBOX; box++) {
5352 if (obits & (1 << box)) {
5353 mbp->param[box] = isp->isp_mboxtmp[box];
5359 if (logmask == 0 || opcode == MBOX_EXEC_FIRMWARE) {
5365 cname = (IS_FC(isp))? fc_mbcmd_names[opcode] : scsi_mbcmd_names[opcode];
5367 if (cname == NULL) {
5369 SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
5373 * Just to be chatty here...
5376 switch (mbp->param[0]) {
5377 case MBOX_COMMAND_COMPLETE:
5379 case MBOX_INVALID_COMMAND:
5380 if (logmask & MBLOGMASK(MBOX_COMMAND_COMPLETE))
5381 xname = "INVALID COMMAND";
5383 case MBOX_HOST_INTERFACE_ERROR:
5384 if (logmask & MBLOGMASK(MBOX_HOST_INTERFACE_ERROR))
5385 xname = "HOST INTERFACE ERROR";
5387 case MBOX_TEST_FAILED:
5388 if (logmask & MBLOGMASK(MBOX_TEST_FAILED))
5389 xname = "TEST FAILED";
5391 case MBOX_COMMAND_ERROR:
5392 if (logmask & MBLOGMASK(MBOX_COMMAND_ERROR))
5393 xname = "COMMAND ERROR";
5395 case MBOX_COMMAND_PARAM_ERROR:
5396 if (logmask & MBLOGMASK(MBOX_COMMAND_PARAM_ERROR))
5397 xname = "COMMAND PARAMETER ERROR";
5399 case MBOX_LOOP_ID_USED:
5400 if (logmask & MBLOGMASK(MBOX_LOOP_ID_USED))
5401 xname = "LOOP ID ALREADY IN USE";
5403 case MBOX_PORT_ID_USED:
5404 if (logmask & MBLOGMASK(MBOX_PORT_ID_USED))
5405 xname = "PORT ID ALREADY IN USE";
5407 case MBOX_ALL_IDS_USED:
5408 if (logmask & MBLOGMASK(MBOX_ALL_IDS_USED))
5409 xname = "ALL LOOP IDS IN USE";
5411 case 0: /* special case */
5415 SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
5420 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s)",
5425 isp_fw_state(struct ispsoftc *isp)
5429 fcparam *fcp = isp->isp_param;
5431 mbs.param[0] = MBOX_GET_FW_STATE;
5432 isp_mboxcmd(isp, &mbs, MBLOGALL);
5433 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
5434 fcp->isp_fwstate = mbs.param[1];
5440 isp_update(struct ispsoftc *isp)
5444 for (bus = 0, upmask = isp->isp_update; upmask != 0; bus++) {
5445 if (upmask & (1 << bus)) {
5446 isp_update_bus(isp, bus);
5448 upmask &= ~(1 << bus);
5453 isp_update_bus(struct ispsoftc *isp, int bus)
5459 isp->isp_update &= ~(1 << bus);
5462 * There are no 'per-bus' settings for Fibre Channel.
5466 sdp = isp->isp_param;
5469 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5470 u_int16_t flags, period, offset;
5473 if (sdp->isp_devparam[tgt].dev_enable == 0) {
5474 sdp->isp_devparam[tgt].dev_update = 0;
5475 sdp->isp_devparam[tgt].dev_refresh = 0;
5476 isp_prt(isp, ISP_LOGDEBUG0,
5477 "skipping target %d bus %d update", tgt, bus);
5481 * If the goal is to update the status of the device,
5482 * take what's in goal_flags and try and set the device
5483 * toward that. Otherwise, if we're just refreshing the
5484 * current device state, get the current parameters.
5488 * Refresh overrides set
5490 if (sdp->isp_devparam[tgt].dev_refresh) {
5491 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
5492 sdp->isp_devparam[tgt].dev_refresh = 0;
5494 } else if (sdp->isp_devparam[tgt].dev_update) {
5495 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
5497 * Make sure goal_flags has "Renegotiate on Error"
5498 * on and "Freeze Queue on Error" off.
5500 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
5501 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
5503 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
5506 * Insist that PARITY must be enabled
5507 * if SYNC or WIDE is enabled.
5509 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
5510 mbs.param[2] |= DPARM_PARITY;
5513 if ((mbs.param[2] & DPARM_SYNC) == 0) {
5517 (sdp->isp_devparam[tgt].goal_offset << 8) |
5518 (sdp->isp_devparam[tgt].goal_period);
5521 * A command completion later that has
5522 * RQSTF_NEGOTIATION set can cause
5523 * the dev_refresh/announce cycle also.
5525 * Note: It is really important to update our current
5526 * flags with at least the state of TAG capabilities-
5527 * otherwise we might try and send a tagged command
5528 * when we have it all turned off. So change it here
5529 * to say that current already matches goal.
5531 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
5532 sdp->isp_devparam[tgt].actv_flags |=
5533 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
5534 isp_prt(isp, ISP_LOGDEBUG0,
5535 "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
5536 bus, tgt, mbs.param[2], mbs.param[3] >> 8,
5537 mbs.param[3] & 0xff);
5538 sdp->isp_devparam[tgt].dev_update = 0;
5539 sdp->isp_devparam[tgt].dev_refresh = 1;
5544 mbs.param[1] = (bus << 15) | (tgt << 8);
5545 isp_mboxcmd(isp, &mbs, MBLOGALL);
5547 isp->isp_sendmarker |= (1 << bus);
5550 flags = mbs.param[2];
5551 period = mbs.param[3] & 0xff;
5552 offset = mbs.param[3] >> 8;
5553 sdp->isp_devparam[tgt].actv_flags = flags;
5554 sdp->isp_devparam[tgt].actv_period = period;
5555 sdp->isp_devparam[tgt].actv_offset = offset;
5556 get = (bus << 16) | tgt;
5557 (void) isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, &get);
5560 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5561 if (sdp->isp_devparam[tgt].dev_update ||
5562 sdp->isp_devparam[tgt].dev_refresh) {
5563 isp->isp_update |= (1 << bus);
5569 #ifndef DEFAULT_FRAMESIZE
5570 #define DEFAULT_FRAMESIZE(isp) ICB_DFLT_FRMLEN
5572 #ifndef DEFAULT_EXEC_THROTTLE
5573 #define DEFAULT_EXEC_THROTTLE(isp) ISP_EXEC_THROTTLE
5577 isp_setdfltparm(struct ispsoftc *isp, int channel)
5584 fcparam *fcp = (fcparam *) isp->isp_param;
5588 if (fcp->isp_gotdparms) {
5591 fcp->isp_gotdparms = 1;
5592 fcp->isp_maxfrmlen = DEFAULT_FRAMESIZE(isp);
5593 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
5594 fcp->isp_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
5595 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
5596 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
5597 /* Platform specific.... */
5598 fcp->isp_loopid = DEFAULT_LOOPID(isp);
5599 fcp->isp_nodewwn = DEFAULT_NODEWWN(isp);
5600 fcp->isp_portwwn = DEFAULT_PORTWWN(isp);
5601 fcp->isp_fwoptions = 0;
5602 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
5603 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
5604 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
5605 #ifndef ISP_NO_FASTPOST_FC
5606 fcp->isp_fwoptions |= ICBOPT_FAST_POST;
5608 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
5609 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
5612 * Make sure this is turned off now until we get
5613 * extended options from NVRAM
5615 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
5618 * Now try and read NVRAM unless told to not do so.
5619 * This will set fcparam's isp_nodewwn && isp_portwwn.
5621 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5622 nvfail = isp_read_nvram(isp);
5624 isp->isp_confopts |= ISP_CFG_NONVRAM;
5629 * Set node && port to override platform set defaults
5630 * unless the nvram read failed (or none was done),
5631 * or the platform code wants to use what had been
5632 * set in the defaults.
5635 isp->isp_confopts |= ISP_CFG_OWNWWPN|ISP_CFG_OWNWWNN;
5637 if (isp->isp_confopts & ISP_CFG_OWNWWNN) {
5638 isp_prt(isp, ISP_LOGCONFIG, "Using Node WWN 0x%08x%08x",
5639 (u_int32_t) (DEFAULT_NODEWWN(isp) >> 32),
5640 (u_int32_t) (DEFAULT_NODEWWN(isp) & 0xffffffff));
5641 ISP_NODEWWN(isp) = DEFAULT_NODEWWN(isp);
5644 * We always start out with values derived
5645 * from NVRAM or our platform default.
5647 ISP_NODEWWN(isp) = fcp->isp_nodewwn;
5649 if (isp->isp_confopts & ISP_CFG_OWNWWPN) {
5650 isp_prt(isp, ISP_LOGCONFIG, "Using Port WWN 0x%08x%08x",
5651 (u_int32_t) (DEFAULT_PORTWWN(isp) >> 32),
5652 (u_int32_t) (DEFAULT_PORTWWN(isp) & 0xffffffff));
5653 ISP_PORTWWN(isp) = DEFAULT_PORTWWN(isp);
5656 * We always start out with values derived
5657 * from NVRAM or our platform default.
5659 ISP_PORTWWN(isp) = fcp->isp_portwwn;
5664 sdp = (sdparam *) isp->isp_param;
5668 * Been there, done that, got the T-shirt...
5670 if (sdp->isp_gotdparms) {
5673 sdp->isp_gotdparms = 1;
5676 * Establish some default parameters.
5678 sdp->isp_cmd_dma_burst_enable = 0;
5679 sdp->isp_data_dma_burst_enabl = 1;
5680 sdp->isp_fifo_threshold = 0;
5681 sdp->isp_initiator_id = DEFAULT_IID(isp);
5682 if (isp->isp_type >= ISP_HA_SCSI_1040) {
5683 sdp->isp_async_data_setup = 9;
5685 sdp->isp_async_data_setup = 6;
5687 sdp->isp_selection_timeout = 250;
5688 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
5689 sdp->isp_tag_aging = 8;
5690 sdp->isp_bus_reset_delay = 5;
5692 * Don't retry selection, busy or queue full automatically- reflect
5695 sdp->isp_retry_count = 0;
5696 sdp->isp_retry_delay = 0;
5698 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5699 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
5700 sdp->isp_devparam[tgt].dev_enable = 1;
5704 * If we've not been told to avoid reading NVRAM, try and read it.
5705 * If we're successful reading it, we can then return because NVRAM
5706 * will tell us what the desired settings are. Otherwise, we establish
5707 * some reasonable 'fake' nvram and goal defaults.
5710 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5711 if (isp_read_nvram(isp) == 0) {
5717 * Now try and see whether we have specific values for them.
5719 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5720 mbs.param[0] = MBOX_GET_ACT_NEG_STATE;
5721 isp_mboxcmd(isp, &mbs, MBLOGNONE);
5722 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
5723 sdp->isp_req_ack_active_neg = 1;
5724 sdp->isp_data_line_active_neg = 1;
5726 sdp->isp_req_ack_active_neg =
5727 (mbs.param[1+channel] >> 4) & 0x1;
5728 sdp->isp_data_line_active_neg =
5729 (mbs.param[1+channel] >> 5) & 0x1;
5733 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc3,
5734 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
5735 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
5736 sdp->isp_retry_delay, sdp->isp_async_data_setup);
5737 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc3,
5738 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
5739 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
5740 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
5743 * The trick here is to establish a default for the default (honk!)
5744 * state (goal_flags). Then try and get the current status from
5745 * the card to fill in the current state. We don't, in fact, set
5746 * the default to the SAFE default state- that's not the goal state.
5748 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5750 sdp->isp_devparam[tgt].actv_offset = 0;
5751 sdp->isp_devparam[tgt].actv_period = 0;
5752 sdp->isp_devparam[tgt].actv_flags = 0;
5754 sdp->isp_devparam[tgt].goal_flags =
5755 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
5758 * We default to Wide/Fast for versions less than a 1040
5759 * (unless it's SBus).
5761 if (IS_ULTRA3(isp)) {
5762 off = ISP_80M_SYNCPARMS >> 8;
5763 per = ISP_80M_SYNCPARMS & 0xff;
5764 } else if (IS_ULTRA2(isp)) {
5765 off = ISP_40M_SYNCPARMS >> 8;
5766 per = ISP_40M_SYNCPARMS & 0xff;
5767 } else if (IS_1240(isp)) {
5768 off = ISP_20M_SYNCPARMS >> 8;
5769 per = ISP_20M_SYNCPARMS & 0xff;
5770 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
5771 isp->isp_type < ISP_HA_SCSI_1020A) ||
5772 (isp->isp_bustype == ISP_BT_PCI &&
5773 isp->isp_type < ISP_HA_SCSI_1040) ||
5774 (isp->isp_clock && isp->isp_clock < 60) ||
5775 (sdp->isp_ultramode == 0)) {
5776 off = ISP_10M_SYNCPARMS >> 8;
5777 per = ISP_10M_SYNCPARMS & 0xff;
5779 off = ISP_20M_SYNCPARMS_1040 >> 8;
5780 per = ISP_20M_SYNCPARMS_1040 & 0xff;
5782 sdp->isp_devparam[tgt].goal_offset =
5783 sdp->isp_devparam[tgt].nvrm_offset = off;
5784 sdp->isp_devparam[tgt].goal_period =
5785 sdp->isp_devparam[tgt].nvrm_period = per;
5787 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc3,
5788 channel, tgt, sdp->isp_devparam[tgt].nvrm_flags,
5789 sdp->isp_devparam[tgt].nvrm_offset,
5790 sdp->isp_devparam[tgt].nvrm_period);
5795 * Re-initialize the ISP and complete all orphaned commands
5796 * with a 'botched' notice. The reset/init routines should
5797 * not disturb an already active list of commands.
5799 * Locks held prior to coming here.
5803 isp_reinit(struct ispsoftc *isp)
5809 if (isp->isp_state != ISP_RESETSTATE) {
5810 isp_prt(isp, ISP_LOGERR, "isp_reinit cannot reset card");
5811 } else if (isp->isp_role != ISP_ROLE_NONE) {
5813 if (isp->isp_state == ISP_INITSTATE) {
5814 isp->isp_state = ISP_RUNSTATE;
5816 if (isp->isp_state != ISP_RUNSTATE) {
5817 isp_prt(isp, ISP_LOGERR,
5818 "isp_reinit cannot restart card");
5821 isp->isp_nactive = 0;
5823 for (handle = 1; (int) handle <= isp->isp_maxcmds; handle++) {
5824 xs = isp_find_xs(isp, handle);
5828 isp_destroy_handle(isp, handle);
5829 if (XS_XFRLEN(xs)) {
5830 ISP_DMAFREE(isp, xs, handle);
5831 XS_RESID(xs) = XS_XFRLEN(xs);
5835 XS_SETERR(xs, HBA_BUSRESET);
5844 isp_read_nvram(struct ispsoftc *isp)
5847 u_int8_t csum, minversion;
5849 u_int8_t _x[ISP2100_NVRAM_SIZE];
5850 u_int16_t _s[ISP2100_NVRAM_SIZE>>1];
5852 #define nvram_data _n._x
5853 #define nvram_words _n._s
5856 amt = ISP2100_NVRAM_SIZE;
5858 } else if (IS_ULTRA2(isp)) {
5859 amt = ISP1080_NVRAM_SIZE;
5862 amt = ISP_NVRAM_SIZE;
5867 * Just read the first two words first to see if we have a valid
5868 * NVRAM to continue reading the rest with.
5870 for (i = 0; i < 2; i++) {
5871 isp_rdnvram_word(isp, i, &nvram_words[i]);
5873 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
5874 nvram_data[2] != 'P') {
5875 if (isp->isp_bustype != ISP_BT_SBUS) {
5876 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
5877 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x",
5878 nvram_data[0], nvram_data[1], nvram_data[2]);
5882 for (i = 2; i < amt>>1; i++) {
5883 isp_rdnvram_word(isp, i, &nvram_words[i]);
5885 for (csum = 0, i = 0; i < amt; i++) {
5886 csum += nvram_data[i];
5889 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
5892 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
5893 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
5894 ISP_NVRAM_VERSION(nvram_data));
5898 if (IS_ULTRA3(isp)) {
5899 isp_parse_nvram_12160(isp, 0, nvram_data);
5901 isp_parse_nvram_12160(isp, 1, nvram_data);
5902 } else if (IS_1080(isp)) {
5903 isp_parse_nvram_1080(isp, 0, nvram_data);
5904 } else if (IS_1280(isp) || IS_1240(isp)) {
5905 isp_parse_nvram_1080(isp, 0, nvram_data);
5906 isp_parse_nvram_1080(isp, 1, nvram_data);
5907 } else if (IS_SCSI(isp)) {
5908 isp_parse_nvram_1020(isp, nvram_data);
5910 isp_parse_nvram_2100(isp, nvram_data);
5918 isp_rdnvram_word(struct ispsoftc *isp, int wo, u_int16_t *rp)
5921 u_int16_t bit, rqst;
5923 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
5925 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
5929 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
5930 if (IS_2312(isp) && isp->isp_port) {
5933 rqst = (ISP_NVRAM_READ << 8) | wo;
5935 } else if (IS_ULTRA2(isp)) {
5936 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
5937 rqst = (ISP_NVRAM_READ << 8) | wo;
5940 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
5941 rqst = (ISP_NVRAM_READ << 6) | wo;
5946 * Clock the word select request out...
5948 for (i = cbits; i >= 0; i--) {
5949 if ((rqst >> i) & 1) {
5950 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
5952 bit = BIU_NVRAM_SELECT;
5954 ISP_WRITE(isp, BIU_NVRAM, bit);
5956 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
5958 ISP_WRITE(isp, BIU_NVRAM, bit);
5962 * Now read the result back in (bits come back in MSB format).
5965 for (i = 0; i < 16; i++) {
5968 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
5970 rv = ISP_READ(isp, BIU_NVRAM);
5971 if (rv & BIU_NVRAM_DATAIN) {
5975 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
5978 ISP_WRITE(isp, BIU_NVRAM, 0);
5980 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
5984 isp_parse_nvram_1020(struct ispsoftc *isp, u_int8_t *nvram_data)
5986 sdparam *sdp = (sdparam *) isp->isp_param;
5989 sdp->isp_fifo_threshold =
5990 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
5991 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
5993 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
5994 sdp->isp_initiator_id =
5995 ISP_NVRAM_INITIATOR_ID(nvram_data);
5997 sdp->isp_bus_reset_delay =
5998 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
6000 sdp->isp_retry_count =
6001 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
6003 sdp->isp_retry_delay =
6004 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
6006 sdp->isp_async_data_setup =
6007 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
6009 if (isp->isp_type >= ISP_HA_SCSI_1040) {
6010 if (sdp->isp_async_data_setup < 9) {
6011 sdp->isp_async_data_setup = 9;
6014 if (sdp->isp_async_data_setup != 6) {
6015 sdp->isp_async_data_setup = 6;
6019 sdp->isp_req_ack_active_neg =
6020 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
6022 sdp->isp_data_line_active_neg =
6023 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
6025 sdp->isp_data_dma_burst_enabl =
6026 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
6028 sdp->isp_cmd_dma_burst_enable =
6029 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
6031 sdp->isp_tag_aging =
6032 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
6034 sdp->isp_selection_timeout =
6035 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
6037 sdp->isp_max_queue_depth =
6038 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
6040 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
6042 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6043 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6044 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6045 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6046 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6047 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6048 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6049 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6051 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6052 sdp->isp_devparam[tgt].dev_enable =
6053 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
6054 sdp->isp_devparam[tgt].exc_throttle =
6055 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
6056 sdp->isp_devparam[tgt].nvrm_offset =
6057 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
6058 sdp->isp_devparam[tgt].nvrm_period =
6059 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
6061 * We probably shouldn't lie about this, but it
6062 * it makes it much safer if we limit NVRAM values
6065 if (isp->isp_type < ISP_HA_SCSI_1040) {
6067 * If we're not ultra, we can't possibly
6068 * be a shorter period than this.
6070 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
6071 sdp->isp_devparam[tgt].nvrm_period = 0x19;
6073 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
6074 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
6077 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
6078 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
6081 sdp->isp_devparam[tgt].nvrm_flags = 0;
6082 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
6083 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6084 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6085 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
6086 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6087 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
6088 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6089 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
6090 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6091 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
6092 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6093 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
6094 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6095 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
6096 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6097 0, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6098 sdp->isp_devparam[tgt].nvrm_offset,
6099 sdp->isp_devparam[tgt].nvrm_period);
6100 sdp->isp_devparam[tgt].goal_offset =
6101 sdp->isp_devparam[tgt].nvrm_offset;
6102 sdp->isp_devparam[tgt].goal_period =
6103 sdp->isp_devparam[tgt].nvrm_period;
6104 sdp->isp_devparam[tgt].goal_flags =
6105 sdp->isp_devparam[tgt].nvrm_flags;
6110 isp_parse_nvram_1080(struct ispsoftc *isp, int bus, u_int8_t *nvram_data)
6112 sdparam *sdp = (sdparam *) isp->isp_param;
6117 sdp->isp_fifo_threshold =
6118 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
6120 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6121 sdp->isp_initiator_id =
6122 ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
6124 sdp->isp_bus_reset_delay =
6125 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6127 sdp->isp_retry_count =
6128 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6130 sdp->isp_retry_delay =
6131 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6133 sdp->isp_async_data_setup =
6134 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6136 sdp->isp_req_ack_active_neg =
6137 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6139 sdp->isp_data_line_active_neg =
6140 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6142 sdp->isp_data_dma_burst_enabl =
6143 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6145 sdp->isp_cmd_dma_burst_enable =
6146 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6148 sdp->isp_selection_timeout =
6149 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6151 sdp->isp_max_queue_depth =
6152 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6154 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6155 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6156 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6157 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6158 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6159 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6160 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6161 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6164 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6165 sdp->isp_devparam[tgt].dev_enable =
6166 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6167 sdp->isp_devparam[tgt].exc_throttle =
6168 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6169 sdp->isp_devparam[tgt].nvrm_offset =
6170 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6171 sdp->isp_devparam[tgt].nvrm_period =
6172 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6173 sdp->isp_devparam[tgt].nvrm_flags = 0;
6174 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6175 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6176 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6177 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6178 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6179 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6180 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6181 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6182 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6183 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6184 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6185 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6186 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6187 sdp->isp_devparam[tgt].actv_flags = 0;
6188 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6189 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6190 sdp->isp_devparam[tgt].nvrm_offset,
6191 sdp->isp_devparam[tgt].nvrm_period);
6192 sdp->isp_devparam[tgt].goal_offset =
6193 sdp->isp_devparam[tgt].nvrm_offset;
6194 sdp->isp_devparam[tgt].goal_period =
6195 sdp->isp_devparam[tgt].nvrm_period;
6196 sdp->isp_devparam[tgt].goal_flags =
6197 sdp->isp_devparam[tgt].nvrm_flags;
6202 isp_parse_nvram_12160(struct ispsoftc *isp, int bus, u_int8_t *nvram_data)
6204 sdparam *sdp = (sdparam *) isp->isp_param;
6209 sdp->isp_fifo_threshold =
6210 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
6212 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6213 sdp->isp_initiator_id =
6214 ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
6216 sdp->isp_bus_reset_delay =
6217 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6219 sdp->isp_retry_count =
6220 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6222 sdp->isp_retry_delay =
6223 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6225 sdp->isp_async_data_setup =
6226 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6228 sdp->isp_req_ack_active_neg =
6229 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6231 sdp->isp_data_line_active_neg =
6232 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6234 sdp->isp_data_dma_burst_enabl =
6235 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6237 sdp->isp_cmd_dma_burst_enable =
6238 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6240 sdp->isp_selection_timeout =
6241 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6243 sdp->isp_max_queue_depth =
6244 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6246 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6247 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6248 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6249 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6250 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6251 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6252 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6253 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6255 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6256 sdp->isp_devparam[tgt].dev_enable =
6257 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6258 sdp->isp_devparam[tgt].exc_throttle =
6259 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6260 sdp->isp_devparam[tgt].nvrm_offset =
6261 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6262 sdp->isp_devparam[tgt].nvrm_period =
6263 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6264 sdp->isp_devparam[tgt].nvrm_flags = 0;
6265 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6266 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6267 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6268 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6269 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6270 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6271 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6272 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6273 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6274 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6275 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6276 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6277 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6278 sdp->isp_devparam[tgt].actv_flags = 0;
6279 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6280 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6281 sdp->isp_devparam[tgt].nvrm_offset,
6282 sdp->isp_devparam[tgt].nvrm_period);
6283 sdp->isp_devparam[tgt].goal_offset =
6284 sdp->isp_devparam[tgt].nvrm_offset;
6285 sdp->isp_devparam[tgt].goal_period =
6286 sdp->isp_devparam[tgt].nvrm_period;
6287 sdp->isp_devparam[tgt].goal_flags =
6288 sdp->isp_devparam[tgt].nvrm_flags;
6293 isp_parse_nvram_2100(struct ispsoftc *isp, u_int8_t *nvram_data)
6295 fcparam *fcp = (fcparam *) isp->isp_param;
6299 * There is NVRAM storage for both Port and Node entities-
6300 * but the Node entity appears to be unused on all the cards
6301 * I can find. However, we should account for this being set
6302 * at some point in the future.
6304 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
6305 * bits 48..60. In the case of the 2202, it appears that they do
6306 * use bit 48 to distinguish between the two instances on the card.
6307 * The 2204, which I've never seen, *probably* extends this method.
6309 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
6311 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
6312 (u_int32_t) (wwn >> 32), (u_int32_t) (wwn & 0xffffffff));
6313 if ((wwn >> 60) == 0) {
6314 wwn |= (((u_int64_t) 2)<< 60);
6317 fcp->isp_portwwn = wwn;
6318 if (IS_2200(isp) || IS_23XX(isp)) {
6319 wwn = ISP2200_NVRAM_NODE_NAME(nvram_data);
6321 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
6322 (u_int32_t) (wwn >> 32),
6323 (u_int32_t) (wwn & 0xffffffff));
6324 if ((wwn >> 60) == 0) {
6325 wwn |= (((u_int64_t) 2)<< 60);
6329 wwn &= ~((u_int64_t) 0xfff << 48);
6331 fcp->isp_nodewwn = wwn;
6334 * Make sure we have both Node and Port as non-zero values.
6336 if (fcp->isp_nodewwn != 0 && fcp->isp_portwwn == 0) {
6337 fcp->isp_portwwn = fcp->isp_nodewwn;
6338 } else if (fcp->isp_nodewwn == 0 && fcp->isp_portwwn != 0) {
6339 fcp->isp_nodewwn = fcp->isp_portwwn;
6343 * Make the Node and Port values sane if they're NAA == 2.
6344 * This means to clear bits 48..56 for the Node WWN and
6345 * make sure that there's some non-zero value in 48..56
6348 if (fcp->isp_nodewwn && fcp->isp_portwwn) {
6349 if ((fcp->isp_nodewwn & (((u_int64_t) 0xfff) << 48)) != 0 &&
6350 (fcp->isp_nodewwn >> 60) == 2) {
6351 fcp->isp_nodewwn &= ~((u_int64_t) 0xfff << 48);
6353 if ((fcp->isp_portwwn & (((u_int64_t) 0xfff) << 48)) == 0 &&
6354 (fcp->isp_portwwn >> 60) == 2) {
6355 fcp->isp_portwwn |= ((u_int64_t) 1 << 56);
6359 isp_prt(isp, ISP_LOGDEBUG0,
6360 "NVRAM: maxfrmlen %d execthrottle %d fwoptions 0x%x loopid %x",
6361 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data),
6362 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
6363 ISP2100_NVRAM_OPTIONS(nvram_data),
6364 ISP2100_NVRAM_HARDLOOPID(nvram_data));
6367 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
6368 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0)
6369 fcp->isp_maxfrmlen =
6370 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
6371 fcp->isp_retry_delay =
6372 ISP2100_NVRAM_RETRY_DELAY(nvram_data);
6373 fcp->isp_retry_count =
6374 ISP2100_NVRAM_RETRY_COUNT(nvram_data);
6375 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6377 ISP2100_NVRAM_HARDLOOPID(nvram_data);
6378 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0)
6379 fcp->isp_execthrottle =
6380 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
6381 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
6384 #ifdef ISP_FW_CRASH_DUMP
6385 static void isp2200_fw_dump(struct ispsoftc *);
6386 static void isp2300_fw_dump(struct ispsoftc *);
6389 isp2200_fw_dump(struct ispsoftc *isp)
6395 ptr = FCPARAM(isp)->isp_dump_data;
6397 isp_prt(isp, ISP_LOGERR,
6398 "No place to dump RISC registers and SRAM");
6402 isp_prt(isp, ISP_LOGERR,
6403 "dump area for RISC registers and SRAM already used");
6406 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6407 for (i = 0; i < 100; i++) {
6409 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6413 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6417 for (i = 0; i < 8; i++) {
6418 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6424 for (i = 0; i < 8; i++) {
6425 *ptr++ = ISP_READ(isp, MBOX_BLOCK + (i << 1));
6431 for (i = 0; i < 48; i++) {
6432 *ptr++ = ISP_READ(isp, DMA_BLOCK + 0x20 + (i << 1));
6436 * RISC H/W Registers
6438 ISP_WRITE(isp, BIU2100_CSR, 0);
6439 for (i = 0; i < 16; i++) {
6440 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6446 for (j = 0; j < 8; j++) {
6447 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 8));
6448 for (i = 0; i < 16; i++) {
6450 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6455 * Frame Buffer Hardware Registers
6457 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6458 for (i = 0; i < 16; i++) {
6459 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6463 * Fibre Protocol Module 0 Hardware Registers
6465 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6466 for (i = 0; i < 64; i++) {
6467 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6471 * Fibre Protocol Module 1 Hardware Registers
6473 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6474 for (i = 0; i < 64; i++) {
6475 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6478 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6481 isp_prt(isp, ISP_LOGALL,
6482 "isp_fw_dump: RISC registers dumped successfully");
6483 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6484 for (i = 0; i < 100; i++) {
6486 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6490 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6491 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6494 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6495 for (i = 0; i < 100; i++) {
6497 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6501 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6502 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause After Reset");
6505 ISP_WRITE(isp, RISC_EMB, 0xf2);
6506 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
6507 for (i = 0; i < 100; i++) {
6509 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6514 mbs.param[0] = MBOX_READ_RAM_WORD;
6515 mbs.param[1] = 0x1000;
6516 isp->isp_mbxworkp = (void *) ptr;
6517 isp->isp_mbxwrk0 = 0xefff; /* continuation count */
6518 isp->isp_mbxwrk1 = 0x1001; /* next SRAM address */
6519 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6520 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6521 isp_prt(isp, ISP_LOGWARN,
6522 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6525 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6526 *ptr++ = isp->isp_mboxtmp[2];
6527 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
6528 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6529 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6533 isp2300_fw_dump(struct ispsoftc *isp)
6539 ptr = FCPARAM(isp)->isp_dump_data;
6541 isp_prt(isp, ISP_LOGERR,
6542 "No place to dump RISC registers and SRAM");
6546 isp_prt(isp, ISP_LOGERR,
6547 "dump area for RISC registers and SRAM already used");
6550 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6551 for (i = 0; i < 100; i++) {
6553 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6557 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6561 for (i = 0; i < 8; i++) {
6562 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6566 * ReqQ-RspQ-Risc2Host Status registers
6568 for (i = 0; i < 8; i++) {
6569 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x10 + (i << 1));
6575 for (i = 0; i < 32; i++) {
6577 ISP_READ(isp, PCI_MBOX_REGS2300_OFF + (i << 1));
6581 * Auto Request Response DMA registers
6583 ISP_WRITE(isp, BIU2100_CSR, 0x40);
6584 for (i = 0; i < 32; i++) {
6585 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6591 ISP_WRITE(isp, BIU2100_CSR, 0x50);
6592 for (i = 0; i < 48; i++) {
6593 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6597 * RISC hardware registers
6599 ISP_WRITE(isp, BIU2100_CSR, 0);
6600 for (i = 0; i < 16; i++) {
6601 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6605 * RISC GP? registers
6607 for (j = 0; j < 8; j++) {
6608 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 9));
6609 for (i = 0; i < 16; i++) {
6611 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6616 * frame buffer hardware registers
6618 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6619 for (i = 0; i < 64; i++) {
6620 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6624 * FPM B0 hardware registers
6626 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6627 for (i = 0; i < 64; i++) {
6628 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6632 * FPM B1 hardware registers
6634 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6635 for (i = 0; i < 64; i++) {
6636 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6639 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6642 isp_prt(isp, ISP_LOGALL,
6643 "isp_fw_dump: RISC registers dumped successfully");
6644 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6645 for (i = 0; i < 100; i++) {
6647 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6651 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6652 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6656 mbs.param[0] = MBOX_READ_RAM_WORD;
6657 mbs.param[1] = 0x800;
6658 isp->isp_mbxworkp = (void *) ptr;
6659 isp->isp_mbxwrk0 = 0xf7ff; /* continuation count */
6660 isp->isp_mbxwrk1 = 0x801; /* next SRAM address */
6661 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6662 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6663 isp_prt(isp, ISP_LOGWARN,
6664 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6667 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6668 *ptr++ = isp->isp_mboxtmp[2];
6671 * We don't have access to mailbox registers 8.. onward
6672 * in our 'common' device model- so we have to set it
6673 * here and hope it stays the same!
6675 ISP_WRITE(isp, PCI_MBOX_REGS2300_OFF + (8 << 1), 0x1);
6677 mbs.param[0] = MBOX_READ_RAM_WORD_EXTENDED;
6679 isp->isp_mbxworkp = (void *) ptr;
6680 isp->isp_mbxwrk0 = 0xffff; /* continuation count */
6681 isp->isp_mbxwrk1 = 0x1; /* next SRAM address */
6682 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6683 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6684 isp_prt(isp, ISP_LOGWARN,
6685 "RAM DUMP FAILED @ WORD %x", 0x10000 + isp->isp_mbxwrk1);
6688 ptr = isp->isp_mbxworkp; /* finish final word */
6689 *ptr++ = mbs.param[2];
6690 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
6691 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6692 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6696 isp_fw_dump(struct ispsoftc *isp)
6699 isp2200_fw_dump(isp);
6700 else if (IS_23XX(isp))
6701 isp2300_fw_dump(isp);