2 * Copyright (c) 1997-2009 by Matthew Jacob
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * Machine and OS Independent (well, as best as possible)
31 * code for the Qlogic ISP SCSI and FC-SCSI adapters.
35 * Inspiration and ideas about this driver are from Erik Moe's Linux driver
36 * (qlogicisp.c) and Dave Miller's SBus version of same (qlogicisp.c). Some
37 * ideas dredged from the Solaris driver.
41 * Include header file appropriate for platform we're building on.
44 #include <sys/cdefs.h>
45 __KERNEL_RCSID(0, "$NetBSD$");
46 #include <dev/ic/isp_netbsd.h>
49 #include <sys/cdefs.h>
50 __FBSDID("$FreeBSD$");
51 #include <dev/isp/isp_freebsd.h>
54 #include <dev/ic/isp_openbsd.h>
57 #include "isp_linux.h"
60 #include "isp_solaris.h"
66 #define MBOX_DELAY_COUNT 1000000 / 100
71 static const char notresp[] = "Not RESPONSE in RESPONSE Queue (type 0x%x) @ idx %d (next %d) nlooked %d";
72 static const char bun[] = "bad underrun (count %d, resid %d, status %s)";
73 static const char lipd[] = "Chan %d LIP destroyed %d active commands";
74 static const char sacq[] = "unable to acquire scratch area";
76 static const uint8_t alpa_map[] = {
77 0xef, 0xe8, 0xe4, 0xe2, 0xe1, 0xe0, 0xdc, 0xda,
78 0xd9, 0xd6, 0xd5, 0xd4, 0xd3, 0xd2, 0xd1, 0xce,
79 0xcd, 0xcc, 0xcb, 0xca, 0xc9, 0xc7, 0xc6, 0xc5,
80 0xc3, 0xbc, 0xba, 0xb9, 0xb6, 0xb5, 0xb4, 0xb3,
81 0xb2, 0xb1, 0xae, 0xad, 0xac, 0xab, 0xaa, 0xa9,
82 0xa7, 0xa6, 0xa5, 0xa3, 0x9f, 0x9e, 0x9d, 0x9b,
83 0x98, 0x97, 0x90, 0x8f, 0x88, 0x84, 0x82, 0x81,
84 0x80, 0x7c, 0x7a, 0x79, 0x76, 0x75, 0x74, 0x73,
85 0x72, 0x71, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x69,
86 0x67, 0x66, 0x65, 0x63, 0x5c, 0x5a, 0x59, 0x56,
87 0x55, 0x54, 0x53, 0x52, 0x51, 0x4e, 0x4d, 0x4c,
88 0x4b, 0x4a, 0x49, 0x47, 0x46, 0x45, 0x43, 0x3c,
89 0x3a, 0x39, 0x36, 0x35, 0x34, 0x33, 0x32, 0x31,
90 0x2e, 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x27, 0x26,
91 0x25, 0x23, 0x1f, 0x1e, 0x1d, 0x1b, 0x18, 0x17,
92 0x10, 0x0f, 0x08, 0x04, 0x02, 0x01, 0x00
96 * Local function prototypes.
98 static int isp_parse_async(ispsoftc_t *, uint16_t);
99 static int isp_parse_async_fc(ispsoftc_t *, uint16_t);
100 static int isp_handle_other_response(ispsoftc_t *, int, isphdr_t *, uint32_t *);
101 static void isp_parse_status(ispsoftc_t *, ispstatusreq_t *, XS_T *, long *); static void
102 isp_parse_status_24xx(ispsoftc_t *, isp24xx_statusreq_t *, XS_T *, long *);
103 static void isp_fastpost_complete(ispsoftc_t *, uint32_t);
104 static int isp_mbox_continue(ispsoftc_t *);
105 static void isp_scsi_init(ispsoftc_t *);
106 static void isp_scsi_channel_init(ispsoftc_t *, int);
107 static void isp_fibre_init(ispsoftc_t *);
108 static void isp_fibre_init_2400(ispsoftc_t *);
109 static void isp_clear_portdb(ispsoftc_t *, int);
110 static void isp_mark_portdb(ispsoftc_t *, int);
111 static int isp_plogx(ispsoftc_t *, int, uint16_t, uint32_t, int, int);
112 static int isp_port_login(ispsoftc_t *, uint16_t, uint32_t);
113 static int isp_port_logout(ispsoftc_t *, uint16_t, uint32_t);
114 static int isp_getpdb(ispsoftc_t *, int, uint16_t, isp_pdb_t *, int);
115 static int isp_gethandles(ispsoftc_t *, int, uint16_t *, int *, int, int);
116 static void isp_dump_chip_portdb(ispsoftc_t *, int, int);
117 static uint64_t isp_get_wwn(ispsoftc_t *, int, int, int);
118 static int isp_fclink_test(ispsoftc_t *, int, int);
119 static int isp_pdb_sync(ispsoftc_t *, int);
120 static int isp_scan_loop(ispsoftc_t *, int);
121 static int isp_gid_ft_sns(ispsoftc_t *, int);
122 static int isp_gid_ft_ct_passthru(ispsoftc_t *, int);
123 static int isp_scan_fabric(ispsoftc_t *, int);
124 static int isp_login_device(ispsoftc_t *, int, uint32_t, isp_pdb_t *, uint16_t *);
125 static int isp_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 uint16_t isp_next_handle(ispsoftc_t *, uint16_t *);
129 static int isp_fw_state(ispsoftc_t *, int);
130 static void isp_mboxcmd_qnw(ispsoftc_t *, mbreg_t *, int);
131 static void isp_mboxcmd(ispsoftc_t *, mbreg_t *);
133 static void isp_spi_update(ispsoftc_t *, int);
134 static void isp_setdfltsdparm(ispsoftc_t *);
135 static void isp_setdfltfcparm(ispsoftc_t *, int);
136 static int isp_read_nvram(ispsoftc_t *, int);
137 static int isp_read_nvram_2400(ispsoftc_t *, uint8_t *);
138 static void isp_rdnvram_word(ispsoftc_t *, int, uint16_t *);
139 static void isp_rd_2400_nvram(ispsoftc_t *, uint32_t, uint32_t *);
140 static void isp_parse_nvram_1020(ispsoftc_t *, uint8_t *);
141 static void isp_parse_nvram_1080(ispsoftc_t *, int, uint8_t *);
142 static void isp_parse_nvram_12160(ispsoftc_t *, int, uint8_t *);
143 static void isp_parse_nvram_2100(ispsoftc_t *, uint8_t *);
144 static void isp_parse_nvram_2400(ispsoftc_t *, uint8_t *);
147 isp_change_fw_state(ispsoftc_t *isp, int chan, int state)
149 fcparam *fcp = FCPARAM(isp, chan);
151 if (fcp->isp_fwstate == state)
153 isp_prt(isp, ISP_LOGCONFIG|ISP_LOG_SANCFG,
154 "Chan %d Firmware state <%s->%s>", chan,
155 isp_fc_fw_statename(fcp->isp_fwstate), isp_fc_fw_statename(state));
156 fcp->isp_fwstate = state;
162 * Hit the chip over the head, download new f/w if available and set it running.
164 * Locking done elsewhere.
168 isp_reset(ispsoftc_t *isp, int do_load_defaults)
173 uint32_t code_org, val;
174 int loops, i, dodnld = 1;
175 const char *btype = "????";
176 static const char dcrc[] = "Downloaded RISC Code Checksum Failure";
178 isp->isp_state = ISP_NILSTATE;
181 ISP_DISABLE_INTS(isp);
186 * Basic types (SCSI, FibreChannel and PCI or SBus)
187 * have been set in the MD code. We figure out more
188 * here. Possibly more refined types based upon PCI
189 * identification. Chip revision has been gathered.
191 * After we've fired this chip up, zero out the conf1 register
192 * for SCSI adapters and do other settings for the 2100.
195 ISP_DISABLE_INTS(isp);
198 * Pick an initial maxcmds value which will be used
199 * to allocate xflist pointer space. It may be changed
200 * later by the firmware.
203 isp->isp_maxcmds = 4096;
204 } else if (IS_2322(isp)) {
205 isp->isp_maxcmds = 2048;
206 } else if (IS_23XX(isp) || IS_2200(isp)) {
207 isp->isp_maxcmds = 1024;
209 isp->isp_maxcmds = 512;
213 * Set up DMA for the request and response queues.
215 * We do this now so we can use the request queue
216 * for dma to load firmware from.
218 if (ISP_MBOXDMASETUP(isp) != 0) {
219 isp_prt(isp, ISP_LOGERR, "Cannot setup DMA");
224 * Set up default request/response queue in-pointer/out-pointer
228 isp->isp_rqstinrp = BIU2400_REQINP;
229 isp->isp_rqstoutrp = BIU2400_REQOUTP;
230 isp->isp_respinrp = BIU2400_RSPINP;
231 isp->isp_respoutrp = BIU2400_RSPOUTP;
232 } else if (IS_23XX(isp)) {
233 isp->isp_rqstinrp = BIU_REQINP;
234 isp->isp_rqstoutrp = BIU_REQOUTP;
235 isp->isp_respinrp = BIU_RSPINP;
236 isp->isp_respoutrp = BIU_RSPOUTP;
238 isp->isp_rqstinrp = INMAILBOX4;
239 isp->isp_rqstoutrp = OUTMAILBOX4;
240 isp->isp_respinrp = OUTMAILBOX5;
241 isp->isp_respoutrp = INMAILBOX5;
245 * Put the board into PAUSE mode (so we can read the SXP registers
246 * or write FPM/FBM registers).
249 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_HOST_INT);
250 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
251 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_PAUSE);
253 ISP_WRITE(isp, HCCR, HCCR_CMD_PAUSE);
257 switch (isp->isp_type) {
285 * While we're paused, reset the FPM module and FBM
288 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
289 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
290 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
291 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
292 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
294 } else if (IS_1240(isp)) {
299 sdp = SDPARAM(isp, 0);
300 sdp->isp_ultramode = 1;
301 sdp = SDPARAM(isp, 1);
302 sdp->isp_ultramode = 1;
304 * XXX: Should probably do some bus sensing.
306 } else if (IS_ULTRA3(isp)) {
307 sdparam *sdp = isp->isp_param;
309 isp->isp_clock = 100;
313 else if (IS_12160(isp))
317 sdp->isp_lvdmode = 1;
319 if (IS_DUALBUS(isp)) {
321 sdp->isp_lvdmode = 1;
323 } else if (IS_ULTRA2(isp)) {
324 static const char m[] = "bus %d is in %s Mode";
326 sdparam *sdp = SDPARAM(isp, 0);
328 isp->isp_clock = 100;
332 else if (IS_1080(isp))
337 l = ISP_READ(isp, SXP_PINS_DIFF) & ISP1080_MODE_MASK;
339 case ISP1080_LVD_MODE:
340 sdp->isp_lvdmode = 1;
341 isp_prt(isp, ISP_LOGCONFIG, m, 0, "LVD");
343 case ISP1080_HVD_MODE:
344 sdp->isp_diffmode = 1;
345 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Differential");
347 case ISP1080_SE_MODE:
348 sdp->isp_ultramode = 1;
349 isp_prt(isp, ISP_LOGCONFIG, m, 0, "Single-Ended");
352 isp_prt(isp, ISP_LOGERR,
353 "unknown mode on bus %d (0x%x)", 0, l);
357 if (IS_DUALBUS(isp)) {
358 sdp = SDPARAM(isp, 1);
359 l = ISP_READ(isp, SXP_PINS_DIFF|SXP_BANK1_SELECT);
360 l &= ISP1080_MODE_MASK;
362 case ISP1080_LVD_MODE:
363 sdp->isp_lvdmode = 1;
364 isp_prt(isp, ISP_LOGCONFIG, m, 1, "LVD");
366 case ISP1080_HVD_MODE:
367 sdp->isp_diffmode = 1;
368 isp_prt(isp, ISP_LOGCONFIG,
369 m, 1, "Differential");
371 case ISP1080_SE_MODE:
372 sdp->isp_ultramode = 1;
373 isp_prt(isp, ISP_LOGCONFIG,
374 m, 1, "Single-Ended");
377 isp_prt(isp, ISP_LOGERR,
378 "unknown mode on bus %d (0x%x)", 1, l);
383 sdparam *sdp = SDPARAM(isp, 0);
384 i = ISP_READ(isp, BIU_CONF0) & BIU_CONF0_HW_MASK;
387 isp_prt(isp, ISP_LOGALL, "Unknown Chip Type 0x%x", i);
391 isp->isp_type = ISP_HA_SCSI_1020;
396 * Some 1020A chips are Ultra Capable, but don't
397 * run the clock rate up for that unless told to
398 * do so by the Ultra Capable bits being set.
401 isp->isp_type = ISP_HA_SCSI_1020A;
406 isp->isp_type = ISP_HA_SCSI_1040;
411 isp->isp_type = ISP_HA_SCSI_1040A;
416 isp->isp_type = ISP_HA_SCSI_1040B;
421 isp->isp_type = ISP_HA_SCSI_1040C;
426 * Now, while we're at it, gather info about ultra
427 * and/or differential mode.
429 if (ISP_READ(isp, SXP_PINS_DIFF) & SXP_PINS_DIFF_MODE) {
430 isp_prt(isp, ISP_LOGCONFIG, "Differential Mode");
431 sdp->isp_diffmode = 1;
433 sdp->isp_diffmode = 0;
435 i = ISP_READ(isp, RISC_PSR);
436 if (isp->isp_bustype == ISP_BT_SBUS) {
437 i &= RISC_PSR_SBUS_ULTRA;
439 i &= RISC_PSR_PCI_ULTRA;
442 isp_prt(isp, ISP_LOGCONFIG, "Ultra Mode Capable");
443 sdp->isp_ultramode = 1;
445 * If we're in Ultra Mode, we have to be 60MHz clock-
446 * even for the SBus version.
450 sdp->isp_ultramode = 0;
452 * Clock is known. Gronk.
457 * Machine dependent clock (if set) overrides
458 * our generic determinations.
460 if (isp->isp_mdvec->dv_clock) {
461 if (isp->isp_mdvec->dv_clock < isp->isp_clock) {
462 isp->isp_clock = isp->isp_mdvec->dv_clock;
469 * Clear instrumentation
471 isp->isp_intcnt = isp->isp_intbogus = 0;
474 * Do MD specific pre initialization
479 * Hit the chip over the head with hammer,
480 * and give it a chance to recover.
484 ISP_WRITE(isp, BIU_ICR, BIU_ICR_SOFT_RESET);
491 * Clear data && control DMA engines.
493 ISP_WRITE(isp, CDMA_CONTROL, DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
494 ISP_WRITE(isp, DDMA_CONTROL, DMA_CNTRL_CLEAR_CHAN | DMA_CNTRL_RESET_INT);
497 } else if (IS_24XX(isp)) {
499 * Stop DMA and wait for it to stop.
501 ISP_WRITE(isp, BIU2400_CSR, BIU2400_DMA_STOP|(3 << 4));
502 for (val = loops = 0; loops < 30000; loops++) {
504 val = ISP_READ(isp, BIU2400_CSR);
505 if ((val & BIU2400_DMA_ACTIVE) == 0) {
509 if (val & BIU2400_DMA_ACTIVE) {
511 isp_prt(isp, ISP_LOGERR, "DMA Failed to Stop on Reset");
515 * Hold it in SOFT_RESET and STOP state for 100us.
517 ISP_WRITE(isp, BIU2400_CSR, BIU2400_SOFT_RESET|BIU2400_DMA_STOP|(3 << 4));
519 for (loops = 0; loops < 10000; loops++) {
521 val = ISP_READ(isp, OUTMAILBOX0);
523 for (val = loops = 0; loops < 500000; loops ++) {
524 val = ISP_READ(isp, BIU2400_CSR);
525 if ((val & BIU2400_SOFT_RESET) == 0) {
529 if (val & BIU2400_SOFT_RESET) {
531 isp_prt(isp, ISP_LOGERR, "Failed to come out of reset");
535 ISP_WRITE(isp, BIU2100_CSR, BIU2100_SOFT_RESET);
542 * Clear data && control DMA engines.
544 ISP_WRITE(isp, CDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
545 ISP_WRITE(isp, TDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
546 ISP_WRITE(isp, RDMA2100_CONTROL, DMA_CNTRL2100_CLEAR_CHAN | DMA_CNTRL2100_RESET_INT);
550 * Wait for ISP to be ready to go...
552 loops = MBOX_DELAY_COUNT;
555 if (!(ISP_READ(isp, BIU_ICR) & BIU_ICR_SOFT_RESET)) {
558 } else if (IS_24XX(isp)) {
559 if (ISP_READ(isp, OUTMAILBOX0) == 0) {
563 if (!(ISP_READ(isp, BIU2100_CSR) & BIU2100_SOFT_RESET))
568 ISP_DUMPREGS(isp, "chip reset timed out");
575 * After we've fired this chip up, zero out the conf1 register
576 * for SCSI adapters and other settings for the 2100.
580 ISP_WRITE(isp, BIU_CONF1, 0);
581 } else if (!IS_24XX(isp)) {
582 ISP_WRITE(isp, BIU2100_CSR, 0);
586 * Reset RISC Processor
589 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RESET);
590 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_RELEASE);
591 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RESET);
593 ISP_WRITE(isp, HCCR, HCCR_CMD_RESET);
595 ISP_WRITE(isp, BIU_SEMA, 0);
599 * Post-RISC Reset stuff.
602 for (val = loops = 0; loops < 5000000; loops++) {
604 val = ISP_READ(isp, OUTMAILBOX0);
611 isp_prt(isp, ISP_LOGERR, "reset didn't clear");
614 } else if (IS_SCSI(isp)) {
615 uint16_t tmp = isp->isp_mdvec->dv_conf1;
617 * Busted FIFO. Turn off all but burst enables.
619 if (isp->isp_type == ISP_HA_SCSI_1040A) {
620 tmp &= BIU_BURST_ENABLE;
622 ISP_SETBITS(isp, BIU_CONF1, tmp);
623 if (tmp & BIU_BURST_ENABLE) {
624 ISP_SETBITS(isp, CDMA_CONF, DMA_ENABLE_BURST);
625 ISP_SETBITS(isp, DDMA_CONF, DMA_ENABLE_BURST);
627 if (SDPARAM(isp, 0)->isp_ptisp) {
628 if (SDPARAM(isp, 0)->isp_ultramode) {
629 while (ISP_READ(isp, RISC_MTR) != 0x1313) {
630 ISP_WRITE(isp, RISC_MTR, 0x1313);
631 ISP_WRITE(isp, HCCR, HCCR_CMD_STEP);
634 ISP_WRITE(isp, RISC_MTR, 0x1212);
637 * PTI specific register
639 ISP_WRITE(isp, RISC_EMB, DUAL_BANK);
641 ISP_WRITE(isp, RISC_MTR, 0x1212);
643 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
645 ISP_WRITE(isp, RISC_MTR2100, 0x1212);
646 if (IS_2200(isp) || IS_23XX(isp)) {
647 ISP_WRITE(isp, HCCR, HCCR_2X00_DISABLE_PARITY_PAUSE);
649 ISP_WRITE(isp, HCCR, HCCR_CMD_RELEASE);
652 ISP_WRITE(isp, isp->isp_rqstinrp, 0);
653 ISP_WRITE(isp, isp->isp_rqstoutrp, 0);
654 ISP_WRITE(isp, isp->isp_respinrp, 0);
655 ISP_WRITE(isp, isp->isp_respoutrp, 0);
657 ISP_WRITE(isp, BIU2400_PRI_REQINP, 0);
658 ISP_WRITE(isp, BIU2400_PRI_REQOUTP, 0);
659 ISP_WRITE(isp, BIU2400_ATIO_RSPINP, 0);
660 ISP_WRITE(isp, BIU2400_ATIO_RSPOUTP, 0);
664 * Do MD specific post initialization
669 * Wait for everything to finish firing up.
671 * Avoid doing this on early 2312s because you can generate a PCI
672 * parity error (chip breakage).
674 if (IS_2312(isp) && isp->isp_revision < 2) {
677 loops = MBOX_DELAY_COUNT;
678 while (ISP_READ(isp, OUTMAILBOX0) == MBOX_BUSY) {
682 isp_prt(isp, ISP_LOGERR, "MBOX_BUSY never cleared on reset");
689 * Up until this point we've done everything by just reading or
690 * setting registers. From this point on we rely on at least *some*
691 * kind of firmware running in the card.
695 * Do some sanity checking by running a NOP command.
696 * If it succeeds, the ROM firmware is now running.
698 MBSINIT(&mbs, MBOX_NO_OP, MBLOGALL, 0);
699 isp_mboxcmd(isp, &mbs);
700 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
701 isp_prt(isp, ISP_LOGERR, "NOP command failed (%x)", mbs.param[0]);
707 * Do some operational tests
710 if (IS_SCSI(isp) || IS_24XX(isp)) {
711 static const uint16_t patterns[MAX_MAILBOX] = {
712 0x0000, 0xdead, 0xbeef, 0xffff,
713 0xa5a5, 0x5a5a, 0x7f7f, 0x7ff7,
714 0x3421, 0xabcd, 0xdcba, 0xfeef,
715 0xbead, 0xdebe, 0x2222, 0x3333,
716 0x5555, 0x6666, 0x7777, 0xaaaa,
717 0xffff, 0xdddd, 0x9999, 0x1fbc,
718 0x6666, 0x6677, 0x1122, 0x33ff,
719 0x0000, 0x0001, 0x1000, 0x1010,
721 int nmbox = ISP_NMBOX(isp);
724 MBSINIT(&mbs, MBOX_MAILBOX_REG_TEST, MBLOGALL, 0);
725 for (i = 1; i < nmbox; i++) {
726 mbs.param[i] = patterns[i];
728 isp_mboxcmd(isp, &mbs);
729 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
733 for (i = 1; i < nmbox; i++) {
734 if (mbs.param[i] != patterns[i]) {
736 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]);
743 * Download new Firmware, unless requested not to do so.
744 * This is made slightly trickier in some cases where the
745 * firmware of the ROM revision is newer than the revision
746 * compiled into the driver. So, where we used to compare
747 * versions of our f/w and the ROM f/w, now we just see
748 * whether we have f/w at all and whether a config flag
749 * has disabled our download.
751 if ((isp->isp_mdvec->dv_ispfw == NULL) || (isp->isp_confopts & ISP_CFG_NORELOAD)) {
756 code_org = ISP_CODE_ORG_2400;
757 } else if (IS_23XX(isp)) {
758 code_org = ISP_CODE_ORG_2300;
760 code_org = ISP_CODE_ORG;
763 if (dodnld && IS_24XX(isp)) {
764 const uint32_t *ptr = isp->isp_mdvec->dv_ispfw;
768 * Keep loading until we run out of f/w.
770 code_org = ptr[2]; /* 1st load address is our start addr */
776 isp_prt(isp, ISP_LOGDEBUG0, "load 0x%x words of code at load address 0x%x", ptr[3], ptr[2]);
782 while (wi < ptr[3]) {
786 nw = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) >> 2;
790 cp = isp->isp_rquest;
791 for (i = 0; i < nw; i++) {
792 ISP_IOXPUT_32(isp, ptr[wi++], &cp[i]);
795 MEMORYBARRIER(isp, SYNC_REQUEST, 0, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)), -1);
797 MBSINIT(&mbs, 0, MBLOGALL, 0);
798 if (la < 0x10000 && nw < 0x10000) {
799 mbs.param[0] = MBOX_LOAD_RISC_RAM_2100;
801 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
802 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
804 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
805 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
806 isp_prt(isp, ISP_LOGDEBUG0, "LOAD RISC RAM 2100 %u words at load address 0x%x", nw, la);
807 } else if (wordload) {
812 ucd.cp = (const uint32_t *)cp;
813 mbs.param[0] = MBOX_WRITE_RAM_WORD_EXTENDED;
815 mbs.param[2] = (*ucd.np);
816 mbs.param[3] = (*ucd.np) >> 16;
817 mbs.param[8] = la >> 16;
818 isp->isp_mbxwrk0 = nw - 1;
819 isp->isp_mbxworkp = ucd.np+1;
820 isp->isp_mbxwrk1 = (la + 1);
821 isp->isp_mbxwrk8 = (la + 1) >> 16;
822 isp_prt(isp, ISP_LOGDEBUG0, "WRITE RAM WORD EXTENDED %u words at load address 0x%x", nw, la);
824 mbs.param[0] = MBOX_LOAD_RISC_RAM;
826 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
827 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
828 mbs.param[4] = nw >> 16;
830 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
831 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
832 mbs.param[8] = la >> 16;
833 isp_prt(isp, ISP_LOGDEBUG0, "LOAD RISC RAM %u words at load address 0x%x", nw, la);
835 isp_mboxcmd(isp, &mbs);
836 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
837 if (mbs.param[0] == MBOX_HOST_INTERFACE_ERROR) {
838 isp_prt(isp, ISP_LOGERR, "switching to word load");
842 isp_prt(isp, ISP_LOGERR, "F/W Risc Ram Load Failed");
854 isp->isp_loaded_fw = 1;
855 } else if (dodnld && IS_23XX(isp)) {
856 const uint16_t *ptr = isp->isp_mdvec->dv_ispfw;
857 uint16_t wi, wl, segno;
866 isp_prt(isp, ISP_LOGDEBUG0, "load 0x%x words of code at load address 0x%x", ptr[3], la);
871 while (wi < ptr[3]) {
875 nw = ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)) >> 1;
879 if (nw > (1 << 15)) {
882 cp = isp->isp_rquest;
883 for (i = 0; i < nw; i++) {
884 ISP_IOXPUT_16(isp, ptr[wi++], &cp[i]);
887 MEMORYBARRIER(isp, SYNC_REQUEST, 0, ISP_QUEUE_SIZE(RQUEST_QUEUE_LEN(isp)), -1);
888 MBSINIT(&mbs, 0, MBLOGALL, 0);
890 mbs.param[0] = MBOX_LOAD_RISC_RAM_2100;
892 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
893 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
895 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
896 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
897 isp_prt(isp, ISP_LOGDEBUG1, "LOAD RISC RAM 2100 %u words at load address 0x%x\n", nw, la);
899 mbs.param[0] = MBOX_LOAD_RISC_RAM;
901 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
902 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
904 mbs.param[6] = DMA_WD3(isp->isp_rquest_dma);
905 mbs.param[7] = DMA_WD2(isp->isp_rquest_dma);
906 mbs.param[8] = la >> 16;
907 isp_prt(isp, ISP_LOGDEBUG1, "LOAD RISC RAM %u words at load address 0x%x\n", nw, la);
909 isp_mboxcmd(isp, &mbs);
910 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
911 isp_prt(isp, ISP_LOGERR, "F/W Risc Ram Load Failed");
927 * If we're a 2322, the firmware actually comes in
928 * three chunks. We loaded the first at the code_org
929 * address. The other two chunks, which follow right
930 * after each other in memory here, get loaded at
931 * addresses specfied at offset 0x9..0xB.
936 la = ptr[5] | ((ptr[4] & 0x3f) << 16);
938 isp->isp_loaded_fw = 1;
944 ucd.cp = isp->isp_mdvec->dv_ispfw;
945 isp->isp_mbxworkp = &ucd.np[1];
946 isp->isp_mbxwrk0 = ucd.np[3] - 1;
947 isp->isp_mbxwrk1 = code_org + 1;
948 MBSINIT(&mbs, MBOX_WRITE_RAM_WORD, MBLOGNONE, 0);
949 mbs.param[1] = code_org;
950 mbs.param[2] = ucd.np[0];
951 isp_prt(isp, ISP_LOGDEBUG1, "WRITE RAM %u words at load address 0x%x", ucd.np[3], code_org);
952 isp_mboxcmd(isp, &mbs);
953 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
954 isp_prt(isp, ISP_LOGERR, "F/W download failed at word %d", isp->isp_mbxwrk1 - code_org);
959 isp->isp_loaded_fw = 0;
960 isp_prt(isp, ISP_LOGDEBUG2, "skipping f/w download");
964 * If we loaded firmware, verify its checksum
966 if (isp->isp_loaded_fw) {
967 MBSINIT(&mbs, MBOX_VERIFY_CHECKSUM, MBLOGNONE, 0);
968 mbs.param[0] = MBOX_VERIFY_CHECKSUM;
970 mbs.param[1] = code_org >> 16;
971 mbs.param[2] = code_org;
973 mbs.param[1] = code_org;
975 isp_mboxcmd(isp, &mbs);
976 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
977 isp_prt(isp, ISP_LOGERR, dcrc);
984 * Now start it rolling.
986 * If we didn't actually download f/w,
987 * we still need to (re)start it.
991 MBSINIT(&mbs, MBOX_EXEC_FIRMWARE, MBLOGALL, 5000000);
993 mbs.param[1] = code_org >> 16;
994 mbs.param[2] = code_org;
995 if (isp->isp_loaded_fw) {
1003 } else if (IS_2322(isp)) {
1004 mbs.param[1] = code_org;
1005 if (isp->isp_loaded_fw) {
1011 mbs.param[1] = code_org;
1013 isp_mboxcmd(isp, &mbs);
1014 if (IS_2322(isp) || IS_24XX(isp)) {
1015 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1023 * Set CLOCK RATE, but only if asked to.
1025 if (isp->isp_clock) {
1026 MBSINIT(&mbs, MBOX_SET_CLOCK_RATE, MBLOGALL, 0);
1027 mbs.param[1] = isp->isp_clock;
1028 isp_mboxcmd(isp, &mbs);
1029 /* we will try not to care if this fails */
1034 * Ask the chip for the current firmware version.
1035 * This should prove that the new firmware is working.
1037 MBSINIT(&mbs, MBOX_ABOUT_FIRMWARE, MBLOGALL, 0);
1038 isp_mboxcmd(isp, &mbs);
1039 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1045 * The SBus firmware that we are using apparently does not return
1046 * major, minor, micro revisions in the mailbox registers, which
1047 * is really, really, annoying.
1049 if (ISP_SBUS_SUPPORTED && isp->isp_bustype == ISP_BT_SBUS) {
1051 #ifdef ISP_TARGET_MODE
1052 isp->isp_fwrev[0] = 7;
1053 isp->isp_fwrev[1] = 55;
1055 isp->isp_fwrev[0] = 1;
1056 isp->isp_fwrev[1] = 37;
1058 isp->isp_fwrev[2] = 0;
1061 isp->isp_fwrev[0] = mbs.param[1];
1062 isp->isp_fwrev[1] = mbs.param[2];
1063 isp->isp_fwrev[2] = mbs.param[3];
1068 * We do not believe firmware attributes for 2100 code less
1069 * than 1.17.0, unless it's the firmware we specifically
1072 * Note that all 22XX and later f/w is greater than 1.X.0.
1074 if ((ISP_FW_OLDER_THAN(isp, 1, 17, 1))) {
1075 #ifdef USE_SMALLER_2100_FIRMWARE
1076 isp->isp_fwattr = ISP_FW_ATTR_SCCLUN;
1078 isp->isp_fwattr = 0;
1081 isp->isp_fwattr = mbs.param[6];
1084 isp->isp_fwattr |= ((uint64_t) mbs.param[15]) << 16;
1085 if (isp->isp_fwattr & ISP2400_FW_ATTR_EXTNDED) {
1087 (((uint64_t) mbs.param[16]) << 32) |
1088 (((uint64_t) mbs.param[17]) << 48);
1091 } else if (IS_SCSI(isp)) {
1092 #ifndef ISP_TARGET_MODE
1093 isp->isp_fwattr = ISP_FW_ATTR_TMODE;
1095 isp->isp_fwattr = 0;
1099 isp_prt(isp, ISP_LOGCONFIG, "Board Type %s, Chip Revision 0x%x, %s F/W Revision %d.%d.%d",
1100 btype, isp->isp_revision, dodnld? "loaded" : "resident", isp->isp_fwrev[0], isp->isp_fwrev[1], isp->isp_fwrev[2]);
1102 fwt = isp->isp_fwattr;
1104 buf = FCPARAM(isp, 0)->isp_scratch;
1105 ISP_SNPRINTF(buf, ISP_FC_SCRLEN, "Attributes:");
1106 if (fwt & ISP2400_FW_ATTR_CLASS2) {
1107 fwt ^=ISP2400_FW_ATTR_CLASS2;
1108 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s Class2", buf);
1110 if (fwt & ISP2400_FW_ATTR_IP) {
1111 fwt ^=ISP2400_FW_ATTR_IP;
1112 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s IP", buf);
1114 if (fwt & ISP2400_FW_ATTR_MULTIID) {
1115 fwt ^=ISP2400_FW_ATTR_MULTIID;
1116 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s MultiID", buf);
1118 if (fwt & ISP2400_FW_ATTR_SB2) {
1119 fwt ^=ISP2400_FW_ATTR_SB2;
1120 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s SB2", buf);
1122 if (fwt & ISP2400_FW_ATTR_T10CRC) {
1123 fwt ^=ISP2400_FW_ATTR_T10CRC;
1124 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s T10CRC", buf);
1126 if (fwt & ISP2400_FW_ATTR_VI) {
1127 fwt ^=ISP2400_FW_ATTR_VI;
1128 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VI", buf);
1130 if (fwt & ISP2400_FW_ATTR_MQ) {
1131 fwt ^=ISP2400_FW_ATTR_MQ;
1132 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s MQ", buf);
1134 if (fwt & ISP2400_FW_ATTR_MSIX) {
1135 fwt ^=ISP2400_FW_ATTR_MSIX;
1136 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s MSIX", buf);
1138 if (fwt & ISP2400_FW_ATTR_FCOE) {
1139 fwt ^=ISP2400_FW_ATTR_FCOE;
1140 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s FCOE", buf);
1142 if (fwt & ISP2400_FW_ATTR_VP0) {
1143 fwt ^= ISP2400_FW_ATTR_VP0;
1144 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VP0_Decoupling", buf);
1146 if (fwt & ISP2400_FW_ATTR_EXPFW) {
1147 fwt ^= ISP2400_FW_ATTR_EXPFW;
1148 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s (Experimental)", buf);
1150 if (fwt & ISP2400_FW_ATTR_HOTFW) {
1151 fwt ^= ISP2400_FW_ATTR_HOTFW;
1152 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s HotFW", buf);
1154 fwt &= ~ISP2400_FW_ATTR_EXTNDED;
1155 if (fwt & ISP2400_FW_ATTR_EXTVP) {
1156 fwt ^= ISP2400_FW_ATTR_EXTVP;
1157 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s ExtVP", buf);
1159 if (fwt & ISP2400_FW_ATTR_VN2VN) {
1160 fwt ^= ISP2400_FW_ATTR_VN2VN;
1161 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VN2VN", buf);
1163 if (fwt & ISP2400_FW_ATTR_EXMOFF) {
1164 fwt ^= ISP2400_FW_ATTR_EXMOFF;
1165 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s EXMOFF", buf);
1167 if (fwt & ISP2400_FW_ATTR_NPMOFF) {
1168 fwt ^= ISP2400_FW_ATTR_NPMOFF;
1169 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s NPMOFF", buf);
1171 if (fwt & ISP2400_FW_ATTR_DIFCHOP) {
1172 fwt ^= ISP2400_FW_ATTR_DIFCHOP;
1173 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s DIFCHOP", buf);
1175 if (fwt & ISP2400_FW_ATTR_SRIOV) {
1176 fwt ^= ISP2400_FW_ATTR_SRIOV;
1177 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s SRIOV", buf);
1179 if (fwt & ISP2400_FW_ATTR_ASICTMP) {
1180 fwt ^= ISP2400_FW_ATTR_ASICTMP;
1181 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s ASICTMP", buf);
1183 if (fwt & ISP2400_FW_ATTR_ATIOMQ) {
1184 fwt ^= ISP2400_FW_ATTR_ATIOMQ;
1185 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s ATIOMQ", buf);
1188 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s (unknown 0x%08x%08x)", buf,
1189 (uint32_t) (fwt >> 32), (uint32_t) fwt);
1191 isp_prt(isp, ISP_LOGCONFIG, "%s", buf);
1192 } else if (IS_FC(isp)) {
1193 buf = FCPARAM(isp, 0)->isp_scratch;
1194 ISP_SNPRINTF(buf, ISP_FC_SCRLEN, "Attributes:");
1195 if (fwt & ISP_FW_ATTR_TMODE) {
1196 fwt ^=ISP_FW_ATTR_TMODE;
1197 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s TargetMode", buf);
1199 if (fwt & ISP_FW_ATTR_SCCLUN) {
1200 fwt ^=ISP_FW_ATTR_SCCLUN;
1201 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s SCC-Lun", buf);
1203 if (fwt & ISP_FW_ATTR_FABRIC) {
1204 fwt ^=ISP_FW_ATTR_FABRIC;
1205 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s Fabric", buf);
1207 if (fwt & ISP_FW_ATTR_CLASS2) {
1208 fwt ^=ISP_FW_ATTR_CLASS2;
1209 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s Class2", buf);
1211 if (fwt & ISP_FW_ATTR_FCTAPE) {
1212 fwt ^=ISP_FW_ATTR_FCTAPE;
1213 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s FC-Tape", buf);
1215 if (fwt & ISP_FW_ATTR_IP) {
1216 fwt ^=ISP_FW_ATTR_IP;
1217 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s IP", buf);
1219 if (fwt & ISP_FW_ATTR_VI) {
1220 fwt ^=ISP_FW_ATTR_VI;
1221 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VI", buf);
1223 if (fwt & ISP_FW_ATTR_VI_SOLARIS) {
1224 fwt ^=ISP_FW_ATTR_VI_SOLARIS;
1225 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s VI_SOLARIS", buf);
1227 if (fwt & ISP_FW_ATTR_2KLOGINS) {
1228 fwt ^=ISP_FW_ATTR_2KLOGINS;
1229 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s 2K-Login", buf);
1232 ISP_SNPRINTF(buf, ISP_FC_SCRLEN - strlen(buf), "%s (unknown 0x%08x%08x)", buf,
1233 (uint32_t) (fwt >> 32), (uint32_t) fwt);
1235 isp_prt(isp, ISP_LOGCONFIG, "%s", buf);
1239 MBSINIT(&mbs, MBOX_GET_RESOURCE_COUNT, MBLOGALL, 0);
1240 isp_mboxcmd(isp, &mbs);
1241 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1245 if (isp->isp_maxcmds >= mbs.param[3]) {
1246 isp->isp_maxcmds = mbs.param[3];
1249 MBSINIT(&mbs, MBOX_GET_FIRMWARE_STATUS, MBLOGALL, 0);
1250 isp_mboxcmd(isp, &mbs);
1251 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1255 if (isp->isp_maxcmds >= mbs.param[2]) {
1256 isp->isp_maxcmds = mbs.param[2];
1259 isp_prt(isp, ISP_LOGCONFIG, "%d max I/O command limit set", isp->isp_maxcmds);
1262 * If we don't have Multi-ID f/w loaded, we need to restrict channels to one.
1263 * Only make this check for non-SCSI cards (I'm not sure firmware attributes
1266 if (IS_FC(isp) && isp->isp_nchan > 1) {
1267 if (!ISP_CAP_MULTI_ID(isp)) {
1268 isp_prt(isp, ISP_LOGWARN, "non-MULTIID f/w loaded, "
1269 "only can enable 1 of %d channels", isp->isp_nchan);
1271 } else if (!ISP_CAP_VP0(isp)) {
1272 isp_prt(isp, ISP_LOGWARN, "We can not use MULTIID "
1273 "feature properly without VP0_Decoupling");
1278 for (i = 0; i < isp->isp_nchan; i++)
1279 isp_change_fw_state(isp, i, FW_CONFIG_WAIT);
1281 if (isp->isp_dead) {
1283 ISP_DISABLE_INTS(isp);
1287 isp->isp_state = ISP_RESETSTATE;
1290 * Okay- now that we have new firmware running, we now (re)set our
1291 * notion of how many luns we support. This is somewhat tricky because
1292 * if we haven't loaded firmware, we sometimes do not have an easy way
1293 * of knowing how many luns we support.
1295 * Expanded lun firmware gives you 32 luns for SCSI cards and
1296 * 16384 luns for Fibre Channel cards.
1298 * It turns out that even for QLogic 2100s with ROM 1.10 and above
1299 * we do get a firmware attributes word returned in mailbox register 6.
1301 * Because the lun is in a different position in the Request Queue
1302 * Entry structure for Fibre Channel with expanded lun firmware, we
1303 * can only support one lun (lun zero) when we don't know what kind
1304 * of firmware we're running.
1308 if (IS_ULTRA2(isp) || IS_ULTRA3(isp)) {
1309 isp->isp_maxluns = 32;
1311 isp->isp_maxluns = 8;
1314 isp->isp_maxluns = 8;
1317 if (ISP_CAP_SCCFW(isp)) {
1318 isp->isp_maxluns = 0; /* No limit -- 2/8 bytes */
1320 isp->isp_maxluns = 16;
1325 * We get some default values established. As a side
1326 * effect, NVRAM is read here (unless overriden by
1327 * a configuration flag).
1329 if (do_load_defaults) {
1331 isp_setdfltsdparm(isp);
1333 for (i = 0; i < isp->isp_nchan; i++) {
1334 isp_setdfltfcparm(isp, i);
1341 * Initialize Parameters of Hardware to a known state.
1343 * Locks are held before coming here.
1347 isp_init(ispsoftc_t *isp)
1351 isp_fibre_init_2400(isp);
1353 isp_fibre_init(isp);
1358 GET_NANOTIME(&isp->isp_init_time);
1362 isp_scsi_init(ispsoftc_t *isp)
1364 sdparam *sdp_chan0, *sdp_chan1;
1367 isp->isp_state = ISP_INITSTATE;
1369 sdp_chan0 = SDPARAM(isp, 0);
1370 sdp_chan1 = sdp_chan0;
1371 if (IS_DUALBUS(isp)) {
1372 sdp_chan1 = SDPARAM(isp, 1);
1375 /* First do overall per-card settings. */
1378 * If we have fast memory timing enabled, turn it on.
1380 if (sdp_chan0->isp_fast_mttr) {
1381 ISP_WRITE(isp, RISC_MTR, 0x1313);
1385 * Set Retry Delay and Count.
1386 * You set both channels at the same time.
1388 MBSINIT(&mbs, MBOX_SET_RETRY_COUNT, MBLOGALL, 0);
1389 mbs.param[1] = sdp_chan0->isp_retry_count;
1390 mbs.param[2] = sdp_chan0->isp_retry_delay;
1391 mbs.param[6] = sdp_chan1->isp_retry_count;
1392 mbs.param[7] = sdp_chan1->isp_retry_delay;
1393 isp_mboxcmd(isp, &mbs);
1394 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1399 * Set ASYNC DATA SETUP time. This is very important.
1401 MBSINIT(&mbs, MBOX_SET_ASYNC_DATA_SETUP_TIME, MBLOGALL, 0);
1402 mbs.param[1] = sdp_chan0->isp_async_data_setup;
1403 mbs.param[2] = sdp_chan1->isp_async_data_setup;
1404 isp_mboxcmd(isp, &mbs);
1405 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1410 * Set ACTIVE Negation State.
1412 MBSINIT(&mbs, MBOX_SET_ACT_NEG_STATE, MBLOGNONE, 0);
1414 (sdp_chan0->isp_req_ack_active_neg << 4) |
1415 (sdp_chan0->isp_data_line_active_neg << 5);
1417 (sdp_chan1->isp_req_ack_active_neg << 4) |
1418 (sdp_chan1->isp_data_line_active_neg << 5);
1419 isp_mboxcmd(isp, &mbs);
1420 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1421 isp_prt(isp, ISP_LOGERR,
1422 "failed to set active negation state (%d,%d), (%d,%d)",
1423 sdp_chan0->isp_req_ack_active_neg,
1424 sdp_chan0->isp_data_line_active_neg,
1425 sdp_chan1->isp_req_ack_active_neg,
1426 sdp_chan1->isp_data_line_active_neg);
1433 * Set the Tag Aging limit
1435 MBSINIT(&mbs, MBOX_SET_TAG_AGE_LIMIT, MBLOGALL, 0);
1436 mbs.param[1] = sdp_chan0->isp_tag_aging;
1437 mbs.param[2] = sdp_chan1->isp_tag_aging;
1438 isp_mboxcmd(isp, &mbs);
1439 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1440 isp_prt(isp, ISP_LOGERR, "failed to set tag age limit (%d,%d)",
1441 sdp_chan0->isp_tag_aging, sdp_chan1->isp_tag_aging);
1446 * Set selection timeout.
1448 MBSINIT(&mbs, MBOX_SET_SELECT_TIMEOUT, MBLOGALL, 0);
1449 mbs.param[1] = sdp_chan0->isp_selection_timeout;
1450 mbs.param[2] = sdp_chan1->isp_selection_timeout;
1451 isp_mboxcmd(isp, &mbs);
1452 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1456 /* now do per-channel settings */
1457 isp_scsi_channel_init(isp, 0);
1458 if (IS_DUALBUS(isp))
1459 isp_scsi_channel_init(isp, 1);
1462 * Now enable request/response queues
1465 if (IS_ULTRA2(isp) || IS_1240(isp)) {
1466 MBSINIT(&mbs, MBOX_INIT_RES_QUEUE_A64, MBLOGALL, 0);
1467 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1468 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1469 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1471 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1472 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1473 isp_mboxcmd(isp, &mbs);
1474 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1477 isp->isp_residx = isp->isp_resodx = mbs.param[5];
1479 MBSINIT(&mbs, MBOX_INIT_REQ_QUEUE_A64, MBLOGALL, 0);
1480 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1481 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1482 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1484 mbs.param[6] = DMA_WD3(isp->isp_result_dma);
1485 mbs.param[7] = DMA_WD2(isp->isp_result_dma);
1486 isp_mboxcmd(isp, &mbs);
1487 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1490 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1492 MBSINIT(&mbs, MBOX_INIT_RES_QUEUE, MBLOGALL, 0);
1493 mbs.param[1] = RESULT_QUEUE_LEN(isp);
1494 mbs.param[2] = DMA_WD1(isp->isp_result_dma);
1495 mbs.param[3] = DMA_WD0(isp->isp_result_dma);
1497 isp_mboxcmd(isp, &mbs);
1498 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1501 isp->isp_residx = isp->isp_resodx = mbs.param[5];
1503 MBSINIT(&mbs, MBOX_INIT_REQ_QUEUE, MBLOGALL, 0);
1504 mbs.param[1] = RQUEST_QUEUE_LEN(isp);
1505 mbs.param[2] = DMA_WD1(isp->isp_rquest_dma);
1506 mbs.param[3] = DMA_WD0(isp->isp_rquest_dma);
1508 isp_mboxcmd(isp, &mbs);
1509 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1512 isp->isp_reqidx = isp->isp_reqodx = mbs.param[4];
1516 * Turn on LVD transitions for ULTRA2 or better and other features
1518 * Now that we have 32 bit handles, don't do any fast posting
1519 * any more. For Ultra2/Ultra3 cards, we can turn on 32 bit RIO
1520 * operation or use fast posting. To be conservative, we'll only
1521 * do this for Ultra3 cards now because the other cards are so
1522 * rare for this author to find and test with.
1525 MBSINIT(&mbs, MBOX_SET_FW_FEATURES, MBLOGALL, 0);
1527 mbs.param[1] |= FW_FEATURE_LVD_NOTIFY;
1530 mbs.param[1] |= FW_FEATURE_FAST_POST;
1533 mbs.param[1] |= FW_FEATURE_RIO_32BIT;
1535 if (mbs.param[1] != 0) {
1536 uint16_t sfeat = mbs.param[1];
1537 isp_mboxcmd(isp, &mbs);
1538 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
1539 isp_prt(isp, ISP_LOGINFO,
1540 "Enabled FW features (0x%x)", sfeat);
1544 isp->isp_state = ISP_RUNSTATE;
1548 isp_scsi_channel_init(ispsoftc_t *isp, int chan)
1554 sdp = SDPARAM(isp, chan);
1557 * Set (possibly new) Initiator ID.
1559 MBSINIT(&mbs, MBOX_SET_INIT_SCSI_ID, MBLOGALL, 0);
1560 mbs.param[1] = (chan << 7) | sdp->isp_initiator_id;
1561 isp_mboxcmd(isp, &mbs);
1562 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1565 isp_prt(isp, ISP_LOGINFO, "Chan %d Initiator ID is %d",
1566 chan, sdp->isp_initiator_id);
1570 * Set current per-target parameters to an initial safe minimum.
1572 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1576 if (sdp->isp_devparam[tgt].dev_enable == 0) {
1579 #ifndef ISP_TARGET_MODE
1580 sdf = sdp->isp_devparam[tgt].goal_flags;
1581 sdf &= DPARM_SAFE_DFLT;
1583 * It is not quite clear when this changed over so that
1584 * we could force narrow and async for 1000/1020 cards,
1585 * but assume that this is only the case for loaded
1588 if (isp->isp_loaded_fw) {
1589 sdf |= DPARM_NARROW | DPARM_ASYNC;
1593 * The !$*!)$!$)* f/w uses the same index into some
1594 * internal table to decide how to respond to negotiations,
1595 * so if we've said "let's be safe" for ID X, and ID X
1596 * selects *us*, the negotiations will back to 'safe'
1597 * (as in narrow/async). What the f/w *should* do is
1598 * use the initiator id settings to decide how to respond.
1600 sdp->isp_devparam[tgt].goal_flags = sdf = DPARM_DEFAULT;
1602 MBSINIT(&mbs, MBOX_SET_TARGET_PARAMS, MBLOGNONE, 0);
1603 mbs.param[1] = (chan << 15) | (tgt << 8);
1605 if ((sdf & DPARM_SYNC) == 0) {
1609 (sdp->isp_devparam[tgt].goal_offset << 8) |
1610 (sdp->isp_devparam[tgt].goal_period);
1612 isp_prt(isp, ISP_LOGDEBUG0, "Initial Settings bus%d tgt%d flags 0x%x off 0x%x per 0x%x",
1613 chan, tgt, mbs.param[2], mbs.param[3] >> 8, mbs.param[3] & 0xff);
1614 isp_mboxcmd(isp, &mbs);
1615 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1616 sdf = DPARM_SAFE_DFLT;
1617 MBSINIT(&mbs, MBOX_SET_TARGET_PARAMS, MBLOGALL, 0);
1618 mbs.param[1] = (tgt << 8) | (chan << 15);
1621 isp_mboxcmd(isp, &mbs);
1622 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1628 * We don't update any information directly from the f/w
1629 * because we need to run at least one command to cause a
1630 * new state to be latched up. So, we just assume that we
1631 * converge to the values we just had set.
1633 * Ensure that we don't believe tagged queuing is enabled yet.
1634 * It turns out that sometimes the ISP just ignores our
1635 * attempts to set parameters for devices that it hasn't
1638 sdp->isp_devparam[tgt].actv_flags = sdf & ~DPARM_TQING;
1639 for (lun = 0; lun < (int) isp->isp_maxluns; lun++) {
1640 MBSINIT(&mbs, MBOX_SET_DEV_QUEUE_PARAMS, MBLOGALL, 0);
1641 mbs.param[1] = (chan << 15) | (tgt << 8) | lun;
1642 mbs.param[2] = sdp->isp_max_queue_depth;
1643 mbs.param[3] = sdp->isp_devparam[tgt].exc_throttle;
1644 isp_mboxcmd(isp, &mbs);
1645 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1650 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
1651 if (sdp->isp_devparam[tgt].dev_refresh) {
1652 sdp->sendmarker = 1;
1660 * Fibre Channel specific initialization.
1663 isp_fibre_init(ispsoftc_t *isp)
1666 isp_icb_t local, *icbp = &local;
1670 * We only support one channel on non-24XX cards
1672 fcp = FCPARAM(isp, 0);
1673 if (fcp->role == ISP_ROLE_NONE)
1676 isp->isp_state = ISP_INITSTATE;
1677 ISP_MEMZERO(icbp, sizeof (*icbp));
1678 icbp->icb_version = ICB_VERSION1;
1679 icbp->icb_fwoptions = fcp->isp_fwoptions;
1682 * Firmware Options are either retrieved from NVRAM or
1683 * are patched elsewhere. We check them for sanity here
1684 * and make changes based on board revision, but otherwise
1685 * let others decide policy.
1689 * If this is a 2100 < revision 5, we have to turn off FAIRNESS.
1691 if (IS_2100(isp) && isp->isp_revision < 5) {
1692 icbp->icb_fwoptions &= ~ICBOPT_FAIRNESS;
1696 * We have to use FULL LOGIN even though it resets the loop too much
1697 * because otherwise port database entries don't get updated after
1698 * a LIP- this is a known f/w bug for 2100 f/w less than 1.17.0.
1700 if (!ISP_FW_NEWER_THAN(isp, 1, 17, 0)) {
1701 icbp->icb_fwoptions |= ICBOPT_FULL_LOGIN;
1705 * Insist on Port Database Update Async notifications
1707 icbp->icb_fwoptions |= ICBOPT_PDBCHANGE_AE;
1710 * Make sure that target role reflects into fwoptions.
1712 if (fcp->role & ISP_ROLE_TARGET) {
1713 icbp->icb_fwoptions |= ICBOPT_TGT_ENABLE;
1715 icbp->icb_fwoptions &= ~ICBOPT_TGT_ENABLE;
1718 if (fcp->role & ISP_ROLE_INITIATOR) {
1719 icbp->icb_fwoptions &= ~ICBOPT_INI_DISABLE;
1721 icbp->icb_fwoptions |= ICBOPT_INI_DISABLE;
1724 icbp->icb_maxfrmlen = DEFAULT_FRAMESIZE(isp);
1725 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN || icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
1726 isp_prt(isp, ISP_LOGERR, "bad frame length (%d) from NVRAM- using %d", DEFAULT_FRAMESIZE(isp), ICB_DFLT_FRMLEN);
1727 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
1729 icbp->icb_maxalloc = fcp->isp_maxalloc;
1730 if (icbp->icb_maxalloc < 1) {
1731 isp_prt(isp, ISP_LOGERR, "bad maximum allocation (%d)- using 16", fcp->isp_maxalloc);
1732 icbp->icb_maxalloc = 16;
1734 icbp->icb_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
1735 if (icbp->icb_execthrottle < 1) {
1736 isp_prt(isp, ISP_LOGERR, "bad execution throttle of %d- using %d", DEFAULT_EXEC_THROTTLE(isp), ICB_DFLT_THROTTLE);
1737 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
1739 icbp->icb_retry_delay = fcp->isp_retry_delay;
1740 icbp->icb_retry_count = fcp->isp_retry_count;
1741 if (fcp->isp_loopid < LOCAL_LOOP_LIM) {
1742 icbp->icb_hardaddr = fcp->isp_loopid;
1743 if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
1744 icbp->icb_fwoptions |= ICBOPT_HARD_ADDRESS;
1746 icbp->icb_fwoptions |= ICBOPT_PREV_ADDRESS;
1750 * Right now we just set extended options to prefer point-to-point
1751 * over loop based upon some soft config options.
1753 * NB: for the 2300, ICBOPT_EXTENDED is required.
1757 * We can't have Fast Posting any more- we now
1758 * have 32 bit handles.
1760 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1761 } else if (IS_2200(isp) || IS_23XX(isp)) {
1762 icbp->icb_fwoptions |= ICBOPT_EXTENDED;
1764 icbp->icb_xfwoptions = fcp->isp_xfwoptions;
1766 if (ISP_CAP_FCTAPE(isp)) {
1767 if (isp->isp_confopts & ISP_CFG_NOFCTAPE)
1768 icbp->icb_xfwoptions &= ~ICBXOPT_FCTAPE;
1770 if (isp->isp_confopts & ISP_CFG_FCTAPE)
1771 icbp->icb_xfwoptions |= ICBXOPT_FCTAPE;
1773 if (icbp->icb_xfwoptions & ICBXOPT_FCTAPE) {
1774 icbp->icb_fwoptions &= ~ICBOPT_FULL_LOGIN; /* per documents */
1775 icbp->icb_xfwoptions |= ICBXOPT_FCTAPE_CCQ|ICBXOPT_FCTAPE_CONFIRM;
1776 FCPARAM(isp, 0)->fctape_enabled = 1;
1778 FCPARAM(isp, 0)->fctape_enabled = 0;
1781 icbp->icb_xfwoptions &= ~ICBXOPT_FCTAPE;
1782 FCPARAM(isp, 0)->fctape_enabled = 0;
1786 * Prefer or force Point-To-Point instead Loop?
1788 switch (isp->isp_confopts & ISP_CFG_PORT_PREF) {
1790 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1791 icbp->icb_xfwoptions |= ICBXOPT_PTP_2_LOOP;
1793 case ISP_CFG_NPORT_ONLY:
1794 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1795 icbp->icb_xfwoptions |= ICBXOPT_PTP_ONLY;
1797 case ISP_CFG_LPORT_ONLY:
1798 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1799 icbp->icb_xfwoptions |= ICBXOPT_LOOP_ONLY;
1803 * Let NVRAM settings define it if they are sane
1805 switch (icbp->icb_xfwoptions & ICBXOPT_TOPO_MASK) {
1806 case ICBXOPT_PTP_2_LOOP:
1807 case ICBXOPT_PTP_ONLY:
1808 case ICBXOPT_LOOP_ONLY:
1809 case ICBXOPT_LOOP_2_PTP:
1812 icbp->icb_xfwoptions &= ~ICBXOPT_TOPO_MASK;
1813 icbp->icb_xfwoptions |= ICBXOPT_LOOP_2_PTP;
1819 * We can't have Fast Posting any more- we now
1820 * have 32 bit handles.
1822 * RIO seemed to have to much breakage.
1824 * Just opt for safety.
1826 icbp->icb_xfwoptions &= ~ICBXOPT_RIO_16BIT;
1827 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1830 * QLogic recommends that FAST Posting be turned
1831 * off for 23XX cards and instead allow the HBA
1832 * to write response queue entries and interrupt
1833 * after a delay (ZIO).
1835 icbp->icb_fwoptions &= ~ICBOPT_FAST_POST;
1836 if ((fcp->isp_xfwoptions & ICBXOPT_TIMER_MASK) == ICBXOPT_ZIO) {
1837 icbp->icb_xfwoptions |= ICBXOPT_ZIO;
1838 icbp->icb_idelaytimer = 10;
1840 icbp->icb_zfwoptions = fcp->isp_zfwoptions;
1841 if (isp->isp_confopts & ISP_CFG_ONEGB) {
1842 icbp->icb_zfwoptions &= ~ICBZOPT_RATE_MASK;
1843 icbp->icb_zfwoptions |= ICBZOPT_RATE_ONEGB;
1844 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
1845 icbp->icb_zfwoptions &= ~ICBZOPT_RATE_MASK;
1846 icbp->icb_zfwoptions |= ICBZOPT_RATE_TWOGB;
1848 switch (icbp->icb_zfwoptions & ICBZOPT_RATE_MASK) {
1849 case ICBZOPT_RATE_ONEGB:
1850 case ICBZOPT_RATE_TWOGB:
1851 case ICBZOPT_RATE_AUTO:
1854 icbp->icb_zfwoptions &= ~ICBZOPT_RATE_MASK;
1855 icbp->icb_zfwoptions |= ICBZOPT_RATE_AUTO;
1864 * For 22XX > 2.1.26 && 23XX, set some options.
1866 if (ISP_FW_NEWER_THAN(isp, 2, 26, 0)) {
1867 MBSINIT(&mbs, MBOX_SET_FIRMWARE_OPTIONS, MBLOGALL, 0);
1868 mbs.param[1] = IFCOPT1_DISF7SWTCH|IFCOPT1_LIPASYNC|IFCOPT1_LIPF8;
1871 if (ISP_FW_NEWER_THAN(isp, 3, 16, 0)) {
1872 mbs.param[1] |= IFCOPT1_EQFQASYNC|IFCOPT1_CTIO_RETRY;
1873 if (fcp->role & ISP_ROLE_TARGET) {
1874 if (ISP_FW_NEWER_THAN(isp, 3, 25, 0)) {
1875 mbs.param[1] |= IFCOPT1_ENAPURE;
1877 mbs.param[3] = IFCOPT3_NOPRLI;
1880 isp_mboxcmd(isp, &mbs);
1881 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1885 icbp->icb_logintime = ICB_LOGIN_TOV;
1887 #ifdef ISP_TARGET_MODE
1888 if (IS_23XX(isp) && (icbp->icb_fwoptions & ICBOPT_TGT_ENABLE)) {
1889 icbp->icb_lunenables = 0xffff;
1890 icbp->icb_ccnt = DFLT_CMND_CNT;
1891 icbp->icb_icnt = DFLT_INOT_CNT;
1892 icbp->icb_lunetimeout = ICB_LUN_ENABLE_TOV;
1895 if (fcp->isp_wwnn && fcp->isp_wwpn) {
1896 icbp->icb_fwoptions |= ICBOPT_BOTH_WWNS;
1897 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, fcp->isp_wwnn);
1898 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1899 isp_prt(isp, ISP_LOGDEBUG1,
1900 "Setting ICB Node 0x%08x%08x Port 0x%08x%08x",
1901 ((uint32_t) (fcp->isp_wwnn >> 32)),
1902 ((uint32_t) (fcp->isp_wwnn)),
1903 ((uint32_t) (fcp->isp_wwpn >> 32)),
1904 ((uint32_t) (fcp->isp_wwpn)));
1905 } else if (fcp->isp_wwpn) {
1906 icbp->icb_fwoptions &= ~ICBOPT_BOTH_WWNS;
1907 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
1908 isp_prt(isp, ISP_LOGDEBUG1,
1909 "Setting ICB Port 0x%08x%08x",
1910 ((uint32_t) (fcp->isp_wwpn >> 32)),
1911 ((uint32_t) (fcp->isp_wwpn)));
1913 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
1916 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
1917 if (icbp->icb_rqstqlen < 1) {
1918 isp_prt(isp, ISP_LOGERR, "bad request queue length");
1920 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
1921 if (icbp->icb_rsltqlen < 1) {
1922 isp_prt(isp, ISP_LOGERR, "bad result queue length");
1924 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
1925 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
1926 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
1927 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
1928 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
1929 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
1930 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
1931 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
1933 if (FC_SCRATCH_ACQUIRE(isp, 0)) {
1934 isp_prt(isp, ISP_LOGERR, sacq);
1937 isp_prt(isp, ISP_LOGDEBUG0, "isp_fibre_init: fwopt 0x%x xfwopt 0x%x zfwopt 0x%x",
1938 icbp->icb_fwoptions, icbp->icb_xfwoptions, icbp->icb_zfwoptions);
1940 isp_put_icb(isp, icbp, (isp_icb_t *)fcp->isp_scratch);
1945 MBSINIT(&mbs, MBOX_INIT_FIRMWARE, MBLOGALL, 30000000);
1947 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
1948 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
1949 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
1950 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
1951 mbs.logval = MBLOGALL;
1952 isp_prt(isp, ISP_LOGDEBUG0, "INIT F/W from %p (%08x%08x)",
1953 fcp->isp_scratch, (uint32_t) ((uint64_t)fcp->isp_scdma >> 32),
1954 (uint32_t) fcp->isp_scdma);
1955 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp), 0);
1956 isp_mboxcmd(isp, &mbs);
1957 FC_SCRATCH_RELEASE(isp, 0);
1958 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
1959 isp_print_bytes(isp, "isp_fibre_init", sizeof (*icbp), icbp);
1962 isp->isp_reqidx = 0;
1963 isp->isp_reqodx = 0;
1964 isp->isp_residx = 0;
1965 isp->isp_resodx = 0;
1968 * Whatever happens, we're now committed to being here.
1970 isp->isp_state = ISP_RUNSTATE;
1974 isp_fibre_init_2400(ispsoftc_t *isp)
1977 isp_icb_2400_t local, *icbp = &local;
1982 * Check to see whether all channels have *some* kind of role
1984 for (chan = 0; chan < isp->isp_nchan; chan++) {
1985 fcp = FCPARAM(isp, chan);
1986 if (fcp->role != ISP_ROLE_NONE) {
1990 if (chan == isp->isp_nchan) {
1991 isp_prt(isp, ISP_LOG_WARN1, "all %d channels with role 'none'", chan);
1995 isp->isp_state = ISP_INITSTATE;
1998 * Start with channel 0.
2000 fcp = FCPARAM(isp, 0);
2003 * Turn on LIP F8 async event (1)
2005 MBSINIT(&mbs, MBOX_SET_FIRMWARE_OPTIONS, MBLOGALL, 0);
2007 isp_mboxcmd(isp, &mbs);
2008 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2012 ISP_MEMZERO(icbp, sizeof (*icbp));
2013 icbp->icb_fwoptions1 = fcp->isp_fwoptions;
2014 icbp->icb_fwoptions2 = fcp->isp_xfwoptions;
2015 icbp->icb_fwoptions3 = fcp->isp_zfwoptions;
2016 if (isp->isp_nchan > 1 && ISP_CAP_VP0(isp)) {
2017 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_INI_DISABLE;
2018 icbp->icb_fwoptions1 |= ICB2400_OPT1_TGT_ENABLE;
2020 if (fcp->role & ISP_ROLE_TARGET)
2021 icbp->icb_fwoptions1 |= ICB2400_OPT1_TGT_ENABLE;
2023 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_TGT_ENABLE;
2024 if (fcp->role & ISP_ROLE_INITIATOR)
2025 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_INI_DISABLE;
2027 icbp->icb_fwoptions1 |= ICB2400_OPT1_INI_DISABLE;
2030 icbp->icb_version = ICB_VERSION1;
2031 icbp->icb_maxfrmlen = DEFAULT_FRAMESIZE(isp);
2032 if (icbp->icb_maxfrmlen < ICB_MIN_FRMLEN || icbp->icb_maxfrmlen > ICB_MAX_FRMLEN) {
2033 isp_prt(isp, ISP_LOGERR, "bad frame length (%d) from NVRAM- using %d", DEFAULT_FRAMESIZE(isp), ICB_DFLT_FRMLEN);
2034 icbp->icb_maxfrmlen = ICB_DFLT_FRMLEN;
2037 icbp->icb_execthrottle = DEFAULT_EXEC_THROTTLE(isp);
2038 if (icbp->icb_execthrottle < 1) {
2039 isp_prt(isp, ISP_LOGERR, "bad execution throttle of %d- using %d", DEFAULT_EXEC_THROTTLE(isp), ICB_DFLT_THROTTLE);
2040 icbp->icb_execthrottle = ICB_DFLT_THROTTLE;
2044 * Set target exchange count. Take half if we are supporting both roles.
2046 if (icbp->icb_fwoptions1 & ICB2400_OPT1_TGT_ENABLE) {
2047 icbp->icb_xchgcnt = isp->isp_maxcmds;
2048 if ((icbp->icb_fwoptions1 & ICB2400_OPT1_INI_DISABLE) == 0)
2049 icbp->icb_xchgcnt >>= 1;
2052 if (fcp->isp_loopid < LOCAL_LOOP_LIM) {
2053 icbp->icb_hardaddr = fcp->isp_loopid;
2054 if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
2055 icbp->icb_fwoptions1 |= ICB2400_OPT1_HARD_ADDRESS;
2057 icbp->icb_fwoptions1 |= ICB2400_OPT1_PREV_ADDRESS;
2060 if (isp->isp_confopts & ISP_CFG_NOFCTAPE) {
2061 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_FCTAPE;
2063 if (isp->isp_confopts & ISP_CFG_FCTAPE) {
2064 icbp->icb_fwoptions2 |= ICB2400_OPT2_FCTAPE;
2067 for (chan = 0; chan < isp->isp_nchan; chan++) {
2068 if (icbp->icb_fwoptions2 & ICB2400_OPT2_FCTAPE)
2069 FCPARAM(isp, chan)->fctape_enabled = 1;
2071 FCPARAM(isp, chan)->fctape_enabled = 0;
2074 switch (isp->isp_confopts & ISP_CFG_PORT_PREF) {
2075 case ISP_CFG_NPORT_ONLY:
2076 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2077 icbp->icb_fwoptions2 |= ICB2400_OPT2_PTP_ONLY;
2079 case ISP_CFG_LPORT_ONLY:
2080 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2081 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_ONLY;
2084 /* ISP_CFG_PTP_2_LOOP not available in 24XX/25XX */
2085 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TOPO_MASK;
2086 icbp->icb_fwoptions2 |= ICB2400_OPT2_LOOP_2_PTP;
2090 switch (icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK) {
2091 case ICB2400_OPT2_ZIO:
2092 case ICB2400_OPT2_ZIO1:
2093 icbp->icb_idelaytimer = 0;
2098 isp_prt(isp, ISP_LOGWARN, "bad value %x in fwopt2 timer field", icbp->icb_fwoptions2 & ICB2400_OPT2_TIMER_MASK);
2099 icbp->icb_fwoptions2 &= ~ICB2400_OPT2_TIMER_MASK;
2103 if ((icbp->icb_fwoptions3 & ICB2400_OPT3_RSPSZ_MASK) == 0) {
2104 icbp->icb_fwoptions3 |= ICB2400_OPT3_RSPSZ_24;
2106 icbp->icb_fwoptions3 &= ~ICB2400_OPT3_RATE_AUTO;
2107 if (isp->isp_confopts & ISP_CFG_ONEGB) {
2108 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_ONEGB;
2109 } else if (isp->isp_confopts & ISP_CFG_TWOGB) {
2110 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_TWOGB;
2111 } else if (isp->isp_confopts & ISP_CFG_FOURGB) {
2112 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_FOURGB;
2113 } else if (IS_25XX(isp) && (isp->isp_confopts & ISP_CFG_EIGHTGB)) {
2114 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_EIGHTGB;
2116 icbp->icb_fwoptions3 |= ICB2400_OPT3_RATE_AUTO;
2118 icbp->icb_logintime = ICB_LOGIN_TOV;
2120 if (fcp->isp_wwnn && fcp->isp_wwpn) {
2121 icbp->icb_fwoptions1 |= ICB2400_OPT1_BOTH_WWNS;
2122 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
2123 MAKE_NODE_NAME_FROM_WWN(icbp->icb_nodename, fcp->isp_wwnn);
2124 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)),
2125 ((uint32_t) (fcp->isp_wwpn >> 32)), ((uint32_t) (fcp->isp_wwpn)));
2126 } else if (fcp->isp_wwpn) {
2127 icbp->icb_fwoptions1 &= ~ICB2400_OPT1_BOTH_WWNS;
2128 MAKE_NODE_NAME_FROM_WWN(icbp->icb_portname, fcp->isp_wwpn);
2129 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)));
2131 isp_prt(isp, ISP_LOGERR, "No valid WWNs to use");
2134 icbp->icb_retry_count = fcp->isp_retry_count;
2136 icbp->icb_rqstqlen = RQUEST_QUEUE_LEN(isp);
2137 if (icbp->icb_rqstqlen < 8) {
2138 isp_prt(isp, ISP_LOGERR, "bad request queue length %d", icbp->icb_rqstqlen);
2141 icbp->icb_rsltqlen = RESULT_QUEUE_LEN(isp);
2142 if (icbp->icb_rsltqlen < 8) {
2143 isp_prt(isp, ISP_LOGERR, "bad result queue length %d",
2144 icbp->icb_rsltqlen);
2147 icbp->icb_rqstaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_rquest_dma);
2148 icbp->icb_rqstaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_rquest_dma);
2149 icbp->icb_rqstaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_rquest_dma);
2150 icbp->icb_rqstaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_rquest_dma);
2152 icbp->icb_respaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_result_dma);
2153 icbp->icb_respaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_result_dma);
2154 icbp->icb_respaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_result_dma);
2155 icbp->icb_respaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_result_dma);
2157 #ifdef ISP_TARGET_MODE
2158 /* unconditionally set up the ATIO queue if we support target mode */
2159 icbp->icb_atioqlen = RESULT_QUEUE_LEN(isp);
2160 if (icbp->icb_atioqlen < 8) {
2161 isp_prt(isp, ISP_LOGERR, "bad ATIO queue length %d", icbp->icb_atioqlen);
2164 icbp->icb_atioqaddr[RQRSP_ADDR0015] = DMA_WD0(isp->isp_atioq_dma);
2165 icbp->icb_atioqaddr[RQRSP_ADDR1631] = DMA_WD1(isp->isp_atioq_dma);
2166 icbp->icb_atioqaddr[RQRSP_ADDR3247] = DMA_WD2(isp->isp_atioq_dma);
2167 icbp->icb_atioqaddr[RQRSP_ADDR4863] = DMA_WD3(isp->isp_atioq_dma);
2168 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),
2169 DMA_WD1(isp->isp_atioq_dma), DMA_WD0(isp->isp_atioq_dma));
2172 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);
2174 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),
2175 DMA_WD1(isp->isp_rquest_dma), DMA_WD0(isp->isp_rquest_dma), DMA_WD3(isp->isp_result_dma), DMA_WD2(isp->isp_result_dma),
2176 DMA_WD1(isp->isp_result_dma), DMA_WD0(isp->isp_result_dma));
2178 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2179 isp_print_bytes(isp, "isp_fibre_init_2400", sizeof (*icbp), icbp);
2182 if (FC_SCRATCH_ACQUIRE(isp, 0)) {
2183 isp_prt(isp, ISP_LOGERR, sacq);
2186 ISP_MEMZERO(fcp->isp_scratch, ISP_FC_SCRLEN);
2187 isp_put_icb_2400(isp, icbp, fcp->isp_scratch);
2190 * Now fill in information about any additional channels
2192 if (isp->isp_nchan > 1) {
2193 isp_icb_2400_vpinfo_t vpinfo, *vdst;
2194 vp_port_info_t pi, *pdst;
2198 vpinfo.vp_global_options = ICB2400_VPGOPT_GEN_RIDA;
2199 if (ISP_CAP_VP0(isp)) {
2200 vpinfo.vp_global_options |= ICB2400_VPGOPT_VP0_DECOUPLE;
2201 vpinfo.vp_count = isp->isp_nchan;
2204 vpinfo.vp_count = isp->isp_nchan - 1;
2207 off = fcp->isp_scratch;
2208 off += ICB2400_VPINFO_OFF;
2209 vdst = (isp_icb_2400_vpinfo_t *) off;
2210 isp_put_icb_2400_vpinfo(isp, &vpinfo, vdst);
2211 amt = ICB2400_VPINFO_OFF + sizeof (isp_icb_2400_vpinfo_t);
2212 for (; chan < isp->isp_nchan; chan++) {
2215 ISP_MEMZERO(&pi, sizeof (pi));
2216 fcp2 = FCPARAM(isp, chan);
2217 if (fcp2->role != ISP_ROLE_NONE) {
2218 pi.vp_port_options = ICB2400_VPOPT_ENABLED |
2219 ICB2400_VPOPT_ENA_SNSLOGIN;
2220 if (fcp2->role & ISP_ROLE_INITIATOR)
2221 pi.vp_port_options |= ICB2400_VPOPT_INI_ENABLE;
2222 if ((fcp2->role & ISP_ROLE_TARGET) == 0)
2223 pi.vp_port_options |= ICB2400_VPOPT_TGT_DISABLE;
2225 if (fcp2->isp_loopid < LOCAL_LOOP_LIM) {
2226 pi.vp_port_loopid = fcp2->isp_loopid;
2227 if (isp->isp_confopts & ISP_CFG_OWNLOOPID)
2228 pi.vp_port_options |= ICB2400_VPOPT_HARD_ADDRESS;
2230 pi.vp_port_options |= ICB2400_VPOPT_PREV_ADDRESS;
2232 MAKE_NODE_NAME_FROM_WWN(pi.vp_port_portname, fcp2->isp_wwpn);
2233 MAKE_NODE_NAME_FROM_WWN(pi.vp_port_nodename, fcp2->isp_wwnn);
2234 off = fcp->isp_scratch;
2235 if (ISP_CAP_VP0(isp))
2236 off += ICB2400_VPINFO_PORT_OFF(chan);
2238 off += ICB2400_VPINFO_PORT_OFF(chan - 1);
2239 pdst = (vp_port_info_t *) off;
2240 isp_put_vp_port_info(isp, &pi, pdst);
2241 amt += ICB2400_VPOPT_WRITE_SIZE;
2243 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2244 isp_print_bytes(isp, "isp_fibre_init_2400",
2245 amt - ICB2400_VPINFO_OFF,
2246 (char *)fcp->isp_scratch + ICB2400_VPINFO_OFF);
2253 MBSINIT(&mbs, 0, MBLOGALL, 30000000);
2254 if (isp->isp_nchan > 1) {
2255 mbs.param[0] = MBOX_INIT_FIRMWARE_MULTI_ID;
2257 mbs.param[0] = MBOX_INIT_FIRMWARE;
2260 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2261 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2262 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2263 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2264 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));
2265 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (*icbp), 0);
2266 isp_mboxcmd(isp, &mbs);
2267 FC_SCRATCH_RELEASE(isp, 0);
2269 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2272 isp->isp_reqidx = 0;
2273 isp->isp_reqodx = 0;
2274 isp->isp_residx = 0;
2275 isp->isp_resodx = 0;
2276 isp->isp_atioodx = 0;
2279 * Whatever happens, we're now committed to being here.
2281 isp->isp_state = ISP_RUNSTATE;
2285 isp_clear_portdb(ispsoftc_t *isp, int chan)
2287 fcparam *fcp = FCPARAM(isp, chan);
2291 for (i = 0; i < MAX_FC_TARG; i++) {
2292 lp = &fcp->portdb[i];
2293 switch (lp->state) {
2294 case FC_PORTDB_STATE_DEAD:
2295 case FC_PORTDB_STATE_CHANGED:
2296 case FC_PORTDB_STATE_VALID:
2297 lp->state = FC_PORTDB_STATE_NIL;
2298 isp_async(isp, ISPASYNC_DEV_GONE, chan, lp);
2300 case FC_PORTDB_STATE_NIL:
2301 case FC_PORTDB_STATE_NEW:
2302 lp->state = FC_PORTDB_STATE_NIL;
2304 case FC_PORTDB_STATE_ZOMBIE:
2307 panic("Don't know how to clear state %d\n", lp->state);
2313 isp_mark_portdb(ispsoftc_t *isp, int chan)
2315 fcparam *fcp = FCPARAM(isp, chan);
2319 for (i = 0; i < MAX_FC_TARG; i++) {
2320 lp = &fcp->portdb[i];
2321 if (lp->state == FC_PORTDB_STATE_NIL)
2323 if (lp->portid >= DOMAIN_CONTROLLER_BASE &&
2324 lp->portid <= DOMAIN_CONTROLLER_END)
2326 fcp->portdb[i].probational = 1;
2331 * Perform an IOCB PLOGI or LOGO via EXECUTE IOCB A64 for 24XX cards
2332 * or via FABRIC LOGIN/FABRIC LOGOUT for other cards.
2335 isp_plogx(ispsoftc_t *isp, int chan, uint16_t handle, uint32_t portid, int flags, int gs)
2338 uint8_t q[QENTRY_LEN];
2342 uint32_t sst, parm1;
2347 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d PLOGX %s PortID 0x%06x nphdl 0x%x",
2348 chan, (flags & PLOGX_FLG_CMD_MASK) == PLOGX_FLG_CMD_PLOGI ?
2349 "Login":"Logout", portid, handle);
2350 if (!IS_24XX(isp)) {
2351 int action = flags & PLOGX_FLG_CMD_MASK;
2352 if (action == PLOGX_FLG_CMD_PLOGI) {
2353 return (isp_port_login(isp, handle, portid));
2354 } else if (action == PLOGX_FLG_CMD_LOGO) {
2355 return (isp_port_logout(isp, handle, portid));
2357 return (MBOX_INVALID_COMMAND);
2361 ISP_MEMZERO(q, QENTRY_LEN);
2362 plp = (isp_plogx_t *) q;
2363 plp->plogx_header.rqs_entry_count = 1;
2364 plp->plogx_header.rqs_entry_type = RQSTYPE_LOGIN;
2365 plp->plogx_handle = 0xffffffff;
2366 plp->plogx_nphdl = handle;
2367 plp->plogx_vphdl = chan;
2368 plp->plogx_portlo = portid;
2369 plp->plogx_rspsz_porthi = (portid >> 16) & 0xff;
2370 plp->plogx_flags = flags;
2372 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2373 isp_print_bytes(isp, "IOCB LOGX", QENTRY_LEN, plp);
2377 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
2378 isp_prt(isp, ISP_LOGERR, sacq);
2382 fcp = FCPARAM(isp, chan);
2383 scp = fcp->isp_scratch;
2384 isp_put_plogx(isp, plp, (isp_plogx_t *) scp);
2386 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 500000);
2387 mbs.param[1] = QENTRY_LEN;
2388 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2389 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2390 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2391 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2392 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, QENTRY_LEN, chan);
2393 isp_mboxcmd(isp, &mbs);
2394 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2395 rval = mbs.param[0];
2398 MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN, QENTRY_LEN, chan);
2400 isp_get_plogx(isp, (isp_plogx_t *) scp, plp);
2401 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2402 isp_print_bytes(isp, "IOCB LOGX response", QENTRY_LEN, plp);
2405 if (plp->plogx_status == PLOGX_STATUS_OK) {
2408 } else if (plp->plogx_status != PLOGX_STATUS_IOCBERR) {
2409 isp_prt(isp, ISP_LOGWARN,
2410 "status 0x%x on port login IOCB channel %d",
2411 plp->plogx_status, chan);
2416 sst = plp->plogx_ioparm[0].lo16 | (plp->plogx_ioparm[0].hi16 << 16);
2417 parm1 = plp->plogx_ioparm[1].lo16 | (plp->plogx_ioparm[1].hi16 << 16);
2424 case PLOGX_IOCBERR_NOLINK:
2427 case PLOGX_IOCBERR_NOIOCB:
2428 msg = "no IOCB buffer";
2430 case PLOGX_IOCBERR_NOXGHG:
2431 msg = "no Exchange Control Block";
2433 case PLOGX_IOCBERR_FAILED:
2434 ISP_SNPRINTF(buf, sizeof (buf), "reason 0x%x (last LOGIN state 0x%x)", parm1 & 0xff, (parm1 >> 8) & 0xff);
2437 case PLOGX_IOCBERR_NOFABRIC:
2440 case PLOGX_IOCBERR_NOTREADY:
2441 msg = "firmware not ready";
2443 case PLOGX_IOCBERR_NOLOGIN:
2444 ISP_SNPRINTF(buf, sizeof (buf), "not logged in (last state 0x%x)", parm1);
2446 rval = MBOX_NOT_LOGGED_IN;
2448 case PLOGX_IOCBERR_REJECT:
2449 ISP_SNPRINTF(buf, sizeof (buf), "LS_RJT = 0x%x", parm1);
2452 case PLOGX_IOCBERR_NOPCB:
2453 msg = "no PCB allocated";
2455 case PLOGX_IOCBERR_EINVAL:
2456 ISP_SNPRINTF(buf, sizeof (buf), "invalid parameter at offset 0x%x", parm1);
2459 case PLOGX_IOCBERR_PORTUSED:
2460 lev = ISP_LOG_SANCFG|ISP_LOG_WARN1;
2461 ISP_SNPRINTF(buf, sizeof (buf), "already logged in with N-Port handle 0x%x", parm1);
2463 rval = MBOX_PORT_ID_USED | (parm1 << 16);
2465 case PLOGX_IOCBERR_HNDLUSED:
2466 lev = ISP_LOG_SANCFG|ISP_LOG_WARN1;
2467 ISP_SNPRINTF(buf, sizeof (buf), "handle already used for PortID 0x%06x", parm1);
2469 rval = MBOX_LOOP_ID_USED;
2471 case PLOGX_IOCBERR_NOHANDLE:
2472 msg = "no handle allocated";
2474 case PLOGX_IOCBERR_NOFLOGI:
2475 msg = "no FLOGI_ACC";
2478 ISP_SNPRINTF(buf, sizeof (buf), "status %x from %x", plp->plogx_status, flags);
2483 isp_prt(isp, ISP_LOGERR, "Chan %d PLOGX PortID 0x%06x to N-Port handle 0x%x: %s", chan, portid, handle, msg);
2487 FC_SCRATCH_RELEASE(isp, chan);
2493 isp_port_login(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2497 MBSINIT(&mbs, MBOX_FABRIC_LOGIN, MBLOGNONE, 500000);
2498 if (ISP_CAP_2KLOGIN(isp)) {
2499 mbs.param[1] = handle;
2500 mbs.ibits = (1 << 10);
2502 mbs.param[1] = handle << 8;
2504 mbs.param[2] = portid >> 16;
2505 mbs.param[3] = portid;
2506 mbs.logval = MBLOGNONE;
2507 mbs.timeout = 500000;
2508 isp_mboxcmd(isp, &mbs);
2510 switch (mbs.param[0]) {
2511 case MBOX_PORT_ID_USED:
2512 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]);
2513 return (MBOX_PORT_ID_USED | (mbs.param[1] << 16));
2515 case MBOX_LOOP_ID_USED:
2516 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);
2517 return (MBOX_LOOP_ID_USED);
2519 case MBOX_COMMAND_COMPLETE:
2522 case MBOX_COMMAND_ERROR:
2523 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);
2524 return (MBOX_COMMAND_ERROR);
2526 case MBOX_ALL_IDS_USED:
2527 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "isp_port_login: all IDs used for fabric login");
2528 return (MBOX_ALL_IDS_USED);
2531 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);
2532 return (mbs.param[0]);
2537 * Pre-24XX fabric port logout
2539 * Note that portid is not used
2542 isp_port_logout(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2546 MBSINIT(&mbs, MBOX_FABRIC_LOGOUT, MBLOGNONE, 500000);
2547 if (ISP_CAP_2KLOGIN(isp)) {
2548 mbs.param[1] = handle;
2549 mbs.ibits = (1 << 10);
2551 mbs.param[1] = handle << 8;
2553 isp_mboxcmd(isp, &mbs);
2554 return (mbs.param[0] == MBOX_COMMAND_COMPLETE? 0 : mbs.param[0]);
2558 isp_getpdb(ispsoftc_t *isp, int chan, uint16_t id, isp_pdb_t *pdb, int dolock)
2560 fcparam *fcp = FCPARAM(isp, chan);
2563 isp_pdb_21xx_t fred;
2564 isp_pdb_24xx_t bill;
2567 MBSINIT(&mbs, MBOX_GET_PORT_DB,
2568 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_PARAM_ERROR), 250000);
2570 mbs.ibits = (1 << 9)|(1 << 10);
2572 mbs.param[9] = chan;
2573 } else if (ISP_CAP_2KLOGIN(isp)) {
2576 mbs.param[1] = id << 8;
2578 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2579 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2580 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2581 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2583 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
2584 isp_prt(isp, ISP_LOGERR, sacq);
2588 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (un), chan);
2589 isp_mboxcmd(isp, &mbs);
2590 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2592 FC_SCRATCH_RELEASE(isp, chan);
2594 return (mbs.param[0] | (mbs.param[1] << 16));
2597 isp_get_pdb_24xx(isp, fcp->isp_scratch, &un.bill);
2598 pdb->handle = un.bill.pdb_handle;
2599 pdb->prli_word3 = un.bill.pdb_prli_svc3;
2600 pdb->portid = BITS2WORD_24XX(un.bill.pdb_portid_bits);
2601 ISP_MEMCPY(pdb->portname, un.bill.pdb_portname, 8);
2602 ISP_MEMCPY(pdb->nodename, un.bill.pdb_nodename, 8);
2603 isp_prt(isp, ISP_LOGDEBUG1,
2604 "Chan %d handle 0x%x Port 0x%06x flags 0x%x curstate %x",
2605 chan, id, pdb->portid, un.bill.pdb_flags,
2606 un.bill.pdb_curstate);
2607 if (un.bill.pdb_curstate < PDB2400_STATE_PLOGI_DONE || un.bill.pdb_curstate > PDB2400_STATE_LOGGED_IN) {
2608 mbs.param[0] = MBOX_NOT_LOGGED_IN;
2610 FC_SCRATCH_RELEASE(isp, chan);
2612 return (mbs.param[0]);
2615 isp_get_pdb_21xx(isp, fcp->isp_scratch, &un.fred);
2616 pdb->handle = un.fred.pdb_loopid;
2617 pdb->prli_word3 = un.fred.pdb_prli_svc3;
2618 pdb->portid = BITS2WORD(un.fred.pdb_portid_bits);
2619 ISP_MEMCPY(pdb->portname, un.fred.pdb_portname, 8);
2620 ISP_MEMCPY(pdb->nodename, un.fred.pdb_nodename, 8);
2621 isp_prt(isp, ISP_LOGDEBUG1,
2622 "Chan %d handle 0x%x Port 0x%06x", chan, id, pdb->portid);
2625 FC_SCRATCH_RELEASE(isp, chan);
2631 isp_gethandles(ispsoftc_t *isp, int chan, uint16_t *handles, int *num,
2632 int dolock, int loop)
2634 fcparam *fcp = FCPARAM(isp, chan);
2636 isp_pnhle_21xx_t el1, *elp1;
2637 isp_pnhle_23xx_t el3, *elp3;
2638 isp_pnhle_24xx_t el4, *elp4;
2643 MBSINIT(&mbs, MBOX_GET_ID_LIST, MBLOGALL, 250000);
2645 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2646 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2647 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2648 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2649 mbs.param[8] = ISP_FC_SCRLEN;
2650 mbs.param[9] = chan;
2652 mbs.ibits = (1 << 1)|(1 << 2)|(1 << 3)|(1 << 6);
2653 mbs.param[1] = DMA_WD1(fcp->isp_scdma);
2654 mbs.param[2] = DMA_WD0(fcp->isp_scdma);
2655 mbs.param[3] = DMA_WD3(fcp->isp_scdma);
2656 mbs.param[6] = DMA_WD2(fcp->isp_scdma);
2659 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
2660 isp_prt(isp, ISP_LOGERR, sacq);
2664 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, ISP_FC_SCRLEN, chan);
2665 isp_mboxcmd(isp, &mbs);
2666 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2668 FC_SCRATCH_RELEASE(isp, chan);
2670 return (mbs.param[0] | (mbs.param[1] << 16));
2672 elp1 = fcp->isp_scratch;
2673 elp3 = fcp->isp_scratch;
2674 elp4 = fcp->isp_scratch;
2675 for (i = 0, j = 0; i < mbs.param[1] && j < *num; i++) {
2677 isp_get_pnhle_24xx(isp, &elp4[i], &el4);
2678 p = el4.pnhle_port_id_lo |
2679 (el4.pnhle_port_id_hi << 16);
2680 h = el4.pnhle_handle;
2681 } else if (IS_23XX(isp)) {
2682 isp_get_pnhle_23xx(isp, &elp3[i], &el3);
2683 p = el3.pnhle_port_id_lo |
2684 (el3.pnhle_port_id_hi << 16);
2685 h = el3.pnhle_handle;
2687 isp_get_pnhle_21xx(isp, &elp1[i], &el1);
2688 p = el1.pnhle_port_id_lo |
2689 ((el1.pnhle_port_id_hi_handle & 0xff) << 16);
2690 h = el1.pnhle_port_id_hi_handle >> 8;
2692 if (loop && (p >> 8) != (fcp->isp_portid >> 8))
2698 FC_SCRATCH_RELEASE(isp, chan);
2703 isp_dump_chip_portdb(ispsoftc_t *isp, int chan, int dolock)
2706 uint16_t lim, nphdl;
2708 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGINFO, "Chan %d chip port dump", chan);
2709 if (ISP_CAP_2KLOGIN(isp)) {
2714 for (nphdl = 0; nphdl != lim; nphdl++) {
2715 if (isp_getpdb(isp, chan, nphdl, &pdb, dolock)) {
2718 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGINFO, "Chan %d Handle 0x%04x "
2719 "PortID 0x%06x WWPN 0x%02x%02x%02x%02x%02x%02x%02x%02x",
2720 chan, nphdl, pdb.portid, pdb.portname[0], pdb.portname[1],
2721 pdb.portname[2], pdb.portname[3], pdb.portname[4],
2722 pdb.portname[5], pdb.portname[6], pdb.portname[7]);
2727 isp_get_wwn(ispsoftc_t *isp, int chan, int nphdl, int nodename)
2729 uint64_t wwn = INI_NONE;
2732 MBSINIT(&mbs, MBOX_GET_PORT_NAME,
2733 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_PARAM_ERROR), 500000);
2734 if (ISP_CAP_2KLOGIN(isp)) {
2735 mbs.param[1] = nphdl;
2739 mbs.param[9] = chan;
2742 mbs.param[1] = nphdl << 8;
2747 isp_mboxcmd(isp, &mbs);
2748 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2753 (((uint64_t)(mbs.param[2] >> 8)) << 56) |
2754 (((uint64_t)(mbs.param[2] & 0xff)) << 48) |
2755 (((uint64_t)(mbs.param[3] >> 8)) << 40) |
2756 (((uint64_t)(mbs.param[3] & 0xff)) << 32) |
2757 (((uint64_t)(mbs.param[6] >> 8)) << 24) |
2758 (((uint64_t)(mbs.param[6] & 0xff)) << 16) |
2759 (((uint64_t)(mbs.param[7] >> 8)) << 8) |
2760 (((uint64_t)(mbs.param[7] & 0xff)));
2763 (((uint64_t)(mbs.param[2] & 0xff)) << 56) |
2764 (((uint64_t)(mbs.param[2] >> 8)) << 48) |
2765 (((uint64_t)(mbs.param[3] & 0xff)) << 40) |
2766 (((uint64_t)(mbs.param[3] >> 8)) << 32) |
2767 (((uint64_t)(mbs.param[6] & 0xff)) << 24) |
2768 (((uint64_t)(mbs.param[6] >> 8)) << 16) |
2769 (((uint64_t)(mbs.param[7] & 0xff)) << 8) |
2770 (((uint64_t)(mbs.param[7] >> 8)));
2776 * Make sure we have good FC link.
2780 isp_fclink_test(ispsoftc_t *isp, int chan, int usdelay)
2787 NANOTIME_T hra, hrb;
2789 fcp = FCPARAM(isp, chan);
2791 if (fcp->isp_loopstate >= LOOP_LTEST_DONE)
2794 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC link test", chan);
2795 fcp->isp_loopstate = LOOP_TESTING_LINK;
2798 * Wait up to N microseconds for F/W to go to a ready state.
2802 isp_change_fw_state(isp, chan, isp_fw_state(isp, chan));
2803 if (fcp->isp_fwstate == FW_READY) {
2807 if ((NANOTIME_SUB(&hrb, &hra) / 1000 + 1000 >= usdelay))
2809 ISP_SLEEP(isp, 1000);
2813 * If we haven't gone to 'ready' state, return.
2815 if (fcp->isp_fwstate != FW_READY) {
2816 isp_prt(isp, ISP_LOG_SANCFG,
2817 "Chan %d Firmware is not ready (%s)",
2818 chan, isp_fc_fw_statename(fcp->isp_fwstate));
2823 * Get our Loop ID and Port ID.
2825 MBSINIT(&mbs, MBOX_GET_LOOP_ID, MBLOGALL, 0);
2826 mbs.param[9] = chan;
2827 isp_mboxcmd(isp, &mbs);
2828 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2834 * Don't bother with fabric if we are using really old
2835 * 2100 firmware. It's just not worth it.
2837 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37))
2838 fcp->isp_topo = TOPO_FL_PORT;
2840 fcp->isp_topo = TOPO_NL_PORT;
2842 int topo = (int) mbs.param[6];
2843 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB) {
2844 topo = TOPO_PTP_STUB;
2846 fcp->isp_topo = topo;
2848 fcp->isp_portid = mbs.param[2] | (mbs.param[3] << 16);
2850 if (!TOPO_IS_FABRIC(fcp->isp_topo)) {
2851 fcp->isp_loopid = mbs.param[1] & 0xff;
2852 } else if (fcp->isp_topo != TOPO_F_PORT) {
2853 uint8_t alpa = fcp->isp_portid;
2855 for (i = 0; alpa_map[i]; i++) {
2856 if (alpa_map[i] == alpa)
2860 fcp->isp_loopid = i;
2863 if (fcp->isp_topo == TOPO_F_PORT || fcp->isp_topo == TOPO_FL_PORT) {
2864 nphdl = IS_24XX(isp) ? NPH_FL_ID : FL_ID;
2865 r = isp_getpdb(isp, chan, nphdl, &pdb, 1);
2866 if (r != 0 || pdb.portid == 0) {
2868 fcp->isp_topo = TOPO_NL_PORT;
2870 isp_prt(isp, ISP_LOGWARN,
2871 "fabric topology, but cannot get info about fabric controller (0x%x)", r);
2872 fcp->isp_topo = TOPO_PTP_STUB;
2878 fcp->isp_fabric_params = mbs.param[7];
2879 fcp->isp_sns_hdl = NPH_SNS_ID;
2880 r = isp_register_fc4_type_24xx(isp, chan);
2882 isp_register_fc4_features_24xx(isp, chan);
2884 fcp->isp_sns_hdl = SNS_ID;
2885 r = isp_register_fc4_type(isp, chan);
2888 isp_prt(isp, ISP_LOGWARN|ISP_LOG_SANCFG, "%s: register fc4 type failed", __func__);
2894 /* Get link speed. */
2895 fcp->isp_gbspeed = 1;
2896 if (IS_23XX(isp) || IS_24XX(isp)) {
2897 MBSINIT(&mbs, MBOX_GET_SET_DATA_RATE, MBLOGALL, 3000000);
2898 mbs.param[1] = MBGSD_GET_RATE;
2899 /* mbs.param[2] undefined if we're just getting rate */
2900 isp_mboxcmd(isp, &mbs);
2901 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
2902 if (mbs.param[1] == MBGSD_10GB)
2903 fcp->isp_gbspeed = 10;
2904 else if (mbs.param[1] == MBGSD_16GB)
2905 fcp->isp_gbspeed = 16;
2906 else if (mbs.param[1] == MBGSD_8GB)
2907 fcp->isp_gbspeed = 8;
2908 else if (mbs.param[1] == MBGSD_4GB)
2909 fcp->isp_gbspeed = 4;
2910 else if (mbs.param[1] == MBGSD_2GB)
2911 fcp->isp_gbspeed = 2;
2912 else if (mbs.param[1] == MBGSD_1GB)
2913 fcp->isp_gbspeed = 1;
2917 fcp->isp_loopstate = LOOP_LTEST_DONE;
2918 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGCONFIG,
2919 "Chan %d WWPN %016jx WWNN %016jx",
2920 chan, (uintmax_t)fcp->isp_wwpn, (uintmax_t)fcp->isp_wwnn);
2921 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGCONFIG,
2922 "Chan %d %dGb %s PortID 0x%06x LoopID 0x%02x",
2923 chan, fcp->isp_gbspeed, isp_fc_toponame(fcp), fcp->isp_portid,
2925 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC link test done", chan);
2930 * Complete the synchronization of our Port Database.
2932 * At this point, we've scanned the local loop (if any) and the fabric
2933 * and performed fabric logins on all new devices.
2935 * Our task here is to go through our port database removing any entities
2936 * that are still marked probational (issuing PLOGO for ones which we had
2937 * PLOGI'd into) or are dead, and notifying upper layers about new/changed
2941 isp_pdb_sync(ispsoftc_t *isp, int chan)
2943 fcparam *fcp = FCPARAM(isp, chan);
2947 if (fcp->isp_loopstate < LOOP_FSCAN_DONE) {
2950 if (fcp->isp_loopstate > LOOP_SYNCING_PDB) {
2954 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC PDB sync", chan);
2956 fcp->isp_loopstate = LOOP_SYNCING_PDB;
2958 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
2959 lp = &fcp->portdb[dbidx];
2961 if (lp->state == FC_PORTDB_STATE_NIL)
2963 if (lp->probational && lp->state != FC_PORTDB_STATE_ZOMBIE)
2964 lp->state = FC_PORTDB_STATE_DEAD;
2965 switch (lp->state) {
2966 case FC_PORTDB_STATE_DEAD:
2967 lp->state = FC_PORTDB_STATE_NIL;
2968 isp_async(isp, ISPASYNC_DEV_GONE, chan, lp);
2969 if (lp->autologin == 0) {
2970 (void) isp_plogx(isp, chan, lp->handle,
2972 PLOGX_FLG_CMD_LOGO |
2973 PLOGX_FLG_IMPLICIT |
2974 PLOGX_FLG_FREE_NPHDL, 0);
2977 * Note that we might come out of this with our state
2978 * set to FC_PORTDB_STATE_ZOMBIE.
2981 case FC_PORTDB_STATE_NEW:
2982 lp->state = FC_PORTDB_STATE_VALID;
2983 isp_async(isp, ISPASYNC_DEV_ARRIVED, chan, lp);
2985 case FC_PORTDB_STATE_CHANGED:
2986 lp->state = FC_PORTDB_STATE_VALID;
2987 isp_async(isp, ISPASYNC_DEV_CHANGED, chan, lp);
2988 lp->portid = lp->new_portid;
2989 lp->prli_word3 = lp->new_prli_word3;
2991 case FC_PORTDB_STATE_VALID:
2992 isp_async(isp, ISPASYNC_DEV_STAYED, chan, lp);
2994 case FC_PORTDB_STATE_ZOMBIE:
2997 isp_prt(isp, ISP_LOGWARN,
2998 "isp_pdb_sync: state %d for idx %d",
3000 isp_dump_portdb(isp, chan);
3005 * If we get here, we've for sure seen not only a valid loop
3006 * but know what is or isn't on it, so mark this for usage
3009 fcp->loop_seen_once = 1;
3010 fcp->isp_loopstate = LOOP_READY;
3011 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC PDB sync done", chan);
3016 isp_pdb_add_update(ispsoftc_t *isp, int chan, isp_pdb_t *pdb)
3019 uint64_t wwnn, wwpn;
3021 MAKE_WWN_FROM_NODE_NAME(wwnn, pdb->nodename);
3022 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb->portname);
3024 /* Search port database for the same WWPN. */
3025 if (isp_find_pdb_by_wwpn(isp, chan, wwpn, &lp)) {
3026 if (!lp->probational) {
3027 isp_prt(isp, ISP_LOGERR,
3028 "Chan %d Port 0x%06x@0x%04x [%d] is not probational (0x%x)",
3029 chan, lp->portid, lp->handle,
3030 FC_PORTDB_TGT(isp, chan, lp), lp->state);
3031 isp_dump_portdb(isp, chan);
3034 lp->probational = 0;
3035 lp->node_wwn = wwnn;
3037 /* Old device, nothing new. */
3038 if (lp->portid == pdb->portid &&
3039 lp->handle == pdb->handle &&
3040 lp->prli_word3 == pdb->prli_word3) {
3041 if (lp->state != FC_PORTDB_STATE_NEW)
3042 lp->state = FC_PORTDB_STATE_VALID;
3043 isp_prt(isp, ISP_LOG_SANCFG,
3044 "Chan %d Port 0x%06x@0x%04x is valid",
3045 chan, pdb->portid, pdb->handle);
3049 /* Something has changed. */
3050 lp->state = FC_PORTDB_STATE_CHANGED;
3051 lp->handle = pdb->handle;
3052 lp->new_portid = pdb->portid;
3053 lp->new_prli_word3 = pdb->prli_word3;
3054 isp_prt(isp, ISP_LOG_SANCFG,
3055 "Chan %d Port 0x%06x@0x%04x is changed",
3056 chan, pdb->portid, pdb->handle);
3060 /* It seems like a new port. Find an empty slot for it. */
3061 if (!isp_find_pdb_empty(isp, chan, &lp)) {
3062 isp_prt(isp, ISP_LOGERR, "Chan %d out of portdb entries", chan);
3066 ISP_MEMZERO(lp, sizeof (fcportdb_t));
3068 lp->probational = 0;
3069 lp->state = FC_PORTDB_STATE_NEW;
3070 lp->portid = lp->new_portid = pdb->portid;
3071 lp->prli_word3 = lp->new_prli_word3 = pdb->prli_word3;
3072 lp->handle = pdb->handle;
3073 lp->port_wwn = wwpn;
3074 lp->node_wwn = wwnn;
3075 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Port 0x%06x@0x%04x is new",
3076 chan, pdb->portid, pdb->handle);
3080 * Fix port IDs for logged-in initiators on pre-2400 chips.
3081 * For those chips we are not receiving login events, adding initiators
3082 * based on ATIO requests, but there is no port ID in that structure.
3085 isp_fix_portids(ispsoftc_t *isp, int chan)
3087 fcparam *fcp = FCPARAM(isp, chan);
3092 for (i = 0; i < MAX_FC_TARG; i++) {
3093 fcportdb_t *lp = &fcp->portdb[i];
3095 if (lp->state == FC_PORTDB_STATE_NIL ||
3096 lp->state == FC_PORTDB_STATE_ZOMBIE)
3098 if (VALID_PORT(lp->portid))
3101 r = isp_getpdb(isp, chan, lp->handle, &pdb, 1);
3102 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3105 isp_prt(isp, ISP_LOGDEBUG1,
3106 "Chan %d FC Scan Loop handle %d returned %x",
3107 chan, lp->handle, r);
3111 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb.portname);
3112 if (lp->port_wwn != wwpn)
3114 lp->portid = lp->new_portid = pdb.portid;
3115 isp_prt(isp, ISP_LOG_SANCFG,
3116 "Chan %d Port 0x%06x@0x%04x is fixed",
3117 chan, pdb.portid, pdb.handle);
3122 * Scan local loop for devices.
3125 isp_scan_loop(ispsoftc_t *isp, int chan)
3127 fcparam *fcp = FCPARAM(isp, chan);
3130 uint16_t handles[LOCAL_LOOP_LIM];
3133 if (fcp->isp_loopstate < LOOP_LTEST_DONE) {
3136 if (fcp->isp_loopstate > LOOP_SCANNING_LOOP) {
3139 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC loop scan", chan);
3140 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
3141 if (TOPO_IS_FABRIC(fcp->isp_topo)) {
3142 if (!IS_24XX(isp)) {
3143 isp_fix_portids(isp, chan);
3144 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3147 isp_prt(isp, ISP_LOG_SANCFG,
3148 "Chan %d FC loop scan done (no loop)", chan);
3149 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3153 lim = LOCAL_LOOP_LIM;
3154 r = isp_gethandles(isp, chan, handles, &lim, 1, 1);
3156 isp_prt(isp, ISP_LOG_SANCFG,
3157 "Chan %d Getting list of handles failed with %x", chan, r);
3158 isp_prt(isp, ISP_LOG_SANCFG,
3159 "Chan %d FC loop scan done (bad)", chan);
3163 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Got %d handles",
3167 * Run through the list and get the port database info for each one.
3169 isp_mark_portdb(isp, chan);
3170 for (idx = 0; idx < lim; idx++) {
3171 handle = handles[idx];
3174 * Don't scan "special" ids.
3176 if (ISP_CAP_2KLOGIN(isp)) {
3177 if (handle >= NPH_RESERVED)
3180 if (handle >= FL_ID && handle <= SNS_ID)
3185 * In older cards with older f/w GET_PORT_DATABASE has been
3186 * known to hang. This trick gets around that problem.
3188 if (IS_2100(isp) || IS_2200(isp)) {
3189 uint64_t node_wwn = isp_get_wwn(isp, chan, handle, 1);
3190 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
3192 isp_prt(isp, ISP_LOG_SANCFG,
3193 "Chan %d FC loop scan done (abort)", chan);
3196 if (node_wwn == INI_NONE) {
3202 * Get the port database entity for this index.
3204 r = isp_getpdb(isp, chan, handle, &pdb, 1);
3205 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3208 isp_prt(isp, ISP_LOGDEBUG1,
3209 "Chan %d FC Scan Loop handle %d returned %x",
3214 isp_pdb_add_update(isp, chan, &pdb);
3216 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3218 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3219 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC loop scan done", chan);
3224 * Scan the fabric for devices and add them to our port database.
3226 * Use the GID_FT command to get all Port IDs for FC4 SCSI devices it knows.
3228 * For 2100-23XX cards, we can use the SNS mailbox command to pass simple
3229 * name server commands to the switch management server via the QLogic f/w.
3231 * For the 24XX card, we have to use CT-Pass through run via the Execute IOCB
3234 * The net result is to leave the list of Port IDs setting untranslated in
3235 * offset IGPOFF of the FC scratch area, whereupon we'll canonicalize it to
3236 * host order at OGPOFF.
3240 * Take half of our scratch area to store Port IDs
3242 #define GIDLEN (ISP_FC_SCRLEN >> 1)
3243 #define NGENT ((GIDLEN - 16) >> 2)
3246 #define OGPOFF (ISP_FC_SCRLEN >> 1)
3247 #define XTXOFF (ISP_FC_SCRLEN - (3 * QENTRY_LEN)) /* CT request */
3248 #define CTXOFF (ISP_FC_SCRLEN - (2 * QENTRY_LEN)) /* Request IOCB */
3249 #define ZTXOFF (ISP_FC_SCRLEN - (1 * QENTRY_LEN)) /* Response IOCB */
3252 isp_gid_ft_sns(ispsoftc_t *isp, int chan)
3255 sns_gid_ft_req_t _x;
3256 uint8_t _y[SNS_GID_FT_REQ_SIZE];
3258 fcparam *fcp = FCPARAM(isp, chan);
3259 sns_gid_ft_req_t *rq = &un._x;
3260 uint8_t *scp = fcp->isp_scratch;
3263 isp_prt(isp, ISP_LOGDEBUG0, "Chan %d scanning fabric (GID_FT) via SNS", chan);
3265 ISP_MEMZERO(rq, SNS_GID_FT_REQ_SIZE);
3266 rq->snscb_rblen = GIDLEN >> 1;
3267 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + IGPOFF);
3268 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + IGPOFF);
3269 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + IGPOFF);
3270 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + IGPOFF);
3271 rq->snscb_sblen = 6;
3272 rq->snscb_cmd = SNS_GID_FT;
3273 rq->snscb_mword_div_2 = NGENT;
3274 rq->snscb_fc4_type = FC4_SCSI;
3276 isp_put_gid_ft_request(isp, rq, (sns_gid_ft_req_t *)&scp[CTXOFF]);
3277 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE, chan);
3279 MBSINIT(&mbs, MBOX_SEND_SNS, MBLOGALL, 10000000);
3280 mbs.param[0] = MBOX_SEND_SNS;
3281 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
3282 mbs.param[2] = DMA_WD1(fcp->isp_scdma + CTXOFF);
3283 mbs.param[3] = DMA_WD0(fcp->isp_scdma + CTXOFF);
3284 mbs.param[6] = DMA_WD3(fcp->isp_scdma + CTXOFF);
3285 mbs.param[7] = DMA_WD2(fcp->isp_scdma + CTXOFF);
3286 isp_mboxcmd(isp, &mbs);
3287 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3288 if (mbs.param[0] == MBOX_INVALID_COMMAND) {
3298 isp_gid_ft_ct_passthru(ispsoftc_t *isp, int chan)
3301 fcparam *fcp = FCPARAM(isp, chan);
3305 uint8_t q[QENTRY_LEN];
3310 uint8_t *scp = fcp->isp_scratch;
3312 isp_prt(isp, ISP_LOGDEBUG0, "Chan %d scanning fabric (GID_FT) via CT", chan);
3315 * Build a Passthrough IOCB in memory.
3318 ISP_MEMZERO(un.q, QENTRY_LEN);
3319 pt->ctp_header.rqs_entry_count = 1;
3320 pt->ctp_header.rqs_entry_type = RQSTYPE_CT_PASSTHRU;
3321 pt->ctp_handle = 0xffffffff;
3322 pt->ctp_nphdl = fcp->isp_sns_hdl;
3323 pt->ctp_cmd_cnt = 1;
3324 pt->ctp_vpidx = ISP_GET_VPIDX(isp, chan);
3326 pt->ctp_rsp_cnt = 1;
3327 pt->ctp_rsp_bcnt = GIDLEN;
3328 pt->ctp_cmd_bcnt = sizeof (*ct) + sizeof (uint32_t);
3329 pt->ctp_dataseg[0].ds_base = DMA_LO32(fcp->isp_scdma+XTXOFF);
3330 pt->ctp_dataseg[0].ds_basehi = DMA_HI32(fcp->isp_scdma+XTXOFF);
3331 pt->ctp_dataseg[0].ds_count = sizeof (*ct) + sizeof (uint32_t);
3332 pt->ctp_dataseg[1].ds_base = DMA_LO32(fcp->isp_scdma+IGPOFF);
3333 pt->ctp_dataseg[1].ds_basehi = DMA_HI32(fcp->isp_scdma+IGPOFF);
3334 pt->ctp_dataseg[1].ds_count = GIDLEN;
3335 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3336 isp_print_bytes(isp, "ct IOCB", QENTRY_LEN, pt);
3338 isp_put_ct_pt(isp, pt, (isp_ct_pt_t *) &scp[CTXOFF]);
3341 * Build the CT header and command in memory.
3343 * Note that the CT header has to end up as Big Endian format in memory.
3346 ISP_MEMZERO(ct, sizeof (*ct));
3347 ct->ct_revision = CT_REVISION;
3348 ct->ct_fcs_type = CT_FC_TYPE_FC;
3349 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3350 ct->ct_cmd_resp = SNS_GID_FT;
3351 ct->ct_bcnt_resid = (GIDLEN - 16) >> 2;
3353 isp_put_ct_hdr(isp, ct, (ct_hdr_t *) &scp[XTXOFF]);
3354 rp = (uint32_t *) &scp[XTXOFF+sizeof (*ct)];
3355 ISP_IOZPUT_32(isp, FC4_SCSI, rp);
3356 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3357 isp_print_bytes(isp, "CT HDR + payload after put",
3358 sizeof (*ct) + sizeof (uint32_t), &scp[XTXOFF]);
3360 ISP_MEMZERO(&scp[ZTXOFF], QENTRY_LEN);
3361 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 500000);
3362 mbs.param[1] = QENTRY_LEN;
3363 mbs.param[2] = DMA_WD1(fcp->isp_scdma + CTXOFF);
3364 mbs.param[3] = DMA_WD0(fcp->isp_scdma + CTXOFF);
3365 mbs.param[6] = DMA_WD3(fcp->isp_scdma + CTXOFF);
3366 mbs.param[7] = DMA_WD2(fcp->isp_scdma + CTXOFF);
3367 MEMORYBARRIER(isp, SYNC_SFORDEV, XTXOFF, 2 * QENTRY_LEN, chan);
3368 isp_mboxcmd(isp, &mbs);
3369 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3372 MEMORYBARRIER(isp, SYNC_SFORCPU, ZTXOFF, QENTRY_LEN, chan);
3374 isp_get_ct_pt(isp, (isp_ct_pt_t *) &scp[ZTXOFF], pt);
3375 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3376 isp_print_bytes(isp, "IOCB response", QENTRY_LEN, pt);
3379 if (pt->ctp_status && pt->ctp_status != RQCS_DATA_UNDERRUN) {
3380 isp_prt(isp, ISP_LOGWARN,
3381 "Chan %d ISP GID FT CT Passthrough returned 0x%x",
3382 chan, pt->ctp_status);
3385 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN, chan);
3386 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3387 isp_print_bytes(isp, "CT response", GIDLEN, &scp[IGPOFF]);
3393 isp_scan_fabric(ispsoftc_t *isp, int chan)
3395 fcparam *fcp = FCPARAM(isp, chan);
3400 int portidx, portlim, r;
3401 sns_gid_ft_rsp_t *rs0, *rs1;
3403 if (fcp->isp_loopstate < LOOP_LSCAN_DONE) {
3406 if (fcp->isp_loopstate > LOOP_SCANNING_FABRIC) {
3409 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC fabric scan", chan);
3410 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
3411 if (!TOPO_IS_FABRIC(fcp->isp_topo)) {
3412 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3413 isp_prt(isp, ISP_LOG_SANCFG,
3414 "Chan %d FC fabric scan done (no fabric)", chan);
3418 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3419 isp_prt(isp, ISP_LOGERR, sacq);
3421 isp_prt(isp, ISP_LOG_SANCFG,
3422 "Chan %d FC fabric scan done (bad)", chan);
3425 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC) {
3427 FC_SCRATCH_RELEASE(isp, chan);
3428 isp_prt(isp, ISP_LOG_SANCFG,
3429 "Chan %d FC fabric scan done (abort)", chan);
3434 * Make sure we still are logged into the fabric controller.
3436 nphdl = IS_24XX(isp) ? NPH_FL_ID : FL_ID;
3437 r = isp_getpdb(isp, chan, nphdl, &pdb, 0);
3438 if ((r & 0xffff) == MBOX_NOT_LOGGED_IN) {
3439 isp_dump_chip_portdb(isp, chan, 0);
3442 fcp->isp_loopstate = LOOP_LTEST_DONE;
3443 FC_SCRATCH_RELEASE(isp, chan);
3447 /* Get list of port IDs from SNS. */
3449 r = isp_gid_ft_ct_passthru(isp, chan);
3451 r = isp_gid_ft_sns(isp, chan);
3452 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3455 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3456 FC_SCRATCH_RELEASE(isp, chan);
3459 fcp->isp_loopstate = LOOP_LTEST_DONE; /* try again */
3460 FC_SCRATCH_RELEASE(isp, chan);
3464 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN, chan);
3465 rs0 = (sns_gid_ft_rsp_t *) ((uint8_t *)fcp->isp_scratch+IGPOFF);
3466 rs1 = (sns_gid_ft_rsp_t *) ((uint8_t *)fcp->isp_scratch+OGPOFF);
3467 isp_get_gid_ft_response(isp, rs0, rs1, NGENT);
3468 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3470 if (rs1->snscb_cthdr.ct_cmd_resp != LS_ACC) {
3472 if (rs1->snscb_cthdr.ct_reason == 9 && rs1->snscb_cthdr.ct_explanation == 7) {
3473 level = ISP_LOG_SANCFG;
3475 level = ISP_LOGWARN;
3477 isp_prt(isp, level, "Chan %d Fabric Nameserver rejected GID_FT"
3478 " (Reason=0x%x Expl=0x%x)", chan,
3479 rs1->snscb_cthdr.ct_reason,
3480 rs1->snscb_cthdr.ct_explanation);
3481 FC_SCRATCH_RELEASE(isp, chan);
3482 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3486 /* Check our buffer was big enough to get the full list. */
3487 for (portidx = 0; portidx < NGENT-1; portidx++) {
3488 if (rs1->snscb_ports[portidx].control & 0x80)
3491 if ((rs1->snscb_ports[portidx].control & 0x80) == 0) {
3492 isp_prt(isp, ISP_LOGWARN,
3493 "fabric too big for scratch area: increase ISP_FC_SCRLEN");
3495 portlim = portidx + 1;
3496 isp_prt(isp, ISP_LOG_SANCFG,
3497 "Chan %d Got %d ports back from name server", chan, portlim);
3499 /* Go through the list and remove duplicate port ids. */
3500 for (portidx = 0; portidx < portlim; portidx++) {
3504 ((rs1->snscb_ports[portidx].portid[0]) << 16) |
3505 ((rs1->snscb_ports[portidx].portid[1]) << 8) |
3506 ((rs1->snscb_ports[portidx].portid[2]));
3508 for (npidx = portidx + 1; npidx < portlim; npidx++) {
3509 uint32_t new_portid =
3510 ((rs1->snscb_ports[npidx].portid[0]) << 16) |
3511 ((rs1->snscb_ports[npidx].portid[1]) << 8) |
3512 ((rs1->snscb_ports[npidx].portid[2]));
3513 if (new_portid == portid) {
3518 if (npidx < portlim) {
3519 rs1->snscb_ports[npidx].portid[0] = 0;
3520 rs1->snscb_ports[npidx].portid[1] = 0;
3521 rs1->snscb_ports[npidx].portid[2] = 0;
3522 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d removing duplicate PortID 0x%06x entry from list", chan, portid);
3527 * We now have a list of Port IDs for all FC4 SCSI devices
3528 * that the Fabric Name server knows about.
3530 * For each entry on this list go through our port database looking
3531 * for probational entries- if we find one, then an old entry is
3532 * maybe still this one. We get some information to find out.
3534 * Otherwise, it's a new fabric device, and we log into it
3535 * (unconditionally). After searching the entire database
3536 * again to make sure that we never ever ever ever have more
3537 * than one entry that has the same PortID or the same
3538 * WWNN/WWPN duple, we enter the device into our database.
3540 isp_mark_portdb(isp, chan);
3541 for (portidx = 0; portidx < portlim; portidx++) {
3542 portid = ((rs1->snscb_ports[portidx].portid[0]) << 16) |
3543 ((rs1->snscb_ports[portidx].portid[1]) << 8) |
3544 ((rs1->snscb_ports[portidx].portid[2]));
3545 isp_prt(isp, ISP_LOG_SANCFG,
3546 "Chan %d Checking fabric port 0x%06x", chan, portid);
3548 isp_prt(isp, ISP_LOG_SANCFG,
3549 "Chan %d Port at idx %d is zero",
3553 if (portid == fcp->isp_portid) {
3554 isp_prt(isp, ISP_LOG_SANCFG,
3555 "Chan %d Port 0x%06x is our", chan, portid);
3559 /* Now search the entire port database for the same portid. */
3560 if (isp_find_pdb_by_portid(isp, chan, portid, &lp)) {
3561 if (!lp->probational) {
3562 isp_prt(isp, ISP_LOGERR,
3563 "Chan %d Port 0x%06x@0x%04x [%d] is not probational (0x%x)",
3564 chan, lp->portid, lp->handle,
3565 FC_PORTDB_TGT(isp, chan, lp), lp->state);
3566 FC_SCRATCH_RELEASE(isp, chan);
3567 isp_dump_portdb(isp, chan);
3572 * See if we're still logged into it.
3574 * If we aren't, mark it as a dead device and
3575 * leave the new portid in the database entry
3576 * for somebody further along to decide what to
3577 * do (policy choice).
3579 * If we are, check to see if it's the same
3580 * device still (it should be). If for some
3581 * reason it isn't, mark it as a changed device
3582 * and leave the new portid and role in the
3583 * database entry for somebody further along to
3584 * decide what to do (policy choice).
3586 r = isp_getpdb(isp, chan, lp->handle, &pdb, 0);
3587 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3590 lp->state = FC_PORTDB_STATE_DEAD;
3591 isp_prt(isp, ISP_LOG_SANCFG,
3592 "Chan %d Port 0x%06x handle 0x%x is dead (%d)",
3593 chan, portid, lp->handle, r);
3597 isp_pdb_add_update(isp, chan, &pdb);
3602 if ((fcp->role & ISP_ROLE_INITIATOR) == 0) {
3603 isp_prt(isp, ISP_LOG_SANCFG,
3604 "Chan %d Port 0x%06x is not logged in", chan, portid);
3608 if (isp_login_device(isp, chan, portid, &pdb,
3609 &FCPARAM(isp, 0)->isp_lasthdl)) {
3610 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3615 isp_pdb_add_update(isp, chan, &pdb);
3618 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3620 FC_SCRATCH_RELEASE(isp, chan);
3621 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3622 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC fabric scan done", chan);
3627 * Find an unused handle and try and use to login to a port.
3630 isp_login_device(ispsoftc_t *isp, int chan, uint32_t portid, isp_pdb_t *p, uint16_t *ohp)
3635 if (ISP_CAP_2KLOGIN(isp)) {
3641 handle = isp_next_handle(isp, ohp);
3642 for (i = 0; i < lim; i++) {
3643 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
3646 /* Check if this handle is free. */
3647 r = isp_getpdb(isp, chan, handle, p, 0);
3649 if (p->portid != portid) {
3650 /* This handle is busy, try next one. */
3651 handle = isp_next_handle(isp, ohp);
3656 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
3660 * Now try and log into the device
3662 r = isp_plogx(isp, chan, handle, portid, PLOGX_FLG_CMD_PLOGI, 1);
3665 } else if ((r & 0xffff) == MBOX_PORT_ID_USED) {
3667 * If we get here, then the firmwware still thinks we're logged into this device, but with a different
3668 * handle. We need to break that association. We used to try and just substitute the handle, but then
3669 * failed to get any data via isp_getpdb (below).
3671 if (isp_plogx(isp, chan, r >> 16, portid, PLOGX_FLG_CMD_LOGO | PLOGX_FLG_IMPLICIT | PLOGX_FLG_FREE_NPHDL, 1)) {
3672 isp_prt(isp, ISP_LOGERR, "baw... logout of %x failed", r >> 16);
3674 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
3676 r = isp_plogx(isp, chan, handle, portid, PLOGX_FLG_CMD_PLOGI, 1);
3680 } else if ((r & 0xffff) == MBOX_LOOP_ID_USED) {
3681 /* Try the next handle. */
3682 handle = isp_next_handle(isp, ohp);
3691 isp_prt(isp, ISP_LOGWARN, "Chan %d PLOGI 0x%06x failed", chan, portid);
3696 * If we successfully logged into it, get the PDB for it
3697 * so we can crosscheck that it is still what we think it
3698 * is and that we also have the role it plays
3700 r = isp_getpdb(isp, chan, handle, p, 0);
3702 isp_prt(isp, ISP_LOGERR, "Chan %d new device 0x%06x@0x%x disappeared", chan, portid, handle);
3706 if (p->handle != handle || p->portid != portid) {
3707 isp_prt(isp, ISP_LOGERR, "Chan %d new device 0x%06x@0x%x changed (0x%06x@0x%0x)",
3708 chan, portid, handle, p->portid, p->handle);
3715 isp_register_fc4_type(ispsoftc_t *isp, int chan)
3717 fcparam *fcp = FCPARAM(isp, chan);
3718 uint8_t local[SNS_RFT_ID_REQ_SIZE];
3719 sns_screq_t *reqp = (sns_screq_t *) local;
3722 ISP_MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
3723 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
3724 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
3725 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
3726 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
3727 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
3728 reqp->snscb_sblen = 22;
3729 reqp->snscb_data[0] = SNS_RFT_ID;
3730 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
3731 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
3732 reqp->snscb_data[6] = (1 << FC4_SCSI);
3733 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3734 isp_prt(isp, ISP_LOGERR, sacq);
3737 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
3738 MBSINIT(&mbs, MBOX_SEND_SNS, MBLOGALL, 1000000);
3739 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
3740 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
3741 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
3742 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
3743 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
3744 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_RFT_ID_REQ_SIZE, chan);
3745 isp_mboxcmd(isp, &mbs);
3746 FC_SCRATCH_RELEASE(isp, chan);
3747 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3755 isp_register_fc4_type_24xx(ispsoftc_t *isp, int chan)
3758 fcparam *fcp = FCPARAM(isp, chan);
3762 uint8_t q[QENTRY_LEN];
3767 uint8_t *scp = fcp->isp_scratch;
3769 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3770 isp_prt(isp, ISP_LOGERR, sacq);
3775 * Build a Passthrough IOCB in memory.
3777 ISP_MEMZERO(un.q, QENTRY_LEN);
3779 pt->ctp_header.rqs_entry_count = 1;
3780 pt->ctp_header.rqs_entry_type = RQSTYPE_CT_PASSTHRU;
3781 pt->ctp_handle = 0xffffffff;
3782 pt->ctp_nphdl = fcp->isp_sns_hdl;
3783 pt->ctp_cmd_cnt = 1;
3784 pt->ctp_vpidx = ISP_GET_VPIDX(isp, chan);
3786 pt->ctp_rsp_cnt = 1;
3787 pt->ctp_rsp_bcnt = sizeof (ct_hdr_t);
3788 pt->ctp_cmd_bcnt = sizeof (rft_id_t);
3789 pt->ctp_dataseg[0].ds_base = DMA_LO32(fcp->isp_scdma+XTXOFF);
3790 pt->ctp_dataseg[0].ds_basehi = DMA_HI32(fcp->isp_scdma+XTXOFF);
3791 pt->ctp_dataseg[0].ds_count = sizeof (rft_id_t);
3792 pt->ctp_dataseg[1].ds_base = DMA_LO32(fcp->isp_scdma+IGPOFF);
3793 pt->ctp_dataseg[1].ds_basehi = DMA_HI32(fcp->isp_scdma+IGPOFF);
3794 pt->ctp_dataseg[1].ds_count = sizeof (ct_hdr_t);
3795 isp_put_ct_pt(isp, pt, (isp_ct_pt_t *) &scp[CTXOFF]);
3796 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3797 isp_print_bytes(isp, "IOCB CT Request", QENTRY_LEN, pt);
3801 * Build the CT header and command in memory.
3803 * Note that the CT header has to end up as Big Endian format in memory.
3805 ISP_MEMZERO(&un.clocal, sizeof (un.clocal));
3806 ct = &un.clocal.rftid_hdr;
3807 ct->ct_revision = CT_REVISION;
3808 ct->ct_fcs_type = CT_FC_TYPE_FC;
3809 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3810 ct->ct_cmd_resp = SNS_RFT_ID;
3811 ct->ct_bcnt_resid = (sizeof (rft_id_t) - sizeof (ct_hdr_t)) >> 2;
3813 rp->rftid_portid[0] = fcp->isp_portid >> 16;
3814 rp->rftid_portid[1] = fcp->isp_portid >> 8;
3815 rp->rftid_portid[2] = fcp->isp_portid;
3816 rp->rftid_fc4types[FC4_SCSI >> 5] = 1 << (FC4_SCSI & 0x1f);
3817 isp_put_rft_id(isp, rp, (rft_id_t *) &scp[XTXOFF]);
3818 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3819 isp_print_bytes(isp, "CT Header", QENTRY_LEN, &scp[XTXOFF]);
3822 ISP_MEMZERO(&scp[ZTXOFF], sizeof (ct_hdr_t));
3824 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 1000000);
3825 mbs.param[1] = QENTRY_LEN;
3826 mbs.param[2] = DMA_WD1(fcp->isp_scdma + CTXOFF);
3827 mbs.param[3] = DMA_WD0(fcp->isp_scdma + CTXOFF);
3828 mbs.param[6] = DMA_WD3(fcp->isp_scdma + CTXOFF);
3829 mbs.param[7] = DMA_WD2(fcp->isp_scdma + CTXOFF);
3830 MEMORYBARRIER(isp, SYNC_SFORDEV, XTXOFF, 2 * QENTRY_LEN, chan);
3831 isp_mboxcmd(isp, &mbs);
3832 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3833 FC_SCRATCH_RELEASE(isp, chan);
3836 MEMORYBARRIER(isp, SYNC_SFORCPU, ZTXOFF, QENTRY_LEN, chan);
3838 isp_get_ct_pt(isp, (isp_ct_pt_t *) &scp[ZTXOFF], pt);
3839 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3840 isp_print_bytes(isp, "IOCB response", QENTRY_LEN, pt);
3842 if (pt->ctp_status) {
3843 FC_SCRATCH_RELEASE(isp, chan);
3844 isp_prt(isp, ISP_LOGWARN,
3845 "Chan %d Register FC4 Type CT Passthrough returned 0x%x",
3846 chan, pt->ctp_status);
3850 isp_get_ct_hdr(isp, (ct_hdr_t *) &scp[IGPOFF], ct);
3851 FC_SCRATCH_RELEASE(isp, chan);
3853 if (ct->ct_cmd_resp == LS_RJT) {
3854 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "Chan %d Register FC4 Type rejected", chan);
3856 } else if (ct->ct_cmd_resp == LS_ACC) {
3857 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Register FC4 Type accepted", chan);
3860 isp_prt(isp, ISP_LOGWARN, "Chan %d Register FC4 Type: 0x%x", chan, ct->ct_cmd_resp);
3866 isp_register_fc4_features_24xx(ispsoftc_t *isp, int chan)
3869 fcparam *fcp = FCPARAM(isp, chan);
3873 uint8_t q[QENTRY_LEN];
3878 uint8_t *scp = fcp->isp_scratch;
3880 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3881 isp_prt(isp, ISP_LOGERR, sacq);
3886 * Build a Passthrough IOCB in memory.
3888 ISP_MEMZERO(un.q, QENTRY_LEN);
3890 pt->ctp_header.rqs_entry_count = 1;
3891 pt->ctp_header.rqs_entry_type = RQSTYPE_CT_PASSTHRU;
3892 pt->ctp_handle = 0xffffffff;
3893 pt->ctp_nphdl = fcp->isp_sns_hdl;
3894 pt->ctp_cmd_cnt = 1;
3895 pt->ctp_vpidx = ISP_GET_VPIDX(isp, chan);
3897 pt->ctp_rsp_cnt = 1;
3898 pt->ctp_rsp_bcnt = sizeof (ct_hdr_t);
3899 pt->ctp_cmd_bcnt = sizeof (rff_id_t);
3900 pt->ctp_dataseg[0].ds_base = DMA_LO32(fcp->isp_scdma+XTXOFF);
3901 pt->ctp_dataseg[0].ds_basehi = DMA_HI32(fcp->isp_scdma+XTXOFF);
3902 pt->ctp_dataseg[0].ds_count = sizeof (rff_id_t);
3903 pt->ctp_dataseg[1].ds_base = DMA_LO32(fcp->isp_scdma+IGPOFF);
3904 pt->ctp_dataseg[1].ds_basehi = DMA_HI32(fcp->isp_scdma+IGPOFF);
3905 pt->ctp_dataseg[1].ds_count = sizeof (ct_hdr_t);
3906 isp_put_ct_pt(isp, pt, (isp_ct_pt_t *) &scp[CTXOFF]);
3907 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3908 isp_print_bytes(isp, "IOCB CT Request", QENTRY_LEN, pt);
3912 * Build the CT header and command in memory.
3914 * Note that the CT header has to end up as Big Endian format in memory.
3916 ISP_MEMZERO(&un.clocal, sizeof (un.clocal));
3917 ct = &un.clocal.rffid_hdr;
3918 ct->ct_revision = CT_REVISION;
3919 ct->ct_fcs_type = CT_FC_TYPE_FC;
3920 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3921 ct->ct_cmd_resp = SNS_RFF_ID;
3922 ct->ct_bcnt_resid = (sizeof (rff_id_t) - sizeof (ct_hdr_t)) >> 2;
3924 rp->rffid_portid[0] = fcp->isp_portid >> 16;
3925 rp->rffid_portid[1] = fcp->isp_portid >> 8;
3926 rp->rffid_portid[2] = fcp->isp_portid;
3927 rp->rffid_fc4features = 0;
3928 if (fcp->role & ISP_ROLE_TARGET)
3929 rp->rffid_fc4features |= 1;
3930 if (fcp->role & ISP_ROLE_INITIATOR)
3931 rp->rffid_fc4features |= 2;
3932 rp->rffid_fc4type = FC4_SCSI;
3933 isp_put_rff_id(isp, rp, (rff_id_t *) &scp[XTXOFF]);
3934 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3935 isp_print_bytes(isp, "CT Header", QENTRY_LEN, &scp[XTXOFF]);
3938 ISP_MEMZERO(&scp[ZTXOFF], sizeof (ct_hdr_t));
3940 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 1000000);
3941 mbs.param[1] = QENTRY_LEN;
3942 mbs.param[2] = DMA_WD1(fcp->isp_scdma + CTXOFF);
3943 mbs.param[3] = DMA_WD0(fcp->isp_scdma + CTXOFF);
3944 mbs.param[6] = DMA_WD3(fcp->isp_scdma + CTXOFF);
3945 mbs.param[7] = DMA_WD2(fcp->isp_scdma + CTXOFF);
3946 MEMORYBARRIER(isp, SYNC_SFORDEV, XTXOFF, 2 * QENTRY_LEN, chan);
3947 isp_mboxcmd(isp, &mbs);
3948 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3949 FC_SCRATCH_RELEASE(isp, chan);
3952 MEMORYBARRIER(isp, SYNC_SFORCPU, ZTXOFF, QENTRY_LEN, chan);
3954 isp_get_ct_pt(isp, (isp_ct_pt_t *) &scp[ZTXOFF], pt);
3955 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3956 isp_print_bytes(isp, "IOCB response", QENTRY_LEN, pt);
3958 if (pt->ctp_status) {
3959 FC_SCRATCH_RELEASE(isp, chan);
3960 isp_prt(isp, ISP_LOGWARN,
3961 "Chan %d Register FC4 Features CT Passthrough returned 0x%x",
3962 chan, pt->ctp_status);
3966 isp_get_ct_hdr(isp, (ct_hdr_t *) &scp[IGPOFF], ct);
3967 FC_SCRATCH_RELEASE(isp, chan);
3969 if (ct->ct_cmd_resp == LS_RJT) {
3970 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1,
3971 "Chan %d Register FC4 Features rejected", chan);
3973 } else if (ct->ct_cmd_resp == LS_ACC) {
3974 isp_prt(isp, ISP_LOG_SANCFG,
3975 "Chan %d Register FC4 Features accepted", chan);
3978 isp_prt(isp, ISP_LOGWARN,
3979 "Chan %d Register FC4 Features: 0x%x", chan, ct->ct_cmd_resp);
3985 isp_next_handle(ispsoftc_t *isp, uint16_t *ohp)
3989 uint16_t handle, minh, maxh;
3992 if (ISP_CAP_2KLOGIN(isp)) {
3994 maxh = NPH_RESERVED - 1;
4002 if (handle == NIL_HANDLE) {
4006 if (handle > maxh) {
4008 isp_prt(isp, ISP_LOGERR, "Out of port handles!");
4009 return (NIL_HANDLE);
4014 for (chan = 0; chan < isp->isp_nchan; chan++) {
4015 fcp = FCPARAM(isp, chan);
4016 if (fcp->role == ISP_ROLE_NONE)
4018 for (i = 0; i < MAX_FC_TARG; i++) {
4019 if (fcp->portdb[i].state != FC_PORTDB_STATE_NIL &&
4020 fcp->portdb[i].handle == handle)
4029 * Start a command. Locking is assumed done in the caller.
4036 uint32_t handle, cdblen;
4037 uint8_t local[QENTRY_LEN];
4042 int target, dmaresult;
4048 * Check command CDB length, etc.. We really are limited to 16 bytes
4049 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
4050 * but probably only if we're running fairly new firmware (we'll
4051 * let the old f/w choke on an extended command queue entry).
4054 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
4055 isp_prt(isp, ISP_LOGERR, "unsupported cdb length (%d, CDB[0]=0x%x)", XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
4056 XS_SETERR(xs, HBA_BOTCH);
4057 return (CMD_COMPLETE);
4061 * Translate the target to device handle as appropriate, checking
4062 * for correct device state as well.
4064 target = XS_TGT(xs);
4066 fcparam *fcp = FCPARAM(isp, XS_CHANNEL(xs));
4068 if ((fcp->role & ISP_ROLE_INITIATOR) == 0) {
4069 isp_prt(isp, ISP_LOG_WARN1,
4070 "%d.%d.%jx I am not an initiator",
4071 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4072 XS_SETERR(xs, HBA_SELTIMEOUT);
4073 return (CMD_COMPLETE);
4076 if (isp->isp_state != ISP_RUNSTATE) {
4077 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
4078 XS_SETERR(xs, HBA_BOTCH);
4079 return (CMD_COMPLETE);
4085 if (fcp->isp_loopstate != LOOP_READY) {
4086 return (CMD_RQLATER);
4089 isp_prt(isp, ISP_LOGDEBUG2, "XS_TGT(xs)=%d", target);
4090 lp = &fcp->portdb[target];
4091 if (target < 0 || target >= MAX_FC_TARG ||
4092 lp->is_target == 0) {
4093 XS_SETERR(xs, HBA_SELTIMEOUT);
4094 return (CMD_COMPLETE);
4096 if (lp->state == FC_PORTDB_STATE_ZOMBIE) {
4097 isp_prt(isp, ISP_LOGDEBUG1,
4098 "%d.%d.%jx target zombie",
4099 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4100 return (CMD_RQLATER);
4102 if (lp->state != FC_PORTDB_STATE_VALID) {
4103 isp_prt(isp, ISP_LOGDEBUG1,
4104 "%d.%d.%jx bad db port state 0x%x",
4105 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs), lp->state);
4106 XS_SETERR(xs, HBA_SELTIMEOUT);
4107 return (CMD_COMPLETE);
4110 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
4111 if ((sdp->role & ISP_ROLE_INITIATOR) == 0) {
4112 isp_prt(isp, ISP_LOGDEBUG1,
4113 "%d.%d.%jx I am not an initiator",
4114 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4115 XS_SETERR(xs, HBA_SELTIMEOUT);
4116 return (CMD_COMPLETE);
4119 if (isp->isp_state != ISP_RUNSTATE) {
4120 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
4121 XS_SETERR(xs, HBA_BOTCH);
4122 return (CMD_COMPLETE);
4126 isp_spi_update(isp, XS_CHANNEL(xs));
4133 qep = isp_getrqentry(isp);
4135 isp_prt(isp, ISP_LOG_WARN1, "Request Queue Overflow");
4136 XS_SETERR(xs, HBA_BOTCH);
4137 return (CMD_EAGAIN);
4139 XS_SETERR(xs, HBA_NOERROR);
4142 * Now see if we need to synchronize the ISP with respect to anything.
4143 * We do dual duty here (cough) for synchronizing for busses other
4144 * than which we got here to send a command to.
4146 reqp = (ispreq_t *) local;
4147 ISP_MEMZERO(local, QENTRY_LEN);
4148 if (ISP_TST_SENDMARKER(isp, XS_CHANNEL(xs))) {
4150 isp_marker_24xx_t *m = (isp_marker_24xx_t *) reqp;
4151 m->mrk_header.rqs_entry_count = 1;
4152 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4153 m->mrk_modifier = SYNC_ALL;
4154 m->mrk_vphdl = XS_CHANNEL(xs);
4155 isp_put_marker_24xx(isp, m, qep);
4157 isp_marker_t *m = (isp_marker_t *) reqp;
4158 m->mrk_header.rqs_entry_count = 1;
4159 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4160 m->mrk_target = (XS_CHANNEL(xs) << 7); /* bus # */
4161 m->mrk_modifier = SYNC_ALL;
4162 isp_put_marker(isp, m, qep);
4164 ISP_SYNC_REQUEST(isp);
4165 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 0);
4169 reqp->req_header.rqs_entry_count = 1;
4172 * Select and install Header Code.
4173 * Note that it might be overridden before going out
4174 * if we're on a 64 bit platform. The lower level
4175 * code (isp_send_cmd) will select the appropriate
4176 * 64 bit variant if it needs to.
4179 reqp->req_header.rqs_entry_type = RQSTYPE_T7RQS;
4180 } else if (IS_FC(isp)) {
4181 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
4183 if (XS_CDBLEN(xs) > 12) {
4184 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
4186 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
4191 * Set task attributes
4196 ttype = XS_TAG_TYPE(xs);
4198 if (XS_CDBP(xs)[0] == 0x3) {
4199 ttype = REQFLAG_HTAG;
4201 ttype = REQFLAG_STAG;
4204 if (ttype == REQFLAG_OTAG) {
4205 ttype = FCP_CMND_TASK_ATTR_ORDERED;
4206 } else if (ttype == REQFLAG_HTAG) {
4207 ttype = FCP_CMND_TASK_ATTR_HEAD;
4209 ttype = FCP_CMND_TASK_ATTR_SIMPLE;
4211 ((ispreqt7_t *)reqp)->req_task_attribute = ttype;
4212 } else if (IS_FC(isp)) {
4214 * See comment in isp_intr
4216 /* XS_SET_RESID(xs, 0); */
4219 * Fibre Channel always requires some kind of tag.
4220 * The Qlogic drivers seem be happy not to use a tag,
4221 * but this breaks for some devices (IBM drives).
4224 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
4227 * If we don't know what tag to use, use HEAD OF QUEUE
4228 * for Request Sense or Simple.
4230 if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
4231 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_HTAG;
4233 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
4236 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
4237 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) && XS_TAG_P(xs)) {
4238 reqp->req_flags = XS_TAG_TYPE(xs);
4242 tptr = &reqp->req_time;
4245 * NB: we do not support long CDBs (yet)
4247 cdblen = XS_CDBLEN(xs);
4250 if (cdblen > sizeof (reqp->req_cdb)) {
4251 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4252 XS_SETERR(xs, HBA_BOTCH);
4253 return (CMD_COMPLETE);
4255 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
4256 reqp->req_lun_trn = XS_LUN(xs);
4257 cdbp = reqp->req_cdb;
4258 reqp->req_cdblen = cdblen;
4259 } else if (IS_24XX(isp)) {
4260 ispreqt7_t *t7 = (ispreqt7_t *)local;
4262 if (cdblen > sizeof (t7->req_cdb)) {
4263 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4264 XS_SETERR(xs, HBA_BOTCH);
4265 return (CMD_COMPLETE);
4268 t7->req_nphdl = lp->handle;
4269 t7->req_tidlo = lp->portid;
4270 t7->req_tidhi = lp->portid >> 16;
4271 t7->req_vpidx = ISP_GET_VPIDX(isp, XS_CHANNEL(xs));
4272 #if __FreeBSD_version >= 1000700
4273 be64enc(t7->req_lun, CAM_EXTLUN_BYTE_SWIZZLE(XS_LUN(xs)));
4275 if (XS_LUN(xs) >= 256) {
4276 t7->req_lun[0] = XS_LUN(xs) >> 8;
4277 t7->req_lun[0] |= 0x40;
4279 t7->req_lun[1] = XS_LUN(xs);
4281 if (FCPARAM(isp, XS_CHANNEL(xs))->fctape_enabled && (lp->prli_word3 & PRLI_WD3_RETRY)) {
4282 if (FCP_NEXT_CRN(isp, &t7->req_crn, xs)) {
4283 isp_prt(isp, ISP_LOG_WARN1,
4284 "%d.%d.%jx cannot generate next CRN",
4285 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4286 XS_SETERR(xs, HBA_BOTCH);
4287 return (CMD_EAGAIN);
4290 tptr = &t7->req_time;
4293 ispreqt2_t *t2 = (ispreqt2_t *)local;
4295 if (cdblen > sizeof t2->req_cdb) {
4296 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4297 XS_SETERR(xs, HBA_BOTCH);
4298 return (CMD_COMPLETE);
4300 if (FCPARAM(isp, XS_CHANNEL(xs))->fctape_enabled && (lp->prli_word3 & PRLI_WD3_RETRY)) {
4301 if (FCP_NEXT_CRN(isp, &t2->req_crn, xs)) {
4302 isp_prt(isp, ISP_LOG_WARN1,
4303 "%d.%d.%jx cannot generate next CRN",
4304 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4305 XS_SETERR(xs, HBA_BOTCH);
4306 return (CMD_EAGAIN);
4309 if (ISP_CAP_2KLOGIN(isp)) {
4310 ispreqt2e_t *t2e = (ispreqt2e_t *)local;
4311 t2e->req_target = lp->handle;
4312 t2e->req_scclun = XS_LUN(xs);
4313 #if __FreeBSD_version < 1000700
4314 if (XS_LUN(xs) >= 256)
4315 t2e->req_scclun |= 0x4000;
4317 cdbp = t2e->req_cdb;
4318 } else if (ISP_CAP_SCCFW(isp)) {
4319 ispreqt2_t *t2 = (ispreqt2_t *)local;
4320 t2->req_target = lp->handle;
4321 t2->req_scclun = XS_LUN(xs);
4322 #if __FreeBSD_version < 1000700
4323 if (XS_LUN(xs) >= 256)
4324 t2->req_scclun |= 0x4000;
4328 t2->req_target = lp->handle;
4329 t2->req_lun_trn = XS_LUN(xs);
4333 ISP_MEMCPY(cdbp, XS_CDBP(xs), cdblen);
4335 *tptr = XS_TIME(xs) / 1000;
4336 if (*tptr == 0 && XS_TIME(xs)) {
4339 if (IS_24XX(isp) && *tptr > 0x1999) {
4343 if (isp_allocate_xs(isp, xs, &handle)) {
4344 isp_prt(isp, ISP_LOG_WARN1, "out of xflist pointers");
4345 XS_SETERR(xs, HBA_BOTCH);
4346 return (CMD_EAGAIN);
4348 /* Whew. Thankfully the same for type 7 requests */
4349 reqp->req_handle = handle;
4352 * Set up DMA and/or do any platform dependent swizzling of the request entry
4353 * so that the Qlogic F/W understands what is being asked of it.
4355 * The callee is responsible for adding all requests at this point.
4357 dmaresult = ISP_DMASETUP(isp, xs, reqp);
4358 if (dmaresult != CMD_QUEUED) {
4359 isp_destroy_handle(isp, handle);
4361 * dmasetup sets actual error in packet, and
4362 * return what we were given to return.
4366 isp_xs_prt(isp, xs, ISP_LOGDEBUG0, "START cmd cdb[0]=0x%x datalen %ld", XS_CDBP(xs)[0], (long) XS_XFRLEN(xs));
4368 return (CMD_QUEUED);
4373 * Locks (ints blocked) assumed held.
4377 isp_control(ispsoftc_t *isp, ispctl_t ctl, ...)
4386 case ISPCTL_RESET_BUS:
4388 * Issue a bus reset.
4391 isp_prt(isp, ISP_LOGERR, "BUS RESET NOT IMPLEMENTED");
4393 } else if (IS_FC(isp)) {
4398 chan = va_arg(ap, int);
4400 mbs.param[1] = SDPARAM(isp, chan)->isp_bus_reset_delay;
4401 if (mbs.param[1] < 2) {
4404 mbs.param[2] = chan;
4406 MBSINIT(&mbs, MBOX_BUS_RESET, MBLOGALL, 0);
4407 ISP_SET_SENDMARKER(isp, chan, 1);
4408 isp_mboxcmd(isp, &mbs);
4409 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4412 isp_prt(isp, ISP_LOGINFO, "driver initiated bus reset of bus %d", chan);
4415 case ISPCTL_RESET_DEV:
4417 chan = va_arg(ap, int);
4418 tgt = va_arg(ap, int);
4421 uint8_t local[QENTRY_LEN];
4423 isp24xx_statusreq_t *sp;
4424 fcparam *fcp = FCPARAM(isp, chan);
4427 if (tgt < 0 || tgt >= MAX_FC_TARG) {
4428 isp_prt(isp, ISP_LOGWARN, "Chan %d trying to reset bad target %d", chan, tgt);
4431 lp = &fcp->portdb[tgt];
4432 if (lp->is_target == 0 ||
4433 lp->state != FC_PORTDB_STATE_VALID) {
4434 isp_prt(isp, ISP_LOGWARN, "Chan %d abort of no longer valid target %d", chan, tgt);
4438 tmf = (isp24xx_tmf_t *) local;
4439 ISP_MEMZERO(tmf, QENTRY_LEN);
4440 tmf->tmf_header.rqs_entry_type = RQSTYPE_TSK_MGMT;
4441 tmf->tmf_header.rqs_entry_count = 1;
4442 tmf->tmf_nphdl = lp->handle;
4444 tmf->tmf_timeout = 2;
4445 tmf->tmf_flags = ISP24XX_TMF_TARGET_RESET;
4446 tmf->tmf_tidlo = lp->portid;
4447 tmf->tmf_tidhi = lp->portid >> 16;
4448 tmf->tmf_vpidx = ISP_GET_VPIDX(isp, chan);
4449 isp_prt(isp, ISP_LOGALL, "Chan %d Reset N-Port Handle 0x%04x @ Port 0x%06x", chan, lp->handle, lp->portid);
4450 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 5000000);
4451 mbs.param[1] = QENTRY_LEN;
4452 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
4453 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
4454 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
4455 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
4457 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4458 isp_prt(isp, ISP_LOGERR, sacq);
4461 isp_put_24xx_tmf(isp, tmf, fcp->isp_scratch);
4462 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, QENTRY_LEN, chan);
4463 fcp->sendmarker = 1;
4464 isp_mboxcmd(isp, &mbs);
4465 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4466 FC_SCRATCH_RELEASE(isp, chan);
4469 MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN, QENTRY_LEN, chan);
4470 sp = (isp24xx_statusreq_t *) local;
4471 isp_get_24xx_response(isp, &((isp24xx_statusreq_t *)fcp->isp_scratch)[1], sp);
4472 FC_SCRATCH_RELEASE(isp, chan);
4473 if (sp->req_completion_status == 0) {
4476 isp_prt(isp, ISP_LOGWARN, "Chan %d reset of target %d returned 0x%x", chan, tgt, sp->req_completion_status);
4478 } else if (IS_FC(isp)) {
4479 if (ISP_CAP_2KLOGIN(isp)) {
4481 mbs.ibits = (1 << 10);
4483 mbs.param[1] = (tgt << 8);
4486 mbs.param[1] = (chan << 15) | (tgt << 8);
4488 MBSINIT(&mbs, MBOX_ABORT_TARGET, MBLOGALL, 0);
4489 mbs.param[2] = 3; /* 'delay', in seconds */
4490 isp_mboxcmd(isp, &mbs);
4491 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4494 isp_prt(isp, ISP_LOGINFO, "Target %d on Bus %d Reset Succeeded", tgt, chan);
4495 ISP_SET_SENDMARKER(isp, chan, 1);
4498 case ISPCTL_ABORT_CMD:
4500 xs = va_arg(ap, XS_T *);
4504 chan = XS_CHANNEL(xs);
4506 handle = isp_find_handle(isp, xs);
4508 isp_prt(isp, ISP_LOGWARN, "cannot find handle for command to abort");
4512 isp24xx_abrt_t local, *ab = &local, *ab2;
4516 fcp = FCPARAM(isp, chan);
4517 if (tgt < 0 || tgt >= MAX_FC_TARG) {
4518 isp_prt(isp, ISP_LOGWARN, "Chan %d trying to abort bad target %d", chan, tgt);
4521 lp = &fcp->portdb[tgt];
4522 if (lp->is_target == 0 ||
4523 lp->state != FC_PORTDB_STATE_VALID) {
4524 isp_prt(isp, ISP_LOGWARN, "Chan %d abort of no longer valid target %d", chan, tgt);
4527 isp_prt(isp, ISP_LOGALL, "Chan %d Abort Cmd for N-Port 0x%04x @ Port 0x%06x", chan, lp->handle, lp->portid);
4528 ISP_MEMZERO(ab, QENTRY_LEN);
4529 ab->abrt_header.rqs_entry_type = RQSTYPE_ABORT_IO;
4530 ab->abrt_header.rqs_entry_count = 1;
4531 ab->abrt_handle = lp->handle;
4532 ab->abrt_cmd_handle = handle;
4533 ab->abrt_tidlo = lp->portid;
4534 ab->abrt_tidhi = lp->portid >> 16;
4535 ab->abrt_vpidx = ISP_GET_VPIDX(isp, chan);
4537 ISP_MEMZERO(&mbs, sizeof (mbs));
4538 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 5000000);
4539 mbs.param[1] = QENTRY_LEN;
4540 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
4541 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
4542 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
4543 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
4545 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4546 isp_prt(isp, ISP_LOGERR, sacq);
4549 isp_put_24xx_abrt(isp, ab, fcp->isp_scratch);
4550 ab2 = (isp24xx_abrt_t *) &((uint8_t *)fcp->isp_scratch)[QENTRY_LEN];
4551 ab2->abrt_nphdl = 0xdeaf;
4552 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, 2 * QENTRY_LEN, chan);
4553 isp_mboxcmd(isp, &mbs);
4554 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4555 FC_SCRATCH_RELEASE(isp, chan);
4558 MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN, QENTRY_LEN, chan);
4559 isp_get_24xx_abrt(isp, ab2, ab);
4560 FC_SCRATCH_RELEASE(isp, chan);
4561 if (ab->abrt_nphdl == ISP24XX_ABRT_OKAY) {
4564 isp_prt(isp, ISP_LOGWARN, "Chan %d handle %d abort returned 0x%x", chan, tgt, ab->abrt_nphdl);
4566 } else if (IS_FC(isp)) {
4567 if (ISP_CAP_SCCFW(isp)) {
4568 if (ISP_CAP_2KLOGIN(isp)) {
4571 mbs.param[1] = tgt << 8;
4573 mbs.param[6] = XS_LUN(xs);
4575 mbs.param[1] = tgt << 8 | XS_LUN(xs);
4578 mbs.param[1] = (chan << 15) | (tgt << 8) | XS_LUN(xs);
4580 MBSINIT(&mbs, MBOX_ABORT,
4581 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_ERROR), 0);
4582 mbs.param[2] = handle;
4583 isp_mboxcmd(isp, &mbs);
4584 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4589 case ISPCTL_UPDATE_PARAMS:
4592 chan = va_arg(ap, int);
4594 isp_spi_update(isp, chan);
4597 case ISPCTL_FCLINK_TEST:
4602 chan = va_arg(ap, int);
4603 usdelay = va_arg(ap, int);
4608 return (isp_fclink_test(isp, chan, usdelay));
4612 case ISPCTL_SCAN_FABRIC:
4616 chan = va_arg(ap, int);
4618 return (isp_scan_fabric(isp, chan));
4622 case ISPCTL_SCAN_LOOP:
4626 chan = va_arg(ap, int);
4628 return (isp_scan_loop(isp, chan));
4632 case ISPCTL_PDB_SYNC:
4636 chan = va_arg(ap, int);
4638 return (isp_pdb_sync(isp, chan));
4642 case ISPCTL_SEND_LIP:
4644 if (IS_FC(isp) && !IS_24XX(isp)) {
4645 MBSINIT(&mbs, MBOX_INIT_LIP, MBLOGALL, 0);
4646 if (ISP_CAP_2KLOGIN(isp)) {
4647 mbs.ibits = (1 << 10);
4649 isp_mboxcmd(isp, &mbs);
4650 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
4656 case ISPCTL_GET_PDB:
4660 chan = va_arg(ap, int);
4661 tgt = va_arg(ap, int);
4662 pdb = va_arg(ap, isp_pdb_t *);
4664 return (isp_getpdb(isp, chan, tgt, pdb, 1));
4668 case ISPCTL_GET_NAMES:
4670 uint64_t *wwnn, *wwnp;
4672 chan = va_arg(ap, int);
4673 tgt = va_arg(ap, int);
4674 wwnn = va_arg(ap, uint64_t *);
4675 wwnp = va_arg(ap, uint64_t *);
4677 if (wwnn == NULL && wwnp == NULL) {
4681 *wwnn = isp_get_wwn(isp, chan, tgt, 1);
4682 if (*wwnn == INI_NONE) {
4687 *wwnp = isp_get_wwn(isp, chan, tgt, 0);
4688 if (*wwnp == INI_NONE) {
4694 case ISPCTL_RUN_MBOXCMD:
4697 mbr = va_arg(ap, mbreg_t *);
4699 isp_mboxcmd(isp, mbr);
4708 p = va_arg(ap, isp_plcmd_t *);
4711 if ((p->flags & PLOGX_FLG_CMD_MASK) != PLOGX_FLG_CMD_PLOGI || (p->handle != NIL_HANDLE)) {
4712 return (isp_plogx(isp, p->channel, p->handle, p->portid, p->flags, 0));
4715 isp_next_handle(isp, &p->handle);
4716 r = isp_plogx(isp, p->channel, p->handle, p->portid, p->flags, 0);
4717 if ((r & 0xffff) == MBOX_PORT_ID_USED) {
4718 p->handle = r >> 16;
4722 } while ((r & 0xffff) == MBOX_LOOP_ID_USED);
4725 case ISPCTL_CHANGE_ROLE:
4730 chan = va_arg(ap, int);
4731 role = va_arg(ap, int);
4734 r = isp_fc_change_role(isp, chan, role);
4736 SDPARAM(isp, chan)->role = role;
4742 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
4750 * Interrupt Service Routine(s).
4752 * External (OS) framework has done the appropriate locking,
4753 * and the locking will be held throughout this function.
4757 * Limit our stack depth by sticking with the max likely number
4758 * of completions on a request queue at any one time.
4760 #ifndef MAX_REQUESTQ_COMPLETIONS
4761 #define MAX_REQUESTQ_COMPLETIONS 32
4765 isp_intr(ispsoftc_t *isp, uint16_t isr, uint16_t sema, uint16_t info)
4767 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
4768 uint32_t iptr, optr, junk;
4769 int i, nlooked = 0, ndone = 0, continuations_expected = 0;
4770 int etype, last_etype = 0;
4774 * Is this a mailbox related interrupt?
4775 * The mailbox semaphore will be nonzero if so.
4779 if (info & MBOX_COMMAND_COMPLETE) {
4780 isp->isp_intmboxc++;
4781 if (isp->isp_mboxbsy) {
4782 int obits = isp->isp_obits;
4783 isp->isp_mboxtmp[0] = info;
4784 for (i = 1; i < ISP_NMBOX(isp); i++) {
4785 if ((obits & (1 << i)) == 0) {
4788 isp->isp_mboxtmp[i] = ISP_READ(isp, MBOX_OFF(i));
4790 if (isp->isp_mbxwrk0) {
4791 if (isp_mbox_continue(isp) == 0) {
4795 MBOX_NOTIFY_COMPLETE(isp);
4797 isp_prt(isp, ISP_LOGWARN, "mailbox cmd (0x%x) with no waiters", info);
4800 i = IS_FC(isp)? isp_parse_async_fc(isp, info) : isp_parse_async(isp, info);
4805 if ((IS_FC(isp) && info != ASYNC_RIOZIO_STALL) || isp->isp_state != ISP_RUNSTATE) {
4811 * We can't be getting this now.
4813 if (isp->isp_state != ISP_RUNSTATE) {
4815 * This seems to happen to 23XX and 24XX cards- don't know why.
4817 if (isp->isp_mboxbsy && isp->isp_lastmbxcmd == MBOX_ABOUT_FIRMWARE) {
4820 isp_prt(isp, ISP_LOGINFO, "interrupt (ISR=%x SEMA=%x INFO=%x) "
4821 "when not ready", isr, sema, info);
4823 * Thank you very much! *Burrrp*!
4825 isp->isp_residx = ISP_READ(isp, isp->isp_respinrp);
4826 isp->isp_resodx = isp->isp_residx;
4827 ISP_WRITE(isp, isp->isp_respoutrp, isp->isp_resodx);
4829 ISP_DISABLE_INTS(isp);
4834 #ifdef ISP_TARGET_MODE
4836 * Check for ATIO Queue entries.
4839 (isr == ISPR2HST_ATIO_UPDATE || isr == ISPR2HST_ATIO_RSPQ_UPDATE ||
4840 isr == ISPR2HST_ATIO_UPDATE2)) {
4841 iptr = ISP_READ(isp, BIU2400_ATIO_RSPINP);
4842 optr = isp->isp_atioodx;
4844 while (optr != iptr) {
4845 uint8_t qe[QENTRY_LEN];
4851 MEMORYBARRIER(isp, SYNC_ATIOQ, oop, QENTRY_LEN, -1);
4852 addr = ISP_QUEUE_ENTRY(isp->isp_atioq, oop);
4853 isp_get_hdr(isp, addr, (isphdr_t *)qe);
4854 hp = (isphdr_t *)qe;
4855 switch (hp->rqs_entry_type) {
4856 case RQSTYPE_NOTIFY:
4858 (void) isp_target_notify(isp, addr, &oop);
4861 isp_print_qentry(isp, "?ATIOQ entry?", oop, addr);
4864 optr = ISP_NXT_QENTRY(oop, RESULT_QUEUE_LEN(isp));
4866 if (isp->isp_atioodx != optr) {
4867 ISP_WRITE(isp, BIU2400_ATIO_RSPOUTP, optr);
4868 isp->isp_atioodx = optr;
4874 * You *must* read the Response Queue In Pointer
4875 * prior to clearing the RISC interrupt.
4877 * Debounce the 2300 if revision less than 2.
4879 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
4882 iptr = ISP_READ(isp, isp->isp_respinrp);
4883 junk = ISP_READ(isp, isp->isp_respinrp);
4884 } while (junk != iptr && ++i < 1000);
4887 isp_prt(isp, ISP_LOGWARN, "Response Queue Out Pointer Unstable (%x, %x)", iptr, junk);
4891 iptr = ISP_READ(isp, isp->isp_respinrp);
4894 optr = isp->isp_resodx;
4895 if (optr == iptr && sema == 0) {
4897 * There are a lot of these- reasons unknown- mostly on
4898 * faster Alpha machines.
4900 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
4901 * make sure the old interrupt went away (to avoid 'ringing'
4902 * effects), but that didn't stop this from occurring.
4906 } else if (IS_23XX(isp)) {
4908 iptr = ISP_READ(isp, isp->isp_respinrp);
4909 junk = ISP_READ(isp, BIU_R2HSTSLO);
4911 junk = ISP_READ(isp, BIU_ISR);
4914 if (IS_23XX(isp) || IS_24XX(isp)) {
4917 sema = ISP_READ(isp, BIU_SEMA);
4918 info = ISP_READ(isp, OUTMAILBOX0);
4919 if ((sema & 0x3) && (info & 0x8000)) {
4923 isp->isp_intbogus++;
4924 isp_prt(isp, ISP_LOGDEBUG1, "bogus intr- isr %x (%x) iptr %x optr %x", isr, junk, iptr, optr);
4927 isp->isp_residx = iptr;
4929 while (optr != iptr) {
4930 uint8_t qe[QENTRY_LEN];
4931 ispstatusreq_t *sp = (ispstatusreq_t *) qe;
4933 int buddaboom, scsi_status, completion_status;
4934 int req_status_flags, req_state_flags;
4935 uint8_t *snsp, *resp;
4936 uint32_t rlen, slen, totslen;
4940 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
4942 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
4945 buddaboom = req_status_flags = req_state_flags = 0;
4949 * Synchronize our view of this response queue entry.
4951 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN, -1);
4952 isp_get_hdr(isp, hp, &sp->req_header);
4953 etype = sp->req_header.rqs_entry_type;
4955 if (IS_24XX(isp) && etype == RQSTYPE_RESPONSE) {
4956 isp24xx_statusreq_t *sp2 = (isp24xx_statusreq_t *)qe;
4957 isp_get_24xx_response(isp, (isp24xx_statusreq_t *)hp, sp2);
4958 if (isp->isp_dblev & ISP_LOGDEBUG1) {
4959 isp_print_bytes(isp, "Response Queue Entry", QENTRY_LEN, sp2);
4961 scsi_status = sp2->req_scsi_status;
4962 completion_status = sp2->req_completion_status;
4963 if ((scsi_status & 0xff) != 0)
4964 req_state_flags = RQSF_GOT_STATUS;
4966 req_state_flags = 0;
4967 resid = sp2->req_resid;
4968 } else if (etype == RQSTYPE_RESPONSE) {
4969 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
4970 if (isp->isp_dblev & ISP_LOGDEBUG1) {
4971 isp_print_bytes(isp, "Response Queue Entry", QENTRY_LEN, sp);
4973 scsi_status = sp->req_scsi_status;
4974 completion_status = sp->req_completion_status;
4975 req_status_flags = sp->req_status_flags;
4976 req_state_flags = sp->req_state_flags;
4977 resid = sp->req_resid;
4978 } else if (etype == RQSTYPE_RIO1) {
4979 isp_rio1_t *rio = (isp_rio1_t *) qe;
4980 isp_get_rio1(isp, (isp_rio1_t *) hp, rio);
4981 if (isp->isp_dblev & ISP_LOGDEBUG1) {
4982 isp_print_bytes(isp, "Response Queue Entry", QENTRY_LEN, rio);
4984 for (i = 0; i < rio->req_header.rqs_seqno; i++) {
4985 isp_fastpost_complete(isp, rio->req_handles[i]);
4987 if (isp->isp_fpcchiwater < rio->req_header.rqs_seqno) {
4988 isp->isp_fpcchiwater = rio->req_header.rqs_seqno;
4990 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
4993 } else if (etype == RQSTYPE_RIO2) {
4994 isp_prt(isp, ISP_LOGERR, "dropping RIO2 response");
4995 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
4998 } else if (etype == RQSTYPE_STATUS_CONT) {
4999 isp_get_cont_response(isp, (ispstatus_cont_t *) hp, (ispstatus_cont_t *) sp);
5000 if (last_etype == RQSTYPE_RESPONSE && continuations_expected && ndone > 0 && (xs = complist[ndone-1]) != NULL) {
5001 ispstatus_cont_t *scp = (ispstatus_cont_t *) sp;
5002 XS_SENSE_APPEND(xs, scp->req_sense_data, sizeof (scp->req_sense_data));
5003 isp_prt(isp, ISP_LOGDEBUG0|ISP_LOG_CWARN, "%d more Status Continuations expected", --continuations_expected);
5005 isp_prt(isp, ISP_LOG_WARN1, "Ignored Continuation Response");
5007 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5011 * Somebody reachable via isp_handle_other_response
5012 * may have updated the response queue pointers for
5013 * us, so we reload our goal index.
5016 uint32_t tsto = oop;
5017 r = isp_handle_other_response(isp, etype, hp, &tsto);
5022 * If somebody updated the output pointer, then reset
5023 * optr to be one more than the updated amount.
5025 while (tsto != oop) {
5026 optr = ISP_NXT_QENTRY(tsto, RESULT_QUEUE_LEN(isp));
5029 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5035 * After this point, we'll just look at the header as
5036 * we don't know how to deal with the rest of the
5041 * It really has to be a bounced request just copied
5042 * from the request queue to the response queue. If
5043 * not, something bad has happened.
5045 if (etype != RQSTYPE_REQUEST) {
5046 isp_prt(isp, ISP_LOGERR, notresp, etype, oop, optr, nlooked);
5047 isp_print_bytes(isp, "Request Queue Entry", QENTRY_LEN, sp);
5048 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5053 scsi_status = sp->req_scsi_status;
5054 completion_status = sp->req_completion_status;
5055 req_status_flags = sp->req_status_flags;
5056 req_state_flags = sp->req_state_flags;
5057 resid = sp->req_resid;
5060 if (sp->req_header.rqs_flags & RQSFLAG_MASK) {
5061 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
5062 isp_print_bytes(isp, "unexpected continuation segment", QENTRY_LEN, sp);
5066 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
5067 isp_prt(isp, ISP_LOG_WARN1, "internal queues full");
5069 * We'll synthesize a QUEUE FULL message below.
5072 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
5073 isp_print_bytes(isp, "bad header flag", QENTRY_LEN, sp);
5076 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
5077 isp_print_bytes(isp, "bad request packet", QENTRY_LEN, sp);
5080 if (sp->req_header.rqs_flags & RQSFLAG_BADCOUNT) {
5081 isp_print_bytes(isp, "invalid entry count", QENTRY_LEN, sp);
5084 if (sp->req_header.rqs_flags & RQSFLAG_BADORDER) {
5085 isp_print_bytes(isp, "invalid IOCB ordering", QENTRY_LEN, sp);
5091 if (!ISP_VALID_HANDLE(isp, sp->req_handle)) {
5092 isp_prt(isp, ISP_LOGERR, "bad request handle 0x%x (iocb type 0x%x)", sp->req_handle, etype);
5093 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5097 xs = isp_find_xs(isp, sp->req_handle);
5099 uint8_t ts = completion_status & 0xff;
5101 * Only whine if this isn't the expected fallout of
5102 * aborting the command or resetting the target.
5104 if (etype != RQSTYPE_RESPONSE) {
5105 isp_prt(isp, ISP_LOGERR, "cannot find handle 0x%x (type 0x%x)", sp->req_handle, etype);
5106 } else if (ts != RQCS_ABORTED && ts != RQCS_RESET_OCCURRED) {
5107 isp_prt(isp, ISP_LOGERR, "cannot find handle 0x%x (status 0x%x)", sp->req_handle, ts);
5109 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5113 if (req_status_flags & RQSTF_BUS_RESET) {
5114 isp_prt(isp, ISP_LOG_WARN1, "%d.%d.%jx bus was reset",
5115 XS_CHANNEL(xs), XS_TGT(xs), (uintmax_t)XS_LUN(xs));
5116 XS_SETERR(xs, HBA_BUSRESET);
5117 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 1);
5120 isp_prt(isp, ISP_LOG_WARN1, "%d.%d.%jx buddaboom",
5121 XS_CHANNEL(xs), XS_TGT(xs), (uintmax_t)XS_LUN(xs));
5122 XS_SETERR(xs, HBA_BOTCH);
5129 if (IS_24XX(isp) && (scsi_status & (RQCS_RV|RQCS_SV)) != 0) {
5130 resp = ((isp24xx_statusreq_t *)sp)->req_rsp_sense;
5131 rlen = ((isp24xx_statusreq_t *)sp)->req_response_len;
5132 } else if (IS_FC(isp) && (scsi_status & RQCS_RV) != 0) {
5133 resp = sp->req_response;
5134 rlen = sp->req_response_len;
5136 if (IS_FC(isp) && (scsi_status & RQCS_SV) != 0) {
5138 * Fibre Channel F/W doesn't say we got status
5139 * if there's Sense Data instead. I guess they
5140 * think it goes w/o saying.
5142 req_state_flags |= RQSF_GOT_STATUS|RQSF_GOT_SENSE;
5144 snsp = ((isp24xx_statusreq_t *)sp)->req_rsp_sense;
5146 totslen = ((isp24xx_statusreq_t *)sp)->req_sense_len;
5147 slen = (sizeof (((isp24xx_statusreq_t *)sp)->req_rsp_sense)) - rlen;
5151 snsp = sp->req_sense_data;
5152 totslen = sp->req_sense_len;
5153 slen = sizeof (sp->req_sense_data);
5157 } else if (IS_SCSI(isp) && (req_state_flags & RQSF_GOT_SENSE)) {
5158 snsp = sp->req_sense_data;
5159 totslen = sp->req_sense_len;
5160 slen = sizeof (sp->req_sense_data);
5164 if (req_state_flags & RQSF_GOT_STATUS) {
5165 *XS_STSP(xs) = scsi_status & 0xff;
5169 case RQSTYPE_RESPONSE:
5170 if (resp && rlen >= 4 && resp[FCP_RSPNS_CODE_OFFSET] != 0) {
5173 const char *rnames[10] = {
5174 "Task Management function complete",
5175 "FCP_DATA length different than FCP_BURST_LEN",
5176 "FCP_CMND fields invalid",
5177 "FCP_DATA parameter mismatch with FCP_DATA_RO",
5178 "Task Management function rejected",
5179 "Task Management function failed",
5182 "Task Management function succeeded",
5183 "Task Management function incorrect logical unit number",
5185 uint8_t code = resp[FCP_RSPNS_CODE_OFFSET];
5186 if (code >= 10 || rnames[code] == NULL) {
5187 ISP_SNPRINTF(lb, sizeof(lb),
5188 "Unknown FCP Response Code 0x%x",
5194 isp_xs_prt(isp, xs, ISP_LOGWARN,
5195 "FCP RESPONSE, LENGTH %u: %s CDB0=0x%02x",
5196 rlen, ptr, XS_CDBP(xs)[0] & 0xff);
5197 if (code != 0 && code != 8)
5198 XS_SETERR(xs, HBA_BOTCH);
5201 isp_parse_status_24xx(isp, (isp24xx_statusreq_t *)sp, xs, &resid);
5203 isp_parse_status(isp, (void *)sp, xs, &resid);
5205 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) && (*XS_STSP(xs) == SCSI_BUSY)) {
5206 XS_SETERR(xs, HBA_TGTBSY);
5209 XS_SET_RESID(xs, resid);
5211 * A new synchronous rate was negotiated for
5212 * this target. Mark state such that we'll go
5213 * look up that which has changed later.
5215 if (req_status_flags & RQSTF_NEGOTIATION) {
5217 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
5218 sdp->isp_devparam[t].dev_refresh = 1;
5222 if (req_status_flags & RQSF_XFER_COMPLETE) {
5223 XS_SET_RESID(xs, 0);
5224 } else if (scsi_status & RQCS_RESID) {
5225 XS_SET_RESID(xs, resid);
5227 XS_SET_RESID(xs, 0);
5231 if (totslen > slen) {
5232 continuations_expected += ((totslen - slen + QENTRY_LEN - 5) / (QENTRY_LEN - 4));
5233 if (ndone > (MAX_REQUESTQ_COMPLETIONS - continuations_expected - 1)) {
5234 /* we'll lose some stats, but that's a small price to pay */
5235 for (i = 0; i < ndone; i++) {
5237 isp->isp_rsltccmplt++;
5238 isp_done(complist[i]);
5243 isp_prt(isp, ISP_LOGDEBUG0|ISP_LOG_CWARN, "Expecting %d more Status Continuations for total sense length of %u",
5244 continuations_expected, totslen);
5246 XS_SAVE_SENSE(xs, snsp, totslen, slen);
5247 } else if ((req_status_flags & RQSF_GOT_STATUS) && (scsi_status & 0xff) == SCSI_CHECK && IS_FC(isp)) {
5248 isp_prt(isp, ISP_LOGWARN, "CHECK CONDITION w/o sense data for CDB=0x%x", XS_CDBP(xs)[0] & 0xff);
5249 isp_print_bytes(isp, "CC with no Sense", QENTRY_LEN, qe);
5251 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));
5253 case RQSTYPE_REQUEST:
5258 if (!IS_24XX(isp) && (sp->req_header.rqs_flags & RQSFLAG_FULL)) {
5260 * Force Queue Full status.
5262 *XS_STSP(xs) = SCSI_QFULL;
5263 XS_SETERR(xs, HBA_NOERROR);
5264 } else if (XS_NOERR(xs)) {
5265 isp_prt(isp, ISP_LOG_WARN1,
5266 "%d.%d.%jx badness at %s:%u",
5267 XS_CHANNEL(xs), XS_TGT(xs),
5268 (uintmax_t)XS_LUN(xs),
5269 __func__, __LINE__);
5270 XS_SETERR(xs, HBA_BOTCH);
5272 XS_SET_RESID(xs, XS_XFRLEN(xs));
5275 isp_print_bytes(isp, "Unhandled Response Type", QENTRY_LEN, qe);
5277 XS_SETERR(xs, HBA_BOTCH);
5283 * Free any DMA resources. As a side effect, this may
5284 * also do any cache flushing necessary for data coherence.
5286 if (XS_XFRLEN(xs)) {
5287 ISP_DMAFREE(isp, xs, sp->req_handle);
5289 isp_destroy_handle(isp, sp->req_handle);
5291 if (isp->isp_nactive > 0) {
5294 complist[ndone++] = xs; /* defer completion call until later */
5295 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5297 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
5303 * If we looked at any commands, then it's valid to find out
5304 * what the outpointer is. It also is a trigger to update the
5305 * ISP's notion of what we've seen so far.
5308 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5309 isp->isp_resodx = optr;
5310 if (isp->isp_rscchiwater < ndone)
5311 isp->isp_rscchiwater = ndone;
5317 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
5319 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
5320 ISP_WRITE(isp, BIU_SEMA, 0);
5323 for (i = 0; i < ndone; i++) {
5326 if (((isp->isp_dblev & (ISP_LOGDEBUG1|ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
5327 ((isp->isp_dblev & (ISP_LOGDEBUG0|ISP_LOG_CWARN) && ((!XS_NOERR(xs)) || (*XS_STSP(xs) != SCSI_GOOD))))) {
5328 isp_prt_endcmd(isp, xs);
5330 isp->isp_rsltccmplt++;
5341 isp_prt_endcmd(ispsoftc_t *isp, XS_T *xs)
5343 char cdbstr[16 * 5 + 1];
5346 lim = XS_CDBLEN(xs) > 16? 16 : XS_CDBLEN(xs);
5347 ISP_SNPRINTF(cdbstr, sizeof (cdbstr), "0x%02x ", XS_CDBP(xs)[0]);
5348 for (i = 1; i < lim; i++) {
5349 ISP_SNPRINTF(cdbstr, sizeof (cdbstr), "%s0x%02x ", cdbstr, XS_CDBP(xs)[i]);
5351 if (XS_SENSE_VALID(xs)) {
5352 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",
5353 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));
5355 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));
5360 * Parse an ASYNC mailbox complete
5362 * Return non-zero if the event has been acknowledged.
5365 isp_parse_async(ispsoftc_t *isp, uint16_t mbox)
5368 uint32_t h1 = 0, h2 = 0;
5372 * Pick up the channel, but not if this is a ASYNC_RIO32_2,
5373 * where Mailboxes 6/7 have the second handle.
5375 if (mbox != ASYNC_RIO32_2) {
5376 if (IS_DUALBUS(isp)) {
5377 chan = ISP_READ(isp, OUTMAILBOX6);
5380 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
5383 case ASYNC_BUS_RESET:
5384 ISP_SET_SENDMARKER(isp, chan, 1);
5385 #ifdef ISP_TARGET_MODE
5386 if (isp_target_async(isp, chan, mbox)) {
5390 isp_async(isp, ISPASYNC_BUS_RESET, chan);
5392 case ASYNC_SYSTEM_ERROR:
5394 isp->isp_state = ISP_CRASHED;
5396 * Were we waiting for a mailbox command to complete?
5397 * If so, it's dead, so wake up the waiter.
5399 if (isp->isp_mboxbsy) {
5401 isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR;
5402 MBOX_NOTIFY_COMPLETE(isp);
5405 * It's up to the handler for isp_async to reinit stuff and
5406 * restart the firmware
5408 isp_async(isp, ISPASYNC_FW_CRASH);
5412 case ASYNC_RQS_XFER_ERR:
5413 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
5416 case ASYNC_RSP_XFER_ERR:
5417 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
5422 * We've just been notified that the Queue has woken up.
5423 * We don't need to be chatty about this- just unlatch things
5426 mbox = ISP_READ(isp, isp->isp_rqstoutrp);
5429 case ASYNC_TIMEOUT_RESET:
5430 isp_prt(isp, ISP_LOGWARN, "timeout initiated SCSI bus reset of chan %d", chan);
5431 ISP_SET_SENDMARKER(isp, chan, 1);
5432 #ifdef ISP_TARGET_MODE
5433 if (isp_target_async(isp, chan, mbox)) {
5439 case ASYNC_DEVICE_RESET:
5440 isp_prt(isp, ISP_LOGINFO, "device reset on chan %d", chan);
5441 ISP_SET_SENDMARKER(isp, chan, 1);
5442 #ifdef ISP_TARGET_MODE
5443 if (isp_target_async(isp, chan, mbox)) {
5449 case ASYNC_EXTMSG_UNDERRUN:
5450 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
5453 case ASYNC_SCAM_INT:
5454 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
5457 case ASYNC_HUNG_SCSI:
5458 isp_prt(isp, ISP_LOGERR, "stalled SCSI Bus after DATA Overrun");
5459 /* XXX: Need to issue SCSI reset at this point */
5462 case ASYNC_KILLED_BUS:
5463 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
5466 case ASYNC_BUS_TRANSIT:
5467 mbox = ISP_READ(isp, OUTMAILBOX2);
5468 switch (mbox & SXP_PINS_MODE_MASK) {
5469 case SXP_PINS_LVD_MODE:
5470 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
5471 SDPARAM(isp, chan)->isp_diffmode = 0;
5472 SDPARAM(isp, chan)->isp_ultramode = 0;
5473 SDPARAM(isp, chan)->isp_lvdmode = 1;
5475 case SXP_PINS_HVD_MODE:
5476 isp_prt(isp, ISP_LOGINFO,
5477 "Transition to Differential mode");
5478 SDPARAM(isp, chan)->isp_diffmode = 1;
5479 SDPARAM(isp, chan)->isp_ultramode = 0;
5480 SDPARAM(isp, chan)->isp_lvdmode = 0;
5482 case SXP_PINS_SE_MODE:
5483 isp_prt(isp, ISP_LOGINFO,
5484 "Transition to Single Ended mode");
5485 SDPARAM(isp, chan)->isp_diffmode = 0;
5486 SDPARAM(isp, chan)->isp_ultramode = 1;
5487 SDPARAM(isp, chan)->isp_lvdmode = 0;
5490 isp_prt(isp, ISP_LOGWARN,
5491 "Transition to Unknown Mode 0x%x", mbox);
5495 * XXX: Set up to renegotiate again!
5497 /* Can only be for a 1080... */
5498 ISP_SET_SENDMARKER(isp, chan, 1);
5501 case ASYNC_CMD_CMPLT:
5503 if (!IS_ULTRA3(isp)) {
5504 isp_prt(isp, ISP_LOGERR, "unexpected fast posting completion");
5508 h1 = (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1);
5512 h1 = (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1);
5513 h2 = (ISP_READ(isp, OUTMAILBOX7) << 16) | ISP_READ(isp, OUTMAILBOX6);
5521 isp_prt(isp, ISP_LOGERR, "unexpected 16 bit RIO handle");
5524 isp_prt(isp, ISP_LOGWARN, "%s: unhandled async code 0x%x", __func__, mbox);
5529 isp_prt(isp, ISP_LOGDEBUG3, "fast post/rio completion of 0x%08x", h1);
5530 isp_fastpost_complete(isp, h1);
5532 isp_prt(isp, ISP_LOGDEBUG3, "fast post/rio completion of 0x%08x", h2);
5533 isp_fastpost_complete(isp, h2);
5534 if (isp->isp_fpcchiwater < 2) {
5535 isp->isp_fpcchiwater = 2;
5538 if (isp->isp_fpcchiwater < 1) {
5539 isp->isp_fpcchiwater = 1;
5543 isp->isp_intoasync++;
5549 isp_parse_async_fc(ispsoftc_t *isp, uint16_t mbox)
5555 if (IS_DUALBUS(isp)) {
5556 chan = ISP_READ(isp, OUTMAILBOX6);
5560 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
5563 case ASYNC_SYSTEM_ERROR:
5565 isp->isp_state = ISP_CRASHED;
5566 FCPARAM(isp, chan)->isp_loopstate = LOOP_NIL;
5567 isp_change_fw_state(isp, chan, FW_CONFIG_WAIT);
5569 * Were we waiting for a mailbox command to complete?
5570 * If so, it's dead, so wake up the waiter.
5572 if (isp->isp_mboxbsy) {
5574 isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR;
5575 MBOX_NOTIFY_COMPLETE(isp);
5578 * It's up to the handler for isp_async to reinit stuff and
5579 * restart the firmware
5581 isp_async(isp, ISPASYNC_FW_CRASH);
5585 case ASYNC_RQS_XFER_ERR:
5586 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
5589 case ASYNC_RSP_XFER_ERR:
5590 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
5594 #ifdef ISP_TARGET_MODE
5596 isp_prt(isp, ISP_LOGERR, "ATIO Queue Transfer Error");
5600 isp_prt(isp, ISP_LOGERR, "%s: unexpected ASYNC_QWAKEUP code", __func__);
5603 case ASYNC_CMD_CMPLT:
5604 isp_fastpost_complete(isp, (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1));
5605 if (isp->isp_fpcchiwater < 1) {
5606 isp->isp_fpcchiwater = 1;
5610 case ASYNC_RIOZIO_STALL:
5613 case ASYNC_CTIO_DONE:
5614 #ifdef ISP_TARGET_MODE
5615 if (isp_target_async(isp, (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1), mbox)) {
5618 isp->isp_fphccmplt++;
5621 isp_prt(isp, ISP_LOGWARN, "unexpected ASYNC CTIO done");
5624 case ASYNC_LIP_ERROR:
5626 case ASYNC_LIP_OCCURRED:
5629 * These are broadcast events that have to be sent across
5630 * all active channels.
5632 for (chan = 0; chan < isp->isp_nchan; chan++) {
5633 fcp = FCPARAM(isp, chan);
5634 int topo = fcp->isp_topo;
5636 if (fcp->role == ISP_ROLE_NONE) {
5640 fcp->isp_loopstate = LOOP_NIL;
5641 ISP_SET_SENDMARKER(isp, chan, 1);
5642 isp_async(isp, ISPASYNC_LIP, chan);
5643 #ifdef ISP_TARGET_MODE
5644 if (isp_target_async(isp, chan, mbox)) {
5649 * We've had problems with data corruption occuring on
5650 * commands that complete (with no apparent error) after
5651 * we receive a LIP. This has been observed mostly on
5652 * Local Loop topologies. To be safe, let's just mark
5653 * all active initiator commands as dead.
5655 if (topo == TOPO_NL_PORT || topo == TOPO_FL_PORT) {
5657 for (i = j = 0; i < isp->isp_maxcmds; i++) {
5661 hdp = &isp->isp_xflist[i];
5662 if (ISP_H2HT(hdp->handle) != ISP_HANDLE_INITIATOR) {
5666 if (XS_CHANNEL(xs) != chan) {
5670 isp_prt(isp, ISP_LOG_WARN1,
5671 "%d.%d.%jx bus reset set at %s:%u",
5672 XS_CHANNEL(xs), XS_TGT(xs),
5673 (uintmax_t)XS_LUN(xs),
5674 __func__, __LINE__);
5675 XS_SETERR(xs, HBA_BUSRESET);
5678 isp_prt(isp, ISP_LOGERR, lipd, chan, j);
5686 * This is a broadcast event that has to be sent across
5687 * all active channels.
5689 for (chan = 0; chan < isp->isp_nchan; chan++) {
5690 fcp = FCPARAM(isp, chan);
5691 if (fcp->role == ISP_ROLE_NONE)
5693 ISP_SET_SENDMARKER(isp, chan, 1);
5694 isp_async(isp, ISPASYNC_LOOP_UP, chan);
5695 #ifdef ISP_TARGET_MODE
5696 if (isp_target_async(isp, chan, mbox)) {
5703 case ASYNC_LOOP_DOWN:
5705 * This is a broadcast event that has to be sent across
5706 * all active channels.
5708 for (chan = 0; chan < isp->isp_nchan; chan++) {
5709 fcp = FCPARAM(isp, chan);
5710 if (fcp->role == ISP_ROLE_NONE)
5712 ISP_SET_SENDMARKER(isp, chan, 1);
5713 fcp->isp_loopstate = LOOP_NIL;
5714 isp_async(isp, ISPASYNC_LOOP_DOWN, chan);
5715 #ifdef ISP_TARGET_MODE
5716 if (isp_target_async(isp, chan, mbox)) {
5723 case ASYNC_LOOP_RESET:
5725 * This is a broadcast event that has to be sent across
5726 * all active channels.
5728 for (chan = 0; chan < isp->isp_nchan; chan++) {
5729 fcp = FCPARAM(isp, chan);
5730 if (fcp->role == ISP_ROLE_NONE)
5732 ISP_SET_SENDMARKER(isp, chan, 1);
5733 fcp->isp_loopstate = LOOP_NIL;
5734 isp_async(isp, ISPASYNC_LOOP_RESET, chan);
5735 #ifdef ISP_TARGET_MODE
5736 if (isp_target_async(isp, chan, mbox)) {
5743 case ASYNC_PDB_CHANGED:
5745 int echan, nphdl, nlstate, reason;
5747 if (IS_23XX(isp) || IS_24XX(isp)) {
5748 nphdl = ISP_READ(isp, OUTMAILBOX1);
5749 nlstate = ISP_READ(isp, OUTMAILBOX2);
5751 nphdl = nlstate = 0xffff;
5754 reason = ISP_READ(isp, OUTMAILBOX3) >> 8;
5757 if (ISP_CAP_MULTI_ID(isp)) {
5758 chan = ISP_READ(isp, OUTMAILBOX3) & 0xff;
5759 if (chan == 0xff || nphdl == NIL_HANDLE) {
5761 echan = isp->isp_nchan - 1;
5762 } else if (chan >= isp->isp_nchan) {
5770 for (; chan <= echan; chan++) {
5771 fcp = FCPARAM(isp, chan);
5772 if (fcp->role == ISP_ROLE_NONE)
5774 if (fcp->isp_loopstate > LOOP_LTEST_DONE)
5775 fcp->isp_loopstate = LOOP_LTEST_DONE;
5776 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan,
5777 ISPASYNC_CHANGE_PDB, nphdl, nlstate, reason);
5781 case ASYNC_CHANGE_NOTIFY:
5785 portid = ((ISP_READ(isp, OUTMAILBOX1) & 0xff) << 16) |
5786 ISP_READ(isp, OUTMAILBOX2);
5787 if (ISP_CAP_MULTI_ID(isp)) {
5788 chan = ISP_READ(isp, OUTMAILBOX3) & 0xff;
5789 if (chan >= isp->isp_nchan)
5794 fcp = FCPARAM(isp, chan);
5795 if (fcp->role == ISP_ROLE_NONE)
5797 if (fcp->isp_loopstate > LOOP_LSCAN_DONE)
5798 fcp->isp_loopstate = LOOP_LSCAN_DONE;
5799 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan,
5800 ISPASYNC_CHANGE_SNS, portid);
5804 case ASYNC_CONNMODE:
5806 * This only applies to 2100 amd 2200 cards
5808 if (!IS_2200(isp) && !IS_2100(isp)) {
5809 isp_prt(isp, ISP_LOGWARN, "bad card for ASYNC_CONNMODE event");
5813 mbox = ISP_READ(isp, OUTMAILBOX1);
5816 isp_prt(isp, ISP_LOGINFO,
5817 "Point-to-Point -> Loop mode");
5820 isp_prt(isp, ISP_LOGINFO,
5821 "Loop -> Point-to-Point mode");
5823 case ISP_CONN_BADLIP:
5824 isp_prt(isp, ISP_LOGWARN,
5825 "Point-to-Point -> Loop mode (BAD LIP)");
5827 case ISP_CONN_FATAL:
5829 isp->isp_state = ISP_CRASHED;
5830 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
5831 isp_async(isp, ISPASYNC_FW_CRASH);
5833 case ISP_CONN_LOOPBACK:
5834 isp_prt(isp, ISP_LOGWARN,
5835 "Looped Back in Point-to-Point mode");
5838 isp_prt(isp, ISP_LOGWARN,
5839 "Unknown connection mode (0x%x)", mbox);
5842 ISP_SET_SENDMARKER(isp, chan, 1);
5843 FCPARAM(isp, chan)->isp_loopstate = LOOP_NIL;
5844 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan, ISPASYNC_CHANGE_OTHER);
5849 isp_prt(isp, ISP_LOGWARN, "Receive Error");
5851 isp_prt(isp, ISP_LOGWARN, "unexpected ASYNC_RCV_ERR");
5854 case ASYNC_RJT_SENT: /* same as ASYNC_QFULL_SENT */
5856 isp_prt(isp, ISP_LOGTDEBUG0, "LS_RJT sent");
5858 } else if (IS_2200(isp)) {
5859 isp_prt(isp, ISP_LOGTDEBUG0, "QFULL sent");
5864 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
5867 if (mbox != ASYNC_CTIO_DONE && mbox != ASYNC_CMD_CMPLT) {
5868 isp->isp_intoasync++;
5874 * Handle other response entries. A pointer to the request queue output
5875 * index is here in case we want to eat several entries at once, although
5876 * this is not used currently.
5880 isp_handle_other_response(ispsoftc_t *isp, int type, isphdr_t *hp, uint32_t *optrp)
5886 case RQSTYPE_STATUS_CONT:
5887 isp_prt(isp, ISP_LOG_WARN1, "Ignored Continuation Response");
5889 case RQSTYPE_MARKER:
5890 isp_prt(isp, ISP_LOG_WARN1, "Marker Response");
5892 case RQSTYPE_RPT_ID_ACQ:
5893 isp_get_ridacq(isp, (isp_ridacq_t *)hp, &rid);
5894 if (rid.ridacq_format == 0) {
5895 for (chan = 0; chan < isp->isp_nchan; chan++) {
5896 fcparam *fcp = FCPARAM(isp, chan);
5897 if (fcp->role == ISP_ROLE_NONE)
5899 c = (chan == 0) ? 127 : (chan - 1);
5900 if (rid.ridacq_map[c / 16] & (1 << (c % 16))) {
5901 fcp->isp_loopstate = LOOP_NIL;
5902 isp_async(isp, ISPASYNC_CHANGE_NOTIFY,
5903 chan, ISPASYNC_CHANGE_OTHER);
5907 FCPARAM(isp, rid.ridacq_vp_index)->isp_loopstate = LOOP_NIL;
5908 isp_async(isp, ISPASYNC_CHANGE_NOTIFY,
5909 rid.ridacq_vp_index, ISPASYNC_CHANGE_OTHER);
5914 case RQSTYPE_ENABLE_LUN:
5915 case RQSTYPE_MODIFY_LUN:
5916 case RQSTYPE_NOTIFY:
5917 case RQSTYPE_NOTIFY_ACK:
5923 case RQSTYPE_ABTS_RCVD:
5924 case RQSTYPE_ABTS_RSP:
5925 isp->isp_rsltccmplt++; /* count as a response completion */
5926 #ifdef ISP_TARGET_MODE
5927 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
5932 case RQSTYPE_REQUEST:
5935 if (type != isp_get_response_type(isp, hp)) {
5937 * This is questionable- we're just papering over
5938 * something we've seen on SMP linux in target
5939 * mode- we don't really know what's happening
5940 * here that causes us to think we've gotten
5941 * an entry, but that either the entry isn't
5942 * filled out yet or our CPU read data is stale.
5944 isp_prt(isp, ISP_LOGINFO,
5945 "unstable type in response queue");
5948 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
5949 isp_get_response_type(isp, hp));
5955 isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
5957 switch (sp->req_completion_status & 0xff) {
5960 XS_SETERR(xs, HBA_NOERROR);
5964 case RQCS_INCOMPLETE:
5965 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
5966 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "Selection Timeout @ %s:%d", __func__, __LINE__);
5968 XS_SETERR(xs, HBA_SELTIMEOUT);
5969 *rp = XS_XFRLEN(xs);
5973 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Incomplete, state 0x%x", sp->req_state_flags);
5976 case RQCS_DMA_ERROR:
5977 isp_xs_prt(isp, xs, ISP_LOGERR, "DMA Error");
5978 *rp = XS_XFRLEN(xs);
5981 case RQCS_TRANSPORT_ERROR:
5984 ISP_SNPRINTF(buf, sizeof (buf), "states=>");
5985 if (sp->req_state_flags & RQSF_GOT_BUS) {
5986 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
5988 if (sp->req_state_flags & RQSF_GOT_TARGET) {
5989 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
5991 if (sp->req_state_flags & RQSF_SENT_CDB) {
5992 ISP_SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
5994 if (sp->req_state_flags & RQSF_XFRD_DATA) {
5995 ISP_SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
5997 if (sp->req_state_flags & RQSF_GOT_STATUS) {
5998 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
6000 if (sp->req_state_flags & RQSF_GOT_SENSE) {
6001 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
6003 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
6004 ISP_SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
6006 ISP_SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
6007 if (sp->req_status_flags & RQSTF_DISCONNECT) {
6008 ISP_SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
6010 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
6011 ISP_SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
6013 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
6014 ISP_SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
6016 if (sp->req_status_flags & RQSTF_BUS_RESET) {
6017 ISP_SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
6019 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
6020 ISP_SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
6022 if (sp->req_status_flags & RQSTF_ABORTED) {
6023 ISP_SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
6025 if (sp->req_status_flags & RQSTF_TIMEOUT) {
6026 ISP_SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
6028 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
6029 ISP_SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
6031 isp_xs_prt(isp, xs, ISP_LOGERR, "Transport Error: %s", buf);
6032 *rp = XS_XFRLEN(xs);
6035 case RQCS_RESET_OCCURRED:
6038 isp_xs_prt(isp, xs, ISP_LOGWARN, "Bus Reset destroyed command");
6039 for (chan = 0; chan < isp->isp_nchan; chan++) {
6040 FCPARAM(isp, chan)->sendmarker = 1;
6043 XS_SETERR(xs, HBA_BUSRESET);
6045 *rp = XS_XFRLEN(xs);
6049 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Aborted");
6050 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 1);
6052 XS_SETERR(xs, HBA_ABORTED);
6057 isp_xs_prt(isp, xs, ISP_LOGWARN, "Command timed out");
6059 * XXX: Check to see if we logged out of the device.
6062 XS_SETERR(xs, HBA_CMDTIMEOUT);
6066 case RQCS_DATA_OVERRUN:
6067 XS_SET_RESID(xs, sp->req_resid);
6068 isp_xs_prt(isp, xs, ISP_LOGERR, "data overrun (%ld)", (long) XS_GET_RESID(xs));
6070 XS_SETERR(xs, HBA_DATAOVR);
6074 case RQCS_COMMAND_OVERRUN:
6075 isp_xs_prt(isp, xs, ISP_LOGERR, "command overrun");
6078 case RQCS_STATUS_OVERRUN:
6079 isp_xs_prt(isp, xs, ISP_LOGERR, "status overrun");
6082 case RQCS_BAD_MESSAGE:
6083 isp_xs_prt(isp, xs, ISP_LOGERR, "msg not COMMAND COMPLETE after status");
6086 case RQCS_NO_MESSAGE_OUT:
6087 isp_xs_prt(isp, xs, ISP_LOGERR, "No MESSAGE OUT phase after selection");
6090 case RQCS_EXT_ID_FAILED:
6091 isp_xs_prt(isp, xs, ISP_LOGERR, "EXTENDED IDENTIFY failed");
6094 case RQCS_IDE_MSG_FAILED:
6095 isp_xs_prt(isp, xs, ISP_LOGERR, "INITIATOR DETECTED ERROR rejected");
6098 case RQCS_ABORT_MSG_FAILED:
6099 isp_xs_prt(isp, xs, ISP_LOGERR, "ABORT OPERATION rejected");
6102 case RQCS_REJECT_MSG_FAILED:
6103 isp_xs_prt(isp, xs, ISP_LOGERR, "MESSAGE REJECT rejected");
6106 case RQCS_NOP_MSG_FAILED:
6107 isp_xs_prt(isp, xs, ISP_LOGERR, "NOP rejected");
6110 case RQCS_PARITY_ERROR_MSG_FAILED:
6111 isp_xs_prt(isp, xs, ISP_LOGERR, "MESSAGE PARITY ERROR rejected");
6114 case RQCS_DEVICE_RESET_MSG_FAILED:
6115 isp_xs_prt(isp, xs, ISP_LOGWARN, "BUS DEVICE RESET rejected");
6118 case RQCS_ID_MSG_FAILED:
6119 isp_xs_prt(isp, xs, ISP_LOGERR, "IDENTIFY rejected");
6122 case RQCS_UNEXP_BUS_FREE:
6123 isp_xs_prt(isp, xs, ISP_LOGERR, "Unexpected Bus Free");
6126 case RQCS_DATA_UNDERRUN:
6129 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
6130 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
6131 isp_xs_prt(isp, xs, ISP_LOGWARN, bun, XS_XFRLEN(xs), sp->req_resid, (ru_marked)? "marked" : "not marked");
6133 XS_SETERR(xs, HBA_BOTCH);
6138 XS_SET_RESID(xs, sp->req_resid);
6140 XS_SETERR(xs, HBA_NOERROR);
6145 case RQCS_XACT_ERR1:
6146 isp_xs_prt(isp, xs, ISP_LOGERR, "HBA attempted queued transaction with disconnect not set");
6149 case RQCS_XACT_ERR2:
6150 isp_xs_prt(isp, xs, ISP_LOGERR,
6151 "HBA attempted queued transaction to target routine %jx",
6152 (uintmax_t)XS_LUN(xs));
6155 case RQCS_XACT_ERR3:
6156 isp_xs_prt(isp, xs, ISP_LOGERR, "HBA attempted queued cmd when queueing disabled");
6159 case RQCS_BAD_ENTRY:
6160 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
6163 case RQCS_QUEUE_FULL:
6164 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "internal queues full status 0x%x", *XS_STSP(xs));
6167 * If QFULL or some other status byte is set, then this
6168 * isn't an error, per se.
6170 * Unfortunately, some QLogic f/w writers have, in
6171 * some cases, ommitted to *set* status to QFULL.
6174 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
6175 XS_SETERR(xs, HBA_NOERROR);
6180 *XS_STSP(xs) = SCSI_QFULL;
6181 XS_SETERR(xs, HBA_NOERROR);
6184 case RQCS_PHASE_SKIPPED:
6185 isp_xs_prt(isp, xs, ISP_LOGERR, "SCSI phase skipped");
6188 case RQCS_ARQS_FAILED:
6189 isp_xs_prt(isp, xs, ISP_LOGERR, "Auto Request Sense Failed");
6191 XS_SETERR(xs, HBA_ARQFAIL);
6195 case RQCS_WIDE_FAILED:
6196 isp_xs_prt(isp, xs, ISP_LOGERR, "Wide Negotiation Failed");
6198 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
6199 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
6200 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
6204 XS_SETERR(xs, HBA_NOERROR);
6208 case RQCS_SYNCXFER_FAILED:
6209 isp_xs_prt(isp, xs, ISP_LOGERR, "SDTR Message Failed");
6211 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
6212 sdp += XS_CHANNEL(xs);
6213 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
6214 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
6219 case RQCS_LVD_BUSERR:
6220 isp_xs_prt(isp, xs, ISP_LOGERR, "Bad LVD condition");
6223 case RQCS_PORT_UNAVAILABLE:
6225 * No such port on the loop. Moral equivalent of SELTIMEO
6227 case RQCS_PORT_LOGGED_OUT:
6230 uint8_t sts = sp->req_completion_status & 0xff;
6233 * It was there (maybe)- treat as a selection timeout.
6235 if (sts == RQCS_PORT_UNAVAILABLE) {
6236 reason = "unavailable";
6241 isp_prt(isp, ISP_LOGINFO, "port %s for target %d", reason, XS_TGT(xs));
6244 * If we're on a local loop, force a LIP (which is overkill)
6245 * to force a re-login of this unit. If we're on fabric,
6246 * then we'll have to log in again as a matter of course.
6248 if (FCPARAM(isp, 0)->isp_topo == TOPO_NL_PORT ||
6249 FCPARAM(isp, 0)->isp_topo == TOPO_FL_PORT) {
6251 MBSINIT(&mbs, MBOX_INIT_LIP, MBLOGALL, 0);
6252 if (ISP_CAP_2KLOGIN(isp)) {
6253 mbs.ibits = (1 << 10);
6255 isp_mboxcmd_qnw(isp, &mbs, 1);
6258 XS_SETERR(xs, HBA_SELTIMEOUT);
6262 case RQCS_PORT_CHANGED:
6263 isp_prt(isp, ISP_LOGWARN, "port changed for target %d", XS_TGT(xs));
6265 XS_SETERR(xs, HBA_SELTIMEOUT);
6269 case RQCS_PORT_BUSY:
6270 isp_prt(isp, ISP_LOGWARN, "port busy for target %d", XS_TGT(xs));
6272 XS_SETERR(xs, HBA_TGTBSY);
6277 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x", sp->req_completion_status);
6281 XS_SETERR(xs, HBA_BOTCH);
6286 isp_parse_status_24xx(ispsoftc_t *isp, isp24xx_statusreq_t *sp, XS_T *xs, long *rp)
6288 int ru_marked, sv_marked;
6289 int chan = XS_CHANNEL(xs);
6291 switch (sp->req_completion_status) {
6294 XS_SETERR(xs, HBA_NOERROR);
6298 case RQCS_DMA_ERROR:
6299 isp_xs_prt(isp, xs, ISP_LOGERR, "DMA error");
6302 case RQCS_TRANSPORT_ERROR:
6303 isp_xs_prt(isp, xs, ISP_LOGERR, "Transport Error");
6306 case RQCS_RESET_OCCURRED:
6307 isp_xs_prt(isp, xs, ISP_LOGWARN, "reset destroyed command");
6308 FCPARAM(isp, chan)->sendmarker = 1;
6310 XS_SETERR(xs, HBA_BUSRESET);
6315 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Aborted");
6316 FCPARAM(isp, chan)->sendmarker = 1;
6318 XS_SETERR(xs, HBA_ABORTED);
6323 isp_xs_prt(isp, xs, ISP_LOGWARN, "Command Timed Out");
6325 XS_SETERR(xs, HBA_CMDTIMEOUT);
6329 case RQCS_DATA_OVERRUN:
6330 XS_SET_RESID(xs, sp->req_resid);
6331 isp_xs_prt(isp, xs, ISP_LOGERR, "Data Overrun");
6333 XS_SETERR(xs, HBA_DATAOVR);
6337 case RQCS_24XX_DRE: /* data reassembly error */
6338 isp_prt(isp, ISP_LOGERR, "Chan %d data reassembly error for target %d", chan, XS_TGT(xs));
6340 XS_SETERR(xs, HBA_ABORTED);
6342 *rp = XS_XFRLEN(xs);
6345 case RQCS_24XX_TABORT: /* aborted by target */
6346 isp_prt(isp, ISP_LOGERR, "Chan %d target %d sent ABTS", chan, XS_TGT(xs));
6348 XS_SETERR(xs, HBA_ABORTED);
6352 case RQCS_DATA_UNDERRUN:
6353 ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
6355 * We can get an underrun w/o things being marked
6356 * if we got a non-zero status.
6358 sv_marked = (sp->req_scsi_status & (RQCS_SV|RQCS_RV)) != 0;
6359 if ((ru_marked == 0 && sv_marked == 0) ||
6360 (sp->req_resid > XS_XFRLEN(xs))) {
6361 isp_xs_prt(isp, xs, ISP_LOGWARN, bun, XS_XFRLEN(xs), sp->req_resid, (ru_marked)? "marked" : "not marked");
6363 XS_SETERR(xs, HBA_BOTCH);
6367 XS_SET_RESID(xs, sp->req_resid);
6368 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "Data Underrun (%d) for command 0x%x", sp->req_resid, XS_CDBP(xs)[0] & 0xff);
6370 XS_SETERR(xs, HBA_NOERROR);
6374 case RQCS_PORT_UNAVAILABLE:
6376 * No such port on the loop. Moral equivalent of SELTIMEO
6378 case RQCS_PORT_LOGGED_OUT:
6381 uint8_t sts = sp->req_completion_status & 0xff;
6384 * It was there (maybe)- treat as a selection timeout.
6386 if (sts == RQCS_PORT_UNAVAILABLE) {
6387 reason = "unavailable";
6392 isp_prt(isp, ISP_LOGINFO, "Chan %d port %s for target %d",
6393 chan, reason, XS_TGT(xs));
6396 * There is no MBOX_INIT_LIP for the 24XX.
6399 XS_SETERR(xs, HBA_SELTIMEOUT);
6403 case RQCS_PORT_CHANGED:
6404 isp_prt(isp, ISP_LOGWARN, "port changed for target %d chan %d", XS_TGT(xs), chan);
6406 XS_SETERR(xs, HBA_SELTIMEOUT);
6411 case RQCS_24XX_ENOMEM: /* f/w resource unavailable */
6412 isp_prt(isp, ISP_LOGWARN, "f/w resource unavailable for target %d chan %d", XS_TGT(xs), chan);
6414 *XS_STSP(xs) = SCSI_BUSY;
6415 XS_SETERR(xs, HBA_TGTBSY);
6419 case RQCS_24XX_TMO: /* task management overrun */
6420 isp_prt(isp, ISP_LOGWARN, "command for target %d overlapped task management for chan %d", XS_TGT(xs), chan);
6422 *XS_STSP(xs) = SCSI_BUSY;
6423 XS_SETERR(xs, HBA_TGTBSY);
6428 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x on chan %d", sp->req_completion_status, chan);
6432 XS_SETERR(xs, HBA_BOTCH);
6437 isp_fastpost_complete(ispsoftc_t *isp, uint32_t fph)
6444 xs = isp_find_xs(isp, fph);
6446 isp_prt(isp, ISP_LOGWARN,
6447 "Command for fast post handle 0x%x not found", fph);
6450 isp_destroy_handle(isp, fph);
6453 * Since we don't have a result queue entry item,
6454 * we must believe that SCSI status is zero and
6455 * that all data transferred.
6457 XS_SET_RESID(xs, 0);
6458 *XS_STSP(xs) = SCSI_GOOD;
6459 if (XS_XFRLEN(xs)) {
6460 ISP_DMAFREE(isp, xs, fph);
6462 if (isp->isp_nactive) {
6465 isp->isp_fphccmplt++;
6470 isp_mbox_continue(ispsoftc_t *isp)
6476 switch (isp->isp_lastmbxcmd) {
6477 case MBOX_WRITE_RAM_WORD:
6478 case MBOX_READ_RAM_WORD:
6479 case MBOX_WRITE_RAM_WORD_EXTENDED:
6480 case MBOX_READ_RAM_WORD_EXTENDED:
6485 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
6486 isp->isp_mbxwrk0 = 0;
6491 * Clear the previous interrupt.
6494 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
6496 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
6497 ISP_WRITE(isp, BIU_SEMA, 0);
6501 * Continue with next word.
6503 ISP_MEMZERO(&mbs, sizeof (mbs));
6504 ptr = isp->isp_mbxworkp;
6505 switch (isp->isp_lastmbxcmd) {
6506 case MBOX_WRITE_RAM_WORD:
6507 mbs.param[1] = isp->isp_mbxwrk1++;
6508 mbs.param[2] = *ptr++;
6510 case MBOX_READ_RAM_WORD:
6511 *ptr++ = isp->isp_mboxtmp[2];
6512 mbs.param[1] = isp->isp_mbxwrk1++;
6514 case MBOX_WRITE_RAM_WORD_EXTENDED:
6516 uint32_t *lptr = (uint32_t *)ptr;
6517 mbs.param[2] = lptr[0];
6518 mbs.param[3] = lptr[0] >> 16;
6520 ptr = (uint16_t *)lptr;
6522 mbs.param[2] = *ptr++;
6524 offset = isp->isp_mbxwrk1;
6525 offset |= isp->isp_mbxwrk8 << 16;
6526 mbs.param[1] = offset;
6527 mbs.param[8] = offset >> 16;
6529 isp->isp_mbxwrk1 = offset;
6530 isp->isp_mbxwrk8 = offset >> 16;
6532 case MBOX_READ_RAM_WORD_EXTENDED:
6534 uint32_t *lptr = (uint32_t *)ptr;
6535 uint32_t val = isp->isp_mboxtmp[2];
6536 val |= (isp->isp_mboxtmp[3]) << 16;
6538 ptr = (uint16_t *)lptr;
6540 *ptr++ = isp->isp_mboxtmp[2];
6542 offset = isp->isp_mbxwrk1;
6543 offset |= isp->isp_mbxwrk8 << 16;
6544 mbs.param[1] = offset;
6545 mbs.param[8] = offset >> 16;
6547 isp->isp_mbxwrk1 = offset;
6548 isp->isp_mbxwrk8 = offset >> 16;
6551 isp->isp_mbxworkp = ptr;
6553 mbs.param[0] = isp->isp_lastmbxcmd;
6554 mbs.logval = MBLOGALL;
6555 isp_mboxcmd_qnw(isp, &mbs, 0);
6559 #define ISP_SCSI_IBITS(op) (mbpscsi[((op)<<1)])
6560 #define ISP_SCSI_OBITS(op) (mbpscsi[((op)<<1) + 1])
6561 #define ISP_SCSI_OPMAP(in, out) in, out
6562 static const uint8_t mbpscsi[] = {
6563 ISP_SCSI_OPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
6564 ISP_SCSI_OPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
6565 ISP_SCSI_OPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
6566 ISP_SCSI_OPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
6567 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
6568 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
6569 ISP_SCSI_OPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
6570 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
6571 ISP_SCSI_OPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
6572 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x09: */
6573 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0a: */
6574 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0b: */
6575 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0c: */
6576 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0d: */
6577 ISP_SCSI_OPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
6578 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0f: */
6579 ISP_SCSI_OPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
6580 ISP_SCSI_OPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
6581 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
6582 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
6583 ISP_SCSI_OPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
6584 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
6585 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
6586 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
6587 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
6588 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
6589 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
6590 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
6591 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
6592 ISP_SCSI_OPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
6593 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x1e: */
6594 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
6595 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
6596 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
6597 ISP_SCSI_OPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
6598 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
6599 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
6600 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
6601 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
6602 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
6603 ISP_SCSI_OPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
6604 ISP_SCSI_OPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
6605 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
6606 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2b: */
6607 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2c: */
6608 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2d: */
6609 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2e: */
6610 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2f: */
6611 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
6612 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
6613 ISP_SCSI_OPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
6614 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
6615 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
6616 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
6617 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
6618 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
6619 ISP_SCSI_OPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
6620 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
6621 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
6622 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3b: */
6623 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3c: */
6624 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3d: */
6625 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3e: */
6626 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3f: */
6627 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
6628 ISP_SCSI_OPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
6629 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
6630 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x43: */
6631 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x44: */
6632 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
6633 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
6634 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x47: */
6635 ISP_SCSI_OPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
6636 ISP_SCSI_OPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
6637 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
6638 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
6639 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4c: */
6640 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4d: */
6641 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4e: */
6642 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4f: */
6643 ISP_SCSI_OPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
6644 ISP_SCSI_OPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
6645 ISP_SCSI_OPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
6646 ISP_SCSI_OPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
6647 ISP_SCSI_OPMAP(0xcf, 0x01), /* 0x54: EXECUCUTE COMMAND IOCB A64 */
6648 ISP_SCSI_OPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
6649 ISP_SCSI_OPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
6650 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x57: */
6651 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x58: */
6652 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x59: */
6653 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
6654 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
6655 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
6656 ISP_SCSI_OPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
6658 #define MAX_SCSI_OPCODE 0x5d
6660 static const char *scsi_mbcmd_names[] = {
6677 "INIT REQUEST QUEUE",
6678 "INIT RESULT QUEUE",
6688 "SINGLE STEP QUEUE",
6690 "GET DEV QUEUE STATUS",
6692 "GET FIRMWARE STATUS",
6694 "GET SELECT TIMEOUT",
6696 "GET TAG AGE LIMIT",
6698 "GET ACT NEG STATE",
6699 "GET ASYNC DATA SETUP TIME",
6701 "GET TARGET PARAMS",
6702 "GET DEV QUEUE PARAMS",
6703 "GET RESET DELAY PARAMS",
6710 "SET SELECT TIMEOUT",
6712 "SET TAG AGE LIMIT",
6714 "SET ACT NEG STATE",
6715 "SET ASYNC DATA SETUP TIME",
6716 "SET PCI CONTROL PARAMS",
6717 "SET TARGET PARAMS",
6718 "SET DEV QUEUE PARAMS",
6719 "SET RESET DELAY PARAMS",
6725 "RETURN BIOS BLOCK ADDR",
6726 "WRITE FOUR RAM WORDS",
6730 "SET SYSTEM PARAMETER",
6731 "GET SYSTEM PARAMETER",
6733 "GET SCAM CONFIGURATION",
6734 "SET SCAM CONFIGURATION",
6735 "SET FIRMWARE FEATURES",
6736 "GET FIRMWARE FEATURES",
6743 "INITIALIZE REQUEST QUEUE A64",
6744 "INITIALIZE RESPONSE QUEUE A64",
6746 "ENABLE TARGET MODE",
6747 "GET TARGET MODE STATE",
6751 "SET DATA OVERRUN RECOVERY MODE",
6752 "GET DATA OVERRUN RECOVERY MODE",
6757 #define ISP_FC_IBITS(op) ((mbpfc[((op)<<3) + 0] << 24) | (mbpfc[((op)<<3) + 1] << 16) | (mbpfc[((op)<<3) + 2] << 8) | (mbpfc[((op)<<3) + 3]))
6758 #define ISP_FC_OBITS(op) ((mbpfc[((op)<<3) + 4] << 24) | (mbpfc[((op)<<3) + 5] << 16) | (mbpfc[((op)<<3) + 6] << 8) | (mbpfc[((op)<<3) + 7]))
6760 #define ISP_FC_OPMAP(in0, out0) 0, 0, 0, in0, 0, 0, 0, out0
6761 #define ISP_FC_OPMAP_HALF(in1, in0, out1, out0) 0, 0, in1, in0, 0, 0, out1, out0
6762 #define ISP_FC_OPMAP_FULL(in3, in2, in1, in0, out3, out2, out1, out0) in3, in2, in1, in0, out3, out2, out1, out0
6763 static const uint32_t mbpfc[] = {
6764 ISP_FC_OPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
6765 ISP_FC_OPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
6766 ISP_FC_OPMAP(0x0f, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
6767 ISP_FC_OPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
6768 ISP_FC_OPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
6769 ISP_FC_OPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
6770 ISP_FC_OPMAP_FULL(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
6771 ISP_FC_OPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
6772 ISP_FC_OPMAP_FULL(0x0, 0x0, 0x0, 0x01, 0x0, 0x3, 0x80, 0x7f), /* 0x08: MBOX_ABOUT_FIRMWARE */
6773 ISP_FC_OPMAP(0xdf, 0x01), /* 0x09: MBOX_LOAD_RISC_RAM_2100 */
6774 ISP_FC_OPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
6775 ISP_FC_OPMAP_HALF(0x1, 0xff, 0x0, 0x01), /* 0x0b: MBOX_LOAD_RISC_RAM */
6776 ISP_FC_OPMAP(0x00, 0x00), /* 0x0c: */
6777 ISP_FC_OPMAP_HALF(0x1, 0x0f, 0x0, 0x01), /* 0x0d: MBOX_WRITE_RAM_WORD_EXTENDED */
6778 ISP_FC_OPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
6779 ISP_FC_OPMAP_HALF(0x1, 0x03, 0x0, 0x0d), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED */
6780 ISP_FC_OPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
6781 ISP_FC_OPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
6782 ISP_FC_OPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
6783 ISP_FC_OPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
6784 ISP_FC_OPMAP(0x01, 0xff), /* 0x14: MBOX_STOP_FIRMWARE */
6785 ISP_FC_OPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
6786 ISP_FC_OPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
6787 ISP_FC_OPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
6788 ISP_FC_OPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
6789 ISP_FC_OPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
6790 ISP_FC_OPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
6791 ISP_FC_OPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
6792 ISP_FC_OPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
6793 ISP_FC_OPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
6794 ISP_FC_OPMAP(0x00, 0x00), /* 0x1e: */
6795 ISP_FC_OPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
6796 ISP_FC_OPMAP_HALF(0x2, 0x01, 0x7e, 0xcf), /* 0x20: MBOX_GET_LOOP_ID */
6797 ISP_FC_OPMAP(0x00, 0x00), /* 0x21: */
6798 ISP_FC_OPMAP(0x01, 0x07), /* 0x22: MBOX_GET_RETRY_COUNT */
6799 ISP_FC_OPMAP(0x00, 0x00), /* 0x23: */
6800 ISP_FC_OPMAP(0x00, 0x00), /* 0x24: */
6801 ISP_FC_OPMAP(0x00, 0x00), /* 0x25: */
6802 ISP_FC_OPMAP(0x00, 0x00), /* 0x26: */
6803 ISP_FC_OPMAP(0x00, 0x00), /* 0x27: */
6804 ISP_FC_OPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
6805 ISP_FC_OPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
6806 ISP_FC_OPMAP(0x00, 0x00), /* 0x2a: */
6807 ISP_FC_OPMAP(0x00, 0x00), /* 0x2b: */
6808 ISP_FC_OPMAP(0x00, 0x00), /* 0x2c: */
6809 ISP_FC_OPMAP(0x00, 0x00), /* 0x2d: */
6810 ISP_FC_OPMAP(0x00, 0x00), /* 0x2e: */
6811 ISP_FC_OPMAP(0x00, 0x00), /* 0x2f: */
6812 ISP_FC_OPMAP(0x00, 0x00), /* 0x30: */
6813 ISP_FC_OPMAP(0x00, 0x00), /* 0x31: */
6814 ISP_FC_OPMAP(0x07, 0x07), /* 0x32: MBOX_SET_RETRY_COUNT */
6815 ISP_FC_OPMAP(0x00, 0x00), /* 0x33: */
6816 ISP_FC_OPMAP(0x00, 0x00), /* 0x34: */
6817 ISP_FC_OPMAP(0x00, 0x00), /* 0x35: */
6818 ISP_FC_OPMAP(0x00, 0x00), /* 0x36: */
6819 ISP_FC_OPMAP(0x00, 0x00), /* 0x37: */
6820 ISP_FC_OPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
6821 ISP_FC_OPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
6822 ISP_FC_OPMAP(0x00, 0x00), /* 0x3a: */
6823 ISP_FC_OPMAP(0x00, 0x00), /* 0x3b: */
6824 ISP_FC_OPMAP(0x00, 0x00), /* 0x3c: */
6825 ISP_FC_OPMAP(0x00, 0x00), /* 0x3d: */
6826 ISP_FC_OPMAP(0x00, 0x00), /* 0x3e: */
6827 ISP_FC_OPMAP(0x00, 0x00), /* 0x3f: */
6828 ISP_FC_OPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
6829 ISP_FC_OPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
6830 ISP_FC_OPMAP_HALF(0x0, 0x01, 0x3, 0xcf), /* 0x42: MBOX_GET_RESOURCE_COUNT */
6831 ISP_FC_OPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_OFFLINE_MODE */
6832 ISP_FC_OPMAP(0x00, 0x00), /* 0x44: */
6833 ISP_FC_OPMAP(0x00, 0x00), /* 0x45: */
6834 ISP_FC_OPMAP(0x00, 0x00), /* 0x46: */
6835 ISP_FC_OPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
6836 ISP_FC_OPMAP(0xcf, 0x0f), /* 0x48: MBOX_INIT_FIRMWARE_MULTI_ID */
6837 ISP_FC_OPMAP(0xcd, 0x01), /* 0x49: MBOX_GET_VP_DATABASE */
6838 ISP_FC_OPMAP_HALF(0x2, 0xcd, 0x0, 0x01), /* 0x4a: MBOX_GET_VP_DATABASE_ENTRY */
6839 ISP_FC_OPMAP(0x00, 0x00), /* 0x4b: */
6840 ISP_FC_OPMAP(0x00, 0x00), /* 0x4c: */
6841 ISP_FC_OPMAP(0x00, 0x00), /* 0x4d: */
6842 ISP_FC_OPMAP(0x00, 0x00), /* 0x4e: */
6843 ISP_FC_OPMAP(0x00, 0x00), /* 0x4f: */
6844 ISP_FC_OPMAP(0x00, 0x00), /* 0x50: */
6845 ISP_FC_OPMAP(0x00, 0x00), /* 0x51: */
6846 ISP_FC_OPMAP(0x00, 0x00), /* 0x52: */
6847 ISP_FC_OPMAP(0x00, 0x00), /* 0x53: */
6848 ISP_FC_OPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
6849 ISP_FC_OPMAP(0x00, 0x00), /* 0x55: */
6850 ISP_FC_OPMAP(0x00, 0x00), /* 0x56: */
6851 ISP_FC_OPMAP(0x00, 0x00), /* 0x57: */
6852 ISP_FC_OPMAP(0x00, 0x00), /* 0x58: */
6853 ISP_FC_OPMAP(0x00, 0x00), /* 0x59: */
6854 ISP_FC_OPMAP(0x00, 0x00), /* 0x5a: */
6855 ISP_FC_OPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
6856 ISP_FC_OPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
6857 ISP_FC_OPMAP(0x07, 0x1f), /* 0x5d: MBOX_GET_SET_DATA_RATE */
6858 ISP_FC_OPMAP(0x00, 0x00), /* 0x5e: */
6859 ISP_FC_OPMAP(0x00, 0x00), /* 0x5f: */
6860 ISP_FC_OPMAP(0xcf, 0x0f), /* 0x60: MBOX_INIT_FIRMWARE */
6861 ISP_FC_OPMAP(0x00, 0x00), /* 0x61: */
6862 ISP_FC_OPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
6863 ISP_FC_OPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
6864 ISP_FC_OPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
6865 ISP_FC_OPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
6866 ISP_FC_OPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
6867 ISP_FC_OPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
6868 ISP_FC_OPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
6869 ISP_FC_OPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
6870 ISP_FC_OPMAP_HALF(0x6, 0x03, 0x0, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
6871 ISP_FC_OPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
6872 ISP_FC_OPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
6873 ISP_FC_OPMAP(0x00, 0x00), /* 0x6d: */
6874 ISP_FC_OPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
6875 ISP_FC_OPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
6876 ISP_FC_OPMAP(0x03, 0x01), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
6877 ISP_FC_OPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
6878 ISP_FC_OPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
6879 ISP_FC_OPMAP(0x00, 0x00), /* 0x73: */
6880 ISP_FC_OPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
6881 ISP_FC_OPMAP_HALF(0x03, 0xcf, 0x00, 0x07), /* 0x75: GET PORT/NODE NAME LIST */
6882 ISP_FC_OPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
6883 ISP_FC_OPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
6884 ISP_FC_OPMAP(0x00, 0x00), /* 0x78: */
6885 ISP_FC_OPMAP(0x00, 0x00), /* 0x79: */
6886 ISP_FC_OPMAP(0x00, 0x00), /* 0x7a: */
6887 ISP_FC_OPMAP(0x00, 0x00), /* 0x7b: */
6888 ISP_FC_OPMAP_HALF(0x03, 0x4f, 0x00, 0x07), /* 0x7c: Get ID List */
6889 ISP_FC_OPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
6890 ISP_FC_OPMAP(0x0f, 0x01) /* 0x7e: LUN RESET */
6892 #define MAX_FC_OPCODE 0x7e
6896 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
6897 * do not access at this time in the core driver. The caller is
6898 * responsible for setting this register first (Gross!). The assumption
6899 * is that we won't overflow.
6902 static const char *fc_mbcmd_names[] = {
6916 "WRITE RAM WORD EXTENDED",
6918 "READ RAM WORD EXTENDED",
6919 "INIT REQUEST QUEUE",
6920 "INIT RESULT QUEUE",
6930 "SINGLE STEP QUEUE",
6932 "GET DEV QUEUE STATUS",
6934 "GET FIRMWARE STATUS",
6943 "GET FIRMWARE OPTIONS",
6944 "GET PORT QUEUE PARAMS",
6959 "SET FIRMWARE OPTIONS",
6960 "SET PORT QUEUE PARAMS",
6969 "GET RESOURCE COUNT",
6970 "REQUEST NON PARTICIPATING MODE",
6974 "GET PORT DATABASE ENHANCED",
6975 "INIT FIRMWARE MULTI ID",
6977 "GET VP DATABASE ENTRY",
6996 "GET/SET DATA RATE",
7002 "GET FC-AL POSITION MAP",
7003 "GET PORT DATABASE",
7015 "SEND CHANGE REQUEST",
7020 "GET PORT/NODE NAME LIST",
7022 "INITIALIZE IP MAILBOX",
7033 isp_mboxcmd_qnw(ispsoftc_t *isp, mbreg_t *mbp, int nodelay)
7035 unsigned int ibits, obits, box, opcode;
7037 opcode = mbp->param[0];
7039 ibits = ISP_FC_IBITS(opcode);
7040 obits = ISP_FC_OBITS(opcode);
7042 ibits = ISP_SCSI_IBITS(opcode);
7043 obits = ISP_SCSI_OBITS(opcode);
7045 ibits |= mbp->ibits;
7046 obits |= mbp->obits;
7047 for (box = 0; box < ISP_NMBOX(isp); box++) {
7048 if (ibits & (1 << box)) {
7049 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
7052 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
7056 isp->isp_lastmbxcmd = opcode;
7057 isp->isp_obits = obits;
7058 isp->isp_mboxbsy = 1;
7061 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_SET_HOST_INT);
7063 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
7066 * Oddly enough, if we're not delaying for an answer,
7067 * delay a bit to give the f/w a chance to pick up the
7076 isp_mboxcmd(ispsoftc_t *isp, mbreg_t *mbp)
7078 const char *cname, *xname, *sname;
7079 char tname[16], mname[16];
7080 unsigned int ibits, obits, box, opcode;
7082 opcode = mbp->param[0];
7084 if (opcode > MAX_FC_OPCODE) {
7085 mbp->param[0] = MBOX_INVALID_COMMAND;
7086 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
7089 cname = fc_mbcmd_names[opcode];
7090 ibits = ISP_FC_IBITS(opcode);
7091 obits = ISP_FC_OBITS(opcode);
7093 if (opcode > MAX_SCSI_OPCODE) {
7094 mbp->param[0] = MBOX_INVALID_COMMAND;
7095 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
7098 cname = scsi_mbcmd_names[opcode];
7099 ibits = ISP_SCSI_IBITS(opcode);
7100 obits = ISP_SCSI_OBITS(opcode);
7102 if (cname == NULL) {
7104 ISP_SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
7106 isp_prt(isp, ISP_LOGDEBUG3, "Mailbox Command '%s'", cname);
7109 * Pick up any additional bits that the caller might have set.
7111 ibits |= mbp->ibits;
7112 obits |= mbp->obits;
7115 * Mask any bits that the caller wants us to mask
7117 ibits &= mbp->ibitm;
7118 obits &= mbp->obitm;
7121 if (ibits == 0 && obits == 0) {
7122 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
7123 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
7128 * Get exclusive usage of mailbox registers.
7130 if (MBOX_ACQUIRE(isp)) {
7131 mbp->param[0] = MBOX_REGS_BUSY;
7135 for (box = 0; box < ISP_NMBOX(isp); box++) {
7136 if (ibits & (1 << box)) {
7137 isp_prt(isp, ISP_LOGDEBUG3, "IN mbox %d = 0x%04x", box,
7139 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
7141 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
7144 isp->isp_lastmbxcmd = opcode;
7147 * We assume that we can't overwrite a previous command.
7149 isp->isp_obits = obits;
7150 isp->isp_mboxbsy = 1;
7153 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
7156 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_SET_HOST_INT);
7158 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
7162 * While we haven't finished the command, spin our wheels here.
7164 MBOX_WAIT_COMPLETE(isp, mbp);
7167 * Did the command time out?
7169 if (mbp->param[0] == MBOX_TIMEOUT) {
7170 isp->isp_mboxbsy = 0;
7176 * Copy back output registers.
7178 for (box = 0; box < ISP_NMBOX(isp); box++) {
7179 if (obits & (1 << box)) {
7180 mbp->param[box] = isp->isp_mboxtmp[box];
7181 isp_prt(isp, ISP_LOGDEBUG3, "OUT mbox %d = 0x%04x", box,
7186 isp->isp_mboxbsy = 0;
7189 if (mbp->logval == 0 || mbp->param[0] == MBOX_COMMAND_COMPLETE)
7192 if ((mbp->param[0] & 0xbfe0) == 0 &&
7193 (mbp->logval & MBLOGMASK(mbp->param[0])) == 0)
7198 switch (mbp->param[0]) {
7199 case MBOX_INVALID_COMMAND:
7200 xname = "INVALID COMMAND";
7202 case MBOX_HOST_INTERFACE_ERROR:
7203 xname = "HOST INTERFACE ERROR";
7205 case MBOX_TEST_FAILED:
7206 xname = "TEST FAILED";
7208 case MBOX_COMMAND_ERROR:
7209 xname = "COMMAND ERROR";
7210 ISP_SNPRINTF(mname, sizeof(mname), " subcode 0x%x",
7214 case MBOX_COMMAND_PARAM_ERROR:
7215 xname = "COMMAND PARAMETER ERROR";
7217 case MBOX_PORT_ID_USED:
7218 xname = "PORT ID ALREADY IN USE";
7220 case MBOX_LOOP_ID_USED:
7221 xname = "LOOP ID ALREADY IN USE";
7223 case MBOX_ALL_IDS_USED:
7224 xname = "ALL LOOP IDS IN USE";
7226 case MBOX_NOT_LOGGED_IN:
7227 xname = "NOT LOGGED IN";
7229 case MBOX_LINK_DOWN_ERROR:
7230 xname = "LINK DOWN ERROR";
7232 case MBOX_LOOPBACK_ERROR:
7233 xname = "LOOPBACK ERROR";
7235 case MBOX_CHECKSUM_ERROR:
7236 xname = "CHECKSUM ERROR";
7238 case MBOX_INVALID_PRODUCT_KEY:
7239 xname = "INVALID PRODUCT KEY";
7241 case MBOX_REGS_BUSY:
7242 xname = "REGISTERS BUSY";
7248 ISP_SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
7253 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s%s)",
7254 cname, xname, sname);
7259 isp_fw_state(ispsoftc_t *isp, int chan)
7264 MBSINIT(&mbs, MBOX_GET_FW_STATE, MBLOGALL, 0);
7265 isp_mboxcmd(isp, &mbs);
7266 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
7267 return (mbs.param[1]);
7274 isp_spi_update(ispsoftc_t *isp, int chan)
7282 * There are no 'per-bus' settings for Fibre Channel.
7286 sdp = SDPARAM(isp, chan);
7289 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7290 uint16_t flags, period, offset;
7293 if (sdp->isp_devparam[tgt].dev_enable == 0) {
7294 sdp->isp_devparam[tgt].dev_update = 0;
7295 sdp->isp_devparam[tgt].dev_refresh = 0;
7296 isp_prt(isp, ISP_LOGDEBUG0, "skipping target %d bus %d update", tgt, chan);
7300 * If the goal is to update the status of the device,
7301 * take what's in goal_flags and try and set the device
7302 * toward that. Otherwise, if we're just refreshing the
7303 * current device state, get the current parameters.
7306 MBSINIT(&mbs, 0, MBLOGALL, 0);
7309 * Refresh overrides set
7311 if (sdp->isp_devparam[tgt].dev_refresh) {
7312 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
7314 } else if (sdp->isp_devparam[tgt].dev_update) {
7315 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
7318 * Make sure goal_flags has "Renegotiate on Error"
7319 * on and "Freeze Queue on Error" off.
7321 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
7322 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
7323 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
7326 * Insist that PARITY must be enabled
7327 * if SYNC or WIDE is enabled.
7329 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
7330 mbs.param[2] |= DPARM_PARITY;
7333 if (mbs.param[2] & DPARM_SYNC) {
7335 (sdp->isp_devparam[tgt].goal_offset << 8) |
7336 (sdp->isp_devparam[tgt].goal_period);
7339 * A command completion later that has
7340 * RQSTF_NEGOTIATION set can cause
7341 * the dev_refresh/announce cycle also.
7343 * Note: It is really important to update our current
7344 * flags with at least the state of TAG capabilities-
7345 * otherwise we might try and send a tagged command
7346 * when we have it all turned off. So change it here
7347 * to say that current already matches goal.
7349 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
7350 sdp->isp_devparam[tgt].actv_flags |=
7351 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
7352 isp_prt(isp, ISP_LOGDEBUG0, "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
7353 chan, tgt, mbs.param[2], mbs.param[3] >> 8, mbs.param[3] & 0xff);
7358 mbs.param[1] = (chan << 15) | (tgt << 8);
7359 isp_mboxcmd(isp, &mbs);
7360 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7364 sdp->sendmarker = 1;
7365 sdp->isp_devparam[tgt].dev_update = 0;
7366 sdp->isp_devparam[tgt].dev_refresh = 1;
7368 sdp->isp_devparam[tgt].dev_refresh = 0;
7369 flags = mbs.param[2];
7370 period = mbs.param[3] & 0xff;
7371 offset = mbs.param[3] >> 8;
7372 sdp->isp_devparam[tgt].actv_flags = flags;
7373 sdp->isp_devparam[tgt].actv_period = period;
7374 sdp->isp_devparam[tgt].actv_offset = offset;
7375 isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, chan, tgt);
7379 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7380 if (sdp->isp_devparam[tgt].dev_update ||
7381 sdp->isp_devparam[tgt].dev_refresh) {
7389 isp_setdfltsdparm(ispsoftc_t *isp)
7392 sdparam *sdp, *sdp1;
7394 sdp = SDPARAM(isp, 0);
7395 sdp->role = GET_DEFAULT_ROLE(isp, 0);
7396 if (IS_DUALBUS(isp)) {
7398 sdp1->role = GET_DEFAULT_ROLE(isp, 1);
7404 * Establish some default parameters.
7406 sdp->isp_cmd_dma_burst_enable = 0;
7407 sdp->isp_data_dma_burst_enabl = 1;
7408 sdp->isp_fifo_threshold = 0;
7409 sdp->isp_initiator_id = DEFAULT_IID(isp, 0);
7410 if (isp->isp_type >= ISP_HA_SCSI_1040) {
7411 sdp->isp_async_data_setup = 9;
7413 sdp->isp_async_data_setup = 6;
7415 sdp->isp_selection_timeout = 250;
7416 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
7417 sdp->isp_tag_aging = 8;
7418 sdp->isp_bus_reset_delay = 5;
7420 * Don't retry selection, busy or queue full automatically- reflect
7423 sdp->isp_retry_count = 0;
7424 sdp->isp_retry_delay = 0;
7426 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7427 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
7428 sdp->isp_devparam[tgt].dev_enable = 1;
7432 * The trick here is to establish a default for the default (honk!)
7433 * state (goal_flags). Then try and get the current status from
7434 * the card to fill in the current state. We don't, in fact, set
7435 * the default to the SAFE default state- that's not the goal state.
7437 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7439 sdp->isp_devparam[tgt].actv_offset = 0;
7440 sdp->isp_devparam[tgt].actv_period = 0;
7441 sdp->isp_devparam[tgt].actv_flags = 0;
7443 sdp->isp_devparam[tgt].goal_flags =
7444 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
7447 * We default to Wide/Fast for versions less than a 1040
7448 * (unless it's SBus).
7450 if (IS_ULTRA3(isp)) {
7451 off = ISP_80M_SYNCPARMS >> 8;
7452 per = ISP_80M_SYNCPARMS & 0xff;
7453 } else if (IS_ULTRA2(isp)) {
7454 off = ISP_40M_SYNCPARMS >> 8;
7455 per = ISP_40M_SYNCPARMS & 0xff;
7456 } else if (IS_1240(isp)) {
7457 off = ISP_20M_SYNCPARMS >> 8;
7458 per = ISP_20M_SYNCPARMS & 0xff;
7459 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
7460 isp->isp_type < ISP_HA_SCSI_1020A) ||
7461 (isp->isp_bustype == ISP_BT_PCI &&
7462 isp->isp_type < ISP_HA_SCSI_1040) ||
7463 (isp->isp_clock && isp->isp_clock < 60) ||
7464 (sdp->isp_ultramode == 0)) {
7465 off = ISP_10M_SYNCPARMS >> 8;
7466 per = ISP_10M_SYNCPARMS & 0xff;
7468 off = ISP_20M_SYNCPARMS_1040 >> 8;
7469 per = ISP_20M_SYNCPARMS_1040 & 0xff;
7471 sdp->isp_devparam[tgt].goal_offset =
7472 sdp->isp_devparam[tgt].nvrm_offset = off;
7473 sdp->isp_devparam[tgt].goal_period =
7474 sdp->isp_devparam[tgt].nvrm_period = per;
7479 * If we're a dual bus card, just copy the data over
7483 sdp1->isp_initiator_id = DEFAULT_IID(isp, 1);
7487 * If we've not been told to avoid reading NVRAM, try and read it.
7488 * If we're successful reading it, we can then return because NVRAM
7489 * will tell us what the desired settings are. Otherwise, we establish
7490 * some reasonable 'fake' nvram and goal defaults.
7492 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7495 if (isp_read_nvram(isp, 0) == 0) {
7496 if (IS_DUALBUS(isp)) {
7497 if (isp_read_nvram(isp, 1) == 0) {
7502 MBSINIT(&mbs, MBOX_GET_ACT_NEG_STATE, MBLOGNONE, 0);
7503 isp_mboxcmd(isp, &mbs);
7504 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7505 sdp->isp_req_ack_active_neg = 1;
7506 sdp->isp_data_line_active_neg = 1;
7508 sdp1->isp_req_ack_active_neg = 1;
7509 sdp1->isp_data_line_active_neg = 1;
7512 sdp->isp_req_ack_active_neg =
7513 (mbs.param[1] >> 4) & 0x1;
7514 sdp->isp_data_line_active_neg =
7515 (mbs.param[1] >> 5) & 0x1;
7517 sdp1->isp_req_ack_active_neg =
7518 (mbs.param[2] >> 4) & 0x1;
7519 sdp1->isp_data_line_active_neg =
7520 (mbs.param[2] >> 5) & 0x1;
7528 isp_setdfltfcparm(ispsoftc_t *isp, int chan)
7530 fcparam *fcp = FCPARAM(isp, chan);
7533 * Establish some default parameters.
7535 fcp->role = GET_DEFAULT_ROLE(isp, chan);
7536 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
7537 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
7538 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
7539 fcp->isp_loopid = DEFAULT_LOOPID(isp, chan);
7540 fcp->isp_wwnn_nvram = DEFAULT_NODEWWN(isp, chan);
7541 fcp->isp_wwpn_nvram = DEFAULT_PORTWWN(isp, chan);
7542 fcp->isp_fwoptions = 0;
7543 fcp->isp_lasthdl = NIL_HANDLE;
7546 fcp->isp_fwoptions |= ICB2400_OPT1_FAIRNESS;
7547 fcp->isp_fwoptions |= ICB2400_OPT1_HARD_ADDRESS;
7548 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX) {
7549 fcp->isp_fwoptions |= ICB2400_OPT1_FULL_DUPLEX;
7551 fcp->isp_fwoptions |= ICB2400_OPT1_BOTH_WWNS;
7553 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
7554 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
7555 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
7556 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX) {
7557 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
7560 * Make sure this is turned off now until we get
7561 * extended options from NVRAM
7563 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
7568 * Now try and read NVRAM unless told to not do so.
7569 * This will set fcparam's isp_wwnn_nvram && isp_wwpn_nvram.
7571 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7574 * Give a couple of tries at reading NVRAM.
7576 for (i = 0; i < 2; i++) {
7577 j = isp_read_nvram(isp, chan);
7583 isp->isp_confopts |= ISP_CFG_NONVRAM;
7587 fcp->isp_wwnn = ACTIVE_NODEWWN(isp, chan);
7588 fcp->isp_wwpn = ACTIVE_PORTWWN(isp, chan);
7589 isp_prt(isp, ISP_LOGCONFIG, "Chan %d 0x%08x%08x/0x%08x%08x Role %s",
7590 chan, (uint32_t) (fcp->isp_wwnn >> 32), (uint32_t) (fcp->isp_wwnn),
7591 (uint32_t) (fcp->isp_wwpn >> 32), (uint32_t) (fcp->isp_wwpn),
7592 isp_class3_roles[fcp->role]);
7596 * Re-initialize the ISP and complete all orphaned commands
7597 * with a 'botched' notice. The reset/init routines should
7598 * not disturb an already active list of commands.
7602 isp_reinit(ispsoftc_t *isp, int do_load_defaults)
7606 if (isp->isp_state != ISP_RESETSTATE)
7607 isp_reset(isp, do_load_defaults);
7608 if (isp->isp_state != ISP_RESETSTATE) {
7610 isp_prt(isp, ISP_LOGERR, "%s: cannot reset card", __func__);
7611 ISP_DISABLE_INTS(isp);
7616 if (isp->isp_state > ISP_RESETSTATE &&
7617 isp->isp_state != ISP_RUNSTATE) {
7619 isp_prt(isp, ISP_LOGERR, "%s: cannot init card", __func__);
7620 ISP_DISABLE_INTS(isp);
7623 * If we're in ISP_ROLE_NONE, turn off the lasers.
7625 if (!IS_24XX(isp)) {
7626 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
7627 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
7628 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
7629 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
7630 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
7636 isp->isp_nactive = 0;
7637 isp_clear_commands(isp);
7639 for (i = 0; i < isp->isp_nchan; i++)
7640 isp_clear_portdb(isp, i);
7649 isp_read_nvram(ispsoftc_t *isp, int bus)
7652 uint8_t csum, minversion;
7654 uint8_t _x[ISP2400_NVRAM_SIZE];
7655 uint16_t _s[ISP2400_NVRAM_SIZE>>1];
7657 #define nvram_data _n._x
7658 #define nvram_words _n._s
7661 return (isp_read_nvram_2400(isp, nvram_data));
7662 } else if (IS_FC(isp)) {
7663 amt = ISP2100_NVRAM_SIZE;
7665 } else if (IS_ULTRA2(isp)) {
7666 amt = ISP1080_NVRAM_SIZE;
7669 amt = ISP_NVRAM_SIZE;
7673 for (i = 0; i < amt>>1; i++) {
7674 isp_rdnvram_word(isp, i, &nvram_words[i]);
7677 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
7678 nvram_data[2] != 'P') {
7679 if (isp->isp_bustype != ISP_BT_SBUS) {
7680 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
7681 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x", nvram_data[0], nvram_data[1], nvram_data[2]);
7687 for (csum = 0, i = 0; i < amt; i++) {
7688 csum += nvram_data[i];
7691 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
7696 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
7697 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
7698 ISP_NVRAM_VERSION(nvram_data));
7703 if (IS_ULTRA3(isp)) {
7704 isp_parse_nvram_12160(isp, bus, nvram_data);
7705 } else if (IS_1080(isp)) {
7706 isp_parse_nvram_1080(isp, bus, nvram_data);
7707 } else if (IS_1280(isp) || IS_1240(isp)) {
7708 isp_parse_nvram_1080(isp, bus, nvram_data);
7709 } else if (IS_SCSI(isp)) {
7710 isp_parse_nvram_1020(isp, nvram_data);
7712 isp_parse_nvram_2100(isp, nvram_data);
7722 isp_read_nvram_2400(ispsoftc_t *isp, uint8_t *nvram_data)
7725 uint32_t addr, csum, lwrds, *dptr;
7727 if (isp->isp_port) {
7728 addr = ISP2400_NVRAM_PORT1_ADDR;
7730 addr = ISP2400_NVRAM_PORT0_ADDR;
7733 dptr = (uint32_t *) nvram_data;
7734 for (lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
7735 isp_rd_2400_nvram(isp, addr++, dptr++);
7737 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
7738 nvram_data[2] != 'P') {
7739 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header (%x %x %x)",
7740 nvram_data[0], nvram_data[1], nvram_data[2]);
7744 dptr = (uint32_t *) nvram_data;
7745 for (csum = 0, lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
7747 ISP_IOXGET_32(isp, &dptr[lwrds], tmp);
7751 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
7755 isp_parse_nvram_2400(isp, nvram_data);
7761 isp_rdnvram_word(ispsoftc_t *isp, int wo, uint16_t *rp)
7764 uint16_t bit, rqst, junk;
7766 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
7768 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
7772 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
7773 if (IS_2312(isp) && isp->isp_port) {
7776 rqst = (ISP_NVRAM_READ << 8) | wo;
7778 } else if (IS_ULTRA2(isp)) {
7779 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
7780 rqst = (ISP_NVRAM_READ << 8) | wo;
7783 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
7784 rqst = (ISP_NVRAM_READ << 6) | wo;
7789 * Clock the word select request out...
7791 for (i = cbits; i >= 0; i--) {
7792 if ((rqst >> i) & 1) {
7793 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
7795 bit = BIU_NVRAM_SELECT;
7797 ISP_WRITE(isp, BIU_NVRAM, bit);
7799 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7800 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
7802 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7803 ISP_WRITE(isp, BIU_NVRAM, bit);
7805 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7808 * Now read the result back in (bits come back in MSB format).
7811 for (i = 0; i < 16; i++) {
7814 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
7816 rv = ISP_READ(isp, BIU_NVRAM);
7817 if (rv & BIU_NVRAM_DATAIN) {
7821 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
7823 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7825 ISP_WRITE(isp, BIU_NVRAM, 0);
7827 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7828 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
7832 isp_rd_2400_nvram(ispsoftc_t *isp, uint32_t addr, uint32_t *rp)
7835 uint32_t base = 0x7ffe0000;
7839 base = 0x7ff00000 | 0x48000;
7841 ISP_WRITE(isp, BIU2400_FLASH_ADDR, base | addr);
7842 for (loops = 0; loops < 5000; loops++) {
7844 tmp = ISP_READ(isp, BIU2400_FLASH_ADDR);
7845 if ((tmp & (1U << 31)) != 0) {
7849 if (tmp & (1U << 31)) {
7850 *rp = ISP_READ(isp, BIU2400_FLASH_DATA);
7851 ISP_SWIZZLE_NVRAM_LONG(isp, rp);
7858 isp_parse_nvram_1020(ispsoftc_t *isp, uint8_t *nvram_data)
7860 sdparam *sdp = SDPARAM(isp, 0);
7863 sdp->isp_fifo_threshold =
7864 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
7865 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
7867 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
7868 sdp->isp_initiator_id = ISP_NVRAM_INITIATOR_ID(nvram_data);
7870 sdp->isp_bus_reset_delay =
7871 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
7873 sdp->isp_retry_count =
7874 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
7876 sdp->isp_retry_delay =
7877 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
7879 sdp->isp_async_data_setup =
7880 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
7882 if (isp->isp_type >= ISP_HA_SCSI_1040) {
7883 if (sdp->isp_async_data_setup < 9) {
7884 sdp->isp_async_data_setup = 9;
7887 if (sdp->isp_async_data_setup != 6) {
7888 sdp->isp_async_data_setup = 6;
7892 sdp->isp_req_ack_active_neg =
7893 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
7895 sdp->isp_data_line_active_neg =
7896 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
7898 sdp->isp_data_dma_burst_enabl =
7899 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
7901 sdp->isp_cmd_dma_burst_enable =
7902 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
7904 sdp->isp_tag_aging =
7905 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
7907 sdp->isp_selection_timeout =
7908 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
7910 sdp->isp_max_queue_depth =
7911 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
7913 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
7915 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7916 sdp->isp_devparam[tgt].dev_enable =
7917 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
7918 sdp->isp_devparam[tgt].exc_throttle =
7919 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
7920 sdp->isp_devparam[tgt].nvrm_offset =
7921 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
7922 sdp->isp_devparam[tgt].nvrm_period =
7923 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
7925 * We probably shouldn't lie about this, but it
7926 * it makes it much safer if we limit NVRAM values
7929 if (isp->isp_type < ISP_HA_SCSI_1040) {
7931 * If we're not ultra, we can't possibly
7932 * be a shorter period than this.
7934 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
7935 sdp->isp_devparam[tgt].nvrm_period = 0x19;
7937 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
7938 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
7941 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
7942 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
7945 sdp->isp_devparam[tgt].nvrm_flags = 0;
7946 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
7947 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
7948 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
7949 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
7950 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
7951 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
7952 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
7953 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
7954 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
7955 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
7956 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
7957 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
7958 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
7959 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
7960 sdp->isp_devparam[tgt].goal_offset =
7961 sdp->isp_devparam[tgt].nvrm_offset;
7962 sdp->isp_devparam[tgt].goal_period =
7963 sdp->isp_devparam[tgt].nvrm_period;
7964 sdp->isp_devparam[tgt].goal_flags =
7965 sdp->isp_devparam[tgt].nvrm_flags;
7970 isp_parse_nvram_1080(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
7972 sdparam *sdp = SDPARAM(isp, bus);
7975 sdp->isp_fifo_threshold =
7976 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
7978 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
7979 sdp->isp_initiator_id = ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
7981 sdp->isp_bus_reset_delay =
7982 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
7984 sdp->isp_retry_count =
7985 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
7987 sdp->isp_retry_delay =
7988 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
7990 sdp->isp_async_data_setup =
7991 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
7993 sdp->isp_req_ack_active_neg =
7994 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
7996 sdp->isp_data_line_active_neg =
7997 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
7999 sdp->isp_data_dma_burst_enabl =
8000 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
8002 sdp->isp_cmd_dma_burst_enable =
8003 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
8005 sdp->isp_selection_timeout =
8006 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
8008 sdp->isp_max_queue_depth =
8009 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
8011 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
8012 sdp->isp_devparam[tgt].dev_enable =
8013 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
8014 sdp->isp_devparam[tgt].exc_throttle =
8015 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
8016 sdp->isp_devparam[tgt].nvrm_offset =
8017 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
8018 sdp->isp_devparam[tgt].nvrm_period =
8019 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
8020 sdp->isp_devparam[tgt].nvrm_flags = 0;
8021 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
8022 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
8023 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
8024 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
8025 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
8026 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
8027 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
8028 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
8029 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
8030 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
8031 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
8032 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
8033 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
8034 sdp->isp_devparam[tgt].actv_flags = 0;
8035 sdp->isp_devparam[tgt].goal_offset =
8036 sdp->isp_devparam[tgt].nvrm_offset;
8037 sdp->isp_devparam[tgt].goal_period =
8038 sdp->isp_devparam[tgt].nvrm_period;
8039 sdp->isp_devparam[tgt].goal_flags =
8040 sdp->isp_devparam[tgt].nvrm_flags;
8045 isp_parse_nvram_12160(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
8047 sdparam *sdp = SDPARAM(isp, bus);
8050 sdp->isp_fifo_threshold =
8051 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
8053 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
8054 sdp->isp_initiator_id = ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
8056 sdp->isp_bus_reset_delay =
8057 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
8059 sdp->isp_retry_count =
8060 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
8062 sdp->isp_retry_delay =
8063 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
8065 sdp->isp_async_data_setup =
8066 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
8068 sdp->isp_req_ack_active_neg =
8069 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
8071 sdp->isp_data_line_active_neg =
8072 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
8074 sdp->isp_data_dma_burst_enabl =
8075 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
8077 sdp->isp_cmd_dma_burst_enable =
8078 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
8080 sdp->isp_selection_timeout =
8081 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
8083 sdp->isp_max_queue_depth =
8084 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
8086 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
8087 sdp->isp_devparam[tgt].dev_enable =
8088 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
8089 sdp->isp_devparam[tgt].exc_throttle =
8090 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
8091 sdp->isp_devparam[tgt].nvrm_offset =
8092 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
8093 sdp->isp_devparam[tgt].nvrm_period =
8094 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
8095 sdp->isp_devparam[tgt].nvrm_flags = 0;
8096 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
8097 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
8098 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
8099 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
8100 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
8101 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
8102 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
8103 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
8104 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
8105 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
8106 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
8107 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
8108 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
8109 sdp->isp_devparam[tgt].actv_flags = 0;
8110 sdp->isp_devparam[tgt].goal_offset =
8111 sdp->isp_devparam[tgt].nvrm_offset;
8112 sdp->isp_devparam[tgt].goal_period =
8113 sdp->isp_devparam[tgt].nvrm_period;
8114 sdp->isp_devparam[tgt].goal_flags =
8115 sdp->isp_devparam[tgt].nvrm_flags;
8120 isp_parse_nvram_2100(ispsoftc_t *isp, uint8_t *nvram_data)
8122 fcparam *fcp = FCPARAM(isp, 0);
8126 * There is NVRAM storage for both Port and Node entities-
8127 * but the Node entity appears to be unused on all the cards
8128 * I can find. However, we should account for this being set
8129 * at some point in the future.
8131 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
8132 * bits 48..60. In the case of the 2202, it appears that they do
8133 * use bit 48 to distinguish between the two instances on the card.
8134 * The 2204, which I've never seen, *probably* extends this method.
8136 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
8138 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
8139 (uint32_t) (wwn >> 32), (uint32_t) (wwn));
8140 if ((wwn >> 60) == 0) {
8141 wwn |= (((uint64_t) 2)<< 60);
8144 fcp->isp_wwpn_nvram = wwn;
8145 if (IS_2200(isp) || IS_23XX(isp)) {
8146 wwn = ISP2100_NVRAM_NODE_NAME(nvram_data);
8148 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
8149 (uint32_t) (wwn >> 32),
8151 if ((wwn >> 60) == 0) {
8152 wwn |= (((uint64_t) 2)<< 60);
8155 wwn = fcp->isp_wwpn_nvram & ~((uint64_t) 0xfff << 48);
8158 wwn &= ~((uint64_t) 0xfff << 48);
8160 fcp->isp_wwnn_nvram = wwn;
8162 fcp->isp_maxalloc = ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
8163 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
8164 DEFAULT_FRAMESIZE(isp) =
8165 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
8167 fcp->isp_retry_delay = ISP2100_NVRAM_RETRY_DELAY(nvram_data);
8168 fcp->isp_retry_count = ISP2100_NVRAM_RETRY_COUNT(nvram_data);
8169 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
8170 fcp->isp_loopid = ISP2100_NVRAM_HARDLOOPID(nvram_data);
8172 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
8173 DEFAULT_EXEC_THROTTLE(isp) =
8174 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
8176 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
8177 isp_prt(isp, ISP_LOGDEBUG0,
8178 "NVRAM 0x%08x%08x 0x%08x%08x maxalloc %d maxframelen %d",
8179 (uint32_t) (fcp->isp_wwnn_nvram >> 32),
8180 (uint32_t) fcp->isp_wwnn_nvram,
8181 (uint32_t) (fcp->isp_wwpn_nvram >> 32),
8182 (uint32_t) fcp->isp_wwpn_nvram,
8183 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data),
8184 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data));
8185 isp_prt(isp, ISP_LOGDEBUG0,
8186 "execthrottle %d fwoptions 0x%x hardloop %d tov %d",
8187 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
8188 ISP2100_NVRAM_OPTIONS(nvram_data),
8189 ISP2100_NVRAM_HARDLOOPID(nvram_data),
8190 ISP2100_NVRAM_TOV(nvram_data));
8191 fcp->isp_xfwoptions = ISP2100_XFW_OPTIONS(nvram_data);
8192 fcp->isp_zfwoptions = ISP2100_ZFW_OPTIONS(nvram_data);
8193 isp_prt(isp, ISP_LOGDEBUG0, "xfwoptions 0x%x zfw options 0x%x",
8194 ISP2100_XFW_OPTIONS(nvram_data), ISP2100_ZFW_OPTIONS(nvram_data));
8198 isp_parse_nvram_2400(ispsoftc_t *isp, uint8_t *nvram_data)
8200 fcparam *fcp = FCPARAM(isp, 0);
8203 isp_prt(isp, ISP_LOGDEBUG0,
8204 "NVRAM 0x%08x%08x 0x%08x%08x exchg_cnt %d maxframelen %d",
8205 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data) >> 32),
8206 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data)),
8207 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data) >> 32),
8208 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data)),
8209 ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data),
8210 ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data));
8211 isp_prt(isp, ISP_LOGDEBUG0,
8212 "NVRAM execthr %d loopid %d fwopt1 0x%x fwopt2 0x%x fwopt3 0x%x",
8213 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data),
8214 ISP2400_NVRAM_HARDLOOPID(nvram_data),
8215 ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data),
8216 ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data),
8217 ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data));
8219 wwn = ISP2400_NVRAM_PORT_NAME(nvram_data);
8220 fcp->isp_wwpn_nvram = wwn;
8222 wwn = ISP2400_NVRAM_NODE_NAME(nvram_data);
8224 if ((wwn >> 60) != 2 && (wwn >> 60) != 5) {
8228 if (wwn == 0 && (fcp->isp_wwpn_nvram >> 60) == 2) {
8229 wwn = fcp->isp_wwpn_nvram;
8230 wwn &= ~((uint64_t) 0xfff << 48);
8232 fcp->isp_wwnn_nvram = wwn;
8234 if (ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data)) {
8235 fcp->isp_maxalloc = ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data);
8237 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
8238 DEFAULT_FRAMESIZE(isp) =
8239 ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data);
8241 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
8242 fcp->isp_loopid = ISP2400_NVRAM_HARDLOOPID(nvram_data);
8244 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
8245 DEFAULT_EXEC_THROTTLE(isp) =
8246 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data);
8248 fcp->isp_fwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data);
8249 fcp->isp_xfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data);
8250 fcp->isp_zfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data);