1 /* $FreeBSD: src/sys/dev/isp/isp.c,v 1.41.2.23 2002/10/11 17:34:28 mjacob Exp $ */
2 /* $DragonFly: src/sys/dev/disk/isp/isp.c,v 1.2 2003/06/17 04:28:27 dillon Exp $ */
4 * Machine and OS Independent (well, as best as possible)
5 * code for the Qlogic ISP SCSI adapters.
7 * Copyright (c) 1997, 1998, 1999, 2000, 2001 by Matthew Jacob
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice immediately at the beginning of the file, without modification,
16 * this list of conditions, and the following disclaimer.
17 * 2. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
35 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
36 * ideas dredged from the Solaris driver.
40 * Include header file appropriate for platform we're building on.
44 #include <dev/ic/isp_netbsd.h>
47 #include <dev/isp/isp_freebsd.h>
50 #include <dev/ic/isp_openbsd.h>
53 #include "isp_linux.h"
56 #include "isp_solaris.h"
63 #define MBOX_DELAY_COUNT 1000000 / 100
68 static const char portshift[] =
69 "Target %d Loop ID 0x%x (Port 0x%x) => Loop 0x%x (Port 0x%x)";
70 static const char portdup[] =
71 "Target %d duplicates Target %d- killing off both";
72 static const char retained[] =
73 "Retaining Loop ID 0x%x for Target %d (Port 0x%x)";
74 static const char lretained[] =
75 "Retained login of Target %d (Loop ID 0x%x) Port 0x%x";
76 static const char plogout[] =
77 "Logging out Target %d at Loop ID 0x%x (Port 0x%x)";
78 static const char plogierr[] =
79 "Command Error in PLOGI for Port 0x%x (0x%x)";
80 static const char nopdb[] =
81 "Could not get PDB for Device @ Port 0x%x";
82 static const char pdbmfail1[] =
83 "PDB Loop ID info for Device @ Port 0x%x does not match up (0x%x)";
84 static const char pdbmfail2[] =
85 "PDB Port info for Device @ Port 0x%x does not match up (0x%x)";
86 static const char ldumped[] =
87 "Target %d (Loop ID 0x%x) Port 0x%x dumped after login info mismatch";
88 static const char notresp[] =
89 "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
90 static const char xact1[] =
91 "HBA attempted queued transaction with disconnect not set for %d.%d.%d";
92 static const char xact2[] =
93 "HBA attempted queued transaction to target routine %d on target %d bus %d";
94 static const char xact3[] =
95 "HBA attempted queued cmd for %d.%d.%d when queueing disabled";
96 static const char pskip[] =
97 "SCSI phase skipped for target %d.%d.%d";
98 static const char topology[] =
99 "Loop ID %d, AL_PA 0x%x, Port ID 0x%x, Loop State 0x%x, Topology '%s'";
100 static const char swrej[] =
101 "Fabric Nameserver rejected %s (Reason=0x%x Expl=0x%x) for Port ID 0x%x";
102 static const char finmsg[] =
103 "(%d.%d.%d): FIN dl%d resid %d STS 0x%x SKEY %c XS_ERR=0x%x";
104 static const char sc0[] =
105 "%s CHAN %d FTHRSH %d IID %d RESETD %d RETRYC %d RETRYD %d ASD 0x%x";
106 static const char sc1[] =
107 "%s RAAN 0x%x DLAN 0x%x DDMAB 0x%x CDMAB 0x%x SELTIME %d MQD %d";
108 static const char sc2[] = "%s CHAN %d TGT %d FLAGS 0x%x 0x%x/0x%x";
109 static const char sc3[] = "Generated";
110 static const char sc4[] = "NVRAM";
111 static const char bun[] =
112 "bad underrun for %d.%d (count %d, resid %d, status %s)";
115 * Local function prototypes.
117 static int isp_parse_async(struct ispsoftc *, u_int16_t);
118 static int isp_handle_other_response(struct ispsoftc *, int, isphdr_t *,
121 isp_parse_status(struct ispsoftc *, ispstatusreq_t *, XS_T *);
122 static void isp_fastpost_complete(struct ispsoftc *, u_int16_t);
123 static int isp_mbox_continue(struct ispsoftc *);
124 static void isp_scsi_init(struct ispsoftc *);
125 static void isp_scsi_channel_init(struct ispsoftc *, int);
126 static void isp_fibre_init(struct ispsoftc *);
127 static void isp_mark_getpdb_all(struct ispsoftc *);
128 static int isp_getmap(struct ispsoftc *, fcpos_map_t *);
129 static int isp_getpdb(struct ispsoftc *, int, isp_pdb_t *);
130 static u_int64_t isp_get_portname(struct ispsoftc *, int, int);
131 static int isp_fclink_test(struct ispsoftc *, int);
132 static char *isp2100_fw_statename(int);
133 static int isp_pdb_sync(struct ispsoftc *);
134 static int isp_scan_loop(struct ispsoftc *);
135 static int isp_fabric_mbox_cmd(struct ispsoftc *, mbreg_t *);
136 static int isp_scan_fabric(struct ispsoftc *, int);
137 static void isp_register_fc4_type(struct ispsoftc *);
138 static void isp_fw_state(struct ispsoftc *);
139 static void isp_mboxcmd_qnw(struct ispsoftc *, mbreg_t *, int);
140 static void isp_mboxcmd(struct ispsoftc *, mbreg_t *, int);
142 static void isp_update(struct ispsoftc *);
143 static void isp_update_bus(struct ispsoftc *, int);
144 static void isp_setdfltparm(struct ispsoftc *, int);
145 static int isp_read_nvram(struct ispsoftc *);
146 static void isp_rdnvram_word(struct ispsoftc *, int, u_int16_t *);
147 static void isp_parse_nvram_1020(struct ispsoftc *, u_int8_t *);
148 static void isp_parse_nvram_1080(struct ispsoftc *, int, u_int8_t *);
149 static void isp_parse_nvram_12160(struct ispsoftc *, int, u_int8_t *);
150 static void isp_parse_nvram_2100(struct ispsoftc *, u_int8_t *);
155 * Hit the chip over the head, download new f/w if available and set it running.
157 * Locking done elsewhere.
161 isp_reset(struct ispsoftc *isp)
165 int loops, i, dodnld = 1;
166 char *btype = "????";
168 isp->isp_state = ISP_NILSTATE;
171 * Basic types (SCSI, FibreChannel and PCI or SBus)
172 * have been set in the MD code. We figure out more
173 * here. Possibly more refined types based upon PCI
174 * identification. Chip revision has been gathered.
176 * After we've fired this chip up, zero out the conf1 register
177 * for SCSI adapters and do other settings for the 2100.
181 * Get the current running firmware revision out of the
182 * chip before we hit it over the head (if this is our
183 * first time through). Note that we store this as the
184 * 'ROM' firmware revision- which it may not be. In any
185 * case, we don't really use this yet, but we may in
188 if (isp->isp_touched == 0) {
190 * First see whether or not we're sitting in the ISP PROM.
191 * If we've just been reset, we'll have the string "ISP "
192 * spread through outgoing mailbox registers 1-3. We do
193 * this for PCI cards because otherwise we really don't
194 * know what state the card is in and we could hang if
195 * we try this command otherwise.
197 * For SBus cards, we just do this because they almost
198 * certainly will be running firmware by now.
200 if (ISP_READ(isp, OUTMAILBOX1) != 0x4953 ||
201 ISP_READ(isp, OUTMAILBOX2) != 0x5020 ||
202 ISP_READ(isp, OUTMAILBOX3) != 0x2020) {
204 * Just in case it was paused...
206 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
207 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
208 isp_mboxcmd(isp, &mbs, MBLOGNONE);
209 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
210 isp->isp_romfw_rev[0] = mbs.param[1];
211 isp->isp_romfw_rev[1] = mbs.param[2];
212 isp->isp_romfw_rev[2] = mbs.param[3];
215 isp->isp_touched = 1;
221 * Set up default request/response queue in-pointer/out-pointer
225 isp->isp_rqstinrp = BIU_REQINP;
226 isp->isp_rqstoutrp = BIU_REQOUTP;
227 isp->isp_respinrp = BIU_RSPINP;
228 isp->isp_respoutrp = BIU_RSPOUTP;
230 isp->isp_rqstinrp = INMAILBOX4;
231 isp->isp_rqstoutrp = OUTMAILBOX4;
232 isp->isp_respinrp = OUTMAILBOX5;
233 isp->isp_respoutrp = INMAILBOX5;
237 * Put the board into PAUSE mode (so we can read the SXP registers
238 * or write FPM/FBM registers).
240 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
243 switch (isp->isp_type) {
260 * While we're paused, reset the FPM module and FBM fifos.
262 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
263 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
264 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
265 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
266 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
267 } else if (IS_1240(isp)) {
268 sdparam *sdp = isp->isp_param;
271 sdp->isp_ultramode = 1;
273 sdp->isp_ultramode = 1;
275 * XXX: Should probably do some bus sensing.
277 } else if (IS_ULTRA2(isp)) {
278 static const char m[] = "bus %d is in %s Mode";
280 sdparam *sdp = isp->isp_param;
282 isp->isp_clock = 100;
286 else if (IS_1080(isp))
288 else if (IS_10160(isp))
290 else if (IS_12160(isp))
295 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
297 case ISP1080_LVD_MODE:
298 sdp->isp_lvdmode = 1;
299 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
301 case ISP1080_HVD_MODE:
302 sdp->isp_diffmode = 1;
303 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
305 case ISP1080_SE_MODE:
306 sdp->isp_ultramode = 1;
307 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
310 isp_prt(isp, ISP_LOGERR,
311 "unknown mode on bus %d (0x%x)", 0, l);
315 if (IS_DUALBUS(isp)) {
317 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
318 l &= ISP1080_MODE_MASK;
320 case ISP1080_LVD_MODE:
321 sdp->isp_lvdmode = 1;
322 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
324 case ISP1080_HVD_MODE:
325 sdp->isp_diffmode = 1;
326 isp_prt(isp, ISP_LOGCONFIG,
327 m, 1, "Differential");
329 case ISP1080_SE_MODE:
330 sdp->isp_ultramode = 1;
331 isp_prt(isp, ISP_LOGCONFIG,
332 m, 1, "Single-Ended");
335 isp_prt(isp, ISP_LOGERR,
336 "unknown mode on bus %d (0x%x)", 1, l);
341 sdparam *sdp = isp->isp_param;
342 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
345 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
349 isp->isp_type = ISP_HA_SCSI_1020;
354 * Some 1020A chips are Ultra Capable, but don't
355 * run the clock rate up for that unless told to
356 * do so by the Ultra Capable bits being set.
359 isp->isp_type = ISP_HA_SCSI_1020A;
364 isp->isp_type = ISP_HA_SCSI_1040;
369 isp->isp_type = ISP_HA_SCSI_1040A;
374 isp->isp_type = ISP_HA_SCSI_1040B;
379 isp->isp_type = ISP_HA_SCSI_1040C;
384 * Now, while we're at it, gather info about ultra
385 * and/or differential mode.
387 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
388 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
389 sdp->isp_diffmode = 1;
391 sdp->isp_diffmode = 0;
393 i = ISP_READ(isp, RISC_PSR);
394 if (isp->isp_bustype == ISP_BT_SBUS) {
395 i &= RISC_PSR_SBUS_ULTRA;
397 i &= RISC_PSR_PCI_ULTRA;
400 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
401 sdp->isp_ultramode = 1;
403 * If we're in Ultra Mode, we have to be 60Mhz clock-
404 * even for the SBus version.
408 sdp->isp_ultramode = 0;
410 * Clock is known. Gronk.
415 * Machine dependent clock (if set) overrides
416 * our generic determinations.
418 if (isp->isp_mdvec->dv_clock) {
419 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
420 isp->isp_clock = isp->isp_mdvec->dv_clock;
427 * Clear instrumentation
429 isp->isp_intcnt = isp->isp_intbogus = 0;
432 * Do MD specific pre initialization
439 * Hit the chip over the head with hammer,
440 * and give the ISP a chance to recover.
444 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
451 * Clear data && control DMA engines.
453 ISP_WRITE(isp, CDMA_CONTROL,
454 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
455 ISP_WRITE(isp, DDMA_CONTROL,
456 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
460 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
467 * Clear data && control DMA engines.
469 ISP_WRITE(isp, CDMA2100_CONTROL,
470 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
471 ISP_WRITE(isp, TDMA2100_CONTROL,
472 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
473 ISP_WRITE(isp, RDMA2100_CONTROL,
474 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
478 * Wait for ISP to be ready to go...
480 loops = MBOX_DELAY_COUNT;
483 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET))
486 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
491 ISP_DUMPREGS(isp, "chip reset timed out");
497 * After we've fired this chip up, zero out the conf1 register
498 * for SCSI adapters and other settings for the 2100.
502 ISP_WRITE(isp, BIU_CONF1, 0);
504 ISP_WRITE(isp, BIU2100_CSR, 0);
508 * Reset RISC Processor
510 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
512 /* Clear semaphore register (just to be sure) */
513 ISP_WRITE(isp, BIU_SEMA, 0);
516 * Establish some initial burst rate stuff.
517 * (only for the 1XX0 boards). This really should
518 * be done later after fetching from NVRAM.
521 u_int16_t tmp = isp->isp_mdvec->dv_conf1;
523 * Busted FIFO. Turn off all but burst enables.
525 if (isp->isp_type == ISP_HA_SCSI_1040A) {
526 tmp &= BIU_BURST_ENABLE;
528 ISP_SETBITS(isp, BIU_CONF1, tmp);
529 if (tmp & BIU_BURST_ENABLE) {
530 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
531 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
534 if (((sdparam *) isp->isp_param)->isp_ultramode) {
535 while (ISP_READ(isp, RISC_MTR) != 0x1313) {
536 ISP_WRITE(isp, RISC_MTR, 0x1313);
537 ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
540 ISP_WRITE(isp, RISC_MTR, 0x1212);
543 * PTI specific register
545 ISP_WRITE(isp, RISC_EMB, DUAL_BANK)
547 ISP_WRITE(isp, RISC_MTR, 0x1212);
550 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
551 if (IS_2200(isp) || IS_23XX(isp)) {
552 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
556 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE); /* release paused processor */
559 * Do MD specific post initialization
564 * Wait for everything to finish firing up.
566 * Avoid doing this on the 2312 because you can generate a PCI
567 * parity error (chip breakage).
572 loops = MBOX_DELAY_COUNT;
573 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
576 isp_prt(isp, ISP_LOGERR,
577 "MBOX_BUSY never cleared on reset");
584 * Up until this point we've done everything by just reading or
585 * setting registers. From this point on we rely on at least *some*
586 * kind of firmware running in the card.
590 * Do some sanity checking.
592 mbs.param[0] = MBOX_NO_OP;
593 isp_mboxcmd(isp, &mbs, MBLOGALL);
594 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
599 mbs.param[0] = MBOX_MAILBOX_REG_TEST;
600 mbs.param[1] = 0xdead;
601 mbs.param[2] = 0xbeef;
602 mbs.param[3] = 0xffff;
603 mbs.param[4] = 0x1111;
604 mbs.param[5] = 0xa5a5;
605 isp_mboxcmd(isp, &mbs, MBLOGALL);
606 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
609 if (mbs.param[1] != 0xdead || mbs.param[2] != 0xbeef ||
610 mbs.param[3] != 0xffff || mbs.param[4] != 0x1111 ||
611 mbs.param[5] != 0xa5a5) {
612 isp_prt(isp, ISP_LOGERR,
613 "Register Test Failed (0x%x 0x%x 0x%x 0x%x 0x%x)",
614 mbs.param[1], mbs.param[2], mbs.param[3],
615 mbs.param[4], mbs.param[5]);
622 * Download new Firmware, unless requested not to do so.
623 * This is made slightly trickier in some cases where the
624 * firmware of the ROM revision is newer than the revision
625 * compiled into the driver. So, where we used to compare
626 * versions of our f/w and the ROM f/w, now we just see
627 * whether we have f/w at all and whether a config flag
628 * has disabled our download.
630 if ((isp->isp_mdvec->dv_ispfw == NULL) ||
631 (isp->isp_confopts & ISP_CFG_NORELOAD)) {
636 code_org = ISP_CODE_ORG_2300;
638 code_org = ISP_CODE_ORG;
641 isp->isp_mbxworkp = (void *) &isp->isp_mdvec->dv_ispfw[1];
642 isp->isp_mbxwrk0 = isp->isp_mdvec->dv_ispfw[3] - 1;
643 isp->isp_mbxwrk1 = code_org + 1;
644 mbs.param[0] = MBOX_WRITE_RAM_WORD;
645 mbs.param[1] = code_org;
646 mbs.param[2] = isp->isp_mdvec->dv_ispfw[0];
647 isp_mboxcmd(isp, &mbs, MBLOGNONE);
648 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
649 isp_prt(isp, ISP_LOGERR,
650 "F/W download failed at word %d",
651 isp->isp_mbxwrk1 - code_org);
656 * Verify that it downloaded correctly.
658 mbs.param[0] = MBOX_VERIFY_CHECKSUM;
659 mbs.param[1] = code_org;
660 isp_mboxcmd(isp, &mbs, MBLOGNONE);
661 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
662 isp_prt(isp, ISP_LOGERR, "Ram Checksum Failure");
665 isp->isp_loaded_fw = 1;
667 isp->isp_loaded_fw = 0;
668 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
672 * Now start it rolling.
674 * If we didn't actually download f/w,
675 * we still need to (re)start it.
679 mbs.param[0] = MBOX_EXEC_FIRMWARE;
680 mbs.param[1] = code_org;
681 isp_mboxcmd(isp, &mbs, MBLOGNONE);
683 * Give it a chance to start.
689 * Set CLOCK RATE, but only if asked to.
691 if (isp->isp_clock) {
692 mbs.param[0] = MBOX_SET_CLOCK_RATE;
693 mbs.param[1] = isp->isp_clock;
694 isp_mboxcmd(isp, &mbs, MBLOGALL);
695 /* we will try not to care if this fails */
699 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
700 isp_mboxcmd(isp, &mbs, MBLOGALL);
701 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
706 * The SBus firmware that we are using apparently does not return
707 * major, minor, micro revisions in the mailbox registers, which
708 * is really, really, annoying.
710 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
712 #ifdef ISP_TARGET_MODE
713 isp->isp_fwrev[0] = 7;
714 isp->isp_fwrev[1] = 55;
716 isp->isp_fwrev[0] = 1;
717 isp->isp_fwrev[1] = 37;
719 isp->isp_fwrev[2] = 0;
722 isp->isp_fwrev[0] = mbs.param[1];
723 isp->isp_fwrev[1] = mbs.param[2];
724 isp->isp_fwrev[2] = mbs.param[3];
726 isp_prt(isp, ISP_LOGCONFIG,
727 "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
728 btype, isp->isp_revision, dodnld? "loaded" : "resident",
729 isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
733 * We do not believe firmware attributes for 2100 code less
734 * than 1.17.0, unless it's the firmware we specifically
737 * Note that all 22XX and 23XX f/w is greater than 1.X.0.
739 if (!(ISP_FW_NEWER_THAN(isp, 1, 17, 0))) {
740 #ifdef USE_SMALLER_2100_FIRMWARE
741 FCPARAM(isp)->isp_fwattr = ISP_FW_ATTR_SCCLUN;
743 FCPARAM(isp)->isp_fwattr = 0;
746 FCPARAM(isp)->isp_fwattr = mbs.param[6];
747 isp_prt(isp, ISP_LOGDEBUG0,
748 "Firmware Attributes = 0x%x", mbs.param[6]);
750 if (ISP_READ(isp, BIU2100_CSR) & BIU2100_PCI64) {
751 isp_prt(isp, ISP_LOGCONFIG,
752 "Installed in 64-Bit PCI slot");
756 if (isp->isp_romfw_rev[0] || isp->isp_romfw_rev[1] ||
757 isp->isp_romfw_rev[2]) {
758 isp_prt(isp, ISP_LOGCONFIG, "Last F/W revision was %d.%d.%d",
759 isp->isp_romfw_rev[0], isp->isp_romfw_rev[1],
760 isp->isp_romfw_rev[2]);
763 mbs.param[0] = MBOX_GET_FIRMWARE_STATUS;
764 isp_mboxcmd(isp, &mbs, MBLOGALL);
765 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
768 isp->isp_maxcmds = mbs.param[2];
769 isp_prt(isp, ISP_LOGINFO,
770 "%d max I/O commands supported", mbs.param[2]);
774 * Set up DMA for the request and result mailboxes.
776 if (ISP_MBOXDMASETUP(isp) != 0) {
777 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
780 isp->isp_state = ISP_RESETSTATE;
783 * Okay- now that we have new firmware running, we now (re)set our
784 * notion of how many luns we support. This is somewhat tricky because
785 * if we haven't loaded firmware, we sometimes do not have an easy way
786 * of knowing how many luns we support.
788 * Expanded lun firmware gives you 32 luns for SCSI cards and
789 * 16384 luns for Fibre Channel cards.
791 * It turns out that even for QLogic 2100s with ROM 1.10 and above
792 * we do get a firmware attributes word returned in mailbox register 6.
794 * Because the lun is in a a different position in the Request Queue
795 * Entry structure for Fibre Channel with expanded lun firmware, we
796 * can only support one lun (lun zero) when we don't know what kind
797 * of firmware we're running.
799 * Note that we only do this once (the first time thru isp_reset)
800 * because we may be called again after firmware has been loaded once
805 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
806 isp->isp_maxluns = 32;
808 isp->isp_maxluns = 8;
811 isp->isp_maxluns = 8;
814 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
815 isp->isp_maxluns = 16384;
817 isp->isp_maxluns = 16;
823 * Initialize Parameters of Hardware to a known state.
825 * Locks are held before coming here.
829 isp_init(struct ispsoftc *isp)
832 * Must do this first to get defaults established.
834 isp_setdfltparm(isp, 0);
835 if (IS_DUALBUS(isp)) {
836 isp_setdfltparm(isp, 1);
846 isp_scsi_init(struct ispsoftc *isp)
848 sdparam *sdp_chan0, *sdp_chan1;
851 sdp_chan0 = isp->isp_param;
852 sdp_chan1 = sdp_chan0;
853 if (IS_DUALBUS(isp)) {
858 * If we have no role (neither target nor initiator), return.
860 if (isp->isp_role == ISP_ROLE_NONE) {
864 /* First do overall per-card settings. */
867 * If we have fast memory timing enabled, turn it on.
869 if (sdp_chan0->isp_fast_mttr) {
870 ISP_WRITE(isp, RISC_MTR, 0x1313);
874 * Set Retry Delay and Count.
875 * You set both channels at the same time.
877 mbs.param[0] = MBOX_SET_RETRY_COUNT;
878 mbs.param[1] = sdp_chan0->isp_retry_count;
879 mbs.param[2] = sdp_chan0->isp_retry_delay;
880 mbs.param[6] = sdp_chan1->isp_retry_count;
881 mbs.param[7] = sdp_chan1->isp_retry_delay;
883 isp_mboxcmd(isp, &mbs, MBLOGALL);
884 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
889 * Set ASYNC DATA SETUP time. This is very important.
891 mbs.param[0] = MBOX_SET_ASYNC_DATA_SETUP_TIME;
892 mbs.param[1] = sdp_chan0->isp_async_data_setup;
893 mbs.param[2] = sdp_chan1->isp_async_data_setup;
894 isp_mboxcmd(isp, &mbs, MBLOGALL);
895 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
900 * Set ACTIVE Negation State.
902 mbs.param[0] = MBOX_SET_ACT_NEG_STATE;
904 (sdp_chan0->isp_req_ack_active_neg << 4) |
905 (sdp_chan0->isp_data_line_active_neg << 5);
907 (sdp_chan1->isp_req_ack_active_neg << 4) |
908 (sdp_chan1->isp_data_line_active_neg << 5);
910 isp_mboxcmd(isp, &mbs, MBLOGNONE);
911 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
912 isp_prt(isp, ISP_LOGERR,
913 "failed to set active negation state (%d,%d), (%d,%d)",
914 sdp_chan0->isp_req_ack_active_neg,
915 sdp_chan0->isp_data_line_active_neg,
916 sdp_chan1->isp_req_ack_active_neg,
917 sdp_chan1->isp_data_line_active_neg);
924 * Set the Tag Aging limit
926 mbs.param[0] = MBOX_SET_TAG_AGE_LIMIT;
927 mbs.param[1] = sdp_chan0->isp_tag_aging;
928 mbs.param[2] = sdp_chan1->isp_tag_aging;
929 isp_mboxcmd(isp, &mbs, MBLOGALL);
930 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
931 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
932 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
937 * Set selection timeout.
939 mbs.param[0] = MBOX_SET_SELECT_TIMEOUT;
940 mbs.param[1] = sdp_chan0->isp_selection_timeout;
941 mbs.param[2] = sdp_chan1->isp_selection_timeout;
942 isp_mboxcmd(isp, &mbs, MBLOGALL);
943 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
947 /* now do per-channel settings */
948 isp_scsi_channel_init(isp, 0);
950 isp_scsi_channel_init(isp, 1);
953 * Now enable request/response queues
956 if (IS_ULTRA2(isp) || IS_1240(isp)) {
957 mbs.param[0] = MBOX_INIT_RES_QUEUE_A64;
958 mbs.param[1] = RESULT_QUEUE_LEN(isp);
959 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
960 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
962 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
963 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
964 isp_mboxcmd(isp, &mbs, MBLOGALL);
965 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
968 isp->isp_residx = mbs.param[5];
970 mbs.param[0] = MBOX_INIT_REQ_QUEUE_A64;
971 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
972 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
973 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
975 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
976 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
977 isp_mboxcmd(isp, &mbs, MBLOGALL);
978 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
981 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
983 mbs.param[0] = MBOX_INIT_RES_QUEUE;
984 mbs.param[1] = RESULT_QUEUE_LEN(isp);
985 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
986 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
988 isp_mboxcmd(isp, &mbs, MBLOGALL);
989 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
992 isp->isp_residx = mbs.param[5];
994 mbs.param[0] = MBOX_INIT_REQ_QUEUE;
995 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
996 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
997 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
999 isp_mboxcmd(isp, &mbs, MBLOGALL);
1000 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1003 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1007 * Turn on Fast Posting, LVD transitions
1009 * Ultra2 F/W always has had fast posting (and LVD transitions)
1011 * Ultra and older (i.e., SBus) cards may not. It's just safer
1012 * to assume not for them.
1015 mbs.param[0] = MBOX_SET_FW_FEATURES;
1018 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1020 if (IS_ULTRA2(isp) || IS_1240(isp))
1021 mbs.param[1] |= FW_FEATURE_RIO_16BIT;
1023 #ifndef ISP_NO_FASTPOST
1024 if (IS_ULTRA2(isp) || IS_1240(isp))
1025 mbs.param[1] |= FW_FEATURE_FAST_POST;
1028 if (mbs.param[1] != 0) {
1029 u_int16_t sfeat = mbs.param[1];
1030 isp_mboxcmd(isp, &mbs, MBLOGALL);
1031 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1032 isp_prt(isp, ISP_LOGINFO,
1033 "Enabled FW features (0x%x)", sfeat);
1038 * Let the outer layers decide whether to issue a SCSI bus reset.
1040 isp->isp_state = ISP_INITSTATE;
1044 isp_scsi_channel_init(struct ispsoftc *isp, int channel)
1050 sdp = isp->isp_param;
1054 * Set (possibly new) Initiator ID.
1056 mbs.param[0] = MBOX_SET_INIT_SCSI_ID;
1057 mbs.param[1] = (channel << 7) | sdp->isp_initiator_id;
1058 isp_mboxcmd(isp, &mbs, MBLOGALL);
1059 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1062 isp_prt(isp, ISP_LOGINFO, "Initiator ID is %d on Channel %d",
1063 sdp->isp_initiator_id, channel);
1067 * Set current per-target parameters to an initial safe minimum.
1069 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1073 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1076 #ifndef ISP_TARGET_MODE
1077 sdf = sdp->isp_devparam[tgt].goal_flags;
1078 sdf &= DPARM_SAFE_DFLT;
1080 * It is not quite clear when this changed over so that
1081 * we could force narrow and async for 1000/1020 cards,
1082 * but assume that this is only the case for loaded
1085 if (isp->isp_loaded_fw) {
1086 sdf |= DPARM_NARROW | DPARM_ASYNC;
1090 * The !$*!)$!$)* f/w uses the same index into some
1091 * internal table to decide how to respond to negotiations,
1092 * so if we've said "let's be safe" for ID X, and ID X
1093 * selects *us*, the negotiations will back to 'safe'
1094 * (as in narrow/async). What the f/w *should* do is
1095 * use the initiator id settings to decide how to respond.
1097 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1099 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1100 mbs.param[1] = (channel << 15) | (tgt << 8);
1102 if ((sdf & DPARM_SYNC) == 0) {
1106 (sdp->isp_devparam[tgt].goal_offset << 8) |
1107 (sdp->isp_devparam[tgt].goal_period);
1109 isp_prt(isp, ISP_LOGDEBUG0,
1110 "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1111 channel, tgt, mbs.param[2], mbs.param[3] >> 8,
1112 mbs.param[3] & 0xff);
1113 isp_mboxcmd(isp, &mbs, MBLOGNONE);
1114 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1115 sdf = DPARM_SAFE_DFLT;
1116 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1117 mbs.param[1] = (tgt << 8) | (channel << 15);
1120 isp_mboxcmd(isp, &mbs, MBLOGALL);
1121 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1127 * We don't update any information directly from the f/w
1128 * because we need to run at least one command to cause a
1129 * new state to be latched up. So, we just assume that we
1130 * converge to the values we just had set.
1132 * Ensure that we don't believe tagged queuing is enabled yet.
1133 * It turns out that sometimes the ISP just ignores our
1134 * attempts to set parameters for devices that it hasn't
1137 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1138 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1139 mbs.param[0] = MBOX_SET_DEV_QUEUE_PARAMS;
1140 mbs.param[1] = (channel << 15) | (tgt << 8) | lun;
1141 mbs.param[2] = sdp->isp_max_queue_depth;
1142 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1143 isp_mboxcmd(isp, &mbs, MBLOGALL);
1144 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1149 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1150 if (sdp->isp_devparam[tgt].dev_refresh) {
1151 isp->isp_sendmarker |= (1 << channel);
1152 isp->isp_update |= (1 << channel);
1159 * Fibre Channel specific initialization.
1161 * Locks are held before coming here.
1164 isp_fibre_init(struct ispsoftc *isp)
1167 isp_icb_t local, *icbp = &local;
1170 u_int64_t nwwn, pwwn;
1172 fcp = isp->isp_param;
1175 * Do this *before* initializing the firmware.
1177 isp_mark_getpdb_all(isp);
1178 fcp->isp_fwstate = FW_CONFIG_WAIT;
1179 fcp->isp_loopstate = LOOP_NIL;
1182 * If we have no role (neither target nor initiator), return.
1184 if (isp->isp_role == ISP_ROLE_NONE) {
1188 loopid = fcp->isp_loopid;
1189 MEMZERO(icbp, sizeof (*icbp));
1190 icbp->icb_version = ICB_VERSION1;
1193 * Firmware Options are either retrieved from NVRAM or
1194 * are patched elsewhere. We check them for sanity here
1195 * and make changes based on board revision, but otherwise
1196 * let others decide policy.
1200 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1202 if ((isp->isp_type == ISP_HA_FC_2100) && isp->isp_revision < 5) {
1203 fcp->isp_fwoptions &= ~ICBOPT_FAIRNESS;
1207 * We have to use FULL LOGIN even though it resets the loop too much
1208 * because otherwise port database entries don't get updated after
1209 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1211 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1212 fcp->isp_fwoptions |= ICBOPT_FULL_LOGIN;
1216 * Insist on Port Database Update Async notifications
1218 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
1221 * Make sure that target role reflects into fwoptions.
1223 if (isp->isp_role & ISP_ROLE_TARGET) {
1224 fcp->isp_fwoptions |= ICBOPT_TGT_ENABLE;
1226 fcp->isp_fwoptions &= ~ICBOPT_TGT_ENABLE;
1230 * Propagate all of this into the ICB structure.
1232 icbp->icb_fwoptions = fcp->isp_fwoptions;
1233 icbp->icb_maxfrmlen = fcp->isp_maxfrmlen;
1234 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN ||
1235 icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1236 isp_prt(isp, ISP_LOGERR,
1237 "bad frame length (%d) from NVRAM- using %d",
1238 fcp->isp_maxfrmlen, ICB_DFLT_FRMLEN);
1239 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1241 icbp->icb_maxalloc = fcp->isp_maxalloc;
1242 if (icbp->icb_maxalloc < 1) {
1243 isp_prt(isp, ISP_LOGERR,
1244 "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1245 icbp->icb_maxalloc = 16;
1247 icbp->icb_execthrottle = fcp->isp_execthrottle;
1248 if (icbp->icb_execthrottle < 1) {
1249 isp_prt(isp, ISP_LOGERR,
1250 "bad execution throttle of %d- using 16",
1251 fcp->isp_execthrottle);
1252 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1254 icbp->icb_retry_delay = fcp->isp_retry_delay;
1255 icbp->icb_retry_count = fcp->isp_retry_count;
1256 icbp->icb_hardaddr = loopid;
1258 * Right now we just set extended options to prefer point-to-point
1259 * over loop based upon some soft config options.
1261 * NB: for the 2300, ICBOPT_EXTENDED is required.
1263 if (IS_2200(isp) || IS_23XX(isp)) {
1264 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1266 * Prefer or force Point-To-Point instead Loop?
1268 switch(isp->isp_confopts & ISP_CFG_PORT_PREF) {
1270 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1272 case ISP_CFG_NPORT_ONLY:
1273 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1275 case ISP_CFG_LPORT_ONLY:
1276 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1279 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1284 * QLogic recommends that FAST Posting be turned
1285 * off for 23XX cards and instead allow the HBA
1286 * to write response queue entries and interrupt
1287 * after a delay (ZIO).
1289 * If we set ZIO, it will disable fast posting,
1290 * so we don't need to clear it in fwoptions.
1292 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1294 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1295 icbp->icb_zfwoptions |= ICBZOPT_RATE_ONEGB;
1296 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1297 icbp->icb_zfwoptions |= ICBZOPT_RATE_TWOGB;
1299 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1304 #ifndef ISP_NO_RIO_FC
1306 * RIO seems to be enabled in 2100s for fw >= 1.17.0.
1308 * I've had some questionable problems with RIO on 2200.
1309 * More specifically, on a 2204 I had problems with RIO
1310 * on a Linux system where I was dropping commands right
1311 * and left. It's not clear to me what the actual problem
1314 * 23XX Cards do not support RIO. Instead they support ZIO.
1317 if (!IS_23XX(isp) && ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1318 icbp->icb_xfwoptions |= ICBXOPT_RIO_16BIT;
1319 icbp->icb_racctimer = 4;
1320 icbp->icb_idelaytimer = 8;
1326 * For 22XX > 2.1.26 && 23XX, set someoptions.
1327 * XXX: Probably okay for newer 2100 f/w too.
1329 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1331 * Turn on LIP F8 async event (1)
1332 * Turn on generate AE 8013 on all LIP Resets (2)
1333 * Disable LIP F7 switching (8)
1335 mbs.param[0] = MBOX_SET_FIRMWARE_OPTIONS;
1339 isp_mboxcmd(isp, &mbs, MBLOGALL);
1341 icbp->icb_logintime = 30; /* 30 second login timeout */
1344 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
1345 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
1346 ISP_WRITE(isp, isp->isp_respinrp, 0);
1347 ISP_WRITE(isp, isp->isp_respoutrp, 0);
1350 nwwn = ISP_NODEWWN(isp);
1351 pwwn = ISP_PORTWWN(isp);
1353 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1354 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, nwwn);
1355 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, pwwn);
1356 isp_prt(isp, ISP_LOGDEBUG1,
1357 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1358 ((u_int32_t) (nwwn >> 32)),
1359 ((u_int32_t) (nwwn & 0xffffffff)),
1360 ((u_int32_t) (pwwn >> 32)),
1361 ((u_int32_t) (pwwn & 0xffffffff)));
1363 isp_prt(isp, ISP_LOGDEBUG1, "Not using any WWNs");
1364 icbp->icb_fwoptions &= ~(ICBOPT_BOTH_WWNS|ICBOPT_FULL_LOGIN);
1366 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1367 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1368 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1369 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1370 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1371 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1372 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1373 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1374 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1375 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1376 isp_prt(isp, ISP_LOGDEBUG0,
1377 "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1378 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1380 FC_SCRATCH_ACQUIRE(isp);
1381 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1386 mbs.param[0] = MBOX_INIT_FIRMWARE;
1388 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1389 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1392 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1393 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1394 isp_mboxcmd(isp, &mbs, MBLOGALL);
1395 FC_SCRATCH_RELEASE(isp);
1396 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1399 isp->isp_reqidx = isp->isp_reqodx = 0;
1400 isp->isp_residx = 0;
1401 isp->isp_sendmarker = 1;
1404 * Whatever happens, we're now committed to being here.
1406 isp->isp_state = ISP_INITSTATE;
1410 * Fibre Channel Support- get the port database for the id.
1412 * Locks are held before coming here. Return 0 if success,
1417 isp_getmap(struct ispsoftc *isp, fcpos_map_t *map)
1419 fcparam *fcp = (fcparam *) isp->isp_param;
1422 mbs.param[0] = MBOX_GET_FC_AL_POSITION_MAP;
1424 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1425 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1427 * Unneeded. For the 2100, except for initializing f/w, registers
1428 * 4/5 have to not be written to.
1435 FC_SCRATCH_ACQUIRE(isp);
1436 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1437 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1438 MEMCPY(map, fcp->isp_scratch, sizeof (fcpos_map_t));
1439 map->fwmap = mbs.param[1] != 0;
1440 FC_SCRATCH_RELEASE(isp);
1443 FC_SCRATCH_RELEASE(isp);
1448 isp_mark_getpdb_all(struct ispsoftc *isp)
1450 fcparam *fcp = (fcparam *) isp->isp_param;
1452 for (i = 0; i < MAX_FC_TARG; i++) {
1453 fcp->portdb[i].valid = fcp->portdb[i].fabric_dev = 0;
1458 isp_getpdb(struct ispsoftc *isp, int id, isp_pdb_t *pdbp)
1460 fcparam *fcp = (fcparam *) isp->isp_param;
1463 mbs.param[0] = MBOX_GET_PORT_DB;
1464 mbs.param[1] = id << 8;
1465 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1466 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1468 * Unneeded. For the 2100, except for initializing f/w, registers
1469 * 4/5 have to not be written to.
1474 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1475 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1476 FC_SCRATCH_ACQUIRE(isp);
1477 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1478 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1479 isp_get_pdb(isp, (isp_pdb_t *)fcp->isp_scratch, pdbp);
1480 FC_SCRATCH_RELEASE(isp);
1483 FC_SCRATCH_RELEASE(isp);
1488 isp_get_portname(struct ispsoftc *isp, int loopid, int nodename)
1493 mbs.param[0] = MBOX_GET_PORT_NAME;
1494 mbs.param[1] = loopid << 8;
1497 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1498 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1500 (((u_int64_t)(mbs.param[2] & 0xff)) << 56) |
1501 (((u_int64_t)(mbs.param[2] >> 8)) << 48) |
1502 (((u_int64_t)(mbs.param[3] & 0xff)) << 40) |
1503 (((u_int64_t)(mbs.param[3] >> 8)) << 32) |
1504 (((u_int64_t)(mbs.param[6] & 0xff)) << 24) |
1505 (((u_int64_t)(mbs.param[6] >> 8)) << 16) |
1506 (((u_int64_t)(mbs.param[7] & 0xff)) << 8) |
1507 (((u_int64_t)(mbs.param[7] >> 8)));
1513 * Make sure we have good FC link and know our Loop ID.
1517 isp_fclink_test(struct ispsoftc *isp, int usdelay)
1519 static char *toponames[] = {
1524 "F Port (no FLOGI_ACC response)"
1527 int count, check_for_fabric;
1533 fcp = isp->isp_param;
1536 * XXX: Here is where we would start a 'loop dead' timeout
1540 * Wait up to N microseconds for F/W to go to a ready state.
1542 lwfs = FW_CONFIG_WAIT;
1544 while (count < usdelay) {
1547 NANOTIME_T hra, hrb;
1551 if (lwfs != fcp->isp_fwstate) {
1552 isp_prt(isp, ISP_LOGINFO, "Firmware State <%s->%s>",
1553 isp2100_fw_statename((int)lwfs),
1554 isp2100_fw_statename((int)fcp->isp_fwstate));
1555 lwfs = fcp->isp_fwstate;
1557 if (fcp->isp_fwstate == FW_READY) {
1563 * Get the elapsed time in nanoseconds.
1564 * Always guaranteed to be non-zero.
1566 enano = NANOTIME_SUB(&hrb, &hra);
1568 isp_prt(isp, ISP_LOGDEBUG1,
1569 "usec%d: 0x%lx->0x%lx enano 0x%x%08x",
1570 count, (long) GET_NANOSEC(&hra), (long) GET_NANOSEC(&hrb),
1571 (u_int32_t)(enano >> 32), (u_int32_t)(enano & 0xffffffff));
1574 * If the elapsed time is less than 1 millisecond,
1575 * delay a period of time up to that millisecond of
1578 * This peculiar code is an attempt to try and avoid
1579 * invoking u_int64_t math support functions for some
1580 * platforms where linkage is a problem.
1582 if (enano < (1000 * 1000)) {
1584 enano = (1000 * 1000) - enano;
1585 while (enano > (u_int64_t) 4000000000U) {
1586 USEC_SLEEP(isp, 4000000);
1587 enano -= (u_int64_t) 4000000000U;
1591 USEC_SLEEP(isp, wrk);
1593 while (enano > (u_int64_t) 4000000000U) {
1595 enano -= (u_int64_t) 4000000000U;
1598 count += (wrk / 1000);
1603 * If we haven't gone to 'ready' state, return.
1605 if (fcp->isp_fwstate != FW_READY) {
1610 * Get our Loop ID (if possible). We really need to have it.
1612 mbs.param[0] = MBOX_GET_LOOP_ID;
1613 isp_mboxcmd(isp, &mbs, MBLOGALL);
1614 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1617 fcp->isp_loopid = mbs.param[1];
1618 if (IS_2200(isp) || IS_23XX(isp)) {
1619 int topo = (int) mbs.param[6];
1620 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB)
1621 topo = TOPO_PTP_STUB;
1622 fcp->isp_topo = topo;
1624 fcp->isp_topo = TOPO_NL_PORT;
1626 fcp->isp_portid = fcp->isp_alpa = mbs.param[2] & 0xff;
1629 * Check to see if we're on a fabric by trying to see if we
1630 * can talk to the fabric name server. This can be a bit
1631 * tricky because if we're a 2100, we should check always
1632 * (in case we're connected to an server doing aliasing).
1634 fcp->isp_onfabric = 0;
1638 * Don't bother with fabric if we are using really old
1639 * 2100 firmware. It's just not worth it.
1641 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37)) {
1642 check_for_fabric = 1;
1644 check_for_fabric = 0;
1646 } else if (fcp->isp_topo == TOPO_FL_PORT ||
1647 fcp->isp_topo == TOPO_F_PORT) {
1648 check_for_fabric = 1;
1650 check_for_fabric = 0;
1652 if (check_for_fabric && isp_getpdb(isp, FL_PORT_ID, &pdb) == 0) {
1653 int loopid = FL_PORT_ID;
1655 fcp->isp_topo = TOPO_FL_PORT;
1658 if (BITS2WORD(pdb.pdb_portid_bits) == 0) {
1662 fcp->isp_topo = TOPO_NL_PORT;
1665 fcp->isp_portid = mbs.param[2] | ((int) mbs.param[3] << 16);
1668 * Save the Fabric controller's port database entry.
1670 lp = &fcp->portdb[loopid];
1672 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1673 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1674 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1675 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1676 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1677 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1678 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1679 (((u_int64_t)pdb.pdb_nodename[7]));
1681 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1682 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1683 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1684 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1685 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1686 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1687 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1688 (((u_int64_t)pdb.pdb_portname[7]));
1690 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
1691 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
1692 lp->loopid = pdb.pdb_loopid;
1693 lp->loggedin = lp->valid = 1;
1694 fcp->isp_onfabric = 1;
1695 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1696 isp_register_fc4_type(isp);
1699 fcp->isp_onfabric = 0;
1700 fcp->portdb[FL_PORT_ID].valid = 0;
1703 fcp->isp_gbspeed = 1;
1705 mbs.param[0] = MBOX_GET_SET_DATA_RATE;
1706 mbs.param[1] = MBGSD_GET_RATE;
1707 /* mbs.param[2] undefined if we're just getting rate */
1708 isp_mboxcmd(isp, &mbs, MBLOGALL);
1709 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1710 if (mbs.param[1] == MBGSD_TWOGB) {
1711 isp_prt(isp, ISP_LOGINFO, "2Gb link speed/s");
1712 fcp->isp_gbspeed = 2;
1717 isp_prt(isp, ISP_LOGCONFIG, topology, fcp->isp_loopid, fcp->isp_alpa,
1718 fcp->isp_portid, fcp->isp_loopstate, toponames[fcp->isp_topo]);
1721 * Announce ourselves, too. This involves synthesizing an entry.
1723 if (fcp->isp_iid_set == 0) {
1724 fcp->isp_iid_set = 1;
1725 fcp->isp_iid = fcp->isp_loopid;
1726 lp = &fcp->portdb[fcp->isp_iid];
1728 lp = &fcp->portdb[fcp->isp_iid];
1729 if (fcp->isp_portid != lp->portid ||
1730 fcp->isp_loopid != lp->loopid ||
1731 fcp->isp_nodewwn != ISP_NODEWWN(isp) ||
1732 fcp->isp_portwwn != ISP_PORTWWN(isp)) {
1734 count = fcp->isp_iid;
1735 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1738 lp->loopid = fcp->isp_loopid;
1739 lp->portid = fcp->isp_portid;
1740 lp->node_wwn = ISP_NODEWWN(isp);
1741 lp->port_wwn = ISP_PORTWWN(isp);
1742 switch (isp->isp_role) {
1746 case ISP_ROLE_TARGET:
1747 lp->roles = SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT;
1749 case ISP_ROLE_INITIATOR:
1750 lp->roles = SVC3_INI_ROLE >> SVC3_ROLE_SHIFT;
1753 lp->roles = (SVC3_INI_ROLE|SVC3_TGT_ROLE) >> SVC3_ROLE_SHIFT;
1756 lp->loggedin = lp->valid = 1;
1757 count = fcp->isp_iid;
1758 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1763 isp2100_fw_statename(int state)
1766 case FW_CONFIG_WAIT: return "Config Wait";
1767 case FW_WAIT_AL_PA: return "Waiting for AL_PA";
1768 case FW_WAIT_LOGIN: return "Wait Login";
1769 case FW_READY: return "Ready";
1770 case FW_LOSS_OF_SYNC: return "Loss Of Sync";
1771 case FW_ERROR: return "Error";
1772 case FW_REINIT: return "Re-Init";
1773 case FW_NON_PART: return "Nonparticipating";
1774 default: return "?????";
1779 * Synchronize our soft copy of the port database with what the f/w thinks
1780 * (with a view toward possibly for a specific target....)
1784 isp_pdb_sync(struct ispsoftc *isp)
1787 fcparam *fcp = isp->isp_param;
1789 int loopid, base, lim;
1792 * Make sure we're okay for doing this right now.
1794 if (fcp->isp_loopstate != LOOP_PDB_RCVD &&
1795 fcp->isp_loopstate != LOOP_FSCAN_DONE &&
1796 fcp->isp_loopstate != LOOP_LSCAN_DONE) {
1800 if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_NL_PORT ||
1801 fcp->isp_topo == TOPO_N_PORT) {
1802 if (fcp->isp_loopstate < LOOP_LSCAN_DONE) {
1803 if (isp_scan_loop(isp) != 0) {
1808 fcp->isp_loopstate = LOOP_SYNCING_PDB;
1811 * If we get this far, we've settled our differences with the f/w
1812 * (for local loop device) and we can say that the loop state is ready.
1815 if (fcp->isp_topo == TOPO_NL_PORT) {
1816 fcp->loop_seen_once = 1;
1817 fcp->isp_loopstate = LOOP_READY;
1822 * Find all Fabric Entities that didn't make it from one scan to the
1823 * next and let the world know they went away. Scan the whole database.
1825 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[MAX_FC_TARG]; lp++) {
1826 if (lp->was_fabric_dev && lp->fabric_dev == 0) {
1827 loopid = lp - fcp->portdb;
1828 lp->valid = 0; /* should already be set */
1829 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1830 MEMZERO((void *) lp, sizeof (*lp));
1833 lp->was_fabric_dev = lp->fabric_dev;
1836 if (fcp->isp_topo == TOPO_FL_PORT)
1841 if (fcp->isp_topo == TOPO_N_PORT)
1847 * Now log in any fabric devices that the outer layer has
1848 * left for us to see. This seems the most sane policy
1851 for (lp = &fcp->portdb[base]; lp < &fcp->portdb[lim]; lp++) {
1855 loopid = lp - fcp->portdb;
1856 if (loopid >= FL_PORT_ID && loopid <= FC_SNS_ID) {
1863 if (lp->port_wwn == 0) {
1868 * Don't try to log into yourself.
1870 if ((portid = lp->portid) == fcp->isp_portid) {
1876 * If we'd been logged in- see if we still are and we haven't
1877 * changed. If so, no need to log ourselves out, etc..
1879 * Unfortunately, our charming Qlogic f/w has decided to
1880 * return a valid port database entry for a fabric device
1881 * that has, in fact, gone away. And it hangs trying to
1884 if (lp->loggedin && lp->force_logout == 0 &&
1885 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
1887 u_int64_t nwwnn, nwwpn;
1889 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
1890 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
1891 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
1892 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
1893 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
1894 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
1895 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
1896 (((u_int64_t)pdb.pdb_nodename[7]));
1898 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
1899 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
1900 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
1901 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
1902 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
1903 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
1904 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
1905 (((u_int64_t)pdb.pdb_portname[7]));
1906 nrole = (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >>
1908 if (pdb.pdb_loopid == lp->loopid && lp->portid ==
1909 (u_int32_t) BITS2WORD(pdb.pdb_portid_bits) &&
1910 nwwnn == lp->node_wwn && nwwpn == lp->port_wwn &&
1911 lp->roles == nrole && lp->force_logout == 0) {
1912 lp->loggedin = lp->valid = 1;
1913 isp_prt(isp, ISP_LOGCONFIG, lretained,
1914 (int) (lp - fcp->portdb),
1915 (int) lp->loopid, lp->portid);
1920 if (fcp->isp_fwstate != FW_READY ||
1921 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1926 * Force a logout if we were logged in.
1929 if (lp->force_logout ||
1930 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
1931 mbs.param[0] = MBOX_FABRIC_LOGOUT;
1932 mbs.param[1] = lp->loopid << 8;
1935 isp_mboxcmd(isp, &mbs, MBLOGNONE);
1936 isp_prt(isp, ISP_LOGINFO, plogout,
1937 (int) (lp - fcp->portdb), lp->loopid,
1940 lp->force_logout = lp->loggedin = 0;
1941 if (fcp->isp_fwstate != FW_READY ||
1942 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1950 loopid = lp - fcp->portdb;
1951 lp->loopid = FL_PORT_ID;
1953 mbs.param[0] = MBOX_FABRIC_LOGIN;
1954 mbs.param[1] = loopid << 8;
1955 mbs.param[2] = portid >> 16;
1956 mbs.param[3] = portid & 0xffff;
1957 isp_mboxcmd(isp, &mbs, MBLOGALL & ~(MBOX_LOOP_ID_USED |
1958 MBOX_PORT_ID_USED | MBOX_COMMAND_ERROR));
1959 if (fcp->isp_fwstate != FW_READY ||
1960 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
1963 switch (mbs.param[0]) {
1964 case MBOX_LOOP_ID_USED:
1966 * Try the next available loop id.
1970 case MBOX_PORT_ID_USED:
1972 * This port is already logged in.
1973 * Snaffle the loop id it's using if it's
1974 * nonzero, otherwise we're hosed.
1976 if (mbs.param[1] != 0) {
1977 loopid = mbs.param[1];
1978 isp_prt(isp, ISP_LOGINFO, retained,
1979 loopid, (int) (lp - fcp->portdb),
1982 loopid = MAX_FC_TARG;
1986 case MBOX_COMMAND_COMPLETE:
1988 lp->loopid = loopid;
1990 case MBOX_COMMAND_ERROR:
1991 isp_prt(isp, ISP_LOGINFO, plogierr,
1992 portid, mbs.param[1]);
1994 case MBOX_ALL_IDS_USED: /* We're outta IDs */
1996 loopid = MAX_FC_TARG;
1999 } while (lp->loopid == FL_PORT_ID && loopid < MAX_FC_TARG);
2002 * If we get here and we haven't set a Loop ID,
2003 * we failed to log into this device.
2006 if (lp->loopid == FL_PORT_ID) {
2012 * Make sure we can get the approriate port information.
2014 if (isp_getpdb(isp, lp->loopid, &pdb) != 0) {
2015 isp_prt(isp, ISP_LOGWARN, nopdb, lp->portid);
2019 if (fcp->isp_fwstate != FW_READY ||
2020 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2024 if (pdb.pdb_loopid != lp->loopid) {
2025 isp_prt(isp, ISP_LOGWARN, pdbmfail1,
2026 lp->portid, pdb.pdb_loopid);
2030 if (lp->portid != (u_int32_t) BITS2WORD(pdb.pdb_portid_bits)) {
2031 isp_prt(isp, ISP_LOGWARN, pdbmfail2,
2032 lp->portid, BITS2WORD(pdb.pdb_portid_bits));
2037 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2039 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
2040 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
2041 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
2042 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
2043 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
2044 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
2045 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
2046 (((u_int64_t)pdb.pdb_nodename[7]));
2048 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
2049 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
2050 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
2051 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
2052 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
2053 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
2054 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
2055 (((u_int64_t)pdb.pdb_portname[7]));
2057 * Check to make sure this all makes sense.
2059 if (lp->node_wwn && lp->port_wwn) {
2061 loopid = lp - fcp->portdb;
2062 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2067 isp_prt(isp, ISP_LOGINFO,
2068 ldumped, loopid, lp->loopid, lp->portid);
2069 mbs.param[0] = MBOX_FABRIC_LOGOUT;
2070 mbs.param[1] = lp->loopid << 8;
2073 isp_mboxcmd(isp, &mbs, MBLOGNONE);
2074 if (fcp->isp_fwstate != FW_READY ||
2075 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2080 * If we get here, we've for sure seen not only a valid loop
2081 * but know what is or isn't on it, so mark this for usage
2084 fcp->loop_seen_once = 1;
2085 fcp->isp_loopstate = LOOP_READY;
2090 isp_scan_loop(struct ispsoftc *isp)
2093 fcparam *fcp = isp->isp_param;
2095 int loopid, lim, hival;
2097 switch (fcp->isp_topo) {
2108 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2111 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
2114 * make sure the temp port database is clean...
2116 MEMZERO((void *)fcp->tport, sizeof (fcp->tport));
2119 * Run through the local loop ports and get port database info
2122 * There's a somewhat unexplained situation where the f/w passes back
2123 * the wrong database entity- if that happens, just restart (up to
2124 * FL_PORT_ID times).
2126 for (lim = loopid = 0; loopid < hival; loopid++) {
2127 lp = &fcp->tport[loopid];
2130 * Don't even try for ourselves...
2132 if (loopid == fcp->isp_loopid)
2135 lp->node_wwn = isp_get_portname(isp, loopid, 1);
2136 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2138 if (lp->node_wwn == 0)
2140 lp->port_wwn = isp_get_portname(isp, loopid, 0);
2141 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2143 if (lp->port_wwn == 0) {
2151 if (isp_getpdb(isp, loopid, &pdb) != 0) {
2152 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
2156 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2161 * If the returned database element doesn't match what we
2162 * asked for, restart the process entirely (up to a point...).
2164 if (pdb.pdb_loopid != loopid) {
2166 if (lim++ < hival) {
2169 isp_prt(isp, ISP_LOGWARN,
2170 "giving up on synchronizing the port database");
2175 * Save the pertinent info locally.
2178 (((u_int64_t)pdb.pdb_nodename[0]) << 56) |
2179 (((u_int64_t)pdb.pdb_nodename[1]) << 48) |
2180 (((u_int64_t)pdb.pdb_nodename[2]) << 40) |
2181 (((u_int64_t)pdb.pdb_nodename[3]) << 32) |
2182 (((u_int64_t)pdb.pdb_nodename[4]) << 24) |
2183 (((u_int64_t)pdb.pdb_nodename[5]) << 16) |
2184 (((u_int64_t)pdb.pdb_nodename[6]) << 8) |
2185 (((u_int64_t)pdb.pdb_nodename[7]));
2187 (((u_int64_t)pdb.pdb_portname[0]) << 56) |
2188 (((u_int64_t)pdb.pdb_portname[1]) << 48) |
2189 (((u_int64_t)pdb.pdb_portname[2]) << 40) |
2190 (((u_int64_t)pdb.pdb_portname[3]) << 32) |
2191 (((u_int64_t)pdb.pdb_portname[4]) << 24) |
2192 (((u_int64_t)pdb.pdb_portname[5]) << 16) |
2193 (((u_int64_t)pdb.pdb_portname[6]) << 8) |
2194 (((u_int64_t)pdb.pdb_portname[7]));
2196 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2197 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
2198 lp->loopid = pdb.pdb_loopid;
2202 * Mark all of the permanent local loop database entries as invalid
2203 * (except our own entry).
2205 for (loopid = 0; loopid < hival; loopid++) {
2206 if (loopid == fcp->isp_iid) {
2207 fcp->portdb[loopid].valid = 1;
2208 fcp->portdb[loopid].loopid = fcp->isp_loopid;
2211 fcp->portdb[loopid].valid = 0;
2215 * Now merge our local copy of the port database into our saved copy.
2216 * Notify the outer layers of new devices arriving.
2218 for (loopid = 0; loopid < hival; loopid++) {
2222 * If we don't have a non-zero Port WWN, we're not here.
2224 if (fcp->tport[loopid].port_wwn == 0) {
2231 if (loopid == fcp->isp_iid) {
2236 * For the purposes of deciding whether this is the
2237 * 'same' device or not, we only search for an identical
2238 * Port WWN. Node WWNs may or may not be the same as
2239 * the Port WWN, and there may be multiple different
2240 * Port WWNs with the same Node WWN. It would be chaos
2241 * to have multiple identical Port WWNs, so we don't
2245 for (i = 0; i < hival; i++) {
2247 if (fcp->portdb[i].port_wwn == 0)
2249 if (fcp->portdb[i].port_wwn !=
2250 fcp->tport[loopid].port_wwn)
2253 * We found this WWN elsewhere- it's changed
2254 * loopids then. We don't change it's actual
2255 * position in our cached port database- we
2256 * just change the actual loop ID we'd use.
2258 if (fcp->portdb[i].loopid != loopid) {
2259 isp_prt(isp, ISP_LOGINFO, portshift, i,
2260 fcp->portdb[i].loopid,
2261 fcp->portdb[i].portid, loopid,
2262 fcp->tport[loopid].portid);
2264 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2265 fcp->portdb[i].loopid = loopid;
2266 fcp->portdb[i].valid = 1;
2267 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2270 * Now make sure this Port WWN doesn't exist elsewhere
2271 * in the port database.
2273 for (j = i+1; j < hival; j++) {
2274 if (fcp->portdb[i].port_wwn !=
2275 fcp->portdb[j].port_wwn) {
2278 isp_prt(isp, ISP_LOGWARN, portdup, j, i);
2280 * Invalidate the 'old' *and* 'new' ones.
2281 * This is really harsh and not quite right,
2282 * but if this happens, we really don't know
2283 * who is what at this point.
2285 fcp->portdb[i].valid = 0;
2286 fcp->portdb[j].valid = 0;
2292 * If we didn't traverse the entire port database,
2293 * then we found (and remapped) an existing entry.
2294 * No need to notify anyone- go for the next one.
2297 isp_prt(isp, ISP_LOGINFO, retained,
2298 fcp->portdb[i].loopid, i, fcp->portdb[i].portid);
2303 * We've not found this Port WWN anywhere. It's a new entry.
2304 * See if we can leave it where it is (with target == loopid).
2306 if (fcp->portdb[loopid].port_wwn != 0) {
2307 for (lim = 0; lim < hival; lim++) {
2308 if (fcp->portdb[lim].port_wwn == 0)
2311 /* "Cannot Happen" */
2313 isp_prt(isp, ISP_LOGWARN, "Remap Overflow");
2322 * NB: The actual loopid we use here is loopid- we may
2323 * in fact be at a completely different index (target).
2325 fcp->portdb[i].loopid = loopid;
2326 fcp->portdb[i].port_wwn = fcp->tport[loopid].port_wwn;
2327 fcp->portdb[i].node_wwn = fcp->tport[loopid].node_wwn;
2328 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2329 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2330 fcp->portdb[i].valid = 1;
2333 * Tell the outside world we've arrived.
2335 (void) isp_async(isp, ISPASYNC_PROMENADE, &i);
2339 * Now find all previously used targets that are now invalid and
2340 * notify the outer layers that they're gone.
2342 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[hival]; lp++) {
2343 if (lp->valid || lp->port_wwn == 0) {
2348 * Tell the outside world we've gone
2349 * away and erase our pdb entry.
2352 loopid = lp - fcp->portdb;
2353 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2354 MEMZERO((void *) lp, sizeof (*lp));
2356 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2362 isp_fabric_mbox_cmd(struct ispsoftc *isp, mbreg_t *mbp)
2364 isp_mboxcmd(isp, mbp, MBLOGNONE);
2365 if (mbp->param[0] != MBOX_COMMAND_COMPLETE) {
2366 if (FCPARAM(isp)->isp_loopstate == LOOP_SCANNING_FABRIC) {
2367 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
2369 if (mbp->param[0] == MBOX_COMMAND_ERROR) {
2372 switch (mbp->param[1]) {
2377 m = "Failed to allocate IOCB buffer";
2380 m = "Failed to allocate XCB buffer";
2383 m = "timeout or transmit failed";
2386 m = "no fabric loop";
2389 m = "remote device not a target";
2392 SNPRINTF(tbuf, sizeof tbuf, "%x",
2397 isp_prt(isp, ISP_LOGERR, "SNS Failed- %s", m);
2402 if (FCPARAM(isp)->isp_fwstate != FW_READY ||
2403 FCPARAM(isp)->isp_loopstate < LOOP_SCANNING_FABRIC) {
2409 #ifdef ISP_USE_GA_NXT
2411 isp_scan_fabric(struct ispsoftc *isp, int ftype)
2413 fcparam *fcp = isp->isp_param;
2414 u_int32_t portid, first_portid, last_portid;
2415 int hicap, last_port_same;
2417 if (fcp->isp_onfabric == 0) {
2418 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2422 FC_SCRATCH_ACQUIRE(isp);
2425 * Since Port IDs are 24 bits, we can check against having seen
2426 * anything yet with this value.
2429 last_portid = 0xffffffff; /* not a port */
2430 first_portid = portid = fcp->isp_portid;
2431 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2433 for (hicap = 0; hicap < GA_NXT_MAX; hicap++) {
2436 sns_ga_nxt_rsp_t *rs0, *rs1;
2438 u_int8_t sc[SNS_GA_NXT_RESP_SIZE];
2440 rq = (sns_screq_t *)sc;
2441 MEMZERO((void *) rq, SNS_GA_NXT_REQ_SIZE);
2442 rq->snscb_rblen = SNS_GA_NXT_RESP_SIZE >> 1;
2443 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+0x100);
2444 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+0x100);
2445 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+0x100);
2446 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+0x100);
2447 rq->snscb_sblen = 6;
2448 rq->snscb_data[0] = SNS_GA_NXT;
2449 rq->snscb_data[4] = portid & 0xffff;
2450 rq->snscb_data[5] = (portid >> 16) & 0xff;
2451 isp_put_sns_request(isp, rq, (sns_screq_t *) fcp->isp_scratch);
2452 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GA_NXT_REQ_SIZE);
2453 mbs.param[0] = MBOX_SEND_SNS;
2454 mbs.param[1] = SNS_GA_NXT_REQ_SIZE >> 1;
2455 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2456 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2458 * Leave 4 and 5 alone
2460 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2461 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2462 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2463 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2464 fcp->isp_loopstate = LOOP_PDB_RCVD;
2466 FC_SCRATCH_RELEASE(isp);
2469 MEMORYBARRIER(isp, SYNC_SFORCPU, 0x100, SNS_GA_NXT_RESP_SIZE);
2470 rs1 = (sns_ga_nxt_rsp_t *) sc;
2471 rs0 = (sns_ga_nxt_rsp_t *) ((u_int8_t *)fcp->isp_scratch+0x100);
2472 isp_get_ga_nxt_response(isp, rs0, rs1);
2473 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2475 if (rs1->snscb_cthdr.ct_reason == 9 &&
2476 rs1->snscb_cthdr.ct_explanation == 7)
2477 level = ISP_LOGDEBUG0;
2479 level = ISP_LOGWARN;
2480 isp_prt(isp, level, swrej, "GA_NXT",
2481 rs1->snscb_cthdr.ct_reason,
2482 rs1->snscb_cthdr.ct_explanation, portid);
2483 FC_SCRATCH_RELEASE(isp);
2484 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2488 (((u_int32_t) rs1->snscb_port_id[0]) << 16) |
2489 (((u_int32_t) rs1->snscb_port_id[1]) << 8) |
2490 (((u_int32_t) rs1->snscb_port_id[2]));
2493 * XXX: We should check to make sure that this entry
2494 * XXX: supports the type(s) we are interested in.
2497 * Okay, we now have information about a fabric object.
2498 * If it is the type we're interested in, tell the outer layers
2499 * about it. The outer layer needs to know: Port ID, WWNN,
2500 * WWPN, FC4 type, and port type.
2502 * The lportdb structure is adequate for this.
2504 MEMZERO(&lcl, sizeof (lcl));
2505 lcl.port_type = rs1->snscb_port_type;
2506 lcl.fc4_type = ftype;
2507 lcl.portid = portid;
2509 (((u_int64_t)rs1->snscb_nodename[0]) << 56) |
2510 (((u_int64_t)rs1->snscb_nodename[1]) << 48) |
2511 (((u_int64_t)rs1->snscb_nodename[2]) << 40) |
2512 (((u_int64_t)rs1->snscb_nodename[3]) << 32) |
2513 (((u_int64_t)rs1->snscb_nodename[4]) << 24) |
2514 (((u_int64_t)rs1->snscb_nodename[5]) << 16) |
2515 (((u_int64_t)rs1->snscb_nodename[6]) << 8) |
2516 (((u_int64_t)rs1->snscb_nodename[7]));
2518 (((u_int64_t)rs1->snscb_portname[0]) << 56) |
2519 (((u_int64_t)rs1->snscb_portname[1]) << 48) |
2520 (((u_int64_t)rs1->snscb_portname[2]) << 40) |
2521 (((u_int64_t)rs1->snscb_portname[3]) << 32) |
2522 (((u_int64_t)rs1->snscb_portname[4]) << 24) |
2523 (((u_int64_t)rs1->snscb_portname[5]) << 16) |
2524 (((u_int64_t)rs1->snscb_portname[6]) << 8) |
2525 (((u_int64_t)rs1->snscb_portname[7]));
2528 * Does this fabric object support the type we want?
2531 if (rs1->snscb_fc4_types[ftype >> 5] & (1 << (ftype & 0x1f))) {
2532 if (first_portid == portid) {
2533 lcl.last_fabric_dev = 1;
2535 lcl.last_fabric_dev = 0;
2537 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2539 isp_prt(isp, ISP_LOGDEBUG0,
2540 "PortID 0x%x doesn't support FC4 type 0x%x",
2543 if (first_portid == portid) {
2544 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2545 FC_SCRATCH_RELEASE(isp);
2548 if (portid == last_portid) {
2549 if (last_port_same++ > 20) {
2550 isp_prt(isp, ISP_LOGWARN,
2551 "tangled fabric database detected");
2555 last_port_same = 0 ;
2556 last_portid = portid;
2559 FC_SCRATCH_RELEASE(isp);
2560 if (hicap >= GA_NXT_MAX) {
2561 isp_prt(isp, ISP_LOGWARN, "fabric too big (> %d)", GA_NXT_MAX);
2563 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2567 #define GIDLEN ((ISP2100_SCRLEN >> 1) + 16)
2568 #define NGENT ((GIDLEN - 16) >> 2)
2570 #define IGPOFF (ISP2100_SCRLEN - GIDLEN)
2574 isp_scan_fabric(struct ispsoftc *isp, int ftype)
2576 fcparam *fcp = FCPARAM(isp);
2579 sns_gid_ft_req_t *rq;
2580 sns_gid_ft_rsp_t *rs0, *rs1;
2582 if (fcp->isp_onfabric == 0) {
2583 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2587 FC_SCRATCH_ACQUIRE(isp);
2588 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2590 rq = (sns_gid_ft_req_t *)fcp->tport;
2591 MEMZERO((void *) rq, SNS_GID_FT_REQ_SIZE);
2592 rq->snscb_rblen = GIDLEN >> 1;
2593 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+IGPOFF);
2594 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+IGPOFF);
2595 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+IGPOFF);
2596 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+IGPOFF);
2597 rq->snscb_sblen = 6;
2598 rq->snscb_cmd = SNS_GID_FT;
2599 rq->snscb_mword_div_2 = NGENT;
2600 rq->snscb_fc4_type = ftype;
2601 isp_put_gid_ft_request(isp, rq, (sns_gid_ft_req_t *) fcp->isp_scratch);
2602 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE);
2603 mbs.param[0] = MBOX_SEND_SNS;
2604 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
2605 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2606 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2609 * Leave 4 and 5 alone
2611 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2612 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2613 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2614 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2615 fcp->isp_loopstate = LOOP_PDB_RCVD;
2617 FC_SCRATCH_RELEASE(isp);
2620 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2621 FC_SCRATCH_RELEASE(isp);
2624 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN);
2625 rs1 = (sns_gid_ft_rsp_t *) fcp->tport;
2626 rs0 = (sns_gid_ft_rsp_t *) ((u_int8_t *)fcp->isp_scratch+IGPOFF);
2627 isp_get_gid_ft_response(isp, rs0, rs1, NGENT);
2628 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2630 if (rs1->snscb_cthdr.ct_reason == 9 &&
2631 rs1->snscb_cthdr.ct_explanation == 7)
2632 level = ISP_LOGDEBUG0;
2634 level = ISP_LOGWARN;
2635 isp_prt(isp, level, swrej, "GID_FT",
2636 rs1->snscb_cthdr.ct_reason,
2637 rs1->snscb_cthdr.ct_explanation, 0);
2638 FC_SCRATCH_RELEASE(isp);
2639 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2644 * Okay, we now have a list of Port IDs for this class of device.
2645 * Go through the list and for each one get the WWPN/WWNN for it
2646 * and tell the outer layers about it. The outer layer needs to
2647 * know: Port ID, WWNN, WWPN, FC4 type, and (possibly) port type.
2649 * The lportdb structure is adequate for this.
2653 sns_gxn_id_req_t grqbuf, *gq = &grqbuf;
2654 sns_gxn_id_rsp_t *gs0, grsbuf, *gs1 = &grsbuf;
2657 sns_gff_id_rsp_t *fs0, ffsbuf, *fs1 = &ffsbuf;
2661 MEMZERO(&lcl, sizeof (lcl));
2662 lcl.fc4_type = ftype;
2664 (((u_int32_t) rs1->snscb_ports[i].portid[0]) << 16) |
2665 (((u_int32_t) rs1->snscb_ports[i].portid[1]) << 8) |
2666 (((u_int32_t) rs1->snscb_ports[i].portid[2]));
2668 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2669 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2670 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2671 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2672 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2673 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2674 gq->snscb_sblen = 6;
2675 gq->snscb_cmd = SNS_GPN_ID;
2676 gq->snscb_portid = lcl.portid;
2677 isp_put_gxn_id_request(isp, gq,
2678 (sns_gxn_id_req_t *) fcp->isp_scratch);
2679 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2680 mbs.param[0] = MBOX_SEND_SNS;
2681 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2682 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2683 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2685 * Leave 4 and 5 alone
2687 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2688 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2689 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2690 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2691 fcp->isp_loopstate = LOOP_PDB_RCVD;
2693 FC_SCRATCH_RELEASE(isp);
2696 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2697 FC_SCRATCH_RELEASE(isp);
2700 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2701 gs0 = (sns_gxn_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2702 isp_get_gxn_id_response(isp, gs0, gs1);
2703 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2704 isp_prt(isp, ISP_LOGWARN, swrej, "GPN_ID",
2705 gs1->snscb_cthdr.ct_reason,
2706 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2707 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2708 FC_SCRATCH_RELEASE(isp);
2714 (((u_int64_t)gs1->snscb_wwn[0]) << 56) |
2715 (((u_int64_t)gs1->snscb_wwn[1]) << 48) |
2716 (((u_int64_t)gs1->snscb_wwn[2]) << 40) |
2717 (((u_int64_t)gs1->snscb_wwn[3]) << 32) |
2718 (((u_int64_t)gs1->snscb_wwn[4]) << 24) |
2719 (((u_int64_t)gs1->snscb_wwn[5]) << 16) |
2720 (((u_int64_t)gs1->snscb_wwn[6]) << 8) |
2721 (((u_int64_t)gs1->snscb_wwn[7]));
2723 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2724 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2725 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2726 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2727 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2728 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2729 gq->snscb_sblen = 6;
2730 gq->snscb_cmd = SNS_GNN_ID;
2731 gq->snscb_portid = lcl.portid;
2732 isp_put_gxn_id_request(isp, gq,
2733 (sns_gxn_id_req_t *) fcp->isp_scratch);
2734 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2735 mbs.param[0] = MBOX_SEND_SNS;
2736 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2737 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2738 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2740 * Leave 4 and 5 alone
2742 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2743 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2744 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2745 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2746 fcp->isp_loopstate = LOOP_PDB_RCVD;
2748 FC_SCRATCH_RELEASE(isp);
2751 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2752 FC_SCRATCH_RELEASE(isp);
2755 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2756 gs0 = (sns_gxn_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2757 isp_get_gxn_id_response(isp, gs0, gs1);
2758 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2759 isp_prt(isp, ISP_LOGWARN, swrej, "GNN_ID",
2760 gs1->snscb_cthdr.ct_reason,
2761 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2762 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2763 FC_SCRATCH_RELEASE(isp);
2769 (((u_int64_t)gs1->snscb_wwn[0]) << 56) |
2770 (((u_int64_t)gs1->snscb_wwn[1]) << 48) |
2771 (((u_int64_t)gs1->snscb_wwn[2]) << 40) |
2772 (((u_int64_t)gs1->snscb_wwn[3]) << 32) |
2773 (((u_int64_t)gs1->snscb_wwn[4]) << 24) |
2774 (((u_int64_t)gs1->snscb_wwn[5]) << 16) |
2775 (((u_int64_t)gs1->snscb_wwn[6]) << 8) |
2776 (((u_int64_t)gs1->snscb_wwn[7]));
2779 * The QLogic f/w is bouncing this with a parameter error.
2783 * Try and get FC4 Features (FC-GS-3 only).
2784 * We can use the sns_gxn_id_req_t for this request.
2786 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2787 gq->snscb_rblen = SNS_GFF_ID_RESP_SIZE >> 1;
2788 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2789 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2790 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2791 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2792 gq->snscb_sblen = 6;
2793 gq->snscb_cmd = SNS_GFF_ID;
2794 gq->snscb_portid = lcl.portid;
2795 isp_put_gxn_id_request(isp, gq,
2796 (sns_gxn_id_req_t *) fcp->isp_scratch);
2797 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2798 mbs.param[0] = MBOX_SEND_SNS;
2799 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2800 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2801 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2803 * Leave 4 and 5 alone
2805 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2806 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2807 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2808 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2809 fcp->isp_loopstate = LOOP_PDB_RCVD;
2811 FC_SCRATCH_RELEASE(isp);
2814 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2815 FC_SCRATCH_RELEASE(isp);
2818 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GFF_ID_RESP_SIZE);
2819 fs0 = (sns_gff_id_rsp_t *) ((u_int8_t *)fcp->isp_scratch+GXOFF);
2820 isp_get_gff_id_response(isp, fs0, fs1);
2821 if (fs1->snscb_cthdr.ct_response != FS_ACC) {
2822 isp_prt(isp, /* ISP_LOGDEBUG0 */ ISP_LOGWARN,
2824 fs1->snscb_cthdr.ct_reason,
2825 fs1->snscb_cthdr.ct_explanation, lcl.portid);
2826 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2827 FC_SCRATCH_RELEASE(isp);
2831 int index = (ftype >> 3);
2832 int bshft = (ftype & 0x7) * 4;
2834 (fs1->snscb_fc4_features[index] >> bshft) & 0xf;
2835 if (fc4_fval & 0x1) {
2837 (SVC3_INI_ROLE >> SVC3_ROLE_SHIFT);
2839 if (fc4_fval & 0x2) {
2841 (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT);
2847 * If we really want to know what kind of port type this is,
2848 * we have to run another CT command. Otherwise, we'll leave
2853 if (rs1->snscb_ports[i].control & 0x80) {
2854 lcl.last_fabric_dev = 1;
2856 lcl.last_fabric_dev = 0;
2858 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2860 } while ((rs1->snscb_ports[i].control & 0x80) == 0 && i < NGENT-1);
2863 * If we're not at the last entry, our list isn't big enough.
2865 if ((rs1->snscb_ports[i].control & 0x80) == 0) {
2866 isp_prt(isp, ISP_LOGWARN, "fabric too big for scratch area");
2869 FC_SCRATCH_RELEASE(isp);
2870 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2876 isp_register_fc4_type(struct ispsoftc *isp)
2878 fcparam *fcp = isp->isp_param;
2879 u_int8_t local[SNS_RFT_ID_REQ_SIZE];
2880 sns_screq_t *reqp = (sns_screq_t *) local;
2883 MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
2884 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
2885 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
2886 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
2887 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
2888 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
2889 reqp->snscb_sblen = 22;
2890 reqp->snscb_data[0] = SNS_RFT_ID;
2891 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
2892 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
2893 reqp->snscb_data[6] = (1 << FC4_SCSI);
2895 reqp->snscb_data[6] |= (1 << FC4_IP); /* ISO/IEC 8802-2 LLC/SNAP */
2897 FC_SCRATCH_ACQUIRE(isp);
2898 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
2899 mbs.param[0] = MBOX_SEND_SNS;
2900 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
2901 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2902 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2904 * Leave 4 and 5 alone
2906 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2907 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2908 isp_mboxcmd(isp, &mbs, MBLOGALL);
2909 FC_SCRATCH_RELEASE(isp);
2910 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
2911 isp_prt(isp, ISP_LOGDEBUG0, "Register FC4 types succeeded");
2916 * Start a command. Locking is assumed done in the caller.
2922 struct ispsoftc *isp;
2923 u_int16_t nxti, optr, handle;
2924 u_int8_t local[QENTRY_LEN];
2925 ispreq_t *reqp, *qep;
2932 * Check to make sure we're supporting initiator role.
2934 if ((isp->isp_role & ISP_ROLE_INITIATOR) == 0) {
2935 XS_SETERR(xs, HBA_SELTIMEOUT);
2936 return (CMD_COMPLETE);
2940 * Now make sure we're running.
2943 if (isp->isp_state != ISP_RUNSTATE) {
2944 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
2945 XS_SETERR(xs, HBA_BOTCH);
2946 return (CMD_COMPLETE);
2950 * Check command CDB length, etc.. We really are limited to 16 bytes
2951 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
2952 * but probably only if we're running fairly new firmware (we'll
2953 * let the old f/w choke on an extended command queue entry).
2956 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
2957 isp_prt(isp, ISP_LOGERR,
2958 "unsupported cdb length (%d, CDB[0]=0x%x)",
2959 XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
2960 XS_SETERR(xs, HBA_BOTCH);
2961 return (CMD_COMPLETE);
2965 * Check to see whether we have good firmware state still or
2966 * need to refresh our port database for this target.
2968 target = XS_TGT(xs);
2970 fcparam *fcp = isp->isp_param;
2972 #ifdef HANDLE_LOOPSTATE_IN_OUTER_LAYERS
2973 if (fcp->isp_fwstate != FW_READY ||
2974 fcp->isp_loopstate != LOOP_READY) {
2975 return (CMD_RQLATER);
2979 * If we're not on a Fabric, we can't have a target
2980 * above FL_PORT_ID-1.
2982 * If we're on a fabric and *not* connected as an F-port,
2983 * we can't have a target less than FC_SNS_ID+1. This
2984 * keeps us from having to sort out the difference between
2985 * local public loop devices and those which we might get
2986 * from a switch's database.
2988 if (fcp->isp_onfabric == 0) {
2989 if (target >= FL_PORT_ID) {
2990 XS_SETERR(xs, HBA_SELTIMEOUT);
2991 return (CMD_COMPLETE);
2994 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
2995 XS_SETERR(xs, HBA_SELTIMEOUT);
2996 return (CMD_COMPLETE);
2999 * We used to exclude having local loop ports
3000 * at the same time that we have fabric ports.
3001 * That is, we used to exclude having ports
3002 * at < FL_PORT_ID if we're FL-port.
3004 * That's wrong. The only thing that could be
3005 * dicey is if the switch you're connected to
3006 * has these local loop ports appear on the
3007 * fabric and we somehow attach them twice.
3012 * Check for f/w being in ready state. If the f/w
3013 * isn't in ready state, then we don't know our
3014 * loop ID and the f/w hasn't completed logging
3015 * into all targets on the loop. If this is the
3016 * case, then bounce the command. We pretend this is
3017 * a SELECTION TIMEOUT error if we've never gone to
3018 * FW_READY state at all- in this case we may not
3019 * be hooked to a loop at all and we shouldn't hang
3020 * the machine for this. Otherwise, defer this command
3023 if (fcp->isp_fwstate != FW_READY) {
3025 * Give ourselves at most a 250ms delay.
3027 if (isp_fclink_test(isp, 250000)) {
3028 XS_SETERR(xs, HBA_SELTIMEOUT);
3029 if (fcp->loop_seen_once) {
3030 return (CMD_RQLATER);
3032 return (CMD_COMPLETE);
3038 * If we're not on a Fabric, we can't have a target
3039 * above FL_PORT_ID-1.
3041 * If we're on a fabric and *not* connected as an F-port,
3042 * we can't have a target less than FC_SNS_ID+1. This
3043 * keeps us from having to sort out the difference between
3044 * local public loop devices and those which we might get
3045 * from a switch's database.
3047 if (fcp->isp_onfabric == 0) {
3048 if (target >= FL_PORT_ID) {
3049 XS_SETERR(xs, HBA_SELTIMEOUT);
3050 return (CMD_COMPLETE);
3053 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3054 XS_SETERR(xs, HBA_SELTIMEOUT);
3055 return (CMD_COMPLETE);
3057 if (fcp->isp_topo != TOPO_F_PORT &&
3058 target < FL_PORT_ID) {
3059 XS_SETERR(xs, HBA_SELTIMEOUT);
3060 return (CMD_COMPLETE);
3065 * If our loop state is such that we haven't yet received
3066 * a "Port Database Changed" notification (after a LIP or
3067 * a Loop Reset or firmware initialization), then defer
3068 * sending commands for a little while, but only if we've
3069 * seen a valid loop at one point (otherwise we can get
3070 * stuck at initialization time).
3072 if (fcp->isp_loopstate < LOOP_PDB_RCVD) {
3073 XS_SETERR(xs, HBA_SELTIMEOUT);
3074 if (fcp->loop_seen_once) {
3075 return (CMD_RQLATER);
3077 return (CMD_COMPLETE);
3082 * If we're in the middle of loop or fabric scanning
3083 * or merging the port databases, retry this command later.
3085 if (fcp->isp_loopstate == LOOP_SCANNING_FABRIC ||
3086 fcp->isp_loopstate == LOOP_SCANNING_LOOP ||
3087 fcp->isp_loopstate == LOOP_SYNCING_PDB) {
3088 return (CMD_RQLATER);
3092 * If our loop state is now such that we've just now
3093 * received a Port Database Change notification, then
3094 * we have to go off and (re)scan the fabric. We back
3095 * out and try again later if this doesn't work.
3097 if (fcp->isp_loopstate == LOOP_PDB_RCVD && fcp->isp_onfabric) {
3098 if (isp_scan_fabric(isp, FC4_SCSI)) {
3099 return (CMD_RQLATER);
3101 if (fcp->isp_fwstate != FW_READY ||
3102 fcp->isp_loopstate < LOOP_FSCAN_DONE) {
3103 return (CMD_RQLATER);
3108 * If our loop state is now such that we've just now
3109 * received a Port Database Change notification, then
3110 * we have to go off and (re)synchronize our port
3113 if (fcp->isp_loopstate < LOOP_READY) {
3114 if (isp_pdb_sync(isp)) {
3115 return (CMD_RQLATER);
3117 if (fcp->isp_fwstate != FW_READY ||
3118 fcp->isp_loopstate != LOOP_READY) {
3119 return (CMD_RQLATER);
3124 * XXX: Here's were we would cancel any loop_dead flag
3125 * XXX: also cancel in dead_loop timeout that's running
3130 * Now check whether we should even think about pursuing this.
3132 lp = &fcp->portdb[target];
3133 if (lp->valid == 0) {
3134 XS_SETERR(xs, HBA_SELTIMEOUT);
3135 return (CMD_COMPLETE);
3137 if ((lp->roles & (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT)) == 0) {
3138 isp_prt(isp, ISP_LOGDEBUG2,
3139 "Target %d does not have target service", target);
3140 XS_SETERR(xs, HBA_SELTIMEOUT);
3141 return (CMD_COMPLETE);
3144 * Now turn target into what the actual Loop ID is.
3146 target = lp->loopid;
3150 * Next check to see if any HBA or Device
3151 * parameters need to be updated.
3153 if (isp->isp_update != 0) {
3157 if (isp_getrqentry(isp, &nxti, &optr, (void **)&qep)) {
3158 isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow");
3159 XS_SETERR(xs, HBA_BOTCH);
3160 return (CMD_EAGAIN);
3164 * Now see if we need to synchronize the ISP with respect to anything.
3165 * We do dual duty here (cough) for synchronizing for busses other
3166 * than which we got here to send a command to.
3168 reqp = (ispreq_t *) local;
3169 if (isp->isp_sendmarker) {
3170 u_int8_t n = (IS_DUALBUS(isp)? 2: 1);
3172 * Check ports to send markers for...
3174 for (i = 0; i < n; i++) {
3175 if ((isp->isp_sendmarker & (1 << i)) == 0) {
3178 MEMZERO((void *) reqp, QENTRY_LEN);
3179 reqp->req_header.rqs_entry_count = 1;
3180 reqp->req_header.rqs_entry_type = RQSTYPE_MARKER;
3181 reqp->req_modifier = SYNC_ALL;
3182 reqp->req_target = i << 7; /* insert bus number */
3183 isp_put_request(isp, reqp, qep);
3184 ISP_ADD_REQUEST(isp, nxti);
3185 isp->isp_sendmarker &= ~(1 << i);
3186 if (isp_getrqentry(isp, &nxti, &optr, (void **) &qep)) {
3187 isp_prt(isp, ISP_LOGDEBUG0,
3188 "Request Queue Overflow+");
3189 XS_SETERR(xs, HBA_BOTCH);
3190 return (CMD_EAGAIN);
3195 MEMZERO((void *)reqp, QENTRY_LEN);
3196 reqp->req_header.rqs_entry_count = 1;
3198 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
3200 if (XS_CDBLEN(xs) > 12)
3201 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
3203 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
3205 /* reqp->req_header.rqs_flags = 0; */
3206 /* reqp->req_header.rqs_seqno = 0; */
3209 * See comment in isp_intr
3211 /* XS_RESID(xs) = 0; */
3214 * Fibre Channel always requires some kind of tag.
3215 * The Qlogic drivers seem be happy not to use a tag,
3216 * but this breaks for some devices (IBM drives).
3219 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
3222 * If we don't know what tag to use, use HEAD OF QUEUE
3223 * for Request Sense or Simple.
3225 if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
3226 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_HTAG;
3228 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
3231 sdparam *sdp = (sdparam *)isp->isp_param;
3232 sdp += XS_CHANNEL(xs);
3233 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) &&
3235 reqp->req_flags = XS_TAG_TYPE(xs);
3238 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
3240 reqp->req_lun_trn = XS_LUN(xs);
3241 reqp->req_cdblen = XS_CDBLEN(xs);
3243 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN)
3244 ((ispreqt2_t *)reqp)->req_scclun = XS_LUN(xs);
3246 ((ispreqt2_t *)reqp)->req_lun_trn = XS_LUN(xs);
3248 MEMCPY(reqp->req_cdb, XS_CDBP(xs), XS_CDBLEN(xs));
3250 reqp->req_time = XS_TIME(xs) / 1000;
3251 if (reqp->req_time == 0 && XS_TIME(xs)) {
3255 if (isp_save_xs(isp, xs, &handle)) {
3256 isp_prt(isp, ISP_LOGDEBUG0, "out of xflist pointers");
3257 XS_SETERR(xs, HBA_BOTCH);
3258 return (CMD_EAGAIN);
3260 reqp->req_handle = handle;
3263 * Set up DMA and/or do any bus swizzling of the request entry
3264 * so that the Qlogic F/W understands what is being asked of it.
3266 i = ISP_DMASETUP(isp, xs, reqp, &nxti, optr);
3267 if (i != CMD_QUEUED) {
3268 isp_destroy_handle(isp, handle);
3270 * dmasetup sets actual error in packet, and
3271 * return what we were given to return.
3275 XS_SETERR(xs, HBA_NOERROR);
3276 isp_prt(isp, ISP_LOGDEBUG2,
3277 "START cmd for %d.%d.%d cmd 0x%x datalen %ld",
3278 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), XS_CDBP(xs)[0],
3279 (long) XS_XFRLEN(xs));
3280 ISP_ADD_REQUEST(isp, nxti);
3282 return (CMD_QUEUED);
3287 * Locks (ints blocked) assumed held.
3291 isp_control(struct ispsoftc *isp, ispctl_t ctl, void *arg)
3300 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
3303 case ISPCTL_RESET_BUS:
3305 * Issue a bus reset.
3307 mbs.param[0] = MBOX_BUS_RESET;
3311 ((sdparam *) isp->isp_param)->isp_bus_reset_delay;
3312 if (mbs.param[1] < 2)
3314 bus = *((int *) arg);
3315 if (IS_DUALBUS(isp))
3321 isp->isp_sendmarker |= (1 << bus);
3322 isp_mboxcmd(isp, &mbs, MBLOGALL);
3323 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3326 isp_prt(isp, ISP_LOGINFO,
3327 "driver initiated bus reset of bus %d", bus);
3330 case ISPCTL_RESET_DEV:
3331 tgt = (*((int *) arg)) & 0xffff;
3332 bus = (*((int *) arg)) >> 16;
3333 mbs.param[0] = MBOX_ABORT_TARGET;
3334 mbs.param[1] = (tgt << 8) | (bus << 15);
3335 mbs.param[2] = 3; /* 'delay', in seconds */
3336 isp_mboxcmd(isp, &mbs, MBLOGALL);
3337 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3340 isp_prt(isp, ISP_LOGINFO,
3341 "Target %d on Bus %d Reset Succeeded", tgt, bus);
3342 isp->isp_sendmarker |= (1 << bus);
3345 case ISPCTL_ABORT_CMD:
3348 handle = isp_find_handle(isp, xs);
3350 isp_prt(isp, ISP_LOGWARN,
3351 "cannot find handle for command to abort");
3354 bus = XS_CHANNEL(xs);
3355 mbs.param[0] = MBOX_ABORT;
3357 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
3358 mbs.param[1] = tgt << 8;
3361 mbs.param[6] = XS_LUN(xs);
3363 mbs.param[1] = tgt << 8 | XS_LUN(xs);
3367 (bus << 15) | (XS_TGT(xs) << 8) | XS_LUN(xs);
3370 mbs.param[2] = handle;
3371 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_ERROR);
3372 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3376 * XXX: Look for command in the REQUEST QUEUE. That is,
3377 * XXX: It hasen't been picked up by firmware yet.
3381 case ISPCTL_UPDATE_PARAMS:
3386 case ISPCTL_FCLINK_TEST:
3389 int usdelay = (arg)? *((int *) arg) : 250000;
3390 return (isp_fclink_test(isp, usdelay));
3394 case ISPCTL_SCAN_FABRIC:
3397 int ftype = (arg)? *((int *) arg) : FC4_SCSI;
3398 return (isp_scan_fabric(isp, ftype));
3402 case ISPCTL_SCAN_LOOP:
3405 return (isp_scan_loop(isp));
3409 case ISPCTL_PDB_SYNC:
3412 return (isp_pdb_sync(isp));
3416 case ISPCTL_SEND_LIP:
3419 mbs.param[0] = MBOX_INIT_LIP;
3420 isp_mboxcmd(isp, &mbs, MBLOGALL);
3421 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3427 case ISPCTL_GET_POSMAP:
3429 if (IS_FC(isp) && arg) {
3430 return (isp_getmap(isp, arg));
3434 case ISPCTL_RUN_MBOXCMD:
3436 isp_mboxcmd(isp, arg, MBLOGALL);
3439 #ifdef ISP_TARGET_MODE
3440 case ISPCTL_TOGGLE_TMODE:
3444 * We don't check/set against role here- that's the
3445 * responsibility for the outer layer to coordinate.
3448 int param = *(int *)arg;
3449 mbs.param[0] = MBOX_ENABLE_TARGET_MODE;
3450 mbs.param[1] = param & 0xffff;
3451 mbs.param[2] = param >> 16;
3452 isp_mboxcmd(isp, &mbs, MBLOGALL);
3453 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3465 * Interrupt Service Routine(s).
3467 * External (OS) framework has done the appropriate locking,
3468 * and the locking will be held throughout this function.
3472 * Limit our stack depth by sticking with the max likely number
3473 * of completions on a request queue at any one time.
3475 #ifndef MAX_REQUESTQ_COMPLETIONS
3476 #define MAX_REQUESTQ_COMPLETIONS 64
3480 isp_intr(struct ispsoftc *isp, u_int16_t isr, u_int16_t sema, u_int16_t mbox)
3482 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
3483 u_int16_t iptr, optr, junk;
3484 int i, nlooked = 0, ndone = 0;
3488 * Is this a mailbox related interrupt?
3489 * The mailbox semaphore will be nonzero if so.
3492 if (mbox & 0x4000) {
3493 isp->isp_intmboxc++;
3494 if (isp->isp_mboxbsy) {
3495 int i = 0, obits = isp->isp_obits;
3496 isp->isp_mboxtmp[i++] = mbox;
3497 for (i = 1; i < MAX_MAILBOX; i++) {
3498 if ((obits & (1 << i)) == 0) {
3501 isp->isp_mboxtmp[i] =
3502 ISP_READ(isp, MBOX_OFF(i));
3504 if (isp->isp_mbxwrk0) {
3505 if (isp_mbox_continue(isp) == 0) {
3509 MBOX_NOTIFY_COMPLETE(isp);
3511 isp_prt(isp, ISP_LOGWARN,
3512 "Mbox Command Async (0x%x) with no waiters",
3515 } else if (isp_parse_async(isp, mbox) < 0) {
3518 if ((IS_FC(isp) && mbox != ASYNC_RIO_RESP) ||
3519 isp->isp_state != ISP_RUNSTATE) {
3520 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3521 ISP_WRITE(isp, BIU_SEMA, 0);
3527 * We can't be getting this now.
3529 if (isp->isp_state != ISP_RUNSTATE) {
3530 isp_prt(isp, ISP_LOGWARN,
3531 "interrupt (ISR=%x SEMA=%x) when not ready", isr, sema);
3533 * Thank you very much! *Burrrp*!
3535 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp,
3536 READ_RESPONSE_QUEUE_IN_POINTER(isp));
3538 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3539 ISP_WRITE(isp, BIU_SEMA, 0);
3544 * Get the current Response Queue Out Pointer.
3546 * If we're a 2300, we can ask what hardware what it thinks.
3549 optr = ISP_READ(isp, isp->isp_respoutrp);
3551 * Debug: to be taken out eventually
3553 if (isp->isp_residx != optr) {
3554 isp_prt(isp, ISP_LOGWARN, "optr %x soft optr %x",
3555 optr, isp->isp_residx);
3558 optr = isp->isp_residx;
3562 * You *must* read the Response Queue In Pointer
3563 * prior to clearing the RISC interrupt.
3565 * Debounce the 2300 if revision less than 2.
3567 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
3570 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3571 junk = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3572 } while (junk != iptr && ++i < 1000);
3575 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3576 isp_prt(isp, ISP_LOGWARN,
3577 "Response Queue Out Pointer Unstable (%x, %x)",
3582 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3584 isp->isp_resodx = iptr;
3587 if (optr == iptr && sema == 0) {
3589 * There are a lot of these- reasons unknown- mostly on
3590 * faster Alpha machines.
3592 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
3593 * make sure the old interrupt went away (to avoid 'ringing'
3594 * effects), but that didn't stop this from occurring.
3598 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3599 junk = ISP_READ(isp, BIU_R2HSTSLO);
3601 junk = ISP_READ(isp, BIU_ISR);
3607 sema = ISP_READ(isp, BIU_SEMA);
3608 mbox = ISP_READ(isp, OUTMAILBOX0);
3609 if ((sema & 0x3) && (mbox & 0x8000)) {
3613 isp->isp_intbogus++;
3614 isp_prt(isp, ISP_LOGDEBUG1,
3615 "bogus intr- isr %x (%x) iptr %x optr %x",
3616 isr, junk, iptr, optr);
3619 isp->isp_resodx = iptr;
3620 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3621 ISP_WRITE(isp, BIU_SEMA, 0);
3623 if (isp->isp_rspbsy) {
3626 isp->isp_rspbsy = 1;
3628 while (optr != iptr) {
3629 ispstatusreq_t local, *sp = &local;
3635 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
3637 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
3640 * Synchronize our view of this response queue entry.
3642 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN);
3644 type = isp_get_response_type(isp, hp);
3646 if (type == RQSTYPE_RESPONSE) {
3647 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3648 } else if (type == RQSTYPE_RIO2) {
3650 isp_get_rio2(isp, (isp_rio2_t *) hp, &rio);
3651 for (i = 0; i < rio.req_header.rqs_seqno; i++) {
3652 isp_fastpost_complete(isp, rio.req_handles[i]);
3654 if (isp->isp_fpcchiwater < rio.req_header.rqs_seqno)
3655 isp->isp_fpcchiwater = rio.req_header.rqs_seqno;
3656 MEMZERO(hp, QENTRY_LEN); /* PERF */
3660 * Somebody reachable via isp_handle_other_response
3661 * may have updated the response queue pointers for
3662 * us, so we reload our goal index.
3664 if (isp_handle_other_response(isp, type, hp, &optr)) {
3665 iptr = isp->isp_resodx;
3666 MEMZERO(hp, QENTRY_LEN); /* PERF */
3671 * After this point, we'll just look at the header as
3672 * we don't know how to deal with the rest of the
3675 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3678 * It really has to be a bounced request just copied
3679 * from the request queue to the response queue. If
3680 * not, something bad has happened.
3682 if (sp->req_header.rqs_entry_type != RQSTYPE_REQUEST) {
3683 isp_prt(isp, ISP_LOGERR, notresp,
3684 sp->req_header.rqs_entry_type, oop, optr,
3686 if (isp->isp_dblev & ISP_LOGDEBUG0) {
3687 isp_print_bytes(isp, "Queue Entry",
3690 MEMZERO(hp, QENTRY_LEN); /* PERF */
3696 if (sp->req_header.rqs_flags & 0xf) {
3697 #define _RQS_OFLAGS \
3698 ~(RQSFLAG_CONTINUATION|RQSFLAG_FULL|RQSFLAG_BADHEADER|RQSFLAG_BADPACKET)
3699 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
3700 isp_prt(isp, ISP_LOGWARN,
3701 "continuation segment");
3702 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3705 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3706 isp_prt(isp, ISP_LOGDEBUG1,
3707 "internal queues full");
3709 * We'll synthesize a QUEUE FULL message below.
3712 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
3713 isp_prt(isp, ISP_LOGERR, "bad header flag");
3716 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
3717 isp_prt(isp, ISP_LOGERR, "bad request packet");
3720 if (sp->req_header.rqs_flags & _RQS_OFLAGS) {
3721 isp_prt(isp, ISP_LOGERR,
3722 "unknown flags (0x%x) in response",
3723 sp->req_header.rqs_flags);
3728 if (sp->req_handle > isp->isp_maxcmds || sp->req_handle < 1) {
3729 MEMZERO(hp, QENTRY_LEN); /* PERF */
3730 isp_prt(isp, ISP_LOGERR,
3731 "bad request handle %d (type 0x%x, flags 0x%x)",
3732 sp->req_handle, sp->req_header.rqs_entry_type,
3733 sp->req_header.rqs_flags);
3734 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3737 xs = isp_find_xs(isp, sp->req_handle);
3739 u_int8_t ts = sp->req_completion_status & 0xff;
3740 MEMZERO(hp, QENTRY_LEN); /* PERF */
3742 * Only whine if this isn't the expected fallout of
3743 * aborting the command.
3745 if (sp->req_header.rqs_entry_type != RQSTYPE_RESPONSE) {
3746 isp_prt(isp, ISP_LOGERR,
3747 "cannot find handle 0x%x (type 0x%x)",
3749 sp->req_header.rqs_entry_type);
3750 } else if (ts != RQCS_ABORTED) {
3751 isp_prt(isp, ISP_LOGERR,
3752 "cannot find handle 0x%x (status 0x%x)",
3753 sp->req_handle, ts);
3755 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3758 isp_destroy_handle(isp, sp->req_handle);
3759 if (sp->req_status_flags & RQSTF_BUS_RESET) {
3760 XS_SETERR(xs, HBA_BUSRESET);
3761 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
3764 XS_SETERR(xs, HBA_BOTCH);
3767 if (IS_FC(isp) && (sp->req_scsi_status & RQCS_SV)) {
3769 * Fibre Channel F/W doesn't say we got status
3770 * if there's Sense Data instead. I guess they
3771 * think it goes w/o saying.
3773 sp->req_state_flags |= RQSF_GOT_STATUS;
3775 if (sp->req_state_flags & RQSF_GOT_STATUS) {
3776 *XS_STSP(xs) = sp->req_scsi_status & 0xff;
3779 switch (sp->req_header.rqs_entry_type) {
3780 case RQSTYPE_RESPONSE:
3781 XS_SET_STATE_STAT(isp, xs, sp);
3782 isp_parse_status(isp, sp, xs);
3783 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) &&
3784 (*XS_STSP(xs) == SCSI_BUSY)) {
3785 XS_SETERR(xs, HBA_TGTBSY);
3788 XS_RESID(xs) = sp->req_resid;
3789 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3790 (*XS_STSP(xs) == SCSI_CHECK) &&
3791 (sp->req_state_flags & RQSF_GOT_SENSE)) {
3792 XS_SAVE_SENSE(xs, sp);
3795 * A new synchronous rate was negotiated for
3796 * this target. Mark state such that we'll go
3797 * look up that which has changed later.
3799 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
3801 sdparam *sdp = isp->isp_param;
3802 sdp += XS_CHANNEL(xs);
3803 sdp->isp_devparam[t].dev_refresh = 1;
3805 (1 << XS_CHANNEL(xs));
3808 if (sp->req_status_flags & RQSF_XFER_COMPLETE) {
3810 } else if (sp->req_scsi_status & RQCS_RESID) {
3811 XS_RESID(xs) = sp->req_resid;
3815 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3816 (*XS_STSP(xs) == SCSI_CHECK) &&
3817 (sp->req_scsi_status & RQCS_SV)) {
3818 XS_SAVE_SENSE(xs, sp);
3819 /* solely for the benefit of debug */
3820 sp->req_state_flags |= RQSF_GOT_SENSE;
3823 isp_prt(isp, ISP_LOGDEBUG2,
3824 "asked for %ld got resid %ld", (long) XS_XFRLEN(xs),
3825 (long) sp->req_resid);
3827 case RQSTYPE_REQUEST:
3828 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3830 * Force Queue Full status.
3832 *XS_STSP(xs) = SCSI_QFULL;
3833 XS_SETERR(xs, HBA_NOERROR);
3834 } else if (XS_NOERR(xs)) {
3838 isp_prt(isp, ISP_LOGDEBUG0,
3839 "Request Queue Entry bounced back");
3840 XS_SETERR(xs, HBA_BOTCH);
3842 XS_RESID(xs) = XS_XFRLEN(xs);
3845 isp_prt(isp, ISP_LOGWARN,
3846 "unhandled response queue type 0x%x",
3847 sp->req_header.rqs_entry_type);
3849 XS_SETERR(xs, HBA_BOTCH);
3855 * Free any dma resources. As a side effect, this may
3856 * also do any cache flushing necessary for data coherence. */
3857 if (XS_XFRLEN(xs)) {
3858 ISP_DMAFREE(isp, xs, sp->req_handle);
3861 if (((isp->isp_dblev & (ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
3862 ((isp->isp_dblev & ISP_LOGDEBUG1) && ((!XS_NOERR(xs)) ||
3863 (*XS_STSP(xs) != SCSI_GOOD)))) {
3865 if (sp->req_state_flags & RQSF_GOT_SENSE) {
3866 skey = XS_SNSKEY(xs) & 0xf;
3871 } else if (*XS_STSP(xs) == SCSI_CHECK) {
3876 isp_prt(isp, ISP_LOGALL, finmsg, XS_CHANNEL(xs),
3877 XS_TGT(xs), XS_LUN(xs), XS_XFRLEN(xs), XS_RESID(xs),
3878 *XS_STSP(xs), skey, XS_ERR(xs));
3881 if (isp->isp_nactive > 0)
3883 complist[ndone++] = xs; /* defer completion call until later */
3884 MEMZERO(hp, QENTRY_LEN); /* PERF */
3885 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
3891 * If we looked at any commands, then it's valid to find out
3892 * what the outpointer is. It also is a trigger to update the
3893 * ISP's notion of what we've seen so far.
3896 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3898 * While we're at it, read the requst queue out pointer.
3900 isp->isp_reqodx = READ_REQUEST_QUEUE_OUT_POINTER(isp);
3901 if (isp->isp_rscchiwater < ndone)
3902 isp->isp_rscchiwater = ndone;
3905 isp->isp_residx = optr;
3906 isp->isp_rspbsy = 0;
3907 for (i = 0; i < ndone; i++) {
3910 isp->isp_rsltccmplt++;
3921 isp_parse_async(struct ispsoftc *isp, u_int16_t mbox)
3926 if (IS_DUALBUS(isp)) {
3927 bus = ISP_READ(isp, OUTMAILBOX6);
3931 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
3934 case ASYNC_BUS_RESET:
3935 isp->isp_sendmarker |= (1 << bus);
3936 #ifdef ISP_TARGET_MODE
3937 if (isp_target_async(isp, bus, mbox))
3940 isp_async(isp, ISPASYNC_BUS_RESET, &bus);
3942 case ASYNC_SYSTEM_ERROR:
3943 #ifdef ISP_FW_CRASH_DUMP
3945 * If we have crash dumps enabled, it's up to the handler
3946 * for isp_async to reinit stuff and restart the firmware
3947 * after performing the crash dump. The reason we do things
3948 * this way is that we may need to activate a kernel thread
3949 * to do all the crash dump goop.
3951 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
3953 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
3955 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
3960 case ASYNC_RQS_XFER_ERR:
3961 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
3964 case ASYNC_RSP_XFER_ERR:
3965 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
3970 * We've just been notified that the Queue has woken up.
3971 * We don't need to be chatty about this- just unlatch things
3974 mbox = READ_REQUEST_QUEUE_OUT_POINTER(isp);
3977 case ASYNC_TIMEOUT_RESET:
3978 isp_prt(isp, ISP_LOGWARN,
3979 "timeout initiated SCSI bus reset of bus %d", bus);
3980 isp->isp_sendmarker |= (1 << bus);
3981 #ifdef ISP_TARGET_MODE
3982 if (isp_target_async(isp, bus, mbox))
3987 case ASYNC_DEVICE_RESET:
3988 isp_prt(isp, ISP_LOGINFO, "device reset on bus %d", bus);
3989 isp->isp_sendmarker |= (1 << bus);
3990 #ifdef ISP_TARGET_MODE
3991 if (isp_target_async(isp, bus, mbox))
3996 case ASYNC_EXTMSG_UNDERRUN:
3997 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
4000 case ASYNC_SCAM_INT:
4001 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
4004 case ASYNC_HUNG_SCSI:
4005 isp_prt(isp, ISP_LOGERR,
4006 "stalled SCSI Bus after DATA Overrun");
4007 /* XXX: Need to issue SCSI reset at this point */
4010 case ASYNC_KILLED_BUS:
4011 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
4014 case ASYNC_BUS_TRANSIT:
4015 mbox = ISP_READ(isp, OUTMAILBOX2);
4016 switch (mbox & 0x1c00) {
4017 case SXP_PINS_LVD_MODE:
4018 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
4019 SDPARAM(isp)->isp_diffmode = 0;
4020 SDPARAM(isp)->isp_ultramode = 0;
4021 SDPARAM(isp)->isp_lvdmode = 1;
4023 case SXP_PINS_HVD_MODE:
4024 isp_prt(isp, ISP_LOGINFO,
4025 "Transition to Differential mode");
4026 SDPARAM(isp)->isp_diffmode = 1;
4027 SDPARAM(isp)->isp_ultramode = 0;
4028 SDPARAM(isp)->isp_lvdmode = 0;
4030 case SXP_PINS_SE_MODE:
4031 isp_prt(isp, ISP_LOGINFO,
4032 "Transition to Single Ended mode");
4033 SDPARAM(isp)->isp_diffmode = 0;
4034 SDPARAM(isp)->isp_ultramode = 1;
4035 SDPARAM(isp)->isp_lvdmode = 0;
4038 isp_prt(isp, ISP_LOGWARN,
4039 "Transition to Unknown Mode 0x%x", mbox);
4043 * XXX: Set up to renegotiate again!
4045 /* Can only be for a 1080... */
4046 isp->isp_sendmarker |= (1 << bus);
4050 * We can use bus, which will always be zero for FC cards,
4051 * as a mailbox pattern accumulator to be checked below.
4054 bus = 0x1ce; /* outgoing mailbox regs 1-3, 6-7 */
4058 bus = 0x14e; /* outgoing mailbox regs 1-3, 6 */
4062 bus = 0x10e; /* outgoing mailbox regs 1-3 */
4066 bus = 0x106; /* outgoing mailbox regs 1-2 */
4070 case ASYNC_CMD_CMPLT:
4071 bus = 0x102; /* outgoing mailbox regs 1 */
4074 case ASYNC_RIO_RESP:
4077 case ASYNC_CTIO_DONE:
4079 #ifdef ISP_TARGET_MODE
4081 (ISP_READ(isp, OUTMAILBOX2) << 16) |
4082 (ISP_READ(isp, OUTMAILBOX1));
4083 if (isp_target_async(isp, handle, mbox))
4086 isp_prt(isp, ISP_LOGINFO, "Fast Posting CTIO done");
4088 isp->isp_fphccmplt++; /* count it as a fast posting intr */
4092 case ASYNC_LIP_OCCURRED:
4093 FCPARAM(isp)->isp_lipseq =
4094 ISP_READ(isp, OUTMAILBOX1);
4095 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4096 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4097 isp->isp_sendmarker = 1;
4098 isp_mark_getpdb_all(isp);
4099 isp_async(isp, ISPASYNC_LIP, NULL);
4100 #ifdef ISP_TARGET_MODE
4101 if (isp_target_async(isp, bus, mbox))
4105 * We've had problems with data corruption occuring on
4106 * commands that complete (with no apparent error) after
4107 * we receive a LIP. This has been observed mostly on
4108 * Local Loop topologies. To be safe, let's just mark
4109 * all active commands as dead.
4111 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4112 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4114 for (i = j = 0; i < isp->isp_maxcmds; i++) {
4116 xs = isp->isp_xflist[i];
4119 XS_SETERR(xs, HBA_BUSRESET);
4123 isp_prt(isp, ISP_LOGERR,
4124 "LIP destroyed %d active commands", j);
4130 isp->isp_sendmarker = 1;
4131 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4132 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4133 isp_mark_getpdb_all(isp);
4134 isp_async(isp, ISPASYNC_LOOP_UP, NULL);
4135 #ifdef ISP_TARGET_MODE
4136 if (isp_target_async(isp, bus, mbox))
4141 case ASYNC_LOOP_DOWN:
4142 isp->isp_sendmarker = 1;
4143 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4144 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4145 isp_mark_getpdb_all(isp);
4146 isp_async(isp, ISPASYNC_LOOP_DOWN, NULL);
4147 #ifdef ISP_TARGET_MODE
4148 if (isp_target_async(isp, bus, mbox))
4153 case ASYNC_LOOP_RESET:
4154 isp->isp_sendmarker = 1;
4155 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4156 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4157 isp_mark_getpdb_all(isp);
4158 isp_async(isp, ISPASYNC_LOOP_RESET, NULL);
4159 #ifdef ISP_TARGET_MODE
4160 if (isp_target_async(isp, bus, mbox))
4165 case ASYNC_PDB_CHANGED:
4166 isp->isp_sendmarker = 1;
4167 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4168 isp_mark_getpdb_all(isp);
4169 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_PDB);
4172 case ASYNC_CHANGE_NOTIFY:
4174 * Not correct, but it will force us to rescan the loop.
4176 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4177 isp_mark_getpdb_all(isp);
4178 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_SNS);
4182 if (FCPARAM(isp)->isp_onfabric)
4183 FCPARAM(isp)->isp_topo = TOPO_F_PORT;
4185 FCPARAM(isp)->isp_topo = TOPO_N_PORT;
4186 isp_mark_getpdb_all(isp);
4187 isp->isp_sendmarker = 1;
4188 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4189 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4190 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4191 #ifdef ISP_TARGET_MODE
4192 if (isp_target_async(isp, bus, mbox))
4195 isp_prt(isp, ISP_LOGINFO, "Point-to-Point mode");
4198 case ASYNC_CONNMODE:
4199 mbox = ISP_READ(isp, OUTMAILBOX1);
4200 isp_mark_getpdb_all(isp);
4203 isp_prt(isp, ISP_LOGINFO,
4204 "Point-to-Point -> Loop mode");
4207 isp_prt(isp, ISP_LOGINFO,
4208 "Loop -> Point-to-Point mode");
4210 case ISP_CONN_BADLIP:
4211 isp_prt(isp, ISP_LOGWARN,
4212 "Point-to-Point -> Loop mode (BAD LIP)");
4214 case ISP_CONN_FATAL:
4215 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
4216 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4218 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4220 case ISP_CONN_LOOPBACK:
4221 isp_prt(isp, ISP_LOGWARN,
4222 "Looped Back in Point-to-Point mode");
4225 isp_prt(isp, ISP_LOGWARN,
4226 "Unknown connection mode (0x%x)", mbox);
4229 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4230 isp->isp_sendmarker = 1;
4231 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4232 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4236 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
4242 u_int16_t handles[5];
4244 for (nh = 0, i = 1; i < MAX_MAILBOX; i++) {
4245 if ((bus & (1 << i)) == 0) {
4248 handles[nh++] = ISP_READ(isp, MBOX_OFF(i));
4250 for (i = 0; i < nh; i++) {
4251 isp_fastpost_complete(isp, handles[i]);
4252 isp_prt(isp, ISP_LOGDEBUG3,
4253 "fast post completion of %u", handles[i]);
4255 if (isp->isp_fpcchiwater < nh)
4256 isp->isp_fpcchiwater = nh;
4258 isp->isp_intoasync++;
4264 * Handle other response entries. A pointer to the request queue output
4265 * index is here in case we want to eat several entries at once, although
4266 * this is not used currently.
4270 isp_handle_other_response(struct ispsoftc *isp, int type,
4271 isphdr_t *hp, u_int16_t *optrp)
4274 case RQSTYPE_STATUS_CONT:
4275 isp_prt(isp, ISP_LOGINFO, "Ignored Continuation Response");
4279 case RQSTYPE_ENABLE_LUN:
4280 case RQSTYPE_MODIFY_LUN:
4281 case RQSTYPE_NOTIFY:
4282 case RQSTYPE_NOTIFY_ACK:
4287 isp->isp_rsltccmplt++; /* count as a response completion */
4288 #ifdef ISP_TARGET_MODE
4289 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
4296 case RQSTYPE_REQUEST:
4298 if (isp_async(isp, ISPASYNC_UNHANDLED_RESPONSE, hp)) {
4301 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
4302 isp_get_response_type(isp, hp));
4308 isp_parse_status(struct ispsoftc *isp, ispstatusreq_t *sp, XS_T *xs)
4310 switch (sp->req_completion_status & 0xff) {
4313 XS_SETERR(xs, HBA_NOERROR);
4317 case RQCS_INCOMPLETE:
4318 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
4319 isp_prt(isp, ISP_LOGDEBUG1,
4320 "Selection Timeout for %d.%d.%d",
4321 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4323 XS_SETERR(xs, HBA_SELTIMEOUT);
4327 isp_prt(isp, ISP_LOGERR,
4328 "command incomplete for %d.%d.%d, state 0x%x",
4329 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
4330 sp->req_state_flags);
4333 case RQCS_DMA_ERROR:
4334 isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
4335 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4338 case RQCS_TRANSPORT_ERROR:
4341 SNPRINTF(buf, sizeof (buf), "states=>");
4342 if (sp->req_state_flags & RQSF_GOT_BUS) {
4343 SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
4345 if (sp->req_state_flags & RQSF_GOT_TARGET) {
4346 SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
4348 if (sp->req_state_flags & RQSF_SENT_CDB) {
4349 SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
4351 if (sp->req_state_flags & RQSF_XFRD_DATA) {
4352 SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
4354 if (sp->req_state_flags & RQSF_GOT_STATUS) {
4355 SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
4357 if (sp->req_state_flags & RQSF_GOT_SENSE) {
4358 SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
4360 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
4361 SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
4363 SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
4364 if (sp->req_status_flags & RQSTF_DISCONNECT) {
4365 SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
4367 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
4368 SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
4370 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
4371 SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
4373 if (sp->req_status_flags & RQSTF_BUS_RESET) {
4374 SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
4376 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
4377 SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
4379 if (sp->req_status_flags & RQSTF_ABORTED) {
4380 SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
4382 if (sp->req_status_flags & RQSTF_TIMEOUT) {
4383 SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
4385 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
4386 SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
4388 isp_prt(isp, ISP_LOGERR, "%s", buf);
4389 isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d:\n%s",
4390 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), buf);
4393 case RQCS_RESET_OCCURRED:
4394 isp_prt(isp, ISP_LOGWARN,
4395 "bus reset destroyed command for %d.%d.%d",
4396 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4397 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4399 XS_SETERR(xs, HBA_BUSRESET);
4404 isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
4405 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4406 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4408 XS_SETERR(xs, HBA_ABORTED);
4413 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
4414 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4416 * Check to see if we logged out the device.
4419 if ((sp->req_completion_status & RQSTF_LOGOUT) &&
4420 FCPARAM(isp)->portdb[XS_TGT(xs)].valid &&
4421 FCPARAM(isp)->portdb[XS_TGT(xs)].fabric_dev) {
4422 FCPARAM(isp)->portdb[XS_TGT(xs)].relogin = 1;
4426 XS_SETERR(xs, HBA_CMDTIMEOUT);
4430 case RQCS_DATA_OVERRUN:
4431 XS_RESID(xs) = sp->req_resid;
4432 isp_prt(isp, ISP_LOGERR, "data overrun for command on %d.%d.%d",
4433 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4435 XS_SETERR(xs, HBA_DATAOVR);
4439 case RQCS_COMMAND_OVERRUN:
4440 isp_prt(isp, ISP_LOGERR,
4441 "command overrun for command on %d.%d.%d",
4442 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4445 case RQCS_STATUS_OVERRUN:
4446 isp_prt(isp, ISP_LOGERR,
4447 "status overrun for command on %d.%d.%d",
4448 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4451 case RQCS_BAD_MESSAGE:
4452 isp_prt(isp, ISP_LOGERR,
4453 "msg not COMMAND COMPLETE after status %d.%d.%d",
4454 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4457 case RQCS_NO_MESSAGE_OUT:
4458 isp_prt(isp, ISP_LOGERR,
4459 "No MESSAGE OUT phase after selection on %d.%d.%d",
4460 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4463 case RQCS_EXT_ID_FAILED:
4464 isp_prt(isp, ISP_LOGERR, "EXTENDED IDENTIFY failed %d.%d.%d",
4465 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4468 case RQCS_IDE_MSG_FAILED:
4469 isp_prt(isp, ISP_LOGERR,
4470 "INITIATOR DETECTED ERROR rejected by %d.%d.%d",
4471 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4474 case RQCS_ABORT_MSG_FAILED:
4475 isp_prt(isp, ISP_LOGERR, "ABORT OPERATION rejected by %d.%d.%d",
4476 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4479 case RQCS_REJECT_MSG_FAILED:
4480 isp_prt(isp, ISP_LOGERR, "MESSAGE REJECT rejected by %d.%d.%d",
4481 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4484 case RQCS_NOP_MSG_FAILED:
4485 isp_prt(isp, ISP_LOGERR, "NOP rejected by %d.%d.%d",
4486 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4489 case RQCS_PARITY_ERROR_MSG_FAILED:
4490 isp_prt(isp, ISP_LOGERR,
4491 "MESSAGE PARITY ERROR rejected by %d.%d.%d",
4492 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4495 case RQCS_DEVICE_RESET_MSG_FAILED:
4496 isp_prt(isp, ISP_LOGWARN,
4497 "BUS DEVICE RESET rejected by %d.%d.%d",
4498 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4501 case RQCS_ID_MSG_FAILED:
4502 isp_prt(isp, ISP_LOGERR, "IDENTIFY rejected by %d.%d.%d",
4503 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4506 case RQCS_UNEXP_BUS_FREE:
4507 isp_prt(isp, ISP_LOGERR, "%d.%d.%d had an unexpected bus free",
4508 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4511 case RQCS_DATA_UNDERRUN:
4514 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
4515 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
4516 isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
4517 XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
4518 (ru_marked)? "marked" : "not marked");
4520 XS_SETERR(xs, HBA_BOTCH);
4525 XS_RESID(xs) = sp->req_resid;
4527 XS_SETERR(xs, HBA_NOERROR);
4532 case RQCS_XACT_ERR1:
4533 isp_prt(isp, ISP_LOGERR, xact1, XS_CHANNEL(xs),
4534 XS_TGT(xs), XS_LUN(xs));
4537 case RQCS_XACT_ERR2:
4538 isp_prt(isp, ISP_LOGERR, xact2,
4539 XS_LUN(xs), XS_TGT(xs), XS_CHANNEL(xs));
4542 case RQCS_XACT_ERR3:
4543 isp_prt(isp, ISP_LOGERR, xact3,
4544 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4547 case RQCS_BAD_ENTRY:
4548 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
4551 case RQCS_QUEUE_FULL:
4552 isp_prt(isp, ISP_LOGDEBUG0,
4553 "internal queues full for %d.%d.%d status 0x%x",
4554 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), *XS_STSP(xs));
4557 * If QFULL or some other status byte is set, then this
4558 * isn't an error, per se.
4560 * Unfortunately, some QLogic f/w writers have, in
4561 * some cases, ommitted to *set* status to QFULL.
4564 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
4565 XS_SETERR(xs, HBA_NOERROR);
4573 *XS_STSP(xs) = SCSI_QFULL;
4574 XS_SETERR(xs, HBA_NOERROR);
4577 case RQCS_PHASE_SKIPPED:
4578 isp_prt(isp, ISP_LOGERR, pskip, XS_CHANNEL(xs),
4579 XS_TGT(xs), XS_LUN(xs));
4582 case RQCS_ARQS_FAILED:
4583 isp_prt(isp, ISP_LOGERR,
4584 "Auto Request Sense failed for %d.%d.%d",
4585 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4587 XS_SETERR(xs, HBA_ARQFAIL);
4591 case RQCS_WIDE_FAILED:
4592 isp_prt(isp, ISP_LOGERR,
4593 "Wide Negotiation failed for %d.%d.%d",
4594 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4596 sdparam *sdp = isp->isp_param;
4597 sdp += XS_CHANNEL(xs);
4598 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
4599 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4600 isp->isp_update |= (1 << XS_CHANNEL(xs));
4603 XS_SETERR(xs, HBA_NOERROR);
4607 case RQCS_SYNCXFER_FAILED:
4608 isp_prt(isp, ISP_LOGERR,
4609 "SDTR Message failed for target %d.%d.%d",
4610 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4612 sdparam *sdp = isp->isp_param;
4613 sdp += XS_CHANNEL(xs);
4614 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
4615 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4616 isp->isp_update |= (1 << XS_CHANNEL(xs));
4620 case RQCS_LVD_BUSERR:
4621 isp_prt(isp, ISP_LOGERR,
4622 "Bad LVD condition while talking to %d.%d.%d",
4623 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4626 case RQCS_PORT_UNAVAILABLE:
4628 * No such port on the loop. Moral equivalent of SELTIMEO
4630 case RQCS_PORT_LOGGED_OUT:
4632 * It was there (maybe)- treat as a selection timeout.
4634 if ((sp->req_completion_status & 0xff) == RQCS_PORT_UNAVAILABLE)
4635 isp_prt(isp, ISP_LOGINFO,
4636 "port unavailable for target %d", XS_TGT(xs));
4638 isp_prt(isp, ISP_LOGINFO,
4639 "port logout for target %d", XS_TGT(xs));
4641 * If we're on a local loop, force a LIP (which is overkill)
4642 * to force a re-login of this unit. If we're on fabric,
4643 * then we'll have to relogin as a matter of course.
4645 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4646 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4648 mbs.param[0] = MBOX_INIT_LIP;
4649 isp_mboxcmd_qnw(isp, &mbs, 1);
4653 * Probably overkill.
4655 isp->isp_sendmarker = 1;
4656 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4657 isp_mark_getpdb_all(isp);
4658 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4660 XS_SETERR(xs, HBA_SELTIMEOUT);
4664 case RQCS_PORT_CHANGED:
4665 isp_prt(isp, ISP_LOGWARN,
4666 "port changed for target %d", XS_TGT(xs));
4668 XS_SETERR(xs, HBA_SELTIMEOUT);
4672 case RQCS_PORT_BUSY:
4673 isp_prt(isp, ISP_LOGWARN,
4674 "port busy for target %d", XS_TGT(xs));
4676 XS_SETERR(xs, HBA_TGTBSY);
4681 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x",
4682 sp->req_completion_status);
4686 XS_SETERR(xs, HBA_BOTCH);
4691 isp_fastpost_complete(struct ispsoftc *isp, u_int16_t fph)
4698 xs = isp_find_xs(isp, fph);
4700 isp_prt(isp, ISP_LOGWARN,
4701 "Command for fast post handle 0x%x not found", fph);
4704 isp_destroy_handle(isp, fph);
4707 * Since we don't have a result queue entry item,
4708 * we must believe that SCSI status is zero and
4709 * that all data transferred.
4711 XS_SET_STATE_STAT(isp, xs, NULL);
4713 *XS_STSP(xs) = SCSI_GOOD;
4714 if (XS_XFRLEN(xs)) {
4715 ISP_DMAFREE(isp, xs, fph);
4717 if (isp->isp_nactive)
4719 isp->isp_fphccmplt++;
4724 isp_mbox_continue(struct ispsoftc *isp)
4729 switch (isp->isp_lastmbxcmd) {
4730 case MBOX_WRITE_RAM_WORD:
4731 case MBOX_READ_RAM_WORD:
4732 case MBOX_READ_RAM_WORD_EXTENDED:
4737 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
4738 isp->isp_mbxwrk0 = 0;
4744 * Clear the previous interrupt.
4746 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
4747 ISP_WRITE(isp, BIU_SEMA, 0);
4750 * Continue with next word.
4752 ptr = isp->isp_mbxworkp;
4753 switch (isp->isp_lastmbxcmd) {
4754 case MBOX_WRITE_RAM_WORD:
4755 mbs.param[2] = *ptr++;
4756 mbs.param[1] = isp->isp_mbxwrk1++;
4758 case MBOX_READ_RAM_WORD:
4759 case MBOX_READ_RAM_WORD_EXTENDED:
4760 *ptr++ = isp->isp_mboxtmp[2];
4761 mbs.param[1] = isp->isp_mbxwrk1++;
4764 isp->isp_mbxworkp = ptr;
4765 mbs.param[0] = isp->isp_lastmbxcmd;
4766 isp->isp_mbxwrk0 -= 1;
4767 isp_mboxcmd_qnw(isp, &mbs, 0);
4772 #define HIBYT(x) ((x) >> 0x8)
4773 #define LOBYT(x) ((x) & 0xff)
4774 #define ISPOPMAP(a, b) (((a) << 8) | (b))
4775 static u_int16_t mbpscsi[] = {
4776 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
4777 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
4778 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
4779 ISPOPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
4780 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
4781 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
4782 ISPOPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
4783 ISPOPMAP(0x03, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
4784 ISPOPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
4785 ISPOPMAP(0x00, 0x00), /* 0x09: */
4786 ISPOPMAP(0x00, 0x00), /* 0x0a: */
4787 ISPOPMAP(0x00, 0x00), /* 0x0b: */
4788 ISPOPMAP(0x00, 0x00), /* 0x0c: */
4789 ISPOPMAP(0x00, 0x00), /* 0x0d: */
4790 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
4791 ISPOPMAP(0x00, 0x00), /* 0x0f: */
4792 ISPOPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
4793 ISPOPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
4794 ISPOPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
4795 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
4796 ISPOPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
4797 ISPOPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
4798 ISPOPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
4799 ISPOPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
4800 ISPOPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
4801 ISPOPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
4802 ISPOPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
4803 ISPOPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
4804 ISPOPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
4805 ISPOPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
4806 ISPOPMAP(0x00, 0x00), /* 0x1e: */
4807 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
4808 ISPOPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
4809 ISPOPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
4810 ISPOPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
4811 ISPOPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
4812 ISPOPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
4813 ISPOPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
4814 ISPOPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
4815 ISPOPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
4816 ISPOPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
4817 ISPOPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
4818 ISPOPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
4819 ISPOPMAP(0x00, 0x00), /* 0x2b: */
4820 ISPOPMAP(0x00, 0x00), /* 0x2c: */
4821 ISPOPMAP(0x00, 0x00), /* 0x2d: */
4822 ISPOPMAP(0x00, 0x00), /* 0x2e: */
4823 ISPOPMAP(0x00, 0x00), /* 0x2f: */
4824 ISPOPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
4825 ISPOPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
4826 ISPOPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
4827 ISPOPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
4828 ISPOPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
4829 ISPOPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
4830 ISPOPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
4831 ISPOPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
4832 ISPOPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
4833 ISPOPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
4834 ISPOPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
4835 ISPOPMAP(0x00, 0x00), /* 0x3b: */
4836 ISPOPMAP(0x00, 0x00), /* 0x3c: */
4837 ISPOPMAP(0x00, 0x00), /* 0x3d: */
4838 ISPOPMAP(0x00, 0x00), /* 0x3e: */
4839 ISPOPMAP(0x00, 0x00), /* 0x3f: */
4840 ISPOPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
4841 ISPOPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
4842 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
4843 ISPOPMAP(0x00, 0x00), /* 0x43: */
4844 ISPOPMAP(0x00, 0x00), /* 0x44: */
4845 ISPOPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
4846 ISPOPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
4847 ISPOPMAP(0x00, 0x00), /* 0x47: */
4848 ISPOPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
4849 ISPOPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
4850 ISPOPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
4851 ISPOPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
4852 ISPOPMAP(0x00, 0x00), /* 0x4c: */
4853 ISPOPMAP(0x00, 0x00), /* 0x4d: */
4854 ISPOPMAP(0x00, 0x00), /* 0x4e: */
4855 ISPOPMAP(0x00, 0x00), /* 0x4f: */
4856 ISPOPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
4857 ISPOPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
4858 ISPOPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
4859 ISPOPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
4860 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
4861 ISPOPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
4862 ISPOPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
4863 ISPOPMAP(0x00, 0x00), /* 0x57: */
4864 ISPOPMAP(0x00, 0x00), /* 0x58: */
4865 ISPOPMAP(0x00, 0x00), /* 0x59: */
4866 ISPOPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
4867 ISPOPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
4868 ISPOPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
4869 ISPOPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
4872 #ifndef ISP_STRIPPED
4873 static char *scsi_mbcmd_names[] = {
4890 "INIT REQUEST QUEUE",
4891 "INIT RESULT QUEUE",
4901 "SINGLE STEP QUEUE",
4903 "GET DEV QUEUE STATUS",
4905 "GET FIRMWARE STATUS",
4907 "GET SELECT TIMEOUT",
4909 "GET TAG AGE LIMIT",
4911 "GET ACT NEG STATE",
4912 "GET ASYNC DATA SETUP TIME",
4914 "GET TARGET PARAMS",
4915 "GET DEV QUEUE PARAMS",
4916 "GET RESET DELAY PARAMS",
4923 "SET SELECT TIMEOUT",
4925 "SET TAG AGE LIMIT",
4927 "SET ACT NEG STATE",
4928 "SET ASYNC DATA SETUP TIME",
4929 "SET PCI CONTROL PARAMS",
4930 "SET TARGET PARAMS",
4931 "SET DEV QUEUE PARAMS",
4932 "SET RESET DELAY PARAMS",
4938 "RETURN BIOS BLOCK ADDR",
4939 "WRITE FOUR RAM WORDS",
4943 "SET SYSTEM PARAMETER",
4944 "GET SYSTEM PARAMETER",
4946 "GET SCAM CONFIGURATION",
4947 "SET SCAM CONFIGURATION",
4948 "SET FIRMWARE FEATURES",
4949 "GET FIRMWARE FEATURES",
4956 "INITIALIZE REQUEST QUEUE A64",
4957 "INITIALIZE RESPONSE QUEUE A64",
4959 "ENABLE TARGET MODE",
4960 "GET TARGET MODE STATE",
4964 "SET DATA OVERRUN RECOVERY MODE",
4965 "GET DATA OVERRUN RECOVERY MODE",
4971 static u_int16_t mbpfc[] = {
4972 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
4973 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
4974 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
4975 ISPOPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
4976 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
4977 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
4978 ISPOPMAP(0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
4979 ISPOPMAP(0x03, 0x05), /* 0x07: MBOX_VERIFY_CHECKSUM */
4980 ISPOPMAP(0x01, 0x4f), /* 0x08: MBOX_ABOUT_FIRMWARE */
4981 ISPOPMAP(0xdf, 0x01), /* 0x09: LOAD RAM */
4982 ISPOPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
4983 ISPOPMAP(0x00, 0x00), /* 0x0b: */
4984 ISPOPMAP(0x00, 0x00), /* 0x0c: */
4985 ISPOPMAP(0x00, 0x00), /* 0x0d: */
4986 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
4987 ISPOPMAP(0x03, 0x07), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED(1) */
4988 ISPOPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
4989 ISPOPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
4990 ISPOPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
4991 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
4992 ISPOPMAP(0x01, 0xff), /* 0x14: MBOX_STOP_FIRMWARE */
4993 ISPOPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
4994 ISPOPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
4995 ISPOPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
4996 ISPOPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
4997 ISPOPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
4998 ISPOPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
4999 ISPOPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
5000 ISPOPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
5001 ISPOPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
5002 ISPOPMAP(0x00, 0x00), /* 0x1e: */
5003 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
5004 ISPOPMAP(0x01, 0x4f), /* 0x20: MBOX_GET_LOOP_ID */
5005 ISPOPMAP(0x00, 0x00), /* 0x21: */
5006 ISPOPMAP(0x01, 0x07), /* 0x22: MBOX_GET_RETRY_COUNT */
5007 ISPOPMAP(0x00, 0x00), /* 0x23: */
5008 ISPOPMAP(0x00, 0x00), /* 0x24: */
5009 ISPOPMAP(0x00, 0x00), /* 0x25: */
5010 ISPOPMAP(0x00, 0x00), /* 0x26: */
5011 ISPOPMAP(0x00, 0x00), /* 0x27: */
5012 ISPOPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
5013 ISPOPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
5014 ISPOPMAP(0x00, 0x00), /* 0x2a: */
5015 ISPOPMAP(0x00, 0x00), /* 0x2b: */
5016 ISPOPMAP(0x00, 0x00), /* 0x2c: */
5017 ISPOPMAP(0x00, 0x00), /* 0x2d: */
5018 ISPOPMAP(0x00, 0x00), /* 0x2e: */
5019 ISPOPMAP(0x00, 0x00), /* 0x2f: */
5020 ISPOPMAP(0x00, 0x00), /* 0x30: */
5021 ISPOPMAP(0x00, 0x00), /* 0x31: */
5022 ISPOPMAP(0x07, 0x07), /* 0x32: MBOX_SET_RETRY_COUNT */
5023 ISPOPMAP(0x00, 0x00), /* 0x33: */
5024 ISPOPMAP(0x00, 0x00), /* 0x34: */
5025 ISPOPMAP(0x00, 0x00), /* 0x35: */
5026 ISPOPMAP(0x00, 0x00), /* 0x36: */
5027 ISPOPMAP(0x00, 0x00), /* 0x37: */
5028 ISPOPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
5029 ISPOPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
5030 ISPOPMAP(0x00, 0x00), /* 0x3a: */
5031 ISPOPMAP(0x00, 0x00), /* 0x3b: */
5032 ISPOPMAP(0x00, 0x00), /* 0x3c: */
5033 ISPOPMAP(0x00, 0x00), /* 0x3d: */
5034 ISPOPMAP(0x00, 0x00), /* 0x3e: */
5035 ISPOPMAP(0x00, 0x00), /* 0x3f: */
5036 ISPOPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
5037 ISPOPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
5038 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_GET_RESOURCE_COUNTS */
5039 ISPOPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_NON_PARTICIPATING_MODE */
5040 ISPOPMAP(0x00, 0x00), /* 0x44: */
5041 ISPOPMAP(0x00, 0x00), /* 0x45: */
5042 ISPOPMAP(0x00, 0x00), /* 0x46: */
5043 ISPOPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
5044 ISPOPMAP(0x00, 0x00), /* 0x48: */
5045 ISPOPMAP(0x00, 0x00), /* 0x49: */
5046 ISPOPMAP(0x00, 0x00), /* 0x4a: */
5047 ISPOPMAP(0x00, 0x00), /* 0x4b: */
5048 ISPOPMAP(0x00, 0x00), /* 0x4c: */
5049 ISPOPMAP(0x00, 0x00), /* 0x4d: */
5050 ISPOPMAP(0x00, 0x00), /* 0x4e: */
5051 ISPOPMAP(0x00, 0x00), /* 0x4f: */
5052 ISPOPMAP(0x00, 0x00), /* 0x50: */
5053 ISPOPMAP(0x00, 0x00), /* 0x51: */
5054 ISPOPMAP(0x00, 0x00), /* 0x52: */
5055 ISPOPMAP(0x00, 0x00), /* 0x53: */
5056 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
5057 ISPOPMAP(0x00, 0x00), /* 0x55: */
5058 ISPOPMAP(0x00, 0x00), /* 0x56: */
5059 ISPOPMAP(0x00, 0x00), /* 0x57: */
5060 ISPOPMAP(0x00, 0x00), /* 0x58: */
5061 ISPOPMAP(0x00, 0x00), /* 0x59: */
5062 ISPOPMAP(0x00, 0x00), /* 0x5a: */
5063 ISPOPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
5064 ISPOPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
5065 ISPOPMAP(0x07, 0x03), /* 0x5d: MBOX_GET_SET_DATA_RATE */
5066 ISPOPMAP(0x00, 0x00), /* 0x5e: */
5067 ISPOPMAP(0x00, 0x00), /* 0x5f: */
5068 ISPOPMAP(0xfd, 0x31), /* 0x60: MBOX_INIT_FIRMWARE */
5069 ISPOPMAP(0x00, 0x00), /* 0x61: */
5070 ISPOPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
5071 ISPOPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
5072 ISPOPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
5073 ISPOPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
5074 ISPOPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
5075 ISPOPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
5076 ISPOPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
5077 ISPOPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
5078 ISPOPMAP(0x03, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
5079 ISPOPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
5080 ISPOPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
5081 ISPOPMAP(0x00, 0x00), /* 0x6d: */
5082 ISPOPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
5083 ISPOPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
5084 ISPOPMAP(0x03, 0x01), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
5085 ISPOPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
5086 ISPOPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
5087 ISPOPMAP(0x00, 0x00), /* 0x73: */
5088 ISPOPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
5089 ISPOPMAP(0xcf, 0x03), /* 0x75: GET PORT/NODE NAME LIST */
5090 ISPOPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
5091 ISPOPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
5092 ISPOPMAP(0x00, 0x00), /* 0x78: */
5093 ISPOPMAP(0x00, 0x00), /* 0x79: */
5094 ISPOPMAP(0x00, 0x00), /* 0x7a: */
5095 ISPOPMAP(0x00, 0x00), /* 0x7b: */
5096 ISPOPMAP(0x4f, 0x03), /* 0x7c: Get ID List */
5097 ISPOPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
5098 ISPOPMAP(0x07, 0x01) /* 0x7e: Lun RESET */
5103 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
5104 * do not access at this time in the core driver. The caller is
5105 * responsible for setting this register first (Gross!).
5108 #ifndef ISP_STRIPPED
5109 static char *fc_mbcmd_names[] = {
5123 "READ RAM WORD EXTENDED",
5126 "INIT REQUEST QUEUE",
5127 "INIT RESULT QUEUE",
5137 "SINGLE STEP QUEUE",
5139 "GET DEV QUEUE STATUS",
5141 "GET FIRMWARE STATUS",
5150 "GET FIRMWARE OPTIONS",
5151 "GET PORT QUEUE PARAMS",
5166 "SET FIRMWARE OPTIONS",
5167 "SET PORT QUEUE PARAMS",
5176 "GET RESOURCE COUNTS",
5177 "REQUEST NON PARTICIPATING MODE",
5181 "GET PORT DATABASE,, ENHANCED",
5203 "GET/SET DATA RATE",
5209 "GET FC-AL POSITION MAP",
5210 "GET PORT DATABASE",
5222 "SEND CHANGE REQUEST",
5227 "GET PORT/NODE NAME LIST",
5229 "INITIALIZE IP MAILBOX",
5241 isp_mboxcmd_qnw(struct ispsoftc *isp, mbreg_t *mbp, int nodelay)
5243 unsigned int lim, ibits, obits, box, opcode;
5248 lim = (sizeof (mbpfc) / sizeof (mbpfc[0]));
5251 lim = (sizeof (mbpscsi) / sizeof (mbpscsi[0]));
5253 opcode = mbp->param[0];
5254 ibits = HIBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5255 obits = LOBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5256 for (box = 0; box < MAX_MAILBOX; box++) {
5257 if (ibits & (1 << box)) {
5258 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5261 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5265 isp->isp_lastmbxcmd = opcode;
5266 isp->isp_obits = obits;
5267 isp->isp_mboxbsy = 1;
5269 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5271 * Oddly enough, if we're not delaying for an answer,
5272 * delay a bit to give the f/w a chance to pick up the
5281 isp_mboxcmd(struct ispsoftc *isp, mbreg_t *mbp, int logmask)
5283 char *cname, *xname, tname[16], mname[16];
5284 unsigned int lim, ibits, obits, box, opcode;
5289 lim = (sizeof (mbpfc) / sizeof (mbpfc[0]));
5292 lim = (sizeof (mbpscsi) / sizeof (mbpscsi[0]));
5295 if ((opcode = mbp->param[0]) >= lim) {
5296 mbp->param[0] = MBOX_INVALID_COMMAND;
5297 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
5301 ibits = HIBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5302 obits = LOBYT(mcp[opcode]) & NMBOX_BMASK(isp);
5304 if (ibits == 0 && obits == 0) {
5305 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
5306 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
5311 * Get exclusive usage of mailbox registers.
5315 for (box = 0; box < MAX_MAILBOX; box++) {
5316 if (ibits & (1 << box)) {
5317 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5319 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5322 isp->isp_lastmbxcmd = opcode;
5325 * We assume that we can't overwrite a previous command.
5327 isp->isp_obits = obits;
5328 isp->isp_mboxbsy = 1;
5331 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
5333 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5336 * While we haven't finished the command, spin our wheels here.
5338 MBOX_WAIT_COMPLETE(isp);
5340 if (isp->isp_mboxbsy) {
5342 * Command timed out.
5344 isp->isp_mboxbsy = 0;
5350 * Copy back output registers.
5352 for (box = 0; box < MAX_MAILBOX; box++) {
5353 if (obits & (1 << box)) {
5354 mbp->param[box] = isp->isp_mboxtmp[box];
5360 if (logmask == 0 || opcode == MBOX_EXEC_FIRMWARE) {
5366 cname = (IS_FC(isp))? fc_mbcmd_names[opcode] : scsi_mbcmd_names[opcode];
5368 if (cname == NULL) {
5370 SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
5374 * Just to be chatty here...
5377 switch (mbp->param[0]) {
5378 case MBOX_COMMAND_COMPLETE:
5380 case MBOX_INVALID_COMMAND:
5381 if (logmask & MBLOGMASK(MBOX_COMMAND_COMPLETE))
5382 xname = "INVALID COMMAND";
5384 case MBOX_HOST_INTERFACE_ERROR:
5385 if (logmask & MBLOGMASK(MBOX_HOST_INTERFACE_ERROR))
5386 xname = "HOST INTERFACE ERROR";
5388 case MBOX_TEST_FAILED:
5389 if (logmask & MBLOGMASK(MBOX_TEST_FAILED))
5390 xname = "TEST FAILED";
5392 case MBOX_COMMAND_ERROR:
5393 if (logmask & MBLOGMASK(MBOX_COMMAND_ERROR))
5394 xname = "COMMAND ERROR";
5396 case MBOX_COMMAND_PARAM_ERROR:
5397 if (logmask & MBLOGMASK(MBOX_COMMAND_PARAM_ERROR))
5398 xname = "COMMAND PARAMETER ERROR";
5400 case MBOX_LOOP_ID_USED:
5401 if (logmask & MBLOGMASK(MBOX_LOOP_ID_USED))
5402 xname = "LOOP ID ALREADY IN USE";
5404 case MBOX_PORT_ID_USED:
5405 if (logmask & MBLOGMASK(MBOX_PORT_ID_USED))
5406 xname = "PORT ID ALREADY IN USE";
5408 case MBOX_ALL_IDS_USED:
5409 if (logmask & MBLOGMASK(MBOX_ALL_IDS_USED))
5410 xname = "ALL LOOP IDS IN USE";
5412 case 0: /* special case */
5416 SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
5421 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s)",
5426 isp_fw_state(struct ispsoftc *isp)
5430 fcparam *fcp = isp->isp_param;
5432 mbs.param[0] = MBOX_GET_FW_STATE;
5433 isp_mboxcmd(isp, &mbs, MBLOGALL);
5434 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
5435 fcp->isp_fwstate = mbs.param[1];
5441 isp_update(struct ispsoftc *isp)
5445 for (bus = 0, upmask = isp->isp_update; upmask != 0; bus++) {
5446 if (upmask & (1 << bus)) {
5447 isp_update_bus(isp, bus);
5449 upmask &= ~(1 << bus);
5454 isp_update_bus(struct ispsoftc *isp, int bus)
5460 isp->isp_update &= ~(1 << bus);
5463 * There are no 'per-bus' settings for Fibre Channel.
5467 sdp = isp->isp_param;
5470 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5471 u_int16_t flags, period, offset;
5474 if (sdp->isp_devparam[tgt].dev_enable == 0) {
5475 sdp->isp_devparam[tgt].dev_update = 0;
5476 sdp->isp_devparam[tgt].dev_refresh = 0;
5477 isp_prt(isp, ISP_LOGDEBUG0,
5478 "skipping target %d bus %d update", tgt, bus);
5482 * If the goal is to update the status of the device,
5483 * take what's in goal_flags and try and set the device
5484 * toward that. Otherwise, if we're just refreshing the
5485 * current device state, get the current parameters.
5489 * Refresh overrides set
5491 if (sdp->isp_devparam[tgt].dev_refresh) {
5492 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
5493 sdp->isp_devparam[tgt].dev_refresh = 0;
5495 } else if (sdp->isp_devparam[tgt].dev_update) {
5496 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
5498 * Make sure goal_flags has "Renegotiate on Error"
5499 * on and "Freeze Queue on Error" off.
5501 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
5502 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
5504 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
5507 * Insist that PARITY must be enabled
5508 * if SYNC or WIDE is enabled.
5510 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
5511 mbs.param[2] |= DPARM_PARITY;
5514 if ((mbs.param[2] & DPARM_SYNC) == 0) {
5518 (sdp->isp_devparam[tgt].goal_offset << 8) |
5519 (sdp->isp_devparam[tgt].goal_period);
5522 * A command completion later that has
5523 * RQSTF_NEGOTIATION set can cause
5524 * the dev_refresh/announce cycle also.
5526 * Note: It is really important to update our current
5527 * flags with at least the state of TAG capabilities-
5528 * otherwise we might try and send a tagged command
5529 * when we have it all turned off. So change it here
5530 * to say that current already matches goal.
5532 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
5533 sdp->isp_devparam[tgt].actv_flags |=
5534 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
5535 isp_prt(isp, ISP_LOGDEBUG0,
5536 "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
5537 bus, tgt, mbs.param[2], mbs.param[3] >> 8,
5538 mbs.param[3] & 0xff);
5539 sdp->isp_devparam[tgt].dev_update = 0;
5540 sdp->isp_devparam[tgt].dev_refresh = 1;
5545 mbs.param[1] = (bus << 15) | (tgt << 8);
5546 isp_mboxcmd(isp, &mbs, MBLOGALL);
5548 isp->isp_sendmarker |= (1 << bus);
5551 flags = mbs.param[2];
5552 period = mbs.param[3] & 0xff;
5553 offset = mbs.param[3] >> 8;
5554 sdp->isp_devparam[tgt].actv_flags = flags;
5555 sdp->isp_devparam[tgt].actv_period = period;
5556 sdp->isp_devparam[tgt].actv_offset = offset;
5557 get = (bus << 16) | tgt;
5558 (void) isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, &get);
5561 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5562 if (sdp->isp_devparam[tgt].dev_update ||
5563 sdp->isp_devparam[tgt].dev_refresh) {
5564 isp->isp_update |= (1 << bus);
5570 #ifndef DEFAULT_FRAMESIZE
5571 #define DEFAULT_FRAMESIZE(isp) ICB_DFLT_FRMLEN
5573 #ifndef DEFAULT_EXEC_THROTTLE
5574 #define DEFAULT_EXEC_THROTTLE(isp) ISP_EXEC_THROTTLE
5578 isp_setdfltparm(struct ispsoftc *isp, int channel)
5585 fcparam *fcp = (fcparam *) isp->isp_param;
5589 if (fcp->isp_gotdparms) {
5592 fcp->isp_gotdparms = 1;
5593 fcp->isp_maxfrmlen = DEFAULT_FRAMESIZE(isp);
5594 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
5595 fcp->isp_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
5596 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
5597 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
5598 /* Platform specific.... */
5599 fcp->isp_loopid = DEFAULT_LOOPID(isp);
5600 fcp->isp_nodewwn = DEFAULT_NODEWWN(isp);
5601 fcp->isp_portwwn = DEFAULT_PORTWWN(isp);
5602 fcp->isp_fwoptions = 0;
5603 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
5604 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
5605 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
5606 #ifndef ISP_NO_FASTPOST_FC
5607 fcp->isp_fwoptions |= ICBOPT_FAST_POST;
5609 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
5610 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
5613 * Make sure this is turned off now until we get
5614 * extended options from NVRAM
5616 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
5619 * Now try and read NVRAM unless told to not do so.
5620 * This will set fcparam's isp_nodewwn && isp_portwwn.
5622 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5623 nvfail = isp_read_nvram(isp);
5625 isp->isp_confopts |= ISP_CFG_NONVRAM;
5630 * Set node && port to override platform set defaults
5631 * unless the nvram read failed (or none was done),
5632 * or the platform code wants to use what had been
5633 * set in the defaults.
5636 isp->isp_confopts |= ISP_CFG_OWNWWPN|ISP_CFG_OWNWWNN;
5638 if (isp->isp_confopts & ISP_CFG_OWNWWNN) {
5639 isp_prt(isp, ISP_LOGCONFIG, "Using Node WWN 0x%08x%08x",
5640 (u_int32_t) (DEFAULT_NODEWWN(isp) >> 32),
5641 (u_int32_t) (DEFAULT_NODEWWN(isp) & 0xffffffff));
5642 ISP_NODEWWN(isp) = DEFAULT_NODEWWN(isp);
5645 * We always start out with values derived
5646 * from NVRAM or our platform default.
5648 ISP_NODEWWN(isp) = fcp->isp_nodewwn;
5650 if (isp->isp_confopts & ISP_CFG_OWNWWPN) {
5651 isp_prt(isp, ISP_LOGCONFIG, "Using Port WWN 0x%08x%08x",
5652 (u_int32_t) (DEFAULT_PORTWWN(isp) >> 32),
5653 (u_int32_t) (DEFAULT_PORTWWN(isp) & 0xffffffff));
5654 ISP_PORTWWN(isp) = DEFAULT_PORTWWN(isp);
5657 * We always start out with values derived
5658 * from NVRAM or our platform default.
5660 ISP_PORTWWN(isp) = fcp->isp_portwwn;
5665 sdp = (sdparam *) isp->isp_param;
5669 * Been there, done that, got the T-shirt...
5671 if (sdp->isp_gotdparms) {
5674 sdp->isp_gotdparms = 1;
5677 * Establish some default parameters.
5679 sdp->isp_cmd_dma_burst_enable = 0;
5680 sdp->isp_data_dma_burst_enabl = 1;
5681 sdp->isp_fifo_threshold = 0;
5682 sdp->isp_initiator_id = DEFAULT_IID(isp);
5683 if (isp->isp_type >= ISP_HA_SCSI_1040) {
5684 sdp->isp_async_data_setup = 9;
5686 sdp->isp_async_data_setup = 6;
5688 sdp->isp_selection_timeout = 250;
5689 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
5690 sdp->isp_tag_aging = 8;
5691 sdp->isp_bus_reset_delay = 5;
5693 * Don't retry selection, busy or queue full automatically- reflect
5696 sdp->isp_retry_count = 0;
5697 sdp->isp_retry_delay = 0;
5699 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5700 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
5701 sdp->isp_devparam[tgt].dev_enable = 1;
5705 * If we've not been told to avoid reading NVRAM, try and read it.
5706 * If we're successful reading it, we can then return because NVRAM
5707 * will tell us what the desired settings are. Otherwise, we establish
5708 * some reasonable 'fake' nvram and goal defaults.
5711 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5712 if (isp_read_nvram(isp) == 0) {
5718 * Now try and see whether we have specific values for them.
5720 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5721 mbs.param[0] = MBOX_GET_ACT_NEG_STATE;
5722 isp_mboxcmd(isp, &mbs, MBLOGNONE);
5723 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
5724 sdp->isp_req_ack_active_neg = 1;
5725 sdp->isp_data_line_active_neg = 1;
5727 sdp->isp_req_ack_active_neg =
5728 (mbs.param[1+channel] >> 4) & 0x1;
5729 sdp->isp_data_line_active_neg =
5730 (mbs.param[1+channel] >> 5) & 0x1;
5734 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc3,
5735 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
5736 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
5737 sdp->isp_retry_delay, sdp->isp_async_data_setup);
5738 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc3,
5739 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
5740 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
5741 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
5744 * The trick here is to establish a default for the default (honk!)
5745 * state (goal_flags). Then try and get the current status from
5746 * the card to fill in the current state. We don't, in fact, set
5747 * the default to the SAFE default state- that's not the goal state.
5749 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5751 sdp->isp_devparam[tgt].actv_offset = 0;
5752 sdp->isp_devparam[tgt].actv_period = 0;
5753 sdp->isp_devparam[tgt].actv_flags = 0;
5755 sdp->isp_devparam[tgt].goal_flags =
5756 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
5759 * We default to Wide/Fast for versions less than a 1040
5760 * (unless it's SBus).
5762 if (IS_ULTRA3(isp)) {
5763 off = ISP_80M_SYNCPARMS >> 8;
5764 per = ISP_80M_SYNCPARMS & 0xff;
5765 } else if (IS_ULTRA2(isp)) {
5766 off = ISP_40M_SYNCPARMS >> 8;
5767 per = ISP_40M_SYNCPARMS & 0xff;
5768 } else if (IS_1240(isp)) {
5769 off = ISP_20M_SYNCPARMS >> 8;
5770 per = ISP_20M_SYNCPARMS & 0xff;
5771 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
5772 isp->isp_type < ISP_HA_SCSI_1020A) ||
5773 (isp->isp_bustype == ISP_BT_PCI &&
5774 isp->isp_type < ISP_HA_SCSI_1040) ||
5775 (isp->isp_clock && isp->isp_clock < 60) ||
5776 (sdp->isp_ultramode == 0)) {
5777 off = ISP_10M_SYNCPARMS >> 8;
5778 per = ISP_10M_SYNCPARMS & 0xff;
5780 off = ISP_20M_SYNCPARMS_1040 >> 8;
5781 per = ISP_20M_SYNCPARMS_1040 & 0xff;
5783 sdp->isp_devparam[tgt].goal_offset =
5784 sdp->isp_devparam[tgt].nvrm_offset = off;
5785 sdp->isp_devparam[tgt].goal_period =
5786 sdp->isp_devparam[tgt].nvrm_period = per;
5788 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc3,
5789 channel, tgt, sdp->isp_devparam[tgt].nvrm_flags,
5790 sdp->isp_devparam[tgt].nvrm_offset,
5791 sdp->isp_devparam[tgt].nvrm_period);
5796 * Re-initialize the ISP and complete all orphaned commands
5797 * with a 'botched' notice. The reset/init routines should
5798 * not disturb an already active list of commands.
5800 * Locks held prior to coming here.
5804 isp_reinit(struct ispsoftc *isp)
5810 if (isp->isp_state != ISP_RESETSTATE) {
5811 isp_prt(isp, ISP_LOGERR, "isp_reinit cannot reset card");
5812 } else if (isp->isp_role != ISP_ROLE_NONE) {
5814 if (isp->isp_state == ISP_INITSTATE) {
5815 isp->isp_state = ISP_RUNSTATE;
5817 if (isp->isp_state != ISP_RUNSTATE) {
5818 isp_prt(isp, ISP_LOGERR,
5819 "isp_reinit cannot restart card");
5822 isp->isp_nactive = 0;
5824 for (handle = 1; (int) handle <= isp->isp_maxcmds; handle++) {
5825 xs = isp_find_xs(isp, handle);
5829 isp_destroy_handle(isp, handle);
5830 if (XS_XFRLEN(xs)) {
5831 ISP_DMAFREE(isp, xs, handle);
5832 XS_RESID(xs) = XS_XFRLEN(xs);
5836 XS_SETERR(xs, HBA_BUSRESET);
5845 isp_read_nvram(struct ispsoftc *isp)
5848 u_int8_t csum, minversion;
5850 u_int8_t _x[ISP2100_NVRAM_SIZE];
5851 u_int16_t _s[ISP2100_NVRAM_SIZE>>1];
5853 #define nvram_data _n._x
5854 #define nvram_words _n._s
5857 amt = ISP2100_NVRAM_SIZE;
5859 } else if (IS_ULTRA2(isp)) {
5860 amt = ISP1080_NVRAM_SIZE;
5863 amt = ISP_NVRAM_SIZE;
5868 * Just read the first two words first to see if we have a valid
5869 * NVRAM to continue reading the rest with.
5871 for (i = 0; i < 2; i++) {
5872 isp_rdnvram_word(isp, i, &nvram_words[i]);
5874 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
5875 nvram_data[2] != 'P') {
5876 if (isp->isp_bustype != ISP_BT_SBUS) {
5877 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
5878 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x",
5879 nvram_data[0], nvram_data[1], nvram_data[2]);
5883 for (i = 2; i < amt>>1; i++) {
5884 isp_rdnvram_word(isp, i, &nvram_words[i]);
5886 for (csum = 0, i = 0; i < amt; i++) {
5887 csum += nvram_data[i];
5890 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
5893 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
5894 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
5895 ISP_NVRAM_VERSION(nvram_data));
5899 if (IS_ULTRA3(isp)) {
5900 isp_parse_nvram_12160(isp, 0, nvram_data);
5902 isp_parse_nvram_12160(isp, 1, nvram_data);
5903 } else if (IS_1080(isp)) {
5904 isp_parse_nvram_1080(isp, 0, nvram_data);
5905 } else if (IS_1280(isp) || IS_1240(isp)) {
5906 isp_parse_nvram_1080(isp, 0, nvram_data);
5907 isp_parse_nvram_1080(isp, 1, nvram_data);
5908 } else if (IS_SCSI(isp)) {
5909 isp_parse_nvram_1020(isp, nvram_data);
5911 isp_parse_nvram_2100(isp, nvram_data);
5919 isp_rdnvram_word(struct ispsoftc *isp, int wo, u_int16_t *rp)
5922 u_int16_t bit, rqst;
5924 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
5926 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
5930 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
5931 if (IS_2312(isp) && isp->isp_port) {
5934 rqst = (ISP_NVRAM_READ << 8) | wo;
5936 } else if (IS_ULTRA2(isp)) {
5937 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
5938 rqst = (ISP_NVRAM_READ << 8) | wo;
5941 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
5942 rqst = (ISP_NVRAM_READ << 6) | wo;
5947 * Clock the word select request out...
5949 for (i = cbits; i >= 0; i--) {
5950 if ((rqst >> i) & 1) {
5951 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
5953 bit = BIU_NVRAM_SELECT;
5955 ISP_WRITE(isp, BIU_NVRAM, bit);
5957 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
5959 ISP_WRITE(isp, BIU_NVRAM, bit);
5963 * Now read the result back in (bits come back in MSB format).
5966 for (i = 0; i < 16; i++) {
5969 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
5971 rv = ISP_READ(isp, BIU_NVRAM);
5972 if (rv & BIU_NVRAM_DATAIN) {
5976 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
5979 ISP_WRITE(isp, BIU_NVRAM, 0);
5981 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
5985 isp_parse_nvram_1020(struct ispsoftc *isp, u_int8_t *nvram_data)
5987 sdparam *sdp = (sdparam *) isp->isp_param;
5990 sdp->isp_fifo_threshold =
5991 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
5992 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
5994 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
5995 sdp->isp_initiator_id =
5996 ISP_NVRAM_INITIATOR_ID(nvram_data);
5998 sdp->isp_bus_reset_delay =
5999 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
6001 sdp->isp_retry_count =
6002 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
6004 sdp->isp_retry_delay =
6005 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
6007 sdp->isp_async_data_setup =
6008 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
6010 if (isp->isp_type >= ISP_HA_SCSI_1040) {
6011 if (sdp->isp_async_data_setup < 9) {
6012 sdp->isp_async_data_setup = 9;
6015 if (sdp->isp_async_data_setup != 6) {
6016 sdp->isp_async_data_setup = 6;
6020 sdp->isp_req_ack_active_neg =
6021 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
6023 sdp->isp_data_line_active_neg =
6024 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
6026 sdp->isp_data_dma_burst_enabl =
6027 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
6029 sdp->isp_cmd_dma_burst_enable =
6030 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
6032 sdp->isp_tag_aging =
6033 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
6035 sdp->isp_selection_timeout =
6036 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
6038 sdp->isp_max_queue_depth =
6039 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
6041 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
6043 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6044 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6045 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6046 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6047 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6048 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6049 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6050 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6052 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6053 sdp->isp_devparam[tgt].dev_enable =
6054 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
6055 sdp->isp_devparam[tgt].exc_throttle =
6056 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
6057 sdp->isp_devparam[tgt].nvrm_offset =
6058 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
6059 sdp->isp_devparam[tgt].nvrm_period =
6060 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
6062 * We probably shouldn't lie about this, but it
6063 * it makes it much safer if we limit NVRAM values
6066 if (isp->isp_type < ISP_HA_SCSI_1040) {
6068 * If we're not ultra, we can't possibly
6069 * be a shorter period than this.
6071 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
6072 sdp->isp_devparam[tgt].nvrm_period = 0x19;
6074 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
6075 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
6078 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
6079 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
6082 sdp->isp_devparam[tgt].nvrm_flags = 0;
6083 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
6084 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6085 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6086 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
6087 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6088 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
6089 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6090 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
6091 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6092 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
6093 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6094 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
6095 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6096 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
6097 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6098 0, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6099 sdp->isp_devparam[tgt].nvrm_offset,
6100 sdp->isp_devparam[tgt].nvrm_period);
6101 sdp->isp_devparam[tgt].goal_offset =
6102 sdp->isp_devparam[tgt].nvrm_offset;
6103 sdp->isp_devparam[tgt].goal_period =
6104 sdp->isp_devparam[tgt].nvrm_period;
6105 sdp->isp_devparam[tgt].goal_flags =
6106 sdp->isp_devparam[tgt].nvrm_flags;
6111 isp_parse_nvram_1080(struct ispsoftc *isp, int bus, u_int8_t *nvram_data)
6113 sdparam *sdp = (sdparam *) isp->isp_param;
6118 sdp->isp_fifo_threshold =
6119 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
6121 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6122 sdp->isp_initiator_id =
6123 ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
6125 sdp->isp_bus_reset_delay =
6126 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6128 sdp->isp_retry_count =
6129 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6131 sdp->isp_retry_delay =
6132 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6134 sdp->isp_async_data_setup =
6135 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6137 sdp->isp_req_ack_active_neg =
6138 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6140 sdp->isp_data_line_active_neg =
6141 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6143 sdp->isp_data_dma_burst_enabl =
6144 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6146 sdp->isp_cmd_dma_burst_enable =
6147 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6149 sdp->isp_selection_timeout =
6150 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6152 sdp->isp_max_queue_depth =
6153 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6155 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6156 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6157 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6158 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6159 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6160 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6161 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6162 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6165 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6166 sdp->isp_devparam[tgt].dev_enable =
6167 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6168 sdp->isp_devparam[tgt].exc_throttle =
6169 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6170 sdp->isp_devparam[tgt].nvrm_offset =
6171 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6172 sdp->isp_devparam[tgt].nvrm_period =
6173 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6174 sdp->isp_devparam[tgt].nvrm_flags = 0;
6175 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6176 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6177 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6178 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6179 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6180 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6181 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6182 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6183 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6184 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6185 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6186 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6187 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6188 sdp->isp_devparam[tgt].actv_flags = 0;
6189 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6190 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6191 sdp->isp_devparam[tgt].nvrm_offset,
6192 sdp->isp_devparam[tgt].nvrm_period);
6193 sdp->isp_devparam[tgt].goal_offset =
6194 sdp->isp_devparam[tgt].nvrm_offset;
6195 sdp->isp_devparam[tgt].goal_period =
6196 sdp->isp_devparam[tgt].nvrm_period;
6197 sdp->isp_devparam[tgt].goal_flags =
6198 sdp->isp_devparam[tgt].nvrm_flags;
6203 isp_parse_nvram_12160(struct ispsoftc *isp, int bus, u_int8_t *nvram_data)
6205 sdparam *sdp = (sdparam *) isp->isp_param;
6210 sdp->isp_fifo_threshold =
6211 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
6213 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6214 sdp->isp_initiator_id =
6215 ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
6217 sdp->isp_bus_reset_delay =
6218 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6220 sdp->isp_retry_count =
6221 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6223 sdp->isp_retry_delay =
6224 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6226 sdp->isp_async_data_setup =
6227 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6229 sdp->isp_req_ack_active_neg =
6230 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6232 sdp->isp_data_line_active_neg =
6233 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6235 sdp->isp_data_dma_burst_enabl =
6236 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6238 sdp->isp_cmd_dma_burst_enable =
6239 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6241 sdp->isp_selection_timeout =
6242 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6244 sdp->isp_max_queue_depth =
6245 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6247 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6248 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6249 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6250 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6251 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6252 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6253 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6254 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6256 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6257 sdp->isp_devparam[tgt].dev_enable =
6258 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6259 sdp->isp_devparam[tgt].exc_throttle =
6260 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6261 sdp->isp_devparam[tgt].nvrm_offset =
6262 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6263 sdp->isp_devparam[tgt].nvrm_period =
6264 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6265 sdp->isp_devparam[tgt].nvrm_flags = 0;
6266 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6267 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6268 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6269 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6270 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6271 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6272 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6273 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6274 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6275 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6276 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6277 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6278 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6279 sdp->isp_devparam[tgt].actv_flags = 0;
6280 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6281 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6282 sdp->isp_devparam[tgt].nvrm_offset,
6283 sdp->isp_devparam[tgt].nvrm_period);
6284 sdp->isp_devparam[tgt].goal_offset =
6285 sdp->isp_devparam[tgt].nvrm_offset;
6286 sdp->isp_devparam[tgt].goal_period =
6287 sdp->isp_devparam[tgt].nvrm_period;
6288 sdp->isp_devparam[tgt].goal_flags =
6289 sdp->isp_devparam[tgt].nvrm_flags;
6294 isp_parse_nvram_2100(struct ispsoftc *isp, u_int8_t *nvram_data)
6296 fcparam *fcp = (fcparam *) isp->isp_param;
6300 * There is NVRAM storage for both Port and Node entities-
6301 * but the Node entity appears to be unused on all the cards
6302 * I can find. However, we should account for this being set
6303 * at some point in the future.
6305 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
6306 * bits 48..60. In the case of the 2202, it appears that they do
6307 * use bit 48 to distinguish between the two instances on the card.
6308 * The 2204, which I've never seen, *probably* extends this method.
6310 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
6312 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
6313 (u_int32_t) (wwn >> 32), (u_int32_t) (wwn & 0xffffffff));
6314 if ((wwn >> 60) == 0) {
6315 wwn |= (((u_int64_t) 2)<< 60);
6318 fcp->isp_portwwn = wwn;
6319 if (IS_2200(isp) || IS_23XX(isp)) {
6320 wwn = ISP2200_NVRAM_NODE_NAME(nvram_data);
6322 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
6323 (u_int32_t) (wwn >> 32),
6324 (u_int32_t) (wwn & 0xffffffff));
6325 if ((wwn >> 60) == 0) {
6326 wwn |= (((u_int64_t) 2)<< 60);
6330 wwn &= ~((u_int64_t) 0xfff << 48);
6332 fcp->isp_nodewwn = wwn;
6335 * Make sure we have both Node and Port as non-zero values.
6337 if (fcp->isp_nodewwn != 0 && fcp->isp_portwwn == 0) {
6338 fcp->isp_portwwn = fcp->isp_nodewwn;
6339 } else if (fcp->isp_nodewwn == 0 && fcp->isp_portwwn != 0) {
6340 fcp->isp_nodewwn = fcp->isp_portwwn;
6344 * Make the Node and Port values sane if they're NAA == 2.
6345 * This means to clear bits 48..56 for the Node WWN and
6346 * make sure that there's some non-zero value in 48..56
6349 if (fcp->isp_nodewwn && fcp->isp_portwwn) {
6350 if ((fcp->isp_nodewwn & (((u_int64_t) 0xfff) << 48)) != 0 &&
6351 (fcp->isp_nodewwn >> 60) == 2) {
6352 fcp->isp_nodewwn &= ~((u_int64_t) 0xfff << 48);
6354 if ((fcp->isp_portwwn & (((u_int64_t) 0xfff) << 48)) == 0 &&
6355 (fcp->isp_portwwn >> 60) == 2) {
6356 fcp->isp_portwwn |= ((u_int64_t) 1 << 56);
6360 isp_prt(isp, ISP_LOGDEBUG0,
6361 "NVRAM: maxfrmlen %d execthrottle %d fwoptions 0x%x loopid %x",
6362 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data),
6363 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
6364 ISP2100_NVRAM_OPTIONS(nvram_data),
6365 ISP2100_NVRAM_HARDLOOPID(nvram_data));
6368 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
6369 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0)
6370 fcp->isp_maxfrmlen =
6371 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
6372 fcp->isp_retry_delay =
6373 ISP2100_NVRAM_RETRY_DELAY(nvram_data);
6374 fcp->isp_retry_count =
6375 ISP2100_NVRAM_RETRY_COUNT(nvram_data);
6376 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6378 ISP2100_NVRAM_HARDLOOPID(nvram_data);
6379 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0)
6380 fcp->isp_execthrottle =
6381 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
6382 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
6385 #ifdef ISP_FW_CRASH_DUMP
6386 static void isp2200_fw_dump(struct ispsoftc *);
6387 static void isp2300_fw_dump(struct ispsoftc *);
6390 isp2200_fw_dump(struct ispsoftc *isp)
6396 ptr = FCPARAM(isp)->isp_dump_data;
6398 isp_prt(isp, ISP_LOGERR,
6399 "No place to dump RISC registers and SRAM");
6403 isp_prt(isp, ISP_LOGERR,
6404 "dump area for RISC registers and SRAM already used");
6407 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6408 for (i = 0; i < 100; i++) {
6410 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6414 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6418 for (i = 0; i < 8; i++) {
6419 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6425 for (i = 0; i < 8; i++) {
6426 *ptr++ = ISP_READ(isp, MBOX_BLOCK + (i << 1));
6432 for (i = 0; i < 48; i++) {
6433 *ptr++ = ISP_READ(isp, DMA_BLOCK + 0x20 + (i << 1));
6437 * RISC H/W Registers
6439 ISP_WRITE(isp, BIU2100_CSR, 0);
6440 for (i = 0; i < 16; i++) {
6441 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6447 for (j = 0; j < 8; j++) {
6448 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 8));
6449 for (i = 0; i < 16; i++) {
6451 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6456 * Frame Buffer Hardware Registers
6458 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6459 for (i = 0; i < 16; i++) {
6460 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6464 * Fibre Protocol Module 0 Hardware Registers
6466 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6467 for (i = 0; i < 64; i++) {
6468 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6472 * Fibre Protocol Module 1 Hardware Registers
6474 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6475 for (i = 0; i < 64; i++) {
6476 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6479 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6482 isp_prt(isp, ISP_LOGALL,
6483 "isp_fw_dump: RISC registers dumped successfully");
6484 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6485 for (i = 0; i < 100; i++) {
6487 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6491 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6492 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6495 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6496 for (i = 0; i < 100; i++) {
6498 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6502 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6503 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause After Reset");
6506 ISP_WRITE(isp, RISC_EMB, 0xf2);
6507 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
6508 for (i = 0; i < 100; i++) {
6510 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6515 mbs.param[0] = MBOX_READ_RAM_WORD;
6516 mbs.param[1] = 0x1000;
6517 isp->isp_mbxworkp = (void *) ptr;
6518 isp->isp_mbxwrk0 = 0xefff; /* continuation count */
6519 isp->isp_mbxwrk1 = 0x1001; /* next SRAM address */
6520 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6521 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6522 isp_prt(isp, ISP_LOGWARN,
6523 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6526 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6527 *ptr++ = isp->isp_mboxtmp[2];
6528 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped succesfully");
6529 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6530 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6534 isp2300_fw_dump(struct ispsoftc *isp)
6540 ptr = FCPARAM(isp)->isp_dump_data;
6542 isp_prt(isp, ISP_LOGERR,
6543 "No place to dump RISC registers and SRAM");
6547 isp_prt(isp, ISP_LOGERR,
6548 "dump area for RISC registers and SRAM already used");
6551 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6552 for (i = 0; i < 100; i++) {
6554 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6558 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6562 for (i = 0; i < 8; i++) {
6563 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6567 * ReqQ-RspQ-Risc2Host Status registers
6569 for (i = 0; i < 8; i++) {
6570 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x10 + (i << 1));
6576 for (i = 0; i < 32; i++) {
6578 ISP_READ(isp, PCI_MBOX_REGS2300_OFF + (i << 1));
6582 * Auto Request Response DMA registers
6584 ISP_WRITE(isp, BIU2100_CSR, 0x40);
6585 for (i = 0; i < 32; i++) {
6586 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6592 ISP_WRITE(isp, BIU2100_CSR, 0x50);
6593 for (i = 0; i < 48; i++) {
6594 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6598 * RISC hardware registers
6600 ISP_WRITE(isp, BIU2100_CSR, 0);
6601 for (i = 0; i < 16; i++) {
6602 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6606 * RISC GP? registers
6608 for (j = 0; j < 8; j++) {
6609 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 9));
6610 for (i = 0; i < 16; i++) {
6612 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6617 * frame buffer hardware registers
6619 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6620 for (i = 0; i < 64; i++) {
6621 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6625 * FPM B0 hardware registers
6627 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6628 for (i = 0; i < 64; i++) {
6629 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6633 * FPM B1 hardware registers
6635 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6636 for (i = 0; i < 64; i++) {
6637 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6640 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6643 isp_prt(isp, ISP_LOGALL,
6644 "isp_fw_dump: RISC registers dumped successfully");
6645 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6646 for (i = 0; i < 100; i++) {
6648 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6652 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6653 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6657 mbs.param[0] = MBOX_READ_RAM_WORD;
6658 mbs.param[1] = 0x800;
6659 isp->isp_mbxworkp = (void *) ptr;
6660 isp->isp_mbxwrk0 = 0xf7ff; /* continuation count */
6661 isp->isp_mbxwrk1 = 0x801; /* next SRAM address */
6662 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6663 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6664 isp_prt(isp, ISP_LOGWARN,
6665 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6668 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6669 *ptr++ = isp->isp_mboxtmp[2];
6672 * We don't have access to mailbox registers 8.. onward
6673 * in our 'common' device model- so we have to set it
6674 * here and hope it stays the same!
6676 ISP_WRITE(isp, PCI_MBOX_REGS2300_OFF + (8 << 1), 0x1);
6678 mbs.param[0] = MBOX_READ_RAM_WORD_EXTENDED;
6680 isp->isp_mbxworkp = (void *) ptr;
6681 isp->isp_mbxwrk0 = 0xffff; /* continuation count */
6682 isp->isp_mbxwrk1 = 0x1; /* next SRAM address */
6683 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6684 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6685 isp_prt(isp, ISP_LOGWARN,
6686 "RAM DUMP FAILED @ WORD %x", 0x10000 + isp->isp_mbxwrk1);
6689 ptr = isp->isp_mbxworkp; /* finish final word */
6690 *ptr++ = mbs.param[2];
6691 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped succesfully");
6692 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6693 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6697 isp_fw_dump(struct ispsoftc *isp)
6700 isp2200_fw_dump(isp);
6701 else if (IS_23XX(isp))
6702 isp2300_fw_dump(isp);