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 & 0xfffc00) == 0xfffc00)
2325 fcp->portdb[i].probational = 1;
2330 * Perform an IOCB PLOGI or LOGO via EXECUTE IOCB A64 for 24XX cards
2331 * or via FABRIC LOGIN/FABRIC LOGOUT for other cards.
2334 isp_plogx(ispsoftc_t *isp, int chan, uint16_t handle, uint32_t portid, int flags, int gs)
2337 uint8_t q[QENTRY_LEN];
2341 uint32_t sst, parm1;
2346 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d PLOGX %s PortID 0x%06x nphdl 0x%x",
2347 chan, (flags & PLOGX_FLG_CMD_MASK) == PLOGX_FLG_CMD_PLOGI ?
2348 "Login":"Logout", portid, handle);
2349 if (!IS_24XX(isp)) {
2350 int action = flags & PLOGX_FLG_CMD_MASK;
2351 if (action == PLOGX_FLG_CMD_PLOGI) {
2352 return (isp_port_login(isp, handle, portid));
2353 } else if (action == PLOGX_FLG_CMD_LOGO) {
2354 return (isp_port_logout(isp, handle, portid));
2356 return (MBOX_INVALID_COMMAND);
2360 ISP_MEMZERO(q, QENTRY_LEN);
2361 plp = (isp_plogx_t *) q;
2362 plp->plogx_header.rqs_entry_count = 1;
2363 plp->plogx_header.rqs_entry_type = RQSTYPE_LOGIN;
2364 plp->plogx_handle = 0xffffffff;
2365 plp->plogx_nphdl = handle;
2366 plp->plogx_vphdl = chan;
2367 plp->plogx_portlo = portid;
2368 plp->plogx_rspsz_porthi = (portid >> 16) & 0xff;
2369 plp->plogx_flags = flags;
2371 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2372 isp_print_bytes(isp, "IOCB LOGX", QENTRY_LEN, plp);
2376 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
2377 isp_prt(isp, ISP_LOGERR, sacq);
2381 fcp = FCPARAM(isp, chan);
2382 scp = fcp->isp_scratch;
2383 isp_put_plogx(isp, plp, (isp_plogx_t *) scp);
2385 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 500000);
2386 mbs.param[1] = QENTRY_LEN;
2387 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2388 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2389 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2390 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2391 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, QENTRY_LEN, chan);
2392 isp_mboxcmd(isp, &mbs);
2393 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2394 rval = mbs.param[0];
2397 MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN, QENTRY_LEN, chan);
2399 isp_get_plogx(isp, (isp_plogx_t *) scp, plp);
2400 if (isp->isp_dblev & ISP_LOGDEBUG1) {
2401 isp_print_bytes(isp, "IOCB LOGX response", QENTRY_LEN, plp);
2404 if (plp->plogx_status == PLOGX_STATUS_OK) {
2407 } else if (plp->plogx_status != PLOGX_STATUS_IOCBERR) {
2408 isp_prt(isp, ISP_LOGWARN,
2409 "status 0x%x on port login IOCB channel %d",
2410 plp->plogx_status, chan);
2415 sst = plp->plogx_ioparm[0].lo16 | (plp->plogx_ioparm[0].hi16 << 16);
2416 parm1 = plp->plogx_ioparm[1].lo16 | (plp->plogx_ioparm[1].hi16 << 16);
2423 case PLOGX_IOCBERR_NOLINK:
2426 case PLOGX_IOCBERR_NOIOCB:
2427 msg = "no IOCB buffer";
2429 case PLOGX_IOCBERR_NOXGHG:
2430 msg = "no Exchange Control Block";
2432 case PLOGX_IOCBERR_FAILED:
2433 ISP_SNPRINTF(buf, sizeof (buf), "reason 0x%x (last LOGIN state 0x%x)", parm1 & 0xff, (parm1 >> 8) & 0xff);
2436 case PLOGX_IOCBERR_NOFABRIC:
2439 case PLOGX_IOCBERR_NOTREADY:
2440 msg = "firmware not ready";
2442 case PLOGX_IOCBERR_NOLOGIN:
2443 ISP_SNPRINTF(buf, sizeof (buf), "not logged in (last state 0x%x)", parm1);
2445 rval = MBOX_NOT_LOGGED_IN;
2447 case PLOGX_IOCBERR_REJECT:
2448 ISP_SNPRINTF(buf, sizeof (buf), "LS_RJT = 0x%x", parm1);
2451 case PLOGX_IOCBERR_NOPCB:
2452 msg = "no PCB allocated";
2454 case PLOGX_IOCBERR_EINVAL:
2455 ISP_SNPRINTF(buf, sizeof (buf), "invalid parameter at offset 0x%x", parm1);
2458 case PLOGX_IOCBERR_PORTUSED:
2459 lev = ISP_LOG_SANCFG|ISP_LOG_WARN1;
2460 ISP_SNPRINTF(buf, sizeof (buf), "already logged in with N-Port handle 0x%x", parm1);
2462 rval = MBOX_PORT_ID_USED | (parm1 << 16);
2464 case PLOGX_IOCBERR_HNDLUSED:
2465 lev = ISP_LOG_SANCFG|ISP_LOG_WARN1;
2466 ISP_SNPRINTF(buf, sizeof (buf), "handle already used for PortID 0x%06x", parm1);
2468 rval = MBOX_LOOP_ID_USED;
2470 case PLOGX_IOCBERR_NOHANDLE:
2471 msg = "no handle allocated";
2473 case PLOGX_IOCBERR_NOFLOGI:
2474 msg = "no FLOGI_ACC";
2477 ISP_SNPRINTF(buf, sizeof (buf), "status %x from %x", plp->plogx_status, flags);
2482 isp_prt(isp, ISP_LOGERR, "Chan %d PLOGX PortID 0x%06x to N-Port handle 0x%x: %s", chan, portid, handle, msg);
2486 FC_SCRATCH_RELEASE(isp, chan);
2492 isp_port_login(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2496 MBSINIT(&mbs, MBOX_FABRIC_LOGIN, MBLOGNONE, 500000);
2497 if (ISP_CAP_2KLOGIN(isp)) {
2498 mbs.param[1] = handle;
2499 mbs.ibits = (1 << 10);
2501 mbs.param[1] = handle << 8;
2503 mbs.param[2] = portid >> 16;
2504 mbs.param[3] = portid;
2505 mbs.logval = MBLOGNONE;
2506 mbs.timeout = 500000;
2507 isp_mboxcmd(isp, &mbs);
2509 switch (mbs.param[0]) {
2510 case MBOX_PORT_ID_USED:
2511 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]);
2512 return (MBOX_PORT_ID_USED | (mbs.param[1] << 16));
2514 case MBOX_LOOP_ID_USED:
2515 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);
2516 return (MBOX_LOOP_ID_USED);
2518 case MBOX_COMMAND_COMPLETE:
2521 case MBOX_COMMAND_ERROR:
2522 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);
2523 return (MBOX_COMMAND_ERROR);
2525 case MBOX_ALL_IDS_USED:
2526 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "isp_port_login: all IDs used for fabric login");
2527 return (MBOX_ALL_IDS_USED);
2530 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);
2531 return (mbs.param[0]);
2536 * Pre-24XX fabric port logout
2538 * Note that portid is not used
2541 isp_port_logout(ispsoftc_t *isp, uint16_t handle, uint32_t portid)
2545 MBSINIT(&mbs, MBOX_FABRIC_LOGOUT, MBLOGNONE, 500000);
2546 if (ISP_CAP_2KLOGIN(isp)) {
2547 mbs.param[1] = handle;
2548 mbs.ibits = (1 << 10);
2550 mbs.param[1] = handle << 8;
2552 isp_mboxcmd(isp, &mbs);
2553 return (mbs.param[0] == MBOX_COMMAND_COMPLETE? 0 : mbs.param[0]);
2557 isp_getpdb(ispsoftc_t *isp, int chan, uint16_t id, isp_pdb_t *pdb, int dolock)
2559 fcparam *fcp = FCPARAM(isp, chan);
2562 isp_pdb_21xx_t fred;
2563 isp_pdb_24xx_t bill;
2566 MBSINIT(&mbs, MBOX_GET_PORT_DB,
2567 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_PARAM_ERROR), 250000);
2569 mbs.ibits = (1 << 9)|(1 << 10);
2571 mbs.param[9] = chan;
2572 } else if (ISP_CAP_2KLOGIN(isp)) {
2575 mbs.param[1] = id << 8;
2577 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2578 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2579 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2580 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2582 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
2583 isp_prt(isp, ISP_LOGERR, sacq);
2587 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, sizeof (un), chan);
2588 isp_mboxcmd(isp, &mbs);
2589 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2591 FC_SCRATCH_RELEASE(isp, chan);
2593 return (mbs.param[0] | (mbs.param[1] << 16));
2596 isp_get_pdb_24xx(isp, fcp->isp_scratch, &un.bill);
2597 pdb->handle = un.bill.pdb_handle;
2598 pdb->prli_word3 = un.bill.pdb_prli_svc3;
2599 pdb->portid = BITS2WORD_24XX(un.bill.pdb_portid_bits);
2600 ISP_MEMCPY(pdb->portname, un.bill.pdb_portname, 8);
2601 ISP_MEMCPY(pdb->nodename, un.bill.pdb_nodename, 8);
2602 isp_prt(isp, ISP_LOGDEBUG1,
2603 "Chan %d handle 0x%x Port 0x%06x flags 0x%x curstate %x",
2604 chan, id, pdb->portid, un.bill.pdb_flags,
2605 un.bill.pdb_curstate);
2606 if (un.bill.pdb_curstate < PDB2400_STATE_PLOGI_DONE || un.bill.pdb_curstate > PDB2400_STATE_LOGGED_IN) {
2607 mbs.param[0] = MBOX_NOT_LOGGED_IN;
2609 FC_SCRATCH_RELEASE(isp, chan);
2611 return (mbs.param[0]);
2614 isp_get_pdb_21xx(isp, fcp->isp_scratch, &un.fred);
2615 pdb->handle = un.fred.pdb_loopid;
2616 pdb->prli_word3 = un.fred.pdb_prli_svc3;
2617 pdb->portid = BITS2WORD(un.fred.pdb_portid_bits);
2618 ISP_MEMCPY(pdb->portname, un.fred.pdb_portname, 8);
2619 ISP_MEMCPY(pdb->nodename, un.fred.pdb_nodename, 8);
2620 isp_prt(isp, ISP_LOGDEBUG1,
2621 "Chan %d handle 0x%x Port 0x%06x", chan, id, pdb->portid);
2624 FC_SCRATCH_RELEASE(isp, chan);
2630 isp_gethandles(ispsoftc_t *isp, int chan, uint16_t *handles, int *num,
2631 int dolock, int loop)
2633 fcparam *fcp = FCPARAM(isp, chan);
2635 isp_pnhle_21xx_t el1, *elp1;
2636 isp_pnhle_23xx_t el3, *elp3;
2637 isp_pnhle_24xx_t el4, *elp4;
2642 MBSINIT(&mbs, MBOX_GET_ID_LIST, MBLOGALL, 250000);
2644 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
2645 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
2646 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
2647 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
2648 mbs.param[8] = ISP_FC_SCRLEN;
2649 mbs.param[9] = chan;
2651 mbs.ibits = (1 << 1)|(1 << 2)|(1 << 3)|(1 << 6);
2652 mbs.param[1] = DMA_WD1(fcp->isp_scdma);
2653 mbs.param[2] = DMA_WD0(fcp->isp_scdma);
2654 mbs.param[3] = DMA_WD3(fcp->isp_scdma);
2655 mbs.param[6] = DMA_WD2(fcp->isp_scdma);
2658 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
2659 isp_prt(isp, ISP_LOGERR, sacq);
2663 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, ISP_FC_SCRLEN, chan);
2664 isp_mboxcmd(isp, &mbs);
2665 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2667 FC_SCRATCH_RELEASE(isp, chan);
2669 return (mbs.param[0] | (mbs.param[1] << 16));
2671 elp1 = fcp->isp_scratch;
2672 elp3 = fcp->isp_scratch;
2673 elp4 = fcp->isp_scratch;
2674 for (i = 0, j = 0; i < mbs.param[1] && j < *num; i++) {
2676 isp_get_pnhle_24xx(isp, &elp4[i], &el4);
2677 p = el4.pnhle_port_id_lo |
2678 (el4.pnhle_port_id_hi << 16);
2679 h = el4.pnhle_handle;
2680 } else if (IS_23XX(isp)) {
2681 isp_get_pnhle_23xx(isp, &elp3[i], &el3);
2682 p = el3.pnhle_port_id_lo |
2683 (el3.pnhle_port_id_hi << 16);
2684 h = el3.pnhle_handle;
2686 isp_get_pnhle_21xx(isp, &elp1[i], &el1);
2687 p = el1.pnhle_port_id_lo |
2688 ((el1.pnhle_port_id_hi_handle & 0xff) << 16);
2689 h = el1.pnhle_port_id_hi_handle >> 8;
2691 if (loop && (p >> 8) != (fcp->isp_portid >> 8))
2697 FC_SCRATCH_RELEASE(isp, chan);
2702 isp_dump_chip_portdb(ispsoftc_t *isp, int chan, int dolock)
2705 uint16_t lim, nphdl;
2707 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGINFO, "Chan %d chip port dump", chan);
2708 if (ISP_CAP_2KLOGIN(isp)) {
2713 for (nphdl = 0; nphdl != lim; nphdl++) {
2714 if (isp_getpdb(isp, chan, nphdl, &pdb, dolock)) {
2717 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGINFO, "Chan %d Handle 0x%04x "
2718 "PortID 0x%06x WWPN 0x%02x%02x%02x%02x%02x%02x%02x%02x",
2719 chan, nphdl, pdb.portid, pdb.portname[0], pdb.portname[1],
2720 pdb.portname[2], pdb.portname[3], pdb.portname[4],
2721 pdb.portname[5], pdb.portname[6], pdb.portname[7]);
2726 isp_get_wwn(ispsoftc_t *isp, int chan, int nphdl, int nodename)
2728 uint64_t wwn = INI_NONE;
2731 MBSINIT(&mbs, MBOX_GET_PORT_NAME,
2732 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_PARAM_ERROR), 500000);
2733 if (ISP_CAP_2KLOGIN(isp)) {
2734 mbs.param[1] = nphdl;
2738 mbs.param[9] = chan;
2741 mbs.param[1] = nphdl << 8;
2746 isp_mboxcmd(isp, &mbs);
2747 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2752 (((uint64_t)(mbs.param[2] >> 8)) << 56) |
2753 (((uint64_t)(mbs.param[2] & 0xff)) << 48) |
2754 (((uint64_t)(mbs.param[3] >> 8)) << 40) |
2755 (((uint64_t)(mbs.param[3] & 0xff)) << 32) |
2756 (((uint64_t)(mbs.param[6] >> 8)) << 24) |
2757 (((uint64_t)(mbs.param[6] & 0xff)) << 16) |
2758 (((uint64_t)(mbs.param[7] >> 8)) << 8) |
2759 (((uint64_t)(mbs.param[7] & 0xff)));
2762 (((uint64_t)(mbs.param[2] & 0xff)) << 56) |
2763 (((uint64_t)(mbs.param[2] >> 8)) << 48) |
2764 (((uint64_t)(mbs.param[3] & 0xff)) << 40) |
2765 (((uint64_t)(mbs.param[3] >> 8)) << 32) |
2766 (((uint64_t)(mbs.param[6] & 0xff)) << 24) |
2767 (((uint64_t)(mbs.param[6] >> 8)) << 16) |
2768 (((uint64_t)(mbs.param[7] & 0xff)) << 8) |
2769 (((uint64_t)(mbs.param[7] >> 8)));
2775 * Make sure we have good FC link.
2779 isp_fclink_test(ispsoftc_t *isp, int chan, int usdelay)
2786 NANOTIME_T hra, hrb;
2788 fcp = FCPARAM(isp, chan);
2790 /* Mark port database entries probational for following scan. */
2791 isp_mark_portdb(isp, chan);
2793 if (fcp->isp_loopstate >= LOOP_LTEST_DONE)
2796 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC link test", chan);
2797 fcp->isp_loopstate = LOOP_TESTING_LINK;
2800 * Wait up to N microseconds for F/W to go to a ready state.
2804 isp_change_fw_state(isp, chan, isp_fw_state(isp, chan));
2805 if (fcp->isp_fwstate == FW_READY) {
2809 if ((NANOTIME_SUB(&hrb, &hra) / 1000 + 1000 >= usdelay))
2811 ISP_SLEEP(isp, 1000);
2815 * If we haven't gone to 'ready' state, return.
2817 if (fcp->isp_fwstate != FW_READY) {
2818 isp_prt(isp, ISP_LOG_SANCFG,
2819 "Chan %d Firmware is not ready (%s)",
2820 chan, isp_fc_fw_statename(fcp->isp_fwstate));
2825 * Get our Loop ID and Port ID.
2827 MBSINIT(&mbs, MBOX_GET_LOOP_ID, MBLOGALL, 0);
2828 mbs.param[9] = chan;
2829 isp_mboxcmd(isp, &mbs);
2830 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
2836 * Don't bother with fabric if we are using really old
2837 * 2100 firmware. It's just not worth it.
2839 if (ISP_FW_NEWER_THAN(isp, 1, 15, 37))
2840 fcp->isp_topo = TOPO_FL_PORT;
2842 fcp->isp_topo = TOPO_NL_PORT;
2844 int topo = (int) mbs.param[6];
2845 if (topo < TOPO_NL_PORT || topo > TOPO_PTP_STUB) {
2846 topo = TOPO_PTP_STUB;
2848 fcp->isp_topo = topo;
2850 fcp->isp_portid = mbs.param[2] | (mbs.param[3] << 16);
2852 if (!TOPO_IS_FABRIC(fcp->isp_topo)) {
2853 fcp->isp_loopid = mbs.param[1] & 0xff;
2854 } else if (fcp->isp_topo != TOPO_F_PORT) {
2855 uint8_t alpa = fcp->isp_portid;
2857 for (i = 0; alpa_map[i]; i++) {
2858 if (alpa_map[i] == alpa)
2862 fcp->isp_loopid = i;
2865 if (fcp->isp_topo == TOPO_F_PORT || fcp->isp_topo == TOPO_FL_PORT) {
2866 nphdl = IS_24XX(isp) ? NPH_FL_ID : FL_ID;
2867 r = isp_getpdb(isp, chan, nphdl, &pdb, 1);
2868 if (r != 0 || pdb.portid == 0) {
2870 fcp->isp_topo = TOPO_NL_PORT;
2872 isp_prt(isp, ISP_LOGWARN,
2873 "fabric topology, but cannot get info about fabric controller (0x%x)", r);
2874 fcp->isp_topo = TOPO_PTP_STUB;
2880 fcp->isp_fabric_params = mbs.param[7];
2881 fcp->isp_sns_hdl = NPH_SNS_ID;
2882 r = isp_register_fc4_type_24xx(isp, chan);
2884 isp_register_fc4_features_24xx(isp, chan);
2886 fcp->isp_sns_hdl = SNS_ID;
2887 r = isp_register_fc4_type(isp, chan);
2890 isp_prt(isp, ISP_LOGWARN|ISP_LOG_SANCFG, "%s: register fc4 type failed", __func__);
2896 /* Get link speed. */
2897 fcp->isp_gbspeed = 1;
2898 if (IS_23XX(isp) || IS_24XX(isp)) {
2899 MBSINIT(&mbs, MBOX_GET_SET_DATA_RATE, MBLOGALL, 3000000);
2900 mbs.param[1] = MBGSD_GET_RATE;
2901 /* mbs.param[2] undefined if we're just getting rate */
2902 isp_mboxcmd(isp, &mbs);
2903 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
2904 if (mbs.param[1] == MBGSD_10GB)
2905 fcp->isp_gbspeed = 10;
2906 else if (mbs.param[1] == MBGSD_16GB)
2907 fcp->isp_gbspeed = 16;
2908 else if (mbs.param[1] == MBGSD_8GB)
2909 fcp->isp_gbspeed = 8;
2910 else if (mbs.param[1] == MBGSD_4GB)
2911 fcp->isp_gbspeed = 4;
2912 else if (mbs.param[1] == MBGSD_2GB)
2913 fcp->isp_gbspeed = 2;
2914 else if (mbs.param[1] == MBGSD_1GB)
2915 fcp->isp_gbspeed = 1;
2919 fcp->isp_loopstate = LOOP_LTEST_DONE;
2920 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGCONFIG,
2921 "Chan %d WWPN %016jx WWNN %016jx",
2922 chan, (uintmax_t)fcp->isp_wwpn, (uintmax_t)fcp->isp_wwnn);
2923 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOGCONFIG,
2924 "Chan %d %dGb %s PortID 0x%06x LoopID 0x%02x",
2925 chan, fcp->isp_gbspeed, isp_fc_toponame(fcp), fcp->isp_portid,
2927 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC link test done", chan);
2932 * Complete the synchronization of our Port Database.
2934 * At this point, we've scanned the local loop (if any) and the fabric
2935 * and performed fabric logins on all new devices.
2937 * Our task here is to go through our port database removing any entities
2938 * that are still marked probational (issuing PLOGO for ones which we had
2939 * PLOGI'd into) or are dead, and notifying upper layers about new/changed
2943 isp_pdb_sync(ispsoftc_t *isp, int chan)
2945 fcparam *fcp = FCPARAM(isp, chan);
2949 if (fcp->isp_loopstate < LOOP_FSCAN_DONE) {
2952 if (fcp->isp_loopstate > LOOP_SYNCING_PDB) {
2956 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC PDB sync", chan);
2958 fcp->isp_loopstate = LOOP_SYNCING_PDB;
2960 for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
2961 lp = &fcp->portdb[dbidx];
2963 if (lp->state == FC_PORTDB_STATE_NIL)
2965 if (lp->probational && lp->state != FC_PORTDB_STATE_ZOMBIE)
2966 lp->state = FC_PORTDB_STATE_DEAD;
2967 switch (lp->state) {
2968 case FC_PORTDB_STATE_DEAD:
2969 lp->state = FC_PORTDB_STATE_NIL;
2970 isp_async(isp, ISPASYNC_DEV_GONE, chan, lp);
2971 if (lp->autologin == 0) {
2972 (void) isp_plogx(isp, chan, lp->handle,
2974 PLOGX_FLG_CMD_LOGO |
2975 PLOGX_FLG_IMPLICIT |
2976 PLOGX_FLG_FREE_NPHDL, 0);
2979 * Note that we might come out of this with our state
2980 * set to FC_PORTDB_STATE_ZOMBIE.
2983 case FC_PORTDB_STATE_NEW:
2984 lp->state = FC_PORTDB_STATE_VALID;
2985 isp_async(isp, ISPASYNC_DEV_ARRIVED, chan, lp);
2987 case FC_PORTDB_STATE_CHANGED:
2988 lp->state = FC_PORTDB_STATE_VALID;
2989 isp_async(isp, ISPASYNC_DEV_CHANGED, chan, lp);
2990 lp->portid = lp->new_portid;
2991 lp->prli_word3 = lp->new_prli_word3;
2993 case FC_PORTDB_STATE_VALID:
2994 isp_async(isp, ISPASYNC_DEV_STAYED, chan, lp);
2996 case FC_PORTDB_STATE_ZOMBIE:
2999 isp_prt(isp, ISP_LOGWARN,
3000 "isp_pdb_sync: state %d for idx %d",
3002 isp_dump_portdb(isp, chan);
3007 * If we get here, we've for sure seen not only a valid loop
3008 * but know what is or isn't on it, so mark this for usage
3011 fcp->loop_seen_once = 1;
3012 fcp->isp_loopstate = LOOP_READY;
3013 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC PDB sync done", chan);
3018 isp_pdb_add_update(ispsoftc_t *isp, int chan, isp_pdb_t *pdb)
3021 uint64_t wwnn, wwpn;
3023 MAKE_WWN_FROM_NODE_NAME(wwnn, pdb->nodename);
3024 MAKE_WWN_FROM_NODE_NAME(wwpn, pdb->portname);
3026 /* Search port database for the same WWPN. */
3027 if (isp_find_pdb_by_wwpn(isp, chan, wwpn, &lp)) {
3028 if (!lp->probational) {
3029 isp_prt(isp, ISP_LOGERR,
3030 "Chan %d Port 0x%06x@0x%04x [%d] is not probational (0x%x)",
3031 chan, lp->portid, lp->handle,
3032 FC_PORTDB_TGT(isp, chan, lp), lp->state);
3033 isp_dump_portdb(isp, chan);
3036 lp->probational = 0;
3037 lp->node_wwn = wwnn;
3039 /* Old device, nothing new. */
3040 if (lp->portid == pdb->portid &&
3041 lp->handle == pdb->handle &&
3042 lp->prli_word3 == pdb->prli_word3) {
3043 if (lp->state != FC_PORTDB_STATE_NEW)
3044 lp->state = FC_PORTDB_STATE_VALID;
3045 isp_prt(isp, ISP_LOG_SANCFG,
3046 "Chan %d Port 0x%06x@0x%04x is valid",
3047 chan, pdb->portid, pdb->handle);
3051 /* Something has changed. */
3052 lp->state = FC_PORTDB_STATE_CHANGED;
3053 lp->handle = pdb->handle;
3054 lp->new_portid = pdb->portid;
3055 lp->new_prli_word3 = pdb->prli_word3;
3056 isp_prt(isp, ISP_LOG_SANCFG,
3057 "Chan %d Port 0x%06x@0x%04x is changed",
3058 chan, pdb->portid, pdb->handle);
3062 /* It seems like a new port. Find an empty slot for it. */
3063 if (!isp_find_pdb_empty(isp, chan, &lp)) {
3064 isp_prt(isp, ISP_LOGERR, "Chan %d out of portdb entries", chan);
3068 ISP_MEMZERO(lp, sizeof (fcportdb_t));
3070 lp->probational = 0;
3071 lp->state = FC_PORTDB_STATE_NEW;
3072 lp->portid = lp->new_portid = pdb->portid;
3073 lp->prli_word3 = lp->new_prli_word3 = pdb->prli_word3;
3074 lp->handle = pdb->handle;
3075 lp->port_wwn = wwpn;
3076 lp->node_wwn = wwnn;
3077 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Port 0x%06x@0x%04x is new",
3078 chan, pdb->portid, pdb->handle);
3082 * Scan local loop for devices.
3085 isp_scan_loop(ispsoftc_t *isp, int chan)
3087 fcparam *fcp = FCPARAM(isp, chan);
3090 uint16_t handles[LOCAL_LOOP_LIM];
3093 if (fcp->isp_loopstate < LOOP_LTEST_DONE) {
3096 if (fcp->isp_loopstate > LOOP_SCANNING_LOOP) {
3099 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC loop scan", chan);
3100 if (TOPO_IS_FABRIC(fcp->isp_topo)) {
3101 isp_prt(isp, ISP_LOG_SANCFG,
3102 "Chan %d FC loop scan done (no loop)", chan);
3103 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3106 fcp->isp_loopstate = LOOP_SCANNING_LOOP;
3108 lim = LOCAL_LOOP_LIM;
3109 r = isp_gethandles(isp, chan, handles, &lim, 1, 1);
3111 isp_prt(isp, ISP_LOG_SANCFG,
3112 "Chan %d Getting list of handles failed with %x", chan, r);
3113 isp_prt(isp, ISP_LOG_SANCFG,
3114 "Chan %d FC loop scan done (bad)", chan);
3118 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Got %d handles",
3122 * Run through the list and get the port database info for each one.
3124 for (idx = 0; idx < lim; idx++) {
3125 handle = handles[idx];
3128 * Don't scan "special" ids.
3130 if (ISP_CAP_2KLOGIN(isp)) {
3131 if (handle >= NPH_RESERVED)
3134 if (handle >= FL_ID && handle <= SNS_ID)
3139 * In older cards with older f/w GET_PORT_DATABASE has been
3140 * known to hang. This trick gets around that problem.
3142 if (IS_2100(isp) || IS_2200(isp)) {
3143 uint64_t node_wwn = isp_get_wwn(isp, chan, handle, 1);
3144 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP) {
3146 isp_prt(isp, ISP_LOG_SANCFG,
3147 "Chan %d FC loop scan done (abort)", chan);
3150 if (node_wwn == INI_NONE) {
3156 * Get the port database entity for this index.
3158 r = isp_getpdb(isp, chan, handle, &pdb, 1);
3159 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3162 isp_prt(isp, ISP_LOGDEBUG1,
3163 "Chan %d FC Scan Loop handle %d returned %x",
3165 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3170 isp_pdb_add_update(isp, chan, &pdb);
3172 if (fcp->isp_loopstate < LOOP_SCANNING_LOOP)
3174 fcp->isp_loopstate = LOOP_LSCAN_DONE;
3175 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC loop scan done", chan);
3180 * Scan the fabric for devices and add them to our port database.
3182 * Use the GID_FT command to get all Port IDs for FC4 SCSI devices it knows.
3184 * For 2100-23XX cards, we can use the SNS mailbox command to pass simple
3185 * name server commands to the switch management server via the QLogic f/w.
3187 * For the 24XX card, we have to use CT-Pass through run via the Execute IOCB
3190 * The net result is to leave the list of Port IDs setting untranslated in
3191 * offset IGPOFF of the FC scratch area, whereupon we'll canonicalize it to
3192 * host order at OGPOFF.
3196 * Take half of our scratch area to store Port IDs
3198 #define GIDLEN (ISP_FC_SCRLEN >> 1)
3199 #define NGENT ((GIDLEN - 16) >> 2)
3202 #define OGPOFF (ISP_FC_SCRLEN >> 1)
3203 #define XTXOFF (ISP_FC_SCRLEN - (3 * QENTRY_LEN)) /* CT request */
3204 #define CTXOFF (ISP_FC_SCRLEN - (2 * QENTRY_LEN)) /* Request IOCB */
3205 #define ZTXOFF (ISP_FC_SCRLEN - (1 * QENTRY_LEN)) /* Response IOCB */
3208 isp_gid_ft_sns(ispsoftc_t *isp, int chan)
3211 sns_gid_ft_req_t _x;
3212 uint8_t _y[SNS_GID_FT_REQ_SIZE];
3214 fcparam *fcp = FCPARAM(isp, chan);
3215 sns_gid_ft_req_t *rq = &un._x;
3216 uint8_t *scp = fcp->isp_scratch;
3219 isp_prt(isp, ISP_LOGDEBUG0, "Chan %d scanning fabric (GID_FT) via SNS", chan);
3221 ISP_MEMZERO(rq, SNS_GID_FT_REQ_SIZE);
3222 rq->snscb_rblen = GIDLEN >> 1;
3223 rq->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + IGPOFF);
3224 rq->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + IGPOFF);
3225 rq->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + IGPOFF);
3226 rq->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + IGPOFF);
3227 rq->snscb_sblen = 6;
3228 rq->snscb_cmd = SNS_GID_FT;
3229 rq->snscb_mword_div_2 = NGENT;
3230 rq->snscb_fc4_type = FC4_SCSI;
3232 isp_put_gid_ft_request(isp, rq, (sns_gid_ft_req_t *)&scp[CTXOFF]);
3233 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_GID_FT_REQ_SIZE, chan);
3235 MBSINIT(&mbs, MBOX_SEND_SNS, MBLOGALL, 10000000);
3236 mbs.param[0] = MBOX_SEND_SNS;
3237 mbs.param[1] = SNS_GID_FT_REQ_SIZE >> 1;
3238 mbs.param[2] = DMA_WD1(fcp->isp_scdma + CTXOFF);
3239 mbs.param[3] = DMA_WD0(fcp->isp_scdma + CTXOFF);
3240 mbs.param[6] = DMA_WD3(fcp->isp_scdma + CTXOFF);
3241 mbs.param[7] = DMA_WD2(fcp->isp_scdma + CTXOFF);
3242 isp_mboxcmd(isp, &mbs);
3243 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3244 if (mbs.param[0] == MBOX_INVALID_COMMAND) {
3254 isp_gid_ft_ct_passthru(ispsoftc_t *isp, int chan)
3257 fcparam *fcp = FCPARAM(isp, chan);
3261 uint8_t q[QENTRY_LEN];
3266 uint8_t *scp = fcp->isp_scratch;
3268 isp_prt(isp, ISP_LOGDEBUG0, "Chan %d scanning fabric (GID_FT) via CT", chan);
3271 * Build a Passthrough IOCB in memory.
3274 ISP_MEMZERO(un.q, QENTRY_LEN);
3275 pt->ctp_header.rqs_entry_count = 1;
3276 pt->ctp_header.rqs_entry_type = RQSTYPE_CT_PASSTHRU;
3277 pt->ctp_handle = 0xffffffff;
3278 pt->ctp_nphdl = fcp->isp_sns_hdl;
3279 pt->ctp_cmd_cnt = 1;
3280 pt->ctp_vpidx = ISP_GET_VPIDX(isp, chan);
3282 pt->ctp_rsp_cnt = 1;
3283 pt->ctp_rsp_bcnt = GIDLEN;
3284 pt->ctp_cmd_bcnt = sizeof (*ct) + sizeof (uint32_t);
3285 pt->ctp_dataseg[0].ds_base = DMA_LO32(fcp->isp_scdma+XTXOFF);
3286 pt->ctp_dataseg[0].ds_basehi = DMA_HI32(fcp->isp_scdma+XTXOFF);
3287 pt->ctp_dataseg[0].ds_count = sizeof (*ct) + sizeof (uint32_t);
3288 pt->ctp_dataseg[1].ds_base = DMA_LO32(fcp->isp_scdma+IGPOFF);
3289 pt->ctp_dataseg[1].ds_basehi = DMA_HI32(fcp->isp_scdma+IGPOFF);
3290 pt->ctp_dataseg[1].ds_count = GIDLEN;
3291 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3292 isp_print_bytes(isp, "ct IOCB", QENTRY_LEN, pt);
3294 isp_put_ct_pt(isp, pt, (isp_ct_pt_t *) &scp[CTXOFF]);
3297 * Build the CT header and command in memory.
3299 * Note that the CT header has to end up as Big Endian format in memory.
3302 ISP_MEMZERO(ct, sizeof (*ct));
3303 ct->ct_revision = CT_REVISION;
3304 ct->ct_fcs_type = CT_FC_TYPE_FC;
3305 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3306 ct->ct_cmd_resp = SNS_GID_FT;
3307 ct->ct_bcnt_resid = (GIDLEN - 16) >> 2;
3309 isp_put_ct_hdr(isp, ct, (ct_hdr_t *) &scp[XTXOFF]);
3310 rp = (uint32_t *) &scp[XTXOFF+sizeof (*ct)];
3311 ISP_IOZPUT_32(isp, FC4_SCSI, rp);
3312 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3313 isp_print_bytes(isp, "CT HDR + payload after put",
3314 sizeof (*ct) + sizeof (uint32_t), &scp[XTXOFF]);
3316 ISP_MEMZERO(&scp[ZTXOFF], QENTRY_LEN);
3317 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 500000);
3318 mbs.param[1] = QENTRY_LEN;
3319 mbs.param[2] = DMA_WD1(fcp->isp_scdma + CTXOFF);
3320 mbs.param[3] = DMA_WD0(fcp->isp_scdma + CTXOFF);
3321 mbs.param[6] = DMA_WD3(fcp->isp_scdma + CTXOFF);
3322 mbs.param[7] = DMA_WD2(fcp->isp_scdma + CTXOFF);
3323 MEMORYBARRIER(isp, SYNC_SFORDEV, XTXOFF, 2 * QENTRY_LEN, chan);
3324 isp_mboxcmd(isp, &mbs);
3325 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3328 MEMORYBARRIER(isp, SYNC_SFORCPU, ZTXOFF, QENTRY_LEN, chan);
3330 isp_get_ct_pt(isp, (isp_ct_pt_t *) &scp[ZTXOFF], pt);
3331 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3332 isp_print_bytes(isp, "IOCB response", QENTRY_LEN, pt);
3335 if (pt->ctp_status && pt->ctp_status != RQCS_DATA_UNDERRUN) {
3336 isp_prt(isp, ISP_LOGWARN,
3337 "Chan %d ISP GID FT CT Passthrough returned 0x%x",
3338 chan, pt->ctp_status);
3341 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN, chan);
3342 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3343 isp_print_bytes(isp, "CT response", GIDLEN, &scp[IGPOFF]);
3349 isp_scan_fabric(ispsoftc_t *isp, int chan)
3351 fcparam *fcp = FCPARAM(isp, chan);
3356 int portidx, portlim, r;
3357 sns_gid_ft_rsp_t *rs0, *rs1;
3359 if (fcp->isp_loopstate < LOOP_LSCAN_DONE) {
3362 if (fcp->isp_loopstate > LOOP_SCANNING_FABRIC) {
3365 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC fabric scan", chan);
3366 if (!TOPO_IS_FABRIC(fcp->isp_topo)) {
3367 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3368 isp_prt(isp, ISP_LOG_SANCFG,
3369 "Chan %d FC fabric scan done (no fabric)", chan);
3372 fcp->isp_loopstate = LOOP_SCANNING_FABRIC;
3374 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3375 isp_prt(isp, ISP_LOGERR, sacq);
3377 isp_prt(isp, ISP_LOG_SANCFG,
3378 "Chan %d FC fabric scan done (bad)", chan);
3381 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC) {
3383 FC_SCRATCH_RELEASE(isp, chan);
3384 isp_prt(isp, ISP_LOG_SANCFG,
3385 "Chan %d FC fabric scan done (abort)", chan);
3390 * Make sure we still are logged into the fabric controller.
3392 nphdl = IS_24XX(isp) ? NPH_FL_ID : FL_ID;
3393 r = isp_getpdb(isp, chan, nphdl, &pdb, 0);
3394 if ((r & 0xffff) == MBOX_NOT_LOGGED_IN) {
3395 isp_dump_chip_portdb(isp, chan, 0);
3398 fcp->isp_loopstate = LOOP_LTEST_DONE;
3399 FC_SCRATCH_RELEASE(isp, chan);
3403 /* Get list of port IDs from SNS. */
3405 r = isp_gid_ft_ct_passthru(isp, chan);
3407 r = isp_gid_ft_sns(isp, chan);
3408 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3411 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3412 FC_SCRATCH_RELEASE(isp, chan);
3415 fcp->isp_loopstate = LOOP_LTEST_DONE; /* try again */
3416 FC_SCRATCH_RELEASE(isp, chan);
3420 MEMORYBARRIER(isp, SYNC_SFORCPU, IGPOFF, GIDLEN, chan);
3421 rs0 = (sns_gid_ft_rsp_t *) ((uint8_t *)fcp->isp_scratch+IGPOFF);
3422 rs1 = (sns_gid_ft_rsp_t *) ((uint8_t *)fcp->isp_scratch+OGPOFF);
3423 isp_get_gid_ft_response(isp, rs0, rs1, NGENT);
3424 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3426 if (rs1->snscb_cthdr.ct_cmd_resp != LS_ACC) {
3428 if (rs1->snscb_cthdr.ct_reason == 9 && rs1->snscb_cthdr.ct_explanation == 7) {
3429 level = ISP_LOG_SANCFG;
3431 level = ISP_LOGWARN;
3433 isp_prt(isp, level, "Chan %d Fabric Nameserver rejected GID_FT"
3434 " (Reason=0x%x Expl=0x%x)", chan,
3435 rs1->snscb_cthdr.ct_reason,
3436 rs1->snscb_cthdr.ct_explanation);
3437 FC_SCRATCH_RELEASE(isp, chan);
3438 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3442 /* Check our buffer was big enough to get the full list. */
3443 for (portidx = 0; portidx < NGENT-1; portidx++) {
3444 if (rs1->snscb_ports[portidx].control & 0x80)
3447 if ((rs1->snscb_ports[portidx].control & 0x80) == 0) {
3448 isp_prt(isp, ISP_LOGWARN,
3449 "fabric too big for scratch area: increase ISP_FC_SCRLEN");
3451 portlim = portidx + 1;
3452 isp_prt(isp, ISP_LOG_SANCFG,
3453 "Chan %d Got %d ports back from name server", chan, portlim);
3455 /* Go through the list and remove duplicate port ids. */
3456 for (portidx = 0; portidx < portlim; portidx++) {
3460 ((rs1->snscb_ports[portidx].portid[0]) << 16) |
3461 ((rs1->snscb_ports[portidx].portid[1]) << 8) |
3462 ((rs1->snscb_ports[portidx].portid[2]));
3464 for (npidx = portidx + 1; npidx < portlim; npidx++) {
3465 uint32_t new_portid =
3466 ((rs1->snscb_ports[npidx].portid[0]) << 16) |
3467 ((rs1->snscb_ports[npidx].portid[1]) << 8) |
3468 ((rs1->snscb_ports[npidx].portid[2]));
3469 if (new_portid == portid) {
3474 if (npidx < portlim) {
3475 rs1->snscb_ports[npidx].portid[0] = 0;
3476 rs1->snscb_ports[npidx].portid[1] = 0;
3477 rs1->snscb_ports[npidx].portid[2] = 0;
3478 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d removing duplicate PortID 0x%06x entry from list", chan, portid);
3483 * We now have a list of Port IDs for all FC4 SCSI devices
3484 * that the Fabric Name server knows about.
3486 * For each entry on this list go through our port database looking
3487 * for probational entries- if we find one, then an old entry is
3488 * maybe still this one. We get some information to find out.
3490 * Otherwise, it's a new fabric device, and we log into it
3491 * (unconditionally). After searching the entire database
3492 * again to make sure that we never ever ever ever have more
3493 * than one entry that has the same PortID or the same
3494 * WWNN/WWPN duple, we enter the device into our database.
3497 for (portidx = 0; portidx < portlim; portidx++) {
3498 portid = ((rs1->snscb_ports[portidx].portid[0]) << 16) |
3499 ((rs1->snscb_ports[portidx].portid[1]) << 8) |
3500 ((rs1->snscb_ports[portidx].portid[2]));
3501 isp_prt(isp, ISP_LOG_SANCFG,
3502 "Chan %d Checking fabric port 0x%06x", chan, portid);
3504 isp_prt(isp, ISP_LOG_SANCFG,
3505 "Chan %d Skipping null PortID at idx %d",
3509 if (portid == fcp->isp_portid) {
3510 isp_prt(isp, ISP_LOG_SANCFG,
3511 "Chan %d Skipping our PortID 0x%06x", chan, portid);
3515 /* Now search the entire port database for the same portid. */
3516 if (isp_find_pdb_by_portid(isp, chan, portid, &lp)) {
3517 if (!lp->probational) {
3518 isp_prt(isp, ISP_LOGERR,
3519 "Chan %d Port 0x%06x@0x%04x [%d] is not probational (0x%x)",
3520 chan, lp->portid, lp->handle,
3521 FC_PORTDB_TGT(isp, chan, lp), lp->state);
3522 FC_SCRATCH_RELEASE(isp, chan);
3523 isp_dump_portdb(isp, chan);
3528 * See if we're still logged into it.
3530 * If we aren't, mark it as a dead device and
3531 * leave the new portid in the database entry
3532 * for somebody further along to decide what to
3533 * do (policy choice).
3535 * If we are, check to see if it's the same
3536 * device still (it should be). If for some
3537 * reason it isn't, mark it as a changed device
3538 * and leave the new portid and role in the
3539 * database entry for somebody further along to
3540 * decide what to do (policy choice).
3542 r = isp_getpdb(isp, chan, lp->handle, &pdb, 0);
3543 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3546 lp->state = FC_PORTDB_STATE_DEAD;
3547 isp_prt(isp, ISP_LOG_SANCFG,
3548 "Chan %d Port 0x%06x handle 0x%x is dead (%d)",
3549 chan, portid, lp->handle, r);
3553 isp_pdb_add_update(isp, chan, &pdb);
3558 if ((fcp->role & ISP_ROLE_INITIATOR) == 0)
3561 if (isp_login_device(isp, chan, portid, &pdb,
3562 &FCPARAM(isp, 0)->isp_lasthdl)) {
3563 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3568 isp_pdb_add_update(isp, chan, &pdb);
3571 if (fcp->isp_loopstate < LOOP_SCANNING_FABRIC)
3573 FC_SCRATCH_RELEASE(isp, chan);
3574 fcp->isp_loopstate = LOOP_FSCAN_DONE;
3575 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d FC fabric scan done", chan);
3580 * Find an unused handle and try and use to login to a port.
3583 isp_login_device(ispsoftc_t *isp, int chan, uint32_t portid, isp_pdb_t *p, uint16_t *ohp)
3588 if (ISP_CAP_2KLOGIN(isp)) {
3594 handle = isp_next_handle(isp, ohp);
3595 for (i = 0; i < lim; i++) {
3596 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
3599 /* Check if this handle is free. */
3600 r = isp_getpdb(isp, chan, handle, p, 0);
3602 if (p->portid != portid) {
3603 /* This handle is busy, try next one. */
3604 handle = isp_next_handle(isp, ohp);
3609 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
3613 * Now try and log into the device
3615 r = isp_plogx(isp, chan, handle, portid, PLOGX_FLG_CMD_PLOGI, 1);
3618 } else if ((r & 0xffff) == MBOX_PORT_ID_USED) {
3620 * If we get here, then the firmwware still thinks we're logged into this device, but with a different
3621 * handle. We need to break that association. We used to try and just substitute the handle, but then
3622 * failed to get any data via isp_getpdb (below).
3624 if (isp_plogx(isp, chan, r >> 16, portid, PLOGX_FLG_CMD_LOGO | PLOGX_FLG_IMPLICIT | PLOGX_FLG_FREE_NPHDL, 1)) {
3625 isp_prt(isp, ISP_LOGERR, "baw... logout of %x failed", r >> 16);
3627 if (FCPARAM(isp, chan)->isp_loopstate != LOOP_SCANNING_FABRIC)
3629 r = isp_plogx(isp, chan, handle, portid, PLOGX_FLG_CMD_PLOGI, 1);
3633 } else if ((r & 0xffff) == MBOX_LOOP_ID_USED) {
3634 /* Try the next handle. */
3635 handle = isp_next_handle(isp, ohp);
3644 isp_prt(isp, ISP_LOGWARN, "Chan %d PLOGI 0x%06x failed", chan, portid);
3649 * If we successfully logged into it, get the PDB for it
3650 * so we can crosscheck that it is still what we think it
3651 * is and that we also have the role it plays
3653 r = isp_getpdb(isp, chan, handle, p, 0);
3655 isp_prt(isp, ISP_LOGERR, "Chan %d new device 0x%06x@0x%x disappeared", chan, portid, handle);
3659 if (p->handle != handle || p->portid != portid) {
3660 isp_prt(isp, ISP_LOGERR, "Chan %d new device 0x%06x@0x%x changed (0x%06x@0x%0x)",
3661 chan, portid, handle, p->portid, p->handle);
3668 isp_register_fc4_type(ispsoftc_t *isp, int chan)
3670 fcparam *fcp = FCPARAM(isp, chan);
3671 uint8_t local[SNS_RFT_ID_REQ_SIZE];
3672 sns_screq_t *reqp = (sns_screq_t *) local;
3675 ISP_MEMZERO((void *) reqp, SNS_RFT_ID_REQ_SIZE);
3676 reqp->snscb_rblen = SNS_RFT_ID_RESP_SIZE >> 1;
3677 reqp->snscb_addr[RQRSP_ADDR0015] = DMA_WD0(fcp->isp_scdma + 0x100);
3678 reqp->snscb_addr[RQRSP_ADDR1631] = DMA_WD1(fcp->isp_scdma + 0x100);
3679 reqp->snscb_addr[RQRSP_ADDR3247] = DMA_WD2(fcp->isp_scdma + 0x100);
3680 reqp->snscb_addr[RQRSP_ADDR4863] = DMA_WD3(fcp->isp_scdma + 0x100);
3681 reqp->snscb_sblen = 22;
3682 reqp->snscb_data[0] = SNS_RFT_ID;
3683 reqp->snscb_data[4] = fcp->isp_portid & 0xffff;
3684 reqp->snscb_data[5] = (fcp->isp_portid >> 16) & 0xff;
3685 reqp->snscb_data[6] = (1 << FC4_SCSI);
3686 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3687 isp_prt(isp, ISP_LOGERR, sacq);
3690 isp_put_sns_request(isp, reqp, (sns_screq_t *) fcp->isp_scratch);
3691 MBSINIT(&mbs, MBOX_SEND_SNS, MBLOGALL, 1000000);
3692 mbs.param[1] = SNS_RFT_ID_REQ_SIZE >> 1;
3693 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
3694 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
3695 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
3696 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
3697 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, SNS_RFT_ID_REQ_SIZE, chan);
3698 isp_mboxcmd(isp, &mbs);
3699 FC_SCRATCH_RELEASE(isp, chan);
3700 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
3708 isp_register_fc4_type_24xx(ispsoftc_t *isp, int chan)
3711 fcparam *fcp = FCPARAM(isp, chan);
3715 uint8_t q[QENTRY_LEN];
3720 uint8_t *scp = fcp->isp_scratch;
3722 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3723 isp_prt(isp, ISP_LOGERR, sacq);
3728 * Build a Passthrough IOCB in memory.
3730 ISP_MEMZERO(un.q, QENTRY_LEN);
3732 pt->ctp_header.rqs_entry_count = 1;
3733 pt->ctp_header.rqs_entry_type = RQSTYPE_CT_PASSTHRU;
3734 pt->ctp_handle = 0xffffffff;
3735 pt->ctp_nphdl = fcp->isp_sns_hdl;
3736 pt->ctp_cmd_cnt = 1;
3737 pt->ctp_vpidx = ISP_GET_VPIDX(isp, chan);
3739 pt->ctp_rsp_cnt = 1;
3740 pt->ctp_rsp_bcnt = sizeof (ct_hdr_t);
3741 pt->ctp_cmd_bcnt = sizeof (rft_id_t);
3742 pt->ctp_dataseg[0].ds_base = DMA_LO32(fcp->isp_scdma+XTXOFF);
3743 pt->ctp_dataseg[0].ds_basehi = DMA_HI32(fcp->isp_scdma+XTXOFF);
3744 pt->ctp_dataseg[0].ds_count = sizeof (rft_id_t);
3745 pt->ctp_dataseg[1].ds_base = DMA_LO32(fcp->isp_scdma+IGPOFF);
3746 pt->ctp_dataseg[1].ds_basehi = DMA_HI32(fcp->isp_scdma+IGPOFF);
3747 pt->ctp_dataseg[1].ds_count = sizeof (ct_hdr_t);
3748 isp_put_ct_pt(isp, pt, (isp_ct_pt_t *) &scp[CTXOFF]);
3749 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3750 isp_print_bytes(isp, "IOCB CT Request", QENTRY_LEN, pt);
3754 * Build the CT header and command in memory.
3756 * Note that the CT header has to end up as Big Endian format in memory.
3758 ISP_MEMZERO(&un.clocal, sizeof (un.clocal));
3759 ct = &un.clocal.rftid_hdr;
3760 ct->ct_revision = CT_REVISION;
3761 ct->ct_fcs_type = CT_FC_TYPE_FC;
3762 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3763 ct->ct_cmd_resp = SNS_RFT_ID;
3764 ct->ct_bcnt_resid = (sizeof (rft_id_t) - sizeof (ct_hdr_t)) >> 2;
3766 rp->rftid_portid[0] = fcp->isp_portid >> 16;
3767 rp->rftid_portid[1] = fcp->isp_portid >> 8;
3768 rp->rftid_portid[2] = fcp->isp_portid;
3769 rp->rftid_fc4types[FC4_SCSI >> 5] = 1 << (FC4_SCSI & 0x1f);
3770 isp_put_rft_id(isp, rp, (rft_id_t *) &scp[XTXOFF]);
3771 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3772 isp_print_bytes(isp, "CT Header", QENTRY_LEN, &scp[XTXOFF]);
3775 ISP_MEMZERO(&scp[ZTXOFF], sizeof (ct_hdr_t));
3777 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 1000000);
3778 mbs.param[1] = QENTRY_LEN;
3779 mbs.param[2] = DMA_WD1(fcp->isp_scdma + CTXOFF);
3780 mbs.param[3] = DMA_WD0(fcp->isp_scdma + CTXOFF);
3781 mbs.param[6] = DMA_WD3(fcp->isp_scdma + CTXOFF);
3782 mbs.param[7] = DMA_WD2(fcp->isp_scdma + CTXOFF);
3783 MEMORYBARRIER(isp, SYNC_SFORDEV, XTXOFF, 2 * QENTRY_LEN, chan);
3784 isp_mboxcmd(isp, &mbs);
3785 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3786 FC_SCRATCH_RELEASE(isp, chan);
3789 MEMORYBARRIER(isp, SYNC_SFORCPU, ZTXOFF, QENTRY_LEN, chan);
3791 isp_get_ct_pt(isp, (isp_ct_pt_t *) &scp[ZTXOFF], pt);
3792 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3793 isp_print_bytes(isp, "IOCB response", QENTRY_LEN, pt);
3795 if (pt->ctp_status) {
3796 FC_SCRATCH_RELEASE(isp, chan);
3797 isp_prt(isp, ISP_LOGWARN,
3798 "Chan %d Register FC4 Type CT Passthrough returned 0x%x",
3799 chan, pt->ctp_status);
3803 isp_get_ct_hdr(isp, (ct_hdr_t *) &scp[IGPOFF], ct);
3804 FC_SCRATCH_RELEASE(isp, chan);
3806 if (ct->ct_cmd_resp == LS_RJT) {
3807 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1, "Chan %d Register FC4 Type rejected", chan);
3809 } else if (ct->ct_cmd_resp == LS_ACC) {
3810 isp_prt(isp, ISP_LOG_SANCFG, "Chan %d Register FC4 Type accepted", chan);
3813 isp_prt(isp, ISP_LOGWARN, "Chan %d Register FC4 Type: 0x%x", chan, ct->ct_cmd_resp);
3819 isp_register_fc4_features_24xx(ispsoftc_t *isp, int chan)
3822 fcparam *fcp = FCPARAM(isp, chan);
3826 uint8_t q[QENTRY_LEN];
3831 uint8_t *scp = fcp->isp_scratch;
3833 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
3834 isp_prt(isp, ISP_LOGERR, sacq);
3839 * Build a Passthrough IOCB in memory.
3841 ISP_MEMZERO(un.q, QENTRY_LEN);
3843 pt->ctp_header.rqs_entry_count = 1;
3844 pt->ctp_header.rqs_entry_type = RQSTYPE_CT_PASSTHRU;
3845 pt->ctp_handle = 0xffffffff;
3846 pt->ctp_nphdl = fcp->isp_sns_hdl;
3847 pt->ctp_cmd_cnt = 1;
3848 pt->ctp_vpidx = ISP_GET_VPIDX(isp, chan);
3850 pt->ctp_rsp_cnt = 1;
3851 pt->ctp_rsp_bcnt = sizeof (ct_hdr_t);
3852 pt->ctp_cmd_bcnt = sizeof (rff_id_t);
3853 pt->ctp_dataseg[0].ds_base = DMA_LO32(fcp->isp_scdma+XTXOFF);
3854 pt->ctp_dataseg[0].ds_basehi = DMA_HI32(fcp->isp_scdma+XTXOFF);
3855 pt->ctp_dataseg[0].ds_count = sizeof (rff_id_t);
3856 pt->ctp_dataseg[1].ds_base = DMA_LO32(fcp->isp_scdma+IGPOFF);
3857 pt->ctp_dataseg[1].ds_basehi = DMA_HI32(fcp->isp_scdma+IGPOFF);
3858 pt->ctp_dataseg[1].ds_count = sizeof (ct_hdr_t);
3859 isp_put_ct_pt(isp, pt, (isp_ct_pt_t *) &scp[CTXOFF]);
3860 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3861 isp_print_bytes(isp, "IOCB CT Request", QENTRY_LEN, pt);
3865 * Build the CT header and command in memory.
3867 * Note that the CT header has to end up as Big Endian format in memory.
3869 ISP_MEMZERO(&un.clocal, sizeof (un.clocal));
3870 ct = &un.clocal.rffid_hdr;
3871 ct->ct_revision = CT_REVISION;
3872 ct->ct_fcs_type = CT_FC_TYPE_FC;
3873 ct->ct_fcs_subtype = CT_FC_SUBTYPE_NS;
3874 ct->ct_cmd_resp = SNS_RFF_ID;
3875 ct->ct_bcnt_resid = (sizeof (rff_id_t) - sizeof (ct_hdr_t)) >> 2;
3877 rp->rffid_portid[0] = fcp->isp_portid >> 16;
3878 rp->rffid_portid[1] = fcp->isp_portid >> 8;
3879 rp->rffid_portid[2] = fcp->isp_portid;
3880 rp->rffid_fc4features = 0;
3881 if (fcp->role & ISP_ROLE_TARGET)
3882 rp->rffid_fc4features |= 1;
3883 if (fcp->role & ISP_ROLE_INITIATOR)
3884 rp->rffid_fc4features |= 2;
3885 rp->rffid_fc4type = FC4_SCSI;
3886 isp_put_rff_id(isp, rp, (rff_id_t *) &scp[XTXOFF]);
3887 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3888 isp_print_bytes(isp, "CT Header", QENTRY_LEN, &scp[XTXOFF]);
3891 ISP_MEMZERO(&scp[ZTXOFF], sizeof (ct_hdr_t));
3893 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 1000000);
3894 mbs.param[1] = QENTRY_LEN;
3895 mbs.param[2] = DMA_WD1(fcp->isp_scdma + CTXOFF);
3896 mbs.param[3] = DMA_WD0(fcp->isp_scdma + CTXOFF);
3897 mbs.param[6] = DMA_WD3(fcp->isp_scdma + CTXOFF);
3898 mbs.param[7] = DMA_WD2(fcp->isp_scdma + CTXOFF);
3899 MEMORYBARRIER(isp, SYNC_SFORDEV, XTXOFF, 2 * QENTRY_LEN, chan);
3900 isp_mboxcmd(isp, &mbs);
3901 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
3902 FC_SCRATCH_RELEASE(isp, chan);
3905 MEMORYBARRIER(isp, SYNC_SFORCPU, ZTXOFF, QENTRY_LEN, chan);
3907 isp_get_ct_pt(isp, (isp_ct_pt_t *) &scp[ZTXOFF], pt);
3908 if (isp->isp_dblev & ISP_LOGDEBUG1) {
3909 isp_print_bytes(isp, "IOCB response", QENTRY_LEN, pt);
3911 if (pt->ctp_status) {
3912 FC_SCRATCH_RELEASE(isp, chan);
3913 isp_prt(isp, ISP_LOGWARN,
3914 "Chan %d Register FC4 Features CT Passthrough returned 0x%x",
3915 chan, pt->ctp_status);
3919 isp_get_ct_hdr(isp, (ct_hdr_t *) &scp[IGPOFF], ct);
3920 FC_SCRATCH_RELEASE(isp, chan);
3922 if (ct->ct_cmd_resp == LS_RJT) {
3923 isp_prt(isp, ISP_LOG_SANCFG|ISP_LOG_WARN1,
3924 "Chan %d Register FC4 Features rejected", chan);
3926 } else if (ct->ct_cmd_resp == LS_ACC) {
3927 isp_prt(isp, ISP_LOG_SANCFG,
3928 "Chan %d Register FC4 Features accepted", chan);
3931 isp_prt(isp, ISP_LOGWARN,
3932 "Chan %d Register FC4 Features: 0x%x", chan, ct->ct_cmd_resp);
3938 isp_next_handle(ispsoftc_t *isp, uint16_t *ohp)
3942 uint16_t handle, minh, maxh;
3945 if (ISP_CAP_2KLOGIN(isp)) {
3947 maxh = NPH_RESERVED - 1;
3955 if (handle == NIL_HANDLE) {
3959 if (handle > maxh) {
3961 isp_prt(isp, ISP_LOGERR, "Out of port handles!");
3962 return (NIL_HANDLE);
3967 for (chan = 0; chan < isp->isp_nchan; chan++) {
3968 fcp = FCPARAM(isp, chan);
3969 if (fcp->role == ISP_ROLE_NONE)
3971 for (i = 0; i < MAX_FC_TARG; i++) {
3972 if (fcp->portdb[i].state != FC_PORTDB_STATE_NIL &&
3973 fcp->portdb[i].handle == handle)
3982 * Start a command. Locking is assumed done in the caller.
3989 uint32_t handle, cdblen;
3990 uint8_t local[QENTRY_LEN];
3995 int target, dmaresult;
4001 * Check command CDB length, etc.. We really are limited to 16 bytes
4002 * for Fibre Channel, but can do up to 44 bytes in parallel SCSI,
4003 * but probably only if we're running fairly new firmware (we'll
4004 * let the old f/w choke on an extended command queue entry).
4007 if (XS_CDBLEN(xs) > (IS_FC(isp)? 16 : 44) || XS_CDBLEN(xs) == 0) {
4008 isp_prt(isp, ISP_LOGERR, "unsupported cdb length (%d, CDB[0]=0x%x)", XS_CDBLEN(xs), XS_CDBP(xs)[0] & 0xff);
4009 XS_SETERR(xs, HBA_BOTCH);
4010 return (CMD_COMPLETE);
4014 * Translate the target to device handle as appropriate, checking
4015 * for correct device state as well.
4017 target = XS_TGT(xs);
4019 fcparam *fcp = FCPARAM(isp, XS_CHANNEL(xs));
4021 if ((fcp->role & ISP_ROLE_INITIATOR) == 0) {
4022 isp_prt(isp, ISP_LOG_WARN1,
4023 "%d.%d.%jx I am not an initiator",
4024 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4025 XS_SETERR(xs, HBA_SELTIMEOUT);
4026 return (CMD_COMPLETE);
4029 if (isp->isp_state != ISP_RUNSTATE) {
4030 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
4031 XS_SETERR(xs, HBA_BOTCH);
4032 return (CMD_COMPLETE);
4038 if (fcp->isp_loopstate != LOOP_READY) {
4039 return (CMD_RQLATER);
4042 isp_prt(isp, ISP_LOGDEBUG2, "XS_TGT(xs)=%d", target);
4043 lp = &fcp->portdb[target];
4044 if (target < 0 || target >= MAX_FC_TARG ||
4045 lp->is_target == 0) {
4046 XS_SETERR(xs, HBA_SELTIMEOUT);
4047 return (CMD_COMPLETE);
4049 if (lp->state == FC_PORTDB_STATE_ZOMBIE) {
4050 isp_prt(isp, ISP_LOGDEBUG1,
4051 "%d.%d.%jx target zombie",
4052 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4053 return (CMD_RQLATER);
4055 if (lp->state != FC_PORTDB_STATE_VALID) {
4056 isp_prt(isp, ISP_LOGDEBUG1,
4057 "%d.%d.%jx bad db port state 0x%x",
4058 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs), lp->state);
4059 XS_SETERR(xs, HBA_SELTIMEOUT);
4060 return (CMD_COMPLETE);
4063 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
4064 if ((sdp->role & ISP_ROLE_INITIATOR) == 0) {
4065 isp_prt(isp, ISP_LOGDEBUG1,
4066 "%d.%d.%jx I am not an initiator",
4067 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4068 XS_SETERR(xs, HBA_SELTIMEOUT);
4069 return (CMD_COMPLETE);
4072 if (isp->isp_state != ISP_RUNSTATE) {
4073 isp_prt(isp, ISP_LOGERR, "Adapter not at RUNSTATE");
4074 XS_SETERR(xs, HBA_BOTCH);
4075 return (CMD_COMPLETE);
4079 isp_spi_update(isp, XS_CHANNEL(xs));
4086 qep = isp_getrqentry(isp);
4088 isp_prt(isp, ISP_LOG_WARN1, "Request Queue Overflow");
4089 XS_SETERR(xs, HBA_BOTCH);
4090 return (CMD_EAGAIN);
4092 XS_SETERR(xs, HBA_NOERROR);
4095 * Now see if we need to synchronize the ISP with respect to anything.
4096 * We do dual duty here (cough) for synchronizing for busses other
4097 * than which we got here to send a command to.
4099 reqp = (ispreq_t *) local;
4100 ISP_MEMZERO(local, QENTRY_LEN);
4101 if (ISP_TST_SENDMARKER(isp, XS_CHANNEL(xs))) {
4103 isp_marker_24xx_t *m = (isp_marker_24xx_t *) reqp;
4104 m->mrk_header.rqs_entry_count = 1;
4105 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4106 m->mrk_modifier = SYNC_ALL;
4107 m->mrk_vphdl = XS_CHANNEL(xs);
4108 isp_put_marker_24xx(isp, m, qep);
4110 isp_marker_t *m = (isp_marker_t *) reqp;
4111 m->mrk_header.rqs_entry_count = 1;
4112 m->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
4113 m->mrk_target = (XS_CHANNEL(xs) << 7); /* bus # */
4114 m->mrk_modifier = SYNC_ALL;
4115 isp_put_marker(isp, m, qep);
4117 ISP_SYNC_REQUEST(isp);
4118 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 0);
4122 reqp->req_header.rqs_entry_count = 1;
4125 * Select and install Header Code.
4126 * Note that it might be overridden before going out
4127 * if we're on a 64 bit platform. The lower level
4128 * code (isp_send_cmd) will select the appropriate
4129 * 64 bit variant if it needs to.
4132 reqp->req_header.rqs_entry_type = RQSTYPE_T7RQS;
4133 } else if (IS_FC(isp)) {
4134 reqp->req_header.rqs_entry_type = RQSTYPE_T2RQS;
4136 if (XS_CDBLEN(xs) > 12) {
4137 reqp->req_header.rqs_entry_type = RQSTYPE_CMDONLY;
4139 reqp->req_header.rqs_entry_type = RQSTYPE_REQUEST;
4144 * Set task attributes
4149 ttype = XS_TAG_TYPE(xs);
4151 if (XS_CDBP(xs)[0] == 0x3) {
4152 ttype = REQFLAG_HTAG;
4154 ttype = REQFLAG_STAG;
4157 if (ttype == REQFLAG_OTAG) {
4158 ttype = FCP_CMND_TASK_ATTR_ORDERED;
4159 } else if (ttype == REQFLAG_HTAG) {
4160 ttype = FCP_CMND_TASK_ATTR_HEAD;
4162 ttype = FCP_CMND_TASK_ATTR_SIMPLE;
4164 ((ispreqt7_t *)reqp)->req_task_attribute = ttype;
4165 } else if (IS_FC(isp)) {
4167 * See comment in isp_intr
4169 /* XS_SET_RESID(xs, 0); */
4172 * Fibre Channel always requires some kind of tag.
4173 * The Qlogic drivers seem be happy not to use a tag,
4174 * but this breaks for some devices (IBM drives).
4177 ((ispreqt2_t *)reqp)->req_flags = XS_TAG_TYPE(xs);
4180 * If we don't know what tag to use, use HEAD OF QUEUE
4181 * for Request Sense or Simple.
4183 if (XS_CDBP(xs)[0] == 0x3) /* REQUEST SENSE */
4184 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_HTAG;
4186 ((ispreqt2_t *)reqp)->req_flags = REQFLAG_STAG;
4189 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
4190 if ((sdp->isp_devparam[target].actv_flags & DPARM_TQING) && XS_TAG_P(xs)) {
4191 reqp->req_flags = XS_TAG_TYPE(xs);
4195 tptr = &reqp->req_time;
4198 * NB: we do not support long CDBs (yet)
4200 cdblen = XS_CDBLEN(xs);
4203 if (cdblen > sizeof (reqp->req_cdb)) {
4204 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4205 XS_SETERR(xs, HBA_BOTCH);
4206 return (CMD_COMPLETE);
4208 reqp->req_target = target | (XS_CHANNEL(xs) << 7);
4209 reqp->req_lun_trn = XS_LUN(xs);
4210 cdbp = reqp->req_cdb;
4211 reqp->req_cdblen = cdblen;
4212 } else if (IS_24XX(isp)) {
4213 ispreqt7_t *t7 = (ispreqt7_t *)local;
4215 if (cdblen > sizeof (t7->req_cdb)) {
4216 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4217 XS_SETERR(xs, HBA_BOTCH);
4218 return (CMD_COMPLETE);
4221 t7->req_nphdl = lp->handle;
4222 t7->req_tidlo = lp->portid;
4223 t7->req_tidhi = lp->portid >> 16;
4224 t7->req_vpidx = ISP_GET_VPIDX(isp, XS_CHANNEL(xs));
4225 #if __FreeBSD_version >= 1000700
4226 be64enc(t7->req_lun, CAM_EXTLUN_BYTE_SWIZZLE(XS_LUN(xs)));
4228 if (XS_LUN(xs) >= 256) {
4229 t7->req_lun[0] = XS_LUN(xs) >> 8;
4230 t7->req_lun[0] |= 0x40;
4232 t7->req_lun[1] = XS_LUN(xs);
4234 if (FCPARAM(isp, XS_CHANNEL(xs))->fctape_enabled && (lp->prli_word3 & PRLI_WD3_RETRY)) {
4235 if (FCP_NEXT_CRN(isp, &t7->req_crn, xs)) {
4236 isp_prt(isp, ISP_LOG_WARN1,
4237 "%d.%d.%jx cannot generate next CRN",
4238 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4239 XS_SETERR(xs, HBA_BOTCH);
4240 return (CMD_EAGAIN);
4243 tptr = &t7->req_time;
4246 ispreqt2_t *t2 = (ispreqt2_t *)local;
4248 if (cdblen > sizeof t2->req_cdb) {
4249 isp_prt(isp, ISP_LOGERR, "Command Length %u too long for this chip", cdblen);
4250 XS_SETERR(xs, HBA_BOTCH);
4251 return (CMD_COMPLETE);
4253 if (FCPARAM(isp, XS_CHANNEL(xs))->fctape_enabled && (lp->prli_word3 & PRLI_WD3_RETRY)) {
4254 if (FCP_NEXT_CRN(isp, &t2->req_crn, xs)) {
4255 isp_prt(isp, ISP_LOG_WARN1,
4256 "%d.%d.%jx cannot generate next CRN",
4257 XS_CHANNEL(xs), target, (uintmax_t)XS_LUN(xs));
4258 XS_SETERR(xs, HBA_BOTCH);
4259 return (CMD_EAGAIN);
4262 if (ISP_CAP_2KLOGIN(isp)) {
4263 ispreqt2e_t *t2e = (ispreqt2e_t *)local;
4264 t2e->req_target = lp->handle;
4265 t2e->req_scclun = XS_LUN(xs);
4266 #if __FreeBSD_version < 1000700
4267 if (XS_LUN(xs) >= 256)
4268 t2e->req_scclun |= 0x4000;
4270 cdbp = t2e->req_cdb;
4271 } else if (ISP_CAP_SCCFW(isp)) {
4272 ispreqt2_t *t2 = (ispreqt2_t *)local;
4273 t2->req_target = lp->handle;
4274 t2->req_scclun = XS_LUN(xs);
4275 #if __FreeBSD_version < 1000700
4276 if (XS_LUN(xs) >= 256)
4277 t2->req_scclun |= 0x4000;
4281 t2->req_target = lp->handle;
4282 t2->req_lun_trn = XS_LUN(xs);
4286 ISP_MEMCPY(cdbp, XS_CDBP(xs), cdblen);
4288 *tptr = XS_TIME(xs) / 1000;
4289 if (*tptr == 0 && XS_TIME(xs)) {
4292 if (IS_24XX(isp) && *tptr > 0x1999) {
4296 if (isp_allocate_xs(isp, xs, &handle)) {
4297 isp_prt(isp, ISP_LOG_WARN1, "out of xflist pointers");
4298 XS_SETERR(xs, HBA_BOTCH);
4299 return (CMD_EAGAIN);
4301 /* Whew. Thankfully the same for type 7 requests */
4302 reqp->req_handle = handle;
4305 * Set up DMA and/or do any platform dependent swizzling of the request entry
4306 * so that the Qlogic F/W understands what is being asked of it.
4308 * The callee is responsible for adding all requests at this point.
4310 dmaresult = ISP_DMASETUP(isp, xs, reqp);
4311 if (dmaresult != CMD_QUEUED) {
4312 isp_destroy_handle(isp, handle);
4314 * dmasetup sets actual error in packet, and
4315 * return what we were given to return.
4319 isp_xs_prt(isp, xs, ISP_LOGDEBUG0, "START cmd cdb[0]=0x%x datalen %ld", XS_CDBP(xs)[0], (long) XS_XFRLEN(xs));
4321 return (CMD_QUEUED);
4326 * Locks (ints blocked) assumed held.
4330 isp_control(ispsoftc_t *isp, ispctl_t ctl, ...)
4339 case ISPCTL_RESET_BUS:
4341 * Issue a bus reset.
4344 isp_prt(isp, ISP_LOGERR, "BUS RESET NOT IMPLEMENTED");
4346 } else if (IS_FC(isp)) {
4351 chan = va_arg(ap, int);
4353 mbs.param[1] = SDPARAM(isp, chan)->isp_bus_reset_delay;
4354 if (mbs.param[1] < 2) {
4357 mbs.param[2] = chan;
4359 MBSINIT(&mbs, MBOX_BUS_RESET, MBLOGALL, 0);
4360 ISP_SET_SENDMARKER(isp, chan, 1);
4361 isp_mboxcmd(isp, &mbs);
4362 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4365 isp_prt(isp, ISP_LOGINFO, "driver initiated bus reset of bus %d", chan);
4368 case ISPCTL_RESET_DEV:
4370 chan = va_arg(ap, int);
4371 tgt = va_arg(ap, int);
4374 uint8_t local[QENTRY_LEN];
4376 isp24xx_statusreq_t *sp;
4377 fcparam *fcp = FCPARAM(isp, chan);
4380 if (tgt < 0 || tgt >= MAX_FC_TARG) {
4381 isp_prt(isp, ISP_LOGWARN, "Chan %d trying to reset bad target %d", chan, tgt);
4384 lp = &fcp->portdb[tgt];
4385 if (lp->is_target == 0 ||
4386 lp->state != FC_PORTDB_STATE_VALID) {
4387 isp_prt(isp, ISP_LOGWARN, "Chan %d abort of no longer valid target %d", chan, tgt);
4391 tmf = (isp24xx_tmf_t *) local;
4392 ISP_MEMZERO(tmf, QENTRY_LEN);
4393 tmf->tmf_header.rqs_entry_type = RQSTYPE_TSK_MGMT;
4394 tmf->tmf_header.rqs_entry_count = 1;
4395 tmf->tmf_nphdl = lp->handle;
4397 tmf->tmf_timeout = 2;
4398 tmf->tmf_flags = ISP24XX_TMF_TARGET_RESET;
4399 tmf->tmf_tidlo = lp->portid;
4400 tmf->tmf_tidhi = lp->portid >> 16;
4401 tmf->tmf_vpidx = ISP_GET_VPIDX(isp, chan);
4402 isp_prt(isp, ISP_LOGALL, "Chan %d Reset N-Port Handle 0x%04x @ Port 0x%06x", chan, lp->handle, lp->portid);
4403 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 5000000);
4404 mbs.param[1] = QENTRY_LEN;
4405 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
4406 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
4407 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
4408 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
4410 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4411 isp_prt(isp, ISP_LOGERR, sacq);
4414 isp_put_24xx_tmf(isp, tmf, fcp->isp_scratch);
4415 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, QENTRY_LEN, chan);
4416 fcp->sendmarker = 1;
4417 isp_mboxcmd(isp, &mbs);
4418 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4419 FC_SCRATCH_RELEASE(isp, chan);
4422 MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN, QENTRY_LEN, chan);
4423 sp = (isp24xx_statusreq_t *) local;
4424 isp_get_24xx_response(isp, &((isp24xx_statusreq_t *)fcp->isp_scratch)[1], sp);
4425 FC_SCRATCH_RELEASE(isp, chan);
4426 if (sp->req_completion_status == 0) {
4429 isp_prt(isp, ISP_LOGWARN, "Chan %d reset of target %d returned 0x%x", chan, tgt, sp->req_completion_status);
4431 } else if (IS_FC(isp)) {
4432 if (ISP_CAP_2KLOGIN(isp)) {
4434 mbs.ibits = (1 << 10);
4436 mbs.param[1] = (tgt << 8);
4439 mbs.param[1] = (chan << 15) | (tgt << 8);
4441 MBSINIT(&mbs, MBOX_ABORT_TARGET, MBLOGALL, 0);
4442 mbs.param[2] = 3; /* 'delay', in seconds */
4443 isp_mboxcmd(isp, &mbs);
4444 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4447 isp_prt(isp, ISP_LOGINFO, "Target %d on Bus %d Reset Succeeded", tgt, chan);
4448 ISP_SET_SENDMARKER(isp, chan, 1);
4451 case ISPCTL_ABORT_CMD:
4453 xs = va_arg(ap, XS_T *);
4457 chan = XS_CHANNEL(xs);
4459 handle = isp_find_handle(isp, xs);
4461 isp_prt(isp, ISP_LOGWARN, "cannot find handle for command to abort");
4465 isp24xx_abrt_t local, *ab = &local, *ab2;
4469 fcp = FCPARAM(isp, chan);
4470 if (tgt < 0 || tgt >= MAX_FC_TARG) {
4471 isp_prt(isp, ISP_LOGWARN, "Chan %d trying to abort bad target %d", chan, tgt);
4474 lp = &fcp->portdb[tgt];
4475 if (lp->is_target == 0 ||
4476 lp->state != FC_PORTDB_STATE_VALID) {
4477 isp_prt(isp, ISP_LOGWARN, "Chan %d abort of no longer valid target %d", chan, tgt);
4480 isp_prt(isp, ISP_LOGALL, "Chan %d Abort Cmd for N-Port 0x%04x @ Port 0x%06x", chan, lp->handle, lp->portid);
4481 ISP_MEMZERO(ab, QENTRY_LEN);
4482 ab->abrt_header.rqs_entry_type = RQSTYPE_ABORT_IO;
4483 ab->abrt_header.rqs_entry_count = 1;
4484 ab->abrt_handle = lp->handle;
4485 ab->abrt_cmd_handle = handle;
4486 ab->abrt_tidlo = lp->portid;
4487 ab->abrt_tidhi = lp->portid >> 16;
4488 ab->abrt_vpidx = ISP_GET_VPIDX(isp, chan);
4490 ISP_MEMZERO(&mbs, sizeof (mbs));
4491 MBSINIT(&mbs, MBOX_EXEC_COMMAND_IOCB_A64, MBLOGALL, 5000000);
4492 mbs.param[1] = QENTRY_LEN;
4493 mbs.param[2] = DMA_WD1(fcp->isp_scdma);
4494 mbs.param[3] = DMA_WD0(fcp->isp_scdma);
4495 mbs.param[6] = DMA_WD3(fcp->isp_scdma);
4496 mbs.param[7] = DMA_WD2(fcp->isp_scdma);
4498 if (FC_SCRATCH_ACQUIRE(isp, chan)) {
4499 isp_prt(isp, ISP_LOGERR, sacq);
4502 isp_put_24xx_abrt(isp, ab, fcp->isp_scratch);
4503 ab2 = (isp24xx_abrt_t *) &((uint8_t *)fcp->isp_scratch)[QENTRY_LEN];
4504 ab2->abrt_nphdl = 0xdeaf;
4505 MEMORYBARRIER(isp, SYNC_SFORDEV, 0, 2 * QENTRY_LEN, chan);
4506 isp_mboxcmd(isp, &mbs);
4507 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4508 FC_SCRATCH_RELEASE(isp, chan);
4511 MEMORYBARRIER(isp, SYNC_SFORCPU, QENTRY_LEN, QENTRY_LEN, chan);
4512 isp_get_24xx_abrt(isp, ab2, ab);
4513 FC_SCRATCH_RELEASE(isp, chan);
4514 if (ab->abrt_nphdl == ISP24XX_ABRT_OKAY) {
4517 isp_prt(isp, ISP_LOGWARN, "Chan %d handle %d abort returned 0x%x", chan, tgt, ab->abrt_nphdl);
4519 } else if (IS_FC(isp)) {
4520 if (ISP_CAP_SCCFW(isp)) {
4521 if (ISP_CAP_2KLOGIN(isp)) {
4524 mbs.param[1] = tgt << 8;
4526 mbs.param[6] = XS_LUN(xs);
4528 mbs.param[1] = tgt << 8 | XS_LUN(xs);
4531 mbs.param[1] = (chan << 15) | (tgt << 8) | XS_LUN(xs);
4533 MBSINIT(&mbs, MBOX_ABORT,
4534 MBLOGALL & ~MBLOGMASK(MBOX_COMMAND_ERROR), 0);
4535 mbs.param[2] = handle;
4536 isp_mboxcmd(isp, &mbs);
4537 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
4542 case ISPCTL_UPDATE_PARAMS:
4545 chan = va_arg(ap, int);
4547 isp_spi_update(isp, chan);
4550 case ISPCTL_FCLINK_TEST:
4555 chan = va_arg(ap, int);
4556 usdelay = va_arg(ap, int);
4561 return (isp_fclink_test(isp, chan, usdelay));
4565 case ISPCTL_SCAN_FABRIC:
4569 chan = va_arg(ap, int);
4571 return (isp_scan_fabric(isp, chan));
4575 case ISPCTL_SCAN_LOOP:
4579 chan = va_arg(ap, int);
4581 return (isp_scan_loop(isp, chan));
4585 case ISPCTL_PDB_SYNC:
4589 chan = va_arg(ap, int);
4591 return (isp_pdb_sync(isp, chan));
4595 case ISPCTL_SEND_LIP:
4597 if (IS_FC(isp) && !IS_24XX(isp)) {
4598 MBSINIT(&mbs, MBOX_INIT_LIP, MBLOGALL, 0);
4599 if (ISP_CAP_2KLOGIN(isp)) {
4600 mbs.ibits = (1 << 10);
4602 isp_mboxcmd(isp, &mbs);
4603 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
4609 case ISPCTL_GET_PDB:
4613 chan = va_arg(ap, int);
4614 tgt = va_arg(ap, int);
4615 pdb = va_arg(ap, isp_pdb_t *);
4617 return (isp_getpdb(isp, chan, tgt, pdb, 1));
4621 case ISPCTL_GET_NAMES:
4623 uint64_t *wwnn, *wwnp;
4625 chan = va_arg(ap, int);
4626 tgt = va_arg(ap, int);
4627 wwnn = va_arg(ap, uint64_t *);
4628 wwnp = va_arg(ap, uint64_t *);
4630 if (wwnn == NULL && wwnp == NULL) {
4634 *wwnn = isp_get_wwn(isp, chan, tgt, 1);
4635 if (*wwnn == INI_NONE) {
4640 *wwnp = isp_get_wwn(isp, chan, tgt, 0);
4641 if (*wwnp == INI_NONE) {
4647 case ISPCTL_RUN_MBOXCMD:
4650 mbr = va_arg(ap, mbreg_t *);
4652 isp_mboxcmd(isp, mbr);
4661 p = va_arg(ap, isp_plcmd_t *);
4664 if ((p->flags & PLOGX_FLG_CMD_MASK) != PLOGX_FLG_CMD_PLOGI || (p->handle != NIL_HANDLE)) {
4665 return (isp_plogx(isp, p->channel, p->handle, p->portid, p->flags, 0));
4668 isp_next_handle(isp, &p->handle);
4669 r = isp_plogx(isp, p->channel, p->handle, p->portid, p->flags, 0);
4670 if ((r & 0xffff) == MBOX_PORT_ID_USED) {
4671 p->handle = r >> 16;
4675 } while ((r & 0xffff) == MBOX_LOOP_ID_USED);
4678 case ISPCTL_CHANGE_ROLE:
4683 chan = va_arg(ap, int);
4684 role = va_arg(ap, int);
4687 r = isp_fc_change_role(isp, chan, role);
4689 SDPARAM(isp, chan)->role = role;
4695 isp_prt(isp, ISP_LOGERR, "Unknown Control Opcode 0x%x", ctl);
4703 * Interrupt Service Routine(s).
4705 * External (OS) framework has done the appropriate locking,
4706 * and the locking will be held throughout this function.
4710 * Limit our stack depth by sticking with the max likely number
4711 * of completions on a request queue at any one time.
4713 #ifndef MAX_REQUESTQ_COMPLETIONS
4714 #define MAX_REQUESTQ_COMPLETIONS 32
4718 isp_intr(ispsoftc_t *isp, uint16_t isr, uint16_t sema, uint16_t info)
4720 XS_T *complist[MAX_REQUESTQ_COMPLETIONS], *xs;
4721 uint32_t iptr, optr, junk;
4722 int i, nlooked = 0, ndone = 0, continuations_expected = 0;
4723 int etype, last_etype = 0;
4727 * Is this a mailbox related interrupt?
4728 * The mailbox semaphore will be nonzero if so.
4732 if (info & MBOX_COMMAND_COMPLETE) {
4733 isp->isp_intmboxc++;
4734 if (isp->isp_mboxbsy) {
4735 int obits = isp->isp_obits;
4736 isp->isp_mboxtmp[0] = info;
4737 for (i = 1; i < ISP_NMBOX(isp); i++) {
4738 if ((obits & (1 << i)) == 0) {
4741 isp->isp_mboxtmp[i] = ISP_READ(isp, MBOX_OFF(i));
4743 if (isp->isp_mbxwrk0) {
4744 if (isp_mbox_continue(isp) == 0) {
4748 MBOX_NOTIFY_COMPLETE(isp);
4750 isp_prt(isp, ISP_LOGWARN, "mailbox cmd (0x%x) with no waiters", info);
4753 i = IS_FC(isp)? isp_parse_async_fc(isp, info) : isp_parse_async(isp, info);
4758 if ((IS_FC(isp) && info != ASYNC_RIOZIO_STALL) || isp->isp_state != ISP_RUNSTATE) {
4764 * We can't be getting this now.
4766 if (isp->isp_state != ISP_RUNSTATE) {
4768 * This seems to happen to 23XX and 24XX cards- don't know why.
4770 if (isp->isp_mboxbsy && isp->isp_lastmbxcmd == MBOX_ABOUT_FIRMWARE) {
4773 isp_prt(isp, ISP_LOGINFO, "interrupt (ISR=%x SEMA=%x INFO=%x) "
4774 "when not ready", isr, sema, info);
4776 * Thank you very much! *Burrrp*!
4778 isp->isp_residx = ISP_READ(isp, isp->isp_respinrp);
4779 isp->isp_resodx = isp->isp_residx;
4780 ISP_WRITE(isp, isp->isp_respoutrp, isp->isp_resodx);
4782 ISP_DISABLE_INTS(isp);
4787 #ifdef ISP_TARGET_MODE
4789 * Check for ATIO Queue entries.
4792 (isr == ISPR2HST_ATIO_UPDATE || isr == ISPR2HST_ATIO_RSPQ_UPDATE ||
4793 isr == ISPR2HST_ATIO_UPDATE2)) {
4794 iptr = ISP_READ(isp, BIU2400_ATIO_RSPINP);
4795 optr = isp->isp_atioodx;
4797 while (optr != iptr) {
4798 uint8_t qe[QENTRY_LEN];
4804 MEMORYBARRIER(isp, SYNC_ATIOQ, oop, QENTRY_LEN, -1);
4805 addr = ISP_QUEUE_ENTRY(isp->isp_atioq, oop);
4806 isp_get_hdr(isp, addr, (isphdr_t *)qe);
4807 hp = (isphdr_t *)qe;
4808 switch (hp->rqs_entry_type) {
4809 case RQSTYPE_NOTIFY:
4811 (void) isp_target_notify(isp, addr, &oop);
4814 isp_print_qentry(isp, "?ATIOQ entry?", oop, addr);
4817 optr = ISP_NXT_QENTRY(oop, RESULT_QUEUE_LEN(isp));
4819 if (isp->isp_atioodx != optr) {
4820 ISP_WRITE(isp, BIU2400_ATIO_RSPOUTP, optr);
4821 isp->isp_atioodx = optr;
4827 * You *must* read the Response Queue In Pointer
4828 * prior to clearing the RISC interrupt.
4830 * Debounce the 2300 if revision less than 2.
4832 if (IS_2100(isp) || (IS_2300(isp) && isp->isp_revision < 2)) {
4835 iptr = ISP_READ(isp, isp->isp_respinrp);
4836 junk = ISP_READ(isp, isp->isp_respinrp);
4837 } while (junk != iptr && ++i < 1000);
4840 isp_prt(isp, ISP_LOGWARN, "Response Queue Out Pointer Unstable (%x, %x)", iptr, junk);
4844 iptr = ISP_READ(isp, isp->isp_respinrp);
4847 optr = isp->isp_resodx;
4848 if (optr == iptr && sema == 0) {
4850 * There are a lot of these- reasons unknown- mostly on
4851 * faster Alpha machines.
4853 * I tried delaying after writing HCCR_CMD_CLEAR_RISC_INT to
4854 * make sure the old interrupt went away (to avoid 'ringing'
4855 * effects), but that didn't stop this from occurring.
4859 } else if (IS_23XX(isp)) {
4861 iptr = ISP_READ(isp, isp->isp_respinrp);
4862 junk = ISP_READ(isp, BIU_R2HSTSLO);
4864 junk = ISP_READ(isp, BIU_ISR);
4867 if (IS_23XX(isp) || IS_24XX(isp)) {
4870 sema = ISP_READ(isp, BIU_SEMA);
4871 info = ISP_READ(isp, OUTMAILBOX0);
4872 if ((sema & 0x3) && (info & 0x8000)) {
4876 isp->isp_intbogus++;
4877 isp_prt(isp, ISP_LOGDEBUG1, "bogus intr- isr %x (%x) iptr %x optr %x", isr, junk, iptr, optr);
4880 isp->isp_residx = iptr;
4882 while (optr != iptr) {
4883 uint8_t qe[QENTRY_LEN];
4884 ispstatusreq_t *sp = (ispstatusreq_t *) qe;
4886 int buddaboom, scsi_status, completion_status;
4887 int req_status_flags, req_state_flags;
4888 uint8_t *snsp, *resp;
4889 uint32_t rlen, slen, totslen;
4893 hp = (isphdr_t *) ISP_QUEUE_ENTRY(isp->isp_result, optr);
4895 optr = ISP_NXT_QENTRY(optr, RESULT_QUEUE_LEN(isp));
4898 buddaboom = req_status_flags = req_state_flags = 0;
4902 * Synchronize our view of this response queue entry.
4904 MEMORYBARRIER(isp, SYNC_RESULT, oop, QENTRY_LEN, -1);
4905 isp_get_hdr(isp, hp, &sp->req_header);
4906 etype = sp->req_header.rqs_entry_type;
4908 if (IS_24XX(isp) && etype == RQSTYPE_RESPONSE) {
4909 isp24xx_statusreq_t *sp2 = (isp24xx_statusreq_t *)qe;
4910 isp_get_24xx_response(isp, (isp24xx_statusreq_t *)hp, sp2);
4911 if (isp->isp_dblev & ISP_LOGDEBUG1) {
4912 isp_print_bytes(isp, "Response Queue Entry", QENTRY_LEN, sp2);
4914 scsi_status = sp2->req_scsi_status;
4915 completion_status = sp2->req_completion_status;
4916 if ((scsi_status & 0xff) != 0)
4917 req_state_flags = RQSF_GOT_STATUS;
4919 req_state_flags = 0;
4920 resid = sp2->req_resid;
4921 } else if (etype == RQSTYPE_RESPONSE) {
4922 isp_get_response(isp, (ispstatusreq_t *) hp, sp);
4923 if (isp->isp_dblev & ISP_LOGDEBUG1) {
4924 isp_print_bytes(isp, "Response Queue Entry", QENTRY_LEN, sp);
4926 scsi_status = sp->req_scsi_status;
4927 completion_status = sp->req_completion_status;
4928 req_status_flags = sp->req_status_flags;
4929 req_state_flags = sp->req_state_flags;
4930 resid = sp->req_resid;
4931 } else if (etype == RQSTYPE_RIO1) {
4932 isp_rio1_t *rio = (isp_rio1_t *) qe;
4933 isp_get_rio1(isp, (isp_rio1_t *) hp, rio);
4934 if (isp->isp_dblev & ISP_LOGDEBUG1) {
4935 isp_print_bytes(isp, "Response Queue Entry", QENTRY_LEN, rio);
4937 for (i = 0; i < rio->req_header.rqs_seqno; i++) {
4938 isp_fastpost_complete(isp, rio->req_handles[i]);
4940 if (isp->isp_fpcchiwater < rio->req_header.rqs_seqno) {
4941 isp->isp_fpcchiwater = rio->req_header.rqs_seqno;
4943 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
4946 } else if (etype == RQSTYPE_RIO2) {
4947 isp_prt(isp, ISP_LOGERR, "dropping RIO2 response");
4948 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
4951 } else if (etype == RQSTYPE_STATUS_CONT) {
4952 isp_get_cont_response(isp, (ispstatus_cont_t *) hp, (ispstatus_cont_t *) sp);
4953 if (last_etype == RQSTYPE_RESPONSE && continuations_expected && ndone > 0 && (xs = complist[ndone-1]) != NULL) {
4954 ispstatus_cont_t *scp = (ispstatus_cont_t *) sp;
4955 XS_SENSE_APPEND(xs, scp->req_sense_data, sizeof (scp->req_sense_data));
4956 isp_prt(isp, ISP_LOGDEBUG0|ISP_LOG_CWARN, "%d more Status Continuations expected", --continuations_expected);
4958 isp_prt(isp, ISP_LOG_WARN1, "Ignored Continuation Response");
4960 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
4964 * Somebody reachable via isp_handle_other_response
4965 * may have updated the response queue pointers for
4966 * us, so we reload our goal index.
4969 uint32_t tsto = oop;
4970 r = isp_handle_other_response(isp, etype, hp, &tsto);
4975 * If somebody updated the output pointer, then reset
4976 * optr to be one more than the updated amount.
4978 while (tsto != oop) {
4979 optr = ISP_NXT_QENTRY(tsto, RESULT_QUEUE_LEN(isp));
4982 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
4988 * After this point, we'll just look at the header as
4989 * we don't know how to deal with the rest of the
4994 * It really has to be a bounced request just copied
4995 * from the request queue to the response queue. If
4996 * not, something bad has happened.
4998 if (etype != RQSTYPE_REQUEST) {
4999 isp_prt(isp, ISP_LOGERR, notresp, etype, oop, optr, nlooked);
5000 isp_print_bytes(isp, "Request Queue Entry", QENTRY_LEN, sp);
5001 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5006 scsi_status = sp->req_scsi_status;
5007 completion_status = sp->req_completion_status;
5008 req_status_flags = sp->req_status_flags;
5009 req_state_flags = sp->req_state_flags;
5010 resid = sp->req_resid;
5013 if (sp->req_header.rqs_flags & RQSFLAG_MASK) {
5014 if (sp->req_header.rqs_flags & RQSFLAG_CONTINUATION) {
5015 isp_print_bytes(isp, "unexpected continuation segment", QENTRY_LEN, sp);
5019 if (sp->req_header.rqs_flags & RQSFLAG_FULL) {
5020 isp_prt(isp, ISP_LOG_WARN1, "internal queues full");
5022 * We'll synthesize a QUEUE FULL message below.
5025 if (sp->req_header.rqs_flags & RQSFLAG_BADHEADER) {
5026 isp_print_bytes(isp, "bad header flag", QENTRY_LEN, sp);
5029 if (sp->req_header.rqs_flags & RQSFLAG_BADPACKET) {
5030 isp_print_bytes(isp, "bad request packet", QENTRY_LEN, sp);
5033 if (sp->req_header.rqs_flags & RQSFLAG_BADCOUNT) {
5034 isp_print_bytes(isp, "invalid entry count", QENTRY_LEN, sp);
5037 if (sp->req_header.rqs_flags & RQSFLAG_BADORDER) {
5038 isp_print_bytes(isp, "invalid IOCB ordering", QENTRY_LEN, sp);
5044 if (!ISP_VALID_HANDLE(isp, sp->req_handle)) {
5045 isp_prt(isp, ISP_LOGERR, "bad request handle 0x%x (iocb type 0x%x)", sp->req_handle, etype);
5046 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5050 xs = isp_find_xs(isp, sp->req_handle);
5052 uint8_t ts = completion_status & 0xff;
5054 * Only whine if this isn't the expected fallout of
5055 * aborting the command or resetting the target.
5057 if (etype != RQSTYPE_RESPONSE) {
5058 isp_prt(isp, ISP_LOGERR, "cannot find handle 0x%x (type 0x%x)", sp->req_handle, etype);
5059 } else if (ts != RQCS_ABORTED && ts != RQCS_RESET_OCCURRED) {
5060 isp_prt(isp, ISP_LOGERR, "cannot find handle 0x%x (status 0x%x)", sp->req_handle, ts);
5062 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5066 if (req_status_flags & RQSTF_BUS_RESET) {
5067 isp_prt(isp, ISP_LOG_WARN1, "%d.%d.%jx bus was reset",
5068 XS_CHANNEL(xs), XS_TGT(xs), (uintmax_t)XS_LUN(xs));
5069 XS_SETERR(xs, HBA_BUSRESET);
5070 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 1);
5073 isp_prt(isp, ISP_LOG_WARN1, "%d.%d.%jx buddaboom",
5074 XS_CHANNEL(xs), XS_TGT(xs), (uintmax_t)XS_LUN(xs));
5075 XS_SETERR(xs, HBA_BOTCH);
5082 if (IS_24XX(isp) && (scsi_status & (RQCS_RV|RQCS_SV)) != 0) {
5083 resp = ((isp24xx_statusreq_t *)sp)->req_rsp_sense;
5084 rlen = ((isp24xx_statusreq_t *)sp)->req_response_len;
5085 } else if (IS_FC(isp) && (scsi_status & RQCS_RV) != 0) {
5086 resp = sp->req_response;
5087 rlen = sp->req_response_len;
5089 if (IS_FC(isp) && (scsi_status & RQCS_SV) != 0) {
5091 * Fibre Channel F/W doesn't say we got status
5092 * if there's Sense Data instead. I guess they
5093 * think it goes w/o saying.
5095 req_state_flags |= RQSF_GOT_STATUS|RQSF_GOT_SENSE;
5097 snsp = ((isp24xx_statusreq_t *)sp)->req_rsp_sense;
5099 totslen = ((isp24xx_statusreq_t *)sp)->req_sense_len;
5100 slen = (sizeof (((isp24xx_statusreq_t *)sp)->req_rsp_sense)) - rlen;
5104 snsp = sp->req_sense_data;
5105 totslen = sp->req_sense_len;
5106 slen = sizeof (sp->req_sense_data);
5110 } else if (IS_SCSI(isp) && (req_state_flags & RQSF_GOT_SENSE)) {
5111 snsp = sp->req_sense_data;
5112 totslen = sp->req_sense_len;
5113 slen = sizeof (sp->req_sense_data);
5117 if (req_state_flags & RQSF_GOT_STATUS) {
5118 *XS_STSP(xs) = scsi_status & 0xff;
5122 case RQSTYPE_RESPONSE:
5123 if (resp && rlen >= 4 && resp[FCP_RSPNS_CODE_OFFSET] != 0) {
5126 const char *rnames[10] = {
5127 "Task Management function complete",
5128 "FCP_DATA length different than FCP_BURST_LEN",
5129 "FCP_CMND fields invalid",
5130 "FCP_DATA parameter mismatch with FCP_DATA_RO",
5131 "Task Management function rejected",
5132 "Task Management function failed",
5135 "Task Management function succeeded",
5136 "Task Management function incorrect logical unit number",
5138 uint8_t code = resp[FCP_RSPNS_CODE_OFFSET];
5139 if (code >= 10 || rnames[code] == NULL) {
5140 ISP_SNPRINTF(lb, sizeof(lb),
5141 "Unknown FCP Response Code 0x%x",
5147 isp_xs_prt(isp, xs, ISP_LOGWARN,
5148 "FCP RESPONSE, LENGTH %u: %s CDB0=0x%02x",
5149 rlen, ptr, XS_CDBP(xs)[0] & 0xff);
5150 if (code != 0 && code != 8)
5151 XS_SETERR(xs, HBA_BOTCH);
5154 isp_parse_status_24xx(isp, (isp24xx_statusreq_t *)sp, xs, &resid);
5156 isp_parse_status(isp, (void *)sp, xs, &resid);
5158 if ((XS_NOERR(xs) || XS_ERR(xs) == HBA_NOERROR) && (*XS_STSP(xs) == SCSI_BUSY)) {
5159 XS_SETERR(xs, HBA_TGTBSY);
5162 XS_SET_RESID(xs, resid);
5164 * A new synchronous rate was negotiated for
5165 * this target. Mark state such that we'll go
5166 * look up that which has changed later.
5168 if (req_status_flags & RQSTF_NEGOTIATION) {
5170 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
5171 sdp->isp_devparam[t].dev_refresh = 1;
5175 if (req_status_flags & RQSF_XFER_COMPLETE) {
5176 XS_SET_RESID(xs, 0);
5177 } else if (scsi_status & RQCS_RESID) {
5178 XS_SET_RESID(xs, resid);
5180 XS_SET_RESID(xs, 0);
5184 if (totslen > slen) {
5185 continuations_expected += ((totslen - slen + QENTRY_LEN - 5) / (QENTRY_LEN - 4));
5186 if (ndone > (MAX_REQUESTQ_COMPLETIONS - continuations_expected - 1)) {
5187 /* we'll lose some stats, but that's a small price to pay */
5188 for (i = 0; i < ndone; i++) {
5190 isp->isp_rsltccmplt++;
5191 isp_done(complist[i]);
5196 isp_prt(isp, ISP_LOGDEBUG0|ISP_LOG_CWARN, "Expecting %d more Status Continuations for total sense length of %u",
5197 continuations_expected, totslen);
5199 XS_SAVE_SENSE(xs, snsp, totslen, slen);
5200 } else if ((req_status_flags & RQSF_GOT_STATUS) && (scsi_status & 0xff) == SCSI_CHECK && IS_FC(isp)) {
5201 isp_prt(isp, ISP_LOGWARN, "CHECK CONDITION w/o sense data for CDB=0x%x", XS_CDBP(xs)[0] & 0xff);
5202 isp_print_bytes(isp, "CC with no Sense", QENTRY_LEN, qe);
5204 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));
5206 case RQSTYPE_REQUEST:
5211 if (!IS_24XX(isp) && (sp->req_header.rqs_flags & RQSFLAG_FULL)) {
5213 * Force Queue Full status.
5215 *XS_STSP(xs) = SCSI_QFULL;
5216 XS_SETERR(xs, HBA_NOERROR);
5217 } else if (XS_NOERR(xs)) {
5218 isp_prt(isp, ISP_LOG_WARN1,
5219 "%d.%d.%jx badness at %s:%u",
5220 XS_CHANNEL(xs), XS_TGT(xs),
5221 (uintmax_t)XS_LUN(xs),
5222 __func__, __LINE__);
5223 XS_SETERR(xs, HBA_BOTCH);
5225 XS_SET_RESID(xs, XS_XFRLEN(xs));
5228 isp_print_bytes(isp, "Unhandled Response Type", QENTRY_LEN, qe);
5230 XS_SETERR(xs, HBA_BOTCH);
5236 * Free any DMA resources. As a side effect, this may
5237 * also do any cache flushing necessary for data coherence.
5239 if (XS_XFRLEN(xs)) {
5240 ISP_DMAFREE(isp, xs, sp->req_handle);
5242 isp_destroy_handle(isp, sp->req_handle);
5244 if (isp->isp_nactive > 0) {
5247 complist[ndone++] = xs; /* defer completion call until later */
5248 ISP_MEMZERO(hp, QENTRY_LEN); /* PERF */
5250 if (ndone == MAX_REQUESTQ_COMPLETIONS) {
5256 * If we looked at any commands, then it's valid to find out
5257 * what the outpointer is. It also is a trigger to update the
5258 * ISP's notion of what we've seen so far.
5261 ISP_WRITE(isp, isp->isp_respoutrp, optr);
5262 isp->isp_resodx = optr;
5263 if (isp->isp_rscchiwater < ndone)
5264 isp->isp_rscchiwater = ndone;
5270 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
5272 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
5273 ISP_WRITE(isp, BIU_SEMA, 0);
5276 for (i = 0; i < ndone; i++) {
5279 if (((isp->isp_dblev & (ISP_LOGDEBUG1|ISP_LOGDEBUG2|ISP_LOGDEBUG3))) ||
5280 ((isp->isp_dblev & (ISP_LOGDEBUG0|ISP_LOG_CWARN) && ((!XS_NOERR(xs)) || (*XS_STSP(xs) != SCSI_GOOD))))) {
5281 isp_prt_endcmd(isp, xs);
5283 isp->isp_rsltccmplt++;
5294 isp_prt_endcmd(ispsoftc_t *isp, XS_T *xs)
5296 char cdbstr[16 * 5 + 1];
5299 lim = XS_CDBLEN(xs) > 16? 16 : XS_CDBLEN(xs);
5300 ISP_SNPRINTF(cdbstr, sizeof (cdbstr), "0x%02x ", XS_CDBP(xs)[0]);
5301 for (i = 1; i < lim; i++) {
5302 ISP_SNPRINTF(cdbstr, sizeof (cdbstr), "%s0x%02x ", cdbstr, XS_CDBP(xs)[i]);
5304 if (XS_SENSE_VALID(xs)) {
5305 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",
5306 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));
5308 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));
5313 * Parse an ASYNC mailbox complete
5315 * Return non-zero if the event has been acknowledged.
5318 isp_parse_async(ispsoftc_t *isp, uint16_t mbox)
5321 uint32_t h1 = 0, h2 = 0;
5325 * Pick up the channel, but not if this is a ASYNC_RIO32_2,
5326 * where Mailboxes 6/7 have the second handle.
5328 if (mbox != ASYNC_RIO32_2) {
5329 if (IS_DUALBUS(isp)) {
5330 chan = ISP_READ(isp, OUTMAILBOX6);
5333 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
5336 case ASYNC_BUS_RESET:
5337 ISP_SET_SENDMARKER(isp, chan, 1);
5338 #ifdef ISP_TARGET_MODE
5339 if (isp_target_async(isp, chan, mbox)) {
5343 isp_async(isp, ISPASYNC_BUS_RESET, chan);
5345 case ASYNC_SYSTEM_ERROR:
5347 isp->isp_state = ISP_CRASHED;
5349 * Were we waiting for a mailbox command to complete?
5350 * If so, it's dead, so wake up the waiter.
5352 if (isp->isp_mboxbsy) {
5354 isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR;
5355 MBOX_NOTIFY_COMPLETE(isp);
5358 * It's up to the handler for isp_async to reinit stuff and
5359 * restart the firmware
5361 isp_async(isp, ISPASYNC_FW_CRASH);
5365 case ASYNC_RQS_XFER_ERR:
5366 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
5369 case ASYNC_RSP_XFER_ERR:
5370 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
5375 * We've just been notified that the Queue has woken up.
5376 * We don't need to be chatty about this- just unlatch things
5379 mbox = ISP_READ(isp, isp->isp_rqstoutrp);
5382 case ASYNC_TIMEOUT_RESET:
5383 isp_prt(isp, ISP_LOGWARN, "timeout initiated SCSI bus reset of chan %d", chan);
5384 ISP_SET_SENDMARKER(isp, chan, 1);
5385 #ifdef ISP_TARGET_MODE
5386 if (isp_target_async(isp, chan, mbox)) {
5392 case ASYNC_DEVICE_RESET:
5393 isp_prt(isp, ISP_LOGINFO, "device reset on chan %d", chan);
5394 ISP_SET_SENDMARKER(isp, chan, 1);
5395 #ifdef ISP_TARGET_MODE
5396 if (isp_target_async(isp, chan, mbox)) {
5402 case ASYNC_EXTMSG_UNDERRUN:
5403 isp_prt(isp, ISP_LOGWARN, "extended message underrun");
5406 case ASYNC_SCAM_INT:
5407 isp_prt(isp, ISP_LOGINFO, "SCAM interrupt");
5410 case ASYNC_HUNG_SCSI:
5411 isp_prt(isp, ISP_LOGERR, "stalled SCSI Bus after DATA Overrun");
5412 /* XXX: Need to issue SCSI reset at this point */
5415 case ASYNC_KILLED_BUS:
5416 isp_prt(isp, ISP_LOGERR, "SCSI Bus reset after DATA Overrun");
5419 case ASYNC_BUS_TRANSIT:
5420 mbox = ISP_READ(isp, OUTMAILBOX2);
5421 switch (mbox & SXP_PINS_MODE_MASK) {
5422 case SXP_PINS_LVD_MODE:
5423 isp_prt(isp, ISP_LOGINFO, "Transition to LVD mode");
5424 SDPARAM(isp, chan)->isp_diffmode = 0;
5425 SDPARAM(isp, chan)->isp_ultramode = 0;
5426 SDPARAM(isp, chan)->isp_lvdmode = 1;
5428 case SXP_PINS_HVD_MODE:
5429 isp_prt(isp, ISP_LOGINFO,
5430 "Transition to Differential mode");
5431 SDPARAM(isp, chan)->isp_diffmode = 1;
5432 SDPARAM(isp, chan)->isp_ultramode = 0;
5433 SDPARAM(isp, chan)->isp_lvdmode = 0;
5435 case SXP_PINS_SE_MODE:
5436 isp_prt(isp, ISP_LOGINFO,
5437 "Transition to Single Ended mode");
5438 SDPARAM(isp, chan)->isp_diffmode = 0;
5439 SDPARAM(isp, chan)->isp_ultramode = 1;
5440 SDPARAM(isp, chan)->isp_lvdmode = 0;
5443 isp_prt(isp, ISP_LOGWARN,
5444 "Transition to Unknown Mode 0x%x", mbox);
5448 * XXX: Set up to renegotiate again!
5450 /* Can only be for a 1080... */
5451 ISP_SET_SENDMARKER(isp, chan, 1);
5454 case ASYNC_CMD_CMPLT:
5456 if (!IS_ULTRA3(isp)) {
5457 isp_prt(isp, ISP_LOGERR, "unexpected fast posting completion");
5461 h1 = (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1);
5465 h1 = (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1);
5466 h2 = (ISP_READ(isp, OUTMAILBOX7) << 16) | ISP_READ(isp, OUTMAILBOX6);
5474 isp_prt(isp, ISP_LOGERR, "unexpected 16 bit RIO handle");
5477 isp_prt(isp, ISP_LOGWARN, "%s: unhandled async code 0x%x", __func__, mbox);
5482 isp_prt(isp, ISP_LOGDEBUG3, "fast post/rio completion of 0x%08x", h1);
5483 isp_fastpost_complete(isp, h1);
5485 isp_prt(isp, ISP_LOGDEBUG3, "fast post/rio completion of 0x%08x", h2);
5486 isp_fastpost_complete(isp, h2);
5487 if (isp->isp_fpcchiwater < 2) {
5488 isp->isp_fpcchiwater = 2;
5491 if (isp->isp_fpcchiwater < 1) {
5492 isp->isp_fpcchiwater = 1;
5496 isp->isp_intoasync++;
5502 isp_parse_async_fc(ispsoftc_t *isp, uint16_t mbox)
5508 if (IS_DUALBUS(isp)) {
5509 chan = ISP_READ(isp, OUTMAILBOX6);
5513 isp_prt(isp, ISP_LOGDEBUG2, "Async Mbox 0x%x", mbox);
5516 case ASYNC_SYSTEM_ERROR:
5518 isp->isp_state = ISP_CRASHED;
5519 FCPARAM(isp, chan)->isp_loopstate = LOOP_NIL;
5520 isp_change_fw_state(isp, chan, FW_CONFIG_WAIT);
5522 * Were we waiting for a mailbox command to complete?
5523 * If so, it's dead, so wake up the waiter.
5525 if (isp->isp_mboxbsy) {
5527 isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR;
5528 MBOX_NOTIFY_COMPLETE(isp);
5531 * It's up to the handler for isp_async to reinit stuff and
5532 * restart the firmware
5534 isp_async(isp, ISPASYNC_FW_CRASH);
5538 case ASYNC_RQS_XFER_ERR:
5539 isp_prt(isp, ISP_LOGERR, "Request Queue Transfer Error");
5542 case ASYNC_RSP_XFER_ERR:
5543 isp_prt(isp, ISP_LOGERR, "Response Queue Transfer Error");
5547 #ifdef ISP_TARGET_MODE
5549 isp_prt(isp, ISP_LOGERR, "ATIO Queue Transfer Error");
5553 isp_prt(isp, ISP_LOGERR, "%s: unexpected ASYNC_QWAKEUP code", __func__);
5556 case ASYNC_CMD_CMPLT:
5557 isp_fastpost_complete(isp, (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1));
5558 if (isp->isp_fpcchiwater < 1) {
5559 isp->isp_fpcchiwater = 1;
5563 case ASYNC_RIOZIO_STALL:
5566 case ASYNC_CTIO_DONE:
5567 #ifdef ISP_TARGET_MODE
5568 if (isp_target_async(isp, (ISP_READ(isp, OUTMAILBOX2) << 16) | ISP_READ(isp, OUTMAILBOX1), mbox)) {
5571 isp->isp_fphccmplt++;
5574 isp_prt(isp, ISP_LOGWARN, "unexpected ASYNC CTIO done");
5577 case ASYNC_LIP_ERROR:
5579 case ASYNC_LIP_OCCURRED:
5582 * These are broadcast events that have to be sent across
5583 * all active channels.
5585 for (chan = 0; chan < isp->isp_nchan; chan++) {
5586 fcp = FCPARAM(isp, chan);
5587 int topo = fcp->isp_topo;
5589 if (fcp->role == ISP_ROLE_NONE) {
5593 fcp->isp_loopstate = LOOP_NIL;
5594 ISP_SET_SENDMARKER(isp, chan, 1);
5595 isp_async(isp, ISPASYNC_LIP, chan);
5596 #ifdef ISP_TARGET_MODE
5597 if (isp_target_async(isp, chan, mbox)) {
5602 * We've had problems with data corruption occuring on
5603 * commands that complete (with no apparent error) after
5604 * we receive a LIP. This has been observed mostly on
5605 * Local Loop topologies. To be safe, let's just mark
5606 * all active initiator commands as dead.
5608 if (topo == TOPO_NL_PORT || topo == TOPO_FL_PORT) {
5610 for (i = j = 0; i < isp->isp_maxcmds; i++) {
5614 hdp = &isp->isp_xflist[i];
5615 if (ISP_H2HT(hdp->handle) != ISP_HANDLE_INITIATOR) {
5619 if (XS_CHANNEL(xs) != chan) {
5623 isp_prt(isp, ISP_LOG_WARN1,
5624 "%d.%d.%jx bus reset set at %s:%u",
5625 XS_CHANNEL(xs), XS_TGT(xs),
5626 (uintmax_t)XS_LUN(xs),
5627 __func__, __LINE__);
5628 XS_SETERR(xs, HBA_BUSRESET);
5631 isp_prt(isp, ISP_LOGERR, lipd, chan, j);
5639 * This is a broadcast event that has to be sent across
5640 * all active channels.
5642 for (chan = 0; chan < isp->isp_nchan; chan++) {
5643 fcp = FCPARAM(isp, chan);
5644 if (fcp->role == ISP_ROLE_NONE)
5646 ISP_SET_SENDMARKER(isp, chan, 1);
5647 isp_async(isp, ISPASYNC_LOOP_UP, chan);
5648 #ifdef ISP_TARGET_MODE
5649 if (isp_target_async(isp, chan, mbox)) {
5656 case ASYNC_LOOP_DOWN:
5658 * This is a broadcast event that has to be sent across
5659 * all active channels.
5661 for (chan = 0; chan < isp->isp_nchan; chan++) {
5662 fcp = FCPARAM(isp, chan);
5663 if (fcp->role == ISP_ROLE_NONE)
5665 ISP_SET_SENDMARKER(isp, chan, 1);
5666 fcp->isp_loopstate = LOOP_NIL;
5667 isp_async(isp, ISPASYNC_LOOP_DOWN, chan);
5668 #ifdef ISP_TARGET_MODE
5669 if (isp_target_async(isp, chan, mbox)) {
5676 case ASYNC_LOOP_RESET:
5678 * This is a broadcast event that has to be sent across
5679 * all active channels.
5681 for (chan = 0; chan < isp->isp_nchan; chan++) {
5682 fcp = FCPARAM(isp, chan);
5683 if (fcp->role == ISP_ROLE_NONE)
5685 ISP_SET_SENDMARKER(isp, chan, 1);
5686 fcp->isp_loopstate = LOOP_NIL;
5687 isp_async(isp, ISPASYNC_LOOP_RESET, chan);
5688 #ifdef ISP_TARGET_MODE
5689 if (isp_target_async(isp, chan, mbox)) {
5696 case ASYNC_PDB_CHANGED:
5698 int echan, nphdl, nlstate, reason;
5700 if (IS_23XX(isp) || IS_24XX(isp)) {
5701 nphdl = ISP_READ(isp, OUTMAILBOX1);
5702 nlstate = ISP_READ(isp, OUTMAILBOX2);
5704 nphdl = nlstate = 0xffff;
5707 reason = ISP_READ(isp, OUTMAILBOX3) >> 8;
5710 if (ISP_CAP_MULTI_ID(isp)) {
5711 chan = ISP_READ(isp, OUTMAILBOX3) & 0xff;
5712 if (chan == 0xff || nphdl == NIL_HANDLE) {
5714 echan = isp->isp_nchan - 1;
5715 } else if (chan >= isp->isp_nchan) {
5723 for (; chan <= echan; chan++) {
5724 fcp = FCPARAM(isp, chan);
5725 if (fcp->role == ISP_ROLE_NONE)
5727 if (fcp->isp_loopstate > LOOP_LTEST_DONE)
5728 fcp->isp_loopstate = LOOP_LTEST_DONE;
5729 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan,
5730 ISPASYNC_CHANGE_PDB, nphdl, nlstate, reason);
5734 case ASYNC_CHANGE_NOTIFY:
5738 portid = ((ISP_READ(isp, OUTMAILBOX1) & 0xff) << 16) |
5739 ISP_READ(isp, OUTMAILBOX2);
5740 if (ISP_CAP_MULTI_ID(isp)) {
5741 chan = ISP_READ(isp, OUTMAILBOX3) & 0xff;
5742 if (chan >= isp->isp_nchan)
5747 fcp = FCPARAM(isp, chan);
5748 if (fcp->role == ISP_ROLE_NONE)
5750 if (fcp->isp_loopstate > LOOP_LSCAN_DONE)
5751 fcp->isp_loopstate = LOOP_LSCAN_DONE;
5752 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan,
5753 ISPASYNC_CHANGE_SNS, portid);
5757 case ASYNC_CONNMODE:
5759 * This only applies to 2100 amd 2200 cards
5761 if (!IS_2200(isp) && !IS_2100(isp)) {
5762 isp_prt(isp, ISP_LOGWARN, "bad card for ASYNC_CONNMODE event");
5766 mbox = ISP_READ(isp, OUTMAILBOX1);
5769 isp_prt(isp, ISP_LOGINFO,
5770 "Point-to-Point -> Loop mode");
5773 isp_prt(isp, ISP_LOGINFO,
5774 "Loop -> Point-to-Point mode");
5776 case ISP_CONN_BADLIP:
5777 isp_prt(isp, ISP_LOGWARN,
5778 "Point-to-Point -> Loop mode (BAD LIP)");
5780 case ISP_CONN_FATAL:
5782 isp->isp_state = ISP_CRASHED;
5783 isp_prt(isp, ISP_LOGERR, "FATAL CONNECTION ERROR");
5784 isp_async(isp, ISPASYNC_FW_CRASH);
5786 case ISP_CONN_LOOPBACK:
5787 isp_prt(isp, ISP_LOGWARN,
5788 "Looped Back in Point-to-Point mode");
5791 isp_prt(isp, ISP_LOGWARN,
5792 "Unknown connection mode (0x%x)", mbox);
5795 ISP_SET_SENDMARKER(isp, chan, 1);
5796 FCPARAM(isp, chan)->isp_loopstate = LOOP_NIL;
5797 isp_async(isp, ISPASYNC_CHANGE_NOTIFY, chan, ISPASYNC_CHANGE_OTHER);
5802 isp_prt(isp, ISP_LOGWARN, "Receive Error");
5804 isp_prt(isp, ISP_LOGWARN, "unexpected ASYNC_RCV_ERR");
5807 case ASYNC_RJT_SENT: /* same as ASYNC_QFULL_SENT */
5809 isp_prt(isp, ISP_LOGTDEBUG0, "LS_RJT sent");
5811 } else if (IS_2200(isp)) {
5812 isp_prt(isp, ISP_LOGTDEBUG0, "QFULL sent");
5817 isp_prt(isp, ISP_LOGWARN, "Unknown Async Code 0x%x", mbox);
5820 if (mbox != ASYNC_CTIO_DONE && mbox != ASYNC_CMD_CMPLT) {
5821 isp->isp_intoasync++;
5827 * Handle other response entries. A pointer to the request queue output
5828 * index is here in case we want to eat several entries at once, although
5829 * this is not used currently.
5833 isp_handle_other_response(ispsoftc_t *isp, int type, isphdr_t *hp, uint32_t *optrp)
5839 case RQSTYPE_STATUS_CONT:
5840 isp_prt(isp, ISP_LOG_WARN1, "Ignored Continuation Response");
5842 case RQSTYPE_MARKER:
5843 isp_prt(isp, ISP_LOG_WARN1, "Marker Response");
5845 case RQSTYPE_RPT_ID_ACQ:
5846 isp_get_ridacq(isp, (isp_ridacq_t *)hp, &rid);
5847 if (rid.ridacq_format == 0) {
5848 for (chan = 0; chan < isp->isp_nchan; chan++) {
5849 fcparam *fcp = FCPARAM(isp, chan);
5850 if (fcp->role == ISP_ROLE_NONE)
5852 c = (chan == 0) ? 127 : (chan - 1);
5853 if (rid.ridacq_map[c / 16] & (1 << (c % 16)))
5854 isp_async(isp, ISPASYNC_CHANGE_NOTIFY,
5855 chan, ISPASYNC_CHANGE_OTHER);
5858 isp_async(isp, ISPASYNC_CHANGE_NOTIFY,
5859 rid.ridacq_vp_index, ISPASYNC_CHANGE_OTHER);
5864 case RQSTYPE_ENABLE_LUN:
5865 case RQSTYPE_MODIFY_LUN:
5866 case RQSTYPE_NOTIFY:
5867 case RQSTYPE_NOTIFY_ACK:
5873 case RQSTYPE_ABTS_RCVD:
5874 case RQSTYPE_ABTS_RSP:
5875 isp->isp_rsltccmplt++; /* count as a response completion */
5876 #ifdef ISP_TARGET_MODE
5877 if (isp_target_notify(isp, (ispstatusreq_t *) hp, optrp)) {
5882 case RQSTYPE_REQUEST:
5885 if (type != isp_get_response_type(isp, hp)) {
5887 * This is questionable- we're just papering over
5888 * something we've seen on SMP linux in target
5889 * mode- we don't really know what's happening
5890 * here that causes us to think we've gotten
5891 * an entry, but that either the entry isn't
5892 * filled out yet or our CPU read data is stale.
5894 isp_prt(isp, ISP_LOGINFO,
5895 "unstable type in response queue");
5898 isp_prt(isp, ISP_LOGWARN, "Unhandled Response Type 0x%x",
5899 isp_get_response_type(isp, hp));
5905 isp_parse_status(ispsoftc_t *isp, ispstatusreq_t *sp, XS_T *xs, long *rp)
5907 switch (sp->req_completion_status & 0xff) {
5910 XS_SETERR(xs, HBA_NOERROR);
5914 case RQCS_INCOMPLETE:
5915 if ((sp->req_state_flags & RQSF_GOT_TARGET) == 0) {
5916 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "Selection Timeout @ %s:%d", __func__, __LINE__);
5918 XS_SETERR(xs, HBA_SELTIMEOUT);
5919 *rp = XS_XFRLEN(xs);
5923 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Incomplete, state 0x%x", sp->req_state_flags);
5926 case RQCS_DMA_ERROR:
5927 isp_xs_prt(isp, xs, ISP_LOGERR, "DMA Error");
5928 *rp = XS_XFRLEN(xs);
5931 case RQCS_TRANSPORT_ERROR:
5934 ISP_SNPRINTF(buf, sizeof (buf), "states=>");
5935 if (sp->req_state_flags & RQSF_GOT_BUS) {
5936 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_BUS", buf);
5938 if (sp->req_state_flags & RQSF_GOT_TARGET) {
5939 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_TGT", buf);
5941 if (sp->req_state_flags & RQSF_SENT_CDB) {
5942 ISP_SNPRINTF(buf, sizeof (buf), "%s SENT_CDB", buf);
5944 if (sp->req_state_flags & RQSF_XFRD_DATA) {
5945 ISP_SNPRINTF(buf, sizeof (buf), "%s XFRD_DATA", buf);
5947 if (sp->req_state_flags & RQSF_GOT_STATUS) {
5948 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_STS", buf);
5950 if (sp->req_state_flags & RQSF_GOT_SENSE) {
5951 ISP_SNPRINTF(buf, sizeof (buf), "%s GOT_SNS", buf);
5953 if (sp->req_state_flags & RQSF_XFER_COMPLETE) {
5954 ISP_SNPRINTF(buf, sizeof (buf), "%s XFR_CMPLT", buf);
5956 ISP_SNPRINTF(buf, sizeof (buf), "%s\nstatus=>", buf);
5957 if (sp->req_status_flags & RQSTF_DISCONNECT) {
5958 ISP_SNPRINTF(buf, sizeof (buf), "%s Disconnect", buf);
5960 if (sp->req_status_flags & RQSTF_SYNCHRONOUS) {
5961 ISP_SNPRINTF(buf, sizeof (buf), "%s Sync_xfr", buf);
5963 if (sp->req_status_flags & RQSTF_PARITY_ERROR) {
5964 ISP_SNPRINTF(buf, sizeof (buf), "%s Parity", buf);
5966 if (sp->req_status_flags & RQSTF_BUS_RESET) {
5967 ISP_SNPRINTF(buf, sizeof (buf), "%s Bus_Reset", buf);
5969 if (sp->req_status_flags & RQSTF_DEVICE_RESET) {
5970 ISP_SNPRINTF(buf, sizeof (buf), "%s Device_Reset", buf);
5972 if (sp->req_status_flags & RQSTF_ABORTED) {
5973 ISP_SNPRINTF(buf, sizeof (buf), "%s Aborted", buf);
5975 if (sp->req_status_flags & RQSTF_TIMEOUT) {
5976 ISP_SNPRINTF(buf, sizeof (buf), "%s Timeout", buf);
5978 if (sp->req_status_flags & RQSTF_NEGOTIATION) {
5979 ISP_SNPRINTF(buf, sizeof (buf), "%s Negotiation", buf);
5981 isp_xs_prt(isp, xs, ISP_LOGERR, "Transport Error: %s", buf);
5982 *rp = XS_XFRLEN(xs);
5985 case RQCS_RESET_OCCURRED:
5988 isp_xs_prt(isp, xs, ISP_LOGWARN, "Bus Reset destroyed command");
5989 for (chan = 0; chan < isp->isp_nchan; chan++) {
5990 FCPARAM(isp, chan)->sendmarker = 1;
5993 XS_SETERR(xs, HBA_BUSRESET);
5995 *rp = XS_XFRLEN(xs);
5999 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Aborted");
6000 ISP_SET_SENDMARKER(isp, XS_CHANNEL(xs), 1);
6002 XS_SETERR(xs, HBA_ABORTED);
6007 isp_xs_prt(isp, xs, ISP_LOGWARN, "Command timed out");
6009 * XXX: Check to see if we logged out of the device.
6012 XS_SETERR(xs, HBA_CMDTIMEOUT);
6016 case RQCS_DATA_OVERRUN:
6017 XS_SET_RESID(xs, sp->req_resid);
6018 isp_xs_prt(isp, xs, ISP_LOGERR, "data overrun (%ld)", (long) XS_GET_RESID(xs));
6020 XS_SETERR(xs, HBA_DATAOVR);
6024 case RQCS_COMMAND_OVERRUN:
6025 isp_xs_prt(isp, xs, ISP_LOGERR, "command overrun");
6028 case RQCS_STATUS_OVERRUN:
6029 isp_xs_prt(isp, xs, ISP_LOGERR, "status overrun");
6032 case RQCS_BAD_MESSAGE:
6033 isp_xs_prt(isp, xs, ISP_LOGERR, "msg not COMMAND COMPLETE after status");
6036 case RQCS_NO_MESSAGE_OUT:
6037 isp_xs_prt(isp, xs, ISP_LOGERR, "No MESSAGE OUT phase after selection");
6040 case RQCS_EXT_ID_FAILED:
6041 isp_xs_prt(isp, xs, ISP_LOGERR, "EXTENDED IDENTIFY failed");
6044 case RQCS_IDE_MSG_FAILED:
6045 isp_xs_prt(isp, xs, ISP_LOGERR, "INITIATOR DETECTED ERROR rejected");
6048 case RQCS_ABORT_MSG_FAILED:
6049 isp_xs_prt(isp, xs, ISP_LOGERR, "ABORT OPERATION rejected");
6052 case RQCS_REJECT_MSG_FAILED:
6053 isp_xs_prt(isp, xs, ISP_LOGERR, "MESSAGE REJECT rejected");
6056 case RQCS_NOP_MSG_FAILED:
6057 isp_xs_prt(isp, xs, ISP_LOGERR, "NOP rejected");
6060 case RQCS_PARITY_ERROR_MSG_FAILED:
6061 isp_xs_prt(isp, xs, ISP_LOGERR, "MESSAGE PARITY ERROR rejected");
6064 case RQCS_DEVICE_RESET_MSG_FAILED:
6065 isp_xs_prt(isp, xs, ISP_LOGWARN, "BUS DEVICE RESET rejected");
6068 case RQCS_ID_MSG_FAILED:
6069 isp_xs_prt(isp, xs, ISP_LOGERR, "IDENTIFY rejected");
6072 case RQCS_UNEXP_BUS_FREE:
6073 isp_xs_prt(isp, xs, ISP_LOGERR, "Unexpected Bus Free");
6076 case RQCS_DATA_UNDERRUN:
6079 int ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
6080 if (!ru_marked || sp->req_resid > XS_XFRLEN(xs)) {
6081 isp_xs_prt(isp, xs, ISP_LOGWARN, bun, XS_XFRLEN(xs), sp->req_resid, (ru_marked)? "marked" : "not marked");
6083 XS_SETERR(xs, HBA_BOTCH);
6088 XS_SET_RESID(xs, sp->req_resid);
6090 XS_SETERR(xs, HBA_NOERROR);
6095 case RQCS_XACT_ERR1:
6096 isp_xs_prt(isp, xs, ISP_LOGERR, "HBA attempted queued transaction with disconnect not set");
6099 case RQCS_XACT_ERR2:
6100 isp_xs_prt(isp, xs, ISP_LOGERR,
6101 "HBA attempted queued transaction to target routine %jx",
6102 (uintmax_t)XS_LUN(xs));
6105 case RQCS_XACT_ERR3:
6106 isp_xs_prt(isp, xs, ISP_LOGERR, "HBA attempted queued cmd when queueing disabled");
6109 case RQCS_BAD_ENTRY:
6110 isp_prt(isp, ISP_LOGERR, "Invalid IOCB entry type detected");
6113 case RQCS_QUEUE_FULL:
6114 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "internal queues full status 0x%x", *XS_STSP(xs));
6117 * If QFULL or some other status byte is set, then this
6118 * isn't an error, per se.
6120 * Unfortunately, some QLogic f/w writers have, in
6121 * some cases, ommitted to *set* status to QFULL.
6124 if (*XS_STSP(xs) != SCSI_GOOD && XS_NOERR(xs)) {
6125 XS_SETERR(xs, HBA_NOERROR);
6130 *XS_STSP(xs) = SCSI_QFULL;
6131 XS_SETERR(xs, HBA_NOERROR);
6134 case RQCS_PHASE_SKIPPED:
6135 isp_xs_prt(isp, xs, ISP_LOGERR, "SCSI phase skipped");
6138 case RQCS_ARQS_FAILED:
6139 isp_xs_prt(isp, xs, ISP_LOGERR, "Auto Request Sense Failed");
6141 XS_SETERR(xs, HBA_ARQFAIL);
6145 case RQCS_WIDE_FAILED:
6146 isp_xs_prt(isp, xs, ISP_LOGERR, "Wide Negotiation Failed");
6148 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
6149 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_WIDE;
6150 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
6154 XS_SETERR(xs, HBA_NOERROR);
6158 case RQCS_SYNCXFER_FAILED:
6159 isp_xs_prt(isp, xs, ISP_LOGERR, "SDTR Message Failed");
6161 sdparam *sdp = SDPARAM(isp, XS_CHANNEL(xs));
6162 sdp += XS_CHANNEL(xs);
6163 sdp->isp_devparam[XS_TGT(xs)].goal_flags &= ~DPARM_SYNC;
6164 sdp->isp_devparam[XS_TGT(xs)].dev_update = 1;
6169 case RQCS_LVD_BUSERR:
6170 isp_xs_prt(isp, xs, ISP_LOGERR, "Bad LVD condition");
6173 case RQCS_PORT_UNAVAILABLE:
6175 * No such port on the loop. Moral equivalent of SELTIMEO
6177 case RQCS_PORT_LOGGED_OUT:
6180 uint8_t sts = sp->req_completion_status & 0xff;
6183 * It was there (maybe)- treat as a selection timeout.
6185 if (sts == RQCS_PORT_UNAVAILABLE) {
6186 reason = "unavailable";
6191 isp_prt(isp, ISP_LOGINFO, "port %s for target %d", reason, XS_TGT(xs));
6194 * If we're on a local loop, force a LIP (which is overkill)
6195 * to force a re-login of this unit. If we're on fabric,
6196 * then we'll have to log in again as a matter of course.
6198 if (FCPARAM(isp, 0)->isp_topo == TOPO_NL_PORT ||
6199 FCPARAM(isp, 0)->isp_topo == TOPO_FL_PORT) {
6201 MBSINIT(&mbs, MBOX_INIT_LIP, MBLOGALL, 0);
6202 if (ISP_CAP_2KLOGIN(isp)) {
6203 mbs.ibits = (1 << 10);
6205 isp_mboxcmd_qnw(isp, &mbs, 1);
6208 XS_SETERR(xs, HBA_SELTIMEOUT);
6212 case RQCS_PORT_CHANGED:
6213 isp_prt(isp, ISP_LOGWARN, "port changed for target %d", XS_TGT(xs));
6215 XS_SETERR(xs, HBA_SELTIMEOUT);
6219 case RQCS_PORT_BUSY:
6220 isp_prt(isp, ISP_LOGWARN, "port busy for target %d", XS_TGT(xs));
6222 XS_SETERR(xs, HBA_TGTBSY);
6227 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x", sp->req_completion_status);
6231 XS_SETERR(xs, HBA_BOTCH);
6236 isp_parse_status_24xx(ispsoftc_t *isp, isp24xx_statusreq_t *sp, XS_T *xs, long *rp)
6238 int ru_marked, sv_marked;
6239 int chan = XS_CHANNEL(xs);
6241 switch (sp->req_completion_status) {
6244 XS_SETERR(xs, HBA_NOERROR);
6248 case RQCS_DMA_ERROR:
6249 isp_xs_prt(isp, xs, ISP_LOGERR, "DMA error");
6252 case RQCS_TRANSPORT_ERROR:
6253 isp_xs_prt(isp, xs, ISP_LOGERR, "Transport Error");
6256 case RQCS_RESET_OCCURRED:
6257 isp_xs_prt(isp, xs, ISP_LOGWARN, "reset destroyed command");
6258 FCPARAM(isp, chan)->sendmarker = 1;
6260 XS_SETERR(xs, HBA_BUSRESET);
6265 isp_xs_prt(isp, xs, ISP_LOGERR, "Command Aborted");
6266 FCPARAM(isp, chan)->sendmarker = 1;
6268 XS_SETERR(xs, HBA_ABORTED);
6273 isp_xs_prt(isp, xs, ISP_LOGWARN, "Command Timed Out");
6275 XS_SETERR(xs, HBA_CMDTIMEOUT);
6279 case RQCS_DATA_OVERRUN:
6280 XS_SET_RESID(xs, sp->req_resid);
6281 isp_xs_prt(isp, xs, ISP_LOGERR, "Data Overrun");
6283 XS_SETERR(xs, HBA_DATAOVR);
6287 case RQCS_24XX_DRE: /* data reassembly error */
6288 isp_prt(isp, ISP_LOGERR, "Chan %d data reassembly error for target %d", chan, XS_TGT(xs));
6290 XS_SETERR(xs, HBA_ABORTED);
6292 *rp = XS_XFRLEN(xs);
6295 case RQCS_24XX_TABORT: /* aborted by target */
6296 isp_prt(isp, ISP_LOGERR, "Chan %d target %d sent ABTS", chan, XS_TGT(xs));
6298 XS_SETERR(xs, HBA_ABORTED);
6302 case RQCS_DATA_UNDERRUN:
6303 ru_marked = (sp->req_scsi_status & RQCS_RU) != 0;
6305 * We can get an underrun w/o things being marked
6306 * if we got a non-zero status.
6308 sv_marked = (sp->req_scsi_status & (RQCS_SV|RQCS_RV)) != 0;
6309 if ((ru_marked == 0 && sv_marked == 0) ||
6310 (sp->req_resid > XS_XFRLEN(xs))) {
6311 isp_xs_prt(isp, xs, ISP_LOGWARN, bun, XS_XFRLEN(xs), sp->req_resid, (ru_marked)? "marked" : "not marked");
6313 XS_SETERR(xs, HBA_BOTCH);
6317 XS_SET_RESID(xs, sp->req_resid);
6318 isp_xs_prt(isp, xs, ISP_LOG_WARN1, "Data Underrun (%d) for command 0x%x", sp->req_resid, XS_CDBP(xs)[0] & 0xff);
6320 XS_SETERR(xs, HBA_NOERROR);
6324 case RQCS_PORT_UNAVAILABLE:
6326 * No such port on the loop. Moral equivalent of SELTIMEO
6328 case RQCS_PORT_LOGGED_OUT:
6331 uint8_t sts = sp->req_completion_status & 0xff;
6334 * It was there (maybe)- treat as a selection timeout.
6336 if (sts == RQCS_PORT_UNAVAILABLE) {
6337 reason = "unavailable";
6342 isp_prt(isp, ISP_LOGINFO, "Chan %d port %s for target %d",
6343 chan, reason, XS_TGT(xs));
6346 * There is no MBOX_INIT_LIP for the 24XX.
6349 XS_SETERR(xs, HBA_SELTIMEOUT);
6353 case RQCS_PORT_CHANGED:
6354 isp_prt(isp, ISP_LOGWARN, "port changed for target %d chan %d", XS_TGT(xs), chan);
6356 XS_SETERR(xs, HBA_SELTIMEOUT);
6361 case RQCS_24XX_ENOMEM: /* f/w resource unavailable */
6362 isp_prt(isp, ISP_LOGWARN, "f/w resource unavailable for target %d chan %d", XS_TGT(xs), chan);
6364 *XS_STSP(xs) = SCSI_BUSY;
6365 XS_SETERR(xs, HBA_TGTBSY);
6369 case RQCS_24XX_TMO: /* task management overrun */
6370 isp_prt(isp, ISP_LOGWARN, "command for target %d overlapped task management for chan %d", XS_TGT(xs), chan);
6372 *XS_STSP(xs) = SCSI_BUSY;
6373 XS_SETERR(xs, HBA_TGTBSY);
6378 isp_prt(isp, ISP_LOGERR, "Unknown Completion Status 0x%x on chan %d", sp->req_completion_status, chan);
6382 XS_SETERR(xs, HBA_BOTCH);
6387 isp_fastpost_complete(ispsoftc_t *isp, uint32_t fph)
6394 xs = isp_find_xs(isp, fph);
6396 isp_prt(isp, ISP_LOGWARN,
6397 "Command for fast post handle 0x%x not found", fph);
6400 isp_destroy_handle(isp, fph);
6403 * Since we don't have a result queue entry item,
6404 * we must believe that SCSI status is zero and
6405 * that all data transferred.
6407 XS_SET_RESID(xs, 0);
6408 *XS_STSP(xs) = SCSI_GOOD;
6409 if (XS_XFRLEN(xs)) {
6410 ISP_DMAFREE(isp, xs, fph);
6412 if (isp->isp_nactive) {
6415 isp->isp_fphccmplt++;
6420 isp_mbox_continue(ispsoftc_t *isp)
6426 switch (isp->isp_lastmbxcmd) {
6427 case MBOX_WRITE_RAM_WORD:
6428 case MBOX_READ_RAM_WORD:
6429 case MBOX_WRITE_RAM_WORD_EXTENDED:
6430 case MBOX_READ_RAM_WORD_EXTENDED:
6435 if (isp->isp_mboxtmp[0] != MBOX_COMMAND_COMPLETE) {
6436 isp->isp_mbxwrk0 = 0;
6441 * Clear the previous interrupt.
6444 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_CLEAR_RISC_INT);
6446 ISP_WRITE(isp, HCCR, HCCR_CMD_CLEAR_RISC_INT);
6447 ISP_WRITE(isp, BIU_SEMA, 0);
6451 * Continue with next word.
6453 ISP_MEMZERO(&mbs, sizeof (mbs));
6454 ptr = isp->isp_mbxworkp;
6455 switch (isp->isp_lastmbxcmd) {
6456 case MBOX_WRITE_RAM_WORD:
6457 mbs.param[1] = isp->isp_mbxwrk1++;
6458 mbs.param[2] = *ptr++;
6460 case MBOX_READ_RAM_WORD:
6461 *ptr++ = isp->isp_mboxtmp[2];
6462 mbs.param[1] = isp->isp_mbxwrk1++;
6464 case MBOX_WRITE_RAM_WORD_EXTENDED:
6466 uint32_t *lptr = (uint32_t *)ptr;
6467 mbs.param[2] = lptr[0];
6468 mbs.param[3] = lptr[0] >> 16;
6470 ptr = (uint16_t *)lptr;
6472 mbs.param[2] = *ptr++;
6474 offset = isp->isp_mbxwrk1;
6475 offset |= isp->isp_mbxwrk8 << 16;
6476 mbs.param[1] = offset;
6477 mbs.param[8] = offset >> 16;
6479 isp->isp_mbxwrk1 = offset;
6480 isp->isp_mbxwrk8 = offset >> 16;
6482 case MBOX_READ_RAM_WORD_EXTENDED:
6484 uint32_t *lptr = (uint32_t *)ptr;
6485 uint32_t val = isp->isp_mboxtmp[2];
6486 val |= (isp->isp_mboxtmp[3]) << 16;
6488 ptr = (uint16_t *)lptr;
6490 *ptr++ = isp->isp_mboxtmp[2];
6492 offset = isp->isp_mbxwrk1;
6493 offset |= isp->isp_mbxwrk8 << 16;
6494 mbs.param[1] = offset;
6495 mbs.param[8] = offset >> 16;
6497 isp->isp_mbxwrk1 = offset;
6498 isp->isp_mbxwrk8 = offset >> 16;
6501 isp->isp_mbxworkp = ptr;
6503 mbs.param[0] = isp->isp_lastmbxcmd;
6504 mbs.logval = MBLOGALL;
6505 isp_mboxcmd_qnw(isp, &mbs, 0);
6509 #define ISP_SCSI_IBITS(op) (mbpscsi[((op)<<1)])
6510 #define ISP_SCSI_OBITS(op) (mbpscsi[((op)<<1) + 1])
6511 #define ISP_SCSI_OPMAP(in, out) in, out
6512 static const uint8_t mbpscsi[] = {
6513 ISP_SCSI_OPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
6514 ISP_SCSI_OPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
6515 ISP_SCSI_OPMAP(0x03, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
6516 ISP_SCSI_OPMAP(0x1f, 0x01), /* 0x03: MBOX_DUMP_RAM */
6517 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
6518 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
6519 ISP_SCSI_OPMAP(0x3f, 0x3f), /* 0x06: MBOX_MAILBOX_REG_TEST */
6520 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
6521 ISP_SCSI_OPMAP(0x01, 0x0f), /* 0x08: MBOX_ABOUT_FIRMWARE */
6522 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x09: */
6523 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0a: */
6524 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0b: */
6525 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0c: */
6526 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0d: */
6527 ISP_SCSI_OPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
6528 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x0f: */
6529 ISP_SCSI_OPMAP(0x1f, 0x1f), /* 0x10: MBOX_INIT_REQ_QUEUE */
6530 ISP_SCSI_OPMAP(0x3f, 0x3f), /* 0x11: MBOX_INIT_RES_QUEUE */
6531 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x12: MBOX_EXECUTE_IOCB */
6532 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
6533 ISP_SCSI_OPMAP(0x01, 0x3f), /* 0x14: MBOX_STOP_FIRMWARE */
6534 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x15: MBOX_ABORT */
6535 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x16: MBOX_ABORT_DEVICE */
6536 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x17: MBOX_ABORT_TARGET */
6537 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x18: MBOX_BUS_RESET */
6538 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x19: MBOX_STOP_QUEUE */
6539 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1a: MBOX_START_QUEUE */
6540 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
6541 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x1c: MBOX_ABORT_QUEUE */
6542 ISP_SCSI_OPMAP(0x03, 0x4f), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
6543 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x1e: */
6544 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
6545 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x20: MBOX_GET_INIT_SCSI_ID */
6546 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x21: MBOX_GET_SELECT_TIMEOUT */
6547 ISP_SCSI_OPMAP(0x01, 0xc7), /* 0x22: MBOX_GET_RETRY_COUNT */
6548 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x23: MBOX_GET_TAG_AGE_LIMIT */
6549 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x24: MBOX_GET_CLOCK_RATE */
6550 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x25: MBOX_GET_ACT_NEG_STATE */
6551 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x26: MBOX_GET_ASYNC_DATA_SETUP_TIME */
6552 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x27: MBOX_GET_PCI_PARAMS */
6553 ISP_SCSI_OPMAP(0x03, 0x4f), /* 0x28: MBOX_GET_TARGET_PARAMS */
6554 ISP_SCSI_OPMAP(0x03, 0x0f), /* 0x29: MBOX_GET_DEV_QUEUE_PARAMS */
6555 ISP_SCSI_OPMAP(0x01, 0x07), /* 0x2a: MBOX_GET_RESET_DELAY_PARAMS */
6556 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2b: */
6557 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2c: */
6558 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2d: */
6559 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2e: */
6560 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x2f: */
6561 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x30: MBOX_SET_INIT_SCSI_ID */
6562 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x31: MBOX_SET_SELECT_TIMEOUT */
6563 ISP_SCSI_OPMAP(0xc7, 0xc7), /* 0x32: MBOX_SET_RETRY_COUNT */
6564 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x33: MBOX_SET_TAG_AGE_LIMIT */
6565 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x34: MBOX_SET_CLOCK_RATE */
6566 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x35: MBOX_SET_ACT_NEG_STATE */
6567 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x36: MBOX_SET_ASYNC_DATA_SETUP_TIME */
6568 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x37: MBOX_SET_PCI_CONTROL_PARAMS */
6569 ISP_SCSI_OPMAP(0x4f, 0x4f), /* 0x38: MBOX_SET_TARGET_PARAMS */
6570 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x39: MBOX_SET_DEV_QUEUE_PARAMS */
6571 ISP_SCSI_OPMAP(0x07, 0x07), /* 0x3a: MBOX_SET_RESET_DELAY_PARAMS */
6572 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3b: */
6573 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3c: */
6574 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3d: */
6575 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3e: */
6576 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x3f: */
6577 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x40: MBOX_RETURN_BIOS_BLOCK_ADDR */
6578 ISP_SCSI_OPMAP(0x3f, 0x01), /* 0x41: MBOX_WRITE_FOUR_RAM_WORDS */
6579 ISP_SCSI_OPMAP(0x03, 0x07), /* 0x42: MBOX_EXEC_BIOS_IOCB */
6580 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x43: */
6581 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x44: */
6582 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x45: SET SYSTEM PARAMETER */
6583 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x46: GET SYSTEM PARAMETER */
6584 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x47: */
6585 ISP_SCSI_OPMAP(0x01, 0xcf), /* 0x48: GET SCAM CONFIGURATION */
6586 ISP_SCSI_OPMAP(0xcf, 0xcf), /* 0x49: SET SCAM CONFIGURATION */
6587 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x4a: MBOX_SET_FIRMWARE_FEATURES */
6588 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x4b: MBOX_GET_FIRMWARE_FEATURES */
6589 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4c: */
6590 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4d: */
6591 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4e: */
6592 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x4f: */
6593 ISP_SCSI_OPMAP(0xdf, 0xdf), /* 0x50: LOAD RAM A64 */
6594 ISP_SCSI_OPMAP(0xdf, 0xdf), /* 0x51: DUMP RAM A64 */
6595 ISP_SCSI_OPMAP(0xdf, 0xff), /* 0x52: INITIALIZE REQUEST QUEUE A64 */
6596 ISP_SCSI_OPMAP(0xef, 0xff), /* 0x53: INITIALIZE RESPONSE QUEUE A64 */
6597 ISP_SCSI_OPMAP(0xcf, 0x01), /* 0x54: EXECUCUTE COMMAND IOCB A64 */
6598 ISP_SCSI_OPMAP(0x07, 0x01), /* 0x55: ENABLE TARGET MODE */
6599 ISP_SCSI_OPMAP(0x03, 0x0f), /* 0x56: GET TARGET STATUS */
6600 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x57: */
6601 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x58: */
6602 ISP_SCSI_OPMAP(0x00, 0x00), /* 0x59: */
6603 ISP_SCSI_OPMAP(0x03, 0x03), /* 0x5a: SET DATA OVERRUN RECOVERY MODE */
6604 ISP_SCSI_OPMAP(0x01, 0x03), /* 0x5b: GET DATA OVERRUN RECOVERY MODE */
6605 ISP_SCSI_OPMAP(0x0f, 0x0f), /* 0x5c: SET HOST DATA */
6606 ISP_SCSI_OPMAP(0x01, 0x01) /* 0x5d: GET NOST DATA */
6608 #define MAX_SCSI_OPCODE 0x5d
6610 static const char *scsi_mbcmd_names[] = {
6627 "INIT REQUEST QUEUE",
6628 "INIT RESULT QUEUE",
6638 "SINGLE STEP QUEUE",
6640 "GET DEV QUEUE STATUS",
6642 "GET FIRMWARE STATUS",
6644 "GET SELECT TIMEOUT",
6646 "GET TAG AGE LIMIT",
6648 "GET ACT NEG STATE",
6649 "GET ASYNC DATA SETUP TIME",
6651 "GET TARGET PARAMS",
6652 "GET DEV QUEUE PARAMS",
6653 "GET RESET DELAY PARAMS",
6660 "SET SELECT TIMEOUT",
6662 "SET TAG AGE LIMIT",
6664 "SET ACT NEG STATE",
6665 "SET ASYNC DATA SETUP TIME",
6666 "SET PCI CONTROL PARAMS",
6667 "SET TARGET PARAMS",
6668 "SET DEV QUEUE PARAMS",
6669 "SET RESET DELAY PARAMS",
6675 "RETURN BIOS BLOCK ADDR",
6676 "WRITE FOUR RAM WORDS",
6680 "SET SYSTEM PARAMETER",
6681 "GET SYSTEM PARAMETER",
6683 "GET SCAM CONFIGURATION",
6684 "SET SCAM CONFIGURATION",
6685 "SET FIRMWARE FEATURES",
6686 "GET FIRMWARE FEATURES",
6693 "INITIALIZE REQUEST QUEUE A64",
6694 "INITIALIZE RESPONSE QUEUE A64",
6696 "ENABLE TARGET MODE",
6697 "GET TARGET MODE STATE",
6701 "SET DATA OVERRUN RECOVERY MODE",
6702 "GET DATA OVERRUN RECOVERY MODE",
6707 #define ISP_FC_IBITS(op) ((mbpfc[((op)<<3) + 0] << 24) | (mbpfc[((op)<<3) + 1] << 16) | (mbpfc[((op)<<3) + 2] << 8) | (mbpfc[((op)<<3) + 3]))
6708 #define ISP_FC_OBITS(op) ((mbpfc[((op)<<3) + 4] << 24) | (mbpfc[((op)<<3) + 5] << 16) | (mbpfc[((op)<<3) + 6] << 8) | (mbpfc[((op)<<3) + 7]))
6710 #define ISP_FC_OPMAP(in0, out0) 0, 0, 0, in0, 0, 0, 0, out0
6711 #define ISP_FC_OPMAP_HALF(in1, in0, out1, out0) 0, 0, in1, in0, 0, 0, out1, out0
6712 #define ISP_FC_OPMAP_FULL(in3, in2, in1, in0, out3, out2, out1, out0) in3, in2, in1, in0, out3, out2, out1, out0
6713 static const uint32_t mbpfc[] = {
6714 ISP_FC_OPMAP(0x01, 0x01), /* 0x00: MBOX_NO_OP */
6715 ISP_FC_OPMAP(0x1f, 0x01), /* 0x01: MBOX_LOAD_RAM */
6716 ISP_FC_OPMAP(0x0f, 0x01), /* 0x02: MBOX_EXEC_FIRMWARE */
6717 ISP_FC_OPMAP(0xdf, 0x01), /* 0x03: MBOX_DUMP_RAM */
6718 ISP_FC_OPMAP(0x07, 0x07), /* 0x04: MBOX_WRITE_RAM_WORD */
6719 ISP_FC_OPMAP(0x03, 0x07), /* 0x05: MBOX_READ_RAM_WORD */
6720 ISP_FC_OPMAP_FULL(0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff), /* 0x06: MBOX_MAILBOX_REG_TEST */
6721 ISP_FC_OPMAP(0x07, 0x07), /* 0x07: MBOX_VERIFY_CHECKSUM */
6722 ISP_FC_OPMAP_FULL(0x0, 0x0, 0x0, 0x01, 0x0, 0x3, 0x80, 0x7f), /* 0x08: MBOX_ABOUT_FIRMWARE */
6723 ISP_FC_OPMAP(0xdf, 0x01), /* 0x09: MBOX_LOAD_RISC_RAM_2100 */
6724 ISP_FC_OPMAP(0xdf, 0x01), /* 0x0a: DUMP RAM */
6725 ISP_FC_OPMAP_HALF(0x1, 0xff, 0x0, 0x01), /* 0x0b: MBOX_LOAD_RISC_RAM */
6726 ISP_FC_OPMAP(0x00, 0x00), /* 0x0c: */
6727 ISP_FC_OPMAP_HALF(0x1, 0x0f, 0x0, 0x01), /* 0x0d: MBOX_WRITE_RAM_WORD_EXTENDED */
6728 ISP_FC_OPMAP(0x01, 0x05), /* 0x0e: MBOX_CHECK_FIRMWARE */
6729 ISP_FC_OPMAP_HALF(0x1, 0x03, 0x0, 0x0d), /* 0x0f: MBOX_READ_RAM_WORD_EXTENDED */
6730 ISP_FC_OPMAP(0x1f, 0x11), /* 0x10: MBOX_INIT_REQ_QUEUE */
6731 ISP_FC_OPMAP(0x2f, 0x21), /* 0x11: MBOX_INIT_RES_QUEUE */
6732 ISP_FC_OPMAP(0x0f, 0x01), /* 0x12: MBOX_EXECUTE_IOCB */
6733 ISP_FC_OPMAP(0x03, 0x03), /* 0x13: MBOX_WAKE_UP */
6734 ISP_FC_OPMAP(0x01, 0xff), /* 0x14: MBOX_STOP_FIRMWARE */
6735 ISP_FC_OPMAP(0x4f, 0x01), /* 0x15: MBOX_ABORT */
6736 ISP_FC_OPMAP(0x07, 0x01), /* 0x16: MBOX_ABORT_DEVICE */
6737 ISP_FC_OPMAP(0x07, 0x01), /* 0x17: MBOX_ABORT_TARGET */
6738 ISP_FC_OPMAP(0x03, 0x03), /* 0x18: MBOX_BUS_RESET */
6739 ISP_FC_OPMAP(0x07, 0x05), /* 0x19: MBOX_STOP_QUEUE */
6740 ISP_FC_OPMAP(0x07, 0x05), /* 0x1a: MBOX_START_QUEUE */
6741 ISP_FC_OPMAP(0x07, 0x05), /* 0x1b: MBOX_SINGLE_STEP_QUEUE */
6742 ISP_FC_OPMAP(0x07, 0x05), /* 0x1c: MBOX_ABORT_QUEUE */
6743 ISP_FC_OPMAP(0x07, 0x03), /* 0x1d: MBOX_GET_DEV_QUEUE_STATUS */
6744 ISP_FC_OPMAP(0x00, 0x00), /* 0x1e: */
6745 ISP_FC_OPMAP(0x01, 0x07), /* 0x1f: MBOX_GET_FIRMWARE_STATUS */
6746 ISP_FC_OPMAP_HALF(0x2, 0x01, 0x7e, 0xcf), /* 0x20: MBOX_GET_LOOP_ID */
6747 ISP_FC_OPMAP(0x00, 0x00), /* 0x21: */
6748 ISP_FC_OPMAP(0x01, 0x07), /* 0x22: MBOX_GET_RETRY_COUNT */
6749 ISP_FC_OPMAP(0x00, 0x00), /* 0x23: */
6750 ISP_FC_OPMAP(0x00, 0x00), /* 0x24: */
6751 ISP_FC_OPMAP(0x00, 0x00), /* 0x25: */
6752 ISP_FC_OPMAP(0x00, 0x00), /* 0x26: */
6753 ISP_FC_OPMAP(0x00, 0x00), /* 0x27: */
6754 ISP_FC_OPMAP(0x01, 0x03), /* 0x28: MBOX_GET_FIRMWARE_OPTIONS */
6755 ISP_FC_OPMAP(0x03, 0x07), /* 0x29: MBOX_GET_PORT_QUEUE_PARAMS */
6756 ISP_FC_OPMAP(0x00, 0x00), /* 0x2a: */
6757 ISP_FC_OPMAP(0x00, 0x00), /* 0x2b: */
6758 ISP_FC_OPMAP(0x00, 0x00), /* 0x2c: */
6759 ISP_FC_OPMAP(0x00, 0x00), /* 0x2d: */
6760 ISP_FC_OPMAP(0x00, 0x00), /* 0x2e: */
6761 ISP_FC_OPMAP(0x00, 0x00), /* 0x2f: */
6762 ISP_FC_OPMAP(0x00, 0x00), /* 0x30: */
6763 ISP_FC_OPMAP(0x00, 0x00), /* 0x31: */
6764 ISP_FC_OPMAP(0x07, 0x07), /* 0x32: MBOX_SET_RETRY_COUNT */
6765 ISP_FC_OPMAP(0x00, 0x00), /* 0x33: */
6766 ISP_FC_OPMAP(0x00, 0x00), /* 0x34: */
6767 ISP_FC_OPMAP(0x00, 0x00), /* 0x35: */
6768 ISP_FC_OPMAP(0x00, 0x00), /* 0x36: */
6769 ISP_FC_OPMAP(0x00, 0x00), /* 0x37: */
6770 ISP_FC_OPMAP(0x0f, 0x01), /* 0x38: MBOX_SET_FIRMWARE_OPTIONS */
6771 ISP_FC_OPMAP(0x0f, 0x07), /* 0x39: MBOX_SET_PORT_QUEUE_PARAMS */
6772 ISP_FC_OPMAP(0x00, 0x00), /* 0x3a: */
6773 ISP_FC_OPMAP(0x00, 0x00), /* 0x3b: */
6774 ISP_FC_OPMAP(0x00, 0x00), /* 0x3c: */
6775 ISP_FC_OPMAP(0x00, 0x00), /* 0x3d: */
6776 ISP_FC_OPMAP(0x00, 0x00), /* 0x3e: */
6777 ISP_FC_OPMAP(0x00, 0x00), /* 0x3f: */
6778 ISP_FC_OPMAP(0x03, 0x01), /* 0x40: MBOX_LOOP_PORT_BYPASS */
6779 ISP_FC_OPMAP(0x03, 0x01), /* 0x41: MBOX_LOOP_PORT_ENABLE */
6780 ISP_FC_OPMAP_HALF(0x0, 0x01, 0x3, 0xcf), /* 0x42: MBOX_GET_RESOURCE_COUNT */
6781 ISP_FC_OPMAP(0x01, 0x01), /* 0x43: MBOX_REQUEST_OFFLINE_MODE */
6782 ISP_FC_OPMAP(0x00, 0x00), /* 0x44: */
6783 ISP_FC_OPMAP(0x00, 0x00), /* 0x45: */
6784 ISP_FC_OPMAP(0x00, 0x00), /* 0x46: */
6785 ISP_FC_OPMAP(0xcf, 0x03), /* 0x47: GET PORT_DATABASE ENHANCED */
6786 ISP_FC_OPMAP(0xcf, 0x0f), /* 0x48: MBOX_INIT_FIRMWARE_MULTI_ID */
6787 ISP_FC_OPMAP(0xcd, 0x01), /* 0x49: MBOX_GET_VP_DATABASE */
6788 ISP_FC_OPMAP_HALF(0x2, 0xcd, 0x0, 0x01), /* 0x4a: MBOX_GET_VP_DATABASE_ENTRY */
6789 ISP_FC_OPMAP(0x00, 0x00), /* 0x4b: */
6790 ISP_FC_OPMAP(0x00, 0x00), /* 0x4c: */
6791 ISP_FC_OPMAP(0x00, 0x00), /* 0x4d: */
6792 ISP_FC_OPMAP(0x00, 0x00), /* 0x4e: */
6793 ISP_FC_OPMAP(0x00, 0x00), /* 0x4f: */
6794 ISP_FC_OPMAP(0x00, 0x00), /* 0x50: */
6795 ISP_FC_OPMAP(0x00, 0x00), /* 0x51: */
6796 ISP_FC_OPMAP(0x00, 0x00), /* 0x52: */
6797 ISP_FC_OPMAP(0x00, 0x00), /* 0x53: */
6798 ISP_FC_OPMAP(0xcf, 0x01), /* 0x54: EXECUTE IOCB A64 */
6799 ISP_FC_OPMAP(0x00, 0x00), /* 0x55: */
6800 ISP_FC_OPMAP(0x00, 0x00), /* 0x56: */
6801 ISP_FC_OPMAP(0x00, 0x00), /* 0x57: */
6802 ISP_FC_OPMAP(0x00, 0x00), /* 0x58: */
6803 ISP_FC_OPMAP(0x00, 0x00), /* 0x59: */
6804 ISP_FC_OPMAP(0x00, 0x00), /* 0x5a: */
6805 ISP_FC_OPMAP(0x03, 0x01), /* 0x5b: MBOX_DRIVER_HEARTBEAT */
6806 ISP_FC_OPMAP(0xcf, 0x01), /* 0x5c: MBOX_FW_HEARTBEAT */
6807 ISP_FC_OPMAP(0x07, 0x1f), /* 0x5d: MBOX_GET_SET_DATA_RATE */
6808 ISP_FC_OPMAP(0x00, 0x00), /* 0x5e: */
6809 ISP_FC_OPMAP(0x00, 0x00), /* 0x5f: */
6810 ISP_FC_OPMAP(0xcf, 0x0f), /* 0x60: MBOX_INIT_FIRMWARE */
6811 ISP_FC_OPMAP(0x00, 0x00), /* 0x61: */
6812 ISP_FC_OPMAP(0x01, 0x01), /* 0x62: MBOX_INIT_LIP */
6813 ISP_FC_OPMAP(0xcd, 0x03), /* 0x63: MBOX_GET_FC_AL_POSITION_MAP */
6814 ISP_FC_OPMAP(0xcf, 0x01), /* 0x64: MBOX_GET_PORT_DB */
6815 ISP_FC_OPMAP(0x07, 0x01), /* 0x65: MBOX_CLEAR_ACA */
6816 ISP_FC_OPMAP(0x07, 0x01), /* 0x66: MBOX_TARGET_RESET */
6817 ISP_FC_OPMAP(0x07, 0x01), /* 0x67: MBOX_CLEAR_TASK_SET */
6818 ISP_FC_OPMAP(0x07, 0x01), /* 0x68: MBOX_ABORT_TASK_SET */
6819 ISP_FC_OPMAP(0x01, 0x07), /* 0x69: MBOX_GET_FW_STATE */
6820 ISP_FC_OPMAP_HALF(0x6, 0x03, 0x0, 0xcf), /* 0x6a: MBOX_GET_PORT_NAME */
6821 ISP_FC_OPMAP(0xcf, 0x01), /* 0x6b: MBOX_GET_LINK_STATUS */
6822 ISP_FC_OPMAP(0x0f, 0x01), /* 0x6c: MBOX_INIT_LIP_RESET */
6823 ISP_FC_OPMAP(0x00, 0x00), /* 0x6d: */
6824 ISP_FC_OPMAP(0xcf, 0x03), /* 0x6e: MBOX_SEND_SNS */
6825 ISP_FC_OPMAP(0x0f, 0x07), /* 0x6f: MBOX_FABRIC_LOGIN */
6826 ISP_FC_OPMAP(0x03, 0x01), /* 0x70: MBOX_SEND_CHANGE_REQUEST */
6827 ISP_FC_OPMAP(0x03, 0x03), /* 0x71: MBOX_FABRIC_LOGOUT */
6828 ISP_FC_OPMAP(0x0f, 0x0f), /* 0x72: MBOX_INIT_LIP_LOGIN */
6829 ISP_FC_OPMAP(0x00, 0x00), /* 0x73: */
6830 ISP_FC_OPMAP(0x07, 0x01), /* 0x74: LOGIN LOOP PORT */
6831 ISP_FC_OPMAP_HALF(0x03, 0xcf, 0x00, 0x07), /* 0x75: GET PORT/NODE NAME LIST */
6832 ISP_FC_OPMAP(0x4f, 0x01), /* 0x76: SET VENDOR ID */
6833 ISP_FC_OPMAP(0xcd, 0x01), /* 0x77: INITIALIZE IP MAILBOX */
6834 ISP_FC_OPMAP(0x00, 0x00), /* 0x78: */
6835 ISP_FC_OPMAP(0x00, 0x00), /* 0x79: */
6836 ISP_FC_OPMAP(0x00, 0x00), /* 0x7a: */
6837 ISP_FC_OPMAP(0x00, 0x00), /* 0x7b: */
6838 ISP_FC_OPMAP_HALF(0x03, 0x4f, 0x00, 0x07), /* 0x7c: Get ID List */
6839 ISP_FC_OPMAP(0xcf, 0x01), /* 0x7d: SEND LFA */
6840 ISP_FC_OPMAP(0x0f, 0x01) /* 0x7e: LUN RESET */
6842 #define MAX_FC_OPCODE 0x7e
6846 * (1): this sets bits 21..16 in mailbox register #8, which we nominally
6847 * do not access at this time in the core driver. The caller is
6848 * responsible for setting this register first (Gross!). The assumption
6849 * is that we won't overflow.
6852 static const char *fc_mbcmd_names[] = {
6866 "WRITE RAM WORD EXTENDED",
6868 "READ RAM WORD EXTENDED",
6869 "INIT REQUEST QUEUE",
6870 "INIT RESULT QUEUE",
6880 "SINGLE STEP QUEUE",
6882 "GET DEV QUEUE STATUS",
6884 "GET FIRMWARE STATUS",
6893 "GET FIRMWARE OPTIONS",
6894 "GET PORT QUEUE PARAMS",
6909 "SET FIRMWARE OPTIONS",
6910 "SET PORT QUEUE PARAMS",
6919 "GET RESOURCE COUNT",
6920 "REQUEST NON PARTICIPATING MODE",
6924 "GET PORT DATABASE ENHANCED",
6925 "INIT FIRMWARE MULTI ID",
6927 "GET VP DATABASE ENTRY",
6946 "GET/SET DATA RATE",
6952 "GET FC-AL POSITION MAP",
6953 "GET PORT DATABASE",
6965 "SEND CHANGE REQUEST",
6970 "GET PORT/NODE NAME LIST",
6972 "INITIALIZE IP MAILBOX",
6983 isp_mboxcmd_qnw(ispsoftc_t *isp, mbreg_t *mbp, int nodelay)
6985 unsigned int ibits, obits, box, opcode;
6987 opcode = mbp->param[0];
6989 ibits = ISP_FC_IBITS(opcode);
6990 obits = ISP_FC_OBITS(opcode);
6992 ibits = ISP_SCSI_IBITS(opcode);
6993 obits = ISP_SCSI_OBITS(opcode);
6995 ibits |= mbp->ibits;
6996 obits |= mbp->obits;
6997 for (box = 0; box < ISP_NMBOX(isp); box++) {
6998 if (ibits & (1 << box)) {
6999 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
7002 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
7006 isp->isp_lastmbxcmd = opcode;
7007 isp->isp_obits = obits;
7008 isp->isp_mboxbsy = 1;
7011 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_SET_HOST_INT);
7013 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
7016 * Oddly enough, if we're not delaying for an answer,
7017 * delay a bit to give the f/w a chance to pick up the
7026 isp_mboxcmd(ispsoftc_t *isp, mbreg_t *mbp)
7028 const char *cname, *xname, *sname;
7029 char tname[16], mname[16];
7030 unsigned int ibits, obits, box, opcode;
7032 opcode = mbp->param[0];
7034 if (opcode > MAX_FC_OPCODE) {
7035 mbp->param[0] = MBOX_INVALID_COMMAND;
7036 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
7039 cname = fc_mbcmd_names[opcode];
7040 ibits = ISP_FC_IBITS(opcode);
7041 obits = ISP_FC_OBITS(opcode);
7043 if (opcode > MAX_SCSI_OPCODE) {
7044 mbp->param[0] = MBOX_INVALID_COMMAND;
7045 isp_prt(isp, ISP_LOGERR, "Unknown Command 0x%x", opcode);
7048 cname = scsi_mbcmd_names[opcode];
7049 ibits = ISP_SCSI_IBITS(opcode);
7050 obits = ISP_SCSI_OBITS(opcode);
7052 if (cname == NULL) {
7054 ISP_SNPRINTF(tname, sizeof tname, "opcode %x", opcode);
7056 isp_prt(isp, ISP_LOGDEBUG3, "Mailbox Command '%s'", cname);
7059 * Pick up any additional bits that the caller might have set.
7061 ibits |= mbp->ibits;
7062 obits |= mbp->obits;
7065 * Mask any bits that the caller wants us to mask
7067 ibits &= mbp->ibitm;
7068 obits &= mbp->obitm;
7071 if (ibits == 0 && obits == 0) {
7072 mbp->param[0] = MBOX_COMMAND_PARAM_ERROR;
7073 isp_prt(isp, ISP_LOGERR, "no parameters for 0x%x", opcode);
7078 * Get exclusive usage of mailbox registers.
7080 if (MBOX_ACQUIRE(isp)) {
7081 mbp->param[0] = MBOX_REGS_BUSY;
7085 for (box = 0; box < ISP_NMBOX(isp); box++) {
7086 if (ibits & (1 << box)) {
7087 isp_prt(isp, ISP_LOGDEBUG3, "IN mbox %d = 0x%04x", box,
7089 ISP_WRITE(isp, MBOX_OFF(box), mbp->param[box]);
7091 isp->isp_mboxtmp[box] = mbp->param[box] = 0;
7094 isp->isp_lastmbxcmd = opcode;
7097 * We assume that we can't overwrite a previous command.
7099 isp->isp_obits = obits;
7100 isp->isp_mboxbsy = 1;
7103 * Set Host Interrupt condition so that RISC will pick up mailbox regs.
7106 ISP_WRITE(isp, BIU2400_HCCR, HCCR_2400_CMD_SET_HOST_INT);
7108 ISP_WRITE(isp, HCCR, HCCR_CMD_SET_HOST_INT);
7112 * While we haven't finished the command, spin our wheels here.
7114 MBOX_WAIT_COMPLETE(isp, mbp);
7117 * Did the command time out?
7119 if (mbp->param[0] == MBOX_TIMEOUT) {
7120 isp->isp_mboxbsy = 0;
7126 * Copy back output registers.
7128 for (box = 0; box < ISP_NMBOX(isp); box++) {
7129 if (obits & (1 << box)) {
7130 mbp->param[box] = isp->isp_mboxtmp[box];
7131 isp_prt(isp, ISP_LOGDEBUG3, "OUT mbox %d = 0x%04x", box,
7136 isp->isp_mboxbsy = 0;
7139 if (mbp->logval == 0 || mbp->param[0] == MBOX_COMMAND_COMPLETE)
7142 if ((mbp->param[0] & 0xbfe0) == 0 &&
7143 (mbp->logval & MBLOGMASK(mbp->param[0])) == 0)
7148 switch (mbp->param[0]) {
7149 case MBOX_INVALID_COMMAND:
7150 xname = "INVALID COMMAND";
7152 case MBOX_HOST_INTERFACE_ERROR:
7153 xname = "HOST INTERFACE ERROR";
7155 case MBOX_TEST_FAILED:
7156 xname = "TEST FAILED";
7158 case MBOX_COMMAND_ERROR:
7159 xname = "COMMAND ERROR";
7160 ISP_SNPRINTF(mname, sizeof(mname), " subcode 0x%x",
7164 case MBOX_COMMAND_PARAM_ERROR:
7165 xname = "COMMAND PARAMETER ERROR";
7167 case MBOX_PORT_ID_USED:
7168 xname = "PORT ID ALREADY IN USE";
7170 case MBOX_LOOP_ID_USED:
7171 xname = "LOOP ID ALREADY IN USE";
7173 case MBOX_ALL_IDS_USED:
7174 xname = "ALL LOOP IDS IN USE";
7176 case MBOX_NOT_LOGGED_IN:
7177 xname = "NOT LOGGED IN";
7179 case MBOX_LINK_DOWN_ERROR:
7180 xname = "LINK DOWN ERROR";
7182 case MBOX_LOOPBACK_ERROR:
7183 xname = "LOOPBACK ERROR";
7185 case MBOX_CHECKSUM_ERROR:
7186 xname = "CHECKSUM ERROR";
7188 case MBOX_INVALID_PRODUCT_KEY:
7189 xname = "INVALID PRODUCT KEY";
7191 case MBOX_REGS_BUSY:
7192 xname = "REGISTERS BUSY";
7198 ISP_SNPRINTF(mname, sizeof mname, "error 0x%x", mbp->param[0]);
7203 isp_prt(isp, ISP_LOGALL, "Mailbox Command '%s' failed (%s%s)",
7204 cname, xname, sname);
7209 isp_fw_state(ispsoftc_t *isp, int chan)
7214 MBSINIT(&mbs, MBOX_GET_FW_STATE, MBLOGALL, 0);
7215 isp_mboxcmd(isp, &mbs);
7216 if (mbs.param[0] == MBOX_COMMAND_COMPLETE) {
7217 return (mbs.param[1]);
7224 isp_spi_update(ispsoftc_t *isp, int chan)
7232 * There are no 'per-bus' settings for Fibre Channel.
7236 sdp = SDPARAM(isp, chan);
7239 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7240 uint16_t flags, period, offset;
7243 if (sdp->isp_devparam[tgt].dev_enable == 0) {
7244 sdp->isp_devparam[tgt].dev_update = 0;
7245 sdp->isp_devparam[tgt].dev_refresh = 0;
7246 isp_prt(isp, ISP_LOGDEBUG0, "skipping target %d bus %d update", tgt, chan);
7250 * If the goal is to update the status of the device,
7251 * take what's in goal_flags and try and set the device
7252 * toward that. Otherwise, if we're just refreshing the
7253 * current device state, get the current parameters.
7256 MBSINIT(&mbs, 0, MBLOGALL, 0);
7259 * Refresh overrides set
7261 if (sdp->isp_devparam[tgt].dev_refresh) {
7262 mbs.param[0] = MBOX_GET_TARGET_PARAMS;
7264 } else if (sdp->isp_devparam[tgt].dev_update) {
7265 mbs.param[0] = MBOX_SET_TARGET_PARAMS;
7268 * Make sure goal_flags has "Renegotiate on Error"
7269 * on and "Freeze Queue on Error" off.
7271 sdp->isp_devparam[tgt].goal_flags |= DPARM_RENEG;
7272 sdp->isp_devparam[tgt].goal_flags &= ~DPARM_QFRZ;
7273 mbs.param[2] = sdp->isp_devparam[tgt].goal_flags;
7276 * Insist that PARITY must be enabled
7277 * if SYNC or WIDE is enabled.
7279 if ((mbs.param[2] & (DPARM_SYNC|DPARM_WIDE)) != 0) {
7280 mbs.param[2] |= DPARM_PARITY;
7283 if (mbs.param[2] & DPARM_SYNC) {
7285 (sdp->isp_devparam[tgt].goal_offset << 8) |
7286 (sdp->isp_devparam[tgt].goal_period);
7289 * A command completion later that has
7290 * RQSTF_NEGOTIATION set can cause
7291 * the dev_refresh/announce cycle also.
7293 * Note: It is really important to update our current
7294 * flags with at least the state of TAG capabilities-
7295 * otherwise we might try and send a tagged command
7296 * when we have it all turned off. So change it here
7297 * to say that current already matches goal.
7299 sdp->isp_devparam[tgt].actv_flags &= ~DPARM_TQING;
7300 sdp->isp_devparam[tgt].actv_flags |=
7301 (sdp->isp_devparam[tgt].goal_flags & DPARM_TQING);
7302 isp_prt(isp, ISP_LOGDEBUG0, "bus %d set tgt %d flags 0x%x off 0x%x period 0x%x",
7303 chan, tgt, mbs.param[2], mbs.param[3] >> 8, mbs.param[3] & 0xff);
7308 mbs.param[1] = (chan << 15) | (tgt << 8);
7309 isp_mboxcmd(isp, &mbs);
7310 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7314 sdp->sendmarker = 1;
7315 sdp->isp_devparam[tgt].dev_update = 0;
7316 sdp->isp_devparam[tgt].dev_refresh = 1;
7318 sdp->isp_devparam[tgt].dev_refresh = 0;
7319 flags = mbs.param[2];
7320 period = mbs.param[3] & 0xff;
7321 offset = mbs.param[3] >> 8;
7322 sdp->isp_devparam[tgt].actv_flags = flags;
7323 sdp->isp_devparam[tgt].actv_period = period;
7324 sdp->isp_devparam[tgt].actv_offset = offset;
7325 isp_async(isp, ISPASYNC_NEW_TGT_PARAMS, chan, tgt);
7329 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7330 if (sdp->isp_devparam[tgt].dev_update ||
7331 sdp->isp_devparam[tgt].dev_refresh) {
7339 isp_setdfltsdparm(ispsoftc_t *isp)
7342 sdparam *sdp, *sdp1;
7344 sdp = SDPARAM(isp, 0);
7345 sdp->role = GET_DEFAULT_ROLE(isp, 0);
7346 if (IS_DUALBUS(isp)) {
7348 sdp1->role = GET_DEFAULT_ROLE(isp, 1);
7354 * Establish some default parameters.
7356 sdp->isp_cmd_dma_burst_enable = 0;
7357 sdp->isp_data_dma_burst_enabl = 1;
7358 sdp->isp_fifo_threshold = 0;
7359 sdp->isp_initiator_id = DEFAULT_IID(isp, 0);
7360 if (isp->isp_type >= ISP_HA_SCSI_1040) {
7361 sdp->isp_async_data_setup = 9;
7363 sdp->isp_async_data_setup = 6;
7365 sdp->isp_selection_timeout = 250;
7366 sdp->isp_max_queue_depth = MAXISPREQUEST(isp);
7367 sdp->isp_tag_aging = 8;
7368 sdp->isp_bus_reset_delay = 5;
7370 * Don't retry selection, busy or queue full automatically- reflect
7373 sdp->isp_retry_count = 0;
7374 sdp->isp_retry_delay = 0;
7376 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7377 sdp->isp_devparam[tgt].exc_throttle = ISP_EXEC_THROTTLE;
7378 sdp->isp_devparam[tgt].dev_enable = 1;
7382 * The trick here is to establish a default for the default (honk!)
7383 * state (goal_flags). Then try and get the current status from
7384 * the card to fill in the current state. We don't, in fact, set
7385 * the default to the SAFE default state- that's not the goal state.
7387 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7389 sdp->isp_devparam[tgt].actv_offset = 0;
7390 sdp->isp_devparam[tgt].actv_period = 0;
7391 sdp->isp_devparam[tgt].actv_flags = 0;
7393 sdp->isp_devparam[tgt].goal_flags =
7394 sdp->isp_devparam[tgt].nvrm_flags = DPARM_DEFAULT;
7397 * We default to Wide/Fast for versions less than a 1040
7398 * (unless it's SBus).
7400 if (IS_ULTRA3(isp)) {
7401 off = ISP_80M_SYNCPARMS >> 8;
7402 per = ISP_80M_SYNCPARMS & 0xff;
7403 } else if (IS_ULTRA2(isp)) {
7404 off = ISP_40M_SYNCPARMS >> 8;
7405 per = ISP_40M_SYNCPARMS & 0xff;
7406 } else if (IS_1240(isp)) {
7407 off = ISP_20M_SYNCPARMS >> 8;
7408 per = ISP_20M_SYNCPARMS & 0xff;
7409 } else if ((isp->isp_bustype == ISP_BT_SBUS &&
7410 isp->isp_type < ISP_HA_SCSI_1020A) ||
7411 (isp->isp_bustype == ISP_BT_PCI &&
7412 isp->isp_type < ISP_HA_SCSI_1040) ||
7413 (isp->isp_clock && isp->isp_clock < 60) ||
7414 (sdp->isp_ultramode == 0)) {
7415 off = ISP_10M_SYNCPARMS >> 8;
7416 per = ISP_10M_SYNCPARMS & 0xff;
7418 off = ISP_20M_SYNCPARMS_1040 >> 8;
7419 per = ISP_20M_SYNCPARMS_1040 & 0xff;
7421 sdp->isp_devparam[tgt].goal_offset =
7422 sdp->isp_devparam[tgt].nvrm_offset = off;
7423 sdp->isp_devparam[tgt].goal_period =
7424 sdp->isp_devparam[tgt].nvrm_period = per;
7429 * If we're a dual bus card, just copy the data over
7433 sdp1->isp_initiator_id = DEFAULT_IID(isp, 1);
7437 * If we've not been told to avoid reading NVRAM, try and read it.
7438 * If we're successful reading it, we can then return because NVRAM
7439 * will tell us what the desired settings are. Otherwise, we establish
7440 * some reasonable 'fake' nvram and goal defaults.
7442 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7445 if (isp_read_nvram(isp, 0) == 0) {
7446 if (IS_DUALBUS(isp)) {
7447 if (isp_read_nvram(isp, 1) == 0) {
7452 MBSINIT(&mbs, MBOX_GET_ACT_NEG_STATE, MBLOGNONE, 0);
7453 isp_mboxcmd(isp, &mbs);
7454 if (mbs.param[0] != MBOX_COMMAND_COMPLETE) {
7455 sdp->isp_req_ack_active_neg = 1;
7456 sdp->isp_data_line_active_neg = 1;
7458 sdp1->isp_req_ack_active_neg = 1;
7459 sdp1->isp_data_line_active_neg = 1;
7462 sdp->isp_req_ack_active_neg =
7463 (mbs.param[1] >> 4) & 0x1;
7464 sdp->isp_data_line_active_neg =
7465 (mbs.param[1] >> 5) & 0x1;
7467 sdp1->isp_req_ack_active_neg =
7468 (mbs.param[2] >> 4) & 0x1;
7469 sdp1->isp_data_line_active_neg =
7470 (mbs.param[2] >> 5) & 0x1;
7478 isp_setdfltfcparm(ispsoftc_t *isp, int chan)
7480 fcparam *fcp = FCPARAM(isp, chan);
7483 * Establish some default parameters.
7485 fcp->role = GET_DEFAULT_ROLE(isp, chan);
7486 fcp->isp_maxalloc = ICB_DFLT_ALLOC;
7487 fcp->isp_retry_delay = ICB_DFLT_RDELAY;
7488 fcp->isp_retry_count = ICB_DFLT_RCOUNT;
7489 fcp->isp_loopid = DEFAULT_LOOPID(isp, chan);
7490 fcp->isp_wwnn_nvram = DEFAULT_NODEWWN(isp, chan);
7491 fcp->isp_wwpn_nvram = DEFAULT_PORTWWN(isp, chan);
7492 fcp->isp_fwoptions = 0;
7493 fcp->isp_lasthdl = NIL_HANDLE;
7496 fcp->isp_fwoptions |= ICB2400_OPT1_FAIRNESS;
7497 fcp->isp_fwoptions |= ICB2400_OPT1_HARD_ADDRESS;
7498 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX) {
7499 fcp->isp_fwoptions |= ICB2400_OPT1_FULL_DUPLEX;
7501 fcp->isp_fwoptions |= ICB2400_OPT1_BOTH_WWNS;
7503 fcp->isp_fwoptions |= ICBOPT_FAIRNESS;
7504 fcp->isp_fwoptions |= ICBOPT_PDBCHANGE_AE;
7505 fcp->isp_fwoptions |= ICBOPT_HARD_ADDRESS;
7506 if (isp->isp_confopts & ISP_CFG_FULL_DUPLEX) {
7507 fcp->isp_fwoptions |= ICBOPT_FULL_DUPLEX;
7510 * Make sure this is turned off now until we get
7511 * extended options from NVRAM
7513 fcp->isp_fwoptions &= ~ICBOPT_EXTENDED;
7518 * Now try and read NVRAM unless told to not do so.
7519 * This will set fcparam's isp_wwnn_nvram && isp_wwpn_nvram.
7521 if ((isp->isp_confopts & ISP_CFG_NONVRAM) == 0) {
7524 * Give a couple of tries at reading NVRAM.
7526 for (i = 0; i < 2; i++) {
7527 j = isp_read_nvram(isp, chan);
7533 isp->isp_confopts |= ISP_CFG_NONVRAM;
7537 fcp->isp_wwnn = ACTIVE_NODEWWN(isp, chan);
7538 fcp->isp_wwpn = ACTIVE_PORTWWN(isp, chan);
7539 isp_prt(isp, ISP_LOGCONFIG, "Chan %d 0x%08x%08x/0x%08x%08x Role %s",
7540 chan, (uint32_t) (fcp->isp_wwnn >> 32), (uint32_t) (fcp->isp_wwnn),
7541 (uint32_t) (fcp->isp_wwpn >> 32), (uint32_t) (fcp->isp_wwpn),
7542 isp_class3_roles[fcp->role]);
7546 * Re-initialize the ISP and complete all orphaned commands
7547 * with a 'botched' notice. The reset/init routines should
7548 * not disturb an already active list of commands.
7552 isp_reinit(ispsoftc_t *isp, int do_load_defaults)
7556 if (isp->isp_state != ISP_RESETSTATE)
7557 isp_reset(isp, do_load_defaults);
7558 if (isp->isp_state != ISP_RESETSTATE) {
7560 isp_prt(isp, ISP_LOGERR, "%s: cannot reset card", __func__);
7561 ISP_DISABLE_INTS(isp);
7566 if (isp->isp_state > ISP_RESETSTATE &&
7567 isp->isp_state != ISP_RUNSTATE) {
7569 isp_prt(isp, ISP_LOGERR, "%s: cannot init card", __func__);
7570 ISP_DISABLE_INTS(isp);
7573 * If we're in ISP_ROLE_NONE, turn off the lasers.
7575 if (!IS_24XX(isp)) {
7576 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FPM0_REGS);
7577 ISP_WRITE(isp, FPM_DIAG_CONFIG, FPM_SOFT_RESET);
7578 ISP_WRITE(isp, BIU2100_CSR, BIU2100_FB_REGS);
7579 ISP_WRITE(isp, FBM_CMD, FBMCMD_FIFO_RESET_ALL);
7580 ISP_WRITE(isp, BIU2100_CSR, BIU2100_RISC_REGS);
7586 isp->isp_nactive = 0;
7587 isp_clear_commands(isp);
7589 for (i = 0; i < isp->isp_nchan; i++)
7590 isp_clear_portdb(isp, i);
7599 isp_read_nvram(ispsoftc_t *isp, int bus)
7602 uint8_t csum, minversion;
7604 uint8_t _x[ISP2400_NVRAM_SIZE];
7605 uint16_t _s[ISP2400_NVRAM_SIZE>>1];
7607 #define nvram_data _n._x
7608 #define nvram_words _n._s
7611 return (isp_read_nvram_2400(isp, nvram_data));
7612 } else if (IS_FC(isp)) {
7613 amt = ISP2100_NVRAM_SIZE;
7615 } else if (IS_ULTRA2(isp)) {
7616 amt = ISP1080_NVRAM_SIZE;
7619 amt = ISP_NVRAM_SIZE;
7623 for (i = 0; i < amt>>1; i++) {
7624 isp_rdnvram_word(isp, i, &nvram_words[i]);
7627 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
7628 nvram_data[2] != 'P') {
7629 if (isp->isp_bustype != ISP_BT_SBUS) {
7630 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header");
7631 isp_prt(isp, ISP_LOGDEBUG0, "%x %x %x", nvram_data[0], nvram_data[1], nvram_data[2]);
7637 for (csum = 0, i = 0; i < amt; i++) {
7638 csum += nvram_data[i];
7641 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
7646 if (ISP_NVRAM_VERSION(nvram_data) < minversion) {
7647 isp_prt(isp, ISP_LOGWARN, "version %d NVRAM not understood",
7648 ISP_NVRAM_VERSION(nvram_data));
7653 if (IS_ULTRA3(isp)) {
7654 isp_parse_nvram_12160(isp, bus, nvram_data);
7655 } else if (IS_1080(isp)) {
7656 isp_parse_nvram_1080(isp, bus, nvram_data);
7657 } else if (IS_1280(isp) || IS_1240(isp)) {
7658 isp_parse_nvram_1080(isp, bus, nvram_data);
7659 } else if (IS_SCSI(isp)) {
7660 isp_parse_nvram_1020(isp, nvram_data);
7662 isp_parse_nvram_2100(isp, nvram_data);
7672 isp_read_nvram_2400(ispsoftc_t *isp, uint8_t *nvram_data)
7675 uint32_t addr, csum, lwrds, *dptr;
7677 if (isp->isp_port) {
7678 addr = ISP2400_NVRAM_PORT1_ADDR;
7680 addr = ISP2400_NVRAM_PORT0_ADDR;
7683 dptr = (uint32_t *) nvram_data;
7684 for (lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
7685 isp_rd_2400_nvram(isp, addr++, dptr++);
7687 if (nvram_data[0] != 'I' || nvram_data[1] != 'S' ||
7688 nvram_data[2] != 'P') {
7689 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM header (%x %x %x)",
7690 nvram_data[0], nvram_data[1], nvram_data[2]);
7694 dptr = (uint32_t *) nvram_data;
7695 for (csum = 0, lwrds = 0; lwrds < ISP2400_NVRAM_SIZE >> 2; lwrds++) {
7697 ISP_IOXGET_32(isp, &dptr[lwrds], tmp);
7701 isp_prt(isp, ISP_LOGWARN, "invalid NVRAM checksum");
7705 isp_parse_nvram_2400(isp, nvram_data);
7711 isp_rdnvram_word(ispsoftc_t *isp, int wo, uint16_t *rp)
7714 uint16_t bit, rqst, junk;
7716 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
7718 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
7722 wo &= ((ISP2100_NVRAM_SIZE >> 1) - 1);
7723 if (IS_2312(isp) && isp->isp_port) {
7726 rqst = (ISP_NVRAM_READ << 8) | wo;
7728 } else if (IS_ULTRA2(isp)) {
7729 wo &= ((ISP1080_NVRAM_SIZE >> 1) - 1);
7730 rqst = (ISP_NVRAM_READ << 8) | wo;
7733 wo &= ((ISP_NVRAM_SIZE >> 1) - 1);
7734 rqst = (ISP_NVRAM_READ << 6) | wo;
7739 * Clock the word select request out...
7741 for (i = cbits; i >= 0; i--) {
7742 if ((rqst >> i) & 1) {
7743 bit = BIU_NVRAM_SELECT | BIU_NVRAM_DATAOUT;
7745 bit = BIU_NVRAM_SELECT;
7747 ISP_WRITE(isp, BIU_NVRAM, bit);
7749 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7750 ISP_WRITE(isp, BIU_NVRAM, bit | BIU_NVRAM_CLOCK);
7752 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7753 ISP_WRITE(isp, BIU_NVRAM, bit);
7755 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7758 * Now read the result back in (bits come back in MSB format).
7761 for (i = 0; i < 16; i++) {
7764 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT|BIU_NVRAM_CLOCK);
7766 rv = ISP_READ(isp, BIU_NVRAM);
7767 if (rv & BIU_NVRAM_DATAIN) {
7771 ISP_WRITE(isp, BIU_NVRAM, BIU_NVRAM_SELECT);
7773 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7775 ISP_WRITE(isp, BIU_NVRAM, 0);
7777 junk = ISP_READ(isp, BIU_NVRAM); /* force PCI flush */
7778 ISP_SWIZZLE_NVRAM_WORD(isp, rp);
7782 isp_rd_2400_nvram(ispsoftc_t *isp, uint32_t addr, uint32_t *rp)
7785 uint32_t base = 0x7ffe0000;
7789 base = 0x7ff00000 | 0x48000;
7791 ISP_WRITE(isp, BIU2400_FLASH_ADDR, base | addr);
7792 for (loops = 0; loops < 5000; loops++) {
7794 tmp = ISP_READ(isp, BIU2400_FLASH_ADDR);
7795 if ((tmp & (1U << 31)) != 0) {
7799 if (tmp & (1U << 31)) {
7800 *rp = ISP_READ(isp, BIU2400_FLASH_DATA);
7801 ISP_SWIZZLE_NVRAM_LONG(isp, rp);
7808 isp_parse_nvram_1020(ispsoftc_t *isp, uint8_t *nvram_data)
7810 sdparam *sdp = SDPARAM(isp, 0);
7813 sdp->isp_fifo_threshold =
7814 ISP_NVRAM_FIFO_THRESHOLD(nvram_data) |
7815 (ISP_NVRAM_FIFO_THRESHOLD_128(nvram_data) << 2);
7817 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
7818 sdp->isp_initiator_id = ISP_NVRAM_INITIATOR_ID(nvram_data);
7820 sdp->isp_bus_reset_delay =
7821 ISP_NVRAM_BUS_RESET_DELAY(nvram_data);
7823 sdp->isp_retry_count =
7824 ISP_NVRAM_BUS_RETRY_COUNT(nvram_data);
7826 sdp->isp_retry_delay =
7827 ISP_NVRAM_BUS_RETRY_DELAY(nvram_data);
7829 sdp->isp_async_data_setup =
7830 ISP_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data);
7832 if (isp->isp_type >= ISP_HA_SCSI_1040) {
7833 if (sdp->isp_async_data_setup < 9) {
7834 sdp->isp_async_data_setup = 9;
7837 if (sdp->isp_async_data_setup != 6) {
7838 sdp->isp_async_data_setup = 6;
7842 sdp->isp_req_ack_active_neg =
7843 ISP_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data);
7845 sdp->isp_data_line_active_neg =
7846 ISP_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data);
7848 sdp->isp_data_dma_burst_enabl =
7849 ISP_NVRAM_DATA_DMA_BURST_ENABLE(nvram_data);
7851 sdp->isp_cmd_dma_burst_enable =
7852 ISP_NVRAM_CMD_DMA_BURST_ENABLE(nvram_data);
7854 sdp->isp_tag_aging =
7855 ISP_NVRAM_TAG_AGE_LIMIT(nvram_data);
7857 sdp->isp_selection_timeout =
7858 ISP_NVRAM_SELECTION_TIMEOUT(nvram_data);
7860 sdp->isp_max_queue_depth =
7861 ISP_NVRAM_MAX_QUEUE_DEPTH(nvram_data);
7863 sdp->isp_fast_mttr = ISP_NVRAM_FAST_MTTR_ENABLE(nvram_data);
7865 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7866 sdp->isp_devparam[tgt].dev_enable =
7867 ISP_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt);
7868 sdp->isp_devparam[tgt].exc_throttle =
7869 ISP_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt);
7870 sdp->isp_devparam[tgt].nvrm_offset =
7871 ISP_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt);
7872 sdp->isp_devparam[tgt].nvrm_period =
7873 ISP_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt);
7875 * We probably shouldn't lie about this, but it
7876 * it makes it much safer if we limit NVRAM values
7879 if (isp->isp_type < ISP_HA_SCSI_1040) {
7881 * If we're not ultra, we can't possibly
7882 * be a shorter period than this.
7884 if (sdp->isp_devparam[tgt].nvrm_period < 0x19) {
7885 sdp->isp_devparam[tgt].nvrm_period = 0x19;
7887 if (sdp->isp_devparam[tgt].nvrm_offset > 0xc) {
7888 sdp->isp_devparam[tgt].nvrm_offset = 0x0c;
7891 if (sdp->isp_devparam[tgt].nvrm_offset > 0x8) {
7892 sdp->isp_devparam[tgt].nvrm_offset = 0x8;
7895 sdp->isp_devparam[tgt].nvrm_flags = 0;
7896 if (ISP_NVRAM_TGT_RENEG(nvram_data, tgt))
7897 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
7898 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
7899 if (ISP_NVRAM_TGT_TQING(nvram_data, tgt))
7900 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
7901 if (ISP_NVRAM_TGT_SYNC(nvram_data, tgt))
7902 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
7903 if (ISP_NVRAM_TGT_WIDE(nvram_data, tgt))
7904 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
7905 if (ISP_NVRAM_TGT_PARITY(nvram_data, tgt))
7906 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
7907 if (ISP_NVRAM_TGT_DISC(nvram_data, tgt))
7908 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
7909 sdp->isp_devparam[tgt].actv_flags = 0; /* we don't know */
7910 sdp->isp_devparam[tgt].goal_offset =
7911 sdp->isp_devparam[tgt].nvrm_offset;
7912 sdp->isp_devparam[tgt].goal_period =
7913 sdp->isp_devparam[tgt].nvrm_period;
7914 sdp->isp_devparam[tgt].goal_flags =
7915 sdp->isp_devparam[tgt].nvrm_flags;
7920 isp_parse_nvram_1080(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
7922 sdparam *sdp = SDPARAM(isp, bus);
7925 sdp->isp_fifo_threshold =
7926 ISP1080_NVRAM_FIFO_THRESHOLD(nvram_data);
7928 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
7929 sdp->isp_initiator_id = ISP1080_NVRAM_INITIATOR_ID(nvram_data, bus);
7931 sdp->isp_bus_reset_delay =
7932 ISP1080_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
7934 sdp->isp_retry_count =
7935 ISP1080_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
7937 sdp->isp_retry_delay =
7938 ISP1080_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
7940 sdp->isp_async_data_setup =
7941 ISP1080_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
7943 sdp->isp_req_ack_active_neg =
7944 ISP1080_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
7946 sdp->isp_data_line_active_neg =
7947 ISP1080_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
7949 sdp->isp_data_dma_burst_enabl =
7950 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
7952 sdp->isp_cmd_dma_burst_enable =
7953 ISP1080_NVRAM_BURST_ENABLE(nvram_data);
7955 sdp->isp_selection_timeout =
7956 ISP1080_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
7958 sdp->isp_max_queue_depth =
7959 ISP1080_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
7961 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
7962 sdp->isp_devparam[tgt].dev_enable =
7963 ISP1080_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
7964 sdp->isp_devparam[tgt].exc_throttle =
7965 ISP1080_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
7966 sdp->isp_devparam[tgt].nvrm_offset =
7967 ISP1080_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
7968 sdp->isp_devparam[tgt].nvrm_period =
7969 ISP1080_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
7970 sdp->isp_devparam[tgt].nvrm_flags = 0;
7971 if (ISP1080_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
7972 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
7973 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
7974 if (ISP1080_NVRAM_TGT_TQING(nvram_data, tgt, bus))
7975 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
7976 if (ISP1080_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
7977 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
7978 if (ISP1080_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
7979 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
7980 if (ISP1080_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
7981 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
7982 if (ISP1080_NVRAM_TGT_DISC(nvram_data, tgt, bus))
7983 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
7984 sdp->isp_devparam[tgt].actv_flags = 0;
7985 sdp->isp_devparam[tgt].goal_offset =
7986 sdp->isp_devparam[tgt].nvrm_offset;
7987 sdp->isp_devparam[tgt].goal_period =
7988 sdp->isp_devparam[tgt].nvrm_period;
7989 sdp->isp_devparam[tgt].goal_flags =
7990 sdp->isp_devparam[tgt].nvrm_flags;
7995 isp_parse_nvram_12160(ispsoftc_t *isp, int bus, uint8_t *nvram_data)
7997 sdparam *sdp = SDPARAM(isp, bus);
8000 sdp->isp_fifo_threshold =
8001 ISP12160_NVRAM_FIFO_THRESHOLD(nvram_data);
8003 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0)
8004 sdp->isp_initiator_id = ISP12160_NVRAM_INITIATOR_ID(nvram_data, bus);
8006 sdp->isp_bus_reset_delay =
8007 ISP12160_NVRAM_BUS_RESET_DELAY(nvram_data, bus);
8009 sdp->isp_retry_count =
8010 ISP12160_NVRAM_BUS_RETRY_COUNT(nvram_data, bus);
8012 sdp->isp_retry_delay =
8013 ISP12160_NVRAM_BUS_RETRY_DELAY(nvram_data, bus);
8015 sdp->isp_async_data_setup =
8016 ISP12160_NVRAM_ASYNC_DATA_SETUP_TIME(nvram_data, bus);
8018 sdp->isp_req_ack_active_neg =
8019 ISP12160_NVRAM_REQ_ACK_ACTIVE_NEGATION(nvram_data, bus);
8021 sdp->isp_data_line_active_neg =
8022 ISP12160_NVRAM_DATA_LINE_ACTIVE_NEGATION(nvram_data, bus);
8024 sdp->isp_data_dma_burst_enabl =
8025 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
8027 sdp->isp_cmd_dma_burst_enable =
8028 ISP12160_NVRAM_BURST_ENABLE(nvram_data);
8030 sdp->isp_selection_timeout =
8031 ISP12160_NVRAM_SELECTION_TIMEOUT(nvram_data, bus);
8033 sdp->isp_max_queue_depth =
8034 ISP12160_NVRAM_MAX_QUEUE_DEPTH(nvram_data, bus);
8036 for (tgt = 0; tgt < MAX_TARGETS; tgt++) {
8037 sdp->isp_devparam[tgt].dev_enable =
8038 ISP12160_NVRAM_TGT_DEVICE_ENABLE(nvram_data, tgt, bus);
8039 sdp->isp_devparam[tgt].exc_throttle =
8040 ISP12160_NVRAM_TGT_EXEC_THROTTLE(nvram_data, tgt, bus);
8041 sdp->isp_devparam[tgt].nvrm_offset =
8042 ISP12160_NVRAM_TGT_SYNC_OFFSET(nvram_data, tgt, bus);
8043 sdp->isp_devparam[tgt].nvrm_period =
8044 ISP12160_NVRAM_TGT_SYNC_PERIOD(nvram_data, tgt, bus);
8045 sdp->isp_devparam[tgt].nvrm_flags = 0;
8046 if (ISP12160_NVRAM_TGT_RENEG(nvram_data, tgt, bus))
8047 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_RENEG;
8048 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_ARQ;
8049 if (ISP12160_NVRAM_TGT_TQING(nvram_data, tgt, bus))
8050 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_TQING;
8051 if (ISP12160_NVRAM_TGT_SYNC(nvram_data, tgt, bus))
8052 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_SYNC;
8053 if (ISP12160_NVRAM_TGT_WIDE(nvram_data, tgt, bus))
8054 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_WIDE;
8055 if (ISP12160_NVRAM_TGT_PARITY(nvram_data, tgt, bus))
8056 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_PARITY;
8057 if (ISP12160_NVRAM_TGT_DISC(nvram_data, tgt, bus))
8058 sdp->isp_devparam[tgt].nvrm_flags |= DPARM_DISC;
8059 sdp->isp_devparam[tgt].actv_flags = 0;
8060 sdp->isp_devparam[tgt].goal_offset =
8061 sdp->isp_devparam[tgt].nvrm_offset;
8062 sdp->isp_devparam[tgt].goal_period =
8063 sdp->isp_devparam[tgt].nvrm_period;
8064 sdp->isp_devparam[tgt].goal_flags =
8065 sdp->isp_devparam[tgt].nvrm_flags;
8070 isp_parse_nvram_2100(ispsoftc_t *isp, uint8_t *nvram_data)
8072 fcparam *fcp = FCPARAM(isp, 0);
8076 * There is NVRAM storage for both Port and Node entities-
8077 * but the Node entity appears to be unused on all the cards
8078 * I can find. However, we should account for this being set
8079 * at some point in the future.
8081 * Qlogic WWNs have an NAA of 2, but usually nothing shows up in
8082 * bits 48..60. In the case of the 2202, it appears that they do
8083 * use bit 48 to distinguish between the two instances on the card.
8084 * The 2204, which I've never seen, *probably* extends this method.
8086 wwn = ISP2100_NVRAM_PORT_NAME(nvram_data);
8088 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Port WWN 0x%08x%08x",
8089 (uint32_t) (wwn >> 32), (uint32_t) (wwn));
8090 if ((wwn >> 60) == 0) {
8091 wwn |= (((uint64_t) 2)<< 60);
8094 fcp->isp_wwpn_nvram = wwn;
8095 if (IS_2200(isp) || IS_23XX(isp)) {
8096 wwn = ISP2100_NVRAM_NODE_NAME(nvram_data);
8098 isp_prt(isp, ISP_LOGCONFIG, "NVRAM Node WWN 0x%08x%08x",
8099 (uint32_t) (wwn >> 32),
8101 if ((wwn >> 60) == 0) {
8102 wwn |= (((uint64_t) 2)<< 60);
8105 wwn = fcp->isp_wwpn_nvram & ~((uint64_t) 0xfff << 48);
8108 wwn &= ~((uint64_t) 0xfff << 48);
8110 fcp->isp_wwnn_nvram = wwn;
8112 fcp->isp_maxalloc = ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data);
8113 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
8114 DEFAULT_FRAMESIZE(isp) =
8115 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data);
8117 fcp->isp_retry_delay = ISP2100_NVRAM_RETRY_DELAY(nvram_data);
8118 fcp->isp_retry_count = ISP2100_NVRAM_RETRY_COUNT(nvram_data);
8119 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
8120 fcp->isp_loopid = ISP2100_NVRAM_HARDLOOPID(nvram_data);
8122 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
8123 DEFAULT_EXEC_THROTTLE(isp) =
8124 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data);
8126 fcp->isp_fwoptions = ISP2100_NVRAM_OPTIONS(nvram_data);
8127 isp_prt(isp, ISP_LOGDEBUG0,
8128 "NVRAM 0x%08x%08x 0x%08x%08x maxalloc %d maxframelen %d",
8129 (uint32_t) (fcp->isp_wwnn_nvram >> 32),
8130 (uint32_t) fcp->isp_wwnn_nvram,
8131 (uint32_t) (fcp->isp_wwpn_nvram >> 32),
8132 (uint32_t) fcp->isp_wwpn_nvram,
8133 ISP2100_NVRAM_MAXIOCBALLOCATION(nvram_data),
8134 ISP2100_NVRAM_MAXFRAMELENGTH(nvram_data));
8135 isp_prt(isp, ISP_LOGDEBUG0,
8136 "execthrottle %d fwoptions 0x%x hardloop %d tov %d",
8137 ISP2100_NVRAM_EXECUTION_THROTTLE(nvram_data),
8138 ISP2100_NVRAM_OPTIONS(nvram_data),
8139 ISP2100_NVRAM_HARDLOOPID(nvram_data),
8140 ISP2100_NVRAM_TOV(nvram_data));
8141 fcp->isp_xfwoptions = ISP2100_XFW_OPTIONS(nvram_data);
8142 fcp->isp_zfwoptions = ISP2100_ZFW_OPTIONS(nvram_data);
8143 isp_prt(isp, ISP_LOGDEBUG0, "xfwoptions 0x%x zfw options 0x%x",
8144 ISP2100_XFW_OPTIONS(nvram_data), ISP2100_ZFW_OPTIONS(nvram_data));
8148 isp_parse_nvram_2400(ispsoftc_t *isp, uint8_t *nvram_data)
8150 fcparam *fcp = FCPARAM(isp, 0);
8153 isp_prt(isp, ISP_LOGDEBUG0,
8154 "NVRAM 0x%08x%08x 0x%08x%08x exchg_cnt %d maxframelen %d",
8155 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data) >> 32),
8156 (uint32_t) (ISP2400_NVRAM_NODE_NAME(nvram_data)),
8157 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data) >> 32),
8158 (uint32_t) (ISP2400_NVRAM_PORT_NAME(nvram_data)),
8159 ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data),
8160 ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data));
8161 isp_prt(isp, ISP_LOGDEBUG0,
8162 "NVRAM execthr %d loopid %d fwopt1 0x%x fwopt2 0x%x fwopt3 0x%x",
8163 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data),
8164 ISP2400_NVRAM_HARDLOOPID(nvram_data),
8165 ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data),
8166 ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data),
8167 ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data));
8169 wwn = ISP2400_NVRAM_PORT_NAME(nvram_data);
8170 fcp->isp_wwpn_nvram = wwn;
8172 wwn = ISP2400_NVRAM_NODE_NAME(nvram_data);
8174 if ((wwn >> 60) != 2 && (wwn >> 60) != 5) {
8178 if (wwn == 0 && (fcp->isp_wwpn_nvram >> 60) == 2) {
8179 wwn = fcp->isp_wwpn_nvram;
8180 wwn &= ~((uint64_t) 0xfff << 48);
8182 fcp->isp_wwnn_nvram = wwn;
8184 if (ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data)) {
8185 fcp->isp_maxalloc = ISP2400_NVRAM_EXCHANGE_COUNT(nvram_data);
8187 if ((isp->isp_confopts & ISP_CFG_OWNFSZ) == 0) {
8188 DEFAULT_FRAMESIZE(isp) =
8189 ISP2400_NVRAM_MAXFRAMELENGTH(nvram_data);
8191 if ((isp->isp_confopts & ISP_CFG_OWNLOOPID) == 0) {
8192 fcp->isp_loopid = ISP2400_NVRAM_HARDLOOPID(nvram_data);
8194 if ((isp->isp_confopts & ISP_CFG_OWNEXCTHROTTLE) == 0) {
8195 DEFAULT_EXEC_THROTTLE(isp) =
8196 ISP2400_NVRAM_EXECUTION_THROTTLE(nvram_data);
8198 fcp->isp_fwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS1(nvram_data);
8199 fcp->isp_xfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS2(nvram_data);
8200 fcp->isp_zfwoptions = ISP2400_NVRAM_FIRMWARE_OPTIONS3(nvram_data);