2 * Copyright (c) 1997-2009 by Matthew Jacob
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * Machine and OS Independent (well, as best as possible)
31 * code for the Qlogic ISP SCSI and FC-SCSI adapters.
35 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
36 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
37 * ideas dredged from the Solaris driver.
41 * Include header file appropriate for platform we're building on.
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD$");
46 #include <dev/ic/isp_netbsd.h>
49 #include <sys/cdefs.h>
50 __FBSDID("$FreeBSD$");
51 #include <dev/isp/isp_freebsd.h>
54 #include <dev/ic/isp_openbsd.h>
57 #include "isp_linux.h"
60 #include "isp_solaris.h"
66 #define MBOX_DELAY_COUNT 1000000 / 100
71 static const char notresp[] = "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
72 static const char bun[] = "bad underrun (count %d, resid %d, status %s)";
73 static const char lipd[] = "Chan %d LIP destroyed %d active commands";
74 static const char sacq[] = "unable to acquire scratch area";
76 static const uint8_t alpa_map[] = {
77 0xef, 0xe8, 0xe4, 0xe2, 0xe1, 0xe0, 0xdc, 0xda,
78 0xd9, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xce,
79 0xcd, 0xcc, 0xcb, 0xca, 0xc9, 0xc7, 0xc6, 0xc5,
80 0xc3, 0xbc, 0xba, 0xb9, 0xb6, 0xb5, 0xb4, 0xb3,
81 0xb2, 0xb1, 0xae, 0xad, 0xac, 0xab, 0xaa, 0xa9,
82 0xa7, 0xa6, 0xa5, 0xa3, 0x9f, 0x9e, 0x9d, 0x9b,
83 0x98, 0x97, 0x90, 0x8f, 0x88, 0x84, 0x82, 0x81,
84 0x80, 0x7c, 0x7a, 0x79, 0x76, 0x75, 0x74, 0x73,
85 0x72, 0x71, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x69,
86 0x67, 0x66, 0x65, 0x63, 0x5c, 0x5a, 0x59, 0x56,
87 0x55, 0x54, 0x53, 0x52, 0x51, 0x4e, 0x4d, 0x4c,
88 0x4b, 0x4a, 0x49, 0x47, 0x46, 0x45, 0x43, 0x3c,
89 0x3a, 0x39, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31,
90 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x27, 0x26,
91 0x25, 0x23, 0x1f, 0x1e, 0x1d, 0x1b, 0x18, 0x17,
92 0x10, 0x0f, 0x08, 0x04, 0x02, 0x01, 0x00
96 * Local function prototypes.
98 static int isp_parse_async(ispsoftc_t *, uint16_t);
99 static int isp_parse_async_fc(ispsoftc_t *, uint16_t);
100 static int isp_handle_other_response(ispsoftc_t *, int, isphdr_t *, uint32_t *);
101 static void isp_parse_status(ispsoftc_t *, ispstatusreq_t *, XS_T *, long *); static void
102 isp_parse_status_24xx(ispsoftc_t *, isp24xx_statusreq_t *, XS_T *, long *);
103 static void isp_fastpost_complete(ispsoftc_t *, uint32_t);
104 static int isp_mbox_continue(ispsoftc_t *);
105 static void isp_scsi_init(ispsoftc_t *);
106 static void isp_scsi_channel_init(ispsoftc_t *, int);
107 static void isp_fibre_init(ispsoftc_t *);
108 static void isp_fibre_init_2400(ispsoftc_t *);
109 static void isp_clear_portdb(ispsoftc_t *, int);
110 static void isp_mark_portdb(ispsoftc_t *, int);
111 static int isp_plogx(ispsoftc_t *, int, uint16_t, uint32_t, int);
112 static int isp_port_login(ispsoftc_t *, uint16_t, uint32_t);
113 static int isp_port_logout(ispsoftc_t *, uint16_t, uint32_t);
114 static int isp_getpdb(ispsoftc_t *, int, uint16_t, isp_pdb_t *);
115 static int isp_gethandles(ispsoftc_t *, int, uint16_t *, int *, int);
116 static void isp_dump_chip_portdb(ispsoftc_t *, int);
117 static uint64_t isp_get_wwn(ispsoftc_t *, int, int, int);
118 static int isp_fclink_test(ispsoftc_t *, int, int);
119 static int isp_pdb_sync(ispsoftc_t *, int);
120 static int isp_scan_loop(ispsoftc_t *, int);
121 static int isp_gid_ft_sns(ispsoftc_t *, int);
122 static int isp_gid_ft_ct_passthru(ispsoftc_t *, int);
123 static int isp_scan_fabric(ispsoftc_t *, int);
124 static int isp_login_device(ispsoftc_t *, int, uint32_t, isp_pdb_t *, uint16_t *);
125 static int isp_send_change_request(ispsoftc_t *, int);
126 static int isp_register_fc4_type(ispsoftc_t *, int);
127 static int isp_register_fc4_type_24xx(ispsoftc_t *, int);
128 static int isp_register_fc4_features_24xx(ispsoftc_t *, int);
129 static int isp_register_port_name_24xx(ispsoftc_t *, int);
130 static int isp_register_node_name_24xx(ispsoftc_t *, int);
131 static uint16_t isp_next_handle(ispsoftc_t *, uint16_t *);
132 static int isp_fw_state(ispsoftc_t *, int);
133 static void isp_mboxcmd_qnw(ispsoftc_t *, mbreg_t *, int);
134 static void isp_mboxcmd(ispsoftc_t *, mbreg_t *);
136 static void isp_spi_update(ispsoftc_t *, int);
137 static void isp_setdfltsdparm(ispsoftc_t *);
138 static void isp_setdfltfcparm(ispsoftc_t *, int);
139 static int isp_read_nvram(ispsoftc_t *, int);
140 static int isp_read_nvram_2400(ispsoftc_t *, uint8_t *);
141 static void isp_rdnvram_word(ispsoftc_t *, int, uint16_t *);
142 static void isp_rd_2400_nvram(ispsoftc_t *, uint32_t, uint32_t *);
143 static void isp_parse_nvram_1020(ispsoftc_t *, uint8_t *);
144 static void isp_parse_nvram_1080(ispsoftc_t *, int, uint8_t *);
145 static void isp_parse_nvram_12160(ispsoftc_t *, int, uint8_t *);
146 static void isp_parse_nvram_2100(ispsoftc_t *, uint8_t *);
147 static void isp_parse_nvram_2400(ispsoftc_t *, uint8_t *);
150 isp_change_fw_state(ispsoftc_t *isp, int chan, int state)
152 fcparam *fcp = FCPARAM(isp, chan);
154 if (fcp->isp_fwstate == state)
156 isp_prt(isp, ISP_LOGCONFIG|ISP_LOG_SANCFG,
157 "Chan %d Firmware state <%s->%s>", chan,
158 isp_fc_fw_statename(fcp->isp_fwstate), isp_fc_fw_statename(state));
159 fcp->isp_fwstate = state;
165 * Hit the chip over the head, download new f/w if available and set it running.
167 * Locking done elsewhere.
171 isp_reset(ispsoftc_t *isp, int do_load_defaults)
176 uint32_t code_org, val;
177 int loops, i, dodnld = 1;
178 const char *btype = "????";
179 static const char dcrc[] = "Downloaded RISC Code Checksum Failure";
181 isp->isp_state = ISP_NILSTATE;
184 ISP_DISABLE_INTS(isp);
189 * Basic types (SCSI, FibreChannel and PCI or SBus)
190 * have been set in the MD code. We figure out more
191 * here. Possibly more refined types based upon PCI
192 * identification. Chip revision has been gathered.
194 * After we've fired this chip up, zero out the conf1 register
195 * for SCSI adapters and do other settings for the 2100.
198 ISP_DISABLE_INTS(isp);
201 * Pick an initial maxcmds value which will be used
202 * to allocate xflist pointer space. It may be changed
203 * later by the firmware.
206 isp->isp_maxcmds = 4096;
207 } else if (IS_2322(isp)) {
208 isp->isp_maxcmds = 2048;
209 } else if (IS_23XX(isp) || IS_2200(isp)) {
210 isp->isp_maxcmds = 1024;
212 isp->isp_maxcmds = 512;
216 * Set up DMA for the request and response queues.
218 * We do this now so we can use the request queue
219 * for dma to load firmware from.
221 if (ISP_MBOXDMASETUP(isp) != 0) {
222 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
227 * Set up default request/response queue in-pointer/out-pointer
231 isp->isp_rqstinrp = BIU2400_REQINP;
232 isp->isp_rqstoutrp = BIU2400_REQOUTP;
233 isp->isp_respinrp = BIU2400_RSPINP;
234 isp->isp_respoutrp = BIU2400_RSPOUTP;
235 } else if (IS_23XX(isp)) {
236 isp->isp_rqstinrp = BIU_REQINP;
237 isp->isp_rqstoutrp = BIU_REQOUTP;
238 isp->isp_respinrp = BIU_RSPINP;
239 isp->isp_respoutrp = BIU_RSPOUTP;
241 isp->isp_rqstinrp = INMAILBOX4;
242 isp->isp_rqstoutrp = OUTMAILBOX4;
243 isp->isp_respinrp = OUTMAILBOX5;
244 isp->isp_respoutrp = INMAILBOX5;
248 * Put the board into PAUSE mode (so we can read the SXP registers
249 * or write FPM/FBM registers).
252 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_HOST_INT);
253 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
254 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_PAUSE);
256 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
260 switch (isp->isp_type) {
291 * While we're paused, reset the FPM module and FBM
294 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
295 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
296 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
297 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
298 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
300 } else if (IS_1240(isp)) {
305 sdp = SDPARAM(isp, 0);
306 sdp->isp_ultramode = 1;
307 sdp = SDPARAM(isp, 1);
308 sdp->isp_ultramode = 1;
310 * XXX: Should probably do some bus sensing.
312 } else if (IS_ULTRA3(isp)) {
313 sdparam *sdp = isp->isp_param;
315 isp->isp_clock = 100;
319 else if (IS_12160(isp))
323 sdp->isp_lvdmode = 1;
325 if (IS_DUALBUS(isp)) {
327 sdp->isp_lvdmode = 1;
329 } else if (IS_ULTRA2(isp)) {
330 static const char m[] = "bus %d is in %s Mode";
332 sdparam *sdp = SDPARAM(isp, 0);
334 isp->isp_clock = 100;
338 else if (IS_1080(isp))
343 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
345 case ISP1080_LVD_MODE:
346 sdp->isp_lvdmode = 1;
347 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
349 case ISP1080_HVD_MODE:
350 sdp->isp_diffmode = 1;
351 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
353 case ISP1080_SE_MODE:
354 sdp->isp_ultramode = 1;
355 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
358 isp_prt(isp, ISP_LOGERR,
359 "unknown mode on bus %d (0x%x)", 0, l);
363 if (IS_DUALBUS(isp)) {
364 sdp = SDPARAM(isp, 1);
365 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
366 l &= ISP1080_MODE_MASK;
368 case ISP1080_LVD_MODE:
369 sdp->isp_lvdmode = 1;
370 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
372 case ISP1080_HVD_MODE:
373 sdp->isp_diffmode = 1;
374 isp_prt(isp, ISP_LOGCONFIG,
375 m, 1, "Differential");
377 case ISP1080_SE_MODE:
378 sdp->isp_ultramode = 1;
379 isp_prt(isp, ISP_LOGCONFIG,
380 m, 1, "Single-Ended");
383 isp_prt(isp, ISP_LOGERR,
384 "unknown mode on bus %d (0x%x)", 1, l);
389 sdparam *sdp = SDPARAM(isp, 0);
390 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
393 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
397 isp->isp_type = ISP_HA_SCSI_1020;
402 * Some 1020A chips are Ultra Capable, but don't
403 * run the clock rate up for that unless told to
404 * do so by the Ultra Capable bits being set.
407 isp->isp_type = ISP_HA_SCSI_1020A;
412 isp->isp_type = ISP_HA_SCSI_1040;
417 isp->isp_type = ISP_HA_SCSI_1040A;
422 isp->isp_type = ISP_HA_SCSI_1040B;
427 isp->isp_type = ISP_HA_SCSI_1040C;
432 * Now, while we're at it, gather info about ultra
433 * and/or differential mode.
435 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
436 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
437 sdp->isp_diffmode = 1;
439 sdp->isp_diffmode = 0;
441 i = ISP_READ(isp, RISC_PSR);
442 if (isp->isp_bustype == ISP_BT_SBUS) {
443 i &= RISC_PSR_SBUS_ULTRA;
445 i &= RISC_PSR_PCI_ULTRA;
448 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
449 sdp->isp_ultramode = 1;
451 * If we're in Ultra Mode, we have to be 60MHz clock-
452 * even for the SBus version.
456 sdp->isp_ultramode = 0;
458 * Clock is known. Gronk.
463 * Machine dependent clock (if set) overrides
464 * our generic determinations.
466 if (isp->isp_mdvec->dv_clock) {
467 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
468 isp->isp_clock = isp->isp_mdvec->dv_clock;
475 * Clear instrumentation
477 isp->isp_intcnt = isp->isp_intbogus = 0;
480 * Do MD specific pre initialization
485 * Hit the chip over the head with hammer,
486 * and give it a chance to recover.
490 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
497 * Clear data && control DMA engines.
499 ISP_WRITE(isp, CDMA_CONTROL, DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
500 ISP_WRITE(isp, DDMA_CONTROL, DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
503 } else if (IS_24XX(isp)) {
505 * Stop DMA and wait for it to stop.
507 ISP_WRITE(isp, BIU2400_CSR, BIU2400_DMA_STOP|(3 << 4));
508 for (val = loops = 0; loops < 30000; loops++) {
510 val = ISP_READ(isp, BIU2400_CSR);
511 if ((val & BIU2400_DMA_ACTIVE) == 0) {
515 if (val & BIU2400_DMA_ACTIVE) {
517 isp_prt(isp, ISP_LOGERR, "DMA Failed to Stop on Reset");
521 * Hold it in SOFT_RESET and STOP state for 100us.
523 ISP_WRITE(isp, BIU2400_CSR, BIU2400_SOFT_RESET|BIU2400_DMA_STOP|(3 << 4));
525 for (loops = 0; loops < 10000; loops++) {
527 val = ISP_READ(isp, OUTMAILBOX0);
529 for (val = loops = 0; loops < 500000; loops ++) {
530 val = ISP_READ(isp, BIU2400_CSR);
531 if ((val & BIU2400_SOFT_RESET) == 0) {
535 if (val & BIU2400_SOFT_RESET) {
537 isp_prt(isp, ISP_LOGERR, "Failed to come out of reset");
541 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
548 * Clear data && control DMA engines.
550 ISP_WRITE(isp, CDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
551 ISP_WRITE(isp, TDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
552 ISP_WRITE(isp, RDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
556 * Wait for ISP to be ready to go...
558 loops = MBOX_DELAY_COUNT;
561 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET)) {
564 } else if (IS_24XX(isp)) {
565 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
569 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
574 ISP_DUMPREGS(isp, "chip reset timed out");
581 * After we've fired this chip up, zero out the conf1 register
582 * for SCSI adapters and other settings for the 2100.
586 ISP_WRITE(isp, BIU_CONF1, 0);
587 } else if (!IS_24XX(isp)) {
588 ISP_WRITE(isp, BIU2100_CSR, 0);
592 * Reset RISC Processor
595 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RESET);
596 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RELEASE);
597 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RESET);
599 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
601 ISP_WRITE(isp, BIU_SEMA, 0);
605 * Post-RISC Reset stuff.
608 for (val = loops = 0; loops < 5000000; loops++) {
610 val = ISP_READ(isp, OUTMAILBOX0);
617 isp_prt(isp, ISP_LOGERR, "reset didn't clear");
620 } else if (IS_SCSI(isp)) {
621 uint16_t tmp = isp->isp_mdvec->dv_conf1;
623 * Busted FIFO. Turn off all but burst enables.
625 if (isp->isp_type == ISP_HA_SCSI_1040A) {
626 tmp &= BIU_BURST_ENABLE;
628 ISP_SETBITS(isp, BIU_CONF1, tmp);
629 if (tmp & BIU_BURST_ENABLE) {
630 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
631 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
633 if (SDPARAM(isp, 0)->isp_ptisp) {
634 if (SDPARAM(isp, 0)->isp_ultramode) {
635 while (ISP_READ(isp, RISC_MTR) != 0x1313) {
636 ISP_WRITE(isp, RISC_MTR, 0x1313);
637 ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
640 ISP_WRITE(isp, RISC_MTR, 0x1212);
643 * PTI specific register
645 ISP_WRITE(isp, RISC_EMB, DUAL_BANK);
647 ISP_WRITE(isp, RISC_MTR, 0x1212);
649 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
651 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
652 if (IS_2200(isp) || IS_23XX(isp)) {
653 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
655 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
658 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
659 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
660 ISP_WRITE(isp, isp->isp_respinrp, 0);
661 ISP_WRITE(isp, isp->isp_respoutrp, 0);
664 ISP_WRITE(isp, BIU2400_PRI_REQINP, 0);
665 ISP_WRITE(isp, BIU2400_PRI_REQOUTP, 0);
667 ISP_WRITE(isp, BIU2400_ATIO_RSPINP, 0);
668 ISP_WRITE(isp, BIU2400_ATIO_RSPOUTP, 0);
672 * Do MD specific post initialization
677 * Wait for everything to finish firing up.
679 * Avoid doing this on early 2312s because you can generate a PCI
680 * parity error (chip breakage).
682 if (IS_2312(isp) && isp->isp_revision < 2) {
685 loops = MBOX_DELAY_COUNT;
686 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
690 isp_prt(isp, ISP_LOGERR, "MBOX_BUSY never cleared on reset");
697 * Up until this point we've done everything by just reading or
698 * setting registers. From this point on we rely on at least *some*
699 * kind of firmware running in the card.
703 * Do some sanity checking by running a NOP command.
704 * If it succeeds, the ROM firmware is now running.
706 MBSINIT(&mbs, MBOX_NO_OP, MBLOGALL, 0);
707 isp_mboxcmd(isp, &mbs);
708 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
709 isp_prt(isp, ISP_LOGERR, "NOP command failed (%x)", mbs.param[0]);
715 * Do some operational tests
718 if (IS_SCSI(isp) || IS_24XX(isp)) {
719 static const uint16_t patterns[MAX_MAILBOX] = {
720 0x0000, 0xdead, 0xbeef, 0xffff,
721 0xa5a5, 0x5a5a, 0x7f7f, 0x7ff7,
722 0x3421, 0xabcd, 0xdcba, 0xfeef,
723 0xbead, 0xdebe, 0x2222, 0x3333,
724 0x5555, 0x6666, 0x7777, 0xaaaa,
725 0xffff, 0xdddd, 0x9999, 0x1fbc,
726 0x6666, 0x6677, 0x1122, 0x33ff,
727 0x0000, 0x0001, 0x1000, 0x1010,
729 int nmbox = ISP_NMBOX(isp);
732 MBSINIT(&mbs, MBOX_MAILBOX_REG_TEST, MBLOGALL, 0);
733 for (i = 1; i < nmbox; i++) {
734 mbs.param[i] = patterns[i];
736 isp_mboxcmd(isp, &mbs);
737 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
741 for (i = 1; i < nmbox; i++) {
742 if (mbs.param[i] != patterns[i]) {
744 isp_prt(isp, ISP_LOGERR, "Register Test Failed at Register %d: should have 0x%04x but got 0x%04x", i, patterns[i], mbs.param[i]);
751 * Download new Firmware, unless requested not to do so.
752 * This is made slightly trickier in some cases where the
753 * firmware of the ROM revision is newer than the revision
754 * compiled into the driver. So, where we used to compare
755 * versions of our f/w and the ROM f/w, now we just see
756 * whether we have f/w at all and whether a config flag
757 * has disabled our download.
759 if ((isp->isp_mdvec->dv_ispfw == NULL) || (isp->isp_confopts & ISP_CFG_NORELOAD)) {
764 code_org = ISP_CODE_ORG_2400;
765 } else if (IS_23XX(isp)) {
766 code_org = ISP_CODE_ORG_2300;
768 code_org = ISP_CODE_ORG;
771 isp->isp_loaded_fw = 0;
772 if (dodnld && IS_24XX(isp)) {
773 const uint32_t *ptr = isp->isp_mdvec->dv_ispfw;
777 * Keep loading until we run out of f/w.
779 code_org = ptr[2]; /* 1st load address is our start addr */
785 isp_prt(isp, ISP_LOGDEBUG0, "load 0x%x words of code at load address 0x%x", ptr[3], ptr[2]);
791 while (wi < ptr[3]) {
795 nw = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) >> 2;
799 cp = isp->isp_rquest;
800 for (i = 0; i < nw; i++) {
801 ISP_IOXPUT_32(isp, ptr[wi++], &cp[i]);
804 MEMORYBARRIER(isp, SYNC_REQUEST, 0, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)), -1);
806 MBSINIT(&mbs, 0, MBLOGALL, 0);
807 if (la < 0x10000 && nw < 0x10000) {
808 mbs.param[0] = MBOX_LOAD_RISC_RAM_2100;
810 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
811 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
813 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
814 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
815 isp_prt(isp, ISP_LOGDEBUG0, "LOAD RISC RAM 2100 %u words at load address 0x%x", nw, la);
816 } else if (wordload) {
821 ucd.cp = (const uint32_t *)cp;
822 mbs.param[0] = MBOX_WRITE_RAM_WORD_EXTENDED;
824 mbs.param[2] = (*ucd.np);
825 mbs.param[3] = (*ucd.np) >> 16;
826 mbs.param[8] = la >> 16;
827 isp->isp_mbxwrk0 = nw - 1;
828 isp->isp_mbxworkp = ucd.np+1;
829 isp->isp_mbxwrk1 = (la + 1);
830 isp->isp_mbxwrk8 = (la + 1) >> 16;
831 isp_prt(isp, ISP_LOGDEBUG0, "WRITE RAM WORD EXTENDED %u words at load address 0x%x", nw, la);
833 mbs.param[0] = MBOX_LOAD_RISC_RAM;
835 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
836 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
837 mbs.param[4] = nw >> 16;
839 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
840 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
841 mbs.param[8] = la >> 16;
842 isp_prt(isp, ISP_LOGDEBUG0, "LOAD RISC RAM %u words at load address 0x%x", nw, la);
844 isp_mboxcmd(isp, &mbs);
845 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
846 if (mbs.param[0] == MBOX_HOST_INTERFACE_ERROR) {
847 isp_prt(isp, ISP_LOGERR, "switching to word load");
851 isp_prt(isp, ISP_LOGERR, "F/W Risc Ram Load Failed");
863 isp->isp_loaded_fw = 1;
864 } else if (dodnld && IS_23XX(isp)) {
865 const uint16_t *ptr = isp->isp_mdvec->dv_ispfw;
866 uint16_t wi, wl, segno;
875 isp_prt(isp, ISP_LOGDEBUG0, "load 0x%x words of code at load address 0x%x", ptr[3], la);
880 while (wi < ptr[3]) {
884 nw = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) >> 1;
888 if (nw > (1 << 15)) {
891 cp = isp->isp_rquest;
892 for (i = 0; i < nw; i++) {
893 ISP_IOXPUT_16(isp, ptr[wi++], &cp[i]);
896 MEMORYBARRIER(isp, SYNC_REQUEST, 0, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)), -1);
897 MBSINIT(&mbs, 0, MBLOGALL, 0);
899 mbs.param[0] = MBOX_LOAD_RISC_RAM_2100;
901 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
902 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
904 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
905 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
906 isp_prt(isp, ISP_LOGDEBUG1, "LOAD RISC RAM 2100 %u words at load address 0x%x\n", nw, la);
908 mbs.param[0] = MBOX_LOAD_RISC_RAM;
910 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
911 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
913 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
914 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
915 mbs.param[8] = la >> 16;
916 isp_prt(isp, ISP_LOGDEBUG1, "LOAD RISC RAM %u words at load address 0x%x\n", nw, la);
918 isp_mboxcmd(isp, &mbs);
919 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
920 isp_prt(isp, ISP_LOGERR, "F/W Risc Ram Load Failed");
936 * If we're a 2322, the firmware actually comes in
937 * three chunks. We loaded the first at the code_org
938 * address. The other two chunks, which follow right
939 * after each other in memory here, get loaded at
940 * addresses specfied at offset 0x9..0xB.
945 la = ptr[5] | ((ptr[4] & 0x3f) << 16);
947 isp->isp_loaded_fw = 1;
953 ucd.cp = isp->isp_mdvec->dv_ispfw;
954 isp->isp_mbxworkp = &ucd.np[1];
955 isp->isp_mbxwrk0 = ucd.np[3] - 1;
956 isp->isp_mbxwrk1 = code_org + 1;
957 MBSINIT(&mbs, MBOX_WRITE_RAM_WORD, MBLOGNONE, 0);
958 mbs.param[1] = code_org;
959 mbs.param[2] = ucd.np[0];
960 isp_prt(isp, ISP_LOGDEBUG1, "WRITE RAM %u words at load address 0x%x", ucd.np[3], code_org);
961 isp_mboxcmd(isp, &mbs);
962 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
963 isp_prt(isp, ISP_LOGERR, "F/W download failed at word %d", isp->isp_mbxwrk1 - code_org);
967 } else if (IS_26XX(isp)) {
968 MBSINIT(&mbs, MBOX_LOAD_FLASH_FIRMWARE, MBLOGALL, 5000000);
971 isp_mboxcmd(isp, &mbs);
972 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
973 isp_prt(isp, ISP_LOGERR, "Flash F/W load failed");
978 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
982 * If we loaded firmware, verify its checksum
984 if (isp->isp_loaded_fw) {
985 MBSINIT(&mbs, MBOX_VERIFY_CHECKSUM, MBLOGNONE, 0);
987 mbs.param[1] = code_org >> 16;
988 mbs.param[2] = code_org;
990 mbs.param[1] = code_org;
992 isp_mboxcmd(isp, &mbs);
993 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
994 isp_prt(isp, ISP_LOGERR, dcrc);
1001 * Now start it rolling.
1003 * If we didn't actually download f/w,
1004 * we still need to (re)start it.
1008 MBSINIT(&mbs, MBOX_EXEC_FIRMWARE, MBLOGALL, 5000000);
1010 mbs.param[1] = code_org >> 16;
1011 mbs.param[2] = code_org;
1012 if (isp->isp_loaded_fw) {
1017 } else if (IS_2322(isp)) {
1018 mbs.param[1] = code_org;
1019 if (isp->isp_loaded_fw) {
1025 mbs.param[1] = code_org;
1027 isp_mboxcmd(isp, &mbs);
1028 if (IS_2322(isp) || IS_24XX(isp)) {
1029 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1037 * Set CLOCK RATE, but only if asked to.
1039 if (isp->isp_clock) {
1040 MBSINIT(&mbs, MBOX_SET_CLOCK_RATE, MBLOGALL, 0);
1041 mbs.param[1] = isp->isp_clock;
1042 isp_mboxcmd(isp, &mbs);
1043 /* we will try not to care if this fails */
1048 * Ask the chip for the current firmware version.
1049 * This should prove that the new firmware is working.
1051 MBSINIT(&mbs, MBOX_ABOUT_FIRMWARE, MBLOGALL, 0);
1052 isp_mboxcmd(isp, &mbs);
1053 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1059 * The SBus firmware that we are using apparently does not return
1060 * major, minor, micro revisions in the mailbox registers, which
1061 * is really, really, annoying.
1063 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
1065 #ifdef ISP_TARGET_MODE
1066 isp->isp_fwrev[0] = 7;
1067 isp->isp_fwrev[1] = 55;
1069 isp->isp_fwrev[0] = 1;
1070 isp->isp_fwrev[1] = 37;
1072 isp->isp_fwrev[2] = 0;
1075 isp->isp_fwrev[0] = mbs.param[1];
1076 isp->isp_fwrev[1] = mbs.param[2];
1077 isp->isp_fwrev[2] = mbs.param[3];
1082 * We do not believe firmware attributes for 2100 code less
1083 * than 1.17.0, unless it's the firmware we specifically
1086 * Note that all 22XX and later f/w is greater than 1.X.0.
1088 if ((ISP_FW_OLDER_THAN(isp, 1, 17, 1))) {
1089 #ifdef USE_SMALLER_2100_FIRMWARE
1090 isp->isp_fwattr = ISP_FW_ATTR_SCCLUN;
1092 isp->isp_fwattr = 0;
1095 isp->isp_fwattr = mbs.param[6];
1098 isp->isp_fwattr |= ((uint64_t) mbs.param[15]) << 16;
1099 if (isp->isp_fwattr & ISP2400_FW_ATTR_EXTNDED) {
1101 (((uint64_t) mbs.param[16]) << 32) |
1102 (((uint64_t) mbs.param[17]) << 48);
1106 isp->isp_fwattr = 0;
1109 isp_prt(isp, ISP_LOGCONFIG, "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
1110 btype, isp->isp_revision, dodnld? "loaded" : "resident", isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
1112 fwt = isp->isp_fwattr;
1114 buf = FCPARAM(isp, 0)->isp_scratch;
1115 ISP_SNPRINTF(buf, ISP_FC_SCRLEN, "Attributes:");
1116 if (fwt & ISP2400_FW_ATTR_CLASS2) {
1117 fwt ^=ISP2400_FW_ATTR_CLASS2;
1118 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s Class2", buf);
1120 if (fwt & ISP2400_FW_ATTR_IP) {
1121 fwt ^=ISP2400_FW_ATTR_IP;
1122 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s IP", buf);
1124 if (fwt & ISP2400_FW_ATTR_MULTIID) {
1125 fwt ^=ISP2400_FW_ATTR_MULTIID;
1126 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s MultiID", buf);
1128 if (fwt & ISP2400_FW_ATTR_SB2) {
1129 fwt ^=ISP2400_FW_ATTR_SB2;
1130 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s SB2", buf);
1132 if (fwt & ISP2400_FW_ATTR_T10CRC) {
1133 fwt ^=ISP2400_FW_ATTR_T10CRC;
1134 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s T10CRC", buf);
1136 if (fwt & ISP2400_FW_ATTR_VI) {
1137 fwt ^=ISP2400_FW_ATTR_VI;
1138 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VI", buf);
1140 if (fwt & ISP2400_FW_ATTR_MQ) {
1141 fwt ^=ISP2400_FW_ATTR_MQ;
1142 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s MQ", buf);
1144 if (fwt & ISP2400_FW_ATTR_MSIX) {
1145 fwt ^=ISP2400_FW_ATTR_MSIX;
1146 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s MSIX", buf);
1148 if (fwt & ISP2400_FW_ATTR_FCOE) {
1149 fwt ^=ISP2400_FW_ATTR_FCOE;
1150 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s FCOE", buf);
1152 if (fwt & ISP2400_FW_ATTR_VP0) {
1153 fwt ^= ISP2400_FW_ATTR_VP0;
1154 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VP0_Decoupling", buf);
1156 if (fwt & ISP2400_FW_ATTR_EXPFW) {
1157 fwt ^= ISP2400_FW_ATTR_EXPFW;
1158 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s (Experimental)", buf);
1160 if (fwt & ISP2400_FW_ATTR_HOTFW) {
1161 fwt ^= ISP2400_FW_ATTR_HOTFW;
1162 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s HotFW", buf);
1164 fwt &= ~ISP2400_FW_ATTR_EXTNDED;
1165 if (fwt & ISP2400_FW_ATTR_EXTVP) {
1166 fwt ^= ISP2400_FW_ATTR_EXTVP;
1167 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s ExtVP", buf);
1169 if (fwt & ISP2400_FW_ATTR_VN2VN) {
1170 fwt ^= ISP2400_FW_ATTR_VN2VN;
1171 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VN2VN", buf);
1173 if (fwt & ISP2400_FW_ATTR_EXMOFF) {
1174 fwt ^= ISP2400_FW_ATTR_EXMOFF;
1175 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s EXMOFF", buf);
1177 if (fwt & ISP2400_FW_ATTR_NPMOFF) {
1178 fwt ^= ISP2400_FW_ATTR_NPMOFF;
1179 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s NPMOFF", buf);
1181 if (fwt & ISP2400_FW_ATTR_DIFCHOP) {
1182 fwt ^= ISP2400_FW_ATTR_DIFCHOP;
1183 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s DIFCHOP", buf);
1185 if (fwt & ISP2400_FW_ATTR_SRIOV) {
1186 fwt ^= ISP2400_FW_ATTR_SRIOV;
1187 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s SRIOV", buf);
1189 if (fwt & ISP2400_FW_ATTR_ASICTMP) {
1190 fwt ^= ISP2400_FW_ATTR_ASICTMP;
1191 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s ASICTMP", buf);
1193 if (fwt & ISP2400_FW_ATTR_ATIOMQ) {
1194 fwt ^= ISP2400_FW_ATTR_ATIOMQ;
1195 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s ATIOMQ", buf);
1198 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s (unknown 0x%08x%08x)", buf,
1199 (uint32_t) (fwt >> 32), (uint32_t) fwt);
1201 isp_prt(isp, ISP_LOGCONFIG, "%s", buf);
1202 } else if (IS_FC(isp)) {
1203 buf = FCPARAM(isp, 0)->isp_scratch;
1204 ISP_SNPRINTF(buf, ISP_FC_SCRLEN, "Attributes:");
1205 if (fwt & ISP_FW_ATTR_TMODE) {
1206 fwt ^=ISP_FW_ATTR_TMODE;
1207 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s TargetMode", buf);
1209 if (fwt & ISP_FW_ATTR_SCCLUN) {
1210 fwt ^=ISP_FW_ATTR_SCCLUN;
1211 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s SCC-Lun", buf);
1213 if (fwt & ISP_FW_ATTR_FABRIC) {
1214 fwt ^=ISP_FW_ATTR_FABRIC;
1215 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s Fabric", buf);
1217 if (fwt & ISP_FW_ATTR_CLASS2) {
1218 fwt ^=ISP_FW_ATTR_CLASS2;
1219 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s Class2", buf);
1221 if (fwt & ISP_FW_ATTR_FCTAPE) {
1222 fwt ^=ISP_FW_ATTR_FCTAPE;
1223 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s FC-Tape", buf);
1225 if (fwt & ISP_FW_ATTR_IP) {
1226 fwt ^=ISP_FW_ATTR_IP;
1227 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s IP", buf);
1229 if (fwt & ISP_FW_ATTR_VI) {
1230 fwt ^=ISP_FW_ATTR_VI;
1231 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VI", buf);
1233 if (fwt & ISP_FW_ATTR_VI_SOLARIS) {
1234 fwt ^=ISP_FW_ATTR_VI_SOLARIS;
1235 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VI_SOLARIS", buf);
1237 if (fwt & ISP_FW_ATTR_2KLOGINS) {
1238 fwt ^=ISP_FW_ATTR_2KLOGINS;
1239 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s 2K-Login", buf);
1242 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s (unknown 0x%08x%08x)", buf,
1243 (uint32_t) (fwt >> 32), (uint32_t) fwt);
1245 isp_prt(isp, ISP_LOGCONFIG, "%s", buf);
1249 MBSINIT(&mbs, MBOX_GET_RESOURCE_COUNT, MBLOGALL, 0);
1250 isp_mboxcmd(isp, &mbs);
1251 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1255 if (isp->isp_maxcmds >= mbs.param[3]) {
1256 isp->isp_maxcmds = mbs.param[3];
1259 MBSINIT(&mbs, MBOX_GET_FIRMWARE_STATUS, MBLOGALL, 0);
1260 isp_mboxcmd(isp, &mbs);
1261 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1265 if (isp->isp_maxcmds >= mbs.param[2]) {
1266 isp->isp_maxcmds = mbs.param[2];
1269 isp_prt(isp, ISP_LOGCONFIG, "%d max I/O command limit set", isp->isp_maxcmds);
1272 * If we don't have Multi-ID f/w loaded, we need to restrict channels to one.
1273 * Only make this check for non-SCSI cards (I'm not sure firmware attributes
1276 if (IS_FC(isp) && isp->isp_nchan > 1) {
1277 if (!ISP_CAP_MULTI_ID(isp)) {
1278 isp_prt(isp, ISP_LOGWARN, "non-MULTIID f/w loaded, "
1279 "only can enable 1 of %d channels", isp->isp_nchan);
1281 } else if (!ISP_CAP_VP0(isp)) {
1282 isp_prt(isp, ISP_LOGWARN, "We can not use MULTIID "
1283 "feature properly without VP0_Decoupling");
1288 for (i = 0; i < isp->isp_nchan; i++)
1289 isp_change_fw_state(isp, i, FW_CONFIG_WAIT);
1291 if (isp->isp_dead) {
1293 ISP_DISABLE_INTS(isp);
1297 isp->isp_state = ISP_RESETSTATE;
1300 * Okay- now that we have new firmware running, we now (re)set our
1301 * notion of how many luns we support. This is somewhat tricky because
1302 * if we haven't loaded firmware, we sometimes do not have an easy way
1303 * of knowing how many luns we support.
1305 * Expanded lun firmware gives you 32 luns for SCSI cards and
1306 * 16384 luns for Fibre Channel cards.
1308 * It turns out that even for QLogic 2100s with ROM 1.10 and above
1309 * we do get a firmware attributes word returned in mailbox register 6.
1311 * Because the lun is in a different position in the Request Queue
1312 * Entry structure for Fibre Channel with expanded lun firmware, we
1313 * can only support one lun (lun zero) when we don't know what kind
1314 * of firmware we're running.
1318 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
1319 isp->isp_maxluns = 32;
1321 isp->isp_maxluns = 8;
1324 isp->isp_maxluns = 8;
1327 if (ISP_CAP_SCCFW(isp)) {
1328 isp->isp_maxluns = 0; /* No limit -- 2/8 bytes */
1330 isp->isp_maxluns = 16;
1335 * We get some default values established. As a side
1336 * effect, NVRAM is read here (unless overriden by
1337 * a configuration flag).
1339 if (do_load_defaults) {
1341 isp_setdfltsdparm(isp);
1343 for (i = 0; i < isp->isp_nchan; i++) {
1344 isp_setdfltfcparm(isp, i);
1351 * Clean firmware shutdown.
1354 isp_deinit(ispsoftc_t *isp)
1358 isp->isp_state = ISP_NILSTATE;
1359 MBSINIT(&mbs, MBOX_STOP_FIRMWARE, MBLOGALL, 500000);
1368 isp_mboxcmd(isp, &mbs);
1369 return (mbs.param[0] == MBOX_COMMAND_COMPLETE ? 0 : mbs.param[0]);
1373 * Initialize Parameters of Hardware to a known state.
1375 * Locks are held before coming here.
1378 isp_init(ispsoftc_t *isp)
1382 isp_fibre_init_2400(isp);
1384 isp_fibre_init(isp);
1389 GET_NANOTIME(&isp->isp_init_time);
1393 isp_scsi_init(ispsoftc_t *isp)
1395 sdparam *sdp_chan0, *sdp_chan1;
1398 isp->isp_state = ISP_INITSTATE;
1400 sdp_chan0 = SDPARAM(isp, 0);
1401 sdp_chan1 = sdp_chan0;
1402 if (IS_DUALBUS(isp)) {
1403 sdp_chan1 = SDPARAM(isp, 1);
1406 /* First do overall per-card settings. */
1409 * If we have fast memory timing enabled, turn it on.
1411 if (sdp_chan0->isp_fast_mttr) {
1412 ISP_WRITE(isp, RISC_MTR, 0x1313);
1416 * Set Retry Delay and Count.
1417 * You set both channels at the same time.
1419 MBSINIT(&mbs, MBOX_SET_RETRY_COUNT, MBLOGALL, 0);
1420 mbs.param[1] = sdp_chan0->isp_retry_count;
1421 mbs.param[2] = sdp_chan0->isp_retry_delay;
1422 mbs.param[6] = sdp_chan1->isp_retry_count;
1423 mbs.param[7] = sdp_chan1->isp_retry_delay;
1424 isp_mboxcmd(isp, &mbs);
1425 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1430 * Set ASYNC DATA SETUP time. This is very important.
1432 MBSINIT(&mbs, MBOX_SET_ASYNC_DATA_SETUP_TIME, MBLOGALL, 0);
1433 mbs.param[1] = sdp_chan0->isp_async_data_setup;
1434 mbs.param[2] = sdp_chan1->isp_async_data_setup;
1435 isp_mboxcmd(isp, &mbs);
1436 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1441 * Set ACTIVE Negation State.
1443 MBSINIT(&mbs, MBOX_SET_ACT_NEG_STATE, MBLOGNONE, 0);
1445 (sdp_chan0->isp_req_ack_active_neg << 4) |
1446 (sdp_chan0->isp_data_line_active_neg << 5);
1448 (sdp_chan1->isp_req_ack_active_neg << 4) |
1449 (sdp_chan1->isp_data_line_active_neg << 5);
1450 isp_mboxcmd(isp, &mbs);
1451 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1452 isp_prt(isp, ISP_LOGERR,
1453 "failed to set active negation state (%d,%d), (%d,%d)",
1454 sdp_chan0->isp_req_ack_active_neg,
1455 sdp_chan0->isp_data_line_active_neg,
1456 sdp_chan1->isp_req_ack_active_neg,
1457 sdp_chan1->isp_data_line_active_neg);
1464 * Set the Tag Aging limit
1466 MBSINIT(&mbs, MBOX_SET_TAG_AGE_LIMIT, MBLOGALL, 0);
1467 mbs.param[1] = sdp_chan0->isp_tag_aging;
1468 mbs.param[2] = sdp_chan1->isp_tag_aging;
1469 isp_mboxcmd(isp, &mbs);
1470 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1471 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
1472 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
1477 * Set selection timeout.
1479 MBSINIT(&mbs, MBOX_SET_SELECT_TIMEOUT, MBLOGALL, 0);
1480 mbs.param[1] = sdp_chan0->isp_selection_timeout;
1481 mbs.param[2] = sdp_chan1->isp_selection_timeout;
1482 isp_mboxcmd(isp, &mbs);
1483 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1487 /* now do per-channel settings */
1488 isp_scsi_channel_init(isp, 0);
1489 if (IS_DUALBUS(isp))
1490 isp_scsi_channel_init(isp, 1);
1493 * Now enable request/response queues
1496 if (IS_ULTRA2(isp) || IS_1240(isp)) {
1497 MBSINIT(&mbs, MBOX_INIT_RES_QUEUE_A64, MBLOGALL, 0);
1498 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1499 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1500 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1502 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1503 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1504 isp_mboxcmd(isp, &mbs);
1505 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1508 isp->isp_residx = isp->isp_resodx = mbs.param[5];
1510 MBSINIT(&mbs, MBOX_INIT_REQ_QUEUE_A64, MBLOGALL, 0);
1511 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1512 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1513 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1515 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1516 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1517 isp_mboxcmd(isp, &mbs);
1518 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1521 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1523 MBSINIT(&mbs, MBOX_INIT_RES_QUEUE, MBLOGALL, 0);
1524 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1525 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1526 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1528 isp_mboxcmd(isp, &mbs);
1529 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1532 isp->isp_residx = isp->isp_resodx = mbs.param[5];
1534 MBSINIT(&mbs, MBOX_INIT_REQ_QUEUE, MBLOGALL, 0);
1535 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1536 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1537 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1539 isp_mboxcmd(isp, &mbs);
1540 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1543 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1547 * Turn on LVD transitions for ULTRA2 or better and other features
1549 * Now that we have 32 bit handles, don't do any fast posting
1550 * any more. For Ultra2/Ultra3 cards, we can turn on 32 bit RIO
1551 * operation or use fast posting. To be conservative, we'll only
1552 * do this for Ultra3 cards now because the other cards are so
1553 * rare for this author to find and test with.
1556 MBSINIT(&mbs, MBOX_SET_FW_FEATURES, MBLOGALL, 0);
1558 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1561 mbs.param[1] |= FW_FEATURE_FAST_POST;
1564 mbs.param[1] |= FW_FEATURE_RIO_32BIT;
1566 if (mbs.param[1] != 0) {
1567 uint16_t sfeat = mbs.param[1];
1568 isp_mboxcmd(isp, &mbs);
1569 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1570 isp_prt(isp, ISP_LOGINFO,
1571 "Enabled FW features (0x%x)", sfeat);
1575 isp->isp_state = ISP_RUNSTATE;
1579 isp_scsi_channel_init(ispsoftc_t *isp, int chan)
1585 sdp = SDPARAM(isp, chan);
1588 * Set (possibly new) Initiator ID.
1590 MBSINIT(&mbs, MBOX_SET_INIT_SCSI_ID, MBLOGALL, 0);
1591 mbs.param[1] = (chan << 7) | sdp->isp_initiator_id;
1592 isp_mboxcmd(isp, &mbs);
1593 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1596 isp_prt(isp, ISP_LOGINFO, "Chan %d Initiator ID is %d",
1597 chan, sdp->isp_initiator_id);
1601 * Set current per-target parameters to an initial safe minimum.
1603 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1607 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1610 #ifndef ISP_TARGET_MODE
1611 sdf = sdp->isp_devparam[tgt].goal_flags;
1612 sdf &= DPARM_SAFE_DFLT;
1614 * It is not quite clear when this changed over so that
1615 * we could force narrow and async for 1000/1020 cards,
1616 * but assume that this is only the case for loaded
1619 if (isp->isp_loaded_fw) {
1620 sdf |= DPARM_NARROW | DPARM_ASYNC;
1624 * The !$*!)$!$)* f/w uses the same index into some
1625 * internal table to decide how to respond to negotiations,
1626 * so if we've said "let's be safe" for ID X, and ID X
1627 * selects *us*, the negotiations will back to 'safe'
1628 * (as in narrow/async). What the f/w *should* do is
1629 * use the initiator id settings to decide how to respond.
1631 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1633 MBSINIT(&mbs, MBOX_SET_TARGET_PARAMS, MBLOGNONE, 0);
1634 mbs.param[1] = (chan << 15) | (tgt << 8);
1636 if ((sdf & DPARM_SYNC) == 0) {
1640 (sdp->isp_devparam[tgt].goal_offset << 8) |
1641 (sdp->isp_devparam[tgt].goal_period);
1643 isp_prt(isp, ISP_LOGDEBUG0, "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1644 chan, tgt, mbs.param[2], mbs.param[3] >> 8, mbs.param[3] & 0xff);
1645 isp_mboxcmd(isp, &mbs);
1646 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1647 sdf = DPARM_SAFE_DFLT;
1648 MBSINIT(&mbs, MBOX_SET_TARGET_PARAMS, MBLOGALL, 0);
1649 mbs.param[1] = (tgt << 8) | (chan << 15);
1652 isp_mboxcmd(isp, &mbs);
1653 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1659 * We don't update any information directly from the f/w
1660 * because we need to run at least one command to cause a
1661 * new state to be latched up. So, we just assume that we
1662 * converge to the values we just had set.
1664 * Ensure that we don't believe tagged queuing is enabled yet.
1665 * It turns out that sometimes the ISP just ignores our
1666 * attempts to set parameters for devices that it hasn't
1669 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1670 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1671 MBSINIT(&mbs, MBOX_SET_DEV_QUEUE_PARAMS, MBLOGALL, 0);
1672 mbs.param[1] = (chan << 15) | (tgt << 8) | lun;
1673 mbs.param[2] = sdp->isp_max_queue_depth;
1674 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1675 isp_mboxcmd(isp, &mbs);
1676 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1681 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1682 if (sdp->isp_devparam[tgt].dev_refresh) {
1683 sdp->sendmarker = 1;
1691 * Fibre Channel specific initialization.
1694 isp_fibre_init(ispsoftc_t *isp)
1697 isp_icb_t local, *icbp = &local;
1701 * We only support one channel on non-24XX cards
1703 fcp = FCPARAM(isp, 0);
1704 if (fcp->role == ISP_ROLE_NONE)
1707 isp->isp_state = ISP_INITSTATE;
1708 ISP_MEMZERO(icbp, sizeof (*icbp));
1709 icbp->icb_version = ICB_VERSION1;
1710 icbp->icb_fwoptions = fcp->isp_fwoptions;
1713 * Firmware Options are either retrieved from NVRAM or
1714 * are patched elsewhere. We check them for sanity here
1715 * and make changes based on board revision, but otherwise
1716 * let others decide policy.
1720 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1722 if (IS_2100(isp) && isp->isp_revision < 5) {
1723 icbp->icb_fwoptions &= ~ICBOPT_FAIRNESS;
1727 * We have to use FULL LOGIN even though it resets the loop too much
1728 * because otherwise port database entries don't get updated after
1729 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1731 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1732 icbp->icb_fwoptions |= ICBOPT_FULL_LOGIN;
1736 * Insist on Port Database Update Async notifications
1738 icbp->icb_fwoptions |= ICBOPT_PDBCHANGE_AE;
1741 * Make sure that target role reflects into fwoptions.
1743 if (fcp->role & ISP_ROLE_TARGET) {
1744 icbp->icb_fwoptions |= ICBOPT_TGT_ENABLE;
1746 icbp->icb_fwoptions &= ~ICBOPT_TGT_ENABLE;
1750 * For some reason my 2200 does not generate ATIOs in target mode
1751 * if initiator is disabled. Extra logins are better then target
1752 * not working at all.
1754 if ((fcp->role & ISP_ROLE_INITIATOR) || IS_2100(isp) || IS_2200(isp)) {
1755 icbp->icb_fwoptions &= ~ICBOPT_INI_DISABLE;
1757 icbp->icb_fwoptions |= ICBOPT_INI_DISABLE;
1760 icbp->icb_maxfrmlen = DEFAULT_FRAMESIZE(isp);
1761 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN || icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1762 isp_prt(isp, ISP_LOGERR, "bad frame length (%d) from NVRAM- using %d", DEFAULT_FRAMESIZE(isp), ICB_DFLT_FRMLEN);
1763 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1765 icbp->icb_maxalloc = fcp->isp_maxalloc;
1766 if (icbp->icb_maxalloc < 1) {
1767 isp_prt(isp, ISP_LOGERR, "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1768 icbp->icb_maxalloc = 16;
1770 icbp->icb_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
1771 if (icbp->icb_execthrottle < 1) {
1772 isp_prt(isp, ISP_LOGERR, "bad execution throttle of %d- using %d", DEFAULT_EXEC_THROTTLE(isp), ICB_DFLT_THROTTLE);
1773 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1775 icbp->icb_retry_delay = fcp->isp_retry_delay;
1776 icbp->icb_retry_count = fcp->isp_retry_count;
1777 if (fcp->isp_loopid < LOCAL_LOOP_LIM) {
1778 icbp->icb_hardaddr = fcp->isp_loopid;
1779 if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
1780 icbp->icb_fwoptions |= ICBOPT_HARD_ADDRESS;
1782 icbp->icb_fwoptions |= ICBOPT_PREV_ADDRESS;
1786 * Right now we just set extended options to prefer point-to-point
1787 * over loop based upon some soft config options.
1789 * NB: for the 2300, ICBOPT_EXTENDED is required.
1793 * We can't have Fast Posting any more- we now
1794 * have 32 bit handles.
1796 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1797 } else if (IS_2200(isp) || IS_23XX(isp)) {
1798 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1800 icbp->icb_xfwoptions = fcp->isp_xfwoptions;
1802 if (ISP_CAP_FCTAPE(isp)) {
1803 if (isp->isp_confopts & ISP_CFG_NOFCTAPE)
1804 icbp->icb_xfwoptions &= ~ICBXOPT_FCTAPE;
1806 if (isp->isp_confopts & ISP_CFG_FCTAPE)
1807 icbp->icb_xfwoptions |= ICBXOPT_FCTAPE;
1809 if (icbp->icb_xfwoptions & ICBXOPT_FCTAPE) {
1810 icbp->icb_fwoptions &= ~ICBOPT_FULL_LOGIN; /* per documents */
1811 icbp->icb_xfwoptions |= ICBXOPT_FCTAPE_CCQ|ICBXOPT_FCTAPE_CONFIRM;
1812 FCPARAM(isp, 0)->fctape_enabled = 1;
1814 FCPARAM(isp, 0)->fctape_enabled = 0;
1817 icbp->icb_xfwoptions &= ~ICBXOPT_FCTAPE;
1818 FCPARAM(isp, 0)->fctape_enabled = 0;
1822 * Prefer or force Point-To-Point instead Loop?
1824 switch (isp->isp_confopts & ISP_CFG_PORT_PREF) {
1826 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1827 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1829 case ISP_CFG_NPORT_ONLY:
1830 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1831 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1833 case ISP_CFG_LPORT_ONLY:
1834 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1835 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1839 * Let NVRAM settings define it if they are sane
1841 switch (icbp->icb_xfwoptions & ICBXOPT_TOPO_MASK) {
1842 case ICBXOPT_PTP_2_LOOP:
1843 case ICBXOPT_PTP_ONLY:
1844 case ICBXOPT_LOOP_ONLY:
1845 case ICBXOPT_LOOP_2_PTP:
1848 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1849 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1855 * We can't have Fast Posting any more- we now
1856 * have 32 bit handles.
1858 * RIO seemed to have to much breakage.
1860 * Just opt for safety.
1862 icbp->icb_xfwoptions &= ~ICBXOPT_RIO_16BIT;
1863 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1866 * QLogic recommends that FAST Posting be turned
1867 * off for 23XX cards and instead allow the HBA
1868 * to write response queue entries and interrupt
1869 * after a delay (ZIO).
1871 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1872 if ((fcp->isp_xfwoptions & ICBXOPT_TIMER_MASK) == ICBXOPT_ZIO) {
1873 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1874 icbp->icb_idelaytimer = 10;
1876 icbp->icb_zfwoptions = fcp->isp_zfwoptions;
1877 if (isp->isp_confopts & ISP_CFG_1GB) {
1878 icbp->icb_zfwoptions &= ~ICBZOPT_RATE_MASK;
1879 icbp->icb_zfwoptions |= ICBZOPT_RATE_1GB;
1880 } else if (isp->isp_confopts & ISP_CFG_2GB) {
1881 icbp->icb_zfwoptions &= ~ICBZOPT_RATE_MASK;
1882 icbp->icb_zfwoptions |= ICBZOPT_RATE_2GB;
1884 switch (icbp->icb_zfwoptions & ICBZOPT_RATE_MASK) {
1885 case ICBZOPT_RATE_1GB:
1886 case ICBZOPT_RATE_2GB:
1887 case ICBZOPT_RATE_AUTO:
1890 icbp->icb_zfwoptions &= ~ICBZOPT_RATE_MASK;
1891 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1900 * For 22XX > 2.1.26 && 23XX, set some options.
1902 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1903 MBSINIT(&mbs, MBOX_SET_FIRMWARE_OPTIONS, MBLOGALL, 0);
1904 mbs.param[1] = IFCOPT1_DISF7SWTCH|IFCOPT1_LIPASYNC|IFCOPT1_LIPF8;
1907 if (ISP_FW_NEWER_THAN(isp, 3, 16, 0)) {
1908 mbs.param[1] |= IFCOPT1_EQFQASYNC|IFCOPT1_CTIO_RETRY;
1909 if (fcp->role & ISP_ROLE_TARGET) {
1910 if (ISP_FW_NEWER_THAN(isp, 3, 25, 0)) {
1911 mbs.param[1] |= IFCOPT1_ENAPURE;
1913 mbs.param[3] = IFCOPT3_NOPRLI;
1916 isp_mboxcmd(isp, &mbs);
1917 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1921 icbp->icb_logintime = ICB_LOGIN_TOV;
1923 #ifdef ISP_TARGET_MODE
1924 if (icbp->icb_fwoptions & ICBOPT_TGT_ENABLE) {
1925 icbp->icb_lunenables = 0xffff;
1926 icbp->icb_ccnt = 0xff;
1927 icbp->icb_icnt = 0xff;
1928 icbp->icb_lunetimeout = ICB_LUN_ENABLE_TOV;
1931 if (fcp->isp_wwnn && fcp->isp_wwpn) {
1932 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1933 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, fcp->isp_wwnn);
1934 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1935 isp_prt(isp, ISP_LOGDEBUG1,
1936 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1937 ((uint32_t) (fcp->isp_wwnn >> 32)),
1938 ((uint32_t) (fcp->isp_wwnn)),
1939 ((uint32_t) (fcp->isp_wwpn >> 32)),
1940 ((uint32_t) (fcp->isp_wwpn)));
1941 } else if (fcp->isp_wwpn) {
1942 icbp->icb_fwoptions &= ~ICBOPT_BOTH_WWNS;
1943 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1944 isp_prt(isp, ISP_LOGDEBUG1,
1945 "Setting ICB Port 0x%08x%08x",
1946 ((uint32_t) (fcp->isp_wwpn >> 32)),
1947 ((uint32_t) (fcp->isp_wwpn)));
1949 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
1952 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1953 if (icbp->icb_rqstqlen < 1) {
1954 isp_prt(isp, ISP_LOGERR, "bad request queue length");
1956 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1957 if (icbp->icb_rsltqlen < 1) {
1958 isp_prt(isp, ISP_LOGERR, "bad result queue length");
1960 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1961 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1962 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1963 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1964 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1965 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1966 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1967 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1969 if (FC_SCRATCH_ACQUIRE(isp, 0)) {
1970 isp_prt(isp, ISP_LOGERR, sacq);
1973 isp_prt(isp, ISP_LOGDEBUG0, "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1974 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1976 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1977 if (isp->isp_dblev & ISP_LOGDEBUG1) {
1978 isp_print_bytes(isp, "isp_fibre_init",
1979 sizeof(*icbp), fcp->isp_scratch);
1985 MBSINIT(&mbs, MBOX_INIT_FIRMWARE, MBLOGALL, 30000000);
1987 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1988 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1989 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1990 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1991 isp_prt(isp, ISP_LOGDEBUG0, "INIT F/W from %p (%08x%08x)",
1992 fcp->isp_scratch, (uint32_t) ((uint64_t)fcp->isp_scdma >> 32),
1993 (uint32_t) fcp->isp_scdma);
1994 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp), 0);
1995 isp_mboxcmd(isp, &mbs);
1996 FC_SCRATCH_RELEASE(isp, 0);
1997 if (mbs.param[0] != MBOX_COMMAND_COMPLETE)
1999 isp->isp_reqidx = 0;
2000 isp->isp_reqodx = 0;
2001 isp->isp_residx = 0;
2002 isp->isp_resodx = 0;
2005 * Whatever happens, we're now committed to being here.
2007 isp->isp_state = ISP_RUNSTATE;
2011 isp_fibre_init_2400(ispsoftc_t *isp)
2014 isp_icb_2400_t local, *icbp = &local;
2019 * Check to see whether all channels have *some* kind of role
2021 for (chan = 0; chan < isp->isp_nchan; chan++) {
2022 fcp = FCPARAM(isp, chan);
2023 if (fcp->role != ISP_ROLE_NONE) {
2027 if (chan == isp->isp_nchan) {
2028 isp_prt(isp, ISP_LOG_WARN1, "all %d channels with role 'none'", chan);
2032 isp->isp_state = ISP_INITSTATE;
2035 * Start with channel 0.
2037 fcp = FCPARAM(isp, 0);
2040 * Turn on LIP F8 async event (1)
2042 MBSINIT(&mbs, MBOX_SET_FIRMWARE_OPTIONS, MBLOGALL, 0);
2044 isp_mboxcmd(isp, &mbs);
2045 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2049 ISP_MEMZERO(icbp, sizeof (*icbp));
2050 icbp->icb_fwoptions1 = fcp->isp_fwoptions;
2051 icbp->icb_fwoptions2 = fcp->isp_xfwoptions;
2052 icbp->icb_fwoptions3 = fcp->isp_zfwoptions;
2053 if (isp->isp_nchan > 1 && ISP_CAP_VP0(isp)) {
2054 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_INI_DISABLE;
2055 icbp->icb_fwoptions1 |= ICB2400_OPT1_TGT_ENABLE;
2057 if (fcp->role & ISP_ROLE_TARGET)
2058 icbp->icb_fwoptions1 |= ICB2400_OPT1_TGT_ENABLE;
2060 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_TGT_ENABLE;
2061 if (fcp->role & ISP_ROLE_INITIATOR)
2062 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_INI_DISABLE;
2064 icbp->icb_fwoptions1 |= ICB2400_OPT1_INI_DISABLE;
2067 icbp->icb_version = ICB_VERSION1;
2068 icbp->icb_maxfrmlen = DEFAULT_FRAMESIZE(isp);
2069 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN || icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
2070 isp_prt(isp, ISP_LOGERR, "bad frame length (%d) from NVRAM- using %d", DEFAULT_FRAMESIZE(isp), ICB_DFLT_FRMLEN);
2071 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
2074 icbp->icb_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
2075 if (icbp->icb_execthrottle < 1) {
2076 isp_prt(isp, ISP_LOGERR, "bad execution throttle of %d- using %d", DEFAULT_EXEC_THROTTLE(isp), ICB_DFLT_THROTTLE);
2077 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
2081 * Set target exchange count. Take half if we are supporting both roles.
2083 if (icbp->icb_fwoptions1 & ICB2400_OPT1_TGT_ENABLE) {
2084 icbp->icb_xchgcnt = isp->isp_maxcmds;
2085 if ((icbp->icb_fwoptions1 & ICB2400_OPT1_INI_DISABLE) == 0)
2086 icbp->icb_xchgcnt >>= 1;
2089 if (fcp->isp_loopid < LOCAL_LOOP_LIM) {
2090 icbp->icb_hardaddr = fcp->isp_loopid;
2091 if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
2092 icbp->icb_fwoptions1 |= ICB2400_OPT1_HARD_ADDRESS;
2094 icbp->icb_fwoptions1 |= ICB2400_OPT1_PREV_ADDRESS;
2097 if (isp->isp_confopts & ISP_CFG_NOFCTAPE) {
2098 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_FCTAPE;
2100 if (isp->isp_confopts & ISP_CFG_FCTAPE) {
2101 icbp->icb_fwoptions2 |= ICB2400_OPT2_FCTAPE;
2104 for (chan = 0; chan < isp->isp_nchan; chan++) {
2105 if (icbp->icb_fwoptions2 & ICB2400_OPT2_FCTAPE)
2106 FCPARAM(isp, chan)->fctape_enabled = 1;
2108 FCPARAM(isp, chan)->fctape_enabled = 0;
2111 switch (isp->isp_confopts & ISP_CFG_PORT_PREF) {
2112 case ISP_CFG_NPORT_ONLY:
2113 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2114 icbp->icb_fwoptions2 |= ICB2400_OPT2_PTP_ONLY;
2116 case ISP_CFG_LPORT_ONLY:
2117 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2118 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_ONLY;
2121 /* ISP_CFG_PTP_2_LOOP not available in 24XX/25XX */
2122 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2123 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_2_PTP;
2127 switch (icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK) {
2128 case ICB2400_OPT2_ZIO:
2129 case ICB2400_OPT2_ZIO1:
2130 icbp->icb_idelaytimer = 0;
2135 isp_prt(isp, ISP_LOGWARN, "bad value %x in fwopt2 timer field", icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK);
2136 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TIMER_MASK;
2141 /* We don't support MSI-X yet, so set this unconditionally. */
2142 icbp->icb_fwoptions2 |= ICB2400_OPT2_ENA_IHR;
2143 icbp->icb_fwoptions2 |= ICB2400_OPT2_ENA_IHA;
2146 if ((icbp->icb_fwoptions3 & ICB2400_OPT3_RSPSZ_MASK) == 0) {
2147 icbp->icb_fwoptions3 |= ICB2400_OPT3_RSPSZ_24;
2149 if (isp->isp_confopts & ISP_CFG_1GB) {
2150 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2151 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_1GB;
2152 } else if (isp->isp_confopts & ISP_CFG_2GB) {
2153 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2154 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_2GB;
2155 } else if (isp->isp_confopts & ISP_CFG_4GB) {
2156 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2157 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_4GB;
2158 } else if (isp->isp_confopts & ISP_CFG_8GB) {
2159 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2160 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_8GB;
2161 } else if (isp->isp_confopts & ISP_CFG_16GB) {
2162 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2163 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_16GB;
2165 switch (icbp->icb_fwoptions3 & ICB2400_OPT3_RATE_MASK) {
2166 case ICB2400_OPT3_RATE_4GB:
2167 case ICB2400_OPT3_RATE_8GB:
2168 case ICB2400_OPT3_RATE_16GB:
2169 case ICB2400_OPT3_RATE_AUTO:
2171 case ICB2400_OPT3_RATE_2GB:
2172 if (isp->isp_type <= ISP_HA_FC_2500)
2175 case ICB2400_OPT3_RATE_1GB:
2176 if (isp->isp_type <= ISP_HA_FC_2400)
2180 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2181 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_AUTO;
2185 icbp->icb_logintime = ICB_LOGIN_TOV;
2187 if (fcp->isp_wwnn && fcp->isp_wwpn) {
2188 icbp->icb_fwoptions1 |= ICB2400_OPT1_BOTH_WWNS;
2189 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
2190 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, fcp->isp_wwnn);
2191 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)),
2192 ((uint32_t) (fcp->isp_wwpn >> 32)), ((uint32_t) (fcp->isp_wwpn)));
2193 } else if (fcp->isp_wwpn) {
2194 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_BOTH_WWNS;
2195 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
2196 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)));
2198 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
2201 icbp->icb_retry_count = fcp->isp_retry_count;
2203 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
2204 if (icbp->icb_rqstqlen < 8) {
2205 isp_prt(isp, ISP_LOGERR, "bad request queue length %d", icbp->icb_rqstqlen);
2208 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
2209 if (icbp->icb_rsltqlen < 8) {
2210 isp_prt(isp, ISP_LOGERR, "bad result queue length %d",
2211 icbp->icb_rsltqlen);
2214 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
2215 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
2216 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
2217 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
2219 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
2220 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
2221 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
2222 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
2224 #ifdef ISP_TARGET_MODE
2225 /* unconditionally set up the ATIO queue if we support target mode */
2226 icbp->icb_atioqlen = RESULT_QUEUE_LEN(isp);
2227 if (icbp->icb_atioqlen < 8) {
2228 isp_prt(isp, ISP_LOGERR, "bad ATIO queue length %d", icbp->icb_atioqlen);
2231 icbp->icb_atioqaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_atioq_dma);
2232 icbp->icb_atioqaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_atioq_dma);
2233 icbp->icb_atioqaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_atioq_dma);
2234 icbp->icb_atioqaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_atioq_dma);
2235 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),
2236 DMA_WD1(isp->isp_atioq_dma), DMA_WD0(isp->isp_atioq_dma));
2239 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);
2241 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),
2242 DMA_WD1(isp->isp_rquest_dma), DMA_WD0(isp->isp_rquest_dma), DMA_WD3(isp->isp_result_dma), DMA_WD2(isp->isp_result_dma),
2243 DMA_WD1(isp->isp_result_dma), DMA_WD0(isp->isp_result_dma));
2245 if (FC_SCRATCH_ACQUIRE(isp, 0)) {
2246 isp_prt(isp, ISP_LOGERR, sacq);
2249 ISP_MEMZERO(fcp->isp_scratch, ISP_FC_SCRLEN);
2250 isp_put_icb_2400(isp, icbp, fcp->isp_scratch);
2251 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2252 isp_print_bytes(isp, "isp_fibre_init_2400",
2253 sizeof (*icbp), fcp->isp_scratch);
2257 * Now fill in information about any additional channels
2259 if (isp->isp_nchan > 1) {
2260 isp_icb_2400_vpinfo_t vpinfo, *vdst;
2261 vp_port_info_t pi, *pdst;
2265 vpinfo.vp_global_options = ICB2400_VPGOPT_GEN_RIDA;
2266 if (ISP_CAP_VP0(isp)) {
2267 vpinfo.vp_global_options |= ICB2400_VPGOPT_VP0_DECOUPLE;
2268 vpinfo.vp_count = isp->isp_nchan;
2271 vpinfo.vp_count = isp->isp_nchan - 1;
2274 off = fcp->isp_scratch;
2275 off += ICB2400_VPINFO_OFF;
2276 vdst = (isp_icb_2400_vpinfo_t *) off;
2277 isp_put_icb_2400_vpinfo(isp, &vpinfo, vdst);
2278 amt = ICB2400_VPINFO_OFF + sizeof (isp_icb_2400_vpinfo_t);
2279 for (; chan < isp->isp_nchan; chan++) {
2282 ISP_MEMZERO(&pi, sizeof (pi));
2283 fcp2 = FCPARAM(isp, chan);
2284 if (fcp2->role != ISP_ROLE_NONE) {
2285 pi.vp_port_options = ICB2400_VPOPT_ENABLED |
2286 ICB2400_VPOPT_ENA_SNSLOGIN;
2287 if (fcp2->role & ISP_ROLE_INITIATOR)
2288 pi.vp_port_options |= ICB2400_VPOPT_INI_ENABLE;
2289 if ((fcp2->role & ISP_ROLE_TARGET) == 0)
2290 pi.vp_port_options |= ICB2400_VPOPT_TGT_DISABLE;
2292 if (fcp2->isp_loopid < LOCAL_LOOP_LIM) {
2293 pi.vp_port_loopid = fcp2->isp_loopid;
2294 if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
2295 pi.vp_port_options |= ICB2400_VPOPT_HARD_ADDRESS;
2297 pi.vp_port_options |= ICB2400_VPOPT_PREV_ADDRESS;
2299 MAKE_NODE_NAME_FROM_WWN(pi.vp_port_portname, fcp2->isp_wwpn);
2300 MAKE_NODE_NAME_FROM_WWN(pi.vp_port_nodename, fcp2->isp_wwnn);
2301 off = fcp->isp_scratch;
2302 if (ISP_CAP_VP0(isp))
2303 off += ICB2400_VPINFO_PORT_OFF(chan);
2305 off += ICB2400_VPINFO_PORT_OFF(chan - 1);
2306 pdst = (vp_port_info_t *) off;
2307 isp_put_vp_port_info(isp, &pi, pdst);
2308 amt += ICB2400_VPOPT_WRITE_SIZE;
2310 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2311 isp_print_bytes(isp, "isp_fibre_init_2400",
2312 amt - ICB2400_VPINFO_OFF,
2313 (char *)fcp->isp_scratch + ICB2400_VPINFO_OFF);
2320 MBSINIT(&mbs, 0, MBLOGALL, 30000000);
2321 if (isp->isp_nchan > 1) {
2322 mbs.param[0] = MBOX_INIT_FIRMWARE_MULTI_ID;
2324 mbs.param[0] = MBOX_INIT_FIRMWARE;
2327 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2328 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2329 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2330 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2331 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));
2332 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp), 0);
2333 isp_mboxcmd(isp, &mbs);
2334 FC_SCRATCH_RELEASE(isp, 0);
2336 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2339 isp->isp_reqidx = 0;
2340 isp->isp_reqodx = 0;
2341 isp->isp_residx = 0;
2342 isp->isp_resodx = 0;
2343 isp->isp_atioodx = 0;
2346 * Whatever happens, we're now committed to being here.
2348 isp->isp_state = ISP_RUNSTATE;
2352 isp_fc_enable_vp(ispsoftc_t *isp, int chan)
2354 fcparam *fcp = FCPARAM(isp, chan);
2357 uint8_t resp[QENTRY_LEN];
2359 /* Build a VP MODIFY command in memory */
2360 ISP_MEMZERO(&vp, sizeof(vp));
2361 vp.vp_mod_hdr.rqs_entry_type = RQSTYPE_VP_MODIFY;
2362 vp.vp_mod_hdr.rqs_entry_count = 1;
2364 vp.vp_mod_idx0 = chan;
2365 vp.vp_mod_cmd = VP_MODIFY_ENA;
2366 vp.vp_mod_ports[0].options = ICB2400_VPOPT_ENABLED |
2367 ICB2400_VPOPT_ENA_SNSLOGIN;
2368 if (fcp->role & ISP_ROLE_INITIATOR)
2369 vp.vp_mod_ports[0].options |= ICB2400_VPOPT_INI_ENABLE;
2370 if ((fcp->role & ISP_ROLE_TARGET) == 0)
2371 vp.vp_mod_ports[0].options |= ICB2400_VPOPT_TGT_DISABLE;
2372 if (fcp->isp_loopid < LOCAL_LOOP_LIM) {
2373 vp.vp_mod_ports[0].loopid = fcp->isp_loopid;
2374 if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
2375 vp.vp_mod_ports[0].options |= ICB2400_VPOPT_HARD_ADDRESS;
2377 vp.vp_mod_ports[0].options |= ICB2400_VPOPT_PREV_ADDRESS;
2379 MAKE_NODE_NAME_FROM_WWN(vp.vp_mod_ports[0].wwpn, fcp->isp_wwpn);
2380 MAKE_NODE_NAME_FROM_WWN(vp.vp_mod_ports[0].wwnn, fcp->isp_wwnn);
2382 /* Prepare space for response in memory */
2383 memset(resp, 0xff, sizeof(resp));
2384 vp.vp_mod_hdl = isp_allocate_handle(isp, resp, ISP_HANDLE_CTRL);
2385 if (vp.vp_mod_hdl == 0) {
2386 isp_prt(isp, ISP_LOGERR,
2387 "%s: VP_MODIFY of Chan %d out of handles", __func__, chan);
2391 /* Send request and wait for response. */
2392 reqp = isp_getrqentry(isp);
2394 isp_prt(isp, ISP_LOGERR,
2395 "%s: VP_MODIFY of Chan %d out of rqent", __func__, chan);
2396 isp_destroy_handle(isp, vp.vp_mod_hdl);
2399 isp_put_vp_modify(isp, &vp, (vp_modify_t *)reqp);
2400 if (isp->isp_dblev & ISP_LOGDEBUG1)
2401 isp_print_bytes(isp, "IOCB VP_MODIFY", QENTRY_LEN, reqp);
2402 ISP_SYNC_REQUEST(isp);
2403 if (msleep(resp, &isp->isp_lock, 0, "VP_MODIFY", 5*hz) == EWOULDBLOCK) {
2404 isp_prt(isp, ISP_LOGERR,
2405 "%s: VP_MODIFY of Chan %d timed out", __func__, chan);
2406 isp_destroy_handle(isp, vp.vp_mod_hdl);
2409 if (isp->isp_dblev & ISP_LOGDEBUG1)
2410 isp_print_bytes(isp, "IOCB VP_MODIFY response", QENTRY_LEN, resp);
2411 isp_get_vp_modify(isp, (vp_modify_t *)resp, &vp);
2413 if (vp.vp_mod_hdr.rqs_flags != 0 || vp.vp_mod_status != VP_STS_OK) {
2414 isp_prt(isp, ISP_LOGERR,
2415 "%s: VP_MODIFY of Chan %d failed with flags %x status %d",
2416 __func__, chan, vp.vp_mod_hdr.rqs_flags, vp.vp_mod_status);
2423 isp_fc_disable_vp(ispsoftc_t *isp, int chan)
2427 uint8_t resp[QENTRY_LEN];
2429 /* Build a VP CTRL command in memory */
2430 ISP_MEMZERO(&vp, sizeof(vp));
2431 vp.vp_ctrl_hdr.rqs_entry_type = RQSTYPE_VP_CTRL;
2432 vp.vp_ctrl_hdr.rqs_entry_count = 1;
2433 if (ISP_CAP_VP0(isp)) {
2434 vp.vp_ctrl_status = 1;
2436 vp.vp_ctrl_status = 0;
2437 chan--; /* VP0 can not be controlled in this case. */
2439 vp.vp_ctrl_command = VP_CTRL_CMD_DISABLE_VP_LOGO_ALL;
2440 vp.vp_ctrl_vp_count = 1;
2441 vp.vp_ctrl_idmap[chan / 16] |= (1 << chan % 16);
2443 /* Prepare space for response in memory */
2444 memset(resp, 0xff, sizeof(resp));
2445 vp.vp_ctrl_handle = isp_allocate_handle(isp, resp, ISP_HANDLE_CTRL);
2446 if (vp.vp_ctrl_handle == 0) {
2447 isp_prt(isp, ISP_LOGERR,
2448 "%s: VP_CTRL of Chan %d out of handles", __func__, chan);
2452 /* Send request and wait for response. */
2453 reqp = isp_getrqentry(isp);
2455 isp_prt(isp, ISP_LOGERR,
2456 "%s: VP_CTRL of Chan %d out of rqent", __func__, chan);
2457 isp_destroy_handle(isp, vp.vp_ctrl_handle);
2460 isp_put_vp_ctrl_info(isp, &vp, (vp_ctrl_info_t *)reqp);
2461 if (isp->isp_dblev & ISP_LOGDEBUG1)
2462 isp_print_bytes(isp, "IOCB VP_CTRL", QENTRY_LEN, reqp);
2463 ISP_SYNC_REQUEST(isp);
2464 if (msleep(resp, &isp->isp_lock, 0, "VP_CTRL", 5*hz) == EWOULDBLOCK) {
2465 isp_prt(isp, ISP_LOGERR,
2466 "%s: VP_CTRL of Chan %d timed out", __func__, chan);
2467 isp_destroy_handle(isp, vp.vp_ctrl_handle);
2470 if (isp->isp_dblev & ISP_LOGDEBUG1)
2471 isp_print_bytes(isp, "IOCB VP_CTRL response", QENTRY_LEN, resp);
2472 isp_get_vp_ctrl_info(isp, (vp_ctrl_info_t *)resp, &vp);
2474 if (vp.vp_ctrl_hdr.rqs_flags != 0 || vp.vp_ctrl_status != 0) {
2475 isp_prt(isp, ISP_LOGERR,
2476 "%s: VP_CTRL of Chan %d failed with flags %x status %d %d",
2477 __func__, chan, vp.vp_ctrl_hdr.rqs_flags,
2478 vp.vp_ctrl_status, vp.vp_ctrl_index_fail);
2485 isp_fc_change_role(ispsoftc_t *isp, int chan, int new_role)
2487 fcparam *fcp = FCPARAM(isp, chan);
2488 int i, was, res = 0;
2490 if (chan >= isp->isp_nchan) {
2491 isp_prt(isp, ISP_LOGWARN, "%s: bad channel %d", __func__, chan);
2494 if (fcp->role == new_role)
2496 for (was = 0, i = 0; i < isp->isp_nchan; i++) {
2497 if (FCPARAM(isp, i)->role != ISP_ROLE_NONE)
2500 if (was == 0 || (was == 1 && fcp->role != ISP_ROLE_NONE)) {
2501 fcp->role = new_role;
2502 return (isp_reinit(isp, 0));
2504 if (fcp->role != ISP_ROLE_NONE) {
2505 res = isp_fc_disable_vp(isp, chan);
2506 isp_clear_portdb(isp, chan);
2508 fcp->role = new_role;
2509 if (fcp->role != ISP_ROLE_NONE)
2510 res = isp_fc_enable_vp(isp, chan);
2515 isp_clear_portdb(ispsoftc_t *isp, int chan)
2517 fcparam *fcp = FCPARAM(isp, chan);
2521 for (i = 0; i < MAX_FC_TARG; i++) {
2522 lp = &fcp->portdb[i];
2523 switch (lp->state) {
2524 case FC_PORTDB_STATE_DEAD:
2525 case FC_PORTDB_STATE_CHANGED:
2526 case FC_PORTDB_STATE_VALID:
2527 lp->state = FC_PORTDB_STATE_NIL;
2528 isp_async(isp, ISPASYNC_DEV_GONE, chan, lp);
2530 case FC_PORTDB_STATE_NIL:
2531 case FC_PORTDB_STATE_NEW:
2532 lp->state = FC_PORTDB_STATE_NIL;
2534 case FC_PORTDB_STATE_ZOMBIE:
2537 panic("Don't know how to clear state %d\n", lp->state);
2543 isp_mark_portdb(ispsoftc_t *isp, int chan)
2545 fcparam *fcp = FCPARAM(isp, chan);
2549 for (i = 0; i < MAX_FC_TARG; i++) {
2550 lp = &fcp->portdb[i];
2551 if (lp->state == FC_PORTDB_STATE_NIL)
2553 if (lp->portid >= DOMAIN_CONTROLLER_BASE &&
2554 lp->portid <= DOMAIN_CONTROLLER_END)
2556 fcp->portdb[i].probational = 1;
2561 * Perform an IOCB PLOGI or LOGO via EXECUTE IOCB A64 for 24XX cards
2562 * or via FABRIC LOGIN/FABRIC LOGOUT for other cards.
2565 isp_plogx(ispsoftc_t *isp, int chan, uint16_t handle, uint32_t portid, int flags)
2569 uint8_t resp[QENTRY_LEN];
2570 uint32_t sst, parm1;
2575 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d PLOGX %s PortID 0x%06x nphdl 0x%x",
2576 chan, (flags & PLOGX_FLG_CMD_MASK) == PLOGX_FLG_CMD_PLOGI ?
2577 "Login":"Logout", portid, handle);
2578 if (!IS_24XX(isp)) {
2579 int action = flags & PLOGX_FLG_CMD_MASK;
2580 if (action == PLOGX_FLG_CMD_PLOGI) {
2581 return (isp_port_login(isp, handle, portid));
2582 } else if (action == PLOGX_FLG_CMD_LOGO) {
2583 return (isp_port_logout(isp, handle, portid));
2585 return (MBOX_INVALID_COMMAND);
2589 ISP_MEMZERO(&pl, sizeof(pl));
2590 pl.plogx_header.rqs_entry_count = 1;
2591 pl.plogx_header.rqs_entry_type = RQSTYPE_LOGIN;
2592 pl.plogx_nphdl = handle;
2593 pl.plogx_vphdl = chan;
2594 pl.plogx_portlo = portid;
2595 pl.plogx_rspsz_porthi = (portid >> 16) & 0xff;
2596 pl.plogx_flags = flags;
2598 /* Prepare space for response in memory */
2599 memset(resp, 0xff, sizeof(resp));
2600 pl.plogx_handle = isp_allocate_handle(isp, resp, ISP_HANDLE_CTRL);
2601 if (pl.plogx_handle == 0) {
2602 isp_prt(isp, ISP_LOGERR,
2603 "%s: PLOGX of Chan %d out of handles", __func__, chan);
2607 /* Send request and wait for response. */
2608 reqp = isp_getrqentry(isp);
2610 isp_prt(isp, ISP_LOGERR,
2611 "%s: PLOGX of Chan %d out of rqent", __func__, chan);
2612 isp_destroy_handle(isp, pl.plogx_handle);
2615 isp_put_plogx(isp, &pl, (isp_plogx_t *)reqp);
2616 if (isp->isp_dblev & ISP_LOGDEBUG1)
2617 isp_print_bytes(isp, "IOCB LOGX", QENTRY_LEN, reqp);
2618 ISP_SYNC_REQUEST(isp);
2619 if (msleep(resp, &isp->isp_lock, 0, "PLOGX", 3 * ICB_LOGIN_TOV * hz)
2621 isp_prt(isp, ISP_LOGERR,
2622 "%s: PLOGX of Chan %d timed out", __func__, chan);
2623 isp_destroy_handle(isp, pl.plogx_handle);
2626 if (isp->isp_dblev & ISP_LOGDEBUG1)
2627 isp_print_bytes(isp, "IOCB LOGX response", QENTRY_LEN, resp);
2628 isp_get_plogx(isp, (isp_plogx_t *)resp, &pl);
2630 if (pl.plogx_status == PLOGX_STATUS_OK) {
2632 } else if (pl.plogx_status != PLOGX_STATUS_IOCBERR) {
2633 isp_prt(isp, ISP_LOGWARN,
2634 "status 0x%x on port login IOCB channel %d",
2635 pl.plogx_status, chan);
2639 sst = pl.plogx_ioparm[0].lo16 | (pl.plogx_ioparm[0].hi16 << 16);
2640 parm1 = pl.plogx_ioparm[1].lo16 | (pl.plogx_ioparm[1].hi16 << 16);
2647 case PLOGX_IOCBERR_NOLINK:
2650 case PLOGX_IOCBERR_NOIOCB:
2651 msg = "no IOCB buffer";
2653 case PLOGX_IOCBERR_NOXGHG:
2654 msg = "no Exchange Control Block";
2656 case PLOGX_IOCBERR_FAILED:
2657 ISP_SNPRINTF(buf, sizeof (buf), "reason 0x%x (last LOGIN state 0x%x)", parm1 & 0xff, (parm1 >> 8) & 0xff);
2660 case PLOGX_IOCBERR_NOFABRIC:
2663 case PLOGX_IOCBERR_NOTREADY:
2664 msg = "firmware not ready";
2666 case PLOGX_IOCBERR_NOLOGIN:
2667 ISP_SNPRINTF(buf, sizeof (buf), "not logged in (last state 0x%x)", parm1);
2669 rval = MBOX_NOT_LOGGED_IN;
2671 case PLOGX_IOCBERR_REJECT:
2672 ISP_SNPRINTF(buf, sizeof (buf), "LS_RJT = 0x%x", parm1);
2675 case PLOGX_IOCBERR_NOPCB:
2676 msg = "no PCB allocated";
2678 case PLOGX_IOCBERR_EINVAL:
2679 ISP_SNPRINTF(buf, sizeof (buf), "invalid parameter at offset 0x%x", parm1);
2682 case PLOGX_IOCBERR_PORTUSED:
2683 lev = ISP_LOG_SANCFG|ISP_LOG_WARN1;
2684 ISP_SNPRINTF(buf, sizeof (buf), "already logged in with N-Port handle 0x%x", parm1);
2686 rval = MBOX_PORT_ID_USED | (parm1 << 16);
2688 case PLOGX_IOCBERR_HNDLUSED:
2689 lev = ISP_LOG_SANCFG|ISP_LOG_WARN1;
2690 ISP_SNPRINTF(buf, sizeof (buf), "handle already used for PortID 0x%06x", parm1);
2692 rval = MBOX_LOOP_ID_USED;
2694 case PLOGX_IOCBERR_NOHANDLE:
2695 msg = "no handle allocated";
2697 case PLOGX_IOCBERR_NOFLOGI:
2698 msg = "no FLOGI_ACC";
2701 ISP_SNPRINTF(buf, sizeof (buf), "status %x from %x", pl.plogx_status, flags);
2706 isp_prt(isp, ISP_LOGERR, "Chan %d PLOGX PortID 0x%06x to N-Port handle 0x%x: %s", chan, portid, handle, msg);
2712 isp_port_login(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2716 MBSINIT(&mbs, MBOX_FABRIC_LOGIN, MBLOGNONE, 500000);
2717 if (ISP_CAP_2KLOGIN(isp)) {
2718 mbs.param[1] = handle;
2719 mbs.ibits = (1 << 10);
2721 mbs.param[1] = handle << 8;
2723 mbs.param[2] = portid >> 16;
2724 mbs.param[3] = portid;
2725 mbs.logval = MBLOGNONE;
2726 mbs.timeout = 500000;
2727 isp_mboxcmd(isp, &mbs);
2729 switch (mbs.param[0]) {
2730 case MBOX_PORT_ID_USED:
2731 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]);
2732 return (MBOX_PORT_ID_USED | (mbs.param[1] << 16));
2734 case MBOX_LOOP_ID_USED:
2735 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);
2736 return (MBOX_LOOP_ID_USED);
2738 case MBOX_COMMAND_COMPLETE:
2741 case MBOX_COMMAND_ERROR:
2742 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);
2743 return (MBOX_COMMAND_ERROR);
2745 case MBOX_ALL_IDS_USED:
2746 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "isp_port_login: all IDs used for fabric login");
2747 return (MBOX_ALL_IDS_USED);
2750 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);
2751 return (mbs.param[0]);
2756 * Pre-24XX fabric port logout
2758 * Note that portid is not used
2761 isp_port_logout(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2765 MBSINIT(&mbs, MBOX_FABRIC_LOGOUT, MBLOGNONE, 500000);
2766 if (ISP_CAP_2KLOGIN(isp)) {
2767 mbs.param[1] = handle;
2768 mbs.ibits = (1 << 10);
2770 mbs.param[1] = handle << 8;
2772 isp_mboxcmd(isp, &mbs);
2773 return (mbs.param[0] == MBOX_COMMAND_COMPLETE? 0 : mbs.param[0]);
2777 isp_getpdb(ispsoftc_t *isp, int chan, uint16_t id, isp_pdb_t *pdb)
2779 fcparam *fcp = FCPARAM(isp, chan);
2782 isp_pdb_21xx_t fred;
2783 isp_pdb_24xx_t bill;
2786 MBSINIT(&mbs, MBOX_GET_PORT_DB,
2787 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_PARAM_ERROR), 250000);
2789 mbs.ibits = (1 << 9)|(1 << 10);
2791 mbs.param[9] = chan;
2792 } else if (ISP_CAP_2KLOGIN(isp)) {
2795 mbs.param[1] = id << 8;
2797 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2798 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2799 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2800 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2801 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
2802 isp_prt(isp, ISP_LOGERR, sacq);
2805 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof(un), chan);
2806 isp_mboxcmd(isp, &mbs);
2807 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2808 FC_SCRATCH_RELEASE(isp, chan);
2809 return (mbs.param[0] | (mbs.param[1] << 16));
2811 MEMORYBARRIER(isp, SYNC_SFORCPU, 0, sizeof(un), chan);
2813 isp_get_pdb_24xx(isp, fcp->isp_scratch, &un.bill);
2814 pdb->handle = un.bill.pdb_handle;
2815 pdb->prli_word3 = un.bill.pdb_prli_svc3;
2816 pdb->portid = BITS2WORD_24XX(un.bill.pdb_portid_bits);
2817 ISP_MEMCPY(pdb->portname, un.bill.pdb_portname, 8);
2818 ISP_MEMCPY(pdb->nodename, un.bill.pdb_nodename, 8);
2819 isp_prt(isp, ISP_LOGDEBUG1,
2820 "Chan %d handle 0x%x Port 0x%06x flags 0x%x curstate %x",
2821 chan, id, pdb->portid, un.bill.pdb_flags,
2822 un.bill.pdb_curstate);
2823 if (un.bill.pdb_curstate < PDB2400_STATE_PLOGI_DONE || un.bill.pdb_curstate > PDB2400_STATE_LOGGED_IN) {
2824 mbs.param[0] = MBOX_NOT_LOGGED_IN;
2825 FC_SCRATCH_RELEASE(isp, chan);
2826 return (mbs.param[0]);
2829 isp_get_pdb_21xx(isp, fcp->isp_scratch, &un.fred);
2830 pdb->handle = un.fred.pdb_loopid;
2831 pdb->prli_word3 = un.fred.pdb_prli_svc3;
2832 pdb->portid = BITS2WORD(un.fred.pdb_portid_bits);
2833 ISP_MEMCPY(pdb->portname, un.fred.pdb_portname, 8);
2834 ISP_MEMCPY(pdb->nodename, un.fred.pdb_nodename, 8);
2835 isp_prt(isp, ISP_LOGDEBUG1,
2836 "Chan %d handle 0x%x Port 0x%06x", chan, id, pdb->portid);
2838 FC_SCRATCH_RELEASE(isp, chan);
2843 isp_gethandles(ispsoftc_t *isp, int chan, uint16_t *handles, int *num, int loop)
2845 fcparam *fcp = FCPARAM(isp, chan);
2847 isp_pnhle_21xx_t el1, *elp1;
2848 isp_pnhle_23xx_t el3, *elp3;
2849 isp_pnhle_24xx_t el4, *elp4;
2854 MBSINIT(&mbs, MBOX_GET_ID_LIST, MBLOGALL, 250000);
2856 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2857 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2858 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2859 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2860 mbs.param[8] = ISP_FC_SCRLEN;
2861 mbs.param[9] = chan;
2863 mbs.ibits = (1 << 1)|(1 << 2)|(1 << 3)|(1 << 6);
2864 mbs.param[1] = DMA_WD1(fcp->isp_scdma);
2865 mbs.param[2] = DMA_WD0(fcp->isp_scdma);
2866 mbs.param[3] = DMA_WD3(fcp->isp_scdma);
2867 mbs.param[6] = DMA_WD2(fcp->isp_scdma);
2869 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
2870 isp_prt(isp, ISP_LOGERR, sacq);
2873 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, ISP_FC_SCRLEN, chan);
2874 isp_mboxcmd(isp, &mbs);
2875 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2876 FC_SCRATCH_RELEASE(isp, chan);
2877 return (mbs.param[0] | (mbs.param[1] << 16));
2879 MEMORYBARRIER(isp, SYNC_SFORCPU, 0, ISP_FC_SCRLEN, chan);
2880 elp1 = fcp->isp_scratch;
2881 elp3 = fcp->isp_scratch;
2882 elp4 = fcp->isp_scratch;
2883 for (i = 0, j = 0; i < mbs.param[1] && j < *num; i++) {
2885 isp_get_pnhle_24xx(isp, &elp4[i], &el4);
2886 p = el4.pnhle_port_id_lo |
2887 (el4.pnhle_port_id_hi << 16);
2888 h = el4.pnhle_handle;
2889 } else if (IS_23XX(isp)) {
2890 isp_get_pnhle_23xx(isp, &elp3[i], &el3);
2891 p = el3.pnhle_port_id_lo |
2892 (el3.pnhle_port_id_hi << 16);
2893 h = el3.pnhle_handle;
2895 isp_get_pnhle_21xx(isp, &elp1[i], &el1);
2896 p = el1.pnhle_port_id_lo |
2897 ((el1.pnhle_port_id_hi_handle & 0xff) << 16);
2898 h = el1.pnhle_port_id_hi_handle >> 8;
2900 if (loop && (p >> 8) != (fcp->isp_portid >> 8))
2905 FC_SCRATCH_RELEASE(isp, chan);
2910 isp_dump_chip_portdb(ispsoftc_t *isp, int chan)
2913 uint16_t lim, nphdl;
2915 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGINFO, "Chan %d chip port dump", chan);
2916 if (ISP_CAP_2KLOGIN(isp)) {
2921 for (nphdl = 0; nphdl != lim; nphdl++) {
2922 if (isp_getpdb(isp, chan, nphdl, &pdb)) {
2925 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGINFO, "Chan %d Handle 0x%04x "
2926 "PortID 0x%06x WWPN 0x%02x%02x%02x%02x%02x%02x%02x%02x",
2927 chan, nphdl, pdb.portid, pdb.portname[0], pdb.portname[1],
2928 pdb.portname[2], pdb.portname[3], pdb.portname[4],
2929 pdb.portname[5], pdb.portname[6], pdb.portname[7]);
2934 isp_get_wwn(ispsoftc_t *isp, int chan, int nphdl, int nodename)
2936 uint64_t wwn = INI_NONE;
2939 MBSINIT(&mbs, MBOX_GET_PORT_NAME,
2940 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_PARAM_ERROR), 500000);
2941 if (ISP_CAP_2KLOGIN(isp)) {
2942 mbs.param[1] = nphdl;
2946 mbs.param[9] = chan;
2949 mbs.param[1] = nphdl << 8;
2954 isp_mboxcmd(isp, &mbs);
2955 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2960 (((uint64_t)(mbs.param[2] >> 8)) << 56) |
2961 (((uint64_t)(mbs.param[2] & 0xff)) << 48) |
2962 (((uint64_t)(mbs.param[3] >> 8)) << 40) |
2963 (((uint64_t)(mbs.param[3] & 0xff)) << 32) |
2964 (((uint64_t)(mbs.param[6] >> 8)) << 24) |
2965 (((uint64_t)(mbs.param[6] & 0xff)) << 16) |
2966 (((uint64_t)(mbs.param[7] >> 8)) << 8) |
2967 (((uint64_t)(mbs.param[7] & 0xff)));
2970 (((uint64_t)(mbs.param[2] & 0xff)) << 56) |
2971 (((uint64_t)(mbs.param[2] >> 8)) << 48) |
2972 (((uint64_t)(mbs.param[3] & 0xff)) << 40) |
2973 (((uint64_t)(mbs.param[3] >> 8)) << 32) |
2974 (((uint64_t)(mbs.param[6] & 0xff)) << 24) |
2975 (((uint64_t)(mbs.param[6] >> 8)) << 16) |
2976 (((uint64_t)(mbs.param[7] & 0xff)) << 8) |
2977 (((uint64_t)(mbs.param[7] >> 8)));
2983 * Make sure we have good FC link.
2987 isp_fclink_test(ispsoftc_t *isp, int chan, int usdelay)
2994 NANOTIME_T hra, hrb;
2996 fcp = FCPARAM(isp, chan);
2998 if (fcp->isp_loopstate < LOOP_HAVE_LINK)
3000 if (fcp->isp_loopstate >= LOOP_LTEST_DONE)
3003 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC link test", chan);
3004 fcp->isp_loopstate = LOOP_TESTING_LINK;
3007 * Wait up to N microseconds for F/W to go to a ready state.
3011 isp_change_fw_state(isp, chan, isp_fw_state(isp, chan));
3012 if (fcp->isp_fwstate == FW_READY) {
3015 if (fcp->isp_loopstate < LOOP_TESTING_LINK)
3018 if ((NANOTIME_SUB(&hrb, &hra) / 1000 + 1000 >= usdelay))
3020 ISP_SLEEP(isp, 1000);
3022 if (fcp->isp_fwstate != FW_READY) {
3023 isp_prt(isp, ISP_LOG_SANCFG,
3024 "Chan %d Firmware is not ready (%s)",
3025 chan, isp_fc_fw_statename(fcp->isp_fwstate));
3030 * Get our Loop ID and Port ID.
3032 MBSINIT(&mbs, MBOX_GET_LOOP_ID, MBLOGALL, 0);
3033 mbs.param[9] = chan;
3034 isp_mboxcmd(isp, &mbs);
3035 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3041 * Don't bother with fabric if we are using really old
3042 * 2100 firmware. It's just not worth it.
3044 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37))
3045 fcp->isp_topo = TOPO_FL_PORT;
3047 fcp->isp_topo = TOPO_NL_PORT;
3049 int topo = (int) mbs.param[6];
3050 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB) {
3051 topo = TOPO_PTP_STUB;
3053 fcp->isp_topo = topo;
3055 fcp->isp_portid = mbs.param[2] | (mbs.param[3] << 16);
3057 if (!TOPO_IS_FABRIC(fcp->isp_topo)) {
3058 fcp->isp_loopid = mbs.param[1] & 0xff;
3059 } else if (fcp->isp_topo != TOPO_F_PORT) {
3060 uint8_t alpa = fcp->isp_portid;
3062 for (i = 0; alpa_map[i]; i++) {
3063 if (alpa_map[i] == alpa)
3067 fcp->isp_loopid = i;
3070 if (fcp->isp_topo == TOPO_F_PORT || fcp->isp_topo == TOPO_FL_PORT) {
3071 nphdl = IS_24XX(isp) ? NPH_FL_ID : FL_ID;
3072 r = isp_getpdb(isp, chan, nphdl, &pdb);
3073 if (r != 0 || pdb.portid == 0) {
3075 fcp->isp_topo = TOPO_NL_PORT;
3077 isp_prt(isp, ISP_LOGWARN,
3078 "fabric topology, but cannot get info about fabric controller (0x%x)", r);
3079 fcp->isp_topo = TOPO_PTP_STUB;
3085 fcp->isp_fabric_params = mbs.param[7];
3086 fcp->isp_sns_hdl = NPH_SNS_ID;
3087 r = isp_register_fc4_type_24xx(isp, chan);
3089 isp_register_fc4_features_24xx(isp, chan);
3090 isp_register_port_name_24xx(isp, chan);
3091 isp_register_node_name_24xx(isp, chan);
3093 fcp->isp_sns_hdl = SNS_ID;
3094 r = isp_register_fc4_type(isp, chan);
3095 if (r == 0 && fcp->role == ISP_ROLE_TARGET)
3096 isp_send_change_request(isp, chan);
3099 isp_prt(isp, ISP_LOGWARN|ISP_LOG_SANCFG, "%s: register fc4 type failed", __func__);
3105 /* Get link speed. */
3106 fcp->isp_gbspeed = 1;
3107 if (IS_23XX(isp) || IS_24XX(isp)) {
3108 MBSINIT(&mbs, MBOX_GET_SET_DATA_RATE, MBLOGALL, 3000000);
3109 mbs.param[1] = MBGSD_GET_RATE;
3110 /* mbs.param[2] undefined if we're just getting rate */
3111 isp_mboxcmd(isp, &mbs);
3112 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3113 if (mbs.param[1] == MBGSD_10GB)
3114 fcp->isp_gbspeed = 10;
3115 else if (mbs.param[1] == MBGSD_16GB)
3116 fcp->isp_gbspeed = 16;
3117 else if (mbs.param[1] == MBGSD_8GB)
3118 fcp->isp_gbspeed = 8;
3119 else if (mbs.param[1] == MBGSD_4GB)
3120 fcp->isp_gbspeed = 4;
3121 else if (mbs.param[1] == MBGSD_2GB)
3122 fcp->isp_gbspeed = 2;
3123 else if (mbs.param[1] == MBGSD_1GB)
3124 fcp->isp_gbspeed = 1;
3128 if (fcp->isp_loopstate < LOOP_TESTING_LINK) {
3130 isp_prt(isp, ISP_LOG_SANCFG,
3131 "Chan %d FC link test aborted", chan);
3134 fcp->isp_loopstate = LOOP_LTEST_DONE;
3135 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGCONFIG,
3136 "Chan %d WWPN %016jx WWNN %016jx",
3137 chan, (uintmax_t)fcp->isp_wwpn, (uintmax_t)fcp->isp_wwnn);
3138 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGCONFIG,
3139 "Chan %d %dGb %s PortID 0x%06x LoopID 0x%02x",
3140 chan, fcp->isp_gbspeed, isp_fc_toponame(fcp), fcp->isp_portid,
3142 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC link test done", chan);
3147 * Complete the synchronization of our Port Database.
3149 * At this point, we've scanned the local loop (if any) and the fabric
3150 * and performed fabric logins on all new devices.
3152 * Our task here is to go through our port database removing any entities
3153 * that are still marked probational (issuing PLOGO for ones which we had
3154 * PLOGI'd into) or are dead, and notifying upper layers about new/changed
3158 isp_pdb_sync(ispsoftc_t *isp, int chan)
3160 fcparam *fcp = FCPARAM(isp, chan);
3164 if (fcp->isp_loopstate < LOOP_FSCAN_DONE)
3166 if (fcp->isp_loopstate >= LOOP_READY)
3169 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC PDB sync", chan);
3171 fcp->isp_loopstate = LOOP_SYNCING_PDB;
3173 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
3174 lp = &fcp->portdb[dbidx];
3176 if (lp->state == FC_PORTDB_STATE_NIL)
3178 if (lp->probational && lp->state != FC_PORTDB_STATE_ZOMBIE)
3179 lp->state = FC_PORTDB_STATE_DEAD;
3180 switch (lp->state) {
3181 case FC_PORTDB_STATE_DEAD:
3182 lp->state = FC_PORTDB_STATE_NIL;
3183 isp_async(isp, ISPASYNC_DEV_GONE, chan, lp);
3184 if (lp->autologin == 0) {
3185 (void) isp_plogx(isp, chan, lp->handle,
3187 PLOGX_FLG_CMD_LOGO |
3188 PLOGX_FLG_IMPLICIT |
3189 PLOGX_FLG_FREE_NPHDL);
3192 * Note that we might come out of this with our state
3193 * set to FC_PORTDB_STATE_ZOMBIE.
3196 case FC_PORTDB_STATE_NEW:
3197 lp->state = FC_PORTDB_STATE_VALID;
3198 isp_async(isp, ISPASYNC_DEV_ARRIVED, chan, lp);
3200 case FC_PORTDB_STATE_CHANGED:
3201 lp->state = FC_PORTDB_STATE_VALID;
3202 isp_async(isp, ISPASYNC_DEV_CHANGED, chan, lp);
3203 lp->portid = lp->new_portid;
3204 lp->prli_word3 = lp->new_prli_word3;
3206 case FC_PORTDB_STATE_VALID:
3207 isp_async(isp, ISPASYNC_DEV_STAYED, chan, lp);
3209 case FC_PORTDB_STATE_ZOMBIE:
3212 isp_prt(isp, ISP_LOGWARN,
3213 "isp_pdb_sync: state %d for idx %d",
3215 isp_dump_portdb(isp, chan);
3219 if (fcp->isp_loopstate < LOOP_SYNCING_PDB) {
3220 isp_prt(isp, ISP_LOG_SANCFG,
3221 "Chan %d FC PDB sync aborted", chan);
3225 fcp->isp_loopstate = LOOP_READY;
3226 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC PDB sync done", chan);
3231 isp_pdb_add_update(ispsoftc_t *isp, int chan, isp_pdb_t *pdb)
3234 uint64_t wwnn, wwpn;
3236 MAKE_WWN_FROM_NODE_NAME(wwnn, pdb->nodename);
3237 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb->portname);
3239 /* Search port database for the same WWPN. */
3240 if (isp_find_pdb_by_wwpn(isp, chan, wwpn, &lp)) {
3241 if (!lp->probational) {
3242 isp_prt(isp, ISP_LOGERR,
3243 "Chan %d Port 0x%06x@0x%04x [%d] is not probational (0x%x)",
3244 chan, lp->portid, lp->handle,
3245 FC_PORTDB_TGT(isp, chan, lp), lp->state);
3246 isp_dump_portdb(isp, chan);
3249 lp->probational = 0;
3250 lp->node_wwn = wwnn;
3252 /* Old device, nothing new. */
3253 if (lp->portid == pdb->portid &&
3254 lp->handle == pdb->handle &&
3255 lp->prli_word3 == pdb->prli_word3) {
3256 if (lp->state != FC_PORTDB_STATE_NEW)
3257 lp->state = FC_PORTDB_STATE_VALID;
3258 isp_prt(isp, ISP_LOG_SANCFG,
3259 "Chan %d Port 0x%06x@0x%04x is valid",
3260 chan, pdb->portid, pdb->handle);
3264 /* Something has changed. */
3265 lp->state = FC_PORTDB_STATE_CHANGED;
3266 lp->handle = pdb->handle;
3267 lp->new_portid = pdb->portid;
3268 lp->new_prli_word3 = pdb->prli_word3;
3269 isp_prt(isp, ISP_LOG_SANCFG,
3270 "Chan %d Port 0x%06x@0x%04x is changed",
3271 chan, pdb->portid, pdb->handle);
3275 /* It seems like a new port. Find an empty slot for it. */
3276 if (!isp_find_pdb_empty(isp, chan, &lp)) {
3277 isp_prt(isp, ISP_LOGERR, "Chan %d out of portdb entries", chan);
3281 ISP_MEMZERO(lp, sizeof (fcportdb_t));
3283 lp->probational = 0;
3284 lp->state = FC_PORTDB_STATE_NEW;
3285 lp->portid = lp->new_portid = pdb->portid;
3286 lp->prli_word3 = lp->new_prli_word3 = pdb->prli_word3;
3287 lp->handle = pdb->handle;
3288 lp->port_wwn = wwpn;
3289 lp->node_wwn = wwnn;
3290 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Port 0x%06x@0x%04x is new",
3291 chan, pdb->portid, pdb->handle);
3295 * Fix port IDs for logged-in initiators on pre-2400 chips.
3296 * For those chips we are not receiving login events, adding initiators
3297 * based on ATIO requests, but there is no port ID in that structure.
3300 isp_fix_portids(ispsoftc_t *isp, int chan)
3302 fcparam *fcp = FCPARAM(isp, chan);
3307 for (i = 0; i < MAX_FC_TARG; i++) {
3308 fcportdb_t *lp = &fcp->portdb[i];
3310 if (lp->state == FC_PORTDB_STATE_NIL ||
3311 lp->state == FC_PORTDB_STATE_ZOMBIE)
3313 if (VALID_PORT(lp->portid))
3316 r = isp_getpdb(isp, chan, lp->handle, &pdb);
3317 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3320 isp_prt(isp, ISP_LOGDEBUG1,
3321 "Chan %d FC Scan Loop handle %d returned %x",
3322 chan, lp->handle, r);
3326 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb.portname);
3327 if (lp->port_wwn != wwpn)
3329 lp->portid = lp->new_portid = pdb.portid;
3330 isp_prt(isp, ISP_LOG_SANCFG,
3331 "Chan %d Port 0x%06x@0x%04x is fixed",
3332 chan, pdb.portid, pdb.handle);
3337 * Scan local loop for devices.
3340 isp_scan_loop(ispsoftc_t *isp, int chan)
3342 fcparam *fcp = FCPARAM(isp, chan);
3348 if (fcp->isp_loopstate < LOOP_LTEST_DONE)
3350 if (fcp->isp_loopstate >= LOOP_LSCAN_DONE)
3353 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC loop scan", chan);
3354 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
3355 if (TOPO_IS_FABRIC(fcp->isp_topo)) {
3356 if (!IS_24XX(isp)) {
3357 isp_fix_portids(isp, chan);
3358 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3361 isp_prt(isp, ISP_LOG_SANCFG,
3362 "Chan %d FC loop scan done (no loop)", chan);
3363 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3367 handles = (uint16_t *)fcp->isp_scanscratch;
3368 lim = ISP_FC_SCRLEN / 2;
3369 r = isp_gethandles(isp, chan, handles, &lim, 1);
3371 isp_prt(isp, ISP_LOG_SANCFG,
3372 "Chan %d Getting list of handles failed with %x", chan, r);
3373 isp_prt(isp, ISP_LOG_SANCFG,
3374 "Chan %d FC loop scan done (bad)", chan);
3378 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Got %d handles",
3382 * Run through the list and get the port database info for each one.
3384 isp_mark_portdb(isp, chan);
3385 for (idx = 0; idx < lim; idx++) {
3386 handle = handles[idx];
3389 * Don't scan "special" ids.
3391 if (ISP_CAP_2KLOGIN(isp)) {
3392 if (handle >= NPH_RESERVED)
3395 if (handle >= FL_ID && handle <= SNS_ID)
3400 * In older cards with older f/w GET_PORT_DATABASE has been
3401 * known to hang. This trick gets around that problem.
3403 if (IS_2100(isp) || IS_2200(isp)) {
3404 uint64_t node_wwn = isp_get_wwn(isp, chan, handle, 1);
3405 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
3407 isp_prt(isp, ISP_LOG_SANCFG,
3408 "Chan %d FC loop scan aborted", chan);
3411 if (node_wwn == INI_NONE) {
3417 * Get the port database entity for this index.
3419 r = isp_getpdb(isp, chan, handle, &pdb);
3420 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3423 isp_prt(isp, ISP_LOGDEBUG1,
3424 "Chan %d FC Scan Loop handle %d returned %x",
3429 isp_pdb_add_update(isp, chan, &pdb);
3431 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3433 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3434 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC loop scan done", chan);
3439 * Scan the fabric for devices and add them to our port database.
3441 * Use the GID_FT command to get all Port IDs for FC4 SCSI devices it knows.
3443 * For 2100-23XX cards, we can use the SNS mailbox command to pass simple
3444 * name server commands to the switch management server via the QLogic f/w.
3446 * For the 24XX card, we have to use CT-Pass through run via the Execute IOCB
3449 #define GIDLEN (ISP_FC_SCRLEN - (3 * QENTRY_LEN))
3450 #define NGENT ((GIDLEN - 16) >> 2)
3452 #define XTXOFF (ISP_FC_SCRLEN - (3 * QENTRY_LEN)) /* CT request */
3453 #define CTXOFF (ISP_FC_SCRLEN - (2 * QENTRY_LEN)) /* Request IOCB */
3454 #define ZTXOFF (ISP_FC_SCRLEN - (1 * QENTRY_LEN)) /* Response IOCB */
3457 isp_gid_ft_sns(ispsoftc_t *isp, int chan)
3460 sns_gid_ft_req_t _x;
3461 uint8_t _y[SNS_GID_FT_REQ_SIZE];
3463 fcparam *fcp = FCPARAM(isp, chan);
3464 sns_gid_ft_req_t *rq = &un._x;
3465 uint8_t *scp = fcp->isp_scratch;
3468 isp_prt(isp, ISP_LOGDEBUG0, "Chan %d requesting GID_FT via SNS", chan);
3469 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3470 isp_prt(isp, ISP_LOGERR, sacq);
3474 ISP_MEMZERO(rq, SNS_GID_FT_REQ_SIZE);
3475 rq->snscb_rblen = GIDLEN >> 1;
3476 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma);
3477 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma);
3478 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma);
3479 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma);
3480 rq->snscb_sblen = 6;
3481 rq->snscb_cmd = SNS_GID_FT;
3482 rq->snscb_mword_div_2 = NGENT;
3483 rq->snscb_fc4_type = FC4_SCSI;
3485 isp_put_gid_ft_request(isp, rq, (sns_gid_ft_req_t *)&scp[CTXOFF]);
3486 MEMORYBARRIER(isp, SYNC_SFORDEV, CTXOFF, SNS_GID_FT_REQ_SIZE, chan);
3488 MBSINIT(&mbs, MBOX_SEND_SNS, MBLOGALL, 10000000);
3489 mbs.param[0] = MBOX_SEND_SNS;
3490 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
3491 mbs.param[2] = DMA_WD1(fcp->isp_scdma + CTXOFF);
3492 mbs.param[3] = DMA_WD0(fcp->isp_scdma + CTXOFF);
3493 mbs.param[6] = DMA_WD3(fcp->isp_scdma + CTXOFF);
3494 mbs.param[7] = DMA_WD2(fcp->isp_scdma + CTXOFF);
3495 isp_mboxcmd(isp, &mbs);
3496 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3497 if (mbs.param[0] == MBOX_INVALID_COMMAND) {
3503 MEMORYBARRIER(isp, SYNC_SFORCPU, 0, GIDLEN, chan);
3504 if (isp->isp_dblev & ISP_LOGDEBUG1)
3505 isp_print_bytes(isp, "CT response", GIDLEN, scp);
3506 isp_get_gid_ft_response(isp, (sns_gid_ft_rsp_t *)scp,
3507 (sns_gid_ft_rsp_t *)fcp->isp_scanscratch, NGENT);
3508 FC_SCRATCH_RELEASE(isp, chan);
3513 isp_ct_passthru(ispsoftc_t *isp, int chan, uint32_t cmd_bcnt, uint32_t rsp_bcnt)
3516 fcparam *fcp = FCPARAM(isp, chan);
3519 uint8_t q[QENTRY_LEN];
3522 uint8_t *scp = fcp->isp_scratch;
3525 * Build a Passthrough IOCB in memory.
3528 ISP_MEMZERO(un.q, QENTRY_LEN);
3529 pt->ctp_header.rqs_entry_count = 1;
3530 pt->ctp_header.rqs_entry_type = RQSTYPE_CT_PASSTHRU;
3531 pt->ctp_handle = 0xffffffff;
3532 pt->ctp_nphdl = fcp->isp_sns_hdl;
3533 pt->ctp_cmd_cnt = 1;
3534 pt->ctp_vpidx = ISP_GET_VPIDX(isp, chan);
3536 pt->ctp_rsp_cnt = 1;
3537 pt->ctp_rsp_bcnt = rsp_bcnt;
3538 pt->ctp_cmd_bcnt = cmd_bcnt;
3539 pt->ctp_dataseg[0].ds_base = DMA_LO32(fcp->isp_scdma+XTXOFF);
3540 pt->ctp_dataseg[0].ds_basehi = DMA_HI32(fcp->isp_scdma+XTXOFF);
3541 pt->ctp_dataseg[0].ds_count = cmd_bcnt;
3542 pt->ctp_dataseg[1].ds_base = DMA_LO32(fcp->isp_scdma);
3543 pt->ctp_dataseg[1].ds_basehi = DMA_HI32(fcp->isp_scdma);
3544 pt->ctp_dataseg[1].ds_count = rsp_bcnt;
3545 isp_put_ct_pt(isp, pt, (isp_ct_pt_t *)&scp[CTXOFF]);
3546 if (isp->isp_dblev & ISP_LOGDEBUG1)
3547 isp_print_bytes(isp, "CT IOCB request", QENTRY_LEN, &scp[CTXOFF]);
3550 * Execute the Passthrough IOCB.
3552 ISP_MEMZERO(&scp[ZTXOFF], QENTRY_LEN);
3553 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL,
3554 MBCMD_DEFAULT_TIMEOUT + pt->ctp_time * 1000000);
3555 mbs.param[1] = QENTRY_LEN;
3556 mbs.param[2] = DMA_WD1(fcp->isp_scdma + CTXOFF);
3557 mbs.param[3] = DMA_WD0(fcp->isp_scdma + CTXOFF);
3558 mbs.param[6] = DMA_WD3(fcp->isp_scdma + CTXOFF);
3559 mbs.param[7] = DMA_WD2(fcp->isp_scdma + CTXOFF);
3560 MEMORYBARRIER(isp, SYNC_SFORDEV, XTXOFF, 2 * QENTRY_LEN, chan);
3561 isp_mboxcmd(isp, &mbs);
3562 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3565 MEMORYBARRIER(isp, SYNC_SFORCPU, 0, ISP_FC_SCRLEN, chan);
3566 if (isp->isp_dblev & ISP_LOGDEBUG1)
3567 isp_print_bytes(isp, "CT IOCB response", QENTRY_LEN, &scp[ZTXOFF]);
3569 isp_get_ct_pt(isp, (isp_ct_pt_t *) &scp[ZTXOFF], pt);
3570 if (pt->ctp_status && pt->ctp_status != RQCS_DATA_UNDERRUN) {
3571 isp_prt(isp, ISP_LOGWARN,
3572 "Chan %d GID_FT CT Passthrough returned 0x%x",
3573 chan, pt->ctp_status);
3581 isp_gid_ft_ct_passthru(ispsoftc_t *isp, int chan)
3583 fcparam *fcp = FCPARAM(isp, chan);
3586 uint8_t *scp = fcp->isp_scratch;
3588 isp_prt(isp, ISP_LOGDEBUG0, "Chan %d requesting GID_FT via CT", chan);
3589 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3590 isp_prt(isp, ISP_LOGERR, sacq);
3595 * Build the CT header and command in memory.
3597 ISP_MEMZERO(&ct, sizeof (ct));
3598 ct.ct_revision = CT_REVISION;
3599 ct.ct_fcs_type = CT_FC_TYPE_FC;
3600 ct.ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3601 ct.ct_cmd_resp = SNS_GID_FT;
3602 ct.ct_bcnt_resid = (GIDLEN - 16) >> 2;
3603 isp_put_ct_hdr(isp, &ct, (ct_hdr_t *) &scp[XTXOFF]);
3604 rp = (uint32_t *) &scp[XTXOFF + sizeof(ct)];
3605 ISP_IOZPUT_32(isp, FC4_SCSI, rp);
3606 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3607 isp_print_bytes(isp, "CT request",
3608 sizeof(ct) + sizeof(uint32_t), &scp[XTXOFF]);
3611 if (isp_ct_passthru(isp, chan, sizeof(ct) + sizeof(uint32_t), GIDLEN)) {
3612 FC_SCRATCH_RELEASE(isp, chan);
3616 if (isp->isp_dblev & ISP_LOGDEBUG1)
3617 isp_print_bytes(isp, "CT response", GIDLEN, scp);
3618 isp_get_gid_ft_response(isp, (sns_gid_ft_rsp_t *)scp,
3619 (sns_gid_ft_rsp_t *)fcp->isp_scanscratch, NGENT);
3620 FC_SCRATCH_RELEASE(isp, chan);
3625 isp_scan_fabric(ispsoftc_t *isp, int chan)
3627 fcparam *fcp = FCPARAM(isp, chan);
3632 int portidx, portlim, r;
3633 sns_gid_ft_rsp_t *rs;
3635 if (fcp->isp_loopstate < LOOP_LSCAN_DONE)
3637 if (fcp->isp_loopstate >= LOOP_FSCAN_DONE)
3640 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC fabric scan", chan);
3641 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
3642 if (!TOPO_IS_FABRIC(fcp->isp_topo)) {
3643 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3644 isp_prt(isp, ISP_LOG_SANCFG,
3645 "Chan %d FC fabric scan done (no fabric)", chan);
3649 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC) {
3651 FC_SCRATCH_RELEASE(isp, chan);
3652 isp_prt(isp, ISP_LOG_SANCFG,
3653 "Chan %d FC fabric scan aborted", chan);
3658 * Make sure we still are logged into the fabric controller.
3660 nphdl = IS_24XX(isp) ? NPH_FL_ID : FL_ID;
3661 r = isp_getpdb(isp, chan, nphdl, &pdb);
3662 if ((r & 0xffff) == MBOX_NOT_LOGGED_IN) {
3663 isp_dump_chip_portdb(isp, chan);
3666 fcp->isp_loopstate = LOOP_LTEST_DONE;
3668 isp_prt(isp, ISP_LOG_SANCFG,
3669 "Chan %d FC fabric scan done (bad)", chan);
3673 /* Get list of port IDs from SNS. */
3675 r = isp_gid_ft_ct_passthru(isp, chan);
3677 r = isp_gid_ft_sns(isp, chan);
3678 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3681 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3684 fcp->isp_loopstate = LOOP_LTEST_DONE; /* try again */
3688 rs = (sns_gid_ft_rsp_t *) fcp->isp_scanscratch;
3689 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3691 if (rs->snscb_cthdr.ct_cmd_resp != LS_ACC) {
3693 if (rs->snscb_cthdr.ct_reason == 9 && rs->snscb_cthdr.ct_explanation == 7) {
3694 level = ISP_LOG_SANCFG;
3696 level = ISP_LOGWARN;
3698 isp_prt(isp, level, "Chan %d Fabric Nameserver rejected GID_FT"
3699 " (Reason=0x%x Expl=0x%x)", chan,
3700 rs->snscb_cthdr.ct_reason,
3701 rs->snscb_cthdr.ct_explanation);
3702 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3706 /* Check our buffer was big enough to get the full list. */
3707 for (portidx = 0; portidx < NGENT-1; portidx++) {
3708 if (rs->snscb_ports[portidx].control & 0x80)
3711 if ((rs->snscb_ports[portidx].control & 0x80) == 0) {
3712 isp_prt(isp, ISP_LOGWARN,
3713 "fabric too big for scratch area: increase ISP_FC_SCRLEN");
3715 portlim = portidx + 1;
3716 isp_prt(isp, ISP_LOG_SANCFG,
3717 "Chan %d Got %d ports back from name server", chan, portlim);
3719 /* Go through the list and remove duplicate port ids. */
3720 for (portidx = 0; portidx < portlim; portidx++) {
3724 ((rs->snscb_ports[portidx].portid[0]) << 16) |
3725 ((rs->snscb_ports[portidx].portid[1]) << 8) |
3726 ((rs->snscb_ports[portidx].portid[2]));
3728 for (npidx = portidx + 1; npidx < portlim; npidx++) {
3729 uint32_t new_portid =
3730 ((rs->snscb_ports[npidx].portid[0]) << 16) |
3731 ((rs->snscb_ports[npidx].portid[1]) << 8) |
3732 ((rs->snscb_ports[npidx].portid[2]));
3733 if (new_portid == portid) {
3738 if (npidx < portlim) {
3739 rs->snscb_ports[npidx].portid[0] = 0;
3740 rs->snscb_ports[npidx].portid[1] = 0;
3741 rs->snscb_ports[npidx].portid[2] = 0;
3742 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d removing duplicate PortID 0x%06x entry from list", chan, portid);
3747 * We now have a list of Port IDs for all FC4 SCSI devices
3748 * that the Fabric Name server knows about.
3750 * For each entry on this list go through our port database looking
3751 * for probational entries- if we find one, then an old entry is
3752 * maybe still this one. We get some information to find out.
3754 * Otherwise, it's a new fabric device, and we log into it
3755 * (unconditionally). After searching the entire database
3756 * again to make sure that we never ever ever ever have more
3757 * than one entry that has the same PortID or the same
3758 * WWNN/WWPN duple, we enter the device into our database.
3760 isp_mark_portdb(isp, chan);
3761 for (portidx = 0; portidx < portlim; portidx++) {
3762 portid = ((rs->snscb_ports[portidx].portid[0]) << 16) |
3763 ((rs->snscb_ports[portidx].portid[1]) << 8) |
3764 ((rs->snscb_ports[portidx].portid[2]));
3765 isp_prt(isp, ISP_LOG_SANCFG,
3766 "Chan %d Checking fabric port 0x%06x", chan, portid);
3768 isp_prt(isp, ISP_LOG_SANCFG,
3769 "Chan %d Port at idx %d is zero",
3773 if (portid == fcp->isp_portid) {
3774 isp_prt(isp, ISP_LOG_SANCFG,
3775 "Chan %d Port 0x%06x is our", chan, portid);
3779 /* Now search the entire port database for the same portid. */
3780 if (isp_find_pdb_by_portid(isp, chan, portid, &lp)) {
3781 if (!lp->probational) {
3782 isp_prt(isp, ISP_LOGERR,
3783 "Chan %d Port 0x%06x@0x%04x [%d] is not probational (0x%x)",
3784 chan, lp->portid, lp->handle,
3785 FC_PORTDB_TGT(isp, chan, lp), lp->state);
3786 isp_dump_portdb(isp, chan);
3791 * See if we're still logged into it.
3793 * If we aren't, mark it as a dead device and
3794 * leave the new portid in the database entry
3795 * for somebody further along to decide what to
3796 * do (policy choice).
3798 * If we are, check to see if it's the same
3799 * device still (it should be). If for some
3800 * reason it isn't, mark it as a changed device
3801 * and leave the new portid and role in the
3802 * database entry for somebody further along to
3803 * decide what to do (policy choice).
3805 r = isp_getpdb(isp, chan, lp->handle, &pdb);
3806 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3809 lp->state = FC_PORTDB_STATE_DEAD;
3810 isp_prt(isp, ISP_LOG_SANCFG,
3811 "Chan %d Port 0x%06x handle 0x%x is dead (%d)",
3812 chan, portid, lp->handle, r);
3816 isp_pdb_add_update(isp, chan, &pdb);
3821 if ((fcp->role & ISP_ROLE_INITIATOR) == 0) {
3822 isp_prt(isp, ISP_LOG_SANCFG,
3823 "Chan %d Port 0x%06x is not logged in", chan, portid);
3827 if (isp_login_device(isp, chan, portid, &pdb,
3828 &FCPARAM(isp, 0)->isp_lasthdl)) {
3829 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3834 isp_pdb_add_update(isp, chan, &pdb);
3837 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3839 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3840 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC fabric scan done", chan);
3845 * Find an unused handle and try and use to login to a port.
3848 isp_login_device(ispsoftc_t *isp, int chan, uint32_t portid, isp_pdb_t *p, uint16_t *ohp)
3853 if (ISP_CAP_2KLOGIN(isp)) {
3859 handle = isp_next_handle(isp, ohp);
3860 for (i = 0; i < lim; i++) {
3861 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
3864 /* Check if this handle is free. */
3865 r = isp_getpdb(isp, chan, handle, p);
3867 if (p->portid != portid) {
3868 /* This handle is busy, try next one. */
3869 handle = isp_next_handle(isp, ohp);
3874 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
3878 * Now try and log into the device
3880 r = isp_plogx(isp, chan, handle, portid, PLOGX_FLG_CMD_PLOGI);
3883 } else if ((r & 0xffff) == MBOX_PORT_ID_USED) {
3885 * If we get here, then the firmwware still thinks we're logged into this device, but with a different
3886 * handle. We need to break that association. We used to try and just substitute the handle, but then
3887 * failed to get any data via isp_getpdb (below).
3889 if (isp_plogx(isp, chan, r >> 16, portid, PLOGX_FLG_CMD_LOGO | PLOGX_FLG_IMPLICIT | PLOGX_FLG_FREE_NPHDL)) {
3890 isp_prt(isp, ISP_LOGERR, "baw... logout of %x failed", r >> 16);
3892 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
3894 r = isp_plogx(isp, chan, handle, portid, PLOGX_FLG_CMD_PLOGI);
3898 } else if ((r & 0xffff) == MBOX_LOOP_ID_USED) {
3899 /* Try the next handle. */
3900 handle = isp_next_handle(isp, ohp);
3909 isp_prt(isp, ISP_LOGWARN, "Chan %d PLOGI 0x%06x failed", chan, portid);
3914 * If we successfully logged into it, get the PDB for it
3915 * so we can crosscheck that it is still what we think it
3916 * is and that we also have the role it plays
3918 r = isp_getpdb(isp, chan, handle, p);
3920 isp_prt(isp, ISP_LOGERR, "Chan %d new device 0x%06x@0x%x disappeared", chan, portid, handle);
3924 if (p->handle != handle || p->portid != portid) {
3925 isp_prt(isp, ISP_LOGERR, "Chan %d new device 0x%06x@0x%x changed (0x%06x@0x%0x)",
3926 chan, portid, handle, p->portid, p->handle);
3933 isp_send_change_request(ispsoftc_t *isp, int chan)
3937 MBSINIT(&mbs, MBOX_SEND_CHANGE_REQUEST, MBLOGALL, 500000);
3938 mbs.param[1] = 0x03;
3939 mbs.param[9] = chan;
3940 isp_mboxcmd(isp, &mbs);
3941 return (mbs.param[0] == MBOX_COMMAND_COMPLETE ? 0 : -1);
3945 isp_register_fc4_type(ispsoftc_t *isp, int chan)
3947 fcparam *fcp = FCPARAM(isp, chan);
3948 uint8_t local[SNS_RFT_ID_REQ_SIZE];
3949 sns_screq_t *reqp = (sns_screq_t *) local;
3952 ISP_MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
3953 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
3954 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
3955 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
3956 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
3957 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
3958 reqp->snscb_sblen = 22;
3959 reqp->snscb_data[0] = SNS_RFT_ID;
3960 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
3961 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
3962 reqp->snscb_data[6] = (1 << FC4_SCSI);
3963 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3964 isp_prt(isp, ISP_LOGERR, sacq);
3967 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
3968 MBSINIT(&mbs, MBOX_SEND_SNS, MBLOGALL, 1000000);
3969 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
3970 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
3971 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
3972 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
3973 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
3974 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_RFT_ID_REQ_SIZE, chan);
3975 isp_mboxcmd(isp, &mbs);
3976 FC_SCRATCH_RELEASE(isp, chan);
3977 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3985 isp_register_fc4_type_24xx(ispsoftc_t *isp, int chan)
3987 fcparam *fcp = FCPARAM(isp, chan);
3990 uint8_t *scp = fcp->isp_scratch;
3992 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3993 isp_prt(isp, ISP_LOGERR, sacq);
3998 * Build the CT header and command in memory.
4000 ISP_MEMZERO(&rp, sizeof(rp));
4002 ct->ct_revision = CT_REVISION;
4003 ct->ct_fcs_type = CT_FC_TYPE_FC;
4004 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
4005 ct->ct_cmd_resp = SNS_RFT_ID;
4006 ct->ct_bcnt_resid = (sizeof (rft_id_t) - sizeof (ct_hdr_t)) >> 2;
4007 rp.rftid_portid[0] = fcp->isp_portid >> 16;
4008 rp.rftid_portid[1] = fcp->isp_portid >> 8;
4009 rp.rftid_portid[2] = fcp->isp_portid;
4010 rp.rftid_fc4types[FC4_SCSI >> 5] = 1 << (FC4_SCSI & 0x1f);
4011 isp_put_rft_id(isp, &rp, (rft_id_t *)&scp[XTXOFF]);
4012 if (isp->isp_dblev & ISP_LOGDEBUG1)
4013 isp_print_bytes(isp, "CT request", sizeof(rft_id_t), &scp[XTXOFF]);
4015 if (isp_ct_passthru(isp, chan, sizeof(rft_id_t), sizeof(ct_hdr_t))) {
4016 FC_SCRATCH_RELEASE(isp, chan);
4020 isp_get_ct_hdr(isp, (ct_hdr_t *) scp, ct);
4021 FC_SCRATCH_RELEASE(isp, chan);
4022 if (ct->ct_cmd_resp == LS_RJT) {
4023 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "Chan %d Register FC4 Type rejected", chan);
4025 } else if (ct->ct_cmd_resp == LS_ACC) {
4026 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Register FC4 Type accepted", chan);
4028 isp_prt(isp, ISP_LOGWARN, "Chan %d Register FC4 Type: 0x%x", chan, ct->ct_cmd_resp);
4035 isp_register_fc4_features_24xx(ispsoftc_t *isp, int chan)
4037 fcparam *fcp = FCPARAM(isp, chan);
4040 uint8_t *scp = fcp->isp_scratch;
4042 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4043 isp_prt(isp, ISP_LOGERR, sacq);
4048 * Build the CT header and command in memory.
4050 ISP_MEMZERO(&rp, sizeof(rp));
4052 ct->ct_revision = CT_REVISION;
4053 ct->ct_fcs_type = CT_FC_TYPE_FC;
4054 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
4055 ct->ct_cmd_resp = SNS_RFF_ID;
4056 ct->ct_bcnt_resid = (sizeof (rff_id_t) - sizeof (ct_hdr_t)) >> 2;
4057 rp.rffid_portid[0] = fcp->isp_portid >> 16;
4058 rp.rffid_portid[1] = fcp->isp_portid >> 8;
4059 rp.rffid_portid[2] = fcp->isp_portid;
4060 rp.rffid_fc4features = 0;
4061 if (fcp->role & ISP_ROLE_TARGET)
4062 rp.rffid_fc4features |= 1;
4063 if (fcp->role & ISP_ROLE_INITIATOR)
4064 rp.rffid_fc4features |= 2;
4065 rp.rffid_fc4type = FC4_SCSI;
4066 isp_put_rff_id(isp, &rp, (rff_id_t *)&scp[XTXOFF]);
4067 if (isp->isp_dblev & ISP_LOGDEBUG1)
4068 isp_print_bytes(isp, "CT request", sizeof(rft_id_t), &scp[XTXOFF]);
4070 if (isp_ct_passthru(isp, chan, sizeof(rft_id_t), sizeof(ct_hdr_t))) {
4071 FC_SCRATCH_RELEASE(isp, chan);
4075 isp_get_ct_hdr(isp, (ct_hdr_t *) scp, ct);
4076 FC_SCRATCH_RELEASE(isp, chan);
4077 if (ct->ct_cmd_resp == LS_RJT) {
4078 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1,
4079 "Chan %d Register FC4 Features rejected", chan);
4081 } else if (ct->ct_cmd_resp == LS_ACC) {
4082 isp_prt(isp, ISP_LOG_SANCFG,
4083 "Chan %d Register FC4 Features accepted", chan);
4085 isp_prt(isp, ISP_LOGWARN,
4086 "Chan %d Register FC4 Features: 0x%x", chan, ct->ct_cmd_resp);
4093 isp_register_port_name_24xx(ispsoftc_t *isp, int chan)
4095 fcparam *fcp = FCPARAM(isp, chan);
4098 uint8_t *scp = fcp->isp_scratch;
4101 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4102 isp_prt(isp, ISP_LOGERR, sacq);
4107 * Build the CT header and command in memory.
4109 ISP_MEMZERO(&rp, sizeof(rp));
4110 ct = &rp.rspnid_hdr;
4111 ct->ct_revision = CT_REVISION;
4112 ct->ct_fcs_type = CT_FC_TYPE_FC;
4113 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
4114 ct->ct_cmd_resp = SNS_RSPN_ID;
4115 rp.rspnid_portid[0] = fcp->isp_portid >> 16;
4116 rp.rspnid_portid[1] = fcp->isp_portid >> 8;
4117 rp.rspnid_portid[2] = fcp->isp_portid;
4118 rp.rspnid_length = 0;
4119 len = offsetof(rspn_id_t, rspnid_name);
4120 mtx_lock(&prison0.pr_mtx);
4121 rp.rspnid_length += sprintf(&scp[XTXOFF + len + rp.rspnid_length],
4122 "%s", prison0.pr_hostname[0] ? prison0.pr_hostname : "FreeBSD");
4123 mtx_unlock(&prison0.pr_mtx);
4124 rp.rspnid_length += sprintf(&scp[XTXOFF + len + rp.rspnid_length],
4125 ":%s", device_get_nameunit(isp->isp_dev));
4127 rp.rspnid_length += sprintf(&scp[XTXOFF + len +
4128 rp.rspnid_length], "/%d", chan);
4130 len += rp.rspnid_length;
4131 ct->ct_bcnt_resid = (len - sizeof(ct_hdr_t)) >> 2;
4132 isp_put_rspn_id(isp, &rp, (rspn_id_t *)&scp[XTXOFF]);
4133 if (isp->isp_dblev & ISP_LOGDEBUG1)
4134 isp_print_bytes(isp, "CT request", len, &scp[XTXOFF]);
4136 if (isp_ct_passthru(isp, chan, len, sizeof(ct_hdr_t))) {
4137 FC_SCRATCH_RELEASE(isp, chan);
4141 isp_get_ct_hdr(isp, (ct_hdr_t *) scp, ct);
4142 FC_SCRATCH_RELEASE(isp, chan);
4143 if (ct->ct_cmd_resp == LS_RJT) {
4144 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1,
4145 "Chan %d Register Symbolic Port Name rejected", chan);
4147 } else if (ct->ct_cmd_resp == LS_ACC) {
4148 isp_prt(isp, ISP_LOG_SANCFG,
4149 "Chan %d Register Symbolic Port Name accepted", chan);
4151 isp_prt(isp, ISP_LOGWARN,
4152 "Chan %d Register Symbolic Port Name: 0x%x", chan, ct->ct_cmd_resp);
4159 isp_register_node_name_24xx(ispsoftc_t *isp, int chan)
4161 fcparam *fcp = FCPARAM(isp, chan);
4164 uint8_t *scp = fcp->isp_scratch;
4167 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4168 isp_prt(isp, ISP_LOGERR, sacq);
4173 * Build the CT header and command in memory.
4175 ISP_MEMZERO(&rp, sizeof(rp));
4176 ct = &rp.rsnnnn_hdr;
4177 ct->ct_revision = CT_REVISION;
4178 ct->ct_fcs_type = CT_FC_TYPE_FC;
4179 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
4180 ct->ct_cmd_resp = SNS_RSNN_NN;
4181 MAKE_NODE_NAME_FROM_WWN(rp.rsnnnn_nodename, fcp->isp_wwnn);
4182 rp.rsnnnn_length = 0;
4183 len = offsetof(rsnn_nn_t, rsnnnn_name);
4184 mtx_lock(&prison0.pr_mtx);
4185 rp.rsnnnn_length += sprintf(&scp[XTXOFF + len + rp.rsnnnn_length],
4186 "%s", prison0.pr_hostname[0] ? prison0.pr_hostname : "FreeBSD");
4187 mtx_unlock(&prison0.pr_mtx);
4188 len += rp.rsnnnn_length;
4189 ct->ct_bcnt_resid = (len - sizeof(ct_hdr_t)) >> 2;
4190 isp_put_rsnn_nn(isp, &rp, (rsnn_nn_t *)&scp[XTXOFF]);
4191 if (isp->isp_dblev & ISP_LOGDEBUG1)
4192 isp_print_bytes(isp, "CT request", len, &scp[XTXOFF]);
4194 if (isp_ct_passthru(isp, chan, len, sizeof(ct_hdr_t))) {
4195 FC_SCRATCH_RELEASE(isp, chan);
4199 isp_get_ct_hdr(isp, (ct_hdr_t *) scp, ct);
4200 FC_SCRATCH_RELEASE(isp, chan);
4201 if (ct->ct_cmd_resp == LS_RJT) {
4202 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1,
4203 "Chan %d Register Symbolic Node Name rejected", chan);
4205 } else if (ct->ct_cmd_resp == LS_ACC) {
4206 isp_prt(isp, ISP_LOG_SANCFG,
4207 "Chan %d Register Symbolic Node Name accepted", chan);
4209 isp_prt(isp, ISP_LOGWARN,
4210 "Chan %d Register Symbolic Node Name: 0x%x", chan, ct->ct_cmd_resp);
4217 isp_next_handle(ispsoftc_t *isp, uint16_t *ohp)
4221 uint16_t handle, minh, maxh;
4224 if (ISP_CAP_2KLOGIN(isp)) {
4226 maxh = NPH_RESERVED - 1;
4234 if (handle == NIL_HANDLE) {
4238 if (handle > maxh) {
4240 isp_prt(isp, ISP_LOGERR, "Out of port handles!");
4241 return (NIL_HANDLE);
4246 for (chan = 0; chan < isp->isp_nchan; chan++) {
4247 fcp = FCPARAM(isp, chan);
4248 if (fcp->role == ISP_ROLE_NONE)
4250 for (i = 0; i < MAX_FC_TARG; i++) {
4251 if (fcp->portdb[i].state != FC_PORTDB_STATE_NIL &&
4252 fcp->portdb[i].handle == handle)
4261 * Start a command. Locking is assumed done in the caller.
4269 uint8_t local[QENTRY_LEN];
4274 int target, dmaresult;
4280 * Check command CDB length, etc.. We really are limited to 16 bytes
4281 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
4282 * but probably only if we're running fairly new firmware (we'll
4283 * let the old f/w choke on an extended command queue entry).
4286 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
4287 isp_prt(isp, ISP_LOGERR, "unsupported cdb length (%d, CDB[0]=0x%x)", XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
4288 XS_SETERR(xs, HBA_BOTCH);
4289 return (CMD_COMPLETE);
4293 * Translate the target to device handle as appropriate, checking
4294 * for correct device state as well.
4296 target = XS_TGT(xs);
4298 fcparam *fcp = FCPARAM(isp, XS_CHANNEL(xs));
4300 if ((fcp->role & ISP_ROLE_INITIATOR) == 0) {
4301 isp_prt(isp, ISP_LOG_WARN1,
4302 "%d.%d.%jx I am not an initiator",
4303 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4304 XS_SETERR(xs, HBA_SELTIMEOUT);
4305 return (CMD_COMPLETE);
4308 if (isp->isp_state != ISP_RUNSTATE) {
4309 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
4310 XS_SETERR(xs, HBA_BOTCH);
4311 return (CMD_COMPLETE);
4317 if (fcp->isp_loopstate != LOOP_READY) {
4318 return (CMD_RQLATER);
4321 isp_prt(isp, ISP_LOGDEBUG2, "XS_TGT(xs)=%d", target);
4322 lp = &fcp->portdb[target];
4323 if (target < 0 || target >= MAX_FC_TARG ||
4324 lp->is_target == 0) {
4325 XS_SETERR(xs, HBA_SELTIMEOUT);
4326 return (CMD_COMPLETE);
4328 if (lp->state == FC_PORTDB_STATE_ZOMBIE) {
4329 isp_prt(isp, ISP_LOGDEBUG1,
4330 "%d.%d.%jx target zombie",
4331 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4332 return (CMD_RQLATER);
4334 if (lp->state != FC_PORTDB_STATE_VALID) {
4335 isp_prt(isp, ISP_LOGDEBUG1,
4336 "%d.%d.%jx bad db port state 0x%x",
4337 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs), lp->state);
4338 XS_SETERR(xs, HBA_SELTIMEOUT);
4339 return (CMD_COMPLETE);
4342 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
4343 if (isp->isp_state != ISP_RUNSTATE) {
4344 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
4345 XS_SETERR(xs, HBA_BOTCH);
4346 return (CMD_COMPLETE);
4350 isp_spi_update(isp, XS_CHANNEL(xs));
4357 qep = isp_getrqentry(isp);
4359 isp_prt(isp, ISP_LOG_WARN1, "Request Queue Overflow");
4360 XS_SETERR(xs, HBA_BOTCH);
4361 return (CMD_EAGAIN);
4363 XS_SETERR(xs, HBA_NOERROR);
4366 * Now see if we need to synchronize the ISP with respect to anything.
4367 * We do dual duty here (cough) for synchronizing for busses other
4368 * than which we got here to send a command to.
4370 reqp = (ispreq_t *) local;
4371 ISP_MEMZERO(local, QENTRY_LEN);
4372 if (ISP_TST_SENDMARKER(isp, XS_CHANNEL(xs))) {
4374 isp_marker_24xx_t *m = (isp_marker_24xx_t *) reqp;
4375 m->mrk_header.rqs_entry_count = 1;
4376 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4377 m->mrk_modifier = SYNC_ALL;
4378 m->mrk_vphdl = XS_CHANNEL(xs);
4379 isp_put_marker_24xx(isp, m, qep);
4381 isp_marker_t *m = (isp_marker_t *) reqp;
4382 m->mrk_header.rqs_entry_count = 1;
4383 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4384 m->mrk_target = (XS_CHANNEL(xs) << 7); /* bus # */
4385 m->mrk_modifier = SYNC_ALL;
4386 isp_put_marker(isp, m, qep);
4388 ISP_SYNC_REQUEST(isp);
4389 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 0);
4393 reqp->req_header.rqs_entry_count = 1;
4396 * Select and install Header Code.
4397 * Note that it might be overridden before going out
4398 * if we're on a 64 bit platform. The lower level
4399 * code (isp_send_cmd) will select the appropriate
4400 * 64 bit variant if it needs to.
4403 reqp->req_header.rqs_entry_type = RQSTYPE_T7RQS;
4404 } else if (IS_FC(isp)) {
4405 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
4407 if (XS_CDBLEN(xs) > 12) {
4408 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
4410 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
4415 * Set task attributes
4420 ttype = XS_TAG_TYPE(xs);
4422 if (XS_CDBP(xs)[0] == 0x3) {
4423 ttype = REQFLAG_HTAG;
4425 ttype = REQFLAG_STAG;
4428 if (ttype == REQFLAG_OTAG) {
4429 ttype = FCP_CMND_TASK_ATTR_ORDERED;
4430 } else if (ttype == REQFLAG_HTAG) {
4431 ttype = FCP_CMND_TASK_ATTR_HEAD;
4433 ttype = FCP_CMND_TASK_ATTR_SIMPLE;
4435 ((ispreqt7_t *)reqp)->req_task_attribute = ttype;
4436 } else if (IS_FC(isp)) {
4438 * See comment in isp_intr
4440 /* XS_SET_RESID(xs, 0); */
4443 * Fibre Channel always requires some kind of tag.
4444 * The Qlogic drivers seem be happy not to use a tag,
4445 * but this breaks for some devices (IBM drives).
4448 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
4451 * If we don't know what tag to use, use HEAD OF QUEUE
4452 * for Request Sense or Simple.
4454 if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
4455 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_HTAG;
4457 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
4460 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
4461 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) && XS_TAG_P(xs)) {
4462 reqp->req_flags = XS_TAG_TYPE(xs);
4466 tptr = &reqp->req_time;
4469 * NB: we do not support long CDBs (yet)
4471 cdblen = XS_CDBLEN(xs);
4474 if (cdblen > sizeof (reqp->req_cdb)) {
4475 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4476 XS_SETERR(xs, HBA_BOTCH);
4477 return (CMD_COMPLETE);
4479 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
4480 reqp->req_lun_trn = XS_LUN(xs);
4481 cdbp = reqp->req_cdb;
4482 reqp->req_cdblen = cdblen;
4483 } else if (IS_24XX(isp)) {
4484 ispreqt7_t *t7 = (ispreqt7_t *)local;
4486 if (cdblen > sizeof (t7->req_cdb)) {
4487 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4488 XS_SETERR(xs, HBA_BOTCH);
4489 return (CMD_COMPLETE);
4492 t7->req_nphdl = lp->handle;
4493 t7->req_tidlo = lp->portid;
4494 t7->req_tidhi = lp->portid >> 16;
4495 t7->req_vpidx = ISP_GET_VPIDX(isp, XS_CHANNEL(xs));
4496 #if __FreeBSD_version >= 1000700
4497 be64enc(t7->req_lun, CAM_EXTLUN_BYTE_SWIZZLE(XS_LUN(xs)));
4499 if (XS_LUN(xs) >= 256) {
4500 t7->req_lun[0] = XS_LUN(xs) >> 8;
4501 t7->req_lun[0] |= 0x40;
4503 t7->req_lun[1] = XS_LUN(xs);
4505 if (FCPARAM(isp, XS_CHANNEL(xs))->fctape_enabled && (lp->prli_word3 & PRLI_WD3_RETRY)) {
4506 if (FCP_NEXT_CRN(isp, &t7->req_crn, xs)) {
4507 isp_prt(isp, ISP_LOG_WARN1,
4508 "%d.%d.%jx cannot generate next CRN",
4509 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4510 XS_SETERR(xs, HBA_BOTCH);
4511 return (CMD_EAGAIN);
4514 tptr = &t7->req_time;
4517 ispreqt2_t *t2 = (ispreqt2_t *)local;
4519 if (cdblen > sizeof t2->req_cdb) {
4520 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4521 XS_SETERR(xs, HBA_BOTCH);
4522 return (CMD_COMPLETE);
4524 if (FCPARAM(isp, XS_CHANNEL(xs))->fctape_enabled && (lp->prli_word3 & PRLI_WD3_RETRY)) {
4525 if (FCP_NEXT_CRN(isp, &t2->req_crn, xs)) {
4526 isp_prt(isp, ISP_LOG_WARN1,
4527 "%d.%d.%jx cannot generate next CRN",
4528 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4529 XS_SETERR(xs, HBA_BOTCH);
4530 return (CMD_EAGAIN);
4533 if (ISP_CAP_2KLOGIN(isp)) {
4534 ispreqt2e_t *t2e = (ispreqt2e_t *)local;
4535 t2e->req_target = lp->handle;
4536 t2e->req_scclun = XS_LUN(xs);
4537 #if __FreeBSD_version < 1000700
4538 if (XS_LUN(xs) >= 256)
4539 t2e->req_scclun |= 0x4000;
4541 cdbp = t2e->req_cdb;
4542 } else if (ISP_CAP_SCCFW(isp)) {
4543 ispreqt2_t *t2 = (ispreqt2_t *)local;
4544 t2->req_target = lp->handle;
4545 t2->req_scclun = XS_LUN(xs);
4546 #if __FreeBSD_version < 1000700
4547 if (XS_LUN(xs) >= 256)
4548 t2->req_scclun |= 0x4000;
4552 t2->req_target = lp->handle;
4553 t2->req_lun_trn = XS_LUN(xs);
4557 ISP_MEMCPY(cdbp, XS_CDBP(xs), cdblen);
4559 *tptr = (XS_TIME(xs) + 999) / 1000;
4560 if (IS_24XX(isp) && *tptr > 0x1999) {
4564 /* Whew. Thankfully the same for type 7 requests */
4565 reqp->req_handle = isp_allocate_handle(isp, xs, ISP_HANDLE_INITIATOR);
4566 if (reqp->req_handle == 0) {
4567 isp_prt(isp, ISP_LOG_WARN1, "out of xflist pointers");
4568 XS_SETERR(xs, HBA_BOTCH);
4569 return (CMD_EAGAIN);
4573 * Set up DMA and/or do any platform dependent swizzling of the request entry
4574 * so that the Qlogic F/W understands what is being asked of it.
4576 * The callee is responsible for adding all requests at this point.
4578 dmaresult = ISP_DMASETUP(isp, xs, reqp);
4579 if (dmaresult != CMD_QUEUED) {
4580 isp_destroy_handle(isp, reqp->req_handle);
4582 * dmasetup sets actual error in packet, and
4583 * return what we were given to return.
4587 isp_xs_prt(isp, xs, ISP_LOGDEBUG0, "START cmd cdb[0]=0x%x datalen %ld", XS_CDBP(xs)[0], (long) XS_XFRLEN(xs));
4589 return (CMD_QUEUED);
4594 * Locks (ints blocked) assumed held.
4598 isp_control(ispsoftc_t *isp, ispctl_t ctl, ...)
4607 case ISPCTL_RESET_BUS:
4609 * Issue a bus reset.
4612 isp_prt(isp, ISP_LOGERR, "BUS RESET NOT IMPLEMENTED");
4614 } else if (IS_FC(isp)) {
4619 chan = va_arg(ap, int);
4621 mbs.param[1] = SDPARAM(isp, chan)->isp_bus_reset_delay;
4622 if (mbs.param[1] < 2) {
4625 mbs.param[2] = chan;
4627 MBSINIT(&mbs, MBOX_BUS_RESET, MBLOGALL, 0);
4628 ISP_SET_SENDMARKER(isp, chan, 1);
4629 isp_mboxcmd(isp, &mbs);
4630 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4633 isp_prt(isp, ISP_LOGINFO, "driver initiated bus reset of bus %d", chan);
4636 case ISPCTL_RESET_DEV:
4638 chan = va_arg(ap, int);
4639 tgt = va_arg(ap, int);
4642 uint8_t local[QENTRY_LEN];
4644 isp24xx_statusreq_t *sp;
4645 fcparam *fcp = FCPARAM(isp, chan);
4648 if (tgt < 0 || tgt >= MAX_FC_TARG) {
4649 isp_prt(isp, ISP_LOGWARN, "Chan %d trying to reset bad target %d", chan, tgt);
4652 lp = &fcp->portdb[tgt];
4653 if (lp->is_target == 0 ||
4654 lp->state != FC_PORTDB_STATE_VALID) {
4655 isp_prt(isp, ISP_LOGWARN, "Chan %d abort of no longer valid target %d", chan, tgt);
4659 tmf = (isp24xx_tmf_t *) local;
4660 ISP_MEMZERO(tmf, QENTRY_LEN);
4661 tmf->tmf_header.rqs_entry_type = RQSTYPE_TSK_MGMT;
4662 tmf->tmf_header.rqs_entry_count = 1;
4663 tmf->tmf_nphdl = lp->handle;
4665 tmf->tmf_timeout = 4;
4666 tmf->tmf_flags = ISP24XX_TMF_TARGET_RESET;
4667 tmf->tmf_tidlo = lp->portid;
4668 tmf->tmf_tidhi = lp->portid >> 16;
4669 tmf->tmf_vpidx = ISP_GET_VPIDX(isp, chan);
4670 isp_prt(isp, ISP_LOGALL, "Chan %d Reset N-Port Handle 0x%04x @ Port 0x%06x", chan, lp->handle, lp->portid);
4671 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL,
4672 MBCMD_DEFAULT_TIMEOUT + tmf->tmf_timeout * 1000000);
4673 mbs.param[1] = QENTRY_LEN;
4674 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
4675 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
4676 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
4677 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
4679 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4680 isp_prt(isp, ISP_LOGERR, sacq);
4683 isp_put_24xx_tmf(isp, tmf, fcp->isp_scratch);
4684 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, QENTRY_LEN, chan);
4685 fcp->sendmarker = 1;
4686 isp_mboxcmd(isp, &mbs);
4687 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4688 FC_SCRATCH_RELEASE(isp, chan);
4691 MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN, QENTRY_LEN, chan);
4692 sp = (isp24xx_statusreq_t *) local;
4693 isp_get_24xx_response(isp, &((isp24xx_statusreq_t *)fcp->isp_scratch)[1], sp);
4694 FC_SCRATCH_RELEASE(isp, chan);
4695 if (sp->req_completion_status == 0) {
4698 isp_prt(isp, ISP_LOGWARN, "Chan %d reset of target %d returned 0x%x", chan, tgt, sp->req_completion_status);
4700 } else if (IS_FC(isp)) {
4701 if (ISP_CAP_2KLOGIN(isp)) {
4703 mbs.ibits = (1 << 10);
4705 mbs.param[1] = (tgt << 8);
4708 mbs.param[1] = (chan << 15) | (tgt << 8);
4710 MBSINIT(&mbs, MBOX_ABORT_TARGET, MBLOGALL, 0);
4711 mbs.param[2] = 3; /* 'delay', in seconds */
4712 isp_mboxcmd(isp, &mbs);
4713 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4716 isp_prt(isp, ISP_LOGINFO, "Target %d on Bus %d Reset Succeeded", tgt, chan);
4717 ISP_SET_SENDMARKER(isp, chan, 1);
4720 case ISPCTL_ABORT_CMD:
4722 xs = va_arg(ap, XS_T *);
4726 chan = XS_CHANNEL(xs);
4728 handle = isp_find_handle(isp, xs);
4730 isp_prt(isp, ISP_LOGWARN, "cannot find handle for command to abort");
4734 isp24xx_abrt_t local, *ab = &local, *ab2;
4738 fcp = FCPARAM(isp, chan);
4739 if (tgt < 0 || tgt >= MAX_FC_TARG) {
4740 isp_prt(isp, ISP_LOGWARN, "Chan %d trying to abort bad target %d", chan, tgt);
4743 lp = &fcp->portdb[tgt];
4744 if (lp->is_target == 0 ||
4745 lp->state != FC_PORTDB_STATE_VALID) {
4746 isp_prt(isp, ISP_LOGWARN, "Chan %d abort of no longer valid target %d", chan, tgt);
4749 isp_prt(isp, ISP_LOGALL, "Chan %d Abort Cmd for N-Port 0x%04x @ Port 0x%06x", chan, lp->handle, lp->portid);
4750 ISP_MEMZERO(ab, QENTRY_LEN);
4751 ab->abrt_header.rqs_entry_type = RQSTYPE_ABORT_IO;
4752 ab->abrt_header.rqs_entry_count = 1;
4753 ab->abrt_handle = lp->handle;
4754 ab->abrt_cmd_handle = handle;
4755 ab->abrt_tidlo = lp->portid;
4756 ab->abrt_tidhi = lp->portid >> 16;
4757 ab->abrt_vpidx = ISP_GET_VPIDX(isp, chan);
4759 ISP_MEMZERO(&mbs, sizeof (mbs));
4760 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 5000000);
4761 mbs.param[1] = QENTRY_LEN;
4762 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
4763 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
4764 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
4765 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
4767 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4768 isp_prt(isp, ISP_LOGERR, sacq);
4771 isp_put_24xx_abrt(isp, ab, fcp->isp_scratch);
4772 ab2 = (isp24xx_abrt_t *) &((uint8_t *)fcp->isp_scratch)[QENTRY_LEN];
4773 ab2->abrt_nphdl = 0xdeaf;
4774 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, 2 * QENTRY_LEN, chan);
4775 isp_mboxcmd(isp, &mbs);
4776 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4777 FC_SCRATCH_RELEASE(isp, chan);
4780 MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN, QENTRY_LEN, chan);
4781 isp_get_24xx_abrt(isp, ab2, ab);
4782 FC_SCRATCH_RELEASE(isp, chan);
4783 if (ab->abrt_nphdl == ISP24XX_ABRT_OKAY) {
4786 isp_prt(isp, ISP_LOGWARN, "Chan %d handle %d abort returned 0x%x", chan, tgt, ab->abrt_nphdl);
4788 } else if (IS_FC(isp)) {
4789 if (ISP_CAP_SCCFW(isp)) {
4790 if (ISP_CAP_2KLOGIN(isp)) {
4793 mbs.param[1] = tgt << 8;
4795 mbs.param[6] = XS_LUN(xs);
4797 mbs.param[1] = tgt << 8 | XS_LUN(xs);
4800 mbs.param[1] = (chan << 15) | (tgt << 8) | XS_LUN(xs);
4802 MBSINIT(&mbs, MBOX_ABORT,
4803 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_ERROR), 0);
4804 mbs.param[2] = handle;
4805 isp_mboxcmd(isp, &mbs);
4806 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4811 case ISPCTL_UPDATE_PARAMS:
4814 chan = va_arg(ap, int);
4816 isp_spi_update(isp, chan);
4819 case ISPCTL_FCLINK_TEST:
4824 chan = va_arg(ap, int);
4825 usdelay = va_arg(ap, int);
4830 return (isp_fclink_test(isp, chan, usdelay));
4834 case ISPCTL_SCAN_FABRIC:
4838 chan = va_arg(ap, int);
4840 return (isp_scan_fabric(isp, chan));
4844 case ISPCTL_SCAN_LOOP:
4848 chan = va_arg(ap, int);
4850 return (isp_scan_loop(isp, chan));
4854 case ISPCTL_PDB_SYNC:
4858 chan = va_arg(ap, int);
4860 return (isp_pdb_sync(isp, chan));
4864 case ISPCTL_SEND_LIP:
4866 if (IS_FC(isp) && !IS_24XX(isp)) {
4867 MBSINIT(&mbs, MBOX_INIT_LIP, MBLOGALL, 0);
4868 if (ISP_CAP_2KLOGIN(isp)) {
4869 mbs.ibits = (1 << 10);
4871 isp_mboxcmd(isp, &mbs);
4872 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
4878 case ISPCTL_GET_PDB:
4882 chan = va_arg(ap, int);
4883 tgt = va_arg(ap, int);
4884 pdb = va_arg(ap, isp_pdb_t *);
4886 return (isp_getpdb(isp, chan, tgt, pdb));
4890 case ISPCTL_GET_NAMES:
4892 uint64_t *wwnn, *wwnp;
4894 chan = va_arg(ap, int);
4895 tgt = va_arg(ap, int);
4896 wwnn = va_arg(ap, uint64_t *);
4897 wwnp = va_arg(ap, uint64_t *);
4899 if (wwnn == NULL && wwnp == NULL) {
4903 *wwnn = isp_get_wwn(isp, chan, tgt, 1);
4904 if (*wwnn == INI_NONE) {
4909 *wwnp = isp_get_wwn(isp, chan, tgt, 0);
4910 if (*wwnp == INI_NONE) {
4916 case ISPCTL_RUN_MBOXCMD:
4919 mbr = va_arg(ap, mbreg_t *);
4921 isp_mboxcmd(isp, mbr);
4930 p = va_arg(ap, isp_plcmd_t *);
4933 if ((p->flags & PLOGX_FLG_CMD_MASK) != PLOGX_FLG_CMD_PLOGI || (p->handle != NIL_HANDLE)) {
4934 return (isp_plogx(isp, p->channel, p->handle, p->portid, p->flags));
4937 isp_next_handle(isp, &p->handle);
4938 r = isp_plogx(isp, p->channel, p->handle, p->portid, p->flags);
4939 if ((r & 0xffff) == MBOX_PORT_ID_USED) {
4940 p->handle = r >> 16;
4944 } while ((r & 0xffff) == MBOX_LOOP_ID_USED);
4947 case ISPCTL_CHANGE_ROLE:
4952 chan = va_arg(ap, int);
4953 role = va_arg(ap, int);
4955 r = isp_fc_change_role(isp, chan, role);
4960 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
4968 * Interrupt Service Routine(s).
4970 * External (OS) framework has done the appropriate locking,
4971 * and the locking will be held throughout this function.
4975 * Limit our stack depth by sticking with the max likely number
4976 * of completions on a request queue at any one time.
4978 #ifndef MAX_REQUESTQ_COMPLETIONS
4979 #define MAX_REQUESTQ_COMPLETIONS 32
4983 isp_intr(ispsoftc_t *isp, uint16_t isr, uint16_t sema, uint16_t info)
4985 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
4986 uint32_t iptr, optr, junk;
4987 int i, nlooked = 0, ndone = 0, continuations_expected = 0;
4988 int etype, last_etype = 0;
4992 * Is this a mailbox related interrupt?
4993 * The mailbox semaphore will be nonzero if so.
4997 if (info & MBOX_COMMAND_COMPLETE) {
4998 isp->isp_intmboxc++;
4999 if (isp->isp_mboxbsy) {
5000 int obits = isp->isp_obits;
5001 isp->isp_mboxtmp[0] = info;
5002 for (i = 1; i < ISP_NMBOX(isp); i++) {
5003 if ((obits & (1 << i)) == 0) {
5006 isp->isp_mboxtmp[i] = ISP_READ(isp, MBOX_OFF(i));
5008 if (isp->isp_mbxwrk0) {
5009 if (isp_mbox_continue(isp) == 0) {
5013 MBOX_NOTIFY_COMPLETE(isp);
5015 isp_prt(isp, ISP_LOGWARN, "mailbox cmd (0x%x) with no waiters", info);
5018 i = IS_FC(isp)? isp_parse_async_fc(isp, info) : isp_parse_async(isp, info);
5023 if ((IS_FC(isp) && info != ASYNC_RIOZIO_STALL) || isp->isp_state != ISP_RUNSTATE) {
5029 * We can't be getting this now.
5031 if (isp->isp_state != ISP_RUNSTATE) {
5033 * This seems to happen to 23XX and 24XX cards- don't know why.
5035 if (isp->isp_mboxbsy && isp->isp_lastmbxcmd == MBOX_ABOUT_FIRMWARE) {
5038 isp_prt(isp, ISP_LOGINFO, "interrupt (ISR=%x SEMA=%x INFO=%x) "
5039 "when not ready", isr, sema, info);
5041 * Thank you very much! *Burrrp*!
5043 isp->isp_residx = ISP_READ(isp, isp->isp_respinrp);
5044 isp->isp_resodx = isp->isp_residx;
5045 ISP_WRITE(isp, isp->isp_respoutrp, isp->isp_resodx);
5047 ISP_DISABLE_INTS(isp);
5052 #ifdef ISP_TARGET_MODE
5054 * Check for ATIO Queue entries.
5057 (isr == ISPR2HST_ATIO_UPDATE || isr == ISPR2HST_ATIO_RSPQ_UPDATE ||
5058 isr == ISPR2HST_ATIO_UPDATE2)) {
5059 iptr = ISP_READ(isp, BIU2400_ATIO_RSPINP);
5060 optr = isp->isp_atioodx;
5062 while (optr != iptr) {
5063 uint8_t qe[QENTRY_LEN];
5069 MEMORYBARRIER(isp, SYNC_ATIOQ, oop, QENTRY_LEN, -1);
5070 addr = ISP_QUEUE_ENTRY(isp->isp_atioq, oop);
5071 isp_get_hdr(isp, addr, (isphdr_t *)qe);
5072 hp = (isphdr_t *)qe;
5073 switch (hp->rqs_entry_type) {
5074 case RQSTYPE_NOTIFY:
5076 (void) isp_target_notify(isp, addr, &oop);
5079 isp_print_qentry(isp, "?ATIOQ entry?", oop, addr);
5082 optr = ISP_NXT_QENTRY(oop, RESULT_QUEUE_LEN(isp));
5084 if (isp->isp_atioodx != optr) {
5085 ISP_WRITE(isp, BIU2400_ATIO_RSPOUTP, optr);
5086 isp->isp_atioodx = optr;
5092 * You *must* read the Response Queue In Pointer
5093 * prior to clearing the RISC interrupt.
5095 * Debounce the 2300 if revision less than 2.
5097 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
5100 iptr = ISP_READ(isp, isp->isp_respinrp);
5101 junk = ISP_READ(isp, isp->isp_respinrp);
5102 } while (junk != iptr && ++i < 1000);
5105 isp_prt(isp, ISP_LOGWARN, "Response Queue Out Pointer Unstable (%x, %x)", iptr, junk);
5109 iptr = ISP_READ(isp, isp->isp_respinrp);
5112 optr = isp->isp_resodx;
5113 if (optr == iptr && sema == 0) {
5115 * There are a lot of these- reasons unknown- mostly on
5116 * faster Alpha machines.
5118 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
5119 * make sure the old interrupt went away (to avoid 'ringing'
5120 * effects), but that didn't stop this from occurring.
5124 } else if (IS_23XX(isp)) {
5126 iptr = ISP_READ(isp, isp->isp_respinrp);
5127 junk = ISP_READ(isp, BIU_R2HSTSLO);
5129 junk = ISP_READ(isp, BIU_ISR);
5132 if (IS_23XX(isp) || IS_24XX(isp)) {
5135 sema = ISP_READ(isp, BIU_SEMA);
5136 info = ISP_READ(isp, OUTMAILBOX0);
5137 if ((sema & 0x3) && (info & 0x8000)) {
5141 isp->isp_intbogus++;
5142 isp_prt(isp, ISP_LOGDEBUG1, "bogus intr- isr %x (%x) iptr %x optr %x", isr, junk, iptr, optr);
5145 isp->isp_residx = iptr;
5147 while (optr != iptr) {
5148 uint8_t qe[QENTRY_LEN];
5149 ispstatusreq_t *sp = (ispstatusreq_t *) qe;
5151 int buddaboom, scsi_status, completion_status;
5152 int req_status_flags, req_state_flags;
5153 uint8_t *snsp, *resp;
5154 uint32_t rlen, slen, totslen;
5158 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
5160 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
5163 buddaboom = req_status_flags = req_state_flags = 0;
5167 * Synchronize our view of this response queue entry.
5169 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN, -1);
5170 if (isp->isp_dblev & ISP_LOGDEBUG1)
5171 isp_print_qentry(isp, "Response Queue Entry", oop, hp);
5172 isp_get_hdr(isp, hp, &sp->req_header);
5173 etype = sp->req_header.rqs_entry_type;
5175 if (IS_24XX(isp) && etype == RQSTYPE_RESPONSE) {
5176 isp24xx_statusreq_t *sp2 = (isp24xx_statusreq_t *)qe;
5177 isp_get_24xx_response(isp, (isp24xx_statusreq_t *)hp, sp2);
5178 scsi_status = sp2->req_scsi_status;
5179 completion_status = sp2->req_completion_status;
5180 if ((scsi_status & 0xff) != 0)
5181 req_state_flags = RQSF_GOT_STATUS;
5183 req_state_flags = 0;
5184 resid = sp2->req_resid;
5185 } else if (etype == RQSTYPE_RESPONSE) {
5186 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
5187 scsi_status = sp->req_scsi_status;
5188 completion_status = sp->req_completion_status;
5189 req_status_flags = sp->req_status_flags;
5190 req_state_flags = sp->req_state_flags;
5191 resid = sp->req_resid;
5192 } else if (etype == RQSTYPE_RIO1) {
5193 isp_rio1_t *rio = (isp_rio1_t *) qe;
5194 isp_get_rio1(isp, (isp_rio1_t *) hp, rio);
5195 for (i = 0; i < rio->req_header.rqs_seqno; i++) {
5196 isp_fastpost_complete(isp, rio->req_handles[i]);
5198 if (isp->isp_fpcchiwater < rio->req_header.rqs_seqno) {
5199 isp->isp_fpcchiwater = rio->req_header.rqs_seqno;
5201 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5204 } else if (etype == RQSTYPE_RIO2) {
5205 isp_prt(isp, ISP_LOGERR, "dropping RIO2 response");
5206 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5209 } else if (etype == RQSTYPE_STATUS_CONT) {
5210 isp_get_cont_response(isp, (ispstatus_cont_t *) hp, (ispstatus_cont_t *) sp);
5211 if (last_etype == RQSTYPE_RESPONSE && continuations_expected && ndone > 0 && (xs = complist[ndone-1]) != NULL) {
5212 ispstatus_cont_t *scp = (ispstatus_cont_t *) sp;
5213 XS_SENSE_APPEND(xs, scp->req_sense_data, sizeof (scp->req_sense_data));
5214 isp_prt(isp, ISP_LOGDEBUG0|ISP_LOG_CWARN, "%d more Status Continuations expected", --continuations_expected);
5216 isp_prt(isp, ISP_LOG_WARN1, "Ignored Continuation Response");
5218 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5222 * Somebody reachable via isp_handle_other_response
5223 * may have updated the response queue pointers for
5224 * us, so we reload our goal index.
5227 uint32_t tsto = oop;
5228 r = isp_handle_other_response(isp, etype, hp, &tsto);
5233 * If somebody updated the output pointer, then reset
5234 * optr to be one more than the updated amount.
5236 while (tsto != oop) {
5237 optr = ISP_NXT_QENTRY(tsto, RESULT_QUEUE_LEN(isp));
5240 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5246 * After this point, we'll just look at the header as
5247 * we don't know how to deal with the rest of the
5252 * It really has to be a bounced request just copied
5253 * from the request queue to the response queue. If
5254 * not, something bad has happened.
5256 if (etype != RQSTYPE_REQUEST) {
5257 isp_prt(isp, ISP_LOGERR, notresp, etype, oop, optr, nlooked);
5258 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5263 scsi_status = sp->req_scsi_status;
5264 completion_status = sp->req_completion_status;
5265 req_status_flags = sp->req_status_flags;
5266 req_state_flags = sp->req_state_flags;
5267 resid = sp->req_resid;
5270 if (sp->req_header.rqs_flags & RQSFLAG_MASK) {
5271 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
5272 isp_print_qentry(isp, "unexpected continuation segment",
5277 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
5278 isp_prt(isp, ISP_LOG_WARN1, "internal queues full");
5280 * We'll synthesize a QUEUE FULL message below.
5283 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
5284 isp_print_qentry(isp, "bad header flag",
5288 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
5289 isp_print_qentry(isp, "bad request packet",
5293 if (sp->req_header.rqs_flags & RQSFLAG_BADCOUNT) {
5294 isp_print_qentry(isp, "invalid entry count",
5298 if (sp->req_header.rqs_flags & RQSFLAG_BADORDER) {
5299 isp_print_qentry(isp, "invalid IOCB ordering",
5306 xs = isp_find_xs(isp, sp->req_handle);
5308 uint8_t ts = completion_status & 0xff;
5310 * Only whine if this isn't the expected fallout of
5311 * aborting the command or resetting the target.
5313 if (etype != RQSTYPE_RESPONSE) {
5314 isp_prt(isp, ISP_LOGERR, "cannot find handle 0x%x (type 0x%x)", sp->req_handle, etype);
5315 } else if (ts != RQCS_ABORTED && ts != RQCS_RESET_OCCURRED) {
5316 isp_prt(isp, ISP_LOGERR, "cannot find handle 0x%x (status 0x%x)", sp->req_handle, ts);
5318 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5322 if (req_status_flags & RQSTF_BUS_RESET) {
5323 isp_prt(isp, ISP_LOG_WARN1, "%d.%d.%jx bus was reset",
5324 XS_CHANNEL(xs), XS_TGT(xs), (uintmax_t)XS_LUN(xs));
5325 XS_SETERR(xs, HBA_BUSRESET);
5326 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 1);
5329 isp_prt(isp, ISP_LOG_WARN1, "%d.%d.%jx buddaboom",
5330 XS_CHANNEL(xs), XS_TGT(xs), (uintmax_t)XS_LUN(xs));
5331 XS_SETERR(xs, HBA_BOTCH);
5338 if (IS_24XX(isp) && (scsi_status & (RQCS_RV|RQCS_SV)) != 0) {
5339 resp = ((isp24xx_statusreq_t *)sp)->req_rsp_sense;
5340 rlen = ((isp24xx_statusreq_t *)sp)->req_response_len;
5341 } else if (IS_FC(isp) && (scsi_status & RQCS_RV) != 0) {
5342 resp = sp->req_response;
5343 rlen = sp->req_response_len;
5345 if (IS_FC(isp) && (scsi_status & RQCS_SV) != 0) {
5347 * Fibre Channel F/W doesn't say we got status
5348 * if there's Sense Data instead. I guess they
5349 * think it goes w/o saying.
5351 req_state_flags |= RQSF_GOT_STATUS|RQSF_GOT_SENSE;
5353 snsp = ((isp24xx_statusreq_t *)sp)->req_rsp_sense;
5355 totslen = ((isp24xx_statusreq_t *)sp)->req_sense_len;
5356 slen = (sizeof (((isp24xx_statusreq_t *)sp)->req_rsp_sense)) - rlen;
5360 snsp = sp->req_sense_data;
5361 totslen = sp->req_sense_len;
5362 slen = sizeof (sp->req_sense_data);
5366 } else if (IS_SCSI(isp) && (req_state_flags & RQSF_GOT_SENSE)) {
5367 snsp = sp->req_sense_data;
5368 totslen = sp->req_sense_len;
5369 slen = sizeof (sp->req_sense_data);
5373 if (req_state_flags & RQSF_GOT_STATUS) {
5374 *XS_STSP(xs) = scsi_status & 0xff;
5378 case RQSTYPE_RESPONSE:
5379 if (resp && rlen >= 4 && resp[FCP_RSPNS_CODE_OFFSET] != 0) {
5382 const char *rnames[10] = {
5383 "Task Management function complete",
5384 "FCP_DATA length different than FCP_BURST_LEN",
5385 "FCP_CMND fields invalid",
5386 "FCP_DATA parameter mismatch with FCP_DATA_RO",
5387 "Task Management function rejected",
5388 "Task Management function failed",
5391 "Task Management function succeeded",
5392 "Task Management function incorrect logical unit number",
5394 uint8_t code = resp[FCP_RSPNS_CODE_OFFSET];
5395 if (code >= 10 || rnames[code] == NULL) {
5396 ISP_SNPRINTF(lb, sizeof(lb),
5397 "Unknown FCP Response Code 0x%x",
5403 isp_xs_prt(isp, xs, ISP_LOGWARN,
5404 "FCP RESPONSE, LENGTH %u: %s CDB0=0x%02x",
5405 rlen, ptr, XS_CDBP(xs)[0] & 0xff);
5406 if (code != 0 && code != 8)
5407 XS_SETERR(xs, HBA_BOTCH);
5410 isp_parse_status_24xx(isp, (isp24xx_statusreq_t *)sp, xs, &resid);
5412 isp_parse_status(isp, (void *)sp, xs, &resid);
5414 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) && (*XS_STSP(xs) == SCSI_BUSY)) {
5415 XS_SETERR(xs, HBA_TGTBSY);
5418 XS_SET_RESID(xs, resid);
5420 * A new synchronous rate was negotiated for
5421 * this target. Mark state such that we'll go
5422 * look up that which has changed later.
5424 if (req_status_flags & RQSTF_NEGOTIATION) {
5426 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
5427 sdp->isp_devparam[t].dev_refresh = 1;
5431 if (req_status_flags & RQSF_XFER_COMPLETE) {
5432 XS_SET_RESID(xs, 0);
5433 } else if (scsi_status & RQCS_RESID) {
5434 XS_SET_RESID(xs, resid);
5436 XS_SET_RESID(xs, 0);
5440 if (totslen > slen) {
5441 continuations_expected += ((totslen - slen + QENTRY_LEN - 5) / (QENTRY_LEN - 4));
5442 if (ndone > (MAX_REQUESTQ_COMPLETIONS - continuations_expected - 1)) {
5443 /* we'll lose some stats, but that's a small price to pay */
5444 for (i = 0; i < ndone; i++) {
5446 isp->isp_rsltccmplt++;
5447 isp_done(complist[i]);
5452 isp_prt(isp, ISP_LOGDEBUG0|ISP_LOG_CWARN, "Expecting %d more Status Continuations for total sense length of %u",
5453 continuations_expected, totslen);
5455 XS_SAVE_SENSE(xs, snsp, totslen, slen);
5456 } else if ((req_status_flags & RQSF_GOT_STATUS) && (scsi_status & 0xff) == SCSI_CHECK && IS_FC(isp)) {
5457 isp_prt(isp, ISP_LOGWARN, "CHECK CONDITION w/o sense data for CDB=0x%x", XS_CDBP(xs)[0] & 0xff);
5458 isp_print_qentry(isp, "CC with no Sense",
5461 isp_prt(isp, ISP_LOGDEBUG2, "asked for %ld got raw resid %ld settled for %ld", (long) XS_XFRLEN(xs), resid, (long) XS_GET_RESID(xs));
5463 case RQSTYPE_REQUEST:
5468 if (!IS_24XX(isp) && (sp->req_header.rqs_flags & RQSFLAG_FULL)) {
5470 * Force Queue Full status.
5472 *XS_STSP(xs) = SCSI_QFULL;
5473 XS_SETERR(xs, HBA_NOERROR);
5474 } else if (XS_NOERR(xs)) {
5475 isp_prt(isp, ISP_LOG_WARN1,
5476 "%d.%d.%jx badness at %s:%u",
5477 XS_CHANNEL(xs), XS_TGT(xs),
5478 (uintmax_t)XS_LUN(xs),
5479 __func__, __LINE__);
5480 XS_SETERR(xs, HBA_BOTCH);
5482 XS_SET_RESID(xs, XS_XFRLEN(xs));
5485 isp_print_qentry(isp, "Unhandled Response Type",
5488 XS_SETERR(xs, HBA_BOTCH);
5494 * Free any DMA resources. As a side effect, this may
5495 * also do any cache flushing necessary for data coherence.
5497 if (XS_XFRLEN(xs)) {
5498 ISP_DMAFREE(isp, xs, sp->req_handle);
5500 isp_destroy_handle(isp, sp->req_handle);
5502 if (isp->isp_nactive > 0) {
5505 complist[ndone++] = xs; /* defer completion call until later */
5506 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5508 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
5514 * If we looked at any commands, then it's valid to find out
5515 * what the outpointer is. It also is a trigger to update the
5516 * ISP's notion of what we've seen so far.
5519 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5520 isp->isp_resodx = optr;
5521 if (isp->isp_rscchiwater < ndone)
5522 isp->isp_rscchiwater = ndone;
5528 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
5530 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
5531 ISP_WRITE(isp, BIU_SEMA, 0);
5534 for (i = 0; i < ndone; i++) {
5537 if (((isp->isp_dblev & (ISP_LOGDEBUG1|ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
5538 ((isp->isp_dblev & (ISP_LOGDEBUG0|ISP_LOG_CWARN) && ((!XS_NOERR(xs)) || (*XS_STSP(xs) != SCSI_GOOD))))) {
5539 isp_prt_endcmd(isp, xs);
5541 isp->isp_rsltccmplt++;
5552 isp_prt_endcmd(ispsoftc_t *isp, XS_T *xs)
5554 char cdbstr[16 * 5 + 1];
5557 lim = XS_CDBLEN(xs) > 16? 16 : XS_CDBLEN(xs);
5558 ISP_SNPRINTF(cdbstr, sizeof (cdbstr), "0x%02x ", XS_CDBP(xs)[0]);
5559 for (i = 1; i < lim; i++) {
5560 ISP_SNPRINTF(cdbstr, sizeof (cdbstr), "%s0x%02x ", cdbstr, XS_CDBP(xs)[i]);
5562 if (XS_SENSE_VALID(xs)) {
5563 isp_xs_prt(isp, xs, ISP_LOGALL, "FIN dl%d resid %ld CDB=%s SenseLength=%u/%u KEY/ASC/ASCQ=0x%02x/0x%02x/0x%02x",
5564 XS_XFRLEN(xs), (long) XS_GET_RESID(xs), cdbstr, XS_CUR_SNSLEN(xs), XS_TOT_SNSLEN(xs), XS_SNSKEY(xs), XS_SNSASC(xs), XS_SNSASCQ(xs));
5566 isp_xs_prt(isp, xs, ISP_LOGALL, "FIN dl%d resid %ld CDB=%s STS 0x%x XS_ERR=0x%x", XS_XFRLEN(xs), (long) XS_GET_RESID(xs), cdbstr, *XS_STSP(xs), XS_ERR(xs));
5571 * Parse an ASYNC mailbox complete
5573 * Return non-zero if the event has been acknowledged.
5576 isp_parse_async(ispsoftc_t *isp, uint16_t mbox)
5579 uint32_t h1 = 0, h2 = 0;
5583 * Pick up the channel, but not if this is a ASYNC_RIO32_2,
5584 * where Mailboxes 6/7 have the second handle.
5586 if (mbox != ASYNC_RIO32_2) {
5587 if (IS_DUALBUS(isp)) {
5588 chan = ISP_READ(isp, OUTMAILBOX6);
5591 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
5594 case ASYNC_BUS_RESET:
5595 ISP_SET_SENDMARKER(isp, chan, 1);
5596 #ifdef ISP_TARGET_MODE
5597 if (isp_target_async(isp, chan, mbox)) {
5601 isp_async(isp, ISPASYNC_BUS_RESET, chan);
5603 case ASYNC_SYSTEM_ERROR:
5605 isp->isp_state = ISP_CRASHED;
5607 * Were we waiting for a mailbox command to complete?
5608 * If so, it's dead, so wake up the waiter.
5610 if (isp->isp_mboxbsy) {
5612 isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR;
5613 MBOX_NOTIFY_COMPLETE(isp);
5616 * It's up to the handler for isp_async to reinit stuff and
5617 * restart the firmware
5619 isp_async(isp, ISPASYNC_FW_CRASH);
5623 case ASYNC_RQS_XFER_ERR:
5624 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
5627 case ASYNC_RSP_XFER_ERR:
5628 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
5633 * We've just been notified that the Queue has woken up.
5634 * We don't need to be chatty about this- just unlatch things
5637 mbox = ISP_READ(isp, isp->isp_rqstoutrp);
5640 case ASYNC_TIMEOUT_RESET:
5641 isp_prt(isp, ISP_LOGWARN, "timeout initiated SCSI bus reset of chan %d", chan);
5642 ISP_SET_SENDMARKER(isp, chan, 1);
5643 #ifdef ISP_TARGET_MODE
5644 if (isp_target_async(isp, chan, mbox)) {
5650 case ASYNC_DEVICE_RESET:
5651 isp_prt(isp, ISP_LOGINFO, "device reset on chan %d", chan);
5652 ISP_SET_SENDMARKER(isp, chan, 1);
5653 #ifdef ISP_TARGET_MODE
5654 if (isp_target_async(isp, chan, mbox)) {
5660 case ASYNC_EXTMSG_UNDERRUN:
5661 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
5664 case ASYNC_SCAM_INT:
5665 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
5668 case ASYNC_HUNG_SCSI:
5669 isp_prt(isp, ISP_LOGERR, "stalled SCSI Bus after DATA Overrun");
5670 /* XXX: Need to issue SCSI reset at this point */
5673 case ASYNC_KILLED_BUS:
5674 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
5677 case ASYNC_BUS_TRANSIT:
5678 mbox = ISP_READ(isp, OUTMAILBOX2);
5679 switch (mbox & SXP_PINS_MODE_MASK) {
5680 case SXP_PINS_LVD_MODE:
5681 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
5682 SDPARAM(isp, chan)->isp_diffmode = 0;
5683 SDPARAM(isp, chan)->isp_ultramode = 0;
5684 SDPARAM(isp, chan)->isp_lvdmode = 1;
5686 case SXP_PINS_HVD_MODE:
5687 isp_prt(isp, ISP_LOGINFO,
5688 "Transition to Differential mode");
5689 SDPARAM(isp, chan)->isp_diffmode = 1;
5690 SDPARAM(isp, chan)->isp_ultramode = 0;
5691 SDPARAM(isp, chan)->isp_lvdmode = 0;
5693 case SXP_PINS_SE_MODE:
5694 isp_prt(isp, ISP_LOGINFO,
5695 "Transition to Single Ended mode");
5696 SDPARAM(isp, chan)->isp_diffmode = 0;
5697 SDPARAM(isp, chan)->isp_ultramode = 1;
5698 SDPARAM(isp, chan)->isp_lvdmode = 0;
5701 isp_prt(isp, ISP_LOGWARN,
5702 "Transition to Unknown Mode 0x%x", mbox);
5706 * XXX: Set up to renegotiate again!
5708 /* Can only be for a 1080... */
5709 ISP_SET_SENDMARKER(isp, chan, 1);
5712 case ASYNC_CMD_CMPLT:
5714 if (!IS_ULTRA3(isp)) {
5715 isp_prt(isp, ISP_LOGERR, "unexpected fast posting completion");
5719 h1 = (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1);
5723 h1 = (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1);
5724 h2 = (ISP_READ(isp, OUTMAILBOX7) << 16) | ISP_READ(isp, OUTMAILBOX6);
5732 isp_prt(isp, ISP_LOGERR, "unexpected 16 bit RIO handle");
5735 isp_prt(isp, ISP_LOGWARN, "%s: unhandled async code 0x%x", __func__, mbox);
5740 isp_prt(isp, ISP_LOGDEBUG3, "fast post/rio completion of 0x%08x", h1);
5741 isp_fastpost_complete(isp, h1);
5743 isp_prt(isp, ISP_LOGDEBUG3, "fast post/rio completion of 0x%08x", h2);
5744 isp_fastpost_complete(isp, h2);
5745 if (isp->isp_fpcchiwater < 2) {
5746 isp->isp_fpcchiwater = 2;
5749 if (isp->isp_fpcchiwater < 1) {
5750 isp->isp_fpcchiwater = 1;
5754 isp->isp_intoasync++;
5760 isp_parse_async_fc(ispsoftc_t *isp, uint16_t mbox)
5766 if (IS_DUALBUS(isp)) {
5767 chan = ISP_READ(isp, OUTMAILBOX6);
5771 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
5774 case ASYNC_SYSTEM_ERROR:
5776 isp->isp_state = ISP_CRASHED;
5777 FCPARAM(isp, chan)->isp_loopstate = LOOP_NIL;
5778 isp_change_fw_state(isp, chan, FW_CONFIG_WAIT);
5780 * Were we waiting for a mailbox command to complete?
5781 * If so, it's dead, so wake up the waiter.
5783 if (isp->isp_mboxbsy) {
5785 isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR;
5786 MBOX_NOTIFY_COMPLETE(isp);
5789 * It's up to the handler for isp_async to reinit stuff and
5790 * restart the firmware
5792 isp_async(isp, ISPASYNC_FW_CRASH);
5796 case ASYNC_RQS_XFER_ERR:
5797 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
5800 case ASYNC_RSP_XFER_ERR:
5801 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
5805 #ifdef ISP_TARGET_MODE
5807 isp_prt(isp, ISP_LOGERR, "ATIO Queue Transfer Error");
5811 isp_prt(isp, ISP_LOGERR, "%s: unexpected ASYNC_QWAKEUP code", __func__);
5814 case ASYNC_CMD_CMPLT:
5815 isp_fastpost_complete(isp, (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1));
5816 if (isp->isp_fpcchiwater < 1) {
5817 isp->isp_fpcchiwater = 1;
5821 case ASYNC_RIOZIO_STALL:
5824 case ASYNC_CTIO_DONE:
5825 #ifdef ISP_TARGET_MODE
5826 if (isp_target_async(isp, (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1), mbox)) {
5829 isp->isp_fphccmplt++;
5832 isp_prt(isp, ISP_LOGWARN, "unexpected ASYNC CTIO done");
5835 case ASYNC_LIP_ERROR:
5836 case ASYNC_LIP_NOS_OLS_RECV:
5837 case ASYNC_LIP_OCCURRED:
5840 * These are broadcast events that have to be sent across
5841 * all active channels.
5843 for (chan = 0; chan < isp->isp_nchan; chan++) {
5844 fcp = FCPARAM(isp, chan);
5845 int topo = fcp->isp_topo;
5847 if (fcp->role == ISP_ROLE_NONE)
5849 if (fcp->isp_loopstate > LOOP_HAVE_LINK)
5850 fcp->isp_loopstate = LOOP_HAVE_LINK;
5851 ISP_SET_SENDMARKER(isp, chan, 1);
5852 isp_async(isp, ISPASYNC_LIP, chan);
5853 #ifdef ISP_TARGET_MODE
5854 if (isp_target_async(isp, chan, mbox)) {
5859 * We've had problems with data corruption occuring on
5860 * commands that complete (with no apparent error) after
5861 * we receive a LIP. This has been observed mostly on
5862 * Local Loop topologies. To be safe, let's just mark
5863 * all active initiator commands as dead.
5865 if (topo == TOPO_NL_PORT || topo == TOPO_FL_PORT) {
5867 for (i = j = 0; i < isp->isp_maxcmds; i++) {
5871 hdp = &isp->isp_xflist[i];
5872 if (ISP_H2HT(hdp->handle) != ISP_HANDLE_INITIATOR) {
5876 if (XS_CHANNEL(xs) != chan) {
5880 isp_prt(isp, ISP_LOG_WARN1,
5881 "%d.%d.%jx bus reset set at %s:%u",
5882 XS_CHANNEL(xs), XS_TGT(xs),
5883 (uintmax_t)XS_LUN(xs),
5884 __func__, __LINE__);
5885 XS_SETERR(xs, HBA_BUSRESET);
5888 isp_prt(isp, ISP_LOGERR, lipd, chan, j);
5896 * This is a broadcast event that has to be sent across
5897 * all active channels.
5899 for (chan = 0; chan < isp->isp_nchan; chan++) {
5900 fcp = FCPARAM(isp, chan);
5901 if (fcp->role == ISP_ROLE_NONE)
5903 fcp->isp_linkstate = 1;
5904 if (fcp->isp_loopstate < LOOP_HAVE_LINK)
5905 fcp->isp_loopstate = LOOP_HAVE_LINK;
5906 ISP_SET_SENDMARKER(isp, chan, 1);
5907 isp_async(isp, ISPASYNC_LOOP_UP, chan);
5908 #ifdef ISP_TARGET_MODE
5909 if (isp_target_async(isp, chan, mbox)) {
5916 case ASYNC_LOOP_DOWN:
5918 * This is a broadcast event that has to be sent across
5919 * all active channels.
5921 for (chan = 0; chan < isp->isp_nchan; chan++) {
5922 fcp = FCPARAM(isp, chan);
5923 if (fcp->role == ISP_ROLE_NONE)
5925 ISP_SET_SENDMARKER(isp, chan, 1);
5926 fcp->isp_linkstate = 0;
5927 fcp->isp_loopstate = LOOP_NIL;
5928 isp_async(isp, ISPASYNC_LOOP_DOWN, chan);
5929 #ifdef ISP_TARGET_MODE
5930 if (isp_target_async(isp, chan, mbox)) {
5937 case ASYNC_LOOP_RESET:
5939 * This is a broadcast event that has to be sent across
5940 * all active channels.
5942 for (chan = 0; chan < isp->isp_nchan; chan++) {
5943 fcp = FCPARAM(isp, chan);
5944 if (fcp->role == ISP_ROLE_NONE)
5946 ISP_SET_SENDMARKER(isp, chan, 1);
5947 if (fcp->isp_loopstate > LOOP_HAVE_LINK)
5948 fcp->isp_loopstate = LOOP_HAVE_LINK;
5949 isp_async(isp, ISPASYNC_LOOP_RESET, chan);
5950 #ifdef ISP_TARGET_MODE
5951 if (isp_target_async(isp, chan, mbox)) {
5958 case ASYNC_PDB_CHANGED:
5960 int echan, nphdl, nlstate, reason;
5962 if (IS_23XX(isp) || IS_24XX(isp)) {
5963 nphdl = ISP_READ(isp, OUTMAILBOX1);
5964 nlstate = ISP_READ(isp, OUTMAILBOX2);
5966 nphdl = nlstate = 0xffff;
5969 reason = ISP_READ(isp, OUTMAILBOX3) >> 8;
5972 if (ISP_CAP_MULTI_ID(isp)) {
5973 chan = ISP_READ(isp, OUTMAILBOX3) & 0xff;
5974 if (chan == 0xff || nphdl == NIL_HANDLE) {
5976 echan = isp->isp_nchan - 1;
5977 } else if (chan >= isp->isp_nchan) {
5985 for (; chan <= echan; chan++) {
5986 fcp = FCPARAM(isp, chan);
5987 if (fcp->role == ISP_ROLE_NONE)
5989 if (fcp->isp_loopstate > LOOP_LTEST_DONE)
5990 fcp->isp_loopstate = LOOP_LTEST_DONE;
5991 else if (fcp->isp_loopstate < LOOP_HAVE_LINK)
5992 fcp->isp_loopstate = LOOP_HAVE_LINK;
5993 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan,
5994 ISPASYNC_CHANGE_PDB, nphdl, nlstate, reason);
5998 case ASYNC_CHANGE_NOTIFY:
6002 portid = ((ISP_READ(isp, OUTMAILBOX1) & 0xff) << 16) |
6003 ISP_READ(isp, OUTMAILBOX2);
6004 if (ISP_CAP_MULTI_ID(isp)) {
6005 chan = ISP_READ(isp, OUTMAILBOX3) & 0xff;
6006 if (chan >= isp->isp_nchan)
6011 fcp = FCPARAM(isp, chan);
6012 if (fcp->role == ISP_ROLE_NONE)
6014 if (fcp->isp_loopstate > LOOP_LTEST_DONE)
6015 fcp->isp_loopstate = LOOP_LTEST_DONE;
6016 else if (fcp->isp_loopstate < LOOP_HAVE_LINK)
6017 fcp->isp_loopstate = LOOP_HAVE_LINK;
6018 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan,
6019 ISPASYNC_CHANGE_SNS, portid);
6022 case ASYNC_ERR_LOGGING_DISABLED:
6023 isp_prt(isp, ISP_LOGWARN, "Error logging disabled (reason 0x%x)",
6024 ISP_READ(isp, OUTMAILBOX1));
6026 case ASYNC_CONNMODE:
6028 * This only applies to 2100 amd 2200 cards
6030 if (!IS_2200(isp) && !IS_2100(isp)) {
6031 isp_prt(isp, ISP_LOGWARN, "bad card for ASYNC_CONNMODE event");
6035 mbox = ISP_READ(isp, OUTMAILBOX1);
6038 isp_prt(isp, ISP_LOGINFO,
6039 "Point-to-Point -> Loop mode");
6042 isp_prt(isp, ISP_LOGINFO,
6043 "Loop -> Point-to-Point mode");
6045 case ISP_CONN_BADLIP:
6046 isp_prt(isp, ISP_LOGWARN,
6047 "Point-to-Point -> Loop mode (BAD LIP)");
6049 case ISP_CONN_FATAL:
6051 isp->isp_state = ISP_CRASHED;
6052 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
6053 isp_async(isp, ISPASYNC_FW_CRASH);
6055 case ISP_CONN_LOOPBACK:
6056 isp_prt(isp, ISP_LOGWARN,
6057 "Looped Back in Point-to-Point mode");
6060 isp_prt(isp, ISP_LOGWARN,
6061 "Unknown connection mode (0x%x)", mbox);
6064 ISP_SET_SENDMARKER(isp, chan, 1);
6065 FCPARAM(isp, chan)->isp_loopstate = LOOP_HAVE_LINK;
6066 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan, ISPASYNC_CHANGE_OTHER);
6068 case ASYNC_P2P_INIT_ERR:
6069 isp_prt(isp, ISP_LOGWARN, "P2P init error (reason 0x%x)",
6070 ISP_READ(isp, OUTMAILBOX1));
6074 isp_prt(isp, ISP_LOGWARN, "Receive Error");
6076 isp_prt(isp, ISP_LOGWARN, "unexpected ASYNC_RCV_ERR");
6079 case ASYNC_RJT_SENT: /* same as ASYNC_QFULL_SENT */
6081 isp_prt(isp, ISP_LOGTDEBUG0, "LS_RJT sent");
6084 isp_prt(isp, ISP_LOGTDEBUG0, "QFULL sent");
6087 case ASYNC_FW_RESTART_COMPLETE:
6088 isp_prt(isp, ISP_LOGDEBUG0, "FW restart complete");
6090 case ASYNC_TEMPERATURE_ALERT:
6091 isp_prt(isp, ISP_LOGERR, "Temperature alert (subcode 0x%x)",
6092 ISP_READ(isp, OUTMAILBOX1));
6094 case ASYNC_AUTOLOAD_FW_COMPLETE:
6095 isp_prt(isp, ISP_LOGDEBUG0, "Autoload FW init complete");
6097 case ASYNC_AUTOLOAD_FW_FAILURE:
6098 isp_prt(isp, ISP_LOGERR, "Autoload FW init failure");
6101 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
6104 if (mbox != ASYNC_CTIO_DONE && mbox != ASYNC_CMD_CMPLT) {
6105 isp->isp_intoasync++;
6111 * Handle other response entries. A pointer to the request queue output
6112 * index is here in case we want to eat several entries at once, although
6113 * this is not used currently.
6117 isp_handle_other_response(ispsoftc_t *isp, int type, isphdr_t *hp, uint32_t *optrp)
6125 case RQSTYPE_STATUS_CONT:
6126 isp_prt(isp, ISP_LOG_WARN1, "Ignored Continuation Response");
6128 case RQSTYPE_MARKER:
6129 isp_prt(isp, ISP_LOG_WARN1, "Marker Response");
6131 case RQSTYPE_RPT_ID_ACQ:
6132 isp_get_ridacq(isp, (isp_ridacq_t *)hp, &rid);
6133 if (rid.ridacq_format == 0) {
6134 for (chan = 0; chan < isp->isp_nchan; chan++) {
6135 fcparam *fcp = FCPARAM(isp, chan);
6136 if (fcp->role == ISP_ROLE_NONE)
6138 c = (chan == 0) ? 127 : (chan - 1);
6139 if (rid.ridacq_map[c / 16] & (1 << (c % 16)) ||
6141 fcp->isp_loopstate = LOOP_HAVE_LINK;
6142 isp_async(isp, ISPASYNC_CHANGE_NOTIFY,
6143 chan, ISPASYNC_CHANGE_OTHER);
6145 fcp->isp_loopstate = LOOP_NIL;
6146 isp_async(isp, ISPASYNC_LOOP_DOWN,
6151 fcparam *fcp = FCPARAM(isp, rid.ridacq_vp_index);
6152 if (rid.ridacq_vp_status == RIDACQ_STS_COMPLETE ||
6153 rid.ridacq_vp_status == RIDACQ_STS_CHANGED) {
6154 fcp->isp_loopstate = LOOP_HAVE_LINK;
6155 isp_async(isp, ISPASYNC_CHANGE_NOTIFY,
6156 rid.ridacq_vp_index, ISPASYNC_CHANGE_OTHER);
6158 fcp->isp_loopstate = LOOP_NIL;
6159 isp_async(isp, ISPASYNC_LOOP_DOWN,
6160 rid.ridacq_vp_index);
6164 case RQSTYPE_VP_MODIFY:
6165 case RQSTYPE_VP_CTRL:
6167 ISP_IOXGET_32(isp, (uint32_t *)(hp + 1), hdl);
6168 ptr = isp_find_xs(isp, hdl);
6170 isp_destroy_handle(isp, hdl);
6171 memcpy(ptr, hp, QENTRY_LEN);
6177 case RQSTYPE_ENABLE_LUN:
6178 case RQSTYPE_MODIFY_LUN:
6179 case RQSTYPE_NOTIFY:
6180 case RQSTYPE_NOTIFY_ACK:
6186 case RQSTYPE_ABTS_RCVD:
6187 case RQSTYPE_ABTS_RSP:
6188 isp->isp_rsltccmplt++; /* count as a response completion */
6189 #ifdef ISP_TARGET_MODE
6190 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
6195 case RQSTYPE_REQUEST:
6198 if (type != isp_get_response_type(isp, hp)) {
6200 * This is questionable- we're just papering over
6201 * something we've seen on SMP linux in target
6202 * mode- we don't really know what's happening
6203 * here that causes us to think we've gotten
6204 * an entry, but that either the entry isn't
6205 * filled out yet or our CPU read data is stale.
6207 isp_prt(isp, ISP_LOGINFO,
6208 "unstable type in response queue");
6211 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
6212 isp_get_response_type(isp, hp));
6218 isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
6220 switch (sp->req_completion_status & 0xff) {
6223 XS_SETERR(xs, HBA_NOERROR);
6227 case RQCS_INCOMPLETE:
6228 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
6229 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "Selection Timeout @ %s:%d", __func__, __LINE__);
6231 XS_SETERR(xs, HBA_SELTIMEOUT);
6232 *rp = XS_XFRLEN(xs);
6236 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Incomplete, state 0x%x", sp->req_state_flags);
6239 case RQCS_DMA_ERROR:
6240 isp_xs_prt(isp, xs, ISP_LOGERR, "DMA Error");
6241 *rp = XS_XFRLEN(xs);
6244 case RQCS_TRANSPORT_ERROR:
6247 ISP_SNPRINTF(buf, sizeof (buf), "states=>");
6248 if (sp->req_state_flags & RQSF_GOT_BUS) {
6249 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
6251 if (sp->req_state_flags & RQSF_GOT_TARGET) {
6252 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
6254 if (sp->req_state_flags & RQSF_SENT_CDB) {
6255 ISP_SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
6257 if (sp->req_state_flags & RQSF_XFRD_DATA) {
6258 ISP_SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
6260 if (sp->req_state_flags & RQSF_GOT_STATUS) {
6261 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
6263 if (sp->req_state_flags & RQSF_GOT_SENSE) {
6264 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
6266 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
6267 ISP_SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
6269 ISP_SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
6270 if (sp->req_status_flags & RQSTF_DISCONNECT) {
6271 ISP_SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
6273 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
6274 ISP_SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
6276 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
6277 ISP_SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
6279 if (sp->req_status_flags & RQSTF_BUS_RESET) {
6280 ISP_SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
6282 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
6283 ISP_SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
6285 if (sp->req_status_flags & RQSTF_ABORTED) {
6286 ISP_SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
6288 if (sp->req_status_flags & RQSTF_TIMEOUT) {
6289 ISP_SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
6291 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
6292 ISP_SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
6294 isp_xs_prt(isp, xs, ISP_LOGERR, "Transport Error: %s", buf);
6295 *rp = XS_XFRLEN(xs);
6298 case RQCS_RESET_OCCURRED:
6301 isp_xs_prt(isp, xs, ISP_LOGWARN, "Bus Reset destroyed command");
6302 for (chan = 0; chan < isp->isp_nchan; chan++) {
6303 FCPARAM(isp, chan)->sendmarker = 1;
6306 XS_SETERR(xs, HBA_BUSRESET);
6308 *rp = XS_XFRLEN(xs);
6312 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Aborted");
6313 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 1);
6315 XS_SETERR(xs, HBA_ABORTED);
6320 isp_xs_prt(isp, xs, ISP_LOGWARN, "Command timed out");
6322 * XXX: Check to see if we logged out of the device.
6325 XS_SETERR(xs, HBA_CMDTIMEOUT);
6329 case RQCS_DATA_OVERRUN:
6330 XS_SET_RESID(xs, sp->req_resid);
6331 isp_xs_prt(isp, xs, ISP_LOGERR, "data overrun (%ld)", (long) XS_GET_RESID(xs));
6333 XS_SETERR(xs, HBA_DATAOVR);
6337 case RQCS_COMMAND_OVERRUN:
6338 isp_xs_prt(isp, xs, ISP_LOGERR, "command overrun");
6341 case RQCS_STATUS_OVERRUN:
6342 isp_xs_prt(isp, xs, ISP_LOGERR, "status overrun");
6345 case RQCS_BAD_MESSAGE:
6346 isp_xs_prt(isp, xs, ISP_LOGERR, "msg not COMMAND COMPLETE after status");
6349 case RQCS_NO_MESSAGE_OUT:
6350 isp_xs_prt(isp, xs, ISP_LOGERR, "No MESSAGE OUT phase after selection");
6353 case RQCS_EXT_ID_FAILED:
6354 isp_xs_prt(isp, xs, ISP_LOGERR, "EXTENDED IDENTIFY failed");
6357 case RQCS_IDE_MSG_FAILED:
6358 isp_xs_prt(isp, xs, ISP_LOGERR, "INITIATOR DETECTED ERROR rejected");
6361 case RQCS_ABORT_MSG_FAILED:
6362 isp_xs_prt(isp, xs, ISP_LOGERR, "ABORT OPERATION rejected");
6365 case RQCS_REJECT_MSG_FAILED:
6366 isp_xs_prt(isp, xs, ISP_LOGERR, "MESSAGE REJECT rejected");
6369 case RQCS_NOP_MSG_FAILED:
6370 isp_xs_prt(isp, xs, ISP_LOGERR, "NOP rejected");
6373 case RQCS_PARITY_ERROR_MSG_FAILED:
6374 isp_xs_prt(isp, xs, ISP_LOGERR, "MESSAGE PARITY ERROR rejected");
6377 case RQCS_DEVICE_RESET_MSG_FAILED:
6378 isp_xs_prt(isp, xs, ISP_LOGWARN, "BUS DEVICE RESET rejected");
6381 case RQCS_ID_MSG_FAILED:
6382 isp_xs_prt(isp, xs, ISP_LOGERR, "IDENTIFY rejected");
6385 case RQCS_UNEXP_BUS_FREE:
6386 isp_xs_prt(isp, xs, ISP_LOGERR, "Unexpected Bus Free");
6389 case RQCS_DATA_UNDERRUN:
6392 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
6393 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
6394 isp_xs_prt(isp, xs, ISP_LOGWARN, bun, XS_XFRLEN(xs), sp->req_resid, (ru_marked)? "marked" : "not marked");
6396 XS_SETERR(xs, HBA_BOTCH);
6401 XS_SET_RESID(xs, sp->req_resid);
6403 XS_SETERR(xs, HBA_NOERROR);
6408 case RQCS_XACT_ERR1:
6409 isp_xs_prt(isp, xs, ISP_LOGERR, "HBA attempted queued transaction with disconnect not set");
6412 case RQCS_XACT_ERR2:
6413 isp_xs_prt(isp, xs, ISP_LOGERR,
6414 "HBA attempted queued transaction to target routine %jx",
6415 (uintmax_t)XS_LUN(xs));
6418 case RQCS_XACT_ERR3:
6419 isp_xs_prt(isp, xs, ISP_LOGERR, "HBA attempted queued cmd when queueing disabled");
6422 case RQCS_BAD_ENTRY:
6423 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
6426 case RQCS_QUEUE_FULL:
6427 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "internal queues full status 0x%x", *XS_STSP(xs));
6430 * If QFULL or some other status byte is set, then this
6431 * isn't an error, per se.
6433 * Unfortunately, some QLogic f/w writers have, in
6434 * some cases, ommitted to *set* status to QFULL.
6437 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
6438 XS_SETERR(xs, HBA_NOERROR);
6443 *XS_STSP(xs) = SCSI_QFULL;
6444 XS_SETERR(xs, HBA_NOERROR);
6447 case RQCS_PHASE_SKIPPED:
6448 isp_xs_prt(isp, xs, ISP_LOGERR, "SCSI phase skipped");
6451 case RQCS_ARQS_FAILED:
6452 isp_xs_prt(isp, xs, ISP_LOGERR, "Auto Request Sense Failed");
6454 XS_SETERR(xs, HBA_ARQFAIL);
6458 case RQCS_WIDE_FAILED:
6459 isp_xs_prt(isp, xs, ISP_LOGERR, "Wide Negotiation Failed");
6461 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
6462 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
6463 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
6467 XS_SETERR(xs, HBA_NOERROR);
6471 case RQCS_SYNCXFER_FAILED:
6472 isp_xs_prt(isp, xs, ISP_LOGERR, "SDTR Message Failed");
6474 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
6475 sdp += XS_CHANNEL(xs);
6476 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
6477 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
6482 case RQCS_LVD_BUSERR:
6483 isp_xs_prt(isp, xs, ISP_LOGERR, "Bad LVD condition");
6486 case RQCS_PORT_UNAVAILABLE:
6488 * No such port on the loop. Moral equivalent of SELTIMEO
6490 case RQCS_PORT_LOGGED_OUT:
6493 uint8_t sts = sp->req_completion_status & 0xff;
6496 * It was there (maybe)- treat as a selection timeout.
6498 if (sts == RQCS_PORT_UNAVAILABLE) {
6499 reason = "unavailable";
6504 isp_prt(isp, ISP_LOGINFO, "port %s for target %d", reason, XS_TGT(xs));
6507 * If we're on a local loop, force a LIP (which is overkill)
6508 * to force a re-login of this unit. If we're on fabric,
6509 * then we'll have to log in again as a matter of course.
6511 if (FCPARAM(isp, 0)->isp_topo == TOPO_NL_PORT ||
6512 FCPARAM(isp, 0)->isp_topo == TOPO_FL_PORT) {
6514 MBSINIT(&mbs, MBOX_INIT_LIP, MBLOGALL, 0);
6515 if (ISP_CAP_2KLOGIN(isp)) {
6516 mbs.ibits = (1 << 10);
6518 isp_mboxcmd_qnw(isp, &mbs, 1);
6521 XS_SETERR(xs, HBA_SELTIMEOUT);
6525 case RQCS_PORT_CHANGED:
6526 isp_prt(isp, ISP_LOGWARN, "port changed for target %d", XS_TGT(xs));
6528 XS_SETERR(xs, HBA_SELTIMEOUT);
6532 case RQCS_PORT_BUSY:
6533 isp_prt(isp, ISP_LOGWARN, "port busy for target %d", XS_TGT(xs));
6535 XS_SETERR(xs, HBA_TGTBSY);
6540 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x", sp->req_completion_status);
6544 XS_SETERR(xs, HBA_BOTCH);
6549 isp_parse_status_24xx(ispsoftc_t *isp, isp24xx_statusreq_t *sp, XS_T *xs, long *rp)
6551 int ru_marked, sv_marked;
6552 int chan = XS_CHANNEL(xs);
6554 switch (sp->req_completion_status) {
6557 XS_SETERR(xs, HBA_NOERROR);
6561 case RQCS_DMA_ERROR:
6562 isp_xs_prt(isp, xs, ISP_LOGERR, "DMA error");
6565 case RQCS_TRANSPORT_ERROR:
6566 isp_xs_prt(isp, xs, ISP_LOGERR, "Transport Error");
6569 case RQCS_RESET_OCCURRED:
6570 isp_xs_prt(isp, xs, ISP_LOGWARN, "reset destroyed command");
6571 FCPARAM(isp, chan)->sendmarker = 1;
6573 XS_SETERR(xs, HBA_BUSRESET);
6578 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Aborted");
6579 FCPARAM(isp, chan)->sendmarker = 1;
6581 XS_SETERR(xs, HBA_ABORTED);
6586 isp_xs_prt(isp, xs, ISP_LOGWARN, "Command Timed Out");
6588 XS_SETERR(xs, HBA_CMDTIMEOUT);
6592 case RQCS_DATA_OVERRUN:
6593 XS_SET_RESID(xs, sp->req_resid);
6594 isp_xs_prt(isp, xs, ISP_LOGERR, "Data Overrun");
6596 XS_SETERR(xs, HBA_DATAOVR);
6600 case RQCS_24XX_DRE: /* data reassembly error */
6601 isp_prt(isp, ISP_LOGERR, "Chan %d data reassembly error for target %d", chan, XS_TGT(xs));
6603 XS_SETERR(xs, HBA_ABORTED);
6605 *rp = XS_XFRLEN(xs);
6608 case RQCS_24XX_TABORT: /* aborted by target */
6609 isp_prt(isp, ISP_LOGERR, "Chan %d target %d sent ABTS", chan, XS_TGT(xs));
6611 XS_SETERR(xs, HBA_ABORTED);
6615 case RQCS_DATA_UNDERRUN:
6616 ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
6618 * We can get an underrun w/o things being marked
6619 * if we got a non-zero status.
6621 sv_marked = (sp->req_scsi_status & (RQCS_SV|RQCS_RV)) != 0;
6622 if ((ru_marked == 0 && sv_marked == 0) ||
6623 (sp->req_resid > XS_XFRLEN(xs))) {
6624 isp_xs_prt(isp, xs, ISP_LOGWARN, bun, XS_XFRLEN(xs), sp->req_resid, (ru_marked)? "marked" : "not marked");
6626 XS_SETERR(xs, HBA_BOTCH);
6630 XS_SET_RESID(xs, sp->req_resid);
6631 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "Data Underrun (%d) for command 0x%x", sp->req_resid, XS_CDBP(xs)[0] & 0xff);
6633 XS_SETERR(xs, HBA_NOERROR);
6637 case RQCS_PORT_UNAVAILABLE:
6639 * No such port on the loop. Moral equivalent of SELTIMEO
6641 case RQCS_PORT_LOGGED_OUT:
6644 uint8_t sts = sp->req_completion_status & 0xff;
6647 * It was there (maybe)- treat as a selection timeout.
6649 if (sts == RQCS_PORT_UNAVAILABLE) {
6650 reason = "unavailable";
6655 isp_prt(isp, ISP_LOGINFO, "Chan %d port %s for target %d",
6656 chan, reason, XS_TGT(xs));
6659 * There is no MBOX_INIT_LIP for the 24XX.
6662 XS_SETERR(xs, HBA_SELTIMEOUT);
6666 case RQCS_PORT_CHANGED:
6667 isp_prt(isp, ISP_LOGWARN, "port changed for target %d chan %d", XS_TGT(xs), chan);
6669 XS_SETERR(xs, HBA_SELTIMEOUT);
6674 case RQCS_24XX_ENOMEM: /* f/w resource unavailable */
6675 isp_prt(isp, ISP_LOGWARN, "f/w resource unavailable for target %d chan %d", XS_TGT(xs), chan);
6677 *XS_STSP(xs) = SCSI_BUSY;
6678 XS_SETERR(xs, HBA_TGTBSY);
6682 case RQCS_24XX_TMO: /* task management overrun */
6683 isp_prt(isp, ISP_LOGWARN, "command for target %d overlapped task management for chan %d", XS_TGT(xs), chan);
6685 *XS_STSP(xs) = SCSI_BUSY;
6686 XS_SETERR(xs, HBA_TGTBSY);
6691 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x on chan %d", sp->req_completion_status, chan);
6695 XS_SETERR(xs, HBA_BOTCH);
6700 isp_fastpost_complete(ispsoftc_t *isp, uint32_t fph)
6707 xs = isp_find_xs(isp, fph);
6709 isp_prt(isp, ISP_LOGWARN,
6710 "Command for fast post handle 0x%x not found", fph);
6713 isp_destroy_handle(isp, fph);
6716 * Since we don't have a result queue entry item,
6717 * we must believe that SCSI status is zero and
6718 * that all data transferred.
6720 XS_SET_RESID(xs, 0);
6721 *XS_STSP(xs) = SCSI_GOOD;
6722 if (XS_XFRLEN(xs)) {
6723 ISP_DMAFREE(isp, xs, fph);
6725 if (isp->isp_nactive) {
6728 isp->isp_fphccmplt++;
6733 isp_mbox_continue(ispsoftc_t *isp)
6739 switch (isp->isp_lastmbxcmd) {
6740 case MBOX_WRITE_RAM_WORD:
6741 case MBOX_READ_RAM_WORD:
6742 case MBOX_WRITE_RAM_WORD_EXTENDED:
6743 case MBOX_READ_RAM_WORD_EXTENDED:
6748 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
6749 isp->isp_mbxwrk0 = 0;
6754 * Clear the previous interrupt.
6757 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
6759 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
6760 ISP_WRITE(isp, BIU_SEMA, 0);
6764 * Continue with next word.
6766 ISP_MEMZERO(&mbs, sizeof (mbs));
6767 ptr = isp->isp_mbxworkp;
6768 switch (isp->isp_lastmbxcmd) {
6769 case MBOX_WRITE_RAM_WORD:
6770 mbs.param[1] = isp->isp_mbxwrk1++;
6771 mbs.param[2] = *ptr++;
6773 case MBOX_READ_RAM_WORD:
6774 *ptr++ = isp->isp_mboxtmp[2];
6775 mbs.param[1] = isp->isp_mbxwrk1++;
6777 case MBOX_WRITE_RAM_WORD_EXTENDED:
6779 uint32_t *lptr = (uint32_t *)ptr;
6780 mbs.param[2] = lptr[0];
6781 mbs.param[3] = lptr[0] >> 16;
6783 ptr = (uint16_t *)lptr;
6785 mbs.param[2] = *ptr++;
6787 offset = isp->isp_mbxwrk1;
6788 offset |= isp->isp_mbxwrk8 << 16;
6789 mbs.param[1] = offset;
6790 mbs.param[8] = offset >> 16;
6792 isp->isp_mbxwrk1 = offset;
6793 isp->isp_mbxwrk8 = offset >> 16;
6795 case MBOX_READ_RAM_WORD_EXTENDED:
6797 uint32_t *lptr = (uint32_t *)ptr;
6798 uint32_t val = isp->isp_mboxtmp[2];
6799 val |= (isp->isp_mboxtmp[3]) << 16;
6801 ptr = (uint16_t *)lptr;
6803 *ptr++ = isp->isp_mboxtmp[2];
6805 offset = isp->isp_mbxwrk1;
6806 offset |= isp->isp_mbxwrk8 << 16;
6807 mbs.param[1] = offset;
6808 mbs.param[8] = offset >> 16;
6810 isp->isp_mbxwrk1 = offset;
6811 isp->isp_mbxwrk8 = offset >> 16;
6814 isp->isp_mbxworkp = ptr;
6816 mbs.param[0] = isp->isp_lastmbxcmd;
6817 mbs.logval = MBLOGALL;
6818 isp_mboxcmd_qnw(isp, &mbs, 0);
6822 #define ISP_SCSI_IBITS(op) (mbpscsi[((op)<<1)])
6823 #define ISP_SCSI_OBITS(op) (mbpscsi[((op)<<1) + 1])
6824 #define ISP_SCSI_OPMAP(in, out) in, out
6825 static const uint8_t mbpscsi[] = {
6826 ISP_SCSI_OPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
6827 ISP_SCSI_OPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
6828 ISP_SCSI_OPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
6829 ISP_SCSI_OPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
6830 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
6831 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
6832 ISP_SCSI_OPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
6833 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
6834 ISP_SCSI_OPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
6835 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x09: */
6836 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0a: */
6837 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0b: */
6838 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0c: */
6839 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0d: */
6840 ISP_SCSI_OPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
6841 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0f: */
6842 ISP_SCSI_OPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
6843 ISP_SCSI_OPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
6844 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
6845 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
6846 ISP_SCSI_OPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
6847 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
6848 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
6849 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
6850 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
6851 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
6852 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
6853 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
6854 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
6855 ISP_SCSI_OPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
6856 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x1e: */
6857 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
6858 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
6859 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
6860 ISP_SCSI_OPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
6861 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
6862 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
6863 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
6864 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
6865 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
6866 ISP_SCSI_OPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
6867 ISP_SCSI_OPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
6868 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
6869 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2b: */
6870 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2c: */
6871 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2d: */
6872 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2e: */
6873 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2f: */
6874 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
6875 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
6876 ISP_SCSI_OPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
6877 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
6878 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
6879 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
6880 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
6881 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
6882 ISP_SCSI_OPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
6883 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
6884 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
6885 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3b: */
6886 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3c: */
6887 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3d: */
6888 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3e: */
6889 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3f: */
6890 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
6891 ISP_SCSI_OPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
6892 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
6893 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x43: */
6894 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x44: */
6895 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
6896 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
6897 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x47: */
6898 ISP_SCSI_OPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
6899 ISP_SCSI_OPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
6900 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
6901 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
6902 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4c: */
6903 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4d: */
6904 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4e: */
6905 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4f: */
6906 ISP_SCSI_OPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
6907 ISP_SCSI_OPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
6908 ISP_SCSI_OPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
6909 ISP_SCSI_OPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
6910 ISP_SCSI_OPMAP(0xcf, 0x01), /* 0x54: EXECUCUTE COMMAND IOCB A64 */
6911 ISP_SCSI_OPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
6912 ISP_SCSI_OPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
6913 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x57: */
6914 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x58: */
6915 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x59: */
6916 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
6917 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
6918 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
6919 ISP_SCSI_OPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
6921 #define MAX_SCSI_OPCODE 0x5d
6923 static const char *scsi_mbcmd_names[] = {
6940 "INIT REQUEST QUEUE",
6941 "INIT RESULT QUEUE",
6951 "SINGLE STEP QUEUE",
6953 "GET DEV QUEUE STATUS",
6955 "GET FIRMWARE STATUS",
6957 "GET SELECT TIMEOUT",
6959 "GET TAG AGE LIMIT",
6961 "GET ACT NEG STATE",
6962 "GET ASYNC DATA SETUP TIME",
6964 "GET TARGET PARAMS",
6965 "GET DEV QUEUE PARAMS",
6966 "GET RESET DELAY PARAMS",
6973 "SET SELECT TIMEOUT",
6975 "SET TAG AGE LIMIT",
6977 "SET ACT NEG STATE",
6978 "SET ASYNC DATA SETUP TIME",
6979 "SET PCI CONTROL PARAMS",
6980 "SET TARGET PARAMS",
6981 "SET DEV QUEUE PARAMS",
6982 "SET RESET DELAY PARAMS",
6988 "RETURN BIOS BLOCK ADDR",
6989 "WRITE FOUR RAM WORDS",
6993 "SET SYSTEM PARAMETER",
6994 "GET SYSTEM PARAMETER",
6996 "GET SCAM CONFIGURATION",
6997 "SET SCAM CONFIGURATION",
6998 "SET FIRMWARE FEATURES",
6999 "GET FIRMWARE FEATURES",
7006 "INITIALIZE REQUEST QUEUE A64",
7007 "INITIALIZE RESPONSE QUEUE A64",
7009 "ENABLE TARGET MODE",
7010 "GET TARGET MODE STATE",
7014 "SET DATA OVERRUN RECOVERY MODE",
7015 "GET DATA OVERRUN RECOVERY MODE",
7020 #define ISP_FC_IBITS(op) ((mbpfc[((op)<<3) + 0] << 24) | (mbpfc[((op)<<3) + 1] << 16) | (mbpfc[((op)<<3) + 2] << 8) | (mbpfc[((op)<<3) + 3]))
7021 #define ISP_FC_OBITS(op) ((mbpfc[((op)<<3) + 4] << 24) | (mbpfc[((op)<<3) + 5] << 16) | (mbpfc[((op)<<3) + 6] << 8) | (mbpfc[((op)<<3) + 7]))
7023 #define ISP_FC_OPMAP(in0, out0) 0, 0, 0, in0, 0, 0, 0, out0
7024 #define ISP_FC_OPMAP_HALF(in1, in0, out1, out0) 0, 0, in1, in0, 0, 0, out1, out0
7025 #define ISP_FC_OPMAP_FULL(in3, in2, in1, in0, out3, out2, out1, out0) in3, in2, in1, in0, out3, out2, out1, out0
7026 static const uint32_t mbpfc[] = {
7027 ISP_FC_OPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
7028 ISP_FC_OPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
7029 ISP_FC_OPMAP_HALF(0x07, 0xff, 0x00, 0x03), /* 0x02: MBOX_EXEC_FIRMWARE */
7030 ISP_FC_OPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
7031 ISP_FC_OPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
7032 ISP_FC_OPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
7033 ISP_FC_OPMAP_FULL(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
7034 ISP_FC_OPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
7035 ISP_FC_OPMAP_FULL(0x0, 0x0, 0x0, 0x01, 0x0, 0x3, 0x80, 0x7f), /* 0x08: MBOX_ABOUT_FIRMWARE */
7036 ISP_FC_OPMAP(0xdf, 0x01), /* 0x09: MBOX_LOAD_RISC_RAM_2100 */
7037 ISP_FC_OPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
7038 ISP_FC_OPMAP_HALF(0x1, 0xff, 0x0, 0x01), /* 0x0b: MBOX_LOAD_RISC_RAM */
7039 ISP_FC_OPMAP(0x00, 0x00), /* 0x0c: */
7040 ISP_FC_OPMAP_HALF(0x1, 0x0f, 0x0, 0x01), /* 0x0d: MBOX_WRITE_RAM_WORD_EXTENDED */
7041 ISP_FC_OPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
7042 ISP_FC_OPMAP_HALF(0x1, 0x03, 0x0, 0x0d), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED */
7043 ISP_FC_OPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
7044 ISP_FC_OPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
7045 ISP_FC_OPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
7046 ISP_FC_OPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
7047 ISP_FC_OPMAP_HALF(0x1, 0xff, 0x0, 0x03), /* 0x14: MBOX_STOP_FIRMWARE */
7048 ISP_FC_OPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
7049 ISP_FC_OPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
7050 ISP_FC_OPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
7051 ISP_FC_OPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
7052 ISP_FC_OPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
7053 ISP_FC_OPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
7054 ISP_FC_OPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
7055 ISP_FC_OPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
7056 ISP_FC_OPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
7057 ISP_FC_OPMAP(0x00, 0x00), /* 0x1e: */
7058 ISP_FC_OPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
7059 ISP_FC_OPMAP_HALF(0x2, 0x01, 0x7e, 0xcf), /* 0x20: MBOX_GET_LOOP_ID */
7060 ISP_FC_OPMAP(0x00, 0x00), /* 0x21: */
7061 ISP_FC_OPMAP(0x03, 0x4b), /* 0x22: MBOX_GET_TIMEOUT_PARAMS */
7062 ISP_FC_OPMAP(0x00, 0x00), /* 0x23: */
7063 ISP_FC_OPMAP(0x00, 0x00), /* 0x24: */
7064 ISP_FC_OPMAP(0x00, 0x00), /* 0x25: */
7065 ISP_FC_OPMAP(0x00, 0x00), /* 0x26: */
7066 ISP_FC_OPMAP(0x00, 0x00), /* 0x27: */
7067 ISP_FC_OPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
7068 ISP_FC_OPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
7069 ISP_FC_OPMAP(0x00, 0x00), /* 0x2a: */
7070 ISP_FC_OPMAP(0x00, 0x00), /* 0x2b: */
7071 ISP_FC_OPMAP(0x00, 0x00), /* 0x2c: */
7072 ISP_FC_OPMAP(0x00, 0x00), /* 0x2d: */
7073 ISP_FC_OPMAP(0x00, 0x00), /* 0x2e: */
7074 ISP_FC_OPMAP(0x00, 0x00), /* 0x2f: */
7075 ISP_FC_OPMAP(0x00, 0x00), /* 0x30: */
7076 ISP_FC_OPMAP(0x00, 0x00), /* 0x31: */
7077 ISP_FC_OPMAP(0x4b, 0x4b), /* 0x32: MBOX_SET_TIMEOUT_PARAMS */
7078 ISP_FC_OPMAP(0x00, 0x00), /* 0x33: */
7079 ISP_FC_OPMAP(0x00, 0x00), /* 0x34: */
7080 ISP_FC_OPMAP(0x00, 0x00), /* 0x35: */
7081 ISP_FC_OPMAP(0x00, 0x00), /* 0x36: */
7082 ISP_FC_OPMAP(0x00, 0x00), /* 0x37: */
7083 ISP_FC_OPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
7084 ISP_FC_OPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
7085 ISP_FC_OPMAP(0x00, 0x00), /* 0x3a: */
7086 ISP_FC_OPMAP(0x00, 0x00), /* 0x3b: */
7087 ISP_FC_OPMAP(0x00, 0x00), /* 0x3c: */
7088 ISP_FC_OPMAP(0x00, 0x00), /* 0x3d: */
7089 ISP_FC_OPMAP(0x00, 0x00), /* 0x3e: */
7090 ISP_FC_OPMAP(0x00, 0x00), /* 0x3f: */
7091 ISP_FC_OPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
7092 ISP_FC_OPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
7093 ISP_FC_OPMAP_HALF(0x0, 0x01, 0x3, 0xcf), /* 0x42: MBOX_GET_RESOURCE_COUNT */
7094 ISP_FC_OPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_OFFLINE_MODE */
7095 ISP_FC_OPMAP(0x00, 0x00), /* 0x44: */
7096 ISP_FC_OPMAP(0x00, 0x00), /* 0x45: */
7097 ISP_FC_OPMAP(0x00, 0x00), /* 0x46: */
7098 ISP_FC_OPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
7099 ISP_FC_OPMAP(0xcf, 0x0f), /* 0x48: MBOX_INIT_FIRMWARE_MULTI_ID */
7100 ISP_FC_OPMAP(0xcd, 0x01), /* 0x49: MBOX_GET_VP_DATABASE */
7101 ISP_FC_OPMAP_HALF(0x2, 0xcd, 0x0, 0x01), /* 0x4a: MBOX_GET_VP_DATABASE_ENTRY */
7102 ISP_FC_OPMAP(0x00, 0x00), /* 0x4b: */
7103 ISP_FC_OPMAP(0x00, 0x00), /* 0x4c: */
7104 ISP_FC_OPMAP(0x00, 0x00), /* 0x4d: */
7105 ISP_FC_OPMAP(0x00, 0x00), /* 0x4e: */
7106 ISP_FC_OPMAP(0x00, 0x00), /* 0x4f: */
7107 ISP_FC_OPMAP(0x00, 0x00), /* 0x50: */
7108 ISP_FC_OPMAP(0x00, 0x00), /* 0x51: */
7109 ISP_FC_OPMAP(0x00, 0x00), /* 0x52: */
7110 ISP_FC_OPMAP(0x00, 0x00), /* 0x53: */
7111 ISP_FC_OPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
7112 ISP_FC_OPMAP(0x00, 0x00), /* 0x55: */
7113 ISP_FC_OPMAP(0x00, 0x00), /* 0x56: */
7114 ISP_FC_OPMAP(0x00, 0x00), /* 0x57: */
7115 ISP_FC_OPMAP(0x00, 0x00), /* 0x58: */
7116 ISP_FC_OPMAP(0x00, 0x00), /* 0x59: */
7117 ISP_FC_OPMAP(0x00, 0x00), /* 0x5a: */
7118 ISP_FC_OPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
7119 ISP_FC_OPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
7120 ISP_FC_OPMAP(0x07, 0x1f), /* 0x5d: MBOX_GET_SET_DATA_RATE */
7121 ISP_FC_OPMAP(0x00, 0x00), /* 0x5e: */
7122 ISP_FC_OPMAP(0x00, 0x00), /* 0x5f: */
7123 ISP_FC_OPMAP(0xcf, 0x0f), /* 0x60: MBOX_INIT_FIRMWARE */
7124 ISP_FC_OPMAP(0x00, 0x00), /* 0x61: */
7125 ISP_FC_OPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
7126 ISP_FC_OPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
7127 ISP_FC_OPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
7128 ISP_FC_OPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
7129 ISP_FC_OPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
7130 ISP_FC_OPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
7131 ISP_FC_OPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
7132 ISP_FC_OPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
7133 ISP_FC_OPMAP_HALF(0x6, 0x03, 0x0, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
7134 ISP_FC_OPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
7135 ISP_FC_OPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
7136 ISP_FC_OPMAP(0x00, 0x00), /* 0x6d: */
7137 ISP_FC_OPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
7138 ISP_FC_OPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
7139 ISP_FC_OPMAP_HALF(0x02, 0x03, 0x00, 0x03), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
7140 ISP_FC_OPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
7141 ISP_FC_OPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
7142 ISP_FC_OPMAP(0x00, 0x00), /* 0x73: */
7143 ISP_FC_OPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
7144 ISP_FC_OPMAP_HALF(0x03, 0xcf, 0x00, 0x07), /* 0x75: GET PORT/NODE NAME LIST */
7145 ISP_FC_OPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
7146 ISP_FC_OPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
7147 ISP_FC_OPMAP(0x00, 0x00), /* 0x78: */
7148 ISP_FC_OPMAP(0x00, 0x00), /* 0x79: */
7149 ISP_FC_OPMAP(0x00, 0x00), /* 0x7a: */
7150 ISP_FC_OPMAP(0x00, 0x00), /* 0x7b: */
7151 ISP_FC_OPMAP_HALF(0x03, 0x4f, 0x00, 0x07), /* 0x7c: Get ID List */
7152 ISP_FC_OPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
7153 ISP_FC_OPMAP(0x0f, 0x01) /* 0x7e: LUN RESET */
7155 #define MAX_FC_OPCODE 0x7e
7159 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
7160 * do not access at this time in the core driver. The caller is
7161 * responsible for setting this register first (Gross!). The assumption
7162 * is that we won't overflow.
7165 static const char *fc_mbcmd_names[] = {
7179 "WRITE RAM WORD EXTENDED",
7181 "READ RAM WORD EXTENDED",
7182 "INIT REQUEST QUEUE", /* 10h */
7183 "INIT RESULT QUEUE",
7193 "SINGLE STEP QUEUE",
7195 "GET DEV QUEUE STATUS",
7197 "GET FIRMWARE STATUS",
7198 "GET LOOP ID", /* 20h */
7200 "GET TIMEOUT PARAMS",
7206 "GET FIRMWARE OPTIONS",
7207 "GET PORT QUEUE PARAMS",
7208 "GENERATE SYSTEM ERROR",
7214 "WRITE SFP", /* 30h */
7216 "SET TIMEOUT PARAMS",
7222 "SET FIRMWARE OPTIONS",
7223 "SET PORT QUEUE PARAMS",
7227 "RESTART NIC FIRMWARE",
7230 "LOOP PORT BYPASS", /* 40h */
7232 "GET RESOURCE COUNT",
7233 "REQUEST NON PARTICIPATING MODE",
7234 "DIAGNOSTIC ECHO TEST",
7235 "DIAGNOSTIC LOOPBACK",
7237 "GET PORT DATABASE ENHANCED",
7238 "INIT FIRMWARE MULTI ID",
7240 "GET VP DATABASE ENTRY",
7246 "GET FCF LIST", /* 50h */
7247 "GET DCBX PARAMETERS",
7258 "FIRMWARE HEARTBEAT",
7259 "GET/SET DATA RATE",
7262 "INIT FIRMWARE", /* 60h */
7263 "GET INIT CONTROL BLOCK",
7265 "GET FC-AL POSITION MAP",
7266 "GET PORT DATABASE",
7275 "GET LINK STATS & PRIVATE DATA CNTS",
7278 "SEND CHANGE REQUEST", /* 70h */
7283 "GET PORT/NODE NAME LIST",
7285 "INITIALIZE IP MAILBOX",
7296 isp_mboxcmd_qnw(ispsoftc_t *isp, mbreg_t *mbp, int nodelay)
7298 unsigned int ibits, obits, box, opcode;
7300 opcode = mbp->param[0];
7302 ibits = ISP_FC_IBITS(opcode);
7303 obits = ISP_FC_OBITS(opcode);
7305 ibits = ISP_SCSI_IBITS(opcode);
7306 obits = ISP_SCSI_OBITS(opcode);
7308 ibits |= mbp->ibits;
7309 obits |= mbp->obits;
7310 for (box = 0; box < ISP_NMBOX(isp); box++) {
7311 if (ibits & (1 << box)) {
7312 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
7315 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
7319 isp->isp_lastmbxcmd = opcode;
7320 isp->isp_obits = obits;
7321 isp->isp_mboxbsy = 1;
7324 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_SET_HOST_INT);
7326 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
7329 * Oddly enough, if we're not delaying for an answer,
7330 * delay a bit to give the f/w a chance to pick up the
7339 isp_mboxcmd(ispsoftc_t *isp, mbreg_t *mbp)
7341 const char *cname, *xname, *sname;
7342 char tname[16], mname[16];
7343 unsigned int ibits, obits, box, opcode;
7345 opcode = mbp->param[0];
7347 if (opcode > MAX_FC_OPCODE) {
7348 mbp->param[0] = MBOX_INVALID_COMMAND;
7349 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
7352 cname = fc_mbcmd_names[opcode];
7353 ibits = ISP_FC_IBITS(opcode);
7354 obits = ISP_FC_OBITS(opcode);
7356 if (opcode > MAX_SCSI_OPCODE) {
7357 mbp->param[0] = MBOX_INVALID_COMMAND;
7358 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
7361 cname = scsi_mbcmd_names[opcode];
7362 ibits = ISP_SCSI_IBITS(opcode);
7363 obits = ISP_SCSI_OBITS(opcode);
7365 if (cname == NULL) {
7367 ISP_SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
7369 isp_prt(isp, ISP_LOGDEBUG3, "Mailbox Command '%s'", cname);
7372 * Pick up any additional bits that the caller might have set.
7374 ibits |= mbp->ibits;
7375 obits |= mbp->obits;
7378 * Mask any bits that the caller wants us to mask
7380 ibits &= mbp->ibitm;
7381 obits &= mbp->obitm;
7384 if (ibits == 0 && obits == 0) {
7385 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
7386 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
7391 * Get exclusive usage of mailbox registers.
7393 if (MBOX_ACQUIRE(isp)) {
7394 mbp->param[0] = MBOX_REGS_BUSY;
7398 for (box = 0; box < ISP_NMBOX(isp); box++) {
7399 if (ibits & (1 << box)) {
7400 isp_prt(isp, ISP_LOGDEBUG3, "IN mbox %d = 0x%04x", box,
7402 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
7404 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
7407 isp->isp_lastmbxcmd = opcode;
7410 * We assume that we can't overwrite a previous command.
7412 isp->isp_obits = obits;
7413 isp->isp_mboxbsy = 1;
7416 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
7419 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_SET_HOST_INT);
7421 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
7425 * While we haven't finished the command, spin our wheels here.
7427 MBOX_WAIT_COMPLETE(isp, mbp);
7430 * Did the command time out?
7432 if (mbp->param[0] == MBOX_TIMEOUT) {
7433 isp->isp_mboxbsy = 0;
7439 * Copy back output registers.
7441 for (box = 0; box < ISP_NMBOX(isp); box++) {
7442 if (obits & (1 << box)) {
7443 mbp->param[box] = isp->isp_mboxtmp[box];
7444 isp_prt(isp, ISP_LOGDEBUG3, "OUT mbox %d = 0x%04x", box,
7449 isp->isp_mboxbsy = 0;
7452 if (mbp->logval == 0 || mbp->param[0] == MBOX_COMMAND_COMPLETE)
7455 if ((mbp->param[0] & 0xbfe0) == 0 &&
7456 (mbp->logval & MBLOGMASK(mbp->param[0])) == 0)
7461 switch (mbp->param[0]) {
7462 case MBOX_INVALID_COMMAND:
7463 xname = "INVALID COMMAND";
7465 case MBOX_HOST_INTERFACE_ERROR:
7466 xname = "HOST INTERFACE ERROR";
7468 case MBOX_TEST_FAILED:
7469 xname = "TEST FAILED";
7471 case MBOX_COMMAND_ERROR:
7472 xname = "COMMAND ERROR";
7473 ISP_SNPRINTF(mname, sizeof(mname), " subcode 0x%x",
7477 case MBOX_COMMAND_PARAM_ERROR:
7478 xname = "COMMAND PARAMETER ERROR";
7480 case MBOX_PORT_ID_USED:
7481 xname = "PORT ID ALREADY IN USE";
7483 case MBOX_LOOP_ID_USED:
7484 xname = "LOOP ID ALREADY IN USE";
7486 case MBOX_ALL_IDS_USED:
7487 xname = "ALL LOOP IDS IN USE";
7489 case MBOX_NOT_LOGGED_IN:
7490 xname = "NOT LOGGED IN";
7492 case MBOX_LINK_DOWN_ERROR:
7493 xname = "LINK DOWN ERROR";
7495 case MBOX_LOOPBACK_ERROR:
7496 xname = "LOOPBACK ERROR";
7498 case MBOX_CHECKSUM_ERROR:
7499 xname = "CHECKSUM ERROR";
7501 case MBOX_INVALID_PRODUCT_KEY:
7502 xname = "INVALID PRODUCT KEY";
7504 case MBOX_REGS_BUSY:
7505 xname = "REGISTERS BUSY";
7511 ISP_SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
7516 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s%s)",
7517 cname, xname, sname);
7522 isp_fw_state(ispsoftc_t *isp, int chan)
7527 MBSINIT(&mbs, MBOX_GET_FW_STATE, MBLOGALL, 0);
7528 isp_mboxcmd(isp, &mbs);
7529 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
7530 return (mbs.param[1]);
7537 isp_spi_update(ispsoftc_t *isp, int chan)
7545 * There are no 'per-bus' settings for Fibre Channel.
7549 sdp = SDPARAM(isp, chan);
7552 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7553 uint16_t flags, period, offset;
7556 if (sdp->isp_devparam[tgt].dev_enable == 0) {
7557 sdp->isp_devparam[tgt].dev_update = 0;
7558 sdp->isp_devparam[tgt].dev_refresh = 0;
7559 isp_prt(isp, ISP_LOGDEBUG0, "skipping target %d bus %d update", tgt, chan);
7563 * If the goal is to update the status of the device,
7564 * take what's in goal_flags and try and set the device
7565 * toward that. Otherwise, if we're just refreshing the
7566 * current device state, get the current parameters.
7569 MBSINIT(&mbs, 0, MBLOGALL, 0);
7572 * Refresh overrides set
7574 if (sdp->isp_devparam[tgt].dev_refresh) {
7575 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
7577 } else if (sdp->isp_devparam[tgt].dev_update) {
7578 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
7581 * Make sure goal_flags has "Renegotiate on Error"
7582 * on and "Freeze Queue on Error" off.
7584 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
7585 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
7586 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
7589 * Insist that PARITY must be enabled
7590 * if SYNC or WIDE is enabled.
7592 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
7593 mbs.param[2] |= DPARM_PARITY;
7596 if (mbs.param[2] & DPARM_SYNC) {
7598 (sdp->isp_devparam[tgt].goal_offset << 8) |
7599 (sdp->isp_devparam[tgt].goal_period);
7602 * A command completion later that has
7603 * RQSTF_NEGOTIATION set can cause
7604 * the dev_refresh/announce cycle also.
7606 * Note: It is really important to update our current
7607 * flags with at least the state of TAG capabilities-
7608 * otherwise we might try and send a tagged command
7609 * when we have it all turned off. So change it here
7610 * to say that current already matches goal.
7612 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
7613 sdp->isp_devparam[tgt].actv_flags |=
7614 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
7615 isp_prt(isp, ISP_LOGDEBUG0, "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
7616 chan, tgt, mbs.param[2], mbs.param[3] >> 8, mbs.param[3] & 0xff);
7621 mbs.param[1] = (chan << 15) | (tgt << 8);
7622 isp_mboxcmd(isp, &mbs);
7623 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7627 sdp->sendmarker = 1;
7628 sdp->isp_devparam[tgt].dev_update = 0;
7629 sdp->isp_devparam[tgt].dev_refresh = 1;
7631 sdp->isp_devparam[tgt].dev_refresh = 0;
7632 flags = mbs.param[2];
7633 period = mbs.param[3] & 0xff;
7634 offset = mbs.param[3] >> 8;
7635 sdp->isp_devparam[tgt].actv_flags = flags;
7636 sdp->isp_devparam[tgt].actv_period = period;
7637 sdp->isp_devparam[tgt].actv_offset = offset;
7638 isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, chan, tgt);
7642 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7643 if (sdp->isp_devparam[tgt].dev_update ||
7644 sdp->isp_devparam[tgt].dev_refresh) {
7652 isp_setdfltsdparm(ispsoftc_t *isp)
7655 sdparam *sdp, *sdp1;
7657 sdp = SDPARAM(isp, 0);
7658 if (IS_DUALBUS(isp))
7664 * Establish some default parameters.
7666 sdp->isp_cmd_dma_burst_enable = 0;
7667 sdp->isp_data_dma_burst_enabl = 1;
7668 sdp->isp_fifo_threshold = 0;
7669 sdp->isp_initiator_id = DEFAULT_IID(isp, 0);
7670 if (isp->isp_type >= ISP_HA_SCSI_1040) {
7671 sdp->isp_async_data_setup = 9;
7673 sdp->isp_async_data_setup = 6;
7675 sdp->isp_selection_timeout = 250;
7676 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
7677 sdp->isp_tag_aging = 8;
7678 sdp->isp_bus_reset_delay = 5;
7680 * Don't retry selection, busy or queue full automatically- reflect
7683 sdp->isp_retry_count = 0;
7684 sdp->isp_retry_delay = 0;
7686 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7687 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
7688 sdp->isp_devparam[tgt].dev_enable = 1;
7692 * The trick here is to establish a default for the default (honk!)
7693 * state (goal_flags). Then try and get the current status from
7694 * the card to fill in the current state. We don't, in fact, set
7695 * the default to the SAFE default state- that's not the goal state.
7697 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7699 sdp->isp_devparam[tgt].actv_offset = 0;
7700 sdp->isp_devparam[tgt].actv_period = 0;
7701 sdp->isp_devparam[tgt].actv_flags = 0;
7703 sdp->isp_devparam[tgt].goal_flags =
7704 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
7707 * We default to Wide/Fast for versions less than a 1040
7708 * (unless it's SBus).
7710 if (IS_ULTRA3(isp)) {
7711 off = ISP_80M_SYNCPARMS >> 8;
7712 per = ISP_80M_SYNCPARMS & 0xff;
7713 } else if (IS_ULTRA2(isp)) {
7714 off = ISP_40M_SYNCPARMS >> 8;
7715 per = ISP_40M_SYNCPARMS & 0xff;
7716 } else if (IS_1240(isp)) {
7717 off = ISP_20M_SYNCPARMS >> 8;
7718 per = ISP_20M_SYNCPARMS & 0xff;
7719 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
7720 isp->isp_type < ISP_HA_SCSI_1020A) ||
7721 (isp->isp_bustype == ISP_BT_PCI &&
7722 isp->isp_type < ISP_HA_SCSI_1040) ||
7723 (isp->isp_clock && isp->isp_clock < 60) ||
7724 (sdp->isp_ultramode == 0)) {
7725 off = ISP_10M_SYNCPARMS >> 8;
7726 per = ISP_10M_SYNCPARMS & 0xff;
7728 off = ISP_20M_SYNCPARMS_1040 >> 8;
7729 per = ISP_20M_SYNCPARMS_1040 & 0xff;
7731 sdp->isp_devparam[tgt].goal_offset =
7732 sdp->isp_devparam[tgt].nvrm_offset = off;
7733 sdp->isp_devparam[tgt].goal_period =
7734 sdp->isp_devparam[tgt].nvrm_period = per;
7739 * If we're a dual bus card, just copy the data over
7743 sdp1->isp_initiator_id = DEFAULT_IID(isp, 1);
7747 * If we've not been told to avoid reading NVRAM, try and read it.
7748 * If we're successful reading it, we can then return because NVRAM
7749 * will tell us what the desired settings are. Otherwise, we establish
7750 * some reasonable 'fake' nvram and goal defaults.
7752 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7755 if (isp_read_nvram(isp, 0) == 0) {
7756 if (IS_DUALBUS(isp)) {
7757 if (isp_read_nvram(isp, 1) == 0) {
7762 MBSINIT(&mbs, MBOX_GET_ACT_NEG_STATE, MBLOGNONE, 0);
7763 isp_mboxcmd(isp, &mbs);
7764 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7765 sdp->isp_req_ack_active_neg = 1;
7766 sdp->isp_data_line_active_neg = 1;
7768 sdp1->isp_req_ack_active_neg = 1;
7769 sdp1->isp_data_line_active_neg = 1;
7772 sdp->isp_req_ack_active_neg =
7773 (mbs.param[1] >> 4) & 0x1;
7774 sdp->isp_data_line_active_neg =
7775 (mbs.param[1] >> 5) & 0x1;
7777 sdp1->isp_req_ack_active_neg =
7778 (mbs.param[2] >> 4) & 0x1;
7779 sdp1->isp_data_line_active_neg =
7780 (mbs.param[2] >> 5) & 0x1;
7788 isp_setdfltfcparm(ispsoftc_t *isp, int chan)
7790 fcparam *fcp = FCPARAM(isp, chan);
7793 * Establish some default parameters.
7795 fcp->role = DEFAULT_ROLE(isp, chan);
7796 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
7797 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
7798 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
7799 fcp->isp_loopid = DEFAULT_LOOPID(isp, chan);
7800 fcp->isp_wwnn_nvram = DEFAULT_NODEWWN(isp, chan);
7801 fcp->isp_wwpn_nvram = DEFAULT_PORTWWN(isp, chan);
7802 fcp->isp_fwoptions = 0;
7803 fcp->isp_xfwoptions = 0;
7804 fcp->isp_zfwoptions = 0;
7805 fcp->isp_lasthdl = NIL_HANDLE;
7808 fcp->isp_fwoptions |= ICB2400_OPT1_FAIRNESS;
7809 fcp->isp_fwoptions |= ICB2400_OPT1_HARD_ADDRESS;
7810 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX) {
7811 fcp->isp_fwoptions |= ICB2400_OPT1_FULL_DUPLEX;
7813 fcp->isp_fwoptions |= ICB2400_OPT1_BOTH_WWNS;
7814 fcp->isp_zfwoptions |= ICB2400_OPT3_RATE_AUTO;
7816 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
7817 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
7818 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
7819 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX) {
7820 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
7823 * Make sure this is turned off now until we get
7824 * extended options from NVRAM
7826 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
7827 fcp->isp_zfwoptions |= ICBZOPT_RATE_AUTO;
7832 * Now try and read NVRAM unless told to not do so.
7833 * This will set fcparam's isp_wwnn_nvram && isp_wwpn_nvram.
7835 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7838 * Give a couple of tries at reading NVRAM.
7840 for (i = 0; i < 2; i++) {
7841 j = isp_read_nvram(isp, chan);
7847 isp->isp_confopts |= ISP_CFG_NONVRAM;
7851 fcp->isp_wwnn = ACTIVE_NODEWWN(isp, chan);
7852 fcp->isp_wwpn = ACTIVE_PORTWWN(isp, chan);
7853 isp_prt(isp, ISP_LOGCONFIG, "Chan %d 0x%08x%08x/0x%08x%08x Role %s",
7854 chan, (uint32_t) (fcp->isp_wwnn >> 32), (uint32_t) (fcp->isp_wwnn),
7855 (uint32_t) (fcp->isp_wwpn >> 32), (uint32_t) (fcp->isp_wwpn),
7856 isp_class3_roles[fcp->role]);
7860 * Re-initialize the ISP and complete all orphaned commands
7861 * with a 'botched' notice. The reset/init routines should
7862 * not disturb an already active list of commands.
7866 isp_reinit(ispsoftc_t *isp, int do_load_defaults)
7870 if (isp->isp_state == ISP_RUNSTATE)
7872 if (isp->isp_state != ISP_RESETSTATE)
7873 isp_reset(isp, do_load_defaults);
7874 if (isp->isp_state != ISP_RESETSTATE) {
7876 isp_prt(isp, ISP_LOGERR, "%s: cannot reset card", __func__);
7877 ISP_DISABLE_INTS(isp);
7882 if (isp->isp_state > ISP_RESETSTATE &&
7883 isp->isp_state != ISP_RUNSTATE) {
7885 isp_prt(isp, ISP_LOGERR, "%s: cannot init card", __func__);
7886 ISP_DISABLE_INTS(isp);
7889 * If we're in ISP_ROLE_NONE, turn off the lasers.
7891 if (!IS_24XX(isp)) {
7892 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
7893 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
7894 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
7895 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
7896 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
7902 isp->isp_nactive = 0;
7903 isp_clear_commands(isp);
7905 for (i = 0; i < isp->isp_nchan; i++)
7906 isp_clear_portdb(isp, i);
7915 isp_read_nvram(ispsoftc_t *isp, int bus)
7918 uint8_t csum, minversion;
7920 uint8_t _x[ISP2400_NVRAM_SIZE];
7921 uint16_t _s[ISP2400_NVRAM_SIZE>>1];
7923 #define nvram_data _n._x
7924 #define nvram_words _n._s
7927 return (isp_read_nvram_2400(isp, nvram_data));
7928 } else if (IS_FC(isp)) {
7929 amt = ISP2100_NVRAM_SIZE;
7931 } else if (IS_ULTRA2(isp)) {
7932 amt = ISP1080_NVRAM_SIZE;
7935 amt = ISP_NVRAM_SIZE;
7939 for (i = 0; i < amt>>1; i++) {
7940 isp_rdnvram_word(isp, i, &nvram_words[i]);
7943 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
7944 nvram_data[2] != 'P') {
7945 if (isp->isp_bustype != ISP_BT_SBUS) {
7946 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
7947 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x", nvram_data[0], nvram_data[1], nvram_data[2]);
7953 for (csum = 0, i = 0; i < amt; i++) {
7954 csum += nvram_data[i];
7957 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
7962 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
7963 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
7964 ISP_NVRAM_VERSION(nvram_data));
7969 if (IS_ULTRA3(isp)) {
7970 isp_parse_nvram_12160(isp, bus, nvram_data);
7971 } else if (IS_1080(isp)) {
7972 isp_parse_nvram_1080(isp, bus, nvram_data);
7973 } else if (IS_1280(isp) || IS_1240(isp)) {
7974 isp_parse_nvram_1080(isp, bus, nvram_data);
7975 } else if (IS_SCSI(isp)) {
7976 isp_parse_nvram_1020(isp, nvram_data);
7978 isp_parse_nvram_2100(isp, nvram_data);
7988 isp_read_nvram_2400(ispsoftc_t *isp, uint8_t *nvram_data)
7991 uint32_t addr, csum, lwrds, *dptr;
7993 if (isp->isp_port) {
7994 addr = ISP2400_NVRAM_PORT1_ADDR;
7996 addr = ISP2400_NVRAM_PORT0_ADDR;
7999 dptr = (uint32_t *) nvram_data;
8000 for (lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
8001 isp_rd_2400_nvram(isp, addr++, dptr++);
8003 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
8004 nvram_data[2] != 'P') {
8005 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header (%x %x %x)",
8006 nvram_data[0], nvram_data[1], nvram_data[2]);
8010 dptr = (uint32_t *) nvram_data;
8011 for (csum = 0, lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
8013 ISP_IOXGET_32(isp, &dptr[lwrds], tmp);
8017 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
8021 isp_parse_nvram_2400(isp, nvram_data);
8027 isp_rdnvram_word(ispsoftc_t *isp, int wo, uint16_t *rp)
8030 uint16_t bit, rqst, junk;
8032 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
8034 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
8038 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
8039 if (IS_2312(isp) && isp->isp_port) {
8042 rqst = (ISP_NVRAM_READ << 8) | wo;
8044 } else if (IS_ULTRA2(isp)) {
8045 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
8046 rqst = (ISP_NVRAM_READ << 8) | wo;
8049 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
8050 rqst = (ISP_NVRAM_READ << 6) | wo;
8055 * Clock the word select request out...
8057 for (i = cbits; i >= 0; i--) {
8058 if ((rqst >> i) & 1) {
8059 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
8061 bit = BIU_NVRAM_SELECT;
8063 ISP_WRITE(isp, BIU_NVRAM, bit);
8065 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
8066 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
8068 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
8069 ISP_WRITE(isp, BIU_NVRAM, bit);
8071 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
8074 * Now read the result back in (bits come back in MSB format).
8077 for (i = 0; i < 16; i++) {
8080 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
8082 rv = ISP_READ(isp, BIU_NVRAM);
8083 if (rv & BIU_NVRAM_DATAIN) {
8087 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
8089 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
8091 ISP_WRITE(isp, BIU_NVRAM, 0);
8093 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
8094 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
8098 isp_rd_2400_nvram(ispsoftc_t *isp, uint32_t addr, uint32_t *rp)
8101 uint32_t base = 0x7ffe0000;
8105 base = 0x7fe7c000; /* XXX: Observation, may be wrong. */
8106 } else if (IS_25XX(isp)) {
8107 base = 0x7ff00000 | 0x48000;
8109 ISP_WRITE(isp, BIU2400_FLASH_ADDR, base | addr);
8110 for (loops = 0; loops < 5000; loops++) {
8112 tmp = ISP_READ(isp, BIU2400_FLASH_ADDR);
8113 if ((tmp & (1U << 31)) != 0) {
8117 if (tmp & (1U << 31)) {
8118 *rp = ISP_READ(isp, BIU2400_FLASH_DATA);
8119 ISP_SWIZZLE_NVRAM_LONG(isp, rp);
8126 isp_parse_nvram_1020(ispsoftc_t *isp, uint8_t *nvram_data)
8128 sdparam *sdp = SDPARAM(isp, 0);
8131 sdp->isp_fifo_threshold =
8132 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
8133 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
8135 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
8136 sdp->isp_initiator_id = ISP_NVRAM_INITIATOR_ID(nvram_data);
8138 sdp->isp_bus_reset_delay =
8139 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
8141 sdp->isp_retry_count =
8142 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
8144 sdp->isp_retry_delay =
8145 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
8147 sdp->isp_async_data_setup =
8148 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
8150 if (isp->isp_type >= ISP_HA_SCSI_1040) {
8151 if (sdp->isp_async_data_setup < 9) {
8152 sdp->isp_async_data_setup = 9;
8155 if (sdp->isp_async_data_setup != 6) {
8156 sdp->isp_async_data_setup = 6;
8160 sdp->isp_req_ack_active_neg =
8161 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
8163 sdp->isp_data_line_active_neg =
8164 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
8166 sdp->isp_data_dma_burst_enabl =
8167 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
8169 sdp->isp_cmd_dma_burst_enable =
8170 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
8172 sdp->isp_tag_aging =
8173 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
8175 sdp->isp_selection_timeout =
8176 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
8178 sdp->isp_max_queue_depth =
8179 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
8181 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
8183 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
8184 sdp->isp_devparam[tgt].dev_enable =
8185 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
8186 sdp->isp_devparam[tgt].exc_throttle =
8187 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
8188 sdp->isp_devparam[tgt].nvrm_offset =
8189 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
8190 sdp->isp_devparam[tgt].nvrm_period =
8191 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
8193 * We probably shouldn't lie about this, but it
8194 * it makes it much safer if we limit NVRAM values
8197 if (isp->isp_type < ISP_HA_SCSI_1040) {
8199 * If we're not ultra, we can't possibly
8200 * be a shorter period than this.
8202 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
8203 sdp->isp_devparam[tgt].nvrm_period = 0x19;
8205 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
8206 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
8209 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
8210 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
8213 sdp->isp_devparam[tgt].nvrm_flags = 0;
8214 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
8215 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
8216 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
8217 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
8218 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
8219 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
8220 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
8221 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
8222 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
8223 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
8224 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
8225 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
8226 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
8227 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
8228 sdp->isp_devparam[tgt].goal_offset =
8229 sdp->isp_devparam[tgt].nvrm_offset;
8230 sdp->isp_devparam[tgt].goal_period =
8231 sdp->isp_devparam[tgt].nvrm_period;
8232 sdp->isp_devparam[tgt].goal_flags =
8233 sdp->isp_devparam[tgt].nvrm_flags;
8238 isp_parse_nvram_1080(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
8240 sdparam *sdp = SDPARAM(isp, bus);
8243 sdp->isp_fifo_threshold =
8244 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
8246 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
8247 sdp->isp_initiator_id = ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
8249 sdp->isp_bus_reset_delay =
8250 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
8252 sdp->isp_retry_count =
8253 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
8255 sdp->isp_retry_delay =
8256 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
8258 sdp->isp_async_data_setup =
8259 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
8261 sdp->isp_req_ack_active_neg =
8262 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
8264 sdp->isp_data_line_active_neg =
8265 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
8267 sdp->isp_data_dma_burst_enabl =
8268 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
8270 sdp->isp_cmd_dma_burst_enable =
8271 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
8273 sdp->isp_selection_timeout =
8274 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
8276 sdp->isp_max_queue_depth =
8277 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
8279 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
8280 sdp->isp_devparam[tgt].dev_enable =
8281 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
8282 sdp->isp_devparam[tgt].exc_throttle =
8283 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
8284 sdp->isp_devparam[tgt].nvrm_offset =
8285 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
8286 sdp->isp_devparam[tgt].nvrm_period =
8287 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
8288 sdp->isp_devparam[tgt].nvrm_flags = 0;
8289 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
8290 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
8291 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
8292 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
8293 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
8294 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
8295 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
8296 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
8297 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
8298 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
8299 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
8300 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
8301 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
8302 sdp->isp_devparam[tgt].actv_flags = 0;
8303 sdp->isp_devparam[tgt].goal_offset =
8304 sdp->isp_devparam[tgt].nvrm_offset;
8305 sdp->isp_devparam[tgt].goal_period =
8306 sdp->isp_devparam[tgt].nvrm_period;
8307 sdp->isp_devparam[tgt].goal_flags =
8308 sdp->isp_devparam[tgt].nvrm_flags;
8313 isp_parse_nvram_12160(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
8315 sdparam *sdp = SDPARAM(isp, bus);
8318 sdp->isp_fifo_threshold =
8319 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
8321 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
8322 sdp->isp_initiator_id = ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
8324 sdp->isp_bus_reset_delay =
8325 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
8327 sdp->isp_retry_count =
8328 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
8330 sdp->isp_retry_delay =
8331 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
8333 sdp->isp_async_data_setup =
8334 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
8336 sdp->isp_req_ack_active_neg =
8337 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
8339 sdp->isp_data_line_active_neg =
8340 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
8342 sdp->isp_data_dma_burst_enabl =
8343 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
8345 sdp->isp_cmd_dma_burst_enable =
8346 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
8348 sdp->isp_selection_timeout =
8349 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
8351 sdp->isp_max_queue_depth =
8352 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
8354 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
8355 sdp->isp_devparam[tgt].dev_enable =
8356 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
8357 sdp->isp_devparam[tgt].exc_throttle =
8358 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
8359 sdp->isp_devparam[tgt].nvrm_offset =
8360 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
8361 sdp->isp_devparam[tgt].nvrm_period =
8362 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
8363 sdp->isp_devparam[tgt].nvrm_flags = 0;
8364 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
8365 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
8366 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
8367 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
8368 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
8369 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
8370 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
8371 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
8372 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
8373 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
8374 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
8375 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
8376 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
8377 sdp->isp_devparam[tgt].actv_flags = 0;
8378 sdp->isp_devparam[tgt].goal_offset =
8379 sdp->isp_devparam[tgt].nvrm_offset;
8380 sdp->isp_devparam[tgt].goal_period =
8381 sdp->isp_devparam[tgt].nvrm_period;
8382 sdp->isp_devparam[tgt].goal_flags =
8383 sdp->isp_devparam[tgt].nvrm_flags;
8388 isp_parse_nvram_2100(ispsoftc_t *isp, uint8_t *nvram_data)
8390 fcparam *fcp = FCPARAM(isp, 0);
8394 * There is NVRAM storage for both Port and Node entities-
8395 * but the Node entity appears to be unused on all the cards
8396 * I can find. However, we should account for this being set
8397 * at some point in the future.
8399 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
8400 * bits 48..60. In the case of the 2202, it appears that they do
8401 * use bit 48 to distinguish between the two instances on the card.
8402 * The 2204, which I've never seen, *probably* extends this method.
8404 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
8406 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
8407 (uint32_t) (wwn >> 32), (uint32_t) (wwn));
8408 if ((wwn >> 60) == 0) {
8409 wwn |= (((uint64_t) 2)<< 60);
8412 fcp->isp_wwpn_nvram = wwn;
8413 if (IS_2200(isp) || IS_23XX(isp)) {
8414 wwn = ISP2100_NVRAM_NODE_NAME(nvram_data);
8416 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
8417 (uint32_t) (wwn >> 32),
8419 if ((wwn >> 60) == 0) {
8420 wwn |= (((uint64_t) 2)<< 60);
8423 wwn = fcp->isp_wwpn_nvram & ~((uint64_t) 0xfff << 48);
8426 wwn &= ~((uint64_t) 0xfff << 48);
8428 fcp->isp_wwnn_nvram = wwn;
8430 fcp->isp_maxalloc = ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
8431 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
8432 DEFAULT_FRAMESIZE(isp) =
8433 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
8435 fcp->isp_retry_delay = ISP2100_NVRAM_RETRY_DELAY(nvram_data);
8436 fcp->isp_retry_count = ISP2100_NVRAM_RETRY_COUNT(nvram_data);
8437 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
8438 fcp->isp_loopid = ISP2100_NVRAM_HARDLOOPID(nvram_data);
8440 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
8441 DEFAULT_EXEC_THROTTLE(isp) =
8442 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
8444 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
8445 isp_prt(isp, ISP_LOGDEBUG0,
8446 "NVRAM 0x%08x%08x 0x%08x%08x maxalloc %d maxframelen %d",
8447 (uint32_t) (fcp->isp_wwnn_nvram >> 32),
8448 (uint32_t) fcp->isp_wwnn_nvram,
8449 (uint32_t) (fcp->isp_wwpn_nvram >> 32),
8450 (uint32_t) fcp->isp_wwpn_nvram,
8451 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data),
8452 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data));
8453 isp_prt(isp, ISP_LOGDEBUG0,
8454 "execthrottle %d fwoptions 0x%x hardloop %d tov %d",
8455 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
8456 ISP2100_NVRAM_OPTIONS(nvram_data),
8457 ISP2100_NVRAM_HARDLOOPID(nvram_data),
8458 ISP2100_NVRAM_TOV(nvram_data));
8459 fcp->isp_xfwoptions = ISP2100_XFW_OPTIONS(nvram_data);
8460 fcp->isp_zfwoptions = ISP2100_ZFW_OPTIONS(nvram_data);
8461 isp_prt(isp, ISP_LOGDEBUG0, "xfwoptions 0x%x zfw options 0x%x",
8462 ISP2100_XFW_OPTIONS(nvram_data), ISP2100_ZFW_OPTIONS(nvram_data));
8466 isp_parse_nvram_2400(ispsoftc_t *isp, uint8_t *nvram_data)
8468 fcparam *fcp = FCPARAM(isp, 0);
8471 isp_prt(isp, ISP_LOGDEBUG0,
8472 "NVRAM 0x%08x%08x 0x%08x%08x exchg_cnt %d maxframelen %d",
8473 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data) >> 32),
8474 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data)),
8475 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data) >> 32),
8476 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data)),
8477 ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data),
8478 ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data));
8479 isp_prt(isp, ISP_LOGDEBUG0,
8480 "NVRAM execthr %d loopid %d fwopt1 0x%x fwopt2 0x%x fwopt3 0x%x",
8481 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data),
8482 ISP2400_NVRAM_HARDLOOPID(nvram_data),
8483 ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data),
8484 ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data),
8485 ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data));
8487 wwn = ISP2400_NVRAM_PORT_NAME(nvram_data);
8488 fcp->isp_wwpn_nvram = wwn;
8490 wwn = ISP2400_NVRAM_NODE_NAME(nvram_data);
8492 if ((wwn >> 60) != 2 && (wwn >> 60) != 5) {
8496 if (wwn == 0 && (fcp->isp_wwpn_nvram >> 60) == 2) {
8497 wwn = fcp->isp_wwpn_nvram;
8498 wwn &= ~((uint64_t) 0xfff << 48);
8500 fcp->isp_wwnn_nvram = wwn;
8502 if (ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data)) {
8503 fcp->isp_maxalloc = ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data);
8505 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
8506 DEFAULT_FRAMESIZE(isp) =
8507 ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data);
8509 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
8510 fcp->isp_loopid = ISP2400_NVRAM_HARDLOOPID(nvram_data);
8512 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
8513 DEFAULT_EXEC_THROTTLE(isp) =
8514 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data);
8516 fcp->isp_fwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data);
8517 fcp->isp_xfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data);
8518 fcp->isp_zfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data);