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"
67 #define MBOX_DELAY_COUNT 1000000 / 100
68 #define ISP_MARK_PORTDB(a, b, c) \
69 isp_prt(isp, ISP_LOGSANCFG, \
70 "Chan %d ISP_MARK_PORTDB@LINE %d", b, __LINE__); \
71 isp_mark_portdb(a, b, c)
76 static const char fconf[] = "Chan %d PortDB[%d] changed:\n current =(0x%x@0x%06x 0x%08x%08x 0x%08x%08x)\n database=(0x%x@0x%06x 0x%08x%08x 0x%08x%08x)";
77 static const char notresp[] = "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
78 static const char xact1[] = "HBA attempted queued transaction with disconnect not set for %d.%d.%d";
79 static const char xact2[] = "HBA attempted queued transaction to target routine %d on target %d bus %d";
80 static const char xact3[] = "HBA attempted queued cmd for %d.%d.%d when queueing disabled";
81 static const char pskip[] = "SCSI phase skipped for target %d.%d.%d";
82 static const char topology[] = "Chan %d WWPN 0x%08x%08x PortID 0x%06x N-Port Handle %d, Connection '%s'";
83 static const char finmsg[] = "%d.%d.%d: FIN dl%d resid %ld STS 0x%x SKEY %c XS_ERR=0x%x";
84 static const char sc4[] = "NVRAM";
85 static const char bun[] = "bad underrun for %d.%d (count %d, resid %d, status %s)";
86 static const char lipd[] = "Chan %d LIP destroyed %d active commands";
87 static const char sacq[] = "unable to acquire scratch area";
89 static const uint8_t alpa_map[] = {
90 0xef, 0xe8, 0xe4, 0xe2, 0xe1, 0xe0, 0xdc, 0xda,
91 0xd9, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xce,
92 0xcd, 0xcc, 0xcb, 0xca, 0xc9, 0xc7, 0xc6, 0xc5,
93 0xc3, 0xbc, 0xba, 0xb9, 0xb6, 0xb5, 0xb4, 0xb3,
94 0xb2, 0xb1, 0xae, 0xad, 0xac, 0xab, 0xaa, 0xa9,
95 0xa7, 0xa6, 0xa5, 0xa3, 0x9f, 0x9e, 0x9d, 0x9b,
96 0x98, 0x97, 0x90, 0x8f, 0x88, 0x84, 0x82, 0x81,
97 0x80, 0x7c, 0x7a, 0x79, 0x76, 0x75, 0x74, 0x73,
98 0x72, 0x71, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x69,
99 0x67, 0x66, 0x65, 0x63, 0x5c, 0x5a, 0x59, 0x56,
100 0x55, 0x54, 0x53, 0x52, 0x51, 0x4e, 0x4d, 0x4c,
101 0x4b, 0x4a, 0x49, 0x47, 0x46, 0x45, 0x43, 0x3c,
102 0x3a, 0x39, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31,
103 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x27, 0x26,
104 0x25, 0x23, 0x1f, 0x1e, 0x1d, 0x1b, 0x18, 0x17,
105 0x10, 0x0f, 0x08, 0x04, 0x02, 0x01, 0x00
109 * Local function prototypes.
111 static int isp_parse_async(ispsoftc_t *, uint16_t);
112 static int isp_handle_other_response(ispsoftc_t *, int, isphdr_t *, uint32_t *);
113 static void isp_parse_status(ispsoftc_t *, ispstatusreq_t *, XS_T *, long *); static void
114 isp_parse_status_24xx(ispsoftc_t *, isp24xx_statusreq_t *, XS_T *, long *);
115 static void isp_fastpost_complete(ispsoftc_t *, uint16_t);
116 static int isp_mbox_continue(ispsoftc_t *);
117 static void isp_scsi_init(ispsoftc_t *);
118 static void isp_scsi_channel_init(ispsoftc_t *, int);
119 static void isp_fibre_init(ispsoftc_t *);
120 static void isp_fibre_init_2400(ispsoftc_t *);
121 static void isp_mark_portdb(ispsoftc_t *, int, int);
122 static int isp_plogx(ispsoftc_t *, int, uint16_t, uint32_t, int, int);
123 static int isp_port_login(ispsoftc_t *, uint16_t, uint32_t);
124 static int isp_port_logout(ispsoftc_t *, uint16_t, uint32_t);
125 static int isp_getpdb(ispsoftc_t *, int, uint16_t, isp_pdb_t *, int);
126 static void isp_dump_chip_portdb(ispsoftc_t *, int, int);
127 static uint64_t isp_get_wwn(ispsoftc_t *, int, int, int);
128 static int isp_fclink_test(ispsoftc_t *, int, int);
129 static int isp_pdb_sync(ispsoftc_t *, int);
130 static int isp_scan_loop(ispsoftc_t *, int);
131 static int isp_gid_ft_sns(ispsoftc_t *, int);
132 static int isp_gid_ft_ct_passthru(ispsoftc_t *, int);
133 static int isp_scan_fabric(ispsoftc_t *, int);
134 static int isp_login_device(ispsoftc_t *, int, uint32_t, isp_pdb_t *, uint16_t *);
135 static int isp_register_fc4_type(ispsoftc_t *, int);
136 static int isp_register_fc4_type_24xx(ispsoftc_t *, int);
137 static uint16_t isp_nxt_handle(ispsoftc_t *, int, uint16_t);
138 static void isp_fw_state(ispsoftc_t *, int);
139 static void isp_mboxcmd_qnw(ispsoftc_t *, mbreg_t *, int);
140 static void isp_mboxcmd(ispsoftc_t *, mbreg_t *);
142 static void isp_spi_update(ispsoftc_t *, int);
143 static void isp_setdfltsdparm(ispsoftc_t *);
144 static void isp_setdfltfcparm(ispsoftc_t *, int);
145 static int isp_read_nvram(ispsoftc_t *, int);
146 static int isp_read_nvram_2400(ispsoftc_t *, uint8_t *);
147 static void isp_rdnvram_word(ispsoftc_t *, int, uint16_t *);
148 static void isp_rd_2400_nvram(ispsoftc_t *, uint32_t, uint32_t *);
149 static void isp_parse_nvram_1020(ispsoftc_t *, uint8_t *);
150 static void isp_parse_nvram_1080(ispsoftc_t *, int, uint8_t *);
151 static void isp_parse_nvram_12160(ispsoftc_t *, int, uint8_t *);
152 static void isp_parse_nvram_2100(ispsoftc_t *, uint8_t *);
153 static void isp_parse_nvram_2400(ispsoftc_t *, uint8_t *);
158 * Hit the chip over the head, download new f/w if available and set it running.
160 * Locking done elsewhere.
164 isp_reset(ispsoftc_t *isp, int do_load_defaults)
167 uint32_t code_org, val;
168 int loops, i, dodnld = 1;
169 const char *btype = "????";
170 static const char dcrc[] = "Downloaded RISC Code Checksum Failure";
172 isp->isp_state = ISP_NILSTATE;
175 ISP_DISABLE_INTS(isp);
180 * Basic types (SCSI, FibreChannel and PCI or SBus)
181 * have been set in the MD code. We figure out more
182 * here. Possibly more refined types based upon PCI
183 * identification. Chip revision has been gathered.
185 * After we've fired this chip up, zero out the conf1 register
186 * for SCSI adapters and do other settings for the 2100.
189 ISP_DISABLE_INTS(isp);
192 * Pick an initial maxcmds value which will be used
193 * to allocate xflist pointer space. It may be changed
194 * later by the firmware.
197 isp->isp_maxcmds = 4096;
198 } else if (IS_2322(isp)) {
199 isp->isp_maxcmds = 2048;
200 } else if (IS_23XX(isp) || IS_2200(isp)) {
201 isp->isp_maxcmds = 1024;
203 isp->isp_maxcmds = 512;
207 * Set up DMA for the request and response queues.
209 * We do this now so we can use the request queue
210 * for dma to load firmware from.
212 if (ISP_MBOXDMASETUP(isp) != 0) {
213 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
218 * Set up default request/response queue in-pointer/out-pointer
222 isp->isp_rqstinrp = BIU2400_REQINP;
223 isp->isp_rqstoutrp = BIU2400_REQOUTP;
224 isp->isp_respinrp = BIU2400_RSPINP;
225 isp->isp_respoutrp = BIU2400_RSPOUTP;
226 } else if (IS_23XX(isp)) {
227 isp->isp_rqstinrp = BIU_REQINP;
228 isp->isp_rqstoutrp = BIU_REQOUTP;
229 isp->isp_respinrp = BIU_RSPINP;
230 isp->isp_respoutrp = BIU_RSPOUTP;
232 isp->isp_rqstinrp = INMAILBOX4;
233 isp->isp_rqstoutrp = OUTMAILBOX4;
234 isp->isp_respinrp = OUTMAILBOX5;
235 isp->isp_respoutrp = INMAILBOX5;
239 * Put the board into PAUSE mode (so we can read the SXP registers
240 * or write FPM/FBM registers).
243 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_HOST_INT);
244 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
245 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_PAUSE);
247 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
251 switch (isp->isp_type) {
279 * While we're paused, reset the FPM module and FBM
282 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
283 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
284 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
285 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
286 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
288 } else if (IS_1240(isp)) {
293 sdp = SDPARAM(isp, 0);
294 sdp->isp_ultramode = 1;
295 sdp = SDPARAM(isp, 1);
296 sdp->isp_ultramode = 1;
298 * XXX: Should probably do some bus sensing.
300 } else if (IS_ULTRA3(isp)) {
301 sdparam *sdp = isp->isp_param;
303 isp->isp_clock = 100;
307 else if (IS_12160(isp))
311 sdp->isp_lvdmode = 1;
313 if (IS_DUALBUS(isp)) {
315 sdp->isp_lvdmode = 1;
317 } else if (IS_ULTRA2(isp)) {
318 static const char m[] = "bus %d is in %s Mode";
320 sdparam *sdp = SDPARAM(isp, 0);
322 isp->isp_clock = 100;
326 else if (IS_1080(isp))
331 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
333 case ISP1080_LVD_MODE:
334 sdp->isp_lvdmode = 1;
335 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
337 case ISP1080_HVD_MODE:
338 sdp->isp_diffmode = 1;
339 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
341 case ISP1080_SE_MODE:
342 sdp->isp_ultramode = 1;
343 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
346 isp_prt(isp, ISP_LOGERR,
347 "unknown mode on bus %d (0x%x)", 0, l);
351 if (IS_DUALBUS(isp)) {
352 sdp = SDPARAM(isp, 1);
353 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
354 l &= ISP1080_MODE_MASK;
356 case ISP1080_LVD_MODE:
357 sdp->isp_lvdmode = 1;
358 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
360 case ISP1080_HVD_MODE:
361 sdp->isp_diffmode = 1;
362 isp_prt(isp, ISP_LOGCONFIG,
363 m, 1, "Differential");
365 case ISP1080_SE_MODE:
366 sdp->isp_ultramode = 1;
367 isp_prt(isp, ISP_LOGCONFIG,
368 m, 1, "Single-Ended");
371 isp_prt(isp, ISP_LOGERR,
372 "unknown mode on bus %d (0x%x)", 1, l);
377 sdparam *sdp = SDPARAM(isp, 0);
378 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
381 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
385 isp->isp_type = ISP_HA_SCSI_1020;
390 * Some 1020A chips are Ultra Capable, but don't
391 * run the clock rate up for that unless told to
392 * do so by the Ultra Capable bits being set.
395 isp->isp_type = ISP_HA_SCSI_1020A;
400 isp->isp_type = ISP_HA_SCSI_1040;
405 isp->isp_type = ISP_HA_SCSI_1040A;
410 isp->isp_type = ISP_HA_SCSI_1040B;
415 isp->isp_type = ISP_HA_SCSI_1040C;
420 * Now, while we're at it, gather info about ultra
421 * and/or differential mode.
423 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
424 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
425 sdp->isp_diffmode = 1;
427 sdp->isp_diffmode = 0;
429 i = ISP_READ(isp, RISC_PSR);
430 if (isp->isp_bustype == ISP_BT_SBUS) {
431 i &= RISC_PSR_SBUS_ULTRA;
433 i &= RISC_PSR_PCI_ULTRA;
436 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
437 sdp->isp_ultramode = 1;
439 * If we're in Ultra Mode, we have to be 60MHz clock-
440 * even for the SBus version.
444 sdp->isp_ultramode = 0;
446 * Clock is known. Gronk.
451 * Machine dependent clock (if set) overrides
452 * our generic determinations.
454 if (isp->isp_mdvec->dv_clock) {
455 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
456 isp->isp_clock = isp->isp_mdvec->dv_clock;
463 * Clear instrumentation
465 isp->isp_intcnt = isp->isp_intbogus = 0;
468 * Do MD specific pre initialization
473 * Hit the chip over the head with hammer,
474 * and give it a chance to recover.
478 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
485 * Clear data && control DMA engines.
487 ISP_WRITE(isp, CDMA_CONTROL, DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
488 ISP_WRITE(isp, DDMA_CONTROL, DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
491 } else if (IS_24XX(isp)) {
493 * Stop DMA and wait for it to stop.
495 ISP_WRITE(isp, BIU2400_CSR, BIU2400_DMA_STOP|(3 << 4));
496 for (val = loops = 0; loops < 30000; loops++) {
498 val = ISP_READ(isp, BIU2400_CSR);
499 if ((val & BIU2400_DMA_ACTIVE) == 0) {
503 if (val & BIU2400_DMA_ACTIVE) {
505 isp_prt(isp, ISP_LOGERR, "DMA Failed to Stop on Reset");
509 * Hold it in SOFT_RESET and STOP state for 100us.
511 ISP_WRITE(isp, BIU2400_CSR, BIU2400_SOFT_RESET|BIU2400_DMA_STOP|(3 << 4));
513 for (loops = 0; loops < 10000; loops++) {
515 val = ISP_READ(isp, OUTMAILBOX0);
517 for (val = loops = 0; loops < 500000; loops ++) {
518 val = ISP_READ(isp, BIU2400_CSR);
519 if ((val & BIU2400_SOFT_RESET) == 0) {
523 if (val & BIU2400_SOFT_RESET) {
525 isp_prt(isp, ISP_LOGERR, "Failed to come out of reset");
529 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
536 * Clear data && control DMA engines.
538 ISP_WRITE(isp, CDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
539 ISP_WRITE(isp, TDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
540 ISP_WRITE(isp, RDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
544 * Wait for ISP to be ready to go...
546 loops = MBOX_DELAY_COUNT;
549 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET)) {
552 } else if (IS_24XX(isp)) {
553 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
557 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
562 ISP_DUMPREGS(isp, "chip reset timed out");
569 * After we've fired this chip up, zero out the conf1 register
570 * for SCSI adapters and other settings for the 2100.
574 ISP_WRITE(isp, BIU_CONF1, 0);
575 } else if (!IS_24XX(isp)) {
576 ISP_WRITE(isp, BIU2100_CSR, 0);
580 * Reset RISC Processor
583 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RESET);
584 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RELEASE);
585 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RESET);
587 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
589 ISP_WRITE(isp, BIU_SEMA, 0);
593 * Post-RISC Reset stuff.
596 for (val = loops = 0; loops < 5000000; loops++) {
598 val = ISP_READ(isp, OUTMAILBOX0);
605 isp_prt(isp, ISP_LOGERR, "reset didn't clear");
608 } else if (IS_SCSI(isp)) {
609 uint16_t tmp = isp->isp_mdvec->dv_conf1;
611 * Busted FIFO. Turn off all but burst enables.
613 if (isp->isp_type == ISP_HA_SCSI_1040A) {
614 tmp &= BIU_BURST_ENABLE;
616 ISP_SETBITS(isp, BIU_CONF1, tmp);
617 if (tmp & BIU_BURST_ENABLE) {
618 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
619 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
621 if (SDPARAM(isp, 0)->isp_ptisp) {
622 if (SDPARAM(isp, 0)->isp_ultramode) {
623 while (ISP_READ(isp, RISC_MTR) != 0x1313) {
624 ISP_WRITE(isp, RISC_MTR, 0x1313);
625 ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
628 ISP_WRITE(isp, RISC_MTR, 0x1212);
631 * PTI specific register
633 ISP_WRITE(isp, RISC_EMB, DUAL_BANK);
635 ISP_WRITE(isp, RISC_MTR, 0x1212);
637 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
639 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
640 if (IS_2200(isp) || IS_23XX(isp)) {
641 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
643 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
646 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
647 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
648 ISP_WRITE(isp, isp->isp_respinrp, 0);
649 ISP_WRITE(isp, isp->isp_respoutrp, 0);
651 ISP_WRITE(isp, BIU2400_PRI_REQINP, 0);
652 ISP_WRITE(isp, BIU2400_PRI_REQOUTP, 0);
653 ISP_WRITE(isp, BIU2400_ATIO_RSPINP, 0);
654 ISP_WRITE(isp, BIU2400_ATIO_RSPOUTP, 0);
658 * Do MD specific post initialization
663 * Wait for everything to finish firing up.
665 * Avoid doing this on early 2312s because you can generate a PCI
666 * parity error (chip breakage).
668 if (IS_2312(isp) && isp->isp_revision < 2) {
671 loops = MBOX_DELAY_COUNT;
672 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
676 isp_prt(isp, ISP_LOGERR,
677 "MBOX_BUSY never cleared on reset");
684 * Up until this point we've done everything by just reading or
685 * setting registers. From this point on we rely on at least *some*
686 * kind of firmware running in the card.
690 * Do some sanity checking by running a NOP command.
691 * If it succeeds, the ROM firmware is now running.
693 ISP_MEMZERO(&mbs, sizeof (mbs));
694 mbs.param[0] = MBOX_NO_OP;
695 mbs.logval = MBLOGALL;
696 isp_mboxcmd(isp, &mbs);
697 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
698 isp_prt(isp, ISP_LOGERR, "NOP ommand failed (%x)", mbs.param[0]);
704 * Do some operational tests
707 if (IS_SCSI(isp) || IS_24XX(isp)) {
708 ISP_MEMZERO(&mbs, sizeof (mbs));
709 mbs.param[0] = MBOX_MAILBOX_REG_TEST;
710 mbs.param[1] = 0xdead;
711 mbs.param[2] = 0xbeef;
712 mbs.param[3] = 0xffff;
713 mbs.param[4] = 0x1111;
714 mbs.param[5] = 0xa5a5;
715 mbs.param[6] = 0x0000;
716 mbs.param[7] = 0x0000;
717 mbs.logval = MBLOGALL;
718 isp_mboxcmd(isp, &mbs);
719 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
723 if (mbs.param[1] != 0xdead || mbs.param[2] != 0xbeef ||
724 mbs.param[3] != 0xffff || mbs.param[4] != 0x1111 ||
725 mbs.param[5] != 0xa5a5) {
727 isp_prt(isp, ISP_LOGERR, "Register Test Failed (0x%x 0x%x 0x%x 0x%x 0x%x)", mbs.param[1], mbs.param[2], mbs.param[3], mbs.param[4], mbs.param[5]);
734 * Download new Firmware, unless requested not to do so.
735 * This is made slightly trickier in some cases where the
736 * firmware of the ROM revision is newer than the revision
737 * compiled into the driver. So, where we used to compare
738 * versions of our f/w and the ROM f/w, now we just see
739 * whether we have f/w at all and whether a config flag
740 * has disabled our download.
742 if ((isp->isp_mdvec->dv_ispfw == NULL) || (isp->isp_confopts & ISP_CFG_NORELOAD)) {
747 code_org = ISP_CODE_ORG_2400;
748 } else if (IS_23XX(isp)) {
749 code_org = ISP_CODE_ORG_2300;
751 code_org = ISP_CODE_ORG;
754 if (dodnld && IS_24XX(isp)) {
755 const uint32_t *ptr = isp->isp_mdvec->dv_ispfw;
758 * Keep loading until we run out of f/w.
760 code_org = ptr[2]; /* 1st load address is our start addr */
765 isp_prt(isp, ISP_LOGDEBUG0, "load 0x%x words of code at load address 0x%x", ptr[3], ptr[2]);
771 while (wi < ptr[3]) {
775 nw = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) >> 2;
779 cp = isp->isp_rquest;
780 for (i = 0; i < nw; i++) {
781 ISP_IOXPUT_32(isp, ptr[wi++], &cp[i]);
784 MEMORYBARRIER(isp, SYNC_REQUEST, 0, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)));
785 ISP_MEMZERO(&mbs, sizeof (mbs));
786 if (la < 0x10000 && nw < 0x10000) {
787 mbs.param[0] = MBOX_LOAD_RISC_RAM_2100;
789 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
790 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
792 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
793 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
795 mbs.param[0] = MBOX_LOAD_RISC_RAM;
797 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
798 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
799 mbs.param[4] = nw >> 16;
801 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
802 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
803 mbs.param[8] = la >> 16;
805 mbs.logval = MBLOGALL;
806 isp_mboxcmd(isp, &mbs);
807 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
808 isp_prt(isp, ISP_LOGERR, "F/W Risc Ram Load Failed");
820 isp->isp_loaded_fw = 1;
821 } else if (dodnld && IS_23XX(isp)) {
822 const uint16_t *ptr = isp->isp_mdvec->dv_ispfw;
823 uint16_t wi, wl, segno;
832 isp_prt(isp, ISP_LOGDEBUG0, "load 0x%x words of code at load address 0x%x", ptr[3], la);
837 while (wi < ptr[3]) {
841 nw = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) >> 1;
845 if (nw > (1 << 15)) {
848 cp = isp->isp_rquest;
849 for (i = 0; i < nw; i++) {
850 ISP_IOXPUT_16(isp, ptr[wi++], &cp[i]);
853 MEMORYBARRIER(isp, SYNC_REQUEST, 0, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)));
854 ISP_MEMZERO(&mbs, sizeof (mbs));
856 mbs.param[0] = MBOX_LOAD_RISC_RAM_2100;
858 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
859 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
861 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
862 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
864 mbs.param[0] = MBOX_LOAD_RISC_RAM;
866 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
867 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
869 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
870 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
871 mbs.param[8] = la >> 16;
873 mbs.logval = MBLOGALL;
874 isp_mboxcmd(isp, &mbs);
875 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
876 isp_prt(isp, ISP_LOGERR, "F/W Risc Ram Load Failed");
892 * If we're a 2322, the firmware actually comes in
893 * three chunks. We loaded the first at the code_org
894 * address. The other two chunks, which follow right
895 * after each other in memory here, get loaded at
896 * addresses specfied at offset 0x9..0xB.
901 la = ptr[5] | ((ptr[4] & 0x3f) << 16);
903 isp->isp_loaded_fw = 1;
909 ucd.cp = isp->isp_mdvec->dv_ispfw;
910 isp->isp_mbxworkp = &ucd.np[1];
911 isp->isp_mbxwrk0 = ucd.np[3] - 1;
912 isp->isp_mbxwrk1 = code_org + 1;
913 ISP_MEMZERO(&mbs, sizeof (mbs));
914 mbs.param[0] = MBOX_WRITE_RAM_WORD;
915 mbs.param[1] = code_org;
916 mbs.param[2] = ucd.np[0];
917 mbs.logval = MBLOGNONE;
918 isp_mboxcmd(isp, &mbs);
919 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
920 isp_prt(isp, ISP_LOGERR, "F/W download failed at word %d", isp->isp_mbxwrk1 - code_org);
925 isp->isp_loaded_fw = 0;
926 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
930 * If we loaded firmware, verify its checksum
932 if (isp->isp_loaded_fw) {
933 ISP_MEMZERO(&mbs, sizeof (mbs));
934 mbs.param[0] = MBOX_VERIFY_CHECKSUM;
936 mbs.param[1] = code_org >> 16;
937 mbs.param[2] = code_org;
939 mbs.param[1] = code_org;
941 isp_mboxcmd(isp, &mbs);
942 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
943 isp_prt(isp, ISP_LOGERR, dcrc);
950 * Now start it rolling.
952 * If we didn't actually download f/w,
953 * we still need to (re)start it.
957 MBSINIT(&mbs, MBOX_EXEC_FIRMWARE, MBLOGALL, 1000000);
959 mbs.param[1] = code_org >> 16;
960 mbs.param[2] = code_org;
961 if (isp->isp_loaded_fw) {
969 } else if (IS_2322(isp)) {
970 mbs.param[1] = code_org;
971 if (isp->isp_loaded_fw) {
977 mbs.param[1] = code_org;
979 isp_mboxcmd(isp, &mbs);
980 if (IS_2322(isp) || IS_24XX(isp)) {
981 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
988 * Give it a chance to finish starting up.
989 * Give the 24XX more time.
994 * Check to see if the 24XX firmware really started.
996 if (mbs.param[1] == 0xdead) {
997 isp_prt(isp, ISP_LOGERR, "f/w didn't *really* start");
1005 * Set CLOCK RATE, but only if asked to.
1007 if (isp->isp_clock) {
1008 mbs.param[0] = MBOX_SET_CLOCK_RATE;
1009 mbs.param[1] = isp->isp_clock;
1010 mbs.logval = MBLOGNONE;
1011 isp_mboxcmd(isp, &mbs);
1012 /* we will try not to care if this fails */
1018 * Ask the chip for the current firmware version.
1019 * This should prove that the new firmware is working.
1021 MBSINIT(&mbs, MBOX_ABOUT_FIRMWARE, MBLOGALL, 0);
1022 isp_mboxcmd(isp, &mbs);
1023 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1029 * The SBus firmware that we are using apparently does not return
1030 * major, minor, micro revisions in the mailbox registers, which
1031 * is really, really, annoying.
1033 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
1035 #ifdef ISP_TARGET_MODE
1036 isp->isp_fwrev[0] = 7;
1037 isp->isp_fwrev[1] = 55;
1039 isp->isp_fwrev[0] = 1;
1040 isp->isp_fwrev[1] = 37;
1042 isp->isp_fwrev[2] = 0;
1045 isp->isp_fwrev[0] = mbs.param[1];
1046 isp->isp_fwrev[1] = mbs.param[2];
1047 isp->isp_fwrev[2] = mbs.param[3];
1050 isp_prt(isp, ISP_LOGCONFIG, "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
1051 btype, isp->isp_revision, dodnld? "loaded" : "resident", isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
1055 * We do not believe firmware attributes for 2100 code less
1056 * than 1.17.0, unless it's the firmware we specifically
1059 * Note that all 22XX and later f/w is greater than 1.X.0.
1061 if ((ISP_FW_OLDER_THAN(isp, 1, 17, 1))) {
1062 #ifdef USE_SMALLER_2100_FIRMWARE
1063 isp->isp_fwattr = ISP_FW_ATTR_SCCLUN;
1065 isp->isp_fwattr = 0;
1068 isp->isp_fwattr = mbs.param[6];
1069 isp_prt(isp, ISP_LOGDEBUG0, "Firmware Attributes = 0x%x", mbs.param[6]);
1072 #ifndef ISP_TARGET_MODE
1073 isp->isp_fwattr = ISP_FW_ATTR_TMODE;
1075 isp->isp_fwattr = 0;
1079 if (!IS_24XX(isp)) {
1080 MBSINIT(&mbs, MBOX_GET_FIRMWARE_STATUS, MBLOGALL, 0);
1081 isp_mboxcmd(isp, &mbs);
1082 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1086 if (isp->isp_maxcmds >= mbs.param[2]) {
1087 isp->isp_maxcmds = mbs.param[2];
1090 isp_prt(isp, ISP_LOGCONFIG, "%d max I/O command limit set", isp->isp_maxcmds);
1093 * If we don't have Multi-ID f/w loaded, we need to restrict channels to one.
1094 * Only make this check for non-SCSI cards (I'm not sure firmware attributes
1097 if (IS_FC(isp) && ISP_CAP_MULTI_ID(isp) == 0 && isp->isp_nchan > 1) {
1098 isp_prt(isp, ISP_LOGWARN, "non-MULTIID f/w loaded, only can enable 1 of %d channels", isp->isp_nchan);
1102 for (i = 0; i < isp->isp_nchan; i++) {
1103 isp_fw_state(isp, i);
1105 if (isp->isp_dead) {
1107 ISP_DISABLE_INTS(isp);
1111 isp->isp_state = ISP_RESETSTATE;
1114 * Okay- now that we have new firmware running, we now (re)set our
1115 * notion of how many luns we support. This is somewhat tricky because
1116 * if we haven't loaded firmware, we sometimes do not have an easy way
1117 * of knowing how many luns we support.
1119 * Expanded lun firmware gives you 32 luns for SCSI cards and
1120 * 16384 luns for Fibre Channel cards.
1122 * It turns out that even for QLogic 2100s with ROM 1.10 and above
1123 * we do get a firmware attributes word returned in mailbox register 6.
1125 * Because the lun is in a different position in the Request Queue
1126 * Entry structure for Fibre Channel with expanded lun firmware, we
1127 * can only support one lun (lun zero) when we don't know what kind
1128 * of firmware we're running.
1132 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
1133 isp->isp_maxluns = 32;
1135 isp->isp_maxluns = 8;
1138 isp->isp_maxluns = 8;
1141 if (ISP_CAP_SCCFW(isp)) {
1142 isp->isp_maxluns = 16384;
1144 isp->isp_maxluns = 16;
1149 * We get some default values established. As a side
1150 * effect, NVRAM is read here (unless overriden by
1151 * a configuration flag).
1153 if (do_load_defaults) {
1155 isp_setdfltsdparm(isp);
1157 for (i = 0; i < isp->isp_nchan; i++) {
1158 isp_setdfltfcparm(isp, i);
1165 * Initialize Parameters of Hardware to a known state.
1167 * Locks are held before coming here.
1171 isp_init(ispsoftc_t *isp)
1175 isp_fibre_init_2400(isp);
1177 isp_fibre_init(isp);
1182 GET_NANOTIME(&isp->isp_init_time);
1186 isp_scsi_init(ispsoftc_t *isp)
1188 sdparam *sdp_chan0, *sdp_chan1;
1191 sdp_chan0 = SDPARAM(isp, 0);
1192 sdp_chan1 = sdp_chan0;
1193 if (IS_DUALBUS(isp)) {
1194 sdp_chan1 = SDPARAM(isp, 1);
1197 /* First do overall per-card settings. */
1200 * If we have fast memory timing enabled, turn it on.
1202 if (sdp_chan0->isp_fast_mttr) {
1203 ISP_WRITE(isp, RISC_MTR, 0x1313);
1207 * Set Retry Delay and Count.
1208 * You set both channels at the same time.
1210 MBSINIT(&mbs, MBOX_SET_RETRY_COUNT, MBLOGALL, 0);
1211 mbs.param[1] = sdp_chan0->isp_retry_count;
1212 mbs.param[2] = sdp_chan0->isp_retry_delay;
1213 mbs.param[6] = sdp_chan1->isp_retry_count;
1214 mbs.param[7] = sdp_chan1->isp_retry_delay;
1215 isp_mboxcmd(isp, &mbs);
1216 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1221 * Set ASYNC DATA SETUP time. This is very important.
1223 MBSINIT(&mbs, MBOX_SET_ASYNC_DATA_SETUP_TIME, MBLOGALL, 0);
1224 mbs.param[1] = sdp_chan0->isp_async_data_setup;
1225 mbs.param[2] = sdp_chan1->isp_async_data_setup;
1226 isp_mboxcmd(isp, &mbs);
1227 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1232 * Set ACTIVE Negation State.
1234 MBSINIT(&mbs, MBOX_SET_ACT_NEG_STATE, MBLOGNONE, 0);
1236 (sdp_chan0->isp_req_ack_active_neg << 4) |
1237 (sdp_chan0->isp_data_line_active_neg << 5);
1239 (sdp_chan1->isp_req_ack_active_neg << 4) |
1240 (sdp_chan1->isp_data_line_active_neg << 5);
1241 isp_mboxcmd(isp, &mbs);
1242 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1243 isp_prt(isp, ISP_LOGERR,
1244 "failed to set active negation state (%d,%d), (%d,%d)",
1245 sdp_chan0->isp_req_ack_active_neg,
1246 sdp_chan0->isp_data_line_active_neg,
1247 sdp_chan1->isp_req_ack_active_neg,
1248 sdp_chan1->isp_data_line_active_neg);
1255 * Set the Tag Aging limit
1257 MBSINIT(&mbs, MBOX_SET_TAG_AGE_LIMIT, MBLOGALL, 0);
1258 mbs.param[1] = sdp_chan0->isp_tag_aging;
1259 mbs.param[2] = sdp_chan1->isp_tag_aging;
1260 isp_mboxcmd(isp, &mbs);
1261 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1262 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
1263 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
1268 * Set selection timeout.
1270 MBSINIT(&mbs, MBOX_SET_SELECT_TIMEOUT, MBLOGALL, 0);
1271 mbs.param[1] = sdp_chan0->isp_selection_timeout;
1272 mbs.param[2] = sdp_chan1->isp_selection_timeout;
1273 isp_mboxcmd(isp, &mbs);
1274 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1278 /* now do per-channel settings */
1279 isp_scsi_channel_init(isp, 0);
1280 if (IS_DUALBUS(isp))
1281 isp_scsi_channel_init(isp, 1);
1284 * Now enable request/response queues
1287 if (IS_ULTRA2(isp) || IS_1240(isp)) {
1288 MBSINIT(&mbs, MBOX_INIT_RES_QUEUE_A64, MBLOGALL, 0);
1289 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1290 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1291 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1293 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1294 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1295 isp_mboxcmd(isp, &mbs);
1296 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1299 isp->isp_residx = mbs.param[5];
1301 MBSINIT(&mbs, MBOX_INIT_REQ_QUEUE_A64, MBLOGALL, 0);
1302 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1303 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1304 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1306 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1307 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1308 isp_mboxcmd(isp, &mbs);
1309 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1312 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1314 MBSINIT(&mbs, MBOX_INIT_RES_QUEUE, MBLOGALL, 0);
1315 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1316 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1317 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1319 isp_mboxcmd(isp, &mbs);
1320 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1323 isp->isp_residx = mbs.param[5];
1325 MBSINIT(&mbs, MBOX_INIT_REQ_QUEUE, MBLOGALL, 0);
1326 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1327 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1328 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1330 isp_mboxcmd(isp, &mbs);
1331 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1334 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1338 * Turn on Fast Posting, LVD transitions
1340 * Ultra2 F/W always has had fast posting (and LVD transitions)
1342 * Ultra and older (i.e., SBus) cards may not. It's just safer
1343 * to assume not for them.
1346 MBSINIT(&mbs, MBOX_SET_FW_FEATURES, MBLOGALL, 0);
1348 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1350 if (IS_ULTRA2(isp) || IS_1240(isp))
1351 mbs.param[1] |= FW_FEATURE_RIO_16BIT;
1353 if (IS_ULTRA2(isp) || IS_1240(isp))
1354 mbs.param[1] |= FW_FEATURE_FAST_POST;
1356 if (mbs.param[1] != 0) {
1357 uint16_t sfeat = mbs.param[1];
1358 isp_mboxcmd(isp, &mbs);
1359 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1360 isp_prt(isp, ISP_LOGINFO,
1361 "Enabled FW features (0x%x)", sfeat);
1365 isp->isp_state = ISP_INITSTATE;
1369 isp_scsi_channel_init(ispsoftc_t *isp, int chan)
1375 sdp = SDPARAM(isp, chan);
1378 * Set (possibly new) Initiator ID.
1380 MBSINIT(&mbs, MBOX_SET_INIT_SCSI_ID, MBLOGALL, 0);
1381 mbs.param[1] = (chan << 7) | sdp->isp_initiator_id;
1382 isp_mboxcmd(isp, &mbs);
1383 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1386 isp_prt(isp, ISP_LOGINFO, "Chan %d Initiator ID is %d",
1387 chan, sdp->isp_initiator_id);
1391 * Set current per-target parameters to an initial safe minimum.
1393 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1397 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1400 #ifndef ISP_TARGET_MODE
1401 sdf = sdp->isp_devparam[tgt].goal_flags;
1402 sdf &= DPARM_SAFE_DFLT;
1404 * It is not quite clear when this changed over so that
1405 * we could force narrow and async for 1000/1020 cards,
1406 * but assume that this is only the case for loaded
1409 if (isp->isp_loaded_fw) {
1410 sdf |= DPARM_NARROW | DPARM_ASYNC;
1414 * The !$*!)$!$)* f/w uses the same index into some
1415 * internal table to decide how to respond to negotiations,
1416 * so if we've said "let's be safe" for ID X, and ID X
1417 * selects *us*, the negotiations will back to 'safe'
1418 * (as in narrow/async). What the f/w *should* do is
1419 * use the initiator id settings to decide how to respond.
1421 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1423 MBSINIT(&mbs, MBOX_SET_TARGET_PARAMS, MBLOGNONE, 0);
1424 mbs.param[1] = (chan << 15) | (tgt << 8);
1426 if ((sdf & DPARM_SYNC) == 0) {
1430 (sdp->isp_devparam[tgt].goal_offset << 8) |
1431 (sdp->isp_devparam[tgt].goal_period);
1433 isp_prt(isp, ISP_LOGDEBUG0,
1434 "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1435 chan, tgt, mbs.param[2], mbs.param[3] >> 8,
1436 mbs.param[3] & 0xff);
1437 isp_mboxcmd(isp, &mbs);
1438 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1439 sdf = DPARM_SAFE_DFLT;
1440 MBSINIT(&mbs, MBOX_SET_TARGET_PARAMS, MBLOGALL, 0);
1441 mbs.param[1] = (tgt << 8) | (chan << 15);
1444 isp_mboxcmd(isp, &mbs);
1445 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1451 * We don't update any information directly from the f/w
1452 * because we need to run at least one command to cause a
1453 * new state to be latched up. So, we just assume that we
1454 * converge to the values we just had set.
1456 * Ensure that we don't believe tagged queuing is enabled yet.
1457 * It turns out that sometimes the ISP just ignores our
1458 * attempts to set parameters for devices that it hasn't
1461 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1462 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1463 MBSINIT(&mbs, MBOX_SET_DEV_QUEUE_PARAMS, MBLOGALL, 0);
1464 mbs.param[1] = (chan << 15) | (tgt << 8) | lun;
1465 mbs.param[2] = sdp->isp_max_queue_depth;
1466 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1467 isp_mboxcmd(isp, &mbs);
1468 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1473 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1474 if (sdp->isp_devparam[tgt].dev_refresh) {
1475 sdp->sendmarker = 1;
1483 * Fibre Channel specific initialization.
1486 isp_fibre_init(ispsoftc_t *isp)
1489 isp_icb_t local, *icbp = &local;
1494 * We only support one channel on non-24XX cards
1496 fcp = FCPARAM(isp, 0);
1497 if (fcp->role == ISP_ROLE_NONE) {
1498 isp->isp_state = ISP_INITSTATE;
1502 ISP_MEMZERO(icbp, sizeof (*icbp));
1503 icbp->icb_version = ICB_VERSION1;
1504 icbp->icb_fwoptions = fcp->isp_fwoptions;
1507 * Firmware Options are either retrieved from NVRAM or
1508 * are patched elsewhere. We check them for sanity here
1509 * and make changes based on board revision, but otherwise
1510 * let others decide policy.
1514 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1516 if (IS_2100(isp) && isp->isp_revision < 5) {
1517 icbp->icb_fwoptions &= ~ICBOPT_FAIRNESS;
1521 * We have to use FULL LOGIN even though it resets the loop too much
1522 * because otherwise port database entries don't get updated after
1523 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1525 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1526 icbp->icb_fwoptions |= ICBOPT_FULL_LOGIN;
1530 * Insist on Port Database Update Async notifications
1532 icbp->icb_fwoptions |= ICBOPT_PDBCHANGE_AE;
1535 * Make sure that target role reflects into fwoptions.
1537 if (fcp->role & ISP_ROLE_TARGET) {
1538 icbp->icb_fwoptions |= ICBOPT_TGT_ENABLE;
1540 icbp->icb_fwoptions &= ~ICBOPT_TGT_ENABLE;
1543 if (fcp->role & ISP_ROLE_INITIATOR) {
1544 icbp->icb_fwoptions &= ~ICBOPT_INI_DISABLE;
1546 icbp->icb_fwoptions |= ICBOPT_INI_DISABLE;
1549 icbp->icb_maxfrmlen = DEFAULT_FRAMESIZE(isp);
1550 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN ||
1551 icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1552 isp_prt(isp, ISP_LOGERR,
1553 "bad frame length (%d) from NVRAM- using %d",
1554 DEFAULT_FRAMESIZE(isp), ICB_DFLT_FRMLEN);
1555 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1557 icbp->icb_maxalloc = fcp->isp_maxalloc;
1558 if (icbp->icb_maxalloc < 1) {
1559 isp_prt(isp, ISP_LOGERR,
1560 "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1561 icbp->icb_maxalloc = 16;
1563 icbp->icb_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
1564 if (icbp->icb_execthrottle < 1) {
1565 isp_prt(isp, ISP_LOGERR,
1566 "bad execution throttle of %d- using %d",
1567 DEFAULT_EXEC_THROTTLE(isp), ICB_DFLT_THROTTLE);
1568 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1570 icbp->icb_retry_delay = fcp->isp_retry_delay;
1571 icbp->icb_retry_count = fcp->isp_retry_count;
1572 icbp->icb_hardaddr = fcp->isp_loopid;
1573 ownloopid = (isp->isp_confopts & ISP_CFG_OWNLOOPID) != 0;
1574 if (icbp->icb_hardaddr >= LOCAL_LOOP_LIM) {
1575 icbp->icb_hardaddr = 0;
1580 * Our life seems so much better with 2200s and later with
1581 * the latest f/w if we set Hard Address.
1583 if (ownloopid || ISP_FW_NEWER_THAN(isp, 2, 2, 5)) {
1584 icbp->icb_fwoptions |= ICBOPT_HARD_ADDRESS;
1588 * Right now we just set extended options to prefer point-to-point
1589 * over loop based upon some soft config options.
1591 * NB: for the 2300, ICBOPT_EXTENDED is required.
1593 if (IS_2200(isp) || IS_23XX(isp)) {
1594 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1596 * Prefer or force Point-To-Point instead Loop?
1598 switch (isp->isp_confopts & ISP_CFG_PORT_PREF) {
1600 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1602 case ISP_CFG_NPORT_ONLY:
1603 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1605 case ISP_CFG_LPORT_ONLY:
1606 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1609 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1614 * There seems to just be too much breakage here
1615 * with RIO and Fast Posting- it probably actually
1616 * works okay but this driver is messing it up.
1617 * This card is really ancient by now, so let's
1618 * just opt for safety and not use the feature.
1621 if (ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1622 icbp->icb_xfwoptions |= ICBXOPT_RIO_16BIT;
1623 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1624 icbp->icb_racctimer = 4;
1625 icbp->icb_idelaytimer = 8;
1627 icbp->icb_fwoptions |= ICBOPT_FAST_POST;
1630 icbp->icb_xfwoptions &= ~ICBXOPT_RIO_16BIT;
1631 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1635 * QLogic recommends that FAST Posting be turned
1636 * off for 23XX cards and instead allow the HBA
1637 * to write response queue entries and interrupt
1638 * after a delay (ZIO).
1640 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1641 if ((fcp->isp_xfwoptions & ICBXOPT_TIMER_MASK) == ICBXOPT_ZIO) {
1642 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1643 icbp->icb_idelaytimer = 10;
1645 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1646 icbp->icb_zfwoptions |= ICBZOPT_RATE_ONEGB;
1647 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1648 icbp->icb_zfwoptions |= ICBZOPT_RATE_TWOGB;
1650 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1652 if (fcp->isp_zfwoptions & ICBZOPT_50_OHM) {
1653 icbp->icb_zfwoptions |= ICBZOPT_50_OHM;
1660 * For 22XX > 2.1.26 && 23XX, set some options.
1661 * XXX: Probably okay for newer 2100 f/w too.
1663 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1665 * Turn on LIP F8 async event (1)
1666 * Turn on generate AE 8013 on all LIP Resets (2)
1667 * Disable LIP F7 switching (8)
1669 MBSINIT(&mbs, MBOX_SET_FIRMWARE_OPTIONS, MBLOGALL, 0);
1673 isp_mboxcmd(isp, &mbs);
1674 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1678 icbp->icb_logintime = ICB_LOGIN_TOV;
1679 icbp->icb_lunetimeout = ICB_LUN_ENABLE_TOV;
1681 if (fcp->isp_wwnn && fcp->isp_wwpn && (fcp->isp_wwnn >> 60) != 2) {
1682 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1683 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, fcp->isp_wwnn);
1684 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1685 isp_prt(isp, ISP_LOGDEBUG1,
1686 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1687 ((uint32_t) (fcp->isp_wwnn >> 32)),
1688 ((uint32_t) (fcp->isp_wwnn)),
1689 ((uint32_t) (fcp->isp_wwpn >> 32)),
1690 ((uint32_t) (fcp->isp_wwpn)));
1691 } else if (fcp->isp_wwpn) {
1692 icbp->icb_fwoptions &= ~ICBOPT_BOTH_WWNS;
1693 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1694 isp_prt(isp, ISP_LOGDEBUG1,
1695 "Setting ICB Port 0x%08x%08x",
1696 ((uint32_t) (fcp->isp_wwpn >> 32)),
1697 ((uint32_t) (fcp->isp_wwpn)));
1699 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
1702 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1703 if (icbp->icb_rqstqlen < 1) {
1704 isp_prt(isp, ISP_LOGERR, "bad request queue length");
1706 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1707 if (icbp->icb_rsltqlen < 1) {
1708 isp_prt(isp, ISP_LOGERR, "bad result queue length");
1710 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1711 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1712 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1713 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1714 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1715 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1716 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1717 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1719 if (FC_SCRATCH_ACQUIRE(isp, 0)) {
1720 isp_prt(isp, ISP_LOGERR, sacq);
1723 isp_prt(isp, ISP_LOGDEBUG0,
1724 "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1725 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1727 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1732 MBSINIT(&mbs, MBOX_INIT_FIRMWARE, MBLOGALL, 30000000);
1733 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1734 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1735 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1736 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1737 mbs.logval = MBLOGALL;
1738 isp_prt(isp, ISP_LOGDEBUG0, "INIT F/W from %p (%08x%08x)",
1739 fcp->isp_scratch, (uint32_t) ((uint64_t)fcp->isp_scdma >> 32),
1740 (uint32_t) fcp->isp_scdma);
1741 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp));
1742 isp_mboxcmd(isp, &mbs);
1743 FC_SCRATCH_RELEASE(isp, 0);
1744 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1745 isp_print_bytes(isp, "isp_fibre_init", sizeof (*icbp), icbp);
1748 isp->isp_reqidx = 0;
1749 isp->isp_reqodx = 0;
1750 isp->isp_residx = 0;
1753 * Whatever happens, we're now committed to being here.
1755 isp->isp_state = ISP_INITSTATE;
1759 isp_fibre_init_2400(ispsoftc_t *isp)
1762 isp_icb_2400_t local, *icbp = &local;
1767 * Check to see whether all channels have *some* kind of role
1769 for (chan = 0; chan < isp->isp_nchan; chan++) {
1770 fcp = FCPARAM(isp, chan);
1771 if (fcp->role != ISP_ROLE_NONE) {
1775 if (chan == isp->isp_nchan) {
1776 isp_prt(isp, ISP_LOGDEBUG0, "all %d channels with role 'none'", chan);
1777 isp->isp_state = ISP_INITSTATE;
1782 * Start with channel 0.
1784 fcp = FCPARAM(isp, 0);
1787 * Turn on LIP F8 async event (1)
1789 MBSINIT(&mbs, MBOX_SET_FIRMWARE_OPTIONS, MBLOGALL, 0);
1791 isp_mboxcmd(isp, &mbs);
1792 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1796 ISP_MEMZERO(icbp, sizeof (*icbp));
1797 icbp->icb_fwoptions1 = fcp->isp_fwoptions;
1798 if (fcp->role & ISP_ROLE_TARGET) {
1799 icbp->icb_fwoptions1 |= ICB2400_OPT1_TGT_ENABLE;
1801 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_TGT_ENABLE;
1804 if (fcp->role & ISP_ROLE_INITIATOR) {
1805 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_INI_DISABLE;
1807 icbp->icb_fwoptions1 |= ICB2400_OPT1_INI_DISABLE;
1810 icbp->icb_version = ICB_VERSION1;
1811 icbp->icb_maxfrmlen = DEFAULT_FRAMESIZE(isp);
1812 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN || icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1813 isp_prt(isp, ISP_LOGERR, "bad frame length (%d) from NVRAM- using %d", DEFAULT_FRAMESIZE(isp), ICB_DFLT_FRMLEN);
1814 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1817 icbp->icb_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
1818 if (icbp->icb_execthrottle < 1) {
1819 isp_prt(isp, ISP_LOGERR, "bad execution throttle of %d- using %d", DEFAULT_EXEC_THROTTLE(isp), ICB_DFLT_THROTTLE);
1820 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1823 if (icbp->icb_fwoptions1 & ICB2400_OPT1_TGT_ENABLE) {
1825 * Get current resource count
1827 MBSINIT(&mbs, MBOX_GET_RESOURCE_COUNT, MBLOGALL, 0);
1829 isp_mboxcmd(isp, &mbs);
1830 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1833 icbp->icb_xchgcnt = mbs.param[3];
1837 icbp->icb_hardaddr = fcp->isp_loopid;
1838 if (icbp->icb_hardaddr >= LOCAL_LOOP_LIM) {
1839 icbp->icb_hardaddr = 0;
1845 icbp->icb_fwoptions1 |= ICB2400_OPT1_HARD_ADDRESS;
1847 icbp->icb_fwoptions2 = fcp->isp_xfwoptions;
1848 switch (isp->isp_confopts & ISP_CFG_PORT_PREF) {
1852 * XXX: This causes the f/w to crash.
1854 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
1855 icbp->icb_fwoptions2 |= ICB2400_OPT2_PTP_2_LOOP;
1858 case ISP_CFG_NPORT_ONLY:
1859 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
1860 icbp->icb_fwoptions2 |= ICB2400_OPT2_PTP_ONLY;
1862 case ISP_CFG_LPORT_ONLY:
1863 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
1864 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_ONLY;
1867 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
1868 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_2_PTP;
1872 /* force this on for now */
1873 icbp->icb_fwoptions2 |= ICB2400_OPT2_ZIO;
1875 switch (icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK) {
1876 case ICB2400_OPT2_ZIO:
1877 case ICB2400_OPT2_ZIO1:
1878 icbp->icb_idelaytimer = 0;
1883 isp_prt(isp, ISP_LOGWARN, "bad value %x in fwopt2 timer field", icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK);
1884 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TIMER_MASK;
1889 * We don't support FCTAPE, so clear it.
1891 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_FCTAPE;
1893 icbp->icb_fwoptions3 = fcp->isp_zfwoptions;
1894 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_AUTO;
1895 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1896 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_ONEGB;
1897 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1898 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_TWOGB;
1899 } else if (isp->isp_confopts & ISP_CFG_FOURGB) {
1900 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_FOURGB;
1902 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_AUTO;
1905 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
1906 icbp->icb_fwoptions3 |= ICB2400_OPT3_SOFTID;
1908 icbp->icb_logintime = ICB_LOGIN_TOV;
1910 if (fcp->isp_wwnn && fcp->isp_wwpn && (fcp->isp_wwnn >> 60) != 2) {
1911 icbp->icb_fwoptions1 |= ICB2400_OPT1_BOTH_WWNS;
1912 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1913 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, fcp->isp_wwnn);
1914 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)),
1915 ((uint32_t) (fcp->isp_wwpn >> 32)), ((uint32_t) (fcp->isp_wwpn)));
1916 } else if (fcp->isp_wwpn) {
1917 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_BOTH_WWNS;
1918 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1919 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)));
1921 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
1924 icbp->icb_retry_count = fcp->isp_retry_count;
1926 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1927 if (icbp->icb_rqstqlen < 8) {
1928 isp_prt(isp, ISP_LOGERR, "bad request queue length %d", icbp->icb_rqstqlen);
1931 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1932 if (icbp->icb_rsltqlen < 8) {
1933 isp_prt(isp, ISP_LOGERR, "bad result queue length %d",
1934 icbp->icb_rsltqlen);
1937 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1938 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1939 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1940 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1942 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1943 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1944 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1945 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1947 #ifdef ISP_TARGET_MODE
1948 /* unconditionally set up the ATIO queue if we support target mode */
1949 icbp->icb_atioqlen = RESULT_QUEUE_LEN(isp);
1950 if (icbp->icb_atioqlen < 8) {
1951 isp_prt(isp, ISP_LOGERR, "bad ATIO queue length %d", icbp->icb_atioqlen);
1954 icbp->icb_atioqaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_atioq_dma);
1955 icbp->icb_atioqaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_atioq_dma);
1956 icbp->icb_atioqaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_atioq_dma);
1957 icbp->icb_atioqaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_atioq_dma);
1958 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),
1959 DMA_WD1(isp->isp_atioq_dma), DMA_WD0(isp->isp_atioq_dma));
1962 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);
1964 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),
1965 DMA_WD1(isp->isp_rquest_dma), DMA_WD0(isp->isp_rquest_dma), DMA_WD3(isp->isp_result_dma), DMA_WD2(isp->isp_result_dma),
1966 DMA_WD1(isp->isp_result_dma), DMA_WD0(isp->isp_result_dma));
1968 if (isp->isp_dblev & ISP_LOGDEBUG1) {
1969 isp_print_bytes(isp, "isp_fibre_init_2400", sizeof (*icbp), icbp);
1972 if (FC_SCRATCH_ACQUIRE(isp, 0)) {
1973 isp_prt(isp, ISP_LOGERR, sacq);
1976 ISP_MEMZERO(fcp->isp_scratch, ISP_FC_SCRLEN);
1977 isp_put_icb_2400(isp, icbp, fcp->isp_scratch);
1980 * Now fill in information about any additional channels
1982 if (isp->isp_nchan > 1) {
1983 isp_icb_2400_vpinfo_t vpinfo, *vdst;
1984 vp_port_info_t pi, *pdst;
1988 vpinfo.vp_count = isp->isp_nchan - 1;
1989 vpinfo.vp_global_options = 0;
1990 off = fcp->isp_scratch;
1991 off += ICB2400_VPINFO_OFF;
1992 vdst = (isp_icb_2400_vpinfo_t *) off;
1993 isp_put_icb_2400_vpinfo(isp, &vpinfo, vdst);
1994 amt = ICB2400_VPINFO_OFF + sizeof (isp_icb_2400_vpinfo_t);
1995 for (chan = 1; chan < isp->isp_nchan; chan++) {
1998 ISP_MEMZERO(&pi, sizeof (pi));
1999 fcp2 = FCPARAM(isp, chan);
2000 if (fcp2->role != ISP_ROLE_NONE) {
2001 pi.vp_port_options = ICB2400_VPOPT_ENABLED;
2002 if (fcp2->role & ISP_ROLE_INITIATOR) {
2003 pi.vp_port_options |= ICB2400_VPOPT_INI_ENABLE;
2005 if ((fcp2->role & ISP_ROLE_TARGET) == 0) {
2006 pi.vp_port_options |= ICB2400_VPOPT_TGT_DISABLE;
2008 MAKE_NODE_NAME_FROM_WWN(pi.vp_port_portname, fcp2->isp_wwpn);
2009 MAKE_NODE_NAME_FROM_WWN(pi.vp_port_nodename, fcp2->isp_wwnn);
2011 off = fcp->isp_scratch;
2012 off += ICB2400_VPINFO_PORT_OFF(chan);
2013 pdst = (vp_port_info_t *) off;
2014 isp_put_vp_port_info(isp, &pi, pdst);
2015 amt += ICB2400_VPOPT_WRITE_SIZE;
2022 MBSINIT(&mbs, 0, MBLOGALL, 30000000);
2023 if (isp->isp_nchan > 1) {
2024 mbs.param[0] = MBOX_INIT_FIRMWARE_MULTI_ID;
2026 mbs.param[0] = MBOX_INIT_FIRMWARE;
2028 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2029 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2030 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2031 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2032 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));
2033 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp));
2034 isp_mboxcmd(isp, &mbs);
2035 FC_SCRATCH_RELEASE(isp, 0);
2037 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2040 isp->isp_reqidx = 0;
2041 isp->isp_reqodx = 0;
2042 isp->isp_residx = 0;
2045 * Whatever happens, we're now committed to being here.
2047 isp->isp_state = ISP_INITSTATE;
2051 isp_mark_portdb(ispsoftc_t *isp, int chan, int disposition)
2053 fcparam *fcp = FCPARAM(isp, chan);
2056 if (chan < 0 || chan >= isp->isp_nchan) {
2057 isp_prt(isp, ISP_LOGWARN, "isp_mark_portdb: bad channel %d", chan);
2060 for (i = 0; i < MAX_FC_TARG; i++) {
2061 if (fcp->portdb[i].target_mode) {
2062 if (disposition < 0) {
2063 isp_prt(isp, ISP_LOGTINFO, "isp_mark_portdb: Chan %d zeroing handle 0x" "%04x port 0x%06x", chan,
2064 fcp->portdb[i].handle, fcp->portdb[i].portid);
2065 ISP_MEMZERO(&fcp->portdb[i], sizeof (fcportdb_t));
2069 if (disposition == 0) {
2070 ISP_MEMZERO(&fcp->portdb[i], sizeof (fcportdb_t));
2072 switch (fcp->portdb[i].state) {
2073 case FC_PORTDB_STATE_CHANGED:
2074 case FC_PORTDB_STATE_PENDING_VALID:
2075 case FC_PORTDB_STATE_VALID:
2076 case FC_PORTDB_STATE_PROBATIONAL:
2077 fcp->portdb[i].state = FC_PORTDB_STATE_PROBATIONAL;
2079 case FC_PORTDB_STATE_ZOMBIE:
2081 case FC_PORTDB_STATE_NIL:
2083 ISP_MEMZERO(&fcp->portdb[i], sizeof (fcportdb_t));
2084 fcp->portdb[i].state = FC_PORTDB_STATE_NIL;
2092 * Perform an IOCB PLOGI or LOGO via EXECUTE IOCB A64 for 24XX cards
2093 * or via FABRIC LOGIN/FABRIC LOGOUT for other cards.
2096 isp_plogx(ispsoftc_t *isp, int chan, uint16_t handle, uint32_t portid,
2100 uint8_t q[QENTRY_LEN];
2104 uint32_t sst, parm1;
2109 if (!IS_24XX(isp)) {
2110 int action = flags & PLOGX_FLG_CMD_MASK;
2111 if (action == PLOGX_FLG_CMD_PLOGI) {
2112 return (isp_port_login(isp, handle, portid));
2113 } else if (action == PLOGX_FLG_CMD_LOGO) {
2114 return (isp_port_logout(isp, handle, portid));
2116 return (MBOX_INVALID_COMMAND);
2120 ISP_MEMZERO(q, QENTRY_LEN);
2121 plp = (isp_plogx_t *) q;
2122 plp->plogx_header.rqs_entry_count = 1;
2123 plp->plogx_header.rqs_entry_type = RQSTYPE_LOGIN;
2124 plp->plogx_handle = 0xffffffff;
2125 plp->plogx_nphdl = handle;
2126 plp->plogx_vphdl = chan;
2127 plp->plogx_portlo = portid;
2128 plp->plogx_rspsz_porthi = (portid >> 16) & 0xff;
2129 plp->plogx_flags = flags;
2131 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2132 isp_print_bytes(isp, "IOCB LOGX", QENTRY_LEN, plp);
2136 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
2137 isp_prt(isp, ISP_LOGERR, sacq);
2141 fcp = FCPARAM(isp, chan);
2142 scp = fcp->isp_scratch;
2143 isp_put_plogx(isp, plp, (isp_plogx_t *) scp);
2145 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 500000);
2146 mbs.param[1] = QENTRY_LEN;
2147 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2148 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2149 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2150 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2151 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, QENTRY_LEN);
2152 isp_mboxcmd(isp, &mbs);
2153 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2154 rval = mbs.param[0];
2157 MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN, QENTRY_LEN);
2159 isp_get_plogx(isp, (isp_plogx_t *) scp, plp);
2160 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2161 isp_print_bytes(isp, "IOCB LOGX response", QENTRY_LEN, plp);
2164 if (plp->plogx_status == PLOGX_STATUS_OK) {
2167 } else if (plp->plogx_status != PLOGX_STATUS_IOCBERR) {
2168 isp_prt(isp, ISP_LOGWARN,
2169 "status 0x%x on port login IOCB chanel %d",
2170 plp->plogx_status, chan);
2175 sst = plp->plogx_ioparm[0].lo16 | (plp->plogx_ioparm[0].hi16 << 16);
2176 parm1 = plp->plogx_ioparm[1].lo16 | (plp->plogx_ioparm[1].hi16 << 16);
2183 case PLOGX_IOCBERR_NOLINK:
2186 case PLOGX_IOCBERR_NOIOCB:
2187 msg = "no IOCB buffer";
2189 case PLOGX_IOCBERR_NOXGHG:
2190 msg = "no Exchange Control Block";
2192 case PLOGX_IOCBERR_FAILED:
2193 ISP_SNPRINTF(buf, sizeof (buf),
2194 "reason 0x%x (last LOGIN state 0x%x)",
2195 parm1 & 0xff, (parm1 >> 8) & 0xff);
2198 case PLOGX_IOCBERR_NOFABRIC:
2201 case PLOGX_IOCBERR_NOTREADY:
2202 msg = "firmware not ready";
2204 case PLOGX_IOCBERR_NOLOGIN:
2205 ISP_SNPRINTF(buf, sizeof (buf), "not logged in (last state 0x%x)",
2208 rval = MBOX_NOT_LOGGED_IN;
2210 case PLOGX_IOCBERR_REJECT:
2211 ISP_SNPRINTF(buf, sizeof (buf), "LS_RJT = 0x%x", parm1);
2214 case PLOGX_IOCBERR_NOPCB:
2215 msg = "no PCB allocated";
2217 case PLOGX_IOCBERR_EINVAL:
2218 ISP_SNPRINTF(buf, sizeof (buf), "invalid parameter at offset 0x%x",
2222 case PLOGX_IOCBERR_PORTUSED:
2223 lev = ISP_LOGSANCFG|ISP_LOGDEBUG0;
2224 ISP_SNPRINTF(buf, sizeof (buf),
2225 "already logged in with N-Port handle 0x%x", parm1);
2227 rval = MBOX_PORT_ID_USED | (parm1 << 16);
2229 case PLOGX_IOCBERR_HNDLUSED:
2230 lev = ISP_LOGSANCFG|ISP_LOGDEBUG0;
2231 ISP_SNPRINTF(buf, sizeof (buf),
2232 "handle already used for PortID 0x%06x", parm1);
2234 rval = MBOX_LOOP_ID_USED;
2236 case PLOGX_IOCBERR_NOHANDLE:
2237 msg = "no handle allocated";
2239 case PLOGX_IOCBERR_NOFLOGI:
2240 msg = "no FLOGI_ACC";
2243 ISP_SNPRINTF(buf, sizeof (buf), "status %x from %x",
2244 plp->plogx_status, flags);
2249 isp_prt(isp, ISP_LOGERR,
2250 "Chan %d PLOGX PortID 0x%06x to N-Port handle 0x%x: %s",
2251 chan, portid, handle, msg);
2255 FC_SCRATCH_RELEASE(isp, chan);
2261 isp_port_login(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2265 MBSINIT(&mbs, MBOX_FABRIC_LOGIN, MBLOGNONE, 500000);
2266 if (ISP_CAP_2KLOGIN(isp)) {
2267 mbs.param[1] = handle;
2268 mbs.ibits = (1 << 10);
2270 mbs.param[1] = handle << 8;
2272 mbs.param[2] = portid >> 16;
2273 mbs.param[3] = portid;
2274 mbs.logval = MBLOGNONE;
2275 mbs.timeout = 500000;
2276 isp_mboxcmd(isp, &mbs);
2278 switch (mbs.param[0]) {
2279 case MBOX_PORT_ID_USED:
2280 isp_prt(isp, ISP_LOGDEBUG0,
2281 "isp_port_login: portid 0x%06x already logged in as %u",
2282 portid, mbs.param[1]);
2283 return (MBOX_PORT_ID_USED | (mbs.param[1] << 16));
2285 case MBOX_LOOP_ID_USED:
2286 isp_prt(isp, ISP_LOGDEBUG0,
2287 "isp_port_login: handle 0x%04x in use for port id 0x%02xXXXX",
2288 handle, mbs.param[1] & 0xff);
2289 return (MBOX_LOOP_ID_USED);
2291 case MBOX_COMMAND_COMPLETE:
2294 case MBOX_COMMAND_ERROR:
2295 isp_prt(isp, ISP_LOGINFO,
2296 "isp_port_login: error 0x%x in PLOGI to port 0x%06x",
2297 mbs.param[1], portid);
2298 return (MBOX_COMMAND_ERROR);
2300 case MBOX_ALL_IDS_USED:
2301 isp_prt(isp, ISP_LOGINFO,
2302 "isp_port_login: all IDs used for fabric login");
2303 return (MBOX_ALL_IDS_USED);
2306 isp_prt(isp, ISP_LOGINFO,
2307 "isp_port_login: error 0x%x on port login of 0x%06x@0x%0x",
2308 mbs.param[0], portid, handle);
2309 return (mbs.param[0]);
2314 isp_port_logout(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2318 MBSINIT(&mbs, MBOX_FABRIC_LOGOUT, MBLOGNONE, 500000);
2319 if (ISP_CAP_2KLOGIN(isp)) {
2320 mbs.param[1] = handle;
2321 mbs.ibits = (1 << 10);
2323 mbs.param[1] = handle << 8;
2325 isp_mboxcmd(isp, &mbs);
2326 return (mbs.param[0] == MBOX_COMMAND_COMPLETE? 0 : mbs.param[0]);
2330 isp_getpdb(ispsoftc_t *isp, int chan, uint16_t id, isp_pdb_t *pdb, int dolock)
2332 fcparam *fcp = FCPARAM(isp, chan);
2335 isp_pdb_21xx_t fred;
2336 isp_pdb_24xx_t bill;
2339 MBSINIT(&mbs, MBOX_GET_PORT_DB, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR, 250000);
2341 mbs.ibits = (1 << 9)|(1 << 10);
2343 mbs.param[9] = chan;
2344 } else if (ISP_CAP_2KLOGIN(isp)) {
2347 mbs.param[1] = id << 8;
2349 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2350 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2351 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2352 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2354 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
2355 isp_prt(isp, ISP_LOGERR, sacq);
2359 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (un));
2360 isp_mboxcmd(isp, &mbs);
2361 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2363 FC_SCRATCH_RELEASE(isp, chan);
2365 return (mbs.param[0]);
2368 isp_get_pdb_24xx(isp, fcp->isp_scratch, &un.bill);
2369 pdb->handle = un.bill.pdb_handle;
2370 pdb->s3_role = un.bill.pdb_prli_svc3;
2371 pdb->portid = BITS2WORD_24XX(un.bill.pdb_portid_bits);
2372 ISP_MEMCPY(pdb->portname, un.bill.pdb_portname, 8);
2373 ISP_MEMCPY(pdb->nodename, un.bill.pdb_nodename, 8);
2374 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2375 "Chan %d Port 0x%06x flags 0x%x curstate %x",
2376 chan, pdb->portid, un.bill.pdb_flags,
2377 un.bill.pdb_curstate);
2378 if (un.bill.pdb_curstate < PDB2400_STATE_PLOGI_DONE ||
2379 un.bill.pdb_curstate > PDB2400_STATE_LOGGED_IN) {
2380 mbs.param[0] = MBOX_NOT_LOGGED_IN;
2382 FC_SCRATCH_RELEASE(isp, chan);
2384 return (mbs.param[0]);
2387 isp_get_pdb_21xx(isp, fcp->isp_scratch, &un.fred);
2388 pdb->handle = un.fred.pdb_loopid;
2389 pdb->s3_role = un.fred.pdb_prli_svc3;
2390 pdb->portid = BITS2WORD(un.fred.pdb_portid_bits);
2391 ISP_MEMCPY(pdb->portname, un.fred.pdb_portname, 8);
2392 ISP_MEMCPY(pdb->nodename, un.fred.pdb_nodename, 8);
2395 FC_SCRATCH_RELEASE(isp, chan);
2401 isp_dump_chip_portdb(ispsoftc_t *isp, int chan, int dolock)
2406 if (ISP_CAP_2KLOGIN(isp)) {
2411 for (loopid = 0; loopid != lim; loopid++) {
2412 if (isp_getpdb(isp, chan, loopid, &pdb, dolock)) {
2415 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGINFO, "Chan %d Loopid 0x%04x "
2416 "PortID 0x%06x WWPN 0x%02x%02x%02x%02x%02x%02x%02x%02x",
2417 chan, loopid, pdb.portid, pdb.portname[0], pdb.portname[1],
2418 pdb.portname[2], pdb.portname[3], pdb.portname[4],
2419 pdb.portname[5], pdb.portname[6], pdb.portname[7]);
2424 isp_get_wwn(ispsoftc_t *isp, int chan, int loopid, int nodename)
2426 uint64_t wwn = INI_NONE;
2427 fcparam *fcp = FCPARAM(isp, chan);
2430 if (fcp->isp_fwstate < FW_READY ||
2431 fcp->isp_loopstate < LOOP_PDB_RCVD) {
2434 MBSINIT(&mbs, MBOX_GET_PORT_NAME, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR, 500000);
2435 if (ISP_CAP_2KLOGIN(isp)) {
2436 mbs.param[1] = loopid;
2437 mbs.ibits = (1 << 10);
2441 if (ISP_CAP_MULTI_ID(isp)) {
2442 mbs.ibits |= (1 << 9);
2443 mbs.param[9] = chan;
2446 mbs.param[1] = loopid << 8;
2451 isp_mboxcmd(isp, &mbs);
2452 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2457 (((uint64_t)(mbs.param[2] >> 8)) << 56) |
2458 (((uint64_t)(mbs.param[2] & 0xff)) << 48) |
2459 (((uint64_t)(mbs.param[3] >> 8)) << 40) |
2460 (((uint64_t)(mbs.param[3] & 0xff)) << 32) |
2461 (((uint64_t)(mbs.param[6] >> 8)) << 24) |
2462 (((uint64_t)(mbs.param[6] & 0xff)) << 16) |
2463 (((uint64_t)(mbs.param[7] >> 8)) << 8) |
2464 (((uint64_t)(mbs.param[7] & 0xff)));
2467 (((uint64_t)(mbs.param[2] & 0xff)) << 56) |
2468 (((uint64_t)(mbs.param[2] >> 8)) << 48) |
2469 (((uint64_t)(mbs.param[3] & 0xff)) << 40) |
2470 (((uint64_t)(mbs.param[3] >> 8)) << 32) |
2471 (((uint64_t)(mbs.param[6] & 0xff)) << 24) |
2472 (((uint64_t)(mbs.param[6] >> 8)) << 16) |
2473 (((uint64_t)(mbs.param[7] & 0xff)) << 8) |
2474 (((uint64_t)(mbs.param[7] >> 8)));
2480 * Make sure we have good FC link.
2484 isp_fclink_test(ispsoftc_t *isp, int chan, int usdelay)
2487 int count, check_for_fabric, r;
2494 fcp = FCPARAM(isp, chan);
2496 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "Chan %d FC Link Test Entry", chan);
2497 ISP_MARK_PORTDB(isp, chan, 1);
2500 * Wait up to N microseconds for F/W to go to a ready state.
2502 lwfs = FW_CONFIG_WAIT;
2504 while (count < usdelay) {
2507 NANOTIME_T hra, hrb;
2510 isp_fw_state(isp, chan);
2511 if (lwfs != fcp->isp_fwstate) {
2512 isp_prt(isp, ISP_LOGCONFIG|ISP_LOGSANCFG, "Chan %d Firmware State <%s->%s>", chan, isp_fc_fw_statename((int)lwfs), isp_fc_fw_statename((int)fcp->isp_fwstate));
2513 lwfs = fcp->isp_fwstate;
2515 if (fcp->isp_fwstate == FW_READY) {
2521 * Get the elapsed time in nanoseconds.
2522 * Always guaranteed to be non-zero.
2524 enano = NANOTIME_SUB(&hrb, &hra);
2526 isp_prt(isp, ISP_LOGDEBUG1, "usec%d: 0x%lx->0x%lx enano 0x%x%08x", count, (long) GET_NANOSEC(&hra), (long) GET_NANOSEC(&hrb), (uint32_t)(enano >> 32), (uint32_t)(enano));
2529 * If the elapsed time is less than 1 millisecond,
2530 * delay a period of time up to that millisecond of
2533 * This peculiar code is an attempt to try and avoid
2534 * invoking uint64_t math support functions for some
2535 * platforms where linkage is a problem.
2537 if (enano < (1000 * 1000)) {
2539 enano = (1000 * 1000) - enano;
2540 while (enano > (uint64_t) 4000000000U) {
2541 ISP_SLEEP(isp, 4000000);
2542 enano -= (uint64_t) 4000000000U;
2546 ISP_SLEEP(isp, wrk);
2548 while (enano > (uint64_t) 4000000000U) {
2550 enano -= (uint64_t) 4000000000U;
2553 count += (wrk / 1000);
2560 * If we haven't gone to 'ready' state, return.
2562 if (fcp->isp_fwstate != FW_READY) {
2563 isp_prt(isp, ISP_LOGSANCFG, "%s: chan %d not at FW_READY state", __func__, chan);
2568 * Get our Loop ID and Port ID.
2570 MBSINIT(&mbs, MBOX_GET_LOOP_ID, MBLOGALL, 0);
2571 if (ISP_CAP_MULTI_ID(isp)) {
2572 mbs.param[9] = chan;
2573 mbs.ibits = (1 << 9);
2574 mbs.obits = (1 << 7);
2576 isp_mboxcmd(isp, &mbs);
2577 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2581 if (ISP_CAP_2KLOGIN(isp)) {
2582 fcp->isp_loopid = mbs.param[1];
2584 fcp->isp_loopid = mbs.param[1] & 0xff;
2588 fcp->isp_topo = TOPO_NL_PORT;
2590 int topo = (int) mbs.param[6];
2591 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB) {
2592 topo = TOPO_PTP_STUB;
2594 fcp->isp_topo = topo;
2596 fcp->isp_portid = mbs.param[2] | (mbs.param[3] << 16);
2600 * Don't bother with fabric if we are using really old
2601 * 2100 firmware. It's just not worth it.
2603 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37)) {
2604 check_for_fabric = 1;
2606 check_for_fabric = 0;
2608 } else if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_F_PORT) {
2609 check_for_fabric = 1;
2611 check_for_fabric = 0;
2615 * Check to make sure we got a valid loopid
2616 * The 24XX seems to mess this up for multiple channels.
2618 if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_NL_PORT) {
2619 uint8_t alpa = fcp->isp_portid;
2622 /* "Cannot Happen" */
2623 isp_prt(isp, ISP_LOGWARN, "Zero AL_PA for Loop Topology?");
2626 for (i = 0; alpa_map[i]; i++) {
2627 if (alpa_map[i] == alpa) {
2631 if (alpa_map[i] && fcp->isp_loopid != i) {
2632 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "Chan %d deriving loopid %d from AL_PA map (AL_PA 0x%x) and ignoring returned value %d (AL_PA 0x%x)", chan, i, alpa_map[i], fcp->isp_loopid, alpa);
2633 fcp->isp_loopid = i;
2639 if (IS_24XX(isp)) { /* XXX SHOULDN'T THIS BE FOR 2K F/W? XXX */
2644 if (check_for_fabric) {
2645 r = isp_getpdb(isp, chan, loopid, &pdb, 1);
2646 if (r && (fcp->isp_topo == TOPO_F_PORT || fcp->isp_topo == TOPO_FL_PORT)) {
2647 isp_prt(isp, ISP_LOGWARN, "fabric topology but cannot get info about fabric controller (0x%x)", r);
2648 fcp->isp_topo = TOPO_PTP_STUB;
2655 fcp->isp_topo = TOPO_FL_PORT;
2657 if (pdb.portid == 0) {
2661 fcp->isp_topo = TOPO_NL_PORT;
2666 * Save the Fabric controller's port database entry.
2668 lp = &fcp->portdb[FL_ID];
2669 lp->state = FC_PORTDB_STATE_PENDING_VALID;
2670 MAKE_WWN_FROM_NODE_NAME(lp->node_wwn, pdb.nodename);
2671 MAKE_WWN_FROM_NODE_NAME(lp->port_wwn, pdb.portname);
2672 lp->roles = (pdb.s3_role & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2673 lp->portid = pdb.portid;
2674 lp->handle = pdb.handle;
2675 lp->new_portid = lp->portid;
2676 lp->new_roles = lp->roles;
2678 fcp->inorder = (mbs.param[7] & ISP24XX_INORDER) != 0;
2679 if (ISP_FW_NEWER_THAN(isp, 4, 0, 27)) {
2680 fcp->npiv_fabric = (mbs.param[7] & ISP24XX_NPIV_SAN) != 0;
2681 if (fcp->npiv_fabric) {
2682 isp_prt(isp, ISP_LOGCONFIG, "fabric supports NP-IV");
2686 fcp->isp_sns_hdl = NPH_SNS_HDLBASE + chan;
2687 r = isp_plogx(isp, chan, fcp->isp_sns_hdl, SNS_PORT_ID, PLOGX_FLG_CMD_PLOGI | PLOGX_FLG_COND_PLOGI | PLOGX_FLG_SKIP_PRLI, 0);
2689 isp_prt(isp, ISP_LOGWARN, "%s: Chan %d cannot log into SNS", __func__, chan);
2693 fcp->isp_sns_hdl = NPH_SNS_ID;
2695 r = isp_register_fc4_type_24xx(isp, chan);
2697 fcp->isp_sns_hdl = SNS_ID;
2698 r = isp_register_fc4_type(isp, chan);
2701 isp_prt(isp, ISP_LOGWARN|ISP_LOGSANCFG, "%s: register fc4 type failed", __func__);
2706 fcp->portdb[FL_ID].state = FC_PORTDB_STATE_NIL;
2709 fcp->isp_gbspeed = 1;
2710 if (IS_23XX(isp) || IS_24XX(isp)) {
2711 MBSINIT(&mbs, MBOX_GET_SET_DATA_RATE, MBLOGALL, 3000000);
2712 mbs.param[1] = MBGSD_GET_RATE;
2713 /* mbs.param[2] undefined if we're just getting rate */
2714 isp_mboxcmd(isp, &mbs);
2715 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
2716 if (mbs.param[1] == MBGSD_EIGHTGB) {
2717 isp_prt(isp, ISP_LOGINFO, "Chan %d 8Gb link speed", chan);
2718 fcp->isp_gbspeed = 8;
2719 } else if (mbs.param[1] == MBGSD_FOURGB) {
2720 isp_prt(isp, ISP_LOGINFO, "Chan %d 4Gb link speed", chan);
2721 fcp->isp_gbspeed = 4;
2722 } else if (mbs.param[1] == MBGSD_TWOGB) {
2723 isp_prt(isp, ISP_LOGINFO, "Chan %d 2Gb link speed", chan);
2724 fcp->isp_gbspeed = 2;
2725 } else if (mbs.param[1] == MBGSD_ONEGB) {
2726 isp_prt(isp, ISP_LOGINFO, "Chan %d 1Gb link speed", chan);
2727 fcp->isp_gbspeed = 1;
2733 * Announce ourselves, too.
2735 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGCONFIG, topology, chan, (uint32_t) (fcp->isp_wwpn >> 32), (uint32_t) fcp->isp_wwpn, fcp->isp_portid, fcp->isp_loopid, isp_fc_toponame(fcp));
2736 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "Chan %d FC Link Test Complete", chan);
2741 * Complete the synchronization of our Port Database.
2743 * At this point, we've scanned the local loop (if any) and the fabric
2744 * and performed fabric logins on all new devices.
2746 * Our task here is to go through our port database and remove any entities
2747 * that are still marked probational (issuing PLOGO for ones which we had
2748 * PLOGI'd into) or are dead.
2750 * Our task here is to also check policy to decide whether devices which
2751 * have *changed* in some way should still be kept active. For example,
2752 * if a device has just changed PortID, we can either elect to treat it
2753 * as an old device or as a newly arrived device (and notify the outer
2754 * layer appropriately).
2756 * We also do initiator map target id assignment here for new initiator
2757 * devices and refresh old ones ot make sure that they point to the corret
2761 isp_pdb_sync(ispsoftc_t *isp, int chan)
2763 fcparam *fcp = FCPARAM(isp, chan);
2767 if (fcp->isp_loopstate == LOOP_READY) {
2772 * Make sure we're okay for doing this right now.
2774 if (fcp->isp_loopstate != LOOP_PDB_RCVD &&
2775 fcp->isp_loopstate != LOOP_FSCAN_DONE &&
2776 fcp->isp_loopstate != LOOP_LSCAN_DONE) {
2777 isp_prt(isp, ISP_LOGWARN, "isp_pdb_sync: bad loopstate %d",
2778 fcp->isp_loopstate);
2782 if (fcp->isp_topo == TOPO_FL_PORT ||
2783 fcp->isp_topo == TOPO_NL_PORT ||
2784 fcp->isp_topo == TOPO_N_PORT) {
2785 if (fcp->isp_loopstate < LOOP_LSCAN_DONE) {
2786 if (isp_scan_loop(isp, chan) != 0) {
2787 isp_prt(isp, ISP_LOGWARN,
2788 "isp_pdb_sync: isp_scan_loop failed");
2794 if (fcp->isp_topo == TOPO_F_PORT || fcp->isp_topo == TOPO_FL_PORT) {
2795 if (fcp->isp_loopstate < LOOP_FSCAN_DONE) {
2796 if (isp_scan_fabric(isp, chan) != 0) {
2797 isp_prt(isp, ISP_LOGWARN,
2798 "isp_pdb_sync: isp_scan_fabric failed");
2804 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2805 "Chan %d Synchronizing PDBs", chan);
2807 fcp->isp_loopstate = LOOP_SYNCING_PDB;
2809 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
2810 lp = &fcp->portdb[dbidx];
2812 if (lp->state == FC_PORTDB_STATE_NIL || lp->target_mode) {
2816 if (lp->state == FC_PORTDB_STATE_VALID) {
2817 if (dbidx != FL_ID) {
2819 ISP_LOGERR, "portdb idx %d already valid",
2825 switch (lp->state) {
2826 case FC_PORTDB_STATE_PROBATIONAL:
2827 case FC_PORTDB_STATE_DEAD:
2829 * It's up to the outer layers to clear isp_dev_map.
2831 lp->state = FC_PORTDB_STATE_NIL;
2832 isp_async(isp, ISPASYNC_DEV_GONE, chan, lp);
2833 if (lp->autologin == 0) {
2834 (void) isp_plogx(isp, chan, lp->handle,
2836 PLOGX_FLG_CMD_LOGO |
2837 PLOGX_FLG_IMPLICIT |
2838 PLOGX_FLG_FREE_NPHDL, 0);
2845 * Note that we might come out of this with our state
2846 * set to FC_PORTDB_STATE_ZOMBIE.
2849 case FC_PORTDB_STATE_NEW:
2851 * It's up to the outer layers to assign a virtual
2852 * target id in isp_dev_map (if any).
2854 lp->portid = lp->new_portid;
2855 lp->roles = lp->new_roles;
2856 lp->state = FC_PORTDB_STATE_VALID;
2857 isp_async(isp, ISPASYNC_DEV_ARRIVED, chan, lp);
2861 lp->new_reserved = 0;
2863 case FC_PORTDB_STATE_CHANGED:
2867 lp->state = FC_PORTDB_STATE_VALID;
2868 isp_async(isp, ISPASYNC_DEV_CHANGED, chan, lp);
2872 lp->new_reserved = 0;
2874 case FC_PORTDB_STATE_PENDING_VALID:
2875 lp->portid = lp->new_portid;
2876 lp->roles = lp->new_roles;
2877 if (lp->dev_map_idx) {
2878 int t = lp->dev_map_idx - 1;
2879 fcp->isp_dev_map[t] = dbidx + 1;
2881 lp->state = FC_PORTDB_STATE_VALID;
2882 isp_async(isp, ISPASYNC_DEV_STAYED, chan, lp);
2883 if (dbidx != FL_ID) {
2888 lp->new_reserved = 0;
2890 case FC_PORTDB_STATE_ZOMBIE:
2893 isp_prt(isp, ISP_LOGWARN,
2894 "isp_scan_loop: state %d for idx %d",
2896 isp_dump_portdb(isp, chan);
2901 * If we get here, we've for sure seen not only a valid loop
2902 * but know what is or isn't on it, so mark this for usage
2905 fcp->loop_seen_once = 1;
2906 fcp->isp_loopstate = LOOP_READY;
2911 * Scan local loop for devices.
2914 isp_scan_loop(ispsoftc_t *isp, int chan)
2916 fcportdb_t *lp, tmp;
2917 fcparam *fcp = FCPARAM(isp, chan);
2920 uint16_t handle, lim = 0;
2922 if (fcp->isp_fwstate < FW_READY ||
2923 fcp->isp_loopstate < LOOP_PDB_RCVD) {
2927 if (fcp->isp_loopstate > LOOP_SCANNING_LOOP) {
2932 * Check our connection topology.
2934 * If we're a public or private loop, we scan 0..125 as handle values.
2935 * The firmware has (typically) peformed a PLOGI for us. We skip this
2936 * step if we're a ISP_24XX in NP-IV mode.
2938 * If we're a N-port connection, we treat this is a short loop (0..1).
2940 switch (fcp->isp_topo) {
2942 lim = LOCAL_LOOP_LIM;
2945 if (IS_24XX(isp) && isp->isp_nchan > 1) {
2946 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2947 "Chan %d Skipping Local Loop Scan", chan);
2948 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2951 lim = LOCAL_LOOP_LIM;
2957 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2958 "Chan %d no loop topology to scan", chan);
2959 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2963 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
2965 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2966 "Chan %d FC scan loop 0..%d", chan, lim-1);
2970 * Run through the list and get the port database info for each one.
2972 for (handle = 0; handle < lim; handle++) {
2975 * Don't scan "special" ids.
2977 if (handle >= FL_ID && handle <= SNS_ID) {
2980 if (ISP_CAP_2KLOGIN(isp)) {
2981 if (handle >= NPH_RESERVED && handle <= NPH_FL_ID) {
2986 * In older cards with older f/w GET_PORT_DATABASE has been
2987 * known to hang. This trick gets around that problem.
2989 if (IS_2100(isp) || IS_2200(isp)) {
2990 uint64_t node_wwn = isp_get_wwn(isp, chan, handle, 1);
2991 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2992 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2993 "Chan %d FC scan loop DONE (bad)", chan);
2996 if (node_wwn == INI_NONE) {
3002 * Get the port database entity for this index.
3004 r = isp_getpdb(isp, chan, handle, &pdb, 1);
3006 isp_prt(isp, ISP_LOGDEBUG1,
3007 "Chan %d FC scan loop handle %d returned %x",
3009 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
3010 ISP_MARK_PORTDB(isp, chan, 1);
3011 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3012 "Chan %d FC scan loop DONE (bad)", chan);
3018 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
3019 ISP_MARK_PORTDB(isp, chan, 1);
3020 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3021 "Chan %d FC scan loop DONE (bad)", chan);
3026 * On *very* old 2100 firmware we would end up sometimes
3027 * with the firmware returning the port database entry
3028 * for something else. We used to restart this, but
3031 if (IS_2100(isp) && pdb.handle != handle) {
3032 isp_prt(isp, ISP_LOGWARN,
3033 "Chan %d cannot synchronize port database", chan);
3034 ISP_MARK_PORTDB(isp, chan, 1);
3035 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3036 "Chan %d FC scan loop DONE (bad)", chan);
3041 * Save the pertinent info locally.
3043 MAKE_WWN_FROM_NODE_NAME(tmp.node_wwn, pdb.nodename);
3044 MAKE_WWN_FROM_NODE_NAME(tmp.port_wwn, pdb.portname);
3045 tmp.roles = (pdb.s3_role & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
3046 tmp.portid = pdb.portid;
3047 tmp.handle = pdb.handle;
3050 * Check to make sure it's still a valid entry. The 24XX seems
3051 * to return a portid but not a WWPN/WWNN or role for devices
3052 * which shift on a loop.
3054 if (tmp.node_wwn == 0 || tmp.port_wwn == 0 || tmp.portid == 0) {
3056 a = (tmp.node_wwn == 0);
3057 b = (tmp.port_wwn == 0);
3058 c = (tmp.portid == 0);
3059 if (a == 0 && b == 0) {
3061 isp_get_wwn(isp, chan, handle, 1);
3063 isp_get_wwn(isp, chan, handle, 0);
3064 if (tmp.node_wwn && tmp.port_wwn) {
3065 isp_prt(isp, ISP_LOGINFO, "DODGED!");
3069 isp_prt(isp, ISP_LOGWARN,
3070 "Chan %d bad pdb (%1d%1d%1d) @ handle 0x%x", chan,
3072 isp_dump_portdb(isp, chan);
3078 * Now search the entire port database
3079 * for the same Port and Node WWN.
3081 for (i = 0; i < MAX_FC_TARG; i++) {
3082 lp = &fcp->portdb[i];
3084 if (lp->state == FC_PORTDB_STATE_NIL ||
3088 if (lp->node_wwn != tmp.node_wwn) {
3091 if (lp->port_wwn != tmp.port_wwn) {
3096 * Okay- we've found a non-nil entry that matches.
3097 * Check to make sure it's probational or a zombie.
3099 if (lp->state != FC_PORTDB_STATE_PROBATIONAL &&
3100 lp->state != FC_PORTDB_STATE_ZOMBIE) {
3101 isp_prt(isp, ISP_LOGERR,
3102 "Chan %d [%d] not probational/zombie (0x%x)",
3103 chan, i, lp->state);
3104 isp_dump_portdb(isp, chan);
3105 ISP_MARK_PORTDB(isp, chan, 1);
3106 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3107 "Chan %d FC scan loop DONE (bad)", chan);
3112 * Mark the device as something the f/w logs into
3118 * Check to make see if really still the same
3119 * device. If it is, we mark it pending valid.
3121 if (lp->portid == tmp.portid &&
3122 lp->handle == tmp.handle &&
3123 lp->roles == tmp.roles) {
3124 lp->new_portid = tmp.portid;
3125 lp->new_roles = tmp.roles;
3126 lp->state = FC_PORTDB_STATE_PENDING_VALID;
3127 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3128 "Chan %d Loop Port 0x%06x@0x%04x Pending "
3129 "Valid", chan, tmp.portid, tmp.handle);
3134 * We can wipe out the old handle value
3135 * here because it's no longer valid.
3137 lp->handle = tmp.handle;
3140 * Claim that this has changed and let somebody else
3141 * decide what to do.
3143 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3144 "Chan %d Loop Port 0x%06x@0x%04x changed",
3145 chan, tmp.portid, tmp.handle);
3146 lp->state = FC_PORTDB_STATE_CHANGED;
3147 lp->new_portid = tmp.portid;
3148 lp->new_roles = tmp.roles;
3153 * Did we find and update an old entry?
3155 if (i < MAX_FC_TARG) {
3160 * Ah. A new device entry. Find an empty slot
3161 * for it and save info for later disposition.
3163 for (i = 0; i < MAX_FC_TARG; i++) {
3164 if (fcp->portdb[i].target_mode) {
3167 if (fcp->portdb[i].state == FC_PORTDB_STATE_NIL) {
3171 if (i == MAX_FC_TARG) {
3172 isp_prt(isp, ISP_LOGERR,
3173 "Chan %d out of portdb entries", chan);
3176 lp = &fcp->portdb[i];
3178 ISP_MEMZERO(lp, sizeof (fcportdb_t));
3180 lp->state = FC_PORTDB_STATE_NEW;
3181 lp->new_portid = tmp.portid;
3182 lp->new_roles = tmp.roles;
3183 lp->handle = tmp.handle;
3184 lp->port_wwn = tmp.port_wwn;
3185 lp->node_wwn = tmp.node_wwn;
3186 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3187 "Chan %d Loop Port 0x%06x@0x%04x is New Entry",
3188 chan, tmp.portid, tmp.handle);
3190 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3191 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3192 "Chan %d FC scan loop DONE", chan);
3197 * Scan the fabric for devices and add them to our port database.
3199 * Use the GID_FT command to get all Port IDs for FC4 SCSI devices it knows.
3201 * For 2100-23XX cards, we can use the SNS mailbox command to pass simple
3202 * name server commands to the switch management server via the QLogic f/w.
3204 * For the 24XX card, we have to use CT-Pass through run via the Execute IOCB
3207 * The net result is to leave the list of Port IDs setting untranslated in
3208 * offset IGPOFF of the FC scratch area, whereupon we'll canonicalize it to
3209 * host order at OGPOFF.
3213 * Take less than half of our scratch area to store Port IDs
3215 #define GIDLEN ((ISP_FC_SCRLEN >> 1) - 16 - SNS_GID_FT_REQ_SIZE)
3216 #define NGENT ((GIDLEN - 16) >> 2)
3218 #define IGPOFF (2 * QENTRY_LEN)
3219 #define OGPOFF (ISP_FC_SCRLEN >> 1)
3220 #define ZTXOFF (ISP_FC_SCRLEN - (1 * QENTRY_LEN))
3221 #define CTXOFF (ISP_FC_SCRLEN - (2 * QENTRY_LEN))
3222 #define XTXOFF (ISP_FC_SCRLEN - (3 * QENTRY_LEN))
3225 isp_gid_ft_sns(ispsoftc_t *isp, int chan)
3228 sns_gid_ft_req_t _x;
3229 uint8_t _y[SNS_GID_FT_REQ_SIZE];
3231 fcparam *fcp = FCPARAM(isp, chan);
3232 sns_gid_ft_req_t *rq = &un._x;
3235 isp_prt(isp, ISP_LOGDEBUG0,
3236 "Chan %d scanning fabric (GID_FT) via SNS", chan);
3238 ISP_MEMZERO(rq, SNS_GID_FT_REQ_SIZE);
3239 rq->snscb_rblen = GIDLEN >> 1;
3240 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + IGPOFF);
3241 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + IGPOFF);
3242 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + IGPOFF);
3243 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + IGPOFF);
3244 rq->snscb_sblen = 6;
3245 rq->snscb_cmd = SNS_GID_FT;
3246 rq->snscb_mword_div_2 = NGENT;
3247 rq->snscb_fc4_type = FC4_SCSI;
3249 isp_put_gid_ft_request(isp, rq, fcp->isp_scratch);
3250 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE);
3252 MBSINIT(&mbs, MBOX_SEND_SNS, MBLOGALL, 10000000);
3253 mbs.param[0] = MBOX_SEND_SNS;
3254 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
3255 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
3256 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
3257 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
3258 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
3259 isp_mboxcmd(isp, &mbs);
3260 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3261 if (mbs.param[0] == MBOX_INVALID_COMMAND) {
3271 isp_gid_ft_ct_passthru(ispsoftc_t *isp, int chan)
3274 fcparam *fcp = FCPARAM(isp, chan);
3278 uint8_t q[QENTRY_LEN];
3283 uint8_t *scp = fcp->isp_scratch;
3285 isp_prt(isp, ISP_LOGDEBUG0,
3286 "Chan %d scanning fabric (GID_FT) via CT", chan);
3288 if (!IS_24XX(isp)) {
3293 * Build a Passthrough IOCB in memory.
3296 ISP_MEMZERO(un.q, QENTRY_LEN);
3297 pt->ctp_header.rqs_entry_count = 1;
3298 pt->ctp_header.rqs_entry_type = RQSTYPE_CT_PASSTHRU;
3299 pt->ctp_handle = 0xffffffff;
3300 pt->ctp_nphdl = fcp->isp_sns_hdl;
3301 pt->ctp_cmd_cnt = 1;
3302 pt->ctp_vpidx = ISP_GET_VPIDX(isp, chan);
3304 pt->ctp_rsp_cnt = 1;
3305 pt->ctp_rsp_bcnt = GIDLEN;
3306 pt->ctp_cmd_bcnt = sizeof (*ct) + sizeof (uint32_t);
3307 pt->ctp_dataseg[0].ds_base = DMA_LO32(fcp->isp_scdma+XTXOFF);
3308 pt->ctp_dataseg[0].ds_basehi = DMA_HI32(fcp->isp_scdma+XTXOFF);
3309 pt->ctp_dataseg[0].ds_count = sizeof (*ct) + sizeof (uint32_t);
3310 pt->ctp_dataseg[1].ds_base = DMA_LO32(fcp->isp_scdma+IGPOFF);
3311 pt->ctp_dataseg[1].ds_basehi = DMA_HI32(fcp->isp_scdma+IGPOFF);
3312 pt->ctp_dataseg[1].ds_count = GIDLEN;
3313 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3314 isp_print_bytes(isp, "ct IOCB", QENTRY_LEN, pt);
3316 isp_put_ct_pt(isp, pt, (isp_ct_pt_t *) &scp[CTXOFF]);
3319 * Build the CT header and command in memory.
3321 * Note that the CT header has to end up as Big Endian format in memory.
3324 ISP_MEMZERO(ct, sizeof (*ct));
3325 ct->ct_revision = CT_REVISION;
3326 ct->ct_fcs_type = CT_FC_TYPE_FC;
3327 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3328 ct->ct_cmd_resp = SNS_GID_FT;
3329 ct->ct_bcnt_resid = (GIDLEN - 16) >> 2;
3331 isp_put_ct_hdr(isp, ct, (ct_hdr_t *) &scp[XTXOFF]);
3332 rp = (uint32_t *) &scp[XTXOFF+sizeof (*ct)];
3333 ISP_IOZPUT_32(isp, FC4_SCSI, rp);
3334 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3335 isp_print_bytes(isp, "CT HDR + payload after put",
3336 sizeof (*ct) + sizeof (uint32_t), &scp[XTXOFF]);
3338 ISP_MEMZERO(&scp[ZTXOFF], QENTRY_LEN);
3339 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 500000);
3340 mbs.param[1] = QENTRY_LEN;
3341 mbs.param[2] = DMA_WD1(fcp->isp_scdma + CTXOFF);
3342 mbs.param[3] = DMA_WD0(fcp->isp_scdma + CTXOFF);
3343 mbs.param[6] = DMA_WD3(fcp->isp_scdma + CTXOFF);
3344 mbs.param[7] = DMA_WD2(fcp->isp_scdma + CTXOFF);
3345 MEMORYBARRIER(isp, SYNC_SFORDEV, XTXOFF, 2 * QENTRY_LEN);
3346 isp_mboxcmd(isp, &mbs);
3347 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3350 MEMORYBARRIER(isp, SYNC_SFORCPU, ZTXOFF, QENTRY_LEN);
3352 isp_get_ct_pt(isp, (isp_ct_pt_t *) &scp[ZTXOFF], pt);
3353 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3354 isp_print_bytes(isp, "IOCB response", QENTRY_LEN, pt);
3357 if (pt->ctp_status && pt->ctp_status != RQCS_DATA_UNDERRUN) {
3358 isp_prt(isp, ISP_LOGWARN,
3359 "Chan %d ISP GID FT CT Passthrough returned 0x%x",
3360 chan, pt->ctp_status);
3363 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN + 16);
3364 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3365 isp_print_bytes(isp, "CT response", GIDLEN+16, &scp[IGPOFF]);
3371 isp_scan_fabric(ispsoftc_t *isp, int chan)
3373 fcparam *fcp = FCPARAM(isp, chan);
3375 uint16_t handle, oldhandle, loopid;
3377 int portidx, portlim, r;
3378 sns_gid_ft_rsp_t *rs0, *rs1;
3380 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3381 "Chan %d FC Scan Fabric", chan);
3382 if (fcp->isp_fwstate != FW_READY ||
3383 fcp->isp_loopstate < LOOP_LSCAN_DONE) {
3386 if (fcp->isp_loopstate > LOOP_SCANNING_FABRIC) {
3389 if (fcp->isp_topo != TOPO_FL_PORT && fcp->isp_topo != TOPO_F_PORT) {
3390 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3391 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3392 "Chan %d FC Scan Fabric Done (no fabric)", chan);
3396 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
3397 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3398 isp_prt(isp, ISP_LOGERR, sacq);
3399 ISP_MARK_PORTDB(isp, chan, 1);
3402 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC) {
3403 FC_SCRATCH_RELEASE(isp, chan);
3404 ISP_MARK_PORTDB(isp, chan, 1);
3409 * Make sure we still are logged into the fabric controller.
3411 if (IS_24XX(isp)) { /* XXX SHOULDN'T THIS BE TRUE FOR 2K F/W? XXX */
3416 r = isp_getpdb(isp, chan, loopid, &pdb, 0);
3417 if (r == MBOX_NOT_LOGGED_IN) {
3418 isp_dump_chip_portdb(isp, chan, 0);
3421 fcp->isp_loopstate = LOOP_PDB_RCVD;
3422 FC_SCRATCH_RELEASE(isp, chan);
3423 ISP_MARK_PORTDB(isp, chan, 1);
3428 r = isp_gid_ft_ct_passthru(isp, chan);
3430 r = isp_gid_ft_sns(isp, chan);
3433 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC) {
3434 FC_SCRATCH_RELEASE(isp, chan);
3435 ISP_MARK_PORTDB(isp, chan, 1);
3440 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3441 FC_SCRATCH_RELEASE(isp, chan);
3444 fcp->isp_loopstate = LOOP_PDB_RCVD; /* try again */
3445 FC_SCRATCH_RELEASE(isp, chan);
3449 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN);
3450 rs0 = (sns_gid_ft_rsp_t *) ((uint8_t *)fcp->isp_scratch+IGPOFF);
3451 rs1 = (sns_gid_ft_rsp_t *) ((uint8_t *)fcp->isp_scratch+OGPOFF);
3452 isp_get_gid_ft_response(isp, rs0, rs1, NGENT);
3453 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC) {
3454 FC_SCRATCH_RELEASE(isp, chan);
3455 ISP_MARK_PORTDB(isp, chan, 1);
3458 if (rs1->snscb_cthdr.ct_cmd_resp != LS_ACC) {
3460 if (rs1->snscb_cthdr.ct_reason == 9 &&
3461 rs1->snscb_cthdr.ct_explanation == 7) {
3462 level = ISP_LOGSANCFG|ISP_LOGDEBUG0;
3464 level = ISP_LOGWARN;
3466 isp_prt(isp, level, "Chan %d Fabric Nameserver rejected GID_FT"
3467 " (Reason=0x%x Expl=0x%x)", chan,
3468 rs1->snscb_cthdr.ct_reason,
3469 rs1->snscb_cthdr.ct_explanation);
3470 FC_SCRATCH_RELEASE(isp, chan);
3471 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3477 * If we get this far, we certainly still have the fabric controller.
3479 fcp->portdb[FL_ID].state = FC_PORTDB_STATE_PENDING_VALID;
3482 * Prime the handle we will start using.
3484 oldhandle = FCPARAM(isp, 0)->isp_lasthdl;
3487 * Go through the list and remove duplicate port ids.
3492 for (portidx = 0; portidx < NGENT-1; portidx++) {
3493 if (rs1->snscb_ports[portidx].control & 0x80) {
3499 * If we're not at the last entry, our list wasn't big enough.
3501 if ((rs1->snscb_ports[portidx].control & 0x80) == 0) {
3502 isp_prt(isp, ISP_LOGWARN,
3503 "fabric too big for scratch area: increase ISP_FC_SCRLEN");
3505 portlim = portidx + 1;
3506 isp_prt(isp, ISP_LOGSANCFG,
3507 "Chan %d got %d ports back from name server", chan, portlim);
3509 for (portidx = 0; portidx < portlim; portidx++) {
3513 ((rs1->snscb_ports[portidx].portid[0]) << 16) |
3514 ((rs1->snscb_ports[portidx].portid[1]) << 8) |
3515 ((rs1->snscb_ports[portidx].portid[2]));
3517 for (npidx = portidx + 1; npidx < portlim; npidx++) {
3518 uint32_t new_portid =
3519 ((rs1->snscb_ports[npidx].portid[0]) << 16) |
3520 ((rs1->snscb_ports[npidx].portid[1]) << 8) |
3521 ((rs1->snscb_ports[npidx].portid[2]));
3522 if (new_portid == portid) {
3527 if (npidx < portlim) {
3528 rs1->snscb_ports[npidx].portid[0] = 0;
3529 rs1->snscb_ports[npidx].portid[1] = 0;
3530 rs1->snscb_ports[npidx].portid[2] = 0;
3531 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3532 "Chan %d removing duplicate PortID 0x%06x"
3533 " entry from list", chan, portid);
3538 * We now have a list of Port IDs for all FC4 SCSI devices
3539 * that the Fabric Name server knows about.
3541 * For each entry on this list go through our port database looking
3542 * for probational entries- if we find one, then an old entry is
3543 * maybe still this one. We get some information to find out.
3545 * Otherwise, it's a new fabric device, and we log into it
3546 * (unconditionally). After searching the entire database
3547 * again to make sure that we never ever ever ever have more
3548 * than one entry that has the same PortID or the same
3549 * WWNN/WWPN duple, we enter the device into our database.
3552 for (portidx = 0; portidx < portlim; portidx++) {
3554 uint64_t wwnn, wwpn;
3558 ((rs1->snscb_ports[portidx].portid[0]) << 16) |
3559 ((rs1->snscb_ports[portidx].portid[1]) << 8) |
3560 ((rs1->snscb_ports[portidx].portid[2]));
3563 isp_prt(isp, ISP_LOGSANCFG,
3564 "Chan %d skipping null PortID at idx %d",
3570 * Skip ourselves here and on other channels. If we're
3571 * multi-id, we can't check the portids in other FCPARAM
3572 * arenas because the resolutions here aren't synchronized.
3573 * The best way to do this is to exclude looking at portids
3574 * that have the same domain and area code as our own
3577 if (ISP_CAP_MULTI_ID(isp)) {
3578 if ((portid >> 8) == (fcp->isp_portid >> 8)) {
3579 isp_prt(isp, ISP_LOGSANCFG,
3580 "Chan %d skip PortID 0x%06x",
3584 } else if (portid == fcp->isp_portid) {
3585 isp_prt(isp, ISP_LOGSANCFG,
3586 "Chan %d skip ourselves on @ PortID 0x%06x",
3591 isp_prt(isp, ISP_LOGSANCFG,
3592 "Chan %d Checking Fabric Port 0x%06x", chan, portid);
3595 * We now search our Port Database for any
3596 * probational entries with this PortID. We don't
3597 * look for zombies here- only probational
3598 * entries (we've already logged out of zombies).
3600 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
3601 lp = &fcp->portdb[dbidx];
3603 if (lp->state != FC_PORTDB_STATE_PROBATIONAL ||
3607 if (lp->portid == portid) {
3613 * We found a probational entry with this Port ID.
3615 if (dbidx < MAX_FC_TARG) {
3616 int handle_changed = 0;
3618 lp = &fcp->portdb[dbidx];
3621 * See if we're still logged into it.
3623 * If we aren't, mark it as a dead device and
3624 * leave the new portid in the database entry
3625 * for somebody further along to decide what to
3626 * do (policy choice).
3628 * If we are, check to see if it's the same
3629 * device still (it should be). If for some
3630 * reason it isn't, mark it as a changed device
3631 * and leave the new portid and role in the
3632 * database entry for somebody further along to
3633 * decide what to do (policy choice).
3637 r = isp_getpdb(isp, chan, lp->handle, &pdb, 0);
3638 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
3639 FC_SCRATCH_RELEASE(isp, chan);
3640 ISP_MARK_PORTDB(isp, chan, 1);
3644 lp->new_portid = portid;
3645 lp->state = FC_PORTDB_STATE_DEAD;
3646 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3647 "Chan %d Fabric Port 0x%06x is dead",
3654 * Check to make sure that handle, portid, WWPN and
3655 * WWNN agree. If they don't, then the association
3656 * between this PortID and the stated handle has been
3657 * broken by the firmware.
3659 MAKE_WWN_FROM_NODE_NAME(wwnn, pdb.nodename);
3660 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb.portname);
3661 if (pdb.handle != lp->handle ||
3662 pdb.portid != portid ||
3663 wwpn != lp->port_wwn ||
3664 wwnn != lp->node_wwn) {
3665 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3666 fconf, chan, dbidx, pdb.handle, pdb.portid,
3667 (uint32_t) (wwnn >> 32), (uint32_t) wwnn,
3668 (uint32_t) (wwpn >> 32), (uint32_t) wwpn,
3670 (uint32_t) (lp->node_wwn >> 32),
3671 (uint32_t) lp->node_wwn,
3672 (uint32_t) (lp->port_wwn >> 32),
3673 (uint32_t) lp->port_wwn);
3675 * Try to re-login to this device using a
3676 * new handle. If that fails, mark it dead.
3678 * isp_login_device will check for handle and
3679 * portid consistency after re-login.
3682 if (isp_login_device(isp, chan, portid, &pdb,
3684 lp->new_portid = portid;
3685 lp->state = FC_PORTDB_STATE_DEAD;
3686 if (fcp->isp_loopstate !=
3687 LOOP_SCANNING_FABRIC) {
3688 FC_SCRATCH_RELEASE(isp, chan);
3689 ISP_MARK_PORTDB(isp, chan, 1);
3694 if (fcp->isp_loopstate !=
3695 LOOP_SCANNING_FABRIC) {
3696 FC_SCRATCH_RELEASE(isp, chan);
3697 ISP_MARK_PORTDB(isp, chan, 1);
3700 FCPARAM(isp, 0)->isp_lasthdl = oldhandle;
3701 MAKE_WWN_FROM_NODE_NAME(wwnn, pdb.nodename);
3702 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb.portname);
3703 if (wwpn != lp->port_wwn ||
3704 wwnn != lp->node_wwn) {
3705 isp_prt(isp, ISP_LOGWARN, "changed WWN"
3707 lp->new_portid = portid;
3708 lp->state = FC_PORTDB_STATE_DEAD;
3712 lp->handle = pdb.handle;
3716 nr = (pdb.s3_role & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
3719 * Check to see whether the portid and roles have
3720 * stayed the same. If they have stayed the same,
3721 * we believe that this is the same device and it
3722 * hasn't become disconnected and reconnected, so
3723 * mark it as pending valid.
3725 * If they aren't the same, mark the device as a
3726 * changed device and save the new port id and role
3727 * and let somebody else decide.
3730 lp->new_portid = portid;
3732 if (pdb.portid != lp->portid || nr != lp->roles ||
3734 isp_prt(isp, ISP_LOGSANCFG,
3735 "Chan %d Fabric Port 0x%06x changed",
3737 lp->state = FC_PORTDB_STATE_CHANGED;
3739 isp_prt(isp, ISP_LOGSANCFG,
3740 "Chan %d Fabric Port 0x%06x "
3741 "Now Pending Valid", chan, portid);
3742 lp->state = FC_PORTDB_STATE_PENDING_VALID;
3748 * Ah- a new entry. Search the database again for all non-NIL
3749 * entries to make sure we never ever make a new database entry
3750 * with the same port id. While we're at it, mark where the
3751 * last free entry was.
3754 dbidx = MAX_FC_TARG;
3755 for (lp = fcp->portdb; lp < &fcp->portdb[MAX_FC_TARG]; lp++) {
3756 if (lp >= &fcp->portdb[FL_ID] &&
3757 lp <= &fcp->portdb[SNS_ID]) {
3761 * Skip any target mode entries.
3763 if (lp->target_mode) {
3766 if (lp->state == FC_PORTDB_STATE_NIL) {
3767 if (dbidx == MAX_FC_TARG) {
3768 dbidx = lp - fcp->portdb;
3772 if (lp->state == FC_PORTDB_STATE_ZOMBIE) {
3775 if (lp->portid == portid) {
3780 if (lp < &fcp->portdb[MAX_FC_TARG]) {
3781 isp_prt(isp, ISP_LOGWARN, "Chan %d PortID 0x%06x "
3782 "already at %d handle %d state %d",
3783 chan, portid, dbidx, lp->handle, lp->state);
3788 * We should have the index of the first free entry seen.
3790 if (dbidx == MAX_FC_TARG) {
3791 isp_prt(isp, ISP_LOGERR,
3792 "port database too small to login PortID 0x%06x"
3793 "- increase MAX_FC_TARG", portid);
3798 * Otherwise, point to our new home.
3800 lp = &fcp->portdb[dbidx];
3803 * Try to see if we are logged into this device,
3804 * and maybe log into it.
3806 * isp_login_device will check for handle and
3807 * portid consistency after login.
3809 if (isp_login_device(isp, chan, portid, &pdb, &oldhandle)) {
3810 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
3811 FC_SCRATCH_RELEASE(isp, chan);
3812 ISP_MARK_PORTDB(isp, chan, 1);
3817 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
3818 FC_SCRATCH_RELEASE(isp, chan);
3819 ISP_MARK_PORTDB(isp, chan, 1);
3822 FCPARAM(isp, 0)->isp_lasthdl = oldhandle;
3824 handle = pdb.handle;
3825 MAKE_WWN_FROM_NODE_NAME(wwnn, pdb.nodename);
3826 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb.portname);
3827 nr = (pdb.s3_role & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
3830 * And go through the database *one* more time to make sure
3831 * that we do not make more than one entry that has the same
3834 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
3835 if (dbidx >= FL_ID && dbidx <= SNS_ID) {
3838 if (fcp->portdb[dbidx].target_mode) {
3841 if (fcp->portdb[dbidx].node_wwn == wwnn &&
3842 fcp->portdb[dbidx].port_wwn == wwpn) {
3847 if (dbidx == MAX_FC_TARG) {
3848 ISP_MEMZERO(lp, sizeof (fcportdb_t));
3849 lp->handle = handle;
3850 lp->node_wwn = wwnn;
3851 lp->port_wwn = wwpn;
3852 lp->new_portid = portid;
3854 lp->state = FC_PORTDB_STATE_NEW;
3855 isp_prt(isp, ISP_LOGSANCFG,
3856 "Chan %d Fabric Port 0x%06x is a New Entry",
3861 if (fcp->portdb[dbidx].state != FC_PORTDB_STATE_ZOMBIE) {
3862 isp_prt(isp, ISP_LOGWARN,
3863 "Chan %d PortID 0x%x 0x%08x%08x/0x%08x%08x %ld "
3864 "already at idx %d, state 0x%x", chan, portid,
3865 (uint32_t) (wwnn >> 32), (uint32_t) wwnn,
3866 (uint32_t) (wwpn >> 32), (uint32_t) wwpn,
3867 (long) (lp - fcp->portdb), dbidx,
3868 fcp->portdb[dbidx].state);
3873 * We found a zombie entry that matches us.
3874 * Revive it. We know that WWN and WWPN
3875 * are the same. For fabric devices, we
3876 * don't care that handle is different
3877 * as we assign that. If role or portid
3878 * are different, it maybe a changed device.
3880 lp = &fcp->portdb[dbidx];
3881 lp->handle = handle;
3882 lp->new_portid = portid;
3884 if (lp->portid != portid || lp->roles != nr) {
3885 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3886 "Chan %d Zombie Fabric Port 0x%06x Now Changed",
3888 lp->state = FC_PORTDB_STATE_CHANGED;
3890 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3891 "Chan %d Zombie Fabric Port 0x%06x "
3892 "Now Pending Valid", chan, portid);
3893 lp->state = FC_PORTDB_STATE_PENDING_VALID;
3897 FC_SCRATCH_RELEASE(isp, chan);
3898 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
3899 ISP_MARK_PORTDB(isp, chan, 1);
3902 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3903 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3904 "Chan %d FC Scan Fabric Done", chan);
3909 * Find an unused handle and try and use to login to a port.
3912 isp_login_device(ispsoftc_t *isp, int chan, uint32_t portid, isp_pdb_t *p,
3918 if (ISP_CAP_2KLOGIN(isp)) {
3924 handle = isp_nxt_handle(isp, chan, *ohp);
3925 for (i = 0; i < lim; i++) {
3927 * See if we're still logged into something with
3928 * this handle and that something agrees with this
3931 r = isp_getpdb(isp, chan, handle, p, 0);
3932 if (r == 0 && p->portid != portid) {
3933 (void) isp_plogx(isp, chan, handle, portid,
3934 PLOGX_FLG_CMD_LOGO | PLOGX_FLG_IMPLICIT, 1);
3935 } else if (r == 0) {
3938 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC) {
3942 * Now try and log into the device
3944 r = isp_plogx(isp, chan, handle, portid,
3945 PLOGX_FLG_CMD_PLOGI, 1);
3946 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC) {
3952 } else if ((r & 0xffff) == MBOX_PORT_ID_USED) {
3955 } else if (r != MBOX_LOOP_ID_USED) {
3958 } else if (r == MBOX_TIMEOUT) {
3962 handle = isp_nxt_handle(isp, chan, *ohp);
3967 isp_prt(isp, ISP_LOGWARN, "Chan %d PLOGI 0x%06x failed",
3973 * If we successfully logged into it, get the PDB for it
3974 * so we can crosscheck that it is still what we think it
3975 * is and that we also have the role it plays
3977 r = isp_getpdb(isp, chan, handle, p, 0);
3978 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC) {
3982 isp_prt(isp, ISP_LOGERR,
3983 "Chan %d new device 0x%06x@0x%x disappeared",
3984 chan, portid, handle);
3988 if (p->handle != handle || p->portid != portid) {
3989 isp_prt(isp, ISP_LOGERR,
3990 "Chan %d new device 0x%06x@0x%x changed (0x%06x@0x%0x)",
3991 chan, portid, handle, p->portid, p->handle);
3998 isp_register_fc4_type(ispsoftc_t *isp, int chan)
4000 fcparam *fcp = FCPARAM(isp, chan);
4001 uint8_t local[SNS_RFT_ID_REQ_SIZE];
4002 sns_screq_t *reqp = (sns_screq_t *) local;
4005 ISP_MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
4006 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
4007 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
4008 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
4009 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
4010 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
4011 reqp->snscb_sblen = 22;
4012 reqp->snscb_data[0] = SNS_RFT_ID;
4013 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
4014 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
4015 reqp->snscb_data[6] = (1 << FC4_SCSI);
4016 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4017 isp_prt(isp, ISP_LOGERR, sacq);
4020 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
4021 MBSINIT(&mbs, MBOX_SEND_SNS, MBLOGALL, 1000000);
4022 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
4023 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
4024 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
4025 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
4026 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
4027 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_RFT_ID_REQ_SIZE);
4028 isp_mboxcmd(isp, &mbs);
4029 FC_SCRATCH_RELEASE(isp, chan);
4030 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
4038 isp_register_fc4_type_24xx(ispsoftc_t *isp, int chan)
4041 fcparam *fcp = FCPARAM(isp, chan);
4045 uint8_t q[QENTRY_LEN];
4050 uint8_t *scp = fcp->isp_scratch;
4052 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4053 isp_prt(isp, ISP_LOGERR, sacq);
4058 * Build a Passthrough IOCB in memory.
4060 ISP_MEMZERO(un.q, QENTRY_LEN);
4062 pt->ctp_header.rqs_entry_count = 1;
4063 pt->ctp_header.rqs_entry_type = RQSTYPE_CT_PASSTHRU;
4064 pt->ctp_handle = 0xffffffff;
4065 pt->ctp_nphdl = fcp->isp_sns_hdl;
4066 pt->ctp_cmd_cnt = 1;
4067 pt->ctp_vpidx = ISP_GET_VPIDX(isp, chan);
4069 pt->ctp_rsp_cnt = 1;
4070 pt->ctp_rsp_bcnt = sizeof (ct_hdr_t);
4071 pt->ctp_cmd_bcnt = sizeof (rft_id_t);
4072 pt->ctp_dataseg[0].ds_base = DMA_LO32(fcp->isp_scdma+XTXOFF);
4073 pt->ctp_dataseg[0].ds_basehi = DMA_HI32(fcp->isp_scdma+XTXOFF);
4074 pt->ctp_dataseg[0].ds_count = sizeof (rft_id_t);
4075 pt->ctp_dataseg[1].ds_base = DMA_LO32(fcp->isp_scdma+IGPOFF);
4076 pt->ctp_dataseg[1].ds_basehi = DMA_HI32(fcp->isp_scdma+IGPOFF);
4077 pt->ctp_dataseg[1].ds_count = sizeof (ct_hdr_t);
4078 isp_put_ct_pt(isp, pt, (isp_ct_pt_t *) &scp[CTXOFF]);
4079 if (isp->isp_dblev & ISP_LOGDEBUG1) {
4080 isp_print_bytes(isp, "IOCB CT Request", QENTRY_LEN, pt);
4084 * Build the CT header and command in memory.
4086 * Note that the CT header has to end up as Big Endian format in memory.
4088 ISP_MEMZERO(&un.clocal, sizeof (un.clocal));
4089 ct = &un.clocal.rftid_hdr;
4090 ct->ct_revision = CT_REVISION;
4091 ct->ct_fcs_type = CT_FC_TYPE_FC;
4092 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
4093 ct->ct_cmd_resp = SNS_RFT_ID;
4094 ct->ct_bcnt_resid = (sizeof (rft_id_t) - sizeof (ct_hdr_t)) >> 2;
4096 rp->rftid_portid[0] = fcp->isp_portid >> 16;
4097 rp->rftid_portid[1] = fcp->isp_portid >> 8;
4098 rp->rftid_portid[2] = fcp->isp_portid;
4099 rp->rftid_fc4types[FC4_SCSI >> 5] = 1 << (FC4_SCSI & 0x1f);
4100 isp_put_rft_id(isp, rp, (rft_id_t *) &scp[XTXOFF]);
4101 if (isp->isp_dblev & ISP_LOGDEBUG1) {
4102 isp_print_bytes(isp, "CT Header", QENTRY_LEN, &scp[XTXOFF]);
4105 ISP_MEMZERO(&scp[ZTXOFF], sizeof (ct_hdr_t));
4107 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 1000000);
4108 mbs.param[1] = QENTRY_LEN;
4109 mbs.param[2] = DMA_WD1(fcp->isp_scdma + CTXOFF);
4110 mbs.param[3] = DMA_WD0(fcp->isp_scdma + CTXOFF);
4111 mbs.param[6] = DMA_WD3(fcp->isp_scdma + CTXOFF);
4112 mbs.param[7] = DMA_WD2(fcp->isp_scdma + CTXOFF);
4113 MEMORYBARRIER(isp, SYNC_SFORDEV, XTXOFF, 2 * QENTRY_LEN);
4114 isp_mboxcmd(isp, &mbs);
4115 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4116 FC_SCRATCH_RELEASE(isp, chan);
4119 MEMORYBARRIER(isp, SYNC_SFORCPU, ZTXOFF, QENTRY_LEN);
4121 isp_get_ct_pt(isp, (isp_ct_pt_t *) &scp[ZTXOFF], pt);
4122 if (isp->isp_dblev & ISP_LOGDEBUG1) {
4123 isp_print_bytes(isp, "IOCB response", QENTRY_LEN, pt);
4125 if (pt->ctp_status) {
4126 FC_SCRATCH_RELEASE(isp, chan);
4127 isp_prt(isp, ISP_LOGWARN,
4128 "Chan %d Register FC4 Type CT Passthrough returned 0x%x",
4129 chan, pt->ctp_status);
4133 isp_get_ct_hdr(isp, (ct_hdr_t *) &scp[IGPOFF], ct);
4134 FC_SCRATCH_RELEASE(isp, chan);
4136 if (ct->ct_cmd_resp == LS_RJT) {
4137 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
4138 "Chan %d Register FC4 Type rejected", chan);
4140 } else if (ct->ct_cmd_resp == LS_ACC) {
4141 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
4142 "Chan %d Register FC4 Type accepted", chan);
4145 isp_prt(isp, ISP_LOGWARN,
4146 "Chan %d Register FC4 Type: 0x%x",
4147 chan, ct->ct_cmd_resp);
4153 isp_nxt_handle(ispsoftc_t *isp, int chan, uint16_t handle)
4156 if (handle == NIL_HANDLE) {
4157 if (FCPARAM(isp, chan)->isp_topo == TOPO_F_PORT) {
4164 if (handle >= FL_ID && handle <= SNS_ID) {
4167 if (handle >= NPH_RESERVED && handle <= NPH_FL_ID) {
4168 handle = NPH_FL_ID+1;
4170 if (ISP_CAP_2KLOGIN(isp)) {
4171 if (handle == NPH_MAX_2K) {
4175 if (handle == NPH_MAX) {
4180 if (handle == FCPARAM(isp, chan)->isp_loopid) {
4181 return (isp_nxt_handle(isp, chan, handle));
4183 for (i = 0; i < MAX_FC_TARG; i++) {
4184 if (FCPARAM(isp, chan)->portdb[i].state ==
4185 FC_PORTDB_STATE_NIL) {
4188 if (FCPARAM(isp, chan)->portdb[i].handle == handle) {
4189 return (isp_nxt_handle(isp, chan, handle));
4196 * Start a command. Locking is assumed done in the caller.
4204 uint8_t local[QENTRY_LEN];
4208 int target, dmaresult, hdlidx = 0;
4214 * Now make sure we're running.
4217 if (isp->isp_state != ISP_RUNSTATE) {
4218 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
4219 XS_SETERR(xs, HBA_BOTCH);
4220 return (CMD_COMPLETE);
4224 * Check command CDB length, etc.. We really are limited to 16 bytes
4225 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
4226 * but probably only if we're running fairly new firmware (we'll
4227 * let the old f/w choke on an extended command queue entry).
4230 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
4231 isp_prt(isp, ISP_LOGERR, "unsupported cdb length (%d, CDB[0]=0x%x)", XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
4232 XS_SETERR(xs, HBA_BOTCH);
4233 return (CMD_COMPLETE);
4237 * Translate the target to device handle as appropriate, checking
4238 * for correct device state as well.
4240 target = XS_TGT(xs);
4242 fcparam *fcp = FCPARAM(isp, XS_CHANNEL(xs));
4244 if ((fcp->role & ISP_ROLE_INITIATOR) == 0) {
4245 XS_SETERR(xs, HBA_SELTIMEOUT);
4246 return (CMD_COMPLETE);
4252 if (fcp->isp_fwstate != FW_READY || fcp->isp_loopstate != LOOP_READY) {
4253 return (CMD_RQLATER);
4256 if (XS_TGT(xs) >= MAX_FC_TARG) {
4257 XS_SETERR(xs, HBA_SELTIMEOUT);
4258 return (CMD_COMPLETE);
4261 hdlidx = fcp->isp_dev_map[XS_TGT(xs)] - 1;
4262 isp_prt(isp, ISP_LOGDEBUG2, "XS_TGT(xs)=%d- hdlidx value %d", XS_TGT(xs), hdlidx);
4263 if (hdlidx < 0 || hdlidx >= MAX_FC_TARG) {
4264 XS_SETERR(xs, HBA_SELTIMEOUT);
4265 return (CMD_COMPLETE);
4267 if (fcp->portdb[hdlidx].state == FC_PORTDB_STATE_ZOMBIE) {
4268 return (CMD_RQLATER);
4270 if (fcp->portdb[hdlidx].state != FC_PORTDB_STATE_VALID) {
4271 XS_SETERR(xs, HBA_SELTIMEOUT);
4272 return (CMD_COMPLETE);
4274 target = fcp->portdb[hdlidx].handle;
4275 fcp->portdb[hdlidx].dirty = 1;
4277 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
4278 if ((sdp->role & ISP_ROLE_INITIATOR) == 0) {
4279 XS_SETERR(xs, HBA_SELTIMEOUT);
4280 return (CMD_COMPLETE);
4283 isp_spi_update(isp, XS_CHANNEL(xs));
4289 qep = isp_getrqentry(isp);
4291 isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow");
4292 XS_SETERR(xs, HBA_BOTCH);
4293 return (CMD_EAGAIN);
4295 XS_SETERR(xs, HBA_NOERROR);
4298 * Now see if we need to synchronize the ISP with respect to anything.
4299 * We do dual duty here (cough) for synchronizing for busses other
4300 * than which we got here to send a command to.
4302 reqp = (ispreq_t *) local;
4303 ISP_MEMZERO(local, QENTRY_LEN);
4304 if (ISP_TST_SENDMARKER(isp, XS_CHANNEL(xs))) {
4306 isp_marker_24xx_t *m = (isp_marker_24xx_t *) reqp;
4307 m->mrk_header.rqs_entry_count = 1;
4308 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4309 m->mrk_modifier = SYNC_ALL;
4310 isp_put_marker_24xx(isp, m, qep);
4312 isp_marker_t *m = (isp_marker_t *) reqp;
4313 m->mrk_header.rqs_entry_count = 1;
4314 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4315 m->mrk_target = (XS_CHANNEL(xs) << 7); /* bus # */
4316 m->mrk_modifier = SYNC_ALL;
4317 isp_put_marker(isp, m, qep);
4319 ISP_SYNC_REQUEST(isp);
4320 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 0);
4324 reqp->req_header.rqs_entry_count = 1;
4326 reqp->req_header.rqs_entry_type = RQSTYPE_T7RQS;
4327 } else if (IS_FC(isp)) {
4328 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
4330 if (XS_CDBLEN(xs) > 12) {
4331 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
4333 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
4336 /* reqp->req_header.rqs_flags = 0; */
4337 /* reqp->req_header.rqs_seqno = 0; */
4341 ttype = XS_TAG_TYPE(xs);
4343 if (XS_CDBP(xs)[0] == 0x3) {
4344 ttype = REQFLAG_HTAG;
4346 ttype = REQFLAG_STAG;
4349 if (ttype == REQFLAG_OTAG) {
4350 ttype = FCP_CMND_TASK_ATTR_ORDERED;
4351 } else if (ttype == REQFLAG_HTAG) {
4352 ttype = FCP_CMND_TASK_ATTR_HEAD;
4354 ttype = FCP_CMND_TASK_ATTR_SIMPLE;
4356 ((ispreqt7_t *)reqp)->req_task_attribute = ttype;
4357 } else if (IS_FC(isp)) {
4359 * See comment in isp_intr
4361 /* XS_SET_RESID(xs, 0); */
4364 * Fibre Channel always requires some kind of tag.
4365 * The Qlogic drivers seem be happy not to use a tag,
4366 * but this breaks for some devices (IBM drives).
4369 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
4372 * If we don't know what tag to use, use HEAD OF QUEUE
4373 * for Request Sense or Simple.
4375 if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
4376 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_HTAG;
4378 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
4381 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
4382 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) && XS_TAG_P(xs)) {
4383 reqp->req_flags = XS_TAG_TYPE(xs);
4386 cdbp = reqp->req_cdb;
4387 tptr = &reqp->req_time;
4390 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
4391 reqp->req_lun_trn = XS_LUN(xs);
4392 reqp->req_cdblen = XS_CDBLEN(xs);
4393 } else if (IS_24XX(isp)) {
4396 lp = &FCPARAM(isp, XS_CHANNEL(xs))->portdb[hdlidx];
4397 ((ispreqt7_t *)reqp)->req_nphdl = target;
4398 ((ispreqt7_t *)reqp)->req_tidlo = lp->portid;
4399 ((ispreqt7_t *)reqp)->req_tidhi = lp->portid >> 16;
4400 ((ispreqt7_t *)reqp)->req_vpidx = ISP_GET_VPIDX(isp, XS_CHANNEL(xs));
4401 if (XS_LUN(xs) > 256) {
4402 ((ispreqt7_t *)reqp)->req_lun[0] = XS_LUN(xs) >> 8;
4403 ((ispreqt7_t *)reqp)->req_lun[0] |= 0x40;
4405 ((ispreqt7_t *)reqp)->req_lun[1] = XS_LUN(xs);
4406 cdbp = ((ispreqt7_t *)reqp)->req_cdb;
4407 tptr = &((ispreqt7_t *)reqp)->req_time;
4408 } else if (ISP_CAP_2KLOGIN(isp)) {
4409 ((ispreqt2e_t *)reqp)->req_target = target;
4410 ((ispreqt2e_t *)reqp)->req_scclun = XS_LUN(xs);
4411 } else if (ISP_CAP_SCCFW(isp)) {
4412 ((ispreqt2_t *)reqp)->req_target = target;
4413 ((ispreqt2_t *)reqp)->req_scclun = XS_LUN(xs);
4415 ((ispreqt2_t *)reqp)->req_target = target;
4416 ((ispreqt2_t *)reqp)->req_lun_trn = XS_LUN(xs);
4418 ISP_MEMCPY(cdbp, XS_CDBP(xs), XS_CDBLEN(xs));
4420 *tptr = XS_TIME(xs) / 1000;
4421 if (*tptr == 0 && XS_TIME(xs)) {
4424 if (IS_24XX(isp) && *tptr > 0x1999) {
4428 if (isp_save_xs(isp, xs, &handle)) {
4429 isp_prt(isp, ISP_LOGDEBUG0, "out of xflist pointers");
4430 XS_SETERR(xs, HBA_BOTCH);
4431 return (CMD_EAGAIN);
4433 /* Whew. Thankfully the same for type 7 requests */
4434 reqp->req_handle = handle;
4437 * Set up DMA and/or do any platform dependent swizzling of the request entry
4438 * so that the Qlogic F/W understands what is being asked of it.
4440 * The callee is responsible for adding all requests at this point.
4442 dmaresult = ISP_DMASETUP(isp, xs, reqp);
4443 if (dmaresult != CMD_QUEUED) {
4444 isp_destroy_handle(isp, handle);
4446 * dmasetup sets actual error in packet, and
4447 * return what we were given to return.
4451 isp_prt(isp, ISP_LOGDEBUG0, "START cmd for %d.%d.%d cmd 0x%x datalen %ld", XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), XS_CDBP(xs)[0], (long) XS_XFRLEN(xs));
4453 return (CMD_QUEUED);
4458 * Locks (ints blocked) assumed held.
4462 isp_control(ispsoftc_t *isp, ispctl_t ctl, ...)
4471 case ISPCTL_RESET_BUS:
4473 * Issue a bus reset.
4476 isp_prt(isp, ISP_LOGWARN, "RESET BUS NOT IMPLEMENTED");
4478 } else if (IS_FC(isp)) {
4483 chan = va_arg(ap, int);
4485 mbs.param[1] = SDPARAM(isp, chan)->isp_bus_reset_delay;
4486 if (mbs.param[1] < 2) {
4489 mbs.param[2] = chan;
4491 MBSINIT(&mbs, MBOX_BUS_RESET, MBLOGALL, 0);
4492 ISP_SET_SENDMARKER(isp, chan, 1);
4493 isp_mboxcmd(isp, &mbs);
4494 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4497 isp_prt(isp, ISP_LOGINFO,
4498 "driver initiated bus reset of bus %d", chan);
4501 case ISPCTL_RESET_DEV:
4503 chan = va_arg(ap, int);
4504 tgt = va_arg(ap, int);
4507 uint8_t local[QENTRY_LEN];
4509 isp24xx_statusreq_t *sp;
4510 fcparam *fcp = FCPARAM(isp, chan);
4514 hdlidx = fcp->isp_dev_map[tgt] - 1;
4515 if (hdlidx < 0 || hdlidx >= MAX_FC_TARG) {
4516 isp_prt(isp, ISP_LOGWARN,
4517 "Chan %d bad handle %d trying to reset"
4518 "target %d", chan, hdlidx, tgt);
4521 lp = &fcp->portdb[hdlidx];
4522 if (lp->state != FC_PORTDB_STATE_VALID) {
4523 isp_prt(isp, ISP_LOGWARN,
4524 "Chan %d handle %d for abort of target %d "
4525 "no longer valid", chan,
4530 tmf = (isp24xx_tmf_t *) local;
4531 ISP_MEMZERO(tmf, QENTRY_LEN);
4532 tmf->tmf_header.rqs_entry_type = RQSTYPE_TSK_MGMT;
4533 tmf->tmf_header.rqs_entry_count = 1;
4534 tmf->tmf_nphdl = lp->handle;
4536 tmf->tmf_timeout = 2;
4537 tmf->tmf_flags = ISP24XX_TMF_TARGET_RESET;
4538 tmf->tmf_tidlo = lp->portid;
4539 tmf->tmf_tidhi = lp->portid >> 16;
4540 tmf->tmf_vpidx = ISP_GET_VPIDX(isp, chan);
4541 isp_prt(isp, ISP_LOGALL, "Chan %d Reset N-Port Handle 0x%04x @ Port 0x%06x", chan, lp->handle, lp->portid);
4542 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 5000000);
4543 mbs.param[1] = QENTRY_LEN;
4544 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
4545 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
4546 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
4547 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
4549 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4550 isp_prt(isp, ISP_LOGERR, sacq);
4553 isp_put_24xx_tmf(isp, tmf, fcp->isp_scratch);
4554 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, QENTRY_LEN);
4555 fcp->sendmarker = 1;
4556 isp_mboxcmd(isp, &mbs);
4557 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4558 FC_SCRATCH_RELEASE(isp, chan);
4561 MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN,
4563 sp = (isp24xx_statusreq_t *) local;
4564 isp_get_24xx_response(isp,
4565 &((isp24xx_statusreq_t *)fcp->isp_scratch)[1], sp);
4566 FC_SCRATCH_RELEASE(isp, chan);
4567 if (sp->req_completion_status == 0) {
4570 isp_prt(isp, ISP_LOGWARN,
4571 "Chan %d reset of target %d returned 0x%x",
4572 chan, tgt, sp->req_completion_status);
4574 } else if (IS_FC(isp)) {
4575 if (ISP_CAP_2KLOGIN(isp)) {
4577 mbs.ibits = (1 << 10);
4579 mbs.param[1] = (tgt << 8);
4582 mbs.param[1] = (chan << 15) | (tgt << 8);
4584 MBSINIT(&mbs, MBOX_ABORT_TARGET, MBLOGALL, 0);
4585 mbs.param[2] = 3; /* 'delay', in seconds */
4586 isp_mboxcmd(isp, &mbs);
4587 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4590 isp_prt(isp, ISP_LOGINFO,
4591 "Target %d on Bus %d Reset Succeeded", tgt, chan);
4592 ISP_SET_SENDMARKER(isp, chan, 1);
4595 case ISPCTL_ABORT_CMD:
4597 xs = va_arg(ap, XS_T *);
4601 chan = XS_CHANNEL(xs);
4603 handle = isp_find_handle(isp, xs);
4605 isp_prt(isp, ISP_LOGWARN,
4606 "cannot find handle for command to abort");
4610 isp24xx_abrt_t local, *ab = &local, *ab2;
4615 fcp = FCPARAM(isp, chan);
4616 hdlidx = fcp->isp_dev_map[tgt] - 1;
4617 if (hdlidx < 0 || hdlidx >= MAX_FC_TARG) {
4618 isp_prt(isp, ISP_LOGWARN,
4619 "Chan %d bad handle %d trying to abort"
4620 "target %d", chan, hdlidx, tgt);
4623 lp = &fcp->portdb[hdlidx];
4624 if (lp->state != FC_PORTDB_STATE_VALID) {
4625 isp_prt(isp, ISP_LOGWARN,
4626 "Chan %d handle %d for abort of target %d "
4627 "no longer valid", chan, hdlidx, tgt);
4630 isp_prt(isp, ISP_LOGALL,
4631 "Chan %d Abort Cmd for N-Port 0x%04x @ Port "
4632 "0x%06x %p", chan, lp->handle, lp->portid, xs);
4633 ISP_MEMZERO(ab, QENTRY_LEN);
4634 ab->abrt_header.rqs_entry_type = RQSTYPE_ABORT_IO;
4635 ab->abrt_header.rqs_entry_count = 1;
4636 ab->abrt_handle = lp->handle;
4637 ab->abrt_cmd_handle = handle;
4638 ab->abrt_tidlo = lp->portid;
4639 ab->abrt_tidhi = lp->portid >> 16;
4640 ab->abrt_vpidx = ISP_GET_VPIDX(isp, chan);
4642 ISP_MEMZERO(&mbs, sizeof (mbs));
4643 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 5000000);
4644 mbs.param[1] = QENTRY_LEN;
4645 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
4646 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
4647 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
4648 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
4650 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4651 isp_prt(isp, ISP_LOGERR, sacq);
4654 isp_put_24xx_abrt(isp, ab, fcp->isp_scratch);
4655 ab2 = (isp24xx_abrt_t *)
4656 &((uint8_t *)fcp->isp_scratch)[QENTRY_LEN];
4657 ab2->abrt_nphdl = 0xdeaf;
4658 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, 2 * QENTRY_LEN);
4659 isp_mboxcmd(isp, &mbs);
4660 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4661 FC_SCRATCH_RELEASE(isp, chan);
4664 MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN,
4666 isp_get_24xx_abrt(isp, ab2, ab);
4667 FC_SCRATCH_RELEASE(isp, chan);
4668 if (ab->abrt_nphdl == ISP24XX_ABRT_OKAY) {
4671 isp_prt(isp, ISP_LOGWARN,
4672 "Chan %d handle %d abort returned 0x%x", chan,
4673 hdlidx, ab->abrt_nphdl);
4675 } else if (IS_FC(isp)) {
4676 if (ISP_CAP_SCCFW(isp)) {
4677 if (ISP_CAP_2KLOGIN(isp)) {
4680 mbs.param[1] = tgt << 8;
4682 mbs.param[6] = XS_LUN(xs);
4684 mbs.param[1] = tgt << 8 | XS_LUN(xs);
4687 mbs.param[1] = (chan << 15) | (tgt << 8) | XS_LUN(xs);
4689 MBSINIT(&mbs, MBOX_ABORT, MBLOGALL & ~MBOX_COMMAND_ERROR, 0);
4690 mbs.param[2] = handle;
4691 isp_mboxcmd(isp, &mbs);
4692 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4697 case ISPCTL_UPDATE_PARAMS:
4700 chan = va_arg(ap, int);
4702 isp_spi_update(isp, chan);
4705 case ISPCTL_FCLINK_TEST:
4710 chan = va_arg(ap, int);
4711 usdelay = va_arg(ap, int);
4716 return (isp_fclink_test(isp, chan, usdelay));
4720 case ISPCTL_SCAN_FABRIC:
4724 chan = va_arg(ap, int);
4726 return (isp_scan_fabric(isp, chan));
4730 case ISPCTL_SCAN_LOOP:
4734 chan = va_arg(ap, int);
4736 return (isp_scan_loop(isp, chan));
4740 case ISPCTL_PDB_SYNC:
4744 chan = va_arg(ap, int);
4746 return (isp_pdb_sync(isp, chan));
4750 case ISPCTL_SEND_LIP:
4752 if (IS_FC(isp) && !IS_24XX(isp)) {
4753 MBSINIT(&mbs, MBOX_INIT_LIP, MBLOGALL, 0);
4754 if (ISP_CAP_2KLOGIN(isp)) {
4755 mbs.ibits = (1 << 10);
4757 isp_mboxcmd(isp, &mbs);
4758 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
4764 case ISPCTL_GET_PDB:
4768 chan = va_arg(ap, int);
4769 tgt = va_arg(ap, int);
4770 pdb = va_arg(ap, isp_pdb_t *);
4772 return (isp_getpdb(isp, chan, tgt, pdb, 1));
4776 case ISPCTL_GET_NAMES:
4778 uint64_t *wwnn, *wwnp;
4780 chan = va_arg(ap, int);
4781 tgt = va_arg(ap, int);
4782 wwnn = va_arg(ap, uint64_t *);
4783 wwnp = va_arg(ap, uint64_t *);
4785 if (wwnn == NULL && wwnp == NULL) {
4789 *wwnn = isp_get_wwn(isp, chan, tgt, 1);
4790 if (*wwnn == INI_NONE) {
4795 *wwnp = isp_get_wwn(isp, chan, tgt, 0);
4796 if (*wwnp == INI_NONE) {
4802 case ISPCTL_RUN_MBOXCMD:
4805 mbr = va_arg(ap, mbreg_t *);
4807 isp_mboxcmd(isp, mbr);
4816 p = va_arg(ap, isp_plcmd_t *);
4819 if ((p->flags & PLOGX_FLG_CMD_MASK) != PLOGX_FLG_CMD_PLOGI || (p->handle != NIL_HANDLE)) {
4820 return (isp_plogx(isp, p->channel, p->handle, p->portid, p->flags, 0));
4823 p->handle = isp_nxt_handle(isp, p->channel, p->handle);
4824 r = isp_plogx(isp, p->channel, p->handle, p->portid, p->flags, 0);
4825 if ((r & 0xffff) == MBOX_PORT_ID_USED) {
4826 p->handle = r >> 16;
4830 } while ((r & 0xffff) == MBOX_LOOP_ID_USED);
4834 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
4842 * Interrupt Service Routine(s).
4844 * External (OS) framework has done the appropriate locking,
4845 * and the locking will be held throughout this function.
4849 * Limit our stack depth by sticking with the max likely number
4850 * of completions on a request queue at any one time.
4852 #ifndef MAX_REQUESTQ_COMPLETIONS
4853 #define MAX_REQUESTQ_COMPLETIONS 32
4857 isp_intr(ispsoftc_t *isp, uint32_t isr, uint16_t sema, uint16_t mbox)
4859 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
4860 uint32_t iptr, optr, junk;
4861 int i, nlooked = 0, ndone = 0;
4864 optr = isp->isp_residx;
4866 * Is this a mailbox related interrupt?
4867 * The mailbox semaphore will be nonzero if so.
4871 if (mbox & 0x4000) {
4872 isp->isp_intmboxc++;
4873 if (isp->isp_mboxbsy) {
4874 int obits = isp->isp_obits;
4875 isp->isp_mboxtmp[0] = mbox;
4876 for (i = 1; i < MAX_MAILBOX(isp); i++) {
4877 if ((obits & (1 << i)) == 0) {
4880 isp->isp_mboxtmp[i] = ISP_READ(isp, MBOX_OFF(i));
4882 if (isp->isp_mbxwrk0) {
4883 if (isp_mbox_continue(isp) == 0) {
4887 MBOX_NOTIFY_COMPLETE(isp);
4889 isp_prt(isp, ISP_LOGWARN, "mailbox cmd (0x%x) with no waiters", mbox);
4891 } else if (isp_parse_async(isp, mbox) < 0) {
4894 if ((IS_FC(isp) && mbox != ASYNC_RIO_RESP) || isp->isp_state != ISP_RUNSTATE) {
4900 * We can't be getting this now.
4902 if (isp->isp_state != ISP_RUNSTATE) {
4904 * This seems to happen to 23XX and 24XX cards- don't know why.
4906 if (isp->isp_mboxbsy && isp->isp_lastmbxcmd == MBOX_ABOUT_FIRMWARE) {
4909 isp_prt(isp, ISP_LOGINFO, "interrupt (ISR=%x SEMA=%x) when not ready", isr, sema);
4911 * Thank you very much! *Burrrp*!
4913 ISP_WRITE(isp, isp->isp_respoutrp, ISP_READ(isp, isp->isp_respinrp));
4915 ISP_DISABLE_INTS(isp);
4920 #ifdef ISP_TARGET_MODE
4922 * Check for ATIO Queue entries.
4925 iptr = ISP_READ(isp, BIU2400_ATIO_RSPINP);
4926 optr = ISP_READ(isp, BIU2400_ATIO_RSPOUTP);
4928 while (optr != iptr) {
4929 uint8_t qe[QENTRY_LEN];
4935 MEMORYBARRIER(isp, SYNC_ATIOQ, oop, QENTRY_LEN);
4936 addr = ISP_QUEUE_ENTRY(isp->isp_atioq, oop);
4937 isp_get_hdr(isp, addr, (isphdr_t *)qe);
4938 hp = (isphdr_t *)qe;
4939 switch (hp->rqs_entry_type) {
4940 case RQSTYPE_NOTIFY:
4942 (void) isp_target_notify(isp, addr, &oop);
4945 isp_print_qentry(isp, "?ATIOQ entry?", oop, addr);
4948 optr = ISP_NXT_QENTRY(oop, RESULT_QUEUE_LEN(isp));
4949 ISP_WRITE(isp, BIU2400_ATIO_RSPOUTP, optr);
4951 optr = isp->isp_residx;
4956 * Get the current Response Queue Out Pointer.
4958 * If we're a 2300 or 2400, we can ask what hardware what it thinks.
4960 if (IS_23XX(isp) || IS_24XX(isp)) {
4961 optr = ISP_READ(isp, isp->isp_respoutrp);
4963 * Debug: to be taken out eventually
4965 if (isp->isp_residx != optr) {
4966 isp_prt(isp, ISP_LOGINFO, "isp_intr: hard optr=%x, soft optr %x", optr, isp->isp_residx);
4967 isp->isp_residx = optr;
4970 optr = isp->isp_residx;
4974 * You *must* read the Response Queue In Pointer
4975 * prior to clearing the RISC interrupt.
4977 * Debounce the 2300 if revision less than 2.
4979 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
4982 iptr = ISP_READ(isp, isp->isp_respinrp);
4983 junk = ISP_READ(isp, isp->isp_respinrp);
4984 } while (junk != iptr && ++i < 1000);
4987 isp_prt(isp, ISP_LOGWARN, "Response Queue Out Pointer Unstable (%x, %x)", iptr, junk);
4991 iptr = ISP_READ(isp, isp->isp_respinrp);
4993 isp->isp_resodx = iptr;
4996 if (optr == iptr && sema == 0) {
4998 * There are a lot of these- reasons unknown- mostly on
4999 * faster Alpha machines.
5001 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
5002 * make sure the old interrupt went away (to avoid 'ringing'
5003 * effects), but that didn't stop this from occurring.
5007 } else if (IS_23XX(isp)) {
5009 iptr = ISP_READ(isp, isp->isp_respinrp);
5010 junk = ISP_READ(isp, BIU_R2HSTSLO);
5012 junk = ISP_READ(isp, BIU_ISR);
5015 if (IS_23XX(isp) || IS_24XX(isp)) {
5018 sema = ISP_READ(isp, BIU_SEMA);
5019 mbox = ISP_READ(isp, OUTMAILBOX0);
5020 if ((sema & 0x3) && (mbox & 0x8000)) {
5024 isp->isp_intbogus++;
5025 isp_prt(isp, ISP_LOGDEBUG1, "bogus intr- isr %x (%x) iptr %x optr %x", isr, junk, iptr, optr);
5028 isp->isp_resodx = iptr;
5030 while (optr != iptr) {
5031 uint8_t qe[QENTRY_LEN];
5032 ispstatusreq_t *sp = (ispstatusreq_t *) qe;
5034 int buddaboom, etype, scsi_status, completion_status;
5035 int req_status_flags, req_state_flags;
5036 uint8_t *snsp, *resp;
5037 uint32_t rlen, slen;
5041 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
5043 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
5046 buddaboom = req_status_flags = req_state_flags = 0;
5050 * Synchronize our view of this response queue entry.
5052 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN);
5053 isp_get_hdr(isp, hp, &sp->req_header);
5054 etype = sp->req_header.rqs_entry_type;
5056 if (IS_24XX(isp) && etype == RQSTYPE_RESPONSE) {
5057 isp24xx_statusreq_t *sp2 = (isp24xx_statusreq_t *)qe;
5058 isp_get_24xx_response(isp, (isp24xx_statusreq_t *)hp, sp2);
5059 if (isp->isp_dblev & ISP_LOGDEBUG1) {
5060 isp_print_bytes(isp, "Response Queue Entry", QENTRY_LEN, sp2);
5062 scsi_status = sp2->req_scsi_status;
5063 completion_status = sp2->req_completion_status;
5064 req_state_flags = 0;
5065 resid = sp2->req_resid;
5066 } else if (etype == RQSTYPE_RESPONSE) {
5067 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
5068 if (isp->isp_dblev & ISP_LOGDEBUG1) {
5069 isp_print_bytes(isp, "Response Queue Entry", QENTRY_LEN, sp);
5071 scsi_status = sp->req_scsi_status;
5072 completion_status = sp->req_completion_status;
5073 req_status_flags = sp->req_status_flags;
5074 req_state_flags = sp->req_state_flags;
5075 resid = sp->req_resid;
5076 } else if (etype == RQSTYPE_RIO2) {
5077 isp_rio2_t *rio = (isp_rio2_t *)qe;
5078 isp_get_rio2(isp, (isp_rio2_t *) hp, rio);
5079 if (isp->isp_dblev & ISP_LOGDEBUG1) {
5080 isp_print_bytes(isp, "Response Queue Entry", QENTRY_LEN, rio);
5082 for (i = 0; i < rio->req_header.rqs_seqno; i++) {
5083 isp_fastpost_complete(isp, rio->req_handles[i]);
5085 if (isp->isp_fpcchiwater < rio->req_header.rqs_seqno) {
5086 isp->isp_fpcchiwater = rio->req_header.rqs_seqno;
5088 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5092 * Somebody reachable via isp_handle_other_response
5093 * may have updated the response queue pointers for
5094 * us, so we reload our goal index.
5097 uint32_t tsto = oop;
5098 r = isp_handle_other_response(isp, etype, hp, &tsto);
5103 * If somebody updated the output pointer, then reset
5104 * optr to be one more than the updated amount.
5106 while (tsto != oop) {
5107 optr = ISP_NXT_QENTRY(tsto,
5108 RESULT_QUEUE_LEN(isp));
5111 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5112 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5117 * After this point, we'll just look at the header as
5118 * we don't know how to deal with the rest of the
5123 * It really has to be a bounced request just copied
5124 * from the request queue to the response queue. If
5125 * not, something bad has happened.
5127 if (etype != RQSTYPE_REQUEST) {
5128 isp_prt(isp, ISP_LOGERR, notresp,
5129 etype, oop, optr, nlooked);
5130 isp_print_bytes(isp,
5131 "Request Queue Entry", QENTRY_LEN, sp);
5132 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5136 scsi_status = sp->req_scsi_status;
5137 completion_status = sp->req_completion_status;
5138 req_status_flags = sp->req_status_flags;
5139 req_state_flags = sp->req_state_flags;
5140 resid = sp->req_resid;
5143 if (sp->req_header.rqs_flags & RQSFLAG_MASK) {
5144 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
5145 isp_print_bytes(isp, "unexpected continuation segment", QENTRY_LEN, sp);
5146 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5149 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
5150 isp_prt(isp, ISP_LOGDEBUG0, "internal queues full");
5152 * We'll synthesize a QUEUE FULL message below.
5155 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
5156 isp_print_bytes(isp, "bad header flag", QENTRY_LEN, sp);
5159 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
5160 isp_print_bytes(isp, "bad request packet", QENTRY_LEN, sp);
5163 if (sp->req_header.rqs_flags & RQSFLAG_BADCOUNT) {
5164 isp_print_bytes(isp, "invalid entry count", QENTRY_LEN, sp);
5167 if (sp->req_header.rqs_flags & RQSFLAG_BADORDER) {
5168 isp_print_bytes(isp, "invalid IOCB ordering", QENTRY_LEN, sp);
5169 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5174 if ((sp->req_handle != ISP_SPCL_HANDLE) && (sp->req_handle > isp->isp_maxcmds || sp->req_handle < 1)) {
5175 isp_prt(isp, ISP_LOGERR, "bad request handle %d (type 0x%x)", sp->req_handle, etype);
5176 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5177 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5180 xs = isp_find_xs(isp, sp->req_handle);
5182 uint8_t ts = completion_status & 0xff;
5184 * Only whine if this isn't the expected fallout of
5185 * aborting the command or resetting the target.
5187 if (etype != RQSTYPE_RESPONSE) {
5188 isp_prt(isp, ISP_LOGERR, "cannot find handle 0x%x (type 0x%x)", sp->req_handle, etype);
5189 } else if (ts != RQCS_ABORTED && ts != RQCS_RESET_OCCURRED && sp->req_handle != ISP_SPCL_HANDLE) {
5190 isp_prt(isp, ISP_LOGERR, "cannot find handle 0x%x (status 0x%x)", sp->req_handle, ts);
5192 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5193 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5196 isp_destroy_handle(isp, sp->req_handle);
5197 if (req_status_flags & RQSTF_BUS_RESET) {
5198 XS_SETERR(xs, HBA_BUSRESET);
5199 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 1);
5202 XS_SETERR(xs, HBA_BOTCH);
5209 if (IS_24XX(isp) && (scsi_status & (RQCS_RV|RQCS_SV)) != 0) {
5210 resp = ((isp24xx_statusreq_t *)sp)->req_rsp_sense;
5211 rlen = ((isp24xx_statusreq_t *)sp)->req_response_len;
5212 } else if (IS_FC(isp) && (scsi_status & RQCS_RV) != 0) {
5213 resp = sp->req_response;
5214 rlen = sp->req_response_len;
5216 if (IS_FC(isp) && (scsi_status & RQCS_SV) != 0) {
5218 * Fibre Channel F/W doesn't say we got status
5219 * if there's Sense Data instead. I guess they
5220 * think it goes w/o saying.
5222 req_state_flags |= RQSF_GOT_STATUS|RQSF_GOT_SENSE;
5224 snsp = ((isp24xx_statusreq_t *)sp)->req_rsp_sense;
5226 slen = ((isp24xx_statusreq_t *)sp)->req_sense_len;
5228 snsp = sp->req_sense_data;
5229 slen = sp->req_sense_len;
5231 } else if (IS_SCSI(isp) && (req_state_flags & RQSF_GOT_SENSE)) {
5232 snsp = sp->req_sense_data;
5233 slen = sp->req_sense_len;
5235 if (req_state_flags & RQSF_GOT_STATUS) {
5236 *XS_STSP(xs) = scsi_status & 0xff;
5240 case RQSTYPE_RESPONSE:
5241 if (resp && rlen >= 4 && resp[FCP_RSPNS_CODE_OFFSET] != 0) {
5244 const char *rnames[6] = {
5245 "Task Management Function Done",
5246 "Data Length Differs From Burst Length",
5248 "FCP DATA RO mismatch with FCP DATA_XFR_RDY RO",
5249 "Task Management Function Rejected",
5250 "Task Management Function Failed",
5252 if (resp[FCP_RSPNS_CODE_OFFSET] > 5) {
5253 ISP_SNPRINTF(lb, sizeof lb, "Unknown FCP Response Code 0x%x", resp[FCP_RSPNS_CODE_OFFSET]);
5256 ptr = rnames[resp[FCP_RSPNS_CODE_OFFSET]];
5258 isp_prt(isp, ISP_LOGWARN, "%d.%d.%d FCP RESPONSE, LENGTH %u: %s CDB0=0x%02x", XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), rlen, ptr, XS_CDBP(xs)[0] & 0xff);
5259 if (resp[FCP_RSPNS_CODE_OFFSET] != 0) {
5260 XS_SETERR(xs, HBA_BOTCH);
5264 isp_parse_status_24xx(isp, (isp24xx_statusreq_t *)sp, xs, &resid);
5266 isp_parse_status(isp, (void *)sp, xs, &resid);
5268 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) && (*XS_STSP(xs) == SCSI_BUSY)) {
5269 XS_SETERR(xs, HBA_TGTBSY);
5272 XS_SET_RESID(xs, resid);
5274 * A new synchronous rate was negotiated for
5275 * this target. Mark state such that we'll go
5276 * look up that which has changed later.
5278 if (req_status_flags & RQSTF_NEGOTIATION) {
5280 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
5281 sdp->isp_devparam[t].dev_refresh = 1;
5285 if (req_status_flags & RQSF_XFER_COMPLETE) {
5286 XS_SET_RESID(xs, 0);
5287 } else if (scsi_status & RQCS_RESID) {
5288 XS_SET_RESID(xs, resid);
5290 XS_SET_RESID(xs, 0);
5294 XS_SAVE_SENSE(xs, snsp, slen);
5295 } else if ((req_status_flags & RQSF_GOT_STATUS) && (scsi_status & 0xff) == SCSI_CHECK && IS_FC(isp)) {
5296 isp_prt(isp, ISP_LOGWARN, "CHECK CONDITION w/o sense data for CDB=0x%x", XS_CDBP(xs)[0] & 0xff);
5297 isp_print_bytes(isp, "CC with no Sense", QENTRY_LEN, qe);
5299 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));
5301 case RQSTYPE_REQUEST:
5306 if (!IS_24XX(isp) && (sp->req_header.rqs_flags & RQSFLAG_FULL)) {
5308 * Force Queue Full status.
5310 *XS_STSP(xs) = SCSI_QFULL;
5311 XS_SETERR(xs, HBA_NOERROR);
5312 } else if (XS_NOERR(xs)) {
5313 XS_SETERR(xs, HBA_BOTCH);
5315 XS_SET_RESID(xs, XS_XFRLEN(xs));
5318 isp_print_bytes(isp, "Unhandled Response Type", QENTRY_LEN, qe);
5320 XS_SETERR(xs, HBA_BOTCH);
5326 * Free any DMA resources. As a side effect, this may
5327 * also do any cache flushing necessary for data coherence.
5329 if (XS_XFRLEN(xs)) {
5330 ISP_DMAFREE(isp, xs, sp->req_handle);
5333 if (((isp->isp_dblev & (ISP_LOGDEBUG1|ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
5334 ((isp->isp_dblev & ISP_LOGDEBUG0) && ((!XS_NOERR(xs)) ||
5335 (*XS_STSP(xs) != SCSI_GOOD)))) {
5337 if (req_state_flags & RQSF_GOT_SENSE) {
5338 skey = XS_SNSKEY(xs) & 0xf;
5343 } else if (*XS_STSP(xs) == SCSI_CHECK) {
5348 isp_prt(isp, ISP_LOGALL, finmsg, XS_CHANNEL(xs),
5349 XS_TGT(xs), XS_LUN(xs), XS_XFRLEN(xs), (long) XS_GET_RESID(xs),
5350 *XS_STSP(xs), skey, XS_ERR(xs));
5353 if (isp->isp_nactive > 0) {
5356 complist[ndone++] = xs; /* defer completion call until later */
5357 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5358 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
5364 * If we looked at any commands, then it's valid to find out
5365 * what the outpointer is. It also is a trigger to update the
5366 * ISP's notion of what we've seen so far.
5369 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5371 * While we're at it, read the requst queue out pointer.
5373 isp->isp_reqodx = ISP_READ(isp, isp->isp_rqstoutrp);
5374 if (isp->isp_rscchiwater < ndone) {
5375 isp->isp_rscchiwater = ndone;
5382 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
5384 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
5385 ISP_WRITE(isp, BIU_SEMA, 0);
5388 isp->isp_residx = optr;
5389 for (i = 0; i < ndone; i++) {
5392 isp->isp_rsltccmplt++;
5402 #define GET_24XX_BUS(isp, chan, msg) \
5403 if (IS_24XX(isp)) { \
5404 chan = ISP_READ(isp, OUTMAILBOX3) & 0xff; \
5405 if (chan >= isp->isp_nchan) { \
5406 isp_prt(isp, ISP_LOGERR, "bogus channel %u for %s at line %d", chan, msg, __LINE__); \
5412 isp_parse_async(ispsoftc_t *isp, uint16_t mbox)
5418 if (IS_DUALBUS(isp)) {
5419 chan = ISP_READ(isp, OUTMAILBOX6);
5423 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
5426 case ASYNC_BUS_RESET:
5428 isp_prt(isp, ISP_LOGWARN,
5429 "ILLEGAL ASYNC_BUS_RESET for FC card");
5432 ISP_SET_SENDMARKER(isp, chan, 1);
5433 #ifdef ISP_TARGET_MODE
5434 if (isp_target_async(isp, chan, mbox)) {
5438 isp_async(isp, ISPASYNC_BUS_RESET, chan);
5440 case ASYNC_SYSTEM_ERROR:
5442 isp->isp_state = ISP_CRASHED;
5444 FCPARAM(isp, chan)->isp_loopstate = LOOP_NIL;
5445 FCPARAM(isp, chan)->isp_fwstate = FW_CONFIG_WAIT;
5448 * Were we waiting for a mailbox command to complete?
5449 * If so, it's dead, so wake up the waiter.
5451 if (isp->isp_mboxbsy) {
5453 isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR;
5454 MBOX_NOTIFY_COMPLETE(isp);
5457 * It's up to the handler for isp_async to reinit stuff and
5458 * restart the firmware
5460 isp_async(isp, ISPASYNC_FW_CRASH);
5464 case ASYNC_RQS_XFER_ERR:
5465 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
5468 case ASYNC_RSP_XFER_ERR:
5469 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
5473 #ifdef ISP_TARGET_MODE
5475 isp_prt(isp, ISP_LOGERR, "ATIO Queue Transfer Error");
5480 isp_prt(isp, ISP_LOGWARN,
5481 "ILLEGAL ASYNC_QWAKEUP for FC card");
5485 * We've just been notified that the Queue has woken up.
5486 * We don't need to be chatty about this- just unlatch things
5489 mbox = ISP_READ(isp, isp->isp_rqstoutrp);
5492 case ASYNC_TIMEOUT_RESET:
5494 isp_prt(isp, ISP_LOGWARN,
5495 "ILLEGAL ASYNC_TIMEOUT_RESET for FC card");
5498 isp_prt(isp, ISP_LOGWARN,
5499 "timeout initiated SCSI bus reset of chan %d", chan);
5500 ISP_SET_SENDMARKER(isp, chan, 1);
5501 #ifdef ISP_TARGET_MODE
5502 if (isp_target_async(isp, chan, mbox)) {
5508 case ASYNC_DEVICE_RESET:
5510 isp_prt(isp, ISP_LOGWARN,
5511 "ILLEGAL DEVICE_RESET for FC card");
5514 isp_prt(isp, ISP_LOGINFO, "device reset on chan %d", chan);
5515 ISP_SET_SENDMARKER(isp, chan, 1);
5516 #ifdef ISP_TARGET_MODE
5517 if (isp_target_async(isp, chan, mbox)) {
5523 case ASYNC_EXTMSG_UNDERRUN:
5525 isp_prt(isp, ISP_LOGWARN,
5526 "ILLEGAL ASYNC_EXTMSG_UNDERRUN for FC card");
5529 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
5532 case ASYNC_SCAM_INT:
5534 isp_prt(isp, ISP_LOGWARN,
5535 "ILLEGAL ASYNC_SCAM_INT for FC card");
5538 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
5541 case ASYNC_HUNG_SCSI:
5543 isp_prt(isp, ISP_LOGWARN,
5544 "ILLEGAL ASYNC_HUNG_SCSI for FC card");
5547 isp_prt(isp, ISP_LOGERR,
5548 "stalled SCSI Bus after DATA Overrun");
5549 /* XXX: Need to issue SCSI reset at this point */
5552 case ASYNC_KILLED_BUS:
5554 isp_prt(isp, ISP_LOGWARN,
5555 "ILLEGAL ASYNC_KILLED_BUS for FC card");
5558 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
5561 case ASYNC_BUS_TRANSIT:
5563 isp_prt(isp, ISP_LOGWARN,
5564 "ILLEGAL ASYNC_BUS_TRANSIT for FC card");
5567 mbox = ISP_READ(isp, OUTMAILBOX2);
5568 switch (mbox & 0x1c00) {
5569 case SXP_PINS_LVD_MODE:
5570 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
5571 SDPARAM(isp, chan)->isp_diffmode = 0;
5572 SDPARAM(isp, chan)->isp_ultramode = 0;
5573 SDPARAM(isp, chan)->isp_lvdmode = 1;
5575 case SXP_PINS_HVD_MODE:
5576 isp_prt(isp, ISP_LOGINFO,
5577 "Transition to Differential mode");
5578 SDPARAM(isp, chan)->isp_diffmode = 1;
5579 SDPARAM(isp, chan)->isp_ultramode = 0;
5580 SDPARAM(isp, chan)->isp_lvdmode = 0;
5582 case SXP_PINS_SE_MODE:
5583 isp_prt(isp, ISP_LOGINFO,
5584 "Transition to Single Ended mode");
5585 SDPARAM(isp, chan)->isp_diffmode = 0;
5586 SDPARAM(isp, chan)->isp_ultramode = 1;
5587 SDPARAM(isp, chan)->isp_lvdmode = 0;
5590 isp_prt(isp, ISP_LOGWARN,
5591 "Transition to Unknown Mode 0x%x", mbox);
5595 * XXX: Set up to renegotiate again!
5597 /* Can only be for a 1080... */
5598 ISP_SET_SENDMARKER(isp, chan, 1);
5602 pattern = 0xce; /* outgoing mailbox regs 1-3, 6-7 */
5606 pattern = 0x4e; /* outgoing mailbox regs 1-3, 6 */
5610 pattern = 0x0e; /* outgoing mailbox regs 1-3 */
5614 pattern = 0x06; /* outgoing mailbox regs 1-2 */
5618 case ASYNC_CMD_CMPLT:
5619 pattern = 0x02; /* outgoing mailbox regs 1 */
5622 case ASYNC_RIO_RESP:
5625 case ASYNC_CTIO_DONE:
5627 #ifdef ISP_TARGET_MODE
5629 if (IS_SCSI(isp) || IS_24XX(isp)) {
5630 isp_prt(isp, ISP_LOGWARN,
5631 "bad ASYNC_CTIO_DONE for %s cards",
5632 IS_SCSI(isp)? "SCSI" : "24XX");
5636 (ISP_READ(isp, OUTMAILBOX2) << 16) |
5637 (ISP_READ(isp, OUTMAILBOX1));
5638 if (isp_target_async(isp, handle, mbox)) {
5641 /* count it as a fast posting intr */
5642 isp->isp_fphccmplt++;
5645 if (IS_SCSI(isp) || IS_24XX(isp)) {
5646 isp_prt(isp, ISP_LOGWARN,
5647 "bad ASYNC_CTIO_DONE for %s cards",
5648 IS_SCSI(isp)? "SCSI" : "24XX");
5651 isp_prt(isp, ISP_LOGINFO, "Fast Posting CTIO done");
5652 isp->isp_fphccmplt++; /* count it as a fast posting intr */
5656 case ASYNC_LIP_ERROR:
5658 case ASYNC_LIP_OCCURRED:
5661 isp_prt(isp, ISP_LOGWARN,
5662 "bad LIP event for SCSI cards");
5666 * These are broadcast events that have to be sent across
5667 * all active channels.
5669 for (chan = 0; chan < isp->isp_nchan; chan++) {
5670 fcparam *fcp = FCPARAM(isp, chan);
5671 int topo = fcp->isp_topo;
5673 if (fcp->role == ISP_ROLE_NONE) {
5677 fcp->isp_fwstate = FW_CONFIG_WAIT;
5678 fcp->isp_loopstate = LOOP_LIP_RCVD;
5679 ISP_SET_SENDMARKER(isp, chan, 1);
5680 ISP_MARK_PORTDB(isp, chan, 1);
5681 isp_async(isp, ISPASYNC_LIP, chan);
5682 #ifdef ISP_TARGET_MODE
5683 if (isp_target_async(isp, chan, mbox)) {
5688 * We've had problems with data corruption occuring on
5689 * commands that complete (with no apparent error) after
5690 * we receive a LIP. This has been observed mostly on
5691 * Local Loop topologies. To be safe, let's just mark
5692 * all active commands as dead.
5694 if (topo == TOPO_NL_PORT || topo == TOPO_FL_PORT) {
5696 for (i = j = 0; i < isp->isp_maxcmds; i++) {
5698 xs = isp->isp_xflist[i];
5702 if (XS_CHANNEL(xs) != chan) {
5706 XS_SETERR(xs, HBA_BUSRESET);
5709 isp_prt(isp, ISP_LOGERR, lipd, chan, j);
5717 isp_prt(isp, ISP_LOGWARN,
5718 "bad LOOP UP event for SCSI cards");
5722 * This is a broadcast event that has to be sent across
5723 * all active channels.
5725 for (chan = 0; chan < isp->isp_nchan; chan++) {
5726 fcparam *fcp = FCPARAM(isp, chan);
5728 if (fcp->role == ISP_ROLE_NONE) {
5732 ISP_SET_SENDMARKER(isp, chan, 1);
5734 fcp->isp_fwstate = FW_CONFIG_WAIT;
5735 fcp->isp_loopstate = LOOP_LIP_RCVD;
5736 ISP_MARK_PORTDB(isp, chan, 1);
5737 isp_async(isp, ISPASYNC_LOOP_UP, chan);
5738 #ifdef ISP_TARGET_MODE
5739 if (isp_target_async(isp, chan, mbox)) {
5746 case ASYNC_LOOP_DOWN:
5748 isp_prt(isp, ISP_LOGWARN,
5749 "bad LOOP DOWN event for SCSI cards");
5753 * This is a broadcast event that has to be sent across
5754 * all active channels.
5756 for (chan = 0; chan < isp->isp_nchan; chan++) {
5757 fcparam *fcp = FCPARAM(isp, chan);
5759 if (fcp->role == ISP_ROLE_NONE) {
5763 ISP_SET_SENDMARKER(isp, chan, 1);
5764 fcp->isp_fwstate = FW_CONFIG_WAIT;
5765 fcp->isp_loopstate = LOOP_NIL;
5766 ISP_MARK_PORTDB(isp, chan, 1);
5767 isp_async(isp, ISPASYNC_LOOP_DOWN, chan);
5768 #ifdef ISP_TARGET_MODE
5769 if (isp_target_async(isp, chan, mbox)) {
5776 case ASYNC_LOOP_RESET:
5778 isp_prt(isp, ISP_LOGWARN,
5779 "bad LIP RESET event for SCSI cards");
5783 * This is a broadcast event that has to be sent across
5784 * all active channels.
5786 for (chan = 0; chan < isp->isp_nchan; chan++) {
5787 fcparam *fcp = FCPARAM(isp, chan);
5789 if (fcp->role == ISP_ROLE_NONE) {
5793 ISP_SET_SENDMARKER(isp, chan, 1);
5794 fcp->isp_fwstate = FW_CONFIG_WAIT;
5795 fcp->isp_loopstate = LOOP_NIL;
5796 ISP_MARK_PORTDB(isp, chan, 1);
5797 isp_async(isp, ISPASYNC_LOOP_RESET, chan);
5798 #ifdef ISP_TARGET_MODE
5799 if (isp_target_async(isp, chan, mbox)) {
5806 case ASYNC_PDB_CHANGED:
5808 int nphdl, nlstate, reason;
5810 isp_prt(isp, ISP_LOGWARN,
5811 "bad PDB CHANGED event for SCSI cards");
5815 * We *should* get a channel out of the 24XX, but we don't seem
5816 * to get more than a PDB CHANGED on channel 0, so turn it into
5817 * a broadcast event.
5820 nphdl = ISP_READ(isp, OUTMAILBOX1);
5821 nlstate = ISP_READ(isp, OUTMAILBOX2);
5822 reason = ISP_READ(isp, OUTMAILBOX3) >> 8;
5825 nlstate = reason = 0;
5827 for (chan = 0; chan < isp->isp_nchan; chan++) {
5828 fcparam *fcp = FCPARAM(isp, chan);
5830 if (fcp->role == ISP_ROLE_NONE) {
5833 ISP_SET_SENDMARKER(isp, chan, 1);
5834 fcp->isp_loopstate = LOOP_PDB_RCVD;
5835 ISP_MARK_PORTDB(isp, chan, 1);
5836 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan,
5837 ISPASYNC_CHANGE_PDB, nphdl, nlstate, reason);
5841 case ASYNC_CHANGE_NOTIFY:
5846 isp_prt(isp, ISP_LOGWARN,
5847 "bad CHANGE NOTIFY event for SCSI cards");
5850 if (ISP_FW_NEWER_THAN(isp, 4, 0, 25) && ISP_CAP_MULTI_ID(isp)) {
5851 GET_24XX_BUS(isp, chan, "ASYNC_CHANGE_NOTIFY");
5856 hichan = isp->isp_nchan;
5858 for (chan = lochan; chan < hichan; chan++) {
5859 fcparam *fcp = FCPARAM(isp, chan);
5861 if (fcp->role == ISP_ROLE_NONE) {
5865 if (fcp->isp_topo == TOPO_F_PORT) {
5866 fcp->isp_loopstate = LOOP_LSCAN_DONE;
5868 fcp->isp_loopstate = LOOP_PDB_RCVD;
5870 ISP_MARK_PORTDB(isp, chan, 1);
5871 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan,
5872 ISPASYNC_CHANGE_SNS);
5877 case ASYNC_CONNMODE:
5879 * This only applies to 2100 amd 2200 cards
5881 if (!IS_2200(isp) && !IS_2100(isp)) {
5882 isp_prt(isp, ISP_LOGWARN,
5883 "bad card for ASYNC_CONNMODE event");
5887 mbox = ISP_READ(isp, OUTMAILBOX1);
5888 ISP_MARK_PORTDB(isp, chan, 1);
5891 isp_prt(isp, ISP_LOGINFO,
5892 "Point-to-Point -> Loop mode");
5895 isp_prt(isp, ISP_LOGINFO,
5896 "Loop -> Point-to-Point mode");
5898 case ISP_CONN_BADLIP:
5899 isp_prt(isp, ISP_LOGWARN,
5900 "Point-to-Point -> Loop mode (BAD LIP)");
5902 case ISP_CONN_FATAL:
5904 isp->isp_state = ISP_CRASHED;
5905 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
5906 isp_async(isp, ISPASYNC_FW_CRASH);
5908 case ISP_CONN_LOOPBACK:
5909 isp_prt(isp, ISP_LOGWARN,
5910 "Looped Back in Point-to-Point mode");
5913 isp_prt(isp, ISP_LOGWARN,
5914 "Unknown connection mode (0x%x)", mbox);
5917 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan,
5918 ISPASYNC_CHANGE_OTHER);
5919 FCPARAM(isp, chan)->sendmarker = 1;
5920 FCPARAM(isp, chan)->isp_fwstate = FW_CONFIG_WAIT;
5921 FCPARAM(isp, chan)->isp_loopstate = LOOP_LIP_RCVD;
5926 isp_prt(isp, ISP_LOGWARN, "Receive Error");
5928 isp_prt(isp, ISP_LOGWARN,
5929 "Unknown Async Code 0x%x", mbox);
5932 case ASYNC_RJT_SENT: /* same as ASYNC_QFULL_SENT */
5934 isp_prt(isp, ISP_LOGTDEBUG0, "LS_RJT sent");
5936 } else if (IS_2200(isp)) {
5937 isp_prt(isp, ISP_LOGTDEBUG0, "QFULL sent");
5942 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
5948 uint16_t handles[16];
5950 for (nh = 0, i = 1; i < MAX_MAILBOX(isp); i++) {
5951 if ((pattern & (1 << i)) == 0) {
5954 handles[nh++] = ISP_READ(isp, MBOX_OFF(i));
5956 for (i = 0; i < nh; i++) {
5957 isp_fastpost_complete(isp, handles[i]);
5958 isp_prt(isp, ISP_LOGDEBUG3,
5959 "fast post completion of %u", handles[i]);
5961 if (isp->isp_fpcchiwater < nh) {
5962 isp->isp_fpcchiwater = nh;
5965 isp->isp_intoasync++;
5971 * Handle other response entries. A pointer to the request queue output
5972 * index is here in case we want to eat several entries at once, although
5973 * this is not used currently.
5977 isp_handle_other_response(ispsoftc_t *isp, int type,
5978 isphdr_t *hp, uint32_t *optrp)
5981 case RQSTYPE_STATUS_CONT:
5982 isp_prt(isp, ISP_LOGDEBUG0, "Ignored Continuation Response");
5984 case RQSTYPE_MARKER:
5985 isp_prt(isp, ISP_LOGDEBUG0, "Marker Response");
5989 case RQSTYPE_ENABLE_LUN:
5990 case RQSTYPE_MODIFY_LUN:
5991 case RQSTYPE_NOTIFY:
5992 case RQSTYPE_NOTIFY_ACK:
5998 case RQSTYPE_ABTS_RCVD:
5999 case RQSTYPE_ABTS_RSP:
6000 isp->isp_rsltccmplt++; /* count as a response completion */
6001 #ifdef ISP_TARGET_MODE
6002 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
6007 case RQSTYPE_RPT_ID_ACQ:
6010 isp_get_ridacq(isp, (isp_ridacq_t *)hp, &rid);
6011 if (rid.ridacq_format == 0) {
6016 case RQSTYPE_REQUEST:
6019 if (type != isp_get_response_type(isp, hp)) {
6021 * This is questionable- we're just papering over
6022 * something we've seen on SMP linux in target
6023 * mode- we don't really know what's happening
6024 * here that causes us to think we've gotten
6025 * an entry, but that either the entry isn't
6026 * filled out yet or our CPU read data is stale.
6028 isp_prt(isp, ISP_LOGINFO,
6029 "unstable type in response queue");
6032 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
6033 isp_get_response_type(isp, hp));
6039 isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
6041 switch (sp->req_completion_status & 0xff) {
6044 XS_SETERR(xs, HBA_NOERROR);
6048 case RQCS_INCOMPLETE:
6049 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
6050 isp_prt(isp, ISP_LOGDEBUG1,
6051 "Selection Timeout for %d.%d.%d",
6052 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6054 XS_SETERR(xs, HBA_SELTIMEOUT);
6055 *rp = XS_XFRLEN(xs);
6059 isp_prt(isp, ISP_LOGERR,
6060 "command incomplete for %d.%d.%d, state 0x%x",
6061 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
6062 sp->req_state_flags);
6065 case RQCS_DMA_ERROR:
6066 isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
6067 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6068 *rp = XS_XFRLEN(xs);
6071 case RQCS_TRANSPORT_ERROR:
6074 ISP_SNPRINTF(buf, sizeof (buf), "states=>");
6075 if (sp->req_state_flags & RQSF_GOT_BUS) {
6076 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
6078 if (sp->req_state_flags & RQSF_GOT_TARGET) {
6079 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
6081 if (sp->req_state_flags & RQSF_SENT_CDB) {
6082 ISP_SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
6084 if (sp->req_state_flags & RQSF_XFRD_DATA) {
6085 ISP_SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
6087 if (sp->req_state_flags & RQSF_GOT_STATUS) {
6088 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
6090 if (sp->req_state_flags & RQSF_GOT_SENSE) {
6091 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
6093 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
6094 ISP_SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
6096 ISP_SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
6097 if (sp->req_status_flags & RQSTF_DISCONNECT) {
6098 ISP_SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
6100 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
6101 ISP_SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
6103 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
6104 ISP_SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
6106 if (sp->req_status_flags & RQSTF_BUS_RESET) {
6107 ISP_SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
6109 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
6110 ISP_SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
6112 if (sp->req_status_flags & RQSTF_ABORTED) {
6113 ISP_SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
6115 if (sp->req_status_flags & RQSTF_TIMEOUT) {
6116 ISP_SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
6118 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
6119 ISP_SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
6121 isp_prt(isp, ISP_LOGERR, "%s", buf);
6122 isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d:\n%s",
6123 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), buf);
6124 *rp = XS_XFRLEN(xs);
6127 case RQCS_RESET_OCCURRED:
6130 isp_prt(isp, ISP_LOGWARN,
6131 "bus reset destroyed command for %d.%d.%d",
6132 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6133 for (chan = 0; chan < isp->isp_nchan; chan++) {
6134 FCPARAM(isp, chan)->sendmarker = 1;
6137 XS_SETERR(xs, HBA_BUSRESET);
6139 *rp = XS_XFRLEN(xs);
6143 isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
6144 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6145 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 1);
6147 XS_SETERR(xs, HBA_ABORTED);
6152 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
6153 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6155 * XXX: Check to see if we logged out of the device.
6158 XS_SETERR(xs, HBA_CMDTIMEOUT);
6162 case RQCS_DATA_OVERRUN:
6163 XS_SET_RESID(xs, sp->req_resid);
6164 isp_prt(isp, ISP_LOGERR, "data overrun (%ld) for command on %d.%d.%d",
6165 (long) XS_GET_RESID(xs), XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6167 XS_SETERR(xs, HBA_DATAOVR);
6171 case RQCS_COMMAND_OVERRUN:
6172 isp_prt(isp, ISP_LOGERR,
6173 "command overrun for command on %d.%d.%d",
6174 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6177 case RQCS_STATUS_OVERRUN:
6178 isp_prt(isp, ISP_LOGERR,
6179 "status overrun for command on %d.%d.%d",
6180 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6183 case RQCS_BAD_MESSAGE:
6184 isp_prt(isp, ISP_LOGERR,
6185 "msg not COMMAND COMPLETE after status %d.%d.%d",
6186 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6189 case RQCS_NO_MESSAGE_OUT:
6190 isp_prt(isp, ISP_LOGERR,
6191 "No MESSAGE OUT phase after selection on %d.%d.%d",
6192 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6195 case RQCS_EXT_ID_FAILED:
6196 isp_prt(isp, ISP_LOGERR, "EXTENDED IDENTIFY failed %d.%d.%d",
6197 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6200 case RQCS_IDE_MSG_FAILED:
6201 isp_prt(isp, ISP_LOGERR,
6202 "INITIATOR DETECTED ERROR rejected by %d.%d.%d",
6203 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6206 case RQCS_ABORT_MSG_FAILED:
6207 isp_prt(isp, ISP_LOGERR, "ABORT OPERATION rejected by %d.%d.%d",
6208 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6211 case RQCS_REJECT_MSG_FAILED:
6212 isp_prt(isp, ISP_LOGERR, "MESSAGE REJECT rejected by %d.%d.%d",
6213 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6216 case RQCS_NOP_MSG_FAILED:
6217 isp_prt(isp, ISP_LOGERR, "NOP rejected by %d.%d.%d",
6218 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6221 case RQCS_PARITY_ERROR_MSG_FAILED:
6222 isp_prt(isp, ISP_LOGERR,
6223 "MESSAGE PARITY ERROR rejected by %d.%d.%d",
6224 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6227 case RQCS_DEVICE_RESET_MSG_FAILED:
6228 isp_prt(isp, ISP_LOGWARN,
6229 "BUS DEVICE RESET rejected by %d.%d.%d",
6230 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6233 case RQCS_ID_MSG_FAILED:
6234 isp_prt(isp, ISP_LOGERR, "IDENTIFY rejected by %d.%d.%d",
6235 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6238 case RQCS_UNEXP_BUS_FREE:
6239 isp_prt(isp, ISP_LOGERR, "%d.%d.%d had an unexpected bus free",
6240 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6243 case RQCS_DATA_UNDERRUN:
6246 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
6247 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
6248 isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
6249 XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
6250 (ru_marked)? "marked" : "not marked");
6252 XS_SETERR(xs, HBA_BOTCH);
6257 XS_SET_RESID(xs, sp->req_resid);
6259 XS_SETERR(xs, HBA_NOERROR);
6264 case RQCS_XACT_ERR1:
6265 isp_prt(isp, ISP_LOGERR, xact1, XS_CHANNEL(xs),
6266 XS_TGT(xs), XS_LUN(xs));
6269 case RQCS_XACT_ERR2:
6270 isp_prt(isp, ISP_LOGERR, xact2,
6271 XS_LUN(xs), XS_TGT(xs), XS_CHANNEL(xs));
6274 case RQCS_XACT_ERR3:
6275 isp_prt(isp, ISP_LOGERR, xact3,
6276 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6279 case RQCS_BAD_ENTRY:
6280 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
6283 case RQCS_QUEUE_FULL:
6284 isp_prt(isp, ISP_LOGDEBUG0,
6285 "internal queues full for %d.%d.%d status 0x%x",
6286 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), *XS_STSP(xs));
6289 * If QFULL or some other status byte is set, then this
6290 * isn't an error, per se.
6292 * Unfortunately, some QLogic f/w writers have, in
6293 * some cases, ommitted to *set* status to QFULL.
6296 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
6297 XS_SETERR(xs, HBA_NOERROR);
6305 *XS_STSP(xs) = SCSI_QFULL;
6306 XS_SETERR(xs, HBA_NOERROR);
6309 case RQCS_PHASE_SKIPPED:
6310 isp_prt(isp, ISP_LOGERR, pskip, XS_CHANNEL(xs),
6311 XS_TGT(xs), XS_LUN(xs));
6314 case RQCS_ARQS_FAILED:
6315 isp_prt(isp, ISP_LOGERR,
6316 "Auto Request Sense failed for %d.%d.%d",
6317 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6319 XS_SETERR(xs, HBA_ARQFAIL);
6323 case RQCS_WIDE_FAILED:
6324 isp_prt(isp, ISP_LOGERR,
6325 "Wide Negotiation failed for %d.%d.%d",
6326 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
6328 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
6329 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
6330 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
6334 XS_SETERR(xs, HBA_NOERROR);
6338 case RQCS_SYNCXFER_FAILED:
6339 isp_prt(isp, ISP_LOGERR,
6340 "SDTR Message failed for target %d.%d.%d",
6341 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
6343 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
6344 sdp += XS_CHANNEL(xs);
6345 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
6346 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
6351 case RQCS_LVD_BUSERR:
6352 isp_prt(isp, ISP_LOGERR,
6353 "Bad LVD condition while talking to %d.%d.%d",
6354 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
6357 case RQCS_PORT_UNAVAILABLE:
6359 * No such port on the loop. Moral equivalent of SELTIMEO
6361 case RQCS_PORT_LOGGED_OUT:
6364 uint8_t sts = sp->req_completion_status & 0xff;
6367 * It was there (maybe)- treat as a selection timeout.
6369 if (sts == RQCS_PORT_UNAVAILABLE) {
6370 reason = "unavailable";
6375 isp_prt(isp, ISP_LOGINFO, "port %s for target %d",
6376 reason, XS_TGT(xs));
6379 * If we're on a local loop, force a LIP (which is overkill)
6380 * to force a re-login of this unit. If we're on fabric,
6381 * then we'll have to log in again as a matter of course.
6383 if (FCPARAM(isp, 0)->isp_topo == TOPO_NL_PORT ||
6384 FCPARAM(isp, 0)->isp_topo == TOPO_FL_PORT) {
6386 MBSINIT(&mbs, MBOX_INIT_LIP, MBLOGALL, 0);
6387 if (ISP_CAP_2KLOGIN(isp)) {
6388 mbs.ibits = (1 << 10);
6390 isp_mboxcmd_qnw(isp, &mbs, 1);
6393 XS_SETERR(xs, HBA_SELTIMEOUT);
6397 case RQCS_PORT_CHANGED:
6398 isp_prt(isp, ISP_LOGWARN,
6399 "port changed for target %d", XS_TGT(xs));
6401 XS_SETERR(xs, HBA_SELTIMEOUT);
6405 case RQCS_PORT_BUSY:
6406 isp_prt(isp, ISP_LOGWARN,
6407 "port busy for target %d", XS_TGT(xs));
6409 XS_SETERR(xs, HBA_TGTBSY);
6414 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x",
6415 sp->req_completion_status);
6419 XS_SETERR(xs, HBA_BOTCH);
6424 isp_parse_status_24xx(ispsoftc_t *isp, isp24xx_statusreq_t *sp,
6427 int ru_marked, sv_marked;
6428 int chan = XS_CHANNEL(xs);
6430 switch (sp->req_completion_status) {
6433 XS_SETERR(xs, HBA_NOERROR);
6437 case RQCS_DMA_ERROR:
6438 isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
6439 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6442 case RQCS_TRANSPORT_ERROR:
6443 isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d",
6444 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6447 case RQCS_RESET_OCCURRED:
6448 isp_prt(isp, ISP_LOGWARN,
6449 "reset destroyed command for %d.%d.%d",
6450 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6451 FCPARAM(isp, chan)->sendmarker = 1;
6453 XS_SETERR(xs, HBA_BUSRESET);
6458 isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
6459 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6460 FCPARAM(isp, chan)->sendmarker = 1;
6462 XS_SETERR(xs, HBA_ABORTED);
6467 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
6468 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6470 XS_SETERR(xs, HBA_CMDTIMEOUT);
6474 case RQCS_DATA_OVERRUN:
6475 XS_SET_RESID(xs, sp->req_resid);
6476 isp_prt(isp, ISP_LOGERR,
6477 "data overrun for command on %d.%d.%d",
6478 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6480 XS_SETERR(xs, HBA_DATAOVR);
6484 case RQCS_24XX_DRE: /* data reassembly error */
6485 isp_prt(isp, ISP_LOGERR,
6486 "Chan %d data reassembly error for target %d",
6489 XS_SETERR(xs, HBA_ABORTED);
6491 *rp = XS_XFRLEN(xs);
6494 case RQCS_24XX_TABORT: /* aborted by target */
6495 isp_prt(isp, ISP_LOGERR, "Chan %d target %d sent ABTS",
6498 XS_SETERR(xs, HBA_ABORTED);
6502 case RQCS_DATA_UNDERRUN:
6503 ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
6505 * We can get an underrun w/o things being marked
6506 * if we got a non-zero status.
6508 sv_marked = (sp->req_scsi_status & (RQCS_SV|RQCS_RV)) != 0;
6509 if ((ru_marked == 0 && sv_marked == 0) ||
6510 (sp->req_resid > XS_XFRLEN(xs))) {
6511 isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
6512 XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
6513 (ru_marked)? "marked" : "not marked");
6515 XS_SETERR(xs, HBA_BOTCH);
6519 XS_SET_RESID(xs, sp->req_resid);
6520 isp_prt(isp, ISP_LOGDEBUG0,
6521 "%d.%d.%d data underrun (%d) for command 0x%x",
6522 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
6523 sp->req_resid, XS_CDBP(xs)[0] & 0xff);
6525 XS_SETERR(xs, HBA_NOERROR);
6529 case RQCS_PORT_UNAVAILABLE:
6531 * No such port on the loop. Moral equivalent of SELTIMEO
6533 case RQCS_PORT_LOGGED_OUT:
6536 uint8_t sts = sp->req_completion_status & 0xff;
6539 * It was there (maybe)- treat as a selection timeout.
6541 if (sts == RQCS_PORT_UNAVAILABLE) {
6542 reason = "unavailable";
6547 isp_prt(isp, ISP_LOGINFO, "Chan %d port %s for target %d",
6548 chan, reason, XS_TGT(xs));
6551 * There is no MBOX_INIT_LIP for the 24XX.
6554 XS_SETERR(xs, HBA_SELTIMEOUT);
6558 case RQCS_PORT_CHANGED:
6559 isp_prt(isp, ISP_LOGWARN,
6560 "port changed for target %d chan %d", XS_TGT(xs), chan);
6562 XS_SETERR(xs, HBA_SELTIMEOUT);
6567 case RQCS_24XX_ENOMEM: /* f/w resource unavailable */
6568 isp_prt(isp, ISP_LOGWARN,
6569 "f/w resource unavailable for target %d chan %d",
6572 *XS_STSP(xs) = SCSI_BUSY;
6573 XS_SETERR(xs, HBA_TGTBSY);
6577 case RQCS_24XX_TMO: /* task management overrun */
6578 isp_prt(isp, ISP_LOGWARN,
6579 "command for target %d overlapped task management for "
6580 "chan %d", XS_TGT(xs), chan);
6582 *XS_STSP(xs) = SCSI_BUSY;
6583 XS_SETERR(xs, HBA_TGTBSY);
6588 isp_prt(isp, ISP_LOGERR,
6589 "Unknown Completion Status 0x%x on chan %d",
6590 sp->req_completion_status, chan);
6594 XS_SETERR(xs, HBA_BOTCH);
6599 isp_fastpost_complete(ispsoftc_t *isp, uint16_t fph)
6606 xs = isp_find_xs(isp, fph);
6608 isp_prt(isp, ISP_LOGWARN,
6609 "Command for fast post handle 0x%x not found", fph);
6612 isp_destroy_handle(isp, fph);
6615 * Since we don't have a result queue entry item,
6616 * we must believe that SCSI status is zero and
6617 * that all data transferred.
6619 XS_SET_RESID(xs, 0);
6620 *XS_STSP(xs) = SCSI_GOOD;
6621 if (XS_XFRLEN(xs)) {
6622 ISP_DMAFREE(isp, xs, fph);
6624 if (isp->isp_nactive) {
6627 isp->isp_fphccmplt++;
6632 isp_mbox_continue(ispsoftc_t *isp)
6638 switch (isp->isp_lastmbxcmd) {
6639 case MBOX_WRITE_RAM_WORD:
6640 case MBOX_READ_RAM_WORD:
6641 case MBOX_WRITE_RAM_WORD_EXTENDED:
6642 case MBOX_READ_RAM_WORD_EXTENDED:
6647 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
6648 isp->isp_mbxwrk0 = 0;
6653 * Clear the previous interrupt.
6656 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
6658 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
6659 ISP_WRITE(isp, BIU_SEMA, 0);
6663 * Continue with next word.
6665 ISP_MEMZERO(&mbs, sizeof (mbs));
6666 ptr = isp->isp_mbxworkp;
6667 switch (isp->isp_lastmbxcmd) {
6668 case MBOX_WRITE_RAM_WORD:
6669 mbs.param[1] = isp->isp_mbxwrk1++;;
6670 mbs.param[2] = *ptr++;;
6672 case MBOX_READ_RAM_WORD:
6673 *ptr++ = isp->isp_mboxtmp[2];
6674 mbs.param[1] = isp->isp_mbxwrk1++;
6676 case MBOX_WRITE_RAM_WORD_EXTENDED:
6677 offset = isp->isp_mbxwrk1;
6678 offset |= isp->isp_mbxwrk8 << 16;
6680 mbs.param[2] = *ptr++;;
6681 mbs.param[1] = offset;
6682 mbs.param[8] = offset >> 16;
6683 isp->isp_mbxwrk1 = ++offset;
6684 isp->isp_mbxwrk8 = offset >> 16;
6686 case MBOX_READ_RAM_WORD_EXTENDED:
6687 offset = isp->isp_mbxwrk1;
6688 offset |= isp->isp_mbxwrk8 << 16;
6690 *ptr++ = isp->isp_mboxtmp[2];
6691 mbs.param[1] = offset;
6692 mbs.param[8] = offset >> 16;
6693 isp->isp_mbxwrk1 = ++offset;
6694 isp->isp_mbxwrk8 = offset >> 16;
6697 isp->isp_mbxworkp = ptr;
6699 mbs.param[0] = isp->isp_lastmbxcmd;
6700 mbs.logval = MBLOGALL;
6701 isp_mboxcmd_qnw(isp, &mbs, 0);
6705 #define HIWRD(x) ((x) >> 16)
6706 #define LOWRD(x) ((x) & 0xffff)
6707 #define ISPOPMAP(a, b) (((a) << 16) | (b))
6708 static const uint32_t mbpscsi[] = {
6709 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
6710 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
6711 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
6712 ISPOPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
6713 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
6714 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
6715 ISPOPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
6716 ISPOPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
6717 ISPOPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
6718 ISPOPMAP(0x00, 0x00), /* 0x09: */
6719 ISPOPMAP(0x00, 0x00), /* 0x0a: */
6720 ISPOPMAP(0x00, 0x00), /* 0x0b: */
6721 ISPOPMAP(0x00, 0x00), /* 0x0c: */
6722 ISPOPMAP(0x00, 0x00), /* 0x0d: */
6723 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
6724 ISPOPMAP(0x00, 0x00), /* 0x0f: */
6725 ISPOPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
6726 ISPOPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
6727 ISPOPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
6728 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
6729 ISPOPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
6730 ISPOPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
6731 ISPOPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
6732 ISPOPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
6733 ISPOPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
6734 ISPOPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
6735 ISPOPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
6736 ISPOPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
6737 ISPOPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
6738 ISPOPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
6739 ISPOPMAP(0x00, 0x00), /* 0x1e: */
6740 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
6741 ISPOPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
6742 ISPOPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
6743 ISPOPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
6744 ISPOPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
6745 ISPOPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
6746 ISPOPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
6747 ISPOPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
6748 ISPOPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
6749 ISPOPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
6750 ISPOPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
6751 ISPOPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
6752 ISPOPMAP(0x00, 0x00), /* 0x2b: */
6753 ISPOPMAP(0x00, 0x00), /* 0x2c: */
6754 ISPOPMAP(0x00, 0x00), /* 0x2d: */
6755 ISPOPMAP(0x00, 0x00), /* 0x2e: */
6756 ISPOPMAP(0x00, 0x00), /* 0x2f: */
6757 ISPOPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
6758 ISPOPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
6759 ISPOPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
6760 ISPOPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
6761 ISPOPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
6762 ISPOPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
6763 ISPOPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
6764 ISPOPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
6765 ISPOPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
6766 ISPOPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
6767 ISPOPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
6768 ISPOPMAP(0x00, 0x00), /* 0x3b: */
6769 ISPOPMAP(0x00, 0x00), /* 0x3c: */
6770 ISPOPMAP(0x00, 0x00), /* 0x3d: */
6771 ISPOPMAP(0x00, 0x00), /* 0x3e: */
6772 ISPOPMAP(0x00, 0x00), /* 0x3f: */
6773 ISPOPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
6774 ISPOPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
6775 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
6776 ISPOPMAP(0x00, 0x00), /* 0x43: */
6777 ISPOPMAP(0x00, 0x00), /* 0x44: */
6778 ISPOPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
6779 ISPOPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
6780 ISPOPMAP(0x00, 0x00), /* 0x47: */
6781 ISPOPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
6782 ISPOPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
6783 ISPOPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
6784 ISPOPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
6785 ISPOPMAP(0x00, 0x00), /* 0x4c: */
6786 ISPOPMAP(0x00, 0x00), /* 0x4d: */
6787 ISPOPMAP(0x00, 0x00), /* 0x4e: */
6788 ISPOPMAP(0x00, 0x00), /* 0x4f: */
6789 ISPOPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
6790 ISPOPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
6791 ISPOPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
6792 ISPOPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
6793 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUCUTE COMMAND IOCB A64 */
6794 ISPOPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
6795 ISPOPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
6796 ISPOPMAP(0x00, 0x00), /* 0x57: */
6797 ISPOPMAP(0x00, 0x00), /* 0x58: */
6798 ISPOPMAP(0x00, 0x00), /* 0x59: */
6799 ISPOPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
6800 ISPOPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
6801 ISPOPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
6802 ISPOPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
6805 static const char *scsi_mbcmd_names[] = {
6822 "INIT REQUEST QUEUE",
6823 "INIT RESULT QUEUE",
6833 "SINGLE STEP QUEUE",
6835 "GET DEV QUEUE STATUS",
6837 "GET FIRMWARE STATUS",
6839 "GET SELECT TIMEOUT",
6841 "GET TAG AGE LIMIT",
6843 "GET ACT NEG STATE",
6844 "GET ASYNC DATA SETUP TIME",
6846 "GET TARGET PARAMS",
6847 "GET DEV QUEUE PARAMS",
6848 "GET RESET DELAY PARAMS",
6855 "SET SELECT TIMEOUT",
6857 "SET TAG AGE LIMIT",
6859 "SET ACT NEG STATE",
6860 "SET ASYNC DATA SETUP TIME",
6861 "SET PCI CONTROL PARAMS",
6862 "SET TARGET PARAMS",
6863 "SET DEV QUEUE PARAMS",
6864 "SET RESET DELAY PARAMS",
6870 "RETURN BIOS BLOCK ADDR",
6871 "WRITE FOUR RAM WORDS",
6875 "SET SYSTEM PARAMETER",
6876 "GET SYSTEM PARAMETER",
6878 "GET SCAM CONFIGURATION",
6879 "SET SCAM CONFIGURATION",
6880 "SET FIRMWARE FEATURES",
6881 "GET FIRMWARE FEATURES",
6888 "INITIALIZE REQUEST QUEUE A64",
6889 "INITIALIZE RESPONSE QUEUE A64",
6891 "ENABLE TARGET MODE",
6892 "GET TARGET MODE STATE",
6896 "SET DATA OVERRUN RECOVERY MODE",
6897 "GET DATA OVERRUN RECOVERY MODE",
6902 static const uint32_t mbpfc[] = {
6903 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
6904 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
6905 ISPOPMAP(0x0f, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
6906 ISPOPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
6907 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
6908 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
6909 ISPOPMAP(0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
6910 ISPOPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
6911 ISPOPMAP(0x01, 0x4f), /* 0x08: MBOX_ABOUT_FIRMWARE */
6912 ISPOPMAP(0xdf, 0x01), /* 0x09: MBOX_LOAD_RISC_RAM_2100 */
6913 ISPOPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
6914 ISPOPMAP(0x1ff, 0x01), /* 0x0b: MBOX_LOAD_RISC_RAM */
6915 ISPOPMAP(0x00, 0x00), /* 0x0c: */
6916 ISPOPMAP(0x10f, 0x01), /* 0x0d: MBOX_WRITE_RAM_WORD_EXTENDED */
6917 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
6918 ISPOPMAP(0x10f, 0x05), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED */
6919 ISPOPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
6920 ISPOPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
6921 ISPOPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
6922 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
6923 ISPOPMAP(0x01, 0xff), /* 0x14: MBOX_STOP_FIRMWARE */
6924 ISPOPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
6925 ISPOPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
6926 ISPOPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
6927 ISPOPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
6928 ISPOPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
6929 ISPOPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
6930 ISPOPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
6931 ISPOPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
6932 ISPOPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
6933 ISPOPMAP(0x00, 0x00), /* 0x1e: */
6934 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
6935 ISPOPMAP(0x01, 0x4f), /* 0x20: MBOX_GET_LOOP_ID */
6936 ISPOPMAP(0x00, 0x00), /* 0x21: */
6937 ISPOPMAP(0x01, 0x07), /* 0x22: MBOX_GET_RETRY_COUNT */
6938 ISPOPMAP(0x00, 0x00), /* 0x23: */
6939 ISPOPMAP(0x00, 0x00), /* 0x24: */
6940 ISPOPMAP(0x00, 0x00), /* 0x25: */
6941 ISPOPMAP(0x00, 0x00), /* 0x26: */
6942 ISPOPMAP(0x00, 0x00), /* 0x27: */
6943 ISPOPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
6944 ISPOPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
6945 ISPOPMAP(0x00, 0x00), /* 0x2a: */
6946 ISPOPMAP(0x00, 0x00), /* 0x2b: */
6947 ISPOPMAP(0x00, 0x00), /* 0x2c: */
6948 ISPOPMAP(0x00, 0x00), /* 0x2d: */
6949 ISPOPMAP(0x00, 0x00), /* 0x2e: */
6950 ISPOPMAP(0x00, 0x00), /* 0x2f: */
6951 ISPOPMAP(0x00, 0x00), /* 0x30: */
6952 ISPOPMAP(0x00, 0x00), /* 0x31: */
6953 ISPOPMAP(0x07, 0x07), /* 0x32: MBOX_SET_RETRY_COUNT */
6954 ISPOPMAP(0x00, 0x00), /* 0x33: */
6955 ISPOPMAP(0x00, 0x00), /* 0x34: */
6956 ISPOPMAP(0x00, 0x00), /* 0x35: */
6957 ISPOPMAP(0x00, 0x00), /* 0x36: */
6958 ISPOPMAP(0x00, 0x00), /* 0x37: */
6959 ISPOPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
6960 ISPOPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
6961 ISPOPMAP(0x00, 0x00), /* 0x3a: */
6962 ISPOPMAP(0x00, 0x00), /* 0x3b: */
6963 ISPOPMAP(0x00, 0x00), /* 0x3c: */
6964 ISPOPMAP(0x00, 0x00), /* 0x3d: */
6965 ISPOPMAP(0x00, 0x00), /* 0x3e: */
6966 ISPOPMAP(0x00, 0x00), /* 0x3f: */
6967 ISPOPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
6968 ISPOPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
6969 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_GET_RESOURCE_COUNT */
6970 ISPOPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_OFFLINE_MODE */
6971 ISPOPMAP(0x00, 0x00), /* 0x44: */
6972 ISPOPMAP(0x00, 0x00), /* 0x45: */
6973 ISPOPMAP(0x00, 0x00), /* 0x46: */
6974 ISPOPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
6975 ISPOPMAP(0xcd, 0x01), /* 0x48: MBOX_INIT_FIRMWARE_MULTI_ID */
6976 ISPOPMAP(0xcd, 0x01), /* 0x49: MBOX_GET_VP_DATABASE */
6977 ISPOPMAP(0x2cd, 0x01), /* 0x4a: MBOX_GET_VP_DATABASE_ENTRY */
6978 ISPOPMAP(0x00, 0x00), /* 0x4b: */
6979 ISPOPMAP(0x00, 0x00), /* 0x4c: */
6980 ISPOPMAP(0x00, 0x00), /* 0x4d: */
6981 ISPOPMAP(0x00, 0x00), /* 0x4e: */
6982 ISPOPMAP(0x00, 0x00), /* 0x4f: */
6983 ISPOPMAP(0x00, 0x00), /* 0x50: */
6984 ISPOPMAP(0x00, 0x00), /* 0x51: */
6985 ISPOPMAP(0x00, 0x00), /* 0x52: */
6986 ISPOPMAP(0x00, 0x00), /* 0x53: */
6987 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
6988 ISPOPMAP(0x00, 0x00), /* 0x55: */
6989 ISPOPMAP(0x00, 0x00), /* 0x56: */
6990 ISPOPMAP(0x00, 0x00), /* 0x57: */
6991 ISPOPMAP(0x00, 0x00), /* 0x58: */
6992 ISPOPMAP(0x00, 0x00), /* 0x59: */
6993 ISPOPMAP(0x00, 0x00), /* 0x5a: */
6994 ISPOPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
6995 ISPOPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
6996 ISPOPMAP(0x07, 0x03), /* 0x5d: MBOX_GET_SET_DATA_RATE */
6997 ISPOPMAP(0x00, 0x00), /* 0x5e: */
6998 ISPOPMAP(0x00, 0x00), /* 0x5f: */
6999 ISPOPMAP(0xcd, 0x01), /* 0x60: MBOX_INIT_FIRMWARE */
7000 ISPOPMAP(0x00, 0x00), /* 0x61: */
7001 ISPOPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
7002 ISPOPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
7003 ISPOPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
7004 ISPOPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
7005 ISPOPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
7006 ISPOPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
7007 ISPOPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
7008 ISPOPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
7009 ISPOPMAP(0x03, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
7010 ISPOPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
7011 ISPOPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
7012 ISPOPMAP(0x00, 0x00), /* 0x6d: */
7013 ISPOPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
7014 ISPOPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
7015 ISPOPMAP(0x03, 0x01), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
7016 ISPOPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
7017 ISPOPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
7018 ISPOPMAP(0x00, 0x00), /* 0x73: */
7019 ISPOPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
7020 ISPOPMAP(0xcf, 0x03), /* 0x75: GET PORT/NODE NAME LIST */
7021 ISPOPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
7022 ISPOPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
7023 ISPOPMAP(0x00, 0x00), /* 0x78: */
7024 ISPOPMAP(0x00, 0x00), /* 0x79: */
7025 ISPOPMAP(0x00, 0x00), /* 0x7a: */
7026 ISPOPMAP(0x00, 0x00), /* 0x7b: */
7027 ISPOPMAP(0x4f, 0x03), /* 0x7c: Get ID List */
7028 ISPOPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
7029 ISPOPMAP(0x0f, 0x01) /* 0x7e: LUN RESET */
7034 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
7035 * do not access at this time in the core driver. The caller is
7036 * responsible for setting this register first (Gross!). The assumption
7037 * is that we won't overflow.
7040 static const char *fc_mbcmd_names[] = {
7052 "WRITE RAM WORD EXTENDED",
7054 "READ RAM WORD EXTENDED",
7057 "INIT REQUEST QUEUE",
7058 "INIT RESULT QUEUE",
7068 "SINGLE STEP QUEUE",
7070 "GET DEV QUEUE STATUS",
7072 "GET FIRMWARE STATUS",
7081 "GET FIRMWARE OPTIONS",
7082 "GET PORT QUEUE PARAMS",
7097 "SET FIRMWARE OPTIONS",
7098 "SET PORT QUEUE PARAMS",
7107 "GET RESOURCE COUNT",
7108 "REQUEST NON PARTICIPATING MODE",
7112 "GET PORT DATABASE ENHANCED",
7113 "INIT FIRMWARE MULTI ID",
7115 "GET VP DATABASE ENTRY",
7134 "GET/SET DATA RATE",
7140 "GET FC-AL POSITION MAP",
7141 "GET PORT DATABASE",
7153 "SEND CHANGE REQUEST",
7158 "GET PORT/NODE NAME LIST",
7160 "INITIALIZE IP MAILBOX",
7171 isp_mboxcmd_qnw(ispsoftc_t *isp, mbreg_t *mbp, int nodelay)
7173 unsigned int ibits, obits, box, opcode;
7174 const uint32_t *mcp;
7181 opcode = mbp->param[0];
7182 ibits = HIWRD(mcp[opcode]) & NMBOX_BMASK(isp);
7183 obits = LOWRD(mcp[opcode]) & NMBOX_BMASK(isp);
7184 ibits |= mbp->ibits;
7185 obits |= mbp->obits;
7186 for (box = 0; box < MAX_MAILBOX(isp); box++) {
7187 if (ibits & (1 << box)) {
7188 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
7191 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
7195 isp->isp_lastmbxcmd = opcode;
7196 isp->isp_obits = obits;
7197 isp->isp_mboxbsy = 1;
7200 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_SET_HOST_INT);
7202 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
7205 * Oddly enough, if we're not delaying for an answer,
7206 * delay a bit to give the f/w a chance to pick up the
7215 isp_mboxcmd(ispsoftc_t *isp, mbreg_t *mbp)
7217 const char *cname, *xname;
7218 char tname[16], mname[16];
7219 unsigned int lim, ibits, obits, box, opcode;
7220 const uint32_t *mcp;
7224 lim = (sizeof (mbpfc) / sizeof (mbpfc[0]));
7227 lim = (sizeof (mbpscsi) / sizeof (mbpscsi[0]));
7230 if ((opcode = mbp->param[0]) >= lim) {
7231 mbp->param[0] = MBOX_INVALID_COMMAND;
7232 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
7236 ibits = HIWRD(mcp[opcode]) & NMBOX_BMASK(isp);
7237 obits = LOWRD(mcp[opcode]) & NMBOX_BMASK(isp);
7240 * Pick up any additional bits that the caller might have set.
7242 ibits |= mbp->ibits;
7243 obits |= mbp->obits;
7245 if (ibits == 0 && obits == 0) {
7246 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
7247 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
7252 * Get exclusive usage of mailbox registers.
7254 if (MBOX_ACQUIRE(isp)) {
7255 mbp->param[0] = MBOX_REGS_BUSY;
7259 for (box = 0; box < MAX_MAILBOX(isp); box++) {
7260 if (ibits & (1 << box)) {
7261 isp_prt(isp, ISP_LOGDEBUG3, "IN mbox %d = 0x%04x", box,
7263 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
7265 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
7268 isp->isp_lastmbxcmd = opcode;
7271 * We assume that we can't overwrite a previous command.
7273 isp->isp_obits = obits;
7274 isp->isp_mboxbsy = 1;
7277 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
7280 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_SET_HOST_INT);
7282 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
7286 * While we haven't finished the command, spin our wheels here.
7288 MBOX_WAIT_COMPLETE(isp, mbp);
7291 * Did the command time out?
7293 if (mbp->param[0] == MBOX_TIMEOUT) {
7294 isp->isp_mboxbsy = 0;
7300 * Copy back output registers.
7302 for (box = 0; box < MAX_MAILBOX(isp); box++) {
7303 if (obits & (1 << box)) {
7304 mbp->param[box] = isp->isp_mboxtmp[box];
7305 isp_prt(isp, ISP_LOGDEBUG3, "OUT mbox %d = 0x%04x", box,
7310 isp->isp_mboxbsy = 0;
7313 if (mbp->logval == 0 || opcode == MBOX_EXEC_FIRMWARE) {
7316 cname = (IS_FC(isp))? fc_mbcmd_names[opcode] : scsi_mbcmd_names[opcode];
7317 if (cname == NULL) {
7319 ISP_SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
7323 * Just to be chatty here...
7326 switch (mbp->param[0]) {
7327 case MBOX_COMMAND_COMPLETE:
7329 case MBOX_INVALID_COMMAND:
7330 if (mbp->logval & MBLOGMASK(MBOX_COMMAND_COMPLETE)) {
7331 xname = "INVALID COMMAND";
7334 case MBOX_HOST_INTERFACE_ERROR:
7335 if (mbp->logval & MBLOGMASK(MBOX_HOST_INTERFACE_ERROR)) {
7336 xname = "HOST INTERFACE ERROR";
7339 case MBOX_TEST_FAILED:
7340 if (mbp->logval & MBLOGMASK(MBOX_TEST_FAILED)) {
7341 xname = "TEST FAILED";
7344 case MBOX_COMMAND_ERROR:
7345 if (mbp->logval & MBLOGMASK(MBOX_COMMAND_ERROR)) {
7346 xname = "COMMAND ERROR";
7349 case MBOX_COMMAND_PARAM_ERROR:
7350 if (mbp->logval & MBLOGMASK(MBOX_COMMAND_PARAM_ERROR)) {
7351 xname = "COMMAND PARAMETER ERROR";
7354 case MBOX_LOOP_ID_USED:
7355 if (mbp->logval & MBLOGMASK(MBOX_LOOP_ID_USED)) {
7356 xname = "LOOP ID ALREADY IN USE";
7359 case MBOX_PORT_ID_USED:
7360 if (mbp->logval & MBLOGMASK(MBOX_PORT_ID_USED)) {
7361 xname = "PORT ID ALREADY IN USE";
7364 case MBOX_ALL_IDS_USED:
7365 if (mbp->logval & MBLOGMASK(MBOX_ALL_IDS_USED)) {
7366 xname = "ALL LOOP IDS IN USE";
7369 case MBOX_REGS_BUSY:
7370 xname = "REGISTERS BUSY";
7376 ISP_SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
7381 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s)",
7387 isp_fw_state(ispsoftc_t *isp, int chan)
7391 fcparam *fcp = FCPARAM(isp, chan);
7393 MBSINIT(&mbs, MBOX_GET_FW_STATE, MBLOGALL, 0);
7394 isp_mboxcmd(isp, &mbs);
7395 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
7396 fcp->isp_fwstate = mbs.param[1];
7402 isp_spi_update(ispsoftc_t *isp, int chan)
7410 * There are no 'per-bus' settings for Fibre Channel.
7414 sdp = SDPARAM(isp, chan);
7417 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7418 uint16_t flags, period, offset;
7421 if (sdp->isp_devparam[tgt].dev_enable == 0) {
7422 sdp->isp_devparam[tgt].dev_update = 0;
7423 sdp->isp_devparam[tgt].dev_refresh = 0;
7424 isp_prt(isp, ISP_LOGDEBUG0,
7425 "skipping target %d bus %d update", tgt, chan);
7429 * If the goal is to update the status of the device,
7430 * take what's in goal_flags and try and set the device
7431 * toward that. Otherwise, if we're just refreshing the
7432 * current device state, get the current parameters.
7435 MBSINIT(&mbs, 0, MBLOGALL, 0);
7438 * Refresh overrides set
7440 if (sdp->isp_devparam[tgt].dev_refresh) {
7441 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
7443 } else if (sdp->isp_devparam[tgt].dev_update) {
7444 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
7447 * Make sure goal_flags has "Renegotiate on Error"
7448 * on and "Freeze Queue on Error" off.
7450 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
7451 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
7452 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
7455 * Insist that PARITY must be enabled
7456 * if SYNC or WIDE is enabled.
7458 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
7459 mbs.param[2] |= DPARM_PARITY;
7462 if (mbs.param[2] & DPARM_SYNC) {
7464 (sdp->isp_devparam[tgt].goal_offset << 8) |
7465 (sdp->isp_devparam[tgt].goal_period);
7468 * A command completion later that has
7469 * RQSTF_NEGOTIATION set can cause
7470 * the dev_refresh/announce cycle also.
7472 * Note: It is really important to update our current
7473 * flags with at least the state of TAG capabilities-
7474 * otherwise we might try and send a tagged command
7475 * when we have it all turned off. So change it here
7476 * to say that current already matches goal.
7478 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
7479 sdp->isp_devparam[tgt].actv_flags |=
7480 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
7481 isp_prt(isp, ISP_LOGDEBUG0,
7482 "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
7483 chan, tgt, mbs.param[2], mbs.param[3] >> 8,
7484 mbs.param[3] & 0xff);
7489 mbs.param[1] = (chan << 15) | (tgt << 8);
7490 isp_mboxcmd(isp, &mbs);
7491 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7495 sdp->sendmarker = 1;
7496 sdp->isp_devparam[tgt].dev_update = 0;
7497 sdp->isp_devparam[tgt].dev_refresh = 1;
7499 sdp->isp_devparam[tgt].dev_refresh = 0;
7500 flags = mbs.param[2];
7501 period = mbs.param[3] & 0xff;
7502 offset = mbs.param[3] >> 8;
7503 sdp->isp_devparam[tgt].actv_flags = flags;
7504 sdp->isp_devparam[tgt].actv_period = period;
7505 sdp->isp_devparam[tgt].actv_offset = offset;
7506 isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, chan, tgt);
7510 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7511 if (sdp->isp_devparam[tgt].dev_update ||
7512 sdp->isp_devparam[tgt].dev_refresh) {
7520 isp_setdfltsdparm(ispsoftc_t *isp)
7523 sdparam *sdp, *sdp1;
7525 sdp = SDPARAM(isp, 0);
7526 sdp->role = GET_DEFAULT_ROLE(isp, 0);
7527 if (IS_DUALBUS(isp)) {
7529 sdp1->role = GET_DEFAULT_ROLE(isp, 1);
7535 * Establish some default parameters.
7537 sdp->isp_cmd_dma_burst_enable = 0;
7538 sdp->isp_data_dma_burst_enabl = 1;
7539 sdp->isp_fifo_threshold = 0;
7540 sdp->isp_initiator_id = DEFAULT_IID(isp, 0);
7541 if (isp->isp_type >= ISP_HA_SCSI_1040) {
7542 sdp->isp_async_data_setup = 9;
7544 sdp->isp_async_data_setup = 6;
7546 sdp->isp_selection_timeout = 250;
7547 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
7548 sdp->isp_tag_aging = 8;
7549 sdp->isp_bus_reset_delay = 5;
7551 * Don't retry selection, busy or queue full automatically- reflect
7554 sdp->isp_retry_count = 0;
7555 sdp->isp_retry_delay = 0;
7557 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7558 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
7559 sdp->isp_devparam[tgt].dev_enable = 1;
7563 * The trick here is to establish a default for the default (honk!)
7564 * state (goal_flags). Then try and get the current status from
7565 * the card to fill in the current state. We don't, in fact, set
7566 * the default to the SAFE default state- that's not the goal state.
7568 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7570 sdp->isp_devparam[tgt].actv_offset = 0;
7571 sdp->isp_devparam[tgt].actv_period = 0;
7572 sdp->isp_devparam[tgt].actv_flags = 0;
7574 sdp->isp_devparam[tgt].goal_flags =
7575 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
7578 * We default to Wide/Fast for versions less than a 1040
7579 * (unless it's SBus).
7581 if (IS_ULTRA3(isp)) {
7582 off = ISP_80M_SYNCPARMS >> 8;
7583 per = ISP_80M_SYNCPARMS & 0xff;
7584 } else if (IS_ULTRA2(isp)) {
7585 off = ISP_40M_SYNCPARMS >> 8;
7586 per = ISP_40M_SYNCPARMS & 0xff;
7587 } else if (IS_1240(isp)) {
7588 off = ISP_20M_SYNCPARMS >> 8;
7589 per = ISP_20M_SYNCPARMS & 0xff;
7590 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
7591 isp->isp_type < ISP_HA_SCSI_1020A) ||
7592 (isp->isp_bustype == ISP_BT_PCI &&
7593 isp->isp_type < ISP_HA_SCSI_1040) ||
7594 (isp->isp_clock && isp->isp_clock < 60) ||
7595 (sdp->isp_ultramode == 0)) {
7596 off = ISP_10M_SYNCPARMS >> 8;
7597 per = ISP_10M_SYNCPARMS & 0xff;
7599 off = ISP_20M_SYNCPARMS_1040 >> 8;
7600 per = ISP_20M_SYNCPARMS_1040 & 0xff;
7602 sdp->isp_devparam[tgt].goal_offset =
7603 sdp->isp_devparam[tgt].nvrm_offset = off;
7604 sdp->isp_devparam[tgt].goal_period =
7605 sdp->isp_devparam[tgt].nvrm_period = per;
7610 * If we're a dual bus card, just copy the data over
7614 sdp1->isp_initiator_id = DEFAULT_IID(isp, 1);
7618 * If we've not been told to avoid reading NVRAM, try and read it.
7619 * If we're successful reading it, we can then return because NVRAM
7620 * will tell us what the desired settings are. Otherwise, we establish
7621 * some reasonable 'fake' nvram and goal defaults.
7623 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7626 if (isp_read_nvram(isp, 0) == 0) {
7627 if (IS_DUALBUS(isp)) {
7628 if (isp_read_nvram(isp, 1) == 0) {
7633 MBSINIT(&mbs, MBOX_GET_ACT_NEG_STATE, MBLOGNONE, 0);
7634 isp_mboxcmd(isp, &mbs);
7635 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7636 sdp->isp_req_ack_active_neg = 1;
7637 sdp->isp_data_line_active_neg = 1;
7639 sdp1->isp_req_ack_active_neg = 1;
7640 sdp1->isp_data_line_active_neg = 1;
7643 sdp->isp_req_ack_active_neg =
7644 (mbs.param[1] >> 4) & 0x1;
7645 sdp->isp_data_line_active_neg =
7646 (mbs.param[1] >> 5) & 0x1;
7648 sdp1->isp_req_ack_active_neg =
7649 (mbs.param[2] >> 4) & 0x1;
7650 sdp1->isp_data_line_active_neg =
7651 (mbs.param[2] >> 5) & 0x1;
7659 isp_setdfltfcparm(ispsoftc_t *isp, int chan)
7661 fcparam *fcp = FCPARAM(isp, chan);
7664 * Establish some default parameters.
7666 fcp->role = GET_DEFAULT_ROLE(isp, chan);
7667 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
7668 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
7669 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
7670 fcp->isp_loopid = DEFAULT_LOOPID(isp, chan);
7671 fcp->isp_wwnn_nvram = DEFAULT_NODEWWN(isp, chan);
7672 fcp->isp_wwpn_nvram = DEFAULT_PORTWWN(isp, chan);
7673 fcp->isp_fwoptions = 0;
7674 fcp->isp_lasthdl = NIL_HANDLE;
7677 fcp->isp_fwoptions |= ICB2400_OPT1_FAIRNESS;
7678 fcp->isp_fwoptions |= ICB2400_OPT1_HARD_ADDRESS;
7679 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX) {
7680 fcp->isp_fwoptions |= ICB2400_OPT1_FULL_DUPLEX;
7682 fcp->isp_fwoptions |= ICB2400_OPT1_BOTH_WWNS;
7684 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
7685 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
7686 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
7687 fcp->isp_fwoptions |= ICBOPT_FAST_POST;
7688 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX) {
7689 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
7692 * Make sure this is turned off now until we get
7693 * extended options from NVRAM
7695 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
7700 * Now try and read NVRAM unless told to not do so.
7701 * This will set fcparam's isp_wwnn_nvram && isp_wwpn_nvram.
7703 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7706 * Give a couple of tries at reading NVRAM.
7708 for (i = 0; i < 2; i++) {
7709 j = isp_read_nvram(isp, chan);
7715 isp->isp_confopts |= ISP_CFG_NONVRAM;
7719 fcp->isp_wwnn = ACTIVE_NODEWWN(isp, chan);
7720 fcp->isp_wwpn = ACTIVE_PORTWWN(isp, chan);
7721 isp_prt(isp, ISP_LOGCONFIG, "Chan %d 0x%08x%08x/0x%08x%08x Role %s",
7722 chan, (uint32_t) (fcp->isp_wwnn >> 32), (uint32_t) (fcp->isp_wwnn),
7723 (uint32_t) (fcp->isp_wwpn >> 32), (uint32_t) (fcp->isp_wwpn),
7724 isp_class3_roles[fcp->role]);
7728 * Re-initialize the ISP and complete all orphaned commands
7729 * with a 'botched' notice. The reset/init routines should
7730 * not disturb an already active list of commands.
7734 isp_reinit(ispsoftc_t *isp, int do_load_defaults)
7738 isp_reset(isp, do_load_defaults);
7740 if (isp->isp_state != ISP_RESETSTATE) {
7741 isp_prt(isp, ISP_LOGERR, "%s: cannot reset card", __func__);
7742 ISP_DISABLE_INTS(isp);
7748 if (isp->isp_state == ISP_INITSTATE) {
7749 isp->isp_state = ISP_RUNSTATE;
7752 if (isp->isp_state != ISP_RUNSTATE) {
7753 #ifndef ISP_TARGET_MODE
7754 isp_prt(isp, ISP_LOGWARN, "%s: not at runstate", __func__);
7756 ISP_DISABLE_INTS(isp);
7759 * If we're in ISP_ROLE_NONE, turn off the lasers.
7761 if (!IS_24XX(isp)) {
7762 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
7763 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
7764 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
7765 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
7766 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
7773 isp->isp_nactive = 0;
7775 isp_clear_commands(isp);
7777 for (i = 0; i < isp->isp_nchan; i++) {
7778 ISP_MARK_PORTDB(isp, i, -1);
7787 isp_read_nvram(ispsoftc_t *isp, int bus)
7790 uint8_t csum, minversion;
7792 uint8_t _x[ISP2400_NVRAM_SIZE];
7793 uint16_t _s[ISP2400_NVRAM_SIZE>>1];
7795 #define nvram_data _n._x
7796 #define nvram_words _n._s
7799 return (isp_read_nvram_2400(isp, nvram_data));
7800 } else if (IS_FC(isp)) {
7801 amt = ISP2100_NVRAM_SIZE;
7803 } else if (IS_ULTRA2(isp)) {
7804 amt = ISP1080_NVRAM_SIZE;
7807 amt = ISP_NVRAM_SIZE;
7811 for (i = 0; i < amt>>1; i++) {
7812 isp_rdnvram_word(isp, i, &nvram_words[i]);
7815 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
7816 nvram_data[2] != 'P') {
7817 if (isp->isp_bustype != ISP_BT_SBUS) {
7818 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
7819 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x",
7820 nvram_data[0], nvram_data[1], nvram_data[2]);
7826 for (csum = 0, i = 0; i < amt; i++) {
7827 csum += nvram_data[i];
7830 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
7835 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
7836 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
7837 ISP_NVRAM_VERSION(nvram_data));
7842 if (IS_ULTRA3(isp)) {
7843 isp_parse_nvram_12160(isp, bus, nvram_data);
7844 } else if (IS_1080(isp)) {
7845 isp_parse_nvram_1080(isp, bus, nvram_data);
7846 } else if (IS_1280(isp) || IS_1240(isp)) {
7847 isp_parse_nvram_1080(isp, bus, nvram_data);
7848 } else if (IS_SCSI(isp)) {
7849 isp_parse_nvram_1020(isp, nvram_data);
7851 isp_parse_nvram_2100(isp, nvram_data);
7861 isp_read_nvram_2400(ispsoftc_t *isp, uint8_t *nvram_data)
7864 uint32_t addr, csum, lwrds, *dptr;
7866 if (isp->isp_port) {
7867 addr = ISP2400_NVRAM_PORT1_ADDR;
7869 addr = ISP2400_NVRAM_PORT0_ADDR;
7872 dptr = (uint32_t *) nvram_data;
7873 for (lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
7874 isp_rd_2400_nvram(isp, addr++, dptr++);
7876 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
7877 nvram_data[2] != 'P') {
7878 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header (%x %x %x)",
7879 nvram_data[0], nvram_data[1], nvram_data[2]);
7883 dptr = (uint32_t *) nvram_data;
7884 for (csum = 0, lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
7886 ISP_IOXGET_32(isp, &dptr[lwrds], tmp);
7890 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
7894 isp_parse_nvram_2400(isp, nvram_data);
7900 isp_rdnvram_word(ispsoftc_t *isp, int wo, uint16_t *rp)
7903 uint16_t bit, rqst, junk;
7905 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
7907 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
7911 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
7912 if (IS_2312(isp) && isp->isp_port) {
7915 rqst = (ISP_NVRAM_READ << 8) | wo;
7917 } else if (IS_ULTRA2(isp)) {
7918 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
7919 rqst = (ISP_NVRAM_READ << 8) | wo;
7922 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
7923 rqst = (ISP_NVRAM_READ << 6) | wo;
7928 * Clock the word select request out...
7930 for (i = cbits; i >= 0; i--) {
7931 if ((rqst >> i) & 1) {
7932 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
7934 bit = BIU_NVRAM_SELECT;
7936 ISP_WRITE(isp, BIU_NVRAM, bit);
7938 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7939 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
7941 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7942 ISP_WRITE(isp, BIU_NVRAM, bit);
7944 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7947 * Now read the result back in (bits come back in MSB format).
7950 for (i = 0; i < 16; i++) {
7953 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
7955 rv = ISP_READ(isp, BIU_NVRAM);
7956 if (rv & BIU_NVRAM_DATAIN) {
7960 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
7962 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7964 ISP_WRITE(isp, BIU_NVRAM, 0);
7966 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7967 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
7971 isp_rd_2400_nvram(ispsoftc_t *isp, uint32_t addr, uint32_t *rp)
7974 uint32_t base = 0x7ffe0000;
7978 base = 0x7ff00000 | 0x48000;
7980 ISP_WRITE(isp, BIU2400_FLASH_ADDR, base | addr);
7981 for (loops = 0; loops < 5000; loops++) {
7983 tmp = ISP_READ(isp, BIU2400_FLASH_ADDR);
7984 if ((tmp & (1U << 31)) != 0) {
7988 if (tmp & (1U << 31)) {
7989 *rp = ISP_READ(isp, BIU2400_FLASH_DATA);
7990 ISP_SWIZZLE_NVRAM_LONG(isp, rp);
7997 isp_parse_nvram_1020(ispsoftc_t *isp, uint8_t *nvram_data)
7999 sdparam *sdp = SDPARAM(isp, 0);
8002 sdp->isp_fifo_threshold =
8003 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
8004 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
8006 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
8007 sdp->isp_initiator_id =
8008 ISP_NVRAM_INITIATOR_ID(nvram_data);
8010 sdp->isp_bus_reset_delay =
8011 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
8013 sdp->isp_retry_count =
8014 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
8016 sdp->isp_retry_delay =
8017 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
8019 sdp->isp_async_data_setup =
8020 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
8022 if (isp->isp_type >= ISP_HA_SCSI_1040) {
8023 if (sdp->isp_async_data_setup < 9) {
8024 sdp->isp_async_data_setup = 9;
8027 if (sdp->isp_async_data_setup != 6) {
8028 sdp->isp_async_data_setup = 6;
8032 sdp->isp_req_ack_active_neg =
8033 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
8035 sdp->isp_data_line_active_neg =
8036 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
8038 sdp->isp_data_dma_burst_enabl =
8039 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
8041 sdp->isp_cmd_dma_burst_enable =
8042 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
8044 sdp->isp_tag_aging =
8045 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
8047 sdp->isp_selection_timeout =
8048 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
8050 sdp->isp_max_queue_depth =
8051 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
8053 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
8055 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
8056 sdp->isp_devparam[tgt].dev_enable =
8057 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
8058 sdp->isp_devparam[tgt].exc_throttle =
8059 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
8060 sdp->isp_devparam[tgt].nvrm_offset =
8061 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
8062 sdp->isp_devparam[tgt].nvrm_period =
8063 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
8065 * We probably shouldn't lie about this, but it
8066 * it makes it much safer if we limit NVRAM values
8069 if (isp->isp_type < ISP_HA_SCSI_1040) {
8071 * If we're not ultra, we can't possibly
8072 * be a shorter period than this.
8074 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
8075 sdp->isp_devparam[tgt].nvrm_period = 0x19;
8077 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
8078 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
8081 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
8082 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
8085 sdp->isp_devparam[tgt].nvrm_flags = 0;
8086 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
8087 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
8088 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
8089 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
8090 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
8091 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
8092 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
8093 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
8094 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
8095 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
8096 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
8097 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
8098 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
8099 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
8100 sdp->isp_devparam[tgt].goal_offset =
8101 sdp->isp_devparam[tgt].nvrm_offset;
8102 sdp->isp_devparam[tgt].goal_period =
8103 sdp->isp_devparam[tgt].nvrm_period;
8104 sdp->isp_devparam[tgt].goal_flags =
8105 sdp->isp_devparam[tgt].nvrm_flags;
8110 isp_parse_nvram_1080(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
8112 sdparam *sdp = SDPARAM(isp, bus);
8115 sdp->isp_fifo_threshold =
8116 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
8118 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
8119 sdp->isp_initiator_id =
8120 ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
8122 sdp->isp_bus_reset_delay =
8123 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
8125 sdp->isp_retry_count =
8126 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
8128 sdp->isp_retry_delay =
8129 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
8131 sdp->isp_async_data_setup =
8132 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
8134 sdp->isp_req_ack_active_neg =
8135 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
8137 sdp->isp_data_line_active_neg =
8138 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
8140 sdp->isp_data_dma_burst_enabl =
8141 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
8143 sdp->isp_cmd_dma_burst_enable =
8144 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
8146 sdp->isp_selection_timeout =
8147 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
8149 sdp->isp_max_queue_depth =
8150 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
8152 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
8153 sdp->isp_devparam[tgt].dev_enable =
8154 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
8155 sdp->isp_devparam[tgt].exc_throttle =
8156 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
8157 sdp->isp_devparam[tgt].nvrm_offset =
8158 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
8159 sdp->isp_devparam[tgt].nvrm_period =
8160 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
8161 sdp->isp_devparam[tgt].nvrm_flags = 0;
8162 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
8163 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
8164 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
8165 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
8166 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
8167 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
8168 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
8169 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
8170 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
8171 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
8172 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
8173 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
8174 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
8175 sdp->isp_devparam[tgt].actv_flags = 0;
8176 sdp->isp_devparam[tgt].goal_offset =
8177 sdp->isp_devparam[tgt].nvrm_offset;
8178 sdp->isp_devparam[tgt].goal_period =
8179 sdp->isp_devparam[tgt].nvrm_period;
8180 sdp->isp_devparam[tgt].goal_flags =
8181 sdp->isp_devparam[tgt].nvrm_flags;
8186 isp_parse_nvram_12160(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
8188 sdparam *sdp = SDPARAM(isp, bus);
8191 sdp->isp_fifo_threshold =
8192 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
8194 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
8195 sdp->isp_initiator_id =
8196 ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
8198 sdp->isp_bus_reset_delay =
8199 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
8201 sdp->isp_retry_count =
8202 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
8204 sdp->isp_retry_delay =
8205 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
8207 sdp->isp_async_data_setup =
8208 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
8210 sdp->isp_req_ack_active_neg =
8211 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
8213 sdp->isp_data_line_active_neg =
8214 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
8216 sdp->isp_data_dma_burst_enabl =
8217 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
8219 sdp->isp_cmd_dma_burst_enable =
8220 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
8222 sdp->isp_selection_timeout =
8223 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
8225 sdp->isp_max_queue_depth =
8226 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
8228 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
8229 sdp->isp_devparam[tgt].dev_enable =
8230 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
8231 sdp->isp_devparam[tgt].exc_throttle =
8232 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
8233 sdp->isp_devparam[tgt].nvrm_offset =
8234 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
8235 sdp->isp_devparam[tgt].nvrm_period =
8236 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
8237 sdp->isp_devparam[tgt].nvrm_flags = 0;
8238 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
8239 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
8240 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
8241 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
8242 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
8243 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
8244 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
8245 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
8246 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
8247 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
8248 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
8249 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
8250 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
8251 sdp->isp_devparam[tgt].actv_flags = 0;
8252 sdp->isp_devparam[tgt].goal_offset =
8253 sdp->isp_devparam[tgt].nvrm_offset;
8254 sdp->isp_devparam[tgt].goal_period =
8255 sdp->isp_devparam[tgt].nvrm_period;
8256 sdp->isp_devparam[tgt].goal_flags =
8257 sdp->isp_devparam[tgt].nvrm_flags;
8262 isp_parse_nvram_2100(ispsoftc_t *isp, uint8_t *nvram_data)
8264 fcparam *fcp = FCPARAM(isp, 0);
8268 * There is NVRAM storage for both Port and Node entities-
8269 * but the Node entity appears to be unused on all the cards
8270 * I can find. However, we should account for this being set
8271 * at some point in the future.
8273 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
8274 * bits 48..60. In the case of the 2202, it appears that they do
8275 * use bit 48 to distinguish between the two instances on the card.
8276 * The 2204, which I've never seen, *probably* extends this method.
8278 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
8280 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
8281 (uint32_t) (wwn >> 32), (uint32_t) (wwn));
8282 if ((wwn >> 60) == 0) {
8283 wwn |= (((uint64_t) 2)<< 60);
8286 fcp->isp_wwpn_nvram = wwn;
8287 if (IS_2200(isp) || IS_23XX(isp)) {
8288 wwn = ISP2100_NVRAM_NODE_NAME(nvram_data);
8290 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
8291 (uint32_t) (wwn >> 32),
8293 if ((wwn >> 60) == 0) {
8294 wwn |= (((uint64_t) 2)<< 60);
8298 wwn &= ~((uint64_t) 0xfff << 48);
8300 fcp->isp_wwnn_nvram = wwn;
8302 fcp->isp_maxalloc = ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
8303 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
8304 DEFAULT_FRAMESIZE(isp) =
8305 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
8307 fcp->isp_retry_delay = ISP2100_NVRAM_RETRY_DELAY(nvram_data);
8308 fcp->isp_retry_count = ISP2100_NVRAM_RETRY_COUNT(nvram_data);
8309 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
8310 fcp->isp_loopid = ISP2100_NVRAM_HARDLOOPID(nvram_data);
8312 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
8313 DEFAULT_EXEC_THROTTLE(isp) =
8314 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
8316 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
8317 isp_prt(isp, ISP_LOGDEBUG0,
8318 "NVRAM 0x%08x%08x 0x%08x%08x maxalloc %d maxframelen %d",
8319 (uint32_t) (fcp->isp_wwnn_nvram >> 32),
8320 (uint32_t) fcp->isp_wwnn_nvram,
8321 (uint32_t) (fcp->isp_wwpn_nvram >> 32),
8322 (uint32_t) fcp->isp_wwpn_nvram,
8323 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data),
8324 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data));
8325 isp_prt(isp, ISP_LOGDEBUG0,
8326 "execthrottle %d fwoptions 0x%x hardloop %d tov %d",
8327 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
8328 ISP2100_NVRAM_OPTIONS(nvram_data),
8329 ISP2100_NVRAM_HARDLOOPID(nvram_data),
8330 ISP2100_NVRAM_TOV(nvram_data));
8331 fcp->isp_xfwoptions = ISP2100_XFW_OPTIONS(nvram_data);
8332 fcp->isp_zfwoptions = ISP2100_ZFW_OPTIONS(nvram_data);
8333 isp_prt(isp, ISP_LOGDEBUG0,
8334 "xfwoptions 0x%x zfw options 0x%x",
8335 ISP2100_XFW_OPTIONS(nvram_data), ISP2100_ZFW_OPTIONS(nvram_data));
8339 isp_parse_nvram_2400(ispsoftc_t *isp, uint8_t *nvram_data)
8341 fcparam *fcp = FCPARAM(isp, 0);
8344 isp_prt(isp, ISP_LOGDEBUG0,
8345 "NVRAM 0x%08x%08x 0x%08x%08x exchg_cnt %d maxframelen %d",
8346 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data) >> 32),
8347 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data)),
8348 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data) >> 32),
8349 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data)),
8350 ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data),
8351 ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data));
8352 isp_prt(isp, ISP_LOGDEBUG0,
8353 "NVRAM execthr %d loopid %d fwopt1 0x%x fwopt2 0x%x fwopt3 0x%x",
8354 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data),
8355 ISP2400_NVRAM_HARDLOOPID(nvram_data),
8356 ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data),
8357 ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data),
8358 ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data));
8360 wwn = ISP2400_NVRAM_PORT_NAME(nvram_data);
8362 if ((wwn >> 60) != 2 && (wwn >> 60) != 5) {
8366 fcp->isp_wwpn_nvram = wwn;
8368 wwn = ISP2400_NVRAM_NODE_NAME(nvram_data);
8370 if ((wwn >> 60) != 2 && (wwn >> 60) != 5) {
8374 fcp->isp_wwnn_nvram = wwn;
8376 if (ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data)) {
8377 fcp->isp_maxalloc = ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data);
8379 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
8380 DEFAULT_FRAMESIZE(isp) =
8381 ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data);
8383 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
8384 fcp->isp_loopid = ISP2400_NVRAM_HARDLOOPID(nvram_data);
8386 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
8387 DEFAULT_EXEC_THROTTLE(isp) =
8388 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data);
8390 fcp->isp_fwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data);
8391 fcp->isp_xfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data);
8392 fcp->isp_zfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data);