2 * Copyright (c) 1997-2007 by Matthew Jacob
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Machine and OS Independent (well, as best as possible)
30 * code for the Qlogic ISP SCSI and FC-SCSI adapters.
34 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
35 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
36 * ideas dredged from the Solaris driver.
40 * Include header file appropriate for platform we're building on.
43 #include <sys/cdefs.h>
44 __KERNEL_RCSID(0, "$NetBSD$");
45 #include <dev/ic/isp_netbsd.h>
48 #include <sys/cdefs.h>
49 __FBSDID("$FreeBSD$");
50 #include <dev/isp/isp_freebsd.h>
53 #include <dev/ic/isp_openbsd.h>
56 #include "isp_linux.h"
59 #include "isp_solaris.h"
66 #define MBOX_DELAY_COUNT 1000000 / 100
67 #define ISP_MARK_PORTDB(a, b) \
68 isp_prt(isp, ISP_LOGSANCFG, "line %d: markportdb", __LINE__); \
74 static const char fconf[] =
75 "PortDB[%d] changed:\n current =(0x%x@0x%06x 0x%08x%08x 0x%08x%08x)\n"
76 " database=(0x%x@0x%06x 0x%08x%08x 0x%08x%08x)";
77 static const char notresp[] =
78 "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
79 static const char xact1[] =
80 "HBA attempted queued transaction with disconnect not set for %d.%d.%d";
81 static const char xact2[] =
82 "HBA attempted queued transaction to target routine %d on target %d bus %d";
83 static const char xact3[] =
84 "HBA attempted queued cmd for %d.%d.%d when queueing disabled";
85 static const char pskip[] =
86 "SCSI phase skipped for target %d.%d.%d";
87 static const char topology[] =
88 "HBA PortID 0x%06x N-Port Handle %d, Connection Topology '%s'";
89 static const char ourwwn[] =
90 "HBA WWNN 0x%08x%08x HBA WWPN 0x%08x%08x";
91 static const char finmsg[] =
92 "%d.%d.%d: FIN dl%d resid %d STS 0x%x SKEY %c XS_ERR=0x%x";
93 static const char sc0[] =
94 "%s CHAN %d FTHRSH %d IID %d RESETD %d RETRYC %d RETRYD %d ASD 0x%x";
95 static const char sc1[] =
96 "%s RAAN 0x%x DLAN 0x%x DDMAB 0x%x CDMAB 0x%x SELTIME %d MQD %d";
97 static const char sc2[] = "%s CHAN %d TGT %d FLAGS 0x%x 0x%x/0x%x";
98 static const char sc3[] = "Generated";
99 static const char sc4[] = "NVRAM";
100 static const char bun[] =
101 "bad underrun for %d.%d (count %d, resid %d, status %s)";
104 * Local function prototypes.
106 static int isp_parse_async(ispsoftc_t *, uint16_t);
107 static int isp_handle_other_response(ispsoftc_t *, int, isphdr_t *,
110 isp_parse_status(ispsoftc_t *, ispstatusreq_t *, XS_T *, long *);
112 isp_parse_status_24xx(ispsoftc_t *, isp24xx_statusreq_t *, XS_T *, long *);
113 static void isp_fastpost_complete(ispsoftc_t *, uint16_t);
114 static int isp_mbox_continue(ispsoftc_t *);
115 static void isp_scsi_init(ispsoftc_t *);
116 static void isp_scsi_channel_init(ispsoftc_t *, int);
117 static void isp_fibre_init(ispsoftc_t *);
118 static void isp_fibre_init_2400(ispsoftc_t *);
119 static void isp_mark_portdb(ispsoftc_t *, int);
120 static int isp_plogx(ispsoftc_t *, uint16_t, uint32_t, int, int);
121 static int isp_port_login(ispsoftc_t *, uint16_t, uint32_t);
122 static int isp_port_logout(ispsoftc_t *, uint16_t, uint32_t);
123 static int isp_getpdb(ispsoftc_t *, uint16_t, isp_pdb_t *, int);
124 static uint64_t isp_get_portname(ispsoftc_t *, int, int);
125 static int isp_fclink_test(ispsoftc_t *, int);
126 static const char *ispfc_fw_statename(int);
127 static int isp_pdb_sync(ispsoftc_t *);
128 static int isp_scan_loop(ispsoftc_t *);
129 static int isp_gid_ft_sns(ispsoftc_t *);
130 static int isp_gid_ft_ct_passthru(ispsoftc_t *);
131 static int isp_scan_fabric(ispsoftc_t *);
132 static int isp_login_device(ispsoftc_t *, uint32_t, isp_pdb_t *, uint16_t *);
133 static int isp_register_fc4_type(ispsoftc_t *);
134 static int isp_register_fc4_type_24xx(ispsoftc_t *);
135 static uint16_t isp_nxt_handle(ispsoftc_t *, uint16_t);
136 static void isp_fw_state(ispsoftc_t *);
137 static void isp_mboxcmd_qnw(ispsoftc_t *, mbreg_t *, int);
138 static void isp_mboxcmd(ispsoftc_t *, mbreg_t *);
140 static void isp_update(ispsoftc_t *);
141 static void isp_update_bus(ispsoftc_t *, int);
142 static void isp_setdfltparm(ispsoftc_t *, int);
143 static void isp_setdfltfcparm(ispsoftc_t *);
144 static int isp_read_nvram(ispsoftc_t *);
145 static int isp_read_nvram_2400(ispsoftc_t *);
146 static void isp_rdnvram_word(ispsoftc_t *, int, uint16_t *);
147 static void isp_rd_2400_nvram(ispsoftc_t *, uint32_t, uint32_t *);
148 static void isp_parse_nvram_1020(ispsoftc_t *, uint8_t *);
149 static void isp_parse_nvram_1080(ispsoftc_t *, int, uint8_t *);
150 static void isp_parse_nvram_12160(ispsoftc_t *, int, uint8_t *);
151 static void isp_fix_nvram_wwns(ispsoftc_t *);
152 static void isp_parse_nvram_2100(ispsoftc_t *, uint8_t *);
153 static void isp_parse_nvram_2400(ispsoftc_t *, uint8_t *);
158 * Hit the chip over the head, download new f/w if available and set it running.
160 * Locking done elsewhere.
164 isp_reset(ispsoftc_t *isp)
167 uint32_t code_org, val;
168 int loops, i, dodnld = 1;
169 static const char *btype = "????";
170 static const char dcrc[] = "Downloaded RISC Code Checksum Failure";
172 isp->isp_state = ISP_NILSTATE;
175 * Basic types (SCSI, FibreChannel and PCI or SBus)
176 * have been set in the MD code. We figure out more
177 * here. Possibly more refined types based upon PCI
178 * identification. Chip revision has been gathered.
180 * After we've fired this chip up, zero out the conf1 register
181 * for SCSI adapters and do other settings for the 2100.
185 * Get the current running firmware revision out of the
186 * chip before we hit it over the head (if this is our
187 * first time through). Note that we store this as the
188 * 'ROM' firmware revision- which it may not be. In any
189 * case, we don't really use this yet, but we may in
192 if (isp->isp_touched == 0) {
194 * First see whether or not we're sitting in the ISP PROM.
195 * If we've just been reset, we'll have the string "ISP "
196 * spread through outgoing mailbox registers 1-3. We do
197 * this for PCI cards because otherwise we really don't
198 * know what state the card is in and we could hang if
199 * we try this command otherwise.
201 * For SBus cards, we just do this because they almost
202 * certainly will be running firmware by now.
204 if (ISP_READ(isp, OUTMAILBOX1) != 0x4953 ||
205 ISP_READ(isp, OUTMAILBOX2) != 0x5020 ||
206 ISP_READ(isp, OUTMAILBOX3) != 0x2020) {
208 * Just in case it was paused...
211 ISP_WRITE(isp, BIU2400_HCCR,
212 HCCR_2400_CMD_RELEASE);
214 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
216 MEMZERO(&mbs, sizeof (mbs));
217 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
218 mbs.logval = MBLOGNONE;
219 isp_mboxcmd(isp, &mbs);
220 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
221 isp->isp_romfw_rev[0] = mbs.param[1];
222 isp->isp_romfw_rev[1] = mbs.param[2];
223 isp->isp_romfw_rev[2] = mbs.param[3];
226 isp->isp_touched = 1;
229 ISP_DISABLE_INTS(isp);
232 * Pick an initial maxcmds value which will be used
233 * to allocate xflist pointer space. It may be changed
234 * later by the firmware.
237 isp->isp_maxcmds = 4096;
238 } else if (IS_2322(isp)) {
239 isp->isp_maxcmds = 2048;
240 } else if (IS_23XX(isp) || IS_2200(isp)) {
241 isp->isp_maxcmds = 1024;
243 isp->isp_maxcmds = 512;
247 * Set up DMA for the request and result queues.
249 * We do this now so we can use the request queue
252 if (ISP_MBOXDMASETUP(isp) != 0) {
253 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
259 * Set up default request/response queue in-pointer/out-pointer
263 isp->isp_rqstinrp = BIU2400_REQINP;
264 isp->isp_rqstoutrp = BIU2400_REQOUTP;
265 isp->isp_respinrp = BIU2400_RSPINP;
266 isp->isp_respoutrp = BIU2400_RSPOUTP;
267 isp->isp_atioinrp = BIU2400_ATIO_RSPINP;
268 isp->isp_atiooutrp = BIU2400_ATIO_REQINP;
269 } else if (IS_23XX(isp)) {
270 isp->isp_rqstinrp = BIU_REQINP;
271 isp->isp_rqstoutrp = BIU_REQOUTP;
272 isp->isp_respinrp = BIU_RSPINP;
273 isp->isp_respoutrp = BIU_RSPOUTP;
275 isp->isp_rqstinrp = INMAILBOX4;
276 isp->isp_rqstoutrp = OUTMAILBOX4;
277 isp->isp_respinrp = OUTMAILBOX5;
278 isp->isp_respoutrp = INMAILBOX5;
282 * Put the board into PAUSE mode (so we can read the SXP registers
283 * or write FPM/FBM registers).
286 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_HOST_INT);
287 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
288 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_PAUSE);
290 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
294 switch (isp->isp_type) {
319 * While we're paused, reset the FPM module and FBM
322 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
323 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
324 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
325 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
326 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
328 } else if (IS_1240(isp)) {
329 sdparam *sdp = isp->isp_param;
332 sdp->isp_ultramode = 1;
334 sdp->isp_ultramode = 1;
336 * XXX: Should probably do some bus sensing.
338 } else if (IS_ULTRA3(isp)) {
339 sdparam *sdp = isp->isp_param;
341 isp->isp_clock = 100;
345 else if (IS_12160(isp))
349 sdp->isp_lvdmode = 1;
351 if (IS_DUALBUS(isp)) {
353 sdp->isp_lvdmode = 1;
355 } else if (IS_ULTRA2(isp)) {
356 static const char m[] = "bus %d is in %s Mode";
358 sdparam *sdp = isp->isp_param;
360 isp->isp_clock = 100;
364 else if (IS_1080(isp))
369 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
371 case ISP1080_LVD_MODE:
372 sdp->isp_lvdmode = 1;
373 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
375 case ISP1080_HVD_MODE:
376 sdp->isp_diffmode = 1;
377 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
379 case ISP1080_SE_MODE:
380 sdp->isp_ultramode = 1;
381 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
384 isp_prt(isp, ISP_LOGERR,
385 "unknown mode on bus %d (0x%x)", 0, l);
389 if (IS_DUALBUS(isp)) {
391 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
392 l &= ISP1080_MODE_MASK;
394 case ISP1080_LVD_MODE:
395 sdp->isp_lvdmode = 1;
396 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
398 case ISP1080_HVD_MODE:
399 sdp->isp_diffmode = 1;
400 isp_prt(isp, ISP_LOGCONFIG,
401 m, 1, "Differential");
403 case ISP1080_SE_MODE:
404 sdp->isp_ultramode = 1;
405 isp_prt(isp, ISP_LOGCONFIG,
406 m, 1, "Single-Ended");
409 isp_prt(isp, ISP_LOGERR,
410 "unknown mode on bus %d (0x%x)", 1, l);
415 sdparam *sdp = isp->isp_param;
416 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
419 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
423 isp->isp_type = ISP_HA_SCSI_1020;
428 * Some 1020A chips are Ultra Capable, but don't
429 * run the clock rate up for that unless told to
430 * do so by the Ultra Capable bits being set.
433 isp->isp_type = ISP_HA_SCSI_1020A;
438 isp->isp_type = ISP_HA_SCSI_1040;
443 isp->isp_type = ISP_HA_SCSI_1040A;
448 isp->isp_type = ISP_HA_SCSI_1040B;
453 isp->isp_type = ISP_HA_SCSI_1040C;
458 * Now, while we're at it, gather info about ultra
459 * and/or differential mode.
461 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
462 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
463 sdp->isp_diffmode = 1;
465 sdp->isp_diffmode = 0;
467 i = ISP_READ(isp, RISC_PSR);
468 if (isp->isp_bustype == ISP_BT_SBUS) {
469 i &= RISC_PSR_SBUS_ULTRA;
471 i &= RISC_PSR_PCI_ULTRA;
474 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
475 sdp->isp_ultramode = 1;
477 * If we're in Ultra Mode, we have to be 60MHz clock-
478 * even for the SBus version.
482 sdp->isp_ultramode = 0;
484 * Clock is known. Gronk.
489 * Machine dependent clock (if set) overrides
490 * our generic determinations.
492 if (isp->isp_mdvec->dv_clock) {
493 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
494 isp->isp_clock = isp->isp_mdvec->dv_clock;
501 * Clear instrumentation
503 isp->isp_intcnt = isp->isp_intbogus = 0;
506 * Do MD specific pre initialization
511 * Hit the chip over the head with hammer,
512 * and give the ISP a chance to recover.
516 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
523 * Clear data && control DMA engines.
525 ISP_WRITE(isp, CDMA_CONTROL,
526 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
527 ISP_WRITE(isp, DDMA_CONTROL,
528 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
531 } else if (IS_24XX(isp)) {
533 * Stop DMA and wait for it to stop.
535 ISP_WRITE(isp, BIU2400_CSR, BIU2400_DMA_STOP|(3 << 4));
536 for (val = loops = 0; loops < 30000; loops++) {
538 val = ISP_READ(isp, BIU2400_CSR);
539 if ((val & BIU2400_DMA_ACTIVE) == 0) {
543 if (val & BIU2400_DMA_ACTIVE) {
545 isp_prt(isp, ISP_LOGERR, "DMA Failed to Stop on Reset");
549 * Hold it in SOFT_RESET and STOP state for 100us.
551 ISP_WRITE(isp, BIU2400_CSR,
552 BIU2400_SOFT_RESET|BIU2400_DMA_STOP|(3 << 4));
554 for (loops = 0; loops < 10000; loops++) {
556 val = ISP_READ(isp, OUTMAILBOX0);
558 for (val = loops = 0; loops < 500000; loops ++) {
559 val = ISP_READ(isp, BIU2400_CSR);
560 if ((val & BIU2400_SOFT_RESET) == 0) {
564 if (val & BIU2400_SOFT_RESET) {
566 isp_prt(isp, ISP_LOGERR, "Failed to come out of reset");
570 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
577 * Clear data && control DMA engines.
579 ISP_WRITE(isp, CDMA2100_CONTROL,
580 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
581 ISP_WRITE(isp, TDMA2100_CONTROL,
582 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
583 ISP_WRITE(isp, RDMA2100_CONTROL,
584 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
588 * Wait for ISP to be ready to go...
590 loops = MBOX_DELAY_COUNT;
593 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET)) {
596 } else if (IS_24XX(isp)) {
597 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
601 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
606 ISP_DUMPREGS(isp, "chip reset timed out");
613 * After we've fired this chip up, zero out the conf1 register
614 * for SCSI adapters and other settings for the 2100.
618 ISP_WRITE(isp, BIU_CONF1, 0);
619 } else if (!IS_24XX(isp)) {
620 ISP_WRITE(isp, BIU2100_CSR, 0);
624 * Reset RISC Processor
627 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RESET);
628 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RELEASE);
629 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RESET);
631 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
633 ISP_WRITE(isp, BIU_SEMA, 0);
638 * Post-RISC Reset stuff.
641 for (val = loops = 0; loops < 5000000; loops++) {
643 val = ISP_READ(isp, OUTMAILBOX0);
650 isp_prt(isp, ISP_LOGERR, "reset didn't clear");
653 } else if (IS_SCSI(isp)) {
654 uint16_t tmp = isp->isp_mdvec->dv_conf1;
656 * Busted FIFO. Turn off all but burst enables.
658 if (isp->isp_type == ISP_HA_SCSI_1040A) {
659 tmp &= BIU_BURST_ENABLE;
661 ISP_SETBITS(isp, BIU_CONF1, tmp);
662 if (tmp & BIU_BURST_ENABLE) {
663 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
664 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
666 if (SDPARAM(isp)->isp_ptisp) {
667 if (SDPARAM(isp)->isp_ultramode) {
668 while (ISP_READ(isp, RISC_MTR) != 0x1313) {
669 ISP_WRITE(isp, RISC_MTR, 0x1313);
670 ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
673 ISP_WRITE(isp, RISC_MTR, 0x1212);
676 * PTI specific register
678 ISP_WRITE(isp, RISC_EMB, DUAL_BANK);
680 ISP_WRITE(isp, RISC_MTR, 0x1212);
682 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
684 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
685 if (IS_2200(isp) || IS_23XX(isp)) {
686 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
688 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
691 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
692 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
693 ISP_WRITE(isp, isp->isp_respinrp, 0);
694 ISP_WRITE(isp, isp->isp_respoutrp, 0);
698 * Do MD specific post initialization
703 * Wait for everything to finish firing up.
705 * Avoid doing this on the 2312 because you can generate a PCI
706 * parity error (chip breakage).
711 loops = MBOX_DELAY_COUNT;
712 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
716 isp_prt(isp, ISP_LOGERR,
717 "MBOX_BUSY never cleared on reset");
724 * Up until this point we've done everything by just reading or
725 * setting registers. From this point on we rely on at least *some*
726 * kind of firmware running in the card.
730 * Do some sanity checking.
732 MEMZERO(&mbs, sizeof (mbs));
733 mbs.param[0] = MBOX_NO_OP;
734 mbs.logval = MBLOGALL;
735 isp_mboxcmd(isp, &mbs);
736 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
741 if (IS_SCSI(isp) || IS_24XX(isp)) {
742 MEMZERO(&mbs, sizeof (mbs));
743 mbs.param[0] = MBOX_MAILBOX_REG_TEST;
744 mbs.param[1] = 0xdead;
745 mbs.param[2] = 0xbeef;
746 mbs.param[3] = 0xffff;
747 mbs.param[4] = 0x1111;
748 mbs.param[5] = 0xa5a5;
749 mbs.param[6] = 0x0000;
750 mbs.param[7] = 0x0000;
751 mbs.logval = MBLOGALL;
752 isp_mboxcmd(isp, &mbs);
753 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
757 if (mbs.param[1] != 0xdead || mbs.param[2] != 0xbeef ||
758 mbs.param[3] != 0xffff || mbs.param[4] != 0x1111 ||
759 mbs.param[5] != 0xa5a5) {
761 isp_prt(isp, ISP_LOGERR,
762 "Register Test Failed (0x%x 0x%x 0x%x 0x%x 0x%x)",
763 mbs.param[1], mbs.param[2], mbs.param[3],
764 mbs.param[4], mbs.param[5]);
771 * Download new Firmware, unless requested not to do so.
772 * This is made slightly trickier in some cases where the
773 * firmware of the ROM revision is newer than the revision
774 * compiled into the driver. So, where we used to compare
775 * versions of our f/w and the ROM f/w, now we just see
776 * whether we have f/w at all and whether a config flag
777 * has disabled our download.
779 if ((isp->isp_mdvec->dv_ispfw == NULL) ||
780 (isp->isp_confopts & ISP_CFG_NORELOAD)) {
785 code_org = ISP_CODE_ORG_2400;
786 } else if (IS_23XX(isp)) {
787 code_org = ISP_CODE_ORG_2300;
789 code_org = ISP_CODE_ORG;
792 if (dodnld && IS_24XX(isp)) {
793 const uint32_t *ptr = isp->isp_mdvec->dv_ispfw;
796 * NB: Whatever you do do, do *not* issue the VERIFY FIRMWARE
797 * NB: command to the 2400 while loading new firmware. This
798 * NB: causes the new f/w to start and immediately crash back
803 * Keep loading until we run out of f/w.
805 code_org = ptr[2]; /* 1st load address is our start addr */
810 isp_prt(isp, ISP_LOGDEBUG0,
811 "load 0x%x words of code at load address 0x%x",
818 while (wi < ptr[3]) {
822 nw = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) >> 2;
826 cp = isp->isp_rquest;
827 for (i = 0; i < nw; i++) {
828 ISP_IOXPUT_32(isp, ptr[wi++], &cp[i]);
831 MEMORYBARRIER(isp, SYNC_REQUEST,
832 0, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)));
833 MEMZERO(&mbs, sizeof (mbs));
834 mbs.param[0] = MBOX_LOAD_RISC_RAM;
836 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
837 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
838 mbs.param[4] = nw >> 16;
840 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
841 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
842 mbs.param[8] = la >> 16;
843 mbs.logval = MBLOGALL;
844 isp_mboxcmd(isp, &mbs);
845 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
846 isp_prt(isp, ISP_LOGERR,
847 "F/W Risc Ram Load Failed");
859 isp->isp_loaded_fw = 1;
860 } else if (dodnld && IS_23XX(isp)) {
861 const uint16_t *ptr = isp->isp_mdvec->dv_ispfw;
862 uint16_t wi, wl, segno;
871 isp_prt(isp, ISP_LOGDEBUG0,
872 "load 0x%x words of code at load address 0x%x",
878 while (wi < ptr[3]) {
882 nw = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) >> 1;
886 if (nw > (1 << 15)) {
889 cp = isp->isp_rquest;
890 for (i = 0; i < nw; i++) {
891 ISP_IOXPUT_16(isp, ptr[wi++], &cp[i]);
894 MEMORYBARRIER(isp, SYNC_REQUEST,
895 0, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)));
896 MEMZERO(&mbs, sizeof (mbs));
897 mbs.param[0] = MBOX_LOAD_RISC_RAM;
899 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
900 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
902 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
903 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
904 mbs.param[8] = la >> 16;
905 mbs.logval = MBLOGALL;
906 isp_mboxcmd(isp, &mbs);
907 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
908 isp_prt(isp, ISP_LOGERR,
909 "F/W Risc Ram Load Failed");
918 * Verify that it downloaded correctly.
920 MEMZERO(&mbs, sizeof (mbs));
921 mbs.param[0] = MBOX_VERIFY_CHECKSUM;
922 mbs.param[1] = code_org;
923 mbs.logval = MBLOGNONE;
924 isp_mboxcmd(isp, &mbs);
925 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
926 isp_prt(isp, ISP_LOGERR, dcrc);
938 * If we're a 2322, the firmware actually comes in
939 * three chunks. We loaded the first at the code_org
940 * address. The other two chunks, which follow right
941 * after each other in memory here, get loaded at
942 * addresses specfied at offset 0x9..0xB.
947 la = ptr[5] | ((ptr[4] & 0x3f) << 16);
949 isp->isp_loaded_fw = 1;
955 u.cp = isp->isp_mdvec->dv_ispfw;
956 isp->isp_mbxworkp = &u.np[1];
957 isp->isp_mbxwrk0 = u.np[3] - 1;
958 isp->isp_mbxwrk1 = code_org + 1;
959 MEMZERO(&mbs, sizeof (mbs));
960 mbs.param[0] = MBOX_WRITE_RAM_WORD;
961 mbs.param[1] = code_org;
962 mbs.param[2] = u.np[0];
963 mbs.logval = MBLOGNONE;
964 isp_mboxcmd(isp, &mbs);
965 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
966 isp_prt(isp, ISP_LOGERR,
967 "F/W download failed at word %d",
968 isp->isp_mbxwrk1 - code_org);
973 * Verify that it downloaded correctly.
975 MEMZERO(&mbs, sizeof (mbs));
976 mbs.param[0] = MBOX_VERIFY_CHECKSUM;
977 mbs.param[1] = code_org;
978 mbs.logval = MBLOGNONE;
979 isp_mboxcmd(isp, &mbs);
980 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
981 isp_prt(isp, ISP_LOGERR, dcrc);
985 isp->isp_loaded_fw = 1;
987 isp->isp_loaded_fw = 0;
988 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
992 * Now start it rolling.
994 * If we didn't actually download f/w,
995 * we still need to (re)start it.
999 MEMZERO(&mbs, sizeof (mbs));
1000 mbs.timeout = 1000000;
1001 mbs.param[0] = MBOX_EXEC_FIRMWARE;
1003 mbs.param[1] = code_org >> 16;
1004 mbs.param[2] = code_org;
1005 if (isp->isp_loaded_fw) {
1010 } else if (IS_2322(isp)) {
1011 mbs.param[1] = code_org;
1012 if (isp->isp_loaded_fw) {
1018 mbs.param[1] = code_org;
1021 mbs.logval = MBLOGALL;
1022 isp_mboxcmd(isp, &mbs);
1023 if (IS_2322(isp) || IS_24XX(isp)) {
1024 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1031 * Give it a chance to finish starting up.
1037 * Set CLOCK RATE, but only if asked to.
1039 if (isp->isp_clock) {
1040 mbs.param[0] = MBOX_SET_CLOCK_RATE;
1041 mbs.param[1] = isp->isp_clock;
1042 mbs.logval = MBLOGNONE;
1043 isp_mboxcmd(isp, &mbs);
1044 /* we will try not to care if this fails */
1048 MEMZERO(&mbs, sizeof (mbs));
1049 mbs.param[0] = MBOX_ABOUT_FIRMWARE;
1050 mbs.logval = MBLOGALL;
1051 isp_mboxcmd(isp, &mbs);
1052 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1057 if (IS_24XX(isp) && mbs.param[1] == 0xdead) {
1058 isp_prt(isp, ISP_LOGERR, "f/w didn't *really* start");
1064 * The SBus firmware that we are using apparently does not return
1065 * major, minor, micro revisions in the mailbox registers, which
1066 * is really, really, annoying.
1068 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
1070 #ifdef ISP_TARGET_MODE
1071 isp->isp_fwrev[0] = 7;
1072 isp->isp_fwrev[1] = 55;
1074 isp->isp_fwrev[0] = 1;
1075 isp->isp_fwrev[1] = 37;
1077 isp->isp_fwrev[2] = 0;
1080 isp->isp_fwrev[0] = mbs.param[1];
1081 isp->isp_fwrev[1] = mbs.param[2];
1082 isp->isp_fwrev[2] = mbs.param[3];
1085 isp_prt(isp, ISP_LOGALL,
1086 "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
1087 btype, isp->isp_revision, dodnld? "loaded" : "resident",
1088 isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
1092 * We do not believe firmware attributes for 2100 code less
1093 * than 1.17.0, unless it's the firmware we specifically
1096 * Note that all 22XX and later f/w is greater than 1.X.0.
1098 if ((ISP_FW_OLDER_THAN(isp, 1, 17, 1))) {
1099 #ifdef USE_SMALLER_2100_FIRMWARE
1100 FCPARAM(isp)->isp_fwattr = ISP_FW_ATTR_SCCLUN;
1102 FCPARAM(isp)->isp_fwattr = 0;
1105 FCPARAM(isp)->isp_fwattr = mbs.param[6];
1106 isp_prt(isp, ISP_LOGDEBUG0,
1107 "Firmware Attributes = 0x%x", mbs.param[6]);
1109 FCPARAM(isp)->isp_2klogin = 0;
1110 FCPARAM(isp)->isp_sccfw = 0;
1111 FCPARAM(isp)->isp_tmode = 0;
1113 FCPARAM(isp)->isp_2klogin = 1;
1114 FCPARAM(isp)->isp_sccfw = 1;
1115 FCPARAM(isp)->isp_tmode = 1;
1117 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_SCCLUN) {
1118 FCPARAM(isp)->isp_sccfw = 1;
1120 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_2KLOGINS) {
1121 FCPARAM(isp)->isp_2klogin = 1;
1122 FCPARAM(isp)->isp_sccfw = 1;
1124 if (FCPARAM(isp)->isp_fwattr & ISP_FW_ATTR_TMODE) {
1125 FCPARAM(isp)->isp_tmode = 1;
1128 if (FCPARAM(isp)->isp_2klogin) {
1129 isp_prt(isp, ISP_LOGCONFIG, "2K Logins Supported");
1133 if (isp->isp_romfw_rev[0] || isp->isp_romfw_rev[1] ||
1134 isp->isp_romfw_rev[2]) {
1135 isp_prt(isp, ISP_LOGCONFIG, "Last F/W revision was %d.%d.%d",
1136 isp->isp_romfw_rev[0], isp->isp_romfw_rev[1],
1137 isp->isp_romfw_rev[2]);
1140 if (!IS_24XX(isp)) {
1141 MEMZERO(&mbs, sizeof (mbs));
1142 mbs.param[0] = MBOX_GET_FIRMWARE_STATUS;
1143 mbs.logval = MBLOGALL;
1144 isp_mboxcmd(isp, &mbs);
1145 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1149 if (isp->isp_maxcmds >= mbs.param[2]) {
1150 isp->isp_maxcmds = mbs.param[2];
1153 isp_prt(isp, ISP_LOGCONFIG,
1154 "%d max I/O command limit set", isp->isp_maxcmds);
1157 isp->isp_state = ISP_RESETSTATE;
1160 * Okay- now that we have new firmware running, we now (re)set our
1161 * notion of how many luns we support. This is somewhat tricky because
1162 * if we haven't loaded firmware, we sometimes do not have an easy way
1163 * of knowing how many luns we support.
1165 * Expanded lun firmware gives you 32 luns for SCSI cards and
1166 * 16384 luns for Fibre Channel cards.
1168 * It turns out that even for QLogic 2100s with ROM 1.10 and above
1169 * we do get a firmware attributes word returned in mailbox register 6.
1171 * Because the lun is in a different position in the Request Queue
1172 * Entry structure for Fibre Channel with expanded lun firmware, we
1173 * can only support one lun (lun zero) when we don't know what kind
1174 * of firmware we're running.
1178 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
1179 isp->isp_maxluns = 32;
1181 isp->isp_maxluns = 8;
1184 isp->isp_maxluns = 8;
1187 if (FCPARAM(isp)->isp_sccfw) {
1188 isp->isp_maxluns = 16384;
1190 isp->isp_maxluns = 16;
1194 * Must do this first to get defaults established.
1197 isp_setdfltparm(isp, 0);
1198 if (IS_DUALBUS(isp)) {
1199 isp_setdfltparm(isp, 1);
1202 isp_setdfltfcparm(isp);
1208 * Initialize Parameters of Hardware to a known state.
1210 * Locks are held before coming here.
1214 isp_init(ispsoftc_t *isp)
1218 * Do this *before* initializing the firmware.
1220 ISP_MARK_PORTDB(isp, 0);
1221 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
1222 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
1224 if (isp->isp_role != ISP_ROLE_NONE) {
1226 isp_fibre_init_2400(isp);
1228 isp_fibre_init(isp);
1237 isp_scsi_init(ispsoftc_t *isp)
1239 sdparam *sdp_chan0, *sdp_chan1;
1242 sdp_chan0 = isp->isp_param;
1243 sdp_chan1 = sdp_chan0;
1244 if (IS_DUALBUS(isp)) {
1249 * If we have no role (neither target nor initiator), return.
1251 if (isp->isp_role == ISP_ROLE_NONE) {
1255 /* First do overall per-card settings. */
1258 * If we have fast memory timing enabled, turn it on.
1260 if (sdp_chan0->isp_fast_mttr) {
1261 ISP_WRITE(isp, RISC_MTR, 0x1313);
1265 * Set Retry Delay and Count.
1266 * You set both channels at the same time.
1268 MEMZERO(&mbs, sizeof (mbs));
1269 mbs.param[0] = MBOX_SET_RETRY_COUNT;
1270 mbs.param[1] = sdp_chan0->isp_retry_count;
1271 mbs.param[2] = sdp_chan0->isp_retry_delay;
1272 mbs.param[6] = sdp_chan1->isp_retry_count;
1273 mbs.param[7] = sdp_chan1->isp_retry_delay;
1274 mbs.logval = MBLOGALL;
1275 isp_mboxcmd(isp, &mbs);
1276 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1281 * Set ASYNC DATA SETUP time. This is very important.
1283 MEMZERO(&mbs, sizeof (mbs));
1284 mbs.param[0] = MBOX_SET_ASYNC_DATA_SETUP_TIME;
1285 mbs.param[1] = sdp_chan0->isp_async_data_setup;
1286 mbs.param[2] = sdp_chan1->isp_async_data_setup;
1287 mbs.logval = MBLOGALL;
1288 isp_mboxcmd(isp, &mbs);
1289 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1294 * Set ACTIVE Negation State.
1296 MEMZERO(&mbs, sizeof (mbs));
1297 mbs.param[0] = MBOX_SET_ACT_NEG_STATE;
1299 (sdp_chan0->isp_req_ack_active_neg << 4) |
1300 (sdp_chan0->isp_data_line_active_neg << 5);
1302 (sdp_chan1->isp_req_ack_active_neg << 4) |
1303 (sdp_chan1->isp_data_line_active_neg << 5);
1304 mbs.logval = MBLOGNONE;
1305 isp_mboxcmd(isp, &mbs);
1306 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1307 isp_prt(isp, ISP_LOGERR,
1308 "failed to set active negation state (%d,%d), (%d,%d)",
1309 sdp_chan0->isp_req_ack_active_neg,
1310 sdp_chan0->isp_data_line_active_neg,
1311 sdp_chan1->isp_req_ack_active_neg,
1312 sdp_chan1->isp_data_line_active_neg);
1319 * Set the Tag Aging limit
1321 MEMZERO(&mbs, sizeof (mbs));
1322 mbs.param[0] = MBOX_SET_TAG_AGE_LIMIT;
1323 mbs.param[1] = sdp_chan0->isp_tag_aging;
1324 mbs.param[2] = sdp_chan1->isp_tag_aging;
1325 mbs.logval = MBLOGALL;
1326 isp_mboxcmd(isp, &mbs);
1327 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1328 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
1329 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
1334 * Set selection timeout.
1336 MEMZERO(&mbs, sizeof (mbs));
1337 mbs.param[0] = MBOX_SET_SELECT_TIMEOUT;
1338 mbs.param[1] = sdp_chan0->isp_selection_timeout;
1339 mbs.param[2] = sdp_chan1->isp_selection_timeout;
1340 mbs.logval = MBLOGALL;
1341 isp_mboxcmd(isp, &mbs);
1342 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1346 /* now do per-channel settings */
1347 isp_scsi_channel_init(isp, 0);
1348 if (IS_DUALBUS(isp))
1349 isp_scsi_channel_init(isp, 1);
1352 * Now enable request/response queues
1355 if (IS_ULTRA2(isp) || IS_1240(isp)) {
1356 MEMZERO(&mbs, sizeof (mbs));
1357 mbs.param[0] = MBOX_INIT_RES_QUEUE_A64;
1358 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1359 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1360 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1362 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1363 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1364 mbs.logval = MBLOGALL;
1365 isp_mboxcmd(isp, &mbs);
1366 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1369 isp->isp_residx = mbs.param[5];
1371 MEMZERO(&mbs, sizeof (mbs));
1372 mbs.param[0] = MBOX_INIT_REQ_QUEUE_A64;
1373 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1374 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1375 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1377 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1378 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1379 mbs.logval = MBLOGALL;
1380 isp_mboxcmd(isp, &mbs);
1381 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1384 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1386 MEMZERO(&mbs, sizeof (mbs));
1387 mbs.param[0] = MBOX_INIT_RES_QUEUE;
1388 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1389 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1390 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1392 mbs.logval = MBLOGALL;
1393 isp_mboxcmd(isp, &mbs);
1394 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1397 isp->isp_residx = mbs.param[5];
1399 MEMZERO(&mbs, sizeof (mbs));
1400 mbs.param[0] = MBOX_INIT_REQ_QUEUE;
1401 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1402 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1403 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1405 mbs.logval = MBLOGALL;
1406 isp_mboxcmd(isp, &mbs);
1407 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1410 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1414 * Turn on Fast Posting, LVD transitions
1416 * Ultra2 F/W always has had fast posting (and LVD transitions)
1418 * Ultra and older (i.e., SBus) cards may not. It's just safer
1419 * to assume not for them.
1422 MEMZERO(&mbs, sizeof (mbs));
1423 mbs.param[0] = MBOX_SET_FW_FEATURES;
1426 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1428 if (IS_ULTRA2(isp) || IS_1240(isp))
1429 mbs.param[1] |= FW_FEATURE_RIO_16BIT;
1431 if (IS_ULTRA2(isp) || IS_1240(isp))
1432 mbs.param[1] |= FW_FEATURE_FAST_POST;
1434 if (mbs.param[1] != 0) {
1435 uint16_t sfeat = mbs.param[1];
1436 mbs.logval = MBLOGALL;
1437 isp_mboxcmd(isp, &mbs);
1438 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1439 isp_prt(isp, ISP_LOGINFO,
1440 "Enabled FW features (0x%x)", sfeat);
1445 * Let the outer layers decide whether to issue a SCSI bus reset.
1447 isp->isp_state = ISP_INITSTATE;
1451 isp_scsi_channel_init(ispsoftc_t *isp, int channel)
1457 sdp = isp->isp_param;
1461 * Set (possibly new) Initiator ID.
1463 MEMZERO(&mbs, sizeof (mbs));
1464 mbs.param[0] = MBOX_SET_INIT_SCSI_ID;
1465 mbs.param[1] = (channel << 7) | sdp->isp_initiator_id;
1466 mbs.logval = MBLOGALL;
1467 isp_mboxcmd(isp, &mbs);
1468 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1471 isp_prt(isp, ISP_LOGINFO, "Initiator ID is %d on Channel %d",
1472 sdp->isp_initiator_id, channel);
1476 * Set current per-target parameters to an initial safe minimum.
1478 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1482 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1485 #ifndef ISP_TARGET_MODE
1486 sdf = sdp->isp_devparam[tgt].goal_flags;
1487 sdf &= DPARM_SAFE_DFLT;
1489 * It is not quite clear when this changed over so that
1490 * we could force narrow and async for 1000/1020 cards,
1491 * but assume that this is only the case for loaded
1494 if (isp->isp_loaded_fw) {
1495 sdf |= DPARM_NARROW | DPARM_ASYNC;
1499 * The !$*!)$!$)* f/w uses the same index into some
1500 * internal table to decide how to respond to negotiations,
1501 * so if we've said "let's be safe" for ID X, and ID X
1502 * selects *us*, the negotiations will back to 'safe'
1503 * (as in narrow/async). What the f/w *should* do is
1504 * use the initiator id settings to decide how to respond.
1506 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1508 MEMZERO(&mbs, sizeof (mbs));
1509 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1510 mbs.param[1] = (channel << 15) | (tgt << 8);
1512 if ((sdf & DPARM_SYNC) == 0) {
1516 (sdp->isp_devparam[tgt].goal_offset << 8) |
1517 (sdp->isp_devparam[tgt].goal_period);
1519 isp_prt(isp, ISP_LOGDEBUG0,
1520 "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1521 channel, tgt, mbs.param[2], mbs.param[3] >> 8,
1522 mbs.param[3] & 0xff);
1523 mbs.logval = MBLOGNONE;
1524 isp_mboxcmd(isp, &mbs);
1525 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1526 sdf = DPARM_SAFE_DFLT;
1527 MEMZERO(&mbs, sizeof (mbs));
1528 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
1529 mbs.param[1] = (tgt << 8) | (channel << 15);
1532 mbs.logval = MBLOGALL;
1533 isp_mboxcmd(isp, &mbs);
1534 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1540 * We don't update any information directly from the f/w
1541 * because we need to run at least one command to cause a
1542 * new state to be latched up. So, we just assume that we
1543 * converge to the values we just had set.
1545 * Ensure that we don't believe tagged queuing is enabled yet.
1546 * It turns out that sometimes the ISP just ignores our
1547 * attempts to set parameters for devices that it hasn't
1550 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1551 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1552 MEMZERO(&mbs, sizeof (mbs));
1553 mbs.param[0] = MBOX_SET_DEV_QUEUE_PARAMS;
1554 mbs.param[1] = (channel << 15) | (tgt << 8) | lun;
1555 mbs.param[2] = sdp->isp_max_queue_depth;
1556 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1557 mbs.logval = MBLOGALL;
1558 isp_mboxcmd(isp, &mbs);
1559 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1564 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1565 if (sdp->isp_devparam[tgt].dev_refresh) {
1566 isp->isp_sendmarker |= (1 << channel);
1567 isp->isp_update |= (1 << channel);
1574 * Fibre Channel specific initialization.
1577 isp_fibre_init(ispsoftc_t *isp)
1580 isp_icb_t local, *icbp = &local;
1583 uint64_t nwwn, pwwn;
1585 fcp = isp->isp_param;
1587 MEMZERO(icbp, sizeof (*icbp));
1588 icbp->icb_version = ICB_VERSION1;
1589 icbp->icb_fwoptions = fcp->isp_fwoptions;
1592 * Firmware Options are either retrieved from NVRAM or
1593 * are patched elsewhere. We check them for sanity here
1594 * and make changes based on board revision, but otherwise
1595 * let others decide policy.
1599 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1601 if (IS_2100(isp) && isp->isp_revision < 5) {
1602 icbp->icb_fwoptions &= ~ICBOPT_FAIRNESS;
1606 * We have to use FULL LOGIN even though it resets the loop too much
1607 * because otherwise port database entries don't get updated after
1608 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1610 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1611 icbp->icb_fwoptions |= ICBOPT_FULL_LOGIN;
1615 * Insist on Port Database Update Async notifications
1617 icbp->icb_fwoptions |= ICBOPT_PDBCHANGE_AE;
1620 * Make sure that target role reflects into fwoptions.
1622 if (isp->isp_role & ISP_ROLE_TARGET) {
1623 icbp->icb_fwoptions |= ICBOPT_TGT_ENABLE;
1625 icbp->icb_fwoptions &= ~ICBOPT_TGT_ENABLE;
1628 if (isp->isp_role & ISP_ROLE_INITIATOR) {
1629 icbp->icb_fwoptions &= ~ICBOPT_INI_DISABLE;
1631 icbp->icb_fwoptions |= ICBOPT_INI_DISABLE;
1634 icbp->icb_maxfrmlen = fcp->isp_maxfrmlen;
1635 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN ||
1636 icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1637 isp_prt(isp, ISP_LOGERR,
1638 "bad frame length (%d) from NVRAM- using %d",
1639 fcp->isp_maxfrmlen, ICB_DFLT_FRMLEN);
1640 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1642 icbp->icb_maxalloc = fcp->isp_maxalloc;
1643 if (icbp->icb_maxalloc < 1) {
1644 isp_prt(isp, ISP_LOGERR,
1645 "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1646 icbp->icb_maxalloc = 16;
1648 icbp->icb_execthrottle = fcp->isp_execthrottle;
1649 if (icbp->icb_execthrottle < 1) {
1650 isp_prt(isp, ISP_LOGERR,
1651 "bad execution throttle of %d- using 16",
1652 fcp->isp_execthrottle);
1653 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1655 icbp->icb_retry_delay = fcp->isp_retry_delay;
1656 icbp->icb_retry_count = fcp->isp_retry_count;
1657 icbp->icb_hardaddr = fcp->isp_loopid;
1658 ownloopid = (isp->isp_confopts & ISP_CFG_OWNLOOPID) != 0;
1659 if (icbp->icb_hardaddr > 125) {
1660 icbp->icb_hardaddr = 0;
1665 * Our life seems so much better with 2200s and later with
1666 * the latest f/w if we set Hard Address.
1668 if (ownloopid || ISP_FW_NEWER_THAN(isp, 2, 2, 5)) {
1669 icbp->icb_fwoptions |= ICBOPT_HARD_ADDRESS;
1673 * Right now we just set extended options to prefer point-to-point
1674 * over loop based upon some soft config options.
1676 * NB: for the 2300, ICBOPT_EXTENDED is required.
1678 if (IS_2200(isp) || IS_23XX(isp)) {
1679 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1681 * Prefer or force Point-To-Point instead Loop?
1683 switch(isp->isp_confopts & ISP_CFG_PORT_PREF) {
1685 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1687 case ISP_CFG_NPORT_ONLY:
1688 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1690 case ISP_CFG_LPORT_ONLY:
1691 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1694 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1698 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1701 * QLogic recommends that FAST Posting be turned
1702 * off for 23XX cards and instead allow the HBA
1703 * to write response queue entries and interrupt
1704 * after a delay (ZIO).
1706 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1707 if ((fcp->isp_xfwoptions & ICBXOPT_TIMER_MASK) ==
1709 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1710 icbp->icb_idelaytimer = 10;
1712 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1713 icbp->icb_zfwoptions |= ICBZOPT_RATE_ONEGB;
1714 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1715 icbp->icb_zfwoptions |= ICBZOPT_RATE_TWOGB;
1717 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1719 if (fcp->isp_zfwoptions & ICBZOPT_50_OHM) {
1720 icbp->icb_zfwoptions |= ICBZOPT_50_OHM;
1727 * For 22XX > 2.1.26 && 23XX, set some options.
1728 * XXX: Probably okay for newer 2100 f/w too.
1730 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1732 * Turn on LIP F8 async event (1)
1733 * Turn on generate AE 8013 on all LIP Resets (2)
1734 * Disable LIP F7 switching (8)
1736 MEMZERO(&mbs, sizeof (mbs));
1737 mbs.param[0] = MBOX_SET_FIRMWARE_OPTIONS;
1741 mbs.logval = MBLOGALL;
1742 isp_mboxcmd(isp, &mbs);
1743 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1747 icbp->icb_logintime = ICB_LOGIN_TOV;
1748 icbp->icb_lunetimeout = ICB_LUN_ENABLE_TOV;
1750 nwwn = ISP_NODEWWN(isp);
1751 pwwn = ISP_PORTWWN(isp);
1753 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1754 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, nwwn);
1755 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, pwwn);
1756 isp_prt(isp, ISP_LOGDEBUG1,
1757 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1758 ((uint32_t) (nwwn >> 32)),
1759 ((uint32_t) (nwwn & 0xffffffff)),
1760 ((uint32_t) (pwwn >> 32)),
1761 ((uint32_t) (pwwn & 0xffffffff)));
1763 icbp->icb_fwoptions &= ~ICBOPT_BOTH_WWNS;
1764 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, pwwn);
1765 isp_prt(isp, ISP_LOGDEBUG1,
1766 "Setting ICB Port 0x%08x%08x",
1767 ((uint32_t) (pwwn >> 32)),
1768 ((uint32_t) (pwwn & 0xffffffff)));
1770 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
1773 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1774 if (icbp->icb_rqstqlen < 1) {
1775 isp_prt(isp, ISP_LOGERR, "bad request queue length");
1777 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1778 if (icbp->icb_rsltqlen < 1) {
1779 isp_prt(isp, ISP_LOGERR, "bad result queue length");
1781 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1782 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1783 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1784 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1785 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1786 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1787 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1788 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1790 isp_prt(isp, ISP_LOGDEBUG0,
1791 "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1792 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1794 FC_SCRATCH_ACQUIRE(isp);
1795 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1800 MEMZERO(&mbs, sizeof (mbs));
1801 mbs.param[0] = MBOX_INIT_FIRMWARE;
1802 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1803 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1804 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1805 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1806 mbs.logval = MBLOGALL;
1807 mbs.timeout = 30 * 1000000;
1808 isp_prt(isp, ISP_LOGDEBUG0, "INIT F/W from %p (%08x%08x)",
1809 fcp->isp_scratch, (uint32_t) ((uint64_t)fcp->isp_scdma >> 32),
1810 (uint32_t) fcp->isp_scdma);
1811 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp));
1812 isp_mboxcmd(isp, &mbs);
1813 FC_SCRATCH_RELEASE(isp);
1814 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1815 isp_print_bytes(isp, "isp_fibre_init", sizeof (*icbp), icbp);
1818 isp->isp_reqidx = 0;
1819 isp->isp_reqodx = 0;
1820 isp->isp_residx = 0;
1823 * Whatever happens, we're now committed to being here.
1825 isp->isp_state = ISP_INITSTATE;
1829 isp_fibre_init_2400(ispsoftc_t *isp)
1832 isp_icb_2400_t local, *icbp = &local;
1835 uint64_t nwwn, pwwn;
1837 fcp = isp->isp_param;
1840 * Turn on LIP F8 async event (1)
1842 MEMZERO(&mbs, sizeof (mbs));
1843 mbs.param[0] = MBOX_SET_FIRMWARE_OPTIONS;
1845 mbs.logval = MBLOGALL;
1846 isp_mboxcmd(isp, &mbs);
1847 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1852 * XXX: This should be applied to icb- not fwoptions
1854 if (isp->isp_role & ISP_ROLE_TARGET) {
1855 fcp->isp_fwoptions |= ICB2400_OPT1_TGT_ENABLE;
1857 fcp->isp_fwoptions &= ~ICB2400_OPT1_TGT_ENABLE;
1860 if (isp->isp_role & ISP_ROLE_INITIATOR) {
1861 fcp->isp_fwoptions &= ~ICB2400_OPT1_INI_DISABLE;
1863 fcp->isp_fwoptions |= ICB2400_OPT1_INI_DISABLE;
1866 MEMZERO(icbp, sizeof (*icbp));
1867 icbp->icb_version = ICB_VERSION1;
1868 icbp->icb_maxfrmlen = fcp->isp_maxfrmlen;
1869 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN ||
1870 icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1871 isp_prt(isp, ISP_LOGERR,
1872 "bad frame length (%d) from NVRAM- using %d",
1873 fcp->isp_maxfrmlen, ICB_DFLT_FRMLEN);
1874 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1877 icbp->icb_execthrottle = fcp->isp_execthrottle;
1878 if (icbp->icb_execthrottle < 1) {
1879 isp_prt(isp, ISP_LOGERR,
1880 "bad execution throttle of %d- using 16",
1881 fcp->isp_execthrottle);
1882 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1885 if (isp->isp_role & ISP_ROLE_TARGET) {
1887 * Get current resource count
1889 MEMZERO(&mbs, sizeof (mbs));
1890 mbs.param[0] = MBOX_GET_RESOURCE_COUNT;
1892 mbs.logval = MBLOGALL;
1893 isp_mboxcmd(isp, &mbs);
1894 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1897 icbp->icb_xchgcnt = mbs.param[3];
1900 icbp->icb_fwoptions1 = fcp->isp_fwoptions;
1902 icbp->icb_hardaddr = fcp->isp_loopid;
1903 ownloopid = (isp->isp_confopts & ISP_CFG_OWNLOOPID) != 0;
1904 if (icbp->icb_hardaddr > 125) {
1905 icbp->icb_hardaddr = 0;
1909 icbp->icb_fwoptions1 |= ICB2400_OPT1_HARD_ADDRESS;
1912 icbp->icb_fwoptions2 = fcp->isp_xfwoptions;
1913 switch(isp->isp_confopts & ISP_CFG_PORT_PREF) {
1915 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
1916 icbp->icb_fwoptions2 |= ICB2400_OPT2_PTP_2_LOOP;
1918 case ISP_CFG_NPORT_ONLY:
1919 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
1920 icbp->icb_fwoptions2 |= ICB2400_OPT2_PTP_ONLY;
1922 case ISP_CFG_LPORT_ONLY:
1923 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
1924 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_ONLY;
1927 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
1928 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_2_PTP;
1932 switch (icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK) {
1933 case ICB2400_OPT2_ZIO:
1934 case ICB2400_OPT2_ZIO1:
1935 icbp->icb_idelaytimer = 0;
1940 isp_prt(isp, ISP_LOGWARN, "bad value %x in fwopt2 timer field",
1941 icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK);
1942 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TIMER_MASK;
1946 icbp->icb_fwoptions3 = fcp->isp_zfwoptions;
1947 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_AUTO;
1948 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1949 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_ONEGB;
1950 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1951 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_TWOGB;
1952 } else if (isp->isp_confopts & ISP_CFG_FOURGB) {
1953 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_FOURGB;
1955 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_AUTO;
1958 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
1959 icbp->icb_fwoptions3 |= ICB2400_OPT3_SOFTID;
1961 icbp->icb_logintime = ICB_LOGIN_TOV;
1963 nwwn = ISP_NODEWWN(isp);
1964 pwwn = ISP_PORTWWN(isp);
1967 icbp->icb_fwoptions1 |= ICB2400_OPT1_BOTH_WWNS;
1968 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, nwwn);
1969 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, pwwn);
1970 isp_prt(isp, ISP_LOGDEBUG1,
1971 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1972 ((uint32_t) (nwwn >> 32)),
1973 ((uint32_t) (nwwn & 0xffffffff)),
1974 ((uint32_t) (pwwn >> 32)),
1975 ((uint32_t) (pwwn & 0xffffffff)));
1977 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_BOTH_WWNS;
1978 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, pwwn);
1979 isp_prt(isp, ISP_LOGDEBUG1,
1980 "Setting ICB Port 0x%08x%08x",
1981 ((uint32_t) (pwwn >> 32)),
1982 ((uint32_t) (pwwn & 0xffffffff)));
1984 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
1987 icbp->icb_retry_count = fcp->isp_retry_count;
1989 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1990 if (icbp->icb_rqstqlen < 8) {
1991 isp_prt(isp, ISP_LOGERR, "bad request queue length %d",
1992 icbp->icb_rqstqlen);
1995 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1996 if (icbp->icb_rsltqlen < 8) {
1997 isp_prt(isp, ISP_LOGERR, "bad result queue length %d",
1998 icbp->icb_rsltqlen);
2001 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
2002 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
2003 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
2004 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
2006 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
2007 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
2008 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
2009 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
2011 #ifdef ISP_TARGET_MODE
2012 if (isp->isp_role & ISP_ROLE_TARGET) {
2013 icbp->icb_atioqlen = RESULT_QUEUE_LEN(isp);
2014 if (icbp->icb_atioqlen < 8) {
2015 isp_prt(isp, ISP_LOGERR, "bad ATIO queue length %d",
2016 icbp->icb_atioqlen);
2019 icbp->icb_atioqaddr[RQRSP_ADDR0015] =
2020 DMA_WD0(isp->isp_atioq_dma);
2021 icbp->icb_atioqaddr[RQRSP_ADDR1631] =
2022 DMA_WD1(isp->isp_atioq_dma);
2023 icbp->icb_atioqaddr[RQRSP_ADDR3247] =
2024 DMA_WD2(isp->isp_atioq_dma);
2025 icbp->icb_atioqaddr[RQRSP_ADDR4863] =
2026 DMA_WD3(isp->isp_atioq_dma);
2027 isp_prt(isp, ISP_LOGDEBUG0,
2028 "isp_fibre_init_2400: atioq %04x%04x%04x%04x",
2029 DMA_WD3(isp->isp_atioq_dma), DMA_WD2(isp->isp_atioq_dma),
2030 DMA_WD1(isp->isp_atioq_dma), DMA_WD0(isp->isp_atioq_dma));
2034 isp_prt(isp, ISP_LOGDEBUG0,
2035 "isp_fibre_init_2400: fwopt1 0x%x fwopt2 0x%x fwopt3 0x%x",
2036 icbp->icb_fwoptions1, icbp->icb_fwoptions2, icbp->icb_fwoptions3);
2038 isp_prt(isp, ISP_LOGDEBUG0,
2039 "isp_fibre_init_2400: rqst %04x%04x%04x%04x rsp %04x%04x%04x%04x",
2040 DMA_WD3(isp->isp_rquest_dma), DMA_WD2(isp->isp_rquest_dma),
2041 DMA_WD1(isp->isp_rquest_dma), DMA_WD0(isp->isp_rquest_dma),
2042 DMA_WD3(isp->isp_result_dma), DMA_WD2(isp->isp_result_dma),
2043 DMA_WD1(isp->isp_result_dma), DMA_WD0(isp->isp_result_dma));
2045 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2046 isp_print_bytes(isp, "isp_fibre_init_2400", sizeof (*icbp),
2049 FC_SCRATCH_ACQUIRE(isp);
2050 isp_put_icb_2400(isp, icbp, fcp->isp_scratch);
2056 MEMZERO(&mbs, sizeof (mbs));
2057 mbs.param[0] = MBOX_INIT_FIRMWARE;
2058 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2059 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2060 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2061 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2062 mbs.logval = MBLOGALL;
2063 mbs.timeout = 30 * 1000000;
2064 isp_prt(isp, ISP_LOGDEBUG0, "INIT F/W from %04x%04x%04x%04x",
2065 DMA_WD3(fcp->isp_scdma), DMA_WD2(fcp->isp_scdma),
2066 DMA_WD1(fcp->isp_scdma), DMA_WD0(fcp->isp_scdma));
2067 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp));
2068 isp_mboxcmd(isp, &mbs);
2069 FC_SCRATCH_RELEASE(isp);
2070 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2073 isp->isp_reqidx = 0;
2074 isp->isp_reqodx = 0;
2075 isp->isp_residx = 0;
2078 * Whatever happens, we're now committed to being here.
2080 isp->isp_state = ISP_INITSTATE;
2084 isp_mark_portdb(ispsoftc_t *isp, int onprobation)
2086 fcparam *fcp = (fcparam *) isp->isp_param;
2089 for (i = 0; i < MAX_FC_TARG; i++) {
2090 if (onprobation == 0) {
2091 MEMZERO(&fcp->portdb[i], sizeof (fcportdb_t));
2093 switch (fcp->portdb[i].state) {
2094 case FC_PORTDB_STATE_CHANGED:
2095 case FC_PORTDB_STATE_PENDING_VALID:
2096 case FC_PORTDB_STATE_VALID:
2097 case FC_PORTDB_STATE_PROBATIONAL:
2098 fcp->portdb[i].state =
2099 FC_PORTDB_STATE_PROBATIONAL;
2101 case FC_PORTDB_STATE_ZOMBIE:
2103 case FC_PORTDB_STATE_NIL:
2105 MEMZERO(&fcp->portdb[i], sizeof (fcportdb_t));
2106 fcp->portdb[i].state =
2107 FC_PORTDB_STATE_NIL;
2115 * Perform an IOCB PLOGI or LOGO via EXECUTE IOCB A64 for 24XX cards
2116 * or via FABRIC LOGIN/FABRIC LOGOUT for other cards.
2119 isp_plogx(ispsoftc_t *isp, uint16_t handle, uint32_t portid, int flags, int gs)
2122 uint8_t q[QENTRY_LEN];
2125 uint32_t sst, parm1;
2128 if (!IS_24XX(isp)) {
2129 int action = flags & PLOGX_FLG_CMD_MASK;
2130 if (action == PLOGX_FLG_CMD_PLOGI) {
2131 return (isp_port_login(isp, handle, portid));
2132 } else if (action == PLOGX_FLG_CMD_LOGO) {
2133 return (isp_port_logout(isp, handle, portid));
2135 return (MBOX_INVALID_COMMAND);
2139 MEMZERO(q, QENTRY_LEN);
2140 plp = (isp_plogx_t *) q;
2141 plp->plogx_header.rqs_entry_count = 1;
2142 plp->plogx_header.rqs_entry_type = RQSTYPE_LOGIN;
2143 plp->plogx_handle = 0xffffffff;
2144 plp->plogx_nphdl = handle;
2145 plp->plogx_portlo = portid;
2146 plp->plogx_rspsz_porthi = (portid >> 16) & 0xff;
2147 plp->plogx_flags = flags;
2149 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2150 isp_print_bytes(isp, "IOCB LOGX", QENTRY_LEN, plp);
2154 FC_SCRATCH_ACQUIRE(isp);
2156 scp = FCPARAM(isp)->isp_scratch;
2157 isp_put_plogx(isp, plp, (isp_plogx_t *) scp);
2160 MEMZERO(&mbs, sizeof (mbs));
2161 mbs.param[0] = MBOX_EXEC_COMMAND_IOCB_A64;
2162 mbs.param[1] = QENTRY_LEN;
2163 mbs.param[2] = DMA_WD1(FCPARAM(isp)->isp_scdma);
2164 mbs.param[3] = DMA_WD0(FCPARAM(isp)->isp_scdma);
2165 mbs.param[6] = DMA_WD3(FCPARAM(isp)->isp_scdma);
2166 mbs.param[7] = DMA_WD2(FCPARAM(isp)->isp_scdma);
2167 mbs.timeout = 500000;
2168 mbs.logval = MBLOGALL;
2169 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, QENTRY_LEN);
2170 isp_mboxcmd(isp, &mbs);
2171 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2172 rval = mbs.param[0];
2175 MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN, QENTRY_LEN);
2177 isp_get_plogx(isp, (isp_plogx_t *) scp, plp);
2178 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2179 isp_print_bytes(isp, "IOCB LOGX response", QENTRY_LEN, plp);
2182 if (plp->plogx_status == PLOGX_STATUS_OK) {
2185 } else if (plp->plogx_status != PLOGX_STATUS_IOCBERR) {
2186 isp_prt(isp, ISP_LOGWARN, "status 0x%x on port login IOCB",
2192 sst = plp->plogx_ioparm[0].lo16 | (plp->plogx_ioparm[0].hi16 << 16);
2193 parm1 = plp->plogx_ioparm[1].lo16 | (plp->plogx_ioparm[1].hi16 << 16);
2198 case PLOGX_IOCBERR_NOLINK:
2199 isp_prt(isp, ISP_LOGERR, "PLOGX failed- no link");
2201 case PLOGX_IOCBERR_NOIOCB:
2202 isp_prt(isp, ISP_LOGERR, "PLOGX failed- no IOCB buffer");
2204 case PLOGX_IOCBERR_NOXGHG:
2205 isp_prt(isp, ISP_LOGERR,
2206 "PLOGX failed- no Exchange Control Block");
2208 case PLOGX_IOCBERR_FAILED:
2209 isp_prt(isp, ISP_LOGERR,
2210 "PLOGX(0x%x) of Port 0x%06x failed: reason 0x%x (last LOGIN"
2211 " state 0x%x)", flags, portid, parm1 & 0xff,
2212 (parm1 >> 8) & 0xff);
2214 case PLOGX_IOCBERR_NOFABRIC:
2215 isp_prt(isp, ISP_LOGERR, "PLOGX failed- no fabric");
2217 case PLOGX_IOCBERR_NOTREADY:
2218 isp_prt(isp, ISP_LOGERR, "PLOGX failed- f/w not ready");
2220 case PLOGX_IOCBERR_NOLOGIN:
2221 isp_prt(isp, ISP_LOGERR,
2222 "PLOGX failed- not logged in (last LOGIN state 0x%x)",
2224 rval = MBOX_NOT_LOGGED_IN;
2226 case PLOGX_IOCBERR_REJECT:
2227 isp_prt(isp, ISP_LOGERR, "PLOGX failed: LS_RJT = 0x%x", parm1);
2229 case PLOGX_IOCBERR_NOPCB:
2230 isp_prt(isp, ISP_LOGERR, "PLOGX failed- no PCB allocated");
2232 case PLOGX_IOCBERR_EINVAL:
2233 isp_prt(isp, ISP_LOGERR,
2234 "PLOGX failed: invalid parameter at offset 0x%x", parm1);
2236 case PLOGX_IOCBERR_PORTUSED:
2237 isp_prt(isp, ISP_LOGDEBUG0,
2238 "portid 0x%x already logged in with N-port handle 0x%x",
2240 rval = MBOX_PORT_ID_USED | (handle << 16);
2242 case PLOGX_IOCBERR_HNDLUSED:
2243 isp_prt(isp, ISP_LOGDEBUG0,
2244 "N-port handle 0x%x already used for portid 0x%x",
2246 rval = MBOX_LOOP_ID_USED;
2248 case PLOGX_IOCBERR_NOHANDLE:
2249 isp_prt(isp, ISP_LOGERR, "PLOGX failed- no handle allocated");
2251 case PLOGX_IOCBERR_NOFLOGI:
2252 isp_prt(isp, ISP_LOGERR, "PLOGX failed- no FLOGI_ACC");
2255 isp_prt(isp, ISP_LOGERR, "status %x from %x", plp->plogx_status,
2262 FC_SCRATCH_RELEASE(isp);
2268 isp_port_login(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2272 MEMZERO(&mbs, sizeof (mbs));
2273 mbs.param[0] = MBOX_FABRIC_LOGIN;
2274 if (FCPARAM(isp)->isp_2klogin) {
2275 mbs.param[1] = handle;
2276 mbs.ibits = (1 << 10);
2278 mbs.param[1] = handle << 8;
2280 mbs.param[2] = portid >> 16;
2281 mbs.param[3] = portid;
2282 mbs.logval = MBLOGNONE;
2283 mbs.timeout = 500000;
2284 isp_mboxcmd(isp, &mbs);
2286 switch (mbs.param[0]) {
2287 case MBOX_PORT_ID_USED:
2288 isp_prt(isp, ISP_LOGDEBUG0,
2289 "isp_plogi_old: portid 0x%06x already logged in as %u",
2290 portid, mbs.param[1]);
2291 return (MBOX_PORT_ID_USED | (mbs.param[1] << 16));
2293 case MBOX_LOOP_ID_USED:
2294 isp_prt(isp, ISP_LOGDEBUG0,
2295 "isp_plogi_old: handle %u in use for port id 0x%02xXXXX",
2296 handle, mbs.param[1] & 0xff);
2297 return (MBOX_LOOP_ID_USED);
2299 case MBOX_COMMAND_COMPLETE:
2302 case MBOX_COMMAND_ERROR:
2303 isp_prt(isp, ISP_LOGINFO,
2304 "isp_plogi_old: error 0x%x in PLOGI to port 0x%06x",
2305 mbs.param[1], portid);
2306 return (MBOX_COMMAND_ERROR);
2308 case MBOX_ALL_IDS_USED:
2309 isp_prt(isp, ISP_LOGINFO,
2310 "isp_plogi_old: all IDs used for fabric login");
2311 return (MBOX_ALL_IDS_USED);
2314 isp_prt(isp, ISP_LOGINFO,
2315 "isp_plogi_old: error 0x%x on port login of 0x%06x@0x%0x",
2316 mbs.param[0], portid, handle);
2317 return (mbs.param[0]);
2322 isp_port_logout(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2326 MEMZERO(&mbs, sizeof (mbs));
2327 mbs.param[0] = MBOX_FABRIC_LOGOUT;
2328 if (FCPARAM(isp)->isp_2klogin) {
2329 mbs.param[1] = handle;
2330 mbs.ibits = (1 << 10);
2332 mbs.param[1] = handle << 8;
2334 mbs.logval = MBLOGNONE;
2335 mbs.timeout = 100000;
2336 isp_mboxcmd(isp, &mbs);
2337 return (mbs.param[0] == MBOX_COMMAND_COMPLETE? 0 : mbs.param[0]);
2341 isp_getpdb(ispsoftc_t *isp, uint16_t id, isp_pdb_t *pdb, int dolock)
2343 fcparam *fcp = (fcparam *) isp->isp_param;
2346 isp_pdb_21xx_t fred;
2347 isp_pdb_24xx_t bill;
2350 MEMZERO(&mbs, sizeof (mbs));
2351 mbs.param[0] = MBOX_GET_PORT_DB;
2355 } else if (FCPARAM(isp)->isp_2klogin) {
2357 mbs.ibits = (1 << 10);
2359 mbs.param[1] = id << 8;
2361 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2362 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2363 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2364 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2365 mbs.timeout = 250000;
2366 mbs.logval = MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR;
2368 FC_SCRATCH_ACQUIRE(isp);
2370 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (un));
2371 isp_mboxcmd(isp, &mbs);
2372 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2374 FC_SCRATCH_RELEASE(isp);
2379 isp_get_pdb_24xx(isp, fcp->isp_scratch, &un.bill);
2380 pdb->handle = un.bill.pdb_handle;
2381 pdb->s3_role = un.bill.pdb_prli_svc3;
2382 pdb->portid = BITS2WORD_24XX(un.bill.pdb_portid_bits);
2383 MEMCPY(pdb->portname, un.bill.pdb_portname, 8);
2384 MEMCPY(pdb->nodename, un.bill.pdb_nodename, 8);
2386 isp_get_pdb_21xx(isp, fcp->isp_scratch, &un.fred);
2387 pdb->handle = un.fred.pdb_loopid;
2388 pdb->s3_role = un.fred.pdb_prli_svc3;
2389 pdb->portid = BITS2WORD(un.fred.pdb_portid_bits);
2390 MEMCPY(pdb->portname, un.fred.pdb_portname, 8);
2391 MEMCPY(pdb->nodename, un.fred.pdb_nodename, 8);
2394 FC_SCRATCH_RELEASE(isp);
2400 isp_get_portname(ispsoftc_t *isp, int loopid, int nodename)
2402 uint64_t wwn = (uint64_t) -1;
2405 MEMZERO(&mbs, sizeof (mbs));
2406 mbs.param[0] = MBOX_GET_PORT_NAME;
2407 if (FCPARAM(isp)->isp_2klogin || IS_24XX(isp)) {
2408 mbs.param[1] = loopid;
2409 mbs.ibits = (1 << 10);
2414 mbs.param[1] = loopid << 8;
2419 mbs.logval = MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR;
2420 isp_mboxcmd(isp, &mbs);
2421 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2426 (((uint64_t)(mbs.param[2] >> 8)) << 56) |
2427 (((uint64_t)(mbs.param[2] & 0xff)) << 48) |
2428 (((uint64_t)(mbs.param[3] >> 8)) << 40) |
2429 (((uint64_t)(mbs.param[3] & 0xff)) << 32) |
2430 (((uint64_t)(mbs.param[6] >> 8)) << 24) |
2431 (((uint64_t)(mbs.param[6] & 0xff)) << 16) |
2432 (((uint64_t)(mbs.param[7] >> 8)) << 8) |
2433 (((uint64_t)(mbs.param[7] & 0xff)));
2436 (((uint64_t)(mbs.param[2] & 0xff)) << 56) |
2437 (((uint64_t)(mbs.param[2] >> 8)) << 48) |
2438 (((uint64_t)(mbs.param[3] & 0xff)) << 40) |
2439 (((uint64_t)(mbs.param[3] >> 8)) << 32) |
2440 (((uint64_t)(mbs.param[6] & 0xff)) << 24) |
2441 (((uint64_t)(mbs.param[6] >> 8)) << 16) |
2442 (((uint64_t)(mbs.param[7] & 0xff)) << 8) |
2443 (((uint64_t)(mbs.param[7] >> 8)));
2449 * Make sure we have good FC link.
2453 isp_fclink_test(ispsoftc_t *isp, int usdelay)
2455 static const char *toponames[] = {
2460 "F Port (no FLOGI_ACC response)"
2463 int count, check_for_fabric;
2470 fcp = isp->isp_param;
2472 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "FC Link Test Entry");
2473 ISP_MARK_PORTDB(isp, 1);
2476 * Wait up to N microseconds for F/W to go to a ready state.
2478 lwfs = FW_CONFIG_WAIT;
2480 while (count < usdelay) {
2483 NANOTIME_T hra, hrb;
2487 if (lwfs != fcp->isp_fwstate) {
2488 isp_prt(isp, ISP_LOGCONFIG|ISP_LOGSANCFG,
2489 "Firmware State <%s->%s>",
2490 ispfc_fw_statename((int)lwfs),
2491 ispfc_fw_statename((int)fcp->isp_fwstate));
2492 lwfs = fcp->isp_fwstate;
2494 if (fcp->isp_fwstate == FW_READY) {
2500 * Get the elapsed time in nanoseconds.
2501 * Always guaranteed to be non-zero.
2503 enano = NANOTIME_SUB(&hrb, &hra);
2505 isp_prt(isp, ISP_LOGDEBUG1,
2506 "usec%d: 0x%lx->0x%lx enano 0x%x%08x",
2507 count, (long) GET_NANOSEC(&hra), (long) GET_NANOSEC(&hrb),
2508 (uint32_t)(enano >> 32), (uint32_t)(enano & 0xffffffff));
2511 * If the elapsed time is less than 1 millisecond,
2512 * delay a period of time up to that millisecond of
2515 * This peculiar code is an attempt to try and avoid
2516 * invoking uint64_t math support functions for some
2517 * platforms where linkage is a problem.
2519 if (enano < (1000 * 1000)) {
2521 enano = (1000 * 1000) - enano;
2522 while (enano > (uint64_t) 4000000000U) {
2523 USEC_SLEEP(isp, 4000000);
2524 enano -= (uint64_t) 4000000000U;
2528 USEC_SLEEP(isp, wrk);
2530 while (enano > (uint64_t) 4000000000U) {
2532 enano -= (uint64_t) 4000000000U;
2535 count += (wrk / 1000);
2540 * If we haven't gone to 'ready' state, return.
2542 if (fcp->isp_fwstate != FW_READY) {
2543 isp_prt(isp, ISP_LOGSANCFG,
2544 "isp_fclink_test: not at FW_READY state");
2549 * Get our Loop ID and Port ID.
2551 MEMZERO(&mbs, sizeof (mbs));
2552 mbs.param[0] = MBOX_GET_LOOP_ID;
2553 mbs.logval = MBLOGALL;
2554 isp_mboxcmd(isp, &mbs);
2555 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2559 if (FCPARAM(isp)->isp_2klogin) {
2560 fcp->isp_loopid = mbs.param[1];
2562 fcp->isp_loopid = mbs.param[1] & 0xff;
2566 fcp->isp_topo = TOPO_NL_PORT;
2568 int topo = (int) mbs.param[6];
2569 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB) {
2570 topo = TOPO_PTP_STUB;
2572 fcp->isp_topo = topo;
2574 fcp->isp_portid = mbs.param[2] | (mbs.param[3] << 16);
2578 * Don't bother with fabric if we are using really old
2579 * 2100 firmware. It's just not worth it.
2581 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37)) {
2582 check_for_fabric = 1;
2584 check_for_fabric = 0;
2586 } else if (fcp->isp_topo == TOPO_FL_PORT ||
2587 fcp->isp_topo == TOPO_F_PORT) {
2588 check_for_fabric = 1;
2590 check_for_fabric = 0;
2599 if (check_for_fabric && isp_getpdb(isp, loopid, &pdb, 1) == 0) {
2602 fcp->isp_topo = TOPO_FL_PORT;
2604 if (pdb.portid == 0) {
2608 fcp->isp_topo = TOPO_NL_PORT;
2613 * Save the Fabric controller's port database entry.
2615 lp = &fcp->portdb[FL_ID];
2616 lp->state = FC_PORTDB_STATE_PENDING_VALID;
2617 MAKE_WWN_FROM_NODE_NAME(lp->node_wwn, pdb.nodename);
2618 MAKE_WWN_FROM_NODE_NAME(lp->port_wwn, pdb.portname);
2619 lp->roles = (pdb.s3_role & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2620 lp->portid = pdb.portid;
2621 lp->handle = pdb.handle;
2622 lp->new_portid = lp->portid;
2623 lp->new_roles = lp->roles;
2625 r = isp_register_fc4_type_24xx(isp);
2627 r = isp_register_fc4_type(isp);
2630 isp_prt(isp, ISP_LOGSANCFG,
2631 "isp_fclink_test: register fc4 type failed");
2636 fcp->portdb[FL_ID].state = FC_PORTDB_STATE_NIL;
2639 fcp->isp_gbspeed = 1;
2640 if (IS_23XX(isp) || IS_24XX(isp)) {
2641 MEMZERO(&mbs, sizeof (mbs));
2642 mbs.param[0] = MBOX_GET_SET_DATA_RATE;
2643 mbs.param[1] = MBGSD_GET_RATE;
2644 /* mbs.param[2] undefined if we're just getting rate */
2645 mbs.logval = MBLOGALL;
2646 mbs.timeout = 3000000;
2647 isp_mboxcmd(isp, &mbs);
2648 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
2649 if (mbs.param[1] == MBGSD_FOURGB) {
2650 isp_prt(isp, ISP_LOGINFO, "4Gb link speed/s");
2651 fcp->isp_gbspeed = 4;
2652 } if (mbs.param[1] == MBGSD_TWOGB) {
2653 isp_prt(isp, ISP_LOGINFO, "2Gb link speed/s");
2654 fcp->isp_gbspeed = 2;
2660 * Announce ourselves, too.
2662 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGCONFIG, topology, fcp->isp_portid,
2663 fcp->isp_loopid, toponames[fcp->isp_topo]);
2664 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGCONFIG, ourwwn,
2665 (uint32_t) (ISP_NODEWWN(isp) >> 32),
2666 (uint32_t) ISP_NODEWWN(isp),
2667 (uint32_t) (ISP_PORTWWN(isp) >> 32),
2668 (uint32_t) ISP_PORTWWN(isp));
2669 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "FC Link Test Complete");
2674 ispfc_fw_statename(int state)
2677 case FW_CONFIG_WAIT: return "Config Wait";
2678 case FW_WAIT_AL_PA: return "Waiting for AL_PA";
2679 case FW_WAIT_LOGIN: return "Wait Login";
2680 case FW_READY: return "Ready";
2681 case FW_LOSS_OF_SYNC: return "Loss Of Sync";
2682 case FW_ERROR: return "Error";
2683 case FW_REINIT: return "Re-Init";
2684 case FW_NON_PART: return "Nonparticipating";
2685 default: return "?????";
2690 * Complete the synchronization of our Port Database.
2692 * At this point, we've scanned the local loop (if any) and the fabric
2693 * and performed fabric logins on all new devices.
2695 * Our task here is to go through our port database and remove any entities
2696 * that are still marked probational (issuing PLOGO for ones which we had
2697 * PLOGI'd into) or are dead.
2699 * Our task here is to also check policy to decide whether devices which
2700 * have *changed* in some way should still be kept active. For example,
2701 * if a device has just changed PortID, we can either elect to treat it
2702 * as an old device or as a newly arrived device (and notify the outer
2703 * layer appropriately).
2705 * We also do initiator map target id assignment here for new initiator
2706 * devices and refresh old ones ot make sure that they point to the corret
2710 isp_pdb_sync(ispsoftc_t *isp)
2712 fcparam *fcp = isp->isp_param;
2716 if (fcp->isp_loopstate == LOOP_READY) {
2721 * Make sure we're okay for doing this right now.
2723 if (fcp->isp_loopstate != LOOP_PDB_RCVD &&
2724 fcp->isp_loopstate != LOOP_FSCAN_DONE &&
2725 fcp->isp_loopstate != LOOP_LSCAN_DONE) {
2726 isp_prt(isp, ISP_LOGWARN, "isp_pdb_sync: bad loopstate %d",
2727 fcp->isp_loopstate);
2731 if (fcp->isp_topo == TOPO_FL_PORT ||
2732 fcp->isp_topo == TOPO_NL_PORT ||
2733 fcp->isp_topo == TOPO_N_PORT) {
2734 if (fcp->isp_loopstate < LOOP_LSCAN_DONE) {
2735 if (isp_scan_loop(isp) != 0) {
2736 isp_prt(isp, ISP_LOGWARN,
2737 "isp_pdb_sync: isp_scan_loop failed");
2743 if (fcp->isp_topo == TOPO_F_PORT || fcp->isp_topo == TOPO_FL_PORT) {
2744 if (fcp->isp_loopstate < LOOP_FSCAN_DONE) {
2745 if (isp_scan_fabric(isp) != 0) {
2746 isp_prt(isp, ISP_LOGWARN,
2747 "isp_pdb_sync: isp_scan_fabric failed");
2753 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "Synchronizing PDBs");
2755 fcp->isp_loopstate = LOOP_SYNCING_PDB;
2757 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
2758 lp = &fcp->portdb[dbidx];
2760 if (lp->state == FC_PORTDB_STATE_NIL) {
2764 if (lp->state == FC_PORTDB_STATE_VALID) {
2765 if (dbidx != FL_ID) {
2767 ISP_LOGERR, "portdb idx %d already valid",
2773 switch (lp->state) {
2774 case FC_PORTDB_STATE_PROBATIONAL:
2775 case FC_PORTDB_STATE_DEAD:
2777 * It's up to the outer layers to clear isp_ini_map.
2779 lp->state = FC_PORTDB_STATE_NIL;
2780 isp_async(isp, ISPASYNC_DEV_GONE, lp);
2781 if (lp->autologin == 0) {
2782 (void) isp_plogx(isp, lp->handle, lp->portid,
2783 PLOGX_FLG_CMD_LOGO |
2784 PLOGX_FLG_IMPLICIT |
2785 PLOGX_FLG_FREE_NPHDL, 0);
2792 * Note that we might come out of this with our state
2793 * set to FC_PORTDB_STATE_ZOMBIE.
2796 case FC_PORTDB_STATE_NEW:
2798 * It's up to the outer layers to assign a virtual
2799 * target id in isp_ini_map (if any).
2801 lp->portid = lp->new_portid;
2802 lp->roles = lp->new_roles;
2803 lp->state = FC_PORTDB_STATE_VALID;
2804 isp_async(isp, ISPASYNC_DEV_ARRIVED, lp);
2808 lp->new_reserved = 0;
2810 case FC_PORTDB_STATE_CHANGED:
2814 lp->state = FC_PORTDB_STATE_VALID;
2815 isp_async(isp, ISPASYNC_DEV_CHANGED, lp);
2819 lp->new_reserved = 0;
2821 case FC_PORTDB_STATE_PENDING_VALID:
2822 lp->portid = lp->new_portid;
2823 lp->roles = lp->new_roles;
2824 if (lp->ini_map_idx) {
2825 int t = lp->ini_map_idx - 1;
2826 fcp->isp_ini_map[t] = dbidx + 1;
2828 lp->state = FC_PORTDB_STATE_VALID;
2829 isp_async(isp, ISPASYNC_DEV_STAYED, lp);
2830 if (dbidx != FL_ID) {
2835 lp->new_reserved = 0;
2837 case FC_PORTDB_STATE_ZOMBIE:
2840 isp_prt(isp, ISP_LOGWARN,
2841 "isp_scan_loop: state %d for idx %d",
2843 isp_dump_portdb(isp);
2848 * If we get here, we've for sure seen not only a valid loop
2849 * but know what is or isn't on it, so mark this for usage
2852 fcp->loop_seen_once = 1;
2853 fcp->isp_loopstate = LOOP_READY;
2858 * Scan local loop for devices.
2861 isp_scan_loop(ispsoftc_t *isp)
2863 fcportdb_t *lp, tmp;
2864 fcparam *fcp = isp->isp_param;
2867 uint16_t handle, lim = 0;
2869 if (fcp->isp_fwstate < FW_READY ||
2870 fcp->isp_loopstate < LOOP_PDB_RCVD) {
2874 if (fcp->isp_loopstate > LOOP_SCANNING_LOOP) {
2879 * Check our connection topology.
2881 * If we're a public or private loop, we scan 0..125 as handle values.
2882 * The firmware has (typically) peformed a PLOGI for us.
2884 * If we're a N-port connection, we treat this is a short loop (0..1).
2886 * If we're in target mode, we can all possible handles to see who
2887 * might have logged into us.
2889 switch (fcp->isp_topo) {
2892 lim = LOCAL_LOOP_LIM;
2898 isp_prt(isp, ISP_LOGDEBUG0, "no loop topology to scan");
2899 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2903 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
2905 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "FC scan loop 0..%d", lim-1);
2909 * Run through the list and get the port database info for each one.
2911 for (handle = 0; handle < lim; handle++) {
2913 * But don't even try for ourselves...
2915 if (handle == fcp->isp_loopid) {
2920 * In older cards with older f/w GET_PORT_DATABASE has been
2921 * known to hang. This trick gets around that problem.
2923 if (IS_2100(isp) || IS_2200(isp)) {
2924 uint64_t node_wwn = isp_get_portname(isp, handle, 1);
2925 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2928 if (node_wwn == 0) {
2934 * Get the port database entity for this index.
2936 if (isp_getpdb(isp, handle, &pdb, 1) != 0) {
2937 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2938 ISP_MARK_PORTDB(isp, 1);
2944 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2945 ISP_MARK_PORTDB(isp, 1);
2950 * On *very* old 2100 firmware we would end up sometimes
2951 * with the firmware returning the port database entry
2952 * for something else. We used to restart this, but
2955 if (IS_2100(isp) && pdb.handle != handle) {
2956 isp_prt(isp, ISP_LOGWARN,
2957 "giving up on synchronizing the port database");
2958 ISP_MARK_PORTDB(isp, 1);
2963 * Save the pertinent info locally.
2965 MAKE_WWN_FROM_NODE_NAME(tmp.node_wwn, pdb.nodename);
2966 MAKE_WWN_FROM_NODE_NAME(tmp.port_wwn, pdb.portname);
2967 tmp.roles = (pdb.s3_role & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2968 tmp.portid = pdb.portid;
2969 tmp.handle = pdb.handle;
2972 * Check to make sure it's still a valid entry. The 24XX seems
2973 * to return a portid but not a WWPN/WWNN or role for devices
2974 * which shift on a loop.
2976 if (tmp.node_wwn == 0 || tmp.port_wwn == 0 || tmp.portid == 0) {
2978 a = (tmp.node_wwn == 0);
2979 b = (tmp.port_wwn == 0);
2980 c = (tmp.portid == 0);
2981 isp_prt(isp, ISP_LOGWARN,
2982 "bad pdb (%1d%1d%1d) @ handle 0x%x", a, b, c,
2984 isp_dump_portdb(isp);
2989 * Now search the entire port database
2990 * for the same Port and Node WWN.
2992 for (i = 0; i < MAX_FC_TARG; i++) {
2993 lp = &fcp->portdb[i];
2994 if (lp->state == FC_PORTDB_STATE_NIL) {
2997 if (lp->node_wwn != tmp.node_wwn) {
3000 if (lp->port_wwn != tmp.port_wwn) {
3005 * Okay- we've found a non-nil entry that matches.
3006 * Check to make sure it's probational or a zombie.
3008 if (lp->state != FC_PORTDB_STATE_PROBATIONAL &&
3009 lp->state != FC_PORTDB_STATE_ZOMBIE) {
3010 isp_prt(isp, ISP_LOGERR,
3011 "[%d] not probational/zombie (0x%x)",
3013 isp_dump_portdb(isp);
3014 ISP_MARK_PORTDB(isp, 1);
3019 * Mark the device as something the f/w logs into
3025 * Check to make see if really still the same
3026 * device. If it is, we mark it pending valid.
3028 if (lp->portid == tmp.portid &&
3029 lp->handle == tmp.handle &&
3030 lp->roles == tmp.roles) {
3031 lp->new_portid = tmp.portid;
3032 lp->new_roles = tmp.roles;
3033 lp->state = FC_PORTDB_STATE_PENDING_VALID;
3034 isp_prt(isp, ISP_LOGSANCFG,
3035 "Loop Port 0x%02x@0x%x Pending Valid",
3036 tmp.portid, tmp.handle);
3041 * We can wipe out the old handle value
3042 * here because it's no longer valid.
3044 lp->handle = tmp.handle;
3047 * Claim that this has changed and let somebody else
3048 * decide what to do.
3050 isp_prt(isp, ISP_LOGSANCFG,
3051 "Loop Port 0x%02x@0x%x changed",
3052 tmp.portid, tmp.handle);
3053 lp->state = FC_PORTDB_STATE_CHANGED;
3054 lp->new_portid = tmp.portid;
3055 lp->new_roles = tmp.roles;
3060 * Did we find and update an old entry?
3062 if (i < MAX_FC_TARG) {
3067 * Ah. A new device entry. Find an empty slot
3068 * for it and save info for later disposition.
3070 for (i = 0; i < MAX_FC_TARG; i++) {
3071 if (fcp->portdb[i].state == FC_PORTDB_STATE_NIL) {
3075 if (i == MAX_FC_TARG) {
3076 isp_prt(isp, ISP_LOGERR, "out of portdb entries");
3079 lp = &fcp->portdb[i];
3081 MEMZERO(lp, sizeof (fcportdb_t));
3083 lp->state = FC_PORTDB_STATE_NEW;
3084 lp->new_portid = tmp.portid;
3085 lp->new_roles = tmp.roles;
3086 lp->handle = tmp.handle;
3087 lp->port_wwn = tmp.port_wwn;
3088 lp->node_wwn = tmp.node_wwn;
3089 isp_prt(isp, ISP_LOGSANCFG,
3090 "Loop Port 0x%02x@0x%x is New Entry",
3091 tmp.portid, tmp.handle);
3093 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3098 * Scan the fabric for devices and add them to our port database.
3100 * Use the GID_FT command to get all Port IDs for FC4 SCSI devices it knows.
3102 * For 2100-23XX cards, we can use the SNS mailbox command to pass simple
3103 * name server commands to the switch management server via the QLogic f/w.
3105 * For the 24XX card, we have to use CT-Pass through run via the Execute IOCB
3108 * The net result is to leave the list of Port IDs setting untranslated in
3109 * offset IGPOFF of the FC scratch area, whereupon we'll canonicalize it to
3110 * host order at OGPOFF.
3114 * Take less than half of our scratch area to store Port IDs
3116 #define GIDLEN ((ISP2100_SCRLEN >> 1) - 16 - SNS_GID_FT_REQ_SIZE)
3117 #define NGENT ((GIDLEN - 16) >> 2)
3119 #define IGPOFF (2 * QENTRY_LEN)
3120 #define OGPOFF (ISP2100_SCRLEN >> 1)
3121 #define ZTXOFF (ISP2100_SCRLEN - (1 * QENTRY_LEN))
3122 #define CTXOFF (ISP2100_SCRLEN - (2 * QENTRY_LEN))
3123 #define XTXOFF (ISP2100_SCRLEN - (3 * QENTRY_LEN))
3126 isp_gid_ft_sns(ispsoftc_t *isp)
3129 sns_gid_ft_req_t _x;
3130 uint8_t _y[SNS_GID_FT_REQ_SIZE];
3132 fcparam *fcp = FCPARAM(isp);
3133 sns_gid_ft_req_t *rq = &un._x;
3136 isp_prt(isp, ISP_LOGDEBUG0, "scanning fabric (GID_FT) via SNS");
3138 MEMZERO(rq, SNS_GID_FT_REQ_SIZE);
3139 rq->snscb_rblen = GIDLEN >> 1;
3140 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + IGPOFF);
3141 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + IGPOFF);
3142 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + IGPOFF);
3143 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + IGPOFF);
3144 rq->snscb_sblen = 6;
3145 rq->snscb_cmd = SNS_GID_FT;
3146 rq->snscb_mword_div_2 = NGENT;
3147 rq->snscb_fc4_type = FC4_SCSI;
3149 isp_put_gid_ft_request(isp, rq, fcp->isp_scratch);
3150 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE);
3152 MEMZERO(&mbs, sizeof (mbs));
3153 mbs.param[0] = MBOX_SEND_SNS;
3154 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
3155 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
3156 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
3157 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
3158 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
3159 mbs.logval = MBLOGALL;
3160 mbs.timeout = 10000000;
3161 isp_mboxcmd(isp, &mbs);
3162 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3163 if (mbs.param[0] == MBOX_INVALID_COMMAND) {
3173 isp_gid_ft_ct_passthru(ispsoftc_t *isp)
3176 fcparam *fcp = FCPARAM(isp);
3180 uint8_t q[QENTRY_LEN];
3185 uint8_t *scp = fcp->isp_scratch;
3187 isp_prt(isp, ISP_LOGDEBUG0, "scanning fabric (GID_FT) via CT");
3189 if (!IS_24XX(isp)) {
3194 * Build a Passthrough IOCB in memory.
3197 MEMZERO(un.q, QENTRY_LEN);
3198 pt->ctp_header.rqs_entry_count = 1;
3199 pt->ctp_header.rqs_entry_type = RQSTYPE_CT_PASSTHRU;
3200 pt->ctp_handle = 0xffffffff;
3201 pt->ctp_nphdl = NPH_SNS_ID;
3202 pt->ctp_cmd_cnt = 1;
3204 pt->ctp_rsp_cnt = 1;
3205 pt->ctp_rsp_bcnt = GIDLEN;
3206 pt->ctp_cmd_bcnt = sizeof (*ct) + sizeof (uint32_t);
3207 pt->ctp_dataseg[0].ds_base = DMA_LO32(fcp->isp_scdma+XTXOFF);
3208 pt->ctp_dataseg[0].ds_basehi = DMA_HI32(fcp->isp_scdma+XTXOFF);
3209 pt->ctp_dataseg[0].ds_count = sizeof (*ct) + sizeof (uint32_t);
3210 pt->ctp_dataseg[1].ds_base = DMA_LO32(fcp->isp_scdma+IGPOFF);
3211 pt->ctp_dataseg[1].ds_basehi = DMA_HI32(fcp->isp_scdma+IGPOFF);
3212 pt->ctp_dataseg[1].ds_count = GIDLEN;
3213 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3214 isp_print_bytes(isp, "ct IOCB", QENTRY_LEN, pt);
3216 isp_put_ct_pt(isp, pt, (isp_ct_pt_t *) &scp[CTXOFF]);
3219 * Build the CT header and command in memory.
3221 * Note that the CT header has to end up as Big Endian format in memory.
3224 MEMZERO(ct, sizeof (*ct));
3225 ct->ct_revision = CT_REVISION;
3226 ct->ct_fcs_type = CT_FC_TYPE_FC;
3227 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3228 ct->ct_cmd_resp = SNS_GID_FT;
3229 ct->ct_bcnt_resid = (GIDLEN - 16) >> 2;
3231 isp_put_ct_hdr(isp, ct, (ct_hdr_t *) &scp[XTXOFF]);
3232 rp = (uint32_t *) &scp[XTXOFF+sizeof (*ct)];
3233 ISP_IOZPUT_32(isp, FC4_SCSI, rp);
3234 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3235 isp_print_bytes(isp, "CT HDR + payload after put",
3236 sizeof (*ct) + sizeof (uint32_t), &scp[XTXOFF]);
3238 MEMZERO(&scp[ZTXOFF], QENTRY_LEN);
3239 MEMZERO(&mbs, sizeof (mbs));
3240 mbs.param[0] = MBOX_EXEC_COMMAND_IOCB_A64;
3241 mbs.param[1] = QENTRY_LEN;
3242 mbs.param[2] = DMA_WD1(fcp->isp_scdma + CTXOFF);
3243 mbs.param[3] = DMA_WD0(fcp->isp_scdma + CTXOFF);
3244 mbs.param[6] = DMA_WD3(fcp->isp_scdma + CTXOFF);
3245 mbs.param[7] = DMA_WD2(fcp->isp_scdma + CTXOFF);
3246 mbs.timeout = 500000;
3247 mbs.logval = MBLOGALL;
3248 MEMORYBARRIER(isp, SYNC_SFORDEV, XTXOFF, 2 * QENTRY_LEN);
3249 isp_mboxcmd(isp, &mbs);
3250 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3253 MEMORYBARRIER(isp, SYNC_SFORCPU, ZTXOFF, QENTRY_LEN);
3255 isp_get_ct_pt(isp, (isp_ct_pt_t *) &scp[ZTXOFF], pt);
3256 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3257 isp_print_bytes(isp, "IOCB response", QENTRY_LEN, pt);
3260 if (pt->ctp_status && pt->ctp_status != RQCS_DATA_UNDERRUN) {
3261 isp_prt(isp, ISP_LOGWARN, "CT Passthrough returned 0x%x",
3265 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN + 16);
3266 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3267 isp_print_bytes(isp, "CT response", GIDLEN+16, &scp[IGPOFF]);
3273 isp_scan_fabric(ispsoftc_t *isp)
3275 fcparam *fcp = FCPARAM(isp);
3277 uint16_t handle, oldhandle;
3278 int portidx, portlim, r;
3279 sns_gid_ft_rsp_t *rs0, *rs1;
3281 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "FC Scan Fabric");
3282 if (fcp->isp_fwstate != FW_READY ||
3283 fcp->isp_loopstate < LOOP_LSCAN_DONE) {
3286 if (fcp->isp_loopstate > LOOP_SCANNING_FABRIC) {
3289 if (fcp->isp_topo != TOPO_FL_PORT && fcp->isp_topo != TOPO_F_PORT) {
3290 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3291 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3292 "FC Scan Fabric Done (no fabric)");
3296 FC_SCRATCH_ACQUIRE(isp);
3297 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
3300 r = isp_gid_ft_ct_passthru(isp);
3302 r = isp_gid_ft_sns(isp);
3306 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3307 FC_SCRATCH_RELEASE(isp);
3310 fcp->isp_loopstate = LOOP_PDB_RCVD; /* try again */
3311 FC_SCRATCH_RELEASE(isp);
3314 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
3315 FC_SCRATCH_RELEASE(isp);
3319 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN);
3320 rs0 = (sns_gid_ft_rsp_t *) ((uint8_t *)fcp->isp_scratch+IGPOFF);
3321 rs1 = (sns_gid_ft_rsp_t *) ((uint8_t *)fcp->isp_scratch+OGPOFF);
3322 isp_get_gid_ft_response(isp, rs0, rs1, NGENT);
3323 if (rs1->snscb_cthdr.ct_cmd_resp != LS_ACC) {
3325 if (rs1->snscb_cthdr.ct_reason == 9 &&
3326 rs1->snscb_cthdr.ct_explanation == 7) {
3327 level = ISP_LOGSANCFG|ISP_LOGDEBUG0;
3329 level = ISP_LOGWARN;
3331 isp_prt(isp, level, "Fabric Nameserver rejected GID_FT "
3332 "(Reason=0x%x Expl=0x%x)", rs1->snscb_cthdr.ct_reason,
3333 rs1->snscb_cthdr.ct_explanation);
3334 FC_SCRATCH_RELEASE(isp);
3335 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3341 * If we get this far, we certainly still have the fabric controller.
3343 fcp->portdb[FL_ID].state = FC_PORTDB_STATE_PENDING_VALID;
3346 * Prime the handle we will start using.
3348 oldhandle = NIL_HANDLE;
3351 * Okay, we now have a list of Port IDs for all FC4 SCSI devices
3352 * that the Fabric Name server knows about. Go through the list
3353 * and remove duplicate port ids.
3358 for (portidx = 0; portidx < NGENT-1; portidx++) {
3359 if (rs1->snscb_ports[portidx].control & 0x80) {
3365 * If we're not at the last entry, our list wasn't big enough.
3367 if ((rs1->snscb_ports[portidx].control & 0x80) == 0) {
3368 isp_prt(isp, ISP_LOGWARN,
3369 "fabric too big for scratch area: increase ISP2100_SCRLEN");
3371 portlim = portidx + 1;
3372 isp_prt(isp, ISP_LOGSANCFG,
3373 "got %d ports back from name server", portlim);
3375 for (portidx = 0; portidx < portlim; portidx++) {
3379 ((rs1->snscb_ports[portidx].portid[0]) << 16) |
3380 ((rs1->snscb_ports[portidx].portid[1]) << 8) |
3381 ((rs1->snscb_ports[portidx].portid[2]));
3383 for (npidx = portidx + 1; npidx < portlim; npidx++) {
3384 uint32_t new_portid =
3385 ((rs1->snscb_ports[npidx].portid[0]) << 16) |
3386 ((rs1->snscb_ports[npidx].portid[1]) << 8) |
3387 ((rs1->snscb_ports[npidx].portid[2]));
3388 if (new_portid == portid) {
3393 if (npidx < portlim) {
3394 rs1->snscb_ports[npidx].portid[0] = 0;
3395 rs1->snscb_ports[npidx].portid[1] = 0;
3396 rs1->snscb_ports[npidx].portid[2] = 0;
3397 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3398 "removing duplicate PortID 0x%x entry from list",
3404 * Okay, we now have a list of Port IDs for all FC4 SCSI devices
3405 * that the Fabric Name server knows about.
3407 * For each entry on this list go through our port database looking
3408 * for probational entries- if we find one, then an old entry is
3409 * is maybe still this one. We get some information to find out.
3411 * Otherwise, it's a new fabric device, and we log into it
3412 * (unconditionally). After searching the entire database
3413 * again to make sure that we never ever ever ever have more
3414 * than one entry that has the same PortID or the same
3415 * WWNN/WWPN duple, we enter the device into our database.
3418 for (portidx = 0; portidx < portlim; portidx++) {
3421 uint64_t wwnn, wwpn;
3425 ((rs1->snscb_ports[portidx].portid[0]) << 16) |
3426 ((rs1->snscb_ports[portidx].portid[1]) << 8) |
3427 ((rs1->snscb_ports[portidx].portid[2]));
3430 isp_prt(isp, ISP_LOGSANCFG,
3431 "skipping null PortID at idx %d", portidx);
3438 if (portid == fcp->isp_portid) {
3439 isp_prt(isp, ISP_LOGSANCFG,
3440 "skip ourselves @ PortID 0x%06x", portid);
3443 isp_prt(isp, ISP_LOGSANCFG,
3444 "Checking Fabric Port 0x%06x", portid);
3447 * We now search our Port Database for any
3448 * probational entries with this PortID. We don't
3449 * look for zombies here- only probational
3450 * entries (we've already logged out of zombies).
3452 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
3453 lp = &fcp->portdb[dbidx];
3455 if (lp->state != FC_PORTDB_STATE_PROBATIONAL) {
3458 if (lp->portid == portid) {
3464 * We found a probational entry with this Port ID.
3466 if (dbidx < MAX_FC_TARG) {
3467 int handle_changed = 0;
3469 lp = &fcp->portdb[dbidx];
3472 * See if we're still logged into it.
3474 * If we aren't, mark it as a dead device and
3475 * leave the new portid in the database entry
3476 * for somebody further along to decide what to
3477 * do (policy choice).
3479 * If we are, check to see if it's the same
3480 * device still (it should be). If for some
3481 * reason it isn't, mark it as a changed device
3482 * and leave the new portid and role in the
3483 * database entry for somebody further along to
3484 * decide what to do (policy choice).
3488 r = isp_getpdb(isp, lp->handle, &pdb, 0);
3489 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
3490 FC_SCRATCH_RELEASE(isp);
3491 ISP_MARK_PORTDB(isp, 1);
3495 lp->new_portid = portid;
3496 lp->state = FC_PORTDB_STATE_DEAD;
3497 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3498 "Fabric Port 0x%06x considered dead",
3505 * Check to make sure that handle, portid, WWPN and
3506 * WWNN agree. If they don't, then the association
3507 * between this PortID and the stated handle has been
3508 * broken by the firmware.
3510 MAKE_WWN_FROM_NODE_NAME(wwnn, pdb.nodename);
3511 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb.portname);
3512 if (pdb.handle != lp->handle ||
3513 pdb.portid != portid ||
3514 wwpn != lp->port_wwn ||
3515 wwnn != lp->node_wwn) {
3516 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3517 fconf, dbidx, pdb.handle, pdb.portid,
3518 (uint32_t) (wwnn >> 32), (uint32_t) wwnn,
3519 (uint32_t) (wwpn >> 32), (uint32_t) wwpn,
3521 (uint32_t) (lp->node_wwn >> 32),
3522 (uint32_t) lp->node_wwn,
3523 (uint32_t) (lp->port_wwn >> 32),
3524 (uint32_t) lp->port_wwn);
3526 * Try to re-login to this device using a
3527 * new handle. If that fails, mark it dead.
3529 * isp_login_device will check for handle and
3530 * portid consistency after re-login.
3533 if (isp_login_device(isp, portid, &pdb,
3535 lp->new_portid = portid;
3536 lp->state = FC_PORTDB_STATE_DEAD;
3537 if (fcp->isp_loopstate !=
3538 LOOP_SCANNING_FABRIC) {
3539 FC_SCRATCH_RELEASE(isp);
3540 ISP_MARK_PORTDB(isp, 1);
3545 MAKE_WWN_FROM_NODE_NAME(wwnn, pdb.nodename);
3546 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb.portname);
3547 if (wwpn != lp->port_wwn ||
3548 wwnn != lp->node_wwn) {
3549 isp_prt(isp, ISP_LOGWARN, "changed WWN"
3551 lp->new_portid = portid;
3552 lp->state = FC_PORTDB_STATE_DEAD;
3556 lp->handle = pdb.handle;
3560 nr = (pdb.s3_role & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
3563 * Check to see whether the portid and roles have
3564 * stayed the same. If they have stayed the same,
3565 * we believe that this is the same device and it
3566 * hasn't become disconnected and reconnected, so
3567 * mark it as pending valid.
3569 * If they aren't the same, mark the device as a
3570 * changed device and save the new port id and role
3571 * and let somebody else decide.
3574 lp->new_portid = portid;
3576 if (pdb.portid != lp->portid || nr != lp->roles ||
3578 isp_prt(isp, ISP_LOGSANCFG,
3579 "Fabric Port 0x%06x changed", portid);
3580 lp->state = FC_PORTDB_STATE_CHANGED;
3582 isp_prt(isp, ISP_LOGSANCFG,
3583 "Fabric Port 0x%06x Now Pending Valid",
3585 lp->state = FC_PORTDB_STATE_PENDING_VALID;
3591 * Ah- a new entry. Search the database again for all non-NIL
3592 * entries to make sure we never ever make a new database entry
3593 * with the same port id. While we're at it, mark where the
3594 * last free entry was.
3597 dbidx = MAX_FC_TARG;
3598 for (lp = fcp->portdb; lp < &fcp->portdb[MAX_FC_TARG]; lp++) {
3599 if (lp >= &fcp->portdb[FL_ID] &&
3600 lp <= &fcp->portdb[SNS_ID]) {
3603 if (lp->state == FC_PORTDB_STATE_NIL) {
3604 if (dbidx == MAX_FC_TARG) {
3605 dbidx = lp - fcp->portdb;
3609 if (lp->state == FC_PORTDB_STATE_ZOMBIE) {
3612 if (lp->portid == portid) {
3617 if (lp < &fcp->portdb[MAX_FC_TARG]) {
3618 isp_prt(isp, ISP_LOGWARN,
3619 "PortID 0x%06x already at %d handle %d state %d",
3620 portid, dbidx, lp->handle, lp->state);
3625 * We should have the index of the first free entry seen.
3627 if (dbidx == MAX_FC_TARG) {
3628 isp_prt(isp, ISP_LOGERR,
3629 "port database too small to login PortID 0x%06x"
3630 "- increase MAX_FC_TARG", portid);
3635 * Otherwise, point to our new home.
3637 lp = &fcp->portdb[dbidx];
3640 * Try to see if we are logged into this device,
3641 * and maybe log into it.
3643 * isp_login_device will check for handle and
3644 * portid consistency after login.
3646 if (isp_login_device(isp, portid, &pdb, &oldhandle)) {
3647 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
3648 FC_SCRATCH_RELEASE(isp);
3649 ISP_MARK_PORTDB(isp, 1);
3655 handle = pdb.handle;
3656 MAKE_WWN_FROM_NODE_NAME(wwnn, pdb.nodename);
3657 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb.portname);
3658 nr = (pdb.s3_role & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
3661 * And go through the database *one* more time to make sure
3662 * that we do not make more than one entry that has the same
3665 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
3666 if (dbidx >= FL_ID && dbidx <= SNS_ID) {
3669 if (fcp->portdb[dbidx].state == FC_PORTDB_STATE_NIL) {
3672 if (fcp->portdb[dbidx].node_wwn == wwnn &&
3673 fcp->portdb[dbidx].port_wwn == wwpn) {
3678 if (dbidx == MAX_FC_TARG) {
3679 MEMZERO(lp, sizeof (fcportdb_t));
3680 lp->handle = handle;
3681 lp->node_wwn = wwnn;
3682 lp->port_wwn = wwpn;
3683 lp->new_portid = portid;
3685 lp->state = FC_PORTDB_STATE_NEW;
3686 isp_prt(isp, ISP_LOGSANCFG,
3687 "Fabric Port 0x%06x is New Entry", portid);
3691 if (fcp->portdb[dbidx].state != FC_PORTDB_STATE_ZOMBIE) {
3692 isp_prt(isp, ISP_LOGWARN,
3693 "PortID 0x%x 0x%08x%08x/0x%08x%08x %ld already at "
3694 "idx %d, state 0x%x", portid,
3695 (uint32_t) (wwnn >> 32), (uint32_t) wwnn,
3696 (uint32_t) (wwpn >> 32), (uint32_t) wwpn,
3697 (long) (lp - fcp->portdb), dbidx,
3698 fcp->portdb[dbidx].state);
3703 * We found a zombie entry that matches us.
3704 * Revive it. We know that WWN and WWPN
3705 * are the same. For fabric devices, we
3706 * don't care that handle is different
3707 * as we assign that. If role or portid
3708 * are different, it maybe a changed device.
3710 lp = &fcp->portdb[dbidx];
3711 lp->handle = handle;
3712 lp->new_portid = portid;
3714 if (lp->portid != portid || lp->roles != nr) {
3715 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3716 "Zombie Fabric Port 0x%06x Now Changed", portid);
3717 lp->state = FC_PORTDB_STATE_CHANGED;
3719 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3720 "Zombie Fabric Port 0x%06x Now Pending Valid",
3722 lp->state = FC_PORTDB_STATE_PENDING_VALID;
3726 FC_SCRATCH_RELEASE(isp);
3727 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
3728 ISP_MARK_PORTDB(isp, 1);
3731 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3732 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "FC Scan Fabric Done");
3737 * Find an unused handle and try and use to login to a port.
3740 isp_login_device(ispsoftc_t *isp, uint32_t portid, isp_pdb_t *p, uint16_t *ohp)
3745 if (FCPARAM(isp)->isp_2klogin) {
3751 handle = isp_nxt_handle(isp, *ohp);
3752 for (i = 0; i < lim; i++) {
3754 * See if we're still logged into something with
3755 * this handle and that something agrees with this
3758 r = isp_getpdb(isp, handle, p, 0);
3759 if (r == 0 && p->portid != portid) {
3760 (void) isp_plogx(isp, handle, portid,
3761 PLOGX_FLG_CMD_LOGO | PLOGX_FLG_IMPLICIT, 1);
3762 } else if (r == 0) {
3765 if (FCPARAM(isp)->isp_loopstate != LOOP_SCANNING_FABRIC) {
3769 * Now try and log into the device
3771 r = isp_plogx(isp, handle, portid, PLOGX_FLG_CMD_PLOGI, 1);
3772 if (FCPARAM(isp)->isp_loopstate != LOOP_SCANNING_FABRIC) {
3778 } else if ((r & 0xffff) == MBOX_PORT_ID_USED) {
3781 } else if (r != MBOX_LOOP_ID_USED) {
3786 handle = isp_nxt_handle(isp, *ohp);
3791 isp_prt(isp, ISP_LOGWARN, "PLOGI 0x%06x failed", portid);
3796 * If we successfully logged into it, get the PDB for it
3797 * so we can crosscheck that it is still what we think it
3798 * is and that we also have the role it plays
3800 r = isp_getpdb(isp, handle, p, 0);
3801 if (FCPARAM(isp)->isp_loopstate != LOOP_SCANNING_FABRIC) {
3805 isp_prt(isp, ISP_LOGERR, "new device 0x%06x@0x%x disappeared",
3810 if (p->handle != handle || p->portid != portid) {
3811 isp_prt(isp, ISP_LOGERR,
3812 "new device 0x%06x@0x%x changed (0x%06x@0x%0x)",
3813 portid, handle, p->portid, p->handle);
3820 isp_register_fc4_type(ispsoftc_t *isp)
3822 fcparam *fcp = isp->isp_param;
3823 uint8_t local[SNS_RFT_ID_REQ_SIZE];
3824 sns_screq_t *reqp = (sns_screq_t *) local;
3827 MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
3828 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
3829 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
3830 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
3831 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
3832 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
3833 reqp->snscb_sblen = 22;
3834 reqp->snscb_data[0] = SNS_RFT_ID;
3835 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
3836 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
3837 reqp->snscb_data[6] = (1 << FC4_SCSI);
3838 FC_SCRATCH_ACQUIRE(isp);
3839 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
3840 MEMZERO(&mbs, sizeof (mbs));
3841 mbs.param[0] = MBOX_SEND_SNS;
3842 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
3843 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
3844 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
3845 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
3846 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
3847 mbs.logval = MBLOGALL;
3848 mbs.timeout = 10000000;
3849 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_RFT_ID_REQ_SIZE);
3850 isp_mboxcmd(isp, &mbs);
3851 FC_SCRATCH_RELEASE(isp);
3852 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3860 isp_register_fc4_type_24xx(ispsoftc_t *isp)
3863 fcparam *fcp = FCPARAM(isp);
3867 uint8_t q[QENTRY_LEN];
3872 uint8_t *scp = fcp->isp_scratch;
3874 FC_SCRATCH_ACQUIRE(isp);
3876 * Build a Passthrough IOCB in memory.
3878 MEMZERO(un.q, QENTRY_LEN);
3880 pt->ctp_header.rqs_entry_count = 1;
3881 pt->ctp_header.rqs_entry_type = RQSTYPE_CT_PASSTHRU;
3882 pt->ctp_handle = 0xffffffff;
3883 pt->ctp_nphdl = NPH_SNS_ID;
3884 pt->ctp_cmd_cnt = 1;
3886 pt->ctp_rsp_cnt = 1;
3887 pt->ctp_rsp_bcnt = sizeof (ct_hdr_t);
3888 pt->ctp_cmd_bcnt = sizeof (rft_id_t);
3889 pt->ctp_dataseg[0].ds_base = DMA_LO32(fcp->isp_scdma+XTXOFF);
3890 pt->ctp_dataseg[0].ds_basehi = DMA_HI32(fcp->isp_scdma+XTXOFF);
3891 pt->ctp_dataseg[0].ds_count = sizeof (rft_id_t);
3892 pt->ctp_dataseg[1].ds_base = DMA_LO32(fcp->isp_scdma+IGPOFF);
3893 pt->ctp_dataseg[1].ds_basehi = DMA_HI32(fcp->isp_scdma+IGPOFF);
3894 pt->ctp_dataseg[1].ds_count = sizeof (ct_hdr_t);
3895 isp_put_ct_pt(isp, pt, (isp_ct_pt_t *) &scp[CTXOFF]);
3898 * Build the CT header and command in memory.
3900 * Note that the CT header has to end up as Big Endian format in memory.
3902 MEMZERO(&un.clocal, sizeof (un.clocal));
3903 ct = &un.clocal.rftid_hdr;
3904 ct->ct_revision = CT_REVISION;
3905 ct->ct_fcs_type = CT_FC_TYPE_FC;
3906 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3907 ct->ct_cmd_resp = SNS_RFT_ID;
3908 ct->ct_bcnt_resid = (sizeof (rft_id_t) - sizeof (ct_hdr_t)) >> 2;
3910 rp->rftid_portid[0] = fcp->isp_portid >> 16;
3911 rp->rftid_portid[1] = fcp->isp_portid >> 8;
3912 rp->rftid_portid[2] = fcp->isp_portid;
3913 rp->rftid_fc4types[FC4_SCSI >> 5] = 1 << (FC4_SCSI & 0x1f);
3914 isp_put_rft_id(isp, rp, (rft_id_t *) &scp[XTXOFF]);
3916 MEMZERO(&scp[ZTXOFF], sizeof (ct_hdr_t));
3918 MEMZERO(&mbs, sizeof (mbs));
3919 mbs.param[0] = MBOX_EXEC_COMMAND_IOCB_A64;
3920 mbs.param[1] = QENTRY_LEN;
3921 mbs.param[2] = DMA_WD1(fcp->isp_scdma + CTXOFF);
3922 mbs.param[3] = DMA_WD0(fcp->isp_scdma + CTXOFF);
3923 mbs.param[6] = DMA_WD3(fcp->isp_scdma + CTXOFF);
3924 mbs.param[7] = DMA_WD2(fcp->isp_scdma + CTXOFF);
3925 mbs.timeout = 500000;
3926 mbs.logval = MBLOGALL;
3927 MEMORYBARRIER(isp, SYNC_SFORDEV, XTXOFF, 2 * QENTRY_LEN);
3928 isp_mboxcmd(isp, &mbs);
3929 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3930 FC_SCRATCH_RELEASE(isp);
3933 MEMORYBARRIER(isp, SYNC_SFORCPU, ZTXOFF, QENTRY_LEN);
3935 isp_get_ct_pt(isp, (isp_ct_pt_t *) &scp[ZTXOFF], pt);
3936 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3937 isp_print_bytes(isp, "IOCB response", QENTRY_LEN, pt);
3939 if (pt->ctp_status) {
3940 FC_SCRATCH_RELEASE(isp);
3941 isp_prt(isp, ISP_LOGWARN, "CT Passthrough returned 0x%x",
3946 isp_get_ct_hdr(isp, (ct_hdr_t *) &scp[IGPOFF], ct);
3947 FC_SCRATCH_RELEASE(isp);
3949 if (ct->ct_cmd_resp == LS_RJT) {
3950 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3951 "Register FC4 Type rejected");
3953 } else if (ct->ct_cmd_resp == LS_ACC) {
3954 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3955 "Register FC4 Type accepted");
3958 isp_prt(isp, ISP_LOGWARN,
3959 "Register FC4 Type: 0x%x", ct->ct_cmd_resp);
3965 isp_nxt_handle(ispsoftc_t *isp, uint16_t handle)
3968 if (handle == NIL_HANDLE) {
3969 if (FCPARAM(isp)->isp_topo == TOPO_F_PORT) {
3976 if (handle >= FL_ID && handle <= SNS_ID) {
3979 if (handle >= NPH_RESERVED && handle <= NPH_FL_ID) {
3980 handle = NPH_FL_ID+1;
3982 if (FCPARAM(isp)->isp_2klogin) {
3983 if (handle == NPH_MAX_2K) {
3987 if (handle == NPH_MAX) {
3992 if (handle == FCPARAM(isp)->isp_loopid) {
3993 return (isp_nxt_handle(isp, handle));
3995 for (i = 0; i < MAX_FC_TARG; i++) {
3996 if (FCPARAM(isp)->portdb[i].state == FC_PORTDB_STATE_NIL) {
3999 if (FCPARAM(isp)->portdb[i].handle == handle) {
4000 return (isp_nxt_handle(isp, handle));
4007 * Start a command. Locking is assumed done in the caller.
4014 uint32_t nxti, optr, handle;
4015 uint8_t local[QENTRY_LEN];
4016 ispreq_t *reqp, *qep;
4019 int target, i, hdlidx = 0;
4025 * Check to make sure we're supporting initiator role.
4027 if ((isp->isp_role & ISP_ROLE_INITIATOR) == 0) {
4028 XS_SETERR(xs, HBA_SELTIMEOUT);
4029 return (CMD_COMPLETE);
4033 * Now make sure we're running.
4036 if (isp->isp_state != ISP_RUNSTATE) {
4037 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
4038 XS_SETERR(xs, HBA_BOTCH);
4039 return (CMD_COMPLETE);
4043 * Check command CDB length, etc.. We really are limited to 16 bytes
4044 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
4045 * but probably only if we're running fairly new firmware (we'll
4046 * let the old f/w choke on an extended command queue entry).
4049 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
4050 isp_prt(isp, ISP_LOGERR,
4051 "unsupported cdb length (%d, CDB[0]=0x%x)",
4052 XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
4053 XS_SETERR(xs, HBA_BOTCH);
4054 return (CMD_COMPLETE);
4058 * Translate the target to device handle as appropriate, checking
4059 * for correct device state as well.
4061 target = XS_TGT(xs);
4063 fcparam *fcp = isp->isp_param;
4068 if (fcp->isp_fwstate != FW_READY ||
4069 fcp->isp_loopstate != LOOP_READY) {
4070 return (CMD_RQLATER);
4073 if (XS_TGT(xs) >= MAX_FC_TARG) {
4074 XS_SETERR(xs, HBA_SELTIMEOUT);
4075 return (CMD_COMPLETE);
4078 hdlidx = fcp->isp_ini_map[XS_TGT(xs)] - 1;
4079 isp_prt(isp, ISP_LOGDEBUG1, "XS_TGT(xs)=%d- hdlidx value %d",
4080 XS_TGT(xs), hdlidx);
4081 if (hdlidx < 0 || hdlidx >= MAX_FC_TARG) {
4082 XS_SETERR(xs, HBA_SELTIMEOUT);
4083 return (CMD_COMPLETE);
4085 if (fcp->portdb[hdlidx].state == FC_PORTDB_STATE_ZOMBIE) {
4086 return (CMD_RQLATER);
4088 if (fcp->portdb[hdlidx].state != FC_PORTDB_STATE_VALID) {
4089 XS_SETERR(xs, HBA_SELTIMEOUT);
4090 return (CMD_COMPLETE);
4092 target = fcp->portdb[hdlidx].handle;
4096 * Next check to see if any HBA or Device parameters need to be updated.
4098 if (isp->isp_update != 0) {
4104 if (isp_getrqentry(isp, &nxti, &optr, (void *)&qep)) {
4105 isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow");
4106 XS_SETERR(xs, HBA_BOTCH);
4107 return (CMD_EAGAIN);
4111 * Now see if we need to synchronize the ISP with respect to anything.
4112 * We do dual duty here (cough) for synchronizing for busses other
4113 * than which we got here to send a command to.
4115 reqp = (ispreq_t *) local;
4116 if (isp->isp_sendmarker) {
4118 isp_marker_24xx_t *m = (isp_marker_24xx_t *) qep;
4119 MEMZERO(m, QENTRY_LEN);
4120 m->mrk_header.rqs_entry_count = 1;
4121 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4122 m->mrk_modifier = SYNC_ALL;
4123 isp_put_marker_24xx(isp, m, (isp_marker_24xx_t *)qep);
4124 ISP_ADD_REQUEST(isp, nxti);
4125 isp->isp_sendmarker = 0;
4128 for (i = 0; i < (IS_DUALBUS(isp)? 2: 1); i++) {
4129 isp_marker_t *m = (isp_marker_t *) qep;
4130 if ((isp->isp_sendmarker & (1 << i)) == 0) {
4133 MEMZERO(m, QENTRY_LEN);
4134 m->mrk_header.rqs_entry_count = 1;
4135 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4136 m->mrk_target = (i << 7); /* bus # */
4137 m->mrk_modifier = SYNC_ALL;
4138 isp_put_marker(isp, m, (isp_marker_t *) qep);
4139 ISP_ADD_REQUEST(isp, nxti);
4140 isp->isp_sendmarker &= ~(1 << i);
4146 MEMZERO((void *)reqp, QENTRY_LEN);
4147 reqp->req_header.rqs_entry_count = 1;
4149 reqp->req_header.rqs_entry_type = RQSTYPE_T7RQS;
4150 } else if (IS_FC(isp)) {
4151 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
4153 if (XS_CDBLEN(xs) > 12)
4154 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
4156 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
4158 /* reqp->req_header.rqs_flags = 0; */
4159 /* reqp->req_header.rqs_seqno = 0; */
4163 ttype = XS_TAG_TYPE(xs);
4165 if (XS_CDBP(xs)[0] == 0x3) {
4166 ttype = REQFLAG_HTAG;
4168 ttype = REQFLAG_STAG;
4171 if (ttype == REQFLAG_OTAG) {
4172 ttype = FCP_CMND_TASK_ATTR_ORDERED;
4173 } else if (ttype == REQFLAG_HTAG) {
4174 ttype = FCP_CMND_TASK_ATTR_HEAD;
4176 ttype = FCP_CMND_TASK_ATTR_SIMPLE;
4178 ((ispreqt7_t *)reqp)->req_task_attribute = ttype;
4179 } else if (IS_FC(isp)) {
4181 * See comment in isp_intr
4183 /* XS_RESID(xs) = 0; */
4186 * Fibre Channel always requires some kind of tag.
4187 * The Qlogic drivers seem be happy not to use a tag,
4188 * but this breaks for some devices (IBM drives).
4191 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
4194 * If we don't know what tag to use, use HEAD OF QUEUE
4195 * for Request Sense or Simple.
4197 if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
4198 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_HTAG;
4200 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
4203 sdparam *sdp = (sdparam *)isp->isp_param;
4204 sdp += XS_CHANNEL(xs);
4205 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) &&
4207 reqp->req_flags = XS_TAG_TYPE(xs);
4210 cdbp = reqp->req_cdb;
4211 tptr = &reqp->req_time;
4214 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
4215 reqp->req_lun_trn = XS_LUN(xs);
4216 reqp->req_cdblen = XS_CDBLEN(xs);
4217 } else if (IS_24XX(isp)) {
4220 lp = &FCPARAM(isp)->portdb[hdlidx];
4221 ((ispreqt7_t *)reqp)->req_nphdl = target;
4222 ((ispreqt7_t *)reqp)->req_tidlo = lp->portid;
4223 ((ispreqt7_t *)reqp)->req_tidhi = lp->portid >> 16;
4224 if (XS_LUN(xs) > 256) {
4225 ((ispreqt7_t *)reqp)->req_lun[0] = XS_LUN(xs) >> 8;
4226 ((ispreqt7_t *)reqp)->req_lun[0] |= 0x40;
4228 ((ispreqt7_t *)reqp)->req_lun[1] = XS_LUN(xs);
4229 cdbp = ((ispreqt7_t *)reqp)->req_cdb;
4230 tptr = &((ispreqt7_t *)reqp)->req_time;
4231 } else if (FCPARAM(isp)->isp_2klogin) {
4232 ((ispreqt2e_t *)reqp)->req_target = target;
4233 ((ispreqt2e_t *)reqp)->req_scclun = XS_LUN(xs);
4234 } else if (FCPARAM(isp)->isp_sccfw) {
4235 ((ispreqt2_t *)reqp)->req_target = target;
4236 ((ispreqt2_t *)reqp)->req_scclun = XS_LUN(xs);
4238 ((ispreqt2_t *)reqp)->req_target = target;
4239 ((ispreqt2_t *)reqp)->req_lun_trn = XS_LUN(xs);
4241 MEMCPY(cdbp, XS_CDBP(xs), XS_CDBLEN(xs));
4243 *tptr = XS_TIME(xs) / 1000;
4244 if (*tptr == 0 && XS_TIME(xs)) {
4247 if (IS_24XX(isp) && *tptr > 0x1999) {
4251 if (isp_save_xs(isp, xs, &handle)) {
4252 isp_prt(isp, ISP_LOGDEBUG0, "out of xflist pointers");
4253 XS_SETERR(xs, HBA_BOTCH);
4254 return (CMD_EAGAIN);
4256 /* Whew. Thankfully the same for type 7 requests */
4257 reqp->req_handle = handle;
4260 * Set up DMA and/or do any bus swizzling of the request entry
4261 * so that the Qlogic F/W understands what is being asked of it.
4263 i = ISP_DMASETUP(isp, xs, reqp, &nxti, optr);
4264 if (i != CMD_QUEUED) {
4265 isp_destroy_handle(isp, handle);
4267 * dmasetup sets actual error in packet, and
4268 * return what we were given to return.
4272 XS_SETERR(xs, HBA_NOERROR);
4273 isp_prt(isp, ISP_LOGDEBUG0,
4274 "START cmd for %d.%d.%d cmd 0x%x datalen %ld",
4275 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), XS_CDBP(xs)[0],
4276 (long) XS_XFRLEN(xs));
4277 ISP_ADD_REQUEST(isp, nxti);
4279 return (CMD_QUEUED);
4284 * Locks (ints blocked) assumed held.
4288 isp_control(ispsoftc_t *isp, ispctl_t ctl, void *arg)
4295 MEMZERO(&mbs, sizeof (mbs));
4299 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
4302 case ISPCTL_RESET_BUS:
4304 * Issue a bus reset.
4307 isp_prt(isp, ISP_LOGWARN, "RESET BUS NOT IMPLEMENTED");
4309 } else if (IS_FC(isp)) {
4313 mbs.param[1] = SDPARAM(isp)->isp_bus_reset_delay;
4314 if (mbs.param[1] < 2) {
4317 bus = *((int *) arg);
4318 if (IS_DUALBUS(isp)) {
4322 mbs.param[0] = MBOX_BUS_RESET;
4323 isp->isp_sendmarker |= (1 << bus);
4324 mbs.logval = MBLOGALL;
4325 isp_mboxcmd(isp, &mbs);
4326 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4329 isp_prt(isp, ISP_LOGINFO,
4330 "driver initiated bus reset of bus %d", bus);
4333 case ISPCTL_RESET_DEV:
4334 tgt = (*((int *) arg)) & 0xffff;
4336 isp_prt(isp, ISP_LOGWARN, "RESET DEV NOT IMPLEMENTED");
4338 } else if (IS_FC(isp)) {
4339 if (FCPARAM(isp)->isp_2klogin) {
4341 mbs.ibits = (1 << 10);
4343 mbs.param[1] = (tgt << 8);
4347 bus = (*((int *) arg)) >> 16;
4348 mbs.param[1] = (bus << 15) | (tgt << 8);
4350 mbs.param[0] = MBOX_ABORT_TARGET;
4351 mbs.param[2] = 3; /* 'delay', in seconds */
4352 mbs.logval = MBLOGALL;
4353 isp_mboxcmd(isp, &mbs);
4354 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4357 isp_prt(isp, ISP_LOGINFO,
4358 "Target %d on Bus %d Reset Succeeded", tgt, bus);
4359 isp->isp_sendmarker |= (1 << bus);
4362 case ISPCTL_ABORT_CMD:
4366 handle = isp_find_handle(isp, xs);
4368 isp_prt(isp, ISP_LOGWARN,
4369 "cannot find handle for command to abort");
4373 isp_prt(isp, ISP_LOGWARN, "ABORT CMD NOT IMPLEMENTED");
4375 } else if (IS_FC(isp)) {
4376 if (FCPARAM(isp)->isp_sccfw) {
4377 if (FCPARAM(isp)->isp_2klogin) {
4380 mbs.param[1] = tgt << 8;
4382 mbs.param[6] = XS_LUN(xs);
4384 mbs.param[1] = tgt << 8 | XS_LUN(xs);
4387 bus = XS_CHANNEL(xs);
4388 mbs.param[1] = (bus << 15) | (tgt << 8) | XS_LUN(xs);
4390 mbs.param[0] = MBOX_ABORT;
4391 mbs.param[2] = handle;
4392 mbs.logval = MBLOGALL & ~MBOX_COMMAND_ERROR;
4393 isp_mboxcmd(isp, &mbs);
4394 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4399 case ISPCTL_UPDATE_PARAMS:
4404 case ISPCTL_FCLINK_TEST:
4407 int usdelay = *((int *) arg);
4411 return (isp_fclink_test(isp, usdelay));
4415 case ISPCTL_SCAN_FABRIC:
4418 return (isp_scan_fabric(isp));
4422 case ISPCTL_SCAN_LOOP:
4425 return (isp_scan_loop(isp));
4429 case ISPCTL_PDB_SYNC:
4432 return (isp_pdb_sync(isp));
4436 case ISPCTL_SEND_LIP:
4438 if (IS_FC(isp) && !IS_24XX(isp)) {
4439 mbs.param[0] = MBOX_INIT_LIP;
4440 if (FCPARAM(isp)->isp_2klogin) {
4441 mbs.ibits = (1 << 10);
4443 mbs.logval = MBLOGALL;
4444 isp_mboxcmd(isp, &mbs);
4445 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
4451 case ISPCTL_GET_PDB:
4452 if (IS_FC(isp) && arg) {
4453 int id = *((int *)arg);
4454 isp_pdb_t *pdb = arg;
4455 return (isp_getpdb(isp, id, pdb, 1));
4459 case ISPCTL_GET_PORTNAME:
4461 uint64_t *wwnp = arg;
4463 *wwnp = isp_get_portname(isp, loopid, 0);
4464 if (*wwnp == (uint64_t) -1) {
4470 case ISPCTL_RUN_MBOXCMD:
4472 isp_mboxcmd(isp, arg);
4477 isp_plcmd_t *p = arg;
4480 if ((p->flags & PLOGX_FLG_CMD_MASK) != PLOGX_FLG_CMD_PLOGI ||
4481 (p->handle != NIL_HANDLE)) {
4482 return (isp_plogx(isp, p->handle, p->portid,
4486 p->handle = isp_nxt_handle(isp, p->handle);
4487 r = isp_plogx(isp, p->handle, p->portid, p->flags, 0);
4488 if ((r & 0xffff) == MBOX_PORT_ID_USED) {
4489 p->handle = r >> 16;
4493 } while ((r & 0xffff) == MBOX_LOOP_ID_USED);
4496 #ifdef ISP_TARGET_MODE
4497 case ISPCTL_TOGGLE_TMODE:
4501 * We don't check/set against role here- that's the
4502 * responsibility for the outer layer to coordinate.
4505 int param = *(int *)arg;
4506 mbs.param[0] = MBOX_ENABLE_TARGET_MODE;
4507 mbs.param[1] = param & 0xffff;
4508 mbs.param[2] = param >> 16;
4509 mbs.logval = MBLOGALL;
4510 isp_mboxcmd(isp, &mbs);
4511 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4523 * Interrupt Service Routine(s).
4525 * External (OS) framework has done the appropriate locking,
4526 * and the locking will be held throughout this function.
4530 * Limit our stack depth by sticking with the max likely number
4531 * of completions on a request queue at any one time.
4533 #ifndef MAX_REQUESTQ_COMPLETIONS
4534 #define MAX_REQUESTQ_COMPLETIONS 32
4538 isp_intr(ispsoftc_t *isp, uint32_t isr, uint16_t sema, uint16_t mbox)
4540 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
4541 uint32_t iptr, optr, junk;
4542 int i, nlooked = 0, ndone = 0;
4545 optr = isp->isp_residx;
4547 * Is this a mailbox related interrupt?
4548 * The mailbox semaphore will be nonzero if so.
4551 if (mbox & 0x4000) {
4552 isp->isp_intmboxc++;
4553 if (isp->isp_mboxbsy) {
4554 int obits = isp->isp_obits;
4555 isp->isp_mboxtmp[0] = mbox;
4556 for (i = 1; i < MAX_MAILBOX(isp); i++) {
4557 if ((obits & (1 << i)) == 0) {
4560 isp->isp_mboxtmp[i] =
4561 ISP_READ(isp, MBOX_OFF(i));
4563 if (isp->isp_mbxwrk0) {
4564 if (isp_mbox_continue(isp) == 0) {
4568 MBOX_NOTIFY_COMPLETE(isp);
4570 isp_prt(isp, ISP_LOGWARN,
4571 "mailbox cmd (0x%x) with no waiters", mbox);
4573 } else if (isp_parse_async(isp, mbox) < 0) {
4576 if ((IS_FC(isp) && mbox != ASYNC_RIO_RESP) ||
4577 isp->isp_state != ISP_RUNSTATE) {
4583 * We can't be getting this now.
4585 if (isp->isp_state != ISP_RUNSTATE) {
4586 isp_prt(isp, ISP_LOGINFO,
4587 "interrupt (ISR=%x SEMA=%x) when not ready", isr, sema);
4589 * Thank you very much! *Burrrp*!
4591 ISP_WRITE(isp, isp->isp_respoutrp,
4592 ISP_READ(isp, isp->isp_respinrp));
4594 ISP_DISABLE_INTS(isp);
4599 #ifdef ISP_TARGET_MODE
4601 * Check for ATIO Queue entries.
4603 if (isp->isp_rspbsy == 0 && (isp->isp_role & ISP_ROLE_TARGET) &&
4605 iptr = ISP_READ(isp, isp->isp_atioinrp);
4606 optr = ISP_READ(isp, isp->isp_atiooutrp);
4608 isp->isp_rspbsy = 1;
4609 while (optr != iptr) {
4610 uint8_t qe[QENTRY_LEN];
4616 MEMORYBARRIER(isp, SYNC_ATIOQ, oop, QENTRY_LEN);
4617 addr = ISP_QUEUE_ENTRY(isp->isp_atioq, oop);
4618 isp_get_hdr(isp, addr, (isphdr_t *)qe);
4619 hp = (isphdr_t *)qe;
4620 switch (hp->rqs_entry_type) {
4621 case RQSTYPE_NOTIFY:
4623 (void) isp_target_notify(isp, addr, &oop);
4626 isp_print_qentry(isp, "?ATIOQ entry?",
4630 optr = ISP_NXT_QENTRY(oop, RESULT_QUEUE_LEN(isp));
4631 ISP_WRITE(isp, isp->isp_atiooutrp, optr);
4633 isp->isp_rspbsy = 0;
4634 optr = isp->isp_residx;
4639 * Get the current Response Queue Out Pointer.
4641 * If we're a 2300 or 2400, we can ask what hardware what it thinks.
4643 if (IS_23XX(isp) || IS_24XX(isp)) {
4644 optr = ISP_READ(isp, isp->isp_respoutrp);
4646 * Debug: to be taken out eventually
4648 if (isp->isp_residx != optr) {
4649 isp_prt(isp, ISP_LOGINFO,
4650 "isp_intr: hard optr=%x, soft optr %x",
4651 optr, isp->isp_residx);
4652 isp->isp_residx = optr;
4655 optr = isp->isp_residx;
4659 * You *must* read the Response Queue In Pointer
4660 * prior to clearing the RISC interrupt.
4662 * Debounce the 2300 if revision less than 2.
4664 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
4667 iptr = ISP_READ(isp, isp->isp_respinrp);
4668 junk = ISP_READ(isp, isp->isp_respinrp);
4669 } while (junk != iptr && ++i < 1000);
4672 isp_prt(isp, ISP_LOGWARN,
4673 "Response Queue Out Pointer Unstable (%x, %x)",
4678 iptr = ISP_READ(isp, isp->isp_respinrp);
4680 isp->isp_resodx = iptr;
4683 if (optr == iptr && sema == 0) {
4685 * There are a lot of these- reasons unknown- mostly on
4686 * faster Alpha machines.
4688 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
4689 * make sure the old interrupt went away (to avoid 'ringing'
4690 * effects), but that didn't stop this from occurring.
4694 } else if (IS_23XX(isp)) {
4696 iptr = ISP_READ(isp, isp->isp_respinrp);
4697 junk = ISP_READ(isp, BIU_R2HSTSLO);
4699 junk = ISP_READ(isp, BIU_ISR);
4702 if (IS_23XX(isp) || IS_24XX(isp)) {
4705 sema = ISP_READ(isp, BIU_SEMA);
4706 mbox = ISP_READ(isp, OUTMAILBOX0);
4707 if ((sema & 0x3) && (mbox & 0x8000)) {
4711 isp->isp_intbogus++;
4712 isp_prt(isp, ISP_LOGDEBUG1,
4713 "bogus intr- isr %x (%x) iptr %x optr %x",
4714 isr, junk, iptr, optr);
4717 isp->isp_resodx = iptr;
4720 if (isp->isp_rspbsy) {
4723 isp->isp_rspbsy = 1;
4724 while (optr != iptr) {
4725 uint8_t qe[QENTRY_LEN];
4726 ispstatusreq_t *sp = (ispstatusreq_t *) qe;
4728 int buddaboom, etype, scsi_status, completion_status;
4729 int req_status_flags, req_state_flags;
4730 uint8_t *snsp, *resp;
4731 uint32_t rlen, slen;
4735 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
4737 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
4740 buddaboom = req_status_flags = req_state_flags = 0;
4744 * Synchronize our view of this response queue entry.
4746 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN);
4747 isp_get_hdr(isp, hp, &sp->req_header);
4748 etype = sp->req_header.rqs_entry_type;
4750 if (IS_24XX(isp) && etype == RQSTYPE_RESPONSE) {
4751 isp24xx_statusreq_t *sp2 = (isp24xx_statusreq_t *)qe;
4752 isp_get_24xx_response(isp,
4753 (isp24xx_statusreq_t *)hp, sp2);
4754 if (isp->isp_dblev & ISP_LOGDEBUG1) {
4755 isp_print_bytes(isp,
4756 "Response Queue Entry", QENTRY_LEN, sp2);
4758 scsi_status = sp2->req_scsi_status;
4759 completion_status = sp2->req_completion_status;
4760 req_state_flags = 0;
4761 resid = sp2->req_resid;
4762 } else if (etype == RQSTYPE_RESPONSE) {
4763 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
4764 if (isp->isp_dblev & ISP_LOGDEBUG1) {
4765 isp_print_bytes(isp,
4766 "Response Queue Entry", QENTRY_LEN, sp);
4768 scsi_status = sp->req_scsi_status;
4769 completion_status = sp->req_completion_status;
4770 req_status_flags = sp->req_status_flags;
4771 req_state_flags = sp->req_state_flags;
4772 resid = sp->req_resid;
4773 } else if (etype == RQSTYPE_RIO2) {
4774 isp_rio2_t *rio = (isp_rio2_t *)qe;
4775 isp_get_rio2(isp, (isp_rio2_t *) hp, rio);
4776 if (isp->isp_dblev & ISP_LOGDEBUG1) {
4777 isp_print_bytes(isp,
4778 "Response Queue Entry", QENTRY_LEN, rio);
4780 for (i = 0; i < rio->req_header.rqs_seqno; i++) {
4781 isp_fastpost_complete(isp, rio->req_handles[i]);
4783 if (isp->isp_fpcchiwater < rio->req_header.rqs_seqno) {
4784 isp->isp_fpcchiwater =
4785 rio->req_header.rqs_seqno;
4787 MEMZERO(hp, QENTRY_LEN); /* PERF */
4791 * Somebody reachable via isp_handle_other_response
4792 * may have updated the response queue pointers for
4793 * us, so we reload our goal index.
4796 r = isp_handle_other_response(isp, etype, hp, &optr);
4801 iptr = isp->isp_resodx;
4802 MEMZERO(hp, QENTRY_LEN); /* PERF */
4807 * After this point, we'll just look at the header as
4808 * we don't know how to deal with the rest of the
4813 * It really has to be a bounced request just copied
4814 * from the request queue to the response queue. If
4815 * not, something bad has happened.
4817 if (etype != RQSTYPE_REQUEST) {
4818 isp_prt(isp, ISP_LOGERR, notresp,
4819 etype, oop, optr, nlooked);
4820 isp_print_bytes(isp,
4821 "Request Queue Entry", QENTRY_LEN, sp);
4822 MEMZERO(hp, QENTRY_LEN); /* PERF */
4826 scsi_status = sp->req_scsi_status;
4827 completion_status = sp->req_completion_status;
4828 req_status_flags = sp->req_status_flags;
4829 req_state_flags = sp->req_state_flags;
4830 resid = sp->req_resid;
4833 if (sp->req_header.rqs_flags & RQSFLAG_MASK) {
4834 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
4835 isp_prt(isp, ISP_LOGWARN,
4836 "continuation segment");
4837 ISP_WRITE(isp, isp->isp_respoutrp, optr);
4840 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
4841 isp_prt(isp, ISP_LOGDEBUG1,
4842 "internal queues full");
4844 * We'll synthesize a QUEUE FULL message below.
4847 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
4848 isp_print_bytes(isp, "bad header flag",
4852 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
4853 isp_print_bytes(isp, "bad request packet",
4859 if (sp->req_handle > isp->isp_maxcmds || sp->req_handle < 1) {
4860 isp_prt(isp, ISP_LOGERR,
4861 "bad request handle %d (type 0x%x)",
4862 sp->req_handle, etype);
4863 MEMZERO(hp, QENTRY_LEN); /* PERF */
4864 ISP_WRITE(isp, isp->isp_respoutrp, optr);
4867 xs = isp_find_xs(isp, sp->req_handle);
4869 uint8_t ts = completion_status & 0xff;
4871 * Only whine if this isn't the expected fallout of
4872 * aborting the command.
4874 if (etype != RQSTYPE_RESPONSE) {
4875 isp_prt(isp, ISP_LOGERR,
4876 "cannot find handle 0x%x (type 0x%x)",
4877 sp->req_handle, etype);
4878 } else if (ts != RQCS_ABORTED) {
4879 isp_prt(isp, ISP_LOGERR,
4880 "cannot find handle 0x%x (status 0x%x)",
4881 sp->req_handle, ts);
4883 MEMZERO(hp, QENTRY_LEN); /* PERF */
4884 ISP_WRITE(isp, isp->isp_respoutrp, optr);
4887 isp_destroy_handle(isp, sp->req_handle);
4888 if (req_status_flags & RQSTF_BUS_RESET) {
4889 XS_SETERR(xs, HBA_BUSRESET);
4890 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
4893 XS_SETERR(xs, HBA_BOTCH);
4900 if (IS_24XX(isp) && (scsi_status & (RQCS_RV|RQCS_SV)) != 0) {
4901 resp = ((isp24xx_statusreq_t *)sp)->req_rsp_sense;
4902 rlen = ((isp24xx_statusreq_t *)sp)->req_response_len;
4903 } else if (IS_FC(isp) && (scsi_status & RQCS_RV) != 0) {
4904 resp = sp->req_response;
4905 rlen = sp->req_response_len;
4907 if (IS_FC(isp) && (scsi_status & RQCS_SV) != 0) {
4909 * Fibre Channel F/W doesn't say we got status
4910 * if there's Sense Data instead. I guess they
4911 * think it goes w/o saying.
4913 req_state_flags |= RQSF_GOT_STATUS|RQSF_GOT_SENSE;
4916 ((isp24xx_statusreq_t *)sp)->req_rsp_sense;
4919 ((isp24xx_statusreq_t *)sp)->req_sense_len;
4921 snsp = sp->req_sense_data;
4922 slen = sp->req_sense_len;
4924 } else if (IS_SCSI(isp) && (req_state_flags & RQSF_GOT_SENSE)) {
4925 snsp = sp->req_sense_data;
4926 slen = sp->req_sense_len;
4928 if (req_state_flags & RQSF_GOT_STATUS) {
4929 *XS_STSP(xs) = scsi_status & 0xff;
4933 case RQSTYPE_RESPONSE:
4934 XS_SET_STATE_STAT(isp, xs, sp);
4935 if (resp && rlen >= 4 &&
4936 resp[FCP_RSPNS_CODE_OFFSET] != 0) {
4937 isp_prt(isp, ISP_LOGWARN,
4938 "%d.%d.%d FCP RESPONSE: 0x%x",
4939 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
4940 resp[FCP_RSPNS_CODE_OFFSET]);
4941 XS_SETERR(xs, HBA_BOTCH);
4944 isp_parse_status_24xx(isp,
4945 (isp24xx_statusreq_t *)sp, xs, &resid);
4947 isp_parse_status(isp, (void *)sp, xs, &resid);
4949 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) &&
4950 (*XS_STSP(xs) == SCSI_BUSY)) {
4951 XS_SETERR(xs, HBA_TGTBSY);
4954 XS_RESID(xs) = resid;
4956 * A new synchronous rate was negotiated for
4957 * this target. Mark state such that we'll go
4958 * look up that which has changed later.
4960 if (req_status_flags & RQSTF_NEGOTIATION) {
4962 sdparam *sdp = isp->isp_param;
4963 sdp += XS_CHANNEL(xs);
4964 sdp->isp_devparam[t].dev_refresh = 1;
4966 (1 << XS_CHANNEL(xs));
4969 if (req_status_flags & RQSF_XFER_COMPLETE) {
4971 } else if (scsi_status & RQCS_RESID) {
4972 XS_RESID(xs) = resid;
4978 XS_SAVE_SENSE(xs, snsp, slen);
4980 isp_prt(isp, ISP_LOGDEBUG2,
4981 "asked for %ld got raw resid %ld settled for %ld",
4982 (long) XS_XFRLEN(xs), resid, (long) XS_RESID(xs));
4984 case RQSTYPE_REQUEST:
4989 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
4991 * Force Queue Full status.
4993 *XS_STSP(xs) = SCSI_QFULL;
4994 XS_SETERR(xs, HBA_NOERROR);
4995 } else if (XS_NOERR(xs)) {
4999 XS_SETERR(xs, HBA_BOTCH);
5000 isp_prt(isp, ISP_LOGDEBUG0,
5001 "Request Queue Entry bounced back");
5002 if ((isp->isp_dblev & ISP_LOGDEBUG1) == 0) {
5003 isp_print_bytes(isp, "Bounced Request",
5007 XS_RESID(xs) = XS_XFRLEN(xs);
5010 isp_print_bytes(isp, "Unhandled Response Type",
5013 XS_SETERR(xs, HBA_BOTCH);
5019 * Free any DMA resources. As a side effect, this may
5020 * also do any cache flushing necessary for data coherence.
5022 if (XS_XFRLEN(xs)) {
5023 ISP_DMAFREE(isp, xs, sp->req_handle);
5026 if (((isp->isp_dblev & (ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
5027 ((isp->isp_dblev & ISP_LOGDEBUG0) && ((!XS_NOERR(xs)) ||
5028 (*XS_STSP(xs) != SCSI_GOOD)))) {
5030 if (req_state_flags & RQSF_GOT_SENSE) {
5031 skey = XS_SNSKEY(xs) & 0xf;
5036 } else if (*XS_STSP(xs) == SCSI_CHECK) {
5041 isp_prt(isp, ISP_LOGALL, finmsg, XS_CHANNEL(xs),
5042 XS_TGT(xs), XS_LUN(xs), XS_XFRLEN(xs), XS_RESID(xs),
5043 *XS_STSP(xs), skey, XS_ERR(xs));
5046 if (isp->isp_nactive > 0)
5048 complist[ndone++] = xs; /* defer completion call until later */
5049 MEMZERO(hp, QENTRY_LEN); /* PERF */
5050 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
5056 * If we looked at any commands, then it's valid to find out
5057 * what the outpointer is. It also is a trigger to update the
5058 * ISP's notion of what we've seen so far.
5061 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5063 * While we're at it, read the requst queue out pointer.
5065 isp->isp_reqodx = ISP_READ(isp, isp->isp_rqstoutrp);
5066 if (isp->isp_rscchiwater < ndone) {
5067 isp->isp_rscchiwater = ndone;
5074 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
5076 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
5077 ISP_WRITE(isp, BIU_SEMA, 0);
5080 isp->isp_residx = optr;
5081 isp->isp_rspbsy = 0;
5082 for (i = 0; i < ndone; i++) {
5085 isp->isp_rsltccmplt++;
5096 isp_parse_async(ispsoftc_t *isp, uint16_t mbox)
5101 if (IS_DUALBUS(isp)) {
5102 bus = ISP_READ(isp, OUTMAILBOX6);
5106 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
5109 case ASYNC_BUS_RESET:
5110 isp->isp_sendmarker |= (1 << bus);
5111 #ifdef ISP_TARGET_MODE
5112 if (isp_target_async(isp, bus, mbox)) {
5116 isp_async(isp, ISPASYNC_BUS_RESET, &bus);
5118 case ASYNC_SYSTEM_ERROR:
5119 isp->isp_state = ISP_CRASHED;
5121 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
5122 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
5125 * Were we waiting for a mailbox command to complete?
5126 * If so, it's dead, so wake up the waiter.
5128 if (isp->isp_mboxbsy) {
5130 isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR;
5131 MBOX_NOTIFY_COMPLETE(isp);
5134 * It's up to the handler for isp_async to reinit stuff and
5135 * restart the firmware
5137 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
5141 case ASYNC_RQS_XFER_ERR:
5142 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
5145 case ASYNC_RSP_XFER_ERR:
5146 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
5151 * We've just been notified that the Queue has woken up.
5152 * We don't need to be chatty about this- just unlatch things
5155 mbox = ISP_READ(isp, isp->isp_rqstoutrp);
5158 case ASYNC_TIMEOUT_RESET:
5159 isp_prt(isp, ISP_LOGWARN,
5160 "timeout initiated SCSI bus reset of bus %d", bus);
5161 isp->isp_sendmarker |= (1 << bus);
5162 #ifdef ISP_TARGET_MODE
5163 if (isp_target_async(isp, bus, mbox)) {
5169 case ASYNC_DEVICE_RESET:
5170 isp_prt(isp, ISP_LOGINFO, "device reset on bus %d", bus);
5171 isp->isp_sendmarker |= (1 << bus);
5172 #ifdef ISP_TARGET_MODE
5173 if (isp_target_async(isp, bus, mbox)) {
5179 case ASYNC_EXTMSG_UNDERRUN:
5180 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
5183 case ASYNC_SCAM_INT:
5184 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
5187 case ASYNC_HUNG_SCSI:
5188 isp_prt(isp, ISP_LOGERR,
5189 "stalled SCSI Bus after DATA Overrun");
5190 /* XXX: Need to issue SCSI reset at this point */
5193 case ASYNC_KILLED_BUS:
5194 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
5197 case ASYNC_BUS_TRANSIT:
5198 mbox = ISP_READ(isp, OUTMAILBOX2);
5199 switch (mbox & 0x1c00) {
5200 case SXP_PINS_LVD_MODE:
5201 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
5202 SDPARAM(isp)->isp_diffmode = 0;
5203 SDPARAM(isp)->isp_ultramode = 0;
5204 SDPARAM(isp)->isp_lvdmode = 1;
5206 case SXP_PINS_HVD_MODE:
5207 isp_prt(isp, ISP_LOGINFO,
5208 "Transition to Differential mode");
5209 SDPARAM(isp)->isp_diffmode = 1;
5210 SDPARAM(isp)->isp_ultramode = 0;
5211 SDPARAM(isp)->isp_lvdmode = 0;
5213 case SXP_PINS_SE_MODE:
5214 isp_prt(isp, ISP_LOGINFO,
5215 "Transition to Single Ended mode");
5216 SDPARAM(isp)->isp_diffmode = 0;
5217 SDPARAM(isp)->isp_ultramode = 1;
5218 SDPARAM(isp)->isp_lvdmode = 0;
5221 isp_prt(isp, ISP_LOGWARN,
5222 "Transition to Unknown Mode 0x%x", mbox);
5226 * XXX: Set up to renegotiate again!
5228 /* Can only be for a 1080... */
5229 isp->isp_sendmarker |= (1 << bus);
5233 * We can use bus, which will always be zero for FC cards,
5234 * as a mailbox pattern accumulator to be checked below.
5237 bus = 0x1ce; /* outgoing mailbox regs 1-3, 6-7 */
5241 bus = 0x14e; /* outgoing mailbox regs 1-3, 6 */
5245 bus = 0x10e; /* outgoing mailbox regs 1-3 */
5249 bus = 0x106; /* outgoing mailbox regs 1-2 */
5253 case ASYNC_CMD_CMPLT:
5254 bus = 0x102; /* outgoing mailbox regs 1 */
5257 case ASYNC_RIO_RESP:
5260 case ASYNC_CTIO_DONE:
5262 #ifdef ISP_TARGET_MODE
5264 (ISP_READ(isp, OUTMAILBOX2) << 16) |
5265 (ISP_READ(isp, OUTMAILBOX1));
5266 if (isp_target_async(isp, handle, mbox)) {
5269 /* count it as a fast posting intr */
5270 isp->isp_fphccmplt++;
5273 isp_prt(isp, ISP_LOGINFO, "Fast Posting CTIO done");
5274 isp->isp_fphccmplt++; /* count it as a fast posting intr */
5278 case ASYNC_LIP_ERROR:
5280 case ASYNC_LIP_OCCURRED:
5281 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
5282 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
5283 isp->isp_sendmarker = 1;
5284 ISP_MARK_PORTDB(isp, 1);
5285 isp_async(isp, ISPASYNC_LIP, NULL);
5286 #ifdef ISP_TARGET_MODE
5287 if (isp_target_async(isp, bus, mbox)) {
5292 * We've had problems with data corruption occuring on
5293 * commands that complete (with no apparent error) after
5294 * we receive a LIP. This has been observed mostly on
5295 * Local Loop topologies. To be safe, let's just mark
5296 * all active commands as dead.
5298 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
5299 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
5301 for (i = j = 0; i < isp->isp_maxcmds; i++) {
5303 xs = isp->isp_xflist[i];
5306 XS_SETERR(xs, HBA_BUSRESET);
5310 isp_prt(isp, ISP_LOGERR,
5311 "LIP destroyed %d active commands", j);
5317 isp->isp_sendmarker = 1;
5318 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
5319 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
5320 ISP_MARK_PORTDB(isp, 1);
5321 isp_async(isp, ISPASYNC_LOOP_UP, NULL);
5322 #ifdef ISP_TARGET_MODE
5323 if (isp_target_async(isp, bus, mbox)) {
5329 case ASYNC_LOOP_DOWN:
5330 isp->isp_sendmarker = 1;
5331 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
5332 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
5333 ISP_MARK_PORTDB(isp, 1);
5334 isp_async(isp, ISPASYNC_LOOP_DOWN, NULL);
5335 #ifdef ISP_TARGET_MODE
5336 if (isp_target_async(isp, bus, mbox)) {
5342 case ASYNC_LOOP_RESET:
5343 isp->isp_sendmarker = 1;
5344 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
5345 FCPARAM(isp)->isp_loopstate = LOOP_NIL;
5346 ISP_MARK_PORTDB(isp, 1);
5347 isp_async(isp, ISPASYNC_LOOP_RESET, NULL);
5348 #ifdef ISP_TARGET_MODE
5349 if (isp_target_async(isp, bus, mbox)) {
5355 case ASYNC_PDB_CHANGED:
5356 isp->isp_sendmarker = 1;
5357 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
5358 ISP_MARK_PORTDB(isp, 1);
5359 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_PDB);
5362 case ASYNC_CHANGE_NOTIFY:
5363 if (FCPARAM(isp)->isp_topo == TOPO_F_PORT) {
5364 FCPARAM(isp)->isp_loopstate = LOOP_LSCAN_DONE;
5366 FCPARAM(isp)->isp_loopstate = LOOP_PDB_RCVD;
5368 ISP_MARK_PORTDB(isp, 1);
5369 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_SNS);
5373 ISP_MARK_PORTDB(isp, 1);
5374 isp->isp_sendmarker = 1;
5375 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
5376 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
5377 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
5378 #ifdef ISP_TARGET_MODE
5379 if (isp_target_async(isp, bus, mbox)) {
5383 isp_prt(isp, ISP_LOGINFO, "Point-to-Point mode");
5386 case ASYNC_CONNMODE:
5387 mbox = ISP_READ(isp, OUTMAILBOX1);
5388 ISP_MARK_PORTDB(isp, 1);
5391 isp_prt(isp, ISP_LOGINFO,
5392 "Point-to-Point -> Loop mode");
5395 isp_prt(isp, ISP_LOGINFO,
5396 "Loop -> Point-to-Point mode");
5398 case ISP_CONN_BADLIP:
5399 isp_prt(isp, ISP_LOGWARN,
5400 "Point-to-Point -> Loop mode (BAD LIP)");
5402 case ISP_CONN_FATAL:
5403 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
5404 isp_async(isp, ISPASYNC_FW_CRASH, NULL);
5406 case ISP_CONN_LOOPBACK:
5407 isp_prt(isp, ISP_LOGWARN,
5408 "Looped Back in Point-to-Point mode");
5411 isp_prt(isp, ISP_LOGWARN,
5412 "Unknown connection mode (0x%x)", mbox);
5415 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, ISPASYNC_CHANGE_OTHER);
5416 isp->isp_sendmarker = 1;
5417 FCPARAM(isp)->isp_fwstate = FW_CONFIG_WAIT;
5418 FCPARAM(isp)->isp_loopstate = LOOP_LIP_RCVD;
5421 case ASYNC_RJT_SENT: /* same as ASYNC_QFULL_SENT */
5423 isp_prt(isp, ISP_LOGTDEBUG0, "LS_RJT sent");
5425 } else if (IS_2200(isp)) {
5426 isp_prt(isp, ISP_LOGTDEBUG0, "QFULL sent");
5431 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
5437 uint16_t handles[16];
5439 for (nh = 0, i = 1; i < MAX_MAILBOX(isp); i++) {
5440 if ((bus & (1 << i)) == 0) {
5443 handles[nh++] = ISP_READ(isp, MBOX_OFF(i));
5445 for (i = 0; i < nh; i++) {
5446 isp_fastpost_complete(isp, handles[i]);
5447 isp_prt(isp, ISP_LOGDEBUG3,
5448 "fast post completion of %u", handles[i]);
5450 if (isp->isp_fpcchiwater < nh) {
5451 isp->isp_fpcchiwater = nh;
5454 isp->isp_intoasync++;
5460 * Handle other response entries. A pointer to the request queue output
5461 * index is here in case we want to eat several entries at once, although
5462 * this is not used currently.
5466 isp_handle_other_response(ispsoftc_t *isp, int type,
5467 isphdr_t *hp, uint32_t *optrp)
5470 case RQSTYPE_STATUS_CONT:
5471 isp_prt(isp, ISP_LOGDEBUG0, "Ignored Continuation Response");
5473 case RQSTYPE_MARKER:
5474 isp_prt(isp, ISP_LOGDEBUG0, "Marker Response");
5478 case RQSTYPE_ENABLE_LUN:
5479 case RQSTYPE_MODIFY_LUN:
5480 case RQSTYPE_NOTIFY:
5481 case RQSTYPE_NOTIFY_ACK:
5487 case RQSTYPE_ABTS_RCVD:
5488 case RQSTYPE_ABTS_RSP:
5489 isp->isp_rsltccmplt++; /* count as a response completion */
5490 #ifdef ISP_TARGET_MODE
5491 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
5496 case RQSTYPE_REQUEST:
5499 if (type != isp_get_response_type(isp, hp)) {
5501 * This is questionable- we're just papering over
5502 * something we've seen on SMP linux in target
5503 * mode- we don't really know what's happening
5504 * here that causes us to think we've gotten
5505 * an entry, but that either the entry isn't
5506 * filled out yet or our CPU read data is stale.
5508 isp_prt(isp, ISP_LOGINFO,
5509 "unstable type in response queue");
5512 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
5513 isp_get_response_type(isp, hp));
5514 if (isp_async(isp, ISPASYNC_UNHANDLED_RESPONSE, hp)) {
5522 isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
5524 switch (sp->req_completion_status & 0xff) {
5527 XS_SETERR(xs, HBA_NOERROR);
5531 case RQCS_INCOMPLETE:
5532 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
5533 isp_prt(isp, ISP_LOGDEBUG1,
5534 "Selection Timeout for %d.%d.%d",
5535 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5537 XS_SETERR(xs, HBA_SELTIMEOUT);
5538 *rp = XS_XFRLEN(xs);
5542 isp_prt(isp, ISP_LOGERR,
5543 "command incomplete for %d.%d.%d, state 0x%x",
5544 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
5545 sp->req_state_flags);
5548 case RQCS_DMA_ERROR:
5549 isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
5550 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5551 *rp = XS_XFRLEN(xs);
5554 case RQCS_TRANSPORT_ERROR:
5557 SNPRINTF(buf, sizeof (buf), "states=>");
5558 if (sp->req_state_flags & RQSF_GOT_BUS) {
5559 SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
5561 if (sp->req_state_flags & RQSF_GOT_TARGET) {
5562 SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
5564 if (sp->req_state_flags & RQSF_SENT_CDB) {
5565 SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
5567 if (sp->req_state_flags & RQSF_XFRD_DATA) {
5568 SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
5570 if (sp->req_state_flags & RQSF_GOT_STATUS) {
5571 SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
5573 if (sp->req_state_flags & RQSF_GOT_SENSE) {
5574 SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
5576 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
5577 SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
5579 SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
5580 if (sp->req_status_flags & RQSTF_DISCONNECT) {
5581 SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
5583 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
5584 SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
5586 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
5587 SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
5589 if (sp->req_status_flags & RQSTF_BUS_RESET) {
5590 SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
5592 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
5593 SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
5595 if (sp->req_status_flags & RQSTF_ABORTED) {
5596 SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
5598 if (sp->req_status_flags & RQSTF_TIMEOUT) {
5599 SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
5601 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
5602 SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
5604 isp_prt(isp, ISP_LOGERR, "%s", buf);
5605 isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d:\n%s",
5606 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), buf);
5607 *rp = XS_XFRLEN(xs);
5610 case RQCS_RESET_OCCURRED:
5611 isp_prt(isp, ISP_LOGWARN,
5612 "bus reset destroyed command for %d.%d.%d",
5613 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5614 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
5616 XS_SETERR(xs, HBA_BUSRESET);
5618 *rp = XS_XFRLEN(xs);
5622 isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
5623 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5624 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
5626 XS_SETERR(xs, HBA_ABORTED);
5631 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
5632 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5634 * XXX: Check to see if we logged out of the device.
5637 XS_SETERR(xs, HBA_CMDTIMEOUT);
5641 case RQCS_DATA_OVERRUN:
5642 XS_RESID(xs) = sp->req_resid;
5643 isp_prt(isp, ISP_LOGERR, "data overrun for command on %d.%d.%d",
5644 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5646 XS_SETERR(xs, HBA_DATAOVR);
5650 case RQCS_COMMAND_OVERRUN:
5651 isp_prt(isp, ISP_LOGERR,
5652 "command overrun for command on %d.%d.%d",
5653 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5656 case RQCS_STATUS_OVERRUN:
5657 isp_prt(isp, ISP_LOGERR,
5658 "status overrun for command on %d.%d.%d",
5659 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5662 case RQCS_BAD_MESSAGE:
5663 isp_prt(isp, ISP_LOGERR,
5664 "msg not COMMAND COMPLETE after status %d.%d.%d",
5665 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5668 case RQCS_NO_MESSAGE_OUT:
5669 isp_prt(isp, ISP_LOGERR,
5670 "No MESSAGE OUT phase after selection on %d.%d.%d",
5671 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5674 case RQCS_EXT_ID_FAILED:
5675 isp_prt(isp, ISP_LOGERR, "EXTENDED IDENTIFY failed %d.%d.%d",
5676 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5679 case RQCS_IDE_MSG_FAILED:
5680 isp_prt(isp, ISP_LOGERR,
5681 "INITIATOR DETECTED ERROR rejected by %d.%d.%d",
5682 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5685 case RQCS_ABORT_MSG_FAILED:
5686 isp_prt(isp, ISP_LOGERR, "ABORT OPERATION rejected by %d.%d.%d",
5687 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5690 case RQCS_REJECT_MSG_FAILED:
5691 isp_prt(isp, ISP_LOGERR, "MESSAGE REJECT rejected by %d.%d.%d",
5692 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5695 case RQCS_NOP_MSG_FAILED:
5696 isp_prt(isp, ISP_LOGERR, "NOP rejected by %d.%d.%d",
5697 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5700 case RQCS_PARITY_ERROR_MSG_FAILED:
5701 isp_prt(isp, ISP_LOGERR,
5702 "MESSAGE PARITY ERROR rejected by %d.%d.%d",
5703 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5706 case RQCS_DEVICE_RESET_MSG_FAILED:
5707 isp_prt(isp, ISP_LOGWARN,
5708 "BUS DEVICE RESET rejected by %d.%d.%d",
5709 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5712 case RQCS_ID_MSG_FAILED:
5713 isp_prt(isp, ISP_LOGERR, "IDENTIFY rejected by %d.%d.%d",
5714 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5717 case RQCS_UNEXP_BUS_FREE:
5718 isp_prt(isp, ISP_LOGERR, "%d.%d.%d had an unexpected bus free",
5719 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5722 case RQCS_DATA_UNDERRUN:
5725 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
5726 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
5727 isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
5728 XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
5729 (ru_marked)? "marked" : "not marked");
5731 XS_SETERR(xs, HBA_BOTCH);
5736 XS_RESID(xs) = sp->req_resid;
5738 XS_SETERR(xs, HBA_NOERROR);
5743 case RQCS_XACT_ERR1:
5744 isp_prt(isp, ISP_LOGERR, xact1, XS_CHANNEL(xs),
5745 XS_TGT(xs), XS_LUN(xs));
5748 case RQCS_XACT_ERR2:
5749 isp_prt(isp, ISP_LOGERR, xact2,
5750 XS_LUN(xs), XS_TGT(xs), XS_CHANNEL(xs));
5753 case RQCS_XACT_ERR3:
5754 isp_prt(isp, ISP_LOGERR, xact3,
5755 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5758 case RQCS_BAD_ENTRY:
5759 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
5762 case RQCS_QUEUE_FULL:
5763 isp_prt(isp, ISP_LOGDEBUG0,
5764 "internal queues full for %d.%d.%d status 0x%x",
5765 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), *XS_STSP(xs));
5768 * If QFULL or some other status byte is set, then this
5769 * isn't an error, per se.
5771 * Unfortunately, some QLogic f/w writers have, in
5772 * some cases, ommitted to *set* status to QFULL.
5775 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
5776 XS_SETERR(xs, HBA_NOERROR);
5784 *XS_STSP(xs) = SCSI_QFULL;
5785 XS_SETERR(xs, HBA_NOERROR);
5788 case RQCS_PHASE_SKIPPED:
5789 isp_prt(isp, ISP_LOGERR, pskip, XS_CHANNEL(xs),
5790 XS_TGT(xs), XS_LUN(xs));
5793 case RQCS_ARQS_FAILED:
5794 isp_prt(isp, ISP_LOGERR,
5795 "Auto Request Sense failed for %d.%d.%d",
5796 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5798 XS_SETERR(xs, HBA_ARQFAIL);
5802 case RQCS_WIDE_FAILED:
5803 isp_prt(isp, ISP_LOGERR,
5804 "Wide Negotiation failed for %d.%d.%d",
5805 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
5807 sdparam *sdp = isp->isp_param;
5808 sdp += XS_CHANNEL(xs);
5809 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
5810 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
5811 isp->isp_update |= (1 << XS_CHANNEL(xs));
5814 XS_SETERR(xs, HBA_NOERROR);
5818 case RQCS_SYNCXFER_FAILED:
5819 isp_prt(isp, ISP_LOGERR,
5820 "SDTR Message failed for target %d.%d.%d",
5821 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
5823 sdparam *sdp = isp->isp_param;
5824 sdp += XS_CHANNEL(xs);
5825 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
5826 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
5827 isp->isp_update |= (1 << XS_CHANNEL(xs));
5831 case RQCS_LVD_BUSERR:
5832 isp_prt(isp, ISP_LOGERR,
5833 "Bad LVD condition while talking to %d.%d.%d",
5834 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
5837 case RQCS_PORT_UNAVAILABLE:
5839 * No such port on the loop. Moral equivalent of SELTIMEO
5841 case RQCS_PORT_LOGGED_OUT:
5844 uint8_t sts = sp->req_completion_status & 0xff;
5847 * It was there (maybe)- treat as a selection timeout.
5849 if (sts == RQCS_PORT_UNAVAILABLE) {
5850 reason = "unavailable";
5855 isp_prt(isp, ISP_LOGINFO, "port %s for target %d",
5856 reason, XS_TGT(xs));
5859 * If we're on a local loop, force a LIP (which is overkill)
5860 * to force a re-login of this unit. If we're on fabric,
5861 * then we'll have to log in again as a matter of course.
5863 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
5864 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
5866 MEMZERO(&mbs, sizeof (mbs));
5867 mbs.param[0] = MBOX_INIT_LIP;
5868 if (FCPARAM(isp)->isp_2klogin) {
5869 mbs.ibits = (1 << 10);
5871 mbs.logval = MBLOGALL;
5872 isp_mboxcmd_qnw(isp, &mbs, 1);
5875 XS_SETERR(xs, HBA_SELTIMEOUT);
5879 case RQCS_PORT_CHANGED:
5880 isp_prt(isp, ISP_LOGWARN,
5881 "port changed for target %d", XS_TGT(xs));
5883 XS_SETERR(xs, HBA_SELTIMEOUT);
5887 case RQCS_PORT_BUSY:
5888 isp_prt(isp, ISP_LOGWARN,
5889 "port busy for target %d", XS_TGT(xs));
5891 XS_SETERR(xs, HBA_TGTBSY);
5896 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x",
5897 sp->req_completion_status);
5901 XS_SETERR(xs, HBA_BOTCH);
5906 isp_parse_status_24xx(ispsoftc_t *isp, isp24xx_statusreq_t *sp,
5909 int ru_marked, sv_marked;
5910 switch (sp->req_completion_status) {
5913 XS_SETERR(xs, HBA_NOERROR);
5917 case RQCS_DMA_ERROR:
5918 isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
5919 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5922 case RQCS_TRANSPORT_ERROR:
5923 isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d",
5924 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5927 case RQCS_RESET_OCCURRED:
5928 isp_prt(isp, ISP_LOGWARN,
5929 "bus reset destroyed command for %d.%d.%d",
5930 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5931 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
5933 XS_SETERR(xs, HBA_BUSRESET);
5938 isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
5939 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5940 isp->isp_sendmarker |= (1 << XS_CHANNEL(xs));
5942 XS_SETERR(xs, HBA_ABORTED);
5947 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
5948 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5950 XS_SETERR(xs, HBA_CMDTIMEOUT);
5954 case RQCS_DATA_OVERRUN:
5955 XS_RESID(xs) = sp->req_resid;
5956 isp_prt(isp, ISP_LOGERR,
5957 "data overrun for command on %d.%d.%d",
5958 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
5960 XS_SETERR(xs, HBA_DATAOVR);
5964 case RQCS_24XX_DRE: /* data reassembly error */
5965 isp_prt(isp, ISP_LOGERR, "data reassembly error for target %d",
5968 XS_SETERR(xs, HBA_ABORTED);
5970 *rp = XS_XFRLEN(xs);
5973 case RQCS_24XX_TABORT: /* aborted by target */
5974 isp_prt(isp, ISP_LOGERR, "target %d sent ABTS",
5977 XS_SETERR(xs, HBA_ABORTED);
5981 case RQCS_DATA_UNDERRUN:
5982 ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
5984 * We can get an underrun w/o things being marked
5985 * if we got a non-zero status.
5987 sv_marked = (sp->req_scsi_status & (RQCS_SV|RQCS_RV)) != 0;
5988 if ((ru_marked == 0 && sv_marked == 0) ||
5989 (sp->req_resid > XS_XFRLEN(xs))) {
5990 isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
5991 XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
5992 (ru_marked)? "marked" : "not marked");
5994 XS_SETERR(xs, HBA_BOTCH);
5998 XS_RESID(xs) = sp->req_resid;
5999 isp_prt(isp, ISP_LOGDEBUG0,
6000 "%d.%d.%d data underrun (%d) for command 0x%x",
6001 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
6002 sp->req_resid, XS_CDBP(xs)[0] & 0xff);
6004 XS_SETERR(xs, HBA_NOERROR);
6008 case RQCS_PORT_UNAVAILABLE:
6010 * No such port on the loop. Moral equivalent of SELTIMEO
6012 case RQCS_PORT_LOGGED_OUT:
6015 uint8_t sts = sp->req_completion_status & 0xff;
6018 * It was there (maybe)- treat as a selection timeout.
6020 if (sts == RQCS_PORT_UNAVAILABLE) {
6021 reason = "unavailable";
6026 isp_prt(isp, ISP_LOGINFO, "port %s for target %d",
6027 reason, XS_TGT(xs));
6030 * If we're on a local loop, force a LIP (which is overkill)
6031 * to force a re-login of this unit. If we're on fabric,
6032 * then we'll have to log in again as a matter of course.
6034 if (FCPARAM(isp)->isp_topo == TOPO_NL_PORT ||
6035 FCPARAM(isp)->isp_topo == TOPO_FL_PORT) {
6037 MEMZERO(&mbs, sizeof (mbs));
6038 mbs.param[0] = MBOX_INIT_LIP;
6039 if (FCPARAM(isp)->isp_2klogin) {
6040 mbs.ibits = (1 << 10);
6042 mbs.logval = MBLOGALL;
6043 isp_mboxcmd_qnw(isp, &mbs, 1);
6046 XS_SETERR(xs, HBA_SELTIMEOUT);
6050 case RQCS_PORT_CHANGED:
6051 isp_prt(isp, ISP_LOGWARN,
6052 "port changed for target %d", XS_TGT(xs));
6054 XS_SETERR(xs, HBA_SELTIMEOUT);
6059 case RQCS_24XX_ENOMEM: /* f/w resource unavailable */
6060 isp_prt(isp, ISP_LOGWARN,
6061 "f/w resource unavailable for target %d", XS_TGT(xs));
6063 *XS_STSP(xs) = SCSI_BUSY;
6064 XS_SETERR(xs, HBA_TGTBSY);
6068 case RQCS_24XX_TMO: /* task management overrun */
6069 isp_prt(isp, ISP_LOGWARN,
6070 "command for target %d overlapped task management",
6073 *XS_STSP(xs) = SCSI_BUSY;
6074 XS_SETERR(xs, HBA_TGTBSY);
6079 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x",
6080 sp->req_completion_status);
6084 XS_SETERR(xs, HBA_BOTCH);
6089 isp_fastpost_complete(ispsoftc_t *isp, uint16_t fph)
6096 xs = isp_find_xs(isp, fph);
6098 isp_prt(isp, ISP_LOGDEBUG1,
6099 "Command for fast post handle 0x%x not found", fph);
6102 isp_destroy_handle(isp, fph);
6105 * Since we don't have a result queue entry item,
6106 * we must believe that SCSI status is zero and
6107 * that all data transferred.
6109 XS_SET_STATE_STAT(isp, xs, NULL);
6111 *XS_STSP(xs) = SCSI_GOOD;
6112 if (XS_XFRLEN(xs)) {
6113 ISP_DMAFREE(isp, xs, fph);
6115 if (isp->isp_nactive)
6117 isp->isp_fphccmplt++;
6122 isp_mbox_continue(ispsoftc_t *isp)
6128 switch (isp->isp_lastmbxcmd) {
6129 case MBOX_WRITE_RAM_WORD:
6130 case MBOX_READ_RAM_WORD:
6131 case MBOX_WRITE_RAM_WORD_EXTENDED:
6132 case MBOX_READ_RAM_WORD_EXTENDED:
6137 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
6138 isp->isp_mbxwrk0 = 0;
6143 * Clear the previous interrupt.
6146 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
6148 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
6149 ISP_WRITE(isp, BIU_SEMA, 0);
6153 * Continue with next word.
6155 MEMZERO(&mbs, sizeof (mbs));
6156 ptr = isp->isp_mbxworkp;
6157 switch (isp->isp_lastmbxcmd) {
6158 case MBOX_WRITE_RAM_WORD:
6159 mbs.param[1] = isp->isp_mbxwrk1++;;
6160 mbs.param[2] = *ptr++;;
6162 case MBOX_READ_RAM_WORD:
6163 *ptr++ = isp->isp_mboxtmp[2];
6164 mbs.param[1] = isp->isp_mbxwrk1++;
6166 case MBOX_WRITE_RAM_WORD_EXTENDED:
6167 offset = isp->isp_mbxwrk1;
6168 offset |= isp->isp_mbxwrk8 << 16;
6170 mbs.param[2] = *ptr++;;
6171 mbs.param[1] = offset;
6172 mbs.param[8] = offset >> 16;
6173 isp->isp_mbxwrk1 = ++offset;
6174 isp->isp_mbxwrk8 = offset >> 16;
6176 case MBOX_READ_RAM_WORD_EXTENDED:
6177 offset = isp->isp_mbxwrk1;
6178 offset |= isp->isp_mbxwrk8 << 16;
6180 *ptr++ = isp->isp_mboxtmp[2];
6181 mbs.param[1] = offset;
6182 mbs.param[8] = offset >> 16;
6183 isp->isp_mbxwrk1 = ++offset;
6184 isp->isp_mbxwrk8 = offset >> 16;
6187 isp->isp_mbxworkp = ptr;
6189 mbs.param[0] = isp->isp_lastmbxcmd;
6190 mbs.logval = MBLOGALL;
6191 isp_mboxcmd_qnw(isp, &mbs, 0);
6195 #define HIWRD(x) ((x) >> 16)
6196 #define LOWRD(x) ((x) & 0xffff)
6197 #define ISPOPMAP(a, b) (((a) << 16) | (b))
6198 static const uint32_t mbpscsi[] = {
6199 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
6200 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
6201 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
6202 ISPOPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
6203 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
6204 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
6205 ISPOPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
6206 ISPOPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
6207 ISPOPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
6208 ISPOPMAP(0x00, 0x00), /* 0x09: */
6209 ISPOPMAP(0x00, 0x00), /* 0x0a: */
6210 ISPOPMAP(0x00, 0x00), /* 0x0b: */
6211 ISPOPMAP(0x00, 0x00), /* 0x0c: */
6212 ISPOPMAP(0x00, 0x00), /* 0x0d: */
6213 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
6214 ISPOPMAP(0x00, 0x00), /* 0x0f: */
6215 ISPOPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
6216 ISPOPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
6217 ISPOPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
6218 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
6219 ISPOPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
6220 ISPOPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
6221 ISPOPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
6222 ISPOPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
6223 ISPOPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
6224 ISPOPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
6225 ISPOPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
6226 ISPOPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
6227 ISPOPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
6228 ISPOPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
6229 ISPOPMAP(0x00, 0x00), /* 0x1e: */
6230 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
6231 ISPOPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
6232 ISPOPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
6233 ISPOPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
6234 ISPOPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
6235 ISPOPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
6236 ISPOPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
6237 ISPOPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
6238 ISPOPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
6239 ISPOPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
6240 ISPOPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
6241 ISPOPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
6242 ISPOPMAP(0x00, 0x00), /* 0x2b: */
6243 ISPOPMAP(0x00, 0x00), /* 0x2c: */
6244 ISPOPMAP(0x00, 0x00), /* 0x2d: */
6245 ISPOPMAP(0x00, 0x00), /* 0x2e: */
6246 ISPOPMAP(0x00, 0x00), /* 0x2f: */
6247 ISPOPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
6248 ISPOPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
6249 ISPOPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
6250 ISPOPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
6251 ISPOPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
6252 ISPOPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
6253 ISPOPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
6254 ISPOPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
6255 ISPOPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
6256 ISPOPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
6257 ISPOPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
6258 ISPOPMAP(0x00, 0x00), /* 0x3b: */
6259 ISPOPMAP(0x00, 0x00), /* 0x3c: */
6260 ISPOPMAP(0x00, 0x00), /* 0x3d: */
6261 ISPOPMAP(0x00, 0x00), /* 0x3e: */
6262 ISPOPMAP(0x00, 0x00), /* 0x3f: */
6263 ISPOPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
6264 ISPOPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
6265 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
6266 ISPOPMAP(0x00, 0x00), /* 0x43: */
6267 ISPOPMAP(0x00, 0x00), /* 0x44: */
6268 ISPOPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
6269 ISPOPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
6270 ISPOPMAP(0x00, 0x00), /* 0x47: */
6271 ISPOPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
6272 ISPOPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
6273 ISPOPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
6274 ISPOPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
6275 ISPOPMAP(0x00, 0x00), /* 0x4c: */
6276 ISPOPMAP(0x00, 0x00), /* 0x4d: */
6277 ISPOPMAP(0x00, 0x00), /* 0x4e: */
6278 ISPOPMAP(0x00, 0x00), /* 0x4f: */
6279 ISPOPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
6280 ISPOPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
6281 ISPOPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
6282 ISPOPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
6283 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUCUTE COMMAND IOCB A64 */
6284 ISPOPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
6285 ISPOPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
6286 ISPOPMAP(0x00, 0x00), /* 0x57: */
6287 ISPOPMAP(0x00, 0x00), /* 0x58: */
6288 ISPOPMAP(0x00, 0x00), /* 0x59: */
6289 ISPOPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
6290 ISPOPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
6291 ISPOPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
6292 ISPOPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
6295 static const char *scsi_mbcmd_names[] = {
6312 "INIT REQUEST QUEUE",
6313 "INIT RESULT QUEUE",
6323 "SINGLE STEP QUEUE",
6325 "GET DEV QUEUE STATUS",
6327 "GET FIRMWARE STATUS",
6329 "GET SELECT TIMEOUT",
6331 "GET TAG AGE LIMIT",
6333 "GET ACT NEG STATE",
6334 "GET ASYNC DATA SETUP TIME",
6336 "GET TARGET PARAMS",
6337 "GET DEV QUEUE PARAMS",
6338 "GET RESET DELAY PARAMS",
6345 "SET SELECT TIMEOUT",
6347 "SET TAG AGE LIMIT",
6349 "SET ACT NEG STATE",
6350 "SET ASYNC DATA SETUP TIME",
6351 "SET PCI CONTROL PARAMS",
6352 "SET TARGET PARAMS",
6353 "SET DEV QUEUE PARAMS",
6354 "SET RESET DELAY PARAMS",
6360 "RETURN BIOS BLOCK ADDR",
6361 "WRITE FOUR RAM WORDS",
6365 "SET SYSTEM PARAMETER",
6366 "GET SYSTEM PARAMETER",
6368 "GET SCAM CONFIGURATION",
6369 "SET SCAM CONFIGURATION",
6370 "SET FIRMWARE FEATURES",
6371 "GET FIRMWARE FEATURES",
6378 "INITIALIZE REQUEST QUEUE A64",
6379 "INITIALIZE RESPONSE QUEUE A64",
6381 "ENABLE TARGET MODE",
6382 "GET TARGET MODE STATE",
6386 "SET DATA OVERRUN RECOVERY MODE",
6387 "GET DATA OVERRUN RECOVERY MODE",
6392 static const uint32_t mbpfc[] = {
6393 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
6394 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
6395 ISPOPMAP(0x0f, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
6396 ISPOPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
6397 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
6398 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
6399 ISPOPMAP(0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
6400 ISPOPMAP(0x03, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
6401 ISPOPMAP(0x01, 0x4f), /* 0x08: MBOX_ABOUT_FIRMWARE */
6402 ISPOPMAP(0xdf, 0x01), /* 0x09: MBOX_LOAD_RISC_RAM_2100 */
6403 ISPOPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
6404 ISPOPMAP(0x1ff, 0x01), /* 0x0b: MBOX_LOAD_RISC_RAM */
6405 ISPOPMAP(0x00, 0x00), /* 0x0c: */
6406 ISPOPMAP(0x10f, 0x01), /* 0x0d: MBOX_WRITE_RAM_WORD_EXTENDED */
6407 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
6408 ISPOPMAP(0x10f, 0x05), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED */
6409 ISPOPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
6410 ISPOPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
6411 ISPOPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
6412 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
6413 ISPOPMAP(0x01, 0xff), /* 0x14: MBOX_STOP_FIRMWARE */
6414 ISPOPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
6415 ISPOPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
6416 ISPOPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
6417 ISPOPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
6418 ISPOPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
6419 ISPOPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
6420 ISPOPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
6421 ISPOPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
6422 ISPOPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
6423 ISPOPMAP(0x00, 0x00), /* 0x1e: */
6424 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
6425 ISPOPMAP(0x01, 0x4f), /* 0x20: MBOX_GET_LOOP_ID */
6426 ISPOPMAP(0x00, 0x00), /* 0x21: */
6427 ISPOPMAP(0x01, 0x07), /* 0x22: MBOX_GET_RETRY_COUNT */
6428 ISPOPMAP(0x00, 0x00), /* 0x23: */
6429 ISPOPMAP(0x00, 0x00), /* 0x24: */
6430 ISPOPMAP(0x00, 0x00), /* 0x25: */
6431 ISPOPMAP(0x00, 0x00), /* 0x26: */
6432 ISPOPMAP(0x00, 0x00), /* 0x27: */
6433 ISPOPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
6434 ISPOPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
6435 ISPOPMAP(0x00, 0x00), /* 0x2a: */
6436 ISPOPMAP(0x00, 0x00), /* 0x2b: */
6437 ISPOPMAP(0x00, 0x00), /* 0x2c: */
6438 ISPOPMAP(0x00, 0x00), /* 0x2d: */
6439 ISPOPMAP(0x00, 0x00), /* 0x2e: */
6440 ISPOPMAP(0x00, 0x00), /* 0x2f: */
6441 ISPOPMAP(0x00, 0x00), /* 0x30: */
6442 ISPOPMAP(0x00, 0x00), /* 0x31: */
6443 ISPOPMAP(0x07, 0x07), /* 0x32: MBOX_SET_RETRY_COUNT */
6444 ISPOPMAP(0x00, 0x00), /* 0x33: */
6445 ISPOPMAP(0x00, 0x00), /* 0x34: */
6446 ISPOPMAP(0x00, 0x00), /* 0x35: */
6447 ISPOPMAP(0x00, 0x00), /* 0x36: */
6448 ISPOPMAP(0x00, 0x00), /* 0x37: */
6449 ISPOPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
6450 ISPOPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
6451 ISPOPMAP(0x00, 0x00), /* 0x3a: */
6452 ISPOPMAP(0x00, 0x00), /* 0x3b: */
6453 ISPOPMAP(0x00, 0x00), /* 0x3c: */
6454 ISPOPMAP(0x00, 0x00), /* 0x3d: */
6455 ISPOPMAP(0x00, 0x00), /* 0x3e: */
6456 ISPOPMAP(0x00, 0x00), /* 0x3f: */
6457 ISPOPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
6458 ISPOPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
6459 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_GET_RESOURCE_COUNT */
6460 ISPOPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_OFFLINE_MODE */
6461 ISPOPMAP(0x00, 0x00), /* 0x44: */
6462 ISPOPMAP(0x00, 0x00), /* 0x45: */
6463 ISPOPMAP(0x00, 0x00), /* 0x46: */
6464 ISPOPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
6465 ISPOPMAP(0x00, 0x00), /* 0x48: */
6466 ISPOPMAP(0x00, 0x00), /* 0x49: */
6467 ISPOPMAP(0x00, 0x00), /* 0x4a: */
6468 ISPOPMAP(0x00, 0x00), /* 0x4b: */
6469 ISPOPMAP(0x00, 0x00), /* 0x4c: */
6470 ISPOPMAP(0x00, 0x00), /* 0x4d: */
6471 ISPOPMAP(0x00, 0x00), /* 0x4e: */
6472 ISPOPMAP(0x00, 0x00), /* 0x4f: */
6473 ISPOPMAP(0x00, 0x00), /* 0x50: */
6474 ISPOPMAP(0x00, 0x00), /* 0x51: */
6475 ISPOPMAP(0x00, 0x00), /* 0x52: */
6476 ISPOPMAP(0x00, 0x00), /* 0x53: */
6477 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
6478 ISPOPMAP(0x00, 0x00), /* 0x55: */
6479 ISPOPMAP(0x00, 0x00), /* 0x56: */
6480 ISPOPMAP(0x00, 0x00), /* 0x57: */
6481 ISPOPMAP(0x00, 0x00), /* 0x58: */
6482 ISPOPMAP(0x00, 0x00), /* 0x59: */
6483 ISPOPMAP(0x00, 0x00), /* 0x5a: */
6484 ISPOPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
6485 ISPOPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
6486 ISPOPMAP(0x07, 0x03), /* 0x5d: MBOX_GET_SET_DATA_RATE */
6487 ISPOPMAP(0x00, 0x00), /* 0x5e: */
6488 ISPOPMAP(0x00, 0x00), /* 0x5f: */
6489 ISPOPMAP(0xcd, 0x01), /* 0x60: MBOX_INIT_FIRMWARE */
6490 ISPOPMAP(0x00, 0x00), /* 0x61: */
6491 ISPOPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
6492 ISPOPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
6493 ISPOPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
6494 ISPOPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
6495 ISPOPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
6496 ISPOPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
6497 ISPOPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
6498 ISPOPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
6499 ISPOPMAP(0x03, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
6500 ISPOPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
6501 ISPOPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
6502 ISPOPMAP(0x00, 0x00), /* 0x6d: */
6503 ISPOPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
6504 ISPOPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
6505 ISPOPMAP(0x03, 0x01), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
6506 ISPOPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
6507 ISPOPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
6508 ISPOPMAP(0x00, 0x00), /* 0x73: */
6509 ISPOPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
6510 ISPOPMAP(0xcf, 0x03), /* 0x75: GET PORT/NODE NAME LIST */
6511 ISPOPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
6512 ISPOPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
6513 ISPOPMAP(0x00, 0x00), /* 0x78: */
6514 ISPOPMAP(0x00, 0x00), /* 0x79: */
6515 ISPOPMAP(0x00, 0x00), /* 0x7a: */
6516 ISPOPMAP(0x00, 0x00), /* 0x7b: */
6517 ISPOPMAP(0x4f, 0x03), /* 0x7c: Get ID List */
6518 ISPOPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
6519 ISPOPMAP(0x0f, 0x01) /* 0x7e: LUN RESET */
6524 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
6525 * do not access at this time in the core driver. The caller is
6526 * responsible for setting this register first (Gross!). The assumption
6527 * is that we won't overflow.
6530 static const char *fc_mbcmd_names[] = {
6542 "WRITE RAM WORD EXTENDED",
6544 "READ RAM WORD EXTENDED",
6547 "INIT REQUEST QUEUE",
6548 "INIT RESULT QUEUE",
6558 "SINGLE STEP QUEUE",
6560 "GET DEV QUEUE STATUS",
6562 "GET FIRMWARE STATUS",
6571 "GET FIRMWARE OPTIONS",
6572 "GET PORT QUEUE PARAMS",
6587 "SET FIRMWARE OPTIONS",
6588 "SET PORT QUEUE PARAMS",
6597 "GET RESOURCE COUNT",
6598 "REQUEST NON PARTICIPATING MODE",
6602 "GET PORT DATABASE ENHANCED",
6624 "GET/SET DATA RATE",
6630 "GET FC-AL POSITION MAP",
6631 "GET PORT DATABASE",
6643 "SEND CHANGE REQUEST",
6648 "GET PORT/NODE NAME LIST",
6650 "INITIALIZE IP MAILBOX",
6661 isp_mboxcmd_qnw(ispsoftc_t *isp, mbreg_t *mbp, int nodelay)
6663 unsigned int ibits, obits, box, opcode;
6664 const uint32_t *mcp;
6671 opcode = mbp->param[0];
6672 ibits = HIWRD(mcp[opcode]) & NMBOX_BMASK(isp);
6673 obits = LOWRD(mcp[opcode]) & NMBOX_BMASK(isp);
6674 ibits |= mbp->ibits;
6675 obits |= mbp->obits;
6676 for (box = 0; box < MAX_MAILBOX(isp); box++) {
6677 if (ibits & (1 << box)) {
6678 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
6681 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
6685 isp->isp_lastmbxcmd = opcode;
6686 isp->isp_obits = obits;
6687 isp->isp_mboxbsy = 1;
6690 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_SET_HOST_INT);
6692 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
6695 * Oddly enough, if we're not delaying for an answer,
6696 * delay a bit to give the f/w a chance to pick up the
6705 isp_mboxcmd(ispsoftc_t *isp, mbreg_t *mbp)
6707 const char *cname, *xname;
6708 char tname[16], mname[16];
6709 unsigned int lim, ibits, obits, box, opcode;
6710 const uint32_t *mcp;
6714 lim = (sizeof (mbpfc) / sizeof (mbpfc[0]));
6717 lim = (sizeof (mbpscsi) / sizeof (mbpscsi[0]));
6720 if ((opcode = mbp->param[0]) >= lim) {
6721 mbp->param[0] = MBOX_INVALID_COMMAND;
6722 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
6726 ibits = HIWRD(mcp[opcode]) & NMBOX_BMASK(isp);
6727 obits = LOWRD(mcp[opcode]) & NMBOX_BMASK(isp);
6730 * Pick up any additional bits that the caller might have set.
6732 ibits |= mbp->ibits;
6733 obits |= mbp->obits;
6735 if (ibits == 0 && obits == 0) {
6736 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
6737 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
6742 * Get exclusive usage of mailbox registers.
6744 if (MBOX_ACQUIRE(isp)) {
6745 mbp->param[0] = MBOX_REGS_BUSY;
6749 for (box = 0; box < MAX_MAILBOX(isp); box++) {
6750 if (ibits & (1 << box)) {
6751 isp_prt(isp, ISP_LOGDEBUG1, "IN mbox %d = 0x%04x", box,
6753 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
6755 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
6758 isp->isp_lastmbxcmd = opcode;
6761 * We assume that we can't overwrite a previous command.
6763 isp->isp_obits = obits;
6764 isp->isp_mboxbsy = 1;
6767 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
6770 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_SET_HOST_INT);
6772 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
6776 * While we haven't finished the command, spin our wheels here.
6778 MBOX_WAIT_COMPLETE(isp, mbp);
6781 * Did the command time out?
6783 if (mbp->param[0] == MBOX_TIMEOUT) {
6789 * Copy back output registers.
6791 for (box = 0; box < MAX_MAILBOX(isp); box++) {
6792 if (obits & (1 << box)) {
6793 mbp->param[box] = isp->isp_mboxtmp[box];
6794 isp_prt(isp, ISP_LOGDEBUG1, "OUT mbox %d = 0x%04x", box,
6801 isp->isp_mboxbsy = 0;
6802 if (mbp->logval == 0 || opcode == MBOX_EXEC_FIRMWARE) {
6805 cname = (IS_FC(isp))? fc_mbcmd_names[opcode] : scsi_mbcmd_names[opcode];
6806 if (cname == NULL) {
6808 SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
6812 * Just to be chatty here...
6815 switch (mbp->param[0]) {
6816 case MBOX_COMMAND_COMPLETE:
6818 case MBOX_INVALID_COMMAND:
6819 if (mbp->logval & MBLOGMASK(MBOX_COMMAND_COMPLETE)) {
6820 xname = "INVALID COMMAND";
6823 case MBOX_HOST_INTERFACE_ERROR:
6824 if (mbp->logval & MBLOGMASK(MBOX_HOST_INTERFACE_ERROR)) {
6825 xname = "HOST INTERFACE ERROR";
6828 case MBOX_TEST_FAILED:
6829 if (mbp->logval & MBLOGMASK(MBOX_TEST_FAILED)) {
6830 xname = "TEST FAILED";
6833 case MBOX_COMMAND_ERROR:
6834 if (mbp->logval & MBLOGMASK(MBOX_COMMAND_ERROR)) {
6835 xname = "COMMAND ERROR";
6838 case MBOX_COMMAND_PARAM_ERROR:
6839 if (mbp->logval & MBLOGMASK(MBOX_COMMAND_PARAM_ERROR)) {
6840 xname = "COMMAND PARAMETER ERROR";
6843 case MBOX_LOOP_ID_USED:
6844 if (mbp->logval & MBLOGMASK(MBOX_LOOP_ID_USED)) {
6845 xname = "LOOP ID ALREADY IN USE";
6848 case MBOX_PORT_ID_USED:
6849 if (mbp->logval & MBLOGMASK(MBOX_PORT_ID_USED)) {
6850 xname = "PORT ID ALREADY IN USE";
6853 case MBOX_ALL_IDS_USED:
6854 if (mbp->logval & MBLOGMASK(MBOX_ALL_IDS_USED)) {
6855 xname = "ALL LOOP IDS IN USE";
6858 case MBOX_REGS_BUSY:
6859 xname = "REGISTERS BUSY";
6865 SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
6870 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s)",
6876 isp_fw_state(ispsoftc_t *isp)
6880 fcparam *fcp = isp->isp_param;
6882 MEMZERO(&mbs, sizeof (mbs));
6883 mbs.param[0] = MBOX_GET_FW_STATE;
6884 mbs.logval = MBLOGALL;
6885 isp_mboxcmd(isp, &mbs);
6886 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
6887 fcp->isp_fwstate = mbs.param[1];
6893 isp_update(ispsoftc_t *isp)
6897 for (bus = 0, upmask = isp->isp_update; upmask != 0; bus++) {
6898 if (upmask & (1 << bus)) {
6899 isp_update_bus(isp, bus);
6901 upmask &= ~(1 << bus);
6906 isp_update_bus(ispsoftc_t *isp, int bus)
6912 isp->isp_update &= ~(1 << bus);
6915 * There are no 'per-bus' settings for Fibre Channel.
6919 sdp = isp->isp_param;
6922 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
6923 uint16_t flags, period, offset;
6926 if (sdp->isp_devparam[tgt].dev_enable == 0) {
6927 sdp->isp_devparam[tgt].dev_update = 0;
6928 sdp->isp_devparam[tgt].dev_refresh = 0;
6929 isp_prt(isp, ISP_LOGDEBUG0,
6930 "skipping target %d bus %d update", tgt, bus);
6934 * If the goal is to update the status of the device,
6935 * take what's in goal_flags and try and set the device
6936 * toward that. Otherwise, if we're just refreshing the
6937 * current device state, get the current parameters.
6940 MEMZERO(&mbs, sizeof (mbs));
6943 * Refresh overrides set
6945 if (sdp->isp_devparam[tgt].dev_refresh) {
6946 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
6948 } else if (sdp->isp_devparam[tgt].dev_update) {
6949 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
6952 * Make sure goal_flags has "Renegotiate on Error"
6953 * on and "Freeze Queue on Error" off.
6955 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
6956 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
6957 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
6960 * Insist that PARITY must be enabled
6961 * if SYNC or WIDE is enabled.
6963 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
6964 mbs.param[2] |= DPARM_PARITY;
6967 if (mbs.param[2] & DPARM_SYNC) {
6969 (sdp->isp_devparam[tgt].goal_offset << 8) |
6970 (sdp->isp_devparam[tgt].goal_period);
6973 * A command completion later that has
6974 * RQSTF_NEGOTIATION set can cause
6975 * the dev_refresh/announce cycle also.
6977 * Note: It is really important to update our current
6978 * flags with at least the state of TAG capabilities-
6979 * otherwise we might try and send a tagged command
6980 * when we have it all turned off. So change it here
6981 * to say that current already matches goal.
6983 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
6984 sdp->isp_devparam[tgt].actv_flags |=
6985 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
6986 isp_prt(isp, ISP_LOGDEBUG0,
6987 "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
6988 bus, tgt, mbs.param[2], mbs.param[3] >> 8,
6989 mbs.param[3] & 0xff);
6994 mbs.param[1] = (bus << 15) | (tgt << 8);
6995 mbs.logval = MBLOGALL;
6996 isp_mboxcmd(isp, &mbs);
6997 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7001 isp->isp_sendmarker |= (1 << bus);
7002 sdp->isp_devparam[tgt].dev_update = 0;
7003 sdp->isp_devparam[tgt].dev_refresh = 1;
7005 sdp->isp_devparam[tgt].dev_refresh = 0;
7006 flags = mbs.param[2];
7007 period = mbs.param[3] & 0xff;
7008 offset = mbs.param[3] >> 8;
7009 sdp->isp_devparam[tgt].actv_flags = flags;
7010 sdp->isp_devparam[tgt].actv_period = period;
7011 sdp->isp_devparam[tgt].actv_offset = offset;
7012 get = (bus << 16) | tgt;
7013 (void) isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, &get);
7017 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7018 if (sdp->isp_devparam[tgt].dev_update ||
7019 sdp->isp_devparam[tgt].dev_refresh) {
7020 isp->isp_update |= (1 << bus);
7026 #ifndef DEFAULT_EXEC_THROTTLE
7027 #define DEFAULT_EXEC_THROTTLE(isp) ISP_EXEC_THROTTLE
7031 isp_setdfltparm(ispsoftc_t *isp, int channel)
7036 sdp = (sdparam *) isp->isp_param;
7040 * Been there, done that, got the T-shirt...
7042 if (sdp->isp_gotdparms) {
7045 sdp->isp_gotdparms = 1;
7046 sdp->isp_bad_nvram = 0;
7048 * Establish some default parameters.
7050 sdp->isp_cmd_dma_burst_enable = 0;
7051 sdp->isp_data_dma_burst_enabl = 1;
7052 sdp->isp_fifo_threshold = 0;
7053 sdp->isp_initiator_id = DEFAULT_IID(isp);
7054 if (isp->isp_type >= ISP_HA_SCSI_1040) {
7055 sdp->isp_async_data_setup = 9;
7057 sdp->isp_async_data_setup = 6;
7059 sdp->isp_selection_timeout = 250;
7060 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
7061 sdp->isp_tag_aging = 8;
7062 sdp->isp_bus_reset_delay = 5;
7064 * Don't retry selection, busy or queue full automatically- reflect
7067 sdp->isp_retry_count = 0;
7068 sdp->isp_retry_delay = 0;
7070 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7071 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
7072 sdp->isp_devparam[tgt].dev_enable = 1;
7076 * If we've not been told to avoid reading NVRAM, try and read it.
7077 * If we're successful reading it, we can then return because NVRAM
7078 * will tell us what the desired settings are. Otherwise, we establish
7079 * some reasonable 'fake' nvram and goal defaults.
7082 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7083 if (isp_read_nvram(isp) == 0) {
7086 sdp->isp_bad_nvram = 1;
7090 * Now try and see whether we have specific values for them.
7092 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7095 MEMZERO(&mbs, sizeof (mbs));
7096 mbs.param[0] = MBOX_GET_ACT_NEG_STATE;
7097 mbs.logval = MBLOGNONE;
7098 isp_mboxcmd(isp, &mbs);
7099 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7100 sdp->isp_req_ack_active_neg = 1;
7101 sdp->isp_data_line_active_neg = 1;
7103 sdp->isp_req_ack_active_neg =
7104 (mbs.param[1+channel] >> 4) & 0x1;
7105 sdp->isp_data_line_active_neg =
7106 (mbs.param[1+channel] >> 5) & 0x1;
7110 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc3,
7111 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
7112 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
7113 sdp->isp_retry_delay, sdp->isp_async_data_setup);
7114 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc3,
7115 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
7116 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
7117 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
7120 * The trick here is to establish a default for the default (honk!)
7121 * state (goal_flags). Then try and get the current status from
7122 * the card to fill in the current state. We don't, in fact, set
7123 * the default to the SAFE default state- that's not the goal state.
7125 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7127 sdp->isp_devparam[tgt].actv_offset = 0;
7128 sdp->isp_devparam[tgt].actv_period = 0;
7129 sdp->isp_devparam[tgt].actv_flags = 0;
7131 sdp->isp_devparam[tgt].goal_flags =
7132 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
7135 * We default to Wide/Fast for versions less than a 1040
7136 * (unless it's SBus).
7138 if (IS_ULTRA3(isp)) {
7139 off = ISP_80M_SYNCPARMS >> 8;
7140 per = ISP_80M_SYNCPARMS & 0xff;
7141 } else if (IS_ULTRA2(isp)) {
7142 off = ISP_40M_SYNCPARMS >> 8;
7143 per = ISP_40M_SYNCPARMS & 0xff;
7144 } else if (IS_1240(isp)) {
7145 off = ISP_20M_SYNCPARMS >> 8;
7146 per = ISP_20M_SYNCPARMS & 0xff;
7147 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
7148 isp->isp_type < ISP_HA_SCSI_1020A) ||
7149 (isp->isp_bustype == ISP_BT_PCI &&
7150 isp->isp_type < ISP_HA_SCSI_1040) ||
7151 (isp->isp_clock && isp->isp_clock < 60) ||
7152 (sdp->isp_ultramode == 0)) {
7153 off = ISP_10M_SYNCPARMS >> 8;
7154 per = ISP_10M_SYNCPARMS & 0xff;
7156 off = ISP_20M_SYNCPARMS_1040 >> 8;
7157 per = ISP_20M_SYNCPARMS_1040 & 0xff;
7159 sdp->isp_devparam[tgt].goal_offset =
7160 sdp->isp_devparam[tgt].nvrm_offset = off;
7161 sdp->isp_devparam[tgt].goal_period =
7162 sdp->isp_devparam[tgt].nvrm_period = per;
7164 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc3,
7165 channel, tgt, sdp->isp_devparam[tgt].nvrm_flags,
7166 sdp->isp_devparam[tgt].nvrm_offset,
7167 sdp->isp_devparam[tgt].nvrm_period);
7171 #ifndef DEFAULT_FRAMESIZE
7172 #define DEFAULT_FRAMESIZE(isp) ICB_DFLT_FRMLEN
7175 isp_setdfltfcparm(ispsoftc_t *isp)
7177 fcparam *fcp = FCPARAM(isp);
7179 if (fcp->isp_gotdparms) {
7182 fcp->isp_gotdparms = 1;
7183 fcp->isp_bad_nvram = 0;
7184 fcp->isp_maxfrmlen = DEFAULT_FRAMESIZE(isp);
7185 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
7186 fcp->isp_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
7187 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
7188 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
7189 /* Platform specific.... */
7190 fcp->isp_loopid = DEFAULT_LOOPID(isp);
7191 fcp->isp_wwnn_nvram = DEFAULT_NODEWWN(isp);
7192 fcp->isp_wwpn_nvram = DEFAULT_PORTWWN(isp);
7193 fcp->isp_fwoptions = 0;
7194 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
7195 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
7196 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
7197 fcp->isp_fwoptions |= ICBOPT_FAST_POST;
7198 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX) {
7199 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
7203 * Make sure this is turned off now until we get
7204 * extended options from NVRAM
7206 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
7209 * Now try and read NVRAM unless told to not do so.
7210 * This will set fcparam's isp_wwnn_nvram && isp_wwpn_nvram.
7212 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7215 * Give a couple of tries at reading NVRAM.
7217 for (i = 0; i < 2; i++) {
7218 j = isp_read_nvram(isp);
7224 fcp->isp_bad_nvram = 1;
7225 isp->isp_confopts |= ISP_CFG_NONVRAM;
7226 isp->isp_confopts |= ISP_CFG_OWNWWPN;
7227 isp->isp_confopts |= ISP_CFG_OWNWWNN;
7230 isp->isp_confopts |= ISP_CFG_OWNWWPN|ISP_CFG_OWNWWNN;
7234 * Set node && port to override platform set defaults
7235 * unless the nvram read failed (or none was done),
7236 * or the platform code wants to use what had been
7237 * set in the defaults.
7239 if (isp->isp_confopts & ISP_CFG_OWNWWNN) {
7240 isp_prt(isp, ISP_LOGCONFIG, "Using Node WWN 0x%08x%08x",
7241 (uint32_t) (DEFAULT_NODEWWN(isp) >> 32),
7242 (uint32_t) (DEFAULT_NODEWWN(isp) & 0xffffffff));
7243 ISP_NODEWWN(isp) = DEFAULT_NODEWWN(isp);
7246 * We always start out with values derived
7247 * from NVRAM or our platform default.
7249 ISP_NODEWWN(isp) = fcp->isp_wwnn_nvram;
7250 if (fcp->isp_wwnn_nvram == 0) {
7251 isp_prt(isp, ISP_LOGCONFIG,
7252 "bad WWNN- using default");
7253 ISP_NODEWWN(isp) = DEFAULT_NODEWWN(isp);
7256 if (isp->isp_confopts & ISP_CFG_OWNWWPN) {
7257 isp_prt(isp, ISP_LOGCONFIG, "Using Port WWN 0x%08x%08x",
7258 (uint32_t) (DEFAULT_PORTWWN(isp) >> 32),
7259 (uint32_t) (DEFAULT_PORTWWN(isp) & 0xffffffff));
7260 ISP_PORTWWN(isp) = DEFAULT_PORTWWN(isp);
7263 * We always start out with values derived
7264 * from NVRAM or our platform default.
7266 ISP_PORTWWN(isp) = fcp->isp_wwpn_nvram;
7267 if (fcp->isp_wwpn_nvram == 0) {
7268 isp_prt(isp, ISP_LOGCONFIG,
7269 "bad WWPN- using default");
7270 ISP_PORTWWN(isp) = DEFAULT_PORTWWN(isp);
7276 * Re-initialize the ISP and complete all orphaned commands
7277 * with a 'botched' notice. The reset/init routines should
7278 * not disturb an already active list of commands.
7282 isp_reinit(ispsoftc_t *isp)
7288 ISP_MARK_PORTDB(isp, 0);
7291 if (isp->isp_state != ISP_RESETSTATE) {
7292 isp_prt(isp, ISP_LOGERR, "isp_reinit cannot reset card");
7293 } else if (isp->isp_role != ISP_ROLE_NONE) {
7295 if (isp->isp_state == ISP_INITSTATE) {
7296 isp->isp_state = ISP_RUNSTATE;
7298 if (isp->isp_state != ISP_RUNSTATE) {
7299 isp_prt(isp, ISP_LOGERR,
7300 "isp_reinit cannot restart card");
7301 ISP_DISABLE_INTS(isp);
7304 ISP_DISABLE_INTS(isp);
7307 * If we're in ISP_ROLE_NONE, turn off the lasers.
7309 if (!IS_24XX(isp)) {
7310 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
7311 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
7312 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
7313 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
7314 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
7318 isp->isp_nactive = 0;
7320 for (tmp = 0; tmp < isp->isp_maxcmds; tmp++) {
7323 xs = isp->isp_xflist[tmp];
7327 handle = isp_find_handle(isp, xs);
7331 isp_destroy_handle(isp, handle);
7332 if (XS_XFRLEN(xs)) {
7333 ISP_DMAFREE(isp, xs, handle);
7334 XS_RESID(xs) = XS_XFRLEN(xs);
7338 XS_SETERR(xs, HBA_BUSRESET);
7341 #ifdef ISP_TARGET_MODE
7342 MEMZERO(isp->isp_tgtlist, isp->isp_maxcmds * sizeof (void **));
7350 isp_read_nvram(ispsoftc_t *isp)
7353 uint8_t csum, minversion;
7355 uint8_t _x[ISP2100_NVRAM_SIZE];
7356 uint16_t _s[ISP2100_NVRAM_SIZE>>1];
7358 #define nvram_data _n._x
7359 #define nvram_words _n._s
7362 return (isp_read_nvram_2400(isp));
7363 } else if (IS_FC(isp)) {
7364 amt = ISP2100_NVRAM_SIZE;
7366 } else if (IS_ULTRA2(isp)) {
7367 amt = ISP1080_NVRAM_SIZE;
7370 amt = ISP_NVRAM_SIZE;
7374 for (i = 0; i < amt>>1; i++) {
7375 isp_rdnvram_word(isp, i, &nvram_words[i]);
7378 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
7379 nvram_data[2] != 'P') {
7380 if (isp->isp_bustype != ISP_BT_SBUS) {
7381 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
7382 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x",
7383 nvram_data[0], nvram_data[1], nvram_data[2]);
7389 for (csum = 0, i = 0; i < amt; i++) {
7390 csum += nvram_data[i];
7393 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
7398 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
7399 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
7400 ISP_NVRAM_VERSION(nvram_data));
7405 if (IS_ULTRA3(isp)) {
7406 isp_parse_nvram_12160(isp, 0, nvram_data);
7408 isp_parse_nvram_12160(isp, 1, nvram_data);
7409 } else if (IS_1080(isp)) {
7410 isp_parse_nvram_1080(isp, 0, nvram_data);
7411 } else if (IS_1280(isp) || IS_1240(isp)) {
7412 isp_parse_nvram_1080(isp, 0, nvram_data);
7413 isp_parse_nvram_1080(isp, 1, nvram_data);
7414 } else if (IS_SCSI(isp)) {
7415 isp_parse_nvram_1020(isp, nvram_data);
7417 isp_parse_nvram_2100(isp, nvram_data);
7427 isp_read_nvram_2400(ispsoftc_t *isp)
7429 uint8_t *nvram_data = FCPARAM(isp)->isp_scratch;
7431 uint32_t addr, csum, lwrds, *dptr;
7433 if (isp->isp_port) {
7434 addr = ISP2400_NVRAM_PORT1_ADDR;
7436 addr = ISP2400_NVRAM_PORT0_ADDR;
7439 dptr = (uint32_t *) nvram_data;
7440 for (lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
7441 isp_rd_2400_nvram(isp, addr++, dptr++);
7443 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
7444 nvram_data[2] != 'P') {
7445 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header (%x %x %x)",
7446 nvram_data[0], nvram_data[1], nvram_data[2]);
7450 dptr = (uint32_t *) nvram_data;
7451 for (csum = 0, lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
7453 ISP_IOXGET_32(isp, &dptr[lwrds], tmp);
7457 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
7461 isp_parse_nvram_2400(isp, nvram_data);
7467 isp_rdnvram_word(ispsoftc_t *isp, int wo, uint16_t *rp)
7470 uint16_t bit, rqst, junk;
7472 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
7474 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
7478 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
7479 if (IS_2312(isp) && isp->isp_port) {
7482 rqst = (ISP_NVRAM_READ << 8) | wo;
7484 } else if (IS_ULTRA2(isp)) {
7485 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
7486 rqst = (ISP_NVRAM_READ << 8) | wo;
7489 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
7490 rqst = (ISP_NVRAM_READ << 6) | wo;
7495 * Clock the word select request out...
7497 for (i = cbits; i >= 0; i--) {
7498 if ((rqst >> i) & 1) {
7499 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
7501 bit = BIU_NVRAM_SELECT;
7503 ISP_WRITE(isp, BIU_NVRAM, bit);
7505 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7506 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
7508 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7509 ISP_WRITE(isp, BIU_NVRAM, bit);
7511 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7514 * Now read the result back in (bits come back in MSB format).
7517 for (i = 0; i < 16; i++) {
7520 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
7522 rv = ISP_READ(isp, BIU_NVRAM);
7523 if (rv & BIU_NVRAM_DATAIN) {
7527 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
7529 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7531 ISP_WRITE(isp, BIU_NVRAM, 0);
7533 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7534 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
7538 isp_rd_2400_nvram(ispsoftc_t *isp, uint32_t addr, uint32_t *rp)
7541 const uint32_t base = 0x7ffe0000;
7544 ISP_WRITE(isp, BIU2400_FLASH_ADDR, base | addr);
7545 for (loops = 0; loops < 5000; loops++) {
7547 tmp = ISP_READ(isp, BIU2400_FLASH_ADDR);
7548 if ((tmp & (1U << 31)) != 0) {
7552 if (tmp & (1U << 31)) {
7553 *rp = ISP_READ(isp, BIU2400_FLASH_DATA);
7554 ISP_SWIZZLE_NVRAM_LONG(isp, rp);
7561 isp_parse_nvram_1020(ispsoftc_t *isp, uint8_t *nvram_data)
7563 sdparam *sdp = (sdparam *) isp->isp_param;
7566 sdp->isp_fifo_threshold =
7567 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
7568 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
7570 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
7571 sdp->isp_initiator_id =
7572 ISP_NVRAM_INITIATOR_ID(nvram_data);
7574 sdp->isp_bus_reset_delay =
7575 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
7577 sdp->isp_retry_count =
7578 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
7580 sdp->isp_retry_delay =
7581 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
7583 sdp->isp_async_data_setup =
7584 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
7586 if (isp->isp_type >= ISP_HA_SCSI_1040) {
7587 if (sdp->isp_async_data_setup < 9) {
7588 sdp->isp_async_data_setup = 9;
7591 if (sdp->isp_async_data_setup != 6) {
7592 sdp->isp_async_data_setup = 6;
7596 sdp->isp_req_ack_active_neg =
7597 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
7599 sdp->isp_data_line_active_neg =
7600 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
7602 sdp->isp_data_dma_burst_enabl =
7603 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
7605 sdp->isp_cmd_dma_burst_enable =
7606 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
7608 sdp->isp_tag_aging =
7609 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
7611 sdp->isp_selection_timeout =
7612 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
7614 sdp->isp_max_queue_depth =
7615 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
7617 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
7619 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
7620 0, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
7621 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
7622 sdp->isp_retry_delay, sdp->isp_async_data_setup);
7623 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
7624 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
7625 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
7626 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
7628 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7629 sdp->isp_devparam[tgt].dev_enable =
7630 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
7631 sdp->isp_devparam[tgt].exc_throttle =
7632 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
7633 sdp->isp_devparam[tgt].nvrm_offset =
7634 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
7635 sdp->isp_devparam[tgt].nvrm_period =
7636 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
7638 * We probably shouldn't lie about this, but it
7639 * it makes it much safer if we limit NVRAM values
7642 if (isp->isp_type < ISP_HA_SCSI_1040) {
7644 * If we're not ultra, we can't possibly
7645 * be a shorter period than this.
7647 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
7648 sdp->isp_devparam[tgt].nvrm_period = 0x19;
7650 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
7651 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
7654 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
7655 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
7658 sdp->isp_devparam[tgt].nvrm_flags = 0;
7659 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
7660 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
7661 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
7662 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
7663 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
7664 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
7665 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
7666 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
7667 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
7668 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
7669 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
7670 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
7671 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
7672 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
7673 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
7674 0, tgt, sdp->isp_devparam[tgt].nvrm_flags,
7675 sdp->isp_devparam[tgt].nvrm_offset,
7676 sdp->isp_devparam[tgt].nvrm_period);
7677 sdp->isp_devparam[tgt].goal_offset =
7678 sdp->isp_devparam[tgt].nvrm_offset;
7679 sdp->isp_devparam[tgt].goal_period =
7680 sdp->isp_devparam[tgt].nvrm_period;
7681 sdp->isp_devparam[tgt].goal_flags =
7682 sdp->isp_devparam[tgt].nvrm_flags;
7687 isp_parse_nvram_1080(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
7689 sdparam *sdp = (sdparam *) isp->isp_param;
7694 sdp->isp_fifo_threshold =
7695 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
7697 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
7698 sdp->isp_initiator_id =
7699 ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
7701 sdp->isp_bus_reset_delay =
7702 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
7704 sdp->isp_retry_count =
7705 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
7707 sdp->isp_retry_delay =
7708 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
7710 sdp->isp_async_data_setup =
7711 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
7713 sdp->isp_req_ack_active_neg =
7714 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
7716 sdp->isp_data_line_active_neg =
7717 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
7719 sdp->isp_data_dma_burst_enabl =
7720 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
7722 sdp->isp_cmd_dma_burst_enable =
7723 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
7725 sdp->isp_selection_timeout =
7726 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
7728 sdp->isp_max_queue_depth =
7729 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
7731 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
7732 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
7733 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
7734 sdp->isp_retry_delay, sdp->isp_async_data_setup);
7735 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
7736 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
7737 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
7738 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
7741 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7742 sdp->isp_devparam[tgt].dev_enable =
7743 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
7744 sdp->isp_devparam[tgt].exc_throttle =
7745 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
7746 sdp->isp_devparam[tgt].nvrm_offset =
7747 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
7748 sdp->isp_devparam[tgt].nvrm_period =
7749 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
7750 sdp->isp_devparam[tgt].nvrm_flags = 0;
7751 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
7752 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
7753 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
7754 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
7755 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
7756 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
7757 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
7758 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
7759 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
7760 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
7761 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
7762 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
7763 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
7764 sdp->isp_devparam[tgt].actv_flags = 0;
7765 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
7766 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
7767 sdp->isp_devparam[tgt].nvrm_offset,
7768 sdp->isp_devparam[tgt].nvrm_period);
7769 sdp->isp_devparam[tgt].goal_offset =
7770 sdp->isp_devparam[tgt].nvrm_offset;
7771 sdp->isp_devparam[tgt].goal_period =
7772 sdp->isp_devparam[tgt].nvrm_period;
7773 sdp->isp_devparam[tgt].goal_flags =
7774 sdp->isp_devparam[tgt].nvrm_flags;
7779 isp_parse_nvram_12160(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
7781 sdparam *sdp = (sdparam *) isp->isp_param;
7786 sdp->isp_fifo_threshold =
7787 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
7789 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
7790 sdp->isp_initiator_id =
7791 ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
7793 sdp->isp_bus_reset_delay =
7794 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
7796 sdp->isp_retry_count =
7797 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
7799 sdp->isp_retry_delay =
7800 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
7802 sdp->isp_async_data_setup =
7803 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
7805 sdp->isp_req_ack_active_neg =
7806 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
7808 sdp->isp_data_line_active_neg =
7809 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
7811 sdp->isp_data_dma_burst_enabl =
7812 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
7814 sdp->isp_cmd_dma_burst_enable =
7815 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
7817 sdp->isp_selection_timeout =
7818 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
7820 sdp->isp_max_queue_depth =
7821 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
7823 isp_prt(isp, ISP_LOGDEBUG0, sc0, sc4,
7824 bus, sdp->isp_fifo_threshold, sdp->isp_initiator_id,
7825 sdp->isp_bus_reset_delay, sdp->isp_retry_count,
7826 sdp->isp_retry_delay, sdp->isp_async_data_setup);
7827 isp_prt(isp, ISP_LOGDEBUG0, sc1, sc4,
7828 sdp->isp_req_ack_active_neg, sdp->isp_data_line_active_neg,
7829 sdp->isp_data_dma_burst_enabl, sdp->isp_cmd_dma_burst_enable,
7830 sdp->isp_selection_timeout, sdp->isp_max_queue_depth);
7832 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7833 sdp->isp_devparam[tgt].dev_enable =
7834 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
7835 sdp->isp_devparam[tgt].exc_throttle =
7836 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
7837 sdp->isp_devparam[tgt].nvrm_offset =
7838 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
7839 sdp->isp_devparam[tgt].nvrm_period =
7840 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
7841 sdp->isp_devparam[tgt].nvrm_flags = 0;
7842 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
7843 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
7844 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
7845 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
7846 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
7847 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
7848 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
7849 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
7850 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
7851 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
7852 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
7853 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
7854 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
7855 sdp->isp_devparam[tgt].actv_flags = 0;
7856 isp_prt(isp, ISP_LOGDEBUG0, sc2, sc4,
7857 bus, tgt, sdp->isp_devparam[tgt].nvrm_flags,
7858 sdp->isp_devparam[tgt].nvrm_offset,
7859 sdp->isp_devparam[tgt].nvrm_period);
7860 sdp->isp_devparam[tgt].goal_offset =
7861 sdp->isp_devparam[tgt].nvrm_offset;
7862 sdp->isp_devparam[tgt].goal_period =
7863 sdp->isp_devparam[tgt].nvrm_period;
7864 sdp->isp_devparam[tgt].goal_flags =
7865 sdp->isp_devparam[tgt].nvrm_flags;
7870 isp_fix_nvram_wwns(ispsoftc_t *isp)
7872 fcparam *fcp = FCPARAM(isp);
7875 * Make sure we have both Node and Port as non-zero values.
7877 if (fcp->isp_wwnn_nvram != 0 && fcp->isp_wwpn_nvram == 0) {
7878 fcp->isp_wwpn_nvram = fcp->isp_wwnn_nvram;
7879 } else if (fcp->isp_wwnn_nvram == 0 && fcp->isp_wwpn_nvram != 0) {
7880 fcp->isp_wwnn_nvram = fcp->isp_wwpn_nvram;
7884 * Make the Node and Port values sane if they're NAA == 2.
7885 * This means to clear bits 48..56 for the Node WWN and
7886 * make sure that there's some non-zero value in 48..56
7889 if (fcp->isp_wwnn_nvram && fcp->isp_wwpn_nvram) {
7890 if ((fcp->isp_wwnn_nvram & (((uint64_t) 0xfff) << 48)) != 0 &&
7891 (fcp->isp_wwnn_nvram >> 60) == 2) {
7892 fcp->isp_wwnn_nvram &= ~((uint64_t) 0xfff << 48);
7894 if ((fcp->isp_wwpn_nvram & (((uint64_t) 0xfff) << 48)) == 0 &&
7895 (fcp->isp_wwpn_nvram >> 60) == 2) {
7896 fcp->isp_wwpn_nvram |= ((uint64_t) 1 << 56);
7902 isp_parse_nvram_2100(ispsoftc_t *isp, uint8_t *nvram_data)
7904 fcparam *fcp = FCPARAM(isp);
7908 * There is NVRAM storage for both Port and Node entities-
7909 * but the Node entity appears to be unused on all the cards
7910 * I can find. However, we should account for this being set
7911 * at some point in the future.
7913 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
7914 * bits 48..60. In the case of the 2202, it appears that they do
7915 * use bit 48 to distinguish between the two instances on the card.
7916 * The 2204, which I've never seen, *probably* extends this method.
7918 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
7920 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
7921 (uint32_t) (wwn >> 32), (uint32_t) (wwn & 0xffffffff));
7922 if ((wwn >> 60) == 0) {
7923 wwn |= (((uint64_t) 2)<< 60);
7926 fcp->isp_wwpn_nvram = wwn;
7927 if (IS_2200(isp) || IS_23XX(isp)) {
7928 wwn = ISP2100_NVRAM_NODE_NAME(nvram_data);
7930 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
7931 (uint32_t) (wwn >> 32),
7932 (uint32_t) (wwn & 0xffffffff));
7933 if ((wwn >> 60) == 0) {
7934 wwn |= (((uint64_t) 2)<< 60);
7938 wwn &= ~((uint64_t) 0xfff << 48);
7940 fcp->isp_wwnn_nvram = wwn;
7942 isp_fix_nvram_wwns(isp);
7944 fcp->isp_maxalloc = ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
7945 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
7946 fcp->isp_maxfrmlen = ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
7948 fcp->isp_retry_delay = ISP2100_NVRAM_RETRY_DELAY(nvram_data);
7949 fcp->isp_retry_count = ISP2100_NVRAM_RETRY_COUNT(nvram_data);
7950 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
7951 fcp->isp_loopid = ISP2100_NVRAM_HARDLOOPID(nvram_data);
7953 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
7954 fcp->isp_execthrottle =
7955 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
7957 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
7958 isp_prt(isp, ISP_LOGDEBUG0,
7959 "NVRAM 0x%08x%08x 0x%08x%08x maxalloc %d maxframelen %d",
7960 (uint32_t) (fcp->isp_wwnn_nvram >> 32), (uint32_t) fcp->isp_wwnn_nvram,
7961 (uint32_t) (fcp->isp_wwpn_nvram >> 32), (uint32_t) fcp->isp_wwpn_nvram,
7962 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data),
7963 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data));
7964 isp_prt(isp, ISP_LOGDEBUG0,
7965 "execthrottle %d fwoptions 0x%x hardloop %d tov %d",
7966 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
7967 ISP2100_NVRAM_OPTIONS(nvram_data),
7968 ISP2100_NVRAM_HARDLOOPID(nvram_data),
7969 ISP2100_NVRAM_TOV(nvram_data));
7970 fcp->isp_xfwoptions = ISP2100_XFW_OPTIONS(nvram_data);
7971 fcp->isp_zfwoptions = ISP2100_ZFW_OPTIONS(nvram_data);
7972 isp_prt(isp, ISP_LOGDEBUG0,
7973 "xfwoptions 0x%x zfw options 0x%x",
7974 ISP2100_XFW_OPTIONS(nvram_data), ISP2100_ZFW_OPTIONS(nvram_data));
7978 isp_parse_nvram_2400(ispsoftc_t *isp, uint8_t *nvram_data)
7980 fcparam *fcp = FCPARAM(isp);
7983 isp_prt(isp, ISP_LOGDEBUG0,
7984 "NVRAM 0x%08x%08x 0x%08x%08x exchg_cnt %d maxframelen %d",
7985 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data) >> 32),
7986 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data)),
7987 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data) >> 32),
7988 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data)),
7989 ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data),
7990 ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data));
7991 isp_prt(isp, ISP_LOGDEBUG0,
7992 "NVRAM execthr %d loopid %d fwopt1 0x%x fwopt2 0x%x fwopt3 0x%x",
7993 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data),
7994 ISP2400_NVRAM_HARDLOOPID(nvram_data),
7995 ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data),
7996 ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data),
7997 ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data));
7999 wwn = ISP2400_NVRAM_PORT_NAME(nvram_data);
8001 if ((wwn >> 60) != 2 && (wwn >> 60) != 5) {
8005 fcp->isp_wwpn_nvram = wwn;
8007 wwn = ISP2400_NVRAM_NODE_NAME(nvram_data);
8009 if ((wwn >> 60) != 2 && (wwn >> 60) != 5) {
8013 fcp->isp_wwnn_nvram = wwn;
8015 isp_fix_nvram_wwns(isp);
8017 if (ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data)) {
8018 fcp->isp_maxalloc = ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data);
8020 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
8021 fcp->isp_maxfrmlen = ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data);
8023 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
8024 fcp->isp_loopid = ISP2400_NVRAM_HARDLOOPID(nvram_data);
8026 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
8027 fcp->isp_execthrottle =
8028 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data);
8030 fcp->isp_fwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data);
8031 fcp->isp_xfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data);
8032 fcp->isp_zfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data);
8035 #ifdef ISP_FW_CRASH_DUMP
8036 static void isp2200_fw_dump(ispsoftc_t *);
8037 static void isp2300_fw_dump(ispsoftc_t *);
8040 isp2200_fw_dump(ispsoftc_t *isp)
8046 MEMZERO(&mbs, sizeof (mbs));
8047 ptr = FCPARAM(isp)->isp_dump_data;
8049 isp_prt(isp, ISP_LOGERR,
8050 "No place to dump RISC registers and SRAM");
8054 isp_prt(isp, ISP_LOGERR,
8055 "dump area for RISC registers and SRAM already used");
8058 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
8059 for (i = 0; i < 100; i++) {
8061 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
8065 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
8069 for (i = 0; i < 8; i++) {
8070 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
8076 for (i = 0; i < 8; i++) {
8077 *ptr++ = ISP_READ(isp, MBOX_BLOCK + (i << 1));
8083 for (i = 0; i < 48; i++) {
8084 *ptr++ = ISP_READ(isp, DMA_BLOCK + 0x20 + (i << 1));
8088 * RISC H/W Registers
8090 ISP_WRITE(isp, BIU2100_CSR, 0);
8091 for (i = 0; i < 16; i++) {
8092 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
8098 for (j = 0; j < 8; j++) {
8099 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 8));
8100 for (i = 0; i < 16; i++) {
8102 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
8107 * Frame Buffer Hardware Registers
8109 ISP_WRITE(isp, BIU2100_CSR, 0x10);
8110 for (i = 0; i < 16; i++) {
8111 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
8115 * Fibre Protocol Module 0 Hardware Registers
8117 ISP_WRITE(isp, BIU2100_CSR, 0x20);
8118 for (i = 0; i < 64; i++) {
8119 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
8123 * Fibre Protocol Module 1 Hardware Registers
8125 ISP_WRITE(isp, BIU2100_CSR, 0x30);
8126 for (i = 0; i < 64; i++) {
8127 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
8130 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
8133 isp_prt(isp, ISP_LOGALL,
8134 "isp_fw_dump: RISC registers dumped successfully");
8135 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
8136 for (i = 0; i < 100; i++) {
8138 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
8142 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
8143 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
8146 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
8147 for (i = 0; i < 100; i++) {
8149 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
8153 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
8154 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause After Reset");
8157 ISP_WRITE(isp, RISC_EMB, 0xf2);
8158 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
8159 for (i = 0; i < 100; i++) {
8161 if ((ISP_READ(isp, HCCR) & HCCR_PAUSE) == 0) {
8165 ISP_ENABLE_INTS(isp);
8166 mbs.param[0] = MBOX_READ_RAM_WORD;
8167 mbs.param[1] = 0x1000;
8168 isp->isp_mbxworkp = (void *) ptr;
8169 isp->isp_mbxwrk0 = 0xefff; /* continuation count */
8170 isp->isp_mbxwrk1 = 0x1001; /* next SRAM address */
8171 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
8172 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
8173 isp_prt(isp, ISP_LOGWARN,
8174 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
8177 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
8178 *ptr++ = isp->isp_mboxtmp[2];
8179 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
8180 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
8181 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
8185 isp2300_fw_dump(ispsoftc_t *isp)
8191 MEMZERO(&mbs, sizeof (mbs));
8192 ptr = FCPARAM(isp)->isp_dump_data;
8194 isp_prt(isp, ISP_LOGERR,
8195 "No place to dump RISC registers and SRAM");
8199 isp_prt(isp, ISP_LOGERR,
8200 "dump area for RISC registers and SRAM already used");
8203 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
8204 for (i = 0; i < 100; i++) {
8206 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
8210 if (ISP_READ(isp, HCCR) & HCCR_PAUSE) {
8214 for (i = 0; i < 8; i++) {
8215 *ptr++ = ISP_READ(isp, BIU_BLOCK + (i << 1));
8219 * ReqQ-RspQ-Risc2Host Status registers
8221 for (i = 0; i < 8; i++) {
8222 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x10 + (i << 1));
8228 for (i = 0; i < 32; i++) {
8230 ISP_READ(isp, PCI_MBOX_REGS2300_OFF + (i << 1));
8234 * Auto Request Response DMA registers
8236 ISP_WRITE(isp, BIU2100_CSR, 0x40);
8237 for (i = 0; i < 32; i++) {
8238 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
8244 ISP_WRITE(isp, BIU2100_CSR, 0x50);
8245 for (i = 0; i < 48; i++) {
8246 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
8250 * RISC hardware registers
8252 ISP_WRITE(isp, BIU2100_CSR, 0);
8253 for (i = 0; i < 16; i++) {
8254 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0xA0 + (i << 1));
8258 * RISC GP? registers
8260 for (j = 0; j < 8; j++) {
8261 ISP_WRITE(isp, BIU_BLOCK + 0xA4, 0x2000 + (j << 9));
8262 for (i = 0; i < 16; i++) {
8264 ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
8269 * frame buffer hardware registers
8271 ISP_WRITE(isp, BIU2100_CSR, 0x10);
8272 for (i = 0; i < 64; i++) {
8273 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
8277 * FPM B0 hardware registers
8279 ISP_WRITE(isp, BIU2100_CSR, 0x20);
8280 for (i = 0; i < 64; i++) {
8281 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
8285 * FPM B1 hardware registers
8287 ISP_WRITE(isp, BIU2100_CSR, 0x30);
8288 for (i = 0; i < 64; i++) {
8289 *ptr++ = ISP_READ(isp, BIU_BLOCK + 0x80 + (i << 1));
8292 isp_prt(isp, ISP_LOGERR, "RISC Would Not Pause");
8295 isp_prt(isp, ISP_LOGALL,
8296 "isp_fw_dump: RISC registers dumped successfully");
8297 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
8298 for (i = 0; i < 100; i++) {
8300 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
8304 if (ISP_READ(isp, OUTMAILBOX0) != 0) {
8305 isp_prt(isp, ISP_LOGERR, "Board Would Not Reset");
8308 ISP_ENABLE_INTS(isp);
8309 MEMZERO(&mbs, sizeof (mbs));
8310 mbs.param[0] = MBOX_READ_RAM_WORD;
8311 mbs.param[1] = 0x800;
8312 isp->isp_mbxworkp = (void *) ptr;
8313 isp->isp_mbxwrk0 = 0xf7ff; /* continuation count */
8314 isp->isp_mbxwrk1 = 0x801; /* next SRAM address */
8315 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
8316 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
8317 isp_prt(isp, ISP_LOGWARN,
8318 "RAM DUMP FAILED @ WORD %x", isp->isp_mbxwrk1);
8321 ptr = isp->isp_mbxworkp; /* finish fetch of final word */
8322 *ptr++ = isp->isp_mboxtmp[2];
8323 MEMZERO(&mbs, sizeof (mbs));
8324 mbs.param[0] = MBOX_READ_RAM_WORD_EXTENDED;
8326 isp->isp_mbxworkp = (void *) ptr;
8327 isp->isp_mbxwrk0 = 0xffff; /* continuation count */
8328 isp->isp_mbxwrk1 = 0x1; /* next SRAM address */
8329 isp->isp_mbxwrk8 = 0x1;
8330 isp_control(isp, ISPCTL_RUN_MBOXCMD, &mbs);
8331 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
8332 isp_prt(isp, ISP_LOGWARN,
8333 "RAM DUMP FAILED @ WORD %x", 0x10000 + isp->isp_mbxwrk1);
8336 ptr = isp->isp_mbxworkp; /* finish final word */
8337 *ptr++ = mbs.param[2];
8338 isp_prt(isp, ISP_LOGALL, "isp_fw_dump: SRAM dumped successfully");
8339 FCPARAM(isp)->isp_dump_data[0] = isp->isp_type; /* now used */
8340 (void) isp_async(isp, ISPASYNC_FW_DUMPED, 0);
8344 isp_fw_dump(ispsoftc_t *isp)
8347 isp2200_fw_dump(isp);
8348 else if (IS_23XX(isp))
8349 isp2300_fw_dump(isp);
8350 else if (IS_24XX(isp))
8351 isp_prt(isp, ISP_LOGERR, "24XX dump method undefined");