2 * Copyright (c) 1997-2009 by Matthew Jacob
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * Machine and OS Independent (well, as best as possible)
31 * code for the Qlogic ISP SCSI and FC-SCSI adapters.
35 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
36 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
37 * ideas dredged from the Solaris driver.
41 * Include header file appropriate for platform we're building on.
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD$");
46 #include <dev/ic/isp_netbsd.h>
49 #include <sys/cdefs.h>
50 __FBSDID("$FreeBSD$");
51 #include <dev/isp/isp_freebsd.h>
54 #include <dev/ic/isp_openbsd.h>
57 #include "isp_linux.h"
60 #include "isp_solaris.h"
66 #define MBOX_DELAY_COUNT 1000000 / 100
67 #define ISP_MARK_PORTDB(a, b, c) \
68 isp_prt(isp, ISP_LOGSANCFG, \
69 "Chan %d ISP_MARK_PORTDB@LINE %d", b, __LINE__); \
70 isp_mark_portdb(a, b, c)
75 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)";
76 static const char notresp[] = "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
77 static const char xact1[] = "HBA attempted queued transaction with disconnect not set for %d.%d.%d";
78 static const char xact2[] = "HBA attempted queued transaction to target routine %d on target %d bus %d";
79 static const char xact3[] = "HBA attempted queued cmd for %d.%d.%d when queueing disabled";
80 static const char pskip[] = "SCSI phase skipped for target %d.%d.%d";
81 static const char topology[] = "Chan %d WWPN 0x%08x%08x PortID 0x%06x N-Port Handle %d, Connection '%s'";
82 static const char finmsg[] = "%d.%d.%d: FIN dl%d resid %ld STS 0x%x SKEY %c XS_ERR=0x%x";
83 static const char sc4[] = "NVRAM";
84 static const char bun[] = "bad underrun for %d.%d (count %d, resid %d, status %s)";
85 static const char lipd[] = "Chan %d LIP destroyed %d active commands";
86 static const char sacq[] = "unable to acquire scratch area";
88 static const uint8_t alpa_map[] = {
89 0xef, 0xe8, 0xe4, 0xe2, 0xe1, 0xe0, 0xdc, 0xda,
90 0xd9, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xce,
91 0xcd, 0xcc, 0xcb, 0xca, 0xc9, 0xc7, 0xc6, 0xc5,
92 0xc3, 0xbc, 0xba, 0xb9, 0xb6, 0xb5, 0xb4, 0xb3,
93 0xb2, 0xb1, 0xae, 0xad, 0xac, 0xab, 0xaa, 0xa9,
94 0xa7, 0xa6, 0xa5, 0xa3, 0x9f, 0x9e, 0x9d, 0x9b,
95 0x98, 0x97, 0x90, 0x8f, 0x88, 0x84, 0x82, 0x81,
96 0x80, 0x7c, 0x7a, 0x79, 0x76, 0x75, 0x74, 0x73,
97 0x72, 0x71, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x69,
98 0x67, 0x66, 0x65, 0x63, 0x5c, 0x5a, 0x59, 0x56,
99 0x55, 0x54, 0x53, 0x52, 0x51, 0x4e, 0x4d, 0x4c,
100 0x4b, 0x4a, 0x49, 0x47, 0x46, 0x45, 0x43, 0x3c,
101 0x3a, 0x39, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31,
102 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x27, 0x26,
103 0x25, 0x23, 0x1f, 0x1e, 0x1d, 0x1b, 0x18, 0x17,
104 0x10, 0x0f, 0x08, 0x04, 0x02, 0x01, 0x00
108 * Local function prototypes.
110 static int isp_parse_async(ispsoftc_t *, uint16_t);
111 static int isp_parse_async_fc(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 *, uint32_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 command 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 LVD transitions for ULTRA2 or better and other features
1340 * Now that we have 32 bit handles, don't do any fast posting
1341 * any more. For Ultra2/Ultra3 cards, we can turn on 32 bit RIO
1342 * operation or use fast posting. To be conservative, we'll only
1343 * do this for Ultra3 cards now because the other cards are so
1344 * rare for this author to find and test with.
1347 MBSINIT(&mbs, MBOX_SET_FW_FEATURES, MBLOGALL, 0);
1349 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1352 mbs.param[1] |= FW_FEATURE_FAST_POST;
1355 mbs.param[1] |= FW_FEATURE_RIO_32BIT;
1357 if (mbs.param[1] != 0) {
1358 uint16_t sfeat = mbs.param[1];
1359 isp_mboxcmd(isp, &mbs);
1360 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1361 isp_prt(isp, ISP_LOGINFO,
1362 "Enabled FW features (0x%x)", sfeat);
1366 isp->isp_state = ISP_INITSTATE;
1370 isp_scsi_channel_init(ispsoftc_t *isp, int chan)
1376 sdp = SDPARAM(isp, chan);
1379 * Set (possibly new) Initiator ID.
1381 MBSINIT(&mbs, MBOX_SET_INIT_SCSI_ID, MBLOGALL, 0);
1382 mbs.param[1] = (chan << 7) | sdp->isp_initiator_id;
1383 isp_mboxcmd(isp, &mbs);
1384 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1387 isp_prt(isp, ISP_LOGINFO, "Chan %d Initiator ID is %d",
1388 chan, sdp->isp_initiator_id);
1392 * Set current per-target parameters to an initial safe minimum.
1394 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1398 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1401 #ifndef ISP_TARGET_MODE
1402 sdf = sdp->isp_devparam[tgt].goal_flags;
1403 sdf &= DPARM_SAFE_DFLT;
1405 * It is not quite clear when this changed over so that
1406 * we could force narrow and async for 1000/1020 cards,
1407 * but assume that this is only the case for loaded
1410 if (isp->isp_loaded_fw) {
1411 sdf |= DPARM_NARROW | DPARM_ASYNC;
1415 * The !$*!)$!$)* f/w uses the same index into some
1416 * internal table to decide how to respond to negotiations,
1417 * so if we've said "let's be safe" for ID X, and ID X
1418 * selects *us*, the negotiations will back to 'safe'
1419 * (as in narrow/async). What the f/w *should* do is
1420 * use the initiator id settings to decide how to respond.
1422 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1424 MBSINIT(&mbs, MBOX_SET_TARGET_PARAMS, MBLOGNONE, 0);
1425 mbs.param[1] = (chan << 15) | (tgt << 8);
1427 if ((sdf & DPARM_SYNC) == 0) {
1431 (sdp->isp_devparam[tgt].goal_offset << 8) |
1432 (sdp->isp_devparam[tgt].goal_period);
1434 isp_prt(isp, ISP_LOGDEBUG0,
1435 "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1436 chan, tgt, mbs.param[2], mbs.param[3] >> 8,
1437 mbs.param[3] & 0xff);
1438 isp_mboxcmd(isp, &mbs);
1439 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1440 sdf = DPARM_SAFE_DFLT;
1441 MBSINIT(&mbs, MBOX_SET_TARGET_PARAMS, MBLOGALL, 0);
1442 mbs.param[1] = (tgt << 8) | (chan << 15);
1445 isp_mboxcmd(isp, &mbs);
1446 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1452 * We don't update any information directly from the f/w
1453 * because we need to run at least one command to cause a
1454 * new state to be latched up. So, we just assume that we
1455 * converge to the values we just had set.
1457 * Ensure that we don't believe tagged queuing is enabled yet.
1458 * It turns out that sometimes the ISP just ignores our
1459 * attempts to set parameters for devices that it hasn't
1462 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1463 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1464 MBSINIT(&mbs, MBOX_SET_DEV_QUEUE_PARAMS, MBLOGALL, 0);
1465 mbs.param[1] = (chan << 15) | (tgt << 8) | lun;
1466 mbs.param[2] = sdp->isp_max_queue_depth;
1467 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1468 isp_mboxcmd(isp, &mbs);
1469 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1474 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1475 if (sdp->isp_devparam[tgt].dev_refresh) {
1476 sdp->sendmarker = 1;
1484 * Fibre Channel specific initialization.
1487 isp_fibre_init(ispsoftc_t *isp)
1490 isp_icb_t local, *icbp = &local;
1495 * We only support one channel on non-24XX cards
1497 fcp = FCPARAM(isp, 0);
1498 if (fcp->role == ISP_ROLE_NONE) {
1499 isp->isp_state = ISP_INITSTATE;
1503 ISP_MEMZERO(icbp, sizeof (*icbp));
1504 icbp->icb_version = ICB_VERSION1;
1505 icbp->icb_fwoptions = fcp->isp_fwoptions;
1508 * Firmware Options are either retrieved from NVRAM or
1509 * are patched elsewhere. We check them for sanity here
1510 * and make changes based on board revision, but otherwise
1511 * let others decide policy.
1515 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1517 if (IS_2100(isp) && isp->isp_revision < 5) {
1518 icbp->icb_fwoptions &= ~ICBOPT_FAIRNESS;
1522 * We have to use FULL LOGIN even though it resets the loop too much
1523 * because otherwise port database entries don't get updated after
1524 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1526 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1527 icbp->icb_fwoptions |= ICBOPT_FULL_LOGIN;
1531 * Insist on Port Database Update Async notifications
1533 icbp->icb_fwoptions |= ICBOPT_PDBCHANGE_AE;
1536 * Make sure that target role reflects into fwoptions.
1538 if (fcp->role & ISP_ROLE_TARGET) {
1539 icbp->icb_fwoptions |= ICBOPT_TGT_ENABLE;
1541 icbp->icb_fwoptions &= ~ICBOPT_TGT_ENABLE;
1544 if (fcp->role & ISP_ROLE_INITIATOR) {
1545 icbp->icb_fwoptions &= ~ICBOPT_INI_DISABLE;
1547 icbp->icb_fwoptions |= ICBOPT_INI_DISABLE;
1550 icbp->icb_maxfrmlen = DEFAULT_FRAMESIZE(isp);
1551 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN || icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1552 isp_prt(isp, ISP_LOGERR, "bad frame length (%d) from NVRAM- using %d", DEFAULT_FRAMESIZE(isp), ICB_DFLT_FRMLEN);
1553 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1555 icbp->icb_maxalloc = fcp->isp_maxalloc;
1556 if (icbp->icb_maxalloc < 1) {
1557 isp_prt(isp, ISP_LOGERR, "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1558 icbp->icb_maxalloc = 16;
1560 icbp->icb_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
1561 if (icbp->icb_execthrottle < 1) {
1562 isp_prt(isp, ISP_LOGERR, "bad execution throttle of %d- using %d", DEFAULT_EXEC_THROTTLE(isp), ICB_DFLT_THROTTLE);
1563 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1565 icbp->icb_retry_delay = fcp->isp_retry_delay;
1566 icbp->icb_retry_count = fcp->isp_retry_count;
1567 icbp->icb_hardaddr = fcp->isp_loopid;
1568 ownloopid = (isp->isp_confopts & ISP_CFG_OWNLOOPID) != 0;
1569 if (icbp->icb_hardaddr >= LOCAL_LOOP_LIM) {
1570 icbp->icb_hardaddr = 0;
1575 * Our life seems so much better with 2200s and later with
1576 * the latest f/w if we set Hard Address.
1578 if (ownloopid || ISP_FW_NEWER_THAN(isp, 2, 2, 5)) {
1579 icbp->icb_fwoptions |= ICBOPT_HARD_ADDRESS;
1583 * Right now we just set extended options to prefer point-to-point
1584 * over loop based upon some soft config options.
1586 * NB: for the 2300, ICBOPT_EXTENDED is required.
1588 if (IS_2200(isp) || IS_23XX(isp)) {
1589 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1591 * Prefer or force Point-To-Point instead Loop?
1593 switch (isp->isp_confopts & ISP_CFG_PORT_PREF) {
1595 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1597 case ISP_CFG_NPORT_ONLY:
1598 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1600 case ISP_CFG_LPORT_ONLY:
1601 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1604 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1609 * We can't have Fast Posting any more- we now
1610 * have 32 bit handles.
1612 * RIO seemed to have to much breakage.
1614 * Just opt for safety.
1616 icbp->icb_xfwoptions &= ~ICBXOPT_RIO_16BIT;
1617 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1620 * QLogic recommends that FAST Posting be turned
1621 * off for 23XX cards and instead allow the HBA
1622 * to write response queue entries and interrupt
1623 * after a delay (ZIO).
1625 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1626 if ((fcp->isp_xfwoptions & ICBXOPT_TIMER_MASK) == ICBXOPT_ZIO) {
1627 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1628 icbp->icb_idelaytimer = 10;
1630 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1631 icbp->icb_zfwoptions |= ICBZOPT_RATE_ONEGB;
1632 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1633 icbp->icb_zfwoptions |= ICBZOPT_RATE_TWOGB;
1635 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1637 if (fcp->isp_zfwoptions & ICBZOPT_50_OHM) {
1638 icbp->icb_zfwoptions |= ICBZOPT_50_OHM;
1645 * For 22XX > 2.1.26 && 23XX, set some options.
1647 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1648 MBSINIT(&mbs, MBOX_SET_FIRMWARE_OPTIONS, MBLOGALL, 0);
1649 mbs.param[1] = IFCOPT1_DISF7SWTCH|IFCOPT1_LIPASYNC|IFCOPT1_LIPF8;
1652 if (ISP_FW_NEWER_THAN(isp, 3, 16, 0)) {
1653 mbs.param[1] |= IFCOPT1_EQFQASYNC|IFCOPT1_CTIO_RETRY;
1654 if (fcp->role & ISP_ROLE_TARGET) {
1655 mbs.param[3] = IFCOPT3_NOPRLI;
1658 isp_mboxcmd(isp, &mbs);
1659 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1663 icbp->icb_logintime = ICB_LOGIN_TOV;
1664 icbp->icb_lunetimeout = ICB_LUN_ENABLE_TOV;
1666 if (fcp->isp_wwnn && fcp->isp_wwpn && (fcp->isp_wwnn >> 60) != 2) {
1667 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1668 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, fcp->isp_wwnn);
1669 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1670 isp_prt(isp, ISP_LOGDEBUG1,
1671 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1672 ((uint32_t) (fcp->isp_wwnn >> 32)),
1673 ((uint32_t) (fcp->isp_wwnn)),
1674 ((uint32_t) (fcp->isp_wwpn >> 32)),
1675 ((uint32_t) (fcp->isp_wwpn)));
1676 } else if (fcp->isp_wwpn) {
1677 icbp->icb_fwoptions &= ~ICBOPT_BOTH_WWNS;
1678 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1679 isp_prt(isp, ISP_LOGDEBUG1,
1680 "Setting ICB Port 0x%08x%08x",
1681 ((uint32_t) (fcp->isp_wwpn >> 32)),
1682 ((uint32_t) (fcp->isp_wwpn)));
1684 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
1687 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1688 if (icbp->icb_rqstqlen < 1) {
1689 isp_prt(isp, ISP_LOGERR, "bad request queue length");
1691 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1692 if (icbp->icb_rsltqlen < 1) {
1693 isp_prt(isp, ISP_LOGERR, "bad result queue length");
1695 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1696 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1697 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1698 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1699 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1700 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1701 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1702 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1704 if (FC_SCRATCH_ACQUIRE(isp, 0)) {
1705 isp_prt(isp, ISP_LOGERR, sacq);
1708 isp_prt(isp, ISP_LOGDEBUG0,
1709 "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1710 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1712 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1717 MBSINIT(&mbs, MBOX_INIT_FIRMWARE, MBLOGALL, 30000000);
1718 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1719 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1720 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1721 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1722 mbs.logval = MBLOGALL;
1723 isp_prt(isp, ISP_LOGDEBUG0, "INIT F/W from %p (%08x%08x)",
1724 fcp->isp_scratch, (uint32_t) ((uint64_t)fcp->isp_scdma >> 32),
1725 (uint32_t) fcp->isp_scdma);
1726 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp));
1727 isp_mboxcmd(isp, &mbs);
1728 FC_SCRATCH_RELEASE(isp, 0);
1729 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1730 isp_print_bytes(isp, "isp_fibre_init", sizeof (*icbp), icbp);
1733 isp->isp_reqidx = 0;
1734 isp->isp_reqodx = 0;
1735 isp->isp_residx = 0;
1738 * Whatever happens, we're now committed to being here.
1740 isp->isp_state = ISP_INITSTATE;
1744 isp_fibre_init_2400(ispsoftc_t *isp)
1747 isp_icb_2400_t local, *icbp = &local;
1752 * Check to see whether all channels have *some* kind of role
1754 for (chan = 0; chan < isp->isp_nchan; chan++) {
1755 fcp = FCPARAM(isp, chan);
1756 if (fcp->role != ISP_ROLE_NONE) {
1760 if (chan == isp->isp_nchan) {
1761 isp_prt(isp, ISP_LOGDEBUG0, "all %d channels with role 'none'", chan);
1762 isp->isp_state = ISP_INITSTATE;
1767 * Start with channel 0.
1769 fcp = FCPARAM(isp, 0);
1772 * Turn on LIP F8 async event (1)
1774 MBSINIT(&mbs, MBOX_SET_FIRMWARE_OPTIONS, MBLOGALL, 0);
1776 isp_mboxcmd(isp, &mbs);
1777 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1781 ISP_MEMZERO(icbp, sizeof (*icbp));
1782 icbp->icb_fwoptions1 = fcp->isp_fwoptions;
1783 if (fcp->role & ISP_ROLE_TARGET) {
1784 icbp->icb_fwoptions1 |= ICB2400_OPT1_TGT_ENABLE;
1786 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_TGT_ENABLE;
1789 if (fcp->role & ISP_ROLE_INITIATOR) {
1790 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_INI_DISABLE;
1792 icbp->icb_fwoptions1 |= ICB2400_OPT1_INI_DISABLE;
1795 icbp->icb_version = ICB_VERSION1;
1796 icbp->icb_maxfrmlen = DEFAULT_FRAMESIZE(isp);
1797 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN || icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1798 isp_prt(isp, ISP_LOGERR, "bad frame length (%d) from NVRAM- using %d", DEFAULT_FRAMESIZE(isp), ICB_DFLT_FRMLEN);
1799 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1802 icbp->icb_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
1803 if (icbp->icb_execthrottle < 1) {
1804 isp_prt(isp, ISP_LOGERR, "bad execution throttle of %d- using %d", DEFAULT_EXEC_THROTTLE(isp), ICB_DFLT_THROTTLE);
1805 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1808 if (icbp->icb_fwoptions1 & ICB2400_OPT1_TGT_ENABLE) {
1810 * Get current resource count
1812 MBSINIT(&mbs, MBOX_GET_RESOURCE_COUNT, MBLOGALL, 0);
1814 isp_mboxcmd(isp, &mbs);
1815 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1818 icbp->icb_xchgcnt = mbs.param[3];
1822 icbp->icb_hardaddr = fcp->isp_loopid;
1823 if (icbp->icb_hardaddr >= LOCAL_LOOP_LIM) {
1824 icbp->icb_hardaddr = 0;
1830 icbp->icb_fwoptions1 |= ICB2400_OPT1_HARD_ADDRESS;
1832 icbp->icb_fwoptions2 = fcp->isp_xfwoptions;
1833 switch (isp->isp_confopts & ISP_CFG_PORT_PREF) {
1837 * XXX: This causes the f/w to crash.
1839 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
1840 icbp->icb_fwoptions2 |= ICB2400_OPT2_PTP_2_LOOP;
1843 case ISP_CFG_NPORT_ONLY:
1844 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
1845 icbp->icb_fwoptions2 |= ICB2400_OPT2_PTP_ONLY;
1847 case ISP_CFG_LPORT_ONLY:
1848 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
1849 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_ONLY;
1852 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
1853 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_2_PTP;
1857 /* force this on for now */
1858 icbp->icb_fwoptions2 |= ICB2400_OPT2_ZIO;
1860 switch (icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK) {
1861 case ICB2400_OPT2_ZIO:
1862 case ICB2400_OPT2_ZIO1:
1863 icbp->icb_idelaytimer = 0;
1868 isp_prt(isp, ISP_LOGWARN, "bad value %x in fwopt2 timer field", icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK);
1869 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TIMER_MASK;
1874 * We don't support FCTAPE, so clear it.
1876 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_FCTAPE;
1878 icbp->icb_fwoptions3 = fcp->isp_zfwoptions;
1879 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_AUTO;
1880 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1881 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_ONEGB;
1882 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1883 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_TWOGB;
1884 } else if (isp->isp_confopts & ISP_CFG_FOURGB) {
1885 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_FOURGB;
1887 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_AUTO;
1890 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
1891 icbp->icb_fwoptions3 |= ICB2400_OPT3_SOFTID;
1893 icbp->icb_logintime = ICB_LOGIN_TOV;
1895 if (fcp->isp_wwnn && fcp->isp_wwpn && (fcp->isp_wwnn >> 60) != 2) {
1896 icbp->icb_fwoptions1 |= ICB2400_OPT1_BOTH_WWNS;
1897 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1898 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, fcp->isp_wwnn);
1899 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)),
1900 ((uint32_t) (fcp->isp_wwpn >> 32)), ((uint32_t) (fcp->isp_wwpn)));
1901 } else if (fcp->isp_wwpn) {
1902 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_BOTH_WWNS;
1903 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1904 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)));
1906 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
1909 icbp->icb_retry_count = fcp->isp_retry_count;
1911 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1912 if (icbp->icb_rqstqlen < 8) {
1913 isp_prt(isp, ISP_LOGERR, "bad request queue length %d", icbp->icb_rqstqlen);
1916 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1917 if (icbp->icb_rsltqlen < 8) {
1918 isp_prt(isp, ISP_LOGERR, "bad result queue length %d",
1919 icbp->icb_rsltqlen);
1922 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1923 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1924 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1925 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1927 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1928 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1929 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1930 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1932 #ifdef ISP_TARGET_MODE
1933 /* unconditionally set up the ATIO queue if we support target mode */
1934 icbp->icb_atioqlen = RESULT_QUEUE_LEN(isp);
1935 if (icbp->icb_atioqlen < 8) {
1936 isp_prt(isp, ISP_LOGERR, "bad ATIO queue length %d", icbp->icb_atioqlen);
1939 icbp->icb_atioqaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_atioq_dma);
1940 icbp->icb_atioqaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_atioq_dma);
1941 icbp->icb_atioqaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_atioq_dma);
1942 icbp->icb_atioqaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_atioq_dma);
1943 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),
1944 DMA_WD1(isp->isp_atioq_dma), DMA_WD0(isp->isp_atioq_dma));
1947 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);
1949 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),
1950 DMA_WD1(isp->isp_rquest_dma), DMA_WD0(isp->isp_rquest_dma), DMA_WD3(isp->isp_result_dma), DMA_WD2(isp->isp_result_dma),
1951 DMA_WD1(isp->isp_result_dma), DMA_WD0(isp->isp_result_dma));
1953 if (isp->isp_dblev & ISP_LOGDEBUG1) {
1954 isp_print_bytes(isp, "isp_fibre_init_2400", sizeof (*icbp), icbp);
1957 if (FC_SCRATCH_ACQUIRE(isp, 0)) {
1958 isp_prt(isp, ISP_LOGERR, sacq);
1961 ISP_MEMZERO(fcp->isp_scratch, ISP_FC_SCRLEN);
1962 isp_put_icb_2400(isp, icbp, fcp->isp_scratch);
1965 * Now fill in information about any additional channels
1967 if (isp->isp_nchan > 1) {
1968 isp_icb_2400_vpinfo_t vpinfo, *vdst;
1969 vp_port_info_t pi, *pdst;
1973 vpinfo.vp_count = isp->isp_nchan - 1;
1974 vpinfo.vp_global_options = 0;
1975 off = fcp->isp_scratch;
1976 off += ICB2400_VPINFO_OFF;
1977 vdst = (isp_icb_2400_vpinfo_t *) off;
1978 isp_put_icb_2400_vpinfo(isp, &vpinfo, vdst);
1979 amt = ICB2400_VPINFO_OFF + sizeof (isp_icb_2400_vpinfo_t);
1980 for (chan = 1; chan < isp->isp_nchan; chan++) {
1983 ISP_MEMZERO(&pi, sizeof (pi));
1984 fcp2 = FCPARAM(isp, chan);
1985 if (fcp2->role != ISP_ROLE_NONE) {
1986 pi.vp_port_options = ICB2400_VPOPT_ENABLED;
1987 if (fcp2->role & ISP_ROLE_INITIATOR) {
1988 pi.vp_port_options |= ICB2400_VPOPT_INI_ENABLE;
1990 if ((fcp2->role & ISP_ROLE_TARGET) == 0) {
1991 pi.vp_port_options |= ICB2400_VPOPT_TGT_DISABLE;
1993 MAKE_NODE_NAME_FROM_WWN(pi.vp_port_portname, fcp2->isp_wwpn);
1994 MAKE_NODE_NAME_FROM_WWN(pi.vp_port_nodename, fcp2->isp_wwnn);
1996 off = fcp->isp_scratch;
1997 off += ICB2400_VPINFO_PORT_OFF(chan);
1998 pdst = (vp_port_info_t *) off;
1999 isp_put_vp_port_info(isp, &pi, pdst);
2000 amt += ICB2400_VPOPT_WRITE_SIZE;
2007 MBSINIT(&mbs, 0, MBLOGALL, 30000000);
2008 if (isp->isp_nchan > 1) {
2009 mbs.param[0] = MBOX_INIT_FIRMWARE_MULTI_ID;
2011 mbs.param[0] = MBOX_INIT_FIRMWARE;
2013 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2014 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2015 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2016 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2017 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));
2018 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp));
2019 isp_mboxcmd(isp, &mbs);
2020 FC_SCRATCH_RELEASE(isp, 0);
2022 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2025 isp->isp_reqidx = 0;
2026 isp->isp_reqodx = 0;
2027 isp->isp_residx = 0;
2030 * Whatever happens, we're now committed to being here.
2032 isp->isp_state = ISP_INITSTATE;
2036 isp_mark_portdb(ispsoftc_t *isp, int chan, int disposition)
2038 fcparam *fcp = FCPARAM(isp, chan);
2041 if (chan < 0 || chan >= isp->isp_nchan) {
2042 isp_prt(isp, ISP_LOGWARN, "isp_mark_portdb: bad channel %d", chan);
2045 for (i = 0; i < MAX_FC_TARG; i++) {
2046 if (fcp->portdb[i].target_mode) {
2047 if (disposition < 0) {
2048 isp_prt(isp, ISP_LOGTINFO, "isp_mark_portdb: Chan %d zeroing handle 0x" "%04x port 0x%06x", chan,
2049 fcp->portdb[i].handle, fcp->portdb[i].portid);
2050 ISP_MEMZERO(&fcp->portdb[i], sizeof (fcportdb_t));
2054 if (disposition == 0) {
2055 ISP_MEMZERO(&fcp->portdb[i], sizeof (fcportdb_t));
2057 switch (fcp->portdb[i].state) {
2058 case FC_PORTDB_STATE_CHANGED:
2059 case FC_PORTDB_STATE_PENDING_VALID:
2060 case FC_PORTDB_STATE_VALID:
2061 case FC_PORTDB_STATE_PROBATIONAL:
2062 fcp->portdb[i].state = FC_PORTDB_STATE_PROBATIONAL;
2064 case FC_PORTDB_STATE_ZOMBIE:
2066 case FC_PORTDB_STATE_NIL:
2068 ISP_MEMZERO(&fcp->portdb[i], sizeof (fcportdb_t));
2069 fcp->portdb[i].state = FC_PORTDB_STATE_NIL;
2077 * Perform an IOCB PLOGI or LOGO via EXECUTE IOCB A64 for 24XX cards
2078 * or via FABRIC LOGIN/FABRIC LOGOUT for other cards.
2081 isp_plogx(ispsoftc_t *isp, int chan, uint16_t handle, uint32_t portid, int flags, int gs)
2084 uint8_t q[QENTRY_LEN];
2088 uint32_t sst, parm1;
2093 if (!IS_24XX(isp)) {
2094 int action = flags & PLOGX_FLG_CMD_MASK;
2095 if (action == PLOGX_FLG_CMD_PLOGI) {
2096 return (isp_port_login(isp, handle, portid));
2097 } else if (action == PLOGX_FLG_CMD_LOGO) {
2098 return (isp_port_logout(isp, handle, portid));
2100 return (MBOX_INVALID_COMMAND);
2104 ISP_MEMZERO(q, QENTRY_LEN);
2105 plp = (isp_plogx_t *) q;
2106 plp->plogx_header.rqs_entry_count = 1;
2107 plp->plogx_header.rqs_entry_type = RQSTYPE_LOGIN;
2108 plp->plogx_handle = 0xffffffff;
2109 plp->plogx_nphdl = handle;
2110 plp->plogx_vphdl = chan;
2111 plp->plogx_portlo = portid;
2112 plp->plogx_rspsz_porthi = (portid >> 16) & 0xff;
2113 plp->plogx_flags = flags;
2115 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2116 isp_print_bytes(isp, "IOCB LOGX", QENTRY_LEN, plp);
2120 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
2121 isp_prt(isp, ISP_LOGERR, sacq);
2125 fcp = FCPARAM(isp, chan);
2126 scp = fcp->isp_scratch;
2127 isp_put_plogx(isp, plp, (isp_plogx_t *) scp);
2129 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 500000);
2130 mbs.param[1] = QENTRY_LEN;
2131 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2132 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2133 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2134 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2135 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, QENTRY_LEN);
2136 isp_mboxcmd(isp, &mbs);
2137 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2138 rval = mbs.param[0];
2141 MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN, QENTRY_LEN);
2143 isp_get_plogx(isp, (isp_plogx_t *) scp, plp);
2144 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2145 isp_print_bytes(isp, "IOCB LOGX response", QENTRY_LEN, plp);
2148 if (plp->plogx_status == PLOGX_STATUS_OK) {
2151 } else if (plp->plogx_status != PLOGX_STATUS_IOCBERR) {
2152 isp_prt(isp, ISP_LOGWARN,
2153 "status 0x%x on port login IOCB chanel %d",
2154 plp->plogx_status, chan);
2159 sst = plp->plogx_ioparm[0].lo16 | (plp->plogx_ioparm[0].hi16 << 16);
2160 parm1 = plp->plogx_ioparm[1].lo16 | (plp->plogx_ioparm[1].hi16 << 16);
2167 case PLOGX_IOCBERR_NOLINK:
2170 case PLOGX_IOCBERR_NOIOCB:
2171 msg = "no IOCB buffer";
2173 case PLOGX_IOCBERR_NOXGHG:
2174 msg = "no Exchange Control Block";
2176 case PLOGX_IOCBERR_FAILED:
2177 ISP_SNPRINTF(buf, sizeof (buf),
2178 "reason 0x%x (last LOGIN state 0x%x)",
2179 parm1 & 0xff, (parm1 >> 8) & 0xff);
2182 case PLOGX_IOCBERR_NOFABRIC:
2185 case PLOGX_IOCBERR_NOTREADY:
2186 msg = "firmware not ready";
2188 case PLOGX_IOCBERR_NOLOGIN:
2189 ISP_SNPRINTF(buf, sizeof (buf), "not logged in (last state 0x%x)",
2192 rval = MBOX_NOT_LOGGED_IN;
2194 case PLOGX_IOCBERR_REJECT:
2195 ISP_SNPRINTF(buf, sizeof (buf), "LS_RJT = 0x%x", parm1);
2198 case PLOGX_IOCBERR_NOPCB:
2199 msg = "no PCB allocated";
2201 case PLOGX_IOCBERR_EINVAL:
2202 ISP_SNPRINTF(buf, sizeof (buf), "invalid parameter at offset 0x%x",
2206 case PLOGX_IOCBERR_PORTUSED:
2207 lev = ISP_LOGSANCFG|ISP_LOGDEBUG0;
2208 ISP_SNPRINTF(buf, sizeof (buf),
2209 "already logged in with N-Port handle 0x%x", parm1);
2211 rval = MBOX_PORT_ID_USED | (parm1 << 16);
2213 case PLOGX_IOCBERR_HNDLUSED:
2214 lev = ISP_LOGSANCFG|ISP_LOGDEBUG0;
2215 ISP_SNPRINTF(buf, sizeof (buf),
2216 "handle already used for PortID 0x%06x", parm1);
2218 rval = MBOX_LOOP_ID_USED;
2220 case PLOGX_IOCBERR_NOHANDLE:
2221 msg = "no handle allocated";
2223 case PLOGX_IOCBERR_NOFLOGI:
2224 msg = "no FLOGI_ACC";
2227 ISP_SNPRINTF(buf, sizeof (buf), "status %x from %x",
2228 plp->plogx_status, flags);
2233 isp_prt(isp, ISP_LOGERR,
2234 "Chan %d PLOGX PortID 0x%06x to N-Port handle 0x%x: %s",
2235 chan, portid, handle, msg);
2239 FC_SCRATCH_RELEASE(isp, chan);
2245 isp_port_login(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2249 MBSINIT(&mbs, MBOX_FABRIC_LOGIN, MBLOGNONE, 500000);
2250 if (ISP_CAP_2KLOGIN(isp)) {
2251 mbs.param[1] = handle;
2252 mbs.ibits = (1 << 10);
2254 mbs.param[1] = handle << 8;
2256 mbs.param[2] = portid >> 16;
2257 mbs.param[3] = portid;
2258 mbs.logval = MBLOGNONE;
2259 mbs.timeout = 500000;
2260 isp_mboxcmd(isp, &mbs);
2262 switch (mbs.param[0]) {
2263 case MBOX_PORT_ID_USED:
2264 isp_prt(isp, ISP_LOGDEBUG0,
2265 "isp_port_login: portid 0x%06x already logged in as %u",
2266 portid, mbs.param[1]);
2267 return (MBOX_PORT_ID_USED | (mbs.param[1] << 16));
2269 case MBOX_LOOP_ID_USED:
2270 isp_prt(isp, ISP_LOGDEBUG0,
2271 "isp_port_login: handle 0x%04x in use for port id 0x%02xXXXX",
2272 handle, mbs.param[1] & 0xff);
2273 return (MBOX_LOOP_ID_USED);
2275 case MBOX_COMMAND_COMPLETE:
2278 case MBOX_COMMAND_ERROR:
2279 isp_prt(isp, ISP_LOGINFO,
2280 "isp_port_login: error 0x%x in PLOGI to port 0x%06x",
2281 mbs.param[1], portid);
2282 return (MBOX_COMMAND_ERROR);
2284 case MBOX_ALL_IDS_USED:
2285 isp_prt(isp, ISP_LOGINFO,
2286 "isp_port_login: all IDs used for fabric login");
2287 return (MBOX_ALL_IDS_USED);
2290 isp_prt(isp, ISP_LOGINFO,
2291 "isp_port_login: error 0x%x on port login of 0x%06x@0x%0x",
2292 mbs.param[0], portid, handle);
2293 return (mbs.param[0]);
2298 isp_port_logout(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2302 MBSINIT(&mbs, MBOX_FABRIC_LOGOUT, MBLOGNONE, 500000);
2303 if (ISP_CAP_2KLOGIN(isp)) {
2304 mbs.param[1] = handle;
2305 mbs.ibits = (1 << 10);
2307 mbs.param[1] = handle << 8;
2309 isp_mboxcmd(isp, &mbs);
2310 return (mbs.param[0] == MBOX_COMMAND_COMPLETE? 0 : mbs.param[0]);
2314 isp_getpdb(ispsoftc_t *isp, int chan, uint16_t id, isp_pdb_t *pdb, int dolock)
2316 fcparam *fcp = FCPARAM(isp, chan);
2319 isp_pdb_21xx_t fred;
2320 isp_pdb_24xx_t bill;
2323 MBSINIT(&mbs, MBOX_GET_PORT_DB, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR, 250000);
2325 mbs.ibits = (1 << 9)|(1 << 10);
2327 mbs.param[9] = chan;
2328 } else if (ISP_CAP_2KLOGIN(isp)) {
2331 mbs.param[1] = id << 8;
2333 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2334 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2335 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2336 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2338 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
2339 isp_prt(isp, ISP_LOGERR, sacq);
2343 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (un));
2344 isp_mboxcmd(isp, &mbs);
2345 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2347 FC_SCRATCH_RELEASE(isp, chan);
2349 return (mbs.param[0]);
2352 isp_get_pdb_24xx(isp, fcp->isp_scratch, &un.bill);
2353 pdb->handle = un.bill.pdb_handle;
2354 pdb->s3_role = un.bill.pdb_prli_svc3;
2355 pdb->portid = BITS2WORD_24XX(un.bill.pdb_portid_bits);
2356 ISP_MEMCPY(pdb->portname, un.bill.pdb_portname, 8);
2357 ISP_MEMCPY(pdb->nodename, un.bill.pdb_nodename, 8);
2358 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2359 "Chan %d Port 0x%06x flags 0x%x curstate %x",
2360 chan, pdb->portid, un.bill.pdb_flags,
2361 un.bill.pdb_curstate);
2362 if (un.bill.pdb_curstate < PDB2400_STATE_PLOGI_DONE ||
2363 un.bill.pdb_curstate > PDB2400_STATE_LOGGED_IN) {
2364 mbs.param[0] = MBOX_NOT_LOGGED_IN;
2366 FC_SCRATCH_RELEASE(isp, chan);
2368 return (mbs.param[0]);
2371 isp_get_pdb_21xx(isp, fcp->isp_scratch, &un.fred);
2372 pdb->handle = un.fred.pdb_loopid;
2373 pdb->s3_role = un.fred.pdb_prli_svc3;
2374 pdb->portid = BITS2WORD(un.fred.pdb_portid_bits);
2375 ISP_MEMCPY(pdb->portname, un.fred.pdb_portname, 8);
2376 ISP_MEMCPY(pdb->nodename, un.fred.pdb_nodename, 8);
2379 FC_SCRATCH_RELEASE(isp, chan);
2385 isp_dump_chip_portdb(ispsoftc_t *isp, int chan, int dolock)
2390 if (ISP_CAP_2KLOGIN(isp)) {
2395 for (loopid = 0; loopid != lim; loopid++) {
2396 if (isp_getpdb(isp, chan, loopid, &pdb, dolock)) {
2399 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGINFO, "Chan %d Loopid 0x%04x "
2400 "PortID 0x%06x WWPN 0x%02x%02x%02x%02x%02x%02x%02x%02x",
2401 chan, loopid, pdb.portid, pdb.portname[0], pdb.portname[1],
2402 pdb.portname[2], pdb.portname[3], pdb.portname[4],
2403 pdb.portname[5], pdb.portname[6], pdb.portname[7]);
2408 isp_get_wwn(ispsoftc_t *isp, int chan, int loopid, int nodename)
2410 uint64_t wwn = INI_NONE;
2411 fcparam *fcp = FCPARAM(isp, chan);
2414 if (fcp->isp_fwstate < FW_READY ||
2415 fcp->isp_loopstate < LOOP_PDB_RCVD) {
2418 MBSINIT(&mbs, MBOX_GET_PORT_NAME, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR, 500000);
2419 if (ISP_CAP_2KLOGIN(isp)) {
2420 mbs.param[1] = loopid;
2421 mbs.ibits = (1 << 10);
2425 if (ISP_CAP_MULTI_ID(isp)) {
2426 mbs.ibits |= (1 << 9);
2427 mbs.param[9] = chan;
2430 mbs.param[1] = loopid << 8;
2435 isp_mboxcmd(isp, &mbs);
2436 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2441 (((uint64_t)(mbs.param[2] >> 8)) << 56) |
2442 (((uint64_t)(mbs.param[2] & 0xff)) << 48) |
2443 (((uint64_t)(mbs.param[3] >> 8)) << 40) |
2444 (((uint64_t)(mbs.param[3] & 0xff)) << 32) |
2445 (((uint64_t)(mbs.param[6] >> 8)) << 24) |
2446 (((uint64_t)(mbs.param[6] & 0xff)) << 16) |
2447 (((uint64_t)(mbs.param[7] >> 8)) << 8) |
2448 (((uint64_t)(mbs.param[7] & 0xff)));
2451 (((uint64_t)(mbs.param[2] & 0xff)) << 56) |
2452 (((uint64_t)(mbs.param[2] >> 8)) << 48) |
2453 (((uint64_t)(mbs.param[3] & 0xff)) << 40) |
2454 (((uint64_t)(mbs.param[3] >> 8)) << 32) |
2455 (((uint64_t)(mbs.param[6] & 0xff)) << 24) |
2456 (((uint64_t)(mbs.param[6] >> 8)) << 16) |
2457 (((uint64_t)(mbs.param[7] & 0xff)) << 8) |
2458 (((uint64_t)(mbs.param[7] >> 8)));
2464 * Make sure we have good FC link.
2468 isp_fclink_test(ispsoftc_t *isp, int chan, int usdelay)
2471 int count, check_for_fabric, r;
2478 fcp = FCPARAM(isp, chan);
2480 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "Chan %d FC Link Test Entry", chan);
2481 ISP_MARK_PORTDB(isp, chan, 1);
2484 * Wait up to N microseconds for F/W to go to a ready state.
2486 lwfs = FW_CONFIG_WAIT;
2488 while (count < usdelay) {
2491 NANOTIME_T hra, hrb;
2494 isp_fw_state(isp, chan);
2495 if (lwfs != fcp->isp_fwstate) {
2496 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));
2497 lwfs = fcp->isp_fwstate;
2499 if (fcp->isp_fwstate == FW_READY) {
2505 * Get the elapsed time in nanoseconds.
2506 * Always guaranteed to be non-zero.
2508 enano = NANOTIME_SUB(&hrb, &hra);
2510 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));
2513 * If the elapsed time is less than 1 millisecond,
2514 * delay a period of time up to that millisecond of
2517 * This peculiar code is an attempt to try and avoid
2518 * invoking uint64_t math support functions for some
2519 * platforms where linkage is a problem.
2521 if (enano < (1000 * 1000)) {
2523 enano = (1000 * 1000) - enano;
2524 while (enano > (uint64_t) 4000000000U) {
2525 ISP_SLEEP(isp, 4000000);
2526 enano -= (uint64_t) 4000000000U;
2530 ISP_SLEEP(isp, wrk);
2532 while (enano > (uint64_t) 4000000000U) {
2534 enano -= (uint64_t) 4000000000U;
2537 count += (wrk / 1000);
2544 * If we haven't gone to 'ready' state, return.
2546 if (fcp->isp_fwstate != FW_READY) {
2547 isp_prt(isp, ISP_LOGSANCFG, "%s: chan %d not at FW_READY state", __func__, chan);
2552 * Get our Loop ID and Port ID.
2554 MBSINIT(&mbs, MBOX_GET_LOOP_ID, MBLOGALL, 0);
2555 if (ISP_CAP_MULTI_ID(isp)) {
2556 mbs.param[9] = chan;
2557 mbs.ibits = (1 << 9);
2558 mbs.obits = (1 << 7);
2560 isp_mboxcmd(isp, &mbs);
2561 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2565 if (ISP_CAP_2KLOGIN(isp)) {
2566 fcp->isp_loopid = mbs.param[1];
2568 fcp->isp_loopid = mbs.param[1] & 0xff;
2572 fcp->isp_topo = TOPO_NL_PORT;
2574 int topo = (int) mbs.param[6];
2575 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB) {
2576 topo = TOPO_PTP_STUB;
2578 fcp->isp_topo = topo;
2580 fcp->isp_portid = mbs.param[2] | (mbs.param[3] << 16);
2584 * Don't bother with fabric if we are using really old
2585 * 2100 firmware. It's just not worth it.
2587 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37)) {
2588 check_for_fabric = 1;
2590 check_for_fabric = 0;
2592 } else if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_F_PORT) {
2593 check_for_fabric = 1;
2595 check_for_fabric = 0;
2599 * Check to make sure we got a valid loopid
2600 * The 24XX seems to mess this up for multiple channels.
2602 if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_NL_PORT) {
2603 uint8_t alpa = fcp->isp_portid;
2606 /* "Cannot Happen" */
2607 isp_prt(isp, ISP_LOGWARN, "Zero AL_PA for Loop Topology?");
2610 for (i = 0; alpa_map[i]; i++) {
2611 if (alpa_map[i] == alpa) {
2615 if (alpa_map[i] && fcp->isp_loopid != i) {
2616 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);
2617 fcp->isp_loopid = i;
2623 if (IS_24XX(isp)) { /* XXX SHOULDN'T THIS BE FOR 2K F/W? XXX */
2628 if (check_for_fabric) {
2629 r = isp_getpdb(isp, chan, loopid, &pdb, 1);
2630 if (r && (fcp->isp_topo == TOPO_F_PORT || fcp->isp_topo == TOPO_FL_PORT)) {
2631 isp_prt(isp, ISP_LOGWARN, "fabric topology but cannot get info about fabric controller (0x%x)", r);
2632 fcp->isp_topo = TOPO_PTP_STUB;
2639 fcp->isp_topo = TOPO_FL_PORT;
2641 if (pdb.portid == 0) {
2645 fcp->isp_topo = TOPO_NL_PORT;
2650 * Save the Fabric controller's port database entry.
2652 lp = &fcp->portdb[FL_ID];
2653 lp->state = FC_PORTDB_STATE_PENDING_VALID;
2654 MAKE_WWN_FROM_NODE_NAME(lp->node_wwn, pdb.nodename);
2655 MAKE_WWN_FROM_NODE_NAME(lp->port_wwn, pdb.portname);
2656 lp->roles = (pdb.s3_role & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2657 lp->portid = pdb.portid;
2658 lp->handle = pdb.handle;
2659 lp->new_portid = lp->portid;
2660 lp->new_roles = lp->roles;
2662 fcp->inorder = (mbs.param[7] & ISP24XX_INORDER) != 0;
2663 if (ISP_FW_NEWER_THAN(isp, 4, 0, 27)) {
2664 fcp->npiv_fabric = (mbs.param[7] & ISP24XX_NPIV_SAN) != 0;
2665 if (fcp->npiv_fabric) {
2666 isp_prt(isp, ISP_LOGCONFIG, "fabric supports NP-IV");
2670 fcp->isp_sns_hdl = NPH_SNS_HDLBASE + chan;
2671 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);
2673 isp_prt(isp, ISP_LOGWARN, "%s: Chan %d cannot log into SNS", __func__, chan);
2677 fcp->isp_sns_hdl = NPH_SNS_ID;
2679 r = isp_register_fc4_type_24xx(isp, chan);
2681 fcp->isp_sns_hdl = SNS_ID;
2682 r = isp_register_fc4_type(isp, chan);
2685 isp_prt(isp, ISP_LOGWARN|ISP_LOGSANCFG, "%s: register fc4 type failed", __func__);
2690 fcp->portdb[FL_ID].state = FC_PORTDB_STATE_NIL;
2693 fcp->isp_gbspeed = 1;
2694 if (IS_23XX(isp) || IS_24XX(isp)) {
2695 MBSINIT(&mbs, MBOX_GET_SET_DATA_RATE, MBLOGALL, 3000000);
2696 mbs.param[1] = MBGSD_GET_RATE;
2697 /* mbs.param[2] undefined if we're just getting rate */
2698 isp_mboxcmd(isp, &mbs);
2699 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
2700 if (mbs.param[1] == MBGSD_EIGHTGB) {
2701 isp_prt(isp, ISP_LOGINFO, "Chan %d 8Gb link speed", chan);
2702 fcp->isp_gbspeed = 8;
2703 } else if (mbs.param[1] == MBGSD_FOURGB) {
2704 isp_prt(isp, ISP_LOGINFO, "Chan %d 4Gb link speed", chan);
2705 fcp->isp_gbspeed = 4;
2706 } else if (mbs.param[1] == MBGSD_TWOGB) {
2707 isp_prt(isp, ISP_LOGINFO, "Chan %d 2Gb link speed", chan);
2708 fcp->isp_gbspeed = 2;
2709 } else if (mbs.param[1] == MBGSD_ONEGB) {
2710 isp_prt(isp, ISP_LOGINFO, "Chan %d 1Gb link speed", chan);
2711 fcp->isp_gbspeed = 1;
2717 * Announce ourselves, too.
2719 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));
2720 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "Chan %d FC Link Test Complete", chan);
2725 * Complete the synchronization of our Port Database.
2727 * At this point, we've scanned the local loop (if any) and the fabric
2728 * and performed fabric logins on all new devices.
2730 * Our task here is to go through our port database and remove any entities
2731 * that are still marked probational (issuing PLOGO for ones which we had
2732 * PLOGI'd into) or are dead.
2734 * Our task here is to also check policy to decide whether devices which
2735 * have *changed* in some way should still be kept active. For example,
2736 * if a device has just changed PortID, we can either elect to treat it
2737 * as an old device or as a newly arrived device (and notify the outer
2738 * layer appropriately).
2740 * We also do initiator map target id assignment here for new initiator
2741 * devices and refresh old ones ot make sure that they point to the corret
2745 isp_pdb_sync(ispsoftc_t *isp, int chan)
2747 fcparam *fcp = FCPARAM(isp, chan);
2751 if (fcp->isp_loopstate == LOOP_READY) {
2756 * Make sure we're okay for doing this right now.
2758 if (fcp->isp_loopstate != LOOP_PDB_RCVD &&
2759 fcp->isp_loopstate != LOOP_FSCAN_DONE &&
2760 fcp->isp_loopstate != LOOP_LSCAN_DONE) {
2761 isp_prt(isp, ISP_LOGWARN, "isp_pdb_sync: bad loopstate %d",
2762 fcp->isp_loopstate);
2766 if (fcp->isp_topo == TOPO_FL_PORT ||
2767 fcp->isp_topo == TOPO_NL_PORT ||
2768 fcp->isp_topo == TOPO_N_PORT) {
2769 if (fcp->isp_loopstate < LOOP_LSCAN_DONE) {
2770 if (isp_scan_loop(isp, chan) != 0) {
2771 isp_prt(isp, ISP_LOGWARN,
2772 "isp_pdb_sync: isp_scan_loop failed");
2778 if (fcp->isp_topo == TOPO_F_PORT || fcp->isp_topo == TOPO_FL_PORT) {
2779 if (fcp->isp_loopstate < LOOP_FSCAN_DONE) {
2780 if (isp_scan_fabric(isp, chan) != 0) {
2781 isp_prt(isp, ISP_LOGWARN,
2782 "isp_pdb_sync: isp_scan_fabric failed");
2788 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2789 "Chan %d Synchronizing PDBs", chan);
2791 fcp->isp_loopstate = LOOP_SYNCING_PDB;
2793 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
2794 lp = &fcp->portdb[dbidx];
2796 if (lp->state == FC_PORTDB_STATE_NIL || lp->target_mode) {
2800 if (lp->state == FC_PORTDB_STATE_VALID) {
2801 if (dbidx != FL_ID) {
2803 ISP_LOGERR, "portdb idx %d already valid",
2809 switch (lp->state) {
2810 case FC_PORTDB_STATE_PROBATIONAL:
2811 case FC_PORTDB_STATE_DEAD:
2813 * It's up to the outer layers to clear isp_dev_map.
2815 lp->state = FC_PORTDB_STATE_NIL;
2816 isp_async(isp, ISPASYNC_DEV_GONE, chan, lp);
2817 if (lp->autologin == 0) {
2818 (void) isp_plogx(isp, chan, lp->handle,
2820 PLOGX_FLG_CMD_LOGO |
2821 PLOGX_FLG_IMPLICIT |
2822 PLOGX_FLG_FREE_NPHDL, 0);
2829 * Note that we might come out of this with our state
2830 * set to FC_PORTDB_STATE_ZOMBIE.
2833 case FC_PORTDB_STATE_NEW:
2835 * It's up to the outer layers to assign a virtual
2836 * target id in isp_dev_map (if any).
2838 lp->portid = lp->new_portid;
2839 lp->roles = lp->new_roles;
2840 lp->state = FC_PORTDB_STATE_VALID;
2841 isp_async(isp, ISPASYNC_DEV_ARRIVED, chan, lp);
2845 lp->new_reserved = 0;
2847 case FC_PORTDB_STATE_CHANGED:
2851 lp->state = FC_PORTDB_STATE_VALID;
2852 isp_async(isp, ISPASYNC_DEV_CHANGED, chan, lp);
2856 lp->new_reserved = 0;
2858 case FC_PORTDB_STATE_PENDING_VALID:
2859 lp->portid = lp->new_portid;
2860 lp->roles = lp->new_roles;
2861 if (lp->dev_map_idx) {
2862 int t = lp->dev_map_idx - 1;
2863 fcp->isp_dev_map[t] = dbidx + 1;
2865 lp->state = FC_PORTDB_STATE_VALID;
2866 isp_async(isp, ISPASYNC_DEV_STAYED, chan, lp);
2867 if (dbidx != FL_ID) {
2872 lp->new_reserved = 0;
2874 case FC_PORTDB_STATE_ZOMBIE:
2877 isp_prt(isp, ISP_LOGWARN,
2878 "isp_scan_loop: state %d for idx %d",
2880 isp_dump_portdb(isp, chan);
2885 * If we get here, we've for sure seen not only a valid loop
2886 * but know what is or isn't on it, so mark this for usage
2889 fcp->loop_seen_once = 1;
2890 fcp->isp_loopstate = LOOP_READY;
2895 * Scan local loop for devices.
2898 isp_scan_loop(ispsoftc_t *isp, int chan)
2900 fcportdb_t *lp, tmp;
2901 fcparam *fcp = FCPARAM(isp, chan);
2904 uint16_t handle, lim = 0;
2906 if (fcp->isp_fwstate < FW_READY ||
2907 fcp->isp_loopstate < LOOP_PDB_RCVD) {
2911 if (fcp->isp_loopstate > LOOP_SCANNING_LOOP) {
2916 * Check our connection topology.
2918 * If we're a public or private loop, we scan 0..125 as handle values.
2919 * The firmware has (typically) peformed a PLOGI for us. We skip this
2920 * step if we're a ISP_24XX in NP-IV mode.
2922 * If we're a N-port connection, we treat this is a short loop (0..1).
2924 switch (fcp->isp_topo) {
2926 lim = LOCAL_LOOP_LIM;
2929 if (IS_24XX(isp) && isp->isp_nchan > 1) {
2930 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2931 "Chan %d Skipping Local Loop Scan", chan);
2932 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2935 lim = LOCAL_LOOP_LIM;
2941 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2942 "Chan %d no loop topology to scan", chan);
2943 fcp->isp_loopstate = LOOP_LSCAN_DONE;
2947 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
2949 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2950 "Chan %d FC scan loop 0..%d", chan, lim-1);
2954 * Run through the list and get the port database info for each one.
2956 for (handle = 0; handle < lim; handle++) {
2959 * Don't scan "special" ids.
2961 if (handle >= FL_ID && handle <= SNS_ID) {
2964 if (ISP_CAP_2KLOGIN(isp)) {
2965 if (handle >= NPH_RESERVED && handle <= NPH_FL_ID) {
2970 * In older cards with older f/w GET_PORT_DATABASE has been
2971 * known to hang. This trick gets around that problem.
2973 if (IS_2100(isp) || IS_2200(isp)) {
2974 uint64_t node_wwn = isp_get_wwn(isp, chan, handle, 1);
2975 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2976 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2977 "Chan %d FC scan loop DONE (bad)", chan);
2980 if (node_wwn == INI_NONE) {
2986 * Get the port database entity for this index.
2988 r = isp_getpdb(isp, chan, handle, &pdb, 1);
2990 isp_prt(isp, ISP_LOGDEBUG1,
2991 "Chan %d FC scan loop handle %d returned %x",
2993 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
2994 ISP_MARK_PORTDB(isp, chan, 1);
2995 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2996 "Chan %d FC scan loop DONE (bad)", chan);
3002 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
3003 ISP_MARK_PORTDB(isp, chan, 1);
3004 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3005 "Chan %d FC scan loop DONE (bad)", chan);
3010 * On *very* old 2100 firmware we would end up sometimes
3011 * with the firmware returning the port database entry
3012 * for something else. We used to restart this, but
3015 if (IS_2100(isp) && pdb.handle != handle) {
3016 isp_prt(isp, ISP_LOGWARN,
3017 "Chan %d cannot synchronize port database", chan);
3018 ISP_MARK_PORTDB(isp, chan, 1);
3019 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3020 "Chan %d FC scan loop DONE (bad)", chan);
3025 * Save the pertinent info locally.
3027 MAKE_WWN_FROM_NODE_NAME(tmp.node_wwn, pdb.nodename);
3028 MAKE_WWN_FROM_NODE_NAME(tmp.port_wwn, pdb.portname);
3029 tmp.roles = (pdb.s3_role & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
3030 tmp.portid = pdb.portid;
3031 tmp.handle = pdb.handle;
3034 * Check to make sure it's still a valid entry. The 24XX seems
3035 * to return a portid but not a WWPN/WWNN or role for devices
3036 * which shift on a loop.
3038 if (tmp.node_wwn == 0 || tmp.port_wwn == 0 || tmp.portid == 0) {
3040 a = (tmp.node_wwn == 0);
3041 b = (tmp.port_wwn == 0);
3042 c = (tmp.portid == 0);
3043 if (a == 0 && b == 0) {
3045 isp_get_wwn(isp, chan, handle, 1);
3047 isp_get_wwn(isp, chan, handle, 0);
3048 if (tmp.node_wwn && tmp.port_wwn) {
3049 isp_prt(isp, ISP_LOGINFO, "DODGED!");
3053 isp_prt(isp, ISP_LOGWARN,
3054 "Chan %d bad pdb (%1d%1d%1d) @ handle 0x%x", chan,
3056 isp_dump_portdb(isp, chan);
3062 * Now search the entire port database
3063 * for the same Port and Node WWN.
3065 for (i = 0; i < MAX_FC_TARG; i++) {
3066 lp = &fcp->portdb[i];
3068 if (lp->state == FC_PORTDB_STATE_NIL ||
3072 if (lp->node_wwn != tmp.node_wwn) {
3075 if (lp->port_wwn != tmp.port_wwn) {
3080 * Okay- we've found a non-nil entry that matches.
3081 * Check to make sure it's probational or a zombie.
3083 if (lp->state != FC_PORTDB_STATE_PROBATIONAL &&
3084 lp->state != FC_PORTDB_STATE_ZOMBIE) {
3085 isp_prt(isp, ISP_LOGERR,
3086 "Chan %d [%d] not probational/zombie (0x%x)",
3087 chan, i, lp->state);
3088 isp_dump_portdb(isp, chan);
3089 ISP_MARK_PORTDB(isp, chan, 1);
3090 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3091 "Chan %d FC scan loop DONE (bad)", chan);
3096 * Mark the device as something the f/w logs into
3102 * Check to make see if really still the same
3103 * device. If it is, we mark it pending valid.
3105 if (lp->portid == tmp.portid &&
3106 lp->handle == tmp.handle &&
3107 lp->roles == tmp.roles) {
3108 lp->new_portid = tmp.portid;
3109 lp->new_roles = tmp.roles;
3110 lp->state = FC_PORTDB_STATE_PENDING_VALID;
3111 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3112 "Chan %d Loop Port 0x%06x@0x%04x Pending "
3113 "Valid", chan, tmp.portid, tmp.handle);
3118 * We can wipe out the old handle value
3119 * here because it's no longer valid.
3121 lp->handle = tmp.handle;
3124 * Claim that this has changed and let somebody else
3125 * decide what to do.
3127 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3128 "Chan %d Loop Port 0x%06x@0x%04x changed",
3129 chan, tmp.portid, tmp.handle);
3130 lp->state = FC_PORTDB_STATE_CHANGED;
3131 lp->new_portid = tmp.portid;
3132 lp->new_roles = tmp.roles;
3137 * Did we find and update an old entry?
3139 if (i < MAX_FC_TARG) {
3144 * Ah. A new device entry. Find an empty slot
3145 * for it and save info for later disposition.
3147 for (i = 0; i < MAX_FC_TARG; i++) {
3148 if (fcp->portdb[i].target_mode) {
3151 if (fcp->portdb[i].state == FC_PORTDB_STATE_NIL) {
3155 if (i == MAX_FC_TARG) {
3156 isp_prt(isp, ISP_LOGERR,
3157 "Chan %d out of portdb entries", chan);
3160 lp = &fcp->portdb[i];
3162 ISP_MEMZERO(lp, sizeof (fcportdb_t));
3164 lp->state = FC_PORTDB_STATE_NEW;
3165 lp->new_portid = tmp.portid;
3166 lp->new_roles = tmp.roles;
3167 lp->handle = tmp.handle;
3168 lp->port_wwn = tmp.port_wwn;
3169 lp->node_wwn = tmp.node_wwn;
3170 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3171 "Chan %d Loop Port 0x%06x@0x%04x is New Entry",
3172 chan, tmp.portid, tmp.handle);
3174 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3175 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3176 "Chan %d FC scan loop DONE", chan);
3181 * Scan the fabric for devices and add them to our port database.
3183 * Use the GID_FT command to get all Port IDs for FC4 SCSI devices it knows.
3185 * For 2100-23XX cards, we can use the SNS mailbox command to pass simple
3186 * name server commands to the switch management server via the QLogic f/w.
3188 * For the 24XX card, we have to use CT-Pass through run via the Execute IOCB
3191 * The net result is to leave the list of Port IDs setting untranslated in
3192 * offset IGPOFF of the FC scratch area, whereupon we'll canonicalize it to
3193 * host order at OGPOFF.
3197 * Take less than half of our scratch area to store Port IDs
3199 #define GIDLEN ((ISP_FC_SCRLEN >> 1) - 16 - SNS_GID_FT_REQ_SIZE)
3200 #define NGENT ((GIDLEN - 16) >> 2)
3202 #define IGPOFF (2 * QENTRY_LEN)
3203 #define OGPOFF (ISP_FC_SCRLEN >> 1)
3204 #define ZTXOFF (ISP_FC_SCRLEN - (1 * QENTRY_LEN))
3205 #define CTXOFF (ISP_FC_SCRLEN - (2 * QENTRY_LEN))
3206 #define XTXOFF (ISP_FC_SCRLEN - (3 * QENTRY_LEN))
3209 isp_gid_ft_sns(ispsoftc_t *isp, int chan)
3212 sns_gid_ft_req_t _x;
3213 uint8_t _y[SNS_GID_FT_REQ_SIZE];
3215 fcparam *fcp = FCPARAM(isp, chan);
3216 sns_gid_ft_req_t *rq = &un._x;
3219 isp_prt(isp, ISP_LOGDEBUG0,
3220 "Chan %d scanning fabric (GID_FT) via SNS", chan);
3222 ISP_MEMZERO(rq, SNS_GID_FT_REQ_SIZE);
3223 rq->snscb_rblen = GIDLEN >> 1;
3224 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + IGPOFF);
3225 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + IGPOFF);
3226 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + IGPOFF);
3227 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + IGPOFF);
3228 rq->snscb_sblen = 6;
3229 rq->snscb_cmd = SNS_GID_FT;
3230 rq->snscb_mword_div_2 = NGENT;
3231 rq->snscb_fc4_type = FC4_SCSI;
3233 isp_put_gid_ft_request(isp, rq, fcp->isp_scratch);
3234 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE);
3236 MBSINIT(&mbs, MBOX_SEND_SNS, MBLOGALL, 10000000);
3237 mbs.param[0] = MBOX_SEND_SNS;
3238 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
3239 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
3240 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
3241 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
3242 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
3243 isp_mboxcmd(isp, &mbs);
3244 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3245 if (mbs.param[0] == MBOX_INVALID_COMMAND) {
3255 isp_gid_ft_ct_passthru(ispsoftc_t *isp, int chan)
3258 fcparam *fcp = FCPARAM(isp, chan);
3262 uint8_t q[QENTRY_LEN];
3267 uint8_t *scp = fcp->isp_scratch;
3269 isp_prt(isp, ISP_LOGDEBUG0,
3270 "Chan %d scanning fabric (GID_FT) via CT", chan);
3272 if (!IS_24XX(isp)) {
3277 * Build a Passthrough IOCB in memory.
3280 ISP_MEMZERO(un.q, QENTRY_LEN);
3281 pt->ctp_header.rqs_entry_count = 1;
3282 pt->ctp_header.rqs_entry_type = RQSTYPE_CT_PASSTHRU;
3283 pt->ctp_handle = 0xffffffff;
3284 pt->ctp_nphdl = fcp->isp_sns_hdl;
3285 pt->ctp_cmd_cnt = 1;
3286 pt->ctp_vpidx = ISP_GET_VPIDX(isp, chan);
3288 pt->ctp_rsp_cnt = 1;
3289 pt->ctp_rsp_bcnt = GIDLEN;
3290 pt->ctp_cmd_bcnt = sizeof (*ct) + sizeof (uint32_t);
3291 pt->ctp_dataseg[0].ds_base = DMA_LO32(fcp->isp_scdma+XTXOFF);
3292 pt->ctp_dataseg[0].ds_basehi = DMA_HI32(fcp->isp_scdma+XTXOFF);
3293 pt->ctp_dataseg[0].ds_count = sizeof (*ct) + sizeof (uint32_t);
3294 pt->ctp_dataseg[1].ds_base = DMA_LO32(fcp->isp_scdma+IGPOFF);
3295 pt->ctp_dataseg[1].ds_basehi = DMA_HI32(fcp->isp_scdma+IGPOFF);
3296 pt->ctp_dataseg[1].ds_count = GIDLEN;
3297 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3298 isp_print_bytes(isp, "ct IOCB", QENTRY_LEN, pt);
3300 isp_put_ct_pt(isp, pt, (isp_ct_pt_t *) &scp[CTXOFF]);
3303 * Build the CT header and command in memory.
3305 * Note that the CT header has to end up as Big Endian format in memory.
3308 ISP_MEMZERO(ct, sizeof (*ct));
3309 ct->ct_revision = CT_REVISION;
3310 ct->ct_fcs_type = CT_FC_TYPE_FC;
3311 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3312 ct->ct_cmd_resp = SNS_GID_FT;
3313 ct->ct_bcnt_resid = (GIDLEN - 16) >> 2;
3315 isp_put_ct_hdr(isp, ct, (ct_hdr_t *) &scp[XTXOFF]);
3316 rp = (uint32_t *) &scp[XTXOFF+sizeof (*ct)];
3317 ISP_IOZPUT_32(isp, FC4_SCSI, rp);
3318 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3319 isp_print_bytes(isp, "CT HDR + payload after put",
3320 sizeof (*ct) + sizeof (uint32_t), &scp[XTXOFF]);
3322 ISP_MEMZERO(&scp[ZTXOFF], QENTRY_LEN);
3323 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 500000);
3324 mbs.param[1] = QENTRY_LEN;
3325 mbs.param[2] = DMA_WD1(fcp->isp_scdma + CTXOFF);
3326 mbs.param[3] = DMA_WD0(fcp->isp_scdma + CTXOFF);
3327 mbs.param[6] = DMA_WD3(fcp->isp_scdma + CTXOFF);
3328 mbs.param[7] = DMA_WD2(fcp->isp_scdma + CTXOFF);
3329 MEMORYBARRIER(isp, SYNC_SFORDEV, XTXOFF, 2 * QENTRY_LEN);
3330 isp_mboxcmd(isp, &mbs);
3331 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3334 MEMORYBARRIER(isp, SYNC_SFORCPU, ZTXOFF, QENTRY_LEN);
3336 isp_get_ct_pt(isp, (isp_ct_pt_t *) &scp[ZTXOFF], pt);
3337 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3338 isp_print_bytes(isp, "IOCB response", QENTRY_LEN, pt);
3341 if (pt->ctp_status && pt->ctp_status != RQCS_DATA_UNDERRUN) {
3342 isp_prt(isp, ISP_LOGWARN,
3343 "Chan %d ISP GID FT CT Passthrough returned 0x%x",
3344 chan, pt->ctp_status);
3347 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN + 16);
3348 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3349 isp_print_bytes(isp, "CT response", GIDLEN+16, &scp[IGPOFF]);
3355 isp_scan_fabric(ispsoftc_t *isp, int chan)
3357 fcparam *fcp = FCPARAM(isp, chan);
3359 uint16_t handle, oldhandle, loopid;
3361 int portidx, portlim, r;
3362 sns_gid_ft_rsp_t *rs0, *rs1;
3364 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3365 "Chan %d FC Scan Fabric", chan);
3366 if (fcp->isp_fwstate != FW_READY ||
3367 fcp->isp_loopstate < LOOP_LSCAN_DONE) {
3370 if (fcp->isp_loopstate > LOOP_SCANNING_FABRIC) {
3373 if (fcp->isp_topo != TOPO_FL_PORT && fcp->isp_topo != TOPO_F_PORT) {
3374 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3375 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3376 "Chan %d FC Scan Fabric Done (no fabric)", chan);
3380 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
3381 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3382 isp_prt(isp, ISP_LOGERR, sacq);
3383 ISP_MARK_PORTDB(isp, chan, 1);
3386 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC) {
3387 FC_SCRATCH_RELEASE(isp, chan);
3388 ISP_MARK_PORTDB(isp, chan, 1);
3393 * Make sure we still are logged into the fabric controller.
3395 if (IS_24XX(isp)) { /* XXX SHOULDN'T THIS BE TRUE FOR 2K F/W? XXX */
3400 r = isp_getpdb(isp, chan, loopid, &pdb, 0);
3401 if (r == MBOX_NOT_LOGGED_IN) {
3402 isp_dump_chip_portdb(isp, chan, 0);
3405 fcp->isp_loopstate = LOOP_PDB_RCVD;
3406 FC_SCRATCH_RELEASE(isp, chan);
3407 ISP_MARK_PORTDB(isp, chan, 1);
3412 r = isp_gid_ft_ct_passthru(isp, chan);
3414 r = isp_gid_ft_sns(isp, chan);
3417 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC) {
3418 FC_SCRATCH_RELEASE(isp, chan);
3419 ISP_MARK_PORTDB(isp, chan, 1);
3424 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3425 FC_SCRATCH_RELEASE(isp, chan);
3428 fcp->isp_loopstate = LOOP_PDB_RCVD; /* try again */
3429 FC_SCRATCH_RELEASE(isp, chan);
3433 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN);
3434 rs0 = (sns_gid_ft_rsp_t *) ((uint8_t *)fcp->isp_scratch+IGPOFF);
3435 rs1 = (sns_gid_ft_rsp_t *) ((uint8_t *)fcp->isp_scratch+OGPOFF);
3436 isp_get_gid_ft_response(isp, rs0, rs1, NGENT);
3437 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC) {
3438 FC_SCRATCH_RELEASE(isp, chan);
3439 ISP_MARK_PORTDB(isp, chan, 1);
3442 if (rs1->snscb_cthdr.ct_cmd_resp != LS_ACC) {
3444 if (rs1->snscb_cthdr.ct_reason == 9 &&
3445 rs1->snscb_cthdr.ct_explanation == 7) {
3446 level = ISP_LOGSANCFG|ISP_LOGDEBUG0;
3448 level = ISP_LOGWARN;
3450 isp_prt(isp, level, "Chan %d Fabric Nameserver rejected GID_FT"
3451 " (Reason=0x%x Expl=0x%x)", chan,
3452 rs1->snscb_cthdr.ct_reason,
3453 rs1->snscb_cthdr.ct_explanation);
3454 FC_SCRATCH_RELEASE(isp, chan);
3455 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3461 * If we get this far, we certainly still have the fabric controller.
3463 fcp->portdb[FL_ID].state = FC_PORTDB_STATE_PENDING_VALID;
3466 * Prime the handle we will start using.
3468 oldhandle = FCPARAM(isp, 0)->isp_lasthdl;
3471 * Go through the list and remove duplicate port ids.
3476 for (portidx = 0; portidx < NGENT-1; portidx++) {
3477 if (rs1->snscb_ports[portidx].control & 0x80) {
3483 * If we're not at the last entry, our list wasn't big enough.
3485 if ((rs1->snscb_ports[portidx].control & 0x80) == 0) {
3486 isp_prt(isp, ISP_LOGWARN,
3487 "fabric too big for scratch area: increase ISP_FC_SCRLEN");
3489 portlim = portidx + 1;
3490 isp_prt(isp, ISP_LOGSANCFG,
3491 "Chan %d got %d ports back from name server", chan, portlim);
3493 for (portidx = 0; portidx < portlim; portidx++) {
3497 ((rs1->snscb_ports[portidx].portid[0]) << 16) |
3498 ((rs1->snscb_ports[portidx].portid[1]) << 8) |
3499 ((rs1->snscb_ports[portidx].portid[2]));
3501 for (npidx = portidx + 1; npidx < portlim; npidx++) {
3502 uint32_t new_portid =
3503 ((rs1->snscb_ports[npidx].portid[0]) << 16) |
3504 ((rs1->snscb_ports[npidx].portid[1]) << 8) |
3505 ((rs1->snscb_ports[npidx].portid[2]));
3506 if (new_portid == portid) {
3511 if (npidx < portlim) {
3512 rs1->snscb_ports[npidx].portid[0] = 0;
3513 rs1->snscb_ports[npidx].portid[1] = 0;
3514 rs1->snscb_ports[npidx].portid[2] = 0;
3515 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3516 "Chan %d removing duplicate PortID 0x%06x"
3517 " entry from list", chan, portid);
3522 * We now have a list of Port IDs for all FC4 SCSI devices
3523 * that the Fabric Name server knows about.
3525 * For each entry on this list go through our port database looking
3526 * for probational entries- if we find one, then an old entry is
3527 * maybe still this one. We get some information to find out.
3529 * Otherwise, it's a new fabric device, and we log into it
3530 * (unconditionally). After searching the entire database
3531 * again to make sure that we never ever ever ever have more
3532 * than one entry that has the same PortID or the same
3533 * WWNN/WWPN duple, we enter the device into our database.
3536 for (portidx = 0; portidx < portlim; portidx++) {
3538 uint64_t wwnn, wwpn;
3542 ((rs1->snscb_ports[portidx].portid[0]) << 16) |
3543 ((rs1->snscb_ports[portidx].portid[1]) << 8) |
3544 ((rs1->snscb_ports[portidx].portid[2]));
3547 isp_prt(isp, ISP_LOGSANCFG,
3548 "Chan %d skipping null PortID at idx %d",
3554 * Skip ourselves here and on other channels. If we're
3555 * multi-id, we can't check the portids in other FCPARAM
3556 * arenas because the resolutions here aren't synchronized.
3557 * The best way to do this is to exclude looking at portids
3558 * that have the same domain and area code as our own
3561 if (ISP_CAP_MULTI_ID(isp)) {
3562 if ((portid >> 8) == (fcp->isp_portid >> 8)) {
3563 isp_prt(isp, ISP_LOGSANCFG,
3564 "Chan %d skip PortID 0x%06x",
3568 } else if (portid == fcp->isp_portid) {
3569 isp_prt(isp, ISP_LOGSANCFG,
3570 "Chan %d skip ourselves on @ PortID 0x%06x",
3575 isp_prt(isp, ISP_LOGSANCFG,
3576 "Chan %d Checking Fabric Port 0x%06x", chan, portid);
3579 * We now search our Port Database for any
3580 * probational entries with this PortID. We don't
3581 * look for zombies here- only probational
3582 * entries (we've already logged out of zombies).
3584 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
3585 lp = &fcp->portdb[dbidx];
3587 if (lp->state != FC_PORTDB_STATE_PROBATIONAL ||
3591 if (lp->portid == portid) {
3597 * We found a probational entry with this Port ID.
3599 if (dbidx < MAX_FC_TARG) {
3600 int handle_changed = 0;
3602 lp = &fcp->portdb[dbidx];
3605 * See if we're still logged into it.
3607 * If we aren't, mark it as a dead device and
3608 * leave the new portid in the database entry
3609 * for somebody further along to decide what to
3610 * do (policy choice).
3612 * If we are, check to see if it's the same
3613 * device still (it should be). If for some
3614 * reason it isn't, mark it as a changed device
3615 * and leave the new portid and role in the
3616 * database entry for somebody further along to
3617 * decide what to do (policy choice).
3621 r = isp_getpdb(isp, chan, lp->handle, &pdb, 0);
3622 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
3623 FC_SCRATCH_RELEASE(isp, chan);
3624 ISP_MARK_PORTDB(isp, chan, 1);
3628 lp->new_portid = portid;
3629 lp->state = FC_PORTDB_STATE_DEAD;
3630 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3631 "Chan %d Fabric Port 0x%06x is dead",
3638 * Check to make sure that handle, portid, WWPN and
3639 * WWNN agree. If they don't, then the association
3640 * between this PortID and the stated handle has been
3641 * broken by the firmware.
3643 MAKE_WWN_FROM_NODE_NAME(wwnn, pdb.nodename);
3644 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb.portname);
3645 if (pdb.handle != lp->handle ||
3646 pdb.portid != portid ||
3647 wwpn != lp->port_wwn ||
3648 wwnn != lp->node_wwn) {
3649 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3650 fconf, chan, dbidx, pdb.handle, pdb.portid,
3651 (uint32_t) (wwnn >> 32), (uint32_t) wwnn,
3652 (uint32_t) (wwpn >> 32), (uint32_t) wwpn,
3654 (uint32_t) (lp->node_wwn >> 32),
3655 (uint32_t) lp->node_wwn,
3656 (uint32_t) (lp->port_wwn >> 32),
3657 (uint32_t) lp->port_wwn);
3659 * Try to re-login to this device using a
3660 * new handle. If that fails, mark it dead.
3662 * isp_login_device will check for handle and
3663 * portid consistency after re-login.
3666 if (isp_login_device(isp, chan, portid, &pdb,
3668 lp->new_portid = portid;
3669 lp->state = FC_PORTDB_STATE_DEAD;
3670 if (fcp->isp_loopstate !=
3671 LOOP_SCANNING_FABRIC) {
3672 FC_SCRATCH_RELEASE(isp, chan);
3673 ISP_MARK_PORTDB(isp, chan, 1);
3678 if (fcp->isp_loopstate !=
3679 LOOP_SCANNING_FABRIC) {
3680 FC_SCRATCH_RELEASE(isp, chan);
3681 ISP_MARK_PORTDB(isp, chan, 1);
3684 FCPARAM(isp, 0)->isp_lasthdl = oldhandle;
3685 MAKE_WWN_FROM_NODE_NAME(wwnn, pdb.nodename);
3686 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb.portname);
3687 if (wwpn != lp->port_wwn ||
3688 wwnn != lp->node_wwn) {
3689 isp_prt(isp, ISP_LOGWARN, "changed WWN"
3691 lp->new_portid = portid;
3692 lp->state = FC_PORTDB_STATE_DEAD;
3696 lp->handle = pdb.handle;
3700 nr = (pdb.s3_role & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
3703 * Check to see whether the portid and roles have
3704 * stayed the same. If they have stayed the same,
3705 * we believe that this is the same device and it
3706 * hasn't become disconnected and reconnected, so
3707 * mark it as pending valid.
3709 * If they aren't the same, mark the device as a
3710 * changed device and save the new port id and role
3711 * and let somebody else decide.
3714 lp->new_portid = portid;
3716 if (pdb.portid != lp->portid || nr != lp->roles ||
3718 isp_prt(isp, ISP_LOGSANCFG,
3719 "Chan %d Fabric Port 0x%06x changed",
3721 lp->state = FC_PORTDB_STATE_CHANGED;
3723 isp_prt(isp, ISP_LOGSANCFG,
3724 "Chan %d Fabric Port 0x%06x "
3725 "Now Pending Valid", chan, portid);
3726 lp->state = FC_PORTDB_STATE_PENDING_VALID;
3732 * Ah- a new entry. Search the database again for all non-NIL
3733 * entries to make sure we never ever make a new database entry
3734 * with the same port id. While we're at it, mark where the
3735 * last free entry was.
3738 dbidx = MAX_FC_TARG;
3739 for (lp = fcp->portdb; lp < &fcp->portdb[MAX_FC_TARG]; lp++) {
3740 if (lp >= &fcp->portdb[FL_ID] &&
3741 lp <= &fcp->portdb[SNS_ID]) {
3745 * Skip any target mode entries.
3747 if (lp->target_mode) {
3750 if (lp->state == FC_PORTDB_STATE_NIL) {
3751 if (dbidx == MAX_FC_TARG) {
3752 dbidx = lp - fcp->portdb;
3756 if (lp->state == FC_PORTDB_STATE_ZOMBIE) {
3759 if (lp->portid == portid) {
3764 if (lp < &fcp->portdb[MAX_FC_TARG]) {
3765 isp_prt(isp, ISP_LOGWARN, "Chan %d PortID 0x%06x "
3766 "already at %d handle %d state %d",
3767 chan, portid, dbidx, lp->handle, lp->state);
3772 * We should have the index of the first free entry seen.
3774 if (dbidx == MAX_FC_TARG) {
3775 isp_prt(isp, ISP_LOGERR,
3776 "port database too small to login PortID 0x%06x"
3777 "- increase MAX_FC_TARG", portid);
3782 * Otherwise, point to our new home.
3784 lp = &fcp->portdb[dbidx];
3787 * Try to see if we are logged into this device,
3788 * and maybe log into it.
3790 * isp_login_device will check for handle and
3791 * portid consistency after login.
3793 if (isp_login_device(isp, chan, portid, &pdb, &oldhandle)) {
3794 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
3795 FC_SCRATCH_RELEASE(isp, chan);
3796 ISP_MARK_PORTDB(isp, chan, 1);
3801 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
3802 FC_SCRATCH_RELEASE(isp, chan);
3803 ISP_MARK_PORTDB(isp, chan, 1);
3806 FCPARAM(isp, 0)->isp_lasthdl = oldhandle;
3808 handle = pdb.handle;
3809 MAKE_WWN_FROM_NODE_NAME(wwnn, pdb.nodename);
3810 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb.portname);
3811 nr = (pdb.s3_role & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
3814 * And go through the database *one* more time to make sure
3815 * that we do not make more than one entry that has the same
3818 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
3819 if (dbidx >= FL_ID && dbidx <= SNS_ID) {
3822 if (fcp->portdb[dbidx].target_mode) {
3825 if (fcp->portdb[dbidx].node_wwn == wwnn &&
3826 fcp->portdb[dbidx].port_wwn == wwpn) {
3831 if (dbidx == MAX_FC_TARG) {
3832 ISP_MEMZERO(lp, sizeof (fcportdb_t));
3833 lp->handle = handle;
3834 lp->node_wwn = wwnn;
3835 lp->port_wwn = wwpn;
3836 lp->new_portid = portid;
3838 lp->state = FC_PORTDB_STATE_NEW;
3839 isp_prt(isp, ISP_LOGSANCFG,
3840 "Chan %d Fabric Port 0x%06x is a New Entry",
3845 if (fcp->portdb[dbidx].state != FC_PORTDB_STATE_ZOMBIE) {
3846 isp_prt(isp, ISP_LOGWARN,
3847 "Chan %d PortID 0x%x 0x%08x%08x/0x%08x%08x %ld "
3848 "already at idx %d, state 0x%x", chan, portid,
3849 (uint32_t) (wwnn >> 32), (uint32_t) wwnn,
3850 (uint32_t) (wwpn >> 32), (uint32_t) wwpn,
3851 (long) (lp - fcp->portdb), dbidx,
3852 fcp->portdb[dbidx].state);
3857 * We found a zombie entry that matches us.
3858 * Revive it. We know that WWN and WWPN
3859 * are the same. For fabric devices, we
3860 * don't care that handle is different
3861 * as we assign that. If role or portid
3862 * are different, it maybe a changed device.
3864 lp = &fcp->portdb[dbidx];
3865 lp->handle = handle;
3866 lp->new_portid = portid;
3868 if (lp->portid != portid || lp->roles != nr) {
3869 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3870 "Chan %d Zombie Fabric Port 0x%06x Now Changed",
3872 lp->state = FC_PORTDB_STATE_CHANGED;
3874 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3875 "Chan %d Zombie Fabric Port 0x%06x "
3876 "Now Pending Valid", chan, portid);
3877 lp->state = FC_PORTDB_STATE_PENDING_VALID;
3881 FC_SCRATCH_RELEASE(isp, chan);
3882 if (fcp->isp_loopstate != LOOP_SCANNING_FABRIC) {
3883 ISP_MARK_PORTDB(isp, chan, 1);
3886 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3887 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3888 "Chan %d FC Scan Fabric Done", chan);
3893 * Find an unused handle and try and use to login to a port.
3896 isp_login_device(ispsoftc_t *isp, int chan, uint32_t portid, isp_pdb_t *p,
3902 if (ISP_CAP_2KLOGIN(isp)) {
3908 handle = isp_nxt_handle(isp, chan, *ohp);
3909 for (i = 0; i < lim; i++) {
3911 * See if we're still logged into something with
3912 * this handle and that something agrees with this
3915 r = isp_getpdb(isp, chan, handle, p, 0);
3916 if (r == 0 && p->portid != portid) {
3917 (void) isp_plogx(isp, chan, handle, portid,
3918 PLOGX_FLG_CMD_LOGO | PLOGX_FLG_IMPLICIT, 1);
3919 } else if (r == 0) {
3922 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC) {
3926 * Now try and log into the device
3928 r = isp_plogx(isp, chan, handle, portid,
3929 PLOGX_FLG_CMD_PLOGI, 1);
3930 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC) {
3936 } else if ((r & 0xffff) == MBOX_PORT_ID_USED) {
3939 } else if (r != MBOX_LOOP_ID_USED) {
3942 } else if (r == MBOX_TIMEOUT) {
3946 handle = isp_nxt_handle(isp, chan, *ohp);
3951 isp_prt(isp, ISP_LOGWARN, "Chan %d PLOGI 0x%06x failed",
3957 * If we successfully logged into it, get the PDB for it
3958 * so we can crosscheck that it is still what we think it
3959 * is and that we also have the role it plays
3961 r = isp_getpdb(isp, chan, handle, p, 0);
3962 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC) {
3966 isp_prt(isp, ISP_LOGERR,
3967 "Chan %d new device 0x%06x@0x%x disappeared",
3968 chan, portid, handle);
3972 if (p->handle != handle || p->portid != portid) {
3973 isp_prt(isp, ISP_LOGERR,
3974 "Chan %d new device 0x%06x@0x%x changed (0x%06x@0x%0x)",
3975 chan, portid, handle, p->portid, p->handle);
3982 isp_register_fc4_type(ispsoftc_t *isp, int chan)
3984 fcparam *fcp = FCPARAM(isp, chan);
3985 uint8_t local[SNS_RFT_ID_REQ_SIZE];
3986 sns_screq_t *reqp = (sns_screq_t *) local;
3989 ISP_MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
3990 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
3991 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
3992 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
3993 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
3994 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
3995 reqp->snscb_sblen = 22;
3996 reqp->snscb_data[0] = SNS_RFT_ID;
3997 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
3998 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
3999 reqp->snscb_data[6] = (1 << FC4_SCSI);
4000 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4001 isp_prt(isp, ISP_LOGERR, sacq);
4004 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
4005 MBSINIT(&mbs, MBOX_SEND_SNS, MBLOGALL, 1000000);
4006 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
4007 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
4008 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
4009 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
4010 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
4011 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_RFT_ID_REQ_SIZE);
4012 isp_mboxcmd(isp, &mbs);
4013 FC_SCRATCH_RELEASE(isp, chan);
4014 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
4022 isp_register_fc4_type_24xx(ispsoftc_t *isp, int chan)
4025 fcparam *fcp = FCPARAM(isp, chan);
4029 uint8_t q[QENTRY_LEN];
4034 uint8_t *scp = fcp->isp_scratch;
4036 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4037 isp_prt(isp, ISP_LOGERR, sacq);
4042 * Build a Passthrough IOCB in memory.
4044 ISP_MEMZERO(un.q, QENTRY_LEN);
4046 pt->ctp_header.rqs_entry_count = 1;
4047 pt->ctp_header.rqs_entry_type = RQSTYPE_CT_PASSTHRU;
4048 pt->ctp_handle = 0xffffffff;
4049 pt->ctp_nphdl = fcp->isp_sns_hdl;
4050 pt->ctp_cmd_cnt = 1;
4051 pt->ctp_vpidx = ISP_GET_VPIDX(isp, chan);
4053 pt->ctp_rsp_cnt = 1;
4054 pt->ctp_rsp_bcnt = sizeof (ct_hdr_t);
4055 pt->ctp_cmd_bcnt = sizeof (rft_id_t);
4056 pt->ctp_dataseg[0].ds_base = DMA_LO32(fcp->isp_scdma+XTXOFF);
4057 pt->ctp_dataseg[0].ds_basehi = DMA_HI32(fcp->isp_scdma+XTXOFF);
4058 pt->ctp_dataseg[0].ds_count = sizeof (rft_id_t);
4059 pt->ctp_dataseg[1].ds_base = DMA_LO32(fcp->isp_scdma+IGPOFF);
4060 pt->ctp_dataseg[1].ds_basehi = DMA_HI32(fcp->isp_scdma+IGPOFF);
4061 pt->ctp_dataseg[1].ds_count = sizeof (ct_hdr_t);
4062 isp_put_ct_pt(isp, pt, (isp_ct_pt_t *) &scp[CTXOFF]);
4063 if (isp->isp_dblev & ISP_LOGDEBUG1) {
4064 isp_print_bytes(isp, "IOCB CT Request", QENTRY_LEN, pt);
4068 * Build the CT header and command in memory.
4070 * Note that the CT header has to end up as Big Endian format in memory.
4072 ISP_MEMZERO(&un.clocal, sizeof (un.clocal));
4073 ct = &un.clocal.rftid_hdr;
4074 ct->ct_revision = CT_REVISION;
4075 ct->ct_fcs_type = CT_FC_TYPE_FC;
4076 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
4077 ct->ct_cmd_resp = SNS_RFT_ID;
4078 ct->ct_bcnt_resid = (sizeof (rft_id_t) - sizeof (ct_hdr_t)) >> 2;
4080 rp->rftid_portid[0] = fcp->isp_portid >> 16;
4081 rp->rftid_portid[1] = fcp->isp_portid >> 8;
4082 rp->rftid_portid[2] = fcp->isp_portid;
4083 rp->rftid_fc4types[FC4_SCSI >> 5] = 1 << (FC4_SCSI & 0x1f);
4084 isp_put_rft_id(isp, rp, (rft_id_t *) &scp[XTXOFF]);
4085 if (isp->isp_dblev & ISP_LOGDEBUG1) {
4086 isp_print_bytes(isp, "CT Header", QENTRY_LEN, &scp[XTXOFF]);
4089 ISP_MEMZERO(&scp[ZTXOFF], sizeof (ct_hdr_t));
4091 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 1000000);
4092 mbs.param[1] = QENTRY_LEN;
4093 mbs.param[2] = DMA_WD1(fcp->isp_scdma + CTXOFF);
4094 mbs.param[3] = DMA_WD0(fcp->isp_scdma + CTXOFF);
4095 mbs.param[6] = DMA_WD3(fcp->isp_scdma + CTXOFF);
4096 mbs.param[7] = DMA_WD2(fcp->isp_scdma + CTXOFF);
4097 MEMORYBARRIER(isp, SYNC_SFORDEV, XTXOFF, 2 * QENTRY_LEN);
4098 isp_mboxcmd(isp, &mbs);
4099 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4100 FC_SCRATCH_RELEASE(isp, chan);
4103 MEMORYBARRIER(isp, SYNC_SFORCPU, ZTXOFF, QENTRY_LEN);
4105 isp_get_ct_pt(isp, (isp_ct_pt_t *) &scp[ZTXOFF], pt);
4106 if (isp->isp_dblev & ISP_LOGDEBUG1) {
4107 isp_print_bytes(isp, "IOCB response", QENTRY_LEN, pt);
4109 if (pt->ctp_status) {
4110 FC_SCRATCH_RELEASE(isp, chan);
4111 isp_prt(isp, ISP_LOGWARN,
4112 "Chan %d Register FC4 Type CT Passthrough returned 0x%x",
4113 chan, pt->ctp_status);
4117 isp_get_ct_hdr(isp, (ct_hdr_t *) &scp[IGPOFF], ct);
4118 FC_SCRATCH_RELEASE(isp, chan);
4120 if (ct->ct_cmd_resp == LS_RJT) {
4121 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
4122 "Chan %d Register FC4 Type rejected", chan);
4124 } else if (ct->ct_cmd_resp == LS_ACC) {
4125 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
4126 "Chan %d Register FC4 Type accepted", chan);
4129 isp_prt(isp, ISP_LOGWARN,
4130 "Chan %d Register FC4 Type: 0x%x",
4131 chan, ct->ct_cmd_resp);
4137 isp_nxt_handle(ispsoftc_t *isp, int chan, uint16_t handle)
4140 if (handle == NIL_HANDLE) {
4141 if (FCPARAM(isp, chan)->isp_topo == TOPO_F_PORT) {
4148 if (handle >= FL_ID && handle <= SNS_ID) {
4151 if (handle >= NPH_RESERVED && handle <= NPH_FL_ID) {
4152 handle = NPH_FL_ID+1;
4154 if (ISP_CAP_2KLOGIN(isp)) {
4155 if (handle == NPH_MAX_2K) {
4159 if (handle == NPH_MAX) {
4164 if (handle == FCPARAM(isp, chan)->isp_loopid) {
4165 return (isp_nxt_handle(isp, chan, handle));
4167 for (i = 0; i < MAX_FC_TARG; i++) {
4168 if (FCPARAM(isp, chan)->portdb[i].state ==
4169 FC_PORTDB_STATE_NIL) {
4172 if (FCPARAM(isp, chan)->portdb[i].handle == handle) {
4173 return (isp_nxt_handle(isp, chan, handle));
4180 * Start a command. Locking is assumed done in the caller.
4188 uint8_t local[QENTRY_LEN];
4192 int target, dmaresult, hdlidx = 0;
4198 * Now make sure we're running.
4201 if (isp->isp_state != ISP_RUNSTATE) {
4202 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
4203 XS_SETERR(xs, HBA_BOTCH);
4204 return (CMD_COMPLETE);
4208 * Check command CDB length, etc.. We really are limited to 16 bytes
4209 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
4210 * but probably only if we're running fairly new firmware (we'll
4211 * let the old f/w choke on an extended command queue entry).
4214 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
4215 isp_prt(isp, ISP_LOGERR, "unsupported cdb length (%d, CDB[0]=0x%x)", XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
4216 XS_SETERR(xs, HBA_BOTCH);
4217 return (CMD_COMPLETE);
4221 * Translate the target to device handle as appropriate, checking
4222 * for correct device state as well.
4224 target = XS_TGT(xs);
4226 fcparam *fcp = FCPARAM(isp, XS_CHANNEL(xs));
4228 if ((fcp->role & ISP_ROLE_INITIATOR) == 0) {
4229 XS_SETERR(xs, HBA_SELTIMEOUT);
4230 return (CMD_COMPLETE);
4236 if (fcp->isp_fwstate != FW_READY || fcp->isp_loopstate != LOOP_READY) {
4237 return (CMD_RQLATER);
4240 if (XS_TGT(xs) >= MAX_FC_TARG) {
4241 XS_SETERR(xs, HBA_SELTIMEOUT);
4242 return (CMD_COMPLETE);
4245 hdlidx = fcp->isp_dev_map[XS_TGT(xs)] - 1;
4246 isp_prt(isp, ISP_LOGDEBUG2, "XS_TGT(xs)=%d- hdlidx value %d", XS_TGT(xs), hdlidx);
4247 if (hdlidx < 0 || hdlidx >= MAX_FC_TARG) {
4248 XS_SETERR(xs, HBA_SELTIMEOUT);
4249 return (CMD_COMPLETE);
4251 if (fcp->portdb[hdlidx].state == FC_PORTDB_STATE_ZOMBIE) {
4252 return (CMD_RQLATER);
4254 if (fcp->portdb[hdlidx].state != FC_PORTDB_STATE_VALID) {
4255 XS_SETERR(xs, HBA_SELTIMEOUT);
4256 return (CMD_COMPLETE);
4258 target = fcp->portdb[hdlidx].handle;
4259 fcp->portdb[hdlidx].dirty = 1;
4261 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
4262 if ((sdp->role & ISP_ROLE_INITIATOR) == 0) {
4263 XS_SETERR(xs, HBA_SELTIMEOUT);
4264 return (CMD_COMPLETE);
4267 isp_spi_update(isp, XS_CHANNEL(xs));
4273 qep = isp_getrqentry(isp);
4275 isp_prt(isp, ISP_LOGDEBUG0, "Request Queue Overflow");
4276 XS_SETERR(xs, HBA_BOTCH);
4277 return (CMD_EAGAIN);
4279 XS_SETERR(xs, HBA_NOERROR);
4282 * Now see if we need to synchronize the ISP with respect to anything.
4283 * We do dual duty here (cough) for synchronizing for busses other
4284 * than which we got here to send a command to.
4286 reqp = (ispreq_t *) local;
4287 ISP_MEMZERO(local, QENTRY_LEN);
4288 if (ISP_TST_SENDMARKER(isp, XS_CHANNEL(xs))) {
4290 isp_marker_24xx_t *m = (isp_marker_24xx_t *) reqp;
4291 m->mrk_header.rqs_entry_count = 1;
4292 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4293 m->mrk_modifier = SYNC_ALL;
4294 isp_put_marker_24xx(isp, m, qep);
4296 isp_marker_t *m = (isp_marker_t *) reqp;
4297 m->mrk_header.rqs_entry_count = 1;
4298 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4299 m->mrk_target = (XS_CHANNEL(xs) << 7); /* bus # */
4300 m->mrk_modifier = SYNC_ALL;
4301 isp_put_marker(isp, m, qep);
4303 ISP_SYNC_REQUEST(isp);
4304 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 0);
4308 reqp->req_header.rqs_entry_count = 1;
4310 reqp->req_header.rqs_entry_type = RQSTYPE_T7RQS;
4311 } else if (IS_FC(isp)) {
4312 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
4314 if (XS_CDBLEN(xs) > 12) {
4315 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
4317 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
4320 /* reqp->req_header.rqs_flags = 0; */
4321 /* reqp->req_header.rqs_seqno = 0; */
4325 ttype = XS_TAG_TYPE(xs);
4327 if (XS_CDBP(xs)[0] == 0x3) {
4328 ttype = REQFLAG_HTAG;
4330 ttype = REQFLAG_STAG;
4333 if (ttype == REQFLAG_OTAG) {
4334 ttype = FCP_CMND_TASK_ATTR_ORDERED;
4335 } else if (ttype == REQFLAG_HTAG) {
4336 ttype = FCP_CMND_TASK_ATTR_HEAD;
4338 ttype = FCP_CMND_TASK_ATTR_SIMPLE;
4340 ((ispreqt7_t *)reqp)->req_task_attribute = ttype;
4341 } else if (IS_FC(isp)) {
4343 * See comment in isp_intr
4345 /* XS_SET_RESID(xs, 0); */
4348 * Fibre Channel always requires some kind of tag.
4349 * The Qlogic drivers seem be happy not to use a tag,
4350 * but this breaks for some devices (IBM drives).
4353 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
4356 * If we don't know what tag to use, use HEAD OF QUEUE
4357 * for Request Sense or Simple.
4359 if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
4360 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_HTAG;
4362 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
4365 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
4366 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) && XS_TAG_P(xs)) {
4367 reqp->req_flags = XS_TAG_TYPE(xs);
4370 cdbp = reqp->req_cdb;
4371 tptr = &reqp->req_time;
4374 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
4375 reqp->req_lun_trn = XS_LUN(xs);
4376 reqp->req_cdblen = XS_CDBLEN(xs);
4377 } else if (IS_24XX(isp)) {
4380 lp = &FCPARAM(isp, XS_CHANNEL(xs))->portdb[hdlidx];
4381 ((ispreqt7_t *)reqp)->req_nphdl = target;
4382 ((ispreqt7_t *)reqp)->req_tidlo = lp->portid;
4383 ((ispreqt7_t *)reqp)->req_tidhi = lp->portid >> 16;
4384 ((ispreqt7_t *)reqp)->req_vpidx = ISP_GET_VPIDX(isp, XS_CHANNEL(xs));
4385 if (XS_LUN(xs) > 256) {
4386 ((ispreqt7_t *)reqp)->req_lun[0] = XS_LUN(xs) >> 8;
4387 ((ispreqt7_t *)reqp)->req_lun[0] |= 0x40;
4389 ((ispreqt7_t *)reqp)->req_lun[1] = XS_LUN(xs);
4390 cdbp = ((ispreqt7_t *)reqp)->req_cdb;
4391 tptr = &((ispreqt7_t *)reqp)->req_time;
4392 } else if (ISP_CAP_2KLOGIN(isp)) {
4393 ((ispreqt2e_t *)reqp)->req_target = target;
4394 ((ispreqt2e_t *)reqp)->req_scclun = XS_LUN(xs);
4395 } else if (ISP_CAP_SCCFW(isp)) {
4396 ((ispreqt2_t *)reqp)->req_target = target;
4397 ((ispreqt2_t *)reqp)->req_scclun = XS_LUN(xs);
4399 ((ispreqt2_t *)reqp)->req_target = target;
4400 ((ispreqt2_t *)reqp)->req_lun_trn = XS_LUN(xs);
4402 ISP_MEMCPY(cdbp, XS_CDBP(xs), XS_CDBLEN(xs));
4404 *tptr = XS_TIME(xs) / 1000;
4405 if (*tptr == 0 && XS_TIME(xs)) {
4408 if (IS_24XX(isp) && *tptr > 0x1999) {
4412 if (isp_allocate_xs(isp, xs, &handle)) {
4413 isp_prt(isp, ISP_LOGDEBUG0, "out of xflist pointers");
4414 XS_SETERR(xs, HBA_BOTCH);
4415 return (CMD_EAGAIN);
4417 /* Whew. Thankfully the same for type 7 requests */
4418 reqp->req_handle = handle;
4421 * Set up DMA and/or do any platform dependent swizzling of the request entry
4422 * so that the Qlogic F/W understands what is being asked of it.
4424 * The callee is responsible for adding all requests at this point.
4426 dmaresult = ISP_DMASETUP(isp, xs, reqp);
4427 if (dmaresult != CMD_QUEUED) {
4428 isp_destroy_handle(isp, handle);
4430 * dmasetup sets actual error in packet, and
4431 * return what we were given to return.
4435 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));
4437 return (CMD_QUEUED);
4442 * Locks (ints blocked) assumed held.
4446 isp_control(ispsoftc_t *isp, ispctl_t ctl, ...)
4455 case ISPCTL_RESET_BUS:
4457 * Issue a bus reset.
4460 isp_prt(isp, ISP_LOGWARN, "RESET BUS NOT IMPLEMENTED");
4462 } else if (IS_FC(isp)) {
4467 chan = va_arg(ap, int);
4469 mbs.param[1] = SDPARAM(isp, chan)->isp_bus_reset_delay;
4470 if (mbs.param[1] < 2) {
4473 mbs.param[2] = chan;
4475 MBSINIT(&mbs, MBOX_BUS_RESET, MBLOGALL, 0);
4476 ISP_SET_SENDMARKER(isp, chan, 1);
4477 isp_mboxcmd(isp, &mbs);
4478 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4481 isp_prt(isp, ISP_LOGINFO,
4482 "driver initiated bus reset of bus %d", chan);
4485 case ISPCTL_RESET_DEV:
4487 chan = va_arg(ap, int);
4488 tgt = va_arg(ap, int);
4491 uint8_t local[QENTRY_LEN];
4493 isp24xx_statusreq_t *sp;
4494 fcparam *fcp = FCPARAM(isp, chan);
4498 hdlidx = fcp->isp_dev_map[tgt] - 1;
4499 if (hdlidx < 0 || hdlidx >= MAX_FC_TARG) {
4500 isp_prt(isp, ISP_LOGWARN,
4501 "Chan %d bad handle %d trying to reset"
4502 "target %d", chan, hdlidx, tgt);
4505 lp = &fcp->portdb[hdlidx];
4506 if (lp->state != FC_PORTDB_STATE_VALID) {
4507 isp_prt(isp, ISP_LOGWARN,
4508 "Chan %d handle %d for abort of target %d "
4509 "no longer valid", chan,
4514 tmf = (isp24xx_tmf_t *) local;
4515 ISP_MEMZERO(tmf, QENTRY_LEN);
4516 tmf->tmf_header.rqs_entry_type = RQSTYPE_TSK_MGMT;
4517 tmf->tmf_header.rqs_entry_count = 1;
4518 tmf->tmf_nphdl = lp->handle;
4520 tmf->tmf_timeout = 2;
4521 tmf->tmf_flags = ISP24XX_TMF_TARGET_RESET;
4522 tmf->tmf_tidlo = lp->portid;
4523 tmf->tmf_tidhi = lp->portid >> 16;
4524 tmf->tmf_vpidx = ISP_GET_VPIDX(isp, chan);
4525 isp_prt(isp, ISP_LOGALL, "Chan %d Reset N-Port Handle 0x%04x @ Port 0x%06x", chan, lp->handle, lp->portid);
4526 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 5000000);
4527 mbs.param[1] = QENTRY_LEN;
4528 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
4529 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
4530 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
4531 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
4533 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4534 isp_prt(isp, ISP_LOGERR, sacq);
4537 isp_put_24xx_tmf(isp, tmf, fcp->isp_scratch);
4538 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, QENTRY_LEN);
4539 fcp->sendmarker = 1;
4540 isp_mboxcmd(isp, &mbs);
4541 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4542 FC_SCRATCH_RELEASE(isp, chan);
4545 MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN,
4547 sp = (isp24xx_statusreq_t *) local;
4548 isp_get_24xx_response(isp,
4549 &((isp24xx_statusreq_t *)fcp->isp_scratch)[1], sp);
4550 FC_SCRATCH_RELEASE(isp, chan);
4551 if (sp->req_completion_status == 0) {
4554 isp_prt(isp, ISP_LOGWARN,
4555 "Chan %d reset of target %d returned 0x%x",
4556 chan, tgt, sp->req_completion_status);
4558 } else if (IS_FC(isp)) {
4559 if (ISP_CAP_2KLOGIN(isp)) {
4561 mbs.ibits = (1 << 10);
4563 mbs.param[1] = (tgt << 8);
4566 mbs.param[1] = (chan << 15) | (tgt << 8);
4568 MBSINIT(&mbs, MBOX_ABORT_TARGET, MBLOGALL, 0);
4569 mbs.param[2] = 3; /* 'delay', in seconds */
4570 isp_mboxcmd(isp, &mbs);
4571 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4574 isp_prt(isp, ISP_LOGINFO,
4575 "Target %d on Bus %d Reset Succeeded", tgt, chan);
4576 ISP_SET_SENDMARKER(isp, chan, 1);
4579 case ISPCTL_ABORT_CMD:
4581 xs = va_arg(ap, XS_T *);
4585 chan = XS_CHANNEL(xs);
4587 handle = isp_find_handle(isp, xs);
4589 isp_prt(isp, ISP_LOGWARN,
4590 "cannot find handle for command to abort");
4594 isp24xx_abrt_t local, *ab = &local, *ab2;
4599 fcp = FCPARAM(isp, chan);
4600 hdlidx = fcp->isp_dev_map[tgt] - 1;
4601 if (hdlidx < 0 || hdlidx >= MAX_FC_TARG) {
4602 isp_prt(isp, ISP_LOGWARN,
4603 "Chan %d bad handle %d trying to abort"
4604 "target %d", chan, hdlidx, tgt);
4607 lp = &fcp->portdb[hdlidx];
4608 if (lp->state != FC_PORTDB_STATE_VALID) {
4609 isp_prt(isp, ISP_LOGWARN,
4610 "Chan %d handle %d for abort of target %d "
4611 "no longer valid", chan, hdlidx, tgt);
4614 isp_prt(isp, ISP_LOGALL,
4615 "Chan %d Abort Cmd for N-Port 0x%04x @ Port "
4616 "0x%06x %p", chan, lp->handle, lp->portid, xs);
4617 ISP_MEMZERO(ab, QENTRY_LEN);
4618 ab->abrt_header.rqs_entry_type = RQSTYPE_ABORT_IO;
4619 ab->abrt_header.rqs_entry_count = 1;
4620 ab->abrt_handle = lp->handle;
4621 ab->abrt_cmd_handle = handle;
4622 ab->abrt_tidlo = lp->portid;
4623 ab->abrt_tidhi = lp->portid >> 16;
4624 ab->abrt_vpidx = ISP_GET_VPIDX(isp, chan);
4626 ISP_MEMZERO(&mbs, sizeof (mbs));
4627 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 5000000);
4628 mbs.param[1] = QENTRY_LEN;
4629 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
4630 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
4631 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
4632 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
4634 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4635 isp_prt(isp, ISP_LOGERR, sacq);
4638 isp_put_24xx_abrt(isp, ab, fcp->isp_scratch);
4639 ab2 = (isp24xx_abrt_t *)
4640 &((uint8_t *)fcp->isp_scratch)[QENTRY_LEN];
4641 ab2->abrt_nphdl = 0xdeaf;
4642 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, 2 * QENTRY_LEN);
4643 isp_mboxcmd(isp, &mbs);
4644 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4645 FC_SCRATCH_RELEASE(isp, chan);
4648 MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN,
4650 isp_get_24xx_abrt(isp, ab2, ab);
4651 FC_SCRATCH_RELEASE(isp, chan);
4652 if (ab->abrt_nphdl == ISP24XX_ABRT_OKAY) {
4655 isp_prt(isp, ISP_LOGWARN,
4656 "Chan %d handle %d abort returned 0x%x", chan,
4657 hdlidx, ab->abrt_nphdl);
4659 } else if (IS_FC(isp)) {
4660 if (ISP_CAP_SCCFW(isp)) {
4661 if (ISP_CAP_2KLOGIN(isp)) {
4664 mbs.param[1] = tgt << 8;
4666 mbs.param[6] = XS_LUN(xs);
4668 mbs.param[1] = tgt << 8 | XS_LUN(xs);
4671 mbs.param[1] = (chan << 15) | (tgt << 8) | XS_LUN(xs);
4673 MBSINIT(&mbs, MBOX_ABORT, MBLOGALL & ~MBOX_COMMAND_ERROR, 0);
4674 mbs.param[2] = handle;
4675 isp_mboxcmd(isp, &mbs);
4676 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4681 case ISPCTL_UPDATE_PARAMS:
4684 chan = va_arg(ap, int);
4686 isp_spi_update(isp, chan);
4689 case ISPCTL_FCLINK_TEST:
4694 chan = va_arg(ap, int);
4695 usdelay = va_arg(ap, int);
4700 return (isp_fclink_test(isp, chan, usdelay));
4704 case ISPCTL_SCAN_FABRIC:
4708 chan = va_arg(ap, int);
4710 return (isp_scan_fabric(isp, chan));
4714 case ISPCTL_SCAN_LOOP:
4718 chan = va_arg(ap, int);
4720 return (isp_scan_loop(isp, chan));
4724 case ISPCTL_PDB_SYNC:
4728 chan = va_arg(ap, int);
4730 return (isp_pdb_sync(isp, chan));
4734 case ISPCTL_SEND_LIP:
4736 if (IS_FC(isp) && !IS_24XX(isp)) {
4737 MBSINIT(&mbs, MBOX_INIT_LIP, MBLOGALL, 0);
4738 if (ISP_CAP_2KLOGIN(isp)) {
4739 mbs.ibits = (1 << 10);
4741 isp_mboxcmd(isp, &mbs);
4742 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
4748 case ISPCTL_GET_PDB:
4752 chan = va_arg(ap, int);
4753 tgt = va_arg(ap, int);
4754 pdb = va_arg(ap, isp_pdb_t *);
4756 return (isp_getpdb(isp, chan, tgt, pdb, 1));
4760 case ISPCTL_GET_NAMES:
4762 uint64_t *wwnn, *wwnp;
4764 chan = va_arg(ap, int);
4765 tgt = va_arg(ap, int);
4766 wwnn = va_arg(ap, uint64_t *);
4767 wwnp = va_arg(ap, uint64_t *);
4769 if (wwnn == NULL && wwnp == NULL) {
4773 *wwnn = isp_get_wwn(isp, chan, tgt, 1);
4774 if (*wwnn == INI_NONE) {
4779 *wwnp = isp_get_wwn(isp, chan, tgt, 0);
4780 if (*wwnp == INI_NONE) {
4786 case ISPCTL_RUN_MBOXCMD:
4789 mbr = va_arg(ap, mbreg_t *);
4791 isp_mboxcmd(isp, mbr);
4800 p = va_arg(ap, isp_plcmd_t *);
4803 if ((p->flags & PLOGX_FLG_CMD_MASK) != PLOGX_FLG_CMD_PLOGI || (p->handle != NIL_HANDLE)) {
4804 return (isp_plogx(isp, p->channel, p->handle, p->portid, p->flags, 0));
4807 p->handle = isp_nxt_handle(isp, p->channel, p->handle);
4808 r = isp_plogx(isp, p->channel, p->handle, p->portid, p->flags, 0);
4809 if ((r & 0xffff) == MBOX_PORT_ID_USED) {
4810 p->handle = r >> 16;
4814 } while ((r & 0xffff) == MBOX_LOOP_ID_USED);
4818 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
4826 * Interrupt Service Routine(s).
4828 * External (OS) framework has done the appropriate locking,
4829 * and the locking will be held throughout this function.
4833 * Limit our stack depth by sticking with the max likely number
4834 * of completions on a request queue at any one time.
4836 #ifndef MAX_REQUESTQ_COMPLETIONS
4837 #define MAX_REQUESTQ_COMPLETIONS 32
4841 isp_intr(ispsoftc_t *isp, uint32_t isr, uint16_t sema, uint16_t mbox)
4843 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
4844 uint32_t iptr, optr, junk;
4845 int i, nlooked = 0, ndone = 0;
4848 optr = isp->isp_residx;
4850 * Is this a mailbox related interrupt?
4851 * The mailbox semaphore will be nonzero if so.
4855 if (mbox & MBOX_COMMAND_COMPLETE) {
4856 isp->isp_intmboxc++;
4857 if (isp->isp_mboxbsy) {
4858 int obits = isp->isp_obits;
4859 isp->isp_mboxtmp[0] = mbox;
4860 for (i = 1; i < MAX_MAILBOX(isp); i++) {
4861 if ((obits & (1 << i)) == 0) {
4864 isp->isp_mboxtmp[i] = ISP_READ(isp, MBOX_OFF(i));
4866 if (isp->isp_mbxwrk0) {
4867 if (isp_mbox_continue(isp) == 0) {
4871 MBOX_NOTIFY_COMPLETE(isp);
4873 isp_prt(isp, ISP_LOGWARN, "mailbox cmd (0x%x) with no waiters", mbox);
4876 i = IS_FC(isp)? isp_parse_async_fc(isp, mbox) : isp_parse_async(isp, mbox);
4881 if ((IS_FC(isp) && mbox != ASYNC_RIOZIO_STALL) || isp->isp_state != ISP_RUNSTATE) {
4887 * We can't be getting this now.
4889 if (isp->isp_state != ISP_RUNSTATE) {
4891 * This seems to happen to 23XX and 24XX cards- don't know why.
4893 if (isp->isp_mboxbsy && isp->isp_lastmbxcmd == MBOX_ABOUT_FIRMWARE) {
4896 isp_prt(isp, ISP_LOGINFO, "interrupt (ISR=%x SEMA=%x) when not ready", isr, sema);
4898 * Thank you very much! *Burrrp*!
4900 ISP_WRITE(isp, isp->isp_respoutrp, ISP_READ(isp, isp->isp_respinrp));
4902 ISP_DISABLE_INTS(isp);
4907 #ifdef ISP_TARGET_MODE
4909 * Check for ATIO Queue entries.
4912 iptr = ISP_READ(isp, BIU2400_ATIO_RSPINP);
4913 optr = ISP_READ(isp, BIU2400_ATIO_RSPOUTP);
4915 while (optr != iptr) {
4916 uint8_t qe[QENTRY_LEN];
4922 MEMORYBARRIER(isp, SYNC_ATIOQ, oop, QENTRY_LEN);
4923 addr = ISP_QUEUE_ENTRY(isp->isp_atioq, oop);
4924 isp_get_hdr(isp, addr, (isphdr_t *)qe);
4925 hp = (isphdr_t *)qe;
4926 switch (hp->rqs_entry_type) {
4927 case RQSTYPE_NOTIFY:
4929 (void) isp_target_notify(isp, addr, &oop);
4932 isp_print_qentry(isp, "?ATIOQ entry?", oop, addr);
4935 optr = ISP_NXT_QENTRY(oop, RESULT_QUEUE_LEN(isp));
4936 ISP_WRITE(isp, BIU2400_ATIO_RSPOUTP, optr);
4938 optr = isp->isp_residx;
4943 * Get the current Response Queue Out Pointer.
4945 * If we're a 2300 or 2400, we can ask what hardware what it thinks.
4947 if (IS_23XX(isp) || IS_24XX(isp)) {
4948 optr = ISP_READ(isp, isp->isp_respoutrp);
4950 * Debug: to be taken out eventually
4952 if (isp->isp_residx != optr) {
4953 isp_prt(isp, ISP_LOGINFO, "isp_intr: hard optr=%x, soft optr %x", optr, isp->isp_residx);
4954 isp->isp_residx = optr;
4957 optr = isp->isp_residx;
4961 * You *must* read the Response Queue In Pointer
4962 * prior to clearing the RISC interrupt.
4964 * Debounce the 2300 if revision less than 2.
4966 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
4969 iptr = ISP_READ(isp, isp->isp_respinrp);
4970 junk = ISP_READ(isp, isp->isp_respinrp);
4971 } while (junk != iptr && ++i < 1000);
4974 isp_prt(isp, ISP_LOGWARN, "Response Queue Out Pointer Unstable (%x, %x)", iptr, junk);
4978 iptr = ISP_READ(isp, isp->isp_respinrp);
4980 isp->isp_resodx = iptr;
4983 if (optr == iptr && sema == 0) {
4985 * There are a lot of these- reasons unknown- mostly on
4986 * faster Alpha machines.
4988 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
4989 * make sure the old interrupt went away (to avoid 'ringing'
4990 * effects), but that didn't stop this from occurring.
4994 } else if (IS_23XX(isp)) {
4996 iptr = ISP_READ(isp, isp->isp_respinrp);
4997 junk = ISP_READ(isp, BIU_R2HSTSLO);
4999 junk = ISP_READ(isp, BIU_ISR);
5002 if (IS_23XX(isp) || IS_24XX(isp)) {
5005 sema = ISP_READ(isp, BIU_SEMA);
5006 mbox = ISP_READ(isp, OUTMAILBOX0);
5007 if ((sema & 0x3) && (mbox & 0x8000)) {
5011 isp->isp_intbogus++;
5012 isp_prt(isp, ISP_LOGDEBUG1, "bogus intr- isr %x (%x) iptr %x optr %x", isr, junk, iptr, optr);
5015 isp->isp_resodx = iptr;
5017 while (optr != iptr) {
5018 uint8_t qe[QENTRY_LEN];
5019 ispstatusreq_t *sp = (ispstatusreq_t *) qe;
5021 int buddaboom, etype, scsi_status, completion_status;
5022 int req_status_flags, req_state_flags;
5023 uint8_t *snsp, *resp;
5024 uint32_t rlen, slen;
5028 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
5030 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
5033 buddaboom = req_status_flags = req_state_flags = 0;
5037 * Synchronize our view of this response queue entry.
5039 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN);
5040 isp_get_hdr(isp, hp, &sp->req_header);
5041 etype = sp->req_header.rqs_entry_type;
5043 if (IS_24XX(isp) && etype == RQSTYPE_RESPONSE) {
5044 isp24xx_statusreq_t *sp2 = (isp24xx_statusreq_t *)qe;
5045 isp_get_24xx_response(isp, (isp24xx_statusreq_t *)hp, sp2);
5046 if (isp->isp_dblev & ISP_LOGDEBUG1) {
5047 isp_print_bytes(isp, "Response Queue Entry", QENTRY_LEN, sp2);
5049 scsi_status = sp2->req_scsi_status;
5050 completion_status = sp2->req_completion_status;
5051 req_state_flags = 0;
5052 resid = sp2->req_resid;
5053 } else if (etype == RQSTYPE_RESPONSE) {
5054 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
5055 if (isp->isp_dblev & ISP_LOGDEBUG1) {
5056 isp_print_bytes(isp, "Response Queue Entry", QENTRY_LEN, sp);
5058 scsi_status = sp->req_scsi_status;
5059 completion_status = sp->req_completion_status;
5060 req_status_flags = sp->req_status_flags;
5061 req_state_flags = sp->req_state_flags;
5062 resid = sp->req_resid;
5063 } else if (etype == RQSTYPE_RIO1) {
5064 isp_rio1_t *rio = (isp_rio1_t *) qe;
5065 isp_get_rio1(isp, (isp_rio1_t *) hp, rio);
5066 if (isp->isp_dblev & ISP_LOGDEBUG1) {
5067 isp_print_bytes(isp, "Response Queue Entry", QENTRY_LEN, rio);
5069 for (i = 0; i < rio->req_header.rqs_seqno; i++) {
5070 isp_fastpost_complete(isp, rio->req_handles[i]);
5072 if (isp->isp_fpcchiwater < rio->req_header.rqs_seqno) {
5073 isp->isp_fpcchiwater = rio->req_header.rqs_seqno;
5075 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5077 } else if (etype == RQSTYPE_RIO2) {
5078 isp_prt(isp, ISP_LOGERR, "dropping RIO2 response\n");
5079 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5083 * Somebody reachable via isp_handle_other_response
5084 * may have updated the response queue pointers for
5085 * us, so we reload our goal index.
5088 uint32_t tsto = oop;
5089 r = isp_handle_other_response(isp, etype, hp, &tsto);
5094 * If somebody updated the output pointer, then reset
5095 * optr to be one more than the updated amount.
5097 while (tsto != oop) {
5098 optr = ISP_NXT_QENTRY(tsto,
5099 RESULT_QUEUE_LEN(isp));
5102 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5103 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5108 * After this point, we'll just look at the header as
5109 * we don't know how to deal with the rest of the
5114 * It really has to be a bounced request just copied
5115 * from the request queue to the response queue. If
5116 * not, something bad has happened.
5118 if (etype != RQSTYPE_REQUEST) {
5119 isp_prt(isp, ISP_LOGERR, notresp,
5120 etype, oop, optr, nlooked);
5121 isp_print_bytes(isp,
5122 "Request Queue Entry", QENTRY_LEN, sp);
5123 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5127 scsi_status = sp->req_scsi_status;
5128 completion_status = sp->req_completion_status;
5129 req_status_flags = sp->req_status_flags;
5130 req_state_flags = sp->req_state_flags;
5131 resid = sp->req_resid;
5134 if (sp->req_header.rqs_flags & RQSFLAG_MASK) {
5135 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
5136 isp_print_bytes(isp, "unexpected continuation segment", QENTRY_LEN, sp);
5137 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5140 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
5141 isp_prt(isp, ISP_LOGDEBUG0, "internal queues full");
5143 * We'll synthesize a QUEUE FULL message below.
5146 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
5147 isp_print_bytes(isp, "bad header flag", QENTRY_LEN, sp);
5150 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
5151 isp_print_bytes(isp, "bad request packet", QENTRY_LEN, sp);
5154 if (sp->req_header.rqs_flags & RQSFLAG_BADCOUNT) {
5155 isp_print_bytes(isp, "invalid entry count", QENTRY_LEN, sp);
5158 if (sp->req_header.rqs_flags & RQSFLAG_BADORDER) {
5159 isp_print_bytes(isp, "invalid IOCB ordering", QENTRY_LEN, sp);
5160 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5165 if (!ISP_VALID_HANDLE(isp, sp->req_handle)) {
5166 isp_prt(isp, ISP_LOGERR, "bad request handle 0x%x (iocb type 0x%x)", sp->req_handle, etype);
5167 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5168 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5171 xs = isp_find_xs(isp, sp->req_handle);
5173 uint8_t ts = completion_status & 0xff;
5175 * Only whine if this isn't the expected fallout of
5176 * aborting the command or resetting the target.
5178 if (etype != RQSTYPE_RESPONSE) {
5179 isp_prt(isp, ISP_LOGERR, "cannot find handle 0x%x (type 0x%x)", sp->req_handle, etype);
5180 } else if (ts != RQCS_ABORTED && ts != RQCS_RESET_OCCURRED) {
5181 isp_prt(isp, ISP_LOGERR, "cannot find handle 0x%x (status 0x%x)", sp->req_handle, ts);
5183 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5184 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5187 if (req_status_flags & RQSTF_BUS_RESET) {
5188 XS_SETERR(xs, HBA_BUSRESET);
5189 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 1);
5192 XS_SETERR(xs, HBA_BOTCH);
5199 if (IS_24XX(isp) && (scsi_status & (RQCS_RV|RQCS_SV)) != 0) {
5200 resp = ((isp24xx_statusreq_t *)sp)->req_rsp_sense;
5201 rlen = ((isp24xx_statusreq_t *)sp)->req_response_len;
5202 } else if (IS_FC(isp) && (scsi_status & RQCS_RV) != 0) {
5203 resp = sp->req_response;
5204 rlen = sp->req_response_len;
5206 if (IS_FC(isp) && (scsi_status & RQCS_SV) != 0) {
5208 * Fibre Channel F/W doesn't say we got status
5209 * if there's Sense Data instead. I guess they
5210 * think it goes w/o saying.
5212 req_state_flags |= RQSF_GOT_STATUS|RQSF_GOT_SENSE;
5214 snsp = ((isp24xx_statusreq_t *)sp)->req_rsp_sense;
5216 slen = ((isp24xx_statusreq_t *)sp)->req_sense_len;
5218 snsp = sp->req_sense_data;
5219 slen = sp->req_sense_len;
5221 } else if (IS_SCSI(isp) && (req_state_flags & RQSF_GOT_SENSE)) {
5222 snsp = sp->req_sense_data;
5223 slen = sp->req_sense_len;
5225 if (req_state_flags & RQSF_GOT_STATUS) {
5226 *XS_STSP(xs) = scsi_status & 0xff;
5230 case RQSTYPE_RESPONSE:
5231 if (resp && rlen >= 4 && resp[FCP_RSPNS_CODE_OFFSET] != 0) {
5234 const char *rnames[6] = {
5235 "Task Management Function Done",
5236 "Data Length Differs From Burst Length",
5238 "FCP DATA RO mismatch with FCP DATA_XFR_RDY RO",
5239 "Task Management Function Rejected",
5240 "Task Management Function Failed",
5242 if (resp[FCP_RSPNS_CODE_OFFSET] > 5) {
5243 ISP_SNPRINTF(lb, sizeof lb, "Unknown FCP Response Code 0x%x", resp[FCP_RSPNS_CODE_OFFSET]);
5246 ptr = rnames[resp[FCP_RSPNS_CODE_OFFSET]];
5248 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);
5249 if (resp[FCP_RSPNS_CODE_OFFSET] != 0) {
5250 XS_SETERR(xs, HBA_BOTCH);
5254 isp_parse_status_24xx(isp, (isp24xx_statusreq_t *)sp, xs, &resid);
5256 isp_parse_status(isp, (void *)sp, xs, &resid);
5258 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) && (*XS_STSP(xs) == SCSI_BUSY)) {
5259 XS_SETERR(xs, HBA_TGTBSY);
5262 XS_SET_RESID(xs, resid);
5264 * A new synchronous rate was negotiated for
5265 * this target. Mark state such that we'll go
5266 * look up that which has changed later.
5268 if (req_status_flags & RQSTF_NEGOTIATION) {
5270 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
5271 sdp->isp_devparam[t].dev_refresh = 1;
5275 if (req_status_flags & RQSF_XFER_COMPLETE) {
5276 XS_SET_RESID(xs, 0);
5277 } else if (scsi_status & RQCS_RESID) {
5278 XS_SET_RESID(xs, resid);
5280 XS_SET_RESID(xs, 0);
5284 XS_SAVE_SENSE(xs, snsp, slen);
5285 } else if ((req_status_flags & RQSF_GOT_STATUS) && (scsi_status & 0xff) == SCSI_CHECK && IS_FC(isp)) {
5286 isp_prt(isp, ISP_LOGWARN, "CHECK CONDITION w/o sense data for CDB=0x%x", XS_CDBP(xs)[0] & 0xff);
5287 isp_print_bytes(isp, "CC with no Sense", QENTRY_LEN, qe);
5289 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));
5291 case RQSTYPE_REQUEST:
5296 if (!IS_24XX(isp) && (sp->req_header.rqs_flags & RQSFLAG_FULL)) {
5298 * Force Queue Full status.
5300 *XS_STSP(xs) = SCSI_QFULL;
5301 XS_SETERR(xs, HBA_NOERROR);
5302 } else if (XS_NOERR(xs)) {
5303 XS_SETERR(xs, HBA_BOTCH);
5305 XS_SET_RESID(xs, XS_XFRLEN(xs));
5308 isp_print_bytes(isp, "Unhandled Response Type", QENTRY_LEN, qe);
5310 XS_SETERR(xs, HBA_BOTCH);
5316 * Free any DMA resources. As a side effect, this may
5317 * also do any cache flushing necessary for data coherence.
5319 if (XS_XFRLEN(xs)) {
5320 ISP_DMAFREE(isp, xs, sp->req_handle);
5322 isp_destroy_handle(isp, sp->req_handle);
5324 if (((isp->isp_dblev & (ISP_LOGDEBUG1|ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
5325 ((isp->isp_dblev & ISP_LOGDEBUG0) && ((!XS_NOERR(xs)) ||
5326 (*XS_STSP(xs) != SCSI_GOOD)))) {
5328 if (req_state_flags & RQSF_GOT_SENSE) {
5329 skey = XS_SNSKEY(xs) & 0xf;
5334 } else if (*XS_STSP(xs) == SCSI_CHECK) {
5339 isp_prt(isp, ISP_LOGALL, finmsg, XS_CHANNEL(xs),
5340 XS_TGT(xs), XS_LUN(xs), XS_XFRLEN(xs), (long) XS_GET_RESID(xs),
5341 *XS_STSP(xs), skey, XS_ERR(xs));
5344 if (isp->isp_nactive > 0) {
5347 complist[ndone++] = xs; /* defer completion call until later */
5348 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5349 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
5355 * If we looked at any commands, then it's valid to find out
5356 * what the outpointer is. It also is a trigger to update the
5357 * ISP's notion of what we've seen so far.
5360 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5362 * While we're at it, read the requst queue out pointer.
5364 isp->isp_reqodx = ISP_READ(isp, isp->isp_rqstoutrp);
5365 if (isp->isp_rscchiwater < ndone) {
5366 isp->isp_rscchiwater = ndone;
5373 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
5375 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
5376 ISP_WRITE(isp, BIU_SEMA, 0);
5379 isp->isp_residx = optr;
5380 for (i = 0; i < ndone; i++) {
5383 isp->isp_rsltccmplt++;
5394 * Parse an ASYNC mailbox complete
5396 * Return non-zero if the event has been acknowledged.
5399 isp_parse_async(ispsoftc_t *isp, uint16_t mbox)
5402 uint32_t h1 = 0, h2 = 0;
5406 * Pick up the channel, but not if this is a ASYNC_RIO32_2,
5407 * where Mailboxes 6/7 have the second handle.
5409 if (mbox != ASYNC_RIO32_2) {
5410 if (IS_DUALBUS(isp)) {
5411 chan = ISP_READ(isp, OUTMAILBOX6);
5414 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
5417 case ASYNC_BUS_RESET:
5418 ISP_SET_SENDMARKER(isp, chan, 1);
5419 #ifdef ISP_TARGET_MODE
5420 if (isp_target_async(isp, chan, mbox)) {
5424 isp_async(isp, ISPASYNC_BUS_RESET, chan);
5426 case ASYNC_SYSTEM_ERROR:
5428 isp->isp_state = ISP_CRASHED;
5430 * Were we waiting for a mailbox command to complete?
5431 * If so, it's dead, so wake up the waiter.
5433 if (isp->isp_mboxbsy) {
5435 isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR;
5436 MBOX_NOTIFY_COMPLETE(isp);
5439 * It's up to the handler for isp_async to reinit stuff and
5440 * restart the firmware
5442 isp_async(isp, ISPASYNC_FW_CRASH);
5446 case ASYNC_RQS_XFER_ERR:
5447 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
5450 case ASYNC_RSP_XFER_ERR:
5451 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
5456 * We've just been notified that the Queue has woken up.
5457 * We don't need to be chatty about this- just unlatch things
5460 mbox = ISP_READ(isp, isp->isp_rqstoutrp);
5463 case ASYNC_TIMEOUT_RESET:
5464 isp_prt(isp, ISP_LOGWARN, "timeout initiated SCSI bus reset of chan %d", chan);
5465 ISP_SET_SENDMARKER(isp, chan, 1);
5466 #ifdef ISP_TARGET_MODE
5467 if (isp_target_async(isp, chan, mbox)) {
5473 case ASYNC_DEVICE_RESET:
5474 isp_prt(isp, ISP_LOGINFO, "device reset on chan %d", chan);
5475 ISP_SET_SENDMARKER(isp, chan, 1);
5476 #ifdef ISP_TARGET_MODE
5477 if (isp_target_async(isp, chan, mbox)) {
5483 case ASYNC_EXTMSG_UNDERRUN:
5484 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
5487 case ASYNC_SCAM_INT:
5488 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
5491 case ASYNC_HUNG_SCSI:
5492 isp_prt(isp, ISP_LOGERR, "stalled SCSI Bus after DATA Overrun");
5493 /* XXX: Need to issue SCSI reset at this point */
5496 case ASYNC_KILLED_BUS:
5497 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
5500 case ASYNC_BUS_TRANSIT:
5501 mbox = ISP_READ(isp, OUTMAILBOX2);
5502 switch (mbox & SXP_PINS_MODE_MASK) {
5503 case SXP_PINS_LVD_MODE:
5504 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
5505 SDPARAM(isp, chan)->isp_diffmode = 0;
5506 SDPARAM(isp, chan)->isp_ultramode = 0;
5507 SDPARAM(isp, chan)->isp_lvdmode = 1;
5509 case SXP_PINS_HVD_MODE:
5510 isp_prt(isp, ISP_LOGINFO,
5511 "Transition to Differential mode");
5512 SDPARAM(isp, chan)->isp_diffmode = 1;
5513 SDPARAM(isp, chan)->isp_ultramode = 0;
5514 SDPARAM(isp, chan)->isp_lvdmode = 0;
5516 case SXP_PINS_SE_MODE:
5517 isp_prt(isp, ISP_LOGINFO,
5518 "Transition to Single Ended mode");
5519 SDPARAM(isp, chan)->isp_diffmode = 0;
5520 SDPARAM(isp, chan)->isp_ultramode = 1;
5521 SDPARAM(isp, chan)->isp_lvdmode = 0;
5524 isp_prt(isp, ISP_LOGWARN,
5525 "Transition to Unknown Mode 0x%x", mbox);
5529 * XXX: Set up to renegotiate again!
5531 /* Can only be for a 1080... */
5532 ISP_SET_SENDMARKER(isp, chan, 1);
5535 case ASYNC_CMD_CMPLT:
5537 if (!IS_ULTRA3(isp)) {
5538 isp_prt(isp, ISP_LOGERR, "unexpected fast posting completion");
5542 h1 = (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1);
5546 h1 = (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1);
5547 h2 = (ISP_READ(isp, OUTMAILBOX7) << 16) | ISP_READ(isp, OUTMAILBOX6);
5555 isp_prt(isp, ISP_LOGERR, "unexpected 16 bit RIO handle");
5558 isp_prt(isp, ISP_LOGWARN, "%s: unhandled async code 0x%x", __func__, mbox);
5563 isp_prt(isp, ISP_LOGDEBUG3, "fast post/rio completion of 0x%08x", h1);
5564 isp_fastpost_complete(isp, h1);
5566 isp_prt(isp, ISP_LOGDEBUG3, "fast post/rio completion of 0x%08x", h2);
5567 isp_fastpost_complete(isp, h2);
5568 if (isp->isp_fpcchiwater < 2) {
5569 isp->isp_fpcchiwater = 2;
5572 if (isp->isp_fpcchiwater < 1) {
5573 isp->isp_fpcchiwater = 1;
5577 isp->isp_intoasync++;
5582 #define GET_24XX_BUS(isp, chan, msg) \
5583 if (IS_24XX(isp)) { \
5584 chan = ISP_READ(isp, OUTMAILBOX3) & 0xff; \
5585 if (chan >= isp->isp_nchan) { \
5586 isp_prt(isp, ISP_LOGERR, "bogus channel %u for %s at line %d", chan, msg, __LINE__); \
5593 isp_parse_async_fc(ispsoftc_t *isp, uint16_t mbox)
5598 if (IS_DUALBUS(isp)) {
5599 chan = ISP_READ(isp, OUTMAILBOX6);
5603 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
5606 case ASYNC_SYSTEM_ERROR:
5608 isp->isp_state = ISP_CRASHED;
5609 FCPARAM(isp, chan)->isp_loopstate = LOOP_NIL;
5610 FCPARAM(isp, chan)->isp_fwstate = FW_CONFIG_WAIT;
5612 * Were we waiting for a mailbox command to complete?
5613 * If so, it's dead, so wake up the waiter.
5615 if (isp->isp_mboxbsy) {
5617 isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR;
5618 MBOX_NOTIFY_COMPLETE(isp);
5621 * It's up to the handler for isp_async to reinit stuff and
5622 * restart the firmware
5624 isp_async(isp, ISPASYNC_FW_CRASH);
5628 case ASYNC_RQS_XFER_ERR:
5629 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
5632 case ASYNC_RSP_XFER_ERR:
5633 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
5637 #ifdef ISP_TARGET_MODE
5639 isp_prt(isp, ISP_LOGERR, "ATIO Queue Transfer Error");
5643 isp_prt(isp, ISP_LOGERR, "%s: unexpected ASYNC_QWAKEUP code", __func__);
5646 case ASYNC_CMD_CMPLT:
5647 isp_fastpost_complete(isp, (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1));
5648 if (isp->isp_fpcchiwater < 1) {
5649 isp->isp_fpcchiwater = 1;
5653 case ASYNC_RIOZIO_STALL:
5656 case ASYNC_CTIO_DONE:
5657 #ifdef ISP_TARGET_MODE
5658 if (isp_target_async(isp, (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1), mbox)) {
5661 isp->isp_fphccmplt++;
5664 isp_prt(isp, ISP_LOGWARN, "unexpected ASYNC CTIO done");
5667 case ASYNC_LIP_ERROR:
5669 case ASYNC_LIP_OCCURRED:
5672 * These are broadcast events that have to be sent across
5673 * all active channels.
5675 for (chan = 0; chan < isp->isp_nchan; chan++) {
5676 fcparam *fcp = FCPARAM(isp, chan);
5677 int topo = fcp->isp_topo;
5679 if (fcp->role == ISP_ROLE_NONE) {
5683 fcp->isp_fwstate = FW_CONFIG_WAIT;
5684 fcp->isp_loopstate = LOOP_LIP_RCVD;
5685 ISP_SET_SENDMARKER(isp, chan, 1);
5686 ISP_MARK_PORTDB(isp, chan, 1);
5687 isp_async(isp, ISPASYNC_LIP, chan);
5688 #ifdef ISP_TARGET_MODE
5689 if (isp_target_async(isp, chan, mbox)) {
5694 * We've had problems with data corruption occuring on
5695 * commands that complete (with no apparent error) after
5696 * we receive a LIP. This has been observed mostly on
5697 * Local Loop topologies. To be safe, let's just mark
5698 * all active initiator commands as dead.
5700 if (topo == TOPO_NL_PORT || topo == TOPO_FL_PORT) {
5702 for (i = j = 0; i < isp->isp_maxcmds; i++) {
5706 hdp = &isp->isp_xflist[i];
5707 if (ISP_H2HT(hdp->handle) != ISP_HANDLE_INITIATOR) {
5711 if (XS_CHANNEL(xs) != chan) {
5715 XS_SETERR(xs, HBA_BUSRESET);
5718 isp_prt(isp, ISP_LOGERR, lipd, chan, j);
5726 * This is a broadcast event that has to be sent across
5727 * all active channels.
5729 for (chan = 0; chan < isp->isp_nchan; chan++) {
5730 fcparam *fcp = FCPARAM(isp, chan);
5732 if (fcp->role == ISP_ROLE_NONE) {
5736 ISP_SET_SENDMARKER(isp, chan, 1);
5738 fcp->isp_fwstate = FW_CONFIG_WAIT;
5739 fcp->isp_loopstate = LOOP_LIP_RCVD;
5740 ISP_MARK_PORTDB(isp, chan, 1);
5741 isp_async(isp, ISPASYNC_LOOP_UP, chan);
5742 #ifdef ISP_TARGET_MODE
5743 if (isp_target_async(isp, chan, mbox)) {
5750 case ASYNC_LOOP_DOWN:
5752 * This is a broadcast event that has to be sent across
5753 * all active channels.
5755 for (chan = 0; chan < isp->isp_nchan; chan++) {
5756 fcparam *fcp = FCPARAM(isp, chan);
5758 if (fcp->role == ISP_ROLE_NONE) {
5762 ISP_SET_SENDMARKER(isp, chan, 1);
5763 fcp->isp_fwstate = FW_CONFIG_WAIT;
5764 fcp->isp_loopstate = LOOP_NIL;
5765 ISP_MARK_PORTDB(isp, chan, 1);
5766 isp_async(isp, ISPASYNC_LOOP_DOWN, chan);
5767 #ifdef ISP_TARGET_MODE
5768 if (isp_target_async(isp, chan, mbox)) {
5775 case ASYNC_LOOP_RESET:
5777 * This is a broadcast event that has to be sent across
5778 * all active channels.
5780 for (chan = 0; chan < isp->isp_nchan; chan++) {
5781 fcparam *fcp = FCPARAM(isp, chan);
5783 if (fcp->role == ISP_ROLE_NONE) {
5787 ISP_SET_SENDMARKER(isp, chan, 1);
5788 fcp->isp_fwstate = FW_CONFIG_WAIT;
5789 fcp->isp_loopstate = LOOP_NIL;
5790 ISP_MARK_PORTDB(isp, chan, 1);
5791 isp_async(isp, ISPASYNC_LOOP_RESET, chan);
5792 #ifdef ISP_TARGET_MODE
5793 if (isp_target_async(isp, chan, mbox)) {
5800 case ASYNC_PDB_CHANGED:
5802 int nphdl, nlstate, reason;
5804 * We *should* get a channel out of the 24XX, but we don't seem
5805 * to get more than a PDB CHANGED on channel 0, so turn it into
5806 * a broadcast event.
5809 nphdl = ISP_READ(isp, OUTMAILBOX1);
5810 nlstate = ISP_READ(isp, OUTMAILBOX2);
5811 reason = ISP_READ(isp, OUTMAILBOX3) >> 8;
5814 nlstate = reason = 0;
5816 for (chan = 0; chan < isp->isp_nchan; chan++) {
5817 fcparam *fcp = FCPARAM(isp, chan);
5819 if (fcp->role == ISP_ROLE_NONE) {
5822 ISP_SET_SENDMARKER(isp, chan, 1);
5823 fcp->isp_loopstate = LOOP_PDB_RCVD;
5824 ISP_MARK_PORTDB(isp, chan, 1);
5825 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan, ISPASYNC_CHANGE_PDB, nphdl, nlstate, reason);
5829 case ASYNC_CHANGE_NOTIFY:
5833 if (ISP_FW_NEWER_THAN(isp, 4, 0, 25) && ISP_CAP_MULTI_ID(isp)) {
5834 GET_24XX_BUS(isp, chan, "ASYNC_CHANGE_NOTIFY");
5839 hichan = isp->isp_nchan;
5841 for (chan = lochan; chan < hichan; chan++) {
5842 fcparam *fcp = FCPARAM(isp, chan);
5844 if (fcp->role == ISP_ROLE_NONE) {
5848 if (fcp->isp_topo == TOPO_F_PORT) {
5849 fcp->isp_loopstate = LOOP_LSCAN_DONE;
5851 fcp->isp_loopstate = LOOP_PDB_RCVD;
5853 ISP_MARK_PORTDB(isp, chan, 1);
5854 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan, ISPASYNC_CHANGE_SNS);
5859 case ASYNC_CONNMODE:
5861 * This only applies to 2100 amd 2200 cards
5863 if (!IS_2200(isp) && !IS_2100(isp)) {
5864 isp_prt(isp, ISP_LOGWARN, "bad card for ASYNC_CONNMODE event");
5868 mbox = ISP_READ(isp, OUTMAILBOX1);
5869 ISP_MARK_PORTDB(isp, chan, 1);
5872 isp_prt(isp, ISP_LOGINFO,
5873 "Point-to-Point -> Loop mode");
5876 isp_prt(isp, ISP_LOGINFO,
5877 "Loop -> Point-to-Point mode");
5879 case ISP_CONN_BADLIP:
5880 isp_prt(isp, ISP_LOGWARN,
5881 "Point-to-Point -> Loop mode (BAD LIP)");
5883 case ISP_CONN_FATAL:
5885 isp->isp_state = ISP_CRASHED;
5886 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
5887 isp_async(isp, ISPASYNC_FW_CRASH);
5889 case ISP_CONN_LOOPBACK:
5890 isp_prt(isp, ISP_LOGWARN,
5891 "Looped Back in Point-to-Point mode");
5894 isp_prt(isp, ISP_LOGWARN,
5895 "Unknown connection mode (0x%x)", mbox);
5898 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan, ISPASYNC_CHANGE_OTHER);
5899 FCPARAM(isp, chan)->sendmarker = 1;
5900 FCPARAM(isp, chan)->isp_fwstate = FW_CONFIG_WAIT;
5901 FCPARAM(isp, chan)->isp_loopstate = LOOP_LIP_RCVD;
5906 isp_prt(isp, ISP_LOGWARN, "Receive Error");
5908 isp_prt(isp, ISP_LOGWARN, "unexpected ASYNC_RCV_ERR");
5911 case ASYNC_RJT_SENT: /* same as ASYNC_QFULL_SENT */
5913 isp_prt(isp, ISP_LOGTDEBUG0, "LS_RJT sent");
5915 } else if (IS_2200(isp)) {
5916 isp_prt(isp, ISP_LOGTDEBUG0, "QFULL sent");
5921 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
5924 if (mbox != ASYNC_CTIO_DONE && mbox != ASYNC_CMD_CMPLT) {
5925 isp->isp_intoasync++;
5931 * Handle other response entries. A pointer to the request queue output
5932 * index is here in case we want to eat several entries at once, although
5933 * this is not used currently.
5937 isp_handle_other_response(ispsoftc_t *isp, int type,
5938 isphdr_t *hp, uint32_t *optrp)
5941 case RQSTYPE_STATUS_CONT:
5942 isp_prt(isp, ISP_LOGDEBUG0, "Ignored Continuation Response");
5944 case RQSTYPE_MARKER:
5945 isp_prt(isp, ISP_LOGDEBUG0, "Marker Response");
5949 case RQSTYPE_ENABLE_LUN:
5950 case RQSTYPE_MODIFY_LUN:
5951 case RQSTYPE_NOTIFY:
5952 case RQSTYPE_NOTIFY_ACK:
5958 case RQSTYPE_ABTS_RCVD:
5959 case RQSTYPE_ABTS_RSP:
5960 isp->isp_rsltccmplt++; /* count as a response completion */
5961 #ifdef ISP_TARGET_MODE
5962 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
5967 case RQSTYPE_RPT_ID_ACQ:
5970 isp_get_ridacq(isp, (isp_ridacq_t *)hp, &rid);
5971 if (rid.ridacq_format == 0) {
5976 case RQSTYPE_REQUEST:
5979 if (type != isp_get_response_type(isp, hp)) {
5981 * This is questionable- we're just papering over
5982 * something we've seen on SMP linux in target
5983 * mode- we don't really know what's happening
5984 * here that causes us to think we've gotten
5985 * an entry, but that either the entry isn't
5986 * filled out yet or our CPU read data is stale.
5988 isp_prt(isp, ISP_LOGINFO,
5989 "unstable type in response queue");
5992 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
5993 isp_get_response_type(isp, hp));
5999 isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
6001 switch (sp->req_completion_status & 0xff) {
6004 XS_SETERR(xs, HBA_NOERROR);
6008 case RQCS_INCOMPLETE:
6009 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
6010 isp_prt(isp, ISP_LOGDEBUG1,
6011 "Selection Timeout for %d.%d.%d",
6012 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6014 XS_SETERR(xs, HBA_SELTIMEOUT);
6015 *rp = XS_XFRLEN(xs);
6019 isp_prt(isp, ISP_LOGERR,
6020 "command incomplete for %d.%d.%d, state 0x%x",
6021 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
6022 sp->req_state_flags);
6025 case RQCS_DMA_ERROR:
6026 isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
6027 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6028 *rp = XS_XFRLEN(xs);
6031 case RQCS_TRANSPORT_ERROR:
6034 ISP_SNPRINTF(buf, sizeof (buf), "states=>");
6035 if (sp->req_state_flags & RQSF_GOT_BUS) {
6036 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
6038 if (sp->req_state_flags & RQSF_GOT_TARGET) {
6039 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
6041 if (sp->req_state_flags & RQSF_SENT_CDB) {
6042 ISP_SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
6044 if (sp->req_state_flags & RQSF_XFRD_DATA) {
6045 ISP_SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
6047 if (sp->req_state_flags & RQSF_GOT_STATUS) {
6048 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
6050 if (sp->req_state_flags & RQSF_GOT_SENSE) {
6051 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
6053 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
6054 ISP_SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
6056 ISP_SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
6057 if (sp->req_status_flags & RQSTF_DISCONNECT) {
6058 ISP_SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
6060 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
6061 ISP_SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
6063 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
6064 ISP_SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
6066 if (sp->req_status_flags & RQSTF_BUS_RESET) {
6067 ISP_SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
6069 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
6070 ISP_SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
6072 if (sp->req_status_flags & RQSTF_ABORTED) {
6073 ISP_SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
6075 if (sp->req_status_flags & RQSTF_TIMEOUT) {
6076 ISP_SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
6078 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
6079 ISP_SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
6081 isp_prt(isp, ISP_LOGERR, "%s", buf);
6082 isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d:\n%s",
6083 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), buf);
6084 *rp = XS_XFRLEN(xs);
6087 case RQCS_RESET_OCCURRED:
6090 isp_prt(isp, ISP_LOGWARN,
6091 "bus reset destroyed command for %d.%d.%d",
6092 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6093 for (chan = 0; chan < isp->isp_nchan; chan++) {
6094 FCPARAM(isp, chan)->sendmarker = 1;
6097 XS_SETERR(xs, HBA_BUSRESET);
6099 *rp = XS_XFRLEN(xs);
6103 isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
6104 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6105 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 1);
6107 XS_SETERR(xs, HBA_ABORTED);
6112 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
6113 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6115 * XXX: Check to see if we logged out of the device.
6118 XS_SETERR(xs, HBA_CMDTIMEOUT);
6122 case RQCS_DATA_OVERRUN:
6123 XS_SET_RESID(xs, sp->req_resid);
6124 isp_prt(isp, ISP_LOGERR, "data overrun (%ld) for command on %d.%d.%d",
6125 (long) XS_GET_RESID(xs), XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6127 XS_SETERR(xs, HBA_DATAOVR);
6131 case RQCS_COMMAND_OVERRUN:
6132 isp_prt(isp, ISP_LOGERR,
6133 "command overrun for command on %d.%d.%d",
6134 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6137 case RQCS_STATUS_OVERRUN:
6138 isp_prt(isp, ISP_LOGERR,
6139 "status overrun for command on %d.%d.%d",
6140 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6143 case RQCS_BAD_MESSAGE:
6144 isp_prt(isp, ISP_LOGERR,
6145 "msg not COMMAND COMPLETE after status %d.%d.%d",
6146 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6149 case RQCS_NO_MESSAGE_OUT:
6150 isp_prt(isp, ISP_LOGERR,
6151 "No MESSAGE OUT phase after selection on %d.%d.%d",
6152 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6155 case RQCS_EXT_ID_FAILED:
6156 isp_prt(isp, ISP_LOGERR, "EXTENDED IDENTIFY failed %d.%d.%d",
6157 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6160 case RQCS_IDE_MSG_FAILED:
6161 isp_prt(isp, ISP_LOGERR,
6162 "INITIATOR DETECTED ERROR rejected by %d.%d.%d",
6163 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6166 case RQCS_ABORT_MSG_FAILED:
6167 isp_prt(isp, ISP_LOGERR, "ABORT OPERATION rejected by %d.%d.%d",
6168 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6171 case RQCS_REJECT_MSG_FAILED:
6172 isp_prt(isp, ISP_LOGERR, "MESSAGE REJECT rejected by %d.%d.%d",
6173 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6176 case RQCS_NOP_MSG_FAILED:
6177 isp_prt(isp, ISP_LOGERR, "NOP rejected by %d.%d.%d",
6178 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6181 case RQCS_PARITY_ERROR_MSG_FAILED:
6182 isp_prt(isp, ISP_LOGERR,
6183 "MESSAGE PARITY ERROR rejected by %d.%d.%d",
6184 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6187 case RQCS_DEVICE_RESET_MSG_FAILED:
6188 isp_prt(isp, ISP_LOGWARN,
6189 "BUS DEVICE RESET rejected by %d.%d.%d",
6190 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6193 case RQCS_ID_MSG_FAILED:
6194 isp_prt(isp, ISP_LOGERR, "IDENTIFY rejected by %d.%d.%d",
6195 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6198 case RQCS_UNEXP_BUS_FREE:
6199 isp_prt(isp, ISP_LOGERR, "%d.%d.%d had an unexpected bus free",
6200 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6203 case RQCS_DATA_UNDERRUN:
6206 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
6207 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
6208 isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
6209 XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
6210 (ru_marked)? "marked" : "not marked");
6212 XS_SETERR(xs, HBA_BOTCH);
6217 XS_SET_RESID(xs, sp->req_resid);
6219 XS_SETERR(xs, HBA_NOERROR);
6224 case RQCS_XACT_ERR1:
6225 isp_prt(isp, ISP_LOGERR, xact1, XS_CHANNEL(xs),
6226 XS_TGT(xs), XS_LUN(xs));
6229 case RQCS_XACT_ERR2:
6230 isp_prt(isp, ISP_LOGERR, xact2,
6231 XS_LUN(xs), XS_TGT(xs), XS_CHANNEL(xs));
6234 case RQCS_XACT_ERR3:
6235 isp_prt(isp, ISP_LOGERR, xact3,
6236 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6239 case RQCS_BAD_ENTRY:
6240 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
6243 case RQCS_QUEUE_FULL:
6244 isp_prt(isp, ISP_LOGDEBUG0,
6245 "internal queues full for %d.%d.%d status 0x%x",
6246 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs), *XS_STSP(xs));
6249 * If QFULL or some other status byte is set, then this
6250 * isn't an error, per se.
6252 * Unfortunately, some QLogic f/w writers have, in
6253 * some cases, ommitted to *set* status to QFULL.
6256 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
6257 XS_SETERR(xs, HBA_NOERROR);
6265 *XS_STSP(xs) = SCSI_QFULL;
6266 XS_SETERR(xs, HBA_NOERROR);
6269 case RQCS_PHASE_SKIPPED:
6270 isp_prt(isp, ISP_LOGERR, pskip, XS_CHANNEL(xs),
6271 XS_TGT(xs), XS_LUN(xs));
6274 case RQCS_ARQS_FAILED:
6275 isp_prt(isp, ISP_LOGERR,
6276 "Auto Request Sense failed for %d.%d.%d",
6277 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6279 XS_SETERR(xs, HBA_ARQFAIL);
6283 case RQCS_WIDE_FAILED:
6284 isp_prt(isp, ISP_LOGERR,
6285 "Wide Negotiation failed for %d.%d.%d",
6286 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
6288 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
6289 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
6290 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
6294 XS_SETERR(xs, HBA_NOERROR);
6298 case RQCS_SYNCXFER_FAILED:
6299 isp_prt(isp, ISP_LOGERR,
6300 "SDTR Message failed for target %d.%d.%d",
6301 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
6303 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
6304 sdp += XS_CHANNEL(xs);
6305 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
6306 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
6311 case RQCS_LVD_BUSERR:
6312 isp_prt(isp, ISP_LOGERR,
6313 "Bad LVD condition while talking to %d.%d.%d",
6314 XS_TGT(xs), XS_LUN(xs), XS_CHANNEL(xs));
6317 case RQCS_PORT_UNAVAILABLE:
6319 * No such port on the loop. Moral equivalent of SELTIMEO
6321 case RQCS_PORT_LOGGED_OUT:
6324 uint8_t sts = sp->req_completion_status & 0xff;
6327 * It was there (maybe)- treat as a selection timeout.
6329 if (sts == RQCS_PORT_UNAVAILABLE) {
6330 reason = "unavailable";
6335 isp_prt(isp, ISP_LOGINFO, "port %s for target %d",
6336 reason, XS_TGT(xs));
6339 * If we're on a local loop, force a LIP (which is overkill)
6340 * to force a re-login of this unit. If we're on fabric,
6341 * then we'll have to log in again as a matter of course.
6343 if (FCPARAM(isp, 0)->isp_topo == TOPO_NL_PORT ||
6344 FCPARAM(isp, 0)->isp_topo == TOPO_FL_PORT) {
6346 MBSINIT(&mbs, MBOX_INIT_LIP, MBLOGALL, 0);
6347 if (ISP_CAP_2KLOGIN(isp)) {
6348 mbs.ibits = (1 << 10);
6350 isp_mboxcmd_qnw(isp, &mbs, 1);
6353 XS_SETERR(xs, HBA_SELTIMEOUT);
6357 case RQCS_PORT_CHANGED:
6358 isp_prt(isp, ISP_LOGWARN,
6359 "port changed for target %d", XS_TGT(xs));
6361 XS_SETERR(xs, HBA_SELTIMEOUT);
6365 case RQCS_PORT_BUSY:
6366 isp_prt(isp, ISP_LOGWARN,
6367 "port busy for target %d", XS_TGT(xs));
6369 XS_SETERR(xs, HBA_TGTBSY);
6374 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x",
6375 sp->req_completion_status);
6379 XS_SETERR(xs, HBA_BOTCH);
6384 isp_parse_status_24xx(ispsoftc_t *isp, isp24xx_statusreq_t *sp,
6387 int ru_marked, sv_marked;
6388 int chan = XS_CHANNEL(xs);
6390 switch (sp->req_completion_status) {
6393 XS_SETERR(xs, HBA_NOERROR);
6397 case RQCS_DMA_ERROR:
6398 isp_prt(isp, ISP_LOGERR, "DMA error for command on %d.%d.%d",
6399 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6402 case RQCS_TRANSPORT_ERROR:
6403 isp_prt(isp, ISP_LOGERR, "transport error for %d.%d.%d",
6404 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6407 case RQCS_RESET_OCCURRED:
6408 isp_prt(isp, ISP_LOGWARN,
6409 "reset destroyed command for %d.%d.%d",
6410 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6411 FCPARAM(isp, chan)->sendmarker = 1;
6413 XS_SETERR(xs, HBA_BUSRESET);
6418 isp_prt(isp, ISP_LOGERR, "command aborted for %d.%d.%d",
6419 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6420 FCPARAM(isp, chan)->sendmarker = 1;
6422 XS_SETERR(xs, HBA_ABORTED);
6427 isp_prt(isp, ISP_LOGWARN, "command timed out for %d.%d.%d",
6428 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6430 XS_SETERR(xs, HBA_CMDTIMEOUT);
6434 case RQCS_DATA_OVERRUN:
6435 XS_SET_RESID(xs, sp->req_resid);
6436 isp_prt(isp, ISP_LOGERR,
6437 "data overrun for command on %d.%d.%d",
6438 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs));
6440 XS_SETERR(xs, HBA_DATAOVR);
6444 case RQCS_24XX_DRE: /* data reassembly error */
6445 isp_prt(isp, ISP_LOGERR,
6446 "Chan %d data reassembly error for target %d",
6449 XS_SETERR(xs, HBA_ABORTED);
6451 *rp = XS_XFRLEN(xs);
6454 case RQCS_24XX_TABORT: /* aborted by target */
6455 isp_prt(isp, ISP_LOGERR, "Chan %d target %d sent ABTS",
6458 XS_SETERR(xs, HBA_ABORTED);
6462 case RQCS_DATA_UNDERRUN:
6463 ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
6465 * We can get an underrun w/o things being marked
6466 * if we got a non-zero status.
6468 sv_marked = (sp->req_scsi_status & (RQCS_SV|RQCS_RV)) != 0;
6469 if ((ru_marked == 0 && sv_marked == 0) ||
6470 (sp->req_resid > XS_XFRLEN(xs))) {
6471 isp_prt(isp, ISP_LOGWARN, bun, XS_TGT(xs),
6472 XS_LUN(xs), XS_XFRLEN(xs), sp->req_resid,
6473 (ru_marked)? "marked" : "not marked");
6475 XS_SETERR(xs, HBA_BOTCH);
6479 XS_SET_RESID(xs, sp->req_resid);
6480 isp_prt(isp, ISP_LOGDEBUG0,
6481 "%d.%d.%d data underrun (%d) for command 0x%x",
6482 XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
6483 sp->req_resid, XS_CDBP(xs)[0] & 0xff);
6485 XS_SETERR(xs, HBA_NOERROR);
6489 case RQCS_PORT_UNAVAILABLE:
6491 * No such port on the loop. Moral equivalent of SELTIMEO
6493 case RQCS_PORT_LOGGED_OUT:
6496 uint8_t sts = sp->req_completion_status & 0xff;
6499 * It was there (maybe)- treat as a selection timeout.
6501 if (sts == RQCS_PORT_UNAVAILABLE) {
6502 reason = "unavailable";
6507 isp_prt(isp, ISP_LOGINFO, "Chan %d port %s for target %d",
6508 chan, reason, XS_TGT(xs));
6511 * There is no MBOX_INIT_LIP for the 24XX.
6514 XS_SETERR(xs, HBA_SELTIMEOUT);
6518 case RQCS_PORT_CHANGED:
6519 isp_prt(isp, ISP_LOGWARN,
6520 "port changed for target %d chan %d", XS_TGT(xs), chan);
6522 XS_SETERR(xs, HBA_SELTIMEOUT);
6527 case RQCS_24XX_ENOMEM: /* f/w resource unavailable */
6528 isp_prt(isp, ISP_LOGWARN,
6529 "f/w resource unavailable for target %d chan %d",
6532 *XS_STSP(xs) = SCSI_BUSY;
6533 XS_SETERR(xs, HBA_TGTBSY);
6537 case RQCS_24XX_TMO: /* task management overrun */
6538 isp_prt(isp, ISP_LOGWARN,
6539 "command for target %d overlapped task management for "
6540 "chan %d", XS_TGT(xs), chan);
6542 *XS_STSP(xs) = SCSI_BUSY;
6543 XS_SETERR(xs, HBA_TGTBSY);
6548 isp_prt(isp, ISP_LOGERR,
6549 "Unknown Completion Status 0x%x on chan %d",
6550 sp->req_completion_status, chan);
6554 XS_SETERR(xs, HBA_BOTCH);
6559 isp_fastpost_complete(ispsoftc_t *isp, uint32_t fph)
6566 xs = isp_find_xs(isp, fph);
6568 isp_prt(isp, ISP_LOGWARN,
6569 "Command for fast post handle 0x%x not found", fph);
6572 isp_destroy_handle(isp, fph);
6575 * Since we don't have a result queue entry item,
6576 * we must believe that SCSI status is zero and
6577 * that all data transferred.
6579 XS_SET_RESID(xs, 0);
6580 *XS_STSP(xs) = SCSI_GOOD;
6581 if (XS_XFRLEN(xs)) {
6582 ISP_DMAFREE(isp, xs, fph);
6584 if (isp->isp_nactive) {
6587 isp->isp_fphccmplt++;
6592 isp_mbox_continue(ispsoftc_t *isp)
6598 switch (isp->isp_lastmbxcmd) {
6599 case MBOX_WRITE_RAM_WORD:
6600 case MBOX_READ_RAM_WORD:
6601 case MBOX_WRITE_RAM_WORD_EXTENDED:
6602 case MBOX_READ_RAM_WORD_EXTENDED:
6607 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
6608 isp->isp_mbxwrk0 = 0;
6613 * Clear the previous interrupt.
6616 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
6618 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
6619 ISP_WRITE(isp, BIU_SEMA, 0);
6623 * Continue with next word.
6625 ISP_MEMZERO(&mbs, sizeof (mbs));
6626 ptr = isp->isp_mbxworkp;
6627 switch (isp->isp_lastmbxcmd) {
6628 case MBOX_WRITE_RAM_WORD:
6629 mbs.param[1] = isp->isp_mbxwrk1++;
6630 mbs.param[2] = *ptr++;
6632 case MBOX_READ_RAM_WORD:
6633 *ptr++ = isp->isp_mboxtmp[2];
6634 mbs.param[1] = isp->isp_mbxwrk1++;
6636 case MBOX_WRITE_RAM_WORD_EXTENDED:
6637 offset = isp->isp_mbxwrk1;
6638 offset |= isp->isp_mbxwrk8 << 16;
6640 mbs.param[2] = *ptr++;
6641 mbs.param[1] = offset;
6642 mbs.param[8] = offset >> 16;
6643 isp->isp_mbxwrk1 = ++offset;
6644 isp->isp_mbxwrk8 = offset >> 16;
6646 case MBOX_READ_RAM_WORD_EXTENDED:
6647 offset = isp->isp_mbxwrk1;
6648 offset |= isp->isp_mbxwrk8 << 16;
6650 *ptr++ = isp->isp_mboxtmp[2];
6651 mbs.param[1] = offset;
6652 mbs.param[8] = offset >> 16;
6653 isp->isp_mbxwrk1 = ++offset;
6654 isp->isp_mbxwrk8 = offset >> 16;
6657 isp->isp_mbxworkp = ptr;
6659 mbs.param[0] = isp->isp_lastmbxcmd;
6660 mbs.logval = MBLOGALL;
6661 isp_mboxcmd_qnw(isp, &mbs, 0);
6665 #define HIWRD(x) ((x) >> 16)
6666 #define LOWRD(x) ((x) & 0xffff)
6667 #define ISPOPMAP(a, b) (((a) << 16) | (b))
6668 static const uint32_t mbpscsi[] = {
6669 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
6670 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
6671 ISPOPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
6672 ISPOPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
6673 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
6674 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
6675 ISPOPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
6676 ISPOPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
6677 ISPOPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
6678 ISPOPMAP(0x00, 0x00), /* 0x09: */
6679 ISPOPMAP(0x00, 0x00), /* 0x0a: */
6680 ISPOPMAP(0x00, 0x00), /* 0x0b: */
6681 ISPOPMAP(0x00, 0x00), /* 0x0c: */
6682 ISPOPMAP(0x00, 0x00), /* 0x0d: */
6683 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
6684 ISPOPMAP(0x00, 0x00), /* 0x0f: */
6685 ISPOPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
6686 ISPOPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
6687 ISPOPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
6688 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
6689 ISPOPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
6690 ISPOPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
6691 ISPOPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
6692 ISPOPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
6693 ISPOPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
6694 ISPOPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
6695 ISPOPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
6696 ISPOPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
6697 ISPOPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
6698 ISPOPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
6699 ISPOPMAP(0x00, 0x00), /* 0x1e: */
6700 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
6701 ISPOPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
6702 ISPOPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
6703 ISPOPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
6704 ISPOPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
6705 ISPOPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
6706 ISPOPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
6707 ISPOPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
6708 ISPOPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
6709 ISPOPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
6710 ISPOPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
6711 ISPOPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
6712 ISPOPMAP(0x00, 0x00), /* 0x2b: */
6713 ISPOPMAP(0x00, 0x00), /* 0x2c: */
6714 ISPOPMAP(0x00, 0x00), /* 0x2d: */
6715 ISPOPMAP(0x00, 0x00), /* 0x2e: */
6716 ISPOPMAP(0x00, 0x00), /* 0x2f: */
6717 ISPOPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
6718 ISPOPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
6719 ISPOPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
6720 ISPOPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
6721 ISPOPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
6722 ISPOPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
6723 ISPOPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
6724 ISPOPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
6725 ISPOPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
6726 ISPOPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
6727 ISPOPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
6728 ISPOPMAP(0x00, 0x00), /* 0x3b: */
6729 ISPOPMAP(0x00, 0x00), /* 0x3c: */
6730 ISPOPMAP(0x00, 0x00), /* 0x3d: */
6731 ISPOPMAP(0x00, 0x00), /* 0x3e: */
6732 ISPOPMAP(0x00, 0x00), /* 0x3f: */
6733 ISPOPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
6734 ISPOPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
6735 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
6736 ISPOPMAP(0x00, 0x00), /* 0x43: */
6737 ISPOPMAP(0x00, 0x00), /* 0x44: */
6738 ISPOPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
6739 ISPOPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
6740 ISPOPMAP(0x00, 0x00), /* 0x47: */
6741 ISPOPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
6742 ISPOPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
6743 ISPOPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
6744 ISPOPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
6745 ISPOPMAP(0x00, 0x00), /* 0x4c: */
6746 ISPOPMAP(0x00, 0x00), /* 0x4d: */
6747 ISPOPMAP(0x00, 0x00), /* 0x4e: */
6748 ISPOPMAP(0x00, 0x00), /* 0x4f: */
6749 ISPOPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
6750 ISPOPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
6751 ISPOPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
6752 ISPOPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
6753 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUCUTE COMMAND IOCB A64 */
6754 ISPOPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
6755 ISPOPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
6756 ISPOPMAP(0x00, 0x00), /* 0x57: */
6757 ISPOPMAP(0x00, 0x00), /* 0x58: */
6758 ISPOPMAP(0x00, 0x00), /* 0x59: */
6759 ISPOPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
6760 ISPOPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
6761 ISPOPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
6762 ISPOPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
6765 static const char *scsi_mbcmd_names[] = {
6782 "INIT REQUEST QUEUE",
6783 "INIT RESULT QUEUE",
6793 "SINGLE STEP QUEUE",
6795 "GET DEV QUEUE STATUS",
6797 "GET FIRMWARE STATUS",
6799 "GET SELECT TIMEOUT",
6801 "GET TAG AGE LIMIT",
6803 "GET ACT NEG STATE",
6804 "GET ASYNC DATA SETUP TIME",
6806 "GET TARGET PARAMS",
6807 "GET DEV QUEUE PARAMS",
6808 "GET RESET DELAY PARAMS",
6815 "SET SELECT TIMEOUT",
6817 "SET TAG AGE LIMIT",
6819 "SET ACT NEG STATE",
6820 "SET ASYNC DATA SETUP TIME",
6821 "SET PCI CONTROL PARAMS",
6822 "SET TARGET PARAMS",
6823 "SET DEV QUEUE PARAMS",
6824 "SET RESET DELAY PARAMS",
6830 "RETURN BIOS BLOCK ADDR",
6831 "WRITE FOUR RAM WORDS",
6835 "SET SYSTEM PARAMETER",
6836 "GET SYSTEM PARAMETER",
6838 "GET SCAM CONFIGURATION",
6839 "SET SCAM CONFIGURATION",
6840 "SET FIRMWARE FEATURES",
6841 "GET FIRMWARE FEATURES",
6848 "INITIALIZE REQUEST QUEUE A64",
6849 "INITIALIZE RESPONSE QUEUE A64",
6851 "ENABLE TARGET MODE",
6852 "GET TARGET MODE STATE",
6856 "SET DATA OVERRUN RECOVERY MODE",
6857 "GET DATA OVERRUN RECOVERY MODE",
6862 static const uint32_t mbpfc[] = {
6863 ISPOPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
6864 ISPOPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
6865 ISPOPMAP(0x0f, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
6866 ISPOPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
6867 ISPOPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
6868 ISPOPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
6869 ISPOPMAP(0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
6870 ISPOPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
6871 ISPOPMAP(0x01, 0x4f), /* 0x08: MBOX_ABOUT_FIRMWARE */
6872 ISPOPMAP(0xdf, 0x01), /* 0x09: MBOX_LOAD_RISC_RAM_2100 */
6873 ISPOPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
6874 ISPOPMAP(0x1ff, 0x01), /* 0x0b: MBOX_LOAD_RISC_RAM */
6875 ISPOPMAP(0x00, 0x00), /* 0x0c: */
6876 ISPOPMAP(0x10f, 0x01), /* 0x0d: MBOX_WRITE_RAM_WORD_EXTENDED */
6877 ISPOPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
6878 ISPOPMAP(0x10f, 0x05), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED */
6879 ISPOPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
6880 ISPOPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
6881 ISPOPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
6882 ISPOPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
6883 ISPOPMAP(0x01, 0xff), /* 0x14: MBOX_STOP_FIRMWARE */
6884 ISPOPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
6885 ISPOPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
6886 ISPOPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
6887 ISPOPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
6888 ISPOPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
6889 ISPOPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
6890 ISPOPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
6891 ISPOPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
6892 ISPOPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
6893 ISPOPMAP(0x00, 0x00), /* 0x1e: */
6894 ISPOPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
6895 ISPOPMAP(0x01, 0x4f), /* 0x20: MBOX_GET_LOOP_ID */
6896 ISPOPMAP(0x00, 0x00), /* 0x21: */
6897 ISPOPMAP(0x01, 0x07), /* 0x22: MBOX_GET_RETRY_COUNT */
6898 ISPOPMAP(0x00, 0x00), /* 0x23: */
6899 ISPOPMAP(0x00, 0x00), /* 0x24: */
6900 ISPOPMAP(0x00, 0x00), /* 0x25: */
6901 ISPOPMAP(0x00, 0x00), /* 0x26: */
6902 ISPOPMAP(0x00, 0x00), /* 0x27: */
6903 ISPOPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
6904 ISPOPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
6905 ISPOPMAP(0x00, 0x00), /* 0x2a: */
6906 ISPOPMAP(0x00, 0x00), /* 0x2b: */
6907 ISPOPMAP(0x00, 0x00), /* 0x2c: */
6908 ISPOPMAP(0x00, 0x00), /* 0x2d: */
6909 ISPOPMAP(0x00, 0x00), /* 0x2e: */
6910 ISPOPMAP(0x00, 0x00), /* 0x2f: */
6911 ISPOPMAP(0x00, 0x00), /* 0x30: */
6912 ISPOPMAP(0x00, 0x00), /* 0x31: */
6913 ISPOPMAP(0x07, 0x07), /* 0x32: MBOX_SET_RETRY_COUNT */
6914 ISPOPMAP(0x00, 0x00), /* 0x33: */
6915 ISPOPMAP(0x00, 0x00), /* 0x34: */
6916 ISPOPMAP(0x00, 0x00), /* 0x35: */
6917 ISPOPMAP(0x00, 0x00), /* 0x36: */
6918 ISPOPMAP(0x00, 0x00), /* 0x37: */
6919 ISPOPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
6920 ISPOPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
6921 ISPOPMAP(0x00, 0x00), /* 0x3a: */
6922 ISPOPMAP(0x00, 0x00), /* 0x3b: */
6923 ISPOPMAP(0x00, 0x00), /* 0x3c: */
6924 ISPOPMAP(0x00, 0x00), /* 0x3d: */
6925 ISPOPMAP(0x00, 0x00), /* 0x3e: */
6926 ISPOPMAP(0x00, 0x00), /* 0x3f: */
6927 ISPOPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
6928 ISPOPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
6929 ISPOPMAP(0x03, 0x07), /* 0x42: MBOX_GET_RESOURCE_COUNT */
6930 ISPOPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_OFFLINE_MODE */
6931 ISPOPMAP(0x00, 0x00), /* 0x44: */
6932 ISPOPMAP(0x00, 0x00), /* 0x45: */
6933 ISPOPMAP(0x00, 0x00), /* 0x46: */
6934 ISPOPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
6935 ISPOPMAP(0xcd, 0x01), /* 0x48: MBOX_INIT_FIRMWARE_MULTI_ID */
6936 ISPOPMAP(0xcd, 0x01), /* 0x49: MBOX_GET_VP_DATABASE */
6937 ISPOPMAP(0x2cd, 0x01), /* 0x4a: MBOX_GET_VP_DATABASE_ENTRY */
6938 ISPOPMAP(0x00, 0x00), /* 0x4b: */
6939 ISPOPMAP(0x00, 0x00), /* 0x4c: */
6940 ISPOPMAP(0x00, 0x00), /* 0x4d: */
6941 ISPOPMAP(0x00, 0x00), /* 0x4e: */
6942 ISPOPMAP(0x00, 0x00), /* 0x4f: */
6943 ISPOPMAP(0x00, 0x00), /* 0x50: */
6944 ISPOPMAP(0x00, 0x00), /* 0x51: */
6945 ISPOPMAP(0x00, 0x00), /* 0x52: */
6946 ISPOPMAP(0x00, 0x00), /* 0x53: */
6947 ISPOPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
6948 ISPOPMAP(0x00, 0x00), /* 0x55: */
6949 ISPOPMAP(0x00, 0x00), /* 0x56: */
6950 ISPOPMAP(0x00, 0x00), /* 0x57: */
6951 ISPOPMAP(0x00, 0x00), /* 0x58: */
6952 ISPOPMAP(0x00, 0x00), /* 0x59: */
6953 ISPOPMAP(0x00, 0x00), /* 0x5a: */
6954 ISPOPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
6955 ISPOPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
6956 ISPOPMAP(0x07, 0x03), /* 0x5d: MBOX_GET_SET_DATA_RATE */
6957 ISPOPMAP(0x00, 0x00), /* 0x5e: */
6958 ISPOPMAP(0x00, 0x00), /* 0x5f: */
6959 ISPOPMAP(0xcd, 0x01), /* 0x60: MBOX_INIT_FIRMWARE */
6960 ISPOPMAP(0x00, 0x00), /* 0x61: */
6961 ISPOPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
6962 ISPOPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
6963 ISPOPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
6964 ISPOPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
6965 ISPOPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
6966 ISPOPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
6967 ISPOPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
6968 ISPOPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
6969 ISPOPMAP(0x03, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
6970 ISPOPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
6971 ISPOPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
6972 ISPOPMAP(0x00, 0x00), /* 0x6d: */
6973 ISPOPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
6974 ISPOPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
6975 ISPOPMAP(0x03, 0x01), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
6976 ISPOPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
6977 ISPOPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
6978 ISPOPMAP(0x00, 0x00), /* 0x73: */
6979 ISPOPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
6980 ISPOPMAP(0xcf, 0x03), /* 0x75: GET PORT/NODE NAME LIST */
6981 ISPOPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
6982 ISPOPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
6983 ISPOPMAP(0x00, 0x00), /* 0x78: */
6984 ISPOPMAP(0x00, 0x00), /* 0x79: */
6985 ISPOPMAP(0x00, 0x00), /* 0x7a: */
6986 ISPOPMAP(0x00, 0x00), /* 0x7b: */
6987 ISPOPMAP(0x4f, 0x03), /* 0x7c: Get ID List */
6988 ISPOPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
6989 ISPOPMAP(0x0f, 0x01) /* 0x7e: LUN RESET */
6994 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
6995 * do not access at this time in the core driver. The caller is
6996 * responsible for setting this register first (Gross!). The assumption
6997 * is that we won't overflow.
7000 static const char *fc_mbcmd_names[] = {
7012 "WRITE RAM WORD EXTENDED",
7014 "READ RAM WORD EXTENDED",
7017 "INIT REQUEST QUEUE",
7018 "INIT RESULT QUEUE",
7028 "SINGLE STEP QUEUE",
7030 "GET DEV QUEUE STATUS",
7032 "GET FIRMWARE STATUS",
7041 "GET FIRMWARE OPTIONS",
7042 "GET PORT QUEUE PARAMS",
7057 "SET FIRMWARE OPTIONS",
7058 "SET PORT QUEUE PARAMS",
7067 "GET RESOURCE COUNT",
7068 "REQUEST NON PARTICIPATING MODE",
7072 "GET PORT DATABASE ENHANCED",
7073 "INIT FIRMWARE MULTI ID",
7075 "GET VP DATABASE ENTRY",
7094 "GET/SET DATA RATE",
7100 "GET FC-AL POSITION MAP",
7101 "GET PORT DATABASE",
7113 "SEND CHANGE REQUEST",
7118 "GET PORT/NODE NAME LIST",
7120 "INITIALIZE IP MAILBOX",
7131 isp_mboxcmd_qnw(ispsoftc_t *isp, mbreg_t *mbp, int nodelay)
7133 unsigned int ibits, obits, box, opcode;
7134 const uint32_t *mcp;
7141 opcode = mbp->param[0];
7142 ibits = HIWRD(mcp[opcode]) & NMBOX_BMASK(isp);
7143 obits = LOWRD(mcp[opcode]) & NMBOX_BMASK(isp);
7144 ibits |= mbp->ibits;
7145 obits |= mbp->obits;
7146 for (box = 0; box < MAX_MAILBOX(isp); box++) {
7147 if (ibits & (1 << box)) {
7148 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
7151 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
7155 isp->isp_lastmbxcmd = opcode;
7156 isp->isp_obits = obits;
7157 isp->isp_mboxbsy = 1;
7160 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_SET_HOST_INT);
7162 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
7165 * Oddly enough, if we're not delaying for an answer,
7166 * delay a bit to give the f/w a chance to pick up the
7175 isp_mboxcmd(ispsoftc_t *isp, mbreg_t *mbp)
7177 const char *cname, *xname;
7178 char tname[16], mname[16];
7179 unsigned int lim, ibits, obits, box, opcode;
7180 const uint32_t *mcp;
7184 lim = (sizeof (mbpfc) / sizeof (mbpfc[0]));
7187 lim = (sizeof (mbpscsi) / sizeof (mbpscsi[0]));
7190 if ((opcode = mbp->param[0]) >= lim) {
7191 mbp->param[0] = MBOX_INVALID_COMMAND;
7192 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
7196 ibits = HIWRD(mcp[opcode]) & NMBOX_BMASK(isp);
7197 obits = LOWRD(mcp[opcode]) & NMBOX_BMASK(isp);
7200 * Pick up any additional bits that the caller might have set.
7202 ibits |= mbp->ibits;
7203 obits |= mbp->obits;
7205 if (ibits == 0 && obits == 0) {
7206 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
7207 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
7212 * Get exclusive usage of mailbox registers.
7214 if (MBOX_ACQUIRE(isp)) {
7215 mbp->param[0] = MBOX_REGS_BUSY;
7219 for (box = 0; box < MAX_MAILBOX(isp); box++) {
7220 if (ibits & (1 << box)) {
7221 isp_prt(isp, ISP_LOGDEBUG3, "IN mbox %d = 0x%04x", box,
7223 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
7225 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
7228 isp->isp_lastmbxcmd = opcode;
7231 * We assume that we can't overwrite a previous command.
7233 isp->isp_obits = obits;
7234 isp->isp_mboxbsy = 1;
7237 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
7240 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_SET_HOST_INT);
7242 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
7246 * While we haven't finished the command, spin our wheels here.
7248 MBOX_WAIT_COMPLETE(isp, mbp);
7251 * Did the command time out?
7253 if (mbp->param[0] == MBOX_TIMEOUT) {
7254 isp->isp_mboxbsy = 0;
7260 * Copy back output registers.
7262 for (box = 0; box < MAX_MAILBOX(isp); box++) {
7263 if (obits & (1 << box)) {
7264 mbp->param[box] = isp->isp_mboxtmp[box];
7265 isp_prt(isp, ISP_LOGDEBUG3, "OUT mbox %d = 0x%04x", box,
7270 isp->isp_mboxbsy = 0;
7273 if (mbp->logval == 0 || opcode == MBOX_EXEC_FIRMWARE) {
7276 cname = (IS_FC(isp))? fc_mbcmd_names[opcode] : scsi_mbcmd_names[opcode];
7277 if (cname == NULL) {
7279 ISP_SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
7283 * Just to be chatty here...
7286 switch (mbp->param[0]) {
7287 case MBOX_COMMAND_COMPLETE:
7289 case MBOX_INVALID_COMMAND:
7290 if (mbp->logval & MBLOGMASK(MBOX_COMMAND_COMPLETE)) {
7291 xname = "INVALID COMMAND";
7294 case MBOX_HOST_INTERFACE_ERROR:
7295 if (mbp->logval & MBLOGMASK(MBOX_HOST_INTERFACE_ERROR)) {
7296 xname = "HOST INTERFACE ERROR";
7299 case MBOX_TEST_FAILED:
7300 if (mbp->logval & MBLOGMASK(MBOX_TEST_FAILED)) {
7301 xname = "TEST FAILED";
7304 case MBOX_COMMAND_ERROR:
7305 if (mbp->logval & MBLOGMASK(MBOX_COMMAND_ERROR)) {
7306 xname = "COMMAND ERROR";
7309 case MBOX_COMMAND_PARAM_ERROR:
7310 if (mbp->logval & MBLOGMASK(MBOX_COMMAND_PARAM_ERROR)) {
7311 xname = "COMMAND PARAMETER ERROR";
7314 case MBOX_LOOP_ID_USED:
7315 if (mbp->logval & MBLOGMASK(MBOX_LOOP_ID_USED)) {
7316 xname = "LOOP ID ALREADY IN USE";
7319 case MBOX_PORT_ID_USED:
7320 if (mbp->logval & MBLOGMASK(MBOX_PORT_ID_USED)) {
7321 xname = "PORT ID ALREADY IN USE";
7324 case MBOX_ALL_IDS_USED:
7325 if (mbp->logval & MBLOGMASK(MBOX_ALL_IDS_USED)) {
7326 xname = "ALL LOOP IDS IN USE";
7329 case MBOX_REGS_BUSY:
7330 xname = "REGISTERS BUSY";
7336 ISP_SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
7341 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s)",
7347 isp_fw_state(ispsoftc_t *isp, int chan)
7351 fcparam *fcp = FCPARAM(isp, chan);
7353 MBSINIT(&mbs, MBOX_GET_FW_STATE, MBLOGALL, 0);
7354 isp_mboxcmd(isp, &mbs);
7355 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
7356 fcp->isp_fwstate = mbs.param[1];
7362 isp_spi_update(ispsoftc_t *isp, int chan)
7370 * There are no 'per-bus' settings for Fibre Channel.
7374 sdp = SDPARAM(isp, chan);
7377 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7378 uint16_t flags, period, offset;
7381 if (sdp->isp_devparam[tgt].dev_enable == 0) {
7382 sdp->isp_devparam[tgt].dev_update = 0;
7383 sdp->isp_devparam[tgt].dev_refresh = 0;
7384 isp_prt(isp, ISP_LOGDEBUG0,
7385 "skipping target %d bus %d update", tgt, chan);
7389 * If the goal is to update the status of the device,
7390 * take what's in goal_flags and try and set the device
7391 * toward that. Otherwise, if we're just refreshing the
7392 * current device state, get the current parameters.
7395 MBSINIT(&mbs, 0, MBLOGALL, 0);
7398 * Refresh overrides set
7400 if (sdp->isp_devparam[tgt].dev_refresh) {
7401 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
7403 } else if (sdp->isp_devparam[tgt].dev_update) {
7404 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
7407 * Make sure goal_flags has "Renegotiate on Error"
7408 * on and "Freeze Queue on Error" off.
7410 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
7411 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
7412 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
7415 * Insist that PARITY must be enabled
7416 * if SYNC or WIDE is enabled.
7418 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
7419 mbs.param[2] |= DPARM_PARITY;
7422 if (mbs.param[2] & DPARM_SYNC) {
7424 (sdp->isp_devparam[tgt].goal_offset << 8) |
7425 (sdp->isp_devparam[tgt].goal_period);
7428 * A command completion later that has
7429 * RQSTF_NEGOTIATION set can cause
7430 * the dev_refresh/announce cycle also.
7432 * Note: It is really important to update our current
7433 * flags with at least the state of TAG capabilities-
7434 * otherwise we might try and send a tagged command
7435 * when we have it all turned off. So change it here
7436 * to say that current already matches goal.
7438 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
7439 sdp->isp_devparam[tgt].actv_flags |=
7440 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
7441 isp_prt(isp, ISP_LOGDEBUG0,
7442 "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
7443 chan, tgt, mbs.param[2], mbs.param[3] >> 8,
7444 mbs.param[3] & 0xff);
7449 mbs.param[1] = (chan << 15) | (tgt << 8);
7450 isp_mboxcmd(isp, &mbs);
7451 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7455 sdp->sendmarker = 1;
7456 sdp->isp_devparam[tgt].dev_update = 0;
7457 sdp->isp_devparam[tgt].dev_refresh = 1;
7459 sdp->isp_devparam[tgt].dev_refresh = 0;
7460 flags = mbs.param[2];
7461 period = mbs.param[3] & 0xff;
7462 offset = mbs.param[3] >> 8;
7463 sdp->isp_devparam[tgt].actv_flags = flags;
7464 sdp->isp_devparam[tgt].actv_period = period;
7465 sdp->isp_devparam[tgt].actv_offset = offset;
7466 isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, chan, tgt);
7470 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7471 if (sdp->isp_devparam[tgt].dev_update ||
7472 sdp->isp_devparam[tgt].dev_refresh) {
7480 isp_setdfltsdparm(ispsoftc_t *isp)
7483 sdparam *sdp, *sdp1;
7485 sdp = SDPARAM(isp, 0);
7486 sdp->role = GET_DEFAULT_ROLE(isp, 0);
7487 if (IS_DUALBUS(isp)) {
7489 sdp1->role = GET_DEFAULT_ROLE(isp, 1);
7495 * Establish some default parameters.
7497 sdp->isp_cmd_dma_burst_enable = 0;
7498 sdp->isp_data_dma_burst_enabl = 1;
7499 sdp->isp_fifo_threshold = 0;
7500 sdp->isp_initiator_id = DEFAULT_IID(isp, 0);
7501 if (isp->isp_type >= ISP_HA_SCSI_1040) {
7502 sdp->isp_async_data_setup = 9;
7504 sdp->isp_async_data_setup = 6;
7506 sdp->isp_selection_timeout = 250;
7507 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
7508 sdp->isp_tag_aging = 8;
7509 sdp->isp_bus_reset_delay = 5;
7511 * Don't retry selection, busy or queue full automatically- reflect
7514 sdp->isp_retry_count = 0;
7515 sdp->isp_retry_delay = 0;
7517 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7518 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
7519 sdp->isp_devparam[tgt].dev_enable = 1;
7523 * The trick here is to establish a default for the default (honk!)
7524 * state (goal_flags). Then try and get the current status from
7525 * the card to fill in the current state. We don't, in fact, set
7526 * the default to the SAFE default state- that's not the goal state.
7528 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7530 sdp->isp_devparam[tgt].actv_offset = 0;
7531 sdp->isp_devparam[tgt].actv_period = 0;
7532 sdp->isp_devparam[tgt].actv_flags = 0;
7534 sdp->isp_devparam[tgt].goal_flags =
7535 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
7538 * We default to Wide/Fast for versions less than a 1040
7539 * (unless it's SBus).
7541 if (IS_ULTRA3(isp)) {
7542 off = ISP_80M_SYNCPARMS >> 8;
7543 per = ISP_80M_SYNCPARMS & 0xff;
7544 } else if (IS_ULTRA2(isp)) {
7545 off = ISP_40M_SYNCPARMS >> 8;
7546 per = ISP_40M_SYNCPARMS & 0xff;
7547 } else if (IS_1240(isp)) {
7548 off = ISP_20M_SYNCPARMS >> 8;
7549 per = ISP_20M_SYNCPARMS & 0xff;
7550 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
7551 isp->isp_type < ISP_HA_SCSI_1020A) ||
7552 (isp->isp_bustype == ISP_BT_PCI &&
7553 isp->isp_type < ISP_HA_SCSI_1040) ||
7554 (isp->isp_clock && isp->isp_clock < 60) ||
7555 (sdp->isp_ultramode == 0)) {
7556 off = ISP_10M_SYNCPARMS >> 8;
7557 per = ISP_10M_SYNCPARMS & 0xff;
7559 off = ISP_20M_SYNCPARMS_1040 >> 8;
7560 per = ISP_20M_SYNCPARMS_1040 & 0xff;
7562 sdp->isp_devparam[tgt].goal_offset =
7563 sdp->isp_devparam[tgt].nvrm_offset = off;
7564 sdp->isp_devparam[tgt].goal_period =
7565 sdp->isp_devparam[tgt].nvrm_period = per;
7570 * If we're a dual bus card, just copy the data over
7574 sdp1->isp_initiator_id = DEFAULT_IID(isp, 1);
7578 * If we've not been told to avoid reading NVRAM, try and read it.
7579 * If we're successful reading it, we can then return because NVRAM
7580 * will tell us what the desired settings are. Otherwise, we establish
7581 * some reasonable 'fake' nvram and goal defaults.
7583 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7586 if (isp_read_nvram(isp, 0) == 0) {
7587 if (IS_DUALBUS(isp)) {
7588 if (isp_read_nvram(isp, 1) == 0) {
7593 MBSINIT(&mbs, MBOX_GET_ACT_NEG_STATE, MBLOGNONE, 0);
7594 isp_mboxcmd(isp, &mbs);
7595 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7596 sdp->isp_req_ack_active_neg = 1;
7597 sdp->isp_data_line_active_neg = 1;
7599 sdp1->isp_req_ack_active_neg = 1;
7600 sdp1->isp_data_line_active_neg = 1;
7603 sdp->isp_req_ack_active_neg =
7604 (mbs.param[1] >> 4) & 0x1;
7605 sdp->isp_data_line_active_neg =
7606 (mbs.param[1] >> 5) & 0x1;
7608 sdp1->isp_req_ack_active_neg =
7609 (mbs.param[2] >> 4) & 0x1;
7610 sdp1->isp_data_line_active_neg =
7611 (mbs.param[2] >> 5) & 0x1;
7619 isp_setdfltfcparm(ispsoftc_t *isp, int chan)
7621 fcparam *fcp = FCPARAM(isp, chan);
7624 * Establish some default parameters.
7626 fcp->role = GET_DEFAULT_ROLE(isp, chan);
7627 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
7628 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
7629 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
7630 fcp->isp_loopid = DEFAULT_LOOPID(isp, chan);
7631 fcp->isp_wwnn_nvram = DEFAULT_NODEWWN(isp, chan);
7632 fcp->isp_wwpn_nvram = DEFAULT_PORTWWN(isp, chan);
7633 fcp->isp_fwoptions = 0;
7634 fcp->isp_lasthdl = NIL_HANDLE;
7637 fcp->isp_fwoptions |= ICB2400_OPT1_FAIRNESS;
7638 fcp->isp_fwoptions |= ICB2400_OPT1_HARD_ADDRESS;
7639 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX) {
7640 fcp->isp_fwoptions |= ICB2400_OPT1_FULL_DUPLEX;
7642 fcp->isp_fwoptions |= ICB2400_OPT1_BOTH_WWNS;
7644 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
7645 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
7646 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
7647 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX) {
7648 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
7651 * Make sure this is turned off now until we get
7652 * extended options from NVRAM
7654 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
7659 * Now try and read NVRAM unless told to not do so.
7660 * This will set fcparam's isp_wwnn_nvram && isp_wwpn_nvram.
7662 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7665 * Give a couple of tries at reading NVRAM.
7667 for (i = 0; i < 2; i++) {
7668 j = isp_read_nvram(isp, chan);
7674 isp->isp_confopts |= ISP_CFG_NONVRAM;
7678 fcp->isp_wwnn = ACTIVE_NODEWWN(isp, chan);
7679 fcp->isp_wwpn = ACTIVE_PORTWWN(isp, chan);
7680 isp_prt(isp, ISP_LOGCONFIG, "Chan %d 0x%08x%08x/0x%08x%08x Role %s",
7681 chan, (uint32_t) (fcp->isp_wwnn >> 32), (uint32_t) (fcp->isp_wwnn),
7682 (uint32_t) (fcp->isp_wwpn >> 32), (uint32_t) (fcp->isp_wwpn),
7683 isp_class3_roles[fcp->role]);
7687 * Re-initialize the ISP and complete all orphaned commands
7688 * with a 'botched' notice. The reset/init routines should
7689 * not disturb an already active list of commands.
7693 isp_reinit(ispsoftc_t *isp, int do_load_defaults)
7697 isp_reset(isp, do_load_defaults);
7699 if (isp->isp_state != ISP_RESETSTATE) {
7700 isp_prt(isp, ISP_LOGERR, "%s: cannot reset card", __func__);
7701 ISP_DISABLE_INTS(isp);
7707 if (isp->isp_state == ISP_INITSTATE) {
7708 isp->isp_state = ISP_RUNSTATE;
7711 if (isp->isp_state != ISP_RUNSTATE) {
7712 #ifndef ISP_TARGET_MODE
7713 isp_prt(isp, ISP_LOGWARN, "%s: not at runstate", __func__);
7715 ISP_DISABLE_INTS(isp);
7718 * If we're in ISP_ROLE_NONE, turn off the lasers.
7720 if (!IS_24XX(isp)) {
7721 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
7722 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
7723 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
7724 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
7725 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
7732 isp->isp_nactive = 0;
7734 isp_clear_commands(isp);
7736 for (i = 0; i < isp->isp_nchan; i++) {
7737 ISP_MARK_PORTDB(isp, i, -1);
7746 isp_read_nvram(ispsoftc_t *isp, int bus)
7749 uint8_t csum, minversion;
7751 uint8_t _x[ISP2400_NVRAM_SIZE];
7752 uint16_t _s[ISP2400_NVRAM_SIZE>>1];
7754 #define nvram_data _n._x
7755 #define nvram_words _n._s
7758 return (isp_read_nvram_2400(isp, nvram_data));
7759 } else if (IS_FC(isp)) {
7760 amt = ISP2100_NVRAM_SIZE;
7762 } else if (IS_ULTRA2(isp)) {
7763 amt = ISP1080_NVRAM_SIZE;
7766 amt = ISP_NVRAM_SIZE;
7770 for (i = 0; i < amt>>1; i++) {
7771 isp_rdnvram_word(isp, i, &nvram_words[i]);
7774 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
7775 nvram_data[2] != 'P') {
7776 if (isp->isp_bustype != ISP_BT_SBUS) {
7777 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
7778 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x",
7779 nvram_data[0], nvram_data[1], nvram_data[2]);
7785 for (csum = 0, i = 0; i < amt; i++) {
7786 csum += nvram_data[i];
7789 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
7794 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
7795 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
7796 ISP_NVRAM_VERSION(nvram_data));
7801 if (IS_ULTRA3(isp)) {
7802 isp_parse_nvram_12160(isp, bus, nvram_data);
7803 } else if (IS_1080(isp)) {
7804 isp_parse_nvram_1080(isp, bus, nvram_data);
7805 } else if (IS_1280(isp) || IS_1240(isp)) {
7806 isp_parse_nvram_1080(isp, bus, nvram_data);
7807 } else if (IS_SCSI(isp)) {
7808 isp_parse_nvram_1020(isp, nvram_data);
7810 isp_parse_nvram_2100(isp, nvram_data);
7820 isp_read_nvram_2400(ispsoftc_t *isp, uint8_t *nvram_data)
7823 uint32_t addr, csum, lwrds, *dptr;
7825 if (isp->isp_port) {
7826 addr = ISP2400_NVRAM_PORT1_ADDR;
7828 addr = ISP2400_NVRAM_PORT0_ADDR;
7831 dptr = (uint32_t *) nvram_data;
7832 for (lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
7833 isp_rd_2400_nvram(isp, addr++, dptr++);
7835 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
7836 nvram_data[2] != 'P') {
7837 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header (%x %x %x)",
7838 nvram_data[0], nvram_data[1], nvram_data[2]);
7842 dptr = (uint32_t *) nvram_data;
7843 for (csum = 0, lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
7845 ISP_IOXGET_32(isp, &dptr[lwrds], tmp);
7849 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
7853 isp_parse_nvram_2400(isp, nvram_data);
7859 isp_rdnvram_word(ispsoftc_t *isp, int wo, uint16_t *rp)
7862 uint16_t bit, rqst, junk;
7864 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
7866 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
7870 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
7871 if (IS_2312(isp) && isp->isp_port) {
7874 rqst = (ISP_NVRAM_READ << 8) | wo;
7876 } else if (IS_ULTRA2(isp)) {
7877 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
7878 rqst = (ISP_NVRAM_READ << 8) | wo;
7881 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
7882 rqst = (ISP_NVRAM_READ << 6) | wo;
7887 * Clock the word select request out...
7889 for (i = cbits; i >= 0; i--) {
7890 if ((rqst >> i) & 1) {
7891 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
7893 bit = BIU_NVRAM_SELECT;
7895 ISP_WRITE(isp, BIU_NVRAM, bit);
7897 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7898 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
7900 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7901 ISP_WRITE(isp, BIU_NVRAM, bit);
7903 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7906 * Now read the result back in (bits come back in MSB format).
7909 for (i = 0; i < 16; i++) {
7912 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
7914 rv = ISP_READ(isp, BIU_NVRAM);
7915 if (rv & BIU_NVRAM_DATAIN) {
7919 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
7921 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7923 ISP_WRITE(isp, BIU_NVRAM, 0);
7925 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7926 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
7930 isp_rd_2400_nvram(ispsoftc_t *isp, uint32_t addr, uint32_t *rp)
7933 uint32_t base = 0x7ffe0000;
7937 base = 0x7ff00000 | 0x48000;
7939 ISP_WRITE(isp, BIU2400_FLASH_ADDR, base | addr);
7940 for (loops = 0; loops < 5000; loops++) {
7942 tmp = ISP_READ(isp, BIU2400_FLASH_ADDR);
7943 if ((tmp & (1U << 31)) != 0) {
7947 if (tmp & (1U << 31)) {
7948 *rp = ISP_READ(isp, BIU2400_FLASH_DATA);
7949 ISP_SWIZZLE_NVRAM_LONG(isp, rp);
7956 isp_parse_nvram_1020(ispsoftc_t *isp, uint8_t *nvram_data)
7958 sdparam *sdp = SDPARAM(isp, 0);
7961 sdp->isp_fifo_threshold =
7962 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
7963 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
7965 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
7966 sdp->isp_initiator_id =
7967 ISP_NVRAM_INITIATOR_ID(nvram_data);
7969 sdp->isp_bus_reset_delay =
7970 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
7972 sdp->isp_retry_count =
7973 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
7975 sdp->isp_retry_delay =
7976 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
7978 sdp->isp_async_data_setup =
7979 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
7981 if (isp->isp_type >= ISP_HA_SCSI_1040) {
7982 if (sdp->isp_async_data_setup < 9) {
7983 sdp->isp_async_data_setup = 9;
7986 if (sdp->isp_async_data_setup != 6) {
7987 sdp->isp_async_data_setup = 6;
7991 sdp->isp_req_ack_active_neg =
7992 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
7994 sdp->isp_data_line_active_neg =
7995 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
7997 sdp->isp_data_dma_burst_enabl =
7998 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
8000 sdp->isp_cmd_dma_burst_enable =
8001 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
8003 sdp->isp_tag_aging =
8004 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
8006 sdp->isp_selection_timeout =
8007 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
8009 sdp->isp_max_queue_depth =
8010 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
8012 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
8014 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
8015 sdp->isp_devparam[tgt].dev_enable =
8016 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
8017 sdp->isp_devparam[tgt].exc_throttle =
8018 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
8019 sdp->isp_devparam[tgt].nvrm_offset =
8020 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
8021 sdp->isp_devparam[tgt].nvrm_period =
8022 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
8024 * We probably shouldn't lie about this, but it
8025 * it makes it much safer if we limit NVRAM values
8028 if (isp->isp_type < ISP_HA_SCSI_1040) {
8030 * If we're not ultra, we can't possibly
8031 * be a shorter period than this.
8033 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
8034 sdp->isp_devparam[tgt].nvrm_period = 0x19;
8036 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
8037 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
8040 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
8041 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
8044 sdp->isp_devparam[tgt].nvrm_flags = 0;
8045 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
8046 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
8047 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
8048 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
8049 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
8050 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
8051 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
8052 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
8053 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
8054 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
8055 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
8056 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
8057 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
8058 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
8059 sdp->isp_devparam[tgt].goal_offset =
8060 sdp->isp_devparam[tgt].nvrm_offset;
8061 sdp->isp_devparam[tgt].goal_period =
8062 sdp->isp_devparam[tgt].nvrm_period;
8063 sdp->isp_devparam[tgt].goal_flags =
8064 sdp->isp_devparam[tgt].nvrm_flags;
8069 isp_parse_nvram_1080(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
8071 sdparam *sdp = SDPARAM(isp, bus);
8074 sdp->isp_fifo_threshold =
8075 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
8077 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
8078 sdp->isp_initiator_id =
8079 ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
8081 sdp->isp_bus_reset_delay =
8082 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
8084 sdp->isp_retry_count =
8085 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
8087 sdp->isp_retry_delay =
8088 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
8090 sdp->isp_async_data_setup =
8091 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
8093 sdp->isp_req_ack_active_neg =
8094 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
8096 sdp->isp_data_line_active_neg =
8097 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
8099 sdp->isp_data_dma_burst_enabl =
8100 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
8102 sdp->isp_cmd_dma_burst_enable =
8103 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
8105 sdp->isp_selection_timeout =
8106 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
8108 sdp->isp_max_queue_depth =
8109 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
8111 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
8112 sdp->isp_devparam[tgt].dev_enable =
8113 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
8114 sdp->isp_devparam[tgt].exc_throttle =
8115 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
8116 sdp->isp_devparam[tgt].nvrm_offset =
8117 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
8118 sdp->isp_devparam[tgt].nvrm_period =
8119 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
8120 sdp->isp_devparam[tgt].nvrm_flags = 0;
8121 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
8122 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
8123 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
8124 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
8125 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
8126 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
8127 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
8128 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
8129 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
8130 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
8131 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
8132 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
8133 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
8134 sdp->isp_devparam[tgt].actv_flags = 0;
8135 sdp->isp_devparam[tgt].goal_offset =
8136 sdp->isp_devparam[tgt].nvrm_offset;
8137 sdp->isp_devparam[tgt].goal_period =
8138 sdp->isp_devparam[tgt].nvrm_period;
8139 sdp->isp_devparam[tgt].goal_flags =
8140 sdp->isp_devparam[tgt].nvrm_flags;
8145 isp_parse_nvram_12160(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
8147 sdparam *sdp = SDPARAM(isp, bus);
8150 sdp->isp_fifo_threshold =
8151 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
8153 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
8154 sdp->isp_initiator_id =
8155 ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
8157 sdp->isp_bus_reset_delay =
8158 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
8160 sdp->isp_retry_count =
8161 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
8163 sdp->isp_retry_delay =
8164 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
8166 sdp->isp_async_data_setup =
8167 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
8169 sdp->isp_req_ack_active_neg =
8170 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
8172 sdp->isp_data_line_active_neg =
8173 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
8175 sdp->isp_data_dma_burst_enabl =
8176 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
8178 sdp->isp_cmd_dma_burst_enable =
8179 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
8181 sdp->isp_selection_timeout =
8182 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
8184 sdp->isp_max_queue_depth =
8185 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
8187 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
8188 sdp->isp_devparam[tgt].dev_enable =
8189 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
8190 sdp->isp_devparam[tgt].exc_throttle =
8191 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
8192 sdp->isp_devparam[tgt].nvrm_offset =
8193 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
8194 sdp->isp_devparam[tgt].nvrm_period =
8195 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
8196 sdp->isp_devparam[tgt].nvrm_flags = 0;
8197 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
8198 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
8199 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
8200 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
8201 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
8202 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
8203 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
8204 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
8205 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
8206 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
8207 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
8208 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
8209 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
8210 sdp->isp_devparam[tgt].actv_flags = 0;
8211 sdp->isp_devparam[tgt].goal_offset =
8212 sdp->isp_devparam[tgt].nvrm_offset;
8213 sdp->isp_devparam[tgt].goal_period =
8214 sdp->isp_devparam[tgt].nvrm_period;
8215 sdp->isp_devparam[tgt].goal_flags =
8216 sdp->isp_devparam[tgt].nvrm_flags;
8221 isp_parse_nvram_2100(ispsoftc_t *isp, uint8_t *nvram_data)
8223 fcparam *fcp = FCPARAM(isp, 0);
8227 * There is NVRAM storage for both Port and Node entities-
8228 * but the Node entity appears to be unused on all the cards
8229 * I can find. However, we should account for this being set
8230 * at some point in the future.
8232 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
8233 * bits 48..60. In the case of the 2202, it appears that they do
8234 * use bit 48 to distinguish between the two instances on the card.
8235 * The 2204, which I've never seen, *probably* extends this method.
8237 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
8239 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
8240 (uint32_t) (wwn >> 32), (uint32_t) (wwn));
8241 if ((wwn >> 60) == 0) {
8242 wwn |= (((uint64_t) 2)<< 60);
8245 fcp->isp_wwpn_nvram = wwn;
8246 if (IS_2200(isp) || IS_23XX(isp)) {
8247 wwn = ISP2100_NVRAM_NODE_NAME(nvram_data);
8249 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
8250 (uint32_t) (wwn >> 32),
8252 if ((wwn >> 60) == 0) {
8253 wwn |= (((uint64_t) 2)<< 60);
8256 wwn = fcp->isp_wwpn_nvram & ~((uint64_t) 0xfff << 48);
8259 wwn &= ~((uint64_t) 0xfff << 48);
8261 fcp->isp_wwnn_nvram = wwn;
8263 fcp->isp_maxalloc = ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
8264 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
8265 DEFAULT_FRAMESIZE(isp) =
8266 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
8268 fcp->isp_retry_delay = ISP2100_NVRAM_RETRY_DELAY(nvram_data);
8269 fcp->isp_retry_count = ISP2100_NVRAM_RETRY_COUNT(nvram_data);
8270 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
8271 fcp->isp_loopid = ISP2100_NVRAM_HARDLOOPID(nvram_data);
8273 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
8274 DEFAULT_EXEC_THROTTLE(isp) =
8275 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
8277 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
8278 isp_prt(isp, ISP_LOGDEBUG0,
8279 "NVRAM 0x%08x%08x 0x%08x%08x maxalloc %d maxframelen %d",
8280 (uint32_t) (fcp->isp_wwnn_nvram >> 32),
8281 (uint32_t) fcp->isp_wwnn_nvram,
8282 (uint32_t) (fcp->isp_wwpn_nvram >> 32),
8283 (uint32_t) fcp->isp_wwpn_nvram,
8284 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data),
8285 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data));
8286 isp_prt(isp, ISP_LOGDEBUG0,
8287 "execthrottle %d fwoptions 0x%x hardloop %d tov %d",
8288 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
8289 ISP2100_NVRAM_OPTIONS(nvram_data),
8290 ISP2100_NVRAM_HARDLOOPID(nvram_data),
8291 ISP2100_NVRAM_TOV(nvram_data));
8292 fcp->isp_xfwoptions = ISP2100_XFW_OPTIONS(nvram_data);
8293 fcp->isp_zfwoptions = ISP2100_ZFW_OPTIONS(nvram_data);
8294 isp_prt(isp, ISP_LOGDEBUG0,
8295 "xfwoptions 0x%x zfw options 0x%x",
8296 ISP2100_XFW_OPTIONS(nvram_data), ISP2100_ZFW_OPTIONS(nvram_data));
8300 isp_parse_nvram_2400(ispsoftc_t *isp, uint8_t *nvram_data)
8302 fcparam *fcp = FCPARAM(isp, 0);
8305 isp_prt(isp, ISP_LOGDEBUG0,
8306 "NVRAM 0x%08x%08x 0x%08x%08x exchg_cnt %d maxframelen %d",
8307 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data) >> 32),
8308 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data)),
8309 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data) >> 32),
8310 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data)),
8311 ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data),
8312 ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data));
8313 isp_prt(isp, ISP_LOGDEBUG0,
8314 "NVRAM execthr %d loopid %d fwopt1 0x%x fwopt2 0x%x fwopt3 0x%x",
8315 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data),
8316 ISP2400_NVRAM_HARDLOOPID(nvram_data),
8317 ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data),
8318 ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data),
8319 ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data));
8321 wwn = ISP2400_NVRAM_PORT_NAME(nvram_data);
8322 fcp->isp_wwpn_nvram = wwn;
8324 wwn = ISP2400_NVRAM_NODE_NAME(nvram_data);
8326 if ((wwn >> 60) != 2 && (wwn >> 60) != 5) {
8330 if (wwn == 0 && (fcp->isp_wwpn_nvram >> 60) == 2) {
8331 wwn = fcp->isp_wwpn_nvram;
8332 wwn &= ~((uint64_t) 0xfff << 48);
8334 fcp->isp_wwnn_nvram = wwn;
8336 if (ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data)) {
8337 fcp->isp_maxalloc = ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data);
8339 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
8340 DEFAULT_FRAMESIZE(isp) =
8341 ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data);
8343 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
8344 fcp->isp_loopid = ISP2400_NVRAM_HARDLOOPID(nvram_data);
8346 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
8347 DEFAULT_EXEC_THROTTLE(isp) =
8348 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data);
8350 fcp->isp_fwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data);
8351 fcp->isp_xfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data);
8352 fcp->isp_zfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data);