1 /* $Id: isp.c,v 1.216 2009/04/03 04:56:00 mjacob Exp $ */
3 * Copyright (c) 1997-2009 by Matthew Jacob
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * Alternatively, this software may be distributed under the terms of the
30 * the GNU Public License ("GPL") with platforms where the prevalant license
31 * is the GNU Public License:
33 * This program is free software; you can redistribute it and/or modify
34 * it under the terms of The Version 2 GNU General Public License as published
35 * by the Free Software Foundation.
37 * This program is distributed in the hope that it will be useful,
38 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 * GNU General Public License for more details.
42 * You should have received a copy of the GNU General Public License
43 * along with this program; if not, write to the Free Software
44 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
50 * Menlo Park, CA 94025
57 * Machine and OS Independent (well, as best as possible)
58 * code for the Qlogic ISP SCSI and FC-SCSI adapters.
62 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
63 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
64 * ideas dredged from the Solaris driver.
68 * Include header file appropriate for platform we're building on.
71 #include <sys/cdefs.h>
72 __KERNEL_RCSID(0, "$NetBSD$");
73 #include <dev/ic/isp_netbsd.h>
76 #include <sys/cdefs.h>
77 __FBSDID("$FreeBSD$");
78 #include <dev/isp/isp_freebsd.h>
81 #include <dev/ic/isp_openbsd.h>
84 #include "isp_linux.h"
87 #include "isp_solaris.h"
94 #define MBOX_DELAY_COUNT 1000000 / 100
95 #define ISP_MARK_PORTDB(a, b, c) \
96 isp_prt(isp, ISP_LOGSANCFG, \
97 "Chan %d ISP_MARK_PORTDB@LINE %d", b, __LINE__); \
98 isp_mark_portdb(a, b, c)
103 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)";
104 static const char notresp[] = "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
105 static const char xact1[] = "HBA attempted queued transaction with disconnect not set for %d.%d.%d";
106 static const char xact2[] = "HBA attempted queued transaction to target routine %d on target %d bus %d";
107 static const char xact3[] = "HBA attempted queued cmd for %d.%d.%d when queueing disabled";
108 static const char pskip[] = "SCSI phase skipped for target %d.%d.%d";
109 static const char topology[] = "Chan %d WWPN 0x%08x%08x PortID 0x%06x N-Port Handle %d, Connection '%s'";
110 static const char finmsg[] = "%d.%d.%d: FIN dl%d resid %ld STS 0x%x SKEY %c XS_ERR=0x%x";
111 static const char sc4[] = "NVRAM";
112 static const char bun[] = "bad underrun for %d.%d (count %d, resid %d, status %s)";
113 static const char lipd[] = "Chan %d LIP destroyed %d active commands";
114 static const char sacq[] = "unable to acquire scratch area";
116 static const uint8_t alpa_map[] = {
117 0xef, 0xe8, 0xe4, 0xe2, 0xe1, 0xe0, 0xdc, 0xda,
118 0xd9, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xce,
119 0xcd, 0xcc, 0xcb, 0xca, 0xc9, 0xc7, 0xc6, 0xc5,
120 0xc3, 0xbc, 0xba, 0xb9, 0xb6, 0xb5, 0xb4, 0xb3,
121 0xb2, 0xb1, 0xae, 0xad, 0xac, 0xab, 0xaa, 0xa9,
122 0xa7, 0xa6, 0xa5, 0xa3, 0x9f, 0x9e, 0x9d, 0x9b,
123 0x98, 0x97, 0x90, 0x8f, 0x88, 0x84, 0x82, 0x81,
124 0x80, 0x7c, 0x7a, 0x79, 0x76, 0x75, 0x74, 0x73,
125 0x72, 0x71, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x69,
126 0x67, 0x66, 0x65, 0x63, 0x5c, 0x5a, 0x59, 0x56,
127 0x55, 0x54, 0x53, 0x52, 0x51, 0x4e, 0x4d, 0x4c,
128 0x4b, 0x4a, 0x49, 0x47, 0x46, 0x45, 0x43, 0x3c,
129 0x3a, 0x39, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31,
130 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x27, 0x26,
131 0x25, 0x23, 0x1f, 0x1e, 0x1d, 0x1b, 0x18, 0x17,
132 0x10, 0x0f, 0x08, 0x04, 0x02, 0x01, 0x00
136 * Local function prototypes.
138 static int isp_parse_async(ispsoftc_t *, uint16_t);
139 static int isp_handle_other_response(ispsoftc_t *, int, isphdr_t *, uint32_t *);
140 static void isp_parse_status(ispsoftc_t *, ispstatusreq_t *, XS_T *, long *); static void
141 isp_parse_status_24xx(ispsoftc_t *, isp24xx_statusreq_t *, XS_T *, long *);
142 static void isp_fastpost_complete(ispsoftc_t *, uint16_t);
143 static int isp_mbox_continue(ispsoftc_t *);
144 static void isp_scsi_init(ispsoftc_t *);
145 static void isp_scsi_channel_init(ispsoftc_t *, int);
146 static void isp_fibre_init(ispsoftc_t *);
147 static void isp_fibre_init_2400(ispsoftc_t *);
148 static void isp_mark_portdb(ispsoftc_t *, int, int);
149 static int isp_plogx(ispsoftc_t *, int, uint16_t, uint32_t, int, int);
150 static int isp_port_login(ispsoftc_t *, uint16_t, uint32_t);
151 static int isp_port_logout(ispsoftc_t *, uint16_t, uint32_t);
152 static int isp_getpdb(ispsoftc_t *, int, uint16_t, isp_pdb_t *, int);
153 static void isp_dump_chip_portdb(ispsoftc_t *, int, int);
154 static uint64_t isp_get_wwn(ispsoftc_t *, int, int, int);
155 static int isp_fclink_test(ispsoftc_t *, int, int);
156 static int isp_pdb_sync(ispsoftc_t *, int);
157 static int isp_scan_loop(ispsoftc_t *, int);
158 static int isp_gid_ft_sns(ispsoftc_t *, int);
159 static int isp_gid_ft_ct_passthru(ispsoftc_t *, int);
160 static int isp_scan_fabric(ispsoftc_t *, int);
161 static int isp_login_device(ispsoftc_t *, int, uint32_t, isp_pdb_t *, uint16_t *);
162 static int isp_register_fc4_type(ispsoftc_t *, int);
163 static int isp_register_fc4_type_24xx(ispsoftc_t *, int);
164 static uint16_t isp_nxt_handle(ispsoftc_t *, int, uint16_t);
165 static void isp_fw_state(ispsoftc_t *, int);
166 static void isp_mboxcmd_qnw(ispsoftc_t *, mbreg_t *, int);
167 static void isp_mboxcmd(ispsoftc_t *, mbreg_t *);
169 static void isp_spi_update(ispsoftc_t *, int);
170 static void isp_setdfltsdparm(ispsoftc_t *);
171 static void isp_setdfltfcparm(ispsoftc_t *, int);
172 static int isp_read_nvram(ispsoftc_t *, int);
173 static int isp_read_nvram_2400(ispsoftc_t *, uint8_t *);
174 static void isp_rdnvram_word(ispsoftc_t *, int, uint16_t *);
175 static void isp_rd_2400_nvram(ispsoftc_t *, uint32_t, uint32_t *);
176 static void isp_parse_nvram_1020(ispsoftc_t *, uint8_t *);
177 static void isp_parse_nvram_1080(ispsoftc_t *, int, uint8_t *);
178 static void isp_parse_nvram_12160(ispsoftc_t *, int, uint8_t *);
179 static void isp_parse_nvram_2100(ispsoftc_t *, uint8_t *);
180 static void isp_parse_nvram_2400(ispsoftc_t *, uint8_t *);
185 * Hit the chip over the head, download new f/w if available and set it running.
187 * Locking done elsewhere.
191 isp_reset(ispsoftc_t *isp)
194 uint32_t code_org, val;
195 int loops, i, dodnld = 1;
196 static const char *btype = "????";
197 static const char dcrc[] = "Downloaded RISC Code Checksum Failure";
199 isp->isp_state = ISP_NILSTATE;
202 ISP_DISABLE_INTS(isp);
207 * Basic types (SCSI, FibreChannel and PCI or SBus)
208 * have been set in the MD code. We figure out more
209 * here. Possibly more refined types based upon PCI
210 * identification. Chip revision has been gathered.
212 * After we've fired this chip up, zero out the conf1 register
213 * for SCSI adapters and do other settings for the 2100.
216 ISP_DISABLE_INTS(isp);
219 * Pick an initial maxcmds value which will be used
220 * to allocate xflist pointer space. It may be changed
221 * later by the firmware.
224 isp->isp_maxcmds = 4096;
225 } else if (IS_2322(isp)) {
226 isp->isp_maxcmds = 2048;
227 } else if (IS_23XX(isp) || IS_2200(isp)) {
228 isp->isp_maxcmds = 1024;
230 isp->isp_maxcmds = 512;
234 * Set up DMA for the request and response queues.
236 * We do this now so we can use the request queue
237 * for dma to load firmware from.
239 if (ISP_MBOXDMASETUP(isp) != 0) {
240 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
245 * Set up default request/response queue in-pointer/out-pointer
249 isp->isp_rqstinrp = BIU2400_REQINP;
250 isp->isp_rqstoutrp = BIU2400_REQOUTP;
251 isp->isp_respinrp = BIU2400_RSPINP;
252 isp->isp_respoutrp = BIU2400_RSPOUTP;
253 } else if (IS_23XX(isp)) {
254 isp->isp_rqstinrp = BIU_REQINP;
255 isp->isp_rqstoutrp = BIU_REQOUTP;
256 isp->isp_respinrp = BIU_RSPINP;
257 isp->isp_respoutrp = BIU_RSPOUTP;
259 isp->isp_rqstinrp = INMAILBOX4;
260 isp->isp_rqstoutrp = OUTMAILBOX4;
261 isp->isp_respinrp = OUTMAILBOX5;
262 isp->isp_respoutrp = INMAILBOX5;
266 * Put the board into PAUSE mode (so we can read the SXP registers
267 * or write FPM/FBM registers).
270 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_HOST_INT);
271 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
272 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_PAUSE);
274 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
278 switch (isp->isp_type) {
306 * While we're paused, reset the FPM module and FBM
309 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
310 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
311 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
312 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
313 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
315 } else if (IS_1240(isp)) {
320 sdp = SDPARAM(isp, 0);
321 sdp->isp_ultramode = 1;
322 sdp = SDPARAM(isp, 1);
323 sdp->isp_ultramode = 1;
325 * XXX: Should probably do some bus sensing.
327 } else if (IS_ULTRA3(isp)) {
328 sdparam *sdp = isp->isp_param;
330 isp->isp_clock = 100;
334 else if (IS_12160(isp))
338 sdp->isp_lvdmode = 1;
340 if (IS_DUALBUS(isp)) {
342 sdp->isp_lvdmode = 1;
344 } else if (IS_ULTRA2(isp)) {
345 static const char m[] = "bus %d is in %s Mode";
347 sdparam *sdp = SDPARAM(isp, 0);
349 isp->isp_clock = 100;
353 else if (IS_1080(isp))
358 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
360 case ISP1080_LVD_MODE:
361 sdp->isp_lvdmode = 1;
362 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
364 case ISP1080_HVD_MODE:
365 sdp->isp_diffmode = 1;
366 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
368 case ISP1080_SE_MODE:
369 sdp->isp_ultramode = 1;
370 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
373 isp_prt(isp, ISP_LOGERR,
374 "unknown mode on bus %d (0x%x)", 0, l);
378 if (IS_DUALBUS(isp)) {
379 sdp = SDPARAM(isp, 1);
380 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
381 l &= ISP1080_MODE_MASK;
383 case ISP1080_LVD_MODE:
384 sdp->isp_lvdmode = 1;
385 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
387 case ISP1080_HVD_MODE:
388 sdp->isp_diffmode = 1;
389 isp_prt(isp, ISP_LOGCONFIG,
390 m, 1, "Differential");
392 case ISP1080_SE_MODE:
393 sdp->isp_ultramode = 1;
394 isp_prt(isp, ISP_LOGCONFIG,
395 m, 1, "Single-Ended");
398 isp_prt(isp, ISP_LOGERR,
399 "unknown mode on bus %d (0x%x)", 1, l);
404 sdparam *sdp = SDPARAM(isp, 0);
405 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
408 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
412 isp->isp_type = ISP_HA_SCSI_1020;
417 * Some 1020A chips are Ultra Capable, but don't
418 * run the clock rate up for that unless told to
419 * do so by the Ultra Capable bits being set.
422 isp->isp_type = ISP_HA_SCSI_1020A;
427 isp->isp_type = ISP_HA_SCSI_1040;
432 isp->isp_type = ISP_HA_SCSI_1040A;
437 isp->isp_type = ISP_HA_SCSI_1040B;
442 isp->isp_type = ISP_HA_SCSI_1040C;
447 * Now, while we're at it, gather info about ultra
448 * and/or differential mode.
450 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
451 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
452 sdp->isp_diffmode = 1;
454 sdp->isp_diffmode = 0;
456 i = ISP_READ(isp, RISC_PSR);
457 if (isp->isp_bustype == ISP_BT_SBUS) {
458 i &= RISC_PSR_SBUS_ULTRA;
460 i &= RISC_PSR_PCI_ULTRA;
463 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
464 sdp->isp_ultramode = 1;
466 * If we're in Ultra Mode, we have to be 60MHz clock-
467 * even for the SBus version.
471 sdp->isp_ultramode = 0;
473 * Clock is known. Gronk.
478 * Machine dependent clock (if set) overrides
479 * our generic determinations.
481 if (isp->isp_mdvec->dv_clock) {
482 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
483 isp->isp_clock = isp->isp_mdvec->dv_clock;
490 * Clear instrumentation
492 isp->isp_intcnt = isp->isp_intbogus = 0;
495 * Do MD specific pre initialization
500 * Hit the chip over the head with hammer,
501 * and give it a chance to recover.
505 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
512 * Clear data && control DMA engines.
514 ISP_WRITE(isp, CDMA_CONTROL,
515 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
516 ISP_WRITE(isp, DDMA_CONTROL,
517 DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
520 } else if (IS_24XX(isp)) {
522 * Stop DMA and wait for it to stop.
524 ISP_WRITE(isp, BIU2400_CSR, BIU2400_DMA_STOP|(3 << 4));
525 for (val = loops = 0; loops < 30000; loops++) {
527 val = ISP_READ(isp, BIU2400_CSR);
528 if ((val & BIU2400_DMA_ACTIVE) == 0) {
532 if (val & BIU2400_DMA_ACTIVE) {
534 isp_prt(isp, ISP_LOGERR, "DMA Failed to Stop on Reset");
538 * Hold it in SOFT_RESET and STOP state for 100us.
540 ISP_WRITE(isp, BIU2400_CSR,
541 BIU2400_SOFT_RESET|BIU2400_DMA_STOP|(3 << 4));
543 for (loops = 0; loops < 10000; loops++) {
545 val = ISP_READ(isp, OUTMAILBOX0);
547 for (val = loops = 0; loops < 500000; loops ++) {
548 val = ISP_READ(isp, BIU2400_CSR);
549 if ((val & BIU2400_SOFT_RESET) == 0) {
553 if (val & BIU2400_SOFT_RESET) {
555 isp_prt(isp, ISP_LOGERR, "Failed to come out of reset");
559 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
566 * Clear data && control DMA engines.
568 ISP_WRITE(isp, CDMA2100_CONTROL,
569 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
570 ISP_WRITE(isp, TDMA2100_CONTROL,
571 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
572 ISP_WRITE(isp, RDMA2100_CONTROL,
573 DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
577 * Wait for ISP to be ready to go...
579 loops = MBOX_DELAY_COUNT;
582 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET)) {
585 } else if (IS_24XX(isp)) {
586 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
590 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
595 ISP_DUMPREGS(isp, "chip reset timed out");
602 * After we've fired this chip up, zero out the conf1 register
603 * for SCSI adapters and other settings for the 2100.
607 ISP_WRITE(isp, BIU_CONF1, 0);
608 } else if (!IS_24XX(isp)) {
609 ISP_WRITE(isp, BIU2100_CSR, 0);
613 * Reset RISC Processor
616 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RESET);
617 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RELEASE);
618 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RESET);
620 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
622 ISP_WRITE(isp, BIU_SEMA, 0);
626 * Post-RISC Reset stuff.
629 for (val = loops = 0; loops < 5000000; loops++) {
631 val = ISP_READ(isp, OUTMAILBOX0);
638 isp_prt(isp, ISP_LOGERR, "reset didn't clear");
641 } else if (IS_SCSI(isp)) {
642 uint16_t tmp = isp->isp_mdvec->dv_conf1;
644 * Busted FIFO. Turn off all but burst enables.
646 if (isp->isp_type == ISP_HA_SCSI_1040A) {
647 tmp &= BIU_BURST_ENABLE;
649 ISP_SETBITS(isp, BIU_CONF1, tmp);
650 if (tmp & BIU_BURST_ENABLE) {
651 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
652 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
654 if (SDPARAM(isp, 0)->isp_ptisp) {
655 if (SDPARAM(isp, 0)->isp_ultramode) {
656 while (ISP_READ(isp, RISC_MTR) != 0x1313) {
657 ISP_WRITE(isp, RISC_MTR, 0x1313);
658 ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
661 ISP_WRITE(isp, RISC_MTR, 0x1212);
664 * PTI specific register
666 ISP_WRITE(isp, RISC_EMB, DUAL_BANK);
668 ISP_WRITE(isp, RISC_MTR, 0x1212);
670 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
672 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
673 if (IS_2200(isp) || IS_23XX(isp)) {
674 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
676 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
679 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
680 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
681 ISP_WRITE(isp, isp->isp_respinrp, 0);
682 ISP_WRITE(isp, isp->isp_respoutrp, 0);
684 ISP_WRITE(isp, BIU2400_PRI_REQINP, 0);
685 ISP_WRITE(isp, BIU2400_PRI_REQOUTP, 0);
686 ISP_WRITE(isp, BIU2400_ATIO_RSPINP, 0);
687 ISP_WRITE(isp, BIU2400_ATIO_RSPOUTP, 0);
691 * Do MD specific post initialization
696 * Wait for everything to finish firing up.
698 * Avoid doing this on early 2312s because you can generate a PCI
699 * parity error (chip breakage).
701 if (IS_2312(isp) && isp->isp_revision < 2) {
704 loops = MBOX_DELAY_COUNT;
705 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
709 isp_prt(isp, ISP_LOGERR,
710 "MBOX_BUSY never cleared on reset");
717 * Up until this point we've done everything by just reading or
718 * setting registers. From this point on we rely on at least *some*
719 * kind of firmware running in the card.
723 * Do some sanity checking by running a NOP command.
724 * If it succeeds, the ROM firmware is now running.
726 ISP_MEMZERO(&mbs, sizeof (mbs));
727 mbs.param[0] = MBOX_NO_OP;
728 mbs.logval = MBLOGALL;
729 isp_mboxcmd(isp, &mbs);
730 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
731 isp_prt(isp, ISP_LOGERR, "NOP ommand failed (%x)",
738 * Do some operational tests
741 if (IS_SCSI(isp) || IS_24XX(isp)) {
742 ISP_MEMZERO(&mbs, sizeof (mbs));
743 mbs.param[0] = MBOX_MAILBOX_REG_TEST;
744 mbs.param[1] = 0xdead;
745 mbs.param[2] = 0xbeef;
746 mbs.param[3] = 0xffff;
747 mbs.param[4] = 0x1111;
748 mbs.param[5] = 0xa5a5;
749 mbs.param[6] = 0x0000;
750 mbs.param[7] = 0x0000;
751 mbs.logval = MBLOGALL;
752 isp_mboxcmd(isp, &mbs);
753 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
757 if (mbs.param[1] != 0xdead || mbs.param[2] != 0xbeef ||
758 mbs.param[3] != 0xffff || mbs.param[4] != 0x1111 ||
759 mbs.param[5] != 0xa5a5) {
761 isp_prt(isp, ISP_LOGERR,
762 "Register Test Failed (0x%x 0x%x 0x%x 0x%x 0x%x)",
763 mbs.param[1], mbs.param[2], mbs.param[3],
764 mbs.param[4], mbs.param[5]);
771 * Download new Firmware, unless requested not to do so.
772 * This is made slightly trickier in some cases where the
773 * firmware of the ROM revision is newer than the revision
774 * compiled into the driver. So, where we used to compare
775 * versions of our f/w and the ROM f/w, now we just see
776 * whether we have f/w at all and whether a config flag
777 * has disabled our download.
779 if ((isp->isp_mdvec->dv_ispfw == NULL) ||
780 (isp->isp_confopts & ISP_CFG_NORELOAD)) {
785 code_org = ISP_CODE_ORG_2400;
786 } else if (IS_23XX(isp)) {
787 code_org = ISP_CODE_ORG_2300;
789 code_org = ISP_CODE_ORG;
792 if (dodnld && IS_24XX(isp)) {
793 const uint32_t *ptr = isp->isp_mdvec->dv_ispfw;
796 * Keep loading until we run out of f/w.
798 code_org = ptr[2]; /* 1st load address is our start addr */
803 isp_prt(isp, ISP_LOGDEBUG0,
804 "load 0x%x words of code at load address 0x%x",
811 while (wi < ptr[3]) {
815 nw = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) >> 2;
819 cp = isp->isp_rquest;
820 for (i = 0; i < nw; i++) {
821 ISP_IOXPUT_32(isp, ptr[wi++], &cp[i]);
824 MEMORYBARRIER(isp, SYNC_REQUEST,
825 0, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)));
826 ISP_MEMZERO(&mbs, sizeof (mbs));
827 mbs.param[0] = MBOX_LOAD_RISC_RAM;
829 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
830 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
831 mbs.param[4] = nw >> 16;
833 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
834 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
835 mbs.param[8] = la >> 16;
836 mbs.logval = MBLOGALL;
837 isp_mboxcmd(isp, &mbs);
838 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
839 isp_prt(isp, ISP_LOGERR,
840 "F/W Risc Ram Load Failed");
852 isp->isp_loaded_fw = 1;
853 } else if (dodnld && IS_23XX(isp)) {
854 const uint16_t *ptr = isp->isp_mdvec->dv_ispfw;
855 uint16_t wi, wl, segno;
864 isp_prt(isp, ISP_LOGDEBUG0,
865 "load 0x%x words of code at load address 0x%x",
871 while (wi < ptr[3]) {
875 nw = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) >> 1;
879 if (nw > (1 << 15)) {
882 cp = isp->isp_rquest;
883 for (i = 0; i < nw; i++) {
884 ISP_IOXPUT_16(isp, ptr[wi++], &cp[i]);
887 MEMORYBARRIER(isp, SYNC_REQUEST,
888 0, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)));
889 ISP_MEMZERO(&mbs, sizeof (mbs));
890 mbs.param[0] = MBOX_LOAD_RISC_RAM;
892 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
893 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
895 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
896 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
897 mbs.param[8] = la >> 16;
898 mbs.logval = MBLOGALL;
899 isp_mboxcmd(isp, &mbs);
900 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
901 isp_prt(isp, ISP_LOGERR,
902 "F/W Risc Ram Load Failed");
918 * If we're a 2322, the firmware actually comes in
919 * three chunks. We loaded the first at the code_org
920 * address. The other two chunks, which follow right
921 * after each other in memory here, get loaded at
922 * addresses specfied at offset 0x9..0xB.
927 la = ptr[5] | ((ptr[4] & 0x3f) << 16);
929 isp->isp_loaded_fw = 1;
935 ucd.cp = isp->isp_mdvec->dv_ispfw;
936 isp->isp_mbxworkp = &ucd.np[1];
937 isp->isp_mbxwrk0 = ucd.np[3] - 1;
938 isp->isp_mbxwrk1 = code_org + 1;
939 ISP_MEMZERO(&mbs, sizeof (mbs));
940 mbs.param[0] = MBOX_WRITE_RAM_WORD;
941 mbs.param[1] = code_org;
942 mbs.param[2] = ucd.np[0];
943 mbs.logval = MBLOGNONE;
944 isp_mboxcmd(isp, &mbs);
945 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
946 isp_prt(isp, ISP_LOGERR,
947 "F/W download failed at word %d",
948 isp->isp_mbxwrk1 - code_org);
953 isp->isp_loaded_fw = 0;
954 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
958 * If we loaded firmware, verify its checksum
960 if (isp->isp_loaded_fw) {
961 ISP_MEMZERO(&mbs, sizeof (mbs));
962 mbs.param[0] = MBOX_VERIFY_CHECKSUM;
964 mbs.param[1] = code_org >> 16;
965 mbs.param[2] = code_org;
967 mbs.param[1] = code_org;
969 isp_mboxcmd(isp, &mbs);
970 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
971 isp_prt(isp, ISP_LOGERR, dcrc);
978 * Now start it rolling.
980 * If we didn't actually download f/w,
981 * we still need to (re)start it.
985 MBSINIT(&mbs, MBOX_EXEC_FIRMWARE, MBLOGALL, 1000000);
987 mbs.param[1] = code_org >> 16;
988 mbs.param[2] = code_org;
989 if (isp->isp_loaded_fw) {
997 } else if (IS_2322(isp)) {
998 mbs.param[1] = code_org;
999 if (isp->isp_loaded_fw) {
1005 mbs.param[1] = code_org;
1007 isp_mboxcmd(isp, &mbs);
1008 if (IS_2322(isp) || IS_24XX(isp)) {
1009 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1016 * Give it a chance to finish starting up.
1017 * Give the 24XX more time.
1022 * Check to see if the 24XX firmware really started.
1024 if (mbs.param[1] == 0xdead) {
1025 isp_prt(isp, ISP_LOGERR, "f/w didn't *really* start");
1033 * Set CLOCK RATE, but only if asked to.
1035 if (isp->isp_clock) {
1036 mbs.param[0] = MBOX_SET_CLOCK_RATE;
1037 mbs.param[1] = isp->isp_clock;
1038 mbs.logval = MBLOGNONE;
1039 isp_mboxcmd(isp, &mbs);
1040 /* we will try not to care if this fails */
1046 * Ask the chip for the current firmware version.
1047 * This should prove that the new firmware is working.
1049 MBSINIT(&mbs, MBOX_ABOUT_FIRMWARE, MBLOGALL, 0);
1050 isp_mboxcmd(isp, &mbs);
1051 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1057 * The SBus firmware that we are using apparently does not return
1058 * major, minor, micro revisions in the mailbox registers, which
1059 * is really, really, annoying.
1061 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
1063 #ifdef ISP_TARGET_MODE
1064 isp->isp_fwrev[0] = 7;
1065 isp->isp_fwrev[1] = 55;
1067 isp->isp_fwrev[0] = 1;
1068 isp->isp_fwrev[1] = 37;
1070 isp->isp_fwrev[2] = 0;
1073 isp->isp_fwrev[0] = mbs.param[1];
1074 isp->isp_fwrev[1] = mbs.param[2];
1075 isp->isp_fwrev[2] = mbs.param[3];
1078 isp_prt(isp, ISP_LOGCONFIG,
1079 "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
1080 btype, isp->isp_revision, dodnld? "loaded" : "resident",
1081 isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
1085 * We do not believe firmware attributes for 2100 code less
1086 * than 1.17.0, unless it's the firmware we specifically
1089 * Note that all 22XX and later f/w is greater than 1.X.0.
1091 if ((ISP_FW_OLDER_THAN(isp, 1, 17, 1))) {
1092 #ifdef USE_SMALLER_2100_FIRMWARE
1093 isp->isp_fwattr = ISP_FW_ATTR_SCCLUN;
1095 isp->isp_fwattr = 0;
1098 isp->isp_fwattr = mbs.param[6];
1099 isp_prt(isp, ISP_LOGDEBUG0,
1100 "Firmware Attributes = 0x%x", mbs.param[6]);
1103 #ifndef ISP_TARGET_MODE
1104 isp->isp_fwattr = ISP_FW_ATTR_TMODE;
1106 isp->isp_fwattr = 0;
1110 if (!IS_24XX(isp)) {
1111 MBSINIT(&mbs, MBOX_GET_FIRMWARE_STATUS, MBLOGALL, 0);
1112 isp_mboxcmd(isp, &mbs);
1113 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1117 if (isp->isp_maxcmds >= mbs.param[2]) {
1118 isp->isp_maxcmds = mbs.param[2];
1121 isp_prt(isp, ISP_LOGCONFIG,
1122 "%d max I/O command limit set", isp->isp_maxcmds);
1123 for (i = 0; i < isp->isp_nchan; i++) {
1124 isp_fw_state(isp, i);
1126 if (isp->isp_dead) {
1128 ISP_DISABLE_INTS(isp);
1132 isp->isp_state = ISP_RESETSTATE;
1135 * Okay- now that we have new firmware running, we now (re)set our
1136 * notion of how many luns we support. This is somewhat tricky because
1137 * if we haven't loaded firmware, we sometimes do not have an easy way
1138 * of knowing how many luns we support.
1140 * Expanded lun firmware gives you 32 luns for SCSI cards and
1141 * 16384 luns for Fibre Channel cards.
1143 * It turns out that even for QLogic 2100s with ROM 1.10 and above
1144 * we do get a firmware attributes word returned in mailbox register 6.
1146 * Because the lun is in a different position in the Request Queue
1147 * Entry structure for Fibre Channel with expanded lun firmware, we
1148 * can only support one lun (lun zero) when we don't know what kind
1149 * of firmware we're running.
1153 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
1154 isp->isp_maxluns = 32;
1156 isp->isp_maxluns = 8;
1159 isp->isp_maxluns = 8;
1162 if (ISP_CAP_SCCFW(isp)) {
1163 isp->isp_maxluns = 16384;
1165 isp->isp_maxluns = 16;
1170 * We get some default values established. As a side
1171 * effect, NVRAM is read here (unless overriden by
1172 * a configuration flag).
1175 isp_setdfltsdparm(isp);
1177 for (i = 0; i < isp->isp_nchan; i++) {
1178 isp_setdfltfcparm(isp, i);
1185 * Initialize Parameters of Hardware to a known state.
1187 * Locks are held before coming here.
1191 isp_init(ispsoftc_t *isp)
1195 isp_fibre_init_2400(isp);
1197 isp_fibre_init(isp);
1205 isp_scsi_init(ispsoftc_t *isp)
1207 sdparam *sdp_chan0, *sdp_chan1;
1210 sdp_chan0 = SDPARAM(isp, 0);
1211 sdp_chan1 = sdp_chan0;
1212 if (IS_DUALBUS(isp)) {
1213 sdp_chan1 = SDPARAM(isp, 1);
1216 /* First do overall per-card settings. */
1219 * If we have fast memory timing enabled, turn it on.
1221 if (sdp_chan0->isp_fast_mttr) {
1222 ISP_WRITE(isp, RISC_MTR, 0x1313);
1226 * Set Retry Delay and Count.
1227 * You set both channels at the same time.
1229 MBSINIT(&mbs, MBOX_SET_RETRY_COUNT, MBLOGALL, 0);
1230 mbs.param[1] = sdp_chan0->isp_retry_count;
1231 mbs.param[2] = sdp_chan0->isp_retry_delay;
1232 mbs.param[6] = sdp_chan1->isp_retry_count;
1233 mbs.param[7] = sdp_chan1->isp_retry_delay;
1234 isp_mboxcmd(isp, &mbs);
1235 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1240 * Set ASYNC DATA SETUP time. This is very important.
1242 MBSINIT(&mbs, MBOX_SET_ASYNC_DATA_SETUP_TIME, MBLOGALL, 0);
1243 mbs.param[1] = sdp_chan0->isp_async_data_setup;
1244 mbs.param[2] = sdp_chan1->isp_async_data_setup;
1245 isp_mboxcmd(isp, &mbs);
1246 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1251 * Set ACTIVE Negation State.
1253 MBSINIT(&mbs, MBOX_SET_ACT_NEG_STATE, MBLOGNONE, 0);
1255 (sdp_chan0->isp_req_ack_active_neg << 4) |
1256 (sdp_chan0->isp_data_line_active_neg << 5);
1258 (sdp_chan1->isp_req_ack_active_neg << 4) |
1259 (sdp_chan1->isp_data_line_active_neg << 5);
1260 isp_mboxcmd(isp, &mbs);
1261 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1262 isp_prt(isp, ISP_LOGERR,
1263 "failed to set active negation state (%d,%d), (%d,%d)",
1264 sdp_chan0->isp_req_ack_active_neg,
1265 sdp_chan0->isp_data_line_active_neg,
1266 sdp_chan1->isp_req_ack_active_neg,
1267 sdp_chan1->isp_data_line_active_neg);
1274 * Set the Tag Aging limit
1276 MBSINIT(&mbs, MBOX_SET_TAG_AGE_LIMIT, MBLOGALL, 0);
1277 mbs.param[1] = sdp_chan0->isp_tag_aging;
1278 mbs.param[2] = sdp_chan1->isp_tag_aging;
1279 isp_mboxcmd(isp, &mbs);
1280 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1281 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
1282 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
1287 * Set selection timeout.
1289 MBSINIT(&mbs, MBOX_SET_SELECT_TIMEOUT, MBLOGALL, 0);
1290 mbs.param[1] = sdp_chan0->isp_selection_timeout;
1291 mbs.param[2] = sdp_chan1->isp_selection_timeout;
1292 isp_mboxcmd(isp, &mbs);
1293 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1297 /* now do per-channel settings */
1298 isp_scsi_channel_init(isp, 0);
1299 if (IS_DUALBUS(isp))
1300 isp_scsi_channel_init(isp, 1);
1303 * Now enable request/response queues
1306 if (IS_ULTRA2(isp) || IS_1240(isp)) {
1307 MBSINIT(&mbs, MBOX_INIT_RES_QUEUE_A64, MBLOGALL, 0);
1308 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1309 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1310 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1312 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1313 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1314 isp_mboxcmd(isp, &mbs);
1315 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1318 isp->isp_residx = mbs.param[5];
1320 MBSINIT(&mbs, MBOX_INIT_REQ_QUEUE_A64, MBLOGALL, 0);
1321 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1322 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1323 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1325 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1326 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1327 isp_mboxcmd(isp, &mbs);
1328 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1331 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1333 MBSINIT(&mbs, MBOX_INIT_RES_QUEUE, MBLOGALL, 0);
1334 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1335 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1336 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1338 isp_mboxcmd(isp, &mbs);
1339 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1342 isp->isp_residx = mbs.param[5];
1344 MBSINIT(&mbs, MBOX_INIT_REQ_QUEUE, MBLOGALL, 0);
1345 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1346 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1347 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1349 isp_mboxcmd(isp, &mbs);
1350 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1353 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1357 * Turn on Fast Posting, LVD transitions
1359 * Ultra2 F/W always has had fast posting (and LVD transitions)
1361 * Ultra and older (i.e., SBus) cards may not. It's just safer
1362 * to assume not for them.
1365 MBSINIT(&mbs, MBOX_SET_FW_FEATURES, MBLOGALL, 0);
1367 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1369 if (IS_ULTRA2(isp) || IS_1240(isp))
1370 mbs.param[1] |= FW_FEATURE_RIO_16BIT;
1372 if (IS_ULTRA2(isp) || IS_1240(isp))
1373 mbs.param[1] |= FW_FEATURE_FAST_POST;
1375 if (mbs.param[1] != 0) {
1376 uint16_t sfeat = mbs.param[1];
1377 isp_mboxcmd(isp, &mbs);
1378 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1379 isp_prt(isp, ISP_LOGINFO,
1380 "Enabled FW features (0x%x)", sfeat);
1384 isp->isp_state = ISP_INITSTATE;
1388 isp_scsi_channel_init(ispsoftc_t *isp, int chan)
1394 sdp = SDPARAM(isp, chan);
1397 * Set (possibly new) Initiator ID.
1399 MBSINIT(&mbs, MBOX_SET_INIT_SCSI_ID, MBLOGALL, 0);
1400 mbs.param[1] = (chan << 7) | sdp->isp_initiator_id;
1401 isp_mboxcmd(isp, &mbs);
1402 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1405 isp_prt(isp, ISP_LOGINFO, "Chan %d Initiator ID is %d",
1406 chan, sdp->isp_initiator_id);
1410 * Set current per-target parameters to an initial safe minimum.
1412 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1416 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1419 #ifndef ISP_TARGET_MODE
1420 sdf = sdp->isp_devparam[tgt].goal_flags;
1421 sdf &= DPARM_SAFE_DFLT;
1423 * It is not quite clear when this changed over so that
1424 * we could force narrow and async for 1000/1020 cards,
1425 * but assume that this is only the case for loaded
1428 if (isp->isp_loaded_fw) {
1429 sdf |= DPARM_NARROW | DPARM_ASYNC;
1433 * The !$*!)$!$)* f/w uses the same index into some
1434 * internal table to decide how to respond to negotiations,
1435 * so if we've said "let's be safe" for ID X, and ID X
1436 * selects *us*, the negotiations will back to 'safe'
1437 * (as in narrow/async). What the f/w *should* do is
1438 * use the initiator id settings to decide how to respond.
1440 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1442 MBSINIT(&mbs, MBOX_SET_TARGET_PARAMS, MBLOGNONE, 0);
1443 mbs.param[1] = (chan << 15) | (tgt << 8);
1445 if ((sdf & DPARM_SYNC) == 0) {
1449 (sdp->isp_devparam[tgt].goal_offset << 8) |
1450 (sdp->isp_devparam[tgt].goal_period);
1452 isp_prt(isp, ISP_LOGDEBUG0,
1453 "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1454 chan, tgt, mbs.param[2], mbs.param[3] >> 8,
1455 mbs.param[3] & 0xff);
1456 isp_mboxcmd(isp, &mbs);
1457 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1458 sdf = DPARM_SAFE_DFLT;
1459 MBSINIT(&mbs, MBOX_SET_TARGET_PARAMS, MBLOGALL, 0);
1460 mbs.param[1] = (tgt << 8) | (chan << 15);
1463 isp_mboxcmd(isp, &mbs);
1464 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1470 * We don't update any information directly from the f/w
1471 * because we need to run at least one command to cause a
1472 * new state to be latched up. So, we just assume that we
1473 * converge to the values we just had set.
1475 * Ensure that we don't believe tagged queuing is enabled yet.
1476 * It turns out that sometimes the ISP just ignores our
1477 * attempts to set parameters for devices that it hasn't
1480 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1481 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1482 MBSINIT(&mbs, MBOX_SET_DEV_QUEUE_PARAMS, MBLOGALL, 0);
1483 mbs.param[1] = (chan << 15) | (tgt << 8) | lun;
1484 mbs.param[2] = sdp->isp_max_queue_depth;
1485 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1486 isp_mboxcmd(isp, &mbs);
1487 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1492 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1493 if (sdp->isp_devparam[tgt].dev_refresh) {
1494 sdp->sendmarker = 1;
1502 * Fibre Channel specific initialization.
1505 isp_fibre_init(ispsoftc_t *isp)
1508 isp_icb_t local, *icbp = &local;
1513 * We only support one channel on non-24XX cards
1515 fcp = FCPARAM(isp, 0);
1516 if (fcp->role == ISP_ROLE_NONE) {
1517 isp->isp_state = ISP_INITSTATE;
1521 ISP_MEMZERO(icbp, sizeof (*icbp));
1522 icbp->icb_version = ICB_VERSION1;
1523 icbp->icb_fwoptions = fcp->isp_fwoptions;
1526 * Firmware Options are either retrieved from NVRAM or
1527 * are patched elsewhere. We check them for sanity here
1528 * and make changes based on board revision, but otherwise
1529 * let others decide policy.
1533 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1535 if (IS_2100(isp) && isp->isp_revision < 5) {
1536 icbp->icb_fwoptions &= ~ICBOPT_FAIRNESS;
1540 * We have to use FULL LOGIN even though it resets the loop too much
1541 * because otherwise port database entries don't get updated after
1542 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1544 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1545 icbp->icb_fwoptions |= ICBOPT_FULL_LOGIN;
1549 * Insist on Port Database Update Async notifications
1551 icbp->icb_fwoptions |= ICBOPT_PDBCHANGE_AE;
1554 * Make sure that target role reflects into fwoptions.
1556 if (fcp->role & ISP_ROLE_TARGET) {
1557 icbp->icb_fwoptions |= ICBOPT_TGT_ENABLE;
1559 icbp->icb_fwoptions &= ~ICBOPT_TGT_ENABLE;
1562 if (fcp->role & ISP_ROLE_INITIATOR) {
1563 icbp->icb_fwoptions &= ~ICBOPT_INI_DISABLE;
1565 icbp->icb_fwoptions |= ICBOPT_INI_DISABLE;
1568 icbp->icb_maxfrmlen = DEFAULT_FRAMESIZE(isp);
1569 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN ||
1570 icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1571 isp_prt(isp, ISP_LOGERR,
1572 "bad frame length (%d) from NVRAM- using %d",
1573 DEFAULT_FRAMESIZE(isp), ICB_DFLT_FRMLEN);
1574 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1576 icbp->icb_maxalloc = fcp->isp_maxalloc;
1577 if (icbp->icb_maxalloc < 1) {
1578 isp_prt(isp, ISP_LOGERR,
1579 "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1580 icbp->icb_maxalloc = 16;
1582 icbp->icb_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
1583 if (icbp->icb_execthrottle < 1) {
1584 isp_prt(isp, ISP_LOGERR,
1585 "bad execution throttle of %d- using %d",
1586 DEFAULT_EXEC_THROTTLE(isp), ICB_DFLT_THROTTLE);
1587 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1589 icbp->icb_retry_delay = fcp->isp_retry_delay;
1590 icbp->icb_retry_count = fcp->isp_retry_count;
1591 icbp->icb_hardaddr = fcp->isp_loopid;
1592 ownloopid = (isp->isp_confopts & ISP_CFG_OWNLOOPID) != 0;
1593 if (icbp->icb_hardaddr >= LOCAL_LOOP_LIM) {
1594 icbp->icb_hardaddr = 0;
1599 * Our life seems so much better with 2200s and later with
1600 * the latest f/w if we set Hard Address.
1602 if (ownloopid || ISP_FW_NEWER_THAN(isp, 2, 2, 5)) {
1603 icbp->icb_fwoptions |= ICBOPT_HARD_ADDRESS;
1607 * Right now we just set extended options to prefer point-to-point
1608 * over loop based upon some soft config options.
1610 * NB: for the 2300, ICBOPT_EXTENDED is required.
1612 if (IS_2200(isp) || IS_23XX(isp)) {
1613 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1615 * Prefer or force Point-To-Point instead Loop?
1617 switch (isp->isp_confopts & ISP_CFG_PORT_PREF) {
1619 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1621 case ISP_CFG_NPORT_ONLY:
1622 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1624 case ISP_CFG_LPORT_ONLY:
1625 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1628 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1633 * There seems to just be too much breakage here
1634 * with RIO and Fast Posting- it probably actually
1635 * works okay but this driver is messing it up.
1636 * This card is really ancient by now, so let's
1637 * just opt for safety and not use the feature.
1640 if (ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1641 icbp->icb_xfwoptions |= ICBXOPT_RIO_16BIT;
1642 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1643 icbp->icb_racctimer = 4;
1644 icbp->icb_idelaytimer = 8;
1646 icbp->icb_fwoptions |= ICBOPT_FAST_POST;
1649 icbp->icb_xfwoptions &= ~ICBXOPT_RIO_16BIT;
1650 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1654 * QLogic recommends that FAST Posting be turned
1655 * off for 23XX cards and instead allow the HBA
1656 * to write response queue entries and interrupt
1657 * after a delay (ZIO).
1659 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1660 if ((fcp->isp_xfwoptions & ICBXOPT_TIMER_MASK) ==
1662 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1663 icbp->icb_idelaytimer = 10;
1665 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1666 icbp->icb_zfwoptions |= ICBZOPT_RATE_ONEGB;
1667 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1668 icbp->icb_zfwoptions |= ICBZOPT_RATE_TWOGB;
1670 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1672 if (fcp->isp_zfwoptions & ICBZOPT_50_OHM) {
1673 icbp->icb_zfwoptions |= ICBZOPT_50_OHM;
1680 * For 22XX > 2.1.26 && 23XX, set some options.
1681 * XXX: Probably okay for newer 2100 f/w too.
1683 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1685 * Turn on LIP F8 async event (1)
1686 * Turn on generate AE 8013 on all LIP Resets (2)
1687 * Disable LIP F7 switching (8)
1689 MBSINIT(&mbs, MBOX_SET_FIRMWARE_OPTIONS, MBLOGALL, 0);
1693 isp_mboxcmd(isp, &mbs);
1694 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1698 icbp->icb_logintime = ICB_LOGIN_TOV;
1699 icbp->icb_lunetimeout = ICB_LUN_ENABLE_TOV;
1701 if (fcp->isp_wwnn && fcp->isp_wwpn && (fcp->isp_wwnn >> 60) != 2) {
1702 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1703 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, fcp->isp_wwnn);
1704 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1705 isp_prt(isp, ISP_LOGDEBUG1,
1706 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1707 ((uint32_t) (fcp->isp_wwnn >> 32)),
1708 ((uint32_t) (fcp->isp_wwnn)),
1709 ((uint32_t) (fcp->isp_wwpn >> 32)),
1710 ((uint32_t) (fcp->isp_wwpn)));
1711 } else if (fcp->isp_wwpn) {
1712 icbp->icb_fwoptions &= ~ICBOPT_BOTH_WWNS;
1713 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1714 isp_prt(isp, ISP_LOGDEBUG1,
1715 "Setting ICB Port 0x%08x%08x",
1716 ((uint32_t) (fcp->isp_wwpn >> 32)),
1717 ((uint32_t) (fcp->isp_wwpn)));
1719 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
1722 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1723 if (icbp->icb_rqstqlen < 1) {
1724 isp_prt(isp, ISP_LOGERR, "bad request queue length");
1726 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1727 if (icbp->icb_rsltqlen < 1) {
1728 isp_prt(isp, ISP_LOGERR, "bad result queue length");
1730 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1731 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1732 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1733 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1734 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1735 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1736 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1737 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1739 if (FC_SCRATCH_ACQUIRE(isp, 0)) {
1740 isp_prt(isp, ISP_LOGERR, sacq);
1743 isp_prt(isp, ISP_LOGDEBUG0,
1744 "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1745 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1747 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1752 MBSINIT(&mbs, MBOX_INIT_FIRMWARE, MBLOGALL, 30000000);
1753 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1754 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1755 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1756 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1757 mbs.logval = MBLOGALL;
1758 isp_prt(isp, ISP_LOGDEBUG0, "INIT F/W from %p (%08x%08x)",
1759 fcp->isp_scratch, (uint32_t) ((uint64_t)fcp->isp_scdma >> 32),
1760 (uint32_t) fcp->isp_scdma);
1761 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp));
1762 isp_mboxcmd(isp, &mbs);
1763 FC_SCRATCH_RELEASE(isp, 0);
1764 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1765 isp_print_bytes(isp, "isp_fibre_init", sizeof (*icbp), icbp);
1768 isp->isp_reqidx = 0;
1769 isp->isp_reqodx = 0;
1770 isp->isp_residx = 0;
1773 * Whatever happens, we're now committed to being here.
1775 isp->isp_state = ISP_INITSTATE;
1779 isp_fibre_init_2400(ispsoftc_t *isp)
1782 isp_icb_2400_t local, *icbp = &local;
1787 * Check to see whether all channels have *some* kind of role
1789 for (chan = 0; chan < isp->isp_nchan; chan++) {
1790 fcp = FCPARAM(isp, chan);
1791 if (fcp->role != ISP_ROLE_NONE) {
1795 if (chan == isp->isp_nchan) {
1796 isp_prt(isp, ISP_LOGDEBUG0, "all %d channels with role 'none'", chan);
1797 isp->isp_state = ISP_INITSTATE;
1801 if (ISP_CAP_MULTI_ID(isp) == 0 && isp->isp_nchan > 1) {
1802 isp_prt(isp, ISP_LOGWARN,
1803 "non-MULTIID f/w loaded, only can enable 1 of %d channels",
1807 nchan = isp->isp_nchan;
1811 * Start with channel 0.
1813 fcp = FCPARAM(isp, 0);
1816 * Turn on LIP F8 async event (1)
1818 MBSINIT(&mbs, MBOX_SET_FIRMWARE_OPTIONS, MBLOGALL, 0);
1820 isp_mboxcmd(isp, &mbs);
1821 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1825 ISP_MEMZERO(icbp, sizeof (*icbp));
1826 icbp->icb_fwoptions1 = fcp->isp_fwoptions;
1827 if (fcp->role & ISP_ROLE_TARGET) {
1828 icbp->icb_fwoptions1 |= ICB2400_OPT1_TGT_ENABLE;
1830 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_TGT_ENABLE;
1833 if (fcp->role & ISP_ROLE_INITIATOR) {
1834 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_INI_DISABLE;
1836 icbp->icb_fwoptions1 |= ICB2400_OPT1_INI_DISABLE;
1839 icbp->icb_version = ICB_VERSION1;
1840 icbp->icb_maxfrmlen = DEFAULT_FRAMESIZE(isp);
1841 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN ||
1842 icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1843 isp_prt(isp, ISP_LOGERR,
1844 "bad frame length (%d) from NVRAM- using %d",
1845 DEFAULT_FRAMESIZE(isp), ICB_DFLT_FRMLEN);
1846 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1849 icbp->icb_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
1850 if (icbp->icb_execthrottle < 1) {
1851 isp_prt(isp, ISP_LOGERR,
1852 "bad execution throttle of %d- using %d",
1853 DEFAULT_EXEC_THROTTLE(isp), ICB_DFLT_THROTTLE);
1854 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1857 if (icbp->icb_fwoptions1 & ICB2400_OPT1_TGT_ENABLE) {
1859 * Get current resource count
1861 MBSINIT(&mbs, MBOX_GET_RESOURCE_COUNT, MBLOGALL, 0);
1863 isp_mboxcmd(isp, &mbs);
1864 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1867 icbp->icb_xchgcnt = mbs.param[3];
1871 icbp->icb_hardaddr = fcp->isp_loopid;
1872 if (icbp->icb_hardaddr >= LOCAL_LOOP_LIM) {
1873 icbp->icb_hardaddr = 0;
1879 icbp->icb_fwoptions1 |= ICB2400_OPT1_HARD_ADDRESS;
1881 icbp->icb_fwoptions2 = fcp->isp_xfwoptions;
1882 switch (isp->isp_confopts & ISP_CFG_PORT_PREF) {
1886 * XXX: This causes the f/w to crash.
1888 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
1889 icbp->icb_fwoptions2 |= ICB2400_OPT2_PTP_2_LOOP;
1892 case ISP_CFG_NPORT_ONLY:
1893 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
1894 icbp->icb_fwoptions2 |= ICB2400_OPT2_PTP_ONLY;
1896 case ISP_CFG_LPORT_ONLY:
1897 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
1898 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_ONLY;
1901 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
1902 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_2_PTP;
1906 /* force this on for now */
1907 icbp->icb_fwoptions2 |= ICB2400_OPT2_ZIO;
1909 switch (icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK) {
1910 case ICB2400_OPT2_ZIO:
1911 case ICB2400_OPT2_ZIO1:
1912 icbp->icb_idelaytimer = 0;
1917 isp_prt(isp, ISP_LOGWARN, "bad value %x in fwopt2 timer field",
1918 icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK);
1919 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TIMER_MASK;
1924 * We don't support FCTAPE, so clear it.
1926 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_FCTAPE;
1928 icbp->icb_fwoptions3 = fcp->isp_zfwoptions;
1929 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_AUTO;
1930 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1931 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_ONEGB;
1932 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1933 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_TWOGB;
1934 } else if (isp->isp_confopts & ISP_CFG_FOURGB) {
1935 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_FOURGB;
1937 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_AUTO;
1940 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
1941 icbp->icb_fwoptions3 |= ICB2400_OPT3_SOFTID;
1943 icbp->icb_logintime = ICB_LOGIN_TOV;
1945 if (fcp->isp_wwnn && fcp->isp_wwpn && (fcp->isp_wwnn >> 60) != 2) {
1946 icbp->icb_fwoptions1 |= ICB2400_OPT1_BOTH_WWNS;
1947 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1948 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, fcp->isp_wwnn);
1949 isp_prt(isp, ISP_LOGDEBUG1,
1950 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1951 ((uint32_t) (fcp->isp_wwnn >> 32)),
1952 ((uint32_t) (fcp->isp_wwnn)),
1953 ((uint32_t) (fcp->isp_wwpn >> 32)),
1954 ((uint32_t) (fcp->isp_wwpn)));
1955 } else if (fcp->isp_wwpn) {
1956 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_BOTH_WWNS;
1957 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1958 isp_prt(isp, ISP_LOGDEBUG1,
1959 "Setting ICB Node to be same as Port 0x%08x%08x",
1960 ((uint32_t) (fcp->isp_wwpn >> 32)),
1961 ((uint32_t) (fcp->isp_wwpn)));
1963 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
1966 icbp->icb_retry_count = fcp->isp_retry_count;
1968 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1969 if (icbp->icb_rqstqlen < 8) {
1970 isp_prt(isp, ISP_LOGERR, "bad request queue length %d",
1971 icbp->icb_rqstqlen);
1974 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1975 if (icbp->icb_rsltqlen < 8) {
1976 isp_prt(isp, ISP_LOGERR, "bad result queue length %d",
1977 icbp->icb_rsltqlen);
1980 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1981 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1982 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1983 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1985 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1986 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1987 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1988 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1990 #ifdef ISP_TARGET_MODE
1991 /* unconditionally set up the ATIO queue if we support target mode */
1992 icbp->icb_atioqlen = RESULT_QUEUE_LEN(isp);
1993 if (icbp->icb_atioqlen < 8) {
1994 isp_prt(isp, ISP_LOGERR,
1995 "bad ATIO queue length %d", icbp->icb_atioqlen);
1998 icbp->icb_atioqaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_atioq_dma);
1999 icbp->icb_atioqaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_atioq_dma);
2000 icbp->icb_atioqaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_atioq_dma);
2001 icbp->icb_atioqaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_atioq_dma);
2002 isp_prt(isp, ISP_LOGDEBUG0,
2003 "isp_fibre_init_2400: atioq %04x%04x%04x%04x",
2004 DMA_WD3(isp->isp_atioq_dma), DMA_WD2(isp->isp_atioq_dma),
2005 DMA_WD1(isp->isp_atioq_dma), DMA_WD0(isp->isp_atioq_dma));
2008 isp_prt(isp, ISP_LOGDEBUG0,
2009 "isp_fibre_init_2400: fwopt1 0x%x fwopt2 0x%x fwopt3 0x%x",
2010 icbp->icb_fwoptions1, icbp->icb_fwoptions2, icbp->icb_fwoptions3);
2012 isp_prt(isp, ISP_LOGDEBUG0,
2013 "isp_fibre_init_2400: rqst %04x%04x%04x%04x rsp %04x%04x%04x%04x",
2014 DMA_WD3(isp->isp_rquest_dma), DMA_WD2(isp->isp_rquest_dma),
2015 DMA_WD1(isp->isp_rquest_dma), DMA_WD0(isp->isp_rquest_dma),
2016 DMA_WD3(isp->isp_result_dma), DMA_WD2(isp->isp_result_dma),
2017 DMA_WD1(isp->isp_result_dma), DMA_WD0(isp->isp_result_dma));
2019 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2020 isp_print_bytes(isp, "isp_fibre_init_2400", sizeof (*icbp),
2024 if (FC_SCRATCH_ACQUIRE(isp, 0)) {
2025 isp_prt(isp, ISP_LOGERR, sacq);
2028 ISP_MEMZERO(fcp->isp_scratch, ISP_FC_SCRLEN);
2029 isp_put_icb_2400(isp, icbp, fcp->isp_scratch);
2032 * Now fill in information about any additional channels
2035 isp_icb_2400_vpinfo_t vpinfo, *vdst;
2036 vp_port_info_t pi, *pdst;
2040 vpinfo.vp_count = isp->isp_nchan - 1;
2041 vpinfo.vp_global_options = 0;
2042 off = fcp->isp_scratch;
2043 off += ICB2400_VPINFO_OFF;
2044 vdst = (isp_icb_2400_vpinfo_t *) off;
2045 isp_put_icb_2400_vpinfo(isp, &vpinfo, vdst);
2046 amt = ICB2400_VPINFO_OFF + sizeof (isp_icb_2400_vpinfo_t);
2047 for (chan = 1; chan < isp->isp_nchan; chan++) {
2050 ISP_MEMZERO(&pi, sizeof (pi));
2051 fcp2 = FCPARAM(isp, chan);
2052 if (fcp2->role != ISP_ROLE_NONE) {
2053 pi.vp_port_options = ICB2400_VPOPT_ENABLED;
2054 if (fcp2->role & ISP_ROLE_INITIATOR) {
2055 pi.vp_port_options |=
2056 ICB2400_VPOPT_INI_ENABLE;
2058 if ((fcp2->role & ISP_ROLE_TARGET) == 0) {
2059 pi.vp_port_options |=
2060 ICB2400_VPOPT_TGT_DISABLE;
2062 MAKE_NODE_NAME_FROM_WWN(pi.vp_port_portname,
2064 MAKE_NODE_NAME_FROM_WWN(pi.vp_port_nodename,
2067 off = fcp->isp_scratch;
2068 off += ICB2400_VPINFO_PORT_OFF(chan);
2069 pdst = (vp_port_info_t *) off;
2070 isp_put_vp_port_info(isp, &pi, pdst);
2071 amt += ICB2400_VPOPT_WRITE_SIZE;
2078 MBSINIT(&mbs, 0, MBLOGALL, 30000000);
2080 mbs.param[0] = MBOX_INIT_FIRMWARE_MULTI_ID;
2082 mbs.param[0] = MBOX_INIT_FIRMWARE;
2084 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2085 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2086 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2087 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2088 isp_prt(isp, ISP_LOGDEBUG0, "INIT F/W from %04x%04x%04x%04x",
2089 DMA_WD3(fcp->isp_scdma), DMA_WD2(fcp->isp_scdma),
2090 DMA_WD1(fcp->isp_scdma), DMA_WD0(fcp->isp_scdma));
2091 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp));
2092 isp_mboxcmd(isp, &mbs);
2093 FC_SCRATCH_RELEASE(isp, 0);
2095 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2098 isp->isp_reqidx = 0;
2099 isp->isp_reqodx = 0;
2100 isp->isp_residx = 0;
2103 * Whatever happens, we're now committed to being here.
2105 isp->isp_state = ISP_INITSTATE;
2109 isp_mark_portdb(ispsoftc_t *isp, int chan, int disposition)
2111 fcparam *fcp = FCPARAM(isp, chan);
2114 if (chan < 0 || chan >= isp->isp_nchan) {
2115 isp_prt(isp, ISP_LOGWARN, "isp_mark_portdb: bad channel %d", chan);
2118 for (i = 0; i < MAX_FC_TARG; i++) {
2119 if (fcp->portdb[i].target_mode) {
2120 if (disposition < 0) {
2121 isp_prt(isp, ISP_LOGTINFO, "isp_mark_portdb: Chan %d zeroing handle 0x" "%02x port 0x%06x", chan,
2122 fcp->portdb[i].handle, fcp->portdb[i].portid);
2123 ISP_MEMZERO(&fcp->portdb[i], sizeof (fcportdb_t));
2127 if (disposition == 0) {
2128 ISP_MEMZERO(&fcp->portdb[i], sizeof (fcportdb_t));
2130 switch (fcp->portdb[i].state) {
2131 case FC_PORTDB_STATE_CHANGED:
2132 case FC_PORTDB_STATE_PENDING_VALID:
2133 case FC_PORTDB_STATE_VALID:
2134 case FC_PORTDB_STATE_PROBATIONAL:
2135 fcp->portdb[i].state = FC_PORTDB_STATE_PROBATIONAL;
2137 case FC_PORTDB_STATE_ZOMBIE:
2139 case FC_PORTDB_STATE_NIL:
2141 ISP_MEMZERO(&fcp->portdb[i], sizeof (fcportdb_t));
2142 fcp->portdb[i].state = FC_PORTDB_STATE_NIL;
2150 * Perform an IOCB PLOGI or LOGO via EXECUTE IOCB A64 for 24XX cards
2151 * or via FABRIC LOGIN/FABRIC LOGOUT for other cards.
2154 isp_plogx(ispsoftc_t *isp, int chan, uint16_t handle, uint32_t portid,
2158 uint8_t q[QENTRY_LEN];
2162 uint32_t sst, parm1;
2167 if (!IS_24XX(isp)) {
2168 int action = flags & PLOGX_FLG_CMD_MASK;
2169 if (action == PLOGX_FLG_CMD_PLOGI) {
2170 return (isp_port_login(isp, handle, portid));
2171 } else if (action == PLOGX_FLG_CMD_LOGO) {
2172 return (isp_port_logout(isp, handle, portid));
2174 return (MBOX_INVALID_COMMAND);
2178 ISP_MEMZERO(q, QENTRY_LEN);
2179 plp = (isp_plogx_t *) q;
2180 plp->plogx_header.rqs_entry_count = 1;
2181 plp->plogx_header.rqs_entry_type = RQSTYPE_LOGIN;
2182 plp->plogx_handle = 0xffffffff;
2183 plp->plogx_nphdl = handle;
2184 plp->plogx_vphdl = chan;
2185 plp->plogx_portlo = portid;
2186 plp->plogx_rspsz_porthi = (portid >> 16) & 0xff;
2187 plp->plogx_flags = flags;
2189 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2190 isp_print_bytes(isp, "IOCB LOGX", QENTRY_LEN, plp);
2194 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
2195 isp_prt(isp, ISP_LOGERR, sacq);
2199 fcp = FCPARAM(isp, chan);
2200 scp = fcp->isp_scratch;
2201 isp_put_plogx(isp, plp, (isp_plogx_t *) scp);
2203 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 500000);
2204 mbs.param[1] = QENTRY_LEN;
2205 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2206 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2207 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2208 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2209 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, QENTRY_LEN);
2210 isp_mboxcmd(isp, &mbs);
2211 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2212 rval = mbs.param[0];
2215 MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN, QENTRY_LEN);
2217 isp_get_plogx(isp, (isp_plogx_t *) scp, plp);
2218 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2219 isp_print_bytes(isp, "IOCB LOGX response", QENTRY_LEN, plp);
2222 if (plp->plogx_status == PLOGX_STATUS_OK) {
2225 } else if (plp->plogx_status != PLOGX_STATUS_IOCBERR) {
2226 isp_prt(isp, ISP_LOGWARN,
2227 "status 0x%x on port login IOCB chanel %d",
2228 plp->plogx_status, chan);
2233 sst = plp->plogx_ioparm[0].lo16 | (plp->plogx_ioparm[0].hi16 << 16);
2234 parm1 = plp->plogx_ioparm[1].lo16 | (plp->plogx_ioparm[1].hi16 << 16);
2241 case PLOGX_IOCBERR_NOLINK:
2244 case PLOGX_IOCBERR_NOIOCB:
2245 msg = "no IOCB buffer";
2247 case PLOGX_IOCBERR_NOXGHG:
2248 msg = "no Exchange Control Block";
2250 case PLOGX_IOCBERR_FAILED:
2251 ISP_SNPRINTF(buf, sizeof (buf),
2252 "reason 0x%x (last LOGIN state 0x%x)",
2253 parm1 & 0xff, (parm1 >> 8) & 0xff);
2256 case PLOGX_IOCBERR_NOFABRIC:
2259 case PLOGX_IOCBERR_NOTREADY:
2260 msg = "firmware not ready";
2262 case PLOGX_IOCBERR_NOLOGIN:
2263 ISP_SNPRINTF(buf, sizeof (buf), "not logged in (last state 0x%x)",
2266 rval = MBOX_NOT_LOGGED_IN;
2268 case PLOGX_IOCBERR_REJECT:
2269 ISP_SNPRINTF(buf, sizeof (buf), "LS_RJT = 0x%x", parm1);
2272 case PLOGX_IOCBERR_NOPCB:
2273 msg = "no PCB allocated";
2275 case PLOGX_IOCBERR_EINVAL:
2276 ISP_SNPRINTF(buf, sizeof (buf), "invalid parameter at offset 0x%x",
2280 case PLOGX_IOCBERR_PORTUSED:
2281 lev = ISP_LOGSANCFG|ISP_LOGDEBUG0;
2282 ISP_SNPRINTF(buf, sizeof (buf),
2283 "already logged in with N-Port handle 0x%x", parm1);
2285 rval = MBOX_PORT_ID_USED | (parm1 << 16);
2287 case PLOGX_IOCBERR_HNDLUSED:
2288 lev = ISP_LOGSANCFG|ISP_LOGDEBUG0;
2289 ISP_SNPRINTF(buf, sizeof (buf),
2290 "handle already used for PortID 0x%06x", parm1);
2292 rval = MBOX_LOOP_ID_USED;
2294 case PLOGX_IOCBERR_NOHANDLE:
2295 msg = "no handle allocated";
2297 case PLOGX_IOCBERR_NOFLOGI:
2298 msg = "no FLOGI_ACC";
2301 ISP_SNPRINTF(buf, sizeof (buf), "status %x from %x",
2302 plp->plogx_status, flags);
2307 isp_prt(isp, ISP_LOGERR,
2308 "Chan %d PLOGX PortID 0x%06x to N-Port handle 0x%x: %s",
2309 chan, portid, handle, msg);
2313 FC_SCRATCH_RELEASE(isp, chan);
2319 isp_port_login(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2323 MBSINIT(&mbs, MBOX_FABRIC_LOGIN, MBLOGNONE, 500000);
2324 if (ISP_CAP_2KLOGIN(isp)) {
2325 mbs.param[1] = handle;
2326 mbs.ibits = (1 << 10);
2328 mbs.param[1] = handle << 8;
2330 mbs.param[2] = portid >> 16;
2331 mbs.param[3] = portid;
2332 mbs.logval = MBLOGNONE;
2333 mbs.timeout = 500000;
2334 isp_mboxcmd(isp, &mbs);
2336 switch (mbs.param[0]) {
2337 case MBOX_PORT_ID_USED:
2338 isp_prt(isp, ISP_LOGDEBUG0,
2339 "isp_port_login: portid 0x%06x already logged in as %u",
2340 portid, mbs.param[1]);
2341 return (MBOX_PORT_ID_USED | (mbs.param[1] << 16));
2343 case MBOX_LOOP_ID_USED:
2344 isp_prt(isp, ISP_LOGDEBUG0,
2345 "isp_port_login: handle %u in use for port id 0x%02xXXXX",
2346 handle, mbs.param[1] & 0xff);
2347 return (MBOX_LOOP_ID_USED);
2349 case MBOX_COMMAND_COMPLETE:
2352 case MBOX_COMMAND_ERROR:
2353 isp_prt(isp, ISP_LOGINFO,
2354 "isp_port_login: error 0x%x in PLOGI to port 0x%06x",
2355 mbs.param[1], portid);
2356 return (MBOX_COMMAND_ERROR);
2358 case MBOX_ALL_IDS_USED:
2359 isp_prt(isp, ISP_LOGINFO,
2360 "isp_port_login: all IDs used for fabric login");
2361 return (MBOX_ALL_IDS_USED);
2364 isp_prt(isp, ISP_LOGINFO,
2365 "isp_port_login: error 0x%x on port login of 0x%06x@0x%0x",
2366 mbs.param[0], portid, handle);
2367 return (mbs.param[0]);
2372 isp_port_logout(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2376 MBSINIT(&mbs, MBOX_FABRIC_LOGOUT, MBLOGNONE, 500000);
2377 if (ISP_CAP_2KLOGIN(isp)) {
2378 mbs.param[1] = handle;
2379 mbs.ibits = (1 << 10);
2381 mbs.param[1] = handle << 8;
2383 isp_mboxcmd(isp, &mbs);
2384 return (mbs.param[0] == MBOX_COMMAND_COMPLETE? 0 : mbs.param[0]);
2388 isp_getpdb(ispsoftc_t *isp, int chan, uint16_t id, isp_pdb_t *pdb, int dolock)
2390 fcparam *fcp = FCPARAM(isp, chan);
2393 isp_pdb_21xx_t fred;
2394 isp_pdb_24xx_t bill;
2397 MBSINIT(&mbs, MBOX_GET_PORT_DB, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR, 250000);
2399 mbs.ibits = (1 << 9)|(1 << 10);
2401 mbs.param[9] = chan;
2402 } else if (ISP_CAP_2KLOGIN(isp)) {
2405 mbs.param[1] = id << 8;
2407 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2408 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2409 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2410 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2412 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
2413 isp_prt(isp, ISP_LOGERR, sacq);
2417 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (un));
2418 isp_mboxcmd(isp, &mbs);
2419 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2421 FC_SCRATCH_RELEASE(isp, chan);
2423 return (mbs.param[0]);
2426 isp_get_pdb_24xx(isp, fcp->isp_scratch, &un.bill);
2427 pdb->handle = un.bill.pdb_handle;
2428 pdb->s3_role = un.bill.pdb_prli_svc3;
2429 pdb->portid = BITS2WORD_24XX(un.bill.pdb_portid_bits);
2430 ISP_MEMCPY(pdb->portname, un.bill.pdb_portname, 8);
2431 ISP_MEMCPY(pdb->nodename, un.bill.pdb_nodename, 8);
2432 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2433 "Chan %d Port 0x%06x flags 0x%x curstate %x",
2434 chan, pdb->portid, un.bill.pdb_flags,
2435 un.bill.pdb_curstate);
2436 if (un.bill.pdb_curstate < PDB2400_STATE_PLOGI_DONE ||
2437 un.bill.pdb_curstate > PDB2400_STATE_LOGGED_IN) {
2438 mbs.param[0] = MBOX_NOT_LOGGED_IN;
2440 FC_SCRATCH_RELEASE(isp, chan);
2442 return (mbs.param[0]);
2445 isp_get_pdb_21xx(isp, fcp->isp_scratch, &un.fred);
2446 pdb->handle = un.fred.pdb_loopid;
2447 pdb->s3_role = un.fred.pdb_prli_svc3;
2448 pdb->portid = BITS2WORD(un.fred.pdb_portid_bits);
2449 ISP_MEMCPY(pdb->portname, un.fred.pdb_portname, 8);
2450 ISP_MEMCPY(pdb->nodename, un.fred.pdb_nodename, 8);
2453 FC_SCRATCH_RELEASE(isp, chan);
2459 isp_dump_chip_portdb(ispsoftc_t *isp, int chan, int dolock)
2464 if (ISP_CAP_2KLOGIN(isp)) {
2469 for (loopid = 0; loopid != lim; loopid++) {
2470 if (isp_getpdb(isp, chan, loopid, &pdb, dolock)) {
2473 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGINFO, "Chan %d Loopid 0x%04x "
2474 "PortID 0x%06x WWPN 0x%02x%02x%02x%02x%02x%02x%02x%02x",
2475 chan, loopid, pdb.portid, pdb.portname[0], pdb.portname[1],
2476 pdb.portname[2], pdb.portname[3], pdb.portname[4],
2477 pdb.portname[5], pdb.portname[6], pdb.portname[7]);
2482 isp_get_wwn(ispsoftc_t *isp, int chan, int loopid, int nodename)
2484 uint64_t wwn = INI_NONE;
2485 fcparam *fcp = FCPARAM(isp, chan);
2488 if (fcp->isp_fwstate < FW_READY ||
2489 fcp->isp_loopstate < LOOP_PDB_RCVD) {
2492 MBSINIT(&mbs, MBOX_GET_PORT_NAME, MBLOGALL & ~MBOX_COMMAND_PARAM_ERROR, 500000);
2493 if (ISP_CAP_2KLOGIN(isp)) {
2494 mbs.param[1] = loopid;
2495 mbs.ibits = (1 << 10);
2499 if (ISP_CAP_MULTI_ID(isp)) {
2500 mbs.ibits |= (1 << 9);
2501 mbs.param[9] = chan;
2504 mbs.param[1] = loopid << 8;
2509 isp_mboxcmd(isp, &mbs);
2510 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2515 (((uint64_t)(mbs.param[2] >> 8)) << 56) |
2516 (((uint64_t)(mbs.param[2] & 0xff)) << 48) |
2517 (((uint64_t)(mbs.param[3] >> 8)) << 40) |
2518 (((uint64_t)(mbs.param[3] & 0xff)) << 32) |
2519 (((uint64_t)(mbs.param[6] >> 8)) << 24) |
2520 (((uint64_t)(mbs.param[6] & 0xff)) << 16) |
2521 (((uint64_t)(mbs.param[7] >> 8)) << 8) |
2522 (((uint64_t)(mbs.param[7] & 0xff)));
2525 (((uint64_t)(mbs.param[2] & 0xff)) << 56) |
2526 (((uint64_t)(mbs.param[2] >> 8)) << 48) |
2527 (((uint64_t)(mbs.param[3] & 0xff)) << 40) |
2528 (((uint64_t)(mbs.param[3] >> 8)) << 32) |
2529 (((uint64_t)(mbs.param[6] & 0xff)) << 24) |
2530 (((uint64_t)(mbs.param[6] >> 8)) << 16) |
2531 (((uint64_t)(mbs.param[7] & 0xff)) << 8) |
2532 (((uint64_t)(mbs.param[7] >> 8)));
2538 * Make sure we have good FC link.
2542 isp_fclink_test(ispsoftc_t *isp, int chan, int usdelay)
2545 int count, check_for_fabric, r;
2552 fcp = FCPARAM(isp, chan);
2554 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "Chan %d FC Link Test Entry", chan);
2555 ISP_MARK_PORTDB(isp, chan, 1);
2558 * Wait up to N microseconds for F/W to go to a ready state.
2560 lwfs = FW_CONFIG_WAIT;
2562 while (count < usdelay) {
2565 NANOTIME_T hra, hrb;
2568 isp_fw_state(isp, chan);
2569 if (lwfs != fcp->isp_fwstate) {
2570 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));
2571 lwfs = fcp->isp_fwstate;
2573 if (fcp->isp_fwstate == FW_READY) {
2579 * Get the elapsed time in nanoseconds.
2580 * Always guaranteed to be non-zero.
2582 enano = NANOTIME_SUB(&hrb, &hra);
2584 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));
2587 * If the elapsed time is less than 1 millisecond,
2588 * delay a period of time up to that millisecond of
2591 * This peculiar code is an attempt to try and avoid
2592 * invoking uint64_t math support functions for some
2593 * platforms where linkage is a problem.
2595 if (enano < (1000 * 1000)) {
2597 enano = (1000 * 1000) - enano;
2598 while (enano > (uint64_t) 4000000000U) {
2599 ISP_SLEEP(isp, 4000000);
2600 enano -= (uint64_t) 4000000000U;
2604 ISP_SLEEP(isp, wrk);
2606 while (enano > (uint64_t) 4000000000U) {
2607 #if defined(__GNUC__) && (__GNUC__ >= 4)
2609 * Prevent to optimize loop, gcc assume libgcc.a
2610 * with __udivdi3 is linked, but this is not
2611 * true when building (linux) kernel
2613 asm("" : "+rm" (enano));
2616 enano -= (uint64_t) 4000000000U;
2619 count += (wrk / 1000);
2626 * If we haven't gone to 'ready' state, return.
2628 if (fcp->isp_fwstate != FW_READY) {
2629 isp_prt(isp, ISP_LOGSANCFG, "%s: chan %d not at FW_READY state", __func__, chan);
2634 * Get our Loop ID and Port ID.
2636 MBSINIT(&mbs, MBOX_GET_LOOP_ID, MBLOGALL, 0);
2637 if (ISP_CAP_MULTI_ID(isp)) {
2638 mbs.param[9] = chan;
2639 mbs.ibits = (1 << 9);
2640 mbs.obits = (1 << 7);
2642 isp_mboxcmd(isp, &mbs);
2643 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2647 if (ISP_CAP_2KLOGIN(isp)) {
2648 fcp->isp_loopid = mbs.param[1];
2650 fcp->isp_loopid = mbs.param[1] & 0xff;
2654 fcp->isp_topo = TOPO_NL_PORT;
2656 int topo = (int) mbs.param[6];
2657 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB) {
2658 topo = TOPO_PTP_STUB;
2660 fcp->isp_topo = topo;
2662 fcp->isp_portid = mbs.param[2] | (mbs.param[3] << 16);
2666 * Don't bother with fabric if we are using really old
2667 * 2100 firmware. It's just not worth it.
2669 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37)) {
2670 check_for_fabric = 1;
2672 check_for_fabric = 0;
2674 } else if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_F_PORT) {
2675 check_for_fabric = 1;
2677 check_for_fabric = 0;
2681 * Check to make sure we got a valid loopid
2682 * The 24XX seems to mess this up for multiple channels.
2684 if (fcp->isp_topo == TOPO_FL_PORT || fcp->isp_topo == TOPO_NL_PORT) {
2685 uint8_t alpa = fcp->isp_portid;
2688 /* "Cannot Happen" */
2689 isp_prt(isp, ISP_LOGWARN, "Zero AL_PA for Loop Topology?");
2692 for (i = 0; alpa_map[i]; i++) {
2693 if (alpa_map[i] == alpa) {
2697 if (alpa_map[i] && fcp->isp_loopid != i) {
2698 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);
2699 fcp->isp_loopid = i;
2705 if (IS_24XX(isp)) { /* XXX SHOULDN'T THIS BE FOR 2K F/W? XXX */
2710 if (check_for_fabric) {
2711 r = isp_getpdb(isp, chan, loopid, &pdb, 1);
2712 if (r && (fcp->isp_topo == TOPO_F_PORT || fcp->isp_topo == TOPO_FL_PORT)) {
2713 isp_prt(isp, ISP_LOGWARN, "fabric topology but cannot get info about fabric controller (0x%x)", r);
2714 fcp->isp_topo = TOPO_PTP_STUB;
2721 fcp->isp_topo = TOPO_FL_PORT;
2723 if (pdb.portid == 0) {
2727 fcp->isp_topo = TOPO_NL_PORT;
2732 * Save the Fabric controller's port database entry.
2734 lp = &fcp->portdb[FL_ID];
2735 lp->state = FC_PORTDB_STATE_PENDING_VALID;
2736 MAKE_WWN_FROM_NODE_NAME(lp->node_wwn, pdb.nodename);
2737 MAKE_WWN_FROM_NODE_NAME(lp->port_wwn, pdb.portname);
2738 lp->roles = (pdb.s3_role & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
2739 lp->portid = pdb.portid;
2740 lp->handle = pdb.handle;
2741 lp->new_portid = lp->portid;
2742 lp->new_roles = lp->roles;
2744 fcp->inorder = (mbs.param[7] & ISP24XX_INORDER) != 0;
2745 if (ISP_FW_NEWER_THAN(isp, 4, 0, 27)) {
2746 fcp->npiv_fabric = (mbs.param[7] & ISP24XX_NPIV_SAN) != 0;
2747 if (fcp->npiv_fabric) {
2748 isp_prt(isp, ISP_LOGCONFIG, "fabric supports NP-IV");
2752 fcp->isp_sns_hdl = NPH_SNS_HDLBASE + chan;
2753 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);
2755 isp_prt(isp, ISP_LOGWARN, "%s: Chan %d cannot log into SNS", __func__, chan);
2759 fcp->isp_sns_hdl = NPH_SNS_ID;
2761 r = isp_register_fc4_type_24xx(isp, chan);
2763 fcp->isp_sns_hdl = SNS_ID;
2764 r = isp_register_fc4_type(isp, chan);
2767 isp_prt(isp, ISP_LOGWARN|ISP_LOGSANCFG, "%s: register fc4 type failed", __func__);
2772 fcp->portdb[FL_ID].state = FC_PORTDB_STATE_NIL;
2775 fcp->isp_gbspeed = 1;
2776 if (IS_23XX(isp) || IS_24XX(isp)) {
2777 MBSINIT(&mbs, MBOX_GET_SET_DATA_RATE, MBLOGALL, 3000000);
2778 mbs.param[1] = MBGSD_GET_RATE;
2779 /* mbs.param[2] undefined if we're just getting rate */
2780 isp_mboxcmd(isp, &mbs);
2781 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
2782 if (mbs.param[1] == MBGSD_EIGHTGB) {
2783 isp_prt(isp, ISP_LOGINFO, "Chan %d 8Gb link speed", chan);
2784 fcp->isp_gbspeed = 8;
2785 } else if (mbs.param[1] == MBGSD_FOURGB) {
2786 isp_prt(isp, ISP_LOGINFO, "Chan %d 4Gb link speed", chan);
2787 fcp->isp_gbspeed = 4;
2788 } else if (mbs.param[1] == MBGSD_TWOGB) {
2789 isp_prt(isp, ISP_LOGINFO, "Chan %d 2Gb link speed", chan);
2790 fcp->isp_gbspeed = 2;
2791 } else if (mbs.param[1] == MBGSD_ONEGB) {
2792 isp_prt(isp, ISP_LOGINFO, "Chan %d 1Gb link speed", chan);
2793 fcp->isp_gbspeed = 1;
2799 * Announce ourselves, too.
2801 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));
2802 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "Chan %d FC Link Test Complete", chan);
2807 * Complete the synchronization of our Port Database.
2809 * At this point, we've scanned the local loop (if any) and the fabric
2810 * and performed fabric logins on all new devices.
2812 * Our task here is to go through our port database and remove any entities
2813 * that are still marked probational (issuing PLOGO for ones which we had
2814 * PLOGI'd into) or are dead.
2816 * Our task here is to also check policy to decide whether devices which
2817 * have *changed* in some way should still be kept active. For example,
2818 * if a device has just changed PortID, we can either elect to treat it
2819 * as an old device or as a newly arrived device (and notify the outer
2820 * layer appropriately).
2822 * We also do initiator map target id assignment here for new initiator
2823 * devices and refresh old ones ot make sure that they point to the corret
2827 isp_pdb_sync(ispsoftc_t *isp, int chan)
2829 fcparam *fcp = FCPARAM(isp, chan);
2833 if (fcp->isp_loopstate == LOOP_READY) {
2838 * Make sure we're okay for doing this right now.
2840 if (fcp->isp_loopstate != LOOP_PDB_RCVD &&
2841 fcp->isp_loopstate != LOOP_FSCAN_DONE &&
2842 fcp->isp_loopstate != LOOP_LSCAN_DONE) {
2843 isp_prt(isp, ISP_LOGWARN, "isp_pdb_sync: bad loopstate %d",
2844 fcp->isp_loopstate);
2848 if (fcp->isp_topo == TOPO_FL_PORT ||
2849 fcp->isp_topo == TOPO_NL_PORT ||
2850 fcp->isp_topo == TOPO_N_PORT) {
2851 if (fcp->isp_loopstate < LOOP_LSCAN_DONE) {
2852 if (isp_scan_loop(isp, chan) != 0) {
2853 isp_prt(isp, ISP_LOGWARN,
2854 "isp_pdb_sync: isp_scan_loop failed");
2860 if (fcp->isp_topo == TOPO_F_PORT || fcp->isp_topo == TOPO_FL_PORT) {
2861 if (fcp->isp_loopstate < LOOP_FSCAN_DONE) {
2862 if (isp_scan_fabric(isp, chan) != 0) {
2863 isp_prt(isp, ISP_LOGWARN,
2864 "isp_pdb_sync: isp_scan_fabric failed");
2870 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
2871 "Chan %d Synchronizing PDBs", chan);
2873 fcp->isp_loopstate = LOOP_SYNCING_PDB;
2875 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
2876 lp = &fcp->portdb[dbidx];
2878 if (lp->state == FC_PORTDB_STATE_NIL || lp->target_mode) {
2882 if (lp->state == FC_PORTDB_STATE_VALID) {
2883 if (dbidx != FL_ID) {
2885 ISP_LOGERR, "portdb idx %d already valid",
2891 switch (lp->state) {
2892 case FC_PORTDB_STATE_PROBATIONAL:
2893 case FC_PORTDB_STATE_DEAD:
2895 * It's up to the outer layers to clear isp_dev_map.
2897 lp->state = FC_PORTDB_STATE_NIL;
2898 isp_async(isp, ISPASYNC_DEV_GONE, chan, lp);
2899 if (lp->autologin == 0) {
2900 (void) isp_plogx(isp, chan, lp->handle,
2902 PLOGX_FLG_CMD_LOGO |
2903 PLOGX_FLG_IMPLICIT |
2904 PLOGX_FLG_FREE_NPHDL, 0);
2911 * Note that we might come out of this with our state
2912 * set to FC_PORTDB_STATE_ZOMBIE.
2915 case FC_PORTDB_STATE_NEW:
2917 * It's up to the outer layers to assign a virtual
2918 * target id in isp_dev_map (if any).
2920 lp->portid = lp->new_portid;
2921 lp->roles = lp->new_roles;
2922 lp->state = FC_PORTDB_STATE_VALID;
2923 isp_async(isp, ISPASYNC_DEV_ARRIVED, chan, lp);
2927 lp->new_reserved = 0;
2929 case FC_PORTDB_STATE_CHANGED:
2933 lp->state = FC_PORTDB_STATE_VALID;
2934 isp_async(isp, ISPASYNC_DEV_CHANGED, chan, lp);
2938 lp->new_reserved = 0;
2940 case FC_PORTDB_STATE_PENDING_VALID:
2941 lp->portid = lp->new_portid;
2942 lp->roles = lp->new_roles;
2943 if (lp->dev_map_idx) {
2944 int t = lp->dev_map_idx - 1;
2945 fcp->isp_dev_map[t] = dbidx + 1;
2947 lp->state = FC_PORTDB_STATE_VALID;
2948 isp_async(isp, ISPASYNC_DEV_STAYED, chan, lp);
2949 if (dbidx != FL_ID) {
2954 lp->new_reserved = 0;
2956 case FC_PORTDB_STATE_ZOMBIE:
2959 isp_prt(isp, ISP_LOGWARN,
2960 "isp_scan_loop: state %d for idx %d",
2962 isp_dump_portdb(isp, chan);
2967 * If we get here, we've for sure seen not only a valid loop
2968 * but know what is or isn't on it, so mark this for usage
2971 fcp->loop_seen_once = 1;
2972 fcp->isp_loopstate = LOOP_READY;
2977 * Scan local loop for devices.
2980 isp_scan_loop(ispsoftc_t *isp, int chan)
2982 fcportdb_t *lp, tmp;
2983 fcparam *fcp = FCPARAM(isp, chan);
2986 uint16_t handle, lim = 0;
2988 if (fcp->isp_fwstate < FW_READY ||
2989 fcp->isp_loopstate < LOOP_PDB_RCVD) {
2993 if (fcp->isp_loopstate > LOOP_SCANNING_LOOP) {
2998 * Check our connection topology.
3000 * If we're a public or private loop, we scan 0..125 as handle values.
3001 * The firmware has (typically) peformed a PLOGI for us. We skip this
3002 * step if we're a ISP_24XX in NP-IV mode.
3004 * If we're a N-port connection, we treat this is a short loop (0..1).
3006 switch (fcp->isp_topo) {
3008 lim = LOCAL_LOOP_LIM;
3011 if (IS_24XX(isp) && isp->isp_nchan > 1) {
3012 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3013 "Chan %d Skipping Local Loop Scan", chan);
3014 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3017 lim = LOCAL_LOOP_LIM;
3023 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3024 "Chan %d no loop topology to scan", chan);
3025 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3029 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
3031 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3032 "Chan %d FC scan loop 0..%d", chan, lim-1);
3036 * Run through the list and get the port database info for each one.
3038 for (handle = 0; handle < lim; handle++) {
3041 * Don't scan "special" ids.
3043 if (handle >= FL_ID && handle <= SNS_ID) {
3046 if (ISP_CAP_2KLOGIN(isp)) {
3047 if (handle >= NPH_RESERVED && handle <= NPH_FL_ID) {
3052 * In older cards with older f/w GET_PORT_DATABASE has been
3053 * known to hang. This trick gets around that problem.
3055 if (IS_2100(isp) || IS_2200(isp)) {
3056 uint64_t node_wwn = isp_get_wwn(isp, chan, handle, 1);
3057 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
3058 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3059 "Chan %d FC scan loop DONE (bad)", chan);
3062 if (node_wwn == INI_NONE) {
3068 * Get the port database entity for this index.
3070 r = isp_getpdb(isp, chan, handle, &pdb, 1);
3072 isp_prt(isp, ISP_LOGDEBUG1,
3073 "Chan %d FC scan loop handle %d returned %x",
3075 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
3076 ISP_MARK_PORTDB(isp, chan, 1);
3077 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3078 "Chan %d FC scan loop DONE (bad)", chan);
3084 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
3085 ISP_MARK_PORTDB(isp, chan, 1);
3086 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3087 "Chan %d FC scan loop DONE (bad)", chan);
3092 * On *very* old 2100 firmware we would end up sometimes
3093 * with the firmware returning the port database entry
3094 * for something else. We used to restart this, but
3097 if (IS_2100(isp) && pdb.handle != handle) {
3098 isp_prt(isp, ISP_LOGWARN,
3099 "Chan %d cannot synchronize port database", chan);
3100 ISP_MARK_PORTDB(isp, chan, 1);
3101 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3102 "Chan %d FC scan loop DONE (bad)", chan);
3107 * Save the pertinent info locally.
3109 MAKE_WWN_FROM_NODE_NAME(tmp.node_wwn, pdb.nodename);
3110 MAKE_WWN_FROM_NODE_NAME(tmp.port_wwn, pdb.portname);
3111 tmp.roles = (pdb.s3_role & SVC3_ROLE_MASK) >> SVC3_ROLE_SHIFT;
3112 tmp.portid = pdb.portid;
3113 tmp.handle = pdb.handle;
3116 * Check to make sure it's still a valid entry. The 24XX seems
3117 * to return a portid but not a WWPN/WWNN or role for devices
3118 * which shift on a loop.
3120 if (tmp.node_wwn == 0 || tmp.port_wwn == 0 || tmp.portid == 0) {
3122 a = (tmp.node_wwn == 0);
3123 b = (tmp.port_wwn == 0);
3124 c = (tmp.portid == 0);
3125 if (a == 0 && b == 0) {
3127 isp_get_wwn(isp, chan, handle, 1);
3129 isp_get_wwn(isp, chan, handle, 0);
3130 if (tmp.node_wwn && tmp.port_wwn) {
3131 isp_prt(isp, ISP_LOGINFO, "DODGED!");
3135 isp_prt(isp, ISP_LOGWARN,
3136 "Chan %d bad pdb (%1d%1d%1d) @ handle 0x%x", chan,
3138 isp_dump_portdb(isp, chan);
3144 * Now search the entire port database
3145 * for the same Port and Node WWN.
3147 for (i = 0; i < MAX_FC_TARG; i++) {
3148 lp = &fcp->portdb[i];
3150 if (lp->state == FC_PORTDB_STATE_NIL ||
3154 if (lp->node_wwn != tmp.node_wwn) {
3157 if (lp->port_wwn != tmp.port_wwn) {
3162 * Okay- we've found a non-nil entry that matches.
3163 * Check to make sure it's probational or a zombie.
3165 if (lp->state != FC_PORTDB_STATE_PROBATIONAL &&
3166 lp->state != FC_PORTDB_STATE_ZOMBIE) {
3167 isp_prt(isp, ISP_LOGERR,
3168 "Chan %d [%d] not probational/zombie (0x%x)",
3169 chan, i, lp->state);
3170 isp_dump_portdb(isp, chan);
3171 ISP_MARK_PORTDB(isp, chan, 1);
3172 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3173 "Chan %d FC scan loop DONE (bad)", chan);
3178 * Mark the device as something the f/w logs into
3184 * Check to make see if really still the same
3185 * device. If it is, we mark it pending valid.
3187 if (lp->portid == tmp.portid &&
3188 lp->handle == tmp.handle &&
3189 lp->roles == tmp.roles) {
3190 lp->new_portid = tmp.portid;
3191 lp->new_roles = tmp.roles;
3192 lp->state = FC_PORTDB_STATE_PENDING_VALID;
3193 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3194 "Chan %d Loop Port 0x%02x@0x%x Pending "
3195 "Valid", chan, tmp.portid, tmp.handle);
3200 * We can wipe out the old handle value
3201 * here because it's no longer valid.
3203 lp->handle = tmp.handle;
3206 * Claim that this has changed and let somebody else
3207 * decide what to do.
3209 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3210 "Chan %d Loop Port 0x%02x@0x%x changed",
3211 chan, tmp.portid, tmp.handle);
3212 lp->state = FC_PORTDB_STATE_CHANGED;
3213 lp->new_portid = tmp.portid;
3214 lp->new_roles = tmp.roles;
3219 * Did we find and update an old entry?
3221 if (i < MAX_FC_TARG) {
3226 * Ah. A new device entry. Find an empty slot
3227 * for it and save info for later disposition.
3229 for (i = 0; i < MAX_FC_TARG; i++) {
3230 if (fcp->portdb[i].target_mode) {
3233 if (fcp->portdb[i].state == FC_PORTDB_STATE_NIL) {
3237 if (i == MAX_FC_TARG) {
3238 isp_prt(isp, ISP_LOGERR,
3239 "Chan %d out of portdb entries", chan);
3242 lp = &fcp->portdb[i];
3244 ISP_MEMZERO(lp, sizeof (fcportdb_t));
3246 lp->state = FC_PORTDB_STATE_NEW;
3247 lp->new_portid = tmp.portid;
3248 lp->new_roles = tmp.roles;
3249 lp->handle = tmp.handle;
3250 lp->port_wwn = tmp.port_wwn;
3251 lp->node_wwn = tmp.node_wwn;
3252 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3253 "Chan %d Loop Port 0x%02x@0x%x is New Entry",
3254 chan, tmp.portid, tmp.handle);
3256 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3257 isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
3258 "Chan %d FC scan loop DONE", chan);
3263 * Scan the fabric for devices and add them to our port database.
3265 * Use the GID_FT command to get all Port IDs for FC4 SCSI devices it knows.
3267 * For 2100-23XX cards, we can use the SNS mailbox command to pass simple
3268 * name server commands to the switch management server via the QLogic f/w.
3270 * For the 24XX card, we have to use CT-Pass through run via the Execute IOCB
3273 * The net result is to leave the list of Port IDs setting untranslated in
3274 * offset IGPOFF of the FC scratch area, whereupon we'll canonicalize it to
3275 * host order at OGPOFF.
3279 * Take less than half of our scratch area to store Port IDs
3281 #define GIDLEN ((ISP_FC_SCRLEN >> 1) - 16 - SNS_GID_FT_REQ_SIZE)
3282 #define NGENT ((GIDLEN - 16) >> 2)
3284 #define IGPOFF (2 * QENTRY_LEN)
3285 #define OGPOFF (ISP_FC_SCRLEN >> 1)
3286 #define ZTXOFF (ISP_FC_SCRLEN - (1 * QENTRY_LEN))
3287 #define CTXOFF (ISP_FC_SCRLEN - (2 * QENTRY_LEN))
3288 #define XTXOFF (ISP_FC_SCRLEN - (3 * QENTRY_LEN))
3291 isp_gid_ft_sns(ispsoftc_t *isp, int chan)
3294 sns_gid_ft_req_t _x;
3295 uint8_t _y[SNS_GID_FT_REQ_SIZE];
3297 fcparam *fcp = FCPARAM(isp, chan);
3298 sns_gid_ft_req_t *rq = &un._x;
3301 isp_prt(isp, ISP_LOGDEBUG0,
3302 "Chan %d scanning fabric (GID_FT) via SNS", chan);
3304 ISP_MEMZERO(rq, SNS_GID_FT_REQ_SIZE);
3305 rq->snscb_rblen = GIDLEN >> 1;
3306 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + IGPOFF);
3307 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + IGPOFF);
3308 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + IGPOFF);
3309 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + IGPOFF);
3310 rq->snscb_sblen = 6;
3311 rq->snscb_cmd = SNS_GID_FT;
3312 rq->snscb_mword_div_2 = NGENT;
3313 rq->snscb_fc4_type = FC4_SCSI;
3315 isp_put_gid_ft_request(isp, rq, fcp->isp_scratch);
3316 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE);
3318 MBSINIT(&mbs, MBOX_SEND_SNS, MBLOGALL, 10000000);
3319 mbs.param[0] = MBOX_SEND_SNS;
3320 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
3321 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
3322 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
3323 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
3324 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
3325 isp_mboxcmd(isp, &mbs);
3326 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3327 if (mbs.param[0] == MBOX_INVALID_COMMAND) {
3337 isp_gid_ft_ct_passthru(ispsoftc_t *isp, int chan)
3340 fcparam *fcp = FCPARAM(isp, chan);
3344 uint8_t q[QENTRY_LEN];
3349 uint8_t *scp = fcp->isp_scratch;
3351 isp_prt(isp, ISP_LOGDEBUG0,
3352 "Chan %d scanning fabric (GID_FT) via CT", chan);
3354 if (!IS_24XX(isp)) {
3359 * Build a Passthrough IOCB in memory.
3362 ISP_MEMZERO(un.q, QENTRY_LEN);
3363 pt->ctp_header.rqs_entry_count = 1;
3364 pt->ctp_header.rqs_entry_type = RQSTYPE_CT_PASSTHRU;
3365 pt->ctp_handle = 0xffffffff;
3366 pt->ctp_nphdl = fcp->isp_sns_hdl;
3367 pt->ctp_cmd_cnt = 1;
3368 pt->ctp_vpidx = chan;
3370 pt->ctp_rsp_cnt = 1;
3371 pt->ctp_rsp_bcnt = GIDLEN;
3372 pt->ctp_cmd_bcnt = sizeof (*ct) + sizeof (uint32_t);
3373 pt->ctp_dataseg[0].ds_base = DMA_LO32(fcp->isp_scdma+XTXOFF);
3374 pt->ctp_dataseg[0].ds_basehi = DMA_HI32(fcp->isp_scdma+XTXOFF);
3375 pt->ctp_dataseg[0].ds_count = sizeof (*ct) + sizeof (uint32_t);
3376 pt->ctp_dataseg[1].ds_base = DMA_LO32(fcp->isp_scdma+IGPOFF);
3377 pt->ctp_dataseg[1].ds_basehi = DMA_HI32(fcp->isp_scdma+IGPOFF);
3378 pt->ctp_dataseg[1].ds_count = GIDLEN;
3379 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3380 isp_print_bytes(isp, "ct IOCB", QENTRY_LEN, pt);
3382 isp_put_ct_pt(isp, pt, (isp_ct_pt_t *) &scp[CTXOFF]);
3385 * Build the CT header and command in memory.
3387 * Note that the CT header has to end up as Big Endian format in memory.
3390 ISP_MEMZERO(ct, sizeof (*ct));
3391 ct->ct_revision = CT_REVISION;
3392 ct->ct_fcs_type = CT_FC_TYPE_FC;
3393 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3394 ct->ct_cmd_resp = SNS_GID_FT;
3395 ct->ct_bcnt_resid = (GIDLEN - 16) >> 2;
3397 isp_put_ct_hdr(isp, ct, (ct_hdr_t *) &scp[XTXOFF]);
3398 rp = (uint32_t *) &scp[XTXOFF+sizeof (*ct)];
3399 ISP_IOZPUT_32(isp, FC4_SCSI, rp);
3400 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3401 isp_print_bytes(isp, "CT HDR + payload after put",
3402 sizeof (*ct) + sizeof (uint32_t), &scp[XTXOFF]);
3404 ISP_MEMZERO(&scp[ZTXOFF], QENTRY_LEN);
3405 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 500000);
3406 mbs.param[1] = QENTRY_LEN;
3407 mbs.param[2] = DMA_WD1(fcp->isp_scdma + CTXOFF);
3408 mbs.param[3] = DMA_WD0(fcp->isp_scdma + CTXOFF);
3409 mbs.param[6] = DMA_WD3(fcp->isp_scdma + CTXOFF);
3410 mbs.param[7] = DMA_WD2(fcp->isp_scdma + CTXOFF);
3411 MEMORYBARRIER(isp, SYNC_SFORDEV, XTXOFF, 2 * QENTRY_LEN);
3412 isp_mboxcmd(isp, &mbs);
3413 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3416 MEMORYBARRIER(isp, SYNC_SFORCPU, ZTXOFF, QENTRY_LEN);
3418 isp_get_ct_pt(isp, (isp_ct_pt_t *) &scp[ZTXOFF], pt);
3419 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3420 isp_print_bytes(isp, "IOCB response", QENTRY_LEN, pt);
3423 if (pt->ctp_status && pt->ctp_status != RQCS_DATA_UNDERRUN) {
3424 isp_prt(isp, ISP_LOGWARN,
3425 "Chan %d ISP GID FT CT Passthrough returned 0x%x",
3426 chan, pt->ctp_status);