2 * Copyright (c) 1997-2009 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
30 * Machine and OS Independent (well, as best as possible)
31 * code for the Qlogic ISP SCSI and FC-SCSI adapters.
35 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
36 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
37 * ideas dredged from the Solaris driver.
41 * Include header file appropriate for platform we're building on.
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD$");
46 #include <dev/ic/isp_netbsd.h>
49 #include <sys/cdefs.h>
50 __FBSDID("$FreeBSD$");
51 #include <dev/isp/isp_freebsd.h>
54 #include <dev/ic/isp_openbsd.h>
57 #include "isp_linux.h"
60 #include "isp_solaris.h"
66 #define MBOX_DELAY_COUNT 1000000 / 100
71 static const char notresp[] = "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
72 static const char bun[] = "bad underrun (count %d, resid %d, status %s)";
73 static const char lipd[] = "Chan %d LIP destroyed %d active commands";
74 static const char sacq[] = "unable to acquire scratch area";
76 static const uint8_t alpa_map[] = {
77 0xef, 0xe8, 0xe4, 0xe2, 0xe1, 0xe0, 0xdc, 0xda,
78 0xd9, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xce,
79 0xcd, 0xcc, 0xcb, 0xca, 0xc9, 0xc7, 0xc6, 0xc5,
80 0xc3, 0xbc, 0xba, 0xb9, 0xb6, 0xb5, 0xb4, 0xb3,
81 0xb2, 0xb1, 0xae, 0xad, 0xac, 0xab, 0xaa, 0xa9,
82 0xa7, 0xa6, 0xa5, 0xa3, 0x9f, 0x9e, 0x9d, 0x9b,
83 0x98, 0x97, 0x90, 0x8f, 0x88, 0x84, 0x82, 0x81,
84 0x80, 0x7c, 0x7a, 0x79, 0x76, 0x75, 0x74, 0x73,
85 0x72, 0x71, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x69,
86 0x67, 0x66, 0x65, 0x63, 0x5c, 0x5a, 0x59, 0x56,
87 0x55, 0x54, 0x53, 0x52, 0x51, 0x4e, 0x4d, 0x4c,
88 0x4b, 0x4a, 0x49, 0x47, 0x46, 0x45, 0x43, 0x3c,
89 0x3a, 0x39, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31,
90 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x27, 0x26,
91 0x25, 0x23, 0x1f, 0x1e, 0x1d, 0x1b, 0x18, 0x17,
92 0x10, 0x0f, 0x08, 0x04, 0x02, 0x01, 0x00
96 * Local function prototypes.
98 static int isp_parse_async(ispsoftc_t *, uint16_t);
99 static int isp_parse_async_fc(ispsoftc_t *, uint16_t);
100 static int isp_handle_other_response(ispsoftc_t *, int, isphdr_t *, uint32_t *);
101 static void isp_parse_status(ispsoftc_t *, ispstatusreq_t *, XS_T *, long *); static void
102 isp_parse_status_24xx(ispsoftc_t *, isp24xx_statusreq_t *, XS_T *, long *);
103 static void isp_fastpost_complete(ispsoftc_t *, uint32_t);
104 static int isp_mbox_continue(ispsoftc_t *);
105 static void isp_scsi_init(ispsoftc_t *);
106 static void isp_scsi_channel_init(ispsoftc_t *, int);
107 static void isp_fibre_init(ispsoftc_t *);
108 static void isp_fibre_init_2400(ispsoftc_t *);
109 static void isp_clear_portdb(ispsoftc_t *, int);
110 static void isp_mark_portdb(ispsoftc_t *, int);
111 static int isp_plogx(ispsoftc_t *, int, uint16_t, uint32_t, int);
112 static int isp_port_login(ispsoftc_t *, uint16_t, uint32_t);
113 static int isp_port_logout(ispsoftc_t *, uint16_t, uint32_t);
114 static int isp_getpdb(ispsoftc_t *, int, uint16_t, isp_pdb_t *);
115 static int isp_gethandles(ispsoftc_t *, int, uint16_t *, int *, int);
116 static void isp_dump_chip_portdb(ispsoftc_t *, int);
117 static uint64_t isp_get_wwn(ispsoftc_t *, int, int, int);
118 static int isp_fclink_test(ispsoftc_t *, int, int);
119 static int isp_pdb_sync(ispsoftc_t *, int);
120 static int isp_scan_loop(ispsoftc_t *, int);
121 static int isp_gid_ft_sns(ispsoftc_t *, int);
122 static int isp_gid_ft_ct_passthru(ispsoftc_t *, int);
123 static int isp_scan_fabric(ispsoftc_t *, int);
124 static int isp_login_device(ispsoftc_t *, int, uint32_t, isp_pdb_t *, uint16_t *);
125 static int isp_send_change_request(ispsoftc_t *, int);
126 static int isp_register_fc4_type(ispsoftc_t *, int);
127 static int isp_register_fc4_type_24xx(ispsoftc_t *, int);
128 static int isp_register_fc4_features_24xx(ispsoftc_t *, int);
129 static int isp_register_port_name_24xx(ispsoftc_t *, int);
130 static int isp_register_node_name_24xx(ispsoftc_t *, int);
131 static uint16_t isp_next_handle(ispsoftc_t *, uint16_t *);
132 static int isp_fw_state(ispsoftc_t *, int);
133 static void isp_mboxcmd_qnw(ispsoftc_t *, mbreg_t *, int);
134 static void isp_mboxcmd(ispsoftc_t *, mbreg_t *);
136 static void isp_spi_update(ispsoftc_t *, int);
137 static void isp_setdfltsdparm(ispsoftc_t *);
138 static void isp_setdfltfcparm(ispsoftc_t *, int);
139 static int isp_read_nvram(ispsoftc_t *, int);
140 static int isp_read_nvram_2400(ispsoftc_t *, uint8_t *);
141 static void isp_rdnvram_word(ispsoftc_t *, int, uint16_t *);
142 static void isp_rd_2400_nvram(ispsoftc_t *, uint32_t, uint32_t *);
143 static void isp_parse_nvram_1020(ispsoftc_t *, uint8_t *);
144 static void isp_parse_nvram_1080(ispsoftc_t *, int, uint8_t *);
145 static void isp_parse_nvram_12160(ispsoftc_t *, int, uint8_t *);
146 static void isp_parse_nvram_2100(ispsoftc_t *, uint8_t *);
147 static void isp_parse_nvram_2400(ispsoftc_t *, uint8_t *);
150 isp_change_fw_state(ispsoftc_t *isp, int chan, int state)
152 fcparam *fcp = FCPARAM(isp, chan);
154 if (fcp->isp_fwstate == state)
156 isp_prt(isp, ISP_LOGCONFIG|ISP_LOG_SANCFG,
157 "Chan %d Firmware state <%s->%s>", chan,
158 isp_fc_fw_statename(fcp->isp_fwstate), isp_fc_fw_statename(state));
159 fcp->isp_fwstate = state;
165 * Hit the chip over the head, download new f/w if available and set it running.
167 * Locking done elsewhere.
171 isp_reset(ispsoftc_t *isp, int do_load_defaults)
176 uint32_t code_org, val;
177 int loops, i, dodnld = 1;
178 const char *btype = "????";
179 static const char dcrc[] = "Downloaded RISC Code Checksum Failure";
181 isp->isp_state = ISP_NILSTATE;
184 ISP_DISABLE_INTS(isp);
189 * Basic types (SCSI, FibreChannel and PCI or SBus)
190 * have been set in the MD code. We figure out more
191 * here. Possibly more refined types based upon PCI
192 * identification. Chip revision has been gathered.
194 * After we've fired this chip up, zero out the conf1 register
195 * for SCSI adapters and do other settings for the 2100.
198 ISP_DISABLE_INTS(isp);
201 * Pick an initial maxcmds value which will be used
202 * to allocate xflist pointer space. It may be changed
203 * later by the firmware.
206 isp->isp_maxcmds = 4096;
207 } else if (IS_2322(isp)) {
208 isp->isp_maxcmds = 2048;
209 } else if (IS_23XX(isp) || IS_2200(isp)) {
210 isp->isp_maxcmds = 1024;
212 isp->isp_maxcmds = 512;
216 * Set up DMA for the request and response queues.
218 * We do this now so we can use the request queue
219 * for dma to load firmware from.
221 if (ISP_MBOXDMASETUP(isp) != 0) {
222 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
227 * Set up default request/response queue in-pointer/out-pointer
231 isp->isp_rqstinrp = BIU2400_REQINP;
232 isp->isp_rqstoutrp = BIU2400_REQOUTP;
233 isp->isp_respinrp = BIU2400_RSPINP;
234 isp->isp_respoutrp = BIU2400_RSPOUTP;
235 } else if (IS_23XX(isp)) {
236 isp->isp_rqstinrp = BIU_REQINP;
237 isp->isp_rqstoutrp = BIU_REQOUTP;
238 isp->isp_respinrp = BIU_RSPINP;
239 isp->isp_respoutrp = BIU_RSPOUTP;
241 isp->isp_rqstinrp = INMAILBOX4;
242 isp->isp_rqstoutrp = OUTMAILBOX4;
243 isp->isp_respinrp = OUTMAILBOX5;
244 isp->isp_respoutrp = INMAILBOX5;
248 * Put the board into PAUSE mode (so we can read the SXP registers
249 * or write FPM/FBM registers).
252 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_HOST_INT);
253 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
254 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_PAUSE);
256 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
260 switch (isp->isp_type) {
291 * While we're paused, reset the FPM module and FBM
294 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
295 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
296 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
297 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
298 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
300 } else if (IS_1240(isp)) {
305 sdp = SDPARAM(isp, 0);
306 sdp->isp_ultramode = 1;
307 sdp = SDPARAM(isp, 1);
308 sdp->isp_ultramode = 1;
310 * XXX: Should probably do some bus sensing.
312 } else if (IS_ULTRA3(isp)) {
313 sdparam *sdp = isp->isp_param;
315 isp->isp_clock = 100;
319 else if (IS_12160(isp))
323 sdp->isp_lvdmode = 1;
325 if (IS_DUALBUS(isp)) {
327 sdp->isp_lvdmode = 1;
329 } else if (IS_ULTRA2(isp)) {
330 static const char m[] = "bus %d is in %s Mode";
332 sdparam *sdp = SDPARAM(isp, 0);
334 isp->isp_clock = 100;
338 else if (IS_1080(isp))
343 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
345 case ISP1080_LVD_MODE:
346 sdp->isp_lvdmode = 1;
347 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
349 case ISP1080_HVD_MODE:
350 sdp->isp_diffmode = 1;
351 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
353 case ISP1080_SE_MODE:
354 sdp->isp_ultramode = 1;
355 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
358 isp_prt(isp, ISP_LOGERR,
359 "unknown mode on bus %d (0x%x)", 0, l);
363 if (IS_DUALBUS(isp)) {
364 sdp = SDPARAM(isp, 1);
365 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
366 l &= ISP1080_MODE_MASK;
368 case ISP1080_LVD_MODE:
369 sdp->isp_lvdmode = 1;
370 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
372 case ISP1080_HVD_MODE:
373 sdp->isp_diffmode = 1;
374 isp_prt(isp, ISP_LOGCONFIG,
375 m, 1, "Differential");
377 case ISP1080_SE_MODE:
378 sdp->isp_ultramode = 1;
379 isp_prt(isp, ISP_LOGCONFIG,
380 m, 1, "Single-Ended");
383 isp_prt(isp, ISP_LOGERR,
384 "unknown mode on bus %d (0x%x)", 1, l);
389 sdparam *sdp = SDPARAM(isp, 0);
390 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
393 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
397 isp->isp_type = ISP_HA_SCSI_1020;
402 * Some 1020A chips are Ultra Capable, but don't
403 * run the clock rate up for that unless told to
404 * do so by the Ultra Capable bits being set.
407 isp->isp_type = ISP_HA_SCSI_1020A;
412 isp->isp_type = ISP_HA_SCSI_1040;
417 isp->isp_type = ISP_HA_SCSI_1040A;
422 isp->isp_type = ISP_HA_SCSI_1040B;
427 isp->isp_type = ISP_HA_SCSI_1040C;
432 * Now, while we're at it, gather info about ultra
433 * and/or differential mode.
435 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
436 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
437 sdp->isp_diffmode = 1;
439 sdp->isp_diffmode = 0;
441 i = ISP_READ(isp, RISC_PSR);
442 if (isp->isp_bustype == ISP_BT_SBUS) {
443 i &= RISC_PSR_SBUS_ULTRA;
445 i &= RISC_PSR_PCI_ULTRA;
448 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
449 sdp->isp_ultramode = 1;
451 * If we're in Ultra Mode, we have to be 60MHz clock-
452 * even for the SBus version.
456 sdp->isp_ultramode = 0;
458 * Clock is known. Gronk.
463 * Machine dependent clock (if set) overrides
464 * our generic determinations.
466 if (isp->isp_mdvec->dv_clock) {
467 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
468 isp->isp_clock = isp->isp_mdvec->dv_clock;
475 * Clear instrumentation
477 isp->isp_intcnt = isp->isp_intbogus = 0;
480 * Do MD specific pre initialization
485 * Hit the chip over the head with hammer,
486 * and give it a chance to recover.
490 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
497 * Clear data && control DMA engines.
499 ISP_WRITE(isp, CDMA_CONTROL, DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
500 ISP_WRITE(isp, DDMA_CONTROL, DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
503 } else if (IS_24XX(isp)) {
505 * Stop DMA and wait for it to stop.
507 ISP_WRITE(isp, BIU2400_CSR, BIU2400_DMA_STOP|(3 << 4));
508 for (val = loops = 0; loops < 30000; loops++) {
510 val = ISP_READ(isp, BIU2400_CSR);
511 if ((val & BIU2400_DMA_ACTIVE) == 0) {
515 if (val & BIU2400_DMA_ACTIVE) {
517 isp_prt(isp, ISP_LOGERR, "DMA Failed to Stop on Reset");
521 * Hold it in SOFT_RESET and STOP state for 100us.
523 ISP_WRITE(isp, BIU2400_CSR, BIU2400_SOFT_RESET|BIU2400_DMA_STOP|(3 << 4));
525 for (loops = 0; loops < 10000; loops++) {
527 val = ISP_READ(isp, OUTMAILBOX0);
529 for (val = loops = 0; loops < 500000; loops ++) {
530 val = ISP_READ(isp, BIU2400_CSR);
531 if ((val & BIU2400_SOFT_RESET) == 0) {
535 if (val & BIU2400_SOFT_RESET) {
537 isp_prt(isp, ISP_LOGERR, "Failed to come out of reset");
541 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
548 * Clear data && control DMA engines.
550 ISP_WRITE(isp, CDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
551 ISP_WRITE(isp, TDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
552 ISP_WRITE(isp, RDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
556 * Wait for ISP to be ready to go...
558 loops = MBOX_DELAY_COUNT;
561 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET)) {
564 } else if (IS_24XX(isp)) {
565 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
569 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
574 ISP_DUMPREGS(isp, "chip reset timed out");
581 * After we've fired this chip up, zero out the conf1 register
582 * for SCSI adapters and other settings for the 2100.
586 ISP_WRITE(isp, BIU_CONF1, 0);
587 } else if (!IS_24XX(isp)) {
588 ISP_WRITE(isp, BIU2100_CSR, 0);
592 * Reset RISC Processor
595 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RESET);
596 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RELEASE);
597 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RESET);
599 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
601 ISP_WRITE(isp, BIU_SEMA, 0);
605 * Post-RISC Reset stuff.
608 for (val = loops = 0; loops < 5000000; loops++) {
610 val = ISP_READ(isp, OUTMAILBOX0);
617 isp_prt(isp, ISP_LOGERR, "reset didn't clear");
620 } else if (IS_SCSI(isp)) {
621 uint16_t tmp = isp->isp_mdvec->dv_conf1;
623 * Busted FIFO. Turn off all but burst enables.
625 if (isp->isp_type == ISP_HA_SCSI_1040A) {
626 tmp &= BIU_BURST_ENABLE;
628 ISP_SETBITS(isp, BIU_CONF1, tmp);
629 if (tmp & BIU_BURST_ENABLE) {
630 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
631 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
633 if (SDPARAM(isp, 0)->isp_ptisp) {
634 if (SDPARAM(isp, 0)->isp_ultramode) {
635 while (ISP_READ(isp, RISC_MTR) != 0x1313) {
636 ISP_WRITE(isp, RISC_MTR, 0x1313);
637 ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
640 ISP_WRITE(isp, RISC_MTR, 0x1212);
643 * PTI specific register
645 ISP_WRITE(isp, RISC_EMB, DUAL_BANK);
647 ISP_WRITE(isp, RISC_MTR, 0x1212);
649 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
651 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
652 if (IS_2200(isp) || IS_23XX(isp)) {
653 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
655 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
658 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
659 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
660 ISP_WRITE(isp, isp->isp_respinrp, 0);
661 ISP_WRITE(isp, isp->isp_respoutrp, 0);
664 ISP_WRITE(isp, BIU2400_PRI_REQINP, 0);
665 ISP_WRITE(isp, BIU2400_PRI_REQOUTP, 0);
667 ISP_WRITE(isp, BIU2400_ATIO_RSPINP, 0);
668 ISP_WRITE(isp, BIU2400_ATIO_RSPOUTP, 0);
672 * Do MD specific post initialization
677 * Wait for everything to finish firing up.
679 * Avoid doing this on early 2312s because you can generate a PCI
680 * parity error (chip breakage).
682 if (IS_2312(isp) && isp->isp_revision < 2) {
685 loops = MBOX_DELAY_COUNT;
686 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
690 isp_prt(isp, ISP_LOGERR, "MBOX_BUSY never cleared on reset");
697 * Up until this point we've done everything by just reading or
698 * setting registers. From this point on we rely on at least *some*
699 * kind of firmware running in the card.
703 * Do some sanity checking by running a NOP command.
704 * If it succeeds, the ROM firmware is now running.
706 MBSINIT(&mbs, MBOX_NO_OP, MBLOGALL, 0);
707 isp_mboxcmd(isp, &mbs);
708 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
709 isp_prt(isp, ISP_LOGERR, "NOP command failed (%x)", mbs.param[0]);
715 * Do some operational tests
718 if (IS_SCSI(isp) || IS_24XX(isp)) {
719 static const uint16_t patterns[MAX_MAILBOX] = {
720 0x0000, 0xdead, 0xbeef, 0xffff,
721 0xa5a5, 0x5a5a, 0x7f7f, 0x7ff7,
722 0x3421, 0xabcd, 0xdcba, 0xfeef,
723 0xbead, 0xdebe, 0x2222, 0x3333,
724 0x5555, 0x6666, 0x7777, 0xaaaa,
725 0xffff, 0xdddd, 0x9999, 0x1fbc,
726 0x6666, 0x6677, 0x1122, 0x33ff,
727 0x0000, 0x0001, 0x1000, 0x1010,
729 int nmbox = ISP_NMBOX(isp);
732 MBSINIT(&mbs, MBOX_MAILBOX_REG_TEST, MBLOGALL, 0);
733 for (i = 1; i < nmbox; i++) {
734 mbs.param[i] = patterns[i];
736 isp_mboxcmd(isp, &mbs);
737 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
741 for (i = 1; i < nmbox; i++) {
742 if (mbs.param[i] != patterns[i]) {
744 isp_prt(isp, ISP_LOGERR, "Register Test Failed at Register %d: should have 0x%04x but got 0x%04x", i, patterns[i], mbs.param[i]);
751 * Download new Firmware, unless requested not to do so.
752 * This is made slightly trickier in some cases where the
753 * firmware of the ROM revision is newer than the revision
754 * compiled into the driver. So, where we used to compare
755 * versions of our f/w and the ROM f/w, now we just see
756 * whether we have f/w at all and whether a config flag
757 * has disabled our download.
759 if ((isp->isp_mdvec->dv_ispfw == NULL) || (isp->isp_confopts & ISP_CFG_NORELOAD)) {
764 code_org = ISP_CODE_ORG_2400;
765 } else if (IS_23XX(isp)) {
766 code_org = ISP_CODE_ORG_2300;
768 code_org = ISP_CODE_ORG;
771 isp->isp_loaded_fw = 0;
772 if (dodnld && IS_24XX(isp)) {
773 const uint32_t *ptr = isp->isp_mdvec->dv_ispfw;
777 * Keep loading until we run out of f/w.
779 code_org = ptr[2]; /* 1st load address is our start addr */
785 isp_prt(isp, ISP_LOGDEBUG0, "load 0x%x words of code at load address 0x%x", ptr[3], ptr[2]);
791 while (wi < ptr[3]) {
795 nw = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) >> 2;
799 cp = isp->isp_rquest;
800 for (i = 0; i < nw; i++) {
801 ISP_IOXPUT_32(isp, ptr[wi++], &cp[i]);
804 MEMORYBARRIER(isp, SYNC_REQUEST, 0, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)), -1);
806 MBSINIT(&mbs, 0, MBLOGALL, 0);
807 if (la < 0x10000 && nw < 0x10000) {
808 mbs.param[0] = MBOX_LOAD_RISC_RAM_2100;
810 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
811 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
813 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
814 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
815 isp_prt(isp, ISP_LOGDEBUG0, "LOAD RISC RAM 2100 %u words at load address 0x%x", nw, la);
816 } else if (wordload) {
821 ucd.cp = (const uint32_t *)cp;
822 mbs.param[0] = MBOX_WRITE_RAM_WORD_EXTENDED;
824 mbs.param[2] = (*ucd.np);
825 mbs.param[3] = (*ucd.np) >> 16;
826 mbs.param[8] = la >> 16;
827 isp->isp_mbxwrk0 = nw - 1;
828 isp->isp_mbxworkp = ucd.np+1;
829 isp->isp_mbxwrk1 = (la + 1);
830 isp->isp_mbxwrk8 = (la + 1) >> 16;
831 isp_prt(isp, ISP_LOGDEBUG0, "WRITE RAM WORD EXTENDED %u words at load address 0x%x", nw, la);
833 mbs.param[0] = MBOX_LOAD_RISC_RAM;
835 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
836 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
837 mbs.param[4] = nw >> 16;
839 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
840 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
841 mbs.param[8] = la >> 16;
842 isp_prt(isp, ISP_LOGDEBUG0, "LOAD RISC RAM %u words at load address 0x%x", nw, la);
844 isp_mboxcmd(isp, &mbs);
845 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
846 if (mbs.param[0] == MBOX_HOST_INTERFACE_ERROR) {
847 isp_prt(isp, ISP_LOGERR, "switching to word load");
851 isp_prt(isp, ISP_LOGERR, "F/W Risc Ram Load Failed");
863 isp->isp_loaded_fw = 1;
864 } else if (dodnld && IS_23XX(isp)) {
865 const uint16_t *ptr = isp->isp_mdvec->dv_ispfw;
866 uint16_t wi, wl, segno;
875 isp_prt(isp, ISP_LOGDEBUG0, "load 0x%x words of code at load address 0x%x", ptr[3], la);
880 while (wi < ptr[3]) {
884 nw = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) >> 1;
888 if (nw > (1 << 15)) {
891 cp = isp->isp_rquest;
892 for (i = 0; i < nw; i++) {
893 ISP_IOXPUT_16(isp, ptr[wi++], &cp[i]);
896 MEMORYBARRIER(isp, SYNC_REQUEST, 0, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)), -1);
897 MBSINIT(&mbs, 0, MBLOGALL, 0);
899 mbs.param[0] = MBOX_LOAD_RISC_RAM_2100;
901 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
902 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
904 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
905 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
906 isp_prt(isp, ISP_LOGDEBUG1, "LOAD RISC RAM 2100 %u words at load address 0x%x\n", nw, la);
908 mbs.param[0] = MBOX_LOAD_RISC_RAM;
910 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
911 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
913 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
914 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
915 mbs.param[8] = la >> 16;
916 isp_prt(isp, ISP_LOGDEBUG1, "LOAD RISC RAM %u words at load address 0x%x\n", nw, la);
918 isp_mboxcmd(isp, &mbs);
919 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
920 isp_prt(isp, ISP_LOGERR, "F/W Risc Ram Load Failed");
936 * If we're a 2322, the firmware actually comes in
937 * three chunks. We loaded the first at the code_org
938 * address. The other two chunks, which follow right
939 * after each other in memory here, get loaded at
940 * addresses specfied at offset 0x9..0xB.
945 la = ptr[5] | ((ptr[4] & 0x3f) << 16);
947 isp->isp_loaded_fw = 1;
953 ucd.cp = isp->isp_mdvec->dv_ispfw;
954 isp->isp_mbxworkp = &ucd.np[1];
955 isp->isp_mbxwrk0 = ucd.np[3] - 1;
956 isp->isp_mbxwrk1 = code_org + 1;
957 MBSINIT(&mbs, MBOX_WRITE_RAM_WORD, MBLOGNONE, 0);
958 mbs.param[1] = code_org;
959 mbs.param[2] = ucd.np[0];
960 isp_prt(isp, ISP_LOGDEBUG1, "WRITE RAM %u words at load address 0x%x", ucd.np[3], code_org);
961 isp_mboxcmd(isp, &mbs);
962 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
963 isp_prt(isp, ISP_LOGERR, "F/W download failed at word %d", isp->isp_mbxwrk1 - code_org);
967 } else if (IS_26XX(isp)) {
968 MBSINIT(&mbs, MBOX_LOAD_FLASH_FIRMWARE, MBLOGALL, 5000000);
971 isp_mboxcmd(isp, &mbs);
972 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
973 isp_prt(isp, ISP_LOGERR, "Flash F/W load failed");
978 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
982 * If we loaded firmware, verify its checksum
984 if (isp->isp_loaded_fw) {
985 MBSINIT(&mbs, MBOX_VERIFY_CHECKSUM, MBLOGNONE, 0);
987 mbs.param[1] = code_org >> 16;
988 mbs.param[2] = code_org;
990 mbs.param[1] = code_org;
992 isp_mboxcmd(isp, &mbs);
993 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
994 isp_prt(isp, ISP_LOGERR, dcrc);
1001 * Now start it rolling.
1003 * If we didn't actually download f/w,
1004 * we still need to (re)start it.
1008 MBSINIT(&mbs, MBOX_EXEC_FIRMWARE, MBLOGALL, 5000000);
1010 mbs.param[1] = code_org >> 16;
1011 mbs.param[2] = code_org;
1012 if (isp->isp_loaded_fw) {
1017 } else if (IS_2322(isp)) {
1018 mbs.param[1] = code_org;
1019 if (isp->isp_loaded_fw) {
1025 mbs.param[1] = code_org;
1027 isp_mboxcmd(isp, &mbs);
1028 if (IS_2322(isp) || IS_24XX(isp)) {
1029 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1037 * Set CLOCK RATE, but only if asked to.
1039 if (isp->isp_clock) {
1040 MBSINIT(&mbs, MBOX_SET_CLOCK_RATE, MBLOGALL, 0);
1041 mbs.param[1] = isp->isp_clock;
1042 isp_mboxcmd(isp, &mbs);
1043 /* we will try not to care if this fails */
1048 * Ask the chip for the current firmware version.
1049 * This should prove that the new firmware is working.
1051 MBSINIT(&mbs, MBOX_ABOUT_FIRMWARE, MBLOGALL, 0);
1052 isp_mboxcmd(isp, &mbs);
1053 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1059 * The SBus firmware that we are using apparently does not return
1060 * major, minor, micro revisions in the mailbox registers, which
1061 * is really, really, annoying.
1063 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
1065 #ifdef ISP_TARGET_MODE
1066 isp->isp_fwrev[0] = 7;
1067 isp->isp_fwrev[1] = 55;
1069 isp->isp_fwrev[0] = 1;
1070 isp->isp_fwrev[1] = 37;
1072 isp->isp_fwrev[2] = 0;
1075 isp->isp_fwrev[0] = mbs.param[1];
1076 isp->isp_fwrev[1] = mbs.param[2];
1077 isp->isp_fwrev[2] = mbs.param[3];
1082 * We do not believe firmware attributes for 2100 code less
1083 * than 1.17.0, unless it's the firmware we specifically
1086 * Note that all 22XX and later f/w is greater than 1.X.0.
1088 if ((ISP_FW_OLDER_THAN(isp, 1, 17, 1))) {
1089 #ifdef USE_SMALLER_2100_FIRMWARE
1090 isp->isp_fwattr = ISP_FW_ATTR_SCCLUN;
1092 isp->isp_fwattr = 0;
1095 isp->isp_fwattr = mbs.param[6];
1098 isp->isp_fwattr |= ((uint64_t) mbs.param[15]) << 16;
1099 if (isp->isp_fwattr & ISP2400_FW_ATTR_EXTNDED) {
1101 (((uint64_t) mbs.param[16]) << 32) |
1102 (((uint64_t) mbs.param[17]) << 48);
1106 isp->isp_fwattr = 0;
1109 isp_prt(isp, ISP_LOGCONFIG, "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
1110 btype, isp->isp_revision, dodnld? "loaded" : "resident", isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
1112 fwt = isp->isp_fwattr;
1114 buf = FCPARAM(isp, 0)->isp_scratch;
1115 ISP_SNPRINTF(buf, ISP_FC_SCRLEN, "Attributes:");
1116 if (fwt & ISP2400_FW_ATTR_CLASS2) {
1117 fwt ^=ISP2400_FW_ATTR_CLASS2;
1118 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s Class2", buf);
1120 if (fwt & ISP2400_FW_ATTR_IP) {
1121 fwt ^=ISP2400_FW_ATTR_IP;
1122 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s IP", buf);
1124 if (fwt & ISP2400_FW_ATTR_MULTIID) {
1125 fwt ^=ISP2400_FW_ATTR_MULTIID;
1126 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s MultiID", buf);
1128 if (fwt & ISP2400_FW_ATTR_SB2) {
1129 fwt ^=ISP2400_FW_ATTR_SB2;
1130 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s SB2", buf);
1132 if (fwt & ISP2400_FW_ATTR_T10CRC) {
1133 fwt ^=ISP2400_FW_ATTR_T10CRC;
1134 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s T10CRC", buf);
1136 if (fwt & ISP2400_FW_ATTR_VI) {
1137 fwt ^=ISP2400_FW_ATTR_VI;
1138 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VI", buf);
1140 if (fwt & ISP2400_FW_ATTR_MQ) {
1141 fwt ^=ISP2400_FW_ATTR_MQ;
1142 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s MQ", buf);
1144 if (fwt & ISP2400_FW_ATTR_MSIX) {
1145 fwt ^=ISP2400_FW_ATTR_MSIX;
1146 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s MSIX", buf);
1148 if (fwt & ISP2400_FW_ATTR_FCOE) {
1149 fwt ^=ISP2400_FW_ATTR_FCOE;
1150 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s FCOE", buf);
1152 if (fwt & ISP2400_FW_ATTR_VP0) {
1153 fwt ^= ISP2400_FW_ATTR_VP0;
1154 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VP0_Decoupling", buf);
1156 if (fwt & ISP2400_FW_ATTR_EXPFW) {
1157 fwt ^= ISP2400_FW_ATTR_EXPFW;
1158 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s (Experimental)", buf);
1160 if (fwt & ISP2400_FW_ATTR_HOTFW) {
1161 fwt ^= ISP2400_FW_ATTR_HOTFW;
1162 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s HotFW", buf);
1164 fwt &= ~ISP2400_FW_ATTR_EXTNDED;
1165 if (fwt & ISP2400_FW_ATTR_EXTVP) {
1166 fwt ^= ISP2400_FW_ATTR_EXTVP;
1167 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s ExtVP", buf);
1169 if (fwt & ISP2400_FW_ATTR_VN2VN) {
1170 fwt ^= ISP2400_FW_ATTR_VN2VN;
1171 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VN2VN", buf);
1173 if (fwt & ISP2400_FW_ATTR_EXMOFF) {
1174 fwt ^= ISP2400_FW_ATTR_EXMOFF;
1175 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s EXMOFF", buf);
1177 if (fwt & ISP2400_FW_ATTR_NPMOFF) {
1178 fwt ^= ISP2400_FW_ATTR_NPMOFF;
1179 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s NPMOFF", buf);
1181 if (fwt & ISP2400_FW_ATTR_DIFCHOP) {
1182 fwt ^= ISP2400_FW_ATTR_DIFCHOP;
1183 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s DIFCHOP", buf);
1185 if (fwt & ISP2400_FW_ATTR_SRIOV) {
1186 fwt ^= ISP2400_FW_ATTR_SRIOV;
1187 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s SRIOV", buf);
1189 if (fwt & ISP2400_FW_ATTR_ASICTMP) {
1190 fwt ^= ISP2400_FW_ATTR_ASICTMP;
1191 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s ASICTMP", buf);
1193 if (fwt & ISP2400_FW_ATTR_ATIOMQ) {
1194 fwt ^= ISP2400_FW_ATTR_ATIOMQ;
1195 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s ATIOMQ", buf);
1198 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s (unknown 0x%08x%08x)", buf,
1199 (uint32_t) (fwt >> 32), (uint32_t) fwt);
1201 isp_prt(isp, ISP_LOGCONFIG, "%s", buf);
1202 } else if (IS_FC(isp)) {
1203 buf = FCPARAM(isp, 0)->isp_scratch;
1204 ISP_SNPRINTF(buf, ISP_FC_SCRLEN, "Attributes:");
1205 if (fwt & ISP_FW_ATTR_TMODE) {
1206 fwt ^=ISP_FW_ATTR_TMODE;
1207 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s TargetMode", buf);
1209 if (fwt & ISP_FW_ATTR_SCCLUN) {
1210 fwt ^=ISP_FW_ATTR_SCCLUN;
1211 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s SCC-Lun", buf);
1213 if (fwt & ISP_FW_ATTR_FABRIC) {
1214 fwt ^=ISP_FW_ATTR_FABRIC;
1215 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s Fabric", buf);
1217 if (fwt & ISP_FW_ATTR_CLASS2) {
1218 fwt ^=ISP_FW_ATTR_CLASS2;
1219 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s Class2", buf);
1221 if (fwt & ISP_FW_ATTR_FCTAPE) {
1222 fwt ^=ISP_FW_ATTR_FCTAPE;
1223 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s FC-Tape", buf);
1225 if (fwt & ISP_FW_ATTR_IP) {
1226 fwt ^=ISP_FW_ATTR_IP;
1227 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s IP", buf);
1229 if (fwt & ISP_FW_ATTR_VI) {
1230 fwt ^=ISP_FW_ATTR_VI;
1231 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VI", buf);
1233 if (fwt & ISP_FW_ATTR_VI_SOLARIS) {
1234 fwt ^=ISP_FW_ATTR_VI_SOLARIS;
1235 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VI_SOLARIS", buf);
1237 if (fwt & ISP_FW_ATTR_2KLOGINS) {
1238 fwt ^=ISP_FW_ATTR_2KLOGINS;
1239 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s 2K-Login", buf);
1242 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s (unknown 0x%08x%08x)", buf,
1243 (uint32_t) (fwt >> 32), (uint32_t) fwt);
1245 isp_prt(isp, ISP_LOGCONFIG, "%s", buf);
1249 MBSINIT(&mbs, MBOX_GET_RESOURCE_COUNT, MBLOGALL, 0);
1250 isp_mboxcmd(isp, &mbs);
1251 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1255 if (isp->isp_maxcmds >= mbs.param[3]) {
1256 isp->isp_maxcmds = mbs.param[3];
1259 MBSINIT(&mbs, MBOX_GET_FIRMWARE_STATUS, MBLOGALL, 0);
1260 isp_mboxcmd(isp, &mbs);
1261 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1265 if (isp->isp_maxcmds >= mbs.param[2]) {
1266 isp->isp_maxcmds = mbs.param[2];
1269 isp_prt(isp, ISP_LOGCONFIG, "%d max I/O command limit set", isp->isp_maxcmds);
1272 * If we don't have Multi-ID f/w loaded, we need to restrict channels to one.
1273 * Only make this check for non-SCSI cards (I'm not sure firmware attributes
1276 if (IS_FC(isp) && isp->isp_nchan > 1) {
1277 if (!ISP_CAP_MULTI_ID(isp)) {
1278 isp_prt(isp, ISP_LOGWARN, "non-MULTIID f/w loaded, "
1279 "only can enable 1 of %d channels", isp->isp_nchan);
1281 } else if (!ISP_CAP_VP0(isp)) {
1282 isp_prt(isp, ISP_LOGWARN, "We can not use MULTIID "
1283 "feature properly without VP0_Decoupling");
1288 for (i = 0; i < isp->isp_nchan; i++)
1289 isp_change_fw_state(isp, i, FW_CONFIG_WAIT);
1291 if (isp->isp_dead) {
1293 ISP_DISABLE_INTS(isp);
1297 isp->isp_state = ISP_RESETSTATE;
1300 * Okay- now that we have new firmware running, we now (re)set our
1301 * notion of how many luns we support. This is somewhat tricky because
1302 * if we haven't loaded firmware, we sometimes do not have an easy way
1303 * of knowing how many luns we support.
1305 * Expanded lun firmware gives you 32 luns for SCSI cards and
1306 * 16384 luns for Fibre Channel cards.
1308 * It turns out that even for QLogic 2100s with ROM 1.10 and above
1309 * we do get a firmware attributes word returned in mailbox register 6.
1311 * Because the lun is in a different position in the Request Queue
1312 * Entry structure for Fibre Channel with expanded lun firmware, we
1313 * can only support one lun (lun zero) when we don't know what kind
1314 * of firmware we're running.
1318 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
1319 isp->isp_maxluns = 32;
1321 isp->isp_maxluns = 8;
1324 isp->isp_maxluns = 8;
1327 if (ISP_CAP_SCCFW(isp)) {
1328 isp->isp_maxluns = 0; /* No limit -- 2/8 bytes */
1330 isp->isp_maxluns = 16;
1335 * We get some default values established. As a side
1336 * effect, NVRAM is read here (unless overriden by
1337 * a configuration flag).
1339 if (do_load_defaults) {
1341 isp_setdfltsdparm(isp);
1343 for (i = 0; i < isp->isp_nchan; i++) {
1344 isp_setdfltfcparm(isp, i);
1351 * Clean firmware shutdown.
1354 isp_deinit(ispsoftc_t *isp)
1358 isp->isp_state = ISP_NILSTATE;
1359 MBSINIT(&mbs, MBOX_STOP_FIRMWARE, MBLOGALL, 500000);
1368 isp_mboxcmd(isp, &mbs);
1369 return (mbs.param[0] == MBOX_COMMAND_COMPLETE ? 0 : mbs.param[0]);
1373 * Initialize Parameters of Hardware to a known state.
1375 * Locks are held before coming here.
1378 isp_init(ispsoftc_t *isp)
1382 isp_fibre_init_2400(isp);
1384 isp_fibre_init(isp);
1389 GET_NANOTIME(&isp->isp_init_time);
1393 isp_scsi_init(ispsoftc_t *isp)
1395 sdparam *sdp_chan0, *sdp_chan1;
1398 isp->isp_state = ISP_INITSTATE;
1400 sdp_chan0 = SDPARAM(isp, 0);
1401 sdp_chan1 = sdp_chan0;
1402 if (IS_DUALBUS(isp)) {
1403 sdp_chan1 = SDPARAM(isp, 1);
1406 /* First do overall per-card settings. */
1409 * If we have fast memory timing enabled, turn it on.
1411 if (sdp_chan0->isp_fast_mttr) {
1412 ISP_WRITE(isp, RISC_MTR, 0x1313);
1416 * Set Retry Delay and Count.
1417 * You set both channels at the same time.
1419 MBSINIT(&mbs, MBOX_SET_RETRY_COUNT, MBLOGALL, 0);
1420 mbs.param[1] = sdp_chan0->isp_retry_count;
1421 mbs.param[2] = sdp_chan0->isp_retry_delay;
1422 mbs.param[6] = sdp_chan1->isp_retry_count;
1423 mbs.param[7] = sdp_chan1->isp_retry_delay;
1424 isp_mboxcmd(isp, &mbs);
1425 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1430 * Set ASYNC DATA SETUP time. This is very important.
1432 MBSINIT(&mbs, MBOX_SET_ASYNC_DATA_SETUP_TIME, MBLOGALL, 0);
1433 mbs.param[1] = sdp_chan0->isp_async_data_setup;
1434 mbs.param[2] = sdp_chan1->isp_async_data_setup;
1435 isp_mboxcmd(isp, &mbs);
1436 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1441 * Set ACTIVE Negation State.
1443 MBSINIT(&mbs, MBOX_SET_ACT_NEG_STATE, MBLOGNONE, 0);
1445 (sdp_chan0->isp_req_ack_active_neg << 4) |
1446 (sdp_chan0->isp_data_line_active_neg << 5);
1448 (sdp_chan1->isp_req_ack_active_neg << 4) |
1449 (sdp_chan1->isp_data_line_active_neg << 5);
1450 isp_mboxcmd(isp, &mbs);
1451 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1452 isp_prt(isp, ISP_LOGERR,
1453 "failed to set active negation state (%d,%d), (%d,%d)",
1454 sdp_chan0->isp_req_ack_active_neg,
1455 sdp_chan0->isp_data_line_active_neg,
1456 sdp_chan1->isp_req_ack_active_neg,
1457 sdp_chan1->isp_data_line_active_neg);
1464 * Set the Tag Aging limit
1466 MBSINIT(&mbs, MBOX_SET_TAG_AGE_LIMIT, MBLOGALL, 0);
1467 mbs.param[1] = sdp_chan0->isp_tag_aging;
1468 mbs.param[2] = sdp_chan1->isp_tag_aging;
1469 isp_mboxcmd(isp, &mbs);
1470 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1471 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
1472 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
1477 * Set selection timeout.
1479 MBSINIT(&mbs, MBOX_SET_SELECT_TIMEOUT, MBLOGALL, 0);
1480 mbs.param[1] = sdp_chan0->isp_selection_timeout;
1481 mbs.param[2] = sdp_chan1->isp_selection_timeout;
1482 isp_mboxcmd(isp, &mbs);
1483 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1487 /* now do per-channel settings */
1488 isp_scsi_channel_init(isp, 0);
1489 if (IS_DUALBUS(isp))
1490 isp_scsi_channel_init(isp, 1);
1493 * Now enable request/response queues
1496 if (IS_ULTRA2(isp) || IS_1240(isp)) {
1497 MBSINIT(&mbs, MBOX_INIT_RES_QUEUE_A64, MBLOGALL, 0);
1498 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1499 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1500 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1502 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1503 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1504 isp_mboxcmd(isp, &mbs);
1505 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1508 isp->isp_residx = isp->isp_resodx = mbs.param[5];
1510 MBSINIT(&mbs, MBOX_INIT_REQ_QUEUE_A64, MBLOGALL, 0);
1511 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1512 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1513 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1515 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1516 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1517 isp_mboxcmd(isp, &mbs);
1518 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1521 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1523 MBSINIT(&mbs, MBOX_INIT_RES_QUEUE, MBLOGALL, 0);
1524 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1525 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1526 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1528 isp_mboxcmd(isp, &mbs);
1529 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1532 isp->isp_residx = isp->isp_resodx = mbs.param[5];
1534 MBSINIT(&mbs, MBOX_INIT_REQ_QUEUE, MBLOGALL, 0);
1535 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1536 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1537 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1539 isp_mboxcmd(isp, &mbs);
1540 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1543 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1547 * Turn on LVD transitions for ULTRA2 or better and other features
1549 * Now that we have 32 bit handles, don't do any fast posting
1550 * any more. For Ultra2/Ultra3 cards, we can turn on 32 bit RIO
1551 * operation or use fast posting. To be conservative, we'll only
1552 * do this for Ultra3 cards now because the other cards are so
1553 * rare for this author to find and test with.
1556 MBSINIT(&mbs, MBOX_SET_FW_FEATURES, MBLOGALL, 0);
1558 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1561 mbs.param[1] |= FW_FEATURE_FAST_POST;
1564 mbs.param[1] |= FW_FEATURE_RIO_32BIT;
1566 if (mbs.param[1] != 0) {
1567 uint16_t sfeat = mbs.param[1];
1568 isp_mboxcmd(isp, &mbs);
1569 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1570 isp_prt(isp, ISP_LOGINFO,
1571 "Enabled FW features (0x%x)", sfeat);
1575 isp->isp_state = ISP_RUNSTATE;
1579 isp_scsi_channel_init(ispsoftc_t *isp, int chan)
1585 sdp = SDPARAM(isp, chan);
1588 * Set (possibly new) Initiator ID.
1590 MBSINIT(&mbs, MBOX_SET_INIT_SCSI_ID, MBLOGALL, 0);
1591 mbs.param[1] = (chan << 7) | sdp->isp_initiator_id;
1592 isp_mboxcmd(isp, &mbs);
1593 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1596 isp_prt(isp, ISP_LOGINFO, "Chan %d Initiator ID is %d",
1597 chan, sdp->isp_initiator_id);
1601 * Set current per-target parameters to an initial safe minimum.
1603 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1607 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1610 #ifndef ISP_TARGET_MODE
1611 sdf = sdp->isp_devparam[tgt].goal_flags;
1612 sdf &= DPARM_SAFE_DFLT;
1614 * It is not quite clear when this changed over so that
1615 * we could force narrow and async for 1000/1020 cards,
1616 * but assume that this is only the case for loaded
1619 if (isp->isp_loaded_fw) {
1620 sdf |= DPARM_NARROW | DPARM_ASYNC;
1624 * The !$*!)$!$)* f/w uses the same index into some
1625 * internal table to decide how to respond to negotiations,
1626 * so if we've said "let's be safe" for ID X, and ID X
1627 * selects *us*, the negotiations will back to 'safe'
1628 * (as in narrow/async). What the f/w *should* do is
1629 * use the initiator id settings to decide how to respond.
1631 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1633 MBSINIT(&mbs, MBOX_SET_TARGET_PARAMS, MBLOGNONE, 0);
1634 mbs.param[1] = (chan << 15) | (tgt << 8);
1636 if ((sdf & DPARM_SYNC) == 0) {
1640 (sdp->isp_devparam[tgt].goal_offset << 8) |
1641 (sdp->isp_devparam[tgt].goal_period);
1643 isp_prt(isp, ISP_LOGDEBUG0, "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1644 chan, tgt, mbs.param[2], mbs.param[3] >> 8, mbs.param[3] & 0xff);
1645 isp_mboxcmd(isp, &mbs);
1646 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1647 sdf = DPARM_SAFE_DFLT;
1648 MBSINIT(&mbs, MBOX_SET_TARGET_PARAMS, MBLOGALL, 0);
1649 mbs.param[1] = (tgt << 8) | (chan << 15);
1652 isp_mboxcmd(isp, &mbs);
1653 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1659 * We don't update any information directly from the f/w
1660 * because we need to run at least one command to cause a
1661 * new state to be latched up. So, we just assume that we
1662 * converge to the values we just had set.
1664 * Ensure that we don't believe tagged queuing is enabled yet.
1665 * It turns out that sometimes the ISP just ignores our
1666 * attempts to set parameters for devices that it hasn't
1669 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1670 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1671 MBSINIT(&mbs, MBOX_SET_DEV_QUEUE_PARAMS, MBLOGALL, 0);
1672 mbs.param[1] = (chan << 15) | (tgt << 8) | lun;
1673 mbs.param[2] = sdp->isp_max_queue_depth;
1674 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1675 isp_mboxcmd(isp, &mbs);
1676 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1681 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1682 if (sdp->isp_devparam[tgt].dev_refresh) {
1683 sdp->sendmarker = 1;
1691 * Fibre Channel specific initialization.
1694 isp_fibre_init(ispsoftc_t *isp)
1697 isp_icb_t local, *icbp = &local;
1701 * We only support one channel on non-24XX cards
1703 fcp = FCPARAM(isp, 0);
1704 if (fcp->role == ISP_ROLE_NONE)
1707 isp->isp_state = ISP_INITSTATE;
1708 ISP_MEMZERO(icbp, sizeof (*icbp));
1709 icbp->icb_version = ICB_VERSION1;
1710 icbp->icb_fwoptions = fcp->isp_fwoptions;
1713 * Firmware Options are either retrieved from NVRAM or
1714 * are patched elsewhere. We check them for sanity here
1715 * and make changes based on board revision, but otherwise
1716 * let others decide policy.
1720 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1722 if (IS_2100(isp) && isp->isp_revision < 5) {
1723 icbp->icb_fwoptions &= ~ICBOPT_FAIRNESS;
1727 * We have to use FULL LOGIN even though it resets the loop too much
1728 * because otherwise port database entries don't get updated after
1729 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1731 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1732 icbp->icb_fwoptions |= ICBOPT_FULL_LOGIN;
1736 * Insist on Port Database Update Async notifications
1738 icbp->icb_fwoptions |= ICBOPT_PDBCHANGE_AE;
1741 * Make sure that target role reflects into fwoptions.
1743 if (fcp->role & ISP_ROLE_TARGET) {
1744 icbp->icb_fwoptions |= ICBOPT_TGT_ENABLE;
1746 icbp->icb_fwoptions &= ~ICBOPT_TGT_ENABLE;
1750 * For some reason my 2200 does not generate ATIOs in target mode
1751 * if initiator is disabled. Extra logins are better then target
1752 * not working at all.
1754 if ((fcp->role & ISP_ROLE_INITIATOR) || IS_2100(isp) || IS_2200(isp)) {
1755 icbp->icb_fwoptions &= ~ICBOPT_INI_DISABLE;
1757 icbp->icb_fwoptions |= ICBOPT_INI_DISABLE;
1760 icbp->icb_maxfrmlen = DEFAULT_FRAMESIZE(isp);
1761 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN || icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1762 isp_prt(isp, ISP_LOGERR, "bad frame length (%d) from NVRAM- using %d", DEFAULT_FRAMESIZE(isp), ICB_DFLT_FRMLEN);
1763 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1765 icbp->icb_maxalloc = fcp->isp_maxalloc;
1766 if (icbp->icb_maxalloc < 1) {
1767 isp_prt(isp, ISP_LOGERR, "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1768 icbp->icb_maxalloc = 16;
1770 icbp->icb_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
1771 if (icbp->icb_execthrottle < 1) {
1772 isp_prt(isp, ISP_LOGERR, "bad execution throttle of %d- using %d", DEFAULT_EXEC_THROTTLE(isp), ICB_DFLT_THROTTLE);
1773 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1775 icbp->icb_retry_delay = fcp->isp_retry_delay;
1776 icbp->icb_retry_count = fcp->isp_retry_count;
1777 if (fcp->isp_loopid < LOCAL_LOOP_LIM) {
1778 icbp->icb_hardaddr = fcp->isp_loopid;
1779 if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
1780 icbp->icb_fwoptions |= ICBOPT_HARD_ADDRESS;
1782 icbp->icb_fwoptions |= ICBOPT_PREV_ADDRESS;
1786 * Right now we just set extended options to prefer point-to-point
1787 * over loop based upon some soft config options.
1789 * NB: for the 2300, ICBOPT_EXTENDED is required.
1793 * We can't have Fast Posting any more- we now
1794 * have 32 bit handles.
1796 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1797 } else if (IS_2200(isp) || IS_23XX(isp)) {
1798 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1800 icbp->icb_xfwoptions = fcp->isp_xfwoptions;
1802 if (ISP_CAP_FCTAPE(isp)) {
1803 if (isp->isp_confopts & ISP_CFG_NOFCTAPE)
1804 icbp->icb_xfwoptions &= ~ICBXOPT_FCTAPE;
1806 if (isp->isp_confopts & ISP_CFG_FCTAPE)
1807 icbp->icb_xfwoptions |= ICBXOPT_FCTAPE;
1809 if (icbp->icb_xfwoptions & ICBXOPT_FCTAPE) {
1810 icbp->icb_fwoptions &= ~ICBOPT_FULL_LOGIN; /* per documents */
1811 icbp->icb_xfwoptions |= ICBXOPT_FCTAPE_CCQ|ICBXOPT_FCTAPE_CONFIRM;
1812 FCPARAM(isp, 0)->fctape_enabled = 1;
1814 FCPARAM(isp, 0)->fctape_enabled = 0;
1817 icbp->icb_xfwoptions &= ~ICBXOPT_FCTAPE;
1818 FCPARAM(isp, 0)->fctape_enabled = 0;
1822 * Prefer or force Point-To-Point instead Loop?
1824 switch (isp->isp_confopts & ISP_CFG_PORT_PREF) {
1825 case ISP_CFG_LPORT_ONLY:
1826 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1827 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1829 case ISP_CFG_NPORT_ONLY:
1830 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1831 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1834 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1835 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1838 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1839 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1842 /* Let NVRAM settings define it if they are sane */
1843 switch (icbp->icb_xfwoptions & ICBXOPT_TOPO_MASK) {
1844 case ICBXOPT_PTP_2_LOOP:
1845 case ICBXOPT_PTP_ONLY:
1846 case ICBXOPT_LOOP_ONLY:
1847 case ICBXOPT_LOOP_2_PTP:
1850 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1851 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1857 * We can't have Fast Posting any more- we now
1858 * have 32 bit handles.
1860 * RIO seemed to have to much breakage.
1862 * Just opt for safety.
1864 icbp->icb_xfwoptions &= ~ICBXOPT_RIO_16BIT;
1865 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1868 * QLogic recommends that FAST Posting be turned
1869 * off for 23XX cards and instead allow the HBA
1870 * to write response queue entries and interrupt
1871 * after a delay (ZIO).
1873 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1874 if ((fcp->isp_xfwoptions & ICBXOPT_TIMER_MASK) == ICBXOPT_ZIO) {
1875 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1876 icbp->icb_idelaytimer = 10;
1878 icbp->icb_zfwoptions = fcp->isp_zfwoptions;
1879 if (isp->isp_confopts & ISP_CFG_1GB) {
1880 icbp->icb_zfwoptions &= ~ICBZOPT_RATE_MASK;
1881 icbp->icb_zfwoptions |= ICBZOPT_RATE_1GB;
1882 } else if (isp->isp_confopts & ISP_CFG_2GB) {
1883 icbp->icb_zfwoptions &= ~ICBZOPT_RATE_MASK;
1884 icbp->icb_zfwoptions |= ICBZOPT_RATE_2GB;
1886 switch (icbp->icb_zfwoptions & ICBZOPT_RATE_MASK) {
1887 case ICBZOPT_RATE_1GB:
1888 case ICBZOPT_RATE_2GB:
1889 case ICBZOPT_RATE_AUTO:
1892 icbp->icb_zfwoptions &= ~ICBZOPT_RATE_MASK;
1893 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1902 * For 22XX > 2.1.26 && 23XX, set some options.
1904 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1905 MBSINIT(&mbs, MBOX_SET_FIRMWARE_OPTIONS, MBLOGALL, 0);
1906 mbs.param[1] = IFCOPT1_DISF7SWTCH|IFCOPT1_LIPASYNC|IFCOPT1_LIPF8;
1909 if (ISP_FW_NEWER_THAN(isp, 3, 16, 0)) {
1910 mbs.param[1] |= IFCOPT1_EQFQASYNC|IFCOPT1_CTIO_RETRY;
1911 if (fcp->role & ISP_ROLE_TARGET) {
1912 if (ISP_FW_NEWER_THAN(isp, 3, 25, 0)) {
1913 mbs.param[1] |= IFCOPT1_ENAPURE;
1915 mbs.param[3] = IFCOPT3_NOPRLI;
1918 isp_mboxcmd(isp, &mbs);
1919 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1923 icbp->icb_logintime = ICB_LOGIN_TOV;
1925 #ifdef ISP_TARGET_MODE
1926 if (icbp->icb_fwoptions & ICBOPT_TGT_ENABLE) {
1927 icbp->icb_lunenables = 0xffff;
1928 icbp->icb_ccnt = 0xff;
1929 icbp->icb_icnt = 0xff;
1930 icbp->icb_lunetimeout = ICB_LUN_ENABLE_TOV;
1933 if (fcp->isp_wwnn && fcp->isp_wwpn) {
1934 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1935 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, fcp->isp_wwnn);
1936 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1937 isp_prt(isp, ISP_LOGDEBUG1,
1938 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1939 ((uint32_t) (fcp->isp_wwnn >> 32)),
1940 ((uint32_t) (fcp->isp_wwnn)),
1941 ((uint32_t) (fcp->isp_wwpn >> 32)),
1942 ((uint32_t) (fcp->isp_wwpn)));
1943 } else if (fcp->isp_wwpn) {
1944 icbp->icb_fwoptions &= ~ICBOPT_BOTH_WWNS;
1945 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1946 isp_prt(isp, ISP_LOGDEBUG1,
1947 "Setting ICB Port 0x%08x%08x",
1948 ((uint32_t) (fcp->isp_wwpn >> 32)),
1949 ((uint32_t) (fcp->isp_wwpn)));
1951 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
1954 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1955 if (icbp->icb_rqstqlen < 1) {
1956 isp_prt(isp, ISP_LOGERR, "bad request queue length");
1958 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1959 if (icbp->icb_rsltqlen < 1) {
1960 isp_prt(isp, ISP_LOGERR, "bad result queue length");
1962 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1963 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1964 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1965 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1966 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1967 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1968 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1969 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1971 if (FC_SCRATCH_ACQUIRE(isp, 0)) {
1972 isp_prt(isp, ISP_LOGERR, sacq);
1975 isp_prt(isp, ISP_LOGDEBUG0, "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1976 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1978 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1979 if (isp->isp_dblev & ISP_LOGDEBUG1) {
1980 isp_print_bytes(isp, "isp_fibre_init",
1981 sizeof(*icbp), fcp->isp_scratch);
1987 MBSINIT(&mbs, MBOX_INIT_FIRMWARE, MBLOGALL, 30000000);
1989 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1990 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1991 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1992 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1993 isp_prt(isp, ISP_LOGDEBUG0, "INIT F/W from %p (%08x%08x)",
1994 fcp->isp_scratch, (uint32_t) ((uint64_t)fcp->isp_scdma >> 32),
1995 (uint32_t) fcp->isp_scdma);
1996 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp), 0);
1997 isp_mboxcmd(isp, &mbs);
1998 FC_SCRATCH_RELEASE(isp, 0);
1999 if (mbs.param[0] != MBOX_COMMAND_COMPLETE)
2001 isp->isp_reqidx = 0;
2002 isp->isp_reqodx = 0;
2003 isp->isp_residx = 0;
2004 isp->isp_resodx = 0;
2007 * Whatever happens, we're now committed to being here.
2009 isp->isp_state = ISP_RUNSTATE;
2013 isp_fibre_init_2400(ispsoftc_t *isp)
2016 isp_icb_2400_t local, *icbp = &local;
2021 * Check to see whether all channels have *some* kind of role
2023 for (chan = 0; chan < isp->isp_nchan; chan++) {
2024 fcp = FCPARAM(isp, chan);
2025 if (fcp->role != ISP_ROLE_NONE) {
2029 if (chan == isp->isp_nchan) {
2030 isp_prt(isp, ISP_LOG_WARN1, "all %d channels with role 'none'", chan);
2034 isp->isp_state = ISP_INITSTATE;
2037 * Start with channel 0.
2039 fcp = FCPARAM(isp, 0);
2042 * Turn on LIP F8 async event (1)
2044 MBSINIT(&mbs, MBOX_SET_FIRMWARE_OPTIONS, MBLOGALL, 0);
2046 isp_mboxcmd(isp, &mbs);
2047 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2051 ISP_MEMZERO(icbp, sizeof (*icbp));
2052 icbp->icb_fwoptions1 = fcp->isp_fwoptions;
2053 icbp->icb_fwoptions2 = fcp->isp_xfwoptions;
2054 icbp->icb_fwoptions3 = fcp->isp_zfwoptions;
2055 if (isp->isp_nchan > 1 && ISP_CAP_VP0(isp)) {
2056 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_INI_DISABLE;
2057 icbp->icb_fwoptions1 |= ICB2400_OPT1_TGT_ENABLE;
2059 if (fcp->role & ISP_ROLE_TARGET)
2060 icbp->icb_fwoptions1 |= ICB2400_OPT1_TGT_ENABLE;
2062 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_TGT_ENABLE;
2063 if (fcp->role & ISP_ROLE_INITIATOR)
2064 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_INI_DISABLE;
2066 icbp->icb_fwoptions1 |= ICB2400_OPT1_INI_DISABLE;
2069 icbp->icb_version = ICB_VERSION1;
2070 icbp->icb_maxfrmlen = DEFAULT_FRAMESIZE(isp);
2071 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN || icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
2072 isp_prt(isp, ISP_LOGERR, "bad frame length (%d) from NVRAM- using %d", DEFAULT_FRAMESIZE(isp), ICB_DFLT_FRMLEN);
2073 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
2076 icbp->icb_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
2077 if (icbp->icb_execthrottle < 1) {
2078 isp_prt(isp, ISP_LOGERR, "bad execution throttle of %d- using %d", DEFAULT_EXEC_THROTTLE(isp), ICB_DFLT_THROTTLE);
2079 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
2083 * Set target exchange count. Take half if we are supporting both roles.
2085 if (icbp->icb_fwoptions1 & ICB2400_OPT1_TGT_ENABLE) {
2086 icbp->icb_xchgcnt = isp->isp_maxcmds;
2087 if ((icbp->icb_fwoptions1 & ICB2400_OPT1_INI_DISABLE) == 0)
2088 icbp->icb_xchgcnt >>= 1;
2091 if (fcp->isp_loopid < LOCAL_LOOP_LIM) {
2092 icbp->icb_hardaddr = fcp->isp_loopid;
2093 if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
2094 icbp->icb_fwoptions1 |= ICB2400_OPT1_HARD_ADDRESS;
2096 icbp->icb_fwoptions1 |= ICB2400_OPT1_PREV_ADDRESS;
2099 if (isp->isp_confopts & ISP_CFG_NOFCTAPE) {
2100 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_FCTAPE;
2102 if (isp->isp_confopts & ISP_CFG_FCTAPE) {
2103 icbp->icb_fwoptions2 |= ICB2400_OPT2_FCTAPE;
2106 for (chan = 0; chan < isp->isp_nchan; chan++) {
2107 if (icbp->icb_fwoptions2 & ICB2400_OPT2_FCTAPE)
2108 FCPARAM(isp, chan)->fctape_enabled = 1;
2110 FCPARAM(isp, chan)->fctape_enabled = 0;
2113 switch (isp->isp_confopts & ISP_CFG_PORT_PREF) {
2114 case ISP_CFG_LPORT_ONLY:
2115 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2116 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_ONLY;
2118 case ISP_CFG_NPORT_ONLY:
2119 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2120 icbp->icb_fwoptions2 |= ICB2400_OPT2_PTP_ONLY;
2123 /* ISP_CFG_PTP_2_LOOP not available in 24XX/25XX */
2125 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2126 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_2_PTP;
2129 /* Let NVRAM settings define it if they are sane */
2130 switch (icbp->icb_fwoptions2 & ICB2400_OPT2_TOPO_MASK) {
2131 case ICB2400_OPT2_LOOP_ONLY:
2132 case ICB2400_OPT2_PTP_ONLY:
2133 case ICB2400_OPT2_LOOP_2_PTP:
2136 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2137 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_2_PTP;
2142 switch (icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK) {
2143 case ICB2400_OPT2_ZIO:
2144 case ICB2400_OPT2_ZIO1:
2145 icbp->icb_idelaytimer = 0;
2150 isp_prt(isp, ISP_LOGWARN, "bad value %x in fwopt2 timer field", icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK);
2151 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TIMER_MASK;
2156 /* We don't support MSI-X yet, so set this unconditionally. */
2157 icbp->icb_fwoptions2 |= ICB2400_OPT2_ENA_IHR;
2158 icbp->icb_fwoptions2 |= ICB2400_OPT2_ENA_IHA;
2161 if ((icbp->icb_fwoptions3 & ICB2400_OPT3_RSPSZ_MASK) == 0) {
2162 icbp->icb_fwoptions3 |= ICB2400_OPT3_RSPSZ_24;
2164 if (isp->isp_confopts & ISP_CFG_1GB) {
2165 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2166 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_1GB;
2167 } else if (isp->isp_confopts & ISP_CFG_2GB) {
2168 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2169 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_2GB;
2170 } else if (isp->isp_confopts & ISP_CFG_4GB) {
2171 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2172 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_4GB;
2173 } else if (isp->isp_confopts & ISP_CFG_8GB) {
2174 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2175 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_8GB;
2176 } else if (isp->isp_confopts & ISP_CFG_16GB) {
2177 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2178 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_16GB;
2180 switch (icbp->icb_fwoptions3 & ICB2400_OPT3_RATE_MASK) {
2181 case ICB2400_OPT3_RATE_4GB:
2182 case ICB2400_OPT3_RATE_8GB:
2183 case ICB2400_OPT3_RATE_16GB:
2184 case ICB2400_OPT3_RATE_AUTO:
2186 case ICB2400_OPT3_RATE_2GB:
2187 if (isp->isp_type <= ISP_HA_FC_2500)
2190 case ICB2400_OPT3_RATE_1GB:
2191 if (isp->isp_type <= ISP_HA_FC_2400)
2195 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2196 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_AUTO;
2200 icbp->icb_logintime = ICB_LOGIN_TOV;
2202 if (fcp->isp_wwnn && fcp->isp_wwpn) {
2203 icbp->icb_fwoptions1 |= ICB2400_OPT1_BOTH_WWNS;
2204 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
2205 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, fcp->isp_wwnn);
2206 isp_prt(isp, ISP_LOGDEBUG1, "Setting ICB Node 0x%08x%08x Port 0x%08x%08x", ((uint32_t) (fcp->isp_wwnn >> 32)), ((uint32_t) (fcp->isp_wwnn)),
2207 ((uint32_t) (fcp->isp_wwpn >> 32)), ((uint32_t) (fcp->isp_wwpn)));
2208 } else if (fcp->isp_wwpn) {
2209 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_BOTH_WWNS;
2210 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
2211 isp_prt(isp, ISP_LOGDEBUG1, "Setting ICB Node to be same as Port 0x%08x%08x", ((uint32_t) (fcp->isp_wwpn >> 32)), ((uint32_t) (fcp->isp_wwpn)));
2213 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
2216 icbp->icb_retry_count = fcp->isp_retry_count;
2218 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
2219 if (icbp->icb_rqstqlen < 8) {
2220 isp_prt(isp, ISP_LOGERR, "bad request queue length %d", icbp->icb_rqstqlen);
2223 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
2224 if (icbp->icb_rsltqlen < 8) {
2225 isp_prt(isp, ISP_LOGERR, "bad result queue length %d",
2226 icbp->icb_rsltqlen);
2229 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
2230 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
2231 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
2232 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
2234 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
2235 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
2236 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
2237 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
2239 #ifdef ISP_TARGET_MODE
2240 /* unconditionally set up the ATIO queue if we support target mode */
2241 icbp->icb_atioqlen = RESULT_QUEUE_LEN(isp);
2242 if (icbp->icb_atioqlen < 8) {
2243 isp_prt(isp, ISP_LOGERR, "bad ATIO queue length %d", icbp->icb_atioqlen);
2246 icbp->icb_atioqaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_atioq_dma);
2247 icbp->icb_atioqaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_atioq_dma);
2248 icbp->icb_atioqaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_atioq_dma);
2249 icbp->icb_atioqaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_atioq_dma);
2250 isp_prt(isp, ISP_LOGDEBUG0, "isp_fibre_init_2400: atioq %04x%04x%04x%04x", DMA_WD3(isp->isp_atioq_dma), DMA_WD2(isp->isp_atioq_dma),
2251 DMA_WD1(isp->isp_atioq_dma), DMA_WD0(isp->isp_atioq_dma));
2254 isp_prt(isp, ISP_LOGDEBUG0, "isp_fibre_init_2400: fwopt1 0x%x fwopt2 0x%x fwopt3 0x%x", icbp->icb_fwoptions1, icbp->icb_fwoptions2, icbp->icb_fwoptions3);
2256 isp_prt(isp, ISP_LOGDEBUG0, "isp_fibre_init_2400: rqst %04x%04x%04x%04x rsp %04x%04x%04x%04x", DMA_WD3(isp->isp_rquest_dma), DMA_WD2(isp->isp_rquest_dma),
2257 DMA_WD1(isp->isp_rquest_dma), DMA_WD0(isp->isp_rquest_dma), DMA_WD3(isp->isp_result_dma), DMA_WD2(isp->isp_result_dma),
2258 DMA_WD1(isp->isp_result_dma), DMA_WD0(isp->isp_result_dma));
2260 if (FC_SCRATCH_ACQUIRE(isp, 0)) {
2261 isp_prt(isp, ISP_LOGERR, sacq);
2264 ISP_MEMZERO(fcp->isp_scratch, ISP_FC_SCRLEN);
2265 isp_put_icb_2400(isp, icbp, fcp->isp_scratch);
2266 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2267 isp_print_bytes(isp, "isp_fibre_init_2400",
2268 sizeof (*icbp), fcp->isp_scratch);
2272 * Now fill in information about any additional channels
2274 if (isp->isp_nchan > 1) {
2275 isp_icb_2400_vpinfo_t vpinfo, *vdst;
2276 vp_port_info_t pi, *pdst;
2280 vpinfo.vp_global_options = ICB2400_VPGOPT_GEN_RIDA;
2281 if (ISP_CAP_VP0(isp)) {
2282 vpinfo.vp_global_options |= ICB2400_VPGOPT_VP0_DECOUPLE;
2283 vpinfo.vp_count = isp->isp_nchan;
2286 vpinfo.vp_count = isp->isp_nchan - 1;
2289 off = fcp->isp_scratch;
2290 off += ICB2400_VPINFO_OFF;
2291 vdst = (isp_icb_2400_vpinfo_t *) off;
2292 isp_put_icb_2400_vpinfo(isp, &vpinfo, vdst);
2293 amt = ICB2400_VPINFO_OFF + sizeof (isp_icb_2400_vpinfo_t);
2294 for (; chan < isp->isp_nchan; chan++) {
2297 ISP_MEMZERO(&pi, sizeof (pi));
2298 fcp2 = FCPARAM(isp, chan);
2299 if (fcp2->role != ISP_ROLE_NONE) {
2300 pi.vp_port_options = ICB2400_VPOPT_ENABLED |
2301 ICB2400_VPOPT_ENA_SNSLOGIN;
2302 if (fcp2->role & ISP_ROLE_INITIATOR)
2303 pi.vp_port_options |= ICB2400_VPOPT_INI_ENABLE;
2304 if ((fcp2->role & ISP_ROLE_TARGET) == 0)
2305 pi.vp_port_options |= ICB2400_VPOPT_TGT_DISABLE;
2307 if (fcp2->isp_loopid < LOCAL_LOOP_LIM) {
2308 pi.vp_port_loopid = fcp2->isp_loopid;
2309 if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
2310 pi.vp_port_options |= ICB2400_VPOPT_HARD_ADDRESS;
2312 pi.vp_port_options |= ICB2400_VPOPT_PREV_ADDRESS;
2314 MAKE_NODE_NAME_FROM_WWN(pi.vp_port_portname, fcp2->isp_wwpn);
2315 MAKE_NODE_NAME_FROM_WWN(pi.vp_port_nodename, fcp2->isp_wwnn);
2316 off = fcp->isp_scratch;
2317 if (ISP_CAP_VP0(isp))
2318 off += ICB2400_VPINFO_PORT_OFF(chan);
2320 off += ICB2400_VPINFO_PORT_OFF(chan - 1);
2321 pdst = (vp_port_info_t *) off;
2322 isp_put_vp_port_info(isp, &pi, pdst);
2323 amt += ICB2400_VPOPT_WRITE_SIZE;
2325 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2326 isp_print_bytes(isp, "isp_fibre_init_2400",
2327 amt - ICB2400_VPINFO_OFF,
2328 (char *)fcp->isp_scratch + ICB2400_VPINFO_OFF);
2335 MBSINIT(&mbs, 0, MBLOGALL, 30000000);
2336 if (isp->isp_nchan > 1) {
2337 mbs.param[0] = MBOX_INIT_FIRMWARE_MULTI_ID;
2339 mbs.param[0] = MBOX_INIT_FIRMWARE;
2342 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2343 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2344 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2345 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2346 isp_prt(isp, ISP_LOGDEBUG0, "INIT F/W from %04x%04x%04x%04x", DMA_WD3(fcp->isp_scdma), DMA_WD2(fcp->isp_scdma), DMA_WD1(fcp->isp_scdma), DMA_WD0(fcp->isp_scdma));
2347 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp), 0);
2348 isp_mboxcmd(isp, &mbs);
2349 FC_SCRATCH_RELEASE(isp, 0);
2351 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2354 isp->isp_reqidx = 0;
2355 isp->isp_reqodx = 0;
2356 isp->isp_residx = 0;
2357 isp->isp_resodx = 0;
2358 isp->isp_atioodx = 0;
2361 * Whatever happens, we're now committed to being here.
2363 isp->isp_state = ISP_RUNSTATE;
2367 isp_fc_enable_vp(ispsoftc_t *isp, int chan)
2369 fcparam *fcp = FCPARAM(isp, chan);
2372 uint8_t resp[QENTRY_LEN];
2374 /* Build a VP MODIFY command in memory */
2375 ISP_MEMZERO(&vp, sizeof(vp));
2376 vp.vp_mod_hdr.rqs_entry_type = RQSTYPE_VP_MODIFY;
2377 vp.vp_mod_hdr.rqs_entry_count = 1;
2379 vp.vp_mod_idx0 = chan;
2380 vp.vp_mod_cmd = VP_MODIFY_ENA;
2381 vp.vp_mod_ports[0].options = ICB2400_VPOPT_ENABLED |
2382 ICB2400_VPOPT_ENA_SNSLOGIN;
2383 if (fcp->role & ISP_ROLE_INITIATOR)
2384 vp.vp_mod_ports[0].options |= ICB2400_VPOPT_INI_ENABLE;
2385 if ((fcp->role & ISP_ROLE_TARGET) == 0)
2386 vp.vp_mod_ports[0].options |= ICB2400_VPOPT_TGT_DISABLE;
2387 if (fcp->isp_loopid < LOCAL_LOOP_LIM) {
2388 vp.vp_mod_ports[0].loopid = fcp->isp_loopid;
2389 if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
2390 vp.vp_mod_ports[0].options |= ICB2400_VPOPT_HARD_ADDRESS;
2392 vp.vp_mod_ports[0].options |= ICB2400_VPOPT_PREV_ADDRESS;
2394 MAKE_NODE_NAME_FROM_WWN(vp.vp_mod_ports[0].wwpn, fcp->isp_wwpn);
2395 MAKE_NODE_NAME_FROM_WWN(vp.vp_mod_ports[0].wwnn, fcp->isp_wwnn);
2397 /* Prepare space for response in memory */
2398 memset(resp, 0xff, sizeof(resp));
2399 vp.vp_mod_hdl = isp_allocate_handle(isp, resp, ISP_HANDLE_CTRL);
2400 if (vp.vp_mod_hdl == 0) {
2401 isp_prt(isp, ISP_LOGERR,
2402 "%s: VP_MODIFY of Chan %d out of handles", __func__, chan);
2406 /* Send request and wait for response. */
2407 reqp = isp_getrqentry(isp);
2409 isp_prt(isp, ISP_LOGERR,
2410 "%s: VP_MODIFY of Chan %d out of rqent", __func__, chan);
2411 isp_destroy_handle(isp, vp.vp_mod_hdl);
2414 isp_put_vp_modify(isp, &vp, (vp_modify_t *)reqp);
2415 if (isp->isp_dblev & ISP_LOGDEBUG1)
2416 isp_print_bytes(isp, "IOCB VP_MODIFY", QENTRY_LEN, reqp);
2417 ISP_SYNC_REQUEST(isp);
2418 if (msleep(resp, &isp->isp_lock, 0, "VP_MODIFY", 5*hz) == EWOULDBLOCK) {
2419 isp_prt(isp, ISP_LOGERR,
2420 "%s: VP_MODIFY of Chan %d timed out", __func__, chan);
2421 isp_destroy_handle(isp, vp.vp_mod_hdl);
2424 if (isp->isp_dblev & ISP_LOGDEBUG1)
2425 isp_print_bytes(isp, "IOCB VP_MODIFY response", QENTRY_LEN, resp);
2426 isp_get_vp_modify(isp, (vp_modify_t *)resp, &vp);
2428 if (vp.vp_mod_hdr.rqs_flags != 0 || vp.vp_mod_status != VP_STS_OK) {
2429 isp_prt(isp, ISP_LOGERR,
2430 "%s: VP_MODIFY of Chan %d failed with flags %x status %d",
2431 __func__, chan, vp.vp_mod_hdr.rqs_flags, vp.vp_mod_status);
2434 GET_NANOTIME(&isp->isp_init_time);
2439 isp_fc_disable_vp(ispsoftc_t *isp, int chan)
2443 uint8_t resp[QENTRY_LEN];
2445 /* Build a VP CTRL command in memory */
2446 ISP_MEMZERO(&vp, sizeof(vp));
2447 vp.vp_ctrl_hdr.rqs_entry_type = RQSTYPE_VP_CTRL;
2448 vp.vp_ctrl_hdr.rqs_entry_count = 1;
2449 if (ISP_CAP_VP0(isp)) {
2450 vp.vp_ctrl_status = 1;
2452 vp.vp_ctrl_status = 0;
2453 chan--; /* VP0 can not be controlled in this case. */
2455 vp.vp_ctrl_command = VP_CTRL_CMD_DISABLE_VP_LOGO_ALL;
2456 vp.vp_ctrl_vp_count = 1;
2457 vp.vp_ctrl_idmap[chan / 16] |= (1 << chan % 16);
2459 /* Prepare space for response in memory */
2460 memset(resp, 0xff, sizeof(resp));
2461 vp.vp_ctrl_handle = isp_allocate_handle(isp, resp, ISP_HANDLE_CTRL);
2462 if (vp.vp_ctrl_handle == 0) {
2463 isp_prt(isp, ISP_LOGERR,
2464 "%s: VP_CTRL of Chan %d out of handles", __func__, chan);
2468 /* Send request and wait for response. */
2469 reqp = isp_getrqentry(isp);
2471 isp_prt(isp, ISP_LOGERR,
2472 "%s: VP_CTRL of Chan %d out of rqent", __func__, chan);
2473 isp_destroy_handle(isp, vp.vp_ctrl_handle);
2476 isp_put_vp_ctrl_info(isp, &vp, (vp_ctrl_info_t *)reqp);
2477 if (isp->isp_dblev & ISP_LOGDEBUG1)
2478 isp_print_bytes(isp, "IOCB VP_CTRL", QENTRY_LEN, reqp);
2479 ISP_SYNC_REQUEST(isp);
2480 if (msleep(resp, &isp->isp_lock, 0, "VP_CTRL", 5*hz) == EWOULDBLOCK) {
2481 isp_prt(isp, ISP_LOGERR,
2482 "%s: VP_CTRL of Chan %d timed out", __func__, chan);
2483 isp_destroy_handle(isp, vp.vp_ctrl_handle);
2486 if (isp->isp_dblev & ISP_LOGDEBUG1)
2487 isp_print_bytes(isp, "IOCB VP_CTRL response", QENTRY_LEN, resp);
2488 isp_get_vp_ctrl_info(isp, (vp_ctrl_info_t *)resp, &vp);
2490 if (vp.vp_ctrl_hdr.rqs_flags != 0 || vp.vp_ctrl_status != 0) {
2491 isp_prt(isp, ISP_LOGERR,
2492 "%s: VP_CTRL of Chan %d failed with flags %x status %d %d",
2493 __func__, chan, vp.vp_ctrl_hdr.rqs_flags,
2494 vp.vp_ctrl_status, vp.vp_ctrl_index_fail);
2501 isp_fc_change_role(ispsoftc_t *isp, int chan, int new_role)
2503 fcparam *fcp = FCPARAM(isp, chan);
2504 int i, was, res = 0;
2506 if (chan >= isp->isp_nchan) {
2507 isp_prt(isp, ISP_LOGWARN, "%s: bad channel %d", __func__, chan);
2510 if (fcp->role == new_role)
2512 for (was = 0, i = 0; i < isp->isp_nchan; i++) {
2513 if (FCPARAM(isp, i)->role != ISP_ROLE_NONE)
2516 if (was == 0 || (was == 1 && fcp->role != ISP_ROLE_NONE)) {
2517 fcp->role = new_role;
2518 return (isp_reinit(isp, 0));
2520 if (fcp->role != ISP_ROLE_NONE) {
2521 res = isp_fc_disable_vp(isp, chan);
2522 isp_clear_portdb(isp, chan);
2524 fcp->role = new_role;
2525 if (fcp->role != ISP_ROLE_NONE)
2526 res = isp_fc_enable_vp(isp, chan);
2531 isp_clear_portdb(ispsoftc_t *isp, int chan)
2533 fcparam *fcp = FCPARAM(isp, chan);
2537 for (i = 0; i < MAX_FC_TARG; i++) {
2538 lp = &fcp->portdb[i];
2539 switch (lp->state) {
2540 case FC_PORTDB_STATE_DEAD:
2541 case FC_PORTDB_STATE_CHANGED:
2542 case FC_PORTDB_STATE_VALID:
2543 lp->state = FC_PORTDB_STATE_NIL;
2544 isp_async(isp, ISPASYNC_DEV_GONE, chan, lp);
2546 case FC_PORTDB_STATE_NIL:
2547 case FC_PORTDB_STATE_NEW:
2548 lp->state = FC_PORTDB_STATE_NIL;
2550 case FC_PORTDB_STATE_ZOMBIE:
2553 panic("Don't know how to clear state %d\n", lp->state);
2559 isp_mark_portdb(ispsoftc_t *isp, int chan)
2561 fcparam *fcp = FCPARAM(isp, chan);
2565 for (i = 0; i < MAX_FC_TARG; i++) {
2566 lp = &fcp->portdb[i];
2567 if (lp->state == FC_PORTDB_STATE_NIL)
2569 if (lp->portid >= DOMAIN_CONTROLLER_BASE &&
2570 lp->portid <= DOMAIN_CONTROLLER_END)
2572 fcp->portdb[i].probational = 1;
2577 * Perform an IOCB PLOGI or LOGO via EXECUTE IOCB A64 for 24XX cards
2578 * or via FABRIC LOGIN/FABRIC LOGOUT for other cards.
2581 isp_plogx(ispsoftc_t *isp, int chan, uint16_t handle, uint32_t portid, int flags)
2585 uint8_t resp[QENTRY_LEN];
2586 uint32_t sst, parm1;
2591 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d PLOGX %s PortID 0x%06x nphdl 0x%x",
2592 chan, (flags & PLOGX_FLG_CMD_MASK) == PLOGX_FLG_CMD_PLOGI ?
2593 "Login":"Logout", portid, handle);
2594 if (!IS_24XX(isp)) {
2595 int action = flags & PLOGX_FLG_CMD_MASK;
2596 if (action == PLOGX_FLG_CMD_PLOGI) {
2597 return (isp_port_login(isp, handle, portid));
2598 } else if (action == PLOGX_FLG_CMD_LOGO) {
2599 return (isp_port_logout(isp, handle, portid));
2601 return (MBOX_INVALID_COMMAND);
2605 ISP_MEMZERO(&pl, sizeof(pl));
2606 pl.plogx_header.rqs_entry_count = 1;
2607 pl.plogx_header.rqs_entry_type = RQSTYPE_LOGIN;
2608 pl.plogx_nphdl = handle;
2609 pl.plogx_vphdl = chan;
2610 pl.plogx_portlo = portid;
2611 pl.plogx_rspsz_porthi = (portid >> 16) & 0xff;
2612 pl.plogx_flags = flags;
2614 /* Prepare space for response in memory */
2615 memset(resp, 0xff, sizeof(resp));
2616 pl.plogx_handle = isp_allocate_handle(isp, resp, ISP_HANDLE_CTRL);
2617 if (pl.plogx_handle == 0) {
2618 isp_prt(isp, ISP_LOGERR,
2619 "%s: PLOGX of Chan %d out of handles", __func__, chan);
2623 /* Send request and wait for response. */
2624 reqp = isp_getrqentry(isp);
2626 isp_prt(isp, ISP_LOGERR,
2627 "%s: PLOGX of Chan %d out of rqent", __func__, chan);
2628 isp_destroy_handle(isp, pl.plogx_handle);
2631 isp_put_plogx(isp, &pl, (isp_plogx_t *)reqp);
2632 if (isp->isp_dblev & ISP_LOGDEBUG1)
2633 isp_print_bytes(isp, "IOCB LOGX", QENTRY_LEN, reqp);
2634 FCPARAM(isp, chan)->isp_login_hdl = handle;
2635 ISP_SYNC_REQUEST(isp);
2636 if (msleep(resp, &isp->isp_lock, 0, "PLOGX", 3 * ICB_LOGIN_TOV * hz)
2638 isp_prt(isp, ISP_LOGERR,
2639 "%s: PLOGX of Chan %d timed out", __func__, chan);
2640 isp_destroy_handle(isp, pl.plogx_handle);
2643 FCPARAM(isp, chan)->isp_login_hdl = NIL_HANDLE;
2644 if (isp->isp_dblev & ISP_LOGDEBUG1)
2645 isp_print_bytes(isp, "IOCB LOGX response", QENTRY_LEN, resp);
2646 isp_get_plogx(isp, (isp_plogx_t *)resp, &pl);
2648 if (pl.plogx_status == PLOGX_STATUS_OK) {
2650 } else if (pl.plogx_status != PLOGX_STATUS_IOCBERR) {
2651 isp_prt(isp, ISP_LOGWARN,
2652 "status 0x%x on port login IOCB channel %d",
2653 pl.plogx_status, chan);
2657 sst = pl.plogx_ioparm[0].lo16 | (pl.plogx_ioparm[0].hi16 << 16);
2658 parm1 = pl.plogx_ioparm[1].lo16 | (pl.plogx_ioparm[1].hi16 << 16);
2665 case PLOGX_IOCBERR_NOLINK:
2668 case PLOGX_IOCBERR_NOIOCB:
2669 msg = "no IOCB buffer";
2671 case PLOGX_IOCBERR_NOXGHG:
2672 msg = "no Exchange Control Block";
2674 case PLOGX_IOCBERR_FAILED:
2675 ISP_SNPRINTF(buf, sizeof (buf), "reason 0x%x (last LOGIN state 0x%x)", parm1 & 0xff, (parm1 >> 8) & 0xff);
2678 case PLOGX_IOCBERR_NOFABRIC:
2681 case PLOGX_IOCBERR_NOTREADY:
2682 msg = "firmware not ready";
2684 case PLOGX_IOCBERR_NOLOGIN:
2685 ISP_SNPRINTF(buf, sizeof (buf), "not logged in (last state 0x%x)", parm1);
2687 rval = MBOX_NOT_LOGGED_IN;
2689 case PLOGX_IOCBERR_REJECT:
2690 ISP_SNPRINTF(buf, sizeof (buf), "LS_RJT = 0x%x", parm1);
2693 case PLOGX_IOCBERR_NOPCB:
2694 msg = "no PCB allocated";
2696 case PLOGX_IOCBERR_EINVAL:
2697 ISP_SNPRINTF(buf, sizeof (buf), "invalid parameter at offset 0x%x", parm1);
2700 case PLOGX_IOCBERR_PORTUSED:
2701 lev = ISP_LOG_SANCFG|ISP_LOG_WARN1;
2702 ISP_SNPRINTF(buf, sizeof (buf), "already logged in with N-Port handle 0x%x", parm1);
2704 rval = MBOX_PORT_ID_USED | (parm1 << 16);
2706 case PLOGX_IOCBERR_HNDLUSED:
2707 lev = ISP_LOG_SANCFG|ISP_LOG_WARN1;
2708 ISP_SNPRINTF(buf, sizeof (buf), "handle already used for PortID 0x%06x", parm1);
2710 rval = MBOX_LOOP_ID_USED;
2712 case PLOGX_IOCBERR_NOHANDLE:
2713 msg = "no handle allocated";
2715 case PLOGX_IOCBERR_NOFLOGI:
2716 msg = "no FLOGI_ACC";
2719 ISP_SNPRINTF(buf, sizeof (buf), "status %x from %x", pl.plogx_status, flags);
2724 isp_prt(isp, ISP_LOGERR, "Chan %d PLOGX PortID 0x%06x to N-Port handle 0x%x: %s", chan, portid, handle, msg);
2730 isp_port_login(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2734 MBSINIT(&mbs, MBOX_FABRIC_LOGIN, MBLOGNONE, 500000);
2735 if (ISP_CAP_2KLOGIN(isp)) {
2736 mbs.param[1] = handle;
2737 mbs.ibits = (1 << 10);
2739 mbs.param[1] = handle << 8;
2741 mbs.param[2] = portid >> 16;
2742 mbs.param[3] = portid;
2743 mbs.logval = MBLOGNONE;
2744 mbs.timeout = 500000;
2745 isp_mboxcmd(isp, &mbs);
2747 switch (mbs.param[0]) {
2748 case MBOX_PORT_ID_USED:
2749 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "isp_port_login: portid 0x%06x already logged in as 0x%x", portid, mbs.param[1]);
2750 return (MBOX_PORT_ID_USED | (mbs.param[1] << 16));
2752 case MBOX_LOOP_ID_USED:
2753 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "isp_port_login: handle 0x%x in use for port id 0x%02xXXXX", handle, mbs.param[1] & 0xff);
2754 return (MBOX_LOOP_ID_USED);
2756 case MBOX_COMMAND_COMPLETE:
2759 case MBOX_COMMAND_ERROR:
2760 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "isp_port_login: error 0x%x in PLOGI to port 0x%06x", mbs.param[1], portid);
2761 return (MBOX_COMMAND_ERROR);
2763 case MBOX_ALL_IDS_USED:
2764 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "isp_port_login: all IDs used for fabric login");
2765 return (MBOX_ALL_IDS_USED);
2768 isp_prt(isp, ISP_LOG_SANCFG, "isp_port_login: error 0x%x on port login of 0x%06x@0x%0x", mbs.param[0], portid, handle);
2769 return (mbs.param[0]);
2774 * Pre-24XX fabric port logout
2776 * Note that portid is not used
2779 isp_port_logout(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2783 MBSINIT(&mbs, MBOX_FABRIC_LOGOUT, MBLOGNONE, 500000);
2784 if (ISP_CAP_2KLOGIN(isp)) {
2785 mbs.param[1] = handle;
2786 mbs.ibits = (1 << 10);
2788 mbs.param[1] = handle << 8;
2790 isp_mboxcmd(isp, &mbs);
2791 return (mbs.param[0] == MBOX_COMMAND_COMPLETE? 0 : mbs.param[0]);
2795 isp_getpdb(ispsoftc_t *isp, int chan, uint16_t id, isp_pdb_t *pdb)
2799 isp_pdb_21xx_t fred;
2800 isp_pdb_24xx_t bill;
2803 MBSINIT(&mbs, MBOX_GET_PORT_DB,
2804 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_PARAM_ERROR), 250000);
2806 mbs.ibits = (1 << 9)|(1 << 10);
2808 mbs.param[9] = chan;
2809 } else if (ISP_CAP_2KLOGIN(isp)) {
2812 mbs.param[1] = id << 8;
2814 mbs.param[2] = DMA_WD1(isp->isp_iocb_dma);
2815 mbs.param[3] = DMA_WD0(isp->isp_iocb_dma);
2816 mbs.param[6] = DMA_WD3(isp->isp_iocb_dma);
2817 mbs.param[7] = DMA_WD2(isp->isp_iocb_dma);
2818 MEMORYBARRIER(isp, SYNC_IFORDEV, 0, sizeof(un), chan);
2820 isp_mboxcmd(isp, &mbs);
2821 if (mbs.param[0] != MBOX_COMMAND_COMPLETE)
2822 return (mbs.param[0] | (mbs.param[1] << 16));
2824 MEMORYBARRIER(isp, SYNC_IFORCPU, 0, sizeof(un), chan);
2826 isp_get_pdb_24xx(isp, isp->isp_iocb, &un.bill);
2827 pdb->handle = un.bill.pdb_handle;
2828 pdb->prli_word3 = un.bill.pdb_prli_svc3;
2829 pdb->portid = BITS2WORD_24XX(un.bill.pdb_portid_bits);
2830 ISP_MEMCPY(pdb->portname, un.bill.pdb_portname, 8);
2831 ISP_MEMCPY(pdb->nodename, un.bill.pdb_nodename, 8);
2832 isp_prt(isp, ISP_LOGDEBUG1,
2833 "Chan %d handle 0x%x Port 0x%06x flags 0x%x curstate %x",
2834 chan, id, pdb->portid, un.bill.pdb_flags,
2835 un.bill.pdb_curstate);
2836 if (un.bill.pdb_curstate < PDB2400_STATE_PLOGI_DONE || un.bill.pdb_curstate > PDB2400_STATE_LOGGED_IN) {
2837 mbs.param[0] = MBOX_NOT_LOGGED_IN;
2838 return (mbs.param[0]);
2841 isp_get_pdb_21xx(isp, isp->isp_iocb, &un.fred);
2842 pdb->handle = un.fred.pdb_loopid;
2843 pdb->prli_word3 = un.fred.pdb_prli_svc3;
2844 pdb->portid = BITS2WORD(un.fred.pdb_portid_bits);
2845 ISP_MEMCPY(pdb->portname, un.fred.pdb_portname, 8);
2846 ISP_MEMCPY(pdb->nodename, un.fred.pdb_nodename, 8);
2847 isp_prt(isp, ISP_LOGDEBUG1,
2848 "Chan %d handle 0x%x Port 0x%06x", chan, id, pdb->portid);
2854 isp_gethandles(ispsoftc_t *isp, int chan, uint16_t *handles, int *num, int loop)
2856 fcparam *fcp = FCPARAM(isp, chan);
2858 isp_pnhle_21xx_t el1, *elp1;
2859 isp_pnhle_23xx_t el3, *elp3;
2860 isp_pnhle_24xx_t el4, *elp4;
2865 MBSINIT(&mbs, MBOX_GET_ID_LIST, MBLOGALL, 250000);
2867 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2868 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2869 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2870 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2871 mbs.param[8] = ISP_FC_SCRLEN;
2872 mbs.param[9] = chan;
2874 mbs.ibits = (1 << 1)|(1 << 2)|(1 << 3)|(1 << 6);
2875 mbs.param[1] = DMA_WD1(fcp->isp_scdma);
2876 mbs.param[2] = DMA_WD0(fcp->isp_scdma);
2877 mbs.param[3] = DMA_WD3(fcp->isp_scdma);
2878 mbs.param[6] = DMA_WD2(fcp->isp_scdma);
2880 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
2881 isp_prt(isp, ISP_LOGERR, sacq);
2884 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, ISP_FC_SCRLEN, chan);
2885 isp_mboxcmd(isp, &mbs);
2886 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2887 FC_SCRATCH_RELEASE(isp, chan);
2888 return (mbs.param[0] | (mbs.param[1] << 16));
2890 MEMORYBARRIER(isp, SYNC_SFORCPU, 0, ISP_FC_SCRLEN, chan);
2891 elp1 = fcp->isp_scratch;
2892 elp3 = fcp->isp_scratch;
2893 elp4 = fcp->isp_scratch;
2894 for (i = 0, j = 0; i < mbs.param[1] && j < *num; i++) {
2896 isp_get_pnhle_24xx(isp, &elp4[i], &el4);
2897 p = el4.pnhle_port_id_lo |
2898 (el4.pnhle_port_id_hi << 16);
2899 h = el4.pnhle_handle;
2900 } else if (IS_23XX(isp)) {
2901 isp_get_pnhle_23xx(isp, &elp3[i], &el3);
2902 p = el3.pnhle_port_id_lo |
2903 (el3.pnhle_port_id_hi << 16);
2904 h = el3.pnhle_handle;
2906 isp_get_pnhle_21xx(isp, &elp1[i], &el1);
2907 p = el1.pnhle_port_id_lo |
2908 ((el1.pnhle_port_id_hi_handle & 0xff) << 16);
2909 h = el1.pnhle_port_id_hi_handle >> 8;
2911 if (loop && (p >> 8) != (fcp->isp_portid >> 8))
2916 FC_SCRATCH_RELEASE(isp, chan);
2921 isp_dump_chip_portdb(ispsoftc_t *isp, int chan)
2924 uint16_t lim, nphdl;
2926 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGINFO, "Chan %d chip port dump", chan);
2927 if (ISP_CAP_2KLOGIN(isp)) {
2932 for (nphdl = 0; nphdl != lim; nphdl++) {
2933 if (isp_getpdb(isp, chan, nphdl, &pdb)) {
2936 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGINFO, "Chan %d Handle 0x%04x "
2937 "PortID 0x%06x WWPN 0x%02x%02x%02x%02x%02x%02x%02x%02x",
2938 chan, nphdl, pdb.portid, pdb.portname[0], pdb.portname[1],
2939 pdb.portname[2], pdb.portname[3], pdb.portname[4],
2940 pdb.portname[5], pdb.portname[6], pdb.portname[7]);
2945 isp_get_wwn(ispsoftc_t *isp, int chan, int nphdl, int nodename)
2947 uint64_t wwn = INI_NONE;
2950 MBSINIT(&mbs, MBOX_GET_PORT_NAME,
2951 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_PARAM_ERROR), 500000);
2952 if (ISP_CAP_2KLOGIN(isp)) {
2953 mbs.param[1] = nphdl;
2957 mbs.param[9] = chan;
2960 mbs.param[1] = nphdl << 8;
2965 isp_mboxcmd(isp, &mbs);
2966 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2971 (((uint64_t)(mbs.param[2] >> 8)) << 56) |
2972 (((uint64_t)(mbs.param[2] & 0xff)) << 48) |
2973 (((uint64_t)(mbs.param[3] >> 8)) << 40) |
2974 (((uint64_t)(mbs.param[3] & 0xff)) << 32) |
2975 (((uint64_t)(mbs.param[6] >> 8)) << 24) |
2976 (((uint64_t)(mbs.param[6] & 0xff)) << 16) |
2977 (((uint64_t)(mbs.param[7] >> 8)) << 8) |
2978 (((uint64_t)(mbs.param[7] & 0xff)));
2981 (((uint64_t)(mbs.param[2] & 0xff)) << 56) |
2982 (((uint64_t)(mbs.param[2] >> 8)) << 48) |
2983 (((uint64_t)(mbs.param[3] & 0xff)) << 40) |
2984 (((uint64_t)(mbs.param[3] >> 8)) << 32) |
2985 (((uint64_t)(mbs.param[6] & 0xff)) << 24) |
2986 (((uint64_t)(mbs.param[6] >> 8)) << 16) |
2987 (((uint64_t)(mbs.param[7] & 0xff)) << 8) |
2988 (((uint64_t)(mbs.param[7] >> 8)));
2994 * Make sure we have good FC link.
2998 isp_fclink_test(ispsoftc_t *isp, int chan, int usdelay)
3005 NANOTIME_T hra, hrb;
3007 fcp = FCPARAM(isp, chan);
3009 if (fcp->isp_loopstate < LOOP_HAVE_LINK)
3011 if (fcp->isp_loopstate >= LOOP_LTEST_DONE)
3014 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC link test", chan);
3017 * Wait up to N microseconds for F/W to go to a ready state.
3021 isp_change_fw_state(isp, chan, isp_fw_state(isp, chan));
3022 if (fcp->isp_fwstate == FW_READY) {
3025 if (fcp->isp_loopstate < LOOP_HAVE_LINK)
3028 if ((NANOTIME_SUB(&hrb, &hra) / 1000 + 1000 >= usdelay))
3030 ISP_SLEEP(isp, 1000);
3032 if (fcp->isp_fwstate != FW_READY) {
3033 isp_prt(isp, ISP_LOG_SANCFG,
3034 "Chan %d Firmware is not ready (%s)",
3035 chan, isp_fc_fw_statename(fcp->isp_fwstate));
3040 * Get our Loop ID and Port ID.
3042 MBSINIT(&mbs, MBOX_GET_LOOP_ID, MBLOGALL, 0);
3043 mbs.param[9] = chan;
3044 isp_mboxcmd(isp, &mbs);
3045 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3051 * Don't bother with fabric if we are using really old
3052 * 2100 firmware. It's just not worth it.
3054 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37))
3055 fcp->isp_topo = TOPO_FL_PORT;
3057 fcp->isp_topo = TOPO_NL_PORT;
3059 int topo = (int) mbs.param[6];
3060 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB) {
3061 topo = TOPO_PTP_STUB;
3063 fcp->isp_topo = topo;
3065 fcp->isp_portid = mbs.param[2] | (mbs.param[3] << 16);
3067 if (!TOPO_IS_FABRIC(fcp->isp_topo)) {
3068 fcp->isp_loopid = mbs.param[1] & 0xff;
3069 } else if (fcp->isp_topo != TOPO_F_PORT) {
3070 uint8_t alpa = fcp->isp_portid;
3072 for (i = 0; alpa_map[i]; i++) {
3073 if (alpa_map[i] == alpa)
3077 fcp->isp_loopid = i;
3081 fcp->isp_loopstate = LOOP_HAVE_ADDR;
3083 fcp->isp_loopstate = LOOP_TESTING_LINK;
3085 if (fcp->isp_topo == TOPO_F_PORT || fcp->isp_topo == TOPO_FL_PORT) {
3086 nphdl = IS_24XX(isp) ? NPH_FL_ID : FL_ID;
3087 r = isp_getpdb(isp, chan, nphdl, &pdb);
3088 if (r != 0 || pdb.portid == 0) {
3090 fcp->isp_topo = TOPO_NL_PORT;
3092 isp_prt(isp, ISP_LOGWARN,
3093 "fabric topology, but cannot get info about fabric controller (0x%x)", r);
3094 fcp->isp_topo = TOPO_PTP_STUB;
3100 fcp->isp_fabric_params = mbs.param[7];
3101 fcp->isp_sns_hdl = NPH_SNS_ID;
3102 r = isp_register_fc4_type_24xx(isp, chan);
3103 if (fcp->isp_loopstate < LOOP_TESTING_LINK)
3107 r = isp_register_fc4_features_24xx(isp, chan);
3108 if (fcp->isp_loopstate < LOOP_TESTING_LINK)
3112 r = isp_register_port_name_24xx(isp, chan);
3113 if (fcp->isp_loopstate < LOOP_TESTING_LINK)
3117 isp_register_node_name_24xx(isp, chan);
3118 if (fcp->isp_loopstate < LOOP_TESTING_LINK)
3121 fcp->isp_sns_hdl = SNS_ID;
3122 r = isp_register_fc4_type(isp, chan);
3125 if (fcp->role == ISP_ROLE_TARGET)
3126 isp_send_change_request(isp, chan);
3131 /* Get link speed. */
3132 fcp->isp_gbspeed = 1;
3133 if (IS_23XX(isp) || IS_24XX(isp)) {
3134 MBSINIT(&mbs, MBOX_GET_SET_DATA_RATE, MBLOGALL, 3000000);
3135 mbs.param[1] = MBGSD_GET_RATE;
3136 /* mbs.param[2] undefined if we're just getting rate */
3137 isp_mboxcmd(isp, &mbs);
3138 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3139 if (mbs.param[1] == MBGSD_10GB)
3140 fcp->isp_gbspeed = 10;
3141 else if (mbs.param[1] == MBGSD_16GB)
3142 fcp->isp_gbspeed = 16;
3143 else if (mbs.param[1] == MBGSD_8GB)
3144 fcp->isp_gbspeed = 8;
3145 else if (mbs.param[1] == MBGSD_4GB)
3146 fcp->isp_gbspeed = 4;
3147 else if (mbs.param[1] == MBGSD_2GB)
3148 fcp->isp_gbspeed = 2;
3149 else if (mbs.param[1] == MBGSD_1GB)
3150 fcp->isp_gbspeed = 1;
3154 if (fcp->isp_loopstate < LOOP_TESTING_LINK) {
3156 isp_prt(isp, ISP_LOG_SANCFG,
3157 "Chan %d FC link test aborted", chan);
3160 fcp->isp_loopstate = LOOP_LTEST_DONE;
3161 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGCONFIG,
3162 "Chan %d WWPN %016jx WWNN %016jx",
3163 chan, (uintmax_t)fcp->isp_wwpn, (uintmax_t)fcp->isp_wwnn);
3164 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGCONFIG,
3165 "Chan %d %dGb %s PortID 0x%06x LoopID 0x%02x",
3166 chan, fcp->isp_gbspeed, isp_fc_toponame(fcp), fcp->isp_portid,
3168 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC link test done", chan);
3173 * Complete the synchronization of our Port Database.
3175 * At this point, we've scanned the local loop (if any) and the fabric
3176 * and performed fabric logins on all new devices.
3178 * Our task here is to go through our port database removing any entities
3179 * that are still marked probational (issuing PLOGO for ones which we had
3180 * PLOGI'd into) or are dead, and notifying upper layers about new/changed
3184 isp_pdb_sync(ispsoftc_t *isp, int chan)
3186 fcparam *fcp = FCPARAM(isp, chan);
3190 if (fcp->isp_loopstate < LOOP_FSCAN_DONE)
3192 if (fcp->isp_loopstate >= LOOP_READY)
3195 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC PDB sync", chan);
3197 fcp->isp_loopstate = LOOP_SYNCING_PDB;
3199 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
3200 lp = &fcp->portdb[dbidx];
3202 if (lp->state == FC_PORTDB_STATE_NIL)
3204 if (lp->probational && lp->state != FC_PORTDB_STATE_ZOMBIE)
3205 lp->state = FC_PORTDB_STATE_DEAD;
3206 switch (lp->state) {
3207 case FC_PORTDB_STATE_DEAD:
3208 lp->state = FC_PORTDB_STATE_NIL;
3209 isp_async(isp, ISPASYNC_DEV_GONE, chan, lp);
3210 if ((lp->portid & 0xffff00) != 0) {
3211 (void) isp_plogx(isp, chan, lp->handle,
3213 PLOGX_FLG_CMD_LOGO |
3214 PLOGX_FLG_IMPLICIT |
3215 PLOGX_FLG_FREE_NPHDL);
3218 * Note that we might come out of this with our state
3219 * set to FC_PORTDB_STATE_ZOMBIE.
3222 case FC_PORTDB_STATE_NEW:
3223 lp->state = FC_PORTDB_STATE_VALID;
3224 isp_async(isp, ISPASYNC_DEV_ARRIVED, chan, lp);
3226 case FC_PORTDB_STATE_CHANGED:
3227 lp->state = FC_PORTDB_STATE_VALID;
3228 isp_async(isp, ISPASYNC_DEV_CHANGED, chan, lp);
3229 lp->portid = lp->new_portid;
3230 lp->prli_word3 = lp->new_prli_word3;
3232 case FC_PORTDB_STATE_VALID:
3233 isp_async(isp, ISPASYNC_DEV_STAYED, chan, lp);
3235 case FC_PORTDB_STATE_ZOMBIE:
3238 isp_prt(isp, ISP_LOGWARN,
3239 "isp_pdb_sync: state %d for idx %d",
3241 isp_dump_portdb(isp, chan);
3245 if (fcp->isp_loopstate < LOOP_SYNCING_PDB) {
3246 isp_prt(isp, ISP_LOG_SANCFG,
3247 "Chan %d FC PDB sync aborted", chan);
3251 fcp->isp_loopstate = LOOP_READY;
3252 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC PDB sync done", chan);
3257 isp_pdb_add_update(ispsoftc_t *isp, int chan, isp_pdb_t *pdb)
3260 uint64_t wwnn, wwpn;
3262 MAKE_WWN_FROM_NODE_NAME(wwnn, pdb->nodename);
3263 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb->portname);
3265 /* Search port database for the same WWPN. */
3266 if (isp_find_pdb_by_wwpn(isp, chan, wwpn, &lp)) {
3267 if (!lp->probational) {
3268 isp_prt(isp, ISP_LOGERR,
3269 "Chan %d Port 0x%06x@0x%04x [%d] is not probational (0x%x)",
3270 chan, lp->portid, lp->handle,
3271 FC_PORTDB_TGT(isp, chan, lp), lp->state);
3272 isp_dump_portdb(isp, chan);
3275 lp->probational = 0;
3276 lp->node_wwn = wwnn;
3278 /* Old device, nothing new. */
3279 if (lp->portid == pdb->portid &&
3280 lp->handle == pdb->handle &&
3281 lp->prli_word3 == pdb->prli_word3) {
3282 if (lp->state != FC_PORTDB_STATE_NEW)
3283 lp->state = FC_PORTDB_STATE_VALID;
3284 isp_prt(isp, ISP_LOG_SANCFG,
3285 "Chan %d Port 0x%06x@0x%04x is valid",
3286 chan, pdb->portid, pdb->handle);
3290 /* Something has changed. */
3291 lp->state = FC_PORTDB_STATE_CHANGED;
3292 lp->handle = pdb->handle;
3293 lp->new_portid = pdb->portid;
3294 lp->new_prli_word3 = pdb->prli_word3;
3295 isp_prt(isp, ISP_LOG_SANCFG,
3296 "Chan %d Port 0x%06x@0x%04x is changed",
3297 chan, pdb->portid, pdb->handle);
3301 /* It seems like a new port. Find an empty slot for it. */
3302 if (!isp_find_pdb_empty(isp, chan, &lp)) {
3303 isp_prt(isp, ISP_LOGERR, "Chan %d out of portdb entries", chan);
3307 ISP_MEMZERO(lp, sizeof (fcportdb_t));
3308 lp->probational = 0;
3309 lp->state = FC_PORTDB_STATE_NEW;
3310 lp->portid = lp->new_portid = pdb->portid;
3311 lp->prli_word3 = lp->new_prli_word3 = pdb->prli_word3;
3312 lp->handle = pdb->handle;
3313 lp->port_wwn = wwpn;
3314 lp->node_wwn = wwnn;
3315 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Port 0x%06x@0x%04x is new",
3316 chan, pdb->portid, pdb->handle);
3320 * Fix port IDs for logged-in initiators on pre-2400 chips.
3321 * For those chips we are not receiving login events, adding initiators
3322 * based on ATIO requests, but there is no port ID in that structure.
3325 isp_fix_portids(ispsoftc_t *isp, int chan)
3327 fcparam *fcp = FCPARAM(isp, chan);
3332 for (i = 0; i < MAX_FC_TARG; i++) {
3333 fcportdb_t *lp = &fcp->portdb[i];
3335 if (lp->state == FC_PORTDB_STATE_NIL ||
3336 lp->state == FC_PORTDB_STATE_ZOMBIE)
3338 if (VALID_PORT(lp->portid))
3341 r = isp_getpdb(isp, chan, lp->handle, &pdb);
3342 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3345 isp_prt(isp, ISP_LOGDEBUG1,
3346 "Chan %d FC Scan Loop handle %d returned %x",
3347 chan, lp->handle, r);
3351 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb.portname);
3352 if (lp->port_wwn != wwpn)
3354 lp->portid = lp->new_portid = pdb.portid;
3355 isp_prt(isp, ISP_LOG_SANCFG,
3356 "Chan %d Port 0x%06x@0x%04x is fixed",
3357 chan, pdb.portid, pdb.handle);
3362 * Scan local loop for devices.
3365 isp_scan_loop(ispsoftc_t *isp, int chan)
3367 fcparam *fcp = FCPARAM(isp, chan);
3373 if (fcp->isp_loopstate < LOOP_LTEST_DONE)
3375 if (fcp->isp_loopstate >= LOOP_LSCAN_DONE)
3378 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC loop scan", chan);
3379 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
3380 if (TOPO_IS_FABRIC(fcp->isp_topo)) {
3381 if (!IS_24XX(isp)) {
3382 isp_fix_portids(isp, chan);
3383 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3386 isp_prt(isp, ISP_LOG_SANCFG,
3387 "Chan %d FC loop scan done (no loop)", chan);
3388 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3392 handles = (uint16_t *)fcp->isp_scanscratch;
3393 lim = ISP_FC_SCRLEN / 2;
3394 r = isp_gethandles(isp, chan, handles, &lim, 1);
3396 isp_prt(isp, ISP_LOG_SANCFG,
3397 "Chan %d Getting list of handles failed with %x", chan, r);
3398 isp_prt(isp, ISP_LOG_SANCFG,
3399 "Chan %d FC loop scan done (bad)", chan);
3403 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Got %d handles",
3407 * Run through the list and get the port database info for each one.
3409 isp_mark_portdb(isp, chan);
3410 for (idx = 0; idx < lim; idx++) {
3411 handle = handles[idx];
3414 * Don't scan "special" ids.
3416 if (ISP_CAP_2KLOGIN(isp)) {
3417 if (handle >= NPH_RESERVED)
3420 if (handle >= FL_ID && handle <= SNS_ID)
3425 * In older cards with older f/w GET_PORT_DATABASE has been
3426 * known to hang. This trick gets around that problem.
3428 if (IS_2100(isp) || IS_2200(isp)) {
3429 uint64_t node_wwn = isp_get_wwn(isp, chan, handle, 1);
3430 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
3432 isp_prt(isp, ISP_LOG_SANCFG,
3433 "Chan %d FC loop scan aborted", chan);
3436 if (node_wwn == INI_NONE) {
3442 * Get the port database entity for this index.
3444 r = isp_getpdb(isp, chan, handle, &pdb);
3445 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3448 isp_prt(isp, ISP_LOGDEBUG1,
3449 "Chan %d FC Scan Loop handle %d returned %x",
3454 isp_pdb_add_update(isp, chan, &pdb);
3456 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3458 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3459 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC loop scan done", chan);
3464 * Scan the fabric for devices and add them to our port database.
3466 * Use the GID_FT command to get all Port IDs for FC4 SCSI devices it knows.
3468 * For 2100-23XX cards, we use the SNS mailbox command to pass simple name
3469 * server commands to the switch management server via the QLogic f/w.
3471 * For the 24XX and above card, we use CT Pass-through IOCB.
3473 #define GIDLEN ISP_FC_SCRLEN
3474 #define NGENT ((GIDLEN - 16) >> 2)
3477 isp_gid_ft_sns(ispsoftc_t *isp, int chan)
3480 sns_gid_ft_req_t _x;
3481 uint8_t _y[SNS_GID_FT_REQ_SIZE];
3483 fcparam *fcp = FCPARAM(isp, chan);
3484 sns_gid_ft_req_t *rq = &un._x;
3485 uint8_t *scp = fcp->isp_scratch;
3488 isp_prt(isp, ISP_LOGDEBUG0, "Chan %d requesting GID_FT via SNS", chan);
3489 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3490 isp_prt(isp, ISP_LOGERR, sacq);
3494 ISP_MEMZERO(rq, SNS_GID_FT_REQ_SIZE);
3495 rq->snscb_rblen = GIDLEN >> 1;
3496 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma);
3497 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma);
3498 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma);
3499 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma);
3500 rq->snscb_sblen = 6;
3501 rq->snscb_cmd = SNS_GID_FT;
3502 rq->snscb_mword_div_2 = NGENT;
3503 rq->snscb_fc4_type = FC4_SCSI;
3505 isp_put_gid_ft_request(isp, rq, (sns_gid_ft_req_t *)scp);
3506 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE, chan);
3508 MBSINIT(&mbs, MBOX_SEND_SNS, MBLOGALL, 10000000);
3509 mbs.param[0] = MBOX_SEND_SNS;
3510 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
3511 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
3512 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
3513 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
3514 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
3515 isp_mboxcmd(isp, &mbs);
3516 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3517 if (mbs.param[0] == MBOX_INVALID_COMMAND) {
3523 MEMORYBARRIER(isp, SYNC_SFORCPU, 0, GIDLEN, chan);
3524 if (isp->isp_dblev & ISP_LOGDEBUG1)
3525 isp_print_bytes(isp, "CT response", GIDLEN, scp);
3526 isp_get_gid_ft_response(isp, (sns_gid_ft_rsp_t *)scp,
3527 (sns_gid_ft_rsp_t *)fcp->isp_scanscratch, NGENT);
3528 FC_SCRATCH_RELEASE(isp, chan);
3533 isp_ct_passthru(ispsoftc_t *isp, int chan, uint32_t cmd_bcnt, uint32_t rsp_bcnt)
3535 fcparam *fcp = FCPARAM(isp, chan);
3538 uint8_t resp[QENTRY_LEN];
3541 * Build a Passthrough IOCB in memory.
3543 ISP_MEMZERO(&pt, sizeof(pt));
3544 pt.ctp_header.rqs_entry_count = 1;
3545 pt.ctp_header.rqs_entry_type = RQSTYPE_CT_PASSTHRU;
3546 pt.ctp_nphdl = fcp->isp_sns_hdl;
3548 pt.ctp_vpidx = ISP_GET_VPIDX(isp, chan);
3551 pt.ctp_rsp_bcnt = rsp_bcnt;
3552 pt.ctp_cmd_bcnt = cmd_bcnt;
3553 pt.ctp_dataseg[0].ds_base = DMA_LO32(fcp->isp_scdma);
3554 pt.ctp_dataseg[0].ds_basehi = DMA_HI32(fcp->isp_scdma);
3555 pt.ctp_dataseg[0].ds_count = cmd_bcnt;
3556 pt.ctp_dataseg[1].ds_base = DMA_LO32(fcp->isp_scdma);
3557 pt.ctp_dataseg[1].ds_basehi = DMA_HI32(fcp->isp_scdma);
3558 pt.ctp_dataseg[1].ds_count = rsp_bcnt;
3560 /* Prepare space for response in memory */
3561 memset(resp, 0xff, sizeof(resp));
3562 pt.ctp_handle = isp_allocate_handle(isp, resp, ISP_HANDLE_CTRL);
3563 if (pt.ctp_handle == 0) {
3564 isp_prt(isp, ISP_LOGERR,
3565 "%s: CTP of Chan %d out of handles", __func__, chan);
3569 /* Send request and wait for response. */
3570 reqp = isp_getrqentry(isp);
3572 isp_prt(isp, ISP_LOGERR,
3573 "%s: CTP of Chan %d out of rqent", __func__, chan);
3574 isp_destroy_handle(isp, pt.ctp_handle);
3577 isp_put_ct_pt(isp, &pt, (isp_ct_pt_t *)reqp);
3578 if (isp->isp_dblev & ISP_LOGDEBUG1)
3579 isp_print_bytes(isp, "CT IOCB request", QENTRY_LEN, reqp);
3580 ISP_SYNC_REQUEST(isp);
3581 if (msleep(resp, &isp->isp_lock, 0, "CTP", pt.ctp_time*hz) == EWOULDBLOCK) {
3582 isp_prt(isp, ISP_LOGERR,
3583 "%s: CTP of Chan %d timed out", __func__, chan);
3584 isp_destroy_handle(isp, pt.ctp_handle);
3587 if (isp->isp_dblev & ISP_LOGDEBUG1)
3588 isp_print_bytes(isp, "CT IOCB response", QENTRY_LEN, resp);
3590 isp_get_ct_pt(isp, (isp_ct_pt_t *)resp, &pt);
3591 if (pt.ctp_status && pt.ctp_status != RQCS_DATA_UNDERRUN) {
3592 isp_prt(isp, ISP_LOGWARN,
3593 "Chan %d GID_FT CT Passthrough returned 0x%x",
3594 chan, pt.ctp_status);
3602 isp_gid_ft_ct_passthru(ispsoftc_t *isp, int chan)
3604 fcparam *fcp = FCPARAM(isp, chan);
3607 uint8_t *scp = fcp->isp_scratch;
3609 isp_prt(isp, ISP_LOGDEBUG0, "Chan %d requesting GID_FT via CT", chan);
3610 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3611 isp_prt(isp, ISP_LOGERR, sacq);
3616 * Build the CT header and command in memory.
3618 ISP_MEMZERO(&ct, sizeof (ct));
3619 ct.ct_revision = CT_REVISION;
3620 ct.ct_fcs_type = CT_FC_TYPE_FC;
3621 ct.ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3622 ct.ct_cmd_resp = SNS_GID_FT;
3623 ct.ct_bcnt_resid = (GIDLEN - 16) >> 2;
3624 isp_put_ct_hdr(isp, &ct, (ct_hdr_t *)scp);
3625 rp = (uint32_t *) &scp[sizeof(ct)];
3626 ISP_IOZPUT_32(isp, FC4_SCSI, rp);
3627 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3628 isp_print_bytes(isp, "CT request",
3629 sizeof(ct) + sizeof(uint32_t), scp);
3632 if (isp_ct_passthru(isp, chan, sizeof(ct) + sizeof(uint32_t), GIDLEN)) {
3633 FC_SCRATCH_RELEASE(isp, chan);
3637 if (isp->isp_dblev & ISP_LOGDEBUG1)
3638 isp_print_bytes(isp, "CT response", GIDLEN, scp);
3639 isp_get_gid_ft_response(isp, (sns_gid_ft_rsp_t *)scp,
3640 (sns_gid_ft_rsp_t *)fcp->isp_scanscratch, NGENT);
3641 FC_SCRATCH_RELEASE(isp, chan);
3646 isp_scan_fabric(ispsoftc_t *isp, int chan)
3648 fcparam *fcp = FCPARAM(isp, chan);
3653 int portidx, portlim, r;
3654 sns_gid_ft_rsp_t *rs;
3656 if (fcp->isp_loopstate < LOOP_LSCAN_DONE)
3658 if (fcp->isp_loopstate >= LOOP_FSCAN_DONE)
3661 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC fabric scan", chan);
3662 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
3663 if (!TOPO_IS_FABRIC(fcp->isp_topo)) {
3664 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3665 isp_prt(isp, ISP_LOG_SANCFG,
3666 "Chan %d FC fabric scan done (no fabric)", chan);
3670 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC) {
3672 FC_SCRATCH_RELEASE(isp, chan);
3673 isp_prt(isp, ISP_LOG_SANCFG,
3674 "Chan %d FC fabric scan aborted", chan);
3679 * Make sure we still are logged into the fabric controller.
3681 nphdl = IS_24XX(isp) ? NPH_FL_ID : FL_ID;
3682 r = isp_getpdb(isp, chan, nphdl, &pdb);
3683 if ((r & 0xffff) == MBOX_NOT_LOGGED_IN) {
3684 isp_dump_chip_portdb(isp, chan);
3687 fcp->isp_loopstate = LOOP_LTEST_DONE;
3689 isp_prt(isp, ISP_LOG_SANCFG,
3690 "Chan %d FC fabric scan done (bad)", chan);
3694 /* Get list of port IDs from SNS. */
3696 r = isp_gid_ft_ct_passthru(isp, chan);
3698 r = isp_gid_ft_sns(isp, chan);
3699 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3702 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3705 fcp->isp_loopstate = LOOP_LTEST_DONE; /* try again */
3709 rs = (sns_gid_ft_rsp_t *) fcp->isp_scanscratch;
3710 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3712 if (rs->snscb_cthdr.ct_cmd_resp != LS_ACC) {
3714 if (rs->snscb_cthdr.ct_reason == 9 && rs->snscb_cthdr.ct_explanation == 7) {
3715 level = ISP_LOG_SANCFG;
3717 level = ISP_LOGWARN;
3719 isp_prt(isp, level, "Chan %d Fabric Nameserver rejected GID_FT"
3720 " (Reason=0x%x Expl=0x%x)", chan,
3721 rs->snscb_cthdr.ct_reason,
3722 rs->snscb_cthdr.ct_explanation);
3723 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3727 /* Check our buffer was big enough to get the full list. */
3728 for (portidx = 0; portidx < NGENT-1; portidx++) {
3729 if (rs->snscb_ports[portidx].control & 0x80)
3732 if ((rs->snscb_ports[portidx].control & 0x80) == 0) {
3733 isp_prt(isp, ISP_LOGWARN,
3734 "fabric too big for scratch area: increase ISP_FC_SCRLEN");
3736 portlim = portidx + 1;
3737 isp_prt(isp, ISP_LOG_SANCFG,
3738 "Chan %d Got %d ports back from name server", chan, portlim);
3740 /* Go through the list and remove duplicate port ids. */
3741 for (portidx = 0; portidx < portlim; portidx++) {
3745 ((rs->snscb_ports[portidx].portid[0]) << 16) |
3746 ((rs->snscb_ports[portidx].portid[1]) << 8) |
3747 ((rs->snscb_ports[portidx].portid[2]));
3749 for (npidx = portidx + 1; npidx < portlim; npidx++) {
3750 uint32_t new_portid =
3751 ((rs->snscb_ports[npidx].portid[0]) << 16) |
3752 ((rs->snscb_ports[npidx].portid[1]) << 8) |
3753 ((rs->snscb_ports[npidx].portid[2]));
3754 if (new_portid == portid) {
3759 if (npidx < portlim) {
3760 rs->snscb_ports[npidx].portid[0] = 0;
3761 rs->snscb_ports[npidx].portid[1] = 0;
3762 rs->snscb_ports[npidx].portid[2] = 0;
3763 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d removing duplicate PortID 0x%06x entry from list", chan, portid);
3768 * We now have a list of Port IDs for all FC4 SCSI devices
3769 * that the Fabric Name server knows about.
3771 * For each entry on this list go through our port database looking
3772 * for probational entries- if we find one, then an old entry is
3773 * maybe still this one. We get some information to find out.
3775 * Otherwise, it's a new fabric device, and we log into it
3776 * (unconditionally). After searching the entire database
3777 * again to make sure that we never ever ever ever have more
3778 * than one entry that has the same PortID or the same
3779 * WWNN/WWPN duple, we enter the device into our database.
3781 isp_mark_portdb(isp, chan);
3782 for (portidx = 0; portidx < portlim; portidx++) {
3783 portid = ((rs->snscb_ports[portidx].portid[0]) << 16) |
3784 ((rs->snscb_ports[portidx].portid[1]) << 8) |
3785 ((rs->snscb_ports[portidx].portid[2]));
3786 isp_prt(isp, ISP_LOG_SANCFG,
3787 "Chan %d Checking fabric port 0x%06x", chan, portid);
3789 isp_prt(isp, ISP_LOG_SANCFG,
3790 "Chan %d Port at idx %d is zero",
3794 if (portid == fcp->isp_portid) {
3795 isp_prt(isp, ISP_LOG_SANCFG,
3796 "Chan %d Port 0x%06x is our", chan, portid);
3800 /* Now search the entire port database for the same portid. */
3801 if (isp_find_pdb_by_portid(isp, chan, portid, &lp)) {
3802 if (!lp->probational) {
3803 isp_prt(isp, ISP_LOGERR,
3804 "Chan %d Port 0x%06x@0x%04x [%d] is not probational (0x%x)",
3805 chan, lp->portid, lp->handle,
3806 FC_PORTDB_TGT(isp, chan, lp), lp->state);
3807 isp_dump_portdb(isp, chan);
3811 if (lp->state == FC_PORTDB_STATE_ZOMBIE)
3815 * See if we're still logged into it.
3817 * If we aren't, mark it as a dead device and
3818 * leave the new portid in the database entry
3819 * for somebody further along to decide what to
3820 * do (policy choice).
3822 * If we are, check to see if it's the same
3823 * device still (it should be). If for some
3824 * reason it isn't, mark it as a changed device
3825 * and leave the new portid and role in the
3826 * database entry for somebody further along to
3827 * decide what to do (policy choice).
3829 r = isp_getpdb(isp, chan, lp->handle, &pdb);
3830 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3833 lp->state = FC_PORTDB_STATE_DEAD;
3834 isp_prt(isp, ISP_LOG_SANCFG,
3835 "Chan %d Port 0x%06x handle 0x%x is dead (%d)",
3836 chan, portid, lp->handle, r);
3840 isp_pdb_add_update(isp, chan, &pdb);
3845 if ((fcp->role & ISP_ROLE_INITIATOR) == 0) {
3846 isp_prt(isp, ISP_LOG_SANCFG,
3847 "Chan %d Port 0x%06x is not logged in", chan, portid);
3851 if (isp_login_device(isp, chan, portid, &pdb,
3852 &FCPARAM(isp, 0)->isp_lasthdl)) {
3853 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3858 isp_pdb_add_update(isp, chan, &pdb);
3861 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3863 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3864 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC fabric scan done", chan);
3869 * Find an unused handle and try and use to login to a port.
3872 isp_login_device(ispsoftc_t *isp, int chan, uint32_t portid, isp_pdb_t *p, uint16_t *ohp)
3877 if (ISP_CAP_2KLOGIN(isp)) {
3883 handle = isp_next_handle(isp, ohp);
3884 for (i = 0; i < lim; i++) {
3885 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
3888 /* Check if this handle is free. */
3889 r = isp_getpdb(isp, chan, handle, p);
3891 if (p->portid != portid) {
3892 /* This handle is busy, try next one. */
3893 handle = isp_next_handle(isp, ohp);
3898 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
3902 * Now try and log into the device
3904 r = isp_plogx(isp, chan, handle, portid, PLOGX_FLG_CMD_PLOGI);
3907 } else if ((r & 0xffff) == MBOX_PORT_ID_USED) {
3909 * If we get here, then the firmwware still thinks we're logged into this device, but with a different
3910 * handle. We need to break that association. We used to try and just substitute the handle, but then
3911 * failed to get any data via isp_getpdb (below).
3913 if (isp_plogx(isp, chan, r >> 16, portid, PLOGX_FLG_CMD_LOGO | PLOGX_FLG_IMPLICIT | PLOGX_FLG_FREE_NPHDL)) {
3914 isp_prt(isp, ISP_LOGERR, "baw... logout of %x failed", r >> 16);
3916 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
3918 r = isp_plogx(isp, chan, handle, portid, PLOGX_FLG_CMD_PLOGI);
3922 } else if ((r & 0xffff) == MBOX_LOOP_ID_USED) {
3923 /* Try the next handle. */
3924 handle = isp_next_handle(isp, ohp);
3933 isp_prt(isp, ISP_LOGWARN, "Chan %d PLOGI 0x%06x failed", chan, portid);
3938 * If we successfully logged into it, get the PDB for it
3939 * so we can crosscheck that it is still what we think it
3940 * is and that we also have the role it plays
3942 r = isp_getpdb(isp, chan, handle, p);
3944 isp_prt(isp, ISP_LOGERR, "Chan %d new device 0x%06x@0x%x disappeared", chan, portid, handle);
3948 if (p->handle != handle || p->portid != portid) {
3949 isp_prt(isp, ISP_LOGERR, "Chan %d new device 0x%06x@0x%x changed (0x%06x@0x%0x)",
3950 chan, portid, handle, p->portid, p->handle);
3957 isp_send_change_request(ispsoftc_t *isp, int chan)
3961 MBSINIT(&mbs, MBOX_SEND_CHANGE_REQUEST, MBLOGALL, 500000);
3962 mbs.param[1] = 0x03;
3963 mbs.param[9] = chan;
3964 isp_mboxcmd(isp, &mbs);
3965 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3968 isp_prt(isp, ISP_LOGWARN, "Chan %d Send Change Request: 0x%x",
3969 chan, mbs.param[0]);
3975 isp_register_fc4_type(ispsoftc_t *isp, int chan)
3977 fcparam *fcp = FCPARAM(isp, chan);
3978 uint8_t local[SNS_RFT_ID_REQ_SIZE];
3979 sns_screq_t *reqp = (sns_screq_t *) local;
3982 ISP_MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
3983 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
3984 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
3985 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
3986 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
3987 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
3988 reqp->snscb_sblen = 22;
3989 reqp->snscb_data[0] = SNS_RFT_ID;
3990 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
3991 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
3992 reqp->snscb_data[6] = (1 << FC4_SCSI);
3993 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3994 isp_prt(isp, ISP_LOGERR, sacq);
3997 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
3998 MBSINIT(&mbs, MBOX_SEND_SNS, MBLOGALL, 1000000);
3999 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
4000 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
4001 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
4002 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
4003 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
4004 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_RFT_ID_REQ_SIZE, chan);
4005 isp_mboxcmd(isp, &mbs);
4006 FC_SCRATCH_RELEASE(isp, chan);
4007 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
4010 isp_prt(isp, ISP_LOGWARN, "Chan %d Register FC4 Type: 0x%x",
4011 chan, mbs.param[0]);
4017 isp_register_fc4_type_24xx(ispsoftc_t *isp, int chan)
4019 fcparam *fcp = FCPARAM(isp, chan);
4022 uint8_t *scp = fcp->isp_scratch;
4024 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4025 isp_prt(isp, ISP_LOGERR, sacq);
4030 * Build the CT header and command in memory.
4032 ISP_MEMZERO(&rp, sizeof(rp));
4034 ct->ct_revision = CT_REVISION;
4035 ct->ct_fcs_type = CT_FC_TYPE_FC;
4036 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
4037 ct->ct_cmd_resp = SNS_RFT_ID;
4038 ct->ct_bcnt_resid = (sizeof (rft_id_t) - sizeof (ct_hdr_t)) >> 2;
4039 rp.rftid_portid[0] = fcp->isp_portid >> 16;
4040 rp.rftid_portid[1] = fcp->isp_portid >> 8;
4041 rp.rftid_portid[2] = fcp->isp_portid;
4042 rp.rftid_fc4types[FC4_SCSI >> 5] = 1 << (FC4_SCSI & 0x1f);
4043 isp_put_rft_id(isp, &rp, (rft_id_t *)scp);
4044 if (isp->isp_dblev & ISP_LOGDEBUG1)
4045 isp_print_bytes(isp, "CT request", sizeof(rft_id_t), scp);
4047 if (isp_ct_passthru(isp, chan, sizeof(rft_id_t), sizeof(ct_hdr_t))) {
4048 FC_SCRATCH_RELEASE(isp, chan);
4052 isp_get_ct_hdr(isp, (ct_hdr_t *) scp, ct);
4053 FC_SCRATCH_RELEASE(isp, chan);
4054 if (ct->ct_cmd_resp == LS_RJT) {
4055 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "Chan %d Register FC4 Type rejected", chan);
4057 } else if (ct->ct_cmd_resp == LS_ACC) {
4058 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Register FC4 Type accepted", chan);
4060 isp_prt(isp, ISP_LOGWARN, "Chan %d Register FC4 Type: 0x%x", chan, ct->ct_cmd_resp);
4067 isp_register_fc4_features_24xx(ispsoftc_t *isp, int chan)
4069 fcparam *fcp = FCPARAM(isp, chan);
4072 uint8_t *scp = fcp->isp_scratch;
4074 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4075 isp_prt(isp, ISP_LOGERR, sacq);
4080 * Build the CT header and command in memory.
4082 ISP_MEMZERO(&rp, sizeof(rp));
4084 ct->ct_revision = CT_REVISION;
4085 ct->ct_fcs_type = CT_FC_TYPE_FC;
4086 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
4087 ct->ct_cmd_resp = SNS_RFF_ID;
4088 ct->ct_bcnt_resid = (sizeof (rff_id_t) - sizeof (ct_hdr_t)) >> 2;
4089 rp.rffid_portid[0] = fcp->isp_portid >> 16;
4090 rp.rffid_portid[1] = fcp->isp_portid >> 8;
4091 rp.rffid_portid[2] = fcp->isp_portid;
4092 rp.rffid_fc4features = 0;
4093 if (fcp->role & ISP_ROLE_TARGET)
4094 rp.rffid_fc4features |= 1;
4095 if (fcp->role & ISP_ROLE_INITIATOR)
4096 rp.rffid_fc4features |= 2;
4097 rp.rffid_fc4type = FC4_SCSI;
4098 isp_put_rff_id(isp, &rp, (rff_id_t *)scp);
4099 if (isp->isp_dblev & ISP_LOGDEBUG1)
4100 isp_print_bytes(isp, "CT request", sizeof(rft_id_t), scp);
4102 if (isp_ct_passthru(isp, chan, sizeof(rft_id_t), sizeof(ct_hdr_t))) {
4103 FC_SCRATCH_RELEASE(isp, chan);
4107 isp_get_ct_hdr(isp, (ct_hdr_t *) scp, ct);
4108 FC_SCRATCH_RELEASE(isp, chan);
4109 if (ct->ct_cmd_resp == LS_RJT) {
4110 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1,
4111 "Chan %d Register FC4 Features rejected", chan);
4113 } else if (ct->ct_cmd_resp == LS_ACC) {
4114 isp_prt(isp, ISP_LOG_SANCFG,
4115 "Chan %d Register FC4 Features accepted", chan);
4117 isp_prt(isp, ISP_LOGWARN,
4118 "Chan %d Register FC4 Features: 0x%x", chan, ct->ct_cmd_resp);
4125 isp_register_port_name_24xx(ispsoftc_t *isp, int chan)
4127 fcparam *fcp = FCPARAM(isp, chan);
4130 uint8_t *scp = fcp->isp_scratch;
4133 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4134 isp_prt(isp, ISP_LOGERR, sacq);
4139 * Build the CT header and command in memory.
4141 ISP_MEMZERO(&rp, sizeof(rp));
4142 ct = &rp.rspnid_hdr;
4143 ct->ct_revision = CT_REVISION;
4144 ct->ct_fcs_type = CT_FC_TYPE_FC;
4145 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
4146 ct->ct_cmd_resp = SNS_RSPN_ID;
4147 rp.rspnid_portid[0] = fcp->isp_portid >> 16;
4148 rp.rspnid_portid[1] = fcp->isp_portid >> 8;
4149 rp.rspnid_portid[2] = fcp->isp_portid;
4150 rp.rspnid_length = 0;
4151 len = offsetof(rspn_id_t, rspnid_name);
4152 mtx_lock(&prison0.pr_mtx);
4153 rp.rspnid_length += sprintf(&scp[len + rp.rspnid_length],
4154 "%s", prison0.pr_hostname[0] ? prison0.pr_hostname : "FreeBSD");
4155 mtx_unlock(&prison0.pr_mtx);
4156 rp.rspnid_length += sprintf(&scp[len + rp.rspnid_length],
4157 ":%s", device_get_nameunit(isp->isp_dev));
4159 rp.rspnid_length += sprintf(&scp[len + rp.rspnid_length],
4162 len += rp.rspnid_length;
4163 ct->ct_bcnt_resid = (len - sizeof(ct_hdr_t)) >> 2;
4164 isp_put_rspn_id(isp, &rp, (rspn_id_t *)scp);
4165 if (isp->isp_dblev & ISP_LOGDEBUG1)
4166 isp_print_bytes(isp, "CT request", len, scp);
4168 if (isp_ct_passthru(isp, chan, len, sizeof(ct_hdr_t))) {
4169 FC_SCRATCH_RELEASE(isp, chan);
4173 isp_get_ct_hdr(isp, (ct_hdr_t *) scp, ct);
4174 FC_SCRATCH_RELEASE(isp, chan);
4175 if (ct->ct_cmd_resp == LS_RJT) {
4176 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1,
4177 "Chan %d Register Symbolic Port Name rejected", chan);
4179 } else if (ct->ct_cmd_resp == LS_ACC) {
4180 isp_prt(isp, ISP_LOG_SANCFG,
4181 "Chan %d Register Symbolic Port Name accepted", chan);
4183 isp_prt(isp, ISP_LOGWARN,
4184 "Chan %d Register Symbolic Port Name: 0x%x", chan, ct->ct_cmd_resp);
4191 isp_register_node_name_24xx(ispsoftc_t *isp, int chan)
4193 fcparam *fcp = FCPARAM(isp, chan);
4196 uint8_t *scp = fcp->isp_scratch;
4199 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4200 isp_prt(isp, ISP_LOGERR, sacq);
4205 * Build the CT header and command in memory.
4207 ISP_MEMZERO(&rp, sizeof(rp));
4208 ct = &rp.rsnnnn_hdr;
4209 ct->ct_revision = CT_REVISION;
4210 ct->ct_fcs_type = CT_FC_TYPE_FC;
4211 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
4212 ct->ct_cmd_resp = SNS_RSNN_NN;
4213 MAKE_NODE_NAME_FROM_WWN(rp.rsnnnn_nodename, fcp->isp_wwnn);
4214 rp.rsnnnn_length = 0;
4215 len = offsetof(rsnn_nn_t, rsnnnn_name);
4216 mtx_lock(&prison0.pr_mtx);
4217 rp.rsnnnn_length += sprintf(&scp[len + rp.rsnnnn_length],
4218 "%s", prison0.pr_hostname[0] ? prison0.pr_hostname : "FreeBSD");
4219 mtx_unlock(&prison0.pr_mtx);
4220 len += rp.rsnnnn_length;
4221 ct->ct_bcnt_resid = (len - sizeof(ct_hdr_t)) >> 2;
4222 isp_put_rsnn_nn(isp, &rp, (rsnn_nn_t *)scp);
4223 if (isp->isp_dblev & ISP_LOGDEBUG1)
4224 isp_print_bytes(isp, "CT request", len, scp);
4226 if (isp_ct_passthru(isp, chan, len, sizeof(ct_hdr_t))) {
4227 FC_SCRATCH_RELEASE(isp, chan);
4231 isp_get_ct_hdr(isp, (ct_hdr_t *) scp, ct);
4232 FC_SCRATCH_RELEASE(isp, chan);
4233 if (ct->ct_cmd_resp == LS_RJT) {
4234 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1,
4235 "Chan %d Register Symbolic Node Name rejected", chan);
4237 } else if (ct->ct_cmd_resp == LS_ACC) {
4238 isp_prt(isp, ISP_LOG_SANCFG,
4239 "Chan %d Register Symbolic Node Name accepted", chan);
4241 isp_prt(isp, ISP_LOGWARN,
4242 "Chan %d Register Symbolic Node Name: 0x%x", chan, ct->ct_cmd_resp);
4249 isp_next_handle(ispsoftc_t *isp, uint16_t *ohp)
4253 uint16_t handle, minh, maxh;
4256 if (ISP_CAP_2KLOGIN(isp)) {
4258 maxh = NPH_RESERVED - 1;
4266 if (handle == NIL_HANDLE) {
4270 if (handle > maxh) {
4272 isp_prt(isp, ISP_LOGERR, "Out of port handles!");
4273 return (NIL_HANDLE);
4278 for (chan = 0; chan < isp->isp_nchan; chan++) {
4279 fcp = FCPARAM(isp, chan);
4280 if (fcp->role == ISP_ROLE_NONE)
4282 for (i = 0; i < MAX_FC_TARG; i++) {
4283 if (fcp->portdb[i].state != FC_PORTDB_STATE_NIL &&
4284 fcp->portdb[i].handle == handle)
4293 * Start a command. Locking is assumed done in the caller.
4301 uint8_t local[QENTRY_LEN];
4306 int target, dmaresult;
4312 * Check command CDB length, etc.. We really are limited to 16 bytes
4313 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
4314 * but probably only if we're running fairly new firmware (we'll
4315 * let the old f/w choke on an extended command queue entry).
4318 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
4319 isp_prt(isp, ISP_LOGERR, "unsupported cdb length (%d, CDB[0]=0x%x)", XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
4320 XS_SETERR(xs, HBA_REQINVAL);
4321 return (CMD_COMPLETE);
4325 * Translate the target to device handle as appropriate, checking
4326 * for correct device state as well.
4328 target = XS_TGT(xs);
4330 fcparam *fcp = FCPARAM(isp, XS_CHANNEL(xs));
4332 if ((fcp->role & ISP_ROLE_INITIATOR) == 0) {
4333 isp_prt(isp, ISP_LOG_WARN1,
4334 "%d.%d.%jx I am not an initiator",
4335 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4336 XS_SETERR(xs, HBA_SELTIMEOUT);
4337 return (CMD_COMPLETE);
4340 if (isp->isp_state != ISP_RUNSTATE) {
4341 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
4342 XS_SETERR(xs, HBA_BOTCH);
4343 return (CMD_COMPLETE);
4349 if (fcp->isp_loopstate != LOOP_READY) {
4350 return (CMD_RQLATER);
4353 isp_prt(isp, ISP_LOGDEBUG2, "XS_TGT(xs)=%d", target);
4354 lp = &fcp->portdb[target];
4355 if (target < 0 || target >= MAX_FC_TARG ||
4356 lp->is_target == 0) {
4357 XS_SETERR(xs, HBA_SELTIMEOUT);
4358 return (CMD_COMPLETE);
4360 if (lp->state == FC_PORTDB_STATE_ZOMBIE) {
4361 isp_prt(isp, ISP_LOGDEBUG1,
4362 "%d.%d.%jx target zombie",
4363 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4364 return (CMD_RQLATER);
4366 if (lp->state != FC_PORTDB_STATE_VALID) {
4367 isp_prt(isp, ISP_LOGDEBUG1,
4368 "%d.%d.%jx bad db port state 0x%x",
4369 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs), lp->state);
4370 XS_SETERR(xs, HBA_SELTIMEOUT);
4371 return (CMD_COMPLETE);
4374 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
4375 if (isp->isp_state != ISP_RUNSTATE) {
4376 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
4377 XS_SETERR(xs, HBA_BOTCH);
4378 return (CMD_COMPLETE);
4382 isp_spi_update(isp, XS_CHANNEL(xs));
4389 qep = isp_getrqentry(isp);
4391 isp_prt(isp, ISP_LOG_WARN1, "Request Queue Overflow");
4392 XS_SETERR(xs, HBA_BOTCH);
4393 return (CMD_EAGAIN);
4395 XS_SETERR(xs, HBA_NOERROR);
4398 * Now see if we need to synchronize the ISP with respect to anything.
4399 * We do dual duty here (cough) for synchronizing for busses other
4400 * than which we got here to send a command to.
4402 reqp = (ispreq_t *) local;
4403 ISP_MEMZERO(local, QENTRY_LEN);
4404 if (ISP_TST_SENDMARKER(isp, XS_CHANNEL(xs))) {
4406 isp_marker_24xx_t *m = (isp_marker_24xx_t *) reqp;
4407 m->mrk_header.rqs_entry_count = 1;
4408 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4409 m->mrk_modifier = SYNC_ALL;
4410 m->mrk_vphdl = XS_CHANNEL(xs);
4411 isp_put_marker_24xx(isp, m, qep);
4413 isp_marker_t *m = (isp_marker_t *) reqp;
4414 m->mrk_header.rqs_entry_count = 1;
4415 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4416 m->mrk_target = (XS_CHANNEL(xs) << 7); /* bus # */
4417 m->mrk_modifier = SYNC_ALL;
4418 isp_put_marker(isp, m, qep);
4420 ISP_SYNC_REQUEST(isp);
4421 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 0);
4425 reqp->req_header.rqs_entry_count = 1;
4428 * Select and install Header Code.
4429 * Note that it might be overridden before going out
4430 * if we're on a 64 bit platform. The lower level
4431 * code (isp_send_cmd) will select the appropriate
4432 * 64 bit variant if it needs to.
4435 reqp->req_header.rqs_entry_type = RQSTYPE_T7RQS;
4436 } else if (IS_FC(isp)) {
4437 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
4439 if (XS_CDBLEN(xs) > 12) {
4440 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
4442 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
4447 * Set task attributes
4452 ttype = XS_TAG_TYPE(xs);
4454 ttype = REQFLAG_STAG;
4456 if (ttype == REQFLAG_OTAG) {
4457 ttype = FCP_CMND_TASK_ATTR_ORDERED;
4458 } else if (ttype == REQFLAG_HTAG) {
4459 ttype = FCP_CMND_TASK_ATTR_HEAD;
4461 ttype = FCP_CMND_TASK_ATTR_SIMPLE;
4463 ((ispreqt7_t *)reqp)->req_task_attribute = ttype;
4464 } else if (IS_FC(isp)) {
4466 * See comment in isp_intr
4468 /* XS_SET_RESID(xs, 0); */
4471 * Fibre Channel always requires some kind of tag.
4472 * The Qlogic drivers seem be happy not to use a tag,
4473 * but this breaks for some devices (IBM drives).
4476 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
4478 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
4481 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
4482 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) && XS_TAG_P(xs)) {
4483 reqp->req_flags = XS_TAG_TYPE(xs);
4487 tptr = &reqp->req_time;
4490 * NB: we do not support long CDBs (yet)
4492 cdblen = XS_CDBLEN(xs);
4495 if (cdblen > sizeof (reqp->req_cdb)) {
4496 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4497 XS_SETERR(xs, HBA_REQINVAL);
4498 return (CMD_COMPLETE);
4500 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
4501 reqp->req_lun_trn = XS_LUN(xs);
4502 cdbp = reqp->req_cdb;
4503 reqp->req_cdblen = cdblen;
4504 } else if (IS_24XX(isp)) {
4505 ispreqt7_t *t7 = (ispreqt7_t *)local;
4507 if (cdblen > sizeof (t7->req_cdb)) {
4508 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4509 XS_SETERR(xs, HBA_REQINVAL);
4510 return (CMD_COMPLETE);
4513 t7->req_nphdl = lp->handle;
4514 t7->req_tidlo = lp->portid;
4515 t7->req_tidhi = lp->portid >> 16;
4516 t7->req_vpidx = ISP_GET_VPIDX(isp, XS_CHANNEL(xs));
4517 be64enc(t7->req_lun, CAM_EXTLUN_BYTE_SWIZZLE(XS_LUN(xs)));
4518 if (FCPARAM(isp, XS_CHANNEL(xs))->fctape_enabled && (lp->prli_word3 & PRLI_WD3_RETRY)) {
4519 if (FCP_NEXT_CRN(isp, &t7->req_crn, xs)) {
4520 isp_prt(isp, ISP_LOG_WARN1,
4521 "%d.%d.%jx cannot generate next CRN",
4522 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4523 XS_SETERR(xs, HBA_BOTCH);
4524 return (CMD_EAGAIN);
4527 tptr = &t7->req_time;
4530 ispreqt2_t *t2 = (ispreqt2_t *)local;
4532 if (cdblen > sizeof t2->req_cdb) {
4533 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4534 XS_SETERR(xs, HBA_REQINVAL);
4535 return (CMD_COMPLETE);
4537 if (FCPARAM(isp, XS_CHANNEL(xs))->fctape_enabled && (lp->prli_word3 & PRLI_WD3_RETRY)) {
4538 if (FCP_NEXT_CRN(isp, &t2->req_crn, xs)) {
4539 isp_prt(isp, ISP_LOG_WARN1,
4540 "%d.%d.%jx cannot generate next CRN",
4541 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4542 XS_SETERR(xs, HBA_BOTCH);
4543 return (CMD_EAGAIN);
4546 if (ISP_CAP_2KLOGIN(isp)) {
4547 ispreqt2e_t *t2e = (ispreqt2e_t *)local;
4548 t2e->req_target = lp->handle;
4549 t2e->req_scclun = XS_LUN(xs);
4550 cdbp = t2e->req_cdb;
4551 } else if (ISP_CAP_SCCFW(isp)) {
4552 ispreqt2_t *t2 = (ispreqt2_t *)local;
4553 t2->req_target = lp->handle;
4554 t2->req_scclun = XS_LUN(xs);
4557 t2->req_target = lp->handle;
4558 t2->req_lun_trn = XS_LUN(xs);
4562 ISP_MEMCPY(cdbp, XS_CDBP(xs), cdblen);
4564 *tptr = (XS_TIME(xs) + 999) / 1000;
4565 if (IS_24XX(isp) && *tptr > 0x1999) {
4569 /* Whew. Thankfully the same for type 7 requests */
4570 reqp->req_handle = isp_allocate_handle(isp, xs, ISP_HANDLE_INITIATOR);
4571 if (reqp->req_handle == 0) {
4572 isp_prt(isp, ISP_LOG_WARN1, "out of xflist pointers");
4573 XS_SETERR(xs, HBA_BOTCH);
4574 return (CMD_EAGAIN);
4578 * Set up DMA and/or do any platform dependent swizzling of the request entry
4579 * so that the Qlogic F/W understands what is being asked of it.
4581 * The callee is responsible for adding all requests at this point.
4583 dmaresult = ISP_DMASETUP(isp, xs, reqp);
4584 if (dmaresult != CMD_QUEUED) {
4585 isp_destroy_handle(isp, reqp->req_handle);
4587 * dmasetup sets actual error in packet, and
4588 * return what we were given to return.
4592 isp_xs_prt(isp, xs, ISP_LOGDEBUG0, "START cmd cdb[0]=0x%x datalen %ld", XS_CDBP(xs)[0], (long) XS_XFRLEN(xs));
4594 return (CMD_QUEUED);
4599 * Locks (ints blocked) assumed held.
4603 isp_control(ispsoftc_t *isp, ispctl_t ctl, ...)
4612 case ISPCTL_RESET_BUS:
4614 * Issue a bus reset.
4617 isp_prt(isp, ISP_LOGERR, "BUS RESET NOT IMPLEMENTED");
4619 } else if (IS_FC(isp)) {
4624 chan = va_arg(ap, int);
4626 mbs.param[1] = SDPARAM(isp, chan)->isp_bus_reset_delay;
4627 if (mbs.param[1] < 2) {
4630 mbs.param[2] = chan;
4632 MBSINIT(&mbs, MBOX_BUS_RESET, MBLOGALL, 0);
4633 ISP_SET_SENDMARKER(isp, chan, 1);
4634 isp_mboxcmd(isp, &mbs);
4635 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4638 isp_prt(isp, ISP_LOGINFO, "driver initiated bus reset of bus %d", chan);
4641 case ISPCTL_RESET_DEV:
4643 chan = va_arg(ap, int);
4644 tgt = va_arg(ap, int);
4647 uint8_t local[QENTRY_LEN];
4649 isp24xx_statusreq_t *sp;
4650 fcparam *fcp = FCPARAM(isp, chan);
4653 if (tgt < 0 || tgt >= MAX_FC_TARG) {
4654 isp_prt(isp, ISP_LOGWARN, "Chan %d trying to reset bad target %d", chan, tgt);
4657 lp = &fcp->portdb[tgt];
4658 if (lp->is_target == 0 ||
4659 lp->state != FC_PORTDB_STATE_VALID) {
4660 isp_prt(isp, ISP_LOGWARN, "Chan %d abort of no longer valid target %d", chan, tgt);
4664 tmf = (isp24xx_tmf_t *) local;
4665 ISP_MEMZERO(tmf, QENTRY_LEN);
4666 tmf->tmf_header.rqs_entry_type = RQSTYPE_TSK_MGMT;
4667 tmf->tmf_header.rqs_entry_count = 1;
4668 tmf->tmf_nphdl = lp->handle;
4670 tmf->tmf_timeout = 4;
4671 tmf->tmf_flags = ISP24XX_TMF_TARGET_RESET;
4672 tmf->tmf_tidlo = lp->portid;
4673 tmf->tmf_tidhi = lp->portid >> 16;
4674 tmf->tmf_vpidx = ISP_GET_VPIDX(isp, chan);
4675 isp_put_24xx_tmf(isp, tmf, isp->isp_iocb);
4676 if (isp->isp_dblev & ISP_LOGDEBUG1)
4677 isp_print_bytes(isp, "TMF IOCB request", QENTRY_LEN, isp->isp_iocb);
4678 MEMORYBARRIER(isp, SYNC_IFORDEV, 0, QENTRY_LEN, chan);
4679 fcp->sendmarker = 1;
4681 isp_prt(isp, ISP_LOGALL, "Chan %d Reset N-Port Handle 0x%04x @ Port 0x%06x", chan, lp->handle, lp->portid);
4682 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL,
4683 MBCMD_DEFAULT_TIMEOUT + tmf->tmf_timeout * 1000000);
4684 mbs.param[1] = QENTRY_LEN;
4685 mbs.param[2] = DMA_WD1(isp->isp_iocb_dma);
4686 mbs.param[3] = DMA_WD0(isp->isp_iocb_dma);
4687 mbs.param[6] = DMA_WD3(isp->isp_iocb_dma);
4688 mbs.param[7] = DMA_WD2(isp->isp_iocb_dma);
4689 isp_mboxcmd(isp, &mbs);
4690 if (mbs.param[0] != MBOX_COMMAND_COMPLETE)
4693 MEMORYBARRIER(isp, SYNC_IFORCPU, QENTRY_LEN, QENTRY_LEN, chan);
4694 if (isp->isp_dblev & ISP_LOGDEBUG1)
4695 isp_print_bytes(isp, "TMF IOCB response", QENTRY_LEN, &((isp24xx_statusreq_t *)isp->isp_iocb)[1]);
4696 sp = (isp24xx_statusreq_t *) local;
4697 isp_get_24xx_response(isp, &((isp24xx_statusreq_t *)isp->isp_iocb)[1], sp);
4698 if (sp->req_completion_status == 0) {
4701 isp_prt(isp, ISP_LOGWARN, "Chan %d reset of target %d returned 0x%x", chan, tgt, sp->req_completion_status);
4703 } else if (IS_FC(isp)) {
4704 if (ISP_CAP_2KLOGIN(isp)) {
4706 mbs.ibits = (1 << 10);
4708 mbs.param[1] = (tgt << 8);
4711 mbs.param[1] = (chan << 15) | (tgt << 8);
4713 MBSINIT(&mbs, MBOX_ABORT_TARGET, MBLOGALL, 0);
4714 mbs.param[2] = 3; /* 'delay', in seconds */
4715 isp_mboxcmd(isp, &mbs);
4716 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4719 isp_prt(isp, ISP_LOGINFO, "Target %d on Bus %d Reset Succeeded", tgt, chan);
4720 ISP_SET_SENDMARKER(isp, chan, 1);
4723 case ISPCTL_ABORT_CMD:
4725 xs = va_arg(ap, XS_T *);
4729 chan = XS_CHANNEL(xs);
4731 handle = isp_find_handle(isp, xs);
4733 isp_prt(isp, ISP_LOGWARN, "cannot find handle for command to abort");
4737 isp24xx_abrt_t local, *ab = &local;
4741 fcp = FCPARAM(isp, chan);
4742 if (tgt < 0 || tgt >= MAX_FC_TARG) {
4743 isp_prt(isp, ISP_LOGWARN, "Chan %d trying to abort bad target %d", chan, tgt);
4746 lp = &fcp->portdb[tgt];
4747 if (lp->is_target == 0 ||
4748 lp->state != FC_PORTDB_STATE_VALID) {
4749 isp_prt(isp, ISP_LOGWARN, "Chan %d abort of no longer valid target %d", chan, tgt);
4752 isp_prt(isp, ISP_LOGALL, "Chan %d Abort Cmd for N-Port 0x%04x @ Port 0x%06x", chan, lp->handle, lp->portid);
4753 ISP_MEMZERO(ab, QENTRY_LEN);
4754 ab->abrt_header.rqs_entry_type = RQSTYPE_ABORT_IO;
4755 ab->abrt_header.rqs_entry_count = 1;
4756 ab->abrt_handle = lp->handle;
4757 ab->abrt_cmd_handle = handle;
4758 ab->abrt_tidlo = lp->portid;
4759 ab->abrt_tidhi = lp->portid >> 16;
4760 ab->abrt_vpidx = ISP_GET_VPIDX(isp, chan);
4761 isp_put_24xx_abrt(isp, ab, isp->isp_iocb);
4762 if (isp->isp_dblev & ISP_LOGDEBUG1)
4763 isp_print_bytes(isp, "AB IOCB quest", QENTRY_LEN, isp->isp_iocb);
4764 MEMORYBARRIER(isp, SYNC_IFORDEV, 0, 2 * QENTRY_LEN, chan);
4766 ISP_MEMZERO(&mbs, sizeof (mbs));
4767 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 5000000);
4768 mbs.param[1] = QENTRY_LEN;
4769 mbs.param[2] = DMA_WD1(isp->isp_iocb_dma);
4770 mbs.param[3] = DMA_WD0(isp->isp_iocb_dma);
4771 mbs.param[6] = DMA_WD3(isp->isp_iocb_dma);
4772 mbs.param[7] = DMA_WD2(isp->isp_iocb_dma);
4774 isp_mboxcmd(isp, &mbs);
4775 if (mbs.param[0] != MBOX_COMMAND_COMPLETE)
4778 MEMORYBARRIER(isp, SYNC_IFORCPU, QENTRY_LEN, QENTRY_LEN, chan);
4779 if (isp->isp_dblev & ISP_LOGDEBUG1)
4780 isp_print_bytes(isp, "AB IOCB response", QENTRY_LEN, &((isp24xx_abrt_t *)isp->isp_iocb)[1]);
4781 isp_get_24xx_abrt(isp, &((isp24xx_abrt_t *)isp->isp_iocb)[1], ab);
4782 if (ab->abrt_nphdl == ISP24XX_ABRT_OKAY) {
4785 isp_prt(isp, ISP_LOGWARN, "Chan %d handle %d abort returned 0x%x", chan, tgt, ab->abrt_nphdl);
4787 } else if (IS_FC(isp)) {
4788 if (ISP_CAP_SCCFW(isp)) {
4789 if (ISP_CAP_2KLOGIN(isp)) {
4792 mbs.param[1] = tgt << 8;
4794 mbs.param[6] = XS_LUN(xs);
4796 mbs.param[1] = tgt << 8 | XS_LUN(xs);
4799 mbs.param[1] = (chan << 15) | (tgt << 8) | XS_LUN(xs);
4801 MBSINIT(&mbs, MBOX_ABORT,
4802 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_ERROR), 0);
4803 mbs.param[2] = handle;
4804 isp_mboxcmd(isp, &mbs);
4805 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4810 case ISPCTL_UPDATE_PARAMS:
4813 chan = va_arg(ap, int);
4815 isp_spi_update(isp, chan);
4818 case ISPCTL_FCLINK_TEST:
4823 chan = va_arg(ap, int);
4824 usdelay = va_arg(ap, int);
4829 return (isp_fclink_test(isp, chan, usdelay));
4833 case ISPCTL_SCAN_FABRIC:
4837 chan = va_arg(ap, int);
4839 return (isp_scan_fabric(isp, chan));
4843 case ISPCTL_SCAN_LOOP:
4847 chan = va_arg(ap, int);
4849 return (isp_scan_loop(isp, chan));
4853 case ISPCTL_PDB_SYNC:
4857 chan = va_arg(ap, int);
4859 return (isp_pdb_sync(isp, chan));
4863 case ISPCTL_SEND_LIP:
4865 if (IS_FC(isp) && !IS_24XX(isp)) {
4866 MBSINIT(&mbs, MBOX_INIT_LIP, MBLOGALL, 0);
4867 if (ISP_CAP_2KLOGIN(isp)) {
4868 mbs.ibits = (1 << 10);
4870 isp_mboxcmd(isp, &mbs);
4871 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
4877 case ISPCTL_GET_PDB:
4881 chan = va_arg(ap, int);
4882 tgt = va_arg(ap, int);
4883 pdb = va_arg(ap, isp_pdb_t *);
4885 return (isp_getpdb(isp, chan, tgt, pdb));
4889 case ISPCTL_GET_NAMES:
4891 uint64_t *wwnn, *wwnp;
4893 chan = va_arg(ap, int);
4894 tgt = va_arg(ap, int);
4895 wwnn = va_arg(ap, uint64_t *);
4896 wwnp = va_arg(ap, uint64_t *);
4898 if (wwnn == NULL && wwnp == NULL) {
4902 *wwnn = isp_get_wwn(isp, chan, tgt, 1);
4903 if (*wwnn == INI_NONE) {
4908 *wwnp = isp_get_wwn(isp, chan, tgt, 0);
4909 if (*wwnp == INI_NONE) {
4915 case ISPCTL_RUN_MBOXCMD:
4918 mbr = va_arg(ap, mbreg_t *);
4920 isp_mboxcmd(isp, mbr);
4929 p = va_arg(ap, isp_plcmd_t *);
4932 if ((p->flags & PLOGX_FLG_CMD_MASK) != PLOGX_FLG_CMD_PLOGI || (p->handle != NIL_HANDLE)) {
4933 return (isp_plogx(isp, p->channel, p->handle, p->portid, p->flags));
4936 isp_next_handle(isp, &p->handle);
4937 r = isp_plogx(isp, p->channel, p->handle, p->portid, p->flags);
4938 if ((r & 0xffff) == MBOX_PORT_ID_USED) {
4939 p->handle = r >> 16;
4943 } while ((r & 0xffff) == MBOX_LOOP_ID_USED);
4946 case ISPCTL_CHANGE_ROLE:
4951 chan = va_arg(ap, int);
4952 role = va_arg(ap, int);
4954 r = isp_fc_change_role(isp, chan, role);
4959 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
4967 * Interrupt Service Routine(s).
4969 * External (OS) framework has done the appropriate locking,
4970 * and the locking will be held throughout this function.
4974 * Limit our stack depth by sticking with the max likely number
4975 * of completions on a request queue at any one time.
4977 #ifndef MAX_REQUESTQ_COMPLETIONS
4978 #define MAX_REQUESTQ_COMPLETIONS 32
4982 isp_intr(ispsoftc_t *isp, uint16_t isr, uint16_t sema, uint16_t info)
4984 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
4985 uint32_t iptr, optr, junk;
4986 int i, nlooked = 0, ndone = 0, continuations_expected = 0;
4987 int etype, last_etype = 0;
4991 * Is this a mailbox related interrupt?
4992 * The mailbox semaphore will be nonzero if so.
4996 if (info & MBOX_COMMAND_COMPLETE) {
4997 isp->isp_intmboxc++;
4998 if (isp->isp_mboxbsy) {
4999 int obits = isp->isp_obits;
5000 isp->isp_mboxtmp[0] = info;
5001 for (i = 1; i < ISP_NMBOX(isp); i++) {
5002 if ((obits & (1 << i)) == 0) {
5005 isp->isp_mboxtmp[i] = ISP_READ(isp, MBOX_OFF(i));
5007 if (isp->isp_mbxwrk0) {
5008 if (isp_mbox_continue(isp) == 0) {
5012 MBOX_NOTIFY_COMPLETE(isp);
5014 isp_prt(isp, ISP_LOGWARN, "mailbox cmd (0x%x) with no waiters", info);
5017 i = IS_FC(isp)? isp_parse_async_fc(isp, info) : isp_parse_async(isp, info);
5022 if ((IS_FC(isp) && info != ASYNC_RIOZIO_STALL) || isp->isp_state != ISP_RUNSTATE) {
5028 * We can't be getting this now.
5030 if (isp->isp_state != ISP_RUNSTATE) {
5032 * This seems to happen to 23XX and 24XX cards- don't know why.
5034 if (isp->isp_mboxbsy && isp->isp_lastmbxcmd == MBOX_ABOUT_FIRMWARE) {
5037 isp_prt(isp, ISP_LOGINFO, "interrupt (ISR=%x SEMA=%x INFO=%x) "
5038 "when not ready", isr, sema, info);
5040 * Thank you very much! *Burrrp*!
5042 isp->isp_residx = ISP_READ(isp, isp->isp_respinrp);
5043 isp->isp_resodx = isp->isp_residx;
5044 ISP_WRITE(isp, isp->isp_respoutrp, isp->isp_resodx);
5046 ISP_DISABLE_INTS(isp);
5051 #ifdef ISP_TARGET_MODE
5053 * Check for ATIO Queue entries.
5056 (isr == ISPR2HST_ATIO_UPDATE || isr == ISPR2HST_ATIO_RSPQ_UPDATE ||
5057 isr == ISPR2HST_ATIO_UPDATE2)) {
5058 iptr = ISP_READ(isp, BIU2400_ATIO_RSPINP);
5059 optr = isp->isp_atioodx;
5061 while (optr != iptr) {
5062 uint8_t qe[QENTRY_LEN];
5068 MEMORYBARRIER(isp, SYNC_ATIOQ, oop, QENTRY_LEN, -1);
5069 addr = ISP_QUEUE_ENTRY(isp->isp_atioq, oop);
5070 isp_get_hdr(isp, addr, (isphdr_t *)qe);
5071 hp = (isphdr_t *)qe;
5072 switch (hp->rqs_entry_type) {
5073 case RQSTYPE_NOTIFY:
5075 (void) isp_target_notify(isp, addr, &oop);
5078 isp_print_qentry(isp, "?ATIOQ entry?", oop, addr);
5081 optr = ISP_NXT_QENTRY(oop, RESULT_QUEUE_LEN(isp));
5083 if (isp->isp_atioodx != optr) {
5084 ISP_WRITE(isp, BIU2400_ATIO_RSPOUTP, optr);
5085 isp->isp_atioodx = optr;
5091 * You *must* read the Response Queue In Pointer
5092 * prior to clearing the RISC interrupt.
5094 * Debounce the 2300 if revision less than 2.
5096 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
5099 iptr = ISP_READ(isp, isp->isp_respinrp);
5100 junk = ISP_READ(isp, isp->isp_respinrp);
5101 } while (junk != iptr && ++i < 1000);
5104 isp_prt(isp, ISP_LOGWARN, "Response Queue Out Pointer Unstable (%x, %x)", iptr, junk);
5108 iptr = ISP_READ(isp, isp->isp_respinrp);
5111 optr = isp->isp_resodx;
5112 if (optr == iptr && sema == 0) {
5114 * There are a lot of these- reasons unknown- mostly on
5115 * faster Alpha machines.
5117 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
5118 * make sure the old interrupt went away (to avoid 'ringing'
5119 * effects), but that didn't stop this from occurring.
5123 } else if (IS_23XX(isp)) {
5125 iptr = ISP_READ(isp, isp->isp_respinrp);
5126 junk = ISP_READ(isp, BIU_R2HSTSLO);
5128 junk = ISP_READ(isp, BIU_ISR);
5131 if (IS_23XX(isp) || IS_24XX(isp)) {
5134 sema = ISP_READ(isp, BIU_SEMA);
5135 info = ISP_READ(isp, OUTMAILBOX0);
5136 if ((sema & 0x3) && (info & 0x8000)) {
5140 isp->isp_intbogus++;
5141 isp_prt(isp, ISP_LOGDEBUG1, "bogus intr- isr %x (%x) iptr %x optr %x", isr, junk, iptr, optr);
5144 isp->isp_residx = iptr;
5146 while (optr != iptr) {
5147 uint8_t qe[QENTRY_LEN];
5148 ispstatusreq_t *sp = (ispstatusreq_t *) qe;
5150 int buddaboom, scsi_status, completion_status;
5151 int req_status_flags, req_state_flags;
5152 uint8_t *snsp, *resp;
5153 uint32_t rlen, slen, totslen;
5157 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
5159 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
5162 buddaboom = req_status_flags = req_state_flags = 0;
5166 * Synchronize our view of this response queue entry.
5168 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN, -1);
5169 if (isp->isp_dblev & ISP_LOGDEBUG1)
5170 isp_print_qentry(isp, "Response Queue Entry", oop, hp);
5171 isp_get_hdr(isp, hp, &sp->req_header);
5172 etype = sp->req_header.rqs_entry_type;
5174 if (IS_24XX(isp) && etype == RQSTYPE_RESPONSE) {
5175 isp24xx_statusreq_t *sp2 = (isp24xx_statusreq_t *)qe;
5176 isp_get_24xx_response(isp, (isp24xx_statusreq_t *)hp, sp2);
5177 scsi_status = sp2->req_scsi_status;
5178 completion_status = sp2->req_completion_status;
5179 if ((scsi_status & 0xff) != 0)
5180 req_state_flags = RQSF_GOT_STATUS;
5182 req_state_flags = 0;
5183 resid = sp2->req_resid;
5184 } else if (etype == RQSTYPE_RESPONSE) {
5185 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
5186 scsi_status = sp->req_scsi_status;
5187 completion_status = sp->req_completion_status;
5188 req_status_flags = sp->req_status_flags;
5189 req_state_flags = sp->req_state_flags;
5190 resid = sp->req_resid;
5191 } else if (etype == RQSTYPE_RIO1) {
5192 isp_rio1_t *rio = (isp_rio1_t *) qe;
5193 isp_get_rio1(isp, (isp_rio1_t *) hp, rio);
5194 for (i = 0; i < rio->req_header.rqs_seqno; i++) {
5195 isp_fastpost_complete(isp, rio->req_handles[i]);
5197 if (isp->isp_fpcchiwater < rio->req_header.rqs_seqno) {
5198 isp->isp_fpcchiwater = rio->req_header.rqs_seqno;
5200 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5203 } else if (etype == RQSTYPE_RIO2) {
5204 isp_prt(isp, ISP_LOGERR, "dropping RIO2 response");
5205 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5208 } else if (etype == RQSTYPE_STATUS_CONT) {
5209 isp_get_cont_response(isp, (ispstatus_cont_t *) hp, (ispstatus_cont_t *) sp);
5210 if (last_etype == RQSTYPE_RESPONSE && continuations_expected && ndone > 0 && (xs = complist[ndone-1]) != NULL) {
5211 ispstatus_cont_t *scp = (ispstatus_cont_t *) sp;
5212 XS_SENSE_APPEND(xs, scp->req_sense_data, sizeof (scp->req_sense_data));
5213 isp_prt(isp, ISP_LOGDEBUG0|ISP_LOG_CWARN, "%d more Status Continuations expected", --continuations_expected);
5215 isp_prt(isp, ISP_LOG_WARN1, "Ignored Continuation Response");
5217 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5221 * Somebody reachable via isp_handle_other_response
5222 * may have updated the response queue pointers for
5223 * us, so we reload our goal index.
5226 uint32_t tsto = oop;
5227 r = isp_handle_other_response(isp, etype, hp, &tsto);
5232 * If somebody updated the output pointer, then reset
5233 * optr to be one more than the updated amount.
5235 while (tsto != oop) {
5236 optr = ISP_NXT_QENTRY(tsto, RESULT_QUEUE_LEN(isp));
5239 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5245 * After this point, we'll just look at the header as
5246 * we don't know how to deal with the rest of the
5251 * It really has to be a bounced request just copied
5252 * from the request queue to the response queue. If
5253 * not, something bad has happened.
5255 if (etype != RQSTYPE_REQUEST) {
5256 isp_prt(isp, ISP_LOGERR, notresp, etype, oop, optr, nlooked);
5257 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5262 scsi_status = sp->req_scsi_status;
5263 completion_status = sp->req_completion_status;
5264 req_status_flags = sp->req_status_flags;
5265 req_state_flags = sp->req_state_flags;
5266 resid = sp->req_resid;
5269 if (sp->req_header.rqs_flags & RQSFLAG_MASK) {
5270 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
5271 isp_print_qentry(isp, "unexpected continuation segment",
5276 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
5277 isp_prt(isp, ISP_LOG_WARN1, "internal queues full");
5279 * We'll synthesize a QUEUE FULL message below.
5282 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
5283 isp_print_qentry(isp, "bad header flag",
5287 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
5288 isp_print_qentry(isp, "bad request packet",
5292 if (sp->req_header.rqs_flags & RQSFLAG_BADCOUNT) {
5293 isp_print_qentry(isp, "invalid entry count",
5297 if (sp->req_header.rqs_flags & RQSFLAG_BADORDER) {
5298 isp_print_qentry(isp, "invalid IOCB ordering",
5305 xs = isp_find_xs(isp, sp->req_handle);
5307 uint8_t ts = completion_status & 0xff;
5309 * Only whine if this isn't the expected fallout of
5310 * aborting the command or resetting the target.
5312 if (etype != RQSTYPE_RESPONSE) {
5313 isp_prt(isp, ISP_LOGERR, "cannot find handle 0x%x (type 0x%x)", sp->req_handle, etype);
5314 } else if (ts != RQCS_ABORTED && ts != RQCS_RESET_OCCURRED) {
5315 isp_prt(isp, ISP_LOGERR, "cannot find handle 0x%x (status 0x%x)", sp->req_handle, ts);
5317 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5321 if (req_status_flags & RQSTF_BUS_RESET) {
5322 isp_prt(isp, ISP_LOG_WARN1, "%d.%d.%jx bus was reset",
5323 XS_CHANNEL(xs), XS_TGT(xs), (uintmax_t)XS_LUN(xs));
5324 XS_SETERR(xs, HBA_BUSRESET);
5325 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 1);
5328 isp_prt(isp, ISP_LOG_WARN1, "%d.%d.%jx buddaboom",
5329 XS_CHANNEL(xs), XS_TGT(xs), (uintmax_t)XS_LUN(xs));
5330 XS_SETERR(xs, HBA_BOTCH);
5337 if (IS_24XX(isp) && (scsi_status & (RQCS_RV|RQCS_SV)) != 0) {
5338 resp = ((isp24xx_statusreq_t *)sp)->req_rsp_sense;
5339 rlen = ((isp24xx_statusreq_t *)sp)->req_response_len;
5340 } else if (IS_FC(isp) && (scsi_status & RQCS_RV) != 0) {
5341 resp = sp->req_response;
5342 rlen = sp->req_response_len;
5344 if (IS_FC(isp) && (scsi_status & RQCS_SV) != 0) {
5346 * Fibre Channel F/W doesn't say we got status
5347 * if there's Sense Data instead. I guess they
5348 * think it goes w/o saying.
5350 req_state_flags |= RQSF_GOT_STATUS|RQSF_GOT_SENSE;
5352 snsp = ((isp24xx_statusreq_t *)sp)->req_rsp_sense;
5354 totslen = ((isp24xx_statusreq_t *)sp)->req_sense_len;
5355 slen = (sizeof (((isp24xx_statusreq_t *)sp)->req_rsp_sense)) - rlen;
5359 snsp = sp->req_sense_data;
5360 totslen = sp->req_sense_len;
5361 slen = sizeof (sp->req_sense_data);
5365 } else if (IS_SCSI(isp) && (req_state_flags & RQSF_GOT_SENSE)) {
5366 snsp = sp->req_sense_data;
5367 totslen = sp->req_sense_len;
5368 slen = sizeof (sp->req_sense_data);
5372 if (req_state_flags & RQSF_GOT_STATUS) {
5373 *XS_STSP(xs) = scsi_status & 0xff;
5377 case RQSTYPE_RESPONSE:
5378 if (resp && rlen >= 4 && resp[FCP_RSPNS_CODE_OFFSET] != 0) {
5381 const char *rnames[10] = {
5382 "Task Management function complete",
5383 "FCP_DATA length different than FCP_BURST_LEN",
5384 "FCP_CMND fields invalid",
5385 "FCP_DATA parameter mismatch with FCP_DATA_RO",
5386 "Task Management function rejected",
5387 "Task Management function failed",
5390 "Task Management function succeeded",
5391 "Task Management function incorrect logical unit number",
5393 uint8_t code = resp[FCP_RSPNS_CODE_OFFSET];
5394 if (code >= 10 || rnames[code] == NULL) {
5395 ISP_SNPRINTF(lb, sizeof(lb),
5396 "Unknown FCP Response Code 0x%x",
5402 isp_xs_prt(isp, xs, ISP_LOGWARN,
5403 "FCP RESPONSE, LENGTH %u: %s CDB0=0x%02x",
5404 rlen, ptr, XS_CDBP(xs)[0] & 0xff);
5405 if (code != 0 && code != 8)
5406 XS_SETERR(xs, HBA_BOTCH);
5409 isp_parse_status_24xx(isp, (isp24xx_statusreq_t *)sp, xs, &resid);
5411 isp_parse_status(isp, (void *)sp, xs, &resid);
5413 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) && (*XS_STSP(xs) == SCSI_BUSY)) {
5414 XS_SETERR(xs, HBA_TGTBSY);
5417 XS_SET_RESID(xs, resid);
5419 * A new synchronous rate was negotiated for
5420 * this target. Mark state such that we'll go
5421 * look up that which has changed later.
5423 if (req_status_flags & RQSTF_NEGOTIATION) {
5425 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
5426 sdp->isp_devparam[t].dev_refresh = 1;
5430 if (req_status_flags & RQSF_XFER_COMPLETE) {
5431 XS_SET_RESID(xs, 0);
5432 } else if (scsi_status & RQCS_RESID) {
5433 XS_SET_RESID(xs, resid);
5435 XS_SET_RESID(xs, 0);
5439 if (totslen > slen) {
5440 continuations_expected += ((totslen - slen + QENTRY_LEN - 5) / (QENTRY_LEN - 4));
5441 if (ndone > (MAX_REQUESTQ_COMPLETIONS - continuations_expected - 1)) {
5442 /* we'll lose some stats, but that's a small price to pay */
5443 for (i = 0; i < ndone; i++) {
5445 isp->isp_rsltccmplt++;
5446 isp_done(complist[i]);
5451 isp_prt(isp, ISP_LOGDEBUG0|ISP_LOG_CWARN, "Expecting %d more Status Continuations for total sense length of %u",
5452 continuations_expected, totslen);
5454 XS_SAVE_SENSE(xs, snsp, totslen, slen);
5455 } else if ((req_status_flags & RQSF_GOT_STATUS) && (scsi_status & 0xff) == SCSI_CHECK && IS_FC(isp)) {
5456 isp_prt(isp, ISP_LOGWARN, "CHECK CONDITION w/o sense data for CDB=0x%x", XS_CDBP(xs)[0] & 0xff);
5457 isp_print_qentry(isp, "CC with no Sense",
5460 isp_prt(isp, ISP_LOGDEBUG2, "asked for %ld got raw resid %ld settled for %ld", (long) XS_XFRLEN(xs), resid, (long) XS_GET_RESID(xs));
5462 case RQSTYPE_REQUEST:
5467 if (!IS_24XX(isp) && (sp->req_header.rqs_flags & RQSFLAG_FULL)) {
5469 * Force Queue Full status.
5471 *XS_STSP(xs) = SCSI_QFULL;
5472 XS_SETERR(xs, HBA_NOERROR);
5473 } else if (XS_NOERR(xs)) {
5474 isp_prt(isp, ISP_LOG_WARN1,
5475 "%d.%d.%jx badness at %s:%u",
5476 XS_CHANNEL(xs), XS_TGT(xs),
5477 (uintmax_t)XS_LUN(xs),
5478 __func__, __LINE__);
5479 XS_SETERR(xs, HBA_BOTCH);
5481 XS_SET_RESID(xs, XS_XFRLEN(xs));
5484 isp_print_qentry(isp, "Unhandled Response Type",
5487 XS_SETERR(xs, HBA_BOTCH);
5493 * Free any DMA resources. As a side effect, this may
5494 * also do any cache flushing necessary for data coherence.
5496 if (XS_XFRLEN(xs)) {
5497 ISP_DMAFREE(isp, xs, sp->req_handle);
5499 isp_destroy_handle(isp, sp->req_handle);
5501 if (isp->isp_nactive > 0) {
5504 complist[ndone++] = xs; /* defer completion call until later */
5505 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5507 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
5513 * If we looked at any commands, then it's valid to find out
5514 * what the outpointer is. It also is a trigger to update the
5515 * ISP's notion of what we've seen so far.
5518 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5519 isp->isp_resodx = optr;
5520 if (isp->isp_rscchiwater < ndone)
5521 isp->isp_rscchiwater = ndone;
5527 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
5529 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
5530 ISP_WRITE(isp, BIU_SEMA, 0);
5533 for (i = 0; i < ndone; i++) {
5536 if (((isp->isp_dblev & (ISP_LOGDEBUG1|ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
5537 ((isp->isp_dblev & (ISP_LOGDEBUG0|ISP_LOG_CWARN) && ((!XS_NOERR(xs)) || (*XS_STSP(xs) != SCSI_GOOD))))) {
5538 isp_prt_endcmd(isp, xs);
5540 isp->isp_rsltccmplt++;
5551 isp_prt_endcmd(ispsoftc_t *isp, XS_T *xs)
5553 char cdbstr[16 * 5 + 1];
5556 lim = XS_CDBLEN(xs) > 16? 16 : XS_CDBLEN(xs);
5557 ISP_SNPRINTF(cdbstr, sizeof (cdbstr), "0x%02x ", XS_CDBP(xs)[0]);
5558 for (i = 1; i < lim; i++) {
5559 ISP_SNPRINTF(cdbstr, sizeof (cdbstr), "%s0x%02x ", cdbstr, XS_CDBP(xs)[i]);
5561 if (XS_SENSE_VALID(xs)) {
5562 isp_xs_prt(isp, xs, ISP_LOGALL, "FIN dl%d resid %ld CDB=%s SenseLength=%u/%u KEY/ASC/ASCQ=0x%02x/0x%02x/0x%02x",
5563 XS_XFRLEN(xs), (long) XS_GET_RESID(xs), cdbstr, XS_CUR_SNSLEN(xs), XS_TOT_SNSLEN(xs), XS_SNSKEY(xs), XS_SNSASC(xs), XS_SNSASCQ(xs));
5565 isp_xs_prt(isp, xs, ISP_LOGALL, "FIN dl%d resid %ld CDB=%s STS 0x%x XS_ERR=0x%x", XS_XFRLEN(xs), (long) XS_GET_RESID(xs), cdbstr, *XS_STSP(xs), XS_ERR(xs));
5570 * Parse an ASYNC mailbox complete
5572 * Return non-zero if the event has been acknowledged.
5575 isp_parse_async(ispsoftc_t *isp, uint16_t mbox)
5578 uint32_t h1 = 0, h2 = 0;
5582 * Pick up the channel, but not if this is a ASYNC_RIO32_2,
5583 * where Mailboxes 6/7 have the second handle.
5585 if (mbox != ASYNC_RIO32_2) {
5586 if (IS_DUALBUS(isp)) {
5587 chan = ISP_READ(isp, OUTMAILBOX6);
5590 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
5593 case ASYNC_BUS_RESET:
5594 ISP_SET_SENDMARKER(isp, chan, 1);
5595 #ifdef ISP_TARGET_MODE
5596 if (isp_target_async(isp, chan, mbox)) {
5600 isp_async(isp, ISPASYNC_BUS_RESET, chan);
5602 case ASYNC_SYSTEM_ERROR:
5604 isp->isp_state = ISP_CRASHED;
5606 * Were we waiting for a mailbox command to complete?
5607 * If so, it's dead, so wake up the waiter.
5609 if (isp->isp_mboxbsy) {
5611 isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR;
5612 MBOX_NOTIFY_COMPLETE(isp);
5615 * It's up to the handler for isp_async to reinit stuff and
5616 * restart the firmware
5618 isp_async(isp, ISPASYNC_FW_CRASH);
5622 case ASYNC_RQS_XFER_ERR:
5623 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
5626 case ASYNC_RSP_XFER_ERR:
5627 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
5632 * We've just been notified that the Queue has woken up.
5633 * We don't need to be chatty about this- just unlatch things
5636 mbox = ISP_READ(isp, isp->isp_rqstoutrp);
5639 case ASYNC_TIMEOUT_RESET:
5640 isp_prt(isp, ISP_LOGWARN, "timeout initiated SCSI bus reset of chan %d", chan);
5641 ISP_SET_SENDMARKER(isp, chan, 1);
5642 #ifdef ISP_TARGET_MODE
5643 if (isp_target_async(isp, chan, mbox)) {
5649 case ASYNC_DEVICE_RESET:
5650 isp_prt(isp, ISP_LOGINFO, "device reset on chan %d", chan);
5651 ISP_SET_SENDMARKER(isp, chan, 1);
5652 #ifdef ISP_TARGET_MODE
5653 if (isp_target_async(isp, chan, mbox)) {
5659 case ASYNC_EXTMSG_UNDERRUN:
5660 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
5663 case ASYNC_SCAM_INT:
5664 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
5667 case ASYNC_HUNG_SCSI:
5668 isp_prt(isp, ISP_LOGERR, "stalled SCSI Bus after DATA Overrun");
5669 /* XXX: Need to issue SCSI reset at this point */
5672 case ASYNC_KILLED_BUS:
5673 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
5676 case ASYNC_BUS_TRANSIT:
5677 mbox = ISP_READ(isp, OUTMAILBOX2);
5678 switch (mbox & SXP_PINS_MODE_MASK) {
5679 case SXP_PINS_LVD_MODE:
5680 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
5681 SDPARAM(isp, chan)->isp_diffmode = 0;
5682 SDPARAM(isp, chan)->isp_ultramode = 0;
5683 SDPARAM(isp, chan)->isp_lvdmode = 1;
5685 case SXP_PINS_HVD_MODE:
5686 isp_prt(isp, ISP_LOGINFO,
5687 "Transition to Differential mode");
5688 SDPARAM(isp, chan)->isp_diffmode = 1;
5689 SDPARAM(isp, chan)->isp_ultramode = 0;
5690 SDPARAM(isp, chan)->isp_lvdmode = 0;
5692 case SXP_PINS_SE_MODE:
5693 isp_prt(isp, ISP_LOGINFO,
5694 "Transition to Single Ended mode");
5695 SDPARAM(isp, chan)->isp_diffmode = 0;
5696 SDPARAM(isp, chan)->isp_ultramode = 1;
5697 SDPARAM(isp, chan)->isp_lvdmode = 0;
5700 isp_prt(isp, ISP_LOGWARN,
5701 "Transition to Unknown Mode 0x%x", mbox);
5705 * XXX: Set up to renegotiate again!
5707 /* Can only be for a 1080... */
5708 ISP_SET_SENDMARKER(isp, chan, 1);
5711 case ASYNC_CMD_CMPLT:
5713 if (!IS_ULTRA3(isp)) {
5714 isp_prt(isp, ISP_LOGERR, "unexpected fast posting completion");
5718 h1 = (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1);
5722 h1 = (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1);
5723 h2 = (ISP_READ(isp, OUTMAILBOX7) << 16) | ISP_READ(isp, OUTMAILBOX6);
5731 isp_prt(isp, ISP_LOGERR, "unexpected 16 bit RIO handle");
5734 isp_prt(isp, ISP_LOGWARN, "%s: unhandled async code 0x%x", __func__, mbox);
5739 isp_prt(isp, ISP_LOGDEBUG3, "fast post/rio completion of 0x%08x", h1);
5740 isp_fastpost_complete(isp, h1);
5742 isp_prt(isp, ISP_LOGDEBUG3, "fast post/rio completion of 0x%08x", h2);
5743 isp_fastpost_complete(isp, h2);
5744 if (isp->isp_fpcchiwater < 2) {
5745 isp->isp_fpcchiwater = 2;
5748 if (isp->isp_fpcchiwater < 1) {
5749 isp->isp_fpcchiwater = 1;
5753 isp->isp_intoasync++;
5759 isp_parse_async_fc(ispsoftc_t *isp, uint16_t mbox)
5765 if (IS_DUALBUS(isp)) {
5766 chan = ISP_READ(isp, OUTMAILBOX6);
5770 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
5773 case ASYNC_SYSTEM_ERROR:
5775 isp->isp_state = ISP_CRASHED;
5776 FCPARAM(isp, chan)->isp_loopstate = LOOP_NIL;
5777 isp_change_fw_state(isp, chan, FW_CONFIG_WAIT);
5779 * Were we waiting for a mailbox command to complete?
5780 * If so, it's dead, so wake up the waiter.
5782 if (isp->isp_mboxbsy) {
5784 isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR;
5785 MBOX_NOTIFY_COMPLETE(isp);
5788 * It's up to the handler for isp_async to reinit stuff and
5789 * restart the firmware
5791 isp_async(isp, ISPASYNC_FW_CRASH);
5795 case ASYNC_RQS_XFER_ERR:
5796 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
5799 case ASYNC_RSP_XFER_ERR:
5800 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
5804 #ifdef ISP_TARGET_MODE
5806 isp_prt(isp, ISP_LOGERR, "ATIO Queue Transfer Error");
5810 isp_prt(isp, ISP_LOGERR, "%s: unexpected ASYNC_QWAKEUP code", __func__);
5813 case ASYNC_CMD_CMPLT:
5814 isp_fastpost_complete(isp, (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1));
5815 if (isp->isp_fpcchiwater < 1) {
5816 isp->isp_fpcchiwater = 1;
5820 case ASYNC_RIOZIO_STALL:
5823 case ASYNC_CTIO_DONE:
5824 #ifdef ISP_TARGET_MODE
5825 if (isp_target_async(isp, (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1), mbox)) {
5828 isp->isp_fphccmplt++;
5831 isp_prt(isp, ISP_LOGWARN, "unexpected ASYNC CTIO done");
5834 case ASYNC_LIP_ERROR:
5835 case ASYNC_LIP_NOS_OLS_RECV:
5836 case ASYNC_LIP_OCCURRED:
5839 * These are broadcast events that have to be sent across
5840 * all active channels.
5842 GET_NANOTIME(&isp->isp_init_time);
5843 for (chan = 0; chan < isp->isp_nchan; chan++) {
5844 fcp = FCPARAM(isp, chan);
5845 int topo = fcp->isp_topo;
5847 if (fcp->role == ISP_ROLE_NONE)
5849 if (fcp->isp_loopstate > LOOP_HAVE_LINK)
5850 fcp->isp_loopstate = LOOP_HAVE_LINK;
5851 ISP_SET_SENDMARKER(isp, chan, 1);
5852 isp_async(isp, ISPASYNC_LIP, chan);
5853 #ifdef ISP_TARGET_MODE
5854 if (isp_target_async(isp, chan, mbox)) {
5859 * We've had problems with data corruption occurring on
5860 * commands that complete (with no apparent error) after
5861 * we receive a LIP. This has been observed mostly on
5862 * Local Loop topologies. To be safe, let's just mark
5863 * all active initiator commands as dead.
5865 if (topo == TOPO_NL_PORT || topo == TOPO_FL_PORT) {
5867 for (i = j = 0; i < isp->isp_maxcmds; i++) {
5871 hdp = &isp->isp_xflist[i];
5872 if (ISP_H2HT(hdp->handle) != ISP_HANDLE_INITIATOR) {
5876 if (XS_CHANNEL(xs) != chan) {
5880 isp_prt(isp, ISP_LOG_WARN1,
5881 "%d.%d.%jx bus reset set at %s:%u",
5882 XS_CHANNEL(xs), XS_TGT(xs),
5883 (uintmax_t)XS_LUN(xs),
5884 __func__, __LINE__);
5885 XS_SETERR(xs, HBA_BUSRESET);
5888 isp_prt(isp, ISP_LOGERR, lipd, chan, j);
5896 * This is a broadcast event that has to be sent across
5897 * all active channels.
5899 GET_NANOTIME(&isp->isp_init_time);
5900 for (chan = 0; chan < isp->isp_nchan; chan++) {
5901 fcp = FCPARAM(isp, chan);
5902 if (fcp->role == ISP_ROLE_NONE)
5904 fcp->isp_linkstate = 1;
5905 if (fcp->isp_loopstate < LOOP_HAVE_LINK)
5906 fcp->isp_loopstate = LOOP_HAVE_LINK;
5907 ISP_SET_SENDMARKER(isp, chan, 1);
5908 isp_async(isp, ISPASYNC_LOOP_UP, chan);
5909 #ifdef ISP_TARGET_MODE
5910 if (isp_target_async(isp, chan, mbox)) {
5917 case ASYNC_LOOP_DOWN:
5919 * This is a broadcast event that has to be sent across
5920 * all active channels.
5922 for (chan = 0; chan < isp->isp_nchan; chan++) {
5923 fcp = FCPARAM(isp, chan);
5924 if (fcp->role == ISP_ROLE_NONE)
5926 ISP_SET_SENDMARKER(isp, chan, 1);
5927 fcp->isp_linkstate = 0;
5928 fcp->isp_loopstate = LOOP_NIL;
5929 isp_async(isp, ISPASYNC_LOOP_DOWN, chan);
5930 #ifdef ISP_TARGET_MODE
5931 if (isp_target_async(isp, chan, mbox)) {
5938 case ASYNC_LOOP_RESET:
5940 * This is a broadcast event that has to be sent across
5941 * all active channels.
5943 GET_NANOTIME(&isp->isp_init_time);
5944 for (chan = 0; chan < isp->isp_nchan; chan++) {
5945 fcp = FCPARAM(isp, chan);
5946 if (fcp->role == ISP_ROLE_NONE)
5948 ISP_SET_SENDMARKER(isp, chan, 1);
5949 if (fcp->isp_loopstate > LOOP_HAVE_LINK)
5950 fcp->isp_loopstate = LOOP_HAVE_LINK;
5951 isp_async(isp, ISPASYNC_LOOP_RESET, chan);
5952 #ifdef ISP_TARGET_MODE
5953 if (isp_target_async(isp, chan, mbox)) {
5960 case ASYNC_PDB_CHANGED:
5962 int echan, nphdl, nlstate, reason;
5964 if (IS_23XX(isp) || IS_24XX(isp)) {
5965 nphdl = ISP_READ(isp, OUTMAILBOX1);
5966 nlstate = ISP_READ(isp, OUTMAILBOX2);
5968 nphdl = nlstate = 0xffff;
5971 reason = ISP_READ(isp, OUTMAILBOX3) >> 8;
5974 if (ISP_CAP_MULTI_ID(isp)) {
5975 chan = ISP_READ(isp, OUTMAILBOX3) & 0xff;
5976 if (chan == 0xff || nphdl == NIL_HANDLE) {
5978 echan = isp->isp_nchan - 1;
5979 } else if (chan >= isp->isp_nchan) {
5987 for (; chan <= echan; chan++) {
5988 fcp = FCPARAM(isp, chan);
5989 if (fcp->role == ISP_ROLE_NONE)
5991 if (fcp->isp_loopstate > LOOP_LTEST_DONE) {
5992 if (nphdl != NIL_HANDLE &&
5993 nphdl == fcp->isp_login_hdl &&
5994 reason == PDB24XX_AE_OPN_2)
5996 fcp->isp_loopstate = LOOP_LTEST_DONE;
5997 } else if (fcp->isp_loopstate < LOOP_HAVE_LINK)
5998 fcp->isp_loopstate = LOOP_HAVE_LINK;
5999 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan,
6000 ISPASYNC_CHANGE_PDB, nphdl, nlstate, reason);
6004 case ASYNC_CHANGE_NOTIFY:
6008 portid = ((ISP_READ(isp, OUTMAILBOX1) & 0xff) << 16) |
6009 ISP_READ(isp, OUTMAILBOX2);
6010 if (ISP_CAP_MULTI_ID(isp)) {
6011 chan = ISP_READ(isp, OUTMAILBOX3) & 0xff;
6012 if (chan >= isp->isp_nchan)
6017 fcp = FCPARAM(isp, chan);
6018 if (fcp->role == ISP_ROLE_NONE)
6020 if (fcp->isp_loopstate > LOOP_LTEST_DONE)
6021 fcp->isp_loopstate = LOOP_LTEST_DONE;
6022 else if (fcp->isp_loopstate < LOOP_HAVE_LINK)
6023 fcp->isp_loopstate = LOOP_HAVE_LINK;
6024 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan,
6025 ISPASYNC_CHANGE_SNS, portid);
6028 case ASYNC_ERR_LOGGING_DISABLED:
6029 isp_prt(isp, ISP_LOGWARN, "Error logging disabled (reason 0x%x)",
6030 ISP_READ(isp, OUTMAILBOX1));
6032 case ASYNC_CONNMODE:
6034 * This only applies to 2100 amd 2200 cards
6036 if (!IS_2200(isp) && !IS_2100(isp)) {
6037 isp_prt(isp, ISP_LOGWARN, "bad card for ASYNC_CONNMODE event");
6041 mbox = ISP_READ(isp, OUTMAILBOX1);
6044 isp_prt(isp, ISP_LOGINFO,
6045 "Point-to-Point -> Loop mode");
6048 isp_prt(isp, ISP_LOGINFO,
6049 "Loop -> Point-to-Point mode");
6051 case ISP_CONN_BADLIP:
6052 isp_prt(isp, ISP_LOGWARN,
6053 "Point-to-Point -> Loop mode (BAD LIP)");
6055 case ISP_CONN_FATAL:
6057 isp->isp_state = ISP_CRASHED;
6058 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
6059 isp_async(isp, ISPASYNC_FW_CRASH);
6061 case ISP_CONN_LOOPBACK:
6062 isp_prt(isp, ISP_LOGWARN,
6063 "Looped Back in Point-to-Point mode");
6066 isp_prt(isp, ISP_LOGWARN,
6067 "Unknown connection mode (0x%x)", mbox);
6070 ISP_SET_SENDMARKER(isp, chan, 1);
6071 FCPARAM(isp, chan)->isp_loopstate = LOOP_HAVE_LINK;
6072 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan, ISPASYNC_CHANGE_OTHER);
6074 case ASYNC_P2P_INIT_ERR:
6075 isp_prt(isp, ISP_LOGWARN, "P2P init error (reason 0x%x)",
6076 ISP_READ(isp, OUTMAILBOX1));
6080 isp_prt(isp, ISP_LOGWARN, "Receive Error");
6082 isp_prt(isp, ISP_LOGWARN, "unexpected ASYNC_RCV_ERR");
6085 case ASYNC_RJT_SENT: /* same as ASYNC_QFULL_SENT */
6087 isp_prt(isp, ISP_LOGTDEBUG0, "LS_RJT sent");
6090 isp_prt(isp, ISP_LOGTDEBUG0, "QFULL sent");
6093 case ASYNC_FW_RESTART_COMPLETE:
6094 isp_prt(isp, ISP_LOGDEBUG0, "FW restart complete");
6096 case ASYNC_TEMPERATURE_ALERT:
6097 isp_prt(isp, ISP_LOGERR, "Temperature alert (subcode 0x%x)",
6098 ISP_READ(isp, OUTMAILBOX1));
6100 case ASYNC_AUTOLOAD_FW_COMPLETE:
6101 isp_prt(isp, ISP_LOGDEBUG0, "Autoload FW init complete");
6103 case ASYNC_AUTOLOAD_FW_FAILURE:
6104 isp_prt(isp, ISP_LOGERR, "Autoload FW init failure");
6107 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
6110 if (mbox != ASYNC_CTIO_DONE && mbox != ASYNC_CMD_CMPLT) {
6111 isp->isp_intoasync++;
6117 * Handle other response entries. A pointer to the request queue output
6118 * index is here in case we want to eat several entries at once, although
6119 * this is not used currently.
6123 isp_handle_other_response(ispsoftc_t *isp, int type, isphdr_t *hp, uint32_t *optrp)
6127 uint32_t hdl, portid;
6131 case RQSTYPE_STATUS_CONT:
6132 isp_prt(isp, ISP_LOG_WARN1, "Ignored Continuation Response");
6134 case RQSTYPE_MARKER:
6135 isp_prt(isp, ISP_LOG_WARN1, "Marker Response");
6137 case RQSTYPE_RPT_ID_ACQ:
6138 isp_get_ridacq(isp, (isp_ridacq_t *)hp, &rid);
6139 portid = (uint32_t)rid.ridacq_vp_port_hi << 16 |
6140 rid.ridacq_vp_port_lo;
6141 if (rid.ridacq_format == 0) {
6142 GET_NANOTIME(&isp->isp_init_time);
6143 for (chan = 0; chan < isp->isp_nchan; chan++) {
6144 fcparam *fcp = FCPARAM(isp, chan);
6145 if (fcp->role == ISP_ROLE_NONE)
6147 c = (chan == 0) ? 127 : (chan - 1);
6148 if (rid.ridacq_map[c / 16] & (1 << (c % 16)) ||
6150 fcp->isp_loopstate = LOOP_HAVE_LINK;
6151 isp_async(isp, ISPASYNC_CHANGE_NOTIFY,
6152 chan, ISPASYNC_CHANGE_OTHER);
6154 fcp->isp_loopstate = LOOP_NIL;
6155 isp_async(isp, ISPASYNC_LOOP_DOWN,
6160 fcparam *fcp = FCPARAM(isp, rid.ridacq_vp_index);
6161 if (rid.ridacq_vp_status == RIDACQ_STS_COMPLETE ||
6162 rid.ridacq_vp_status == RIDACQ_STS_CHANGED) {
6163 fcp->isp_topo = (rid.ridacq_map[0] >> 9) & 0x7;
6164 fcp->isp_portid = portid;
6165 fcp->isp_loopstate = LOOP_HAVE_ADDR;
6166 isp_async(isp, ISPASYNC_CHANGE_NOTIFY,
6167 rid.ridacq_vp_index, ISPASYNC_CHANGE_OTHER);
6169 fcp->isp_loopstate = LOOP_NIL;
6170 isp_async(isp, ISPASYNC_LOOP_DOWN,
6171 rid.ridacq_vp_index);
6175 case RQSTYPE_CT_PASSTHRU:
6176 case RQSTYPE_VP_MODIFY:
6177 case RQSTYPE_VP_CTRL:
6179 ISP_IOXGET_32(isp, (uint32_t *)(hp + 1), hdl);
6180 ptr = isp_find_xs(isp, hdl);
6182 isp_destroy_handle(isp, hdl);
6183 memcpy(ptr, hp, QENTRY_LEN);
6189 case RQSTYPE_ENABLE_LUN:
6190 case RQSTYPE_MODIFY_LUN:
6191 case RQSTYPE_NOTIFY:
6192 case RQSTYPE_NOTIFY_ACK:
6198 case RQSTYPE_ABTS_RCVD:
6199 case RQSTYPE_ABTS_RSP:
6200 isp->isp_rsltccmplt++; /* count as a response completion */
6201 #ifdef ISP_TARGET_MODE
6202 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
6207 case RQSTYPE_REQUEST:
6210 if (type != isp_get_response_type(isp, hp)) {
6212 * This is questionable- we're just papering over
6213 * something we've seen on SMP linux in target
6214 * mode- we don't really know what's happening
6215 * here that causes us to think we've gotten
6216 * an entry, but that either the entry isn't
6217 * filled out yet or our CPU read data is stale.
6219 isp_prt(isp, ISP_LOGINFO,
6220 "unstable type in response queue");
6223 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
6224 isp_get_response_type(isp, hp));
6230 isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
6232 switch (sp->req_completion_status & 0xff) {
6235 XS_SETERR(xs, HBA_NOERROR);
6239 case RQCS_INCOMPLETE:
6240 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
6241 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "Selection Timeout @ %s:%d", __func__, __LINE__);
6243 XS_SETERR(xs, HBA_SELTIMEOUT);
6244 *rp = XS_XFRLEN(xs);
6248 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Incomplete, state 0x%x", sp->req_state_flags);
6251 case RQCS_DMA_ERROR:
6252 isp_xs_prt(isp, xs, ISP_LOGERR, "DMA Error");
6253 *rp = XS_XFRLEN(xs);
6256 case RQCS_TRANSPORT_ERROR:
6259 ISP_SNPRINTF(buf, sizeof (buf), "states=>");
6260 if (sp->req_state_flags & RQSF_GOT_BUS) {
6261 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
6263 if (sp->req_state_flags & RQSF_GOT_TARGET) {
6264 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
6266 if (sp->req_state_flags & RQSF_SENT_CDB) {
6267 ISP_SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
6269 if (sp->req_state_flags & RQSF_XFRD_DATA) {
6270 ISP_SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
6272 if (sp->req_state_flags & RQSF_GOT_STATUS) {
6273 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
6275 if (sp->req_state_flags & RQSF_GOT_SENSE) {
6276 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
6278 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
6279 ISP_SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
6281 ISP_SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
6282 if (sp->req_status_flags & RQSTF_DISCONNECT) {
6283 ISP_SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
6285 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
6286 ISP_SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
6288 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
6289 ISP_SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
6291 if (sp->req_status_flags & RQSTF_BUS_RESET) {
6292 ISP_SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
6294 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
6295 ISP_SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
6297 if (sp->req_status_flags & RQSTF_ABORTED) {
6298 ISP_SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
6300 if (sp->req_status_flags & RQSTF_TIMEOUT) {
6301 ISP_SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
6303 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
6304 ISP_SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
6306 isp_xs_prt(isp, xs, ISP_LOGERR, "Transport Error: %s", buf);
6307 *rp = XS_XFRLEN(xs);
6310 case RQCS_RESET_OCCURRED:
6313 isp_xs_prt(isp, xs, ISP_LOGWARN, "Bus Reset destroyed command");
6314 for (chan = 0; chan < isp->isp_nchan; chan++) {
6315 FCPARAM(isp, chan)->sendmarker = 1;
6318 XS_SETERR(xs, HBA_BUSRESET);
6320 *rp = XS_XFRLEN(xs);
6324 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Aborted");
6325 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 1);
6327 XS_SETERR(xs, HBA_ABORTED);
6332 isp_xs_prt(isp, xs, ISP_LOGWARN, "Command timed out");
6334 * XXX: Check to see if we logged out of the device.
6337 XS_SETERR(xs, HBA_CMDTIMEOUT);
6341 case RQCS_DATA_OVERRUN:
6342 XS_SET_RESID(xs, sp->req_resid);
6343 isp_xs_prt(isp, xs, ISP_LOGERR, "data overrun (%ld)", (long) XS_GET_RESID(xs));
6345 XS_SETERR(xs, HBA_DATAOVR);
6349 case RQCS_COMMAND_OVERRUN:
6350 isp_xs_prt(isp, xs, ISP_LOGERR, "command overrun");
6353 case RQCS_STATUS_OVERRUN:
6354 isp_xs_prt(isp, xs, ISP_LOGERR, "status overrun");
6357 case RQCS_BAD_MESSAGE:
6358 isp_xs_prt(isp, xs, ISP_LOGERR, "msg not COMMAND COMPLETE after status");
6361 case RQCS_NO_MESSAGE_OUT:
6362 isp_xs_prt(isp, xs, ISP_LOGERR, "No MESSAGE OUT phase after selection");
6365 case RQCS_EXT_ID_FAILED:
6366 isp_xs_prt(isp, xs, ISP_LOGERR, "EXTENDED IDENTIFY failed");
6369 case RQCS_IDE_MSG_FAILED:
6370 isp_xs_prt(isp, xs, ISP_LOGERR, "INITIATOR DETECTED ERROR rejected");
6373 case RQCS_ABORT_MSG_FAILED:
6374 isp_xs_prt(isp, xs, ISP_LOGERR, "ABORT OPERATION rejected");
6377 case RQCS_REJECT_MSG_FAILED:
6378 isp_xs_prt(isp, xs, ISP_LOGERR, "MESSAGE REJECT rejected");
6381 case RQCS_NOP_MSG_FAILED:
6382 isp_xs_prt(isp, xs, ISP_LOGERR, "NOP rejected");
6385 case RQCS_PARITY_ERROR_MSG_FAILED:
6386 isp_xs_prt(isp, xs, ISP_LOGERR, "MESSAGE PARITY ERROR rejected");
6389 case RQCS_DEVICE_RESET_MSG_FAILED:
6390 isp_xs_prt(isp, xs, ISP_LOGWARN, "BUS DEVICE RESET rejected");
6393 case RQCS_ID_MSG_FAILED:
6394 isp_xs_prt(isp, xs, ISP_LOGERR, "IDENTIFY rejected");
6397 case RQCS_UNEXP_BUS_FREE:
6398 isp_xs_prt(isp, xs, ISP_LOGERR, "Unexpected Bus Free");
6401 case RQCS_DATA_UNDERRUN:
6404 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
6405 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
6406 isp_xs_prt(isp, xs, ISP_LOGWARN, bun, XS_XFRLEN(xs), sp->req_resid, (ru_marked)? "marked" : "not marked");
6408 XS_SETERR(xs, HBA_BOTCH);
6413 XS_SET_RESID(xs, sp->req_resid);
6415 XS_SETERR(xs, HBA_NOERROR);
6420 case RQCS_XACT_ERR1:
6421 isp_xs_prt(isp, xs, ISP_LOGERR, "HBA attempted queued transaction with disconnect not set");
6424 case RQCS_XACT_ERR2:
6425 isp_xs_prt(isp, xs, ISP_LOGERR,
6426 "HBA attempted queued transaction to target routine %jx",
6427 (uintmax_t)XS_LUN(xs));
6430 case RQCS_XACT_ERR3:
6431 isp_xs_prt(isp, xs, ISP_LOGERR, "HBA attempted queued cmd when queueing disabled");
6434 case RQCS_BAD_ENTRY:
6435 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
6438 case RQCS_QUEUE_FULL:
6439 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "internal queues full status 0x%x", *XS_STSP(xs));
6442 * If QFULL or some other status byte is set, then this
6443 * isn't an error, per se.
6445 * Unfortunately, some QLogic f/w writers have, in
6446 * some cases, omitted to *set* status to QFULL.
6449 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
6450 XS_SETERR(xs, HBA_NOERROR);
6455 *XS_STSP(xs) = SCSI_QFULL;
6456 XS_SETERR(xs, HBA_NOERROR);
6459 case RQCS_PHASE_SKIPPED:
6460 isp_xs_prt(isp, xs, ISP_LOGERR, "SCSI phase skipped");
6463 case RQCS_ARQS_FAILED:
6464 isp_xs_prt(isp, xs, ISP_LOGERR, "Auto Request Sense Failed");
6466 XS_SETERR(xs, HBA_ARQFAIL);
6470 case RQCS_WIDE_FAILED:
6471 isp_xs_prt(isp, xs, ISP_LOGERR, "Wide Negotiation Failed");
6473 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
6474 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
6475 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
6479 XS_SETERR(xs, HBA_NOERROR);
6483 case RQCS_SYNCXFER_FAILED:
6484 isp_xs_prt(isp, xs, ISP_LOGERR, "SDTR Message Failed");
6486 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
6487 sdp += XS_CHANNEL(xs);
6488 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
6489 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
6494 case RQCS_LVD_BUSERR:
6495 isp_xs_prt(isp, xs, ISP_LOGERR, "Bad LVD condition");
6498 case RQCS_PORT_UNAVAILABLE:
6500 * No such port on the loop. Moral equivalent of SELTIMEO
6502 case RQCS_PORT_LOGGED_OUT:
6505 uint8_t sts = sp->req_completion_status & 0xff;
6506 fcparam *fcp = FCPARAM(isp, 0);
6510 * It was there (maybe)- treat as a selection timeout.
6512 if (sts == RQCS_PORT_UNAVAILABLE) {
6513 reason = "unavailable";
6518 isp_prt(isp, ISP_LOGINFO, "port %s for target %d", reason, XS_TGT(xs));
6521 * If we're on a local loop, force a LIP (which is overkill)
6522 * to force a re-login of this unit. If we're on fabric,
6523 * then we'll have to log in again as a matter of course.
6525 if (fcp->isp_topo == TOPO_NL_PORT ||
6526 fcp->isp_topo == TOPO_FL_PORT) {
6528 MBSINIT(&mbs, MBOX_INIT_LIP, MBLOGALL, 0);
6529 if (ISP_CAP_2KLOGIN(isp)) {
6530 mbs.ibits = (1 << 10);
6532 isp_mboxcmd_qnw(isp, &mbs, 1);
6535 lp = &fcp->portdb[XS_TGT(xs)];
6536 if (lp->state == FC_PORTDB_STATE_ZOMBIE) {
6537 *XS_STSP(xs) = SCSI_BUSY;
6538 XS_SETERR(xs, HBA_TGTBSY);
6540 XS_SETERR(xs, HBA_SELTIMEOUT);
6544 case RQCS_PORT_CHANGED:
6545 isp_prt(isp, ISP_LOGWARN, "port changed for target %d", XS_TGT(xs));
6547 XS_SETERR(xs, HBA_SELTIMEOUT);
6551 case RQCS_PORT_BUSY:
6552 isp_prt(isp, ISP_LOGWARN, "port busy for target %d", XS_TGT(xs));
6554 *XS_STSP(xs) = SCSI_BUSY;
6555 XS_SETERR(xs, HBA_TGTBSY);
6560 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x", sp->req_completion_status);
6564 XS_SETERR(xs, HBA_BOTCH);
6569 isp_parse_status_24xx(ispsoftc_t *isp, isp24xx_statusreq_t *sp, XS_T *xs, long *rp)
6571 int ru_marked, sv_marked;
6572 int chan = XS_CHANNEL(xs);
6574 switch (sp->req_completion_status) {
6577 XS_SETERR(xs, HBA_NOERROR);
6581 case RQCS_DMA_ERROR:
6582 isp_xs_prt(isp, xs, ISP_LOGERR, "DMA error");
6585 case RQCS_TRANSPORT_ERROR:
6586 isp_xs_prt(isp, xs, ISP_LOGERR, "Transport Error");
6589 case RQCS_RESET_OCCURRED:
6590 isp_xs_prt(isp, xs, ISP_LOGWARN, "reset destroyed command");
6591 FCPARAM(isp, chan)->sendmarker = 1;
6593 XS_SETERR(xs, HBA_BUSRESET);
6598 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Aborted");
6599 FCPARAM(isp, chan)->sendmarker = 1;
6601 XS_SETERR(xs, HBA_ABORTED);
6606 isp_xs_prt(isp, xs, ISP_LOGWARN, "Command Timed Out");
6608 XS_SETERR(xs, HBA_CMDTIMEOUT);
6612 case RQCS_DATA_OVERRUN:
6613 XS_SET_RESID(xs, sp->req_resid);
6614 isp_xs_prt(isp, xs, ISP_LOGERR, "Data Overrun");
6616 XS_SETERR(xs, HBA_DATAOVR);
6620 case RQCS_24XX_DRE: /* data reassembly error */
6621 isp_prt(isp, ISP_LOGERR, "Chan %d data reassembly error for target %d", chan, XS_TGT(xs));
6623 XS_SETERR(xs, HBA_ABORTED);
6625 *rp = XS_XFRLEN(xs);
6628 case RQCS_24XX_TABORT: /* aborted by target */
6629 isp_prt(isp, ISP_LOGERR, "Chan %d target %d sent ABTS", chan, XS_TGT(xs));
6631 XS_SETERR(xs, HBA_ABORTED);
6635 case RQCS_DATA_UNDERRUN:
6636 ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
6638 * We can get an underrun w/o things being marked
6639 * if we got a non-zero status.
6641 sv_marked = (sp->req_scsi_status & (RQCS_SV|RQCS_RV)) != 0;
6642 if ((ru_marked == 0 && sv_marked == 0) ||
6643 (sp->req_resid > XS_XFRLEN(xs))) {
6644 isp_xs_prt(isp, xs, ISP_LOGWARN, bun, XS_XFRLEN(xs), sp->req_resid, (ru_marked)? "marked" : "not marked");
6646 XS_SETERR(xs, HBA_BOTCH);
6650 XS_SET_RESID(xs, sp->req_resid);
6651 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "Data Underrun (%d) for command 0x%x", sp->req_resid, XS_CDBP(xs)[0] & 0xff);
6653 XS_SETERR(xs, HBA_NOERROR);
6657 case RQCS_PORT_UNAVAILABLE:
6659 * No such port on the loop. Moral equivalent of SELTIMEO
6661 case RQCS_PORT_LOGGED_OUT:
6664 uint8_t sts = sp->req_completion_status & 0xff;
6665 fcparam *fcp = FCPARAM(isp, XS_CHANNEL(xs));
6669 * It was there (maybe)- treat as a selection timeout.
6671 if (sts == RQCS_PORT_UNAVAILABLE) {
6672 reason = "unavailable";
6677 isp_prt(isp, ISP_LOGINFO, "Chan %d port %s for target %d",
6678 chan, reason, XS_TGT(xs));
6681 * There is no MBOX_INIT_LIP for the 24XX.
6684 lp = &fcp->portdb[XS_TGT(xs)];
6685 if (lp->state == FC_PORTDB_STATE_ZOMBIE) {
6686 *XS_STSP(xs) = SCSI_BUSY;
6687 XS_SETERR(xs, HBA_TGTBSY);
6689 XS_SETERR(xs, HBA_SELTIMEOUT);
6693 case RQCS_PORT_CHANGED:
6694 isp_prt(isp, ISP_LOGWARN, "port changed for target %d chan %d", XS_TGT(xs), chan);
6696 XS_SETERR(xs, HBA_SELTIMEOUT);
6701 case RQCS_24XX_ENOMEM: /* f/w resource unavailable */
6702 isp_prt(isp, ISP_LOGWARN, "f/w resource unavailable for target %d chan %d", XS_TGT(xs), chan);
6704 *XS_STSP(xs) = SCSI_BUSY;
6705 XS_SETERR(xs, HBA_TGTBSY);
6709 case RQCS_24XX_TMO: /* task management overrun */
6710 isp_prt(isp, ISP_LOGWARN, "command for target %d overlapped task management for chan %d", XS_TGT(xs), chan);
6712 *XS_STSP(xs) = SCSI_BUSY;
6713 XS_SETERR(xs, HBA_TGTBSY);
6718 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x on chan %d", sp->req_completion_status, chan);
6722 XS_SETERR(xs, HBA_BOTCH);
6727 isp_fastpost_complete(ispsoftc_t *isp, uint32_t fph)
6734 xs = isp_find_xs(isp, fph);
6736 isp_prt(isp, ISP_LOGWARN,
6737 "Command for fast post handle 0x%x not found", fph);
6740 isp_destroy_handle(isp, fph);
6743 * Since we don't have a result queue entry item,
6744 * we must believe that SCSI status is zero and
6745 * that all data transferred.
6747 XS_SET_RESID(xs, 0);
6748 *XS_STSP(xs) = SCSI_GOOD;
6749 if (XS_XFRLEN(xs)) {
6750 ISP_DMAFREE(isp, xs, fph);
6752 if (isp->isp_nactive) {
6755 isp->isp_fphccmplt++;
6760 isp_mbox_continue(ispsoftc_t *isp)
6766 switch (isp->isp_lastmbxcmd) {
6767 case MBOX_WRITE_RAM_WORD:
6768 case MBOX_READ_RAM_WORD:
6769 case MBOX_WRITE_RAM_WORD_EXTENDED:
6770 case MBOX_READ_RAM_WORD_EXTENDED:
6775 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
6776 isp->isp_mbxwrk0 = 0;
6781 * Clear the previous interrupt.
6784 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
6786 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
6787 ISP_WRITE(isp, BIU_SEMA, 0);
6791 * Continue with next word.
6793 ISP_MEMZERO(&mbs, sizeof (mbs));
6794 ptr = isp->isp_mbxworkp;
6795 switch (isp->isp_lastmbxcmd) {
6796 case MBOX_WRITE_RAM_WORD:
6797 mbs.param[1] = isp->isp_mbxwrk1++;
6798 mbs.param[2] = *ptr++;
6800 case MBOX_READ_RAM_WORD:
6801 *ptr++ = isp->isp_mboxtmp[2];
6802 mbs.param[1] = isp->isp_mbxwrk1++;
6804 case MBOX_WRITE_RAM_WORD_EXTENDED:
6806 uint32_t *lptr = (uint32_t *)ptr;
6807 mbs.param[2] = lptr[0];
6808 mbs.param[3] = lptr[0] >> 16;
6810 ptr = (uint16_t *)lptr;
6812 mbs.param[2] = *ptr++;
6814 offset = isp->isp_mbxwrk1;
6815 offset |= isp->isp_mbxwrk8 << 16;
6816 mbs.param[1] = offset;
6817 mbs.param[8] = offset >> 16;
6819 isp->isp_mbxwrk1 = offset;
6820 isp->isp_mbxwrk8 = offset >> 16;
6822 case MBOX_READ_RAM_WORD_EXTENDED:
6824 uint32_t *lptr = (uint32_t *)ptr;
6825 uint32_t val = isp->isp_mboxtmp[2];
6826 val |= (isp->isp_mboxtmp[3]) << 16;
6828 ptr = (uint16_t *)lptr;
6830 *ptr++ = isp->isp_mboxtmp[2];
6832 offset = isp->isp_mbxwrk1;
6833 offset |= isp->isp_mbxwrk8 << 16;
6834 mbs.param[1] = offset;
6835 mbs.param[8] = offset >> 16;
6837 isp->isp_mbxwrk1 = offset;
6838 isp->isp_mbxwrk8 = offset >> 16;
6841 isp->isp_mbxworkp = ptr;
6843 mbs.param[0] = isp->isp_lastmbxcmd;
6844 mbs.logval = MBLOGALL;
6845 isp_mboxcmd_qnw(isp, &mbs, 0);
6849 #define ISP_SCSI_IBITS(op) (mbpscsi[((op)<<1)])
6850 #define ISP_SCSI_OBITS(op) (mbpscsi[((op)<<1) + 1])
6851 #define ISP_SCSI_OPMAP(in, out) in, out
6852 static const uint8_t mbpscsi[] = {
6853 ISP_SCSI_OPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
6854 ISP_SCSI_OPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
6855 ISP_SCSI_OPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
6856 ISP_SCSI_OPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
6857 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
6858 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
6859 ISP_SCSI_OPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
6860 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
6861 ISP_SCSI_OPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
6862 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x09: */
6863 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0a: */
6864 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0b: */
6865 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0c: */
6866 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0d: */
6867 ISP_SCSI_OPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
6868 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0f: */
6869 ISP_SCSI_OPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
6870 ISP_SCSI_OPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
6871 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
6872 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
6873 ISP_SCSI_OPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
6874 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
6875 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
6876 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
6877 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
6878 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
6879 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
6880 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
6881 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
6882 ISP_SCSI_OPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
6883 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x1e: */
6884 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
6885 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
6886 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
6887 ISP_SCSI_OPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
6888 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
6889 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
6890 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
6891 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
6892 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
6893 ISP_SCSI_OPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
6894 ISP_SCSI_OPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
6895 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
6896 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2b: */
6897 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2c: */
6898 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2d: */
6899 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2e: */
6900 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2f: */
6901 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
6902 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
6903 ISP_SCSI_OPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
6904 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
6905 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
6906 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
6907 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
6908 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
6909 ISP_SCSI_OPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
6910 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
6911 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
6912 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3b: */
6913 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3c: */
6914 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3d: */
6915 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3e: */
6916 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3f: */
6917 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
6918 ISP_SCSI_OPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
6919 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
6920 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x43: */
6921 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x44: */
6922 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
6923 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
6924 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x47: */
6925 ISP_SCSI_OPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
6926 ISP_SCSI_OPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
6927 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
6928 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
6929 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4c: */
6930 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4d: */
6931 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4e: */
6932 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4f: */
6933 ISP_SCSI_OPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
6934 ISP_SCSI_OPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
6935 ISP_SCSI_OPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
6936 ISP_SCSI_OPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
6937 ISP_SCSI_OPMAP(0xcf, 0x01), /* 0x54: EXECUCUTE COMMAND IOCB A64 */
6938 ISP_SCSI_OPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
6939 ISP_SCSI_OPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
6940 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x57: */
6941 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x58: */
6942 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x59: */
6943 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
6944 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
6945 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
6946 ISP_SCSI_OPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
6948 #define MAX_SCSI_OPCODE 0x5d
6950 static const char *scsi_mbcmd_names[] = {
6967 "INIT REQUEST QUEUE",
6968 "INIT RESULT QUEUE",
6978 "SINGLE STEP QUEUE",
6980 "GET DEV QUEUE STATUS",
6982 "GET FIRMWARE STATUS",
6984 "GET SELECT TIMEOUT",
6986 "GET TAG AGE LIMIT",
6988 "GET ACT NEG STATE",
6989 "GET ASYNC DATA SETUP TIME",
6991 "GET TARGET PARAMS",
6992 "GET DEV QUEUE PARAMS",
6993 "GET RESET DELAY PARAMS",
7000 "SET SELECT TIMEOUT",
7002 "SET TAG AGE LIMIT",
7004 "SET ACT NEG STATE",
7005 "SET ASYNC DATA SETUP TIME",
7006 "SET PCI CONTROL PARAMS",
7007 "SET TARGET PARAMS",
7008 "SET DEV QUEUE PARAMS",
7009 "SET RESET DELAY PARAMS",
7015 "RETURN BIOS BLOCK ADDR",
7016 "WRITE FOUR RAM WORDS",
7020 "SET SYSTEM PARAMETER",
7021 "GET SYSTEM PARAMETER",
7023 "GET SCAM CONFIGURATION",
7024 "SET SCAM CONFIGURATION",
7025 "SET FIRMWARE FEATURES",
7026 "GET FIRMWARE FEATURES",
7033 "INITIALIZE REQUEST QUEUE A64",
7034 "INITIALIZE RESPONSE QUEUE A64",
7036 "ENABLE TARGET MODE",
7037 "GET TARGET MODE STATE",
7041 "SET DATA OVERRUN RECOVERY MODE",
7042 "GET DATA OVERRUN RECOVERY MODE",
7047 #define ISP_FC_IBITS(op) ((mbpfc[((op)<<3) + 0] << 24) | (mbpfc[((op)<<3) + 1] << 16) | (mbpfc[((op)<<3) + 2] << 8) | (mbpfc[((op)<<3) + 3]))
7048 #define ISP_FC_OBITS(op) ((mbpfc[((op)<<3) + 4] << 24) | (mbpfc[((op)<<3) + 5] << 16) | (mbpfc[((op)<<3) + 6] << 8) | (mbpfc[((op)<<3) + 7]))
7050 #define ISP_FC_OPMAP(in0, out0) 0, 0, 0, in0, 0, 0, 0, out0
7051 #define ISP_FC_OPMAP_HALF(in1, in0, out1, out0) 0, 0, in1, in0, 0, 0, out1, out0
7052 #define ISP_FC_OPMAP_FULL(in3, in2, in1, in0, out3, out2, out1, out0) in3, in2, in1, in0, out3, out2, out1, out0
7053 static const uint32_t mbpfc[] = {
7054 ISP_FC_OPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
7055 ISP_FC_OPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
7056 ISP_FC_OPMAP_HALF(0x07, 0xff, 0x00, 0x03), /* 0x02: MBOX_EXEC_FIRMWARE */
7057 ISP_FC_OPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
7058 ISP_FC_OPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
7059 ISP_FC_OPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
7060 ISP_FC_OPMAP_FULL(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
7061 ISP_FC_OPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
7062 ISP_FC_OPMAP_FULL(0x0, 0x0, 0x0, 0x01, 0x0, 0x3, 0x80, 0x7f), /* 0x08: MBOX_ABOUT_FIRMWARE */
7063 ISP_FC_OPMAP(0xdf, 0x01), /* 0x09: MBOX_LOAD_RISC_RAM_2100 */
7064 ISP_FC_OPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
7065 ISP_FC_OPMAP_HALF(0x1, 0xff, 0x0, 0x01), /* 0x0b: MBOX_LOAD_RISC_RAM */
7066 ISP_FC_OPMAP(0x00, 0x00), /* 0x0c: */
7067 ISP_FC_OPMAP_HALF(0x1, 0x0f, 0x0, 0x01), /* 0x0d: MBOX_WRITE_RAM_WORD_EXTENDED */
7068 ISP_FC_OPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
7069 ISP_FC_OPMAP_HALF(0x1, 0x03, 0x0, 0x0d), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED */
7070 ISP_FC_OPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
7071 ISP_FC_OPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
7072 ISP_FC_OPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
7073 ISP_FC_OPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
7074 ISP_FC_OPMAP_HALF(0x1, 0xff, 0x0, 0x03), /* 0x14: MBOX_STOP_FIRMWARE */
7075 ISP_FC_OPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
7076 ISP_FC_OPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
7077 ISP_FC_OPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
7078 ISP_FC_OPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
7079 ISP_FC_OPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
7080 ISP_FC_OPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
7081 ISP_FC_OPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
7082 ISP_FC_OPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
7083 ISP_FC_OPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
7084 ISP_FC_OPMAP(0x00, 0x00), /* 0x1e: */
7085 ISP_FC_OPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
7086 ISP_FC_OPMAP_HALF(0x2, 0x01, 0x7e, 0xcf), /* 0x20: MBOX_GET_LOOP_ID */
7087 ISP_FC_OPMAP(0x00, 0x00), /* 0x21: */
7088 ISP_FC_OPMAP(0x03, 0x4b), /* 0x22: MBOX_GET_TIMEOUT_PARAMS */
7089 ISP_FC_OPMAP(0x00, 0x00), /* 0x23: */
7090 ISP_FC_OPMAP(0x00, 0x00), /* 0x24: */
7091 ISP_FC_OPMAP(0x00, 0x00), /* 0x25: */
7092 ISP_FC_OPMAP(0x00, 0x00), /* 0x26: */
7093 ISP_FC_OPMAP(0x00, 0x00), /* 0x27: */
7094 ISP_FC_OPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
7095 ISP_FC_OPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
7096 ISP_FC_OPMAP(0x00, 0x00), /* 0x2a: */
7097 ISP_FC_OPMAP(0x00, 0x00), /* 0x2b: */
7098 ISP_FC_OPMAP(0x00, 0x00), /* 0x2c: */
7099 ISP_FC_OPMAP(0x00, 0x00), /* 0x2d: */
7100 ISP_FC_OPMAP(0x00, 0x00), /* 0x2e: */
7101 ISP_FC_OPMAP(0x00, 0x00), /* 0x2f: */
7102 ISP_FC_OPMAP(0x00, 0x00), /* 0x30: */
7103 ISP_FC_OPMAP(0x00, 0x00), /* 0x31: */
7104 ISP_FC_OPMAP(0x4b, 0x4b), /* 0x32: MBOX_SET_TIMEOUT_PARAMS */
7105 ISP_FC_OPMAP(0x00, 0x00), /* 0x33: */
7106 ISP_FC_OPMAP(0x00, 0x00), /* 0x34: */
7107 ISP_FC_OPMAP(0x00, 0x00), /* 0x35: */
7108 ISP_FC_OPMAP(0x00, 0x00), /* 0x36: */
7109 ISP_FC_OPMAP(0x00, 0x00), /* 0x37: */
7110 ISP_FC_OPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
7111 ISP_FC_OPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
7112 ISP_FC_OPMAP(0x00, 0x00), /* 0x3a: */
7113 ISP_FC_OPMAP(0x00, 0x00), /* 0x3b: */
7114 ISP_FC_OPMAP(0x00, 0x00), /* 0x3c: */
7115 ISP_FC_OPMAP(0x00, 0x00), /* 0x3d: */
7116 ISP_FC_OPMAP(0x00, 0x00), /* 0x3e: */
7117 ISP_FC_OPMAP(0x00, 0x00), /* 0x3f: */
7118 ISP_FC_OPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
7119 ISP_FC_OPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
7120 ISP_FC_OPMAP_HALF(0x0, 0x01, 0x1f, 0xcf), /* 0x42: MBOX_GET_RESOURCE_COUNT */
7121 ISP_FC_OPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_OFFLINE_MODE */
7122 ISP_FC_OPMAP(0x00, 0x00), /* 0x44: */
7123 ISP_FC_OPMAP(0x00, 0x00), /* 0x45: */
7124 ISP_FC_OPMAP(0x00, 0x00), /* 0x46: */
7125 ISP_FC_OPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
7126 ISP_FC_OPMAP(0xcf, 0x0f), /* 0x48: MBOX_INIT_FIRMWARE_MULTI_ID */
7127 ISP_FC_OPMAP(0xcd, 0x01), /* 0x49: MBOX_GET_VP_DATABASE */
7128 ISP_FC_OPMAP_HALF(0x2, 0xcd, 0x0, 0x01), /* 0x4a: MBOX_GET_VP_DATABASE_ENTRY */
7129 ISP_FC_OPMAP(0x00, 0x00), /* 0x4b: */
7130 ISP_FC_OPMAP(0x00, 0x00), /* 0x4c: */
7131 ISP_FC_OPMAP(0x00, 0x00), /* 0x4d: */
7132 ISP_FC_OPMAP(0x00, 0x00), /* 0x4e: */
7133 ISP_FC_OPMAP(0x00, 0x00), /* 0x4f: */
7134 ISP_FC_OPMAP(0x00, 0x00), /* 0x50: */
7135 ISP_FC_OPMAP(0x00, 0x00), /* 0x51: */
7136 ISP_FC_OPMAP(0x00, 0x00), /* 0x52: */
7137 ISP_FC_OPMAP(0x00, 0x00), /* 0x53: */
7138 ISP_FC_OPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
7139 ISP_FC_OPMAP(0x00, 0x00), /* 0x55: */
7140 ISP_FC_OPMAP(0x00, 0x00), /* 0x56: */
7141 ISP_FC_OPMAP(0x00, 0x00), /* 0x57: */
7142 ISP_FC_OPMAP(0x00, 0x00), /* 0x58: */
7143 ISP_FC_OPMAP(0x00, 0x00), /* 0x59: */
7144 ISP_FC_OPMAP(0x00, 0x00), /* 0x5a: */
7145 ISP_FC_OPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
7146 ISP_FC_OPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
7147 ISP_FC_OPMAP(0x07, 0x1f), /* 0x5d: MBOX_GET_SET_DATA_RATE */
7148 ISP_FC_OPMAP(0x00, 0x00), /* 0x5e: */
7149 ISP_FC_OPMAP(0x00, 0x00), /* 0x5f: */
7150 ISP_FC_OPMAP(0xcf, 0x0f), /* 0x60: MBOX_INIT_FIRMWARE */
7151 ISP_FC_OPMAP(0x00, 0x00), /* 0x61: */
7152 ISP_FC_OPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
7153 ISP_FC_OPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
7154 ISP_FC_OPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
7155 ISP_FC_OPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
7156 ISP_FC_OPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
7157 ISP_FC_OPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
7158 ISP_FC_OPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
7159 ISP_FC_OPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
7160 ISP_FC_OPMAP_HALF(0x6, 0x03, 0x0, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
7161 ISP_FC_OPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
7162 ISP_FC_OPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
7163 ISP_FC_OPMAP(0x00, 0x00), /* 0x6d: */
7164 ISP_FC_OPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
7165 ISP_FC_OPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
7166 ISP_FC_OPMAP_HALF(0x02, 0x03, 0x00, 0x03), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
7167 ISP_FC_OPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
7168 ISP_FC_OPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
7169 ISP_FC_OPMAP(0x00, 0x00), /* 0x73: */
7170 ISP_FC_OPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
7171 ISP_FC_OPMAP_HALF(0x03, 0xcf, 0x00, 0x07), /* 0x75: GET PORT/NODE NAME LIST */
7172 ISP_FC_OPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
7173 ISP_FC_OPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
7174 ISP_FC_OPMAP(0x00, 0x00), /* 0x78: */
7175 ISP_FC_OPMAP(0x00, 0x00), /* 0x79: */
7176 ISP_FC_OPMAP(0x00, 0x00), /* 0x7a: */
7177 ISP_FC_OPMAP(0x00, 0x00), /* 0x7b: */
7178 ISP_FC_OPMAP_HALF(0x03, 0x4f, 0x00, 0x07), /* 0x7c: Get ID List */
7179 ISP_FC_OPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
7180 ISP_FC_OPMAP(0x0f, 0x01) /* 0x7e: LUN RESET */
7182 #define MAX_FC_OPCODE 0x7e
7186 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
7187 * do not access at this time in the core driver. The caller is
7188 * responsible for setting this register first (Gross!). The assumption
7189 * is that we won't overflow.
7192 static const char *fc_mbcmd_names[] = {
7206 "WRITE RAM WORD EXTENDED",
7208 "READ RAM WORD EXTENDED",
7209 "INIT REQUEST QUEUE", /* 10h */
7210 "INIT RESULT QUEUE",
7220 "SINGLE STEP QUEUE",
7222 "GET DEV QUEUE STATUS",
7224 "GET FIRMWARE STATUS",
7225 "GET LOOP ID", /* 20h */
7227 "GET TIMEOUT PARAMS",
7233 "GET FIRMWARE OPTIONS",
7234 "GET PORT QUEUE PARAMS",
7235 "GENERATE SYSTEM ERROR",
7241 "WRITE SFP", /* 30h */
7243 "SET TIMEOUT PARAMS",
7249 "SET FIRMWARE OPTIONS",
7250 "SET PORT QUEUE PARAMS",
7254 "RESTART NIC FIRMWARE",
7257 "LOOP PORT BYPASS", /* 40h */
7259 "GET RESOURCE COUNT",
7260 "REQUEST NON PARTICIPATING MODE",
7261 "DIAGNOSTIC ECHO TEST",
7262 "DIAGNOSTIC LOOPBACK",
7264 "GET PORT DATABASE ENHANCED",
7265 "INIT FIRMWARE MULTI ID",
7267 "GET VP DATABASE ENTRY",
7273 "GET FCF LIST", /* 50h */
7274 "GET DCBX PARAMETERS",
7285 "FIRMWARE HEARTBEAT",
7286 "GET/SET DATA RATE",
7289 "INIT FIRMWARE", /* 60h */
7290 "GET INIT CONTROL BLOCK",
7292 "GET FC-AL POSITION MAP",
7293 "GET PORT DATABASE",
7302 "GET LINK STATS & PRIVATE DATA CNTS",
7305 "SEND CHANGE REQUEST", /* 70h */
7310 "GET PORT/NODE NAME LIST",
7312 "INITIALIZE IP MAILBOX",
7323 isp_mboxcmd_qnw(ispsoftc_t *isp, mbreg_t *mbp, int nodelay)
7325 unsigned int ibits, obits, box, opcode;
7327 opcode = mbp->param[0];
7329 ibits = ISP_FC_IBITS(opcode);
7330 obits = ISP_FC_OBITS(opcode);
7332 ibits = ISP_SCSI_IBITS(opcode);
7333 obits = ISP_SCSI_OBITS(opcode);
7335 ibits |= mbp->ibits;
7336 obits |= mbp->obits;
7337 for (box = 0; box < ISP_NMBOX(isp); box++) {
7338 if (ibits & (1 << box)) {
7339 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
7342 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
7346 isp->isp_lastmbxcmd = opcode;
7347 isp->isp_obits = obits;
7348 isp->isp_mboxbsy = 1;
7351 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_SET_HOST_INT);
7353 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
7356 * Oddly enough, if we're not delaying for an answer,
7357 * delay a bit to give the f/w a chance to pick up the
7366 isp_mboxcmd(ispsoftc_t *isp, mbreg_t *mbp)
7368 const char *cname, *xname, *sname;
7369 char tname[16], mname[16];
7370 unsigned int ibits, obits, box, opcode;
7372 opcode = mbp->param[0];
7374 if (opcode > MAX_FC_OPCODE) {
7375 mbp->param[0] = MBOX_INVALID_COMMAND;
7376 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
7379 cname = fc_mbcmd_names[opcode];
7380 ibits = ISP_FC_IBITS(opcode);
7381 obits = ISP_FC_OBITS(opcode);
7383 if (opcode > MAX_SCSI_OPCODE) {
7384 mbp->param[0] = MBOX_INVALID_COMMAND;
7385 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
7388 cname = scsi_mbcmd_names[opcode];
7389 ibits = ISP_SCSI_IBITS(opcode);
7390 obits = ISP_SCSI_OBITS(opcode);
7392 if (cname == NULL) {
7394 ISP_SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
7396 isp_prt(isp, ISP_LOGDEBUG3, "Mailbox Command '%s'", cname);
7399 * Pick up any additional bits that the caller might have set.
7401 ibits |= mbp->ibits;
7402 obits |= mbp->obits;
7405 * Mask any bits that the caller wants us to mask
7407 ibits &= mbp->ibitm;
7408 obits &= mbp->obitm;
7411 if (ibits == 0 && obits == 0) {
7412 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
7413 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
7418 * Get exclusive usage of mailbox registers.
7420 if (MBOX_ACQUIRE(isp)) {
7421 mbp->param[0] = MBOX_REGS_BUSY;
7425 for (box = 0; box < ISP_NMBOX(isp); box++) {
7426 if (ibits & (1 << box)) {
7427 isp_prt(isp, ISP_LOGDEBUG3, "IN mbox %d = 0x%04x", box,
7429 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
7431 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
7434 isp->isp_lastmbxcmd = opcode;
7437 * We assume that we can't overwrite a previous command.
7439 isp->isp_obits = obits;
7440 isp->isp_mboxbsy = 1;
7443 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
7446 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_SET_HOST_INT);
7448 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
7452 * While we haven't finished the command, spin our wheels here.
7454 MBOX_WAIT_COMPLETE(isp, mbp);
7457 * Did the command time out?
7459 if (mbp->param[0] == MBOX_TIMEOUT) {
7460 isp->isp_mboxbsy = 0;
7466 * Copy back output registers.
7468 for (box = 0; box < ISP_NMBOX(isp); box++) {
7469 if (obits & (1 << box)) {
7470 mbp->param[box] = isp->isp_mboxtmp[box];
7471 isp_prt(isp, ISP_LOGDEBUG3, "OUT mbox %d = 0x%04x", box,
7476 isp->isp_mboxbsy = 0;
7479 if (mbp->logval == 0 || mbp->param[0] == MBOX_COMMAND_COMPLETE)
7482 if ((mbp->param[0] & 0xbfe0) == 0 &&
7483 (mbp->logval & MBLOGMASK(mbp->param[0])) == 0)
7488 switch (mbp->param[0]) {
7489 case MBOX_INVALID_COMMAND:
7490 xname = "INVALID COMMAND";
7492 case MBOX_HOST_INTERFACE_ERROR:
7493 xname = "HOST INTERFACE ERROR";
7495 case MBOX_TEST_FAILED:
7496 xname = "TEST FAILED";
7498 case MBOX_COMMAND_ERROR:
7499 xname = "COMMAND ERROR";
7500 ISP_SNPRINTF(mname, sizeof(mname), " subcode 0x%x",
7504 case MBOX_COMMAND_PARAM_ERROR:
7505 xname = "COMMAND PARAMETER ERROR";
7507 case MBOX_PORT_ID_USED:
7508 xname = "PORT ID ALREADY IN USE";
7510 case MBOX_LOOP_ID_USED:
7511 xname = "LOOP ID ALREADY IN USE";
7513 case MBOX_ALL_IDS_USED:
7514 xname = "ALL LOOP IDS IN USE";
7516 case MBOX_NOT_LOGGED_IN:
7517 xname = "NOT LOGGED IN";
7519 case MBOX_LINK_DOWN_ERROR:
7520 xname = "LINK DOWN ERROR";
7522 case MBOX_LOOPBACK_ERROR:
7523 xname = "LOOPBACK ERROR";
7525 case MBOX_CHECKSUM_ERROR:
7526 xname = "CHECKSUM ERROR";
7528 case MBOX_INVALID_PRODUCT_KEY:
7529 xname = "INVALID PRODUCT KEY";
7531 case MBOX_REGS_BUSY:
7532 xname = "REGISTERS BUSY";
7538 ISP_SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
7543 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s%s)",
7544 cname, xname, sname);
7549 isp_fw_state(ispsoftc_t *isp, int chan)
7554 MBSINIT(&mbs, MBOX_GET_FW_STATE, MBLOGALL, 0);
7555 isp_mboxcmd(isp, &mbs);
7556 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
7557 return (mbs.param[1]);
7564 isp_spi_update(ispsoftc_t *isp, int chan)
7572 * There are no 'per-bus' settings for Fibre Channel.
7576 sdp = SDPARAM(isp, chan);
7579 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7580 uint16_t flags, period, offset;
7583 if (sdp->isp_devparam[tgt].dev_enable == 0) {
7584 sdp->isp_devparam[tgt].dev_update = 0;
7585 sdp->isp_devparam[tgt].dev_refresh = 0;
7586 isp_prt(isp, ISP_LOGDEBUG0, "skipping target %d bus %d update", tgt, chan);
7590 * If the goal is to update the status of the device,
7591 * take what's in goal_flags and try and set the device
7592 * toward that. Otherwise, if we're just refreshing the
7593 * current device state, get the current parameters.
7596 MBSINIT(&mbs, 0, MBLOGALL, 0);
7599 * Refresh overrides set
7601 if (sdp->isp_devparam[tgt].dev_refresh) {
7602 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
7604 } else if (sdp->isp_devparam[tgt].dev_update) {
7605 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
7608 * Make sure goal_flags has "Renegotiate on Error"
7609 * on and "Freeze Queue on Error" off.
7611 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
7612 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
7613 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
7616 * Insist that PARITY must be enabled
7617 * if SYNC or WIDE is enabled.
7619 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
7620 mbs.param[2] |= DPARM_PARITY;
7623 if (mbs.param[2] & DPARM_SYNC) {
7625 (sdp->isp_devparam[tgt].goal_offset << 8) |
7626 (sdp->isp_devparam[tgt].goal_period);
7629 * A command completion later that has
7630 * RQSTF_NEGOTIATION set can cause
7631 * the dev_refresh/announce cycle also.
7633 * Note: It is really important to update our current
7634 * flags with at least the state of TAG capabilities-
7635 * otherwise we might try and send a tagged command
7636 * when we have it all turned off. So change it here
7637 * to say that current already matches goal.
7639 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
7640 sdp->isp_devparam[tgt].actv_flags |=
7641 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
7642 isp_prt(isp, ISP_LOGDEBUG0, "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
7643 chan, tgt, mbs.param[2], mbs.param[3] >> 8, mbs.param[3] & 0xff);
7648 mbs.param[1] = (chan << 15) | (tgt << 8);
7649 isp_mboxcmd(isp, &mbs);
7650 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7654 sdp->sendmarker = 1;
7655 sdp->isp_devparam[tgt].dev_update = 0;
7656 sdp->isp_devparam[tgt].dev_refresh = 1;
7658 sdp->isp_devparam[tgt].dev_refresh = 0;
7659 flags = mbs.param[2];
7660 period = mbs.param[3] & 0xff;
7661 offset = mbs.param[3] >> 8;
7662 sdp->isp_devparam[tgt].actv_flags = flags;
7663 sdp->isp_devparam[tgt].actv_period = period;
7664 sdp->isp_devparam[tgt].actv_offset = offset;
7665 isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, chan, tgt);
7669 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7670 if (sdp->isp_devparam[tgt].dev_update ||
7671 sdp->isp_devparam[tgt].dev_refresh) {
7679 isp_setdfltsdparm(ispsoftc_t *isp)
7682 sdparam *sdp, *sdp1;
7684 sdp = SDPARAM(isp, 0);
7685 if (IS_DUALBUS(isp))
7691 * Establish some default parameters.
7693 sdp->isp_cmd_dma_burst_enable = 0;
7694 sdp->isp_data_dma_burst_enabl = 1;
7695 sdp->isp_fifo_threshold = 0;
7696 sdp->isp_initiator_id = DEFAULT_IID(isp, 0);
7697 if (isp->isp_type >= ISP_HA_SCSI_1040) {
7698 sdp->isp_async_data_setup = 9;
7700 sdp->isp_async_data_setup = 6;
7702 sdp->isp_selection_timeout = 250;
7703 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
7704 sdp->isp_tag_aging = 8;
7705 sdp->isp_bus_reset_delay = 5;
7707 * Don't retry selection, busy or queue full automatically- reflect
7710 sdp->isp_retry_count = 0;
7711 sdp->isp_retry_delay = 0;
7713 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7714 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
7715 sdp->isp_devparam[tgt].dev_enable = 1;
7719 * The trick here is to establish a default for the default (honk!)
7720 * state (goal_flags). Then try and get the current status from
7721 * the card to fill in the current state. We don't, in fact, set
7722 * the default to the SAFE default state- that's not the goal state.
7724 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7726 sdp->isp_devparam[tgt].actv_offset = 0;
7727 sdp->isp_devparam[tgt].actv_period = 0;
7728 sdp->isp_devparam[tgt].actv_flags = 0;
7730 sdp->isp_devparam[tgt].goal_flags =
7731 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
7734 * We default to Wide/Fast for versions less than a 1040
7735 * (unless it's SBus).
7737 if (IS_ULTRA3(isp)) {
7738 off = ISP_80M_SYNCPARMS >> 8;
7739 per = ISP_80M_SYNCPARMS & 0xff;
7740 } else if (IS_ULTRA2(isp)) {
7741 off = ISP_40M_SYNCPARMS >> 8;
7742 per = ISP_40M_SYNCPARMS & 0xff;
7743 } else if (IS_1240(isp)) {
7744 off = ISP_20M_SYNCPARMS >> 8;
7745 per = ISP_20M_SYNCPARMS & 0xff;
7746 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
7747 isp->isp_type < ISP_HA_SCSI_1020A) ||
7748 (isp->isp_bustype == ISP_BT_PCI &&
7749 isp->isp_type < ISP_HA_SCSI_1040) ||
7750 (isp->isp_clock && isp->isp_clock < 60) ||
7751 (sdp->isp_ultramode == 0)) {
7752 off = ISP_10M_SYNCPARMS >> 8;
7753 per = ISP_10M_SYNCPARMS & 0xff;
7755 off = ISP_20M_SYNCPARMS_1040 >> 8;
7756 per = ISP_20M_SYNCPARMS_1040 & 0xff;
7758 sdp->isp_devparam[tgt].goal_offset =
7759 sdp->isp_devparam[tgt].nvrm_offset = off;
7760 sdp->isp_devparam[tgt].goal_period =
7761 sdp->isp_devparam[tgt].nvrm_period = per;
7766 * If we're a dual bus card, just copy the data over
7770 sdp1->isp_initiator_id = DEFAULT_IID(isp, 1);
7774 * If we've not been told to avoid reading NVRAM, try and read it.
7775 * If we're successful reading it, we can then return because NVRAM
7776 * will tell us what the desired settings are. Otherwise, we establish
7777 * some reasonable 'fake' nvram and goal defaults.
7779 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7782 if (isp_read_nvram(isp, 0) == 0) {
7783 if (IS_DUALBUS(isp)) {
7784 if (isp_read_nvram(isp, 1) == 0) {
7789 MBSINIT(&mbs, MBOX_GET_ACT_NEG_STATE, MBLOGNONE, 0);
7790 isp_mboxcmd(isp, &mbs);
7791 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7792 sdp->isp_req_ack_active_neg = 1;
7793 sdp->isp_data_line_active_neg = 1;
7795 sdp1->isp_req_ack_active_neg = 1;
7796 sdp1->isp_data_line_active_neg = 1;
7799 sdp->isp_req_ack_active_neg =
7800 (mbs.param[1] >> 4) & 0x1;
7801 sdp->isp_data_line_active_neg =
7802 (mbs.param[1] >> 5) & 0x1;
7804 sdp1->isp_req_ack_active_neg =
7805 (mbs.param[2] >> 4) & 0x1;
7806 sdp1->isp_data_line_active_neg =
7807 (mbs.param[2] >> 5) & 0x1;
7815 isp_setdfltfcparm(ispsoftc_t *isp, int chan)
7817 fcparam *fcp = FCPARAM(isp, chan);
7820 * Establish some default parameters.
7822 fcp->role = DEFAULT_ROLE(isp, chan);
7823 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
7824 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
7825 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
7826 fcp->isp_loopid = DEFAULT_LOOPID(isp, chan);
7827 fcp->isp_wwnn_nvram = DEFAULT_NODEWWN(isp, chan);
7828 fcp->isp_wwpn_nvram = DEFAULT_PORTWWN(isp, chan);
7829 fcp->isp_fwoptions = 0;
7830 fcp->isp_xfwoptions = 0;
7831 fcp->isp_zfwoptions = 0;
7832 fcp->isp_lasthdl = NIL_HANDLE;
7833 fcp->isp_login_hdl = NIL_HANDLE;
7836 fcp->isp_fwoptions |= ICB2400_OPT1_FAIRNESS;
7837 fcp->isp_fwoptions |= ICB2400_OPT1_HARD_ADDRESS;
7838 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
7839 fcp->isp_fwoptions |= ICB2400_OPT1_FULL_DUPLEX;
7840 fcp->isp_fwoptions |= ICB2400_OPT1_BOTH_WWNS;
7841 fcp->isp_xfwoptions |= ICB2400_OPT2_LOOP_2_PTP;
7842 fcp->isp_zfwoptions |= ICB2400_OPT3_RATE_AUTO;
7844 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
7845 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
7846 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
7847 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
7848 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
7850 * Make sure this is turned off now until we get
7851 * extended options from NVRAM
7853 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
7854 fcp->isp_xfwoptions |= ICBXOPT_LOOP_2_PTP;
7855 fcp->isp_zfwoptions |= ICBZOPT_RATE_AUTO;
7860 * Now try and read NVRAM unless told to not do so.
7861 * This will set fcparam's isp_wwnn_nvram && isp_wwpn_nvram.
7863 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7866 * Give a couple of tries at reading NVRAM.
7868 for (i = 0; i < 2; i++) {
7869 j = isp_read_nvram(isp, chan);
7875 isp->isp_confopts |= ISP_CFG_NONVRAM;
7879 fcp->isp_wwnn = ACTIVE_NODEWWN(isp, chan);
7880 fcp->isp_wwpn = ACTIVE_PORTWWN(isp, chan);
7881 isp_prt(isp, ISP_LOGCONFIG, "Chan %d 0x%08x%08x/0x%08x%08x Role %s",
7882 chan, (uint32_t) (fcp->isp_wwnn >> 32), (uint32_t) (fcp->isp_wwnn),
7883 (uint32_t) (fcp->isp_wwpn >> 32), (uint32_t) (fcp->isp_wwpn),
7884 isp_class3_roles[fcp->role]);
7888 * Re-initialize the ISP and complete all orphaned commands
7889 * with a 'botched' notice. The reset/init routines should
7890 * not disturb an already active list of commands.
7894 isp_reinit(ispsoftc_t *isp, int do_load_defaults)
7898 if (isp->isp_state == ISP_RUNSTATE)
7900 if (isp->isp_state != ISP_RESETSTATE)
7901 isp_reset(isp, do_load_defaults);
7902 if (isp->isp_state != ISP_RESETSTATE) {
7904 isp_prt(isp, ISP_LOGERR, "%s: cannot reset card", __func__);
7905 ISP_DISABLE_INTS(isp);
7910 if (isp->isp_state > ISP_RESETSTATE &&
7911 isp->isp_state != ISP_RUNSTATE) {
7913 isp_prt(isp, ISP_LOGERR, "%s: cannot init card", __func__);
7914 ISP_DISABLE_INTS(isp);
7917 * If we're in ISP_ROLE_NONE, turn off the lasers.
7919 if (!IS_24XX(isp)) {
7920 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
7921 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
7922 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
7923 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
7924 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
7930 isp->isp_nactive = 0;
7931 isp_clear_commands(isp);
7933 for (i = 0; i < isp->isp_nchan; i++)
7934 isp_clear_portdb(isp, i);
7943 isp_read_nvram(ispsoftc_t *isp, int bus)
7946 uint8_t csum, minversion;
7948 uint8_t _x[ISP2400_NVRAM_SIZE];
7949 uint16_t _s[ISP2400_NVRAM_SIZE>>1];
7951 #define nvram_data _n._x
7952 #define nvram_words _n._s
7955 return (isp_read_nvram_2400(isp, nvram_data));
7956 } else if (IS_FC(isp)) {
7957 amt = ISP2100_NVRAM_SIZE;
7959 } else if (IS_ULTRA2(isp)) {
7960 amt = ISP1080_NVRAM_SIZE;
7963 amt = ISP_NVRAM_SIZE;
7967 for (i = 0; i < amt>>1; i++) {
7968 isp_rdnvram_word(isp, i, &nvram_words[i]);
7971 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
7972 nvram_data[2] != 'P') {
7973 if (isp->isp_bustype != ISP_BT_SBUS) {
7974 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
7975 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x", nvram_data[0], nvram_data[1], nvram_data[2]);
7981 for (csum = 0, i = 0; i < amt; i++) {
7982 csum += nvram_data[i];
7985 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
7990 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
7991 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
7992 ISP_NVRAM_VERSION(nvram_data));
7997 if (IS_ULTRA3(isp)) {
7998 isp_parse_nvram_12160(isp, bus, nvram_data);
7999 } else if (IS_1080(isp)) {
8000 isp_parse_nvram_1080(isp, bus, nvram_data);
8001 } else if (IS_1280(isp) || IS_1240(isp)) {
8002 isp_parse_nvram_1080(isp, bus, nvram_data);
8003 } else if (IS_SCSI(isp)) {
8004 isp_parse_nvram_1020(isp, nvram_data);
8006 isp_parse_nvram_2100(isp, nvram_data);
8016 isp_read_nvram_2400(ispsoftc_t *isp, uint8_t *nvram_data)
8019 uint32_t addr, csum, lwrds, *dptr;
8021 if (isp->isp_port) {
8022 addr = ISP2400_NVRAM_PORT1_ADDR;
8024 addr = ISP2400_NVRAM_PORT0_ADDR;
8027 dptr = (uint32_t *) nvram_data;
8028 for (lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
8029 isp_rd_2400_nvram(isp, addr++, dptr++);
8031 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
8032 nvram_data[2] != 'P') {
8033 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header (%x %x %x)",
8034 nvram_data[0], nvram_data[1], nvram_data[2]);
8038 dptr = (uint32_t *) nvram_data;
8039 for (csum = 0, lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
8041 ISP_IOXGET_32(isp, &dptr[lwrds], tmp);
8045 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
8049 isp_parse_nvram_2400(isp, nvram_data);
8055 isp_rdnvram_word(ispsoftc_t *isp, int wo, uint16_t *rp)
8058 uint16_t bit, rqst, junk;
8060 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
8062 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
8066 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
8067 if (IS_2312(isp) && isp->isp_port) {
8070 rqst = (ISP_NVRAM_READ << 8) | wo;
8072 } else if (IS_ULTRA2(isp)) {
8073 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
8074 rqst = (ISP_NVRAM_READ << 8) | wo;
8077 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
8078 rqst = (ISP_NVRAM_READ << 6) | wo;
8083 * Clock the word select request out...
8085 for (i = cbits; i >= 0; i--) {
8086 if ((rqst >> i) & 1) {
8087 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
8089 bit = BIU_NVRAM_SELECT;
8091 ISP_WRITE(isp, BIU_NVRAM, bit);
8093 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
8094 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
8096 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
8097 ISP_WRITE(isp, BIU_NVRAM, bit);
8099 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
8102 * Now read the result back in (bits come back in MSB format).
8105 for (i = 0; i < 16; i++) {
8108 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
8110 rv = ISP_READ(isp, BIU_NVRAM);
8111 if (rv & BIU_NVRAM_DATAIN) {
8115 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
8117 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
8119 ISP_WRITE(isp, BIU_NVRAM, 0);
8121 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
8122 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
8126 isp_rd_2400_nvram(ispsoftc_t *isp, uint32_t addr, uint32_t *rp)
8129 uint32_t base = 0x7ffe0000;
8133 base = 0x7fe7c000; /* XXX: Observation, may be wrong. */
8134 } else if (IS_25XX(isp)) {
8135 base = 0x7ff00000 | 0x48000;
8137 ISP_WRITE(isp, BIU2400_FLASH_ADDR, base | addr);
8138 for (loops = 0; loops < 5000; loops++) {
8140 tmp = ISP_READ(isp, BIU2400_FLASH_ADDR);
8141 if ((tmp & (1U << 31)) != 0) {
8145 if (tmp & (1U << 31)) {
8146 *rp = ISP_READ(isp, BIU2400_FLASH_DATA);
8147 ISP_SWIZZLE_NVRAM_LONG(isp, rp);
8154 isp_parse_nvram_1020(ispsoftc_t *isp, uint8_t *nvram_data)
8156 sdparam *sdp = SDPARAM(isp, 0);
8159 sdp->isp_fifo_threshold =
8160 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
8161 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
8163 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
8164 sdp->isp_initiator_id = ISP_NVRAM_INITIATOR_ID(nvram_data);
8166 sdp->isp_bus_reset_delay =
8167 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
8169 sdp->isp_retry_count =
8170 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
8172 sdp->isp_retry_delay =
8173 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
8175 sdp->isp_async_data_setup =
8176 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
8178 if (isp->isp_type >= ISP_HA_SCSI_1040) {
8179 if (sdp->isp_async_data_setup < 9) {
8180 sdp->isp_async_data_setup = 9;
8183 if (sdp->isp_async_data_setup != 6) {
8184 sdp->isp_async_data_setup = 6;
8188 sdp->isp_req_ack_active_neg =
8189 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
8191 sdp->isp_data_line_active_neg =
8192 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
8194 sdp->isp_data_dma_burst_enabl =
8195 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
8197 sdp->isp_cmd_dma_burst_enable =
8198 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
8200 sdp->isp_tag_aging =
8201 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
8203 sdp->isp_selection_timeout =
8204 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
8206 sdp->isp_max_queue_depth =
8207 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
8209 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
8211 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
8212 sdp->isp_devparam[tgt].dev_enable =
8213 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
8214 sdp->isp_devparam[tgt].exc_throttle =
8215 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
8216 sdp->isp_devparam[tgt].nvrm_offset =
8217 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
8218 sdp->isp_devparam[tgt].nvrm_period =
8219 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
8221 * We probably shouldn't lie about this, but it
8222 * it makes it much safer if we limit NVRAM values
8225 if (isp->isp_type < ISP_HA_SCSI_1040) {
8227 * If we're not ultra, we can't possibly
8228 * be a shorter period than this.
8230 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
8231 sdp->isp_devparam[tgt].nvrm_period = 0x19;
8233 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
8234 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
8237 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
8238 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
8241 sdp->isp_devparam[tgt].nvrm_flags = 0;
8242 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
8243 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
8244 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
8245 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
8246 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
8247 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
8248 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
8249 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
8250 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
8251 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
8252 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
8253 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
8254 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
8255 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
8256 sdp->isp_devparam[tgt].goal_offset =
8257 sdp->isp_devparam[tgt].nvrm_offset;
8258 sdp->isp_devparam[tgt].goal_period =
8259 sdp->isp_devparam[tgt].nvrm_period;
8260 sdp->isp_devparam[tgt].goal_flags =
8261 sdp->isp_devparam[tgt].nvrm_flags;
8266 isp_parse_nvram_1080(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
8268 sdparam *sdp = SDPARAM(isp, bus);
8271 sdp->isp_fifo_threshold =
8272 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
8274 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
8275 sdp->isp_initiator_id = ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
8277 sdp->isp_bus_reset_delay =
8278 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
8280 sdp->isp_retry_count =
8281 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
8283 sdp->isp_retry_delay =
8284 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
8286 sdp->isp_async_data_setup =
8287 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
8289 sdp->isp_req_ack_active_neg =
8290 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
8292 sdp->isp_data_line_active_neg =
8293 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
8295 sdp->isp_data_dma_burst_enabl =
8296 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
8298 sdp->isp_cmd_dma_burst_enable =
8299 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
8301 sdp->isp_selection_timeout =
8302 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
8304 sdp->isp_max_queue_depth =
8305 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
8307 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
8308 sdp->isp_devparam[tgt].dev_enable =
8309 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
8310 sdp->isp_devparam[tgt].exc_throttle =
8311 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
8312 sdp->isp_devparam[tgt].nvrm_offset =
8313 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
8314 sdp->isp_devparam[tgt].nvrm_period =
8315 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
8316 sdp->isp_devparam[tgt].nvrm_flags = 0;
8317 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
8318 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
8319 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
8320 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
8321 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
8322 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
8323 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
8324 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
8325 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
8326 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
8327 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
8328 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
8329 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
8330 sdp->isp_devparam[tgt].actv_flags = 0;
8331 sdp->isp_devparam[tgt].goal_offset =
8332 sdp->isp_devparam[tgt].nvrm_offset;
8333 sdp->isp_devparam[tgt].goal_period =
8334 sdp->isp_devparam[tgt].nvrm_period;
8335 sdp->isp_devparam[tgt].goal_flags =
8336 sdp->isp_devparam[tgt].nvrm_flags;
8341 isp_parse_nvram_12160(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
8343 sdparam *sdp = SDPARAM(isp, bus);
8346 sdp->isp_fifo_threshold =
8347 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
8349 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
8350 sdp->isp_initiator_id = ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
8352 sdp->isp_bus_reset_delay =
8353 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
8355 sdp->isp_retry_count =
8356 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
8358 sdp->isp_retry_delay =
8359 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
8361 sdp->isp_async_data_setup =
8362 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
8364 sdp->isp_req_ack_active_neg =
8365 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
8367 sdp->isp_data_line_active_neg =
8368 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
8370 sdp->isp_data_dma_burst_enabl =
8371 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
8373 sdp->isp_cmd_dma_burst_enable =
8374 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
8376 sdp->isp_selection_timeout =
8377 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
8379 sdp->isp_max_queue_depth =
8380 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
8382 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
8383 sdp->isp_devparam[tgt].dev_enable =
8384 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
8385 sdp->isp_devparam[tgt].exc_throttle =
8386 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
8387 sdp->isp_devparam[tgt].nvrm_offset =
8388 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
8389 sdp->isp_devparam[tgt].nvrm_period =
8390 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
8391 sdp->isp_devparam[tgt].nvrm_flags = 0;
8392 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
8393 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
8394 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
8395 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
8396 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
8397 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
8398 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
8399 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
8400 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
8401 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
8402 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
8403 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
8404 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
8405 sdp->isp_devparam[tgt].actv_flags = 0;
8406 sdp->isp_devparam[tgt].goal_offset =
8407 sdp->isp_devparam[tgt].nvrm_offset;
8408 sdp->isp_devparam[tgt].goal_period =
8409 sdp->isp_devparam[tgt].nvrm_period;
8410 sdp->isp_devparam[tgt].goal_flags =
8411 sdp->isp_devparam[tgt].nvrm_flags;
8416 isp_parse_nvram_2100(ispsoftc_t *isp, uint8_t *nvram_data)
8418 fcparam *fcp = FCPARAM(isp, 0);
8422 * There is NVRAM storage for both Port and Node entities-
8423 * but the Node entity appears to be unused on all the cards
8424 * I can find. However, we should account for this being set
8425 * at some point in the future.
8427 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
8428 * bits 48..60. In the case of the 2202, it appears that they do
8429 * use bit 48 to distinguish between the two instances on the card.
8430 * The 2204, which I've never seen, *probably* extends this method.
8432 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
8434 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
8435 (uint32_t) (wwn >> 32), (uint32_t) (wwn));
8436 if ((wwn >> 60) == 0) {
8437 wwn |= (((uint64_t) 2)<< 60);
8440 fcp->isp_wwpn_nvram = wwn;
8441 if (IS_2200(isp) || IS_23XX(isp)) {
8442 wwn = ISP2100_NVRAM_NODE_NAME(nvram_data);
8444 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
8445 (uint32_t) (wwn >> 32),
8447 if ((wwn >> 60) == 0) {
8448 wwn |= (((uint64_t) 2)<< 60);
8451 wwn = fcp->isp_wwpn_nvram & ~((uint64_t) 0xfff << 48);
8454 wwn &= ~((uint64_t) 0xfff << 48);
8456 fcp->isp_wwnn_nvram = wwn;
8458 fcp->isp_maxalloc = ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
8459 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
8460 DEFAULT_FRAMESIZE(isp) =
8461 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
8463 fcp->isp_retry_delay = ISP2100_NVRAM_RETRY_DELAY(nvram_data);
8464 fcp->isp_retry_count = ISP2100_NVRAM_RETRY_COUNT(nvram_data);
8465 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
8466 fcp->isp_loopid = ISP2100_NVRAM_HARDLOOPID(nvram_data);
8468 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
8469 DEFAULT_EXEC_THROTTLE(isp) =
8470 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
8472 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
8473 isp_prt(isp, ISP_LOGDEBUG0,
8474 "NVRAM 0x%08x%08x 0x%08x%08x maxalloc %d maxframelen %d",
8475 (uint32_t) (fcp->isp_wwnn_nvram >> 32),
8476 (uint32_t) fcp->isp_wwnn_nvram,
8477 (uint32_t) (fcp->isp_wwpn_nvram >> 32),
8478 (uint32_t) fcp->isp_wwpn_nvram,
8479 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data),
8480 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data));
8481 isp_prt(isp, ISP_LOGDEBUG0,
8482 "execthrottle %d fwoptions 0x%x hardloop %d tov %d",
8483 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
8484 ISP2100_NVRAM_OPTIONS(nvram_data),
8485 ISP2100_NVRAM_HARDLOOPID(nvram_data),
8486 ISP2100_NVRAM_TOV(nvram_data));
8487 fcp->isp_xfwoptions = ISP2100_XFW_OPTIONS(nvram_data);
8488 fcp->isp_zfwoptions = ISP2100_ZFW_OPTIONS(nvram_data);
8489 isp_prt(isp, ISP_LOGDEBUG0, "xfwoptions 0x%x zfw options 0x%x",
8490 ISP2100_XFW_OPTIONS(nvram_data), ISP2100_ZFW_OPTIONS(nvram_data));
8494 isp_parse_nvram_2400(ispsoftc_t *isp, uint8_t *nvram_data)
8496 fcparam *fcp = FCPARAM(isp, 0);
8499 isp_prt(isp, ISP_LOGDEBUG0,
8500 "NVRAM 0x%08x%08x 0x%08x%08x exchg_cnt %d maxframelen %d",
8501 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data) >> 32),
8502 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data)),
8503 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data) >> 32),
8504 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data)),
8505 ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data),
8506 ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data));
8507 isp_prt(isp, ISP_LOGDEBUG0,
8508 "NVRAM execthr %d loopid %d fwopt1 0x%x fwopt2 0x%x fwopt3 0x%x",
8509 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data),
8510 ISP2400_NVRAM_HARDLOOPID(nvram_data),
8511 ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data),
8512 ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data),
8513 ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data));
8515 wwn = ISP2400_NVRAM_PORT_NAME(nvram_data);
8516 fcp->isp_wwpn_nvram = wwn;
8518 wwn = ISP2400_NVRAM_NODE_NAME(nvram_data);
8520 if ((wwn >> 60) != 2 && (wwn >> 60) != 5) {
8524 if (wwn == 0 && (fcp->isp_wwpn_nvram >> 60) == 2) {
8525 wwn = fcp->isp_wwpn_nvram;
8526 wwn &= ~((uint64_t) 0xfff << 48);
8528 fcp->isp_wwnn_nvram = wwn;
8530 if (ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data)) {
8531 fcp->isp_maxalloc = ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data);
8533 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
8534 DEFAULT_FRAMESIZE(isp) =
8535 ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data);
8537 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
8538 fcp->isp_loopid = ISP2400_NVRAM_HARDLOOPID(nvram_data);
8540 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
8541 DEFAULT_EXEC_THROTTLE(isp) =
8542 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data);
8544 fcp->isp_fwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data);
8545 fcp->isp_xfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data);
8546 fcp->isp_zfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data);