2 * Copyright (c) 2009-2018 Alexander Motin <mav@FreeBSD.org>
3 * Copyright (c) 1997-2009 by Matthew Jacob
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * Machine and OS Independent (well, as best as possible)
32 * code for the Qlogic ISP SCSI and FC-SCSI adapters.
36 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
37 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
38 * ideas dredged from the Solaris driver.
42 * Include header file appropriate for platform we're building on.
45 #include <sys/cdefs.h>
46 __KERNEL_RCSID(0, "$NetBSD$");
47 #include <dev/ic/isp_netbsd.h>
50 #include <sys/cdefs.h>
51 __FBSDID("$FreeBSD$");
52 #include <dev/isp/isp_freebsd.h>
55 #include <dev/ic/isp_openbsd.h>
58 #include "isp_linux.h"
61 #include "isp_solaris.h"
67 #define MBOX_DELAY_COUNT 1000000 / 100
72 static const char notresp[] = "Unknown IOCB in RESPONSE Queue (type 0x%x) @ idx %d (next %d)";
73 static const char bun[] = "bad underrun (count %d, resid %d, status %s)";
74 static const char lipd[] = "Chan %d LIP destroyed %d active commands";
75 static const char sacq[] = "unable to acquire scratch area";
77 static const uint8_t alpa_map[] = {
78 0xef, 0xe8, 0xe4, 0xe2, 0xe1, 0xe0, 0xdc, 0xda,
79 0xd9, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xce,
80 0xcd, 0xcc, 0xcb, 0xca, 0xc9, 0xc7, 0xc6, 0xc5,
81 0xc3, 0xbc, 0xba, 0xb9, 0xb6, 0xb5, 0xb4, 0xb3,
82 0xb2, 0xb1, 0xae, 0xad, 0xac, 0xab, 0xaa, 0xa9,
83 0xa7, 0xa6, 0xa5, 0xa3, 0x9f, 0x9e, 0x9d, 0x9b,
84 0x98, 0x97, 0x90, 0x8f, 0x88, 0x84, 0x82, 0x81,
85 0x80, 0x7c, 0x7a, 0x79, 0x76, 0x75, 0x74, 0x73,
86 0x72, 0x71, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x69,
87 0x67, 0x66, 0x65, 0x63, 0x5c, 0x5a, 0x59, 0x56,
88 0x55, 0x54, 0x53, 0x52, 0x51, 0x4e, 0x4d, 0x4c,
89 0x4b, 0x4a, 0x49, 0x47, 0x46, 0x45, 0x43, 0x3c,
90 0x3a, 0x39, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31,
91 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x27, 0x26,
92 0x25, 0x23, 0x1f, 0x1e, 0x1d, 0x1b, 0x18, 0x17,
93 0x10, 0x0f, 0x08, 0x04, 0x02, 0x01, 0x00
97 * Local function prototypes.
99 static void isp_parse_async(ispsoftc_t *, uint16_t);
100 static void isp_parse_async_fc(ispsoftc_t *, uint16_t);
101 static int isp_handle_other_response(ispsoftc_t *, int, isphdr_t *, uint32_t *);
102 static void isp_parse_status(ispsoftc_t *, ispstatusreq_t *, XS_T *, uint32_t *);
103 static void isp_parse_status_24xx(ispsoftc_t *, isp24xx_statusreq_t *, XS_T *, uint32_t *);
104 static void isp_fastpost_complete(ispsoftc_t *, uint32_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_pt(ispsoftc_t *, int);
122 static int isp_scan_fabric(ispsoftc_t *, int);
123 static int isp_login_device(ispsoftc_t *, int, uint32_t, isp_pdb_t *, uint16_t *);
124 static int isp_send_change_request(ispsoftc_t *, int);
125 static int isp_register_fc4_type(ispsoftc_t *, int);
126 static int isp_register_fc4_features_24xx(ispsoftc_t *, int);
127 static int isp_register_port_name_24xx(ispsoftc_t *, int);
128 static int isp_register_node_name_24xx(ispsoftc_t *, int);
129 static uint16_t isp_next_handle(ispsoftc_t *, uint16_t *);
130 static int isp_fw_state(ispsoftc_t *, int);
131 static void isp_mboxcmd(ispsoftc_t *, mbreg_t *);
133 static void isp_spi_update(ispsoftc_t *, int);
134 static void isp_setdfltsdparm(ispsoftc_t *);
135 static void isp_setdfltfcparm(ispsoftc_t *, int);
136 static int isp_read_nvram(ispsoftc_t *, int);
137 static int isp_read_nvram_2400(ispsoftc_t *, uint8_t *);
138 static void isp_rdnvram_word(ispsoftc_t *, int, uint16_t *);
139 static void isp_rd_2400_nvram(ispsoftc_t *, uint32_t, uint32_t *);
140 static void isp_parse_nvram_1020(ispsoftc_t *, uint8_t *);
141 static void isp_parse_nvram_1080(ispsoftc_t *, int, uint8_t *);
142 static void isp_parse_nvram_12160(ispsoftc_t *, int, uint8_t *);
143 static void isp_parse_nvram_2100(ispsoftc_t *, uint8_t *);
144 static void isp_parse_nvram_2400(ispsoftc_t *, uint8_t *);
147 isp_change_fw_state(ispsoftc_t *isp, int chan, int state)
149 fcparam *fcp = FCPARAM(isp, chan);
151 if (fcp->isp_fwstate == state)
153 isp_prt(isp, ISP_LOGCONFIG|ISP_LOG_SANCFG,
154 "Chan %d Firmware state <%s->%s>", chan,
155 isp_fc_fw_statename(fcp->isp_fwstate), isp_fc_fw_statename(state));
156 fcp->isp_fwstate = state;
162 * Hit the chip over the head, download new f/w if available and set it running.
164 * Locking done elsewhere.
168 isp_reset(ispsoftc_t *isp, int do_load_defaults)
173 uint32_t code_org, val;
174 int loops, i, dodnld = 1;
175 const char *btype = "????";
176 static const char dcrc[] = "Downloaded RISC Code Checksum Failure";
179 * Basic types (SCSI, FibreChannel and PCI or SBus)
180 * have been set in the MD code. We figure out more
181 * here. Possibly more refined types based upon PCI
182 * identification. Chip revision has been gathered.
184 * After we've fired this chip up, zero out the conf1 register
185 * for SCSI adapters and do other settings for the 2100.
188 isp->isp_state = ISP_NILSTATE;
189 ISP_DISABLE_INTS(isp);
192 * Put the board into PAUSE mode (so we can read the SXP registers
193 * or write FPM/FBM registers).
196 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_HOST_INT);
197 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
198 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_PAUSE);
200 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
204 switch (isp->isp_type) {
238 * While we're paused, reset the FPM module and FBM
241 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
242 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
243 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
244 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
245 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
247 } else if (IS_1240(isp)) {
252 sdp = SDPARAM(isp, 0);
253 sdp->isp_ultramode = 1;
254 sdp = SDPARAM(isp, 1);
255 sdp->isp_ultramode = 1;
257 * XXX: Should probably do some bus sensing.
259 } else if (IS_ULTRA3(isp)) {
260 sdparam *sdp = isp->isp_param;
262 isp->isp_clock = 100;
266 else if (IS_12160(isp))
270 sdp->isp_lvdmode = 1;
272 if (IS_DUALBUS(isp)) {
274 sdp->isp_lvdmode = 1;
276 } else if (IS_ULTRA2(isp)) {
277 static const char m[] = "bus %d is in %s Mode";
279 sdparam *sdp = SDPARAM(isp, 0);
281 isp->isp_clock = 100;
285 else if (IS_1080(isp))
290 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
292 case ISP1080_LVD_MODE:
293 sdp->isp_lvdmode = 1;
294 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
296 case ISP1080_HVD_MODE:
297 sdp->isp_diffmode = 1;
298 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
300 case ISP1080_SE_MODE:
301 sdp->isp_ultramode = 1;
302 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
305 isp_prt(isp, ISP_LOGERR,
306 "unknown mode on bus %d (0x%x)", 0, l);
310 if (IS_DUALBUS(isp)) {
311 sdp = SDPARAM(isp, 1);
312 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
313 l &= ISP1080_MODE_MASK;
315 case ISP1080_LVD_MODE:
316 sdp->isp_lvdmode = 1;
317 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
319 case ISP1080_HVD_MODE:
320 sdp->isp_diffmode = 1;
321 isp_prt(isp, ISP_LOGCONFIG,
322 m, 1, "Differential");
324 case ISP1080_SE_MODE:
325 sdp->isp_ultramode = 1;
326 isp_prt(isp, ISP_LOGCONFIG,
327 m, 1, "Single-Ended");
330 isp_prt(isp, ISP_LOGERR,
331 "unknown mode on bus %d (0x%x)", 1, l);
336 sdparam *sdp = SDPARAM(isp, 0);
337 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
340 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
344 isp->isp_type = ISP_HA_SCSI_1020;
349 * Some 1020A chips are Ultra Capable, but don't
350 * run the clock rate up for that unless told to
351 * do so by the Ultra Capable bits being set.
354 isp->isp_type = ISP_HA_SCSI_1020A;
359 isp->isp_type = ISP_HA_SCSI_1040;
364 isp->isp_type = ISP_HA_SCSI_1040A;
369 isp->isp_type = ISP_HA_SCSI_1040B;
374 isp->isp_type = ISP_HA_SCSI_1040C;
379 * Now, while we're at it, gather info about ultra
380 * and/or differential mode.
382 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
383 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
384 sdp->isp_diffmode = 1;
386 sdp->isp_diffmode = 0;
388 i = ISP_READ(isp, RISC_PSR);
389 if (isp->isp_bustype == ISP_BT_SBUS) {
390 i &= RISC_PSR_SBUS_ULTRA;
392 i &= RISC_PSR_PCI_ULTRA;
395 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
396 sdp->isp_ultramode = 1;
398 * If we're in Ultra Mode, we have to be 60MHz clock-
399 * even for the SBus version.
403 sdp->isp_ultramode = 0;
405 * Clock is known. Gronk.
410 * Machine dependent clock (if set) overrides
411 * our generic determinations.
413 if (isp->isp_mdvec->dv_clock) {
414 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
415 isp->isp_clock = isp->isp_mdvec->dv_clock;
421 * Hit the chip over the head with hammer,
422 * and give it a chance to recover.
426 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
433 * Clear data && control DMA engines.
435 ISP_WRITE(isp, CDMA_CONTROL, DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
436 ISP_WRITE(isp, DDMA_CONTROL, DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
439 } else if (IS_24XX(isp)) {
441 * Stop DMA and wait for it to stop.
443 ISP_WRITE(isp, BIU2400_CSR, BIU2400_DMA_STOP|(3 << 4));
444 for (val = loops = 0; loops < 30000; loops++) {
446 val = ISP_READ(isp, BIU2400_CSR);
447 if ((val & BIU2400_DMA_ACTIVE) == 0) {
451 if (val & BIU2400_DMA_ACTIVE) {
452 isp_prt(isp, ISP_LOGERR, "DMA Failed to Stop on Reset");
456 * Hold it in SOFT_RESET and STOP state for 100us.
458 ISP_WRITE(isp, BIU2400_CSR, BIU2400_SOFT_RESET|BIU2400_DMA_STOP|(3 << 4));
460 for (loops = 0; loops < 10000; loops++) {
462 val = ISP_READ(isp, OUTMAILBOX0);
464 for (val = loops = 0; loops < 500000; loops ++) {
465 val = ISP_READ(isp, BIU2400_CSR);
466 if ((val & BIU2400_SOFT_RESET) == 0) {
470 if (val & BIU2400_SOFT_RESET) {
471 isp_prt(isp, ISP_LOGERR, "Failed to come out of reset");
475 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
482 * Clear data && control DMA engines.
484 ISP_WRITE(isp, CDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
485 ISP_WRITE(isp, TDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
486 ISP_WRITE(isp, RDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
490 * Wait for ISP to be ready to go...
492 loops = MBOX_DELAY_COUNT;
495 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET)) {
498 } else if (IS_24XX(isp)) {
499 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
503 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
508 ISP_DUMPREGS(isp, "chip reset timed out");
514 * After we've fired this chip up, zero out the conf1 register
515 * for SCSI adapters and other settings for the 2100.
519 ISP_WRITE(isp, BIU_CONF1, 0);
520 } else if (!IS_24XX(isp)) {
521 ISP_WRITE(isp, BIU2100_CSR, 0);
525 * Reset RISC Processor
528 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RESET);
529 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RELEASE);
530 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RESET);
532 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
534 ISP_WRITE(isp, BIU_SEMA, 0);
538 * Post-RISC Reset stuff.
541 for (val = loops = 0; loops < 5000000; loops++) {
543 val = ISP_READ(isp, OUTMAILBOX0);
549 isp_prt(isp, ISP_LOGERR, "reset didn't clear");
552 } else if (IS_SCSI(isp)) {
553 uint16_t tmp = isp->isp_mdvec->dv_conf1;
555 * Busted FIFO. Turn off all but burst enables.
557 if (isp->isp_type == ISP_HA_SCSI_1040A) {
558 tmp &= BIU_BURST_ENABLE;
560 ISP_SETBITS(isp, BIU_CONF1, tmp);
561 if (tmp & BIU_BURST_ENABLE) {
562 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
563 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
565 if (SDPARAM(isp, 0)->isp_ptisp) {
566 if (SDPARAM(isp, 0)->isp_ultramode) {
567 while (ISP_READ(isp, RISC_MTR) != 0x1313) {
568 ISP_WRITE(isp, RISC_MTR, 0x1313);
569 ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
572 ISP_WRITE(isp, RISC_MTR, 0x1212);
575 * PTI specific register
577 ISP_WRITE(isp, RISC_EMB, DUAL_BANK);
579 ISP_WRITE(isp, RISC_MTR, 0x1212);
581 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
583 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
584 if (IS_2200(isp) || IS_23XX(isp)) {
585 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
587 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
591 * Set up default request/response queue in-pointer/out-pointer
595 isp->isp_rqstinrp = BIU2400_REQINP;
596 isp->isp_rqstoutrp = BIU2400_REQOUTP;
597 isp->isp_respinrp = BIU2400_RSPINP;
598 isp->isp_respoutrp = BIU2400_RSPOUTP;
599 } else if (IS_23XX(isp)) {
600 isp->isp_rqstinrp = BIU_REQINP;
601 isp->isp_rqstoutrp = BIU_REQOUTP;
602 isp->isp_respinrp = BIU_RSPINP;
603 isp->isp_respoutrp = BIU_RSPOUTP;
605 isp->isp_rqstinrp = INMAILBOX4;
606 isp->isp_rqstoutrp = OUTMAILBOX4;
607 isp->isp_respinrp = OUTMAILBOX5;
608 isp->isp_respoutrp = INMAILBOX5;
610 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
611 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
612 ISP_WRITE(isp, isp->isp_respinrp, 0);
613 ISP_WRITE(isp, isp->isp_respoutrp, 0);
616 ISP_WRITE(isp, BIU2400_PRI_REQINP, 0);
617 ISP_WRITE(isp, BIU2400_PRI_REQOUTP, 0);
619 ISP_WRITE(isp, BIU2400_ATIO_RSPINP, 0);
620 ISP_WRITE(isp, BIU2400_ATIO_RSPOUTP, 0);
623 if (!IS_24XX(isp) && isp->isp_bustype == ISP_BT_PCI) {
624 /* Make sure the BIOS is disabled */
625 ISP_WRITE(isp, HCCR, PCI_HCCR_CMD_BIOS);
629 * Wait for everything to finish firing up.
631 * Avoid doing this on early 2312s because you can generate a PCI
632 * parity error (chip breakage).
634 if (IS_2312(isp) && isp->isp_revision < 2) {
637 loops = MBOX_DELAY_COUNT;
638 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
641 isp_prt(isp, ISP_LOGERR, "MBOX_BUSY never cleared on reset");
648 * Up until this point we've done everything by just reading or
649 * setting registers. From this point on we rely on at least *some*
650 * kind of firmware running in the card.
654 * Do some sanity checking by running a NOP command.
655 * If it succeeds, the ROM firmware is now running.
657 MBSINIT(&mbs, MBOX_NO_OP, MBLOGALL, 0);
658 isp_mboxcmd(isp, &mbs);
659 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
660 isp_prt(isp, ISP_LOGERR, "NOP command failed (%x)", mbs.param[0]);
665 * Do some operational tests
667 if (IS_SCSI(isp) || IS_24XX(isp)) {
668 static const uint16_t patterns[MAX_MAILBOX] = {
669 0x0000, 0xdead, 0xbeef, 0xffff,
670 0xa5a5, 0x5a5a, 0x7f7f, 0x7ff7,
671 0x3421, 0xabcd, 0xdcba, 0xfeef,
672 0xbead, 0xdebe, 0x2222, 0x3333,
673 0x5555, 0x6666, 0x7777, 0xaaaa,
674 0xffff, 0xdddd, 0x9999, 0x1fbc,
675 0x6666, 0x6677, 0x1122, 0x33ff,
676 0x0000, 0x0001, 0x1000, 0x1010,
678 int nmbox = ISP_NMBOX(isp);
681 MBSINIT(&mbs, MBOX_MAILBOX_REG_TEST, MBLOGALL, 0);
682 for (i = 1; i < nmbox; i++) {
683 mbs.param[i] = patterns[i];
685 isp_mboxcmd(isp, &mbs);
686 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
689 for (i = 1; i < nmbox; i++) {
690 if (mbs.param[i] != patterns[i]) {
691 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]);
698 * Download new Firmware, unless requested not to do so.
699 * This is made slightly trickier in some cases where the
700 * firmware of the ROM revision is newer than the revision
701 * compiled into the driver. So, where we used to compare
702 * versions of our f/w and the ROM f/w, now we just see
703 * whether we have f/w at all and whether a config flag
704 * has disabled our download.
706 if ((isp->isp_mdvec->dv_ispfw == NULL) || (isp->isp_confopts & ISP_CFG_NORELOAD)) {
711 * Set up DMA for the request and response queues.
712 * We do this now so we can use the request queue
713 * for dma to load firmware from.
715 if (ISP_MBOXDMASETUP(isp) != 0) {
716 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
722 code_org = ISP_CODE_ORG_2400;
723 } else if (IS_23XX(isp)) {
724 code_org = ISP_CODE_ORG_2300;
726 code_org = ISP_CODE_ORG;
729 isp->isp_loaded_fw = 0;
730 if (dodnld && IS_24XX(isp)) {
731 const uint32_t *ptr = isp->isp_mdvec->dv_ispfw;
735 * Keep loading until we run out of f/w.
737 code_org = ptr[2]; /* 1st load address is our start addr */
741 isp_prt(isp, ISP_LOGDEBUG0, "load 0x%x words of code at load address 0x%x", ptr[3], ptr[2]);
746 while (wi < ptr[3]) {
750 nw = min(wl, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) / 4);
751 cp = isp->isp_rquest;
752 for (i = 0; i < nw; i++)
753 ISP_IOXPUT_32(isp, ptr[wi + i], &cp[i]);
754 MEMORYBARRIER(isp, SYNC_REQUEST, 0, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)), -1);
755 MBSINIT(&mbs, MBOX_LOAD_RISC_RAM, MBLOGALL, 0);
757 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
758 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
759 mbs.param[4] = nw >> 16;
761 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
762 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
763 mbs.param[8] = la >> 16;
764 isp_prt(isp, ISP_LOGDEBUG0, "LOAD RISC RAM %u words at load address 0x%x", nw, la);
765 isp_mboxcmd(isp, &mbs);
766 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
767 isp_prt(isp, ISP_LOGERR, "F/W download failed");
780 isp->isp_loaded_fw = 1;
781 } else if (dodnld && IS_23XX(isp)) {
782 const uint16_t *ptr = isp->isp_mdvec->dv_ispfw;
783 uint16_t wi, wl, segno;
792 isp_prt(isp, ISP_LOGDEBUG0, "load 0x%x words of code at load address 0x%x", ptr[3], la);
797 while (wi < ptr[3]) {
801 nw = min(wl, min((1 << 15), ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) / 2));
802 cp = isp->isp_rquest;
803 for (i = 0; i < nw; i++)
804 ISP_IOXPUT_16(isp, ptr[wi + i], &cp[i]);
805 MEMORYBARRIER(isp, SYNC_REQUEST, 0, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)), -1);
806 MBSINIT(&mbs, 0, MBLOGALL, 0);
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_LOGDEBUG1, "LOAD RISC RAM 2100 %u words at load address 0x%x\n", nw, la);
817 mbs.param[0] = MBOX_LOAD_RISC_RAM;
819 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
820 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
822 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
823 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
824 mbs.param[8] = la >> 16;
825 isp_prt(isp, ISP_LOGDEBUG1, "LOAD RISC RAM %u words at load address 0x%x\n", nw, la);
827 isp_mboxcmd(isp, &mbs);
828 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
829 isp_prt(isp, ISP_LOGERR, "F/W download failed");
846 * If we're a 2322, the firmware actually comes in
847 * three chunks. We loaded the first at the code_org
848 * address. The other two chunks, which follow right
849 * after each other in memory here, get loaded at
850 * addresses specfied at offset 0x9..0xB.
855 la = ptr[5] | ((ptr[4] & 0x3f) << 16);
857 isp->isp_loaded_fw = 1;
859 const uint16_t *ptr = isp->isp_mdvec->dv_ispfw;
863 isp_prt(isp, ISP_LOGDEBUG1,
864 "WRITE RAM %u words at load address 0x%x", wl, code_org);
865 for (i = 0; i < wl; i++) {
866 MBSINIT(&mbs, MBOX_WRITE_RAM_WORD, MBLOGNONE, 0);
867 mbs.param[1] = code_org + i;
868 mbs.param[2] = ptr[i];
869 isp_mboxcmd(isp, &mbs);
870 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
871 isp_prt(isp, ISP_LOGERR,
872 "F/W download failed at word %d", i);
876 } else if (IS_26XX(isp)) {
877 isp_prt(isp, ISP_LOGDEBUG1, "loading firmware from flash");
878 MBSINIT(&mbs, MBOX_LOAD_FLASH_FIRMWARE, MBLOGALL, 5000000);
881 isp_mboxcmd(isp, &mbs);
882 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
883 isp_prt(isp, ISP_LOGERR, "Flash F/W load failed");
887 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
891 * If we loaded firmware, verify its checksum
893 if (isp->isp_loaded_fw) {
894 MBSINIT(&mbs, MBOX_VERIFY_CHECKSUM, MBLOGNONE, 0);
896 mbs.param[1] = code_org >> 16;
897 mbs.param[2] = code_org;
899 mbs.param[1] = code_org;
901 isp_mboxcmd(isp, &mbs);
902 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
903 isp_prt(isp, ISP_LOGERR, dcrc);
909 * Now start it rolling.
911 * If we didn't actually download f/w,
912 * we still need to (re)start it.
914 MBSINIT(&mbs, MBOX_EXEC_FIRMWARE, MBLOGALL, 5000000);
916 mbs.param[1] = code_org >> 16;
917 mbs.param[2] = code_org;
918 } else if (IS_24XX(isp)) {
919 mbs.param[1] = code_org >> 16;
920 mbs.param[2] = code_org;
921 if (isp->isp_loaded_fw) {
926 } else if (IS_2322(isp)) {
927 mbs.param[1] = code_org;
928 if (isp->isp_loaded_fw) {
934 mbs.param[1] = code_org;
936 isp_mboxcmd(isp, &mbs);
937 if (IS_2322(isp) || IS_24XX(isp)) {
938 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
945 * Set CLOCK RATE, but only if asked to.
947 if (isp->isp_clock) {
948 MBSINIT(&mbs, MBOX_SET_CLOCK_RATE, MBLOGALL, 0);
949 mbs.param[1] = isp->isp_clock;
950 isp_mboxcmd(isp, &mbs);
951 /* we will try not to care if this fails */
956 * Ask the chip for the current firmware version.
957 * This should prove that the new firmware is working.
959 MBSINIT(&mbs, MBOX_ABOUT_FIRMWARE, MBLOGALL, 5000000);
960 isp_mboxcmd(isp, &mbs);
961 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
966 * The SBus firmware that we are using apparently does not return
967 * major, minor, micro revisions in the mailbox registers, which
968 * is really, really, annoying.
970 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
972 #ifdef ISP_TARGET_MODE
973 isp->isp_fwrev[0] = 7;
974 isp->isp_fwrev[1] = 55;
976 isp->isp_fwrev[0] = 1;
977 isp->isp_fwrev[1] = 37;
979 isp->isp_fwrev[2] = 0;
982 isp->isp_fwrev[0] = mbs.param[1];
983 isp->isp_fwrev[1] = mbs.param[2];
984 isp->isp_fwrev[2] = mbs.param[3];
989 * We do not believe firmware attributes for 2100 code less
990 * than 1.17.0, unless it's the firmware we specifically
993 * Note that all 22XX and later f/w is greater than 1.X.0.
995 if ((ISP_FW_OLDER_THAN(isp, 1, 17, 1))) {
996 #ifdef USE_SMALLER_2100_FIRMWARE
997 isp->isp_fwattr = ISP_FW_ATTR_SCCLUN;
1002 isp->isp_fwattr = mbs.param[6];
1005 isp->isp_fwattr |= ((uint64_t) mbs.param[15]) << 16;
1006 if (isp->isp_fwattr & ISP2400_FW_ATTR_EXTNDED) {
1008 (((uint64_t) mbs.param[16]) << 32) |
1009 (((uint64_t) mbs.param[17]) << 48);
1013 isp->isp_fwattr = 0;
1016 isp_prt(isp, ISP_LOGCONFIG, "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
1017 btype, isp->isp_revision, dodnld? "loaded" : "resident", isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
1019 fwt = isp->isp_fwattr;
1021 buf = FCPARAM(isp, 0)->isp_scanscratch;
1022 ISP_SNPRINTF(buf, ISP_FC_SCRLEN, "Attributes:");
1023 if (fwt & ISP2400_FW_ATTR_CLASS2) {
1024 fwt ^=ISP2400_FW_ATTR_CLASS2;
1025 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s Class2", buf);
1027 if (fwt & ISP2400_FW_ATTR_IP) {
1028 fwt ^=ISP2400_FW_ATTR_IP;
1029 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s IP", buf);
1031 if (fwt & ISP2400_FW_ATTR_MULTIID) {
1032 fwt ^=ISP2400_FW_ATTR_MULTIID;
1033 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s MultiID", buf);
1035 if (fwt & ISP2400_FW_ATTR_SB2) {
1036 fwt ^=ISP2400_FW_ATTR_SB2;
1037 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s SB2", buf);
1039 if (fwt & ISP2400_FW_ATTR_T10CRC) {
1040 fwt ^=ISP2400_FW_ATTR_T10CRC;
1041 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s T10CRC", buf);
1043 if (fwt & ISP2400_FW_ATTR_VI) {
1044 fwt ^=ISP2400_FW_ATTR_VI;
1045 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VI", buf);
1047 if (fwt & ISP2400_FW_ATTR_MQ) {
1048 fwt ^=ISP2400_FW_ATTR_MQ;
1049 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s MQ", buf);
1051 if (fwt & ISP2400_FW_ATTR_MSIX) {
1052 fwt ^=ISP2400_FW_ATTR_MSIX;
1053 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s MSIX", buf);
1055 if (fwt & ISP2400_FW_ATTR_FCOE) {
1056 fwt ^=ISP2400_FW_ATTR_FCOE;
1057 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s FCOE", buf);
1059 if (fwt & ISP2400_FW_ATTR_VP0) {
1060 fwt ^= ISP2400_FW_ATTR_VP0;
1061 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VP0_Decoupling", buf);
1063 if (fwt & ISP2400_FW_ATTR_EXPFW) {
1064 fwt ^= ISP2400_FW_ATTR_EXPFW;
1065 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s (Experimental)", buf);
1067 if (fwt & ISP2400_FW_ATTR_HOTFW) {
1068 fwt ^= ISP2400_FW_ATTR_HOTFW;
1069 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s HotFW", buf);
1071 fwt &= ~ISP2400_FW_ATTR_EXTNDED;
1072 if (fwt & ISP2400_FW_ATTR_EXTVP) {
1073 fwt ^= ISP2400_FW_ATTR_EXTVP;
1074 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s ExtVP", buf);
1076 if (fwt & ISP2400_FW_ATTR_VN2VN) {
1077 fwt ^= ISP2400_FW_ATTR_VN2VN;
1078 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VN2VN", buf);
1080 if (fwt & ISP2400_FW_ATTR_EXMOFF) {
1081 fwt ^= ISP2400_FW_ATTR_EXMOFF;
1082 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s EXMOFF", buf);
1084 if (fwt & ISP2400_FW_ATTR_NPMOFF) {
1085 fwt ^= ISP2400_FW_ATTR_NPMOFF;
1086 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s NPMOFF", buf);
1088 if (fwt & ISP2400_FW_ATTR_DIFCHOP) {
1089 fwt ^= ISP2400_FW_ATTR_DIFCHOP;
1090 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s DIFCHOP", buf);
1092 if (fwt & ISP2400_FW_ATTR_SRIOV) {
1093 fwt ^= ISP2400_FW_ATTR_SRIOV;
1094 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s SRIOV", buf);
1096 if (fwt & ISP2400_FW_ATTR_ASICTMP) {
1097 fwt ^= ISP2400_FW_ATTR_ASICTMP;
1098 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s ASICTMP", buf);
1100 if (fwt & ISP2400_FW_ATTR_ATIOMQ) {
1101 fwt ^= ISP2400_FW_ATTR_ATIOMQ;
1102 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s ATIOMQ", buf);
1105 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s (unknown 0x%08x%08x)", buf,
1106 (uint32_t) (fwt >> 32), (uint32_t) fwt);
1108 isp_prt(isp, ISP_LOGCONFIG, "%s", buf);
1109 } else if (IS_FC(isp)) {
1110 buf = FCPARAM(isp, 0)->isp_scanscratch;
1111 ISP_SNPRINTF(buf, ISP_FC_SCRLEN, "Attributes:");
1112 if (fwt & ISP_FW_ATTR_TMODE) {
1113 fwt ^=ISP_FW_ATTR_TMODE;
1114 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s TargetMode", buf);
1116 if (fwt & ISP_FW_ATTR_SCCLUN) {
1117 fwt ^=ISP_FW_ATTR_SCCLUN;
1118 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s SCC-Lun", buf);
1120 if (fwt & ISP_FW_ATTR_FABRIC) {
1121 fwt ^=ISP_FW_ATTR_FABRIC;
1122 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s Fabric", buf);
1124 if (fwt & ISP_FW_ATTR_CLASS2) {
1125 fwt ^=ISP_FW_ATTR_CLASS2;
1126 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s Class2", buf);
1128 if (fwt & ISP_FW_ATTR_FCTAPE) {
1129 fwt ^=ISP_FW_ATTR_FCTAPE;
1130 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s FC-Tape", buf);
1132 if (fwt & ISP_FW_ATTR_IP) {
1133 fwt ^=ISP_FW_ATTR_IP;
1134 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s IP", buf);
1136 if (fwt & ISP_FW_ATTR_VI) {
1137 fwt ^=ISP_FW_ATTR_VI;
1138 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VI", buf);
1140 if (fwt & ISP_FW_ATTR_VI_SOLARIS) {
1141 fwt ^=ISP_FW_ATTR_VI_SOLARIS;
1142 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VI_SOLARIS", buf);
1144 if (fwt & ISP_FW_ATTR_2KLOGINS) {
1145 fwt ^=ISP_FW_ATTR_2KLOGINS;
1146 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s 2K-Login", buf);
1149 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s (unknown 0x%08x%08x)", buf,
1150 (uint32_t) (fwt >> 32), (uint32_t) fwt);
1152 isp_prt(isp, ISP_LOGCONFIG, "%s", buf);
1156 MBSINIT(&mbs, MBOX_GET_RESOURCE_COUNT, MBLOGALL, 0);
1157 isp_mboxcmd(isp, &mbs);
1158 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1161 isp->isp_maxcmds = mbs.param[3];
1163 MBSINIT(&mbs, MBOX_GET_FIRMWARE_STATUS, MBLOGALL, 0);
1164 isp_mboxcmd(isp, &mbs);
1165 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1168 isp->isp_maxcmds = mbs.param[2];
1170 isp_prt(isp, ISP_LOGCONFIG, "%d max I/O command limit set", isp->isp_maxcmds);
1173 * If we don't have Multi-ID f/w loaded, we need to restrict channels to one.
1174 * Only make this check for non-SCSI cards (I'm not sure firmware attributes
1177 if (IS_FC(isp) && isp->isp_nchan > 1) {
1178 if (!ISP_CAP_MULTI_ID(isp)) {
1179 isp_prt(isp, ISP_LOGWARN, "non-MULTIID f/w loaded, "
1180 "only can enable 1 of %d channels", isp->isp_nchan);
1182 } else if (!ISP_CAP_VP0(isp)) {
1183 isp_prt(isp, ISP_LOGWARN, "We can not use MULTIID "
1184 "feature properly without VP0_Decoupling");
1190 * Final DMA setup after we got isp_maxcmds.
1192 if (ISP_MBOXDMASETUP(isp) != 0) {
1193 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
1200 if (ISP_IRQSETUP(isp) != 0) {
1201 isp_prt(isp, ISP_LOGERR, "Cannot setup IRQ");
1204 ISP_ENABLE_INTS(isp);
1207 for (i = 0; i < isp->isp_nchan; i++)
1208 isp_change_fw_state(isp, i, FW_CONFIG_WAIT);
1211 isp->isp_state = ISP_RESETSTATE;
1214 * Okay- now that we have new firmware running, we now (re)set our
1215 * notion of how many luns we support. This is somewhat tricky because
1216 * if we haven't loaded firmware, we sometimes do not have an easy way
1217 * of knowing how many luns we support.
1219 * Expanded lun firmware gives you 32 luns for SCSI cards and
1220 * unlimited luns for Fibre Channel cards.
1222 * It turns out that even for QLogic 2100s with ROM 1.10 and above
1223 * we do get a firmware attributes word returned in mailbox register 6.
1225 * Because the lun is in a different position in the Request Queue
1226 * Entry structure for Fibre Channel with expanded lun firmware, we
1227 * can only support one lun (lun zero) when we don't know what kind
1228 * of firmware we're running.
1232 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
1233 isp->isp_maxluns = 32;
1235 isp->isp_maxluns = 8;
1238 isp->isp_maxluns = 8;
1241 if (ISP_CAP_SCCFW(isp)) {
1242 isp->isp_maxluns = 0; /* No limit -- 2/8 bytes */
1244 isp->isp_maxluns = 16;
1249 * We get some default values established. As a side
1250 * effect, NVRAM is read here (unless overriden by
1251 * a configuration flag).
1253 if (do_load_defaults) {
1255 isp_setdfltsdparm(isp);
1257 for (i = 0; i < isp->isp_nchan; i++) {
1258 isp_setdfltfcparm(isp, i);
1265 * Clean firmware shutdown.
1268 isp_stop(ispsoftc_t *isp)
1272 isp->isp_state = ISP_NILSTATE;
1273 MBSINIT(&mbs, MBOX_STOP_FIRMWARE, MBLOGALL, 500000);
1282 isp_mboxcmd(isp, &mbs);
1283 return (mbs.param[0] == MBOX_COMMAND_COMPLETE ? 0 : mbs.param[0]);
1287 * Hardware shutdown.
1290 isp_shutdown(ispsoftc_t *isp)
1293 if (isp->isp_state >= ISP_RESETSTATE)
1295 ISP_DISABLE_INTS(isp);
1298 ISP_WRITE(isp, BIU2400_ICR, 0);
1299 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_PAUSE);
1301 ISP_WRITE(isp, BIU_ICR, 0);
1302 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
1303 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
1304 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
1305 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
1306 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
1307 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
1310 ISP_WRITE(isp, BIU_ICR, 0);
1311 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
1316 * Initialize Parameters of Hardware to a known state.
1318 * Locks are held before coming here.
1321 isp_init(ispsoftc_t *isp)
1325 isp_fibre_init_2400(isp);
1327 isp_fibre_init(isp);
1335 isp_scsi_init(ispsoftc_t *isp)
1337 sdparam *sdp_chan0, *sdp_chan1;
1340 isp->isp_state = ISP_INITSTATE;
1342 sdp_chan0 = SDPARAM(isp, 0);
1343 sdp_chan1 = sdp_chan0;
1344 if (IS_DUALBUS(isp)) {
1345 sdp_chan1 = SDPARAM(isp, 1);
1348 /* First do overall per-card settings. */
1351 * If we have fast memory timing enabled, turn it on.
1353 if (sdp_chan0->isp_fast_mttr) {
1354 ISP_WRITE(isp, RISC_MTR, 0x1313);
1358 * Set Retry Delay and Count.
1359 * You set both channels at the same time.
1361 MBSINIT(&mbs, MBOX_SET_RETRY_COUNT, MBLOGALL, 0);
1362 mbs.param[1] = sdp_chan0->isp_retry_count;
1363 mbs.param[2] = sdp_chan0->isp_retry_delay;
1364 mbs.param[6] = sdp_chan1->isp_retry_count;
1365 mbs.param[7] = sdp_chan1->isp_retry_delay;
1366 isp_mboxcmd(isp, &mbs);
1367 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1372 * Set ASYNC DATA SETUP time. This is very important.
1374 MBSINIT(&mbs, MBOX_SET_ASYNC_DATA_SETUP_TIME, MBLOGALL, 0);
1375 mbs.param[1] = sdp_chan0->isp_async_data_setup;
1376 mbs.param[2] = sdp_chan1->isp_async_data_setup;
1377 isp_mboxcmd(isp, &mbs);
1378 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1383 * Set ACTIVE Negation State.
1385 MBSINIT(&mbs, MBOX_SET_ACT_NEG_STATE, MBLOGNONE, 0);
1387 (sdp_chan0->isp_req_ack_active_neg << 4) |
1388 (sdp_chan0->isp_data_line_active_neg << 5);
1390 (sdp_chan1->isp_req_ack_active_neg << 4) |
1391 (sdp_chan1->isp_data_line_active_neg << 5);
1392 isp_mboxcmd(isp, &mbs);
1393 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1394 isp_prt(isp, ISP_LOGERR,
1395 "failed to set active negation state (%d,%d), (%d,%d)",
1396 sdp_chan0->isp_req_ack_active_neg,
1397 sdp_chan0->isp_data_line_active_neg,
1398 sdp_chan1->isp_req_ack_active_neg,
1399 sdp_chan1->isp_data_line_active_neg);
1406 * Set the Tag Aging limit
1408 MBSINIT(&mbs, MBOX_SET_TAG_AGE_LIMIT, MBLOGALL, 0);
1409 mbs.param[1] = sdp_chan0->isp_tag_aging;
1410 mbs.param[2] = sdp_chan1->isp_tag_aging;
1411 isp_mboxcmd(isp, &mbs);
1412 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1413 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
1414 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
1419 * Set selection timeout.
1421 MBSINIT(&mbs, MBOX_SET_SELECT_TIMEOUT, MBLOGALL, 0);
1422 mbs.param[1] = sdp_chan0->isp_selection_timeout;
1423 mbs.param[2] = sdp_chan1->isp_selection_timeout;
1424 isp_mboxcmd(isp, &mbs);
1425 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1429 /* now do per-channel settings */
1430 isp_scsi_channel_init(isp, 0);
1431 if (IS_DUALBUS(isp))
1432 isp_scsi_channel_init(isp, 1);
1435 * Now enable request/response queues
1438 if (IS_ULTRA2(isp) || IS_1240(isp)) {
1439 MBSINIT(&mbs, MBOX_INIT_RES_QUEUE_A64, MBLOGALL, 0);
1440 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1441 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1442 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1444 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1445 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1446 isp_mboxcmd(isp, &mbs);
1447 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1450 isp->isp_residx = isp->isp_resodx = mbs.param[5];
1452 MBSINIT(&mbs, MBOX_INIT_REQ_QUEUE_A64, MBLOGALL, 0);
1453 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1454 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1455 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1457 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1458 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1459 isp_mboxcmd(isp, &mbs);
1460 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1463 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1465 MBSINIT(&mbs, MBOX_INIT_RES_QUEUE, MBLOGALL, 0);
1466 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1467 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1468 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1470 isp_mboxcmd(isp, &mbs);
1471 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1474 isp->isp_residx = isp->isp_resodx = mbs.param[5];
1476 MBSINIT(&mbs, MBOX_INIT_REQ_QUEUE, MBLOGALL, 0);
1477 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1478 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1479 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1481 isp_mboxcmd(isp, &mbs);
1482 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1485 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1489 * Turn on LVD transitions for ULTRA2 or better and other features
1491 * Now that we have 32 bit handles, don't do any fast posting
1492 * any more. For Ultra2/Ultra3 cards, we can turn on 32 bit RIO
1493 * operation or use fast posting. To be conservative, we'll only
1494 * do this for Ultra3 cards now because the other cards are so
1495 * rare for this author to find and test with.
1498 MBSINIT(&mbs, MBOX_SET_FW_FEATURES, MBLOGALL, 0);
1500 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1503 mbs.param[1] |= FW_FEATURE_FAST_POST;
1506 mbs.param[1] |= FW_FEATURE_RIO_32BIT;
1508 if (mbs.param[1] != 0) {
1509 uint16_t sfeat = mbs.param[1];
1510 isp_mboxcmd(isp, &mbs);
1511 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1512 isp_prt(isp, ISP_LOGINFO,
1513 "Enabled FW features (0x%x)", sfeat);
1517 isp->isp_state = ISP_RUNSTATE;
1521 isp_scsi_channel_init(ispsoftc_t *isp, int chan)
1527 sdp = SDPARAM(isp, chan);
1530 * Set (possibly new) Initiator ID.
1532 MBSINIT(&mbs, MBOX_SET_INIT_SCSI_ID, MBLOGALL, 0);
1533 mbs.param[1] = (chan << 7) | sdp->isp_initiator_id;
1534 isp_mboxcmd(isp, &mbs);
1535 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1538 isp_prt(isp, ISP_LOGINFO, "Chan %d Initiator ID is %d",
1539 chan, sdp->isp_initiator_id);
1543 * Set current per-target parameters to an initial safe minimum.
1545 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1549 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1552 #ifndef ISP_TARGET_MODE
1553 sdf = sdp->isp_devparam[tgt].goal_flags;
1554 sdf &= DPARM_SAFE_DFLT;
1556 * It is not quite clear when this changed over so that
1557 * we could force narrow and async for 1000/1020 cards,
1558 * but assume that this is only the case for loaded
1561 if (isp->isp_loaded_fw) {
1562 sdf |= DPARM_NARROW | DPARM_ASYNC;
1566 * The !$*!)$!$)* f/w uses the same index into some
1567 * internal table to decide how to respond to negotiations,
1568 * so if we've said "let's be safe" for ID X, and ID X
1569 * selects *us*, the negotiations will back to 'safe'
1570 * (as in narrow/async). What the f/w *should* do is
1571 * use the initiator id settings to decide how to respond.
1573 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1575 MBSINIT(&mbs, MBOX_SET_TARGET_PARAMS, MBLOGNONE, 0);
1576 mbs.param[1] = (chan << 15) | (tgt << 8);
1578 if ((sdf & DPARM_SYNC) == 0) {
1582 (sdp->isp_devparam[tgt].goal_offset << 8) |
1583 (sdp->isp_devparam[tgt].goal_period);
1585 isp_prt(isp, ISP_LOGDEBUG0, "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1586 chan, tgt, mbs.param[2], mbs.param[3] >> 8, mbs.param[3] & 0xff);
1587 isp_mboxcmd(isp, &mbs);
1588 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1589 sdf = DPARM_SAFE_DFLT;
1590 MBSINIT(&mbs, MBOX_SET_TARGET_PARAMS, MBLOGALL, 0);
1591 mbs.param[1] = (tgt << 8) | (chan << 15);
1594 isp_mboxcmd(isp, &mbs);
1595 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1601 * We don't update any information directly from the f/w
1602 * because we need to run at least one command to cause a
1603 * new state to be latched up. So, we just assume that we
1604 * converge to the values we just had set.
1606 * Ensure that we don't believe tagged queuing is enabled yet.
1607 * It turns out that sometimes the ISP just ignores our
1608 * attempts to set parameters for devices that it hasn't
1611 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1612 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1613 MBSINIT(&mbs, MBOX_SET_DEV_QUEUE_PARAMS, MBLOGALL, 0);
1614 mbs.param[1] = (chan << 15) | (tgt << 8) | lun;
1615 mbs.param[2] = sdp->isp_max_queue_depth;
1616 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1617 isp_mboxcmd(isp, &mbs);
1618 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1623 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1624 if (sdp->isp_devparam[tgt].dev_refresh) {
1625 sdp->sendmarker = 1;
1633 * Fibre Channel specific initialization.
1636 isp_fibre_init(ispsoftc_t *isp)
1639 isp_icb_t local, *icbp = &local;
1644 * We only support one channel on non-24XX cards
1646 fcp = FCPARAM(isp, 0);
1647 if (fcp->role == ISP_ROLE_NONE)
1650 isp->isp_state = ISP_INITSTATE;
1651 ISP_MEMZERO(icbp, sizeof (*icbp));
1652 icbp->icb_version = ICB_VERSION1;
1653 icbp->icb_fwoptions = fcp->isp_fwoptions;
1656 * Firmware Options are either retrieved from NVRAM or
1657 * are patched elsewhere. We check them for sanity here
1658 * and make changes based on board revision, but otherwise
1659 * let others decide policy.
1663 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1665 if (IS_2100(isp) && isp->isp_revision < 5) {
1666 icbp->icb_fwoptions &= ~ICBOPT_FAIRNESS;
1670 * We have to use FULL LOGIN even though it resets the loop too much
1671 * because otherwise port database entries don't get updated after
1672 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1674 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1675 icbp->icb_fwoptions |= ICBOPT_FULL_LOGIN;
1679 * Insist on Port Database Update Async notifications
1681 icbp->icb_fwoptions |= ICBOPT_PDBCHANGE_AE;
1684 * Make sure that target role reflects into fwoptions.
1686 if (fcp->role & ISP_ROLE_TARGET) {
1687 icbp->icb_fwoptions |= ICBOPT_TGT_ENABLE;
1689 icbp->icb_fwoptions &= ~ICBOPT_TGT_ENABLE;
1693 * For some reason my 2200 does not generate ATIOs in target mode
1694 * if initiator is disabled. Extra logins are better then target
1695 * not working at all.
1697 if ((fcp->role & ISP_ROLE_INITIATOR) || IS_2100(isp) || IS_2200(isp)) {
1698 icbp->icb_fwoptions &= ~ICBOPT_INI_DISABLE;
1700 icbp->icb_fwoptions |= ICBOPT_INI_DISABLE;
1703 icbp->icb_maxfrmlen = DEFAULT_FRAMESIZE(isp);
1704 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN || icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1705 isp_prt(isp, ISP_LOGERR, "bad frame length (%d) from NVRAM- using %d", DEFAULT_FRAMESIZE(isp), ICB_DFLT_FRMLEN);
1706 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1708 icbp->icb_maxalloc = fcp->isp_maxalloc;
1709 if (icbp->icb_maxalloc < 1) {
1710 isp_prt(isp, ISP_LOGERR, "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1711 icbp->icb_maxalloc = 16;
1713 icbp->icb_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
1714 if (icbp->icb_execthrottle < 1) {
1715 isp_prt(isp, ISP_LOGERR, "bad execution throttle of %d- using %d", DEFAULT_EXEC_THROTTLE(isp), ICB_DFLT_THROTTLE);
1716 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1718 icbp->icb_retry_delay = fcp->isp_retry_delay;
1719 icbp->icb_retry_count = fcp->isp_retry_count;
1720 icbp->icb_hardaddr = fcp->isp_loopid;
1721 ownloopid = (isp->isp_confopts & ISP_CFG_OWNLOOPID) != 0;
1722 if (icbp->icb_hardaddr >= LOCAL_LOOP_LIM) {
1723 icbp->icb_hardaddr = 0;
1728 * Our life seems so much better with 2200s and later with
1729 * the latest f/w if we set Hard Address.
1731 if (ownloopid || ISP_FW_NEWER_THAN(isp, 2, 2, 5)) {
1732 icbp->icb_fwoptions |= ICBOPT_HARD_ADDRESS;
1736 * Right now we just set extended options to prefer point-to-point
1737 * over loop based upon some soft config options.
1739 * NB: for the 2300, ICBOPT_EXTENDED is required.
1743 * We can't have Fast Posting any more- we now
1744 * have 32 bit handles.
1746 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1747 } else if (IS_2200(isp) || IS_23XX(isp)) {
1748 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1750 icbp->icb_xfwoptions = fcp->isp_xfwoptions;
1752 if (ISP_CAP_FCTAPE(isp)) {
1753 if (isp->isp_confopts & ISP_CFG_NOFCTAPE)
1754 icbp->icb_xfwoptions &= ~ICBXOPT_FCTAPE;
1756 if (isp->isp_confopts & ISP_CFG_FCTAPE)
1757 icbp->icb_xfwoptions |= ICBXOPT_FCTAPE;
1759 if (icbp->icb_xfwoptions & ICBXOPT_FCTAPE) {
1760 icbp->icb_fwoptions &= ~ICBOPT_FULL_LOGIN; /* per documents */
1761 icbp->icb_xfwoptions |= ICBXOPT_FCTAPE_CCQ|ICBXOPT_FCTAPE_CONFIRM;
1762 FCPARAM(isp, 0)->fctape_enabled = 1;
1764 FCPARAM(isp, 0)->fctape_enabled = 0;
1767 icbp->icb_xfwoptions &= ~ICBXOPT_FCTAPE;
1768 FCPARAM(isp, 0)->fctape_enabled = 0;
1772 * Prefer or force Point-To-Point instead Loop?
1774 switch (isp->isp_confopts & ISP_CFG_PORT_PREF) {
1775 case ISP_CFG_LPORT_ONLY:
1776 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1777 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1779 case ISP_CFG_NPORT_ONLY:
1780 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1781 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1784 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1785 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1788 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1789 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1792 /* Let NVRAM settings define it if they are sane */
1793 switch (icbp->icb_xfwoptions & ICBXOPT_TOPO_MASK) {
1794 case ICBXOPT_PTP_2_LOOP:
1795 case ICBXOPT_PTP_ONLY:
1796 case ICBXOPT_LOOP_ONLY:
1797 case ICBXOPT_LOOP_2_PTP:
1800 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1801 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1807 * We can't have Fast Posting any more- we now
1808 * have 32 bit handles.
1810 * RIO seemed to have to much breakage.
1812 * Just opt for safety.
1814 icbp->icb_xfwoptions &= ~ICBXOPT_RIO_16BIT;
1815 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1818 * QLogic recommends that FAST Posting be turned
1819 * off for 23XX cards and instead allow the HBA
1820 * to write response queue entries and interrupt
1821 * after a delay (ZIO).
1823 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1824 if ((fcp->isp_xfwoptions & ICBXOPT_TIMER_MASK) == ICBXOPT_ZIO) {
1825 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1826 icbp->icb_idelaytimer = 10;
1828 icbp->icb_zfwoptions = fcp->isp_zfwoptions;
1829 if (isp->isp_confopts & ISP_CFG_1GB) {
1830 icbp->icb_zfwoptions &= ~ICBZOPT_RATE_MASK;
1831 icbp->icb_zfwoptions |= ICBZOPT_RATE_1GB;
1832 } else if (isp->isp_confopts & ISP_CFG_2GB) {
1833 icbp->icb_zfwoptions &= ~ICBZOPT_RATE_MASK;
1834 icbp->icb_zfwoptions |= ICBZOPT_RATE_2GB;
1836 switch (icbp->icb_zfwoptions & ICBZOPT_RATE_MASK) {
1837 case ICBZOPT_RATE_1GB:
1838 case ICBZOPT_RATE_2GB:
1839 case ICBZOPT_RATE_AUTO:
1842 icbp->icb_zfwoptions &= ~ICBZOPT_RATE_MASK;
1843 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1852 * For 22XX > 2.1.26 && 23XX, set some options.
1854 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1855 MBSINIT(&mbs, MBOX_SET_FIRMWARE_OPTIONS, MBLOGALL, 0);
1856 mbs.param[1] = IFCOPT1_DISF7SWTCH|IFCOPT1_LIPASYNC|IFCOPT1_LIPF8;
1859 if (ISP_FW_NEWER_THAN(isp, 3, 16, 0)) {
1860 mbs.param[1] |= IFCOPT1_EQFQASYNC|IFCOPT1_CTIO_RETRY;
1861 if (fcp->role & ISP_ROLE_TARGET) {
1862 if (ISP_FW_NEWER_THAN(isp, 3, 25, 0)) {
1863 mbs.param[1] |= IFCOPT1_ENAPURE;
1865 mbs.param[3] = IFCOPT3_NOPRLI;
1868 isp_mboxcmd(isp, &mbs);
1869 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1873 icbp->icb_logintime = ICB_LOGIN_TOV;
1875 #ifdef ISP_TARGET_MODE
1876 if (icbp->icb_fwoptions & ICBOPT_TGT_ENABLE) {
1877 icbp->icb_lunenables = 0xffff;
1878 icbp->icb_ccnt = 0xff;
1879 icbp->icb_icnt = 0xff;
1880 icbp->icb_lunetimeout = ICB_LUN_ENABLE_TOV;
1883 if (fcp->isp_wwnn && fcp->isp_wwpn) {
1884 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1885 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, fcp->isp_wwnn);
1886 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1887 isp_prt(isp, ISP_LOGDEBUG1,
1888 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1889 ((uint32_t) (fcp->isp_wwnn >> 32)),
1890 ((uint32_t) (fcp->isp_wwnn)),
1891 ((uint32_t) (fcp->isp_wwpn >> 32)),
1892 ((uint32_t) (fcp->isp_wwpn)));
1893 } else if (fcp->isp_wwpn) {
1894 icbp->icb_fwoptions &= ~ICBOPT_BOTH_WWNS;
1895 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1896 isp_prt(isp, ISP_LOGDEBUG1,
1897 "Setting ICB Port 0x%08x%08x",
1898 ((uint32_t) (fcp->isp_wwpn >> 32)),
1899 ((uint32_t) (fcp->isp_wwpn)));
1901 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
1904 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1905 if (icbp->icb_rqstqlen < 1) {
1906 isp_prt(isp, ISP_LOGERR, "bad request queue length");
1908 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1909 if (icbp->icb_rsltqlen < 1) {
1910 isp_prt(isp, ISP_LOGERR, "bad result queue length");
1912 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1913 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1914 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1915 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1916 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1917 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1918 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1919 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1921 if (FC_SCRATCH_ACQUIRE(isp, 0)) {
1922 isp_prt(isp, ISP_LOGERR, sacq);
1925 isp_prt(isp, ISP_LOGDEBUG0, "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1926 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1928 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1929 if (isp->isp_dblev & ISP_LOGDEBUG1) {
1930 isp_print_bytes(isp, "isp_fibre_init",
1931 sizeof(*icbp), fcp->isp_scratch);
1937 MBSINIT(&mbs, MBOX_INIT_FIRMWARE, MBLOGALL, 30000000);
1939 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1940 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1941 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1942 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1943 isp_prt(isp, ISP_LOGDEBUG0, "INIT F/W from %p (%08x%08x)",
1944 fcp->isp_scratch, (uint32_t) ((uint64_t)fcp->isp_scdma >> 32),
1945 (uint32_t) fcp->isp_scdma);
1946 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp), 0);
1947 isp_mboxcmd(isp, &mbs);
1948 FC_SCRATCH_RELEASE(isp, 0);
1949 if (mbs.param[0] != MBOX_COMMAND_COMPLETE)
1951 isp->isp_reqidx = 0;
1952 isp->isp_reqodx = 0;
1953 isp->isp_residx = 0;
1954 isp->isp_resodx = 0;
1957 * Whatever happens, we're now committed to being here.
1959 isp->isp_state = ISP_RUNSTATE;
1963 isp_fibre_init_2400(ispsoftc_t *isp)
1966 isp_icb_2400_t local, *icbp = &local;
1972 * Check to see whether all channels have *some* kind of role
1974 for (chan = 0; chan < isp->isp_nchan; chan++) {
1975 fcp = FCPARAM(isp, chan);
1976 if (fcp->role != ISP_ROLE_NONE) {
1980 if (chan == isp->isp_nchan) {
1981 isp_prt(isp, ISP_LOG_WARN1, "all %d channels with role 'none'", chan);
1985 isp->isp_state = ISP_INITSTATE;
1988 * Start with channel 0.
1990 fcp = FCPARAM(isp, 0);
1993 * Turn on LIP F8 async event (1)
1995 MBSINIT(&mbs, MBOX_SET_FIRMWARE_OPTIONS, MBLOGALL, 0);
1997 isp_mboxcmd(isp, &mbs);
1998 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2002 ISP_MEMZERO(icbp, sizeof (*icbp));
2003 icbp->icb_fwoptions1 = fcp->isp_fwoptions;
2004 icbp->icb_fwoptions2 = fcp->isp_xfwoptions;
2005 icbp->icb_fwoptions3 = fcp->isp_zfwoptions;
2006 if (isp->isp_nchan > 1 && ISP_CAP_VP0(isp)) {
2007 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_INI_DISABLE;
2008 icbp->icb_fwoptions1 |= ICB2400_OPT1_TGT_ENABLE;
2010 if (fcp->role & ISP_ROLE_TARGET)
2011 icbp->icb_fwoptions1 |= ICB2400_OPT1_TGT_ENABLE;
2013 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_TGT_ENABLE;
2014 if (fcp->role & ISP_ROLE_INITIATOR)
2015 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_INI_DISABLE;
2017 icbp->icb_fwoptions1 |= ICB2400_OPT1_INI_DISABLE;
2020 icbp->icb_version = ICB_VERSION1;
2021 icbp->icb_maxfrmlen = DEFAULT_FRAMESIZE(isp);
2022 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN || icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
2023 isp_prt(isp, ISP_LOGERR, "bad frame length (%d) from NVRAM- using %d", DEFAULT_FRAMESIZE(isp), ICB_DFLT_FRMLEN);
2024 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
2027 icbp->icb_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
2028 if (icbp->icb_execthrottle < 1 && !IS_26XX(isp)) {
2029 isp_prt(isp, ISP_LOGERR, "bad execution throttle of %d- using %d", DEFAULT_EXEC_THROTTLE(isp), ICB_DFLT_THROTTLE);
2030 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
2034 * Set target exchange count. Take half if we are supporting both roles.
2036 if (icbp->icb_fwoptions1 & ICB2400_OPT1_TGT_ENABLE) {
2037 icbp->icb_xchgcnt = isp->isp_maxcmds;
2038 if ((icbp->icb_fwoptions1 & ICB2400_OPT1_INI_DISABLE) == 0)
2039 icbp->icb_xchgcnt >>= 1;
2043 ownloopid = (isp->isp_confopts & ISP_CFG_OWNLOOPID) != 0;
2044 icbp->icb_hardaddr = fcp->isp_loopid;
2045 if (icbp->icb_hardaddr >= LOCAL_LOOP_LIM) {
2046 icbp->icb_hardaddr = 0;
2051 icbp->icb_fwoptions1 |= ICB2400_OPT1_HARD_ADDRESS;
2053 if (isp->isp_confopts & ISP_CFG_NOFCTAPE) {
2054 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_FCTAPE;
2056 if (isp->isp_confopts & ISP_CFG_FCTAPE) {
2057 icbp->icb_fwoptions2 |= ICB2400_OPT2_FCTAPE;
2060 for (chan = 0; chan < isp->isp_nchan; chan++) {
2061 if (icbp->icb_fwoptions2 & ICB2400_OPT2_FCTAPE)
2062 FCPARAM(isp, chan)->fctape_enabled = 1;
2064 FCPARAM(isp, chan)->fctape_enabled = 0;
2067 switch (isp->isp_confopts & ISP_CFG_PORT_PREF) {
2068 case ISP_CFG_LPORT_ONLY:
2069 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2070 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_ONLY;
2072 case ISP_CFG_NPORT_ONLY:
2073 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2074 icbp->icb_fwoptions2 |= ICB2400_OPT2_PTP_ONLY;
2077 /* ISP_CFG_PTP_2_LOOP not available in 24XX/25XX */
2079 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2080 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_2_PTP;
2083 /* Let NVRAM settings define it if they are sane */
2084 switch (icbp->icb_fwoptions2 & ICB2400_OPT2_TOPO_MASK) {
2085 case ICB2400_OPT2_LOOP_ONLY:
2086 case ICB2400_OPT2_PTP_ONLY:
2087 case ICB2400_OPT2_LOOP_2_PTP:
2090 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2091 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_2_PTP;
2096 switch (icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK) {
2097 case ICB2400_OPT2_ZIO:
2098 case ICB2400_OPT2_ZIO1:
2099 icbp->icb_idelaytimer = 0;
2104 isp_prt(isp, ISP_LOGWARN, "bad value %x in fwopt2 timer field", icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK);
2105 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TIMER_MASK;
2110 /* Use handshake to reduce global lock congestion. */
2111 icbp->icb_fwoptions2 |= ICB2400_OPT2_ENA_IHR;
2112 icbp->icb_fwoptions2 |= ICB2400_OPT2_ENA_IHA;
2115 if ((icbp->icb_fwoptions3 & ICB2400_OPT3_RSPSZ_MASK) == 0) {
2116 icbp->icb_fwoptions3 |= ICB2400_OPT3_RSPSZ_24;
2118 if (isp->isp_confopts & ISP_CFG_1GB) {
2119 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2120 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_1GB;
2121 } else if (isp->isp_confopts & ISP_CFG_2GB) {
2122 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2123 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_2GB;
2124 } else if (isp->isp_confopts & ISP_CFG_4GB) {
2125 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2126 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_4GB;
2127 } else if (isp->isp_confopts & ISP_CFG_8GB) {
2128 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2129 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_8GB;
2130 } else if (isp->isp_confopts & ISP_CFG_16GB) {
2131 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2132 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_16GB;
2133 } else if (isp->isp_confopts & ISP_CFG_32GB) {
2134 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2135 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_32GB;
2137 switch (icbp->icb_fwoptions3 & ICB2400_OPT3_RATE_MASK) {
2138 case ICB2400_OPT3_RATE_4GB:
2139 case ICB2400_OPT3_RATE_8GB:
2140 case ICB2400_OPT3_RATE_16GB:
2141 case ICB2400_OPT3_RATE_32GB:
2142 case ICB2400_OPT3_RATE_AUTO:
2144 case ICB2400_OPT3_RATE_2GB:
2145 if (isp->isp_type <= ISP_HA_FC_2500)
2148 case ICB2400_OPT3_RATE_1GB:
2149 if (isp->isp_type <= ISP_HA_FC_2400)
2153 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2154 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_AUTO;
2158 if (ownloopid == 0) {
2159 icbp->icb_fwoptions3 |= ICB2400_OPT3_SOFTID;
2161 icbp->icb_logintime = ICB_LOGIN_TOV;
2163 if (fcp->isp_wwnn && fcp->isp_wwpn) {
2164 icbp->icb_fwoptions1 |= ICB2400_OPT1_BOTH_WWNS;
2165 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
2166 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, fcp->isp_wwnn);
2167 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)),
2168 ((uint32_t) (fcp->isp_wwpn >> 32)), ((uint32_t) (fcp->isp_wwpn)));
2169 } else if (fcp->isp_wwpn) {
2170 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_BOTH_WWNS;
2171 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
2172 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)));
2174 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
2177 icbp->icb_retry_count = fcp->isp_retry_count;
2179 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
2180 if (icbp->icb_rqstqlen < 8) {
2181 isp_prt(isp, ISP_LOGERR, "bad request queue length %d", icbp->icb_rqstqlen);
2184 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
2185 if (icbp->icb_rsltqlen < 8) {
2186 isp_prt(isp, ISP_LOGERR, "bad result queue length %d",
2187 icbp->icb_rsltqlen);
2190 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
2191 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
2192 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
2193 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
2195 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
2196 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
2197 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
2198 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
2200 #ifdef ISP_TARGET_MODE
2201 /* unconditionally set up the ATIO queue if we support target mode */
2202 icbp->icb_atioqlen = RESULT_QUEUE_LEN(isp);
2203 if (icbp->icb_atioqlen < 8) {
2204 isp_prt(isp, ISP_LOGERR, "bad ATIO queue length %d", icbp->icb_atioqlen);
2207 icbp->icb_atioqaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_atioq_dma);
2208 icbp->icb_atioqaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_atioq_dma);
2209 icbp->icb_atioqaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_atioq_dma);
2210 icbp->icb_atioqaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_atioq_dma);
2211 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),
2212 DMA_WD1(isp->isp_atioq_dma), DMA_WD0(isp->isp_atioq_dma));
2215 if (ISP_CAP_MSIX(isp) && isp->isp_nirq >= 2) {
2216 icbp->icb_msixresp = 1;
2217 if (IS_26XX(isp) && isp->isp_nirq >= 3)
2218 icbp->icb_msixatio = 2;
2221 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);
2223 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),
2224 DMA_WD1(isp->isp_rquest_dma), DMA_WD0(isp->isp_rquest_dma), DMA_WD3(isp->isp_result_dma), DMA_WD2(isp->isp_result_dma),
2225 DMA_WD1(isp->isp_result_dma), DMA_WD0(isp->isp_result_dma));
2227 if (FC_SCRATCH_ACQUIRE(isp, 0)) {
2228 isp_prt(isp, ISP_LOGERR, sacq);
2231 ISP_MEMZERO(fcp->isp_scratch, ISP_FC_SCRLEN);
2232 isp_put_icb_2400(isp, icbp, fcp->isp_scratch);
2233 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2234 isp_print_bytes(isp, "isp_fibre_init_2400",
2235 sizeof (*icbp), fcp->isp_scratch);
2239 * Now fill in information about any additional channels
2241 if (isp->isp_nchan > 1) {
2242 isp_icb_2400_vpinfo_t vpinfo, *vdst;
2243 vp_port_info_t pi, *pdst;
2247 vpinfo.vp_global_options = ICB2400_VPGOPT_GEN_RIDA;
2248 if (ISP_CAP_VP0(isp)) {
2249 vpinfo.vp_global_options |= ICB2400_VPGOPT_VP0_DECOUPLE;
2250 vpinfo.vp_count = isp->isp_nchan;
2253 vpinfo.vp_count = isp->isp_nchan - 1;
2256 off = fcp->isp_scratch;
2257 off += ICB2400_VPINFO_OFF;
2258 vdst = (isp_icb_2400_vpinfo_t *) off;
2259 isp_put_icb_2400_vpinfo(isp, &vpinfo, vdst);
2260 amt = ICB2400_VPINFO_OFF + sizeof (isp_icb_2400_vpinfo_t);
2261 for (; chan < isp->isp_nchan; chan++) {
2264 ISP_MEMZERO(&pi, sizeof (pi));
2265 fcp2 = FCPARAM(isp, chan);
2266 if (fcp2->role != ISP_ROLE_NONE) {
2267 pi.vp_port_options = ICB2400_VPOPT_ENABLED |
2268 ICB2400_VPOPT_ENA_SNSLOGIN;
2269 if (fcp2->role & ISP_ROLE_INITIATOR)
2270 pi.vp_port_options |= ICB2400_VPOPT_INI_ENABLE;
2271 if ((fcp2->role & ISP_ROLE_TARGET) == 0)
2272 pi.vp_port_options |= ICB2400_VPOPT_TGT_DISABLE;
2273 if (fcp2->isp_loopid < LOCAL_LOOP_LIM) {
2274 pi.vp_port_loopid = fcp2->isp_loopid;
2275 if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
2276 pi.vp_port_options |= ICB2400_VPOPT_HARD_ADDRESS;
2280 MAKE_NODE_NAME_FROM_WWN(pi.vp_port_portname, fcp2->isp_wwpn);
2281 MAKE_NODE_NAME_FROM_WWN(pi.vp_port_nodename, fcp2->isp_wwnn);
2282 off = fcp->isp_scratch;
2283 if (ISP_CAP_VP0(isp))
2284 off += ICB2400_VPINFO_PORT_OFF(chan);
2286 off += ICB2400_VPINFO_PORT_OFF(chan - 1);
2287 pdst = (vp_port_info_t *) off;
2288 isp_put_vp_port_info(isp, &pi, pdst);
2289 amt += ICB2400_VPOPT_WRITE_SIZE;
2291 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2292 isp_print_bytes(isp, "isp_fibre_init_2400",
2293 amt - ICB2400_VPINFO_OFF,
2294 (char *)fcp->isp_scratch + ICB2400_VPINFO_OFF);
2301 MBSINIT(&mbs, 0, MBLOGALL, 30000000);
2302 if (isp->isp_nchan > 1) {
2303 mbs.param[0] = MBOX_INIT_FIRMWARE_MULTI_ID;
2305 mbs.param[0] = MBOX_INIT_FIRMWARE;
2308 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2309 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2310 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2311 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2312 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));
2313 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp), 0);
2314 isp_mboxcmd(isp, &mbs);
2315 FC_SCRATCH_RELEASE(isp, 0);
2317 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2320 isp->isp_reqidx = 0;
2321 isp->isp_reqodx = 0;
2322 isp->isp_residx = 0;
2323 isp->isp_resodx = 0;
2324 isp->isp_atioodx = 0;
2327 * Whatever happens, we're now committed to being here.
2329 isp->isp_state = ISP_RUNSTATE;
2333 isp_fc_enable_vp(ispsoftc_t *isp, int chan)
2335 fcparam *fcp = FCPARAM(isp, chan);
2338 uint8_t resp[QENTRY_LEN];
2340 /* Build a VP MODIFY command in memory */
2341 ISP_MEMZERO(&vp, sizeof(vp));
2342 vp.vp_mod_hdr.rqs_entry_type = RQSTYPE_VP_MODIFY;
2343 vp.vp_mod_hdr.rqs_entry_count = 1;
2345 vp.vp_mod_idx0 = chan;
2346 vp.vp_mod_cmd = VP_MODIFY_ENA;
2347 vp.vp_mod_ports[0].options = ICB2400_VPOPT_ENABLED |
2348 ICB2400_VPOPT_ENA_SNSLOGIN;
2349 if (fcp->role & ISP_ROLE_INITIATOR)
2350 vp.vp_mod_ports[0].options |= ICB2400_VPOPT_INI_ENABLE;
2351 if ((fcp->role & ISP_ROLE_TARGET) == 0)
2352 vp.vp_mod_ports[0].options |= ICB2400_VPOPT_TGT_DISABLE;
2353 if (fcp->isp_loopid < LOCAL_LOOP_LIM) {
2354 vp.vp_mod_ports[0].loopid = fcp->isp_loopid;
2355 if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
2356 vp.vp_mod_ports[0].options |= ICB2400_VPOPT_HARD_ADDRESS;
2358 MAKE_NODE_NAME_FROM_WWN(vp.vp_mod_ports[0].wwpn, fcp->isp_wwpn);
2359 MAKE_NODE_NAME_FROM_WWN(vp.vp_mod_ports[0].wwnn, fcp->isp_wwnn);
2361 /* Prepare space for response in memory */
2362 memset(resp, 0xff, sizeof(resp));
2363 vp.vp_mod_hdl = isp_allocate_handle(isp, resp, ISP_HANDLE_CTRL);
2364 if (vp.vp_mod_hdl == 0) {
2365 isp_prt(isp, ISP_LOGERR,
2366 "%s: VP_MODIFY of Chan %d out of handles", __func__, chan);
2370 /* Send request and wait for response. */
2371 reqp = isp_getrqentry(isp);
2373 isp_prt(isp, ISP_LOGERR,
2374 "%s: VP_MODIFY of Chan %d out of rqent", __func__, chan);
2375 isp_destroy_handle(isp, vp.vp_mod_hdl);
2378 isp_put_vp_modify(isp, &vp, (vp_modify_t *)reqp);
2379 if (isp->isp_dblev & ISP_LOGDEBUG1)
2380 isp_print_bytes(isp, "IOCB VP_MODIFY", QENTRY_LEN, reqp);
2381 ISP_SYNC_REQUEST(isp);
2382 if (msleep(resp, &isp->isp_lock, 0, "VP_MODIFY", 5*hz) == EWOULDBLOCK) {
2383 isp_prt(isp, ISP_LOGERR,
2384 "%s: VP_MODIFY of Chan %d timed out", __func__, chan);
2385 isp_destroy_handle(isp, vp.vp_mod_hdl);
2388 if (isp->isp_dblev & ISP_LOGDEBUG1)
2389 isp_print_bytes(isp, "IOCB VP_MODIFY response", QENTRY_LEN, resp);
2390 isp_get_vp_modify(isp, (vp_modify_t *)resp, &vp);
2392 if (vp.vp_mod_hdr.rqs_flags != 0 || vp.vp_mod_status != VP_STS_OK) {
2393 isp_prt(isp, ISP_LOGERR,
2394 "%s: VP_MODIFY of Chan %d failed with flags %x status %d",
2395 __func__, chan, vp.vp_mod_hdr.rqs_flags, vp.vp_mod_status);
2402 isp_fc_disable_vp(ispsoftc_t *isp, int chan)
2406 uint8_t resp[QENTRY_LEN];
2408 /* Build a VP CTRL command in memory */
2409 ISP_MEMZERO(&vp, sizeof(vp));
2410 vp.vp_ctrl_hdr.rqs_entry_type = RQSTYPE_VP_CTRL;
2411 vp.vp_ctrl_hdr.rqs_entry_count = 1;
2412 if (ISP_CAP_VP0(isp)) {
2413 vp.vp_ctrl_status = 1;
2415 vp.vp_ctrl_status = 0;
2416 chan--; /* VP0 can not be controlled in this case. */
2418 vp.vp_ctrl_command = VP_CTRL_CMD_DISABLE_VP_LOGO_ALL;
2419 vp.vp_ctrl_vp_count = 1;
2420 vp.vp_ctrl_idmap[chan / 16] |= (1 << chan % 16);
2422 /* Prepare space for response in memory */
2423 memset(resp, 0xff, sizeof(resp));
2424 vp.vp_ctrl_handle = isp_allocate_handle(isp, resp, ISP_HANDLE_CTRL);
2425 if (vp.vp_ctrl_handle == 0) {
2426 isp_prt(isp, ISP_LOGERR,
2427 "%s: VP_CTRL of Chan %d out of handles", __func__, chan);
2431 /* Send request and wait for response. */
2432 reqp = isp_getrqentry(isp);
2434 isp_prt(isp, ISP_LOGERR,
2435 "%s: VP_CTRL of Chan %d out of rqent", __func__, chan);
2436 isp_destroy_handle(isp, vp.vp_ctrl_handle);
2439 isp_put_vp_ctrl_info(isp, &vp, (vp_ctrl_info_t *)reqp);
2440 if (isp->isp_dblev & ISP_LOGDEBUG1)
2441 isp_print_bytes(isp, "IOCB VP_CTRL", QENTRY_LEN, reqp);
2442 ISP_SYNC_REQUEST(isp);
2443 if (msleep(resp, &isp->isp_lock, 0, "VP_CTRL", 5*hz) == EWOULDBLOCK) {
2444 isp_prt(isp, ISP_LOGERR,
2445 "%s: VP_CTRL of Chan %d timed out", __func__, chan);
2446 isp_destroy_handle(isp, vp.vp_ctrl_handle);
2449 if (isp->isp_dblev & ISP_LOGDEBUG1)
2450 isp_print_bytes(isp, "IOCB VP_CTRL response", QENTRY_LEN, resp);
2451 isp_get_vp_ctrl_info(isp, (vp_ctrl_info_t *)resp, &vp);
2453 if (vp.vp_ctrl_hdr.rqs_flags != 0 || vp.vp_ctrl_status != 0) {
2454 isp_prt(isp, ISP_LOGERR,
2455 "%s: VP_CTRL of Chan %d failed with flags %x status %d %d",
2456 __func__, chan, vp.vp_ctrl_hdr.rqs_flags,
2457 vp.vp_ctrl_status, vp.vp_ctrl_index_fail);
2464 isp_fc_change_role(ispsoftc_t *isp, int chan, int new_role)
2466 fcparam *fcp = FCPARAM(isp, chan);
2467 int i, was, res = 0;
2469 if (chan >= isp->isp_nchan) {
2470 isp_prt(isp, ISP_LOGWARN, "%s: bad channel %d", __func__, chan);
2473 if (fcp->role == new_role)
2475 for (was = 0, i = 0; i < isp->isp_nchan; i++) {
2476 if (FCPARAM(isp, i)->role != ISP_ROLE_NONE)
2479 if (was == 0 || (was == 1 && fcp->role != ISP_ROLE_NONE)) {
2480 fcp->role = new_role;
2481 return (isp_reinit(isp, 0));
2483 if (fcp->role != ISP_ROLE_NONE) {
2484 res = isp_fc_disable_vp(isp, chan);
2485 isp_clear_portdb(isp, chan);
2487 fcp->role = new_role;
2488 if (fcp->role != ISP_ROLE_NONE)
2489 res = isp_fc_enable_vp(isp, chan);
2494 isp_clear_portdb(ispsoftc_t *isp, int chan)
2496 fcparam *fcp = FCPARAM(isp, chan);
2500 for (i = 0; i < MAX_FC_TARG; i++) {
2501 lp = &fcp->portdb[i];
2502 switch (lp->state) {
2503 case FC_PORTDB_STATE_DEAD:
2504 case FC_PORTDB_STATE_CHANGED:
2505 case FC_PORTDB_STATE_VALID:
2506 lp->state = FC_PORTDB_STATE_NIL;
2507 isp_async(isp, ISPASYNC_DEV_GONE, chan, lp);
2509 case FC_PORTDB_STATE_NIL:
2510 case FC_PORTDB_STATE_NEW:
2511 lp->state = FC_PORTDB_STATE_NIL;
2513 case FC_PORTDB_STATE_ZOMBIE:
2516 panic("Don't know how to clear state %d\n", lp->state);
2522 isp_mark_portdb(ispsoftc_t *isp, int chan)
2524 fcparam *fcp = FCPARAM(isp, chan);
2528 for (i = 0; i < MAX_FC_TARG; i++) {
2529 lp = &fcp->portdb[i];
2530 if (lp->state == FC_PORTDB_STATE_NIL)
2532 if (lp->portid >= DOMAIN_CONTROLLER_BASE &&
2533 lp->portid <= DOMAIN_CONTROLLER_END)
2535 fcp->portdb[i].probational = 1;
2540 * Perform an IOCB PLOGI or LOGO via EXECUTE IOCB A64 for 24XX cards
2541 * or via FABRIC LOGIN/FABRIC LOGOUT for other cards.
2544 isp_plogx(ispsoftc_t *isp, int chan, uint16_t handle, uint32_t portid, int flags)
2548 uint8_t resp[QENTRY_LEN];
2549 uint32_t sst, parm1;
2554 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d PLOGX %s PortID 0x%06x nphdl 0x%x",
2555 chan, (flags & PLOGX_FLG_CMD_MASK) == PLOGX_FLG_CMD_PLOGI ?
2556 "Login":"Logout", portid, handle);
2557 if (!IS_24XX(isp)) {
2558 int action = flags & PLOGX_FLG_CMD_MASK;
2559 if (action == PLOGX_FLG_CMD_PLOGI) {
2560 return (isp_port_login(isp, handle, portid));
2561 } else if (action == PLOGX_FLG_CMD_LOGO) {
2562 return (isp_port_logout(isp, handle, portid));
2564 return (MBOX_INVALID_COMMAND);
2568 ISP_MEMZERO(&pl, sizeof(pl));
2569 pl.plogx_header.rqs_entry_count = 1;
2570 pl.plogx_header.rqs_entry_type = RQSTYPE_LOGIN;
2571 pl.plogx_nphdl = handle;
2572 pl.plogx_vphdl = chan;
2573 pl.plogx_portlo = portid;
2574 pl.plogx_rspsz_porthi = (portid >> 16) & 0xff;
2575 pl.plogx_flags = flags;
2577 /* Prepare space for response in memory */
2578 memset(resp, 0xff, sizeof(resp));
2579 pl.plogx_handle = isp_allocate_handle(isp, resp, ISP_HANDLE_CTRL);
2580 if (pl.plogx_handle == 0) {
2581 isp_prt(isp, ISP_LOGERR,
2582 "%s: PLOGX of Chan %d out of handles", __func__, chan);
2586 /* Send request and wait for response. */
2587 reqp = isp_getrqentry(isp);
2589 isp_prt(isp, ISP_LOGERR,
2590 "%s: PLOGX of Chan %d out of rqent", __func__, chan);
2591 isp_destroy_handle(isp, pl.plogx_handle);
2594 isp_put_plogx(isp, &pl, (isp_plogx_t *)reqp);
2595 if (isp->isp_dblev & ISP_LOGDEBUG1)
2596 isp_print_bytes(isp, "IOCB LOGX", QENTRY_LEN, reqp);
2597 FCPARAM(isp, chan)->isp_login_hdl = handle;
2598 ISP_SYNC_REQUEST(isp);
2599 if (msleep(resp, &isp->isp_lock, 0, "PLOGX", 3 * ICB_LOGIN_TOV * hz)
2601 isp_prt(isp, ISP_LOGERR,
2602 "%s: PLOGX of Chan %d timed out", __func__, chan);
2603 isp_destroy_handle(isp, pl.plogx_handle);
2606 FCPARAM(isp, chan)->isp_login_hdl = NIL_HANDLE;
2607 if (isp->isp_dblev & ISP_LOGDEBUG1)
2608 isp_print_bytes(isp, "IOCB LOGX response", QENTRY_LEN, resp);
2609 isp_get_plogx(isp, (isp_plogx_t *)resp, &pl);
2611 if (pl.plogx_status == PLOGX_STATUS_OK) {
2613 } else if (pl.plogx_status != PLOGX_STATUS_IOCBERR) {
2614 isp_prt(isp, ISP_LOGWARN,
2615 "status 0x%x on port login IOCB channel %d",
2616 pl.plogx_status, chan);
2620 sst = pl.plogx_ioparm[0].lo16 | (pl.plogx_ioparm[0].hi16 << 16);
2621 parm1 = pl.plogx_ioparm[1].lo16 | (pl.plogx_ioparm[1].hi16 << 16);
2628 case PLOGX_IOCBERR_NOLINK:
2631 case PLOGX_IOCBERR_NOIOCB:
2632 msg = "no IOCB buffer";
2634 case PLOGX_IOCBERR_NOXGHG:
2635 msg = "no Exchange Control Block";
2637 case PLOGX_IOCBERR_FAILED:
2638 ISP_SNPRINTF(buf, sizeof (buf), "reason 0x%x (last LOGIN state 0x%x)", parm1 & 0xff, (parm1 >> 8) & 0xff);
2641 case PLOGX_IOCBERR_NOFABRIC:
2644 case PLOGX_IOCBERR_NOTREADY:
2645 msg = "firmware not ready";
2647 case PLOGX_IOCBERR_NOLOGIN:
2648 ISP_SNPRINTF(buf, sizeof (buf), "not logged in (last state 0x%x)", parm1);
2650 rval = MBOX_NOT_LOGGED_IN;
2652 case PLOGX_IOCBERR_REJECT:
2653 ISP_SNPRINTF(buf, sizeof (buf), "LS_RJT = 0x%x", parm1);
2656 case PLOGX_IOCBERR_NOPCB:
2657 msg = "no PCB allocated";
2659 case PLOGX_IOCBERR_EINVAL:
2660 ISP_SNPRINTF(buf, sizeof (buf), "invalid parameter at offset 0x%x", parm1);
2663 case PLOGX_IOCBERR_PORTUSED:
2664 lev = ISP_LOG_SANCFG|ISP_LOG_WARN1;
2665 ISP_SNPRINTF(buf, sizeof (buf), "already logged in with N-Port handle 0x%x", parm1);
2667 rval = MBOX_PORT_ID_USED | (parm1 << 16);
2669 case PLOGX_IOCBERR_HNDLUSED:
2670 lev = ISP_LOG_SANCFG|ISP_LOG_WARN1;
2671 ISP_SNPRINTF(buf, sizeof (buf), "handle already used for PortID 0x%06x", parm1);
2673 rval = MBOX_LOOP_ID_USED;
2675 case PLOGX_IOCBERR_NOHANDLE:
2676 msg = "no handle allocated";
2678 case PLOGX_IOCBERR_NOFLOGI:
2679 msg = "no FLOGI_ACC";
2682 ISP_SNPRINTF(buf, sizeof (buf), "status %x from %x", pl.plogx_status, flags);
2687 isp_prt(isp, lev, "Chan %d PLOGX PortID 0x%06x to N-Port handle 0x%x: %s",
2688 chan, portid, handle, msg);
2694 isp_port_login(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2698 MBSINIT(&mbs, MBOX_FABRIC_LOGIN, MBLOGNONE, 500000);
2699 if (ISP_CAP_2KLOGIN(isp)) {
2700 mbs.param[1] = handle;
2701 mbs.ibits = (1 << 10);
2703 mbs.param[1] = handle << 8;
2705 mbs.param[2] = portid >> 16;
2706 mbs.param[3] = portid;
2707 mbs.logval = MBLOGNONE;
2708 mbs.timeout = 500000;
2709 isp_mboxcmd(isp, &mbs);
2711 switch (mbs.param[0]) {
2712 case MBOX_PORT_ID_USED:
2713 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]);
2714 return (MBOX_PORT_ID_USED | (mbs.param[1] << 16));
2716 case MBOX_LOOP_ID_USED:
2717 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);
2718 return (MBOX_LOOP_ID_USED);
2720 case MBOX_COMMAND_COMPLETE:
2723 case MBOX_COMMAND_ERROR:
2724 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);
2725 return (MBOX_COMMAND_ERROR);
2727 case MBOX_ALL_IDS_USED:
2728 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "isp_port_login: all IDs used for fabric login");
2729 return (MBOX_ALL_IDS_USED);
2732 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);
2733 return (mbs.param[0]);
2738 * Pre-24XX fabric port logout
2740 * Note that portid is not used
2743 isp_port_logout(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2747 MBSINIT(&mbs, MBOX_FABRIC_LOGOUT, MBLOGNONE, 500000);
2748 if (ISP_CAP_2KLOGIN(isp)) {
2749 mbs.param[1] = handle;
2750 mbs.ibits = (1 << 10);
2752 mbs.param[1] = handle << 8;
2754 isp_mboxcmd(isp, &mbs);
2755 return (mbs.param[0] == MBOX_COMMAND_COMPLETE? 0 : mbs.param[0]);
2759 isp_getpdb(ispsoftc_t *isp, int chan, uint16_t id, isp_pdb_t *pdb)
2763 isp_pdb_21xx_t fred;
2764 isp_pdb_24xx_t bill;
2767 MBSINIT(&mbs, MBOX_GET_PORT_DB,
2768 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_PARAM_ERROR), 250000);
2770 mbs.ibits = (1 << 9)|(1 << 10);
2772 mbs.param[9] = chan;
2773 } else if (ISP_CAP_2KLOGIN(isp)) {
2776 mbs.param[1] = id << 8;
2778 mbs.param[2] = DMA_WD1(isp->isp_iocb_dma);
2779 mbs.param[3] = DMA_WD0(isp->isp_iocb_dma);
2780 mbs.param[6] = DMA_WD3(isp->isp_iocb_dma);
2781 mbs.param[7] = DMA_WD2(isp->isp_iocb_dma);
2782 MEMORYBARRIER(isp, SYNC_IFORDEV, 0, sizeof(un), chan);
2784 isp_mboxcmd(isp, &mbs);
2785 if (mbs.param[0] != MBOX_COMMAND_COMPLETE)
2786 return (mbs.param[0] | (mbs.param[1] << 16));
2788 MEMORYBARRIER(isp, SYNC_IFORCPU, 0, sizeof(un), chan);
2790 isp_get_pdb_24xx(isp, isp->isp_iocb, &un.bill);
2791 pdb->handle = un.bill.pdb_handle;
2792 pdb->prli_word0 = un.bill.pdb_prli_svc0;
2793 pdb->prli_word3 = un.bill.pdb_prli_svc3;
2794 pdb->portid = BITS2WORD_24XX(un.bill.pdb_portid_bits);
2795 ISP_MEMCPY(pdb->portname, un.bill.pdb_portname, 8);
2796 ISP_MEMCPY(pdb->nodename, un.bill.pdb_nodename, 8);
2797 isp_prt(isp, ISP_LOGDEBUG0,
2798 "Chan %d handle 0x%x Port 0x%06x flags 0x%x curstate %x laststate %x",
2799 chan, id, pdb->portid, un.bill.pdb_flags,
2800 un.bill.pdb_curstate, un.bill.pdb_laststate);
2802 if (un.bill.pdb_curstate < PDB2400_STATE_PLOGI_DONE || un.bill.pdb_curstate > PDB2400_STATE_LOGGED_IN) {
2803 mbs.param[0] = MBOX_NOT_LOGGED_IN;
2804 return (mbs.param[0]);
2807 isp_get_pdb_21xx(isp, isp->isp_iocb, &un.fred);
2808 pdb->handle = un.fred.pdb_loopid;
2809 pdb->prli_word0 = un.fred.pdb_prli_svc0;
2810 pdb->prli_word3 = un.fred.pdb_prli_svc3;
2811 pdb->portid = BITS2WORD(un.fred.pdb_portid_bits);
2812 ISP_MEMCPY(pdb->portname, un.fred.pdb_portname, 8);
2813 ISP_MEMCPY(pdb->nodename, un.fred.pdb_nodename, 8);
2814 isp_prt(isp, ISP_LOGDEBUG1,
2815 "Chan %d handle 0x%x Port 0x%06x", chan, id, pdb->portid);
2821 isp_gethandles(ispsoftc_t *isp, int chan, uint16_t *handles, int *num, int loop)
2823 fcparam *fcp = FCPARAM(isp, chan);
2825 isp_pnhle_21xx_t el1, *elp1;
2826 isp_pnhle_23xx_t el3, *elp3;
2827 isp_pnhle_24xx_t el4, *elp4;
2832 MBSINIT(&mbs, MBOX_GET_ID_LIST, MBLOGALL, 250000);
2834 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2835 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2836 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2837 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2838 mbs.param[8] = ISP_FC_SCRLEN;
2839 mbs.param[9] = chan;
2841 mbs.ibits = (1 << 1)|(1 << 2)|(1 << 3)|(1 << 6);
2842 mbs.param[1] = DMA_WD1(fcp->isp_scdma);
2843 mbs.param[2] = DMA_WD0(fcp->isp_scdma);
2844 mbs.param[3] = DMA_WD3(fcp->isp_scdma);
2845 mbs.param[6] = DMA_WD2(fcp->isp_scdma);
2847 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
2848 isp_prt(isp, ISP_LOGERR, sacq);
2851 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, ISP_FC_SCRLEN, chan);
2852 isp_mboxcmd(isp, &mbs);
2853 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2854 FC_SCRATCH_RELEASE(isp, chan);
2855 return (mbs.param[0] | (mbs.param[1] << 16));
2857 MEMORYBARRIER(isp, SYNC_SFORCPU, 0, ISP_FC_SCRLEN, chan);
2858 elp1 = fcp->isp_scratch;
2859 elp3 = fcp->isp_scratch;
2860 elp4 = fcp->isp_scratch;
2861 for (i = 0, j = 0; i < mbs.param[1] && j < *num; i++) {
2863 isp_get_pnhle_24xx(isp, &elp4[i], &el4);
2864 p = el4.pnhle_port_id_lo |
2865 (el4.pnhle_port_id_hi << 16);
2866 h = el4.pnhle_handle;
2867 } else if (IS_23XX(isp)) {
2868 isp_get_pnhle_23xx(isp, &elp3[i], &el3);
2869 p = el3.pnhle_port_id_lo |
2870 (el3.pnhle_port_id_hi << 16);
2871 h = el3.pnhle_handle;
2873 isp_get_pnhle_21xx(isp, &elp1[i], &el1);
2874 p = el1.pnhle_port_id_lo |
2875 ((el1.pnhle_port_id_hi_handle & 0xff) << 16);
2876 h = el1.pnhle_port_id_hi_handle >> 8;
2878 if (loop && (p >> 8) != (fcp->isp_portid >> 8))
2883 FC_SCRATCH_RELEASE(isp, chan);
2888 isp_dump_chip_portdb(ispsoftc_t *isp, int chan)
2891 uint16_t lim, nphdl;
2893 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGINFO, "Chan %d chip port dump", chan);
2894 if (ISP_CAP_2KLOGIN(isp)) {
2899 for (nphdl = 0; nphdl != lim; nphdl++) {
2900 if (isp_getpdb(isp, chan, nphdl, &pdb)) {
2903 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGINFO, "Chan %d Handle 0x%04x "
2904 "PortID 0x%06x WWPN 0x%02x%02x%02x%02x%02x%02x%02x%02x",
2905 chan, nphdl, pdb.portid, pdb.portname[0], pdb.portname[1],
2906 pdb.portname[2], pdb.portname[3], pdb.portname[4],
2907 pdb.portname[5], pdb.portname[6], pdb.portname[7]);
2912 isp_get_wwn(ispsoftc_t *isp, int chan, int nphdl, int nodename)
2914 uint64_t wwn = INI_NONE;
2917 MBSINIT(&mbs, MBOX_GET_PORT_NAME,
2918 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_PARAM_ERROR), 500000);
2919 if (ISP_CAP_2KLOGIN(isp)) {
2920 mbs.param[1] = nphdl;
2924 mbs.param[9] = chan;
2927 mbs.param[1] = nphdl << 8;
2932 isp_mboxcmd(isp, &mbs);
2933 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2938 (((uint64_t)(mbs.param[2] >> 8)) << 56) |
2939 (((uint64_t)(mbs.param[2] & 0xff)) << 48) |
2940 (((uint64_t)(mbs.param[3] >> 8)) << 40) |
2941 (((uint64_t)(mbs.param[3] & 0xff)) << 32) |
2942 (((uint64_t)(mbs.param[6] >> 8)) << 24) |
2943 (((uint64_t)(mbs.param[6] & 0xff)) << 16) |
2944 (((uint64_t)(mbs.param[7] >> 8)) << 8) |
2945 (((uint64_t)(mbs.param[7] & 0xff)));
2948 (((uint64_t)(mbs.param[2] & 0xff)) << 56) |
2949 (((uint64_t)(mbs.param[2] >> 8)) << 48) |
2950 (((uint64_t)(mbs.param[3] & 0xff)) << 40) |
2951 (((uint64_t)(mbs.param[3] >> 8)) << 32) |
2952 (((uint64_t)(mbs.param[6] & 0xff)) << 24) |
2953 (((uint64_t)(mbs.param[6] >> 8)) << 16) |
2954 (((uint64_t)(mbs.param[7] & 0xff)) << 8) |
2955 (((uint64_t)(mbs.param[7] >> 8)));
2961 * Make sure we have good FC link.
2965 isp_fclink_test(ispsoftc_t *isp, int chan, int usdelay)
2972 NANOTIME_T hra, hrb;
2974 fcp = FCPARAM(isp, chan);
2976 if (fcp->isp_loopstate < LOOP_HAVE_LINK)
2978 if (fcp->isp_loopstate >= LOOP_LTEST_DONE)
2981 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC link test", chan);
2984 * Wait up to N microseconds for F/W to go to a ready state.
2988 isp_change_fw_state(isp, chan, isp_fw_state(isp, chan));
2989 if (fcp->isp_fwstate == FW_READY) {
2992 if (fcp->isp_loopstate < LOOP_HAVE_LINK)
2995 if ((NANOTIME_SUB(&hrb, &hra) / 1000 + 1000 >= usdelay))
2997 ISP_SLEEP(isp, 1000);
2999 if (fcp->isp_fwstate != FW_READY) {
3000 isp_prt(isp, ISP_LOG_SANCFG,
3001 "Chan %d Firmware is not ready (%s)",
3002 chan, isp_fc_fw_statename(fcp->isp_fwstate));
3007 * Get our Loop ID and Port ID.
3009 MBSINIT(&mbs, MBOX_GET_LOOP_ID, MBLOGALL, 0);
3010 mbs.param[9] = chan;
3011 isp_mboxcmd(isp, &mbs);
3012 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3018 * Don't bother with fabric if we are using really old
3019 * 2100 firmware. It's just not worth it.
3021 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37))
3022 fcp->isp_topo = TOPO_FL_PORT;
3024 fcp->isp_topo = TOPO_NL_PORT;
3026 int topo = (int) mbs.param[6];
3027 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB) {
3028 topo = TOPO_PTP_STUB;
3030 fcp->isp_topo = topo;
3032 fcp->isp_portid = mbs.param[2] | (mbs.param[3] << 16);
3034 if (!TOPO_IS_FABRIC(fcp->isp_topo)) {
3035 fcp->isp_loopid = mbs.param[1] & 0xff;
3036 } else if (fcp->isp_topo != TOPO_F_PORT) {
3037 uint8_t alpa = fcp->isp_portid;
3039 for (i = 0; alpa_map[i]; i++) {
3040 if (alpa_map[i] == alpa)
3044 fcp->isp_loopid = i;
3048 fcp->isp_loopstate = LOOP_HAVE_ADDR;
3050 fcp->isp_loopstate = LOOP_TESTING_LINK;
3052 if (fcp->isp_topo == TOPO_F_PORT || fcp->isp_topo == TOPO_FL_PORT) {
3053 nphdl = IS_24XX(isp) ? NPH_FL_ID : FL_ID;
3054 r = isp_getpdb(isp, chan, nphdl, &pdb);
3055 if (r != 0 || pdb.portid == 0) {
3057 fcp->isp_topo = TOPO_NL_PORT;
3059 isp_prt(isp, ISP_LOGWARN,
3060 "fabric topology, but cannot get info about fabric controller (0x%x)", r);
3061 fcp->isp_topo = TOPO_PTP_STUB;
3067 fcp->isp_fabric_params = mbs.param[7];
3068 fcp->isp_sns_hdl = NPH_SNS_ID;
3069 r = isp_register_fc4_type(isp, chan);
3070 if (fcp->isp_loopstate < LOOP_TESTING_LINK)
3074 r = isp_register_fc4_features_24xx(isp, chan);
3075 if (fcp->isp_loopstate < LOOP_TESTING_LINK)
3079 r = isp_register_port_name_24xx(isp, chan);
3080 if (fcp->isp_loopstate < LOOP_TESTING_LINK)
3084 isp_register_node_name_24xx(isp, chan);
3085 if (fcp->isp_loopstate < LOOP_TESTING_LINK)
3088 fcp->isp_sns_hdl = SNS_ID;
3089 r = isp_register_fc4_type(isp, chan);
3092 if (fcp->role == ISP_ROLE_TARGET)
3093 isp_send_change_request(isp, chan);
3098 /* Get link speed. */
3099 fcp->isp_gbspeed = 1;
3100 if (IS_23XX(isp) || IS_24XX(isp)) {
3101 MBSINIT(&mbs, MBOX_GET_SET_DATA_RATE, MBLOGALL, 3000000);
3102 mbs.param[1] = MBGSD_GET_RATE;
3103 /* mbs.param[2] undefined if we're just getting rate */
3104 isp_mboxcmd(isp, &mbs);
3105 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3106 if (mbs.param[1] == MBGSD_10GB)
3107 fcp->isp_gbspeed = 10;
3108 else if (mbs.param[1] == MBGSD_32GB)
3109 fcp->isp_gbspeed = 32;
3110 else if (mbs.param[1] == MBGSD_16GB)
3111 fcp->isp_gbspeed = 16;
3112 else if (mbs.param[1] == MBGSD_8GB)
3113 fcp->isp_gbspeed = 8;
3114 else if (mbs.param[1] == MBGSD_4GB)
3115 fcp->isp_gbspeed = 4;
3116 else if (mbs.param[1] == MBGSD_2GB)
3117 fcp->isp_gbspeed = 2;
3118 else if (mbs.param[1] == MBGSD_1GB)
3119 fcp->isp_gbspeed = 1;
3123 if (fcp->isp_loopstate < LOOP_TESTING_LINK) {
3125 isp_prt(isp, ISP_LOG_SANCFG,
3126 "Chan %d FC link test aborted", chan);
3129 fcp->isp_loopstate = LOOP_LTEST_DONE;
3130 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGCONFIG,
3131 "Chan %d WWPN %016jx WWNN %016jx",
3132 chan, (uintmax_t)fcp->isp_wwpn, (uintmax_t)fcp->isp_wwnn);
3133 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGCONFIG,
3134 "Chan %d %dGb %s PortID 0x%06x LoopID 0x%02x",
3135 chan, fcp->isp_gbspeed, isp_fc_toponame(fcp), fcp->isp_portid,
3137 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC link test done", chan);
3142 * Complete the synchronization of our Port Database.
3144 * At this point, we've scanned the local loop (if any) and the fabric
3145 * and performed fabric logins on all new devices.
3147 * Our task here is to go through our port database removing any entities
3148 * that are still marked probational (issuing PLOGO for ones which we had
3149 * PLOGI'd into) or are dead, and notifying upper layers about new/changed
3153 isp_pdb_sync(ispsoftc_t *isp, int chan)
3155 fcparam *fcp = FCPARAM(isp, chan);
3159 if (fcp->isp_loopstate < LOOP_FSCAN_DONE)
3161 if (fcp->isp_loopstate >= LOOP_READY)
3164 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC PDB sync", chan);
3166 fcp->isp_loopstate = LOOP_SYNCING_PDB;
3168 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
3169 lp = &fcp->portdb[dbidx];
3171 if (lp->state == FC_PORTDB_STATE_NIL)
3173 if (lp->probational && lp->state != FC_PORTDB_STATE_ZOMBIE)
3174 lp->state = FC_PORTDB_STATE_DEAD;
3175 switch (lp->state) {
3176 case FC_PORTDB_STATE_DEAD:
3177 lp->state = FC_PORTDB_STATE_NIL;
3178 isp_async(isp, ISPASYNC_DEV_GONE, chan, lp);
3179 if ((lp->portid & 0xffff00) != 0) {
3180 (void) isp_plogx(isp, chan, lp->handle,
3182 PLOGX_FLG_CMD_LOGO |
3183 PLOGX_FLG_IMPLICIT |
3184 PLOGX_FLG_FREE_NPHDL);
3187 * Note that we might come out of this with our state
3188 * set to FC_PORTDB_STATE_ZOMBIE.
3191 case FC_PORTDB_STATE_NEW:
3192 lp->state = FC_PORTDB_STATE_VALID;
3193 isp_async(isp, ISPASYNC_DEV_ARRIVED, chan, lp);
3195 case FC_PORTDB_STATE_CHANGED:
3196 lp->state = FC_PORTDB_STATE_VALID;
3197 isp_async(isp, ISPASYNC_DEV_CHANGED, chan, lp);
3198 lp->portid = lp->new_portid;
3199 lp->prli_word0 = lp->new_prli_word0;
3200 lp->prli_word3 = lp->new_prli_word3;
3202 case FC_PORTDB_STATE_VALID:
3203 isp_async(isp, ISPASYNC_DEV_STAYED, chan, lp);
3205 case FC_PORTDB_STATE_ZOMBIE:
3208 isp_prt(isp, ISP_LOGWARN,
3209 "isp_pdb_sync: state %d for idx %d",
3211 isp_dump_portdb(isp, chan);
3215 if (fcp->isp_loopstate < LOOP_SYNCING_PDB) {
3216 isp_prt(isp, ISP_LOG_SANCFG,
3217 "Chan %d FC PDB sync aborted", chan);
3221 fcp->isp_loopstate = LOOP_READY;
3222 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC PDB sync done", chan);
3227 isp_pdb_add_update(ispsoftc_t *isp, int chan, isp_pdb_t *pdb)
3230 uint64_t wwnn, wwpn;
3232 MAKE_WWN_FROM_NODE_NAME(wwnn, pdb->nodename);
3233 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb->portname);
3235 /* Search port database for the same WWPN. */
3236 if (isp_find_pdb_by_wwpn(isp, chan, wwpn, &lp)) {
3237 if (!lp->probational) {
3238 isp_prt(isp, ISP_LOGERR,
3239 "Chan %d Port 0x%06x@0x%04x [%d] is not probational (0x%x)",
3240 chan, lp->portid, lp->handle,
3241 FC_PORTDB_TGT(isp, chan, lp), lp->state);
3242 isp_dump_portdb(isp, chan);
3245 lp->probational = 0;
3246 lp->node_wwn = wwnn;
3248 /* Old device, nothing new. */
3249 if (lp->portid == pdb->portid &&
3250 lp->handle == pdb->handle &&
3251 lp->prli_word3 == pdb->prli_word3 &&
3252 ((pdb->prli_word0 & PRLI_WD0_EST_IMAGE_PAIR) ==
3253 (lp->prli_word0 & PRLI_WD0_EST_IMAGE_PAIR))) {
3254 if (lp->state != FC_PORTDB_STATE_NEW)
3255 lp->state = FC_PORTDB_STATE_VALID;
3256 isp_prt(isp, ISP_LOG_SANCFG,
3257 "Chan %d Port 0x%06x@0x%04x is valid",
3258 chan, pdb->portid, pdb->handle);
3262 /* Something has changed. */
3263 lp->state = FC_PORTDB_STATE_CHANGED;
3264 lp->handle = pdb->handle;
3265 lp->new_portid = pdb->portid;
3266 lp->new_prli_word0 = pdb->prli_word0;
3267 lp->new_prli_word3 = pdb->prli_word3;
3268 isp_prt(isp, ISP_LOG_SANCFG,
3269 "Chan %d Port 0x%06x@0x%04x is changed",
3270 chan, pdb->portid, pdb->handle);
3274 /* It seems like a new port. Find an empty slot for it. */
3275 if (!isp_find_pdb_empty(isp, chan, &lp)) {
3276 isp_prt(isp, ISP_LOGERR, "Chan %d out of portdb entries", chan);
3280 ISP_MEMZERO(lp, sizeof (fcportdb_t));
3281 lp->probational = 0;
3282 lp->state = FC_PORTDB_STATE_NEW;
3283 lp->portid = lp->new_portid = pdb->portid;
3284 lp->prli_word0 = lp->new_prli_word0 = pdb->prli_word0;
3285 lp->prli_word3 = lp->new_prli_word3 = pdb->prli_word3;
3286 lp->handle = pdb->handle;
3287 lp->port_wwn = wwpn;
3288 lp->node_wwn = wwnn;
3289 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Port 0x%06x@0x%04x is new",
3290 chan, pdb->portid, pdb->handle);
3294 * Fix port IDs for logged-in initiators on pre-2400 chips.
3295 * For those chips we are not receiving login events, adding initiators
3296 * based on ATIO requests, but there is no port ID in that structure.
3299 isp_fix_portids(ispsoftc_t *isp, int chan)
3301 fcparam *fcp = FCPARAM(isp, chan);
3306 for (i = 0; i < MAX_FC_TARG; i++) {
3307 fcportdb_t *lp = &fcp->portdb[i];
3309 if (lp->state == FC_PORTDB_STATE_NIL ||
3310 lp->state == FC_PORTDB_STATE_ZOMBIE)
3312 if (VALID_PORT(lp->portid))
3315 r = isp_getpdb(isp, chan, lp->handle, &pdb);
3316 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3319 isp_prt(isp, ISP_LOGDEBUG1,
3320 "Chan %d FC Scan Loop handle %d returned %x",
3321 chan, lp->handle, r);
3325 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb.portname);
3326 if (lp->port_wwn != wwpn)
3328 lp->portid = lp->new_portid = pdb.portid;
3329 isp_prt(isp, ISP_LOG_SANCFG,
3330 "Chan %d Port 0x%06x@0x%04x is fixed",
3331 chan, pdb.portid, pdb.handle);
3336 * Scan local loop for devices.
3339 isp_scan_loop(ispsoftc_t *isp, int chan)
3341 fcparam *fcp = FCPARAM(isp, chan);
3347 if (fcp->isp_loopstate < LOOP_LTEST_DONE)
3349 if (fcp->isp_loopstate >= LOOP_LSCAN_DONE)
3352 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC loop scan", chan);
3353 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
3354 if (TOPO_IS_FABRIC(fcp->isp_topo)) {
3355 if (!IS_24XX(isp)) {
3356 isp_fix_portids(isp, chan);
3357 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3360 isp_prt(isp, ISP_LOG_SANCFG,
3361 "Chan %d FC loop scan done (no loop)", chan);
3362 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3366 handles = (uint16_t *)fcp->isp_scanscratch;
3367 lim = ISP_FC_SCRLEN / 2;
3368 r = isp_gethandles(isp, chan, handles, &lim, 1);
3370 isp_prt(isp, ISP_LOG_SANCFG,
3371 "Chan %d Getting list of handles failed with %x", chan, r);
3372 isp_prt(isp, ISP_LOG_SANCFG,
3373 "Chan %d FC loop scan done (bad)", chan);
3377 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Got %d handles",
3381 * Run through the list and get the port database info for each one.
3383 isp_mark_portdb(isp, chan);
3384 for (idx = 0; idx < lim; idx++) {
3385 handle = handles[idx];
3388 * Don't scan "special" ids.
3390 if (ISP_CAP_2KLOGIN(isp)) {
3391 if (handle >= NPH_RESERVED)
3394 if (handle >= FL_ID && handle <= SNS_ID)
3399 * In older cards with older f/w GET_PORT_DATABASE has been
3400 * known to hang. This trick gets around that problem.
3402 if (IS_2100(isp) || IS_2200(isp)) {
3403 uint64_t node_wwn = isp_get_wwn(isp, chan, handle, 1);
3404 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
3406 isp_prt(isp, ISP_LOG_SANCFG,
3407 "Chan %d FC loop scan aborted", chan);
3410 if (node_wwn == INI_NONE) {
3416 * Get the port database entity for this index.
3418 r = isp_getpdb(isp, chan, handle, &pdb);
3419 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3422 isp_prt(isp, ISP_LOGDEBUG1,
3423 "Chan %d FC Scan Loop handle %d returned %x",
3428 isp_pdb_add_update(isp, chan, &pdb);
3430 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3432 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3433 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC loop scan done", chan);
3438 isp_ct_sns(ispsoftc_t *isp, int chan, uint32_t cmd_bcnt, uint32_t rsp_bcnt)
3440 fcparam *fcp = FCPARAM(isp, chan);
3443 if (isp->isp_dblev & ISP_LOGDEBUG1)
3444 isp_print_bytes(isp, "CT SNS request", cmd_bcnt, fcp->isp_scratch);
3445 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, cmd_bcnt, chan);
3447 MBSINIT(&mbs, MBOX_SEND_SNS, MBLOGALL, 10000000);
3448 mbs.param[1] = cmd_bcnt >> 1;
3449 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
3450 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
3451 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
3452 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
3453 isp_mboxcmd(isp, &mbs);
3454 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3455 if (mbs.param[0] == MBOX_INVALID_COMMAND) {
3462 MEMORYBARRIER(isp, SYNC_SFORCPU, 0, rsp_bcnt, chan);
3463 if (isp->isp_dblev & ISP_LOGDEBUG1)
3464 isp_print_bytes(isp, "CT response", rsp_bcnt, fcp->isp_scratch);
3469 isp_ct_passthru(ispsoftc_t *isp, int chan, uint32_t cmd_bcnt, uint32_t rsp_bcnt)
3471 fcparam *fcp = FCPARAM(isp, chan);
3474 uint8_t resp[QENTRY_LEN];
3476 if (isp->isp_dblev & ISP_LOGDEBUG1)
3477 isp_print_bytes(isp, "CT request", cmd_bcnt, fcp->isp_scratch);
3480 * Build a Passthrough IOCB in memory.
3482 ISP_MEMZERO(&pt, sizeof(pt));
3483 pt.ctp_header.rqs_entry_count = 1;
3484 pt.ctp_header.rqs_entry_type = RQSTYPE_CT_PASSTHRU;
3485 pt.ctp_nphdl = fcp->isp_sns_hdl;
3487 pt.ctp_vpidx = ISP_GET_VPIDX(isp, chan);
3490 pt.ctp_rsp_bcnt = rsp_bcnt;
3491 pt.ctp_cmd_bcnt = cmd_bcnt;
3492 pt.ctp_dataseg[0].ds_base = DMA_LO32(fcp->isp_scdma);
3493 pt.ctp_dataseg[0].ds_basehi = DMA_HI32(fcp->isp_scdma);
3494 pt.ctp_dataseg[0].ds_count = cmd_bcnt;
3495 pt.ctp_dataseg[1].ds_base = DMA_LO32(fcp->isp_scdma);
3496 pt.ctp_dataseg[1].ds_basehi = DMA_HI32(fcp->isp_scdma);
3497 pt.ctp_dataseg[1].ds_count = rsp_bcnt;
3499 /* Prepare space for response in memory */
3500 memset(resp, 0xff, sizeof(resp));
3501 pt.ctp_handle = isp_allocate_handle(isp, resp, ISP_HANDLE_CTRL);
3502 if (pt.ctp_handle == 0) {
3503 isp_prt(isp, ISP_LOGERR,
3504 "%s: CTP of Chan %d out of handles", __func__, chan);
3508 /* Send request and wait for response. */
3509 reqp = isp_getrqentry(isp);
3511 isp_prt(isp, ISP_LOGERR,
3512 "%s: CTP of Chan %d out of rqent", __func__, chan);
3513 isp_destroy_handle(isp, pt.ctp_handle);
3516 isp_put_ct_pt(isp, &pt, (isp_ct_pt_t *)reqp);
3517 if (isp->isp_dblev & ISP_LOGDEBUG1)
3518 isp_print_bytes(isp, "CT IOCB request", QENTRY_LEN, reqp);
3519 ISP_SYNC_REQUEST(isp);
3520 if (msleep(resp, &isp->isp_lock, 0, "CTP", pt.ctp_time*hz) == EWOULDBLOCK) {
3521 isp_prt(isp, ISP_LOGERR,
3522 "%s: CTP of Chan %d timed out", __func__, chan);
3523 isp_destroy_handle(isp, pt.ctp_handle);
3526 if (isp->isp_dblev & ISP_LOGDEBUG1)
3527 isp_print_bytes(isp, "CT IOCB response", QENTRY_LEN, resp);
3529 isp_get_ct_pt(isp, (isp_ct_pt_t *)resp, &pt);
3530 if (pt.ctp_status && pt.ctp_status != RQCS_DATA_UNDERRUN) {
3531 isp_prt(isp, ISP_LOGWARN,
3532 "Chan %d CT pass-through returned 0x%x",
3533 chan, pt.ctp_status);
3537 if (isp->isp_dblev & ISP_LOGDEBUG1)
3538 isp_print_bytes(isp, "CT response", rsp_bcnt, fcp->isp_scratch);
3544 * Scan the fabric for devices and add them to our port database.
3546 * Use the GID_PT command to get list of all Nx_Port IDs SNS knows.
3547 * Use GFF_ID and GFT_ID to check port type (FCP) and features (target).
3549 * For 2100-23XX cards, we use the SNS mailbox command to pass simple name
3550 * server commands to the switch management server via the QLogic f/w.
3552 * For the 24XX and above card, we use CT Pass-through IOCB.
3554 #define GIDLEN ISP_FC_SCRLEN
3555 #define NGENT ((GIDLEN - 16) >> 2)
3558 isp_gid_pt(ispsoftc_t *isp, int chan)
3560 fcparam *fcp = FCPARAM(isp, chan);
3562 sns_gid_pt_req_t rq;
3563 uint8_t *scp = fcp->isp_scratch;
3565 isp_prt(isp, ISP_LOGDEBUG0, "Chan %d requesting GID_PT", chan);
3566 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3567 isp_prt(isp, ISP_LOGERR, sacq);
3572 /* Build the CT command and execute via pass-through. */
3573 ISP_MEMZERO(&ct, sizeof (ct));
3574 ct.ct_revision = CT_REVISION;
3575 ct.ct_fcs_type = CT_FC_TYPE_FC;
3576 ct.ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3577 ct.ct_cmd_resp = SNS_GID_PT;
3578 ct.ct_bcnt_resid = (GIDLEN - 16) >> 2;
3579 isp_put_ct_hdr(isp, &ct, (ct_hdr_t *)scp);
3580 scp[sizeof(ct)] = 0x7f; /* Port Type = Nx_Port */
3581 scp[sizeof(ct)+1] = 0; /* Domain_ID = any */
3582 scp[sizeof(ct)+2] = 0; /* Area_ID = any */
3583 scp[sizeof(ct)+3] = 0; /* Flags = no Area_ID */
3585 if (isp_ct_passthru(isp, chan, sizeof(ct) + sizeof(uint32_t), GIDLEN)) {
3586 FC_SCRATCH_RELEASE(isp, chan);
3590 /* Build the SNS request and execute via firmware. */
3591 ISP_MEMZERO(&rq, SNS_GID_PT_REQ_SIZE);
3592 rq.snscb_rblen = GIDLEN >> 1;
3593 rq.snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma);
3594 rq.snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma);
3595 rq.snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma);
3596 rq.snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma);
3598 rq.snscb_cmd = SNS_GID_PT;
3599 rq.snscb_mword_div_2 = NGENT;
3600 rq.snscb_port_type = 0x7f; /* Port Type = Nx_Port */
3601 rq.snscb_domain = 0; /* Domain_ID = any */
3602 rq.snscb_area = 0; /* Area_ID = any */
3603 rq.snscb_flags = 0; /* Flags = no Area_ID */
3604 isp_put_gid_pt_request(isp, &rq, (sns_gid_pt_req_t *)scp);
3606 if (isp_ct_sns(isp, chan, sizeof(rq), NGENT)) {
3607 FC_SCRATCH_RELEASE(isp, chan);
3612 isp_get_gid_xx_response(isp, (sns_gid_xx_rsp_t *)scp,
3613 (sns_gid_xx_rsp_t *)fcp->isp_scanscratch, NGENT);
3614 FC_SCRATCH_RELEASE(isp, chan);
3619 isp_gff_id(ispsoftc_t *isp, int chan, uint32_t portid)
3621 fcparam *fcp = FCPARAM(isp, chan);
3624 uint8_t *scp = fcp->isp_scratch;
3625 sns_gff_id_rsp_t rsp;
3628 if (!fcp->isp_use_gff_id) /* User may block GFF_ID use. */
3631 if (!IS_24XX(isp)) /* Old chips can't request GFF_ID. */
3634 isp_prt(isp, ISP_LOGDEBUG0, "Chan %d requesting GFF_ID", chan);
3635 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3636 isp_prt(isp, ISP_LOGERR, sacq);
3640 /* Build the CT command and execute via pass-through. */
3641 ISP_MEMZERO(&ct, sizeof (ct));
3642 ct.ct_revision = CT_REVISION;
3643 ct.ct_fcs_type = CT_FC_TYPE_FC;
3644 ct.ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3645 ct.ct_cmd_resp = SNS_GFF_ID;
3646 ct.ct_bcnt_resid = (SNS_GFF_ID_RESP_SIZE - sizeof(ct)) / 4;
3647 isp_put_ct_hdr(isp, &ct, (ct_hdr_t *)scp);
3648 rp = (uint32_t *) &scp[sizeof(ct)];
3649 ISP_IOZPUT_32(isp, portid, rp);
3651 if (isp_ct_passthru(isp, chan, sizeof(ct) + sizeof(uint32_t),
3652 SNS_GFF_ID_RESP_SIZE)) {
3653 FC_SCRATCH_RELEASE(isp, chan);
3657 isp_get_gff_id_response(isp, (sns_gff_id_rsp_t *)scp, &rsp);
3658 if (rsp.snscb_cthdr.ct_cmd_resp == LS_ACC) {
3659 for (i = 0; i < 32; i++) {
3660 if (rsp.snscb_fc4_features[i] != 0) {
3665 if (((rsp.snscb_fc4_features[FC4_SCSI / 8] >>
3666 ((FC4_SCSI % 8) * 4)) & 0x01) != 0)
3668 /* Workaround for broken Brocade firmware. */
3669 if (((ISP_SWAP32(isp, rsp.snscb_fc4_features[FC4_SCSI / 8]) >>
3670 ((FC4_SCSI % 8) * 4)) & 0x01) != 0)
3673 FC_SCRATCH_RELEASE(isp, chan);
3674 isp_prt(isp, ISP_LOGDEBUG0, "Chan %d GFF_ID result is %d", chan, res);
3679 isp_gft_id(ispsoftc_t *isp, int chan, uint32_t portid)
3681 fcparam *fcp = FCPARAM(isp, chan);
3683 sns_gxx_id_req_t rq;
3685 uint8_t *scp = fcp->isp_scratch;
3686 sns_gft_id_rsp_t rsp;
3689 if (!fcp->isp_use_gft_id) /* User may block GFT_ID use. */
3692 isp_prt(isp, ISP_LOGDEBUG0, "Chan %d requesting GFT_ID", chan);
3693 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3694 isp_prt(isp, ISP_LOGERR, sacq);
3699 /* Build the CT command and execute via pass-through. */
3700 ISP_MEMZERO(&ct, sizeof (ct));
3701 ct.ct_revision = CT_REVISION;
3702 ct.ct_fcs_type = CT_FC_TYPE_FC;
3703 ct.ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3704 ct.ct_cmd_resp = SNS_GFT_ID;
3705 ct.ct_bcnt_resid = (SNS_GFT_ID_RESP_SIZE - sizeof(ct)) / 4;
3706 isp_put_ct_hdr(isp, &ct, (ct_hdr_t *)scp);
3707 rp = (uint32_t *) &scp[sizeof(ct)];
3708 ISP_IOZPUT_32(isp, portid, rp);
3710 if (isp_ct_passthru(isp, chan, sizeof(ct) + sizeof(uint32_t),
3711 SNS_GFT_ID_RESP_SIZE)) {
3712 FC_SCRATCH_RELEASE(isp, chan);
3716 /* Build the SNS request and execute via firmware. */
3717 ISP_MEMZERO(&rq, SNS_GXX_ID_REQ_SIZE);
3718 rq.snscb_rblen = SNS_GFT_ID_RESP_SIZE >> 1;
3719 rq.snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma);
3720 rq.snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma);
3721 rq.snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma);
3722 rq.snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma);
3724 rq.snscb_cmd = SNS_GFT_ID;
3725 rq.snscb_mword_div_2 = (SNS_GFT_ID_RESP_SIZE - sizeof(ct)) / 4;
3726 rq.snscb_portid = portid;
3727 isp_put_gxx_id_request(isp, &rq, (sns_gxx_id_req_t *)scp);
3729 if (isp_ct_sns(isp, chan, sizeof(rq), SNS_GFT_ID_RESP_SIZE)) {
3730 FC_SCRATCH_RELEASE(isp, chan);
3735 isp_get_gft_id_response(isp, (sns_gft_id_rsp_t *)scp, &rsp);
3736 if (rsp.snscb_cthdr.ct_cmd_resp == LS_ACC) {
3737 for (i = 0; i < 8; i++) {
3738 if (rsp.snscb_fc4_types[i] != 0) {
3743 if (((rsp.snscb_fc4_types[FC4_SCSI / 32] >>
3744 (FC4_SCSI % 32)) & 0x01) != 0)
3747 FC_SCRATCH_RELEASE(isp, chan);
3748 isp_prt(isp, ISP_LOGDEBUG0, "Chan %d GFT_ID result is %d", chan, res);
3753 isp_scan_fabric(ispsoftc_t *isp, int chan)
3755 fcparam *fcp = FCPARAM(isp, chan);
3760 int portidx, portlim, r;
3761 sns_gid_xx_rsp_t *rs;
3763 if (fcp->isp_loopstate < LOOP_LSCAN_DONE)
3765 if (fcp->isp_loopstate >= LOOP_FSCAN_DONE)
3768 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC fabric scan", chan);
3769 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
3770 if (!TOPO_IS_FABRIC(fcp->isp_topo)) {
3771 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3772 isp_prt(isp, ISP_LOG_SANCFG,
3773 "Chan %d FC fabric scan done (no fabric)", chan);
3777 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC) {
3779 FC_SCRATCH_RELEASE(isp, chan);
3780 isp_prt(isp, ISP_LOG_SANCFG,
3781 "Chan %d FC fabric scan aborted", chan);
3786 * Make sure we still are logged into the fabric controller.
3788 nphdl = IS_24XX(isp) ? NPH_FL_ID : FL_ID;
3789 r = isp_getpdb(isp, chan, nphdl, &pdb);
3790 if ((r & 0xffff) == MBOX_NOT_LOGGED_IN) {
3791 isp_dump_chip_portdb(isp, chan);
3794 fcp->isp_loopstate = LOOP_LTEST_DONE;
3796 isp_prt(isp, ISP_LOG_SANCFG,
3797 "Chan %d FC fabric scan done (bad)", chan);
3801 /* Get list of port IDs from SNS. */
3802 r = isp_gid_pt(isp, chan);
3803 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3806 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3809 fcp->isp_loopstate = LOOP_LTEST_DONE; /* try again */
3813 rs = (sns_gid_xx_rsp_t *) fcp->isp_scanscratch;
3814 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3816 if (rs->snscb_cthdr.ct_cmd_resp != LS_ACC) {
3818 /* FC-4 Type and Port Type not registered are not errors. */
3819 if (rs->snscb_cthdr.ct_reason == 9 &&
3820 (rs->snscb_cthdr.ct_explanation == 0x07 ||
3821 rs->snscb_cthdr.ct_explanation == 0x0a)) {
3822 level = ISP_LOG_SANCFG;
3824 level = ISP_LOGWARN;
3826 isp_prt(isp, level, "Chan %d Fabric Nameserver rejected GID_PT"
3827 " (Reason=0x%x Expl=0x%x)", chan,
3828 rs->snscb_cthdr.ct_reason,
3829 rs->snscb_cthdr.ct_explanation);
3830 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3834 /* Check our buffer was big enough to get the full list. */
3835 for (portidx = 0; portidx < NGENT-1; portidx++) {
3836 if (rs->snscb_ports[portidx].control & 0x80)
3839 if ((rs->snscb_ports[portidx].control & 0x80) == 0) {
3840 isp_prt(isp, ISP_LOGWARN,
3841 "fabric too big for scratch area: increase ISP_FC_SCRLEN");
3843 portlim = portidx + 1;
3844 isp_prt(isp, ISP_LOG_SANCFG,
3845 "Chan %d Got %d ports back from name server", chan, portlim);
3847 /* Go through the list and remove duplicate port ids. */
3848 for (portidx = 0; portidx < portlim; portidx++) {
3852 ((rs->snscb_ports[portidx].portid[0]) << 16) |
3853 ((rs->snscb_ports[portidx].portid[1]) << 8) |
3854 ((rs->snscb_ports[portidx].portid[2]));
3856 for (npidx = portidx + 1; npidx < portlim; npidx++) {
3857 uint32_t new_portid =
3858 ((rs->snscb_ports[npidx].portid[0]) << 16) |
3859 ((rs->snscb_ports[npidx].portid[1]) << 8) |
3860 ((rs->snscb_ports[npidx].portid[2]));
3861 if (new_portid == portid) {
3866 if (npidx < portlim) {
3867 rs->snscb_ports[npidx].portid[0] = 0;
3868 rs->snscb_ports[npidx].portid[1] = 0;
3869 rs->snscb_ports[npidx].portid[2] = 0;
3870 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d removing duplicate PortID 0x%06x entry from list", chan, portid);
3875 * We now have a list of Port IDs for all FC4 SCSI devices
3876 * that the Fabric Name server knows about.
3878 * For each entry on this list go through our port database looking
3879 * for probational entries- if we find one, then an old entry is
3880 * maybe still this one. We get some information to find out.
3882 * Otherwise, it's a new fabric device, and we log into it
3883 * (unconditionally). After searching the entire database
3884 * again to make sure that we never ever ever ever have more
3885 * than one entry that has the same PortID or the same
3886 * WWNN/WWPN duple, we enter the device into our database.
3888 isp_mark_portdb(isp, chan);
3889 for (portidx = 0; portidx < portlim; portidx++) {
3890 portid = ((rs->snscb_ports[portidx].portid[0]) << 16) |
3891 ((rs->snscb_ports[portidx].portid[1]) << 8) |
3892 ((rs->snscb_ports[portidx].portid[2]));
3893 isp_prt(isp, ISP_LOG_SANCFG,
3894 "Chan %d Checking fabric port 0x%06x", chan, portid);
3896 isp_prt(isp, ISP_LOG_SANCFG,
3897 "Chan %d Port at idx %d is zero",
3901 if (portid == fcp->isp_portid) {
3902 isp_prt(isp, ISP_LOG_SANCFG,
3903 "Chan %d Port 0x%06x is our", chan, portid);
3907 /* Now search the entire port database for the same portid. */
3908 if (isp_find_pdb_by_portid(isp, chan, portid, &lp)) {
3909 if (!lp->probational) {
3910 isp_prt(isp, ISP_LOGERR,
3911 "Chan %d Port 0x%06x@0x%04x [%d] is not probational (0x%x)",
3912 chan, lp->portid, lp->handle,
3913 FC_PORTDB_TGT(isp, chan, lp), lp->state);
3914 isp_dump_portdb(isp, chan);
3918 if (lp->state == FC_PORTDB_STATE_ZOMBIE)
3922 * See if we're still logged into it.
3924 * If we aren't, mark it as a dead device and
3925 * leave the new portid in the database entry
3926 * for somebody further along to decide what to
3927 * do (policy choice).
3929 * If we are, check to see if it's the same
3930 * device still (it should be). If for some
3931 * reason it isn't, mark it as a changed device
3932 * and leave the new portid and role in the
3933 * database entry for somebody further along to
3934 * decide what to do (policy choice).
3936 r = isp_getpdb(isp, chan, lp->handle, &pdb);
3937 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3940 lp->state = FC_PORTDB_STATE_DEAD;
3941 isp_prt(isp, ISP_LOG_SANCFG,
3942 "Chan %d Port 0x%06x handle 0x%x is dead (%d)",
3943 chan, portid, lp->handle, r);
3947 isp_pdb_add_update(isp, chan, &pdb);
3952 if ((fcp->role & ISP_ROLE_INITIATOR) == 0) {
3953 isp_prt(isp, ISP_LOG_SANCFG,
3954 "Chan %d Port 0x%06x is not logged in", chan, portid);
3958 r = isp_gff_id(isp, chan, portid);
3960 isp_prt(isp, ISP_LOG_SANCFG,
3961 "Chan %d Port 0x%06x is not an FCP target", chan, portid);
3965 r = isp_gft_id(isp, chan, portid);
3967 isp_prt(isp, ISP_LOG_SANCFG,
3968 "Chan %d Port 0x%06x is not FCP", chan, portid);
3972 if (isp_login_device(isp, chan, portid, &pdb,
3973 &FCPARAM(isp, 0)->isp_lasthdl)) {
3974 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3979 isp_pdb_add_update(isp, chan, &pdb);
3982 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3984 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3985 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC fabric scan done", chan);
3990 * Find an unused handle and try and use to login to a port.
3993 isp_login_device(ispsoftc_t *isp, int chan, uint32_t portid, isp_pdb_t *p, uint16_t *ohp)
3998 if (ISP_CAP_2KLOGIN(isp)) {
4004 handle = isp_next_handle(isp, ohp);
4005 for (i = 0; i < lim; i++) {
4006 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
4009 /* Check if this handle is free. */
4010 r = isp_getpdb(isp, chan, handle, p);
4012 if (p->portid != portid) {
4013 /* This handle is busy, try next one. */
4014 handle = isp_next_handle(isp, ohp);
4019 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
4023 * Now try and log into the device
4025 r = isp_plogx(isp, chan, handle, portid, PLOGX_FLG_CMD_PLOGI);
4028 } else if ((r & 0xffff) == MBOX_PORT_ID_USED) {
4030 * If we get here, then the firmwware still thinks we're logged into this device, but with a different
4031 * handle. We need to break that association. We used to try and just substitute the handle, but then
4032 * failed to get any data via isp_getpdb (below).
4034 if (isp_plogx(isp, chan, r >> 16, portid, PLOGX_FLG_CMD_LOGO | PLOGX_FLG_IMPLICIT | PLOGX_FLG_FREE_NPHDL)) {
4035 isp_prt(isp, ISP_LOGERR, "baw... logout of %x failed", r >> 16);
4037 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
4039 r = isp_plogx(isp, chan, handle, portid, PLOGX_FLG_CMD_PLOGI);
4043 } else if ((r & 0xffff) == MBOX_LOOP_ID_USED) {
4044 /* Try the next handle. */
4045 handle = isp_next_handle(isp, ohp);
4054 isp_prt(isp, ISP_LOGWARN, "Chan %d PLOGI 0x%06x failed", chan, portid);
4059 * If we successfully logged into it, get the PDB for it
4060 * so we can crosscheck that it is still what we think it
4061 * is and that we also have the role it plays
4063 r = isp_getpdb(isp, chan, handle, p);
4065 isp_prt(isp, ISP_LOGERR, "Chan %d new device 0x%06x@0x%x disappeared", chan, portid, handle);
4069 if (p->handle != handle || p->portid != portid) {
4070 isp_prt(isp, ISP_LOGERR, "Chan %d new device 0x%06x@0x%x changed (0x%06x@0x%0x)",
4071 chan, portid, handle, p->portid, p->handle);
4078 isp_send_change_request(ispsoftc_t *isp, int chan)
4082 MBSINIT(&mbs, MBOX_SEND_CHANGE_REQUEST, MBLOGALL, 500000);
4083 mbs.param[1] = 0x03;
4084 mbs.param[9] = chan;
4085 isp_mboxcmd(isp, &mbs);
4086 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
4089 isp_prt(isp, ISP_LOGWARN, "Chan %d Send Change Request: 0x%x",
4090 chan, mbs.param[0]);
4096 isp_register_fc4_type(ispsoftc_t *isp, int chan)
4098 fcparam *fcp = FCPARAM(isp, chan);
4100 ct_hdr_t *ct = &rp.rftid_hdr;
4101 uint8_t local[SNS_RFT_ID_REQ_SIZE];
4102 sns_screq_t *reqp = (sns_screq_t *) local;
4103 uint8_t *scp = fcp->isp_scratch;
4105 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4106 isp_prt(isp, ISP_LOGERR, sacq);
4111 /* Build the CT command and execute via pass-through. */
4112 ISP_MEMZERO(&rp, sizeof(rp));
4113 ct->ct_revision = CT_REVISION;
4114 ct->ct_fcs_type = CT_FC_TYPE_FC;
4115 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
4116 ct->ct_cmd_resp = SNS_RFT_ID;
4117 ct->ct_bcnt_resid = (sizeof (rft_id_t) - sizeof (ct_hdr_t)) >> 2;
4118 rp.rftid_portid[0] = fcp->isp_portid >> 16;
4119 rp.rftid_portid[1] = fcp->isp_portid >> 8;
4120 rp.rftid_portid[2] = fcp->isp_portid;
4121 rp.rftid_fc4types[FC4_SCSI >> 5] = 1 << (FC4_SCSI & 0x1f);
4122 isp_put_rft_id(isp, &rp, (rft_id_t *)scp);
4124 if (isp_ct_passthru(isp, chan, sizeof(rft_id_t), sizeof(ct_hdr_t))) {
4125 FC_SCRATCH_RELEASE(isp, chan);
4129 /* Build the SNS request and execute via firmware. */
4130 ISP_MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
4131 reqp->snscb_rblen = sizeof (ct_hdr_t) >> 1;
4132 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma);
4133 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma);
4134 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma);
4135 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma);
4136 reqp->snscb_sblen = 22;
4137 reqp->snscb_data[0] = SNS_RFT_ID;
4138 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
4139 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
4140 reqp->snscb_data[6] = (1 << FC4_SCSI);
4141 isp_put_sns_request(isp, reqp, (sns_screq_t *)scp);
4143 if (isp_ct_sns(isp, chan, SNS_RFT_ID_REQ_SIZE, sizeof(ct_hdr_t))) {
4144 FC_SCRATCH_RELEASE(isp, chan);
4149 isp_get_ct_hdr(isp, (ct_hdr_t *) scp, ct);
4150 FC_SCRATCH_RELEASE(isp, chan);
4151 if (ct->ct_cmd_resp == LS_RJT) {
4152 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "Chan %d Register FC4 Type rejected", chan);
4154 } else if (ct->ct_cmd_resp == LS_ACC) {
4155 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Register FC4 Type accepted", chan);
4157 isp_prt(isp, ISP_LOGWARN, "Chan %d Register FC4 Type: 0x%x", chan, ct->ct_cmd_resp);
4164 isp_register_fc4_features_24xx(ispsoftc_t *isp, int chan)
4166 fcparam *fcp = FCPARAM(isp, chan);
4169 uint8_t *scp = fcp->isp_scratch;
4171 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4172 isp_prt(isp, ISP_LOGERR, sacq);
4177 * Build the CT header and command in memory.
4179 ISP_MEMZERO(&rp, sizeof(rp));
4181 ct->ct_revision = CT_REVISION;
4182 ct->ct_fcs_type = CT_FC_TYPE_FC;
4183 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
4184 ct->ct_cmd_resp = SNS_RFF_ID;
4185 ct->ct_bcnt_resid = (sizeof (rff_id_t) - sizeof (ct_hdr_t)) >> 2;
4186 rp.rffid_portid[0] = fcp->isp_portid >> 16;
4187 rp.rffid_portid[1] = fcp->isp_portid >> 8;
4188 rp.rffid_portid[2] = fcp->isp_portid;
4189 rp.rffid_fc4features = 0;
4190 if (fcp->role & ISP_ROLE_TARGET)
4191 rp.rffid_fc4features |= 1;
4192 if (fcp->role & ISP_ROLE_INITIATOR)
4193 rp.rffid_fc4features |= 2;
4194 rp.rffid_fc4type = FC4_SCSI;
4195 isp_put_rff_id(isp, &rp, (rff_id_t *)scp);
4196 if (isp->isp_dblev & ISP_LOGDEBUG1)
4197 isp_print_bytes(isp, "CT request", sizeof(rft_id_t), scp);
4199 if (isp_ct_passthru(isp, chan, sizeof(rft_id_t), sizeof(ct_hdr_t))) {
4200 FC_SCRATCH_RELEASE(isp, chan);
4204 isp_get_ct_hdr(isp, (ct_hdr_t *) scp, ct);
4205 FC_SCRATCH_RELEASE(isp, chan);
4206 if (ct->ct_cmd_resp == LS_RJT) {
4207 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1,
4208 "Chan %d Register FC4 Features rejected", chan);
4210 } else if (ct->ct_cmd_resp == LS_ACC) {
4211 isp_prt(isp, ISP_LOG_SANCFG,
4212 "Chan %d Register FC4 Features accepted", chan);
4214 isp_prt(isp, ISP_LOGWARN,
4215 "Chan %d Register FC4 Features: 0x%x", chan, ct->ct_cmd_resp);
4222 isp_register_port_name_24xx(ispsoftc_t *isp, int chan)
4224 fcparam *fcp = FCPARAM(isp, chan);
4227 uint8_t *scp = fcp->isp_scratch;
4230 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4231 isp_prt(isp, ISP_LOGERR, sacq);
4236 * Build the CT header and command in memory.
4238 ISP_MEMZERO(&rp, sizeof(rp));
4239 ct = &rp.rspnid_hdr;
4240 ct->ct_revision = CT_REVISION;
4241 ct->ct_fcs_type = CT_FC_TYPE_FC;
4242 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
4243 ct->ct_cmd_resp = SNS_RSPN_ID;
4244 rp.rspnid_portid[0] = fcp->isp_portid >> 16;
4245 rp.rspnid_portid[1] = fcp->isp_portid >> 8;
4246 rp.rspnid_portid[2] = fcp->isp_portid;
4247 rp.rspnid_length = 0;
4248 len = offsetof(rspn_id_t, rspnid_name);
4249 mtx_lock(&prison0.pr_mtx);
4250 rp.rspnid_length += sprintf(&scp[len + rp.rspnid_length],
4251 "%s", prison0.pr_hostname[0] ? prison0.pr_hostname : "FreeBSD");
4252 mtx_unlock(&prison0.pr_mtx);
4253 rp.rspnid_length += sprintf(&scp[len + rp.rspnid_length],
4254 ":%s", device_get_nameunit(isp->isp_dev));
4256 rp.rspnid_length += sprintf(&scp[len + rp.rspnid_length],
4259 len += rp.rspnid_length;
4260 ct->ct_bcnt_resid = (len - sizeof(ct_hdr_t)) >> 2;
4261 isp_put_rspn_id(isp, &rp, (rspn_id_t *)scp);
4263 if (isp_ct_passthru(isp, chan, len, sizeof(ct_hdr_t))) {
4264 FC_SCRATCH_RELEASE(isp, chan);
4268 isp_get_ct_hdr(isp, (ct_hdr_t *) scp, ct);
4269 FC_SCRATCH_RELEASE(isp, chan);
4270 if (ct->ct_cmd_resp == LS_RJT) {
4271 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1,
4272 "Chan %d Register Symbolic Port Name rejected", chan);
4274 } else if (ct->ct_cmd_resp == LS_ACC) {
4275 isp_prt(isp, ISP_LOG_SANCFG,
4276 "Chan %d Register Symbolic Port Name accepted", chan);
4278 isp_prt(isp, ISP_LOGWARN,
4279 "Chan %d Register Symbolic Port Name: 0x%x", chan, ct->ct_cmd_resp);
4286 isp_register_node_name_24xx(ispsoftc_t *isp, int chan)
4288 fcparam *fcp = FCPARAM(isp, chan);
4291 uint8_t *scp = fcp->isp_scratch;
4294 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4295 isp_prt(isp, ISP_LOGERR, sacq);
4300 * Build the CT header and command in memory.
4302 ISP_MEMZERO(&rp, sizeof(rp));
4303 ct = &rp.rsnnnn_hdr;
4304 ct->ct_revision = CT_REVISION;
4305 ct->ct_fcs_type = CT_FC_TYPE_FC;
4306 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
4307 ct->ct_cmd_resp = SNS_RSNN_NN;
4308 MAKE_NODE_NAME_FROM_WWN(rp.rsnnnn_nodename, fcp->isp_wwnn);
4309 rp.rsnnnn_length = 0;
4310 len = offsetof(rsnn_nn_t, rsnnnn_name);
4311 mtx_lock(&prison0.pr_mtx);
4312 rp.rsnnnn_length += sprintf(&scp[len + rp.rsnnnn_length],
4313 "%s", prison0.pr_hostname[0] ? prison0.pr_hostname : "FreeBSD");
4314 mtx_unlock(&prison0.pr_mtx);
4315 len += rp.rsnnnn_length;
4316 ct->ct_bcnt_resid = (len - sizeof(ct_hdr_t)) >> 2;
4317 isp_put_rsnn_nn(isp, &rp, (rsnn_nn_t *)scp);
4319 if (isp_ct_passthru(isp, chan, len, sizeof(ct_hdr_t))) {
4320 FC_SCRATCH_RELEASE(isp, chan);
4324 isp_get_ct_hdr(isp, (ct_hdr_t *) scp, ct);
4325 FC_SCRATCH_RELEASE(isp, chan);
4326 if (ct->ct_cmd_resp == LS_RJT) {
4327 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1,
4328 "Chan %d Register Symbolic Node Name rejected", chan);
4330 } else if (ct->ct_cmd_resp == LS_ACC) {
4331 isp_prt(isp, ISP_LOG_SANCFG,
4332 "Chan %d Register Symbolic Node Name accepted", chan);
4334 isp_prt(isp, ISP_LOGWARN,
4335 "Chan %d Register Symbolic Node Name: 0x%x", chan, ct->ct_cmd_resp);
4342 isp_next_handle(ispsoftc_t *isp, uint16_t *ohp)
4346 uint16_t handle, minh, maxh;
4349 if (ISP_CAP_2KLOGIN(isp)) {
4351 maxh = NPH_RESERVED - 1;
4359 if (handle == NIL_HANDLE) {
4363 if (handle > maxh) {
4365 isp_prt(isp, ISP_LOGERR, "Out of port handles!");
4366 return (NIL_HANDLE);
4371 for (chan = 0; chan < isp->isp_nchan; chan++) {
4372 fcp = FCPARAM(isp, chan);
4373 if (fcp->role == ISP_ROLE_NONE)
4375 for (i = 0; i < MAX_FC_TARG; i++) {
4376 if (fcp->portdb[i].state != FC_PORTDB_STATE_NIL &&
4377 fcp->portdb[i].handle == handle)
4386 * Start a command. Locking is assumed done in the caller.
4394 uint8_t local[QENTRY_LEN];
4399 int target, dmaresult;
4405 * Check command CDB length, etc.. We really are limited to 16 bytes
4406 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
4407 * but probably only if we're running fairly new firmware (we'll
4408 * let the old f/w choke on an extended command queue entry).
4411 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
4412 isp_prt(isp, ISP_LOGERR, "unsupported cdb length (%d, CDB[0]=0x%x)", XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
4413 XS_SETERR(xs, HBA_REQINVAL);
4414 return (CMD_COMPLETE);
4418 * Translate the target to device handle as appropriate, checking
4419 * for correct device state as well.
4421 target = XS_TGT(xs);
4423 fcparam *fcp = FCPARAM(isp, XS_CHANNEL(xs));
4425 if ((fcp->role & ISP_ROLE_INITIATOR) == 0) {
4426 isp_prt(isp, ISP_LOG_WARN1,
4427 "%d.%d.%jx I am not an initiator",
4428 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4429 XS_SETERR(xs, HBA_SELTIMEOUT);
4430 return (CMD_COMPLETE);
4433 if (isp->isp_state != ISP_RUNSTATE) {
4434 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
4435 XS_SETERR(xs, HBA_BOTCH);
4436 return (CMD_COMPLETE);
4439 isp_prt(isp, ISP_LOGDEBUG2, "XS_TGT(xs)=%d", target);
4440 lp = &fcp->portdb[target];
4441 if (target < 0 || target >= MAX_FC_TARG ||
4442 lp->is_target == 0) {
4443 XS_SETERR(xs, HBA_SELTIMEOUT);
4444 return (CMD_COMPLETE);
4446 if (fcp->isp_loopstate != LOOP_READY) {
4447 isp_prt(isp, ISP_LOGDEBUG1,
4448 "%d.%d.%jx loop is not ready",
4449 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4450 return (CMD_RQLATER);
4452 if (lp->state == FC_PORTDB_STATE_ZOMBIE) {
4453 isp_prt(isp, ISP_LOGDEBUG1,
4454 "%d.%d.%jx target zombie",
4455 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4456 return (CMD_RQLATER);
4458 if (lp->state != FC_PORTDB_STATE_VALID) {
4459 isp_prt(isp, ISP_LOGDEBUG1,
4460 "%d.%d.%jx bad db port state 0x%x",
4461 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs), lp->state);
4462 XS_SETERR(xs, HBA_SELTIMEOUT);
4463 return (CMD_COMPLETE);
4466 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
4467 if (isp->isp_state != ISP_RUNSTATE) {
4468 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
4469 XS_SETERR(xs, HBA_BOTCH);
4470 return (CMD_COMPLETE);
4474 isp_spi_update(isp, XS_CHANNEL(xs));
4481 qep = isp_getrqentry(isp);
4483 isp_prt(isp, ISP_LOG_WARN1, "Request Queue Overflow");
4484 XS_SETERR(xs, HBA_BOTCH);
4485 return (CMD_EAGAIN);
4487 XS_SETERR(xs, HBA_NOERROR);
4490 * Now see if we need to synchronize the ISP with respect to anything.
4491 * We do dual duty here (cough) for synchronizing for busses other
4492 * than which we got here to send a command to.
4494 reqp = (ispreq_t *) local;
4495 ISP_MEMZERO(local, QENTRY_LEN);
4496 if (ISP_TST_SENDMARKER(isp, XS_CHANNEL(xs))) {
4498 isp_marker_24xx_t *m = (isp_marker_24xx_t *) reqp;
4499 m->mrk_header.rqs_entry_count = 1;
4500 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4501 m->mrk_modifier = SYNC_ALL;
4502 m->mrk_vphdl = XS_CHANNEL(xs);
4503 isp_put_marker_24xx(isp, m, qep);
4505 isp_marker_t *m = (isp_marker_t *) reqp;
4506 m->mrk_header.rqs_entry_count = 1;
4507 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4508 m->mrk_target = (XS_CHANNEL(xs) << 7); /* bus # */
4509 m->mrk_modifier = SYNC_ALL;
4510 isp_put_marker(isp, m, qep);
4512 ISP_SYNC_REQUEST(isp);
4513 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 0);
4517 reqp->req_header.rqs_entry_count = 1;
4520 * Select and install Header Code.
4521 * Note that it might be overridden before going out
4522 * if we're on a 64 bit platform. The lower level
4523 * code (isp_send_cmd) will select the appropriate
4524 * 64 bit variant if it needs to.
4527 reqp->req_header.rqs_entry_type = RQSTYPE_T7RQS;
4528 } else if (IS_FC(isp)) {
4529 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
4531 if (XS_CDBLEN(xs) > 12) {
4532 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
4534 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
4539 * Set task attributes
4544 ttype = XS_TAG_TYPE(xs);
4546 ttype = REQFLAG_STAG;
4548 if (ttype == REQFLAG_OTAG) {
4549 ttype = FCP_CMND_TASK_ATTR_ORDERED;
4550 } else if (ttype == REQFLAG_HTAG) {
4551 ttype = FCP_CMND_TASK_ATTR_HEAD;
4553 ttype = FCP_CMND_TASK_ATTR_SIMPLE;
4555 ((ispreqt7_t *)reqp)->req_task_attribute = ttype;
4556 } else if (IS_FC(isp)) {
4558 * See comment in isp_intr_respq
4560 /* XS_SET_RESID(xs, 0); */
4563 * Fibre Channel always requires some kind of tag.
4564 * The Qlogic drivers seem be happy not to use a tag,
4565 * but this breaks for some devices (IBM drives).
4568 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
4570 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
4573 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
4574 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) && XS_TAG_P(xs)) {
4575 reqp->req_flags = XS_TAG_TYPE(xs);
4580 * NB: we do not support long CDBs (yet)
4582 cdblen = XS_CDBLEN(xs);
4585 if (cdblen > sizeof (reqp->req_cdb)) {
4586 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4587 XS_SETERR(xs, HBA_REQINVAL);
4588 return (CMD_COMPLETE);
4590 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
4591 reqp->req_lun_trn = XS_LUN(xs);
4592 reqp->req_cdblen = cdblen;
4593 tptr = &reqp->req_time;
4594 cdbp = reqp->req_cdb;
4595 } else if (IS_24XX(isp)) {
4596 ispreqt7_t *t7 = (ispreqt7_t *)local;
4598 if (cdblen > sizeof (t7->req_cdb)) {
4599 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4600 XS_SETERR(xs, HBA_REQINVAL);
4601 return (CMD_COMPLETE);
4604 t7->req_nphdl = lp->handle;
4605 t7->req_tidlo = lp->portid;
4606 t7->req_tidhi = lp->portid >> 16;
4607 t7->req_vpidx = ISP_GET_VPIDX(isp, XS_CHANNEL(xs));
4608 be64enc(t7->req_lun, CAM_EXTLUN_BYTE_SWIZZLE(XS_LUN(xs)));
4609 if (FCPARAM(isp, XS_CHANNEL(xs))->fctape_enabled && (lp->prli_word3 & PRLI_WD3_RETRY)) {
4610 if (FCP_NEXT_CRN(isp, &t7->req_crn, xs)) {
4611 isp_prt(isp, ISP_LOG_WARN1,
4612 "%d.%d.%jx cannot generate next CRN",
4613 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4614 XS_SETERR(xs, HBA_BOTCH);
4615 return (CMD_EAGAIN);
4618 tptr = &t7->req_time;
4621 ispreqt2_t *t2 = (ispreqt2_t *)local;
4623 if (cdblen > sizeof t2->req_cdb) {
4624 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4625 XS_SETERR(xs, HBA_REQINVAL);
4626 return (CMD_COMPLETE);
4628 if (FCPARAM(isp, XS_CHANNEL(xs))->fctape_enabled && (lp->prli_word3 & PRLI_WD3_RETRY)) {
4629 if (FCP_NEXT_CRN(isp, &t2->req_crn, xs)) {
4630 isp_prt(isp, ISP_LOG_WARN1,
4631 "%d.%d.%jx cannot generate next CRN",
4632 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4633 XS_SETERR(xs, HBA_BOTCH);
4634 return (CMD_EAGAIN);
4637 if (ISP_CAP_2KLOGIN(isp)) {
4638 ispreqt2e_t *t2e = (ispreqt2e_t *)local;
4639 t2e->req_target = lp->handle;
4640 t2e->req_scclun = XS_LUN(xs);
4641 tptr = &t2e->req_time;
4642 cdbp = t2e->req_cdb;
4643 } else if (ISP_CAP_SCCFW(isp)) {
4644 t2->req_target = lp->handle;
4645 t2->req_scclun = XS_LUN(xs);
4646 tptr = &t2->req_time;
4649 t2->req_target = lp->handle;
4650 t2->req_lun_trn = XS_LUN(xs);
4651 tptr = &t2->req_time;
4655 *tptr = XS_TIME(xs);
4656 ISP_MEMCPY(cdbp, XS_CDBP(xs), cdblen);
4658 /* Whew. Thankfully the same for type 7 requests */
4659 reqp->req_handle = isp_allocate_handle(isp, xs, ISP_HANDLE_INITIATOR);
4660 if (reqp->req_handle == 0) {
4661 isp_prt(isp, ISP_LOG_WARN1, "out of xflist pointers");
4662 XS_SETERR(xs, HBA_BOTCH);
4663 return (CMD_EAGAIN);
4667 * Set up DMA and/or do any platform dependent swizzling of the request entry
4668 * so that the Qlogic F/W understands what is being asked of it.
4670 * The callee is responsible for adding all requests at this point.
4672 dmaresult = ISP_DMASETUP(isp, xs, reqp);
4673 if (dmaresult != CMD_QUEUED) {
4674 isp_destroy_handle(isp, reqp->req_handle);
4676 * dmasetup sets actual error in packet, and
4677 * return what we were given to return.
4681 isp_xs_prt(isp, xs, ISP_LOGDEBUG0, "START cmd cdb[0]=0x%x datalen %ld", XS_CDBP(xs)[0], (long) XS_XFRLEN(xs));
4682 return (CMD_QUEUED);
4687 * Locks (ints blocked) assumed held.
4691 isp_control(ispsoftc_t *isp, ispctl_t ctl, ...)
4700 case ISPCTL_RESET_BUS:
4702 * Issue a bus reset.
4705 isp_prt(isp, ISP_LOGERR, "BUS RESET NOT IMPLEMENTED");
4707 } else if (IS_FC(isp)) {
4712 chan = va_arg(ap, int);
4714 mbs.param[1] = SDPARAM(isp, chan)->isp_bus_reset_delay;
4715 if (mbs.param[1] < 2) {
4718 mbs.param[2] = chan;
4720 MBSINIT(&mbs, MBOX_BUS_RESET, MBLOGALL, 0);
4721 ISP_SET_SENDMARKER(isp, chan, 1);
4722 isp_mboxcmd(isp, &mbs);
4723 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4726 isp_prt(isp, ISP_LOGINFO, "driver initiated bus reset of bus %d", chan);
4729 case ISPCTL_RESET_DEV:
4731 chan = va_arg(ap, int);
4732 tgt = va_arg(ap, int);
4735 uint8_t local[QENTRY_LEN];
4737 isp24xx_statusreq_t *sp;
4738 fcparam *fcp = FCPARAM(isp, chan);
4741 if (tgt < 0 || tgt >= MAX_FC_TARG) {
4742 isp_prt(isp, ISP_LOGWARN, "Chan %d trying to reset bad target %d", chan, tgt);
4745 lp = &fcp->portdb[tgt];
4746 if (lp->is_target == 0 ||
4747 lp->state != FC_PORTDB_STATE_VALID) {
4748 isp_prt(isp, ISP_LOGWARN, "Chan %d abort of no longer valid target %d", chan, tgt);
4752 tmf = (isp24xx_tmf_t *) local;
4753 ISP_MEMZERO(tmf, QENTRY_LEN);
4754 tmf->tmf_header.rqs_entry_type = RQSTYPE_TSK_MGMT;
4755 tmf->tmf_header.rqs_entry_count = 1;
4756 tmf->tmf_nphdl = lp->handle;
4758 tmf->tmf_timeout = 4;
4759 tmf->tmf_flags = ISP24XX_TMF_TARGET_RESET;
4760 tmf->tmf_tidlo = lp->portid;
4761 tmf->tmf_tidhi = lp->portid >> 16;
4762 tmf->tmf_vpidx = ISP_GET_VPIDX(isp, chan);
4763 isp_put_24xx_tmf(isp, tmf, isp->isp_iocb);
4764 if (isp->isp_dblev & ISP_LOGDEBUG1)
4765 isp_print_bytes(isp, "TMF IOCB request", QENTRY_LEN, isp->isp_iocb);
4766 MEMORYBARRIER(isp, SYNC_IFORDEV, 0, QENTRY_LEN, chan);
4767 fcp->sendmarker = 1;
4769 isp_prt(isp, ISP_LOGALL, "Chan %d Reset N-Port Handle 0x%04x @ Port 0x%06x", chan, lp->handle, lp->portid);
4770 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL,
4771 MBCMD_DEFAULT_TIMEOUT + tmf->tmf_timeout * 1000000);
4772 mbs.param[1] = QENTRY_LEN;
4773 mbs.param[2] = DMA_WD1(isp->isp_iocb_dma);
4774 mbs.param[3] = DMA_WD0(isp->isp_iocb_dma);
4775 mbs.param[6] = DMA_WD3(isp->isp_iocb_dma);
4776 mbs.param[7] = DMA_WD2(isp->isp_iocb_dma);
4777 isp_mboxcmd(isp, &mbs);
4778 if (mbs.param[0] != MBOX_COMMAND_COMPLETE)
4781 MEMORYBARRIER(isp, SYNC_IFORCPU, QENTRY_LEN, QENTRY_LEN, chan);
4782 if (isp->isp_dblev & ISP_LOGDEBUG1)
4783 isp_print_bytes(isp, "TMF IOCB response", QENTRY_LEN, &((isp24xx_statusreq_t *)isp->isp_iocb)[1]);
4784 sp = (isp24xx_statusreq_t *) local;
4785 isp_get_24xx_response(isp, &((isp24xx_statusreq_t *)isp->isp_iocb)[1], sp);
4786 if (sp->req_completion_status == 0) {
4789 isp_prt(isp, ISP_LOGWARN, "Chan %d reset of target %d returned 0x%x", chan, tgt, sp->req_completion_status);
4791 } else if (IS_FC(isp)) {
4792 if (ISP_CAP_2KLOGIN(isp)) {
4794 mbs.ibits = (1 << 10);
4796 mbs.param[1] = (tgt << 8);
4799 mbs.param[1] = (chan << 15) | (tgt << 8);
4801 MBSINIT(&mbs, MBOX_ABORT_TARGET, MBLOGALL, 0);
4802 mbs.param[2] = 3; /* 'delay', in seconds */
4803 isp_mboxcmd(isp, &mbs);
4804 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4807 isp_prt(isp, ISP_LOGINFO, "Target %d on Bus %d Reset Succeeded", tgt, chan);
4808 ISP_SET_SENDMARKER(isp, chan, 1);
4811 case ISPCTL_ABORT_CMD:
4813 xs = va_arg(ap, XS_T *);
4817 chan = XS_CHANNEL(xs);
4819 handle = isp_find_handle(isp, xs);
4821 isp_prt(isp, ISP_LOGWARN, "cannot find handle for command to abort");
4825 isp24xx_abrt_t local, *ab = &local;
4829 fcp = FCPARAM(isp, chan);
4830 if (tgt < 0 || tgt >= MAX_FC_TARG) {
4831 isp_prt(isp, ISP_LOGWARN, "Chan %d trying to abort bad target %d", chan, tgt);
4834 lp = &fcp->portdb[tgt];
4835 if (lp->is_target == 0 ||
4836 lp->state != FC_PORTDB_STATE_VALID) {
4837 isp_prt(isp, ISP_LOGWARN, "Chan %d abort of no longer valid target %d", chan, tgt);
4840 isp_prt(isp, ISP_LOGALL, "Chan %d Abort Cmd for N-Port 0x%04x @ Port 0x%06x", chan, lp->handle, lp->portid);
4841 ISP_MEMZERO(ab, QENTRY_LEN);
4842 ab->abrt_header.rqs_entry_type = RQSTYPE_ABORT_IO;
4843 ab->abrt_header.rqs_entry_count = 1;
4844 ab->abrt_handle = lp->handle;
4845 ab->abrt_cmd_handle = handle;
4846 ab->abrt_tidlo = lp->portid;
4847 ab->abrt_tidhi = lp->portid >> 16;
4848 ab->abrt_vpidx = ISP_GET_VPIDX(isp, chan);
4849 isp_put_24xx_abrt(isp, ab, isp->isp_iocb);
4850 if (isp->isp_dblev & ISP_LOGDEBUG1)
4851 isp_print_bytes(isp, "AB IOCB quest", QENTRY_LEN, isp->isp_iocb);
4852 MEMORYBARRIER(isp, SYNC_IFORDEV, 0, 2 * QENTRY_LEN, chan);
4854 ISP_MEMZERO(&mbs, sizeof (mbs));
4855 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 5000000);
4856 mbs.param[1] = QENTRY_LEN;
4857 mbs.param[2] = DMA_WD1(isp->isp_iocb_dma);
4858 mbs.param[3] = DMA_WD0(isp->isp_iocb_dma);
4859 mbs.param[6] = DMA_WD3(isp->isp_iocb_dma);
4860 mbs.param[7] = DMA_WD2(isp->isp_iocb_dma);
4862 isp_mboxcmd(isp, &mbs);
4863 if (mbs.param[0] != MBOX_COMMAND_COMPLETE)
4866 MEMORYBARRIER(isp, SYNC_IFORCPU, QENTRY_LEN, QENTRY_LEN, chan);
4867 if (isp->isp_dblev & ISP_LOGDEBUG1)
4868 isp_print_bytes(isp, "AB IOCB response", QENTRY_LEN, &((isp24xx_abrt_t *)isp->isp_iocb)[1]);
4869 isp_get_24xx_abrt(isp, &((isp24xx_abrt_t *)isp->isp_iocb)[1], ab);
4870 if (ab->abrt_nphdl == ISP24XX_ABRT_OKAY) {
4873 isp_prt(isp, ISP_LOGWARN, "Chan %d handle %d abort returned 0x%x", chan, tgt, ab->abrt_nphdl);
4875 } else if (IS_FC(isp)) {
4876 if (ISP_CAP_SCCFW(isp)) {
4877 if (ISP_CAP_2KLOGIN(isp)) {
4880 mbs.param[1] = tgt << 8;
4882 mbs.param[6] = XS_LUN(xs);
4884 mbs.param[1] = tgt << 8 | XS_LUN(xs);
4887 mbs.param[1] = (chan << 15) | (tgt << 8) | XS_LUN(xs);
4889 MBSINIT(&mbs, MBOX_ABORT,
4890 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_ERROR), 0);
4891 mbs.param[2] = handle;
4892 isp_mboxcmd(isp, &mbs);
4893 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4898 case ISPCTL_UPDATE_PARAMS:
4901 chan = va_arg(ap, int);
4903 isp_spi_update(isp, chan);
4906 case ISPCTL_FCLINK_TEST:
4911 chan = va_arg(ap, int);
4912 usdelay = va_arg(ap, int);
4917 return (isp_fclink_test(isp, chan, usdelay));
4921 case ISPCTL_SCAN_FABRIC:
4925 chan = va_arg(ap, int);
4927 return (isp_scan_fabric(isp, chan));
4931 case ISPCTL_SCAN_LOOP:
4935 chan = va_arg(ap, int);
4937 return (isp_scan_loop(isp, chan));
4941 case ISPCTL_PDB_SYNC:
4945 chan = va_arg(ap, int);
4947 return (isp_pdb_sync(isp, chan));
4951 case ISPCTL_SEND_LIP:
4953 if (IS_FC(isp) && !IS_24XX(isp)) {
4954 MBSINIT(&mbs, MBOX_INIT_LIP, MBLOGALL, 0);
4955 if (ISP_CAP_2KLOGIN(isp)) {
4956 mbs.ibits = (1 << 10);
4958 isp_mboxcmd(isp, &mbs);
4959 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
4965 case ISPCTL_GET_PDB:
4969 chan = va_arg(ap, int);
4970 tgt = va_arg(ap, int);
4971 pdb = va_arg(ap, isp_pdb_t *);
4973 return (isp_getpdb(isp, chan, tgt, pdb));
4977 case ISPCTL_GET_NAMES:
4979 uint64_t *wwnn, *wwnp;
4981 chan = va_arg(ap, int);
4982 tgt = va_arg(ap, int);
4983 wwnn = va_arg(ap, uint64_t *);
4984 wwnp = va_arg(ap, uint64_t *);
4986 if (wwnn == NULL && wwnp == NULL) {
4990 *wwnn = isp_get_wwn(isp, chan, tgt, 1);
4991 if (*wwnn == INI_NONE) {
4996 *wwnp = isp_get_wwn(isp, chan, tgt, 0);
4997 if (*wwnp == INI_NONE) {
5003 case ISPCTL_RUN_MBOXCMD:
5006 mbr = va_arg(ap, mbreg_t *);
5008 isp_mboxcmd(isp, mbr);
5017 p = va_arg(ap, isp_plcmd_t *);
5020 if ((p->flags & PLOGX_FLG_CMD_MASK) != PLOGX_FLG_CMD_PLOGI || (p->handle != NIL_HANDLE)) {
5021 return (isp_plogx(isp, p->channel, p->handle, p->portid, p->flags));
5024 isp_next_handle(isp, &p->handle);
5025 r = isp_plogx(isp, p->channel, p->handle, p->portid, p->flags);
5026 if ((r & 0xffff) == MBOX_PORT_ID_USED) {
5027 p->handle = r >> 16;
5031 } while ((r & 0xffff) == MBOX_LOOP_ID_USED);
5034 case ISPCTL_CHANGE_ROLE:
5039 chan = va_arg(ap, int);
5040 role = va_arg(ap, int);
5042 r = isp_fc_change_role(isp, chan, role);
5047 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
5055 * Interrupt Service Routine(s).
5057 * External (OS) framework has done the appropriate locking,
5058 * and the locking will be held throughout this function.
5061 #ifdef ISP_TARGET_MODE
5063 isp_intr_atioq(ispsoftc_t *isp)
5065 uint8_t qe[QENTRY_LEN];
5068 uint32_t iptr, optr, oop;
5070 iptr = ISP_READ(isp, BIU2400_ATIO_RSPINP);
5071 optr = isp->isp_atioodx;
5072 while (optr != iptr) {
5074 MEMORYBARRIER(isp, SYNC_ATIOQ, oop, QENTRY_LEN, -1);
5075 addr = ISP_QUEUE_ENTRY(isp->isp_atioq, oop);
5076 isp_get_hdr(isp, addr, (isphdr_t *)qe);
5077 hp = (isphdr_t *)qe;
5078 switch (hp->rqs_entry_type) {
5079 case RQSTYPE_NOTIFY:
5081 (void) isp_target_notify(isp, addr, &oop);
5084 isp_print_qentry(isp, "?ATIOQ entry?", oop, addr);
5087 optr = ISP_NXT_QENTRY(oop, RESULT_QUEUE_LEN(isp));
5089 if (isp->isp_atioodx != optr) {
5090 ISP_WRITE(isp, BIU2400_ATIO_RSPOUTP, optr);
5091 isp->isp_atioodx = optr;
5097 isp_intr_async(ispsoftc_t *isp, uint16_t event)
5101 isp_parse_async_fc(isp, event);
5103 isp_parse_async(isp, event);
5107 isp_intr_mbox(ispsoftc_t *isp, uint16_t mbox0)
5111 if (!isp->isp_mboxbsy) {
5112 isp_prt(isp, ISP_LOGWARN, "mailbox 0x%x with no waiters", mbox0);
5115 obits = isp->isp_obits;
5116 isp->isp_mboxtmp[0] = mbox0;
5117 for (i = 1; i < ISP_NMBOX(isp); i++) {
5118 if ((obits & (1 << i)) == 0)
5120 isp->isp_mboxtmp[i] = ISP_READ(isp, MBOX_OFF(i));
5122 MBOX_NOTIFY_COMPLETE(isp);
5126 isp_intr_respq(ispsoftc_t *isp)
5129 uint8_t qe[QENTRY_LEN];
5130 ispstatusreq_t *sp = (ispstatusreq_t *)qe;
5131 isp24xx_statusreq_t *sp2 = (isp24xx_statusreq_t *)qe;
5133 uint8_t *resp, *snsp;
5134 int buddaboom, completion_status, cont = 0, etype, i;
5135 int req_status_flags, req_state_flags, scsi_status;
5136 uint32_t iptr, junk, cptr, optr, rlen, slen, sptr, totslen, resid;
5139 * We can't be getting this now.
5141 if (isp->isp_state != ISP_RUNSTATE) {
5142 isp_prt(isp, ISP_LOGINFO, "respq interrupt when not ready");
5146 iptr = ISP_READ(isp, isp->isp_respinrp);
5147 /* Debounce the 2300 if revision less than 2. */
5148 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
5151 iptr = ISP_READ(isp, isp->isp_respinrp);
5152 } while (junk != iptr);
5154 isp->isp_residx = iptr;
5156 optr = isp->isp_resodx;
5157 while (optr != iptr) {
5159 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, cptr);
5160 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
5163 * Synchronize our view of this response queue entry.
5165 MEMORYBARRIER(isp, SYNC_RESULT, cptr, QENTRY_LEN, -1);
5166 if (isp->isp_dblev & ISP_LOGDEBUG1)
5167 isp_print_qentry(isp, "Response Queue Entry", cptr, hp);
5168 isp_get_hdr(isp, hp, &sp->req_header);
5169 etype = sp->req_header.rqs_entry_type;
5171 /* We expected Status Continuation, but got different IOCB. */
5172 if (cont > 0 && etype != RQSTYPE_STATUS_CONT) {
5177 if (IS_24XX(isp) && etype == RQSTYPE_RESPONSE) {
5178 isp_get_24xx_response(isp, (isp24xx_statusreq_t *)hp, sp2);
5179 scsi_status = sp2->req_scsi_status;
5180 completion_status = sp2->req_completion_status;
5181 req_status_flags = 0;
5182 if ((scsi_status & 0xff) != 0)
5183 req_state_flags = RQSF_GOT_STATUS;
5185 req_state_flags = 0;
5186 resid = sp2->req_resid;
5187 } else if (etype == RQSTYPE_RESPONSE) {
5188 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
5189 scsi_status = sp->req_scsi_status;
5190 completion_status = sp->req_completion_status;
5191 req_status_flags = sp->req_status_flags;
5192 req_state_flags = sp->req_state_flags;
5193 resid = sp->req_resid;
5194 } else if (etype == RQSTYPE_RIO1) {
5195 isp_rio1_t *rio = (isp_rio1_t *) qe;
5196 isp_get_rio1(isp, (isp_rio1_t *) hp, rio);
5197 for (i = 0; i < rio->req_header.rqs_seqno; i++) {
5198 isp_fastpost_complete(isp, rio->req_handles[i]);
5200 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5202 } else if (etype == RQSTYPE_RIO2) {
5203 isp_prt(isp, ISP_LOGERR, "dropping RIO2 response");
5204 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5206 } else if (etype == RQSTYPE_STATUS_CONT) {
5207 ispstatus_cont_t *scp = (ispstatus_cont_t *)qe;
5208 isp_get_cont_response(isp, (ispstatus_cont_t *)hp, scp);
5210 i = min(cont, sizeof(scp->req_sense_data));
5211 XS_SENSE_APPEND(cont_xs, scp->req_sense_data, i);
5216 isp_prt(isp, ISP_LOGDEBUG0|ISP_LOG_CWARN,
5217 "Expecting Status Continuations for %u bytes",
5221 isp_prt(isp, ISP_LOG_WARN1, "Ignored Continuation Response");
5223 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5225 } else if (isp_handle_other_response(isp, etype, hp, &cptr)) {
5226 /* More then one IOCB could be consumed. */
5227 while (sptr != cptr) {
5228 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5229 sptr = ISP_NXT_QENTRY(sptr, RESULT_QUEUE_LEN(isp));
5230 hp = (isphdr_t *)ISP_QUEUE_ENTRY(isp->isp_result, sptr);
5232 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5233 optr = ISP_NXT_QENTRY(cptr, RESULT_QUEUE_LEN(isp));
5236 /* We don't know what was this -- log and skip. */
5237 isp_prt(isp, ISP_LOGERR, notresp, etype, cptr, optr);
5238 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5243 if (sp->req_header.rqs_flags & RQSFLAG_MASK) {
5244 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
5245 isp_print_qentry(isp, "unexpected continuation segment",
5249 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
5250 isp_prt(isp, ISP_LOG_WARN1, "internal queues full");
5252 * We'll synthesize a QUEUE FULL message below.
5255 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
5256 isp_print_qentry(isp, "bad header flag",
5260 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
5261 isp_print_qentry(isp, "bad request packet",
5265 if (sp->req_header.rqs_flags & RQSFLAG_BADCOUNT) {
5266 isp_print_qentry(isp, "invalid entry count",
5270 if (sp->req_header.rqs_flags & RQSFLAG_BADORDER) {
5271 isp_print_qentry(isp, "invalid IOCB ordering",
5277 xs = isp_find_xs(isp, sp->req_handle);
5279 uint8_t ts = completion_status & 0xff;
5281 * Only whine if this isn't the expected fallout of
5282 * aborting the command or resetting the target.
5284 if (etype != RQSTYPE_RESPONSE) {
5285 isp_prt(isp, ISP_LOGERR, "cannot find handle 0x%x (type 0x%x)", sp->req_handle, etype);
5286 } else if (ts != RQCS_ABORTED && ts != RQCS_RESET_OCCURRED) {
5287 isp_prt(isp, ISP_LOGERR, "cannot find handle 0x%x (status 0x%x)", sp->req_handle, ts);
5289 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5292 if (req_status_flags & RQSTF_BUS_RESET) {
5293 isp_prt(isp, ISP_LOG_WARN1, "%d.%d.%jx bus was reset",
5294 XS_CHANNEL(xs), XS_TGT(xs), (uintmax_t)XS_LUN(xs));
5295 XS_SETERR(xs, HBA_BUSRESET);
5296 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 1);
5299 isp_prt(isp, ISP_LOG_WARN1, "%d.%d.%jx buddaboom",
5300 XS_CHANNEL(xs), XS_TGT(xs), (uintmax_t)XS_LUN(xs));
5301 XS_SETERR(xs, HBA_BOTCH);
5305 rlen = slen = totslen = 0;
5306 if (IS_24XX(isp) && (scsi_status & (RQCS_RV|RQCS_SV)) != 0) {
5307 resp = sp2->req_rsp_sense;
5308 rlen = sp2->req_response_len;
5309 } else if (IS_FC(isp) && (scsi_status & RQCS_RV) != 0) {
5310 resp = sp->req_response;
5311 rlen = sp->req_response_len;
5313 if (IS_FC(isp) && (scsi_status & RQCS_SV) != 0) {
5315 * Fibre Channel F/W doesn't say we got status
5316 * if there's Sense Data instead. I guess they
5317 * think it goes w/o saying.
5319 req_state_flags |= RQSF_GOT_STATUS|RQSF_GOT_SENSE;
5321 snsp = sp2->req_rsp_sense;
5323 totslen = sp2->req_sense_len;
5324 slen = sizeof(sp2->req_rsp_sense) - rlen;
5326 snsp = sp->req_sense_data;
5327 totslen = sp->req_sense_len;
5328 slen = sizeof(sp->req_sense_data);
5330 } else if (IS_SCSI(isp) && (req_state_flags & RQSF_GOT_SENSE)) {
5331 snsp = sp->req_sense_data;
5332 totslen = sp->req_sense_len;
5333 slen = sizeof (sp->req_sense_data);
5337 if (req_state_flags & RQSF_GOT_STATUS)
5338 *XS_STSP(xs) = scsi_status & 0xff;
5340 if (rlen >= 4 && resp[FCP_RSPNS_CODE_OFFSET] != 0) {
5343 const char *rnames[10] = {
5344 "Task Management function complete",
5345 "FCP_DATA length different than FCP_BURST_LEN",
5346 "FCP_CMND fields invalid",
5347 "FCP_DATA parameter mismatch with FCP_DATA_RO",
5348 "Task Management function rejected",
5349 "Task Management function failed",
5352 "Task Management function succeeded",
5353 "Task Management function incorrect logical unit number",
5355 uint8_t code = resp[FCP_RSPNS_CODE_OFFSET];
5356 if (code >= 10 || rnames[code] == NULL) {
5357 ISP_SNPRINTF(lb, sizeof(lb),
5358 "Unknown FCP Response Code 0x%x", code);
5363 isp_xs_prt(isp, xs, ISP_LOGWARN,
5364 "FCP RESPONSE, LENGTH %u: %s CDB0=0x%02x",
5365 rlen, ptr, XS_CDBP(xs)[0] & 0xff);
5366 if (code != 0 && code != 8)
5367 XS_SETERR(xs, HBA_BOTCH);
5370 isp_parse_status_24xx(isp, sp2, xs, &resid);
5372 isp_parse_status(isp, sp, xs, &resid);
5373 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) &&
5374 (*XS_STSP(xs) == SCSI_BUSY))
5375 XS_SETERR(xs, HBA_TGTBSY);
5377 XS_SET_RESID(xs, resid);
5379 * A new synchronous rate was negotiated for
5380 * this target. Mark state such that we'll go
5381 * look up that which has changed later.
5383 if (req_status_flags & RQSTF_NEGOTIATION) {
5385 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
5386 sdp->isp_devparam[t].dev_refresh = 1;
5390 if (req_status_flags & RQSF_XFER_COMPLETE) {
5391 XS_SET_RESID(xs, 0);
5392 } else if (scsi_status & RQCS_RESID) {
5393 XS_SET_RESID(xs, resid);
5395 XS_SET_RESID(xs, 0);
5399 XS_SAVE_SENSE(xs, snsp, slen);
5400 if (totslen > slen) {
5401 cont = totslen - slen;
5403 isp_prt(isp, ISP_LOGDEBUG0|ISP_LOG_CWARN,
5404 "Expecting Status Continuations for %u bytes",
5408 isp_prt(isp, ISP_LOGDEBUG2, "asked for %lu got raw resid %lu settled for %lu",
5409 (u_long)XS_XFRLEN(xs), (u_long)resid, (u_long)XS_GET_RESID(xs));
5412 ISP_DMAFREE(isp, xs, sp->req_handle);
5413 isp_destroy_handle(isp, sp->req_handle);
5415 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5417 /* Complete command if we expect no Status Continuations. */
5422 /* We haven't received all Status Continuations, but that is it. */
5426 /* If we processed any IOCBs, let ISP know about it. */
5427 if (optr != isp->isp_resodx) {
5428 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5429 isp->isp_resodx = optr;
5434 * Parse an ASYNC mailbox complete
5437 isp_parse_async(ispsoftc_t *isp, uint16_t mbox)
5439 uint32_t h1 = 0, h2 = 0;
5443 * Pick up the channel, but not if this is a ASYNC_RIO32_2,
5444 * where Mailboxes 6/7 have the second handle.
5446 if (mbox != ASYNC_RIO32_2) {
5447 if (IS_DUALBUS(isp)) {
5448 chan = ISP_READ(isp, OUTMAILBOX6);
5451 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
5454 case ASYNC_BUS_RESET:
5455 ISP_SET_SENDMARKER(isp, chan, 1);
5456 #ifdef ISP_TARGET_MODE
5457 isp_target_async(isp, chan, mbox);
5459 isp_async(isp, ISPASYNC_BUS_RESET, chan);
5461 case ASYNC_SYSTEM_ERROR:
5462 isp->isp_state = ISP_CRASHED;
5464 * Were we waiting for a mailbox command to complete?
5465 * If so, it's dead, so wake up the waiter.
5467 if (isp->isp_mboxbsy) {
5469 isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR;
5470 MBOX_NOTIFY_COMPLETE(isp);
5473 * It's up to the handler for isp_async to reinit stuff and
5474 * restart the firmware
5476 isp_async(isp, ISPASYNC_FW_CRASH);
5479 case ASYNC_RQS_XFER_ERR:
5480 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
5483 case ASYNC_RSP_XFER_ERR:
5484 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
5489 * We've just been notified that the Queue has woken up.
5490 * We don't need to be chatty about this- just unlatch things
5493 mbox = ISP_READ(isp, isp->isp_rqstoutrp);
5496 case ASYNC_TIMEOUT_RESET:
5497 isp_prt(isp, ISP_LOGWARN, "timeout initiated SCSI bus reset of chan %d", chan);
5498 ISP_SET_SENDMARKER(isp, chan, 1);
5499 #ifdef ISP_TARGET_MODE
5500 isp_target_async(isp, chan, mbox);
5504 case ASYNC_DEVICE_RESET:
5505 isp_prt(isp, ISP_LOGINFO, "device reset on chan %d", chan);
5506 ISP_SET_SENDMARKER(isp, chan, 1);
5507 #ifdef ISP_TARGET_MODE
5508 isp_target_async(isp, chan, mbox);
5512 case ASYNC_EXTMSG_UNDERRUN:
5513 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
5516 case ASYNC_SCAM_INT:
5517 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
5520 case ASYNC_HUNG_SCSI:
5521 isp_prt(isp, ISP_LOGERR, "stalled SCSI Bus after DATA Overrun");
5522 /* XXX: Need to issue SCSI reset at this point */
5525 case ASYNC_KILLED_BUS:
5526 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
5529 case ASYNC_BUS_TRANSIT:
5530 mbox = ISP_READ(isp, OUTMAILBOX2);
5531 switch (mbox & SXP_PINS_MODE_MASK) {
5532 case SXP_PINS_LVD_MODE:
5533 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
5534 SDPARAM(isp, chan)->isp_diffmode = 0;
5535 SDPARAM(isp, chan)->isp_ultramode = 0;
5536 SDPARAM(isp, chan)->isp_lvdmode = 1;
5538 case SXP_PINS_HVD_MODE:
5539 isp_prt(isp, ISP_LOGINFO,
5540 "Transition to Differential mode");
5541 SDPARAM(isp, chan)->isp_diffmode = 1;
5542 SDPARAM(isp, chan)->isp_ultramode = 0;
5543 SDPARAM(isp, chan)->isp_lvdmode = 0;
5545 case SXP_PINS_SE_MODE:
5546 isp_prt(isp, ISP_LOGINFO,
5547 "Transition to Single Ended mode");
5548 SDPARAM(isp, chan)->isp_diffmode = 0;
5549 SDPARAM(isp, chan)->isp_ultramode = 1;
5550 SDPARAM(isp, chan)->isp_lvdmode = 0;
5553 isp_prt(isp, ISP_LOGWARN,
5554 "Transition to Unknown Mode 0x%x", mbox);
5558 * XXX: Set up to renegotiate again!
5560 /* Can only be for a 1080... */
5561 ISP_SET_SENDMARKER(isp, chan, 1);
5564 case ASYNC_CMD_CMPLT:
5566 if (!IS_ULTRA3(isp)) {
5567 isp_prt(isp, ISP_LOGERR, "unexpected fast posting completion");
5571 h1 = (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1);
5575 h1 = (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1);
5576 h2 = (ISP_READ(isp, OUTMAILBOX7) << 16) | ISP_READ(isp, OUTMAILBOX6);
5584 isp_prt(isp, ISP_LOGERR, "unexpected 16 bit RIO handle");
5587 isp_prt(isp, ISP_LOGWARN, "%s: unhandled async code 0x%x", __func__, mbox);
5592 isp_prt(isp, ISP_LOGDEBUG3, "fast post/rio completion of 0x%08x", h1);
5593 isp_fastpost_complete(isp, h1);
5595 isp_prt(isp, ISP_LOGDEBUG3, "fast post/rio completion of 0x%08x", h2);
5596 isp_fastpost_complete(isp, h2);
5602 isp_parse_async_fc(ispsoftc_t *isp, uint16_t mbox)
5607 if (IS_DUALBUS(isp)) {
5608 chan = ISP_READ(isp, OUTMAILBOX6);
5612 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
5615 case ASYNC_SYSTEM_ERROR:
5616 isp->isp_state = ISP_CRASHED;
5617 FCPARAM(isp, chan)->isp_loopstate = LOOP_NIL;
5618 isp_change_fw_state(isp, chan, FW_CONFIG_WAIT);
5620 * Were we waiting for a mailbox command to complete?
5621 * If so, it's dead, so wake up the waiter.
5623 if (isp->isp_mboxbsy) {
5625 isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR;
5626 MBOX_NOTIFY_COMPLETE(isp);
5629 * It's up to the handler for isp_async to reinit stuff and
5630 * restart the firmware
5632 isp_async(isp, ISPASYNC_FW_CRASH);
5635 case ASYNC_RQS_XFER_ERR:
5636 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
5639 case ASYNC_RSP_XFER_ERR:
5640 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
5644 #ifdef ISP_TARGET_MODE
5646 isp_prt(isp, ISP_LOGERR, "ATIO Queue Transfer Error");
5650 isp_prt(isp, ISP_LOGERR, "%s: unexpected ASYNC_QWAKEUP code", __func__);
5653 case ASYNC_CMD_CMPLT:
5654 isp_fastpost_complete(isp, (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1));
5657 case ASYNC_RIOZIO_STALL:
5658 isp_intr_respq(isp);
5661 case ASYNC_CTIO_DONE:
5662 #ifdef ISP_TARGET_MODE
5663 isp_target_async(isp, (ISP_READ(isp, OUTMAILBOX2) << 16) |
5664 ISP_READ(isp, OUTMAILBOX1), mbox);
5666 isp_prt(isp, ISP_LOGWARN, "unexpected ASYNC CTIO done");
5669 case ASYNC_LIP_ERROR:
5670 case ASYNC_LIP_NOS_OLS_RECV:
5671 case ASYNC_LIP_OCCURRED:
5674 * These are broadcast events that have to be sent across
5675 * all active channels.
5677 for (chan = 0; chan < isp->isp_nchan; chan++) {
5678 fcp = FCPARAM(isp, chan);
5679 int topo = fcp->isp_topo;
5681 if (fcp->role == ISP_ROLE_NONE)
5683 if (fcp->isp_loopstate > LOOP_HAVE_LINK)
5684 fcp->isp_loopstate = LOOP_HAVE_LINK;
5685 ISP_SET_SENDMARKER(isp, chan, 1);
5686 isp_async(isp, ISPASYNC_LIP, chan);
5687 #ifdef ISP_TARGET_MODE
5688 isp_target_async(isp, chan, mbox);
5691 * We've had problems with data corruption occurring on
5692 * commands that complete (with no apparent error) after
5693 * we receive a LIP. This has been observed mostly on
5694 * Local Loop topologies. To be safe, let's just mark
5695 * all active initiator commands as dead.
5697 if (topo == TOPO_NL_PORT || topo == TOPO_FL_PORT) {
5699 for (i = j = 0; i < isp->isp_maxcmds; i++) {
5703 hdp = &isp->isp_xflist[i];
5704 if (ISP_H2HT(hdp->handle) != ISP_HANDLE_INITIATOR) {
5708 if (XS_CHANNEL(xs) != chan) {
5712 isp_prt(isp, ISP_LOG_WARN1,
5713 "%d.%d.%jx bus reset set at %s:%u",
5714 XS_CHANNEL(xs), XS_TGT(xs),
5715 (uintmax_t)XS_LUN(xs),
5716 __func__, __LINE__);
5717 XS_SETERR(xs, HBA_BUSRESET);
5720 isp_prt(isp, ISP_LOGERR, lipd, chan, j);
5728 * This is a broadcast event that has to be sent across
5729 * all active channels.
5731 for (chan = 0; chan < isp->isp_nchan; chan++) {
5732 fcp = FCPARAM(isp, chan);
5733 if (fcp->role == ISP_ROLE_NONE)
5735 fcp->isp_linkstate = 1;
5736 if (fcp->isp_loopstate < LOOP_HAVE_LINK)
5737 fcp->isp_loopstate = LOOP_HAVE_LINK;
5738 ISP_SET_SENDMARKER(isp, chan, 1);
5739 isp_async(isp, ISPASYNC_LOOP_UP, chan);
5740 #ifdef ISP_TARGET_MODE
5741 isp_target_async(isp, chan, mbox);
5746 case ASYNC_LOOP_DOWN:
5748 * This is a broadcast event that has to be sent across
5749 * all active channels.
5751 for (chan = 0; chan < isp->isp_nchan; chan++) {
5752 fcp = FCPARAM(isp, chan);
5753 if (fcp->role == ISP_ROLE_NONE)
5755 ISP_SET_SENDMARKER(isp, chan, 1);
5756 fcp->isp_linkstate = 0;
5757 fcp->isp_loopstate = LOOP_NIL;
5758 isp_async(isp, ISPASYNC_LOOP_DOWN, chan);
5759 #ifdef ISP_TARGET_MODE
5760 isp_target_async(isp, chan, mbox);
5765 case ASYNC_LOOP_RESET:
5767 * This is a broadcast event that has to be sent across
5768 * all active channels.
5770 for (chan = 0; chan < isp->isp_nchan; chan++) {
5771 fcp = FCPARAM(isp, chan);
5772 if (fcp->role == ISP_ROLE_NONE)
5774 ISP_SET_SENDMARKER(isp, chan, 1);
5775 if (fcp->isp_loopstate > LOOP_HAVE_LINK)
5776 fcp->isp_loopstate = LOOP_HAVE_LINK;
5777 isp_async(isp, ISPASYNC_LOOP_RESET, chan);
5778 #ifdef ISP_TARGET_MODE
5779 isp_target_async(isp, chan, mbox);
5784 case ASYNC_PDB_CHANGED:
5786 int echan, nphdl, nlstate, reason;
5788 if (IS_23XX(isp) || IS_24XX(isp)) {
5789 nphdl = ISP_READ(isp, OUTMAILBOX1);
5790 nlstate = ISP_READ(isp, OUTMAILBOX2);
5792 nphdl = nlstate = 0xffff;
5795 reason = ISP_READ(isp, OUTMAILBOX3) >> 8;
5798 if (ISP_CAP_MULTI_ID(isp)) {
5799 chan = ISP_READ(isp, OUTMAILBOX3) & 0xff;
5800 if (chan == 0xff || nphdl == NIL_HANDLE) {
5802 echan = isp->isp_nchan - 1;
5803 } else if (chan >= isp->isp_nchan) {
5811 for (; chan <= echan; chan++) {
5812 fcp = FCPARAM(isp, chan);
5813 if (fcp->role == ISP_ROLE_NONE)
5815 if (fcp->isp_loopstate > LOOP_LTEST_DONE) {
5816 if (nphdl != NIL_HANDLE &&
5817 nphdl == fcp->isp_login_hdl &&
5818 reason == PDB24XX_AE_OPN_2)
5820 fcp->isp_loopstate = LOOP_LTEST_DONE;
5821 } else if (fcp->isp_loopstate < LOOP_HAVE_LINK)
5822 fcp->isp_loopstate = LOOP_HAVE_LINK;
5823 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan,
5824 ISPASYNC_CHANGE_PDB, nphdl, nlstate, reason);
5828 case ASYNC_CHANGE_NOTIFY:
5832 portid = ((ISP_READ(isp, OUTMAILBOX1) & 0xff) << 16) |
5833 ISP_READ(isp, OUTMAILBOX2);
5834 if (ISP_CAP_MULTI_ID(isp)) {
5835 chan = ISP_READ(isp, OUTMAILBOX3) & 0xff;
5836 if (chan >= isp->isp_nchan)
5841 fcp = FCPARAM(isp, chan);
5842 if (fcp->role == ISP_ROLE_NONE)
5844 if (fcp->isp_loopstate > LOOP_LTEST_DONE)
5845 fcp->isp_loopstate = LOOP_LTEST_DONE;
5846 else if (fcp->isp_loopstate < LOOP_HAVE_LINK)
5847 fcp->isp_loopstate = LOOP_HAVE_LINK;
5848 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan,
5849 ISPASYNC_CHANGE_SNS, portid);
5852 case ASYNC_ERR_LOGGING_DISABLED:
5853 isp_prt(isp, ISP_LOGWARN, "Error logging disabled (reason 0x%x)",
5854 ISP_READ(isp, OUTMAILBOX1));
5856 case ASYNC_CONNMODE:
5858 * This only applies to 2100 amd 2200 cards
5860 if (!IS_2200(isp) && !IS_2100(isp)) {
5861 isp_prt(isp, ISP_LOGWARN, "bad card for ASYNC_CONNMODE event");
5865 mbox = ISP_READ(isp, OUTMAILBOX1);
5868 isp_prt(isp, ISP_LOGINFO,
5869 "Point-to-Point -> Loop mode");
5872 isp_prt(isp, ISP_LOGINFO,
5873 "Loop -> Point-to-Point mode");
5875 case ISP_CONN_BADLIP:
5876 isp_prt(isp, ISP_LOGWARN,
5877 "Point-to-Point -> Loop mode (BAD LIP)");
5879 case ISP_CONN_FATAL:
5880 isp->isp_state = ISP_CRASHED;
5881 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
5882 isp_async(isp, ISPASYNC_FW_CRASH);
5884 case ISP_CONN_LOOPBACK:
5885 isp_prt(isp, ISP_LOGWARN,
5886 "Looped Back in Point-to-Point mode");
5889 isp_prt(isp, ISP_LOGWARN,
5890 "Unknown connection mode (0x%x)", mbox);
5893 ISP_SET_SENDMARKER(isp, chan, 1);
5894 FCPARAM(isp, chan)->isp_loopstate = LOOP_HAVE_LINK;
5895 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan, ISPASYNC_CHANGE_OTHER);
5897 case ASYNC_P2P_INIT_ERR:
5898 isp_prt(isp, ISP_LOGWARN, "P2P init error (reason 0x%x)",
5899 ISP_READ(isp, OUTMAILBOX1));
5903 isp_prt(isp, ISP_LOGWARN, "Receive Error");
5905 isp_prt(isp, ISP_LOGWARN, "unexpected ASYNC_RCV_ERR");
5908 case ASYNC_RJT_SENT: /* same as ASYNC_QFULL_SENT */
5910 isp_prt(isp, ISP_LOGTDEBUG0, "LS_RJT sent");
5913 isp_prt(isp, ISP_LOGTDEBUG0, "QFULL sent");
5916 case ASYNC_FW_RESTART_COMPLETE:
5917 isp_prt(isp, ISP_LOGDEBUG0, "FW restart complete");
5919 case ASYNC_TEMPERATURE_ALERT:
5920 isp_prt(isp, ISP_LOGERR, "Temperature alert (subcode 0x%x)",
5921 ISP_READ(isp, OUTMAILBOX1));
5923 case ASYNC_TRANSCEIVER_INSERTION:
5924 isp_prt(isp, ISP_LOGDEBUG0, "Transceiver insertion (0x%x)",
5925 ISP_READ(isp, OUTMAILBOX1));
5927 case ASYNC_TRANSCEIVER_REMOVAL:
5928 isp_prt(isp, ISP_LOGDEBUG0, "Transceiver removal");
5930 case ASYNC_AUTOLOAD_FW_COMPLETE:
5931 isp_prt(isp, ISP_LOGDEBUG0, "Autoload FW init complete");
5933 case ASYNC_AUTOLOAD_FW_FAILURE:
5934 isp_prt(isp, ISP_LOGERR, "Autoload FW init failure");
5937 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
5943 * Handle other response entries. A pointer to the request queue output
5944 * index is here in case we want to eat several entries at once, although
5945 * this is not used currently.
5949 isp_handle_other_response(ispsoftc_t *isp, int type, isphdr_t *hp, uint32_t *optrp)
5953 uint32_t hdl, portid;
5957 case RQSTYPE_MARKER:
5958 isp_prt(isp, ISP_LOG_WARN1, "Marker Response");
5960 case RQSTYPE_RPT_ID_ACQ:
5961 isp_get_ridacq(isp, (isp_ridacq_t *)hp, &rid);
5962 portid = (uint32_t)rid.ridacq_vp_port_hi << 16 |
5963 rid.ridacq_vp_port_lo;
5964 if (rid.ridacq_format == 0) {
5965 for (chan = 0; chan < isp->isp_nchan; chan++) {
5966 fcparam *fcp = FCPARAM(isp, chan);
5967 if (fcp->role == ISP_ROLE_NONE)
5969 c = (chan == 0) ? 127 : (chan - 1);
5970 if (rid.ridacq_map[c / 16] & (1 << (c % 16)) ||
5972 fcp->isp_loopstate = LOOP_HAVE_LINK;
5973 isp_async(isp, ISPASYNC_CHANGE_NOTIFY,
5974 chan, ISPASYNC_CHANGE_OTHER);
5976 fcp->isp_loopstate = LOOP_NIL;
5977 isp_async(isp, ISPASYNC_LOOP_DOWN,
5982 fcparam *fcp = FCPARAM(isp, rid.ridacq_vp_index);
5983 if (rid.ridacq_vp_status == RIDACQ_STS_COMPLETE ||
5984 rid.ridacq_vp_status == RIDACQ_STS_CHANGED) {
5985 fcp->isp_topo = (rid.ridacq_map[0] >> 9) & 0x7;
5986 fcp->isp_portid = portid;
5987 fcp->isp_loopstate = LOOP_HAVE_ADDR;
5988 isp_async(isp, ISPASYNC_CHANGE_NOTIFY,
5989 rid.ridacq_vp_index, ISPASYNC_CHANGE_OTHER);
5991 fcp->isp_loopstate = LOOP_NIL;
5992 isp_async(isp, ISPASYNC_LOOP_DOWN,
5993 rid.ridacq_vp_index);
5997 case RQSTYPE_CT_PASSTHRU:
5998 case RQSTYPE_VP_MODIFY:
5999 case RQSTYPE_VP_CTRL:
6001 ISP_IOXGET_32(isp, (uint32_t *)(hp + 1), hdl);
6002 ptr = isp_find_xs(isp, hdl);
6004 isp_destroy_handle(isp, hdl);
6005 memcpy(ptr, hp, QENTRY_LEN);
6011 case RQSTYPE_NOTIFY:
6012 case RQSTYPE_NOTIFY_ACK:
6018 case RQSTYPE_ABTS_RCVD:
6019 case RQSTYPE_ABTS_RSP:
6020 #ifdef ISP_TARGET_MODE
6021 return (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp));
6024 case RQSTYPE_REQUEST:
6031 isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, uint32_t *rp)
6033 switch (sp->req_completion_status & 0xff) {
6036 XS_SETERR(xs, HBA_NOERROR);
6040 case RQCS_INCOMPLETE:
6041 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
6042 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "Selection Timeout @ %s:%d", __func__, __LINE__);
6044 XS_SETERR(xs, HBA_SELTIMEOUT);
6045 *rp = XS_XFRLEN(xs);
6049 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Incomplete, state 0x%x", sp->req_state_flags);
6052 case RQCS_DMA_ERROR:
6053 isp_xs_prt(isp, xs, ISP_LOGERR, "DMA Error");
6054 *rp = XS_XFRLEN(xs);
6057 case RQCS_TRANSPORT_ERROR:
6060 ISP_SNPRINTF(buf, sizeof (buf), "states=>");
6061 if (sp->req_state_flags & RQSF_GOT_BUS) {
6062 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
6064 if (sp->req_state_flags & RQSF_GOT_TARGET) {
6065 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
6067 if (sp->req_state_flags & RQSF_SENT_CDB) {
6068 ISP_SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
6070 if (sp->req_state_flags & RQSF_XFRD_DATA) {
6071 ISP_SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
6073 if (sp->req_state_flags & RQSF_GOT_STATUS) {
6074 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
6076 if (sp->req_state_flags & RQSF_GOT_SENSE) {
6077 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
6079 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
6080 ISP_SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
6082 ISP_SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
6083 if (sp->req_status_flags & RQSTF_DISCONNECT) {
6084 ISP_SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
6086 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
6087 ISP_SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
6089 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
6090 ISP_SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
6092 if (sp->req_status_flags & RQSTF_BUS_RESET) {
6093 ISP_SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
6095 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
6096 ISP_SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
6098 if (sp->req_status_flags & RQSTF_ABORTED) {
6099 ISP_SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
6101 if (sp->req_status_flags & RQSTF_TIMEOUT) {
6102 ISP_SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
6104 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
6105 ISP_SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
6107 isp_xs_prt(isp, xs, ISP_LOGERR, "Transport Error: %s", buf);
6108 *rp = XS_XFRLEN(xs);
6111 case RQCS_RESET_OCCURRED:
6114 isp_xs_prt(isp, xs, ISP_LOGWARN, "Bus Reset destroyed command");
6115 for (chan = 0; chan < isp->isp_nchan; chan++) {
6116 FCPARAM(isp, chan)->sendmarker = 1;
6119 XS_SETERR(xs, HBA_BUSRESET);
6121 *rp = XS_XFRLEN(xs);
6125 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Aborted");
6126 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 1);
6128 XS_SETERR(xs, HBA_ABORTED);
6133 isp_xs_prt(isp, xs, ISP_LOGWARN, "Command timed out");
6135 * XXX: Check to see if we logged out of the device.
6138 XS_SETERR(xs, HBA_CMDTIMEOUT);
6142 case RQCS_DATA_OVERRUN:
6143 XS_SET_RESID(xs, sp->req_resid);
6144 isp_xs_prt(isp, xs, ISP_LOGERR, "data overrun (%ld)", (long) XS_GET_RESID(xs));
6146 XS_SETERR(xs, HBA_DATAOVR);
6150 case RQCS_COMMAND_OVERRUN:
6151 isp_xs_prt(isp, xs, ISP_LOGERR, "command overrun");
6154 case RQCS_STATUS_OVERRUN:
6155 isp_xs_prt(isp, xs, ISP_LOGERR, "status overrun");
6158 case RQCS_BAD_MESSAGE:
6159 isp_xs_prt(isp, xs, ISP_LOGERR, "msg not COMMAND COMPLETE after status");
6162 case RQCS_NO_MESSAGE_OUT:
6163 isp_xs_prt(isp, xs, ISP_LOGERR, "No MESSAGE OUT phase after selection");
6166 case RQCS_EXT_ID_FAILED:
6167 isp_xs_prt(isp, xs, ISP_LOGERR, "EXTENDED IDENTIFY failed");
6170 case RQCS_IDE_MSG_FAILED:
6171 isp_xs_prt(isp, xs, ISP_LOGERR, "INITIATOR DETECTED ERROR rejected");
6174 case RQCS_ABORT_MSG_FAILED:
6175 isp_xs_prt(isp, xs, ISP_LOGERR, "ABORT OPERATION rejected");
6178 case RQCS_REJECT_MSG_FAILED:
6179 isp_xs_prt(isp, xs, ISP_LOGERR, "MESSAGE REJECT rejected");
6182 case RQCS_NOP_MSG_FAILED:
6183 isp_xs_prt(isp, xs, ISP_LOGERR, "NOP rejected");
6186 case RQCS_PARITY_ERROR_MSG_FAILED:
6187 isp_xs_prt(isp, xs, ISP_LOGERR, "MESSAGE PARITY ERROR rejected");
6190 case RQCS_DEVICE_RESET_MSG_FAILED:
6191 isp_xs_prt(isp, xs, ISP_LOGWARN, "BUS DEVICE RESET rejected");
6194 case RQCS_ID_MSG_FAILED:
6195 isp_xs_prt(isp, xs, ISP_LOGERR, "IDENTIFY rejected");
6198 case RQCS_UNEXP_BUS_FREE:
6199 isp_xs_prt(isp, xs, ISP_LOGERR, "Unexpected Bus Free");
6202 case RQCS_DATA_UNDERRUN:
6205 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
6206 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
6207 isp_xs_prt(isp, xs, ISP_LOGWARN, bun, XS_XFRLEN(xs), sp->req_resid, (ru_marked)? "marked" : "not marked");
6209 XS_SETERR(xs, HBA_BOTCH);
6214 XS_SET_RESID(xs, sp->req_resid);
6216 XS_SETERR(xs, HBA_NOERROR);
6221 case RQCS_XACT_ERR1:
6222 isp_xs_prt(isp, xs, ISP_LOGERR, "HBA attempted queued transaction with disconnect not set");
6225 case RQCS_XACT_ERR2:
6226 isp_xs_prt(isp, xs, ISP_LOGERR,
6227 "HBA attempted queued transaction to target routine %jx",
6228 (uintmax_t)XS_LUN(xs));
6231 case RQCS_XACT_ERR3:
6232 isp_xs_prt(isp, xs, ISP_LOGERR, "HBA attempted queued cmd when queueing disabled");
6235 case RQCS_BAD_ENTRY:
6236 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
6239 case RQCS_QUEUE_FULL:
6240 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "internal queues full status 0x%x", *XS_STSP(xs));
6243 * If QFULL or some other status byte is set, then this
6244 * isn't an error, per se.
6246 * Unfortunately, some QLogic f/w writers have, in
6247 * some cases, omitted to *set* status to QFULL.
6250 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
6251 XS_SETERR(xs, HBA_NOERROR);
6256 *XS_STSP(xs) = SCSI_QFULL;
6257 XS_SETERR(xs, HBA_NOERROR);
6260 case RQCS_PHASE_SKIPPED:
6261 isp_xs_prt(isp, xs, ISP_LOGERR, "SCSI phase skipped");
6264 case RQCS_ARQS_FAILED:
6265 isp_xs_prt(isp, xs, ISP_LOGERR, "Auto Request Sense Failed");
6267 XS_SETERR(xs, HBA_ARQFAIL);
6271 case RQCS_WIDE_FAILED:
6272 isp_xs_prt(isp, xs, ISP_LOGERR, "Wide Negotiation Failed");
6274 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
6275 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
6276 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
6280 XS_SETERR(xs, HBA_NOERROR);
6284 case RQCS_SYNCXFER_FAILED:
6285 isp_xs_prt(isp, xs, ISP_LOGERR, "SDTR Message Failed");
6287 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
6288 sdp += XS_CHANNEL(xs);
6289 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
6290 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
6295 case RQCS_LVD_BUSERR:
6296 isp_xs_prt(isp, xs, ISP_LOGERR, "Bad LVD condition");
6299 case RQCS_PORT_UNAVAILABLE:
6301 * No such port on the loop. Moral equivalent of SELTIMEO
6303 case RQCS_PORT_LOGGED_OUT:
6306 uint8_t sts = sp->req_completion_status & 0xff;
6307 fcparam *fcp = FCPARAM(isp, 0);
6311 * It was there (maybe)- treat as a selection timeout.
6313 if (sts == RQCS_PORT_UNAVAILABLE) {
6314 reason = "unavailable";
6319 isp_prt(isp, ISP_LOGINFO, "port %s for target %d", reason, XS_TGT(xs));
6321 /* XXX: Should we trigger rescan or FW announce change? */
6324 lp = &fcp->portdb[XS_TGT(xs)];
6325 if (lp->state == FC_PORTDB_STATE_ZOMBIE) {
6326 *XS_STSP(xs) = SCSI_BUSY;
6327 XS_SETERR(xs, HBA_TGTBSY);
6329 XS_SETERR(xs, HBA_SELTIMEOUT);
6333 case RQCS_PORT_CHANGED:
6334 isp_prt(isp, ISP_LOGWARN, "port changed for target %d", XS_TGT(xs));
6336 *XS_STSP(xs) = SCSI_BUSY;
6337 XS_SETERR(xs, HBA_TGTBSY);
6341 case RQCS_PORT_BUSY:
6342 isp_prt(isp, ISP_LOGWARN, "port busy for target %d", XS_TGT(xs));
6344 *XS_STSP(xs) = SCSI_BUSY;
6345 XS_SETERR(xs, HBA_TGTBSY);
6350 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x", sp->req_completion_status);
6354 XS_SETERR(xs, HBA_BOTCH);
6359 isp_parse_status_24xx(ispsoftc_t *isp, isp24xx_statusreq_t *sp, XS_T *xs, uint32_t *rp)
6361 int ru_marked, sv_marked;
6362 int chan = XS_CHANNEL(xs);
6364 switch (sp->req_completion_status) {
6367 XS_SETERR(xs, HBA_NOERROR);
6371 case RQCS_DMA_ERROR:
6372 isp_xs_prt(isp, xs, ISP_LOGERR, "DMA error");
6375 case RQCS_TRANSPORT_ERROR:
6376 isp_xs_prt(isp, xs, ISP_LOGERR, "Transport Error");
6379 case RQCS_RESET_OCCURRED:
6380 isp_xs_prt(isp, xs, ISP_LOGWARN, "reset destroyed command");
6381 FCPARAM(isp, chan)->sendmarker = 1;
6383 XS_SETERR(xs, HBA_BUSRESET);
6388 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Aborted");
6389 FCPARAM(isp, chan)->sendmarker = 1;
6391 XS_SETERR(xs, HBA_ABORTED);
6396 isp_xs_prt(isp, xs, ISP_LOGWARN, "Command Timed Out");
6398 XS_SETERR(xs, HBA_CMDTIMEOUT);
6402 case RQCS_DATA_OVERRUN:
6403 XS_SET_RESID(xs, sp->req_resid);
6404 isp_xs_prt(isp, xs, ISP_LOGERR, "Data Overrun");
6406 XS_SETERR(xs, HBA_DATAOVR);
6410 case RQCS_24XX_DRE: /* data reassembly error */
6411 isp_prt(isp, ISP_LOGERR, "Chan %d data reassembly error for target %d", chan, XS_TGT(xs));
6413 XS_SETERR(xs, HBA_ABORTED);
6415 *rp = XS_XFRLEN(xs);
6418 case RQCS_24XX_TABORT: /* aborted by target */
6419 isp_prt(isp, ISP_LOGERR, "Chan %d target %d sent ABTS", chan, XS_TGT(xs));
6421 XS_SETERR(xs, HBA_ABORTED);
6425 case RQCS_DATA_UNDERRUN:
6426 ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
6428 * We can get an underrun w/o things being marked
6429 * if we got a non-zero status.
6431 sv_marked = (sp->req_scsi_status & (RQCS_SV|RQCS_RV)) != 0;
6432 if ((ru_marked == 0 && sv_marked == 0) ||
6433 (sp->req_resid > XS_XFRLEN(xs))) {
6434 isp_xs_prt(isp, xs, ISP_LOGWARN, bun, XS_XFRLEN(xs), sp->req_resid, (ru_marked)? "marked" : "not marked");
6436 XS_SETERR(xs, HBA_BOTCH);
6440 XS_SET_RESID(xs, sp->req_resid);
6441 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "Data Underrun (%d) for command 0x%x", sp->req_resid, XS_CDBP(xs)[0] & 0xff);
6443 XS_SETERR(xs, HBA_NOERROR);
6447 case RQCS_PORT_UNAVAILABLE:
6449 * No such port on the loop. Moral equivalent of SELTIMEO
6451 case RQCS_PORT_LOGGED_OUT:
6454 uint8_t sts = sp->req_completion_status & 0xff;
6455 fcparam *fcp = FCPARAM(isp, XS_CHANNEL(xs));
6459 * It was there (maybe)- treat as a selection timeout.
6461 if (sts == RQCS_PORT_UNAVAILABLE) {
6462 reason = "unavailable";
6467 isp_prt(isp, ISP_LOGINFO, "Chan %d port %s for target %d",
6468 chan, reason, XS_TGT(xs));
6470 /* XXX: Should we trigger rescan or FW announce change? */
6473 lp = &fcp->portdb[XS_TGT(xs)];
6474 if (lp->state == FC_PORTDB_STATE_ZOMBIE) {
6475 *XS_STSP(xs) = SCSI_BUSY;
6476 XS_SETERR(xs, HBA_TGTBSY);
6478 XS_SETERR(xs, HBA_SELTIMEOUT);
6482 case RQCS_PORT_CHANGED:
6483 isp_prt(isp, ISP_LOGWARN, "port changed for target %d chan %d", XS_TGT(xs), chan);
6485 *XS_STSP(xs) = SCSI_BUSY;
6486 XS_SETERR(xs, HBA_TGTBSY);
6490 case RQCS_24XX_ENOMEM: /* f/w resource unavailable */
6491 isp_prt(isp, ISP_LOGWARN, "f/w resource unavailable for target %d chan %d", XS_TGT(xs), chan);
6493 *XS_STSP(xs) = SCSI_BUSY;
6494 XS_SETERR(xs, HBA_TGTBSY);
6498 case RQCS_24XX_TMO: /* task management overrun */
6499 isp_prt(isp, ISP_LOGWARN, "command for target %d overlapped task management for chan %d", XS_TGT(xs), chan);
6501 *XS_STSP(xs) = SCSI_BUSY;
6502 XS_SETERR(xs, HBA_TGTBSY);
6507 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x on chan %d", sp->req_completion_status, chan);
6511 XS_SETERR(xs, HBA_BOTCH);
6516 isp_fastpost_complete(ispsoftc_t *isp, uint32_t fph)
6523 xs = isp_find_xs(isp, fph);
6525 isp_prt(isp, ISP_LOGWARN,
6526 "Command for fast post handle 0x%x not found", fph);
6529 isp_destroy_handle(isp, fph);
6532 * Since we don't have a result queue entry item,
6533 * we must believe that SCSI status is zero and
6534 * that all data transferred.
6536 XS_SET_RESID(xs, 0);
6537 *XS_STSP(xs) = SCSI_GOOD;
6538 if (XS_XFRLEN(xs)) {
6539 ISP_DMAFREE(isp, xs, fph);
6544 #define ISP_SCSI_IBITS(op) (mbpscsi[((op)<<1)])
6545 #define ISP_SCSI_OBITS(op) (mbpscsi[((op)<<1) + 1])
6546 #define ISP_SCSI_OPMAP(in, out) in, out
6547 static const uint8_t mbpscsi[] = {
6548 ISP_SCSI_OPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
6549 ISP_SCSI_OPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
6550 ISP_SCSI_OPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
6551 ISP_SCSI_OPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
6552 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
6553 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
6554 ISP_SCSI_OPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
6555 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
6556 ISP_SCSI_OPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
6557 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x09: */
6558 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0a: */
6559 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0b: */
6560 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0c: */
6561 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0d: */
6562 ISP_SCSI_OPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
6563 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0f: */
6564 ISP_SCSI_OPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
6565 ISP_SCSI_OPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
6566 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
6567 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
6568 ISP_SCSI_OPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
6569 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
6570 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
6571 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
6572 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
6573 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
6574 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
6575 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
6576 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
6577 ISP_SCSI_OPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
6578 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x1e: */
6579 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
6580 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
6581 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
6582 ISP_SCSI_OPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
6583 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
6584 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
6585 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
6586 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
6587 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
6588 ISP_SCSI_OPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
6589 ISP_SCSI_OPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
6590 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
6591 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2b: */
6592 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2c: */
6593 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2d: */
6594 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2e: */
6595 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2f: */
6596 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
6597 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
6598 ISP_SCSI_OPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
6599 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
6600 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
6601 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
6602 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
6603 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
6604 ISP_SCSI_OPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
6605 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
6606 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
6607 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3b: */
6608 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3c: */
6609 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3d: */
6610 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3e: */
6611 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3f: */
6612 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
6613 ISP_SCSI_OPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
6614 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
6615 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x43: */
6616 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x44: */
6617 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
6618 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
6619 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x47: */
6620 ISP_SCSI_OPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
6621 ISP_SCSI_OPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
6622 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
6623 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
6624 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4c: */
6625 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4d: */
6626 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4e: */
6627 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4f: */
6628 ISP_SCSI_OPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
6629 ISP_SCSI_OPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
6630 ISP_SCSI_OPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
6631 ISP_SCSI_OPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
6632 ISP_SCSI_OPMAP(0xcf, 0x01), /* 0x54: EXECUCUTE COMMAND IOCB A64 */
6633 ISP_SCSI_OPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
6634 ISP_SCSI_OPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
6635 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x57: */
6636 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x58: */
6637 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x59: */
6638 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
6639 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
6640 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
6641 ISP_SCSI_OPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
6643 #define MAX_SCSI_OPCODE 0x5d
6645 static const char *scsi_mbcmd_names[] = {
6662 "INIT REQUEST QUEUE",
6663 "INIT RESULT QUEUE",
6673 "SINGLE STEP QUEUE",
6675 "GET DEV QUEUE STATUS",
6677 "GET FIRMWARE STATUS",
6679 "GET SELECT TIMEOUT",
6681 "GET TAG AGE LIMIT",
6683 "GET ACT NEG STATE",
6684 "GET ASYNC DATA SETUP TIME",
6686 "GET TARGET PARAMS",
6687 "GET DEV QUEUE PARAMS",
6688 "GET RESET DELAY PARAMS",
6695 "SET SELECT TIMEOUT",
6697 "SET TAG AGE LIMIT",
6699 "SET ACT NEG STATE",
6700 "SET ASYNC DATA SETUP TIME",
6701 "SET PCI CONTROL PARAMS",
6702 "SET TARGET PARAMS",
6703 "SET DEV QUEUE PARAMS",
6704 "SET RESET DELAY PARAMS",
6710 "RETURN BIOS BLOCK ADDR",
6711 "WRITE FOUR RAM WORDS",
6715 "SET SYSTEM PARAMETER",
6716 "GET SYSTEM PARAMETER",
6718 "GET SCAM CONFIGURATION",
6719 "SET SCAM CONFIGURATION",
6720 "SET FIRMWARE FEATURES",
6721 "GET FIRMWARE FEATURES",
6728 "INITIALIZE REQUEST QUEUE A64",
6729 "INITIALIZE RESPONSE QUEUE A64",
6731 "ENABLE TARGET MODE",
6732 "GET TARGET MODE STATE",
6736 "SET DATA OVERRUN RECOVERY MODE",
6737 "GET DATA OVERRUN RECOVERY MODE",
6742 #define ISP_FC_IBITS(op) ((mbpfc[((op)<<3) + 0] << 24) | (mbpfc[((op)<<3) + 1] << 16) | (mbpfc[((op)<<3) + 2] << 8) | (mbpfc[((op)<<3) + 3]))
6743 #define ISP_FC_OBITS(op) ((mbpfc[((op)<<3) + 4] << 24) | (mbpfc[((op)<<3) + 5] << 16) | (mbpfc[((op)<<3) + 6] << 8) | (mbpfc[((op)<<3) + 7]))
6745 #define ISP_FC_OPMAP(in0, out0) 0, 0, 0, in0, 0, 0, 0, out0
6746 #define ISP_FC_OPMAP_HALF(in1, in0, out1, out0) 0, 0, in1, in0, 0, 0, out1, out0
6747 #define ISP_FC_OPMAP_FULL(in3, in2, in1, in0, out3, out2, out1, out0) in3, in2, in1, in0, out3, out2, out1, out0
6748 static const uint32_t mbpfc[] = {
6749 ISP_FC_OPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
6750 ISP_FC_OPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
6751 ISP_FC_OPMAP_HALF(0x07, 0xff, 0x00, 0x1f), /* 0x02: MBOX_EXEC_FIRMWARE */
6752 ISP_FC_OPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
6753 ISP_FC_OPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
6754 ISP_FC_OPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
6755 ISP_FC_OPMAP_FULL(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
6756 ISP_FC_OPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
6757 ISP_FC_OPMAP_FULL(0x0, 0x0, 0x0, 0x01, 0x0, 0x3, 0x80, 0x7f), /* 0x08: MBOX_ABOUT_FIRMWARE */
6758 ISP_FC_OPMAP(0xdf, 0x01), /* 0x09: MBOX_LOAD_RISC_RAM_2100 */
6759 ISP_FC_OPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
6760 ISP_FC_OPMAP_HALF(0x1, 0xff, 0x0, 0x01), /* 0x0b: MBOX_LOAD_RISC_RAM */
6761 ISP_FC_OPMAP(0x00, 0x00), /* 0x0c: */
6762 ISP_FC_OPMAP_HALF(0x1, 0x0f, 0x0, 0x01), /* 0x0d: MBOX_WRITE_RAM_WORD_EXTENDED */
6763 ISP_FC_OPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
6764 ISP_FC_OPMAP_HALF(0x1, 0x03, 0x0, 0x0d), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED */
6765 ISP_FC_OPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
6766 ISP_FC_OPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
6767 ISP_FC_OPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
6768 ISP_FC_OPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
6769 ISP_FC_OPMAP_HALF(0x1, 0xff, 0x0, 0x03), /* 0x14: MBOX_STOP_FIRMWARE */
6770 ISP_FC_OPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
6771 ISP_FC_OPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
6772 ISP_FC_OPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
6773 ISP_FC_OPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
6774 ISP_FC_OPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
6775 ISP_FC_OPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
6776 ISP_FC_OPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
6777 ISP_FC_OPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
6778 ISP_FC_OPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
6779 ISP_FC_OPMAP(0x00, 0x00), /* 0x1e: */
6780 ISP_FC_OPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
6781 ISP_FC_OPMAP_HALF(0x2, 0x01, 0x7e, 0xcf), /* 0x20: MBOX_GET_LOOP_ID */
6782 ISP_FC_OPMAP(0x00, 0x00), /* 0x21: */
6783 ISP_FC_OPMAP(0x03, 0x4b), /* 0x22: MBOX_GET_TIMEOUT_PARAMS */
6784 ISP_FC_OPMAP(0x00, 0x00), /* 0x23: */
6785 ISP_FC_OPMAP(0x00, 0x00), /* 0x24: */
6786 ISP_FC_OPMAP(0x00, 0x00), /* 0x25: */
6787 ISP_FC_OPMAP(0x00, 0x00), /* 0x26: */
6788 ISP_FC_OPMAP(0x00, 0x00), /* 0x27: */
6789 ISP_FC_OPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
6790 ISP_FC_OPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
6791 ISP_FC_OPMAP(0x00, 0x00), /* 0x2a: */
6792 ISP_FC_OPMAP(0x00, 0x00), /* 0x2b: */
6793 ISP_FC_OPMAP(0x00, 0x00), /* 0x2c: */
6794 ISP_FC_OPMAP(0x00, 0x00), /* 0x2d: */
6795 ISP_FC_OPMAP(0x00, 0x00), /* 0x2e: */
6796 ISP_FC_OPMAP(0x00, 0x00), /* 0x2f: */
6797 ISP_FC_OPMAP(0x00, 0x00), /* 0x30: */
6798 ISP_FC_OPMAP(0x00, 0x00), /* 0x31: */
6799 ISP_FC_OPMAP(0x4b, 0x4b), /* 0x32: MBOX_SET_TIMEOUT_PARAMS */
6800 ISP_FC_OPMAP(0x00, 0x00), /* 0x33: */
6801 ISP_FC_OPMAP(0x00, 0x00), /* 0x34: */
6802 ISP_FC_OPMAP(0x00, 0x00), /* 0x35: */
6803 ISP_FC_OPMAP(0x00, 0x00), /* 0x36: */
6804 ISP_FC_OPMAP(0x00, 0x00), /* 0x37: */
6805 ISP_FC_OPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
6806 ISP_FC_OPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
6807 ISP_FC_OPMAP(0x00, 0x00), /* 0x3a: */
6808 ISP_FC_OPMAP(0x00, 0x00), /* 0x3b: */
6809 ISP_FC_OPMAP(0x00, 0x00), /* 0x3c: */
6810 ISP_FC_OPMAP(0x00, 0x00), /* 0x3d: */
6811 ISP_FC_OPMAP(0x00, 0x00), /* 0x3e: */
6812 ISP_FC_OPMAP(0x00, 0x00), /* 0x3f: */
6813 ISP_FC_OPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
6814 ISP_FC_OPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
6815 ISP_FC_OPMAP_HALF(0x0, 0x01, 0x1f, 0xcf), /* 0x42: MBOX_GET_RESOURCE_COUNT */
6816 ISP_FC_OPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_OFFLINE_MODE */
6817 ISP_FC_OPMAP(0x00, 0x00), /* 0x44: */
6818 ISP_FC_OPMAP(0x00, 0x00), /* 0x45: */
6819 ISP_FC_OPMAP(0x00, 0x00), /* 0x46: */
6820 ISP_FC_OPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
6821 ISP_FC_OPMAP(0xcf, 0x0f), /* 0x48: MBOX_INIT_FIRMWARE_MULTI_ID */
6822 ISP_FC_OPMAP(0xcd, 0x01), /* 0x49: MBOX_GET_VP_DATABASE */
6823 ISP_FC_OPMAP_HALF(0x2, 0xcd, 0x0, 0x01), /* 0x4a: MBOX_GET_VP_DATABASE_ENTRY */
6824 ISP_FC_OPMAP(0x00, 0x00), /* 0x4b: */
6825 ISP_FC_OPMAP(0x00, 0x00), /* 0x4c: */
6826 ISP_FC_OPMAP(0x00, 0x00), /* 0x4d: */
6827 ISP_FC_OPMAP(0x00, 0x00), /* 0x4e: */
6828 ISP_FC_OPMAP(0x00, 0x00), /* 0x4f: */
6829 ISP_FC_OPMAP(0x00, 0x00), /* 0x50: */
6830 ISP_FC_OPMAP(0x00, 0x00), /* 0x51: */
6831 ISP_FC_OPMAP(0x00, 0x00), /* 0x52: */
6832 ISP_FC_OPMAP(0x00, 0x00), /* 0x53: */
6833 ISP_FC_OPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
6834 ISP_FC_OPMAP(0x00, 0x00), /* 0x55: */
6835 ISP_FC_OPMAP(0x00, 0x00), /* 0x56: */
6836 ISP_FC_OPMAP(0x00, 0x00), /* 0x57: */
6837 ISP_FC_OPMAP(0x00, 0x00), /* 0x58: */
6838 ISP_FC_OPMAP(0x00, 0x00), /* 0x59: */
6839 ISP_FC_OPMAP(0x00, 0x00), /* 0x5a: */
6840 ISP_FC_OPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
6841 ISP_FC_OPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
6842 ISP_FC_OPMAP(0x07, 0x1f), /* 0x5d: MBOX_GET_SET_DATA_RATE */
6843 ISP_FC_OPMAP(0x00, 0x00), /* 0x5e: */
6844 ISP_FC_OPMAP(0x00, 0x00), /* 0x5f: */
6845 ISP_FC_OPMAP(0xcf, 0x0f), /* 0x60: MBOX_INIT_FIRMWARE */
6846 ISP_FC_OPMAP(0x00, 0x00), /* 0x61: */
6847 ISP_FC_OPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
6848 ISP_FC_OPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
6849 ISP_FC_OPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
6850 ISP_FC_OPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
6851 ISP_FC_OPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
6852 ISP_FC_OPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
6853 ISP_FC_OPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
6854 ISP_FC_OPMAP_HALF(0x00, 0x01, 0x0f, 0x1f), /* 0x69: MBOX_GET_FW_STATE */
6855 ISP_FC_OPMAP_HALF(0x6, 0x03, 0x0, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
6856 ISP_FC_OPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
6857 ISP_FC_OPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
6858 ISP_FC_OPMAP(0x00, 0x00), /* 0x6d: */
6859 ISP_FC_OPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
6860 ISP_FC_OPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
6861 ISP_FC_OPMAP_HALF(0x02, 0x03, 0x00, 0x03), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
6862 ISP_FC_OPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
6863 ISP_FC_OPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
6864 ISP_FC_OPMAP(0x00, 0x00), /* 0x73: */
6865 ISP_FC_OPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
6866 ISP_FC_OPMAP_HALF(0x03, 0xcf, 0x00, 0x07), /* 0x75: GET PORT/NODE NAME LIST */
6867 ISP_FC_OPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
6868 ISP_FC_OPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
6869 ISP_FC_OPMAP(0x00, 0x00), /* 0x78: */
6870 ISP_FC_OPMAP(0x00, 0x00), /* 0x79: */
6871 ISP_FC_OPMAP(0x00, 0x00), /* 0x7a: */
6872 ISP_FC_OPMAP(0x00, 0x00), /* 0x7b: */
6873 ISP_FC_OPMAP_HALF(0x03, 0x4f, 0x00, 0x07), /* 0x7c: Get ID List */
6874 ISP_FC_OPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
6875 ISP_FC_OPMAP(0x0f, 0x01) /* 0x7e: LUN RESET */
6877 #define MAX_FC_OPCODE 0x7e
6881 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
6882 * do not access at this time in the core driver. The caller is
6883 * responsible for setting this register first (Gross!). The assumption
6884 * is that we won't overflow.
6887 static const char *fc_mbcmd_names[] = {
6901 "WRITE RAM WORD EXTENDED",
6903 "READ RAM WORD EXTENDED",
6904 "INIT REQUEST QUEUE", /* 10h */
6905 "INIT RESULT QUEUE",
6915 "SINGLE STEP QUEUE",
6917 "GET DEV QUEUE STATUS",
6919 "GET FIRMWARE STATUS",
6920 "GET LOOP ID", /* 20h */
6922 "GET TIMEOUT PARAMS",
6928 "GET FIRMWARE OPTIONS",
6929 "GET PORT QUEUE PARAMS",
6930 "GENERATE SYSTEM ERROR",
6936 "WRITE SFP", /* 30h */
6938 "SET TIMEOUT PARAMS",
6944 "SET FIRMWARE OPTIONS",
6945 "SET PORT QUEUE PARAMS",
6949 "RESTART NIC FIRMWARE",
6952 "LOOP PORT BYPASS", /* 40h */
6954 "GET RESOURCE COUNT",
6955 "REQUEST NON PARTICIPATING MODE",
6956 "DIAGNOSTIC ECHO TEST",
6957 "DIAGNOSTIC LOOPBACK",
6959 "GET PORT DATABASE ENHANCED",
6960 "INIT FIRMWARE MULTI ID",
6962 "GET VP DATABASE ENTRY",
6968 "GET FCF LIST", /* 50h */
6969 "GET DCBX PARAMETERS",
6980 "FIRMWARE HEARTBEAT",
6981 "GET/SET DATA RATE",
6984 "INIT FIRMWARE", /* 60h */
6985 "GET INIT CONTROL BLOCK",
6987 "GET FC-AL POSITION MAP",
6988 "GET PORT DATABASE",
6997 "GET LINK STATS & PRIVATE DATA CNTS",
7000 "SEND CHANGE REQUEST", /* 70h */
7005 "GET PORT/NODE NAME LIST",
7007 "INITIALIZE IP MAILBOX",
7018 isp_mboxcmd(ispsoftc_t *isp, mbreg_t *mbp)
7020 const char *cname, *xname, *sname;
7021 char tname[16], mname[16];
7022 unsigned int ibits, obits, box, opcode;
7024 opcode = mbp->param[0];
7026 if (opcode > MAX_FC_OPCODE) {
7027 mbp->param[0] = MBOX_INVALID_COMMAND;
7028 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
7031 cname = fc_mbcmd_names[opcode];
7032 ibits = ISP_FC_IBITS(opcode);
7033 obits = ISP_FC_OBITS(opcode);
7035 if (opcode > MAX_SCSI_OPCODE) {
7036 mbp->param[0] = MBOX_INVALID_COMMAND;
7037 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
7040 cname = scsi_mbcmd_names[opcode];
7041 ibits = ISP_SCSI_IBITS(opcode);
7042 obits = ISP_SCSI_OBITS(opcode);
7044 if (cname == NULL) {
7046 ISP_SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
7048 isp_prt(isp, ISP_LOGDEBUG3, "Mailbox Command '%s'", cname);
7051 * Pick up any additional bits that the caller might have set.
7053 ibits |= mbp->ibits;
7054 obits |= mbp->obits;
7057 * Mask any bits that the caller wants us to mask
7059 ibits &= mbp->ibitm;
7060 obits &= mbp->obitm;
7063 if (ibits == 0 && obits == 0) {
7064 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
7065 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
7070 * Get exclusive usage of mailbox registers.
7072 if (MBOX_ACQUIRE(isp)) {
7073 mbp->param[0] = MBOX_REGS_BUSY;
7077 for (box = 0; box < ISP_NMBOX(isp); box++) {
7078 if (ibits & (1 << box)) {
7079 isp_prt(isp, ISP_LOGDEBUG3, "IN mbox %d = 0x%04x", box,
7081 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
7083 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
7086 isp->isp_lastmbxcmd = opcode;
7089 * We assume that we can't overwrite a previous command.
7091 isp->isp_obits = obits;
7092 isp->isp_mboxbsy = 1;
7095 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
7098 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_SET_HOST_INT);
7100 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
7104 * While we haven't finished the command, spin our wheels here.
7106 MBOX_WAIT_COMPLETE(isp, mbp);
7109 * Did the command time out?
7111 if (mbp->param[0] == MBOX_TIMEOUT) {
7112 isp->isp_mboxbsy = 0;
7118 * Copy back output registers.
7120 for (box = 0; box < ISP_NMBOX(isp); box++) {
7121 if (obits & (1 << box)) {
7122 mbp->param[box] = isp->isp_mboxtmp[box];
7123 isp_prt(isp, ISP_LOGDEBUG3, "OUT mbox %d = 0x%04x", box,
7128 isp->isp_mboxbsy = 0;
7131 if (mbp->logval == 0 || mbp->param[0] == MBOX_COMMAND_COMPLETE)
7134 if ((mbp->param[0] & 0xbfe0) == 0 &&
7135 (mbp->logval & MBLOGMASK(mbp->param[0])) == 0)
7140 switch (mbp->param[0]) {
7141 case MBOX_INVALID_COMMAND:
7142 xname = "INVALID COMMAND";
7144 case MBOX_HOST_INTERFACE_ERROR:
7145 xname = "HOST INTERFACE ERROR";
7147 case MBOX_TEST_FAILED:
7148 xname = "TEST FAILED";
7150 case MBOX_COMMAND_ERROR:
7151 xname = "COMMAND ERROR";
7152 ISP_SNPRINTF(mname, sizeof(mname), " subcode 0x%x",
7156 case MBOX_COMMAND_PARAM_ERROR:
7157 xname = "COMMAND PARAMETER ERROR";
7159 case MBOX_PORT_ID_USED:
7160 xname = "PORT ID ALREADY IN USE";
7162 case MBOX_LOOP_ID_USED:
7163 xname = "LOOP ID ALREADY IN USE";
7165 case MBOX_ALL_IDS_USED:
7166 xname = "ALL LOOP IDS IN USE";
7168 case MBOX_NOT_LOGGED_IN:
7169 xname = "NOT LOGGED IN";
7171 case MBOX_LINK_DOWN_ERROR:
7172 xname = "LINK DOWN ERROR";
7174 case MBOX_LOOPBACK_ERROR:
7175 xname = "LOOPBACK ERROR";
7177 case MBOX_CHECKSUM_ERROR:
7178 xname = "CHECKSUM ERROR";
7180 case MBOX_INVALID_PRODUCT_KEY:
7181 xname = "INVALID PRODUCT KEY";
7183 case MBOX_REGS_BUSY:
7184 xname = "REGISTERS BUSY";
7190 ISP_SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
7195 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s%s)",
7196 cname, xname, sname);
7201 isp_fw_state(ispsoftc_t *isp, int chan)
7206 MBSINIT(&mbs, MBOX_GET_FW_STATE, MBLOGALL, 0);
7207 isp_mboxcmd(isp, &mbs);
7208 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
7209 return (mbs.param[1]);
7216 isp_spi_update(ispsoftc_t *isp, int chan)
7224 * There are no 'per-bus' settings for Fibre Channel.
7228 sdp = SDPARAM(isp, chan);
7231 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7232 uint16_t flags, period, offset;
7235 if (sdp->isp_devparam[tgt].dev_enable == 0) {
7236 sdp->isp_devparam[tgt].dev_update = 0;
7237 sdp->isp_devparam[tgt].dev_refresh = 0;
7238 isp_prt(isp, ISP_LOGDEBUG0, "skipping target %d bus %d update", tgt, chan);
7242 * If the goal is to update the status of the device,
7243 * take what's in goal_flags and try and set the device
7244 * toward that. Otherwise, if we're just refreshing the
7245 * current device state, get the current parameters.
7248 MBSINIT(&mbs, 0, MBLOGALL, 0);
7251 * Refresh overrides set
7253 if (sdp->isp_devparam[tgt].dev_refresh) {
7254 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
7256 } else if (sdp->isp_devparam[tgt].dev_update) {
7257 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
7260 * Make sure goal_flags has "Renegotiate on Error"
7261 * on and "Freeze Queue on Error" off.
7263 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
7264 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
7265 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
7268 * Insist that PARITY must be enabled
7269 * if SYNC or WIDE is enabled.
7271 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
7272 mbs.param[2] |= DPARM_PARITY;
7275 if (mbs.param[2] & DPARM_SYNC) {
7277 (sdp->isp_devparam[tgt].goal_offset << 8) |
7278 (sdp->isp_devparam[tgt].goal_period);
7281 * A command completion later that has
7282 * RQSTF_NEGOTIATION set can cause
7283 * the dev_refresh/announce cycle also.
7285 * Note: It is really important to update our current
7286 * flags with at least the state of TAG capabilities-
7287 * otherwise we might try and send a tagged command
7288 * when we have it all turned off. So change it here
7289 * to say that current already matches goal.
7291 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
7292 sdp->isp_devparam[tgt].actv_flags |=
7293 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
7294 isp_prt(isp, ISP_LOGDEBUG0, "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
7295 chan, tgt, mbs.param[2], mbs.param[3] >> 8, mbs.param[3] & 0xff);
7300 mbs.param[1] = (chan << 15) | (tgt << 8);
7301 isp_mboxcmd(isp, &mbs);
7302 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7306 sdp->sendmarker = 1;
7307 sdp->isp_devparam[tgt].dev_update = 0;
7308 sdp->isp_devparam[tgt].dev_refresh = 1;
7310 sdp->isp_devparam[tgt].dev_refresh = 0;
7311 flags = mbs.param[2];
7312 period = mbs.param[3] & 0xff;
7313 offset = mbs.param[3] >> 8;
7314 sdp->isp_devparam[tgt].actv_flags = flags;
7315 sdp->isp_devparam[tgt].actv_period = period;
7316 sdp->isp_devparam[tgt].actv_offset = offset;
7317 isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, chan, tgt);
7321 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7322 if (sdp->isp_devparam[tgt].dev_update ||
7323 sdp->isp_devparam[tgt].dev_refresh) {
7331 isp_setdfltsdparm(ispsoftc_t *isp)
7334 sdparam *sdp, *sdp1;
7336 sdp = SDPARAM(isp, 0);
7337 if (IS_DUALBUS(isp))
7343 * Establish some default parameters.
7345 sdp->isp_cmd_dma_burst_enable = 0;
7346 sdp->isp_data_dma_burst_enabl = 1;
7347 sdp->isp_fifo_threshold = 0;
7348 sdp->isp_initiator_id = DEFAULT_IID(isp, 0);
7349 if (isp->isp_type >= ISP_HA_SCSI_1040) {
7350 sdp->isp_async_data_setup = 9;
7352 sdp->isp_async_data_setup = 6;
7354 sdp->isp_selection_timeout = 250;
7355 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
7356 sdp->isp_tag_aging = 8;
7357 sdp->isp_bus_reset_delay = 5;
7359 * Don't retry selection, busy or queue full automatically- reflect
7362 sdp->isp_retry_count = 0;
7363 sdp->isp_retry_delay = 0;
7365 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7366 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
7367 sdp->isp_devparam[tgt].dev_enable = 1;
7371 * The trick here is to establish a default for the default (honk!)
7372 * state (goal_flags). Then try and get the current status from
7373 * the card to fill in the current state. We don't, in fact, set
7374 * the default to the SAFE default state- that's not the goal state.
7376 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7378 sdp->isp_devparam[tgt].actv_offset = 0;
7379 sdp->isp_devparam[tgt].actv_period = 0;
7380 sdp->isp_devparam[tgt].actv_flags = 0;
7382 sdp->isp_devparam[tgt].goal_flags =
7383 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
7386 * We default to Wide/Fast for versions less than a 1040
7387 * (unless it's SBus).
7389 if (IS_ULTRA3(isp)) {
7390 off = ISP_80M_SYNCPARMS >> 8;
7391 per = ISP_80M_SYNCPARMS & 0xff;
7392 } else if (IS_ULTRA2(isp)) {
7393 off = ISP_40M_SYNCPARMS >> 8;
7394 per = ISP_40M_SYNCPARMS & 0xff;
7395 } else if (IS_1240(isp)) {
7396 off = ISP_20M_SYNCPARMS >> 8;
7397 per = ISP_20M_SYNCPARMS & 0xff;
7398 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
7399 isp->isp_type < ISP_HA_SCSI_1020A) ||
7400 (isp->isp_bustype == ISP_BT_PCI &&
7401 isp->isp_type < ISP_HA_SCSI_1040) ||
7402 (isp->isp_clock && isp->isp_clock < 60) ||
7403 (sdp->isp_ultramode == 0)) {
7404 off = ISP_10M_SYNCPARMS >> 8;
7405 per = ISP_10M_SYNCPARMS & 0xff;
7407 off = ISP_20M_SYNCPARMS_1040 >> 8;
7408 per = ISP_20M_SYNCPARMS_1040 & 0xff;
7410 sdp->isp_devparam[tgt].goal_offset =
7411 sdp->isp_devparam[tgt].nvrm_offset = off;
7412 sdp->isp_devparam[tgt].goal_period =
7413 sdp->isp_devparam[tgt].nvrm_period = per;
7418 * If we're a dual bus card, just copy the data over
7422 sdp1->isp_initiator_id = DEFAULT_IID(isp, 1);
7426 * If we've not been told to avoid reading NVRAM, try and read it.
7427 * If we're successful reading it, we can then return because NVRAM
7428 * will tell us what the desired settings are. Otherwise, we establish
7429 * some reasonable 'fake' nvram and goal defaults.
7431 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7434 if (isp_read_nvram(isp, 0) == 0) {
7435 if (IS_DUALBUS(isp)) {
7436 if (isp_read_nvram(isp, 1) == 0) {
7441 MBSINIT(&mbs, MBOX_GET_ACT_NEG_STATE, MBLOGNONE, 0);
7442 isp_mboxcmd(isp, &mbs);
7443 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7444 sdp->isp_req_ack_active_neg = 1;
7445 sdp->isp_data_line_active_neg = 1;
7447 sdp1->isp_req_ack_active_neg = 1;
7448 sdp1->isp_data_line_active_neg = 1;
7451 sdp->isp_req_ack_active_neg =
7452 (mbs.param[1] >> 4) & 0x1;
7453 sdp->isp_data_line_active_neg =
7454 (mbs.param[1] >> 5) & 0x1;
7456 sdp1->isp_req_ack_active_neg =
7457 (mbs.param[2] >> 4) & 0x1;
7458 sdp1->isp_data_line_active_neg =
7459 (mbs.param[2] >> 5) & 0x1;
7467 isp_setdfltfcparm(ispsoftc_t *isp, int chan)
7469 fcparam *fcp = FCPARAM(isp, chan);
7472 * Establish some default parameters.
7474 fcp->role = DEFAULT_ROLE(isp, chan);
7475 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
7476 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
7477 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
7478 fcp->isp_loopid = DEFAULT_LOOPID(isp, chan);
7479 fcp->isp_wwnn_nvram = DEFAULT_NODEWWN(isp, chan);
7480 fcp->isp_wwpn_nvram = DEFAULT_PORTWWN(isp, chan);
7481 fcp->isp_fwoptions = 0;
7482 fcp->isp_xfwoptions = 0;
7483 fcp->isp_zfwoptions = 0;
7484 fcp->isp_lasthdl = NIL_HANDLE;
7485 fcp->isp_login_hdl = NIL_HANDLE;
7488 fcp->isp_fwoptions |= ICB2400_OPT1_FAIRNESS;
7489 fcp->isp_fwoptions |= ICB2400_OPT1_HARD_ADDRESS;
7490 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
7491 fcp->isp_fwoptions |= ICB2400_OPT1_FULL_DUPLEX;
7492 fcp->isp_fwoptions |= ICB2400_OPT1_BOTH_WWNS;
7493 fcp->isp_xfwoptions |= ICB2400_OPT2_LOOP_2_PTP;
7494 fcp->isp_zfwoptions |= ICB2400_OPT3_RATE_AUTO;
7496 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
7497 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
7498 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
7499 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
7500 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
7502 * Make sure this is turned off now until we get
7503 * extended options from NVRAM
7505 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
7506 fcp->isp_xfwoptions |= ICBXOPT_LOOP_2_PTP;
7507 fcp->isp_zfwoptions |= ICBZOPT_RATE_AUTO;
7512 * Now try and read NVRAM unless told to not do so.
7513 * This will set fcparam's isp_wwnn_nvram && isp_wwpn_nvram.
7515 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7518 * Give a couple of tries at reading NVRAM.
7520 for (i = 0; i < 2; i++) {
7521 j = isp_read_nvram(isp, chan);
7527 isp->isp_confopts |= ISP_CFG_NONVRAM;
7531 fcp->isp_wwnn = ACTIVE_NODEWWN(isp, chan);
7532 fcp->isp_wwpn = ACTIVE_PORTWWN(isp, chan);
7533 isp_prt(isp, ISP_LOGCONFIG, "Chan %d 0x%08x%08x/0x%08x%08x Role %s",
7534 chan, (uint32_t) (fcp->isp_wwnn >> 32), (uint32_t) (fcp->isp_wwnn),
7535 (uint32_t) (fcp->isp_wwpn >> 32), (uint32_t) (fcp->isp_wwpn),
7536 isp_class3_roles[fcp->role]);
7540 * Re-initialize the ISP and complete all orphaned commands
7541 * with a 'botched' notice. The reset/init routines should
7542 * not disturb an already active list of commands.
7546 isp_reinit(ispsoftc_t *isp, int do_load_defaults)
7550 if (isp->isp_state > ISP_RESETSTATE)
7552 if (isp->isp_state != ISP_RESETSTATE)
7553 isp_reset(isp, do_load_defaults);
7554 if (isp->isp_state != ISP_RESETSTATE) {
7556 isp_prt(isp, ISP_LOGERR, "%s: cannot reset card", __func__);
7561 if (isp->isp_state > ISP_RESETSTATE &&
7562 isp->isp_state != ISP_RUNSTATE) {
7564 isp_prt(isp, ISP_LOGERR, "%s: cannot init card", __func__);
7565 ISP_DISABLE_INTS(isp);
7568 * If we're in ISP_ROLE_NONE, turn off the lasers.
7570 if (!IS_24XX(isp)) {
7571 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
7572 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
7573 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
7574 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
7575 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
7581 isp_clear_commands(isp);
7583 for (i = 0; i < isp->isp_nchan; i++)
7584 isp_clear_portdb(isp, i);
7593 isp_read_nvram(ispsoftc_t *isp, int bus)
7596 uint8_t csum, minversion;
7598 uint8_t _x[ISP2400_NVRAM_SIZE];
7599 uint16_t _s[ISP2400_NVRAM_SIZE>>1];
7601 #define nvram_data _n._x
7602 #define nvram_words _n._s
7605 return (isp_read_nvram_2400(isp, nvram_data));
7606 } else if (IS_FC(isp)) {
7607 amt = ISP2100_NVRAM_SIZE;
7609 } else if (IS_ULTRA2(isp)) {
7610 amt = ISP1080_NVRAM_SIZE;
7613 amt = ISP_NVRAM_SIZE;
7617 for (i = 0; i < amt>>1; i++) {
7618 isp_rdnvram_word(isp, i, &nvram_words[i]);
7621 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
7622 nvram_data[2] != 'P') {
7623 if (isp->isp_bustype != ISP_BT_SBUS) {
7624 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
7625 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x", nvram_data[0], nvram_data[1], nvram_data[2]);
7631 for (csum = 0, i = 0; i < amt; i++) {
7632 csum += nvram_data[i];
7635 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
7640 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
7641 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
7642 ISP_NVRAM_VERSION(nvram_data));
7647 if (IS_ULTRA3(isp)) {
7648 isp_parse_nvram_12160(isp, bus, nvram_data);
7649 } else if (IS_1080(isp)) {
7650 isp_parse_nvram_1080(isp, bus, nvram_data);
7651 } else if (IS_1280(isp) || IS_1240(isp)) {
7652 isp_parse_nvram_1080(isp, bus, nvram_data);
7653 } else if (IS_SCSI(isp)) {
7654 isp_parse_nvram_1020(isp, nvram_data);
7656 isp_parse_nvram_2100(isp, nvram_data);
7666 isp_read_nvram_2400(ispsoftc_t *isp, uint8_t *nvram_data)
7669 uint32_t addr, csum, lwrds, *dptr;
7671 if (isp->isp_port) {
7672 addr = ISP2400_NVRAM_PORT1_ADDR;
7674 addr = ISP2400_NVRAM_PORT0_ADDR;
7677 dptr = (uint32_t *) nvram_data;
7678 for (lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
7679 isp_rd_2400_nvram(isp, addr++, dptr++);
7681 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
7682 nvram_data[2] != 'P') {
7683 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header (%x %x %x)",
7684 nvram_data[0], nvram_data[1], nvram_data[2]);
7688 dptr = (uint32_t *) nvram_data;
7689 for (csum = 0, lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
7691 ISP_IOXGET_32(isp, &dptr[lwrds], tmp);
7695 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
7699 isp_parse_nvram_2400(isp, nvram_data);
7705 isp_rdnvram_word(ispsoftc_t *isp, int wo, uint16_t *rp)
7708 uint16_t bit, rqst, junk;
7710 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
7712 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
7716 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
7717 if (IS_2312(isp) && isp->isp_port) {
7720 rqst = (ISP_NVRAM_READ << 8) | wo;
7722 } else if (IS_ULTRA2(isp)) {
7723 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
7724 rqst = (ISP_NVRAM_READ << 8) | wo;
7727 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
7728 rqst = (ISP_NVRAM_READ << 6) | wo;
7733 * Clock the word select request out...
7735 for (i = cbits; i >= 0; i--) {
7736 if ((rqst >> i) & 1) {
7737 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
7739 bit = BIU_NVRAM_SELECT;
7741 ISP_WRITE(isp, BIU_NVRAM, bit);
7743 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7744 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
7746 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7747 ISP_WRITE(isp, BIU_NVRAM, bit);
7749 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7752 * Now read the result back in (bits come back in MSB format).
7755 for (i = 0; i < 16; i++) {
7758 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
7760 rv = ISP_READ(isp, BIU_NVRAM);
7761 if (rv & BIU_NVRAM_DATAIN) {
7765 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
7767 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7769 ISP_WRITE(isp, BIU_NVRAM, 0);
7771 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7772 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
7776 isp_rd_2400_nvram(ispsoftc_t *isp, uint32_t addr, uint32_t *rp)
7779 uint32_t base = 0x7ffe0000;
7783 base = 0x7fe7c000; /* XXX: Observation, may be wrong. */
7784 } else if (IS_25XX(isp)) {
7785 base = 0x7ff00000 | 0x48000;
7787 ISP_WRITE(isp, BIU2400_FLASH_ADDR, base | addr);
7788 for (loops = 0; loops < 5000; loops++) {
7790 tmp = ISP_READ(isp, BIU2400_FLASH_ADDR);
7791 if ((tmp & (1U << 31)) != 0) {
7795 if (tmp & (1U << 31)) {
7796 *rp = ISP_READ(isp, BIU2400_FLASH_DATA);
7797 ISP_SWIZZLE_NVRAM_LONG(isp, rp);
7804 isp_parse_nvram_1020(ispsoftc_t *isp, uint8_t *nvram_data)
7806 sdparam *sdp = SDPARAM(isp, 0);
7809 sdp->isp_fifo_threshold =
7810 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
7811 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
7813 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
7814 sdp->isp_initiator_id = ISP_NVRAM_INITIATOR_ID(nvram_data);
7816 sdp->isp_bus_reset_delay =
7817 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
7819 sdp->isp_retry_count =
7820 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
7822 sdp->isp_retry_delay =
7823 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
7825 sdp->isp_async_data_setup =
7826 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
7828 if (isp->isp_type >= ISP_HA_SCSI_1040) {
7829 if (sdp->isp_async_data_setup < 9) {
7830 sdp->isp_async_data_setup = 9;
7833 if (sdp->isp_async_data_setup != 6) {
7834 sdp->isp_async_data_setup = 6;
7838 sdp->isp_req_ack_active_neg =
7839 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
7841 sdp->isp_data_line_active_neg =
7842 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
7844 sdp->isp_data_dma_burst_enabl =
7845 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
7847 sdp->isp_cmd_dma_burst_enable =
7848 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
7850 sdp->isp_tag_aging =
7851 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
7853 sdp->isp_selection_timeout =
7854 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
7856 sdp->isp_max_queue_depth =
7857 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
7859 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
7861 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7862 sdp->isp_devparam[tgt].dev_enable =
7863 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
7864 sdp->isp_devparam[tgt].exc_throttle =
7865 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
7866 sdp->isp_devparam[tgt].nvrm_offset =
7867 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
7868 sdp->isp_devparam[tgt].nvrm_period =
7869 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
7871 * We probably shouldn't lie about this, but it
7872 * it makes it much safer if we limit NVRAM values
7875 if (isp->isp_type < ISP_HA_SCSI_1040) {
7877 * If we're not ultra, we can't possibly
7878 * be a shorter period than this.
7880 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
7881 sdp->isp_devparam[tgt].nvrm_period = 0x19;
7883 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
7884 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
7887 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
7888 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
7891 sdp->isp_devparam[tgt].nvrm_flags = 0;
7892 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
7893 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
7894 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
7895 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
7896 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
7897 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
7898 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
7899 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
7900 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
7901 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
7902 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
7903 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
7904 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
7905 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
7906 sdp->isp_devparam[tgt].goal_offset =
7907 sdp->isp_devparam[tgt].nvrm_offset;
7908 sdp->isp_devparam[tgt].goal_period =
7909 sdp->isp_devparam[tgt].nvrm_period;
7910 sdp->isp_devparam[tgt].goal_flags =
7911 sdp->isp_devparam[tgt].nvrm_flags;
7916 isp_parse_nvram_1080(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
7918 sdparam *sdp = SDPARAM(isp, bus);
7921 sdp->isp_fifo_threshold =
7922 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
7924 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
7925 sdp->isp_initiator_id = ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
7927 sdp->isp_bus_reset_delay =
7928 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
7930 sdp->isp_retry_count =
7931 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
7933 sdp->isp_retry_delay =
7934 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
7936 sdp->isp_async_data_setup =
7937 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
7939 sdp->isp_req_ack_active_neg =
7940 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
7942 sdp->isp_data_line_active_neg =
7943 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
7945 sdp->isp_data_dma_burst_enabl =
7946 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
7948 sdp->isp_cmd_dma_burst_enable =
7949 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
7951 sdp->isp_selection_timeout =
7952 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
7954 sdp->isp_max_queue_depth =
7955 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
7957 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7958 sdp->isp_devparam[tgt].dev_enable =
7959 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
7960 sdp->isp_devparam[tgt].exc_throttle =
7961 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
7962 sdp->isp_devparam[tgt].nvrm_offset =
7963 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
7964 sdp->isp_devparam[tgt].nvrm_period =
7965 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
7966 sdp->isp_devparam[tgt].nvrm_flags = 0;
7967 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
7968 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
7969 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
7970 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
7971 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
7972 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
7973 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
7974 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
7975 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
7976 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
7977 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
7978 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
7979 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
7980 sdp->isp_devparam[tgt].actv_flags = 0;
7981 sdp->isp_devparam[tgt].goal_offset =
7982 sdp->isp_devparam[tgt].nvrm_offset;
7983 sdp->isp_devparam[tgt].goal_period =
7984 sdp->isp_devparam[tgt].nvrm_period;
7985 sdp->isp_devparam[tgt].goal_flags =
7986 sdp->isp_devparam[tgt].nvrm_flags;
7991 isp_parse_nvram_12160(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
7993 sdparam *sdp = SDPARAM(isp, bus);
7996 sdp->isp_fifo_threshold =
7997 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
7999 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
8000 sdp->isp_initiator_id = ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
8002 sdp->isp_bus_reset_delay =
8003 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
8005 sdp->isp_retry_count =
8006 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
8008 sdp->isp_retry_delay =
8009 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
8011 sdp->isp_async_data_setup =
8012 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
8014 sdp->isp_req_ack_active_neg =
8015 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
8017 sdp->isp_data_line_active_neg =
8018 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
8020 sdp->isp_data_dma_burst_enabl =
8021 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
8023 sdp->isp_cmd_dma_burst_enable =
8024 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
8026 sdp->isp_selection_timeout =
8027 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
8029 sdp->isp_max_queue_depth =
8030 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
8032 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
8033 sdp->isp_devparam[tgt].dev_enable =
8034 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
8035 sdp->isp_devparam[tgt].exc_throttle =
8036 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
8037 sdp->isp_devparam[tgt].nvrm_offset =
8038 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
8039 sdp->isp_devparam[tgt].nvrm_period =
8040 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
8041 sdp->isp_devparam[tgt].nvrm_flags = 0;
8042 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
8043 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
8044 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
8045 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
8046 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
8047 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
8048 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
8049 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
8050 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
8051 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
8052 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
8053 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
8054 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
8055 sdp->isp_devparam[tgt].actv_flags = 0;
8056 sdp->isp_devparam[tgt].goal_offset =
8057 sdp->isp_devparam[tgt].nvrm_offset;
8058 sdp->isp_devparam[tgt].goal_period =
8059 sdp->isp_devparam[tgt].nvrm_period;
8060 sdp->isp_devparam[tgt].goal_flags =
8061 sdp->isp_devparam[tgt].nvrm_flags;
8066 isp_parse_nvram_2100(ispsoftc_t *isp, uint8_t *nvram_data)
8068 fcparam *fcp = FCPARAM(isp, 0);
8072 * There is NVRAM storage for both Port and Node entities-
8073 * but the Node entity appears to be unused on all the cards
8074 * I can find. However, we should account for this being set
8075 * at some point in the future.
8077 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
8078 * bits 48..60. In the case of the 2202, it appears that they do
8079 * use bit 48 to distinguish between the two instances on the card.
8080 * The 2204, which I've never seen, *probably* extends this method.
8082 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
8084 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
8085 (uint32_t) (wwn >> 32), (uint32_t) (wwn));
8086 if ((wwn >> 60) == 0) {
8087 wwn |= (((uint64_t) 2)<< 60);
8090 fcp->isp_wwpn_nvram = wwn;
8091 if (IS_2200(isp) || IS_23XX(isp)) {
8092 wwn = ISP2100_NVRAM_NODE_NAME(nvram_data);
8094 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
8095 (uint32_t) (wwn >> 32),
8097 if ((wwn >> 60) == 0) {
8098 wwn |= (((uint64_t) 2)<< 60);
8101 wwn = fcp->isp_wwpn_nvram & ~((uint64_t) 0xfff << 48);
8104 wwn &= ~((uint64_t) 0xfff << 48);
8106 fcp->isp_wwnn_nvram = wwn;
8108 fcp->isp_maxalloc = ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
8109 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
8110 DEFAULT_FRAMESIZE(isp) =
8111 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
8113 fcp->isp_retry_delay = ISP2100_NVRAM_RETRY_DELAY(nvram_data);
8114 fcp->isp_retry_count = ISP2100_NVRAM_RETRY_COUNT(nvram_data);
8115 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
8116 fcp->isp_loopid = ISP2100_NVRAM_HARDLOOPID(nvram_data);
8118 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
8119 DEFAULT_EXEC_THROTTLE(isp) =
8120 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
8122 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
8123 isp_prt(isp, ISP_LOGDEBUG0,
8124 "NVRAM 0x%08x%08x 0x%08x%08x maxalloc %d maxframelen %d",
8125 (uint32_t) (fcp->isp_wwnn_nvram >> 32),
8126 (uint32_t) fcp->isp_wwnn_nvram,
8127 (uint32_t) (fcp->isp_wwpn_nvram >> 32),
8128 (uint32_t) fcp->isp_wwpn_nvram,
8129 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data),
8130 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data));
8131 isp_prt(isp, ISP_LOGDEBUG0,
8132 "execthrottle %d fwoptions 0x%x hardloop %d tov %d",
8133 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
8134 ISP2100_NVRAM_OPTIONS(nvram_data),
8135 ISP2100_NVRAM_HARDLOOPID(nvram_data),
8136 ISP2100_NVRAM_TOV(nvram_data));
8137 fcp->isp_xfwoptions = ISP2100_XFW_OPTIONS(nvram_data);
8138 fcp->isp_zfwoptions = ISP2100_ZFW_OPTIONS(nvram_data);
8139 isp_prt(isp, ISP_LOGDEBUG0, "xfwoptions 0x%x zfw options 0x%x",
8140 ISP2100_XFW_OPTIONS(nvram_data), ISP2100_ZFW_OPTIONS(nvram_data));
8144 isp_parse_nvram_2400(ispsoftc_t *isp, uint8_t *nvram_data)
8146 fcparam *fcp = FCPARAM(isp, 0);
8149 isp_prt(isp, ISP_LOGDEBUG0,
8150 "NVRAM 0x%08x%08x 0x%08x%08x exchg_cnt %d maxframelen %d",
8151 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data) >> 32),
8152 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data)),
8153 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data) >> 32),
8154 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data)),
8155 ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data),
8156 ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data));
8157 isp_prt(isp, ISP_LOGDEBUG0,
8158 "NVRAM execthr %d loopid %d fwopt1 0x%x fwopt2 0x%x fwopt3 0x%x",
8159 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data),
8160 ISP2400_NVRAM_HARDLOOPID(nvram_data),
8161 ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data),
8162 ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data),
8163 ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data));
8165 wwn = ISP2400_NVRAM_PORT_NAME(nvram_data);
8166 fcp->isp_wwpn_nvram = wwn;
8168 wwn = ISP2400_NVRAM_NODE_NAME(nvram_data);
8170 if ((wwn >> 60) != 2 && (wwn >> 60) != 5) {
8174 if (wwn == 0 && (fcp->isp_wwpn_nvram >> 60) == 2) {
8175 wwn = fcp->isp_wwpn_nvram;
8176 wwn &= ~((uint64_t) 0xfff << 48);
8178 fcp->isp_wwnn_nvram = wwn;
8180 if (ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data)) {
8181 fcp->isp_maxalloc = ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data);
8183 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
8184 DEFAULT_FRAMESIZE(isp) =
8185 ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data);
8187 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
8188 fcp->isp_loopid = ISP2400_NVRAM_HARDLOOPID(nvram_data);
8190 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
8191 DEFAULT_EXEC_THROTTLE(isp) =
8192 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data);
8194 fcp->isp_fwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data);
8195 fcp->isp_xfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data);
8196 fcp->isp_zfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data);