2 * Copyright (c) 1997-2006 by Matthew Jacob
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice immediately at the beginning of the file, without modification,
10 * this list of conditions, and the following disclaimer.
11 * 2. The name of the author may not be used to endorse or promote products
12 * derived from this software without specific prior written permission.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * Machine and OS Independent (well, as best as possible)
29 * code for the Qlogic ISP SCSI adapters.
32 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
33 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
34 * ideas dredged from the Solaris driver.
38 * Include header file appropriate for platform we're building on.
41 #include <dev/ic/isp_netbsd.h>
44 #include <sys/cdefs.h>
45 __FBSDID("$FreeBSD$");
46 #include <dev/isp/isp_freebsd.h>
49 #include <dev/ic/isp_openbsd.h>
52 #include "isp_linux.h"
55 #include "isp_solaris.h"
62 #define MBOX_DELAY_COUNT 1000000 / 100
67 static const char portshift[] =
68 "Target %d Loop ID 0x%x (Port 0x%x) => Loop 0x%x (Port 0x%x)";
69 static const char portdup[] =
70 "Target %d duplicates Target %d- killing off both";
71 static const char retained[] =
72 "Retaining Loop ID 0x%x for Target %d (Port 0x%x)";
73 static const char lretained[] =
74 "Retained login of Target %d (Loop ID 0x%x) Port 0x%x";
75 static const char plogout[] =
76 "Logging out Target %d at Loop ID 0x%x (Port 0x%x)";
77 static const char plogierr[] =
78 "Command Error in PLOGI for Port 0x%x (0x%x)";
79 static const char nopdb[] =
80 "Could not get PDB for Device @ Port 0x%x";
81 static const char pdbmfail1[] =
82 "PDB Loop ID info for Device @ Port 0x%x does not match up (0x%x)";
83 static const char pdbmfail2[] =
84 "PDB Port info for Device @ Port 0x%x does not match up (0x%x)";
85 static const char ldumped[] =
86 "Target %d (Loop ID 0x%x) Port 0x%x dumped after login info mismatch";
87 static const char notresp[] =
88 "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
89 static const char xact1[] =
90 "HBA attempted queued transaction with disconnect not set for %d.%d.%d";
91 static const char xact2[] =
92 "HBA attempted queued transaction to target routine %d on target %d bus %d";
93 static const char xact3[] =
94 "HBA attempted queued cmd for %d.%d.%d when queueing disabled";
95 static const char pskip[] =
96 "SCSI phase skipped for target %d.%d.%d";
97 static const char topology[] =
98 "Loop ID %d, Port ID 0x%x, Loop State 0x%x, Topology '%s'";
99 static const char swrej[] =
100 "Fabric Nameserver rejected %s (Reason=0x%x Expl=0x%x) for Port ID 0x%x";
101 static const char finmsg[] =
102 "%d.%d.%d: FIN dl%d resid %d STS 0x%x SKEY %c XS_ERR=0x%x";
103 static const char sc0[] =
104 "%s CHAN %d FTHRSH %d IID %d RESETD %d RETRYC %d RETRYD %d ASD 0x%x";
105 static const char sc1[] =
106 "%s RAAN 0x%x DLAN 0x%x DDMAB 0x%x CDMAB 0x%x SELTIME %d MQD %d";
107 static const char sc2[] = "%s CHAN %d TGT %d FLAGS 0x%x 0x%x/0x%x";
108 static const char sc3[] = "Generated";
109 static const char sc4[] = "NVRAM";
110 static const char bun[] =
111 "bad underrun for %d.%d (count %d, resid %d, status %s)";
114 * Local function prototypes.
116 static int isp_parse_async(ispsoftc_t *, uint16_t);
117 static int isp_handle_other_response(ispsoftc_t *, int, isphdr_t *,
120 isp_parse_status(ispsoftc_t *, ispstatusreq_t *, XS_T *);
121 static void isp_fastpost_complete(ispsoftc_t *, uint16_t);
122 static int isp_mbox_continue(ispsoftc_t *);
123 static void isp_scsi_init(ispsoftc_t *);
124 static void isp_scsi_channel_init(ispsoftc_t *, int);
125 static void isp_fibre_init(ispsoftc_t *);
126 static void isp_mark_getpdb_all(ispsoftc_t *);
127 static int isp_getmap(ispsoftc_t *, fcpos_map_t *);
128 static int isp_getpdb(ispsoftc_t *, int, isp_pdb_t *);
129 static uint64_t isp_get_portname(ispsoftc_t *, int, int);
130 static int isp_fclink_test(ispsoftc_t *, int);
131 static const char *isp2100_fw_statename(int);
132 static int isp_pdb_sync(ispsoftc_t *);
133 static int isp_scan_loop(ispsoftc_t *);
134 static int isp_fabric_mbox_cmd(ispsoftc_t *, mbreg_t *);
135 static int isp_scan_fabric(ispsoftc_t *, int);
136 static void isp_register_fc4_type(ispsoftc_t *);
137 static void isp_fw_state(ispsoftc_t *);
138 static void isp_mboxcmd_qnw(ispsoftc_t *, mbreg_t *, int);
139 static void isp_mboxcmd(ispsoftc_t *, mbreg_t *, int);
141 static void isp_update(ispsoftc_t *);
142 static void isp_update_bus(ispsoftc_t *, int);
143 static void isp_setdfltparm(ispsoftc_t *, int);
144 static int isp_read_nvram(ispsoftc_t *);
145 static void isp_rdnvram_word(ispsoftc_t *, int, uint16_t *);
146 static void isp_parse_nvram_1020(ispsoftc_t *, uint8_t *);
147 static void isp_parse_nvram_1080(ispsoftc_t *, int, uint8_t *);
148 static void isp_parse_nvram_12160(ispsoftc_t *, int, uint8_t *);
149 static void isp_parse_nvram_2100(ispsoftc_t *, uint8_t *);
154 * Hit the chip over the head, download new f/w if available and set it running.
156 * Locking done elsewhere.
160 isp_reset(ispsoftc_t *isp)
164 int loops, i, dodnld = 1;
165 char *btype = "????";
167 isp->isp_state = ISP_NILSTATE;
170 * Basic types (SCSI, FibreChannel and PCI or SBus)
171 * have been set in the MD code. We figure out more
172 * here. Possibly more refined types based upon PCI
173 * identification. Chip revision has been gathered.
175 * After we've fired this chip up, zero out the conf1 register
176 * for SCSI adapters and do other settings for the 2100.
180 * Get the current running firmware revision out of the
181 * chip before we hit it over the head (if this is our
182 * first time through). Note that we store this as the
183 * 'ROM' firmware revision- which it may not be. In any
184 * case, we don't really use this yet, but we may in
187 if (isp->isp_touched == 0) {
189 * First see whether or not we're sitting in the ISP PROM.
190 * If we've just been reset, we'll have the string "ISP "
191 * spread through outgoing mailbox registers 1-3. We do
192 * this for PCI cards because otherwise we really don't
193 * know what state the card is in and we could hang if
194 * we try this command otherwise.
196 * For SBus cards, we just do this because they almost
197 * certainly will be running firmware by now.
199 if (ISP_READ(isp, OUTMAILBOX1) != 0x4953 ||
200 ISP_READ(isp, OUTMAILBOX2) != 0x5020 ||
201 ISP_READ(isp, OUTMAILBOX3) != 0x2020) {
203 * Just in case it was paused...
205 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
206 MEMZERO(&mbs, sizeof (mbs));
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;
229 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
230 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
231 ISP_WRITE(isp, isp->isp_respinrp, 0);
232 ISP_WRITE(isp, isp->isp_respoutrp, 0);
234 isp->isp_rqstinrp = INMAILBOX4;
235 isp->isp_rqstoutrp = OUTMAILBOX4;
236 isp->isp_respinrp = OUTMAILBOX5;
237 isp->isp_respoutrp = INMAILBOX5;
241 * Put the board into PAUSE mode (so we can read the SXP registers
242 * or write FPM/FBM registers).
244 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
247 switch (isp->isp_type) {
270 * While we're paused, reset the FPM module and FBM fifos.
272 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
273 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
274 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
275 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
276 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
277 } else if (IS_1240(isp)) {
278 sdparam *sdp = isp->isp_param;
281 sdp->isp_ultramode = 1;
283 sdp->isp_ultramode = 1;
285 * XXX: Should probably do some bus sensing.
287 } else if (IS_ULTRA2(isp)) {
288 static const char m[] = "bus %d is in %s Mode";
290 sdparam *sdp = isp->isp_param;
292 isp->isp_clock = 100;
296 else if (IS_1080(isp))
298 else if (IS_10160(isp))
300 else if (IS_12160(isp))
305 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
307 case ISP1080_LVD_MODE:
308 sdp->isp_lvdmode = 1;
309 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
311 case ISP1080_HVD_MODE:
312 sdp->isp_diffmode = 1;
313 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
315 case ISP1080_SE_MODE:
316 sdp->isp_ultramode = 1;
317 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
320 isp_prt(isp, ISP_LOGERR,
321 "unknown mode on bus %d (0x%x)", 0, l);
325 if (IS_DUALBUS(isp)) {
327 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
328 l &= ISP1080_MODE_MASK;
330 case ISP1080_LVD_MODE:
331 sdp->isp_lvdmode = 1;
332 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
334 case ISP1080_HVD_MODE:
335 sdp->isp_diffmode = 1;
336 isp_prt(isp, ISP_LOGCONFIG,
337 m, 1, "Differential");
339 case ISP1080_SE_MODE:
340 sdp->isp_ultramode = 1;
341 isp_prt(isp, ISP_LOGCONFIG,
342 m, 1, "Single-Ended");
345 isp_prt(isp, ISP_LOGERR,
346 "unknown mode on bus %d (0x%x)", 1, l);
351 sdparam *sdp = isp->isp_param;
352 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
355 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
359 isp->isp_type = ISP_HA_SCSI_1020;
364 * Some 1020A chips are Ultra Capable, but don't
365 * run the clock rate up for that unless told to
366 * do so by the Ultra Capable bits being set.
369 isp->isp_type = ISP_HA_SCSI_1020A;
374 isp->isp_type = ISP_HA_SCSI_1040;
379 isp->isp_type = ISP_HA_SCSI_1040A;
384 isp->isp_type = ISP_HA_SCSI_1040B;
389 isp->isp_type = ISP_HA_SCSI_1040C;
394 * Now, while we're at it, gather info about ultra
395 * and/or differential mode.
397 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
398 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
399 sdp->isp_diffmode = 1;
401 sdp->isp_diffmode = 0;
403 i = ISP_READ(isp, RISC_PSR);
404 if (isp->isp_bustype == ISP_BT_SBUS) {
405 i &= RISC_PSR_SBUS_ULTRA;
407 i &= RISC_PSR_PCI_ULTRA;
410 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
411 sdp->isp_ultramode = 1;
413 * If we're in Ultra Mode, we have to be 60MHz clock-
414 * even for the SBus version.
418 sdp->isp_ultramode = 0;
420 * Clock is known. Gronk.
425 * Machine dependent clock (if set) overrides
426 * our generic determinations.
428 if (isp->isp_mdvec->dv_clock) {
429 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
430 isp->isp_clock = isp->isp_mdvec->dv_clock;
437 * Clear instrumentation
439 isp->isp_intcnt = isp->isp_intbogus = 0;
442 * Do MD specific pre initialization
449 * Hit the chip over the head with hammer,
450 * and give the ISP a chance to recover.
454 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
461 * Clear data && control DMA engines.
463 ISP_WRITE(isp, CDMA_CONTROL,
464 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
465 ISP_WRITE(isp, DDMA_CONTROL,
466 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
470 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
477 * Clear data && control DMA engines.
479 ISP_WRITE(isp, CDMA2100_CONTROL,
480 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
481 ISP_WRITE(isp, TDMA2100_CONTROL,
482 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
483 ISP_WRITE(isp, RDMA2100_CONTROL,
484 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
488 * Wait for ISP to be ready to go...
490 loops = MBOX_DELAY_COUNT;
493 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET))
496 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
501 ISP_DUMPREGS(isp, "chip reset timed out");
507 * After we've fired this chip up, zero out the conf1 register
508 * for SCSI adapters and other settings for the 2100.
512 ISP_WRITE(isp, BIU_CONF1, 0);
514 ISP_WRITE(isp, BIU2100_CSR, 0);
518 * Reset RISC Processor
520 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
522 /* Clear semaphore register (just to be sure) */
523 ISP_WRITE(isp, BIU_SEMA, 0);
526 * Establish some initial burst rate stuff.
527 * (only for the 1XX0 boards). This really should
528 * be done later after fetching from NVRAM.
531 uint16_t tmp = isp->isp_mdvec->dv_conf1;
533 * Busted FIFO. Turn off all but burst enables.
535 if (isp->isp_type == ISP_HA_SCSI_1040A) {
536 tmp &= BIU_BURST_ENABLE;
538 ISP_SETBITS(isp, BIU_CONF1, tmp);
539 if (tmp & BIU_BURST_ENABLE) {
540 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
541 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
543 ISP_WRITE(isp, RISC_MTR, 0x1212);
545 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
546 if (IS_2200(isp) || IS_23XX(isp)) {
547 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
551 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE); /* release paused processor */
554 * Do MD specific post initialization
559 * Wait for everything to finish firing up.
561 * Avoid doing this on the 2312 because you can generate a PCI
562 * parity error (chip breakage).
567 loops = MBOX_DELAY_COUNT;
568 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
571 isp_prt(isp, ISP_LOGERR,
572 "MBOX_BUSY never cleared on reset");
579 * Up until this point we've done everything by just reading or
580 * setting registers. From this point on we rely on at least *some*
581 * kind of firmware running in the card.
585 * Do some sanity checking.
587 MEMZERO(&mbs, sizeof (mbs));
588 mbs.param[0] = MBOX_NO_OP;
589 isp_mboxcmd(isp, &mbs, MBLOGALL);
590 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
595 MEMZERO(&mbs, sizeof (mbs));
596 mbs.param[0] = MBOX_MAILBOX_REG_TEST;
597 mbs.param[1] = 0xdead;
598 mbs.param[2] = 0xbeef;
599 mbs.param[3] = 0xffff;
600 mbs.param[4] = 0x1111;
601 mbs.param[5] = 0xa5a5;
602 isp_mboxcmd(isp, &mbs, MBLOGALL);
603 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
606 if (mbs.param[1] != 0xdead || mbs.param[2] != 0xbeef ||
607 mbs.param[3] != 0xffff || mbs.param[4] != 0x1111 ||
608 mbs.param[5] != 0xa5a5) {
609 isp_prt(isp, ISP_LOGERR,
610 "Register Test Failed (0x%x 0x%x 0x%x 0x%x 0x%x)",
611 mbs.param[1], mbs.param[2], mbs.param[3],
612 mbs.param[4], mbs.param[5]);
619 * Download new Firmware, unless requested not to do so.
620 * This is made slightly trickier in some cases where the
621 * firmware of the ROM revision is newer than the revision
622 * compiled into the driver. So, where we used to compare
623 * versions of our f/w and the ROM f/w, now we just see
624 * whether we have f/w at all and whether a config flag
625 * has disabled our download.
627 if ((isp->isp_mdvec->dv_ispfw == NULL) ||
628 (isp->isp_confopts & ISP_CFG_NORELOAD)) {
633 code_org = ISP_CODE_ORG_2300;
635 code_org = ISP_CODE_ORG;
638 uint16_t *ptr = isp->isp_mdvec->dv_ispfw;
640 isp->isp_mbxworkp = &ptr[1];
641 isp->isp_mbxwrk0 = ptr[3] - 1;
642 isp->isp_mbxwrk1 = code_org + 1;
643 MEMZERO(&mbs, sizeof (mbs));
644 mbs.param[0] = MBOX_WRITE_RAM_WORD;
645 mbs.param[1] = code_org;
646 mbs.param[2] = ptr[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);
657 * If we're a 2322, the firmware actually comes in three chunks.
658 * We loaded the first at the code_org address. The other two
659 * chunks, which follow right after each other in memory here,
660 * get loaded at addresses specfied at offset 0x9..0xB.
668 offset = ptr[5] | (((uint32_t)(ptr[4] & 0xff)) << 16);
669 isp->isp_mbxworkp = &ptr[1];
670 isp->isp_mbxwrk0 = ptr[3] + 1;
671 isp->isp_mbxwrk1 = offset + 1;
672 isp->isp_mbxwrk8 = (offset + 1) >> 16;
673 MEMZERO(&mbs, sizeof (mbs));
674 mbs.param[0] = MBOX_WRITE_RAM_WORD_EXTENDED;
675 mbs.param[1] = offset;
676 mbs.param[2] = ptr[0];
677 mbs.param[8] = offset >> 16;
678 isp_mboxcmd(isp, &mbs, MBLOGNONE);
679 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
680 isp_prt(isp, ISP_LOGERR,
681 "Receive Sequencer F/W Load Failed");
687 offset = ptr[5] | (((uint32_t)(ptr[4] & 0xff)) << 16);
688 isp->isp_mbxworkp = &ptr[1];
689 isp->isp_mbxwrk0 = ptr[3] - 1;
690 isp->isp_mbxwrk1 = (offset + 1);
691 isp->isp_mbxwrk8 = (offset + 1) >> 16;
692 MEMZERO(&mbs, sizeof (mbs));
693 mbs.param[0] = MBOX_WRITE_RAM_WORD_EXTENDED;
694 mbs.param[1] = offset;
695 mbs.param[2] = ptr[0];
696 mbs.param[8] = offset >> 16;
697 isp_mboxcmd(isp, &mbs, MBLOGNONE);
698 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
699 isp_prt(isp, ISP_LOGERR,
700 "Transmit Sequencer F/W Load Failed");
705 * Verify that it downloaded correctly.
707 MEMZERO(&mbs, sizeof (mbs));
708 mbs.param[0] = MBOX_VERIFY_CHECKSUM;
709 mbs.param[1] = code_org;
710 isp_mboxcmd(isp, &mbs, MBLOGNONE);
711 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
712 isp_prt(isp, ISP_LOGERR,
713 "Downloaded RISC Code Checksum Failure");
718 isp->isp_loaded_fw = 1;
720 isp->isp_loaded_fw = 0;
721 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
725 * Now start it rolling.
727 * If we didn't actually download f/w,
728 * we still need to (re)start it.
732 MEMZERO(&mbs, sizeof (mbs));
733 mbs.param[0] = MBOX_EXEC_FIRMWARE;
734 mbs.param[1] = code_org;
735 if (IS_2322(isp) || IS_24XX(isp)) {
736 if (isp->isp_loaded_fw) {
742 isp_mboxcmd(isp, &mbs, MBLOGNONE);
743 if (IS_2322(isp) || IS_24XX(isp)) {
744 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
745 isp_prt(isp, ISP_LOGERR, "EXEC F/W failed: 0x%x",
752 * Give it a chance to start.
758 * Set CLOCK RATE, but only if asked to.
760 if (isp->isp_clock) {
761 mbs.param[0] = MBOX_SET_CLOCK_RATE;
762 mbs.param[1] = isp->isp_clock;
763 isp_mboxcmd(isp, &mbs, MBLOGALL);
764 /* we will try not to care if this fails */
768 MEMZERO(&mbs, sizeof (mbs));
769 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
770 isp_mboxcmd(isp, &mbs, MBLOGALL);
771 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
776 * The SBus firmware that we are using apparently does not return
777 * major, minor, micro revisions in the mailbox registers, which
778 * is really, really, annoying.
780 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
782 #ifdef ISP_TARGET_MODE
783 isp->isp_fwrev[0] = 7;
784 isp->isp_fwrev[1] = 55;
786 isp->isp_fwrev[0] = 1;
787 isp->isp_fwrev[1] = 37;
789 isp->isp_fwrev[2] = 0;
792 isp->isp_fwrev[0] = mbs.param[1];
793 isp->isp_fwrev[1] = mbs.param[2];
794 isp->isp_fwrev[2] = mbs.param[3];
797 isp_prt(isp, ISP_LOGCONFIG,
798 "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
799 btype, isp->isp_revision, dodnld? "loaded" : "resident",
800 isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
804 * We do not believe firmware attributes for 2100 code less
805 * than 1.17.0, unless it's the firmware we specifically
808 * Note that all 22XX and 23XX f/w is greater than 1.X.0.
810 if (!(ISP_FW_NEWER_THAN(isp, 1, 17, 0))) {
811 #ifdef USE_SMALLER_2100_FIRMWARE
812 FCPARAM(isp)->isp_fwattr = ISP_FW_ATTR_SCCLUN;
814 FCPARAM(isp)->isp_fwattr = 0;
817 FCPARAM(isp)->isp_fwattr = mbs.param[6];
818 isp_prt(isp, ISP_LOGDEBUG0,
819 "Firmware Attributes = 0x%x", mbs.param[6]);
821 if (IS_2KLOGIN(isp)) {
822 isp_prt(isp, ISP_LOGCONFIG, "2K Logins Supported");
826 if (isp->isp_romfw_rev[0] || isp->isp_romfw_rev[1] ||
827 isp->isp_romfw_rev[2]) {
828 isp_prt(isp, ISP_LOGCONFIG, "Last F/W revision was %d.%d.%d",
829 isp->isp_romfw_rev[0], isp->isp_romfw_rev[1],
830 isp->isp_romfw_rev[2]);
833 MEMZERO(&mbs, sizeof (mbs));
834 mbs.param[0] = MBOX_GET_FIRMWARE_STATUS;
835 isp_mboxcmd(isp, &mbs, MBLOGALL);
836 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
839 isp->isp_maxcmds = mbs.param[2];
840 isp_prt(isp, ISP_LOGINFO,
841 "%d max I/O commands supported", mbs.param[2]);
845 * Set up DMA for the request and result mailboxes.
847 if (ISP_MBOXDMASETUP(isp) != 0) {
848 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
851 isp->isp_state = ISP_RESETSTATE;
854 * Okay- now that we have new firmware running, we now (re)set our
855 * notion of how many luns we support. This is somewhat tricky because
856 * if we haven't loaded firmware, we sometimes do not have an easy way
857 * of knowing how many luns we support.
859 * Expanded lun firmware gives you 32 luns for SCSI cards and
860 * 16384 luns for Fibre Channel cards.
862 * It turns out that even for QLogic 2100s with ROM 1.10 and above
863 * we do get a firmware attributes word returned in mailbox register 6.
865 * Because the lun is in a different position in the Request Queue
866 * Entry structure for Fibre Channel with expanded lun firmware, we
867 * can only support one lun (lun zero) when we don't know what kind
868 * of firmware we're running.
872 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
873 isp->isp_maxluns = 32;
875 isp->isp_maxluns = 8;
878 isp->isp_maxluns = 8;
881 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
882 isp->isp_maxluns = 16384;
884 isp->isp_maxluns = 16;
890 * Initialize Parameters of Hardware to a known state.
892 * Locks are held before coming here.
896 isp_init(ispsoftc_t *isp)
899 * Must do this first to get defaults established.
901 isp_setdfltparm(isp, 0);
902 if (IS_DUALBUS(isp)) {
903 isp_setdfltparm(isp, 1);
913 isp_scsi_init(ispsoftc_t *isp)
915 sdparam *sdp_chan0, *sdp_chan1;
918 sdp_chan0 = isp->isp_param;
919 sdp_chan1 = sdp_chan0;
920 if (IS_DUALBUS(isp)) {
925 * If we have no role (neither target nor initiator), return.
927 if (isp->isp_role == ISP_ROLE_NONE) {
931 /* First do overall per-card settings. */
934 * If we have fast memory timing enabled, turn it on.
936 if (sdp_chan0->isp_fast_mttr) {
937 ISP_WRITE(isp, RISC_MTR, 0x1313);
941 * Set Retry Delay and Count.
942 * You set both channels at the same time.
944 MEMZERO(&mbs, sizeof (mbs));
945 mbs.param[0] = MBOX_SET_RETRY_COUNT;
946 mbs.param[1] = sdp_chan0->isp_retry_count;
947 mbs.param[2] = sdp_chan0->isp_retry_delay;
948 mbs.param[6] = sdp_chan1->isp_retry_count;
949 mbs.param[7] = sdp_chan1->isp_retry_delay;
951 isp_mboxcmd(isp, &mbs, MBLOGALL);
952 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
957 * Set ASYNC DATA SETUP time. This is very important.
959 MEMZERO(&mbs, sizeof (mbs));
960 mbs.param[0] = MBOX_SET_ASYNC_DATA_SETUP_TIME;
961 mbs.param[1] = sdp_chan0->isp_async_data_setup;
962 mbs.param[2] = sdp_chan1->isp_async_data_setup;
963 isp_mboxcmd(isp, &mbs, MBLOGALL);
964 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
969 * Set ACTIVE Negation State.
971 MEMZERO(&mbs, sizeof (mbs));
972 mbs.param[0] = MBOX_SET_ACT_NEG_STATE;
974 (sdp_chan0->isp_req_ack_active_neg << 4) |
975 (sdp_chan0->isp_data_line_active_neg << 5);
977 (sdp_chan1->isp_req_ack_active_neg << 4) |
978 (sdp_chan1->isp_data_line_active_neg << 5);
980 MEMZERO(&mbs, sizeof (mbs));
981 isp_mboxcmd(isp, &mbs, MBLOGNONE);
982 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
983 isp_prt(isp, ISP_LOGERR,
984 "failed to set active negation state (%d,%d), (%d,%d)",
985 sdp_chan0->isp_req_ack_active_neg,
986 sdp_chan0->isp_data_line_active_neg,
987 sdp_chan1->isp_req_ack_active_neg,
988 sdp_chan1->isp_data_line_active_neg);
995 * Set the Tag Aging limit
997 MEMZERO(&mbs, sizeof (mbs));
998 mbs.param[0] = MBOX_SET_TAG_AGE_LIMIT;
999 mbs.param[1] = sdp_chan0->isp_tag_aging;
1000 mbs.param[2] = sdp_chan1->isp_tag_aging;
1001 isp_mboxcmd(isp, &mbs, MBLOGALL);
1002 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1003 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
1004 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
1009 * Set selection timeout.
1011 MEMZERO(&mbs, sizeof (mbs));
1012 mbs.param[0] = MBOX_SET_SELECT_TIMEOUT;
1013 mbs.param[1] = sdp_chan0->isp_selection_timeout;
1014 mbs.param[2] = sdp_chan1->isp_selection_timeout;
1015 isp_mboxcmd(isp, &mbs, MBLOGALL);
1016 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1020 /* now do per-channel settings */
1021 isp_scsi_channel_init(isp, 0);
1022 if (IS_DUALBUS(isp))
1023 isp_scsi_channel_init(isp, 1);
1026 * Now enable request/response queues
1029 if (IS_ULTRA2(isp) || IS_1240(isp)) {
1030 MEMZERO(&mbs, sizeof (mbs));
1031 mbs.param[0] = MBOX_INIT_RES_QUEUE_A64;
1032 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1033 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1034 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1036 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1037 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1038 isp_mboxcmd(isp, &mbs, MBLOGALL);
1039 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1042 isp->isp_residx = mbs.param[5];
1044 MEMZERO(&mbs, sizeof (mbs));
1045 mbs.param[0] = MBOX_INIT_REQ_QUEUE_A64;
1046 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1047 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1048 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1050 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1051 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1052 isp_mboxcmd(isp, &mbs, MBLOGALL);
1053 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1056 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1058 MEMZERO(&mbs, sizeof (mbs));
1059 mbs.param[0] = MBOX_INIT_RES_QUEUE;
1060 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1061 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1062 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1064 isp_mboxcmd(isp, &mbs, MBLOGALL);
1065 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1068 isp->isp_residx = mbs.param[5];
1070 MEMZERO(&mbs, sizeof (mbs));
1071 mbs.param[0] = MBOX_INIT_REQ_QUEUE;
1072 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1073 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1074 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1076 isp_mboxcmd(isp, &mbs, MBLOGALL);
1077 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1080 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1084 * Turn on Fast Posting, LVD transitions
1086 * Ultra2 F/W always has had fast posting (and LVD transitions)
1088 * Ultra and older (i.e., SBus) cards may not. It's just safer
1089 * to assume not for them.
1092 MEMZERO(&mbs, sizeof (mbs));
1093 mbs.param[0] = MBOX_SET_FW_FEATURES;
1096 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1098 if (IS_ULTRA2(isp) || IS_1240(isp))
1099 mbs.param[1] |= FW_FEATURE_RIO_16BIT;
1101 if (IS_ULTRA2(isp) || IS_1240(isp))
1102 mbs.param[1] |= FW_FEATURE_FAST_POST;
1104 if (mbs.param[1] != 0) {
1105 uint16_t sfeat = mbs.param[1];
1106 isp_mboxcmd(isp, &mbs, MBLOGALL);
1107 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1108 isp_prt(isp, ISP_LOGINFO,
1109 "Enabled FW features (0x%x)", sfeat);
1114 * Let the outer layers decide whether to issue a SCSI bus reset.
1116 isp->isp_state = ISP_INITSTATE;
1120 isp_scsi_channel_init(ispsoftc_t *isp, int channel)
1126 sdp = isp->isp_param;
1130 * Set (possibly new) Initiator ID.
1132 MEMZERO(&mbs, sizeof (mbs));
1133 mbs.param[0] = MBOX_SET_INIT_SCSI_ID;
1134 mbs.param[1] = (channel << 7) | sdp->isp_initiator_id;
1135 isp_mboxcmd(isp, &mbs, MBLOGALL);
1136 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1139 isp_prt(isp, ISP_LOGINFO, "Initiator ID is %d on Channel %d",
1140 sdp->isp_initiator_id, channel);
1144 * Set current per-target parameters to an initial safe minimum.
1146 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1150 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1153 #ifndef ISP_TARGET_MODE
1154 sdf = sdp->isp_devparam[tgt].goal_flags;
1155 sdf &= DPARM_SAFE_DFLT;
1157 * It is not quite clear when this changed over so that
1158 * we could force narrow and async for 1000/1020 cards,
1159 * but assume that this is only the case for loaded
1162 if (isp->isp_loaded_fw) {
1163 sdf |= DPARM_NARROW | DPARM_ASYNC;
1167 * The !$*!)$!$)* f/w uses the same index into some
1168 * internal table to decide how to respond to negotiations,
1169 * so if we've said "let's be safe" for ID X, and ID X
1170 * selects *us*, the negotiations will back to 'safe'
1171 * (as in narrow/async). What the f/w *should* do is
1172 * use the initiator id settings to decide how to respond.
1174 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1176 MEMZERO(&mbs, sizeof (mbs));
1177 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1178 mbs.param[1] = (channel << 15) | (tgt << 8);
1180 if ((sdf & DPARM_SYNC) == 0) {
1184 (sdp->isp_devparam[tgt].goal_offset << 8) |
1185 (sdp->isp_devparam[tgt].goal_period);
1187 isp_prt(isp, ISP_LOGDEBUG0,
1188 "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1189 channel, tgt, mbs.param[2], mbs.param[3] >> 8,
1190 mbs.param[3] & 0xff);
1191 isp_mboxcmd(isp, &mbs, MBLOGNONE);
1192 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1193 sdf = DPARM_SAFE_DFLT;
1194 MEMZERO(&mbs, sizeof (mbs));
1195 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1196 mbs.param[1] = (tgt << 8) | (channel << 15);
1199 isp_mboxcmd(isp, &mbs, MBLOGALL);
1200 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1206 * We don't update any information directly from the f/w
1207 * because we need to run at least one command to cause a
1208 * new state to be latched up. So, we just assume that we
1209 * converge to the values we just had set.
1211 * Ensure that we don't believe tagged queuing is enabled yet.
1212 * It turns out that sometimes the ISP just ignores our
1213 * attempts to set parameters for devices that it hasn't
1216 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1217 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1218 MEMZERO(&mbs, sizeof (mbs));
1219 mbs.param[0] = MBOX_SET_DEV_QUEUE_PARAMS;
1220 mbs.param[1] = (channel << 15) | (tgt << 8) | lun;
1221 mbs.param[2] = sdp->isp_max_queue_depth;
1222 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1223 isp_mboxcmd(isp, &mbs, MBLOGALL);
1224 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1229 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1230 if (sdp->isp_devparam[tgt].dev_refresh) {
1231 isp->isp_sendmarker |= (1 << channel);
1232 isp->isp_update |= (1 << channel);
1239 * Fibre Channel specific initialization.
1241 * Locks are held before coming here.
1244 isp_fibre_init(ispsoftc_t *isp)
1247 isp_icb_t local, *icbp = &local;
1250 uint64_t nwwn, pwwn;
1252 fcp = isp->isp_param;
1255 * Do this *before* initializing the firmware.
1257 isp_mark_getpdb_all(isp);
1258 fcp->isp_fwstate = FW_CONFIG_WAIT;
1259 fcp->isp_loopstate = LOOP_NIL;
1262 * If we have no role (neither target nor initiator), return.
1264 if (isp->isp_role == ISP_ROLE_NONE) {
1268 loopid = fcp->isp_loopid;
1269 MEMZERO(icbp, sizeof (*icbp));
1270 icbp->icb_version = ICB_VERSION1;
1273 * Firmware Options are either retrieved from NVRAM or
1274 * are patched elsewhere. We check them for sanity here
1275 * and make changes based on board revision, but otherwise
1276 * let others decide policy.
1280 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1282 if ((isp->isp_type == ISP_HA_FC_2100) && isp->isp_revision < 5) {
1283 fcp->isp_fwoptions &= ~ICBOPT_FAIRNESS;
1287 * We have to use FULL LOGIN even though it resets the loop too much
1288 * because otherwise port database entries don't get updated after
1289 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1291 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1292 fcp->isp_fwoptions |= ICBOPT_FULL_LOGIN;
1296 * Insist on Port Database Update Async notifications
1298 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
1301 * Make sure that target role reflects into fwoptions.
1303 if (isp->isp_role & ISP_ROLE_TARGET) {
1304 fcp->isp_fwoptions |= ICBOPT_TGT_ENABLE;
1306 fcp->isp_fwoptions &= ~ICBOPT_TGT_ENABLE;
1309 if (isp->isp_role & ISP_ROLE_INITIATOR) {
1310 fcp->isp_fwoptions &= ~ICBOPT_INI_DISABLE;
1312 fcp->isp_fwoptions |= ICBOPT_INI_DISABLE;
1316 * Propagate all of this into the ICB structure.
1318 icbp->icb_fwoptions = fcp->isp_fwoptions;
1319 icbp->icb_maxfrmlen = fcp->isp_maxfrmlen;
1320 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN ||
1321 icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1322 isp_prt(isp, ISP_LOGERR,
1323 "bad frame length (%d) from NVRAM- using %d",
1324 fcp->isp_maxfrmlen, ICB_DFLT_FRMLEN);
1325 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1327 icbp->icb_maxalloc = fcp->isp_maxalloc;
1328 if (icbp->icb_maxalloc < 1) {
1329 isp_prt(isp, ISP_LOGERR,
1330 "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1331 icbp->icb_maxalloc = 16;
1333 icbp->icb_execthrottle = fcp->isp_execthrottle;
1334 if (icbp->icb_execthrottle < 1) {
1335 isp_prt(isp, ISP_LOGERR,
1336 "bad execution throttle of %d- using 16",
1337 fcp->isp_execthrottle);
1338 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1340 icbp->icb_retry_delay = fcp->isp_retry_delay;
1341 icbp->icb_retry_count = fcp->isp_retry_count;
1342 icbp->icb_hardaddr = loopid;
1343 if (icbp->icb_hardaddr > 125) {
1345 * We end up with these Loop IDs for F-Port topologies
1347 if (icbp->icb_hardaddr != 0xff && icbp->icb_hardaddr != 0x800) {
1348 isp_prt(isp, ISP_LOGERR,
1349 "bad hard address %u- resetting to zero",
1350 icbp->icb_hardaddr);
1352 icbp->icb_hardaddr = 0;
1356 * Our life seems so much better with 2200s and later with
1357 * the latest f/w if we set Hard Address.
1359 if (ISP_FW_NEWER_THAN(isp, 2, 2, 5)) {
1360 icbp->icb_fwoptions |= ICBOPT_HARD_ADDRESS;
1364 * Right now we just set extended options to prefer point-to-point
1365 * over loop based upon some soft config options.
1367 * NB: for the 2300, ICBOPT_EXTENDED is required.
1369 if (IS_2200(isp) || IS_23XX(isp)) {
1370 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1372 * Prefer or force Point-To-Point instead Loop?
1374 switch(isp->isp_confopts & ISP_CFG_PORT_PREF) {
1376 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1378 case ISP_CFG_NPORT_ONLY:
1379 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1381 case ISP_CFG_LPORT_ONLY:
1382 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1385 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1389 if (ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1390 icbp->icb_xfwoptions |= ICBXOPT_RIO_16BIT;
1391 icbp->icb_racctimer = 4;
1392 icbp->icb_idelaytimer = 8;
1394 icbp->icb_fwoptions |= ICBOPT_FAST_POST;
1397 * QLogic recommends that FAST Posting be turned
1398 * off for 23XX cards and instead allow the HBA
1399 * to write response queue entries and interrupt
1400 * after a delay (ZIO).
1402 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1403 if ((fcp->isp_xfwoptions & ICBXOPT_TIMER_MASK) ==
1405 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1406 icbp->icb_idelaytimer = 10;
1408 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1409 icbp->icb_zfwoptions |= ICBZOPT_RATE_ONEGB;
1410 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1411 icbp->icb_zfwoptions |= ICBZOPT_RATE_TWOGB;
1413 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1415 if (fcp->isp_zfwoptions & ICBZOPT_50_OHM) {
1416 icbp->icb_zfwoptions |= ICBZOPT_50_OHM;
1423 * For 22XX > 2.1.26 && 23XX, set some options.
1424 * XXX: Probably okay for newer 2100 f/w too.
1426 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1428 * Turn on LIP F8 async event (1)
1429 * Turn on generate AE 8013 on all LIP Resets (2)
1430 * Disable LIP F7 switching (8)
1432 MEMZERO(&mbs, sizeof (mbs));
1433 mbs.param[0] = MBOX_SET_FIRMWARE_OPTIONS;
1437 isp_mboxcmd(isp, &mbs, MBLOGALL);
1439 icbp->icb_logintime = ICB_LOGIN_TOV;
1440 icbp->icb_lunetimeout = ICB_LUN_ENABLE_TOV;
1442 nwwn = ISP_NODEWWN(isp);
1443 pwwn = ISP_PORTWWN(isp);
1445 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1446 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, nwwn);
1447 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, pwwn);
1448 isp_prt(isp, ISP_LOGDEBUG1,
1449 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1450 ((uint32_t) (nwwn >> 32)),
1451 ((uint32_t) (nwwn & 0xffffffff)),
1452 ((uint32_t) (pwwn >> 32)),
1453 ((uint32_t) (pwwn & 0xffffffff)));
1455 isp_prt(isp, ISP_LOGDEBUG1, "Not using any WWNs");
1456 icbp->icb_fwoptions &= ~(ICBOPT_BOTH_WWNS|ICBOPT_FULL_LOGIN);
1458 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1459 if (icbp->icb_rqstqlen < 1) {
1460 isp_prt(isp, ISP_LOGERR, "bad request queue length");
1462 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1463 if (icbp->icb_rsltqlen < 1) {
1464 isp_prt(isp, ISP_LOGERR, "bad result queue length");
1466 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1467 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1468 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1469 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1470 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1471 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1472 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1473 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1475 isp_prt(isp, ISP_LOGDEBUG0,
1476 "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1477 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1479 FC_SCRATCH_ACQUIRE(isp);
1480 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1485 MEMZERO(&mbs, sizeof (mbs));
1486 mbs.param[0] = MBOX_INIT_FIRMWARE;
1487 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1488 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1489 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1490 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1491 isp_prt(isp, ISP_LOGDEBUG0, "INIT F/W from %p (%08x%08x)",
1492 fcp->isp_scratch, (uint32_t) ((uint64_t)fcp->isp_scdma >> 32),
1493 (uint32_t) fcp->isp_scdma);
1494 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp));
1495 isp_mboxcmd(isp, &mbs, MBLOGALL);
1496 FC_SCRATCH_RELEASE(isp);
1497 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1500 isp->isp_reqidx = isp->isp_reqodx = 0;
1501 isp->isp_residx = 0;
1502 isp->isp_sendmarker = 1;
1505 * Whatever happens, we're now committed to being here.
1507 isp->isp_state = ISP_INITSTATE;
1511 * Fibre Channel Support- get the port database for the id.
1513 * Locks are held before coming here. Return 0 if success,
1518 isp_getmap(ispsoftc_t *isp, fcpos_map_t *map)
1520 fcparam *fcp = (fcparam *) isp->isp_param;
1523 MEMZERO(&mbs, sizeof (mbs));
1524 mbs.param[0] = MBOX_GET_FC_AL_POSITION_MAP;
1525 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1526 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1527 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1528 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1529 FC_SCRATCH_ACQUIRE(isp);
1530 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (fcpos_map_t));
1531 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1532 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1533 MEMCPY(map, fcp->isp_scratch, sizeof (fcpos_map_t));
1534 map->fwmap = mbs.param[1] != 0;
1535 FC_SCRATCH_RELEASE(isp);
1538 FC_SCRATCH_RELEASE(isp);
1543 isp_mark_getpdb_all(ispsoftc_t *isp)
1545 fcparam *fcp = (fcparam *) isp->isp_param;
1547 for (i = 0; i < MAX_FC_TARG; i++) {
1548 fcp->portdb[i].valid = fcp->portdb[i].fabric_dev = 0;
1553 isp_getpdb(ispsoftc_t *isp, int id, isp_pdb_t *pdbp)
1555 fcparam *fcp = (fcparam *) isp->isp_param;
1558 MEMZERO(&mbs, sizeof (mbs));
1559 mbs.param[0] = MBOX_GET_PORT_DB;
1560 if (IS_2KLOGIN(isp)) {
1562 mbs.ibits |= (1 << 10);
1564 mbs.param[1] = id << 8;
1566 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1567 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1568 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1569 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1570 FC_SCRATCH_ACQUIRE(isp);
1571 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (isp_pdb_t));
1572 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1573 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1574 isp_get_pdb(isp, (isp_pdb_t *)fcp->isp_scratch, pdbp);
1575 FC_SCRATCH_RELEASE(isp);
1578 FC_SCRATCH_RELEASE(isp);
1583 isp_get_portname(ispsoftc_t *isp, int loopid, int nodename)
1588 MEMZERO(&mbs, sizeof (mbs));
1589 mbs.param[0] = MBOX_GET_PORT_NAME;
1590 if (IS_2KLOGIN(isp)) {
1591 mbs.param[1] = loopid;
1592 mbs.ibits |= (1 << 10);
1597 mbs.param[1] = loopid << 8;
1602 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR);
1603 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1605 (((uint64_t)(mbs.param[2] & 0xff)) << 56) |
1606 (((uint64_t)(mbs.param[2] >> 8)) << 48) |
1607 (((uint64_t)(mbs.param[3] & 0xff)) << 40) |
1608 (((uint64_t)(mbs.param[3] >> 8)) << 32) |
1609 (((uint64_t)(mbs.param[6] & 0xff)) << 24) |
1610 (((uint64_t)(mbs.param[6] >> 8)) << 16) |
1611 (((uint64_t)(mbs.param[7] & 0xff)) << 8) |
1612 (((uint64_t)(mbs.param[7] >> 8)));
1618 * Make sure we have good FC link and know our Loop ID.
1622 isp_fclink_test(ispsoftc_t *isp, int usdelay)
1624 static char *toponames[] = {
1629 "F Port (no FLOGI_ACC response)"
1632 int count, check_for_fabric;
1638 fcp = isp->isp_param;
1640 isp_prt(isp, ISP_LOGDEBUG0, "FC Link Test Entry");
1643 * XXX: Here is where we would start a 'loop dead' timeout
1647 * Wait up to N microseconds for F/W to go to a ready state.
1649 lwfs = FW_CONFIG_WAIT;
1651 while (count < usdelay) {
1654 NANOTIME_T hra, hrb;
1658 if (lwfs != fcp->isp_fwstate) {
1659 isp_prt(isp, ISP_LOGINFO, "Firmware State <%s->%s>",
1660 isp2100_fw_statename((int)lwfs),
1661 isp2100_fw_statename((int)fcp->isp_fwstate));
1662 lwfs = fcp->isp_fwstate;
1664 if (fcp->isp_fwstate == FW_READY) {
1670 * Get the elapsed time in nanoseconds.
1671 * Always guaranteed to be non-zero.
1673 enano = NANOTIME_SUB(&hrb, &hra);
1675 isp_prt(isp, ISP_LOGDEBUG1,
1676 "usec%d: 0x%lx->0x%lx enano 0x%x%08x",
1677 count, (long) GET_NANOSEC(&hra), (long) GET_NANOSEC(&hrb),
1678 (uint32_t)(enano >> 32), (uint32_t)(enano & 0xffffffff));
1681 * If the elapsed time is less than 1 millisecond,
1682 * delay a period of time up to that millisecond of
1685 * This peculiar code is an attempt to try and avoid
1686 * invoking uint64_t math support functions for some
1687 * platforms where linkage is a problem.
1689 if (enano < (1000 * 1000)) {
1691 enano = (1000 * 1000) - enano;
1692 while (enano > (uint64_t) 4000000000U) {
1693 USEC_SLEEP(isp, 4000000);
1694 enano -= (uint64_t) 4000000000U;
1698 USEC_SLEEP(isp, wrk);
1700 while (enano > (uint64_t) 4000000000U) {
1702 enano -= (uint64_t) 4000000000U;
1705 count += (wrk / 1000);
1710 * If we haven't gone to 'ready' state, return.
1712 if (fcp->isp_fwstate != FW_READY) {
1717 * Get our Loop ID (if possible). We really need to have it.
1719 MEMZERO(&mbs, sizeof (mbs));
1720 mbs.param[0] = MBOX_GET_LOOP_ID;
1721 isp_mboxcmd(isp, &mbs, MBLOGALL);
1722 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1725 if (IS_2KLOGIN(isp)) {
1726 fcp->isp_loopid = mbs.param[1];
1728 fcp->isp_loopid = mbs.param[1] & 0xff;
1730 if (fcp->isp_loopid == 0xffff) { /* happens with 2k login f/w */
1731 fcp->isp_loopid = MAX_FC_TARG-1;
1732 } else if (fcp->isp_loopid >= MAX_FC_TARG) {
1733 isp_prt(isp, ISP_LOGWARN, "bad initiator loopid (0x%x)", fcp->isp_loopid);
1734 fcp->isp_loopid = MAX_FC_TARG-1;
1736 if (IS_2200(isp) || IS_23XX(isp)) {
1737 int topo = (int) mbs.param[6];
1738 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB)
1739 topo = TOPO_PTP_STUB;
1740 fcp->isp_topo = topo;
1742 fcp->isp_topo = TOPO_NL_PORT;
1747 fcp->isp_portid = mbs.param[2] | (mbs.param[3] << 16);
1750 * Check to see if we're on a fabric by trying to see if we
1751 * can talk to the fabric name server. This can be a bit
1752 * tricky because if we're a 2100, we should check always
1753 * (in case we're connected to a server doing aliasing).
1755 fcp->isp_onfabric = 0;
1759 * Don't bother with fabric if we are using really old
1760 * 2100 firmware. It's just not worth it.
1762 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37)) {
1763 check_for_fabric = 1;
1765 check_for_fabric = 0;
1767 } else if (fcp->isp_topo == TOPO_FL_PORT ||
1768 fcp->isp_topo == TOPO_F_PORT) {
1769 check_for_fabric = 1;
1771 check_for_fabric = 0;
1773 if (check_for_fabric && isp_getpdb(isp, FL_PORT_ID, &pdb) == 0) {
1774 int loopid = FL_PORT_ID;
1776 fcp->isp_topo = TOPO_FL_PORT;
1779 if (BITS2WORD(pdb.pdb_portid_bits) == 0) {
1783 fcp->isp_topo = TOPO_NL_PORT;
1786 fcp->isp_portid = mbs.param[2] | ((int) mbs.param[3] << 16);
1789 * Save the Fabric controller's port database entry.
1791 lp = &fcp->portdb[loopid];
1793 (((uint64_t)pdb.pdb_nodename[0]) << 56) |
1794 (((uint64_t)pdb.pdb_nodename[1]) << 48) |
1795 (((uint64_t)pdb.pdb_nodename[2]) << 40) |
1796 (((uint64_t)pdb.pdb_nodename[3]) << 32) |
1797 (((uint64_t)pdb.pdb_nodename[4]) << 24) |
1798 (((uint64_t)pdb.pdb_nodename[5]) << 16) |
1799 (((uint64_t)pdb.pdb_nodename[6]) << 8) |
1800 (((uint64_t)pdb.pdb_nodename[7]));
1802 (((uint64_t)pdb.pdb_portname[0]) << 56) |
1803 (((uint64_t)pdb.pdb_portname[1]) << 48) |
1804 (((uint64_t)pdb.pdb_portname[2]) << 40) |
1805 (((uint64_t)pdb.pdb_portname[3]) << 32) |
1806 (((uint64_t)pdb.pdb_portname[4]) << 24) |
1807 (((uint64_t)pdb.pdb_portname[5]) << 16) |
1808 (((uint64_t)pdb.pdb_portname[6]) << 8) |
1809 (((uint64_t)pdb.pdb_portname[7]));
1811 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
1812 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
1813 lp->loopid = pdb.pdb_loopid;
1814 lp->loggedin = lp->valid = 1;
1815 fcp->isp_onfabric = 1;
1816 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1817 isp_register_fc4_type(isp);
1820 fcp->isp_onfabric = 0;
1821 fcp->portdb[FL_PORT_ID].valid = 0;
1824 fcp->isp_gbspeed = 1;
1826 MEMZERO(&mbs, sizeof (mbs));
1827 mbs.param[0] = MBOX_GET_SET_DATA_RATE;
1828 mbs.param[1] = MBGSD_GET_RATE;
1829 /* mbs.param[2] undefined if we're just getting rate */
1830 isp_mboxcmd(isp, &mbs, MBLOGALL);
1831 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1832 if (mbs.param[1] == MBGSD_TWOGB) {
1833 isp_prt(isp, ISP_LOGINFO, "2Gb link speed/s");
1834 fcp->isp_gbspeed = 2;
1839 isp_prt(isp, ISP_LOGCONFIG, topology, fcp->isp_loopid,
1840 fcp->isp_portid, fcp->isp_loopstate, toponames[fcp->isp_topo]);
1843 * Announce ourselves, too. This involves synthesizing an entry.
1845 if (fcp->isp_iid_set == 0) {
1846 fcp->isp_iid_set = 1;
1847 fcp->isp_iid = fcp->isp_loopid;
1848 lp = &fcp->portdb[fcp->isp_iid];
1850 lp = &fcp->portdb[fcp->isp_iid];
1851 if (fcp->isp_portid != lp->portid ||
1852 fcp->isp_loopid != lp->loopid ||
1853 fcp->isp_nodewwn != ISP_NODEWWN(isp) ||
1854 fcp->isp_portwwn != ISP_PORTWWN(isp)) {
1856 count = fcp->isp_iid;
1857 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1860 lp->loopid = fcp->isp_loopid;
1861 lp->portid = fcp->isp_portid;
1862 lp->node_wwn = ISP_NODEWWN(isp);
1863 lp->port_wwn = ISP_PORTWWN(isp);
1864 switch (isp->isp_role) {
1868 case ISP_ROLE_TARGET:
1869 lp->roles = SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT;
1871 case ISP_ROLE_INITIATOR:
1872 lp->roles = SVC3_INI_ROLE >> SVC3_ROLE_SHIFT;
1875 lp->roles = (SVC3_INI_ROLE|SVC3_TGT_ROLE) >> SVC3_ROLE_SHIFT;
1878 lp->loggedin = lp->valid = 1;
1879 count = fcp->isp_iid;
1880 (void) isp_async(isp, ISPASYNC_PROMENADE, &count);
1881 isp_prt(isp, ISP_LOGDEBUG0, "FC Link Test Complete");
1886 isp2100_fw_statename(int state)
1889 case FW_CONFIG_WAIT: return "Config Wait";
1890 case FW_WAIT_AL_PA: return "Waiting for AL_PA";
1891 case FW_WAIT_LOGIN: return "Wait Login";
1892 case FW_READY: return "Ready";
1893 case FW_LOSS_OF_SYNC: return "Loss Of Sync";
1894 case FW_ERROR: return "Error";
1895 case FW_REINIT: return "Re-Init";
1896 case FW_NON_PART: return "Nonparticipating";
1897 default: return "?????";
1902 * Synchronize our soft copy of the port database with what the f/w thinks
1903 * (with a view toward possibly for a specific target....)
1907 isp_pdb_sync(ispsoftc_t *isp)
1910 fcparam *fcp = isp->isp_param;
1912 int loopid, base, lim;
1915 * Make sure we're okay for doing this right now.
1917 if (fcp->isp_loopstate != LOOP_PDB_RCVD &&
1918 fcp->isp_loopstate != LOOP_FSCAN_DONE &&
1919 fcp->isp_loopstate != LOOP_LSCAN_DONE) {
1923 if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_NL_PORT ||
1924 fcp->isp_topo == TOPO_N_PORT) {
1925 if (fcp->isp_loopstate < LOOP_LSCAN_DONE) {
1926 if (isp_scan_loop(isp) != 0) {
1931 fcp->isp_loopstate = LOOP_SYNCING_PDB;
1934 * If we get this far, we've settled our differences with the f/w
1935 * (for local loop device) and we can say that the loop state is ready.
1938 if (fcp->isp_topo == TOPO_NL_PORT) {
1939 fcp->loop_seen_once = 1;
1940 fcp->isp_loopstate = LOOP_READY;
1945 * Find all Fabric Entities that didn't make it from one scan to the
1946 * next and let the world know they went away. Scan the whole database.
1948 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[MAX_FC_TARG]; lp++) {
1949 if (lp->was_fabric_dev && lp->fabric_dev == 0) {
1950 loopid = lp - fcp->portdb;
1951 lp->valid = 0; /* should already be set */
1952 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
1953 MEMZERO((void *) lp, sizeof (*lp));
1956 lp->was_fabric_dev = lp->fabric_dev;
1959 if (fcp->isp_topo == TOPO_FL_PORT)
1964 if (fcp->isp_topo == TOPO_N_PORT)
1970 * Now log in any fabric devices that the outer layer has
1971 * left for us to see. This seems the most sane policy
1974 for (lp = &fcp->portdb[base]; lp < &fcp->portdb[lim]; lp++) {
1978 loopid = lp - fcp->portdb;
1979 if (loopid >= FL_PORT_ID && loopid <= FC_SNS_ID) {
1986 if (lp->port_wwn == 0) {
1991 * Don't try to log into yourself.
1993 if ((portid = lp->portid) == fcp->isp_portid) {
1999 * If we'd been logged in- see if we still are and we haven't
2000 * changed. If so, no need to log ourselves out, etc..
2002 * Unfortunately, our charming Qlogic f/w has decided to
2003 * return a valid port database entry for a fabric device
2004 * that has, in fact, gone away. And it hangs trying to
2007 if (lp->loggedin && lp->force_logout == 0 &&
2008 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
2010 uint64_t nwwnn, nwwpn;
2012 (((uint64_t)pdb.pdb_nodename[0]) << 56) |
2013 (((uint64_t)pdb.pdb_nodename[1]) << 48) |
2014 (((uint64_t)pdb.pdb_nodename[2]) << 40) |
2015 (((uint64_t)pdb.pdb_nodename[3]) << 32) |
2016 (((uint64_t)pdb.pdb_nodename[4]) << 24) |
2017 (((uint64_t)pdb.pdb_nodename[5]) << 16) |
2018 (((uint64_t)pdb.pdb_nodename[6]) << 8) |
2019 (((uint64_t)pdb.pdb_nodename[7]));
2021 (((uint64_t)pdb.pdb_portname[0]) << 56) |
2022 (((uint64_t)pdb.pdb_portname[1]) << 48) |
2023 (((uint64_t)pdb.pdb_portname[2]) << 40) |
2024 (((uint64_t)pdb.pdb_portname[3]) << 32) |
2025 (((uint64_t)pdb.pdb_portname[4]) << 24) |
2026 (((uint64_t)pdb.pdb_portname[5]) << 16) |
2027 (((uint64_t)pdb.pdb_portname[6]) << 8) |
2028 (((uint64_t)pdb.pdb_portname[7]));
2029 nrole = (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >>
2031 if (pdb.pdb_loopid == lp->loopid && lp->portid ==
2032 (uint32_t) BITS2WORD(pdb.pdb_portid_bits) &&
2033 nwwnn == lp->node_wwn && nwwpn == lp->port_wwn &&
2034 lp->roles == nrole && lp->force_logout == 0) {
2035 lp->loggedin = lp->valid = 1;
2036 isp_prt(isp, ISP_LOGCONFIG, lretained,
2037 (int) (lp - fcp->portdb),
2038 (int) lp->loopid, lp->portid);
2043 if (fcp->isp_fwstate != FW_READY ||
2044 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2049 * Force a logout if we were logged in.
2052 if (lp->force_logout ||
2053 isp_getpdb(isp, lp->loopid, &pdb) == 0) {
2054 MEMZERO(&mbs, sizeof (mbs));
2055 mbs.param[0] = MBOX_FABRIC_LOGOUT;
2056 if (IS_2KLOGIN(isp)) {
2057 mbs.param[1] = lp->loopid;
2058 mbs.ibits |= (1 << 10);
2060 mbs.param[1] = lp->loopid << 8;
2062 isp_mboxcmd(isp, &mbs, MBLOGNONE);
2063 isp_prt(isp, ISP_LOGINFO, plogout,
2064 (int) (lp - fcp->portdb), lp->loopid,
2067 lp->force_logout = lp->loggedin = 0;
2068 if (fcp->isp_fwstate != FW_READY ||
2069 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2077 loopid = lp - fcp->portdb;
2078 lp->loopid = FL_PORT_ID;
2080 MEMZERO(&mbs, sizeof (mbs));
2081 mbs.param[0] = MBOX_FABRIC_LOGIN;
2082 if (IS_2KLOGIN(isp)) {
2083 mbs.param[1] = loopid;
2084 mbs.ibits |= (1 << 10);
2086 mbs.param[1] = loopid << 8;
2088 mbs.param[2] = portid >> 16;
2089 mbs.param[3] = portid & 0xffff;
2090 isp_mboxcmd(isp, &mbs, MBLOGALL & ~(MBOX_LOOP_ID_USED |
2091 MBOX_PORT_ID_USED | MBOX_COMMAND_ERROR));
2092 if (fcp->isp_fwstate != FW_READY ||
2093 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2096 switch (mbs.param[0]) {
2097 case MBOX_LOOP_ID_USED:
2099 * Try the next available loop id.
2103 case MBOX_PORT_ID_USED:
2105 * This port is already logged in.
2106 * Snaffle the loop id it's using if it's
2107 * nonzero, otherwise we're hosed.
2109 if (mbs.param[1] != 0) {
2110 loopid = mbs.param[1];
2111 if (loopid >= MAX_FC_TARG) {
2112 loopid = MAX_FC_TARG;
2115 isp_prt(isp, ISP_LOGINFO, retained,
2116 loopid, (int) (lp - fcp->portdb),
2119 loopid = MAX_FC_TARG;
2123 case MBOX_COMMAND_COMPLETE:
2125 lp->loopid = loopid;
2127 case MBOX_COMMAND_ERROR:
2128 isp_prt(isp, ISP_LOGINFO, plogierr,
2129 portid, mbs.param[1]);
2131 case MBOX_ALL_IDS_USED: /* We're outta IDs */
2133 loopid = MAX_FC_TARG;
2136 } while (lp->loopid == FL_PORT_ID && loopid < MAX_FC_TARG);
2139 * If we get here and we haven't set a Loop ID,
2140 * we failed to log into this device.
2143 if (lp->loopid == FL_PORT_ID) {
2149 * Make sure we can get the approriate port information.
2151 if (isp_getpdb(isp, lp->loopid, &pdb) != 0) {
2152 isp_prt(isp, ISP_LOGWARN, nopdb, lp->portid);
2156 if (fcp->isp_fwstate != FW_READY ||
2157 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2161 if (pdb.pdb_loopid != lp->loopid) {
2162 isp_prt(isp, ISP_LOGWARN, pdbmfail1,
2163 lp->portid, pdb.pdb_loopid);
2167 if (lp->portid != (uint32_t) BITS2WORD(pdb.pdb_portid_bits)) {
2168 isp_prt(isp, ISP_LOGWARN, pdbmfail2,
2169 lp->portid, BITS2WORD(pdb.pdb_portid_bits));
2174 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2176 (((uint64_t)pdb.pdb_nodename[0]) << 56) |
2177 (((uint64_t)pdb.pdb_nodename[1]) << 48) |
2178 (((uint64_t)pdb.pdb_nodename[2]) << 40) |
2179 (((uint64_t)pdb.pdb_nodename[3]) << 32) |
2180 (((uint64_t)pdb.pdb_nodename[4]) << 24) |
2181 (((uint64_t)pdb.pdb_nodename[5]) << 16) |
2182 (((uint64_t)pdb.pdb_nodename[6]) << 8) |
2183 (((uint64_t)pdb.pdb_nodename[7]));
2185 (((uint64_t)pdb.pdb_portname[0]) << 56) |
2186 (((uint64_t)pdb.pdb_portname[1]) << 48) |
2187 (((uint64_t)pdb.pdb_portname[2]) << 40) |
2188 (((uint64_t)pdb.pdb_portname[3]) << 32) |
2189 (((uint64_t)pdb.pdb_portname[4]) << 24) |
2190 (((uint64_t)pdb.pdb_portname[5]) << 16) |
2191 (((uint64_t)pdb.pdb_portname[6]) << 8) |
2192 (((uint64_t)pdb.pdb_portname[7]));
2194 * Check to make sure this all makes sense.
2196 if (lp->node_wwn && lp->port_wwn) {
2198 loopid = lp - fcp->portdb;
2199 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2204 isp_prt(isp, ISP_LOGINFO,
2205 ldumped, loopid, lp->loopid, lp->portid);
2206 MEMZERO(&mbs, sizeof (mbs));
2207 mbs.param[0] = MBOX_FABRIC_LOGOUT;
2208 if (IS_2KLOGIN(isp)) {
2209 mbs.param[1] = lp->loopid;
2210 mbs.ibits |= (1 << 10);
2212 mbs.param[1] = lp->loopid << 8;
2214 isp_mboxcmd(isp, &mbs, MBLOGNONE);
2215 if (fcp->isp_fwstate != FW_READY ||
2216 fcp->isp_loopstate != LOOP_SYNCING_PDB) {
2221 * If we get here, we've for sure seen not only a valid loop
2222 * but know what is or isn't on it, so mark this for usage
2225 fcp->loop_seen_once = 1;
2226 fcp->isp_loopstate = LOOP_READY;
2231 isp_scan_loop(ispsoftc_t *isp)
2234 fcparam *fcp = isp->isp_param;
2236 int loopid, lim, hival;
2238 switch (fcp->isp_topo) {
2249 isp_prt(isp, ISP_LOGDEBUG0, "no loop topology to scan");
2250 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2253 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
2255 isp_prt(isp, ISP_LOGDEBUG0, "scanning local loop 0..%d", hival);
2259 * make sure the temp port database is clean...
2261 MEMZERO((void *)fcp->tport, sizeof (fcp->tport));
2264 * Run through the local loop ports and get port database info
2267 * There's a somewhat unexplained situation where the f/w passes back
2268 * the wrong database entity- if that happens, just restart (up to
2269 * FL_PORT_ID times).
2271 for (lim = loopid = 0; loopid < hival; loopid++) {
2272 lp = &fcp->tport[loopid];
2275 * Don't even try for ourselves...
2277 if (loopid == fcp->isp_loopid) {
2281 if (IS_2100(isp) || IS_2200(isp)) {
2282 lp->node_wwn = isp_get_portname(isp, loopid, 1);
2283 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2286 if (lp->node_wwn == 0) {
2294 if (isp_getpdb(isp, loopid, &pdb) != 0) {
2295 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2301 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2306 * If the returned database element doesn't match what we
2307 * asked for, restart the process entirely (up to a point...).
2309 if (pdb.pdb_loopid != loopid) {
2311 if (lim++ < hival) {
2314 isp_prt(isp, ISP_LOGWARN,
2315 "giving up on synchronizing the port database");
2320 * Save the pertinent info locally.
2323 (((uint64_t)pdb.pdb_nodename[0]) << 56) |
2324 (((uint64_t)pdb.pdb_nodename[1]) << 48) |
2325 (((uint64_t)pdb.pdb_nodename[2]) << 40) |
2326 (((uint64_t)pdb.pdb_nodename[3]) << 32) |
2327 (((uint64_t)pdb.pdb_nodename[4]) << 24) |
2328 (((uint64_t)pdb.pdb_nodename[5]) << 16) |
2329 (((uint64_t)pdb.pdb_nodename[6]) << 8) |
2330 (((uint64_t)pdb.pdb_nodename[7]));
2332 (((uint64_t)pdb.pdb_portname[0]) << 56) |
2333 (((uint64_t)pdb.pdb_portname[1]) << 48) |
2334 (((uint64_t)pdb.pdb_portname[2]) << 40) |
2335 (((uint64_t)pdb.pdb_portname[3]) << 32) |
2336 (((uint64_t)pdb.pdb_portname[4]) << 24) |
2337 (((uint64_t)pdb.pdb_portname[5]) << 16) |
2338 (((uint64_t)pdb.pdb_portname[6]) << 8) |
2339 (((uint64_t)pdb.pdb_portname[7]));
2341 (pdb.pdb_prli_svc3 & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2342 lp->portid = BITS2WORD(pdb.pdb_portid_bits);
2343 lp->loopid = pdb.pdb_loopid;
2347 * Mark all of the permanent local loop database entries as invalid
2348 * (except our own entry).
2350 for (loopid = 0; loopid < hival; loopid++) {
2351 if (loopid == fcp->isp_iid) {
2352 fcp->portdb[loopid].valid = 1;
2353 fcp->portdb[loopid].loopid = fcp->isp_loopid;
2356 fcp->portdb[loopid].valid = 0;
2360 * Now merge our local copy of the port database into our saved copy.
2361 * Notify the outer layers of new devices arriving.
2363 for (loopid = 0; loopid < hival; loopid++) {
2367 * If we don't have a non-zero Port WWN, we're not here.
2369 if (fcp->tport[loopid].port_wwn == 0) {
2376 if (loopid == fcp->isp_iid) {
2381 * For the purposes of deciding whether this is the
2382 * 'same' device or not, we only search for an identical
2383 * Port WWN. Node WWNs may or may not be the same as
2384 * the Port WWN, and there may be multiple different
2385 * Port WWNs with the same Node WWN. It would be chaos
2386 * to have multiple identical Port WWNs, so we don't
2390 for (i = 0; i < hival; i++) {
2392 if (fcp->portdb[i].port_wwn == 0)
2394 if (fcp->portdb[i].port_wwn !=
2395 fcp->tport[loopid].port_wwn)
2398 * We found this WWN elsewhere- it's changed
2399 * loopids then. We don't change it's actual
2400 * position in our cached port database- we
2401 * just change the actual loop ID we'd use.
2403 if (fcp->portdb[i].loopid != loopid) {
2404 isp_prt(isp, ISP_LOGINFO, portshift, i,
2405 fcp->portdb[i].loopid,
2406 fcp->portdb[i].portid, loopid,
2407 fcp->tport[loopid].portid);
2409 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2410 fcp->portdb[i].loopid = loopid;
2411 fcp->portdb[i].valid = 1;
2412 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2415 * Now make sure this Port WWN doesn't exist elsewhere
2416 * in the port database.
2418 for (j = i+1; j < hival; j++) {
2419 if (fcp->portdb[i].port_wwn !=
2420 fcp->portdb[j].port_wwn) {
2423 isp_prt(isp, ISP_LOGWARN, portdup, j, i);
2425 * Invalidate the 'old' *and* 'new' ones.
2426 * This is really harsh and not quite right,
2427 * but if this happens, we really don't know
2428 * who is what at this point.
2430 fcp->portdb[i].valid = 0;
2431 fcp->portdb[j].valid = 0;
2437 * If we didn't traverse the entire port database,
2438 * then we found (and remapped) an existing entry.
2439 * No need to notify anyone- go for the next one.
2442 isp_prt(isp, ISP_LOGINFO, retained,
2443 fcp->portdb[i].loopid, i, fcp->portdb[i].portid);
2448 * We've not found this Port WWN anywhere. It's a new entry.
2449 * See if we can leave it where it is (with target == loopid).
2451 if (fcp->portdb[loopid].port_wwn != 0) {
2452 for (lim = 0; lim < hival; lim++) {
2453 if (fcp->portdb[lim].port_wwn == 0)
2456 /* "Cannot Happen" */
2458 isp_prt(isp, ISP_LOGWARN, "Remap Overflow");
2467 * NB: The actual loopid we use here is loopid- we may
2468 * in fact be at a completely different index (target).
2470 fcp->portdb[i].loopid = loopid;
2471 fcp->portdb[i].port_wwn = fcp->tport[loopid].port_wwn;
2472 fcp->portdb[i].node_wwn = fcp->tport[loopid].node_wwn;
2473 fcp->portdb[i].roles = fcp->tport[loopid].roles;
2474 fcp->portdb[i].portid = fcp->tport[loopid].portid;
2475 fcp->portdb[i].valid = 1;
2478 * Tell the outside world we've arrived.
2480 (void) isp_async(isp, ISPASYNC_PROMENADE, &i);
2484 * Now find all previously used targets that are now invalid and
2485 * notify the outer layers that they're gone.
2487 for (lp = &fcp->portdb[0]; lp < &fcp->portdb[hival]; lp++) {
2488 if (lp->valid || lp->port_wwn == 0) {
2493 * Tell the outside world we've gone
2494 * away and erase our pdb entry.
2497 loopid = lp - fcp->portdb;
2498 (void) isp_async(isp, ISPASYNC_PROMENADE, &loopid);
2499 MEMZERO((void *) lp, sizeof (*lp));
2501 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2507 isp_fabric_mbox_cmd(ispsoftc_t *isp, mbreg_t *mbp)
2509 /* the caller sets up the mailbox */
2510 isp_mboxcmd(isp, mbp, MBLOGNONE);
2511 if (mbp->param[0] != MBOX_COMMAND_COMPLETE) {
2512 if (FCPARAM(isp)->isp_loopstate == LOOP_SCANNING_FABRIC) {
2513 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
2515 if (mbp->param[0] == MBOX_COMMAND_ERROR) {
2518 switch (mbp->param[1]) {
2523 m = "Failed to allocate IOCB buffer";
2526 m = "Failed to allocate XCB buffer";
2529 m = "timeout or transmit failed";
2532 m = "no fabric loop";
2535 m = "remote device not a target";
2538 SNPRINTF(tbuf, sizeof tbuf, "%x",
2543 isp_prt(isp, ISP_LOGERR, "SNS Failed- %s", m);
2548 if (FCPARAM(isp)->isp_fwstate != FW_READY ||
2549 FCPARAM(isp)->isp_loopstate < LOOP_SCANNING_FABRIC) {
2555 #ifdef ISP_USE_GA_NXT
2557 isp_scan_fabric(ispsoftc_t *isp, int ftype)
2559 fcparam *fcp = isp->isp_param;
2560 uint32_t portid, first_portid, last_portid;
2561 int hicap, last_port_same;
2563 if (fcp->isp_onfabric == 0) {
2564 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2568 isp_prt(isp, ISP_LOGDEBUG0, "scanning fabric (GA_NXT)");
2570 FC_SCRATCH_ACQUIRE(isp);
2573 * Since Port IDs are 24 bits, we can check against having seen
2574 * anything yet with this value.
2577 last_portid = 0xffffffff; /* not a port */
2578 first_portid = portid = fcp->isp_portid;
2579 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2581 for (hicap = 0; hicap < GA_NXT_MAX; hicap++) {
2584 sns_ga_nxt_rsp_t *rs0, *rs1;
2586 uint8_t sc[SNS_GA_NXT_RESP_SIZE];
2588 rq = (sns_screq_t *)sc;
2589 MEMZERO((void *) rq, SNS_GA_NXT_REQ_SIZE);
2590 rq->snscb_rblen = SNS_GA_NXT_RESP_SIZE >> 1;
2591 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+0x100);
2592 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+0x100);
2593 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+0x100);
2594 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+0x100);
2595 rq->snscb_sblen = 6;
2596 rq->snscb_data[0] = SNS_GA_NXT;
2597 rq->snscb_data[4] = portid & 0xffff;
2598 rq->snscb_data[5] = (portid >> 16) & 0xff;
2599 isp_put_sns_request(isp, rq, (sns_screq_t *) fcp->isp_scratch);
2600 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GA_NXT_REQ_SIZE);
2601 MEMZERO(&mbs, sizeof (mbs));
2602 mbs.param[0] = MBOX_SEND_SNS;
2603 mbs.param[1] = SNS_GA_NXT_REQ_SIZE >> 1;
2604 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2605 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2607 * Leave 4 and 5 alone
2609 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2610 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2611 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2612 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2613 fcp->isp_loopstate = LOOP_PDB_RCVD;
2615 FC_SCRATCH_RELEASE(isp);
2618 MEMORYBARRIER(isp, SYNC_SFORCPU, 0x100, SNS_GA_NXT_RESP_SIZE);
2619 rs1 = (sns_ga_nxt_rsp_t *) sc;
2620 rs0 = (sns_ga_nxt_rsp_t *) ((uint8_t *)fcp->isp_scratch+0x100);
2621 isp_get_ga_nxt_response(isp, rs0, rs1);
2622 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2624 if (rs1->snscb_cthdr.ct_reason == 9 &&
2625 rs1->snscb_cthdr.ct_explanation == 7)
2626 level = ISP_LOGDEBUG0;
2628 level = ISP_LOGWARN;
2629 isp_prt(isp, level, swrej, "GA_NXT",
2630 rs1->snscb_cthdr.ct_reason,
2631 rs1->snscb_cthdr.ct_explanation, portid);
2632 FC_SCRATCH_RELEASE(isp);
2633 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2637 (((uint32_t) rs1->snscb_port_id[0]) << 16) |
2638 (((uint32_t) rs1->snscb_port_id[1]) << 8) |
2639 (((uint32_t) rs1->snscb_port_id[2]));
2642 * XXX: We should check to make sure that this entry
2643 * XXX: supports the type(s) we are interested in.
2646 * Okay, we now have information about a fabric object.
2647 * If it is the type we're interested in, tell the outer layers
2648 * about it. The outer layer needs to know: Port ID, WWNN,
2649 * WWPN, FC4 type, and port type.
2651 * The lportdb structure is adequate for this.
2653 MEMZERO(&lcl, sizeof (lcl));
2654 lcl.port_type = rs1->snscb_port_type;
2655 lcl.fc4_type = ftype;
2656 lcl.portid = portid;
2658 (((uint64_t)rs1->snscb_nodename[0]) << 56) |
2659 (((uint64_t)rs1->snscb_nodename[1]) << 48) |
2660 (((uint64_t)rs1->snscb_nodename[2]) << 40) |
2661 (((uint64_t)rs1->snscb_nodename[3]) << 32) |
2662 (((uint64_t)rs1->snscb_nodename[4]) << 24) |
2663 (((uint64_t)rs1->snscb_nodename[5]) << 16) |
2664 (((uint64_t)rs1->snscb_nodename[6]) << 8) |
2665 (((uint64_t)rs1->snscb_nodename[7]));
2667 (((uint64_t)rs1->snscb_portname[0]) << 56) |
2668 (((uint64_t)rs1->snscb_portname[1]) << 48) |
2669 (((uint64_t)rs1->snscb_portname[2]) << 40) |
2670 (((uint64_t)rs1->snscb_portname[3]) << 32) |
2671 (((uint64_t)rs1->snscb_portname[4]) << 24) |
2672 (((uint64_t)rs1->snscb_portname[5]) << 16) |
2673 (((uint64_t)rs1->snscb_portname[6]) << 8) |
2674 (((uint64_t)rs1->snscb_portname[7]));
2677 * Does this fabric object support the type we want?
2680 if (rs1->snscb_fc4_types[ftype >> 5] & (1 << (ftype & 0x1f))) {
2681 if (first_portid == portid) {
2682 lcl.last_fabric_dev = 1;
2684 lcl.last_fabric_dev = 0;
2686 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
2688 isp_prt(isp, ISP_LOGDEBUG0,
2689 "PortID 0x%x doesn't support FC4 type 0x%x",
2692 if (first_portid == portid) {
2693 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2694 FC_SCRATCH_RELEASE(isp);
2697 if (portid == last_portid) {
2698 if (last_port_same++ > 20) {
2699 isp_prt(isp, ISP_LOGWARN,
2700 "tangled fabric database detected");
2704 last_port_same = 0 ;
2705 last_portid = portid;
2708 FC_SCRATCH_RELEASE(isp);
2709 if (hicap >= GA_NXT_MAX) {
2710 isp_prt(isp, ISP_LOGWARN, "fabric too big (> %d)", GA_NXT_MAX);
2712 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2716 #define GIDLEN ((ISP2100_SCRLEN >> 1) + 16)
2717 #define NGENT ((GIDLEN - 16) >> 2)
2719 #define IGPOFF (ISP2100_SCRLEN - GIDLEN)
2723 isp_scan_fabric(ispsoftc_t *isp, int ftype)
2725 fcparam *fcp = FCPARAM(isp);
2728 sns_gid_ft_req_t *rq;
2729 sns_gid_ft_rsp_t *rs0, *rs1;
2731 if (fcp->isp_onfabric == 0) {
2732 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2736 isp_prt(isp, ISP_LOGDEBUG0, "scanning fabric (GID_FT)");
2738 FC_SCRATCH_ACQUIRE(isp);
2739 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
2741 rq = (sns_gid_ft_req_t *)fcp->tport;
2742 MEMZERO((void *) rq, SNS_GID_FT_REQ_SIZE);
2743 rq->snscb_rblen = GIDLEN >> 1;
2744 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+IGPOFF);
2745 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+IGPOFF);
2746 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+IGPOFF);
2747 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+IGPOFF);
2748 rq->snscb_sblen = 6;
2749 rq->snscb_cmd = SNS_GID_FT;
2750 rq->snscb_mword_div_2 = NGENT;
2751 rq->snscb_fc4_type = ftype;
2752 isp_put_gid_ft_request(isp, rq, (sns_gid_ft_req_t *) fcp->isp_scratch);
2753 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE);
2754 MEMZERO(&mbs, sizeof (mbs));
2755 mbs.param[0] = MBOX_SEND_SNS;
2756 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
2757 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2758 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2761 * Leave 4 and 5 alone
2763 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2764 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2765 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2766 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2767 fcp->isp_loopstate = LOOP_PDB_RCVD;
2769 FC_SCRATCH_RELEASE(isp);
2772 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2773 FC_SCRATCH_RELEASE(isp);
2776 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN);
2777 rs1 = (sns_gid_ft_rsp_t *) fcp->tport;
2778 rs0 = (sns_gid_ft_rsp_t *) ((uint8_t *)fcp->isp_scratch+IGPOFF);
2779 isp_get_gid_ft_response(isp, rs0, rs1, NGENT);
2780 if (rs1->snscb_cthdr.ct_response != FS_ACC) {
2782 if (rs1->snscb_cthdr.ct_reason == 9 &&
2783 rs1->snscb_cthdr.ct_explanation == 7)
2784 level = ISP_LOGDEBUG0;
2786 level = ISP_LOGWARN;
2787 isp_prt(isp, level, swrej, "GID_FT",
2788 rs1->snscb_cthdr.ct_reason,
2789 rs1->snscb_cthdr.ct_explanation, 0);
2790 FC_SCRATCH_RELEASE(isp);
2791 fcp->isp_loopstate = LOOP_FSCAN_DONE;
2796 * Okay, we now have a list of Port IDs for this class of device.
2797 * Go through the list and for each one get the WWPN/WWNN for it
2798 * and tell the outer layers about it. The outer layer needs to
2799 * know: Port ID, WWNN, WWPN, FC4 type, and (possibly) port type.
2801 * The lportdb structure is adequate for this.
2805 sns_gxn_id_req_t grqbuf, *gq = &grqbuf;
2806 sns_gxn_id_rsp_t *gs0, grsbuf, *gs1 = &grsbuf;
2809 sns_gff_id_rsp_t *fs0, ffsbuf, *fs1 = &ffsbuf;
2813 MEMZERO(&lcl, sizeof (lcl));
2814 lcl.fc4_type = ftype;
2816 (((uint32_t) rs1->snscb_ports[i].portid[0]) << 16) |
2817 (((uint32_t) rs1->snscb_ports[i].portid[1]) << 8) |
2818 (((uint32_t) rs1->snscb_ports[i].portid[2]));
2820 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2821 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2822 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2823 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2824 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2825 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2826 gq->snscb_sblen = 6;
2827 gq->snscb_cmd = SNS_GPN_ID;
2828 gq->snscb_portid = lcl.portid;
2829 isp_put_gxn_id_request(isp, gq,
2830 (sns_gxn_id_req_t *) fcp->isp_scratch);
2831 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2832 MEMZERO(&mbs, sizeof (mbs));
2833 mbs.param[0] = MBOX_SEND_SNS;
2834 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2835 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2836 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2838 * Leave 4 and 5 alone
2840 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2841 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2842 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2843 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2844 fcp->isp_loopstate = LOOP_PDB_RCVD;
2846 FC_SCRATCH_RELEASE(isp);
2849 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2850 FC_SCRATCH_RELEASE(isp);
2853 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2854 gs0 = (sns_gxn_id_rsp_t *) ((uint8_t *)fcp->isp_scratch+GXOFF);
2855 isp_get_gxn_id_response(isp, gs0, gs1);
2856 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2857 isp_prt(isp, ISP_LOGWARN, swrej, "GPN_ID",
2858 gs1->snscb_cthdr.ct_reason,
2859 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2860 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2861 FC_SCRATCH_RELEASE(isp);
2867 (((uint64_t)gs1->snscb_wwn[0]) << 56) |
2868 (((uint64_t)gs1->snscb_wwn[1]) << 48) |
2869 (((uint64_t)gs1->snscb_wwn[2]) << 40) |
2870 (((uint64_t)gs1->snscb_wwn[3]) << 32) |
2871 (((uint64_t)gs1->snscb_wwn[4]) << 24) |
2872 (((uint64_t)gs1->snscb_wwn[5]) << 16) |
2873 (((uint64_t)gs1->snscb_wwn[6]) << 8) |
2874 (((uint64_t)gs1->snscb_wwn[7]));
2876 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2877 gq->snscb_rblen = SNS_GXN_ID_RESP_SIZE >> 1;
2878 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2879 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2880 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2881 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2882 gq->snscb_sblen = 6;
2883 gq->snscb_cmd = SNS_GNN_ID;
2884 gq->snscb_portid = lcl.portid;
2885 isp_put_gxn_id_request(isp, gq,
2886 (sns_gxn_id_req_t *) fcp->isp_scratch);
2887 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2888 MEMZERO(&mbs, sizeof (mbs));
2889 mbs.param[0] = MBOX_SEND_SNS;
2890 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2891 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2892 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2894 * Leave 4 and 5 alone
2896 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2897 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2898 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2899 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2900 fcp->isp_loopstate = LOOP_PDB_RCVD;
2902 FC_SCRATCH_RELEASE(isp);
2905 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2906 FC_SCRATCH_RELEASE(isp);
2909 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GXN_ID_RESP_SIZE);
2910 gs0 = (sns_gxn_id_rsp_t *) ((uint8_t *)fcp->isp_scratch+GXOFF);
2911 isp_get_gxn_id_response(isp, gs0, gs1);
2912 if (gs1->snscb_cthdr.ct_response != FS_ACC) {
2913 isp_prt(isp, ISP_LOGWARN, swrej, "GNN_ID",
2914 gs1->snscb_cthdr.ct_reason,
2915 gs1->snscb_cthdr.ct_explanation, lcl.portid);
2916 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2917 FC_SCRATCH_RELEASE(isp);
2923 (((uint64_t)gs1->snscb_wwn[0]) << 56) |
2924 (((uint64_t)gs1->snscb_wwn[1]) << 48) |
2925 (((uint64_t)gs1->snscb_wwn[2]) << 40) |
2926 (((uint64_t)gs1->snscb_wwn[3]) << 32) |
2927 (((uint64_t)gs1->snscb_wwn[4]) << 24) |
2928 (((uint64_t)gs1->snscb_wwn[5]) << 16) |
2929 (((uint64_t)gs1->snscb_wwn[6]) << 8) |
2930 (((uint64_t)gs1->snscb_wwn[7]));
2933 * The QLogic f/w is bouncing this with a parameter error.
2937 * Try and get FC4 Features (FC-GS-3 only).
2938 * We can use the sns_gxn_id_req_t for this request.
2940 MEMZERO((void *) gq, sizeof (sns_gxn_id_req_t));
2941 gq->snscb_rblen = SNS_GFF_ID_RESP_SIZE >> 1;
2942 gq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma+GXOFF);
2943 gq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma+GXOFF);
2944 gq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma+GXOFF);
2945 gq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma+GXOFF);
2946 gq->snscb_sblen = 6;
2947 gq->snscb_cmd = SNS_GFF_ID;
2948 gq->snscb_portid = lcl.portid;
2949 isp_put_gxn_id_request(isp, gq,
2950 (sns_gxn_id_req_t *) fcp->isp_scratch);
2951 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GXN_ID_REQ_SIZE);
2952 MEMZERO(&mbs, sizeof (mbs));
2953 mbs.param[0] = MBOX_SEND_SNS;
2954 mbs.param[1] = SNS_GXN_ID_REQ_SIZE >> 1;
2955 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2956 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2958 * Leave 4 and 5 alone
2960 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2961 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2962 if (isp_fabric_mbox_cmd(isp, &mbs)) {
2963 if (fcp->isp_loopstate >= LOOP_SCANNING_FABRIC) {
2964 fcp->isp_loopstate = LOOP_PDB_RCVD;
2966 FC_SCRATCH_RELEASE(isp);
2969 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2970 FC_SCRATCH_RELEASE(isp);
2973 MEMORYBARRIER(isp, SYNC_SFORCPU, GXOFF, SNS_GFF_ID_RESP_SIZE);
2974 fs0 = (sns_gff_id_rsp_t *) ((uint8_t *)fcp->isp_scratch+GXOFF);
2975 isp_get_gff_id_response(isp, fs0, fs1);
2976 if (fs1->snscb_cthdr.ct_response != FS_ACC) {
2977 isp_prt(isp, /* ISP_LOGDEBUG0 */ ISP_LOGWARN,
2979 fs1->snscb_cthdr.ct_reason,
2980 fs1->snscb_cthdr.ct_explanation, lcl.portid);
2981 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
2982 FC_SCRATCH_RELEASE(isp);
2986 int index = (ftype >> 3);
2987 int bshft = (ftype & 0x7) * 4;
2989 (fs1->snscb_fc4_features[index] >> bshft) & 0xf;
2990 if (fc4_fval & 0x1) {
2992 (SVC3_INI_ROLE >> SVC3_ROLE_SHIFT);
2994 if (fc4_fval & 0x2) {
2996 (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT);
3002 * If we really want to know what kind of port type this is,
3003 * we have to run another CT command. Otherwise, we'll leave
3008 if (rs1->snscb_ports[i].control & 0x80) {
3009 lcl.last_fabric_dev = 1;
3011 lcl.last_fabric_dev = 0;
3013 (void) isp_async(isp, ISPASYNC_FABRIC_DEV, &lcl);
3015 } while ((rs1->snscb_ports[i].control & 0x80) == 0 && i < NGENT-1);
3018 * If we're not at the last entry, our list isn't big enough.
3020 if ((rs1->snscb_ports[i].control & 0x80) == 0) {
3021 isp_prt(isp, ISP_LOGWARN, "fabric too big for scratch area");
3024 FC_SCRATCH_RELEASE(isp);
3025 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3031 isp_register_fc4_type(ispsoftc_t *isp)
3033 fcparam *fcp = isp->isp_param;
3034 uint8_t local[SNS_RFT_ID_REQ_SIZE];
3035 sns_screq_t *reqp = (sns_screq_t *) local;
3038 MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
3039 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
3040 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
3041 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
3042 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
3043 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
3044 reqp->snscb_sblen = 22;
3045 reqp->snscb_data[0] = SNS_RFT_ID;
3046 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
3047 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
3048 reqp->snscb_data[6] = (1 << FC4_SCSI);
3050 reqp->snscb_data[6] |= (1 << FC4_IP); /* ISO/IEC 8802-2 LLC/SNAP */
3052 FC_SCRATCH_ACQUIRE(isp);
3053 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
3054 MEMZERO(&mbs, sizeof (mbs));
3055 mbs.param[0] = MBOX_SEND_SNS;
3056 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
3057 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
3058 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
3060 * Leave 4 and 5 alone
3062 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
3063 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
3064 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_RFT_ID_REQ_SIZE);
3065 isp_mboxcmd(isp, &mbs, MBLOGALL);
3066 FC_SCRATCH_RELEASE(isp);
3067 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3068 isp_prt(isp, ISP_LOGDEBUG0, "Register FC4 types succeeded");
3073 * Start a command. Locking is assumed done in the caller.
3080 uint16_t nxti, optr, handle;
3081 uint8_t local[QENTRY_LEN];
3082 ispreq_t *reqp, *qep;
3089 * Check to make sure we're supporting initiator role.
3091 if ((isp->isp_role & ISP_ROLE_INITIATOR) == 0) {
3092 XS_SETERR(xs, HBA_SELTIMEOUT);
3093 return (CMD_COMPLETE);
3097 * Now make sure we're running.
3100 if (isp->isp_state != ISP_RUNSTATE) {
3101 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
3102 XS_SETERR(xs, HBA_BOTCH);
3103 return (CMD_COMPLETE);
3107 * Check command CDB length, etc.. We really are limited to 16 bytes
3108 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
3109 * but probably only if we're running fairly new firmware (we'll
3110 * let the old f/w choke on an extended command queue entry).
3113 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
3114 isp_prt(isp, ISP_LOGERR,
3115 "unsupported cdb length (%d, CDB[0]=0x%x)",
3116 XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
3117 XS_SETERR(xs, HBA_BOTCH);
3118 return (CMD_COMPLETE);
3122 * Check to see whether we have good firmware state still or
3123 * need to refresh our port database for this target.
3125 target = XS_TGT(xs);
3127 fcparam *fcp = isp->isp_param;
3129 #ifdef HANDLE_LOOPSTATE_IN_OUTER_LAYERS
3130 if (fcp->isp_fwstate != FW_READY ||
3131 fcp->isp_loopstate != LOOP_READY) {
3132 return (CMD_RQLATER);
3136 * If we're not on a Fabric, we can't have a target
3137 * above FL_PORT_ID-1.
3139 * If we're on a fabric and *not* connected as an F-port,
3140 * we can't have a target less than FC_SNS_ID+1. This
3141 * keeps us from having to sort out the difference between
3142 * local public loop devices and those which we might get
3143 * from a switch's database.
3145 if (fcp->isp_onfabric == 0) {
3146 if (target >= FL_PORT_ID) {
3147 XS_SETERR(xs, HBA_SELTIMEOUT);
3148 return (CMD_COMPLETE);
3151 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3152 XS_SETERR(xs, HBA_SELTIMEOUT);
3153 return (CMD_COMPLETE);
3156 * We used to exclude having local loop ports
3157 * at the same time that we have fabric ports.
3158 * That is, we used to exclude having ports
3159 * at < FL_PORT_ID if we're FL-port.
3161 * That's wrong. The only thing that could be
3162 * dicey is if the switch you're connected to
3163 * has these local loop ports appear on the
3164 * fabric and we somehow attach them twice.
3169 * Check for f/w being in ready state. If the f/w
3170 * isn't in ready state, then we don't know our
3171 * loop ID and the f/w hasn't completed logging
3172 * into all targets on the loop. If this is the
3173 * case, then bounce the command. We pretend this is
3174 * a SELECTION TIMEOUT error if we've never gone to
3175 * FW_READY state at all- in this case we may not
3176 * be hooked to a loop at all and we shouldn't hang
3177 * the machine for this. Otherwise, defer this command
3180 if (fcp->isp_fwstate != FW_READY) {
3182 * Give ourselves at most a 250ms delay.
3184 if (isp_fclink_test(isp, 250000)) {
3185 XS_SETERR(xs, HBA_SELTIMEOUT);
3186 if (fcp->loop_seen_once) {
3187 return (CMD_RQLATER);
3189 return (CMD_COMPLETE);
3195 * If we're not on a Fabric, we can't have a target
3196 * above FL_PORT_ID-1.
3198 * If we're on a fabric and *not* connected as an F-port,
3199 * we can't have a target less than FC_SNS_ID+1. This
3200 * keeps us from having to sort out the difference between
3201 * local public loop devices and those which we might get
3202 * from a switch's database.
3204 if (fcp->isp_onfabric == 0) {
3205 if (target >= FL_PORT_ID) {
3206 XS_SETERR(xs, HBA_SELTIMEOUT);
3207 return (CMD_COMPLETE);
3210 if (target >= FL_PORT_ID && target <= FC_SNS_ID) {
3211 XS_SETERR(xs, HBA_SELTIMEOUT);
3212 return (CMD_COMPLETE);
3214 if (fcp->isp_topo != TOPO_F_PORT &&
3215 target < FL_PORT_ID) {
3216 XS_SETERR(xs, HBA_SELTIMEOUT);
3217 return (CMD_COMPLETE);
3222 * If our loop state is such that we haven't yet received
3223 * a "Port Database Changed" notification (after a LIP or
3224 * a Loop Reset or firmware initialization), then defer
3225 * sending commands for a little while, but only if we've
3226 * seen a valid loop at one point (otherwise we can get
3227 * stuck at initialization time).
3229 if (fcp->isp_loopstate < LOOP_PDB_RCVD) {
3230 XS_SETERR(xs, HBA_SELTIMEOUT);
3231 if (fcp->loop_seen_once) {
3232 return (CMD_RQLATER);
3234 return (CMD_COMPLETE);
3239 * If we're in the middle of loop or fabric scanning
3240 * or merging the port databases, retry this command later.
3242 if (fcp->isp_loopstate == LOOP_SCANNING_FABRIC ||
3243 fcp->isp_loopstate == LOOP_SCANNING_LOOP ||
3244 fcp->isp_loopstate == LOOP_SYNCING_PDB) {
3245 return (CMD_RQLATER);
3249 * If our loop state is now such that we've just now
3250 * received a Port Database Change notification, then
3251 * we have to go off and (re)scan the fabric. We back
3252 * out and try again later if this doesn't work.
3254 if (fcp->isp_loopstate == LOOP_PDB_RCVD && fcp->isp_onfabric) {
3255 if (isp_scan_fabric(isp, FC4_SCSI)) {
3256 return (CMD_RQLATER);
3258 if (fcp->isp_fwstate != FW_READY ||
3259 fcp->isp_loopstate < LOOP_FSCAN_DONE) {
3260 return (CMD_RQLATER);
3265 * If our loop state is now such that we've just now
3266 * received a Port Database Change notification, then
3267 * we have to go off and (re)synchronize our port
3270 if (fcp->isp_loopstate < LOOP_READY) {
3271 if (isp_pdb_sync(isp)) {
3272 return (CMD_RQLATER);
3274 if (fcp->isp_fwstate != FW_READY ||
3275 fcp->isp_loopstate != LOOP_READY) {
3276 return (CMD_RQLATER);
3281 * XXX: Here's were we would cancel any loop_dead flag
3282 * XXX: also cancel in dead_loop timeout that's running
3287 * Now check whether we should even think about pursuing this.
3289 lp = &fcp->portdb[target];
3290 if (lp->valid == 0) {
3291 XS_SETERR(xs, HBA_SELTIMEOUT);
3292 return (CMD_COMPLETE);
3294 if ((lp->roles & (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT)) == 0) {
3295 isp_prt(isp, ISP_LOGDEBUG2,
3296 "Target %d does not have target service", target);
3297 XS_SETERR(xs, HBA_SELTIMEOUT);
3298 return (CMD_COMPLETE);
3301 * Now turn target into what the actual Loop ID is.
3303 target = lp->loopid;
3307 * Next check to see if any HBA or Device
3308 * parameters need to be updated.
3310 if (isp->isp_update != 0) {
3314 if (isp_getrqentry(isp, &nxti, &optr, (void *)&qep)) {
3315 isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow");
3316 XS_SETERR(xs, HBA_BOTCH);
3317 return (CMD_EAGAIN);
3321 * Now see if we need to synchronize the ISP with respect to anything.
3322 * We do dual duty here (cough) for synchronizing for busses other
3323 * than which we got here to send a command to.
3325 reqp = (ispreq_t *) local;
3326 if (isp->isp_sendmarker) {
3327 uint8_t n = (IS_DUALBUS(isp)? 2: 1);
3329 * Check ports to send markers for...
3331 for (i = 0; i < n; i++) {
3332 if ((isp->isp_sendmarker & (1 << i)) == 0) {
3335 MEMZERO((void *) reqp, QENTRY_LEN);
3336 reqp->req_header.rqs_entry_count = 1;
3337 reqp->req_header.rqs_entry_type = RQSTYPE_MARKER;
3338 reqp->req_modifier = SYNC_ALL;
3339 reqp->req_target = i << 7; /* insert bus number */
3340 isp_put_request(isp, reqp, qep);
3341 ISP_ADD_REQUEST(isp, nxti);
3342 isp->isp_sendmarker &= ~(1 << i);
3343 if (isp_getrqentry(isp, &nxti, &optr, (void *) &qep)) {
3344 isp_prt(isp, ISP_LOGDEBUG0,
3345 "Request Queue Overflow+");
3346 XS_SETERR(xs, HBA_BOTCH);
3347 return (CMD_EAGAIN);
3352 MEMZERO((void *)reqp, QENTRY_LEN);
3353 reqp->req_header.rqs_entry_count = 1;
3355 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
3357 if (XS_CDBLEN(xs) > 12)
3358 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
3360 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
3362 /* reqp->req_header.rqs_flags = 0; */
3363 /* reqp->req_header.rqs_seqno = 0; */
3366 * See comment in isp_intr
3368 /* XS_RESID(xs) = 0; */
3371 * Fibre Channel always requires some kind of tag.
3372 * The Qlogic drivers seem be happy not to use a tag,
3373 * but this breaks for some devices (IBM drives).
3376 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
3379 * If we don't know what tag to use, use HEAD OF QUEUE
3380 * for Request Sense or Simple.
3382 if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
3383 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_HTAG;
3385 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
3388 sdparam *sdp = (sdparam *)isp->isp_param;
3389 sdp += XS_CHANNEL(xs);
3390 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) &&
3392 reqp->req_flags = XS_TAG_TYPE(xs);
3396 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
3397 reqp->req_lun_trn = XS_LUN(xs);
3398 reqp->req_cdblen = XS_CDBLEN(xs);
3399 } else if (IS_2KLOGIN(isp)) {
3400 ((ispreqt2e_t *)reqp)->req_target = target;
3401 ((ispreqt2e_t *)reqp)->req_scclun = XS_LUN(xs);
3402 } else if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
3403 ((ispreqt2_t *)reqp)->req_target = target;
3404 ((ispreqt2_t *)reqp)->req_scclun = XS_LUN(xs);
3406 ((ispreqt2_t *)reqp)->req_target = target;
3407 ((ispreqt2_t *)reqp)->req_lun_trn = XS_LUN(xs);
3409 MEMCPY(reqp->req_cdb, XS_CDBP(xs), XS_CDBLEN(xs));
3411 reqp->req_time = XS_TIME(xs) / 1000;
3412 if (reqp->req_time == 0 && XS_TIME(xs)) {
3416 if (isp_save_xs(isp, xs, &handle)) {
3417 isp_prt(isp, ISP_LOGDEBUG0, "out of xflist pointers");
3418 XS_SETERR(xs, HBA_BOTCH);
3419 return (CMD_EAGAIN);
3421 reqp->req_handle = handle;
3424 * Set up DMA and/or do any bus swizzling of the request entry
3425 * so that the Qlogic F/W understands what is being asked of it.
3427 i = ISP_DMASETUP(isp, xs, reqp, &nxti, optr);
3428 if (i != CMD_QUEUED) {
3429 isp_destroy_handle(isp, handle);
3431 * dmasetup sets actual error in packet, and
3432 * return what we were given to return.
3436 XS_SETERR(xs, HBA_NOERROR);
3437 isp_prt(isp, ISP_LOGDEBUG2,
3438 "START cmd for %d.%d.%d cmd 0x%x datalen %ld",
3439 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), XS_CDBP(xs)[0],
3440 (long) XS_XFRLEN(xs));
3441 ISP_ADD_REQUEST(isp, nxti);
3443 return (CMD_QUEUED);
3448 * Locks (ints blocked) assumed held.
3452 isp_control(ispsoftc_t *isp, ispctl_t ctl, void *arg)
3459 MEMZERO(&mbs, sizeof (mbs));
3463 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
3466 case ISPCTL_RESET_BUS:
3468 * Issue a bus reset.
3470 mbs.param[0] = MBOX_BUS_RESET;
3473 ((sdparam *) isp->isp_param)->isp_bus_reset_delay;
3474 if (mbs.param[1] < 2) {
3477 bus = *((int *) arg);
3478 if (IS_DUALBUS(isp)) {
3485 isp->isp_sendmarker |= (1 << bus);
3486 isp_mboxcmd(isp, &mbs, MBLOGALL);
3487 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3490 isp_prt(isp, ISP_LOGINFO,
3491 "driver initiated bus reset of bus %d", bus);
3494 case ISPCTL_RESET_DEV:
3495 tgt = (*((int *) arg)) & 0xffff;
3496 bus = (*((int *) arg)) >> 16;
3497 mbs.param[0] = MBOX_ABORT_TARGET;
3499 mbs.param[1] = (tgt << 8) | (bus << 15);
3501 if (IS_2KLOGIN(isp)) {
3503 mbs.ibits |= (1 << 10);
3505 mbs.param[1] = (tgt << 8);
3508 mbs.param[2] = 3; /* 'delay', in seconds */
3509 isp_mboxcmd(isp, &mbs, MBLOGALL);
3510 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3513 isp_prt(isp, ISP_LOGINFO,
3514 "Target %d on Bus %d Reset Succeeded", tgt, bus);
3515 isp->isp_sendmarker |= (1 << bus);
3518 case ISPCTL_ABORT_CMD:
3521 handle = isp_find_handle(isp, xs);
3523 isp_prt(isp, ISP_LOGWARN,
3524 "cannot find handle for command to abort");
3527 bus = XS_CHANNEL(xs);
3528 mbs.param[0] = MBOX_ABORT;
3530 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
3531 if (IS_2KLOGIN(isp)) {
3534 mbs.param[1] = tgt << 8;
3536 mbs.param[6] = XS_LUN(xs);
3538 mbs.param[1] = tgt << 8 | XS_LUN(xs);
3542 (bus << 15) | (XS_TGT(xs) << 8) | XS_LUN(xs);
3544 mbs.param[2] = handle;
3545 isp_mboxcmd(isp, &mbs, MBLOGALL & ~MBOX_COMMAND_ERROR);
3546 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3550 * XXX: Look for command in the REQUEST QUEUE. That is,
3551 * XXX: It hasen't been picked up by firmware yet.
3555 case ISPCTL_UPDATE_PARAMS:
3560 case ISPCTL_FCLINK_TEST:
3563 int usdelay = *((int *) arg);
3567 return (isp_fclink_test(isp, usdelay));
3571 case ISPCTL_SCAN_FABRIC:
3574 int ftype = (arg)? *((int *) arg) : FC4_SCSI;
3575 return (isp_scan_fabric(isp, ftype));
3579 case ISPCTL_SCAN_LOOP:
3582 return (isp_scan_loop(isp));
3586 case ISPCTL_PDB_SYNC:
3589 return (isp_pdb_sync(isp));
3593 case ISPCTL_SEND_LIP:
3596 mbs.param[0] = MBOX_INIT_LIP;
3597 if (IS_2KLOGIN(isp)) {
3598 mbs.ibits |= (1 << 10);
3600 isp_mboxcmd(isp, &mbs, MBLOGALL);
3601 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3607 case ISPCTL_GET_POSMAP:
3609 if (IS_FC(isp) && arg) {
3610 return (isp_getmap(isp, arg));
3615 case ISPCTL_GET_PDB:
3616 if (IS_FC(isp) && arg) {
3617 int id = *((int *)arg);
3618 isp_pdb_t *pdb = arg;
3619 return (isp_getpdb(isp, id, pdb));
3623 case ISPCTL_RUN_MBOXCMD:
3625 isp_mboxcmd(isp, arg, MBLOGALL);
3628 #ifdef ISP_TARGET_MODE
3629 case ISPCTL_TOGGLE_TMODE:
3633 * We don't check/set against role here- that's the
3634 * responsibility for the outer layer to coordinate.
3637 int param = *(int *)arg;
3638 mbs.param[0] = MBOX_ENABLE_TARGET_MODE;
3639 mbs.param[1] = param & 0xffff;
3640 mbs.param[2] = param >> 16;
3641 isp_mboxcmd(isp, &mbs, MBLOGALL);
3642 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3654 * Interrupt Service Routine(s).
3656 * External (OS) framework has done the appropriate locking,
3657 * and the locking will be held throughout this function.
3661 * Limit our stack depth by sticking with the max likely number
3662 * of completions on a request queue at any one time.
3664 #ifndef MAX_REQUESTQ_COMPLETIONS
3665 #define MAX_REQUESTQ_COMPLETIONS 64
3669 isp_intr(ispsoftc_t *isp, uint16_t isr, uint16_t sema, uint16_t mbox)
3671 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
3672 uint16_t iptr, optr, junk;
3673 int i, nlooked = 0, ndone = 0;
3677 * Is this a mailbox related interrupt?
3678 * The mailbox semaphore will be nonzero if so.
3681 if (mbox & 0x4000) {
3682 isp->isp_intmboxc++;
3683 if (isp->isp_mboxbsy) {
3684 int i = 0, obits = isp->isp_obits;
3685 isp->isp_mboxtmp[i++] = mbox;
3686 for (i = 1; i < MAX_MAILBOX(isp); i++) {
3687 if ((obits & (1 << i)) == 0) {
3690 isp->isp_mboxtmp[i] =
3691 ISP_READ(isp, MBOX_OFF(i));
3693 if (isp->isp_mbxwrk0) {
3694 if (isp_mbox_continue(isp) == 0) {
3698 MBOX_NOTIFY_COMPLETE(isp);
3700 isp_prt(isp, ISP_LOGWARN,
3701 "Mbox Command Async (0x%x) with no waiters",
3704 } else if (isp_parse_async(isp, mbox) < 0) {
3707 if ((IS_FC(isp) && mbox != ASYNC_RIO_RESP) ||
3708 isp->isp_state != ISP_RUNSTATE) {
3709 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3710 ISP_WRITE(isp, BIU_SEMA, 0);
3716 * We can't be getting this now.
3718 if (isp->isp_state != ISP_RUNSTATE) {
3719 isp_prt(isp, ISP_LOGWARN,
3720 "interrupt (ISR=%x SEMA=%x) when not ready", isr, sema);
3722 * Thank you very much! *Burrrp*!
3724 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp,
3725 READ_RESPONSE_QUEUE_IN_POINTER(isp));
3727 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3728 ISP_WRITE(isp, BIU_SEMA, 0);
3733 * Get the current Response Queue Out Pointer.
3735 * If we're a 2300, we can ask what hardware what it thinks.
3738 optr = ISP_READ(isp, isp->isp_respoutrp);
3740 * Debug: to be taken out eventually
3742 if (isp->isp_residx != optr) {
3743 isp_prt(isp, ISP_LOGWARN, "optr %x soft optr %x",
3744 optr, isp->isp_residx);
3747 optr = isp->isp_residx;
3751 * You *must* read the Response Queue In Pointer
3752 * prior to clearing the RISC interrupt.
3754 * Debounce the 2300 if revision less than 2.
3756 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
3759 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3760 junk = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3761 } while (junk != iptr && ++i < 1000);
3764 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3765 isp_prt(isp, ISP_LOGWARN,
3766 "Response Queue Out Pointer Unstable (%x, %x)",
3771 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3773 isp->isp_resodx = iptr;
3776 if (optr == iptr && sema == 0) {
3778 * There are a lot of these- reasons unknown- mostly on
3779 * faster Alpha machines.
3781 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
3782 * make sure the old interrupt went away (to avoid 'ringing'
3783 * effects), but that didn't stop this from occurring.
3787 iptr = READ_RESPONSE_QUEUE_IN_POINTER(isp);
3788 junk = ISP_READ(isp, BIU_R2HSTSLO);
3790 junk = ISP_READ(isp, BIU_ISR);
3796 sema = ISP_READ(isp, BIU_SEMA);
3797 mbox = ISP_READ(isp, OUTMAILBOX0);
3798 if ((sema & 0x3) && (mbox & 0x8000)) {
3802 isp->isp_intbogus++;
3803 isp_prt(isp, ISP_LOGDEBUG1,
3804 "bogus intr- isr %x (%x) iptr %x optr %x",
3805 isr, junk, iptr, optr);
3808 isp->isp_resodx = iptr;
3809 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
3810 ISP_WRITE(isp, BIU_SEMA, 0);
3812 if (isp->isp_rspbsy) {
3815 isp->isp_rspbsy = 1;
3817 while (optr != iptr) {
3818 ispstatusreq_t local, *sp = &local;
3824 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
3826 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
3830 * Synchronize our view of this response queue entry.
3832 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN);
3834 type = isp_get_response_type(isp, hp);
3836 if (type == RQSTYPE_RESPONSE) {
3837 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3838 } else if (type == RQSTYPE_RIO2) {
3840 isp_get_rio2(isp, (isp_rio2_t *) hp, &rio);
3841 for (i = 0; i < rio.req_header.rqs_seqno; i++) {
3842 isp_fastpost_complete(isp, rio.req_handles[i]);
3844 if (isp->isp_fpcchiwater < rio.req_header.rqs_seqno)
3845 isp->isp_fpcchiwater = rio.req_header.rqs_seqno;
3846 MEMZERO(hp, QENTRY_LEN); /* PERF */
3850 * Somebody reachable via isp_handle_other_response
3851 * may have updated the response queue pointers for
3852 * us, so we reload our goal index.
3854 int i = isp_handle_other_response(isp, type, hp, &optr);
3858 iptr = isp->isp_resodx;
3859 MEMZERO(hp, QENTRY_LEN); /* PERF */
3864 * After this point, we'll just look at the header as
3865 * we don't know how to deal with the rest of the
3868 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
3871 * It really has to be a bounced request just copied
3872 * from the request queue to the response queue. If
3873 * not, something bad has happened.
3875 if (sp->req_header.rqs_entry_type != RQSTYPE_REQUEST) {
3876 isp_prt(isp, ISP_LOGERR, notresp,
3877 sp->req_header.rqs_entry_type, oop, optr,
3879 if (isp->isp_dblev & ISP_LOGDEBUG0) {
3880 isp_print_bytes(isp, "Queue Entry",
3883 MEMZERO(hp, QENTRY_LEN); /* PERF */
3889 if (sp->req_header.rqs_flags & 0xf) {
3890 #define _RQS_OFLAGS \
3891 ~(RQSFLAG_CONTINUATION|RQSFLAG_FULL|RQSFLAG_BADHEADER|RQSFLAG_BADPACKET)
3892 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
3893 isp_prt(isp, ISP_LOGWARN,
3894 "continuation segment");
3895 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3898 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
3899 isp_prt(isp, ISP_LOGDEBUG1,
3900 "internal queues full");
3902 * We'll synthesize a QUEUE FULL message below.
3905 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
3906 isp_prt(isp, ISP_LOGERR, "bad header flag");
3909 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
3910 isp_prt(isp, ISP_LOGERR, "bad request packet");
3913 if (sp->req_header.rqs_flags & _RQS_OFLAGS) {
3914 isp_prt(isp, ISP_LOGERR,
3915 "unknown flags (0x%x) in response",
3916 sp->req_header.rqs_flags);
3921 if (sp->req_handle > isp->isp_maxcmds || sp->req_handle < 1) {
3922 MEMZERO(hp, QENTRY_LEN); /* PERF */
3923 isp_prt(isp, ISP_LOGERR,
3924 "bad request handle %d (type 0x%x, flags 0x%x)",
3925 sp->req_handle, sp->req_header.rqs_entry_type,
3926 sp->req_header.rqs_flags);
3927 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3930 xs = isp_find_xs(isp, sp->req_handle);
3932 uint8_t ts = sp->req_completion_status & 0xff;
3933 MEMZERO(hp, QENTRY_LEN); /* PERF */
3935 * Only whine if this isn't the expected fallout of
3936 * aborting the command.
3938 if (sp->req_header.rqs_entry_type != RQSTYPE_RESPONSE) {
3939 isp_prt(isp, ISP_LOGERR,
3940 "cannot find handle 0x%x (type 0x%x)",
3942 sp->req_header.rqs_entry_type);
3943 } else if (ts != RQCS_ABORTED) {
3944 isp_prt(isp, ISP_LOGERR,
3945 "cannot find handle 0x%x (status 0x%x)",
3946 sp->req_handle, ts);
3948 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
3951 isp_destroy_handle(isp, sp->req_handle);
3952 if (sp->req_status_flags & RQSTF_BUS_RESET) {
3953 XS_SETERR(xs, HBA_BUSRESET);
3954 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
3957 XS_SETERR(xs, HBA_BOTCH);
3960 if (IS_FC(isp) && (sp->req_scsi_status & RQCS_SV)) {
3962 * Fibre Channel F/W doesn't say we got status
3963 * if there's Sense Data instead. I guess they
3964 * think it goes w/o saying.
3966 sp->req_state_flags |= RQSF_GOT_STATUS;
3968 if (sp->req_state_flags & RQSF_GOT_STATUS) {
3969 *XS_STSP(xs) = sp->req_scsi_status & 0xff;
3972 switch (sp->req_header.rqs_entry_type) {
3973 case RQSTYPE_RESPONSE:
3974 XS_SET_STATE_STAT(isp, xs, sp);
3975 isp_parse_status(isp, sp, xs);
3976 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) &&
3977 (*XS_STSP(xs) == SCSI_BUSY)) {
3978 XS_SETERR(xs, HBA_TGTBSY);
3981 XS_RESID(xs) = sp->req_resid;
3982 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
3983 (*XS_STSP(xs) == SCSI_CHECK) &&
3984 (sp->req_state_flags & RQSF_GOT_SENSE)) {
3985 XS_SAVE_SENSE(xs, sp);
3988 * A new synchronous rate was negotiated for
3989 * this target. Mark state such that we'll go
3990 * look up that which has changed later.
3992 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
3994 sdparam *sdp = isp->isp_param;
3995 sdp += XS_CHANNEL(xs);
3996 sdp->isp_devparam[t].dev_refresh = 1;
3998 (1 << XS_CHANNEL(xs));
4001 if (sp->req_status_flags & RQSF_XFER_COMPLETE) {
4003 } else if (sp->req_scsi_status & RQCS_RESID) {
4004 XS_RESID(xs) = sp->req_resid;
4008 if ((sp->req_state_flags & RQSF_GOT_STATUS) &&
4009 (*XS_STSP(xs) == SCSI_CHECK) &&
4010 (sp->req_scsi_status & RQCS_SV)) {
4011 XS_SAVE_SENSE(xs, sp);
4012 /* solely for the benefit of debug */
4013 sp->req_state_flags |= RQSF_GOT_SENSE;
4016 isp_prt(isp, ISP_LOGDEBUG2,
4017 "asked for %ld got raw resid %ld settled for %ld",
4018 (long) XS_XFRLEN(xs), (long) sp->req_resid,
4019 (long) XS_RESID(xs));
4021 case RQSTYPE_REQUEST:
4022 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
4024 * Force Queue Full status.
4026 *XS_STSP(xs) = SCSI_QFULL;
4027 XS_SETERR(xs, HBA_NOERROR);
4028 } else if (XS_NOERR(xs)) {
4032 isp_prt(isp, ISP_LOGDEBUG0,
4033 "Request Queue Entry bounced back");
4034 XS_SETERR(xs, HBA_BOTCH);
4036 XS_RESID(xs) = XS_XFRLEN(xs);
4039 isp_prt(isp, ISP_LOGWARN,
4040 "unhandled response queue type 0x%x",
4041 sp->req_header.rqs_entry_type);
4043 XS_SETERR(xs, HBA_BOTCH);
4049 * Free any DMA resources. As a side effect, this may
4050 * also do any cache flushing necessary for data coherence. */
4051 if (XS_XFRLEN(xs)) {
4052 ISP_DMAFREE(isp, xs, sp->req_handle);
4055 if (((isp->isp_dblev & (ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
4056 ((isp->isp_dblev & ISP_LOGDEBUG1) && ((!XS_NOERR(xs)) ||
4057 (*XS_STSP(xs) != SCSI_GOOD)))) {
4059 if (sp->req_state_flags & RQSF_GOT_SENSE) {
4060 skey = XS_SNSKEY(xs) & 0xf;
4065 } else if (*XS_STSP(xs) == SCSI_CHECK) {
4070 isp_prt(isp, ISP_LOGALL, finmsg, XS_CHANNEL(xs),
4071 XS_TGT(xs), XS_LUN(xs), XS_XFRLEN(xs), XS_RESID(xs),
4072 *XS_STSP(xs), skey, XS_ERR(xs));
4075 if (isp->isp_nactive > 0)
4077 complist[ndone++] = xs; /* defer completion call until later */
4078 MEMZERO(hp, QENTRY_LEN); /* PERF */
4079 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
4085 * If we looked at any commands, then it's valid to find out
4086 * what the outpointer is. It also is a trigger to update the
4087 * ISP's notion of what we've seen so far.
4090 WRITE_RESPONSE_QUEUE_OUT_POINTER(isp, optr);
4092 * While we're at it, read the requst queue out pointer.
4094 isp->isp_reqodx = READ_REQUEST_QUEUE_OUT_POINTER(isp);
4095 if (isp->isp_rscchiwater < ndone)
4096 isp->isp_rscchiwater = ndone;
4099 isp->isp_residx = optr;
4100 isp->isp_rspbsy = 0;
4101 for (i = 0; i < ndone; i++) {
4104 isp->isp_rsltccmplt++;
4115 isp_parse_async(ispsoftc_t *isp, uint16_t mbox)
4120 if (IS_DUALBUS(isp)) {
4121 bus = ISP_READ(isp, OUTMAILBOX6);
4125 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
4128 case ASYNC_BUS_RESET:
4129 isp->isp_sendmarker |= (1 << bus);
4130 #ifdef ISP_TARGET_MODE
4131 if (isp_target_async(isp, bus, mbox))
4134 isp_async(isp, ISPASYNC_BUS_RESET, &bus);
4136 case ASYNC_SYSTEM_ERROR:
4137 isp->isp_state = ISP_CRASHED;
4139 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4140 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4143 * Were we waiting for a mailbox command to complete?
4144 * If so, it's dead, so wake up the waiter.
4146 if (isp->isp_mboxbsy) {
4148 isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR;
4149 MBOX_NOTIFY_COMPLETE(isp);
4151 #ifdef ISP_FW_CRASH_DUMP
4153 * If we have crash dumps enabled, it's up to the handler
4154 * for isp_async to reinit stuff and restart the firmware
4155 * after performing the crash dump. The reason we do things
4156 * this way is that we may need to activate a kernel thread
4157 * to do all the crash dump goop.
4159 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4161 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4163 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4168 case ASYNC_RQS_XFER_ERR:
4169 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
4172 case ASYNC_RSP_XFER_ERR:
4173 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
4178 * We've just been notified that the Queue has woken up.
4179 * We don't need to be chatty about this- just unlatch things
4182 mbox = READ_REQUEST_QUEUE_OUT_POINTER(isp);
4185 case ASYNC_TIMEOUT_RESET:
4186 isp_prt(isp, ISP_LOGWARN,
4187 "timeout initiated SCSI bus reset of bus %d", bus);
4188 isp->isp_sendmarker |= (1 << bus);
4189 #ifdef ISP_TARGET_MODE
4190 if (isp_target_async(isp, bus, mbox))
4195 case ASYNC_DEVICE_RESET:
4196 isp_prt(isp, ISP_LOGINFO, "device reset on bus %d", bus);
4197 isp->isp_sendmarker |= (1 << bus);
4198 #ifdef ISP_TARGET_MODE
4199 if (isp_target_async(isp, bus, mbox))
4204 case ASYNC_EXTMSG_UNDERRUN:
4205 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
4208 case ASYNC_SCAM_INT:
4209 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
4212 case ASYNC_HUNG_SCSI:
4213 isp_prt(isp, ISP_LOGERR,
4214 "stalled SCSI Bus after DATA Overrun");
4215 /* XXX: Need to issue SCSI reset at this point */
4218 case ASYNC_KILLED_BUS:
4219 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
4222 case ASYNC_BUS_TRANSIT:
4223 mbox = ISP_READ(isp, OUTMAILBOX2);
4224 switch (mbox & 0x1c00) {
4225 case SXP_PINS_LVD_MODE:
4226 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
4227 SDPARAM(isp)->isp_diffmode = 0;
4228 SDPARAM(isp)->isp_ultramode = 0;
4229 SDPARAM(isp)->isp_lvdmode = 1;
4231 case SXP_PINS_HVD_MODE:
4232 isp_prt(isp, ISP_LOGINFO,
4233 "Transition to Differential mode");
4234 SDPARAM(isp)->isp_diffmode = 1;
4235 SDPARAM(isp)->isp_ultramode = 0;
4236 SDPARAM(isp)->isp_lvdmode = 0;
4238 case SXP_PINS_SE_MODE:
4239 isp_prt(isp, ISP_LOGINFO,
4240 "Transition to Single Ended mode");
4241 SDPARAM(isp)->isp_diffmode = 0;
4242 SDPARAM(isp)->isp_ultramode = 1;
4243 SDPARAM(isp)->isp_lvdmode = 0;
4246 isp_prt(isp, ISP_LOGWARN,
4247 "Transition to Unknown Mode 0x%x", mbox);
4251 * XXX: Set up to renegotiate again!
4253 /* Can only be for a 1080... */
4254 isp->isp_sendmarker |= (1 << bus);
4258 * We can use bus, which will always be zero for FC cards,
4259 * as a mailbox pattern accumulator to be checked below.
4262 bus = 0x1ce; /* outgoing mailbox regs 1-3, 6-7 */
4266 bus = 0x14e; /* outgoing mailbox regs 1-3, 6 */
4270 bus = 0x10e; /* outgoing mailbox regs 1-3 */
4274 bus = 0x106; /* outgoing mailbox regs 1-2 */
4278 case ASYNC_CMD_CMPLT:
4279 bus = 0x102; /* outgoing mailbox regs 1 */
4282 case ASYNC_RIO_RESP:
4285 case ASYNC_CTIO_DONE:
4287 #ifdef ISP_TARGET_MODE
4289 (ISP_READ(isp, OUTMAILBOX2) << 16) |
4290 (ISP_READ(isp, OUTMAILBOX1));
4291 if (isp_target_async(isp, handle, mbox)) {
4294 /* count it as a fast posting intr */
4295 isp->isp_fphccmplt++;
4298 isp_prt(isp, ISP_LOGINFO, "Fast Posting CTIO done");
4299 isp->isp_fphccmplt++; /* count it as a fast posting intr */
4304 case ASYNC_LIP_OCCURRED:
4305 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4306 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4307 isp->isp_sendmarker = 1;
4308 isp_mark_getpdb_all(isp);
4309 isp_async(isp, ISPASYNC_LIP, NULL);
4310 #ifdef ISP_TARGET_MODE
4311 if (isp_target_async(isp, bus, mbox))
4315 * We've had problems with data corruption occuring on
4316 * commands that complete (with no apparent error) after
4317 * we receive a LIP. This has been observed mostly on
4318 * Local Loop topologies. To be safe, let's just mark
4319 * all active commands as dead.
4321 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4322 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4324 for (i = j = 0; i < isp->isp_maxcmds; i++) {
4326 xs = isp->isp_xflist[i];
4329 XS_SETERR(xs, HBA_BUSRESET);
4333 isp_prt(isp, ISP_LOGERR,
4334 "LIP destroyed %d active commands", j);
4340 isp->isp_sendmarker = 1;
4341 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4342 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4343 isp_mark_getpdb_all(isp);
4344 isp_async(isp, ISPASYNC_LOOP_UP, NULL);
4345 #ifdef ISP_TARGET_MODE
4346 if (isp_target_async(isp, bus, mbox)) {
4352 case ASYNC_LOOP_DOWN:
4353 isp->isp_sendmarker = 1;
4354 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4355 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4356 isp_mark_getpdb_all(isp);
4357 isp_async(isp, ISPASYNC_LOOP_DOWN, NULL);
4358 #ifdef ISP_TARGET_MODE
4359 if (isp_target_async(isp, bus, mbox)) {
4365 case ASYNC_LOOP_RESET:
4366 isp->isp_sendmarker = 1;
4367 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4368 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
4369 isp_mark_getpdb_all(isp);
4370 isp_async(isp, ISPASYNC_LOOP_RESET, NULL);
4371 #ifdef ISP_TARGET_MODE
4372 if (isp_target_async(isp, bus, mbox)) {
4378 case ASYNC_PDB_CHANGED:
4379 isp->isp_sendmarker = 1;
4380 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4381 isp_mark_getpdb_all(isp);
4382 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_PDB);
4385 case ASYNC_CHANGE_NOTIFY:
4387 * Not correct, but it will force us to rescan the loop.
4389 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4390 isp_mark_getpdb_all(isp);
4391 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_SNS);
4395 if (FCPARAM(isp)->isp_onfabric)
4396 FCPARAM(isp)->isp_topo = TOPO_F_PORT;
4398 FCPARAM(isp)->isp_topo = TOPO_N_PORT;
4399 isp_mark_getpdb_all(isp);
4400 isp->isp_sendmarker = 1;
4401 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4402 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4403 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4404 #ifdef ISP_TARGET_MODE
4405 if (isp_target_async(isp, bus, mbox))
4408 isp_prt(isp, ISP_LOGINFO, "Point-to-Point mode");
4411 case ASYNC_CONNMODE:
4412 mbox = ISP_READ(isp, OUTMAILBOX1);
4413 isp_mark_getpdb_all(isp);
4416 isp_prt(isp, ISP_LOGINFO,
4417 "Point-to-Point -> Loop mode");
4420 isp_prt(isp, ISP_LOGINFO,
4421 "Loop -> Point-to-Point mode");
4423 case ISP_CONN_BADLIP:
4424 isp_prt(isp, ISP_LOGWARN,
4425 "Point-to-Point -> Loop mode (BAD LIP)");
4427 case ISP_CONN_FATAL:
4428 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
4429 #ifdef ISP_FW_CRASH_DUMP
4430 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4432 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
4434 isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
4437 case ISP_CONN_LOOPBACK:
4438 isp_prt(isp, ISP_LOGWARN,
4439 "Looped Back in Point-to-Point mode");
4442 isp_prt(isp, ISP_LOGWARN,
4443 "Unknown connection mode (0x%x)", mbox);
4446 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4447 isp->isp_sendmarker = 1;
4448 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
4449 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
4453 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
4459 uint16_t handles[16];
4461 for (nh = 0, i = 1; i < MAX_MAILBOX(isp); i++) {
4462 if ((bus & (1 << i)) == 0) {
4465 handles[nh++] = ISP_READ(isp, MBOX_OFF(i));
4467 for (i = 0; i < nh; i++) {
4468 isp_fastpost_complete(isp, handles[i]);
4469 isp_prt(isp, ISP_LOGDEBUG3,
4470 "fast post completion of %u", handles[i]);
4472 if (isp->isp_fpcchiwater < nh)
4473 isp->isp_fpcchiwater = nh;
4475 isp->isp_intoasync++;
4481 * Handle other response entries. A pointer to the request queue output
4482 * index is here in case we want to eat several entries at once, although
4483 * this is not used currently.
4487 isp_handle_other_response(ispsoftc_t *isp, int type,
4488 isphdr_t *hp, uint16_t *optrp)
4491 case RQSTYPE_STATUS_CONT:
4492 isp_prt(isp, ISP_LOGINFO, "Ignored Continuation Response");
4496 case RQSTYPE_ENABLE_LUN:
4497 case RQSTYPE_MODIFY_LUN:
4498 case RQSTYPE_NOTIFY:
4499 case RQSTYPE_NOTIFY_ACK:
4504 isp->isp_rsltccmplt++; /* count as a response completion */
4505 #ifdef ISP_TARGET_MODE
4506 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
4511 case RQSTYPE_REQUEST:
4514 if (type != isp_get_response_type(isp, hp)) {
4516 * This is questionable- we're just papering over
4517 * something we've seen on SMP linux in target
4518 * mode- we don't really know what's happening
4519 * here that causes us to think we've gotten
4520 * an entry, but that either the entry isn't
4521 * filled out yet or our CPU read data is stale.
4523 isp_prt(isp, ISP_LOGINFO,
4524 "unstable type in response queue");
4527 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
4528 isp_get_response_type(isp, hp));
4529 if (isp_async(isp, ISPASYNC_UNHANDLED_RESPONSE, hp)) {
4537 isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs)
4539 switch (sp->req_completion_status & 0xff) {
4542 XS_SETERR(xs, HBA_NOERROR);
4546 case RQCS_INCOMPLETE:
4547 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
4548 isp_prt(isp, ISP_LOGDEBUG1,
4549 "Selection Timeout for %d.%d.%d",
4550 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4552 XS_SETERR(xs, HBA_SELTIMEOUT);
4556 isp_prt(isp, ISP_LOGERR,
4557 "command incomplete for %d.%d.%d, state 0x%x",
4558 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
4559 sp->req_state_flags);
4562 case RQCS_DMA_ERROR:
4563 isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
4564 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4567 case RQCS_TRANSPORT_ERROR:
4570 SNPRINTF(buf, sizeof (buf), "states=>");
4571 if (sp->req_state_flags & RQSF_GOT_BUS) {
4572 SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
4574 if (sp->req_state_flags & RQSF_GOT_TARGET) {
4575 SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
4577 if (sp->req_state_flags & RQSF_SENT_CDB) {
4578 SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
4580 if (sp->req_state_flags & RQSF_XFRD_DATA) {
4581 SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
4583 if (sp->req_state_flags & RQSF_GOT_STATUS) {
4584 SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
4586 if (sp->req_state_flags & RQSF_GOT_SENSE) {
4587 SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
4589 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
4590 SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
4592 SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
4593 if (sp->req_status_flags & RQSTF_DISCONNECT) {
4594 SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
4596 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
4597 SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
4599 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
4600 SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
4602 if (sp->req_status_flags & RQSTF_BUS_RESET) {
4603 SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
4605 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
4606 SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
4608 if (sp->req_status_flags & RQSTF_ABORTED) {
4609 SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
4611 if (sp->req_status_flags & RQSTF_TIMEOUT) {
4612 SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
4614 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
4615 SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
4617 isp_prt(isp, ISP_LOGERR, "%s", buf);
4618 isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d:\n%s",
4619 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), buf);
4622 case RQCS_RESET_OCCURRED:
4623 isp_prt(isp, ISP_LOGWARN,
4624 "bus reset destroyed command for %d.%d.%d",
4625 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4626 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4628 XS_SETERR(xs, HBA_BUSRESET);
4633 isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
4634 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4635 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4637 XS_SETERR(xs, HBA_ABORTED);
4642 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
4643 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4645 * Check to see if we logged out the device.
4648 if ((sp->req_completion_status & RQSTF_LOGOUT) &&
4649 FCPARAM(isp)->portdb[XS_TGT(xs)].valid &&
4650 FCPARAM(isp)->portdb[XS_TGT(xs)].fabric_dev) {
4651 FCPARAM(isp)->portdb[XS_TGT(xs)].relogin = 1;
4655 XS_SETERR(xs, HBA_CMDTIMEOUT);
4659 case RQCS_DATA_OVERRUN:
4660 XS_RESID(xs) = sp->req_resid;
4661 isp_prt(isp, ISP_LOGERR, "data overrun for command on %d.%d.%d",
4662 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4664 XS_SETERR(xs, HBA_DATAOVR);
4668 case RQCS_COMMAND_OVERRUN:
4669 isp_prt(isp, ISP_LOGERR,
4670 "command overrun for command on %d.%d.%d",
4671 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4674 case RQCS_STATUS_OVERRUN:
4675 isp_prt(isp, ISP_LOGERR,
4676 "status overrun for command on %d.%d.%d",
4677 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4680 case RQCS_BAD_MESSAGE:
4681 isp_prt(isp, ISP_LOGERR,
4682 "msg not COMMAND COMPLETE after status %d.%d.%d",
4683 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4686 case RQCS_NO_MESSAGE_OUT:
4687 isp_prt(isp, ISP_LOGERR,
4688 "No MESSAGE OUT phase after selection on %d.%d.%d",
4689 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4692 case RQCS_EXT_ID_FAILED:
4693 isp_prt(isp, ISP_LOGERR, "EXTENDED IDENTIFY failed %d.%d.%d",
4694 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4697 case RQCS_IDE_MSG_FAILED:
4698 isp_prt(isp, ISP_LOGERR,
4699 "INITIATOR DETECTED ERROR rejected by %d.%d.%d",
4700 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4703 case RQCS_ABORT_MSG_FAILED:
4704 isp_prt(isp, ISP_LOGERR, "ABORT OPERATION rejected by %d.%d.%d",
4705 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4708 case RQCS_REJECT_MSG_FAILED:
4709 isp_prt(isp, ISP_LOGERR, "MESSAGE REJECT rejected by %d.%d.%d",
4710 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4713 case RQCS_NOP_MSG_FAILED:
4714 isp_prt(isp, ISP_LOGERR, "NOP rejected by %d.%d.%d",
4715 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4718 case RQCS_PARITY_ERROR_MSG_FAILED:
4719 isp_prt(isp, ISP_LOGERR,
4720 "MESSAGE PARITY ERROR rejected by %d.%d.%d",
4721 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4724 case RQCS_DEVICE_RESET_MSG_FAILED:
4725 isp_prt(isp, ISP_LOGWARN,
4726 "BUS DEVICE RESET rejected by %d.%d.%d",
4727 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4730 case RQCS_ID_MSG_FAILED:
4731 isp_prt(isp, ISP_LOGERR, "IDENTIFY rejected by %d.%d.%d",
4732 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4735 case RQCS_UNEXP_BUS_FREE:
4736 isp_prt(isp, ISP_LOGERR, "%d.%d.%d had an unexpected bus free",
4737 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4740 case RQCS_DATA_UNDERRUN:
4743 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
4744 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
4745 isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
4746 XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
4747 (ru_marked)? "marked" : "not marked");
4749 XS_SETERR(xs, HBA_BOTCH);
4754 XS_RESID(xs) = sp->req_resid;
4756 XS_SETERR(xs, HBA_NOERROR);
4761 case RQCS_XACT_ERR1:
4762 isp_prt(isp, ISP_LOGERR, xact1, XS_CHANNEL(xs),
4763 XS_TGT(xs), XS_LUN(xs));
4766 case RQCS_XACT_ERR2:
4767 isp_prt(isp, ISP_LOGERR, xact2,
4768 XS_LUN(xs), XS_TGT(xs), XS_CHANNEL(xs));
4771 case RQCS_XACT_ERR3:
4772 isp_prt(isp, ISP_LOGERR, xact3,
4773 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4776 case RQCS_BAD_ENTRY:
4777 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
4780 case RQCS_QUEUE_FULL:
4781 isp_prt(isp, ISP_LOGDEBUG0,
4782 "internal queues full for %d.%d.%d status 0x%x",
4783 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), *XS_STSP(xs));
4786 * If QFULL or some other status byte is set, then this
4787 * isn't an error, per se.
4789 * Unfortunately, some QLogic f/w writers have, in
4790 * some cases, ommitted to *set* status to QFULL.
4793 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
4794 XS_SETERR(xs, HBA_NOERROR);
4802 *XS_STSP(xs) = SCSI_QFULL;
4803 XS_SETERR(xs, HBA_NOERROR);
4806 case RQCS_PHASE_SKIPPED:
4807 isp_prt(isp, ISP_LOGERR, pskip, XS_CHANNEL(xs),
4808 XS_TGT(xs), XS_LUN(xs));
4811 case RQCS_ARQS_FAILED:
4812 isp_prt(isp, ISP_LOGERR,
4813 "Auto Request Sense failed for %d.%d.%d",
4814 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
4816 XS_SETERR(xs, HBA_ARQFAIL);
4820 case RQCS_WIDE_FAILED:
4821 isp_prt(isp, ISP_LOGERR,
4822 "Wide Negotiation failed for %d.%d.%d",
4823 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4825 sdparam *sdp = isp->isp_param;
4826 sdp += XS_CHANNEL(xs);
4827 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
4828 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4829 isp->isp_update |= (1 << XS_CHANNEL(xs));
4832 XS_SETERR(xs, HBA_NOERROR);
4836 case RQCS_SYNCXFER_FAILED:
4837 isp_prt(isp, ISP_LOGERR,
4838 "SDTR Message failed for target %d.%d.%d",
4839 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4841 sdparam *sdp = isp->isp_param;
4842 sdp += XS_CHANNEL(xs);
4843 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
4844 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
4845 isp->isp_update |= (1 << XS_CHANNEL(xs));
4849 case RQCS_LVD_BUSERR:
4850 isp_prt(isp, ISP_LOGERR,
4851 "Bad LVD condition while talking to %d.%d.%d",
4852 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
4855 case RQCS_PORT_UNAVAILABLE:
4857 * No such port on the loop. Moral equivalent of SELTIMEO
4859 case RQCS_PORT_LOGGED_OUT:
4861 * It was there (maybe)- treat as a selection timeout.
4863 if ((sp->req_completion_status & 0xff) == RQCS_PORT_UNAVAILABLE)
4864 isp_prt(isp, ISP_LOGINFO,
4865 "port unavailable for target %d", XS_TGT(xs));
4867 isp_prt(isp, ISP_LOGINFO,
4868 "port logout for target %d", XS_TGT(xs));
4870 * If we're on a local loop, force a LIP (which is overkill)
4871 * to force a re-login of this unit. If we're on fabric,
4872 * then we'll have to relogin as a matter of course.
4874 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
4875 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
4877 MEMZERO(&mbs, sizeof (mbs));
4878 mbs.param[0] = MBOX_INIT_LIP;
4879 if (IS_2KLOGIN(isp)) {
4880 mbs.ibits |= (1 << 10);
4882 isp_mboxcmd_qnw(isp, &mbs, 1);
4886 * Probably overkill.
4888 isp->isp_sendmarker = 1;
4889 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
4890 isp_mark_getpdb_all(isp);
4891 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
4893 XS_SETERR(xs, HBA_SELTIMEOUT);
4897 case RQCS_PORT_CHANGED:
4898 isp_prt(isp, ISP_LOGWARN,
4899 "port changed for target %d", XS_TGT(xs));
4901 XS_SETERR(xs, HBA_SELTIMEOUT);
4905 case RQCS_PORT_BUSY:
4906 isp_prt(isp, ISP_LOGWARN,
4907 "port busy for target %d", XS_TGT(xs));
4909 XS_SETERR(xs, HBA_TGTBSY);
4914 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x",
4915 sp->req_completion_status);
4919 XS_SETERR(xs, HBA_BOTCH);
4924 isp_fastpost_complete(ispsoftc_t *isp, uint16_t fph)
4931 xs = isp_find_xs(isp, fph);
4933 isp_prt(isp, ISP_LOGWARN,
4934 "Command for fast post handle 0x%x not found", fph);
4937 isp_destroy_handle(isp, fph);
4940 * Since we don't have a result queue entry item,
4941 * we must believe that SCSI status is zero and
4942 * that all data transferred.
4944 XS_SET_STATE_STAT(isp, xs, NULL);
4946 *XS_STSP(xs) = SCSI_GOOD;
4947 if (XS_XFRLEN(xs)) {
4948 ISP_DMAFREE(isp, xs, fph);
4950 if (isp->isp_nactive)
4952 isp->isp_fphccmplt++;
4957 isp_mbox_continue(ispsoftc_t *isp)
4963 switch (isp->isp_lastmbxcmd) {
4964 case MBOX_WRITE_RAM_WORD:
4965 case MBOX_READ_RAM_WORD:
4966 case MBOX_WRITE_RAM_WORD_EXTENDED:
4967 case MBOX_READ_RAM_WORD_EXTENDED:
4972 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
4973 isp->isp_mbxwrk0 = 0;
4978 * Clear the previous interrupt.
4980 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
4981 ISP_WRITE(isp, BIU_SEMA, 0);
4984 * Continue with next word.
4986 MEMZERO(&mbs, sizeof (mbs));
4987 ptr = isp->isp_mbxworkp;
4988 switch (isp->isp_lastmbxcmd) {
4989 case MBOX_WRITE_RAM_WORD:
4990 mbs.param[1] = isp->isp_mbxwrk1++;;
4991 mbs.param[2] = *ptr++;;
4993 case MBOX_READ_RAM_WORD:
4994 *ptr++ = isp->isp_mboxtmp[2];
4995 mbs.param[1] = isp->isp_mbxwrk1++;
4997 case MBOX_WRITE_RAM_WORD_EXTENDED:
4998 offset = isp->isp_mbxwrk1;
4999 offset |= ((uint32_t) isp->isp_mbxwrk8 << 16);
5001 mbs.param[2] = *ptr++;;
5002 mbs.param[1] = offset;
5003 mbs.param[8] = offset >> 16;
5004 isp->isp_mbxwrk1 = ++offset;
5005 isp->isp_mbxwrk8 = offset >> 16;
5007 case MBOX_READ_RAM_WORD_EXTENDED:
5008 offset = isp->isp_mbxwrk1;
5009 offset |= ((uint32_t) isp->isp_mbxwrk8 << 16);
5011 *ptr++ = isp->isp_mboxtmp[2];
5012 mbs.param[1] = offset;
5013 mbs.param[8] = offset >> 16;
5014 isp->isp_mbxwrk1 = ++offset;
5015 isp->isp_mbxwrk8 = offset >> 16;
5018 isp->isp_mbxworkp = ptr;
5020 mbs.param[0] = isp->isp_lastmbxcmd;
5021 isp_mboxcmd_qnw(isp, &mbs, 0);
5026 #define HIWRD(x) ((x) >> 16)
5027 #define LOWRD(x) ((x) & 0xffff)
5028 #define ISPOPMAP(a, b) (((a) << 16) | (b))
5029 static const uint32_t mbpscsi[] = {
5030 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
5031 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
5032 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
5033 ISPOPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
5034 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
5035 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
5036 ISPOPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
5037 ISPOPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
5038 ISPOPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
5039 ISPOPMAP(0x00, 0x00), /* 0x09: */
5040 ISPOPMAP(0x00, 0x00), /* 0x0a: */
5041 ISPOPMAP(0x00, 0x00), /* 0x0b: */
5042 ISPOPMAP(0x00, 0x00), /* 0x0c: */
5043 ISPOPMAP(0x00, 0x00), /* 0x0d: */
5044 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
5045 ISPOPMAP(0x00, 0x00), /* 0x0f: */
5046 ISPOPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
5047 ISPOPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
5048 ISPOPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
5049 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
5050 ISPOPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
5051 ISPOPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
5052 ISPOPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
5053 ISPOPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
5054 ISPOPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
5055 ISPOPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
5056 ISPOPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
5057 ISPOPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
5058 ISPOPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
5059 ISPOPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
5060 ISPOPMAP(0x00, 0x00), /* 0x1e: */
5061 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
5062 ISPOPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
5063 ISPOPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
5064 ISPOPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
5065 ISPOPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
5066 ISPOPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
5067 ISPOPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
5068 ISPOPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
5069 ISPOPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
5070 ISPOPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
5071 ISPOPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
5072 ISPOPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
5073 ISPOPMAP(0x00, 0x00), /* 0x2b: */
5074 ISPOPMAP(0x00, 0x00), /* 0x2c: */
5075 ISPOPMAP(0x00, 0x00), /* 0x2d: */
5076 ISPOPMAP(0x00, 0x00), /* 0x2e: */
5077 ISPOPMAP(0x00, 0x00), /* 0x2f: */
5078 ISPOPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
5079 ISPOPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
5080 ISPOPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
5081 ISPOPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
5082 ISPOPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
5083 ISPOPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
5084 ISPOPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
5085 ISPOPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
5086 ISPOPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
5087 ISPOPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
5088 ISPOPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
5089 ISPOPMAP(0x00, 0x00), /* 0x3b: */
5090 ISPOPMAP(0x00, 0x00), /* 0x3c: */
5091 ISPOPMAP(0x00, 0x00), /* 0x3d: */
5092 ISPOPMAP(0x00, 0x00), /* 0x3e: */
5093 ISPOPMAP(0x00, 0x00), /* 0x3f: */
5094 ISPOPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
5095 ISPOPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
5096 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
5097 ISPOPMAP(0x00, 0x00), /* 0x43: */
5098 ISPOPMAP(0x00, 0x00), /* 0x44: */
5099 ISPOPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
5100 ISPOPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
5101 ISPOPMAP(0x00, 0x00), /* 0x47: */
5102 ISPOPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
5103 ISPOPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
5104 ISPOPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
5105 ISPOPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
5106 ISPOPMAP(0x00, 0x00), /* 0x4c: */
5107 ISPOPMAP(0x00, 0x00), /* 0x4d: */
5108 ISPOPMAP(0x00, 0x00), /* 0x4e: */
5109 ISPOPMAP(0x00, 0x00), /* 0x4f: */
5110 ISPOPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
5111 ISPOPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
5112 ISPOPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
5113 ISPOPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
5114 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
5115 ISPOPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
5116 ISPOPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
5117 ISPOPMAP(0x00, 0x00), /* 0x57: */
5118 ISPOPMAP(0x00, 0x00), /* 0x58: */
5119 ISPOPMAP(0x00, 0x00), /* 0x59: */
5120 ISPOPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
5121 ISPOPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
5122 ISPOPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
5123 ISPOPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
5126 #ifndef ISP_STRIPPED
5127 static char *scsi_mbcmd_names[] = {
5144 "INIT REQUEST QUEUE",
5145 "INIT RESULT QUEUE",
5155 "SINGLE STEP QUEUE",
5157 "GET DEV QUEUE STATUS",
5159 "GET FIRMWARE STATUS",
5161 "GET SELECT TIMEOUT",
5163 "GET TAG AGE LIMIT",
5165 "GET ACT NEG STATE",
5166 "GET ASYNC DATA SETUP TIME",
5168 "GET TARGET PARAMS",
5169 "GET DEV QUEUE PARAMS",
5170 "GET RESET DELAY PARAMS",
5177 "SET SELECT TIMEOUT",
5179 "SET TAG AGE LIMIT",
5181 "SET ACT NEG STATE",
5182 "SET ASYNC DATA SETUP TIME",
5183 "SET PCI CONTROL PARAMS",
5184 "SET TARGET PARAMS",
5185 "SET DEV QUEUE PARAMS",
5186 "SET RESET DELAY PARAMS",
5192 "RETURN BIOS BLOCK ADDR",
5193 "WRITE FOUR RAM WORDS",
5197 "SET SYSTEM PARAMETER",
5198 "GET SYSTEM PARAMETER",
5200 "GET SCAM CONFIGURATION",
5201 "SET SCAM CONFIGURATION",
5202 "SET FIRMWARE FEATURES",
5203 "GET FIRMWARE FEATURES",
5210 "INITIALIZE REQUEST QUEUE A64",
5211 "INITIALIZE RESPONSE QUEUE A64",
5213 "ENABLE TARGET MODE",
5214 "GET TARGET MODE STATE",
5218 "SET DATA OVERRUN RECOVERY MODE",
5219 "GET DATA OVERRUN RECOVERY MODE",
5225 static const uint32_t mbpfc[] = {
5226 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
5227 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
5228 ISPOPMAP(0x07, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
5229 ISPOPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
5230 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
5231 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
5232 ISPOPMAP(0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
5233 ISPOPMAP(0x03, 0x05), /* 0x07: MBOX_VERIFY_CHECKSUM */
5234 ISPOPMAP(0x01, 0x4f), /* 0x08: MBOX_ABOUT_FIRMWARE */
5235 ISPOPMAP(0xdf, 0x01), /* 0x09: LOAD RAM */
5236 ISPOPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
5237 ISPOPMAP(0x00, 0x00), /* 0x0b: */
5238 ISPOPMAP(0x00, 0x00), /* 0x0c: */
5239 ISPOPMAP(0x10f, 0x01), /* 0x0d: MBOX_WRITE_RAM_WORD_EXTENDED) */
5240 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
5241 ISPOPMAP(0x10f, 0x05), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED */
5242 ISPOPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
5243 ISPOPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
5244 ISPOPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
5245 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
5246 ISPOPMAP(0x01, 0xff), /* 0x14: MBOX_STOP_FIRMWARE */
5247 ISPOPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
5248 ISPOPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
5249 ISPOPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
5250 ISPOPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
5251 ISPOPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
5252 ISPOPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
5253 ISPOPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
5254 ISPOPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
5255 ISPOPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
5256 ISPOPMAP(0x00, 0x00), /* 0x1e: */
5257 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
5258 ISPOPMAP(0x01, 0x4f), /* 0x20: MBOX_GET_LOOP_ID */
5259 ISPOPMAP(0x00, 0x00), /* 0x21: */
5260 ISPOPMAP(0x01, 0x07), /* 0x22: MBOX_GET_RETRY_COUNT */
5261 ISPOPMAP(0x00, 0x00), /* 0x23: */
5262 ISPOPMAP(0x00, 0x00), /* 0x24: */
5263 ISPOPMAP(0x00, 0x00), /* 0x25: */
5264 ISPOPMAP(0x00, 0x00), /* 0x26: */
5265 ISPOPMAP(0x00, 0x00), /* 0x27: */
5266 ISPOPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
5267 ISPOPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
5268 ISPOPMAP(0x00, 0x00), /* 0x2a: */
5269 ISPOPMAP(0x00, 0x00), /* 0x2b: */
5270 ISPOPMAP(0x00, 0x00), /* 0x2c: */
5271 ISPOPMAP(0x00, 0x00), /* 0x2d: */
5272 ISPOPMAP(0x00, 0x00), /* 0x2e: */
5273 ISPOPMAP(0x00, 0x00), /* 0x2f: */
5274 ISPOPMAP(0x00, 0x00), /* 0x30: */
5275 ISPOPMAP(0x00, 0x00), /* 0x31: */
5276 ISPOPMAP(0x07, 0x07), /* 0x32: MBOX_SET_RETRY_COUNT */
5277 ISPOPMAP(0x00, 0x00), /* 0x33: */
5278 ISPOPMAP(0x00, 0x00), /* 0x34: */
5279 ISPOPMAP(0x00, 0x00), /* 0x35: */
5280 ISPOPMAP(0x00, 0x00), /* 0x36: */
5281 ISPOPMAP(0x00, 0x00), /* 0x37: */
5282 ISPOPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
5283 ISPOPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
5284 ISPOPMAP(0x00, 0x00), /* 0x3a: */
5285 ISPOPMAP(0x00, 0x00), /* 0x3b: */
5286 ISPOPMAP(0x00, 0x00), /* 0x3c: */
5287 ISPOPMAP(0x00, 0x00), /* 0x3d: */
5288 ISPOPMAP(0x00, 0x00), /* 0x3e: */
5289 ISPOPMAP(0x00, 0x00), /* 0x3f: */
5290 ISPOPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
5291 ISPOPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
5292 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_GET_RESOURCE_COUNTS */
5293 ISPOPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_NON_PARTICIPATING_MODE */
5294 ISPOPMAP(0x00, 0x00), /* 0x44: */
5295 ISPOPMAP(0x00, 0x00), /* 0x45: */
5296 ISPOPMAP(0x00, 0x00), /* 0x46: */
5297 ISPOPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
5298 ISPOPMAP(0x00, 0x00), /* 0x48: */
5299 ISPOPMAP(0x00, 0x00), /* 0x49: */
5300 ISPOPMAP(0x00, 0x00), /* 0x4a: */
5301 ISPOPMAP(0x00, 0x00), /* 0x4b: */
5302 ISPOPMAP(0x00, 0x00), /* 0x4c: */
5303 ISPOPMAP(0x00, 0x00), /* 0x4d: */
5304 ISPOPMAP(0x00, 0x00), /* 0x4e: */
5305 ISPOPMAP(0x00, 0x00), /* 0x4f: */
5306 ISPOPMAP(0x00, 0x00), /* 0x50: */
5307 ISPOPMAP(0x00, 0x00), /* 0x51: */
5308 ISPOPMAP(0x00, 0x00), /* 0x52: */
5309 ISPOPMAP(0x00, 0x00), /* 0x53: */
5310 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
5311 ISPOPMAP(0x00, 0x00), /* 0x55: */
5312 ISPOPMAP(0x00, 0x00), /* 0x56: */
5313 ISPOPMAP(0x00, 0x00), /* 0x57: */
5314 ISPOPMAP(0x00, 0x00), /* 0x58: */
5315 ISPOPMAP(0x00, 0x00), /* 0x59: */
5316 ISPOPMAP(0x00, 0x00), /* 0x5a: */
5317 ISPOPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
5318 ISPOPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
5319 ISPOPMAP(0x07, 0x03), /* 0x5d: MBOX_GET_SET_DATA_RATE */
5320 ISPOPMAP(0x00, 0x00), /* 0x5e: */
5321 ISPOPMAP(0x00, 0x00), /* 0x5f: */
5322 ISPOPMAP(0xcd, 0x31), /* 0x60: MBOX_INIT_FIRMWARE */
5323 ISPOPMAP(0x00, 0x00), /* 0x61: */
5324 ISPOPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
5325 ISPOPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
5326 ISPOPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
5327 ISPOPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
5328 ISPOPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
5329 ISPOPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
5330 ISPOPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
5331 ISPOPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
5332 ISPOPMAP(0x03, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
5333 ISPOPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
5334 ISPOPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
5335 ISPOPMAP(0x00, 0x00), /* 0x6d: */
5336 ISPOPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
5337 ISPOPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
5338 ISPOPMAP(0x03, 0x01), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
5339 ISPOPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
5340 ISPOPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
5341 ISPOPMAP(0x00, 0x00), /* 0x73: */
5342 ISPOPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
5343 ISPOPMAP(0xcf, 0x03), /* 0x75: GET PORT/NODE NAME LIST */
5344 ISPOPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
5345 ISPOPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
5346 ISPOPMAP(0x00, 0x00), /* 0x78: */
5347 ISPOPMAP(0x00, 0x00), /* 0x79: */
5348 ISPOPMAP(0x00, 0x00), /* 0x7a: */
5349 ISPOPMAP(0x00, 0x00), /* 0x7b: */
5350 ISPOPMAP(0x4f, 0x03), /* 0x7c: Get ID List */
5351 ISPOPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
5352 ISPOPMAP(0x0f, 0x01) /* 0x7e: LUN RESET */
5357 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
5358 * do not access at this time in the core driver. The caller is
5359 * responsible for setting this register first (Gross!). The assumption
5360 * is that we won't overflow.
5363 #ifndef ISP_STRIPPED
5364 static char *fc_mbcmd_names[] = {
5376 "WRITE RAM WORD EXTENDED",
5378 "READ RAM WORD EXTENDED",
5381 "INIT REQUEST QUEUE",
5382 "INIT RESULT QUEUE",
5392 "SINGLE STEP QUEUE",
5394 "GET DEV QUEUE STATUS",
5396 "GET FIRMWARE STATUS",
5405 "GET FIRMWARE OPTIONS",
5406 "GET PORT QUEUE PARAMS",
5421 "SET FIRMWARE OPTIONS",
5422 "SET PORT QUEUE PARAMS",
5431 "GET RESOURCE COUNTS",
5432 "REQUEST NON PARTICIPATING MODE",
5436 "GET PORT DATABASE ENHANCED",
5458 "GET/SET DATA RATE",
5464 "GET FC-AL POSITION MAP",
5465 "GET PORT DATABASE",
5477 "SEND CHANGE REQUEST",
5482 "GET PORT/NODE NAME LIST",
5484 "INITIALIZE IP MAILBOX",
5496 isp_mboxcmd_qnw(ispsoftc_t *isp, mbreg_t *mbp, int nodelay)
5498 unsigned int ibits, obits, box, opcode;
5499 const uint32_t *mcp;
5506 opcode = mbp->param[0];
5507 ibits = HIWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5508 obits = LOWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5509 ibits |= mbp->ibits;
5510 obits |= mbp->obits;
5511 for (box = 0; box < MAX_MAILBOX(isp); box++) {
5512 if (ibits & (1 << box)) {
5513 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5516 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5520 isp->isp_lastmbxcmd = opcode;
5521 isp->isp_obits = obits;
5522 isp->isp_mboxbsy = 1;
5524 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5526 * Oddly enough, if we're not delaying for an answer,
5527 * delay a bit to give the f/w a chance to pick up the
5536 isp_mboxcmd(ispsoftc_t *isp, mbreg_t *mbp, int logmask)
5538 char *cname, *xname, tname[16], mname[16];
5539 unsigned int lim, ibits, obits, box, opcode;
5540 const uint32_t *mcp;
5544 lim = (sizeof (mbpfc) / sizeof (mbpfc[0]));
5547 lim = (sizeof (mbpscsi) / sizeof (mbpscsi[0]));
5550 if ((opcode = mbp->param[0]) >= lim) {
5551 mbp->param[0] = MBOX_INVALID_COMMAND;
5552 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
5556 ibits = HIWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5557 obits = LOWRD(mcp[opcode]) & NMBOX_BMASK(isp);
5560 * Pick up any additional bits that the caller might have set.
5562 ibits |= mbp->ibits;
5563 obits |= mbp->obits;
5565 if (ibits == 0 && obits == 0) {
5566 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
5567 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
5572 * Get exclusive usage of mailbox registers.
5576 for (box = 0; box < MAX_MAILBOX(isp); box++) {
5577 if (ibits & (1 << box)) {
5578 isp_prt(isp, ISP_LOGDEBUG1, "IN mbox %d = 0x%x", box,
5580 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
5582 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
5585 isp->isp_lastmbxcmd = opcode;
5588 * We assume that we can't overwrite a previous command.
5590 isp->isp_obits = obits;
5591 isp->isp_mboxbsy = 1;
5594 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
5596 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
5599 * While we haven't finished the command, spin our wheels here.
5601 MBOX_WAIT_COMPLETE(isp);
5604 * Did the command time out?
5606 if (isp->isp_mboxbsy) {
5607 isp->isp_mboxbsy = 0;
5613 * Copy back output registers.
5615 for (box = 0; box < MAX_MAILBOX(isp); box++) {
5616 if (obits & (1 << box)) {
5617 mbp->param[box] = isp->isp_mboxtmp[box];
5618 isp_prt(isp, ISP_LOGDEBUG1, "OUT mbox %d = 0x%x", box,
5625 if (logmask == 0 || opcode == MBOX_EXEC_FIRMWARE) {
5631 cname = (IS_FC(isp))? fc_mbcmd_names[opcode] : scsi_mbcmd_names[opcode];
5633 if (cname == NULL) {
5635 SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
5639 * Just to be chatty here...
5642 switch (mbp->param[0]) {
5643 case MBOX_COMMAND_COMPLETE:
5645 case MBOX_INVALID_COMMAND:
5646 if (logmask & MBLOGMASK(MBOX_COMMAND_COMPLETE)) {
5647 xname = "INVALID COMMAND";
5650 case MBOX_HOST_INTERFACE_ERROR:
5651 if (logmask & MBLOGMASK(MBOX_HOST_INTERFACE_ERROR)) {
5652 xname = "HOST INTERFACE ERROR";
5655 case MBOX_TEST_FAILED:
5656 if (logmask & MBLOGMASK(MBOX_TEST_FAILED)) {
5657 xname = "TEST FAILED";
5660 case MBOX_COMMAND_ERROR:
5661 if (logmask & MBLOGMASK(MBOX_COMMAND_ERROR)) {
5662 xname = "COMMAND ERROR";
5665 case MBOX_COMMAND_PARAM_ERROR:
5666 if (logmask & MBLOGMASK(MBOX_COMMAND_PARAM_ERROR)) {
5667 xname = "COMMAND PARAMETER ERROR";
5670 case MBOX_LOOP_ID_USED:
5671 if (logmask & MBLOGMASK(MBOX_LOOP_ID_USED)) {
5672 xname = "LOOP ID ALREADY IN USE";
5675 case MBOX_PORT_ID_USED:
5676 if (logmask & MBLOGMASK(MBOX_PORT_ID_USED)) {
5677 xname = "PORT ID ALREADY IN USE";
5680 case MBOX_ALL_IDS_USED:
5681 if (logmask & MBLOGMASK(MBOX_ALL_IDS_USED)) {
5682 xname = "ALL LOOP IDS IN USE";
5685 case 0: /* special case */
5689 SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
5694 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s)",
5700 isp_fw_state(ispsoftc_t *isp)
5704 fcparam *fcp = isp->isp_param;
5706 MEMZERO(&mbs, sizeof (mbs));
5707 mbs.param[0] = MBOX_GET_FW_STATE;
5708 isp_mboxcmd(isp, &mbs, MBLOGALL);
5709 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
5710 fcp->isp_fwstate = mbs.param[1];
5716 isp_update(ispsoftc_t *isp)
5720 for (bus = 0, upmask = isp->isp_update; upmask != 0; bus++) {
5721 if (upmask & (1 << bus)) {
5722 isp_update_bus(isp, bus);
5724 upmask &= ~(1 << bus);
5729 isp_update_bus(ispsoftc_t *isp, int bus)
5735 isp->isp_update &= ~(1 << bus);
5738 * There are no 'per-bus' settings for Fibre Channel.
5742 sdp = isp->isp_param;
5745 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5746 uint16_t flags, period, offset;
5749 if (sdp->isp_devparam[tgt].dev_enable == 0) {
5750 sdp->isp_devparam[tgt].dev_update = 0;
5751 sdp->isp_devparam[tgt].dev_refresh = 0;
5752 isp_prt(isp, ISP_LOGDEBUG0,
5753 "skipping target %d bus %d update", tgt, bus);
5757 * If the goal is to update the status of the device,
5758 * take what's in goal_flags and try and set the device
5759 * toward that. Otherwise, if we're just refreshing the
5760 * current device state, get the current parameters.
5763 MEMZERO(&mbs, sizeof (mbs));
5766 * Refresh overrides set
5768 if (sdp->isp_devparam[tgt].dev_refresh) {
5769 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
5770 sdp->isp_devparam[tgt].dev_refresh = 0;
5772 } else if (sdp->isp_devparam[tgt].dev_update) {
5773 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
5775 * Make sure goal_flags has "Renegotiate on Error"
5776 * on and "Freeze Queue on Error" off.
5778 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
5779 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
5781 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
5784 * Insist that PARITY must be enabled
5785 * if SYNC or WIDE is enabled.
5787 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
5788 mbs.param[2] |= DPARM_PARITY;
5791 if (mbs.param[2] & DPARM_SYNC) {
5793 (sdp->isp_devparam[tgt].goal_offset << 8) |
5794 (sdp->isp_devparam[tgt].goal_period);
5797 * A command completion later that has
5798 * RQSTF_NEGOTIATION set can cause
5799 * the dev_refresh/announce cycle also.
5801 * Note: It is really important to update our current
5802 * flags with at least the state of TAG capabilities-
5803 * otherwise we might try and send a tagged command
5804 * when we have it all turned off. So change it here
5805 * to say that current already matches goal.
5807 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
5808 sdp->isp_devparam[tgt].actv_flags |=
5809 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
5810 isp_prt(isp, ISP_LOGDEBUG0,
5811 "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
5812 bus, tgt, mbs.param[2], mbs.param[3] >> 8,
5813 mbs.param[3] & 0xff);
5814 sdp->isp_devparam[tgt].dev_update = 0;
5815 sdp->isp_devparam[tgt].dev_refresh = 1;
5820 mbs.param[1] = (bus << 15) | (tgt << 8);
5821 isp_mboxcmd(isp, &mbs, MBLOGALL);
5823 isp->isp_sendmarker |= (1 << bus);
5826 flags = mbs.param[2];
5827 period = mbs.param[3] & 0xff;
5828 offset = mbs.param[3] >> 8;
5829 sdp->isp_devparam[tgt].actv_flags = flags;
5830 sdp->isp_devparam[tgt].actv_period = period;
5831 sdp->isp_devparam[tgt].actv_offset = offset;
5832 get = (bus << 16) | tgt;
5833 (void) isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, &get);
5836 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5837 if (sdp->isp_devparam[tgt].dev_update ||
5838 sdp->isp_devparam[tgt].dev_refresh) {
5839 isp->isp_update |= (1 << bus);
5845 #ifndef DEFAULT_FRAMESIZE
5846 #define DEFAULT_FRAMESIZE(isp) ICB_DFLT_FRMLEN
5848 #ifndef DEFAULT_EXEC_THROTTLE
5849 #define DEFAULT_EXEC_THROTTLE(isp) ISP_EXEC_THROTTLE
5853 isp_setdfltparm(ispsoftc_t *isp, int channel)
5859 fcparam *fcp = (fcparam *) isp->isp_param;
5863 if (fcp->isp_gotdparms) {
5866 fcp->isp_gotdparms = 1;
5867 fcp->isp_maxfrmlen = DEFAULT_FRAMESIZE(isp);
5868 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
5869 fcp->isp_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
5870 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
5871 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
5872 /* Platform specific.... */
5873 fcp->isp_loopid = DEFAULT_LOOPID(isp);
5874 fcp->isp_nodewwn = DEFAULT_NODEWWN(isp);
5875 fcp->isp_portwwn = DEFAULT_PORTWWN(isp);
5876 fcp->isp_fwoptions = 0;
5877 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
5878 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
5879 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
5880 fcp->isp_fwoptions |= ICBOPT_FAST_POST;
5881 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
5882 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
5885 * Make sure this is turned off now until we get
5886 * extended options from NVRAM
5888 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
5891 * Now try and read NVRAM unless told to not do so.
5892 * This will set fcparam's isp_nodewwn && isp_portwwn.
5894 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5895 nvfail = isp_read_nvram(isp);
5897 isp->isp_confopts |= ISP_CFG_NONVRAM;
5903 * Set node && port to override platform set defaults
5904 * unless the nvram read failed (or none was done),
5905 * or the platform code wants to use what had been
5906 * set in the defaults.
5909 isp->isp_confopts |= ISP_CFG_OWNWWPN|ISP_CFG_OWNWWNN;
5911 if (isp->isp_confopts & ISP_CFG_OWNWWNN) {
5912 isp_prt(isp, ISP_LOGCONFIG, "Using Node WWN 0x%08x%08x",
5913 (uint32_t) (DEFAULT_NODEWWN(isp) >> 32),
5914 (uint32_t) (DEFAULT_NODEWWN(isp) & 0xffffffff));
5915 ISP_NODEWWN(isp) = DEFAULT_NODEWWN(isp);
5918 * We always start out with values derived
5919 * from NVRAM or our platform default.
5921 ISP_NODEWWN(isp) = fcp->isp_nodewwn;
5922 if (fcp->isp_nodewwn == 0) {
5923 isp_prt(isp, ISP_LOGCONFIG,
5924 "bad WWNN- using default\n");
5925 ISP_NODEWWN(isp) = DEFAULT_NODEWWN(isp);
5928 if (isp->isp_confopts & ISP_CFG_OWNWWPN) {
5929 isp_prt(isp, ISP_LOGCONFIG, "Using Port WWN 0x%08x%08x",
5930 (uint32_t) (DEFAULT_PORTWWN(isp) >> 32),
5931 (uint32_t) (DEFAULT_PORTWWN(isp) & 0xffffffff));
5932 ISP_PORTWWN(isp) = DEFAULT_PORTWWN(isp);
5935 * We always start out with values derived
5936 * from NVRAM or our platform default.
5938 ISP_PORTWWN(isp) = fcp->isp_portwwn;
5939 if (fcp->isp_portwwn == 0) {
5940 isp_prt(isp, ISP_LOGCONFIG,
5941 "bad WWPN- using default\n");
5942 ISP_PORTWWN(isp) = DEFAULT_PORTWWN(isp);
5948 sdp = (sdparam *) isp->isp_param;
5952 * Been there, done that, got the T-shirt...
5954 if (sdp->isp_gotdparms) {
5957 sdp->isp_gotdparms = 1;
5960 * Establish some default parameters.
5962 sdp->isp_cmd_dma_burst_enable = 0;
5963 sdp->isp_data_dma_burst_enabl = 1;
5964 sdp->isp_fifo_threshold = 0;
5965 sdp->isp_initiator_id = DEFAULT_IID(isp);
5966 if (isp->isp_type >= ISP_HA_SCSI_1040) {
5967 sdp->isp_async_data_setup = 9;
5969 sdp->isp_async_data_setup = 6;
5971 sdp->isp_selection_timeout = 250;
5972 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
5973 sdp->isp_tag_aging = 8;
5974 sdp->isp_bus_reset_delay = 5;
5976 * Don't retry selection, busy or queue full automatically- reflect
5979 sdp->isp_retry_count = 0;
5980 sdp->isp_retry_delay = 0;
5982 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
5983 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
5984 sdp->isp_devparam[tgt].dev_enable = 1;
5988 * If we've not been told to avoid reading NVRAM, try and read it.
5989 * If we're successful reading it, we can then return because NVRAM
5990 * will tell us what the desired settings are. Otherwise, we establish
5991 * some reasonable 'fake' nvram and goal defaults.
5994 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
5995 if (isp_read_nvram(isp) == 0) {
6001 * Now try and see whether we have specific values for them.
6003 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
6006 MEMZERO(&mbs, sizeof (mbs));
6007 mbs.param[0] = MBOX_GET_ACT_NEG_STATE;
6008 isp_mboxcmd(isp, &mbs, MBLOGNONE);
6009 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6010 sdp->isp_req_ack_active_neg = 1;
6011 sdp->isp_data_line_active_neg = 1;
6013 sdp->isp_req_ack_active_neg =
6014 (mbs.param[1+channel] >> 4) & 0x1;
6015 sdp->isp_data_line_active_neg =
6016 (mbs.param[1+channel] >> 5) & 0x1;
6020 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc3,
6021 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6022 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6023 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6024 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc3,
6025 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6026 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6027 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6030 * The trick here is to establish a default for the default (honk!)
6031 * state (goal_flags). Then try and get the current status from
6032 * the card to fill in the current state. We don't, in fact, set
6033 * the default to the SAFE default state- that's not the goal state.
6035 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6037 sdp->isp_devparam[tgt].actv_offset = 0;
6038 sdp->isp_devparam[tgt].actv_period = 0;
6039 sdp->isp_devparam[tgt].actv_flags = 0;
6041 sdp->isp_devparam[tgt].goal_flags =
6042 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
6045 * We default to Wide/Fast for versions less than a 1040
6046 * (unless it's SBus).
6048 if (IS_ULTRA3(isp)) {
6049 off = ISP_80M_SYNCPARMS >> 8;
6050 per = ISP_80M_SYNCPARMS & 0xff;
6051 } else if (IS_ULTRA2(isp)) {
6052 off = ISP_40M_SYNCPARMS >> 8;
6053 per = ISP_40M_SYNCPARMS & 0xff;
6054 } else if (IS_1240(isp)) {
6055 off = ISP_20M_SYNCPARMS >> 8;
6056 per = ISP_20M_SYNCPARMS & 0xff;
6057 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
6058 isp->isp_type < ISP_HA_SCSI_1020A) ||
6059 (isp->isp_bustype == ISP_BT_PCI &&
6060 isp->isp_type < ISP_HA_SCSI_1040) ||
6061 (isp->isp_clock && isp->isp_clock < 60) ||
6062 (sdp->isp_ultramode == 0)) {
6063 off = ISP_10M_SYNCPARMS >> 8;
6064 per = ISP_10M_SYNCPARMS & 0xff;
6066 off = ISP_20M_SYNCPARMS_1040 >> 8;
6067 per = ISP_20M_SYNCPARMS_1040 & 0xff;
6069 sdp->isp_devparam[tgt].goal_offset =
6070 sdp->isp_devparam[tgt].nvrm_offset = off;
6071 sdp->isp_devparam[tgt].goal_period =
6072 sdp->isp_devparam[tgt].nvrm_period = per;
6074 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc3,
6075 channel, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6076 sdp->isp_devparam[tgt].nvrm_offset,
6077 sdp->isp_devparam[tgt].nvrm_period);
6082 * Re-initialize the ISP and complete all orphaned commands
6083 * with a 'botched' notice. The reset/init routines should
6084 * not disturb an already active list of commands.
6086 * Locks held prior to coming here.
6090 isp_reinit(ispsoftc_t *isp)
6096 isp_mark_getpdb_all(isp);
6099 if (isp->isp_state != ISP_RESETSTATE) {
6100 isp_prt(isp, ISP_LOGERR, "isp_reinit cannot reset card");
6101 } else if (isp->isp_role != ISP_ROLE_NONE) {
6103 if (isp->isp_state == ISP_INITSTATE) {
6104 isp->isp_state = ISP_RUNSTATE;
6106 if (isp->isp_state != ISP_RUNSTATE) {
6107 isp_prt(isp, ISP_LOGERR,
6108 "isp_reinit cannot restart card");
6111 isp->isp_nactive = 0;
6113 for (i = 0; i < isp->isp_maxcmds; i++) {
6115 xs = isp->isp_xflist[i];
6119 handle = isp_index_handle(i);
6120 isp_destroy_handle(isp, handle);
6121 if (XS_XFRLEN(xs)) {
6122 ISP_DMAFREE(isp, xs, handle);
6123 XS_RESID(xs) = XS_XFRLEN(xs);
6127 XS_SETERR(xs, HBA_BUSRESET);
6136 isp_read_nvram(ispsoftc_t *isp)
6139 uint8_t csum, minversion;
6141 uint8_t _x[ISP2100_NVRAM_SIZE];
6142 uint16_t _s[ISP2100_NVRAM_SIZE>>1];
6144 #define nvram_data _n._x
6145 #define nvram_words _n._s
6148 amt = ISP2100_NVRAM_SIZE;
6150 } else if (IS_ULTRA2(isp)) {
6151 amt = ISP1080_NVRAM_SIZE;
6154 amt = ISP_NVRAM_SIZE;
6159 * Just read the first two words first to see if we have a valid
6160 * NVRAM to continue reading the rest with.
6162 for (i = 0; i < 2; i++) {
6163 isp_rdnvram_word(isp, i, &nvram_words[i]);
6165 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
6166 nvram_data[2] != 'P') {
6167 if (isp->isp_bustype != ISP_BT_SBUS) {
6168 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
6169 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x",
6170 nvram_data[0], nvram_data[1], nvram_data[2]);
6175 for (i = 2; i < amt>>1; i++) {
6176 isp_rdnvram_word(isp, i, &nvram_words[i]);
6178 for (csum = 0, i = 0; i < amt; i++) {
6179 csum += nvram_data[i];
6182 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
6186 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
6187 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
6188 ISP_NVRAM_VERSION(nvram_data));
6193 if (IS_ULTRA3(isp)) {
6194 isp_parse_nvram_12160(isp, 0, nvram_data);
6196 isp_parse_nvram_12160(isp, 1, nvram_data);
6197 } else if (IS_1080(isp)) {
6198 isp_parse_nvram_1080(isp, 0, nvram_data);
6199 } else if (IS_1280(isp) || IS_1240(isp)) {
6200 isp_parse_nvram_1080(isp, 0, nvram_data);
6201 isp_parse_nvram_1080(isp, 1, nvram_data);
6202 } else if (IS_SCSI(isp)) {
6203 isp_parse_nvram_1020(isp, nvram_data);
6205 isp_parse_nvram_2100(isp, nvram_data);
6215 isp_rdnvram_word(ispsoftc_t *isp, int wo, uint16_t *rp)
6218 uint16_t bit, rqst, junk;
6220 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
6222 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
6226 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
6227 if (IS_2312(isp) && isp->isp_port) {
6230 rqst = (ISP_NVRAM_READ << 8) | wo;
6232 } else if (IS_ULTRA2(isp)) {
6233 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
6234 rqst = (ISP_NVRAM_READ << 8) | wo;
6237 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
6238 rqst = (ISP_NVRAM_READ << 6) | wo;
6243 * Clock the word select request out...
6245 for (i = cbits; i >= 0; i--) {
6246 if ((rqst >> i) & 1) {
6247 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
6249 bit = BIU_NVRAM_SELECT;
6251 ISP_WRITE(isp, BIU_NVRAM, bit);
6253 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
6254 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
6256 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
6257 ISP_WRITE(isp, BIU_NVRAM, bit);
6259 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
6262 * Now read the result back in (bits come back in MSB format).
6265 for (i = 0; i < 16; i++) {
6268 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
6270 rv = ISP_READ(isp, BIU_NVRAM);
6271 if (rv & BIU_NVRAM_DATAIN) {
6275 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
6277 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
6279 ISP_WRITE(isp, BIU_NVRAM, 0);
6281 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
6282 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
6286 isp_parse_nvram_1020(ispsoftc_t *isp, uint8_t *nvram_data)
6288 sdparam *sdp = (sdparam *) isp->isp_param;
6291 sdp->isp_fifo_threshold =
6292 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
6293 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
6295 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6296 sdp->isp_initiator_id =
6297 ISP_NVRAM_INITIATOR_ID(nvram_data);
6299 sdp->isp_bus_reset_delay =
6300 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
6302 sdp->isp_retry_count =
6303 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
6305 sdp->isp_retry_delay =
6306 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
6308 sdp->isp_async_data_setup =
6309 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
6311 if (isp->isp_type >= ISP_HA_SCSI_1040) {
6312 if (sdp->isp_async_data_setup < 9) {
6313 sdp->isp_async_data_setup = 9;
6316 if (sdp->isp_async_data_setup != 6) {
6317 sdp->isp_async_data_setup = 6;
6321 sdp->isp_req_ack_active_neg =
6322 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
6324 sdp->isp_data_line_active_neg =
6325 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
6327 sdp->isp_data_dma_burst_enabl =
6328 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
6330 sdp->isp_cmd_dma_burst_enable =
6331 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
6333 sdp->isp_tag_aging =
6334 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
6336 sdp->isp_selection_timeout =
6337 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
6339 sdp->isp_max_queue_depth =
6340 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
6342 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
6344 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6345 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6346 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6347 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6348 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6349 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6350 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6351 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6353 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6354 sdp->isp_devparam[tgt].dev_enable =
6355 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
6356 sdp->isp_devparam[tgt].exc_throttle =
6357 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
6358 sdp->isp_devparam[tgt].nvrm_offset =
6359 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
6360 sdp->isp_devparam[tgt].nvrm_period =
6361 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
6363 * We probably shouldn't lie about this, but it
6364 * it makes it much safer if we limit NVRAM values
6367 if (isp->isp_type < ISP_HA_SCSI_1040) {
6369 * If we're not ultra, we can't possibly
6370 * be a shorter period than this.
6372 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
6373 sdp->isp_devparam[tgt].nvrm_period = 0x19;
6375 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
6376 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
6379 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
6380 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
6383 sdp->isp_devparam[tgt].nvrm_flags = 0;
6384 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
6385 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6386 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6387 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
6388 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6389 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
6390 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6391 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
6392 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6393 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
6394 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6395 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
6396 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6397 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
6398 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6399 0, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6400 sdp->isp_devparam[tgt].nvrm_offset,
6401 sdp->isp_devparam[tgt].nvrm_period);
6402 sdp->isp_devparam[tgt].goal_offset =
6403 sdp->isp_devparam[tgt].nvrm_offset;
6404 sdp->isp_devparam[tgt].goal_period =
6405 sdp->isp_devparam[tgt].nvrm_period;
6406 sdp->isp_devparam[tgt].goal_flags =
6407 sdp->isp_devparam[tgt].nvrm_flags;
6412 isp_parse_nvram_1080(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
6414 sdparam *sdp = (sdparam *) isp->isp_param;
6419 sdp->isp_fifo_threshold =
6420 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
6422 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6423 sdp->isp_initiator_id =
6424 ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
6426 sdp->isp_bus_reset_delay =
6427 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6429 sdp->isp_retry_count =
6430 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6432 sdp->isp_retry_delay =
6433 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6435 sdp->isp_async_data_setup =
6436 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6438 sdp->isp_req_ack_active_neg =
6439 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6441 sdp->isp_data_line_active_neg =
6442 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6444 sdp->isp_data_dma_burst_enabl =
6445 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6447 sdp->isp_cmd_dma_burst_enable =
6448 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
6450 sdp->isp_selection_timeout =
6451 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6453 sdp->isp_max_queue_depth =
6454 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6456 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6457 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6458 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6459 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6460 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6461 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6462 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6463 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6466 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6467 sdp->isp_devparam[tgt].dev_enable =
6468 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6469 sdp->isp_devparam[tgt].exc_throttle =
6470 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6471 sdp->isp_devparam[tgt].nvrm_offset =
6472 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6473 sdp->isp_devparam[tgt].nvrm_period =
6474 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6475 sdp->isp_devparam[tgt].nvrm_flags = 0;
6476 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6477 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6478 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6479 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6480 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6481 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6482 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6483 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6484 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6485 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6486 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6487 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6488 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6489 sdp->isp_devparam[tgt].actv_flags = 0;
6490 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6491 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6492 sdp->isp_devparam[tgt].nvrm_offset,
6493 sdp->isp_devparam[tgt].nvrm_period);
6494 sdp->isp_devparam[tgt].goal_offset =
6495 sdp->isp_devparam[tgt].nvrm_offset;
6496 sdp->isp_devparam[tgt].goal_period =
6497 sdp->isp_devparam[tgt].nvrm_period;
6498 sdp->isp_devparam[tgt].goal_flags =
6499 sdp->isp_devparam[tgt].nvrm_flags;
6504 isp_parse_nvram_12160(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
6506 sdparam *sdp = (sdparam *) isp->isp_param;
6511 sdp->isp_fifo_threshold =
6512 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
6514 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6515 sdp->isp_initiator_id =
6516 ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
6518 sdp->isp_bus_reset_delay =
6519 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
6521 sdp->isp_retry_count =
6522 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
6524 sdp->isp_retry_delay =
6525 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
6527 sdp->isp_async_data_setup =
6528 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
6530 sdp->isp_req_ack_active_neg =
6531 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
6533 sdp->isp_data_line_active_neg =
6534 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
6536 sdp->isp_data_dma_burst_enabl =
6537 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6539 sdp->isp_cmd_dma_burst_enable =
6540 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
6542 sdp->isp_selection_timeout =
6543 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
6545 sdp->isp_max_queue_depth =
6546 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
6548 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
6549 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
6550 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
6551 sdp->isp_retry_delay, sdp->isp_async_data_setup);
6552 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
6553 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
6554 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
6555 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
6557 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6558 sdp->isp_devparam[tgt].dev_enable =
6559 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
6560 sdp->isp_devparam[tgt].exc_throttle =
6561 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
6562 sdp->isp_devparam[tgt].nvrm_offset =
6563 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
6564 sdp->isp_devparam[tgt].nvrm_period =
6565 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
6566 sdp->isp_devparam[tgt].nvrm_flags = 0;
6567 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
6568 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
6569 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
6570 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
6571 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
6572 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
6573 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
6574 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
6575 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
6576 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
6577 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
6578 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
6579 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
6580 sdp->isp_devparam[tgt].actv_flags = 0;
6581 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
6582 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
6583 sdp->isp_devparam[tgt].nvrm_offset,
6584 sdp->isp_devparam[tgt].nvrm_period);
6585 sdp->isp_devparam[tgt].goal_offset =
6586 sdp->isp_devparam[tgt].nvrm_offset;
6587 sdp->isp_devparam[tgt].goal_period =
6588 sdp->isp_devparam[tgt].nvrm_period;
6589 sdp->isp_devparam[tgt].goal_flags =
6590 sdp->isp_devparam[tgt].nvrm_flags;
6595 isp_parse_nvram_2100(ispsoftc_t *isp, uint8_t *nvram_data)
6597 fcparam *fcp = (fcparam *) isp->isp_param;
6601 * There is NVRAM storage for both Port and Node entities-
6602 * but the Node entity appears to be unused on all the cards
6603 * I can find. However, we should account for this being set
6604 * at some point in the future.
6606 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
6607 * bits 48..60. In the case of the 2202, it appears that they do
6608 * use bit 48 to distinguish between the two instances on the card.
6609 * The 2204, which I've never seen, *probably* extends this method.
6611 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
6613 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
6614 (uint32_t) (wwn >> 32), (uint32_t) (wwn & 0xffffffff));
6615 if ((wwn >> 60) == 0) {
6616 wwn |= (((uint64_t) 2)<< 60);
6619 fcp->isp_portwwn = wwn;
6620 if (IS_2200(isp) || IS_23XX(isp)) {
6621 wwn = ISP2100_NVRAM_NODE_NAME(nvram_data);
6623 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
6624 (uint32_t) (wwn >> 32),
6625 (uint32_t) (wwn & 0xffffffff));
6626 if ((wwn >> 60) == 0) {
6627 wwn |= (((uint64_t) 2)<< 60);
6631 wwn &= ~((uint64_t) 0xfff << 48);
6633 fcp->isp_nodewwn = wwn;
6636 * Make sure we have both Node and Port as non-zero values.
6638 if (fcp->isp_nodewwn != 0 && fcp->isp_portwwn == 0) {
6639 fcp->isp_portwwn = fcp->isp_nodewwn;
6640 } else if (fcp->isp_nodewwn == 0 && fcp->isp_portwwn != 0) {
6641 fcp->isp_nodewwn = fcp->isp_portwwn;
6645 * Make the Node and Port values sane if they're NAA == 2.
6646 * This means to clear bits 48..56 for the Node WWN and
6647 * make sure that there's some non-zero value in 48..56
6650 if (fcp->isp_nodewwn && fcp->isp_portwwn) {
6651 if ((fcp->isp_nodewwn & (((uint64_t) 0xfff) << 48)) != 0 &&
6652 (fcp->isp_nodewwn >> 60) == 2) {
6653 fcp->isp_nodewwn &= ~((uint64_t) 0xfff << 48);
6655 if ((fcp->isp_portwwn & (((uint64_t) 0xfff) << 48)) == 0 &&
6656 (fcp->isp_portwwn >> 60) == 2) {
6657 fcp->isp_portwwn |= ((uint64_t) 1 << 56);
6662 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
6663 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0)
6664 fcp->isp_maxfrmlen =
6665 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
6666 fcp->isp_retry_delay =
6667 ISP2100_NVRAM_RETRY_DELAY(nvram_data);
6668 fcp->isp_retry_count =
6669 ISP2100_NVRAM_RETRY_COUNT(nvram_data);
6670 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
6672 ISP2100_NVRAM_HARDLOOPID(nvram_data);
6673 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0)
6674 fcp->isp_execthrottle =
6675 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
6676 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
6677 isp_prt(isp, ISP_LOGDEBUG0,
6678 "NVRAM 0x%08x%08x 0x%08x%08x maxalloc %d maxframelen %d",
6679 (uint32_t) (fcp->isp_nodewwn >> 32), (uint32_t) fcp->isp_nodewwn,
6680 (uint32_t) (fcp->isp_portwwn >> 32), (uint32_t) fcp->isp_portwwn,
6681 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data),
6682 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data));
6683 isp_prt(isp, ISP_LOGDEBUG0,
6684 "execthrottle %d fwoptions 0x%x hardloop %d tov %d",
6685 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
6686 ISP2100_NVRAM_OPTIONS(nvram_data),
6687 ISP2100_NVRAM_HARDLOOPID(nvram_data),
6688 ISP2100_NVRAM_TOV(nvram_data));
6689 fcp->isp_xfwoptions = ISP2100_XFW_OPTIONS(nvram_data);
6690 fcp->isp_zfwoptions = ISP2100_ZFW_OPTIONS(nvram_data);
6691 isp_prt(isp, ISP_LOGDEBUG0,
6692 "xfwoptions 0x%x zfw options 0x%x",
6693 ISP2100_XFW_OPTIONS(nvram_data), ISP2100_ZFW_OPTIONS(nvram_data));
6696 #ifdef ISP_FW_CRASH_DUMP
6697 static void isp2200_fw_dump(ispsoftc_t *);
6698 static void isp2300_fw_dump(ispsoftc_t *);
6701 isp2200_fw_dump(ispsoftc_t *isp)
6707 MEMZERO(&mbs, sizeof (mbs));
6708 ptr = FCPARAM(isp)->isp_dump_data;
6710 isp_prt(isp, ISP_LOGERR,
6711 "No place to dump RISC registers and SRAM");
6715 isp_prt(isp, ISP_LOGERR,
6716 "dump area for RISC registers and SRAM already used");
6719 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6720 for (i = 0; i < 100; i++) {
6722 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6726 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6730 for (i = 0; i < 8; i++) {
6731 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6737 for (i = 0; i < 8; i++) {
6738 *ptr++ = ISP_READ(isp, MBOX_BLOCK + (i << 1));
6744 for (i = 0; i < 48; i++) {
6745 *ptr++ = ISP_READ(isp, DMA_BLOCK + 0x20 + (i << 1));
6749 * RISC H/W Registers
6751 ISP_WRITE(isp, BIU2100_CSR, 0);
6752 for (i = 0; i < 16; i++) {
6753 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6759 for (j = 0; j < 8; j++) {
6760 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 8));
6761 for (i = 0; i < 16; i++) {
6763 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6768 * Frame Buffer Hardware Registers
6770 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6771 for (i = 0; i < 16; i++) {
6772 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6776 * Fibre Protocol Module 0 Hardware Registers
6778 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6779 for (i = 0; i < 64; i++) {
6780 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6784 * Fibre Protocol Module 1 Hardware Registers
6786 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6787 for (i = 0; i < 64; i++) {
6788 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6791 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6794 isp_prt(isp, ISP_LOGALL,
6795 "isp_fw_dump: RISC registers dumped successfully");
6796 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6797 for (i = 0; i < 100; i++) {
6799 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6803 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6804 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6807 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6808 for (i = 0; i < 100; i++) {
6810 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6814 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6815 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause After Reset");
6818 ISP_WRITE(isp, RISC_EMB, 0xf2);
6819 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
6820 for (i = 0; i < 100; i++) {
6822 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
6827 mbs.param[0] = MBOX_READ_RAM_WORD;
6828 mbs.param[1] = 0x1000;
6829 isp->isp_mbxworkp = (void *) ptr;
6830 isp->isp_mbxwrk0 = 0xefff; /* continuation count */
6831 isp->isp_mbxwrk1 = 0x1001; /* next SRAM address */
6832 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6833 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6834 isp_prt(isp, ISP_LOGWARN,
6835 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6838 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6839 *ptr++ = isp->isp_mboxtmp[2];
6840 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
6841 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
6842 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
6846 isp2300_fw_dump(ispsoftc_t *isp)
6852 MEMZERO(&mbs, sizeof (mbs));
6853 ptr = FCPARAM(isp)->isp_dump_data;
6855 isp_prt(isp, ISP_LOGERR,
6856 "No place to dump RISC registers and SRAM");
6860 isp_prt(isp, ISP_LOGERR,
6861 "dump area for RISC registers and SRAM already used");
6864 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
6865 for (i = 0; i < 100; i++) {
6867 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6871 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
6875 for (i = 0; i < 8; i++) {
6876 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
6880 * ReqQ-RspQ-Risc2Host Status registers
6882 for (i = 0; i < 8; i++) {
6883 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x10 + (i << 1));
6889 for (i = 0; i < 32; i++) {
6891 ISP_READ(isp, PCI_MBOX_REGS2300_OFF + (i << 1));
6895 * Auto Request Response DMA registers
6897 ISP_WRITE(isp, BIU2100_CSR, 0x40);
6898 for (i = 0; i < 32; i++) {
6899 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6905 ISP_WRITE(isp, BIU2100_CSR, 0x50);
6906 for (i = 0; i < 48; i++) {
6907 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6911 * RISC hardware registers
6913 ISP_WRITE(isp, BIU2100_CSR, 0);
6914 for (i = 0; i < 16; i++) {
6915 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
6919 * RISC GP? registers
6921 for (j = 0; j < 8; j++) {
6922 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 9));
6923 for (i = 0; i < 16; i++) {
6925 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6930 * frame buffer hardware registers
6932 ISP_WRITE(isp, BIU2100_CSR, 0x10);
6933 for (i = 0; i < 64; i++) {
6934 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6938 * FPM B0 hardware registers
6940 ISP_WRITE(isp, BIU2100_CSR, 0x20);
6941 for (i = 0; i < 64; i++) {
6942 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6946 * FPM B1 hardware registers
6948 ISP_WRITE(isp, BIU2100_CSR, 0x30);
6949 for (i = 0; i < 64; i++) {
6950 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
6953 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
6956 isp_prt(isp, ISP_LOGALL,
6957 "isp_fw_dump: RISC registers dumped successfully");
6958 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
6959 for (i = 0; i < 100; i++) {
6961 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
6965 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
6966 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
6970 MEMZERO(&mbs, sizeof (mbs));
6971 mbs.param[0] = MBOX_READ_RAM_WORD;
6972 mbs.param[1] = 0x800;
6973 isp->isp_mbxworkp = (void *) ptr;
6974 isp->isp_mbxwrk0 = 0xf7ff; /* continuation count */
6975 isp->isp_mbxwrk1 = 0x801; /* next SRAM address */
6976 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6977 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6978 isp_prt(isp, ISP_LOGWARN,
6979 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
6982 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
6983 *ptr++ = isp->isp_mboxtmp[2];
6984 MEMZERO(&mbs, sizeof (mbs));
6985 mbs.param[0] = MBOX_READ_RAM_WORD_EXTENDED;
6987 isp->isp_mbxworkp = (void *) ptr;
6988 isp->isp_mbxwrk0 = 0xffff; /* continuation count */
6989 isp->isp_mbxwrk1 = 0x1; /* next SRAM address */
6990 isp->isp_mbxwrk8 = 0x1;
6991 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
6992 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
6993 isp_prt(isp, ISP_LOGWARN,
6994 "RAM DUMP FAILED @ WORD %x", 0x10000 + isp->isp_mbxwrk1);
6997 ptr = isp->isp_mbxworkp; /* finish final word */
6998 *ptr++ = mbs.param[2];
6999 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
7000 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
7001 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
7005 isp_fw_dump(ispsoftc_t *isp)
7008 isp2200_fw_dump(isp);
7009 else if (IS_23XX(isp))
7010 isp2300_fw_dump(isp);