2 * Copyright (c) 1997-2009 by Matthew Jacob
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * Machine and OS Independent (well, as best as possible)
31 * code for the Qlogic ISP SCSI and FC-SCSI adapters.
35 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
36 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
37 * ideas dredged from the Solaris driver.
41 * Include header file appropriate for platform we're building on.
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD$");
46 #include <dev/ic/isp_netbsd.h>
49 #include <sys/cdefs.h>
50 __FBSDID("$FreeBSD$");
51 #include <dev/isp/isp_freebsd.h>
54 #include <dev/ic/isp_openbsd.h>
57 #include "isp_linux.h"
60 #include "isp_solaris.h"
66 #define MBOX_DELAY_COUNT 1000000 / 100
71 static const char notresp[] = "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
72 static const char bun[] = "bad underrun (count %d, resid %d, status %s)";
73 static const char lipd[] = "Chan %d LIP destroyed %d active commands";
74 static const char sacq[] = "unable to acquire scratch area";
76 static const uint8_t alpa_map[] = {
77 0xef, 0xe8, 0xe4, 0xe2, 0xe1, 0xe0, 0xdc, 0xda,
78 0xd9, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xce,
79 0xcd, 0xcc, 0xcb, 0xca, 0xc9, 0xc7, 0xc6, 0xc5,
80 0xc3, 0xbc, 0xba, 0xb9, 0xb6, 0xb5, 0xb4, 0xb3,
81 0xb2, 0xb1, 0xae, 0xad, 0xac, 0xab, 0xaa, 0xa9,
82 0xa7, 0xa6, 0xa5, 0xa3, 0x9f, 0x9e, 0x9d, 0x9b,
83 0x98, 0x97, 0x90, 0x8f, 0x88, 0x84, 0x82, 0x81,
84 0x80, 0x7c, 0x7a, 0x79, 0x76, 0x75, 0x74, 0x73,
85 0x72, 0x71, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x69,
86 0x67, 0x66, 0x65, 0x63, 0x5c, 0x5a, 0x59, 0x56,
87 0x55, 0x54, 0x53, 0x52, 0x51, 0x4e, 0x4d, 0x4c,
88 0x4b, 0x4a, 0x49, 0x47, 0x46, 0x45, 0x43, 0x3c,
89 0x3a, 0x39, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31,
90 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x27, 0x26,
91 0x25, 0x23, 0x1f, 0x1e, 0x1d, 0x1b, 0x18, 0x17,
92 0x10, 0x0f, 0x08, 0x04, 0x02, 0x01, 0x00
96 * Local function prototypes.
98 static void isp_parse_async(ispsoftc_t *, uint16_t);
99 static void isp_parse_async_fc(ispsoftc_t *, uint16_t);
100 static int isp_handle_other_response(ispsoftc_t *, int, isphdr_t *, uint32_t *);
101 static void isp_parse_status(ispsoftc_t *, ispstatusreq_t *, XS_T *, long *);
102 static void isp_parse_status_24xx(ispsoftc_t *, isp24xx_statusreq_t *, XS_T *, long *);
103 static void isp_fastpost_complete(ispsoftc_t *, uint32_t);
104 static void isp_scsi_init(ispsoftc_t *);
105 static void isp_scsi_channel_init(ispsoftc_t *, int);
106 static void isp_fibre_init(ispsoftc_t *);
107 static void isp_fibre_init_2400(ispsoftc_t *);
108 static void isp_clear_portdb(ispsoftc_t *, int);
109 static void isp_mark_portdb(ispsoftc_t *, int);
110 static int isp_plogx(ispsoftc_t *, int, uint16_t, uint32_t, int);
111 static int isp_port_login(ispsoftc_t *, uint16_t, uint32_t);
112 static int isp_port_logout(ispsoftc_t *, uint16_t, uint32_t);
113 static int isp_getpdb(ispsoftc_t *, int, uint16_t, isp_pdb_t *);
114 static int isp_gethandles(ispsoftc_t *, int, uint16_t *, int *, int);
115 static void isp_dump_chip_portdb(ispsoftc_t *, int);
116 static uint64_t isp_get_wwn(ispsoftc_t *, int, int, int);
117 static int isp_fclink_test(ispsoftc_t *, int, int);
118 static int isp_pdb_sync(ispsoftc_t *, int);
119 static int isp_scan_loop(ispsoftc_t *, int);
120 static int isp_gid_ft_sns(ispsoftc_t *, int);
121 static int isp_gid_ft_ct_passthru(ispsoftc_t *, int);
122 static int isp_scan_fabric(ispsoftc_t *, int);
123 static int isp_login_device(ispsoftc_t *, int, uint32_t, isp_pdb_t *, uint16_t *);
124 static int isp_send_change_request(ispsoftc_t *, int);
125 static int isp_register_fc4_type(ispsoftc_t *, int);
126 static int isp_register_fc4_type_24xx(ispsoftc_t *, int);
127 static int isp_register_fc4_features_24xx(ispsoftc_t *, int);
128 static int isp_register_port_name_24xx(ispsoftc_t *, int);
129 static int isp_register_node_name_24xx(ispsoftc_t *, int);
130 static uint16_t isp_next_handle(ispsoftc_t *, uint16_t *);
131 static int isp_fw_state(ispsoftc_t *, int);
132 static void isp_mboxcmd(ispsoftc_t *, mbreg_t *);
134 static void isp_spi_update(ispsoftc_t *, int);
135 static void isp_setdfltsdparm(ispsoftc_t *);
136 static void isp_setdfltfcparm(ispsoftc_t *, int);
137 static int isp_read_nvram(ispsoftc_t *, int);
138 static int isp_read_nvram_2400(ispsoftc_t *, uint8_t *);
139 static void isp_rdnvram_word(ispsoftc_t *, int, uint16_t *);
140 static void isp_rd_2400_nvram(ispsoftc_t *, uint32_t, uint32_t *);
141 static void isp_parse_nvram_1020(ispsoftc_t *, uint8_t *);
142 static void isp_parse_nvram_1080(ispsoftc_t *, int, uint8_t *);
143 static void isp_parse_nvram_12160(ispsoftc_t *, int, uint8_t *);
144 static void isp_parse_nvram_2100(ispsoftc_t *, uint8_t *);
145 static void isp_parse_nvram_2400(ispsoftc_t *, uint8_t *);
148 isp_change_fw_state(ispsoftc_t *isp, int chan, int state)
150 fcparam *fcp = FCPARAM(isp, chan);
152 if (fcp->isp_fwstate == state)
154 isp_prt(isp, ISP_LOGCONFIG|ISP_LOG_SANCFG,
155 "Chan %d Firmware state <%s->%s>", chan,
156 isp_fc_fw_statename(fcp->isp_fwstate), isp_fc_fw_statename(state));
157 fcp->isp_fwstate = state;
163 * Hit the chip over the head, download new f/w if available and set it running.
165 * Locking done elsewhere.
169 isp_reset(ispsoftc_t *isp, int do_load_defaults)
174 uint32_t code_org, val;
175 int loops, i, dodnld = 1;
176 const char *btype = "????";
177 static const char dcrc[] = "Downloaded RISC Code Checksum Failure";
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->isp_state = ISP_NILSTATE;
190 ISP_DISABLE_INTS(isp);
193 * Put the board into PAUSE mode (so we can read the SXP registers
194 * or write FPM/FBM registers).
197 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_HOST_INT);
198 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
199 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_PAUSE);
201 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
205 switch (isp->isp_type) {
236 * While we're paused, reset the FPM module and FBM
239 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
240 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
241 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
242 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
243 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
245 } else if (IS_1240(isp)) {
250 sdp = SDPARAM(isp, 0);
251 sdp->isp_ultramode = 1;
252 sdp = SDPARAM(isp, 1);
253 sdp->isp_ultramode = 1;
255 * XXX: Should probably do some bus sensing.
257 } else if (IS_ULTRA3(isp)) {
258 sdparam *sdp = isp->isp_param;
260 isp->isp_clock = 100;
264 else if (IS_12160(isp))
268 sdp->isp_lvdmode = 1;
270 if (IS_DUALBUS(isp)) {
272 sdp->isp_lvdmode = 1;
274 } else if (IS_ULTRA2(isp)) {
275 static const char m[] = "bus %d is in %s Mode";
277 sdparam *sdp = SDPARAM(isp, 0);
279 isp->isp_clock = 100;
283 else if (IS_1080(isp))
288 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
290 case ISP1080_LVD_MODE:
291 sdp->isp_lvdmode = 1;
292 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
294 case ISP1080_HVD_MODE:
295 sdp->isp_diffmode = 1;
296 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
298 case ISP1080_SE_MODE:
299 sdp->isp_ultramode = 1;
300 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
303 isp_prt(isp, ISP_LOGERR,
304 "unknown mode on bus %d (0x%x)", 0, l);
308 if (IS_DUALBUS(isp)) {
309 sdp = SDPARAM(isp, 1);
310 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
311 l &= ISP1080_MODE_MASK;
313 case ISP1080_LVD_MODE:
314 sdp->isp_lvdmode = 1;
315 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
317 case ISP1080_HVD_MODE:
318 sdp->isp_diffmode = 1;
319 isp_prt(isp, ISP_LOGCONFIG,
320 m, 1, "Differential");
322 case ISP1080_SE_MODE:
323 sdp->isp_ultramode = 1;
324 isp_prt(isp, ISP_LOGCONFIG,
325 m, 1, "Single-Ended");
328 isp_prt(isp, ISP_LOGERR,
329 "unknown mode on bus %d (0x%x)", 1, l);
334 sdparam *sdp = SDPARAM(isp, 0);
335 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
338 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
342 isp->isp_type = ISP_HA_SCSI_1020;
347 * Some 1020A chips are Ultra Capable, but don't
348 * run the clock rate up for that unless told to
349 * do so by the Ultra Capable bits being set.
352 isp->isp_type = ISP_HA_SCSI_1020A;
357 isp->isp_type = ISP_HA_SCSI_1040;
362 isp->isp_type = ISP_HA_SCSI_1040A;
367 isp->isp_type = ISP_HA_SCSI_1040B;
372 isp->isp_type = ISP_HA_SCSI_1040C;
377 * Now, while we're at it, gather info about ultra
378 * and/or differential mode.
380 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
381 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
382 sdp->isp_diffmode = 1;
384 sdp->isp_diffmode = 0;
386 i = ISP_READ(isp, RISC_PSR);
387 if (isp->isp_bustype == ISP_BT_SBUS) {
388 i &= RISC_PSR_SBUS_ULTRA;
390 i &= RISC_PSR_PCI_ULTRA;
393 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
394 sdp->isp_ultramode = 1;
396 * If we're in Ultra Mode, we have to be 60MHz clock-
397 * even for the SBus version.
401 sdp->isp_ultramode = 0;
403 * Clock is known. Gronk.
408 * Machine dependent clock (if set) overrides
409 * our generic determinations.
411 if (isp->isp_mdvec->dv_clock) {
412 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
413 isp->isp_clock = isp->isp_mdvec->dv_clock;
419 * Hit the chip over the head with hammer,
420 * and give it a chance to recover.
424 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
431 * Clear data && control DMA engines.
433 ISP_WRITE(isp, CDMA_CONTROL, DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
434 ISP_WRITE(isp, DDMA_CONTROL, DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
437 } else if (IS_24XX(isp)) {
439 * Stop DMA and wait for it to stop.
441 ISP_WRITE(isp, BIU2400_CSR, BIU2400_DMA_STOP|(3 << 4));
442 for (val = loops = 0; loops < 30000; loops++) {
444 val = ISP_READ(isp, BIU2400_CSR);
445 if ((val & BIU2400_DMA_ACTIVE) == 0) {
449 if (val & BIU2400_DMA_ACTIVE) {
450 isp_prt(isp, ISP_LOGERR, "DMA Failed to Stop on Reset");
454 * Hold it in SOFT_RESET and STOP state for 100us.
456 ISP_WRITE(isp, BIU2400_CSR, BIU2400_SOFT_RESET|BIU2400_DMA_STOP|(3 << 4));
458 for (loops = 0; loops < 10000; loops++) {
460 val = ISP_READ(isp, OUTMAILBOX0);
462 for (val = loops = 0; loops < 500000; loops ++) {
463 val = ISP_READ(isp, BIU2400_CSR);
464 if ((val & BIU2400_SOFT_RESET) == 0) {
468 if (val & BIU2400_SOFT_RESET) {
469 isp_prt(isp, ISP_LOGERR, "Failed to come out of reset");
473 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
480 * Clear data && control DMA engines.
482 ISP_WRITE(isp, CDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
483 ISP_WRITE(isp, TDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
484 ISP_WRITE(isp, RDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
488 * Wait for ISP to be ready to go...
490 loops = MBOX_DELAY_COUNT;
493 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET)) {
496 } else if (IS_24XX(isp)) {
497 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
501 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
506 ISP_DUMPREGS(isp, "chip reset timed out");
512 * After we've fired this chip up, zero out the conf1 register
513 * for SCSI adapters and other settings for the 2100.
517 ISP_WRITE(isp, BIU_CONF1, 0);
518 } else if (!IS_24XX(isp)) {
519 ISP_WRITE(isp, BIU2100_CSR, 0);
523 * Reset RISC Processor
526 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RESET);
527 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RELEASE);
528 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RESET);
530 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
532 ISP_WRITE(isp, BIU_SEMA, 0);
536 * Post-RISC Reset stuff.
539 for (val = loops = 0; loops < 5000000; loops++) {
541 val = ISP_READ(isp, OUTMAILBOX0);
547 isp_prt(isp, ISP_LOGERR, "reset didn't clear");
550 } else if (IS_SCSI(isp)) {
551 uint16_t tmp = isp->isp_mdvec->dv_conf1;
553 * Busted FIFO. Turn off all but burst enables.
555 if (isp->isp_type == ISP_HA_SCSI_1040A) {
556 tmp &= BIU_BURST_ENABLE;
558 ISP_SETBITS(isp, BIU_CONF1, tmp);
559 if (tmp & BIU_BURST_ENABLE) {
560 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
561 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
563 if (SDPARAM(isp, 0)->isp_ptisp) {
564 if (SDPARAM(isp, 0)->isp_ultramode) {
565 while (ISP_READ(isp, RISC_MTR) != 0x1313) {
566 ISP_WRITE(isp, RISC_MTR, 0x1313);
567 ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
570 ISP_WRITE(isp, RISC_MTR, 0x1212);
573 * PTI specific register
575 ISP_WRITE(isp, RISC_EMB, DUAL_BANK);
577 ISP_WRITE(isp, RISC_MTR, 0x1212);
579 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
581 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
582 if (IS_2200(isp) || IS_23XX(isp)) {
583 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
585 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
589 * Set up default request/response queue in-pointer/out-pointer
593 isp->isp_rqstinrp = BIU2400_REQINP;
594 isp->isp_rqstoutrp = BIU2400_REQOUTP;
595 isp->isp_respinrp = BIU2400_RSPINP;
596 isp->isp_respoutrp = BIU2400_RSPOUTP;
597 } else if (IS_23XX(isp)) {
598 isp->isp_rqstinrp = BIU_REQINP;
599 isp->isp_rqstoutrp = BIU_REQOUTP;
600 isp->isp_respinrp = BIU_RSPINP;
601 isp->isp_respoutrp = BIU_RSPOUTP;
603 isp->isp_rqstinrp = INMAILBOX4;
604 isp->isp_rqstoutrp = OUTMAILBOX4;
605 isp->isp_respinrp = OUTMAILBOX5;
606 isp->isp_respoutrp = INMAILBOX5;
608 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
609 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
610 ISP_WRITE(isp, isp->isp_respinrp, 0);
611 ISP_WRITE(isp, isp->isp_respoutrp, 0);
614 ISP_WRITE(isp, BIU2400_PRI_REQINP, 0);
615 ISP_WRITE(isp, BIU2400_PRI_REQOUTP, 0);
617 ISP_WRITE(isp, BIU2400_ATIO_RSPINP, 0);
618 ISP_WRITE(isp, BIU2400_ATIO_RSPOUTP, 0);
621 if (!IS_24XX(isp) && isp->isp_bustype == ISP_BT_PCI) {
622 /* Make sure the BIOS is disabled */
623 ISP_WRITE(isp, HCCR, PCI_HCCR_CMD_BIOS);
627 * Wait for everything to finish firing up.
629 * Avoid doing this on early 2312s because you can generate a PCI
630 * parity error (chip breakage).
632 if (IS_2312(isp) && isp->isp_revision < 2) {
635 loops = MBOX_DELAY_COUNT;
636 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
639 isp_prt(isp, ISP_LOGERR, "MBOX_BUSY never cleared on reset");
646 * Up until this point we've done everything by just reading or
647 * setting registers. From this point on we rely on at least *some*
648 * kind of firmware running in the card.
652 * Do some sanity checking by running a NOP command.
653 * If it succeeds, the ROM firmware is now running.
655 MBSINIT(&mbs, MBOX_NO_OP, MBLOGALL, 0);
656 isp_mboxcmd(isp, &mbs);
657 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
658 isp_prt(isp, ISP_LOGERR, "NOP command failed (%x)", mbs.param[0]);
663 * Do some operational tests
665 if (IS_SCSI(isp) || IS_24XX(isp)) {
666 static const uint16_t patterns[MAX_MAILBOX] = {
667 0x0000, 0xdead, 0xbeef, 0xffff,
668 0xa5a5, 0x5a5a, 0x7f7f, 0x7ff7,
669 0x3421, 0xabcd, 0xdcba, 0xfeef,
670 0xbead, 0xdebe, 0x2222, 0x3333,
671 0x5555, 0x6666, 0x7777, 0xaaaa,
672 0xffff, 0xdddd, 0x9999, 0x1fbc,
673 0x6666, 0x6677, 0x1122, 0x33ff,
674 0x0000, 0x0001, 0x1000, 0x1010,
676 int nmbox = ISP_NMBOX(isp);
679 MBSINIT(&mbs, MBOX_MAILBOX_REG_TEST, MBLOGALL, 0);
680 for (i = 1; i < nmbox; i++) {
681 mbs.param[i] = patterns[i];
683 isp_mboxcmd(isp, &mbs);
684 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
687 for (i = 1; i < nmbox; i++) {
688 if (mbs.param[i] != patterns[i]) {
689 isp_prt(isp, ISP_LOGERR, "Register Test Failed at Register %d: should have 0x%04x but got 0x%04x", i, patterns[i], mbs.param[i]);
696 * Download new Firmware, unless requested not to do so.
697 * This is made slightly trickier in some cases where the
698 * firmware of the ROM revision is newer than the revision
699 * compiled into the driver. So, where we used to compare
700 * versions of our f/w and the ROM f/w, now we just see
701 * whether we have f/w at all and whether a config flag
702 * has disabled our download.
704 if ((isp->isp_mdvec->dv_ispfw == NULL) || (isp->isp_confopts & ISP_CFG_NORELOAD)) {
709 * Set up DMA for the request and response queues.
710 * We do this now so we can use the request queue
711 * for dma to load firmware from.
713 if (ISP_MBOXDMASETUP(isp) != 0) {
714 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
720 code_org = ISP_CODE_ORG_2400;
721 } else if (IS_23XX(isp)) {
722 code_org = ISP_CODE_ORG_2300;
724 code_org = ISP_CODE_ORG;
727 isp->isp_loaded_fw = 0;
728 if (dodnld && IS_24XX(isp)) {
729 const uint32_t *ptr = isp->isp_mdvec->dv_ispfw;
733 * Keep loading until we run out of f/w.
735 code_org = ptr[2]; /* 1st load address is our start addr */
739 isp_prt(isp, ISP_LOGDEBUG0, "load 0x%x words of code at load address 0x%x", ptr[3], ptr[2]);
744 while (wi < ptr[3]) {
748 nw = min(wl, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) / 4);
749 cp = isp->isp_rquest;
750 for (i = 0; i < nw; i++)
751 ISP_IOXPUT_32(isp, ptr[wi + i], &cp[i]);
752 MEMORYBARRIER(isp, SYNC_REQUEST, 0, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)), -1);
753 MBSINIT(&mbs, MBOX_LOAD_RISC_RAM, MBLOGALL, 0);
755 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
756 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
757 mbs.param[4] = nw >> 16;
759 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
760 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
761 mbs.param[8] = la >> 16;
762 isp_prt(isp, ISP_LOGDEBUG0, "LOAD RISC RAM %u words at load address 0x%x", nw, la);
763 isp_mboxcmd(isp, &mbs);
764 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
765 isp_prt(isp, ISP_LOGERR, "F/W download failed");
778 isp->isp_loaded_fw = 1;
779 } else if (dodnld && IS_23XX(isp)) {
780 const uint16_t *ptr = isp->isp_mdvec->dv_ispfw;
781 uint16_t wi, wl, segno;
790 isp_prt(isp, ISP_LOGDEBUG0, "load 0x%x words of code at load address 0x%x", ptr[3], la);
795 while (wi < ptr[3]) {
799 nw = min(wl, min((1 << 15), ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) / 2));
800 cp = isp->isp_rquest;
801 for (i = 0; i < nw; i++)
802 ISP_IOXPUT_16(isp, ptr[wi + i], &cp[i]);
803 MEMORYBARRIER(isp, SYNC_REQUEST, 0, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)), -1);
804 MBSINIT(&mbs, 0, MBLOGALL, 0);
806 mbs.param[0] = MBOX_LOAD_RISC_RAM_2100;
808 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
809 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
811 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
812 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
813 isp_prt(isp, ISP_LOGDEBUG1, "LOAD RISC RAM 2100 %u words at load address 0x%x\n", nw, la);
815 mbs.param[0] = MBOX_LOAD_RISC_RAM;
817 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
818 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
820 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
821 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
822 mbs.param[8] = la >> 16;
823 isp_prt(isp, ISP_LOGDEBUG1, "LOAD RISC RAM %u words at load address 0x%x\n", nw, la);
825 isp_mboxcmd(isp, &mbs);
826 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
827 isp_prt(isp, ISP_LOGERR, "F/W download failed");
844 * If we're a 2322, the firmware actually comes in
845 * three chunks. We loaded the first at the code_org
846 * address. The other two chunks, which follow right
847 * after each other in memory here, get loaded at
848 * addresses specfied at offset 0x9..0xB.
853 la = ptr[5] | ((ptr[4] & 0x3f) << 16);
855 isp->isp_loaded_fw = 1;
857 const uint16_t *ptr = isp->isp_mdvec->dv_ispfw;
861 isp_prt(isp, ISP_LOGDEBUG1,
862 "WRITE RAM %u words at load address 0x%x", wl, code_org);
863 for (i = 0; i < wl; i++) {
864 MBSINIT(&mbs, MBOX_WRITE_RAM_WORD, MBLOGNONE, 0);
865 mbs.param[1] = code_org + i;
866 mbs.param[2] = ptr[i];
867 isp_mboxcmd(isp, &mbs);
868 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
869 isp_prt(isp, ISP_LOGERR,
870 "F/W download failed at word %d", i);
874 } else if (IS_26XX(isp)) {
875 MBSINIT(&mbs, MBOX_LOAD_FLASH_FIRMWARE, MBLOGALL, 5000000);
878 isp_mboxcmd(isp, &mbs);
879 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
880 isp_prt(isp, ISP_LOGERR, "Flash F/W load failed");
884 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
888 * If we loaded firmware, verify its checksum
890 if (isp->isp_loaded_fw) {
891 MBSINIT(&mbs, MBOX_VERIFY_CHECKSUM, MBLOGNONE, 0);
893 mbs.param[1] = code_org >> 16;
894 mbs.param[2] = code_org;
896 mbs.param[1] = code_org;
898 isp_mboxcmd(isp, &mbs);
899 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
900 isp_prt(isp, ISP_LOGERR, dcrc);
906 * Now start it rolling.
908 * If we didn't actually download f/w,
909 * we still need to (re)start it.
911 MBSINIT(&mbs, MBOX_EXEC_FIRMWARE, MBLOGALL, 5000000);
913 mbs.param[1] = code_org >> 16;
914 mbs.param[2] = code_org;
915 if (isp->isp_loaded_fw) {
920 } else if (IS_2322(isp)) {
921 mbs.param[1] = code_org;
922 if (isp->isp_loaded_fw) {
928 mbs.param[1] = code_org;
930 isp_mboxcmd(isp, &mbs);
931 if (IS_2322(isp) || IS_24XX(isp)) {
932 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
939 * Set CLOCK RATE, but only if asked to.
941 if (isp->isp_clock) {
942 MBSINIT(&mbs, MBOX_SET_CLOCK_RATE, MBLOGALL, 0);
943 mbs.param[1] = isp->isp_clock;
944 isp_mboxcmd(isp, &mbs);
945 /* we will try not to care if this fails */
950 * Ask the chip for the current firmware version.
951 * This should prove that the new firmware is working.
953 MBSINIT(&mbs, MBOX_ABOUT_FIRMWARE, MBLOGALL, 0);
954 isp_mboxcmd(isp, &mbs);
955 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
960 * The SBus firmware that we are using apparently does not return
961 * major, minor, micro revisions in the mailbox registers, which
962 * is really, really, annoying.
964 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
966 #ifdef ISP_TARGET_MODE
967 isp->isp_fwrev[0] = 7;
968 isp->isp_fwrev[1] = 55;
970 isp->isp_fwrev[0] = 1;
971 isp->isp_fwrev[1] = 37;
973 isp->isp_fwrev[2] = 0;
976 isp->isp_fwrev[0] = mbs.param[1];
977 isp->isp_fwrev[1] = mbs.param[2];
978 isp->isp_fwrev[2] = mbs.param[3];
983 * We do not believe firmware attributes for 2100 code less
984 * than 1.17.0, unless it's the firmware we specifically
987 * Note that all 22XX and later f/w is greater than 1.X.0.
989 if ((ISP_FW_OLDER_THAN(isp, 1, 17, 1))) {
990 #ifdef USE_SMALLER_2100_FIRMWARE
991 isp->isp_fwattr = ISP_FW_ATTR_SCCLUN;
996 isp->isp_fwattr = mbs.param[6];
999 isp->isp_fwattr |= ((uint64_t) mbs.param[15]) << 16;
1000 if (isp->isp_fwattr & ISP2400_FW_ATTR_EXTNDED) {
1002 (((uint64_t) mbs.param[16]) << 32) |
1003 (((uint64_t) mbs.param[17]) << 48);
1007 isp->isp_fwattr = 0;
1010 isp_prt(isp, ISP_LOGCONFIG, "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
1011 btype, isp->isp_revision, dodnld? "loaded" : "resident", isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
1013 fwt = isp->isp_fwattr;
1015 buf = FCPARAM(isp, 0)->isp_scratch;
1016 ISP_SNPRINTF(buf, ISP_FC_SCRLEN, "Attributes:");
1017 if (fwt & ISP2400_FW_ATTR_CLASS2) {
1018 fwt ^=ISP2400_FW_ATTR_CLASS2;
1019 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s Class2", buf);
1021 if (fwt & ISP2400_FW_ATTR_IP) {
1022 fwt ^=ISP2400_FW_ATTR_IP;
1023 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s IP", buf);
1025 if (fwt & ISP2400_FW_ATTR_MULTIID) {
1026 fwt ^=ISP2400_FW_ATTR_MULTIID;
1027 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s MultiID", buf);
1029 if (fwt & ISP2400_FW_ATTR_SB2) {
1030 fwt ^=ISP2400_FW_ATTR_SB2;
1031 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s SB2", buf);
1033 if (fwt & ISP2400_FW_ATTR_T10CRC) {
1034 fwt ^=ISP2400_FW_ATTR_T10CRC;
1035 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s T10CRC", buf);
1037 if (fwt & ISP2400_FW_ATTR_VI) {
1038 fwt ^=ISP2400_FW_ATTR_VI;
1039 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VI", buf);
1041 if (fwt & ISP2400_FW_ATTR_MQ) {
1042 fwt ^=ISP2400_FW_ATTR_MQ;
1043 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s MQ", buf);
1045 if (fwt & ISP2400_FW_ATTR_MSIX) {
1046 fwt ^=ISP2400_FW_ATTR_MSIX;
1047 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s MSIX", buf);
1049 if (fwt & ISP2400_FW_ATTR_FCOE) {
1050 fwt ^=ISP2400_FW_ATTR_FCOE;
1051 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s FCOE", buf);
1053 if (fwt & ISP2400_FW_ATTR_VP0) {
1054 fwt ^= ISP2400_FW_ATTR_VP0;
1055 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VP0_Decoupling", buf);
1057 if (fwt & ISP2400_FW_ATTR_EXPFW) {
1058 fwt ^= ISP2400_FW_ATTR_EXPFW;
1059 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s (Experimental)", buf);
1061 if (fwt & ISP2400_FW_ATTR_HOTFW) {
1062 fwt ^= ISP2400_FW_ATTR_HOTFW;
1063 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s HotFW", buf);
1065 fwt &= ~ISP2400_FW_ATTR_EXTNDED;
1066 if (fwt & ISP2400_FW_ATTR_EXTVP) {
1067 fwt ^= ISP2400_FW_ATTR_EXTVP;
1068 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s ExtVP", buf);
1070 if (fwt & ISP2400_FW_ATTR_VN2VN) {
1071 fwt ^= ISP2400_FW_ATTR_VN2VN;
1072 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VN2VN", buf);
1074 if (fwt & ISP2400_FW_ATTR_EXMOFF) {
1075 fwt ^= ISP2400_FW_ATTR_EXMOFF;
1076 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s EXMOFF", buf);
1078 if (fwt & ISP2400_FW_ATTR_NPMOFF) {
1079 fwt ^= ISP2400_FW_ATTR_NPMOFF;
1080 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s NPMOFF", buf);
1082 if (fwt & ISP2400_FW_ATTR_DIFCHOP) {
1083 fwt ^= ISP2400_FW_ATTR_DIFCHOP;
1084 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s DIFCHOP", buf);
1086 if (fwt & ISP2400_FW_ATTR_SRIOV) {
1087 fwt ^= ISP2400_FW_ATTR_SRIOV;
1088 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s SRIOV", buf);
1090 if (fwt & ISP2400_FW_ATTR_ASICTMP) {
1091 fwt ^= ISP2400_FW_ATTR_ASICTMP;
1092 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s ASICTMP", buf);
1094 if (fwt & ISP2400_FW_ATTR_ATIOMQ) {
1095 fwt ^= ISP2400_FW_ATTR_ATIOMQ;
1096 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s ATIOMQ", buf);
1099 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s (unknown 0x%08x%08x)", buf,
1100 (uint32_t) (fwt >> 32), (uint32_t) fwt);
1102 isp_prt(isp, ISP_LOGCONFIG, "%s", buf);
1103 } else if (IS_FC(isp)) {
1104 buf = FCPARAM(isp, 0)->isp_scratch;
1105 ISP_SNPRINTF(buf, ISP_FC_SCRLEN, "Attributes:");
1106 if (fwt & ISP_FW_ATTR_TMODE) {
1107 fwt ^=ISP_FW_ATTR_TMODE;
1108 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s TargetMode", buf);
1110 if (fwt & ISP_FW_ATTR_SCCLUN) {
1111 fwt ^=ISP_FW_ATTR_SCCLUN;
1112 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s SCC-Lun", buf);
1114 if (fwt & ISP_FW_ATTR_FABRIC) {
1115 fwt ^=ISP_FW_ATTR_FABRIC;
1116 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s Fabric", buf);
1118 if (fwt & ISP_FW_ATTR_CLASS2) {
1119 fwt ^=ISP_FW_ATTR_CLASS2;
1120 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s Class2", buf);
1122 if (fwt & ISP_FW_ATTR_FCTAPE) {
1123 fwt ^=ISP_FW_ATTR_FCTAPE;
1124 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s FC-Tape", buf);
1126 if (fwt & ISP_FW_ATTR_IP) {
1127 fwt ^=ISP_FW_ATTR_IP;
1128 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s IP", buf);
1130 if (fwt & ISP_FW_ATTR_VI) {
1131 fwt ^=ISP_FW_ATTR_VI;
1132 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VI", buf);
1134 if (fwt & ISP_FW_ATTR_VI_SOLARIS) {
1135 fwt ^=ISP_FW_ATTR_VI_SOLARIS;
1136 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VI_SOLARIS", buf);
1138 if (fwt & ISP_FW_ATTR_2KLOGINS) {
1139 fwt ^=ISP_FW_ATTR_2KLOGINS;
1140 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s 2K-Login", buf);
1143 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s (unknown 0x%08x%08x)", buf,
1144 (uint32_t) (fwt >> 32), (uint32_t) fwt);
1146 isp_prt(isp, ISP_LOGCONFIG, "%s", buf);
1150 MBSINIT(&mbs, MBOX_GET_RESOURCE_COUNT, MBLOGALL, 0);
1151 isp_mboxcmd(isp, &mbs);
1152 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1155 isp->isp_maxcmds = mbs.param[3];
1157 MBSINIT(&mbs, MBOX_GET_FIRMWARE_STATUS, MBLOGALL, 0);
1158 isp_mboxcmd(isp, &mbs);
1159 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1162 isp->isp_maxcmds = mbs.param[2];
1164 isp_prt(isp, ISP_LOGCONFIG, "%d max I/O command limit set", isp->isp_maxcmds);
1167 * If we don't have Multi-ID f/w loaded, we need to restrict channels to one.
1168 * Only make this check for non-SCSI cards (I'm not sure firmware attributes
1171 if (IS_FC(isp) && isp->isp_nchan > 1) {
1172 if (!ISP_CAP_MULTI_ID(isp)) {
1173 isp_prt(isp, ISP_LOGWARN, "non-MULTIID f/w loaded, "
1174 "only can enable 1 of %d channels", isp->isp_nchan);
1176 } else if (!ISP_CAP_VP0(isp)) {
1177 isp_prt(isp, ISP_LOGWARN, "We can not use MULTIID "
1178 "feature properly without VP0_Decoupling");
1184 * Final DMA setup after we got isp_maxcmds.
1186 if (ISP_MBOXDMASETUP(isp) != 0) {
1187 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
1194 if (ISP_IRQSETUP(isp) != 0) {
1195 isp_prt(isp, ISP_LOGERR, "Cannot setup IRQ");
1198 ISP_ENABLE_INTS(isp);
1201 for (i = 0; i < isp->isp_nchan; i++)
1202 isp_change_fw_state(isp, i, FW_CONFIG_WAIT);
1205 isp->isp_state = ISP_RESETSTATE;
1208 * Okay- now that we have new firmware running, we now (re)set our
1209 * notion of how many luns we support. This is somewhat tricky because
1210 * if we haven't loaded firmware, we sometimes do not have an easy way
1211 * of knowing how many luns we support.
1213 * Expanded lun firmware gives you 32 luns for SCSI cards and
1214 * unlimited luns for Fibre Channel cards.
1216 * It turns out that even for QLogic 2100s with ROM 1.10 and above
1217 * we do get a firmware attributes word returned in mailbox register 6.
1219 * Because the lun is in a different position in the Request Queue
1220 * Entry structure for Fibre Channel with expanded lun firmware, we
1221 * can only support one lun (lun zero) when we don't know what kind
1222 * of firmware we're running.
1226 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
1227 isp->isp_maxluns = 32;
1229 isp->isp_maxluns = 8;
1232 isp->isp_maxluns = 8;
1235 if (ISP_CAP_SCCFW(isp)) {
1236 isp->isp_maxluns = 0; /* No limit -- 2/8 bytes */
1238 isp->isp_maxluns = 16;
1243 * We get some default values established. As a side
1244 * effect, NVRAM is read here (unless overriden by
1245 * a configuration flag).
1247 if (do_load_defaults) {
1249 isp_setdfltsdparm(isp);
1251 for (i = 0; i < isp->isp_nchan; i++) {
1252 isp_setdfltfcparm(isp, i);
1259 * Clean firmware shutdown.
1262 isp_stop(ispsoftc_t *isp)
1266 isp->isp_state = ISP_NILSTATE;
1267 MBSINIT(&mbs, MBOX_STOP_FIRMWARE, MBLOGALL, 500000);
1276 isp_mboxcmd(isp, &mbs);
1277 return (mbs.param[0] == MBOX_COMMAND_COMPLETE ? 0 : mbs.param[0]);
1281 * Hardware shutdown.
1284 isp_shutdown(ispsoftc_t *isp)
1287 if (isp->isp_state >= ISP_RESETSTATE)
1289 ISP_DISABLE_INTS(isp);
1292 ISP_WRITE(isp, BIU2400_ICR, 0);
1293 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_PAUSE);
1295 ISP_WRITE(isp, BIU_ICR, 0);
1296 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
1297 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
1298 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
1299 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
1300 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
1301 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
1304 ISP_WRITE(isp, BIU_ICR, 0);
1305 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
1310 * Initialize Parameters of Hardware to a known state.
1312 * Locks are held before coming here.
1315 isp_init(ispsoftc_t *isp)
1319 isp_fibre_init_2400(isp);
1321 isp_fibre_init(isp);
1329 isp_scsi_init(ispsoftc_t *isp)
1331 sdparam *sdp_chan0, *sdp_chan1;
1334 isp->isp_state = ISP_INITSTATE;
1336 sdp_chan0 = SDPARAM(isp, 0);
1337 sdp_chan1 = sdp_chan0;
1338 if (IS_DUALBUS(isp)) {
1339 sdp_chan1 = SDPARAM(isp, 1);
1342 /* First do overall per-card settings. */
1345 * If we have fast memory timing enabled, turn it on.
1347 if (sdp_chan0->isp_fast_mttr) {
1348 ISP_WRITE(isp, RISC_MTR, 0x1313);
1352 * Set Retry Delay and Count.
1353 * You set both channels at the same time.
1355 MBSINIT(&mbs, MBOX_SET_RETRY_COUNT, MBLOGALL, 0);
1356 mbs.param[1] = sdp_chan0->isp_retry_count;
1357 mbs.param[2] = sdp_chan0->isp_retry_delay;
1358 mbs.param[6] = sdp_chan1->isp_retry_count;
1359 mbs.param[7] = sdp_chan1->isp_retry_delay;
1360 isp_mboxcmd(isp, &mbs);
1361 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1366 * Set ASYNC DATA SETUP time. This is very important.
1368 MBSINIT(&mbs, MBOX_SET_ASYNC_DATA_SETUP_TIME, MBLOGALL, 0);
1369 mbs.param[1] = sdp_chan0->isp_async_data_setup;
1370 mbs.param[2] = sdp_chan1->isp_async_data_setup;
1371 isp_mboxcmd(isp, &mbs);
1372 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1377 * Set ACTIVE Negation State.
1379 MBSINIT(&mbs, MBOX_SET_ACT_NEG_STATE, MBLOGNONE, 0);
1381 (sdp_chan0->isp_req_ack_active_neg << 4) |
1382 (sdp_chan0->isp_data_line_active_neg << 5);
1384 (sdp_chan1->isp_req_ack_active_neg << 4) |
1385 (sdp_chan1->isp_data_line_active_neg << 5);
1386 isp_mboxcmd(isp, &mbs);
1387 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1388 isp_prt(isp, ISP_LOGERR,
1389 "failed to set active negation state (%d,%d), (%d,%d)",
1390 sdp_chan0->isp_req_ack_active_neg,
1391 sdp_chan0->isp_data_line_active_neg,
1392 sdp_chan1->isp_req_ack_active_neg,
1393 sdp_chan1->isp_data_line_active_neg);
1400 * Set the Tag Aging limit
1402 MBSINIT(&mbs, MBOX_SET_TAG_AGE_LIMIT, MBLOGALL, 0);
1403 mbs.param[1] = sdp_chan0->isp_tag_aging;
1404 mbs.param[2] = sdp_chan1->isp_tag_aging;
1405 isp_mboxcmd(isp, &mbs);
1406 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1407 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
1408 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
1413 * Set selection timeout.
1415 MBSINIT(&mbs, MBOX_SET_SELECT_TIMEOUT, MBLOGALL, 0);
1416 mbs.param[1] = sdp_chan0->isp_selection_timeout;
1417 mbs.param[2] = sdp_chan1->isp_selection_timeout;
1418 isp_mboxcmd(isp, &mbs);
1419 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1423 /* now do per-channel settings */
1424 isp_scsi_channel_init(isp, 0);
1425 if (IS_DUALBUS(isp))
1426 isp_scsi_channel_init(isp, 1);
1429 * Now enable request/response queues
1432 if (IS_ULTRA2(isp) || IS_1240(isp)) {
1433 MBSINIT(&mbs, MBOX_INIT_RES_QUEUE_A64, MBLOGALL, 0);
1434 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1435 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1436 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1438 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1439 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1440 isp_mboxcmd(isp, &mbs);
1441 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1444 isp->isp_residx = isp->isp_resodx = mbs.param[5];
1446 MBSINIT(&mbs, MBOX_INIT_REQ_QUEUE_A64, MBLOGALL, 0);
1447 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1448 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1449 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1451 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1452 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1453 isp_mboxcmd(isp, &mbs);
1454 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1457 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1459 MBSINIT(&mbs, MBOX_INIT_RES_QUEUE, MBLOGALL, 0);
1460 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1461 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1462 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1464 isp_mboxcmd(isp, &mbs);
1465 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1468 isp->isp_residx = isp->isp_resodx = mbs.param[5];
1470 MBSINIT(&mbs, MBOX_INIT_REQ_QUEUE, MBLOGALL, 0);
1471 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1472 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1473 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1475 isp_mboxcmd(isp, &mbs);
1476 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1479 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1483 * Turn on LVD transitions for ULTRA2 or better and other features
1485 * Now that we have 32 bit handles, don't do any fast posting
1486 * any more. For Ultra2/Ultra3 cards, we can turn on 32 bit RIO
1487 * operation or use fast posting. To be conservative, we'll only
1488 * do this for Ultra3 cards now because the other cards are so
1489 * rare for this author to find and test with.
1492 MBSINIT(&mbs, MBOX_SET_FW_FEATURES, MBLOGALL, 0);
1494 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1497 mbs.param[1] |= FW_FEATURE_FAST_POST;
1500 mbs.param[1] |= FW_FEATURE_RIO_32BIT;
1502 if (mbs.param[1] != 0) {
1503 uint16_t sfeat = mbs.param[1];
1504 isp_mboxcmd(isp, &mbs);
1505 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1506 isp_prt(isp, ISP_LOGINFO,
1507 "Enabled FW features (0x%x)", sfeat);
1511 isp->isp_state = ISP_RUNSTATE;
1515 isp_scsi_channel_init(ispsoftc_t *isp, int chan)
1521 sdp = SDPARAM(isp, chan);
1524 * Set (possibly new) Initiator ID.
1526 MBSINIT(&mbs, MBOX_SET_INIT_SCSI_ID, MBLOGALL, 0);
1527 mbs.param[1] = (chan << 7) | sdp->isp_initiator_id;
1528 isp_mboxcmd(isp, &mbs);
1529 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1532 isp_prt(isp, ISP_LOGINFO, "Chan %d Initiator ID is %d",
1533 chan, sdp->isp_initiator_id);
1537 * Set current per-target parameters to an initial safe minimum.
1539 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1543 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1546 #ifndef ISP_TARGET_MODE
1547 sdf = sdp->isp_devparam[tgt].goal_flags;
1548 sdf &= DPARM_SAFE_DFLT;
1550 * It is not quite clear when this changed over so that
1551 * we could force narrow and async for 1000/1020 cards,
1552 * but assume that this is only the case for loaded
1555 if (isp->isp_loaded_fw) {
1556 sdf |= DPARM_NARROW | DPARM_ASYNC;
1560 * The !$*!)$!$)* f/w uses the same index into some
1561 * internal table to decide how to respond to negotiations,
1562 * so if we've said "let's be safe" for ID X, and ID X
1563 * selects *us*, the negotiations will back to 'safe'
1564 * (as in narrow/async). What the f/w *should* do is
1565 * use the initiator id settings to decide how to respond.
1567 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1569 MBSINIT(&mbs, MBOX_SET_TARGET_PARAMS, MBLOGNONE, 0);
1570 mbs.param[1] = (chan << 15) | (tgt << 8);
1572 if ((sdf & DPARM_SYNC) == 0) {
1576 (sdp->isp_devparam[tgt].goal_offset << 8) |
1577 (sdp->isp_devparam[tgt].goal_period);
1579 isp_prt(isp, ISP_LOGDEBUG0, "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1580 chan, tgt, mbs.param[2], mbs.param[3] >> 8, mbs.param[3] & 0xff);
1581 isp_mboxcmd(isp, &mbs);
1582 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1583 sdf = DPARM_SAFE_DFLT;
1584 MBSINIT(&mbs, MBOX_SET_TARGET_PARAMS, MBLOGALL, 0);
1585 mbs.param[1] = (tgt << 8) | (chan << 15);
1588 isp_mboxcmd(isp, &mbs);
1589 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1595 * We don't update any information directly from the f/w
1596 * because we need to run at least one command to cause a
1597 * new state to be latched up. So, we just assume that we
1598 * converge to the values we just had set.
1600 * Ensure that we don't believe tagged queuing is enabled yet.
1601 * It turns out that sometimes the ISP just ignores our
1602 * attempts to set parameters for devices that it hasn't
1605 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1606 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1607 MBSINIT(&mbs, MBOX_SET_DEV_QUEUE_PARAMS, MBLOGALL, 0);
1608 mbs.param[1] = (chan << 15) | (tgt << 8) | lun;
1609 mbs.param[2] = sdp->isp_max_queue_depth;
1610 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1611 isp_mboxcmd(isp, &mbs);
1612 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1617 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1618 if (sdp->isp_devparam[tgt].dev_refresh) {
1619 sdp->sendmarker = 1;
1627 * Fibre Channel specific initialization.
1630 isp_fibre_init(ispsoftc_t *isp)
1633 isp_icb_t local, *icbp = &local;
1637 * We only support one channel on non-24XX cards
1639 fcp = FCPARAM(isp, 0);
1640 if (fcp->role == ISP_ROLE_NONE)
1643 isp->isp_state = ISP_INITSTATE;
1644 ISP_MEMZERO(icbp, sizeof (*icbp));
1645 icbp->icb_version = ICB_VERSION1;
1646 icbp->icb_fwoptions = fcp->isp_fwoptions;
1649 * Firmware Options are either retrieved from NVRAM or
1650 * are patched elsewhere. We check them for sanity here
1651 * and make changes based on board revision, but otherwise
1652 * let others decide policy.
1656 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1658 if (IS_2100(isp) && isp->isp_revision < 5) {
1659 icbp->icb_fwoptions &= ~ICBOPT_FAIRNESS;
1663 * We have to use FULL LOGIN even though it resets the loop too much
1664 * because otherwise port database entries don't get updated after
1665 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1667 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1668 icbp->icb_fwoptions |= ICBOPT_FULL_LOGIN;
1672 * Insist on Port Database Update Async notifications
1674 icbp->icb_fwoptions |= ICBOPT_PDBCHANGE_AE;
1677 * Make sure that target role reflects into fwoptions.
1679 if (fcp->role & ISP_ROLE_TARGET) {
1680 icbp->icb_fwoptions |= ICBOPT_TGT_ENABLE;
1682 icbp->icb_fwoptions &= ~ICBOPT_TGT_ENABLE;
1686 * For some reason my 2200 does not generate ATIOs in target mode
1687 * if initiator is disabled. Extra logins are better then target
1688 * not working at all.
1690 if ((fcp->role & ISP_ROLE_INITIATOR) || IS_2100(isp) || IS_2200(isp)) {
1691 icbp->icb_fwoptions &= ~ICBOPT_INI_DISABLE;
1693 icbp->icb_fwoptions |= ICBOPT_INI_DISABLE;
1696 icbp->icb_maxfrmlen = DEFAULT_FRAMESIZE(isp);
1697 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN || icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1698 isp_prt(isp, ISP_LOGERR, "bad frame length (%d) from NVRAM- using %d", DEFAULT_FRAMESIZE(isp), ICB_DFLT_FRMLEN);
1699 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1701 icbp->icb_maxalloc = fcp->isp_maxalloc;
1702 if (icbp->icb_maxalloc < 1) {
1703 isp_prt(isp, ISP_LOGERR, "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1704 icbp->icb_maxalloc = 16;
1706 icbp->icb_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
1707 if (icbp->icb_execthrottle < 1) {
1708 isp_prt(isp, ISP_LOGERR, "bad execution throttle of %d- using %d", DEFAULT_EXEC_THROTTLE(isp), ICB_DFLT_THROTTLE);
1709 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1711 icbp->icb_retry_delay = fcp->isp_retry_delay;
1712 icbp->icb_retry_count = fcp->isp_retry_count;
1713 if (fcp->isp_loopid < LOCAL_LOOP_LIM) {
1714 icbp->icb_hardaddr = fcp->isp_loopid;
1715 if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
1716 icbp->icb_fwoptions |= ICBOPT_HARD_ADDRESS;
1718 icbp->icb_fwoptions |= ICBOPT_PREV_ADDRESS;
1722 * Right now we just set extended options to prefer point-to-point
1723 * over loop based upon some soft config options.
1725 * NB: for the 2300, ICBOPT_EXTENDED is required.
1729 * We can't have Fast Posting any more- we now
1730 * have 32 bit handles.
1732 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1733 } else if (IS_2200(isp) || IS_23XX(isp)) {
1734 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1736 icbp->icb_xfwoptions = fcp->isp_xfwoptions;
1738 if (ISP_CAP_FCTAPE(isp)) {
1739 if (isp->isp_confopts & ISP_CFG_NOFCTAPE)
1740 icbp->icb_xfwoptions &= ~ICBXOPT_FCTAPE;
1742 if (isp->isp_confopts & ISP_CFG_FCTAPE)
1743 icbp->icb_xfwoptions |= ICBXOPT_FCTAPE;
1745 if (icbp->icb_xfwoptions & ICBXOPT_FCTAPE) {
1746 icbp->icb_fwoptions &= ~ICBOPT_FULL_LOGIN; /* per documents */
1747 icbp->icb_xfwoptions |= ICBXOPT_FCTAPE_CCQ|ICBXOPT_FCTAPE_CONFIRM;
1748 FCPARAM(isp, 0)->fctape_enabled = 1;
1750 FCPARAM(isp, 0)->fctape_enabled = 0;
1753 icbp->icb_xfwoptions &= ~ICBXOPT_FCTAPE;
1754 FCPARAM(isp, 0)->fctape_enabled = 0;
1758 * Prefer or force Point-To-Point instead Loop?
1760 switch (isp->isp_confopts & ISP_CFG_PORT_PREF) {
1761 case ISP_CFG_LPORT_ONLY:
1762 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1763 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1765 case ISP_CFG_NPORT_ONLY:
1766 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1767 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1770 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1771 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1774 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1775 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1778 /* Let NVRAM settings define it if they are sane */
1779 switch (icbp->icb_xfwoptions & ICBXOPT_TOPO_MASK) {
1780 case ICBXOPT_PTP_2_LOOP:
1781 case ICBXOPT_PTP_ONLY:
1782 case ICBXOPT_LOOP_ONLY:
1783 case ICBXOPT_LOOP_2_PTP:
1786 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1787 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1793 * We can't have Fast Posting any more- we now
1794 * have 32 bit handles.
1796 * RIO seemed to have to much breakage.
1798 * Just opt for safety.
1800 icbp->icb_xfwoptions &= ~ICBXOPT_RIO_16BIT;
1801 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1804 * QLogic recommends that FAST Posting be turned
1805 * off for 23XX cards and instead allow the HBA
1806 * to write response queue entries and interrupt
1807 * after a delay (ZIO).
1809 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1810 if ((fcp->isp_xfwoptions & ICBXOPT_TIMER_MASK) == ICBXOPT_ZIO) {
1811 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1812 icbp->icb_idelaytimer = 10;
1814 icbp->icb_zfwoptions = fcp->isp_zfwoptions;
1815 if (isp->isp_confopts & ISP_CFG_1GB) {
1816 icbp->icb_zfwoptions &= ~ICBZOPT_RATE_MASK;
1817 icbp->icb_zfwoptions |= ICBZOPT_RATE_1GB;
1818 } else if (isp->isp_confopts & ISP_CFG_2GB) {
1819 icbp->icb_zfwoptions &= ~ICBZOPT_RATE_MASK;
1820 icbp->icb_zfwoptions |= ICBZOPT_RATE_2GB;
1822 switch (icbp->icb_zfwoptions & ICBZOPT_RATE_MASK) {
1823 case ICBZOPT_RATE_1GB:
1824 case ICBZOPT_RATE_2GB:
1825 case ICBZOPT_RATE_AUTO:
1828 icbp->icb_zfwoptions &= ~ICBZOPT_RATE_MASK;
1829 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1838 * For 22XX > 2.1.26 && 23XX, set some options.
1840 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1841 MBSINIT(&mbs, MBOX_SET_FIRMWARE_OPTIONS, MBLOGALL, 0);
1842 mbs.param[1] = IFCOPT1_DISF7SWTCH|IFCOPT1_LIPASYNC|IFCOPT1_LIPF8;
1845 if (ISP_FW_NEWER_THAN(isp, 3, 16, 0)) {
1846 mbs.param[1] |= IFCOPT1_EQFQASYNC|IFCOPT1_CTIO_RETRY;
1847 if (fcp->role & ISP_ROLE_TARGET) {
1848 if (ISP_FW_NEWER_THAN(isp, 3, 25, 0)) {
1849 mbs.param[1] |= IFCOPT1_ENAPURE;
1851 mbs.param[3] = IFCOPT3_NOPRLI;
1854 isp_mboxcmd(isp, &mbs);
1855 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1859 icbp->icb_logintime = ICB_LOGIN_TOV;
1861 #ifdef ISP_TARGET_MODE
1862 if (icbp->icb_fwoptions & ICBOPT_TGT_ENABLE) {
1863 icbp->icb_lunenables = 0xffff;
1864 icbp->icb_ccnt = 0xff;
1865 icbp->icb_icnt = 0xff;
1866 icbp->icb_lunetimeout = ICB_LUN_ENABLE_TOV;
1869 if (fcp->isp_wwnn && fcp->isp_wwpn) {
1870 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1871 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, fcp->isp_wwnn);
1872 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1873 isp_prt(isp, ISP_LOGDEBUG1,
1874 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1875 ((uint32_t) (fcp->isp_wwnn >> 32)),
1876 ((uint32_t) (fcp->isp_wwnn)),
1877 ((uint32_t) (fcp->isp_wwpn >> 32)),
1878 ((uint32_t) (fcp->isp_wwpn)));
1879 } else if (fcp->isp_wwpn) {
1880 icbp->icb_fwoptions &= ~ICBOPT_BOTH_WWNS;
1881 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1882 isp_prt(isp, ISP_LOGDEBUG1,
1883 "Setting ICB Port 0x%08x%08x",
1884 ((uint32_t) (fcp->isp_wwpn >> 32)),
1885 ((uint32_t) (fcp->isp_wwpn)));
1887 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
1890 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1891 if (icbp->icb_rqstqlen < 1) {
1892 isp_prt(isp, ISP_LOGERR, "bad request queue length");
1894 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1895 if (icbp->icb_rsltqlen < 1) {
1896 isp_prt(isp, ISP_LOGERR, "bad result queue length");
1898 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1899 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1900 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1901 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1902 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1903 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1904 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1905 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1907 if (FC_SCRATCH_ACQUIRE(isp, 0)) {
1908 isp_prt(isp, ISP_LOGERR, sacq);
1911 isp_prt(isp, ISP_LOGDEBUG0, "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1912 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1914 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1915 if (isp->isp_dblev & ISP_LOGDEBUG1) {
1916 isp_print_bytes(isp, "isp_fibre_init",
1917 sizeof(*icbp), fcp->isp_scratch);
1923 MBSINIT(&mbs, MBOX_INIT_FIRMWARE, MBLOGALL, 30000000);
1925 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1926 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1927 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1928 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1929 isp_prt(isp, ISP_LOGDEBUG0, "INIT F/W from %p (%08x%08x)",
1930 fcp->isp_scratch, (uint32_t) ((uint64_t)fcp->isp_scdma >> 32),
1931 (uint32_t) fcp->isp_scdma);
1932 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp), 0);
1933 isp_mboxcmd(isp, &mbs);
1934 FC_SCRATCH_RELEASE(isp, 0);
1935 if (mbs.param[0] != MBOX_COMMAND_COMPLETE)
1937 isp->isp_reqidx = 0;
1938 isp->isp_reqodx = 0;
1939 isp->isp_residx = 0;
1940 isp->isp_resodx = 0;
1943 * Whatever happens, we're now committed to being here.
1945 isp->isp_state = ISP_RUNSTATE;
1949 isp_fibre_init_2400(ispsoftc_t *isp)
1952 isp_icb_2400_t local, *icbp = &local;
1957 * Check to see whether all channels have *some* kind of role
1959 for (chan = 0; chan < isp->isp_nchan; chan++) {
1960 fcp = FCPARAM(isp, chan);
1961 if (fcp->role != ISP_ROLE_NONE) {
1965 if (chan == isp->isp_nchan) {
1966 isp_prt(isp, ISP_LOG_WARN1, "all %d channels with role 'none'", chan);
1970 isp->isp_state = ISP_INITSTATE;
1973 * Start with channel 0.
1975 fcp = FCPARAM(isp, 0);
1978 * Turn on LIP F8 async event (1)
1980 MBSINIT(&mbs, MBOX_SET_FIRMWARE_OPTIONS, MBLOGALL, 0);
1982 isp_mboxcmd(isp, &mbs);
1983 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1987 ISP_MEMZERO(icbp, sizeof (*icbp));
1988 icbp->icb_fwoptions1 = fcp->isp_fwoptions;
1989 icbp->icb_fwoptions2 = fcp->isp_xfwoptions;
1990 icbp->icb_fwoptions3 = fcp->isp_zfwoptions;
1991 if (isp->isp_nchan > 1 && ISP_CAP_VP0(isp)) {
1992 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_INI_DISABLE;
1993 icbp->icb_fwoptions1 |= ICB2400_OPT1_TGT_ENABLE;
1995 if (fcp->role & ISP_ROLE_TARGET)
1996 icbp->icb_fwoptions1 |= ICB2400_OPT1_TGT_ENABLE;
1998 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_TGT_ENABLE;
1999 if (fcp->role & ISP_ROLE_INITIATOR)
2000 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_INI_DISABLE;
2002 icbp->icb_fwoptions1 |= ICB2400_OPT1_INI_DISABLE;
2005 icbp->icb_version = ICB_VERSION1;
2006 icbp->icb_maxfrmlen = DEFAULT_FRAMESIZE(isp);
2007 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN || icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
2008 isp_prt(isp, ISP_LOGERR, "bad frame length (%d) from NVRAM- using %d", DEFAULT_FRAMESIZE(isp), ICB_DFLT_FRMLEN);
2009 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
2012 icbp->icb_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
2013 if (icbp->icb_execthrottle < 1) {
2014 isp_prt(isp, ISP_LOGERR, "bad execution throttle of %d- using %d", DEFAULT_EXEC_THROTTLE(isp), ICB_DFLT_THROTTLE);
2015 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
2019 * Set target exchange count. Take half if we are supporting both roles.
2021 if (icbp->icb_fwoptions1 & ICB2400_OPT1_TGT_ENABLE) {
2022 icbp->icb_xchgcnt = isp->isp_maxcmds;
2023 if ((icbp->icb_fwoptions1 & ICB2400_OPT1_INI_DISABLE) == 0)
2024 icbp->icb_xchgcnt >>= 1;
2027 if (fcp->isp_loopid < LOCAL_LOOP_LIM) {
2028 icbp->icb_hardaddr = fcp->isp_loopid;
2029 if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
2030 icbp->icb_fwoptions1 |= ICB2400_OPT1_HARD_ADDRESS;
2032 icbp->icb_fwoptions1 |= ICB2400_OPT1_PREV_ADDRESS;
2035 if (isp->isp_confopts & ISP_CFG_NOFCTAPE) {
2036 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_FCTAPE;
2038 if (isp->isp_confopts & ISP_CFG_FCTAPE) {
2039 icbp->icb_fwoptions2 |= ICB2400_OPT2_FCTAPE;
2042 for (chan = 0; chan < isp->isp_nchan; chan++) {
2043 if (icbp->icb_fwoptions2 & ICB2400_OPT2_FCTAPE)
2044 FCPARAM(isp, chan)->fctape_enabled = 1;
2046 FCPARAM(isp, chan)->fctape_enabled = 0;
2049 switch (isp->isp_confopts & ISP_CFG_PORT_PREF) {
2050 case ISP_CFG_LPORT_ONLY:
2051 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2052 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_ONLY;
2054 case ISP_CFG_NPORT_ONLY:
2055 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2056 icbp->icb_fwoptions2 |= ICB2400_OPT2_PTP_ONLY;
2059 /* ISP_CFG_PTP_2_LOOP not available in 24XX/25XX */
2061 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2062 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_2_PTP;
2065 /* Let NVRAM settings define it if they are sane */
2066 switch (icbp->icb_fwoptions2 & ICB2400_OPT2_TOPO_MASK) {
2067 case ICB2400_OPT2_LOOP_ONLY:
2068 case ICB2400_OPT2_PTP_ONLY:
2069 case ICB2400_OPT2_LOOP_2_PTP:
2072 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2073 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_2_PTP;
2078 switch (icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK) {
2079 case ICB2400_OPT2_ZIO:
2080 case ICB2400_OPT2_ZIO1:
2081 icbp->icb_idelaytimer = 0;
2086 isp_prt(isp, ISP_LOGWARN, "bad value %x in fwopt2 timer field", icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK);
2087 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TIMER_MASK;
2092 /* Use handshake to reduce global lock congestion. */
2093 icbp->icb_fwoptions2 |= ICB2400_OPT2_ENA_IHR;
2094 icbp->icb_fwoptions2 |= ICB2400_OPT2_ENA_IHA;
2097 if ((icbp->icb_fwoptions3 & ICB2400_OPT3_RSPSZ_MASK) == 0) {
2098 icbp->icb_fwoptions3 |= ICB2400_OPT3_RSPSZ_24;
2100 if (isp->isp_confopts & ISP_CFG_1GB) {
2101 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2102 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_1GB;
2103 } else if (isp->isp_confopts & ISP_CFG_2GB) {
2104 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2105 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_2GB;
2106 } else if (isp->isp_confopts & ISP_CFG_4GB) {
2107 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2108 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_4GB;
2109 } else if (isp->isp_confopts & ISP_CFG_8GB) {
2110 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2111 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_8GB;
2112 } else if (isp->isp_confopts & ISP_CFG_16GB) {
2113 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2114 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_16GB;
2116 switch (icbp->icb_fwoptions3 & ICB2400_OPT3_RATE_MASK) {
2117 case ICB2400_OPT3_RATE_4GB:
2118 case ICB2400_OPT3_RATE_8GB:
2119 case ICB2400_OPT3_RATE_16GB:
2120 case ICB2400_OPT3_RATE_AUTO:
2122 case ICB2400_OPT3_RATE_2GB:
2123 if (isp->isp_type <= ISP_HA_FC_2500)
2126 case ICB2400_OPT3_RATE_1GB:
2127 if (isp->isp_type <= ISP_HA_FC_2400)
2131 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_MASK;
2132 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_AUTO;
2136 icbp->icb_logintime = ICB_LOGIN_TOV;
2138 if (fcp->isp_wwnn && fcp->isp_wwpn) {
2139 icbp->icb_fwoptions1 |= ICB2400_OPT1_BOTH_WWNS;
2140 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
2141 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, fcp->isp_wwnn);
2142 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)),
2143 ((uint32_t) (fcp->isp_wwpn >> 32)), ((uint32_t) (fcp->isp_wwpn)));
2144 } else if (fcp->isp_wwpn) {
2145 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_BOTH_WWNS;
2146 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
2147 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)));
2149 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
2152 icbp->icb_retry_count = fcp->isp_retry_count;
2154 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
2155 if (icbp->icb_rqstqlen < 8) {
2156 isp_prt(isp, ISP_LOGERR, "bad request queue length %d", icbp->icb_rqstqlen);
2159 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
2160 if (icbp->icb_rsltqlen < 8) {
2161 isp_prt(isp, ISP_LOGERR, "bad result queue length %d",
2162 icbp->icb_rsltqlen);
2165 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
2166 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
2167 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
2168 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
2170 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
2171 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
2172 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
2173 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
2175 #ifdef ISP_TARGET_MODE
2176 /* unconditionally set up the ATIO queue if we support target mode */
2177 icbp->icb_atioqlen = RESULT_QUEUE_LEN(isp);
2178 if (icbp->icb_atioqlen < 8) {
2179 isp_prt(isp, ISP_LOGERR, "bad ATIO queue length %d", icbp->icb_atioqlen);
2182 icbp->icb_atioqaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_atioq_dma);
2183 icbp->icb_atioqaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_atioq_dma);
2184 icbp->icb_atioqaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_atioq_dma);
2185 icbp->icb_atioqaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_atioq_dma);
2186 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),
2187 DMA_WD1(isp->isp_atioq_dma), DMA_WD0(isp->isp_atioq_dma));
2190 if (ISP_CAP_MSIX(isp) && isp->isp_nirq >= 2) {
2191 icbp->icb_msixresp = 1;
2192 if (IS_26XX(isp) && isp->isp_nirq >= 3)
2193 icbp->icb_msixatio = 2;
2196 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);
2198 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),
2199 DMA_WD1(isp->isp_rquest_dma), DMA_WD0(isp->isp_rquest_dma), DMA_WD3(isp->isp_result_dma), DMA_WD2(isp->isp_result_dma),
2200 DMA_WD1(isp->isp_result_dma), DMA_WD0(isp->isp_result_dma));
2202 if (FC_SCRATCH_ACQUIRE(isp, 0)) {
2203 isp_prt(isp, ISP_LOGERR, sacq);
2206 ISP_MEMZERO(fcp->isp_scratch, ISP_FC_SCRLEN);
2207 isp_put_icb_2400(isp, icbp, fcp->isp_scratch);
2208 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2209 isp_print_bytes(isp, "isp_fibre_init_2400",
2210 sizeof (*icbp), fcp->isp_scratch);
2214 * Now fill in information about any additional channels
2216 if (isp->isp_nchan > 1) {
2217 isp_icb_2400_vpinfo_t vpinfo, *vdst;
2218 vp_port_info_t pi, *pdst;
2222 vpinfo.vp_global_options = ICB2400_VPGOPT_GEN_RIDA;
2223 if (ISP_CAP_VP0(isp)) {
2224 vpinfo.vp_global_options |= ICB2400_VPGOPT_VP0_DECOUPLE;
2225 vpinfo.vp_count = isp->isp_nchan;
2228 vpinfo.vp_count = isp->isp_nchan - 1;
2231 off = fcp->isp_scratch;
2232 off += ICB2400_VPINFO_OFF;
2233 vdst = (isp_icb_2400_vpinfo_t *) off;
2234 isp_put_icb_2400_vpinfo(isp, &vpinfo, vdst);
2235 amt = ICB2400_VPINFO_OFF + sizeof (isp_icb_2400_vpinfo_t);
2236 for (; chan < isp->isp_nchan; chan++) {
2239 ISP_MEMZERO(&pi, sizeof (pi));
2240 fcp2 = FCPARAM(isp, chan);
2241 if (fcp2->role != ISP_ROLE_NONE) {
2242 pi.vp_port_options = ICB2400_VPOPT_ENABLED |
2243 ICB2400_VPOPT_ENA_SNSLOGIN;
2244 if (fcp2->role & ISP_ROLE_INITIATOR)
2245 pi.vp_port_options |= ICB2400_VPOPT_INI_ENABLE;
2246 if ((fcp2->role & ISP_ROLE_TARGET) == 0)
2247 pi.vp_port_options |= ICB2400_VPOPT_TGT_DISABLE;
2249 if (fcp2->isp_loopid < LOCAL_LOOP_LIM) {
2250 pi.vp_port_loopid = fcp2->isp_loopid;
2251 if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
2252 pi.vp_port_options |= ICB2400_VPOPT_HARD_ADDRESS;
2254 pi.vp_port_options |= ICB2400_VPOPT_PREV_ADDRESS;
2256 MAKE_NODE_NAME_FROM_WWN(pi.vp_port_portname, fcp2->isp_wwpn);
2257 MAKE_NODE_NAME_FROM_WWN(pi.vp_port_nodename, fcp2->isp_wwnn);
2258 off = fcp->isp_scratch;
2259 if (ISP_CAP_VP0(isp))
2260 off += ICB2400_VPINFO_PORT_OFF(chan);
2262 off += ICB2400_VPINFO_PORT_OFF(chan - 1);
2263 pdst = (vp_port_info_t *) off;
2264 isp_put_vp_port_info(isp, &pi, pdst);
2265 amt += ICB2400_VPOPT_WRITE_SIZE;
2267 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2268 isp_print_bytes(isp, "isp_fibre_init_2400",
2269 amt - ICB2400_VPINFO_OFF,
2270 (char *)fcp->isp_scratch + ICB2400_VPINFO_OFF);
2277 MBSINIT(&mbs, 0, MBLOGALL, 30000000);
2278 if (isp->isp_nchan > 1) {
2279 mbs.param[0] = MBOX_INIT_FIRMWARE_MULTI_ID;
2281 mbs.param[0] = MBOX_INIT_FIRMWARE;
2284 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2285 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2286 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2287 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2288 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));
2289 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp), 0);
2290 isp_mboxcmd(isp, &mbs);
2291 FC_SCRATCH_RELEASE(isp, 0);
2293 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2296 isp->isp_reqidx = 0;
2297 isp->isp_reqodx = 0;
2298 isp->isp_residx = 0;
2299 isp->isp_resodx = 0;
2300 isp->isp_atioodx = 0;
2303 * Whatever happens, we're now committed to being here.
2305 isp->isp_state = ISP_RUNSTATE;
2309 isp_fc_enable_vp(ispsoftc_t *isp, int chan)
2311 fcparam *fcp = FCPARAM(isp, chan);
2314 uint8_t resp[QENTRY_LEN];
2316 /* Build a VP MODIFY command in memory */
2317 ISP_MEMZERO(&vp, sizeof(vp));
2318 vp.vp_mod_hdr.rqs_entry_type = RQSTYPE_VP_MODIFY;
2319 vp.vp_mod_hdr.rqs_entry_count = 1;
2321 vp.vp_mod_idx0 = chan;
2322 vp.vp_mod_cmd = VP_MODIFY_ENA;
2323 vp.vp_mod_ports[0].options = ICB2400_VPOPT_ENABLED |
2324 ICB2400_VPOPT_ENA_SNSLOGIN;
2325 if (fcp->role & ISP_ROLE_INITIATOR)
2326 vp.vp_mod_ports[0].options |= ICB2400_VPOPT_INI_ENABLE;
2327 if ((fcp->role & ISP_ROLE_TARGET) == 0)
2328 vp.vp_mod_ports[0].options |= ICB2400_VPOPT_TGT_DISABLE;
2329 if (fcp->isp_loopid < LOCAL_LOOP_LIM) {
2330 vp.vp_mod_ports[0].loopid = fcp->isp_loopid;
2331 if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
2332 vp.vp_mod_ports[0].options |= ICB2400_VPOPT_HARD_ADDRESS;
2334 vp.vp_mod_ports[0].options |= ICB2400_VPOPT_PREV_ADDRESS;
2336 MAKE_NODE_NAME_FROM_WWN(vp.vp_mod_ports[0].wwpn, fcp->isp_wwpn);
2337 MAKE_NODE_NAME_FROM_WWN(vp.vp_mod_ports[0].wwnn, fcp->isp_wwnn);
2339 /* Prepare space for response in memory */
2340 memset(resp, 0xff, sizeof(resp));
2341 vp.vp_mod_hdl = isp_allocate_handle(isp, resp, ISP_HANDLE_CTRL);
2342 if (vp.vp_mod_hdl == 0) {
2343 isp_prt(isp, ISP_LOGERR,
2344 "%s: VP_MODIFY of Chan %d out of handles", __func__, chan);
2348 /* Send request and wait for response. */
2349 reqp = isp_getrqentry(isp);
2351 isp_prt(isp, ISP_LOGERR,
2352 "%s: VP_MODIFY of Chan %d out of rqent", __func__, chan);
2353 isp_destroy_handle(isp, vp.vp_mod_hdl);
2356 isp_put_vp_modify(isp, &vp, (vp_modify_t *)reqp);
2357 if (isp->isp_dblev & ISP_LOGDEBUG1)
2358 isp_print_bytes(isp, "IOCB VP_MODIFY", QENTRY_LEN, reqp);
2359 ISP_SYNC_REQUEST(isp);
2360 if (msleep(resp, &isp->isp_lock, 0, "VP_MODIFY", 5*hz) == EWOULDBLOCK) {
2361 isp_prt(isp, ISP_LOGERR,
2362 "%s: VP_MODIFY of Chan %d timed out", __func__, chan);
2363 isp_destroy_handle(isp, vp.vp_mod_hdl);
2366 if (isp->isp_dblev & ISP_LOGDEBUG1)
2367 isp_print_bytes(isp, "IOCB VP_MODIFY response", QENTRY_LEN, resp);
2368 isp_get_vp_modify(isp, (vp_modify_t *)resp, &vp);
2370 if (vp.vp_mod_hdr.rqs_flags != 0 || vp.vp_mod_status != VP_STS_OK) {
2371 isp_prt(isp, ISP_LOGERR,
2372 "%s: VP_MODIFY of Chan %d failed with flags %x status %d",
2373 __func__, chan, vp.vp_mod_hdr.rqs_flags, vp.vp_mod_status);
2380 isp_fc_disable_vp(ispsoftc_t *isp, int chan)
2384 uint8_t resp[QENTRY_LEN];
2386 /* Build a VP CTRL command in memory */
2387 ISP_MEMZERO(&vp, sizeof(vp));
2388 vp.vp_ctrl_hdr.rqs_entry_type = RQSTYPE_VP_CTRL;
2389 vp.vp_ctrl_hdr.rqs_entry_count = 1;
2390 if (ISP_CAP_VP0(isp)) {
2391 vp.vp_ctrl_status = 1;
2393 vp.vp_ctrl_status = 0;
2394 chan--; /* VP0 can not be controlled in this case. */
2396 vp.vp_ctrl_command = VP_CTRL_CMD_DISABLE_VP_LOGO_ALL;
2397 vp.vp_ctrl_vp_count = 1;
2398 vp.vp_ctrl_idmap[chan / 16] |= (1 << chan % 16);
2400 /* Prepare space for response in memory */
2401 memset(resp, 0xff, sizeof(resp));
2402 vp.vp_ctrl_handle = isp_allocate_handle(isp, resp, ISP_HANDLE_CTRL);
2403 if (vp.vp_ctrl_handle == 0) {
2404 isp_prt(isp, ISP_LOGERR,
2405 "%s: VP_CTRL of Chan %d out of handles", __func__, chan);
2409 /* Send request and wait for response. */
2410 reqp = isp_getrqentry(isp);
2412 isp_prt(isp, ISP_LOGERR,
2413 "%s: VP_CTRL of Chan %d out of rqent", __func__, chan);
2414 isp_destroy_handle(isp, vp.vp_ctrl_handle);
2417 isp_put_vp_ctrl_info(isp, &vp, (vp_ctrl_info_t *)reqp);
2418 if (isp->isp_dblev & ISP_LOGDEBUG1)
2419 isp_print_bytes(isp, "IOCB VP_CTRL", QENTRY_LEN, reqp);
2420 ISP_SYNC_REQUEST(isp);
2421 if (msleep(resp, &isp->isp_lock, 0, "VP_CTRL", 5*hz) == EWOULDBLOCK) {
2422 isp_prt(isp, ISP_LOGERR,
2423 "%s: VP_CTRL of Chan %d timed out", __func__, chan);
2424 isp_destroy_handle(isp, vp.vp_ctrl_handle);
2427 if (isp->isp_dblev & ISP_LOGDEBUG1)
2428 isp_print_bytes(isp, "IOCB VP_CTRL response", QENTRY_LEN, resp);
2429 isp_get_vp_ctrl_info(isp, (vp_ctrl_info_t *)resp, &vp);
2431 if (vp.vp_ctrl_hdr.rqs_flags != 0 || vp.vp_ctrl_status != 0) {
2432 isp_prt(isp, ISP_LOGERR,
2433 "%s: VP_CTRL of Chan %d failed with flags %x status %d %d",
2434 __func__, chan, vp.vp_ctrl_hdr.rqs_flags,
2435 vp.vp_ctrl_status, vp.vp_ctrl_index_fail);
2442 isp_fc_change_role(ispsoftc_t *isp, int chan, int new_role)
2444 fcparam *fcp = FCPARAM(isp, chan);
2445 int i, was, res = 0;
2447 if (chan >= isp->isp_nchan) {
2448 isp_prt(isp, ISP_LOGWARN, "%s: bad channel %d", __func__, chan);
2451 if (fcp->role == new_role)
2453 for (was = 0, i = 0; i < isp->isp_nchan; i++) {
2454 if (FCPARAM(isp, i)->role != ISP_ROLE_NONE)
2457 if (was == 0 || (was == 1 && fcp->role != ISP_ROLE_NONE)) {
2458 fcp->role = new_role;
2459 return (isp_reinit(isp, 0));
2461 if (fcp->role != ISP_ROLE_NONE) {
2462 res = isp_fc_disable_vp(isp, chan);
2463 isp_clear_portdb(isp, chan);
2465 fcp->role = new_role;
2466 if (fcp->role != ISP_ROLE_NONE)
2467 res = isp_fc_enable_vp(isp, chan);
2472 isp_clear_portdb(ispsoftc_t *isp, int chan)
2474 fcparam *fcp = FCPARAM(isp, chan);
2478 for (i = 0; i < MAX_FC_TARG; i++) {
2479 lp = &fcp->portdb[i];
2480 switch (lp->state) {
2481 case FC_PORTDB_STATE_DEAD:
2482 case FC_PORTDB_STATE_CHANGED:
2483 case FC_PORTDB_STATE_VALID:
2484 lp->state = FC_PORTDB_STATE_NIL;
2485 isp_async(isp, ISPASYNC_DEV_GONE, chan, lp);
2487 case FC_PORTDB_STATE_NIL:
2488 case FC_PORTDB_STATE_NEW:
2489 lp->state = FC_PORTDB_STATE_NIL;
2491 case FC_PORTDB_STATE_ZOMBIE:
2494 panic("Don't know how to clear state %d\n", lp->state);
2500 isp_mark_portdb(ispsoftc_t *isp, int chan)
2502 fcparam *fcp = FCPARAM(isp, chan);
2506 for (i = 0; i < MAX_FC_TARG; i++) {
2507 lp = &fcp->portdb[i];
2508 if (lp->state == FC_PORTDB_STATE_NIL)
2510 if (lp->portid >= DOMAIN_CONTROLLER_BASE &&
2511 lp->portid <= DOMAIN_CONTROLLER_END)
2513 fcp->portdb[i].probational = 1;
2518 * Perform an IOCB PLOGI or LOGO via EXECUTE IOCB A64 for 24XX cards
2519 * or via FABRIC LOGIN/FABRIC LOGOUT for other cards.
2522 isp_plogx(ispsoftc_t *isp, int chan, uint16_t handle, uint32_t portid, int flags)
2526 uint8_t resp[QENTRY_LEN];
2527 uint32_t sst, parm1;
2532 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d PLOGX %s PortID 0x%06x nphdl 0x%x",
2533 chan, (flags & PLOGX_FLG_CMD_MASK) == PLOGX_FLG_CMD_PLOGI ?
2534 "Login":"Logout", portid, handle);
2535 if (!IS_24XX(isp)) {
2536 int action = flags & PLOGX_FLG_CMD_MASK;
2537 if (action == PLOGX_FLG_CMD_PLOGI) {
2538 return (isp_port_login(isp, handle, portid));
2539 } else if (action == PLOGX_FLG_CMD_LOGO) {
2540 return (isp_port_logout(isp, handle, portid));
2542 return (MBOX_INVALID_COMMAND);
2546 ISP_MEMZERO(&pl, sizeof(pl));
2547 pl.plogx_header.rqs_entry_count = 1;
2548 pl.plogx_header.rqs_entry_type = RQSTYPE_LOGIN;
2549 pl.plogx_nphdl = handle;
2550 pl.plogx_vphdl = chan;
2551 pl.plogx_portlo = portid;
2552 pl.plogx_rspsz_porthi = (portid >> 16) & 0xff;
2553 pl.plogx_flags = flags;
2555 /* Prepare space for response in memory */
2556 memset(resp, 0xff, sizeof(resp));
2557 pl.plogx_handle = isp_allocate_handle(isp, resp, ISP_HANDLE_CTRL);
2558 if (pl.plogx_handle == 0) {
2559 isp_prt(isp, ISP_LOGERR,
2560 "%s: PLOGX of Chan %d out of handles", __func__, chan);
2564 /* Send request and wait for response. */
2565 reqp = isp_getrqentry(isp);
2567 isp_prt(isp, ISP_LOGERR,
2568 "%s: PLOGX of Chan %d out of rqent", __func__, chan);
2569 isp_destroy_handle(isp, pl.plogx_handle);
2572 isp_put_plogx(isp, &pl, (isp_plogx_t *)reqp);
2573 if (isp->isp_dblev & ISP_LOGDEBUG1)
2574 isp_print_bytes(isp, "IOCB LOGX", QENTRY_LEN, reqp);
2575 FCPARAM(isp, chan)->isp_login_hdl = handle;
2576 ISP_SYNC_REQUEST(isp);
2577 if (msleep(resp, &isp->isp_lock, 0, "PLOGX", 3 * ICB_LOGIN_TOV * hz)
2579 isp_prt(isp, ISP_LOGERR,
2580 "%s: PLOGX of Chan %d timed out", __func__, chan);
2581 isp_destroy_handle(isp, pl.plogx_handle);
2584 FCPARAM(isp, chan)->isp_login_hdl = NIL_HANDLE;
2585 if (isp->isp_dblev & ISP_LOGDEBUG1)
2586 isp_print_bytes(isp, "IOCB LOGX response", QENTRY_LEN, resp);
2587 isp_get_plogx(isp, (isp_plogx_t *)resp, &pl);
2589 if (pl.plogx_status == PLOGX_STATUS_OK) {
2591 } else if (pl.plogx_status != PLOGX_STATUS_IOCBERR) {
2592 isp_prt(isp, ISP_LOGWARN,
2593 "status 0x%x on port login IOCB channel %d",
2594 pl.plogx_status, chan);
2598 sst = pl.plogx_ioparm[0].lo16 | (pl.plogx_ioparm[0].hi16 << 16);
2599 parm1 = pl.plogx_ioparm[1].lo16 | (pl.plogx_ioparm[1].hi16 << 16);
2606 case PLOGX_IOCBERR_NOLINK:
2609 case PLOGX_IOCBERR_NOIOCB:
2610 msg = "no IOCB buffer";
2612 case PLOGX_IOCBERR_NOXGHG:
2613 msg = "no Exchange Control Block";
2615 case PLOGX_IOCBERR_FAILED:
2616 ISP_SNPRINTF(buf, sizeof (buf), "reason 0x%x (last LOGIN state 0x%x)", parm1 & 0xff, (parm1 >> 8) & 0xff);
2619 case PLOGX_IOCBERR_NOFABRIC:
2622 case PLOGX_IOCBERR_NOTREADY:
2623 msg = "firmware not ready";
2625 case PLOGX_IOCBERR_NOLOGIN:
2626 ISP_SNPRINTF(buf, sizeof (buf), "not logged in (last state 0x%x)", parm1);
2628 rval = MBOX_NOT_LOGGED_IN;
2630 case PLOGX_IOCBERR_REJECT:
2631 ISP_SNPRINTF(buf, sizeof (buf), "LS_RJT = 0x%x", parm1);
2634 case PLOGX_IOCBERR_NOPCB:
2635 msg = "no PCB allocated";
2637 case PLOGX_IOCBERR_EINVAL:
2638 ISP_SNPRINTF(buf, sizeof (buf), "invalid parameter at offset 0x%x", parm1);
2641 case PLOGX_IOCBERR_PORTUSED:
2642 lev = ISP_LOG_SANCFG|ISP_LOG_WARN1;
2643 ISP_SNPRINTF(buf, sizeof (buf), "already logged in with N-Port handle 0x%x", parm1);
2645 rval = MBOX_PORT_ID_USED | (parm1 << 16);
2647 case PLOGX_IOCBERR_HNDLUSED:
2648 lev = ISP_LOG_SANCFG|ISP_LOG_WARN1;
2649 ISP_SNPRINTF(buf, sizeof (buf), "handle already used for PortID 0x%06x", parm1);
2651 rval = MBOX_LOOP_ID_USED;
2653 case PLOGX_IOCBERR_NOHANDLE:
2654 msg = "no handle allocated";
2656 case PLOGX_IOCBERR_NOFLOGI:
2657 msg = "no FLOGI_ACC";
2660 ISP_SNPRINTF(buf, sizeof (buf), "status %x from %x", pl.plogx_status, flags);
2665 isp_prt(isp, lev, "Chan %d PLOGX PortID 0x%06x to N-Port handle 0x%x: %s",
2666 chan, portid, handle, msg);
2672 isp_port_login(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2676 MBSINIT(&mbs, MBOX_FABRIC_LOGIN, MBLOGNONE, 500000);
2677 if (ISP_CAP_2KLOGIN(isp)) {
2678 mbs.param[1] = handle;
2679 mbs.ibits = (1 << 10);
2681 mbs.param[1] = handle << 8;
2683 mbs.param[2] = portid >> 16;
2684 mbs.param[3] = portid;
2685 mbs.logval = MBLOGNONE;
2686 mbs.timeout = 500000;
2687 isp_mboxcmd(isp, &mbs);
2689 switch (mbs.param[0]) {
2690 case MBOX_PORT_ID_USED:
2691 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "isp_port_login: portid 0x%06x already logged in as 0x%x", portid, mbs.param[1]);
2692 return (MBOX_PORT_ID_USED | (mbs.param[1] << 16));
2694 case MBOX_LOOP_ID_USED:
2695 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "isp_port_login: handle 0x%x in use for port id 0x%02xXXXX", handle, mbs.param[1] & 0xff);
2696 return (MBOX_LOOP_ID_USED);
2698 case MBOX_COMMAND_COMPLETE:
2701 case MBOX_COMMAND_ERROR:
2702 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "isp_port_login: error 0x%x in PLOGI to port 0x%06x", mbs.param[1], portid);
2703 return (MBOX_COMMAND_ERROR);
2705 case MBOX_ALL_IDS_USED:
2706 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "isp_port_login: all IDs used for fabric login");
2707 return (MBOX_ALL_IDS_USED);
2710 isp_prt(isp, ISP_LOG_SANCFG, "isp_port_login: error 0x%x on port login of 0x%06x@0x%0x", mbs.param[0], portid, handle);
2711 return (mbs.param[0]);
2716 * Pre-24XX fabric port logout
2718 * Note that portid is not used
2721 isp_port_logout(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2725 MBSINIT(&mbs, MBOX_FABRIC_LOGOUT, MBLOGNONE, 500000);
2726 if (ISP_CAP_2KLOGIN(isp)) {
2727 mbs.param[1] = handle;
2728 mbs.ibits = (1 << 10);
2730 mbs.param[1] = handle << 8;
2732 isp_mboxcmd(isp, &mbs);
2733 return (mbs.param[0] == MBOX_COMMAND_COMPLETE? 0 : mbs.param[0]);
2737 isp_getpdb(ispsoftc_t *isp, int chan, uint16_t id, isp_pdb_t *pdb)
2741 isp_pdb_21xx_t fred;
2742 isp_pdb_24xx_t bill;
2745 MBSINIT(&mbs, MBOX_GET_PORT_DB,
2746 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_PARAM_ERROR), 250000);
2748 mbs.ibits = (1 << 9)|(1 << 10);
2750 mbs.param[9] = chan;
2751 } else if (ISP_CAP_2KLOGIN(isp)) {
2754 mbs.param[1] = id << 8;
2756 mbs.param[2] = DMA_WD1(isp->isp_iocb_dma);
2757 mbs.param[3] = DMA_WD0(isp->isp_iocb_dma);
2758 mbs.param[6] = DMA_WD3(isp->isp_iocb_dma);
2759 mbs.param[7] = DMA_WD2(isp->isp_iocb_dma);
2760 MEMORYBARRIER(isp, SYNC_IFORDEV, 0, sizeof(un), chan);
2762 isp_mboxcmd(isp, &mbs);
2763 if (mbs.param[0] != MBOX_COMMAND_COMPLETE)
2764 return (mbs.param[0] | (mbs.param[1] << 16));
2766 MEMORYBARRIER(isp, SYNC_IFORCPU, 0, sizeof(un), chan);
2768 isp_get_pdb_24xx(isp, isp->isp_iocb, &un.bill);
2769 pdb->handle = un.bill.pdb_handle;
2770 pdb->prli_word3 = un.bill.pdb_prli_svc3;
2771 pdb->portid = BITS2WORD_24XX(un.bill.pdb_portid_bits);
2772 ISP_MEMCPY(pdb->portname, un.bill.pdb_portname, 8);
2773 ISP_MEMCPY(pdb->nodename, un.bill.pdb_nodename, 8);
2774 isp_prt(isp, ISP_LOGDEBUG1,
2775 "Chan %d handle 0x%x Port 0x%06x flags 0x%x curstate %x",
2776 chan, id, pdb->portid, un.bill.pdb_flags,
2777 un.bill.pdb_curstate);
2778 if (un.bill.pdb_curstate < PDB2400_STATE_PLOGI_DONE || un.bill.pdb_curstate > PDB2400_STATE_LOGGED_IN) {
2779 mbs.param[0] = MBOX_NOT_LOGGED_IN;
2780 return (mbs.param[0]);
2783 isp_get_pdb_21xx(isp, isp->isp_iocb, &un.fred);
2784 pdb->handle = un.fred.pdb_loopid;
2785 pdb->prli_word3 = un.fred.pdb_prli_svc3;
2786 pdb->portid = BITS2WORD(un.fred.pdb_portid_bits);
2787 ISP_MEMCPY(pdb->portname, un.fred.pdb_portname, 8);
2788 ISP_MEMCPY(pdb->nodename, un.fred.pdb_nodename, 8);
2789 isp_prt(isp, ISP_LOGDEBUG1,
2790 "Chan %d handle 0x%x Port 0x%06x", chan, id, pdb->portid);
2796 isp_gethandles(ispsoftc_t *isp, int chan, uint16_t *handles, int *num, int loop)
2798 fcparam *fcp = FCPARAM(isp, chan);
2800 isp_pnhle_21xx_t el1, *elp1;
2801 isp_pnhle_23xx_t el3, *elp3;
2802 isp_pnhle_24xx_t el4, *elp4;
2807 MBSINIT(&mbs, MBOX_GET_ID_LIST, MBLOGALL, 250000);
2809 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2810 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2811 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2812 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2813 mbs.param[8] = ISP_FC_SCRLEN;
2814 mbs.param[9] = chan;
2816 mbs.ibits = (1 << 1)|(1 << 2)|(1 << 3)|(1 << 6);
2817 mbs.param[1] = DMA_WD1(fcp->isp_scdma);
2818 mbs.param[2] = DMA_WD0(fcp->isp_scdma);
2819 mbs.param[3] = DMA_WD3(fcp->isp_scdma);
2820 mbs.param[6] = DMA_WD2(fcp->isp_scdma);
2822 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
2823 isp_prt(isp, ISP_LOGERR, sacq);
2826 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, ISP_FC_SCRLEN, chan);
2827 isp_mboxcmd(isp, &mbs);
2828 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2829 FC_SCRATCH_RELEASE(isp, chan);
2830 return (mbs.param[0] | (mbs.param[1] << 16));
2832 MEMORYBARRIER(isp, SYNC_SFORCPU, 0, ISP_FC_SCRLEN, chan);
2833 elp1 = fcp->isp_scratch;
2834 elp3 = fcp->isp_scratch;
2835 elp4 = fcp->isp_scratch;
2836 for (i = 0, j = 0; i < mbs.param[1] && j < *num; i++) {
2838 isp_get_pnhle_24xx(isp, &elp4[i], &el4);
2839 p = el4.pnhle_port_id_lo |
2840 (el4.pnhle_port_id_hi << 16);
2841 h = el4.pnhle_handle;
2842 } else if (IS_23XX(isp)) {
2843 isp_get_pnhle_23xx(isp, &elp3[i], &el3);
2844 p = el3.pnhle_port_id_lo |
2845 (el3.pnhle_port_id_hi << 16);
2846 h = el3.pnhle_handle;
2848 isp_get_pnhle_21xx(isp, &elp1[i], &el1);
2849 p = el1.pnhle_port_id_lo |
2850 ((el1.pnhle_port_id_hi_handle & 0xff) << 16);
2851 h = el1.pnhle_port_id_hi_handle >> 8;
2853 if (loop && (p >> 8) != (fcp->isp_portid >> 8))
2858 FC_SCRATCH_RELEASE(isp, chan);
2863 isp_dump_chip_portdb(ispsoftc_t *isp, int chan)
2866 uint16_t lim, nphdl;
2868 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGINFO, "Chan %d chip port dump", chan);
2869 if (ISP_CAP_2KLOGIN(isp)) {
2874 for (nphdl = 0; nphdl != lim; nphdl++) {
2875 if (isp_getpdb(isp, chan, nphdl, &pdb)) {
2878 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGINFO, "Chan %d Handle 0x%04x "
2879 "PortID 0x%06x WWPN 0x%02x%02x%02x%02x%02x%02x%02x%02x",
2880 chan, nphdl, pdb.portid, pdb.portname[0], pdb.portname[1],
2881 pdb.portname[2], pdb.portname[3], pdb.portname[4],
2882 pdb.portname[5], pdb.portname[6], pdb.portname[7]);
2887 isp_get_wwn(ispsoftc_t *isp, int chan, int nphdl, int nodename)
2889 uint64_t wwn = INI_NONE;
2892 MBSINIT(&mbs, MBOX_GET_PORT_NAME,
2893 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_PARAM_ERROR), 500000);
2894 if (ISP_CAP_2KLOGIN(isp)) {
2895 mbs.param[1] = nphdl;
2899 mbs.param[9] = chan;
2902 mbs.param[1] = nphdl << 8;
2907 isp_mboxcmd(isp, &mbs);
2908 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2913 (((uint64_t)(mbs.param[2] >> 8)) << 56) |
2914 (((uint64_t)(mbs.param[2] & 0xff)) << 48) |
2915 (((uint64_t)(mbs.param[3] >> 8)) << 40) |
2916 (((uint64_t)(mbs.param[3] & 0xff)) << 32) |
2917 (((uint64_t)(mbs.param[6] >> 8)) << 24) |
2918 (((uint64_t)(mbs.param[6] & 0xff)) << 16) |
2919 (((uint64_t)(mbs.param[7] >> 8)) << 8) |
2920 (((uint64_t)(mbs.param[7] & 0xff)));
2923 (((uint64_t)(mbs.param[2] & 0xff)) << 56) |
2924 (((uint64_t)(mbs.param[2] >> 8)) << 48) |
2925 (((uint64_t)(mbs.param[3] & 0xff)) << 40) |
2926 (((uint64_t)(mbs.param[3] >> 8)) << 32) |
2927 (((uint64_t)(mbs.param[6] & 0xff)) << 24) |
2928 (((uint64_t)(mbs.param[6] >> 8)) << 16) |
2929 (((uint64_t)(mbs.param[7] & 0xff)) << 8) |
2930 (((uint64_t)(mbs.param[7] >> 8)));
2936 * Make sure we have good FC link.
2940 isp_fclink_test(ispsoftc_t *isp, int chan, int usdelay)
2947 NANOTIME_T hra, hrb;
2949 fcp = FCPARAM(isp, chan);
2951 if (fcp->isp_loopstate < LOOP_HAVE_LINK)
2953 if (fcp->isp_loopstate >= LOOP_LTEST_DONE)
2956 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC link test", chan);
2959 * Wait up to N microseconds for F/W to go to a ready state.
2963 isp_change_fw_state(isp, chan, isp_fw_state(isp, chan));
2964 if (fcp->isp_fwstate == FW_READY) {
2967 if (fcp->isp_loopstate < LOOP_HAVE_LINK)
2970 if ((NANOTIME_SUB(&hrb, &hra) / 1000 + 1000 >= usdelay))
2972 ISP_SLEEP(isp, 1000);
2974 if (fcp->isp_fwstate != FW_READY) {
2975 isp_prt(isp, ISP_LOG_SANCFG,
2976 "Chan %d Firmware is not ready (%s)",
2977 chan, isp_fc_fw_statename(fcp->isp_fwstate));
2982 * Get our Loop ID and Port ID.
2984 MBSINIT(&mbs, MBOX_GET_LOOP_ID, MBLOGALL, 0);
2985 mbs.param[9] = chan;
2986 isp_mboxcmd(isp, &mbs);
2987 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2993 * Don't bother with fabric if we are using really old
2994 * 2100 firmware. It's just not worth it.
2996 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37))
2997 fcp->isp_topo = TOPO_FL_PORT;
2999 fcp->isp_topo = TOPO_NL_PORT;
3001 int topo = (int) mbs.param[6];
3002 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB) {
3003 topo = TOPO_PTP_STUB;
3005 fcp->isp_topo = topo;
3007 fcp->isp_portid = mbs.param[2] | (mbs.param[3] << 16);
3009 if (!TOPO_IS_FABRIC(fcp->isp_topo)) {
3010 fcp->isp_loopid = mbs.param[1] & 0xff;
3011 } else if (fcp->isp_topo != TOPO_F_PORT) {
3012 uint8_t alpa = fcp->isp_portid;
3014 for (i = 0; alpa_map[i]; i++) {
3015 if (alpa_map[i] == alpa)
3019 fcp->isp_loopid = i;
3023 fcp->isp_loopstate = LOOP_HAVE_ADDR;
3025 fcp->isp_loopstate = LOOP_TESTING_LINK;
3027 if (fcp->isp_topo == TOPO_F_PORT || fcp->isp_topo == TOPO_FL_PORT) {
3028 nphdl = IS_24XX(isp) ? NPH_FL_ID : FL_ID;
3029 r = isp_getpdb(isp, chan, nphdl, &pdb);
3030 if (r != 0 || pdb.portid == 0) {
3032 fcp->isp_topo = TOPO_NL_PORT;
3034 isp_prt(isp, ISP_LOGWARN,
3035 "fabric topology, but cannot get info about fabric controller (0x%x)", r);
3036 fcp->isp_topo = TOPO_PTP_STUB;
3042 fcp->isp_fabric_params = mbs.param[7];
3043 fcp->isp_sns_hdl = NPH_SNS_ID;
3044 r = isp_register_fc4_type_24xx(isp, chan);
3045 if (fcp->isp_loopstate < LOOP_TESTING_LINK)
3049 r = isp_register_fc4_features_24xx(isp, chan);
3050 if (fcp->isp_loopstate < LOOP_TESTING_LINK)
3054 r = isp_register_port_name_24xx(isp, chan);
3055 if (fcp->isp_loopstate < LOOP_TESTING_LINK)
3059 isp_register_node_name_24xx(isp, chan);
3060 if (fcp->isp_loopstate < LOOP_TESTING_LINK)
3063 fcp->isp_sns_hdl = SNS_ID;
3064 r = isp_register_fc4_type(isp, chan);
3067 if (fcp->role == ISP_ROLE_TARGET)
3068 isp_send_change_request(isp, chan);
3073 /* Get link speed. */
3074 fcp->isp_gbspeed = 1;
3075 if (IS_23XX(isp) || IS_24XX(isp)) {
3076 MBSINIT(&mbs, MBOX_GET_SET_DATA_RATE, MBLOGALL, 3000000);
3077 mbs.param[1] = MBGSD_GET_RATE;
3078 /* mbs.param[2] undefined if we're just getting rate */
3079 isp_mboxcmd(isp, &mbs);
3080 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3081 if (mbs.param[1] == MBGSD_10GB)
3082 fcp->isp_gbspeed = 10;
3083 else if (mbs.param[1] == MBGSD_16GB)
3084 fcp->isp_gbspeed = 16;
3085 else if (mbs.param[1] == MBGSD_8GB)
3086 fcp->isp_gbspeed = 8;
3087 else if (mbs.param[1] == MBGSD_4GB)
3088 fcp->isp_gbspeed = 4;
3089 else if (mbs.param[1] == MBGSD_2GB)
3090 fcp->isp_gbspeed = 2;
3091 else if (mbs.param[1] == MBGSD_1GB)
3092 fcp->isp_gbspeed = 1;
3096 if (fcp->isp_loopstate < LOOP_TESTING_LINK) {
3098 isp_prt(isp, ISP_LOG_SANCFG,
3099 "Chan %d FC link test aborted", chan);
3102 fcp->isp_loopstate = LOOP_LTEST_DONE;
3103 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGCONFIG,
3104 "Chan %d WWPN %016jx WWNN %016jx",
3105 chan, (uintmax_t)fcp->isp_wwpn, (uintmax_t)fcp->isp_wwnn);
3106 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGCONFIG,
3107 "Chan %d %dGb %s PortID 0x%06x LoopID 0x%02x",
3108 chan, fcp->isp_gbspeed, isp_fc_toponame(fcp), fcp->isp_portid,
3110 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC link test done", chan);
3115 * Complete the synchronization of our Port Database.
3117 * At this point, we've scanned the local loop (if any) and the fabric
3118 * and performed fabric logins on all new devices.
3120 * Our task here is to go through our port database removing any entities
3121 * that are still marked probational (issuing PLOGO for ones which we had
3122 * PLOGI'd into) or are dead, and notifying upper layers about new/changed
3126 isp_pdb_sync(ispsoftc_t *isp, int chan)
3128 fcparam *fcp = FCPARAM(isp, chan);
3132 if (fcp->isp_loopstate < LOOP_FSCAN_DONE)
3134 if (fcp->isp_loopstate >= LOOP_READY)
3137 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC PDB sync", chan);
3139 fcp->isp_loopstate = LOOP_SYNCING_PDB;
3141 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
3142 lp = &fcp->portdb[dbidx];
3144 if (lp->state == FC_PORTDB_STATE_NIL)
3146 if (lp->probational && lp->state != FC_PORTDB_STATE_ZOMBIE)
3147 lp->state = FC_PORTDB_STATE_DEAD;
3148 switch (lp->state) {
3149 case FC_PORTDB_STATE_DEAD:
3150 lp->state = FC_PORTDB_STATE_NIL;
3151 isp_async(isp, ISPASYNC_DEV_GONE, chan, lp);
3152 if ((lp->portid & 0xffff00) != 0) {
3153 (void) isp_plogx(isp, chan, lp->handle,
3155 PLOGX_FLG_CMD_LOGO |
3156 PLOGX_FLG_IMPLICIT |
3157 PLOGX_FLG_FREE_NPHDL);
3160 * Note that we might come out of this with our state
3161 * set to FC_PORTDB_STATE_ZOMBIE.
3164 case FC_PORTDB_STATE_NEW:
3165 lp->state = FC_PORTDB_STATE_VALID;
3166 isp_async(isp, ISPASYNC_DEV_ARRIVED, chan, lp);
3168 case FC_PORTDB_STATE_CHANGED:
3169 lp->state = FC_PORTDB_STATE_VALID;
3170 isp_async(isp, ISPASYNC_DEV_CHANGED, chan, lp);
3171 lp->portid = lp->new_portid;
3172 lp->prli_word3 = lp->new_prli_word3;
3174 case FC_PORTDB_STATE_VALID:
3175 isp_async(isp, ISPASYNC_DEV_STAYED, chan, lp);
3177 case FC_PORTDB_STATE_ZOMBIE:
3180 isp_prt(isp, ISP_LOGWARN,
3181 "isp_pdb_sync: state %d for idx %d",
3183 isp_dump_portdb(isp, chan);
3187 if (fcp->isp_loopstate < LOOP_SYNCING_PDB) {
3188 isp_prt(isp, ISP_LOG_SANCFG,
3189 "Chan %d FC PDB sync aborted", chan);
3193 fcp->isp_loopstate = LOOP_READY;
3194 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC PDB sync done", chan);
3199 isp_pdb_add_update(ispsoftc_t *isp, int chan, isp_pdb_t *pdb)
3202 uint64_t wwnn, wwpn;
3204 MAKE_WWN_FROM_NODE_NAME(wwnn, pdb->nodename);
3205 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb->portname);
3207 /* Search port database for the same WWPN. */
3208 if (isp_find_pdb_by_wwpn(isp, chan, wwpn, &lp)) {
3209 if (!lp->probational) {
3210 isp_prt(isp, ISP_LOGERR,
3211 "Chan %d Port 0x%06x@0x%04x [%d] is not probational (0x%x)",
3212 chan, lp->portid, lp->handle,
3213 FC_PORTDB_TGT(isp, chan, lp), lp->state);
3214 isp_dump_portdb(isp, chan);
3217 lp->probational = 0;
3218 lp->node_wwn = wwnn;
3220 /* Old device, nothing new. */
3221 if (lp->portid == pdb->portid &&
3222 lp->handle == pdb->handle &&
3223 lp->prli_word3 == pdb->prli_word3) {
3224 if (lp->state != FC_PORTDB_STATE_NEW)
3225 lp->state = FC_PORTDB_STATE_VALID;
3226 isp_prt(isp, ISP_LOG_SANCFG,
3227 "Chan %d Port 0x%06x@0x%04x is valid",
3228 chan, pdb->portid, pdb->handle);
3232 /* Something has changed. */
3233 lp->state = FC_PORTDB_STATE_CHANGED;
3234 lp->handle = pdb->handle;
3235 lp->new_portid = pdb->portid;
3236 lp->new_prli_word3 = pdb->prli_word3;
3237 isp_prt(isp, ISP_LOG_SANCFG,
3238 "Chan %d Port 0x%06x@0x%04x is changed",
3239 chan, pdb->portid, pdb->handle);
3243 /* It seems like a new port. Find an empty slot for it. */
3244 if (!isp_find_pdb_empty(isp, chan, &lp)) {
3245 isp_prt(isp, ISP_LOGERR, "Chan %d out of portdb entries", chan);
3249 ISP_MEMZERO(lp, sizeof (fcportdb_t));
3250 lp->probational = 0;
3251 lp->state = FC_PORTDB_STATE_NEW;
3252 lp->portid = lp->new_portid = pdb->portid;
3253 lp->prli_word3 = lp->new_prli_word3 = pdb->prli_word3;
3254 lp->handle = pdb->handle;
3255 lp->port_wwn = wwpn;
3256 lp->node_wwn = wwnn;
3257 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Port 0x%06x@0x%04x is new",
3258 chan, pdb->portid, pdb->handle);
3262 * Fix port IDs for logged-in initiators on pre-2400 chips.
3263 * For those chips we are not receiving login events, adding initiators
3264 * based on ATIO requests, but there is no port ID in that structure.
3267 isp_fix_portids(ispsoftc_t *isp, int chan)
3269 fcparam *fcp = FCPARAM(isp, chan);
3274 for (i = 0; i < MAX_FC_TARG; i++) {
3275 fcportdb_t *lp = &fcp->portdb[i];
3277 if (lp->state == FC_PORTDB_STATE_NIL ||
3278 lp->state == FC_PORTDB_STATE_ZOMBIE)
3280 if (VALID_PORT(lp->portid))
3283 r = isp_getpdb(isp, chan, lp->handle, &pdb);
3284 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3287 isp_prt(isp, ISP_LOGDEBUG1,
3288 "Chan %d FC Scan Loop handle %d returned %x",
3289 chan, lp->handle, r);
3293 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb.portname);
3294 if (lp->port_wwn != wwpn)
3296 lp->portid = lp->new_portid = pdb.portid;
3297 isp_prt(isp, ISP_LOG_SANCFG,
3298 "Chan %d Port 0x%06x@0x%04x is fixed",
3299 chan, pdb.portid, pdb.handle);
3304 * Scan local loop for devices.
3307 isp_scan_loop(ispsoftc_t *isp, int chan)
3309 fcparam *fcp = FCPARAM(isp, chan);
3315 if (fcp->isp_loopstate < LOOP_LTEST_DONE)
3317 if (fcp->isp_loopstate >= LOOP_LSCAN_DONE)
3320 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC loop scan", chan);
3321 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
3322 if (TOPO_IS_FABRIC(fcp->isp_topo)) {
3323 if (!IS_24XX(isp)) {
3324 isp_fix_portids(isp, chan);
3325 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3328 isp_prt(isp, ISP_LOG_SANCFG,
3329 "Chan %d FC loop scan done (no loop)", chan);
3330 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3334 handles = (uint16_t *)fcp->isp_scanscratch;
3335 lim = ISP_FC_SCRLEN / 2;
3336 r = isp_gethandles(isp, chan, handles, &lim, 1);
3338 isp_prt(isp, ISP_LOG_SANCFG,
3339 "Chan %d Getting list of handles failed with %x", chan, r);
3340 isp_prt(isp, ISP_LOG_SANCFG,
3341 "Chan %d FC loop scan done (bad)", chan);
3345 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Got %d handles",
3349 * Run through the list and get the port database info for each one.
3351 isp_mark_portdb(isp, chan);
3352 for (idx = 0; idx < lim; idx++) {
3353 handle = handles[idx];
3356 * Don't scan "special" ids.
3358 if (ISP_CAP_2KLOGIN(isp)) {
3359 if (handle >= NPH_RESERVED)
3362 if (handle >= FL_ID && handle <= SNS_ID)
3367 * In older cards with older f/w GET_PORT_DATABASE has been
3368 * known to hang. This trick gets around that problem.
3370 if (IS_2100(isp) || IS_2200(isp)) {
3371 uint64_t node_wwn = isp_get_wwn(isp, chan, handle, 1);
3372 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
3374 isp_prt(isp, ISP_LOG_SANCFG,
3375 "Chan %d FC loop scan aborted", chan);
3378 if (node_wwn == INI_NONE) {
3384 * Get the port database entity for this index.
3386 r = isp_getpdb(isp, chan, handle, &pdb);
3387 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3390 isp_prt(isp, ISP_LOGDEBUG1,
3391 "Chan %d FC Scan Loop handle %d returned %x",
3396 isp_pdb_add_update(isp, chan, &pdb);
3398 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3400 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3401 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC loop scan done", chan);
3406 * Scan the fabric for devices and add them to our port database.
3408 * Use the GID_FT command to get all Port IDs for FC4 SCSI devices it knows.
3410 * For 2100-23XX cards, we use the SNS mailbox command to pass simple name
3411 * server commands to the switch management server via the QLogic f/w.
3413 * For the 24XX and above card, we use CT Pass-through IOCB.
3415 #define GIDLEN ISP_FC_SCRLEN
3416 #define NGENT ((GIDLEN - 16) >> 2)
3419 isp_gid_ft_sns(ispsoftc_t *isp, int chan)
3422 sns_gid_ft_req_t _x;
3423 uint8_t _y[SNS_GID_FT_REQ_SIZE];
3425 fcparam *fcp = FCPARAM(isp, chan);
3426 sns_gid_ft_req_t *rq = &un._x;
3427 uint8_t *scp = fcp->isp_scratch;
3430 isp_prt(isp, ISP_LOGDEBUG0, "Chan %d requesting GID_FT via SNS", chan);
3431 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3432 isp_prt(isp, ISP_LOGERR, sacq);
3436 ISP_MEMZERO(rq, SNS_GID_FT_REQ_SIZE);
3437 rq->snscb_rblen = GIDLEN >> 1;
3438 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma);
3439 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma);
3440 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma);
3441 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma);
3442 rq->snscb_sblen = 6;
3443 rq->snscb_cmd = SNS_GID_FT;
3444 rq->snscb_mword_div_2 = NGENT;
3445 rq->snscb_fc4_type = FC4_SCSI;
3447 isp_put_gid_ft_request(isp, rq, (sns_gid_ft_req_t *)scp);
3448 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE, chan);
3450 MBSINIT(&mbs, MBOX_SEND_SNS, MBLOGALL, 10000000);
3451 mbs.param[0] = MBOX_SEND_SNS;
3452 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
3453 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
3454 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
3455 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
3456 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
3457 isp_mboxcmd(isp, &mbs);
3458 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3459 if (mbs.param[0] == MBOX_INVALID_COMMAND) {
3465 MEMORYBARRIER(isp, SYNC_SFORCPU, 0, GIDLEN, chan);
3466 if (isp->isp_dblev & ISP_LOGDEBUG1)
3467 isp_print_bytes(isp, "CT response", GIDLEN, scp);
3468 isp_get_gid_ft_response(isp, (sns_gid_ft_rsp_t *)scp,
3469 (sns_gid_ft_rsp_t *)fcp->isp_scanscratch, NGENT);
3470 FC_SCRATCH_RELEASE(isp, chan);
3475 isp_ct_passthru(ispsoftc_t *isp, int chan, uint32_t cmd_bcnt, uint32_t rsp_bcnt)
3477 fcparam *fcp = FCPARAM(isp, chan);
3480 uint8_t resp[QENTRY_LEN];
3483 * Build a Passthrough IOCB in memory.
3485 ISP_MEMZERO(&pt, sizeof(pt));
3486 pt.ctp_header.rqs_entry_count = 1;
3487 pt.ctp_header.rqs_entry_type = RQSTYPE_CT_PASSTHRU;
3488 pt.ctp_nphdl = fcp->isp_sns_hdl;
3490 pt.ctp_vpidx = ISP_GET_VPIDX(isp, chan);
3493 pt.ctp_rsp_bcnt = rsp_bcnt;
3494 pt.ctp_cmd_bcnt = cmd_bcnt;
3495 pt.ctp_dataseg[0].ds_base = DMA_LO32(fcp->isp_scdma);
3496 pt.ctp_dataseg[0].ds_basehi = DMA_HI32(fcp->isp_scdma);
3497 pt.ctp_dataseg[0].ds_count = cmd_bcnt;
3498 pt.ctp_dataseg[1].ds_base = DMA_LO32(fcp->isp_scdma);
3499 pt.ctp_dataseg[1].ds_basehi = DMA_HI32(fcp->isp_scdma);
3500 pt.ctp_dataseg[1].ds_count = rsp_bcnt;
3502 /* Prepare space for response in memory */
3503 memset(resp, 0xff, sizeof(resp));
3504 pt.ctp_handle = isp_allocate_handle(isp, resp, ISP_HANDLE_CTRL);
3505 if (pt.ctp_handle == 0) {
3506 isp_prt(isp, ISP_LOGERR,
3507 "%s: CTP of Chan %d out of handles", __func__, chan);
3511 /* Send request and wait for response. */
3512 reqp = isp_getrqentry(isp);
3514 isp_prt(isp, ISP_LOGERR,
3515 "%s: CTP of Chan %d out of rqent", __func__, chan);
3516 isp_destroy_handle(isp, pt.ctp_handle);
3519 isp_put_ct_pt(isp, &pt, (isp_ct_pt_t *)reqp);
3520 if (isp->isp_dblev & ISP_LOGDEBUG1)
3521 isp_print_bytes(isp, "CT IOCB request", QENTRY_LEN, reqp);
3522 ISP_SYNC_REQUEST(isp);
3523 if (msleep(resp, &isp->isp_lock, 0, "CTP", pt.ctp_time*hz) == EWOULDBLOCK) {
3524 isp_prt(isp, ISP_LOGERR,
3525 "%s: CTP of Chan %d timed out", __func__, chan);
3526 isp_destroy_handle(isp, pt.ctp_handle);
3529 if (isp->isp_dblev & ISP_LOGDEBUG1)
3530 isp_print_bytes(isp, "CT IOCB response", QENTRY_LEN, resp);
3532 isp_get_ct_pt(isp, (isp_ct_pt_t *)resp, &pt);
3533 if (pt.ctp_status && pt.ctp_status != RQCS_DATA_UNDERRUN) {
3534 isp_prt(isp, ISP_LOGWARN,
3535 "Chan %d GID_FT CT Passthrough returned 0x%x",
3536 chan, pt.ctp_status);
3544 isp_gid_ft_ct_passthru(ispsoftc_t *isp, int chan)
3546 fcparam *fcp = FCPARAM(isp, chan);
3549 uint8_t *scp = fcp->isp_scratch;
3551 isp_prt(isp, ISP_LOGDEBUG0, "Chan %d requesting GID_FT via CT", chan);
3552 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3553 isp_prt(isp, ISP_LOGERR, sacq);
3558 * Build the CT header and command in memory.
3560 ISP_MEMZERO(&ct, sizeof (ct));
3561 ct.ct_revision = CT_REVISION;
3562 ct.ct_fcs_type = CT_FC_TYPE_FC;
3563 ct.ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3564 ct.ct_cmd_resp = SNS_GID_FT;
3565 ct.ct_bcnt_resid = (GIDLEN - 16) >> 2;
3566 isp_put_ct_hdr(isp, &ct, (ct_hdr_t *)scp);
3567 rp = (uint32_t *) &scp[sizeof(ct)];
3568 ISP_IOZPUT_32(isp, FC4_SCSI, rp);
3569 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3570 isp_print_bytes(isp, "CT request",
3571 sizeof(ct) + sizeof(uint32_t), scp);
3574 if (isp_ct_passthru(isp, chan, sizeof(ct) + sizeof(uint32_t), GIDLEN)) {
3575 FC_SCRATCH_RELEASE(isp, chan);
3579 if (isp->isp_dblev & ISP_LOGDEBUG1)
3580 isp_print_bytes(isp, "CT response", GIDLEN, scp);
3581 isp_get_gid_ft_response(isp, (sns_gid_ft_rsp_t *)scp,
3582 (sns_gid_ft_rsp_t *)fcp->isp_scanscratch, NGENT);
3583 FC_SCRATCH_RELEASE(isp, chan);
3588 isp_scan_fabric(ispsoftc_t *isp, int chan)
3590 fcparam *fcp = FCPARAM(isp, chan);
3595 int portidx, portlim, r;
3596 sns_gid_ft_rsp_t *rs;
3598 if (fcp->isp_loopstate < LOOP_LSCAN_DONE)
3600 if (fcp->isp_loopstate >= LOOP_FSCAN_DONE)
3603 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC fabric scan", chan);
3604 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
3605 if (!TOPO_IS_FABRIC(fcp->isp_topo)) {
3606 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3607 isp_prt(isp, ISP_LOG_SANCFG,
3608 "Chan %d FC fabric scan done (no fabric)", chan);
3612 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC) {
3614 FC_SCRATCH_RELEASE(isp, chan);
3615 isp_prt(isp, ISP_LOG_SANCFG,
3616 "Chan %d FC fabric scan aborted", chan);
3621 * Make sure we still are logged into the fabric controller.
3623 nphdl = IS_24XX(isp) ? NPH_FL_ID : FL_ID;
3624 r = isp_getpdb(isp, chan, nphdl, &pdb);
3625 if ((r & 0xffff) == MBOX_NOT_LOGGED_IN) {
3626 isp_dump_chip_portdb(isp, chan);
3629 fcp->isp_loopstate = LOOP_LTEST_DONE;
3631 isp_prt(isp, ISP_LOG_SANCFG,
3632 "Chan %d FC fabric scan done (bad)", chan);
3636 /* Get list of port IDs from SNS. */
3638 r = isp_gid_ft_ct_passthru(isp, chan);
3640 r = isp_gid_ft_sns(isp, chan);
3641 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3644 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3647 fcp->isp_loopstate = LOOP_LTEST_DONE; /* try again */
3651 rs = (sns_gid_ft_rsp_t *) fcp->isp_scanscratch;
3652 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3654 if (rs->snscb_cthdr.ct_cmd_resp != LS_ACC) {
3656 if (rs->snscb_cthdr.ct_reason == 9 && rs->snscb_cthdr.ct_explanation == 7) {
3657 level = ISP_LOG_SANCFG;
3659 level = ISP_LOGWARN;
3661 isp_prt(isp, level, "Chan %d Fabric Nameserver rejected GID_FT"
3662 " (Reason=0x%x Expl=0x%x)", chan,
3663 rs->snscb_cthdr.ct_reason,
3664 rs->snscb_cthdr.ct_explanation);
3665 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3669 /* Check our buffer was big enough to get the full list. */
3670 for (portidx = 0; portidx < NGENT-1; portidx++) {
3671 if (rs->snscb_ports[portidx].control & 0x80)
3674 if ((rs->snscb_ports[portidx].control & 0x80) == 0) {
3675 isp_prt(isp, ISP_LOGWARN,
3676 "fabric too big for scratch area: increase ISP_FC_SCRLEN");
3678 portlim = portidx + 1;
3679 isp_prt(isp, ISP_LOG_SANCFG,
3680 "Chan %d Got %d ports back from name server", chan, portlim);
3682 /* Go through the list and remove duplicate port ids. */
3683 for (portidx = 0; portidx < portlim; portidx++) {
3687 ((rs->snscb_ports[portidx].portid[0]) << 16) |
3688 ((rs->snscb_ports[portidx].portid[1]) << 8) |
3689 ((rs->snscb_ports[portidx].portid[2]));
3691 for (npidx = portidx + 1; npidx < portlim; npidx++) {
3692 uint32_t new_portid =
3693 ((rs->snscb_ports[npidx].portid[0]) << 16) |
3694 ((rs->snscb_ports[npidx].portid[1]) << 8) |
3695 ((rs->snscb_ports[npidx].portid[2]));
3696 if (new_portid == portid) {
3701 if (npidx < portlim) {
3702 rs->snscb_ports[npidx].portid[0] = 0;
3703 rs->snscb_ports[npidx].portid[1] = 0;
3704 rs->snscb_ports[npidx].portid[2] = 0;
3705 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d removing duplicate PortID 0x%06x entry from list", chan, portid);
3710 * We now have a list of Port IDs for all FC4 SCSI devices
3711 * that the Fabric Name server knows about.
3713 * For each entry on this list go through our port database looking
3714 * for probational entries- if we find one, then an old entry is
3715 * maybe still this one. We get some information to find out.
3717 * Otherwise, it's a new fabric device, and we log into it
3718 * (unconditionally). After searching the entire database
3719 * again to make sure that we never ever ever ever have more
3720 * than one entry that has the same PortID or the same
3721 * WWNN/WWPN duple, we enter the device into our database.
3723 isp_mark_portdb(isp, chan);
3724 for (portidx = 0; portidx < portlim; portidx++) {
3725 portid = ((rs->snscb_ports[portidx].portid[0]) << 16) |
3726 ((rs->snscb_ports[portidx].portid[1]) << 8) |
3727 ((rs->snscb_ports[portidx].portid[2]));
3728 isp_prt(isp, ISP_LOG_SANCFG,
3729 "Chan %d Checking fabric port 0x%06x", chan, portid);
3731 isp_prt(isp, ISP_LOG_SANCFG,
3732 "Chan %d Port at idx %d is zero",
3736 if (portid == fcp->isp_portid) {
3737 isp_prt(isp, ISP_LOG_SANCFG,
3738 "Chan %d Port 0x%06x is our", chan, portid);
3742 /* Now search the entire port database for the same portid. */
3743 if (isp_find_pdb_by_portid(isp, chan, portid, &lp)) {
3744 if (!lp->probational) {
3745 isp_prt(isp, ISP_LOGERR,
3746 "Chan %d Port 0x%06x@0x%04x [%d] is not probational (0x%x)",
3747 chan, lp->portid, lp->handle,
3748 FC_PORTDB_TGT(isp, chan, lp), lp->state);
3749 isp_dump_portdb(isp, chan);
3753 if (lp->state == FC_PORTDB_STATE_ZOMBIE)
3757 * See if we're still logged into it.
3759 * If we aren't, mark it as a dead device and
3760 * leave the new portid in the database entry
3761 * for somebody further along to decide what to
3762 * do (policy choice).
3764 * If we are, check to see if it's the same
3765 * device still (it should be). If for some
3766 * reason it isn't, mark it as a changed device
3767 * and leave the new portid and role in the
3768 * database entry for somebody further along to
3769 * decide what to do (policy choice).
3771 r = isp_getpdb(isp, chan, lp->handle, &pdb);
3772 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3775 lp->state = FC_PORTDB_STATE_DEAD;
3776 isp_prt(isp, ISP_LOG_SANCFG,
3777 "Chan %d Port 0x%06x handle 0x%x is dead (%d)",
3778 chan, portid, lp->handle, r);
3782 isp_pdb_add_update(isp, chan, &pdb);
3787 if ((fcp->role & ISP_ROLE_INITIATOR) == 0) {
3788 isp_prt(isp, ISP_LOG_SANCFG,
3789 "Chan %d Port 0x%06x is not logged in", chan, portid);
3793 if (isp_login_device(isp, chan, portid, &pdb,
3794 &FCPARAM(isp, 0)->isp_lasthdl)) {
3795 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3800 isp_pdb_add_update(isp, chan, &pdb);
3803 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3805 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3806 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC fabric scan done", chan);
3811 * Find an unused handle and try and use to login to a port.
3814 isp_login_device(ispsoftc_t *isp, int chan, uint32_t portid, isp_pdb_t *p, uint16_t *ohp)
3819 if (ISP_CAP_2KLOGIN(isp)) {
3825 handle = isp_next_handle(isp, ohp);
3826 for (i = 0; i < lim; i++) {
3827 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
3830 /* Check if this handle is free. */
3831 r = isp_getpdb(isp, chan, handle, p);
3833 if (p->portid != portid) {
3834 /* This handle is busy, try next one. */
3835 handle = isp_next_handle(isp, ohp);
3840 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
3844 * Now try and log into the device
3846 r = isp_plogx(isp, chan, handle, portid, PLOGX_FLG_CMD_PLOGI);
3849 } else if ((r & 0xffff) == MBOX_PORT_ID_USED) {
3851 * If we get here, then the firmwware still thinks we're logged into this device, but with a different
3852 * handle. We need to break that association. We used to try and just substitute the handle, but then
3853 * failed to get any data via isp_getpdb (below).
3855 if (isp_plogx(isp, chan, r >> 16, portid, PLOGX_FLG_CMD_LOGO | PLOGX_FLG_IMPLICIT | PLOGX_FLG_FREE_NPHDL)) {
3856 isp_prt(isp, ISP_LOGERR, "baw... logout of %x failed", r >> 16);
3858 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
3860 r = isp_plogx(isp, chan, handle, portid, PLOGX_FLG_CMD_PLOGI);
3864 } else if ((r & 0xffff) == MBOX_LOOP_ID_USED) {
3865 /* Try the next handle. */
3866 handle = isp_next_handle(isp, ohp);
3875 isp_prt(isp, ISP_LOGWARN, "Chan %d PLOGI 0x%06x failed", chan, portid);
3880 * If we successfully logged into it, get the PDB for it
3881 * so we can crosscheck that it is still what we think it
3882 * is and that we also have the role it plays
3884 r = isp_getpdb(isp, chan, handle, p);
3886 isp_prt(isp, ISP_LOGERR, "Chan %d new device 0x%06x@0x%x disappeared", chan, portid, handle);
3890 if (p->handle != handle || p->portid != portid) {
3891 isp_prt(isp, ISP_LOGERR, "Chan %d new device 0x%06x@0x%x changed (0x%06x@0x%0x)",
3892 chan, portid, handle, p->portid, p->handle);
3899 isp_send_change_request(ispsoftc_t *isp, int chan)
3903 MBSINIT(&mbs, MBOX_SEND_CHANGE_REQUEST, MBLOGALL, 500000);
3904 mbs.param[1] = 0x03;
3905 mbs.param[9] = chan;
3906 isp_mboxcmd(isp, &mbs);
3907 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3910 isp_prt(isp, ISP_LOGWARN, "Chan %d Send Change Request: 0x%x",
3911 chan, mbs.param[0]);
3917 isp_register_fc4_type(ispsoftc_t *isp, int chan)
3919 fcparam *fcp = FCPARAM(isp, chan);
3920 uint8_t local[SNS_RFT_ID_REQ_SIZE];
3921 sns_screq_t *reqp = (sns_screq_t *) local;
3924 ISP_MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
3925 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
3926 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
3927 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
3928 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
3929 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
3930 reqp->snscb_sblen = 22;
3931 reqp->snscb_data[0] = SNS_RFT_ID;
3932 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
3933 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
3934 reqp->snscb_data[6] = (1 << FC4_SCSI);
3935 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3936 isp_prt(isp, ISP_LOGERR, sacq);
3939 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
3940 MBSINIT(&mbs, MBOX_SEND_SNS, MBLOGALL, 1000000);
3941 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
3942 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
3943 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
3944 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
3945 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
3946 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_RFT_ID_REQ_SIZE, chan);
3947 isp_mboxcmd(isp, &mbs);
3948 FC_SCRATCH_RELEASE(isp, chan);
3949 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3952 isp_prt(isp, ISP_LOGWARN, "Chan %d Register FC4 Type: 0x%x",
3953 chan, mbs.param[0]);
3959 isp_register_fc4_type_24xx(ispsoftc_t *isp, int chan)
3961 fcparam *fcp = FCPARAM(isp, chan);
3964 uint8_t *scp = fcp->isp_scratch;
3966 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3967 isp_prt(isp, ISP_LOGERR, sacq);
3972 * Build the CT header and command in memory.
3974 ISP_MEMZERO(&rp, sizeof(rp));
3976 ct->ct_revision = CT_REVISION;
3977 ct->ct_fcs_type = CT_FC_TYPE_FC;
3978 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3979 ct->ct_cmd_resp = SNS_RFT_ID;
3980 ct->ct_bcnt_resid = (sizeof (rft_id_t) - sizeof (ct_hdr_t)) >> 2;
3981 rp.rftid_portid[0] = fcp->isp_portid >> 16;
3982 rp.rftid_portid[1] = fcp->isp_portid >> 8;
3983 rp.rftid_portid[2] = fcp->isp_portid;
3984 rp.rftid_fc4types[FC4_SCSI >> 5] = 1 << (FC4_SCSI & 0x1f);
3985 isp_put_rft_id(isp, &rp, (rft_id_t *)scp);
3986 if (isp->isp_dblev & ISP_LOGDEBUG1)
3987 isp_print_bytes(isp, "CT request", sizeof(rft_id_t), scp);
3989 if (isp_ct_passthru(isp, chan, sizeof(rft_id_t), sizeof(ct_hdr_t))) {
3990 FC_SCRATCH_RELEASE(isp, chan);
3994 isp_get_ct_hdr(isp, (ct_hdr_t *) scp, ct);
3995 FC_SCRATCH_RELEASE(isp, chan);
3996 if (ct->ct_cmd_resp == LS_RJT) {
3997 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "Chan %d Register FC4 Type rejected", chan);
3999 } else if (ct->ct_cmd_resp == LS_ACC) {
4000 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Register FC4 Type accepted", chan);
4002 isp_prt(isp, ISP_LOGWARN, "Chan %d Register FC4 Type: 0x%x", chan, ct->ct_cmd_resp);
4009 isp_register_fc4_features_24xx(ispsoftc_t *isp, int chan)
4011 fcparam *fcp = FCPARAM(isp, chan);
4014 uint8_t *scp = fcp->isp_scratch;
4016 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4017 isp_prt(isp, ISP_LOGERR, sacq);
4022 * Build the CT header and command in memory.
4024 ISP_MEMZERO(&rp, sizeof(rp));
4026 ct->ct_revision = CT_REVISION;
4027 ct->ct_fcs_type = CT_FC_TYPE_FC;
4028 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
4029 ct->ct_cmd_resp = SNS_RFF_ID;
4030 ct->ct_bcnt_resid = (sizeof (rff_id_t) - sizeof (ct_hdr_t)) >> 2;
4031 rp.rffid_portid[0] = fcp->isp_portid >> 16;
4032 rp.rffid_portid[1] = fcp->isp_portid >> 8;
4033 rp.rffid_portid[2] = fcp->isp_portid;
4034 rp.rffid_fc4features = 0;
4035 if (fcp->role & ISP_ROLE_TARGET)
4036 rp.rffid_fc4features |= 1;
4037 if (fcp->role & ISP_ROLE_INITIATOR)
4038 rp.rffid_fc4features |= 2;
4039 rp.rffid_fc4type = FC4_SCSI;
4040 isp_put_rff_id(isp, &rp, (rff_id_t *)scp);
4041 if (isp->isp_dblev & ISP_LOGDEBUG1)
4042 isp_print_bytes(isp, "CT request", sizeof(rft_id_t), scp);
4044 if (isp_ct_passthru(isp, chan, sizeof(rft_id_t), sizeof(ct_hdr_t))) {
4045 FC_SCRATCH_RELEASE(isp, chan);
4049 isp_get_ct_hdr(isp, (ct_hdr_t *) scp, ct);
4050 FC_SCRATCH_RELEASE(isp, chan);
4051 if (ct->ct_cmd_resp == LS_RJT) {
4052 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1,
4053 "Chan %d Register FC4 Features rejected", chan);
4055 } else if (ct->ct_cmd_resp == LS_ACC) {
4056 isp_prt(isp, ISP_LOG_SANCFG,
4057 "Chan %d Register FC4 Features accepted", chan);
4059 isp_prt(isp, ISP_LOGWARN,
4060 "Chan %d Register FC4 Features: 0x%x", chan, ct->ct_cmd_resp);
4067 isp_register_port_name_24xx(ispsoftc_t *isp, int chan)
4069 fcparam *fcp = FCPARAM(isp, chan);
4072 uint8_t *scp = fcp->isp_scratch;
4075 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4076 isp_prt(isp, ISP_LOGERR, sacq);
4081 * Build the CT header and command in memory.
4083 ISP_MEMZERO(&rp, sizeof(rp));
4084 ct = &rp.rspnid_hdr;
4085 ct->ct_revision = CT_REVISION;
4086 ct->ct_fcs_type = CT_FC_TYPE_FC;
4087 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
4088 ct->ct_cmd_resp = SNS_RSPN_ID;
4089 rp.rspnid_portid[0] = fcp->isp_portid >> 16;
4090 rp.rspnid_portid[1] = fcp->isp_portid >> 8;
4091 rp.rspnid_portid[2] = fcp->isp_portid;
4092 rp.rspnid_length = 0;
4093 len = offsetof(rspn_id_t, rspnid_name);
4094 mtx_lock(&prison0.pr_mtx);
4095 rp.rspnid_length += sprintf(&scp[len + rp.rspnid_length],
4096 "%s", prison0.pr_hostname[0] ? prison0.pr_hostname : "FreeBSD");
4097 mtx_unlock(&prison0.pr_mtx);
4098 rp.rspnid_length += sprintf(&scp[len + rp.rspnid_length],
4099 ":%s", device_get_nameunit(isp->isp_dev));
4101 rp.rspnid_length += sprintf(&scp[len + rp.rspnid_length],
4104 len += rp.rspnid_length;
4105 ct->ct_bcnt_resid = (len - sizeof(ct_hdr_t)) >> 2;
4106 isp_put_rspn_id(isp, &rp, (rspn_id_t *)scp);
4107 if (isp->isp_dblev & ISP_LOGDEBUG1)
4108 isp_print_bytes(isp, "CT request", len, scp);
4110 if (isp_ct_passthru(isp, chan, len, sizeof(ct_hdr_t))) {
4111 FC_SCRATCH_RELEASE(isp, chan);
4115 isp_get_ct_hdr(isp, (ct_hdr_t *) scp, ct);
4116 FC_SCRATCH_RELEASE(isp, chan);
4117 if (ct->ct_cmd_resp == LS_RJT) {
4118 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1,
4119 "Chan %d Register Symbolic Port Name rejected", chan);
4121 } else if (ct->ct_cmd_resp == LS_ACC) {
4122 isp_prt(isp, ISP_LOG_SANCFG,
4123 "Chan %d Register Symbolic Port Name accepted", chan);
4125 isp_prt(isp, ISP_LOGWARN,
4126 "Chan %d Register Symbolic Port Name: 0x%x", chan, ct->ct_cmd_resp);
4133 isp_register_node_name_24xx(ispsoftc_t *isp, int chan)
4135 fcparam *fcp = FCPARAM(isp, chan);
4138 uint8_t *scp = fcp->isp_scratch;
4141 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4142 isp_prt(isp, ISP_LOGERR, sacq);
4147 * Build the CT header and command in memory.
4149 ISP_MEMZERO(&rp, sizeof(rp));
4150 ct = &rp.rsnnnn_hdr;
4151 ct->ct_revision = CT_REVISION;
4152 ct->ct_fcs_type = CT_FC_TYPE_FC;
4153 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
4154 ct->ct_cmd_resp = SNS_RSNN_NN;
4155 MAKE_NODE_NAME_FROM_WWN(rp.rsnnnn_nodename, fcp->isp_wwnn);
4156 rp.rsnnnn_length = 0;
4157 len = offsetof(rsnn_nn_t, rsnnnn_name);
4158 mtx_lock(&prison0.pr_mtx);
4159 rp.rsnnnn_length += sprintf(&scp[len + rp.rsnnnn_length],
4160 "%s", prison0.pr_hostname[0] ? prison0.pr_hostname : "FreeBSD");
4161 mtx_unlock(&prison0.pr_mtx);
4162 len += rp.rsnnnn_length;
4163 ct->ct_bcnt_resid = (len - sizeof(ct_hdr_t)) >> 2;
4164 isp_put_rsnn_nn(isp, &rp, (rsnn_nn_t *)scp);
4165 if (isp->isp_dblev & ISP_LOGDEBUG1)
4166 isp_print_bytes(isp, "CT request", len, scp);
4168 if (isp_ct_passthru(isp, chan, len, sizeof(ct_hdr_t))) {
4169 FC_SCRATCH_RELEASE(isp, chan);
4173 isp_get_ct_hdr(isp, (ct_hdr_t *) scp, ct);
4174 FC_SCRATCH_RELEASE(isp, chan);
4175 if (ct->ct_cmd_resp == LS_RJT) {
4176 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1,
4177 "Chan %d Register Symbolic Node Name rejected", chan);
4179 } else if (ct->ct_cmd_resp == LS_ACC) {
4180 isp_prt(isp, ISP_LOG_SANCFG,
4181 "Chan %d Register Symbolic Node Name accepted", chan);
4183 isp_prt(isp, ISP_LOGWARN,
4184 "Chan %d Register Symbolic Node Name: 0x%x", chan, ct->ct_cmd_resp);
4191 isp_next_handle(ispsoftc_t *isp, uint16_t *ohp)
4195 uint16_t handle, minh, maxh;
4198 if (ISP_CAP_2KLOGIN(isp)) {
4200 maxh = NPH_RESERVED - 1;
4208 if (handle == NIL_HANDLE) {
4212 if (handle > maxh) {
4214 isp_prt(isp, ISP_LOGERR, "Out of port handles!");
4215 return (NIL_HANDLE);
4220 for (chan = 0; chan < isp->isp_nchan; chan++) {
4221 fcp = FCPARAM(isp, chan);
4222 if (fcp->role == ISP_ROLE_NONE)
4224 for (i = 0; i < MAX_FC_TARG; i++) {
4225 if (fcp->portdb[i].state != FC_PORTDB_STATE_NIL &&
4226 fcp->portdb[i].handle == handle)
4235 * Start a command. Locking is assumed done in the caller.
4243 uint8_t local[QENTRY_LEN];
4248 int target, dmaresult;
4254 * Check command CDB length, etc.. We really are limited to 16 bytes
4255 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
4256 * but probably only if we're running fairly new firmware (we'll
4257 * let the old f/w choke on an extended command queue entry).
4260 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
4261 isp_prt(isp, ISP_LOGERR, "unsupported cdb length (%d, CDB[0]=0x%x)", XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
4262 XS_SETERR(xs, HBA_REQINVAL);
4263 return (CMD_COMPLETE);
4267 * Translate the target to device handle as appropriate, checking
4268 * for correct device state as well.
4270 target = XS_TGT(xs);
4272 fcparam *fcp = FCPARAM(isp, XS_CHANNEL(xs));
4274 if ((fcp->role & ISP_ROLE_INITIATOR) == 0) {
4275 isp_prt(isp, ISP_LOG_WARN1,
4276 "%d.%d.%jx I am not an initiator",
4277 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4278 XS_SETERR(xs, HBA_SELTIMEOUT);
4279 return (CMD_COMPLETE);
4282 if (isp->isp_state != ISP_RUNSTATE) {
4283 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
4284 XS_SETERR(xs, HBA_BOTCH);
4285 return (CMD_COMPLETE);
4288 isp_prt(isp, ISP_LOGDEBUG2, "XS_TGT(xs)=%d", target);
4289 lp = &fcp->portdb[target];
4290 if (target < 0 || target >= MAX_FC_TARG ||
4291 lp->is_target == 0) {
4292 XS_SETERR(xs, HBA_SELTIMEOUT);
4293 return (CMD_COMPLETE);
4295 if (fcp->isp_loopstate != LOOP_READY) {
4296 isp_prt(isp, ISP_LOGDEBUG1,
4297 "%d.%d.%jx loop is not ready",
4298 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4299 return (CMD_RQLATER);
4301 if (lp->state == FC_PORTDB_STATE_ZOMBIE) {
4302 isp_prt(isp, ISP_LOGDEBUG1,
4303 "%d.%d.%jx target zombie",
4304 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4305 return (CMD_RQLATER);
4307 if (lp->state != FC_PORTDB_STATE_VALID) {
4308 isp_prt(isp, ISP_LOGDEBUG1,
4309 "%d.%d.%jx bad db port state 0x%x",
4310 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs), lp->state);
4311 XS_SETERR(xs, HBA_SELTIMEOUT);
4312 return (CMD_COMPLETE);
4315 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
4316 if (isp->isp_state != ISP_RUNSTATE) {
4317 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
4318 XS_SETERR(xs, HBA_BOTCH);
4319 return (CMD_COMPLETE);
4323 isp_spi_update(isp, XS_CHANNEL(xs));
4330 qep = isp_getrqentry(isp);
4332 isp_prt(isp, ISP_LOG_WARN1, "Request Queue Overflow");
4333 XS_SETERR(xs, HBA_BOTCH);
4334 return (CMD_EAGAIN);
4336 XS_SETERR(xs, HBA_NOERROR);
4339 * Now see if we need to synchronize the ISP with respect to anything.
4340 * We do dual duty here (cough) for synchronizing for busses other
4341 * than which we got here to send a command to.
4343 reqp = (ispreq_t *) local;
4344 ISP_MEMZERO(local, QENTRY_LEN);
4345 if (ISP_TST_SENDMARKER(isp, XS_CHANNEL(xs))) {
4347 isp_marker_24xx_t *m = (isp_marker_24xx_t *) reqp;
4348 m->mrk_header.rqs_entry_count = 1;
4349 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4350 m->mrk_modifier = SYNC_ALL;
4351 m->mrk_vphdl = XS_CHANNEL(xs);
4352 isp_put_marker_24xx(isp, m, qep);
4354 isp_marker_t *m = (isp_marker_t *) reqp;
4355 m->mrk_header.rqs_entry_count = 1;
4356 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4357 m->mrk_target = (XS_CHANNEL(xs) << 7); /* bus # */
4358 m->mrk_modifier = SYNC_ALL;
4359 isp_put_marker(isp, m, qep);
4361 ISP_SYNC_REQUEST(isp);
4362 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 0);
4366 reqp->req_header.rqs_entry_count = 1;
4369 * Select and install Header Code.
4370 * Note that it might be overridden before going out
4371 * if we're on a 64 bit platform. The lower level
4372 * code (isp_send_cmd) will select the appropriate
4373 * 64 bit variant if it needs to.
4376 reqp->req_header.rqs_entry_type = RQSTYPE_T7RQS;
4377 } else if (IS_FC(isp)) {
4378 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
4380 if (XS_CDBLEN(xs) > 12) {
4381 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
4383 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
4388 * Set task attributes
4393 ttype = XS_TAG_TYPE(xs);
4395 ttype = REQFLAG_STAG;
4397 if (ttype == REQFLAG_OTAG) {
4398 ttype = FCP_CMND_TASK_ATTR_ORDERED;
4399 } else if (ttype == REQFLAG_HTAG) {
4400 ttype = FCP_CMND_TASK_ATTR_HEAD;
4402 ttype = FCP_CMND_TASK_ATTR_SIMPLE;
4404 ((ispreqt7_t *)reqp)->req_task_attribute = ttype;
4405 } else if (IS_FC(isp)) {
4407 * See comment in isp_intr_respq
4409 /* XS_SET_RESID(xs, 0); */
4412 * Fibre Channel always requires some kind of tag.
4413 * The Qlogic drivers seem be happy not to use a tag,
4414 * but this breaks for some devices (IBM drives).
4417 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
4419 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
4422 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
4423 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) && XS_TAG_P(xs)) {
4424 reqp->req_flags = XS_TAG_TYPE(xs);
4429 * NB: we do not support long CDBs (yet)
4431 cdblen = XS_CDBLEN(xs);
4434 if (cdblen > sizeof (reqp->req_cdb)) {
4435 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4436 XS_SETERR(xs, HBA_REQINVAL);
4437 return (CMD_COMPLETE);
4439 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
4440 reqp->req_lun_trn = XS_LUN(xs);
4441 reqp->req_cdblen = cdblen;
4442 tptr = &reqp->req_time;
4443 cdbp = reqp->req_cdb;
4444 } else if (IS_24XX(isp)) {
4445 ispreqt7_t *t7 = (ispreqt7_t *)local;
4447 if (cdblen > sizeof (t7->req_cdb)) {
4448 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4449 XS_SETERR(xs, HBA_REQINVAL);
4450 return (CMD_COMPLETE);
4453 t7->req_nphdl = lp->handle;
4454 t7->req_tidlo = lp->portid;
4455 t7->req_tidhi = lp->portid >> 16;
4456 t7->req_vpidx = ISP_GET_VPIDX(isp, XS_CHANNEL(xs));
4457 be64enc(t7->req_lun, CAM_EXTLUN_BYTE_SWIZZLE(XS_LUN(xs)));
4458 if (FCPARAM(isp, XS_CHANNEL(xs))->fctape_enabled && (lp->prli_word3 & PRLI_WD3_RETRY)) {
4459 if (FCP_NEXT_CRN(isp, &t7->req_crn, xs)) {
4460 isp_prt(isp, ISP_LOG_WARN1,
4461 "%d.%d.%jx cannot generate next CRN",
4462 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4463 XS_SETERR(xs, HBA_BOTCH);
4464 return (CMD_EAGAIN);
4467 tptr = &t7->req_time;
4470 ispreqt2_t *t2 = (ispreqt2_t *)local;
4472 if (cdblen > sizeof t2->req_cdb) {
4473 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4474 XS_SETERR(xs, HBA_REQINVAL);
4475 return (CMD_COMPLETE);
4477 if (FCPARAM(isp, XS_CHANNEL(xs))->fctape_enabled && (lp->prli_word3 & PRLI_WD3_RETRY)) {
4478 if (FCP_NEXT_CRN(isp, &t2->req_crn, xs)) {
4479 isp_prt(isp, ISP_LOG_WARN1,
4480 "%d.%d.%jx cannot generate next CRN",
4481 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4482 XS_SETERR(xs, HBA_BOTCH);
4483 return (CMD_EAGAIN);
4486 if (ISP_CAP_2KLOGIN(isp)) {
4487 ispreqt2e_t *t2e = (ispreqt2e_t *)local;
4488 t2e->req_target = lp->handle;
4489 t2e->req_scclun = XS_LUN(xs);
4490 tptr = &t2e->req_time;
4491 cdbp = t2e->req_cdb;
4492 } else if (ISP_CAP_SCCFW(isp)) {
4493 t2->req_target = lp->handle;
4494 t2->req_scclun = XS_LUN(xs);
4495 tptr = &t2->req_time;
4498 t2->req_target = lp->handle;
4499 t2->req_lun_trn = XS_LUN(xs);
4500 tptr = &t2->req_time;
4504 *tptr = XS_TIME(xs);
4505 ISP_MEMCPY(cdbp, XS_CDBP(xs), cdblen);
4507 /* Whew. Thankfully the same for type 7 requests */
4508 reqp->req_handle = isp_allocate_handle(isp, xs, ISP_HANDLE_INITIATOR);
4509 if (reqp->req_handle == 0) {
4510 isp_prt(isp, ISP_LOG_WARN1, "out of xflist pointers");
4511 XS_SETERR(xs, HBA_BOTCH);
4512 return (CMD_EAGAIN);
4516 * Set up DMA and/or do any platform dependent swizzling of the request entry
4517 * so that the Qlogic F/W understands what is being asked of it.
4519 * The callee is responsible for adding all requests at this point.
4521 dmaresult = ISP_DMASETUP(isp, xs, reqp);
4522 if (dmaresult != CMD_QUEUED) {
4523 isp_destroy_handle(isp, reqp->req_handle);
4525 * dmasetup sets actual error in packet, and
4526 * return what we were given to return.
4530 isp_xs_prt(isp, xs, ISP_LOGDEBUG0, "START cmd cdb[0]=0x%x datalen %ld", XS_CDBP(xs)[0], (long) XS_XFRLEN(xs));
4531 return (CMD_QUEUED);
4536 * Locks (ints blocked) assumed held.
4540 isp_control(ispsoftc_t *isp, ispctl_t ctl, ...)
4549 case ISPCTL_RESET_BUS:
4551 * Issue a bus reset.
4554 isp_prt(isp, ISP_LOGERR, "BUS RESET NOT IMPLEMENTED");
4556 } else if (IS_FC(isp)) {
4561 chan = va_arg(ap, int);
4563 mbs.param[1] = SDPARAM(isp, chan)->isp_bus_reset_delay;
4564 if (mbs.param[1] < 2) {
4567 mbs.param[2] = chan;
4569 MBSINIT(&mbs, MBOX_BUS_RESET, MBLOGALL, 0);
4570 ISP_SET_SENDMARKER(isp, chan, 1);
4571 isp_mboxcmd(isp, &mbs);
4572 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4575 isp_prt(isp, ISP_LOGINFO, "driver initiated bus reset of bus %d", chan);
4578 case ISPCTL_RESET_DEV:
4580 chan = va_arg(ap, int);
4581 tgt = va_arg(ap, int);
4584 uint8_t local[QENTRY_LEN];
4586 isp24xx_statusreq_t *sp;
4587 fcparam *fcp = FCPARAM(isp, chan);
4590 if (tgt < 0 || tgt >= MAX_FC_TARG) {
4591 isp_prt(isp, ISP_LOGWARN, "Chan %d trying to reset bad target %d", chan, tgt);
4594 lp = &fcp->portdb[tgt];
4595 if (lp->is_target == 0 ||
4596 lp->state != FC_PORTDB_STATE_VALID) {
4597 isp_prt(isp, ISP_LOGWARN, "Chan %d abort of no longer valid target %d", chan, tgt);
4601 tmf = (isp24xx_tmf_t *) local;
4602 ISP_MEMZERO(tmf, QENTRY_LEN);
4603 tmf->tmf_header.rqs_entry_type = RQSTYPE_TSK_MGMT;
4604 tmf->tmf_header.rqs_entry_count = 1;
4605 tmf->tmf_nphdl = lp->handle;
4607 tmf->tmf_timeout = 4;
4608 tmf->tmf_flags = ISP24XX_TMF_TARGET_RESET;
4609 tmf->tmf_tidlo = lp->portid;
4610 tmf->tmf_tidhi = lp->portid >> 16;
4611 tmf->tmf_vpidx = ISP_GET_VPIDX(isp, chan);
4612 isp_put_24xx_tmf(isp, tmf, isp->isp_iocb);
4613 if (isp->isp_dblev & ISP_LOGDEBUG1)
4614 isp_print_bytes(isp, "TMF IOCB request", QENTRY_LEN, isp->isp_iocb);
4615 MEMORYBARRIER(isp, SYNC_IFORDEV, 0, QENTRY_LEN, chan);
4616 fcp->sendmarker = 1;
4618 isp_prt(isp, ISP_LOGALL, "Chan %d Reset N-Port Handle 0x%04x @ Port 0x%06x", chan, lp->handle, lp->portid);
4619 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL,
4620 MBCMD_DEFAULT_TIMEOUT + tmf->tmf_timeout * 1000000);
4621 mbs.param[1] = QENTRY_LEN;
4622 mbs.param[2] = DMA_WD1(isp->isp_iocb_dma);
4623 mbs.param[3] = DMA_WD0(isp->isp_iocb_dma);
4624 mbs.param[6] = DMA_WD3(isp->isp_iocb_dma);
4625 mbs.param[7] = DMA_WD2(isp->isp_iocb_dma);
4626 isp_mboxcmd(isp, &mbs);
4627 if (mbs.param[0] != MBOX_COMMAND_COMPLETE)
4630 MEMORYBARRIER(isp, SYNC_IFORCPU, QENTRY_LEN, QENTRY_LEN, chan);
4631 if (isp->isp_dblev & ISP_LOGDEBUG1)
4632 isp_print_bytes(isp, "TMF IOCB response", QENTRY_LEN, &((isp24xx_statusreq_t *)isp->isp_iocb)[1]);
4633 sp = (isp24xx_statusreq_t *) local;
4634 isp_get_24xx_response(isp, &((isp24xx_statusreq_t *)isp->isp_iocb)[1], sp);
4635 if (sp->req_completion_status == 0) {
4638 isp_prt(isp, ISP_LOGWARN, "Chan %d reset of target %d returned 0x%x", chan, tgt, sp->req_completion_status);
4640 } else if (IS_FC(isp)) {
4641 if (ISP_CAP_2KLOGIN(isp)) {
4643 mbs.ibits = (1 << 10);
4645 mbs.param[1] = (tgt << 8);
4648 mbs.param[1] = (chan << 15) | (tgt << 8);
4650 MBSINIT(&mbs, MBOX_ABORT_TARGET, MBLOGALL, 0);
4651 mbs.param[2] = 3; /* 'delay', in seconds */
4652 isp_mboxcmd(isp, &mbs);
4653 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4656 isp_prt(isp, ISP_LOGINFO, "Target %d on Bus %d Reset Succeeded", tgt, chan);
4657 ISP_SET_SENDMARKER(isp, chan, 1);
4660 case ISPCTL_ABORT_CMD:
4662 xs = va_arg(ap, XS_T *);
4666 chan = XS_CHANNEL(xs);
4668 handle = isp_find_handle(isp, xs);
4670 isp_prt(isp, ISP_LOGWARN, "cannot find handle for command to abort");
4674 isp24xx_abrt_t local, *ab = &local;
4678 fcp = FCPARAM(isp, chan);
4679 if (tgt < 0 || tgt >= MAX_FC_TARG) {
4680 isp_prt(isp, ISP_LOGWARN, "Chan %d trying to abort bad target %d", chan, tgt);
4683 lp = &fcp->portdb[tgt];
4684 if (lp->is_target == 0 ||
4685 lp->state != FC_PORTDB_STATE_VALID) {
4686 isp_prt(isp, ISP_LOGWARN, "Chan %d abort of no longer valid target %d", chan, tgt);
4689 isp_prt(isp, ISP_LOGALL, "Chan %d Abort Cmd for N-Port 0x%04x @ Port 0x%06x", chan, lp->handle, lp->portid);
4690 ISP_MEMZERO(ab, QENTRY_LEN);
4691 ab->abrt_header.rqs_entry_type = RQSTYPE_ABORT_IO;
4692 ab->abrt_header.rqs_entry_count = 1;
4693 ab->abrt_handle = lp->handle;
4694 ab->abrt_cmd_handle = handle;
4695 ab->abrt_tidlo = lp->portid;
4696 ab->abrt_tidhi = lp->portid >> 16;
4697 ab->abrt_vpidx = ISP_GET_VPIDX(isp, chan);
4698 isp_put_24xx_abrt(isp, ab, isp->isp_iocb);
4699 if (isp->isp_dblev & ISP_LOGDEBUG1)
4700 isp_print_bytes(isp, "AB IOCB quest", QENTRY_LEN, isp->isp_iocb);
4701 MEMORYBARRIER(isp, SYNC_IFORDEV, 0, 2 * QENTRY_LEN, chan);
4703 ISP_MEMZERO(&mbs, sizeof (mbs));
4704 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 5000000);
4705 mbs.param[1] = QENTRY_LEN;
4706 mbs.param[2] = DMA_WD1(isp->isp_iocb_dma);
4707 mbs.param[3] = DMA_WD0(isp->isp_iocb_dma);
4708 mbs.param[6] = DMA_WD3(isp->isp_iocb_dma);
4709 mbs.param[7] = DMA_WD2(isp->isp_iocb_dma);
4711 isp_mboxcmd(isp, &mbs);
4712 if (mbs.param[0] != MBOX_COMMAND_COMPLETE)
4715 MEMORYBARRIER(isp, SYNC_IFORCPU, QENTRY_LEN, QENTRY_LEN, chan);
4716 if (isp->isp_dblev & ISP_LOGDEBUG1)
4717 isp_print_bytes(isp, "AB IOCB response", QENTRY_LEN, &((isp24xx_abrt_t *)isp->isp_iocb)[1]);
4718 isp_get_24xx_abrt(isp, &((isp24xx_abrt_t *)isp->isp_iocb)[1], ab);
4719 if (ab->abrt_nphdl == ISP24XX_ABRT_OKAY) {
4722 isp_prt(isp, ISP_LOGWARN, "Chan %d handle %d abort returned 0x%x", chan, tgt, ab->abrt_nphdl);
4724 } else if (IS_FC(isp)) {
4725 if (ISP_CAP_SCCFW(isp)) {
4726 if (ISP_CAP_2KLOGIN(isp)) {
4729 mbs.param[1] = tgt << 8;
4731 mbs.param[6] = XS_LUN(xs);
4733 mbs.param[1] = tgt << 8 | XS_LUN(xs);
4736 mbs.param[1] = (chan << 15) | (tgt << 8) | XS_LUN(xs);
4738 MBSINIT(&mbs, MBOX_ABORT,
4739 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_ERROR), 0);
4740 mbs.param[2] = handle;
4741 isp_mboxcmd(isp, &mbs);
4742 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4747 case ISPCTL_UPDATE_PARAMS:
4750 chan = va_arg(ap, int);
4752 isp_spi_update(isp, chan);
4755 case ISPCTL_FCLINK_TEST:
4760 chan = va_arg(ap, int);
4761 usdelay = va_arg(ap, int);
4766 return (isp_fclink_test(isp, chan, usdelay));
4770 case ISPCTL_SCAN_FABRIC:
4774 chan = va_arg(ap, int);
4776 return (isp_scan_fabric(isp, chan));
4780 case ISPCTL_SCAN_LOOP:
4784 chan = va_arg(ap, int);
4786 return (isp_scan_loop(isp, chan));
4790 case ISPCTL_PDB_SYNC:
4794 chan = va_arg(ap, int);
4796 return (isp_pdb_sync(isp, chan));
4800 case ISPCTL_SEND_LIP:
4802 if (IS_FC(isp) && !IS_24XX(isp)) {
4803 MBSINIT(&mbs, MBOX_INIT_LIP, MBLOGALL, 0);
4804 if (ISP_CAP_2KLOGIN(isp)) {
4805 mbs.ibits = (1 << 10);
4807 isp_mboxcmd(isp, &mbs);
4808 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
4814 case ISPCTL_GET_PDB:
4818 chan = va_arg(ap, int);
4819 tgt = va_arg(ap, int);
4820 pdb = va_arg(ap, isp_pdb_t *);
4822 return (isp_getpdb(isp, chan, tgt, pdb));
4826 case ISPCTL_GET_NAMES:
4828 uint64_t *wwnn, *wwnp;
4830 chan = va_arg(ap, int);
4831 tgt = va_arg(ap, int);
4832 wwnn = va_arg(ap, uint64_t *);
4833 wwnp = va_arg(ap, uint64_t *);
4835 if (wwnn == NULL && wwnp == NULL) {
4839 *wwnn = isp_get_wwn(isp, chan, tgt, 1);
4840 if (*wwnn == INI_NONE) {
4845 *wwnp = isp_get_wwn(isp, chan, tgt, 0);
4846 if (*wwnp == INI_NONE) {
4852 case ISPCTL_RUN_MBOXCMD:
4855 mbr = va_arg(ap, mbreg_t *);
4857 isp_mboxcmd(isp, mbr);
4866 p = va_arg(ap, isp_plcmd_t *);
4869 if ((p->flags & PLOGX_FLG_CMD_MASK) != PLOGX_FLG_CMD_PLOGI || (p->handle != NIL_HANDLE)) {
4870 return (isp_plogx(isp, p->channel, p->handle, p->portid, p->flags));
4873 isp_next_handle(isp, &p->handle);
4874 r = isp_plogx(isp, p->channel, p->handle, p->portid, p->flags);
4875 if ((r & 0xffff) == MBOX_PORT_ID_USED) {
4876 p->handle = r >> 16;
4880 } while ((r & 0xffff) == MBOX_LOOP_ID_USED);
4883 case ISPCTL_CHANGE_ROLE:
4888 chan = va_arg(ap, int);
4889 role = va_arg(ap, int);
4891 r = isp_fc_change_role(isp, chan, role);
4896 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
4904 * Interrupt Service Routine(s).
4906 * External (OS) framework has done the appropriate locking,
4907 * and the locking will be held throughout this function.
4910 #ifdef ISP_TARGET_MODE
4912 isp_intr_atioq(ispsoftc_t *isp)
4914 uint8_t qe[QENTRY_LEN];
4917 uint32_t iptr, optr, oop;
4919 iptr = ISP_READ(isp, BIU2400_ATIO_RSPINP);
4920 optr = isp->isp_atioodx;
4921 while (optr != iptr) {
4923 MEMORYBARRIER(isp, SYNC_ATIOQ, oop, QENTRY_LEN, -1);
4924 addr = ISP_QUEUE_ENTRY(isp->isp_atioq, oop);
4925 isp_get_hdr(isp, addr, (isphdr_t *)qe);
4926 hp = (isphdr_t *)qe;
4927 switch (hp->rqs_entry_type) {
4928 case RQSTYPE_NOTIFY:
4930 (void) isp_target_notify(isp, addr, &oop);
4933 isp_print_qentry(isp, "?ATIOQ entry?", oop, addr);
4936 optr = ISP_NXT_QENTRY(oop, RESULT_QUEUE_LEN(isp));
4938 if (isp->isp_atioodx != optr) {
4939 ISP_WRITE(isp, BIU2400_ATIO_RSPOUTP, optr);
4940 isp->isp_atioodx = optr;
4946 isp_intr_async(ispsoftc_t *isp, uint16_t event)
4950 isp_parse_async_fc(isp, event);
4952 isp_parse_async(isp, event);
4956 isp_intr_mbox(ispsoftc_t *isp, uint16_t mbox0)
4960 if (!isp->isp_mboxbsy) {
4961 isp_prt(isp, ISP_LOGWARN, "mailbox 0x%x with no waiters", mbox0);
4964 obits = isp->isp_obits;
4965 isp->isp_mboxtmp[0] = mbox0;
4966 for (i = 1; i < ISP_NMBOX(isp); i++) {
4967 if ((obits & (1 << i)) == 0)
4969 isp->isp_mboxtmp[i] = ISP_READ(isp, MBOX_OFF(i));
4971 MBOX_NOTIFY_COMPLETE(isp);
4975 * Limit our stack depth by sticking with the max likely number
4976 * of completions on a request queue at any one time.
4978 #ifndef MAX_REQUESTQ_COMPLETIONS
4979 #define MAX_REQUESTQ_COMPLETIONS 32
4983 isp_intr_respq(ispsoftc_t *isp)
4985 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
4986 uint32_t iptr, optr, junk;
4987 int i, nlooked = 0, ndone = 0, continuations_expected = 0;
4988 int etype, last_etype = 0;
4991 * We can't be getting this now.
4993 if (isp->isp_state != ISP_RUNSTATE) {
4994 isp_prt(isp, ISP_LOGINFO, "respq interrupt when not ready");
4998 iptr = ISP_READ(isp, isp->isp_respinrp);
4999 /* Debounce the 2300 if revision less than 2. */
5000 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
5003 iptr = ISP_READ(isp, isp->isp_respinrp);
5004 } while (junk != iptr);
5006 isp->isp_residx = iptr;
5008 optr = isp->isp_resodx;
5009 while (optr != iptr) {
5010 uint8_t qe[QENTRY_LEN];
5011 ispstatusreq_t *sp = (ispstatusreq_t *) qe;
5013 int buddaboom, scsi_status, completion_status;
5014 int req_status_flags, req_state_flags;
5015 uint8_t *snsp, *resp;
5016 uint32_t rlen, slen, totslen;
5020 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
5022 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
5025 buddaboom = req_status_flags = req_state_flags = 0;
5029 * Synchronize our view of this response queue entry.
5031 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN, -1);
5032 if (isp->isp_dblev & ISP_LOGDEBUG1)
5033 isp_print_qentry(isp, "Response Queue Entry", oop, hp);
5034 isp_get_hdr(isp, hp, &sp->req_header);
5035 etype = sp->req_header.rqs_entry_type;
5037 if (IS_24XX(isp) && etype == RQSTYPE_RESPONSE) {
5038 isp24xx_statusreq_t *sp2 = (isp24xx_statusreq_t *)qe;
5039 isp_get_24xx_response(isp, (isp24xx_statusreq_t *)hp, sp2);
5040 scsi_status = sp2->req_scsi_status;
5041 completion_status = sp2->req_completion_status;
5042 if ((scsi_status & 0xff) != 0)
5043 req_state_flags = RQSF_GOT_STATUS;
5045 req_state_flags = 0;
5046 resid = sp2->req_resid;
5047 } else if (etype == RQSTYPE_RESPONSE) {
5048 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
5049 scsi_status = sp->req_scsi_status;
5050 completion_status = sp->req_completion_status;
5051 req_status_flags = sp->req_status_flags;
5052 req_state_flags = sp->req_state_flags;
5053 resid = sp->req_resid;
5054 } else if (etype == RQSTYPE_RIO1) {
5055 isp_rio1_t *rio = (isp_rio1_t *) qe;
5056 isp_get_rio1(isp, (isp_rio1_t *) hp, rio);
5057 for (i = 0; i < rio->req_header.rqs_seqno; i++) {
5058 isp_fastpost_complete(isp, rio->req_handles[i]);
5060 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5063 } else if (etype == RQSTYPE_RIO2) {
5064 isp_prt(isp, ISP_LOGERR, "dropping RIO2 response");
5065 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5068 } else if (etype == RQSTYPE_STATUS_CONT) {
5069 isp_get_cont_response(isp, (ispstatus_cont_t *) hp, (ispstatus_cont_t *) sp);
5070 if (last_etype == RQSTYPE_RESPONSE && continuations_expected && ndone > 0 && (xs = complist[ndone-1]) != NULL) {
5071 ispstatus_cont_t *scp = (ispstatus_cont_t *) sp;
5072 XS_SENSE_APPEND(xs, scp->req_sense_data, sizeof (scp->req_sense_data));
5073 isp_prt(isp, ISP_LOGDEBUG0|ISP_LOG_CWARN, "%d more Status Continuations expected", --continuations_expected);
5075 isp_prt(isp, ISP_LOG_WARN1, "Ignored Continuation Response");
5077 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5081 * Somebody reachable via isp_handle_other_response
5082 * may have updated the response queue pointers for
5083 * us, so we reload our goal index.
5086 uint32_t tsto = oop;
5087 r = isp_handle_other_response(isp, etype, hp, &tsto);
5092 * If somebody updated the output pointer, then reset
5093 * optr to be one more than the updated amount.
5095 while (tsto != oop) {
5096 optr = ISP_NXT_QENTRY(tsto, RESULT_QUEUE_LEN(isp));
5099 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5105 * After this point, we'll just look at the header as
5106 * we don't know how to deal with the rest of the
5111 * It really has to be a bounced request just copied
5112 * from the request queue to the response queue. If
5113 * not, something bad has happened.
5115 if (etype != RQSTYPE_REQUEST) {
5116 isp_prt(isp, ISP_LOGERR, notresp, etype, oop, optr, nlooked);
5117 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5122 scsi_status = sp->req_scsi_status;
5123 completion_status = sp->req_completion_status;
5124 req_status_flags = sp->req_status_flags;
5125 req_state_flags = sp->req_state_flags;
5126 resid = sp->req_resid;
5129 if (sp->req_header.rqs_flags & RQSFLAG_MASK) {
5130 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
5131 isp_print_qentry(isp, "unexpected continuation segment",
5136 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
5137 isp_prt(isp, ISP_LOG_WARN1, "internal queues full");
5139 * We'll synthesize a QUEUE FULL message below.
5142 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
5143 isp_print_qentry(isp, "bad header flag",
5147 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
5148 isp_print_qentry(isp, "bad request packet",
5152 if (sp->req_header.rqs_flags & RQSFLAG_BADCOUNT) {
5153 isp_print_qentry(isp, "invalid entry count",
5157 if (sp->req_header.rqs_flags & RQSFLAG_BADORDER) {
5158 isp_print_qentry(isp, "invalid IOCB ordering",
5165 xs = isp_find_xs(isp, sp->req_handle);
5167 uint8_t ts = completion_status & 0xff;
5169 * Only whine if this isn't the expected fallout of
5170 * aborting the command or resetting the target.
5172 if (etype != RQSTYPE_RESPONSE) {
5173 isp_prt(isp, ISP_LOGERR, "cannot find handle 0x%x (type 0x%x)", sp->req_handle, etype);
5174 } else if (ts != RQCS_ABORTED && ts != RQCS_RESET_OCCURRED) {
5175 isp_prt(isp, ISP_LOGERR, "cannot find handle 0x%x (status 0x%x)", sp->req_handle, ts);
5177 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5181 if (req_status_flags & RQSTF_BUS_RESET) {
5182 isp_prt(isp, ISP_LOG_WARN1, "%d.%d.%jx bus was reset",
5183 XS_CHANNEL(xs), XS_TGT(xs), (uintmax_t)XS_LUN(xs));
5184 XS_SETERR(xs, HBA_BUSRESET);
5185 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 1);
5188 isp_prt(isp, ISP_LOG_WARN1, "%d.%d.%jx buddaboom",
5189 XS_CHANNEL(xs), XS_TGT(xs), (uintmax_t)XS_LUN(xs));
5190 XS_SETERR(xs, HBA_BOTCH);
5197 if (IS_24XX(isp) && (scsi_status & (RQCS_RV|RQCS_SV)) != 0) {
5198 resp = ((isp24xx_statusreq_t *)sp)->req_rsp_sense;
5199 rlen = ((isp24xx_statusreq_t *)sp)->req_response_len;
5200 } else if (IS_FC(isp) && (scsi_status & RQCS_RV) != 0) {
5201 resp = sp->req_response;
5202 rlen = sp->req_response_len;
5204 if (IS_FC(isp) && (scsi_status & RQCS_SV) != 0) {
5206 * Fibre Channel F/W doesn't say we got status
5207 * if there's Sense Data instead. I guess they
5208 * think it goes w/o saying.
5210 req_state_flags |= RQSF_GOT_STATUS|RQSF_GOT_SENSE;
5212 snsp = ((isp24xx_statusreq_t *)sp)->req_rsp_sense;
5214 totslen = ((isp24xx_statusreq_t *)sp)->req_sense_len;
5215 slen = (sizeof (((isp24xx_statusreq_t *)sp)->req_rsp_sense)) - rlen;
5219 snsp = sp->req_sense_data;
5220 totslen = sp->req_sense_len;
5221 slen = sizeof (sp->req_sense_data);
5225 } else if (IS_SCSI(isp) && (req_state_flags & RQSF_GOT_SENSE)) {
5226 snsp = sp->req_sense_data;
5227 totslen = sp->req_sense_len;
5228 slen = sizeof (sp->req_sense_data);
5232 if (req_state_flags & RQSF_GOT_STATUS) {
5233 *XS_STSP(xs) = scsi_status & 0xff;
5237 case RQSTYPE_RESPONSE:
5238 if (resp && rlen >= 4 && resp[FCP_RSPNS_CODE_OFFSET] != 0) {
5241 const char *rnames[10] = {
5242 "Task Management function complete",
5243 "FCP_DATA length different than FCP_BURST_LEN",
5244 "FCP_CMND fields invalid",
5245 "FCP_DATA parameter mismatch with FCP_DATA_RO",
5246 "Task Management function rejected",
5247 "Task Management function failed",
5250 "Task Management function succeeded",
5251 "Task Management function incorrect logical unit number",
5253 uint8_t code = resp[FCP_RSPNS_CODE_OFFSET];
5254 if (code >= 10 || rnames[code] == NULL) {
5255 ISP_SNPRINTF(lb, sizeof(lb),
5256 "Unknown FCP Response Code 0x%x",
5262 isp_xs_prt(isp, xs, ISP_LOGWARN,
5263 "FCP RESPONSE, LENGTH %u: %s CDB0=0x%02x",
5264 rlen, ptr, XS_CDBP(xs)[0] & 0xff);
5265 if (code != 0 && code != 8)
5266 XS_SETERR(xs, HBA_BOTCH);
5269 isp_parse_status_24xx(isp, (isp24xx_statusreq_t *)sp, xs, &resid);
5271 isp_parse_status(isp, (void *)sp, xs, &resid);
5273 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) && (*XS_STSP(xs) == SCSI_BUSY)) {
5274 XS_SETERR(xs, HBA_TGTBSY);
5277 XS_SET_RESID(xs, resid);
5279 * A new synchronous rate was negotiated for
5280 * this target. Mark state such that we'll go
5281 * look up that which has changed later.
5283 if (req_status_flags & RQSTF_NEGOTIATION) {
5285 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
5286 sdp->isp_devparam[t].dev_refresh = 1;
5290 if (req_status_flags & RQSF_XFER_COMPLETE) {
5291 XS_SET_RESID(xs, 0);
5292 } else if (scsi_status & RQCS_RESID) {
5293 XS_SET_RESID(xs, resid);
5295 XS_SET_RESID(xs, 0);
5299 if (totslen > slen) {
5300 continuations_expected += ((totslen - slen + QENTRY_LEN - 5) / (QENTRY_LEN - 4));
5301 if (ndone > (MAX_REQUESTQ_COMPLETIONS - continuations_expected - 1)) {
5302 /* we'll lose some stats, but that's a small price to pay */
5303 for (i = 0; i < ndone; i++) {
5305 isp_done(complist[i]);
5309 isp_prt(isp, ISP_LOGDEBUG0|ISP_LOG_CWARN, "Expecting %d more Status Continuations for total sense length of %u",
5310 continuations_expected, totslen);
5312 XS_SAVE_SENSE(xs, snsp, totslen, slen);
5313 } else if ((req_status_flags & RQSF_GOT_STATUS) && (scsi_status & 0xff) == SCSI_CHECK && IS_FC(isp)) {
5314 isp_prt(isp, ISP_LOGWARN, "CHECK CONDITION w/o sense data for CDB=0x%x", XS_CDBP(xs)[0] & 0xff);
5315 isp_print_qentry(isp, "CC with no Sense",
5318 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));
5320 case RQSTYPE_REQUEST:
5325 if (!IS_24XX(isp) && (sp->req_header.rqs_flags & RQSFLAG_FULL)) {
5327 * Force Queue Full status.
5329 *XS_STSP(xs) = SCSI_QFULL;
5330 XS_SETERR(xs, HBA_NOERROR);
5331 } else if (XS_NOERR(xs)) {
5332 isp_prt(isp, ISP_LOG_WARN1,
5333 "%d.%d.%jx badness at %s:%u",
5334 XS_CHANNEL(xs), XS_TGT(xs),
5335 (uintmax_t)XS_LUN(xs),
5336 __func__, __LINE__);
5337 XS_SETERR(xs, HBA_BOTCH);
5339 XS_SET_RESID(xs, XS_XFRLEN(xs));
5342 isp_print_qentry(isp, "Unhandled Response Type",
5345 XS_SETERR(xs, HBA_BOTCH);
5351 * Free any DMA resources. As a side effect, this may
5352 * also do any cache flushing necessary for data coherence.
5354 if (XS_XFRLEN(xs)) {
5355 ISP_DMAFREE(isp, xs, sp->req_handle);
5357 isp_destroy_handle(isp, sp->req_handle);
5359 complist[ndone++] = xs; /* defer completion call until later */
5360 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5362 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
5368 * If we looked at any commands, then it's valid to find out
5369 * what the outpointer is. It also is a trigger to update the
5370 * ISP's notion of what we've seen so far.
5373 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5374 isp->isp_resodx = optr;
5377 for (i = 0; i < ndone; i++) {
5380 if (((isp->isp_dblev & (ISP_LOGDEBUG1|ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
5381 ((isp->isp_dblev & (ISP_LOGDEBUG0|ISP_LOG_CWARN) && ((!XS_NOERR(xs)) || (*XS_STSP(xs) != SCSI_GOOD))))) {
5382 isp_prt_endcmd(isp, xs);
5394 isp_prt_endcmd(ispsoftc_t *isp, XS_T *xs)
5396 char cdbstr[16 * 5 + 1];
5399 lim = XS_CDBLEN(xs) > 16? 16 : XS_CDBLEN(xs);
5400 ISP_SNPRINTF(cdbstr, sizeof (cdbstr), "0x%02x ", XS_CDBP(xs)[0]);
5401 for (i = 1; i < lim; i++) {
5402 ISP_SNPRINTF(cdbstr, sizeof (cdbstr), "%s0x%02x ", cdbstr, XS_CDBP(xs)[i]);
5404 if (XS_SENSE_VALID(xs)) {
5405 isp_xs_prt(isp, xs, ISP_LOGALL, "FIN dl%d resid %ld CDB=%s SenseLength=%u/%u KEY/ASC/ASCQ=0x%02x/0x%02x/0x%02x",
5406 XS_XFRLEN(xs), (long) XS_GET_RESID(xs), cdbstr, XS_CUR_SNSLEN(xs), XS_TOT_SNSLEN(xs), XS_SNSKEY(xs), XS_SNSASC(xs), XS_SNSASCQ(xs));
5408 isp_xs_prt(isp, xs, ISP_LOGALL, "FIN dl%d resid %ld CDB=%s STS 0x%x XS_ERR=0x%x", XS_XFRLEN(xs), (long) XS_GET_RESID(xs), cdbstr, *XS_STSP(xs), XS_ERR(xs));
5413 * Parse an ASYNC mailbox complete
5416 isp_parse_async(ispsoftc_t *isp, uint16_t mbox)
5418 uint32_t h1 = 0, h2 = 0;
5422 * Pick up the channel, but not if this is a ASYNC_RIO32_2,
5423 * where Mailboxes 6/7 have the second handle.
5425 if (mbox != ASYNC_RIO32_2) {
5426 if (IS_DUALBUS(isp)) {
5427 chan = ISP_READ(isp, OUTMAILBOX6);
5430 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
5433 case ASYNC_BUS_RESET:
5434 ISP_SET_SENDMARKER(isp, chan, 1);
5435 #ifdef ISP_TARGET_MODE
5436 isp_target_async(isp, chan, mbox);
5438 isp_async(isp, ISPASYNC_BUS_RESET, chan);
5440 case ASYNC_SYSTEM_ERROR:
5441 isp->isp_state = ISP_CRASHED;
5443 * Were we waiting for a mailbox command to complete?
5444 * If so, it's dead, so wake up the waiter.
5446 if (isp->isp_mboxbsy) {
5448 isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR;
5449 MBOX_NOTIFY_COMPLETE(isp);
5452 * It's up to the handler for isp_async to reinit stuff and
5453 * restart the firmware
5455 isp_async(isp, ISPASYNC_FW_CRASH);
5458 case ASYNC_RQS_XFER_ERR:
5459 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
5462 case ASYNC_RSP_XFER_ERR:
5463 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
5468 * We've just been notified that the Queue has woken up.
5469 * We don't need to be chatty about this- just unlatch things
5472 mbox = ISP_READ(isp, isp->isp_rqstoutrp);
5475 case ASYNC_TIMEOUT_RESET:
5476 isp_prt(isp, ISP_LOGWARN, "timeout initiated SCSI bus reset of chan %d", chan);
5477 ISP_SET_SENDMARKER(isp, chan, 1);
5478 #ifdef ISP_TARGET_MODE
5479 isp_target_async(isp, chan, mbox);
5483 case ASYNC_DEVICE_RESET:
5484 isp_prt(isp, ISP_LOGINFO, "device reset on chan %d", chan);
5485 ISP_SET_SENDMARKER(isp, chan, 1);
5486 #ifdef ISP_TARGET_MODE
5487 isp_target_async(isp, chan, mbox);
5491 case ASYNC_EXTMSG_UNDERRUN:
5492 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
5495 case ASYNC_SCAM_INT:
5496 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
5499 case ASYNC_HUNG_SCSI:
5500 isp_prt(isp, ISP_LOGERR, "stalled SCSI Bus after DATA Overrun");
5501 /* XXX: Need to issue SCSI reset at this point */
5504 case ASYNC_KILLED_BUS:
5505 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
5508 case ASYNC_BUS_TRANSIT:
5509 mbox = ISP_READ(isp, OUTMAILBOX2);
5510 switch (mbox & SXP_PINS_MODE_MASK) {
5511 case SXP_PINS_LVD_MODE:
5512 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
5513 SDPARAM(isp, chan)->isp_diffmode = 0;
5514 SDPARAM(isp, chan)->isp_ultramode = 0;
5515 SDPARAM(isp, chan)->isp_lvdmode = 1;
5517 case SXP_PINS_HVD_MODE:
5518 isp_prt(isp, ISP_LOGINFO,
5519 "Transition to Differential mode");
5520 SDPARAM(isp, chan)->isp_diffmode = 1;
5521 SDPARAM(isp, chan)->isp_ultramode = 0;
5522 SDPARAM(isp, chan)->isp_lvdmode = 0;
5524 case SXP_PINS_SE_MODE:
5525 isp_prt(isp, ISP_LOGINFO,
5526 "Transition to Single Ended mode");
5527 SDPARAM(isp, chan)->isp_diffmode = 0;
5528 SDPARAM(isp, chan)->isp_ultramode = 1;
5529 SDPARAM(isp, chan)->isp_lvdmode = 0;
5532 isp_prt(isp, ISP_LOGWARN,
5533 "Transition to Unknown Mode 0x%x", mbox);
5537 * XXX: Set up to renegotiate again!
5539 /* Can only be for a 1080... */
5540 ISP_SET_SENDMARKER(isp, chan, 1);
5543 case ASYNC_CMD_CMPLT:
5545 if (!IS_ULTRA3(isp)) {
5546 isp_prt(isp, ISP_LOGERR, "unexpected fast posting completion");
5550 h1 = (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1);
5554 h1 = (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1);
5555 h2 = (ISP_READ(isp, OUTMAILBOX7) << 16) | ISP_READ(isp, OUTMAILBOX6);
5563 isp_prt(isp, ISP_LOGERR, "unexpected 16 bit RIO handle");
5566 isp_prt(isp, ISP_LOGWARN, "%s: unhandled async code 0x%x", __func__, mbox);
5571 isp_prt(isp, ISP_LOGDEBUG3, "fast post/rio completion of 0x%08x", h1);
5572 isp_fastpost_complete(isp, h1);
5574 isp_prt(isp, ISP_LOGDEBUG3, "fast post/rio completion of 0x%08x", h2);
5575 isp_fastpost_complete(isp, h2);
5581 isp_parse_async_fc(ispsoftc_t *isp, uint16_t mbox)
5586 if (IS_DUALBUS(isp)) {
5587 chan = ISP_READ(isp, OUTMAILBOX6);
5591 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
5594 case ASYNC_SYSTEM_ERROR:
5595 isp->isp_state = ISP_CRASHED;
5596 FCPARAM(isp, chan)->isp_loopstate = LOOP_NIL;
5597 isp_change_fw_state(isp, chan, FW_CONFIG_WAIT);
5599 * Were we waiting for a mailbox command to complete?
5600 * If so, it's dead, so wake up the waiter.
5602 if (isp->isp_mboxbsy) {
5604 isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR;
5605 MBOX_NOTIFY_COMPLETE(isp);
5608 * It's up to the handler for isp_async to reinit stuff and
5609 * restart the firmware
5611 isp_async(isp, ISPASYNC_FW_CRASH);
5614 case ASYNC_RQS_XFER_ERR:
5615 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
5618 case ASYNC_RSP_XFER_ERR:
5619 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
5623 #ifdef ISP_TARGET_MODE
5625 isp_prt(isp, ISP_LOGERR, "ATIO Queue Transfer Error");
5629 isp_prt(isp, ISP_LOGERR, "%s: unexpected ASYNC_QWAKEUP code", __func__);
5632 case ASYNC_CMD_CMPLT:
5633 isp_fastpost_complete(isp, (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1));
5636 case ASYNC_RIOZIO_STALL:
5637 isp_intr_respq(isp);
5640 case ASYNC_CTIO_DONE:
5641 #ifdef ISP_TARGET_MODE
5642 isp_target_async(isp, (ISP_READ(isp, OUTMAILBOX2) << 16) |
5643 ISP_READ(isp, OUTMAILBOX1), mbox);
5645 isp_prt(isp, ISP_LOGWARN, "unexpected ASYNC CTIO done");
5648 case ASYNC_LIP_ERROR:
5649 case ASYNC_LIP_NOS_OLS_RECV:
5650 case ASYNC_LIP_OCCURRED:
5653 * These are broadcast events that have to be sent across
5654 * all active channels.
5656 for (chan = 0; chan < isp->isp_nchan; chan++) {
5657 fcp = FCPARAM(isp, chan);
5658 int topo = fcp->isp_topo;
5660 if (fcp->role == ISP_ROLE_NONE)
5662 if (fcp->isp_loopstate > LOOP_HAVE_LINK)
5663 fcp->isp_loopstate = LOOP_HAVE_LINK;
5664 ISP_SET_SENDMARKER(isp, chan, 1);
5665 isp_async(isp, ISPASYNC_LIP, chan);
5666 #ifdef ISP_TARGET_MODE
5667 isp_target_async(isp, chan, mbox);
5670 * We've had problems with data corruption occurring on
5671 * commands that complete (with no apparent error) after
5672 * we receive a LIP. This has been observed mostly on
5673 * Local Loop topologies. To be safe, let's just mark
5674 * all active initiator commands as dead.
5676 if (topo == TOPO_NL_PORT || topo == TOPO_FL_PORT) {
5678 for (i = j = 0; i < isp->isp_maxcmds; i++) {
5682 hdp = &isp->isp_xflist[i];
5683 if (ISP_H2HT(hdp->handle) != ISP_HANDLE_INITIATOR) {
5687 if (XS_CHANNEL(xs) != chan) {
5691 isp_prt(isp, ISP_LOG_WARN1,
5692 "%d.%d.%jx bus reset set at %s:%u",
5693 XS_CHANNEL(xs), XS_TGT(xs),
5694 (uintmax_t)XS_LUN(xs),
5695 __func__, __LINE__);
5696 XS_SETERR(xs, HBA_BUSRESET);
5699 isp_prt(isp, ISP_LOGERR, lipd, chan, j);
5707 * This is a broadcast event that has to be sent across
5708 * all active channels.
5710 for (chan = 0; chan < isp->isp_nchan; chan++) {
5711 fcp = FCPARAM(isp, chan);
5712 if (fcp->role == ISP_ROLE_NONE)
5714 fcp->isp_linkstate = 1;
5715 if (fcp->isp_loopstate < LOOP_HAVE_LINK)
5716 fcp->isp_loopstate = LOOP_HAVE_LINK;
5717 ISP_SET_SENDMARKER(isp, chan, 1);
5718 isp_async(isp, ISPASYNC_LOOP_UP, chan);
5719 #ifdef ISP_TARGET_MODE
5720 isp_target_async(isp, chan, mbox);
5725 case ASYNC_LOOP_DOWN:
5727 * This is a broadcast event that has to be sent across
5728 * all active channels.
5730 for (chan = 0; chan < isp->isp_nchan; chan++) {
5731 fcp = FCPARAM(isp, chan);
5732 if (fcp->role == ISP_ROLE_NONE)
5734 ISP_SET_SENDMARKER(isp, chan, 1);
5735 fcp->isp_linkstate = 0;
5736 fcp->isp_loopstate = LOOP_NIL;
5737 isp_async(isp, ISPASYNC_LOOP_DOWN, chan);
5738 #ifdef ISP_TARGET_MODE
5739 isp_target_async(isp, chan, mbox);
5744 case ASYNC_LOOP_RESET:
5746 * This is a broadcast event that has to be sent across
5747 * all active channels.
5749 for (chan = 0; chan < isp->isp_nchan; chan++) {
5750 fcp = FCPARAM(isp, chan);
5751 if (fcp->role == ISP_ROLE_NONE)
5753 ISP_SET_SENDMARKER(isp, chan, 1);
5754 if (fcp->isp_loopstate > LOOP_HAVE_LINK)
5755 fcp->isp_loopstate = LOOP_HAVE_LINK;
5756 isp_async(isp, ISPASYNC_LOOP_RESET, chan);
5757 #ifdef ISP_TARGET_MODE
5758 isp_target_async(isp, chan, mbox);
5763 case ASYNC_PDB_CHANGED:
5765 int echan, nphdl, nlstate, reason;
5767 if (IS_23XX(isp) || IS_24XX(isp)) {
5768 nphdl = ISP_READ(isp, OUTMAILBOX1);
5769 nlstate = ISP_READ(isp, OUTMAILBOX2);
5771 nphdl = nlstate = 0xffff;
5774 reason = ISP_READ(isp, OUTMAILBOX3) >> 8;
5777 if (ISP_CAP_MULTI_ID(isp)) {
5778 chan = ISP_READ(isp, OUTMAILBOX3) & 0xff;
5779 if (chan == 0xff || nphdl == NIL_HANDLE) {
5781 echan = isp->isp_nchan - 1;
5782 } else if (chan >= isp->isp_nchan) {
5790 for (; chan <= echan; chan++) {
5791 fcp = FCPARAM(isp, chan);
5792 if (fcp->role == ISP_ROLE_NONE)
5794 if (fcp->isp_loopstate > LOOP_LTEST_DONE) {
5795 if (nphdl != NIL_HANDLE &&
5796 nphdl == fcp->isp_login_hdl &&
5797 reason == PDB24XX_AE_OPN_2)
5799 fcp->isp_loopstate = LOOP_LTEST_DONE;
5800 } else if (fcp->isp_loopstate < LOOP_HAVE_LINK)
5801 fcp->isp_loopstate = LOOP_HAVE_LINK;
5802 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan,
5803 ISPASYNC_CHANGE_PDB, nphdl, nlstate, reason);
5807 case ASYNC_CHANGE_NOTIFY:
5811 portid = ((ISP_READ(isp, OUTMAILBOX1) & 0xff) << 16) |
5812 ISP_READ(isp, OUTMAILBOX2);
5813 if (ISP_CAP_MULTI_ID(isp)) {
5814 chan = ISP_READ(isp, OUTMAILBOX3) & 0xff;
5815 if (chan >= isp->isp_nchan)
5820 fcp = FCPARAM(isp, chan);
5821 if (fcp->role == ISP_ROLE_NONE)
5823 if (fcp->isp_loopstate > LOOP_LTEST_DONE)
5824 fcp->isp_loopstate = LOOP_LTEST_DONE;
5825 else if (fcp->isp_loopstate < LOOP_HAVE_LINK)
5826 fcp->isp_loopstate = LOOP_HAVE_LINK;
5827 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan,
5828 ISPASYNC_CHANGE_SNS, portid);
5831 case ASYNC_ERR_LOGGING_DISABLED:
5832 isp_prt(isp, ISP_LOGWARN, "Error logging disabled (reason 0x%x)",
5833 ISP_READ(isp, OUTMAILBOX1));
5835 case ASYNC_CONNMODE:
5837 * This only applies to 2100 amd 2200 cards
5839 if (!IS_2200(isp) && !IS_2100(isp)) {
5840 isp_prt(isp, ISP_LOGWARN, "bad card for ASYNC_CONNMODE event");
5844 mbox = ISP_READ(isp, OUTMAILBOX1);
5847 isp_prt(isp, ISP_LOGINFO,
5848 "Point-to-Point -> Loop mode");
5851 isp_prt(isp, ISP_LOGINFO,
5852 "Loop -> Point-to-Point mode");
5854 case ISP_CONN_BADLIP:
5855 isp_prt(isp, ISP_LOGWARN,
5856 "Point-to-Point -> Loop mode (BAD LIP)");
5858 case ISP_CONN_FATAL:
5859 isp->isp_state = ISP_CRASHED;
5860 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
5861 isp_async(isp, ISPASYNC_FW_CRASH);
5863 case ISP_CONN_LOOPBACK:
5864 isp_prt(isp, ISP_LOGWARN,
5865 "Looped Back in Point-to-Point mode");
5868 isp_prt(isp, ISP_LOGWARN,
5869 "Unknown connection mode (0x%x)", mbox);
5872 ISP_SET_SENDMARKER(isp, chan, 1);
5873 FCPARAM(isp, chan)->isp_loopstate = LOOP_HAVE_LINK;
5874 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan, ISPASYNC_CHANGE_OTHER);
5876 case ASYNC_P2P_INIT_ERR:
5877 isp_prt(isp, ISP_LOGWARN, "P2P init error (reason 0x%x)",
5878 ISP_READ(isp, OUTMAILBOX1));
5882 isp_prt(isp, ISP_LOGWARN, "Receive Error");
5884 isp_prt(isp, ISP_LOGWARN, "unexpected ASYNC_RCV_ERR");
5887 case ASYNC_RJT_SENT: /* same as ASYNC_QFULL_SENT */
5889 isp_prt(isp, ISP_LOGTDEBUG0, "LS_RJT sent");
5892 isp_prt(isp, ISP_LOGTDEBUG0, "QFULL sent");
5895 case ASYNC_FW_RESTART_COMPLETE:
5896 isp_prt(isp, ISP_LOGDEBUG0, "FW restart complete");
5898 case ASYNC_TEMPERATURE_ALERT:
5899 isp_prt(isp, ISP_LOGERR, "Temperature alert (subcode 0x%x)",
5900 ISP_READ(isp, OUTMAILBOX1));
5902 case ASYNC_AUTOLOAD_FW_COMPLETE:
5903 isp_prt(isp, ISP_LOGDEBUG0, "Autoload FW init complete");
5905 case ASYNC_AUTOLOAD_FW_FAILURE:
5906 isp_prt(isp, ISP_LOGERR, "Autoload FW init failure");
5909 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
5915 * Handle other response entries. A pointer to the request queue output
5916 * index is here in case we want to eat several entries at once, although
5917 * this is not used currently.
5921 isp_handle_other_response(ispsoftc_t *isp, int type, isphdr_t *hp, uint32_t *optrp)
5925 uint32_t hdl, portid;
5929 case RQSTYPE_MARKER:
5930 isp_prt(isp, ISP_LOG_WARN1, "Marker Response");
5932 case RQSTYPE_RPT_ID_ACQ:
5933 isp_get_ridacq(isp, (isp_ridacq_t *)hp, &rid);
5934 portid = (uint32_t)rid.ridacq_vp_port_hi << 16 |
5935 rid.ridacq_vp_port_lo;
5936 if (rid.ridacq_format == 0) {
5937 for (chan = 0; chan < isp->isp_nchan; chan++) {
5938 fcparam *fcp = FCPARAM(isp, chan);
5939 if (fcp->role == ISP_ROLE_NONE)
5941 c = (chan == 0) ? 127 : (chan - 1);
5942 if (rid.ridacq_map[c / 16] & (1 << (c % 16)) ||
5944 fcp->isp_loopstate = LOOP_HAVE_LINK;
5945 isp_async(isp, ISPASYNC_CHANGE_NOTIFY,
5946 chan, ISPASYNC_CHANGE_OTHER);
5948 fcp->isp_loopstate = LOOP_NIL;
5949 isp_async(isp, ISPASYNC_LOOP_DOWN,
5954 fcparam *fcp = FCPARAM(isp, rid.ridacq_vp_index);
5955 if (rid.ridacq_vp_status == RIDACQ_STS_COMPLETE ||
5956 rid.ridacq_vp_status == RIDACQ_STS_CHANGED) {
5957 fcp->isp_topo = (rid.ridacq_map[0] >> 9) & 0x7;
5958 fcp->isp_portid = portid;
5959 fcp->isp_loopstate = LOOP_HAVE_ADDR;
5960 isp_async(isp, ISPASYNC_CHANGE_NOTIFY,
5961 rid.ridacq_vp_index, ISPASYNC_CHANGE_OTHER);
5963 fcp->isp_loopstate = LOOP_NIL;
5964 isp_async(isp, ISPASYNC_LOOP_DOWN,
5965 rid.ridacq_vp_index);
5969 case RQSTYPE_CT_PASSTHRU:
5970 case RQSTYPE_VP_MODIFY:
5971 case RQSTYPE_VP_CTRL:
5973 ISP_IOXGET_32(isp, (uint32_t *)(hp + 1), hdl);
5974 ptr = isp_find_xs(isp, hdl);
5976 isp_destroy_handle(isp, hdl);
5977 memcpy(ptr, hp, QENTRY_LEN);
5983 case RQSTYPE_NOTIFY:
5984 case RQSTYPE_NOTIFY_ACK:
5990 case RQSTYPE_ABTS_RCVD:
5991 case RQSTYPE_ABTS_RSP:
5992 #ifdef ISP_TARGET_MODE
5993 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp))
5997 case RQSTYPE_REQUEST:
6000 if (type != isp_get_response_type(isp, hp)) {
6002 * This is questionable- we're just papering over
6003 * something we've seen on SMP linux in target
6004 * mode- we don't really know what's happening
6005 * here that causes us to think we've gotten
6006 * an entry, but that either the entry isn't
6007 * filled out yet or our CPU read data is stale.
6009 isp_prt(isp, ISP_LOGINFO,
6010 "unstable type in response queue");
6013 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
6014 isp_get_response_type(isp, hp));
6020 isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
6022 switch (sp->req_completion_status & 0xff) {
6025 XS_SETERR(xs, HBA_NOERROR);
6029 case RQCS_INCOMPLETE:
6030 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
6031 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "Selection Timeout @ %s:%d", __func__, __LINE__);
6033 XS_SETERR(xs, HBA_SELTIMEOUT);
6034 *rp = XS_XFRLEN(xs);
6038 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Incomplete, state 0x%x", sp->req_state_flags);
6041 case RQCS_DMA_ERROR:
6042 isp_xs_prt(isp, xs, ISP_LOGERR, "DMA Error");
6043 *rp = XS_XFRLEN(xs);
6046 case RQCS_TRANSPORT_ERROR:
6049 ISP_SNPRINTF(buf, sizeof (buf), "states=>");
6050 if (sp->req_state_flags & RQSF_GOT_BUS) {
6051 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
6053 if (sp->req_state_flags & RQSF_GOT_TARGET) {
6054 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
6056 if (sp->req_state_flags & RQSF_SENT_CDB) {
6057 ISP_SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
6059 if (sp->req_state_flags & RQSF_XFRD_DATA) {
6060 ISP_SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
6062 if (sp->req_state_flags & RQSF_GOT_STATUS) {
6063 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
6065 if (sp->req_state_flags & RQSF_GOT_SENSE) {
6066 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
6068 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
6069 ISP_SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
6071 ISP_SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
6072 if (sp->req_status_flags & RQSTF_DISCONNECT) {
6073 ISP_SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
6075 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
6076 ISP_SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
6078 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
6079 ISP_SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
6081 if (sp->req_status_flags & RQSTF_BUS_RESET) {
6082 ISP_SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
6084 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
6085 ISP_SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
6087 if (sp->req_status_flags & RQSTF_ABORTED) {
6088 ISP_SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
6090 if (sp->req_status_flags & RQSTF_TIMEOUT) {
6091 ISP_SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
6093 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
6094 ISP_SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
6096 isp_xs_prt(isp, xs, ISP_LOGERR, "Transport Error: %s", buf);
6097 *rp = XS_XFRLEN(xs);
6100 case RQCS_RESET_OCCURRED:
6103 isp_xs_prt(isp, xs, ISP_LOGWARN, "Bus Reset destroyed command");
6104 for (chan = 0; chan < isp->isp_nchan; chan++) {
6105 FCPARAM(isp, chan)->sendmarker = 1;
6108 XS_SETERR(xs, HBA_BUSRESET);
6110 *rp = XS_XFRLEN(xs);
6114 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Aborted");
6115 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 1);
6117 XS_SETERR(xs, HBA_ABORTED);
6122 isp_xs_prt(isp, xs, ISP_LOGWARN, "Command timed out");
6124 * XXX: Check to see if we logged out of the device.
6127 XS_SETERR(xs, HBA_CMDTIMEOUT);
6131 case RQCS_DATA_OVERRUN:
6132 XS_SET_RESID(xs, sp->req_resid);
6133 isp_xs_prt(isp, xs, ISP_LOGERR, "data overrun (%ld)", (long) XS_GET_RESID(xs));
6135 XS_SETERR(xs, HBA_DATAOVR);
6139 case RQCS_COMMAND_OVERRUN:
6140 isp_xs_prt(isp, xs, ISP_LOGERR, "command overrun");
6143 case RQCS_STATUS_OVERRUN:
6144 isp_xs_prt(isp, xs, ISP_LOGERR, "status overrun");
6147 case RQCS_BAD_MESSAGE:
6148 isp_xs_prt(isp, xs, ISP_LOGERR, "msg not COMMAND COMPLETE after status");
6151 case RQCS_NO_MESSAGE_OUT:
6152 isp_xs_prt(isp, xs, ISP_LOGERR, "No MESSAGE OUT phase after selection");
6155 case RQCS_EXT_ID_FAILED:
6156 isp_xs_prt(isp, xs, ISP_LOGERR, "EXTENDED IDENTIFY failed");
6159 case RQCS_IDE_MSG_FAILED:
6160 isp_xs_prt(isp, xs, ISP_LOGERR, "INITIATOR DETECTED ERROR rejected");
6163 case RQCS_ABORT_MSG_FAILED:
6164 isp_xs_prt(isp, xs, ISP_LOGERR, "ABORT OPERATION rejected");
6167 case RQCS_REJECT_MSG_FAILED:
6168 isp_xs_prt(isp, xs, ISP_LOGERR, "MESSAGE REJECT rejected");
6171 case RQCS_NOP_MSG_FAILED:
6172 isp_xs_prt(isp, xs, ISP_LOGERR, "NOP rejected");
6175 case RQCS_PARITY_ERROR_MSG_FAILED:
6176 isp_xs_prt(isp, xs, ISP_LOGERR, "MESSAGE PARITY ERROR rejected");
6179 case RQCS_DEVICE_RESET_MSG_FAILED:
6180 isp_xs_prt(isp, xs, ISP_LOGWARN, "BUS DEVICE RESET rejected");
6183 case RQCS_ID_MSG_FAILED:
6184 isp_xs_prt(isp, xs, ISP_LOGERR, "IDENTIFY rejected");
6187 case RQCS_UNEXP_BUS_FREE:
6188 isp_xs_prt(isp, xs, ISP_LOGERR, "Unexpected Bus Free");
6191 case RQCS_DATA_UNDERRUN:
6194 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
6195 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
6196 isp_xs_prt(isp, xs, ISP_LOGWARN, bun, XS_XFRLEN(xs), sp->req_resid, (ru_marked)? "marked" : "not marked");
6198 XS_SETERR(xs, HBA_BOTCH);
6203 XS_SET_RESID(xs, sp->req_resid);
6205 XS_SETERR(xs, HBA_NOERROR);
6210 case RQCS_XACT_ERR1:
6211 isp_xs_prt(isp, xs, ISP_LOGERR, "HBA attempted queued transaction with disconnect not set");
6214 case RQCS_XACT_ERR2:
6215 isp_xs_prt(isp, xs, ISP_LOGERR,
6216 "HBA attempted queued transaction to target routine %jx",
6217 (uintmax_t)XS_LUN(xs));
6220 case RQCS_XACT_ERR3:
6221 isp_xs_prt(isp, xs, ISP_LOGERR, "HBA attempted queued cmd when queueing disabled");
6224 case RQCS_BAD_ENTRY:
6225 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
6228 case RQCS_QUEUE_FULL:
6229 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "internal queues full status 0x%x", *XS_STSP(xs));
6232 * If QFULL or some other status byte is set, then this
6233 * isn't an error, per se.
6235 * Unfortunately, some QLogic f/w writers have, in
6236 * some cases, omitted to *set* status to QFULL.
6239 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
6240 XS_SETERR(xs, HBA_NOERROR);
6245 *XS_STSP(xs) = SCSI_QFULL;
6246 XS_SETERR(xs, HBA_NOERROR);
6249 case RQCS_PHASE_SKIPPED:
6250 isp_xs_prt(isp, xs, ISP_LOGERR, "SCSI phase skipped");
6253 case RQCS_ARQS_FAILED:
6254 isp_xs_prt(isp, xs, ISP_LOGERR, "Auto Request Sense Failed");
6256 XS_SETERR(xs, HBA_ARQFAIL);
6260 case RQCS_WIDE_FAILED:
6261 isp_xs_prt(isp, xs, ISP_LOGERR, "Wide Negotiation Failed");
6263 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
6264 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
6265 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
6269 XS_SETERR(xs, HBA_NOERROR);
6273 case RQCS_SYNCXFER_FAILED:
6274 isp_xs_prt(isp, xs, ISP_LOGERR, "SDTR Message Failed");
6276 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
6277 sdp += XS_CHANNEL(xs);
6278 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
6279 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
6284 case RQCS_LVD_BUSERR:
6285 isp_xs_prt(isp, xs, ISP_LOGERR, "Bad LVD condition");
6288 case RQCS_PORT_UNAVAILABLE:
6290 * No such port on the loop. Moral equivalent of SELTIMEO
6292 case RQCS_PORT_LOGGED_OUT:
6295 uint8_t sts = sp->req_completion_status & 0xff;
6296 fcparam *fcp = FCPARAM(isp, 0);
6300 * It was there (maybe)- treat as a selection timeout.
6302 if (sts == RQCS_PORT_UNAVAILABLE) {
6303 reason = "unavailable";
6308 isp_prt(isp, ISP_LOGINFO, "port %s for target %d", reason, XS_TGT(xs));
6310 /* XXX: Should we trigger rescan or FW announce change? */
6313 lp = &fcp->portdb[XS_TGT(xs)];
6314 if (lp->state == FC_PORTDB_STATE_ZOMBIE) {
6315 *XS_STSP(xs) = SCSI_BUSY;
6316 XS_SETERR(xs, HBA_TGTBSY);
6318 XS_SETERR(xs, HBA_SELTIMEOUT);
6322 case RQCS_PORT_CHANGED:
6323 isp_prt(isp, ISP_LOGWARN, "port changed for target %d", XS_TGT(xs));
6325 *XS_STSP(xs) = SCSI_BUSY;
6326 XS_SETERR(xs, HBA_TGTBSY);
6330 case RQCS_PORT_BUSY:
6331 isp_prt(isp, ISP_LOGWARN, "port busy for target %d", XS_TGT(xs));
6333 *XS_STSP(xs) = SCSI_BUSY;
6334 XS_SETERR(xs, HBA_TGTBSY);
6339 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x", sp->req_completion_status);
6343 XS_SETERR(xs, HBA_BOTCH);
6348 isp_parse_status_24xx(ispsoftc_t *isp, isp24xx_statusreq_t *sp, XS_T *xs, long *rp)
6350 int ru_marked, sv_marked;
6351 int chan = XS_CHANNEL(xs);
6353 switch (sp->req_completion_status) {
6356 XS_SETERR(xs, HBA_NOERROR);
6360 case RQCS_DMA_ERROR:
6361 isp_xs_prt(isp, xs, ISP_LOGERR, "DMA error");
6364 case RQCS_TRANSPORT_ERROR:
6365 isp_xs_prt(isp, xs, ISP_LOGERR, "Transport Error");
6368 case RQCS_RESET_OCCURRED:
6369 isp_xs_prt(isp, xs, ISP_LOGWARN, "reset destroyed command");
6370 FCPARAM(isp, chan)->sendmarker = 1;
6372 XS_SETERR(xs, HBA_BUSRESET);
6377 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Aborted");
6378 FCPARAM(isp, chan)->sendmarker = 1;
6380 XS_SETERR(xs, HBA_ABORTED);
6385 isp_xs_prt(isp, xs, ISP_LOGWARN, "Command Timed Out");
6387 XS_SETERR(xs, HBA_CMDTIMEOUT);
6391 case RQCS_DATA_OVERRUN:
6392 XS_SET_RESID(xs, sp->req_resid);
6393 isp_xs_prt(isp, xs, ISP_LOGERR, "Data Overrun");
6395 XS_SETERR(xs, HBA_DATAOVR);
6399 case RQCS_24XX_DRE: /* data reassembly error */
6400 isp_prt(isp, ISP_LOGERR, "Chan %d data reassembly error for target %d", chan, XS_TGT(xs));
6402 XS_SETERR(xs, HBA_ABORTED);
6404 *rp = XS_XFRLEN(xs);
6407 case RQCS_24XX_TABORT: /* aborted by target */
6408 isp_prt(isp, ISP_LOGERR, "Chan %d target %d sent ABTS", chan, XS_TGT(xs));
6410 XS_SETERR(xs, HBA_ABORTED);
6414 case RQCS_DATA_UNDERRUN:
6415 ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
6417 * We can get an underrun w/o things being marked
6418 * if we got a non-zero status.
6420 sv_marked = (sp->req_scsi_status & (RQCS_SV|RQCS_RV)) != 0;
6421 if ((ru_marked == 0 && sv_marked == 0) ||
6422 (sp->req_resid > XS_XFRLEN(xs))) {
6423 isp_xs_prt(isp, xs, ISP_LOGWARN, bun, XS_XFRLEN(xs), sp->req_resid, (ru_marked)? "marked" : "not marked");
6425 XS_SETERR(xs, HBA_BOTCH);
6429 XS_SET_RESID(xs, sp->req_resid);
6430 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "Data Underrun (%d) for command 0x%x", sp->req_resid, XS_CDBP(xs)[0] & 0xff);
6432 XS_SETERR(xs, HBA_NOERROR);
6436 case RQCS_PORT_UNAVAILABLE:
6438 * No such port on the loop. Moral equivalent of SELTIMEO
6440 case RQCS_PORT_LOGGED_OUT:
6443 uint8_t sts = sp->req_completion_status & 0xff;
6444 fcparam *fcp = FCPARAM(isp, XS_CHANNEL(xs));
6448 * It was there (maybe)- treat as a selection timeout.
6450 if (sts == RQCS_PORT_UNAVAILABLE) {
6451 reason = "unavailable";
6456 isp_prt(isp, ISP_LOGINFO, "Chan %d port %s for target %d",
6457 chan, reason, XS_TGT(xs));
6459 /* XXX: Should we trigger rescan or FW announce change? */
6462 lp = &fcp->portdb[XS_TGT(xs)];
6463 if (lp->state == FC_PORTDB_STATE_ZOMBIE) {
6464 *XS_STSP(xs) = SCSI_BUSY;
6465 XS_SETERR(xs, HBA_TGTBSY);
6467 XS_SETERR(xs, HBA_SELTIMEOUT);
6471 case RQCS_PORT_CHANGED:
6472 isp_prt(isp, ISP_LOGWARN, "port changed for target %d chan %d", XS_TGT(xs), chan);
6474 *XS_STSP(xs) = SCSI_BUSY;
6475 XS_SETERR(xs, HBA_TGTBSY);
6479 case RQCS_24XX_ENOMEM: /* f/w resource unavailable */
6480 isp_prt(isp, ISP_LOGWARN, "f/w resource unavailable for target %d chan %d", XS_TGT(xs), chan);
6482 *XS_STSP(xs) = SCSI_BUSY;
6483 XS_SETERR(xs, HBA_TGTBSY);
6487 case RQCS_24XX_TMO: /* task management overrun */
6488 isp_prt(isp, ISP_LOGWARN, "command for target %d overlapped task management for chan %d", XS_TGT(xs), chan);
6490 *XS_STSP(xs) = SCSI_BUSY;
6491 XS_SETERR(xs, HBA_TGTBSY);
6496 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x on chan %d", sp->req_completion_status, chan);
6500 XS_SETERR(xs, HBA_BOTCH);
6505 isp_fastpost_complete(ispsoftc_t *isp, uint32_t fph)
6512 xs = isp_find_xs(isp, fph);
6514 isp_prt(isp, ISP_LOGWARN,
6515 "Command for fast post handle 0x%x not found", fph);
6518 isp_destroy_handle(isp, fph);
6521 * Since we don't have a result queue entry item,
6522 * we must believe that SCSI status is zero and
6523 * that all data transferred.
6525 XS_SET_RESID(xs, 0);
6526 *XS_STSP(xs) = SCSI_GOOD;
6527 if (XS_XFRLEN(xs)) {
6528 ISP_DMAFREE(isp, xs, fph);
6533 #define ISP_SCSI_IBITS(op) (mbpscsi[((op)<<1)])
6534 #define ISP_SCSI_OBITS(op) (mbpscsi[((op)<<1) + 1])
6535 #define ISP_SCSI_OPMAP(in, out) in, out
6536 static const uint8_t mbpscsi[] = {
6537 ISP_SCSI_OPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
6538 ISP_SCSI_OPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
6539 ISP_SCSI_OPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
6540 ISP_SCSI_OPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
6541 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
6542 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
6543 ISP_SCSI_OPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
6544 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
6545 ISP_SCSI_OPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
6546 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x09: */
6547 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0a: */
6548 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0b: */
6549 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0c: */
6550 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0d: */
6551 ISP_SCSI_OPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
6552 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0f: */
6553 ISP_SCSI_OPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
6554 ISP_SCSI_OPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
6555 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
6556 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
6557 ISP_SCSI_OPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
6558 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
6559 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
6560 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
6561 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
6562 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
6563 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
6564 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
6565 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
6566 ISP_SCSI_OPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
6567 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x1e: */
6568 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
6569 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
6570 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
6571 ISP_SCSI_OPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
6572 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
6573 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
6574 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
6575 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
6576 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
6577 ISP_SCSI_OPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
6578 ISP_SCSI_OPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
6579 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
6580 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2b: */
6581 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2c: */
6582 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2d: */
6583 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2e: */
6584 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2f: */
6585 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
6586 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
6587 ISP_SCSI_OPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
6588 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
6589 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
6590 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
6591 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
6592 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
6593 ISP_SCSI_OPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
6594 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
6595 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
6596 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3b: */
6597 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3c: */
6598 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3d: */
6599 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3e: */
6600 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3f: */
6601 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
6602 ISP_SCSI_OPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
6603 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
6604 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x43: */
6605 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x44: */
6606 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
6607 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
6608 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x47: */
6609 ISP_SCSI_OPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
6610 ISP_SCSI_OPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
6611 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
6612 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
6613 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4c: */
6614 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4d: */
6615 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4e: */
6616 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4f: */
6617 ISP_SCSI_OPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
6618 ISP_SCSI_OPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
6619 ISP_SCSI_OPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
6620 ISP_SCSI_OPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
6621 ISP_SCSI_OPMAP(0xcf, 0x01), /* 0x54: EXECUCUTE COMMAND IOCB A64 */
6622 ISP_SCSI_OPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
6623 ISP_SCSI_OPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
6624 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x57: */
6625 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x58: */
6626 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x59: */
6627 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
6628 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
6629 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
6630 ISP_SCSI_OPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
6632 #define MAX_SCSI_OPCODE 0x5d
6634 static const char *scsi_mbcmd_names[] = {
6651 "INIT REQUEST QUEUE",
6652 "INIT RESULT QUEUE",
6662 "SINGLE STEP QUEUE",
6664 "GET DEV QUEUE STATUS",
6666 "GET FIRMWARE STATUS",
6668 "GET SELECT TIMEOUT",
6670 "GET TAG AGE LIMIT",
6672 "GET ACT NEG STATE",
6673 "GET ASYNC DATA SETUP TIME",
6675 "GET TARGET PARAMS",
6676 "GET DEV QUEUE PARAMS",
6677 "GET RESET DELAY PARAMS",
6684 "SET SELECT TIMEOUT",
6686 "SET TAG AGE LIMIT",
6688 "SET ACT NEG STATE",
6689 "SET ASYNC DATA SETUP TIME",
6690 "SET PCI CONTROL PARAMS",
6691 "SET TARGET PARAMS",
6692 "SET DEV QUEUE PARAMS",
6693 "SET RESET DELAY PARAMS",
6699 "RETURN BIOS BLOCK ADDR",
6700 "WRITE FOUR RAM WORDS",
6704 "SET SYSTEM PARAMETER",
6705 "GET SYSTEM PARAMETER",
6707 "GET SCAM CONFIGURATION",
6708 "SET SCAM CONFIGURATION",
6709 "SET FIRMWARE FEATURES",
6710 "GET FIRMWARE FEATURES",
6717 "INITIALIZE REQUEST QUEUE A64",
6718 "INITIALIZE RESPONSE QUEUE A64",
6720 "ENABLE TARGET MODE",
6721 "GET TARGET MODE STATE",
6725 "SET DATA OVERRUN RECOVERY MODE",
6726 "GET DATA OVERRUN RECOVERY MODE",
6731 #define ISP_FC_IBITS(op) ((mbpfc[((op)<<3) + 0] << 24) | (mbpfc[((op)<<3) + 1] << 16) | (mbpfc[((op)<<3) + 2] << 8) | (mbpfc[((op)<<3) + 3]))
6732 #define ISP_FC_OBITS(op) ((mbpfc[((op)<<3) + 4] << 24) | (mbpfc[((op)<<3) + 5] << 16) | (mbpfc[((op)<<3) + 6] << 8) | (mbpfc[((op)<<3) + 7]))
6734 #define ISP_FC_OPMAP(in0, out0) 0, 0, 0, in0, 0, 0, 0, out0
6735 #define ISP_FC_OPMAP_HALF(in1, in0, out1, out0) 0, 0, in1, in0, 0, 0, out1, out0
6736 #define ISP_FC_OPMAP_FULL(in3, in2, in1, in0, out3, out2, out1, out0) in3, in2, in1, in0, out3, out2, out1, out0
6737 static const uint32_t mbpfc[] = {
6738 ISP_FC_OPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
6739 ISP_FC_OPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
6740 ISP_FC_OPMAP_HALF(0x07, 0xff, 0x00, 0x03), /* 0x02: MBOX_EXEC_FIRMWARE */
6741 ISP_FC_OPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
6742 ISP_FC_OPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
6743 ISP_FC_OPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
6744 ISP_FC_OPMAP_FULL(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
6745 ISP_FC_OPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
6746 ISP_FC_OPMAP_FULL(0x0, 0x0, 0x0, 0x01, 0x0, 0x3, 0x80, 0x7f), /* 0x08: MBOX_ABOUT_FIRMWARE */
6747 ISP_FC_OPMAP(0xdf, 0x01), /* 0x09: MBOX_LOAD_RISC_RAM_2100 */
6748 ISP_FC_OPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
6749 ISP_FC_OPMAP_HALF(0x1, 0xff, 0x0, 0x01), /* 0x0b: MBOX_LOAD_RISC_RAM */
6750 ISP_FC_OPMAP(0x00, 0x00), /* 0x0c: */
6751 ISP_FC_OPMAP_HALF(0x1, 0x0f, 0x0, 0x01), /* 0x0d: MBOX_WRITE_RAM_WORD_EXTENDED */
6752 ISP_FC_OPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
6753 ISP_FC_OPMAP_HALF(0x1, 0x03, 0x0, 0x0d), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED */
6754 ISP_FC_OPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
6755 ISP_FC_OPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
6756 ISP_FC_OPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
6757 ISP_FC_OPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
6758 ISP_FC_OPMAP_HALF(0x1, 0xff, 0x0, 0x03), /* 0x14: MBOX_STOP_FIRMWARE */
6759 ISP_FC_OPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
6760 ISP_FC_OPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
6761 ISP_FC_OPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
6762 ISP_FC_OPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
6763 ISP_FC_OPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
6764 ISP_FC_OPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
6765 ISP_FC_OPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
6766 ISP_FC_OPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
6767 ISP_FC_OPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
6768 ISP_FC_OPMAP(0x00, 0x00), /* 0x1e: */
6769 ISP_FC_OPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
6770 ISP_FC_OPMAP_HALF(0x2, 0x01, 0x7e, 0xcf), /* 0x20: MBOX_GET_LOOP_ID */
6771 ISP_FC_OPMAP(0x00, 0x00), /* 0x21: */
6772 ISP_FC_OPMAP(0x03, 0x4b), /* 0x22: MBOX_GET_TIMEOUT_PARAMS */
6773 ISP_FC_OPMAP(0x00, 0x00), /* 0x23: */
6774 ISP_FC_OPMAP(0x00, 0x00), /* 0x24: */
6775 ISP_FC_OPMAP(0x00, 0x00), /* 0x25: */
6776 ISP_FC_OPMAP(0x00, 0x00), /* 0x26: */
6777 ISP_FC_OPMAP(0x00, 0x00), /* 0x27: */
6778 ISP_FC_OPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
6779 ISP_FC_OPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
6780 ISP_FC_OPMAP(0x00, 0x00), /* 0x2a: */
6781 ISP_FC_OPMAP(0x00, 0x00), /* 0x2b: */
6782 ISP_FC_OPMAP(0x00, 0x00), /* 0x2c: */
6783 ISP_FC_OPMAP(0x00, 0x00), /* 0x2d: */
6784 ISP_FC_OPMAP(0x00, 0x00), /* 0x2e: */
6785 ISP_FC_OPMAP(0x00, 0x00), /* 0x2f: */
6786 ISP_FC_OPMAP(0x00, 0x00), /* 0x30: */
6787 ISP_FC_OPMAP(0x00, 0x00), /* 0x31: */
6788 ISP_FC_OPMAP(0x4b, 0x4b), /* 0x32: MBOX_SET_TIMEOUT_PARAMS */
6789 ISP_FC_OPMAP(0x00, 0x00), /* 0x33: */
6790 ISP_FC_OPMAP(0x00, 0x00), /* 0x34: */
6791 ISP_FC_OPMAP(0x00, 0x00), /* 0x35: */
6792 ISP_FC_OPMAP(0x00, 0x00), /* 0x36: */
6793 ISP_FC_OPMAP(0x00, 0x00), /* 0x37: */
6794 ISP_FC_OPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
6795 ISP_FC_OPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
6796 ISP_FC_OPMAP(0x00, 0x00), /* 0x3a: */
6797 ISP_FC_OPMAP(0x00, 0x00), /* 0x3b: */
6798 ISP_FC_OPMAP(0x00, 0x00), /* 0x3c: */
6799 ISP_FC_OPMAP(0x00, 0x00), /* 0x3d: */
6800 ISP_FC_OPMAP(0x00, 0x00), /* 0x3e: */
6801 ISP_FC_OPMAP(0x00, 0x00), /* 0x3f: */
6802 ISP_FC_OPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
6803 ISP_FC_OPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
6804 ISP_FC_OPMAP_HALF(0x0, 0x01, 0x1f, 0xcf), /* 0x42: MBOX_GET_RESOURCE_COUNT */
6805 ISP_FC_OPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_OFFLINE_MODE */
6806 ISP_FC_OPMAP(0x00, 0x00), /* 0x44: */
6807 ISP_FC_OPMAP(0x00, 0x00), /* 0x45: */
6808 ISP_FC_OPMAP(0x00, 0x00), /* 0x46: */
6809 ISP_FC_OPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
6810 ISP_FC_OPMAP(0xcf, 0x0f), /* 0x48: MBOX_INIT_FIRMWARE_MULTI_ID */
6811 ISP_FC_OPMAP(0xcd, 0x01), /* 0x49: MBOX_GET_VP_DATABASE */
6812 ISP_FC_OPMAP_HALF(0x2, 0xcd, 0x0, 0x01), /* 0x4a: MBOX_GET_VP_DATABASE_ENTRY */
6813 ISP_FC_OPMAP(0x00, 0x00), /* 0x4b: */
6814 ISP_FC_OPMAP(0x00, 0x00), /* 0x4c: */
6815 ISP_FC_OPMAP(0x00, 0x00), /* 0x4d: */
6816 ISP_FC_OPMAP(0x00, 0x00), /* 0x4e: */
6817 ISP_FC_OPMAP(0x00, 0x00), /* 0x4f: */
6818 ISP_FC_OPMAP(0x00, 0x00), /* 0x50: */
6819 ISP_FC_OPMAP(0x00, 0x00), /* 0x51: */
6820 ISP_FC_OPMAP(0x00, 0x00), /* 0x52: */
6821 ISP_FC_OPMAP(0x00, 0x00), /* 0x53: */
6822 ISP_FC_OPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
6823 ISP_FC_OPMAP(0x00, 0x00), /* 0x55: */
6824 ISP_FC_OPMAP(0x00, 0x00), /* 0x56: */
6825 ISP_FC_OPMAP(0x00, 0x00), /* 0x57: */
6826 ISP_FC_OPMAP(0x00, 0x00), /* 0x58: */
6827 ISP_FC_OPMAP(0x00, 0x00), /* 0x59: */
6828 ISP_FC_OPMAP(0x00, 0x00), /* 0x5a: */
6829 ISP_FC_OPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
6830 ISP_FC_OPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
6831 ISP_FC_OPMAP(0x07, 0x1f), /* 0x5d: MBOX_GET_SET_DATA_RATE */
6832 ISP_FC_OPMAP(0x00, 0x00), /* 0x5e: */
6833 ISP_FC_OPMAP(0x00, 0x00), /* 0x5f: */
6834 ISP_FC_OPMAP(0xcf, 0x0f), /* 0x60: MBOX_INIT_FIRMWARE */
6835 ISP_FC_OPMAP(0x00, 0x00), /* 0x61: */
6836 ISP_FC_OPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
6837 ISP_FC_OPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
6838 ISP_FC_OPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
6839 ISP_FC_OPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
6840 ISP_FC_OPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
6841 ISP_FC_OPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
6842 ISP_FC_OPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
6843 ISP_FC_OPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
6844 ISP_FC_OPMAP_HALF(0x6, 0x03, 0x0, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
6845 ISP_FC_OPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
6846 ISP_FC_OPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
6847 ISP_FC_OPMAP(0x00, 0x00), /* 0x6d: */
6848 ISP_FC_OPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
6849 ISP_FC_OPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
6850 ISP_FC_OPMAP_HALF(0x02, 0x03, 0x00, 0x03), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
6851 ISP_FC_OPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
6852 ISP_FC_OPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
6853 ISP_FC_OPMAP(0x00, 0x00), /* 0x73: */
6854 ISP_FC_OPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
6855 ISP_FC_OPMAP_HALF(0x03, 0xcf, 0x00, 0x07), /* 0x75: GET PORT/NODE NAME LIST */
6856 ISP_FC_OPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
6857 ISP_FC_OPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
6858 ISP_FC_OPMAP(0x00, 0x00), /* 0x78: */
6859 ISP_FC_OPMAP(0x00, 0x00), /* 0x79: */
6860 ISP_FC_OPMAP(0x00, 0x00), /* 0x7a: */
6861 ISP_FC_OPMAP(0x00, 0x00), /* 0x7b: */
6862 ISP_FC_OPMAP_HALF(0x03, 0x4f, 0x00, 0x07), /* 0x7c: Get ID List */
6863 ISP_FC_OPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
6864 ISP_FC_OPMAP(0x0f, 0x01) /* 0x7e: LUN RESET */
6866 #define MAX_FC_OPCODE 0x7e
6870 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
6871 * do not access at this time in the core driver. The caller is
6872 * responsible for setting this register first (Gross!). The assumption
6873 * is that we won't overflow.
6876 static const char *fc_mbcmd_names[] = {
6890 "WRITE RAM WORD EXTENDED",
6892 "READ RAM WORD EXTENDED",
6893 "INIT REQUEST QUEUE", /* 10h */
6894 "INIT RESULT QUEUE",
6904 "SINGLE STEP QUEUE",
6906 "GET DEV QUEUE STATUS",
6908 "GET FIRMWARE STATUS",
6909 "GET LOOP ID", /* 20h */
6911 "GET TIMEOUT PARAMS",
6917 "GET FIRMWARE OPTIONS",
6918 "GET PORT QUEUE PARAMS",
6919 "GENERATE SYSTEM ERROR",
6925 "WRITE SFP", /* 30h */
6927 "SET TIMEOUT PARAMS",
6933 "SET FIRMWARE OPTIONS",
6934 "SET PORT QUEUE PARAMS",
6938 "RESTART NIC FIRMWARE",
6941 "LOOP PORT BYPASS", /* 40h */
6943 "GET RESOURCE COUNT",
6944 "REQUEST NON PARTICIPATING MODE",
6945 "DIAGNOSTIC ECHO TEST",
6946 "DIAGNOSTIC LOOPBACK",
6948 "GET PORT DATABASE ENHANCED",
6949 "INIT FIRMWARE MULTI ID",
6951 "GET VP DATABASE ENTRY",
6957 "GET FCF LIST", /* 50h */
6958 "GET DCBX PARAMETERS",
6969 "FIRMWARE HEARTBEAT",
6970 "GET/SET DATA RATE",
6973 "INIT FIRMWARE", /* 60h */
6974 "GET INIT CONTROL BLOCK",
6976 "GET FC-AL POSITION MAP",
6977 "GET PORT DATABASE",
6986 "GET LINK STATS & PRIVATE DATA CNTS",
6989 "SEND CHANGE REQUEST", /* 70h */
6994 "GET PORT/NODE NAME LIST",
6996 "INITIALIZE IP MAILBOX",
7007 isp_mboxcmd(ispsoftc_t *isp, mbreg_t *mbp)
7009 const char *cname, *xname, *sname;
7010 char tname[16], mname[16];
7011 unsigned int ibits, obits, box, opcode;
7013 opcode = mbp->param[0];
7015 if (opcode > MAX_FC_OPCODE) {
7016 mbp->param[0] = MBOX_INVALID_COMMAND;
7017 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
7020 cname = fc_mbcmd_names[opcode];
7021 ibits = ISP_FC_IBITS(opcode);
7022 obits = ISP_FC_OBITS(opcode);
7024 if (opcode > MAX_SCSI_OPCODE) {
7025 mbp->param[0] = MBOX_INVALID_COMMAND;
7026 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
7029 cname = scsi_mbcmd_names[opcode];
7030 ibits = ISP_SCSI_IBITS(opcode);
7031 obits = ISP_SCSI_OBITS(opcode);
7033 if (cname == NULL) {
7035 ISP_SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
7037 isp_prt(isp, ISP_LOGDEBUG3, "Mailbox Command '%s'", cname);
7040 * Pick up any additional bits that the caller might have set.
7042 ibits |= mbp->ibits;
7043 obits |= mbp->obits;
7046 * Mask any bits that the caller wants us to mask
7048 ibits &= mbp->ibitm;
7049 obits &= mbp->obitm;
7052 if (ibits == 0 && obits == 0) {
7053 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
7054 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
7059 * Get exclusive usage of mailbox registers.
7061 if (MBOX_ACQUIRE(isp)) {
7062 mbp->param[0] = MBOX_REGS_BUSY;
7066 for (box = 0; box < ISP_NMBOX(isp); box++) {
7067 if (ibits & (1 << box)) {
7068 isp_prt(isp, ISP_LOGDEBUG3, "IN mbox %d = 0x%04x", box,
7070 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
7072 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
7075 isp->isp_lastmbxcmd = opcode;
7078 * We assume that we can't overwrite a previous command.
7080 isp->isp_obits = obits;
7081 isp->isp_mboxbsy = 1;
7084 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
7087 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_SET_HOST_INT);
7089 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
7093 * While we haven't finished the command, spin our wheels here.
7095 MBOX_WAIT_COMPLETE(isp, mbp);
7098 * Did the command time out?
7100 if (mbp->param[0] == MBOX_TIMEOUT) {
7101 isp->isp_mboxbsy = 0;
7107 * Copy back output registers.
7109 for (box = 0; box < ISP_NMBOX(isp); box++) {
7110 if (obits & (1 << box)) {
7111 mbp->param[box] = isp->isp_mboxtmp[box];
7112 isp_prt(isp, ISP_LOGDEBUG3, "OUT mbox %d = 0x%04x", box,
7117 isp->isp_mboxbsy = 0;
7120 if (mbp->logval == 0 || mbp->param[0] == MBOX_COMMAND_COMPLETE)
7123 if ((mbp->param[0] & 0xbfe0) == 0 &&
7124 (mbp->logval & MBLOGMASK(mbp->param[0])) == 0)
7129 switch (mbp->param[0]) {
7130 case MBOX_INVALID_COMMAND:
7131 xname = "INVALID COMMAND";
7133 case MBOX_HOST_INTERFACE_ERROR:
7134 xname = "HOST INTERFACE ERROR";
7136 case MBOX_TEST_FAILED:
7137 xname = "TEST FAILED";
7139 case MBOX_COMMAND_ERROR:
7140 xname = "COMMAND ERROR";
7141 ISP_SNPRINTF(mname, sizeof(mname), " subcode 0x%x",
7145 case MBOX_COMMAND_PARAM_ERROR:
7146 xname = "COMMAND PARAMETER ERROR";
7148 case MBOX_PORT_ID_USED:
7149 xname = "PORT ID ALREADY IN USE";
7151 case MBOX_LOOP_ID_USED:
7152 xname = "LOOP ID ALREADY IN USE";
7154 case MBOX_ALL_IDS_USED:
7155 xname = "ALL LOOP IDS IN USE";
7157 case MBOX_NOT_LOGGED_IN:
7158 xname = "NOT LOGGED IN";
7160 case MBOX_LINK_DOWN_ERROR:
7161 xname = "LINK DOWN ERROR";
7163 case MBOX_LOOPBACK_ERROR:
7164 xname = "LOOPBACK ERROR";
7166 case MBOX_CHECKSUM_ERROR:
7167 xname = "CHECKSUM ERROR";
7169 case MBOX_INVALID_PRODUCT_KEY:
7170 xname = "INVALID PRODUCT KEY";
7172 case MBOX_REGS_BUSY:
7173 xname = "REGISTERS BUSY";
7179 ISP_SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
7184 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s%s)",
7185 cname, xname, sname);
7190 isp_fw_state(ispsoftc_t *isp, int chan)
7195 MBSINIT(&mbs, MBOX_GET_FW_STATE, MBLOGALL, 0);
7196 isp_mboxcmd(isp, &mbs);
7197 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
7198 return (mbs.param[1]);
7205 isp_spi_update(ispsoftc_t *isp, int chan)
7213 * There are no 'per-bus' settings for Fibre Channel.
7217 sdp = SDPARAM(isp, chan);
7220 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7221 uint16_t flags, period, offset;
7224 if (sdp->isp_devparam[tgt].dev_enable == 0) {
7225 sdp->isp_devparam[tgt].dev_update = 0;
7226 sdp->isp_devparam[tgt].dev_refresh = 0;
7227 isp_prt(isp, ISP_LOGDEBUG0, "skipping target %d bus %d update", tgt, chan);
7231 * If the goal is to update the status of the device,
7232 * take what's in goal_flags and try and set the device
7233 * toward that. Otherwise, if we're just refreshing the
7234 * current device state, get the current parameters.
7237 MBSINIT(&mbs, 0, MBLOGALL, 0);
7240 * Refresh overrides set
7242 if (sdp->isp_devparam[tgt].dev_refresh) {
7243 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
7245 } else if (sdp->isp_devparam[tgt].dev_update) {
7246 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
7249 * Make sure goal_flags has "Renegotiate on Error"
7250 * on and "Freeze Queue on Error" off.
7252 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
7253 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
7254 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
7257 * Insist that PARITY must be enabled
7258 * if SYNC or WIDE is enabled.
7260 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
7261 mbs.param[2] |= DPARM_PARITY;
7264 if (mbs.param[2] & DPARM_SYNC) {
7266 (sdp->isp_devparam[tgt].goal_offset << 8) |
7267 (sdp->isp_devparam[tgt].goal_period);
7270 * A command completion later that has
7271 * RQSTF_NEGOTIATION set can cause
7272 * the dev_refresh/announce cycle also.
7274 * Note: It is really important to update our current
7275 * flags with at least the state of TAG capabilities-
7276 * otherwise we might try and send a tagged command
7277 * when we have it all turned off. So change it here
7278 * to say that current already matches goal.
7280 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
7281 sdp->isp_devparam[tgt].actv_flags |=
7282 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
7283 isp_prt(isp, ISP_LOGDEBUG0, "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
7284 chan, tgt, mbs.param[2], mbs.param[3] >> 8, mbs.param[3] & 0xff);
7289 mbs.param[1] = (chan << 15) | (tgt << 8);
7290 isp_mboxcmd(isp, &mbs);
7291 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7295 sdp->sendmarker = 1;
7296 sdp->isp_devparam[tgt].dev_update = 0;
7297 sdp->isp_devparam[tgt].dev_refresh = 1;
7299 sdp->isp_devparam[tgt].dev_refresh = 0;
7300 flags = mbs.param[2];
7301 period = mbs.param[3] & 0xff;
7302 offset = mbs.param[3] >> 8;
7303 sdp->isp_devparam[tgt].actv_flags = flags;
7304 sdp->isp_devparam[tgt].actv_period = period;
7305 sdp->isp_devparam[tgt].actv_offset = offset;
7306 isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, chan, tgt);
7310 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7311 if (sdp->isp_devparam[tgt].dev_update ||
7312 sdp->isp_devparam[tgt].dev_refresh) {
7320 isp_setdfltsdparm(ispsoftc_t *isp)
7323 sdparam *sdp, *sdp1;
7325 sdp = SDPARAM(isp, 0);
7326 if (IS_DUALBUS(isp))
7332 * Establish some default parameters.
7334 sdp->isp_cmd_dma_burst_enable = 0;
7335 sdp->isp_data_dma_burst_enabl = 1;
7336 sdp->isp_fifo_threshold = 0;
7337 sdp->isp_initiator_id = DEFAULT_IID(isp, 0);
7338 if (isp->isp_type >= ISP_HA_SCSI_1040) {
7339 sdp->isp_async_data_setup = 9;
7341 sdp->isp_async_data_setup = 6;
7343 sdp->isp_selection_timeout = 250;
7344 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
7345 sdp->isp_tag_aging = 8;
7346 sdp->isp_bus_reset_delay = 5;
7348 * Don't retry selection, busy or queue full automatically- reflect
7351 sdp->isp_retry_count = 0;
7352 sdp->isp_retry_delay = 0;
7354 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7355 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
7356 sdp->isp_devparam[tgt].dev_enable = 1;
7360 * The trick here is to establish a default for the default (honk!)
7361 * state (goal_flags). Then try and get the current status from
7362 * the card to fill in the current state. We don't, in fact, set
7363 * the default to the SAFE default state- that's not the goal state.
7365 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7367 sdp->isp_devparam[tgt].actv_offset = 0;
7368 sdp->isp_devparam[tgt].actv_period = 0;
7369 sdp->isp_devparam[tgt].actv_flags = 0;
7371 sdp->isp_devparam[tgt].goal_flags =
7372 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
7375 * We default to Wide/Fast for versions less than a 1040
7376 * (unless it's SBus).
7378 if (IS_ULTRA3(isp)) {
7379 off = ISP_80M_SYNCPARMS >> 8;
7380 per = ISP_80M_SYNCPARMS & 0xff;
7381 } else if (IS_ULTRA2(isp)) {
7382 off = ISP_40M_SYNCPARMS >> 8;
7383 per = ISP_40M_SYNCPARMS & 0xff;
7384 } else if (IS_1240(isp)) {
7385 off = ISP_20M_SYNCPARMS >> 8;
7386 per = ISP_20M_SYNCPARMS & 0xff;
7387 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
7388 isp->isp_type < ISP_HA_SCSI_1020A) ||
7389 (isp->isp_bustype == ISP_BT_PCI &&
7390 isp->isp_type < ISP_HA_SCSI_1040) ||
7391 (isp->isp_clock && isp->isp_clock < 60) ||
7392 (sdp->isp_ultramode == 0)) {
7393 off = ISP_10M_SYNCPARMS >> 8;
7394 per = ISP_10M_SYNCPARMS & 0xff;
7396 off = ISP_20M_SYNCPARMS_1040 >> 8;
7397 per = ISP_20M_SYNCPARMS_1040 & 0xff;
7399 sdp->isp_devparam[tgt].goal_offset =
7400 sdp->isp_devparam[tgt].nvrm_offset = off;
7401 sdp->isp_devparam[tgt].goal_period =
7402 sdp->isp_devparam[tgt].nvrm_period = per;
7407 * If we're a dual bus card, just copy the data over
7411 sdp1->isp_initiator_id = DEFAULT_IID(isp, 1);
7415 * If we've not been told to avoid reading NVRAM, try and read it.
7416 * If we're successful reading it, we can then return because NVRAM
7417 * will tell us what the desired settings are. Otherwise, we establish
7418 * some reasonable 'fake' nvram and goal defaults.
7420 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7423 if (isp_read_nvram(isp, 0) == 0) {
7424 if (IS_DUALBUS(isp)) {
7425 if (isp_read_nvram(isp, 1) == 0) {
7430 MBSINIT(&mbs, MBOX_GET_ACT_NEG_STATE, MBLOGNONE, 0);
7431 isp_mboxcmd(isp, &mbs);
7432 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7433 sdp->isp_req_ack_active_neg = 1;
7434 sdp->isp_data_line_active_neg = 1;
7436 sdp1->isp_req_ack_active_neg = 1;
7437 sdp1->isp_data_line_active_neg = 1;
7440 sdp->isp_req_ack_active_neg =
7441 (mbs.param[1] >> 4) & 0x1;
7442 sdp->isp_data_line_active_neg =
7443 (mbs.param[1] >> 5) & 0x1;
7445 sdp1->isp_req_ack_active_neg =
7446 (mbs.param[2] >> 4) & 0x1;
7447 sdp1->isp_data_line_active_neg =
7448 (mbs.param[2] >> 5) & 0x1;
7456 isp_setdfltfcparm(ispsoftc_t *isp, int chan)
7458 fcparam *fcp = FCPARAM(isp, chan);
7461 * Establish some default parameters.
7463 fcp->role = DEFAULT_ROLE(isp, chan);
7464 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
7465 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
7466 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
7467 fcp->isp_loopid = DEFAULT_LOOPID(isp, chan);
7468 fcp->isp_wwnn_nvram = DEFAULT_NODEWWN(isp, chan);
7469 fcp->isp_wwpn_nvram = DEFAULT_PORTWWN(isp, chan);
7470 fcp->isp_fwoptions = 0;
7471 fcp->isp_xfwoptions = 0;
7472 fcp->isp_zfwoptions = 0;
7473 fcp->isp_lasthdl = NIL_HANDLE;
7474 fcp->isp_login_hdl = NIL_HANDLE;
7477 fcp->isp_fwoptions |= ICB2400_OPT1_FAIRNESS;
7478 fcp->isp_fwoptions |= ICB2400_OPT1_HARD_ADDRESS;
7479 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
7480 fcp->isp_fwoptions |= ICB2400_OPT1_FULL_DUPLEX;
7481 fcp->isp_fwoptions |= ICB2400_OPT1_BOTH_WWNS;
7482 fcp->isp_xfwoptions |= ICB2400_OPT2_LOOP_2_PTP;
7483 fcp->isp_zfwoptions |= ICB2400_OPT3_RATE_AUTO;
7485 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
7486 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
7487 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
7488 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX)
7489 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
7491 * Make sure this is turned off now until we get
7492 * extended options from NVRAM
7494 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
7495 fcp->isp_xfwoptions |= ICBXOPT_LOOP_2_PTP;
7496 fcp->isp_zfwoptions |= ICBZOPT_RATE_AUTO;
7501 * Now try and read NVRAM unless told to not do so.
7502 * This will set fcparam's isp_wwnn_nvram && isp_wwpn_nvram.
7504 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7507 * Give a couple of tries at reading NVRAM.
7509 for (i = 0; i < 2; i++) {
7510 j = isp_read_nvram(isp, chan);
7516 isp->isp_confopts |= ISP_CFG_NONVRAM;
7520 fcp->isp_wwnn = ACTIVE_NODEWWN(isp, chan);
7521 fcp->isp_wwpn = ACTIVE_PORTWWN(isp, chan);
7522 isp_prt(isp, ISP_LOGCONFIG, "Chan %d 0x%08x%08x/0x%08x%08x Role %s",
7523 chan, (uint32_t) (fcp->isp_wwnn >> 32), (uint32_t) (fcp->isp_wwnn),
7524 (uint32_t) (fcp->isp_wwpn >> 32), (uint32_t) (fcp->isp_wwpn),
7525 isp_class3_roles[fcp->role]);
7529 * Re-initialize the ISP and complete all orphaned commands
7530 * with a 'botched' notice. The reset/init routines should
7531 * not disturb an already active list of commands.
7535 isp_reinit(ispsoftc_t *isp, int do_load_defaults)
7539 if (isp->isp_state > ISP_RESETSTATE)
7541 if (isp->isp_state != ISP_RESETSTATE)
7542 isp_reset(isp, do_load_defaults);
7543 if (isp->isp_state != ISP_RESETSTATE) {
7545 isp_prt(isp, ISP_LOGERR, "%s: cannot reset card", __func__);
7550 if (isp->isp_state > ISP_RESETSTATE &&
7551 isp->isp_state != ISP_RUNSTATE) {
7553 isp_prt(isp, ISP_LOGERR, "%s: cannot init card", __func__);
7554 ISP_DISABLE_INTS(isp);
7557 * If we're in ISP_ROLE_NONE, turn off the lasers.
7559 if (!IS_24XX(isp)) {
7560 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
7561 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
7562 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
7563 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
7564 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
7570 isp_clear_commands(isp);
7572 for (i = 0; i < isp->isp_nchan; i++)
7573 isp_clear_portdb(isp, i);
7582 isp_read_nvram(ispsoftc_t *isp, int bus)
7585 uint8_t csum, minversion;
7587 uint8_t _x[ISP2400_NVRAM_SIZE];
7588 uint16_t _s[ISP2400_NVRAM_SIZE>>1];
7590 #define nvram_data _n._x
7591 #define nvram_words _n._s
7594 return (isp_read_nvram_2400(isp, nvram_data));
7595 } else if (IS_FC(isp)) {
7596 amt = ISP2100_NVRAM_SIZE;
7598 } else if (IS_ULTRA2(isp)) {
7599 amt = ISP1080_NVRAM_SIZE;
7602 amt = ISP_NVRAM_SIZE;
7606 for (i = 0; i < amt>>1; i++) {
7607 isp_rdnvram_word(isp, i, &nvram_words[i]);
7610 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
7611 nvram_data[2] != 'P') {
7612 if (isp->isp_bustype != ISP_BT_SBUS) {
7613 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
7614 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x", nvram_data[0], nvram_data[1], nvram_data[2]);
7620 for (csum = 0, i = 0; i < amt; i++) {
7621 csum += nvram_data[i];
7624 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
7629 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
7630 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
7631 ISP_NVRAM_VERSION(nvram_data));
7636 if (IS_ULTRA3(isp)) {
7637 isp_parse_nvram_12160(isp, bus, nvram_data);
7638 } else if (IS_1080(isp)) {
7639 isp_parse_nvram_1080(isp, bus, nvram_data);
7640 } else if (IS_1280(isp) || IS_1240(isp)) {
7641 isp_parse_nvram_1080(isp, bus, nvram_data);
7642 } else if (IS_SCSI(isp)) {
7643 isp_parse_nvram_1020(isp, nvram_data);
7645 isp_parse_nvram_2100(isp, nvram_data);
7655 isp_read_nvram_2400(ispsoftc_t *isp, uint8_t *nvram_data)
7658 uint32_t addr, csum, lwrds, *dptr;
7660 if (isp->isp_port) {
7661 addr = ISP2400_NVRAM_PORT1_ADDR;
7663 addr = ISP2400_NVRAM_PORT0_ADDR;
7666 dptr = (uint32_t *) nvram_data;
7667 for (lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
7668 isp_rd_2400_nvram(isp, addr++, dptr++);
7670 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
7671 nvram_data[2] != 'P') {
7672 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header (%x %x %x)",
7673 nvram_data[0], nvram_data[1], nvram_data[2]);
7677 dptr = (uint32_t *) nvram_data;
7678 for (csum = 0, lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
7680 ISP_IOXGET_32(isp, &dptr[lwrds], tmp);
7684 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
7688 isp_parse_nvram_2400(isp, nvram_data);
7694 isp_rdnvram_word(ispsoftc_t *isp, int wo, uint16_t *rp)
7697 uint16_t bit, rqst, junk;
7699 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
7701 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
7705 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
7706 if (IS_2312(isp) && isp->isp_port) {
7709 rqst = (ISP_NVRAM_READ << 8) | wo;
7711 } else if (IS_ULTRA2(isp)) {
7712 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
7713 rqst = (ISP_NVRAM_READ << 8) | wo;
7716 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
7717 rqst = (ISP_NVRAM_READ << 6) | wo;
7722 * Clock the word select request out...
7724 for (i = cbits; i >= 0; i--) {
7725 if ((rqst >> i) & 1) {
7726 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
7728 bit = BIU_NVRAM_SELECT;
7730 ISP_WRITE(isp, BIU_NVRAM, bit);
7732 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7733 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
7735 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7736 ISP_WRITE(isp, BIU_NVRAM, bit);
7738 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7741 * Now read the result back in (bits come back in MSB format).
7744 for (i = 0; i < 16; i++) {
7747 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
7749 rv = ISP_READ(isp, BIU_NVRAM);
7750 if (rv & BIU_NVRAM_DATAIN) {
7754 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
7756 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7758 ISP_WRITE(isp, BIU_NVRAM, 0);
7760 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7761 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
7765 isp_rd_2400_nvram(ispsoftc_t *isp, uint32_t addr, uint32_t *rp)
7768 uint32_t base = 0x7ffe0000;
7772 base = 0x7fe7c000; /* XXX: Observation, may be wrong. */
7773 } else if (IS_25XX(isp)) {
7774 base = 0x7ff00000 | 0x48000;
7776 ISP_WRITE(isp, BIU2400_FLASH_ADDR, base | addr);
7777 for (loops = 0; loops < 5000; loops++) {
7779 tmp = ISP_READ(isp, BIU2400_FLASH_ADDR);
7780 if ((tmp & (1U << 31)) != 0) {
7784 if (tmp & (1U << 31)) {
7785 *rp = ISP_READ(isp, BIU2400_FLASH_DATA);
7786 ISP_SWIZZLE_NVRAM_LONG(isp, rp);
7793 isp_parse_nvram_1020(ispsoftc_t *isp, uint8_t *nvram_data)
7795 sdparam *sdp = SDPARAM(isp, 0);
7798 sdp->isp_fifo_threshold =
7799 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
7800 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
7802 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
7803 sdp->isp_initiator_id = ISP_NVRAM_INITIATOR_ID(nvram_data);
7805 sdp->isp_bus_reset_delay =
7806 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
7808 sdp->isp_retry_count =
7809 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
7811 sdp->isp_retry_delay =
7812 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
7814 sdp->isp_async_data_setup =
7815 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
7817 if (isp->isp_type >= ISP_HA_SCSI_1040) {
7818 if (sdp->isp_async_data_setup < 9) {
7819 sdp->isp_async_data_setup = 9;
7822 if (sdp->isp_async_data_setup != 6) {
7823 sdp->isp_async_data_setup = 6;
7827 sdp->isp_req_ack_active_neg =
7828 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
7830 sdp->isp_data_line_active_neg =
7831 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
7833 sdp->isp_data_dma_burst_enabl =
7834 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
7836 sdp->isp_cmd_dma_burst_enable =
7837 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
7839 sdp->isp_tag_aging =
7840 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
7842 sdp->isp_selection_timeout =
7843 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
7845 sdp->isp_max_queue_depth =
7846 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
7848 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
7850 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7851 sdp->isp_devparam[tgt].dev_enable =
7852 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
7853 sdp->isp_devparam[tgt].exc_throttle =
7854 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
7855 sdp->isp_devparam[tgt].nvrm_offset =
7856 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
7857 sdp->isp_devparam[tgt].nvrm_period =
7858 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
7860 * We probably shouldn't lie about this, but it
7861 * it makes it much safer if we limit NVRAM values
7864 if (isp->isp_type < ISP_HA_SCSI_1040) {
7866 * If we're not ultra, we can't possibly
7867 * be a shorter period than this.
7869 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
7870 sdp->isp_devparam[tgt].nvrm_period = 0x19;
7872 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
7873 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
7876 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
7877 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
7880 sdp->isp_devparam[tgt].nvrm_flags = 0;
7881 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
7882 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
7883 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
7884 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
7885 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
7886 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
7887 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
7888 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
7889 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
7890 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
7891 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
7892 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
7893 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
7894 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
7895 sdp->isp_devparam[tgt].goal_offset =
7896 sdp->isp_devparam[tgt].nvrm_offset;
7897 sdp->isp_devparam[tgt].goal_period =
7898 sdp->isp_devparam[tgt].nvrm_period;
7899 sdp->isp_devparam[tgt].goal_flags =
7900 sdp->isp_devparam[tgt].nvrm_flags;
7905 isp_parse_nvram_1080(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
7907 sdparam *sdp = SDPARAM(isp, bus);
7910 sdp->isp_fifo_threshold =
7911 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
7913 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
7914 sdp->isp_initiator_id = ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
7916 sdp->isp_bus_reset_delay =
7917 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
7919 sdp->isp_retry_count =
7920 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
7922 sdp->isp_retry_delay =
7923 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
7925 sdp->isp_async_data_setup =
7926 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
7928 sdp->isp_req_ack_active_neg =
7929 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
7931 sdp->isp_data_line_active_neg =
7932 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
7934 sdp->isp_data_dma_burst_enabl =
7935 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
7937 sdp->isp_cmd_dma_burst_enable =
7938 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
7940 sdp->isp_selection_timeout =
7941 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
7943 sdp->isp_max_queue_depth =
7944 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
7946 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7947 sdp->isp_devparam[tgt].dev_enable =
7948 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
7949 sdp->isp_devparam[tgt].exc_throttle =
7950 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
7951 sdp->isp_devparam[tgt].nvrm_offset =
7952 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
7953 sdp->isp_devparam[tgt].nvrm_period =
7954 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
7955 sdp->isp_devparam[tgt].nvrm_flags = 0;
7956 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
7957 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
7958 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
7959 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
7960 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
7961 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
7962 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
7963 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
7964 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
7965 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
7966 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
7967 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
7968 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
7969 sdp->isp_devparam[tgt].actv_flags = 0;
7970 sdp->isp_devparam[tgt].goal_offset =
7971 sdp->isp_devparam[tgt].nvrm_offset;
7972 sdp->isp_devparam[tgt].goal_period =
7973 sdp->isp_devparam[tgt].nvrm_period;
7974 sdp->isp_devparam[tgt].goal_flags =
7975 sdp->isp_devparam[tgt].nvrm_flags;
7980 isp_parse_nvram_12160(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
7982 sdparam *sdp = SDPARAM(isp, bus);
7985 sdp->isp_fifo_threshold =
7986 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
7988 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
7989 sdp->isp_initiator_id = ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
7991 sdp->isp_bus_reset_delay =
7992 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
7994 sdp->isp_retry_count =
7995 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
7997 sdp->isp_retry_delay =
7998 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
8000 sdp->isp_async_data_setup =
8001 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
8003 sdp->isp_req_ack_active_neg =
8004 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
8006 sdp->isp_data_line_active_neg =
8007 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
8009 sdp->isp_data_dma_burst_enabl =
8010 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
8012 sdp->isp_cmd_dma_burst_enable =
8013 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
8015 sdp->isp_selection_timeout =
8016 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
8018 sdp->isp_max_queue_depth =
8019 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
8021 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
8022 sdp->isp_devparam[tgt].dev_enable =
8023 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
8024 sdp->isp_devparam[tgt].exc_throttle =
8025 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
8026 sdp->isp_devparam[tgt].nvrm_offset =
8027 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
8028 sdp->isp_devparam[tgt].nvrm_period =
8029 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
8030 sdp->isp_devparam[tgt].nvrm_flags = 0;
8031 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
8032 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
8033 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
8034 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
8035 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
8036 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
8037 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
8038 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
8039 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
8040 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
8041 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
8042 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
8043 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
8044 sdp->isp_devparam[tgt].actv_flags = 0;
8045 sdp->isp_devparam[tgt].goal_offset =
8046 sdp->isp_devparam[tgt].nvrm_offset;
8047 sdp->isp_devparam[tgt].goal_period =
8048 sdp->isp_devparam[tgt].nvrm_period;
8049 sdp->isp_devparam[tgt].goal_flags =
8050 sdp->isp_devparam[tgt].nvrm_flags;
8055 isp_parse_nvram_2100(ispsoftc_t *isp, uint8_t *nvram_data)
8057 fcparam *fcp = FCPARAM(isp, 0);
8061 * There is NVRAM storage for both Port and Node entities-
8062 * but the Node entity appears to be unused on all the cards
8063 * I can find. However, we should account for this being set
8064 * at some point in the future.
8066 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
8067 * bits 48..60. In the case of the 2202, it appears that they do
8068 * use bit 48 to distinguish between the two instances on the card.
8069 * The 2204, which I've never seen, *probably* extends this method.
8071 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
8073 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
8074 (uint32_t) (wwn >> 32), (uint32_t) (wwn));
8075 if ((wwn >> 60) == 0) {
8076 wwn |= (((uint64_t) 2)<< 60);
8079 fcp->isp_wwpn_nvram = wwn;
8080 if (IS_2200(isp) || IS_23XX(isp)) {
8081 wwn = ISP2100_NVRAM_NODE_NAME(nvram_data);
8083 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
8084 (uint32_t) (wwn >> 32),
8086 if ((wwn >> 60) == 0) {
8087 wwn |= (((uint64_t) 2)<< 60);
8090 wwn = fcp->isp_wwpn_nvram & ~((uint64_t) 0xfff << 48);
8093 wwn &= ~((uint64_t) 0xfff << 48);
8095 fcp->isp_wwnn_nvram = wwn;
8097 fcp->isp_maxalloc = ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
8098 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
8099 DEFAULT_FRAMESIZE(isp) =
8100 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
8102 fcp->isp_retry_delay = ISP2100_NVRAM_RETRY_DELAY(nvram_data);
8103 fcp->isp_retry_count = ISP2100_NVRAM_RETRY_COUNT(nvram_data);
8104 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
8105 fcp->isp_loopid = ISP2100_NVRAM_HARDLOOPID(nvram_data);
8107 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
8108 DEFAULT_EXEC_THROTTLE(isp) =
8109 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
8111 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
8112 isp_prt(isp, ISP_LOGDEBUG0,
8113 "NVRAM 0x%08x%08x 0x%08x%08x maxalloc %d maxframelen %d",
8114 (uint32_t) (fcp->isp_wwnn_nvram >> 32),
8115 (uint32_t) fcp->isp_wwnn_nvram,
8116 (uint32_t) (fcp->isp_wwpn_nvram >> 32),
8117 (uint32_t) fcp->isp_wwpn_nvram,
8118 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data),
8119 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data));
8120 isp_prt(isp, ISP_LOGDEBUG0,
8121 "execthrottle %d fwoptions 0x%x hardloop %d tov %d",
8122 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
8123 ISP2100_NVRAM_OPTIONS(nvram_data),
8124 ISP2100_NVRAM_HARDLOOPID(nvram_data),
8125 ISP2100_NVRAM_TOV(nvram_data));
8126 fcp->isp_xfwoptions = ISP2100_XFW_OPTIONS(nvram_data);
8127 fcp->isp_zfwoptions = ISP2100_ZFW_OPTIONS(nvram_data);
8128 isp_prt(isp, ISP_LOGDEBUG0, "xfwoptions 0x%x zfw options 0x%x",
8129 ISP2100_XFW_OPTIONS(nvram_data), ISP2100_ZFW_OPTIONS(nvram_data));
8133 isp_parse_nvram_2400(ispsoftc_t *isp, uint8_t *nvram_data)
8135 fcparam *fcp = FCPARAM(isp, 0);
8138 isp_prt(isp, ISP_LOGDEBUG0,
8139 "NVRAM 0x%08x%08x 0x%08x%08x exchg_cnt %d maxframelen %d",
8140 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data) >> 32),
8141 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data)),
8142 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data) >> 32),
8143 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data)),
8144 ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data),
8145 ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data));
8146 isp_prt(isp, ISP_LOGDEBUG0,
8147 "NVRAM execthr %d loopid %d fwopt1 0x%x fwopt2 0x%x fwopt3 0x%x",
8148 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data),
8149 ISP2400_NVRAM_HARDLOOPID(nvram_data),
8150 ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data),
8151 ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data),
8152 ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data));
8154 wwn = ISP2400_NVRAM_PORT_NAME(nvram_data);
8155 fcp->isp_wwpn_nvram = wwn;
8157 wwn = ISP2400_NVRAM_NODE_NAME(nvram_data);
8159 if ((wwn >> 60) != 2 && (wwn >> 60) != 5) {
8163 if (wwn == 0 && (fcp->isp_wwpn_nvram >> 60) == 2) {
8164 wwn = fcp->isp_wwpn_nvram;
8165 wwn &= ~((uint64_t) 0xfff << 48);
8167 fcp->isp_wwnn_nvram = wwn;
8169 if (ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data)) {
8170 fcp->isp_maxalloc = ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data);
8172 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
8173 DEFAULT_FRAMESIZE(isp) =
8174 ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data);
8176 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
8177 fcp->isp_loopid = ISP2400_NVRAM_HARDLOOPID(nvram_data);
8179 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
8180 DEFAULT_EXEC_THROTTLE(isp) =
8181 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data);
8183 fcp->isp_fwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data);
8184 fcp->isp_xfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data);
8185 fcp->isp_zfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data);